@directive-run/core 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter-utils.cjs +1 -1
- package/dist/adapter-utils.d.cts +2 -2
- package/dist/adapter-utils.d.ts +2 -2
- package/dist/adapter-utils.js +1 -1
- package/dist/adapter-utils.js.map +1 -1
- package/dist/audit-ledger-Dc6hAXam.d.cts +378 -0
- package/dist/audit-ledger-dxvslGi3.d.ts +378 -0
- package/dist/chunk-2FF6QGOA.js +2 -0
- package/dist/chunk-2FF6QGOA.js.map +1 -0
- package/dist/chunk-4MNQDXH7.cjs +3 -0
- package/dist/chunk-4MNQDXH7.cjs.map +1 -0
- package/dist/chunk-644QZVTT.js +16 -0
- package/dist/{chunk-26Z5VNPZ.js.map → chunk-644QZVTT.js.map} +1 -1
- package/dist/chunk-ENZEHIL7.cjs +3 -0
- package/dist/chunk-ENZEHIL7.cjs.map +1 -0
- package/dist/chunk-I722BZA5.js +7 -0
- package/dist/chunk-I722BZA5.js.map +1 -0
- package/dist/chunk-IXRS4LM4.cjs +2 -0
- package/dist/chunk-IXRS4LM4.cjs.map +1 -0
- package/dist/chunk-NPX5EKPP.cjs +16 -0
- package/dist/{chunk-EX3XG667.cjs.map → chunk-NPX5EKPP.cjs.map} +1 -1
- package/dist/chunk-PA6VC32N.js +2 -0
- package/dist/chunk-PA6VC32N.js.map +1 -0
- package/dist/chunk-PXRV64PA.js +3 -0
- package/dist/chunk-PXRV64PA.js.map +1 -0
- package/dist/chunk-R2GHSCTR.js +3 -0
- package/dist/chunk-R2GHSCTR.js.map +1 -0
- package/dist/chunk-T4TRJEJN.cjs +2 -0
- package/dist/chunk-T4TRJEJN.cjs.map +1 -0
- package/dist/chunk-X7G7UBXU.cjs +7 -0
- package/dist/chunk-X7G7UBXU.cjs.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +214 -391
- package/dist/index.d.ts +214 -391
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +1 -1
- package/dist/internals.d.cts +5 -5
- package/dist/internals.d.ts +5 -5
- package/dist/internals.js +1 -1
- package/dist/plugins/index.cjs +2 -2
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.cts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/index.js.map +1 -1
- package/dist/{plugins-Ykl_sAPE.d.ts → plugins-BIzXaYbg.d.cts} +15 -1
- package/dist/{plugins-Ykl_sAPE.d.cts → plugins-BIzXaYbg.d.ts} +15 -1
- package/dist/predicate-Bnx3LN7P.d.cts +655 -0
- package/dist/predicate-BxQVf0ug.d.ts +655 -0
- package/dist/system-A6VYKLVF.js +2 -0
- package/dist/{system-VZWB6WXX.js.map → system-A6VYKLVF.js.map} +1 -1
- package/dist/system-CDJMD5O5.cjs +2 -0
- package/dist/{system-GK3NSFQH.cjs.map → system-CDJMD5O5.cjs.map} +1 -1
- package/dist/testing.cjs +1 -1
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/{utils-BnQajqPu.d.cts → utils-Mg55IerF.d.cts} +27 -1
- package/dist/{utils-BnQajqPu.d.ts → utils-Mg55IerF.d.ts} +27 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/audit-ledger-9IElAHH9.d.ts +0 -205
- package/dist/audit-ledger-qMjEBqiP.d.cts +0 -205
- package/dist/chunk-26Z5VNPZ.js +0 -16
- package/dist/chunk-4VZOZWXM.cjs +0 -2
- package/dist/chunk-4VZOZWXM.cjs.map +0 -1
- package/dist/chunk-7NMXRATK.cjs +0 -3
- package/dist/chunk-7NMXRATK.cjs.map +0 -1
- package/dist/chunk-7TSYQEN3.js +0 -2
- package/dist/chunk-7TSYQEN3.js.map +0 -1
- package/dist/chunk-EOLY64E6.cjs +0 -3
- package/dist/chunk-EOLY64E6.cjs.map +0 -1
- package/dist/chunk-EX3XG667.cjs +0 -16
- package/dist/chunk-N4KTCKOI.cjs +0 -7
- package/dist/chunk-N4KTCKOI.cjs.map +0 -1
- package/dist/chunk-T6IJUWYR.js +0 -3
- package/dist/chunk-T6IJUWYR.js.map +0 -1
- package/dist/chunk-TPOKS4RY.js +0 -3
- package/dist/chunk-TPOKS4RY.js.map +0 -1
- package/dist/chunk-TZHC4E6S.js +0 -7
- package/dist/chunk-TZHC4E6S.js.map +0 -1
- package/dist/helpers-D2pfb6vT.d.ts +0 -235
- package/dist/helpers-hh6UanB1.d.cts +0 -235
- package/dist/system-GK3NSFQH.cjs +0 -2
- package/dist/system-VZWB6WXX.js +0 -2
package/dist/adapter-utils.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkX7G7UBXU_cjs=require('./chunk-X7G7UBXU.cjs'),chunk4MNQDXH7_cjs=require('./chunk-4MNQDXH7.cjs');function w(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 S(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 x(n,e){if(chunk4MNQDXH7_cjs.a&&e==null)throw new Error(`[Directive] ${n}() requires a system instance as the first argument. Received ${e}.`)}function R(n,e){return Object.is(n,e)}function T(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 I(n,e){let r={};for(let t of e)r[t]=n.facts.$store.get(t);return r}function C(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}=chunkX7G7UBXU_cjs.h(()=>r(s));return {value:a,factKeys:Array.from(u),deriveKeys:t}}function P(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 q(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 chunkX7G7UBXU_cjs.c}});Object.defineProperty(exports,"getBridgeFact",{enumerable:true,get:function(){return chunkX7G7UBXU_cjs.b}});Object.defineProperty(exports,"requirementGuard",{enumerable:true,get:function(){return chunkX7G7UBXU_cjs.d}});Object.defineProperty(exports,"requirementGuardMultiple",{enumerable:true,get:function(){return chunkX7G7UBXU_cjs.e}});Object.defineProperty(exports,"setBridgeFact",{enumerable:true,get:function(){return chunkX7G7UBXU_cjs.a}});Object.defineProperty(exports,"shallowEqual",{enumerable:true,get:function(){return chunk4MNQDXH7_cjs.g}});exports.assertSystem=x;exports.buildHistoryState=T;exports.computeInspectState=w;exports.createThrottle=S;exports.defaultEquality=R;exports.depsChanged=P;exports.mergeHydrationFacts=q;exports.pickFacts=I;exports.runTrackedSelector=C;//# sourceMappingURL=adapter-utils.cjs.map
|
|
2
2
|
//# sourceMappingURL=adapter-utils.cjs.map
|
package/dist/adapter-utils.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { s as shallowEqual } from './utils-
|
|
1
|
+
import { q as Requirement, P as Plugin, a as Facts, a8 as Schema, H as HistoryAPI, ac as SystemInspection, I as HistoryState } from './plugins-BIzXaYbg.cjs';
|
|
2
|
+
export { s as shallowEqual } from './utils-Mg55IerF.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Adapter Type Utilities - Shared types and helpers for framework adapters
|
package/dist/adapter-utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { s as shallowEqual } from './utils-
|
|
1
|
+
import { q as Requirement, P as Plugin, a as Facts, a8 as Schema, H as HistoryAPI, ac as SystemInspection, I as HistoryState } from './plugins-BIzXaYbg.js';
|
|
2
|
+
export { s as shallowEqual } from './utils-Mg55IerF.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Adapter Type Utilities - Shared types and helpers for framework adapters
|
package/dist/adapter-utils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {h}from'./chunk-I722BZA5.js';export{c as createCallbackPlugin,b as getBridgeFact,d as requirementGuard,e as requirementGuardMultiple,a as setBridgeFact}from'./chunk-I722BZA5.js';import {a}from'./chunk-PXRV64PA.js';export{g as shallowEqual}from'./chunk-PXRV64PA.js';function w(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 S(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 x(n,e){if(a&&e==null)throw new Error(`[Directive] ${n}() requires a system instance as the first argument. Received ${e}.`)}function R(n,e){return Object.is(n,e)}function T(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 I(n,e){let r={};for(let t of e)r[t]=n.facts.$store.get(t);return r}function C(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 P(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 q(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{x as assertSystem,T as buildHistoryState,w as computeInspectState,S as createThrottle,R as defaultEquality,P as depsChanged,q as mergeHydrationFacts,I as pickFacts,C 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","dev_true_default","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":"8OAuGO,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,C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,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 isDevelopment from \"#is-development\";\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 (isDevelopment && 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
|
+
{"version":3,"sources":["../src/adapter-utils.ts"],"names":["computeInspectState","system","inspection","createThrottle","callback","ms","timeoutId","lastArgs","lastCallTime","args","now","timeSinceLastCall","assertSystem","hookName","dev_true_default","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":"gRAuGO,SAASA,CAAAA,CAAoBC,CAAAA,CAAkC,CACpE,IAAMC,CAAAA,CAAaD,CAAAA,CAAO,OAAA,EAAQ,C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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 isDevelopment from \"#is-development\";\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 (isDevelopment && 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,378 @@
|
|
|
1
|
+
import { F as FactPredicate, C as ClauseResult, P as Plugin, M as ModuleSchema } from './plugins-BIzXaYbg.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* createAuditLedger — append-only, queryable, hash-chained
|
|
5
|
+
* (djb2; SHA-256 reserved for v2) audit of every state change. For
|
|
6
|
+
* forensics and "show me why this user got that decision."
|
|
7
|
+
*
|
|
8
|
+
* Captures (per observation event):
|
|
9
|
+
*
|
|
10
|
+
* - `constraint.evaluate` → { whenSpec, whenExplain, active, whenSource? }
|
|
11
|
+
* - `resolver.write.rejected` (rejection + summary kinds)
|
|
12
|
+
* - `fact.change` → { key, prior, next }
|
|
13
|
+
* - `resolver.complete` → { resolverId, requirementId, duration }
|
|
14
|
+
* - `system.init` / `system.start` / `system.stop` / `system.destroy`
|
|
15
|
+
* - `system.snapshot` / `system.history.navigate` (lifecycle markers)
|
|
16
|
+
* - `system.truncated` (ring-buffer overflow marker)
|
|
17
|
+
* - `system.entry-erased` / `system.subject-erased` (GDPR Art.17 stub)
|
|
18
|
+
*
|
|
19
|
+
* Hash chain: each entry stores `prevHash` — the djb2 (`hashObject`)
|
|
20
|
+
* hash of the previous entry's stable-stringified payload. Tampering
|
|
21
|
+
* with any entry's payload breaks the next entry's `prevHash` link —
|
|
22
|
+
* visible in `verify()`. v1 ships sync djb2 only; `verify({ strong: true })`
|
|
23
|
+
* is reserved for v2 (SHA-256) and throws today.
|
|
24
|
+
*
|
|
25
|
+
* PII redaction: by default, fact keys whose meta carries the `pii`
|
|
26
|
+
* tag (via `system.meta.byTag("pii")`) have their values replaced with
|
|
27
|
+
* `"[redacted]"` in `whenExplain.actual`, `fact.change.prior`,
|
|
28
|
+
* `fact.change.next`, and the cached `whenSpec` operands. Opt out with
|
|
29
|
+
* `capturePII: true`.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** Hash algorithm tag — bumped if canonicalization or hash function changes. */
|
|
33
|
+
declare const HASH_ALGO: "djb2-1";
|
|
34
|
+
/**
|
|
35
|
+
* Entry schema version. Bumped if `AuditEntry` field shape changes in
|
|
36
|
+
* a way that breaks back-compat parsers. Persisted on every entry so
|
|
37
|
+
* exports remain self-describing across library upgrades. (F-5)
|
|
38
|
+
*/
|
|
39
|
+
declare const SCHEMA_VERSION: 1;
|
|
40
|
+
/**
|
|
41
|
+
* Private sentinel stamped onto tombstone entries by {@link createAuditLedger.erase}.
|
|
42
|
+
* Never exported, never serialized — `verify()` checks for it before
|
|
43
|
+
* accepting a `system.entry-erased` entry as a legitimate chain break.
|
|
44
|
+
*
|
|
45
|
+
* (N7) Without this, a caller holding a raw `AuditLedgerSink` reference
|
|
46
|
+
* could write `{ kind: "system.entry-erased", … }` directly into the
|
|
47
|
+
* sink to mask real tampering as legitimate erasure. The sentinel
|
|
48
|
+
* raises the bar so only the in-process ledger plugin (which lives in
|
|
49
|
+
* this module's closure) can mint a valid tombstone.
|
|
50
|
+
*/
|
|
51
|
+
declare const LEDGER_INTERNAL_TOKEN: unique symbol;
|
|
52
|
+
type AuditEntryKind = "constraint.evaluate" | "resolver.write.rejected" | "fact.change" | "resolver.complete" | "resolver.error" | "system.init" | "system.start" | "system.stop" | "system.destroy" | "system.snapshot" | "system.history.navigate" | "system.truncated" | "system.entry-erased" | "system.subject-erased";
|
|
53
|
+
interface AuditEntryBase {
|
|
54
|
+
/** Monotonic sequence number, starting at 0. */
|
|
55
|
+
readonly seq: number;
|
|
56
|
+
/** Wall-clock timestamp (ms epoch). */
|
|
57
|
+
readonly ts: number;
|
|
58
|
+
/** Discriminator. */
|
|
59
|
+
readonly kind: AuditEntryKind;
|
|
60
|
+
/** Hash of the previous entry's full payload. null on the genesis entry. */
|
|
61
|
+
readonly prevHash: string | null;
|
|
62
|
+
/**
|
|
63
|
+
* Hash algorithm tag identifying the canonicalization + hash
|
|
64
|
+
* function in use. Bumped if the algorithm or canonical form
|
|
65
|
+
* changes, so exports remain verifiable across versions.
|
|
66
|
+
*/
|
|
67
|
+
readonly hashAlgo: typeof HASH_ALGO;
|
|
68
|
+
/**
|
|
69
|
+
* Entry schema version — bumped if any `AuditEntry` field shape
|
|
70
|
+
* changes in a way that breaks back-compat. Pair with `hashAlgo`
|
|
71
|
+
* when migrating older exports. (F-5)
|
|
72
|
+
*/
|
|
73
|
+
readonly schemaVersion: typeof SCHEMA_VERSION;
|
|
74
|
+
/**
|
|
75
|
+
* Private sentinel — present (and equal to the in-module token) only
|
|
76
|
+
* on legitimate tombstones minted by `ledger.erase()`. Filtered out
|
|
77
|
+
* of all public read paths (`query`, `recent`, `toJSON`, etc.) so
|
|
78
|
+
* consumers never see or copy it. (N7)
|
|
79
|
+
*
|
|
80
|
+
* NOT serialized. NOT exported. Forging this from outside the module
|
|
81
|
+
* is impossible without the symbol reference; `verify()` rejects any
|
|
82
|
+
* `system.entry-erased` entry that lacks it.
|
|
83
|
+
*
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
readonly __internal?: typeof LEDGER_INTERNAL_TOKEN;
|
|
87
|
+
}
|
|
88
|
+
type AuditEntry = (AuditEntryBase & {
|
|
89
|
+
kind: "constraint.evaluate";
|
|
90
|
+
constraintId: string;
|
|
91
|
+
active: boolean;
|
|
92
|
+
/** Cached at ledger start from `system.inspect().constraints[].whenSpec`. Refreshed on `register()`/`assign()`/`unregister()`. May be undefined for function-form constraints (see `whenSource`). PII operands redacted unless `capturePII: true`. */
|
|
93
|
+
whenSpec?: FactPredicate<unknown>;
|
|
94
|
+
whenExplain?: readonly ClauseResult[];
|
|
95
|
+
/**
|
|
96
|
+
* For function-form constraints (no `whenSpec`), a tamper-evident
|
|
97
|
+
* identity for the function. We DO NOT capture the raw source —
|
|
98
|
+
* closures routinely reference secrets, API keys, or PII (e.g.
|
|
99
|
+
* `if (apiKey === "sk-live-xxx")`) and a preview would leak them
|
|
100
|
+
* into the audit log. Instead, we capture a djb2 hash of the
|
|
101
|
+
* stringified function (`hashObject(String(fn))`). Auditors can
|
|
102
|
+
* detect "the function changed between deploys" by comparing
|
|
103
|
+
* hashes across entries, without ever seeing the function body.
|
|
104
|
+
*
|
|
105
|
+
* Informational only — NOT replayable. (N5, M22)
|
|
106
|
+
*/
|
|
107
|
+
whenSource?: {
|
|
108
|
+
kind: "function";
|
|
109
|
+
sourceHash: string;
|
|
110
|
+
};
|
|
111
|
+
}) | (AuditEntryBase & {
|
|
112
|
+
kind: "resolver.write.rejected";
|
|
113
|
+
rejection: "rejection" | "summary";
|
|
114
|
+
resolverId: string;
|
|
115
|
+
requirementId: string;
|
|
116
|
+
reason: string;
|
|
117
|
+
fact?: string;
|
|
118
|
+
expected?: unknown;
|
|
119
|
+
actual?: unknown;
|
|
120
|
+
dropped?: number;
|
|
121
|
+
}) | (AuditEntryBase & {
|
|
122
|
+
kind: "fact.change";
|
|
123
|
+
key: string;
|
|
124
|
+
prior: unknown;
|
|
125
|
+
next: unknown;
|
|
126
|
+
}) | (AuditEntryBase & {
|
|
127
|
+
kind: "resolver.complete";
|
|
128
|
+
resolverId: string;
|
|
129
|
+
requirementId: string;
|
|
130
|
+
duration: number;
|
|
131
|
+
}) | (AuditEntryBase & {
|
|
132
|
+
kind: "resolver.error";
|
|
133
|
+
resolverId: string;
|
|
134
|
+
requirementId: string;
|
|
135
|
+
error: string;
|
|
136
|
+
}) | (AuditEntryBase & {
|
|
137
|
+
kind: "system.init" | "system.start" | "system.stop" | "system.destroy";
|
|
138
|
+
}) | (AuditEntryBase & {
|
|
139
|
+
kind: "system.snapshot";
|
|
140
|
+
snapshotId: number;
|
|
141
|
+
trigger: string;
|
|
142
|
+
}) | (AuditEntryBase & {
|
|
143
|
+
kind: "system.history.navigate";
|
|
144
|
+
from: number;
|
|
145
|
+
to: number;
|
|
146
|
+
}) | (AuditEntryBase & {
|
|
147
|
+
kind: "system.truncated";
|
|
148
|
+
droppedSeq: number;
|
|
149
|
+
droppedCount: number;
|
|
150
|
+
}) | (AuditEntryBase & {
|
|
151
|
+
kind: "system.entry-erased";
|
|
152
|
+
originalKind: AuditEntryKind;
|
|
153
|
+
erasedAt: number;
|
|
154
|
+
}) | (AuditEntryBase & {
|
|
155
|
+
kind: "system.subject-erased";
|
|
156
|
+
/**
|
|
157
|
+
* djb2 hash of the filter (via `hashObject(filter)`). PII-safe —
|
|
158
|
+
* the raw filter values never land in the ledger. Pair with
|
|
159
|
+
* `filterShape` to see which filter fields were used. (N2)
|
|
160
|
+
*/
|
|
161
|
+
filterHash: string;
|
|
162
|
+
/**
|
|
163
|
+
* Stripped-values shape of the filter — captures WHICH fields were
|
|
164
|
+
* present without recording their values. (N2)
|
|
165
|
+
*/
|
|
166
|
+
filterShape: {
|
|
167
|
+
factPath: boolean;
|
|
168
|
+
constraintId: boolean;
|
|
169
|
+
kind: AuditEntryKind | readonly AuditEntryKind[] | undefined;
|
|
170
|
+
changedBetween: "[range]" | undefined;
|
|
171
|
+
};
|
|
172
|
+
erased: number;
|
|
173
|
+
});
|
|
174
|
+
interface QueryFilter {
|
|
175
|
+
/** Exact-match fact path. */
|
|
176
|
+
factPath?: string;
|
|
177
|
+
/** Filter by constraint id. */
|
|
178
|
+
constraintId?: string;
|
|
179
|
+
/** Filter by entry kind. */
|
|
180
|
+
kind?: AuditEntryKind | readonly AuditEntryKind[];
|
|
181
|
+
/** Time range as `[startMs, endMs]`, ISO strings, or epoch numbers. */
|
|
182
|
+
changedBetween?: [string | number | Date, string | number | Date];
|
|
183
|
+
/** Maximum entries returned. Default 1000. */
|
|
184
|
+
limit?: number;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Verify result — chain valid OR a break with full context for tamper visualization.
|
|
188
|
+
*
|
|
189
|
+
* Erased entries (via `ledger.erase()`) appear as legitimate chain breaks —
|
|
190
|
+
* `verify()` reports them in `erasedSeqs` and continues the walk from the
|
|
191
|
+
* tombstone's own hash. Real tamper still surfaces as `valid: false`.
|
|
192
|
+
*
|
|
193
|
+
* Forged tombstones (a caller writes `kind: "system.entry-erased"`
|
|
194
|
+
* directly via `sink.write()` to mask tamper as erasure) are detected:
|
|
195
|
+
* legitimate tombstones carry an in-module sentinel that forgeries
|
|
196
|
+
* cannot mint, so `verify()` reports them as tamper. (N7)
|
|
197
|
+
*/
|
|
198
|
+
type VerifyResult = {
|
|
199
|
+
valid: true;
|
|
200
|
+
entryCount: number;
|
|
201
|
+
/**
|
|
202
|
+
* Seq numbers of entries legitimately broken by `erase()`
|
|
203
|
+
* tombstones. NOT timestamps — each entry pairs this seq with
|
|
204
|
+
* the per-entry `system.entry-erased.erasedAt` (ms epoch) for
|
|
205
|
+
* the timestamp. Empty unless the chain contains erasures.
|
|
206
|
+
* (N1 + M1; renamed from `erasedAt` in R3)
|
|
207
|
+
*/
|
|
208
|
+
erasedSeqs?: number[];
|
|
209
|
+
} | {
|
|
210
|
+
valid: false;
|
|
211
|
+
brokenAt: number;
|
|
212
|
+
expectedHash: string;
|
|
213
|
+
actualHash: string;
|
|
214
|
+
entry: AuditEntry;
|
|
215
|
+
/**
|
|
216
|
+
* Human-readable reason for the break — populated for cases
|
|
217
|
+
* where the cause is more specific than "hash mismatch" (e.g.
|
|
218
|
+
* tombstone forgery detected via missing sentinel).
|
|
219
|
+
*/
|
|
220
|
+
reason?: string;
|
|
221
|
+
};
|
|
222
|
+
interface AuditLedgerSink {
|
|
223
|
+
write(entry: AuditEntry): void;
|
|
224
|
+
query(filter: QueryFilter): readonly AuditEntry[];
|
|
225
|
+
recent(n: number): readonly AuditEntry[];
|
|
226
|
+
forFact(path: string, opts?: {
|
|
227
|
+
limit?: number;
|
|
228
|
+
}): readonly AuditEntry[];
|
|
229
|
+
forConstraint(id: string, opts?: {
|
|
230
|
+
limit?: number;
|
|
231
|
+
}): readonly AuditEntry[];
|
|
232
|
+
toJSON(): {
|
|
233
|
+
entries: readonly AuditEntry[];
|
|
234
|
+
capturedAt: number;
|
|
235
|
+
};
|
|
236
|
+
clear(): void;
|
|
237
|
+
destroy(): void;
|
|
238
|
+
/**
|
|
239
|
+
* Replace matching entries with tombstones IN PLACE (preserving seq +
|
|
240
|
+
* prevHash so the hash chain still verifies). v1 implementation
|
|
241
|
+
* matches on the same `QueryFilter` shape used by `query()`.
|
|
242
|
+
* Returns the count of entries replaced.
|
|
243
|
+
*
|
|
244
|
+
* WARNING: erases only from this sink. Any external copies (toJSON
|
|
245
|
+
* exports, downstream pipelines) must be erased separately.
|
|
246
|
+
*/
|
|
247
|
+
erase?(filter: QueryFilter, tombstoneFactory: (e: AuditEntry) => AuditEntry): number;
|
|
248
|
+
/**
|
|
249
|
+
* Optional hook fired by the sink BEFORE shifting the oldest entry
|
|
250
|
+
* out of a bounded ring buffer. The ledger plugin uses this to emit
|
|
251
|
+
* a `system.truncated` marker so an auditor sees that the log was
|
|
252
|
+
* truncated and where. (M23)
|
|
253
|
+
*/
|
|
254
|
+
onTruncate?(handler: (droppedSeq: number, droppedCount: number) => void): void;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* In-memory bounded ring-buffer sink. Drops oldest entries past
|
|
258
|
+
* `capacity` (default 10,000). Use this as the default sink for dev,
|
|
259
|
+
* tests, and StackBlitz demos.
|
|
260
|
+
*/
|
|
261
|
+
declare function memorySink(opts?: {
|
|
262
|
+
capacity?: number;
|
|
263
|
+
}): AuditLedgerSink;
|
|
264
|
+
interface AuditLedgerOptions {
|
|
265
|
+
/** Sink to write entries to. Default: in-memory ring buffer (capacity 10k). */
|
|
266
|
+
sink?: AuditLedgerSink;
|
|
267
|
+
/**
|
|
268
|
+
* Whether to capture raw fact values (`prior`/`next` on fact.change,
|
|
269
|
+
* `actual` in whenExplain). Default `false` — PII-tagged facts are
|
|
270
|
+
* redacted by default. Set `true` to opt out of redaction.
|
|
271
|
+
*/
|
|
272
|
+
capturePII?: boolean;
|
|
273
|
+
/**
|
|
274
|
+
* Optional caller-supplied redactor. Runs AFTER the default
|
|
275
|
+
* pii-tag-based redaction. Useful for additional sanitization.
|
|
276
|
+
*/
|
|
277
|
+
redact?: (entry: AuditEntry) => AuditEntry;
|
|
278
|
+
}
|
|
279
|
+
interface AuditLedger {
|
|
280
|
+
/** The plugin to pass to `createSystem({ plugins: [...] })`. */
|
|
281
|
+
readonly plugin: Plugin<ModuleSchema>;
|
|
282
|
+
/** Query entries matching the filter. */
|
|
283
|
+
query(filter?: QueryFilter): readonly AuditEntry[];
|
|
284
|
+
/** Most recent N entries (chronological). */
|
|
285
|
+
recent(n: number): readonly AuditEntry[];
|
|
286
|
+
/** All entries that touch this fact path (exact match). */
|
|
287
|
+
forFact(path: string, opts?: {
|
|
288
|
+
limit?: number;
|
|
289
|
+
}): readonly AuditEntry[];
|
|
290
|
+
/** All entries for this constraint id. */
|
|
291
|
+
forConstraint(id: string, opts?: {
|
|
292
|
+
limit?: number;
|
|
293
|
+
}): readonly AuditEntry[];
|
|
294
|
+
/** Full ledger snapshot for export / serialization. */
|
|
295
|
+
toJSON(): {
|
|
296
|
+
entries: readonly AuditEntry[];
|
|
297
|
+
capturedAt: number;
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* Walk the hash chain genesis → tip. Returns `{ valid: true }` iff
|
|
301
|
+
* every entry's `prevHash` matches the (sync, djb2-based) hash of
|
|
302
|
+
* the previous entry. On break, returns the index of the first
|
|
303
|
+
* broken link plus the expected vs actual hashes — feed into a
|
|
304
|
+
* "TAMPERED" visualization.
|
|
305
|
+
*
|
|
306
|
+
* Erased entries (via `ledger.erase()`) appear as legitimate chain
|
|
307
|
+
* breaks — `verify()` reports them in `erasedSeqs` and continues
|
|
308
|
+
* the walk from the tombstone's actual hash. Real tamper still
|
|
309
|
+
* surfaces as `valid: false`. (N1 + M1)
|
|
310
|
+
*
|
|
311
|
+
* Forged tombstones — `kind: "system.entry-erased"` entries written
|
|
312
|
+
* directly via `sink.write()` to mask tamper — are detected as
|
|
313
|
+
* forgery. Legitimate tombstones carry an in-module sentinel that
|
|
314
|
+
* forgeries cannot mint. (N7)
|
|
315
|
+
*
|
|
316
|
+
* v1 ships sync djb2 only. `verify({ strong: true })` is reserved
|
|
317
|
+
* for v2 (SHA-256) and THROWS today — there is no silent fallback.
|
|
318
|
+
* Call `verify()` (no args) for tamper detection.
|
|
319
|
+
*/
|
|
320
|
+
verify(opts?: {
|
|
321
|
+
strong?: boolean;
|
|
322
|
+
}): VerifyResult;
|
|
323
|
+
/**
|
|
324
|
+
* Per-subject erasure (GDPR Art. 17 stub). Replaces matching entries
|
|
325
|
+
* in this sink with `system.entry-erased` tombstones (preserving
|
|
326
|
+
* seq + prevHash so verify() can resync), then appends a chained
|
|
327
|
+
* `system.subject-erased` marker entry that summarises the erasure.
|
|
328
|
+
*
|
|
329
|
+
* Returns `{ erased, markerEntry }` — `markerEntry` is the chained
|
|
330
|
+
* `system.subject-erased` summary (the N per-entry tombstones live
|
|
331
|
+
* in the sink, not on the return value). (M7)
|
|
332
|
+
*
|
|
333
|
+
* When `erased === 0` (filter matched nothing), `markerEntry` is
|
|
334
|
+
* `null` and no marker is emitted into the chain — avoids polluting
|
|
335
|
+
* the audit trail with empty "erased: 0" records. (MAJOR-3)
|
|
336
|
+
*
|
|
337
|
+
* WARNING: v1 erases only from THIS sink. External copies (toJSON
|
|
338
|
+
* exports, downstream pipelines, persisted backups) must be erased
|
|
339
|
+
* separately. (C8)
|
|
340
|
+
*/
|
|
341
|
+
erase(filter: QueryFilter): {
|
|
342
|
+
erased: number;
|
|
343
|
+
markerEntry: AuditEntry | null;
|
|
344
|
+
};
|
|
345
|
+
/** Empty the sink. */
|
|
346
|
+
clear(): void;
|
|
347
|
+
/** Unsubscribe + drop the sink. */
|
|
348
|
+
destroy(): void;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Create an audit ledger that subscribes to the given system's
|
|
352
|
+
* observation stream. Returns a `Plugin` to install + a query/verify
|
|
353
|
+
* API for the ledger.
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts
|
|
357
|
+
* import { createAuditLedger } from "@directive-run/core/plugins";
|
|
358
|
+
*
|
|
359
|
+
* const ledger = createAuditLedger();
|
|
360
|
+
* const system = createSystem({ module, plugins: [ledger.plugin] });
|
|
361
|
+
* system.start();
|
|
362
|
+
*
|
|
363
|
+
* // Six months later — auditor asks "what changed cart-total in March?"
|
|
364
|
+
* ledger.query({
|
|
365
|
+
* factPath: "cartTotal",
|
|
366
|
+
* changedBetween: ["2026-03-01", "2026-04-01"],
|
|
367
|
+
* });
|
|
368
|
+
*
|
|
369
|
+
* // Verify nobody tampered with the ledger
|
|
370
|
+
* const verdict = await ledger.verify();
|
|
371
|
+
* if (!verdict.valid) {
|
|
372
|
+
* console.error("Tamper at entry", verdict.brokenAt);
|
|
373
|
+
* }
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
declare function createAuditLedger(opts?: AuditLedgerOptions): AuditLedger;
|
|
377
|
+
|
|
378
|
+
export { type AuditEntry as A, type QueryFilter as Q, type VerifyResult as V, type AuditEntryKind as a, type AuditLedger as b, type AuditLedgerOptions as c, type AuditLedgerSink as d, createAuditLedger as e, memorySink as m };
|