@gadicc/loom 1.29.0 → 1.30.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/esm/mod.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import "./_dnt.polyfills.js";
2
2
  export * from "./src/apiKeys/mod.js";
3
+ export * from "./src/clientData/mod.js";
3
4
  export * from "./src/files/mod.js";
4
5
  export * from "./src/jobs/mod.js";
5
6
  export * from "./src/mail/mod.js";
package/esm/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
package/esm/mod.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import "./_dnt.polyfills.js";
2
2
  export * from "./src/apiKeys/mod.js";
3
+ export * from "./src/clientData/mod.js";
3
4
  export * from "./src/files/mod.js";
4
5
  export * from "./src/jobs/mod.js";
5
6
  export * from "./src/mail/mod.js";
@@ -0,0 +1,89 @@
1
+ export type ClientDataIdentityStatus = "active" | "signed-out" | "unknown";
2
+ /**
3
+ * Storage-neutral identity fence for account-owned browser data.
4
+ *
5
+ * Owner IDs are opaque strings. The consuming app remains responsible for
6
+ * validating their format before calling these helpers.
7
+ */
8
+ export interface ClientDataIdentityState<TOwnerId extends string = string> {
9
+ /** Last verified owner, retained while signed out so stored rows stay attributable. */
10
+ readonly lastOwnerId: TOwnerId | null;
11
+ /** Whether the last durable identity decision activated or fenced the owner. */
12
+ readonly status: ClientDataIdentityStatus;
13
+ /** Monotonic ordering for identity writes and cross-context notifications. */
14
+ readonly revision: number;
15
+ /** Revision of the newest sign-out explicitly requested by the user. */
16
+ readonly explicitSignOutRevision: number;
17
+ }
18
+ export type ClientDataIdentitySignal<TOwnerId extends string = string> = {
19
+ readonly type: "owner-active";
20
+ readonly ownerId: TOwnerId;
21
+ readonly revision: number;
22
+ } | {
23
+ readonly type: "signed-out";
24
+ readonly explicit: boolean;
25
+ /** An immediate pre-persistence sign-out fence intentionally has no revision. */
26
+ readonly revision?: number;
27
+ };
28
+ export interface ClientDataIdentitySignalDecision {
29
+ readonly accepted: boolean;
30
+ readonly appliedRevision: number;
31
+ }
32
+ export type ClientDataSignOutTransition<TOwnerId extends string = string> = {
33
+ readonly outcome: "applied";
34
+ readonly revision: number;
35
+ readonly signal: Extract<ClientDataIdentitySignal<TOwnerId>, {
36
+ type: "signed-out";
37
+ }>;
38
+ readonly state: ClientDataIdentityState<TOwnerId>;
39
+ } | {
40
+ readonly outcome: "stale" | "unchanged";
41
+ readonly state: ClientDataIdentityState<TOwnerId>;
42
+ };
43
+ export type ClientDataActivationTransition<TOwnerId extends string = string> = {
44
+ readonly outcome: "applied";
45
+ readonly revision: number;
46
+ readonly signal: Extract<ClientDataIdentitySignal<TOwnerId>, {
47
+ type: "owner-active";
48
+ }>;
49
+ readonly state: ClientDataIdentityState<TOwnerId>;
50
+ } | {
51
+ readonly outcome: "blocked";
52
+ readonly state: ClientDataIdentityState<TOwnerId>;
53
+ };
54
+ /** Creates the durable state used before this device has verified an owner. */
55
+ export declare function createClientDataIdentityState<TOwnerId extends string = string>(): ClientDataIdentityState<TOwnerId>;
56
+ /** Returns the owner that may be reopened offline, or null while fenced. */
57
+ export declare function activeClientDataOwner<TOwnerId extends string>(state: ClientDataIdentityState<TOwnerId>): TOwnerId | null;
58
+ /**
59
+ * Applies a signed-out identity answer to a state read in the same transaction.
60
+ *
61
+ * Pass `expectedRevision` from before an asynchronous session check. A newer
62
+ * identity write then makes that delayed answer stale instead of allowing it to
63
+ * fence the newly activated owner.
64
+ */
65
+ export declare function transitionClientDataSignOut<TOwnerId extends string>(state: ClientDataIdentityState<TOwnerId>, options?: {
66
+ readonly expectedRevision?: number;
67
+ readonly explicit?: boolean;
68
+ }): ClientDataSignOutTransition<TOwnerId>;
69
+ /**
70
+ * Activates a freshly verified owner and advances the durable identity revision.
71
+ *
72
+ * `baselineRevision` only fences an explicit sign-out that happened after the
73
+ * caller began verification. It does not order competing owner verifications.
74
+ * Within one runtime, callers must abort or generation-check asynchronous
75
+ * session requests. Across tabs or workers, the persistence adapter must also
76
+ * compare the durable revision with the request's original revision, or apply
77
+ * equivalent durable ordering, before calling this transition. Otherwise an
78
+ * older owner-A response can overtake a newer owner-B activation.
79
+ */
80
+ export declare function transitionClientDataActivation<TOwnerId extends string>(state: ClientDataIdentityState<TOwnerId>, ownerId: TOwnerId, options?: {
81
+ readonly baselineRevision?: number;
82
+ }): ClientDataActivationTransition<TOwnerId>;
83
+ /**
84
+ * Orders a validated cross-context identity signal against the newest applied
85
+ * durable revision. An unrevisioned sign-out is an immediate fence and always
86
+ * applies; the storage adapter must later reconcile it with durable state.
87
+ */
88
+ export declare function acceptClientDataIdentitySignal<TOwnerId extends string>(appliedRevision: number, signal: ClientDataIdentitySignal<TOwnerId>): ClientDataIdentitySignalDecision;
89
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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QAAQ,CAAC,CA6BvC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,SAAS,MAAM,EACpE,KAAK,EAAE,uBAAuB,CAAC,QAAQ,CAAC,EACxC,OAAO,EAAE,QAAQ,EACjB,OAAO,GAAE;IAAE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAO,GACnD,8BAA8B,CAAC,QAAQ,CAAC,CAyB1C;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,SAAS,MAAM,EACpE,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,wBAAwB,CAAC,QAAQ,CAAC,GACzC,gCAAgC,CASlC"}
@@ -0,0 +1,127 @@
1
+ function assertRevision(value, label) {
2
+ if (!Number.isSafeInteger(value) || value < 0) {
3
+ throw new TypeError(`${label} must be a non-negative safe integer.`);
4
+ }
5
+ }
6
+ function assertState(state) {
7
+ assertRevision(state.revision, "Identity revision");
8
+ assertRevision(state.explicitSignOutRevision, "Explicit sign-out revision");
9
+ if (state.explicitSignOutRevision > state.revision) {
10
+ throw new TypeError("Explicit sign-out revision cannot exceed the identity revision.");
11
+ }
12
+ if (state.status !== "active" &&
13
+ state.status !== "signed-out" &&
14
+ state.status !== "unknown") {
15
+ throw new TypeError("Identity status is invalid.");
16
+ }
17
+ if ((state.lastOwnerId !== null && typeof state.lastOwnerId !== "string") ||
18
+ (state.status === "active" && state.lastOwnerId === null)) {
19
+ throw new TypeError("Active client data must have a string owner ID.");
20
+ }
21
+ }
22
+ function nextRevision(revision) {
23
+ if (revision === Number.MAX_SAFE_INTEGER) {
24
+ throw new RangeError("Identity revision is exhausted.");
25
+ }
26
+ return revision + 1;
27
+ }
28
+ /** Creates the durable state used before this device has verified an owner. */
29
+ export function createClientDataIdentityState() {
30
+ return {
31
+ lastOwnerId: null,
32
+ status: "unknown",
33
+ revision: 0,
34
+ explicitSignOutRevision: 0,
35
+ };
36
+ }
37
+ /** Returns the owner that may be reopened offline, or null while fenced. */
38
+ export function activeClientDataOwner(state) {
39
+ assertState(state);
40
+ return state.status === "active" ? state.lastOwnerId : null;
41
+ }
42
+ /**
43
+ * Applies a signed-out identity answer to a state read in the same transaction.
44
+ *
45
+ * Pass `expectedRevision` from before an asynchronous session check. A newer
46
+ * identity write then makes that delayed answer stale instead of allowing it to
47
+ * fence the newly activated owner.
48
+ */
49
+ export function transitionClientDataSignOut(state, options = {}) {
50
+ assertState(state);
51
+ if (options.expectedRevision !== undefined) {
52
+ assertRevision(options.expectedRevision, "Expected identity revision");
53
+ if (options.expectedRevision !== state.revision) {
54
+ return { outcome: "stale", state };
55
+ }
56
+ }
57
+ const explicit = options.explicit === true;
58
+ if (state.status === "signed-out" && !explicit) {
59
+ return { outcome: "unchanged", state };
60
+ }
61
+ const revision = nextRevision(state.revision);
62
+ const next = {
63
+ ...state,
64
+ status: "signed-out",
65
+ revision,
66
+ explicitSignOutRevision: explicit
67
+ ? revision
68
+ : state.explicitSignOutRevision,
69
+ };
70
+ return {
71
+ outcome: "applied",
72
+ revision,
73
+ signal: { type: "signed-out", explicit, revision },
74
+ state: next,
75
+ };
76
+ }
77
+ /**
78
+ * Activates a freshly verified owner and advances the durable identity revision.
79
+ *
80
+ * `baselineRevision` only fences an explicit sign-out that happened after the
81
+ * caller began verification. It does not order competing owner verifications.
82
+ * Within one runtime, callers must abort or generation-check asynchronous
83
+ * session requests. Across tabs or workers, the persistence adapter must also
84
+ * compare the durable revision with the request's original revision, or apply
85
+ * equivalent durable ordering, before calling this transition. Otherwise an
86
+ * older owner-A response can overtake a newer owner-B activation.
87
+ */
88
+ export function transitionClientDataActivation(state, ownerId, options = {}) {
89
+ assertState(state);
90
+ if (typeof ownerId !== "string") {
91
+ throw new TypeError("Client-data owner ID must be a string.");
92
+ }
93
+ if (options.baselineRevision !== undefined) {
94
+ assertRevision(options.baselineRevision, "Baseline identity revision");
95
+ if (state.explicitSignOutRevision > options.baselineRevision) {
96
+ return { outcome: "blocked", state };
97
+ }
98
+ }
99
+ const revision = nextRevision(state.revision);
100
+ const next = {
101
+ ...state,
102
+ lastOwnerId: ownerId,
103
+ status: "active",
104
+ revision,
105
+ };
106
+ return {
107
+ outcome: "applied",
108
+ revision,
109
+ signal: { type: "owner-active", ownerId, revision },
110
+ state: next,
111
+ };
112
+ }
113
+ /**
114
+ * Orders a validated cross-context identity signal against the newest applied
115
+ * durable revision. An unrevisioned sign-out is an immediate fence and always
116
+ * applies; the storage adapter must later reconcile it with durable state.
117
+ */
118
+ export function acceptClientDataIdentitySignal(appliedRevision, signal) {
119
+ assertRevision(appliedRevision, "Applied identity revision");
120
+ if (signal.revision === undefined) {
121
+ return { accepted: true, appliedRevision };
122
+ }
123
+ assertRevision(signal.revision, "Signal identity revision");
124
+ return signal.revision < appliedRevision
125
+ ? { accepted: false, appliedRevision }
126
+ : { accepted: true, appliedRevision: signal.revision };
127
+ }
@@ -0,0 +1,3 @@
1
+ import "../../_dnt.polyfills.js";
2
+ export * from "./identity.js";
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/clientData/mod.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,cAAc,eAAe,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "./identity.js";
@@ -22,6 +22,13 @@ type PendingSessionState = {
22
22
  *
23
23
  * Server renders never settle, so hydration still starts from the pending
24
24
  * state the server rendered.
25
+ *
26
+ * This works around Better Auth deriving `isPending` from "has no data"
27
+ * (`isPending: current.data === null` in its session atom) rather than from
28
+ * "has had no answer yet". If a Better Auth release separates those, this
29
+ * whole module and its tests can go, and consumers can call the client's
30
+ * `useSession` directly again; the manifest's auth client module is the only
31
+ * other place to check.
25
32
  */
26
33
  export declare function createSettledSessionHook<TState extends PendingSessionState>(useSession: () => TState): () => TState;
27
34
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/src/next/auth/client.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,CAAC;AAGpC;;;;;GAKG;AAEH,KAAK,mBAAmB,GAAG;IACzB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,SAAS,mBAAmB,EACzE,UAAU,EAAE,MAAM,MAAM,GACvB,MAAM,MAAM,CAWd"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/src/next/auth/client.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,CAAC;AAGpC;;;;;GAKG;AAEH,KAAK,mBAAmB,GAAG;IACzB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,SAAS,mBAAmB,EACzE,UAAU,EAAE,MAAM,MAAM,GACvB,MAAM,MAAM,CAWd"}
@@ -13,6 +13,13 @@
13
13
  *
14
14
  * Server renders never settle, so hydration still starts from the pending
15
15
  * state the server rendered.
16
+ *
17
+ * This works around Better Auth deriving `isPending` from "has no data"
18
+ * (`isPending: current.data === null` in its session atom) rather than from
19
+ * "has had no answer yet". If a Better Auth release separates those, this
20
+ * whole module and its tests can go, and consumers can call the client's
21
+ * `useSession` directly again; the manifest's auth client module is the only
22
+ * other place to check.
16
23
  */
17
24
  export function createSettledSessionHook(useSession) {
18
25
  let settled = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gadicc/loom",
3
- "version": "1.29.0",
3
+ "version": "1.30.0",
4
4
  "description": "Deno-first shared helpers for extracting common Next.js app code.",
5
5
  "homepage": "https://github.com/gadicc/loom#readme",
6
6
  "repository": {
@@ -27,6 +27,10 @@
27
27
  "import": "./esm/src/apiKeys/mod.js",
28
28
  "require": "./script/src/apiKeys/mod.js"
29
29
  },
30
+ "./src/clientData/mod.js": {
31
+ "import": "./esm/src/clientData/mod.js",
32
+ "require": "./script/src/clientData/mod.js"
33
+ },
30
34
  "./src/files/mod.js": {
31
35
  "import": "./esm/src/files/mod.js",
32
36
  "require": "./script/src/files/mod.js"
@@ -75,6 +79,11 @@
75
79
  "import": "./esm/src/next/pwa/worker.js",
76
80
  "require": "./script/src/next/pwa/worker.js"
77
81
  },
82
+ "./client-data": {
83
+ "types": "./esm/src/clientData/mod.d.ts",
84
+ "import": "./esm/src/clientData/mod.js",
85
+ "require": "./script/src/clientData/mod.js"
86
+ },
78
87
  "./db/drizzle-config": {
79
88
  "types": "./db/drizzle-config.d.ts",
80
89
  "import": "./db/drizzle-config.js",
@@ -235,7 +244,7 @@
235
244
  },
236
245
  "scripts": {},
237
246
  "loom": {
238
- "gitCommit": "3b37c6ad50a4faaf5ee2e48fa5669dcbdee9b36a"
247
+ "gitCommit": "043c9f47694f82164138ecf0960e367a7aec437d"
239
248
  },
240
249
  "bin": {
241
250
  "loom": "script/bin/loom.js"
@@ -248,6 +257,9 @@
248
257
  "apiKeys": [
249
258
  "esm/src/apiKeys/mod.d.ts"
250
259
  ],
260
+ "client-data": [
261
+ "esm/src/clientData/mod.d.ts"
262
+ ],
251
263
  "files": [
252
264
  "esm/src/files/mod.d.ts"
253
265
  ],
package/script/mod.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import "./_dnt.polyfills.js";
2
2
  export * from "./src/apiKeys/mod.js";
3
+ export * from "./src/clientData/mod.js";
3
4
  export * from "./src/files/mod.js";
4
5
  export * from "./src/jobs/mod.js";
5
6
  export * from "./src/mail/mod.js";
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
package/script/mod.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  require("./_dnt.polyfills.js");
18
18
  __exportStar(require("./src/apiKeys/mod.js"), exports);
19
+ __exportStar(require("./src/clientData/mod.js"), exports);
19
20
  __exportStar(require("./src/files/mod.js"), exports);
20
21
  __exportStar(require("./src/jobs/mod.js"), exports);
21
22
  __exportStar(require("./src/mail/mod.js"), exports);
@@ -0,0 +1,89 @@
1
+ export type ClientDataIdentityStatus = "active" | "signed-out" | "unknown";
2
+ /**
3
+ * Storage-neutral identity fence for account-owned browser data.
4
+ *
5
+ * Owner IDs are opaque strings. The consuming app remains responsible for
6
+ * validating their format before calling these helpers.
7
+ */
8
+ export interface ClientDataIdentityState<TOwnerId extends string = string> {
9
+ /** Last verified owner, retained while signed out so stored rows stay attributable. */
10
+ readonly lastOwnerId: TOwnerId | null;
11
+ /** Whether the last durable identity decision activated or fenced the owner. */
12
+ readonly status: ClientDataIdentityStatus;
13
+ /** Monotonic ordering for identity writes and cross-context notifications. */
14
+ readonly revision: number;
15
+ /** Revision of the newest sign-out explicitly requested by the user. */
16
+ readonly explicitSignOutRevision: number;
17
+ }
18
+ export type ClientDataIdentitySignal<TOwnerId extends string = string> = {
19
+ readonly type: "owner-active";
20
+ readonly ownerId: TOwnerId;
21
+ readonly revision: number;
22
+ } | {
23
+ readonly type: "signed-out";
24
+ readonly explicit: boolean;
25
+ /** An immediate pre-persistence sign-out fence intentionally has no revision. */
26
+ readonly revision?: number;
27
+ };
28
+ export interface ClientDataIdentitySignalDecision {
29
+ readonly accepted: boolean;
30
+ readonly appliedRevision: number;
31
+ }
32
+ export type ClientDataSignOutTransition<TOwnerId extends string = string> = {
33
+ readonly outcome: "applied";
34
+ readonly revision: number;
35
+ readonly signal: Extract<ClientDataIdentitySignal<TOwnerId>, {
36
+ type: "signed-out";
37
+ }>;
38
+ readonly state: ClientDataIdentityState<TOwnerId>;
39
+ } | {
40
+ readonly outcome: "stale" | "unchanged";
41
+ readonly state: ClientDataIdentityState<TOwnerId>;
42
+ };
43
+ export type ClientDataActivationTransition<TOwnerId extends string = string> = {
44
+ readonly outcome: "applied";
45
+ readonly revision: number;
46
+ readonly signal: Extract<ClientDataIdentitySignal<TOwnerId>, {
47
+ type: "owner-active";
48
+ }>;
49
+ readonly state: ClientDataIdentityState<TOwnerId>;
50
+ } | {
51
+ readonly outcome: "blocked";
52
+ readonly state: ClientDataIdentityState<TOwnerId>;
53
+ };
54
+ /** Creates the durable state used before this device has verified an owner. */
55
+ export declare function createClientDataIdentityState<TOwnerId extends string = string>(): ClientDataIdentityState<TOwnerId>;
56
+ /** Returns the owner that may be reopened offline, or null while fenced. */
57
+ export declare function activeClientDataOwner<TOwnerId extends string>(state: ClientDataIdentityState<TOwnerId>): TOwnerId | null;
58
+ /**
59
+ * Applies a signed-out identity answer to a state read in the same transaction.
60
+ *
61
+ * Pass `expectedRevision` from before an asynchronous session check. A newer
62
+ * identity write then makes that delayed answer stale instead of allowing it to
63
+ * fence the newly activated owner.
64
+ */
65
+ export declare function transitionClientDataSignOut<TOwnerId extends string>(state: ClientDataIdentityState<TOwnerId>, options?: {
66
+ readonly expectedRevision?: number;
67
+ readonly explicit?: boolean;
68
+ }): ClientDataSignOutTransition<TOwnerId>;
69
+ /**
70
+ * Activates a freshly verified owner and advances the durable identity revision.
71
+ *
72
+ * `baselineRevision` only fences an explicit sign-out that happened after the
73
+ * caller began verification. It does not order competing owner verifications.
74
+ * Within one runtime, callers must abort or generation-check asynchronous
75
+ * session requests. Across tabs or workers, the persistence adapter must also
76
+ * compare the durable revision with the request's original revision, or apply
77
+ * equivalent durable ordering, before calling this transition. Otherwise an
78
+ * older owner-A response can overtake a newer owner-B activation.
79
+ */
80
+ export declare function transitionClientDataActivation<TOwnerId extends string>(state: ClientDataIdentityState<TOwnerId>, ownerId: TOwnerId, options?: {
81
+ readonly baselineRevision?: number;
82
+ }): ClientDataActivationTransition<TOwnerId>;
83
+ /**
84
+ * Orders a validated cross-context identity signal against the newest applied
85
+ * durable revision. An unrevisioned sign-out is an immediate fence and always
86
+ * applies; the storage adapter must later reconcile it with durable state.
87
+ */
88
+ export declare function acceptClientDataIdentitySignal<TOwnerId extends string>(appliedRevision: number, signal: ClientDataIdentitySignal<TOwnerId>): ClientDataIdentitySignalDecision;
89
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../src/src/clientData/identity.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,wBAAwB,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC;AAE3E;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM;IACvE,uFAAuF;IACvF,QAAQ,CAAC,WAAW,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtC,gFAAgF;IAChF,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAC1C,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,wEAAwE;IACxE,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CA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ict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createClientDataIdentityState = createClientDataIdentityState;
4
+ exports.activeClientDataOwner = activeClientDataOwner;
5
+ exports.transitionClientDataSignOut = transitionClientDataSignOut;
6
+ exports.transitionClientDataActivation = transitionClientDataActivation;
7
+ exports.acceptClientDataIdentitySignal = acceptClientDataIdentitySignal;
8
+ function assertRevision(value, label) {
9
+ if (!Number.isSafeInteger(value) || value < 0) {
10
+ throw new TypeError(`${label} must be a non-negative safe integer.`);
11
+ }
12
+ }
13
+ function assertState(state) {
14
+ assertRevision(state.revision, "Identity revision");
15
+ assertRevision(state.explicitSignOutRevision, "Explicit sign-out revision");
16
+ if (state.explicitSignOutRevision > state.revision) {
17
+ throw new TypeError("Explicit sign-out revision cannot exceed the identity revision.");
18
+ }
19
+ if (state.status !== "active" &&
20
+ state.status !== "signed-out" &&
21
+ state.status !== "unknown") {
22
+ throw new TypeError("Identity status is invalid.");
23
+ }
24
+ if ((state.lastOwnerId !== null && typeof state.lastOwnerId !== "string") ||
25
+ (state.status === "active" && state.lastOwnerId === null)) {
26
+ throw new TypeError("Active client data must have a string owner ID.");
27
+ }
28
+ }
29
+ function nextRevision(revision) {
30
+ if (revision === Number.MAX_SAFE_INTEGER) {
31
+ throw new RangeError("Identity revision is exhausted.");
32
+ }
33
+ return revision + 1;
34
+ }
35
+ /** Creates the durable state used before this device has verified an owner. */
36
+ function createClientDataIdentityState() {
37
+ return {
38
+ lastOwnerId: null,
39
+ status: "unknown",
40
+ revision: 0,
41
+ explicitSignOutRevision: 0,
42
+ };
43
+ }
44
+ /** Returns the owner that may be reopened offline, or null while fenced. */
45
+ function activeClientDataOwner(state) {
46
+ assertState(state);
47
+ return state.status === "active" ? state.lastOwnerId : null;
48
+ }
49
+ /**
50
+ * Applies a signed-out identity answer to a state read in the same transaction.
51
+ *
52
+ * Pass `expectedRevision` from before an asynchronous session check. A newer
53
+ * identity write then makes that delayed answer stale instead of allowing it to
54
+ * fence the newly activated owner.
55
+ */
56
+ function transitionClientDataSignOut(state, options = {}) {
57
+ assertState(state);
58
+ if (options.expectedRevision !== undefined) {
59
+ assertRevision(options.expectedRevision, "Expected identity revision");
60
+ if (options.expectedRevision !== state.revision) {
61
+ return { outcome: "stale", state };
62
+ }
63
+ }
64
+ const explicit = options.explicit === true;
65
+ if (state.status === "signed-out" && !explicit) {
66
+ return { outcome: "unchanged", state };
67
+ }
68
+ const revision = nextRevision(state.revision);
69
+ const next = {
70
+ ...state,
71
+ status: "signed-out",
72
+ revision,
73
+ explicitSignOutRevision: explicit
74
+ ? revision
75
+ : state.explicitSignOutRevision,
76
+ };
77
+ return {
78
+ outcome: "applied",
79
+ revision,
80
+ signal: { type: "signed-out", explicit, revision },
81
+ state: next,
82
+ };
83
+ }
84
+ /**
85
+ * Activates a freshly verified owner and advances the durable identity revision.
86
+ *
87
+ * `baselineRevision` only fences an explicit sign-out that happened after the
88
+ * caller began verification. It does not order competing owner verifications.
89
+ * Within one runtime, callers must abort or generation-check asynchronous
90
+ * session requests. Across tabs or workers, the persistence adapter must also
91
+ * compare the durable revision with the request's original revision, or apply
92
+ * equivalent durable ordering, before calling this transition. Otherwise an
93
+ * older owner-A response can overtake a newer owner-B activation.
94
+ */
95
+ function transitionClientDataActivation(state, ownerId, options = {}) {
96
+ assertState(state);
97
+ if (typeof ownerId !== "string") {
98
+ throw new TypeError("Client-data owner ID must be a string.");
99
+ }
100
+ if (options.baselineRevision !== undefined) {
101
+ assertRevision(options.baselineRevision, "Baseline identity revision");
102
+ if (state.explicitSignOutRevision > options.baselineRevision) {
103
+ return { outcome: "blocked", state };
104
+ }
105
+ }
106
+ const revision = nextRevision(state.revision);
107
+ const next = {
108
+ ...state,
109
+ lastOwnerId: ownerId,
110
+ status: "active",
111
+ revision,
112
+ };
113
+ return {
114
+ outcome: "applied",
115
+ revision,
116
+ signal: { type: "owner-active", ownerId, revision },
117
+ state: next,
118
+ };
119
+ }
120
+ /**
121
+ * Orders a validated cross-context identity signal against the newest applied
122
+ * durable revision. An unrevisioned sign-out is an immediate fence and always
123
+ * applies; the storage adapter must later reconcile it with durable state.
124
+ */
125
+ function acceptClientDataIdentitySignal(appliedRevision, signal) {
126
+ assertRevision(appliedRevision, "Applied identity revision");
127
+ if (signal.revision === undefined) {
128
+ return { accepted: true, appliedRevision };
129
+ }
130
+ assertRevision(signal.revision, "Signal identity revision");
131
+ return signal.revision < appliedRevision
132
+ ? { accepted: false, appliedRevision }
133
+ : { accepted: true, appliedRevision: signal.revision };
134
+ }
@@ -0,0 +1,3 @@
1
+ import "../../_dnt.polyfills.js";
2
+ export * from "./identity.js";
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/clientData/mod.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ require("../../_dnt.polyfills.js");
18
+ __exportStar(require("./identity.js"), exports);
@@ -22,6 +22,13 @@ type PendingSessionState = {
22
22
  *
23
23
  * Server renders never settle, so hydration still starts from the pending
24
24
  * state the server rendered.
25
+ *
26
+ * This works around Better Auth deriving `isPending` from "has no data"
27
+ * (`isPending: current.data === null` in its session atom) rather than from
28
+ * "has had no answer yet". If a Better Auth release separates those, this
29
+ * whole module and its tests can go, and consumers can call the client's
30
+ * `useSession` directly again; the manifest's auth client module is the only
31
+ * other place to check.
25
32
  */
26
33
  export declare function createSettledSessionHook<TState extends PendingSessionState>(useSession: () => TState): () => TState;
27
34
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/src/next/auth/client.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,CAAC;AAGpC;;;;;GAKG;AAEH,KAAK,mBAAmB,GAAG;IACzB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,SAAS,mBAAmB,EACzE,UAAU,EAAE,MAAM,MAAM,GACvB,MAAM,MAAM,CAWd"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/src/next/auth/client.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,CAAC;AAGpC;;;;;GAKG;AAEH,KAAK,mBAAmB,GAAG;IACzB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,SAAS,mBAAmB,EACzE,UAAU,EAAE,MAAM,MAAM,GACvB,MAAM,MAAM,CAWd"}
@@ -17,6 +17,13 @@ require("../../../_dnt.polyfills.js");
17
17
  *
18
18
  * Server renders never settle, so hydration still starts from the pending
19
19
  * state the server rendered.
20
+ *
21
+ * This works around Better Auth deriving `isPending` from "has no data"
22
+ * (`isPending: current.data === null` in its session atom) rather than from
23
+ * "has had no answer yet". If a Better Auth release separates those, this
24
+ * whole module and its tests can go, and consumers can call the client's
25
+ * `useSession` directly again; the manifest's auth client module is the only
26
+ * other place to check.
20
27
  */
21
28
  function createSettledSessionHook(useSession) {
22
29
  let settled = false;
@@ -53,6 +53,12 @@ first. Prepare SQL schemas and pure import planners locally, then exercise
53
53
  protected real input without publishing private fixtures. Build browser recovery
54
54
  before retiring any legacy store or protocol it depends on.
55
55
 
56
+ A migrated app usually ends up with auth wiring that differs from a greenfield
57
+ shape: a factory kept free of environment reads, a guarded catch-all route, or
58
+ app-owned session readers. Record those paths in `loom.json` and adopt the
59
+ feature around them. Reshaping working authentication to match a default layout
60
+ buys nothing and risks a live boundary.
61
+
56
62
  Choose authentication and persistence release boundaries from actual ID/session
57
63
  dependencies. A verified NextAuth-to-Gongo bridge can allow staged replacement;
58
64
  it is an option, not a mandatory intermediate destination. A database adapter is