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