@powersync/service-core-tests 0.0.0-dev-20260225160713 → 0.0.0-dev-20260313100403

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 +39 -3
  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/tests/register-compacting-tests.d.ts +1 -1
  6. package/dist/tests/register-compacting-tests.js +360 -297
  7. package/dist/tests/register-compacting-tests.js.map +1 -1
  8. package/dist/tests/register-data-storage-checkpoint-tests.d.ts +1 -1
  9. package/dist/tests/register-data-storage-checkpoint-tests.js +59 -48
  10. package/dist/tests/register-data-storage-checkpoint-tests.js.map +1 -1
  11. package/dist/tests/register-data-storage-data-tests.d.ts +2 -2
  12. package/dist/tests/register-data-storage-data-tests.js +1112 -612
  13. package/dist/tests/register-data-storage-data-tests.js.map +1 -1
  14. package/dist/tests/register-data-storage-parameter-tests.d.ts +1 -1
  15. package/dist/tests/register-data-storage-parameter-tests.js +273 -254
  16. package/dist/tests/register-data-storage-parameter-tests.js.map +1 -1
  17. package/dist/tests/register-parameter-compacting-tests.d.ts +1 -1
  18. package/dist/tests/register-parameter-compacting-tests.js +83 -87
  19. package/dist/tests/register-parameter-compacting-tests.js.map +1 -1
  20. package/dist/tests/register-report-tests.js +22 -22
  21. package/dist/tests/register-report-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/tests/register-compacting-tests.ts +376 -322
  31. package/src/tests/register-data-storage-checkpoint-tests.ts +85 -53
  32. package/src/tests/register-data-storage-data-tests.ts +1050 -559
  33. package/src/tests/register-data-storage-parameter-tests.ts +330 -288
  34. package/src/tests/register-parameter-compacting-tests.ts +87 -90
  35. package/src/tests/register-report-tests.ts +22 -22
  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]);
@@ -117,35 +117,35 @@ const removeVolatileFields = <T>(connections: LocalConnection[]) => {
117
117
  };
118
118
 
119
119
  export async function registerReportTests(factory: storage.ReportStorage) {
120
- it('Should show currently connected users', async () => {
121
- const current = await factory.getConnectedClients();
120
+ it('getCurrentConnections returns current connections', async () => {
121
+ const current = await factory.getCurrentConnections();
122
122
  expect(current).toMatchSnapshot();
123
123
  });
124
124
 
125
- it('Should show connection report data for user over the past month', async () => {
126
- const sdk = await factory.getClientConnectionReports({
125
+ it('getClientConnectionsSummary returns the past month summary', async () => {
126
+ const sdk = await factory.getClientConnectionsSummary({
127
127
  start: monthAgo,
128
128
  end: now
129
129
  });
130
130
  expect(sdk).toMatchSnapshot();
131
131
  });
132
- it('Should show connection report data for user over the past week', async () => {
133
- const sdk = await factory.getClientConnectionReports({
132
+ it('getClientConnectionsSummary returns the past week summary', async () => {
133
+ const sdk = await factory.getClientConnectionsSummary({
134
134
  start: weekAgo,
135
135
  end: now
136
136
  });
137
137
  expect(sdk).toMatchSnapshot();
138
138
  });
139
- it('Should show connection report data for user over the past day', async () => {
140
- const sdk = await factory.getClientConnectionReports({
139
+ it('getClientConnectionsSummary returns the past day summary', async () => {
140
+ const sdk = await factory.getClientConnectionsSummary({
141
141
  start: dayAgo,
142
142
  end: now
143
143
  });
144
144
  expect(sdk).toMatchSnapshot();
145
145
  });
146
146
 
147
- it('Should show paginated response of all connections of specified client_id', async () => {
148
- const connections = await factory.getGeneralClientConnectionAnalytics({
147
+ it('getClientSessions returns sessions for a client_id', async () => {
148
+ const connections = await factory.getClientSessions({
149
149
  client_id: user_two.client_id
150
150
  });
151
151
  const cleaned = {
@@ -155,8 +155,8 @@ export async function registerReportTests(factory: storage.ReportStorage) {
155
155
  expect(cleaned).toMatchSnapshot();
156
156
  });
157
157
 
158
- it('Should show paginated response of connections of specified user_id', async () => {
159
- const connections = await factory.getGeneralClientConnectionAnalytics({
158
+ it('getClientSessions returns sessions for a user_id', async () => {
159
+ const connections = await factory.getClientSessions({
160
160
  user_id: user_one.user_id
161
161
  });
162
162
 
@@ -167,8 +167,8 @@ export async function registerReportTests(factory: storage.ReportStorage) {
167
167
  expect(cleaned).toMatchSnapshot();
168
168
  });
169
169
 
170
- it('Should show paginated response of connections over a date range', async () => {
171
- const connections = await factory.getGeneralClientConnectionAnalytics({
170
+ it('getClientSessions returns sessions for a date range', async () => {
171
+ const connections = await factory.getClientSessions({
172
172
  date_range: {
173
173
  start: weekAgo,
174
174
  end: now
@@ -182,8 +182,8 @@ export async function registerReportTests(factory: storage.ReportStorage) {
182
182
  expect(cleaned).toMatchSnapshot();
183
183
  });
184
184
 
185
- it('Should show paginated response of connections over a date range of specified client_id and user_id', async () => {
186
- const connections = await factory.getGeneralClientConnectionAnalytics({
185
+ it('getClientSessions returns sessions for client_id and user_id within a date range', async () => {
186
+ const connections = await factory.getClientSessions({
187
187
  client_id: user_one.client_id,
188
188
  user_id: user_one.user_id,
189
189
  date_range: {
@@ -199,8 +199,8 @@ export async function registerReportTests(factory: storage.ReportStorage) {
199
199
  expect(cleaned).toMatchSnapshot();
200
200
  });
201
201
 
202
- it('Should show paginated response of all connections with a limit', async () => {
203
- const initial = await factory.getGeneralClientConnectionAnalytics({
202
+ it('getClientSessions returns paginated sessions with a limit', async () => {
203
+ const initial = await factory.getClientSessions({
204
204
  limit: 4
205
205
  });
206
206
 
@@ -212,7 +212,7 @@ export async function registerReportTests(factory: storage.ReportStorage) {
212
212
  items: removeVolatileFields(initial.items)
213
213
  };
214
214
  expect(cleanedInitial).toMatchSnapshot();
215
- const connections = await factory.getGeneralClientConnectionAnalytics({
215
+ const connections = await factory.getClientSessions({
216
216
  cursor
217
217
  });
218
218
  const cleaned = {
@@ -222,12 +222,12 @@ export async function registerReportTests(factory: storage.ReportStorage) {
222
222
  expect(cleaned).toMatchSnapshot();
223
223
  });
224
224
 
225
- it('Should show paginated response of all connections with a limit with date range', async () => {
225
+ it('getClientSessions returns paginated sessions with a limit and date range', async () => {
226
226
  const date_range = {
227
227
  start: monthAgo,
228
228
  end: nowLess5minutes
229
229
  };
230
- const initial = await factory.getGeneralClientConnectionAnalytics({
230
+ const initial = await factory.getClientSessions({
231
231
  limit: 4,
232
232
  date_range
233
233
  });
@@ -241,7 +241,7 @@ export async function registerReportTests(factory: storage.ReportStorage) {
241
241
  items: removeVolatileFields(initial.items)
242
242
  };
243
243
  expect(cleanedInitial).toMatchSnapshot();
244
- const connections = await factory.getGeneralClientConnectionAnalytics({
244
+ const connections = await factory.getClientSessions({
245
245
  cursor,
246
246
  date_range
247
247
  });