@tldraw/sync-core 5.3.0-next.2fa9c61a8de6 → 5.3.0-next.6c821af8959b
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-cjs/index.d.ts +8 -0
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/InMemorySyncStorage.js +11 -0
- package/dist-cjs/lib/InMemorySyncStorage.js.map +2 -2
- package/dist-cjs/lib/SQLiteSyncStorage.js +15 -0
- package/dist-cjs/lib/SQLiteSyncStorage.js.map +2 -2
- package/dist-cjs/lib/TLSyncRoom.js +7 -7
- package/dist-cjs/lib/TLSyncRoom.js.map +2 -2
- package/dist-cjs/lib/TLSyncStorage.js.map +2 -2
- package/dist-esm/index.d.mts +8 -0
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/InMemorySyncStorage.mjs +11 -0
- package/dist-esm/lib/InMemorySyncStorage.mjs.map +2 -2
- package/dist-esm/lib/SQLiteSyncStorage.mjs +15 -0
- package/dist-esm/lib/SQLiteSyncStorage.mjs.map +2 -2
- package/dist-esm/lib/TLSyncRoom.mjs +7 -7
- package/dist-esm/lib/TLSyncRoom.mjs.map +2 -2
- package/dist-esm/lib/TLSyncStorage.mjs.map +2 -2
- package/package.json +6 -6
- package/src/lib/InMemorySyncStorage.ts +12 -0
- package/src/lib/SQLiteSyncStorage.ts +16 -0
- package/src/lib/TLSyncRoom.ts +17 -8
- package/src/lib/TLSyncStorage.ts +7 -0
- package/src/test/storageContractSuite.ts +22 -0
package/src/lib/TLSyncStorage.ts
CHANGED
|
@@ -92,6 +92,13 @@ export interface TLSyncStorage<R extends UnknownRecord> {
|
|
|
92
92
|
* `RoomSnapshot['documents']` so a lane can be persisted and re-seeded via a merged snapshot.
|
|
93
93
|
*/
|
|
94
94
|
getObjectsSnapshot?(): RoomSnapshot['documents']
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The same entries for the given ids, for callers that need a handful of records rather than the
|
|
98
|
+
* whole (parsed) lane. Ids with no object-lane record are omitted — document-lane ids included —
|
|
99
|
+
* and duplicates yield one entry.
|
|
100
|
+
*/
|
|
101
|
+
getObjectsByIds?(ids: Iterable<string>): RoomSnapshot['documents']
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
/**
|
|
@@ -128,6 +128,28 @@ export function registerStorageContractTests(factory: StorageContractFactory) {
|
|
|
128
128
|
})
|
|
129
129
|
})
|
|
130
130
|
|
|
131
|
+
it('returns targeted object-lane entries by id from getObjectsByIds', () => {
|
|
132
|
+
const storage = createPartitioned(makeContractSnapshot(contractRecords))
|
|
133
|
+
const newPage = makePage('lane')
|
|
134
|
+
storage.transaction((txn) => txn.set(newPage.id, newPage))
|
|
135
|
+
|
|
136
|
+
const pageId = contractRecords[1].id
|
|
137
|
+
const entries = storage.getObjectsByIds!([newPage.id, pageId])
|
|
138
|
+
expect(entries.map((d) => d.state.id).sort()).toEqual([newPage.id, pageId].sort())
|
|
139
|
+
// same entry shape as getObjectsSnapshot: state + lastChangedClock
|
|
140
|
+
const laneEntry = entries.find((d) => d.state.id === newPage.id)!
|
|
141
|
+
expect(laneEntry.state).toEqual(newPage)
|
|
142
|
+
expect(laneEntry.lastChangedClock).toBe(storage.getClock())
|
|
143
|
+
|
|
144
|
+
// unknown ids and document-lane ids are omitted; duplicates yield one entry
|
|
145
|
+
expect(storage.getObjectsByIds!(['page:nope', TLDOCUMENT_ID])).toEqual([])
|
|
146
|
+
expect(storage.getObjectsByIds!([newPage.id, newPage.id]).length).toBe(1)
|
|
147
|
+
|
|
148
|
+
// a deleted record stops being returned
|
|
149
|
+
storage.transaction((txn) => txn.delete(newPage.id))
|
|
150
|
+
expect(storage.getObjectsByIds!([newPage.id])).toEqual([])
|
|
151
|
+
})
|
|
152
|
+
|
|
131
153
|
it('round-trips through a merged snapshot (persist lanes separately, re-seed together)', () => {
|
|
132
154
|
const storage = createPartitioned(makeContractSnapshot(contractRecords))
|
|
133
155
|
const merged = {
|