2023-04-25 11:01:25 +00:00
|
|
|
## 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';
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export type AllRecords<T extends Store<any>> = ExtractR<ExtractRecordType<T>>;
|
|
|
|
|
|
|
|
// @public
|
2023-05-24 11:25:41 +00:00
|
|
|
export function assertIdType<R extends UnknownRecord>(id: string | undefined, type: RecordType<R, any>): asserts id is IdOf<R>;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public
|
2023-05-24 11:25:41 +00:00
|
|
|
export interface BaseRecord<TypeName extends string, Id extends ID<UnknownRecord>> {
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
2023-05-24 11:25:41 +00:00
|
|
|
readonly id: Id;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
|
|
|
readonly typeName: TypeName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export type CollectionDiff<T> = {
|
|
|
|
added?: Set<T>;
|
|
|
|
removed?: Set<T>;
|
|
|
|
};
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export function compareRecordVersions(a: RecordVersion, b: RecordVersion): -1 | 0 | 1;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
derived presence state (#1204)
This PR adds
- A new `TLInstancePresence` record type, to collect info about the
presence state in a particular instance of the editor. This will
eventually be used to sync presence data instead of sending
instance-only state across the wire.
- **Record Scopes**
`RecordType` now has a `scope` property which can be one of three
things:
- `document`: the record belongs to the document and should be synced
and persisted freely. Currently: `TLDocument`, `TLPage`, `TLShape`, and
`TLAsset`
- `instance`: the record belongs to a single instance of the store and
should not be synced at all. It should not be persisted directly in most
cases, but rather compiled into a kind of 'instance configuration' to
store alongside the local document data so that when reopening the
associated document it can remember some of the previous instance state.
Currently: `TLInstance`, `TLInstancePageState`, `TLCamera`, `TLUser`,
`TLUserDocument`, `TLUserPresence`
- `presence`: the record belongs to a single instance of the store and
should not be persisted, but may be synced using the special presence
sync protocol. Currently just `TLInstancePresence`
This sets us up for the following changes, which are gonna be pretty
high-impact in terms of integrating tldraw into existing systems:
- Removing `instanceId` as a config option. Each instance gets a
randomly generated ID.
- We'd replace it with an `instanceConfig` option that has stuff like
selectedIds, camera positions, and so on. Then it's up to library users
to get and reinstate the instance config at persistence boundaries.
- Removing `userId` as config option, and removing the `TLUser` type
altogether.
- We might need to revisit when doing auth-enabled features like locking
shapes, but I suspect that will be separate.
2023-04-27 18:03:19 +00:00
|
|
|
export const compareSchemas: (a: SerializedSchema, b: SerializedSchema) => -1 | 0 | 1;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public
|
2023-05-24 11:25:41 +00:00
|
|
|
export type ComputedCache<Data, R extends UnknownRecord> = {
|
|
|
|
get(id: IdOf<R>): Data | undefined;
|
2023-04-25 11:01:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// @public
|
2023-05-24 11:25:41 +00:00
|
|
|
export function createRecordType<R extends UnknownRecord>(typeName: R['typeName'], config: {
|
2023-04-25 11:01:25 +00:00
|
|
|
migrations?: Migrations;
|
2023-05-23 12:32:42 +00:00
|
|
|
validator?: StoreValidator<R>;
|
derived presence state (#1204)
This PR adds
- A new `TLInstancePresence` record type, to collect info about the
presence state in a particular instance of the editor. This will
eventually be used to sync presence data instead of sending
instance-only state across the wire.
- **Record Scopes**
`RecordType` now has a `scope` property which can be one of three
things:
- `document`: the record belongs to the document and should be synced
and persisted freely. Currently: `TLDocument`, `TLPage`, `TLShape`, and
`TLAsset`
- `instance`: the record belongs to a single instance of the store and
should not be synced at all. It should not be persisted directly in most
cases, but rather compiled into a kind of 'instance configuration' to
store alongside the local document data so that when reopening the
associated document it can remember some of the previous instance state.
Currently: `TLInstance`, `TLInstancePageState`, `TLCamera`, `TLUser`,
`TLUserDocument`, `TLUserPresence`
- `presence`: the record belongs to a single instance of the store and
should not be persisted, but may be synced using the special presence
sync protocol. Currently just `TLInstancePresence`
This sets us up for the following changes, which are gonna be pretty
high-impact in terms of integrating tldraw into existing systems:
- Removing `instanceId` as a config option. Each instance gets a
randomly generated ID.
- We'd replace it with an `instanceConfig` option that has stuff like
selectedIds, camera positions, and so on. Then it's up to library users
to get and reinstate the instance config at persistence boundaries.
- Removing `userId` as config option, and removing the `TLUser` type
altogether.
- We might need to revisit when doing auth-enabled features like locking
shapes, but I suspect that will be separate.
2023-04-27 18:03:19 +00:00
|
|
|
scope: Scope;
|
2023-04-25 11:01:25 +00:00
|
|
|
}): RecordType<R, keyof Omit<R, 'id' | 'typeName'>>;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
2023-05-22 21:46:24 +00:00
|
|
|
export function defineMigrations<FirstVersion extends EMPTY_SYMBOL | number = EMPTY_SYMBOL, CurrentVersion extends EMPTY_SYMBOL | Exclude<number, 0> = EMPTY_SYMBOL>(opts: {
|
|
|
|
firstVersion?: CurrentVersion extends number ? FirstVersion : never;
|
|
|
|
currentVersion?: CurrentVersion;
|
|
|
|
migrators?: CurrentVersion extends number ? FirstVersion extends number ? CurrentVersion extends FirstVersion ? {
|
|
|
|
[version in Exclude<Range_2<1, CurrentVersion>, 0>]: Migration;
|
|
|
|
} : {
|
2023-04-25 11:01:25 +00:00
|
|
|
[version in Exclude<Range_2<FirstVersion, CurrentVersion>, FirstVersion>]: Migration;
|
2023-05-22 21:46:24 +00:00
|
|
|
} : {
|
|
|
|
[version in Exclude<Range_2<1, CurrentVersion>, 0>]: Migration;
|
|
|
|
} : never;
|
2023-04-25 11:01:25 +00:00
|
|
|
subTypeKey?: string;
|
|
|
|
subTypeMigrations?: Record<string, BaseMigrationsInfo>;
|
|
|
|
}): Migrations;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function devFreeze<T>(object: T): T;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
2023-05-24 11:25:41 +00:00
|
|
|
export function getRecordVersion(record: UnknownRecord, serializedSchema: SerializedSchema): RecordVersion;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public
|
2023-05-24 11:25:41 +00:00
|
|
|
export type HistoryEntry<R extends UnknownRecord = UnknownRecord> = {
|
2023-04-25 11:01:25 +00:00
|
|
|
changes: RecordsDiff<R>;
|
|
|
|
source: 'remote' | 'user';
|
|
|
|
};
|
|
|
|
|
|
|
|
// @public (undocumented)
|
2023-05-24 11:25:41 +00:00
|
|
|
export type ID<R extends UnknownRecord> = string & {
|
2023-04-25 11:01:25 +00:00
|
|
|
__type__: R;
|
|
|
|
};
|
|
|
|
|
2023-05-24 11:25:41 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export type IdOf<R extends UnknownRecord> = R['id'];
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @internal
|
|
|
|
export class IncrementalSetConstructor<T> {
|
|
|
|
constructor(
|
|
|
|
previousValue: Set<T>);
|
|
|
|
// @public
|
|
|
|
add(item: T): void;
|
|
|
|
// @public
|
|
|
|
get(): {
|
|
|
|
value: Set<T>;
|
|
|
|
diff: CollectionDiff<T>;
|
|
|
|
} | undefined;
|
|
|
|
// @public
|
|
|
|
remove(item: T): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export function migrate<T>({ value, migrations, fromVersion, toVersion, }: {
|
|
|
|
value: unknown;
|
|
|
|
migrations: Migrations;
|
|
|
|
fromVersion: number;
|
|
|
|
toVersion: number;
|
|
|
|
}): MigrationResult<T>;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
2023-05-24 11:25:41 +00:00
|
|
|
export function migrateRecord<R extends UnknownRecord>({ record, migrations, fromVersion, toVersion, }: {
|
2023-04-25 11:01:25 +00:00
|
|
|
record: unknown;
|
|
|
|
migrations: Migrations;
|
|
|
|
fromVersion: number;
|
|
|
|
toVersion: number;
|
|
|
|
}): MigrationResult<R>;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
2023-05-22 21:46:24 +00:00
|
|
|
export type Migration<Before = any, After = any> = {
|
|
|
|
up: (oldState: Before) => After;
|
|
|
|
down: (newState: After) => Before;
|
2023-04-25 11:01:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// @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<T> = {
|
|
|
|
type: 'error';
|
|
|
|
reason: MigrationFailureReason;
|
|
|
|
} | {
|
|
|
|
type: 'success';
|
|
|
|
value: T;
|
|
|
|
};
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export interface Migrations extends BaseMigrationsInfo {
|
|
|
|
// (undocumented)
|
|
|
|
subTypeKey?: string;
|
|
|
|
// (undocumented)
|
|
|
|
subTypeMigrations?: Record<string, BaseMigrationsInfo>;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public
|
2023-05-24 11:25:41 +00:00
|
|
|
export type RecordsDiff<R extends UnknownRecord> = {
|
|
|
|
added: Record<IdOf<R>, R>;
|
|
|
|
updated: Record<IdOf<R>, [from: R, to: R]>;
|
|
|
|
removed: Record<IdOf<R>, R>;
|
2023-04-25 11:01:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// @public
|
2023-05-24 11:25:41 +00:00
|
|
|
export class RecordType<R extends UnknownRecord, RequiredProperties extends keyof Omit<R, 'id' | 'typeName'>> {
|
2023-04-25 11:01:25 +00:00
|
|
|
constructor(
|
|
|
|
typeName: R['typeName'], config: {
|
|
|
|
readonly createDefaultProperties: () => Exclude<OmitMeta<R>, RequiredProperties>;
|
|
|
|
readonly migrations: Migrations;
|
|
|
|
readonly validator?: {
|
|
|
|
validate: (r: unknown) => R;
|
|
|
|
} | StoreValidator<R>;
|
derived presence state (#1204)
This PR adds
- A new `TLInstancePresence` record type, to collect info about the
presence state in a particular instance of the editor. This will
eventually be used to sync presence data instead of sending
instance-only state across the wire.
- **Record Scopes**
`RecordType` now has a `scope` property which can be one of three
things:
- `document`: the record belongs to the document and should be synced
and persisted freely. Currently: `TLDocument`, `TLPage`, `TLShape`, and
`TLAsset`
- `instance`: the record belongs to a single instance of the store and
should not be synced at all. It should not be persisted directly in most
cases, but rather compiled into a kind of 'instance configuration' to
store alongside the local document data so that when reopening the
associated document it can remember some of the previous instance state.
Currently: `TLInstance`, `TLInstancePageState`, `TLCamera`, `TLUser`,
`TLUserDocument`, `TLUserPresence`
- `presence`: the record belongs to a single instance of the store and
should not be persisted, but may be synced using the special presence
sync protocol. Currently just `TLInstancePresence`
This sets us up for the following changes, which are gonna be pretty
high-impact in terms of integrating tldraw into existing systems:
- Removing `instanceId` as a config option. Each instance gets a
randomly generated ID.
- We'd replace it with an `instanceConfig` option that has stuff like
selectedIds, camera positions, and so on. Then it's up to library users
to get and reinstate the instance config at persistence boundaries.
- Removing `userId` as config option, and removing the `TLUser` type
altogether.
- We might need to revisit when doing auth-enabled features like locking
shapes, but I suspect that will be separate.
2023-04-27 18:03:19 +00:00
|
|
|
readonly scope?: Scope;
|
2023-04-25 11:01:25 +00:00
|
|
|
});
|
|
|
|
clone(record: R): R;
|
|
|
|
create(properties: Pick<R, RequiredProperties> & Omit<Partial<R>, RequiredProperties>): R;
|
2023-05-24 11:25:41 +00:00
|
|
|
createCustomId(id: string): IdOf<R>;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
|
|
|
readonly createDefaultProperties: () => Exclude<OmitMeta<R>, RequiredProperties>;
|
2023-05-24 11:25:41 +00:00
|
|
|
createId(): IdOf<R>;
|
|
|
|
isId(id?: string): id is IdOf<R>;
|
|
|
|
isInstance: (record?: UnknownRecord) => record is R;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
|
|
|
readonly migrations: Migrations;
|
2023-05-24 11:25:41 +00:00
|
|
|
parseId(id: string): IdOf<R>;
|
derived presence state (#1204)
This PR adds
- A new `TLInstancePresence` record type, to collect info about the
presence state in a particular instance of the editor. This will
eventually be used to sync presence data instead of sending
instance-only state across the wire.
- **Record Scopes**
`RecordType` now has a `scope` property which can be one of three
things:
- `document`: the record belongs to the document and should be synced
and persisted freely. Currently: `TLDocument`, `TLPage`, `TLShape`, and
`TLAsset`
- `instance`: the record belongs to a single instance of the store and
should not be synced at all. It should not be persisted directly in most
cases, but rather compiled into a kind of 'instance configuration' to
store alongside the local document data so that when reopening the
associated document it can remember some of the previous instance state.
Currently: `TLInstance`, `TLInstancePageState`, `TLCamera`, `TLUser`,
`TLUserDocument`, `TLUserPresence`
- `presence`: the record belongs to a single instance of the store and
should not be persisted, but may be synced using the special presence
sync protocol. Currently just `TLInstancePresence`
This sets us up for the following changes, which are gonna be pretty
high-impact in terms of integrating tldraw into existing systems:
- Removing `instanceId` as a config option. Each instance gets a
randomly generated ID.
- We'd replace it with an `instanceConfig` option that has stuff like
selectedIds, camera positions, and so on. Then it's up to library users
to get and reinstate the instance config at persistence boundaries.
- Removing `userId` as config option, and removing the `TLUser` type
altogether.
- We might need to revisit when doing auth-enabled features like locking
shapes, but I suspect that will be separate.
2023-04-27 18:03:19 +00:00
|
|
|
// (undocumented)
|
|
|
|
readonly scope: Scope;
|
2023-04-25 11:01:25 +00:00
|
|
|
readonly typeName: R['typeName'];
|
|
|
|
validate(record: unknown): R;
|
|
|
|
// (undocumented)
|
|
|
|
readonly validator: {
|
|
|
|
validate: (r: unknown) => R;
|
|
|
|
} | StoreValidator<R>;
|
|
|
|
withDefaultProperties<DefaultProps extends Omit<Partial<R>, 'id' | 'typeName'>>(createDefaultProperties: () => DefaultProps): RecordType<R, Exclude<RequiredProperties, keyof DefaultProps>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export type RecordVersion = {
|
|
|
|
rootVersion: number;
|
|
|
|
subTypeVersion?: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export function reverseRecordsDiff(diff: RecordsDiff<any>): RecordsDiff<any>;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export interface SerializedSchema {
|
|
|
|
recordVersions: Record<string, {
|
|
|
|
version: number;
|
|
|
|
subTypeVersions: Record<string, number>;
|
|
|
|
subTypeKey: string;
|
|
|
|
} | {
|
|
|
|
version: number;
|
|
|
|
}>;
|
|
|
|
schemaVersion: number;
|
|
|
|
storeVersion: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public
|
2023-05-24 11:25:41 +00:00
|
|
|
export function squashRecordDiffs<T extends UnknownRecord>(diffs: RecordsDiff<T>[]): RecordsDiff<T>;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public
|
2023-05-24 11:25:41 +00:00
|
|
|
export class Store<R extends UnknownRecord = UnknownRecord, Props = unknown> {
|
2023-04-25 11:01:25 +00:00
|
|
|
constructor(config: {
|
|
|
|
initialData?: StoreSnapshot<R>;
|
|
|
|
schema: StoreSchema<R, Props>;
|
|
|
|
props: Props;
|
|
|
|
});
|
|
|
|
allRecords: () => R[];
|
|
|
|
// (undocumented)
|
|
|
|
applyDiff(diff: RecordsDiff<R>, runCallbacks?: boolean): void;
|
|
|
|
clear: () => void;
|
|
|
|
createComputedCache: <T, V extends R = R>(name: string, derive: (record: V) => T | undefined) => ComputedCache<T, V>;
|
|
|
|
createSelectedComputedCache: <T, J, V extends R = R>(name: string, selector: (record: V) => T | undefined, derive: (input: T) => J | undefined) => ComputedCache<J, V>;
|
|
|
|
deserialize: (snapshot: StoreSnapshot<R>) => void;
|
|
|
|
// @internal (undocumented)
|
|
|
|
ensureStoreIsUsable(): void;
|
|
|
|
// (undocumented)
|
|
|
|
extractingChanges(fn: () => void): RecordsDiff<R>;
|
|
|
|
// (undocumented)
|
|
|
|
_flushHistory(): void;
|
2023-05-24 11:25:41 +00:00
|
|
|
get: <K extends IdOf<R>>(id: K) => RecFromId<K> | undefined;
|
|
|
|
has: <K extends IdOf<R>>(id: K) => boolean;
|
2023-04-25 11:01:25 +00:00
|
|
|
readonly history: Atom<number, RecordsDiff<R>>;
|
|
|
|
// @internal (undocumented)
|
|
|
|
isPossiblyCorrupted(): boolean;
|
|
|
|
listen: (listener: StoreListener<R>) => () => 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<R>;
|
2023-05-24 11:25:41 +00:00
|
|
|
remove: (ids: IdOf<R>[]) => void;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
|
|
|
readonly schema: StoreSchema<R, Props>;
|
|
|
|
serialize: (filter?: ((record: R) => boolean) | undefined) => StoreSnapshot<R>;
|
2023-05-17 16:17:31 +00:00
|
|
|
serializeDocumentState: () => StoreSnapshot<R>;
|
2023-05-24 11:25:41 +00:00
|
|
|
unsafeGetWithoutCapture: <K extends IdOf<R>>(id: K) => RecFromId<K> | undefined;
|
|
|
|
update: <K extends IdOf<R>>(id: K, updater: (record: RecFromId<K>) => RecFromId<K>) => void;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (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
|
2023-05-24 11:25:41 +00:00
|
|
|
export type StoreListener<R extends UnknownRecord> = (entry: HistoryEntry<R>) => void;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public (undocumented)
|
2023-05-24 11:25:41 +00:00
|
|
|
export class StoreSchema<R extends UnknownRecord, P = unknown> {
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
2023-05-24 11:25:41 +00:00
|
|
|
static create<R extends UnknownRecord, P = unknown>(types: {
|
2023-04-25 11:01:25 +00:00
|
|
|
[TypeName in R['typeName']]: {
|
|
|
|
createId: any;
|
|
|
|
};
|
|
|
|
}, options?: StoreSchemaOptions<R, P>): StoreSchema<R, P>;
|
2023-05-12 11:39:36 +00:00
|
|
|
// @internal (undocumented)
|
|
|
|
createIntegrityChecker(store: Store<R, P>): (() => void) | undefined;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
|
|
|
get currentStoreVersion(): number;
|
|
|
|
// (undocumented)
|
|
|
|
migratePersistedRecord(record: R, persistedSchema: SerializedSchema, direction?: 'down' | 'up'): MigrationResult<R>;
|
|
|
|
// (undocumented)
|
|
|
|
migrateStoreSnapshot(storeSnapshot: StoreSnapshot<R>, persistedSchema: SerializedSchema): MigrationResult<StoreSnapshot<R>>;
|
|
|
|
// (undocumented)
|
|
|
|
serialize(): SerializedSchema;
|
|
|
|
// (undocumented)
|
|
|
|
serializeEarliestVersion(): SerializedSchema;
|
|
|
|
// (undocumented)
|
|
|
|
readonly types: {
|
|
|
|
[Record in R as Record['typeName']]: RecordType<R, any>;
|
|
|
|
};
|
|
|
|
// (undocumented)
|
|
|
|
validateRecord(store: Store<R>, record: R, phase: 'createRecord' | 'initialize' | 'tests' | 'updateRecord', recordBefore: null | R): R;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public (undocumented)
|
2023-05-24 11:25:41 +00:00
|
|
|
export type StoreSchemaOptions<R extends UnknownRecord, P> = {
|
2023-04-25 11:01:25 +00:00
|
|
|
snapshotMigrations?: Migrations;
|
|
|
|
onValidationFailure?: (data: {
|
|
|
|
error: unknown;
|
|
|
|
store: Store<R>;
|
|
|
|
record: R;
|
|
|
|
phase: 'createRecord' | 'initialize' | 'tests' | 'updateRecord';
|
|
|
|
recordBefore: null | R;
|
|
|
|
}) => R;
|
2023-05-12 11:39:36 +00:00
|
|
|
createIntegrityChecker?: (store: Store<R, P>) => void;
|
2023-04-25 11:01:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// @public
|
2023-05-24 11:25:41 +00:00
|
|
|
export type StoreSnapshot<R extends UnknownRecord> = Record<IdOf<R>, R>;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public (undocumented)
|
2023-05-24 11:25:41 +00:00
|
|
|
export type StoreValidator<R extends UnknownRecord> = {
|
2023-04-25 11:01:25 +00:00
|
|
|
validate: (record: unknown) => R;
|
|
|
|
};
|
|
|
|
|
|
|
|
// @public (undocumented)
|
2023-05-24 11:25:41 +00:00
|
|
|
export type StoreValidators<R extends UnknownRecord> = {
|
2023-04-25 11:01:25 +00:00
|
|
|
[K in R['typeName']]: StoreValidator<Extract<R, {
|
|
|
|
typeName: K;
|
|
|
|
}>>;
|
|
|
|
};
|
|
|
|
|
2023-05-24 11:25:41 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export type UnknownRecord = BaseRecord<string, ID<UnknownRecord>>;
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// (No @packageDocumentation comment for this package)
|
|
|
|
|
|
|
|
```
|