@mocanvas/store · class
declare class StoreSchema<R extends UnknownRecord, Props = unknown>The set of record types a store holds plus the migrations that bring persisted data up to date.
Methods · 9
static create<R extends UnknownRecord, Props = unknown>(types: RecordTypeMap<R>, options?: StoreSchemaOptions<R, Props>): StoreSchema<R, Props>getMigrationsSince(persistedSchema: SerializedSchema): MigrationResult<Migration[]>The migrations that must run to bring data saved under persistedSchema
up to this schema, in order. Sequences the persisted schema knows but we
do not are ignored with a warning.
getScope(typeName: string): RecordScopeScope of a record type; unknown types are treated as document.
getType(typeName: string): RecordType<R, any> | undefinedmigratePersistedRecord(record: UnknownRecord, persistedSchema: SerializedSchema, direction?: "up" | "down"): MigrationResult<UnknownRecord>Migrate a single record. Only record-scoped migrations can be applied;
encountering a store-scoped one is an error. down runs the migrations
in reverse (from this schema to persistedSchema).
migrateStoreSnapshot(snapshot: StoreSnapshot<R>): MigrationResult<SerializedStore<R>>Bring a whole persisted store up to date. The input is not mutated. Records of types this schema does not know are preserved as-is.
serialize(): SerializedSchemaV2The current version of every sequence. Always the v2 shape — mocanvas never writes v1.
serializeEarliestVersion(): SerializedSchemaV2A schema at version 0 of every sequence (all migrations still pending).
validateRecord(store: Store<R, any>, record: R, phase: StoreValidationPhase, recordBefore: R | undefined): RValidate a record, delegating to its record type's validator.
Two things are checked before the delegation. First, the value has to be a
record at all: an object with a string id and a string typeName.
Without that check a value carrying no typeName looks up undefined in
the type map, misses, and takes the unknown-type path below — which is how
store.put([{ id: "shape:bogus", x: 0, y: 0 }]) used to be accepted.
Second, a record whose typeName this schema does not know is passed
through untouched, so foreign data survives a load/save round-trip. That
is the escape hatch; it is not meant to cover malformed input, hence the
first check.
Properties · 3
readonly migrations: Readonly<Record<string, MigrationSequence>>readonly sortedMigrations: readonly Migration[]All migrations in application order (sequence registration order, then version).
readonly types: RecordTypeMap<R>mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.