Skip to main content

@lexical/y/migrate

Classes​

YMigrationError​

Defined in: packages/lexical-y/src/internal/Runner.ts:140

Experimental

A migration refused or failed. Nothing was written: the caller's document and stored state are as they were.

Extends​

Constructors​

Constructor​

new YMigrationError(code, message, problems?, root?): YMigrationError

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

Experimental

Parameters​
code​

YMigrationErrorCode

message​

string

problems?​

readonly string[] = []

root?​

string | null

Returns​

YMigrationError

Overrides​

Error.constructor

Properties​

cause?​

optional cause?: unknown

Defined in: typescript/lib/lib.es2022.error.d.ts:24

Experimental

Inherited from​

Error.cause

code​

readonly code: YMigrationErrorCode

Defined in: packages/lexical-y/src/internal/Runner.ts:141

Experimental

message​

message: string

Defined in: typescript/lib/lib.es5.d.ts:1075

Experimental

Inherited from​

Error.message

name​

name: string

Defined in: typescript/lib/lib.es5.d.ts:1074

Experimental

Inherited from​

Error.name

problems​

readonly problems: readonly string[]

Defined in: packages/lexical-y/src/internal/Runner.ts:143

Experimental

Every problem found (for 'post-condition', every failed check).

root​

readonly root: string | null

Defined in: packages/lexical-y/src/internal/Runner.ts:145

Experimental

The root concerned, null when the whole document is.

stack?​

optional stack?: string

Defined in: typescript/lib/lib.es5.d.ts:1076

Experimental

Inherited from​

Error.stack

stackTraceLimit​

static stackTraceLimit: number

Defined in: @types/node/globals.d.ts:67

Experimental

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

Inherited from​

Error.stackTraceLimit

Methods​

captureStackTrace()​

static captureStackTrace(targetObject, constructorOpt?): void

Defined in: @types/node/globals.d.ts:51

Experimental

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

function a() {
b();
}

function b() {
c();
}

function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;

// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}

a();
Parameters​
targetObject​

object

constructorOpt?​

Function

Returns​

void

Inherited from​

Error.captureStackTrace

isError()​

static isError(error): error is Error

Defined in: typescript/lib/lib.esnext.error.d.ts:21

Experimental

Indicates whether the argument provided is a built-in Error instance or not.

Parameters​
error​

unknown

Returns​

error is Error

Inherited from​

Error.isError

prepareStackTrace()​

static prepareStackTrace(err, stackTraces): any

Defined in: @types/node/globals.d.ts:55

Experimental

Parameters​
err​

Error

stackTraces​

CallSite[]

Returns​

any

See​

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from​

Error.prepareStackTrace

Interfaces​

YLayoutMigration​

Defined in: packages/lexical-y/src/internal/Runner.ts:71

Experimental

A frozen layout migration step: one root from layout from to from + 1, in place (see @lexical/y/migrate). The runner owns the traversal and calls the step per container (the root, nested containers, attribute-held types). Pure (no clock, randomness, app code, binding or editor) and frozen: it imports @y/y and its own copies of what it reads and writes, never the live binding. Any change to what it writes bumps revision.

Properties​

from​

readonly from: number

Defined in: packages/lexical-y/src/internal/Runner.ts:77

Experimental

The layout the step migrates from.

id​

readonly id: string

Defined in: packages/lexical-y/src/internal/Runner.ts:73

Experimental

lexical-y/layout/<from>to<to>.

revision​

readonly revision: number

Defined in: packages/lexical-y/src/internal/Runner.ts:75

Experimental

From 1; bumped on any change to what the step writes (hashed into the client).

to​

readonly to: number

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

Experimental

from + 1, always.

Methods​

checkAfter()​

checkAfter(container): readonly string[]

Defined in: packages/lexical-y/src/internal/Runner.ts:105

Experimental

The target layout's own invariants on one migrated container (problems; none: empty), so a step that only stamps the record cannot pass on equal reads.

Parameters​
container​

YNode

Returns​

readonly string[]

migrateContainer()​

migrateContainer(tr, container): object

Defined in: packages/lexical-y/src/internal/Runner.ts:86

Experimental

Migrate one container's own sequence, inside the runner's transaction on an observer-free copy (the runner records the layout before the first container and the epoch after the last). Returns what it wrote and deleted (informational; the receipt counts the transaction).

Parameters​
tr​

Transaction

container​

YNode

Returns​

object

deleted​

readonly deleted: number

written​

readonly written: number

readAfter()​

readAfter(container): readonly string[]

Defined in: packages/lexical-y/src/internal/Runner.ts:99

Experimental

Frozen read of layout to, in the same shape as readBefore.

Parameters​
container​

YNode

Returns​

readonly string[]

readBefore()​

readBefore(container): readonly string[]

Defined in: packages/lexical-y/src/internal/Runner.ts:97

Experimental

Frozen read of layout from: one normalized string per live countable unit of the container's own sequence, in order (each UTF-16 code unit of a string item, each embed or type item once). Compared with readAfter of the result unit by unit, so item splits and merges do not matter.

Parameters​
container​

YNode

Returns​

readonly string[]

rewrites()​

rewrites(key): boolean

Defined in: packages/lexical-y/src/internal/Runner.ts:110

Experimental

The format keys the step rewrites. Every other format item, and every attribute, is untouched.

Parameters​
key​

string

Returns​

boolean


YMigrateOptions​

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

Experimental

Options of migrateYDoc.

Extended by​

Properties​

clientID?​

readonly optional clientID?: (input) => number

Defined in: packages/lexical-y/src/internal/Runner.ts:226

Experimental

An allocator of guaranteed-unique client ids, one per step run (default: the hash of the inputs). Its id must not be one the document holds.

Parameters​
input​

YMigrationStepInput

Returns​

number

clientIDRange?​

readonly optional clientIDRange?: ClientIDRange

Defined in: packages/lexical-y/src/internal/Runner.ts:221

Experimental

The range of the hashed client ids (default 'uint53'; 'uint32' for servers that read client ids as 32-bit numbers).

roots?​

readonly optional roots?: readonly string[]

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

Experimental

The roots to migrate (default ['lexical-y']), run sorted by name and de-duplicated. Each must have a layout record or be pristine.

to?​

readonly optional to?: number

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

Experimental

The layout to migrate to (default: MIN_LAYOUT of this build, so only roots below the floor migrate).


YMigrateStateOptions​

Defined in: packages/lexical-y/src/internal/Runner.ts:230

Experimental

Options of migrateYState.

Extends​

Properties​

clientID?​

readonly optional clientID?: (input) => number

Defined in: packages/lexical-y/src/internal/Runner.ts:226

Experimental

An allocator of guaranteed-unique client ids, one per step run (default: the hash of the inputs). Its id must not be one the document holds.

Parameters​
input​

YMigrationStepInput

Returns​

number

Inherited from​

YMigrateOptions.clientID

clientIDRange?​

readonly optional clientIDRange?: ClientIDRange

Defined in: packages/lexical-y/src/internal/Runner.ts:221

Experimental

The range of the hashed client ids (default 'uint53'; 'uint32' for servers that read client ids as 32-bit numbers).

Inherited from​

YMigrateOptions.clientIDRange

gc?​

readonly optional gc?: boolean

Defined in: packages/lexical-y/src/internal/Runner.ts:235

Experimental

Yjs garbage collection of the document (default true, as clients store one): must equal the authority's stored documents' setting.

roots?​

readonly optional roots?: readonly string[]

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

Experimental

The roots to migrate (default ['lexical-y']), run sorted by name and de-duplicated. Each must have a layout record or be pristine.

Inherited from​

YMigrateOptions.roots

to?​

readonly optional to?: number

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

Experimental

The layout to migrate to (default: MIN_LAYOUT of this build, so only roots below the floor migrate).

Inherited from​

YMigrateOptions.to


YMigrationReceipt​

Defined in: packages/lexical-y/src/internal/Runner.ts:186

Experimental

What a migration did.

Properties​

bytesAfter​

readonly bytesAfter: number

Defined in: packages/lexical-y/src/internal/Runner.ts:193

Experimental

bytesBefore​

readonly bytesBefore: number

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

Experimental

The encoded state's size before and after, in bytes.

changed​

readonly changed: boolean

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

Experimental

Whether any root changed.

ms​

readonly ms: number

Defined in: packages/lexical-y/src/internal/Runner.ts:194

Experimental

roots​

readonly roots: readonly YMigrationRootReceipt[]

Defined in: packages/lexical-y/src/internal/Runner.ts:188

Experimental

One per root, sorted by name.


YMigrationResult​

Defined in: packages/lexical-y/src/internal/Runner.ts:239

Experimental

What migrateYState returns.

Properties​

pending​

readonly pending: Uint8Array<ArrayBufferLike> | null

Defined in: packages/lexical-y/src/internal/Runner.ts:251

Experimental

The input's pending structs and pending delete set (V1), for the quarantine: never in state. Null when there are none or nothing ran.

receipt​

readonly receipt: YMigrationReceipt

Defined in: packages/lexical-y/src/internal/Runner.ts:252

Experimental

state​

readonly state: Uint8Array

Defined in: packages/lexical-y/src/internal/Runner.ts:244

Experimental

The migrated state (update format V1), without pending material; the input bytes themselves when nothing ran (store nothing then).

update​

readonly update: Uint8Array<ArrayBufferLike> | null

Defined in: packages/lexical-y/src/internal/Runner.ts:246

Experimental

The update from the input's integrated state to state; null when nothing ran.


YMigrationRootReceipt​

Defined in: packages/lexical-y/src/internal/Runner.ts:173

Experimental

What a migration did to one root.

Properties​

changed​

readonly changed: boolean

Defined in: packages/lexical-y/src/internal/Runner.ts:179

Experimental

epoch​

readonly epoch: YLayoutEpoch | null

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

Experimental

The epoch the last step recorded, null when none ran.

from​

readonly from: number | null

Defined in: packages/lexical-y/src/internal/Runner.ts:176

Experimental

The layout found, null for a pristine root (no record, no content).

root​

readonly root: string

Defined in: packages/lexical-y/src/internal/Runner.ts:174

Experimental

steps​

readonly steps: readonly YMigrationStepReceipt[]

Defined in: packages/lexical-y/src/internal/Runner.ts:180

Experimental

to​

readonly to: number | null

Defined in: packages/lexical-y/src/internal/Runner.ts:178

Experimental

The layout after the migration (from when nothing ran).


YMigrationStepInput​

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

Experimental

What a step writes with, for a clientID allocator.

Properties​

revision​

readonly revision: number

Defined in: packages/lexical-y/src/internal/Runner.ts:201

Experimental

root​

readonly root: string

Defined in: packages/lexical-y/src/internal/Runner.ts:199

Experimental

step​

readonly step: string

Defined in: packages/lexical-y/src/internal/Runner.ts:200

Experimental

to​

readonly to: number

Defined in: packages/lexical-y/src/internal/Runner.ts:202

Experimental


YMigrationStepReceipt​

Defined in: packages/lexical-y/src/internal/Runner.ts:161

Experimental

One step a migration ran on one root.

Properties​

client​

readonly client: number

Defined in: packages/lexical-y/src/internal/Runner.ts:165

Experimental

The client id the step wrote with.

deleted​

readonly deleted: number

Defined in: packages/lexical-y/src/internal/Runner.ts:169

Experimental

Items it deleted (an earlier epoch included).

id​

readonly id: string

Defined in: packages/lexical-y/src/internal/Runner.ts:162

Experimental

revision​

readonly revision: number

Defined in: packages/lexical-y/src/internal/Runner.ts:163

Experimental

written​

readonly written: number

Defined in: packages/lexical-y/src/internal/Runner.ts:167

Experimental

Items the step's transaction wrote (the record and epoch included).

Type Aliases​

YMigrationErrorCode​

YMigrationErrorCode = "missing-step" | "invalid-steps" | "missing" | "malformed" | "newer" | "pending" | "post-condition" | "in-transaction"

Defined in: packages/lexical-y/src/internal/Runner.ts:114

Experimental

The codes of YMigrationError.


YMigrationLoaders​

YMigrationLoaders = object

Defined in: packages/lexical-y/src/internal/Runner.ts:269

Experimental

Loaders of steps by the layout they migrate from, e.g. {1: () => import('@lexical/y/migrate/1to2')}. A loader may resolve to the step or to its module (default export). Other keys are ignored.

Index Signature​

[from: number]: () => Promise<unknown>

Variables​

MIGRATION_ORIGIN​

const MIGRATION_ORIGIN: unique symbol

Defined in: packages/lexical-y/src/internal/Runner.ts:260

Experimental

The origin of the transaction that applies a migration to a document (migrateYDoc). A registered symbol, so every copy of the package (the binding's bundle and the runner's) names the same one.

Functions​

layoutEpoch()​

layoutEpoch(doc, root?): YLayoutEpoch | null

Defined in: packages/lexical-y/src/internal/Runner.ts:1345

Experimental

The epoch doc records under root, null when none or malformed.

Parameters​

doc​

Doc

root?​

string = DEFAULT_ROOT_NAME

Returns​

YLayoutEpoch | null


loadYMigrationSteps()​

loadYMigrationSteps(loaders, from, to?): Promise<YLayoutMigration[]>

Defined in: packages/lexical-y/src/internal/Runner.ts:431

Experimental

Load the steps a root at layout from needs to reach to (default LAYOUT_VERSION), only those, in parallel. Rejects with a 'missing-step' YMigrationError when a link has no loader or a loader gives something else than the step from that layout.

Parameters​

loaders​

YMigrationLoaders

from​

number

to?​

number = LAYOUT_VERSION

Returns​

Promise<YLayoutMigration[]>


migrateYDoc()​

migrateYDoc(doc, steps, options?): YMigrationReceipt

Defined in: packages/lexical-y/src/internal/Runner.ts:1272

Experimental

Migrate a live document in place: the steps run and are checked on an observer-free copy of its integrated state, and only then is their update applied to doc in one transaction with MIGRATION_ORIGIN (pending material stays pending in doc). Only for a document no other client or server writes (or an authority's own copy with every session out). Refused inside a transaction of doc ('in-transaction': an outer transaction would give the migration its origin and its undo capture).

Parameters​

doc​

Doc

steps​

readonly YLayoutMigration[]

options?​

YMigrateOptions = {}

Returns​

YMigrationReceipt


migrateYState()​

migrateYState(state, steps, options?): YMigrationResult

Defined in: packages/lexical-y/src/internal/Runner.ts:1214

Experimental

Migrate a stored state (synchronous; for an authority with every session out, behind its barrier and compare-and-set over exactly these bytes). Every root below the target runs its chain of steps on an observer-free copy, each step checked there; any refusal or failed check throws a YMigrationError and nothing is returned. Pending structs, a pending delete set and skipped ranges (with everything after the gap and everything that depends on it) are split out (pending), never migrated or kept in state. When no root needs a step, the input bytes come back as state, with update: null and changed: false: store nothing.

Parameters​

state​

Uint8Array

steps​

readonly YLayoutMigration[]

options?​

YMigrateStateOptions = {}

Returns​

YMigrationResult


recordedLayout()​

recordedLayout(doc, root?): number | null

Defined in: packages/lexical-y/src/internal/Runner.ts:1328

Experimental

The layout doc records under root: the highest lexical-y:<n> record; null when it has none (or no such root); NaN when a record is not a version (the binding opens it read only).

Parameters​

doc​

Doc

root?​

string = DEFAULT_ROOT_NAME

Returns​

number | null

References​

YLayoutEpoch​

Re-exports YLayoutEpoch