## API Report File for "@tldraw/store" > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts import { Atom } from '@tldraw/state'; import { Computed } from '@tldraw/state'; // @public export type AllRecords> = ExtractR>; // @public export function assertIdType(id: string | undefined, type: RecordType): asserts id is IdOf; // @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: IdOf): Data | undefined; }; // @public export function createRecordType(typeName: R['typeName'], config: { migrations?: Migrations; validator?: StoreValidator; scope: RecordScope; }): RecordType>; // @public (undocumented) export function defineMigrations = EMPTY_SYMBOL>(opts: { firstVersion?: CurrentVersion extends number ? FirstVersion : never; currentVersion?: CurrentVersion; migrators?: CurrentVersion extends number ? FirstVersion extends number ? CurrentVersion extends FirstVersion ? { [version in Exclude, 0>]: Migration; } : { [version in Exclude, FirstVersion>]: Migration; } : { [version in Exclude, 0>]: Migration; } : never; subTypeKey?: string; subTypeMigrations?: Record; }): Migrations; // @public export function devFreeze(object: T): T; // @public (undocumented) export function getRecordVersion(record: UnknownRecord, serializedSchema: SerializedSchema): RecordVersion; // @public export type HistoryEntry = { changes: RecordsDiff; source: ChangeSource; }; // @public (undocumented) export type IdOf = R['id']; // @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: Before) => After; down: (newState: After) => Before; }; // @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 (undocumented) export type RecordId = string & { __type__: R; }; // @public export type RecordsDiff = { added: Record, R>; updated: Record, [from: R, to: R]>; removed: Record, R>; }; // @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?: RecordScope; }); clone(record: R): R; create(properties: Pick & Omit, RequiredProperties>): R; // @deprecated createCustomId(id: string): IdOf; // (undocumented) readonly createDefaultProperties: () => Exclude, RequiredProperties>; createId(customUniquePart?: string): IdOf; isId(id?: string): id is IdOf; isInstance: (record?: UnknownRecord) => record is R; // (undocumented) readonly migrations: Migrations; parseId(id: IdOf): string; // (undocumented) readonly scope: RecordScope; 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 type SerializedStore = Record, R>; // @public export function squashRecordDiffs(diffs: RecordsDiff[]): RecordsDiff; // @public export class Store { constructor(config: { initialData?: SerializedStore; 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; // @internal (undocumented) ensureStoreIsUsable(): void; // (undocumented) extractingChanges(fn: () => void): RecordsDiff; filterChangesByScope(change: RecordsDiff, scope: RecordScope): { added: { [K in IdOf]: R; }; updated: { [K_1 in IdOf]: [from: R, to: R]; }; removed: { [K in IdOf]: R; }; } | null; // (undocumented) _flushHistory(): void; get: >(id: K) => RecFromId | undefined; getSnapshot(scope?: 'all' | RecordScope): StoreSnapshot; has: >(id: K) => boolean; readonly history: Atom>; readonly id: string; // @internal (undocumented) isPossiblyCorrupted(): boolean; listen: (onHistory: StoreListener, filters?: Partial) => () => void; loadSnapshot(snapshot: StoreSnapshot): 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: IdOf[]) => void; // (undocumented) readonly schema: StoreSchema; // (undocumented) readonly scopedTypes: { readonly [K in RecordScope]: ReadonlySet; }; serialize: (scope?: 'all' | RecordScope) => SerializedStore; 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; // (undocumented) migratePersistedRecord(record: R, persistedSchema: SerializedSchema, direction?: 'down' | 'up'): MigrationResult; // (undocumented) migrateStoreSnapshot(snapshot: StoreSnapshot): 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; }; // @public (undocumented) export type StoreSnapshot = { store: SerializedStore; schema: SerializedSchema; }; // @public (undocumented) export type StoreValidator = { validate: (record: unknown) => R; }; // @public (undocumented) export type StoreValidators = { [K in R['typeName']]: StoreValidator>; }; // @public (undocumented) export type UnknownRecord = BaseRecord>; // (No @packageDocumentation comment for this package) ```