@powersync/service-core-tests 0.15.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 (28) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/test-utils/general-utils.d.ts +13 -1
  3. package/dist/test-utils/general-utils.js +30 -1
  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.js +266 -257
  8. package/dist/tests/register-compacting-tests.js.map +1 -1
  9. package/dist/tests/register-data-storage-checkpoint-tests.js +36 -57
  10. package/dist/tests/register-data-storage-checkpoint-tests.js.map +1 -1
  11. package/dist/tests/register-data-storage-data-tests.js +839 -863
  12. package/dist/tests/register-data-storage-data-tests.js.map +1 -1
  13. package/dist/tests/register-data-storage-parameter-tests.js +228 -236
  14. package/dist/tests/register-data-storage-parameter-tests.js.map +1 -1
  15. package/dist/tests/register-parameter-compacting-tests.js +81 -89
  16. package/dist/tests/register-parameter-compacting-tests.js.map +1 -1
  17. package/dist/tests/register-sync-tests.js +468 -462
  18. package/dist/tests/register-sync-tests.js.map +1 -1
  19. package/package.json +3 -3
  20. package/src/test-utils/general-utils.ts +41 -2
  21. package/src/test-utils/stream_utils.ts +2 -2
  22. package/src/tests/register-compacting-tests.ts +279 -270
  23. package/src/tests/register-data-storage-checkpoint-tests.ts +36 -57
  24. package/src/tests/register-data-storage-data-tests.ts +673 -770
  25. package/src/tests/register-data-storage-parameter-tests.ts +245 -257
  26. package/src/tests/register-parameter-compacting-tests.ts +84 -92
  27. package/src/tests/register-sync-tests.ts +375 -391
  28. package/tsconfig.tsbuildinfo +1 -1
@@ -7,8 +7,6 @@ import { parameterLookupScope } from './util.js';
7
7
  export function registerParameterCompactTests(config: storage.TestStorageConfig) {
8
8
  const generateStorageFactory = config.factory;
9
9
 
10
- const TEST_TABLE = test_utils.makeTestTable('test', ['id'], config);
11
-
12
10
  test('compacting parameters', async () => {
13
11
  await using factory = await generateStorageFactory();
14
12
  const syncRules = await factory.updateSyncRules(
@@ -20,60 +18,58 @@ bucket_definitions:
20
18
  `)
21
19
  );
22
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
+ });
23
33
 
24
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
25
- await batch.markAllSnapshotDone('1/1');
26
- await batch.save({
27
- sourceTable: TEST_TABLE,
28
- tag: storage.SaveOperationTag.INSERT,
29
- after: {
30
- id: 't1'
31
- },
32
- afterReplicaId: 't1'
33
- });
34
-
35
- await batch.save({
36
- sourceTable: TEST_TABLE,
37
- tag: storage.SaveOperationTag.INSERT,
38
- after: {
39
- id: 't2'
40
- },
41
- afterReplicaId: 't2'
42
- });
43
-
44
- 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'
45
41
  });
46
42
 
47
- const lookup = ScopedParameterLookup.direct(parameterLookupScope('test', '1'), ['t1']);
43
+ await writer.commit('1/1');
44
+
45
+ const lookup = ScopedParameterLookup.direct({ lookupName: 'test', queryId: '1', source: null as any }, ['t1']);
48
46
 
49
47
  const checkpoint1 = await bucketStorage.getCheckpoint();
50
48
  const parameters1 = await checkpoint1.getParameterSets([lookup]);
51
49
  expect(parameters1).toEqual([{ id: 't1' }]);
52
50
 
53
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
54
- await batch.save({
55
- sourceTable: TEST_TABLE,
56
- tag: storage.SaveOperationTag.UPDATE,
57
- before: {
58
- id: 't1'
59
- },
60
- beforeReplicaId: 't1',
61
- after: {
62
- id: 't1'
63
- },
64
- afterReplicaId: 't1'
65
- });
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
+ });
66
63
 
67
- await batch.save({
68
- sourceTable: TEST_TABLE,
69
- tag: storage.SaveOperationTag.DELETE,
70
- before: {
71
- id: 't1'
72
- },
73
- beforeReplicaId: 't1'
74
- });
75
- 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'
76
71
  });
72
+ await writer.commit('1/2');
77
73
  const checkpoint2 = await bucketStorage.getCheckpoint();
78
74
  const parameters2 = await checkpoint2.getParameterSets([lookup]);
79
75
  expect(parameters2).toEqual([]);
@@ -104,59 +100,55 @@ bucket_definitions:
104
100
  `)
105
101
  );
106
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);
107
105
 
108
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
109
- await batch.markAllSnapshotDone('1/1');
110
- await batch.save({
111
- sourceTable: TEST_TABLE,
112
- tag: storage.SaveOperationTag.INSERT,
113
- after: {
114
- id: 't1',
115
- uid: 'u1'
116
- },
117
- afterReplicaId: 't1'
118
- });
119
- // Interleave with another operation, to evict the other cache entry when compacting.
120
- await batch.save({
121
- sourceTable: TEST_TABLE,
122
- tag: storage.SaveOperationTag.INSERT,
123
- after: {
124
- id: 't2',
125
- uid: 'u1'
126
- },
127
- afterReplicaId: 't2'
128
- });
129
-
130
- 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'
131
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'
125
+ });
126
+
127
+ await writer.commit('1/1');
132
128
 
133
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
134
- await batch.save({
135
- sourceTable: TEST_TABLE,
136
- tag: storage.SaveOperationTag.DELETE,
137
- before: {
138
- id: 't1',
139
- uid: 'u1'
140
- },
141
- beforeReplicaId: 't1'
142
- });
143
- await batch.commit('2/1');
129
+ await writer.save({
130
+ sourceTable: testTable,
131
+ tag: storage.SaveOperationTag.DELETE,
132
+ before: {
133
+ id: 't1',
134
+ uid: 'u1'
135
+ },
136
+ beforeReplicaId: 't1'
144
137
  });
138
+ await writer.commit('2/1');
145
139
 
146
- await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
147
- await batch.save({
148
- sourceTable: TEST_TABLE,
149
- tag: storage.SaveOperationTag.UPDATE,
150
- after: {
151
- id: 't2',
152
- uid: 'u2'
153
- },
154
- afterReplicaId: 't2'
155
- });
156
- 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'
157
148
  });
149
+ await writer.commit('3/1');
158
150
 
159
- const lookup = ScopedParameterLookup.direct(parameterLookupScope('test', '1'), ['u1']);
151
+ const lookup = ScopedParameterLookup.direct({ lookupName: 'test', queryId: '1', source: null as any }, ['u1']);
160
152
 
161
153
  const checkpoint1 = await bucketStorage.getCheckpoint();
162
154
  const parameters1 = await checkpoint1.getParameterSets([lookup]);