Reference · 132 exports · mocanvas 4.11.2

@mocanvas/store

The reactive record store, its schema and its migrations.

Read out of the type declarations inside the published package, so a name here is a name in the version above — and its description is the one written next to the code.

132 of 132

Describes one kind of record in the store: how to make ids, defaults, validation, and where the record lives (its scope).

Store

class

A reactive, transactional collection of records.

The set of record types a store holds plus the migrations that bring persisted data up to date.

Hooks that run around record writes.

Record that `id` went from `before` to `after` in `target`, collapsing with any change already recorded for the same id:

Apply a {@link CollectionDiff} to a set, in place.

Apply one migration (record- or store-scoped) to a whole store in place.

Apply one record migration to a single record, honoring its filter.

assertIdType

function

Assert that `id` belongs to `type`, narrowing it to that type's id.

Shallow-copy a diff (entries are shared).

Compare two keys: negative, zero, or positive.

compareZKeys

function

Compare two zkeys as unsigned 64-bit integers.

Declare a per-record memo, keyed by record id, recomputed only when that record changes.

A {@link SynchronousStorage} backed by a plain `Map`.

Build the ids of a sequence's migrations from friendly names:

Create a validated migration sequence.

Convenience for the common case: a sequence of record-scoped migrations that all apply to one record type (optionally narrowed further by `filter`).

Define a record type.

devFreeze

function

Deep-freeze `object` in development builds, and hand it straight back in production.

freezeRecord

function

Freeze a record and its `props` / `meta` bags (one level).

How many grapheme clusters `str` has — its length as a reader would count it.

getGraphemes

function

The grapheme clusters of `str`, as an array.

The property this query can be answered from an index on, or `undefined` when none of it is indexable.

Generate a key strictly above `below` (or a first key when omitted).

Generate a key strictly below `above` (or a first key when omitted).

Generate a key strictly between `below` and `above`; either may be omitted.

getIndices

function

`start`, followed by `n` freshly generated keys above it.

Generate `n` sorted keys strictly above `below`.

Generate `n` sorted keys strictly below `above`.

Generate `n` sorted keys strictly between `below` and `above`.

Whether a {@link CollectionDiff} describes no change at all.

Whether jitter is on right now.

isIndexKey

function

Non-throwing variant of `validateIndexKey`.

isRecordLike

function

Assert that `value` looks like a record: an object with string `id` and `typeName`.

Records are considered unchanged when every top-level value is identical, with `props` and `meta` compared one level deeper.

Whether a persisted schema is in the pre-sequence format.

Iterate the grapheme clusters of `str`.

matchesQuery

function

Whether `record` satisfies every entry of `query`.

Whether `value` satisfies `matcher`.

Split any `${typeName}:${unique}` id into its parts.

Parse a `.tldr` file.

Produce the diff that undoes `diff`.

Serialize records and their schema into the `.tldr` envelope (pretty-printed, stable key order).

Turn jitter on or off for the rest of this process; `null` restores the default resolution above.

sortByIndex

function

Return a sorted copy of `items` ordered by their `index` (stable).

Squash a sequence of diffs into one equivalent diff (does not mutate inputs).

Merge `diff` into `target` in place (see `applyChangeToDiff` for the rules).

Convert a `{ store, schema }` snapshot into `.tldr` text.

Convert a parsed file into a `{ store, schema }` snapshot.

uniqueId

function

Generate a URL-safe unique id (21 chars by default).

Throws if `key` is not a well-formed fractional index key: a head marker, enough base-62 integer digits for that head, then an optional fraction of base-62 digits that does not end in `0`.

zKeyToBigInt

function

Recombine a zkey into a BigInt (mostly for tests and debugging).

BaseRecord

interface

Every record has an id and a type name.

What changed in a set: the members added and the members removed.

ComputedCache

interface

The handle returned by {@link createComputedCache}.

Options for {@link createComputedCache}.

HistoryEntry

interface

The version bounds every legacy migration table declares.

One numbered step of a {@link LegacyMigrations} table.

A legacy migration table: the version range it covers, the numbered steps, and optionally the sub-type split a record type used (a shape's `type`, say, each with its own version line).

RecordsDiff

interface

A set of changes to a store's records.

The persisted schema shape used before migration sequences: a version number per record type, and one for the store as a whole.

Persisted description of a schema: for each migration sequence, how many migrations had been applied when the data was saved.

A dependency declared by a standalone migration sequence: it must run after (or before) another sequence's numbered migration, even though neither owns the other.

StoreError

interface

A record that failed validation, with enough context to say what was being done to it at the time.

StoreOptions

interface

StoreSnapshot

interface

Somewhere records can be read from and written to, one at a time, without awaiting.

Record storage that also remembers the schema its records were written against, so they can be migrated when they are read back.

TldrFile

interface

TypeIndex

interface

A context a computed cache can read a store from: a store itself, or anything holding one (an `Editor`).

Options for {@link createComputedCache}, including the record-level equality that decides when a derivation is worth re-running at all.

IdOf

type

A fractional index: an order key that sorts lexicographically (plain string comparison) and between which new keys can always be generated.

A query over the records of one type: property name to matcher, every entry of which must hold (they are ANDed).

How one property of a record is matched.

Properties the caller must pass to `create()`: the record's data keys minus whatever `withDefaultProperties` provides.

Keys of `R` that hold data (everything except `id` and `typeName`).

Extract the record type an id refers to.

A branded string id.

Where a record lives: - `document`: persisted, shared between collaborators (shapes, pages, ...) - `session`: persisted locally only (camera, current page, ...) - `presence`: shared but never persisted (cursors, ...)

A live index over one property, as a diff-carrying signal.

How an {@link RSIndexMap} changed: per property value, which ids joined and left.

An index over one property of one record type: for each value that property takes, the ids of the records that hold it.

A persisted schema, in either format mocanvas can read.

Serialized records keyed by id.

Return `false` to veto the deletion.

Anything that owns a store: a `Store` itself, or an object holding one (an `Editor`).

The record union of whatever store a {@link StoreObject} carries.

How the records of one type are narrowed: a predicate, or a declarative {@link QueryExpression} the store can answer from an index.

A validator per record type, as `StoreSchema` collects them from the record types.

ZKey

type

Why loading a persisted snapshot failed.

The key a run of indices starts from when the caller names none.

`.tldr` file envelope.

Length of the unique part of a generated record id.

The conventional first key.

Number of base-62 digits (after the head marker) that affect the zkey.

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.