@powersync/service-core-tests 0.18.1 → 0.18.3

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 (39) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/test-utils/AbstractStreamTestContext.js +4 -3
  3. package/dist/test-utils/AbstractStreamTestContext.js.map +1 -1
  4. package/dist/test-utils/leased-storage.d.ts +9 -0
  5. package/dist/test-utils/leased-storage.js +53 -0
  6. package/dist/test-utils/leased-storage.js.map +1 -0
  7. package/dist/test-utils/storage-combinations.d.ts +5 -3
  8. package/dist/test-utils/storage-combinations.js +5 -4
  9. package/dist/test-utils/storage-combinations.js.map +1 -1
  10. package/dist/test-utils/test-utils-index.d.ts +1 -0
  11. package/dist/test-utils/test-utils-index.js +1 -0
  12. package/dist/test-utils/test-utils-index.js.map +1 -1
  13. package/dist/tests/register-compacting-tests.js +16 -7
  14. package/dist/tests/register-compacting-tests.js.map +1 -1
  15. package/dist/tests/register-data-storage-checkpoint-tests.js +8 -7
  16. package/dist/tests/register-data-storage-checkpoint-tests.js.map +1 -1
  17. package/dist/tests/register-data-storage-data-tests.d.ts +7 -3
  18. package/dist/tests/register-data-storage-data-tests.js +38 -26
  19. package/dist/tests/register-data-storage-data-tests.js.map +1 -1
  20. package/dist/tests/register-data-storage-parameter-tests.d.ts +4 -2
  21. package/dist/tests/register-data-storage-parameter-tests.js +19 -18
  22. package/dist/tests/register-data-storage-parameter-tests.js.map +1 -1
  23. package/dist/tests/register-parameter-compacting-tests.d.ts +3 -1
  24. package/dist/tests/register-parameter-compacting-tests.js +13 -6
  25. package/dist/tests/register-parameter-compacting-tests.js.map +1 -1
  26. package/dist/tests/register-sync-tests.js +20 -19
  27. package/dist/tests/register-sync-tests.js.map +1 -1
  28. package/package.json +4 -4
  29. package/src/test-utils/AbstractStreamTestContext.ts +4 -3
  30. package/src/test-utils/leased-storage.ts +58 -0
  31. package/src/test-utils/storage-combinations.ts +16 -5
  32. package/src/test-utils/test-utils-index.ts +1 -0
  33. package/src/tests/register-compacting-tests.ts +16 -7
  34. package/src/tests/register-data-storage-checkpoint-tests.ts +8 -7
  35. package/src/tests/register-data-storage-data-tests.ts +43 -28
  36. package/src/tests/register-data-storage-parameter-tests.ts +20 -19
  37. package/src/tests/register-parameter-compacting-tests.ts +23 -9
  38. package/src/tests/register-sync-tests.ts +20 -19
  39. package/tsconfig.tsbuildinfo +1 -1
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  BucketDataBatchOptions,
3
- CURRENT_STORAGE_VERSION,
4
3
  getUuidReplicaIdentityBson,
5
4
  OplogEntry,
6
5
  reduceBucket,
@@ -8,6 +7,7 @@ import {
8
7
  updateSyncRulesFromYaml
9
8
  } from '@powersync/service-core';
10
9
  import { describe, expect, test } from 'vitest';
10
+ import { getTestStorage } from '../test-utils/leased-storage.js';
11
11
  import * as test_utils from '../test-utils/test-utils-index.js';
12
12
  import { bucketRequest } from '../test-utils/test-utils-index.js';
13
13
 
@@ -27,14 +27,29 @@ const normalizeOplogData = (data: OplogEntry['data']) => {
27
27
  * ```TypeScript
28
28
  *
29
29
  * describe('store - mongodb', function () {
30
- * registerDataStorageDataTests(MONGO_STORAGE_FACTORY);
30
+ * registerDataStorageDataTests({ ...MONGO_STORAGE_FACTORY, storageVersion: storage.STORAGE_VERSION_4 });
31
31
  * });
32
32
  *
33
33
  * ```
34
34
  */
35
- export function registerDataStorageDataTests(config: storage.TestStorageConfig) {
35
+ export function registerDataStorageDataTests(config: storage.TestStorageConfig & { storageVersion: number }) {
36
36
  const generateStorageFactory = config.factory;
37
- const storageVersion = config.storageVersion ?? storage.CURRENT_STORAGE_VERSION;
37
+ const storageVersion = config.storageVersion;
38
+
39
+ test('releases test replication leases when leaving an await using scope', async () => {
40
+ {
41
+ await using factory = await generateStorageFactory();
42
+ const stream = await factory.updateSyncRules(
43
+ updateSyncRulesFromYaml('bucket_definitions: {}', { storageVersion })
44
+ );
45
+ await getTestStorage(factory, stream);
46
+ }
47
+
48
+ await using replacement = await generateStorageFactory({ doNotClear: true });
49
+ const deploying = await replacement.getDeployingSyncConfig();
50
+ expect(deploying).not.toBeNull();
51
+ await getTestStorage(replacement, deploying!.replicationStream);
52
+ });
38
53
 
39
54
  test('removing row', async () => {
40
55
  await using factory = await generateStorageFactory();
@@ -50,7 +65,7 @@ bucket_definitions:
50
65
  { storageVersion }
51
66
  )
52
67
  );
53
- const bucketStorage = factory.getInstance(replicationStream);
68
+ const bucketStorage = await getTestStorage(factory, replicationStream);
54
69
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
55
70
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
56
71
 
@@ -116,7 +131,7 @@ bucket_definitions:
116
131
  { storageVersion }
117
132
  )
118
133
  );
119
- const bucketStorage = factory.getInstance(replicationStream);
134
+ const bucketStorage = await getTestStorage(factory, replicationStream);
120
135
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
121
136
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
122
137
  await writer.markAllSnapshotDone('1/1');
@@ -181,7 +196,7 @@ bucket_definitions:
181
196
  { storageVersion }
182
197
  )
183
198
  );
184
- const bucketStorage = factory.getInstance(replicationStream);
199
+ const bucketStorage = await getTestStorage(factory, replicationStream);
185
200
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
186
201
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
187
202
  await writer.markAllSnapshotDone('1/1');
@@ -251,7 +266,7 @@ bucket_definitions:
251
266
  }
252
267
  )
253
268
  );
254
- const bucketStorage = factory.getInstance(replicationStream);
269
+ const bucketStorage = await getTestStorage(factory, replicationStream);
255
270
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
256
271
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
257
272
  await writer.markAllSnapshotDone('1/1');
@@ -314,7 +329,7 @@ bucket_definitions:
314
329
  }
315
330
  )
316
331
  );
317
- const bucketStorage = factory.getInstance(replicationStream);
332
+ const bucketStorage = await getTestStorage(factory, replicationStream);
318
333
  {
319
334
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
320
335
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
@@ -393,7 +408,7 @@ bucket_definitions:
393
408
  }
394
409
  )
395
410
  );
396
- const bucketStorage = factory.getInstance(replicationStream);
411
+ const bucketStorage = await getTestStorage(factory, replicationStream);
397
412
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
398
413
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
399
414
  await writer.markAllSnapshotDone('1/1');
@@ -465,7 +480,7 @@ bucket_definitions:
465
480
  }
466
481
  )
467
482
  );
468
- const bucketStorage = factory.getInstance(replicationStream);
483
+ const bucketStorage = await getTestStorage(factory, replicationStream);
469
484
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
470
485
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
471
486
  await writer.markAllSnapshotDone('1/1');
@@ -540,7 +555,7 @@ bucket_definitions:
540
555
  { storageVersion }
541
556
  )
542
557
  );
543
- const bucketStorage = factory.getInstance(replicationStream);
558
+ const bucketStorage = await getTestStorage(factory, replicationStream);
544
559
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
545
560
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
546
561
  await writer.markAllSnapshotDone('1/1');
@@ -671,7 +686,7 @@ bucket_definitions:
671
686
  { storageVersion }
672
687
  )
673
688
  );
674
- const bucketStorage = factory.getInstance(replicationStream);
689
+ const bucketStorage = await getTestStorage(factory, replicationStream);
675
690
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
676
691
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
677
692
 
@@ -835,7 +850,7 @@ bucket_definitions:
835
850
  }
836
851
  )
837
852
  );
838
- const bucketStorage = factory.getInstance(replicationStream);
853
+ const bucketStorage = await getTestStorage(factory, replicationStream);
839
854
 
840
855
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
841
856
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id', 'description'], config);
@@ -949,7 +964,7 @@ bucket_definitions:
949
964
  }
950
965
  )
951
966
  );
952
- const bucketStorage = factory.getInstance(replicationStream);
967
+ const bucketStorage = await getTestStorage(factory, replicationStream);
953
968
 
954
969
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
955
970
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id', 'description'], config);
@@ -1053,7 +1068,7 @@ bucket_definitions:
1053
1068
  }
1054
1069
  )
1055
1070
  );
1056
- const bucketStorage = factory.getInstance(replicationStream);
1071
+ const bucketStorage = await getTestStorage(factory, replicationStream);
1057
1072
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1058
1073
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
1059
1074
  await writer.markAllSnapshotDone('1/1');
@@ -1167,7 +1182,7 @@ bucket_definitions:
1167
1182
  }
1168
1183
  )
1169
1184
  );
1170
- const bucketStorage = factory.getInstance(replicationStream);
1185
+ const bucketStorage = await getTestStorage(factory, replicationStream);
1171
1186
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1172
1187
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
1173
1188
  await writer.markAllSnapshotDone('1/1');
@@ -1267,7 +1282,7 @@ bucket_definitions:
1267
1282
  { storageVersion }
1268
1283
  )
1269
1284
  );
1270
- const bucketStorage = factory.getInstance(replicationStream);
1285
+ const bucketStorage = await getTestStorage(factory, replicationStream);
1271
1286
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1272
1287
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
1273
1288
  await writer.markAllSnapshotDone('1/1');
@@ -1466,7 +1481,7 @@ bucket_definitions:
1466
1481
  });
1467
1482
 
1468
1483
  const r = await f.configureSyncRules(updateSyncRulesFromYaml('bucket_definitions: {}'));
1469
- const storage = f.getInstance(r.persisted_sync_rules!);
1484
+ const storage = await getTestStorage(f, r.persisted_sync_rules!);
1470
1485
  await using writer = await storage.createWriter(test_utils.BATCH_OPTIONS);
1471
1486
  await writer.markAllSnapshotDone('1/0');
1472
1487
  await writer.keepalive('1/0');
@@ -1495,7 +1510,7 @@ bucket_definitions:
1495
1510
  }
1496
1511
  )
1497
1512
  );
1498
- const bucketStorage = factory.getInstance(replicationStream);
1513
+ const bucketStorage = await getTestStorage(factory, replicationStream);
1499
1514
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1500
1515
 
1501
1516
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config, 1);
@@ -1547,7 +1562,7 @@ bucket_definitions:
1547
1562
  }
1548
1563
  )
1549
1564
  );
1550
- const bucketStorage = factory.getInstance(replicationStream);
1565
+ const bucketStorage = await getTestStorage(factory, replicationStream);
1551
1566
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1552
1567
 
1553
1568
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
@@ -1589,7 +1604,7 @@ bucket_definitions:
1589
1604
  { storageVersion }
1590
1605
  )
1591
1606
  );
1592
- const bucketStorage = factory.getInstance(replicationStream);
1607
+ const bucketStorage = await getTestStorage(factory, replicationStream);
1593
1608
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1594
1609
  await writer.markAllSnapshotDone('1/1');
1595
1610
  await writer.commit('1/1');
@@ -1628,7 +1643,7 @@ bucket_definitions:
1628
1643
  }
1629
1644
  )
1630
1645
  );
1631
- const bucketStorage = factory.getInstance(replicationStream);
1646
+ const bucketStorage = await getTestStorage(factory, replicationStream);
1632
1647
  await using writer1 = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1633
1648
  await using writer2 = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1634
1649
  const sourceTable = await test_utils.resolveTestTable(writer2, 'test', ['id'], config);
@@ -1679,7 +1694,7 @@ bucket_definitions:
1679
1694
  }
1680
1695
  )
1681
1696
  );
1682
- const bucketStorage = factory.getInstance(replicationStream);
1697
+ const bucketStorage = await getTestStorage(factory, replicationStream);
1683
1698
 
1684
1699
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1685
1700
  const result1 = await writer.commit('1/1', { createEmptyCheckpoints: false });
@@ -1732,7 +1747,7 @@ bucket_definitions:
1732
1747
  }
1733
1748
  )
1734
1749
  );
1735
- const bucketStorage = factory.getInstance(replicationStream);
1750
+ const bucketStorage = await getTestStorage(factory, replicationStream);
1736
1751
  await using snapshotWriter = await bucketStorage.createWriter({
1737
1752
  ...test_utils.BATCH_OPTIONS,
1738
1753
  skipExistingRows: true
@@ -1784,8 +1799,8 @@ bucket_definitions:
1784
1799
  *
1785
1800
  * Exposed as a separate test so we can test with more storage parameters.
1786
1801
  */
1787
- export function testChecksumBatching(config: storage.TestStorageConfig) {
1788
- const storageVersion = config.storageVersion ?? CURRENT_STORAGE_VERSION;
1802
+ export function testChecksumBatching(config: storage.TestStorageConfig & { storageVersion: number }) {
1803
+ const storageVersion = config.storageVersion;
1789
1804
  test('checksums for multiple buckets', async () => {
1790
1805
  await using factory = await config.factory();
1791
1806
  const { stream: replicationStream, content: syncRules } = await test_utils.deploySyncRules(
@@ -1803,7 +1818,7 @@ bucket_definitions:
1803
1818
  }
1804
1819
  )
1805
1820
  );
1806
- const bucketStorage = factory.getInstance(replicationStream);
1821
+ const bucketStorage = await getTestStorage(factory, replicationStream);
1807
1822
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1808
1823
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
1809
1824
  await writer.markAllSnapshotDone('1/1');
@@ -1,4 +1,4 @@
1
- import { CURRENT_STORAGE_VERSION, JwtPayload, storage, updateSyncRulesFromYaml } from '@powersync/service-core';
1
+ import { JwtPayload, storage, updateSyncRulesFromYaml } from '@powersync/service-core';
2
2
  import {
3
3
  ParameterIndexLookupCreator,
4
4
  RequestParameters,
@@ -7,6 +7,7 @@ import {
7
7
  UnscopedParameterLookup
8
8
  } from '@powersync/service-sync-rules';
9
9
  import { expect, test } from 'vitest';
10
+ import { getTestStorage } from '../test-utils/leased-storage.js';
10
11
  import * as test_utils from '../test-utils/test-utils-index.js';
11
12
  import { bucketRequest } from '../test-utils/test-utils-index.js';
12
13
 
@@ -15,14 +16,14 @@ import { bucketRequest } from '../test-utils/test-utils-index.js';
15
16
  * ```TypeScript
16
17
  *
17
18
  * describe('store - mongodb', function () {
18
- * registerDataStorageTests(MONGO_STORAGE_FACTORY);
19
+ * registerDataStorageParameterTests({ ...MONGO_STORAGE_FACTORY, storageVersion: storage.STORAGE_VERSION_4 });
19
20
  * });
20
21
  *
21
22
  * ```
22
23
  */
23
- export function registerDataStorageParameterTests(config: storage.TestStorageConfig) {
24
+ export function registerDataStorageParameterTests(config: storage.TestStorageConfig & { storageVersion: number }) {
24
25
  const generateStorageFactory = config.factory;
25
- const storageVersion = config.storageVersion ?? CURRENT_STORAGE_VERSION;
26
+ const storageVersion = config.storageVersion;
26
27
 
27
28
  test('save and load parameters', async () => {
28
29
  await using factory = await generateStorageFactory();
@@ -41,7 +42,7 @@ bucket_definitions:
41
42
  }
42
43
  )
43
44
  );
44
- const bucketStorage = factory.getInstance(replicationStream);
45
+ const bucketStorage = await getTestStorage(factory, replicationStream);
45
46
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
46
47
 
47
48
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
@@ -108,7 +109,7 @@ bucket_definitions:
108
109
  }
109
110
  )
110
111
  );
111
- const bucketStorage = factory.getInstance(replicationStream);
112
+ const bucketStorage = await getTestStorage(factory, replicationStream);
112
113
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
113
114
 
114
115
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
@@ -180,7 +181,7 @@ bucket_definitions:
180
181
  { storageVersion }
181
182
  )
182
183
  );
183
- const bucketStorage = factory.getInstance(replicationStream);
184
+ const bucketStorage = await getTestStorage(factory, replicationStream);
184
185
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
185
186
 
186
187
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
@@ -268,7 +269,7 @@ bucket_definitions:
268
269
  }
269
270
  )
270
271
  );
271
- const bucketStorage = factory.getInstance(replicationStream);
272
+ const bucketStorage = await getTestStorage(factory, replicationStream);
272
273
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
273
274
 
274
275
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
@@ -337,7 +338,7 @@ bucket_definitions:
337
338
  }
338
339
  )
339
340
  );
340
- const bucketStorage = factory.getInstance(replicationStream);
341
+ const bucketStorage = await getTestStorage(factory, replicationStream);
341
342
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
342
343
 
343
344
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
@@ -407,7 +408,7 @@ bucket_definitions:
407
408
  )
408
409
  );
409
410
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
410
- const bucketStorage = factory.getInstance(replicationStream);
411
+ const bucketStorage = await getTestStorage(factory, replicationStream);
411
412
 
412
413
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
413
414
  const workspaceTable = await test_utils.resolveTestTable(writer, 'workspace', ['id'], config);
@@ -466,7 +467,7 @@ bucket_definitions:
466
467
  )
467
468
  );
468
469
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
469
- const bucketStorage = factory.getInstance(replicationStream);
470
+ const bucketStorage = await getTestStorage(factory, replicationStream);
470
471
 
471
472
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
472
473
  const workspaceTable = await test_utils.resolveTestTable(writer, 'workspace', undefined, config);
@@ -561,7 +562,7 @@ bucket_definitions:
561
562
  )
562
563
  );
563
564
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
564
- const bucketStorage = factory.getInstance(replicationStream);
565
+ const bucketStorage = await getTestStorage(factory, replicationStream);
565
566
 
566
567
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
567
568
  const workspaceTable = await test_utils.resolveTestTable(writer, 'workspace', undefined, config);
@@ -662,7 +663,7 @@ bucket_definitions:
662
663
  }
663
664
  )
664
665
  );
665
- const bucketStorage = factory.getInstance(replicationStream);
666
+ const bucketStorage = await getTestStorage(factory, replicationStream);
666
667
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
667
668
 
668
669
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
@@ -716,7 +717,7 @@ bucket_definitions:
716
717
  }
717
718
  )
718
719
  );
719
- const syncBucketStorage = bucketStorageFactory.getInstance(syncRules);
720
+ const syncBucketStorage = await getTestStorage(bucketStorageFactory, syncRules);
720
721
 
721
722
  const parsedSchema1 = syncBucketStorage.getParsedSyncRules({
722
723
  defaultSchema: 'public'
@@ -754,7 +755,7 @@ streams:
754
755
  WHERE data.foo = param.bar AND param.baz = auth.user_id()
755
756
  `)
756
757
  );
757
- const bucketStorage = factory.getInstance(replicationStream);
758
+ const bucketStorage = await getTestStorage(factory, replicationStream);
758
759
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
759
760
 
760
761
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
@@ -826,7 +827,7 @@ streams:
826
827
  }
827
828
  )
828
829
  );
829
- const bucketStorage = factory.getInstance(replicationStream);
830
+ const bucketStorage = await getTestStorage(factory, replicationStream);
830
831
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
831
832
 
832
833
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
@@ -876,7 +877,7 @@ streams:
876
877
  WHERE a.x = x.value AND y.value = auth.user_id()
877
878
  `)
878
879
  );
879
- const bucketStorage = factory.getInstance(replicationStream);
880
+ const bucketStorage = await getTestStorage(factory, replicationStream);
880
881
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
881
882
 
882
883
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
@@ -1005,7 +1006,7 @@ streams:
1005
1006
  query: SELECT * FROM b WHERE p IN (SELECT id FROM param_b WHERE u = auth.user_id())
1006
1007
  `)
1007
1008
  );
1008
- const bucketStorage = factory.getInstance(replicationStream);
1009
+ const bucketStorage = await getTestStorage(factory, replicationStream);
1009
1010
  const parsedSyncRules = syncRules.parsed(test_utils.PARSE_OPTIONS);
1010
1011
  const hydrationState = parsedSyncRules.hydrationState;
1011
1012
  const [parsedSyncConfig] = parsedSyncRules.syncConfigs;
@@ -1106,7 +1107,7 @@ streams:
1106
1107
  }
1107
1108
  )
1108
1109
  );
1109
- const bucketStorage = factory.getInstance(replicationStream);
1110
+ const bucketStorage = await getTestStorage(factory, replicationStream);
1110
1111
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
1111
1112
 
1112
1113
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
@@ -1,23 +1,34 @@
1
1
  import { storage, updateSyncRulesFromYaml } from '@powersync/service-core';
2
2
  import { ScopedParameterLookup } from '@powersync/service-sync-rules';
3
3
  import { expect, test } from 'vitest';
4
+ import { getTestStorage } from '../test-utils/leased-storage.js';
4
5
  import * as test_utils from '../test-utils/test-utils-index.js';
5
6
  import { compactActive } from './util.js';
6
7
 
7
- export function registerParameterCompactTests(config: storage.TestStorageConfig) {
8
+ export function registerParameterCompactTests(config: storage.TestStorageConfig & { storageVersion: number }) {
8
9
  const generateStorageFactory = config.factory;
9
10
 
11
+ function parameterLookup(content: storage.PersistedSyncConfigContent, value: string) {
12
+ const parsed = content.parsed(test_utils.PARSE_OPTIONS);
13
+ const sources = [...parsed.syncConfigs[0].config.bucketParameterLookupSources];
14
+ expect(sources).toHaveLength(1);
15
+ return ScopedParameterLookup.direct(parsed.hydrationState.getParameterIndexLookupScope(sources[0]), [value]);
16
+ }
17
+
10
18
  test('compacting parameters', async () => {
11
19
  await using factory = await generateStorageFactory();
12
20
  const syncRules = await factory.updateSyncRules(
13
- updateSyncRulesFromYaml(`
21
+ updateSyncRulesFromYaml(
22
+ `
14
23
  bucket_definitions:
15
24
  test:
16
25
  parameters: select id from test where id = request.user_id()
17
26
  data: []
18
- `)
27
+ `,
28
+ { storageVersion: config.storageVersion }
29
+ )
19
30
  );
20
- const bucketStorage = factory.getInstance(syncRules);
31
+ const bucketStorage = await getTestStorage(factory, syncRules);
21
32
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
22
33
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
23
34
 
@@ -42,7 +53,7 @@ bucket_definitions:
42
53
 
43
54
  await writer.commit('1/1');
44
55
 
45
- const lookup = ScopedParameterLookup.direct({ lookupName: 'test', queryId: '1', source: null as any }, ['t1']);
56
+ const lookup = parameterLookup(syncRules.syncConfigContent[0], 't1');
46
57
 
47
58
  const checkpoint1 = await bucketStorage.getCheckpoint();
48
59
  const parameters1 = await checkpoint1.getParameterSets([lookup], 1000);
@@ -92,14 +103,17 @@ bucket_definitions:
92
103
  test(`compacting deleted parameters with cache size ${cacheLimit}`, async () => {
93
104
  await using factory = await generateStorageFactory();
94
105
  const syncRules = await factory.updateSyncRules(
95
- updateSyncRulesFromYaml(`
106
+ updateSyncRulesFromYaml(
107
+ `
96
108
  bucket_definitions:
97
109
  test:
98
110
  parameters: select id from test where uid = request.user_id()
99
111
  data: []
100
- `)
112
+ `,
113
+ { storageVersion: config.storageVersion }
114
+ )
101
115
  );
102
- const bucketStorage = factory.getInstance(syncRules);
116
+ const bucketStorage = await getTestStorage(factory, syncRules);
103
117
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
104
118
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
105
119
 
@@ -148,7 +162,7 @@ bucket_definitions:
148
162
  });
149
163
  await writer.commit('3/1');
150
164
 
151
- const lookup = ScopedParameterLookup.direct({ lookupName: 'test', queryId: '1', source: null as any }, ['u1']);
165
+ const lookup = parameterLookup(syncRules.syncConfigContent[0], 'u1');
152
166
 
153
167
  const checkpoint1 = await bucketStorage.getCheckpoint();
154
168
  const parameters1 = await checkpoint1.getParameterSets([lookup], 1000);
@@ -13,6 +13,7 @@ import path from 'path';
13
13
  import * as timers from 'timers/promises';
14
14
  import { fileURLToPath } from 'url';
15
15
  import { expect, test, vi } from 'vitest';
16
+ import { getTestStorage } from '../test-utils/leased-storage.js';
16
17
  import * as test_utils from '../test-utils/test-utils-index.js';
17
18
  import { bucketRequest, METRICS_HELPER } from '../test-utils/test-utils-index.js';
18
19
  import { compactActive } from './util.js';
@@ -70,7 +71,7 @@ export function registerSyncTests(
70
71
  content: BASIC_SYNC_RULES
71
72
  });
72
73
 
73
- const bucketStorage = f.getInstance(syncRules);
74
+ const bucketStorage = await getTestStorage(f, syncRules);
74
75
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
75
76
  const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
76
77
 
@@ -133,7 +134,7 @@ bucket_definitions:
133
134
  `
134
135
  });
135
136
 
136
- const bucketStorage = f.getInstance(syncRules);
137
+ const bucketStorage = await getTestStorage(f, syncRules);
137
138
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
138
139
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
139
140
 
@@ -192,7 +193,7 @@ streams:
192
193
  `
193
194
  });
194
195
 
195
- const bucketStorage = f.getInstance(syncRules);
196
+ const bucketStorage = await getTestStorage(f, syncRules);
196
197
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
197
198
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
198
199
 
@@ -273,7 +274,7 @@ bucket_definitions:
273
274
  `
274
275
  });
275
276
 
276
- const bucketStorage = f.getInstance(syncRules);
277
+ const bucketStorage = await getTestStorage(f, syncRules);
277
278
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
278
279
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
279
280
  const syncRulesContent = syncRules.syncConfigContent[0];
@@ -451,7 +452,7 @@ bucket_definitions:
451
452
  `
452
453
  });
453
454
 
454
- const bucketStorage = f.getInstance(syncRules);
455
+ const bucketStorage = await getTestStorage(f, syncRules);
455
456
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
456
457
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
457
458
 
@@ -585,7 +586,7 @@ bucket_definitions:
585
586
  `
586
587
  });
587
588
 
588
- const bucketStorage = f.getInstance(syncRules);
589
+ const bucketStorage = await getTestStorage(f, syncRules);
589
590
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
590
591
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
591
592
  const syncRulesContent = syncRules.syncConfigContent[0];
@@ -761,7 +762,7 @@ bucket_definitions:
761
762
  const syncRules = await updateSyncRules(f, {
762
763
  content: BASIC_SYNC_RULES
763
764
  });
764
- const bucketStorage = f.getInstance(syncRules);
765
+ const bucketStorage = await getTestStorage(f, syncRules);
765
766
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
766
767
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
767
768
 
@@ -824,7 +825,7 @@ bucket_definitions:
824
825
  content: BASIC_SYNC_RULES
825
826
  });
826
827
 
827
- const bucketStorage = await f.getInstance(syncRules);
828
+ const bucketStorage = await await getTestStorage(f, syncRules);
828
829
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
829
830
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
830
831
 
@@ -869,7 +870,7 @@ bucket_definitions:
869
870
  content: BASIC_SYNC_RULES
870
871
  });
871
872
 
872
- const bucketStorage = await f.getInstance(syncRules);
873
+ const bucketStorage = await await getTestStorage(f, syncRules);
873
874
 
874
875
  const stream = sync.streamResponse({
875
876
  syncContext,
@@ -896,7 +897,7 @@ bucket_definitions:
896
897
  content: BASIC_SYNC_RULES
897
898
  });
898
899
 
899
- const bucketStorage = await f.getInstance(syncRules);
900
+ const bucketStorage = await await getTestStorage(f, syncRules);
900
901
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
901
902
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
902
903
  // Activate
@@ -964,7 +965,7 @@ bucket_definitions:
964
965
  `
965
966
  });
966
967
 
967
- const bucketStorage = await f.getInstance(syncRules);
968
+ const bucketStorage = await await getTestStorage(f, syncRules);
968
969
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
969
970
  const usersTable = await test_utils.resolveTestTable(writer, 'users', ['id'], config, 1);
970
971
 
@@ -1030,7 +1031,7 @@ bucket_definitions:
1030
1031
  `
1031
1032
  });
1032
1033
 
1033
- const bucketStorage = await f.getInstance(syncRules);
1034
+ const bucketStorage = await await getTestStorage(f, syncRules);
1034
1035
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1035
1036
  const usersTable = await test_utils.resolveTestTable(writer, 'users', ['id'], config, 1);
1036
1037
  const listsTable = await test_utils.resolveTestTable(writer, 'lists', ['id'], config, 2);
@@ -1105,7 +1106,7 @@ bucket_definitions:
1105
1106
  `
1106
1107
  });
1107
1108
 
1108
- const bucketStorage = await f.getInstance(syncRules);
1109
+ const bucketStorage = await await getTestStorage(f, syncRules);
1109
1110
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1110
1111
  const usersTable = await test_utils.resolveTestTable(writer, 'users', ['id'], config, 1);
1111
1112
  const listsTable = await test_utils.resolveTestTable(writer, 'lists', ['id'], config, 2);
@@ -1175,7 +1176,7 @@ bucket_definitions:
1175
1176
  content: BASIC_SYNC_RULES
1176
1177
  });
1177
1178
 
1178
- const bucketStorage = await f.getInstance(syncRules);
1179
+ const bucketStorage = await await getTestStorage(f, syncRules);
1179
1180
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1180
1181
  // Activate
1181
1182
  await writer.markAllSnapshotDone('0/0');
@@ -1215,7 +1216,7 @@ bucket_definitions:
1215
1216
  content: BASIC_SYNC_RULES
1216
1217
  });
1217
1218
 
1218
- const bucketStorage = await f.getInstance(syncRules);
1219
+ const bucketStorage = await await getTestStorage(f, syncRules);
1219
1220
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1220
1221
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
1221
1222
 
@@ -1306,7 +1307,7 @@ bucket_definitions:
1306
1307
  content: BASIC_SYNC_RULES
1307
1308
  });
1308
1309
 
1309
- const bucketStorage = await f.getInstance(syncRules);
1310
+ const bucketStorage = await await getTestStorage(f, syncRules);
1310
1311
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1311
1312
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
1312
1313
  const bucket = bucketRequest(syncRules.syncConfigContent[0], 'mybucket[]').bucket;
@@ -1466,7 +1467,7 @@ bucket_definitions:
1466
1467
  `
1467
1468
  });
1468
1469
 
1469
- const bucketStorage = await f.getInstance(syncRules);
1470
+ const bucketStorage = await await getTestStorage(f, syncRules);
1470
1471
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1471
1472
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
1472
1473
  const highPriorityBucket = bucketRequest(syncRules.syncConfigContent[0], 'high_priority[]').bucket;
@@ -1593,7 +1594,7 @@ bucket_definitions:
1593
1594
  content: BASIC_SYNC_RULES
1594
1595
  });
1595
1596
 
1596
- const bucketStorage = f.getInstance(syncRules);
1597
+ const bucketStorage = await getTestStorage(f, syncRules);
1597
1598
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1598
1599
 
1599
1600
  await writer.markAllSnapshotDone('0/1');
@@ -1679,7 +1680,7 @@ config:
1679
1680
  const syncRules = await updateSyncRules(f, {
1680
1681
  content: rules[i]
1681
1682
  });
1682
- const bucketStorage = f.getInstance(syncRules);
1683
+ const bucketStorage = await getTestStorage(f, syncRules);
1683
1684
  await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
1684
1685
 
1685
1686
  const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config, i + 1);