Skip to main content

@lexical/y/server

Interfaces​

YDraft​

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

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

Experimental

json​

readonly json: unknown

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

Experimental


YLegacySignal​

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

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

Experimental

clock​

readonly clock: number

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

Experimental

key​

readonly key: string

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

Experimental

root​

readonly root: string

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

Experimental

update​

readonly update: Uint8Array

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

Experimental


YPendingRecordInput​

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

Experimental

The input of createYQuarantineRecord for a migration's pending material (stored and pending are reserved for this form: it is taken only for kind 'pending' with both present as bytes; any other kind ignores them). The form is exclusive: beside them it takes only id, source, receivedAt and the header; any field of the material form (a draft, requires, signals, peers, clients, a session or replica, other material) is refused: give such a record in the material form (prepareYRoom's or migrateYState's), stored atomically with the migrated state: the record's kind is 'pending', its snapshot the whole stored state the material 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 carries both. The stored state may itself lack updates (a skipped range): the record is then incomplete until they arrive (append them as deltas). Its base is the migrated state, which lacks the cut items.

Properties​

id?​

readonly optional id?: string

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

Experimental

kind​

readonly kind: "pending"

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

Experimental

pending​

readonly pending: Uint8Array

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

Experimental

The split material (pending).

receivedAt​

readonly receivedAt: number

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

Experimental

source​

readonly source: YRecordSource

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

Experimental

stored​

readonly stored: Uint8Array

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

Experimental

The stored state the material was split from.

updateFormat?​

readonly optional updateFormat?: "yjs-v1"

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

Experimental

v?​

readonly optional v?: 1

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

Experimental

As YQuarantineRecordInput's: absent, or version 1, 'yjs-v1'.


YPreparedRoom​

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

Experimental

What prepareYRoom returns.

Properties​

base​

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

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

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

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

Experimental

Its generation (see getYGeneration).

pending​

readonly pending: Uint8Array<ArrayBufferLike> | null

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

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

Experimental

state​

readonly state: Uint8Array

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

Experimental

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


YPrepareRoomOptions​

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

Experimental

Options of prepareYRoom.

Properties​

clientID?​

readonly optional clientID?: (input) => number

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

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

Experimental

gc?​

readonly optional gc?: boolean

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

Experimental

Garbage collection of its stored documents (default true).

incarnation​

readonly incarnation: string

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

Experimental

The room's incarnation (see getYGeneration).

roots?​

readonly optional roots?: readonly string[]

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

Experimental

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

steps?​

readonly optional steps?: readonly YLayoutMigration[]

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

Experimental

The steps the authority runs (default: every published step, statically imported with the server entry).

to?​

readonly optional to?: number

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

Experimental

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


YQuarantineRecord​

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

Experimental

A per-document quarantine record (version 1; the room's records are append-only).

Properties​

actionable​

readonly actionable: boolean

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

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

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

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

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

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

Experimental

Later updates of a captured session.

draft​

readonly draft: YDraft | null

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

Experimental

hash​

readonly hash: string

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

Experimental

The hash of the record's canonical payload, version 1: 'yr1-sha256:' and the lowercase hex SHA-256 of its kind, source (provenance, incarnation and generation included), peers, clients, snapshot, deltas, queue, draft (canonical JSON, keys sorted), signal transcripts, requirements and format (see y-server.md, "Records"). Not in it: the id, session, replica, times and what the server derives (base, complete, actionable, collisions). Equal hashes are not proof of equal records: confirm the exact payload before discarding either. An acknowledgement names it within its scope (see YRecordAcknowledgement).

id​

readonly id: string

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

Experimental

The record's id: its hash unless given.

kind​

readonly kind: YQuarantineRecordKind

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

Experimental

peers​

readonly peers: boolean

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

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

Experimental

The replica's queue of unsent updates.

receivedAt​

readonly receivedAt: number

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

Experimental

replica​

readonly replica: string | null

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

Experimental

requires​

readonly requires: readonly string[]

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

Experimental

Features its material needs to be read (see YRoomDescription's requires), sorted by code units, each once; none by default. A record that requires a feature this release does not know is kept and exported as it is, never read as one it knows.

session​

readonly session: string | null

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

Experimental

signals​

readonly signals: readonly YLegacySignal[]

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

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

Experimental

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

source​

readonly source: YRecordSource

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

Experimental

updateFormat​

readonly updateFormat: "yjs-v1"

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

Experimental

The encoding of snapshot, deltas, queue and signal updates: Yjs update format V1.

v​

readonly v: 1

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

Experimental

The record format's version.


YQuarantineRecordInput​

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

Experimental

The input of createYQuarantineRecord: a record's material as a replica or a capture handed it over.

Properties​

clients?​

readonly optional clients?: readonly number[]

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

Experimental

Default none; kept once each, in order.

deltas?​

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

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

Experimental

draft?​

readonly optional draft?: YDraft | null

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

Experimental

id?​

readonly optional id?: string

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

Experimental

kind​

readonly kind: YQuarantineRecordKind

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

Experimental

peers?​

readonly optional peers?: boolean

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

Experimental

Default true (unknown provenance).

queue?​

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

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

Experimental

receivedAt​

readonly receivedAt: number

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

Experimental

replica?​

readonly optional replica?: string | null

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

Experimental

requires?​

readonly optional requires?: readonly string[]

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

Experimental

Default none; kept once each, sorted.

session?​

readonly optional session?: string | null

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

Experimental

signals?​

readonly optional signals?: readonly YLegacySignal[]

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

Experimental

snapshot?​

readonly optional snapshot?: Uint8Array<ArrayBufferLike> | null

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

Experimental

source​

readonly source: YRecordSource

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

Experimental

updateFormat?​

readonly optional updateFormat?: "yjs-v1"

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

Experimental

v?​

readonly optional v?: 1

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

Experimental

The material's version and update format, when it carries them (a capture's material does): only version 1, 'yjs-v1', is accepted, so material of another format is never stamped as version 1.


YRecordAcknowledgement​

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

Experimental

The durable acknowledgement of one record, version 1: the server holds it only once the record is stored durably. It acknowledges exactly the uploaded payload, in its scope: the room, the replica that uploaded it, the generation its material was made against (source.generation, 'unknown' when none), the record's id and hash. A replica drops its material only for an acknowledgement whose every field matches what it uploaded; a bare hash, or one from another room, replica or generation, acknowledges nothing, and an acknowledgement of an unknown version keeps the material.

Properties​

hash​

readonly hash: string

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

Experimental

record​

readonly record: string

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

Experimental

replica​

readonly replica: string

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

Experimental

room​

readonly room: string

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

Experimental

sourceGeneration​

readonly sourceGeneration: string

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

Experimental

v​

readonly v: 1

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

Experimental


YRecordSource​

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

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

Experimental

incarnation​

readonly incarnation: string | null

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

Experimental

layouts​

readonly layouts: readonly [number, number] | null

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

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

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

Experimental


YRoomDescription​

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

Experimental

The room as checkYSession sees it (see describeYRoom).

Properties​

generation​

readonly generation: string

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

Experimental

hasMigration​

readonly hasMigration: boolean

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

Experimental

Whether a served root records an epoch (a migration ran on it), or a malformed one: a client from before the fence is then never admitted.

incarnation​

readonly incarnation: string

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

Experimental

inherited​

readonly inherited: boolean

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

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

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

Experimental

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

requires​

readonly requires: readonly string[]

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

Experimental

The features the served roots require (lexical-y-require:<feature> set to true), sorted by code units, each once. A client must present every one of them (see checkYSession). A malformed requirement makes its root unreadable instead.

seedContract​

readonly seedContract: number

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

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

Experimental

Served roots with content but no well-formed layout record (missing or malformed), with a malformed epoch or with a malformed requirement: no client reads them.


YSessionCapture​

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

Experimental

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

Properties​

messages​

readonly messages: readonly Uint8Array<ArrayBufferLike>[]

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

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

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

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

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

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(): YSessionCaptureMaterial

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

Experimental

The material kept so far (version 1, copies): persist it as it is to resume the capture later (createYSessionCapture's resume), or build the session's record from it (createYQuarantineRecord).

Returns​

YSessionCaptureMaterial

signal()​

signal(supportedSchema, root?): YLegacySignal | null

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

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


YSessionCaptureMaterial​

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

Experimental

A legacy capture's material, version 1: the session's standalone snapshot (null until its sync step 2 arrives), its later updates and the signals sent to it, all Yjs update format V1. Persist it whole, v and updateFormat included: a capture resumes only material of a version and format it reads, and leaves any other untouched.

Properties​

deltas​

readonly deltas: readonly Uint8Array<ArrayBufferLike>[]

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

Experimental

signals​

readonly signals: readonly YLegacySignal[]

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

Experimental

snapshot​

readonly snapshot: Uint8Array<ArrayBufferLike> | null

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

Experimental

updateFormat​

readonly updateFormat: "yjs-v1"

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

Experimental

v​

readonly v: 1

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

Experimental


YSessionHandshake​

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

Experimental

What a client sends before any sync message (version 1): 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]), the layout its seed records (SEED_LAYOUT) and the features it implements (see YRoomDescription's requires; default none). v is required: a handshake without it, or with another version, is malformed (refuse-layout); no handshake at all (null) is the legacy route. Unknown fields are ignored: a later version that needs new semantics negotiates them with a feature or a new v.

Properties​

features?​

readonly optional features?: readonly string[]

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

Experimental

generation​

readonly generation: string | null

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

Experimental

layouts​

readonly layouts: readonly [number, number]

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

Experimental

material​

readonly material: boolean

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

Experimental

seed​

readonly seed: number

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

Experimental

v​

readonly v: 1

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

Experimental

Type Aliases​

YQuarantineRecordKind​

YQuarantineRecordKind = "handoff" | "capture" | "pending" | string & object

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

Experimental

What a record holds: a stale replica's handoff, a legacy session's capture, or a migration's pending material. Open: a later release may add kinds; a record of a kind this release does not know is kept and exported as it is (preservation only), never read, replayed or judged as one it knows.


YSessionVerdict​

YSessionVerdict = { initialize: boolean; reason?: string; verdict: "admit"; } | { initialize: boolean; reason?: string; verdict: "bootstrap"; } | { reason?: string; verdict: "stale"; } | { reason?: string; verdict: "refuse-layout"; } | { reason?: string; verdict: "legacy"; }

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

Experimental

checkYSession's verdict (y-server.md, the handshake table). The five verdicts are permanent. reason is an optional explanation for logs and diagnostics (open: new reasons may be added; never branch on it): 'malformed-handshake', 'generation', 'layout', 'seed', 'requires', 'unreadable', 'migrated', 'not-inherited'.

Union Members​

Type Literal​

{ initialize: boolean; reason?: string; verdict: "admit"; }

Sync both ways. initialize: the room is pristine and the client may seed it.


Type Literal​

{ initialize: boolean; reason?: string; 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​

{ reason?: string; 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​

{ reason?: string; verdict: "refuse-layout"; }

The client cannot read, seed or meet the requirements of the room: reload to another release.


Type Literal​

{ reason?: string; verdict: "legacy"; }

No handshake on a room it may not join: capture (createYSessionCapture).

Variables​

UNKNOWN_GENERATION​

const UNKNOWN_GENERATION: "unknown" = 'unknown'

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

Experimental

A generation that never matches: a replica's material with no recorded generation (from before the fence), or a state whose served root has a malformed epoch (see getYGeneration).

Functions​

checkYSession()​

checkYSession(room, client): YSessionVerdict

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

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, it never migrated (no epoch, hasMigration false) or was replaced (a new incarnation is never inherited), it requires no feature and every served root is readable; otherwise legacy.
  2. A handshake that is not well formed (it arrives from the network: no v or another version, features that are not strings, 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): refuse-layout.
  3. 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 that is unreadable), a pristine room whose seed contract is not the client's seed, a required feature the client does not present: stale. No client holding material is refused before its material is acknowledged.
  4. A served root's layout outside layouts, or an unreadable root: refuse-layout.
  5. A required feature the client does not present: refuse-layout.
  6. A pristine room whose seed contract is not seed: refuse-layout.
  7. The room's generation: admit (initialize in a pristine room).
  8. No material: bootstrap (initialize in 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​

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


createYQuarantineRecord()​

createYQuarantineRecord(input, base?): YQuarantineRecord

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

Experimental

Build a quarantine record (version 1), from a replica's or a capture's material (YQuarantineRecordInput) or from a migration's pending material (YPendingRecordInput): its hash (of its canonical payload, see YQuarantineRecord's hash), whether its source view is complete, and, when base is given (the state of the base generation), whether it holds anything new (a struct or a deletion the base lacks, a draft marked differs, or a missing dependency; without a base, or when it requires a feature, it counts as actionable). Throws a TypeError when the draft is not JSON: keep the material and report it.

Parameters​

input​

YPendingRecordInput | YQuarantineRecordInput

base?​

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

Returns​

YQuarantineRecord


createYSessionCapture()​

createYSessionCapture(resume?): YSessionCapture

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

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 createYQuarantineRecord. resume: the material (material()) an earlier capture of the same session kept, for an authority that persists it between messages (a hibernating Durable Object); the capture continues from it (its signals included). Material of another version or update format is refused with a TypeError before any of it is read, and left as it is (keep it, export it raw).

Parameters​

resume?​

YSessionCaptureMaterial | null

Returns​

YSessionCapture


describeYRoom()​

describeYRoom(doc, options): YRoomDescription

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

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


getYGeneration()​

getYGeneration(doc, incarnation, roots?): string

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

Experimental

The generation of a document's state over the roots an authority serves, by version 1 of the algorithm (frozen): 'g1:' + JSON.stringify([incarnation, entries]), where entries has one [root, transition] pair per served root (every one, sorted by code units, each once): transition is the [client, clock] of the root's epoch (the identity of the transition that last migrated it), or null when it has none. The epoch's layout and other fields are not part of it. A served root whose epoch is malformed has no generation: the result is then UNKNOWN_GENERATION, which never matches (fail closed). 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. Opaque: compare and persist it; never parse it (carry the incarnation explicitly where it is needed).

Parameters​

doc​

Doc

incarnation​

string

roots?​

readonly string[] = ...

Returns​

string


prepareYRoom()​

prepareYRoom(stored, options): YPreparedRoom

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

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


sourceView()​

sourceView(record): object

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

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 rendering, export of a readable form and replay read. It takes the record (or its header and material: v, updateFormat, kind, requires) and reads only a record this release reads: version 1, update format 'yjs-v1', a kind it knows and no feature it does not support. Any other record is refused with a TypeError before any of its bytes are applied: keep it and export it raw.

Parameters​

record​

Pick<YQuarantineRecord, "v" | "updateFormat" | "kind" | "requires" | "snapshot" | "deltas" | "queue">

Returns​

object

complete​

complete: boolean

doc​

doc: Doc

References​

createYServerLayoutUpgrade​

Re-exports createYServerLayoutUpgrade


isYLayoutUpgradeHandle​

Re-exports isYLayoutUpgradeHandle


LAYOUT_VERSION​

Re-exports LAYOUT_VERSION


MIN_LAYOUT​

Re-exports MIN_LAYOUT


SEED_LAYOUT​

Re-exports SEED_LAYOUT


YClientSession​

Re-exports YClientSession


YDoc​

Re-exports YDoc


YDocOptions​

Re-exports YDocOptions


YLayoutUpgradeHandle​

Re-exports YLayoutUpgradeHandle