## 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'; import { Result } from '@tldraw/utils'; // @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 export type ComputedCache = { get(id: IdOf): Data | undefined; }; // @internal (undocumented) export function createEmptyRecordsDiff(): RecordsDiff; // @public export function createMigrationIds>(sequenceId: ID, versions: Versions): { [K in keyof Versions]: `${ID}/${Versions[K]}`; }; // @public export function createMigrationSequence({ sequence, sequenceId, retroactive, }: { retroactive?: boolean; sequence: Array; sequenceId: string; }): MigrationSequence; // @internal (undocumented) export function createRecordMigrationSequence(opts: { filter?: (record: UnknownRecord) => boolean; recordType: string; retroactive?: boolean; sequence: Omit, 'scope'>[]; sequenceId: string; }): MigrationSequence; // @public export function createRecordType(typeName: R['typeName'], config: { ephemeralKeys?: { readonly [K in Exclude]: boolean; }; scope: RecordScope; validator?: StoreValidator; }): RecordType>; // @public @deprecated (undocumented) export function defineMigrations(opts: { currentVersion?: number; firstVersion?: number; migrators?: Record; subTypeKey?: string; subTypeMigrations?: Record; }): LegacyMigrations; // @public export function devFreeze(object: T): T; // @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(): { diff: CollectionDiff; value: Set; } | undefined; // @public remove(item: T): void; } // @internal export function isRecordsDiffEmpty(diff: RecordsDiff): boolean; // @public (undocumented) export type LegacyMigration = { down: (newState: After) => Before; up: (oldState: Before) => After; }; // @public (undocumented) export interface LegacyMigrations extends LegacyBaseMigrationsInfo { // (undocumented) subTypeKey?: string; // (undocumented) subTypeMigrations?: Record; } // @public (undocumented) export type Migration = { readonly dependsOn?: readonly MigrationId[] | undefined; readonly id: MigrationId; } & ({ readonly down?: (newState: SerializedStore) => SerializedStore | void; readonly scope: 'store'; readonly up: (oldState: SerializedStore) => SerializedStore | void; } | { readonly down?: (newState: UnknownRecord) => UnknownRecord | void; readonly filter?: (record: UnknownRecord) => boolean; readonly scope: 'record'; readonly up: (oldState: UnknownRecord) => UnknownRecord | void; }); // @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 MigrationId = `${string}/${number}`; // @public (undocumented) export type MigrationResult = { reason: MigrationFailureReason; type: 'error'; } | { type: 'success'; value: T; }; // @public (undocumented) export interface MigrationSequence { retroactive: boolean; // (undocumented) sequence: Migration[]; // (undocumented) sequenceId: string; } // @internal (undocumented) export function parseMigrationId(id: MigrationId): { sequenceId: string; version: number; }; // @public (undocumented) export type RecordId = string & { __type__: R; }; // @public export type RecordsDiff = { added: Record, R>; removed: Record, R>; updated: Record, [from: R, to: R]>; }; // @public export class RecordType> { constructor( typeName: R['typeName'], config: { readonly createDefaultProperties: () => Exclude, RequiredProperties>; readonly ephemeralKeys?: { readonly [K in Exclude]: boolean; }; readonly scope?: RecordScope; readonly validator?: StoreValidator; }); clone(record: R): R; create(properties: Pick & Omit, RequiredProperties>): R; // @deprecated createCustomId(id: string): IdOf; // (undocumented) readonly createDefaultProperties: () => Exclude, RequiredProperties>; createId(customUniquePart?: string): IdOf; // (undocumented) readonly ephemeralKeys?: { readonly [K in Exclude]: boolean; }; // (undocumented) readonly ephemeralKeySet: ReadonlySet; isId(id?: string): id is IdOf; isInstance: (record?: UnknownRecord) => record is R; parseId(id: IdOf): string; // (undocumented) readonly scope: RecordScope; readonly typeName: R['typeName']; validate(record: unknown, recordBefore?: R): R; // (undocumented) readonly validator: StoreValidator; withDefaultProperties, 'id' | 'typeName'>>(createDefaultProperties: () => DefaultProps): RecordType>; } // @public (undocumented) export function reverseRecordsDiff(diff: RecordsDiff): RecordsDiff; // @public (undocumented) export type SerializedSchema = SerializedSchemaV1 | SerializedSchemaV2; // @public (undocumented) export interface SerializedSchemaV1 { recordVersions: Record; version: number; } | { version: number; }>; schemaVersion: 1; storeVersion: number; } // @public (undocumented) export interface SerializedSchemaV2 { // (undocumented) schemaVersion: 2; // (undocumented) sequences: { [sequenceId: string]: number; }; } // @public export type SerializedStore = Record, R>; // @public export function squashRecordDiffs(diffs: RecordsDiff[]): RecordsDiff; // @internal export function squashRecordDiffsMutable(target: RecordsDiff, diffs: RecordsDiff[]): void; // @public export class Store { constructor(config: { schema: StoreSchema; initialData?: SerializedStore; id?: string; props: Props; }); // @internal (undocumented) addHistoryInterceptor(fn: (entry: HistoryEntry, source: ChangeSource) => void): () => void; allRecords: () => R[]; // (undocumented) applyDiff(diff: RecordsDiff, { runCallbacks, ignoreEphemeralKeys, }?: { ignoreEphemeralKeys?: boolean; runCallbacks?: boolean; }): void; // @internal (undocumented) atomic(fn: () => T, runCallbacks?: boolean): T; clear: () => void; createComputedCache: (name: string, derive: (record: V) => T | undefined, isEqual?: ((a: V, b: V) => boolean) | undefined) => ComputedCache; createSelectedComputedCache: (name: string, selector: (record: V) => T | undefined, derive: (input: T) => J | undefined) => ComputedCache; // @internal (undocumented) ensureStoreIsUsable(): void; extractingChanges(fn: () => void): RecordsDiff; filterChangesByScope(change: RecordsDiff, scope: RecordScope): { added: { [K in IdOf]: R; }; removed: { [K in IdOf]: R; }; updated: { [K_1 in IdOf]: [from: R, to: 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; migrateSnapshot(snapshot: StoreSnapshot): StoreSnapshot; onAfterChange?: (prev: R, next: R, source: 'remote' | 'user') => void; onAfterCreate?: (record: R, source: 'remote' | 'user') => void; onAfterDelete?: (prev: R, source: 'remote' | 'user') => void; onBeforeChange?: (prev: R, next: R, source: 'remote' | 'user') => R; onBeforeCreate?: (next: R, source: 'remote' | 'user') => R; onBeforeDelete?: (prev: R, source: 'remote' | 'user') => false | 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; isExistingValidationIssue: boolean; phase: 'createRecord' | 'initialize' | 'tests' | 'updateRecord'; recordAfter: unknown; recordBefore?: unknown; }; // @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) getMigrationsSince(persistedSchema: SerializedSchema): Result; // @internal (undocumented) getType(typeName: string): RecordType; // (undocumented) migratePersistedRecord(record: R, persistedSchema: SerializedSchema, direction?: 'down' | 'up'): MigrationResult; // (undocumented) migrateStoreSnapshot(snapshot: StoreSnapshot): MigrationResult>; // (undocumented) readonly migrations: Record; // (undocumented) serialize(): SerializedSchemaV2; // @deprecated (undocumented) serializeEarliestVersion(): SerializedSchema; // (undocumented) readonly sortedMigrations: readonly Migration[]; // (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 = { createIntegrityChecker?: (store: Store) => void; onValidationFailure?: (data: { error: unknown; phase: 'createRecord' | 'initialize' | 'tests' | 'updateRecord'; record: R; recordBefore: null | R; store: Store; }) => R; migrations?: MigrationSequence[]; }; // @public (undocumented) export type StoreSnapshot = { schema: SerializedSchema; store: SerializedStore; }; // @public (undocumented) export type StoreValidator = { validate: (record: unknown) => R; validateUsingKnownGoodVersion?: (knownGoodVersion: R, 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) ```