@powersync/service-core-tests 0.14.0 → 0.15.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.
- package/CHANGELOG.md +19 -0
- package/dist/test-utils/general-utils.d.ts +9 -2
- package/dist/test-utils/general-utils.js +26 -2
- package/dist/test-utils/general-utils.js.map +1 -1
- package/dist/tests/register-compacting-tests.d.ts +1 -1
- package/dist/tests/register-compacting-tests.js +122 -68
- package/dist/tests/register-compacting-tests.js.map +1 -1
- package/dist/tests/register-data-storage-checkpoint-tests.d.ts +1 -1
- package/dist/tests/register-data-storage-checkpoint-tests.js +38 -6
- package/dist/tests/register-data-storage-checkpoint-tests.js.map +1 -1
- package/dist/tests/register-data-storage-data-tests.d.ts +2 -2
- package/dist/tests/register-data-storage-data-tests.js +666 -142
- package/dist/tests/register-data-storage-data-tests.js.map +1 -1
- package/dist/tests/register-data-storage-parameter-tests.d.ts +1 -1
- package/dist/tests/register-data-storage-parameter-tests.js +60 -33
- package/dist/tests/register-data-storage-parameter-tests.js.map +1 -1
- package/dist/tests/register-parameter-compacting-tests.d.ts +1 -1
- package/dist/tests/register-parameter-compacting-tests.js +8 -4
- package/dist/tests/register-parameter-compacting-tests.js.map +1 -1
- package/dist/tests/register-sync-tests.d.ts +2 -1
- package/dist/tests/register-sync-tests.js +40 -18
- package/dist/tests/register-sync-tests.js.map +1 -1
- package/dist/tests/util.d.ts +5 -4
- package/dist/tests/util.js +27 -12
- package/dist/tests/util.js.map +1 -1
- package/package.json +3 -3
- package/src/test-utils/general-utils.ts +41 -3
- package/src/tests/register-compacting-tests.ts +127 -82
- package/src/tests/register-data-storage-checkpoint-tests.ts +64 -11
- package/src/tests/register-data-storage-data-tests.ts +640 -52
- package/src/tests/register-data-storage-parameter-tests.ts +101 -47
- package/src/tests/register-parameter-compacting-tests.ts +9 -4
- package/src/tests/register-sync-tests.ts +45 -19
- package/src/tests/util.ts +46 -17
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { JwtPayload, storage, updateSyncRulesFromYaml } from '@powersync/service-core';
|
|
1
|
+
import { CURRENT_STORAGE_VERSION, JwtPayload, storage, updateSyncRulesFromYaml } from '@powersync/service-core';
|
|
2
2
|
import { RequestParameters, ScopedParameterLookup, SqliteJsonRow } from '@powersync/service-sync-rules';
|
|
3
3
|
import { expect, test } from 'vitest';
|
|
4
4
|
import * as test_utils from '../test-utils/test-utils-index.js';
|
|
5
|
-
import { bucketRequest
|
|
6
|
-
import {
|
|
5
|
+
import { bucketRequest } from '../test-utils/test-utils-index.js';
|
|
6
|
+
import { parameterLookupScope } from './util.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @example
|
|
@@ -15,23 +15,33 @@ import { ParameterLookupScope } from '@powersync/service-sync-rules';
|
|
|
15
15
|
*
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
export function registerDataStorageParameterTests(
|
|
19
|
-
const
|
|
18
|
+
export function registerDataStorageParameterTests(config: storage.TestStorageConfig) {
|
|
19
|
+
const generateStorageFactory = config.factory;
|
|
20
|
+
const storageVersion = config.storageVersion ?? CURRENT_STORAGE_VERSION;
|
|
21
|
+
const TEST_TABLE = test_utils.makeTestTable('test', ['id'], config);
|
|
22
|
+
const MYBUCKET_1 = parameterLookupScope('mybucket', '1');
|
|
20
23
|
|
|
21
24
|
test('save and load parameters', async () => {
|
|
22
25
|
await using factory = await generateStorageFactory();
|
|
23
26
|
const syncRules = await factory.updateSyncRules(
|
|
24
|
-
updateSyncRulesFromYaml(
|
|
27
|
+
updateSyncRulesFromYaml(
|
|
28
|
+
`
|
|
25
29
|
bucket_definitions:
|
|
26
30
|
mybucket:
|
|
27
31
|
parameters:
|
|
28
32
|
- SELECT group_id FROM test WHERE id1 = token_parameters.user_id OR id2 = token_parameters.user_id
|
|
29
33
|
data: []
|
|
30
|
-
|
|
34
|
+
`,
|
|
35
|
+
{
|
|
36
|
+
storageVersion
|
|
37
|
+
}
|
|
38
|
+
)
|
|
31
39
|
);
|
|
32
40
|
const bucketStorage = factory.getInstance(syncRules);
|
|
33
41
|
|
|
34
42
|
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|
|
43
|
+
await batch.markAllSnapshotDone('1/1');
|
|
44
|
+
|
|
35
45
|
await batch.save({
|
|
36
46
|
sourceTable: TEST_TABLE,
|
|
37
47
|
tag: storage.SaveOperationTag.INSERT,
|
|
@@ -71,17 +81,23 @@ bucket_definitions:
|
|
|
71
81
|
test('it should use the latest version', async () => {
|
|
72
82
|
await using factory = await generateStorageFactory();
|
|
73
83
|
const syncRules = await factory.updateSyncRules(
|
|
74
|
-
updateSyncRulesFromYaml(
|
|
84
|
+
updateSyncRulesFromYaml(
|
|
85
|
+
`
|
|
75
86
|
bucket_definitions:
|
|
76
87
|
mybucket:
|
|
77
88
|
parameters:
|
|
78
89
|
- SELECT group_id FROM test WHERE id = token_parameters.user_id
|
|
79
90
|
data: []
|
|
80
|
-
|
|
91
|
+
`,
|
|
92
|
+
{
|
|
93
|
+
storageVersion
|
|
94
|
+
}
|
|
95
|
+
)
|
|
81
96
|
);
|
|
82
97
|
const bucketStorage = factory.getInstance(syncRules);
|
|
83
98
|
|
|
84
99
|
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|
|
100
|
+
await batch.markAllSnapshotDone('1/1');
|
|
85
101
|
await batch.save({
|
|
86
102
|
sourceTable: TEST_TABLE,
|
|
87
103
|
tag: storage.SaveOperationTag.INSERT,
|
|
@@ -127,7 +143,8 @@ bucket_definitions:
|
|
|
127
143
|
test('it should use the latest version after updates', async () => {
|
|
128
144
|
await using factory = await generateStorageFactory();
|
|
129
145
|
const syncRules = await factory.updateSyncRules(
|
|
130
|
-
updateSyncRulesFromYaml(
|
|
146
|
+
updateSyncRulesFromYaml(
|
|
147
|
+
`
|
|
131
148
|
bucket_definitions:
|
|
132
149
|
mybucket:
|
|
133
150
|
parameters:
|
|
@@ -135,13 +152,16 @@ bucket_definitions:
|
|
|
135
152
|
FROM todos
|
|
136
153
|
WHERE list_id IN token_parameters.list_id
|
|
137
154
|
data: []
|
|
138
|
-
|
|
155
|
+
`,
|
|
156
|
+
{ storageVersion }
|
|
157
|
+
)
|
|
139
158
|
);
|
|
140
159
|
const bucketStorage = factory.getInstance(syncRules);
|
|
141
160
|
|
|
142
|
-
const table = test_utils.makeTestTable('todos', ['id', 'list_id']);
|
|
161
|
+
const table = test_utils.makeTestTable('todos', ['id', 'list_id'], config);
|
|
143
162
|
|
|
144
163
|
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|
|
164
|
+
await batch.markAllSnapshotDone('1/1');
|
|
145
165
|
// Create two todos which initially belong to different lists
|
|
146
166
|
await batch.save({
|
|
147
167
|
sourceTable: table,
|
|
@@ -202,17 +222,23 @@ bucket_definitions:
|
|
|
202
222
|
test('save and load parameters with different number types', async () => {
|
|
203
223
|
await using factory = await generateStorageFactory();
|
|
204
224
|
const syncRules = await factory.updateSyncRules(
|
|
205
|
-
updateSyncRulesFromYaml(
|
|
225
|
+
updateSyncRulesFromYaml(
|
|
226
|
+
`
|
|
206
227
|
bucket_definitions:
|
|
207
228
|
mybucket:
|
|
208
229
|
parameters:
|
|
209
230
|
- SELECT group_id FROM test WHERE n1 = token_parameters.n1 and f2 = token_parameters.f2 and f3 = token_parameters.f3
|
|
210
231
|
data: []
|
|
211
|
-
|
|
232
|
+
`,
|
|
233
|
+
{
|
|
234
|
+
storageVersion
|
|
235
|
+
}
|
|
236
|
+
)
|
|
212
237
|
);
|
|
213
238
|
const bucketStorage = factory.getInstance(syncRules);
|
|
214
239
|
|
|
215
240
|
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|
|
241
|
+
await batch.markAllSnapshotDone('1/1');
|
|
216
242
|
await batch.save({
|
|
217
243
|
sourceTable: TEST_TABLE,
|
|
218
244
|
tag: storage.SaveOperationTag.INSERT,
|
|
@@ -252,17 +278,23 @@ bucket_definitions:
|
|
|
252
278
|
|
|
253
279
|
await using factory = await generateStorageFactory();
|
|
254
280
|
const syncRules = await factory.updateSyncRules(
|
|
255
|
-
updateSyncRulesFromYaml(
|
|
281
|
+
updateSyncRulesFromYaml(
|
|
282
|
+
`
|
|
256
283
|
bucket_definitions:
|
|
257
284
|
mybucket:
|
|
258
285
|
parameters:
|
|
259
286
|
- SELECT group_id FROM test WHERE n1 = token_parameters.n1
|
|
260
287
|
data: []
|
|
261
|
-
|
|
288
|
+
`,
|
|
289
|
+
{
|
|
290
|
+
storageVersion
|
|
291
|
+
}
|
|
292
|
+
)
|
|
262
293
|
);
|
|
263
294
|
const bucketStorage = factory.getInstance(syncRules);
|
|
264
295
|
|
|
265
296
|
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|
|
297
|
+
await batch.markAllSnapshotDone('1/1');
|
|
266
298
|
await batch.save({
|
|
267
299
|
sourceTable: TEST_TABLE,
|
|
268
300
|
tag: storage.SaveOperationTag.INSERT,
|
|
@@ -301,23 +333,29 @@ bucket_definitions:
|
|
|
301
333
|
});
|
|
302
334
|
|
|
303
335
|
test('save and load parameters with workspaceId', async () => {
|
|
304
|
-
const WORKSPACE_TABLE = test_utils.makeTestTable('workspace', ['id']);
|
|
336
|
+
const WORKSPACE_TABLE = test_utils.makeTestTable('workspace', ['id'], config);
|
|
305
337
|
|
|
306
338
|
await using factory = await generateStorageFactory();
|
|
307
339
|
const syncRules = await factory.updateSyncRules(
|
|
308
|
-
updateSyncRulesFromYaml(
|
|
340
|
+
updateSyncRulesFromYaml(
|
|
341
|
+
`
|
|
309
342
|
bucket_definitions:
|
|
310
343
|
by_workspace:
|
|
311
344
|
parameters:
|
|
312
345
|
- SELECT id as workspace_id FROM workspace WHERE
|
|
313
346
|
workspace."userId" = token_parameters.user_id
|
|
314
347
|
data: []
|
|
315
|
-
|
|
348
|
+
`,
|
|
349
|
+
{
|
|
350
|
+
storageVersion
|
|
351
|
+
}
|
|
352
|
+
)
|
|
316
353
|
);
|
|
317
354
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncRules();
|
|
318
355
|
const bucketStorage = factory.getInstance(syncRules);
|
|
319
356
|
|
|
320
357
|
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|
|
358
|
+
await batch.markAllSnapshotDone('1/1');
|
|
321
359
|
await batch.save({
|
|
322
360
|
sourceTable: WORKSPACE_TABLE,
|
|
323
361
|
tag: storage.SaveOperationTag.INSERT,
|
|
@@ -337,7 +375,7 @@ bucket_definitions:
|
|
|
337
375
|
|
|
338
376
|
const buckets = await querier.queryDynamicBucketDescriptions({
|
|
339
377
|
async getParameterSets(lookups) {
|
|
340
|
-
expect(lookups).toEqual([ScopedParameterLookup.direct(
|
|
378
|
+
expect(lookups).toEqual([ScopedParameterLookup.direct(parameterLookupScope('by_workspace', '1'), ['u1'])]);
|
|
341
379
|
|
|
342
380
|
const parameter_sets = await checkpoint.getParameterSets(lookups);
|
|
343
381
|
expect(parameter_sets).toEqual([{ workspace_id: 'workspace1' }]);
|
|
@@ -346,7 +384,7 @@ bucket_definitions:
|
|
|
346
384
|
});
|
|
347
385
|
expect(buckets).toEqual([
|
|
348
386
|
{
|
|
349
|
-
bucket: bucketRequest(syncRules, 'by_workspace["workspace1"]'),
|
|
387
|
+
bucket: bucketRequest(syncRules, 'by_workspace["workspace1"]').bucket,
|
|
350
388
|
priority: 3,
|
|
351
389
|
definition: 'by_workspace',
|
|
352
390
|
inclusion_reasons: ['default']
|
|
@@ -355,23 +393,29 @@ bucket_definitions:
|
|
|
355
393
|
});
|
|
356
394
|
|
|
357
395
|
test('save and load parameters with dynamic global buckets', async () => {
|
|
358
|
-
const WORKSPACE_TABLE = test_utils.makeTestTable('workspace');
|
|
396
|
+
const WORKSPACE_TABLE = test_utils.makeTestTable('workspace', undefined, config);
|
|
359
397
|
|
|
360
398
|
await using factory = await generateStorageFactory();
|
|
361
399
|
const syncRules = await factory.updateSyncRules(
|
|
362
|
-
updateSyncRulesFromYaml(
|
|
400
|
+
updateSyncRulesFromYaml(
|
|
401
|
+
`
|
|
363
402
|
bucket_definitions:
|
|
364
403
|
by_public_workspace:
|
|
365
404
|
parameters:
|
|
366
405
|
- SELECT id as workspace_id FROM workspace WHERE
|
|
367
406
|
workspace.visibility = 'public'
|
|
368
407
|
data: []
|
|
369
|
-
|
|
408
|
+
`,
|
|
409
|
+
{
|
|
410
|
+
storageVersion
|
|
411
|
+
}
|
|
412
|
+
)
|
|
370
413
|
);
|
|
371
414
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncRules();
|
|
372
415
|
const bucketStorage = factory.getInstance(syncRules);
|
|
373
416
|
|
|
374
417
|
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|
|
418
|
+
await batch.markAllSnapshotDone('1/1');
|
|
375
419
|
await batch.save({
|
|
376
420
|
sourceTable: WORKSPACE_TABLE,
|
|
377
421
|
tag: storage.SaveOperationTag.INSERT,
|
|
@@ -413,9 +457,7 @@ bucket_definitions:
|
|
|
413
457
|
|
|
414
458
|
const buckets = await querier.queryDynamicBucketDescriptions({
|
|
415
459
|
async getParameterSets(lookups) {
|
|
416
|
-
expect(lookups).toEqual([
|
|
417
|
-
ScopedParameterLookup.direct({ lookupName: 'by_public_workspace', queryId: '1' }, [])
|
|
418
|
-
]);
|
|
460
|
+
expect(lookups).toEqual([ScopedParameterLookup.direct(parameterLookupScope('by_public_workspace', '1'), [])]);
|
|
419
461
|
|
|
420
462
|
const parameter_sets = await checkpoint.getParameterSets(lookups);
|
|
421
463
|
parameter_sets.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
|
|
@@ -426,13 +468,13 @@ bucket_definitions:
|
|
|
426
468
|
buckets.sort((a, b) => a.bucket.localeCompare(b.bucket));
|
|
427
469
|
expect(buckets).toEqual([
|
|
428
470
|
{
|
|
429
|
-
bucket: bucketRequest(syncRules, 'by_public_workspace["workspace1"]'),
|
|
471
|
+
bucket: bucketRequest(syncRules, 'by_public_workspace["workspace1"]').bucket,
|
|
430
472
|
priority: 3,
|
|
431
473
|
definition: 'by_public_workspace',
|
|
432
474
|
inclusion_reasons: ['default']
|
|
433
475
|
},
|
|
434
476
|
{
|
|
435
|
-
bucket: bucketRequest(syncRules, 'by_public_workspace["workspace3"]'),
|
|
477
|
+
bucket: bucketRequest(syncRules, 'by_public_workspace["workspace3"]').bucket,
|
|
436
478
|
priority: 3,
|
|
437
479
|
definition: 'by_public_workspace',
|
|
438
480
|
inclusion_reasons: ['default']
|
|
@@ -441,11 +483,12 @@ bucket_definitions:
|
|
|
441
483
|
});
|
|
442
484
|
|
|
443
485
|
test('multiple parameter queries', async () => {
|
|
444
|
-
const WORKSPACE_TABLE = test_utils.makeTestTable('workspace');
|
|
486
|
+
const WORKSPACE_TABLE = test_utils.makeTestTable('workspace', undefined, config);
|
|
445
487
|
|
|
446
488
|
await using factory = await generateStorageFactory();
|
|
447
489
|
const syncRules = await factory.updateSyncRules(
|
|
448
|
-
updateSyncRulesFromYaml(
|
|
490
|
+
updateSyncRulesFromYaml(
|
|
491
|
+
`
|
|
449
492
|
bucket_definitions:
|
|
450
493
|
by_workspace:
|
|
451
494
|
parameters:
|
|
@@ -454,12 +497,17 @@ bucket_definitions:
|
|
|
454
497
|
- SELECT id as workspace_id FROM workspace WHERE
|
|
455
498
|
workspace.user_id = token_parameters.user_id
|
|
456
499
|
data: []
|
|
457
|
-
|
|
500
|
+
`,
|
|
501
|
+
{
|
|
502
|
+
storageVersion
|
|
503
|
+
}
|
|
504
|
+
)
|
|
458
505
|
);
|
|
459
506
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncRules();
|
|
460
507
|
const bucketStorage = factory.getInstance(syncRules);
|
|
461
508
|
|
|
462
509
|
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|
|
510
|
+
await batch.markAllSnapshotDone('1/1');
|
|
463
511
|
await batch.save({
|
|
464
512
|
sourceTable: WORKSPACE_TABLE,
|
|
465
513
|
tag: storage.SaveOperationTag.INSERT,
|
|
@@ -526,33 +574,39 @@ bucket_definitions:
|
|
|
526
574
|
})
|
|
527
575
|
).map((e) => e.bucket);
|
|
528
576
|
expect(foundLookups).toEqual([
|
|
529
|
-
ScopedParameterLookup.direct(
|
|
530
|
-
ScopedParameterLookup.direct(
|
|
577
|
+
ScopedParameterLookup.direct(parameterLookupScope('by_workspace', '1'), []),
|
|
578
|
+
ScopedParameterLookup.direct(parameterLookupScope('by_workspace', '2'), ['u1'])
|
|
531
579
|
]);
|
|
532
580
|
parameter_sets.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
|
|
533
581
|
expect(parameter_sets).toEqual([{ workspace_id: 'workspace1' }, { workspace_id: 'workspace3' }]);
|
|
534
582
|
|
|
535
583
|
buckets.sort();
|
|
536
584
|
expect(buckets).toEqual([
|
|
537
|
-
bucketRequest(syncRules, 'by_workspace["workspace1"]'),
|
|
538
|
-
bucketRequest(syncRules, 'by_workspace["workspace3"]')
|
|
585
|
+
bucketRequest(syncRules, 'by_workspace["workspace1"]').bucket,
|
|
586
|
+
bucketRequest(syncRules, 'by_workspace["workspace3"]').bucket
|
|
539
587
|
]);
|
|
540
588
|
});
|
|
541
589
|
|
|
542
590
|
test('truncate parameters', async () => {
|
|
543
591
|
await using factory = await generateStorageFactory();
|
|
544
592
|
const syncRules = await factory.updateSyncRules(
|
|
545
|
-
updateSyncRulesFromYaml(
|
|
593
|
+
updateSyncRulesFromYaml(
|
|
594
|
+
`
|
|
546
595
|
bucket_definitions:
|
|
547
596
|
mybucket:
|
|
548
597
|
parameters:
|
|
549
598
|
- SELECT group_id FROM test WHERE id1 = token_parameters.user_id OR id2 = token_parameters.user_id
|
|
550
599
|
data: []
|
|
551
|
-
|
|
600
|
+
`,
|
|
601
|
+
{
|
|
602
|
+
storageVersion
|
|
603
|
+
}
|
|
604
|
+
)
|
|
552
605
|
);
|
|
553
606
|
const bucketStorage = factory.getInstance(syncRules);
|
|
554
607
|
|
|
555
608
|
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|
|
609
|
+
await batch.markAllSnapshotDone('1/1');
|
|
556
610
|
await batch.save({
|
|
557
611
|
sourceTable: TEST_TABLE,
|
|
558
612
|
tag: storage.SaveOperationTag.INSERT,
|
|
@@ -577,14 +631,19 @@ bucket_definitions:
|
|
|
577
631
|
test('invalidate cached parsed sync rules', async () => {
|
|
578
632
|
await using bucketStorageFactory = await generateStorageFactory();
|
|
579
633
|
const syncRules = await bucketStorageFactory.updateSyncRules(
|
|
580
|
-
updateSyncRulesFromYaml(
|
|
634
|
+
updateSyncRulesFromYaml(
|
|
635
|
+
`
|
|
581
636
|
bucket_definitions:
|
|
582
637
|
by_workspace:
|
|
583
638
|
parameters:
|
|
584
639
|
- SELECT id as workspace_id FROM workspace WHERE
|
|
585
640
|
workspace."userId" = token_parameters.user_id
|
|
586
641
|
data: []
|
|
587
|
-
|
|
642
|
+
`,
|
|
643
|
+
{
|
|
644
|
+
storageVersion
|
|
645
|
+
}
|
|
646
|
+
)
|
|
588
647
|
);
|
|
589
648
|
const syncBucketStorage = bucketStorageFactory.getInstance(syncRules);
|
|
590
649
|
|
|
@@ -626,6 +685,7 @@ streams:
|
|
|
626
685
|
const bucketStorage = factory.getInstance(syncRules);
|
|
627
686
|
|
|
628
687
|
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|
|
688
|
+
await batch.markAllSnapshotDone('1/1');
|
|
629
689
|
await batch.save({
|
|
630
690
|
sourceTable: TEST_TABLE,
|
|
631
691
|
tag: storage.SaveOperationTag.INSERT,
|
|
@@ -641,13 +701,7 @@ streams:
|
|
|
641
701
|
|
|
642
702
|
const checkpoint = await bucketStorage.getCheckpoint();
|
|
643
703
|
const parameters = await checkpoint.getParameterSets([
|
|
644
|
-
ScopedParameterLookup.direct(
|
|
645
|
-
{
|
|
646
|
-
lookupName: 'lookup',
|
|
647
|
-
queryId: '0'
|
|
648
|
-
},
|
|
649
|
-
['baz']
|
|
650
|
-
)
|
|
704
|
+
ScopedParameterLookup.direct(parameterLookupScope('lookup', '0'), ['baz'])
|
|
651
705
|
]);
|
|
652
706
|
expect(parameters).toEqual([
|
|
653
707
|
{
|
|
@@ -2,10 +2,13 @@ import { storage, updateSyncRulesFromYaml } from '@powersync/service-core';
|
|
|
2
2
|
import { ScopedParameterLookup } from '@powersync/service-sync-rules';
|
|
3
3
|
import { expect, test } from 'vitest';
|
|
4
4
|
import * as test_utils from '../test-utils/test-utils-index.js';
|
|
5
|
+
import { parameterLookupScope } from './util.js';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
export function registerParameterCompactTests(config: storage.TestStorageConfig) {
|
|
8
|
+
const generateStorageFactory = config.factory;
|
|
9
|
+
|
|
10
|
+
const TEST_TABLE = test_utils.makeTestTable('test', ['id'], config);
|
|
7
11
|
|
|
8
|
-
export function registerParameterCompactTests(generateStorageFactory: storage.TestStorageFactory) {
|
|
9
12
|
test('compacting parameters', async () => {
|
|
10
13
|
await using factory = await generateStorageFactory();
|
|
11
14
|
const syncRules = await factory.updateSyncRules(
|
|
@@ -19,6 +22,7 @@ bucket_definitions:
|
|
|
19
22
|
const bucketStorage = factory.getInstance(syncRules);
|
|
20
23
|
|
|
21
24
|
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|
|
25
|
+
await batch.markAllSnapshotDone('1/1');
|
|
22
26
|
await batch.save({
|
|
23
27
|
sourceTable: TEST_TABLE,
|
|
24
28
|
tag: storage.SaveOperationTag.INSERT,
|
|
@@ -40,7 +44,7 @@ bucket_definitions:
|
|
|
40
44
|
await batch.commit('1/1');
|
|
41
45
|
});
|
|
42
46
|
|
|
43
|
-
const lookup = ScopedParameterLookup.direct(
|
|
47
|
+
const lookup = ScopedParameterLookup.direct(parameterLookupScope('test', '1'), ['t1']);
|
|
44
48
|
|
|
45
49
|
const checkpoint1 = await bucketStorage.getCheckpoint();
|
|
46
50
|
const parameters1 = await checkpoint1.getParameterSets([lookup]);
|
|
@@ -102,6 +106,7 @@ bucket_definitions:
|
|
|
102
106
|
const bucketStorage = factory.getInstance(syncRules);
|
|
103
107
|
|
|
104
108
|
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|
|
109
|
+
await batch.markAllSnapshotDone('1/1');
|
|
105
110
|
await batch.save({
|
|
106
111
|
sourceTable: TEST_TABLE,
|
|
107
112
|
tag: storage.SaveOperationTag.INSERT,
|
|
@@ -151,7 +156,7 @@ bucket_definitions:
|
|
|
151
156
|
await batch.commit('3/1');
|
|
152
157
|
});
|
|
153
158
|
|
|
154
|
-
const lookup = ScopedParameterLookup.direct(
|
|
159
|
+
const lookup = ScopedParameterLookup.direct(parameterLookupScope('test', '1'), ['u1']);
|
|
155
160
|
|
|
156
161
|
const checkpoint1 = await bucketStorage.getCheckpoint();
|
|
157
162
|
const parameters1 = await checkpoint1.getParameterSets([lookup]);
|