@lexical/y/server
Interfaces
YDraft
Defined in: packages/lexical-y/src/internal/Server.ts:574
Experimental
What the editor held that could not be committed (see
binding.quiesce()): its state as JSON, and whether it differs from the
document's own read.
Properties
differs
readonlydiffers:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:576
Experimental
json
readonlyjson:unknown
Defined in: packages/lexical-y/src/internal/Server.ts:575
Experimental
YLegacySignal
Defined in: packages/lexical-y/src/internal/Server.ts:351
Experimental
A legacy signal as sent (see legacySignal): its exact
payload, and the one item it writes (client, clock), on root's
attribute key, with the value true.
Properties
client
readonlyclient:number
Defined in: packages/lexical-y/src/internal/Server.ts:353
Experimental
clock
readonlyclock:number
Defined in: packages/lexical-y/src/internal/Server.ts:354
Experimental
key
readonlykey:string
Defined in: packages/lexical-y/src/internal/Server.ts:356
Experimental
root
readonlyroot:string
Defined in: packages/lexical-y/src/internal/Server.ts:355
Experimental
update
readonlyupdate:Uint8Array
Defined in: packages/lexical-y/src/internal/Server.ts:352
Experimental
YPreparedRoom
Defined in: packages/lexical-y/src/internal/Server.ts:86
Experimental
What prepareYRoom returns.
Properties
base
readonlybase: {generation:string;state:Uint8Array; } |null
Defined in: packages/lexical-y/src/internal/Server.ts:97
Experimental
When changed: the stored state and its generation, to keep as the
immutable base of that generation (bases[generation] = state).
changed
readonlychanged:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:88
Experimental
Whether the state was migrated (store the result) or not (store nothing).
generation
readonlygeneration:string
Defined in: packages/lexical-y/src/internal/Server.ts:92
Experimental
Its generation (see generationOf).
pending
readonlypending:Uint8Array<ArrayBufferLike> |null
Defined in: packages/lexical-y/src/internal/Server.ts:102
Experimental
Pending material split out of the stored state, for a pending record.
receipt
readonlyreceipt:YMigrationReceipt
Defined in: packages/lexical-y/src/internal/Server.ts:103
Experimental
state
readonlystate:Uint8Array
Defined in: packages/lexical-y/src/internal/Server.ts:90
Experimental
The state to serve: the stored bytes themselves when nothing changed.
YPrepareRoomOptions
Defined in: packages/lexical-y/src/internal/Server.ts:65
Experimental
Options of prepareYRoom.
Properties
clientID?
readonlyoptionalclientID?: (input) =>number
Defined in: packages/lexical-y/src/internal/Server.ts:77
Experimental
Parameters
input
revision
number
root
string
step
string
to
number
Returns
number
clientIDRange?
readonlyoptionalclientIDRange?:ClientIDRange
Defined in: packages/lexical-y/src/internal/Server.ts:76
Experimental
gc?
readonlyoptionalgc?:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:73
Experimental
Garbage collection of its stored documents (default true).
incarnation
readonlyincarnation:string
Defined in: packages/lexical-y/src/internal/Server.ts:69
Experimental
The room's incarnation (see generationOf).
roots?
readonlyoptionalroots?: readonlystring[]
Defined in: packages/lexical-y/src/internal/Server.ts:71
Experimental
The roots it serves (default ['lexical-y']).
steps
readonlysteps: readonlyYLayoutMigration[]
Defined in: packages/lexical-y/src/internal/Server.ts:67
Experimental
The steps the authority ships (statically imported).
to?
readonlyoptionalto?:number
Defined in: packages/lexical-y/src/internal/Server.ts:75
Experimental
The target (default MIN_LAYOUT: only roots below the floor migrate).
YQuarantineRecord
Defined in: packages/lexical-y/src/internal/Server.ts:580
Experimental
A per-document quarantine record (append-only).
Properties
actionable
readonlyactionable:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:609
Experimental
Whether it holds anything new (see hasNewYEdits); true when unknown.
base
readonlybase:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:595
Experimental
The generation of the base it can be compared with, null: none.
collisions
readonlycollisions: readonlyYLegacySignal[]
Defined in: packages/lexical-y/src/internal/Server.ts:602
Experimental
Signals whose id holds other content (the replica's own): kept.
complete
readonlycomplete:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:607
Experimental
Whether the source view has every dependency (see sourceView).
deltas
readonlydeltas: readonlyUint8Array<ArrayBufferLike>[]
Defined in: packages/lexical-y/src/internal/Server.ts:590
Experimental
Later updates of a captured session.
draft
readonlydraft:YDraft|null
Defined in: packages/lexical-y/src/internal/Server.ts:593
Experimental
hash
readonlyhash:string
Defined in: packages/lexical-y/src/internal/Server.ts:605
Experimental
A hash of the material (what an acknowledgement names).
id
readonlyid:string
Defined in: packages/lexical-y/src/internal/Server.ts:582
Experimental
The record's id: its hash unless given.
kind
readonlykind:"capture"|"pending"|"handoff"
Defined in: packages/lexical-y/src/internal/Server.ts:585
Experimental
queue
readonlyqueue: readonlyUint8Array<ArrayBufferLike>[]
Defined in: packages/lexical-y/src/internal/Server.ts:592
Experimental
The replica's queue of unsent updates.
receivedAt
readonlyreceivedAt:number
Defined in: packages/lexical-y/src/internal/Server.ts:603
Experimental
replica
readonlyreplica:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:584
Experimental
session
readonlysession:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:583
Experimental
signals
readonlysignals: readonlyYLegacySignal[]
Defined in: packages/lexical-y/src/internal/Server.ts:600
Experimental
Legacy signals the authority built for this session (exact payloads): their items are ignored where id, parent, key and content all match.
snapshot
readonlysnapshot:Uint8Array<ArrayBufferLike> |null
Defined in: packages/lexical-y/src/internal/Server.ts:588
Experimental
The replica's whole document (V1), standalone.
source
readonlysource:YRecordSource
Defined in: packages/lexical-y/src/internal/Server.ts:586
Experimental
YQuarantineRecordInput
Defined in: packages/lexical-y/src/internal/Server.ts:613
Experimental
The input of quarantineRecord.
Properties
deltas?
readonlyoptionaldeltas?: readonlyUint8Array<ArrayBufferLike>[]
Defined in: packages/lexical-y/src/internal/Server.ts:620
Experimental
draft?
readonlyoptionaldraft?:YDraft|null
Defined in: packages/lexical-y/src/internal/Server.ts:622
Experimental
id?
readonlyoptionalid?:string
Defined in: packages/lexical-y/src/internal/Server.ts:614
Experimental
kind
readonlykind:"capture"|"pending"|"handoff"
Defined in: packages/lexical-y/src/internal/Server.ts:617
Experimental
queue?
readonlyoptionalqueue?: readonlyUint8Array<ArrayBufferLike>[]
Defined in: packages/lexical-y/src/internal/Server.ts:621
Experimental
receivedAt
readonlyreceivedAt:number
Defined in: packages/lexical-y/src/internal/Server.ts:624
Experimental
replica?
readonlyoptionalreplica?:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:616
Experimental
session?
readonlyoptionalsession?:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:615
Experimental
signals?
readonlyoptionalsignals?: readonlyYLegacySignal[]
Defined in: packages/lexical-y/src/internal/Server.ts:623
Experimental
snapshot?
readonlyoptionalsnapshot?:Uint8Array<ArrayBufferLike> |null
Defined in: packages/lexical-y/src/internal/Server.ts:619
Experimental
source
readonlysource:YRecordSource
Defined in: packages/lexical-y/src/internal/Server.ts:618
Experimental
YRecordSource
Defined in: packages/lexical-y/src/internal/Server.ts:559
Experimental
Where a quarantine record's material came from (null: unknown).
Properties
generation
readonlygeneration:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:561
Experimental
incarnation
readonlyincarnation:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:560
Experimental
layouts
readonlylayouts: readonly [number,number] |null
Defined in: packages/lexical-y/src/internal/Server.ts:563
Experimental
The layouts the source's release reads ([MIN_LAYOUT, LAYOUT_VERSION]).
renderer
readonlyrenderer:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:566
Experimental
The app's renderer (a release name) that can show the source.
schemaVersion
readonlyschemaVersion:number|null
Defined in: packages/lexical-y/src/internal/Server.ts:564
Experimental
YRoomDescription
Defined in: packages/lexical-y/src/internal/Server.ts:175
Experimental
The room as checkYSession sees it (see describeYRoom).
Properties
generation
readonlygeneration:string
Defined in: packages/lexical-y/src/internal/Server.ts:176
Experimental
incarnation
readonlyincarnation:string
Defined in: packages/lexical-y/src/internal/Server.ts:177
Experimental
inherited
readonlyinherited:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:182
Experimental
Whether the incarnation was inherited: assigned to a room that already existed when the fence was deployed.
layout
readonlylayout:number|null
Defined in: packages/lexical-y/src/internal/Server.ts:186
Experimental
The highest layout the served roots record, null when none does.
pristine
readonlypristine:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:184
Experimental
Whether the room has no state at all (never seeded).
seedContract
readonlyseedContract:number
Defined in: packages/lexical-y/src/internal/Server.ts:192
Experimental
The room's seed contract: the SEED_LAYOUT its incarnation was issued under. An authority whose own SEED_LAYOUT differs replaces a pristine room's incarnation before it admits anyone (see needsNewIncarnation).
YSessionCapture
Defined in: packages/lexical-y/src/internal/Server.ts:360
Experimental
What a legacy capture sends and keeps (see captureYSession).
Properties
messages
readonlymessages: readonlyUint8Array<ArrayBufferLike>[]
Defined in: packages/lexical-y/src/internal/Server.ts:372
Experimental
The same two as y-websocket messages (messageSync framing), in order.
syncStep1
readonlysyncStep1:Uint8Array
Defined in: packages/lexical-y/src/internal/Server.ts:370
Experimental
The authority's own sync step 1: an empty state vector, so the client's sync step 2 is its whole document (a standalone snapshot).
syncStep2
readonlysyncStep2:Uint8Array
Defined in: packages/lexical-y/src/internal/Server.ts:365
Experimental
The answer to the client's sync step 1: an empty update (it receives nothing of the room).
Methods
add()
add(
update):void
Defined in: packages/lexical-y/src/internal/Server.ts:377
Experimental
Keep an update the session sent: its sync step 2 (the snapshot) first, then every later update (deltas). Never apply them to the room.
Parameters
update
Returns
void
collisions()
collisions():
YLegacySignal[]
Defined in: packages/lexical-y/src/internal/Server.ts:389
Experimental
Signals whose id the session wrote other content at (its own client had the same id): each was not a signal; send another.
Returns
material()
material():
object
Defined in: packages/lexical-y/src/internal/Server.ts:391
Experimental
The snapshot, deltas and signals kept so far.
Returns
object
deltas
deltas:
Uint8Array<ArrayBufferLike>[]
signals
signals:
YLegacySignal[]
snapshot
snapshot:
Uint8Array<ArrayBufferLike> |null
signal()
signal(
supportedSchema,root?):YLegacySignal|null
Defined in: packages/lexical-y/src/internal/Server.ts:384
Experimental
The update that turns the legacy client read only (see legacySignal),
built on its snapshot and deltas once the snapshot has arrived (null
before), kept with the capture. Send it to the client only. Call it
again when collisions() names one: another fresh client id.
Parameters
supportedSchema
number
root?
string
Returns
YLegacySignal | null
YSessionHandshake
Defined in: packages/lexical-y/src/internal/Server.ts:167
Experimental
What a client sends before any sync message: the
generation its replica's material was made against (null: none,
'unknown': material without a recorded generation), whether it holds
material (unsent edits or a cached state), the layouts its release reads
([MIN_LAYOUT, LAYOUT_VERSION]) and the layout its seed records
(SEED_LAYOUT).
Properties
generation
readonlygeneration:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:168
Experimental
layouts
readonlylayouts: readonly [number,number]
Defined in: packages/lexical-y/src/internal/Server.ts:170
Experimental
material
readonlymaterial:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:169
Experimental
seed
readonlyseed:number
Defined in: packages/lexical-y/src/internal/Server.ts:171
Experimental
Type Aliases
YSessionVerdict
YSessionVerdict = {
initialize:boolean;verdict:"admit"; } | {initialize:boolean;verdict:"bootstrap"; } | {verdict:"stale"; } | {verdict:"refuse-layout"; } | {verdict:"legacy"; }
Defined in: packages/lexical-y/src/internal/Server.ts:248
Experimental
checkYSession's verdict (y-server.md, the handshake table).
Union Members
Type Literal
{ initialize: boolean; verdict: "admit"; }
Sync both ways. initialize: the room is pristine and the client may
seed it.
Type Literal
{ initialize: boolean; verdict: "bootstrap"; }
A replica without material: load the room's state into a new document,
persist it with the generation, then bind. initialize: the room is
pristine and the client may seed it.
Type Literal
{ verdict: "stale"; }
A replica with material that may not sync with this room: no sync either way; it hands its material off (recovery handoff) and connects again once acknowledged, without material.
Type Literal
{ verdict: "refuse-layout"; }
The client cannot read or seed the room: reload to another release.
Type Literal
{ verdict: "legacy"; }
No handshake on a room it may not join: capture (captureYSession).
Variables
UNKNOWN_GENERATION
constUNKNOWN_GENERATION:"unknown"='unknown'
Defined in: packages/lexical-y/src/internal/Server.ts:157
Experimental
A generation a replica cannot name (material from before the fence).
Functions
captureYSession()
captureYSession():
YSessionCapture
Defined in: packages/lexical-y/src/internal/Server.ts:406
Experimental
The legacy capture (a session with no handshake on a room
it may not join): the authority answers its sync step 1 with an empty
sync step 2 and sends its own sync step 1 with an empty state vector, so
the client's sync step 2 is its whole document, a standalone snapshot
never merged with anything the authority holds; later updates are kept
as deltas. Build a record from material() with quarantineRecord.
Returns
checkYSession()
checkYSession(
room,client):YSessionVerdict
Defined in: packages/lexical-y/src/internal/Server.ts:289
Experimental
The handshake verdict for a session (y-server.md "Migrating stored documents"): the first row that matches wins.
- No handshake (
clientnull, a release before the fence): admit as today when the room's incarnation is inherited and it never migrated (no epoch) or was replaced (a new incarnation is never inherited); otherwise legacy. - Material, and any of: another generation (another token, unknown or
null), the room's layout outside the client's
layouts, a pristine room whose seed contract is not the client'sseed: stale. No client holding material is refused before its material is acknowledged. - The room's layout outside
layouts: refuse-layout. - A pristine room whose seed contract is not
seed: refuse-layout. - The room's generation: admit (
initializein a pristine room). - No material: bootstrap (
initializein a pristine room). Never sync a session whose verdict is not'admit', and check every update again at commit against the room's current generation.
Parameters
room
client
YSessionHandshake | null
Returns
createYDoc()
createYDoc(
state?,options?):YDoc
Defined in: packages/lexical-y/src/internal/RawYDoc.ts:67
Experimental
A Y.Doc for a relay's, server's or migration's copy of an
@lexical/y document (exported as createYDoc by @lexical/y/server):
Yjs's format cleanup is turned off (cleanupFormatting = false) before
anything is applied to it, and nothing else is added. Applying an update
to a document with the cleanup on deletes format items the binding keeps,
and the stored state then reads differently from what the clients show.
A relay never undoes, so it needs nothing the binding adds to a client's
document: bind a client's document from @lexical/y's createYDoc.
state, a stored state, is applied when given; options are those of
new Y.Doc(options) (the default document is garbage collected, as
clients store one). Throws a YUnsupportedYjsError, before the document
is made, when the @y/y the app loaded is not the one @lexical/y
supports.
Parameters
state?
Uint8Array<ArrayBufferLike> | null
options?
Returns
describeYRoom()
describeYRoom(
doc,options):YRoomDescription
Defined in: packages/lexical-y/src/internal/Server.ts:196
Experimental
Describe a room's document for checkYSession.
Parameters
doc
options
incarnation
string
inherited
boolean
roots?
readonly string[]
seedContract
number
The SEED_LAYOUT the room's incarnation was issued under.
Returns
generationOf()
generationOf(
doc,incarnation,roots?):string
Defined in: packages/lexical-y/src/internal/Server.ts:42
Experimental
The generation of a document's state, over the roots an
authority serves: `${incarnation}/${epochs}` where epochs lists,
in root-name order, encodeURIComponent(root)=layout.client.clock for
each root with an epoch (=? for a malformed one), joined by ,, or -
when none has one. Opaque: only equality matters. incarnation is the
room's (a new one on every recreation, restore and fresh-document
migration), so a copy from an earlier incarnation never matches.
Parameters
doc
incarnation
string
roots?
readonly string[] = ...
Returns
string
hasNewYEdits()
hasNewYEdits(
record,base):boolean
Defined in: packages/lexical-y/src/internal/Server.ts:748
Experimental
Whether a quarantine record holds anything base (the
state of the generation it was made against) lacks, read from its source
view (Yjs only, no Lexical): a struct the base lacks (not a legacy
signal's own item), a deletion of an item the base holds live, a draft the
client marked differs, or an incomplete view (a missing dependency: it
cannot be shown to hold nothing). Only then should an app prompt; every
record stays listable.
Parameters
record
RecordMaterial & Pick<YQuarantineRecord, "draft">
base
Returns
boolean
legacySignal()
legacySignal(
snapshot,supportedSchema,root?):YLegacySignal
Defined in: packages/lexical-y/src/internal/Server.ts:487
Experimental
The update that turns a client from before the fence read
only with its existing "newer version" state: built on that client's own
standalone snapshot, under a fresh random client id, it records
lexical-y-schema:<n> on root, n above the highest schema version the
snapshot records and above supportedSchema. It adds no deletion the
replica does not have. Never apply it to the room, and never build it on
the room's state (that would bring the room's deletions into the
client's offline text). Keep the returned signal with the record: its
item is excluded only where id, parent, key and content all match.
Parameters
snapshot
supportedSchema
number
root?
string = DEFAULT_ROOT_NAME
Returns
needsNewIncarnation()
needsNewIncarnation(
room,seedLayout):boolean
Defined in: packages/lexical-y/src/internal/Server.ts:240
Experimental
Whether an authority whose SEED_LAYOUT is seedLayout must
replace the room's incarnation (a new token, the new seed contract)
before it admits anyone: the room is pristine and was issued under
another seed contract. A replica that seeded under the old contract and
never reached storage then presents another generation and hands off its
material, instead of being admitted or refused.
Parameters
room
seedLayout
number
Returns
boolean
prepareYRoom()
prepareYRoom(
stored,options):YPreparedRoom
Defined in: packages/lexical-y/src/internal/Server.ts:115
Experimental
The load-time migration of a stored document, minus
storage (y-server.md "Migrating stored documents", steps 2 to 4): run it
behind the room's barrier with every session out, then store {state, generation}, bases[base.generation] = base.state and a pending
record, atomically, compare-and-set on the version read. Throws a
YMigrationError when a root is refused or a check fails: store nothing,
leave the room stuck (it applies nothing) and alert.
Parameters
stored
options
Returns
quarantineRecord()
quarantineRecord(
input,base?):YQuarantineRecord
Defined in: packages/lexical-y/src/internal/Server.ts:692
Experimental
Build a quarantine record: its hash (of the kind, snapshot,
deltas, queue and draft), whether its source view is complete, and, when
base is given (the state of the base generation), whether it holds
anything new (hasNewYEdits; without a base, it counts as actionable).
Parameters
input
base?
{ generation: string; state: Uint8Array; } | null
Returns
sourceView()
sourceView(
record):object
Defined in: packages/lexical-y/src/internal/Server.ts:665
Experimental
A record's source view: its snapshot, deltas and queue
applied, idempotently, into one scratch document (never stored, sent or
merged; destroy it when done). complete: no update in it lacks a
dependency (no pending material, no skipped range). What actionability,
rendering, export and replay read.
Parameters
record
Pick<YQuarantineRecord, "snapshot" | "deltas" | "queue">
Returns
object
complete
complete:
boolean
doc
doc:
Doc
References
YDoc
Re-exports YDoc
YDocOptions
Re-exports YDocOptions