@lexical/y/server
Interfaces
YDraft
Defined in: packages/lexical-y/src/internal/Server.ts:599
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:601
Experimental
json
readonlyjson:unknown
Defined in: packages/lexical-y/src/internal/Server.ts:600
Experimental
YLegacySignal
Defined in: packages/lexical-y/src/internal/Server.ts:376
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:378
Experimental
clock
readonlyclock:number
Defined in: packages/lexical-y/src/internal/Server.ts:379
Experimental
key
readonlykey:string
Defined in: packages/lexical-y/src/internal/Server.ts:381
Experimental
root
readonlyroot:string
Defined in: packages/lexical-y/src/internal/Server.ts:380
Experimental
update
readonlyupdate:Uint8Array
Defined in: packages/lexical-y/src/internal/Server.ts:377
Experimental
YPreparedRoom
Defined in: packages/lexical-y/src/internal/Server.ts:90
Experimental
What prepareYRoom returns.
Properties
base
readonlybase: {generation:string;state:Uint8Array; } |null
Defined in: packages/lexical-y/src/internal/Server.ts:101
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:92
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:96
Experimental
Its generation (see generationOf).
pending
readonlypending:Uint8Array<ArrayBufferLike> |null
Defined in: packages/lexical-y/src/internal/Server.ts:106
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:107
Experimental
state
readonlystate:Uint8Array
Defined in: packages/lexical-y/src/internal/Server.ts:94
Experimental
The state to serve: the stored bytes themselves when nothing changed.
YPrepareRoomOptions
Defined in: packages/lexical-y/src/internal/Server.ts:69
Experimental
Options of prepareYRoom.
Properties
clientID?
readonlyoptionalclientID?: (input) =>number
Defined in: packages/lexical-y/src/internal/Server.ts:81
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:80
Experimental
gc?
readonlyoptionalgc?:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:77
Experimental
Garbage collection of its stored documents (default true).
incarnation
readonlyincarnation:string
Defined in: packages/lexical-y/src/internal/Server.ts:73
Experimental
The room's incarnation (see generationOf).
roots?
readonlyoptionalroots?: readonlystring[]
Defined in: packages/lexical-y/src/internal/Server.ts:75
Experimental
The roots it serves (default ['lexical-y']).
steps
readonlysteps: readonlyYLayoutMigration[]
Defined in: packages/lexical-y/src/internal/Server.ts:71
Experimental
The steps the authority ships (statically imported).
to?
readonlyoptionalto?:number
Defined in: packages/lexical-y/src/internal/Server.ts:79
Experimental
The target (default MIN_LAYOUT: only roots below the floor migrate).
YQuarantineRecord
Defined in: packages/lexical-y/src/internal/Server.ts:605
Experimental
A per-document quarantine record (append-only).
Properties
actionable
readonlyactionable:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:649
Experimental
Whether it holds anything new (see hasNewYEdits); true when unknown.
base
readonlybase:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:635
Experimental
The generation of the base it can be compared with, null: none.
clients
readonlyclients: readonlynumber[]
Defined in: packages/lexical-y/src/internal/Server.ts:625
Experimental
Every client id the replica wrote under since its last sync with the authority (persisted with its partition; ids Yjs switched to after a collision and those of writers sharing its document included). What the replica wrote under another id is not proved its own.
collisions
readonlycollisions: readonlyYLegacySignal[]
Defined in: packages/lexical-y/src/internal/Server.ts:642
Experimental
Signals whose id holds other content (the replica's own): kept.
complete
readonlycomplete:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:647
Experimental
Whether the source view has every dependency (see sourceView).
deltas
readonlydeltas: readonlyUint8Array<ArrayBufferLike>[]
Defined in: packages/lexical-y/src/internal/Server.ts:630
Experimental
Later updates of a captured session.
draft
readonlydraft:YDraft|null
Defined in: packages/lexical-y/src/internal/Server.ts:633
Experimental
hash
readonlyhash:string
Defined in: packages/lexical-y/src/internal/Server.ts:645
Experimental
A hash of the material (what an acknowledgement names).
id
readonlyid:string
Defined in: packages/lexical-y/src/internal/Server.ts:607
Experimental
The record's id: its hash unless given.
kind
readonlykind:"capture"|"pending"|"handoff"
Defined in: packages/lexical-y/src/internal/Server.ts:610
Experimental
peers
readonlypeers:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:618
Experimental
Whether any channel other than the authority could have delivered updates to the replica since its last sync with the authority (a property of the material's history, persisted with the replica's partition; unknown is true). A replica with peers can hold a deletion the authority never saw.
queue
readonlyqueue: readonlyUint8Array<ArrayBufferLike>[]
Defined in: packages/lexical-y/src/internal/Server.ts:632
Experimental
The replica's queue of unsent updates.
receivedAt
readonlyreceivedAt:number
Defined in: packages/lexical-y/src/internal/Server.ts:643
Experimental
replica
readonlyreplica:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:609
Experimental
session
readonlysession:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:608
Experimental
signals
readonlysignals: readonlyYLegacySignal[]
Defined in: packages/lexical-y/src/internal/Server.ts:640
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:628
Experimental
The replica's whole document (V1), standalone.
source
readonlysource:YRecordSource
Defined in: packages/lexical-y/src/internal/Server.ts:626
Experimental
YQuarantineRecordInput
Defined in: packages/lexical-y/src/internal/Server.ts:653
Experimental
The input of quarantineRecord.
Properties
clients?
readonlyoptionalclients?: readonlynumber[]
Defined in: packages/lexical-y/src/internal/Server.ts:661
Experimental
Default none.
deltas?
readonlyoptionaldeltas?: readonlyUint8Array<ArrayBufferLike>[]
Defined in: packages/lexical-y/src/internal/Server.ts:664
Experimental
draft?
readonlyoptionaldraft?:YDraft|null
Defined in: packages/lexical-y/src/internal/Server.ts:666
Experimental
id?
readonlyoptionalid?:string
Defined in: packages/lexical-y/src/internal/Server.ts:654
Experimental
kind
readonlykind:"capture"|"pending"|"handoff"
Defined in: packages/lexical-y/src/internal/Server.ts:657
Experimental
peers?
readonlyoptionalpeers?:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:659
Experimental
Default true (unknown provenance).
queue?
readonlyoptionalqueue?: readonlyUint8Array<ArrayBufferLike>[]
Defined in: packages/lexical-y/src/internal/Server.ts:665
Experimental
receivedAt
readonlyreceivedAt:number
Defined in: packages/lexical-y/src/internal/Server.ts:668
Experimental
replica?
readonlyoptionalreplica?:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:656
Experimental
session?
readonlyoptionalsession?:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:655
Experimental
signals?
readonlyoptionalsignals?: readonlyYLegacySignal[]
Defined in: packages/lexical-y/src/internal/Server.ts:667
Experimental
snapshot?
readonlyoptionalsnapshot?:Uint8Array<ArrayBufferLike> |null
Defined in: packages/lexical-y/src/internal/Server.ts:663
Experimental
source
readonlysource:YRecordSource
Defined in: packages/lexical-y/src/internal/Server.ts:662
Experimental
YRecordSource
Defined in: packages/lexical-y/src/internal/Server.ts:584
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:586
Experimental
incarnation
readonlyincarnation:string|null
Defined in: packages/lexical-y/src/internal/Server.ts:585
Experimental
layouts
readonlylayouts: readonly [number,number] |null
Defined in: packages/lexical-y/src/internal/Server.ts:588
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:591
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:589
Experimental
YRoomDescription
Defined in: packages/lexical-y/src/internal/Server.ts:179
Experimental
The room as checkYSession sees it (see describeYRoom).
Properties
generation
readonlygeneration:string
Defined in: packages/lexical-y/src/internal/Server.ts:180
Experimental
incarnation
readonlyincarnation:string
Defined in: packages/lexical-y/src/internal/Server.ts:181
Experimental
inherited
readonlyinherited:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:186
Experimental
Whether the incarnation was inherited: assigned to a room that already existed when the fence was deployed.
layouts
readonlylayouts: readonly [number,number] |null
Defined in: packages/lexical-y/src/internal/Server.ts:194
Experimental
The lowest and highest layouts the served roots record, null when none
does. A client must read every served root: both bounds inside its
layouts.
pristine
readonlypristine:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:188
Experimental
Whether the room has no state at all (never seeded).
seedContract
readonlyseedContract:number
Defined in: packages/lexical-y/src/internal/Server.ts:205
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).
unreadable
readonlyunreadable: readonlystring[]
Defined in: packages/lexical-y/src/internal/Server.ts:199
Experimental
Served roots with content but no well-formed layout record (missing or malformed) or with a malformed epoch: no client reads them.
YSessionCapture
Defined in: packages/lexical-y/src/internal/Server.ts:385
Experimental
What a legacy capture sends and keeps (see captureYSession).
Properties
messages
readonlymessages: readonlyUint8Array<ArrayBufferLike>[]
Defined in: packages/lexical-y/src/internal/Server.ts:397
Experimental
The same two as y-websocket messages (messageSync framing), in order.
syncStep1
readonlysyncStep1:Uint8Array
Defined in: packages/lexical-y/src/internal/Server.ts:395
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:390
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:402
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:414
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:416
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:409
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:171
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:172
Experimental
layouts
readonlylayouts: readonly [number,number]
Defined in: packages/lexical-y/src/internal/Server.ts:174
Experimental
material
readonlymaterial:boolean
Defined in: packages/lexical-y/src/internal/Server.ts:173
Experimental
seed
readonlyseed:number
Defined in: packages/lexical-y/src/internal/Server.ts:175
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:269
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:161
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:431
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:311
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), a served root's layout outside the client's
layouts(or a served root without a well-formed record), a pristine room whose seed contract is not the client'sseed: stale. No client holding material is refused before its material is acknowledged. - A served root'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:209
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:46
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:830
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:512
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:261
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
pendingYRecord()
pendingYRecord(
input,base?):YQuarantineRecord
Defined in: packages/lexical-y/src/internal/Server.ts:796
Experimental
The quarantine record of a migration's pending material
(prepareYRoom's or migrateYState's), stored atomically with the migrated
state: kind 'pending', its snapshot the whole stored state it was split
from (which still holds every cut item and what they depend on) and its
queue the split bytes, so its source view renders the cut material in
place, and a raw export of the record carries both. The stored state may
itself lack updates (a skipped range): the record is then incomplete
until they arrive (append them as deltas). base, as for
quarantineRecord: the migrated state, which lacks the cut items.
Parameters
input
id?
string
pending
The split material (pending).
receivedAt
number
source
stored
The stored state the material was split from.
base?
{ generation: string; state: Uint8Array; } | null
Returns
prepareYRoom()
prepareYRoom(
stored,options):YPreparedRoom
Defined in: packages/lexical-y/src/internal/Server.ts:119
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:736
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:709
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