@directive-run/solid 1.19.6 → 1.20.1
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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var core=require('@directive-run/core'),adapterUtils=require('@directive-run/core/adapter-utils'),solidJs=require('solid-js');var F=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var v=typeof process<"u"&&process.env?.NODE_ENV!=="production";function H(e,t){return adapterUtils.assertSystem("useFact",e),v&&typeof t=="function"&&console.error("[Directive] useFact() received a function. Did you mean useSelector()? useFact() takes a string key or array of keys, not a selector function."),Array.isArray(t)?Q(e,t):L(e,t)}function L(e,t){v&&(e.facts.$store.has(t)||console.warn(`[Directive] useFact("${t}") \u2014 fact not found in store. Check that "${t}" is defined in your module's schema.`));let[n,r]=solidJs.createSignal(e.facts.$store.get(t)),s=e.facts.$store.subscribe([t],()=>{r(()=>e.facts.$store.get(t));});return solidJs.onCleanup(s),n}function Q(e,t){let n=()=>{let i={};for(let u of t)i[u]=e.facts.$store.get(u);return i},[r,s]=solidJs.createSignal(n()),o=e.facts.$store.subscribe(t,()=>{s(n);});return solidJs.onCleanup(o),r}function N(e,t){return adapterUtils.assertSystem("useDerived",e),v&&typeof t=="function"&&console.error("[Directive] useDerived() received a function. Did you mean useSelector()? useDerived() takes a string key or array of keys, not a selector function."),Array.isArray(t)?_(e,t):W(e,t)}function W(e,t){v&&e.read(t)===void 0&&console.warn(`[Directive] useDerived("${t}") returned undefined. Check that "${t}" is defined in your module's derive property.`);let[n,r]=solidJs.createSignal(e.read(t)),s=e.subscribe([t],()=>{r(()=>e.read(t));});return solidJs.onCleanup(s),n}function _(e,t){let n=()=>{let i={};for(let u of t)i[u]=e.read(u);return i},[r,s]=solidJs.createSignal(n()),o=e.subscribe(t,()=>{s(n);});return solidJs.onCleanup(o),r}function se(e,t,n=adapterUtils.defaultEquality){adapterUtils.assertSystem("useSelector",e);let r=new Set(Object.keys(e.derive??{})),s=()=>adapterUtils.runTrackedSelector(e,r,t),o=s(),i=o.factKeys,u=o.deriveKeys,[c,f]=solidJs.createSignal(o.value),d=[],p=()=>{for(let y of d)y();d.length=0;let S=()=>{let y=s();f(m=>n(m,y.value)?m:y.value),adapterUtils.depsChanged(i,y.factKeys,u,y.deriveKeys)&&(i=y.factKeys,u=y.deriveKeys,p());};i.length>0?d.push(e.facts.$store.subscribe(i,S)):u.length===0&&d.push(e.facts.$store.subscribeAll(S)),u.length>0&&d.push(e.subscribe(u,S));};return p(),solidJs.onCleanup(()=>{for(let S of d)S();}),c}function re(e){return adapterUtils.assertSystem("useDispatch",e),t=>{e.dispatch(t);}}function B(e){return adapterUtils.assertSystem("useEvents",e),e.events}function j(e,t,n){adapterUtils.assertSystem("useWatch",e);let r=e.watch(t,n);solidJs.onCleanup(r);}function oe(e,t){adapterUtils.assertSystem("useInspect",e);let[n,r]=solidJs.createSignal(adapterUtils.computeInspectState(e)),s=()=>{r(adapterUtils.computeInspectState(e));};if(t?.throttleMs&&t.throttleMs>0){let{throttled:o,cleanup:i}=adapterUtils.createThrottle(s,t.throttleMs),u=e.facts.$store.subscribeAll(o),c=e.onSettledChange(o);solidJs.onCleanup(()=>{i(),u(),c();});}else {let o=e.facts.$store.subscribeAll(s),i=e.onSettledChange(s);solidJs.onCleanup(()=>{o(),i();});}return n}function R(e,t){if(Array.isArray(t)){let o=()=>{let f={};for(let d of t)f[d]=e.getStatus(d);return f},[i,u]=solidJs.createSignal(o()),c=e.subscribe(()=>{u(o);});return solidJs.onCleanup(c),i}let[n,r]=solidJs.createSignal(e.getStatus(t)),s=e.subscribe(()=>{r(e.getStatus(t));});return solidJs.onCleanup(s),n}function ie(e,t){adapterUtils.assertSystem("useExplain",e);let[n,r]=solidJs.createSignal(e.explain(t)),s=()=>r(e.explain(t)),o=e.facts.$store.subscribeAll(s),i=e.onSettledChange(s);return solidJs.onCleanup(()=>{o(),i();}),n}function ue(e,t){adapterUtils.assertSystem("useConstraintStatus",e);let n=()=>{let c=e.inspect();return t?c.constraints.find(f=>f.id===t)??null:c.constraints},[r,s]=solidJs.createSignal(n()),o=()=>s(n),i=e.facts.$store.subscribeAll(o),u=e.onSettledChange(o);return solidJs.onCleanup(()=>{i(),u();}),r}function ce(e,t,n){adapterUtils.assertSystem("useOptimisticUpdate",e);let[r,s]=solidJs.createSignal(false),[o,i]=solidJs.createSignal(null),u=null,c=null,f=()=>{u&&(e.restore(u),u=null),s(false),i(null),c?.(),c=null;},d=p=>{u=e.getSnapshot(),s(true),i(null),e.batch(p),t&&n&&(c?.(),c=t.subscribe(()=>{let S=t.getStatus(n);!S.isLoading&&!S.hasError?(u=null,s(false),c?.(),c=null):S.hasError&&(i(()=>S.lastError),f());}));};return solidJs.onCleanup(()=>{c?.();}),{mutate:d,isPending:r,error:o,rollback:f}}function ae(e,t){let n=Array.isArray(t)?t:[t],r=()=>n.some(s=>e.getStatus(s).isLoading);if(r())throw new Promise(s=>{let o=e.subscribe(()=>{r()||(o(),s());});});return R(e,t)}function le(e){adapterUtils.assertSystem("useHistory",e);let[t,n]=solidJs.createSignal(adapterUtils.buildHistoryState(e)),r=e.onHistoryChange(()=>n(adapterUtils.buildHistoryState(e)));return solidJs.onCleanup(r),t}function z(e,t){let n=[...t?.plugins??[]],r;if(t?.status){let M=core.createRequirementStatusPlugin();r=M,n.push(M.plugin);}let s=core.createSystem({module:e,plugins:n.length>0?n:void 0,trace:t?.trace,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:t?.initialFacts});typeof window<"u"?s.start():s.initialize(),solidJs.onCleanup(()=>{s.
|
|
1
|
+
'use strict';var core=require('@directive-run/core'),adapterUtils=require('@directive-run/core/adapter-utils'),solidJs=require('solid-js');var F=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var v=typeof process<"u"&&process.env?.NODE_ENV!=="production";function H(e,t){return adapterUtils.assertSystem("useFact",e),v&&typeof t=="function"&&console.error("[Directive] useFact() received a function. Did you mean useSelector()? useFact() takes a string key or array of keys, not a selector function."),Array.isArray(t)?Q(e,t):L(e,t)}function L(e,t){v&&(e.facts.$store.has(t)||console.warn(`[Directive] useFact("${t}") \u2014 fact not found in store. Check that "${t}" is defined in your module's schema.`));let[n,r]=solidJs.createSignal(e.facts.$store.get(t)),s=e.facts.$store.subscribe([t],()=>{r(()=>e.facts.$store.get(t));});return solidJs.onCleanup(s),n}function Q(e,t){let n=()=>{let i={};for(let u of t)i[u]=e.facts.$store.get(u);return i},[r,s]=solidJs.createSignal(n()),o=e.facts.$store.subscribe(t,()=>{s(n);});return solidJs.onCleanup(o),r}function N(e,t){return adapterUtils.assertSystem("useDerived",e),v&&typeof t=="function"&&console.error("[Directive] useDerived() received a function. Did you mean useSelector()? useDerived() takes a string key or array of keys, not a selector function."),Array.isArray(t)?_(e,t):W(e,t)}function W(e,t){v&&e.read(t)===void 0&&console.warn(`[Directive] useDerived("${t}") returned undefined. Check that "${t}" is defined in your module's derive property.`);let[n,r]=solidJs.createSignal(e.read(t)),s=e.subscribe([t],()=>{r(()=>e.read(t));});return solidJs.onCleanup(s),n}function _(e,t){let n=()=>{let i={};for(let u of t)i[u]=e.read(u);return i},[r,s]=solidJs.createSignal(n()),o=e.subscribe(t,()=>{s(n);});return solidJs.onCleanup(o),r}function se(e,t,n=adapterUtils.defaultEquality){adapterUtils.assertSystem("useSelector",e);let r=new Set(Object.keys(e.derive??{})),s=()=>adapterUtils.runTrackedSelector(e,r,t),o=s(),i=o.factKeys,u=o.deriveKeys,[c,f]=solidJs.createSignal(o.value),d=[],p=()=>{for(let y of d)y();d.length=0;let S=()=>{let y=s();f(m=>n(m,y.value)?m:y.value),adapterUtils.depsChanged(i,y.factKeys,u,y.deriveKeys)&&(i=y.factKeys,u=y.deriveKeys,p());};i.length>0?d.push(e.facts.$store.subscribe(i,S)):u.length===0&&d.push(e.facts.$store.subscribeAll(S)),u.length>0&&d.push(e.subscribe(u,S));};return p(),solidJs.onCleanup(()=>{for(let S of d)S();}),c}function re(e){return adapterUtils.assertSystem("useDispatch",e),t=>{e.dispatch(t);}}function B(e){return adapterUtils.assertSystem("useEvents",e),e.events}function j(e,t,n){adapterUtils.assertSystem("useWatch",e);let r=e.watch(t,n);solidJs.onCleanup(r);}function oe(e,t){adapterUtils.assertSystem("useInspect",e);let[n,r]=solidJs.createSignal(adapterUtils.computeInspectState(e)),s=()=>{r(adapterUtils.computeInspectState(e));};if(t?.throttleMs&&t.throttleMs>0){let{throttled:o,cleanup:i}=adapterUtils.createThrottle(s,t.throttleMs),u=e.facts.$store.subscribeAll(o),c=e.onSettledChange(o);solidJs.onCleanup(()=>{i(),u(),c();});}else {let o=e.facts.$store.subscribeAll(s),i=e.onSettledChange(s);solidJs.onCleanup(()=>{o(),i();});}return n}function R(e,t){if(Array.isArray(t)){let o=()=>{let f={};for(let d of t)f[d]=e.getStatus(d);return f},[i,u]=solidJs.createSignal(o()),c=e.subscribe(()=>{u(o);});return solidJs.onCleanup(c),i}let[n,r]=solidJs.createSignal(e.getStatus(t)),s=e.subscribe(()=>{r(e.getStatus(t));});return solidJs.onCleanup(s),n}function ie(e,t){adapterUtils.assertSystem("useExplain",e);let[n,r]=solidJs.createSignal(e.explain(t)),s=()=>r(e.explain(t)),o=e.facts.$store.subscribeAll(s),i=e.onSettledChange(s);return solidJs.onCleanup(()=>{o(),i();}),n}function ue(e,t){adapterUtils.assertSystem("useConstraintStatus",e);let n=()=>{let c=e.inspect();return t?c.constraints.find(f=>f.id===t)??null:c.constraints},[r,s]=solidJs.createSignal(n()),o=()=>s(n),i=e.facts.$store.subscribeAll(o),u=e.onSettledChange(o);return solidJs.onCleanup(()=>{i(),u();}),r}function ce(e,t,n){adapterUtils.assertSystem("useOptimisticUpdate",e);let[r,s]=solidJs.createSignal(false),[o,i]=solidJs.createSignal(null),u=null,c=null,f=()=>{u&&(e.restore(u),u=null),s(false),i(null),c?.(),c=null;},d=p=>{u=e.getSnapshot(),s(true),i(null),e.batch(p),t&&n&&(c?.(),c=t.subscribe(()=>{let S=t.getStatus(n);!S.isLoading&&!S.hasError?(u=null,s(false),c?.(),c=null):S.hasError&&(i(()=>S.lastError),f());}));};return solidJs.onCleanup(()=>{c?.();}),{mutate:d,isPending:r,error:o,rollback:f}}function ae(e,t){let n=Array.isArray(t)?t:[t],r=()=>n.some(s=>e.getStatus(s).isLoading);if(r())throw new Promise(s=>{let o=e.subscribe(()=>{r()||(o(),s());});});return R(e,t)}function le(e){adapterUtils.assertSystem("useHistory",e);let[t,n]=solidJs.createSignal(adapterUtils.buildHistoryState(e)),r=e.onHistoryChange(()=>n(adapterUtils.buildHistoryState(e)));return solidJs.onCleanup(r),t}function z(e,t){let n=[...t?.plugins??[]],r;if(t?.status){let M=core.createRequirementStatusPlugin();r=M,n.push(M.plugin);}let s=core.createSystem({module:e,plugins:n.length>0?n:void 0,trace:t?.trace,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:t?.initialFacts});typeof window<"u"?s.start():s.initialize(),solidJs.onCleanup(()=>{s.destroyAsync().catch(()=>{});});let o=t?.facts,i=t?.derived,u=!o&&!i,[c,f]=solidJs.createSignal(u?s.facts.$store.toObject():adapterUtils.pickFacts(s,o??[])),d=u?s.facts.$store.subscribeAll(()=>{f(()=>s.facts.$store.toObject());}):o&&o.length>0?s.facts.$store.subscribe(o,()=>{f(()=>adapterUtils.pickFacts(s,o));}):null,p=u?Object.keys(s.derive??{}):i??[],S=()=>{let M={};for(let h of p)M[h]=s.read(h);return M},[y,m]=solidJs.createSignal(S()),I=p.length>0?s.subscribe(p,()=>{m(S);}):null;solidJs.onCleanup(()=>{d?.(),I?.();});let w=s.events;return {system:s,facts:c,derived:y,events:w,dispatch:M=>s.dispatch(M),statusPlugin:r}}function de(e,t){let[n,r]=solidJs.createSignal(e.read(t)),s=e.subscribe([t],()=>{r(()=>e.read(t));});return [n,s]}function Se(e,t){let[n,r]=solidJs.createSignal(e.facts.$store.get(t)),s=e.facts.$store.subscribe([t],()=>{r(()=>e.facts.$store.get(t));});return [n,s]}function fe(){return {useFact:(e,t)=>H(e,t),useDerived:(e,t)=>N(e,t),useDispatch:e=>t=>{e.dispatch(t);},useEvents:e=>B(e),useWatch:(e,t,n)=>j(e,t,n)}}function ge(e,t,n){let[r,s]=solidJs.createSignal(n(e)),o=e.subscribe(t,()=>{s(()=>n(e));});return solidJs.onCleanup(o),r}var b=null;function J(){if(!b)try{b=F("@directive-run/query").createQuerySystem;}catch{throw new Error("[Directive] @directive-run/query is not installed. Install it with: pnpm add @directive-run/query")}return b}function ye(e){let n=J()(e);return typeof window<"u"&&!n.isRunning&&n.start(),solidJs.onCleanup(()=>{n.destroyAsync().catch(()=>{});}),n}var D=solidJs.createContext(),pe=D.Provider;function Me(e,t){let n=solidJs.useContext(D),r=adapterUtils.mergeHydrationFacts(n,t?.initialFacts);return z(e,{...t,initialFacts:r}).system}function ve(e,t={},n={}){let r=n.pollMs??250,s=Math.max(50,r);if(v&&(n.pollMs!==void 0&&n.pollMs<50&&console.warn(`[Directive] useAuditLedger() pollMs=${n.pollMs} is below the 50 ms floor; clamped to 50 ms.`),s<100)){let c=e.toJSON().entries.length;c>1e3&&console.warn(`[Directive] useAuditLedger() polling every ${s} ms against a ${c}-entry ledger \u2014 that's a lot of CPU per tick. Consider raising pollMs or tightening the filter.`);}let[o,i]=solidJs.createSignal(e.query(t)),u=setInterval(()=>i(()=>e.query(t)),s);return solidJs.onCleanup(()=>clearInterval(u)),o}Object.defineProperty(exports,"shallowEqual",{enumerable:true,get:function(){return adapterUtils.shallowEqual}});exports.DirectiveHydrator=pe;exports.createDerivedSignal=de;exports.createFactSignal=Se;exports.createTypedHooks=fe;exports.useAuditLedger=ve;exports.useConstraintStatus=ue;exports.useDerived=N;exports.useDirective=z;exports.useDispatch=re;exports.useEvents=B;exports.useExplain=ie;exports.useFact=H;exports.useHistory=le;exports.useHydratedSystem=Me;exports.useInspect=oe;exports.useNamespacedSelector=ge;exports.useOptimisticUpdate=ce;exports.useQuerySystem=ye;exports.useRequirementStatus=R;exports.useSelector=se;exports.useSuspenseRequirement=ae;exports.useWatch=j;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dev-true.ts","../src/index.ts"],"names":["dev_true_default","useFact","system","keyOrKeys","assertSystem","_useFactMulti","_useFactSingle","factKey","value","setValue","createSignal","unsubscribe","onCleanup","factKeys","getValues","result","key","state","setState","useDerived","idOrIds","_useDerivedMulti","_useDerivedSingle","derivationId","derivationIds","id","useSelector","selector","equalityFn","defaultEquality","deriveKeySet","runWithTracking","runTrackedSelector","initial","trackedFactKeys","trackedDeriveKeys","selected","setSelected","unsubs","resubscribe","unsub","onUpdate","prev","depsChanged","useDispatch","event","useEvents","useWatch","callback","useInspect","options","computeInspectState","update","throttled","cleanup","createThrottle","unsubFacts","unsubSettled","useRequirementStatus","statusPlugin","typeOrTypes","type","status","setStatus","useExplain","requirementId","explanation","setExplanation","useConstraintStatus","constraintId","getVal","inspection","c","useOptimisticUpdate","requirementType","isPending","setIsPending","error","setError","snapshot","statusUnsub","rollback","mutate","updateFn","useSuspenseRequirement","types","anyLoading","t","resolve","useHistory","buildHistoryState","useDirective","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","createSystem","derivedKeys","subscribeAll","factsState","setFactsState","pickFacts","allDerivationKeys","getDerived","derivedState","setDerivedState","unsubDerived","events","createDerivedSignal","createFactSignal","createTypedHooks","useNamespacedSelector","keys","_createQuerySystem","getCreateQuerySystem","useQuerySystem","HydrationContext","createContext","DirectiveHydrator","useHydratedSystem","useContext","mergedFacts","mergeHydrationFacts","useAuditLedger","ledger","filter","opts","requestedPollMs","pollMs","entryCount","entries","setEntries"],"mappings":"oYAAA,IAAOA,CAAAA,CAAQ,OAAO,OAAA,CAAY,GAAA,EAChC,QAAQ,GAAA,EAAK,QAAA,GAAa,YAAA,CCiFrB,SAASC,CAAAA,CAEdC,CAAAA,CACAC,EACmB,CAUnB,OATAC,0BAAa,SAAA,CAAWF,CAAM,EAC1BF,CAAAA,EAAiB,OAAOG,GAAc,UAAA,EACxC,OAAA,CAAQ,MACN,gJAEF,CAAA,CAIE,MAAM,OAAA,CAAQA,CAAS,EAClBE,CAAAA,CAAcH,CAAAA,CAAQC,CAAS,CAAA,CAIjCG,CAAAA,CAAeJ,CAAAA,CAAQC,CAAS,CACzC,CAGA,SAASG,CAAAA,CACPJ,CAAAA,CACAK,EACmB,CACfP,CAAAA,GACGE,CAAAA,CAAO,KAAA,CAAM,MAAA,CAAO,GAAA,CAAIK,CAAO,CAAA,EAClC,OAAA,CAAQ,KACN,CAAA,qBAAA,EAAwBA,CAAO,kDACdA,CAAO,CAAA,qCAAA,CAC1B,CAAA,CAAA,CAIJ,GAAM,CAACC,CAAAA,CAAOC,CAAQ,CAAA,CAAIC,oBAAAA,CAAaR,EAAO,KAAA,CAAM,MAAA,CAAO,IAAIK,CAAO,CAAC,EACjEI,CAAAA,CAAcT,CAAAA,CAAO,MAAM,MAAA,CAAO,SAAA,CAAU,CAACK,CAAO,CAAA,CAAG,IAAM,CACjEE,CAAAA,CAAS,IAAMP,CAAAA,CAAO,KAAA,CAAM,MAAA,CAAO,IAAIK,CAAO,CAAC,EACjD,CAAC,CAAA,CACD,OAAAK,iBAAAA,CAAUD,CAAW,CAAA,CACdH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,CAAE,GAAGC,CAAAA,CAAQ,YAAA,CAAc6B,CAAY,CAAC,CAAA,CACpE,MACL,CAiCO,SAASE,GACdC,CAAAA,CACAC,CAAAA,CAAsB,EAAC,CACvBC,CAAAA,CAA4B,EAAC,CACI,CACjC,IAAMC,EAAkBD,CAAAA,CAAK,MAAA,EAAU,IACjCE,CAAAA,CAAS,IAAA,CAAK,IAAI,EAAA,CAAID,CAAe,CAAA,CAE3C,GAAIhI,CAAAA,GACE+H,CAAAA,CAAK,SAAW,MAAA,EAAaA,CAAAA,CAAK,OAAS,EAAA,EAC7C,OAAA,CAAQ,KACN,CAAA,oCAAA,EAAuCA,CAAAA,CAAK,MAAM,CAAA,4CAAA,CACpD,CAAA,CAEEE,CAAAA,CAAS,KAAK,CAChB,IAAMC,EAAaL,CAAAA,CAAO,MAAA,GAAS,OAAA,CAAQ,MAAA,CACvCK,CAAAA,CAAa,GAAA,EACf,OAAA,CAAQ,IAAA,CACN,8CAA8CD,CAAM,CAAA,cAAA,EAAiBC,CAAU,CAAA,oGAAA,CACjF,EAEJ,CAGF,GAAM,CAACC,CAAAA,CAASC,CAAU,CAAA,CAAI1H,oBAAAA,CAC5BmH,EAAO,KAAA,CAAMC,CAAM,CACrB,CAAA,CACMrG,CAAAA,CAAK,YAAY,IAAM2G,CAAAA,CAAW,IAAMP,CAAAA,CAAO,KAAA,CAAMC,CAAM,CAAC,CAAA,CAAGG,CAAM,EAC3E,OAAArH,iBAAAA,CAAU,IAAM,aAAA,CAAca,CAAE,CAAC,CAAA,CAE1B0G,CACT","file":"index.cjs","sourcesContent":["export default typeof process !== \"undefined\" &&\n process.env?.NODE_ENV !== \"production\";\n","/**\n * Solid Adapter - Consolidated SolidJS primitives for Directive\n *\n * 16 active exports: useFact, useDerived, useDispatch, useSelector,\n * useWatch, useInspect, useRequirementStatus, useEvents, useExplain,\n * useConstraintStatus, useOptimisticUpdate, useDirective, useHistory,\n * createTypedHooks, useSuspenseRequirement, shallowEqual\n *\n * Signal factories: createDerivedSignal, createFactSignal\n */\n\nimport type {\n ErrorBoundaryConfig,\n InferDerivations,\n InferEvents,\n InferFacts,\n InferSelectorState,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemSnapshot,\n TraceOption,\n} from \"@directive-run/core\";\nimport {\n createRequirementStatusPlugin,\n createSystem,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n type ConstraintInfo,\n type InspectState,\n assertSystem,\n buildHistoryState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n mergeHydrationFacts,\n pickFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport {\n type Accessor,\n createContext,\n createSignal,\n onCleanup,\n useContext,\n} from \"solid-js\";\nimport isDevelopment from \"#is-development\";\n\n// Re-export for convenience\nexport type { RequirementTypeStatus, InspectState, ConstraintInfo };\nexport { shallowEqual };\n\n/** Type for the requirement status plugin return value */\nexport type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;\n\n// ============================================================================\n// useFact — single key or multi key\n// ============================================================================\n\n/** Single key overload */\nexport function useFact<\n S extends ModuleSchema,\n K extends keyof InferFacts<S> & string,\n>(\n system: SingleModuleSystem<S>,\n factKey: K,\n): Accessor<InferFacts<S>[K] | undefined>;\n/** Multi-key overload */\nexport function useFact<\n S extends ModuleSchema,\n K extends keyof InferFacts<S> & string,\n>(\n system: SingleModuleSystem<S>,\n factKeys: K[],\n): Accessor<Pick<InferFacts<S>, K>>;\n/** Implementation */\nexport function useFact(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n keyOrKeys: string | string[],\n): Accessor<unknown> {\n assertSystem(\"useFact\", system);\n if (isDevelopment && typeof keyOrKeys === \"function\") {\n console.error(\n \"[Directive] useFact() received a function. Did you mean useSelector()? \" +\n \"useFact() takes a string key or array of keys, not a selector function.\",\n );\n }\n\n // Multi-key path\n if (Array.isArray(keyOrKeys)) {\n return _useFactMulti(system, keyOrKeys);\n }\n\n // Single key path\n return _useFactSingle(system, keyOrKeys);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactSingle(\n system: SingleModuleSystem<any>,\n factKey: string,\n): Accessor<unknown> {\n if (isDevelopment) {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] useFact(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n\n const [value, setValue] = createSignal(system.facts.$store.get(factKey));\n const unsubscribe = system.facts.$store.subscribe([factKey], () => {\n setValue(() => system.facts.$store.get(factKey));\n });\n onCleanup(unsubscribe);\n return value;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactMulti(\n system: SingleModuleSystem<any>,\n factKeys: string[],\n): Accessor<Record<string, unknown>> {\n const getValues = (): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n for (const key of factKeys) {\n result[key] = system.facts.$store.get(key);\n }\n return result;\n };\n const [state, setState] = createSignal(getValues());\n const unsubscribe = system.facts.$store.subscribe(factKeys, () => {\n setState(getValues);\n });\n onCleanup(unsubscribe);\n return state;\n}\n\n// ============================================================================\n// useDerived — single key or multi key\n// ============================================================================\n\n/** Single key overload */\nexport function useDerived<\n S extends ModuleSchema,\n K extends keyof InferDerivations<S> & string,\n>(\n system: SingleModuleSystem<S>,\n derivationId: K,\n): Accessor<InferDerivations<S>[K]>;\n/** Multi-key overload */\nexport function useDerived<\n S extends ModuleSchema,\n K extends keyof InferDerivations<S> & string,\n>(\n system: SingleModuleSystem<S>,\n derivationIds: K[],\n): Accessor<Pick<InferDerivations<S>, K>>;\n/** Implementation */\nexport function useDerived(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n idOrIds: string | string[],\n): Accessor<unknown> {\n assertSystem(\"useDerived\", system);\n if (isDevelopment && typeof idOrIds === \"function\") {\n console.error(\n \"[Directive] useDerived() received a function. Did you mean useSelector()? \" +\n \"useDerived() takes a string key or array of keys, not a selector function.\",\n );\n }\n\n // Multi-key path\n if (Array.isArray(idOrIds)) {\n return _useDerivedMulti(system, idOrIds);\n }\n\n // Single key path\n return _useDerivedSingle(system, idOrIds);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useDerivedSingle(\n system: SingleModuleSystem<any>,\n derivationId: string,\n): Accessor<unknown> {\n if (isDevelopment) {\n const initialValue = system.read(derivationId);\n if (initialValue === undefined) {\n console.warn(\n `[Directive] useDerived(\"${derivationId}\") returned undefined. ` +\n `Check that \"${derivationId}\" is defined in your module's derive property.`,\n );\n }\n }\n const [value, setValue] = createSignal(system.read(derivationId));\n const unsubscribe = system.subscribe([derivationId], () => {\n setValue(() => system.read(derivationId));\n });\n onCleanup(unsubscribe);\n return value;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useDerivedMulti(\n system: SingleModuleSystem<any>,\n derivationIds: string[],\n): Accessor<Record<string, unknown>> {\n const getValues = (): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n for (const id of derivationIds) {\n result[id] = system.read(id);\n }\n return result;\n };\n const [state, setState] = createSignal(getValues());\n const unsubscribe = system.subscribe(derivationIds, () => {\n setState(getValues);\n });\n onCleanup(unsubscribe);\n return state;\n}\n\n// ============================================================================\n// useSelector — auto-tracking selector over facts and derivations\n// ============================================================================\n\n/**\n * Auto-tracking selector over facts and derivations.\n * Uses `withTracking()` to detect which facts the selector accesses,\n * then subscribes only to those keys.\n */\nexport function useSelector<S extends ModuleSchema, R>(\n system: SingleModuleSystem<S>,\n selector: (state: InferSelectorState<S>) => R,\n equalityFn?: (a: R, b: R) => boolean,\n): Accessor<R>;\nexport function useSelector(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n selector: (state: any) => unknown,\n equalityFn: (a: unknown, b: unknown) => boolean = defaultEquality,\n): Accessor<unknown> {\n assertSystem(\"useSelector\", system);\n const deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n // Build a tracking-aware state proxy that exposes both facts and derivations\n const runWithTracking = () =>\n runTrackedSelector(system, deriveKeySet, selector);\n\n const initial = runWithTracking();\n let trackedFactKeys = initial.factKeys;\n let trackedDeriveKeys = initial.deriveKeys;\n const [selected, setSelected] = createSignal(initial.value);\n\n const unsubs: Array<() => void> = [];\n\n const resubscribe = () => {\n for (const unsub of unsubs) unsub();\n unsubs.length = 0;\n\n const onUpdate = () => {\n const result = runWithTracking();\n setSelected((prev) => {\n if (!equalityFn(prev, result.value)) return result.value;\n return prev;\n });\n // Re-track: check if deps changed\n if (\n depsChanged(\n trackedFactKeys,\n result.factKeys,\n trackedDeriveKeys,\n result.deriveKeys,\n )\n ) {\n trackedFactKeys = result.factKeys;\n trackedDeriveKeys = result.deriveKeys;\n resubscribe();\n }\n };\n\n if (trackedFactKeys.length > 0) {\n unsubs.push(system.facts.$store.subscribe(trackedFactKeys, onUpdate));\n } else if (trackedDeriveKeys.length === 0) {\n unsubs.push(system.facts.$store.subscribeAll(onUpdate));\n }\n if (trackedDeriveKeys.length > 0) {\n unsubs.push(system.subscribe(trackedDeriveKeys, onUpdate));\n }\n };\n\n resubscribe();\n\n onCleanup(() => {\n for (const unsub of unsubs) unsub();\n });\n\n return selected;\n}\n\n// ============================================================================\n// useDispatch\n// ============================================================================\n\nexport function useDispatch<S extends ModuleSchema>(\n system: SingleModuleSystem<S>,\n): (event: InferEvents<S>) => void {\n assertSystem(\"useDispatch\", system);\n return (event: InferEvents<S>) => {\n system.dispatch(event);\n };\n}\n\n// ============================================================================\n// useEvents — memoized events reference\n// ============================================================================\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<S extends ModuleSchema>(\n system: SingleModuleSystem<S>,\n): SingleModuleSystem<S>[\"events\"] {\n assertSystem(\"useEvents\", system);\n return system.events;\n}\n\n// ============================================================================\n// useWatch — derivation or fact side-effect\n// ============================================================================\n\n/** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */\nexport function useWatch<\n S extends ModuleSchema,\n K extends keyof InferDerivations<S> & string,\n>(\n system: SingleModuleSystem<S>,\n key: K,\n callback: (\n newValue: InferDerivations<S>[K],\n previousValue: InferDerivations<S>[K] | undefined,\n ) => void,\n): void;\n/** Watch a fact key with auto-detection. */\nexport function useWatch<\n S extends ModuleSchema,\n K extends keyof InferFacts<S> & string,\n>(\n system: SingleModuleSystem<S>,\n key: K,\n callback: (\n newValue: InferFacts<S>[K] | undefined,\n previousValue: InferFacts<S>[K] | undefined,\n ) => void,\n): void;\n/** Implementation */\nexport function useWatch(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n key: string,\n callback: (newValue: unknown, prevValue: unknown) => void,\n): void {\n assertSystem(\"useWatch\", system);\n\n const unsubscribe = system.watch(key, callback);\n onCleanup(unsubscribe);\n}\n\n// ============================================================================\n// useInspect — consolidated inspection hook\n// ============================================================================\n\n/** Options for useInspect */\nexport interface UseInspectOptions {\n throttleMs?: number;\n}\n\n/**\n * Consolidated system inspection hook.\n * Returns Accessor<InspectState> with optional throttling.\n */\nexport function useInspect(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n options?: UseInspectOptions,\n): Accessor<InspectState> {\n assertSystem(\"useInspect\", system);\n const [state, setState] = createSignal<InspectState>(\n computeInspectState(system),\n );\n\n const update = () => {\n setState(computeInspectState(system));\n };\n\n if (options?.throttleMs && options.throttleMs > 0) {\n const { throttled, cleanup } = createThrottle(update, options.throttleMs);\n const unsubFacts = system.facts.$store.subscribeAll(throttled);\n const unsubSettled = system.onSettledChange(throttled);\n onCleanup(() => {\n cleanup();\n unsubFacts();\n unsubSettled();\n });\n } else {\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n onCleanup(() => {\n unsubFacts();\n unsubSettled();\n });\n }\n\n return state;\n}\n\n// ============================================================================\n// useRequirementStatus — single or multi\n// ============================================================================\n\n/** Single type overload */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n type: string,\n): Accessor<RequirementTypeStatus>;\n/** Multi-type overload */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n types: string[],\n): Accessor<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n typeOrTypes: string | string[],\n):\n | Accessor<RequirementTypeStatus>\n | Accessor<Record<string, RequirementTypeStatus>> {\n if (Array.isArray(typeOrTypes)) {\n const getValues = (): Record<string, RequirementTypeStatus> => {\n const result: Record<string, RequirementTypeStatus> = {};\n for (const type of typeOrTypes) {\n result[type] = statusPlugin.getStatus(type);\n }\n return result;\n };\n const [state, setState] = createSignal(getValues());\n const unsubscribe = statusPlugin.subscribe(() => {\n setState(getValues);\n });\n onCleanup(unsubscribe);\n return state;\n }\n\n const [status, setStatus] = createSignal<RequirementTypeStatus>(\n statusPlugin.getStatus(typeOrTypes),\n );\n const unsubscribe = statusPlugin.subscribe(() => {\n setStatus(statusPlugin.getStatus(typeOrTypes));\n });\n onCleanup(unsubscribe);\n return status;\n}\n\n// ============================================================================\n// useExplain — reactive requirement explanation\n// ============================================================================\n\n/**\n * Reactively returns the explanation string for a requirement.\n */\nexport function useExplain(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n requirementId: string,\n): Accessor<string | null> {\n assertSystem(\"useExplain\", system);\n const [explanation, setExplanation] = createSignal<string | null>(\n system.explain(requirementId),\n );\n\n const update = () => setExplanation(system.explain(requirementId));\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n onCleanup(() => {\n unsubFacts();\n unsubSettled();\n });\n\n return explanation;\n}\n\n// ============================================================================\n// useConstraintStatus — reactive constraint inspection\n// ============================================================================\n\n/** Get all constraints */\nexport function useConstraintStatus(\n system: SingleModuleSystem<any>,\n): Accessor<ConstraintInfo[]>;\n/** Get a single constraint by ID */\nexport function useConstraintStatus(\n system: SingleModuleSystem<any>,\n constraintId: string,\n): Accessor<ConstraintInfo | null>;\n/** Implementation */\nexport function useConstraintStatus(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): Accessor<ConstraintInfo[] | ConstraintInfo | null> {\n assertSystem(\"useConstraintStatus\", system);\n const getVal = () => {\n const inspection = system.inspect();\n if (!constraintId) return inspection.constraints;\n return (\n inspection.constraints.find(\n (c: ConstraintInfo) => c.id === constraintId,\n ) ?? null\n );\n };\n\n const [state, setState] = createSignal<\n ConstraintInfo[] | ConstraintInfo | null\n >(getVal());\n\n const update = () => setState(getVal);\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n onCleanup(() => {\n unsubFacts();\n unsubSettled();\n });\n\n return state;\n}\n\n// ============================================================================\n// useOptimisticUpdate — batch with rollback on failure\n// ============================================================================\n\nexport interface OptimisticUpdateResult {\n mutate: (updateFn: () => void) => void;\n isPending: Accessor<boolean>;\n error: Accessor<Error | null>;\n rollback: () => void;\n}\n\n/**\n * Optimistic update hook. Saves a snapshot before mutating, monitors\n * a requirement type via statusPlugin, and rolls back on failure.\n */\nexport function useOptimisticUpdate(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n): OptimisticUpdateResult {\n assertSystem(\"useOptimisticUpdate\", system);\n const [isPending, setIsPending] = createSignal(false);\n const [error, setError] = createSignal<Error | null>(null);\n let snapshot: SystemSnapshot | null = null;\n let statusUnsub: (() => void) | null = null;\n\n const rollback = () => {\n if (snapshot) {\n system.restore(snapshot);\n snapshot = null;\n }\n setIsPending(false);\n setError(null);\n statusUnsub?.();\n statusUnsub = null;\n };\n\n const mutate = (updateFn: () => void) => {\n snapshot = system.getSnapshot();\n setIsPending(true);\n setError(null);\n system.batch(updateFn);\n\n if (statusPlugin && requirementType) {\n statusUnsub?.();\n statusUnsub = statusPlugin.subscribe(() => {\n const status = statusPlugin.getStatus(requirementType);\n if (!status.isLoading && !status.hasError) {\n snapshot = null;\n setIsPending(false);\n statusUnsub?.();\n statusUnsub = null;\n } else if (status.hasError) {\n setError(() => status.lastError);\n rollback();\n }\n });\n }\n };\n\n onCleanup(() => {\n statusUnsub?.();\n });\n\n return { mutate, isPending, error, rollback };\n}\n\n// ============================================================================\n// useSuspenseRequirement — Solid-specific Suspense integration\n// ============================================================================\n\n/**\n * Single type: throws a promise while the requirement is pending (Suspense).\n */\nexport function useSuspenseRequirement(\n statusPlugin: StatusPlugin,\n type: string,\n): Accessor<RequirementTypeStatus>;\n/**\n * Multi-type: throws a promise while any of the requirements are pending.\n */\nexport function useSuspenseRequirement(\n statusPlugin: StatusPlugin,\n types: string[],\n): Accessor<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useSuspenseRequirement(\n statusPlugin: StatusPlugin,\n typeOrTypes: string | string[],\n):\n | Accessor<RequirementTypeStatus>\n | Accessor<Record<string, RequirementTypeStatus>> {\n const types = Array.isArray(typeOrTypes) ? typeOrTypes : [typeOrTypes];\n\n // Check if any are still loading — if so, throw a promise\n const anyLoading = () =>\n types.some((t) => statusPlugin.getStatus(t).isLoading);\n\n if (anyLoading()) {\n throw new Promise<void>((resolve) => {\n const unsub = statusPlugin.subscribe(() => {\n if (!anyLoading()) {\n unsub();\n resolve();\n }\n });\n });\n }\n\n // Once resolved, return normal accessor\n if (Array.isArray(typeOrTypes)) {\n return useRequirementStatus(statusPlugin, typeOrTypes) as Accessor<\n Record<string, RequirementTypeStatus>\n >;\n }\n return useRequirementStatus(\n statusPlugin,\n typeOrTypes,\n ) as Accessor<RequirementTypeStatus>;\n}\n\n// ============================================================================\n// useHistory — reactive history signal\n// ============================================================================\n\n/**\n * Reactive history signal. Returns an Accessor that updates\n * when snapshots are taken or navigation occurs.\n *\n * @example\n * ```tsx\n * const history = useHistory(system);\n * <button disabled={!history()?.canGoBack} onClick={() => history()?.goBack()}>Undo</button>\n * ```\n */\nexport function useHistory(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n): Accessor<ReturnType<typeof buildHistoryState>> {\n assertSystem(\"useHistory\", system);\n const [state, setState] = createSignal<ReturnType<typeof buildHistoryState>>(\n buildHistoryState(system),\n );\n const unsub = system.onHistoryChange(() =>\n setState(buildHistoryState(system)),\n );\n onCleanup(unsub);\n return state;\n}\n\n// ============================================================================\n// Scoped System\n// ============================================================================\n\n/** Configuration for useDirective */\ninterface UseDirectiveConfig {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n /** Fact keys to subscribe to (omit for all) */\n facts?: string[];\n /** Derivation keys to subscribe to (omit for all) */\n derived?: string[];\n}\n\n/**\n * Create a scoped Directive system with automatic lifecycle management.\n * When no `facts` or `derived` keys are specified, subscribes to ALL\n * facts and derivations and returns reactive signals.\n *\n * @example\n * ```tsx\n * // Subscribe to everything\n * const { facts, derived, events, dispatch } = useDirective(counterModule);\n *\n * // Selective keys\n * const { facts, derived } = useDirective(counterModule, { facts: [\"count\"], derived: [\"doubled\"] });\n * ```\n */\nexport function useDirective<M extends ModuleSchema>(\n moduleDef: ModuleDef<M>,\n config?: UseDirectiveConfig,\n) {\n const allPlugins = [...(config?.plugins ?? [])];\n let statusPlugin: StatusPlugin | undefined;\n\n if (config?.status) {\n const sp = createRequirementStatusPlugin();\n statusPlugin = sp;\n // biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n allPlugins.push(sp.plugin as Plugin<any>);\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: moduleDef,\n plugins: allPlugins.length > 0 ? allPlugins : undefined,\n trace: config?.trace,\n errorBoundary: config?.errorBoundary,\n tickMs: config?.tickMs,\n zeroConfig: config?.zeroConfig,\n initialFacts: config?.initialFacts,\n } as any) as unknown as SingleModuleSystem<M>;\n\n // SSR guard: initialize facts for SSR rendering, start reconciliation only in the browser\n if (typeof window !== \"undefined\") {\n system.start();\n } else {\n system.initialize();\n }\n\n onCleanup(() => {\n system.destroy();\n });\n\n const factKeys = config?.facts;\n const derivedKeys = config?.derived;\n const subscribeAll = !factKeys && !derivedKeys;\n\n // Subscribe to facts\n const [factsState, setFactsState] = createSignal(\n subscribeAll\n ? (system.facts.$store.toObject() as InferFacts<M>)\n : (pickFacts(system, factKeys ?? []) as InferFacts<M>),\n );\n const unsubFacts = subscribeAll\n ? system.facts.$store.subscribeAll(() => {\n setFactsState(() => system.facts.$store.toObject() as InferFacts<M>);\n })\n : factKeys && factKeys.length > 0\n ? system.facts.$store.subscribe(factKeys, () => {\n setFactsState(() => pickFacts(system, factKeys) as InferFacts<M>);\n })\n : null;\n\n // Subscribe to derivations\n const allDerivationKeys = subscribeAll\n ? Object.keys(system.derive ?? {})\n : (derivedKeys ?? []);\n const getDerived = (): InferDerivations<M> => {\n const result: Record<string, unknown> = {};\n for (const key of allDerivationKeys) {\n result[key] = system.read(key);\n }\n return result as InferDerivations<M>;\n };\n const [derivedState, setDerivedState] = createSignal(getDerived());\n const unsubDerived =\n allDerivationKeys.length > 0\n ? system.subscribe(allDerivationKeys, () => {\n setDerivedState(getDerived);\n })\n : null;\n\n onCleanup(() => {\n unsubFacts?.();\n unsubDerived?.();\n });\n\n const events = system.events;\n const dispatch = (event: InferEvents<M>) => system.dispatch(event);\n\n return {\n system,\n facts: factsState as Accessor<InferFacts<M>>,\n derived: derivedState as Accessor<InferDerivations<M>>,\n events,\n dispatch,\n statusPlugin,\n };\n}\n\n// ============================================================================\n// Signal Factories (for use outside components)\n// ============================================================================\n\n/**\n * Create a derivation signal outside of a component.\n */\nexport function createDerivedSignal<T>(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n derivationId: string,\n): [Accessor<T>, () => void] {\n const [value, setValue] = createSignal<T>(system.read(derivationId) as T);\n const unsubscribe = system.subscribe([derivationId], () => {\n setValue(() => system.read(derivationId) as T);\n });\n return [value, unsubscribe];\n}\n\n/**\n * Create a fact signal outside of a component.\n */\nexport function createFactSignal<T>(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n factKey: string,\n): [Accessor<T | undefined>, () => void] {\n const [value, setValue] = createSignal<T | undefined>(\n system.facts.$store.get(factKey) as T | undefined,\n );\n const unsubscribe = system.facts.$store.subscribe([factKey], () => {\n setValue(() => system.facts.$store.get(factKey) as T | undefined);\n });\n return [value, unsubscribe];\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n useFact: <K extends keyof InferFacts<M> & string>(\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => Accessor<InferFacts<M>[K] | undefined>;\n useDerived: <K extends keyof InferDerivations<M> & string>(\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => Accessor<InferDerivations<M>[K]>;\n useDispatch: (\n system: SingleModuleSystem<M>,\n ) => (event: InferEvents<M>) => void;\n useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n useWatch: <K extends string>(\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => void;\n} {\n return {\n useFact: <K extends keyof InferFacts<M> & string>(\n system: SingleModuleSystem<M>,\n factKey: K,\n ) =>\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n useFact(system as SingleModuleSystem<any>, factKey as string) as Accessor<\n InferFacts<M>[K] | undefined\n >,\n useDerived: <K extends keyof InferDerivations<M> & string>(\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) =>\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n useDerived(\n system as SingleModuleSystem<any>,\n derivationId as string,\n ) as Accessor<InferDerivations<M>[K]>,\n useDispatch: (system: SingleModuleSystem<M>) => {\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n },\n useEvents: (system: SingleModuleSystem<M>) => useEvents<M>(system),\n useWatch: <K extends string>(\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) =>\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n useWatch(system as SingleModuleSystem<any>, key, callback),\n };\n}\n\n// ============================================================================\n// useNamespacedSelector — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * SolidJS accessor that selects from a NamespacedSystem.\n * Subscribes to specified keys and provides reactive updates.\n *\n * @param system - The namespaced system\n * @param keys - Namespaced keys to subscribe to (e.g., [\"auth.token\", \"data.count\"])\n * @param selector - Function that reads from system.facts / system.derive\n *\n * @example\n * ```tsx\n * const token = useNamespacedSelector(system, [\"auth.token\"], (s) => s.facts.auth.token);\n * ```\n */\nexport function useNamespacedSelector<Modules extends ModulesMap, R>(\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n): Accessor<R> {\n const [value, setValue] = createSignal<R>(selector(system));\n const unsubscribe = system.subscribe(keys, () => {\n setValue(() => selector(system));\n });\n onCleanup(unsubscribe);\n\n return value as Accessor<R>;\n}\n\n// ============================================================================\n// useQuerySystem — Stable query system with lifecycle management\n// ============================================================================\n\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nlet _createQuerySystem: ((config: Record<string, unknown>) => any) | null =\n null;\n\nfunction getCreateQuerySystem() {\n if (!_createQuerySystem) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const mod = require(\"@directive-run/query\");\n _createQuerySystem = mod.createQuerySystem;\n } catch {\n throw new Error(\n \"[Directive] @directive-run/query is not installed. \" +\n \"Install it with: pnpm add @directive-run/query\",\n );\n }\n }\n\n return _createQuerySystem!;\n}\n\n/**\n * Solid composable to create and manage a query system with proper lifecycle.\n *\n * Accepts a config object or a factory function that creates the system.\n * Handles cleanup via onCleanup.\n *\n * @example\n * ```tsx\n * import { useQuerySystem, useDerived } from \"@directive-run/solid\";\n *\n * function App() {\n * const app = useQuerySystem({\n * facts: { userId: \"\" },\n * queries: { user: { key: ..., fetcher: ... } },\n * });\n *\n * const user = useDerived(app, \"user\");\n * return <div>{user().data?.name}</div>;\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nexport function useQuerySystem<\n T extends {\n start: () => void;\n destroy: () => void;\n isRunning?: boolean;\n [key: string]: any;\n },\n>(config: Record<string, unknown>): T {\n const createQuerySystem = getCreateQuerySystem();\n const system = createQuerySystem(config) as T;\n\n if (typeof window !== \"undefined\" && !system.isRunning) {\n system.start();\n }\n\n onCleanup(() => {\n system.destroy();\n });\n\n return system;\n}\n\n// ============================================================================\n// SSR Hydration\n// ============================================================================\n\n/** Context for SSR hydration snapshot */\nconst HydrationContext = createContext<Record<string, unknown> | undefined>();\n\n/**\n * Solid component that provides a DistributableSnapshot to child components.\n * Uses `HydrationContext.Provider` under the hood — pass `value` as the snapshot.\n *\n * @example\n * ```tsx\n * <DirectiveHydrator value={snapshot}>\n * <App />\n * </DirectiveHydrator>\n * ```\n */\nexport const DirectiveHydrator = HydrationContext.Provider;\n\n/**\n * Create a system hydrated from a server snapshot.\n * Must be used inside a `<DirectiveHydrator>` ancestor.\n */\nexport function useHydratedSystem<S extends ModuleSchema>(\n moduleDef: ModuleDef<S>,\n config?: UseDirectiveConfig,\n): SingleModuleSystem<S> {\n const snapshot = useContext(HydrationContext);\n const mergedFacts = mergeHydrationFacts(\n snapshot,\n config?.initialFacts as Record<string, unknown>,\n );\n\n return useDirective(moduleDef, { ...config, initialFacts: mergedFacts })\n .system;\n}\n\n// ============================================================================\n// useAuditLedger — live ledger entries with filter (R4.I parity)\n// ============================================================================\n\nimport type { AuditEntry, AuditLedger, QueryFilter } from \"@directive-run/core\";\n\n/**\n * Subscribe to an audit ledger and return the latest entries matching\n * `filter` as a Solid `Accessor`. Re-evaluates on each poll tick\n * (default 250 ms — override with `pollMs`).\n *\n * **Polling floor:** `pollMs` is clamped to a minimum of 50 ms to prevent\n * accidental DoS from typos like `pollMs: 5`. Values below the floor are\n * silently clamped in production; dev mode logs a warning.\n *\n * @example\n * ```tsx\n * import { useAuditLedger } from \"@directive-run/solid\";\n *\n * function AuditLog(props: { ledger: AuditLedger }) {\n * const entries = useAuditLedger(props.ledger, { kind: \"constraint.evaluate\", limit: 20 });\n * return (\n * <ul>\n * <For each={entries()}>\n * {(e) => <li>{e.kind} @ {new Date(e.ts).toISOString()}</li>}\n * </For>\n * </ul>\n * );\n * }\n * ```\n */\nexport function useAuditLedger(\n ledger: AuditLedger,\n filter: QueryFilter = {},\n opts: { pollMs?: number } = {},\n): Accessor<readonly AuditEntry[]> {\n const requestedPollMs = opts.pollMs ?? 250;\n const pollMs = Math.max(50, requestedPollMs);\n\n if (isDevelopment) {\n if (opts.pollMs !== undefined && opts.pollMs < 50) {\n console.warn(\n `[Directive] useAuditLedger() pollMs=${opts.pollMs} is below the 50 ms floor; clamped to 50 ms.`,\n );\n }\n if (pollMs < 100) {\n const entryCount = ledger.toJSON().entries.length;\n if (entryCount > 1000) {\n console.warn(\n `[Directive] useAuditLedger() polling every ${pollMs} ms against a ${entryCount}-entry ledger — that's a lot of CPU per tick. Consider raising pollMs or tightening the filter.`,\n );\n }\n }\n }\n\n const [entries, setEntries] = createSignal<readonly AuditEntry[]>(\n ledger.query(filter),\n );\n const id = setInterval(() => setEntries(() => ledger.query(filter)), pollMs);\n onCleanup(() => clearInterval(id));\n\n return entries;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/dev-true.ts","../src/index.ts"],"names":["dev_true_default","useFact","system","keyOrKeys","assertSystem","_useFactMulti","_useFactSingle","factKey","value","setValue","createSignal","unsubscribe","onCleanup","factKeys","getValues","result","key","state","setState","useDerived","idOrIds","_useDerivedMulti","_useDerivedSingle","derivationId","derivationIds","id","useSelector","selector","equalityFn","defaultEquality","deriveKeySet","runWithTracking","runTrackedSelector","initial","trackedFactKeys","trackedDeriveKeys","selected","setSelected","unsubs","resubscribe","unsub","onUpdate","prev","depsChanged","useDispatch","event","useEvents","useWatch","callback","useInspect","options","computeInspectState","update","throttled","cleanup","createThrottle","unsubFacts","unsubSettled","useRequirementStatus","statusPlugin","typeOrTypes","type","status","setStatus","useExplain","requirementId","explanation","setExplanation","useConstraintStatus","constraintId","getVal","inspection","c","useOptimisticUpdate","requirementType","isPending","setIsPending","error","setError","snapshot","statusUnsub","rollback","mutate","updateFn","useSuspenseRequirement","types","anyLoading","t","resolve","useHistory","buildHistoryState","useDirective","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","createSystem","derivedKeys","subscribeAll","factsState","setFactsState","pickFacts","allDerivationKeys","getDerived","derivedState","setDerivedState","unsubDerived","events","createDerivedSignal","createFactSignal","createTypedHooks","useNamespacedSelector","keys","_createQuerySystem","getCreateQuerySystem","useQuerySystem","HydrationContext","createContext","DirectiveHydrator","useHydratedSystem","useContext","mergedFacts","mergeHydrationFacts","useAuditLedger","ledger","filter","opts","requestedPollMs","pollMs","entryCount","entries","setEntries"],"mappings":"oYAAA,IAAOA,CAAAA,CAAQ,OAAO,OAAA,CAAY,GAAA,EAChC,QAAQ,GAAA,EAAK,QAAA,GAAa,YAAA,CCiFrB,SAASC,CAAAA,CAEdC,CAAAA,CACAC,EACmB,CAUnB,OATAC,0BAAa,SAAA,CAAWF,CAAM,EAC1BF,CAAAA,EAAiB,OAAOG,GAAc,UAAA,EACxC,OAAA,CAAQ,MACN,gJAEF,CAAA,CAIE,MAAM,OAAA,CAAQA,CAAS,EAClBE,CAAAA,CAAcH,CAAAA,CAAQC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AAS,KAAK,CAChB,IAAMC,EAAaL,CAAAA,CAAO,MAAA,GAAS,OAAA,CAAQ,MAAA,CACvCK,CAAAA,CAAa,GAAA,EACf,OAAA,CAAQ,IAAA,CACN,8CAA8CD,CAAM,CAAA,cAAA,EAAiBC,CAAU,CAAA,oGAAA,CACjF,EAEJ,CAGF,GAAM,CAACC,CAAAA,CAASC,CAAU,CAAA,CAAI1H,oBAAAA,CAC5BmH,EAAO,KAAA,CAAMC,CAAM,CACrB,CAAA,CACMrG,CAAAA,CAAK,YAAY,IAAM2G,CAAAA,CAAW,IAAMP,CAAAA,CAAO,KAAA,CAAMC,CAAM,CAAC,CAAA,CAAGG,CAAM,EAC3E,OAAArH,iBAAAA,CAAU,IAAM,aAAA,CAAca,CAAE,CAAC,CAAA,CAE1B0G,CACT","file":"index.cjs","sourcesContent":["export default typeof process !== \"undefined\" &&\n process.env?.NODE_ENV !== \"production\";\n","/**\n * Solid Adapter - Consolidated SolidJS primitives for Directive\n *\n * 16 active exports: useFact, useDerived, useDispatch, useSelector,\n * useWatch, useInspect, useRequirementStatus, useEvents, useExplain,\n * useConstraintStatus, useOptimisticUpdate, useDirective, useHistory,\n * createTypedHooks, useSuspenseRequirement, shallowEqual\n *\n * Signal factories: createDerivedSignal, createFactSignal\n */\n\nimport type {\n ErrorBoundaryConfig,\n InferDerivations,\n InferEvents,\n InferFacts,\n InferSelectorState,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemSnapshot,\n TraceOption,\n} from \"@directive-run/core\";\nimport {\n createRequirementStatusPlugin,\n createSystem,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n type ConstraintInfo,\n type InspectState,\n assertSystem,\n buildHistoryState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n mergeHydrationFacts,\n pickFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport {\n type Accessor,\n createContext,\n createSignal,\n onCleanup,\n useContext,\n} from \"solid-js\";\nimport isDevelopment from \"#is-development\";\n\n// Re-export for convenience\nexport type { RequirementTypeStatus, InspectState, ConstraintInfo };\nexport { shallowEqual };\n\n/** Type for the requirement status plugin return value */\nexport type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;\n\n// ============================================================================\n// useFact — single key or multi key\n// ============================================================================\n\n/** Single key overload */\nexport function useFact<\n S extends ModuleSchema,\n K extends keyof InferFacts<S> & string,\n>(\n system: SingleModuleSystem<S>,\n factKey: K,\n): Accessor<InferFacts<S>[K] | undefined>;\n/** Multi-key overload */\nexport function useFact<\n S extends ModuleSchema,\n K extends keyof InferFacts<S> & string,\n>(\n system: SingleModuleSystem<S>,\n factKeys: K[],\n): Accessor<Pick<InferFacts<S>, K>>;\n/** Implementation */\nexport function useFact(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n keyOrKeys: string | string[],\n): Accessor<unknown> {\n assertSystem(\"useFact\", system);\n if (isDevelopment && typeof keyOrKeys === \"function\") {\n console.error(\n \"[Directive] useFact() received a function. Did you mean useSelector()? \" +\n \"useFact() takes a string key or array of keys, not a selector function.\",\n );\n }\n\n // Multi-key path\n if (Array.isArray(keyOrKeys)) {\n return _useFactMulti(system, keyOrKeys);\n }\n\n // Single key path\n return _useFactSingle(system, keyOrKeys);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactSingle(\n system: SingleModuleSystem<any>,\n factKey: string,\n): Accessor<unknown> {\n if (isDevelopment) {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] useFact(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n\n const [value, setValue] = createSignal(system.facts.$store.get(factKey));\n const unsubscribe = system.facts.$store.subscribe([factKey], () => {\n setValue(() => system.facts.$store.get(factKey));\n });\n onCleanup(unsubscribe);\n return value;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactMulti(\n system: SingleModuleSystem<any>,\n factKeys: string[],\n): Accessor<Record<string, unknown>> {\n const getValues = (): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n for (const key of factKeys) {\n result[key] = system.facts.$store.get(key);\n }\n return result;\n };\n const [state, setState] = createSignal(getValues());\n const unsubscribe = system.facts.$store.subscribe(factKeys, () => {\n setState(getValues);\n });\n onCleanup(unsubscribe);\n return state;\n}\n\n// ============================================================================\n// useDerived — single key or multi key\n// ============================================================================\n\n/** Single key overload */\nexport function useDerived<\n S extends ModuleSchema,\n K extends keyof InferDerivations<S> & string,\n>(\n system: SingleModuleSystem<S>,\n derivationId: K,\n): Accessor<InferDerivations<S>[K]>;\n/** Multi-key overload */\nexport function useDerived<\n S extends ModuleSchema,\n K extends keyof InferDerivations<S> & string,\n>(\n system: SingleModuleSystem<S>,\n derivationIds: K[],\n): Accessor<Pick<InferDerivations<S>, K>>;\n/** Implementation */\nexport function useDerived(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n idOrIds: string | string[],\n): Accessor<unknown> {\n assertSystem(\"useDerived\", system);\n if (isDevelopment && typeof idOrIds === \"function\") {\n console.error(\n \"[Directive] useDerived() received a function. Did you mean useSelector()? \" +\n \"useDerived() takes a string key or array of keys, not a selector function.\",\n );\n }\n\n // Multi-key path\n if (Array.isArray(idOrIds)) {\n return _useDerivedMulti(system, idOrIds);\n }\n\n // Single key path\n return _useDerivedSingle(system, idOrIds);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useDerivedSingle(\n system: SingleModuleSystem<any>,\n derivationId: string,\n): Accessor<unknown> {\n if (isDevelopment) {\n const initialValue = system.read(derivationId);\n if (initialValue === undefined) {\n console.warn(\n `[Directive] useDerived(\"${derivationId}\") returned undefined. ` +\n `Check that \"${derivationId}\" is defined in your module's derive property.`,\n );\n }\n }\n const [value, setValue] = createSignal(system.read(derivationId));\n const unsubscribe = system.subscribe([derivationId], () => {\n setValue(() => system.read(derivationId));\n });\n onCleanup(unsubscribe);\n return value;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useDerivedMulti(\n system: SingleModuleSystem<any>,\n derivationIds: string[],\n): Accessor<Record<string, unknown>> {\n const getValues = (): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n for (const id of derivationIds) {\n result[id] = system.read(id);\n }\n return result;\n };\n const [state, setState] = createSignal(getValues());\n const unsubscribe = system.subscribe(derivationIds, () => {\n setState(getValues);\n });\n onCleanup(unsubscribe);\n return state;\n}\n\n// ============================================================================\n// useSelector — auto-tracking selector over facts and derivations\n// ============================================================================\n\n/**\n * Auto-tracking selector over facts and derivations.\n * Uses `withTracking()` to detect which facts the selector accesses,\n * then subscribes only to those keys.\n */\nexport function useSelector<S extends ModuleSchema, R>(\n system: SingleModuleSystem<S>,\n selector: (state: InferSelectorState<S>) => R,\n equalityFn?: (a: R, b: R) => boolean,\n): Accessor<R>;\nexport function useSelector(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n selector: (state: any) => unknown,\n equalityFn: (a: unknown, b: unknown) => boolean = defaultEquality,\n): Accessor<unknown> {\n assertSystem(\"useSelector\", system);\n const deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n // Build a tracking-aware state proxy that exposes both facts and derivations\n const runWithTracking = () =>\n runTrackedSelector(system, deriveKeySet, selector);\n\n const initial = runWithTracking();\n let trackedFactKeys = initial.factKeys;\n let trackedDeriveKeys = initial.deriveKeys;\n const [selected, setSelected] = createSignal(initial.value);\n\n const unsubs: Array<() => void> = [];\n\n const resubscribe = () => {\n for (const unsub of unsubs) unsub();\n unsubs.length = 0;\n\n const onUpdate = () => {\n const result = runWithTracking();\n setSelected((prev) => {\n if (!equalityFn(prev, result.value)) return result.value;\n return prev;\n });\n // Re-track: check if deps changed\n if (\n depsChanged(\n trackedFactKeys,\n result.factKeys,\n trackedDeriveKeys,\n result.deriveKeys,\n )\n ) {\n trackedFactKeys = result.factKeys;\n trackedDeriveKeys = result.deriveKeys;\n resubscribe();\n }\n };\n\n if (trackedFactKeys.length > 0) {\n unsubs.push(system.facts.$store.subscribe(trackedFactKeys, onUpdate));\n } else if (trackedDeriveKeys.length === 0) {\n unsubs.push(system.facts.$store.subscribeAll(onUpdate));\n }\n if (trackedDeriveKeys.length > 0) {\n unsubs.push(system.subscribe(trackedDeriveKeys, onUpdate));\n }\n };\n\n resubscribe();\n\n onCleanup(() => {\n for (const unsub of unsubs) unsub();\n });\n\n return selected;\n}\n\n// ============================================================================\n// useDispatch\n// ============================================================================\n\nexport function useDispatch<S extends ModuleSchema>(\n system: SingleModuleSystem<S>,\n): (event: InferEvents<S>) => void {\n assertSystem(\"useDispatch\", system);\n return (event: InferEvents<S>) => {\n system.dispatch(event);\n };\n}\n\n// ============================================================================\n// useEvents — memoized events reference\n// ============================================================================\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<S extends ModuleSchema>(\n system: SingleModuleSystem<S>,\n): SingleModuleSystem<S>[\"events\"] {\n assertSystem(\"useEvents\", system);\n return system.events;\n}\n\n// ============================================================================\n// useWatch — derivation or fact side-effect\n// ============================================================================\n\n/** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */\nexport function useWatch<\n S extends ModuleSchema,\n K extends keyof InferDerivations<S> & string,\n>(\n system: SingleModuleSystem<S>,\n key: K,\n callback: (\n newValue: InferDerivations<S>[K],\n previousValue: InferDerivations<S>[K] | undefined,\n ) => void,\n): void;\n/** Watch a fact key with auto-detection. */\nexport function useWatch<\n S extends ModuleSchema,\n K extends keyof InferFacts<S> & string,\n>(\n system: SingleModuleSystem<S>,\n key: K,\n callback: (\n newValue: InferFacts<S>[K] | undefined,\n previousValue: InferFacts<S>[K] | undefined,\n ) => void,\n): void;\n/** Implementation */\nexport function useWatch(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n key: string,\n callback: (newValue: unknown, prevValue: unknown) => void,\n): void {\n assertSystem(\"useWatch\", system);\n\n const unsubscribe = system.watch(key, callback);\n onCleanup(unsubscribe);\n}\n\n// ============================================================================\n// useInspect — consolidated inspection hook\n// ============================================================================\n\n/** Options for useInspect */\nexport interface UseInspectOptions {\n throttleMs?: number;\n}\n\n/**\n * Consolidated system inspection hook.\n * Returns Accessor<InspectState> with optional throttling.\n */\nexport function useInspect(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n options?: UseInspectOptions,\n): Accessor<InspectState> {\n assertSystem(\"useInspect\", system);\n const [state, setState] = createSignal<InspectState>(\n computeInspectState(system),\n );\n\n const update = () => {\n setState(computeInspectState(system));\n };\n\n if (options?.throttleMs && options.throttleMs > 0) {\n const { throttled, cleanup } = createThrottle(update, options.throttleMs);\n const unsubFacts = system.facts.$store.subscribeAll(throttled);\n const unsubSettled = system.onSettledChange(throttled);\n onCleanup(() => {\n cleanup();\n unsubFacts();\n unsubSettled();\n });\n } else {\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n onCleanup(() => {\n unsubFacts();\n unsubSettled();\n });\n }\n\n return state;\n}\n\n// ============================================================================\n// useRequirementStatus — single or multi\n// ============================================================================\n\n/** Single type overload */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n type: string,\n): Accessor<RequirementTypeStatus>;\n/** Multi-type overload */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n types: string[],\n): Accessor<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n typeOrTypes: string | string[],\n):\n | Accessor<RequirementTypeStatus>\n | Accessor<Record<string, RequirementTypeStatus>> {\n if (Array.isArray(typeOrTypes)) {\n const getValues = (): Record<string, RequirementTypeStatus> => {\n const result: Record<string, RequirementTypeStatus> = {};\n for (const type of typeOrTypes) {\n result[type] = statusPlugin.getStatus(type);\n }\n return result;\n };\n const [state, setState] = createSignal(getValues());\n const unsubscribe = statusPlugin.subscribe(() => {\n setState(getValues);\n });\n onCleanup(unsubscribe);\n return state;\n }\n\n const [status, setStatus] = createSignal<RequirementTypeStatus>(\n statusPlugin.getStatus(typeOrTypes),\n );\n const unsubscribe = statusPlugin.subscribe(() => {\n setStatus(statusPlugin.getStatus(typeOrTypes));\n });\n onCleanup(unsubscribe);\n return status;\n}\n\n// ============================================================================\n// useExplain — reactive requirement explanation\n// ============================================================================\n\n/**\n * Reactively returns the explanation string for a requirement.\n */\nexport function useExplain(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n requirementId: string,\n): Accessor<string | null> {\n assertSystem(\"useExplain\", system);\n const [explanation, setExplanation] = createSignal<string | null>(\n system.explain(requirementId),\n );\n\n const update = () => setExplanation(system.explain(requirementId));\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n onCleanup(() => {\n unsubFacts();\n unsubSettled();\n });\n\n return explanation;\n}\n\n// ============================================================================\n// useConstraintStatus — reactive constraint inspection\n// ============================================================================\n\n/** Get all constraints */\nexport function useConstraintStatus(\n system: SingleModuleSystem<any>,\n): Accessor<ConstraintInfo[]>;\n/** Get a single constraint by ID */\nexport function useConstraintStatus(\n system: SingleModuleSystem<any>,\n constraintId: string,\n): Accessor<ConstraintInfo | null>;\n/** Implementation */\nexport function useConstraintStatus(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): Accessor<ConstraintInfo[] | ConstraintInfo | null> {\n assertSystem(\"useConstraintStatus\", system);\n const getVal = () => {\n const inspection = system.inspect();\n if (!constraintId) return inspection.constraints;\n return (\n inspection.constraints.find(\n (c: ConstraintInfo) => c.id === constraintId,\n ) ?? null\n );\n };\n\n const [state, setState] = createSignal<\n ConstraintInfo[] | ConstraintInfo | null\n >(getVal());\n\n const update = () => setState(getVal);\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n onCleanup(() => {\n unsubFacts();\n unsubSettled();\n });\n\n return state;\n}\n\n// ============================================================================\n// useOptimisticUpdate — batch with rollback on failure\n// ============================================================================\n\nexport interface OptimisticUpdateResult {\n mutate: (updateFn: () => void) => void;\n isPending: Accessor<boolean>;\n error: Accessor<Error | null>;\n rollback: () => void;\n}\n\n/**\n * Optimistic update hook. Saves a snapshot before mutating, monitors\n * a requirement type via statusPlugin, and rolls back on failure.\n */\nexport function useOptimisticUpdate(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n): OptimisticUpdateResult {\n assertSystem(\"useOptimisticUpdate\", system);\n const [isPending, setIsPending] = createSignal(false);\n const [error, setError] = createSignal<Error | null>(null);\n let snapshot: SystemSnapshot | null = null;\n let statusUnsub: (() => void) | null = null;\n\n const rollback = () => {\n if (snapshot) {\n system.restore(snapshot);\n snapshot = null;\n }\n setIsPending(false);\n setError(null);\n statusUnsub?.();\n statusUnsub = null;\n };\n\n const mutate = (updateFn: () => void) => {\n snapshot = system.getSnapshot();\n setIsPending(true);\n setError(null);\n system.batch(updateFn);\n\n if (statusPlugin && requirementType) {\n statusUnsub?.();\n statusUnsub = statusPlugin.subscribe(() => {\n const status = statusPlugin.getStatus(requirementType);\n if (!status.isLoading && !status.hasError) {\n snapshot = null;\n setIsPending(false);\n statusUnsub?.();\n statusUnsub = null;\n } else if (status.hasError) {\n setError(() => status.lastError);\n rollback();\n }\n });\n }\n };\n\n onCleanup(() => {\n statusUnsub?.();\n });\n\n return { mutate, isPending, error, rollback };\n}\n\n// ============================================================================\n// useSuspenseRequirement — Solid-specific Suspense integration\n// ============================================================================\n\n/**\n * Single type: throws a promise while the requirement is pending (Suspense).\n */\nexport function useSuspenseRequirement(\n statusPlugin: StatusPlugin,\n type: string,\n): Accessor<RequirementTypeStatus>;\n/**\n * Multi-type: throws a promise while any of the requirements are pending.\n */\nexport function useSuspenseRequirement(\n statusPlugin: StatusPlugin,\n types: string[],\n): Accessor<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useSuspenseRequirement(\n statusPlugin: StatusPlugin,\n typeOrTypes: string | string[],\n):\n | Accessor<RequirementTypeStatus>\n | Accessor<Record<string, RequirementTypeStatus>> {\n const types = Array.isArray(typeOrTypes) ? typeOrTypes : [typeOrTypes];\n\n // Check if any are still loading — if so, throw a promise\n const anyLoading = () =>\n types.some((t) => statusPlugin.getStatus(t).isLoading);\n\n if (anyLoading()) {\n throw new Promise<void>((resolve) => {\n const unsub = statusPlugin.subscribe(() => {\n if (!anyLoading()) {\n unsub();\n resolve();\n }\n });\n });\n }\n\n // Once resolved, return normal accessor\n if (Array.isArray(typeOrTypes)) {\n return useRequirementStatus(statusPlugin, typeOrTypes) as Accessor<\n Record<string, RequirementTypeStatus>\n >;\n }\n return useRequirementStatus(\n statusPlugin,\n typeOrTypes,\n ) as Accessor<RequirementTypeStatus>;\n}\n\n// ============================================================================\n// useHistory — reactive history signal\n// ============================================================================\n\n/**\n * Reactive history signal. Returns an Accessor that updates\n * when snapshots are taken or navigation occurs.\n *\n * @example\n * ```tsx\n * const history = useHistory(system);\n * <button disabled={!history()?.canGoBack} onClick={() => history()?.goBack()}>Undo</button>\n * ```\n */\nexport function useHistory(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n): Accessor<ReturnType<typeof buildHistoryState>> {\n assertSystem(\"useHistory\", system);\n const [state, setState] = createSignal<ReturnType<typeof buildHistoryState>>(\n buildHistoryState(system),\n );\n const unsub = system.onHistoryChange(() =>\n setState(buildHistoryState(system)),\n );\n onCleanup(unsub);\n return state;\n}\n\n// ============================================================================\n// Scoped System\n// ============================================================================\n\n/** Configuration for useDirective */\ninterface UseDirectiveConfig {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n /** Fact keys to subscribe to (omit for all) */\n facts?: string[];\n /** Derivation keys to subscribe to (omit for all) */\n derived?: string[];\n}\n\n/**\n * Create a scoped Directive system with automatic lifecycle management.\n * When no `facts` or `derived` keys are specified, subscribes to ALL\n * facts and derivations and returns reactive signals.\n *\n * @example\n * ```tsx\n * // Subscribe to everything\n * const { facts, derived, events, dispatch } = useDirective(counterModule);\n *\n * // Selective keys\n * const { facts, derived } = useDirective(counterModule, { facts: [\"count\"], derived: [\"doubled\"] });\n * ```\n */\nexport function useDirective<M extends ModuleSchema>(\n moduleDef: ModuleDef<M>,\n config?: UseDirectiveConfig,\n) {\n const allPlugins = [...(config?.plugins ?? [])];\n let statusPlugin: StatusPlugin | undefined;\n\n if (config?.status) {\n const sp = createRequirementStatusPlugin();\n statusPlugin = sp;\n // biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n allPlugins.push(sp.plugin as Plugin<any>);\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: moduleDef,\n plugins: allPlugins.length > 0 ? allPlugins : undefined,\n trace: config?.trace,\n errorBoundary: config?.errorBoundary,\n tickMs: config?.tickMs,\n zeroConfig: config?.zeroConfig,\n initialFacts: config?.initialFacts,\n } as any) as unknown as SingleModuleSystem<M>;\n\n // SSR guard: initialize facts for SSR rendering, start reconciliation only in the browser\n if (typeof window !== \"undefined\") {\n system.start();\n } else {\n system.initialize();\n }\n\n onCleanup(() => {\n // RFC 0009 follow-up (R18 Tier 2-B): destroyAsync so source\n // unsubscribes complete; fire-and-forget with swallow-catch\n // (the framework's onCleanup is sync).\n system.destroyAsync().catch(() => {});\n });\n\n const factKeys = config?.facts;\n const derivedKeys = config?.derived;\n const subscribeAll = !factKeys && !derivedKeys;\n\n // Subscribe to facts\n const [factsState, setFactsState] = createSignal(\n subscribeAll\n ? (system.facts.$store.toObject() as InferFacts<M>)\n : (pickFacts(system, factKeys ?? []) as InferFacts<M>),\n );\n const unsubFacts = subscribeAll\n ? system.facts.$store.subscribeAll(() => {\n setFactsState(() => system.facts.$store.toObject() as InferFacts<M>);\n })\n : factKeys && factKeys.length > 0\n ? system.facts.$store.subscribe(factKeys, () => {\n setFactsState(() => pickFacts(system, factKeys) as InferFacts<M>);\n })\n : null;\n\n // Subscribe to derivations\n const allDerivationKeys = subscribeAll\n ? Object.keys(system.derive ?? {})\n : (derivedKeys ?? []);\n const getDerived = (): InferDerivations<M> => {\n const result: Record<string, unknown> = {};\n for (const key of allDerivationKeys) {\n result[key] = system.read(key);\n }\n return result as InferDerivations<M>;\n };\n const [derivedState, setDerivedState] = createSignal(getDerived());\n const unsubDerived =\n allDerivationKeys.length > 0\n ? system.subscribe(allDerivationKeys, () => {\n setDerivedState(getDerived);\n })\n : null;\n\n onCleanup(() => {\n unsubFacts?.();\n unsubDerived?.();\n });\n\n const events = system.events;\n const dispatch = (event: InferEvents<M>) => system.dispatch(event);\n\n return {\n system,\n facts: factsState as Accessor<InferFacts<M>>,\n derived: derivedState as Accessor<InferDerivations<M>>,\n events,\n dispatch,\n statusPlugin,\n };\n}\n\n// ============================================================================\n// Signal Factories (for use outside components)\n// ============================================================================\n\n/**\n * Create a derivation signal outside of a component.\n */\nexport function createDerivedSignal<T>(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n derivationId: string,\n): [Accessor<T>, () => void] {\n const [value, setValue] = createSignal<T>(system.read(derivationId) as T);\n const unsubscribe = system.subscribe([derivationId], () => {\n setValue(() => system.read(derivationId) as T);\n });\n return [value, unsubscribe];\n}\n\n/**\n * Create a fact signal outside of a component.\n */\nexport function createFactSignal<T>(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n factKey: string,\n): [Accessor<T | undefined>, () => void] {\n const [value, setValue] = createSignal<T | undefined>(\n system.facts.$store.get(factKey) as T | undefined,\n );\n const unsubscribe = system.facts.$store.subscribe([factKey], () => {\n setValue(() => system.facts.$store.get(factKey) as T | undefined);\n });\n return [value, unsubscribe];\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n useFact: <K extends keyof InferFacts<M> & string>(\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => Accessor<InferFacts<M>[K] | undefined>;\n useDerived: <K extends keyof InferDerivations<M> & string>(\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => Accessor<InferDerivations<M>[K]>;\n useDispatch: (\n system: SingleModuleSystem<M>,\n ) => (event: InferEvents<M>) => void;\n useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n useWatch: <K extends string>(\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => void;\n} {\n return {\n useFact: <K extends keyof InferFacts<M> & string>(\n system: SingleModuleSystem<M>,\n factKey: K,\n ) =>\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n useFact(system as SingleModuleSystem<any>, factKey as string) as Accessor<\n InferFacts<M>[K] | undefined\n >,\n useDerived: <K extends keyof InferDerivations<M> & string>(\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) =>\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n useDerived(\n system as SingleModuleSystem<any>,\n derivationId as string,\n ) as Accessor<InferDerivations<M>[K]>,\n useDispatch: (system: SingleModuleSystem<M>) => {\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n },\n useEvents: (system: SingleModuleSystem<M>) => useEvents<M>(system),\n useWatch: <K extends string>(\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) =>\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n useWatch(system as SingleModuleSystem<any>, key, callback),\n };\n}\n\n// ============================================================================\n// useNamespacedSelector — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * SolidJS accessor that selects from a NamespacedSystem.\n * Subscribes to specified keys and provides reactive updates.\n *\n * @param system - The namespaced system\n * @param keys - Namespaced keys to subscribe to (e.g., [\"auth.token\", \"data.count\"])\n * @param selector - Function that reads from system.facts / system.derive\n *\n * @example\n * ```tsx\n * const token = useNamespacedSelector(system, [\"auth.token\"], (s) => s.facts.auth.token);\n * ```\n */\nexport function useNamespacedSelector<Modules extends ModulesMap, R>(\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n): Accessor<R> {\n const [value, setValue] = createSignal<R>(selector(system));\n const unsubscribe = system.subscribe(keys, () => {\n setValue(() => selector(system));\n });\n onCleanup(unsubscribe);\n\n return value as Accessor<R>;\n}\n\n// ============================================================================\n// useQuerySystem — Stable query system with lifecycle management\n// ============================================================================\n\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nlet _createQuerySystem: ((config: Record<string, unknown>) => any) | null =\n null;\n\nfunction getCreateQuerySystem() {\n if (!_createQuerySystem) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const mod = require(\"@directive-run/query\");\n _createQuerySystem = mod.createQuerySystem;\n } catch {\n throw new Error(\n \"[Directive] @directive-run/query is not installed. \" +\n \"Install it with: pnpm add @directive-run/query\",\n );\n }\n }\n\n return _createQuerySystem!;\n}\n\n/**\n * Solid composable to create and manage a query system with proper lifecycle.\n *\n * Accepts a config object or a factory function that creates the system.\n * Handles cleanup via onCleanup.\n *\n * @example\n * ```tsx\n * import { useQuerySystem, useDerived } from \"@directive-run/solid\";\n *\n * function App() {\n * const app = useQuerySystem({\n * facts: { userId: \"\" },\n * queries: { user: { key: ..., fetcher: ... } },\n * });\n *\n * const user = useDerived(app, \"user\");\n * return <div>{user().data?.name}</div>;\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nexport function useQuerySystem<\n T extends {\n start: () => void;\n destroy: () => void;\n isRunning?: boolean;\n [key: string]: any;\n },\n>(config: Record<string, unknown>): T {\n const createQuerySystem = getCreateQuerySystem();\n const system = createQuerySystem(config) as T;\n\n if (typeof window !== \"undefined\" && !system.isRunning) {\n system.start();\n }\n\n onCleanup(() => {\n // RFC 0009 follow-up (R18 Tier 2-B): destroyAsync so source\n // unsubscribes complete; fire-and-forget with swallow-catch\n // (the framework's onCleanup is sync).\n system.destroyAsync().catch(() => {});\n });\n\n return system;\n}\n\n// ============================================================================\n// SSR Hydration\n// ============================================================================\n\n/** Context for SSR hydration snapshot */\nconst HydrationContext = createContext<Record<string, unknown> | undefined>();\n\n/**\n * Solid component that provides a DistributableSnapshot to child components.\n * Uses `HydrationContext.Provider` under the hood — pass `value` as the snapshot.\n *\n * @example\n * ```tsx\n * <DirectiveHydrator value={snapshot}>\n * <App />\n * </DirectiveHydrator>\n * ```\n */\nexport const DirectiveHydrator = HydrationContext.Provider;\n\n/**\n * Create a system hydrated from a server snapshot.\n * Must be used inside a `<DirectiveHydrator>` ancestor.\n */\nexport function useHydratedSystem<S extends ModuleSchema>(\n moduleDef: ModuleDef<S>,\n config?: UseDirectiveConfig,\n): SingleModuleSystem<S> {\n const snapshot = useContext(HydrationContext);\n const mergedFacts = mergeHydrationFacts(\n snapshot,\n config?.initialFacts as Record<string, unknown>,\n );\n\n return useDirective(moduleDef, { ...config, initialFacts: mergedFacts })\n .system;\n}\n\n// ============================================================================\n// useAuditLedger — live ledger entries with filter (R4.I parity)\n// ============================================================================\n\nimport type { AuditEntry, AuditLedger, QueryFilter } from \"@directive-run/core\";\n\n/**\n * Subscribe to an audit ledger and return the latest entries matching\n * `filter` as a Solid `Accessor`. Re-evaluates on each poll tick\n * (default 250 ms — override with `pollMs`).\n *\n * **Polling floor:** `pollMs` is clamped to a minimum of 50 ms to prevent\n * accidental DoS from typos like `pollMs: 5`. Values below the floor are\n * silently clamped in production; dev mode logs a warning.\n *\n * @example\n * ```tsx\n * import { useAuditLedger } from \"@directive-run/solid\";\n *\n * function AuditLog(props: { ledger: AuditLedger }) {\n * const entries = useAuditLedger(props.ledger, { kind: \"constraint.evaluate\", limit: 20 });\n * return (\n * <ul>\n * <For each={entries()}>\n * {(e) => <li>{e.kind} @ {new Date(e.ts).toISOString()}</li>}\n * </For>\n * </ul>\n * );\n * }\n * ```\n */\nexport function useAuditLedger(\n ledger: AuditLedger,\n filter: QueryFilter = {},\n opts: { pollMs?: number } = {},\n): Accessor<readonly AuditEntry[]> {\n const requestedPollMs = opts.pollMs ?? 250;\n const pollMs = Math.max(50, requestedPollMs);\n\n if (isDevelopment) {\n if (opts.pollMs !== undefined && opts.pollMs < 50) {\n console.warn(\n `[Directive] useAuditLedger() pollMs=${opts.pollMs} is below the 50 ms floor; clamped to 50 ms.`,\n );\n }\n if (pollMs < 100) {\n const entryCount = ledger.toJSON().entries.length;\n if (entryCount > 1000) {\n console.warn(\n `[Directive] useAuditLedger() polling every ${pollMs} ms against a ${entryCount}-entry ledger — that's a lot of CPU per tick. Consider raising pollMs or tightening the filter.`,\n );\n }\n }\n }\n\n const [entries, setEntries] = createSignal<readonly AuditEntry[]>(\n ledger.query(filter),\n );\n const id = setInterval(() => setEntries(() => ledger.query(filter)), pollMs);\n onCleanup(() => clearInterval(id));\n\n return entries;\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {createRequirementStatusPlugin,createSystem}from'@directive-run/core';import {defaultEquality,assertSystem,computeInspectState,createThrottle,buildHistoryState,pickFacts,mergeHydrationFacts,runTrackedSelector,depsChanged}from'@directive-run/core/adapter-utils';export{shallowEqual}from'@directive-run/core/adapter-utils';import {createContext,createSignal,onCleanup,useContext}from'solid-js';var F=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var v=typeof process<"u"&&process.env?.NODE_ENV!=="production";function H(e,t){return assertSystem("useFact",e),v&&typeof t=="function"&&console.error("[Directive] useFact() received a function. Did you mean useSelector()? useFact() takes a string key or array of keys, not a selector function."),Array.isArray(t)?Q(e,t):L(e,t)}function L(e,t){v&&(e.facts.$store.has(t)||console.warn(`[Directive] useFact("${t}") \u2014 fact not found in store. Check that "${t}" is defined in your module's schema.`));let[n,r]=createSignal(e.facts.$store.get(t)),s=e.facts.$store.subscribe([t],()=>{r(()=>e.facts.$store.get(t));});return onCleanup(s),n}function Q(e,t){let n=()=>{let i={};for(let u of t)i[u]=e.facts.$store.get(u);return i},[r,s]=createSignal(n()),o=e.facts.$store.subscribe(t,()=>{s(n);});return onCleanup(o),r}function N(e,t){return assertSystem("useDerived",e),v&&typeof t=="function"&&console.error("[Directive] useDerived() received a function. Did you mean useSelector()? useDerived() takes a string key or array of keys, not a selector function."),Array.isArray(t)?_(e,t):W(e,t)}function W(e,t){v&&e.read(t)===void 0&&console.warn(`[Directive] useDerived("${t}") returned undefined. Check that "${t}" is defined in your module's derive property.`);let[n,r]=createSignal(e.read(t)),s=e.subscribe([t],()=>{r(()=>e.read(t));});return onCleanup(s),n}function _(e,t){let n=()=>{let i={};for(let u of t)i[u]=e.read(u);return i},[r,s]=createSignal(n()),o=e.subscribe(t,()=>{s(n);});return onCleanup(o),r}function se(e,t,n=defaultEquality){assertSystem("useSelector",e);let r=new Set(Object.keys(e.derive??{})),s=()=>runTrackedSelector(e,r,t),o=s(),i=o.factKeys,u=o.deriveKeys,[c,f]=createSignal(o.value),d=[],p=()=>{for(let y of d)y();d.length=0;let S=()=>{let y=s();f(m=>n(m,y.value)?m:y.value),depsChanged(i,y.factKeys,u,y.deriveKeys)&&(i=y.factKeys,u=y.deriveKeys,p());};i.length>0?d.push(e.facts.$store.subscribe(i,S)):u.length===0&&d.push(e.facts.$store.subscribeAll(S)),u.length>0&&d.push(e.subscribe(u,S));};return p(),onCleanup(()=>{for(let S of d)S();}),c}function re(e){return assertSystem("useDispatch",e),t=>{e.dispatch(t);}}function B(e){return assertSystem("useEvents",e),e.events}function j(e,t,n){assertSystem("useWatch",e);let r=e.watch(t,n);onCleanup(r);}function oe(e,t){assertSystem("useInspect",e);let[n,r]=createSignal(computeInspectState(e)),s=()=>{r(computeInspectState(e));};if(t?.throttleMs&&t.throttleMs>0){let{throttled:o,cleanup:i}=createThrottle(s,t.throttleMs),u=e.facts.$store.subscribeAll(o),c=e.onSettledChange(o);onCleanup(()=>{i(),u(),c();});}else {let o=e.facts.$store.subscribeAll(s),i=e.onSettledChange(s);onCleanup(()=>{o(),i();});}return n}function R(e,t){if(Array.isArray(t)){let o=()=>{let f={};for(let d of t)f[d]=e.getStatus(d);return f},[i,u]=createSignal(o()),c=e.subscribe(()=>{u(o);});return onCleanup(c),i}let[n,r]=createSignal(e.getStatus(t)),s=e.subscribe(()=>{r(e.getStatus(t));});return onCleanup(s),n}function ie(e,t){assertSystem("useExplain",e);let[n,r]=createSignal(e.explain(t)),s=()=>r(e.explain(t)),o=e.facts.$store.subscribeAll(s),i=e.onSettledChange(s);return onCleanup(()=>{o(),i();}),n}function ue(e,t){assertSystem("useConstraintStatus",e);let n=()=>{let c=e.inspect();return t?c.constraints.find(f=>f.id===t)??null:c.constraints},[r,s]=createSignal(n()),o=()=>s(n),i=e.facts.$store.subscribeAll(o),u=e.onSettledChange(o);return onCleanup(()=>{i(),u();}),r}function ce(e,t,n){assertSystem("useOptimisticUpdate",e);let[r,s]=createSignal(false),[o,i]=createSignal(null),u=null,c=null,f=()=>{u&&(e.restore(u),u=null),s(false),i(null),c?.(),c=null;},d=p=>{u=e.getSnapshot(),s(true),i(null),e.batch(p),t&&n&&(c?.(),c=t.subscribe(()=>{let S=t.getStatus(n);!S.isLoading&&!S.hasError?(u=null,s(false),c?.(),c=null):S.hasError&&(i(()=>S.lastError),f());}));};return onCleanup(()=>{c?.();}),{mutate:d,isPending:r,error:o,rollback:f}}function ae(e,t){let n=Array.isArray(t)?t:[t],r=()=>n.some(s=>e.getStatus(s).isLoading);if(r())throw new Promise(s=>{let o=e.subscribe(()=>{r()||(o(),s());});});return R(e,t)}function le(e){assertSystem("useHistory",e);let[t,n]=createSignal(buildHistoryState(e)),r=e.onHistoryChange(()=>n(buildHistoryState(e)));return onCleanup(r),t}function z(e,t){let n=[...t?.plugins??[]],r;if(t?.status){let M=createRequirementStatusPlugin();r=M,n.push(M.plugin);}let s=createSystem({module:e,plugins:n.length>0?n:void 0,trace:t?.trace,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:t?.initialFacts});typeof window<"u"?s.start():s.initialize(),onCleanup(()=>{s.
|
|
1
|
+
import {createRequirementStatusPlugin,createSystem}from'@directive-run/core';import {defaultEquality,assertSystem,computeInspectState,createThrottle,buildHistoryState,pickFacts,mergeHydrationFacts,runTrackedSelector,depsChanged}from'@directive-run/core/adapter-utils';export{shallowEqual}from'@directive-run/core/adapter-utils';import {createContext,createSignal,onCleanup,useContext}from'solid-js';var F=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var v=typeof process<"u"&&process.env?.NODE_ENV!=="production";function H(e,t){return assertSystem("useFact",e),v&&typeof t=="function"&&console.error("[Directive] useFact() received a function. Did you mean useSelector()? useFact() takes a string key or array of keys, not a selector function."),Array.isArray(t)?Q(e,t):L(e,t)}function L(e,t){v&&(e.facts.$store.has(t)||console.warn(`[Directive] useFact("${t}") \u2014 fact not found in store. Check that "${t}" is defined in your module's schema.`));let[n,r]=createSignal(e.facts.$store.get(t)),s=e.facts.$store.subscribe([t],()=>{r(()=>e.facts.$store.get(t));});return onCleanup(s),n}function Q(e,t){let n=()=>{let i={};for(let u of t)i[u]=e.facts.$store.get(u);return i},[r,s]=createSignal(n()),o=e.facts.$store.subscribe(t,()=>{s(n);});return onCleanup(o),r}function N(e,t){return assertSystem("useDerived",e),v&&typeof t=="function"&&console.error("[Directive] useDerived() received a function. Did you mean useSelector()? useDerived() takes a string key or array of keys, not a selector function."),Array.isArray(t)?_(e,t):W(e,t)}function W(e,t){v&&e.read(t)===void 0&&console.warn(`[Directive] useDerived("${t}") returned undefined. Check that "${t}" is defined in your module's derive property.`);let[n,r]=createSignal(e.read(t)),s=e.subscribe([t],()=>{r(()=>e.read(t));});return onCleanup(s),n}function _(e,t){let n=()=>{let i={};for(let u of t)i[u]=e.read(u);return i},[r,s]=createSignal(n()),o=e.subscribe(t,()=>{s(n);});return onCleanup(o),r}function se(e,t,n=defaultEquality){assertSystem("useSelector",e);let r=new Set(Object.keys(e.derive??{})),s=()=>runTrackedSelector(e,r,t),o=s(),i=o.factKeys,u=o.deriveKeys,[c,f]=createSignal(o.value),d=[],p=()=>{for(let y of d)y();d.length=0;let S=()=>{let y=s();f(m=>n(m,y.value)?m:y.value),depsChanged(i,y.factKeys,u,y.deriveKeys)&&(i=y.factKeys,u=y.deriveKeys,p());};i.length>0?d.push(e.facts.$store.subscribe(i,S)):u.length===0&&d.push(e.facts.$store.subscribeAll(S)),u.length>0&&d.push(e.subscribe(u,S));};return p(),onCleanup(()=>{for(let S of d)S();}),c}function re(e){return assertSystem("useDispatch",e),t=>{e.dispatch(t);}}function B(e){return assertSystem("useEvents",e),e.events}function j(e,t,n){assertSystem("useWatch",e);let r=e.watch(t,n);onCleanup(r);}function oe(e,t){assertSystem("useInspect",e);let[n,r]=createSignal(computeInspectState(e)),s=()=>{r(computeInspectState(e));};if(t?.throttleMs&&t.throttleMs>0){let{throttled:o,cleanup:i}=createThrottle(s,t.throttleMs),u=e.facts.$store.subscribeAll(o),c=e.onSettledChange(o);onCleanup(()=>{i(),u(),c();});}else {let o=e.facts.$store.subscribeAll(s),i=e.onSettledChange(s);onCleanup(()=>{o(),i();});}return n}function R(e,t){if(Array.isArray(t)){let o=()=>{let f={};for(let d of t)f[d]=e.getStatus(d);return f},[i,u]=createSignal(o()),c=e.subscribe(()=>{u(o);});return onCleanup(c),i}let[n,r]=createSignal(e.getStatus(t)),s=e.subscribe(()=>{r(e.getStatus(t));});return onCleanup(s),n}function ie(e,t){assertSystem("useExplain",e);let[n,r]=createSignal(e.explain(t)),s=()=>r(e.explain(t)),o=e.facts.$store.subscribeAll(s),i=e.onSettledChange(s);return onCleanup(()=>{o(),i();}),n}function ue(e,t){assertSystem("useConstraintStatus",e);let n=()=>{let c=e.inspect();return t?c.constraints.find(f=>f.id===t)??null:c.constraints},[r,s]=createSignal(n()),o=()=>s(n),i=e.facts.$store.subscribeAll(o),u=e.onSettledChange(o);return onCleanup(()=>{i(),u();}),r}function ce(e,t,n){assertSystem("useOptimisticUpdate",e);let[r,s]=createSignal(false),[o,i]=createSignal(null),u=null,c=null,f=()=>{u&&(e.restore(u),u=null),s(false),i(null),c?.(),c=null;},d=p=>{u=e.getSnapshot(),s(true),i(null),e.batch(p),t&&n&&(c?.(),c=t.subscribe(()=>{let S=t.getStatus(n);!S.isLoading&&!S.hasError?(u=null,s(false),c?.(),c=null):S.hasError&&(i(()=>S.lastError),f());}));};return onCleanup(()=>{c?.();}),{mutate:d,isPending:r,error:o,rollback:f}}function ae(e,t){let n=Array.isArray(t)?t:[t],r=()=>n.some(s=>e.getStatus(s).isLoading);if(r())throw new Promise(s=>{let o=e.subscribe(()=>{r()||(o(),s());});});return R(e,t)}function le(e){assertSystem("useHistory",e);let[t,n]=createSignal(buildHistoryState(e)),r=e.onHistoryChange(()=>n(buildHistoryState(e)));return onCleanup(r),t}function z(e,t){let n=[...t?.plugins??[]],r;if(t?.status){let M=createRequirementStatusPlugin();r=M,n.push(M.plugin);}let s=createSystem({module:e,plugins:n.length>0?n:void 0,trace:t?.trace,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:t?.initialFacts});typeof window<"u"?s.start():s.initialize(),onCleanup(()=>{s.destroyAsync().catch(()=>{});});let o=t?.facts,i=t?.derived,u=!o&&!i,[c,f]=createSignal(u?s.facts.$store.toObject():pickFacts(s,o??[])),d=u?s.facts.$store.subscribeAll(()=>{f(()=>s.facts.$store.toObject());}):o&&o.length>0?s.facts.$store.subscribe(o,()=>{f(()=>pickFacts(s,o));}):null,p=u?Object.keys(s.derive??{}):i??[],S=()=>{let M={};for(let h of p)M[h]=s.read(h);return M},[y,m]=createSignal(S()),I=p.length>0?s.subscribe(p,()=>{m(S);}):null;onCleanup(()=>{d?.(),I?.();});let w=s.events;return {system:s,facts:c,derived:y,events:w,dispatch:M=>s.dispatch(M),statusPlugin:r}}function de(e,t){let[n,r]=createSignal(e.read(t)),s=e.subscribe([t],()=>{r(()=>e.read(t));});return [n,s]}function Se(e,t){let[n,r]=createSignal(e.facts.$store.get(t)),s=e.facts.$store.subscribe([t],()=>{r(()=>e.facts.$store.get(t));});return [n,s]}function fe(){return {useFact:(e,t)=>H(e,t),useDerived:(e,t)=>N(e,t),useDispatch:e=>t=>{e.dispatch(t);},useEvents:e=>B(e),useWatch:(e,t,n)=>j(e,t,n)}}function ge(e,t,n){let[r,s]=createSignal(n(e)),o=e.subscribe(t,()=>{s(()=>n(e));});return onCleanup(o),r}var b=null;function J(){if(!b)try{b=F("@directive-run/query").createQuerySystem;}catch{throw new Error("[Directive] @directive-run/query is not installed. Install it with: pnpm add @directive-run/query")}return b}function ye(e){let n=J()(e);return typeof window<"u"&&!n.isRunning&&n.start(),onCleanup(()=>{n.destroyAsync().catch(()=>{});}),n}var D=createContext(),pe=D.Provider;function Me(e,t){let n=useContext(D),r=mergeHydrationFacts(n,t?.initialFacts);return z(e,{...t,initialFacts:r}).system}function ve(e,t={},n={}){let r=n.pollMs??250,s=Math.max(50,r);if(v&&(n.pollMs!==void 0&&n.pollMs<50&&console.warn(`[Directive] useAuditLedger() pollMs=${n.pollMs} is below the 50 ms floor; clamped to 50 ms.`),s<100)){let c=e.toJSON().entries.length;c>1e3&&console.warn(`[Directive] useAuditLedger() polling every ${s} ms against a ${c}-entry ledger \u2014 that's a lot of CPU per tick. Consider raising pollMs or tightening the filter.`);}let[o,i]=createSignal(e.query(t)),u=setInterval(()=>i(()=>e.query(t)),s);return onCleanup(()=>clearInterval(u)),o}export{pe as DirectiveHydrator,de as createDerivedSignal,Se as createFactSignal,fe as createTypedHooks,ve as useAuditLedger,ue as useConstraintStatus,N as useDerived,z as useDirective,re as useDispatch,B as useEvents,ie as useExplain,H as useFact,le as useHistory,Me as useHydratedSystem,oe as useInspect,ge as useNamespacedSelector,ce as useOptimisticUpdate,ye as useQuerySystem,R as useRequirementStatus,se as useSelector,ae as useSuspenseRequirement,j as useWatch};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dev-true.ts","../src/index.ts"],"names":["dev_true_default","useFact","system","keyOrKeys","assertSystem","_useFactMulti","_useFactSingle","factKey","value","setValue","createSignal","unsubscribe","onCleanup","factKeys","getValues","result","key","state","setState","useDerived","idOrIds","_useDerivedMulti","_useDerivedSingle","derivationId","derivationIds","id","useSelector","selector","equalityFn","defaultEquality","deriveKeySet","runWithTracking","runTrackedSelector","initial","trackedFactKeys","trackedDeriveKeys","selected","setSelected","unsubs","resubscribe","unsub","onUpdate","prev","depsChanged","useDispatch","event","useEvents","useWatch","callback","useInspect","options","computeInspectState","update","throttled","cleanup","createThrottle","unsubFacts","unsubSettled","useRequirementStatus","statusPlugin","typeOrTypes","type","status","setStatus","useExplain","requirementId","explanation","setExplanation","useConstraintStatus","constraintId","getVal","inspection","c","useOptimisticUpdate","requirementType","isPending","setIsPending","error","setError","snapshot","statusUnsub","rollback","mutate","updateFn","useSuspenseRequirement","types","anyLoading","t","resolve","useHistory","buildHistoryState","useDirective","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","createSystem","derivedKeys","subscribeAll","factsState","setFactsState","pickFacts","allDerivationKeys","getDerived","derivedState","setDerivedState","unsubDerived","events","createDerivedSignal","createFactSignal","createTypedHooks","useNamespacedSelector","keys","_createQuerySystem","getCreateQuerySystem","useQuerySystem","HydrationContext","createContext","DirectiveHydrator","useHydratedSystem","useContext","mergedFacts","mergeHydrationFacts","useAuditLedger","ledger","filter","opts","requestedPollMs","pollMs","entryCount","entries","setEntries"],"mappings":"woBAAA,IAAOA,CAAAA,CAAQ,OAAO,OAAA,CAAY,GAAA,EAChC,QAAQ,GAAA,EAAK,QAAA,GAAa,YAAA,CCiFrB,SAASC,CAAAA,CAEdC,CAAAA,CACAC,EACmB,CAUnB,OATAC,aAAa,SAAA,CAAWF,CAAM,EAC1BF,CAAAA,EAAiB,OAAOG,GAAc,UAAA,EACxC,OAAA,CAAQ,MACN,gJAEF,CAAA,CAIE,MAAM,OAAA,CAAQA,CAAS,EAClBE,CAAAA,CAAcH,CAAAA,CAAQC,CAAS,CAAA,CAIjCG,CAAAA,CAAeJ,CAAAA,CAAQC,CAAS,CACzC,CAGA,SAASG,CAAAA,CACPJ,CAAAA,CACAK,EACmB,CACfP,CAAAA,GACGE,CAAAA,CAAO,KAAA,CAAM,MAAA,CAAO,GAAA,CAAIK,CAAO,CAAA,EAClC,OAAA,CAAQ,KACN,CAAA,qBAAA,EAAwBA,CAAO,kDACdA,CAAO,CAAA,qCAAA,CAC1B,CAAA,CAAA,CAIJ,GAAM,CAACC,CAAAA,CAAOC,CAAQ,CAAA,CAAIC,YAAAA,CAAaR,EAAO,KAAA,CAAM,MAAA,CAAO,IAAIK,CAAO,CAAC,EACjEI,CAAAA,CAAcT,CAAAA,CAAO,MAAM,MAAA,CAAO,SAAA,CAAU,CAACK,CAAO,CAAA,CAAG,IAAM,CACjEE,CAAAA,CAAS,IAAMP,CAAAA,CAAO,KAAA,CAAM,MAAA,CAAO,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EAAaC,CAAAA,CAAW,CAAE,GAAGC,CAAAA,CAAQ,YAAA,CAAc6B,CAAY,CAAC,CAAA,CACpE,MACL,CAiCO,SAASE,GACdC,CAAAA,CACAC,CAAAA,CAAsB,EAAC,CACvBC,CAAAA,CAA4B,EAAC,CACI,CACjC,IAAMC,EAAkBD,CAAAA,CAAK,MAAA,EAAU,IACjCE,CAAAA,CAAS,IAAA,CAAK,IAAI,EAAA,CAAID,CAAe,CAAA,CAE3C,GAAIhI,CAAAA,GACE+H,CAAAA,CAAK,SAAW,MAAA,EAAaA,CAAAA,CAAK,OAAS,EAAA,EAC7C,OAAA,CAAQ,KACN,CAAA,oCAAA,EAAuCA,CAAAA,CAAK,MAAM,CAAA,4CAAA,CACpD,CAAA,CAEEE,CAAAA,CAAS,KAAK,CAChB,IAAMC,EAAaL,CAAAA,CAAO,MAAA,GAAS,OAAA,CAAQ,MAAA,CACvCK,CAAAA,CAAa,GAAA,EACf,OAAA,CAAQ,IAAA,CACN,8CAA8CD,CAAM,CAAA,cAAA,EAAiBC,CAAU,CAAA,oGAAA,CACjF,EAEJ,CAGF,GAAM,CAACC,CAAAA,CAASC,CAAU,CAAA,CAAI1H,YAAAA,CAC5BmH,EAAO,KAAA,CAAMC,CAAM,CACrB,CAAA,CACMrG,CAAAA,CAAK,YAAY,IAAM2G,CAAAA,CAAW,IAAMP,CAAAA,CAAO,KAAA,CAAMC,CAAM,CAAC,CAAA,CAAGG,CAAM,EAC3E,OAAArH,SAAAA,CAAU,IAAM,aAAA,CAAca,CAAE,CAAC,CAAA,CAE1B0G,CACT","file":"index.js","sourcesContent":["export default typeof process !== \"undefined\" &&\n process.env?.NODE_ENV !== \"production\";\n","/**\n * Solid Adapter - Consolidated SolidJS primitives for Directive\n *\n * 16 active exports: useFact, useDerived, useDispatch, useSelector,\n * useWatch, useInspect, useRequirementStatus, useEvents, useExplain,\n * useConstraintStatus, useOptimisticUpdate, useDirective, useHistory,\n * createTypedHooks, useSuspenseRequirement, shallowEqual\n *\n * Signal factories: createDerivedSignal, createFactSignal\n */\n\nimport type {\n ErrorBoundaryConfig,\n InferDerivations,\n InferEvents,\n InferFacts,\n InferSelectorState,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemSnapshot,\n TraceOption,\n} from \"@directive-run/core\";\nimport {\n createRequirementStatusPlugin,\n createSystem,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n type ConstraintInfo,\n type InspectState,\n assertSystem,\n buildHistoryState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n mergeHydrationFacts,\n pickFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport {\n type Accessor,\n createContext,\n createSignal,\n onCleanup,\n useContext,\n} from \"solid-js\";\nimport isDevelopment from \"#is-development\";\n\n// Re-export for convenience\nexport type { RequirementTypeStatus, InspectState, ConstraintInfo };\nexport { shallowEqual };\n\n/** Type for the requirement status plugin return value */\nexport type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;\n\n// ============================================================================\n// useFact — single key or multi key\n// ============================================================================\n\n/** Single key overload */\nexport function useFact<\n S extends ModuleSchema,\n K extends keyof InferFacts<S> & string,\n>(\n system: SingleModuleSystem<S>,\n factKey: K,\n): Accessor<InferFacts<S>[K] | undefined>;\n/** Multi-key overload */\nexport function useFact<\n S extends ModuleSchema,\n K extends keyof InferFacts<S> & string,\n>(\n system: SingleModuleSystem<S>,\n factKeys: K[],\n): Accessor<Pick<InferFacts<S>, K>>;\n/** Implementation */\nexport function useFact(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n keyOrKeys: string | string[],\n): Accessor<unknown> {\n assertSystem(\"useFact\", system);\n if (isDevelopment && typeof keyOrKeys === \"function\") {\n console.error(\n \"[Directive] useFact() received a function. Did you mean useSelector()? \" +\n \"useFact() takes a string key or array of keys, not a selector function.\",\n );\n }\n\n // Multi-key path\n if (Array.isArray(keyOrKeys)) {\n return _useFactMulti(system, keyOrKeys);\n }\n\n // Single key path\n return _useFactSingle(system, keyOrKeys);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactSingle(\n system: SingleModuleSystem<any>,\n factKey: string,\n): Accessor<unknown> {\n if (isDevelopment) {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] useFact(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n\n const [value, setValue] = createSignal(system.facts.$store.get(factKey));\n const unsubscribe = system.facts.$store.subscribe([factKey], () => {\n setValue(() => system.facts.$store.get(factKey));\n });\n onCleanup(unsubscribe);\n return value;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactMulti(\n system: SingleModuleSystem<any>,\n factKeys: string[],\n): Accessor<Record<string, unknown>> {\n const getValues = (): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n for (const key of factKeys) {\n result[key] = system.facts.$store.get(key);\n }\n return result;\n };\n const [state, setState] = createSignal(getValues());\n const unsubscribe = system.facts.$store.subscribe(factKeys, () => {\n setState(getValues);\n });\n onCleanup(unsubscribe);\n return state;\n}\n\n// ============================================================================\n// useDerived — single key or multi key\n// ============================================================================\n\n/** Single key overload */\nexport function useDerived<\n S extends ModuleSchema,\n K extends keyof InferDerivations<S> & string,\n>(\n system: SingleModuleSystem<S>,\n derivationId: K,\n): Accessor<InferDerivations<S>[K]>;\n/** Multi-key overload */\nexport function useDerived<\n S extends ModuleSchema,\n K extends keyof InferDerivations<S> & string,\n>(\n system: SingleModuleSystem<S>,\n derivationIds: K[],\n): Accessor<Pick<InferDerivations<S>, K>>;\n/** Implementation */\nexport function useDerived(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n idOrIds: string | string[],\n): Accessor<unknown> {\n assertSystem(\"useDerived\", system);\n if (isDevelopment && typeof idOrIds === \"function\") {\n console.error(\n \"[Directive] useDerived() received a function. Did you mean useSelector()? \" +\n \"useDerived() takes a string key or array of keys, not a selector function.\",\n );\n }\n\n // Multi-key path\n if (Array.isArray(idOrIds)) {\n return _useDerivedMulti(system, idOrIds);\n }\n\n // Single key path\n return _useDerivedSingle(system, idOrIds);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useDerivedSingle(\n system: SingleModuleSystem<any>,\n derivationId: string,\n): Accessor<unknown> {\n if (isDevelopment) {\n const initialValue = system.read(derivationId);\n if (initialValue === undefined) {\n console.warn(\n `[Directive] useDerived(\"${derivationId}\") returned undefined. ` +\n `Check that \"${derivationId}\" is defined in your module's derive property.`,\n );\n }\n }\n const [value, setValue] = createSignal(system.read(derivationId));\n const unsubscribe = system.subscribe([derivationId], () => {\n setValue(() => system.read(derivationId));\n });\n onCleanup(unsubscribe);\n return value;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useDerivedMulti(\n system: SingleModuleSystem<any>,\n derivationIds: string[],\n): Accessor<Record<string, unknown>> {\n const getValues = (): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n for (const id of derivationIds) {\n result[id] = system.read(id);\n }\n return result;\n };\n const [state, setState] = createSignal(getValues());\n const unsubscribe = system.subscribe(derivationIds, () => {\n setState(getValues);\n });\n onCleanup(unsubscribe);\n return state;\n}\n\n// ============================================================================\n// useSelector — auto-tracking selector over facts and derivations\n// ============================================================================\n\n/**\n * Auto-tracking selector over facts and derivations.\n * Uses `withTracking()` to detect which facts the selector accesses,\n * then subscribes only to those keys.\n */\nexport function useSelector<S extends ModuleSchema, R>(\n system: SingleModuleSystem<S>,\n selector: (state: InferSelectorState<S>) => R,\n equalityFn?: (a: R, b: R) => boolean,\n): Accessor<R>;\nexport function useSelector(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n selector: (state: any) => unknown,\n equalityFn: (a: unknown, b: unknown) => boolean = defaultEquality,\n): Accessor<unknown> {\n assertSystem(\"useSelector\", system);\n const deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n // Build a tracking-aware state proxy that exposes both facts and derivations\n const runWithTracking = () =>\n runTrackedSelector(system, deriveKeySet, selector);\n\n const initial = runWithTracking();\n let trackedFactKeys = initial.factKeys;\n let trackedDeriveKeys = initial.deriveKeys;\n const [selected, setSelected] = createSignal(initial.value);\n\n const unsubs: Array<() => void> = [];\n\n const resubscribe = () => {\n for (const unsub of unsubs) unsub();\n unsubs.length = 0;\n\n const onUpdate = () => {\n const result = runWithTracking();\n setSelected((prev) => {\n if (!equalityFn(prev, result.value)) return result.value;\n return prev;\n });\n // Re-track: check if deps changed\n if (\n depsChanged(\n trackedFactKeys,\n result.factKeys,\n trackedDeriveKeys,\n result.deriveKeys,\n )\n ) {\n trackedFactKeys = result.factKeys;\n trackedDeriveKeys = result.deriveKeys;\n resubscribe();\n }\n };\n\n if (trackedFactKeys.length > 0) {\n unsubs.push(system.facts.$store.subscribe(trackedFactKeys, onUpdate));\n } else if (trackedDeriveKeys.length === 0) {\n unsubs.push(system.facts.$store.subscribeAll(onUpdate));\n }\n if (trackedDeriveKeys.length > 0) {\n unsubs.push(system.subscribe(trackedDeriveKeys, onUpdate));\n }\n };\n\n resubscribe();\n\n onCleanup(() => {\n for (const unsub of unsubs) unsub();\n });\n\n return selected;\n}\n\n// ============================================================================\n// useDispatch\n// ============================================================================\n\nexport function useDispatch<S extends ModuleSchema>(\n system: SingleModuleSystem<S>,\n): (event: InferEvents<S>) => void {\n assertSystem(\"useDispatch\", system);\n return (event: InferEvents<S>) => {\n system.dispatch(event);\n };\n}\n\n// ============================================================================\n// useEvents — memoized events reference\n// ============================================================================\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<S extends ModuleSchema>(\n system: SingleModuleSystem<S>,\n): SingleModuleSystem<S>[\"events\"] {\n assertSystem(\"useEvents\", system);\n return system.events;\n}\n\n// ============================================================================\n// useWatch — derivation or fact side-effect\n// ============================================================================\n\n/** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */\nexport function useWatch<\n S extends ModuleSchema,\n K extends keyof InferDerivations<S> & string,\n>(\n system: SingleModuleSystem<S>,\n key: K,\n callback: (\n newValue: InferDerivations<S>[K],\n previousValue: InferDerivations<S>[K] | undefined,\n ) => void,\n): void;\n/** Watch a fact key with auto-detection. */\nexport function useWatch<\n S extends ModuleSchema,\n K extends keyof InferFacts<S> & string,\n>(\n system: SingleModuleSystem<S>,\n key: K,\n callback: (\n newValue: InferFacts<S>[K] | undefined,\n previousValue: InferFacts<S>[K] | undefined,\n ) => void,\n): void;\n/** Implementation */\nexport function useWatch(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n key: string,\n callback: (newValue: unknown, prevValue: unknown) => void,\n): void {\n assertSystem(\"useWatch\", system);\n\n const unsubscribe = system.watch(key, callback);\n onCleanup(unsubscribe);\n}\n\n// ============================================================================\n// useInspect — consolidated inspection hook\n// ============================================================================\n\n/** Options for useInspect */\nexport interface UseInspectOptions {\n throttleMs?: number;\n}\n\n/**\n * Consolidated system inspection hook.\n * Returns Accessor<InspectState> with optional throttling.\n */\nexport function useInspect(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n options?: UseInspectOptions,\n): Accessor<InspectState> {\n assertSystem(\"useInspect\", system);\n const [state, setState] = createSignal<InspectState>(\n computeInspectState(system),\n );\n\n const update = () => {\n setState(computeInspectState(system));\n };\n\n if (options?.throttleMs && options.throttleMs > 0) {\n const { throttled, cleanup } = createThrottle(update, options.throttleMs);\n const unsubFacts = system.facts.$store.subscribeAll(throttled);\n const unsubSettled = system.onSettledChange(throttled);\n onCleanup(() => {\n cleanup();\n unsubFacts();\n unsubSettled();\n });\n } else {\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n onCleanup(() => {\n unsubFacts();\n unsubSettled();\n });\n }\n\n return state;\n}\n\n// ============================================================================\n// useRequirementStatus — single or multi\n// ============================================================================\n\n/** Single type overload */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n type: string,\n): Accessor<RequirementTypeStatus>;\n/** Multi-type overload */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n types: string[],\n): Accessor<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n typeOrTypes: string | string[],\n):\n | Accessor<RequirementTypeStatus>\n | Accessor<Record<string, RequirementTypeStatus>> {\n if (Array.isArray(typeOrTypes)) {\n const getValues = (): Record<string, RequirementTypeStatus> => {\n const result: Record<string, RequirementTypeStatus> = {};\n for (const type of typeOrTypes) {\n result[type] = statusPlugin.getStatus(type);\n }\n return result;\n };\n const [state, setState] = createSignal(getValues());\n const unsubscribe = statusPlugin.subscribe(() => {\n setState(getValues);\n });\n onCleanup(unsubscribe);\n return state;\n }\n\n const [status, setStatus] = createSignal<RequirementTypeStatus>(\n statusPlugin.getStatus(typeOrTypes),\n );\n const unsubscribe = statusPlugin.subscribe(() => {\n setStatus(statusPlugin.getStatus(typeOrTypes));\n });\n onCleanup(unsubscribe);\n return status;\n}\n\n// ============================================================================\n// useExplain — reactive requirement explanation\n// ============================================================================\n\n/**\n * Reactively returns the explanation string for a requirement.\n */\nexport function useExplain(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n requirementId: string,\n): Accessor<string | null> {\n assertSystem(\"useExplain\", system);\n const [explanation, setExplanation] = createSignal<string | null>(\n system.explain(requirementId),\n );\n\n const update = () => setExplanation(system.explain(requirementId));\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n onCleanup(() => {\n unsubFacts();\n unsubSettled();\n });\n\n return explanation;\n}\n\n// ============================================================================\n// useConstraintStatus — reactive constraint inspection\n// ============================================================================\n\n/** Get all constraints */\nexport function useConstraintStatus(\n system: SingleModuleSystem<any>,\n): Accessor<ConstraintInfo[]>;\n/** Get a single constraint by ID */\nexport function useConstraintStatus(\n system: SingleModuleSystem<any>,\n constraintId: string,\n): Accessor<ConstraintInfo | null>;\n/** Implementation */\nexport function useConstraintStatus(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): Accessor<ConstraintInfo[] | ConstraintInfo | null> {\n assertSystem(\"useConstraintStatus\", system);\n const getVal = () => {\n const inspection = system.inspect();\n if (!constraintId) return inspection.constraints;\n return (\n inspection.constraints.find(\n (c: ConstraintInfo) => c.id === constraintId,\n ) ?? null\n );\n };\n\n const [state, setState] = createSignal<\n ConstraintInfo[] | ConstraintInfo | null\n >(getVal());\n\n const update = () => setState(getVal);\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n onCleanup(() => {\n unsubFacts();\n unsubSettled();\n });\n\n return state;\n}\n\n// ============================================================================\n// useOptimisticUpdate — batch with rollback on failure\n// ============================================================================\n\nexport interface OptimisticUpdateResult {\n mutate: (updateFn: () => void) => void;\n isPending: Accessor<boolean>;\n error: Accessor<Error | null>;\n rollback: () => void;\n}\n\n/**\n * Optimistic update hook. Saves a snapshot before mutating, monitors\n * a requirement type via statusPlugin, and rolls back on failure.\n */\nexport function useOptimisticUpdate(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n): OptimisticUpdateResult {\n assertSystem(\"useOptimisticUpdate\", system);\n const [isPending, setIsPending] = createSignal(false);\n const [error, setError] = createSignal<Error | null>(null);\n let snapshot: SystemSnapshot | null = null;\n let statusUnsub: (() => void) | null = null;\n\n const rollback = () => {\n if (snapshot) {\n system.restore(snapshot);\n snapshot = null;\n }\n setIsPending(false);\n setError(null);\n statusUnsub?.();\n statusUnsub = null;\n };\n\n const mutate = (updateFn: () => void) => {\n snapshot = system.getSnapshot();\n setIsPending(true);\n setError(null);\n system.batch(updateFn);\n\n if (statusPlugin && requirementType) {\n statusUnsub?.();\n statusUnsub = statusPlugin.subscribe(() => {\n const status = statusPlugin.getStatus(requirementType);\n if (!status.isLoading && !status.hasError) {\n snapshot = null;\n setIsPending(false);\n statusUnsub?.();\n statusUnsub = null;\n } else if (status.hasError) {\n setError(() => status.lastError);\n rollback();\n }\n });\n }\n };\n\n onCleanup(() => {\n statusUnsub?.();\n });\n\n return { mutate, isPending, error, rollback };\n}\n\n// ============================================================================\n// useSuspenseRequirement — Solid-specific Suspense integration\n// ============================================================================\n\n/**\n * Single type: throws a promise while the requirement is pending (Suspense).\n */\nexport function useSuspenseRequirement(\n statusPlugin: StatusPlugin,\n type: string,\n): Accessor<RequirementTypeStatus>;\n/**\n * Multi-type: throws a promise while any of the requirements are pending.\n */\nexport function useSuspenseRequirement(\n statusPlugin: StatusPlugin,\n types: string[],\n): Accessor<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useSuspenseRequirement(\n statusPlugin: StatusPlugin,\n typeOrTypes: string | string[],\n):\n | Accessor<RequirementTypeStatus>\n | Accessor<Record<string, RequirementTypeStatus>> {\n const types = Array.isArray(typeOrTypes) ? typeOrTypes : [typeOrTypes];\n\n // Check if any are still loading — if so, throw a promise\n const anyLoading = () =>\n types.some((t) => statusPlugin.getStatus(t).isLoading);\n\n if (anyLoading()) {\n throw new Promise<void>((resolve) => {\n const unsub = statusPlugin.subscribe(() => {\n if (!anyLoading()) {\n unsub();\n resolve();\n }\n });\n });\n }\n\n // Once resolved, return normal accessor\n if (Array.isArray(typeOrTypes)) {\n return useRequirementStatus(statusPlugin, typeOrTypes) as Accessor<\n Record<string, RequirementTypeStatus>\n >;\n }\n return useRequirementStatus(\n statusPlugin,\n typeOrTypes,\n ) as Accessor<RequirementTypeStatus>;\n}\n\n// ============================================================================\n// useHistory — reactive history signal\n// ============================================================================\n\n/**\n * Reactive history signal. Returns an Accessor that updates\n * when snapshots are taken or navigation occurs.\n *\n * @example\n * ```tsx\n * const history = useHistory(system);\n * <button disabled={!history()?.canGoBack} onClick={() => history()?.goBack()}>Undo</button>\n * ```\n */\nexport function useHistory(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n): Accessor<ReturnType<typeof buildHistoryState>> {\n assertSystem(\"useHistory\", system);\n const [state, setState] = createSignal<ReturnType<typeof buildHistoryState>>(\n buildHistoryState(system),\n );\n const unsub = system.onHistoryChange(() =>\n setState(buildHistoryState(system)),\n );\n onCleanup(unsub);\n return state;\n}\n\n// ============================================================================\n// Scoped System\n// ============================================================================\n\n/** Configuration for useDirective */\ninterface UseDirectiveConfig {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n /** Fact keys to subscribe to (omit for all) */\n facts?: string[];\n /** Derivation keys to subscribe to (omit for all) */\n derived?: string[];\n}\n\n/**\n * Create a scoped Directive system with automatic lifecycle management.\n * When no `facts` or `derived` keys are specified, subscribes to ALL\n * facts and derivations and returns reactive signals.\n *\n * @example\n * ```tsx\n * // Subscribe to everything\n * const { facts, derived, events, dispatch } = useDirective(counterModule);\n *\n * // Selective keys\n * const { facts, derived } = useDirective(counterModule, { facts: [\"count\"], derived: [\"doubled\"] });\n * ```\n */\nexport function useDirective<M extends ModuleSchema>(\n moduleDef: ModuleDef<M>,\n config?: UseDirectiveConfig,\n) {\n const allPlugins = [...(config?.plugins ?? [])];\n let statusPlugin: StatusPlugin | undefined;\n\n if (config?.status) {\n const sp = createRequirementStatusPlugin();\n statusPlugin = sp;\n // biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n allPlugins.push(sp.plugin as Plugin<any>);\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: moduleDef,\n plugins: allPlugins.length > 0 ? allPlugins : undefined,\n trace: config?.trace,\n errorBoundary: config?.errorBoundary,\n tickMs: config?.tickMs,\n zeroConfig: config?.zeroConfig,\n initialFacts: config?.initialFacts,\n } as any) as unknown as SingleModuleSystem<M>;\n\n // SSR guard: initialize facts for SSR rendering, start reconciliation only in the browser\n if (typeof window !== \"undefined\") {\n system.start();\n } else {\n system.initialize();\n }\n\n onCleanup(() => {\n system.destroy();\n });\n\n const factKeys = config?.facts;\n const derivedKeys = config?.derived;\n const subscribeAll = !factKeys && !derivedKeys;\n\n // Subscribe to facts\n const [factsState, setFactsState] = createSignal(\n subscribeAll\n ? (system.facts.$store.toObject() as InferFacts<M>)\n : (pickFacts(system, factKeys ?? []) as InferFacts<M>),\n );\n const unsubFacts = subscribeAll\n ? system.facts.$store.subscribeAll(() => {\n setFactsState(() => system.facts.$store.toObject() as InferFacts<M>);\n })\n : factKeys && factKeys.length > 0\n ? system.facts.$store.subscribe(factKeys, () => {\n setFactsState(() => pickFacts(system, factKeys) as InferFacts<M>);\n })\n : null;\n\n // Subscribe to derivations\n const allDerivationKeys = subscribeAll\n ? Object.keys(system.derive ?? {})\n : (derivedKeys ?? []);\n const getDerived = (): InferDerivations<M> => {\n const result: Record<string, unknown> = {};\n for (const key of allDerivationKeys) {\n result[key] = system.read(key);\n }\n return result as InferDerivations<M>;\n };\n const [derivedState, setDerivedState] = createSignal(getDerived());\n const unsubDerived =\n allDerivationKeys.length > 0\n ? system.subscribe(allDerivationKeys, () => {\n setDerivedState(getDerived);\n })\n : null;\n\n onCleanup(() => {\n unsubFacts?.();\n unsubDerived?.();\n });\n\n const events = system.events;\n const dispatch = (event: InferEvents<M>) => system.dispatch(event);\n\n return {\n system,\n facts: factsState as Accessor<InferFacts<M>>,\n derived: derivedState as Accessor<InferDerivations<M>>,\n events,\n dispatch,\n statusPlugin,\n };\n}\n\n// ============================================================================\n// Signal Factories (for use outside components)\n// ============================================================================\n\n/**\n * Create a derivation signal outside of a component.\n */\nexport function createDerivedSignal<T>(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n derivationId: string,\n): [Accessor<T>, () => void] {\n const [value, setValue] = createSignal<T>(system.read(derivationId) as T);\n const unsubscribe = system.subscribe([derivationId], () => {\n setValue(() => system.read(derivationId) as T);\n });\n return [value, unsubscribe];\n}\n\n/**\n * Create a fact signal outside of a component.\n */\nexport function createFactSignal<T>(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n factKey: string,\n): [Accessor<T | undefined>, () => void] {\n const [value, setValue] = createSignal<T | undefined>(\n system.facts.$store.get(factKey) as T | undefined,\n );\n const unsubscribe = system.facts.$store.subscribe([factKey], () => {\n setValue(() => system.facts.$store.get(factKey) as T | undefined);\n });\n return [value, unsubscribe];\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n useFact: <K extends keyof InferFacts<M> & string>(\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => Accessor<InferFacts<M>[K] | undefined>;\n useDerived: <K extends keyof InferDerivations<M> & string>(\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => Accessor<InferDerivations<M>[K]>;\n useDispatch: (\n system: SingleModuleSystem<M>,\n ) => (event: InferEvents<M>) => void;\n useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n useWatch: <K extends string>(\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => void;\n} {\n return {\n useFact: <K extends keyof InferFacts<M> & string>(\n system: SingleModuleSystem<M>,\n factKey: K,\n ) =>\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n useFact(system as SingleModuleSystem<any>, factKey as string) as Accessor<\n InferFacts<M>[K] | undefined\n >,\n useDerived: <K extends keyof InferDerivations<M> & string>(\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) =>\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n useDerived(\n system as SingleModuleSystem<any>,\n derivationId as string,\n ) as Accessor<InferDerivations<M>[K]>,\n useDispatch: (system: SingleModuleSystem<M>) => {\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n },\n useEvents: (system: SingleModuleSystem<M>) => useEvents<M>(system),\n useWatch: <K extends string>(\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) =>\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n useWatch(system as SingleModuleSystem<any>, key, callback),\n };\n}\n\n// ============================================================================\n// useNamespacedSelector — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * SolidJS accessor that selects from a NamespacedSystem.\n * Subscribes to specified keys and provides reactive updates.\n *\n * @param system - The namespaced system\n * @param keys - Namespaced keys to subscribe to (e.g., [\"auth.token\", \"data.count\"])\n * @param selector - Function that reads from system.facts / system.derive\n *\n * @example\n * ```tsx\n * const token = useNamespacedSelector(system, [\"auth.token\"], (s) => s.facts.auth.token);\n * ```\n */\nexport function useNamespacedSelector<Modules extends ModulesMap, R>(\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n): Accessor<R> {\n const [value, setValue] = createSignal<R>(selector(system));\n const unsubscribe = system.subscribe(keys, () => {\n setValue(() => selector(system));\n });\n onCleanup(unsubscribe);\n\n return value as Accessor<R>;\n}\n\n// ============================================================================\n// useQuerySystem — Stable query system with lifecycle management\n// ============================================================================\n\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nlet _createQuerySystem: ((config: Record<string, unknown>) => any) | null =\n null;\n\nfunction getCreateQuerySystem() {\n if (!_createQuerySystem) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const mod = require(\"@directive-run/query\");\n _createQuerySystem = mod.createQuerySystem;\n } catch {\n throw new Error(\n \"[Directive] @directive-run/query is not installed. \" +\n \"Install it with: pnpm add @directive-run/query\",\n );\n }\n }\n\n return _createQuerySystem!;\n}\n\n/**\n * Solid composable to create and manage a query system with proper lifecycle.\n *\n * Accepts a config object or a factory function that creates the system.\n * Handles cleanup via onCleanup.\n *\n * @example\n * ```tsx\n * import { useQuerySystem, useDerived } from \"@directive-run/solid\";\n *\n * function App() {\n * const app = useQuerySystem({\n * facts: { userId: \"\" },\n * queries: { user: { key: ..., fetcher: ... } },\n * });\n *\n * const user = useDerived(app, \"user\");\n * return <div>{user().data?.name}</div>;\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nexport function useQuerySystem<\n T extends {\n start: () => void;\n destroy: () => void;\n isRunning?: boolean;\n [key: string]: any;\n },\n>(config: Record<string, unknown>): T {\n const createQuerySystem = getCreateQuerySystem();\n const system = createQuerySystem(config) as T;\n\n if (typeof window !== \"undefined\" && !system.isRunning) {\n system.start();\n }\n\n onCleanup(() => {\n system.destroy();\n });\n\n return system;\n}\n\n// ============================================================================\n// SSR Hydration\n// ============================================================================\n\n/** Context for SSR hydration snapshot */\nconst HydrationContext = createContext<Record<string, unknown> | undefined>();\n\n/**\n * Solid component that provides a DistributableSnapshot to child components.\n * Uses `HydrationContext.Provider` under the hood — pass `value` as the snapshot.\n *\n * @example\n * ```tsx\n * <DirectiveHydrator value={snapshot}>\n * <App />\n * </DirectiveHydrator>\n * ```\n */\nexport const DirectiveHydrator = HydrationContext.Provider;\n\n/**\n * Create a system hydrated from a server snapshot.\n * Must be used inside a `<DirectiveHydrator>` ancestor.\n */\nexport function useHydratedSystem<S extends ModuleSchema>(\n moduleDef: ModuleDef<S>,\n config?: UseDirectiveConfig,\n): SingleModuleSystem<S> {\n const snapshot = useContext(HydrationContext);\n const mergedFacts = mergeHydrationFacts(\n snapshot,\n config?.initialFacts as Record<string, unknown>,\n );\n\n return useDirective(moduleDef, { ...config, initialFacts: mergedFacts })\n .system;\n}\n\n// ============================================================================\n// useAuditLedger — live ledger entries with filter (R4.I parity)\n// ============================================================================\n\nimport type { AuditEntry, AuditLedger, QueryFilter } from \"@directive-run/core\";\n\n/**\n * Subscribe to an audit ledger and return the latest entries matching\n * `filter` as a Solid `Accessor`. Re-evaluates on each poll tick\n * (default 250 ms — override with `pollMs`).\n *\n * **Polling floor:** `pollMs` is clamped to a minimum of 50 ms to prevent\n * accidental DoS from typos like `pollMs: 5`. Values below the floor are\n * silently clamped in production; dev mode logs a warning.\n *\n * @example\n * ```tsx\n * import { useAuditLedger } from \"@directive-run/solid\";\n *\n * function AuditLog(props: { ledger: AuditLedger }) {\n * const entries = useAuditLedger(props.ledger, { kind: \"constraint.evaluate\", limit: 20 });\n * return (\n * <ul>\n * <For each={entries()}>\n * {(e) => <li>{e.kind} @ {new Date(e.ts).toISOString()}</li>}\n * </For>\n * </ul>\n * );\n * }\n * ```\n */\nexport function useAuditLedger(\n ledger: AuditLedger,\n filter: QueryFilter = {},\n opts: { pollMs?: number } = {},\n): Accessor<readonly AuditEntry[]> {\n const requestedPollMs = opts.pollMs ?? 250;\n const pollMs = Math.max(50, requestedPollMs);\n\n if (isDevelopment) {\n if (opts.pollMs !== undefined && opts.pollMs < 50) {\n console.warn(\n `[Directive] useAuditLedger() pollMs=${opts.pollMs} is below the 50 ms floor; clamped to 50 ms.`,\n );\n }\n if (pollMs < 100) {\n const entryCount = ledger.toJSON().entries.length;\n if (entryCount > 1000) {\n console.warn(\n `[Directive] useAuditLedger() polling every ${pollMs} ms against a ${entryCount}-entry ledger — that's a lot of CPU per tick. Consider raising pollMs or tightening the filter.`,\n );\n }\n }\n }\n\n const [entries, setEntries] = createSignal<readonly AuditEntry[]>(\n ledger.query(filter),\n );\n const id = setInterval(() => setEntries(() => ledger.query(filter)), pollMs);\n onCleanup(() => clearInterval(id));\n\n return entries;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/dev-true.ts","../src/index.ts"],"names":["dev_true_default","useFact","system","keyOrKeys","assertSystem","_useFactMulti","_useFactSingle","factKey","value","setValue","createSignal","unsubscribe","onCleanup","factKeys","getValues","result","key","state","setState","useDerived","idOrIds","_useDerivedMulti","_useDerivedSingle","derivationId","derivationIds","id","useSelector","selector","equalityFn","defaultEquality","deriveKeySet","runWithTracking","runTrackedSelector","initial","trackedFactKeys","trackedDeriveKeys","selected","setSelected","unsubs","resubscribe","unsub","onUpdate","prev","depsChanged","useDispatch","event","useEvents","useWatch","callback","useInspect","options","computeInspectState","update","throttled","cleanup","createThrottle","unsubFacts","unsubSettled","useRequirementStatus","statusPlugin","typeOrTypes","type","status","setStatus","useExplain","requirementId","explanation","setExplanation","useConstraintStatus","constraintId","getVal","inspection","c","useOptimisticUpdate","requirementType","isPending","setIsPending","error","setError","snapshot","statusUnsub","rollback","mutate","updateFn","useSuspenseRequirement","types","anyLoading","t","resolve","useHistory","buildHistoryState","useDirective","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","createSystem","derivedKeys","subscribeAll","factsState","setFactsState","pickFacts","allDerivationKeys","getDerived","derivedState","setDerivedState","unsubDerived","events","createDerivedSignal","createFactSignal","createTypedHooks","useNamespacedSelector","keys","_createQuerySystem","getCreateQuerySystem","useQuerySystem","HydrationContext","createContext","DirectiveHydrator","useHydratedSystem","useContext","mergedFacts","mergeHydrationFacts","useAuditLedger","ledger","filter","opts","requestedPollMs","pollMs","entryCount","entries","setEntries"],"mappings":"woBAAA,IAAOA,CAAAA,CAAQ,OAAO,OAAA,CAAY,GAAA,EAChC,QAAQ,GAAA,EAAK,QAAA,GAAa,YAAA,CCiFrB,SAASC,CAAAA,CAEdC,CAAAA,CACAC,EACmB,CAUnB,OATAC,aAAa,SAAA,CAAWF,CAAM,EAC1BF,CAAAA,EAAiB,OAAOG,GAAc,UAAA,EACxC,OAAA,CAAQ,MACN,gJAEF,CAAA,CAIE,MAAM,OAAA,CAAQA,CAAS,EAClBE,CAAAA,CAAcH,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AAS,OAAA,CAAQ,MAAA,CACvCK,CAAAA,CAAa,GAAA,EACf,OAAA,CAAQ,IAAA,CACN,8CAA8CD,CAAM,CAAA,cAAA,EAAiBC,CAAU,CAAA,oGAAA,CACjF,EAEJ,CAGF,GAAM,CAACC,CAAAA,CAASC,CAAU,CAAA,CAAI1H,YAAAA,CAC5BmH,EAAO,KAAA,CAAMC,CAAM,CACrB,CAAA,CACMrG,CAAAA,CAAK,YAAY,IAAM2G,CAAAA,CAAW,IAAMP,CAAAA,CAAO,KAAA,CAAMC,CAAM,CAAC,CAAA,CAAGG,CAAM,EAC3E,OAAArH,SAAAA,CAAU,IAAM,aAAA,CAAca,CAAE,CAAC,CAAA,CAE1B0G,CACT","file":"index.js","sourcesContent":["export default typeof process !== \"undefined\" &&\n process.env?.NODE_ENV !== \"production\";\n","/**\n * Solid Adapter - Consolidated SolidJS primitives for Directive\n *\n * 16 active exports: useFact, useDerived, useDispatch, useSelector,\n * useWatch, useInspect, useRequirementStatus, useEvents, useExplain,\n * useConstraintStatus, useOptimisticUpdate, useDirective, useHistory,\n * createTypedHooks, useSuspenseRequirement, shallowEqual\n *\n * Signal factories: createDerivedSignal, createFactSignal\n */\n\nimport type {\n ErrorBoundaryConfig,\n InferDerivations,\n InferEvents,\n InferFacts,\n InferSelectorState,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemSnapshot,\n TraceOption,\n} from \"@directive-run/core\";\nimport {\n createRequirementStatusPlugin,\n createSystem,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n type ConstraintInfo,\n type InspectState,\n assertSystem,\n buildHistoryState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n mergeHydrationFacts,\n pickFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport {\n type Accessor,\n createContext,\n createSignal,\n onCleanup,\n useContext,\n} from \"solid-js\";\nimport isDevelopment from \"#is-development\";\n\n// Re-export for convenience\nexport type { RequirementTypeStatus, InspectState, ConstraintInfo };\nexport { shallowEqual };\n\n/** Type for the requirement status plugin return value */\nexport type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;\n\n// ============================================================================\n// useFact — single key or multi key\n// ============================================================================\n\n/** Single key overload */\nexport function useFact<\n S extends ModuleSchema,\n K extends keyof InferFacts<S> & string,\n>(\n system: SingleModuleSystem<S>,\n factKey: K,\n): Accessor<InferFacts<S>[K] | undefined>;\n/** Multi-key overload */\nexport function useFact<\n S extends ModuleSchema,\n K extends keyof InferFacts<S> & string,\n>(\n system: SingleModuleSystem<S>,\n factKeys: K[],\n): Accessor<Pick<InferFacts<S>, K>>;\n/** Implementation */\nexport function useFact(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n keyOrKeys: string | string[],\n): Accessor<unknown> {\n assertSystem(\"useFact\", system);\n if (isDevelopment && typeof keyOrKeys === \"function\") {\n console.error(\n \"[Directive] useFact() received a function. Did you mean useSelector()? \" +\n \"useFact() takes a string key or array of keys, not a selector function.\",\n );\n }\n\n // Multi-key path\n if (Array.isArray(keyOrKeys)) {\n return _useFactMulti(system, keyOrKeys);\n }\n\n // Single key path\n return _useFactSingle(system, keyOrKeys);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactSingle(\n system: SingleModuleSystem<any>,\n factKey: string,\n): Accessor<unknown> {\n if (isDevelopment) {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] useFact(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n\n const [value, setValue] = createSignal(system.facts.$store.get(factKey));\n const unsubscribe = system.facts.$store.subscribe([factKey], () => {\n setValue(() => system.facts.$store.get(factKey));\n });\n onCleanup(unsubscribe);\n return value;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactMulti(\n system: SingleModuleSystem<any>,\n factKeys: string[],\n): Accessor<Record<string, unknown>> {\n const getValues = (): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n for (const key of factKeys) {\n result[key] = system.facts.$store.get(key);\n }\n return result;\n };\n const [state, setState] = createSignal(getValues());\n const unsubscribe = system.facts.$store.subscribe(factKeys, () => {\n setState(getValues);\n });\n onCleanup(unsubscribe);\n return state;\n}\n\n// ============================================================================\n// useDerived — single key or multi key\n// ============================================================================\n\n/** Single key overload */\nexport function useDerived<\n S extends ModuleSchema,\n K extends keyof InferDerivations<S> & string,\n>(\n system: SingleModuleSystem<S>,\n derivationId: K,\n): Accessor<InferDerivations<S>[K]>;\n/** Multi-key overload */\nexport function useDerived<\n S extends ModuleSchema,\n K extends keyof InferDerivations<S> & string,\n>(\n system: SingleModuleSystem<S>,\n derivationIds: K[],\n): Accessor<Pick<InferDerivations<S>, K>>;\n/** Implementation */\nexport function useDerived(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n idOrIds: string | string[],\n): Accessor<unknown> {\n assertSystem(\"useDerived\", system);\n if (isDevelopment && typeof idOrIds === \"function\") {\n console.error(\n \"[Directive] useDerived() received a function. Did you mean useSelector()? \" +\n \"useDerived() takes a string key or array of keys, not a selector function.\",\n );\n }\n\n // Multi-key path\n if (Array.isArray(idOrIds)) {\n return _useDerivedMulti(system, idOrIds);\n }\n\n // Single key path\n return _useDerivedSingle(system, idOrIds);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useDerivedSingle(\n system: SingleModuleSystem<any>,\n derivationId: string,\n): Accessor<unknown> {\n if (isDevelopment) {\n const initialValue = system.read(derivationId);\n if (initialValue === undefined) {\n console.warn(\n `[Directive] useDerived(\"${derivationId}\") returned undefined. ` +\n `Check that \"${derivationId}\" is defined in your module's derive property.`,\n );\n }\n }\n const [value, setValue] = createSignal(system.read(derivationId));\n const unsubscribe = system.subscribe([derivationId], () => {\n setValue(() => system.read(derivationId));\n });\n onCleanup(unsubscribe);\n return value;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useDerivedMulti(\n system: SingleModuleSystem<any>,\n derivationIds: string[],\n): Accessor<Record<string, unknown>> {\n const getValues = (): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n for (const id of derivationIds) {\n result[id] = system.read(id);\n }\n return result;\n };\n const [state, setState] = createSignal(getValues());\n const unsubscribe = system.subscribe(derivationIds, () => {\n setState(getValues);\n });\n onCleanup(unsubscribe);\n return state;\n}\n\n// ============================================================================\n// useSelector — auto-tracking selector over facts and derivations\n// ============================================================================\n\n/**\n * Auto-tracking selector over facts and derivations.\n * Uses `withTracking()` to detect which facts the selector accesses,\n * then subscribes only to those keys.\n */\nexport function useSelector<S extends ModuleSchema, R>(\n system: SingleModuleSystem<S>,\n selector: (state: InferSelectorState<S>) => R,\n equalityFn?: (a: R, b: R) => boolean,\n): Accessor<R>;\nexport function useSelector(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n selector: (state: any) => unknown,\n equalityFn: (a: unknown, b: unknown) => boolean = defaultEquality,\n): Accessor<unknown> {\n assertSystem(\"useSelector\", system);\n const deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n // Build a tracking-aware state proxy that exposes both facts and derivations\n const runWithTracking = () =>\n runTrackedSelector(system, deriveKeySet, selector);\n\n const initial = runWithTracking();\n let trackedFactKeys = initial.factKeys;\n let trackedDeriveKeys = initial.deriveKeys;\n const [selected, setSelected] = createSignal(initial.value);\n\n const unsubs: Array<() => void> = [];\n\n const resubscribe = () => {\n for (const unsub of unsubs) unsub();\n unsubs.length = 0;\n\n const onUpdate = () => {\n const result = runWithTracking();\n setSelected((prev) => {\n if (!equalityFn(prev, result.value)) return result.value;\n return prev;\n });\n // Re-track: check if deps changed\n if (\n depsChanged(\n trackedFactKeys,\n result.factKeys,\n trackedDeriveKeys,\n result.deriveKeys,\n )\n ) {\n trackedFactKeys = result.factKeys;\n trackedDeriveKeys = result.deriveKeys;\n resubscribe();\n }\n };\n\n if (trackedFactKeys.length > 0) {\n unsubs.push(system.facts.$store.subscribe(trackedFactKeys, onUpdate));\n } else if (trackedDeriveKeys.length === 0) {\n unsubs.push(system.facts.$store.subscribeAll(onUpdate));\n }\n if (trackedDeriveKeys.length > 0) {\n unsubs.push(system.subscribe(trackedDeriveKeys, onUpdate));\n }\n };\n\n resubscribe();\n\n onCleanup(() => {\n for (const unsub of unsubs) unsub();\n });\n\n return selected;\n}\n\n// ============================================================================\n// useDispatch\n// ============================================================================\n\nexport function useDispatch<S extends ModuleSchema>(\n system: SingleModuleSystem<S>,\n): (event: InferEvents<S>) => void {\n assertSystem(\"useDispatch\", system);\n return (event: InferEvents<S>) => {\n system.dispatch(event);\n };\n}\n\n// ============================================================================\n// useEvents — memoized events reference\n// ============================================================================\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<S extends ModuleSchema>(\n system: SingleModuleSystem<S>,\n): SingleModuleSystem<S>[\"events\"] {\n assertSystem(\"useEvents\", system);\n return system.events;\n}\n\n// ============================================================================\n// useWatch — derivation or fact side-effect\n// ============================================================================\n\n/** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */\nexport function useWatch<\n S extends ModuleSchema,\n K extends keyof InferDerivations<S> & string,\n>(\n system: SingleModuleSystem<S>,\n key: K,\n callback: (\n newValue: InferDerivations<S>[K],\n previousValue: InferDerivations<S>[K] | undefined,\n ) => void,\n): void;\n/** Watch a fact key with auto-detection. */\nexport function useWatch<\n S extends ModuleSchema,\n K extends keyof InferFacts<S> & string,\n>(\n system: SingleModuleSystem<S>,\n key: K,\n callback: (\n newValue: InferFacts<S>[K] | undefined,\n previousValue: InferFacts<S>[K] | undefined,\n ) => void,\n): void;\n/** Implementation */\nexport function useWatch(\n // biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n system: SingleModuleSystem<any>,\n key: string,\n callback: (newValue: unknown, prevValue: unknown) => void,\n): void {\n assertSystem(\"useWatch\", system);\n\n const unsubscribe = system.watch(key, callback);\n onCleanup(unsubscribe);\n}\n\n// ============================================================================\n// useInspect — consolidated inspection hook\n// ============================================================================\n\n/** Options for useInspect */\nexport interface UseInspectOptions {\n throttleMs?: number;\n}\n\n/**\n * Consolidated system inspection hook.\n * Returns Accessor<InspectState> with optional throttling.\n */\nexport function useInspect(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n options?: UseInspectOptions,\n): Accessor<InspectState> {\n assertSystem(\"useInspect\", system);\n const [state, setState] = createSignal<InspectState>(\n computeInspectState(system),\n );\n\n const update = () => {\n setState(computeInspectState(system));\n };\n\n if (options?.throttleMs && options.throttleMs > 0) {\n const { throttled, cleanup } = createThrottle(update, options.throttleMs);\n const unsubFacts = system.facts.$store.subscribeAll(throttled);\n const unsubSettled = system.onSettledChange(throttled);\n onCleanup(() => {\n cleanup();\n unsubFacts();\n unsubSettled();\n });\n } else {\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n onCleanup(() => {\n unsubFacts();\n unsubSettled();\n });\n }\n\n return state;\n}\n\n// ============================================================================\n// useRequirementStatus — single or multi\n// ============================================================================\n\n/** Single type overload */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n type: string,\n): Accessor<RequirementTypeStatus>;\n/** Multi-type overload */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n types: string[],\n): Accessor<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n typeOrTypes: string | string[],\n):\n | Accessor<RequirementTypeStatus>\n | Accessor<Record<string, RequirementTypeStatus>> {\n if (Array.isArray(typeOrTypes)) {\n const getValues = (): Record<string, RequirementTypeStatus> => {\n const result: Record<string, RequirementTypeStatus> = {};\n for (const type of typeOrTypes) {\n result[type] = statusPlugin.getStatus(type);\n }\n return result;\n };\n const [state, setState] = createSignal(getValues());\n const unsubscribe = statusPlugin.subscribe(() => {\n setState(getValues);\n });\n onCleanup(unsubscribe);\n return state;\n }\n\n const [status, setStatus] = createSignal<RequirementTypeStatus>(\n statusPlugin.getStatus(typeOrTypes),\n );\n const unsubscribe = statusPlugin.subscribe(() => {\n setStatus(statusPlugin.getStatus(typeOrTypes));\n });\n onCleanup(unsubscribe);\n return status;\n}\n\n// ============================================================================\n// useExplain — reactive requirement explanation\n// ============================================================================\n\n/**\n * Reactively returns the explanation string for a requirement.\n */\nexport function useExplain(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n requirementId: string,\n): Accessor<string | null> {\n assertSystem(\"useExplain\", system);\n const [explanation, setExplanation] = createSignal<string | null>(\n system.explain(requirementId),\n );\n\n const update = () => setExplanation(system.explain(requirementId));\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n onCleanup(() => {\n unsubFacts();\n unsubSettled();\n });\n\n return explanation;\n}\n\n// ============================================================================\n// useConstraintStatus — reactive constraint inspection\n// ============================================================================\n\n/** Get all constraints */\nexport function useConstraintStatus(\n system: SingleModuleSystem<any>,\n): Accessor<ConstraintInfo[]>;\n/** Get a single constraint by ID */\nexport function useConstraintStatus(\n system: SingleModuleSystem<any>,\n constraintId: string,\n): Accessor<ConstraintInfo | null>;\n/** Implementation */\nexport function useConstraintStatus(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): Accessor<ConstraintInfo[] | ConstraintInfo | null> {\n assertSystem(\"useConstraintStatus\", system);\n const getVal = () => {\n const inspection = system.inspect();\n if (!constraintId) return inspection.constraints;\n return (\n inspection.constraints.find(\n (c: ConstraintInfo) => c.id === constraintId,\n ) ?? null\n );\n };\n\n const [state, setState] = createSignal<\n ConstraintInfo[] | ConstraintInfo | null\n >(getVal());\n\n const update = () => setState(getVal);\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n onCleanup(() => {\n unsubFacts();\n unsubSettled();\n });\n\n return state;\n}\n\n// ============================================================================\n// useOptimisticUpdate — batch with rollback on failure\n// ============================================================================\n\nexport interface OptimisticUpdateResult {\n mutate: (updateFn: () => void) => void;\n isPending: Accessor<boolean>;\n error: Accessor<Error | null>;\n rollback: () => void;\n}\n\n/**\n * Optimistic update hook. Saves a snapshot before mutating, monitors\n * a requirement type via statusPlugin, and rolls back on failure.\n */\nexport function useOptimisticUpdate(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n): OptimisticUpdateResult {\n assertSystem(\"useOptimisticUpdate\", system);\n const [isPending, setIsPending] = createSignal(false);\n const [error, setError] = createSignal<Error | null>(null);\n let snapshot: SystemSnapshot | null = null;\n let statusUnsub: (() => void) | null = null;\n\n const rollback = () => {\n if (snapshot) {\n system.restore(snapshot);\n snapshot = null;\n }\n setIsPending(false);\n setError(null);\n statusUnsub?.();\n statusUnsub = null;\n };\n\n const mutate = (updateFn: () => void) => {\n snapshot = system.getSnapshot();\n setIsPending(true);\n setError(null);\n system.batch(updateFn);\n\n if (statusPlugin && requirementType) {\n statusUnsub?.();\n statusUnsub = statusPlugin.subscribe(() => {\n const status = statusPlugin.getStatus(requirementType);\n if (!status.isLoading && !status.hasError) {\n snapshot = null;\n setIsPending(false);\n statusUnsub?.();\n statusUnsub = null;\n } else if (status.hasError) {\n setError(() => status.lastError);\n rollback();\n }\n });\n }\n };\n\n onCleanup(() => {\n statusUnsub?.();\n });\n\n return { mutate, isPending, error, rollback };\n}\n\n// ============================================================================\n// useSuspenseRequirement — Solid-specific Suspense integration\n// ============================================================================\n\n/**\n * Single type: throws a promise while the requirement is pending (Suspense).\n */\nexport function useSuspenseRequirement(\n statusPlugin: StatusPlugin,\n type: string,\n): Accessor<RequirementTypeStatus>;\n/**\n * Multi-type: throws a promise while any of the requirements are pending.\n */\nexport function useSuspenseRequirement(\n statusPlugin: StatusPlugin,\n types: string[],\n): Accessor<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useSuspenseRequirement(\n statusPlugin: StatusPlugin,\n typeOrTypes: string | string[],\n):\n | Accessor<RequirementTypeStatus>\n | Accessor<Record<string, RequirementTypeStatus>> {\n const types = Array.isArray(typeOrTypes) ? typeOrTypes : [typeOrTypes];\n\n // Check if any are still loading — if so, throw a promise\n const anyLoading = () =>\n types.some((t) => statusPlugin.getStatus(t).isLoading);\n\n if (anyLoading()) {\n throw new Promise<void>((resolve) => {\n const unsub = statusPlugin.subscribe(() => {\n if (!anyLoading()) {\n unsub();\n resolve();\n }\n });\n });\n }\n\n // Once resolved, return normal accessor\n if (Array.isArray(typeOrTypes)) {\n return useRequirementStatus(statusPlugin, typeOrTypes) as Accessor<\n Record<string, RequirementTypeStatus>\n >;\n }\n return useRequirementStatus(\n statusPlugin,\n typeOrTypes,\n ) as Accessor<RequirementTypeStatus>;\n}\n\n// ============================================================================\n// useHistory — reactive history signal\n// ============================================================================\n\n/**\n * Reactive history signal. Returns an Accessor that updates\n * when snapshots are taken or navigation occurs.\n *\n * @example\n * ```tsx\n * const history = useHistory(system);\n * <button disabled={!history()?.canGoBack} onClick={() => history()?.goBack()}>Undo</button>\n * ```\n */\nexport function useHistory(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n): Accessor<ReturnType<typeof buildHistoryState>> {\n assertSystem(\"useHistory\", system);\n const [state, setState] = createSignal<ReturnType<typeof buildHistoryState>>(\n buildHistoryState(system),\n );\n const unsub = system.onHistoryChange(() =>\n setState(buildHistoryState(system)),\n );\n onCleanup(unsub);\n return state;\n}\n\n// ============================================================================\n// Scoped System\n// ============================================================================\n\n/** Configuration for useDirective */\ninterface UseDirectiveConfig {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n /** Fact keys to subscribe to (omit for all) */\n facts?: string[];\n /** Derivation keys to subscribe to (omit for all) */\n derived?: string[];\n}\n\n/**\n * Create a scoped Directive system with automatic lifecycle management.\n * When no `facts` or `derived` keys are specified, subscribes to ALL\n * facts and derivations and returns reactive signals.\n *\n * @example\n * ```tsx\n * // Subscribe to everything\n * const { facts, derived, events, dispatch } = useDirective(counterModule);\n *\n * // Selective keys\n * const { facts, derived } = useDirective(counterModule, { facts: [\"count\"], derived: [\"doubled\"] });\n * ```\n */\nexport function useDirective<M extends ModuleSchema>(\n moduleDef: ModuleDef<M>,\n config?: UseDirectiveConfig,\n) {\n const allPlugins = [...(config?.plugins ?? [])];\n let statusPlugin: StatusPlugin | undefined;\n\n if (config?.status) {\n const sp = createRequirementStatusPlugin();\n statusPlugin = sp;\n // biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n allPlugins.push(sp.plugin as Plugin<any>);\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: moduleDef,\n plugins: allPlugins.length > 0 ? allPlugins : undefined,\n trace: config?.trace,\n errorBoundary: config?.errorBoundary,\n tickMs: config?.tickMs,\n zeroConfig: config?.zeroConfig,\n initialFacts: config?.initialFacts,\n } as any) as unknown as SingleModuleSystem<M>;\n\n // SSR guard: initialize facts for SSR rendering, start reconciliation only in the browser\n if (typeof window !== \"undefined\") {\n system.start();\n } else {\n system.initialize();\n }\n\n onCleanup(() => {\n // RFC 0009 follow-up (R18 Tier 2-B): destroyAsync so source\n // unsubscribes complete; fire-and-forget with swallow-catch\n // (the framework's onCleanup is sync).\n system.destroyAsync().catch(() => {});\n });\n\n const factKeys = config?.facts;\n const derivedKeys = config?.derived;\n const subscribeAll = !factKeys && !derivedKeys;\n\n // Subscribe to facts\n const [factsState, setFactsState] = createSignal(\n subscribeAll\n ? (system.facts.$store.toObject() as InferFacts<M>)\n : (pickFacts(system, factKeys ?? []) as InferFacts<M>),\n );\n const unsubFacts = subscribeAll\n ? system.facts.$store.subscribeAll(() => {\n setFactsState(() => system.facts.$store.toObject() as InferFacts<M>);\n })\n : factKeys && factKeys.length > 0\n ? system.facts.$store.subscribe(factKeys, () => {\n setFactsState(() => pickFacts(system, factKeys) as InferFacts<M>);\n })\n : null;\n\n // Subscribe to derivations\n const allDerivationKeys = subscribeAll\n ? Object.keys(system.derive ?? {})\n : (derivedKeys ?? []);\n const getDerived = (): InferDerivations<M> => {\n const result: Record<string, unknown> = {};\n for (const key of allDerivationKeys) {\n result[key] = system.read(key);\n }\n return result as InferDerivations<M>;\n };\n const [derivedState, setDerivedState] = createSignal(getDerived());\n const unsubDerived =\n allDerivationKeys.length > 0\n ? system.subscribe(allDerivationKeys, () => {\n setDerivedState(getDerived);\n })\n : null;\n\n onCleanup(() => {\n unsubFacts?.();\n unsubDerived?.();\n });\n\n const events = system.events;\n const dispatch = (event: InferEvents<M>) => system.dispatch(event);\n\n return {\n system,\n facts: factsState as Accessor<InferFacts<M>>,\n derived: derivedState as Accessor<InferDerivations<M>>,\n events,\n dispatch,\n statusPlugin,\n };\n}\n\n// ============================================================================\n// Signal Factories (for use outside components)\n// ============================================================================\n\n/**\n * Create a derivation signal outside of a component.\n */\nexport function createDerivedSignal<T>(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n derivationId: string,\n): [Accessor<T>, () => void] {\n const [value, setValue] = createSignal<T>(system.read(derivationId) as T);\n const unsubscribe = system.subscribe([derivationId], () => {\n setValue(() => system.read(derivationId) as T);\n });\n return [value, unsubscribe];\n}\n\n/**\n * Create a fact signal outside of a component.\n */\nexport function createFactSignal<T>(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n factKey: string,\n): [Accessor<T | undefined>, () => void] {\n const [value, setValue] = createSignal<T | undefined>(\n system.facts.$store.get(factKey) as T | undefined,\n );\n const unsubscribe = system.facts.$store.subscribe([factKey], () => {\n setValue(() => system.facts.$store.get(factKey) as T | undefined);\n });\n return [value, unsubscribe];\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n useFact: <K extends keyof InferFacts<M> & string>(\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => Accessor<InferFacts<M>[K] | undefined>;\n useDerived: <K extends keyof InferDerivations<M> & string>(\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => Accessor<InferDerivations<M>[K]>;\n useDispatch: (\n system: SingleModuleSystem<M>,\n ) => (event: InferEvents<M>) => void;\n useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n useWatch: <K extends string>(\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => void;\n} {\n return {\n useFact: <K extends keyof InferFacts<M> & string>(\n system: SingleModuleSystem<M>,\n factKey: K,\n ) =>\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n useFact(system as SingleModuleSystem<any>, factKey as string) as Accessor<\n InferFacts<M>[K] | undefined\n >,\n useDerived: <K extends keyof InferDerivations<M> & string>(\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) =>\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n useDerived(\n system as SingleModuleSystem<any>,\n derivationId as string,\n ) as Accessor<InferDerivations<M>[K]>,\n useDispatch: (system: SingleModuleSystem<M>) => {\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n },\n useEvents: (system: SingleModuleSystem<M>) => useEvents<M>(system),\n useWatch: <K extends string>(\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) =>\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n useWatch(system as SingleModuleSystem<any>, key, callback),\n };\n}\n\n// ============================================================================\n// useNamespacedSelector — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * SolidJS accessor that selects from a NamespacedSystem.\n * Subscribes to specified keys and provides reactive updates.\n *\n * @param system - The namespaced system\n * @param keys - Namespaced keys to subscribe to (e.g., [\"auth.token\", \"data.count\"])\n * @param selector - Function that reads from system.facts / system.derive\n *\n * @example\n * ```tsx\n * const token = useNamespacedSelector(system, [\"auth.token\"], (s) => s.facts.auth.token);\n * ```\n */\nexport function useNamespacedSelector<Modules extends ModulesMap, R>(\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n): Accessor<R> {\n const [value, setValue] = createSignal<R>(selector(system));\n const unsubscribe = system.subscribe(keys, () => {\n setValue(() => selector(system));\n });\n onCleanup(unsubscribe);\n\n return value as Accessor<R>;\n}\n\n// ============================================================================\n// useQuerySystem — Stable query system with lifecycle management\n// ============================================================================\n\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nlet _createQuerySystem: ((config: Record<string, unknown>) => any) | null =\n null;\n\nfunction getCreateQuerySystem() {\n if (!_createQuerySystem) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const mod = require(\"@directive-run/query\");\n _createQuerySystem = mod.createQuerySystem;\n } catch {\n throw new Error(\n \"[Directive] @directive-run/query is not installed. \" +\n \"Install it with: pnpm add @directive-run/query\",\n );\n }\n }\n\n return _createQuerySystem!;\n}\n\n/**\n * Solid composable to create and manage a query system with proper lifecycle.\n *\n * Accepts a config object or a factory function that creates the system.\n * Handles cleanup via onCleanup.\n *\n * @example\n * ```tsx\n * import { useQuerySystem, useDerived } from \"@directive-run/solid\";\n *\n * function App() {\n * const app = useQuerySystem({\n * facts: { userId: \"\" },\n * queries: { user: { key: ..., fetcher: ... } },\n * });\n *\n * const user = useDerived(app, \"user\");\n * return <div>{user().data?.name}</div>;\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nexport function useQuerySystem<\n T extends {\n start: () => void;\n destroy: () => void;\n isRunning?: boolean;\n [key: string]: any;\n },\n>(config: Record<string, unknown>): T {\n const createQuerySystem = getCreateQuerySystem();\n const system = createQuerySystem(config) as T;\n\n if (typeof window !== \"undefined\" && !system.isRunning) {\n system.start();\n }\n\n onCleanup(() => {\n // RFC 0009 follow-up (R18 Tier 2-B): destroyAsync so source\n // unsubscribes complete; fire-and-forget with swallow-catch\n // (the framework's onCleanup is sync).\n system.destroyAsync().catch(() => {});\n });\n\n return system;\n}\n\n// ============================================================================\n// SSR Hydration\n// ============================================================================\n\n/** Context for SSR hydration snapshot */\nconst HydrationContext = createContext<Record<string, unknown> | undefined>();\n\n/**\n * Solid component that provides a DistributableSnapshot to child components.\n * Uses `HydrationContext.Provider` under the hood — pass `value` as the snapshot.\n *\n * @example\n * ```tsx\n * <DirectiveHydrator value={snapshot}>\n * <App />\n * </DirectiveHydrator>\n * ```\n */\nexport const DirectiveHydrator = HydrationContext.Provider;\n\n/**\n * Create a system hydrated from a server snapshot.\n * Must be used inside a `<DirectiveHydrator>` ancestor.\n */\nexport function useHydratedSystem<S extends ModuleSchema>(\n moduleDef: ModuleDef<S>,\n config?: UseDirectiveConfig,\n): SingleModuleSystem<S> {\n const snapshot = useContext(HydrationContext);\n const mergedFacts = mergeHydrationFacts(\n snapshot,\n config?.initialFacts as Record<string, unknown>,\n );\n\n return useDirective(moduleDef, { ...config, initialFacts: mergedFacts })\n .system;\n}\n\n// ============================================================================\n// useAuditLedger — live ledger entries with filter (R4.I parity)\n// ============================================================================\n\nimport type { AuditEntry, AuditLedger, QueryFilter } from \"@directive-run/core\";\n\n/**\n * Subscribe to an audit ledger and return the latest entries matching\n * `filter` as a Solid `Accessor`. Re-evaluates on each poll tick\n * (default 250 ms — override with `pollMs`).\n *\n * **Polling floor:** `pollMs` is clamped to a minimum of 50 ms to prevent\n * accidental DoS from typos like `pollMs: 5`. Values below the floor are\n * silently clamped in production; dev mode logs a warning.\n *\n * @example\n * ```tsx\n * import { useAuditLedger } from \"@directive-run/solid\";\n *\n * function AuditLog(props: { ledger: AuditLedger }) {\n * const entries = useAuditLedger(props.ledger, { kind: \"constraint.evaluate\", limit: 20 });\n * return (\n * <ul>\n * <For each={entries()}>\n * {(e) => <li>{e.kind} @ {new Date(e.ts).toISOString()}</li>}\n * </For>\n * </ul>\n * );\n * }\n * ```\n */\nexport function useAuditLedger(\n ledger: AuditLedger,\n filter: QueryFilter = {},\n opts: { pollMs?: number } = {},\n): Accessor<readonly AuditEntry[]> {\n const requestedPollMs = opts.pollMs ?? 250;\n const pollMs = Math.max(50, requestedPollMs);\n\n if (isDevelopment) {\n if (opts.pollMs !== undefined && opts.pollMs < 50) {\n console.warn(\n `[Directive] useAuditLedger() pollMs=${opts.pollMs} is below the 50 ms floor; clamped to 50 ms.`,\n );\n }\n if (pollMs < 100) {\n const entryCount = ledger.toJSON().entries.length;\n if (entryCount > 1000) {\n console.warn(\n `[Directive] useAuditLedger() polling every ${pollMs} ms against a ${entryCount}-entry ledger — that's a lot of CPU per tick. Consider raising pollMs or tightening the filter.`,\n );\n }\n }\n }\n\n const [entries, setEntries] = createSignal<readonly AuditEntry[]>(\n ledger.query(filter),\n );\n const id = setInterval(() => setEntries(() => ledger.query(filter)), pollMs);\n onCleanup(() => clearInterval(id));\n\n return entries;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directive-run/solid",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.1",
|
|
4
4
|
"imports": {
|
|
5
5
|
"#is-development": {
|
|
6
6
|
"production": "./src/dev-false.ts",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"solid-js": "^1.8.0",
|
|
66
66
|
"tsup": "^8.3.5",
|
|
67
67
|
"typescript": "^5.7.2",
|
|
68
|
-
"@directive-run/core": "1.
|
|
68
|
+
"@directive-run/core": "1.20.1",
|
|
69
69
|
"@directive-run/query": "1.2.0"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|