@powersync/service-core 0.0.0-dev-20250827091123 → 0.0.0-dev-20250828090417

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 (79) hide show
  1. package/CHANGELOG.md +18 -12
  2. package/dist/api/api-metrics.js +5 -0
  3. package/dist/api/api-metrics.js.map +1 -1
  4. package/dist/metrics/open-telemetry/util.d.ts +0 -3
  5. package/dist/metrics/open-telemetry/util.js +18 -13
  6. package/dist/metrics/open-telemetry/util.js.map +1 -1
  7. package/dist/routes/compression.d.ts +19 -0
  8. package/dist/routes/compression.js +70 -0
  9. package/dist/routes/compression.js.map +1 -0
  10. package/dist/routes/configure-fastify.js.map +1 -1
  11. package/dist/routes/endpoints/socket-route.js +23 -18
  12. package/dist/routes/endpoints/socket-route.js.map +1 -1
  13. package/dist/routes/endpoints/sync-stream.js +14 -24
  14. package/dist/routes/endpoints/sync-stream.js.map +1 -1
  15. package/dist/routes/router.d.ts +3 -3
  16. package/dist/storage/BucketStorage.d.ts +1 -1
  17. package/dist/storage/BucketStorage.js.map +1 -1
  18. package/dist/storage/BucketStorageFactory.d.ts +0 -2
  19. package/dist/storage/ChecksumCache.d.ts +4 -19
  20. package/dist/storage/ChecksumCache.js +4 -0
  21. package/dist/storage/ChecksumCache.js.map +1 -1
  22. package/dist/storage/StorageEngine.d.ts +2 -2
  23. package/dist/storage/StorageEngine.js.map +1 -1
  24. package/dist/storage/StorageProvider.d.ts +1 -3
  25. package/dist/storage/SyncRulesBucketStorage.d.ts +9 -0
  26. package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
  27. package/dist/storage/storage-index.d.ts +0 -1
  28. package/dist/storage/storage-index.js +0 -1
  29. package/dist/storage/storage-index.js.map +1 -1
  30. package/dist/sync/BucketChecksumState.d.ts +7 -3
  31. package/dist/sync/BucketChecksumState.js +5 -4
  32. package/dist/sync/BucketChecksumState.js.map +1 -1
  33. package/dist/sync/RequestTracker.d.ts +7 -1
  34. package/dist/sync/RequestTracker.js +22 -2
  35. package/dist/sync/RequestTracker.js.map +1 -1
  36. package/dist/sync/sync.d.ts +2 -2
  37. package/dist/sync/sync.js.map +1 -1
  38. package/dist/sync/util.js +1 -1
  39. package/dist/sync/util.js.map +1 -1
  40. package/dist/system/ServiceContext.d.ts +0 -3
  41. package/dist/system/ServiceContext.js +1 -10
  42. package/dist/system/ServiceContext.js.map +1 -1
  43. package/dist/util/utils.d.ts +17 -2
  44. package/dist/util/utils.js +33 -9
  45. package/dist/util/utils.js.map +1 -1
  46. package/package.json +13 -13
  47. package/src/api/api-metrics.ts +6 -0
  48. package/src/metrics/open-telemetry/util.ts +22 -21
  49. package/src/routes/compression.ts +75 -0
  50. package/src/routes/configure-fastify.ts +1 -0
  51. package/src/routes/endpoints/socket-route.ts +24 -19
  52. package/src/routes/endpoints/sync-stream.ts +15 -24
  53. package/src/routes/router.ts +3 -3
  54. package/src/storage/BucketStorage.ts +2 -2
  55. package/src/storage/BucketStorageFactory.ts +0 -2
  56. package/src/storage/ChecksumCache.ts +8 -22
  57. package/src/storage/StorageEngine.ts +3 -3
  58. package/src/storage/StorageProvider.ts +1 -3
  59. package/src/storage/SyncRulesBucketStorage.ts +12 -0
  60. package/src/storage/storage-index.ts +0 -1
  61. package/src/sync/BucketChecksumState.ts +12 -6
  62. package/src/sync/RequestTracker.ts +27 -2
  63. package/src/sync/sync.ts +3 -3
  64. package/src/sync/util.ts +1 -1
  65. package/src/system/ServiceContext.ts +1 -13
  66. package/src/util/utils.ts +55 -11
  67. package/test/src/checksum_cache.test.ts +6 -8
  68. package/test/src/routes/mocks.ts +59 -0
  69. package/test/src/routes/stream.test.ts +84 -0
  70. package/test/src/sync/BucketChecksumState.test.ts +48 -26
  71. package/tsconfig.tsbuildinfo +1 -1
  72. package/dist/events/EventsEngine.d.ts +0 -14
  73. package/dist/events/EventsEngine.js +0 -33
  74. package/dist/events/EventsEngine.js.map +0 -1
  75. package/dist/storage/ReportStorage.d.ts +0 -36
  76. package/dist/storage/ReportStorage.js +0 -2
  77. package/dist/storage/ReportStorage.js.map +0 -1
  78. package/src/events/EventsEngine.ts +0 -38
  79. package/src/storage/ReportStorage.ts +0 -39
@@ -17,9 +17,7 @@ import {
17
17
  ParameterLookup,
18
18
  SqlSyncRules,
19
19
  RequestJwtPayload,
20
- BucketSource,
21
- BucketSourceType,
22
- BucketParameterQuerier
20
+ BucketSource
23
21
  } from '@powersync/service-sync-rules';
24
22
  import { describe, expect, test, beforeEach } from 'vitest';
25
23
 
@@ -77,7 +75,10 @@ bucket_definitions:
77
75
  syncContext,
78
76
  syncRequest,
79
77
  tokenPayload,
80
- syncRules: SYNC_RULES_GLOBAL,
78
+ syncRules: {
79
+ syncRules: SYNC_RULES_GLOBAL,
80
+ version: 1
81
+ },
81
82
  bucketStorage: storage
82
83
  });
83
84
 
@@ -147,7 +148,10 @@ bucket_definitions:
147
148
  tokenPayload,
148
149
  // Client sets the initial state here
149
150
  syncRequest: { buckets: [{ name: 'global[]', after: '1' }] },
150
- syncRules: SYNC_RULES_GLOBAL,
151
+ syncRules: {
152
+ syncRules: SYNC_RULES_GLOBAL,
153
+ version: 1
154
+ },
151
155
  bucketStorage: storage
152
156
  });
153
157
 
@@ -185,7 +189,10 @@ bucket_definitions:
185
189
  syncContext,
186
190
  tokenPayload,
187
191
  syncRequest,
188
- syncRules: SYNC_RULES_GLOBAL_TWO,
192
+ syncRules: {
193
+ syncRules: SYNC_RULES_GLOBAL_TWO,
194
+ version: 2
195
+ },
189
196
  bucketStorage: storage
190
197
  });
191
198
 
@@ -253,7 +260,10 @@ bucket_definitions:
253
260
  tokenPayload,
254
261
  // Client sets the initial state here
255
262
  syncRequest: { buckets: [{ name: 'something_here[]', after: '1' }] },
256
- syncRules: SYNC_RULES_GLOBAL,
263
+ syncRules: {
264
+ syncRules: SYNC_RULES_GLOBAL,
265
+ version: 1
266
+ },
257
267
  bucketStorage: storage
258
268
  });
259
269
 
@@ -294,7 +304,10 @@ bucket_definitions:
294
304
  syncContext,
295
305
  tokenPayload,
296
306
  syncRequest,
297
- syncRules: SYNC_RULES_GLOBAL_TWO,
307
+ syncRules: {
308
+ syncRules: SYNC_RULES_GLOBAL_TWO,
309
+ version: 1
310
+ },
298
311
  bucketStorage: storage
299
312
  });
300
313
 
@@ -347,7 +360,10 @@ bucket_definitions:
347
360
  syncContext,
348
361
  tokenPayload,
349
362
  syncRequest,
350
- syncRules: SYNC_RULES_GLOBAL_TWO,
363
+ syncRules: {
364
+ syncRules: SYNC_RULES_GLOBAL_TWO,
365
+ version: 2
366
+ },
351
367
  bucketStorage: storage
352
368
  });
353
369
 
@@ -402,7 +418,10 @@ bucket_definitions:
402
418
  syncContext,
403
419
  tokenPayload,
404
420
  syncRequest,
405
- syncRules: SYNC_RULES_GLOBAL_TWO,
421
+ syncRules: {
422
+ syncRules: SYNC_RULES_GLOBAL_TWO,
423
+ version: 2
424
+ },
406
425
  bucketStorage: storage
407
426
  });
408
427
 
@@ -506,7 +525,10 @@ bucket_definitions:
506
525
  syncContext,
507
526
  tokenPayload: { sub: 'u1' },
508
527
  syncRequest,
509
- syncRules: SYNC_RULES_DYNAMIC,
528
+ syncRules: {
529
+ syncRules: SYNC_RULES_DYNAMIC,
530
+ version: 1
531
+ },
510
532
  bucketStorage: storage
511
533
  });
512
534
 
@@ -629,7 +651,7 @@ config:
629
651
  syncContext,
630
652
  syncRequest,
631
653
  tokenPayload,
632
- syncRules: rules,
654
+ syncRules: { syncRules: rules, version: 1 },
633
655
  bucketStorage: storage,
634
656
  ...options
635
657
  });
@@ -637,9 +659,9 @@ config:
637
659
 
638
660
  beforeEach(() => {
639
661
  storage = new MockBucketChecksumStateStorage();
640
- storage.updateTestChecksum({ bucket: 'stream|0["default"]', checksum: 1, count: 1 });
641
- storage.updateTestChecksum({ bucket: 'stream|0["a"]', checksum: 1, count: 1 });
642
- storage.updateTestChecksum({ bucket: 'stream|0["b"]', checksum: 1, count: 1 });
662
+ storage.updateTestChecksum({ bucket: '1#stream|0["default"]', checksum: 1, count: 1 });
663
+ storage.updateTestChecksum({ bucket: '1#stream|0["a"]', checksum: 1, count: 1 });
664
+ storage.updateTestChecksum({ bucket: '1#stream|0["b"]', checksum: 1, count: 1 });
643
665
  });
644
666
 
645
667
  test('includes defaults', async () => {
@@ -653,7 +675,7 @@ config:
653
675
  expect(line?.checkpointLine).toEqual({
654
676
  checkpoint: {
655
677
  buckets: [
656
- { bucket: 'stream|0["default"]', checksum: 1, count: 1, priority: 3, subscriptions: [{ default: 0 }] }
678
+ { bucket: '1#stream|0["default"]', checksum: 1, count: 1, priority: 3, subscriptions: [{ default: 0 }] }
657
679
  ],
658
680
  last_op_id: '1',
659
681
  write_checkpoint: undefined,
@@ -702,9 +724,9 @@ config:
702
724
  expect(line?.checkpointLine).toEqual({
703
725
  checkpoint: {
704
726
  buckets: [
705
- { bucket: 'stream|0["a"]', checksum: 1, count: 1, priority: 3, subscriptions: [{ sub: 0 }] },
706
- { bucket: 'stream|0["b"]', checksum: 1, count: 1, priority: 1, subscriptions: [{ sub: 1 }] },
707
- { bucket: 'stream|0["default"]', checksum: 1, count: 1, priority: 3, subscriptions: [{ default: 0 }] }
727
+ { bucket: '1#stream|0["a"]', checksum: 1, count: 1, priority: 3, subscriptions: [{ sub: 0 }] },
728
+ { bucket: '1#stream|0["b"]', checksum: 1, count: 1, priority: 1, subscriptions: [{ sub: 1 }] },
729
+ { bucket: '1#stream|0["default"]', checksum: 1, count: 1, priority: 3, subscriptions: [{ default: 0 }] }
708
730
  ],
709
731
  last_op_id: '1',
710
732
  write_checkpoint: undefined,
@@ -734,8 +756,8 @@ config:
734
756
  expect(line?.checkpointLine).toEqual({
735
757
  checkpoint: {
736
758
  buckets: [
737
- { bucket: 'stream|0["a"]', checksum: 1, count: 1, priority: 3, subscriptions: [{ sub: 0 }] },
738
- { bucket: 'stream|0["b"]', checksum: 1, count: 1, priority: 1, subscriptions: [{ sub: 0 }, { sub: 1 }] }
759
+ { bucket: '1#stream|0["a"]', checksum: 1, count: 1, priority: 3, subscriptions: [{ sub: 0 }] },
760
+ { bucket: '1#stream|0["b"]', checksum: 1, count: 1, priority: 1, subscriptions: [{ sub: 0 }, { sub: 1 }] }
739
761
  ],
740
762
  last_op_id: '1',
741
763
  write_checkpoint: undefined,
@@ -762,9 +784,9 @@ config:
762
784
  expect(line?.checkpointLine).toEqual({
763
785
  checkpoint: {
764
786
  buckets: [
765
- { bucket: 'stream|0["a"]', checksum: 1, count: 1, priority: 1, subscriptions: [{ sub: 0 }] },
787
+ { bucket: '1#stream|0["a"]', checksum: 1, count: 1, priority: 1, subscriptions: [{ sub: 0 }] },
766
788
  {
767
- bucket: 'stream|0["default"]',
789
+ bucket: '1#stream|0["default"]',
768
790
  checksum: 1,
769
791
  count: 1,
770
792
  priority: 1,
@@ -799,10 +821,10 @@ config:
799
821
  expect(line?.checkpointLine).toEqual({
800
822
  checkpoint: {
801
823
  buckets: [
802
- { bucket: 'stream|0["a"]', checksum: 1, count: 1, priority: 1, subscriptions: [{ sub: 0 }] },
803
- { bucket: 'stream|0["b"]', checksum: 1, count: 1, priority: 1, subscriptions: [{ sub: 0 }] },
824
+ { bucket: '1#stream|0["a"]', checksum: 1, count: 1, priority: 1, subscriptions: [{ sub: 0 }] },
825
+ { bucket: '1#stream|0["b"]', checksum: 1, count: 1, priority: 1, subscriptions: [{ sub: 0 }] },
804
826
  {
805
- bucket: 'stream|0["default"]',
827
+ bucket: '1#stream|0["default"]',
806
828
  checksum: 1,
807
829
  count: 1,
808
830
  priority: 3,