@powersync/service-core-tests 0.14.0 → 0.15.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/test-utils/general-utils.d.ts +22 -3
  3. package/dist/test-utils/general-utils.js +56 -3
  4. package/dist/test-utils/general-utils.js.map +1 -1
  5. package/dist/test-utils/stream_utils.js +2 -2
  6. package/dist/test-utils/stream_utils.js.map +1 -1
  7. package/dist/tests/register-compacting-tests.d.ts +1 -1
  8. package/dist/tests/register-compacting-tests.js +360 -297
  9. package/dist/tests/register-compacting-tests.js.map +1 -1
  10. package/dist/tests/register-data-storage-checkpoint-tests.d.ts +1 -1
  11. package/dist/tests/register-data-storage-checkpoint-tests.js +59 -48
  12. package/dist/tests/register-data-storage-checkpoint-tests.js.map +1 -1
  13. package/dist/tests/register-data-storage-data-tests.d.ts +2 -2
  14. package/dist/tests/register-data-storage-data-tests.js +1112 -612
  15. package/dist/tests/register-data-storage-data-tests.js.map +1 -1
  16. package/dist/tests/register-data-storage-parameter-tests.d.ts +1 -1
  17. package/dist/tests/register-data-storage-parameter-tests.js +273 -254
  18. package/dist/tests/register-data-storage-parameter-tests.js.map +1 -1
  19. package/dist/tests/register-parameter-compacting-tests.d.ts +1 -1
  20. package/dist/tests/register-parameter-compacting-tests.js +83 -87
  21. package/dist/tests/register-parameter-compacting-tests.js.map +1 -1
  22. package/dist/tests/register-sync-tests.d.ts +2 -1
  23. package/dist/tests/register-sync-tests.js +479 -451
  24. package/dist/tests/register-sync-tests.js.map +1 -1
  25. package/dist/tests/util.d.ts +5 -4
  26. package/dist/tests/util.js +27 -12
  27. package/dist/tests/util.js.map +1 -1
  28. package/package.json +3 -3
  29. package/src/test-utils/general-utils.ts +81 -4
  30. package/src/test-utils/stream_utils.ts +2 -2
  31. package/src/tests/register-compacting-tests.ts +376 -322
  32. package/src/tests/register-data-storage-checkpoint-tests.ts +85 -53
  33. package/src/tests/register-data-storage-data-tests.ts +1050 -559
  34. package/src/tests/register-data-storage-parameter-tests.ts +330 -288
  35. package/src/tests/register-parameter-compacting-tests.ts +87 -90
  36. package/src/tests/register-sync-tests.ts +390 -380
  37. package/src/tests/util.ts +46 -17
  38. package/tsconfig.tsbuildinfo +1 -1
@@ -50,11 +50,12 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
50
50
  var e = new Error(message);
51
51
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
52
  });
53
- import { JwtPayload, storage, updateSyncRulesFromYaml } from '@powersync/service-core';
53
+ import { CURRENT_STORAGE_VERSION, JwtPayload, storage, updateSyncRulesFromYaml } from '@powersync/service-core';
54
54
  import { RequestParameters, ScopedParameterLookup } from '@powersync/service-sync-rules';
55
55
  import { expect, test } from 'vitest';
56
56
  import * as test_utils from '../test-utils/test-utils-index.js';
57
- import { bucketRequest, TEST_TABLE } from './util.js';
57
+ import { bucketRequest } from '../test-utils/test-utils-index.js';
58
+ import { parameterLookupScope } from './util.js';
58
59
  /**
59
60
  * @example
60
61
  * ```TypeScript
@@ -65,8 +66,10 @@ import { bucketRequest, TEST_TABLE } from './util.js';
65
66
  *
66
67
  * ```
67
68
  */
68
- export function registerDataStorageParameterTests(generateStorageFactory) {
69
- const MYBUCKET_1 = { lookupName: 'mybucket', queryId: '1' };
69
+ export function registerDataStorageParameterTests(config) {
70
+ const generateStorageFactory = config.factory;
71
+ const storageVersion = config.storageVersion ?? CURRENT_STORAGE_VERSION;
72
+ const MYBUCKET_1 = parameterLookupScope('mybucket', '1');
70
73
  test('save and load parameters', async () => {
71
74
  const env_1 = { stack: [], error: void 0, hasError: false };
72
75
  try {
@@ -77,33 +80,36 @@ bucket_definitions:
77
80
  parameters:
78
81
  - SELECT group_id FROM test WHERE id1 = token_parameters.user_id OR id2 = token_parameters.user_id
79
82
  data: []
80
- `));
83
+ `, {
84
+ storageVersion
85
+ }));
81
86
  const bucketStorage = factory.getInstance(syncRules);
82
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
83
- await batch.save({
84
- sourceTable: TEST_TABLE,
85
- tag: storage.SaveOperationTag.INSERT,
86
- after: {
87
- id: 't2',
88
- id1: 'user3',
89
- id2: 'user4',
90
- group_id: 'group2a'
91
- },
92
- afterReplicaId: test_utils.rid('t2')
93
- });
94
- await batch.save({
95
- sourceTable: TEST_TABLE,
96
- tag: storage.SaveOperationTag.INSERT,
97
- after: {
98
- id: 't1',
99
- id1: 'user1',
100
- id2: 'user2',
101
- group_id: 'group1a'
102
- },
103
- afterReplicaId: test_utils.rid('t1')
104
- });
105
- await batch.commit('1/1');
87
+ const writer = __addDisposableResource(env_1, await bucketStorage.createWriter(test_utils.BATCH_OPTIONS), true);
88
+ const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
89
+ await writer.markAllSnapshotDone('1/1');
90
+ await writer.save({
91
+ sourceTable: testTable,
92
+ tag: storage.SaveOperationTag.INSERT,
93
+ after: {
94
+ id: 't2',
95
+ id1: 'user3',
96
+ id2: 'user4',
97
+ group_id: 'group2a'
98
+ },
99
+ afterReplicaId: test_utils.rid('t2')
100
+ });
101
+ await writer.save({
102
+ sourceTable: testTable,
103
+ tag: storage.SaveOperationTag.INSERT,
104
+ after: {
105
+ id: 't1',
106
+ id1: 'user1',
107
+ id2: 'user2',
108
+ group_id: 'group1a'
109
+ },
110
+ afterReplicaId: test_utils.rid('t1')
106
111
  });
112
+ await writer.commit('1/1');
107
113
  const checkpoint = await bucketStorage.getCheckpoint();
108
114
  const parameters = await checkpoint.getParameterSets([ScopedParameterLookup.direct(MYBUCKET_1, ['user1'])]);
109
115
  expect(parameters).toEqual([
@@ -132,33 +138,34 @@ bucket_definitions:
132
138
  parameters:
133
139
  - SELECT group_id FROM test WHERE id = token_parameters.user_id
134
140
  data: []
135
- `));
141
+ `, {
142
+ storageVersion
143
+ }));
136
144
  const bucketStorage = factory.getInstance(syncRules);
137
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
138
- await batch.save({
139
- sourceTable: TEST_TABLE,
140
- tag: storage.SaveOperationTag.INSERT,
141
- after: {
142
- id: 'user1',
143
- group_id: 'group1'
144
- },
145
- afterReplicaId: test_utils.rid('user1')
146
- });
147
- await batch.commit('1/1');
145
+ const writer = __addDisposableResource(env_2, await bucketStorage.createWriter(test_utils.BATCH_OPTIONS), true);
146
+ const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
147
+ await writer.markAllSnapshotDone('1/1');
148
+ await writer.save({
149
+ sourceTable: testTable,
150
+ tag: storage.SaveOperationTag.INSERT,
151
+ after: {
152
+ id: 'user1',
153
+ group_id: 'group1'
154
+ },
155
+ afterReplicaId: test_utils.rid('user1')
148
156
  });
157
+ await writer.commit('1/1');
149
158
  const checkpoint1 = await bucketStorage.getCheckpoint();
150
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
151
- await batch.save({
152
- sourceTable: TEST_TABLE,
153
- tag: storage.SaveOperationTag.INSERT,
154
- after: {
155
- id: 'user1',
156
- group_id: 'group2'
157
- },
158
- afterReplicaId: test_utils.rid('user1')
159
- });
160
- await batch.commit('1/2');
159
+ await writer.save({
160
+ sourceTable: testTable,
161
+ tag: storage.SaveOperationTag.INSERT,
162
+ after: {
163
+ id: 'user1',
164
+ group_id: 'group2'
165
+ },
166
+ afterReplicaId: test_utils.rid('user1')
161
167
  });
168
+ await writer.commit('1/2');
162
169
  const checkpoint2 = await bucketStorage.getCheckpoint();
163
170
  const parameters = await checkpoint2.getParameterSets([ScopedParameterLookup.direct(MYBUCKET_1, ['user1'])]);
164
171
  expect(parameters).toEqual([
@@ -196,44 +203,42 @@ bucket_definitions:
196
203
  FROM todos
197
204
  WHERE list_id IN token_parameters.list_id
198
205
  data: []
199
- `));
206
+ `, { storageVersion }));
200
207
  const bucketStorage = factory.getInstance(syncRules);
201
- const table = test_utils.makeTestTable('todos', ['id', 'list_id']);
202
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
203
- // Create two todos which initially belong to different lists
204
- await batch.save({
205
- sourceTable: table,
206
- tag: storage.SaveOperationTag.INSERT,
207
- after: {
208
- id: 'todo1',
209
- list_id: 'list1'
210
- },
211
- afterReplicaId: test_utils.rid('todo1')
212
- });
213
- await batch.save({
214
- sourceTable: table,
215
- tag: storage.SaveOperationTag.INSERT,
216
- after: {
217
- id: 'todo2',
218
- list_id: 'list2'
219
- },
220
- afterReplicaId: test_utils.rid('todo2')
221
- });
222
- await batch.commit('1/1');
208
+ const writer = __addDisposableResource(env_3, await bucketStorage.createWriter(test_utils.BATCH_OPTIONS), true);
209
+ const table = await test_utils.resolveTestTable(writer, 'todos', ['id', 'list_id'], config);
210
+ await writer.markAllSnapshotDone('1/1');
211
+ // Create two todos which initially belong to different lists
212
+ await writer.save({
213
+ sourceTable: table,
214
+ tag: storage.SaveOperationTag.INSERT,
215
+ after: {
216
+ id: 'todo1',
217
+ list_id: 'list1'
218
+ },
219
+ afterReplicaId: test_utils.rid('todo1')
223
220
  });
224
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
225
- // Update the second todo item to now belong to list 1
226
- await batch.save({
227
- sourceTable: table,
228
- tag: storage.SaveOperationTag.UPDATE,
229
- after: {
230
- id: 'todo2',
231
- list_id: 'list1'
232
- },
233
- afterReplicaId: test_utils.rid('todo2')
234
- });
235
- await batch.commit('1/1');
221
+ await writer.save({
222
+ sourceTable: table,
223
+ tag: storage.SaveOperationTag.INSERT,
224
+ after: {
225
+ id: 'todo2',
226
+ list_id: 'list2'
227
+ },
228
+ afterReplicaId: test_utils.rid('todo2')
236
229
  });
230
+ await writer.commit('1/1');
231
+ // Update the second todo item to now belong to list 1
232
+ await writer.save({
233
+ sourceTable: table,
234
+ tag: storage.SaveOperationTag.UPDATE,
235
+ after: {
236
+ id: 'todo2',
237
+ list_id: 'list1'
238
+ },
239
+ afterReplicaId: test_utils.rid('todo2')
240
+ });
241
+ await writer.commit('1/1');
237
242
  // We specifically request the todo_ids for both lists.
238
243
  // There removal operation for the association of `list2`::`todo2` should not interfere with the new
239
244
  // association of `list1`::`todo2`
@@ -271,23 +276,26 @@ bucket_definitions:
271
276
  parameters:
272
277
  - SELECT group_id FROM test WHERE n1 = token_parameters.n1 and f2 = token_parameters.f2 and f3 = token_parameters.f3
273
278
  data: []
274
- `));
279
+ `, {
280
+ storageVersion
281
+ }));
275
282
  const bucketStorage = factory.getInstance(syncRules);
276
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
277
- await batch.save({
278
- sourceTable: TEST_TABLE,
279
- tag: storage.SaveOperationTag.INSERT,
280
- after: {
281
- id: 't1',
282
- group_id: 'group1',
283
- n1: 314n,
284
- f2: 314,
285
- f3: 3.14
286
- },
287
- afterReplicaId: test_utils.rid('t1')
288
- });
289
- await batch.commit('1/1');
283
+ const writer = __addDisposableResource(env_4, await bucketStorage.createWriter(test_utils.BATCH_OPTIONS), true);
284
+ const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
285
+ await writer.markAllSnapshotDone('1/1');
286
+ await writer.save({
287
+ sourceTable: testTable,
288
+ tag: storage.SaveOperationTag.INSERT,
289
+ after: {
290
+ id: 't1',
291
+ group_id: 'group1',
292
+ n1: 314n,
293
+ f2: 314,
294
+ f3: 3.14
295
+ },
296
+ afterReplicaId: test_utils.rid('t1')
290
297
  });
298
+ await writer.commit('1/1');
291
299
  const TEST_PARAMS = { group_id: 'group1' };
292
300
  const checkpoint = await bucketStorage.getCheckpoint();
293
301
  const parameters1 = await checkpoint.getParameterSets([
@@ -324,33 +332,36 @@ bucket_definitions:
324
332
  parameters:
325
333
  - SELECT group_id FROM test WHERE n1 = token_parameters.n1
326
334
  data: []
327
- `));
335
+ `, {
336
+ storageVersion
337
+ }));
328
338
  const bucketStorage = factory.getInstance(syncRules);
329
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
330
- await batch.save({
331
- sourceTable: TEST_TABLE,
332
- tag: storage.SaveOperationTag.INSERT,
333
- after: {
334
- id: 't1',
335
- group_id: 'group1',
336
- n1: 1152921504606846976n // 2^60
337
- },
338
- afterReplicaId: test_utils.rid('t1')
339
- });
340
- await batch.save({
341
- sourceTable: TEST_TABLE,
342
- tag: storage.SaveOperationTag.UPDATE,
343
- after: {
344
- id: 't1',
345
- group_id: 'group1',
346
- // Simulate a TOAST value, even though it can't happen for values like this
347
- // in practice.
348
- n1: undefined
349
- },
350
- afterReplicaId: test_utils.rid('t1')
351
- });
352
- await batch.commit('1/1');
339
+ const writer = __addDisposableResource(env_5, await bucketStorage.createWriter(test_utils.BATCH_OPTIONS), true);
340
+ const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
341
+ await writer.markAllSnapshotDone('1/1');
342
+ await writer.save({
343
+ sourceTable: testTable,
344
+ tag: storage.SaveOperationTag.INSERT,
345
+ after: {
346
+ id: 't1',
347
+ group_id: 'group1',
348
+ n1: 1152921504606846976n // 2^60
349
+ },
350
+ afterReplicaId: test_utils.rid('t1')
351
+ });
352
+ await writer.save({
353
+ sourceTable: testTable,
354
+ tag: storage.SaveOperationTag.UPDATE,
355
+ after: {
356
+ id: 't1',
357
+ group_id: 'group1',
358
+ // Simulate a TOAST value, even though it can't happen for values like this
359
+ // in practice.
360
+ n1: undefined
361
+ },
362
+ afterReplicaId: test_utils.rid('t1')
353
363
  });
364
+ await writer.commit('1/1');
354
365
  const TEST_PARAMS = { group_id: 'group1' };
355
366
  const checkpoint = await bucketStorage.getCheckpoint();
356
367
  const parameters1 = await checkpoint.getParameterSets([
@@ -371,7 +382,6 @@ bucket_definitions:
371
382
  test('save and load parameters with workspaceId', async () => {
372
383
  const env_6 = { stack: [], error: void 0, hasError: false };
373
384
  try {
374
- const WORKSPACE_TABLE = test_utils.makeTestTable('workspace', ['id']);
375
385
  const factory = __addDisposableResource(env_6, await generateStorageFactory(), true);
376
386
  const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
377
387
  bucket_definitions:
@@ -380,27 +390,30 @@ bucket_definitions:
380
390
  - SELECT id as workspace_id FROM workspace WHERE
381
391
  workspace."userId" = token_parameters.user_id
382
392
  data: []
383
- `));
393
+ `, {
394
+ storageVersion
395
+ }));
384
396
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncRules();
385
397
  const bucketStorage = factory.getInstance(syncRules);
386
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
387
- await batch.save({
388
- sourceTable: WORKSPACE_TABLE,
389
- tag: storage.SaveOperationTag.INSERT,
390
- after: {
391
- id: 'workspace1',
392
- userId: 'u1'
393
- },
394
- afterReplicaId: test_utils.rid('workspace1')
395
- });
396
- await batch.commit('1/1');
398
+ const writer = __addDisposableResource(env_6, await bucketStorage.createWriter(test_utils.BATCH_OPTIONS), true);
399
+ const workspaceTable = await test_utils.resolveTestTable(writer, 'workspace', ['id'], config);
400
+ await writer.markAllSnapshotDone('1/1');
401
+ await writer.save({
402
+ sourceTable: workspaceTable,
403
+ tag: storage.SaveOperationTag.INSERT,
404
+ after: {
405
+ id: 'workspace1',
406
+ userId: 'u1'
407
+ },
408
+ afterReplicaId: test_utils.rid('workspace1')
397
409
  });
410
+ await writer.commit('1/1');
398
411
  const checkpoint = await bucketStorage.getCheckpoint();
399
412
  const parameters = new RequestParameters(new JwtPayload({ sub: 'u1' }), {});
400
413
  const querier = sync_rules.getBucketParameterQuerier(test_utils.querierOptions(parameters)).querier;
401
414
  const buckets = await querier.queryDynamicBucketDescriptions({
402
415
  async getParameterSets(lookups) {
403
- expect(lookups).toEqual([ScopedParameterLookup.direct({ lookupName: 'by_workspace', queryId: '1' }, ['u1'])]);
416
+ expect(lookups).toEqual([ScopedParameterLookup.direct(parameterLookupScope('by_workspace', '1'), ['u1'])]);
404
417
  const parameter_sets = await checkpoint.getParameterSets(lookups);
405
418
  expect(parameter_sets).toEqual([{ workspace_id: 'workspace1' }]);
406
419
  return parameter_sets;
@@ -408,7 +421,7 @@ bucket_definitions:
408
421
  });
409
422
  expect(buckets).toEqual([
410
423
  {
411
- bucket: bucketRequest(syncRules, 'by_workspace["workspace1"]'),
424
+ bucket: bucketRequest(syncRules, 'by_workspace["workspace1"]').bucket,
412
425
  priority: 3,
413
426
  definition: 'by_workspace',
414
427
  inclusion_reasons: ['default']
@@ -428,7 +441,6 @@ bucket_definitions:
428
441
  test('save and load parameters with dynamic global buckets', async () => {
429
442
  const env_7 = { stack: [], error: void 0, hasError: false };
430
443
  try {
431
- const WORKSPACE_TABLE = test_utils.makeTestTable('workspace');
432
444
  const factory = __addDisposableResource(env_7, await generateStorageFactory(), true);
433
445
  const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
434
446
  bucket_definitions:
@@ -437,47 +449,48 @@ bucket_definitions:
437
449
  - SELECT id as workspace_id FROM workspace WHERE
438
450
  workspace.visibility = 'public'
439
451
  data: []
440
- `));
452
+ `, {
453
+ storageVersion
454
+ }));
441
455
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncRules();
442
456
  const bucketStorage = factory.getInstance(syncRules);
443
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
444
- await batch.save({
445
- sourceTable: WORKSPACE_TABLE,
446
- tag: storage.SaveOperationTag.INSERT,
447
- after: {
448
- id: 'workspace1',
449
- visibility: 'public'
450
- },
451
- afterReplicaId: test_utils.rid('workspace1')
452
- });
453
- await batch.save({
454
- sourceTable: WORKSPACE_TABLE,
455
- tag: storage.SaveOperationTag.INSERT,
456
- after: {
457
- id: 'workspace2',
458
- visibility: 'private'
459
- },
460
- afterReplicaId: test_utils.rid('workspace2')
461
- });
462
- await batch.save({
463
- sourceTable: WORKSPACE_TABLE,
464
- tag: storage.SaveOperationTag.INSERT,
465
- after: {
466
- id: 'workspace3',
467
- visibility: 'public'
468
- },
469
- afterReplicaId: test_utils.rid('workspace3')
470
- });
471
- await batch.commit('1/1');
457
+ const writer = __addDisposableResource(env_7, await bucketStorage.createWriter(test_utils.BATCH_OPTIONS), true);
458
+ const workspaceTable = await test_utils.resolveTestTable(writer, 'workspace', undefined, config);
459
+ await writer.markAllSnapshotDone('1/1');
460
+ await writer.save({
461
+ sourceTable: workspaceTable,
462
+ tag: storage.SaveOperationTag.INSERT,
463
+ after: {
464
+ id: 'workspace1',
465
+ visibility: 'public'
466
+ },
467
+ afterReplicaId: test_utils.rid('workspace1')
468
+ });
469
+ await writer.save({
470
+ sourceTable: workspaceTable,
471
+ tag: storage.SaveOperationTag.INSERT,
472
+ after: {
473
+ id: 'workspace2',
474
+ visibility: 'private'
475
+ },
476
+ afterReplicaId: test_utils.rid('workspace2')
477
+ });
478
+ await writer.save({
479
+ sourceTable: workspaceTable,
480
+ tag: storage.SaveOperationTag.INSERT,
481
+ after: {
482
+ id: 'workspace3',
483
+ visibility: 'public'
484
+ },
485
+ afterReplicaId: test_utils.rid('workspace3')
472
486
  });
487
+ await writer.commit('1/1');
473
488
  const checkpoint = await bucketStorage.getCheckpoint();
474
489
  const parameters = new RequestParameters(new JwtPayload({ sub: 'unknown' }), {});
475
490
  const querier = sync_rules.getBucketParameterQuerier(test_utils.querierOptions(parameters)).querier;
476
491
  const buckets = await querier.queryDynamicBucketDescriptions({
477
492
  async getParameterSets(lookups) {
478
- expect(lookups).toEqual([
479
- ScopedParameterLookup.direct({ lookupName: 'by_public_workspace', queryId: '1' }, [])
480
- ]);
493
+ expect(lookups).toEqual([ScopedParameterLookup.direct(parameterLookupScope('by_public_workspace', '1'), [])]);
481
494
  const parameter_sets = await checkpoint.getParameterSets(lookups);
482
495
  parameter_sets.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
483
496
  expect(parameter_sets).toEqual([{ workspace_id: 'workspace1' }, { workspace_id: 'workspace3' }]);
@@ -487,13 +500,13 @@ bucket_definitions:
487
500
  buckets.sort((a, b) => a.bucket.localeCompare(b.bucket));
488
501
  expect(buckets).toEqual([
489
502
  {
490
- bucket: bucketRequest(syncRules, 'by_public_workspace["workspace1"]'),
503
+ bucket: bucketRequest(syncRules, 'by_public_workspace["workspace1"]').bucket,
491
504
  priority: 3,
492
505
  definition: 'by_public_workspace',
493
506
  inclusion_reasons: ['default']
494
507
  },
495
508
  {
496
- bucket: bucketRequest(syncRules, 'by_public_workspace["workspace3"]'),
509
+ bucket: bucketRequest(syncRules, 'by_public_workspace["workspace3"]').bucket,
497
510
  priority: 3,
498
511
  definition: 'by_public_workspace',
499
512
  inclusion_reasons: ['default']
@@ -513,7 +526,6 @@ bucket_definitions:
513
526
  test('multiple parameter queries', async () => {
514
527
  const env_8 = { stack: [], error: void 0, hasError: false };
515
528
  try {
516
- const WORKSPACE_TABLE = test_utils.makeTestTable('workspace');
517
529
  const factory = __addDisposableResource(env_8, await generateStorageFactory(), true);
518
530
  const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
519
531
  bucket_definitions:
@@ -524,50 +536,53 @@ bucket_definitions:
524
536
  - SELECT id as workspace_id FROM workspace WHERE
525
537
  workspace.user_id = token_parameters.user_id
526
538
  data: []
527
- `));
539
+ `, {
540
+ storageVersion
541
+ }));
528
542
  const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncRules();
529
543
  const bucketStorage = factory.getInstance(syncRules);
530
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
531
- await batch.save({
532
- sourceTable: WORKSPACE_TABLE,
533
- tag: storage.SaveOperationTag.INSERT,
534
- after: {
535
- id: 'workspace1',
536
- visibility: 'public'
537
- },
538
- afterReplicaId: test_utils.rid('workspace1')
539
- });
540
- await batch.save({
541
- sourceTable: WORKSPACE_TABLE,
542
- tag: storage.SaveOperationTag.INSERT,
543
- after: {
544
- id: 'workspace2',
545
- visibility: 'private'
546
- },
547
- afterReplicaId: test_utils.rid('workspace2')
548
- });
549
- await batch.save({
550
- sourceTable: WORKSPACE_TABLE,
551
- tag: storage.SaveOperationTag.INSERT,
552
- after: {
553
- id: 'workspace3',
554
- user_id: 'u1',
555
- visibility: 'private'
556
- },
557
- afterReplicaId: test_utils.rid('workspace3')
558
- });
559
- await batch.save({
560
- sourceTable: WORKSPACE_TABLE,
561
- tag: storage.SaveOperationTag.INSERT,
562
- after: {
563
- id: 'workspace4',
564
- user_id: 'u2',
565
- visibility: 'private'
566
- },
567
- afterReplicaId: test_utils.rid('workspace4')
568
- });
569
- await batch.commit('1/1');
544
+ const writer = __addDisposableResource(env_8, await bucketStorage.createWriter(test_utils.BATCH_OPTIONS), true);
545
+ const workspaceTable = await test_utils.resolveTestTable(writer, 'workspace', undefined, config);
546
+ await writer.markAllSnapshotDone('1/1');
547
+ await writer.save({
548
+ sourceTable: workspaceTable,
549
+ tag: storage.SaveOperationTag.INSERT,
550
+ after: {
551
+ id: 'workspace1',
552
+ visibility: 'public'
553
+ },
554
+ afterReplicaId: test_utils.rid('workspace1')
570
555
  });
556
+ await writer.save({
557
+ sourceTable: workspaceTable,
558
+ tag: storage.SaveOperationTag.INSERT,
559
+ after: {
560
+ id: 'workspace2',
561
+ visibility: 'private'
562
+ },
563
+ afterReplicaId: test_utils.rid('workspace2')
564
+ });
565
+ await writer.save({
566
+ sourceTable: workspaceTable,
567
+ tag: storage.SaveOperationTag.INSERT,
568
+ after: {
569
+ id: 'workspace3',
570
+ user_id: 'u1',
571
+ visibility: 'private'
572
+ },
573
+ afterReplicaId: test_utils.rid('workspace3')
574
+ });
575
+ await writer.save({
576
+ sourceTable: workspaceTable,
577
+ tag: storage.SaveOperationTag.INSERT,
578
+ after: {
579
+ id: 'workspace4',
580
+ user_id: 'u2',
581
+ visibility: 'private'
582
+ },
583
+ afterReplicaId: test_utils.rid('workspace4')
584
+ });
585
+ await writer.commit('1/1');
571
586
  const checkpoint = await bucketStorage.getCheckpoint();
572
587
  const parameters = new RequestParameters(new JwtPayload({ sub: 'u1' }), {});
573
588
  // Test intermediate values - could be moved to sync_rules.test.ts
@@ -584,15 +599,15 @@ bucket_definitions:
584
599
  }
585
600
  })).map((e) => e.bucket);
586
601
  expect(foundLookups).toEqual([
587
- ScopedParameterLookup.direct({ lookupName: 'by_workspace', queryId: '1' }, []),
588
- ScopedParameterLookup.direct({ lookupName: 'by_workspace', queryId: '2' }, ['u1'])
602
+ ScopedParameterLookup.direct(parameterLookupScope('by_workspace', '1'), []),
603
+ ScopedParameterLookup.direct(parameterLookupScope('by_workspace', '2'), ['u1'])
589
604
  ]);
590
605
  parameter_sets.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
591
606
  expect(parameter_sets).toEqual([{ workspace_id: 'workspace1' }, { workspace_id: 'workspace3' }]);
592
607
  buckets.sort();
593
608
  expect(buckets).toEqual([
594
- bucketRequest(syncRules, 'by_workspace["workspace1"]'),
595
- bucketRequest(syncRules, 'by_workspace["workspace3"]')
609
+ bucketRequest(syncRules, 'by_workspace["workspace1"]').bucket,
610
+ bucketRequest(syncRules, 'by_workspace["workspace3"]').bucket
596
611
  ]);
597
612
  }
598
613
  catch (e_8) {
@@ -615,22 +630,26 @@ bucket_definitions:
615
630
  parameters:
616
631
  - SELECT group_id FROM test WHERE id1 = token_parameters.user_id OR id2 = token_parameters.user_id
617
632
  data: []
618
- `));
633
+ `, {
634
+ storageVersion
635
+ }));
619
636
  const bucketStorage = factory.getInstance(syncRules);
620
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
621
- await batch.save({
622
- sourceTable: TEST_TABLE,
623
- tag: storage.SaveOperationTag.INSERT,
624
- after: {
625
- id: 't2',
626
- id1: 'user3',
627
- id2: 'user4',
628
- group_id: 'group2a'
629
- },
630
- afterReplicaId: test_utils.rid('t2')
631
- });
632
- await batch.truncate([TEST_TABLE]);
637
+ const writer = __addDisposableResource(env_9, await bucketStorage.createWriter(test_utils.BATCH_OPTIONS), true);
638
+ const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
639
+ await writer.markAllSnapshotDone('1/1');
640
+ await writer.save({
641
+ sourceTable: testTable,
642
+ tag: storage.SaveOperationTag.INSERT,
643
+ after: {
644
+ id: 't2',
645
+ id1: 'user3',
646
+ id2: 'user4',
647
+ group_id: 'group2a'
648
+ },
649
+ afterReplicaId: test_utils.rid('t2')
633
650
  });
651
+ await writer.truncate([testTable]);
652
+ await writer.flush();
634
653
  const checkpoint = await bucketStorage.getCheckpoint();
635
654
  const parameters = await checkpoint.getParameterSets([ScopedParameterLookup.direct(MYBUCKET_1, ['user1'])]);
636
655
  expect(parameters).toEqual([]);
@@ -656,7 +675,9 @@ bucket_definitions:
656
675
  - SELECT id as workspace_id FROM workspace WHERE
657
676
  workspace."userId" = token_parameters.user_id
658
677
  data: []
659
- `));
678
+ `, {
679
+ storageVersion
680
+ }));
660
681
  const syncBucketStorage = bucketStorageFactory.getInstance(syncRules);
661
682
  const parsedSchema1 = syncBucketStorage.getParsedSyncRules({
662
683
  defaultSchema: 'public'
@@ -699,24 +720,22 @@ streams:
699
720
  WHERE data.foo = param.bar AND param.baz = auth.user_id()
700
721
  `));
701
722
  const bucketStorage = factory.getInstance(syncRules);
702
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
703
- await batch.save({
704
- sourceTable: TEST_TABLE,
705
- tag: storage.SaveOperationTag.INSERT,
706
- after: {
707
- baz: 'baz',
708
- bar: 'bar'
709
- },
710
- afterReplicaId: test_utils.rid('t1')
711
- });
712
- await batch.commit('1/1');
723
+ const writer = __addDisposableResource(env_11, await bucketStorage.createWriter(test_utils.BATCH_OPTIONS), true);
724
+ const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
725
+ await writer.markAllSnapshotDone('1/1');
726
+ await writer.save({
727
+ sourceTable: testTable,
728
+ tag: storage.SaveOperationTag.INSERT,
729
+ after: {
730
+ baz: 'baz',
731
+ bar: 'bar'
732
+ },
733
+ afterReplicaId: test_utils.rid('t1')
713
734
  });
735
+ await writer.commit('1/1');
714
736
  const checkpoint = await bucketStorage.getCheckpoint();
715
737
  const parameters = await checkpoint.getParameterSets([
716
- ScopedParameterLookup.direct({
717
- lookupName: 'lookup',
718
- queryId: '0'
719
- }, ['baz'])
738
+ ScopedParameterLookup.direct(parameterLookupScope('lookup', '0'), ['baz'])
720
739
  ]);
721
740
  expect(parameters).toEqual([
722
741
  {