@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.
- package/CHANGELOG.md +39 -3
- package/dist/test-utils/general-utils.d.ts +22 -3
- package/dist/test-utils/general-utils.js +56 -3
- 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 +360 -297
- 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 +59 -48
- 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 +1112 -612
- 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 +273 -254
- 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 +83 -87
- package/dist/tests/register-parameter-compacting-tests.js.map +1 -1
- package/dist/tests/register-report-tests.js +22 -22
- package/dist/tests/register-report-tests.js.map +1 -1
- package/dist/tests/register-sync-tests.d.ts +2 -1
- package/dist/tests/register-sync-tests.js +479 -451
- 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 +81 -4
- package/src/tests/register-compacting-tests.ts +376 -322
- package/src/tests/register-data-storage-checkpoint-tests.ts +85 -53
- package/src/tests/register-data-storage-data-tests.ts +1050 -559
- package/src/tests/register-data-storage-parameter-tests.ts +330 -288
- package/src/tests/register-parameter-compacting-tests.ts +87 -90
- package/src/tests/register-report-tests.ts +22 -22
- package/src/tests/register-sync-tests.ts +390 -380
- package/src/tests/util.ts +46 -17
- 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
|
-
|
|
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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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('
|
|
121
|
-
const current = await factory.
|
|
120
|
+
it('getCurrentConnections returns current connections', async () => {
|
|
121
|
+
const current = await factory.getCurrentConnections();
|
|
122
122
|
expect(current).toMatchSnapshot();
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
-
it('
|
|
126
|
-
const sdk = await factory.
|
|
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('
|
|
133
|
-
const sdk = await factory.
|
|
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('
|
|
140
|
-
const sdk = await factory.
|
|
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('
|
|
148
|
-
const connections = await factory.
|
|
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('
|
|
159
|
-
const connections = await factory.
|
|
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('
|
|
171
|
-
const connections = await factory.
|
|
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('
|
|
186
|
-
const connections = await factory.
|
|
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('
|
|
203
|
-
const initial = await factory.
|
|
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.
|
|
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('
|
|
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.
|
|
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.
|
|
244
|
+
const connections = await factory.getClientSessions({
|
|
245
245
|
cursor,
|
|
246
246
|
date_range
|
|
247
247
|
});
|