## 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 interface CollectionDiff { // (undocumented) added?: Set; // (undocumented) removed?: Set; } // @public export interface ComputedCache { // (undocumented) get(id: IdOf): Data | undefined; } // @public export function createComputedCache, Result, Record extends ContextRecordType = ContextRecordType>(name: string, derive: (context: Context, record: Record) => Result | undefined, isEqual?: (a: Record, b: Record) => boolean): { get(context: Context, id: IdOf): Result | 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 interface HistoryEntry { // (undocumented) changes: RecordsDiff; // (undocumented) 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 interface LegacyMigration { // (undocumented) down: (newState: After) => Before; // (undocumented) 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 interface RecordsDiff { // (undocumented) added: Record, R>; // (undocumented) removed: Record, R>; // (undocumented) 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 (undocumented) export interface StandaloneDependsOn { // (undocumented) readonly dependsOn: readonly MigrationId[]; } // @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: Record) => Result | undefined, isEqual?: ((a: Record, b: Record) => boolean) | undefined) => ComputedCache; createSelectedComputedCache: (name: string, selector: (record: Record) => Selection | undefined, derive: (input: Selection) => Result | 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; // @deprecated (undocumented) getSnapshot(scope?: 'all' | RecordScope): StoreSnapshot; getStoreSnapshot(scope?: 'all' | RecordScope): StoreSnapshot; has: >(id: K) => boolean; readonly history: Atom>; readonly id: string; // @internal (undocumented) isPossiblyCorrupted(): boolean; listen: (onHistory: StoreListener, filters?: Partial) => () => void; // @deprecated (undocumented) loadSnapshot(snapshot: StoreSnapshot): void; loadStoreSnapshot(snapshot: StoreSnapshot): void; // @internal (undocumented) markAsPossiblyCorrupted(): void; mergeRemoteChanges: (fn: () => void) => void; migrateSnapshot(snapshot: StoreSnapshot): StoreSnapshot; // (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; // (undocumented) readonly sideEffects: StoreSideEffects; 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 StoreAfterChangeHandler = (prev: R, next: R, source: 'remote' | 'user') => void; // @public (undocumented) export type StoreAfterCreateHandler = (record: R, source: 'remote' | 'user') => void; // @public (undocumented) export type StoreAfterDeleteHandler = (record: R, source: 'remote' | 'user') => void; // @public (undocumented) export type StoreBeforeChangeHandler = (prev: R, next: R, source: 'remote' | 'user') => R; // @public (undocumented) export type StoreBeforeCreateHandler = (record: R, source: 'remote' | 'user') => R; // @public (undocumented) export type StoreBeforeDeleteHandler = (record: R, source: 'remote' | 'user') => false | void; // @public (undocumented) export interface StoreError { // (undocumented) error: Error; // (undocumented) isExistingValidationIssue: boolean; // (undocumented) phase: 'createRecord' | 'initialize' | 'tests' | 'updateRecord'; // (undocumented) recordAfter: unknown; // (undocumented) recordBefore?: unknown; } // @public export type StoreListener = (entry: HistoryEntry) => void; // @public (undocumented) export type StoreOperationCompleteHandler = (source: 'remote' | 'user') => 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 interface StoreSchemaOptions { // @internal (undocumented) createIntegrityChecker?: (store: Store) => void; // (undocumented) migrations?: MigrationSequence[]; // (undocumented) onValidationFailure?: (data: { error: unknown; phase: 'createRecord' | 'initialize' | 'tests' | 'updateRecord'; record: R; recordBefore: null | R; store: Store; }) => R; } // @public export class StoreSideEffects { constructor(store: Store); // @internal (undocumented) handleAfterChange(prev: R, next: R, source: 'remote' | 'user'): void; // @internal (undocumented) handleAfterCreate(record: R, source: 'remote' | 'user'): void; // @internal (undocumented) handleAfterDelete(record: R, source: 'remote' | 'user'): void; // @internal (undocumented) handleBeforeChange(prev: R, next: R, source: 'remote' | 'user'): R; // @internal (undocumented) handleBeforeCreate(record: R, source: 'remote' | 'user'): R; // @internal (undocumented) handleBeforeDelete(record: R, source: 'remote' | 'user'): boolean; // @internal (undocumented) handleOperationComplete(source: 'remote' | 'user'): void; // @internal (undocumented) isEnabled(): boolean; // @internal register(handlersByType: { [T in R as T['typeName']]?: { afterChange?: StoreAfterChangeHandler; afterCreate?: StoreAfterCreateHandler; afterDelete?: StoreAfterDeleteHandler; beforeChange?: StoreBeforeChangeHandler; beforeCreate?: StoreBeforeCreateHandler; beforeDelete?: StoreBeforeDeleteHandler; }; }): () => void; registerAfterChangeHandler(typeName: T, handler: StoreAfterChangeHandler): () => void; registerAfterCreateHandler(typeName: T, handler: StoreAfterCreateHandler): () => void; registerAfterDeleteHandler(typeName: T, handler: StoreAfterDeleteHandler): () => void; registerBeforeChangeHandler(typeName: T, handler: StoreBeforeChangeHandler): () => void; registerBeforeCreateHandler(typeName: T, handler: StoreBeforeCreateHandler): () => void; registerBeforeDeleteHandler(typeName: T, handler: StoreBeforeDeleteHandler): () => void; registerOperationCompleteHandler(handler: StoreOperationCompleteHandler): () => void; // @internal (undocumented) setIsEnabled(enabled: boolean): void; } // @public (undocumented) export interface StoreSnapshot { // (undocumented) schema: SerializedSchema; // (undocumented) store: SerializedStore; } // @public (undocumented) export interface StoreValidator { // (undocumented) validate: (record: unknown) => R; // (undocumented) 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) ```