@powersync/service-core-tests 0.13.1 → 0.14.0

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 (30) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/test-utils/general-utils.d.ts +0 -1
  3. package/dist/test-utils/general-utils.js +0 -24
  4. package/dist/test-utils/general-utils.js.map +1 -1
  5. package/dist/tests/register-compacting-tests.js +40 -51
  6. package/dist/tests/register-compacting-tests.js.map +1 -1
  7. package/dist/tests/register-data-storage-checkpoint-tests.js +11 -26
  8. package/dist/tests/register-data-storage-checkpoint-tests.js.map +1 -1
  9. package/dist/tests/register-data-storage-data-tests.js +80 -96
  10. package/dist/tests/register-data-storage-data-tests.js.map +1 -1
  11. package/dist/tests/register-data-storage-parameter-tests.js +84 -46
  12. package/dist/tests/register-data-storage-parameter-tests.js.map +1 -1
  13. package/dist/tests/register-parameter-compacting-tests.js +5 -9
  14. package/dist/tests/register-parameter-compacting-tests.js.map +1 -1
  15. package/dist/tests/register-sync-tests.d.ts +3 -1
  16. package/dist/tests/register-sync-tests.js +29 -22
  17. package/dist/tests/register-sync-tests.js.map +1 -1
  18. package/dist/tests/util.d.ts +5 -1
  19. package/dist/tests/util.js +14 -0
  20. package/dist/tests/util.js.map +1 -1
  21. package/package.json +4 -4
  22. package/src/test-utils/general-utils.ts +1 -25
  23. package/src/tests/register-compacting-tests.ts +56 -51
  24. package/src/tests/register-data-storage-checkpoint-tests.ts +21 -26
  25. package/src/tests/register-data-storage-data-tests.ts +135 -101
  26. package/src/tests/register-data-storage-parameter-tests.ts +102 -47
  27. package/src/tests/register-parameter-compacting-tests.ts +9 -9
  28. package/src/tests/register-sync-tests.ts +32 -22
  29. package/src/tests/util.ts +21 -0
  30. package/tsconfig.tsbuildinfo +1 -1
@@ -1,7 +1,13 @@
1
- import { BucketDataBatchOptions, getUuidReplicaIdentityBson, OplogEntry, storage } from '@powersync/service-core';
1
+ import {
2
+ BucketDataBatchOptions,
3
+ getUuidReplicaIdentityBson,
4
+ OplogEntry,
5
+ storage,
6
+ updateSyncRulesFromYaml
7
+ } from '@powersync/service-core';
2
8
  import { describe, expect, test } from 'vitest';
3
9
  import * as test_utils from '../test-utils/test-utils-index.js';
4
- import { TEST_TABLE } from './util.js';
10
+ import { bucketRequest, bucketRequestMap, bucketRequests, TEST_TABLE } from './util.js';
5
11
 
6
12
  /**
7
13
  * Normalize data from OplogEntries for comparison in tests.
@@ -27,14 +33,14 @@ const normalizeOplogData = (data: OplogEntry['data']) => {
27
33
  export function registerDataStorageDataTests(generateStorageFactory: storage.TestStorageFactory) {
28
34
  test('removing row', async () => {
29
35
  await using factory = await generateStorageFactory();
30
- const syncRules = await factory.updateSyncRules({
31
- content: `
36
+ const syncRules = await factory.updateSyncRules(
37
+ updateSyncRulesFromYaml(`
32
38
  bucket_definitions:
33
39
  global:
34
40
  data:
35
41
  - SELECT id, description FROM "%"
36
- `
37
- });
42
+ `)
43
+ );
38
44
  const bucketStorage = factory.getInstance(syncRules);
39
45
 
40
46
  await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
@@ -59,7 +65,9 @@ bucket_definitions:
59
65
 
60
66
  const { checkpoint } = await bucketStorage.getCheckpoint();
61
67
 
62
- const batch = await test_utils.fromAsync(bucketStorage.getBucketDataBatch(checkpoint, new Map([['global[]', 0n]])));
68
+ const batch = await test_utils.fromAsync(
69
+ bucketStorage.getBucketDataBatch(checkpoint, bucketRequestMap(syncRules, [['global[]', 0n]]))
70
+ );
63
71
  const data = batch[0].chunkData.data.map((d) => {
64
72
  return {
65
73
  op: d.op,
@@ -76,10 +84,12 @@ bucket_definitions:
76
84
  { op: 'REMOVE', object_id: 'test1', checksum: c2 }
77
85
  ]);
78
86
 
79
- const checksums = [...(await bucketStorage.getChecksums(checkpoint, ['global[]'])).values()];
87
+ const checksums = [
88
+ ...(await bucketStorage.getChecksums(checkpoint, bucketRequests(syncRules, ['global[]']))).values()
89
+ ];
80
90
  expect(checksums).toEqual([
81
91
  {
82
- bucket: 'global[]',
92
+ bucket: bucketRequest(syncRules, 'global[]'),
83
93
  checksum: (c1 + c2) & 0xffffffff,
84
94
  count: 2
85
95
  }
@@ -88,14 +98,14 @@ bucket_definitions:
88
98
 
89
99
  test('changing client ids', async () => {
90
100
  await using factory = await generateStorageFactory();
91
- const syncRules = await factory.updateSyncRules({
92
- content: `
101
+ const syncRules = await factory.updateSyncRules(
102
+ updateSyncRulesFromYaml(`
93
103
  bucket_definitions:
94
104
  global:
95
105
  data:
96
106
  - SELECT client_id as id, description FROM "%"
97
- `
98
- });
107
+ `)
108
+ );
99
109
  const bucketStorage = factory.getInstance(syncRules);
100
110
 
101
111
  const sourceTable = TEST_TABLE;
@@ -135,7 +145,9 @@ bucket_definitions:
135
145
  await batch.commit('1/1');
136
146
  });
137
147
  const { checkpoint } = await bucketStorage.getCheckpoint();
138
- const batch = await test_utils.fromAsync(bucketStorage.getBucketDataBatch(checkpoint, new Map([['global[]', 0n]])));
148
+ const batch = await test_utils.fromAsync(
149
+ bucketStorage.getBucketDataBatch(checkpoint, bucketRequestMap(syncRules, [['global[]', 0n]]))
150
+ );
139
151
  const data = batch[0].chunkData.data.map((d) => {
140
152
  return {
141
153
  op: d.op,
@@ -153,14 +165,14 @@ bucket_definitions:
153
165
 
154
166
  test('re-apply delete', async () => {
155
167
  await using factory = await generateStorageFactory();
156
- const syncRules = await factory.updateSyncRules({
157
- content: `
168
+ const syncRules = await factory.updateSyncRules(
169
+ updateSyncRulesFromYaml(`
158
170
  bucket_definitions:
159
171
  global:
160
172
  data:
161
173
  - SELECT id, description FROM "%"
162
- `
163
- });
174
+ `)
175
+ );
164
176
  const bucketStorage = factory.getInstance(syncRules);
165
177
 
166
178
  await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
@@ -201,7 +213,9 @@ bucket_definitions:
201
213
 
202
214
  const { checkpoint } = await bucketStorage.getCheckpoint();
203
215
 
204
- const batch = await test_utils.fromAsync(bucketStorage.getBucketDataBatch(checkpoint, new Map([['global[]', 0n]])));
216
+ const batch = await test_utils.fromAsync(
217
+ bucketStorage.getBucketDataBatch(checkpoint, bucketRequestMap(syncRules, [['global[]', 0n]]))
218
+ );
205
219
  const data = batch[0].chunkData.data.map((d) => {
206
220
  return {
207
221
  op: d.op,
@@ -218,10 +232,12 @@ bucket_definitions:
218
232
  { op: 'REMOVE', object_id: 'test1', checksum: c2 }
219
233
  ]);
220
234
 
221
- const checksums = [...(await bucketStorage.getChecksums(checkpoint, ['global[]'])).values()];
235
+ const checksums = [
236
+ ...(await bucketStorage.getChecksums(checkpoint, bucketRequests(syncRules, ['global[]']))).values()
237
+ ];
222
238
  expect(checksums).toEqual([
223
239
  {
224
- bucket: 'global[]',
240
+ bucket: bucketRequest(syncRules, 'global[]'),
225
241
  checksum: (c1 + c2) & 0xffffffff,
226
242
  count: 2
227
243
  }
@@ -230,14 +246,14 @@ bucket_definitions:
230
246
 
231
247
  test('re-apply update + delete', async () => {
232
248
  await using factory = await generateStorageFactory();
233
- const syncRules = await factory.updateSyncRules({
234
- content: `
249
+ const syncRules = await factory.updateSyncRules(
250
+ updateSyncRulesFromYaml(`
235
251
  bucket_definitions:
236
252
  global:
237
253
  data:
238
254
  - SELECT id, description FROM "%"
239
- `
240
- });
255
+ `)
256
+ );
241
257
  const bucketStorage = factory.getInstance(syncRules);
242
258
 
243
259
  await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
@@ -320,7 +336,9 @@ bucket_definitions:
320
336
 
321
337
  const { checkpoint } = await bucketStorage.getCheckpoint();
322
338
 
323
- const batch = await test_utils.fromAsync(bucketStorage.getBucketDataBatch(checkpoint, new Map([['global[]', 0n]])));
339
+ const batch = await test_utils.fromAsync(
340
+ bucketStorage.getBucketDataBatch(checkpoint, bucketRequestMap(syncRules, [['global[]', 0n]]))
341
+ );
324
342
 
325
343
  const data = batch[0].chunkData.data.map((d) => {
326
344
  return {
@@ -340,10 +358,12 @@ bucket_definitions:
340
358
  { op: 'REMOVE', object_id: 'test1', checksum: c2 }
341
359
  ]);
342
360
 
343
- const checksums = [...(await bucketStorage.getChecksums(checkpoint, ['global[]'])).values()];
361
+ const checksums = [
362
+ ...(await bucketStorage.getChecksums(checkpoint, bucketRequests(syncRules, ['global[]']))).values()
363
+ ];
344
364
  expect(checksums).toEqual([
345
365
  {
346
- bucket: 'global[]',
366
+ bucket: bucketRequest(syncRules, 'global[]'),
347
367
  checksum: (c1 + c1 + c1 + c2) & 0xffffffff,
348
368
  count: 4
349
369
  }
@@ -360,14 +380,14 @@ bucket_definitions:
360
380
  // 2. Output order not being correct.
361
381
 
362
382
  await using factory = await generateStorageFactory();
363
- const syncRules = await factory.updateSyncRules({
364
- content: `
383
+ const syncRules = await factory.updateSyncRules(
384
+ updateSyncRulesFromYaml(`
365
385
  bucket_definitions:
366
386
  global:
367
387
  data:
368
388
  - SELECT id, description FROM "test"
369
- `
370
- });
389
+ `)
390
+ );
371
391
  const bucketStorage = factory.getInstance(syncRules);
372
392
 
373
393
  // Pre-setup
@@ -480,7 +500,7 @@ bucket_definitions:
480
500
  const checkpoint2 = result2!.flushed_op;
481
501
 
482
502
  const batch = await test_utils.fromAsync(
483
- bucketStorage.getBucketDataBatch(checkpoint2, new Map([['global[]', checkpoint1]]))
503
+ bucketStorage.getBucketDataBatch(checkpoint2, bucketRequestMap(syncRules, [['global[]', checkpoint1]]))
484
504
  );
485
505
 
486
506
  const data = batch[0].chunkData.data.map((d) => {
@@ -518,14 +538,14 @@ bucket_definitions:
518
538
  ]);
519
539
  }
520
540
  await using factory = await generateStorageFactory();
521
- const syncRules = await factory.updateSyncRules({
522
- content: `
541
+ const syncRules = await factory.updateSyncRules(
542
+ updateSyncRulesFromYaml(`
523
543
  bucket_definitions:
524
544
  global:
525
545
  data:
526
546
  - SELECT id, description FROM "test"
527
- `
528
- });
547
+ `)
548
+ );
529
549
  const bucketStorage = factory.getInstance(syncRules);
530
550
 
531
551
  const sourceTable = test_utils.makeTestTable('test', ['id', 'description']);
@@ -580,7 +600,7 @@ bucket_definitions:
580
600
  const checkpoint3 = result3!.flushed_op;
581
601
 
582
602
  const batch = await test_utils.fromAsync(
583
- bucketStorage.getBucketDataBatch(checkpoint3, new Map([['global[]', checkpoint1]]))
603
+ bucketStorage.getBucketDataBatch(checkpoint3, bucketRequestMap(syncRules, [['global[]', checkpoint1]]))
584
604
  );
585
605
  const data = batch[0].chunkData.data.map((d) => {
586
606
  return {
@@ -626,14 +646,14 @@ bucket_definitions:
626
646
  }
627
647
 
628
648
  await using factory = await generateStorageFactory();
629
- const syncRules = await factory.updateSyncRules({
630
- content: `
649
+ const syncRules = await factory.updateSyncRules(
650
+ updateSyncRulesFromYaml(`
631
651
  bucket_definitions:
632
652
  global:
633
653
  data:
634
654
  - SELECT id, description FROM "test"
635
- `
636
- });
655
+ `)
656
+ );
637
657
  const bucketStorage = factory.getInstance(syncRules);
638
658
 
639
659
  const sourceTable = test_utils.makeTestTable('test', ['id', 'description']);
@@ -688,7 +708,7 @@ bucket_definitions:
688
708
  const checkpoint3 = result3!.flushed_op;
689
709
 
690
710
  const batch = await test_utils.fromAsync(
691
- bucketStorage.getBucketDataBatch(checkpoint3, new Map([['global[]', checkpoint1]]))
711
+ bucketStorage.getBucketDataBatch(checkpoint3, bucketRequestMap(syncRules, [['global[]', checkpoint1]]))
692
712
  );
693
713
  const data = batch[0].chunkData.data.map((d) => {
694
714
  return {
@@ -724,14 +744,14 @@ bucket_definitions:
724
744
  // The specific batch splits is an implementation detail of the storage driver,
725
745
  // and the test will have to updated when other implementations are added.
726
746
  await using factory = await generateStorageFactory();
727
- const syncRules = await factory.updateSyncRules({
728
- content: `
747
+ const syncRules = await factory.updateSyncRules(
748
+ updateSyncRulesFromYaml(`
729
749
  bucket_definitions:
730
750
  global:
731
751
  data:
732
752
  - SELECT id, description FROM "%"
733
- `
734
- });
753
+ `)
754
+ );
735
755
  const bucketStorage = factory.getInstance(syncRules);
736
756
 
737
757
  await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
@@ -790,7 +810,7 @@ bucket_definitions:
790
810
  };
791
811
 
792
812
  const batch1 = await test_utils.fromAsync(
793
- bucketStorage.getBucketDataBatch(checkpoint, new Map([['global[]', 0n]]), options)
813
+ bucketStorage.getBucketDataBatch(checkpoint, bucketRequestMap(syncRules, [['global[]', 0n]]), options)
794
814
  );
795
815
  expect(test_utils.getBatchData(batch1)).toEqual([
796
816
  { op_id: '1', op: 'PUT', object_id: 'test1', checksum: 2871785649 },
@@ -805,7 +825,7 @@ bucket_definitions:
805
825
  const batch2 = await test_utils.fromAsync(
806
826
  bucketStorage.getBucketDataBatch(
807
827
  checkpoint,
808
- new Map([['global[]', BigInt(batch1[0].chunkData.next_after)]]),
828
+ bucketRequestMap(syncRules, [['global[]', BigInt(batch1[0].chunkData.next_after)]]),
809
829
  options
810
830
  )
811
831
  );
@@ -822,7 +842,7 @@ bucket_definitions:
822
842
  const batch3 = await test_utils.fromAsync(
823
843
  bucketStorage.getBucketDataBatch(
824
844
  checkpoint,
825
- new Map([['global[]', BigInt(batch2[0].chunkData.next_after)]]),
845
+ bucketRequestMap(syncRules, [['global[]', BigInt(batch2[0].chunkData.next_after)]]),
826
846
  options
827
847
  )
828
848
  );
@@ -833,14 +853,14 @@ bucket_definitions:
833
853
  test('long batch', async () => {
834
854
  // Test syncing a batch of data that is limited by count.
835
855
  await using factory = await generateStorageFactory();
836
- const syncRules = await factory.updateSyncRules({
837
- content: `
856
+ const syncRules = await factory.updateSyncRules(
857
+ updateSyncRulesFromYaml(`
838
858
  bucket_definitions:
839
859
  global:
840
860
  data:
841
861
  - SELECT id, description FROM "%"
842
- `
843
- });
862
+ `)
863
+ );
844
864
  const bucketStorage = factory.getInstance(syncRules);
845
865
 
846
866
  await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
@@ -864,7 +884,7 @@ bucket_definitions:
864
884
  const { checkpoint } = await bucketStorage.getCheckpoint();
865
885
 
866
886
  const batch1 = await test_utils.oneFromAsync(
867
- bucketStorage.getBucketDataBatch(checkpoint, new Map([['global[]', 0n]]), { limit: 4 })
887
+ bucketStorage.getBucketDataBatch(checkpoint, bucketRequestMap(syncRules, [['global[]', 0n]]), { limit: 4 })
868
888
  );
869
889
 
870
890
  expect(test_utils.getBatchData(batch1)).toEqual([
@@ -881,9 +901,13 @@ bucket_definitions:
881
901
  });
882
902
 
883
903
  const batch2 = await test_utils.oneFromAsync(
884
- bucketStorage.getBucketDataBatch(checkpoint, new Map([['global[]', BigInt(batch1.chunkData.next_after)]]), {
885
- limit: 4
886
- })
904
+ bucketStorage.getBucketDataBatch(
905
+ checkpoint,
906
+ bucketRequestMap(syncRules, [['global[]', BigInt(batch1.chunkData.next_after)]]),
907
+ {
908
+ limit: 4
909
+ }
910
+ )
887
911
  );
888
912
  expect(test_utils.getBatchData(batch2)).toEqual([
889
913
  { op_id: '5', op: 'PUT', object_id: 'test5', checksum: 3686902721 },
@@ -897,9 +921,13 @@ bucket_definitions:
897
921
  });
898
922
 
899
923
  const batch3 = await test_utils.fromAsync(
900
- bucketStorage.getBucketDataBatch(checkpoint, new Map([['global[]', BigInt(batch2.chunkData.next_after)]]), {
901
- limit: 4
902
- })
924
+ bucketStorage.getBucketDataBatch(
925
+ checkpoint,
926
+ bucketRequestMap(syncRules, [['global[]', BigInt(batch2.chunkData.next_after)]]),
927
+ {
928
+ limit: 4
929
+ }
930
+ )
903
931
  );
904
932
  expect(test_utils.getBatchData(batch3)).toEqual([]);
905
933
 
@@ -909,8 +937,8 @@ bucket_definitions:
909
937
  describe('batch has_more', () => {
910
938
  const setup = async (options: BucketDataBatchOptions) => {
911
939
  await using factory = await generateStorageFactory();
912
- const syncRules = await factory.updateSyncRules({
913
- content: `
940
+ const syncRules = await factory.updateSyncRules(
941
+ updateSyncRulesFromYaml(`
914
942
  bucket_definitions:
915
943
  global1:
916
944
  data:
@@ -918,8 +946,8 @@ bucket_definitions:
918
946
  global2:
919
947
  data:
920
948
  - SELECT id, description FROM test WHERE bucket = 'global2'
921
- `
922
- });
949
+ `)
950
+ );
923
951
  const bucketStorage = factory.getInstance(syncRules);
924
952
 
925
953
  await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
@@ -942,24 +970,26 @@ bucket_definitions:
942
970
  });
943
971
 
944
972
  const { checkpoint } = await bucketStorage.getCheckpoint();
945
- return await test_utils.fromAsync(
973
+ const batch = await test_utils.fromAsync(
946
974
  bucketStorage.getBucketDataBatch(
947
975
  checkpoint,
948
- new Map([
976
+ bucketRequestMap(syncRules, [
949
977
  ['global1[]', 0n],
950
978
  ['global2[]', 0n]
951
979
  ]),
952
980
  options
953
981
  )
954
982
  );
983
+
984
+ return { syncRules, batch };
955
985
  };
956
986
 
957
987
  test('batch has_more (1)', async () => {
958
- const batch = await setup({ limit: 5 });
988
+ const { batch, syncRules } = await setup({ limit: 5 });
959
989
  expect(batch.length).toEqual(2);
960
990
 
961
- expect(batch[0].chunkData.bucket).toEqual('global1[]');
962
- expect(batch[1].chunkData.bucket).toEqual('global2[]');
991
+ expect(batch[0].chunkData.bucket).toEqual(bucketRequest(syncRules, 'global1[]'));
992
+ expect(batch[1].chunkData.bucket).toEqual(bucketRequest(syncRules, 'global2[]'));
963
993
 
964
994
  expect(test_utils.getBatchData(batch[0])).toEqual([
965
995
  { op_id: '1', op: 'PUT', object_id: 'test1', checksum: 2871785649 }
@@ -986,11 +1016,11 @@ bucket_definitions:
986
1016
  });
987
1017
 
988
1018
  test('batch has_more (2)', async () => {
989
- const batch = await setup({ limit: 11 });
1019
+ const { batch, syncRules } = await setup({ limit: 11 });
990
1020
  expect(batch.length).toEqual(2);
991
1021
 
992
- expect(batch[0].chunkData.bucket).toEqual('global1[]');
993
- expect(batch[1].chunkData.bucket).toEqual('global2[]');
1022
+ expect(batch[0].chunkData.bucket).toEqual(bucketRequest(syncRules, 'global1[]'));
1023
+ expect(batch[1].chunkData.bucket).toEqual(bucketRequest(syncRules, 'global2[]'));
994
1024
 
995
1025
  expect(test_utils.getBatchData(batch[0])).toEqual([
996
1026
  { op_id: '1', op: 'PUT', object_id: 'test1', checksum: 2871785649 }
@@ -1023,12 +1053,12 @@ bucket_definitions:
1023
1053
 
1024
1054
  test('batch has_more (3)', async () => {
1025
1055
  // 50 bytes is more than 1 row, less than 2 rows
1026
- const batch = await setup({ limit: 3, chunkLimitBytes: 50 });
1056
+ const { batch, syncRules } = await setup({ limit: 3, chunkLimitBytes: 50 });
1027
1057
 
1028
1058
  expect(batch.length).toEqual(3);
1029
- expect(batch[0].chunkData.bucket).toEqual('global1[]');
1030
- expect(batch[1].chunkData.bucket).toEqual('global2[]');
1031
- expect(batch[2].chunkData.bucket).toEqual('global2[]');
1059
+ expect(batch[0].chunkData.bucket).toEqual(bucketRequest(syncRules, 'global1[]'));
1060
+ expect(batch[1].chunkData.bucket).toEqual(bucketRequest(syncRules, 'global2[]'));
1061
+ expect(batch[2].chunkData.bucket).toEqual(bucketRequest(syncRules, 'global2[]'));
1032
1062
 
1033
1063
  expect(test_utils.getBatchData(batch[0])).toEqual([
1034
1064
  { op_id: '1', op: 'PUT', object_id: 'test1', checksum: 2871785649 }
@@ -1070,14 +1100,14 @@ bucket_definitions:
1070
1100
  replication_size_bytes: 0
1071
1101
  });
1072
1102
 
1073
- const r = await f.configureSyncRules({ content: 'bucket_definitions: {}', validate: false });
1103
+ const r = await f.configureSyncRules(updateSyncRulesFromYaml('bucket_definitions: {}'));
1074
1104
  const storage = f.getInstance(r.persisted_sync_rules!);
1075
1105
  await storage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
1076
1106
  await batch.keepalive('1/0');
1077
1107
  });
1078
1108
 
1079
- const metrics2 = await f.getStorageMetrics();
1080
- expect(metrics2).toMatchSnapshot();
1109
+ await f.getStorageMetrics();
1110
+ // We don't care about the specific values here
1081
1111
  });
1082
1112
 
1083
1113
  test('op_id initialization edge case', async () => {
@@ -1085,15 +1115,15 @@ bucket_definitions:
1085
1115
  // but large enough in size to be split over multiple returned chunks.
1086
1116
  // Similar to the above test, but splits over 1MB chunks.
1087
1117
  await using factory = await generateStorageFactory();
1088
- const syncRules = await factory.updateSyncRules({
1089
- content: `
1118
+ const syncRules = await factory.updateSyncRules(
1119
+ updateSyncRulesFromYaml(`
1090
1120
  bucket_definitions:
1091
1121
  global:
1092
1122
  data:
1093
1123
  - SELECT id FROM test
1094
1124
  - SELECT id FROM test_ignore WHERE false
1095
- `
1096
- });
1125
+ `)
1126
+ );
1097
1127
  const bucketStorage = factory.getInstance(syncRules);
1098
1128
 
1099
1129
  const sourceTable = test_utils.makeTestTable('test', ['id']);
@@ -1132,14 +1162,14 @@ bucket_definitions:
1132
1162
 
1133
1163
  test('unchanged checksums', async () => {
1134
1164
  await using factory = await generateStorageFactory();
1135
- const syncRules = await factory.updateSyncRules({
1136
- content: `
1165
+ const syncRules = await factory.updateSyncRules(
1166
+ updateSyncRulesFromYaml(`
1137
1167
  bucket_definitions:
1138
1168
  global:
1139
1169
  data:
1140
1170
  - SELECT client_id as id, description FROM "%"
1141
- `
1142
- });
1171
+ `)
1172
+ );
1143
1173
  const bucketStorage = factory.getInstance(syncRules);
1144
1174
 
1145
1175
  const sourceTable = TEST_TABLE;
@@ -1157,10 +1187,14 @@ bucket_definitions:
1157
1187
  });
1158
1188
  const { checkpoint } = await bucketStorage.getCheckpoint();
1159
1189
 
1160
- const checksums = [...(await bucketStorage.getChecksums(checkpoint, ['global[]'])).values()];
1161
- expect(checksums).toEqual([{ bucket: 'global[]', checksum: 1917136889, count: 1 }]);
1162
- const checksums2 = [...(await bucketStorage.getChecksums(checkpoint + 1n, ['global[]'])).values()];
1163
- expect(checksums2).toEqual([{ bucket: 'global[]', checksum: 1917136889, count: 1 }]);
1190
+ const checksums = [
1191
+ ...(await bucketStorage.getChecksums(checkpoint, bucketRequests(syncRules, ['global[]']))).values()
1192
+ ];
1193
+ expect(checksums).toEqual([{ bucket: bucketRequest(syncRules, 'global[]'), checksum: 1917136889, count: 1 }]);
1194
+ const checksums2 = [
1195
+ ...(await bucketStorage.getChecksums(checkpoint + 1n, bucketRequests(syncRules, ['global[]']))).values()
1196
+ ];
1197
+ expect(checksums2).toEqual([{ bucket: bucketRequest(syncRules, 'global[]'), checksum: 1917136889, count: 1 }]);
1164
1198
  });
1165
1199
 
1166
1200
  testChecksumBatching(generateStorageFactory);
@@ -1174,15 +1208,15 @@ bucket_definitions:
1174
1208
  export function testChecksumBatching(generateStorageFactory: storage.TestStorageFactory) {
1175
1209
  test('checksums for multiple buckets', async () => {
1176
1210
  await using factory = await generateStorageFactory();
1177
- const syncRules = await factory.updateSyncRules({
1178
- content: `
1211
+ const syncRules = await factory.updateSyncRules(
1212
+ updateSyncRulesFromYaml(`
1179
1213
  bucket_definitions:
1180
1214
  user:
1181
1215
  parameters: select request.user_id() as user_id
1182
1216
  data:
1183
1217
  - select id, description from test where user_id = bucket.user_id
1184
- `
1185
- });
1218
+ `)
1219
+ );
1186
1220
  const bucketStorage = factory.getInstance(syncRules);
1187
1221
 
1188
1222
  const sourceTable = TEST_TABLE;
@@ -1207,14 +1241,14 @@ bucket_definitions:
1207
1241
  const { checkpoint } = await bucketStorage.getCheckpoint();
1208
1242
 
1209
1243
  bucketStorage.clearChecksumCache();
1210
- const buckets = ['user["u1"]', 'user["u2"]', 'user["u3"]', 'user["u4"]'];
1244
+ const buckets = bucketRequests(syncRules, ['user["u1"]', 'user["u2"]', 'user["u3"]', 'user["u4"]']);
1211
1245
  const checksums = [...(await bucketStorage.getChecksums(checkpoint, buckets)).values()];
1212
1246
  checksums.sort((a, b) => a.bucket.localeCompare(b.bucket));
1213
1247
  expect(checksums).toEqual([
1214
- { bucket: 'user["u1"]', count: 4, checksum: 346204588 },
1215
- { bucket: 'user["u2"]', count: 4, checksum: 5261081 },
1216
- { bucket: 'user["u3"]', count: 4, checksum: 134760718 },
1217
- { bucket: 'user["u4"]', count: 4, checksum: -302639724 }
1248
+ { bucket: bucketRequest(syncRules, 'user["u1"]'), count: 4, checksum: 346204588 },
1249
+ { bucket: bucketRequest(syncRules, 'user["u2"]'), count: 4, checksum: 5261081 },
1250
+ { bucket: bucketRequest(syncRules, 'user["u3"]'), count: 4, checksum: 134760718 },
1251
+ { bucket: bucketRequest(syncRules, 'user["u4"]'), count: 4, checksum: -302639724 }
1218
1252
  ]);
1219
1253
  });
1220
1254
  }