2023-06-03 08:59:04 +00:00
|
|
|
## API Report File for "@tldraw/store"
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
2023-06-20 13:31:26 +00:00
|
|
|
import { Atom } from '@tldraw/state';
|
|
|
|
import { Computed } from '@tldraw/state';
|
2024-04-15 12:53:42 +00:00
|
|
|
import { Result } from '@tldraw/utils';
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @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-06-03 20:46:53 +00:00
|
|
|
export interface BaseRecord<TypeName extends string, Id extends RecordId<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
|
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
|
|
|
};
|
|
|
|
|
2024-04-15 12:53:42 +00:00
|
|
|
// @public
|
|
|
|
export function createMigrationIds<ID extends string, Versions extends Record<string, number>>(sequenceId: ID, versions: Versions): {
|
|
|
|
[K in keyof Versions]: `${ID}/${Versions[K]}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function createMigrationSequence({ sequence, sequenceId, retroactive, }: {
|
|
|
|
retroactive?: boolean;
|
|
|
|
sequence: Array<Migration | StandaloneDependsOn>;
|
|
|
|
sequenceId: string;
|
|
|
|
}): MigrationSequence;
|
|
|
|
|
|
|
|
// @internal (undocumented)
|
|
|
|
export function createRecordMigrationSequence(opts: {
|
|
|
|
filter?: (record: UnknownRecord) => boolean;
|
|
|
|
recordType: string;
|
|
|
|
retroactive?: boolean;
|
|
|
|
sequence: Omit<Extract<Migration, {
|
|
|
|
scope: 'record';
|
|
|
|
}>, 'scope'>[];
|
|
|
|
sequenceId: string;
|
|
|
|
}): MigrationSequence;
|
|
|
|
|
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: {
|
Independent instance state persistence (#1493)
This PR
- Removes UserDocumentRecordType
- moving isSnapMode to user preferences
- moving isGridMode and isPenMode to InstanceRecordType
- deleting the other properties which are no longer needed.
- Creates a separate pipeline for persisting instance state.
Previously the instance state records were stored alongside the document
state records, and in order to load the state for a particular instance
(in our case, a particular tab) you needed to pass the 'instanceId'
prop. This prop ended up totally pervading the public API and people ran
into all kinds of issues with it, e.g. using the same instance id in
multiple editor instances.
There was also an issue whereby it was hard for us to clean up old
instance state so the idb table ended up bloating over time.
This PR makes it so that rather than passing an instanceId, you load the
instance state yourself while creating the store. It provides tools to
make that easy.
- Undoes the assumption that we might have more than one instance's
state in the store.
- Like `document`, `instance` now has a singleton id
`instance:instance`.
- Page state ids and camera ids are no longer random, but rather derive
from the page they belong to. This is like having a foreign primary key
in SQL databases. It's something i'd love to support fully as part of
the RecordType/Store api.
Tests to do
- [x] Test Migrations
- [x] Test Store.listen filtering
- [x] Make type sets in Store public and readonly
- [x] Test RecordType.createId
- [x] Test Instance state snapshot loading/exporting
- [x] Manual test File I/O
- [x] Manual test Vscode extension with multiple tabs
- [x] Audit usages of store.query
- [x] Audit usages of changed types: InstanceRecordType, 'instance',
InstancePageStateRecordType, 'instance_page_state', 'user_document',
'camera', CameraRecordType, InstancePresenceRecordType,
'instance_presence'
- [x] Test user preferences
- [x] Manual test isSnapMode and isGridMode and isPenMode
- [ ] Test indexedDb functions
- [x] Add instanceId stuff back
### Change Type
- [x] `major` — Breaking Change
### Test Plan
1. Add a step-by-step description of how to test your PR here.
2.
- [ ] Unit Tests
- [ ] Webdriver tests
### Release Notes
- Add a brief release note for your PR here.
2023-06-05 14:11:07 +00:00
|
|
|
scope: RecordScope;
|
2024-04-15 12:53:42 +00:00
|
|
|
validator?: StoreValidator<R>;
|
2023-04-25 11:01:25 +00:00
|
|
|
}): RecordType<R, keyof Omit<R, 'id' | 'typeName'>>;
|
|
|
|
|
2024-04-15 12:53:42 +00:00
|
|
|
// @public @deprecated (undocumented)
|
|
|
|
export function defineMigrations(opts: {
|
|
|
|
currentVersion?: number;
|
|
|
|
firstVersion?: number;
|
|
|
|
migrators?: Record<number, LegacyMigration>;
|
2023-04-25 11:01:25 +00:00
|
|
|
subTypeKey?: string;
|
2024-04-15 12:53:42 +00:00
|
|
|
subTypeMigrations?: Record<string, LegacyBaseMigrationsInfo>;
|
|
|
|
}): LegacyMigrations;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public
|
|
|
|
export function devFreeze<T>(object: T): T;
|
|
|
|
|
|
|
|
// @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>;
|
Independent instance state persistence (#1493)
This PR
- Removes UserDocumentRecordType
- moving isSnapMode to user preferences
- moving isGridMode and isPenMode to InstanceRecordType
- deleting the other properties which are no longer needed.
- Creates a separate pipeline for persisting instance state.
Previously the instance state records were stored alongside the document
state records, and in order to load the state for a particular instance
(in our case, a particular tab) you needed to pass the 'instanceId'
prop. This prop ended up totally pervading the public API and people ran
into all kinds of issues with it, e.g. using the same instance id in
multiple editor instances.
There was also an issue whereby it was hard for us to clean up old
instance state so the idb table ended up bloating over time.
This PR makes it so that rather than passing an instanceId, you load the
instance state yourself while creating the store. It provides tools to
make that easy.
- Undoes the assumption that we might have more than one instance's
state in the store.
- Like `document`, `instance` now has a singleton id
`instance:instance`.
- Page state ids and camera ids are no longer random, but rather derive
from the page they belong to. This is like having a foreign primary key
in SQL databases. It's something i'd love to support fully as part of
the RecordType/Store api.
Tests to do
- [x] Test Migrations
- [x] Test Store.listen filtering
- [x] Make type sets in Store public and readonly
- [x] Test RecordType.createId
- [x] Test Instance state snapshot loading/exporting
- [x] Manual test File I/O
- [x] Manual test Vscode extension with multiple tabs
- [x] Audit usages of store.query
- [x] Audit usages of changed types: InstanceRecordType, 'instance',
InstancePageStateRecordType, 'instance_page_state', 'user_document',
'camera', CameraRecordType, InstancePresenceRecordType,
'instance_presence'
- [x] Test user preferences
- [x] Manual test isSnapMode and isGridMode and isPenMode
- [ ] Test indexedDb functions
- [x] Add instanceId stuff back
### Change Type
- [x] `major` — Breaking Change
### Test Plan
1. Add a step-by-step description of how to test your PR here.
2.
- [ ] Unit Tests
- [ ] Webdriver tests
### Release Notes
- Add a brief release note for your PR here.
2023-06-05 14:11:07 +00:00
|
|
|
source: ChangeSource;
|
2023-04-25 11:01:25 +00:00
|
|
|
};
|
|
|
|
|
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(): {
|
|
|
|
diff: CollectionDiff<T>;
|
2024-04-15 12:53:42 +00:00
|
|
|
value: Set<T>;
|
2023-04-25 11:01:25 +00:00
|
|
|
} | undefined;
|
|
|
|
// @public
|
|
|
|
remove(item: T): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public (undocumented)
|
2024-04-15 12:53:42 +00:00
|
|
|
export type LegacyMigration<Before = any, After = any> = {
|
|
|
|
down: (newState: After) => Before;
|
|
|
|
up: (oldState: Before) => After;
|
|
|
|
};
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public (undocumented)
|
2024-04-15 12:53:42 +00:00
|
|
|
export interface LegacyMigrations extends LegacyBaseMigrationsInfo {
|
|
|
|
// (undocumented)
|
|
|
|
subTypeKey?: string;
|
|
|
|
// (undocumented)
|
|
|
|
subTypeMigrations?: Record<string, LegacyBaseMigrationsInfo>;
|
|
|
|
}
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public (undocumented)
|
2024-04-15 12:53:42 +00:00
|
|
|
export type Migration = {
|
|
|
|
readonly dependsOn?: readonly MigrationId[] | undefined;
|
|
|
|
readonly id: MigrationId;
|
|
|
|
} & ({
|
|
|
|
readonly down?: (newState: SerializedStore<UnknownRecord>) => SerializedStore<UnknownRecord> | void;
|
|
|
|
readonly scope: 'store';
|
|
|
|
readonly up: (oldState: SerializedStore<UnknownRecord>) => SerializedStore<UnknownRecord> | void;
|
|
|
|
} | {
|
|
|
|
readonly down?: (newState: UnknownRecord) => UnknownRecord | void;
|
|
|
|
readonly filter?: (record: UnknownRecord) => boolean;
|
|
|
|
readonly scope: 'record';
|
|
|
|
readonly up: (oldState: UnknownRecord) => UnknownRecord | void;
|
|
|
|
});
|
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"
|
|
|
|
}
|
|
|
|
|
2024-04-15 12:53:42 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export type MigrationId = `${string}/${number}`;
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export type MigrationResult<T> = {
|
|
|
|
reason: MigrationFailureReason;
|
2024-04-15 12:53:42 +00:00
|
|
|
type: 'error';
|
2023-04-25 11:01:25 +00:00
|
|
|
} | {
|
|
|
|
type: 'success';
|
|
|
|
value: T;
|
|
|
|
};
|
|
|
|
|
|
|
|
// @public (undocumented)
|
2024-04-15 12:53:42 +00:00
|
|
|
export interface MigrationSequence {
|
|
|
|
retroactive: boolean;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
2024-04-15 12:53:42 +00:00
|
|
|
sequence: Migration[];
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
2024-04-15 12:53:42 +00:00
|
|
|
sequenceId: string;
|
2023-04-25 11:01:25 +00:00
|
|
|
}
|
|
|
|
|
2024-04-15 12:53:42 +00:00
|
|
|
// @internal (undocumented)
|
|
|
|
export function parseMigrationId(id: MigrationId): {
|
|
|
|
sequenceId: string;
|
|
|
|
version: number;
|
|
|
|
};
|
|
|
|
|
2023-06-03 20:46:53 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export type RecordId<R extends UnknownRecord> = string & {
|
|
|
|
__type__: R;
|
|
|
|
};
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @public
|
2023-05-24 11:25:41 +00:00
|
|
|
export type RecordsDiff<R extends UnknownRecord> = {
|
|
|
|
added: Record<IdOf<R>, R>;
|
|
|
|
removed: Record<IdOf<R>, R>;
|
2024-04-15 12:53:42 +00:00
|
|
|
updated: Record<IdOf<R>, [from: R, to: 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>;
|
Independent instance state persistence (#1493)
This PR
- Removes UserDocumentRecordType
- moving isSnapMode to user preferences
- moving isGridMode and isPenMode to InstanceRecordType
- deleting the other properties which are no longer needed.
- Creates a separate pipeline for persisting instance state.
Previously the instance state records were stored alongside the document
state records, and in order to load the state for a particular instance
(in our case, a particular tab) you needed to pass the 'instanceId'
prop. This prop ended up totally pervading the public API and people ran
into all kinds of issues with it, e.g. using the same instance id in
multiple editor instances.
There was also an issue whereby it was hard for us to clean up old
instance state so the idb table ended up bloating over time.
This PR makes it so that rather than passing an instanceId, you load the
instance state yourself while creating the store. It provides tools to
make that easy.
- Undoes the assumption that we might have more than one instance's
state in the store.
- Like `document`, `instance` now has a singleton id
`instance:instance`.
- Page state ids and camera ids are no longer random, but rather derive
from the page they belong to. This is like having a foreign primary key
in SQL databases. It's something i'd love to support fully as part of
the RecordType/Store api.
Tests to do
- [x] Test Migrations
- [x] Test Store.listen filtering
- [x] Make type sets in Store public and readonly
- [x] Test RecordType.createId
- [x] Test Instance state snapshot loading/exporting
- [x] Manual test File I/O
- [x] Manual test Vscode extension with multiple tabs
- [x] Audit usages of store.query
- [x] Audit usages of changed types: InstanceRecordType, 'instance',
InstancePageStateRecordType, 'instance_page_state', 'user_document',
'camera', CameraRecordType, InstancePresenceRecordType,
'instance_presence'
- [x] Test user preferences
- [x] Manual test isSnapMode and isGridMode and isPenMode
- [ ] Test indexedDb functions
- [x] Add instanceId stuff back
### Change Type
- [x] `major` — Breaking Change
### Test Plan
1. Add a step-by-step description of how to test your PR here.
2.
- [ ] Unit Tests
- [ ] Webdriver tests
### Release Notes
- Add a brief release note for your PR here.
2023-06-05 14:11:07 +00:00
|
|
|
readonly scope?: RecordScope;
|
2024-04-15 12:53:42 +00:00
|
|
|
readonly validator?: StoreValidator<R>;
|
2023-04-25 11:01:25 +00:00
|
|
|
});
|
|
|
|
clone(record: R): R;
|
|
|
|
create(properties: Pick<R, RequiredProperties> & Omit<Partial<R>, RequiredProperties>): R;
|
Independent instance state persistence (#1493)
This PR
- Removes UserDocumentRecordType
- moving isSnapMode to user preferences
- moving isGridMode and isPenMode to InstanceRecordType
- deleting the other properties which are no longer needed.
- Creates a separate pipeline for persisting instance state.
Previously the instance state records were stored alongside the document
state records, and in order to load the state for a particular instance
(in our case, a particular tab) you needed to pass the 'instanceId'
prop. This prop ended up totally pervading the public API and people ran
into all kinds of issues with it, e.g. using the same instance id in
multiple editor instances.
There was also an issue whereby it was hard for us to clean up old
instance state so the idb table ended up bloating over time.
This PR makes it so that rather than passing an instanceId, you load the
instance state yourself while creating the store. It provides tools to
make that easy.
- Undoes the assumption that we might have more than one instance's
state in the store.
- Like `document`, `instance` now has a singleton id
`instance:instance`.
- Page state ids and camera ids are no longer random, but rather derive
from the page they belong to. This is like having a foreign primary key
in SQL databases. It's something i'd love to support fully as part of
the RecordType/Store api.
Tests to do
- [x] Test Migrations
- [x] Test Store.listen filtering
- [x] Make type sets in Store public and readonly
- [x] Test RecordType.createId
- [x] Test Instance state snapshot loading/exporting
- [x] Manual test File I/O
- [x] Manual test Vscode extension with multiple tabs
- [x] Audit usages of store.query
- [x] Audit usages of changed types: InstanceRecordType, 'instance',
InstancePageStateRecordType, 'instance_page_state', 'user_document',
'camera', CameraRecordType, InstancePresenceRecordType,
'instance_presence'
- [x] Test user preferences
- [x] Manual test isSnapMode and isGridMode and isPenMode
- [ ] Test indexedDb functions
- [x] Add instanceId stuff back
### Change Type
- [x] `major` — Breaking Change
### Test Plan
1. Add a step-by-step description of how to test your PR here.
2.
- [ ] Unit Tests
- [ ] Webdriver tests
### Release Notes
- Add a brief release note for your PR here.
2023-06-05 14:11:07 +00:00
|
|
|
// @deprecated
|
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>;
|
Independent instance state persistence (#1493)
This PR
- Removes UserDocumentRecordType
- moving isSnapMode to user preferences
- moving isGridMode and isPenMode to InstanceRecordType
- deleting the other properties which are no longer needed.
- Creates a separate pipeline for persisting instance state.
Previously the instance state records were stored alongside the document
state records, and in order to load the state for a particular instance
(in our case, a particular tab) you needed to pass the 'instanceId'
prop. This prop ended up totally pervading the public API and people ran
into all kinds of issues with it, e.g. using the same instance id in
multiple editor instances.
There was also an issue whereby it was hard for us to clean up old
instance state so the idb table ended up bloating over time.
This PR makes it so that rather than passing an instanceId, you load the
instance state yourself while creating the store. It provides tools to
make that easy.
- Undoes the assumption that we might have more than one instance's
state in the store.
- Like `document`, `instance` now has a singleton id
`instance:instance`.
- Page state ids and camera ids are no longer random, but rather derive
from the page they belong to. This is like having a foreign primary key
in SQL databases. It's something i'd love to support fully as part of
the RecordType/Store api.
Tests to do
- [x] Test Migrations
- [x] Test Store.listen filtering
- [x] Make type sets in Store public and readonly
- [x] Test RecordType.createId
- [x] Test Instance state snapshot loading/exporting
- [x] Manual test File I/O
- [x] Manual test Vscode extension with multiple tabs
- [x] Audit usages of store.query
- [x] Audit usages of changed types: InstanceRecordType, 'instance',
InstancePageStateRecordType, 'instance_page_state', 'user_document',
'camera', CameraRecordType, InstancePresenceRecordType,
'instance_presence'
- [x] Test user preferences
- [x] Manual test isSnapMode and isGridMode and isPenMode
- [ ] Test indexedDb functions
- [x] Add instanceId stuff back
### Change Type
- [x] `major` — Breaking Change
### Test Plan
1. Add a step-by-step description of how to test your PR here.
2.
- [ ] Unit Tests
- [ ] Webdriver tests
### Release Notes
- Add a brief release note for your PR here.
2023-06-05 14:11:07 +00:00
|
|
|
createId(customUniquePart?: string): IdOf<R>;
|
2023-05-24 11:25:41 +00:00
|
|
|
isId(id?: string): id is IdOf<R>;
|
|
|
|
isInstance: (record?: UnknownRecord) => record is R;
|
Independent instance state persistence (#1493)
This PR
- Removes UserDocumentRecordType
- moving isSnapMode to user preferences
- moving isGridMode and isPenMode to InstanceRecordType
- deleting the other properties which are no longer needed.
- Creates a separate pipeline for persisting instance state.
Previously the instance state records were stored alongside the document
state records, and in order to load the state for a particular instance
(in our case, a particular tab) you needed to pass the 'instanceId'
prop. This prop ended up totally pervading the public API and people ran
into all kinds of issues with it, e.g. using the same instance id in
multiple editor instances.
There was also an issue whereby it was hard for us to clean up old
instance state so the idb table ended up bloating over time.
This PR makes it so that rather than passing an instanceId, you load the
instance state yourself while creating the store. It provides tools to
make that easy.
- Undoes the assumption that we might have more than one instance's
state in the store.
- Like `document`, `instance` now has a singleton id
`instance:instance`.
- Page state ids and camera ids are no longer random, but rather derive
from the page they belong to. This is like having a foreign primary key
in SQL databases. It's something i'd love to support fully as part of
the RecordType/Store api.
Tests to do
- [x] Test Migrations
- [x] Test Store.listen filtering
- [x] Make type sets in Store public and readonly
- [x] Test RecordType.createId
- [x] Test Instance state snapshot loading/exporting
- [x] Manual test File I/O
- [x] Manual test Vscode extension with multiple tabs
- [x] Audit usages of store.query
- [x] Audit usages of changed types: InstanceRecordType, 'instance',
InstancePageStateRecordType, 'instance_page_state', 'user_document',
'camera', CameraRecordType, InstancePresenceRecordType,
'instance_presence'
- [x] Test user preferences
- [x] Manual test isSnapMode and isGridMode and isPenMode
- [ ] Test indexedDb functions
- [x] Add instanceId stuff back
### Change Type
- [x] `major` — Breaking Change
### Test Plan
1. Add a step-by-step description of how to test your PR here.
2.
- [ ] Unit Tests
- [ ] Webdriver tests
### Release Notes
- Add a brief release note for your PR here.
2023-06-05 14:11:07 +00:00
|
|
|
parseId(id: IdOf<R>): string;
|
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)
|
Independent instance state persistence (#1493)
This PR
- Removes UserDocumentRecordType
- moving isSnapMode to user preferences
- moving isGridMode and isPenMode to InstanceRecordType
- deleting the other properties which are no longer needed.
- Creates a separate pipeline for persisting instance state.
Previously the instance state records were stored alongside the document
state records, and in order to load the state for a particular instance
(in our case, a particular tab) you needed to pass the 'instanceId'
prop. This prop ended up totally pervading the public API and people ran
into all kinds of issues with it, e.g. using the same instance id in
multiple editor instances.
There was also an issue whereby it was hard for us to clean up old
instance state so the idb table ended up bloating over time.
This PR makes it so that rather than passing an instanceId, you load the
instance state yourself while creating the store. It provides tools to
make that easy.
- Undoes the assumption that we might have more than one instance's
state in the store.
- Like `document`, `instance` now has a singleton id
`instance:instance`.
- Page state ids and camera ids are no longer random, but rather derive
from the page they belong to. This is like having a foreign primary key
in SQL databases. It's something i'd love to support fully as part of
the RecordType/Store api.
Tests to do
- [x] Test Migrations
- [x] Test Store.listen filtering
- [x] Make type sets in Store public and readonly
- [x] Test RecordType.createId
- [x] Test Instance state snapshot loading/exporting
- [x] Manual test File I/O
- [x] Manual test Vscode extension with multiple tabs
- [x] Audit usages of store.query
- [x] Audit usages of changed types: InstanceRecordType, 'instance',
InstancePageStateRecordType, 'instance_page_state', 'user_document',
'camera', CameraRecordType, InstancePresenceRecordType,
'instance_presence'
- [x] Test user preferences
- [x] Manual test isSnapMode and isGridMode and isPenMode
- [ ] Test indexedDb functions
- [x] Add instanceId stuff back
### Change Type
- [x] `major` — Breaking Change
### Test Plan
1. Add a step-by-step description of how to test your PR here.
2.
- [ ] Unit Tests
- [ ] Webdriver tests
### Release Notes
- Add a brief release note for your PR here.
2023-06-05 14:11:07 +00:00
|
|
|
readonly scope: RecordScope;
|
2023-04-25 11:01:25 +00:00
|
|
|
readonly typeName: R['typeName'];
|
2024-02-20 12:35:25 +00:00
|
|
|
validate(record: unknown, recordBefore?: R): R;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
2024-02-20 12:35:25 +00:00
|
|
|
readonly validator: StoreValidator<R>;
|
2023-04-25 11:01:25 +00:00
|
|
|
withDefaultProperties<DefaultProps extends Omit<Partial<R>, 'id' | 'typeName'>>(createDefaultProperties: () => DefaultProps): RecordType<R, Exclude<RequiredProperties, keyof DefaultProps>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public (undocumented)
|
2024-04-15 12:53:42 +00:00
|
|
|
export function reverseRecordsDiff(diff: RecordsDiff<any>): RecordsDiff<any>;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public (undocumented)
|
2024-04-15 12:53:42 +00:00
|
|
|
export type SerializedSchema = SerializedSchemaV1 | SerializedSchemaV2;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public (undocumented)
|
2024-04-15 12:53:42 +00:00
|
|
|
export interface SerializedSchemaV1 {
|
2023-04-25 11:01:25 +00:00
|
|
|
recordVersions: Record<string, {
|
|
|
|
subTypeKey: string;
|
2024-04-15 12:53:42 +00:00
|
|
|
subTypeVersions: Record<string, number>;
|
|
|
|
version: number;
|
2023-04-25 11:01:25 +00:00
|
|
|
} | {
|
|
|
|
version: number;
|
|
|
|
}>;
|
2024-04-15 12:53:42 +00:00
|
|
|
schemaVersion: 1;
|
2023-04-25 11:01:25 +00:00
|
|
|
storeVersion: number;
|
|
|
|
}
|
|
|
|
|
2024-04-15 12:53:42 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export interface SerializedSchemaV2 {
|
|
|
|
// (undocumented)
|
|
|
|
schemaVersion: 2;
|
|
|
|
// (undocumented)
|
|
|
|
sequences: {
|
|
|
|
[sequenceId: string]: number;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-27 12:25:55 +00:00
|
|
|
// @public
|
|
|
|
export type SerializedStore<R extends UnknownRecord> = Record<IdOf<R>, R>;
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @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: {
|
|
|
|
schema: StoreSchema<R, Props>;
|
2024-04-15 12:53:42 +00:00
|
|
|
initialData?: SerializedStore<R>;
|
2023-04-25 11:01:25 +00:00
|
|
|
props: Props;
|
|
|
|
});
|
|
|
|
allRecords: () => R[];
|
|
|
|
// (undocumented)
|
|
|
|
applyDiff(diff: RecordsDiff<R>, runCallbacks?: boolean): void;
|
|
|
|
clear: () => void;
|
2023-09-19 15:29:13 +00:00
|
|
|
createComputedCache: <T, V extends R = R>(name: string, derive: (record: V) => T | undefined, isEqual?: ((a: V, b: V) => boolean) | undefined) => ComputedCache<T, V>;
|
2023-04-25 11:01:25 +00:00
|
|
|
createSelectedComputedCache: <T, J, V extends R = R>(name: string, selector: (record: V) => T | undefined, derive: (input: T) => J | undefined) => ComputedCache<J, V>;
|
|
|
|
// @internal (undocumented)
|
|
|
|
ensureStoreIsUsable(): void;
|
|
|
|
// (undocumented)
|
|
|
|
extractingChanges(fn: () => void): RecordsDiff<R>;
|
Independent instance state persistence (#1493)
This PR
- Removes UserDocumentRecordType
- moving isSnapMode to user preferences
- moving isGridMode and isPenMode to InstanceRecordType
- deleting the other properties which are no longer needed.
- Creates a separate pipeline for persisting instance state.
Previously the instance state records were stored alongside the document
state records, and in order to load the state for a particular instance
(in our case, a particular tab) you needed to pass the 'instanceId'
prop. This prop ended up totally pervading the public API and people ran
into all kinds of issues with it, e.g. using the same instance id in
multiple editor instances.
There was also an issue whereby it was hard for us to clean up old
instance state so the idb table ended up bloating over time.
This PR makes it so that rather than passing an instanceId, you load the
instance state yourself while creating the store. It provides tools to
make that easy.
- Undoes the assumption that we might have more than one instance's
state in the store.
- Like `document`, `instance` now has a singleton id
`instance:instance`.
- Page state ids and camera ids are no longer random, but rather derive
from the page they belong to. This is like having a foreign primary key
in SQL databases. It's something i'd love to support fully as part of
the RecordType/Store api.
Tests to do
- [x] Test Migrations
- [x] Test Store.listen filtering
- [x] Make type sets in Store public and readonly
- [x] Test RecordType.createId
- [x] Test Instance state snapshot loading/exporting
- [x] Manual test File I/O
- [x] Manual test Vscode extension with multiple tabs
- [x] Audit usages of store.query
- [x] Audit usages of changed types: InstanceRecordType, 'instance',
InstancePageStateRecordType, 'instance_page_state', 'user_document',
'camera', CameraRecordType, InstancePresenceRecordType,
'instance_presence'
- [x] Test user preferences
- [x] Manual test isSnapMode and isGridMode and isPenMode
- [ ] Test indexedDb functions
- [x] Add instanceId stuff back
### Change Type
- [x] `major` — Breaking Change
### Test Plan
1. Add a step-by-step description of how to test your PR here.
2.
- [ ] Unit Tests
- [ ] Webdriver tests
### Release Notes
- Add a brief release note for your PR here.
2023-06-05 14:11:07 +00:00
|
|
|
filterChangesByScope(change: RecordsDiff<R>, scope: RecordScope): {
|
|
|
|
added: { [K in IdOf<R>]: R; };
|
|
|
|
removed: { [K in IdOf<R>]: R; };
|
2024-04-15 12:53:42 +00:00
|
|
|
updated: { [K_1 in IdOf<R>]: [from: R, to: R]; };
|
Independent instance state persistence (#1493)
This PR
- Removes UserDocumentRecordType
- moving isSnapMode to user preferences
- moving isGridMode and isPenMode to InstanceRecordType
- deleting the other properties which are no longer needed.
- Creates a separate pipeline for persisting instance state.
Previously the instance state records were stored alongside the document
state records, and in order to load the state for a particular instance
(in our case, a particular tab) you needed to pass the 'instanceId'
prop. This prop ended up totally pervading the public API and people ran
into all kinds of issues with it, e.g. using the same instance id in
multiple editor instances.
There was also an issue whereby it was hard for us to clean up old
instance state so the idb table ended up bloating over time.
This PR makes it so that rather than passing an instanceId, you load the
instance state yourself while creating the store. It provides tools to
make that easy.
- Undoes the assumption that we might have more than one instance's
state in the store.
- Like `document`, `instance` now has a singleton id
`instance:instance`.
- Page state ids and camera ids are no longer random, but rather derive
from the page they belong to. This is like having a foreign primary key
in SQL databases. It's something i'd love to support fully as part of
the RecordType/Store api.
Tests to do
- [x] Test Migrations
- [x] Test Store.listen filtering
- [x] Make type sets in Store public and readonly
- [x] Test RecordType.createId
- [x] Test Instance state snapshot loading/exporting
- [x] Manual test File I/O
- [x] Manual test Vscode extension with multiple tabs
- [x] Audit usages of store.query
- [x] Audit usages of changed types: InstanceRecordType, 'instance',
InstancePageStateRecordType, 'instance_page_state', 'user_document',
'camera', CameraRecordType, InstancePresenceRecordType,
'instance_presence'
- [x] Test user preferences
- [x] Manual test isSnapMode and isGridMode and isPenMode
- [ ] Test indexedDb functions
- [x] Add instanceId stuff back
### Change Type
- [x] `major` — Breaking Change
### Test Plan
1. Add a step-by-step description of how to test your PR here.
2.
- [ ] Unit Tests
- [ ] Webdriver tests
### Release Notes
- Add a brief release note for your PR here.
2023-06-05 14:11:07 +00:00
|
|
|
} | null;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
|
|
|
_flushHistory(): void;
|
2023-05-24 11:25:41 +00:00
|
|
|
get: <K extends IdOf<R>>(id: K) => RecFromId<K> | undefined;
|
2023-08-02 11:05:14 +00:00
|
|
|
// (undocumented)
|
|
|
|
getRecordType: <T extends R>(record: R) => T;
|
2023-06-27 12:25:55 +00:00
|
|
|
getSnapshot(scope?: 'all' | RecordScope): StoreSnapshot<R>;
|
2023-05-24 11:25:41 +00:00
|
|
|
has: <K extends IdOf<R>>(id: K) => boolean;
|
2023-04-25 11:01:25 +00:00
|
|
|
readonly history: Atom<number, RecordsDiff<R>>;
|
Independent instance state persistence (#1493)
This PR
- Removes UserDocumentRecordType
- moving isSnapMode to user preferences
- moving isGridMode and isPenMode to InstanceRecordType
- deleting the other properties which are no longer needed.
- Creates a separate pipeline for persisting instance state.
Previously the instance state records were stored alongside the document
state records, and in order to load the state for a particular instance
(in our case, a particular tab) you needed to pass the 'instanceId'
prop. This prop ended up totally pervading the public API and people ran
into all kinds of issues with it, e.g. using the same instance id in
multiple editor instances.
There was also an issue whereby it was hard for us to clean up old
instance state so the idb table ended up bloating over time.
This PR makes it so that rather than passing an instanceId, you load the
instance state yourself while creating the store. It provides tools to
make that easy.
- Undoes the assumption that we might have more than one instance's
state in the store.
- Like `document`, `instance` now has a singleton id
`instance:instance`.
- Page state ids and camera ids are no longer random, but rather derive
from the page they belong to. This is like having a foreign primary key
in SQL databases. It's something i'd love to support fully as part of
the RecordType/Store api.
Tests to do
- [x] Test Migrations
- [x] Test Store.listen filtering
- [x] Make type sets in Store public and readonly
- [x] Test RecordType.createId
- [x] Test Instance state snapshot loading/exporting
- [x] Manual test File I/O
- [x] Manual test Vscode extension with multiple tabs
- [x] Audit usages of store.query
- [x] Audit usages of changed types: InstanceRecordType, 'instance',
InstancePageStateRecordType, 'instance_page_state', 'user_document',
'camera', CameraRecordType, InstancePresenceRecordType,
'instance_presence'
- [x] Test user preferences
- [x] Manual test isSnapMode and isGridMode and isPenMode
- [ ] Test indexedDb functions
- [x] Add instanceId stuff back
### Change Type
- [x] `major` — Breaking Change
### Test Plan
1. Add a step-by-step description of how to test your PR here.
2.
- [ ] Unit Tests
- [ ] Webdriver tests
### Release Notes
- Add a brief release note for your PR here.
2023-06-05 14:11:07 +00:00
|
|
|
readonly id: string;
|
2023-04-25 11:01:25 +00:00
|
|
|
// @internal (undocumented)
|
|
|
|
isPossiblyCorrupted(): boolean;
|
Independent instance state persistence (#1493)
This PR
- Removes UserDocumentRecordType
- moving isSnapMode to user preferences
- moving isGridMode and isPenMode to InstanceRecordType
- deleting the other properties which are no longer needed.
- Creates a separate pipeline for persisting instance state.
Previously the instance state records were stored alongside the document
state records, and in order to load the state for a particular instance
(in our case, a particular tab) you needed to pass the 'instanceId'
prop. This prop ended up totally pervading the public API and people ran
into all kinds of issues with it, e.g. using the same instance id in
multiple editor instances.
There was also an issue whereby it was hard for us to clean up old
instance state so the idb table ended up bloating over time.
This PR makes it so that rather than passing an instanceId, you load the
instance state yourself while creating the store. It provides tools to
make that easy.
- Undoes the assumption that we might have more than one instance's
state in the store.
- Like `document`, `instance` now has a singleton id
`instance:instance`.
- Page state ids and camera ids are no longer random, but rather derive
from the page they belong to. This is like having a foreign primary key
in SQL databases. It's something i'd love to support fully as part of
the RecordType/Store api.
Tests to do
- [x] Test Migrations
- [x] Test Store.listen filtering
- [x] Make type sets in Store public and readonly
- [x] Test RecordType.createId
- [x] Test Instance state snapshot loading/exporting
- [x] Manual test File I/O
- [x] Manual test Vscode extension with multiple tabs
- [x] Audit usages of store.query
- [x] Audit usages of changed types: InstanceRecordType, 'instance',
InstancePageStateRecordType, 'instance_page_state', 'user_document',
'camera', CameraRecordType, InstancePresenceRecordType,
'instance_presence'
- [x] Test user preferences
- [x] Manual test isSnapMode and isGridMode and isPenMode
- [ ] Test indexedDb functions
- [x] Add instanceId stuff back
### Change Type
- [x] `major` — Breaking Change
### Test Plan
1. Add a step-by-step description of how to test your PR here.
2.
- [ ] Unit Tests
- [ ] Webdriver tests
### Release Notes
- Add a brief release note for your PR here.
2023-06-05 14:11:07 +00:00
|
|
|
listen: (onHistory: StoreListener<R>, filters?: Partial<StoreListenerFilters>) => () => void;
|
2023-06-27 12:25:55 +00:00
|
|
|
loadSnapshot(snapshot: StoreSnapshot<R>): void;
|
2023-04-25 11:01:25 +00:00
|
|
|
// @internal (undocumented)
|
|
|
|
markAsPossiblyCorrupted(): void;
|
|
|
|
mergeRemoteChanges: (fn: () => void) => void;
|
2023-09-08 17:04:53 +00:00
|
|
|
migrateSnapshot(snapshot: StoreSnapshot<R>): StoreSnapshot<R>;
|
2023-08-02 11:05:14 +00:00
|
|
|
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;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (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>;
|
Independent instance state persistence (#1493)
This PR
- Removes UserDocumentRecordType
- moving isSnapMode to user preferences
- moving isGridMode and isPenMode to InstanceRecordType
- deleting the other properties which are no longer needed.
- Creates a separate pipeline for persisting instance state.
Previously the instance state records were stored alongside the document
state records, and in order to load the state for a particular instance
(in our case, a particular tab) you needed to pass the 'instanceId'
prop. This prop ended up totally pervading the public API and people ran
into all kinds of issues with it, e.g. using the same instance id in
multiple editor instances.
There was also an issue whereby it was hard for us to clean up old
instance state so the idb table ended up bloating over time.
This PR makes it so that rather than passing an instanceId, you load the
instance state yourself while creating the store. It provides tools to
make that easy.
- Undoes the assumption that we might have more than one instance's
state in the store.
- Like `document`, `instance` now has a singleton id
`instance:instance`.
- Page state ids and camera ids are no longer random, but rather derive
from the page they belong to. This is like having a foreign primary key
in SQL databases. It's something i'd love to support fully as part of
the RecordType/Store api.
Tests to do
- [x] Test Migrations
- [x] Test Store.listen filtering
- [x] Make type sets in Store public and readonly
- [x] Test RecordType.createId
- [x] Test Instance state snapshot loading/exporting
- [x] Manual test File I/O
- [x] Manual test Vscode extension with multiple tabs
- [x] Audit usages of store.query
- [x] Audit usages of changed types: InstanceRecordType, 'instance',
InstancePageStateRecordType, 'instance_page_state', 'user_document',
'camera', CameraRecordType, InstancePresenceRecordType,
'instance_presence'
- [x] Test user preferences
- [x] Manual test isSnapMode and isGridMode and isPenMode
- [ ] Test indexedDb functions
- [x] Add instanceId stuff back
### Change Type
- [x] `major` — Breaking Change
### Test Plan
1. Add a step-by-step description of how to test your PR here.
2.
- [ ] Unit Tests
- [ ] Webdriver tests
### Release Notes
- Add a brief release note for your PR here.
2023-06-05 14:11:07 +00:00
|
|
|
// (undocumented)
|
|
|
|
readonly scopedTypes: {
|
|
|
|
readonly [K in RecordScope]: ReadonlySet<R['typeName']>;
|
|
|
|
};
|
2023-06-27 12:25:55 +00:00
|
|
|
serialize: (scope?: 'all' | RecordScope) => SerializedStore<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;
|
2024-04-15 12:53:42 +00:00
|
|
|
isExistingValidationIssue: boolean;
|
2023-04-25 11:01:25 +00:00
|
|
|
phase: 'createRecord' | 'initialize' | 'tests' | 'updateRecord';
|
|
|
|
recordAfter: unknown;
|
2024-04-15 12:53:42 +00:00
|
|
|
recordBefore?: unknown;
|
2023-04-25 11:01:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// @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)
|
2024-04-15 12:53:42 +00:00
|
|
|
getMigrationsSince(persistedSchema: SerializedSchema): Result<Migration[], string>;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
|
|
|
migratePersistedRecord(record: R, persistedSchema: SerializedSchema, direction?: 'down' | 'up'): MigrationResult<R>;
|
|
|
|
// (undocumented)
|
2023-06-27 13:59:07 +00:00
|
|
|
migrateStoreSnapshot(snapshot: StoreSnapshot<R>): MigrationResult<SerializedStore<R>>;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
2024-04-15 12:53:42 +00:00
|
|
|
readonly migrations: Record<string, MigrationSequence>;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
2024-04-15 12:53:42 +00:00
|
|
|
serialize(): SerializedSchemaV2;
|
|
|
|
// @deprecated (undocumented)
|
2023-04-25 11:01:25 +00:00
|
|
|
serializeEarliestVersion(): SerializedSchema;
|
|
|
|
// (undocumented)
|
2024-04-15 12:53:42 +00:00
|
|
|
readonly sortedMigrations: readonly Migration[];
|
|
|
|
// (undocumented)
|
2023-04-25 11:01:25 +00:00
|
|
|
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> = {
|
2024-04-15 12:53:42 +00:00
|
|
|
createIntegrityChecker?: (store: Store<R, P>) => void;
|
2023-04-25 11:01:25 +00:00
|
|
|
onValidationFailure?: (data: {
|
|
|
|
error: unknown;
|
|
|
|
phase: 'createRecord' | 'initialize' | 'tests' | 'updateRecord';
|
2024-04-15 12:53:42 +00:00
|
|
|
record: R;
|
2023-04-25 11:01:25 +00:00
|
|
|
recordBefore: null | R;
|
2024-04-15 12:53:42 +00:00
|
|
|
store: Store<R>;
|
2023-04-25 11:01:25 +00:00
|
|
|
}) => R;
|
2024-04-15 12:53:42 +00:00
|
|
|
migrations?: MigrationSequence[];
|
2023-04-25 11:01:25 +00:00
|
|
|
};
|
|
|
|
|
2023-06-27 12:25:55 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export type StoreSnapshot<R extends UnknownRecord> = {
|
|
|
|
schema: SerializedSchema;
|
2024-04-15 12:53:42 +00:00
|
|
|
store: SerializedStore<R>;
|
2023-06-27 12:25:55 +00:00
|
|
|
};
|
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;
|
2024-02-20 12:35:25 +00:00
|
|
|
validateUsingKnownGoodVersion?: (knownGoodVersion: R, record: unknown) => R;
|
2023-04-25 11:01:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// @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)
|
2023-06-03 20:46:53 +00:00
|
|
|
export type UnknownRecord = BaseRecord<string, RecordId<UnknownRecord>>;
|
2023-05-24 11:25:41 +00:00
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// (No @packageDocumentation comment for this package)
|
|
|
|
|
|
|
|
```
|