@powersync/service-module-postgres-storage 0.3.0 → 0.4.0
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 +26 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/storage/PostgresBucketStorageFactory.d.ts +4 -8
- package/dist/@types/storage/PostgresSyncRulesStorage.d.ts +9 -3
- package/dist/@types/storage/batch/PostgresBucketBatch.d.ts +3 -2
- package/dist/storage/PostgresBucketStorageFactory.js +18 -134
- package/dist/storage/PostgresBucketStorageFactory.js.map +1 -1
- package/dist/storage/PostgresSyncRulesStorage.js +141 -90
- package/dist/storage/PostgresSyncRulesStorage.js.map +1 -1
- package/dist/storage/batch/PostgresBucketBatch.js +5 -2
- package/dist/storage/batch/PostgresBucketBatch.js.map +1 -1
- package/package.json +6 -6
- package/src/storage/PostgresBucketStorageFactory.ts +17 -152
- package/src/storage/PostgresSyncRulesStorage.ts +151 -4
- package/src/storage/batch/PostgresBucketBatch.ts +6 -2
- package/test/src/__snapshots__/storage_sync.test.ts.snap +82 -0
- package/test/src/storage.test.ts +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
2
2
|
import {
|
|
3
|
+
BaseObserver,
|
|
3
4
|
container,
|
|
4
|
-
DisposableObserver,
|
|
5
5
|
ErrorCode,
|
|
6
6
|
errors,
|
|
7
7
|
logger,
|
|
@@ -51,7 +51,7 @@ type StatefulCheckpointDecoded = t.Decoded<typeof StatefulCheckpoint>;
|
|
|
51
51
|
const MAX_ROW_SIZE = 15 * 1024 * 1024;
|
|
52
52
|
|
|
53
53
|
export class PostgresBucketBatch
|
|
54
|
-
extends
|
|
54
|
+
extends BaseObserver<storage.BucketBatchStorageListener>
|
|
55
55
|
implements storage.BucketStorageBatch
|
|
56
56
|
{
|
|
57
57
|
public last_flushed_op: bigint | null = null;
|
|
@@ -87,6 +87,10 @@ export class PostgresBucketBatch
|
|
|
87
87
|
return this.last_checkpoint_lsn;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
async [Symbol.asyncDispose]() {
|
|
91
|
+
super.clearListeners();
|
|
92
|
+
}
|
|
93
|
+
|
|
90
94
|
async save(record: storage.SaveOptions): Promise<storage.FlushedResult | null> {
|
|
91
95
|
// TODO maybe share with abstract class
|
|
92
96
|
const { after, before, sourceTable, tag } = record;
|
|
@@ -9,6 +9,7 @@ exports[`sync - postgres > compacting data - invalidate checkpoint 1`] = `
|
|
|
9
9
|
"bucket": "mybucket[]",
|
|
10
10
|
"checksum": -93886621,
|
|
11
11
|
"count": 2,
|
|
12
|
+
"priority": 3,
|
|
12
13
|
},
|
|
13
14
|
],
|
|
14
15
|
"last_op_id": "2",
|
|
@@ -44,6 +45,7 @@ exports[`sync - postgres > compacting data - invalidate checkpoint 2`] = `
|
|
|
44
45
|
"bucket": "mybucket[]",
|
|
45
46
|
"checksum": 499012468,
|
|
46
47
|
"count": 4,
|
|
48
|
+
"priority": 3,
|
|
47
49
|
},
|
|
48
50
|
],
|
|
49
51
|
"write_checkpoint": undefined,
|
|
@@ -102,6 +104,7 @@ exports[`sync - postgres > expiring token 1`] = `
|
|
|
102
104
|
"bucket": "mybucket[]",
|
|
103
105
|
"checksum": 0,
|
|
104
106
|
"count": 0,
|
|
107
|
+
"priority": 3,
|
|
105
108
|
},
|
|
106
109
|
],
|
|
107
110
|
"last_op_id": "0",
|
|
@@ -124,6 +127,80 @@ exports[`sync - postgres > expiring token 2`] = `
|
|
|
124
127
|
]
|
|
125
128
|
`;
|
|
126
129
|
|
|
130
|
+
exports[`sync - postgres > sync buckets in order 1`] = `
|
|
131
|
+
[
|
|
132
|
+
{
|
|
133
|
+
"checkpoint": {
|
|
134
|
+
"buckets": [
|
|
135
|
+
{
|
|
136
|
+
"bucket": "b0[]",
|
|
137
|
+
"checksum": 920318466,
|
|
138
|
+
"count": 1,
|
|
139
|
+
"priority": 2,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"bucket": "b1[]",
|
|
143
|
+
"checksum": -1382098757,
|
|
144
|
+
"count": 1,
|
|
145
|
+
"priority": 1,
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
"last_op_id": "2",
|
|
149
|
+
"write_checkpoint": undefined,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"data": {
|
|
154
|
+
"after": "0",
|
|
155
|
+
"bucket": "b1[]",
|
|
156
|
+
"data": [
|
|
157
|
+
{
|
|
158
|
+
"checksum": 2912868539n,
|
|
159
|
+
"data": "{"id":"earlier","description":"Test 2"}",
|
|
160
|
+
"object_id": "earlier",
|
|
161
|
+
"object_type": "test",
|
|
162
|
+
"op": "PUT",
|
|
163
|
+
"op_id": "2",
|
|
164
|
+
"subkey": "243b0e26-87b2-578a-993c-5ac5b6f7fd64",
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
"has_more": false,
|
|
168
|
+
"next_after": "2",
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"partial_checkpoint_complete": {
|
|
173
|
+
"last_op_id": "2",
|
|
174
|
+
"priority": 1,
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"data": {
|
|
179
|
+
"after": "0",
|
|
180
|
+
"bucket": "b0[]",
|
|
181
|
+
"data": [
|
|
182
|
+
{
|
|
183
|
+
"checksum": 920318466n,
|
|
184
|
+
"data": "{"id":"t1","description":"Test 1"}",
|
|
185
|
+
"object_id": "t1",
|
|
186
|
+
"object_type": "test",
|
|
187
|
+
"op": "PUT",
|
|
188
|
+
"op_id": "1",
|
|
189
|
+
"subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
"has_more": false,
|
|
193
|
+
"next_after": "1",
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"checkpoint_complete": {
|
|
198
|
+
"last_op_id": "2",
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
]
|
|
202
|
+
`;
|
|
203
|
+
|
|
127
204
|
exports[`sync - postgres > sync global data 1`] = `
|
|
128
205
|
[
|
|
129
206
|
{
|
|
@@ -133,6 +210,7 @@ exports[`sync - postgres > sync global data 1`] = `
|
|
|
133
210
|
"bucket": "mybucket[]",
|
|
134
211
|
"checksum": -93886621,
|
|
135
212
|
"count": 2,
|
|
213
|
+
"priority": 3,
|
|
136
214
|
},
|
|
137
215
|
],
|
|
138
216
|
"last_op_id": "2",
|
|
@@ -184,6 +262,7 @@ exports[`sync - postgres > sync legacy non-raw data 1`] = `
|
|
|
184
262
|
"bucket": "mybucket[]",
|
|
185
263
|
"checksum": -852817836,
|
|
186
264
|
"count": 1,
|
|
265
|
+
"priority": 3,
|
|
187
266
|
},
|
|
188
267
|
],
|
|
189
268
|
"last_op_id": "1",
|
|
@@ -231,6 +310,7 @@ exports[`sync - postgres > sync updates to global data 1`] = `
|
|
|
231
310
|
"bucket": "mybucket[]",
|
|
232
311
|
"checksum": 0,
|
|
233
312
|
"count": 0,
|
|
313
|
+
"priority": 3,
|
|
234
314
|
},
|
|
235
315
|
],
|
|
236
316
|
"last_op_id": "0",
|
|
@@ -256,6 +336,7 @@ exports[`sync - postgres > sync updates to global data 2`] = `
|
|
|
256
336
|
"bucket": "mybucket[]",
|
|
257
337
|
"checksum": 920318466,
|
|
258
338
|
"count": 1,
|
|
339
|
+
"priority": 3,
|
|
259
340
|
},
|
|
260
341
|
],
|
|
261
342
|
"write_checkpoint": undefined,
|
|
@@ -299,6 +380,7 @@ exports[`sync - postgres > sync updates to global data 3`] = `
|
|
|
299
380
|
"bucket": "mybucket[]",
|
|
300
381
|
"checksum": -93886621,
|
|
301
382
|
"count": 2,
|
|
383
|
+
"priority": 3,
|
|
302
384
|
},
|
|
303
385
|
],
|
|
304
386
|
"write_checkpoint": undefined,
|
package/test/src/storage.test.ts
CHANGED
|
@@ -26,7 +26,7 @@ describe('Postgres Sync Bucket Storage', () => {
|
|
|
26
26
|
- SELECT id, description FROM "%"
|
|
27
27
|
`
|
|
28
28
|
);
|
|
29
|
-
using factory = await POSTGRES_STORAGE_FACTORY();
|
|
29
|
+
await using factory = await POSTGRES_STORAGE_FACTORY();
|
|
30
30
|
const bucketStorage = factory.getInstance(sync_rules);
|
|
31
31
|
|
|
32
32
|
const result = await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
|