@tanstack/electron-db-sqlite-persistence 0.1.33 → 0.2.1
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/README.md +72 -0
- package/dist/cjs/electron-coordinator.cjs +5 -534
- package/dist/cjs/electron-coordinator.cjs.map +1 -1
- package/dist/cjs/electron-coordinator.d.cts +3 -65
- package/dist/cjs/index.cjs +16 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/main.cjs +13 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/protocol.cjs +1 -1
- package/dist/cjs/protocol.cjs.map +1 -1
- package/dist/cjs/protocol.d.cts +25 -3
- package/dist/cjs/renderer.cjs +24 -8
- package/dist/cjs/renderer.cjs.map +1 -1
- package/dist/esm/electron-coordinator.d.ts +3 -65
- package/dist/esm/electron-coordinator.js +5 -534
- package/dist/esm/electron-coordinator.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +5 -1
- package/dist/esm/main.js +13 -0
- package/dist/esm/main.js.map +1 -1
- package/dist/esm/protocol.d.ts +25 -3
- package/dist/esm/protocol.js +1 -1
- package/dist/esm/protocol.js.map +1 -1
- package/dist/esm/renderer.js +24 -8
- package/dist/esm/renderer.js.map +1 -1
- package/package.json +2 -2
- package/src/electron-coordinator.ts +10 -834
- package/src/index.ts +12 -1
- package/src/main.ts +14 -0
- package/src/protocol.ts +22 -1
- package/src/renderer.ts +33 -14
package/src/index.ts
CHANGED
|
@@ -10,8 +10,19 @@ export type {
|
|
|
10
10
|
} from './renderer'
|
|
11
11
|
export { ElectronCollectionCoordinator } from './electron-coordinator'
|
|
12
12
|
export type { ElectronCollectionCoordinatorOptions } from './electron-coordinator'
|
|
13
|
-
export {
|
|
13
|
+
export {
|
|
14
|
+
DuplicateRemoteSubsetOwnerError,
|
|
15
|
+
IndeterminateCommitError,
|
|
16
|
+
PersistedCollectionDurabilityError,
|
|
17
|
+
RemoteSubsetWireValueError,
|
|
18
|
+
persistedCollectionOptions,
|
|
19
|
+
} from '@tanstack/db-sqlite-persistence-core'
|
|
14
20
|
export type {
|
|
15
21
|
PersistedCollectionCoordinator,
|
|
16
22
|
PersistedCollectionPersistence,
|
|
23
|
+
IndeterminateCommitRequestType,
|
|
24
|
+
RemoteSubsetOwner,
|
|
25
|
+
RemoteSubsetWireExpression,
|
|
26
|
+
RemoteSubsetWireValue,
|
|
27
|
+
TransportedLoadSubsetOptions,
|
|
17
28
|
} from '@tanstack/db-sqlite-persistence-core'
|
package/src/main.ts
CHANGED
|
@@ -120,6 +120,20 @@ async function executeRequestAgainstAdapter(
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
case `loadResumeSnapshot`: {
|
|
124
|
+
const result = await adapter.loadResumeSnapshot(
|
|
125
|
+
request.collectionId,
|
|
126
|
+
request.payload.ctx,
|
|
127
|
+
)
|
|
128
|
+
return {
|
|
129
|
+
v: ELECTRON_PERSISTENCE_PROTOCOL_VERSION,
|
|
130
|
+
requestId: request.requestId,
|
|
131
|
+
method: request.method,
|
|
132
|
+
ok: true,
|
|
133
|
+
result,
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
123
137
|
case `loadCollectionMetadata`: {
|
|
124
138
|
if (!adapter.loadCollectionMetadata) {
|
|
125
139
|
throw new InvalidPersistedCollectionConfigError(
|
package/src/protocol.ts
CHANGED
|
@@ -2,11 +2,12 @@ import type { LoadSubsetOptions } from '@tanstack/db'
|
|
|
2
2
|
import type {
|
|
3
3
|
PersistedCollectionMode,
|
|
4
4
|
PersistedIndexSpec,
|
|
5
|
+
PersistedKeySetEvidence,
|
|
5
6
|
PersistedTx,
|
|
6
7
|
SQLitePullSinceResult,
|
|
7
8
|
} from '@tanstack/db-sqlite-persistence-core'
|
|
8
9
|
|
|
9
|
-
export const ELECTRON_PERSISTENCE_PROTOCOL_VERSION =
|
|
10
|
+
export const ELECTRON_PERSISTENCE_PROTOCOL_VERSION = 2 as const
|
|
10
11
|
export const DEFAULT_ELECTRON_PERSISTENCE_CHANNEL = `tanstack-db:sqlite-persistence`
|
|
11
12
|
|
|
12
13
|
export type ElectronPersistedRow = Record<string, unknown>
|
|
@@ -19,6 +20,7 @@ export type ElectronPersistenceResolution = {
|
|
|
19
20
|
|
|
20
21
|
export type ElectronPersistenceMethod =
|
|
21
22
|
| `loadSubset`
|
|
23
|
+
| `loadResumeSnapshot`
|
|
22
24
|
| `loadCollectionMetadata`
|
|
23
25
|
| `scanRows`
|
|
24
26
|
| `applyCommittedTx`
|
|
@@ -32,6 +34,12 @@ export type ElectronPersistencePayloadMap = {
|
|
|
32
34
|
options: LoadSubsetOptions
|
|
33
35
|
ctx?: { requiredIndexSignatures?: ReadonlyArray<string> }
|
|
34
36
|
}
|
|
37
|
+
loadResumeSnapshot: {
|
|
38
|
+
ctx?: {
|
|
39
|
+
requiredIndexSignatures?: ReadonlyArray<string>
|
|
40
|
+
includeRows?: boolean
|
|
41
|
+
}
|
|
42
|
+
}
|
|
35
43
|
loadCollectionMetadata: {}
|
|
36
44
|
scanRows: {
|
|
37
45
|
options?: {
|
|
@@ -56,6 +64,19 @@ export type ElectronPersistencePayloadMap = {
|
|
|
56
64
|
|
|
57
65
|
export type ElectronPersistenceResultMap = {
|
|
58
66
|
loadSubset: Array<{ key: ElectronPersistedKey; value: ElectronPersistedRow }>
|
|
67
|
+
loadResumeSnapshot: {
|
|
68
|
+
rows: Array<{
|
|
69
|
+
key: ElectronPersistedKey
|
|
70
|
+
value: ElectronPersistedRow
|
|
71
|
+
metadata?: unknown
|
|
72
|
+
}>
|
|
73
|
+
keySet?: PersistedKeySetEvidence
|
|
74
|
+
collectionMetadata: Array<{ key: string; value: unknown }>
|
|
75
|
+
latestTerm: number
|
|
76
|
+
latestSeq: number
|
|
77
|
+
latestRowVersion: number
|
|
78
|
+
resetEpoch: number
|
|
79
|
+
}
|
|
59
80
|
loadCollectionMetadata: Array<{ key: string; value: unknown }>
|
|
60
81
|
scanRows: Array<{
|
|
61
82
|
key: ElectronPersistedKey
|
package/src/renderer.ts
CHANGED
|
@@ -200,6 +200,20 @@ function createResolvedRendererAdapter(
|
|
|
200
200
|
value: Record<string, unknown>
|
|
201
201
|
}>
|
|
202
202
|
},
|
|
203
|
+
loadResumeSnapshot: async (
|
|
204
|
+
collectionId: string,
|
|
205
|
+
ctx?: {
|
|
206
|
+
requiredIndexSignatures?: ReadonlyArray<string>
|
|
207
|
+
includeRows?: boolean
|
|
208
|
+
},
|
|
209
|
+
) => {
|
|
210
|
+
return executeRequest(
|
|
211
|
+
`loadResumeSnapshot`,
|
|
212
|
+
collectionId,
|
|
213
|
+
{ ctx },
|
|
214
|
+
resolution,
|
|
215
|
+
)
|
|
216
|
+
},
|
|
203
217
|
applyCommittedTx: async (
|
|
204
218
|
collectionId: string,
|
|
205
219
|
tx: PersistedTx<Record<string, unknown>, string | number>,
|
|
@@ -359,35 +373,40 @@ export function createElectronSQLitePersistence(
|
|
|
359
373
|
schemaVersion,
|
|
360
374
|
})
|
|
361
375
|
adapterCache.set(cacheKey, adapter)
|
|
362
|
-
|
|
363
|
-
// Wire the adapter into the coordinator so it can handle
|
|
364
|
-
// leader-side RPCs (applyCommittedTx, pullSince, getStreamPosition, etc.)
|
|
365
|
-
if (coordinator instanceof ElectronCollectionCoordinator) {
|
|
366
|
-
coordinator.setAdapter(adapter)
|
|
367
|
-
}
|
|
368
|
-
|
|
369
376
|
return adapter
|
|
370
377
|
}
|
|
371
378
|
|
|
372
379
|
const createCollectionPersistence = (
|
|
380
|
+
collectionId: string | undefined,
|
|
373
381
|
mode: PersistedCollectionMode,
|
|
374
382
|
schemaVersion: number | undefined,
|
|
375
|
-
): PersistedCollectionPersistence =>
|
|
376
|
-
adapter
|
|
377
|
-
coordinator
|
|
378
|
-
|
|
383
|
+
): PersistedCollectionPersistence => {
|
|
384
|
+
const adapter = getAdapterForCollection(mode, schemaVersion)
|
|
385
|
+
if (coordinator instanceof ElectronCollectionCoordinator) {
|
|
386
|
+
if (collectionId === undefined) {
|
|
387
|
+
coordinator.setAdapter(adapter)
|
|
388
|
+
} else {
|
|
389
|
+
coordinator.setAdapterForCollection(collectionId, adapter)
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return { adapter, coordinator }
|
|
393
|
+
}
|
|
379
394
|
|
|
380
395
|
const defaultPersistence = createCollectionPersistence(
|
|
396
|
+
undefined,
|
|
381
397
|
`sync-absent`,
|
|
382
398
|
undefined,
|
|
383
399
|
)
|
|
400
|
+
if (coordinator instanceof ElectronCollectionCoordinator) {
|
|
401
|
+
coordinator.setAdapter(defaultPersistence.adapter)
|
|
402
|
+
}
|
|
384
403
|
|
|
385
404
|
return {
|
|
386
405
|
...defaultPersistence,
|
|
387
|
-
resolvePersistenceForCollection: ({ mode, schemaVersion }) =>
|
|
388
|
-
createCollectionPersistence(mode, schemaVersion),
|
|
406
|
+
resolvePersistenceForCollection: ({ collectionId, mode, schemaVersion }) =>
|
|
407
|
+
createCollectionPersistence(collectionId, mode, schemaVersion),
|
|
389
408
|
// Backward compatible fallback for older callers.
|
|
390
409
|
resolvePersistenceForMode: (mode) =>
|
|
391
|
-
createCollectionPersistence(mode, undefined),
|
|
410
|
+
createCollectionPersistence(undefined, mode, undefined),
|
|
392
411
|
}
|
|
393
412
|
}
|