@verdant-web/store 2.7.6 → 2.7.7-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/index.js +9 -9
- package/dist/bundle/index.js.map +4 -4
- package/dist/cjs/AckInfoStore.d.ts +10 -0
- package/dist/cjs/AckInfoStore.js +26 -0
- package/dist/cjs/AckInfoStore.js.map +1 -0
- package/dist/cjs/BackoffScheduler.d.ts +19 -19
- package/dist/cjs/BackoffScheduler.js +44 -44
- package/dist/cjs/BaselinesStore.d.ts +10 -0
- package/dist/cjs/BaselinesStore.js +36 -0
- package/dist/cjs/BaselinesStore.js.map +1 -0
- package/dist/cjs/DocumentManager.d.ts +31 -28
- package/dist/cjs/DocumentManager.js +44 -44
- package/dist/cjs/Entity.d.ts +96 -0
- package/dist/cjs/Entity.js +345 -0
- package/dist/cjs/Entity.js.map +1 -0
- package/dist/cjs/EntityStore.d.ts +36 -0
- package/dist/cjs/EntityStore.js +172 -0
- package/dist/cjs/EntityStore.js.map +1 -0
- package/dist/cjs/FakeWeakRef.d.ts +11 -11
- package/dist/cjs/FakeWeakRef.js +18 -18
- package/dist/cjs/IDBService.d.ts +9 -9
- package/dist/cjs/IDBService.js +63 -63
- package/dist/cjs/LocalHistoryStore.d.ts +15 -0
- package/dist/cjs/LocalHistoryStore.js +53 -0
- package/dist/cjs/LocalHistoryStore.js.map +1 -0
- package/dist/cjs/LocalReplicaStore.d.ts +13 -0
- package/dist/cjs/LocalReplicaStore.js +49 -0
- package/dist/cjs/LocalReplicaStore.js.map +1 -0
- package/dist/cjs/MessageCreator.d.ts +19 -0
- package/dist/cjs/MessageCreator.js +104 -0
- package/dist/cjs/MessageCreator.js.map +1 -0
- package/dist/cjs/Metadata.d.ts +91 -0
- package/dist/cjs/Metadata.js +250 -0
- package/dist/cjs/Metadata.js.map +1 -0
- package/dist/cjs/OperationsStore.d.ts +38 -0
- package/dist/cjs/OperationsStore.js +146 -0
- package/dist/cjs/OperationsStore.js.map +1 -0
- package/dist/cjs/PresenceManager.d.ts +30 -0
- package/dist/cjs/PresenceManager.js +89 -0
- package/dist/cjs/PresenceManager.js.map +1 -0
- package/dist/cjs/Query.d.ts +26 -0
- package/dist/cjs/Query.js +86 -0
- package/dist/cjs/Query.js.map +1 -0
- package/dist/cjs/QueryMaker.d.ts +18 -0
- package/dist/cjs/QueryMaker.js +98 -0
- package/dist/cjs/QueryMaker.js.map +1 -0
- package/dist/cjs/QueryStore.d.ts +38 -0
- package/dist/cjs/QueryStore.js +146 -0
- package/dist/cjs/QueryStore.js.map +1 -0
- package/dist/cjs/SchemaStore.d.ts +9 -0
- package/dist/cjs/SchemaStore.js +35 -0
- package/dist/cjs/SchemaStore.js.map +1 -0
- package/dist/cjs/Storage.d.ts +147 -0
- package/dist/cjs/Storage.js +346 -0
- package/dist/cjs/Storage.js.map +1 -0
- package/dist/cjs/Sync.d.ts +117 -0
- package/dist/cjs/Sync.js +561 -0
- package/dist/cjs/Sync.js.map +1 -0
- package/dist/cjs/SyncHarness.d.ts +45 -0
- package/dist/cjs/SyncHarness.js +110 -0
- package/dist/cjs/SyncHarness.js.map +1 -0
- package/dist/cjs/UndoHistory.d.ts +16 -16
- package/dist/cjs/UndoHistory.js +50 -50
- package/dist/cjs/__tests__/batching.test.d.ts +1 -1
- package/dist/cjs/__tests__/batching.test.js +44 -44
- package/dist/cjs/__tests__/documents.test.d.ts +1 -1
- package/dist/cjs/__tests__/documents.test.js +415 -415
- package/dist/cjs/__tests__/fixtures/testStorage.d.ts +123 -122
- package/dist/cjs/__tests__/fixtures/testStorage.js +117 -115
- package/dist/cjs/__tests__/fixtures/testStorage.js.map +1 -1
- package/dist/cjs/__tests__/legacyOids.test.d.ts +1 -1
- package/dist/cjs/__tests__/legacyOids.test.js +309 -123
- package/dist/cjs/__tests__/legacyOids.test.js.map +1 -1
- package/dist/cjs/__tests__/mutations.test.d.ts +1 -1
- package/dist/cjs/__tests__/mutations.test.js +41 -41
- package/dist/cjs/__tests__/queries.test.d.ts +1 -1
- package/dist/cjs/__tests__/queries.test.js +318 -318
- package/dist/cjs/__tests__/setup/indexedDB.d.ts +1 -1
- package/dist/cjs/__tests__/setup/indexedDB.js +3 -3
- package/dist/cjs/__tests__/undo.test.d.ts +1 -1
- package/dist/cjs/__tests__/undo.test.js +86 -86
- package/dist/cjs/client/Client.d.ts +98 -99
- package/dist/cjs/client/Client.js +227 -227
- package/dist/cjs/client/ClientDescriptor.d.ts +76 -74
- package/dist/cjs/client/ClientDescriptor.js +197 -194
- package/dist/cjs/client/ClientDescriptor.js.map +1 -1
- package/dist/cjs/client/constants.d.ts +1 -0
- package/dist/cjs/client/constants.js +5 -0
- package/dist/cjs/client/constants.js.map +1 -0
- package/dist/cjs/constants.d.ts +1 -1
- package/dist/cjs/constants.js +4 -4
- package/dist/cjs/context.d.ts +29 -29
- package/dist/cjs/context.js +2 -2
- package/dist/cjs/entities/DocumentFamiliyCache.d.ts +90 -90
- package/dist/cjs/entities/DocumentFamiliyCache.js +282 -282
- package/dist/cjs/entities/Entity.d.ts +206 -206
- package/dist/cjs/entities/Entity.js +520 -520
- package/dist/cjs/entities/EntityStore.d.ts +85 -85
- package/dist/cjs/entities/EntityStore.js +479 -479
- package/dist/cjs/files/EntityFile.d.ts +31 -31
- package/dist/cjs/files/EntityFile.js +76 -76
- package/dist/cjs/files/FileManager.d.ts +42 -42
- package/dist/cjs/files/FileManager.js +152 -152
- package/dist/cjs/files/FileStorage.d.ts +28 -28
- package/dist/cjs/files/FileStorage.js +104 -104
- package/dist/cjs/files/utils.d.ts +8 -8
- package/dist/cjs/files/utils.js +55 -55
- package/dist/cjs/files/utils.test.d.ts +1 -1
- package/dist/cjs/files/utils.test.js +80 -80
- package/dist/cjs/idb.d.ts +11 -11
- package/dist/cjs/idb.js +111 -111
- package/dist/cjs/index.d.ts +21 -21
- package/dist/cjs/index.js +23 -23
- package/dist/cjs/indexes.d.ts +3 -0
- package/dist/cjs/indexes.js +20 -0
- package/dist/cjs/indexes.js.map +1 -0
- package/dist/cjs/metadata/AckInfoStore.d.ts +10 -10
- package/dist/cjs/metadata/AckInfoStore.js +25 -25
- package/dist/cjs/metadata/BaselinesStore.d.ts +33 -33
- package/dist/cjs/metadata/BaselinesStore.js +89 -89
- package/dist/cjs/metadata/LocalHistoryStore.d.ts +15 -0
- package/dist/cjs/metadata/LocalHistoryStore.js +53 -0
- package/dist/cjs/metadata/LocalHistoryStore.js.map +1 -0
- package/dist/cjs/metadata/LocalReplicaStore.d.ts +17 -17
- package/dist/cjs/metadata/LocalReplicaStore.js +47 -47
- package/dist/cjs/metadata/MessageCreator.d.ts +19 -19
- package/dist/cjs/metadata/MessageCreator.js +127 -127
- package/dist/cjs/metadata/Metadata.d.ts +112 -112
- package/dist/cjs/metadata/Metadata.js +352 -352
- package/dist/cjs/metadata/OperationsStore.d.ts +53 -53
- package/dist/cjs/metadata/OperationsStore.js +152 -152
- package/dist/cjs/metadata/SchemaStore.d.ts +9 -9
- package/dist/cjs/metadata/SchemaStore.js +38 -38
- package/dist/cjs/metadata/openMetadataDatabase.d.ts +19 -17
- package/dist/cjs/metadata/openMetadataDatabase.js +219 -158
- package/dist/cjs/metadata/openMetadataDatabase.js.map +1 -1
- package/dist/cjs/migration/db.d.ts +8 -8
- package/dist/cjs/migration/db.js +111 -111
- package/dist/cjs/migration/errors.d.ts +5 -5
- package/dist/cjs/migration/errors.js +11 -11
- package/dist/cjs/migration/openDatabase.d.ts +20 -20
- package/dist/cjs/migration/openDatabase.js +428 -428
- package/dist/cjs/migration/paths.d.ts +6 -6
- package/dist/cjs/migration/paths.js +52 -52
- package/dist/cjs/migration/paths.test.d.ts +1 -1
- package/dist/cjs/migration/paths.test.js +90 -90
- package/dist/cjs/openDocumentDatabase.d.ts +12 -0
- package/dist/cjs/openDocumentDatabase.js +432 -0
- package/dist/cjs/openDocumentDatabase.js.map +1 -0
- package/dist/cjs/queries/BaseQuery.d.ts +53 -53
- package/dist/cjs/queries/BaseQuery.js +135 -135
- package/dist/cjs/queries/CollectionQueries.d.ts +55 -55
- package/dist/cjs/queries/CollectionQueries.js +91 -91
- package/dist/cjs/queries/FindAllQuery.d.ts +12 -12
- package/dist/cjs/queries/FindAllQuery.js +42 -42
- package/dist/cjs/queries/FindInfiniteQuery.d.ts +19 -19
- package/dist/cjs/queries/FindInfiniteQuery.js +69 -69
- package/dist/cjs/queries/FindOneQuery.d.ts +12 -12
- package/dist/cjs/queries/FindOneQuery.js +42 -42
- package/dist/cjs/queries/FindPageQuery.d.ts +24 -24
- package/dist/cjs/queries/FindPageQuery.js +76 -76
- package/dist/cjs/queries/GetQuery.d.ts +10 -10
- package/dist/cjs/queries/GetQuery.js +29 -29
- package/dist/cjs/queries/LiveQuery.d.ts +28 -0
- package/dist/cjs/queries/LiveQuery.js +96 -0
- package/dist/cjs/queries/LiveQuery.js.map +1 -0
- package/dist/cjs/queries/LiveQueryMaker.d.ts +15 -0
- package/dist/cjs/queries/LiveQueryMaker.js +42 -0
- package/dist/cjs/queries/LiveQueryMaker.js.map +1 -0
- package/dist/cjs/queries/LiveQueryStore.d.ts +33 -0
- package/dist/cjs/queries/LiveQueryStore.js +85 -0
- package/dist/cjs/queries/LiveQueryStore.js.map +1 -0
- package/dist/cjs/queries/Query.d.ts +18 -0
- package/dist/cjs/queries/Query.js +36 -0
- package/dist/cjs/queries/Query.js.map +1 -0
- package/dist/cjs/queries/QueryCache.d.ts +16 -16
- package/dist/cjs/queries/QueryCache.js +41 -41
- package/dist/cjs/queries/QueryMaker.d.ts +14 -0
- package/dist/cjs/queries/QueryMaker.js +42 -0
- package/dist/cjs/queries/QueryMaker.js.map +1 -0
- package/dist/cjs/queries/QueryStore.d.ts +35 -0
- package/dist/cjs/queries/QueryStore.js +130 -0
- package/dist/cjs/queries/QueryStore.js.map +1 -0
- package/dist/cjs/queries/dbQueries.d.ts +22 -22
- package/dist/cjs/queries/dbQueries.js +125 -125
- package/dist/cjs/queries/keys.d.ts +10 -10
- package/dist/cjs/queries/keys.js +33 -33
- package/dist/cjs/queries/ranges.d.ts +2 -2
- package/dist/cjs/queries/ranges.js +69 -69
- package/dist/cjs/queries/types.d.ts +6 -6
- package/dist/cjs/queries/types.js +2 -2
- package/dist/cjs/queries/utils.d.ts +3 -3
- package/dist/cjs/queries/utils.js +24 -24
- package/dist/cjs/queries2/BaseQuery.d.ts +39 -0
- package/dist/cjs/queries2/BaseQuery.js +99 -0
- package/dist/cjs/queries2/BaseQuery.js.map +1 -0
- package/dist/cjs/queries2/CollectionQueries.d.ts +55 -0
- package/dist/cjs/queries2/CollectionQueries.js +83 -0
- package/dist/cjs/queries2/CollectionQueries.js.map +1 -0
- package/dist/cjs/queries2/FindAllQuery.d.ts +11 -0
- package/dist/cjs/queries2/FindAllQuery.js +34 -0
- package/dist/cjs/queries2/FindAllQuery.js.map +1 -0
- package/dist/cjs/queries2/FindInfiniteQuery.d.ts +18 -0
- package/dist/cjs/queries2/FindInfiniteQuery.js +61 -0
- package/dist/cjs/queries2/FindInfiniteQuery.js.map +1 -0
- package/dist/cjs/queries2/FindOneQuery.d.ts +11 -0
- package/dist/cjs/queries2/FindOneQuery.js +34 -0
- package/dist/cjs/queries2/FindOneQuery.js.map +1 -0
- package/dist/cjs/queries2/FindPageQuery.d.ts +23 -0
- package/dist/cjs/queries2/FindPageQuery.js +68 -0
- package/dist/cjs/queries2/FindPageQuery.js.map +1 -0
- package/dist/cjs/queries2/GetQuery.d.ts +10 -0
- package/dist/cjs/queries2/GetQuery.js +30 -0
- package/dist/cjs/queries2/GetQuery.js.map +1 -0
- package/dist/cjs/queries2/QueryCache.d.ts +16 -0
- package/dist/cjs/queries2/QueryCache.js +40 -0
- package/dist/cjs/queries2/QueryCache.js.map +1 -0
- package/dist/cjs/queries2/dbQueries.d.ts +22 -0
- package/dist/cjs/queries2/dbQueries.js +126 -0
- package/dist/cjs/queries2/dbQueries.js.map +1 -0
- package/dist/cjs/queries2/keys.d.ts +10 -0
- package/dist/cjs/queries2/keys.js +34 -0
- package/dist/cjs/queries2/keys.js.map +1 -0
- package/dist/cjs/queries2/ranges.d.ts +2 -0
- package/dist/cjs/queries2/ranges.js +70 -0
- package/dist/cjs/queries2/ranges.js.map +1 -0
- package/dist/cjs/queries2/types.d.ts +6 -0
- package/dist/cjs/queries2/types.js +3 -0
- package/dist/cjs/queries2/types.js.map +1 -0
- package/dist/cjs/queries2/utils.d.ts +1 -0
- package/dist/cjs/queries2/utils.js +20 -0
- package/dist/cjs/queries2/utils.js.map +1 -0
- package/dist/cjs/reactives/DocumentFamiliyCache.d.ts +47 -0
- package/dist/cjs/reactives/DocumentFamiliyCache.js +211 -0
- package/dist/cjs/reactives/DocumentFamiliyCache.js.map +1 -0
- package/dist/cjs/reactives/Entity.d.ts +191 -0
- package/dist/cjs/reactives/Entity.js +463 -0
- package/dist/cjs/reactives/Entity.js.map +1 -0
- package/dist/cjs/reactives/EntityStore.d.ts +84 -0
- package/dist/cjs/reactives/EntityStore.js +422 -0
- package/dist/cjs/reactives/EntityStore.js.map +1 -0
- package/dist/cjs/reactives/FakeWeakRef.d.ts +11 -0
- package/dist/cjs/reactives/FakeWeakRef.js +19 -0
- package/dist/cjs/reactives/FakeWeakRef.js.map +1 -0
- package/dist/cjs/sync/FileSync.d.ts +23 -23
- package/dist/cjs/sync/FileSync.js +84 -84
- package/dist/cjs/sync/Heartbeat.d.ts +25 -25
- package/dist/cjs/sync/Heartbeat.js +63 -63
- package/dist/cjs/sync/PresenceManager.d.ts +43 -43
- package/dist/cjs/sync/PresenceManager.js +119 -119
- package/dist/cjs/sync/PushPullSync.d.ts +36 -36
- package/dist/cjs/sync/PushPullSync.js +143 -143
- package/dist/cjs/sync/ServerSyncEndpointProvider.d.ts +27 -27
- package/dist/cjs/sync/ServerSyncEndpointProvider.js +64 -64
- package/dist/cjs/sync/Sync.d.ts +146 -146
- package/dist/cjs/sync/Sync.js +270 -270
- package/dist/cjs/sync/Sync.js.map +1 -1
- package/dist/cjs/sync/WebSocketSync.d.ts +41 -41
- package/dist/cjs/sync/WebSocketSync.js +190 -190
- package/dist/cjs/types.d.ts +12 -12
- package/dist/cjs/types.js +2 -2
- package/dist/cjs/utils/Disposable.d.ts +6 -6
- package/dist/cjs/utils/Disposable.js +18 -18
- package/dist/cjs/utils/Resolvable.d.ts +8 -8
- package/dist/cjs/utils/Resolvable.js +22 -22
- package/dist/cjs/v2/AckInfoStore.d.ts +10 -0
- package/dist/cjs/v2/AckInfoStore.js +26 -0
- package/dist/cjs/v2/AckInfoStore.js.map +1 -0
- package/dist/cjs/v2/BaselinesStore.d.ts +10 -0
- package/dist/cjs/v2/BaselinesStore.js +36 -0
- package/dist/cjs/v2/BaselinesStore.js.map +1 -0
- package/dist/cjs/v2/DocumentManager.d.ts +19 -0
- package/dist/cjs/v2/DocumentManager.js +47 -0
- package/dist/cjs/v2/DocumentManager.js.map +1 -0
- package/dist/cjs/v2/Entity.d.ts +87 -0
- package/dist/cjs/v2/Entity.js +305 -0
- package/dist/cjs/v2/Entity.js.map +1 -0
- package/dist/cjs/v2/EntityStore.d.ts +37 -0
- package/dist/cjs/v2/EntityStore.js +165 -0
- package/dist/cjs/v2/EntityStore.js.map +1 -0
- package/dist/cjs/v2/IDBService.d.ts +7 -0
- package/dist/cjs/v2/IDBService.js +26 -0
- package/dist/cjs/v2/IDBService.js.map +1 -0
- package/dist/cjs/v2/LocalHistoryStore.d.ts +15 -0
- package/dist/cjs/v2/LocalHistoryStore.js +53 -0
- package/dist/cjs/v2/LocalHistoryStore.js.map +1 -0
- package/dist/cjs/v2/LocalReplicaStore.d.ts +14 -0
- package/dist/cjs/v2/LocalReplicaStore.js +49 -0
- package/dist/cjs/v2/LocalReplicaStore.js.map +1 -0
- package/dist/cjs/v2/MessageCreator.d.ts +19 -0
- package/dist/cjs/v2/MessageCreator.js +99 -0
- package/dist/cjs/v2/MessageCreator.js.map +1 -0
- package/dist/cjs/v2/Metadata.d.ts +90 -0
- package/dist/cjs/v2/Metadata.js +251 -0
- package/dist/cjs/v2/Metadata.js.map +1 -0
- package/dist/cjs/v2/OperationsStore.d.ts +38 -0
- package/dist/cjs/v2/OperationsStore.js +146 -0
- package/dist/cjs/v2/OperationsStore.js.map +1 -0
- package/dist/cjs/v2/PresenceManager.d.ts +24 -0
- package/dist/cjs/v2/PresenceManager.js +73 -0
- package/dist/cjs/v2/PresenceManager.js.map +1 -0
- package/dist/cjs/v2/Query.d.ts +24 -0
- package/dist/cjs/v2/Query.js +79 -0
- package/dist/cjs/v2/Query.js.map +1 -0
- package/dist/cjs/v2/QueryMaker.d.ts +16 -0
- package/dist/cjs/v2/QueryMaker.js +84 -0
- package/dist/cjs/v2/QueryMaker.js.map +1 -0
- package/dist/cjs/v2/QueryStore.d.ts +26 -0
- package/dist/cjs/v2/QueryStore.js +136 -0
- package/dist/cjs/v2/QueryStore.js.map +1 -0
- package/dist/cjs/v2/SchemaStore.d.ts +9 -0
- package/dist/cjs/v2/SchemaStore.js +35 -0
- package/dist/cjs/v2/SchemaStore.js.map +1 -0
- package/dist/cjs/v2/Storage.d.ts +80 -0
- package/dist/cjs/v2/Storage.js +154 -0
- package/dist/cjs/v2/Storage.js.map +1 -0
- package/dist/cjs/v2/Sync.d.ts +42 -0
- package/dist/cjs/v2/Sync.js +98 -0
- package/dist/cjs/v2/Sync.js.map +1 -0
- package/dist/cjs/v2/SyncHarness.d.ts +45 -0
- package/dist/cjs/v2/SyncHarness.js +110 -0
- package/dist/cjs/v2/SyncHarness.js.map +1 -0
- package/dist/cjs/v2/__tests__/documents.test.d.ts +1 -0
- package/dist/cjs/v2/__tests__/documents.test.js +185 -0
- package/dist/cjs/v2/__tests__/documents.test.js.map +1 -0
- package/dist/cjs/v2/__tests__/fixtures/testStorage.d.ts +189 -0
- package/dist/cjs/v2/__tests__/fixtures/testStorage.js +93 -0
- package/dist/cjs/v2/__tests__/fixtures/testStorage.js.map +1 -0
- package/dist/cjs/v2/__tests__/queries.test.d.ts +1 -0
- package/dist/cjs/v2/__tests__/queries.test.js +92 -0
- package/dist/cjs/v2/__tests__/queries.test.js.map +1 -0
- package/dist/cjs/v2/__tests__/setup/indexedDB.d.ts +1 -0
- package/dist/cjs/v2/__tests__/setup/indexedDB.js +4 -0
- package/dist/cjs/v2/__tests__/setup/indexedDB.js.map +1 -0
- package/dist/cjs/v2/constants.d.ts +1 -0
- package/dist/cjs/v2/constants.js +5 -0
- package/dist/cjs/v2/constants.js.map +1 -0
- package/dist/cjs/v2/idb.d.ts +6 -0
- package/dist/cjs/v2/idb.js +71 -0
- package/dist/cjs/v2/idb.js.map +1 -0
- package/dist/cjs/v2/index.d.ts +6 -0
- package/dist/cjs/v2/index.js +14 -0
- package/dist/cjs/v2/index.js.map +1 -0
- package/dist/cjs/v2/indexes.d.ts +3 -0
- package/dist/cjs/v2/indexes.js +20 -0
- package/dist/cjs/v2/indexes.js.map +1 -0
- package/dist/cjs/v2/openDocumentDatabase.d.ts +9 -0
- package/dist/cjs/v2/openDocumentDatabase.js +100 -0
- package/dist/cjs/v2/openDocumentDatabase.js.map +1 -0
- package/dist/cjs/v2/types.d.ts +3 -0
- package/dist/cjs/v2/types.js +3 -0
- package/dist/cjs/v2/types.js.map +1 -0
- package/dist/cjs/vanilla.d.ts +1 -1
- package/dist/cjs/vanilla.js +27 -27
- package/dist/esm/AckInfoStore.d.ts +10 -0
- package/dist/esm/AckInfoStore.js +22 -0
- package/dist/esm/AckInfoStore.js.map +1 -0
- package/dist/esm/BackoffScheduler.d.ts +19 -19
- package/dist/esm/BackoffScheduler.js +39 -39
- package/dist/esm/BaselinesStore.d.ts +10 -0
- package/dist/esm/BaselinesStore.js +32 -0
- package/dist/esm/BaselinesStore.js.map +1 -0
- package/dist/esm/DocumentManager.d.ts +28 -28
- package/dist/esm/DocumentManager.js +40 -40
- package/dist/esm/Entity.d.ts +96 -0
- package/dist/esm/Entity.js +337 -0
- package/dist/esm/Entity.js.map +1 -0
- package/dist/esm/EntityStore.d.ts +36 -0
- package/dist/esm/EntityStore.js +168 -0
- package/dist/esm/EntityStore.js.map +1 -0
- package/dist/esm/FakeWeakRef.d.ts +11 -11
- package/dist/esm/FakeWeakRef.js +14 -14
- package/dist/esm/IDBService.d.ts +9 -9
- package/dist/esm/IDBService.js +59 -59
- package/dist/esm/LocalHistoryStore.d.ts +15 -0
- package/dist/esm/LocalHistoryStore.js +49 -0
- package/dist/esm/LocalHistoryStore.js.map +1 -0
- package/dist/esm/LocalReplicaStore.d.ts +13 -0
- package/dist/esm/LocalReplicaStore.js +42 -0
- package/dist/esm/LocalReplicaStore.js.map +1 -0
- package/dist/esm/MessageCreator.d.ts +19 -0
- package/dist/esm/MessageCreator.js +97 -0
- package/dist/esm/MessageCreator.js.map +1 -0
- package/dist/esm/Metadata.d.ts +91 -0
- package/dist/esm/Metadata.js +245 -0
- package/dist/esm/Metadata.js.map +1 -0
- package/dist/esm/OperationsStore.d.ts +38 -0
- package/dist/esm/OperationsStore.js +142 -0
- package/dist/esm/OperationsStore.js.map +1 -0
- package/dist/esm/PresenceManager.d.ts +30 -0
- package/dist/esm/PresenceManager.js +85 -0
- package/dist/esm/PresenceManager.js.map +1 -0
- package/dist/esm/Query.d.ts +26 -0
- package/dist/esm/Query.js +82 -0
- package/dist/esm/Query.js.map +1 -0
- package/dist/esm/QueryMaker.d.ts +18 -0
- package/dist/esm/QueryMaker.js +94 -0
- package/dist/esm/QueryMaker.js.map +1 -0
- package/dist/esm/QueryStore.d.ts +38 -0
- package/dist/esm/QueryStore.js +142 -0
- package/dist/esm/QueryStore.js.map +1 -0
- package/dist/esm/SchemaStore.d.ts +9 -0
- package/dist/esm/SchemaStore.js +31 -0
- package/dist/esm/SchemaStore.js.map +1 -0
- package/dist/esm/Storage.d.ts +147 -0
- package/dist/esm/Storage.js +341 -0
- package/dist/esm/Storage.js.map +1 -0
- package/dist/esm/Sync.d.ts +117 -0
- package/dist/esm/Sync.js +553 -0
- package/dist/esm/Sync.js.map +1 -0
- package/dist/esm/SyncHarness.d.ts +45 -0
- package/dist/esm/SyncHarness.js +105 -0
- package/dist/esm/SyncHarness.js.map +1 -0
- package/dist/esm/UndoHistory.d.ts +16 -16
- package/dist/esm/UndoHistory.js +46 -46
- package/dist/esm/__tests__/batching.test.d.ts +1 -1
- package/dist/esm/__tests__/batching.test.js +42 -42
- package/dist/esm/__tests__/documents.test.d.ts +1 -1
- package/dist/esm/__tests__/documents.test.js +413 -413
- package/dist/esm/__tests__/fixtures/testStorage.d.ts +123 -122
- package/dist/esm/__tests__/fixtures/testStorage.js +113 -111
- package/dist/esm/__tests__/fixtures/testStorage.js.map +1 -1
- package/dist/esm/__tests__/legacyOids.test.d.ts +1 -1
- package/dist/esm/__tests__/legacyOids.test.js +307 -121
- package/dist/esm/__tests__/legacyOids.test.js.map +1 -1
- package/dist/esm/__tests__/mutations.test.d.ts +1 -1
- package/dist/esm/__tests__/mutations.test.js +39 -39
- package/dist/esm/__tests__/queries.test.d.ts +1 -1
- package/dist/esm/__tests__/queries.test.js +316 -316
- package/dist/esm/__tests__/setup/indexedDB.d.ts +1 -1
- package/dist/esm/__tests__/setup/indexedDB.js +1 -1
- package/dist/esm/__tests__/undo.test.d.ts +1 -1
- package/dist/esm/__tests__/undo.test.js +84 -84
- package/dist/esm/client/Client.d.ts +99 -99
- package/dist/esm/client/Client.js +223 -223
- package/dist/esm/client/ClientDescriptor.d.ts +76 -74
- package/dist/esm/client/ClientDescriptor.js +193 -190
- package/dist/esm/client/ClientDescriptor.js.map +1 -1
- package/dist/esm/client/constants.d.ts +1 -0
- package/dist/esm/client/constants.js +2 -0
- package/dist/esm/client/constants.js.map +1 -0
- package/dist/esm/constants.d.ts +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/context.d.ts +29 -29
- package/dist/esm/context.js +1 -1
- package/dist/esm/entities/DocumentFamiliyCache.d.ts +90 -90
- package/dist/esm/entities/DocumentFamiliyCache.js +278 -278
- package/dist/esm/entities/Entity.d.ts +206 -206
- package/dist/esm/entities/Entity.js +515 -515
- package/dist/esm/entities/EntityStore.d.ts +85 -85
- package/dist/esm/entities/EntityStore.js +475 -475
- package/dist/esm/files/EntityFile.d.ts +31 -31
- package/dist/esm/files/EntityFile.js +72 -72
- package/dist/esm/files/FileManager.d.ts +42 -42
- package/dist/esm/files/FileManager.js +148 -148
- package/dist/esm/files/FileStorage.d.ts +28 -28
- package/dist/esm/files/FileStorage.js +99 -99
- package/dist/esm/files/utils.d.ts +8 -8
- package/dist/esm/files/utils.js +46 -46
- package/dist/esm/files/utils.test.d.ts +1 -1
- package/dist/esm/files/utils.test.js +78 -78
- package/dist/esm/idb.d.ts +11 -11
- package/dist/esm/idb.js +100 -100
- package/dist/esm/index.d.ts +21 -21
- package/dist/esm/index.js +12 -12
- package/dist/esm/indexes.d.ts +3 -0
- package/dist/esm/indexes.js +15 -0
- package/dist/esm/indexes.js.map +1 -0
- package/dist/esm/metadata/AckInfoStore.d.ts +10 -10
- package/dist/esm/metadata/AckInfoStore.js +21 -21
- package/dist/esm/metadata/BaselinesStore.d.ts +33 -33
- package/dist/esm/metadata/BaselinesStore.js +85 -85
- package/dist/esm/metadata/LocalHistoryStore.d.ts +15 -0
- package/dist/esm/metadata/LocalHistoryStore.js +49 -0
- package/dist/esm/metadata/LocalHistoryStore.js.map +1 -0
- package/dist/esm/metadata/LocalReplicaStore.d.ts +17 -17
- package/dist/esm/metadata/LocalReplicaStore.js +40 -40
- package/dist/esm/metadata/MessageCreator.d.ts +19 -19
- package/dist/esm/metadata/MessageCreator.js +123 -123
- package/dist/esm/metadata/Metadata.d.ts +112 -112
- package/dist/esm/metadata/Metadata.js +348 -348
- package/dist/esm/metadata/OperationsStore.d.ts +53 -53
- package/dist/esm/metadata/OperationsStore.js +148 -148
- package/dist/esm/metadata/SchemaStore.d.ts +9 -9
- package/dist/esm/metadata/SchemaStore.js +34 -34
- package/dist/esm/metadata/openMetadataDatabase.d.ts +19 -17
- package/dist/esm/metadata/openMetadataDatabase.js +214 -153
- package/dist/esm/metadata/openMetadataDatabase.js.map +1 -1
- package/dist/esm/migration/db.d.ts +8 -8
- package/dist/esm/migration/db.js +103 -103
- package/dist/esm/migration/errors.d.ts +5 -5
- package/dist/esm/migration/errors.js +7 -7
- package/dist/esm/migration/openDatabase.d.ts +20 -20
- package/dist/esm/migration/openDatabase.js +423 -423
- package/dist/esm/migration/paths.d.ts +6 -6
- package/dist/esm/migration/paths.js +48 -48
- package/dist/esm/migration/paths.test.d.ts +1 -1
- package/dist/esm/migration/paths.test.js +88 -88
- package/dist/esm/openDocumentDatabase.d.ts +12 -0
- package/dist/esm/openDocumentDatabase.js +428 -0
- package/dist/esm/openDocumentDatabase.js.map +1 -0
- package/dist/esm/queries/BaseQuery.d.ts +53 -53
- package/dist/esm/queries/BaseQuery.js +131 -131
- package/dist/esm/queries/CollectionQueries.d.ts +55 -55
- package/dist/esm/queries/CollectionQueries.js +87 -87
- package/dist/esm/queries/FindAllQuery.d.ts +12 -12
- package/dist/esm/queries/FindAllQuery.js +38 -38
- package/dist/esm/queries/FindInfiniteQuery.d.ts +19 -19
- package/dist/esm/queries/FindInfiniteQuery.js +65 -65
- package/dist/esm/queries/FindOneQuery.d.ts +12 -12
- package/dist/esm/queries/FindOneQuery.js +38 -38
- package/dist/esm/queries/FindPageQuery.d.ts +24 -24
- package/dist/esm/queries/FindPageQuery.js +72 -72
- package/dist/esm/queries/GetQuery.d.ts +10 -10
- package/dist/esm/queries/GetQuery.js +25 -25
- package/dist/esm/queries/LiveQuery.d.ts +28 -0
- package/dist/esm/queries/LiveQuery.js +92 -0
- package/dist/esm/queries/LiveQuery.js.map +1 -0
- package/dist/esm/queries/LiveQueryMaker.d.ts +15 -0
- package/dist/esm/queries/LiveQueryMaker.js +38 -0
- package/dist/esm/queries/LiveQueryMaker.js.map +1 -0
- package/dist/esm/queries/LiveQueryStore.d.ts +33 -0
- package/dist/esm/queries/LiveQueryStore.js +81 -0
- package/dist/esm/queries/LiveQueryStore.js.map +1 -0
- package/dist/esm/queries/Query.d.ts +18 -0
- package/dist/esm/queries/Query.js +32 -0
- package/dist/esm/queries/Query.js.map +1 -0
- package/dist/esm/queries/QueryCache.d.ts +16 -16
- package/dist/esm/queries/QueryCache.js +37 -37
- package/dist/esm/queries/QueryMaker.d.ts +14 -0
- package/dist/esm/queries/QueryMaker.js +38 -0
- package/dist/esm/queries/QueryMaker.js.map +1 -0
- package/dist/esm/queries/QueryStore.d.ts +35 -0
- package/dist/esm/queries/QueryStore.js +126 -0
- package/dist/esm/queries/QueryStore.js.map +1 -0
- package/dist/esm/queries/dbQueries.d.ts +22 -22
- package/dist/esm/queries/dbQueries.js +119 -119
- package/dist/esm/queries/keys.d.ts +10 -10
- package/dist/esm/queries/keys.js +29 -29
- package/dist/esm/queries/ranges.d.ts +2 -2
- package/dist/esm/queries/ranges.js +65 -65
- package/dist/esm/queries/types.d.ts +6 -6
- package/dist/esm/queries/types.js +1 -1
- package/dist/esm/queries/utils.d.ts +3 -3
- package/dist/esm/queries/utils.js +19 -19
- package/dist/esm/queries2/BaseQuery.d.ts +39 -0
- package/dist/esm/queries2/BaseQuery.js +95 -0
- package/dist/esm/queries2/BaseQuery.js.map +1 -0
- package/dist/esm/queries2/CollectionQueries.d.ts +55 -0
- package/dist/esm/queries2/CollectionQueries.js +79 -0
- package/dist/esm/queries2/CollectionQueries.js.map +1 -0
- package/dist/esm/queries2/FindAllQuery.d.ts +11 -0
- package/dist/esm/queries2/FindAllQuery.js +30 -0
- package/dist/esm/queries2/FindAllQuery.js.map +1 -0
- package/dist/esm/queries2/FindInfiniteQuery.d.ts +18 -0
- package/dist/esm/queries2/FindInfiniteQuery.js +57 -0
- package/dist/esm/queries2/FindInfiniteQuery.js.map +1 -0
- package/dist/esm/queries2/FindOneQuery.d.ts +11 -0
- package/dist/esm/queries2/FindOneQuery.js +30 -0
- package/dist/esm/queries2/FindOneQuery.js.map +1 -0
- package/dist/esm/queries2/FindPageQuery.d.ts +23 -0
- package/dist/esm/queries2/FindPageQuery.js +64 -0
- package/dist/esm/queries2/FindPageQuery.js.map +1 -0
- package/dist/esm/queries2/GetQuery.d.ts +10 -0
- package/dist/esm/queries2/GetQuery.js +26 -0
- package/dist/esm/queries2/GetQuery.js.map +1 -0
- package/dist/esm/queries2/QueryCache.d.ts +16 -0
- package/dist/esm/queries2/QueryCache.js +36 -0
- package/dist/esm/queries2/QueryCache.js.map +1 -0
- package/dist/esm/queries2/dbQueries.d.ts +22 -0
- package/dist/esm/queries2/dbQueries.js +120 -0
- package/dist/esm/queries2/dbQueries.js.map +1 -0
- package/dist/esm/queries2/keys.d.ts +10 -0
- package/dist/esm/queries2/keys.js +30 -0
- package/dist/esm/queries2/keys.js.map +1 -0
- package/dist/esm/queries2/ranges.d.ts +2 -0
- package/dist/esm/queries2/ranges.js +66 -0
- package/dist/esm/queries2/ranges.js.map +1 -0
- package/dist/esm/queries2/types.d.ts +6 -0
- package/dist/esm/queries2/types.js +2 -0
- package/dist/esm/queries2/types.js.map +1 -0
- package/dist/esm/queries2/utils.d.ts +1 -0
- package/dist/esm/queries2/utils.js +16 -0
- package/dist/esm/queries2/utils.js.map +1 -0
- package/dist/esm/reactives/DocumentFamiliyCache.d.ts +47 -0
- package/dist/esm/reactives/DocumentFamiliyCache.js +207 -0
- package/dist/esm/reactives/DocumentFamiliyCache.js.map +1 -0
- package/dist/esm/reactives/Entity.d.ts +191 -0
- package/dist/esm/reactives/Entity.js +458 -0
- package/dist/esm/reactives/Entity.js.map +1 -0
- package/dist/esm/reactives/EntityStore.d.ts +84 -0
- package/dist/esm/reactives/EntityStore.js +418 -0
- package/dist/esm/reactives/EntityStore.js.map +1 -0
- package/dist/esm/reactives/FakeWeakRef.d.ts +11 -0
- package/dist/esm/reactives/FakeWeakRef.js +15 -0
- package/dist/esm/reactives/FakeWeakRef.js.map +1 -0
- package/dist/esm/sync/FileSync.d.ts +23 -23
- package/dist/esm/sync/FileSync.js +80 -80
- package/dist/esm/sync/Heartbeat.d.ts +25 -25
- package/dist/esm/sync/Heartbeat.js +59 -59
- package/dist/esm/sync/PresenceManager.d.ts +43 -43
- package/dist/esm/sync/PresenceManager.js +115 -115
- package/dist/esm/sync/PushPullSync.d.ts +36 -36
- package/dist/esm/sync/PushPullSync.js +139 -139
- package/dist/esm/sync/ServerSyncEndpointProvider.d.ts +27 -27
- package/dist/esm/sync/ServerSyncEndpointProvider.js +57 -57
- package/dist/esm/sync/Sync.d.ts +146 -146
- package/dist/esm/sync/Sync.js +265 -265
- package/dist/esm/sync/Sync.js.map +1 -1
- package/dist/esm/sync/{WebSocketSync.d.ts → WebsocketSync.d.ts} +41 -41
- package/dist/esm/sync/{WebSocketSync.js → WebsocketSync.js} +186 -186
- package/dist/esm/types.d.ts +12 -12
- package/dist/esm/types.js +1 -1
- package/dist/esm/utils/Disposable.d.ts +6 -6
- package/dist/esm/utils/Disposable.js +14 -14
- package/dist/esm/utils/Resolvable.d.ts +8 -8
- package/dist/esm/utils/Resolvable.js +18 -18
- package/dist/esm/v2/AckInfoStore.d.ts +10 -0
- package/dist/esm/v2/AckInfoStore.js +22 -0
- package/dist/esm/v2/AckInfoStore.js.map +1 -0
- package/dist/esm/v2/BaselinesStore.d.ts +10 -0
- package/dist/esm/v2/BaselinesStore.js +32 -0
- package/dist/esm/v2/BaselinesStore.js.map +1 -0
- package/dist/esm/v2/DocumentManager.d.ts +19 -0
- package/dist/esm/v2/DocumentManager.js +43 -0
- package/dist/esm/v2/DocumentManager.js.map +1 -0
- package/dist/esm/v2/Entity.d.ts +91 -0
- package/dist/esm/v2/Entity.js +305 -0
- package/dist/esm/v2/Entity.js.map +1 -0
- package/dist/esm/v2/EntityStore.d.ts +37 -0
- package/dist/esm/v2/EntityStore.js +166 -0
- package/dist/esm/v2/EntityStore.js.map +1 -0
- package/dist/esm/v2/IDBService.d.ts +7 -0
- package/dist/esm/v2/IDBService.js +22 -0
- package/dist/esm/v2/IDBService.js.map +1 -0
- package/dist/esm/v2/LocalHistoryStore.d.ts +15 -0
- package/dist/esm/v2/LocalHistoryStore.js +49 -0
- package/dist/esm/v2/LocalHistoryStore.js.map +1 -0
- package/dist/esm/v2/LocalReplicaStore.d.ts +14 -0
- package/dist/esm/v2/LocalReplicaStore.js +42 -0
- package/dist/esm/v2/LocalReplicaStore.js.map +1 -0
- package/dist/esm/v2/MessageCreator.d.ts +19 -0
- package/dist/esm/v2/MessageCreator.js +92 -0
- package/dist/esm/v2/MessageCreator.js.map +1 -0
- package/dist/esm/v2/Metadata.d.ts +90 -0
- package/dist/esm/v2/Metadata.js +246 -0
- package/dist/esm/v2/Metadata.js.map +1 -0
- package/dist/esm/v2/OperationsStore.d.ts +38 -0
- package/dist/esm/v2/OperationsStore.js +142 -0
- package/dist/esm/v2/OperationsStore.js.map +1 -0
- package/dist/esm/v2/PresenceManager.d.ts +24 -0
- package/dist/esm/v2/PresenceManager.js +69 -0
- package/dist/esm/v2/PresenceManager.js.map +1 -0
- package/dist/esm/v2/Query.d.ts +24 -0
- package/dist/esm/v2/Query.js +75 -0
- package/dist/esm/v2/Query.js.map +1 -0
- package/dist/esm/v2/QueryMaker.d.ts +16 -0
- package/dist/esm/v2/QueryMaker.js +80 -0
- package/dist/esm/v2/QueryMaker.js.map +1 -0
- package/dist/esm/v2/QueryStore.d.ts +26 -0
- package/dist/esm/v2/QueryStore.js +132 -0
- package/dist/esm/v2/QueryStore.js.map +1 -0
- package/dist/esm/v2/SchemaStore.d.ts +9 -0
- package/dist/esm/v2/SchemaStore.js +31 -0
- package/dist/esm/v2/SchemaStore.js.map +1 -0
- package/dist/esm/v2/Storage.d.ts +80 -0
- package/dist/esm/v2/Storage.js +149 -0
- package/dist/esm/v2/Storage.js.map +1 -0
- package/dist/esm/v2/Sync.d.ts +42 -0
- package/dist/esm/v2/Sync.js +94 -0
- package/dist/esm/v2/Sync.js.map +1 -0
- package/dist/esm/v2/SyncHarness.d.ts +45 -0
- package/dist/esm/v2/SyncHarness.js +105 -0
- package/dist/esm/v2/SyncHarness.js.map +1 -0
- package/dist/esm/v2/__tests__/documents.test.d.ts +1 -0
- package/dist/esm/v2/__tests__/documents.test.js +208 -0
- package/dist/esm/v2/__tests__/documents.test.js.map +1 -0
- package/dist/esm/v2/__tests__/fixtures/testStorage.d.ts +223 -0
- package/dist/esm/v2/__tests__/fixtures/testStorage.js +106 -0
- package/dist/esm/v2/__tests__/fixtures/testStorage.js.map +1 -0
- package/dist/esm/v2/__tests__/queries.test.d.ts +1 -0
- package/dist/esm/v2/__tests__/queries.test.js +90 -0
- package/dist/esm/v2/__tests__/queries.test.js.map +1 -0
- package/dist/esm/v2/__tests__/setup/indexedDB.d.ts +1 -0
- package/dist/esm/v2/__tests__/setup/indexedDB.js +2 -0
- package/dist/esm/v2/__tests__/setup/indexedDB.js.map +1 -0
- package/dist/esm/v2/constants.d.ts +1 -0
- package/dist/esm/v2/constants.js +2 -0
- package/dist/esm/v2/constants.js.map +1 -0
- package/dist/esm/v2/idb.d.ts +6 -0
- package/dist/esm/v2/idb.js +65 -0
- package/dist/esm/v2/idb.js.map +1 -0
- package/dist/esm/v2/index.d.ts +6 -0
- package/dist/esm/v2/index.js +5 -0
- package/dist/esm/v2/index.js.map +1 -0
- package/dist/esm/v2/indexes.d.ts +3 -0
- package/dist/esm/v2/indexes.js +15 -0
- package/dist/esm/v2/indexes.js.map +1 -0
- package/dist/esm/v2/openDocumentDatabase.d.ts +9 -0
- package/dist/esm/v2/openDocumentDatabase.js +96 -0
- package/dist/esm/v2/openDocumentDatabase.js.map +1 -0
- package/dist/esm/v2/types.d.ts +3 -0
- package/dist/esm/v2/types.js +2 -0
- package/dist/esm/v2/types.js.map +1 -0
- package/dist/esm/vanilla.d.ts +1 -1
- package/dist/esm/vanilla.js +2 -2
- package/dist/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/__tests__/fixtures/testStorage.ts +8 -1
- package/src/__tests__/legacyOids.test.ts +240 -49
- package/src/client/ClientDescriptor.ts +6 -0
- package/src/client/constants.ts +1 -0
- package/src/metadata/openMetadataDatabase.ts +65 -2
- package/src/sync/Sync.ts +1 -0
- /package/dist/esm/sync/{WebSocketSync.js.map → WebsocketSync.js.map} +0 -0
|
@@ -1,351 +1,351 @@
|
|
|
1
|
-
import { applyPatch, assert, assignOid, EventSubscriber, isFileRef, getOidRoot, HybridLogicalClockTimestampProvider, PatchCreator, substituteRefsWithObjects, } from '@verdant-web/common';
|
|
2
|
-
import { AckInfoStore } from './AckInfoStore.js';
|
|
3
|
-
import { BaselinesStore } from './BaselinesStore.js';
|
|
4
|
-
import { getAllFromObjectStores, getSizeOfObjectStore, storeRequestPromise, } from '../idb.js';
|
|
5
|
-
import { LocalReplicaStore } from './LocalReplicaStore.js';
|
|
6
|
-
import { MessageCreator } from './MessageCreator.js';
|
|
7
|
-
import { OperationsStore } from './OperationsStore.js';
|
|
8
|
-
import { SchemaStore } from './SchemaStore.js';
|
|
9
|
-
export class Metadata extends EventSubscriber {
|
|
10
|
-
constructor({ disableRebasing, context, }) {
|
|
11
|
-
super();
|
|
12
|
-
this.time = new HybridLogicalClockTimestampProvider();
|
|
13
|
-
this.disableRebasing = false;
|
|
14
|
-
/**
|
|
15
|
-
* indicates the client is shutting down and we should stop
|
|
16
|
-
* accessing the database.
|
|
17
|
-
*/
|
|
18
|
-
this._closing = false;
|
|
19
|
-
this.setContext = (context) => {
|
|
20
|
-
this.context = context;
|
|
21
|
-
};
|
|
22
|
-
this.close = () => {
|
|
23
|
-
this._closing = true;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Methods for accessing data
|
|
27
|
-
*/
|
|
28
|
-
this.createTransaction = (stores) => {
|
|
29
|
-
return this.db.transaction(stores, 'readwrite');
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Gets the OID and every sub-object OID for a given document.
|
|
33
|
-
* Includes any sub-objects that are not referenced by the root object
|
|
34
|
-
* but still happen to be in storage.
|
|
35
|
-
*/
|
|
36
|
-
this.getAllDocumentRelatedOids = async (oid) => {
|
|
37
|
-
const oids = new Set();
|
|
38
|
-
const documentOid = getOidRoot(oid);
|
|
39
|
-
assert(documentOid === oid, 'Must be root document OID');
|
|
40
|
-
oids.add(documentOid);
|
|
41
|
-
// readwrite mode to block on other write transactions
|
|
42
|
-
const transaction = this.db.transaction(['baselines', 'operations'], 'readwrite');
|
|
43
|
-
await Promise.all([
|
|
44
|
-
this.baselines.iterateOverAllForDocument(documentOid, (baseline) => {
|
|
45
|
-
oids.add(baseline.oid);
|
|
46
|
-
}, { transaction }),
|
|
47
|
-
this.operations.iterateOverAllOperationsForDocument(documentOid, (patch) => {
|
|
48
|
-
oids.add(patch.oid);
|
|
49
|
-
}, { transaction }),
|
|
50
|
-
]);
|
|
51
|
-
return Array.from(oids);
|
|
52
|
-
};
|
|
53
|
-
this.getDocumentSnapshot = async (oid, options = {}) => {
|
|
54
|
-
const documentOid = getOidRoot(oid);
|
|
55
|
-
assert(documentOid === oid, 'Must be root document OID');
|
|
56
|
-
const transaction = this.db.transaction(['baselines', 'operations'], 'readwrite');
|
|
57
|
-
const baselines = await this.baselines.getAllForDocument(documentOid, {
|
|
58
|
-
transaction,
|
|
59
|
-
});
|
|
60
|
-
const objectMap = new Map();
|
|
61
|
-
for (const baseline of baselines) {
|
|
62
|
-
if (baseline.snapshot) {
|
|
63
|
-
assignOid(baseline.snapshot, baseline.oid);
|
|
64
|
-
}
|
|
65
|
-
objectMap.set(baseline.oid, baseline.snapshot);
|
|
66
|
-
}
|
|
67
|
-
await this.operations.iterateOverAllOperationsForDocument(documentOid, (op) => {
|
|
68
|
-
const obj = objectMap.get(op.oid) || undefined;
|
|
69
|
-
const newObj = applyPatch(obj, op.data);
|
|
70
|
-
if (newObj) {
|
|
71
|
-
assignOid(newObj, op.oid);
|
|
72
|
-
}
|
|
73
|
-
objectMap.set(op.oid, newObj);
|
|
74
|
-
}, {
|
|
75
|
-
transaction,
|
|
76
|
-
// only apply operations up to the current time
|
|
77
|
-
to: options.to || this.now,
|
|
78
|
-
});
|
|
79
|
-
const root = objectMap.get(documentOid);
|
|
80
|
-
if (root) {
|
|
81
|
-
substituteRefsWithObjects(root, objectMap);
|
|
82
|
-
}
|
|
83
|
-
return root;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Methods for writing data
|
|
87
|
-
*/
|
|
88
|
-
/**
|
|
89
|
-
* Acks that we have seen a timestamp to the server
|
|
90
|
-
* and stores it as our local ackedLogicalTime if it's
|
|
91
|
-
* greater than our current ackedLogicalTime.
|
|
92
|
-
*/
|
|
93
|
-
this.ack = async (timestamp) => {
|
|
94
|
-
const localReplicaInfo = await this.localReplica.get();
|
|
95
|
-
// can't ack timestamps from the future.
|
|
96
|
-
if (timestamp > this.now)
|
|
97
|
-
return;
|
|
98
|
-
this.emit('message', {
|
|
99
|
-
type: 'ack',
|
|
100
|
-
replicaId: localReplicaInfo.id,
|
|
101
|
-
timestamp,
|
|
102
|
-
});
|
|
103
|
-
if (!this._closing &&
|
|
104
|
-
(!localReplicaInfo.ackedLogicalTime ||
|
|
105
|
-
timestamp > localReplicaInfo.ackedLogicalTime)) {
|
|
106
|
-
this.localReplica.update({ ackedLogicalTime: timestamp });
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Applies a patch to the document and stores it in the database.
|
|
111
|
-
* @returns the oldest local history timestamp
|
|
112
|
-
*/
|
|
113
|
-
this.insertLocalOperation = async (operations) => {
|
|
114
|
-
if (operations.length === 0)
|
|
115
|
-
return;
|
|
116
|
-
// await this.rebaseLock;
|
|
117
|
-
this.log(`Inserting ${operations.length} local operations`);
|
|
118
|
-
// add local flag, in place.
|
|
119
|
-
for (const operation of operations) {
|
|
120
|
-
operation.isLocal = true;
|
|
121
|
-
}
|
|
122
|
-
await this.operations.addOperations(operations);
|
|
123
|
-
const message = await this.messageCreator.createOperation({ operations });
|
|
124
|
-
this.emit('message', message);
|
|
125
|
-
// we can now enqueue and check for rebase opportunities
|
|
126
|
-
this.tryAutonomousRebase();
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* Inserts remote operations. This does not affect local history.
|
|
130
|
-
* @returns a list of affected document OIDs
|
|
131
|
-
*/
|
|
132
|
-
this.insertRemoteOperations = async (operations) => {
|
|
133
|
-
if (operations.length === 0)
|
|
134
|
-
return [];
|
|
135
|
-
// await this.rebaseLock;
|
|
136
|
-
this.log(`Inserting ${operations.length} remote operations`);
|
|
137
|
-
const affectedDocumentOids = await this.operations.addOperations(operations.map((patch) => (Object.assign(Object.assign({}, patch), { isLocal: false }))));
|
|
138
|
-
this.ack(operations[operations.length - 1].timestamp);
|
|
139
|
-
return affectedDocumentOids;
|
|
140
|
-
};
|
|
141
|
-
this.insertRemoteBaselines = async (baselines) => {
|
|
142
|
-
if (baselines.length === 0)
|
|
143
|
-
return [];
|
|
144
|
-
this.log(`Inserting ${baselines.length} remote baselines`);
|
|
145
|
-
await this.baselines.setAll(baselines);
|
|
146
|
-
// this.ack(baselines[baselines.length - 1].timestamp);
|
|
147
|
-
const affectedOidSet = new Set();
|
|
148
|
-
baselines.forEach((baseline) => {
|
|
149
|
-
affectedOidSet.add(getOidRoot(baseline.oid));
|
|
150
|
-
});
|
|
151
|
-
return Array.from(affectedOidSet);
|
|
152
|
-
};
|
|
153
|
-
this.updateLastSynced = async (timestamp) => {
|
|
154
|
-
if (this._closing)
|
|
155
|
-
return;
|
|
156
|
-
return this.localReplica.update({
|
|
157
|
-
lastSyncedLogicalTime: timestamp,
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
this.lastSyncedTimestamp = async () => {
|
|
161
|
-
const localReplicaInfo = await this.localReplica.get();
|
|
162
|
-
return localReplicaInfo.lastSyncedLogicalTime;
|
|
163
|
-
};
|
|
164
|
-
this.tryAutonomousRebase = async () => {
|
|
165
|
-
if (this.disableRebasing)
|
|
166
|
-
return;
|
|
167
|
-
const localReplicaInfo = await this.localReplica.get();
|
|
168
|
-
if (localReplicaInfo.lastSyncedLogicalTime)
|
|
169
|
-
return; // cannot autonomously rebase if we've synced
|
|
170
|
-
// but if we have never synced... we can rebase everything!
|
|
171
|
-
await this.runRebase(this.now);
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* Attempt to autonomously rebase local documents without server intervention.
|
|
175
|
-
* This can currently only happen for a client who has never synced before.
|
|
176
|
-
* The goal is to allow local-only clients to compress their history to exactly
|
|
177
|
-
* their undo stack.
|
|
178
|
-
*/
|
|
179
|
-
this.runRebase = async (globalAckTimestamp) => {
|
|
180
|
-
if (this._closing)
|
|
181
|
-
return;
|
|
182
|
-
// find all operations before the global ack
|
|
183
|
-
let lastTimestamp;
|
|
184
|
-
const toRebase = new Set();
|
|
185
|
-
const transaction = this.db.transaction(['baselines', 'operations'], 'readwrite');
|
|
186
|
-
let operationCount = 0;
|
|
187
|
-
await this.operations.iterateOverAllOperations((patch) => {
|
|
188
|
-
toRebase.add(patch.oid);
|
|
189
|
-
lastTimestamp = patch.timestamp;
|
|
190
|
-
operationCount++;
|
|
191
|
-
}, {
|
|
192
|
-
before: globalAckTimestamp,
|
|
193
|
-
transaction,
|
|
194
|
-
});
|
|
195
|
-
if (!toRebase.size) {
|
|
196
|
-
this.log('Cannot rebase, no operations prior to', globalAckTimestamp);
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if (this._closing) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
// rebase each affected document
|
|
203
|
-
let newBaselines = [];
|
|
204
|
-
for (const oid of toRebase) {
|
|
205
|
-
newBaselines.push(await this.rebase(oid, lastTimestamp || globalAckTimestamp, transaction));
|
|
206
|
-
}
|
|
207
|
-
this.emit('rebase', newBaselines);
|
|
208
|
-
};
|
|
209
|
-
this.rebase = async (oid, upTo, providedTx) => {
|
|
210
|
-
// including replica Id for testing I guess
|
|
211
|
-
const replicaId = (await this.localReplica.get()).id;
|
|
212
|
-
this.log('[', replicaId, ']', 'Rebasing', oid, 'up to', upTo);
|
|
213
|
-
const transaction = providedTx ||
|
|
214
|
-
this.db.transaction(['operations', 'baselines'], 'readwrite');
|
|
215
|
-
const baseline = await this.baselines.get(oid, { transaction });
|
|
216
|
-
let current = (baseline === null || baseline === void 0 ? void 0 : baseline.snapshot) || undefined;
|
|
217
|
-
let operationsApplied = 0;
|
|
218
|
-
const deletedRefs = [];
|
|
219
|
-
await this.operations.iterateOverAllOperationsForEntity(oid, (patch, store) => {
|
|
220
|
-
// FIXME: this seems like the wrong place to do this
|
|
221
|
-
// but it's here as a safety measure...
|
|
222
|
-
if (!baseline || patch.timestamp > baseline.timestamp) {
|
|
223
|
-
current = applyPatch(current, patch.data, deletedRefs);
|
|
224
|
-
}
|
|
225
|
-
// delete all prior operations to the baseline
|
|
226
|
-
operationsApplied++;
|
|
227
|
-
store.delete(patch.oid_timestamp);
|
|
228
|
-
}, {
|
|
229
|
-
to: upTo,
|
|
230
|
-
transaction,
|
|
231
|
-
});
|
|
232
|
-
if (current) {
|
|
233
|
-
assignOid(current, oid);
|
|
234
|
-
}
|
|
235
|
-
const newBaseline = {
|
|
236
|
-
oid,
|
|
237
|
-
snapshot: current,
|
|
238
|
-
timestamp: upTo,
|
|
239
|
-
};
|
|
240
|
-
if (newBaseline.snapshot) {
|
|
241
|
-
await this.baselines.set(newBaseline, { transaction });
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
await this.baselines.delete(oid, { transaction });
|
|
245
|
-
}
|
|
246
|
-
this.log('successfully rebased', oid, 'up to', upTo, ':', current, 'and deleted', operationsApplied, 'operations');
|
|
247
|
-
// cleanup deleted refs
|
|
248
|
-
if (deletedRefs.length) {
|
|
249
|
-
const fileRefs = deletedRefs.filter(isFileRef);
|
|
250
|
-
if (fileRefs.length) {
|
|
251
|
-
this.emit('filesDeleted', fileRefs);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return newBaseline;
|
|
255
|
-
};
|
|
256
|
-
this.reset = async () => {
|
|
257
|
-
await this.operations.reset();
|
|
258
|
-
await this.baselines.reset();
|
|
259
|
-
await this.localReplica.reset();
|
|
260
|
-
};
|
|
261
|
-
this.updateSchema = async (schema, overrideConflict) => {
|
|
262
|
-
const storedSchema = await this.schema.get();
|
|
263
|
-
if (storedSchema) {
|
|
264
|
-
// version changes will be handled by migration routines in
|
|
265
|
-
// the actual idb database loading code (see: initializeDatabases)
|
|
266
|
-
// but this check determines if the schema has been changed without
|
|
267
|
-
// a version change. if so, it will error.
|
|
268
|
-
if (overrideConflict === storedSchema.version &&
|
|
269
|
-
storedSchema.version === schema.version &&
|
|
270
|
-
JSON.stringify(storedSchema) !== JSON.stringify(schema)) {
|
|
1
|
+
import { applyPatch, assert, assignOid, EventSubscriber, isFileRef, getOidRoot, HybridLogicalClockTimestampProvider, PatchCreator, substituteRefsWithObjects, } from '@verdant-web/common';
|
|
2
|
+
import { AckInfoStore } from './AckInfoStore.js';
|
|
3
|
+
import { BaselinesStore } from './BaselinesStore.js';
|
|
4
|
+
import { getAllFromObjectStores, getSizeOfObjectStore, storeRequestPromise, } from '../idb.js';
|
|
5
|
+
import { LocalReplicaStore } from './LocalReplicaStore.js';
|
|
6
|
+
import { MessageCreator } from './MessageCreator.js';
|
|
7
|
+
import { OperationsStore } from './OperationsStore.js';
|
|
8
|
+
import { SchemaStore } from './SchemaStore.js';
|
|
9
|
+
export class Metadata extends EventSubscriber {
|
|
10
|
+
constructor({ disableRebasing, context, }) {
|
|
11
|
+
super();
|
|
12
|
+
this.time = new HybridLogicalClockTimestampProvider();
|
|
13
|
+
this.disableRebasing = false;
|
|
14
|
+
/**
|
|
15
|
+
* indicates the client is shutting down and we should stop
|
|
16
|
+
* accessing the database.
|
|
17
|
+
*/
|
|
18
|
+
this._closing = false;
|
|
19
|
+
this.setContext = (context) => {
|
|
20
|
+
this.context = context;
|
|
21
|
+
};
|
|
22
|
+
this.close = () => {
|
|
23
|
+
this._closing = true;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Methods for accessing data
|
|
27
|
+
*/
|
|
28
|
+
this.createTransaction = (stores) => {
|
|
29
|
+
return this.db.transaction(stores, 'readwrite');
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Gets the OID and every sub-object OID for a given document.
|
|
33
|
+
* Includes any sub-objects that are not referenced by the root object
|
|
34
|
+
* but still happen to be in storage.
|
|
35
|
+
*/
|
|
36
|
+
this.getAllDocumentRelatedOids = async (oid) => {
|
|
37
|
+
const oids = new Set();
|
|
38
|
+
const documentOid = getOidRoot(oid);
|
|
39
|
+
assert(documentOid === oid, 'Must be root document OID');
|
|
40
|
+
oids.add(documentOid);
|
|
41
|
+
// readwrite mode to block on other write transactions
|
|
42
|
+
const transaction = this.db.transaction(['baselines', 'operations'], 'readwrite');
|
|
43
|
+
await Promise.all([
|
|
44
|
+
this.baselines.iterateOverAllForDocument(documentOid, (baseline) => {
|
|
45
|
+
oids.add(baseline.oid);
|
|
46
|
+
}, { transaction }),
|
|
47
|
+
this.operations.iterateOverAllOperationsForDocument(documentOid, (patch) => {
|
|
48
|
+
oids.add(patch.oid);
|
|
49
|
+
}, { transaction }),
|
|
50
|
+
]);
|
|
51
|
+
return Array.from(oids);
|
|
52
|
+
};
|
|
53
|
+
this.getDocumentSnapshot = async (oid, options = {}) => {
|
|
54
|
+
const documentOid = getOidRoot(oid);
|
|
55
|
+
assert(documentOid === oid, 'Must be root document OID');
|
|
56
|
+
const transaction = this.db.transaction(['baselines', 'operations'], 'readwrite');
|
|
57
|
+
const baselines = await this.baselines.getAllForDocument(documentOid, {
|
|
58
|
+
transaction,
|
|
59
|
+
});
|
|
60
|
+
const objectMap = new Map();
|
|
61
|
+
for (const baseline of baselines) {
|
|
62
|
+
if (baseline.snapshot) {
|
|
63
|
+
assignOid(baseline.snapshot, baseline.oid);
|
|
64
|
+
}
|
|
65
|
+
objectMap.set(baseline.oid, baseline.snapshot);
|
|
66
|
+
}
|
|
67
|
+
await this.operations.iterateOverAllOperationsForDocument(documentOid, (op) => {
|
|
68
|
+
const obj = objectMap.get(op.oid) || undefined;
|
|
69
|
+
const newObj = applyPatch(obj, op.data);
|
|
70
|
+
if (newObj) {
|
|
71
|
+
assignOid(newObj, op.oid);
|
|
72
|
+
}
|
|
73
|
+
objectMap.set(op.oid, newObj);
|
|
74
|
+
}, {
|
|
75
|
+
transaction,
|
|
76
|
+
// only apply operations up to the current time
|
|
77
|
+
to: options.to || this.now,
|
|
78
|
+
});
|
|
79
|
+
const root = objectMap.get(documentOid);
|
|
80
|
+
if (root) {
|
|
81
|
+
substituteRefsWithObjects(root, objectMap);
|
|
82
|
+
}
|
|
83
|
+
return root;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Methods for writing data
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* Acks that we have seen a timestamp to the server
|
|
90
|
+
* and stores it as our local ackedLogicalTime if it's
|
|
91
|
+
* greater than our current ackedLogicalTime.
|
|
92
|
+
*/
|
|
93
|
+
this.ack = async (timestamp) => {
|
|
94
|
+
const localReplicaInfo = await this.localReplica.get();
|
|
95
|
+
// can't ack timestamps from the future.
|
|
96
|
+
if (timestamp > this.now)
|
|
97
|
+
return;
|
|
98
|
+
this.emit('message', {
|
|
99
|
+
type: 'ack',
|
|
100
|
+
replicaId: localReplicaInfo.id,
|
|
101
|
+
timestamp,
|
|
102
|
+
});
|
|
103
|
+
if (!this._closing &&
|
|
104
|
+
(!localReplicaInfo.ackedLogicalTime ||
|
|
105
|
+
timestamp > localReplicaInfo.ackedLogicalTime)) {
|
|
106
|
+
this.localReplica.update({ ackedLogicalTime: timestamp });
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Applies a patch to the document and stores it in the database.
|
|
111
|
+
* @returns the oldest local history timestamp
|
|
112
|
+
*/
|
|
113
|
+
this.insertLocalOperation = async (operations) => {
|
|
114
|
+
if (operations.length === 0)
|
|
115
|
+
return;
|
|
116
|
+
// await this.rebaseLock;
|
|
117
|
+
this.log(`Inserting ${operations.length} local operations`);
|
|
118
|
+
// add local flag, in place.
|
|
119
|
+
for (const operation of operations) {
|
|
120
|
+
operation.isLocal = true;
|
|
121
|
+
}
|
|
122
|
+
await this.operations.addOperations(operations);
|
|
123
|
+
const message = await this.messageCreator.createOperation({ operations });
|
|
124
|
+
this.emit('message', message);
|
|
125
|
+
// we can now enqueue and check for rebase opportunities
|
|
126
|
+
this.tryAutonomousRebase();
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Inserts remote operations. This does not affect local history.
|
|
130
|
+
* @returns a list of affected document OIDs
|
|
131
|
+
*/
|
|
132
|
+
this.insertRemoteOperations = async (operations) => {
|
|
133
|
+
if (operations.length === 0)
|
|
134
|
+
return [];
|
|
135
|
+
// await this.rebaseLock;
|
|
136
|
+
this.log(`Inserting ${operations.length} remote operations`);
|
|
137
|
+
const affectedDocumentOids = await this.operations.addOperations(operations.map((patch) => (Object.assign(Object.assign({}, patch), { isLocal: false }))));
|
|
138
|
+
this.ack(operations[operations.length - 1].timestamp);
|
|
139
|
+
return affectedDocumentOids;
|
|
140
|
+
};
|
|
141
|
+
this.insertRemoteBaselines = async (baselines) => {
|
|
142
|
+
if (baselines.length === 0)
|
|
143
|
+
return [];
|
|
144
|
+
this.log(`Inserting ${baselines.length} remote baselines`);
|
|
145
|
+
await this.baselines.setAll(baselines);
|
|
146
|
+
// this.ack(baselines[baselines.length - 1].timestamp);
|
|
147
|
+
const affectedOidSet = new Set();
|
|
148
|
+
baselines.forEach((baseline) => {
|
|
149
|
+
affectedOidSet.add(getOidRoot(baseline.oid));
|
|
150
|
+
});
|
|
151
|
+
return Array.from(affectedOidSet);
|
|
152
|
+
};
|
|
153
|
+
this.updateLastSynced = async (timestamp) => {
|
|
154
|
+
if (this._closing)
|
|
155
|
+
return;
|
|
156
|
+
return this.localReplica.update({
|
|
157
|
+
lastSyncedLogicalTime: timestamp,
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
this.lastSyncedTimestamp = async () => {
|
|
161
|
+
const localReplicaInfo = await this.localReplica.get();
|
|
162
|
+
return localReplicaInfo.lastSyncedLogicalTime;
|
|
163
|
+
};
|
|
164
|
+
this.tryAutonomousRebase = async () => {
|
|
165
|
+
if (this.disableRebasing)
|
|
166
|
+
return;
|
|
167
|
+
const localReplicaInfo = await this.localReplica.get();
|
|
168
|
+
if (localReplicaInfo.lastSyncedLogicalTime)
|
|
169
|
+
return; // cannot autonomously rebase if we've synced
|
|
170
|
+
// but if we have never synced... we can rebase everything!
|
|
171
|
+
await this.runRebase(this.now);
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Attempt to autonomously rebase local documents without server intervention.
|
|
175
|
+
* This can currently only happen for a client who has never synced before.
|
|
176
|
+
* The goal is to allow local-only clients to compress their history to exactly
|
|
177
|
+
* their undo stack.
|
|
178
|
+
*/
|
|
179
|
+
this.runRebase = async (globalAckTimestamp) => {
|
|
180
|
+
if (this._closing)
|
|
181
|
+
return;
|
|
182
|
+
// find all operations before the global ack
|
|
183
|
+
let lastTimestamp;
|
|
184
|
+
const toRebase = new Set();
|
|
185
|
+
const transaction = this.db.transaction(['baselines', 'operations'], 'readwrite');
|
|
186
|
+
let operationCount = 0;
|
|
187
|
+
await this.operations.iterateOverAllOperations((patch) => {
|
|
188
|
+
toRebase.add(patch.oid);
|
|
189
|
+
lastTimestamp = patch.timestamp;
|
|
190
|
+
operationCount++;
|
|
191
|
+
}, {
|
|
192
|
+
before: globalAckTimestamp,
|
|
193
|
+
transaction,
|
|
194
|
+
});
|
|
195
|
+
if (!toRebase.size) {
|
|
196
|
+
this.log('Cannot rebase, no operations prior to', globalAckTimestamp);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (this._closing) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// rebase each affected document
|
|
203
|
+
let newBaselines = [];
|
|
204
|
+
for (const oid of toRebase) {
|
|
205
|
+
newBaselines.push(await this.rebase(oid, lastTimestamp || globalAckTimestamp, transaction));
|
|
206
|
+
}
|
|
207
|
+
this.emit('rebase', newBaselines);
|
|
208
|
+
};
|
|
209
|
+
this.rebase = async (oid, upTo, providedTx) => {
|
|
210
|
+
// including replica Id for testing I guess
|
|
211
|
+
const replicaId = (await this.localReplica.get()).id;
|
|
212
|
+
this.log('[', replicaId, ']', 'Rebasing', oid, 'up to', upTo);
|
|
213
|
+
const transaction = providedTx ||
|
|
214
|
+
this.db.transaction(['operations', 'baselines'], 'readwrite');
|
|
215
|
+
const baseline = await this.baselines.get(oid, { transaction });
|
|
216
|
+
let current = (baseline === null || baseline === void 0 ? void 0 : baseline.snapshot) || undefined;
|
|
217
|
+
let operationsApplied = 0;
|
|
218
|
+
const deletedRefs = [];
|
|
219
|
+
await this.operations.iterateOverAllOperationsForEntity(oid, (patch, store) => {
|
|
220
|
+
// FIXME: this seems like the wrong place to do this
|
|
221
|
+
// but it's here as a safety measure...
|
|
222
|
+
if (!baseline || patch.timestamp > baseline.timestamp) {
|
|
223
|
+
current = applyPatch(current, patch.data, deletedRefs);
|
|
224
|
+
}
|
|
225
|
+
// delete all prior operations to the baseline
|
|
226
|
+
operationsApplied++;
|
|
227
|
+
store.delete(patch.oid_timestamp);
|
|
228
|
+
}, {
|
|
229
|
+
to: upTo,
|
|
230
|
+
transaction,
|
|
231
|
+
});
|
|
232
|
+
if (current) {
|
|
233
|
+
assignOid(current, oid);
|
|
234
|
+
}
|
|
235
|
+
const newBaseline = {
|
|
236
|
+
oid,
|
|
237
|
+
snapshot: current,
|
|
238
|
+
timestamp: upTo,
|
|
239
|
+
};
|
|
240
|
+
if (newBaseline.snapshot) {
|
|
241
|
+
await this.baselines.set(newBaseline, { transaction });
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
await this.baselines.delete(oid, { transaction });
|
|
245
|
+
}
|
|
246
|
+
this.log('successfully rebased', oid, 'up to', upTo, ':', current, 'and deleted', operationsApplied, 'operations');
|
|
247
|
+
// cleanup deleted refs
|
|
248
|
+
if (deletedRefs.length) {
|
|
249
|
+
const fileRefs = deletedRefs.filter(isFileRef);
|
|
250
|
+
if (fileRefs.length) {
|
|
251
|
+
this.emit('filesDeleted', fileRefs);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return newBaseline;
|
|
255
|
+
};
|
|
256
|
+
this.reset = async () => {
|
|
257
|
+
await this.operations.reset();
|
|
258
|
+
await this.baselines.reset();
|
|
259
|
+
await this.localReplica.reset();
|
|
260
|
+
};
|
|
261
|
+
this.updateSchema = async (schema, overrideConflict) => {
|
|
262
|
+
const storedSchema = await this.schema.get();
|
|
263
|
+
if (storedSchema) {
|
|
264
|
+
// version changes will be handled by migration routines in
|
|
265
|
+
// the actual idb database loading code (see: initializeDatabases)
|
|
266
|
+
// but this check determines if the schema has been changed without
|
|
267
|
+
// a version change. if so, it will error.
|
|
268
|
+
if (overrideConflict === storedSchema.version &&
|
|
269
|
+
storedSchema.version === schema.version &&
|
|
270
|
+
JSON.stringify(storedSchema) !== JSON.stringify(schema)) {
|
|
271
271
|
console.error(`Schema mismatch for version ${schema.version}
|
|
272
272
|
${JSON.stringify(storedSchema)}
|
|
273
|
-
${JSON.stringify(schema)}`);
|
|
274
|
-
throw new Error('Schema has changed without a version change! Any changes to your schema must be accompanied by a change in schema version and a migration routine.');
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
await this.schema.set(schema);
|
|
278
|
-
};
|
|
279
|
-
this.setGlobalAck = async (timestamp) => {
|
|
280
|
-
if (this._closing)
|
|
281
|
-
return;
|
|
282
|
-
await this.ackInfo.setGlobalAck(timestamp);
|
|
283
|
-
if (!this.disableRebasing) {
|
|
284
|
-
await this.runRebase(timestamp);
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
this.export = async () => {
|
|
288
|
-
const db = this.db;
|
|
289
|
-
const [baselines, operations] = await getAllFromObjectStores(db, [
|
|
290
|
-
'baselines',
|
|
291
|
-
'operations',
|
|
292
|
-
]);
|
|
293
|
-
const localReplica = await this.localReplica.get();
|
|
294
|
-
const schema = await this.schema.get();
|
|
295
|
-
if (!schema) {
|
|
296
|
-
throw new Error('Cannot export Client data before initializing');
|
|
297
|
-
}
|
|
298
|
-
return {
|
|
299
|
-
operations,
|
|
300
|
-
baselines,
|
|
301
|
-
localReplica,
|
|
302
|
-
schema,
|
|
303
|
-
};
|
|
304
|
-
};
|
|
305
|
-
/**
|
|
306
|
-
* Resets local metadata and clears operation/baseline stores.
|
|
307
|
-
* DOES NOT add operations/baselines - this should be done
|
|
308
|
-
* through the normal higher level systems.
|
|
309
|
-
*/
|
|
310
|
-
this.resetFrom = async (data) => {
|
|
311
|
-
const db = this.db;
|
|
312
|
-
const transaction = db.transaction(['baselines', 'operations', 'info'], 'readwrite');
|
|
313
|
-
await storeRequestPromise(transaction.objectStore('baselines').clear());
|
|
314
|
-
await storeRequestPromise(transaction.objectStore('operations').clear());
|
|
315
|
-
await storeRequestPromise(transaction.objectStore('info').clear());
|
|
316
|
-
await this.localReplica.update({
|
|
317
|
-
ackedLogicalTime: data.localReplica.ackedLogicalTime,
|
|
318
|
-
lastSyncedLogicalTime: data.localReplica.lastSyncedLogicalTime,
|
|
319
|
-
}, { transaction });
|
|
320
|
-
};
|
|
321
|
-
this.stats = async () => {
|
|
322
|
-
const db = this.db;
|
|
323
|
-
const operationsSize = await getSizeOfObjectStore(db, 'operations');
|
|
324
|
-
const baselinesSize = await getSizeOfObjectStore(db, 'baselines');
|
|
325
|
-
return {
|
|
326
|
-
operationsSize,
|
|
327
|
-
baselinesSize,
|
|
328
|
-
};
|
|
329
|
-
};
|
|
330
|
-
this.context = context;
|
|
331
|
-
this.schema = new SchemaStore(context.metaDb, context.schema.version);
|
|
332
|
-
this.operations = new OperationsStore(this.db);
|
|
333
|
-
this.baselines = new BaselinesStore(this.db);
|
|
334
|
-
this.localReplica = new LocalReplicaStore(this.db);
|
|
335
|
-
this.ackInfo = new AckInfoStore(this.db);
|
|
336
|
-
this.messageCreator = new MessageCreator(this);
|
|
337
|
-
this.patchCreator = new PatchCreator(() => this.now);
|
|
338
|
-
if (disableRebasing)
|
|
339
|
-
this.disableRebasing = disableRebasing;
|
|
340
|
-
}
|
|
341
|
-
get db() {
|
|
342
|
-
return this.context.metaDb;
|
|
343
|
-
}
|
|
344
|
-
get log() {
|
|
345
|
-
return this.context.log;
|
|
346
|
-
}
|
|
347
|
-
get now() {
|
|
348
|
-
return this.time.now(this.schema.currentVersion);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
273
|
+
${JSON.stringify(schema)}`);
|
|
274
|
+
throw new Error('Schema has changed without a version change! Any changes to your schema must be accompanied by a change in schema version and a migration routine.');
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
await this.schema.set(schema);
|
|
278
|
+
};
|
|
279
|
+
this.setGlobalAck = async (timestamp) => {
|
|
280
|
+
if (this._closing)
|
|
281
|
+
return;
|
|
282
|
+
await this.ackInfo.setGlobalAck(timestamp);
|
|
283
|
+
if (!this.disableRebasing) {
|
|
284
|
+
await this.runRebase(timestamp);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
this.export = async () => {
|
|
288
|
+
const db = this.db;
|
|
289
|
+
const [baselines, operations] = await getAllFromObjectStores(db, [
|
|
290
|
+
'baselines',
|
|
291
|
+
'operations',
|
|
292
|
+
]);
|
|
293
|
+
const localReplica = await this.localReplica.get();
|
|
294
|
+
const schema = await this.schema.get();
|
|
295
|
+
if (!schema) {
|
|
296
|
+
throw new Error('Cannot export Client data before initializing');
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
operations,
|
|
300
|
+
baselines,
|
|
301
|
+
localReplica,
|
|
302
|
+
schema,
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Resets local metadata and clears operation/baseline stores.
|
|
307
|
+
* DOES NOT add operations/baselines - this should be done
|
|
308
|
+
* through the normal higher level systems.
|
|
309
|
+
*/
|
|
310
|
+
this.resetFrom = async (data) => {
|
|
311
|
+
const db = this.db;
|
|
312
|
+
const transaction = db.transaction(['baselines', 'operations', 'info'], 'readwrite');
|
|
313
|
+
await storeRequestPromise(transaction.objectStore('baselines').clear());
|
|
314
|
+
await storeRequestPromise(transaction.objectStore('operations').clear());
|
|
315
|
+
await storeRequestPromise(transaction.objectStore('info').clear());
|
|
316
|
+
await this.localReplica.update({
|
|
317
|
+
ackedLogicalTime: data.localReplica.ackedLogicalTime,
|
|
318
|
+
lastSyncedLogicalTime: data.localReplica.lastSyncedLogicalTime,
|
|
319
|
+
}, { transaction });
|
|
320
|
+
};
|
|
321
|
+
this.stats = async () => {
|
|
322
|
+
const db = this.db;
|
|
323
|
+
const operationsSize = await getSizeOfObjectStore(db, 'operations');
|
|
324
|
+
const baselinesSize = await getSizeOfObjectStore(db, 'baselines');
|
|
325
|
+
return {
|
|
326
|
+
operationsSize,
|
|
327
|
+
baselinesSize,
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
this.context = context;
|
|
331
|
+
this.schema = new SchemaStore(context.metaDb, context.schema.version);
|
|
332
|
+
this.operations = new OperationsStore(this.db);
|
|
333
|
+
this.baselines = new BaselinesStore(this.db);
|
|
334
|
+
this.localReplica = new LocalReplicaStore(this.db);
|
|
335
|
+
this.ackInfo = new AckInfoStore(this.db);
|
|
336
|
+
this.messageCreator = new MessageCreator(this);
|
|
337
|
+
this.patchCreator = new PatchCreator(() => this.now);
|
|
338
|
+
if (disableRebasing)
|
|
339
|
+
this.disableRebasing = disableRebasing;
|
|
340
|
+
}
|
|
341
|
+
get db() {
|
|
342
|
+
return this.context.metaDb;
|
|
343
|
+
}
|
|
344
|
+
get log() {
|
|
345
|
+
return this.context.log;
|
|
346
|
+
}
|
|
347
|
+
get now() {
|
|
348
|
+
return this.time.now(this.schema.currentVersion);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
351
|
//# sourceMappingURL=Metadata.js.map
|