@powersync/service-core 0.0.0-dev-20251209070120 → 0.0.0-dev-20260114113449

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 (47) hide show
  1. package/CHANGELOG.md +29 -4
  2. package/dist/metrics/open-telemetry/util.js +3 -1
  3. package/dist/metrics/open-telemetry/util.js.map +1 -1
  4. package/dist/modules/ModuleManager.d.ts +3 -0
  5. package/dist/modules/ModuleManager.js +11 -0
  6. package/dist/modules/ModuleManager.js.map +1 -1
  7. package/dist/replication/AbstractReplicator.js +3 -1
  8. package/dist/replication/AbstractReplicator.js.map +1 -1
  9. package/dist/routes/endpoints/admin.js +4 -1
  10. package/dist/routes/endpoints/admin.js.map +1 -1
  11. package/dist/routes/endpoints/socket-route.js +1 -4
  12. package/dist/routes/endpoints/socket-route.js.map +1 -1
  13. package/dist/routes/endpoints/sync-rules.js +1 -1
  14. package/dist/routes/endpoints/sync-rules.js.map +1 -1
  15. package/dist/routes/endpoints/sync-stream.js +1 -4
  16. package/dist/routes/endpoints/sync-stream.js.map +1 -1
  17. package/dist/storage/PersistedSyncRulesContent.d.ts +2 -1
  18. package/dist/storage/SyncRulesBucketStorage.d.ts +4 -4
  19. package/dist/storage/bson.d.ts +3 -3
  20. package/dist/storage/bson.js.map +1 -1
  21. package/dist/sync/BucketChecksumState.d.ts +4 -8
  22. package/dist/sync/BucketChecksumState.js +5 -6
  23. package/dist/sync/BucketChecksumState.js.map +1 -1
  24. package/dist/sync/sync.d.ts +2 -2
  25. package/dist/sync/sync.js.map +1 -1
  26. package/dist/util/config/collectors/config-collector.js +5 -2
  27. package/dist/util/config/collectors/config-collector.js.map +1 -1
  28. package/package.json +4 -4
  29. package/src/metrics/open-telemetry/util.ts +3 -1
  30. package/src/modules/ModuleManager.ts +13 -0
  31. package/src/replication/AbstractReplicator.ts +3 -1
  32. package/src/routes/endpoints/admin.ts +4 -1
  33. package/src/routes/endpoints/socket-route.ts +1 -4
  34. package/src/routes/endpoints/sync-rules.ts +1 -1
  35. package/src/routes/endpoints/sync-stream.ts +1 -4
  36. package/src/storage/PersistedSyncRulesContent.ts +3 -1
  37. package/src/storage/SyncRulesBucketStorage.ts +4 -4
  38. package/src/storage/bson.ts +3 -3
  39. package/src/sync/BucketChecksumState.ts +10 -16
  40. package/src/sync/sync.ts +4 -4
  41. package/src/util/config/collectors/config-collector.ts +9 -2
  42. package/test/src/config.test.ts +17 -0
  43. package/test/src/routes/stream.test.ts +2 -2
  44. package/test/src/sync/BucketChecksumState.test.ts +20 -50
  45. package/tsconfig.json +0 -3
  46. package/tsconfig.tsbuildinfo +1 -1
  47. package/vitest.config.ts +6 -7
@@ -12,14 +12,9 @@ import {
12
12
  WatchFilterEvent
13
13
  } from '@/index.js';
14
14
  import { JSONBig } from '@powersync/service-jsonbig';
15
- import {
16
- SqliteJsonRow,
17
- ParameterLookup,
18
- SqlSyncRules,
19
- RequestJwtPayload,
20
- BucketSource
21
- } from '@powersync/service-sync-rules';
22
- import { describe, expect, test, beforeEach } from 'vitest';
15
+ import { RequestJwtPayload, ScopedParameterLookup, SqliteJsonRow, SqlSyncRules } from '@powersync/service-sync-rules';
16
+ import { versionedHydrationState } from '@powersync/service-sync-rules/src/HydrationState.js';
17
+ import { beforeEach, describe, expect, test } from 'vitest';
23
18
 
24
19
  describe('BucketChecksumState', () => {
25
20
  // Single global[] bucket.
@@ -31,7 +26,7 @@ bucket_definitions:
31
26
  data: []
32
27
  `,
33
28
  { defaultSchema: 'public' }
34
- );
29
+ ).hydrate({ hydrationState: versionedHydrationState(1) });
35
30
 
36
31
  // global[1] and global[2]
37
32
  const SYNC_RULES_GLOBAL_TWO = SqlSyncRules.fromYaml(
@@ -44,7 +39,7 @@ bucket_definitions:
44
39
  data: []
45
40
  `,
46
41
  { defaultSchema: 'public' }
47
- );
42
+ ).hydrate({ hydrationState: versionedHydrationState(2) });
48
43
 
49
44
  // by_project[n]
50
45
  const SYNC_RULES_DYNAMIC = SqlSyncRules.fromYaml(
@@ -55,7 +50,7 @@ bucket_definitions:
55
50
  data: []
56
51
  `,
57
52
  { defaultSchema: 'public' }
58
- );
53
+ ).hydrate({ hydrationState: versionedHydrationState(3) });
59
54
 
60
55
  const syncContext = new SyncContext({
61
56
  maxBuckets: 100,
@@ -75,10 +70,7 @@ bucket_definitions:
75
70
  syncContext,
76
71
  syncRequest,
77
72
  tokenPayload,
78
- syncRules: {
79
- syncRules: SYNC_RULES_GLOBAL,
80
- version: 1
81
- },
73
+ syncRules: SYNC_RULES_GLOBAL,
82
74
  bucketStorage: storage
83
75
  });
84
76
 
@@ -148,10 +140,7 @@ bucket_definitions:
148
140
  tokenPayload,
149
141
  // Client sets the initial state here
150
142
  syncRequest: { buckets: [{ name: 'global[]', after: '1' }] },
151
- syncRules: {
152
- syncRules: SYNC_RULES_GLOBAL,
153
- version: 1
154
- },
143
+ syncRules: SYNC_RULES_GLOBAL,
155
144
  bucketStorage: storage
156
145
  });
157
146
 
@@ -189,10 +178,7 @@ bucket_definitions:
189
178
  syncContext,
190
179
  tokenPayload,
191
180
  syncRequest,
192
- syncRules: {
193
- syncRules: SYNC_RULES_GLOBAL_TWO,
194
- version: 2
195
- },
181
+ syncRules: SYNC_RULES_GLOBAL_TWO,
196
182
  bucketStorage: storage
197
183
  });
198
184
 
@@ -260,10 +246,7 @@ bucket_definitions:
260
246
  tokenPayload,
261
247
  // Client sets the initial state here
262
248
  syncRequest: { buckets: [{ name: 'something_here[]', after: '1' }] },
263
- syncRules: {
264
- syncRules: SYNC_RULES_GLOBAL,
265
- version: 1
266
- },
249
+ syncRules: SYNC_RULES_GLOBAL,
267
250
  bucketStorage: storage
268
251
  });
269
252
 
@@ -304,10 +287,7 @@ bucket_definitions:
304
287
  syncContext,
305
288
  tokenPayload,
306
289
  syncRequest,
307
- syncRules: {
308
- syncRules: SYNC_RULES_GLOBAL_TWO,
309
- version: 1
310
- },
290
+ syncRules: SYNC_RULES_GLOBAL_TWO,
311
291
  bucketStorage: storage
312
292
  });
313
293
 
@@ -360,10 +340,7 @@ bucket_definitions:
360
340
  syncContext,
361
341
  tokenPayload,
362
342
  syncRequest,
363
- syncRules: {
364
- syncRules: SYNC_RULES_GLOBAL_TWO,
365
- version: 2
366
- },
343
+ syncRules: SYNC_RULES_GLOBAL_TWO,
367
344
  bucketStorage: storage
368
345
  });
369
346
 
@@ -418,10 +395,7 @@ bucket_definitions:
418
395
  syncContext,
419
396
  tokenPayload,
420
397
  syncRequest,
421
- syncRules: {
422
- syncRules: SYNC_RULES_GLOBAL_TWO,
423
- version: 2
424
- },
398
+ syncRules: SYNC_RULES_GLOBAL_TWO,
425
399
  bucketStorage: storage
426
400
  });
427
401
 
@@ -525,16 +499,13 @@ bucket_definitions:
525
499
  syncContext,
526
500
  tokenPayload: { sub: 'u1' },
527
501
  syncRequest,
528
- syncRules: {
529
- syncRules: SYNC_RULES_DYNAMIC,
530
- version: 1
531
- },
502
+ syncRules: SYNC_RULES_DYNAMIC,
532
503
  bucketStorage: storage
533
504
  });
534
505
 
535
506
  const line = (await state.buildNextCheckpointLine({
536
507
  base: storage.makeCheckpoint(1n, (lookups) => {
537
- expect(lookups).toEqual([ParameterLookup.normalized('by_project', '1', ['u1'])]);
508
+ expect(lookups).toEqual([ScopedParameterLookup.direct({ lookupName: 'by_project', queryId: '1' }, ['u1'])]);
538
509
  return [{ id: 1 }, { id: 2 }];
539
510
  }),
540
511
  writeCheckpoint: null,
@@ -595,7 +566,7 @@ bucket_definitions:
595
566
  // Now we get a new line
596
567
  const line2 = (await state.buildNextCheckpointLine({
597
568
  base: storage.makeCheckpoint(2n, (lookups) => {
598
- expect(lookups).toEqual([ParameterLookup.normalized('by_project', '1', ['u1'])]);
569
+ expect(lookups).toEqual([ScopedParameterLookup.direct({ lookupName: 'by_project', queryId: '1' }, ['u1'])]);
599
570
  return [{ id: 1 }, { id: 2 }, { id: 3 }];
600
571
  }),
601
572
  writeCheckpoint: null,
@@ -627,7 +598,6 @@ bucket_definitions:
627
598
  });
628
599
 
629
600
  describe('streams', () => {
630
- let source: { -readonly [P in keyof BucketSource]: BucketSource[P] };
631
601
  let storage: MockBucketChecksumStateStorage;
632
602
 
633
603
  function checksumState(source: string | boolean, options?: Partial<BucketChecksumStateOptions>) {
@@ -645,13 +615,13 @@ config:
645
615
 
646
616
  const rules = SqlSyncRules.fromYaml(source, {
647
617
  defaultSchema: 'public'
648
- });
618
+ }).hydrate({ hydrationState: versionedHydrationState(1) });
649
619
 
650
620
  return new BucketChecksumState({
651
621
  syncContext,
652
622
  syncRequest,
653
623
  tokenPayload,
654
- syncRules: { syncRules: rules, version: 1 },
624
+ syncRules: rules,
655
625
  bucketStorage: storage,
656
626
  ...options
657
627
  });
@@ -884,12 +854,12 @@ class MockBucketChecksumStateStorage implements BucketChecksumStateStorage {
884
854
 
885
855
  makeCheckpoint(
886
856
  opId: InternalOpId,
887
- parameters?: (lookups: ParameterLookup[]) => SqliteJsonRow[]
857
+ parameters?: (lookups: ScopedParameterLookup[]) => SqliteJsonRow[]
888
858
  ): ReplicationCheckpoint {
889
859
  return {
890
860
  checkpoint: opId,
891
861
  lsn: String(opId),
892
- getParameterSets: async (lookups: ParameterLookup[]) => {
862
+ getParameterSets: async (lookups: ScopedParameterLookup[]) => {
893
863
  if (parameters == null) {
894
864
  throw new Error(`getParametersSets not defined for checkpoint ${opId}`);
895
865
  }
package/tsconfig.json CHANGED
@@ -18,9 +18,6 @@
18
18
  {
19
19
  "path": "../jsonbig"
20
20
  },
21
- {
22
- "path": "../jpgwire"
23
- },
24
21
  {
25
22
  "path": "../sync-rules"
26
23
  },