@terreno/syncdb 57.3.0 → 57.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/dist/auth/betterAuthReactClient.d.ts +17 -0
- package/dist/auth/betterAuthReactClient.d.ts.map +1 -0
- package/dist/auth/betterAuthReactClient.js +11 -0
- package/dist/auth/betterAuthReactClient.js.map +1 -0
- package/dist/auth/betterAuthReactClient.test.d.ts +2 -0
- package/dist/auth/betterAuthReactClient.test.d.ts.map +1 -0
- package/dist/auth/betterAuthReactClient.test.js +43 -0
- package/dist/auth/betterAuthReactClient.test.js.map +1 -0
- package/dist/client.adminWindowMutation.test.d.ts +2 -0
- package/dist/client.adminWindowMutation.test.d.ts.map +1 -0
- package/dist/client.adminWindowMutation.test.js +65 -0
- package/dist/client.adminWindowMutation.test.js.map +1 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +46 -4
- package/dist/client.js.map +1 -1
- package/dist/client.test.js +232 -2
- package/dist/client.test.js.map +1 -1
- package/dist/codegen/emitSdk.js +3 -3
- package/dist/codegen/emitSdk.js.map +1 -1
- package/dist/codegen/generate.test.js +32 -2
- package/dist/codegen/generate.test.js.map +1 -1
- package/dist/codegen/safeIdentifiers.d.ts +5 -0
- package/dist/codegen/safeIdentifiers.d.ts.map +1 -1
- package/dist/codegen/safeIdentifiers.js +8 -0
- package/dist/codegen/safeIdentifiers.js.map +1 -1
- package/dist/codegen/safeIdentifiers.test.js +20 -8
- package/dist/codegen/safeIdentifiers.test.js.map +1 -1
- package/dist/codegen/types.d.ts +4 -3
- package/dist/codegen/types.d.ts.map +1 -1
- package/dist/debug/debugChannel.test.js +5 -0
- package/dist/debug/debugChannel.test.js.map +1 -1
- package/dist/debug/debugLog.d.ts +1 -0
- package/dist/debug/debugLog.d.ts.map +1 -1
- package/dist/debug/debugLog.js +1 -0
- package/dist/debug/debugLog.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/isolated/defaultPersisterFactoryNativeErrors.isolated.d.ts +2 -0
- package/dist/isolated/defaultPersisterFactoryNativeErrors.isolated.d.ts.map +1 -0
- package/dist/isolated/defaultPersisterFactoryNativeErrors.isolated.js +19 -0
- package/dist/isolated/defaultPersisterFactoryNativeErrors.isolated.js.map +1 -0
- package/dist/mutations/outbox.d.ts +7 -3
- package/dist/mutations/outbox.d.ts.map +1 -1
- package/dist/mutations/outbox.js +6 -0
- package/dist/mutations/outbox.js.map +1 -1
- package/dist/mutations/outbox.test.js +17 -0
- package/dist/mutations/outbox.test.js.map +1 -1
- package/dist/storage/idb.d.ts +1 -0
- package/dist/storage/idb.d.ts.map +1 -1
- package/dist/storage/idb.js +1 -0
- package/dist/storage/idb.js.map +1 -1
- package/dist/storage/schema.d.ts.map +1 -1
- package/dist/storage/schema.js +1 -0
- package/dist/storage/schema.js.map +1 -1
- package/dist/storage/store.d.ts +3 -2
- package/dist/storage/store.d.ts.map +1 -1
- package/dist/storage/types.d.ts +1 -7
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/sync/deltaApplier.d.ts +2 -0
- package/dist/sync/deltaApplier.d.ts.map +1 -1
- package/dist/sync/deltaApplier.js +9 -0
- package/dist/sync/deltaApplier.js.map +1 -1
- package/dist/sync/deltaApplier.test.js +63 -0
- package/dist/sync/deltaApplier.test.js.map +1 -1
- package/dist/sync/entityRepair.d.ts +1 -0
- package/dist/sync/entityRepair.d.ts.map +1 -1
- package/dist/sync/entityRepair.js +1 -0
- package/dist/sync/entityRepair.js.map +1 -1
- package/dist/sync/httpChannel.d.ts +3 -1
- package/dist/sync/httpChannel.d.ts.map +1 -1
- package/dist/sync/httpChannel.js +3 -1
- package/dist/sync/httpChannel.js.map +1 -1
- package/dist/sync/httpChannel.test.js +68 -0
- package/dist/sync/httpChannel.test.js.map +1 -1
- package/dist/sync/replayCoordinator.d.ts +6 -12
- package/dist/sync/replayCoordinator.d.ts.map +1 -1
- package/dist/sync/replayCoordinator.js +9 -2
- package/dist/sync/replayCoordinator.js.map +1 -1
- package/dist/sync/socketTransport.d.ts +3 -45
- package/dist/sync/socketTransport.d.ts.map +1 -1
- package/dist/sync/socketTransport.js +31 -9
- package/dist/sync/socketTransport.js.map +1 -1
- package/dist/sync/socketTransport.test.js +7 -0
- package/dist/sync/socketTransport.test.js.map +1 -1
- package/dist/sync/transport.d.ts +3 -1
- package/dist/sync/transport.d.ts.map +1 -1
- package/dist/sync/windowHydrate.d.ts +25 -0
- package/dist/sync/windowHydrate.d.ts.map +1 -0
- package/dist/sync/windowHydrate.js +67 -0
- package/dist/sync/windowHydrate.js.map +1 -0
- package/dist/sync/windowHydrate.test.d.ts +2 -0
- package/dist/sync/windowHydrate.test.d.ts.map +1 -0
- package/dist/sync/windowHydrate.test.js +164 -0
- package/dist/sync/windowHydrate.test.js.map +1 -0
- package/dist/testing/fakeTransport.js +1 -1
- package/dist/testing/fakeTransport.js.map +1 -1
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/auth/betterAuthReactClient.test.ts +50 -0
- package/src/auth/betterAuthReactClient.ts +33 -0
- package/src/client.adminWindowMutation.test.ts +69 -0
- package/src/client.test.ts +248 -2
- package/src/client.ts +85 -3
- package/src/codegen/emitSdk.ts +3 -3
- package/src/codegen/generate.test.ts +35 -2
- package/src/codegen/safeIdentifiers.test.ts +37 -10
- package/src/codegen/safeIdentifiers.ts +17 -0
- package/src/codegen/types.ts +3 -3
- package/src/debug/debugChannel.test.ts +6 -0
- package/src/debug/debugLog.ts +1 -0
- package/src/index.ts +4 -0
- package/src/isolated/defaultPersisterFactoryNativeErrors.isolated.ts +23 -0
- package/src/mutations/outbox.test.ts +20 -0
- package/src/mutations/outbox.ts +11 -3
- package/src/storage/idb.ts +1 -0
- package/src/storage/schema.ts +1 -0
- package/src/storage/store.ts +2 -2
- package/src/storage/types.ts +1 -8
- package/src/sync/deltaApplier.test.ts +70 -0
- package/src/sync/deltaApplier.ts +10 -0
- package/src/sync/entityRepair.ts +1 -0
- package/src/sync/httpChannel.test.ts +82 -0
- package/src/sync/httpChannel.ts +5 -0
- package/src/sync/replayCoordinator.ts +10 -3
- package/src/sync/socketTransport.test.ts +10 -2
- package/src/sync/socketTransport.ts +64 -22
- package/src/sync/transport.ts +1 -1
- package/src/sync/windowHydrate.test.ts +179 -0
- package/src/sync/windowHydrate.ts +97 -0
- package/src/testing/fakeTransport.ts +1 -1
- package/src/types.ts +16 -0
package/dist/client.test.js
CHANGED
|
@@ -145,9 +145,9 @@ const makeObservableTransport = (base) => {
|
|
|
145
145
|
events.push("disconnect");
|
|
146
146
|
base.disconnect();
|
|
147
147
|
},
|
|
148
|
-
subscribe: (collections) => {
|
|
148
|
+
subscribe: (collections, options) => {
|
|
149
149
|
events.push("subscribe");
|
|
150
|
-
base.subscribe(collections);
|
|
150
|
+
base.subscribe(collections, options);
|
|
151
151
|
},
|
|
152
152
|
},
|
|
153
153
|
};
|
|
@@ -403,6 +403,20 @@ describe("createSyncDb", () => {
|
|
|
403
403
|
await expect(client.reconcile()).resolves.toBeUndefined();
|
|
404
404
|
await client.stop();
|
|
405
405
|
});
|
|
406
|
+
it("window collection reconcile interval does not GET /sync/snapshot", async () => {
|
|
407
|
+
const snapshotStreams = [];
|
|
408
|
+
const harness = makeHarness({ reconcileIntervalMs: 20, windowCollections: ["todos"] });
|
|
409
|
+
const fetchSnapshotPage = harness.http.channel.fetchSnapshotPage;
|
|
410
|
+
harness.http.channel.fetchSnapshotPage = async (args) => {
|
|
411
|
+
snapshotStreams.push(args.stream);
|
|
412
|
+
return fetchSnapshotPage(args);
|
|
413
|
+
};
|
|
414
|
+
const client = createSyncDb(harness.config);
|
|
415
|
+
await client.start();
|
|
416
|
+
await new Promise((resolve) => setTimeout(resolve, 70));
|
|
417
|
+
assert.deepEqual(snapshotStreams, []);
|
|
418
|
+
await client.stop();
|
|
419
|
+
});
|
|
406
420
|
});
|
|
407
421
|
describe("subscribe confirmation catch-up", () => {
|
|
408
422
|
it("pages a confirmed stream, catching a write the startup snapshot missed", async () => {
|
|
@@ -451,6 +465,27 @@ describe("createSyncDb", () => {
|
|
|
451
465
|
expect(client.store.getKnownStreams()).not.toContain("projects|all");
|
|
452
466
|
await client.stop();
|
|
453
467
|
});
|
|
468
|
+
it("window subscribe confirmation does not GET /sync/snapshot", async () => {
|
|
469
|
+
const harness = makeHarness({ windowCollections: ["todos"] });
|
|
470
|
+
const snapshotStreams = [];
|
|
471
|
+
const fetchSnapshotPage = harness.http.channel.fetchSnapshotPage;
|
|
472
|
+
harness.http.channel.fetchSnapshotPage = async (args) => {
|
|
473
|
+
snapshotStreams.push(args.stream);
|
|
474
|
+
return fetchSnapshotPage(args);
|
|
475
|
+
};
|
|
476
|
+
const client = createSyncDb(harness.config);
|
|
477
|
+
await client.start();
|
|
478
|
+
await flush();
|
|
479
|
+
snapshotStreams.length = 0;
|
|
480
|
+
harness.transport.confirmSubscribed({
|
|
481
|
+
collection: "todos",
|
|
482
|
+
mode: "window",
|
|
483
|
+
streams: ["todos|admin"],
|
|
484
|
+
});
|
|
485
|
+
await flush();
|
|
486
|
+
assert.deepEqual(snapshotStreams, []);
|
|
487
|
+
await client.stop();
|
|
488
|
+
});
|
|
454
489
|
it("does not page while simulated-offline", async () => {
|
|
455
490
|
const harness = makeHarness();
|
|
456
491
|
const client = createSyncDb(harness.config);
|
|
@@ -2581,5 +2616,200 @@ describe("createSyncDb", () => {
|
|
|
2581
2616
|
}
|
|
2582
2617
|
});
|
|
2583
2618
|
});
|
|
2619
|
+
describe("forceResync", () => {
|
|
2620
|
+
it("skips when there is no HTTP channel", async () => {
|
|
2621
|
+
const harness = makeHarness();
|
|
2622
|
+
const client = createSyncDb({
|
|
2623
|
+
...harness.config,
|
|
2624
|
+
httpChannel: undefined,
|
|
2625
|
+
});
|
|
2626
|
+
const result = await client.forceResync();
|
|
2627
|
+
assert.deepEqual(result, {
|
|
2628
|
+
ok: false,
|
|
2629
|
+
purged: 0,
|
|
2630
|
+
reason: "noHttpChannel",
|
|
2631
|
+
repaired: 0,
|
|
2632
|
+
streams: 0,
|
|
2633
|
+
});
|
|
2634
|
+
});
|
|
2635
|
+
it("skips while simulated offline", async () => {
|
|
2636
|
+
const harness = makeHarness();
|
|
2637
|
+
const client = createSyncDb(harness.config);
|
|
2638
|
+
await client.start();
|
|
2639
|
+
client.goOffline();
|
|
2640
|
+
const result = await client.forceResync();
|
|
2641
|
+
assert.equal(result.ok, false);
|
|
2642
|
+
assert.equal(result.reason, "offline");
|
|
2643
|
+
await client.stop();
|
|
2644
|
+
});
|
|
2645
|
+
it("skips while auth-paused", async () => {
|
|
2646
|
+
const harness = makeHarness();
|
|
2647
|
+
harness.http.state.streamsError = new AuthRequiredError();
|
|
2648
|
+
const client = createSyncDb(harness.config);
|
|
2649
|
+
await client.start();
|
|
2650
|
+
await flush();
|
|
2651
|
+
const result = await client.forceResync();
|
|
2652
|
+
assert.equal(result.ok, false);
|
|
2653
|
+
assert.equal(result.reason, "authPaused");
|
|
2654
|
+
await client.stop();
|
|
2655
|
+
});
|
|
2656
|
+
it("skips when the server and local store have no streams", async () => {
|
|
2657
|
+
const harness = makeHarness();
|
|
2658
|
+
harness.http.state.streams = [];
|
|
2659
|
+
const client = createSyncDb(harness.config);
|
|
2660
|
+
await client.start();
|
|
2661
|
+
await flush();
|
|
2662
|
+
const result = await client.forceResync();
|
|
2663
|
+
assert.equal(result.ok, false);
|
|
2664
|
+
assert.equal(result.reason, "noStreams");
|
|
2665
|
+
await client.stop();
|
|
2666
|
+
});
|
|
2667
|
+
it("purges local rows and re-bootstraps from the snapshot", async () => {
|
|
2668
|
+
const harness = makeHarness();
|
|
2669
|
+
harness.http.state.pages[DEFAULT_STREAM] = {
|
|
2670
|
+
cursor: 1,
|
|
2671
|
+
entities: [{ data: { title: "stale" }, deleted: false, id: "local-1", seq: 1 }],
|
|
2672
|
+
frontierSeq: 1,
|
|
2673
|
+
hasMore: false,
|
|
2674
|
+
oldestRetainedSeq: 0,
|
|
2675
|
+
stream: DEFAULT_STREAM,
|
|
2676
|
+
};
|
|
2677
|
+
const client = createSyncDb(harness.config);
|
|
2678
|
+
await client.start();
|
|
2679
|
+
await flush();
|
|
2680
|
+
assert.deepEqual(client.store.getEntity({ collection: "todos", id: "local-1" })?.data, {
|
|
2681
|
+
title: "stale",
|
|
2682
|
+
});
|
|
2683
|
+
harness.http.state.pages[DEFAULT_STREAM] = {
|
|
2684
|
+
cursor: 9,
|
|
2685
|
+
entities: [{ data: { title: "fresh" }, deleted: false, id: "server-1", seq: 9 }],
|
|
2686
|
+
frontierSeq: 9,
|
|
2687
|
+
hasMore: false,
|
|
2688
|
+
oldestRetainedSeq: 0,
|
|
2689
|
+
stream: DEFAULT_STREAM,
|
|
2690
|
+
};
|
|
2691
|
+
const result = await client.forceResync();
|
|
2692
|
+
assert.equal(result.ok, true);
|
|
2693
|
+
assert.isAtLeast(result.streams, 1);
|
|
2694
|
+
assert.isAtLeast(result.purged, 1);
|
|
2695
|
+
assert.equal(client.store.getEntity({ collection: "todos", id: "local-1" }), undefined);
|
|
2696
|
+
assert.deepEqual(client.store.getEntity({ collection: "todos", id: "server-1" })?.data, {
|
|
2697
|
+
title: "fresh",
|
|
2698
|
+
});
|
|
2699
|
+
await client.stop();
|
|
2700
|
+
});
|
|
2701
|
+
it("falls back to locally known streams when discovery 401s", async () => {
|
|
2702
|
+
const harness = makeHarness();
|
|
2703
|
+
harness.http.state.pages[DEFAULT_STREAM] = {
|
|
2704
|
+
cursor: 2,
|
|
2705
|
+
entities: [{ data: { title: "kept" }, deleted: false, id: "k1", seq: 2 }],
|
|
2706
|
+
frontierSeq: 2,
|
|
2707
|
+
hasMore: false,
|
|
2708
|
+
oldestRetainedSeq: 0,
|
|
2709
|
+
stream: DEFAULT_STREAM,
|
|
2710
|
+
};
|
|
2711
|
+
const client = createSyncDb(harness.config);
|
|
2712
|
+
await client.start();
|
|
2713
|
+
await flush();
|
|
2714
|
+
harness.http.state.streamsError = new AuthRequiredError();
|
|
2715
|
+
const result = await client.forceResync();
|
|
2716
|
+
assert.equal(result.ok, true);
|
|
2717
|
+
assert.equal(result.streams, 1);
|
|
2718
|
+
assert.deepEqual(client.store.getEntity({ collection: "todos", id: "k1" })?.data, {
|
|
2719
|
+
title: "kept",
|
|
2720
|
+
});
|
|
2721
|
+
await client.stop();
|
|
2722
|
+
});
|
|
2723
|
+
it("pauses and reports authPaused when a snapshot page 401s mid-resync", async () => {
|
|
2724
|
+
const harness = makeHarness();
|
|
2725
|
+
const client = createSyncDb(harness.config);
|
|
2726
|
+
await client.start();
|
|
2727
|
+
await flush();
|
|
2728
|
+
harness.http.channel.fetchSnapshotPage = async () => {
|
|
2729
|
+
throw new AuthRequiredError();
|
|
2730
|
+
};
|
|
2731
|
+
const result = await client.forceResync();
|
|
2732
|
+
assert.equal(result.ok, false);
|
|
2733
|
+
assert.equal(result.reason, "authPaused");
|
|
2734
|
+
assert.equal(client.getSyncStatus().paused, "auth");
|
|
2735
|
+
await client.stop();
|
|
2736
|
+
});
|
|
2737
|
+
it("rethrows a non-auth discovery error", async () => {
|
|
2738
|
+
const harness = makeHarness();
|
|
2739
|
+
const client = createSyncDb(harness.config);
|
|
2740
|
+
await client.start();
|
|
2741
|
+
await flush();
|
|
2742
|
+
harness.http.state.streamsError = new Error("resync boom");
|
|
2743
|
+
await expect(client.forceResync()).rejects.toThrow("resync boom");
|
|
2744
|
+
await client.stop();
|
|
2745
|
+
});
|
|
2746
|
+
it("repairs marked entities after re-bootstrap", async () => {
|
|
2747
|
+
const harness = makeHarness();
|
|
2748
|
+
harness.http.state.pages[DEFAULT_STREAM] = {
|
|
2749
|
+
cursor: 1,
|
|
2750
|
+
entities: [{ data: { title: "broken" }, deleted: false, id: "r1", seq: 1 }],
|
|
2751
|
+
frontierSeq: 1,
|
|
2752
|
+
hasMore: false,
|
|
2753
|
+
oldestRetainedSeq: 0,
|
|
2754
|
+
stream: DEFAULT_STREAM,
|
|
2755
|
+
};
|
|
2756
|
+
const client = createSyncDb(harness.config);
|
|
2757
|
+
await client.start();
|
|
2758
|
+
await flush();
|
|
2759
|
+
client.store.markNeedsRepair({
|
|
2760
|
+
collection: "todos",
|
|
2761
|
+
entityId: "r1",
|
|
2762
|
+
missedSeq: 1,
|
|
2763
|
+
stream: DEFAULT_STREAM,
|
|
2764
|
+
});
|
|
2765
|
+
harness.http.channel.fetchEntities = async () => ({
|
|
2766
|
+
entities: [
|
|
2767
|
+
{
|
|
2768
|
+
data: { title: "repaired" },
|
|
2769
|
+
deleted: false,
|
|
2770
|
+
id: "r1",
|
|
2771
|
+
seq: 2,
|
|
2772
|
+
stream: DEFAULT_STREAM,
|
|
2773
|
+
},
|
|
2774
|
+
],
|
|
2775
|
+
});
|
|
2776
|
+
const result = await client.forceResync();
|
|
2777
|
+
assert.equal(result.ok, true);
|
|
2778
|
+
await client.stop();
|
|
2779
|
+
});
|
|
2780
|
+
it("abandons the resync when the user changes during discovery", async () => {
|
|
2781
|
+
const harness = makeHarness();
|
|
2782
|
+
const client = createSyncDb(harness.config);
|
|
2783
|
+
await client.start();
|
|
2784
|
+
await flush();
|
|
2785
|
+
const originalFetch = harness.http.channel.fetchStreams;
|
|
2786
|
+
harness.http.channel.fetchStreams = async () => {
|
|
2787
|
+
harness.auth.setUserId("other-user");
|
|
2788
|
+
harness.auth.emitAuthChange();
|
|
2789
|
+
await flush();
|
|
2790
|
+
return originalFetch();
|
|
2791
|
+
};
|
|
2792
|
+
const result = await client.forceResync();
|
|
2793
|
+
assert.equal(result.ok, false);
|
|
2794
|
+
assert.equal(result.reason, "superseded");
|
|
2795
|
+
await client.stop();
|
|
2796
|
+
});
|
|
2797
|
+
it("abandons the resync when the user changes during bootstrap", async () => {
|
|
2798
|
+
const harness = makeHarness();
|
|
2799
|
+
const client = createSyncDb(harness.config);
|
|
2800
|
+
await client.start();
|
|
2801
|
+
await flush();
|
|
2802
|
+
harness.http.channel.fetchSnapshotPage = async ({ stream }) => {
|
|
2803
|
+
harness.auth.setUserId("other-user");
|
|
2804
|
+
harness.auth.emitAuthChange();
|
|
2805
|
+
await flush();
|
|
2806
|
+
return emptyPage(stream);
|
|
2807
|
+
};
|
|
2808
|
+
const result = await client.forceResync();
|
|
2809
|
+
assert.equal(result.ok, false);
|
|
2810
|
+
assert.equal(result.reason, "superseded");
|
|
2811
|
+
await client.stop();
|
|
2812
|
+
});
|
|
2813
|
+
});
|
|
2584
2814
|
});
|
|
2585
2815
|
//# sourceMappingURL=client.test.js.map
|