@quereus/plugin-sync 0.3.1 → 0.3.3
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 +2 -1
- package/package.json +4 -4
- package/dist/src/clock/hlc.d.ts +0 -105
- package/dist/src/clock/hlc.d.ts.map +0 -1
- package/dist/src/clock/hlc.js +0 -251
- package/dist/src/clock/hlc.js.map +0 -1
- package/dist/src/clock/index.d.ts +0 -6
- package/dist/src/clock/index.d.ts.map +0 -1
- package/dist/src/clock/index.js +0 -6
- package/dist/src/clock/index.js.map +0 -1
- package/dist/src/clock/site.d.ts +0 -58
- package/dist/src/clock/site.d.ts.map +0 -1
- package/dist/src/clock/site.js +0 -137
- package/dist/src/clock/site.js.map +0 -1
- package/dist/src/create-sync-module.d.ts +0 -85
- package/dist/src/create-sync-module.d.ts.map +0 -1
- package/dist/src/create-sync-module.js +0 -54
- package/dist/src/create-sync-module.js.map +0 -1
- package/dist/src/index.d.ts +0 -31
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -42
- package/dist/src/index.js.map +0 -1
- package/dist/src/metadata/change-log.d.ts +0 -67
- package/dist/src/metadata/change-log.d.ts.map +0 -1
- package/dist/src/metadata/change-log.js +0 -107
- package/dist/src/metadata/change-log.js.map +0 -1
- package/dist/src/metadata/column-version.d.ts +0 -58
- package/dist/src/metadata/column-version.d.ts.map +0 -1
- package/dist/src/metadata/column-version.js +0 -100
- package/dist/src/metadata/column-version.js.map +0 -1
- package/dist/src/metadata/index.d.ts +0 -11
- package/dist/src/metadata/index.d.ts.map +0 -1
- package/dist/src/metadata/index.js +0 -11
- package/dist/src/metadata/index.js.map +0 -1
- package/dist/src/metadata/keys.d.ts +0 -180
- package/dist/src/metadata/keys.d.ts.map +0 -1
- package/dist/src/metadata/keys.js +0 -390
- package/dist/src/metadata/keys.js.map +0 -1
- package/dist/src/metadata/peer-state.d.ts +0 -52
- package/dist/src/metadata/peer-state.d.ts.map +0 -1
- package/dist/src/metadata/peer-state.js +0 -87
- package/dist/src/metadata/peer-state.js.map +0 -1
- package/dist/src/metadata/schema-migration.d.ts +0 -60
- package/dist/src/metadata/schema-migration.d.ts.map +0 -1
- package/dist/src/metadata/schema-migration.js +0 -126
- package/dist/src/metadata/schema-migration.js.map +0 -1
- package/dist/src/metadata/schema-version.d.ts +0 -163
- package/dist/src/metadata/schema-version.d.ts.map +0 -1
- package/dist/src/metadata/schema-version.js +0 -307
- package/dist/src/metadata/schema-version.js.map +0 -1
- package/dist/src/metadata/tombstones.d.ts +0 -67
- package/dist/src/metadata/tombstones.d.ts.map +0 -1
- package/dist/src/metadata/tombstones.js +0 -125
- package/dist/src/metadata/tombstones.js.map +0 -1
- package/dist/src/sync/events.d.ts +0 -117
- package/dist/src/sync/events.d.ts.map +0 -1
- package/dist/src/sync/events.js +0 -56
- package/dist/src/sync/events.js.map +0 -1
- package/dist/src/sync/index.d.ts +0 -8
- package/dist/src/sync/index.d.ts.map +0 -1
- package/dist/src/sync/index.js +0 -8
- package/dist/src/sync/index.js.map +0 -1
- package/dist/src/sync/manager.d.ts +0 -146
- package/dist/src/sync/manager.d.ts.map +0 -1
- package/dist/src/sync/manager.js +0 -8
- package/dist/src/sync/manager.js.map +0 -1
- package/dist/src/sync/protocol.d.ts +0 -282
- package/dist/src/sync/protocol.d.ts.map +0 -1
- package/dist/src/sync/protocol.js +0 -16
- package/dist/src/sync/protocol.js.map +0 -1
- package/dist/src/sync/store-adapter.d.ts +0 -42
- package/dist/src/sync/store-adapter.d.ts.map +0 -1
- package/dist/src/sync/store-adapter.js +0 -232
- package/dist/src/sync/store-adapter.js.map +0 -1
- package/dist/src/sync/sync-manager-impl.d.ts +0 -91
- package/dist/src/sync/sync-manager-impl.d.ts.map +0 -1
- package/dist/src/sync/sync-manager-impl.js +0 -1123
- package/dist/src/sync/sync-manager-impl.js.map +0 -1
package/dist/src/sync/events.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sync event types for reactive UI integration.
|
|
3
|
-
*
|
|
4
|
-
* These events allow applications to react to sync state changes,
|
|
5
|
-
* remote data updates, and conflict resolution.
|
|
6
|
-
*/
|
|
7
|
-
// ============================================================================
|
|
8
|
-
// Event Emitter Implementation
|
|
9
|
-
// ============================================================================
|
|
10
|
-
/**
|
|
11
|
-
* Default implementation of SyncEventEmitter.
|
|
12
|
-
*/
|
|
13
|
-
export class SyncEventEmitterImpl {
|
|
14
|
-
remoteChangeListeners = new Set();
|
|
15
|
-
localChangeListeners = new Set();
|
|
16
|
-
syncStateListeners = new Set();
|
|
17
|
-
conflictListeners = new Set();
|
|
18
|
-
onRemoteChange(listener) {
|
|
19
|
-
this.remoteChangeListeners.add(listener);
|
|
20
|
-
return () => this.remoteChangeListeners.delete(listener);
|
|
21
|
-
}
|
|
22
|
-
onLocalChange(listener) {
|
|
23
|
-
this.localChangeListeners.add(listener);
|
|
24
|
-
return () => this.localChangeListeners.delete(listener);
|
|
25
|
-
}
|
|
26
|
-
onSyncStateChange(listener) {
|
|
27
|
-
this.syncStateListeners.add(listener);
|
|
28
|
-
return () => this.syncStateListeners.delete(listener);
|
|
29
|
-
}
|
|
30
|
-
onConflictResolved(listener) {
|
|
31
|
-
this.conflictListeners.add(listener);
|
|
32
|
-
return () => this.conflictListeners.delete(listener);
|
|
33
|
-
}
|
|
34
|
-
// Internal emit methods
|
|
35
|
-
emitRemoteChange(event) {
|
|
36
|
-
for (const listener of this.remoteChangeListeners) {
|
|
37
|
-
listener(event);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
emitLocalChange(event) {
|
|
41
|
-
for (const listener of this.localChangeListeners) {
|
|
42
|
-
listener(event);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
emitSyncStateChange(state) {
|
|
46
|
-
for (const listener of this.syncStateListeners) {
|
|
47
|
-
listener(state);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
emitConflictResolved(event) {
|
|
51
|
-
for (const listener of this.conflictListeners) {
|
|
52
|
-
listener(event);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=events.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/sync/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyGH,+EAA+E;AAC/E,+BAA+B;AAC/B,+EAA+E;AAE/E;;GAEG;AACH,MAAM,OAAO,oBAAoB;IACvB,qBAAqB,GAAG,IAAI,GAAG,EAAsC,CAAC;IACtE,oBAAoB,GAAG,IAAI,GAAG,EAAqC,CAAC;IACpE,kBAAkB,GAAG,IAAI,GAAG,EAA8B,CAAC;IAC3D,iBAAiB,GAAG,IAAI,GAAG,EAAkC,CAAC;IAEtE,cAAc,CAAC,QAA4C;QACzD,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC3D,CAAC;IAED,aAAa,CAAC,QAA2C;QACvD,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACxC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC;IAED,iBAAiB,CAAC,QAAoC;QACpD,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACtC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC;IAED,kBAAkB,CAAC,QAAwC;QACzD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACrC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACvD,CAAC;IAED,wBAAwB;IAExB,gBAAgB,CAAC,KAAwB;QACvC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAClD,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,eAAe,CAAC,KAAuB;QACrC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACjD,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,KAAgB;QAClC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC/C,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,oBAAoB,CAAC,KAAoB;QACvC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC9C,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CACF"}
|
package/dist/src/sync/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sync/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC"}
|
package/dist/src/sync/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sync/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC"}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SyncManager - main API for sync operations.
|
|
3
|
-
*
|
|
4
|
-
* This interface defines the transport-agnostic sync API.
|
|
5
|
-
* Applications implement their own transport layer and call these methods.
|
|
6
|
-
*/
|
|
7
|
-
import type { HLC } from '../clock/hlc.js';
|
|
8
|
-
import type { SiteId } from '../clock/site.js';
|
|
9
|
-
import type { ApplyResult, ChangeSet, Snapshot, SnapshotChunk, SnapshotProgress } from './protocol.js';
|
|
10
|
-
/**
|
|
11
|
-
* Main sync manager interface.
|
|
12
|
-
*
|
|
13
|
-
* This is the primary API for sync operations. Applications use this to:
|
|
14
|
-
* - Get changes to send to peers
|
|
15
|
-
* - Apply changes received from peers
|
|
16
|
-
* - Manage sync state
|
|
17
|
-
*/
|
|
18
|
-
export interface SyncManager {
|
|
19
|
-
/**
|
|
20
|
-
* Get this replica's site ID.
|
|
21
|
-
*/
|
|
22
|
-
getSiteId(): SiteId;
|
|
23
|
-
/**
|
|
24
|
-
* Get current HLC for state comparison.
|
|
25
|
-
*/
|
|
26
|
-
getCurrentHLC(): HLC;
|
|
27
|
-
/**
|
|
28
|
-
* Get all changes since a peer's last known state.
|
|
29
|
-
*
|
|
30
|
-
* @param peerSiteId - The peer requesting changes
|
|
31
|
-
* @param sinceHLC - The peer's last known HLC (omit for full sync)
|
|
32
|
-
* @returns Array of change sets to send to the peer
|
|
33
|
-
*/
|
|
34
|
-
getChangesSince(peerSiteId: SiteId, sinceHLC?: HLC): Promise<ChangeSet[]>;
|
|
35
|
-
/**
|
|
36
|
-
* Apply changes received from a peer.
|
|
37
|
-
*
|
|
38
|
-
* Changes are applied atomically per transaction.
|
|
39
|
-
* Conflicts are resolved using column-level LWW.
|
|
40
|
-
*
|
|
41
|
-
* @param changes - Change sets received from a peer
|
|
42
|
-
* @returns Statistics about what was applied
|
|
43
|
-
*/
|
|
44
|
-
applyChanges(changes: ChangeSet[]): Promise<ApplyResult>;
|
|
45
|
-
/**
|
|
46
|
-
* Check if delta sync is possible with a peer.
|
|
47
|
-
*
|
|
48
|
-
* Returns false if:
|
|
49
|
-
* - Tombstone TTL has expired for relevant data
|
|
50
|
-
* - Peer's last sync is too old
|
|
51
|
-
* - Full snapshot is required
|
|
52
|
-
*
|
|
53
|
-
* @param peerSiteId - The peer to check
|
|
54
|
-
* @param sinceHLC - The peer's last known HLC
|
|
55
|
-
*/
|
|
56
|
-
canDeltaSync(peerSiteId: SiteId, sinceHLC: HLC): Promise<boolean>;
|
|
57
|
-
/**
|
|
58
|
-
* Get a full snapshot for initial sync or TTL expiration recovery.
|
|
59
|
-
*
|
|
60
|
-
* This includes all current data and schema state.
|
|
61
|
-
*/
|
|
62
|
-
getSnapshot(): Promise<Snapshot>;
|
|
63
|
-
/**
|
|
64
|
-
* Apply a full snapshot (replaces all local data).
|
|
65
|
-
*
|
|
66
|
-
* Used for initial sync or when delta sync is not possible.
|
|
67
|
-
*
|
|
68
|
-
* @param snapshot - Full snapshot from a peer
|
|
69
|
-
*/
|
|
70
|
-
applySnapshot(snapshot: Snapshot): Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* Update the last sync state for a peer.
|
|
73
|
-
*
|
|
74
|
-
* Called after successfully syncing with a peer.
|
|
75
|
-
*
|
|
76
|
-
* @param peerSiteId - The peer we synced with
|
|
77
|
-
* @param hlc - The HLC we synced up to
|
|
78
|
-
*/
|
|
79
|
-
updatePeerSyncState(peerSiteId: SiteId, hlc: HLC): Promise<void>;
|
|
80
|
-
/**
|
|
81
|
-
* Get the last sync state for a peer.
|
|
82
|
-
*
|
|
83
|
-
* @param peerSiteId - The peer to check
|
|
84
|
-
* @returns The last HLC we synced to, or undefined if never synced
|
|
85
|
-
*/
|
|
86
|
-
getPeerSyncState(peerSiteId: SiteId): Promise<HLC | undefined>;
|
|
87
|
-
/**
|
|
88
|
-
* Prune expired tombstones.
|
|
89
|
-
*
|
|
90
|
-
* Should be called periodically to clean up old tombstones.
|
|
91
|
-
* Returns the number of tombstones pruned.
|
|
92
|
-
*/
|
|
93
|
-
pruneTombstones(): Promise<number>;
|
|
94
|
-
/**
|
|
95
|
-
* Stream a snapshot as chunks for memory-efficient transfer.
|
|
96
|
-
*
|
|
97
|
-
* Use this instead of getSnapshot() for large databases.
|
|
98
|
-
* Chunks are yielded in order and can be sent over any streaming transport.
|
|
99
|
-
*
|
|
100
|
-
* @param chunkSize - Max column version entries per chunk (default: 1000)
|
|
101
|
-
*/
|
|
102
|
-
getSnapshotStream(chunkSize?: number): AsyncIterable<SnapshotChunk>;
|
|
103
|
-
/**
|
|
104
|
-
* Apply a streamed snapshot.
|
|
105
|
-
*
|
|
106
|
-
* Processes chunks as they arrive, minimizing memory usage.
|
|
107
|
-
* Supports resumption via checkpoint tracking.
|
|
108
|
-
*
|
|
109
|
-
* @param chunks - Async iterable of snapshot chunks
|
|
110
|
-
* @param onProgress - Optional progress callback
|
|
111
|
-
*/
|
|
112
|
-
applySnapshotStream(chunks: AsyncIterable<SnapshotChunk>, onProgress?: (progress: SnapshotProgress) => void): Promise<void>;
|
|
113
|
-
/**
|
|
114
|
-
* Get a resumable checkpoint for an in-progress snapshot.
|
|
115
|
-
*
|
|
116
|
-
* Used to resume an interrupted snapshot transfer.
|
|
117
|
-
*
|
|
118
|
-
* @param snapshotId - The snapshot ID to get checkpoint for
|
|
119
|
-
*/
|
|
120
|
-
getSnapshotCheckpoint(snapshotId: string): Promise<SnapshotCheckpoint | undefined>;
|
|
121
|
-
/**
|
|
122
|
-
* Resume a snapshot transfer from a checkpoint.
|
|
123
|
-
*
|
|
124
|
-
* @param checkpoint - Previously saved checkpoint
|
|
125
|
-
*/
|
|
126
|
-
resumeSnapshotStream(checkpoint: SnapshotCheckpoint): AsyncIterable<SnapshotChunk>;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Checkpoint for resumable snapshot transfers.
|
|
130
|
-
*/
|
|
131
|
-
export interface SnapshotCheckpoint {
|
|
132
|
-
readonly snapshotId: string;
|
|
133
|
-
readonly siteId: SiteId;
|
|
134
|
-
readonly hlc: HLC;
|
|
135
|
-
/** Last completed table index. */
|
|
136
|
-
readonly lastTableIndex: number;
|
|
137
|
-
/** Last completed entry within current table. */
|
|
138
|
-
readonly lastEntryIndex: number;
|
|
139
|
-
/** Tables completed so far. */
|
|
140
|
-
readonly completedTables: string[];
|
|
141
|
-
/** Total entries processed. */
|
|
142
|
-
readonly entriesProcessed: number;
|
|
143
|
-
/** Timestamp when checkpoint was created. */
|
|
144
|
-
readonly createdAt: number;
|
|
145
|
-
}
|
|
146
|
-
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/sync/manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEvG;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,SAAS,IAAI,MAAM,CAAC;IAEpB;;OAEG;IACH,aAAa,IAAI,GAAG,CAAC;IAErB;;;;;;OAMG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAE1E;;;;;;;;OAQG;IACH,YAAY,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAEzD;;;;;;;;;;OAUG;IACH,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAElE;;;;OAIG;IACH,WAAW,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEjC;;;;;;OAMG;IACH,aAAa,CAAC,QAAQ,EAAE,QAA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;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B"}
|
package/dist/src/sync/manager.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/sync/manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sync protocol types - transport-agnostic data structures.
|
|
3
|
-
*
|
|
4
|
-
* These types define the sync protocol without assuming any transport layer.
|
|
5
|
-
* Applications can serialize these to JSON, MessagePack, protobuf, etc.
|
|
6
|
-
* and send via WebSocket, HTTP, WebRTC, or any other transport.
|
|
7
|
-
*/
|
|
8
|
-
import type { Row, SqlValue } from '@quereus/quereus';
|
|
9
|
-
import type { HLC } from '../clock/hlc.js';
|
|
10
|
-
import type { SiteId } from '../clock/site.js';
|
|
11
|
-
/**
|
|
12
|
-
* A single column modification within a row.
|
|
13
|
-
*/
|
|
14
|
-
export interface ColumnChange {
|
|
15
|
-
readonly type: 'column';
|
|
16
|
-
readonly schema: string;
|
|
17
|
-
readonly table: string;
|
|
18
|
-
readonly pk: SqlValue[];
|
|
19
|
-
readonly column: string;
|
|
20
|
-
readonly value: SqlValue;
|
|
21
|
-
readonly hlc: HLC;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* A row deletion.
|
|
25
|
-
*/
|
|
26
|
-
export interface RowDeletion {
|
|
27
|
-
readonly type: 'delete';
|
|
28
|
-
readonly schema: string;
|
|
29
|
-
readonly table: string;
|
|
30
|
-
readonly pk: SqlValue[];
|
|
31
|
-
readonly hlc: HLC;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Union type for all change kinds.
|
|
35
|
-
*/
|
|
36
|
-
export type Change = ColumnChange | RowDeletion;
|
|
37
|
-
/**
|
|
38
|
-
* Types of schema migrations.
|
|
39
|
-
*/
|
|
40
|
-
export type SchemaMigrationType = 'create_table' | 'drop_table' | 'add_column' | 'drop_column' | 'add_index' | 'drop_index' | 'alter_column';
|
|
41
|
-
/**
|
|
42
|
-
* A schema migration record.
|
|
43
|
-
*/
|
|
44
|
-
export interface SchemaMigration {
|
|
45
|
-
readonly type: SchemaMigrationType;
|
|
46
|
-
readonly schema: string;
|
|
47
|
-
readonly table: string;
|
|
48
|
-
readonly ddl: string;
|
|
49
|
-
readonly hlc: HLC;
|
|
50
|
-
readonly schemaVersion: number;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* A transaction's worth of changes.
|
|
54
|
-
* All changes within a ChangeSet are applied atomically.
|
|
55
|
-
*/
|
|
56
|
-
export interface ChangeSet {
|
|
57
|
-
/** Origin replica */
|
|
58
|
-
readonly siteId: SiteId;
|
|
59
|
-
/** Unique transaction identifier */
|
|
60
|
-
readonly transactionId: string;
|
|
61
|
-
/** Transaction commit time */
|
|
62
|
-
readonly hlc: HLC;
|
|
63
|
-
/** Data changes in this transaction */
|
|
64
|
-
readonly changes: Change[];
|
|
65
|
-
/** Schema migrations in this transaction */
|
|
66
|
-
readonly schemaMigrations: SchemaMigration[];
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Result of applying changes from a peer.
|
|
70
|
-
*/
|
|
71
|
-
export interface ApplyResult {
|
|
72
|
-
/** Changes successfully applied (winner was remote) */
|
|
73
|
-
applied: number;
|
|
74
|
-
/** Changes skipped (already present or local won) */
|
|
75
|
-
skipped: number;
|
|
76
|
-
/** Conflicts resolved via LWW */
|
|
77
|
-
conflicts: number;
|
|
78
|
-
/** Number of transactions processed */
|
|
79
|
-
transactions: number;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Column version entry for snapshot.
|
|
83
|
-
*/
|
|
84
|
-
export interface ColumnVersionEntry {
|
|
85
|
-
readonly hlc: HLC;
|
|
86
|
-
readonly value: SqlValue;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Full snapshot of a table for initial sync or recovery.
|
|
90
|
-
*/
|
|
91
|
-
export interface TableSnapshot {
|
|
92
|
-
readonly schema: string;
|
|
93
|
-
readonly table: string;
|
|
94
|
-
readonly rows: Row[];
|
|
95
|
-
/** Column versions for each row, keyed by serialized PK + column name */
|
|
96
|
-
readonly columnVersions: Map<string, ColumnVersionEntry>;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Full database snapshot.
|
|
100
|
-
*/
|
|
101
|
-
export interface Snapshot {
|
|
102
|
-
readonly siteId: SiteId;
|
|
103
|
-
readonly hlc: HLC;
|
|
104
|
-
readonly tables: TableSnapshot[];
|
|
105
|
-
readonly schemaMigrations: SchemaMigration[];
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Snapshot chunk types for streaming.
|
|
109
|
-
*/
|
|
110
|
-
export type SnapshotChunkType = 'header' | 'table-start' | 'column-versions' | 'table-end' | 'schema-migration' | 'footer';
|
|
111
|
-
/**
|
|
112
|
-
* Header chunk - sent first with metadata.
|
|
113
|
-
*/
|
|
114
|
-
export interface SnapshotHeaderChunk {
|
|
115
|
-
readonly type: 'header';
|
|
116
|
-
readonly siteId: SiteId;
|
|
117
|
-
readonly hlc: HLC;
|
|
118
|
-
readonly tableCount: number;
|
|
119
|
-
readonly migrationCount: number;
|
|
120
|
-
/** Unique identifier for this snapshot transfer. */
|
|
121
|
-
readonly snapshotId: string;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Table start chunk - marks beginning of a table's data.
|
|
125
|
-
*/
|
|
126
|
-
export interface SnapshotTableStartChunk {
|
|
127
|
-
readonly type: 'table-start';
|
|
128
|
-
readonly schema: string;
|
|
129
|
-
readonly table: string;
|
|
130
|
-
/** Estimated number of column version entries for this table. */
|
|
131
|
-
readonly estimatedEntries: number;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Column versions chunk - batch of column version entries.
|
|
135
|
-
*/
|
|
136
|
-
export interface SnapshotColumnVersionsChunk {
|
|
137
|
-
readonly type: 'column-versions';
|
|
138
|
-
readonly schema: string;
|
|
139
|
-
readonly table: string;
|
|
140
|
-
/** Column versions as [versionKey, hlc, value] tuples. */
|
|
141
|
-
readonly entries: Array<[string, HLC, SqlValue]>;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Table end chunk - marks end of a table's data.
|
|
145
|
-
*/
|
|
146
|
-
export interface SnapshotTableEndChunk {
|
|
147
|
-
readonly type: 'table-end';
|
|
148
|
-
readonly schema: string;
|
|
149
|
-
readonly table: string;
|
|
150
|
-
readonly entriesWritten: number;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Schema migration chunk.
|
|
154
|
-
*/
|
|
155
|
-
export interface SnapshotSchemaMigrationChunk {
|
|
156
|
-
readonly type: 'schema-migration';
|
|
157
|
-
readonly migration: SchemaMigration;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Footer chunk - sent last with checksum/stats.
|
|
161
|
-
*/
|
|
162
|
-
export interface SnapshotFooterChunk {
|
|
163
|
-
readonly type: 'footer';
|
|
164
|
-
readonly snapshotId: string;
|
|
165
|
-
readonly totalTables: number;
|
|
166
|
-
readonly totalEntries: number;
|
|
167
|
-
readonly totalMigrations: number;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Union of all snapshot chunk types.
|
|
171
|
-
*/
|
|
172
|
-
export type SnapshotChunk = SnapshotHeaderChunk | SnapshotTableStartChunk | SnapshotColumnVersionsChunk | SnapshotTableEndChunk | SnapshotSchemaMigrationChunk | SnapshotFooterChunk;
|
|
173
|
-
/**
|
|
174
|
-
* Progress info during snapshot streaming.
|
|
175
|
-
*/
|
|
176
|
-
export interface SnapshotProgress {
|
|
177
|
-
readonly snapshotId: string;
|
|
178
|
-
readonly tablesProcessed: number;
|
|
179
|
-
readonly totalTables: number;
|
|
180
|
-
readonly entriesProcessed: number;
|
|
181
|
-
readonly totalEntries: number;
|
|
182
|
-
readonly currentTable?: string;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Options for applying changes to the store.
|
|
186
|
-
*/
|
|
187
|
-
export interface ApplyToStoreOptions {
|
|
188
|
-
/**
|
|
189
|
-
* Mark resulting events as remote (from sync).
|
|
190
|
-
* When true, the store should emit events with `remote: true`,
|
|
191
|
-
* preventing the SyncManager from re-recording CRDT metadata.
|
|
192
|
-
*/
|
|
193
|
-
readonly remote: boolean;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* A data change to apply to the store.
|
|
197
|
-
*/
|
|
198
|
-
export interface DataChangeToApply {
|
|
199
|
-
readonly type: 'insert' | 'update' | 'delete';
|
|
200
|
-
readonly schema: string;
|
|
201
|
-
readonly table: string;
|
|
202
|
-
readonly pk: SqlValue[];
|
|
203
|
-
/** Column values to apply. Keys are column names, values are column values. */
|
|
204
|
-
readonly columns?: Record<string, SqlValue>;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* A schema change to apply to the store.
|
|
208
|
-
*/
|
|
209
|
-
export interface SchemaChangeToApply {
|
|
210
|
-
readonly type: SchemaMigrationType;
|
|
211
|
-
readonly schema: string;
|
|
212
|
-
readonly table: string;
|
|
213
|
-
/** The DDL statement to execute. */
|
|
214
|
-
readonly ddl: string;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Result of applying changes to the store.
|
|
218
|
-
*/
|
|
219
|
-
export interface ApplyToStoreResult {
|
|
220
|
-
/** Number of data changes successfully applied. */
|
|
221
|
-
dataChangesApplied: number;
|
|
222
|
-
/** Number of schema changes successfully applied. */
|
|
223
|
-
schemaChangesApplied: number;
|
|
224
|
-
/** Errors encountered (empty if all succeeded). */
|
|
225
|
-
errors: Array<{
|
|
226
|
-
change: DataChangeToApply | SchemaChangeToApply;
|
|
227
|
-
error: Error;
|
|
228
|
-
}>;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Callback interface for applying remote changes to the store.
|
|
232
|
-
*
|
|
233
|
-
* The SyncManager uses this callback to apply changes from remote replicas.
|
|
234
|
-
* The implementation should:
|
|
235
|
-
* 1. Execute the changes against the actual data store
|
|
236
|
-
* 2. Emit events with `remote: true` when `options.remote` is true
|
|
237
|
-
*
|
|
238
|
-
* This allows the store plugin to handle the actual data manipulation
|
|
239
|
-
* while the sync module handles CRDT metadata.
|
|
240
|
-
*/
|
|
241
|
-
export type ApplyToStoreCallback = (dataChanges: DataChangeToApply[], schemaChanges: SchemaChangeToApply[], options: ApplyToStoreOptions) => Promise<ApplyToStoreResult>;
|
|
242
|
-
/**
|
|
243
|
-
* Tracks sync state with a specific peer.
|
|
244
|
-
*/
|
|
245
|
-
export interface PeerSyncState {
|
|
246
|
-
readonly peerSiteId: SiteId;
|
|
247
|
-
/** Last HLC we've synced up to with this peer */
|
|
248
|
-
readonly lastSyncHLC: HLC;
|
|
249
|
-
/** When we last successfully synced */
|
|
250
|
-
readonly lastSyncTime: number;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Sync module configuration.
|
|
254
|
-
*/
|
|
255
|
-
export interface SyncConfig {
|
|
256
|
-
/**
|
|
257
|
-
* Tombstone retention period in milliseconds.
|
|
258
|
-
* After this period, delta sync may not be possible.
|
|
259
|
-
* Default: 30 days (30 * 24 * 60 * 60 * 1000)
|
|
260
|
-
*/
|
|
261
|
-
tombstoneTTL: number;
|
|
262
|
-
/**
|
|
263
|
-
* Whether deleted rows can be resurrected by later writes.
|
|
264
|
-
* If false (default), a deletion prevents any column write with earlier HLC.
|
|
265
|
-
* If true, an insert/update with later HLC can resurrect a deleted row.
|
|
266
|
-
*/
|
|
267
|
-
allowResurrection: boolean;
|
|
268
|
-
/**
|
|
269
|
-
* Maximum number of changes to return in a single sync batch.
|
|
270
|
-
* Default: 1000
|
|
271
|
-
*/
|
|
272
|
-
batchSize: number;
|
|
273
|
-
/**
|
|
274
|
-
* Pre-configured site ID. If not provided, one will be generated.
|
|
275
|
-
*/
|
|
276
|
-
siteId?: SiteId;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Default sync configuration.
|
|
280
|
-
*/
|
|
281
|
-
export declare const DEFAULT_SYNC_CONFIG: SyncConfig;
|
|
282
|
-
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/sync/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAM/C;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,WAAW,CAAC;AAMhD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAC3B,cAAc,GACd,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,WAAW,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B;AAMD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,iBAAiB,EAAE,OAAO,CAAC;IAE3B;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,UAIjC,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sync protocol types - transport-agnostic data structures.
|
|
3
|
-
*
|
|
4
|
-
* These types define the sync protocol without assuming any transport layer.
|
|
5
|
-
* Applications can serialize these to JSON, MessagePack, protobuf, etc.
|
|
6
|
-
* and send via WebSocket, HTTP, WebRTC, or any other transport.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Default sync configuration.
|
|
10
|
-
*/
|
|
11
|
-
export const DEFAULT_SYNC_CONFIG = {
|
|
12
|
-
tombstoneTTL: 30 * 24 * 60 * 60 * 1000, // 30 days
|
|
13
|
-
allowResurrection: false,
|
|
14
|
-
batchSize: 1000,
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=protocol.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/sync/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkWH;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAe;IAC7C,YAAY,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAAG,UAAU;IACnD,iBAAiB,EAAE,KAAK;IACxB,SAAS,EAAE,IAAI;CAChB,CAAC"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Store adapter for applying remote sync changes.
|
|
3
|
-
*
|
|
4
|
-
* This module provides adapters that implement the ApplyToStoreCallback
|
|
5
|
-
* interface for LevelDB and IndexedDB stores, enabling the SyncManager
|
|
6
|
-
* to apply remote changes to the actual data store.
|
|
7
|
-
*/
|
|
8
|
-
import type { Database, TableSchema } from '@quereus/quereus';
|
|
9
|
-
import type { KVStore, StoreEventEmitter } from '@quereus/plugin-store';
|
|
10
|
-
import type { ApplyToStoreCallback } from './protocol.js';
|
|
11
|
-
/**
|
|
12
|
-
* Options for creating a SyncStoreAdapter.
|
|
13
|
-
*/
|
|
14
|
-
export interface SyncStoreAdapterOptions {
|
|
15
|
-
/** The Quereus database for executing DDL statements. */
|
|
16
|
-
db: Database;
|
|
17
|
-
/**
|
|
18
|
-
* Function to get the KV store for a specific table.
|
|
19
|
-
* Each table may have its own IndexedDB database, so we need to look up
|
|
20
|
-
* the correct store for each table when applying remote changes.
|
|
21
|
-
*/
|
|
22
|
-
getKVStore: (schemaName: string, tableName: string) => Promise<KVStore>;
|
|
23
|
-
/** The event emitter for data change events. */
|
|
24
|
-
events: StoreEventEmitter;
|
|
25
|
-
/** Function to get table schema by name. */
|
|
26
|
-
getTableSchema: (schemaName: string, tableName: string) => TableSchema | undefined;
|
|
27
|
-
/** Collation for text key encoding. */
|
|
28
|
-
collation?: 'BINARY' | 'NOCASE';
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Creates an ApplyToStoreCallback for applying remote sync changes.
|
|
32
|
-
*
|
|
33
|
-
* This adapter handles:
|
|
34
|
-
* - UPSERT semantics for column changes (insert if row doesn't exist, update if it does)
|
|
35
|
-
* - Row deletions by primary key
|
|
36
|
-
* - DDL execution for schema changes
|
|
37
|
-
*
|
|
38
|
-
* All data change events are emitted with `remote: true` to prevent
|
|
39
|
-
* the SyncManager from re-recording CRDT metadata.
|
|
40
|
-
*/
|
|
41
|
-
export declare function createStoreAdapter(options: SyncStoreAdapterOptions): ApplyToStoreCallback;
|
|
42
|
-
//# sourceMappingURL=store-adapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-adapter.d.ts","sourceRoot":"","sources":["../../../src/sync/store-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAiB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAExE,OAAO,KAAK,EACV,oBAAoB,EAKrB,MAAM,eAAe,CAAC;AAEvB;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,yDAAyD;IACzD,EAAE,EAAE,QAAQ,CAAC;IACb;;;;OAIG;IACH,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACxE,gDAAgD;IAChD,MAAM,EAAE,iBAAiB,CAAC;IAC1B,4CAA4C;IAC5C,cAAc,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAC;IACnF,uCAAuC;IACvC,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;CACjC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,uBAAuB,GAAG,oBAAoB,CAyDzF"}
|