## API Report File for "@tldraw/tlstore" > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts import { Atom } from 'signia'; import { Computed } from 'signia'; import { Signal } from 'signia'; // @public export type AllRecords> = ExtractR>; // @public export function assertIdType(id: string | undefined, type: RecordType): asserts id is ID; // @public export interface BaseRecord { // (undocumented) readonly id: ID; // (undocumented) readonly typeName: TypeName; } // @public export type CollectionDiff = { added?: Set; removed?: Set; }; // @public (undocumented) export function compareRecordVersions(a: RecordVersion, b: RecordVersion): -1 | 0 | 1; // @public (undocumented) export const compareSchemas: (a: SerializedSchema, b: SerializedSchema) => -1 | 0 | 1; // @public export type ComputedCache = { get(id: ID): Data | undefined; }; // @public export function createRecordType(typeName: R['typeName'], config: { migrations?: Migrations; validator: StoreValidator; scope: Scope; }): RecordType>; // @public (undocumented) export function defineMigrations({ firstVersion, currentVersion, migrators, subTypeKey, subTypeMigrations, }: { firstVersion: FirstVersion; currentVersion: CurrentVersion; migrators: { [version in Exclude, FirstVersion>]: Migration; }; subTypeKey?: string; subTypeMigrations?: Record; }): Migrations; // @public export function devFreeze(object: T): T; // @public (undocumented) export function getRecordVersion(record: BaseRecord, serializedSchema: SerializedSchema): RecordVersion; // @public export type HistoryEntry = { changes: RecordsDiff; source: 'remote' | 'user'; }; // @public (undocumented) export type ID = string & { __type__: R; }; // @internal export class IncrementalSetConstructor { constructor( previousValue: Set); // @public add(item: T): void; // @public get(): { value: Set; diff: CollectionDiff; } | undefined; // @public remove(item: T): void; } // @public (undocumented) export function migrate({ value, migrations, fromVersion, toVersion, }: { value: unknown; migrations: Migrations; fromVersion: number; toVersion: number; }): MigrationResult; // @public (undocumented) export function migrateRecord({ record, migrations, fromVersion, toVersion, }: { record: unknown; migrations: Migrations; fromVersion: number; toVersion: number; }): MigrationResult; // @public (undocumented) export type Migration = { up: (oldState: T) => T; down: (newState: T) => T; }; // @public (undocumented) export enum MigrationFailureReason { // (undocumented) IncompatibleSubtype = "incompatible-subtype", // (undocumented) MigrationError = "migration-error", // (undocumented) TargetVersionTooNew = "target-version-too-new", // (undocumented) TargetVersionTooOld = "target-version-too-old", // (undocumented) UnknownType = "unknown-type", // (undocumented) UnrecognizedSubtype = "unrecognized-subtype" } // @public (undocumented) export type MigrationResult = { type: 'error'; reason: MigrationFailureReason; } | { type: 'success'; value: T; }; // @public (undocumented) export interface Migrations extends BaseMigrationsInfo { // (undocumented) subTypeKey?: string; // (undocumented) subTypeMigrations?: Record; } // @public export type RecordsDiff = { added: Record; updated: Record; removed: Record; }; // @public export class RecordType> { constructor( typeName: R['typeName'], config: { readonly createDefaultProperties: () => Exclude, RequiredProperties>; readonly migrations: Migrations; readonly validator?: { validate: (r: unknown) => R; } | StoreValidator; readonly scope?: Scope; }); clone(record: R): R; create(properties: Pick & Omit, RequiredProperties>): R; createCustomId(id: string): ID; // (undocumented) readonly createDefaultProperties: () => Exclude, RequiredProperties>; createId(): ID; isId(id?: string): id is ID; isInstance: (record?: BaseRecord) => record is R; // (undocumented) readonly migrations: Migrations; parseId(id: string): ID; // (undocumented) readonly scope: Scope; readonly typeName: R['typeName']; validate(record: unknown): R; // (undocumented) readonly validator: { validate: (r: unknown) => R; } | StoreValidator; withDefaultProperties, 'id' | 'typeName'>>(createDefaultProperties: () => DefaultProps): RecordType>; } // @public (undocumented) export type RecordVersion = { rootVersion: number; subTypeVersion?: number; }; // @public (undocumented) export function reverseRecordsDiff(diff: RecordsDiff): RecordsDiff; // @public (undocumented) export interface SerializedSchema { recordVersions: Record; subTypeKey: string; } | { version: number; }>; schemaVersion: number; storeVersion: number; } // @public export function squashRecordDiffs(diffs: RecordsDiff[]): RecordsDiff; // @public export class Store { constructor(config: { initialData?: StoreSnapshot; schema: StoreSchema; props: Props; }); allRecords: () => R[]; // (undocumented) applyDiff(diff: RecordsDiff, runCallbacks?: boolean): void; clear: () => void; createComputedCache: (name: string, derive: (record: V) => T | undefined) => ComputedCache; createSelectedComputedCache: (name: string, selector: (record: V) => T | undefined, derive: (input: T) => J | undefined) => ComputedCache; deserialize: (snapshot: StoreSnapshot) => void; // @internal (undocumented) ensureStoreIsUsable(): void; // (undocumented) extractingChanges(fn: () => void): RecordsDiff; // (undocumented) _flushHistory(): void; get: >(id: K) => RecFromId | undefined; has: >(id: K) => boolean; readonly history: Atom>; // @internal (undocumented) isPossiblyCorrupted(): boolean; listen: (listener: StoreListener) => () => void; // @internal (undocumented) markAsPossiblyCorrupted(): void; mergeRemoteChanges: (fn: () => void) => void; onAfterChange?: (prev: R, next: R) => void; onAfterCreate?: (record: R) => void; onAfterDelete?: (prev: R) => void; onBeforeDelete?: (prev: R) => void; // (undocumented) readonly props: Props; put: (records: R[], phaseOverride?: 'initialize') => void; readonly query: StoreQueries; remove: (ids: ID[]) => void; // (undocumented) readonly schema: StoreSchema; serialize: (filter?: ((record: R) => boolean) | undefined) => StoreSnapshot; serializeDocumentState: () => StoreSnapshot; unsafeGetWithoutCapture: >(id: K) => RecFromId | undefined; update: >(id: K, updater: (record: RecFromId) => RecFromId) => void; // (undocumented) validate(phase: 'createRecord' | 'initialize' | 'tests' | 'updateRecord'): void; } // @public (undocumented) export type StoreError = { error: Error; phase: 'createRecord' | 'initialize' | 'tests' | 'updateRecord'; recordBefore?: unknown; recordAfter: unknown; isExistingValidationIssue: boolean; }; // @public export type StoreListener = (entry: HistoryEntry) => void; // @public (undocumented) export class StoreSchema { // (undocumented) static create(types: { [TypeName in R['typeName']]: { createId: any; }; }, options?: StoreSchemaOptions): StoreSchema; // @internal (undocumented) createIntegrityChecker(store: Store): (() => void) | undefined; // (undocumented) get currentStoreVersion(): number; // @internal (undocumented) derivePresenceState(store: Store): Signal | undefined; // (undocumented) migratePersistedRecord(record: R, persistedSchema: SerializedSchema, direction?: 'down' | 'up'): MigrationResult; // (undocumented) migrateStoreSnapshot(storeSnapshot: StoreSnapshot, persistedSchema: SerializedSchema): MigrationResult>; // (undocumented) serialize(): SerializedSchema; // (undocumented) serializeEarliestVersion(): SerializedSchema; // (undocumented) readonly types: { [Record in R as Record['typeName']]: RecordType; }; // (undocumented) validateRecord(store: Store, record: R, phase: 'createRecord' | 'initialize' | 'tests' | 'updateRecord', recordBefore: null | R): R; } // @public (undocumented) export type StoreSchemaOptions = { snapshotMigrations?: Migrations; onValidationFailure?: (data: { error: unknown; store: Store; record: R; phase: 'createRecord' | 'initialize' | 'tests' | 'updateRecord'; recordBefore: null | R; }) => R; createIntegrityChecker?: (store: Store) => void; derivePresenceState?: (store: Store) => Signal; }; // @public export type StoreSnapshot = Record; // @public (undocumented) export type StoreValidator = { validate: (record: unknown) => R; }; // @public (undocumented) export type StoreValidators = { [K in R['typeName']]: StoreValidator>; }; // (No @packageDocumentation comment for this package) ```