Skip to main content

@lexical/y/server

Interfaces​

YDraft​

Defined in: packages/lexical-y/src/internal/Server.ts:636

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​

readonly differs: boolean

Defined in: packages/lexical-y/src/internal/Server.ts:638

Experimental

json​

readonly json: unknown

Defined in: packages/lexical-y/src/internal/Server.ts:637

Experimental


YLegacySignal​

Defined in: packages/lexical-y/src/internal/Server.ts:413

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​

readonly client: number

Defined in: packages/lexical-y/src/internal/Server.ts:415

Experimental

clock​

readonly clock: number

Defined in: packages/lexical-y/src/internal/Server.ts:416

Experimental

key​

readonly key: string

Defined in: packages/lexical-y/src/internal/Server.ts:418

Experimental

root​

readonly root: string

Defined in: packages/lexical-y/src/internal/Server.ts:417

Experimental

update​

readonly update: Uint8Array

Defined in: packages/lexical-y/src/internal/Server.ts:414

Experimental


YPreparedRoom​

Defined in: packages/lexical-y/src/internal/Server.ts:100

Experimental

What prepareYRoom returns.

Properties​

base​

readonly base: { generation: string; state: Uint8Array; } | null

Defined in: packages/lexical-y/src/internal/Server.ts:111

Experimental

When changed: the stored state and its generation, to keep as the immutable base of that generation (bases[generation] = state).

changed​

readonly changed: boolean

Defined in: packages/lexical-y/src/internal/Server.ts:102

Experimental

Whether the state was migrated (store the result) or not (store nothing).

generation​

readonly generation: string

Defined in: packages/lexical-y/src/internal/Server.ts:106

Experimental

Its generation (see generationOf).

pending​

readonly pending: Uint8Array<ArrayBufferLike> | null

Defined in: packages/lexical-y/src/internal/Server.ts:116

Experimental

Pending material split out of the stored state, for a pending record.

receipt​

readonly receipt: YMigrationReceipt

Defined in: packages/lexical-y/src/internal/Server.ts:117

Experimental

state​

readonly state: Uint8Array

Defined in: packages/lexical-y/src/internal/Server.ts:104

Experimental

The state to serve: the stored bytes themselves when nothing changed.


YPrepareRoomOptions​

Defined in: packages/lexical-y/src/internal/Server.ts:79

Experimental

Options of prepareYRoom.

Properties​

clientID?​

readonly optional clientID?: (input) => number

Defined in: packages/lexical-y/src/internal/Server.ts:91

Experimental

Parameters​
input​
revision​

number

root​

string

step​

string

to​

number

Returns​

number

clientIDRange?​

readonly optional clientIDRange?: ClientIDRange

Defined in: packages/lexical-y/src/internal/Server.ts:90

Experimental

gc?​

readonly optional gc?: boolean

Defined in: packages/lexical-y/src/internal/Server.ts:87

Experimental

Garbage collection of its stored documents (default true).

incarnation​

readonly incarnation: string

Defined in: packages/lexical-y/src/internal/Server.ts:83

Experimental

The room's incarnation (see generationOf).

roots?​

readonly optional roots?: readonly string[]

Defined in: packages/lexical-y/src/internal/Server.ts:85

Experimental

The roots it serves (default ['lexical-y']).

steps​

readonly steps: readonly YLayoutMigration[]

Defined in: packages/lexical-y/src/internal/Server.ts:81

Experimental

The steps the authority ships (statically imported).

to?​

readonly optional to?: number

Defined in: packages/lexical-y/src/internal/Server.ts:89

Experimental

The target (default MIN_LAYOUT: only roots below the floor migrate).


YQuarantineRecord​

Defined in: packages/lexical-y/src/internal/Server.ts:642

Experimental

A per-document quarantine record (append-only).

Properties​

actionable​

readonly actionable: boolean

Defined in: packages/lexical-y/src/internal/Server.ts:690

Experimental

Whether it holds anything new (see hasNewYEdits); true when unknown.

base​

readonly base: string | null

Defined in: packages/lexical-y/src/internal/Server.ts:672

Experimental

The generation of the base it can be compared with, null: none.

clients​

readonly clients: readonly number[]

Defined in: packages/lexical-y/src/internal/Server.ts:662

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​

readonly collisions: readonly YLegacySignal[]

Defined in: packages/lexical-y/src/internal/Server.ts:679

Experimental

Signals whose id holds other content (the replica's own): kept.

complete​

readonly complete: boolean

Defined in: packages/lexical-y/src/internal/Server.ts:688

Experimental

Whether the source view has every dependency (see sourceView).

deltas​

readonly deltas: readonly Uint8Array<ArrayBufferLike>[]

Defined in: packages/lexical-y/src/internal/Server.ts:667

Experimental

Later updates of a captured session.

draft​

readonly draft: YDraft | null

Defined in: packages/lexical-y/src/internal/Server.ts:670

Experimental

hash​

readonly hash: string

Defined in: packages/lexical-y/src/internal/Server.ts:686

Experimental

A hash of the record's kind, material (snapshot, deltas, queue, draft) and provenance (peers, clients): what an acknowledgement names. The source, session, replica and times are not in it.

id​

readonly id: string

Defined in: packages/lexical-y/src/internal/Server.ts:644

Experimental

The record's id: its hash unless given.

kind​

readonly kind: "capture" | "pending" | "handoff"

Defined in: packages/lexical-y/src/internal/Server.ts:647

Experimental

peers​

readonly peers: boolean

Defined in: packages/lexical-y/src/internal/Server.ts:655

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​

readonly queue: readonly Uint8Array<ArrayBufferLike>[]

Defined in: packages/lexical-y/src/internal/Server.ts:669

Experimental

The replica's queue of unsent updates.

receivedAt​

readonly receivedAt: number

Defined in: packages/lexical-y/src/internal/Server.ts:680

Experimental

replica​

readonly replica: string | null

Defined in: packages/lexical-y/src/internal/Server.ts:646

Experimental

session​

readonly session: string | null

Defined in: packages/lexical-y/src/internal/Server.ts:645

Experimental

signals​

readonly signals: readonly YLegacySignal[]

Defined in: packages/lexical-y/src/internal/Server.ts:677

Experimental

Legacy signals the authority built for this session (exact payloads): their items are ignored where id, parent, key and content all match.

snapshot​

readonly snapshot: Uint8Array<ArrayBufferLike> | null

Defined in: packages/lexical-y/src/internal/Server.ts:665

Experimental

The replica's whole document (V1), standalone.

source​

readonly source: YRecordSource

Defined in: packages/lexical-y/src/internal/Server.ts:663

Experimental


YQuarantineRecordInput​

Defined in: packages/lexical-y/src/internal/Server.ts:694

Experimental

The input of quarantineRecord.

Properties​

clients?​

readonly optional clients?: readonly number[]

Defined in: packages/lexical-y/src/internal/Server.ts:702

Experimental

Default none; kept once each, in order.

deltas?​

readonly optional deltas?: readonly Uint8Array<ArrayBufferLike>[]

Defined in: packages/lexical-y/src/internal/Server.ts:705

Experimental

draft?​

readonly optional draft?: YDraft | null

Defined in: packages/lexical-y/src/internal/Server.ts:707

Experimental

id?​

readonly optional id?: string

Defined in: packages/lexical-y/src/internal/Server.ts:695

Experimental

kind​

readonly kind: "capture" | "pending" | "handoff"

Defined in: packages/lexical-y/src/internal/Server.ts:698

Experimental

peers?​

readonly optional peers?: boolean

Defined in: packages/lexical-y/src/internal/Server.ts:700

Experimental

Default true (unknown provenance).

queue?​

readonly optional queue?: readonly Uint8Array<ArrayBufferLike>[]

Defined in: packages/lexical-y/src/internal/Server.ts:706

Experimental

receivedAt​

readonly receivedAt: number

Defined in: packages/lexical-y/src/internal/Server.ts:709

Experimental

replica?​

readonly optional replica?: string | null

Defined in: packages/lexical-y/src/internal/Server.ts:697

Experimental

session?​

readonly optional session?: string | null

Defined in: packages/lexical-y/src/internal/Server.ts:696

Experimental

signals?​

readonly optional signals?: readonly YLegacySignal[]

Defined in: packages/lexical-y/src/internal/Server.ts:708

Experimental

snapshot?​

readonly optional snapshot?: Uint8Array<ArrayBufferLike> | null

Defined in: packages/lexical-y/src/internal/Server.ts:704

Experimental

source​

readonly source: YRecordSource

Defined in: packages/lexical-y/src/internal/Server.ts:703

Experimental


YRecordSource​

Defined in: packages/lexical-y/src/internal/Server.ts:621

Experimental

Where a quarantine record's material came from (null: unknown).

Properties​

generation​

readonly generation: string | null

Defined in: packages/lexical-y/src/internal/Server.ts:623

Experimental

incarnation​

readonly incarnation: string | null

Defined in: packages/lexical-y/src/internal/Server.ts:622

Experimental

layouts​

readonly layouts: readonly [number, number] | null

Defined in: packages/lexical-y/src/internal/Server.ts:625

Experimental

The layouts the source's release reads ([MIN_LAYOUT, LAYOUT_VERSION]).

renderer​

readonly renderer: string | null

Defined in: packages/lexical-y/src/internal/Server.ts:628

Experimental

The app's renderer (a release name) that can show the source.

schemaVersion​

readonly schemaVersion: number | null

Defined in: packages/lexical-y/src/internal/Server.ts:626

Experimental


YRoomDescription​

Defined in: packages/lexical-y/src/internal/Server.ts:189

Experimental

The room as checkYSession sees it (see describeYRoom).

Properties​

generation​

readonly generation: string

Defined in: packages/lexical-y/src/internal/Server.ts:190

Experimental

incarnation​

readonly incarnation: string

Defined in: packages/lexical-y/src/internal/Server.ts:191

Experimental

inherited​

readonly inherited: boolean

Defined in: packages/lexical-y/src/internal/Server.ts:196

Experimental

Whether the incarnation was inherited: assigned to a room that already existed when the fence was deployed.

layouts​

readonly layouts: readonly [number, number] | null

Defined in: packages/lexical-y/src/internal/Server.ts:204

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​

readonly pristine: boolean

Defined in: packages/lexical-y/src/internal/Server.ts:198

Experimental

Whether the room has no state at all (never seeded).

seedContract​

readonly seedContract: number

Defined in: packages/lexical-y/src/internal/Server.ts:215

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​

readonly unreadable: readonly string[]

Defined in: packages/lexical-y/src/internal/Server.ts:209

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:422

Experimental

What a legacy capture sends and keeps (see captureYSession).

Properties​

messages​

readonly messages: readonly Uint8Array<ArrayBufferLike>[]

Defined in: packages/lexical-y/src/internal/Server.ts:434

Experimental

The same two as y-websocket messages (messageSync framing), in order.

syncStep1​

readonly syncStep1: Uint8Array

Defined in: packages/lexical-y/src/internal/Server.ts:432

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​

readonly syncStep2: Uint8Array

Defined in: packages/lexical-y/src/internal/Server.ts:427

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:439

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​

Uint8Array

Returns​

void

collisions()​

collisions(): YLegacySignal[]

Defined in: packages/lexical-y/src/internal/Server.ts:451

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​

YLegacySignal[]

material()​

material(): object

Defined in: packages/lexical-y/src/internal/Server.ts:453

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:446

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:181

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​

readonly generation: string | null

Defined in: packages/lexical-y/src/internal/Server.ts:182

Experimental

layouts​

readonly layouts: readonly [number, number]

Defined in: packages/lexical-y/src/internal/Server.ts:184

Experimental

material​

readonly material: boolean

Defined in: packages/lexical-y/src/internal/Server.ts:183

Experimental

seed​

readonly seed: number

Defined in: packages/lexical-y/src/internal/Server.ts:185

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:279

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​

const UNKNOWN_GENERATION: "unknown" = 'unknown'

Defined in: packages/lexical-y/src/internal/Server.ts:171

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:468

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​

YSessionCapture


checkYSession()​

checkYSession(room, client): YSessionVerdict

Defined in: packages/lexical-y/src/internal/Server.ts:345

Experimental

The handshake verdict for a session (y-server.md "Migrating stored documents"): the first row that matches wins.

  1. No handshake (client null, 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.
  2. 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's seed: stale. No client holding material is refused before its material is acknowledged.
  3. A served root's layout outside layouts: refuse-layout.
  4. A pristine room whose seed contract is not seed: refuse-layout.
  5. The room's generation: admit (initialize in a pristine room).
  6. No material: bootstrap (initialize in a pristine room). A handshake that is not well formed (it arrives from the network: a generation that is neither a string nor null, a non-boolean material, layouts that are not two layouts from 1 in order, a seed that is not a layout) is 'refuse-layout'. Never sync a session whose verdict is not 'admit', and check every update again at commit against the room's current generation.

Parameters​

room​

YRoomDescription

client​

YSessionHandshake | null

Returns​

YSessionVerdict


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?​

DocOpts

Returns​

YDoc


describeYRoom()​

describeYRoom(doc, options): YRoomDescription

Defined in: packages/lexical-y/src/internal/Server.ts:219

Experimental

Describe a room's document for checkYSession.

Parameters​

doc​

Doc

options​
incarnation​

string

inherited​

boolean

roots?​

readonly string[]

seedContract​

number

The SEED_LAYOUT the room's incarnation was issued under.

Returns​

YRoomDescription


generationOf()​

generationOf(doc, incarnation, roots?): string

Defined in: packages/lexical-y/src/internal/Server.ts:56

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​

Doc

incarnation​

string

roots?​

readonly string[] = ...

Returns​

string


hasNewYEdits()​

hasNewYEdits(record, base): boolean

Defined in: packages/lexical-y/src/internal/Server.ts:877

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​

Uint8Array

Returns​

boolean


legacySignal()​

legacySignal(snapshot, supportedSchema, root?): YLegacySignal

Defined in: packages/lexical-y/src/internal/Server.ts:549

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​

Uint8Array

supportedSchema​

number

root?​

string = DEFAULT_ROOT_NAME

Returns​

YLegacySignal


needsNewIncarnation()​

needsNewIncarnation(room, seedLayout): boolean

Defined in: packages/lexical-y/src/internal/Server.ts:271

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​

YRoomDescription

seedLayout​

number

Returns​

boolean


pendingYRecord()​

pendingYRecord(input, base?): YQuarantineRecord

Defined in: packages/lexical-y/src/internal/Server.ts:843

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​

Uint8Array

The split material (pending).

receivedAt​

number

source​

YRecordSource

stored​

Uint8Array

The stored state the material was split from.

base?​

{ generation: string; state: Uint8Array; } | null

Returns​

YQuarantineRecord


prepareYRoom()​

prepareYRoom(stored, options): YPreparedRoom

Defined in: packages/lexical-y/src/internal/Server.ts:129

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​

Uint8Array

options​

YPrepareRoomOptions

Returns​

YPreparedRoom


quarantineRecord()​

quarantineRecord(input, base?): YQuarantineRecord

Defined in: packages/lexical-y/src/internal/Server.ts:777

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​

YQuarantineRecordInput

base?​

{ generation: string; state: Uint8Array; } | null

Returns​

YQuarantineRecord


sourceView()​

sourceView(record): object

Defined in: packages/lexical-y/src/internal/Server.ts:750

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​

LAYOUT_VERSION​

Re-exports LAYOUT_VERSION


MIN_LAYOUT​

Re-exports MIN_LAYOUT


SEED_LAYOUT​

Re-exports SEED_LAYOUT


YDoc​

Re-exports YDoc


YDocOptions​

Re-exports YDocOptions