@directive-run/core 0.8.5 → 0.8.7

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 (54) hide show
  1. package/README.md +13 -0
  2. package/dist/adapter-utils.cjs +1 -1
  3. package/dist/adapter-utils.cjs.map +1 -1
  4. package/dist/adapter-utils.d.cts +14 -2
  5. package/dist/adapter-utils.d.ts +14 -2
  6. package/dist/adapter-utils.js +1 -1
  7. package/dist/adapter-utils.js.map +1 -1
  8. package/dist/chunk-4CMO5OVZ.js +3 -0
  9. package/dist/chunk-4CMO5OVZ.js.map +1 -0
  10. package/dist/chunk-BEJ6ICA7.cjs +3 -0
  11. package/dist/chunk-BEJ6ICA7.cjs.map +1 -0
  12. package/dist/chunk-FVPJU5F3.js +3 -0
  13. package/dist/chunk-FVPJU5F3.js.map +1 -0
  14. package/dist/{chunk-MAARYRI4.js → chunk-KXIHB2EB.js} +3 -3
  15. package/dist/{chunk-MAARYRI4.js.map → chunk-KXIHB2EB.js.map} +1 -1
  16. package/dist/chunk-SGMWAVHO.cjs +3 -0
  17. package/dist/chunk-SGMWAVHO.cjs.map +1 -0
  18. package/dist/{chunk-LAH2FMON.cjs → chunk-W4VP6SVP.cjs} +3 -3
  19. package/dist/{chunk-LAH2FMON.cjs.map → chunk-W4VP6SVP.cjs.map} +1 -1
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.d.cts +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.js +1 -1
  24. package/dist/internals.cjs +1 -1
  25. package/dist/internals.d.cts +23 -2
  26. package/dist/internals.d.ts +23 -2
  27. package/dist/internals.js +1 -1
  28. package/dist/plugins/index.cjs +2 -2
  29. package/dist/plugins/index.cjs.map +1 -1
  30. package/dist/plugins/index.d.cts +71 -3
  31. package/dist/plugins/index.d.ts +71 -3
  32. package/dist/plugins/index.js +2 -2
  33. package/dist/plugins/index.js.map +1 -1
  34. package/dist/system-HQCNSUY5.cjs +2 -0
  35. package/dist/{system-L45Z2N4U.cjs.map → system-HQCNSUY5.cjs.map} +1 -1
  36. package/dist/system-QNIJLXKW.js +2 -0
  37. package/dist/{system-L2FVVUSN.js.map → system-QNIJLXKW.js.map} +1 -1
  38. package/dist/testing.cjs +1 -1
  39. package/dist/testing.js +1 -1
  40. package/dist/{utils-4JrY5fk9.d.cts → utils-BnQajqPu.d.cts} +9 -1
  41. package/dist/{utils-4JrY5fk9.d.ts → utils-BnQajqPu.d.ts} +9 -1
  42. package/dist/worker.cjs +1 -1
  43. package/dist/worker.js +1 -1
  44. package/package.json +2 -2
  45. package/dist/chunk-6WG7FPH7.cjs +0 -3
  46. package/dist/chunk-6WG7FPH7.cjs.map +0 -1
  47. package/dist/chunk-DIK3SZBM.js +0 -3
  48. package/dist/chunk-DIK3SZBM.js.map +0 -1
  49. package/dist/chunk-GO63IIN5.js +0 -2
  50. package/dist/chunk-GO63IIN5.js.map +0 -1
  51. package/dist/chunk-KQKNE23L.cjs +0 -2
  52. package/dist/chunk-KQKNE23L.cjs.map +0 -1
  53. package/dist/system-L2FVVUSN.js +0 -2
  54. package/dist/system-L45Z2N4U.cjs +0 -2
package/README.md CHANGED
@@ -191,6 +191,18 @@ system.events.addItem({ name: "Widget", price: 9.99 });
191
191
  - **Constraint-driven over event-driven** – instead of chaining events to coordinate async work, declare constraints that the runtime satisfies automatically with retry, batching, and error boundaries.
192
192
  - **Framework-agnostic core** – one state layer, five framework adapters. Move between React, Vue, Svelte, Solid, and Lit without rewriting your state logic.
193
193
 
194
+ ## Related Blog Posts
195
+
196
+ - [Introducing Directive](https://directive.run/blog/introducing-directive) – the vision behind constraint-driven state management
197
+ - [Constraint-Driven Architecture](https://directive.run/blog/constraint-driven-architecture) – why declaring "what must be true" beats imperative transitions
198
+ - [Inside Directive's Reconciliation Loop](https://directive.run/blog/inside-the-reconciliation-loop) – deep-dive into the five-phase reconciliation cycle
199
+ - [From Redux to Directive in 10 Minutes](https://directive.run/blog/from-redux-to-directive) – practical migration guide with real auth examples
200
+ - [Why State Machines Aren't Enough](https://directive.run/blog/why-state-machines-arent-enough) – when to use state machines vs. constraint-driven systems
201
+ - [Your Zustand Store Is Secretly an Imperative State Machine](https://directive.run/blog/zustand-imperative-state-machine) – spotting the inflection point where Zustand stops scaling
202
+ - [Stop Writing If-Else Chains for Business Logic](https://directive.run/blog/stop-writing-if-else-chains) – replacing conditional spaghetti with declarative constraints
203
+ - [Feature Flags Without a Feature Flag Service](https://directive.run/blog/feature-flags-without-a-service) – reactive feature flags with constraints and derivations
204
+ - [Directive on the Server](https://directive.run/blog/directive-on-the-server) – snapshots, signed verification, and audit trails on Node.js
205
+
194
206
  ## Documentation
195
207
 
196
208
  - [Getting Started](https://directive.run/docs/getting-started)
@@ -200,3 +212,4 @@ system.events.addItem({ name: "Widget", price: 9.99 });
200
212
  ## License
201
213
 
202
214
  MIT
215
+
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkPK2EH26L_cjs=require('./chunk-PK2EH26L.cjs'),chunkKQKNE23L_cjs=require('./chunk-KQKNE23L.cjs');function k(n){let t=n.inspect();return {isSettled:n.isSettled,unmet:t.unmet,inflight:t.inflight,isWorking:t.unmet.length>0||t.inflight.length>0,hasUnmet:t.unmet.length>0,hasInflight:t.inflight.length>0}}function b(n,t){let r=null,e=null,s=0;return {throttled:((...i)=>{let o=Date.now(),u=o-s;u>=t?(s=o,n(...i)):(e=i,r||(r=setTimeout(()=>{r=null,s=Date.now(),e&&(n(...e),e=null);},t-u)));}),cleanup:()=>{r&&(clearTimeout(r),r=null),e=null;}}}function S(n,t){if(process.env.NODE_ENV!=="production"&&t==null)throw new Error(`[Directive] ${n}() requires a system instance as the first argument. Received ${t}.`)}function w(n,t){return Object.is(n,t)}function x(n){let t=n.history;if(!t)return null;let r=t.snapshots.map(e=>({id:e.id,timestamp:e.timestamp,trigger:e.trigger}));return {canGoBack:t.currentIndex>0,canGoForward:t.currentIndex<t.snapshots.length-1,currentIndex:t.currentIndex,totalSnapshots:t.snapshots.length,snapshots:r,getSnapshotFacts:e=>{let s=t.snapshots.find(a=>a.id===e);return s?s.facts:null},goTo:e=>t.goTo(e),goBack:e=>t.goBack(e),goForward:e=>t.goForward(e),replay:()=>t.replay(),exportSession:()=>t.export(),importSession:e=>t.import(e),beginChangeset:e=>t.beginChangeset(e),endChangeset:()=>t.endChangeset(),isPaused:t.isPaused,pause:()=>t.pause(),resume:()=>t.resume()}}function T(n,t){let r={};for(let e of t)r[e]=n.facts.$store.get(e);return r}function R(n,t,r){let e=[],s=new Proxy({},{get(i,o){if(typeof o=="string")return t.has(o)?(e.push(o),n.read(o)):n.facts.$store.get(o)},has(i,o){return typeof o!="string"?false:t.has(o)||n.facts.$store.has(o)},ownKeys(){let i=Object.keys(n.facts.$store.toObject()),o=new Set(i);for(let u of t)o.add(u);return [...o]},getOwnPropertyDescriptor(){return {configurable:true,enumerable:true,writable:true}}}),{value:a,deps:l}=chunkPK2EH26L_cjs.h(()=>r(s));return {value:a,factKeys:Array.from(l),deriveKeys:e}}function I(n,t,r,e){let s=t.length!==n.length||t.some((l,i)=>l!==n[i]),a=e.length!==r.length||e.some((l,i)=>l!==r[i]);return s||a}Object.defineProperty(exports,"createCallbackPlugin",{enumerable:true,get:function(){return chunkPK2EH26L_cjs.c}});Object.defineProperty(exports,"getBridgeFact",{enumerable:true,get:function(){return chunkPK2EH26L_cjs.b}});Object.defineProperty(exports,"requirementGuard",{enumerable:true,get:function(){return chunkPK2EH26L_cjs.d}});Object.defineProperty(exports,"requirementGuardMultiple",{enumerable:true,get:function(){return chunkPK2EH26L_cjs.e}});Object.defineProperty(exports,"setBridgeFact",{enumerable:true,get:function(){return chunkPK2EH26L_cjs.a}});Object.defineProperty(exports,"shallowEqual",{enumerable:true,get:function(){return chunkKQKNE23L_cjs.d}});exports.assertSystem=S;exports.buildHistoryState=x;exports.computeInspectState=k;exports.createThrottle=b;exports.defaultEquality=w;exports.depsChanged=I;exports.pickFacts=T;exports.runTrackedSelector=R;//# sourceMappingURL=adapter-utils.cjs.map
1
+ 'use strict';var chunkPK2EH26L_cjs=require('./chunk-PK2EH26L.cjs'),chunkBEJ6ICA7_cjs=require('./chunk-BEJ6ICA7.cjs');function k(n){let e=n.inspect();return {isSettled:n.isSettled,unmet:e.unmet,inflight:e.inflight,isWorking:e.unmet.length>0||e.inflight.length>0,hasUnmet:e.unmet.length>0,hasInflight:e.inflight.length>0}}function b(n,e){let r=null,t=null,s=0;return {throttled:((...i)=>{let o=Date.now(),l=o-s;l>=e?(s=o,n(...i)):(t=i,r||(r=setTimeout(()=>{r=null,s=Date.now(),t&&(n(...t),t=null);},e-l)));}),cleanup:()=>{r&&(clearTimeout(r),r=null),t=null;}}}function w(n,e){if(process.env.NODE_ENV!=="production"&&e==null)throw new Error(`[Directive] ${n}() requires a system instance as the first argument. Received ${e}.`)}function S(n,e){return Object.is(n,e)}function x(n){let e=n.history;if(!e)return null;let r=e.snapshots.map(t=>({id:t.id,timestamp:t.timestamp,trigger:t.trigger}));return {canGoBack:e.currentIndex>0,canGoForward:e.currentIndex<e.snapshots.length-1,currentIndex:e.currentIndex,totalSnapshots:e.snapshots.length,snapshots:r,getSnapshotFacts:t=>{let s=e.snapshots.find(a=>a.id===t);return s?s.facts:null},goTo:t=>e.goTo(t),goBack:t=>e.goBack(t),goForward:t=>e.goForward(t),replay:()=>e.replay(),exportSession:()=>e.export(),importSession:t=>e.import(t),beginChangeset:t=>e.beginChangeset(t),endChangeset:()=>e.endChangeset(),isPaused:e.isPaused,pause:()=>e.pause(),resume:()=>e.resume()}}function R(n,e){let r={};for(let t of e)r[t]=n.facts.$store.get(t);return r}function T(n,e,r){let t=[],s=new Proxy({},{get(i,o){if(typeof o=="string")return e.has(o)?(t.push(o),n.read(o)):n.facts.$store.get(o)},has(i,o){return typeof o!="string"?false:e.has(o)||n.facts.$store.has(o)},ownKeys(){let i=Object.keys(n.facts.$store.toObject()),o=new Set(i);for(let l of e)o.add(l);return [...o]},getOwnPropertyDescriptor(){return {configurable:true,enumerable:true,writable:true}}}),{value:a,deps:u}=chunkPK2EH26L_cjs.h(()=>r(s));return {value:a,factKeys:Array.from(u),deriveKeys:t}}function I(n,e,r,t){let s=e.length!==n.length||e.some((u,i)=>u!==n[i]),a=t.length!==r.length||t.some((u,i)=>u!==r[i]);return s||a}function C(n,e){if(!n)return {...e};let r="data"in n&&typeof n.data=="object"&&n.data!==null?n.data:n;return {...e,...r}}Object.defineProperty(exports,"createCallbackPlugin",{enumerable:true,get:function(){return chunkPK2EH26L_cjs.c}});Object.defineProperty(exports,"getBridgeFact",{enumerable:true,get:function(){return chunkPK2EH26L_cjs.b}});Object.defineProperty(exports,"requirementGuard",{enumerable:true,get:function(){return chunkPK2EH26L_cjs.d}});Object.defineProperty(exports,"requirementGuardMultiple",{enumerable:true,get:function(){return chunkPK2EH26L_cjs.e}});Object.defineProperty(exports,"setBridgeFact",{enumerable:true,get:function(){return chunkPK2EH26L_cjs.a}});Object.defineProperty(exports,"shallowEqual",{enumerable:true,get:function(){return chunkBEJ6ICA7_cjs.d}});exports.assertSystem=w;exports.buildHistoryState=x;exports.computeInspectState=k;exports.createThrottle=b;exports.defaultEquality=S;exports.depsChanged=I;exports.mergeHydrationFacts=C;exports.pickFacts=R;exports.runTrackedSelector=T;//# sourceMappingURL=adapter-utils.cjs.map
2
2
  //# sourceMappingURL=adapter-utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/adapter-utils.ts"],"names":["computeInspectState","system","inspection","createThrottle","callback","ms","timeoutId","lastArgs","lastCallTime","args","now","timeSinceLastCall","assertSystem","hookName","defaultEquality","a","b","buildHistoryState","debug","snapshots","s","id","snap","snapshotId","steps","json","label","pickFacts","keys","result","key","runTrackedSelector","deriveKeySet","selector","accessedDeriveKeys","stateProxy","_","prop","factKeys","combined","k","value","deps","withTracking","depsChanged","prevFacts","newFacts","prevDerived","newDerived","factsChanged","derivedChanged"],"mappings":"qHAsGO,SAASA,CAAAA,CAAoBC,CAAAA,CAAkC,CACpE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,CACJF,CAAAA,CAAW,MAAA,GAAWD,CAAAA,CAAY,QAClCC,CAAAA,CAAW,IAAA,CAAK,CAACR,CAAAA,CAAG,CAAA,GAAMA,CAAAA,GAAMO,CAAAA,CAAY,CAAC,CAAC,CAAA,CAChD,OAAOE,CAAAA,EAAgBC,CACzB","file":"adapter-utils.cjs","sourcesContent":["/**\n * Shared Adapter Utilities\n *\n * Common types and helper functions used across all framework adapters.\n * @internal\n */\n\nimport { withTracking } from \"./core/tracking.js\";\nimport type {\n HistoryAPI,\n HistoryState,\n SnapshotMeta,\n SystemInspection,\n} from \"./core/types.js\";\n\n// ============================================================================\n// SystemLike — structural type satisfied by both System and SingleModuleSystem\n// ============================================================================\n\n/**\n * Minimal structural type for shared adapter helpers.\n * Both `System<any>` and `SingleModuleSystem<any>` satisfy this interface,\n * eliminating the need for `as unknown as System<any>` casts in adapters.\n * @internal\n */\nexport interface SystemLike {\n readonly isSettled: boolean;\n readonly history: HistoryAPI | null;\n readonly facts: {\n $store: {\n get(key: string): unknown;\n has(key: string): boolean;\n toObject(): Record<string, unknown>;\n };\n };\n readonly derive?: Record<string, unknown>;\n read(key: string): unknown;\n inspect(): SystemInspection;\n}\n\n// ============================================================================\n// Requirements State\n// ============================================================================\n\n/**\n * Requirements state returned by useRequirements hooks.\n * Provides a focused view of just requirements without full inspection overhead.\n */\nexport interface RequirementsState {\n /** Array of unmet requirements waiting to be resolved */\n unmet: Array<{\n id: string;\n requirement: { type: string; [key: string]: unknown };\n fromConstraint: string;\n }>;\n /** Array of requirements currently being resolved */\n inflight: Array<{ id: string; resolverId: string; startedAt: number }>;\n /** Whether there are any unmet requirements */\n hasUnmet: boolean;\n /** Whether there are any inflight requirements */\n hasInflight: boolean;\n /** Whether the system is actively working (has unmet or inflight requirements) */\n isWorking: boolean;\n}\n\n// ============================================================================\n// Inspect State (shared across all adapters)\n// ============================================================================\n\n/**\n * Consolidated inspection state returned by useInspect hooks.\n * Identical shape across React, Vue, Svelte, Solid, and Lit adapters.\n */\nexport interface InspectState {\n /** Whether the system has settled (no pending operations) */\n isSettled: boolean;\n /** Array of unmet requirements */\n unmet: RequirementsState[\"unmet\"];\n /** Array of inflight requirements */\n inflight: RequirementsState[\"inflight\"];\n /** Whether the system is actively working */\n isWorking: boolean;\n /** Whether there are any unmet requirements */\n hasUnmet: boolean;\n /** Whether there are any inflight requirements */\n hasInflight: boolean;\n}\n\n/**\n * Information about a single constraint.\n */\nexport interface ConstraintInfo {\n id: string;\n active: boolean;\n priority: number;\n}\n\n/**\n * Compute InspectState from a system instance.\n * Centralizes the logic currently duplicated across adapters.\n * @internal\n */\nexport function computeInspectState(system: SystemLike): InspectState {\n const inspection = system.inspect();\n return {\n isSettled: system.isSettled,\n unmet: inspection.unmet,\n inflight: inspection.inflight,\n isWorking: inspection.unmet.length > 0 || inspection.inflight.length > 0,\n hasUnmet: inspection.unmet.length > 0,\n hasInflight: inspection.inflight.length > 0,\n };\n}\n\n// ============================================================================\n// Throttled Hook Options\n// ============================================================================\n\n/**\n * Options for throttled hooks.\n * Used by useInspectThrottled, useRequirementsThrottled, etc.\n */\nexport interface ThrottledHookOptions {\n /**\n * Minimum time between updates in milliseconds.\n * @default 100\n */\n throttleMs?: number;\n}\n\n// ============================================================================\n// Throttle Utility\n// ============================================================================\n\n/**\n * Create a throttled version of a callback function.\n * Uses trailing-edge throttling: the callback will be called at most once per interval,\n * with the latest arguments from the most recent call.\n *\n * @param callback - The function to throttle\n * @param ms - The minimum time between calls in milliseconds\n * @returns A throttled version of the callback and a cleanup function\n * @internal\n */\nexport function createThrottle<T extends (...args: unknown[]) => void>(\n callback: T,\n ms: number,\n): { throttled: T; cleanup: () => void } {\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n let lastArgs: Parameters<T> | null = null;\n let lastCallTime = 0;\n\n const throttled = ((...args: Parameters<T>) => {\n const now = Date.now();\n const timeSinceLastCall = now - lastCallTime;\n\n if (timeSinceLastCall >= ms) {\n // Enough time has passed, call immediately\n lastCallTime = now;\n callback(...args);\n } else {\n // Schedule for later, keeping latest args\n lastArgs = args;\n if (!timeoutId) {\n timeoutId = setTimeout(() => {\n timeoutId = null;\n lastCallTime = Date.now();\n if (lastArgs) {\n callback(...lastArgs);\n lastArgs = null;\n }\n }, ms - timeSinceLastCall);\n }\n }\n }) as T;\n\n const cleanup = () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n lastArgs = null;\n };\n\n return { throttled, cleanup };\n}\n\n// ============================================================================\n// Shared Adapter Helpers\n// ============================================================================\n\n/**\n * Dev-mode assertion that the system parameter is non-null.\n * Tree-shaken in production builds.\n * @internal\n */\nexport function assertSystem(hookName: string, system: unknown): void {\n if (process.env.NODE_ENV !== \"production\" && system == null) {\n throw new Error(\n `[Directive] ${hookName}() requires a system instance as the first argument. Received ${system}.`,\n );\n }\n}\n\n/** Default equality function using Object.is */\nexport function defaultEquality<T>(a: T, b: T): boolean {\n return Object.is(a, b);\n}\n\n/**\n * Build a HistoryState object from a system's history instance.\n * Returns null when history is disabled.\n * @internal\n */\nexport function buildHistoryState(system: SystemLike): HistoryState | null {\n const debug = system.history;\n if (!debug) return null;\n\n // Build lightweight metadata array (no facts data)\n const snapshots: SnapshotMeta[] = debug.snapshots.map((s) => ({\n id: s.id,\n timestamp: s.timestamp,\n trigger: s.trigger,\n }));\n\n return {\n // Navigation state\n canGoBack: debug.currentIndex > 0,\n canGoForward: debug.currentIndex < debug.snapshots.length - 1,\n currentIndex: debug.currentIndex,\n totalSnapshots: debug.snapshots.length,\n\n // Snapshot access\n snapshots,\n getSnapshotFacts: (id: number): Record<string, unknown> | null => {\n const snap = debug.snapshots.find((s) => s.id === id);\n return snap ? snap.facts : null;\n },\n\n // Navigation\n goTo: (snapshotId: number) => debug.goTo(snapshotId),\n goBack: (steps?: number) => debug.goBack(steps),\n goForward: (steps?: number) => debug.goForward(steps),\n replay: () => debug.replay(),\n\n // Session persistence\n exportSession: () => debug.export(),\n importSession: (json: string) => debug.import(json),\n\n // Changesets\n beginChangeset: (label: string) => debug.beginChangeset(label),\n endChangeset: () => debug.endChangeset(),\n\n // Recording control\n isPaused: debug.isPaused,\n pause: () => debug.pause(),\n resume: () => debug.resume(),\n };\n}\n\n/**\n * Pick specific fact values from a system's store.\n * @internal\n */\nexport function pickFacts(\n system: SystemLike,\n keys: string[],\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const key of keys) {\n result[key] = system.facts.$store.get(key);\n }\n return result;\n}\n\n// ============================================================================\n// Tracked Selector\n// ============================================================================\n\n/** Result of running a selector with tracking. @internal */\nexport interface TrackedSelectorResult<R> {\n value: R;\n factKeys: string[];\n deriveKeys: string[];\n}\n\n/**\n * Run a selector against a system with automatic dependency tracking.\n * Creates a Proxy that intercepts property access to distinguish between\n * fact reads (tracked via withTracking) and derivation reads (tracked manually).\n *\n * Used by useSelector in all framework adapters.\n * @internal\n */\nexport function runTrackedSelector<R>(\n system: SystemLike,\n deriveKeySet: Set<string>,\n selector: (state: Record<string, unknown>) => R,\n): TrackedSelectorResult<R> {\n const accessedDeriveKeys: string[] = [];\n\n const stateProxy = new Proxy(\n {},\n {\n get(_, prop: string | symbol) {\n if (typeof prop !== \"string\") return undefined;\n if (deriveKeySet.has(prop)) {\n accessedDeriveKeys.push(prop);\n return system.read(prop);\n }\n return system.facts.$store.get(prop);\n },\n has(_, prop: string | symbol) {\n if (typeof prop !== \"string\") return false;\n return deriveKeySet.has(prop) || system.facts.$store.has(prop);\n },\n ownKeys() {\n const factKeys = Object.keys(system.facts.$store.toObject());\n const combined = new Set(factKeys);\n for (const k of deriveKeySet) combined.add(k);\n return [...combined];\n },\n getOwnPropertyDescriptor() {\n return { configurable: true, enumerable: true, writable: true };\n },\n },\n );\n\n const { value, deps } = withTracking(() =>\n selector(stateProxy as Record<string, unknown>),\n );\n return {\n value,\n factKeys: Array.from(deps) as string[],\n deriveKeys: accessedDeriveKeys,\n };\n}\n\n/**\n * Check if tracked dependency keys have changed.\n * @internal\n */\nexport function depsChanged(\n prevFacts: string[],\n newFacts: string[],\n prevDerived: string[],\n newDerived: string[],\n): boolean {\n const factsChanged =\n newFacts.length !== prevFacts.length ||\n newFacts.some((k, i) => k !== prevFacts[i]);\n const derivedChanged =\n newDerived.length !== prevDerived.length ||\n newDerived.some((k, i) => k !== prevDerived[i]);\n return factsChanged || derivedChanged;\n}\n\n// ============================================================================\n// Re-exports from core/types/adapter-utils and utils/utils\n// ============================================================================\n\nexport {\n setBridgeFact,\n getBridgeFact,\n createCallbackPlugin,\n requirementGuard,\n requirementGuardMultiple,\n} from \"./core/types/adapter-utils.js\";\n\nexport { shallowEqual } from \"./utils/utils.js\";\n"]}
1
+ {"version":3,"sources":["../src/adapter-utils.ts"],"names":["computeInspectState","system","inspection","createThrottle","callback","ms","timeoutId","lastArgs","lastCallTime","args","now","timeSinceLastCall","assertSystem","hookName","defaultEquality","a","b","buildHistoryState","debug","snapshots","s","id","snap","snapshotId","steps","json","label","pickFacts","keys","result","key","runTrackedSelector","deriveKeySet","selector","accessedDeriveKeys","stateProxy","_","prop","factKeys","combined","k","value","deps","withTracking","depsChanged","prevFacts","newFacts","prevDerived","newDerived","factsChanged","derivedChanged","mergeHydrationFacts","snapshot","initialFacts","data"],"mappings":"qHAsGO,SAASA,CAAAA,CAAoBC,CAAAA,CAAkC,CACpE,IAAMC,CAAAA,CAAaD,CAAAA,CAAO,OAAA,EAAQ,CAClC,OAAO,CACL,SAAA,CAAWA,CAAAA,CAAO,SAAA,CAClB,KAAA,CAAOC,CAAAA,CAAW,KAAA,CAClB,QAAA,CAAUA,CAAAA,CAAW,QAAA,CACrB,SAAA,CAAWA,CAAAA,CAAW,KAAA,CAAM,MAAA,CAAS,CAAA,EAAKA,CAAAA,CAAW,QAAA,CAAS,MAAA,CAAS,CAAA,CACvE,QAAA,CAAUA,CAAAA,CAAW,KAAA,CAAM,MAAA,CAAS,CAAA,CACpC,WAAA,CAAaA,CAAAA,CAAW,QAAA,CAAS,MAAA,CAAS,CAC5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CAAA,CAI3B,IAAMC,CAAAA,CACJ,MAAA,GAAUF,CAAAA,EACV,OAAOA,CAAAA,CAAS,IAAA,EAAS,QAAA,EACzBA,CAAAA,CAAS,IAAA,GAAS,IAAA,CACbA,CAAAA,CAAS,IAAA,CACTA,CAAAA,CAEP,OAAO,CAAE,GAAGC,CAAAA,CAAc,GAAGC,CAAK,CACpC","file":"adapter-utils.cjs","sourcesContent":["/**\n * Shared Adapter Utilities\n *\n * Common types and helper functions used across all framework adapters.\n * @internal\n */\n\nimport { withTracking } from \"./core/tracking.js\";\nimport type {\n HistoryAPI,\n HistoryState,\n SnapshotMeta,\n SystemInspection,\n} from \"./core/types.js\";\n\n// ============================================================================\n// SystemLike — structural type satisfied by both System and SingleModuleSystem\n// ============================================================================\n\n/**\n * Minimal structural type for shared adapter helpers.\n * Both `System<any>` and `SingleModuleSystem<any>` satisfy this interface,\n * eliminating the need for `as unknown as System<any>` casts in adapters.\n * @internal\n */\nexport interface SystemLike {\n readonly isSettled: boolean;\n readonly history: HistoryAPI | null;\n readonly facts: {\n $store: {\n get(key: string): unknown;\n has(key: string): boolean;\n toObject(): Record<string, unknown>;\n };\n };\n readonly derive?: Record<string, unknown>;\n read(key: string): unknown;\n inspect(): SystemInspection;\n}\n\n// ============================================================================\n// Requirements State\n// ============================================================================\n\n/**\n * Requirements state returned by useRequirements hooks.\n * Provides a focused view of just requirements without full inspection overhead.\n */\nexport interface RequirementsState {\n /** Array of unmet requirements waiting to be resolved */\n unmet: Array<{\n id: string;\n requirement: { type: string; [key: string]: unknown };\n fromConstraint: string;\n }>;\n /** Array of requirements currently being resolved */\n inflight: Array<{ id: string; resolverId: string; startedAt: number }>;\n /** Whether there are any unmet requirements */\n hasUnmet: boolean;\n /** Whether there are any inflight requirements */\n hasInflight: boolean;\n /** Whether the system is actively working (has unmet or inflight requirements) */\n isWorking: boolean;\n}\n\n// ============================================================================\n// Inspect State (shared across all adapters)\n// ============================================================================\n\n/**\n * Consolidated inspection state returned by useInspect hooks.\n * Identical shape across React, Vue, Svelte, Solid, and Lit adapters.\n */\nexport interface InspectState {\n /** Whether the system has settled (no pending operations) */\n isSettled: boolean;\n /** Array of unmet requirements */\n unmet: RequirementsState[\"unmet\"];\n /** Array of inflight requirements */\n inflight: RequirementsState[\"inflight\"];\n /** Whether the system is actively working */\n isWorking: boolean;\n /** Whether there are any unmet requirements */\n hasUnmet: boolean;\n /** Whether there are any inflight requirements */\n hasInflight: boolean;\n}\n\n/**\n * Information about a single constraint.\n */\nexport interface ConstraintInfo {\n id: string;\n active: boolean;\n priority: number;\n}\n\n/**\n * Compute InspectState from a system instance.\n * Centralizes the logic currently duplicated across adapters.\n * @internal\n */\nexport function computeInspectState(system: SystemLike): InspectState {\n const inspection = system.inspect();\n return {\n isSettled: system.isSettled,\n unmet: inspection.unmet,\n inflight: inspection.inflight,\n isWorking: inspection.unmet.length > 0 || inspection.inflight.length > 0,\n hasUnmet: inspection.unmet.length > 0,\n hasInflight: inspection.inflight.length > 0,\n };\n}\n\n// ============================================================================\n// Throttled Hook Options\n// ============================================================================\n\n/**\n * Options for throttled hooks.\n * Used by useInspectThrottled, useRequirementsThrottled, etc.\n */\nexport interface ThrottledHookOptions {\n /**\n * Minimum time between updates in milliseconds.\n * @default 100\n */\n throttleMs?: number;\n}\n\n// ============================================================================\n// Throttle Utility\n// ============================================================================\n\n/**\n * Create a throttled version of a callback function.\n * Uses trailing-edge throttling: the callback will be called at most once per interval,\n * with the latest arguments from the most recent call.\n *\n * @param callback - The function to throttle\n * @param ms - The minimum time between calls in milliseconds\n * @returns A throttled version of the callback and a cleanup function\n * @internal\n */\nexport function createThrottle<T extends (...args: unknown[]) => void>(\n callback: T,\n ms: number,\n): { throttled: T; cleanup: () => void } {\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n let lastArgs: Parameters<T> | null = null;\n let lastCallTime = 0;\n\n const throttled = ((...args: Parameters<T>) => {\n const now = Date.now();\n const timeSinceLastCall = now - lastCallTime;\n\n if (timeSinceLastCall >= ms) {\n // Enough time has passed, call immediately\n lastCallTime = now;\n callback(...args);\n } else {\n // Schedule for later, keeping latest args\n lastArgs = args;\n if (!timeoutId) {\n timeoutId = setTimeout(() => {\n timeoutId = null;\n lastCallTime = Date.now();\n if (lastArgs) {\n callback(...lastArgs);\n lastArgs = null;\n }\n }, ms - timeSinceLastCall);\n }\n }\n }) as T;\n\n const cleanup = () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n lastArgs = null;\n };\n\n return { throttled, cleanup };\n}\n\n// ============================================================================\n// Shared Adapter Helpers\n// ============================================================================\n\n/**\n * Dev-mode assertion that the system parameter is non-null.\n * Tree-shaken in production builds.\n * @internal\n */\nexport function assertSystem(hookName: string, system: unknown): void {\n if (process.env.NODE_ENV !== \"production\" && system == null) {\n throw new Error(\n `[Directive] ${hookName}() requires a system instance as the first argument. Received ${system}.`,\n );\n }\n}\n\n/** Default equality function using Object.is */\nexport function defaultEquality<T>(a: T, b: T): boolean {\n return Object.is(a, b);\n}\n\n/**\n * Build a HistoryState object from a system's history instance.\n * Returns null when history is disabled.\n * @internal\n */\nexport function buildHistoryState(system: SystemLike): HistoryState | null {\n const debug = system.history;\n if (!debug) return null;\n\n // Build lightweight metadata array (no facts data)\n const snapshots: SnapshotMeta[] = debug.snapshots.map((s) => ({\n id: s.id,\n timestamp: s.timestamp,\n trigger: s.trigger,\n }));\n\n return {\n // Navigation state\n canGoBack: debug.currentIndex > 0,\n canGoForward: debug.currentIndex < debug.snapshots.length - 1,\n currentIndex: debug.currentIndex,\n totalSnapshots: debug.snapshots.length,\n\n // Snapshot access\n snapshots,\n getSnapshotFacts: (id: number): Record<string, unknown> | null => {\n const snap = debug.snapshots.find((s) => s.id === id);\n return snap ? snap.facts : null;\n },\n\n // Navigation\n goTo: (snapshotId: number) => debug.goTo(snapshotId),\n goBack: (steps?: number) => debug.goBack(steps),\n goForward: (steps?: number) => debug.goForward(steps),\n replay: () => debug.replay(),\n\n // Session persistence\n exportSession: () => debug.export(),\n importSession: (json: string) => debug.import(json),\n\n // Changesets\n beginChangeset: (label: string) => debug.beginChangeset(label),\n endChangeset: () => debug.endChangeset(),\n\n // Recording control\n isPaused: debug.isPaused,\n pause: () => debug.pause(),\n resume: () => debug.resume(),\n };\n}\n\n/**\n * Pick specific fact values from a system's store.\n * @internal\n */\nexport function pickFacts(\n system: SystemLike,\n keys: string[],\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const key of keys) {\n result[key] = system.facts.$store.get(key);\n }\n return result;\n}\n\n// ============================================================================\n// Tracked Selector\n// ============================================================================\n\n/** Result of running a selector with tracking. @internal */\nexport interface TrackedSelectorResult<R> {\n value: R;\n factKeys: string[];\n deriveKeys: string[];\n}\n\n/**\n * Run a selector against a system with automatic dependency tracking.\n * Creates a Proxy that intercepts property access to distinguish between\n * fact reads (tracked via withTracking) and derivation reads (tracked manually).\n *\n * Used by useSelector in all framework adapters.\n * @internal\n */\nexport function runTrackedSelector<R>(\n system: SystemLike,\n deriveKeySet: Set<string>,\n selector: (state: Record<string, unknown>) => R,\n): TrackedSelectorResult<R> {\n const accessedDeriveKeys: string[] = [];\n\n const stateProxy = new Proxy(\n {},\n {\n get(_, prop: string | symbol) {\n if (typeof prop !== \"string\") return undefined;\n if (deriveKeySet.has(prop)) {\n accessedDeriveKeys.push(prop);\n return system.read(prop);\n }\n return system.facts.$store.get(prop);\n },\n has(_, prop: string | symbol) {\n if (typeof prop !== \"string\") return false;\n return deriveKeySet.has(prop) || system.facts.$store.has(prop);\n },\n ownKeys() {\n const factKeys = Object.keys(system.facts.$store.toObject());\n const combined = new Set(factKeys);\n for (const k of deriveKeySet) combined.add(k);\n return [...combined];\n },\n getOwnPropertyDescriptor() {\n return { configurable: true, enumerable: true, writable: true };\n },\n },\n );\n\n const { value, deps } = withTracking(() =>\n selector(stateProxy as Record<string, unknown>),\n );\n return {\n value,\n factKeys: Array.from(deps) as string[],\n deriveKeys: accessedDeriveKeys,\n };\n}\n\n/**\n * Check if tracked dependency keys have changed.\n * @internal\n */\nexport function depsChanged(\n prevFacts: string[],\n newFacts: string[],\n prevDerived: string[],\n newDerived: string[],\n): boolean {\n const factsChanged =\n newFacts.length !== prevFacts.length ||\n newFacts.some((k, i) => k !== prevFacts[i]);\n const derivedChanged =\n newDerived.length !== prevDerived.length ||\n newDerived.some((k, i) => k !== prevDerived[i]);\n return factsChanged || derivedChanged;\n}\n\n// ============================================================================\n// Re-exports from core/types/adapter-utils and utils/utils\n// ============================================================================\n\nexport {\n setBridgeFact,\n getBridgeFact,\n createCallbackPlugin,\n requirementGuard,\n requirementGuardMultiple,\n} from \"./core/types/adapter-utils.js\";\n\nexport { shallowEqual } from \"./utils/utils.js\";\n\n/**\n * Merge a DistributableSnapshot's data into initialFacts for SSR hydration.\n * Used by all framework adapters' hydration hooks/controllers.\n *\n * Accepts both shapes:\n * - DistributableSnapshot (`{ data: Record<string, unknown> }`) — used by React's DirectiveHydrator\n * - Plain `Record<string, unknown>` — used by Lit/Vue/Svelte/Solid adapters\n */\nexport function mergeHydrationFacts(\n snapshot:\n | { data?: Record<string, unknown> }\n | Record<string, unknown>\n | undefined\n | null,\n initialFacts?: Record<string, unknown>,\n): Record<string, unknown> {\n if (!snapshot) {\n return { ...initialFacts };\n }\n\n // If snapshot has a .data property that is a non-null object, treat as DistributableSnapshot\n const data =\n \"data\" in snapshot &&\n typeof snapshot.data === \"object\" &&\n snapshot.data !== null\n ? (snapshot.data as Record<string, unknown>)\n : (snapshot as Record<string, unknown>);\n\n return { ...initialFacts, ...data };\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { o as Requirement, P as Plugin, F as Facts, Q as Schema, H as HistoryAPI, X as SystemInspection, x as HistoryState } from './plugins-Bg_oq2sO.cjs';
2
- export { s as shallowEqual } from './utils-4JrY5fk9.cjs';
2
+ export { s as shallowEqual } from './utils-BnQajqPu.cjs';
3
3
 
4
4
  /**
5
5
  * Adapter Type Utilities - Shared types and helpers for framework adapters
@@ -227,4 +227,16 @@ declare function runTrackedSelector<R>(system: SystemLike, deriveKeySet: Set<str
227
227
  */
228
228
  declare function depsChanged(prevFacts: string[], newFacts: string[], prevDerived: string[], newDerived: string[]): boolean;
229
229
 
230
- export { type ConstraintInfo, type InspectState, type RequirementsState, type SystemLike, type ThrottledHookOptions, type TrackedSelectorResult, assertSystem, buildHistoryState, computeInspectState, createCallbackPlugin, createThrottle, defaultEquality, depsChanged, getBridgeFact, pickFacts, requirementGuard, requirementGuardMultiple, runTrackedSelector, setBridgeFact };
230
+ /**
231
+ * Merge a DistributableSnapshot's data into initialFacts for SSR hydration.
232
+ * Used by all framework adapters' hydration hooks/controllers.
233
+ *
234
+ * Accepts both shapes:
235
+ * - DistributableSnapshot (`{ data: Record<string, unknown> }`) — used by React's DirectiveHydrator
236
+ * - Plain `Record<string, unknown>` — used by Lit/Vue/Svelte/Solid adapters
237
+ */
238
+ declare function mergeHydrationFacts(snapshot: {
239
+ data?: Record<string, unknown>;
240
+ } | Record<string, unknown> | undefined | null, initialFacts?: Record<string, unknown>): Record<string, unknown>;
241
+
242
+ export { type ConstraintInfo, type InspectState, type RequirementsState, type SystemLike, type ThrottledHookOptions, type TrackedSelectorResult, assertSystem, buildHistoryState, computeInspectState, createCallbackPlugin, createThrottle, defaultEquality, depsChanged, getBridgeFact, mergeHydrationFacts, pickFacts, requirementGuard, requirementGuardMultiple, runTrackedSelector, setBridgeFact };
@@ -1,5 +1,5 @@
1
1
  import { o as Requirement, P as Plugin, F as Facts, Q as Schema, H as HistoryAPI, X as SystemInspection, x as HistoryState } from './plugins-Bg_oq2sO.js';
2
- export { s as shallowEqual } from './utils-4JrY5fk9.js';
2
+ export { s as shallowEqual } from './utils-BnQajqPu.js';
3
3
 
4
4
  /**
5
5
  * Adapter Type Utilities - Shared types and helpers for framework adapters
@@ -227,4 +227,16 @@ declare function runTrackedSelector<R>(system: SystemLike, deriveKeySet: Set<str
227
227
  */
228
228
  declare function depsChanged(prevFacts: string[], newFacts: string[], prevDerived: string[], newDerived: string[]): boolean;
229
229
 
230
- export { type ConstraintInfo, type InspectState, type RequirementsState, type SystemLike, type ThrottledHookOptions, type TrackedSelectorResult, assertSystem, buildHistoryState, computeInspectState, createCallbackPlugin, createThrottle, defaultEquality, depsChanged, getBridgeFact, pickFacts, requirementGuard, requirementGuardMultiple, runTrackedSelector, setBridgeFact };
230
+ /**
231
+ * Merge a DistributableSnapshot's data into initialFacts for SSR hydration.
232
+ * Used by all framework adapters' hydration hooks/controllers.
233
+ *
234
+ * Accepts both shapes:
235
+ * - DistributableSnapshot (`{ data: Record<string, unknown> }`) — used by React's DirectiveHydrator
236
+ * - Plain `Record<string, unknown>` — used by Lit/Vue/Svelte/Solid adapters
237
+ */
238
+ declare function mergeHydrationFacts(snapshot: {
239
+ data?: Record<string, unknown>;
240
+ } | Record<string, unknown> | undefined | null, initialFacts?: Record<string, unknown>): Record<string, unknown>;
241
+
242
+ export { type ConstraintInfo, type InspectState, type RequirementsState, type SystemLike, type ThrottledHookOptions, type TrackedSelectorResult, assertSystem, buildHistoryState, computeInspectState, createCallbackPlugin, createThrottle, defaultEquality, depsChanged, getBridgeFact, mergeHydrationFacts, pickFacts, requirementGuard, requirementGuardMultiple, runTrackedSelector, setBridgeFact };
@@ -1,2 +1,2 @@
1
- import {h}from'./chunk-O75OISQ2.js';export{c as createCallbackPlugin,b as getBridgeFact,d as requirementGuard,e as requirementGuardMultiple,a as setBridgeFact}from'./chunk-O75OISQ2.js';export{d as shallowEqual}from'./chunk-GO63IIN5.js';function k(n){let t=n.inspect();return {isSettled:n.isSettled,unmet:t.unmet,inflight:t.inflight,isWorking:t.unmet.length>0||t.inflight.length>0,hasUnmet:t.unmet.length>0,hasInflight:t.inflight.length>0}}function b(n,t){let r=null,e=null,s=0;return {throttled:((...i)=>{let o=Date.now(),u=o-s;u>=t?(s=o,n(...i)):(e=i,r||(r=setTimeout(()=>{r=null,s=Date.now(),e&&(n(...e),e=null);},t-u)));}),cleanup:()=>{r&&(clearTimeout(r),r=null),e=null;}}}function S(n,t){if(process.env.NODE_ENV!=="production"&&t==null)throw new Error(`[Directive] ${n}() requires a system instance as the first argument. Received ${t}.`)}function w(n,t){return Object.is(n,t)}function x(n){let t=n.history;if(!t)return null;let r=t.snapshots.map(e=>({id:e.id,timestamp:e.timestamp,trigger:e.trigger}));return {canGoBack:t.currentIndex>0,canGoForward:t.currentIndex<t.snapshots.length-1,currentIndex:t.currentIndex,totalSnapshots:t.snapshots.length,snapshots:r,getSnapshotFacts:e=>{let s=t.snapshots.find(a=>a.id===e);return s?s.facts:null},goTo:e=>t.goTo(e),goBack:e=>t.goBack(e),goForward:e=>t.goForward(e),replay:()=>t.replay(),exportSession:()=>t.export(),importSession:e=>t.import(e),beginChangeset:e=>t.beginChangeset(e),endChangeset:()=>t.endChangeset(),isPaused:t.isPaused,pause:()=>t.pause(),resume:()=>t.resume()}}function T(n,t){let r={};for(let e of t)r[e]=n.facts.$store.get(e);return r}function R(n,t,r){let e=[],s=new Proxy({},{get(i,o){if(typeof o=="string")return t.has(o)?(e.push(o),n.read(o)):n.facts.$store.get(o)},has(i,o){return typeof o!="string"?false:t.has(o)||n.facts.$store.has(o)},ownKeys(){let i=Object.keys(n.facts.$store.toObject()),o=new Set(i);for(let u of t)o.add(u);return [...o]},getOwnPropertyDescriptor(){return {configurable:true,enumerable:true,writable:true}}}),{value:a,deps:l}=h(()=>r(s));return {value:a,factKeys:Array.from(l),deriveKeys:e}}function I(n,t,r,e){let s=t.length!==n.length||t.some((l,i)=>l!==n[i]),a=e.length!==r.length||e.some((l,i)=>l!==r[i]);return s||a}export{S as assertSystem,x as buildHistoryState,k as computeInspectState,b as createThrottle,w as defaultEquality,I as depsChanged,T as pickFacts,R as runTrackedSelector};//# sourceMappingURL=adapter-utils.js.map
1
+ import {h}from'./chunk-O75OISQ2.js';export{c as createCallbackPlugin,b as getBridgeFact,d as requirementGuard,e as requirementGuardMultiple,a as setBridgeFact}from'./chunk-O75OISQ2.js';export{d as shallowEqual}from'./chunk-4CMO5OVZ.js';function k(n){let e=n.inspect();return {isSettled:n.isSettled,unmet:e.unmet,inflight:e.inflight,isWorking:e.unmet.length>0||e.inflight.length>0,hasUnmet:e.unmet.length>0,hasInflight:e.inflight.length>0}}function b(n,e){let r=null,t=null,s=0;return {throttled:((...i)=>{let o=Date.now(),l=o-s;l>=e?(s=o,n(...i)):(t=i,r||(r=setTimeout(()=>{r=null,s=Date.now(),t&&(n(...t),t=null);},e-l)));}),cleanup:()=>{r&&(clearTimeout(r),r=null),t=null;}}}function w(n,e){if(process.env.NODE_ENV!=="production"&&e==null)throw new Error(`[Directive] ${n}() requires a system instance as the first argument. Received ${e}.`)}function S(n,e){return Object.is(n,e)}function x(n){let e=n.history;if(!e)return null;let r=e.snapshots.map(t=>({id:t.id,timestamp:t.timestamp,trigger:t.trigger}));return {canGoBack:e.currentIndex>0,canGoForward:e.currentIndex<e.snapshots.length-1,currentIndex:e.currentIndex,totalSnapshots:e.snapshots.length,snapshots:r,getSnapshotFacts:t=>{let s=e.snapshots.find(a=>a.id===t);return s?s.facts:null},goTo:t=>e.goTo(t),goBack:t=>e.goBack(t),goForward:t=>e.goForward(t),replay:()=>e.replay(),exportSession:()=>e.export(),importSession:t=>e.import(t),beginChangeset:t=>e.beginChangeset(t),endChangeset:()=>e.endChangeset(),isPaused:e.isPaused,pause:()=>e.pause(),resume:()=>e.resume()}}function R(n,e){let r={};for(let t of e)r[t]=n.facts.$store.get(t);return r}function T(n,e,r){let t=[],s=new Proxy({},{get(i,o){if(typeof o=="string")return e.has(o)?(t.push(o),n.read(o)):n.facts.$store.get(o)},has(i,o){return typeof o!="string"?false:e.has(o)||n.facts.$store.has(o)},ownKeys(){let i=Object.keys(n.facts.$store.toObject()),o=new Set(i);for(let l of e)o.add(l);return [...o]},getOwnPropertyDescriptor(){return {configurable:true,enumerable:true,writable:true}}}),{value:a,deps:u}=h(()=>r(s));return {value:a,factKeys:Array.from(u),deriveKeys:t}}function I(n,e,r,t){let s=e.length!==n.length||e.some((u,i)=>u!==n[i]),a=t.length!==r.length||t.some((u,i)=>u!==r[i]);return s||a}function C(n,e){if(!n)return {...e};let r="data"in n&&typeof n.data=="object"&&n.data!==null?n.data:n;return {...e,...r}}export{w as assertSystem,x as buildHistoryState,k as computeInspectState,b as createThrottle,S as defaultEquality,I as depsChanged,C as mergeHydrationFacts,R as pickFacts,T as runTrackedSelector};//# sourceMappingURL=adapter-utils.js.map
2
2
  //# sourceMappingURL=adapter-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/adapter-utils.ts"],"names":["computeInspectState","system","inspection","createThrottle","callback","ms","timeoutId","lastArgs","lastCallTime","args","now","timeSinceLastCall","assertSystem","hookName","defaultEquality","a","b","buildHistoryState","debug","snapshots","s","id","snap","snapshotId","steps","json","label","pickFacts","keys","result","key","runTrackedSelector","deriveKeySet","selector","accessedDeriveKeys","stateProxy","_","prop","factKeys","combined","k","value","deps","withTracking","depsChanged","prevFacts","newFacts","prevDerived","newDerived","factsChanged","derivedChanged"],"mappings":"4OAsGO,SAASA,CAAAA,CAAoBC,CAAAA,CAAkC,CACpE,IAAMC,CAAAA,CAAaD,CAAAA,CAAO,OAAA,EAAQ,CAClC,OAAO,CACL,SAAA,CAAWA,CAAAA,CAAO,SAAA,CAClB,MAAOC,CAAAA,CAAW,KAAA,CAClB,QAAA,CAAUA,CAAAA,CAAW,QAAA,CACrB,SAAA,CAAWA,CAAAA,CAAW,KAAA,CAAM,MAAA,CAAS,CAAA,EAAKA,CAAAA,CAAW,QAAA,CAAS,MAAA,CAAS,CAAA,CACvE,SAAUA,CAAAA,CAAW,KAAA,CAAM,MAAA,CAAS,CAAA,CACpC,WAAA,CAAaA,CAAAA,CAAW,QAAA,CAAS,MAAA,CAAS,CAC5C,CACF,CAgCO,SAASC,CAAAA,CACdC,CAAAA,CACAC,EACuC,CACvC,IAAIC,CAAAA,CAAkD,IAAA,CAClDC,CAAAA,CAAiC,IAAA,CACjCC,CAAAA,CA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AAS,IAAIC,CAAC,CAAA,CAC5C,OAAO,CAAC,GAAGD,CAAQ,CACrB,CAAA,CACA,wBAAA,EAA2B,CACzB,OAAO,CAAE,YAAA,CAAc,IAAA,CAAM,WAAY,IAAA,CAAM,QAAA,CAAU,IAAK,CAChE,CACF,CACF,CAAA,CAEM,CAAE,KAAA,CAAAE,CAAAA,CAAO,IAAA,CAAAC,CAAK,CAAA,CAAIC,CAAAA,CAAa,IACnCV,CAAAA,CAASE,CAAqC,CAChD,CAAA,CACA,OAAO,CACL,KAAA,CAAAM,CAAAA,CACA,QAAA,CAAU,KAAA,CAAM,IAAA,CAAKC,CAAI,CAAA,CACzB,UAAA,CAAYR,CACd,CACF,CAMO,SAASU,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACS,CACT,IAAMC,CAAAA,CACJH,CAAAA,CAAS,MAAA,GAAWD,CAAAA,CAAU,QAC9BC,CAAAA,CAAS,IAAA,CAAK,CAACN,CAAAA,CAAG,CAAA,GAAMA,CAAAA,GAAMK,CAAAA,CAAU,CAAC,CAAC,CAAA,CACtCK,CAAAA,CACJF,CAAAA,CAAW,MAAA,GAAWD,CAAAA,CAAY,QAClCC,CAAAA,CAAW,IAAA,CAAK,CAACR,CAAAA,CAAG,CAAA,GAAMA,CAAAA,GAAMO,CAAAA,CAAY,CAAC,CAAC,CAAA,CAChD,OAAOE,CAAAA,EAAgBC,CACzB","file":"adapter-utils.js","sourcesContent":["/**\n * Shared Adapter Utilities\n *\n * Common types and helper functions used across all framework adapters.\n * @internal\n */\n\nimport { withTracking } from \"./core/tracking.js\";\nimport type {\n HistoryAPI,\n HistoryState,\n SnapshotMeta,\n SystemInspection,\n} from \"./core/types.js\";\n\n// ============================================================================\n// SystemLike — structural type satisfied by both System and SingleModuleSystem\n// ============================================================================\n\n/**\n * Minimal structural type for shared adapter helpers.\n * Both `System<any>` and `SingleModuleSystem<any>` satisfy this interface,\n * eliminating the need for `as unknown as System<any>` casts in adapters.\n * @internal\n */\nexport interface SystemLike {\n readonly isSettled: boolean;\n readonly history: HistoryAPI | null;\n readonly facts: {\n $store: {\n get(key: string): unknown;\n has(key: string): boolean;\n toObject(): Record<string, unknown>;\n };\n };\n readonly derive?: Record<string, unknown>;\n read(key: string): unknown;\n inspect(): SystemInspection;\n}\n\n// ============================================================================\n// Requirements State\n// ============================================================================\n\n/**\n * Requirements state returned by useRequirements hooks.\n * Provides a focused view of just requirements without full inspection overhead.\n */\nexport interface RequirementsState {\n /** Array of unmet requirements waiting to be resolved */\n unmet: Array<{\n id: string;\n requirement: { type: string; [key: string]: unknown };\n fromConstraint: string;\n }>;\n /** Array of requirements currently being resolved */\n inflight: Array<{ id: string; resolverId: string; startedAt: number }>;\n /** Whether there are any unmet requirements */\n hasUnmet: boolean;\n /** Whether there are any inflight requirements */\n hasInflight: boolean;\n /** Whether the system is actively working (has unmet or inflight requirements) */\n isWorking: boolean;\n}\n\n// ============================================================================\n// Inspect State (shared across all adapters)\n// ============================================================================\n\n/**\n * Consolidated inspection state returned by useInspect hooks.\n * Identical shape across React, Vue, Svelte, Solid, and Lit adapters.\n */\nexport interface InspectState {\n /** Whether the system has settled (no pending operations) */\n isSettled: boolean;\n /** Array of unmet requirements */\n unmet: RequirementsState[\"unmet\"];\n /** Array of inflight requirements */\n inflight: RequirementsState[\"inflight\"];\n /** Whether the system is actively working */\n isWorking: boolean;\n /** Whether there are any unmet requirements */\n hasUnmet: boolean;\n /** Whether there are any inflight requirements */\n hasInflight: boolean;\n}\n\n/**\n * Information about a single constraint.\n */\nexport interface ConstraintInfo {\n id: string;\n active: boolean;\n priority: number;\n}\n\n/**\n * Compute InspectState from a system instance.\n * Centralizes the logic currently duplicated across adapters.\n * @internal\n */\nexport function computeInspectState(system: SystemLike): InspectState {\n const inspection = system.inspect();\n return {\n isSettled: system.isSettled,\n unmet: inspection.unmet,\n inflight: inspection.inflight,\n isWorking: inspection.unmet.length > 0 || inspection.inflight.length > 0,\n hasUnmet: inspection.unmet.length > 0,\n hasInflight: inspection.inflight.length > 0,\n };\n}\n\n// ============================================================================\n// Throttled Hook Options\n// ============================================================================\n\n/**\n * Options for throttled hooks.\n * Used by useInspectThrottled, useRequirementsThrottled, etc.\n */\nexport interface ThrottledHookOptions {\n /**\n * Minimum time between updates in milliseconds.\n * @default 100\n */\n throttleMs?: number;\n}\n\n// ============================================================================\n// Throttle Utility\n// ============================================================================\n\n/**\n * Create a throttled version of a callback function.\n * Uses trailing-edge throttling: the callback will be called at most once per interval,\n * with the latest arguments from the most recent call.\n *\n * @param callback - The function to throttle\n * @param ms - The minimum time between calls in milliseconds\n * @returns A throttled version of the callback and a cleanup function\n * @internal\n */\nexport function createThrottle<T extends (...args: unknown[]) => void>(\n callback: T,\n ms: number,\n): { throttled: T; cleanup: () => void } {\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n let lastArgs: Parameters<T> | null = null;\n let lastCallTime = 0;\n\n const throttled = ((...args: Parameters<T>) => {\n const now = Date.now();\n const timeSinceLastCall = now - lastCallTime;\n\n if (timeSinceLastCall >= ms) {\n // Enough time has passed, call immediately\n lastCallTime = now;\n callback(...args);\n } else {\n // Schedule for later, keeping latest args\n lastArgs = args;\n if (!timeoutId) {\n timeoutId = setTimeout(() => {\n timeoutId = null;\n lastCallTime = Date.now();\n if (lastArgs) {\n callback(...lastArgs);\n lastArgs = null;\n }\n }, ms - timeSinceLastCall);\n }\n }\n }) as T;\n\n const cleanup = () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n lastArgs = null;\n };\n\n return { throttled, cleanup };\n}\n\n// ============================================================================\n// Shared Adapter Helpers\n// ============================================================================\n\n/**\n * Dev-mode assertion that the system parameter is non-null.\n * Tree-shaken in production builds.\n * @internal\n */\nexport function assertSystem(hookName: string, system: unknown): void {\n if (process.env.NODE_ENV !== \"production\" && system == null) {\n throw new Error(\n `[Directive] ${hookName}() requires a system instance as the first argument. Received ${system}.`,\n );\n }\n}\n\n/** Default equality function using Object.is */\nexport function defaultEquality<T>(a: T, b: T): boolean {\n return Object.is(a, b);\n}\n\n/**\n * Build a HistoryState object from a system's history instance.\n * Returns null when history is disabled.\n * @internal\n */\nexport function buildHistoryState(system: SystemLike): HistoryState | null {\n const debug = system.history;\n if (!debug) return null;\n\n // Build lightweight metadata array (no facts data)\n const snapshots: SnapshotMeta[] = debug.snapshots.map((s) => ({\n id: s.id,\n timestamp: s.timestamp,\n trigger: s.trigger,\n }));\n\n return {\n // Navigation state\n canGoBack: debug.currentIndex > 0,\n canGoForward: debug.currentIndex < debug.snapshots.length - 1,\n currentIndex: debug.currentIndex,\n totalSnapshots: debug.snapshots.length,\n\n // Snapshot access\n snapshots,\n getSnapshotFacts: (id: number): Record<string, unknown> | null => {\n const snap = debug.snapshots.find((s) => s.id === id);\n return snap ? snap.facts : null;\n },\n\n // Navigation\n goTo: (snapshotId: number) => debug.goTo(snapshotId),\n goBack: (steps?: number) => debug.goBack(steps),\n goForward: (steps?: number) => debug.goForward(steps),\n replay: () => debug.replay(),\n\n // Session persistence\n exportSession: () => debug.export(),\n importSession: (json: string) => debug.import(json),\n\n // Changesets\n beginChangeset: (label: string) => debug.beginChangeset(label),\n endChangeset: () => debug.endChangeset(),\n\n // Recording control\n isPaused: debug.isPaused,\n pause: () => debug.pause(),\n resume: () => debug.resume(),\n };\n}\n\n/**\n * Pick specific fact values from a system's store.\n * @internal\n */\nexport function pickFacts(\n system: SystemLike,\n keys: string[],\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const key of keys) {\n result[key] = system.facts.$store.get(key);\n }\n return result;\n}\n\n// ============================================================================\n// Tracked Selector\n// ============================================================================\n\n/** Result of running a selector with tracking. @internal */\nexport interface TrackedSelectorResult<R> {\n value: R;\n factKeys: string[];\n deriveKeys: string[];\n}\n\n/**\n * Run a selector against a system with automatic dependency tracking.\n * Creates a Proxy that intercepts property access to distinguish between\n * fact reads (tracked via withTracking) and derivation reads (tracked manually).\n *\n * Used by useSelector in all framework adapters.\n * @internal\n */\nexport function runTrackedSelector<R>(\n system: SystemLike,\n deriveKeySet: Set<string>,\n selector: (state: Record<string, unknown>) => R,\n): TrackedSelectorResult<R> {\n const accessedDeriveKeys: string[] = [];\n\n const stateProxy = new Proxy(\n {},\n {\n get(_, prop: string | symbol) {\n if (typeof prop !== \"string\") return undefined;\n if (deriveKeySet.has(prop)) {\n accessedDeriveKeys.push(prop);\n return system.read(prop);\n }\n return system.facts.$store.get(prop);\n },\n has(_, prop: string | symbol) {\n if (typeof prop !== \"string\") return false;\n return deriveKeySet.has(prop) || system.facts.$store.has(prop);\n },\n ownKeys() {\n const factKeys = Object.keys(system.facts.$store.toObject());\n const combined = new Set(factKeys);\n for (const k of deriveKeySet) combined.add(k);\n return [...combined];\n },\n getOwnPropertyDescriptor() {\n return { configurable: true, enumerable: true, writable: true };\n },\n },\n );\n\n const { value, deps } = withTracking(() =>\n selector(stateProxy as Record<string, unknown>),\n );\n return {\n value,\n factKeys: Array.from(deps) as string[],\n deriveKeys: accessedDeriveKeys,\n };\n}\n\n/**\n * Check if tracked dependency keys have changed.\n * @internal\n */\nexport function depsChanged(\n prevFacts: string[],\n newFacts: string[],\n prevDerived: string[],\n newDerived: string[],\n): boolean {\n const factsChanged =\n newFacts.length !== prevFacts.length ||\n newFacts.some((k, i) => k !== prevFacts[i]);\n const derivedChanged =\n newDerived.length !== prevDerived.length ||\n newDerived.some((k, i) => k !== prevDerived[i]);\n return factsChanged || derivedChanged;\n}\n\n// ============================================================================\n// Re-exports from core/types/adapter-utils and utils/utils\n// ============================================================================\n\nexport {\n setBridgeFact,\n getBridgeFact,\n createCallbackPlugin,\n requirementGuard,\n requirementGuardMultiple,\n} from \"./core/types/adapter-utils.js\";\n\nexport { shallowEqual } from \"./utils/utils.js\";\n"]}
1
+ {"version":3,"sources":["../src/adapter-utils.ts"],"names":["computeInspectState","system","inspection","createThrottle","callback","ms","timeoutId","lastArgs","lastCallTime","args","now","timeSinceLastCall","assertSystem","hookName","defaultEquality","a","b","buildHistoryState","debug","snapshots","s","id","snap","snapshotId","steps","json","label","pickFacts","keys","result","key","runTrackedSelector","deriveKeySet","selector","accessedDeriveKeys","stateProxy","_","prop","factKeys","combined","k","value","deps","withTracking","depsChanged","prevFacts","newFacts","prevDerived","newDerived","factsChanged","derivedChanged","mergeHydrationFacts","snapshot","initialFacts","data"],"mappings":"4OAsGO,SAASA,CAAAA,CAAoBC,CAAAA,CAAkC,CACpE,IAAMC,CAAAA,CAAaD,CAAAA,CAAO,OAAA,EAAQ,CAClC,OAAO,CACL,SAAA,CAAWA,CAAAA,CAAO,SAAA,CAClB,KAAA,CAAOC,CAAAA,CAAW,KAAA,CAClB,QAAA,CAAUA,CAAAA,CAAW,QAAA,CACrB,SAAA,CAAWA,CAAAA,CAAW,KAAA,CAAM,MAAA,CAAS,CAAA,EAAKA,CAAAA,CAAW,QAAA,CAAS,MAAA,CAAS,CAAA,CACvE,QAAA,CAAUA,CAAAA,CAAW,KAAA,CAAM,MAAA,CAAS,CAAA,CACpC,WAAA,CAAaA,CAAAA,CAAW,QAAA,CAAS,MAAA,CAAS,CAC5C,CACF,CAgCO,SAASC,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACuC,CACvC,IAAIC,CAAAA,CAAkD,IAAA,CAClDC,CAAAA,CAAiC,IAAA,CACjCC,CAAAA,CAAe,CAAA,CAkCnB,OAAO,CAAE,SAAA,EAhCU,CAAA,GAAIC,CAAAA,GAAwB,CAC7C,IAAMC,CAAAA,CAAM,IAAA,CAAK,GAAA,EAAI,CACfC,CAAAA,CAAoBD,CAAAA,CAAMF,CAAAA,CAE5BG,CAAAA,EAAqBN,CAAAA,EAEvBG,CAAAA,CAAeE,CAAAA,CACfN,CAAAA,CAAS,GAAGK,CAAI,CAAA,GAGhBF,CAAAA,CAAWE,CAAAA,CACNH,CAAAA,GACHA,CAAAA,CAAY,UAAA,CAAW,IAAM,CAC3BA,CAAAA,CAAY,IAAA,CACZE,CAAAA,CAAe,IAA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OAAO,CACL,KAAA,CAAAM,CAAAA,CACA,QAAA,CAAU,KAAA,CAAM,IAAA,CAAKC,CAAI,CAAA,CACzB,UAAA,CAAYR,CACd,CACF,CAMO,SAASU,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACS,CACT,IAAMC,CAAAA,CACJH,CAAAA,CAAS,MAAA,GAAWD,CAAAA,CAAU,MAAA,EAC9BC,CAAAA,CAAS,IAAA,CAAK,CAACN,CAAAA,CAAG,CAAA,GAAMA,CAAAA,GAAMK,CAAAA,CAAU,CAAC,CAAC,CAAA,CACtCK,CAAAA,CACJF,CAAAA,CAAW,MAAA,GAAWD,CAAAA,CAAY,MAAA,EAClCC,CAAAA,CAAW,IAAA,CAAK,CAACR,CAAAA,CAAG,CAAA,GAAMA,CAAAA,GAAMO,CAAAA,CAAY,CAAC,CAAC,CAAA,CAChD,OAAOE,CAAAA,EAAgBC,CACzB,CAwBO,SAASC,CAAAA,CACdC,CAAAA,CAKAC,CAAAA,CACyB,CACzB,GAAI,CAACD,CAAAA,CACH,OAAO,CAAE,GAAGC,CAAa,CAAA,CAI3B,IAAMC,CAAAA,CACJ,MAAA,GAAUF,CAAAA,EACV,OAAOA,CAAAA,CAAS,IAAA,EAAS,QAAA,EACzBA,CAAAA,CAAS,IAAA,GAAS,IAAA,CACbA,CAAAA,CAAS,IAAA,CACTA,CAAAA,CAEP,OAAO,CAAE,GAAGC,CAAAA,CAAc,GAAGC,CAAK,CACpC","file":"adapter-utils.js","sourcesContent":["/**\n * Shared Adapter Utilities\n *\n * Common types and helper functions used across all framework adapters.\n * @internal\n */\n\nimport { withTracking } from \"./core/tracking.js\";\nimport type {\n HistoryAPI,\n HistoryState,\n SnapshotMeta,\n SystemInspection,\n} from \"./core/types.js\";\n\n// ============================================================================\n// SystemLike — structural type satisfied by both System and SingleModuleSystem\n// ============================================================================\n\n/**\n * Minimal structural type for shared adapter helpers.\n * Both `System<any>` and `SingleModuleSystem<any>` satisfy this interface,\n * eliminating the need for `as unknown as System<any>` casts in adapters.\n * @internal\n */\nexport interface SystemLike {\n readonly isSettled: boolean;\n readonly history: HistoryAPI | null;\n readonly facts: {\n $store: {\n get(key: string): unknown;\n has(key: string): boolean;\n toObject(): Record<string, unknown>;\n };\n };\n readonly derive?: Record<string, unknown>;\n read(key: string): unknown;\n inspect(): SystemInspection;\n}\n\n// ============================================================================\n// Requirements State\n// ============================================================================\n\n/**\n * Requirements state returned by useRequirements hooks.\n * Provides a focused view of just requirements without full inspection overhead.\n */\nexport interface RequirementsState {\n /** Array of unmet requirements waiting to be resolved */\n unmet: Array<{\n id: string;\n requirement: { type: string; [key: string]: unknown };\n fromConstraint: string;\n }>;\n /** Array of requirements currently being resolved */\n inflight: Array<{ id: string; resolverId: string; startedAt: number }>;\n /** Whether there are any unmet requirements */\n hasUnmet: boolean;\n /** Whether there are any inflight requirements */\n hasInflight: boolean;\n /** Whether the system is actively working (has unmet or inflight requirements) */\n isWorking: boolean;\n}\n\n// ============================================================================\n// Inspect State (shared across all adapters)\n// ============================================================================\n\n/**\n * Consolidated inspection state returned by useInspect hooks.\n * Identical shape across React, Vue, Svelte, Solid, and Lit adapters.\n */\nexport interface InspectState {\n /** Whether the system has settled (no pending operations) */\n isSettled: boolean;\n /** Array of unmet requirements */\n unmet: RequirementsState[\"unmet\"];\n /** Array of inflight requirements */\n inflight: RequirementsState[\"inflight\"];\n /** Whether the system is actively working */\n isWorking: boolean;\n /** Whether there are any unmet requirements */\n hasUnmet: boolean;\n /** Whether there are any inflight requirements */\n hasInflight: boolean;\n}\n\n/**\n * Information about a single constraint.\n */\nexport interface ConstraintInfo {\n id: string;\n active: boolean;\n priority: number;\n}\n\n/**\n * Compute InspectState from a system instance.\n * Centralizes the logic currently duplicated across adapters.\n * @internal\n */\nexport function computeInspectState(system: SystemLike): InspectState {\n const inspection = system.inspect();\n return {\n isSettled: system.isSettled,\n unmet: inspection.unmet,\n inflight: inspection.inflight,\n isWorking: inspection.unmet.length > 0 || inspection.inflight.length > 0,\n hasUnmet: inspection.unmet.length > 0,\n hasInflight: inspection.inflight.length > 0,\n };\n}\n\n// ============================================================================\n// Throttled Hook Options\n// ============================================================================\n\n/**\n * Options for throttled hooks.\n * Used by useInspectThrottled, useRequirementsThrottled, etc.\n */\nexport interface ThrottledHookOptions {\n /**\n * Minimum time between updates in milliseconds.\n * @default 100\n */\n throttleMs?: number;\n}\n\n// ============================================================================\n// Throttle Utility\n// ============================================================================\n\n/**\n * Create a throttled version of a callback function.\n * Uses trailing-edge throttling: the callback will be called at most once per interval,\n * with the latest arguments from the most recent call.\n *\n * @param callback - The function to throttle\n * @param ms - The minimum time between calls in milliseconds\n * @returns A throttled version of the callback and a cleanup function\n * @internal\n */\nexport function createThrottle<T extends (...args: unknown[]) => void>(\n callback: T,\n ms: number,\n): { throttled: T; cleanup: () => void } {\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n let lastArgs: Parameters<T> | null = null;\n let lastCallTime = 0;\n\n const throttled = ((...args: Parameters<T>) => {\n const now = Date.now();\n const timeSinceLastCall = now - lastCallTime;\n\n if (timeSinceLastCall >= ms) {\n // Enough time has passed, call immediately\n lastCallTime = now;\n callback(...args);\n } else {\n // Schedule for later, keeping latest args\n lastArgs = args;\n if (!timeoutId) {\n timeoutId = setTimeout(() => {\n timeoutId = null;\n lastCallTime = Date.now();\n if (lastArgs) {\n callback(...lastArgs);\n lastArgs = null;\n }\n }, ms - timeSinceLastCall);\n }\n }\n }) as T;\n\n const cleanup = () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n lastArgs = null;\n };\n\n return { throttled, cleanup };\n}\n\n// ============================================================================\n// Shared Adapter Helpers\n// ============================================================================\n\n/**\n * Dev-mode assertion that the system parameter is non-null.\n * Tree-shaken in production builds.\n * @internal\n */\nexport function assertSystem(hookName: string, system: unknown): void {\n if (process.env.NODE_ENV !== \"production\" && system == null) {\n throw new Error(\n `[Directive] ${hookName}() requires a system instance as the first argument. Received ${system}.`,\n );\n }\n}\n\n/** Default equality function using Object.is */\nexport function defaultEquality<T>(a: T, b: T): boolean {\n return Object.is(a, b);\n}\n\n/**\n * Build a HistoryState object from a system's history instance.\n * Returns null when history is disabled.\n * @internal\n */\nexport function buildHistoryState(system: SystemLike): HistoryState | null {\n const debug = system.history;\n if (!debug) return null;\n\n // Build lightweight metadata array (no facts data)\n const snapshots: SnapshotMeta[] = debug.snapshots.map((s) => ({\n id: s.id,\n timestamp: s.timestamp,\n trigger: s.trigger,\n }));\n\n return {\n // Navigation state\n canGoBack: debug.currentIndex > 0,\n canGoForward: debug.currentIndex < debug.snapshots.length - 1,\n currentIndex: debug.currentIndex,\n totalSnapshots: debug.snapshots.length,\n\n // Snapshot access\n snapshots,\n getSnapshotFacts: (id: number): Record<string, unknown> | null => {\n const snap = debug.snapshots.find((s) => s.id === id);\n return snap ? snap.facts : null;\n },\n\n // Navigation\n goTo: (snapshotId: number) => debug.goTo(snapshotId),\n goBack: (steps?: number) => debug.goBack(steps),\n goForward: (steps?: number) => debug.goForward(steps),\n replay: () => debug.replay(),\n\n // Session persistence\n exportSession: () => debug.export(),\n importSession: (json: string) => debug.import(json),\n\n // Changesets\n beginChangeset: (label: string) => debug.beginChangeset(label),\n endChangeset: () => debug.endChangeset(),\n\n // Recording control\n isPaused: debug.isPaused,\n pause: () => debug.pause(),\n resume: () => debug.resume(),\n };\n}\n\n/**\n * Pick specific fact values from a system's store.\n * @internal\n */\nexport function pickFacts(\n system: SystemLike,\n keys: string[],\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const key of keys) {\n result[key] = system.facts.$store.get(key);\n }\n return result;\n}\n\n// ============================================================================\n// Tracked Selector\n// ============================================================================\n\n/** Result of running a selector with tracking. @internal */\nexport interface TrackedSelectorResult<R> {\n value: R;\n factKeys: string[];\n deriveKeys: string[];\n}\n\n/**\n * Run a selector against a system with automatic dependency tracking.\n * Creates a Proxy that intercepts property access to distinguish between\n * fact reads (tracked via withTracking) and derivation reads (tracked manually).\n *\n * Used by useSelector in all framework adapters.\n * @internal\n */\nexport function runTrackedSelector<R>(\n system: SystemLike,\n deriveKeySet: Set<string>,\n selector: (state: Record<string, unknown>) => R,\n): TrackedSelectorResult<R> {\n const accessedDeriveKeys: string[] = [];\n\n const stateProxy = new Proxy(\n {},\n {\n get(_, prop: string | symbol) {\n if (typeof prop !== \"string\") return undefined;\n if (deriveKeySet.has(prop)) {\n accessedDeriveKeys.push(prop);\n return system.read(prop);\n }\n return system.facts.$store.get(prop);\n },\n has(_, prop: string | symbol) {\n if (typeof prop !== \"string\") return false;\n return deriveKeySet.has(prop) || system.facts.$store.has(prop);\n },\n ownKeys() {\n const factKeys = Object.keys(system.facts.$store.toObject());\n const combined = new Set(factKeys);\n for (const k of deriveKeySet) combined.add(k);\n return [...combined];\n },\n getOwnPropertyDescriptor() {\n return { configurable: true, enumerable: true, writable: true };\n },\n },\n );\n\n const { value, deps } = withTracking(() =>\n selector(stateProxy as Record<string, unknown>),\n );\n return {\n value,\n factKeys: Array.from(deps) as string[],\n deriveKeys: accessedDeriveKeys,\n };\n}\n\n/**\n * Check if tracked dependency keys have changed.\n * @internal\n */\nexport function depsChanged(\n prevFacts: string[],\n newFacts: string[],\n prevDerived: string[],\n newDerived: string[],\n): boolean {\n const factsChanged =\n newFacts.length !== prevFacts.length ||\n newFacts.some((k, i) => k !== prevFacts[i]);\n const derivedChanged =\n newDerived.length !== prevDerived.length ||\n newDerived.some((k, i) => k !== prevDerived[i]);\n return factsChanged || derivedChanged;\n}\n\n// ============================================================================\n// Re-exports from core/types/adapter-utils and utils/utils\n// ============================================================================\n\nexport {\n setBridgeFact,\n getBridgeFact,\n createCallbackPlugin,\n requirementGuard,\n requirementGuardMultiple,\n} from \"./core/types/adapter-utils.js\";\n\nexport { shallowEqual } from \"./utils/utils.js\";\n\n/**\n * Merge a DistributableSnapshot's data into initialFacts for SSR hydration.\n * Used by all framework adapters' hydration hooks/controllers.\n *\n * Accepts both shapes:\n * - DistributableSnapshot (`{ data: Record<string, unknown> }`) — used by React's DirectiveHydrator\n * - Plain `Record<string, unknown>` — used by Lit/Vue/Svelte/Solid adapters\n */\nexport function mergeHydrationFacts(\n snapshot:\n | { data?: Record<string, unknown> }\n | Record<string, unknown>\n | undefined\n | null,\n initialFacts?: Record<string, unknown>,\n): Record<string, unknown> {\n if (!snapshot) {\n return { ...initialFacts };\n }\n\n // If snapshot has a .data property that is a non-null object, treat as DistributableSnapshot\n const data =\n \"data\" in snapshot &&\n typeof snapshot.data === \"object\" &&\n snapshot.data !== null\n ? (snapshot.data as Record<string, unknown>)\n : (snapshot as Record<string, unknown>);\n\n return { ...initialFacts, ...data };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ async function w(n,i,o){let s,u=new Promise((g,d)=>{s=setTimeout(()=>d(new Error(o)),i);});try{return await Promise.race([n,u])}finally{clearTimeout(s);}}function p(n,i=50){let o=new WeakSet;function s(r){if(r===null)return "null";if(r===void 0)return "undefined";let e=typeof r;if(e==="string")return JSON.stringify(r);if(e==="number"||e==="boolean")return String(r);if(e==="function")return '"[function]"';if(e==="symbol")return '"[symbol]"'}function u(r,e){if(o.has(r))return '"[circular]"';o.add(r);let t=e();return o.delete(r),t}function g(r,e){return u(r,()=>`[${r.map(t=>c(t,e+1)).join(",")}]`)}function d(r,e){return u(r,()=>`{${Object.keys(r).sort().map(f=>`${JSON.stringify(f)}:${c(r[f],e+1)}`).join(",")}}`)}function c(r,e){if(e>i)return '"[max depth exceeded]"';let t=s(r);return t!==void 0?t:Array.isArray(r)?g(r,e):typeof r=="object"?d(r,e):'"[unknown]"'}return c(n,0)}function b(n,i=50){let o=new Set(["__proto__","constructor","prototype"]),s=new WeakSet;function u(r,e){if(s.has(r))return true;s.add(r);let t=e();return s.delete(r),t}function g(r,e){for(let t of r)if(!c(t,e+1))return false;return true}function d(r,e){for(let t of Object.keys(r))if(o.has(t)||!c(r[t],e+1))return false;return true}function c(r,e){if(e>i)return false;if(r==null||typeof r!="object")return true;let t=r;return Array.isArray(t)?u(t,()=>g(t,e)):u(t,()=>d(t,e))}return c(n,0)}function S(n,i){if(n===i)return true;if(!n||!i)return false;let o=Object.keys(n),s=Object.keys(i);if(o.length!==s.length)return false;for(let u of o)if(n[u]!==i[u])return false;return true}function A(n){let i=p(n),o=5381;for(let s=0;s<i.length;s++)o=(o<<5)+o^i.charCodeAt(s);return (o>>>0).toString(16)}function k(n,i=Date.now()){return n.expiresAt!==void 0&&i>n.expiresAt}function x(n,i=Date.now()){if(!n||typeof n!="object")throw new Error("[Directive] Invalid snapshot: expected an object with 'data' and 'createdAt' properties.");if(!("data"in n))throw new Error("[Directive] Invalid snapshot: missing required 'data' property.");if(!("createdAt"in n)||typeof n.createdAt!="number")throw new Error("[Directive] Invalid snapshot: missing or invalid 'createdAt' property (expected number).");if(k(n,i)){let o=new Date(n.expiresAt).toISOString();throw new Error(`[Directive] Snapshot expired at ${o}. Obtain a fresh snapshot from the source.`)}return n.data}function T(n,i){let o=[];function s(e,t,a,f){o.push({path:e,oldValue:t,newValue:a,type:f});}function u(e,t,a){return e==null?(t!=null&&s(a,e,t,"added"),true):t==null?(s(a,e,t,"removed"),true):false}function g(e,t,a){if(e.length!==t.length){s(a,e,t,"changed");return}for(let f=0;f<e.length;f++)c(e[f],t[f],`${a}[${f}]`);}function d(e,t,a){let f=new Set([...Object.keys(e),...Object.keys(t)]);for(let y of f){let l=a?`${a}.${y}`:y;y in e?y in t?c(e[y],t[y],l):s(l,e[y],void 0,"removed"):s(l,void 0,t[y],"added");}}function c(e,t,a){if(!u(e,t,a)){if(typeof e!="object"||typeof t!="object"){Object.is(e,t)||s(a,e,t,"changed");return}if(Array.isArray(e)&&Array.isArray(t)){g(e,t,a);return}d(e,t,a);}}c(n.data,i.data,"");let r=n.version!==i.version&&(n.version!==void 0||i.version!==void 0);return {identical:o.length===0,changes:o,versionChanged:r,oldVersion:n.version,newVersion:i.version}}function D(n){return "signature"in n&&typeof n.signature=="string"}async function v(n,i){let o=p({data:n.data,createdAt:n.createdAt,expiresAt:n.expiresAt,version:n.version,metadata:n.metadata}),s=await m(o,i);return {...n,signature:s,algorithm:"hmac-sha256"}}async function E(n,i){if(!n.signature||n.algorithm!=="hmac-sha256")return false;let o=p({data:n.data,createdAt:n.createdAt,expiresAt:n.expiresAt,version:n.version,metadata:n.metadata}),s=await m(o,i);return h(n.signature,s)}async function m(n,i){let o=typeof i=="string"?new TextEncoder().encode(i):i,s={name:"HMAC",hash:{name:"SHA-256"}},u=await crypto.subtle.importKey("raw",o,s,false,["sign"]),g=new TextEncoder().encode(n),d=await crypto.subtle.sign("HMAC",u,g);return Array.from(new Uint8Array(d)).map(c=>c.toString(16).padStart(2,"0")).join("")}function h(n,i){if(n.length!==i.length)return false;let o=0;for(let s=0;s<n.length;s++)o|=n.charCodeAt(s)^i.charCodeAt(s);return o===0}function P(n,i=500){try{let o=JSON.stringify(n,(s,u)=>typeof u=="bigint"?`${u}n`:u,2);return o?o.length<=i?o:`${o.slice(0,i)}
2
+ ... (truncated, ${o.length} chars total)`:"[undefined]"}catch{return "[unserializable]"}}export{w as a,p as b,b as c,S as d,A as e,k as f,x as g,T as h,D as i,v as j,E as k,P as l};//# sourceMappingURL=chunk-4CMO5OVZ.js.map
3
+ //# sourceMappingURL=chunk-4CMO5OVZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/utils.ts"],"names":["withTimeout","promise","ms","errorMessage","timeoutId","timeoutPromise","_","reject","stableStringify","value","maxDepth","seen","stringifyPrimitive","val","type","withCircularGuard","obj","fn","result","stringifyArray","depth","v","stringify","stringifyObject","k","primitive","isPrototypeSafe","dangerousKeys","objVal","checkArray","arr","item","check","checkObject","key","shallowEqual","a","b","keysA","keysB","hashObject","str","hash","i","isSnapshotExpired","snapshot","now","validateSnapshot","expiredAt","diffSnapshots","oldSnapshot","newSnapshot","changes","pushChange","path","oldValue","newValue","compareNullish","oldObj","newObj","compareArrays","oldArr","newArr","compare","compareObjects","oldRecord","newRecord","allKeys","childPath","versionChanged","isSignedSnapshot","signSnapshot","secret","payload","signature","hmacSha256","verifySnapshotSignature","signedSnapshot","expectedSignature","timingSafeEqual","message","secretBytes","algorithm","messageBytes","safeStringify","data","maxLen","_key"],"mappings":"AAcA,eAAsBA,CAAAA,CACpBC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACY,CACZ,IAAIC,CAAAA,CAEEC,CAAAA,CAAiB,IAAI,OAAA,CAAe,CAACC,CAAAA,CAAGC,CAAAA,GAAW,CACvDH,CAAAA,CAAY,UAAA,CAAW,IAAMG,CAAAA,CAAO,IAAI,KAAA,CAAMJ,CAAY,CAAC,CAAA,CAAGD,CAAE,EAClE,CAAC,CAAA,CAED,GAAI,CACF,OAAO,MAAM,OAAA,CAAQ,IAAA,CAAK,CAACD,CAAAA,CAASI,CAAc,CAAC,CACrD,CAAA,OAAE,CACA,YAAA,CAAaD,CAAU,EACzB,CACF,CAwBO,SAASI,CAAAA,CAAgBC,CAAAA,CAAgBC,CAAAA,CAAW,EAAA,CAAY,CACrE,IAAMC,CAAAA,CAAO,IAAI,OAAA,CAGjB,SAASC,CAAAA,CAAmBC,CAAAA,CAAkC,CAC5D,GAAIA,CAAAA,GAAQ,KAAM,OAAO,MAAA,CACzB,GAAIA,CAAAA,GAAQ,MAAA,CAAW,OAAO,WAAA,CAE9B,IAAMC,CAAAA,CAAO,OAAOD,CAAAA,CACpB,GAAIC,CAAAA,GAAS,QAAA,CAAU,OAAO,IAAA,CAAK,SAAA,CAAUD,CAAG,CAAA,CAChD,GAAIC,CAAAA,GAAS,QAAA,EAAYA,CAAAA,GAAS,SAAA,CAAW,OAAO,MAAA,CAAOD,CAAG,CAAA,CAC9D,GAAIC,CAAAA,GAAS,UAAA,CAAY,OAAO,eAChC,GAAIA,CAAAA,GAAS,QAAA,CAAU,OAAO,YAGhC,CAGA,SAASC,CAAAA,CACPC,CAAAA,CACAC,CAAAA,CACQ,CACR,GAAIN,CAAAA,CAAK,GAA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F,IAAM7C,CAAAA,CAAM,IAAA,CAAK,SAAA,CACf4C,CAAAA,CACA,CAACE,CAAAA,CAAM9E,CAAAA,GACD,OAAOA,CAAAA,EAAU,SACZ,CAAA,EAAGA,CAAK,CAAA,CAAA,CAAA,CAGVA,CAAAA,CAET,CACF,CAAA,CACA,OAAKgC,CAAAA,CAGDA,CAAAA,CAAI,MAAA,EAAU6C,CAAAA,CACT7C,CAAAA,CAGF,CAAA,EAAGA,CAAAA,CAAI,KAAA,CAAM,CAAA,CAAG6C,CAAM,CAAC;AAAA,gBAAA,EAAqB7C,CAAAA,CAAI,MAAM,CAAA,aAAA,CAAA,CANpD,aAOX,MAAQ,CACN,OAAO,kBACT,CACF","file":"chunk-4CMO5OVZ.js","sourcesContent":["/**\n * Shared utilities for Directive\n */\n\n/**\n * Execute a promise with a timeout, properly cleaning up the timer.\n * Used by both constraints and resolvers for timeout handling.\n *\n * @param promise - The promise to wrap with a timeout\n * @param ms - Timeout duration in milliseconds\n * @param errorMessage - Error message if timeout occurs\n * @returns The promise result\n * @throws Error if timeout is exceeded\n */\nexport async function withTimeout<T>(\n promise: Promise<T>,\n ms: number,\n errorMessage: string,\n): Promise<T> {\n let timeoutId: ReturnType<typeof setTimeout>;\n\n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutId = setTimeout(() => reject(new Error(errorMessage)), ms);\n });\n\n try {\n return await Promise.race([promise, timeoutPromise]);\n } finally {\n clearTimeout(timeoutId!);\n }\n}\n\n/**\n * Normalize an error to an Error instance.\n * Ensures consistent error handling throughout the library.\n *\n * @param error - The error to normalize (can be anything)\n * @returns An Error instance\n */\nexport function normalizeError(error: unknown): Error {\n if (error instanceof Error) {\n return error;\n }\n return new Error(String(error));\n}\n\n/**\n * Create a stable JSON string with sorted keys.\n * Handles circular references and deeply nested objects safely.\n *\n * @param value - The value to stringify\n * @param maxDepth - Maximum nesting depth (default: 50)\n * @returns A stable JSON string\n */\nexport function stableStringify(value: unknown, maxDepth = 50): string {\n const seen = new WeakSet();\n\n /** Stringify a primitive value (null, undefined, string, number, boolean, function, symbol). */\n function stringifyPrimitive(val: unknown): string | undefined {\n if (val === null) return \"null\";\n if (val === undefined) return \"undefined\";\n\n const type = typeof val;\n if (type === \"string\") return JSON.stringify(val);\n if (type === \"number\" || type === \"boolean\") return String(val);\n if (type === \"function\") return '\"[function]\"';\n if (type === \"symbol\") return '\"[symbol]\"';\n\n return undefined;\n }\n\n /** Guard against circular references using a seen-set, then delegate to fn. */\n function withCircularGuard(\n obj: object,\n fn: () => string,\n ): string {\n if (seen.has(obj)) {\n return '\"[circular]\"';\n }\n seen.add(obj);\n const result = fn();\n seen.delete(obj);\n\n return result;\n }\n\n /** Stringify an array with circular reference protection. */\n function stringifyArray(val: unknown[], depth: number): string {\n return withCircularGuard(val, () =>\n `[${val.map((v) => stringify(v, depth + 1)).join(\",\")}]`,\n );\n }\n\n /** Stringify an object with sorted keys and circular reference protection. */\n function stringifyObject(obj: Record<string, unknown>, depth: number): string {\n return withCircularGuard(obj, () => {\n const keys = Object.keys(obj).sort();\n const pairs = keys.map(\n (k) => `${JSON.stringify(k)}:${stringify(obj[k], depth + 1)}`,\n );\n\n return `{${pairs.join(\",\")}}`;\n });\n }\n\n /** Recursively stringify a value with depth limit and circular detection. */\n function stringify(val: unknown, depth: number): string {\n if (depth > maxDepth) {\n return '\"[max depth exceeded]\"';\n }\n\n const primitive = stringifyPrimitive(val);\n if (primitive !== undefined) {\n return primitive;\n }\n\n if (Array.isArray(val)) {\n return stringifyArray(val, depth);\n }\n\n if (typeof val === \"object\") {\n return stringifyObject(val as Record<string, unknown>, depth);\n }\n\n return '\"[unknown]\"';\n }\n\n return stringify(value, 0);\n}\n\n/**\n * Check for prototype pollution in an object, including nested objects.\n * Returns true if the object is safe, false if dangerous keys are found.\n *\n * @param obj - The object to check\n * @param maxDepth - Maximum nesting depth to check (default: 50)\n * @returns True if safe, false if dangerous keys found\n */\nexport function isPrototypeSafe(obj: unknown, maxDepth = 50): boolean {\n const dangerousKeys = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n const seen = new WeakSet();\n\n /** Guard against circular references using a seen-set, then delegate to fn. */\n function withCircularGuard(\n objVal: object,\n fn: () => boolean,\n ): boolean {\n if (seen.has(objVal)) return true;\n seen.add(objVal);\n const result = fn();\n seen.delete(objVal);\n\n return result;\n }\n\n /** Check array elements for prototype pollution keys. */\n function checkArray(arr: unknown[], depth: number): boolean {\n for (const item of arr) {\n if (!check(item, depth + 1)) {\n return false;\n }\n }\n\n return true;\n }\n\n /** Check object keys and values for prototype pollution. */\n function checkObject(objVal: Record<string, unknown>, depth: number): boolean {\n for (const key of Object.keys(objVal)) {\n if (dangerousKeys.has(key)) {\n return false;\n }\n if (!check(objVal[key], depth + 1)) {\n return false;\n }\n }\n\n return true;\n }\n\n /** Recursively check a value tree for dangerous prototype keys. */\n function check(val: unknown, depth: number): boolean {\n if (depth > maxDepth) return false; // Fail safe at max depth - don't assume safety\n if (val === null || val === undefined) return true;\n if (typeof val !== \"object\") return true;\n\n const objVal = val as Record<string, unknown>;\n\n if (Array.isArray(objVal)) {\n return withCircularGuard(objVal, () => checkArray(objVal, depth));\n }\n\n return withCircularGuard(objVal, () => checkObject(objVal, depth));\n }\n\n return check(obj, 0);\n}\n\n/**\n * Shallow equality comparison for objects.\n * Used by React hooks to avoid unnecessary re-renders.\n *\n * @param a - First object\n * @param b - Second object\n * @returns True if objects are shallowly equal\n */\nexport function shallowEqual<T extends Record<string, unknown>>(\n a: T,\n b: T,\n): boolean {\n if (a === b) return true;\n if (!a || !b) return false;\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (a[key] !== b[key]) return false;\n }\n\n return true;\n}\n\n/**\n * Generate a simple hash string from an object.\n * Uses djb2 algorithm on the stable stringified value.\n *\n * **Limitations:**\n * - 32-bit hash output means collision probability increases with data set size\n * (birthday paradox: ~50% collision chance at ~77,000 distinct values)\n * - Suitable for: cache invalidation, change detection, deduplication of small sets\n * - NOT suitable for: cryptographic use, security-sensitive operations, large-scale deduplication\n *\n * For security-sensitive use cases requiring stronger collision resistance,\n * consider using a cryptographic hash like SHA-256.\n *\n * @param value - The value to hash\n * @returns A hex hash string (8 characters, 32 bits)\n */\nexport function hashObject(value: unknown): string {\n const str = stableStringify(value);\n let hash = 5381;\n for (let i = 0; i < str.length; i++) {\n hash = ((hash << 5) + hash) ^ str.charCodeAt(i);\n }\n // Convert to unsigned 32-bit and then to hex\n return (hash >>> 0).toString(16);\n}\n\n// ============================================================================\n// Distributable Snapshot Utilities\n// ============================================================================\n\n/**\n * Distributable snapshot type for type-safe helper functions.\n */\nexport interface DistributableSnapshotLike<T = Record<string, unknown>> {\n data: T;\n createdAt: number;\n expiresAt?: number;\n version?: string;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Check if a distributable snapshot has expired.\n * Returns false if the snapshot has no expiresAt field.\n *\n * @example\n * ```typescript\n * const snapshot = system.getDistributableSnapshot({ ttlSeconds: 3600 });\n * // ... later ...\n * if (isSnapshotExpired(snapshot)) {\n * // Refresh the snapshot\n * }\n * ```\n *\n * @param snapshot - The snapshot to check\n * @param now - Optional current timestamp (defaults to Date.now())\n * @returns True if the snapshot has expired, false otherwise\n */\nexport function isSnapshotExpired<T>(\n snapshot: DistributableSnapshotLike<T>,\n now: number = Date.now(),\n): boolean {\n return snapshot.expiresAt !== undefined && now > snapshot.expiresAt;\n}\n\n/**\n * Validate a distributable snapshot and return its data.\n * Throws if the snapshot is malformed or has expired.\n *\n * @example\n * ```typescript\n * const cached = JSON.parse(await redis.get(`entitlements:${userId}`));\n * try {\n * const data = validateSnapshot(cached);\n * // Use data.canUseFeature, etc.\n * } catch (e) {\n * // Snapshot invalid or expired, refresh it\n * }\n * ```\n *\n * @example Using custom timestamp for testing\n * ```typescript\n * const snapshot = { data: { test: true }, createdAt: 1000, expiresAt: 2000 };\n * validateSnapshot(snapshot, 1500); // Returns { test: true }\n * validateSnapshot(snapshot, 2500); // Throws: Snapshot expired\n * ```\n *\n * @param snapshot - The snapshot to validate\n * @param now - Optional current timestamp (defaults to Date.now())\n * @returns The snapshot data if valid\n * @throws Error if the snapshot is malformed or has expired\n */\nexport function validateSnapshot<T>(\n snapshot: DistributableSnapshotLike<T>,\n now: number = Date.now(),\n): T {\n // Structural validation\n if (!snapshot || typeof snapshot !== \"object\") {\n throw new Error(\n \"[Directive] Invalid snapshot: expected an object with 'data' and 'createdAt' properties.\",\n );\n }\n if (!(\"data\" in snapshot)) {\n throw new Error(\n \"[Directive] Invalid snapshot: missing required 'data' property.\",\n );\n }\n if (!(\"createdAt\" in snapshot) || typeof snapshot.createdAt !== \"number\") {\n throw new Error(\n \"[Directive] Invalid snapshot: missing or invalid 'createdAt' property (expected number).\",\n );\n }\n\n // Expiration validation\n if (isSnapshotExpired(snapshot, now)) {\n const expiredAt = new Date(snapshot.expiresAt!).toISOString();\n throw new Error(\n `[Directive] Snapshot expired at ${expiredAt}. Obtain a fresh snapshot from the source.`,\n );\n }\n return snapshot.data;\n}\n\n/**\n * Diff result for a single changed value.\n */\nexport interface SnapshotDiffEntry {\n /** The key path that changed (e.g., \"canUseApi\" or \"limits.apiCalls\") */\n path: string;\n /** The value in the old snapshot */\n oldValue: unknown;\n /** The value in the new snapshot */\n newValue: unknown;\n /** Type of change: \"added\", \"removed\", or \"changed\" */\n type: \"added\" | \"removed\" | \"changed\";\n}\n\n/**\n * Result of diffing two snapshots.\n */\nexport interface SnapshotDiff {\n /** Whether the snapshots are identical */\n identical: boolean;\n /** List of changes between snapshots */\n changes: SnapshotDiffEntry[];\n /** Whether the version changed (if both have versions) */\n versionChanged: boolean;\n /** Old version (if available) */\n oldVersion?: string;\n /** New version (if available) */\n newVersion?: string;\n}\n\n/**\n * Compare two distributable snapshots and return the differences.\n * Useful for debugging, audit logs, and webhook payloads.\n *\n * @example\n * ```typescript\n * const oldSnapshot = system.getDistributableSnapshot({ includeVersion: true });\n * system.dispatch({ type: \"upgradePlan\", plan: \"pro\" });\n * const newSnapshot = system.getDistributableSnapshot({ includeVersion: true });\n *\n * const diff = diffSnapshots(oldSnapshot, newSnapshot);\n * if (!diff.identical) {\n * console.log(\"Changes:\", diff.changes);\n * // [{ path: \"canUseApi\", oldValue: false, newValue: true, type: \"changed\" }]\n * }\n * ```\n *\n * @param oldSnapshot - The previous snapshot\n * @param newSnapshot - The new snapshot\n * @returns A diff result with all changes\n */\nexport function diffSnapshots<T = Record<string, unknown>>(\n oldSnapshot: DistributableSnapshotLike<T>,\n newSnapshot: DistributableSnapshotLike<T>,\n): SnapshotDiff {\n const changes: SnapshotDiffEntry[] = [];\n\n /** Push a change entry to the diff results. */\n function pushChange(\n path: string,\n oldValue: unknown,\n newValue: unknown,\n type: SnapshotDiffEntry[\"type\"],\n ): void {\n changes.push({ path, oldValue, newValue, type });\n }\n\n /** Handle null/undefined comparison cases. Returns true if fully handled. */\n function compareNullish(\n oldObj: unknown,\n newObj: unknown,\n path: string,\n ): boolean {\n if (oldObj === null || oldObj === undefined) {\n if (newObj !== null && newObj !== undefined) {\n pushChange(path, oldObj, newObj, \"added\");\n }\n\n return true;\n }\n if (newObj === null || newObj === undefined) {\n pushChange(path, oldObj, newObj, \"removed\");\n\n return true;\n }\n\n return false;\n }\n\n /** Compare two arrays element by element, recursing into each. */\n function compareArrays(\n oldArr: unknown[],\n newArr: unknown[],\n path: string,\n ): void {\n if (oldArr.length !== newArr.length) {\n pushChange(path, oldArr, newArr, \"changed\");\n\n return;\n }\n for (let i = 0; i < oldArr.length; i++) {\n compare(oldArr[i], newArr[i], `${path}[${i}]`);\n }\n }\n\n /** Compare two objects by key union, detecting added/removed/changed. */\n function compareObjects(\n oldRecord: Record<string, unknown>,\n newRecord: Record<string, unknown>,\n path: string,\n ): void {\n const allKeys = new Set([\n ...Object.keys(oldRecord),\n ...Object.keys(newRecord),\n ]);\n\n for (const key of allKeys) {\n const childPath = path ? `${path}.${key}` : key;\n if (!(key in oldRecord)) {\n pushChange(childPath, undefined, newRecord[key], \"added\");\n } else if (!(key in newRecord)) {\n pushChange(childPath, oldRecord[key], undefined, \"removed\");\n } else {\n compare(oldRecord[key], newRecord[key], childPath);\n }\n }\n }\n\n /** Recursively compare two values and record differences. */\n function compare(oldObj: unknown, newObj: unknown, path: string): void {\n if (compareNullish(oldObj, newObj, path)) {\n return;\n }\n\n // Handle primitives\n if (typeof oldObj !== \"object\" || typeof newObj !== \"object\") {\n if (!Object.is(oldObj, newObj)) {\n pushChange(path, oldObj, newObj, \"changed\");\n }\n\n return;\n }\n\n // Handle arrays\n if (Array.isArray(oldObj) && Array.isArray(newObj)) {\n compareArrays(oldObj, newObj, path);\n\n return;\n }\n\n // Handle objects\n compareObjects(\n oldObj as Record<string, unknown>,\n newObj as Record<string, unknown>,\n path,\n );\n }\n\n // Compare data\n compare(oldSnapshot.data, newSnapshot.data, \"\");\n\n // Check version change\n const versionChanged =\n oldSnapshot.version !== newSnapshot.version &&\n (oldSnapshot.version !== undefined || newSnapshot.version !== undefined);\n\n return {\n identical: changes.length === 0,\n changes,\n versionChanged,\n oldVersion: oldSnapshot.version,\n newVersion: newSnapshot.version,\n };\n}\n\n// ============================================================================\n// Snapshot Signing (HMAC)\n// ============================================================================\n\n/**\n * A signed distributable snapshot.\n * Contains the original snapshot plus a cryptographic signature.\n */\nexport interface SignedSnapshot<T = Record<string, unknown>>\n extends DistributableSnapshotLike<T> {\n /** HMAC-SHA256 signature in hex format */\n signature: string;\n /** Signing algorithm used */\n algorithm: \"hmac-sha256\";\n}\n\n/**\n * Check if a snapshot is signed.\n *\n * @param snapshot - The snapshot to check\n * @returns True if the snapshot has a signature\n */\nexport function isSignedSnapshot<T>(\n snapshot: DistributableSnapshotLike<T> | SignedSnapshot<T>,\n): snapshot is SignedSnapshot<T> {\n return \"signature\" in snapshot && typeof snapshot.signature === \"string\";\n}\n\n/**\n * Sign a distributable snapshot using HMAC-SHA256.\n * Creates a tamper-proof signature that can be verified later.\n *\n * **Security Notes:**\n * - Use a cryptographically random secret of at least 32 bytes\n * - Store the secret securely (environment variable, secrets manager)\n * - Never expose the secret to clients\n * - The signature covers all snapshot fields for integrity\n *\n * @example\n * ```typescript\n * const snapshot = system.getDistributableSnapshot({\n * includeDerivations: ['canUseFeature', 'limits'],\n * ttlSeconds: 3600,\n * });\n *\n * // Sign the snapshot (server-side only)\n * const signed = await signSnapshot(snapshot, process.env.SNAPSHOT_SECRET);\n *\n * // Store in JWT, Redis, or send to client\n * const jwt = createJWT({ snapshot: signed });\n *\n * // Later, verify the signature\n * const isValid = await verifySnapshotSignature(signed, process.env.SNAPSHOT_SECRET);\n * if (!isValid) {\n * throw new Error('Snapshot has been tampered with');\n * }\n * ```\n *\n * @param snapshot - The snapshot to sign\n * @param secret - The HMAC secret (string or Uint8Array)\n * @returns A signed snapshot with the signature attached\n */\nexport async function signSnapshot<T>(\n snapshot: DistributableSnapshotLike<T>,\n secret: string | Uint8Array,\n): Promise<SignedSnapshot<T>> {\n // Create a canonical representation for signing\n const payload = stableStringify({\n data: snapshot.data,\n createdAt: snapshot.createdAt,\n expiresAt: snapshot.expiresAt,\n version: snapshot.version,\n metadata: snapshot.metadata,\n });\n\n const signature = await hmacSha256(payload, secret);\n\n return {\n ...snapshot,\n signature,\n algorithm: \"hmac-sha256\",\n };\n}\n\n/**\n * Verify the signature of a signed snapshot.\n * Returns true if the signature is valid, false otherwise.\n *\n * **Important:** Always verify signatures before trusting snapshot data,\n * especially if the snapshot was received from an untrusted source (client, cache).\n *\n * @example\n * ```typescript\n * // Receive signed snapshot from client or cache\n * const snapshot = JSON.parse(cachedData);\n *\n * // Verify before using\n * const isValid = await verifySnapshotSignature(snapshot, process.env.SNAPSHOT_SECRET);\n * if (!isValid) {\n * throw new Error('Invalid snapshot signature - possible tampering');\n * }\n *\n * // Now safe to use snapshot.data\n * if (snapshot.data.canUseFeature.api) {\n * // Grant access\n * }\n * ```\n *\n * @param signedSnapshot - The signed snapshot to verify\n * @param secret - The HMAC secret (must match the signing secret)\n * @returns True if signature is valid, false otherwise\n */\nexport async function verifySnapshotSignature<T>(\n signedSnapshot: SignedSnapshot<T>,\n secret: string | Uint8Array,\n): Promise<boolean> {\n if (!signedSnapshot.signature || signedSnapshot.algorithm !== \"hmac-sha256\") {\n return false;\n }\n\n // Recreate the canonical payload (same as signing)\n const payload = stableStringify({\n data: signedSnapshot.data,\n createdAt: signedSnapshot.createdAt,\n expiresAt: signedSnapshot.expiresAt,\n version: signedSnapshot.version,\n metadata: signedSnapshot.metadata,\n });\n\n const expectedSignature = await hmacSha256(payload, secret);\n\n // Use timing-safe comparison\n return timingSafeEqual(signedSnapshot.signature, expectedSignature);\n}\n\n/**\n * Create HMAC-SHA256 signature of a message.\n * Uses Web Crypto API for cross-platform support (Node.js, browsers, Deno, Bun).\n */\nasync function hmacSha256(\n message: string,\n secret: string | Uint8Array,\n): Promise<string> {\n // Convert secret to Uint8Array if string\n const secretBytes: Uint8Array =\n typeof secret === \"string\" ? new TextEncoder().encode(secret) : secret;\n\n // Import key for HMAC\n const algorithm: HmacImportParams = {\n name: \"HMAC\",\n hash: { name: \"SHA-256\" },\n };\n const key = await crypto.subtle.importKey(\n \"raw\",\n secretBytes as unknown as ArrayBuffer,\n algorithm,\n false,\n [\"sign\"],\n );\n\n // Sign the message\n const messageBytes = new TextEncoder().encode(message);\n const signature = await crypto.subtle.sign(\"HMAC\", key, messageBytes);\n\n // Convert to hex string\n return Array.from(new Uint8Array(signature))\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Timing-safe string comparison to prevent timing attacks.\n * Both strings should be the same length (hex signatures from same algorithm).\n */\nfunction timingSafeEqual(a: string, b: string): boolean {\n if (a.length !== b.length) {\n return false;\n }\n\n let result = 0;\n for (let i = 0; i < a.length; i++) {\n result |= a.charCodeAt(i) ^ b.charCodeAt(i);\n }\n return result === 0;\n}\n\n/**\n * Safely stringify any value for display. Handles circular references,\n * BigInt, throwing toJSON, and optional truncation.\n *\n * This is the canonical implementation – all packages should import this\n * instead of maintaining local copies.\n */\nexport function safeStringify(\n data: unknown,\n maxLen = 500,\n): string {\n try {\n const str = JSON.stringify(\n data,\n (_key, value) => {\n if (typeof value === \"bigint\") {\n return `${value}n`;\n }\n\n return value;\n },\n 2,\n );\n if (!str) {\n return \"[undefined]\";\n }\n if (str.length <= maxLen) {\n return str;\n }\n\n return `${str.slice(0, maxLen)}\\n... (truncated, ${str.length} chars total)`;\n } catch {\n return \"[unserializable]\";\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ 'use strict';async function w(n,i,o){let s,u=new Promise((g,d)=>{s=setTimeout(()=>d(new Error(o)),i);});try{return await Promise.race([n,u])}finally{clearTimeout(s);}}function p(n,i=50){let o=new WeakSet;function s(r){if(r===null)return "null";if(r===void 0)return "undefined";let e=typeof r;if(e==="string")return JSON.stringify(r);if(e==="number"||e==="boolean")return String(r);if(e==="function")return '"[function]"';if(e==="symbol")return '"[symbol]"'}function u(r,e){if(o.has(r))return '"[circular]"';o.add(r);let t=e();return o.delete(r),t}function g(r,e){return u(r,()=>`[${r.map(t=>c(t,e+1)).join(",")}]`)}function d(r,e){return u(r,()=>`{${Object.keys(r).sort().map(f=>`${JSON.stringify(f)}:${c(r[f],e+1)}`).join(",")}}`)}function c(r,e){if(e>i)return '"[max depth exceeded]"';let t=s(r);return t!==void 0?t:Array.isArray(r)?g(r,e):typeof r=="object"?d(r,e):'"[unknown]"'}return c(n,0)}function b(n,i=50){let o=new Set(["__proto__","constructor","prototype"]),s=new WeakSet;function u(r,e){if(s.has(r))return true;s.add(r);let t=e();return s.delete(r),t}function g(r,e){for(let t of r)if(!c(t,e+1))return false;return true}function d(r,e){for(let t of Object.keys(r))if(o.has(t)||!c(r[t],e+1))return false;return true}function c(r,e){if(e>i)return false;if(r==null||typeof r!="object")return true;let t=r;return Array.isArray(t)?u(t,()=>g(t,e)):u(t,()=>d(t,e))}return c(n,0)}function S(n,i){if(n===i)return true;if(!n||!i)return false;let o=Object.keys(n),s=Object.keys(i);if(o.length!==s.length)return false;for(let u of o)if(n[u]!==i[u])return false;return true}function A(n){let i=p(n),o=5381;for(let s=0;s<i.length;s++)o=(o<<5)+o^i.charCodeAt(s);return (o>>>0).toString(16)}function k(n,i=Date.now()){return n.expiresAt!==void 0&&i>n.expiresAt}function x(n,i=Date.now()){if(!n||typeof n!="object")throw new Error("[Directive] Invalid snapshot: expected an object with 'data' and 'createdAt' properties.");if(!("data"in n))throw new Error("[Directive] Invalid snapshot: missing required 'data' property.");if(!("createdAt"in n)||typeof n.createdAt!="number")throw new Error("[Directive] Invalid snapshot: missing or invalid 'createdAt' property (expected number).");if(k(n,i)){let o=new Date(n.expiresAt).toISOString();throw new Error(`[Directive] Snapshot expired at ${o}. Obtain a fresh snapshot from the source.`)}return n.data}function T(n,i){let o=[];function s(e,t,a,f){o.push({path:e,oldValue:t,newValue:a,type:f});}function u(e,t,a){return e==null?(t!=null&&s(a,e,t,"added"),true):t==null?(s(a,e,t,"removed"),true):false}function g(e,t,a){if(e.length!==t.length){s(a,e,t,"changed");return}for(let f=0;f<e.length;f++)c(e[f],t[f],`${a}[${f}]`);}function d(e,t,a){let f=new Set([...Object.keys(e),...Object.keys(t)]);for(let y of f){let l=a?`${a}.${y}`:y;y in e?y in t?c(e[y],t[y],l):s(l,e[y],void 0,"removed"):s(l,void 0,t[y],"added");}}function c(e,t,a){if(!u(e,t,a)){if(typeof e!="object"||typeof t!="object"){Object.is(e,t)||s(a,e,t,"changed");return}if(Array.isArray(e)&&Array.isArray(t)){g(e,t,a);return}d(e,t,a);}}c(n.data,i.data,"");let r=n.version!==i.version&&(n.version!==void 0||i.version!==void 0);return {identical:o.length===0,changes:o,versionChanged:r,oldVersion:n.version,newVersion:i.version}}function D(n){return "signature"in n&&typeof n.signature=="string"}async function v(n,i){let o=p({data:n.data,createdAt:n.createdAt,expiresAt:n.expiresAt,version:n.version,metadata:n.metadata}),s=await m(o,i);return {...n,signature:s,algorithm:"hmac-sha256"}}async function E(n,i){if(!n.signature||n.algorithm!=="hmac-sha256")return false;let o=p({data:n.data,createdAt:n.createdAt,expiresAt:n.expiresAt,version:n.version,metadata:n.metadata}),s=await m(o,i);return h(n.signature,s)}async function m(n,i){let o=typeof i=="string"?new TextEncoder().encode(i):i,s={name:"HMAC",hash:{name:"SHA-256"}},u=await crypto.subtle.importKey("raw",o,s,false,["sign"]),g=new TextEncoder().encode(n),d=await crypto.subtle.sign("HMAC",u,g);return Array.from(new Uint8Array(d)).map(c=>c.toString(16).padStart(2,"0")).join("")}function h(n,i){if(n.length!==i.length)return false;let o=0;for(let s=0;s<n.length;s++)o|=n.charCodeAt(s)^i.charCodeAt(s);return o===0}function P(n,i=500){try{let o=JSON.stringify(n,(s,u)=>typeof u=="bigint"?`${u}n`:u,2);return o?o.length<=i?o:`${o.slice(0,i)}
2
+ ... (truncated, ${o.length} chars total)`:"[undefined]"}catch{return "[unserializable]"}}exports.a=w;exports.b=p;exports.c=b;exports.d=S;exports.e=A;exports.f=k;exports.g=x;exports.h=T;exports.i=D;exports.j=v;exports.k=E;exports.l=P;//# sourceMappingURL=chunk-BEJ6ICA7.cjs.map
3
+ //# sourceMappingURL=chunk-BEJ6ICA7.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/utils.ts"],"names":["withTimeout","promise","ms","errorMessage","timeoutId","timeoutPromise","_","reject","stableStringify","value","maxDepth","seen","stringifyPrimitive","val","type","withCircularGuard","obj","fn","result","stringifyArray","depth","v","stringify","stringifyObject","k","primitive","isPrototypeSafe","dangerousKeys","objVal","checkArray","arr","item","check","checkObject","key","shallowEqual","a","b","keysA","keysB","hashObject","str","hash","i","isSnapshotExpired","snapshot","now","validateSnapshot","expiredAt","diffSnapshots","oldSnapshot","newSnapshot","changes","pushChange","path","oldValue","newValue","compareNullish","oldObj","newObj","compareArrays","oldArr","newArr","compare","compareObjects","oldRecord","newRecord","allKeys","childPath","versionChanged","isSignedSnapshot","signSnapshot","secret","payload","signature","hmacSha256","verifySnapshotSignature","signedSnapshot","expectedSignature","timingSafeEqual","message","secretBytes","algorithm","messageBytes","safeStringify","data","maxLen","_key"],"mappings":"aAcA,eAAsBA,CAAAA,CACpBC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACY,CACZ,IAAIC,CAAAA,CAEEC,CAAAA,CAAiB,IAAI,OAAA,CAAe,CAACC,CAAAA,CAAGC,CAAAA,GAAW,CACvDH,CAAAA,CAAY,UAAA,CAAW,IAAMG,CAAAA,CAAO,IAAI,KAAA,CAAMJ,CAAY,CAAC,CAAA,CAAGD,CAAE,EAClE,CAAC,CAAA,CAED,GAAI,CACF,OAAO,MAAM,OAAA,CAAQ,IAAA,CAAK,CAACD,CAAAA,CAASI,CAAc,CAAC,CACrD,CAAA,OAAE,CACA,YAAA,CAAaD,CAAU,EACzB,CACF,CAwBO,SAASI,CAAAA,CAAgBC,CAAAA,CAAgBC,CAAAA,CAAW,EAAA,CAAY,CACrE,IAAMC,CAAAA,CAAO,IAAI,OAAA,CAGjB,SAASC,CAAAA,CAAmBC,CAAAA,CAAkC,CAC5D,GAAIA,CAAAA,GAAQ,KAAM,OAAO,MAAA,CACzB,GAAIA,CAAAA,GAAQ,MAAA,CAAW,OAAO,WAAA,CAE9B,IAAMC,CAAAA,CAAO,OAAOD,CAAAA,CACpB,GAAIC,CAAAA,GAAS,QAAA,CAAU,OAAO,IAAA,CAAK,SAAA,CAAUD,CAAG,CAAA,CAChD,GAAIC,CAAAA,GAAS,QAAA,EAAYA,CAAAA,GAAS,SAAA,CAAW,OAAO,MAAA,CAAOD,CAAG,CAAA,CAC9D,GAAIC,CAAAA,GAAS,UAAA,CAAY,OAAO,eAChC,GAAIA,CAAAA,GAAS,QAAA,CAAU,OAAO,YAGhC,CAGA,SAASC,CAAAA,CACPC,CAAAA,CACAC,CAAAA,CACQ,CACR,GAAIN,CAAAA,CAAK,GAAA,CAAIK,CAAG,CAAA,CACd,OAAO,cAAA,CAETL,CAAAA,CAAK,GAA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CAACE,CAAAA,CAAM9E,CAAAA,GACD,OAAOA,CAAAA,EAAU,SACZ,CAAA,EAAGA,CAAK,CAAA,CAAA,CAAA,CAGVA,CAAAA,CAET,CACF,CAAA,CACA,OAAKgC,CAAAA,CAGDA,CAAAA,CAAI,MAAA,EAAU6C,CAAAA,CACT7C,CAAAA,CAGF,CAAA,EAAGA,CAAAA,CAAI,KAAA,CAAM,CAAA,CAAG6C,CAAM,CAAC;AAAA,gBAAA,EAAqB7C,CAAAA,CAAI,MAAM,CAAA,aAAA,CAAA,CANpD,aAOX,MAAQ,CACN,OAAO,kBACT,CACF","file":"chunk-BEJ6ICA7.cjs","sourcesContent":["/**\n * Shared utilities for Directive\n */\n\n/**\n * Execute a promise with a timeout, properly cleaning up the timer.\n * Used by both constraints and resolvers for timeout handling.\n *\n * @param promise - The promise to wrap with a timeout\n * @param ms - Timeout duration in milliseconds\n * @param errorMessage - Error message if timeout occurs\n * @returns The promise result\n * @throws Error if timeout is exceeded\n */\nexport async function withTimeout<T>(\n promise: Promise<T>,\n ms: number,\n errorMessage: string,\n): Promise<T> {\n let timeoutId: ReturnType<typeof setTimeout>;\n\n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutId = setTimeout(() => reject(new Error(errorMessage)), ms);\n });\n\n try {\n return await Promise.race([promise, timeoutPromise]);\n } finally {\n clearTimeout(timeoutId!);\n }\n}\n\n/**\n * Normalize an error to an Error instance.\n * Ensures consistent error handling throughout the library.\n *\n * @param error - The error to normalize (can be anything)\n * @returns An Error instance\n */\nexport function normalizeError(error: unknown): Error {\n if (error instanceof Error) {\n return error;\n }\n return new Error(String(error));\n}\n\n/**\n * Create a stable JSON string with sorted keys.\n * Handles circular references and deeply nested objects safely.\n *\n * @param value - The value to stringify\n * @param maxDepth - Maximum nesting depth (default: 50)\n * @returns A stable JSON string\n */\nexport function stableStringify(value: unknown, maxDepth = 50): string {\n const seen = new WeakSet();\n\n /** Stringify a primitive value (null, undefined, string, number, boolean, function, symbol). */\n function stringifyPrimitive(val: unknown): string | undefined {\n if (val === null) return \"null\";\n if (val === undefined) return \"undefined\";\n\n const type = typeof val;\n if (type === \"string\") return JSON.stringify(val);\n if (type === \"number\" || type === \"boolean\") return String(val);\n if (type === \"function\") return '\"[function]\"';\n if (type === \"symbol\") return '\"[symbol]\"';\n\n return undefined;\n }\n\n /** Guard against circular references using a seen-set, then delegate to fn. */\n function withCircularGuard(\n obj: object,\n fn: () => string,\n ): string {\n if (seen.has(obj)) {\n return '\"[circular]\"';\n }\n seen.add(obj);\n const result = fn();\n seen.delete(obj);\n\n return result;\n }\n\n /** Stringify an array with circular reference protection. */\n function stringifyArray(val: unknown[], depth: number): string {\n return withCircularGuard(val, () =>\n `[${val.map((v) => stringify(v, depth + 1)).join(\",\")}]`,\n );\n }\n\n /** Stringify an object with sorted keys and circular reference protection. */\n function stringifyObject(obj: Record<string, unknown>, depth: number): string {\n return withCircularGuard(obj, () => {\n const keys = Object.keys(obj).sort();\n const pairs = keys.map(\n (k) => `${JSON.stringify(k)}:${stringify(obj[k], depth + 1)}`,\n );\n\n return `{${pairs.join(\",\")}}`;\n });\n }\n\n /** Recursively stringify a value with depth limit and circular detection. */\n function stringify(val: unknown, depth: number): string {\n if (depth > maxDepth) {\n return '\"[max depth exceeded]\"';\n }\n\n const primitive = stringifyPrimitive(val);\n if (primitive !== undefined) {\n return primitive;\n }\n\n if (Array.isArray(val)) {\n return stringifyArray(val, depth);\n }\n\n if (typeof val === \"object\") {\n return stringifyObject(val as Record<string, unknown>, depth);\n }\n\n return '\"[unknown]\"';\n }\n\n return stringify(value, 0);\n}\n\n/**\n * Check for prototype pollution in an object, including nested objects.\n * Returns true if the object is safe, false if dangerous keys are found.\n *\n * @param obj - The object to check\n * @param maxDepth - Maximum nesting depth to check (default: 50)\n * @returns True if safe, false if dangerous keys found\n */\nexport function isPrototypeSafe(obj: unknown, maxDepth = 50): boolean {\n const dangerousKeys = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n const seen = new WeakSet();\n\n /** Guard against circular references using a seen-set, then delegate to fn. */\n function withCircularGuard(\n objVal: object,\n fn: () => boolean,\n ): boolean {\n if (seen.has(objVal)) return true;\n seen.add(objVal);\n const result = fn();\n seen.delete(objVal);\n\n return result;\n }\n\n /** Check array elements for prototype pollution keys. */\n function checkArray(arr: unknown[], depth: number): boolean {\n for (const item of arr) {\n if (!check(item, depth + 1)) {\n return false;\n }\n }\n\n return true;\n }\n\n /** Check object keys and values for prototype pollution. */\n function checkObject(objVal: Record<string, unknown>, depth: number): boolean {\n for (const key of Object.keys(objVal)) {\n if (dangerousKeys.has(key)) {\n return false;\n }\n if (!check(objVal[key], depth + 1)) {\n return false;\n }\n }\n\n return true;\n }\n\n /** Recursively check a value tree for dangerous prototype keys. */\n function check(val: unknown, depth: number): boolean {\n if (depth > maxDepth) return false; // Fail safe at max depth - don't assume safety\n if (val === null || val === undefined) return true;\n if (typeof val !== \"object\") return true;\n\n const objVal = val as Record<string, unknown>;\n\n if (Array.isArray(objVal)) {\n return withCircularGuard(objVal, () => checkArray(objVal, depth));\n }\n\n return withCircularGuard(objVal, () => checkObject(objVal, depth));\n }\n\n return check(obj, 0);\n}\n\n/**\n * Shallow equality comparison for objects.\n * Used by React hooks to avoid unnecessary re-renders.\n *\n * @param a - First object\n * @param b - Second object\n * @returns True if objects are shallowly equal\n */\nexport function shallowEqual<T extends Record<string, unknown>>(\n a: T,\n b: T,\n): boolean {\n if (a === b) return true;\n if (!a || !b) return false;\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (a[key] !== b[key]) return false;\n }\n\n return true;\n}\n\n/**\n * Generate a simple hash string from an object.\n * Uses djb2 algorithm on the stable stringified value.\n *\n * **Limitations:**\n * - 32-bit hash output means collision probability increases with data set size\n * (birthday paradox: ~50% collision chance at ~77,000 distinct values)\n * - Suitable for: cache invalidation, change detection, deduplication of small sets\n * - NOT suitable for: cryptographic use, security-sensitive operations, large-scale deduplication\n *\n * For security-sensitive use cases requiring stronger collision resistance,\n * consider using a cryptographic hash like SHA-256.\n *\n * @param value - The value to hash\n * @returns A hex hash string (8 characters, 32 bits)\n */\nexport function hashObject(value: unknown): string {\n const str = stableStringify(value);\n let hash = 5381;\n for (let i = 0; i < str.length; i++) {\n hash = ((hash << 5) + hash) ^ str.charCodeAt(i);\n }\n // Convert to unsigned 32-bit and then to hex\n return (hash >>> 0).toString(16);\n}\n\n// ============================================================================\n// Distributable Snapshot Utilities\n// ============================================================================\n\n/**\n * Distributable snapshot type for type-safe helper functions.\n */\nexport interface DistributableSnapshotLike<T = Record<string, unknown>> {\n data: T;\n createdAt: number;\n expiresAt?: number;\n version?: string;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Check if a distributable snapshot has expired.\n * Returns false if the snapshot has no expiresAt field.\n *\n * @example\n * ```typescript\n * const snapshot = system.getDistributableSnapshot({ ttlSeconds: 3600 });\n * // ... later ...\n * if (isSnapshotExpired(snapshot)) {\n * // Refresh the snapshot\n * }\n * ```\n *\n * @param snapshot - The snapshot to check\n * @param now - Optional current timestamp (defaults to Date.now())\n * @returns True if the snapshot has expired, false otherwise\n */\nexport function isSnapshotExpired<T>(\n snapshot: DistributableSnapshotLike<T>,\n now: number = Date.now(),\n): boolean {\n return snapshot.expiresAt !== undefined && now > snapshot.expiresAt;\n}\n\n/**\n * Validate a distributable snapshot and return its data.\n * Throws if the snapshot is malformed or has expired.\n *\n * @example\n * ```typescript\n * const cached = JSON.parse(await redis.get(`entitlements:${userId}`));\n * try {\n * const data = validateSnapshot(cached);\n * // Use data.canUseFeature, etc.\n * } catch (e) {\n * // Snapshot invalid or expired, refresh it\n * }\n * ```\n *\n * @example Using custom timestamp for testing\n * ```typescript\n * const snapshot = { data: { test: true }, createdAt: 1000, expiresAt: 2000 };\n * validateSnapshot(snapshot, 1500); // Returns { test: true }\n * validateSnapshot(snapshot, 2500); // Throws: Snapshot expired\n * ```\n *\n * @param snapshot - The snapshot to validate\n * @param now - Optional current timestamp (defaults to Date.now())\n * @returns The snapshot data if valid\n * @throws Error if the snapshot is malformed or has expired\n */\nexport function validateSnapshot<T>(\n snapshot: DistributableSnapshotLike<T>,\n now: number = Date.now(),\n): T {\n // Structural validation\n if (!snapshot || typeof snapshot !== \"object\") {\n throw new Error(\n \"[Directive] Invalid snapshot: expected an object with 'data' and 'createdAt' properties.\",\n );\n }\n if (!(\"data\" in snapshot)) {\n throw new Error(\n \"[Directive] Invalid snapshot: missing required 'data' property.\",\n );\n }\n if (!(\"createdAt\" in snapshot) || typeof snapshot.createdAt !== \"number\") {\n throw new Error(\n \"[Directive] Invalid snapshot: missing or invalid 'createdAt' property (expected number).\",\n );\n }\n\n // Expiration validation\n if (isSnapshotExpired(snapshot, now)) {\n const expiredAt = new Date(snapshot.expiresAt!).toISOString();\n throw new Error(\n `[Directive] Snapshot expired at ${expiredAt}. Obtain a fresh snapshot from the source.`,\n );\n }\n return snapshot.data;\n}\n\n/**\n * Diff result for a single changed value.\n */\nexport interface SnapshotDiffEntry {\n /** The key path that changed (e.g., \"canUseApi\" or \"limits.apiCalls\") */\n path: string;\n /** The value in the old snapshot */\n oldValue: unknown;\n /** The value in the new snapshot */\n newValue: unknown;\n /** Type of change: \"added\", \"removed\", or \"changed\" */\n type: \"added\" | \"removed\" | \"changed\";\n}\n\n/**\n * Result of diffing two snapshots.\n */\nexport interface SnapshotDiff {\n /** Whether the snapshots are identical */\n identical: boolean;\n /** List of changes between snapshots */\n changes: SnapshotDiffEntry[];\n /** Whether the version changed (if both have versions) */\n versionChanged: boolean;\n /** Old version (if available) */\n oldVersion?: string;\n /** New version (if available) */\n newVersion?: string;\n}\n\n/**\n * Compare two distributable snapshots and return the differences.\n * Useful for debugging, audit logs, and webhook payloads.\n *\n * @example\n * ```typescript\n * const oldSnapshot = system.getDistributableSnapshot({ includeVersion: true });\n * system.dispatch({ type: \"upgradePlan\", plan: \"pro\" });\n * const newSnapshot = system.getDistributableSnapshot({ includeVersion: true });\n *\n * const diff = diffSnapshots(oldSnapshot, newSnapshot);\n * if (!diff.identical) {\n * console.log(\"Changes:\", diff.changes);\n * // [{ path: \"canUseApi\", oldValue: false, newValue: true, type: \"changed\" }]\n * }\n * ```\n *\n * @param oldSnapshot - The previous snapshot\n * @param newSnapshot - The new snapshot\n * @returns A diff result with all changes\n */\nexport function diffSnapshots<T = Record<string, unknown>>(\n oldSnapshot: DistributableSnapshotLike<T>,\n newSnapshot: DistributableSnapshotLike<T>,\n): SnapshotDiff {\n const changes: SnapshotDiffEntry[] = [];\n\n /** Push a change entry to the diff results. */\n function pushChange(\n path: string,\n oldValue: unknown,\n newValue: unknown,\n type: SnapshotDiffEntry[\"type\"],\n ): void {\n changes.push({ path, oldValue, newValue, type });\n }\n\n /** Handle null/undefined comparison cases. Returns true if fully handled. */\n function compareNullish(\n oldObj: unknown,\n newObj: unknown,\n path: string,\n ): boolean {\n if (oldObj === null || oldObj === undefined) {\n if (newObj !== null && newObj !== undefined) {\n pushChange(path, oldObj, newObj, \"added\");\n }\n\n return true;\n }\n if (newObj === null || newObj === undefined) {\n pushChange(path, oldObj, newObj, \"removed\");\n\n return true;\n }\n\n return false;\n }\n\n /** Compare two arrays element by element, recursing into each. */\n function compareArrays(\n oldArr: unknown[],\n newArr: unknown[],\n path: string,\n ): void {\n if (oldArr.length !== newArr.length) {\n pushChange(path, oldArr, newArr, \"changed\");\n\n return;\n }\n for (let i = 0; i < oldArr.length; i++) {\n compare(oldArr[i], newArr[i], `${path}[${i}]`);\n }\n }\n\n /** Compare two objects by key union, detecting added/removed/changed. */\n function compareObjects(\n oldRecord: Record<string, unknown>,\n newRecord: Record<string, unknown>,\n path: string,\n ): void {\n const allKeys = new Set([\n ...Object.keys(oldRecord),\n ...Object.keys(newRecord),\n ]);\n\n for (const key of allKeys) {\n const childPath = path ? `${path}.${key}` : key;\n if (!(key in oldRecord)) {\n pushChange(childPath, undefined, newRecord[key], \"added\");\n } else if (!(key in newRecord)) {\n pushChange(childPath, oldRecord[key], undefined, \"removed\");\n } else {\n compare(oldRecord[key], newRecord[key], childPath);\n }\n }\n }\n\n /** Recursively compare two values and record differences. */\n function compare(oldObj: unknown, newObj: unknown, path: string): void {\n if (compareNullish(oldObj, newObj, path)) {\n return;\n }\n\n // Handle primitives\n if (typeof oldObj !== \"object\" || typeof newObj !== \"object\") {\n if (!Object.is(oldObj, newObj)) {\n pushChange(path, oldObj, newObj, \"changed\");\n }\n\n return;\n }\n\n // Handle arrays\n if (Array.isArray(oldObj) && Array.isArray(newObj)) {\n compareArrays(oldObj, newObj, path);\n\n return;\n }\n\n // Handle objects\n compareObjects(\n oldObj as Record<string, unknown>,\n newObj as Record<string, unknown>,\n path,\n );\n }\n\n // Compare data\n compare(oldSnapshot.data, newSnapshot.data, \"\");\n\n // Check version change\n const versionChanged =\n oldSnapshot.version !== newSnapshot.version &&\n (oldSnapshot.version !== undefined || newSnapshot.version !== undefined);\n\n return {\n identical: changes.length === 0,\n changes,\n versionChanged,\n oldVersion: oldSnapshot.version,\n newVersion: newSnapshot.version,\n };\n}\n\n// ============================================================================\n// Snapshot Signing (HMAC)\n// ============================================================================\n\n/**\n * A signed distributable snapshot.\n * Contains the original snapshot plus a cryptographic signature.\n */\nexport interface SignedSnapshot<T = Record<string, unknown>>\n extends DistributableSnapshotLike<T> {\n /** HMAC-SHA256 signature in hex format */\n signature: string;\n /** Signing algorithm used */\n algorithm: \"hmac-sha256\";\n}\n\n/**\n * Check if a snapshot is signed.\n *\n * @param snapshot - The snapshot to check\n * @returns True if the snapshot has a signature\n */\nexport function isSignedSnapshot<T>(\n snapshot: DistributableSnapshotLike<T> | SignedSnapshot<T>,\n): snapshot is SignedSnapshot<T> {\n return \"signature\" in snapshot && typeof snapshot.signature === \"string\";\n}\n\n/**\n * Sign a distributable snapshot using HMAC-SHA256.\n * Creates a tamper-proof signature that can be verified later.\n *\n * **Security Notes:**\n * - Use a cryptographically random secret of at least 32 bytes\n * - Store the secret securely (environment variable, secrets manager)\n * - Never expose the secret to clients\n * - The signature covers all snapshot fields for integrity\n *\n * @example\n * ```typescript\n * const snapshot = system.getDistributableSnapshot({\n * includeDerivations: ['canUseFeature', 'limits'],\n * ttlSeconds: 3600,\n * });\n *\n * // Sign the snapshot (server-side only)\n * const signed = await signSnapshot(snapshot, process.env.SNAPSHOT_SECRET);\n *\n * // Store in JWT, Redis, or send to client\n * const jwt = createJWT({ snapshot: signed });\n *\n * // Later, verify the signature\n * const isValid = await verifySnapshotSignature(signed, process.env.SNAPSHOT_SECRET);\n * if (!isValid) {\n * throw new Error('Snapshot has been tampered with');\n * }\n * ```\n *\n * @param snapshot - The snapshot to sign\n * @param secret - The HMAC secret (string or Uint8Array)\n * @returns A signed snapshot with the signature attached\n */\nexport async function signSnapshot<T>(\n snapshot: DistributableSnapshotLike<T>,\n secret: string | Uint8Array,\n): Promise<SignedSnapshot<T>> {\n // Create a canonical representation for signing\n const payload = stableStringify({\n data: snapshot.data,\n createdAt: snapshot.createdAt,\n expiresAt: snapshot.expiresAt,\n version: snapshot.version,\n metadata: snapshot.metadata,\n });\n\n const signature = await hmacSha256(payload, secret);\n\n return {\n ...snapshot,\n signature,\n algorithm: \"hmac-sha256\",\n };\n}\n\n/**\n * Verify the signature of a signed snapshot.\n * Returns true if the signature is valid, false otherwise.\n *\n * **Important:** Always verify signatures before trusting snapshot data,\n * especially if the snapshot was received from an untrusted source (client, cache).\n *\n * @example\n * ```typescript\n * // Receive signed snapshot from client or cache\n * const snapshot = JSON.parse(cachedData);\n *\n * // Verify before using\n * const isValid = await verifySnapshotSignature(snapshot, process.env.SNAPSHOT_SECRET);\n * if (!isValid) {\n * throw new Error('Invalid snapshot signature - possible tampering');\n * }\n *\n * // Now safe to use snapshot.data\n * if (snapshot.data.canUseFeature.api) {\n * // Grant access\n * }\n * ```\n *\n * @param signedSnapshot - The signed snapshot to verify\n * @param secret - The HMAC secret (must match the signing secret)\n * @returns True if signature is valid, false otherwise\n */\nexport async function verifySnapshotSignature<T>(\n signedSnapshot: SignedSnapshot<T>,\n secret: string | Uint8Array,\n): Promise<boolean> {\n if (!signedSnapshot.signature || signedSnapshot.algorithm !== \"hmac-sha256\") {\n return false;\n }\n\n // Recreate the canonical payload (same as signing)\n const payload = stableStringify({\n data: signedSnapshot.data,\n createdAt: signedSnapshot.createdAt,\n expiresAt: signedSnapshot.expiresAt,\n version: signedSnapshot.version,\n metadata: signedSnapshot.metadata,\n });\n\n const expectedSignature = await hmacSha256(payload, secret);\n\n // Use timing-safe comparison\n return timingSafeEqual(signedSnapshot.signature, expectedSignature);\n}\n\n/**\n * Create HMAC-SHA256 signature of a message.\n * Uses Web Crypto API for cross-platform support (Node.js, browsers, Deno, Bun).\n */\nasync function hmacSha256(\n message: string,\n secret: string | Uint8Array,\n): Promise<string> {\n // Convert secret to Uint8Array if string\n const secretBytes: Uint8Array =\n typeof secret === \"string\" ? new TextEncoder().encode(secret) : secret;\n\n // Import key for HMAC\n const algorithm: HmacImportParams = {\n name: \"HMAC\",\n hash: { name: \"SHA-256\" },\n };\n const key = await crypto.subtle.importKey(\n \"raw\",\n secretBytes as unknown as ArrayBuffer,\n algorithm,\n false,\n [\"sign\"],\n );\n\n // Sign the message\n const messageBytes = new TextEncoder().encode(message);\n const signature = await crypto.subtle.sign(\"HMAC\", key, messageBytes);\n\n // Convert to hex string\n return Array.from(new Uint8Array(signature))\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Timing-safe string comparison to prevent timing attacks.\n * Both strings should be the same length (hex signatures from same algorithm).\n */\nfunction timingSafeEqual(a: string, b: string): boolean {\n if (a.length !== b.length) {\n return false;\n }\n\n let result = 0;\n for (let i = 0; i < a.length; i++) {\n result |= a.charCodeAt(i) ^ b.charCodeAt(i);\n }\n return result === 0;\n}\n\n/**\n * Safely stringify any value for display. Handles circular references,\n * BigInt, throwing toJSON, and optional truncation.\n *\n * This is the canonical implementation – all packages should import this\n * instead of maintaining local copies.\n */\nexport function safeStringify(\n data: unknown,\n maxLen = 500,\n): string {\n try {\n const str = JSON.stringify(\n data,\n (_key, value) => {\n if (typeof value === \"bigint\") {\n return `${value}n`;\n }\n\n return value;\n },\n 2,\n );\n if (!str) {\n return \"[undefined]\";\n }\n if (str.length <= maxLen) {\n return str;\n }\n\n return `${str.slice(0, maxLen)}\\n... (truncated, ${str.length} chars total)`;\n } catch {\n return \"[unserializable]\";\n }\n}\n"]}