@powersync/service-module-postgres-storage 0.12.0 → 0.13.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 (65) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/@types/migrations/scripts/1771424826685-current-data-pending-deletes.d.ts +3 -0
  4. package/dist/@types/storage/PostgresBucketStorageFactory.d.ts +4 -0
  5. package/dist/@types/storage/PostgresCompactor.d.ts +8 -2
  6. package/dist/@types/storage/PostgresSyncRulesStorage.d.ts +5 -3
  7. package/dist/@types/storage/batch/OperationBatch.d.ts +2 -2
  8. package/dist/@types/storage/batch/PostgresBucketBatch.d.ts +12 -9
  9. package/dist/@types/storage/batch/PostgresPersistedBatch.d.ts +17 -5
  10. package/dist/@types/storage/current-data-store.d.ts +85 -0
  11. package/dist/@types/storage/current-data-table.d.ts +9 -0
  12. package/dist/@types/storage/table-id.d.ts +2 -0
  13. package/dist/@types/types/models/CurrentData.d.ts +18 -3
  14. package/dist/@types/utils/bson.d.ts +1 -1
  15. package/dist/@types/utils/test-utils.d.ts +1 -1
  16. package/dist/migrations/scripts/1771424826685-current-data-pending-deletes.js +8 -0
  17. package/dist/migrations/scripts/1771424826685-current-data-pending-deletes.js.map +1 -0
  18. package/dist/storage/PostgresBucketStorageFactory.js +41 -4
  19. package/dist/storage/PostgresBucketStorageFactory.js.map +1 -1
  20. package/dist/storage/PostgresCompactor.js +14 -6
  21. package/dist/storage/PostgresCompactor.js.map +1 -1
  22. package/dist/storage/PostgresSyncRulesStorage.js +23 -15
  23. package/dist/storage/PostgresSyncRulesStorage.js.map +1 -1
  24. package/dist/storage/batch/OperationBatch.js +2 -1
  25. package/dist/storage/batch/OperationBatch.js.map +1 -1
  26. package/dist/storage/batch/PostgresBucketBatch.js +286 -213
  27. package/dist/storage/batch/PostgresBucketBatch.js.map +1 -1
  28. package/dist/storage/batch/PostgresPersistedBatch.js +86 -81
  29. package/dist/storage/batch/PostgresPersistedBatch.js.map +1 -1
  30. package/dist/storage/current-data-store.js +270 -0
  31. package/dist/storage/current-data-store.js.map +1 -0
  32. package/dist/storage/current-data-table.js +22 -0
  33. package/dist/storage/current-data-table.js.map +1 -0
  34. package/dist/storage/table-id.js +8 -0
  35. package/dist/storage/table-id.js.map +1 -0
  36. package/dist/types/models/CurrentData.js +11 -2
  37. package/dist/types/models/CurrentData.js.map +1 -1
  38. package/dist/utils/bson.js.map +1 -1
  39. package/dist/utils/db.js +9 -0
  40. package/dist/utils/db.js.map +1 -1
  41. package/dist/utils/test-utils.js +13 -6
  42. package/dist/utils/test-utils.js.map +1 -1
  43. package/package.json +8 -8
  44. package/src/migrations/scripts/1771424826685-current-data-pending-deletes.ts +10 -0
  45. package/src/storage/PostgresBucketStorageFactory.ts +53 -5
  46. package/src/storage/PostgresCompactor.ts +17 -8
  47. package/src/storage/PostgresSyncRulesStorage.ts +30 -17
  48. package/src/storage/batch/OperationBatch.ts +4 -3
  49. package/src/storage/batch/PostgresBucketBatch.ts +306 -238
  50. package/src/storage/batch/PostgresPersistedBatch.ts +92 -84
  51. package/src/storage/current-data-store.ts +326 -0
  52. package/src/storage/current-data-table.ts +26 -0
  53. package/src/storage/table-id.ts +9 -0
  54. package/src/types/models/CurrentData.ts +17 -4
  55. package/src/utils/bson.ts +1 -1
  56. package/src/utils/db.ts +10 -0
  57. package/src/utils/test-utils.ts +14 -7
  58. package/test/src/__snapshots__/storage.test.ts.snap +151 -0
  59. package/test/src/__snapshots__/storage_compacting.test.ts.snap +17 -0
  60. package/test/src/__snapshots__/storage_sync.test.ts.snap +1095 -0
  61. package/test/src/migrations.test.ts +1 -1
  62. package/test/src/storage.test.ts +136 -130
  63. package/test/src/storage_compacting.test.ts +65 -3
  64. package/test/src/storage_sync.test.ts +11 -9
  65. package/test/src/util.ts +4 -4
@@ -2189,3 +2189,1098 @@ exports[`sync - postgres > storage v2 > sync updates to parameter query only 2`]
2189
2189
  },
2190
2190
  ]
2191
2191
  `;
2192
+
2193
+ exports[`sync - postgres > storage v3 > compacting data - invalidate checkpoint 1`] = `
2194
+ [
2195
+ {
2196
+ "checkpoint": {
2197
+ "buckets": [
2198
+ {
2199
+ "bucket": "1#mybucket[]",
2200
+ "checksum": -93886621,
2201
+ "count": 2,
2202
+ "priority": 3,
2203
+ "subscriptions": [
2204
+ {
2205
+ "default": 0,
2206
+ },
2207
+ ],
2208
+ },
2209
+ ],
2210
+ "last_op_id": "2",
2211
+ "streams": [
2212
+ {
2213
+ "errors": [],
2214
+ "is_default": true,
2215
+ "name": "mybucket",
2216
+ },
2217
+ ],
2218
+ "write_checkpoint": undefined,
2219
+ },
2220
+ },
2221
+ ]
2222
+ `;
2223
+
2224
+ exports[`sync - postgres > storage v3 > compacting data - invalidate checkpoint 2`] = `
2225
+ [
2226
+ {
2227
+ "data": {
2228
+ "after": "0",
2229
+ "bucket": "1#mybucket[]",
2230
+ "data": [
2231
+ {
2232
+ "checksum": -93886621,
2233
+ "op": "CLEAR",
2234
+ "op_id": "2",
2235
+ },
2236
+ ],
2237
+ "has_more": false,
2238
+ "next_after": "2",
2239
+ },
2240
+ },
2241
+ {
2242
+ "checkpoint_diff": {
2243
+ "last_op_id": "4",
2244
+ "removed_buckets": [],
2245
+ "updated_buckets": [
2246
+ {
2247
+ "bucket": "1#mybucket[]",
2248
+ "checksum": 499012468,
2249
+ "count": 4,
2250
+ "priority": 3,
2251
+ "subscriptions": [
2252
+ {
2253
+ "default": 0,
2254
+ },
2255
+ ],
2256
+ },
2257
+ ],
2258
+ "write_checkpoint": undefined,
2259
+ },
2260
+ },
2261
+ {
2262
+ "data": {
2263
+ "after": "2",
2264
+ "bucket": "1#mybucket[]",
2265
+ "data": [
2266
+ {
2267
+ "checksum": 1859363232,
2268
+ "data": "{"id":"t1","description":"Test 1b"}",
2269
+ "object_id": "t1",
2270
+ "object_type": "test",
2271
+ "op": "PUT",
2272
+ "op_id": "3",
2273
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
2274
+ },
2275
+ {
2276
+ "checksum": 3028503153,
2277
+ "data": "{"id":"t2","description":"Test 2b"}",
2278
+ "object_id": "t2",
2279
+ "object_type": "test",
2280
+ "op": "PUT",
2281
+ "op_id": "4",
2282
+ "subkey": "a17e6883-d5d2-599d-a805-d60528127dbd",
2283
+ },
2284
+ ],
2285
+ "has_more": false,
2286
+ "next_after": "4",
2287
+ },
2288
+ },
2289
+ {
2290
+ "checkpoint_complete": {
2291
+ "last_op_id": "4",
2292
+ },
2293
+ },
2294
+ ]
2295
+ `;
2296
+
2297
+ exports[`sync - postgres > storage v3 > encodes sync rules id in buckes for streams 1`] = `
2298
+ [
2299
+ {
2300
+ "checkpoint": {
2301
+ "buckets": [
2302
+ {
2303
+ "bucket": "1#test|0[]",
2304
+ "checksum": 920318466,
2305
+ "count": 1,
2306
+ "priority": 3,
2307
+ "subscriptions": [
2308
+ {
2309
+ "default": 0,
2310
+ },
2311
+ ],
2312
+ },
2313
+ ],
2314
+ "last_op_id": "1",
2315
+ "streams": [
2316
+ {
2317
+ "errors": [],
2318
+ "is_default": true,
2319
+ "name": "test",
2320
+ },
2321
+ ],
2322
+ "write_checkpoint": undefined,
2323
+ },
2324
+ },
2325
+ {
2326
+ "data": {
2327
+ "after": "0",
2328
+ "bucket": "1#test|0[]",
2329
+ "data": [
2330
+ {
2331
+ "checksum": 920318466,
2332
+ "data": "{"id":"t1","description":"Test 1"}",
2333
+ "object_id": "t1",
2334
+ "object_type": "test",
2335
+ "op": "PUT",
2336
+ "op_id": "1",
2337
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
2338
+ },
2339
+ ],
2340
+ "has_more": false,
2341
+ "next_after": "1",
2342
+ },
2343
+ },
2344
+ {
2345
+ "checkpoint_complete": {
2346
+ "last_op_id": "1",
2347
+ },
2348
+ },
2349
+ ]
2350
+ `;
2351
+
2352
+ exports[`sync - postgres > storage v3 > encodes sync rules id in buckes for streams 2`] = `
2353
+ [
2354
+ {
2355
+ "checkpoint": {
2356
+ "buckets": [
2357
+ {
2358
+ "bucket": "2#test|0[]",
2359
+ "checksum": 920318466,
2360
+ "count": 1,
2361
+ "priority": 3,
2362
+ "subscriptions": [
2363
+ {
2364
+ "default": 0,
2365
+ },
2366
+ ],
2367
+ },
2368
+ ],
2369
+ "last_op_id": "2",
2370
+ "streams": [
2371
+ {
2372
+ "errors": [],
2373
+ "is_default": true,
2374
+ "name": "test",
2375
+ },
2376
+ ],
2377
+ "write_checkpoint": undefined,
2378
+ },
2379
+ },
2380
+ {
2381
+ "data": {
2382
+ "after": "0",
2383
+ "bucket": "2#test|0[]",
2384
+ "data": [
2385
+ {
2386
+ "checksum": 920318466,
2387
+ "data": "{"id":"t1","description":"Test 1"}",
2388
+ "object_id": "t1",
2389
+ "object_type": "test",
2390
+ "op": "PUT",
2391
+ "op_id": "2",
2392
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
2393
+ },
2394
+ ],
2395
+ "has_more": false,
2396
+ "next_after": "2",
2397
+ },
2398
+ },
2399
+ {
2400
+ "checkpoint_complete": {
2401
+ "last_op_id": "2",
2402
+ },
2403
+ },
2404
+ ]
2405
+ `;
2406
+
2407
+ exports[`sync - postgres > storage v3 > expired token 1`] = `
2408
+ [
2409
+ {
2410
+ "token_expires_in": 0,
2411
+ },
2412
+ ]
2413
+ `;
2414
+
2415
+ exports[`sync - postgres > storage v3 > expiring token 1`] = `
2416
+ [
2417
+ {
2418
+ "checkpoint": {
2419
+ "buckets": [
2420
+ {
2421
+ "bucket": "1#mybucket[]",
2422
+ "checksum": 0,
2423
+ "count": 0,
2424
+ "priority": 3,
2425
+ "subscriptions": [
2426
+ {
2427
+ "default": 0,
2428
+ },
2429
+ ],
2430
+ },
2431
+ ],
2432
+ "last_op_id": "0",
2433
+ "streams": [
2434
+ {
2435
+ "errors": [],
2436
+ "is_default": true,
2437
+ "name": "mybucket",
2438
+ },
2439
+ ],
2440
+ "write_checkpoint": undefined,
2441
+ },
2442
+ },
2443
+ {
2444
+ "checkpoint_complete": {
2445
+ "last_op_id": "0",
2446
+ },
2447
+ },
2448
+ ]
2449
+ `;
2450
+
2451
+ exports[`sync - postgres > storage v3 > expiring token 2`] = `
2452
+ [
2453
+ {
2454
+ "token_expires_in": 0,
2455
+ },
2456
+ ]
2457
+ `;
2458
+
2459
+ exports[`sync - postgres > storage v3 > sends checkpoint complete line for empty checkpoint 1`] = `
2460
+ [
2461
+ {
2462
+ "checkpoint": {
2463
+ "buckets": [
2464
+ {
2465
+ "bucket": "1#mybucket[]",
2466
+ "checksum": -1221282404,
2467
+ "count": 1,
2468
+ "priority": 3,
2469
+ "subscriptions": [
2470
+ {
2471
+ "default": 0,
2472
+ },
2473
+ ],
2474
+ },
2475
+ ],
2476
+ "last_op_id": "1",
2477
+ "streams": [
2478
+ {
2479
+ "errors": [],
2480
+ "is_default": true,
2481
+ "name": "mybucket",
2482
+ },
2483
+ ],
2484
+ "write_checkpoint": undefined,
2485
+ },
2486
+ },
2487
+ {
2488
+ "data": {
2489
+ "after": "0",
2490
+ "bucket": "1#mybucket[]",
2491
+ "data": [
2492
+ {
2493
+ "checksum": 3073684892,
2494
+ "data": "{"id":"t1","description":"sync"}",
2495
+ "object_id": "t1",
2496
+ "object_type": "test",
2497
+ "op": "PUT",
2498
+ "op_id": "1",
2499
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
2500
+ },
2501
+ ],
2502
+ "has_more": false,
2503
+ "next_after": "1",
2504
+ },
2505
+ },
2506
+ null,
2507
+ {
2508
+ "checkpoint_complete": {
2509
+ "last_op_id": "1",
2510
+ },
2511
+ },
2512
+ {
2513
+ "checkpoint_diff": {
2514
+ "last_op_id": "1",
2515
+ "removed_buckets": [],
2516
+ "updated_buckets": [],
2517
+ "write_checkpoint": "1",
2518
+ },
2519
+ },
2520
+ {
2521
+ "checkpoint_complete": {
2522
+ "last_op_id": "1",
2523
+ },
2524
+ },
2525
+ ]
2526
+ `;
2527
+
2528
+ exports[`sync - postgres > storage v3 > sync buckets in order 1`] = `
2529
+ [
2530
+ {
2531
+ "checkpoint": {
2532
+ "buckets": [
2533
+ {
2534
+ "bucket": "1#b0[]",
2535
+ "checksum": 920318466,
2536
+ "count": 1,
2537
+ "priority": 2,
2538
+ "subscriptions": [
2539
+ {
2540
+ "default": 0,
2541
+ },
2542
+ ],
2543
+ },
2544
+ {
2545
+ "bucket": "1#b1[]",
2546
+ "checksum": -1382098757,
2547
+ "count": 1,
2548
+ "priority": 1,
2549
+ "subscriptions": [
2550
+ {
2551
+ "default": 1,
2552
+ },
2553
+ ],
2554
+ },
2555
+ ],
2556
+ "last_op_id": "2",
2557
+ "streams": [
2558
+ {
2559
+ "errors": [],
2560
+ "is_default": true,
2561
+ "name": "b0",
2562
+ },
2563
+ {
2564
+ "errors": [],
2565
+ "is_default": true,
2566
+ "name": "b1",
2567
+ },
2568
+ ],
2569
+ "write_checkpoint": undefined,
2570
+ },
2571
+ },
2572
+ {
2573
+ "data": {
2574
+ "after": "0",
2575
+ "bucket": "1#b1[]",
2576
+ "data": [
2577
+ {
2578
+ "checksum": 2912868539,
2579
+ "data": "{"id":"earlier","description":"Test 2"}",
2580
+ "object_id": "earlier",
2581
+ "object_type": "test",
2582
+ "op": "PUT",
2583
+ "op_id": "2",
2584
+ "subkey": "243b0e26-87b2-578a-993c-5ac5b6f7fd64",
2585
+ },
2586
+ ],
2587
+ "has_more": false,
2588
+ "next_after": "2",
2589
+ },
2590
+ },
2591
+ {
2592
+ "partial_checkpoint_complete": {
2593
+ "last_op_id": "2",
2594
+ "priority": 1,
2595
+ },
2596
+ },
2597
+ {
2598
+ "data": {
2599
+ "after": "0",
2600
+ "bucket": "1#b0[]",
2601
+ "data": [
2602
+ {
2603
+ "checksum": 920318466,
2604
+ "data": "{"id":"t1","description":"Test 1"}",
2605
+ "object_id": "t1",
2606
+ "object_type": "test",
2607
+ "op": "PUT",
2608
+ "op_id": "1",
2609
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
2610
+ },
2611
+ ],
2612
+ "has_more": false,
2613
+ "next_after": "1",
2614
+ },
2615
+ },
2616
+ {
2617
+ "checkpoint_complete": {
2618
+ "last_op_id": "2",
2619
+ },
2620
+ },
2621
+ ]
2622
+ `;
2623
+
2624
+ exports[`sync - postgres > storage v3 > sync global data 1`] = `
2625
+ [
2626
+ {
2627
+ "checkpoint": {
2628
+ "buckets": [
2629
+ {
2630
+ "bucket": "1#mybucket[]",
2631
+ "checksum": -93886621,
2632
+ "count": 2,
2633
+ "priority": 3,
2634
+ "subscriptions": [
2635
+ {
2636
+ "default": 0,
2637
+ },
2638
+ ],
2639
+ },
2640
+ ],
2641
+ "last_op_id": "2",
2642
+ "streams": [
2643
+ {
2644
+ "errors": [],
2645
+ "is_default": true,
2646
+ "name": "mybucket",
2647
+ },
2648
+ ],
2649
+ "write_checkpoint": undefined,
2650
+ },
2651
+ },
2652
+ {
2653
+ "data": {
2654
+ "after": "0",
2655
+ "bucket": "1#mybucket[]",
2656
+ "data": [
2657
+ {
2658
+ "checksum": 920318466,
2659
+ "data": "{"id":"t1","description":"Test 1"}",
2660
+ "object_id": "t1",
2661
+ "object_type": "test",
2662
+ "op": "PUT",
2663
+ "op_id": "1",
2664
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
2665
+ },
2666
+ {
2667
+ "checksum": 3280762209,
2668
+ "data": "{"id":"t2","description":"Test 2"}",
2669
+ "object_id": "t2",
2670
+ "object_type": "test",
2671
+ "op": "PUT",
2672
+ "op_id": "2",
2673
+ "subkey": "a17e6883-d5d2-599d-a805-d60528127dbd",
2674
+ },
2675
+ ],
2676
+ "has_more": false,
2677
+ "next_after": "2",
2678
+ },
2679
+ },
2680
+ {
2681
+ "checkpoint_complete": {
2682
+ "last_op_id": "2",
2683
+ },
2684
+ },
2685
+ ]
2686
+ `;
2687
+
2688
+ exports[`sync - postgres > storage v3 > sync interrupts low-priority buckets on new checkpoints (2) 1`] = `
2689
+ [
2690
+ {
2691
+ "checkpoint": {
2692
+ "buckets": [
2693
+ {
2694
+ "bucket": "1#b0a[]",
2695
+ "checksum": -659831575,
2696
+ "count": 2000,
2697
+ "priority": 2,
2698
+ "subscriptions": [
2699
+ {
2700
+ "default": 0,
2701
+ },
2702
+ ],
2703
+ },
2704
+ {
2705
+ "bucket": "1#b0b[]",
2706
+ "checksum": -659831575,
2707
+ "count": 2000,
2708
+ "priority": 2,
2709
+ "subscriptions": [
2710
+ {
2711
+ "default": 1,
2712
+ },
2713
+ ],
2714
+ },
2715
+ {
2716
+ "bucket": "1#b1[]",
2717
+ "checksum": -1096116670,
2718
+ "count": 1,
2719
+ "priority": 1,
2720
+ "subscriptions": [
2721
+ {
2722
+ "default": 2,
2723
+ },
2724
+ ],
2725
+ },
2726
+ ],
2727
+ "last_op_id": "4001",
2728
+ "streams": [
2729
+ {
2730
+ "errors": [],
2731
+ "is_default": true,
2732
+ "name": "b0a",
2733
+ },
2734
+ {
2735
+ "errors": [],
2736
+ "is_default": true,
2737
+ "name": "b0b",
2738
+ },
2739
+ {
2740
+ "errors": [],
2741
+ "is_default": true,
2742
+ "name": "b1",
2743
+ },
2744
+ ],
2745
+ "write_checkpoint": undefined,
2746
+ },
2747
+ },
2748
+ {
2749
+ "data": {
2750
+ "after": "0",
2751
+ "bucket": "1#b1[]",
2752
+ "data": undefined,
2753
+ "has_more": false,
2754
+ "next_after": "1",
2755
+ },
2756
+ },
2757
+ {
2758
+ "partial_checkpoint_complete": {
2759
+ "last_op_id": "4001",
2760
+ "priority": 1,
2761
+ },
2762
+ },
2763
+ {
2764
+ "data": {
2765
+ "after": "0",
2766
+ "bucket": "1#b0a[]",
2767
+ "data": undefined,
2768
+ "has_more": true,
2769
+ "next_after": "2000",
2770
+ },
2771
+ },
2772
+ {
2773
+ "data": {
2774
+ "after": "2000",
2775
+ "bucket": "1#b0a[]",
2776
+ "data": undefined,
2777
+ "has_more": true,
2778
+ "next_after": "4000",
2779
+ },
2780
+ },
2781
+ {
2782
+ "checkpoint_diff": {
2783
+ "last_op_id": "4004",
2784
+ "removed_buckets": [],
2785
+ "updated_buckets": [
2786
+ {
2787
+ "bucket": "1#b0a[]",
2788
+ "checksum": 883076828,
2789
+ "count": 2001,
2790
+ "priority": 2,
2791
+ "subscriptions": [
2792
+ {
2793
+ "default": 0,
2794
+ },
2795
+ ],
2796
+ },
2797
+ {
2798
+ "bucket": "1#b0b[]",
2799
+ "checksum": 883076828,
2800
+ "count": 2001,
2801
+ "priority": 2,
2802
+ "subscriptions": [
2803
+ {
2804
+ "default": 1,
2805
+ },
2806
+ ],
2807
+ },
2808
+ {
2809
+ "bucket": "1#b1[]",
2810
+ "checksum": 1841937527,
2811
+ "count": 2,
2812
+ "priority": 1,
2813
+ "subscriptions": [
2814
+ {
2815
+ "default": 2,
2816
+ },
2817
+ ],
2818
+ },
2819
+ ],
2820
+ "write_checkpoint": undefined,
2821
+ },
2822
+ },
2823
+ {
2824
+ "data": {
2825
+ "after": "1",
2826
+ "bucket": "1#b1[]",
2827
+ "data": undefined,
2828
+ "has_more": false,
2829
+ "next_after": "4002",
2830
+ },
2831
+ },
2832
+ {
2833
+ "partial_checkpoint_complete": {
2834
+ "last_op_id": "4004",
2835
+ "priority": 1,
2836
+ },
2837
+ },
2838
+ {
2839
+ "data": {
2840
+ "after": "4000",
2841
+ "bucket": "1#b0a[]",
2842
+ "data": undefined,
2843
+ "has_more": false,
2844
+ "next_after": "4003",
2845
+ },
2846
+ },
2847
+ {
2848
+ "data": {
2849
+ "after": "0",
2850
+ "bucket": "1#b0b[]",
2851
+ "data": undefined,
2852
+ "has_more": true,
2853
+ "next_after": "1999",
2854
+ },
2855
+ },
2856
+ {
2857
+ "data": {
2858
+ "after": "1999",
2859
+ "bucket": "1#b0b[]",
2860
+ "data": undefined,
2861
+ "has_more": true,
2862
+ "next_after": "3999",
2863
+ },
2864
+ },
2865
+ {
2866
+ "data": {
2867
+ "after": "3999",
2868
+ "bucket": "1#b0b[]",
2869
+ "data": undefined,
2870
+ "has_more": false,
2871
+ "next_after": "4004",
2872
+ },
2873
+ },
2874
+ {
2875
+ "checkpoint_complete": {
2876
+ "last_op_id": "4004",
2877
+ },
2878
+ },
2879
+ ]
2880
+ `;
2881
+
2882
+ exports[`sync - postgres > storage v3 > sync legacy non-raw data 1`] = `
2883
+ [
2884
+ {
2885
+ "checkpoint": {
2886
+ "buckets": [
2887
+ {
2888
+ "bucket": "1#mybucket[]",
2889
+ "checksum": -852817836,
2890
+ "count": 1,
2891
+ "priority": 3,
2892
+ "subscriptions": [
2893
+ {
2894
+ "default": 0,
2895
+ },
2896
+ ],
2897
+ },
2898
+ ],
2899
+ "last_op_id": "1",
2900
+ "streams": [
2901
+ {
2902
+ "errors": [],
2903
+ "is_default": true,
2904
+ "name": "mybucket",
2905
+ },
2906
+ ],
2907
+ "write_checkpoint": undefined,
2908
+ },
2909
+ },
2910
+ {
2911
+ "data": {
2912
+ "after": "0",
2913
+ "bucket": "1#mybucket[]",
2914
+ "data": [
2915
+ {
2916
+ "checksum": 3442149460n,
2917
+ "data": {
2918
+ "description": "Test
2919
+ "string"",
2920
+ "id": "t1",
2921
+ "large_num": 12345678901234567890n,
2922
+ },
2923
+ "object_id": "t1",
2924
+ "object_type": "test",
2925
+ "op": "PUT",
2926
+ "op_id": "1",
2927
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
2928
+ },
2929
+ ],
2930
+ "has_more": false,
2931
+ "next_after": "1",
2932
+ },
2933
+ },
2934
+ {
2935
+ "checkpoint_complete": {
2936
+ "last_op_id": "1",
2937
+ },
2938
+ },
2939
+ ]
2940
+ `;
2941
+
2942
+ exports[`sync - postgres > storage v3 > sync updates to data query only 1`] = `
2943
+ [
2944
+ {
2945
+ "checkpoint": {
2946
+ "buckets": [
2947
+ {
2948
+ "bucket": "1#by_user["user1"]",
2949
+ "checksum": 0,
2950
+ "count": 0,
2951
+ "priority": 3,
2952
+ "subscriptions": [
2953
+ {
2954
+ "default": 0,
2955
+ },
2956
+ ],
2957
+ },
2958
+ ],
2959
+ "last_op_id": "1",
2960
+ "streams": [
2961
+ {
2962
+ "errors": [],
2963
+ "is_default": true,
2964
+ "name": "by_user",
2965
+ },
2966
+ ],
2967
+ "write_checkpoint": undefined,
2968
+ },
2969
+ },
2970
+ {
2971
+ "checkpoint_complete": {
2972
+ "last_op_id": "1",
2973
+ },
2974
+ },
2975
+ ]
2976
+ `;
2977
+
2978
+ exports[`sync - postgres > storage v3 > sync updates to data query only 2`] = `
2979
+ [
2980
+ {
2981
+ "checkpoint_diff": {
2982
+ "last_op_id": "2",
2983
+ "removed_buckets": [],
2984
+ "updated_buckets": [
2985
+ {
2986
+ "bucket": "1#by_user["user1"]",
2987
+ "checksum": 1418351250,
2988
+ "count": 1,
2989
+ "priority": 3,
2990
+ "subscriptions": [
2991
+ {
2992
+ "default": 0,
2993
+ },
2994
+ ],
2995
+ },
2996
+ ],
2997
+ "write_checkpoint": undefined,
2998
+ },
2999
+ },
3000
+ {
3001
+ "data": {
3002
+ "after": "0",
3003
+ "bucket": "1#by_user["user1"]",
3004
+ "data": [
3005
+ {
3006
+ "checksum": 1418351250,
3007
+ "data": "{"id":"list1","user_id":"user1","name":"User 1"}",
3008
+ "object_id": "list1",
3009
+ "object_type": "lists",
3010
+ "op": "PUT",
3011
+ "op_id": "2",
3012
+ "subkey": "5ad0aa14-3d5e-5428-ad5b-2c33927d991c",
3013
+ },
3014
+ ],
3015
+ "has_more": false,
3016
+ "next_after": "2",
3017
+ },
3018
+ },
3019
+ {
3020
+ "checkpoint_complete": {
3021
+ "last_op_id": "2",
3022
+ },
3023
+ },
3024
+ ]
3025
+ `;
3026
+
3027
+ exports[`sync - postgres > storage v3 > sync updates to global data 1`] = `
3028
+ [
3029
+ {
3030
+ "checkpoint": {
3031
+ "buckets": [
3032
+ {
3033
+ "bucket": "1#mybucket[]",
3034
+ "checksum": 0,
3035
+ "count": 0,
3036
+ "priority": 3,
3037
+ "subscriptions": [
3038
+ {
3039
+ "default": 0,
3040
+ },
3041
+ ],
3042
+ },
3043
+ ],
3044
+ "last_op_id": "0",
3045
+ "streams": [
3046
+ {
3047
+ "errors": [],
3048
+ "is_default": true,
3049
+ "name": "mybucket",
3050
+ },
3051
+ ],
3052
+ "write_checkpoint": undefined,
3053
+ },
3054
+ },
3055
+ {
3056
+ "checkpoint_complete": {
3057
+ "last_op_id": "0",
3058
+ },
3059
+ },
3060
+ ]
3061
+ `;
3062
+
3063
+ exports[`sync - postgres > storage v3 > sync updates to global data 2`] = `
3064
+ [
3065
+ {
3066
+ "checkpoint_diff": {
3067
+ "last_op_id": "1",
3068
+ "removed_buckets": [],
3069
+ "updated_buckets": [
3070
+ {
3071
+ "bucket": "1#mybucket[]",
3072
+ "checksum": 920318466,
3073
+ "count": 1,
3074
+ "priority": 3,
3075
+ "subscriptions": [
3076
+ {
3077
+ "default": 0,
3078
+ },
3079
+ ],
3080
+ },
3081
+ ],
3082
+ "write_checkpoint": undefined,
3083
+ },
3084
+ },
3085
+ {
3086
+ "data": {
3087
+ "after": "0",
3088
+ "bucket": "1#mybucket[]",
3089
+ "data": [
3090
+ {
3091
+ "checksum": 920318466,
3092
+ "data": "{"id":"t1","description":"Test 1"}",
3093
+ "object_id": "t1",
3094
+ "object_type": "test",
3095
+ "op": "PUT",
3096
+ "op_id": "1",
3097
+ "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
3098
+ },
3099
+ ],
3100
+ "has_more": false,
3101
+ "next_after": "1",
3102
+ },
3103
+ },
3104
+ {
3105
+ "checkpoint_complete": {
3106
+ "last_op_id": "1",
3107
+ },
3108
+ },
3109
+ ]
3110
+ `;
3111
+
3112
+ exports[`sync - postgres > storage v3 > sync updates to global data 3`] = `
3113
+ [
3114
+ {
3115
+ "checkpoint_diff": {
3116
+ "last_op_id": "2",
3117
+ "removed_buckets": [],
3118
+ "updated_buckets": [
3119
+ {
3120
+ "bucket": "1#mybucket[]",
3121
+ "checksum": -93886621,
3122
+ "count": 2,
3123
+ "priority": 3,
3124
+ "subscriptions": [
3125
+ {
3126
+ "default": 0,
3127
+ },
3128
+ ],
3129
+ },
3130
+ ],
3131
+ "write_checkpoint": undefined,
3132
+ },
3133
+ },
3134
+ {
3135
+ "data": {
3136
+ "after": "1",
3137
+ "bucket": "1#mybucket[]",
3138
+ "data": [
3139
+ {
3140
+ "checksum": 3280762209,
3141
+ "data": "{"id":"t2","description":"Test 2"}",
3142
+ "object_id": "t2",
3143
+ "object_type": "test",
3144
+ "op": "PUT",
3145
+ "op_id": "2",
3146
+ "subkey": "a17e6883-d5d2-599d-a805-d60528127dbd",
3147
+ },
3148
+ ],
3149
+ "has_more": false,
3150
+ "next_after": "2",
3151
+ },
3152
+ },
3153
+ {
3154
+ "checkpoint_complete": {
3155
+ "last_op_id": "2",
3156
+ },
3157
+ },
3158
+ ]
3159
+ `;
3160
+
3161
+ exports[`sync - postgres > storage v3 > sync updates to parameter query + data 1`] = `
3162
+ [
3163
+ {
3164
+ "checkpoint": {
3165
+ "buckets": [],
3166
+ "last_op_id": "0",
3167
+ "streams": [
3168
+ {
3169
+ "errors": [],
3170
+ "is_default": true,
3171
+ "name": "by_user",
3172
+ },
3173
+ ],
3174
+ "write_checkpoint": undefined,
3175
+ },
3176
+ },
3177
+ {
3178
+ "checkpoint_complete": {
3179
+ "last_op_id": "0",
3180
+ },
3181
+ },
3182
+ ]
3183
+ `;
3184
+
3185
+ exports[`sync - postgres > storage v3 > sync updates to parameter query + data 2`] = `
3186
+ [
3187
+ {
3188
+ "checkpoint_diff": {
3189
+ "last_op_id": "2",
3190
+ "removed_buckets": [],
3191
+ "updated_buckets": [
3192
+ {
3193
+ "bucket": "1#by_user["user1"]",
3194
+ "checksum": 1418351250,
3195
+ "count": 1,
3196
+ "priority": 3,
3197
+ "subscriptions": [
3198
+ {
3199
+ "default": 0,
3200
+ },
3201
+ ],
3202
+ },
3203
+ ],
3204
+ "write_checkpoint": undefined,
3205
+ },
3206
+ },
3207
+ {
3208
+ "data": {
3209
+ "after": "0",
3210
+ "bucket": "1#by_user["user1"]",
3211
+ "data": [
3212
+ {
3213
+ "checksum": 1418351250,
3214
+ "data": "{"id":"list1","user_id":"user1","name":"User 1"}",
3215
+ "object_id": "list1",
3216
+ "object_type": "lists",
3217
+ "op": "PUT",
3218
+ "op_id": "1",
3219
+ "subkey": "5ad0aa14-3d5e-5428-ad5b-2c33927d991c",
3220
+ },
3221
+ ],
3222
+ "has_more": false,
3223
+ "next_after": "1",
3224
+ },
3225
+ },
3226
+ {
3227
+ "checkpoint_complete": {
3228
+ "last_op_id": "2",
3229
+ },
3230
+ },
3231
+ ]
3232
+ `;
3233
+
3234
+ exports[`sync - postgres > storage v3 > sync updates to parameter query only 1`] = `
3235
+ [
3236
+ {
3237
+ "checkpoint": {
3238
+ "buckets": [],
3239
+ "last_op_id": "0",
3240
+ "streams": [
3241
+ {
3242
+ "errors": [],
3243
+ "is_default": true,
3244
+ "name": "by_user",
3245
+ },
3246
+ ],
3247
+ "write_checkpoint": undefined,
3248
+ },
3249
+ },
3250
+ {
3251
+ "checkpoint_complete": {
3252
+ "last_op_id": "0",
3253
+ },
3254
+ },
3255
+ ]
3256
+ `;
3257
+
3258
+ exports[`sync - postgres > storage v3 > sync updates to parameter query only 2`] = `
3259
+ [
3260
+ {
3261
+ "checkpoint_diff": {
3262
+ "last_op_id": "1",
3263
+ "removed_buckets": [],
3264
+ "updated_buckets": [
3265
+ {
3266
+ "bucket": "1#by_user["user1"]",
3267
+ "checksum": 0,
3268
+ "count": 0,
3269
+ "priority": 3,
3270
+ "subscriptions": [
3271
+ {
3272
+ "default": 0,
3273
+ },
3274
+ ],
3275
+ },
3276
+ ],
3277
+ "write_checkpoint": undefined,
3278
+ },
3279
+ },
3280
+ {
3281
+ "checkpoint_complete": {
3282
+ "last_op_id": "1",
3283
+ },
3284
+ },
3285
+ ]
3286
+ `;