@powersync/service-core-tests 0.15.1 → 0.15.3
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 +18 -0
- package/dist/tests/register-compacting-tests.js +491 -627
- package/dist/tests/register-compacting-tests.js.map +1 -1
- package/dist/tests/register-data-storage-checkpoint-tests.js +192 -304
- package/dist/tests/register-data-storage-checkpoint-tests.js.map +1 -1
- package/dist/tests/register-data-storage-data-tests.js +1105 -1444
- package/dist/tests/register-data-storage-data-tests.js.map +1 -1
- package/dist/tests/register-data-storage-parameter-tests.js +452 -636
- package/dist/tests/register-data-storage-parameter-tests.js.map +1 -1
- package/dist/tests/register-migration-tests.js +63 -139
- package/dist/tests/register-migration-tests.js.map +1 -1
- package/dist/tests/register-parameter-compacting-tests.js +94 -170
- package/dist/tests/register-parameter-compacting-tests.js.map +1 -1
- package/dist/tests/register-sync-tests.js +899 -1155
- package/dist/tests/register-sync-tests.js.map +1 -1
- package/package.json +5 -5
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,55 +1,3 @@
|
|
|
1
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
-
if (value !== null && value !== void 0) {
|
|
3
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose, inner;
|
|
5
|
-
if (async) {
|
|
6
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
-
dispose = value[Symbol.asyncDispose];
|
|
8
|
-
}
|
|
9
|
-
if (dispose === void 0) {
|
|
10
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
-
dispose = value[Symbol.dispose];
|
|
12
|
-
if (async) inner = dispose;
|
|
13
|
-
}
|
|
14
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
-
}
|
|
18
|
-
else if (async) {
|
|
19
|
-
env.stack.push({ async: true });
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
-
return function (env) {
|
|
25
|
-
function fail(e) {
|
|
26
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
-
env.hasError = true;
|
|
28
|
-
}
|
|
29
|
-
var r, s = 0;
|
|
30
|
-
function next() {
|
|
31
|
-
while (r = env.stack.pop()) {
|
|
32
|
-
try {
|
|
33
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
-
if (r.dispose) {
|
|
35
|
-
var result = r.dispose.call(r.value);
|
|
36
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
-
}
|
|
38
|
-
else s |= 1;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
fail(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
-
if (env.hasError) throw env.error;
|
|
46
|
-
}
|
|
47
|
-
return next();
|
|
48
|
-
};
|
|
49
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
-
var e = new Error(message);
|
|
51
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
-
});
|
|
53
1
|
import { CURRENT_STORAGE_VERSION, JwtPayload, storage, updateSyncRulesFromYaml } from '@powersync/service-core';
|
|
54
2
|
import { RequestParameters, ScopedParameterLookup } from '@powersync/service-sync-rules';
|
|
55
3
|
import { expect, test } from 'vitest';
|
|
@@ -71,131 +19,105 @@ export function registerDataStorageParameterTests(config) {
|
|
|
71
19
|
const storageVersion = config.storageVersion ?? CURRENT_STORAGE_VERSION;
|
|
72
20
|
const MYBUCKET_1 = parameterLookupScope('mybucket', '1');
|
|
73
21
|
test('save and load parameters', async () => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const factory = __addDisposableResource(env_1, await generateStorageFactory(), true);
|
|
77
|
-
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
22
|
+
await using factory = await generateStorageFactory();
|
|
23
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
78
24
|
bucket_definitions:
|
|
79
25
|
mybucket:
|
|
80
26
|
parameters:
|
|
81
27
|
- SELECT group_id FROM test WHERE id1 = token_parameters.user_id OR id2 = token_parameters.user_id
|
|
82
28
|
data: []
|
|
83
29
|
`, {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
catch (e_1) {
|
|
122
|
-
env_1.error = e_1;
|
|
123
|
-
env_1.hasError = true;
|
|
124
|
-
}
|
|
125
|
-
finally {
|
|
126
|
-
const result_1 = __disposeResources(env_1);
|
|
127
|
-
if (result_1)
|
|
128
|
-
await result_1;
|
|
129
|
-
}
|
|
30
|
+
storageVersion
|
|
31
|
+
}));
|
|
32
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
33
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
34
|
+
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
35
|
+
await writer.markAllSnapshotDone('1/1');
|
|
36
|
+
await writer.save({
|
|
37
|
+
sourceTable: testTable,
|
|
38
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
39
|
+
after: {
|
|
40
|
+
id: 't2',
|
|
41
|
+
id1: 'user3',
|
|
42
|
+
id2: 'user4',
|
|
43
|
+
group_id: 'group2a'
|
|
44
|
+
},
|
|
45
|
+
afterReplicaId: test_utils.rid('t2')
|
|
46
|
+
});
|
|
47
|
+
await writer.save({
|
|
48
|
+
sourceTable: testTable,
|
|
49
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
50
|
+
after: {
|
|
51
|
+
id: 't1',
|
|
52
|
+
id1: 'user1',
|
|
53
|
+
id2: 'user2',
|
|
54
|
+
group_id: 'group1a'
|
|
55
|
+
},
|
|
56
|
+
afterReplicaId: test_utils.rid('t1')
|
|
57
|
+
});
|
|
58
|
+
await writer.commit('1/1');
|
|
59
|
+
const checkpoint = await bucketStorage.getCheckpoint();
|
|
60
|
+
const parameters = await checkpoint.getParameterSets([ScopedParameterLookup.direct(MYBUCKET_1, ['user1'])]);
|
|
61
|
+
expect(parameters).toEqual([
|
|
62
|
+
{
|
|
63
|
+
group_id: 'group1a'
|
|
64
|
+
}
|
|
65
|
+
]);
|
|
130
66
|
});
|
|
131
67
|
test('it should use the latest version', async () => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const factory = __addDisposableResource(env_2, await generateStorageFactory(), true);
|
|
135
|
-
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
68
|
+
await using factory = await generateStorageFactory();
|
|
69
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
136
70
|
bucket_definitions:
|
|
137
71
|
mybucket:
|
|
138
72
|
parameters:
|
|
139
73
|
- SELECT group_id FROM test WHERE id = token_parameters.user_id
|
|
140
74
|
data: []
|
|
141
75
|
`, {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
catch (e_2) {
|
|
185
|
-
env_2.error = e_2;
|
|
186
|
-
env_2.hasError = true;
|
|
187
|
-
}
|
|
188
|
-
finally {
|
|
189
|
-
const result_2 = __disposeResources(env_2);
|
|
190
|
-
if (result_2)
|
|
191
|
-
await result_2;
|
|
192
|
-
}
|
|
76
|
+
storageVersion
|
|
77
|
+
}));
|
|
78
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
79
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
80
|
+
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
81
|
+
await writer.markAllSnapshotDone('1/1');
|
|
82
|
+
await writer.save({
|
|
83
|
+
sourceTable: testTable,
|
|
84
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
85
|
+
after: {
|
|
86
|
+
id: 'user1',
|
|
87
|
+
group_id: 'group1'
|
|
88
|
+
},
|
|
89
|
+
afterReplicaId: test_utils.rid('user1')
|
|
90
|
+
});
|
|
91
|
+
await writer.commit('1/1');
|
|
92
|
+
const checkpoint1 = await bucketStorage.getCheckpoint();
|
|
93
|
+
await writer.save({
|
|
94
|
+
sourceTable: testTable,
|
|
95
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
96
|
+
after: {
|
|
97
|
+
id: 'user1',
|
|
98
|
+
group_id: 'group2'
|
|
99
|
+
},
|
|
100
|
+
afterReplicaId: test_utils.rid('user1')
|
|
101
|
+
});
|
|
102
|
+
await writer.commit('1/2');
|
|
103
|
+
const checkpoint2 = await bucketStorage.getCheckpoint();
|
|
104
|
+
const parameters = await checkpoint2.getParameterSets([ScopedParameterLookup.direct(MYBUCKET_1, ['user1'])]);
|
|
105
|
+
expect(parameters).toEqual([
|
|
106
|
+
{
|
|
107
|
+
group_id: 'group2'
|
|
108
|
+
}
|
|
109
|
+
]);
|
|
110
|
+
// Use the checkpoint to get older data if relevant
|
|
111
|
+
const parameters2 = await checkpoint1.getParameterSets([ScopedParameterLookup.direct(MYBUCKET_1, ['user1'])]);
|
|
112
|
+
expect(parameters2).toEqual([
|
|
113
|
+
{
|
|
114
|
+
group_id: 'group1'
|
|
115
|
+
}
|
|
116
|
+
]);
|
|
193
117
|
});
|
|
194
118
|
test('it should use the latest version after updates', async () => {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const factory = __addDisposableResource(env_3, await generateStorageFactory(), true);
|
|
198
|
-
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
119
|
+
await using factory = await generateStorageFactory();
|
|
120
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
199
121
|
bucket_definitions:
|
|
200
122
|
mybucket:
|
|
201
123
|
parameters:
|
|
@@ -204,186 +126,150 @@ bucket_definitions:
|
|
|
204
126
|
WHERE list_id IN token_parameters.list_id
|
|
205
127
|
data: []
|
|
206
128
|
`, { storageVersion }));
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
catch (e_3) {
|
|
260
|
-
env_3.error = e_3;
|
|
261
|
-
env_3.hasError = true;
|
|
262
|
-
}
|
|
263
|
-
finally {
|
|
264
|
-
const result_3 = __disposeResources(env_3);
|
|
265
|
-
if (result_3)
|
|
266
|
-
await result_3;
|
|
267
|
-
}
|
|
129
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
130
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
131
|
+
const table = await test_utils.resolveTestTable(writer, 'todos', ['id', 'list_id'], config);
|
|
132
|
+
await writer.markAllSnapshotDone('1/1');
|
|
133
|
+
// Create two todos which initially belong to different lists
|
|
134
|
+
await writer.save({
|
|
135
|
+
sourceTable: table,
|
|
136
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
137
|
+
after: {
|
|
138
|
+
id: 'todo1',
|
|
139
|
+
list_id: 'list1'
|
|
140
|
+
},
|
|
141
|
+
afterReplicaId: test_utils.rid('todo1')
|
|
142
|
+
});
|
|
143
|
+
await writer.save({
|
|
144
|
+
sourceTable: table,
|
|
145
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
146
|
+
after: {
|
|
147
|
+
id: 'todo2',
|
|
148
|
+
list_id: 'list2'
|
|
149
|
+
},
|
|
150
|
+
afterReplicaId: test_utils.rid('todo2')
|
|
151
|
+
});
|
|
152
|
+
await writer.commit('1/1');
|
|
153
|
+
// Update the second todo item to now belong to list 1
|
|
154
|
+
await writer.save({
|
|
155
|
+
sourceTable: table,
|
|
156
|
+
tag: storage.SaveOperationTag.UPDATE,
|
|
157
|
+
after: {
|
|
158
|
+
id: 'todo2',
|
|
159
|
+
list_id: 'list1'
|
|
160
|
+
},
|
|
161
|
+
afterReplicaId: test_utils.rid('todo2')
|
|
162
|
+
});
|
|
163
|
+
await writer.commit('1/1');
|
|
164
|
+
// We specifically request the todo_ids for both lists.
|
|
165
|
+
// There removal operation for the association of `list2`::`todo2` should not interfere with the new
|
|
166
|
+
// association of `list1`::`todo2`
|
|
167
|
+
const checkpoint = await bucketStorage.getCheckpoint();
|
|
168
|
+
const parameters = await checkpoint.getParameterSets([
|
|
169
|
+
ScopedParameterLookup.direct(MYBUCKET_1, ['list1']),
|
|
170
|
+
ScopedParameterLookup.direct(MYBUCKET_1, ['list2'])
|
|
171
|
+
]);
|
|
172
|
+
expect(parameters.sort((a, b) => a.todo_id.localeCompare(b.todo_id))).toEqual([
|
|
173
|
+
{
|
|
174
|
+
todo_id: 'todo1'
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
todo_id: 'todo2'
|
|
178
|
+
}
|
|
179
|
+
]);
|
|
268
180
|
});
|
|
269
181
|
test('save and load parameters with different number types', async () => {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const factory = __addDisposableResource(env_4, await generateStorageFactory(), true);
|
|
273
|
-
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
182
|
+
await using factory = await generateStorageFactory();
|
|
183
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
274
184
|
bucket_definitions:
|
|
275
185
|
mybucket:
|
|
276
186
|
parameters:
|
|
277
187
|
- SELECT group_id FROM test WHERE n1 = token_parameters.n1 and f2 = token_parameters.f2 and f3 = token_parameters.f3
|
|
278
188
|
data: []
|
|
279
189
|
`, {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
catch (e_4) {
|
|
313
|
-
env_4.error = e_4;
|
|
314
|
-
env_4.hasError = true;
|
|
315
|
-
}
|
|
316
|
-
finally {
|
|
317
|
-
const result_4 = __disposeResources(env_4);
|
|
318
|
-
if (result_4)
|
|
319
|
-
await result_4;
|
|
320
|
-
}
|
|
190
|
+
storageVersion
|
|
191
|
+
}));
|
|
192
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
193
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
194
|
+
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
195
|
+
await writer.markAllSnapshotDone('1/1');
|
|
196
|
+
await writer.save({
|
|
197
|
+
sourceTable: testTable,
|
|
198
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
199
|
+
after: {
|
|
200
|
+
id: 't1',
|
|
201
|
+
group_id: 'group1',
|
|
202
|
+
n1: 314n,
|
|
203
|
+
f2: 314,
|
|
204
|
+
f3: 3.14
|
|
205
|
+
},
|
|
206
|
+
afterReplicaId: test_utils.rid('t1')
|
|
207
|
+
});
|
|
208
|
+
await writer.commit('1/1');
|
|
209
|
+
const TEST_PARAMS = { group_id: 'group1' };
|
|
210
|
+
const checkpoint = await bucketStorage.getCheckpoint();
|
|
211
|
+
const parameters1 = await checkpoint.getParameterSets([
|
|
212
|
+
ScopedParameterLookup.direct(MYBUCKET_1, [314n, 314, 3.14])
|
|
213
|
+
]);
|
|
214
|
+
expect(parameters1).toEqual([TEST_PARAMS]);
|
|
215
|
+
const parameters2 = await checkpoint.getParameterSets([
|
|
216
|
+
ScopedParameterLookup.direct(MYBUCKET_1, [314, 314n, 3.14])
|
|
217
|
+
]);
|
|
218
|
+
expect(parameters2).toEqual([TEST_PARAMS]);
|
|
219
|
+
const parameters3 = await checkpoint.getParameterSets([ScopedParameterLookup.direct(MYBUCKET_1, [314n, 314, 3])]);
|
|
220
|
+
expect(parameters3).toEqual([]);
|
|
321
221
|
});
|
|
322
222
|
test('save and load parameters with large numbers', async () => {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const factory = __addDisposableResource(env_5, await generateStorageFactory(), true);
|
|
329
|
-
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
223
|
+
// This ensures serialization / deserialization of "current_data" is done correctly.
|
|
224
|
+
// This specific case tested here cannot happen with postgres in practice, but we still
|
|
225
|
+
// test this to ensure correct deserialization.
|
|
226
|
+
await using factory = await generateStorageFactory();
|
|
227
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
330
228
|
bucket_definitions:
|
|
331
229
|
mybucket:
|
|
332
230
|
parameters:
|
|
333
231
|
- SELECT group_id FROM test WHERE n1 = token_parameters.n1
|
|
334
232
|
data: []
|
|
335
233
|
`, {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
catch (e_5) {
|
|
373
|
-
env_5.error = e_5;
|
|
374
|
-
env_5.hasError = true;
|
|
375
|
-
}
|
|
376
|
-
finally {
|
|
377
|
-
const result_5 = __disposeResources(env_5);
|
|
378
|
-
if (result_5)
|
|
379
|
-
await result_5;
|
|
380
|
-
}
|
|
234
|
+
storageVersion
|
|
235
|
+
}));
|
|
236
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
237
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
238
|
+
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
239
|
+
await writer.markAllSnapshotDone('1/1');
|
|
240
|
+
await writer.save({
|
|
241
|
+
sourceTable: testTable,
|
|
242
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
243
|
+
after: {
|
|
244
|
+
id: 't1',
|
|
245
|
+
group_id: 'group1',
|
|
246
|
+
n1: 1152921504606846976n // 2^60
|
|
247
|
+
},
|
|
248
|
+
afterReplicaId: test_utils.rid('t1')
|
|
249
|
+
});
|
|
250
|
+
await writer.save({
|
|
251
|
+
sourceTable: testTable,
|
|
252
|
+
tag: storage.SaveOperationTag.UPDATE,
|
|
253
|
+
after: {
|
|
254
|
+
id: 't1',
|
|
255
|
+
group_id: 'group1',
|
|
256
|
+
// Simulate a TOAST value, even though it can't happen for values like this
|
|
257
|
+
// in practice.
|
|
258
|
+
n1: undefined
|
|
259
|
+
},
|
|
260
|
+
afterReplicaId: test_utils.rid('t1')
|
|
261
|
+
});
|
|
262
|
+
await writer.commit('1/1');
|
|
263
|
+
const TEST_PARAMS = { group_id: 'group1' };
|
|
264
|
+
const checkpoint = await bucketStorage.getCheckpoint();
|
|
265
|
+
const parameters1 = await checkpoint.getParameterSets([
|
|
266
|
+
ScopedParameterLookup.direct(MYBUCKET_1, [1152921504606846976n])
|
|
267
|
+
]);
|
|
268
|
+
expect(parameters1).toEqual([TEST_PARAMS]);
|
|
381
269
|
});
|
|
382
270
|
test('save and load parameters with workspaceId', async () => {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const factory = __addDisposableResource(env_6, await generateStorageFactory(), true);
|
|
386
|
-
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
271
|
+
await using factory = await generateStorageFactory();
|
|
272
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
387
273
|
bucket_definitions:
|
|
388
274
|
by_workspace:
|
|
389
275
|
parameters:
|
|
@@ -391,58 +277,46 @@ bucket_definitions:
|
|
|
391
277
|
workspace."userId" = token_parameters.user_id
|
|
392
278
|
data: []
|
|
393
279
|
`, {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
431
|
-
catch (e_6) {
|
|
432
|
-
env_6.error = e_6;
|
|
433
|
-
env_6.hasError = true;
|
|
434
|
-
}
|
|
435
|
-
finally {
|
|
436
|
-
const result_6 = __disposeResources(env_6);
|
|
437
|
-
if (result_6)
|
|
438
|
-
await result_6;
|
|
439
|
-
}
|
|
280
|
+
storageVersion
|
|
281
|
+
}));
|
|
282
|
+
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncRules();
|
|
283
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
284
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
285
|
+
const workspaceTable = await test_utils.resolveTestTable(writer, 'workspace', ['id'], config);
|
|
286
|
+
await writer.markAllSnapshotDone('1/1');
|
|
287
|
+
await writer.save({
|
|
288
|
+
sourceTable: workspaceTable,
|
|
289
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
290
|
+
after: {
|
|
291
|
+
id: 'workspace1',
|
|
292
|
+
userId: 'u1'
|
|
293
|
+
},
|
|
294
|
+
afterReplicaId: test_utils.rid('workspace1')
|
|
295
|
+
});
|
|
296
|
+
await writer.commit('1/1');
|
|
297
|
+
const checkpoint = await bucketStorage.getCheckpoint();
|
|
298
|
+
const parameters = new RequestParameters(new JwtPayload({ sub: 'u1' }), {});
|
|
299
|
+
const querier = sync_rules.getBucketParameterQuerier(test_utils.querierOptions(parameters)).querier;
|
|
300
|
+
const buckets = await querier.queryDynamicBucketDescriptions({
|
|
301
|
+
async getParameterSets(lookups) {
|
|
302
|
+
expect(lookups).toEqual([ScopedParameterLookup.direct(parameterLookupScope('by_workspace', '1'), ['u1'])]);
|
|
303
|
+
const parameter_sets = await checkpoint.getParameterSets(lookups);
|
|
304
|
+
expect(parameter_sets).toEqual([{ workspace_id: 'workspace1' }]);
|
|
305
|
+
return parameter_sets;
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
expect(buckets).toEqual([
|
|
309
|
+
{
|
|
310
|
+
bucket: bucketRequest(syncRules, 'by_workspace["workspace1"]').bucket,
|
|
311
|
+
priority: 3,
|
|
312
|
+
definition: 'by_workspace',
|
|
313
|
+
inclusion_reasons: ['default']
|
|
314
|
+
}
|
|
315
|
+
]);
|
|
440
316
|
});
|
|
441
317
|
test('save and load parameters with dynamic global buckets', async () => {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
const factory = __addDisposableResource(env_7, await generateStorageFactory(), true);
|
|
445
|
-
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
318
|
+
await using factory = await generateStorageFactory();
|
|
319
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
446
320
|
bucket_definitions:
|
|
447
321
|
by_public_workspace:
|
|
448
322
|
parameters:
|
|
@@ -450,84 +324,72 @@ bucket_definitions:
|
|
|
450
324
|
workspace.visibility = 'public'
|
|
451
325
|
data: []
|
|
452
326
|
`, {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
catch (e_7) {
|
|
517
|
-
env_7.error = e_7;
|
|
518
|
-
env_7.hasError = true;
|
|
519
|
-
}
|
|
520
|
-
finally {
|
|
521
|
-
const result_7 = __disposeResources(env_7);
|
|
522
|
-
if (result_7)
|
|
523
|
-
await result_7;
|
|
524
|
-
}
|
|
327
|
+
storageVersion
|
|
328
|
+
}));
|
|
329
|
+
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncRules();
|
|
330
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
331
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
332
|
+
const workspaceTable = await test_utils.resolveTestTable(writer, 'workspace', undefined, config);
|
|
333
|
+
await writer.markAllSnapshotDone('1/1');
|
|
334
|
+
await writer.save({
|
|
335
|
+
sourceTable: workspaceTable,
|
|
336
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
337
|
+
after: {
|
|
338
|
+
id: 'workspace1',
|
|
339
|
+
visibility: 'public'
|
|
340
|
+
},
|
|
341
|
+
afterReplicaId: test_utils.rid('workspace1')
|
|
342
|
+
});
|
|
343
|
+
await writer.save({
|
|
344
|
+
sourceTable: workspaceTable,
|
|
345
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
346
|
+
after: {
|
|
347
|
+
id: 'workspace2',
|
|
348
|
+
visibility: 'private'
|
|
349
|
+
},
|
|
350
|
+
afterReplicaId: test_utils.rid('workspace2')
|
|
351
|
+
});
|
|
352
|
+
await writer.save({
|
|
353
|
+
sourceTable: workspaceTable,
|
|
354
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
355
|
+
after: {
|
|
356
|
+
id: 'workspace3',
|
|
357
|
+
visibility: 'public'
|
|
358
|
+
},
|
|
359
|
+
afterReplicaId: test_utils.rid('workspace3')
|
|
360
|
+
});
|
|
361
|
+
await writer.commit('1/1');
|
|
362
|
+
const checkpoint = await bucketStorage.getCheckpoint();
|
|
363
|
+
const parameters = new RequestParameters(new JwtPayload({ sub: 'unknown' }), {});
|
|
364
|
+
const querier = sync_rules.getBucketParameterQuerier(test_utils.querierOptions(parameters)).querier;
|
|
365
|
+
const buckets = await querier.queryDynamicBucketDescriptions({
|
|
366
|
+
async getParameterSets(lookups) {
|
|
367
|
+
expect(lookups).toEqual([ScopedParameterLookup.direct(parameterLookupScope('by_public_workspace', '1'), [])]);
|
|
368
|
+
const parameter_sets = await checkpoint.getParameterSets(lookups);
|
|
369
|
+
parameter_sets.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
|
|
370
|
+
expect(parameter_sets).toEqual([{ workspace_id: 'workspace1' }, { workspace_id: 'workspace3' }]);
|
|
371
|
+
return parameter_sets;
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
buckets.sort((a, b) => a.bucket.localeCompare(b.bucket));
|
|
375
|
+
expect(buckets).toEqual([
|
|
376
|
+
{
|
|
377
|
+
bucket: bucketRequest(syncRules, 'by_public_workspace["workspace1"]').bucket,
|
|
378
|
+
priority: 3,
|
|
379
|
+
definition: 'by_public_workspace',
|
|
380
|
+
inclusion_reasons: ['default']
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
bucket: bucketRequest(syncRules, 'by_public_workspace["workspace3"]').bucket,
|
|
384
|
+
priority: 3,
|
|
385
|
+
definition: 'by_public_workspace',
|
|
386
|
+
inclusion_reasons: ['default']
|
|
387
|
+
}
|
|
388
|
+
]);
|
|
525
389
|
});
|
|
526
390
|
test('multiple parameter queries', async () => {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
const factory = __addDisposableResource(env_8, await generateStorageFactory(), true);
|
|
530
|
-
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
391
|
+
await using factory = await generateStorageFactory();
|
|
392
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
531
393
|
bucket_definitions:
|
|
532
394
|
by_workspace:
|
|
533
395
|
parameters:
|
|
@@ -537,138 +399,114 @@ bucket_definitions:
|
|
|
537
399
|
workspace.user_id = token_parameters.user_id
|
|
538
400
|
data: []
|
|
539
401
|
`, {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
}
|
|
613
|
-
catch (e_8) {
|
|
614
|
-
env_8.error = e_8;
|
|
615
|
-
env_8.hasError = true;
|
|
616
|
-
}
|
|
617
|
-
finally {
|
|
618
|
-
const result_8 = __disposeResources(env_8);
|
|
619
|
-
if (result_8)
|
|
620
|
-
await result_8;
|
|
621
|
-
}
|
|
402
|
+
storageVersion
|
|
403
|
+
}));
|
|
404
|
+
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncRules();
|
|
405
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
406
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
407
|
+
const workspaceTable = await test_utils.resolveTestTable(writer, 'workspace', undefined, config);
|
|
408
|
+
await writer.markAllSnapshotDone('1/1');
|
|
409
|
+
await writer.save({
|
|
410
|
+
sourceTable: workspaceTable,
|
|
411
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
412
|
+
after: {
|
|
413
|
+
id: 'workspace1',
|
|
414
|
+
visibility: 'public'
|
|
415
|
+
},
|
|
416
|
+
afterReplicaId: test_utils.rid('workspace1')
|
|
417
|
+
});
|
|
418
|
+
await writer.save({
|
|
419
|
+
sourceTable: workspaceTable,
|
|
420
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
421
|
+
after: {
|
|
422
|
+
id: 'workspace2',
|
|
423
|
+
visibility: 'private'
|
|
424
|
+
},
|
|
425
|
+
afterReplicaId: test_utils.rid('workspace2')
|
|
426
|
+
});
|
|
427
|
+
await writer.save({
|
|
428
|
+
sourceTable: workspaceTable,
|
|
429
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
430
|
+
after: {
|
|
431
|
+
id: 'workspace3',
|
|
432
|
+
user_id: 'u1',
|
|
433
|
+
visibility: 'private'
|
|
434
|
+
},
|
|
435
|
+
afterReplicaId: test_utils.rid('workspace3')
|
|
436
|
+
});
|
|
437
|
+
await writer.save({
|
|
438
|
+
sourceTable: workspaceTable,
|
|
439
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
440
|
+
after: {
|
|
441
|
+
id: 'workspace4',
|
|
442
|
+
user_id: 'u2',
|
|
443
|
+
visibility: 'private'
|
|
444
|
+
},
|
|
445
|
+
afterReplicaId: test_utils.rid('workspace4')
|
|
446
|
+
});
|
|
447
|
+
await writer.commit('1/1');
|
|
448
|
+
const checkpoint = await bucketStorage.getCheckpoint();
|
|
449
|
+
const parameters = new RequestParameters(new JwtPayload({ sub: 'u1' }), {});
|
|
450
|
+
// Test intermediate values - could be moved to sync_rules.test.ts
|
|
451
|
+
const querier = sync_rules.getBucketParameterQuerier(test_utils.querierOptions(parameters)).querier;
|
|
452
|
+
// Test final values - the important part
|
|
453
|
+
const foundLookups = [];
|
|
454
|
+
const parameter_sets = [];
|
|
455
|
+
const buckets = (await querier.queryDynamicBucketDescriptions({
|
|
456
|
+
async getParameterSets(lookups) {
|
|
457
|
+
foundLookups.push(...lookups);
|
|
458
|
+
const output = await checkpoint.getParameterSets(lookups);
|
|
459
|
+
parameter_sets.push(...output);
|
|
460
|
+
return output;
|
|
461
|
+
}
|
|
462
|
+
})).map((e) => e.bucket);
|
|
463
|
+
expect(foundLookups).toEqual([
|
|
464
|
+
ScopedParameterLookup.direct(parameterLookupScope('by_workspace', '1'), []),
|
|
465
|
+
ScopedParameterLookup.direct(parameterLookupScope('by_workspace', '2'), ['u1'])
|
|
466
|
+
]);
|
|
467
|
+
parameter_sets.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
|
|
468
|
+
expect(parameter_sets).toEqual([{ workspace_id: 'workspace1' }, { workspace_id: 'workspace3' }]);
|
|
469
|
+
buckets.sort();
|
|
470
|
+
expect(buckets).toEqual([
|
|
471
|
+
bucketRequest(syncRules, 'by_workspace["workspace1"]').bucket,
|
|
472
|
+
bucketRequest(syncRules, 'by_workspace["workspace3"]').bucket
|
|
473
|
+
]);
|
|
622
474
|
});
|
|
623
475
|
test('truncate parameters', async () => {
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
const factory = __addDisposableResource(env_9, await generateStorageFactory(), true);
|
|
627
|
-
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
476
|
+
await using factory = await generateStorageFactory();
|
|
477
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
628
478
|
bucket_definitions:
|
|
629
479
|
mybucket:
|
|
630
480
|
parameters:
|
|
631
481
|
- SELECT group_id FROM test WHERE id1 = token_parameters.user_id OR id2 = token_parameters.user_id
|
|
632
482
|
data: []
|
|
633
483
|
`, {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
657
|
-
catch (e_9) {
|
|
658
|
-
env_9.error = e_9;
|
|
659
|
-
env_9.hasError = true;
|
|
660
|
-
}
|
|
661
|
-
finally {
|
|
662
|
-
const result_9 = __disposeResources(env_9);
|
|
663
|
-
if (result_9)
|
|
664
|
-
await result_9;
|
|
665
|
-
}
|
|
484
|
+
storageVersion
|
|
485
|
+
}));
|
|
486
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
487
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
488
|
+
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
489
|
+
await writer.markAllSnapshotDone('1/1');
|
|
490
|
+
await writer.save({
|
|
491
|
+
sourceTable: testTable,
|
|
492
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
493
|
+
after: {
|
|
494
|
+
id: 't2',
|
|
495
|
+
id1: 'user3',
|
|
496
|
+
id2: 'user4',
|
|
497
|
+
group_id: 'group2a'
|
|
498
|
+
},
|
|
499
|
+
afterReplicaId: test_utils.rid('t2')
|
|
500
|
+
});
|
|
501
|
+
await writer.truncate([testTable]);
|
|
502
|
+
await writer.flush();
|
|
503
|
+
const checkpoint = await bucketStorage.getCheckpoint();
|
|
504
|
+
const parameters = await checkpoint.getParameterSets([ScopedParameterLookup.direct(MYBUCKET_1, ['user1'])]);
|
|
505
|
+
expect(parameters).toEqual([]);
|
|
666
506
|
});
|
|
667
507
|
test('invalidate cached parsed sync rules', async () => {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
const bucketStorageFactory = __addDisposableResource(env_10, await generateStorageFactory(), true);
|
|
671
|
-
const syncRules = await bucketStorageFactory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
508
|
+
await using bucketStorageFactory = await generateStorageFactory();
|
|
509
|
+
const syncRules = await bucketStorageFactory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
672
510
|
bucket_definitions:
|
|
673
511
|
by_workspace:
|
|
674
512
|
parameters:
|
|
@@ -676,40 +514,28 @@ bucket_definitions:
|
|
|
676
514
|
workspace."userId" = token_parameters.user_id
|
|
677
515
|
data: []
|
|
678
516
|
`, {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
}
|
|
698
|
-
catch (e_10) {
|
|
699
|
-
env_10.error = e_10;
|
|
700
|
-
env_10.hasError = true;
|
|
701
|
-
}
|
|
702
|
-
finally {
|
|
703
|
-
const result_10 = __disposeResources(env_10);
|
|
704
|
-
if (result_10)
|
|
705
|
-
await result_10;
|
|
706
|
-
}
|
|
517
|
+
storageVersion
|
|
518
|
+
}));
|
|
519
|
+
const syncBucketStorage = bucketStorageFactory.getInstance(syncRules);
|
|
520
|
+
const parsedSchema1 = syncBucketStorage.getParsedSyncRules({
|
|
521
|
+
defaultSchema: 'public'
|
|
522
|
+
});
|
|
523
|
+
const parsedSchema2 = syncBucketStorage.getParsedSyncRules({
|
|
524
|
+
defaultSchema: 'public'
|
|
525
|
+
});
|
|
526
|
+
// These should be cached, this will be the same instance
|
|
527
|
+
expect(parsedSchema2).equals(parsedSchema1);
|
|
528
|
+
expect(parsedSchema1.getSourceTables()[0].schema).equals('public');
|
|
529
|
+
const parsedSchema3 = syncBucketStorage.getParsedSyncRules({
|
|
530
|
+
defaultSchema: 'databasename'
|
|
531
|
+
});
|
|
532
|
+
// The cache should not be used
|
|
533
|
+
expect(parsedSchema3).not.equals(parsedSchema2);
|
|
534
|
+
expect(parsedSchema3.getSourceTables()[0].schema).equals('databasename');
|
|
707
535
|
});
|
|
708
536
|
test('sync streams smoke test', async () => {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
const factory = __addDisposableResource(env_11, await generateStorageFactory(), true);
|
|
712
|
-
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
537
|
+
await using factory = await generateStorageFactory();
|
|
538
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(`
|
|
713
539
|
config:
|
|
714
540
|
edition: 3
|
|
715
541
|
|
|
@@ -719,39 +545,29 @@ streams:
|
|
|
719
545
|
SELECT data.* FROM test AS data, test AS param
|
|
720
546
|
WHERE data.foo = param.bar AND param.baz = auth.user_id()
|
|
721
547
|
`));
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
}
|
|
746
|
-
catch (e_11) {
|
|
747
|
-
env_11.error = e_11;
|
|
748
|
-
env_11.hasError = true;
|
|
749
|
-
}
|
|
750
|
-
finally {
|
|
751
|
-
const result_11 = __disposeResources(env_11);
|
|
752
|
-
if (result_11)
|
|
753
|
-
await result_11;
|
|
754
|
-
}
|
|
548
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
549
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
550
|
+
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
551
|
+
await writer.markAllSnapshotDone('1/1');
|
|
552
|
+
await writer.save({
|
|
553
|
+
sourceTable: testTable,
|
|
554
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
555
|
+
after: {
|
|
556
|
+
baz: 'baz',
|
|
557
|
+
bar: 'bar'
|
|
558
|
+
},
|
|
559
|
+
afterReplicaId: test_utils.rid('t1')
|
|
560
|
+
});
|
|
561
|
+
await writer.commit('1/1');
|
|
562
|
+
const checkpoint = await bucketStorage.getCheckpoint();
|
|
563
|
+
const parameters = await checkpoint.getParameterSets([
|
|
564
|
+
ScopedParameterLookup.direct(parameterLookupScope('lookup', '0'), ['baz'])
|
|
565
|
+
]);
|
|
566
|
+
expect(parameters).toEqual([
|
|
567
|
+
{
|
|
568
|
+
'0': 'bar'
|
|
569
|
+
}
|
|
570
|
+
]);
|
|
755
571
|
});
|
|
756
572
|
}
|
|
757
573
|
//# sourceMappingURL=register-data-storage-parameter-tests.js.map
|