@powersync/service-module-postgres-storage 0.11.1 → 0.12.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/@types/migrations/scripts/1771232439485-storage-version.d.ts +3 -0
  4. package/dist/@types/migrations/scripts/1771491856000-sync-plan.d.ts +3 -0
  5. package/dist/@types/storage/PostgresBucketStorageFactory.d.ts +2 -10
  6. package/dist/@types/storage/PostgresCompactor.d.ts +2 -1
  7. package/dist/@types/storage/sync-rules/PostgresPersistedSyncRulesContent.d.ts +1 -10
  8. package/dist/@types/types/models/SyncRules.d.ts +12 -2
  9. package/dist/@types/types/models/json.d.ts +11 -0
  10. package/dist/@types/types/types.d.ts +2 -0
  11. package/dist/@types/utils/db.d.ts +9 -0
  12. package/dist/migrations/scripts/1771232439485-storage-version.js +111 -0
  13. package/dist/migrations/scripts/1771232439485-storage-version.js.map +1 -0
  14. package/dist/migrations/scripts/1771491856000-sync-plan.js +91 -0
  15. package/dist/migrations/scripts/1771491856000-sync-plan.js.map +1 -0
  16. package/dist/storage/PostgresBucketStorageFactory.js +16 -55
  17. package/dist/storage/PostgresBucketStorageFactory.js.map +1 -1
  18. package/dist/storage/PostgresCompactor.js +41 -60
  19. package/dist/storage/PostgresCompactor.js.map +1 -1
  20. package/dist/storage/sync-rules/PostgresPersistedSyncRulesContent.js +14 -30
  21. package/dist/storage/sync-rules/PostgresPersistedSyncRulesContent.js.map +1 -1
  22. package/dist/types/models/SyncRules.js +12 -1
  23. package/dist/types/models/SyncRules.js.map +1 -1
  24. package/dist/types/models/json.js +21 -0
  25. package/dist/types/models/json.js.map +1 -0
  26. package/dist/utils/db.js +32 -0
  27. package/dist/utils/db.js.map +1 -1
  28. package/dist/utils/test-utils.js +39 -10
  29. package/dist/utils/test-utils.js.map +1 -1
  30. package/package.json +8 -8
  31. package/src/migrations/scripts/1771232439485-storage-version.ts +44 -0
  32. package/src/migrations/scripts/1771491856000-sync-plan.ts +21 -0
  33. package/src/storage/PostgresBucketStorageFactory.ts +18 -65
  34. package/src/storage/PostgresCompactor.ts +46 -64
  35. package/src/storage/sync-rules/PostgresPersistedSyncRulesContent.ts +13 -33
  36. package/src/types/models/SyncRules.ts +16 -1
  37. package/src/types/models/json.ts +26 -0
  38. package/src/utils/db.ts +37 -0
  39. package/src/utils/test-utils.ts +30 -10
  40. package/test/src/__snapshots__/storage_sync.test.ts.snap +1116 -21
  41. package/test/src/migrations.test.ts +8 -1
  42. package/test/src/storage.test.ts +11 -11
  43. package/test/src/storage_compacting.test.ts +51 -2
  44. package/test/src/storage_sync.test.ts +146 -4
  45. package/test/src/util.ts +3 -0
  46. package/test/tsconfig.json +2 -6
  47. package/test/src/__snapshots__/storage.test.ts.snap +0 -9
@@ -1,6 +1,6 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
- exports[`sync - postgres > compacting data - invalidate checkpoint 1`] = `
3
+ exports[`sync - postgres > storage v1 > compacting data - invalidate checkpoint 1`] = `
4
4
  [
5
5
  {
6
6
  "checkpoint": {
@@ -31,7 +31,7 @@ exports[`sync - postgres > compacting data - invalidate checkpoint 1`] = `
31
31
  ]
32
32
  `;
33
33
 
34
- exports[`sync - postgres > compacting data - invalidate checkpoint 2`] = `
34
+ exports[`sync - postgres > storage v1 > compacting data - invalidate checkpoint 2`] = `
35
35
  [
36
36
  {
37
37
  "data": {
@@ -104,7 +104,7 @@ exports[`sync - postgres > compacting data - invalidate checkpoint 2`] = `
104
104
  ]
105
105
  `;
106
106
 
107
- exports[`sync - postgres > encodes sync rules id in buckes for streams 1`] = `
107
+ exports[`sync - postgres > storage v1 > encodes sync rules id in buckes for streams 1`] = `
108
108
  [
109
109
  {
110
110
  "checkpoint": {
@@ -159,7 +159,7 @@ exports[`sync - postgres > encodes sync rules id in buckes for streams 1`] = `
159
159
  ]
160
160
  `;
161
161
 
162
- exports[`sync - postgres > encodes sync rules id in buckes for streams 2`] = `
162
+ exports[`sync - postgres > storage v1 > encodes sync rules id in buckes for streams 2`] = `
163
163
  [
164
164
  {
165
165
  "checkpoint": {
@@ -214,7 +214,7 @@ exports[`sync - postgres > encodes sync rules id in buckes for streams 2`] = `
214
214
  ]
215
215
  `;
216
216
 
217
- exports[`sync - postgres > expired token 1`] = `
217
+ exports[`sync - postgres > storage v1 > expired token 1`] = `
218
218
  [
219
219
  {
220
220
  "token_expires_in": 0,
@@ -222,7 +222,7 @@ exports[`sync - postgres > expired token 1`] = `
222
222
  ]
223
223
  `;
224
224
 
225
- exports[`sync - postgres > expiring token 1`] = `
225
+ exports[`sync - postgres > storage v1 > expiring token 1`] = `
226
226
  [
227
227
  {
228
228
  "checkpoint": {
@@ -258,7 +258,7 @@ exports[`sync - postgres > expiring token 1`] = `
258
258
  ]
259
259
  `;
260
260
 
261
- exports[`sync - postgres > expiring token 2`] = `
261
+ exports[`sync - postgres > storage v1 > expiring token 2`] = `
262
262
  [
263
263
  {
264
264
  "token_expires_in": 0,
@@ -266,7 +266,7 @@ exports[`sync - postgres > expiring token 2`] = `
266
266
  ]
267
267
  `;
268
268
 
269
- exports[`sync - postgres > sends checkpoint complete line for empty checkpoint 1`] = `
269
+ exports[`sync - postgres > storage v1 > sends checkpoint complete line for empty checkpoint 1`] = `
270
270
  [
271
271
  {
272
272
  "checkpoint": {
@@ -335,7 +335,7 @@ exports[`sync - postgres > sends checkpoint complete line for empty checkpoint 1
335
335
  ]
336
336
  `;
337
337
 
338
- exports[`sync - postgres > sync buckets in order 1`] = `
338
+ exports[`sync - postgres > storage v1 > sync buckets in order 1`] = `
339
339
  [
340
340
  {
341
341
  "checkpoint": {
@@ -431,7 +431,7 @@ exports[`sync - postgres > sync buckets in order 1`] = `
431
431
  ]
432
432
  `;
433
433
 
434
- exports[`sync - postgres > sync global data 1`] = `
434
+ exports[`sync - postgres > storage v1 > sync global data 1`] = `
435
435
  [
436
436
  {
437
437
  "checkpoint": {
@@ -495,7 +495,7 @@ exports[`sync - postgres > sync global data 1`] = `
495
495
  ]
496
496
  `;
497
497
 
498
- exports[`sync - postgres > sync interrupts low-priority buckets on new checkpoints (2) 1`] = `
498
+ exports[`sync - postgres > storage v1 > sync interrupts low-priority buckets on new checkpoints (2) 1`] = `
499
499
  [
500
500
  {
501
501
  "checkpoint": {
@@ -689,7 +689,7 @@ exports[`sync - postgres > sync interrupts low-priority buckets on new checkpoin
689
689
  ]
690
690
  `;
691
691
 
692
- exports[`sync - postgres > sync legacy non-raw data 1`] = `
692
+ exports[`sync - postgres > storage v1 > sync legacy non-raw data 1`] = `
693
693
  [
694
694
  {
695
695
  "checkpoint": {
@@ -749,7 +749,7 @@ exports[`sync - postgres > sync legacy non-raw data 1`] = `
749
749
  ]
750
750
  `;
751
751
 
752
- exports[`sync - postgres > sync updates to data query only 1`] = `
752
+ exports[`sync - postgres > storage v1 > sync updates to data query only 1`] = `
753
753
  [
754
754
  {
755
755
  "checkpoint": {
@@ -785,7 +785,7 @@ exports[`sync - postgres > sync updates to data query only 1`] = `
785
785
  ]
786
786
  `;
787
787
 
788
- exports[`sync - postgres > sync updates to data query only 2`] = `
788
+ exports[`sync - postgres > storage v1 > sync updates to data query only 2`] = `
789
789
  [
790
790
  {
791
791
  "checkpoint_diff": {
@@ -834,7 +834,7 @@ exports[`sync - postgres > sync updates to data query only 2`] = `
834
834
  ]
835
835
  `;
836
836
 
837
- exports[`sync - postgres > sync updates to global data 1`] = `
837
+ exports[`sync - postgres > storage v1 > sync updates to global data 1`] = `
838
838
  [
839
839
  {
840
840
  "checkpoint": {
@@ -870,7 +870,7 @@ exports[`sync - postgres > sync updates to global data 1`] = `
870
870
  ]
871
871
  `;
872
872
 
873
- exports[`sync - postgres > sync updates to global data 2`] = `
873
+ exports[`sync - postgres > storage v1 > sync updates to global data 2`] = `
874
874
  [
875
875
  {
876
876
  "checkpoint_diff": {
@@ -919,7 +919,7 @@ exports[`sync - postgres > sync updates to global data 2`] = `
919
919
  ]
920
920
  `;
921
921
 
922
- exports[`sync - postgres > sync updates to global data 3`] = `
922
+ exports[`sync - postgres > storage v1 > sync updates to global data 3`] = `
923
923
  [
924
924
  {
925
925
  "checkpoint_diff": {
@@ -968,7 +968,7 @@ exports[`sync - postgres > sync updates to global data 3`] = `
968
968
  ]
969
969
  `;
970
970
 
971
- exports[`sync - postgres > sync updates to parameter query + data 1`] = `
971
+ exports[`sync - postgres > storage v1 > sync updates to parameter query + data 1`] = `
972
972
  [
973
973
  {
974
974
  "checkpoint": {
@@ -992,7 +992,7 @@ exports[`sync - postgres > sync updates to parameter query + data 1`] = `
992
992
  ]
993
993
  `;
994
994
 
995
- exports[`sync - postgres > sync updates to parameter query + data 2`] = `
995
+ exports[`sync - postgres > storage v1 > sync updates to parameter query + data 2`] = `
996
996
  [
997
997
  {
998
998
  "checkpoint_diff": {
@@ -1041,7 +1041,7 @@ exports[`sync - postgres > sync updates to parameter query + data 2`] = `
1041
1041
  ]
1042
1042
  `;
1043
1043
 
1044
- exports[`sync - postgres > sync updates to parameter query only 1`] = `
1044
+ exports[`sync - postgres > storage v1 > sync updates to parameter query only 1`] = `
1045
1045
  [
1046
1046
  {
1047
1047
  "checkpoint": {
@@ -1065,7 +1065,7 @@ exports[`sync - postgres > sync updates to parameter query only 1`] = `
1065
1065
  ]
1066
1066
  `;
1067
1067
 
1068
- exports[`sync - postgres > sync updates to parameter query only 2`] = `
1068
+ exports[`sync - postgres > storage v1 > sync updates to parameter query only 2`] = `
1069
1069
  [
1070
1070
  {
1071
1071
  "checkpoint_diff": {
@@ -1094,3 +1094,1098 @@ exports[`sync - postgres > sync updates to parameter query only 2`] = `
1094
1094
  },
1095
1095
  ]
1096
1096
  `;
1097
+
1098
+ exports[`sync - postgres > storage v2 > compacting data - invalidate checkpoint 1`] = `
1099
+ [
1100
+ {
1101
+ "checkpoint": {
1102
+ "buckets": [
1103
+ {
1104
+ "bucket": "1#mybucket[]",
1105
+ "checksum": -93886621,
1106
+ "count": 2,
1107
+ "priority": 3,
1108
+ "subscriptions": [
1109
+ {
1110
+ "default": 0,
1111
+ },
1112
+ ],
1113
+ },
1114
+ ],
1115
+ "last_op_id": "2",
1116
+ "streams": [
1117
+ {
1118
+ "errors": [],
1119
+ "is_default": true,
1120
+ "name": "mybucket",
1121
+ },
1122
+ ],
1123
+ "write_checkpoint": undefined,
1124
+ },
1125
+ },
1126
+ ]
1127
+ `;
1128
+
1129
+ exports[`sync - postgres > storage v2 > compacting data - invalidate checkpoint 2`] = `
1130
+ [
1131
+ {
1132
+ "data": {
1133
+ "after": "0",
1134
+ "bucket": "1#mybucket[]",
1135
+ "data": [
1136
+ {
1137
+ "checksum": -93886621,
1138
+ "op": "CLEAR",
1139
+ "op_id": "2",
1140
+ },
1141
+ ],
1142
+ "has_more": false,
1143
+ "next_after": "2",
1144
+ },
1145
+ },
1146
+ {
1147
+ "checkpoint_diff": {
1148
+ "last_op_id": "4",
1149
+ "removed_buckets": [],
1150
+ "updated_buckets": [
1151
+ {
1152
+ "bucket": "1#mybucket[]",
1153
+ "checksum": 499012468,
1154
+ "count": 4,
1155
+ "priority": 3,
1156
+ "subscriptions": [
1157
+ {
1158
+ "default": 0,
1159
+ },
1160
+ ],
1161
+ },
1162
+ ],
1163
+ "write_checkpoint": undefined,
1164
+ },
1165
+ },
1166
+ {
1167
+ "data": {
1168
+ "after": "2",
1169
+ "bucket": "1#mybucket[]",
1170
+ "data": [
1171
+ {
1172
+ "checksum": 1859363232,
1173
+ "data": "{"id":"t1","description":"Test 1b"}",
1174
+ "object_id": "t1",
1175
+ "object_type": "test",
1176
+ "op": "PUT",
1177
+ "op_id": "3",
1178
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
1179
+ },
1180
+ {
1181
+ "checksum": 3028503153,
1182
+ "data": "{"id":"t2","description":"Test 2b"}",
1183
+ "object_id": "t2",
1184
+ "object_type": "test",
1185
+ "op": "PUT",
1186
+ "op_id": "4",
1187
+ "subkey": "a17e6883-d5d2-599d-a805-d60528127dbd",
1188
+ },
1189
+ ],
1190
+ "has_more": false,
1191
+ "next_after": "4",
1192
+ },
1193
+ },
1194
+ {
1195
+ "checkpoint_complete": {
1196
+ "last_op_id": "4",
1197
+ },
1198
+ },
1199
+ ]
1200
+ `;
1201
+
1202
+ exports[`sync - postgres > storage v2 > encodes sync rules id in buckes for streams 1`] = `
1203
+ [
1204
+ {
1205
+ "checkpoint": {
1206
+ "buckets": [
1207
+ {
1208
+ "bucket": "1#test|0[]",
1209
+ "checksum": 920318466,
1210
+ "count": 1,
1211
+ "priority": 3,
1212
+ "subscriptions": [
1213
+ {
1214
+ "default": 0,
1215
+ },
1216
+ ],
1217
+ },
1218
+ ],
1219
+ "last_op_id": "1",
1220
+ "streams": [
1221
+ {
1222
+ "errors": [],
1223
+ "is_default": true,
1224
+ "name": "test",
1225
+ },
1226
+ ],
1227
+ "write_checkpoint": undefined,
1228
+ },
1229
+ },
1230
+ {
1231
+ "data": {
1232
+ "after": "0",
1233
+ "bucket": "1#test|0[]",
1234
+ "data": [
1235
+ {
1236
+ "checksum": 920318466,
1237
+ "data": "{"id":"t1","description":"Test 1"}",
1238
+ "object_id": "t1",
1239
+ "object_type": "test",
1240
+ "op": "PUT",
1241
+ "op_id": "1",
1242
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
1243
+ },
1244
+ ],
1245
+ "has_more": false,
1246
+ "next_after": "1",
1247
+ },
1248
+ },
1249
+ {
1250
+ "checkpoint_complete": {
1251
+ "last_op_id": "1",
1252
+ },
1253
+ },
1254
+ ]
1255
+ `;
1256
+
1257
+ exports[`sync - postgres > storage v2 > encodes sync rules id in buckes for streams 2`] = `
1258
+ [
1259
+ {
1260
+ "checkpoint": {
1261
+ "buckets": [
1262
+ {
1263
+ "bucket": "2#test|0[]",
1264
+ "checksum": 920318466,
1265
+ "count": 1,
1266
+ "priority": 3,
1267
+ "subscriptions": [
1268
+ {
1269
+ "default": 0,
1270
+ },
1271
+ ],
1272
+ },
1273
+ ],
1274
+ "last_op_id": "2",
1275
+ "streams": [
1276
+ {
1277
+ "errors": [],
1278
+ "is_default": true,
1279
+ "name": "test",
1280
+ },
1281
+ ],
1282
+ "write_checkpoint": undefined,
1283
+ },
1284
+ },
1285
+ {
1286
+ "data": {
1287
+ "after": "0",
1288
+ "bucket": "2#test|0[]",
1289
+ "data": [
1290
+ {
1291
+ "checksum": 920318466,
1292
+ "data": "{"id":"t1","description":"Test 1"}",
1293
+ "object_id": "t1",
1294
+ "object_type": "test",
1295
+ "op": "PUT",
1296
+ "op_id": "2",
1297
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
1298
+ },
1299
+ ],
1300
+ "has_more": false,
1301
+ "next_after": "2",
1302
+ },
1303
+ },
1304
+ {
1305
+ "checkpoint_complete": {
1306
+ "last_op_id": "2",
1307
+ },
1308
+ },
1309
+ ]
1310
+ `;
1311
+
1312
+ exports[`sync - postgres > storage v2 > expired token 1`] = `
1313
+ [
1314
+ {
1315
+ "token_expires_in": 0,
1316
+ },
1317
+ ]
1318
+ `;
1319
+
1320
+ exports[`sync - postgres > storage v2 > expiring token 1`] = `
1321
+ [
1322
+ {
1323
+ "checkpoint": {
1324
+ "buckets": [
1325
+ {
1326
+ "bucket": "1#mybucket[]",
1327
+ "checksum": 0,
1328
+ "count": 0,
1329
+ "priority": 3,
1330
+ "subscriptions": [
1331
+ {
1332
+ "default": 0,
1333
+ },
1334
+ ],
1335
+ },
1336
+ ],
1337
+ "last_op_id": "0",
1338
+ "streams": [
1339
+ {
1340
+ "errors": [],
1341
+ "is_default": true,
1342
+ "name": "mybucket",
1343
+ },
1344
+ ],
1345
+ "write_checkpoint": undefined,
1346
+ },
1347
+ },
1348
+ {
1349
+ "checkpoint_complete": {
1350
+ "last_op_id": "0",
1351
+ },
1352
+ },
1353
+ ]
1354
+ `;
1355
+
1356
+ exports[`sync - postgres > storage v2 > expiring token 2`] = `
1357
+ [
1358
+ {
1359
+ "token_expires_in": 0,
1360
+ },
1361
+ ]
1362
+ `;
1363
+
1364
+ exports[`sync - postgres > storage v2 > sends checkpoint complete line for empty checkpoint 1`] = `
1365
+ [
1366
+ {
1367
+ "checkpoint": {
1368
+ "buckets": [
1369
+ {
1370
+ "bucket": "1#mybucket[]",
1371
+ "checksum": -1221282404,
1372
+ "count": 1,
1373
+ "priority": 3,
1374
+ "subscriptions": [
1375
+ {
1376
+ "default": 0,
1377
+ },
1378
+ ],
1379
+ },
1380
+ ],
1381
+ "last_op_id": "1",
1382
+ "streams": [
1383
+ {
1384
+ "errors": [],
1385
+ "is_default": true,
1386
+ "name": "mybucket",
1387
+ },
1388
+ ],
1389
+ "write_checkpoint": undefined,
1390
+ },
1391
+ },
1392
+ {
1393
+ "data": {
1394
+ "after": "0",
1395
+ "bucket": "1#mybucket[]",
1396
+ "data": [
1397
+ {
1398
+ "checksum": 3073684892,
1399
+ "data": "{"id":"t1","description":"sync"}",
1400
+ "object_id": "t1",
1401
+ "object_type": "test",
1402
+ "op": "PUT",
1403
+ "op_id": "1",
1404
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
1405
+ },
1406
+ ],
1407
+ "has_more": false,
1408
+ "next_after": "1",
1409
+ },
1410
+ },
1411
+ null,
1412
+ {
1413
+ "checkpoint_complete": {
1414
+ "last_op_id": "1",
1415
+ },
1416
+ },
1417
+ {
1418
+ "checkpoint_diff": {
1419
+ "last_op_id": "1",
1420
+ "removed_buckets": [],
1421
+ "updated_buckets": [],
1422
+ "write_checkpoint": "1",
1423
+ },
1424
+ },
1425
+ {
1426
+ "checkpoint_complete": {
1427
+ "last_op_id": "1",
1428
+ },
1429
+ },
1430
+ ]
1431
+ `;
1432
+
1433
+ exports[`sync - postgres > storage v2 > sync buckets in order 1`] = `
1434
+ [
1435
+ {
1436
+ "checkpoint": {
1437
+ "buckets": [
1438
+ {
1439
+ "bucket": "1#b0[]",
1440
+ "checksum": 920318466,
1441
+ "count": 1,
1442
+ "priority": 2,
1443
+ "subscriptions": [
1444
+ {
1445
+ "default": 0,
1446
+ },
1447
+ ],
1448
+ },
1449
+ {
1450
+ "bucket": "1#b1[]",
1451
+ "checksum": -1382098757,
1452
+ "count": 1,
1453
+ "priority": 1,
1454
+ "subscriptions": [
1455
+ {
1456
+ "default": 1,
1457
+ },
1458
+ ],
1459
+ },
1460
+ ],
1461
+ "last_op_id": "2",
1462
+ "streams": [
1463
+ {
1464
+ "errors": [],
1465
+ "is_default": true,
1466
+ "name": "b0",
1467
+ },
1468
+ {
1469
+ "errors": [],
1470
+ "is_default": true,
1471
+ "name": "b1",
1472
+ },
1473
+ ],
1474
+ "write_checkpoint": undefined,
1475
+ },
1476
+ },
1477
+ {
1478
+ "data": {
1479
+ "after": "0",
1480
+ "bucket": "1#b1[]",
1481
+ "data": [
1482
+ {
1483
+ "checksum": 2912868539,
1484
+ "data": "{"id":"earlier","description":"Test 2"}",
1485
+ "object_id": "earlier",
1486
+ "object_type": "test",
1487
+ "op": "PUT",
1488
+ "op_id": "2",
1489
+ "subkey": "243b0e26-87b2-578a-993c-5ac5b6f7fd64",
1490
+ },
1491
+ ],
1492
+ "has_more": false,
1493
+ "next_after": "2",
1494
+ },
1495
+ },
1496
+ {
1497
+ "partial_checkpoint_complete": {
1498
+ "last_op_id": "2",
1499
+ "priority": 1,
1500
+ },
1501
+ },
1502
+ {
1503
+ "data": {
1504
+ "after": "0",
1505
+ "bucket": "1#b0[]",
1506
+ "data": [
1507
+ {
1508
+ "checksum": 920318466,
1509
+ "data": "{"id":"t1","description":"Test 1"}",
1510
+ "object_id": "t1",
1511
+ "object_type": "test",
1512
+ "op": "PUT",
1513
+ "op_id": "1",
1514
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
1515
+ },
1516
+ ],
1517
+ "has_more": false,
1518
+ "next_after": "1",
1519
+ },
1520
+ },
1521
+ {
1522
+ "checkpoint_complete": {
1523
+ "last_op_id": "2",
1524
+ },
1525
+ },
1526
+ ]
1527
+ `;
1528
+
1529
+ exports[`sync - postgres > storage v2 > sync global data 1`] = `
1530
+ [
1531
+ {
1532
+ "checkpoint": {
1533
+ "buckets": [
1534
+ {
1535
+ "bucket": "1#mybucket[]",
1536
+ "checksum": -93886621,
1537
+ "count": 2,
1538
+ "priority": 3,
1539
+ "subscriptions": [
1540
+ {
1541
+ "default": 0,
1542
+ },
1543
+ ],
1544
+ },
1545
+ ],
1546
+ "last_op_id": "2",
1547
+ "streams": [
1548
+ {
1549
+ "errors": [],
1550
+ "is_default": true,
1551
+ "name": "mybucket",
1552
+ },
1553
+ ],
1554
+ "write_checkpoint": undefined,
1555
+ },
1556
+ },
1557
+ {
1558
+ "data": {
1559
+ "after": "0",
1560
+ "bucket": "1#mybucket[]",
1561
+ "data": [
1562
+ {
1563
+ "checksum": 920318466,
1564
+ "data": "{"id":"t1","description":"Test 1"}",
1565
+ "object_id": "t1",
1566
+ "object_type": "test",
1567
+ "op": "PUT",
1568
+ "op_id": "1",
1569
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
1570
+ },
1571
+ {
1572
+ "checksum": 3280762209,
1573
+ "data": "{"id":"t2","description":"Test 2"}",
1574
+ "object_id": "t2",
1575
+ "object_type": "test",
1576
+ "op": "PUT",
1577
+ "op_id": "2",
1578
+ "subkey": "a17e6883-d5d2-599d-a805-d60528127dbd",
1579
+ },
1580
+ ],
1581
+ "has_more": false,
1582
+ "next_after": "2",
1583
+ },
1584
+ },
1585
+ {
1586
+ "checkpoint_complete": {
1587
+ "last_op_id": "2",
1588
+ },
1589
+ },
1590
+ ]
1591
+ `;
1592
+
1593
+ exports[`sync - postgres > storage v2 > sync interrupts low-priority buckets on new checkpoints (2) 1`] = `
1594
+ [
1595
+ {
1596
+ "checkpoint": {
1597
+ "buckets": [
1598
+ {
1599
+ "bucket": "1#b0a[]",
1600
+ "checksum": -659831575,
1601
+ "count": 2000,
1602
+ "priority": 2,
1603
+ "subscriptions": [
1604
+ {
1605
+ "default": 0,
1606
+ },
1607
+ ],
1608
+ },
1609
+ {
1610
+ "bucket": "1#b0b[]",
1611
+ "checksum": -659831575,
1612
+ "count": 2000,
1613
+ "priority": 2,
1614
+ "subscriptions": [
1615
+ {
1616
+ "default": 1,
1617
+ },
1618
+ ],
1619
+ },
1620
+ {
1621
+ "bucket": "1#b1[]",
1622
+ "checksum": -1096116670,
1623
+ "count": 1,
1624
+ "priority": 1,
1625
+ "subscriptions": [
1626
+ {
1627
+ "default": 2,
1628
+ },
1629
+ ],
1630
+ },
1631
+ ],
1632
+ "last_op_id": "4001",
1633
+ "streams": [
1634
+ {
1635
+ "errors": [],
1636
+ "is_default": true,
1637
+ "name": "b0a",
1638
+ },
1639
+ {
1640
+ "errors": [],
1641
+ "is_default": true,
1642
+ "name": "b0b",
1643
+ },
1644
+ {
1645
+ "errors": [],
1646
+ "is_default": true,
1647
+ "name": "b1",
1648
+ },
1649
+ ],
1650
+ "write_checkpoint": undefined,
1651
+ },
1652
+ },
1653
+ {
1654
+ "data": {
1655
+ "after": "0",
1656
+ "bucket": "1#b1[]",
1657
+ "data": undefined,
1658
+ "has_more": false,
1659
+ "next_after": "1",
1660
+ },
1661
+ },
1662
+ {
1663
+ "partial_checkpoint_complete": {
1664
+ "last_op_id": "4001",
1665
+ "priority": 1,
1666
+ },
1667
+ },
1668
+ {
1669
+ "data": {
1670
+ "after": "0",
1671
+ "bucket": "1#b0a[]",
1672
+ "data": undefined,
1673
+ "has_more": true,
1674
+ "next_after": "2000",
1675
+ },
1676
+ },
1677
+ {
1678
+ "data": {
1679
+ "after": "2000",
1680
+ "bucket": "1#b0a[]",
1681
+ "data": undefined,
1682
+ "has_more": true,
1683
+ "next_after": "4000",
1684
+ },
1685
+ },
1686
+ {
1687
+ "checkpoint_diff": {
1688
+ "last_op_id": "4004",
1689
+ "removed_buckets": [],
1690
+ "updated_buckets": [
1691
+ {
1692
+ "bucket": "1#b0a[]",
1693
+ "checksum": 883076828,
1694
+ "count": 2001,
1695
+ "priority": 2,
1696
+ "subscriptions": [
1697
+ {
1698
+ "default": 0,
1699
+ },
1700
+ ],
1701
+ },
1702
+ {
1703
+ "bucket": "1#b0b[]",
1704
+ "checksum": 883076828,
1705
+ "count": 2001,
1706
+ "priority": 2,
1707
+ "subscriptions": [
1708
+ {
1709
+ "default": 1,
1710
+ },
1711
+ ],
1712
+ },
1713
+ {
1714
+ "bucket": "1#b1[]",
1715
+ "checksum": 1841937527,
1716
+ "count": 2,
1717
+ "priority": 1,
1718
+ "subscriptions": [
1719
+ {
1720
+ "default": 2,
1721
+ },
1722
+ ],
1723
+ },
1724
+ ],
1725
+ "write_checkpoint": undefined,
1726
+ },
1727
+ },
1728
+ {
1729
+ "data": {
1730
+ "after": "1",
1731
+ "bucket": "1#b1[]",
1732
+ "data": undefined,
1733
+ "has_more": false,
1734
+ "next_after": "4002",
1735
+ },
1736
+ },
1737
+ {
1738
+ "partial_checkpoint_complete": {
1739
+ "last_op_id": "4004",
1740
+ "priority": 1,
1741
+ },
1742
+ },
1743
+ {
1744
+ "data": {
1745
+ "after": "4000",
1746
+ "bucket": "1#b0a[]",
1747
+ "data": undefined,
1748
+ "has_more": false,
1749
+ "next_after": "4003",
1750
+ },
1751
+ },
1752
+ {
1753
+ "data": {
1754
+ "after": "0",
1755
+ "bucket": "1#b0b[]",
1756
+ "data": undefined,
1757
+ "has_more": true,
1758
+ "next_after": "1999",
1759
+ },
1760
+ },
1761
+ {
1762
+ "data": {
1763
+ "after": "1999",
1764
+ "bucket": "1#b0b[]",
1765
+ "data": undefined,
1766
+ "has_more": true,
1767
+ "next_after": "3999",
1768
+ },
1769
+ },
1770
+ {
1771
+ "data": {
1772
+ "after": "3999",
1773
+ "bucket": "1#b0b[]",
1774
+ "data": undefined,
1775
+ "has_more": false,
1776
+ "next_after": "4004",
1777
+ },
1778
+ },
1779
+ {
1780
+ "checkpoint_complete": {
1781
+ "last_op_id": "4004",
1782
+ },
1783
+ },
1784
+ ]
1785
+ `;
1786
+
1787
+ exports[`sync - postgres > storage v2 > sync legacy non-raw data 1`] = `
1788
+ [
1789
+ {
1790
+ "checkpoint": {
1791
+ "buckets": [
1792
+ {
1793
+ "bucket": "1#mybucket[]",
1794
+ "checksum": -852817836,
1795
+ "count": 1,
1796
+ "priority": 3,
1797
+ "subscriptions": [
1798
+ {
1799
+ "default": 0,
1800
+ },
1801
+ ],
1802
+ },
1803
+ ],
1804
+ "last_op_id": "1",
1805
+ "streams": [
1806
+ {
1807
+ "errors": [],
1808
+ "is_default": true,
1809
+ "name": "mybucket",
1810
+ },
1811
+ ],
1812
+ "write_checkpoint": undefined,
1813
+ },
1814
+ },
1815
+ {
1816
+ "data": {
1817
+ "after": "0",
1818
+ "bucket": "1#mybucket[]",
1819
+ "data": [
1820
+ {
1821
+ "checksum": 3442149460n,
1822
+ "data": {
1823
+ "description": "Test
1824
+ "string"",
1825
+ "id": "t1",
1826
+ "large_num": 12345678901234567890n,
1827
+ },
1828
+ "object_id": "t1",
1829
+ "object_type": "test",
1830
+ "op": "PUT",
1831
+ "op_id": "1",
1832
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
1833
+ },
1834
+ ],
1835
+ "has_more": false,
1836
+ "next_after": "1",
1837
+ },
1838
+ },
1839
+ {
1840
+ "checkpoint_complete": {
1841
+ "last_op_id": "1",
1842
+ },
1843
+ },
1844
+ ]
1845
+ `;
1846
+
1847
+ exports[`sync - postgres > storage v2 > sync updates to data query only 1`] = `
1848
+ [
1849
+ {
1850
+ "checkpoint": {
1851
+ "buckets": [
1852
+ {
1853
+ "bucket": "1#by_user["user1"]",
1854
+ "checksum": 0,
1855
+ "count": 0,
1856
+ "priority": 3,
1857
+ "subscriptions": [
1858
+ {
1859
+ "default": 0,
1860
+ },
1861
+ ],
1862
+ },
1863
+ ],
1864
+ "last_op_id": "1",
1865
+ "streams": [
1866
+ {
1867
+ "errors": [],
1868
+ "is_default": true,
1869
+ "name": "by_user",
1870
+ },
1871
+ ],
1872
+ "write_checkpoint": undefined,
1873
+ },
1874
+ },
1875
+ {
1876
+ "checkpoint_complete": {
1877
+ "last_op_id": "1",
1878
+ },
1879
+ },
1880
+ ]
1881
+ `;
1882
+
1883
+ exports[`sync - postgres > storage v2 > sync updates to data query only 2`] = `
1884
+ [
1885
+ {
1886
+ "checkpoint_diff": {
1887
+ "last_op_id": "2",
1888
+ "removed_buckets": [],
1889
+ "updated_buckets": [
1890
+ {
1891
+ "bucket": "1#by_user["user1"]",
1892
+ "checksum": 1418351250,
1893
+ "count": 1,
1894
+ "priority": 3,
1895
+ "subscriptions": [
1896
+ {
1897
+ "default": 0,
1898
+ },
1899
+ ],
1900
+ },
1901
+ ],
1902
+ "write_checkpoint": undefined,
1903
+ },
1904
+ },
1905
+ {
1906
+ "data": {
1907
+ "after": "0",
1908
+ "bucket": "1#by_user["user1"]",
1909
+ "data": [
1910
+ {
1911
+ "checksum": 1418351250,
1912
+ "data": "{"id":"list1","user_id":"user1","name":"User 1"}",
1913
+ "object_id": "list1",
1914
+ "object_type": "lists",
1915
+ "op": "PUT",
1916
+ "op_id": "2",
1917
+ "subkey": "5ad0aa14-3d5e-5428-ad5b-2c33927d991c",
1918
+ },
1919
+ ],
1920
+ "has_more": false,
1921
+ "next_after": "2",
1922
+ },
1923
+ },
1924
+ {
1925
+ "checkpoint_complete": {
1926
+ "last_op_id": "2",
1927
+ },
1928
+ },
1929
+ ]
1930
+ `;
1931
+
1932
+ exports[`sync - postgres > storage v2 > sync updates to global data 1`] = `
1933
+ [
1934
+ {
1935
+ "checkpoint": {
1936
+ "buckets": [
1937
+ {
1938
+ "bucket": "1#mybucket[]",
1939
+ "checksum": 0,
1940
+ "count": 0,
1941
+ "priority": 3,
1942
+ "subscriptions": [
1943
+ {
1944
+ "default": 0,
1945
+ },
1946
+ ],
1947
+ },
1948
+ ],
1949
+ "last_op_id": "0",
1950
+ "streams": [
1951
+ {
1952
+ "errors": [],
1953
+ "is_default": true,
1954
+ "name": "mybucket",
1955
+ },
1956
+ ],
1957
+ "write_checkpoint": undefined,
1958
+ },
1959
+ },
1960
+ {
1961
+ "checkpoint_complete": {
1962
+ "last_op_id": "0",
1963
+ },
1964
+ },
1965
+ ]
1966
+ `;
1967
+
1968
+ exports[`sync - postgres > storage v2 > sync updates to global data 2`] = `
1969
+ [
1970
+ {
1971
+ "checkpoint_diff": {
1972
+ "last_op_id": "1",
1973
+ "removed_buckets": [],
1974
+ "updated_buckets": [
1975
+ {
1976
+ "bucket": "1#mybucket[]",
1977
+ "checksum": 920318466,
1978
+ "count": 1,
1979
+ "priority": 3,
1980
+ "subscriptions": [
1981
+ {
1982
+ "default": 0,
1983
+ },
1984
+ ],
1985
+ },
1986
+ ],
1987
+ "write_checkpoint": undefined,
1988
+ },
1989
+ },
1990
+ {
1991
+ "data": {
1992
+ "after": "0",
1993
+ "bucket": "1#mybucket[]",
1994
+ "data": [
1995
+ {
1996
+ "checksum": 920318466,
1997
+ "data": "{"id":"t1","description":"Test 1"}",
1998
+ "object_id": "t1",
1999
+ "object_type": "test",
2000
+ "op": "PUT",
2001
+ "op_id": "1",
2002
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
2003
+ },
2004
+ ],
2005
+ "has_more": false,
2006
+ "next_after": "1",
2007
+ },
2008
+ },
2009
+ {
2010
+ "checkpoint_complete": {
2011
+ "last_op_id": "1",
2012
+ },
2013
+ },
2014
+ ]
2015
+ `;
2016
+
2017
+ exports[`sync - postgres > storage v2 > sync updates to global data 3`] = `
2018
+ [
2019
+ {
2020
+ "checkpoint_diff": {
2021
+ "last_op_id": "2",
2022
+ "removed_buckets": [],
2023
+ "updated_buckets": [
2024
+ {
2025
+ "bucket": "1#mybucket[]",
2026
+ "checksum": -93886621,
2027
+ "count": 2,
2028
+ "priority": 3,
2029
+ "subscriptions": [
2030
+ {
2031
+ "default": 0,
2032
+ },
2033
+ ],
2034
+ },
2035
+ ],
2036
+ "write_checkpoint": undefined,
2037
+ },
2038
+ },
2039
+ {
2040
+ "data": {
2041
+ "after": "1",
2042
+ "bucket": "1#mybucket[]",
2043
+ "data": [
2044
+ {
2045
+ "checksum": 3280762209,
2046
+ "data": "{"id":"t2","description":"Test 2"}",
2047
+ "object_id": "t2",
2048
+ "object_type": "test",
2049
+ "op": "PUT",
2050
+ "op_id": "2",
2051
+ "subkey": "a17e6883-d5d2-599d-a805-d60528127dbd",
2052
+ },
2053
+ ],
2054
+ "has_more": false,
2055
+ "next_after": "2",
2056
+ },
2057
+ },
2058
+ {
2059
+ "checkpoint_complete": {
2060
+ "last_op_id": "2",
2061
+ },
2062
+ },
2063
+ ]
2064
+ `;
2065
+
2066
+ exports[`sync - postgres > storage v2 > sync updates to parameter query + data 1`] = `
2067
+ [
2068
+ {
2069
+ "checkpoint": {
2070
+ "buckets": [],
2071
+ "last_op_id": "0",
2072
+ "streams": [
2073
+ {
2074
+ "errors": [],
2075
+ "is_default": true,
2076
+ "name": "by_user",
2077
+ },
2078
+ ],
2079
+ "write_checkpoint": undefined,
2080
+ },
2081
+ },
2082
+ {
2083
+ "checkpoint_complete": {
2084
+ "last_op_id": "0",
2085
+ },
2086
+ },
2087
+ ]
2088
+ `;
2089
+
2090
+ exports[`sync - postgres > storage v2 > sync updates to parameter query + data 2`] = `
2091
+ [
2092
+ {
2093
+ "checkpoint_diff": {
2094
+ "last_op_id": "2",
2095
+ "removed_buckets": [],
2096
+ "updated_buckets": [
2097
+ {
2098
+ "bucket": "1#by_user["user1"]",
2099
+ "checksum": 1418351250,
2100
+ "count": 1,
2101
+ "priority": 3,
2102
+ "subscriptions": [
2103
+ {
2104
+ "default": 0,
2105
+ },
2106
+ ],
2107
+ },
2108
+ ],
2109
+ "write_checkpoint": undefined,
2110
+ },
2111
+ },
2112
+ {
2113
+ "data": {
2114
+ "after": "0",
2115
+ "bucket": "1#by_user["user1"]",
2116
+ "data": [
2117
+ {
2118
+ "checksum": 1418351250,
2119
+ "data": "{"id":"list1","user_id":"user1","name":"User 1"}",
2120
+ "object_id": "list1",
2121
+ "object_type": "lists",
2122
+ "op": "PUT",
2123
+ "op_id": "1",
2124
+ "subkey": "5ad0aa14-3d5e-5428-ad5b-2c33927d991c",
2125
+ },
2126
+ ],
2127
+ "has_more": false,
2128
+ "next_after": "1",
2129
+ },
2130
+ },
2131
+ {
2132
+ "checkpoint_complete": {
2133
+ "last_op_id": "2",
2134
+ },
2135
+ },
2136
+ ]
2137
+ `;
2138
+
2139
+ exports[`sync - postgres > storage v2 > sync updates to parameter query only 1`] = `
2140
+ [
2141
+ {
2142
+ "checkpoint": {
2143
+ "buckets": [],
2144
+ "last_op_id": "0",
2145
+ "streams": [
2146
+ {
2147
+ "errors": [],
2148
+ "is_default": true,
2149
+ "name": "by_user",
2150
+ },
2151
+ ],
2152
+ "write_checkpoint": undefined,
2153
+ },
2154
+ },
2155
+ {
2156
+ "checkpoint_complete": {
2157
+ "last_op_id": "0",
2158
+ },
2159
+ },
2160
+ ]
2161
+ `;
2162
+
2163
+ exports[`sync - postgres > storage v2 > sync updates to parameter query only 2`] = `
2164
+ [
2165
+ {
2166
+ "checkpoint_diff": {
2167
+ "last_op_id": "1",
2168
+ "removed_buckets": [],
2169
+ "updated_buckets": [
2170
+ {
2171
+ "bucket": "1#by_user["user1"]",
2172
+ "checksum": 0,
2173
+ "count": 0,
2174
+ "priority": 3,
2175
+ "subscriptions": [
2176
+ {
2177
+ "default": 0,
2178
+ },
2179
+ ],
2180
+ },
2181
+ ],
2182
+ "write_checkpoint": undefined,
2183
+ },
2184
+ },
2185
+ {
2186
+ "checkpoint_complete": {
2187
+ "last_op_id": "1",
2188
+ },
2189
+ },
2190
+ ]
2191
+ `;