@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
@@ -2,10 +2,11 @@ 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
- const TEST_TABLE = test_utils.makeTestTable('test', ['id']);
7
+ export function registerParameterCompactTests(config: storage.TestStorageConfig) {
8
+ const generateStorageFactory = config.factory;
7
9
 
8
- export function registerParameterCompactTests(generateStorageFactory: storage.TestStorageFactory) {
9
10
  test('compacting parameters', async () => {
10
11
  await using factory = await generateStorageFactory();
11
12
  const syncRules = await factory.updateSyncRules(
@@ -17,59 +18,58 @@ bucket_definitions:
17
18
  `)
18
19
  );
19
20
  const bucketStorage = factory.getInstance(syncRules);
21
+ await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
22
+ const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
23
+
24
+ await writer.markAllSnapshotDone('1/1');
25
+ await writer.save({
26
+ sourceTable: testTable,
27
+ tag: storage.SaveOperationTag.INSERT,
28
+ after: {
29
+ id: 't1'
30
+ },
31
+ afterReplicaId: 't1'
32
+ });
20
33
 
21
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
22
- await batch.save({
23
- sourceTable: TEST_TABLE,
24
- tag: storage.SaveOperationTag.INSERT,
25
- after: {
26
- id: 't1'
27
- },
28
- afterReplicaId: 't1'
29
- });
30
-
31
- await batch.save({
32
- sourceTable: TEST_TABLE,
33
- tag: storage.SaveOperationTag.INSERT,
34
- after: {
35
- id: 't2'
36
- },
37
- afterReplicaId: 't2'
38
- });
39
-
40
- await batch.commit('1/1');
34
+ await writer.save({
35
+ sourceTable: testTable,
36
+ tag: storage.SaveOperationTag.INSERT,
37
+ after: {
38
+ id: 't2'
39
+ },
40
+ afterReplicaId: 't2'
41
41
  });
42
42
 
43
- const lookup = ScopedParameterLookup.direct({ lookupName: 'test', queryId: '1' }, ['t1']);
43
+ await writer.commit('1/1');
44
+
45
+ const lookup = ScopedParameterLookup.direct({ lookupName: 'test', queryId: '1', source: null as any }, ['t1']);
44
46
 
45
47
  const checkpoint1 = await bucketStorage.getCheckpoint();
46
48
  const parameters1 = await checkpoint1.getParameterSets([lookup]);
47
49
  expect(parameters1).toEqual([{ id: 't1' }]);
48
50
 
49
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
50
- await batch.save({
51
- sourceTable: TEST_TABLE,
52
- tag: storage.SaveOperationTag.UPDATE,
53
- before: {
54
- id: 't1'
55
- },
56
- beforeReplicaId: 't1',
57
- after: {
58
- id: 't1'
59
- },
60
- afterReplicaId: 't1'
61
- });
51
+ await writer.save({
52
+ sourceTable: testTable,
53
+ tag: storage.SaveOperationTag.UPDATE,
54
+ before: {
55
+ id: 't1'
56
+ },
57
+ beforeReplicaId: 't1',
58
+ after: {
59
+ id: 't1'
60
+ },
61
+ afterReplicaId: 't1'
62
+ });
62
63
 
63
- await batch.save({
64
- sourceTable: TEST_TABLE,
65
- tag: storage.SaveOperationTag.DELETE,
66
- before: {
67
- id: 't1'
68
- },
69
- beforeReplicaId: 't1'
70
- });
71
- await batch.commit('1/2');
64
+ await writer.save({
65
+ sourceTable: testTable,
66
+ tag: storage.SaveOperationTag.DELETE,
67
+ before: {
68
+ id: 't1'
69
+ },
70
+ beforeReplicaId: 't1'
72
71
  });
72
+ await writer.commit('1/2');
73
73
  const checkpoint2 = await bucketStorage.getCheckpoint();
74
74
  const parameters2 = await checkpoint2.getParameterSets([lookup]);
75
75
  expect(parameters2).toEqual([]);
@@ -100,58 +100,55 @@ bucket_definitions:
100
100
  `)
101
101
  );
102
102
  const bucketStorage = factory.getInstance(syncRules);
103
+ await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
104
+ const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
103
105
 
104
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
105
- await batch.save({
106
- sourceTable: TEST_TABLE,
107
- tag: storage.SaveOperationTag.INSERT,
108
- after: {
109
- id: 't1',
110
- uid: 'u1'
111
- },
112
- afterReplicaId: 't1'
113
- });
114
- // Interleave with another operation, to evict the other cache entry when compacting.
115
- await batch.save({
116
- sourceTable: TEST_TABLE,
117
- tag: storage.SaveOperationTag.INSERT,
118
- after: {
119
- id: 't2',
120
- uid: 'u1'
121
- },
122
- afterReplicaId: 't2'
123
- });
124
-
125
- await batch.commit('1/1');
106
+ await writer.markAllSnapshotDone('1/1');
107
+ await writer.save({
108
+ sourceTable: testTable,
109
+ tag: storage.SaveOperationTag.INSERT,
110
+ after: {
111
+ id: 't1',
112
+ uid: 'u1'
113
+ },
114
+ afterReplicaId: 't1'
115
+ });
116
+ // Interleave with another operation, to evict the other cache entry when compacting.
117
+ await writer.save({
118
+ sourceTable: testTable,
119
+ tag: storage.SaveOperationTag.INSERT,
120
+ after: {
121
+ id: 't2',
122
+ uid: 'u1'
123
+ },
124
+ afterReplicaId: 't2'
126
125
  });
127
126
 
128
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
129
- await batch.save({
130
- sourceTable: TEST_TABLE,
131
- tag: storage.SaveOperationTag.DELETE,
132
- before: {
133
- id: 't1',
134
- uid: 'u1'
135
- },
136
- beforeReplicaId: 't1'
137
- });
138
- await batch.commit('2/1');
127
+ await writer.commit('1/1');
128
+
129
+ await writer.save({
130
+ sourceTable: testTable,
131
+ tag: storage.SaveOperationTag.DELETE,
132
+ before: {
133
+ id: 't1',
134
+ uid: 'u1'
135
+ },
136
+ beforeReplicaId: 't1'
139
137
  });
138
+ await writer.commit('2/1');
140
139
 
141
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
142
- await batch.save({
143
- sourceTable: TEST_TABLE,
144
- tag: storage.SaveOperationTag.UPDATE,
145
- after: {
146
- id: 't2',
147
- uid: 'u2'
148
- },
149
- afterReplicaId: 't2'
150
- });
151
- await batch.commit('3/1');
140
+ await writer.save({
141
+ sourceTable: testTable,
142
+ tag: storage.SaveOperationTag.UPDATE,
143
+ after: {
144
+ id: 't2',
145
+ uid: 'u2'
146
+ },
147
+ afterReplicaId: 't2'
152
148
  });
149
+ await writer.commit('3/1');
153
150
 
154
- const lookup = ScopedParameterLookup.direct({ lookupName: 'test', queryId: '1' }, ['u1']);
151
+ const lookup = ScopedParameterLookup.direct({ lookupName: 'test', queryId: '1', source: null as any }, ['u1']);
155
152
 
156
153
  const checkpoint1 = await bucketStorage.getCheckpoint();
157
154
  const parameters1 = await checkpoint1.getParameterSets([lookup]);