Migrate snapshot (#1843)

Add `Store.migrateSnapshot`, another surface API alongside getSnapshot
and loadSnapshot.

### Change Type

- [x] `minor` — New feature

### Release Notes

- [editor] add `Store.migrateSnapshot`
This commit is contained in:
Steve Ruiz 2023-09-08 18:04:53 +01:00 committed by GitHub
parent 0b3e83be52
commit 48a1bb4d88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 126 additions and 13 deletions

View file

@ -2495,9 +2495,9 @@ export type TLStoreOptions = {
initialData?: SerializedStore<TLRecord>;
defaultName?: string;
} & ({
schema: StoreSchema<TLRecord, TLStoreProps>;
schema?: StoreSchema<TLRecord, TLStoreProps>;
} | {
shapeUtils: readonly TLAnyShapeUtilConstructor[];
shapeUtils?: readonly TLAnyShapeUtilConstructor[];
});
// @public (undocumented)

View file

@ -15,8 +15,8 @@ export type TLStoreOptions = {
initialData?: SerializedStore<TLRecord>
defaultName?: string
} & (
| { shapeUtils: readonly TLAnyShapeUtilConstructor[] }
| { schema: StoreSchema<TLRecord, TLStoreProps> }
| { shapeUtils?: readonly TLAnyShapeUtilConstructor[] }
| { schema?: StoreSchema<TLRecord, TLStoreProps> }
)
/** @public */
@ -30,11 +30,16 @@ export type TLStoreEventInfo = HistoryEntry<TLRecord>
* @public */
export function createTLStore({ initialData, defaultName = '', ...rest }: TLStoreOptions): TLStore {
const schema =
'schema' in rest
? rest.schema
: createTLSchema({
shapes: currentPageShapesToShapeMap(checkShapesAndAddCore(rest.shapeUtils)),
'schema' in rest && rest.schema
? // we have a schema
rest.schema
: // we need a schema
createTLSchema({
shapes: currentPageShapesToShapeMap(
checkShapesAndAddCore('shapeUtils' in rest && rest.shapeUtils ? rest.shapeUtils : [])
),
})
return new Store({
schema,
initialData,