@lexical/y/migrate
Classes
YMigrationError
Defined in: packages/lexical-y/src/internal/Runner.ts:151
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:157
Experimental
Parameters
code
message
string
problems?
readonly string[] = []
root?
string | null
Returns
Overrides
Error.constructor
Properties
cause?
optionalcause?:unknown
Defined in: typescript/lib/lib.es2022.error.d.ts:24
Experimental
Inherited from
Error.cause
code
readonlycode:YMigrationErrorCode
Defined in: packages/lexical-y/src/internal/Runner.ts:152
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
readonlyproblems: readonlystring[]
Defined in: packages/lexical-y/src/internal/Runner.ts:154
Experimental
Every problem found (for 'post-condition', every failed check).
root
readonlyroot:string|null
Defined in: packages/lexical-y/src/internal/Runner.ts:156
Experimental
The root concerned, null when the whole document is.
stack?
optionalstack?:string
Defined in: typescript/lib/lib.es5.d.ts:1076
Experimental
Inherited from
Error.stack
stackTraceLimit
staticstackTraceLimit: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()
staticcaptureStackTrace(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?
Returns
void
Inherited from
Error.captureStackTrace
isError()
staticisError(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()
staticprepareStackTrace(err,stackTraces):any
Defined in: @types/node/globals.d.ts:55
Experimental
Parameters
err
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:82
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
readonlyfrom:number
Defined in: packages/lexical-y/src/internal/Runner.ts:88
Experimental
The layout the step migrates from.
id
readonlyid:string
Defined in: packages/lexical-y/src/internal/Runner.ts:84
Experimental
lexical-y/layout/<from>to<to>.
revision
readonlyrevision:number
Defined in: packages/lexical-y/src/internal/Runner.ts:86
Experimental
From 1; bumped on any change to what the step writes (hashed into the client).
to
readonlyto:number
Defined in: packages/lexical-y/src/internal/Runner.ts:90
Experimental
from + 1, always.
Methods
checkAfter()
checkAfter(
container): readonlystring[]
Defined in: packages/lexical-y/src/internal/Runner.ts:116
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
Returns
readonly string[]
migrateContainer()
migrateContainer(
tr,container):object
Defined in: packages/lexical-y/src/internal/Runner.ts:97
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
container
Returns
object
deleted
readonlydeleted:number
written
readonlywritten:number
readAfter()
readAfter(
container): readonlystring[]
Defined in: packages/lexical-y/src/internal/Runner.ts:110
Experimental
Frozen read of layout to, in the same shape as readBefore.
Parameters
container
Returns
readonly string[]
readBefore()
readBefore(
container): readonlystring[]
Defined in: packages/lexical-y/src/internal/Runner.ts:108
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
Returns
readonly string[]
rewrites()
rewrites(
key):boolean
Defined in: packages/lexical-y/src/internal/Runner.ts:121
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:217
Experimental
Options of migrateYDoc.
Extended by
Properties
clientID?
readonlyoptionalclientID?: (input) =>number
Defined in: packages/lexical-y/src/internal/Runner.ts:237
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
Returns
number
clientIDRange?
readonlyoptionalclientIDRange?:ClientIDRange
Defined in: packages/lexical-y/src/internal/Runner.ts:232
Experimental
The range of the hashed client ids (default 'uint53'; 'uint32' for
servers that read client ids as 32-bit numbers).
roots?
readonlyoptionalroots?: readonlystring[]
Defined in: packages/lexical-y/src/internal/Runner.ts:222
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?
readonlyoptionalto?:number
Defined in: packages/lexical-y/src/internal/Runner.ts:227
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:241
Experimental
Options of migrateYState.
Extends
Properties
clientID?
readonlyoptionalclientID?: (input) =>number
Defined in: packages/lexical-y/src/internal/Runner.ts:237
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
Returns
number
Inherited from
clientIDRange?
readonlyoptionalclientIDRange?:ClientIDRange
Defined in: packages/lexical-y/src/internal/Runner.ts:232
Experimental
The range of the hashed client ids (default 'uint53'; 'uint32' for
servers that read client ids as 32-bit numbers).
Inherited from
gc?
readonlyoptionalgc?:boolean
Defined in: packages/lexical-y/src/internal/Runner.ts:246
Experimental
Yjs garbage collection of the document (default true, as clients store one): must equal the authority's stored documents' setting.
roots?
readonlyoptionalroots?: readonlystring[]
Defined in: packages/lexical-y/src/internal/Runner.ts:222
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
to?
readonlyoptionalto?:number
Defined in: packages/lexical-y/src/internal/Runner.ts:227
Experimental
The layout to migrate to (default: MIN_LAYOUT of this build, so only roots below the floor migrate).
Inherited from
YMigrationReceipt
Defined in: packages/lexical-y/src/internal/Runner.ts:197
Experimental
What a migration did.
Properties
bytesAfter
readonlybytesAfter:number
Defined in: packages/lexical-y/src/internal/Runner.ts:204
Experimental
bytesBefore
readonlybytesBefore:number
Defined in: packages/lexical-y/src/internal/Runner.ts:203
Experimental
The encoded state's size before and after, in bytes.
changed
readonlychanged:boolean
Defined in: packages/lexical-y/src/internal/Runner.ts:201
Experimental
Whether any root changed.
ms
readonlyms:number
Defined in: packages/lexical-y/src/internal/Runner.ts:205
Experimental
roots
readonlyroots: readonlyYMigrationRootReceipt[]
Defined in: packages/lexical-y/src/internal/Runner.ts:199
Experimental
One per root, sorted by name.
YMigrationResult
Defined in: packages/lexical-y/src/internal/Runner.ts:250
Experimental
What migrateYState returns.
Properties
pending
readonlypending:Uint8Array<ArrayBufferLike> |null
Defined in: packages/lexical-y/src/internal/Runner.ts:262
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
readonlyreceipt:YMigrationReceipt
Defined in: packages/lexical-y/src/internal/Runner.ts:263
Experimental
state
readonlystate:Uint8Array
Defined in: packages/lexical-y/src/internal/Runner.ts:255
Experimental
The migrated state (update format V1), without pending material; the input bytes themselves when nothing ran (store nothing then).
update
readonlyupdate:Uint8Array<ArrayBufferLike> |null
Defined in: packages/lexical-y/src/internal/Runner.ts:257
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:184
Experimental
What a migration did to one root.
Properties
changed
readonlychanged:boolean
Defined in: packages/lexical-y/src/internal/Runner.ts:190
Experimental
epoch
readonlyepoch:YLayoutEpoch|null
Defined in: packages/lexical-y/src/internal/Runner.ts:193
Experimental
The epoch the last step recorded, null when none ran.
from
readonlyfrom:number|null
Defined in: packages/lexical-y/src/internal/Runner.ts:187
Experimental
The layout found, null for a pristine root (no record, no content).
root
readonlyroot:string
Defined in: packages/lexical-y/src/internal/Runner.ts:185
Experimental
steps
readonlysteps: readonlyYMigrationStepReceipt[]
Defined in: packages/lexical-y/src/internal/Runner.ts:191
Experimental
to
readonlyto:number|null
Defined in: packages/lexical-y/src/internal/Runner.ts:189
Experimental
The layout after the migration (from when nothing ran).
YMigrationStepInput
Defined in: packages/lexical-y/src/internal/Runner.ts:209
Experimental
What a step writes with, for a clientID allocator.
Properties
revision
readonlyrevision:number
Defined in: packages/lexical-y/src/internal/Runner.ts:212
Experimental
root
readonlyroot:string
Defined in: packages/lexical-y/src/internal/Runner.ts:210
Experimental
step
readonlystep:string
Defined in: packages/lexical-y/src/internal/Runner.ts:211
Experimental
to
readonlyto:number
Defined in: packages/lexical-y/src/internal/Runner.ts:213
Experimental
YMigrationStepReceipt
Defined in: packages/lexical-y/src/internal/Runner.ts:172
Experimental
One step a migration ran on one root.
Properties
client
readonlyclient:number
Defined in: packages/lexical-y/src/internal/Runner.ts:176
Experimental
The client id the step wrote with.
deleted
readonlydeleted:number
Defined in: packages/lexical-y/src/internal/Runner.ts:180
Experimental
Items it deleted (an earlier epoch included).
id
readonlyid:string
Defined in: packages/lexical-y/src/internal/Runner.ts:173
Experimental
revision
readonlyrevision:number
Defined in: packages/lexical-y/src/internal/Runner.ts:174
Experimental
written
readonlywritten:number
Defined in: packages/lexical-y/src/internal/Runner.ts:178
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:125
Experimental
The codes of YMigrationError.
YMigrationLoaders
YMigrationLoaders =
object
Defined in: packages/lexical-y/src/internal/Runner.ts:280
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
constMIGRATION_ORIGIN: uniquesymbol
Defined in: packages/lexical-y/src/internal/Runner.ts:271
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:1597
Experimental
The epoch doc records under root, null when none or malformed.
Parameters
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:442
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
from
number
to?
number = LAYOUT_VERSION
Returns
migrateYDoc()
migrateYDoc(
doc,steps,options?):YMigrationReceipt
Defined in: packages/lexical-y/src/internal/Runner.ts:1517
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
steps
readonly YLayoutMigration[]
options?
YMigrateOptions = {}
Returns
migrateYState()
migrateYState(
state,steps,options?):YMigrationResult
Defined in: packages/lexical-y/src/internal/Runner.ts:1453
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
steps
readonly YLayoutMigration[]
options?
YMigrateStateOptions = {}
Returns
recordedLayout()
recordedLayout(
doc,root?):number|null
Defined in: packages/lexical-y/src/internal/Runner.ts:1580
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
root?
string = DEFAULT_ROOT_NAME
Returns
number | null
References
YLayoutEpoch
Re-exports YLayoutEpoch