@terreno/syncdb 57.16.1 → 57.17.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.
@@ -3,6 +3,7 @@ import "fake-indexeddb/auto";
3
3
  import {describe, expect, it} from "bun:test";
4
4
  import {assert} from "chai";
5
5
 
6
+ import {betterAuthAdapter} from "./auth/betterAuthAdapter";
6
7
  import {createSyncDb, type SyncDbConfig} from "./client";
7
8
  import {createLocalKeyProvider, DEFAULT_KEY_CACHE_DB_NAME} from "./crypto/keyProviders";
8
9
  import {getConflict} from "./mutations/conflicts";
@@ -2636,6 +2637,46 @@ describe("createSyncDb", () => {
2636
2637
  });
2637
2638
  });
2638
2639
 
2640
+ describe("auth change while the session read fails (betterAuthAdapter)", () => {
2641
+ it("keeps the user and mutate() working when the device goes offline before the auth-change handler reads the session", async () => {
2642
+ // start() subscribes to the session atom, which hands over the current session at
2643
+ // once; the handler that emission queues runs after start() resolves. When the
2644
+ // network drops in between, its get-session read fails. That must not count as a
2645
+ // sign-out.
2646
+ const listeners = new Set<(value: unknown) => void>();
2647
+ // Only start()'s own read gets through; the network is gone for every later one.
2648
+ let sessionReads = 0;
2649
+ const session = {data: {session: {token: "tok"}, user: {id: "u1"}}};
2650
+ const harness = makeHarness({
2651
+ authProvider: betterAuthAdapter({
2652
+ getSession: async () => {
2653
+ sessionReads += 1;
2654
+ if (sessionReads > 1) {
2655
+ throw new TypeError("Failed to fetch");
2656
+ }
2657
+ return session;
2658
+ },
2659
+ useSession: {
2660
+ subscribe: (listener) => {
2661
+ listeners.add(listener);
2662
+ listener(session);
2663
+ return () => listeners.delete(listener);
2664
+ },
2665
+ },
2666
+ }),
2667
+ });
2668
+ const client = createSyncDb(harness.config);
2669
+ await client.start();
2670
+ await waitUntil(() => sessionReads > 1);
2671
+ await flush();
2672
+
2673
+ expect(client.getSyncStatus().paused).toBeUndefined();
2674
+ const {id} = client.mutate({collection: "todos", data: {title: "x"}, operation: "create"});
2675
+ expect(id).toBeTruthy();
2676
+ await client.stop();
2677
+ });
2678
+ });
2679
+
2639
2680
  describe("signOut() (A4)", () => {
2640
2681
  it("serializes against a concurrent auth change and leaves no destroyed persister behind", async () => {
2641
2682
  const harness = makeHarness();