@quereus/plugin-sync 0.3.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.
Files changed (78) hide show
  1. package/README.md +154 -0
  2. package/dist/src/clock/hlc.d.ts +105 -0
  3. package/dist/src/clock/hlc.d.ts.map +1 -0
  4. package/dist/src/clock/hlc.js +251 -0
  5. package/dist/src/clock/hlc.js.map +1 -0
  6. package/dist/src/clock/index.d.ts +6 -0
  7. package/dist/src/clock/index.d.ts.map +1 -0
  8. package/dist/src/clock/index.js +6 -0
  9. package/dist/src/clock/index.js.map +1 -0
  10. package/dist/src/clock/site.d.ts +58 -0
  11. package/dist/src/clock/site.d.ts.map +1 -0
  12. package/dist/src/clock/site.js +137 -0
  13. package/dist/src/clock/site.js.map +1 -0
  14. package/dist/src/create-sync-module.d.ts +85 -0
  15. package/dist/src/create-sync-module.d.ts.map +1 -0
  16. package/dist/src/create-sync-module.js +54 -0
  17. package/dist/src/create-sync-module.js.map +1 -0
  18. package/dist/src/index.d.ts +31 -0
  19. package/dist/src/index.d.ts.map +1 -0
  20. package/dist/src/index.js +42 -0
  21. package/dist/src/index.js.map +1 -0
  22. package/dist/src/metadata/change-log.d.ts +67 -0
  23. package/dist/src/metadata/change-log.d.ts.map +1 -0
  24. package/dist/src/metadata/change-log.js +107 -0
  25. package/dist/src/metadata/change-log.js.map +1 -0
  26. package/dist/src/metadata/column-version.d.ts +58 -0
  27. package/dist/src/metadata/column-version.d.ts.map +1 -0
  28. package/dist/src/metadata/column-version.js +100 -0
  29. package/dist/src/metadata/column-version.js.map +1 -0
  30. package/dist/src/metadata/index.d.ts +11 -0
  31. package/dist/src/metadata/index.d.ts.map +1 -0
  32. package/dist/src/metadata/index.js +11 -0
  33. package/dist/src/metadata/index.js.map +1 -0
  34. package/dist/src/metadata/keys.d.ts +180 -0
  35. package/dist/src/metadata/keys.d.ts.map +1 -0
  36. package/dist/src/metadata/keys.js +390 -0
  37. package/dist/src/metadata/keys.js.map +1 -0
  38. package/dist/src/metadata/peer-state.d.ts +52 -0
  39. package/dist/src/metadata/peer-state.d.ts.map +1 -0
  40. package/dist/src/metadata/peer-state.js +87 -0
  41. package/dist/src/metadata/peer-state.js.map +1 -0
  42. package/dist/src/metadata/schema-migration.d.ts +60 -0
  43. package/dist/src/metadata/schema-migration.d.ts.map +1 -0
  44. package/dist/src/metadata/schema-migration.js +126 -0
  45. package/dist/src/metadata/schema-migration.js.map +1 -0
  46. package/dist/src/metadata/schema-version.d.ts +163 -0
  47. package/dist/src/metadata/schema-version.d.ts.map +1 -0
  48. package/dist/src/metadata/schema-version.js +307 -0
  49. package/dist/src/metadata/schema-version.js.map +1 -0
  50. package/dist/src/metadata/tombstones.d.ts +67 -0
  51. package/dist/src/metadata/tombstones.d.ts.map +1 -0
  52. package/dist/src/metadata/tombstones.js +125 -0
  53. package/dist/src/metadata/tombstones.js.map +1 -0
  54. package/dist/src/sync/events.d.ts +117 -0
  55. package/dist/src/sync/events.d.ts.map +1 -0
  56. package/dist/src/sync/events.js +56 -0
  57. package/dist/src/sync/events.js.map +1 -0
  58. package/dist/src/sync/index.d.ts +8 -0
  59. package/dist/src/sync/index.d.ts.map +1 -0
  60. package/dist/src/sync/index.js +8 -0
  61. package/dist/src/sync/index.js.map +1 -0
  62. package/dist/src/sync/manager.d.ts +146 -0
  63. package/dist/src/sync/manager.d.ts.map +1 -0
  64. package/dist/src/sync/manager.js +8 -0
  65. package/dist/src/sync/manager.js.map +1 -0
  66. package/dist/src/sync/protocol.d.ts +282 -0
  67. package/dist/src/sync/protocol.d.ts.map +1 -0
  68. package/dist/src/sync/protocol.js +16 -0
  69. package/dist/src/sync/protocol.js.map +1 -0
  70. package/dist/src/sync/store-adapter.d.ts +42 -0
  71. package/dist/src/sync/store-adapter.d.ts.map +1 -0
  72. package/dist/src/sync/store-adapter.js +232 -0
  73. package/dist/src/sync/store-adapter.js.map +1 -0
  74. package/dist/src/sync/sync-manager-impl.d.ts +91 -0
  75. package/dist/src/sync/sync-manager-impl.d.ts.map +1 -0
  76. package/dist/src/sync/sync-manager-impl.js +1123 -0
  77. package/dist/src/sync/sync-manager-impl.js.map +1 -0
  78. package/package.json +64 -0
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Column version tracking for LWW conflict resolution.
3
+ *
4
+ * Each column of each row has an associated HLC timestamp.
5
+ * When merging changes, the column with the higher HLC wins.
6
+ */
7
+ import { serializeHLC, deserializeHLC, compareHLC } from '../clock/hlc.js';
8
+ import { buildColumnVersionKey, buildColumnVersionScanBounds } from './keys.js';
9
+ /**
10
+ * Serialize a column version for storage.
11
+ * Format: 26 bytes HLC + JSON value
12
+ */
13
+ export function serializeColumnVersion(cv) {
14
+ const hlcBytes = serializeHLC(cv.hlc);
15
+ const valueJson = JSON.stringify(cv.value);
16
+ const valueBytes = new TextEncoder().encode(valueJson);
17
+ const result = new Uint8Array(hlcBytes.length + valueBytes.length);
18
+ result.set(hlcBytes, 0);
19
+ result.set(valueBytes, hlcBytes.length);
20
+ return result;
21
+ }
22
+ /**
23
+ * Deserialize a column version from storage.
24
+ */
25
+ export function deserializeColumnVersion(buffer) {
26
+ const hlc = deserializeHLC(buffer.slice(0, 26));
27
+ const valueJson = new TextDecoder().decode(buffer.slice(26));
28
+ const value = JSON.parse(valueJson);
29
+ return { hlc, value };
30
+ }
31
+ /**
32
+ * Column version store operations.
33
+ */
34
+ export class ColumnVersionStore {
35
+ kv;
36
+ constructor(kv) {
37
+ this.kv = kv;
38
+ }
39
+ /**
40
+ * Get the version of a specific column.
41
+ */
42
+ async getColumnVersion(schemaName, tableName, pk, column) {
43
+ const key = buildColumnVersionKey(schemaName, tableName, pk, column);
44
+ const data = await this.kv.get(key);
45
+ if (!data)
46
+ return undefined;
47
+ return deserializeColumnVersion(data);
48
+ }
49
+ /**
50
+ * Set the version of a specific column.
51
+ */
52
+ async setColumnVersion(schemaName, tableName, pk, column, version) {
53
+ const key = buildColumnVersionKey(schemaName, tableName, pk, column);
54
+ await this.kv.put(key, serializeColumnVersion(version));
55
+ }
56
+ /**
57
+ * Set column version in a batch.
58
+ */
59
+ setColumnVersionBatch(batch, schemaName, tableName, pk, column, version) {
60
+ const key = buildColumnVersionKey(schemaName, tableName, pk, column);
61
+ batch.put(key, serializeColumnVersion(version));
62
+ }
63
+ /**
64
+ * Get all column versions for a row.
65
+ */
66
+ async getRowVersions(schemaName, tableName, pk) {
67
+ const bounds = buildColumnVersionScanBounds(schemaName, tableName, pk);
68
+ const versions = new Map();
69
+ for await (const entry of this.kv.iterate(bounds)) {
70
+ // Extract column name from key
71
+ const keyStr = new TextDecoder().decode(entry.key);
72
+ const lastColon = keyStr.lastIndexOf(':');
73
+ const column = keyStr.slice(lastColon + 1);
74
+ versions.set(column, deserializeColumnVersion(entry.value));
75
+ }
76
+ return versions;
77
+ }
78
+ /**
79
+ * Delete all column versions for a row.
80
+ */
81
+ async deleteRowVersions(schemaName, tableName, pk) {
82
+ const bounds = buildColumnVersionScanBounds(schemaName, tableName, pk);
83
+ const batch = this.kv.batch();
84
+ for await (const entry of this.kv.iterate(bounds)) {
85
+ batch.delete(entry.key);
86
+ }
87
+ await batch.write();
88
+ }
89
+ /**
90
+ * Check if a column write should be applied (LWW comparison).
91
+ * Returns true if the incoming HLC is newer than the current version.
92
+ */
93
+ async shouldApplyWrite(schemaName, tableName, pk, column, incomingHLC) {
94
+ const current = await this.getColumnVersion(schemaName, tableName, pk, column);
95
+ if (!current)
96
+ return true;
97
+ return compareHLC(incomingHLC, current.hlc) > 0;
98
+ }
99
+ }
100
+ //# sourceMappingURL=column-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column-version.js","sourceRoot":"","sources":["../../../src/metadata/column-version.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAY,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAC;AAU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AC,CAAC;YAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;YAE3C,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,wBAAwB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,iBAAiB,CACrB,UAAkB,EAClB,SAAiB,EACjB,EAAc;QAEd,MAAM,MAAM,GAAG,4BAA4B,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QACvE,MAAM,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;QAE9B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAClD,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;QAED,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,gBAAgB,CACpB,UAAkB,EAClB,SAAiB,EACjB,EAAc,EACd,MAAc,EACd,WAAgB;QAEhB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QAC/E,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAC1B,OAAO,UAAU,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Metadata module exports.
3
+ */
4
+ export * from './keys.js';
5
+ export * from './column-version.js';
6
+ export * from './tombstones.js';
7
+ export * from './peer-state.js';
8
+ export * from './schema-migration.js';
9
+ export * from './schema-version.js';
10
+ export * from './change-log.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/metadata/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Metadata module exports.
3
+ */
4
+ export * from './keys.js';
5
+ export * from './column-version.js';
6
+ export * from './tombstones.js';
7
+ export * from './peer-state.js';
8
+ export * from './schema-migration.js';
9
+ export * from './schema-version.js';
10
+ export * from './change-log.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/metadata/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Key builders for CRDT metadata storage.
3
+ *
4
+ * Key prefixes (sync-specific):
5
+ * cv: - Column versions (HLC per column per row)
6
+ * tb: - Tombstones (deleted row markers)
7
+ * tx: - Transaction records
8
+ * ps: - Peer sync state
9
+ * sm: - Schema migrations
10
+ * si: - Site identity
11
+ * hc: - HLC clock state
12
+ * cl: - Change log (HLC-indexed for efficient delta queries)
13
+ */
14
+ import type { SqlValue } from '@quereus/quereus';
15
+ import type { SiteId } from '../clock/site.js';
16
+ import type { HLC } from '../clock/hlc.js';
17
+ /** Key prefix bytes for sync metadata. */
18
+ export declare const SYNC_KEY_PREFIX: {
19
+ readonly COLUMN_VERSION: Uint8Array<ArrayBufferLike>;
20
+ readonly TOMBSTONE: Uint8Array<ArrayBufferLike>;
21
+ readonly TRANSACTION: Uint8Array<ArrayBufferLike>;
22
+ readonly PEER_STATE: Uint8Array<ArrayBufferLike>;
23
+ readonly SCHEMA_MIGRATION: Uint8Array<ArrayBufferLike>;
24
+ readonly SITE_IDENTITY: Uint8Array<ArrayBufferLike>;
25
+ readonly HLC_STATE: Uint8Array<ArrayBufferLike>;
26
+ readonly CHANGE_LOG: Uint8Array<ArrayBufferLike>;
27
+ };
28
+ /**
29
+ * Encode a primary key as a string for use in metadata keys.
30
+ * Uses JSON for simplicity and determinism.
31
+ */
32
+ export declare function encodePK(pk: SqlValue[]): string;
33
+ /**
34
+ * Decode a primary key from its string representation.
35
+ */
36
+ export declare function decodePK(encoded: string): SqlValue[];
37
+ /**
38
+ * Build a column version key.
39
+ * Format: cv:{schema}.{table}:{pk_json}:{column}
40
+ */
41
+ export declare function buildColumnVersionKey(schemaName: string, tableName: string, pk: SqlValue[], column: string): Uint8Array;
42
+ /**
43
+ * Build a tombstone key.
44
+ * Format: tb:{schema}.{table}:{pk_json}
45
+ */
46
+ export declare function buildTombstoneKey(schemaName: string, tableName: string, pk: SqlValue[]): Uint8Array;
47
+ /**
48
+ * Build a transaction record key.
49
+ * Format: tx:{transactionId}
50
+ */
51
+ export declare function buildTransactionKey(transactionId: string): Uint8Array;
52
+ /**
53
+ * Build a peer sync state key.
54
+ * Format: ps:{siteId_base64url}
55
+ */
56
+ export declare function buildPeerStateKey(siteId: SiteId): Uint8Array;
57
+ /**
58
+ * Build a schema migration key.
59
+ * Format: sm:{schema}.{table}:{version}
60
+ */
61
+ export declare function buildSchemaMigrationKey(schemaName: string, tableName: string, version: number): Uint8Array;
62
+ /**
63
+ * Build scan bounds for all column versions of a row.
64
+ * Returns keys to scan cv:{schema}.{table}:{pk_json}:*
65
+ */
66
+ export declare function buildColumnVersionScanBounds(schemaName: string, tableName: string, pk: SqlValue[]): {
67
+ gte: Uint8Array;
68
+ lt: Uint8Array;
69
+ };
70
+ /**
71
+ * Build scan bounds for all tombstones in a table.
72
+ */
73
+ export declare function buildTombstoneScanBounds(schemaName: string, tableName: string): {
74
+ gte: Uint8Array;
75
+ lt: Uint8Array;
76
+ };
77
+ /**
78
+ * Build scan bounds for all schema migrations of a table.
79
+ */
80
+ export declare function buildSchemaMigrationScanBounds(schemaName: string, tableName: string): {
81
+ gte: Uint8Array;
82
+ lt: Uint8Array;
83
+ };
84
+ /**
85
+ * Build scan bounds for ALL column versions across all tables.
86
+ */
87
+ export declare function buildAllColumnVersionsScanBounds(): {
88
+ gte: Uint8Array;
89
+ lt: Uint8Array;
90
+ };
91
+ /**
92
+ * Build scan bounds for ALL tombstones across all tables.
93
+ */
94
+ export declare function buildAllTombstonesScanBounds(): {
95
+ gte: Uint8Array;
96
+ lt: Uint8Array;
97
+ };
98
+ /**
99
+ * Build scan bounds for ALL schema migrations across all tables.
100
+ */
101
+ export declare function buildAllSchemaMigrationsScanBounds(): {
102
+ gte: Uint8Array;
103
+ lt: Uint8Array;
104
+ };
105
+ /**
106
+ * Parse a column version key to extract components.
107
+ * Key format: cv:{schema}.{table}:{pk_json}:{column}
108
+ */
109
+ export declare function parseColumnVersionKey(key: Uint8Array): {
110
+ schema: string;
111
+ table: string;
112
+ pk: SqlValue[];
113
+ column: string;
114
+ } | null;
115
+ /**
116
+ * Parse a tombstone key to extract components.
117
+ * Key format: tb:{schema}.{table}:{pk_json}
118
+ */
119
+ export declare function parseTombstoneKey(key: Uint8Array): {
120
+ schema: string;
121
+ table: string;
122
+ pk: SqlValue[];
123
+ } | null;
124
+ /**
125
+ * Parse a schema migration key to extract components.
126
+ * Key format: sm:{schema}.{table}:{version}
127
+ */
128
+ export declare function parseSchemaMigrationKey(key: Uint8Array): {
129
+ schema: string;
130
+ table: string;
131
+ version: number;
132
+ } | null;
133
+ /**
134
+ * Change log entry type.
135
+ */
136
+ export type ChangeLogEntryType = 'column' | 'delete';
137
+ /**
138
+ * Serialize an HLC to a sortable key component (26 bytes, big-endian).
139
+ * This format ensures lexicographic ordering matches HLC ordering.
140
+ */
141
+ export declare function serializeHLCForKey(hlc: HLC): Uint8Array;
142
+ /**
143
+ * Deserialize an HLC from a key component.
144
+ */
145
+ export declare function deserializeHLCFromKey(buffer: Uint8Array): HLC;
146
+ /**
147
+ * Build a change log key.
148
+ * Format: cl:{hlc_bytes}{type_byte}{schema}.{table}:{pk_json}:{column?}
149
+ *
150
+ * The HLC comes first to enable efficient range scans by time.
151
+ * type_byte: 0x01 for column change, 0x02 for delete
152
+ */
153
+ export declare function buildChangeLogKey(hlc: HLC, entryType: ChangeLogEntryType, schemaName: string, tableName: string, pk: SqlValue[], column?: string): Uint8Array;
154
+ /**
155
+ * Build scan bounds for change log entries after a given HLC.
156
+ * Returns keys to scan cl:{sinceHLC}* to end of change log.
157
+ */
158
+ export declare function buildChangeLogScanBoundsAfter(sinceHLC: HLC): {
159
+ gte: Uint8Array;
160
+ lt: Uint8Array;
161
+ };
162
+ /**
163
+ * Build scan bounds for all change log entries.
164
+ */
165
+ export declare function buildAllChangeLogScanBounds(): {
166
+ gte: Uint8Array;
167
+ lt: Uint8Array;
168
+ };
169
+ /**
170
+ * Parse a change log key to extract components.
171
+ */
172
+ export declare function parseChangeLogKey(key: Uint8Array): {
173
+ hlc: HLC;
174
+ entryType: ChangeLogEntryType;
175
+ schema: string;
176
+ table: string;
177
+ pk: SqlValue[];
178
+ column?: string;
179
+ } | null;
180
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/metadata/keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,GAAG,EAAE,MA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