@powersync/service-core 0.0.0-dev-20250317122913 → 0.0.0-dev-20250325131118

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 (104) hide show
  1. package/CHANGELOG.md +18 -4
  2. package/dist/api/api-index.d.ts +1 -0
  3. package/dist/api/api-index.js +1 -0
  4. package/dist/api/api-index.js.map +1 -1
  5. package/dist/api/api-metrics.d.ts +11 -0
  6. package/dist/api/api-metrics.js +30 -0
  7. package/dist/api/api-metrics.js.map +1 -0
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.js +2 -2
  10. package/dist/index.js.map +1 -1
  11. package/dist/metrics/MetricsEngine.d.ts +21 -0
  12. package/dist/metrics/MetricsEngine.js +79 -0
  13. package/dist/metrics/MetricsEngine.js.map +1 -0
  14. package/dist/metrics/metrics-index.d.ts +4 -0
  15. package/dist/metrics/metrics-index.js +5 -0
  16. package/dist/metrics/metrics-index.js.map +1 -0
  17. package/dist/metrics/metrics-interfaces.d.ts +36 -0
  18. package/dist/metrics/metrics-interfaces.js +6 -0
  19. package/dist/metrics/metrics-interfaces.js.map +1 -0
  20. package/dist/metrics/open-telemetry/OpenTelemetryMetricsFactory.d.ts +10 -0
  21. package/dist/metrics/open-telemetry/OpenTelemetryMetricsFactory.js +51 -0
  22. package/dist/metrics/open-telemetry/OpenTelemetryMetricsFactory.js.map +1 -0
  23. package/dist/metrics/open-telemetry/util.d.ts +6 -0
  24. package/dist/metrics/open-telemetry/util.js +56 -0
  25. package/dist/metrics/open-telemetry/util.js.map +1 -0
  26. package/dist/replication/AbstractReplicationJob.d.ts +2 -0
  27. package/dist/replication/AbstractReplicationJob.js.map +1 -1
  28. package/dist/replication/AbstractReplicator.d.ts +3 -0
  29. package/dist/replication/AbstractReplicator.js +3 -0
  30. package/dist/replication/AbstractReplicator.js.map +1 -1
  31. package/dist/replication/ReplicationModule.d.ts +7 -0
  32. package/dist/replication/ReplicationModule.js +1 -0
  33. package/dist/replication/ReplicationModule.js.map +1 -1
  34. package/dist/replication/replication-index.d.ts +1 -0
  35. package/dist/replication/replication-index.js +1 -0
  36. package/dist/replication/replication-index.js.map +1 -1
  37. package/dist/replication/replication-metrics.d.ts +11 -0
  38. package/dist/replication/replication-metrics.js +39 -0
  39. package/dist/replication/replication-metrics.js.map +1 -0
  40. package/dist/routes/configure-fastify.d.ts +1 -1
  41. package/dist/routes/endpoints/probes.d.ts +2 -2
  42. package/dist/routes/endpoints/probes.js +16 -2
  43. package/dist/routes/endpoints/probes.js.map +1 -1
  44. package/dist/routes/endpoints/socket-route.js +5 -5
  45. package/dist/routes/endpoints/socket-route.js.map +1 -1
  46. package/dist/routes/endpoints/sync-stream.js +6 -6
  47. package/dist/routes/endpoints/sync-stream.js.map +1 -1
  48. package/dist/storage/SyncRulesBucketStorage.d.ts +11 -1
  49. package/dist/storage/SyncRulesBucketStorage.js +1 -1
  50. package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
  51. package/dist/storage/WriteCheckpointAPI.d.ts +0 -2
  52. package/dist/storage/WriteCheckpointAPI.js.map +1 -1
  53. package/dist/storage/storage-index.d.ts +1 -0
  54. package/dist/storage/storage-index.js +1 -0
  55. package/dist/storage/storage-index.js.map +1 -1
  56. package/dist/storage/storage-metrics.d.ts +4 -0
  57. package/dist/storage/storage-metrics.js +56 -0
  58. package/dist/storage/storage-metrics.js.map +1 -0
  59. package/dist/sync/BucketChecksumState.d.ts +4 -2
  60. package/dist/sync/BucketChecksumState.js +17 -26
  61. package/dist/sync/BucketChecksumState.js.map +1 -1
  62. package/dist/sync/RequestTracker.d.ts +3 -0
  63. package/dist/sync/RequestTracker.js +8 -3
  64. package/dist/sync/RequestTracker.js.map +1 -1
  65. package/dist/sync/util.d.ts +10 -2
  66. package/dist/sync/util.js +25 -6
  67. package/dist/sync/util.js.map +1 -1
  68. package/dist/system/ServiceContext.d.ts +3 -3
  69. package/dist/system/ServiceContext.js +7 -3
  70. package/dist/system/ServiceContext.js.map +1 -1
  71. package/package.json +8 -8
  72. package/src/api/api-index.ts +1 -0
  73. package/src/api/api-metrics.ts +35 -0
  74. package/src/index.ts +2 -2
  75. package/src/metrics/MetricsEngine.ts +98 -0
  76. package/src/metrics/metrics-index.ts +4 -0
  77. package/src/metrics/metrics-interfaces.ts +41 -0
  78. package/src/metrics/open-telemetry/OpenTelemetryMetricsFactory.ts +66 -0
  79. package/src/metrics/open-telemetry/util.ts +74 -0
  80. package/src/replication/AbstractReplicationJob.ts +2 -0
  81. package/src/replication/AbstractReplicator.ts +7 -0
  82. package/src/replication/ReplicationModule.ts +10 -0
  83. package/src/replication/replication-index.ts +1 -0
  84. package/src/replication/replication-metrics.ts +45 -0
  85. package/src/routes/endpoints/probes.ts +18 -2
  86. package/src/routes/endpoints/socket-route.ts +6 -5
  87. package/src/routes/endpoints/sync-stream.ts +7 -6
  88. package/src/storage/SyncRulesBucketStorage.ts +12 -2
  89. package/src/storage/WriteCheckpointAPI.ts +0 -2
  90. package/src/storage/storage-index.ts +1 -0
  91. package/src/storage/storage-metrics.ts +67 -0
  92. package/src/sync/BucketChecksumState.ts +25 -41
  93. package/src/sync/RequestTracker.ts +9 -3
  94. package/src/sync/util.ts +29 -8
  95. package/src/system/ServiceContext.ts +9 -4
  96. package/test/src/routes/probes.integration.test.ts +5 -5
  97. package/test/src/routes/probes.test.ts +5 -4
  98. package/test/src/sync/BucketChecksumState.test.ts +5 -5
  99. package/test/src/util.test.ts +48 -0
  100. package/tsconfig.tsbuildinfo +1 -1
  101. package/dist/metrics/Metrics.d.ts +0 -30
  102. package/dist/metrics/Metrics.js +0 -202
  103. package/dist/metrics/Metrics.js.map +0 -1
  104. package/src/metrics/Metrics.ts +0 -255
@@ -98,7 +98,7 @@ bucket_definitions:
98
98
  base: { checkpoint: 2n, lsn: '2' },
99
99
  writeCheckpoint: null,
100
100
  update: {
101
- updatedDataBuckets: ['global[]'],
101
+ updatedDataBuckets: new Set(['global[]']),
102
102
  invalidateDataBuckets: false,
103
103
  updatedParameterLookups: new Set(),
104
104
  invalidateParameterBuckets: false
@@ -201,7 +201,7 @@ bucket_definitions:
201
201
  writeCheckpoint: null,
202
202
  update: {
203
203
  ...CHECKPOINT_INVALIDATE_ALL,
204
- updatedDataBuckets: ['global[1]', 'global[2]'],
204
+ updatedDataBuckets: new Set(['global[1]', 'global[2]']),
205
205
  invalidateDataBuckets: false
206
206
  }
207
207
  }))!;
@@ -294,7 +294,7 @@ bucket_definitions:
294
294
  // Invalidate the state for global[1] - will only re-check the single bucket.
295
295
  // This is essentially inconsistent state, but is the simplest way to test that
296
296
  // the filter is working.
297
- updatedDataBuckets: ['global[1]'],
297
+ updatedDataBuckets: new Set(['global[1]']),
298
298
  invalidateDataBuckets: false
299
299
  }
300
300
  }))!;
@@ -421,7 +421,7 @@ bucket_definitions:
421
421
  update: {
422
422
  ...CHECKPOINT_INVALIDATE_ALL,
423
423
  invalidateDataBuckets: false,
424
- updatedDataBuckets: ['global[1]']
424
+ updatedDataBuckets: new Set(['global[1]'])
425
425
  }
426
426
  }))!;
427
427
  expect(line2.checkpointLine).toEqual({
@@ -533,7 +533,7 @@ bucket_definitions:
533
533
  writeCheckpoint: null,
534
534
  update: {
535
535
  invalidateDataBuckets: false,
536
- updatedDataBuckets: [],
536
+ updatedDataBuckets: new Set(),
537
537
  updatedParameterLookups: new Set([JSONBig.stringify(['by_project', '1', 'u1'])]),
538
538
  invalidateParameterBuckets: false
539
539
  }
@@ -0,0 +1,48 @@
1
+ import { getIntersection, hasIntersection } from '@/index.js';
2
+ import { describe, expect, test } from 'vitest';
3
+
4
+ describe('utils', () => {
5
+ function testInstersection(a: Set<any>, b: Set<any>, expected: boolean) {
6
+ expect(hasIntersection(a, b)).toBe(expected);
7
+ expect(hasIntersection(b, a)).toBe(expected);
8
+ const mapA = new Map([...a].map((v) => [v, 1]));
9
+ const mapB = new Map([...b].map((v) => [v, 1]));
10
+ expect(hasIntersection(mapA, b)).toBe(expected);
11
+ expect(hasIntersection(mapB, a)).toBe(expected);
12
+ expect(hasIntersection(mapA, mapB)).toBe(expected);
13
+ }
14
+
15
+ test('hasIntersection', async () => {
16
+ testInstersection(new Set(['a']), new Set(['a']), true);
17
+ testInstersection(new Set(['a', 'b', 'c']), new Set(['a', 'b', 'c']), true);
18
+ testInstersection(new Set(['a', 'b', 'c']), new Set(['d', 'e']), false);
19
+ testInstersection(new Set(['a', 'b', 'c']), new Set(['d', 'c', 'e']), true);
20
+ testInstersection(new Set(['a', 'b', 'c']), new Set(['c', 'e']), true);
21
+ testInstersection(new Set(['a', 'b', 'c', 2]), new Set([1, 2, 3]), true);
22
+ testInstersection(new Set(['a', 'b', 'c', 4]), new Set([1, 2, 3]), false);
23
+ testInstersection(new Set([]), new Set([1, 2, 3]), false);
24
+ testInstersection(new Set([]), new Set([]), false);
25
+ });
26
+
27
+ function testGetIntersection(a: Set<any>, b: Set<any>, expected: any[]) {
28
+ expect([...getIntersection(a, b)]).toEqual(expected);
29
+ expect([...getIntersection(b, a)]).toEqual(expected);
30
+ const mapA = new Map([...a].map((v) => [v, 1]));
31
+ const mapB = new Map([...b].map((v) => [v, 1]));
32
+ expect([...getIntersection(mapA, b)]).toEqual(expected);
33
+ expect([...getIntersection(mapB, a)]).toEqual(expected);
34
+ expect([...getIntersection(mapA, mapB)]).toEqual(expected);
35
+ }
36
+
37
+ test('getIntersection', async () => {
38
+ testGetIntersection(new Set(['a']), new Set(['a']), ['a']);
39
+ testGetIntersection(new Set(['a', 'b', 'c']), new Set(['a', 'b', 'c']), ['a', 'b', 'c']);
40
+ testGetIntersection(new Set(['a', 'b', 'c']), new Set(['d', 'e']), []);
41
+ testGetIntersection(new Set(['a', 'b', 'c']), new Set(['d', 'c', 'e']), ['c']);
42
+ testGetIntersection(new Set(['a', 'b', 'c']), new Set(['c', 'e']), ['c']);
43
+ testGetIntersection(new Set(['a', 'b', 'c', 2]), new Set([1, 2, 3]), [2]);
44
+ testGetIntersection(new Set(['a', 'b', 'c', 4]), new Set([1, 2, 3]), []);
45
+ testGetIntersection(new Set([]), new Set([1, 2, 3]), []);
46
+ testGetIntersection(new Set([]), new Set([]), []);
47
+ });
48
+ });