@directive-run/svelte 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +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
|
|
1
|
+
'use strict';var core=require('@directive-run/core'),adapterUtils=require('@directive-run/core/adapter-utils'),svelte=require('svelte'),store=require('svelte/store');function C(e,t){return process.env.NODE_ENV!=="production"&&e.read(t)===void 0&&console.warn(`[Directive] createDerivedStore("${t}") returned undefined. Check that "${t}" is defined in your module's derive property.`),store.readable(e.read(t),n=>e.subscribe([t],()=>{n(e.read(t));}))}function E(e,t){let n=()=>{let s={};for(let r of t)s[r]=e.read(r);return s};return store.readable(n(),s=>e.subscribe(t,()=>{s(n());}))}function w(e,t){return process.env.NODE_ENV!=="production"&&(e.facts.$store.has(t)||console.warn(`[Directive] createFactStore("${t}") \u2014 fact not found in store. Check that "${t}" is defined in your module's schema.`)),store.readable(e.facts.$store.get(t),n=>e.facts.$store.subscribe([t],()=>{n(e.facts.$store.get(t));}))}function O(e){return store.readable(e.inspect(),t=>{let n=()=>t(e.inspect()),s=e.facts.$store.subscribeAll(n),r=e.onSettledChange(n);return ()=>{s(),r();}})}function V(e,t){return adapterUtils.assertSystem("useFact",e),process.env.NODE_ENV!=="production"&&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)?$(e,t):w(e,t)}function $(e,t){let n=()=>{let s={};for(let r of t)s[r]=e.facts.$store.get(r);return s};return store.readable(n(),s=>e.facts.$store.subscribe(t,()=>{s(n());}))}function q(e,t){return adapterUtils.assertSystem("useDerived",e),process.env.NODE_ENV!=="production"&&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(e,t):C(e,t)}function j(e,t,n=adapterUtils.defaultEquality){adapterUtils.assertSystem("useSelector",e);let s=new Set(Object.keys(e.derive??{})),r=()=>adapterUtils.runTrackedSelector(e,s,t),o=r();return store.readable(o.value,l=>{let p=o.value,g=o.factKeys,S=o.deriveKeys,d=[],y=()=>{for(let c of d)c();d.length=0;let f=()=>{let c=r();n(p,c.value)||(p=c.value,l(c.value)),adapterUtils.depsChanged(g,c.factKeys,S,c.deriveKeys)&&(g=c.factKeys,S=c.deriveKeys,y());};g.length>0?d.push(e.facts.$store.subscribe(g,f)):S.length===0&&d.push(e.facts.$store.subscribeAll(f)),S.length>0&&d.push(e.subscribe(S,f));};return y(),()=>{for(let f of d)f();}})}function z(e){return adapterUtils.assertSystem("useDispatch",e),t=>{e.dispatch(t);}}function A(e){return adapterUtils.assertSystem("useEvents",e),e.events}function P(e,t,n){adapterUtils.assertSystem("useWatch",e);let s=e.watch(t,n);svelte.onDestroy(s);}function H(e,t){return adapterUtils.assertSystem("useInspect",e),t?.throttleMs&&t.throttleMs>0?store.readable(adapterUtils.computeInspectState(e),n=>{let{throttled:s,cleanup:r}=adapterUtils.createThrottle(()=>{n(adapterUtils.computeInspectState(e));},t.throttleMs),o=e.facts.$store.subscribeAll(s),l=e.onSettledChange(s);return ()=>{r(),o(),l();}}):store.readable(adapterUtils.computeInspectState(e),n=>{let s=()=>n(adapterUtils.computeInspectState(e)),r=e.facts.$store.subscribeAll(s),o=e.onSettledChange(s);return ()=>{r(),o();}})}function L(e,t){if(Array.isArray(t)){let n=()=>{let s={};for(let r of t)s[r]=e.getStatus(r);return s};return store.readable(n(),s=>e.subscribe(()=>{s(n());}))}return store.readable(e.getStatus(t),n=>e.subscribe(()=>{n(e.getStatus(t));}))}function G(e,t){return adapterUtils.assertSystem("useExplain",e),store.readable(e.explain(t),n=>{let s=()=>n(e.explain(t)),r=e.facts.$store.subscribeAll(s),o=e.onSettledChange(s);return ()=>{r(),o();}})}function J(e,t){return adapterUtils.assertSystem("useConstraintStatus",e),store.readable(x(e,t),n=>{let s=()=>n(x(e,t)),r=e.facts.$store.subscribeAll(s),o=e.onSettledChange(s);return ()=>{r(),o();}})}function x(e,t){let n=e.inspect();return t?n.constraints.find(s=>s.id===t)??null:n.constraints}function Q(e,t,n){adapterUtils.assertSystem("useOptimisticUpdate",e);let s=false,r=null,o=null,l=null,p=new Set,g=new Set,S={subscribe(u){return u(s),p.add(u),()=>p.delete(u)}},d={subscribe(u){return u(r),g.add(u),()=>g.delete(u)}},y=u=>{s=u;for(let M of p)M(u);},f=u=>{r=u;for(let M of g)M(u);},c=()=>{o&&(e.restore(o),o=null),y(false),f(null),l?.(),l=null;},a=u=>{o=e.getSnapshot(),y(true),f(null),e.batch(u),t&&n&&(l?.(),l=t.subscribe(()=>{let M=t.getStatus(n);!M.isLoading&&!M.hasError?(o=null,y(false),l?.(),l=null):M.hasError&&(f(M.lastError),c());}));};return svelte.onDestroy(()=>{l?.();}),{mutate:a,isPending:S,error:d,rollback:c}}function X(e){return adapterUtils.assertSystem("useTimeTravel",e),store.readable(adapterUtils.buildTimeTravelState(e),t=>e.onTimeTravelChange(()=>t(adapterUtils.buildTimeTravelState(e))))}function Y(e,t){let n=[...t?.plugins??[]],s;if(t?.status){let a=core.createRequirementStatusPlugin();s=a,n.push(a.plugin);}let r=core.createSystem({module:e,plugins:n.length>0?n:void 0,debug:t?.debug,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:t?.initialFacts});r.start(),svelte.onDestroy(()=>{r.destroy();});let o=t?.facts,l=t?.derived,p=!o&&!l,g=p?store.readable(r.facts.$store.toObject(),a=>r.facts.$store.subscribeAll(()=>{a(r.facts.$store.toObject());})):store.readable(adapterUtils.pickFacts(r,o??[]),a=>!o||o.length===0?()=>{}:r.facts.$store.subscribe(o,()=>{a(adapterUtils.pickFacts(r,o));})),S=p?Object.keys(r.derive??{}):l??[],d=()=>{let a={};for(let u of S)a[u]=r.read(u);return a},y=S.length>0?store.readable(d(),a=>r.subscribe(S,()=>{a(d());})):store.readable(d(),()=>()=>{}),f=r.events;return {system:r,facts:g,derived:y,events:f,dispatch:a=>r.dispatch(a),statusPlugin:s}}function Z(){return {useFact:(e,t)=>V(e,t),useDerived:(e,t)=>q(e,t),useDispatch:e=>t=>{e.dispatch(t);},useEvents:e=>A(e),useWatch:(e,t,n)=>P(e,t,n)}}function ee(e,t,n){return store.readable(n(e),s=>e.subscribe(t,()=>{s(n(e));}))}Object.defineProperty(exports,"shallowEqual",{enumerable:true,get:function(){return adapterUtils.shallowEqual}});exports.createDerivedStore=C;exports.createDerivedsStore=E;exports.createFactStore=w;exports.createInspectStore=O;exports.createTypedHooks=Z;exports.useConstraintStatus=J;exports.useDerived=q;exports.useDirective=Y;exports.useDispatch=z;exports.useEvents=A;exports.useExplain=G;exports.useFact=V;exports.useInspect=H;exports.useNamespacedSelector=ee;exports.useOptimisticUpdate=Q;exports.useRequirementStatus=L;exports.useSelector=j;exports.useTimeTravel=X;exports.useWatch=P;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["createDerivedStore","system","derivationId","readable","set","createDerivedsStore","derivationIds","getValues","result","id","createFactStore","factKey","createInspectStore","update","unsubFacts","unsubSettled","useFact","keyOrKeys","assertSystem","_useFactMulti","factKeys","key","useDerived","idOrIds","useSelector","selector","equalityFn","defaultEquality","deriveKeySet","runWithTracking","runTrackedSelector","initial","currentSelected","trackedFactKeys","trackedDeriveKeys","unsubs","resubscribe","unsub","onUpdate","depsChanged","useDispatch","event","useEvents","useWatch","callback","unsubscribe","onDestroy","useInspect","options","computeInspectState","throttled","cleanup","createThrottle","useRequirementStatus","statusPlugin","typeOrTypes","type","useExplain","requirementId","useConstraintStatus","constraintId","_getConstraintValue","inspection","c","useOptimisticUpdate","requirementType","isPendingValue","errorValue","snapshot","statusUnsub","pendingSubscribers","errorSubscribers","isPending","fn","error","setPending","v","setError","rollback","mutate","updateFn","status","useTimeTravel","buildTimeTravelState","useDirective","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","createSystem","derivedKeys","subscribeAll","factsStore","pickFacts","allDerivationKeys","getDerived","derivedStore","events","createTypedHooks","useNamespacedSelector","keys"],"mappings":"sKA+DO,SAASA,CAAAA,CAEfC,CAAAA,CACAC,EACc,CACd,OAAI,OAAA,CAAQ,GAAA,CAAI,WAAa,YAAA,EACPD,CAAAA,CAAO,IAAA,CAAKC,CAAY,IACxB,MAAA,EACpB,OAAA,CAAQ,IAAA,CACP,CAAA,gCAAA,EAAmCA,CAAY,CAAA,mCAAA,EAChCA,CAAY,gDAC5B,CAAA,CAIKC,cAAAA,CAAYF,EAAO,IAAA,CAAKC,CAAY,CAAA,CAASE,CAAAA,EAC/BH,EAAO,SAAA,CAAU,CAACC,CAAY,CAAA,CAAG,IAAM,CAC1DE,CAAAA,CAAIH,CAAAA,CAAO,IAAA,CAAKC,CAAY,CAAM,EACnC,CAAC,CAED,CACF,CAKO,SAASG,CAAAA,CAEfJ,CAAAA,CACAK,CAAAA,CACc,CACd,IAAMC,CAAAA,CAAY,IAAS,CAC1B,IAAMC,CAAAA,CAAkC,EAAC,CACzC,IAAA,IAAWC,KAAMH,CAAAA,CAChBE,CAAAA,CAAOC,CAAE,CAAA,CAAIR,CAAAA,CAAO,KAAKQ,CAAE,CAAA,CAE5B,OAAOD,CACR,EAEA,OAAOL,cAAAA,CAAYI,CAAAA,EAAU,CAAIH,GACZH,CAAAA,CAAO,SAAA,CAAUK,CAAAA,CAAe,IAAM,CACzDF,CAAAA,CAAIG,CAAAA,EAAW,EAChB,CAAC,CAED,CACF,CAKO,SAASG,CAAAA,CAEfT,EACAU,CAAAA,CAC0B,CAC1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,EACA,KAAA,CAAO4F,CAAAA,CACP,QAASI,CAAAA,CACT,MAAA,CAAAC,CAAAA,CACA,QAAA,CAPiBzD,GAA0BxC,CAAAA,CAAO,QAAA,CAASwC,CAAK,CAAA,CAQhE,aAAAa,CACD,CACD,CAMO,SAAS6C,GAgBd,CACD,OAAO,CACN,OAAA,CAAS,CAAyClG,EAA+BU,CAAAA,GAEhFK,CAAAA,CAAQf,CAAAA,CAAmCU,CAAO,EACnD,UAAA,CAAY,CAA+CV,CAAAA,CAA+BC,CAAAA,GAEzFoB,EAAWrB,CAAAA,CAAmCC,CAAY,CAAA,CAC3D,WAAA,CAAcD,GACLwC,CAAAA,EAA0B,CACjCxC,EAAO,QAAA,CAASwC,CAAK,EACtB,CAAA,CAED,SAAA,CAAYxC,CAAAA,EAAkCyC,CAAAA,CAAazC,CAAM,CAAA,CACjE,QAAA,CAAU,CACTA,CAAAA,CACAoB,EACAuB,CAAAA,GAGAD,CAAAA,CAAS1C,CAAAA,CAAmCoB,CAAAA,CAAKuB,CAAQ,CAC3D,CACD,CAmBO,SAASwD,EAAAA,CACfnG,EACAoG,CAAAA,CACA5E,CAAAA,CACc,CACd,OAAOtB,eAAYsB,CAAAA,CAASxB,CAAM,CAAA,CAAIG,CAAAA,EACjBH,EAAO,SAAA,CAAUoG,CAAAA,CAAM,IAAM,CAChDjG,EAAIqB,CAAAA,CAASxB,CAAM,CAAC,EACrB,CAAC,CAGD,CACF","file":"index.cjs","sourcesContent":["/**\n * Svelte Adapter - Consolidated Svelte stores for Directive\n *\n * 15 active exports: useFact, useDerived, useDispatch, useSelector,\n * useWatch, useInspect, useRequirementStatus, useEvents, useExplain,\n * useConstraintStatus, useOptimisticUpdate, useDirective, useTimeTravel,\n * createTypedHooks, shallowEqual\n *\n * Store factories: createDerivedStore, createDerivedsStore, createFactStore, createInspectStore\n */\n\nimport { onDestroy } from \"svelte\";\nimport { readable, type Readable } from \"svelte/store\";\nimport type {\n\tModuleSchema,\n\tModuleDef,\n\tModulesMap,\n\tPlugin,\n\tDebugConfig,\n\tErrorBoundaryConfig,\n\tInferFacts,\n\tInferDerivations,\n\tInferSelectorState,\n\tInferEvents,\n\tSingleModuleSystem,\n\tNamespacedSystem,\n\tSystemInspection,\n\tSystemSnapshot,\n\tTimeTravelState,\n} from \"@directive-run/core\";\nimport {\n\tcreateSystem,\n\tcreateRequirementStatusPlugin,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n\ttype InspectState,\n\ttype ConstraintInfo,\n\tcomputeInspectState,\n\tcreateThrottle,\n\tassertSystem,\n\tdefaultEquality,\n\tbuildTimeTravelState,\n\tpickFacts,\n\trunTrackedSelector,\n\tdepsChanged,\n\tshallowEqual,\n} from \"@directive-run/core/adapter-utils\";\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// Store Factories\n// ============================================================================\n\n/**\n * Create a Svelte store for a derived value.\n */\nexport function createDerivedStore<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tderivationId: string,\n): Readable<T> {\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tconst initialValue = system.read(derivationId);\n\t\tif (initialValue === undefined) {\n\t\t\tconsole.warn(\n\t\t\t\t`[Directive] createDerivedStore(\"${derivationId}\") returned undefined. ` +\n\t\t\t\t`Check that \"${derivationId}\" is defined in your module's derive property.`,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn readable<T>(system.read(derivationId) as T, (set) => {\n\t\tconst unsubscribe = system.subscribe([derivationId], () => {\n\t\t\tset(system.read(derivationId) as T);\n\t\t});\n\t\treturn unsubscribe;\n\t});\n}\n\n/**\n * Create a Svelte store for multiple derived values.\n */\nexport function createDerivedsStore<T extends Record<string, unknown>>(\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tderivationIds: string[],\n): Readable<T> {\n\tconst getValues = (): T => {\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const id of derivationIds) {\n\t\t\tresult[id] = system.read(id);\n\t\t}\n\t\treturn result as T;\n\t};\n\n\treturn readable<T>(getValues(), (set) => {\n\t\tconst unsubscribe = system.subscribe(derivationIds, () => {\n\t\t\tset(getValues());\n\t\t});\n\t\treturn unsubscribe;\n\t});\n}\n\n/**\n * Create a Svelte store for a single fact value.\n */\nexport function createFactStore<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tfactKey: string,\n): Readable<T | undefined> {\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tif (!system.facts.$store.has(factKey)) {\n\t\t\tconsole.warn(\n\t\t\t\t`[Directive] createFactStore(\"${factKey}\") — fact not found in store. ` +\n\t\t\t\t`Check that \"${factKey}\" is defined in your module's schema.`,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn readable<T | undefined>(\n\t\tsystem.facts.$store.get(factKey) as T | undefined,\n\t\t(set) => {\n\t\t\tconst unsubscribe = system.facts.$store.subscribe([factKey], () => {\n\t\t\t\tset(system.facts.$store.get(factKey) as T | undefined);\n\t\t\t});\n\t\t\treturn unsubscribe;\n\t\t},\n\t);\n}\n\n/**\n * Create a Svelte store for system inspection data.\n * NOTE: This updates on every fact change. Use sparingly in production.\n */\nexport function createInspectStore(\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n): Readable<SystemInspection> {\n\treturn readable<SystemInspection>(system.inspect(), (set) => {\n\t\tconst update = () => set(system.inspect());\n\t\tconst unsubFacts = system.facts.$store.subscribeAll(update);\n\t\tconst unsubSettled = system.onSettledChange(update);\n\t\treturn () => {\n\t\t\tunsubFacts();\n\t\t\tunsubSettled();\n\t\t};\n\t});\n}\n\n// ============================================================================\n// useFact — single key or multi key\n// ============================================================================\n\n/** Single key overload */\nexport function useFact<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(system: SingleModuleSystem<S>, factKey: K): Readable<InferFacts<S>[K] | undefined>;\n/** Multi-key overload */\nexport function useFact<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(system: SingleModuleSystem<S>, factKeys: K[]): Readable<Pick<InferFacts<S>, K>>;\n/** Implementation */\nexport function useFact(\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tsystem: SingleModuleSystem<any>,\n\tkeyOrKeys: string | string[],\n): Readable<unknown> {\n\tassertSystem(\"useFact\", system);\n\tif (process.env.NODE_ENV !== \"production\" && typeof keyOrKeys === \"function\") {\n\t\tconsole.error(\n\t\t\t\"[Directive] useFact() received a function. Did you mean useSelector()? \" +\n\t\t\t\t\"useFact() takes a string key or array of keys, not a selector function.\",\n\t\t);\n\t}\n\n\t// Multi-key path: useFact(system, [keys])\n\tif (Array.isArray(keyOrKeys)) {\n\t\treturn _useFactMulti(system, keyOrKeys);\n\t}\n\n\t// Single key path: useFact(system, key)\n\treturn createFactStore(system, keyOrKeys);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactMulti(system: SingleModuleSystem<any>, factKeys: string[]): Readable<Record<string, unknown>> {\n\tconst getValues = (): Record<string, unknown> => {\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const key of factKeys) {\n\t\t\tresult[key] = system.facts.$store.get(key);\n\t\t}\n\t\treturn result;\n\t};\n\n\treturn readable(getValues(), (set) => {\n\t\tconst unsubscribe = system.facts.$store.subscribe(factKeys, () => {\n\t\t\tset(getValues());\n\t\t});\n\t\treturn unsubscribe;\n\t});\n}\n\n// ============================================================================\n// useDerived — single key or multi key\n// ============================================================================\n\n/** Single key overload */\nexport function useDerived<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(system: SingleModuleSystem<S>, derivationId: K): Readable<InferDerivations<S>[K]>;\n/** Multi-key overload */\nexport function useDerived<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(system: SingleModuleSystem<S>, derivationIds: K[]): Readable<Pick<InferDerivations<S>, K>>;\n/** Implementation */\nexport function useDerived(\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tsystem: SingleModuleSystem<any>,\n\tidOrIds: string | string[],\n): Readable<unknown> {\n\tassertSystem(\"useDerived\", system);\n\tif (process.env.NODE_ENV !== \"production\" && typeof idOrIds === \"function\") {\n\t\tconsole.error(\n\t\t\t\"[Directive] useDerived() received a function. Did you mean useSelector()? \" +\n\t\t\t\t\"useDerived() takes a string key or array of keys, not a selector function.\",\n\t\t);\n\t}\n\n\t// Multi-key path\n\tif (Array.isArray(idOrIds)) {\n\t\treturn createDerivedsStore(system, idOrIds);\n\t}\n\n\t// Single key path\n\treturn createDerivedStore(system, idOrIds);\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>(system: SingleModuleSystem<S>, selector: (state: InferSelectorState<S>) => R, equalityFn?: (a: R, b: R) => boolean): Readable<R>;\nexport function useSelector(\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tsystem: SingleModuleSystem<any>,\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tselector: (state: any) => unknown,\n\tequalityFn: (a: unknown, b: unknown) => boolean = defaultEquality,\n): Readable<unknown> {\n\tassertSystem(\"useSelector\", system);\n\tconst deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n\t// Build a tracking-aware state proxy that exposes both facts and derivations\n\tconst runWithTracking = () => runTrackedSelector(system, deriveKeySet, selector);\n\n\tconst initial = runWithTracking();\n\n\treturn readable(initial.value, (set) => {\n\t\tlet currentSelected = initial.value;\n\t\tlet trackedFactKeys = initial.factKeys;\n\t\tlet trackedDeriveKeys = initial.deriveKeys;\n\t\tconst unsubs: Array<() => void> = [];\n\n\t\tconst resubscribe = () => {\n\t\t\tfor (const unsub of unsubs) unsub();\n\t\t\tunsubs.length = 0;\n\n\t\t\tconst onUpdate = () => {\n\t\t\t\tconst result = runWithTracking();\n\t\t\t\tif (!equalityFn(currentSelected, result.value)) {\n\t\t\t\t\tcurrentSelected = result.value;\n\t\t\t\t\tset(result.value);\n\t\t\t\t}\n\t\t\t\t// Re-track: check if deps changed\n\t\t\t\tif (depsChanged(trackedFactKeys, result.factKeys, trackedDeriveKeys, result.deriveKeys)) {\n\t\t\t\t\ttrackedFactKeys = result.factKeys;\n\t\t\t\t\ttrackedDeriveKeys = result.deriveKeys;\n\t\t\t\t\tresubscribe();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tif (trackedFactKeys.length > 0) {\n\t\t\t\tunsubs.push(system.facts.$store.subscribe(trackedFactKeys, onUpdate));\n\t\t\t} else if (trackedDeriveKeys.length === 0) {\n\t\t\t\tunsubs.push(system.facts.$store.subscribeAll(onUpdate));\n\t\t\t}\n\t\t\tif (trackedDeriveKeys.length > 0) {\n\t\t\t\tunsubs.push(system.subscribe(trackedDeriveKeys, onUpdate));\n\t\t\t}\n\t\t};\n\n\t\tresubscribe();\n\n\t\treturn () => {\n\t\t\tfor (const unsub of unsubs) unsub();\n\t\t};\n\t});\n}\n\n// ============================================================================\n// useDispatch\n// ============================================================================\n\nexport function useDispatch<S extends ModuleSchema>(\n\tsystem: SingleModuleSystem<S>,\n): (event: InferEvents<S>) => void {\n\tassertSystem(\"useDispatch\", system);\n\treturn (event: InferEvents<S>) => {\n\t\tsystem.dispatch(event);\n\t};\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\tsystem: SingleModuleSystem<S>,\n): SingleModuleSystem<S>[\"events\"] {\n\tassertSystem(\"useEvents\", system);\n\treturn 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<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(\n\tsystem: SingleModuleSystem<S>,\n\tkey: K,\n\tcallback: (newValue: InferDerivations<S>[K], previousValue: InferDerivations<S>[K] | undefined) => void,\n): void;\n/** Watch a fact key with auto-detection. */\nexport function useWatch<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(\n\tsystem: SingleModuleSystem<S>,\n\tkey: K,\n\tcallback: (newValue: InferFacts<S>[K] | undefined, previousValue: InferFacts<S>[K] | undefined) => void,\n): void;\n/** Implementation */\nexport function useWatch(\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tsystem: SingleModuleSystem<any>,\n\tkey: string,\n\tcallback: (newValue: unknown, prevValue: unknown) => void,\n): void {\n\tassertSystem(\"useWatch\", system);\n\n\tconst unsubscribe = system.watch(key, callback);\n\tonDestroy(unsubscribe);\n}\n\n// ============================================================================\n// useInspect — consolidated inspection hook\n// ============================================================================\n\n/** Options for useInspect */\nexport interface UseInspectOptions {\n\tthrottleMs?: number;\n}\n\n/**\n * Consolidated system inspection hook.\n * Returns Readable<InspectState> with optional throttling.\n */\nexport function useInspect(\n\t// biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n\tsystem: SingleModuleSystem<any>,\n\toptions?: UseInspectOptions,\n): Readable<InspectState> {\n\tassertSystem(\"useInspect\", system);\n\tif (options?.throttleMs && options.throttleMs > 0) {\n\t\treturn readable<InspectState>(computeInspectState(system), (set) => {\n\t\t\tconst { throttled, cleanup } = createThrottle(() => {\n\t\t\t\tset(computeInspectState(system));\n\t\t\t}, options.throttleMs!);\n\n\t\t\tconst unsubFacts = system.facts.$store.subscribeAll(throttled);\n\t\t\tconst unsubSettled = system.onSettledChange(throttled);\n\n\t\t\treturn () => {\n\t\t\t\tcleanup();\n\t\t\t\tunsubFacts();\n\t\t\t\tunsubSettled();\n\t\t\t};\n\t\t});\n\t}\n\n\treturn readable<InspectState>(computeInspectState(system), (set) => {\n\t\tconst update = () => set(computeInspectState(system));\n\t\tconst unsubFacts = system.facts.$store.subscribeAll(update);\n\t\tconst unsubSettled = system.onSettledChange(update);\n\n\t\treturn () => {\n\t\t\tunsubFacts();\n\t\t\tunsubSettled();\n\t\t};\n\t});\n}\n\n// ============================================================================\n// useRequirementStatus — single or multi\n// ============================================================================\n\n/** Single type overload */\nexport function useRequirementStatus(statusPlugin: StatusPlugin, type: string): Readable<RequirementTypeStatus>;\n/** Multi-type overload */\nexport function useRequirementStatus(statusPlugin: StatusPlugin, types: string[]): Readable<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useRequirementStatus(\n\tstatusPlugin: StatusPlugin,\n\ttypeOrTypes: string | string[],\n): Readable<RequirementTypeStatus> | Readable<Record<string, RequirementTypeStatus>> {\n\tif (Array.isArray(typeOrTypes)) {\n\t\tconst getValues = (): Record<string, RequirementTypeStatus> => {\n\t\t\tconst result: Record<string, RequirementTypeStatus> = {};\n\t\t\tfor (const type of typeOrTypes) {\n\t\t\t\tresult[type] = statusPlugin.getStatus(type);\n\t\t\t}\n\t\t\treturn result;\n\t\t};\n\n\t\treturn readable(getValues(), (set) => {\n\t\t\tconst unsubscribe = statusPlugin.subscribe(() => {\n\t\t\t\tset(getValues());\n\t\t\t});\n\t\t\treturn unsubscribe;\n\t\t});\n\t}\n\n\treturn readable<RequirementTypeStatus>(statusPlugin.getStatus(typeOrTypes), (set) => {\n\t\tconst unsubscribe = statusPlugin.subscribe(() => {\n\t\t\tset(statusPlugin.getStatus(typeOrTypes));\n\t\t});\n\t\treturn unsubscribe;\n\t});\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\t// biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n\tsystem: SingleModuleSystem<any>,\n\trequirementId: string,\n): Readable<string | null> {\n\tassertSystem(\"useExplain\", system);\n\treturn readable<string | null>(system.explain(requirementId), (set) => {\n\t\tconst update = () => set(system.explain(requirementId));\n\t\tconst unsubFacts = system.facts.$store.subscribeAll(update);\n\t\tconst unsubSettled = system.onSettledChange(update);\n\n\t\treturn () => {\n\t\t\tunsubFacts();\n\t\t\tunsubSettled();\n\t\t};\n\t});\n}\n\n// ============================================================================\n// useConstraintStatus — reactive constraint inspection\n// ============================================================================\n\n/** Get all constraints */\nexport function useConstraintStatus(\n\tsystem: SingleModuleSystem<any>,\n): Readable<ConstraintInfo[]>;\n/** Get a single constraint by ID */\nexport function useConstraintStatus(\n\tsystem: SingleModuleSystem<any>,\n\tconstraintId: string,\n): Readable<ConstraintInfo | null>;\n/** Implementation */\nexport function useConstraintStatus(\n\t// biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n\tsystem: SingleModuleSystem<any>,\n\tconstraintId?: string,\n): Readable<ConstraintInfo[] | ConstraintInfo | null> {\n\tassertSystem(\"useConstraintStatus\", system);\n\treturn readable<ConstraintInfo[] | ConstraintInfo | null>(\n\t\t_getConstraintValue(system, constraintId),\n\t\t(set) => {\n\t\t\tconst update = () => set(_getConstraintValue(system, constraintId));\n\t\t\tconst unsubFacts = system.facts.$store.subscribeAll(update);\n\t\t\tconst unsubSettled = system.onSettledChange(update);\n\n\t\t\treturn () => {\n\t\t\t\tunsubFacts();\n\t\t\t\tunsubSettled();\n\t\t\t};\n\t\t},\n\t);\n}\n\nfunction _getConstraintValue(\n\t// biome-ignore lint/suspicious/noExplicitAny: Internal\n\tsystem: SingleModuleSystem<any>,\n\tconstraintId?: string,\n): ConstraintInfo[] | ConstraintInfo | null {\n\tconst inspection = system.inspect();\n\tif (!constraintId) return inspection.constraints;\n\treturn inspection.constraints.find((c: ConstraintInfo) => c.id === constraintId) ?? null;\n}\n\n// ============================================================================\n// useOptimisticUpdate — batch with rollback on failure\n// ============================================================================\n\nexport interface OptimisticUpdateResult {\n\tmutate: (updateFn: () => void) => void;\n\tisPending: Readable<boolean>;\n\terror: Readable<Error | null>;\n\trollback: () => 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\t// biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n\tsystem: SingleModuleSystem<any>,\n\tstatusPlugin?: StatusPlugin,\n\trequirementType?: string,\n): OptimisticUpdateResult {\n\tassertSystem(\"useOptimisticUpdate\", system);\n\tlet isPendingValue = false;\n\tlet errorValue: Error | null = null;\n\tlet snapshot: SystemSnapshot | null = null;\n\tlet statusUnsub: (() => void) | null = null;\n\n\t// We track subscribers manually since we need imperative push\n\tconst pendingSubscribers = new Set<(v: boolean) => void>();\n\tconst errorSubscribers = new Set<(v: Error | null) => void>();\n\n\tconst isPending: Readable<boolean> = {\n\t\tsubscribe(fn) {\n\t\t\tfn(isPendingValue);\n\t\t\tpendingSubscribers.add(fn);\n\t\t\treturn () => pendingSubscribers.delete(fn);\n\t\t},\n\t};\n\n\tconst error: Readable<Error | null> = {\n\t\tsubscribe(fn) {\n\t\t\tfn(errorValue);\n\t\t\terrorSubscribers.add(fn);\n\t\t\treturn () => errorSubscribers.delete(fn);\n\t\t},\n\t};\n\n\tconst setPending = (v: boolean) => {\n\t\tisPendingValue = v;\n\t\tfor (const fn of pendingSubscribers) fn(v);\n\t};\n\n\tconst setError = (v: Error | null) => {\n\t\terrorValue = v;\n\t\tfor (const fn of errorSubscribers) fn(v);\n\t};\n\n\tconst rollback = () => {\n\t\tif (snapshot) {\n\t\t\tsystem.restore(snapshot);\n\t\t\tsnapshot = null;\n\t\t}\n\t\tsetPending(false);\n\t\tsetError(null);\n\t\tstatusUnsub?.();\n\t\tstatusUnsub = null;\n\t};\n\n\tconst mutate = (updateFn: () => void) => {\n\t\tsnapshot = system.getSnapshot();\n\t\tsetPending(true);\n\t\tsetError(null);\n\t\tsystem.batch(updateFn);\n\n\t\tif (statusPlugin && requirementType) {\n\t\t\tstatusUnsub?.();\n\t\t\tstatusUnsub = statusPlugin.subscribe(() => {\n\t\t\t\tconst status = statusPlugin.getStatus(requirementType);\n\t\t\t\tif (!status.isLoading && !status.hasError) {\n\t\t\t\t\tsnapshot = null;\n\t\t\t\t\tsetPending(false);\n\t\t\t\t\tstatusUnsub?.();\n\t\t\t\t\tstatusUnsub = null;\n\t\t\t\t} else if (status.hasError) {\n\t\t\t\t\tsetError(status.lastError);\n\t\t\t\t\trollback();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t};\n\n\tonDestroy(() => {\n\t\tstatusUnsub?.();\n\t});\n\n\treturn { mutate, isPending, error, rollback };\n}\n\n// ============================================================================\n// useTimeTravel — reactive time-travel store\n// ============================================================================\n\n/**\n * Reactive time-travel Svelte store. Returns a Readable that updates\n * when snapshots are taken or navigation occurs.\n *\n * @example\n * ```svelte\n * const tt = useTimeTravel(system);\n * <button disabled={!$tt?.canUndo} on:click={() => $tt?.undo()}>Undo</button>\n * ```\n */\nexport function useTimeTravel(\n\t// biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n\tsystem: SingleModuleSystem<any>,\n): Readable<TimeTravelState | null> {\n\tassertSystem(\"useTimeTravel\", system);\n\treturn readable<TimeTravelState | null>(buildTimeTravelState(system), (set) => {\n\t\treturn system.onTimeTravelChange(() => set(buildTimeTravelState(system)));\n\t});\n}\n\n// ============================================================================\n// Scoped System\n// ============================================================================\n\n/** Configuration for useDirective */\ninterface UseDirectiveConfig {\n\t// biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n\tplugins?: Plugin<any>[];\n\tdebug?: DebugConfig;\n\terrorBoundary?: ErrorBoundaryConfig;\n\ttickMs?: number;\n\tzeroConfig?: boolean;\n\t// biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n\tinitialFacts?: Record<string, any>;\n\tstatus?: boolean;\n\t/** Fact keys to subscribe to (omit for all) */\n\tfacts?: string[];\n\t/** Derivation keys to subscribe to (omit for all) */\n\tderived?: 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 Svelte readable stores.\n *\n * @example\n * ```svelte\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\tmoduleDef: ModuleDef<M>,\n\tconfig?: UseDirectiveConfig,\n) {\n\tconst allPlugins = [...(config?.plugins ?? [])];\n\tlet statusPlugin: StatusPlugin | undefined;\n\n\tif (config?.status) {\n\t\tconst sp = createRequirementStatusPlugin();\n\t\tstatusPlugin = sp;\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n\t\tallPlugins.push(sp.plugin as Plugin<any>);\n\t}\n\n\t// biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n\tconst system = createSystem({\n\t\tmodule: moduleDef,\n\t\tplugins: allPlugins.length > 0 ? allPlugins : undefined,\n\t\tdebug: config?.debug,\n\t\terrorBoundary: config?.errorBoundary,\n\t\ttickMs: config?.tickMs,\n\t\tzeroConfig: config?.zeroConfig,\n\t\tinitialFacts: config?.initialFacts,\n\t} as any) as unknown as SingleModuleSystem<M>;\n\n\tsystem.start();\n\n\tonDestroy(() => {\n\t\tsystem.destroy();\n\t});\n\n\tconst factKeys = config?.facts;\n\tconst derivedKeys = config?.derived;\n\tconst subscribeAll = !factKeys && !derivedKeys;\n\n\t// Subscribe to facts\n\tconst factsStore: Readable<InferFacts<M>> = subscribeAll\n\t\t? readable(system.facts.$store.toObject() as InferFacts<M>, (set) => {\n\t\t\treturn system.facts.$store.subscribeAll(() => {\n\t\t\t\tset(system.facts.$store.toObject() as InferFacts<M>);\n\t\t\t});\n\t\t})\n\t\t: readable(pickFacts(system, factKeys ?? []) as InferFacts<M>, (set) => {\n\t\t\tif (!factKeys || factKeys.length === 0) return () => {};\n\t\t\treturn system.facts.$store.subscribe(factKeys, () => {\n\t\t\t\tset(pickFacts(system, factKeys) as InferFacts<M>);\n\t\t\t});\n\t\t});\n\n\t// Subscribe to derivations\n\tconst allDerivationKeys = subscribeAll ? Object.keys(system.derive ?? {}) : (derivedKeys ?? []);\n\tconst getDerived = (): InferDerivations<M> => {\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const key of allDerivationKeys) {\n\t\t\tresult[key] = system.read(key);\n\t\t}\n\t\treturn result as InferDerivations<M>;\n\t};\n\tconst derivedStore: Readable<InferDerivations<M>> = allDerivationKeys.length > 0\n\t\t? readable(getDerived(), (set) => {\n\t\t\treturn system.subscribe(allDerivationKeys, () => {\n\t\t\t\tset(getDerived());\n\t\t\t});\n\t\t})\n\t\t: readable(getDerived(), () => () => {});\n\n\tconst events = system.events;\n\tconst dispatch = (event: InferEvents<M>) => system.dispatch(event);\n\n\treturn {\n\t\tsystem,\n\t\tfacts: factsStore,\n\t\tderived: derivedStore,\n\t\tevents,\n\t\tdispatch,\n\t\tstatusPlugin,\n\t};\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n\tuseFact: <K extends keyof InferFacts<M> & string>(\n\t\tsystem: SingleModuleSystem<M>,\n\t\tfactKey: K,\n\t) => Readable<InferFacts<M>[K] | undefined>;\n\tuseDerived: <K extends keyof InferDerivations<M> & string>(\n\t\tsystem: SingleModuleSystem<M>,\n\t\tderivationId: K,\n\t) => Readable<InferDerivations<M>[K]>;\n\tuseDispatch: (system: SingleModuleSystem<M>) => (event: InferEvents<M>) => void;\n\tuseEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n\tuseWatch: <K extends string>(\n\t\tsystem: SingleModuleSystem<M>,\n\t\tkey: K,\n\t\tcallback: (newValue: unknown, previousValue: unknown) => void,\n\t) => void;\n} {\n\treturn {\n\t\tuseFact: <K extends keyof InferFacts<M> & string>(system: SingleModuleSystem<M>, factKey: K) =>\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Cast for overload compatibility\n\t\t\tuseFact(system as SingleModuleSystem<any>, factKey) as Readable<InferFacts<M>[K] | undefined>,\n\t\tuseDerived: <K extends keyof InferDerivations<M> & string>(system: SingleModuleSystem<M>, derivationId: K) =>\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Cast for overload compatibility\n\t\t\tuseDerived(system as SingleModuleSystem<any>, derivationId) as Readable<InferDerivations<M>[K]>,\n\t\tuseDispatch: (system: SingleModuleSystem<M>) => {\n\t\t\treturn (event: InferEvents<M>) => {\n\t\t\t\tsystem.dispatch(event);\n\t\t\t};\n\t\t},\n\t\tuseEvents: (system: SingleModuleSystem<M>) => useEvents<M>(system),\n\t\tuseWatch: <K extends string>(\n\t\t\tsystem: SingleModuleSystem<M>,\n\t\t\tkey: K,\n\t\t\tcallback: (newValue: unknown, previousValue: unknown) => void,\n\t\t) =>\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Cast for overload compatibility\n\t\t\tuseWatch(system as SingleModuleSystem<any>, key, callback),\n\t};\n}\n\n// ============================================================================\n// useNamespacedSelector — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * Svelte readable store 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 * ```svelte\n * const token$ = useNamespacedSelector(system, [\"auth.token\"], (s) => s.facts.auth.token);\n * ```\n */\nexport function useNamespacedSelector<Modules extends ModulesMap, R>(\n\tsystem: NamespacedSystem<Modules>,\n\tkeys: string[],\n\tselector: (system: NamespacedSystem<Modules>) => R,\n): Readable<R> {\n\treturn readable<R>(selector(system), (set) => {\n\t\tconst unsubscribe = system.subscribe(keys, () => {\n\t\t\tset(selector(system));\n\t\t});\n\n\t\treturn unsubscribe;\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["createDerivedStore","system","derivationId","readable","set","createDerivedsStore","derivationIds","getValues","result","id","createFactStore","factKey","createInspectStore","update","unsubFacts","unsubSettled","useFact","keyOrKeys","assertSystem","_useFactMulti","factKeys","key","useDerived","idOrIds","useSelector","selector","equalityFn","defaultEquality","deriveKeySet","runWithTracking","runTrackedSelector","initial","currentSelected","trackedFactKeys","trackedDeriveKeys","unsubs","resubscribe","unsub","onUpdate","depsChanged","useDispatch","event","useEvents","useWatch","callback","unsubscribe","onDestroy","useInspect","options","computeInspectState","throttled","cleanup","createThrottle","useRequirementStatus","statusPlugin","typeOrTypes","type","useExplain","requirementId","useConstraintStatus","constraintId","_getConstraintValue","inspection","c","useOptimisticUpdate","requirementType","isPendingValue","errorValue","snapshot","statusUnsub","pendingSubscribers","errorSubscribers","isPending","fn","error","setPending","v","setError","rollback","mutate","updateFn","status","useTimeTravel","buildTimeTravelState","useDirective","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","createSystem","derivedKeys","subscribeAll","factsStore","pickFacts","allDerivationKeys","getDerived","derivedStore","events","createTypedHooks","useNamespacedSelector","keys"],"mappings":"sKA+DO,SAASA,CAAAA,CAEdC,CAAAA,CACAC,EACa,CACb,OAAI,OAAA,CAAQ,GAAA,CAAI,WAAa,YAAA,EACND,CAAAA,CAAO,IAAA,CAAKC,CAAY,IACxB,MAAA,EACnB,OAAA,CAAQ,IAAA,CACN,CAAA,gCAAA,EAAmCA,CAAY,CAAA,mCAAA,EAC9BA,CAAY,gDAC/B,CAAA,CAIGC,cAAAA,CAAYF,EAAO,IAAA,CAAKC,CAAY,CAAA,CAASE,CAAAA,EAC9BH,EAAO,SAAA,CAAU,CAACC,CAAY,CAAA,CAAG,IAAM,CACzDE,CAAAA,CAAIH,CAAAA,CAAO,IAAA,CAAKC,CAAY,CAAM,EACpC,CAAC,CAEF,CACH,CAKO,SAASG,CAAAA,CAEdJ,CAAAA,CACAK,C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CAC/CjG,EAAIqB,CAAAA,CAASxB,CAAM,CAAC,EACtB,CAAC,CAGF,CACH","file":"index.cjs","sourcesContent":["/**\n * Svelte Adapter - Consolidated Svelte stores for Directive\n *\n * 15 active exports: useFact, useDerived, useDispatch, useSelector,\n * useWatch, useInspect, useRequirementStatus, useEvents, useExplain,\n * useConstraintStatus, useOptimisticUpdate, useDirective, useTimeTravel,\n * createTypedHooks, shallowEqual\n *\n * Store factories: createDerivedStore, createDerivedsStore, createFactStore, createInspectStore\n */\n\nimport type {\n DebugConfig,\n ErrorBoundaryConfig,\n InferDerivations,\n InferEvents,\n InferFacts,\n InferSelectorState,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemInspection,\n SystemSnapshot,\n TimeTravelState,\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 buildTimeTravelState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n pickFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport { onDestroy } from \"svelte\";\nimport { type Readable, readable } from \"svelte/store\";\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// Store Factories\n// ============================================================================\n\n/**\n * Create a Svelte store for a derived value.\n */\nexport function createDerivedStore<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n): Readable<T> {\n if (process.env.NODE_ENV !== \"production\") {\n const initialValue = system.read(derivationId);\n if (initialValue === undefined) {\n console.warn(\n `[Directive] createDerivedStore(\"${derivationId}\") returned undefined. ` +\n `Check that \"${derivationId}\" is defined in your module's derive property.`,\n );\n }\n }\n\n return readable<T>(system.read(derivationId) as T, (set) => {\n const unsubscribe = system.subscribe([derivationId], () => {\n set(system.read(derivationId) as T);\n });\n return unsubscribe;\n });\n}\n\n/**\n * Create a Svelte store for multiple derived values.\n */\nexport function createDerivedsStore<T extends Record<string, unknown>>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationIds: string[],\n): Readable<T> {\n const getValues = (): T => {\n const result: Record<string, unknown> = {};\n for (const id of derivationIds) {\n result[id] = system.read(id);\n }\n return result as T;\n };\n\n return readable<T>(getValues(), (set) => {\n const unsubscribe = system.subscribe(derivationIds, () => {\n set(getValues());\n });\n return unsubscribe;\n });\n}\n\n/**\n * Create a Svelte store for a single fact value.\n */\nexport function createFactStore<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): Readable<T | undefined> {\n if (process.env.NODE_ENV !== \"production\") {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] createFactStore(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n\n return readable<T | undefined>(\n system.facts.$store.get(factKey) as T | undefined,\n (set) => {\n const unsubscribe = system.facts.$store.subscribe([factKey], () => {\n set(system.facts.$store.get(factKey) as T | undefined);\n });\n return unsubscribe;\n },\n );\n}\n\n/**\n * Create a Svelte store for system inspection data.\n * NOTE: This updates on every fact change. Use sparingly in production.\n */\nexport function createInspectStore(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n): Readable<SystemInspection> {\n return readable<SystemInspection>(system.inspect(), (set) => {\n const update = () => set(system.inspect());\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n return () => {\n unsubFacts();\n unsubSettled();\n };\n });\n}\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): Readable<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): Readable<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): Readable<unknown> {\n assertSystem(\"useFact\", system);\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof keyOrKeys === \"function\"\n ) {\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: useFact(system, [keys])\n if (Array.isArray(keyOrKeys)) {\n return _useFactMulti(system, keyOrKeys);\n }\n\n // Single key path: useFact(system, key)\n return createFactStore(system, keyOrKeys);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactMulti(\n system: SingleModuleSystem<any>,\n factKeys: string[],\n): Readable<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\n return readable(getValues(), (set) => {\n const unsubscribe = system.facts.$store.subscribe(factKeys, () => {\n set(getValues());\n });\n return unsubscribe;\n });\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): Readable<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): Readable<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): Readable<unknown> {\n assertSystem(\"useDerived\", system);\n if (process.env.NODE_ENV !== \"production\" && 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 createDerivedsStore(system, idOrIds);\n }\n\n // Single key path\n return createDerivedStore(system, idOrIds);\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): Readable<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): Readable<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\n return readable(initial.value, (set) => {\n let currentSelected = initial.value;\n let trackedFactKeys = initial.factKeys;\n let trackedDeriveKeys = initial.deriveKeys;\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 if (!equalityFn(currentSelected, result.value)) {\n currentSelected = result.value;\n set(result.value);\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 return () => {\n for (const unsub of unsubs) unsub();\n };\n });\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 onDestroy(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 Readable<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): Readable<InspectState> {\n assertSystem(\"useInspect\", system);\n if (options?.throttleMs && options.throttleMs > 0) {\n return readable<InspectState>(computeInspectState(system), (set) => {\n const { throttled, cleanup } = createThrottle(() => {\n set(computeInspectState(system));\n }, options.throttleMs!);\n\n const unsubFacts = system.facts.$store.subscribeAll(throttled);\n const unsubSettled = system.onSettledChange(throttled);\n\n return () => {\n cleanup();\n unsubFacts();\n unsubSettled();\n };\n });\n }\n\n return readable<InspectState>(computeInspectState(system), (set) => {\n const update = () => set(computeInspectState(system));\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n\n return () => {\n unsubFacts();\n unsubSettled();\n };\n });\n}\n\n// ============================================================================\n// useRequirementStatus — single or multi\n// ============================================================================\n\n/** Single type overload */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n type: string,\n): Readable<RequirementTypeStatus>;\n/** Multi-type overload */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n types: string[],\n): Readable<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n typeOrTypes: string | string[],\n):\n | Readable<RequirementTypeStatus>\n | Readable<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\n return readable(getValues(), (set) => {\n const unsubscribe = statusPlugin.subscribe(() => {\n set(getValues());\n });\n return unsubscribe;\n });\n }\n\n return readable<RequirementTypeStatus>(\n statusPlugin.getStatus(typeOrTypes),\n (set) => {\n const unsubscribe = statusPlugin.subscribe(() => {\n set(statusPlugin.getStatus(typeOrTypes));\n });\n return unsubscribe;\n },\n );\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): Readable<string | null> {\n assertSystem(\"useExplain\", system);\n return readable<string | null>(system.explain(requirementId), (set) => {\n const update = () => set(system.explain(requirementId));\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n\n return () => {\n unsubFacts();\n unsubSettled();\n };\n });\n}\n\n// ============================================================================\n// useConstraintStatus — reactive constraint inspection\n// ============================================================================\n\n/** Get all constraints */\nexport function useConstraintStatus(\n system: SingleModuleSystem<any>,\n): Readable<ConstraintInfo[]>;\n/** Get a single constraint by ID */\nexport function useConstraintStatus(\n system: SingleModuleSystem<any>,\n constraintId: string,\n): Readable<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): Readable<ConstraintInfo[] | ConstraintInfo | null> {\n assertSystem(\"useConstraintStatus\", system);\n return readable<ConstraintInfo[] | ConstraintInfo | null>(\n _getConstraintValue(system, constraintId),\n (set) => {\n const update = () => set(_getConstraintValue(system, constraintId));\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n\n return () => {\n unsubFacts();\n unsubSettled();\n };\n },\n );\n}\n\nfunction _getConstraintValue(\n // biome-ignore lint/suspicious/noExplicitAny: Internal\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): ConstraintInfo[] | ConstraintInfo | null {\n const inspection = system.inspect();\n if (!constraintId) return inspection.constraints;\n return (\n inspection.constraints.find((c: ConstraintInfo) => c.id === constraintId) ??\n null\n );\n}\n\n// ============================================================================\n// useOptimisticUpdate — batch with rollback on failure\n// ============================================================================\n\nexport interface OptimisticUpdateResult {\n mutate: (updateFn: () => void) => void;\n isPending: Readable<boolean>;\n error: Readable<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 let isPendingValue = false;\n let errorValue: Error | null = null;\n let snapshot: SystemSnapshot | null = null;\n let statusUnsub: (() => void) | null = null;\n\n // We track subscribers manually since we need imperative push\n const pendingSubscribers = new Set<(v: boolean) => void>();\n const errorSubscribers = new Set<(v: Error | null) => void>();\n\n const isPending: Readable<boolean> = {\n subscribe(fn) {\n fn(isPendingValue);\n pendingSubscribers.add(fn);\n return () => pendingSubscribers.delete(fn);\n },\n };\n\n const error: Readable<Error | null> = {\n subscribe(fn) {\n fn(errorValue);\n errorSubscribers.add(fn);\n return () => errorSubscribers.delete(fn);\n },\n };\n\n const setPending = (v: boolean) => {\n isPendingValue = v;\n for (const fn of pendingSubscribers) fn(v);\n };\n\n const setError = (v: Error | null) => {\n errorValue = v;\n for (const fn of errorSubscribers) fn(v);\n };\n\n const rollback = () => {\n if (snapshot) {\n system.restore(snapshot);\n snapshot = null;\n }\n setPending(false);\n setError(null);\n statusUnsub?.();\n statusUnsub = null;\n };\n\n const mutate = (updateFn: () => void) => {\n snapshot = system.getSnapshot();\n setPending(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 setPending(false);\n statusUnsub?.();\n statusUnsub = null;\n } else if (status.hasError) {\n setError(status.lastError);\n rollback();\n }\n });\n }\n };\n\n onDestroy(() => {\n statusUnsub?.();\n });\n\n return { mutate, isPending, error, rollback };\n}\n\n// ============================================================================\n// useTimeTravel — reactive time-travel store\n// ============================================================================\n\n/**\n * Reactive time-travel Svelte store. Returns a Readable that updates\n * when snapshots are taken or navigation occurs.\n *\n * @example\n * ```svelte\n * const tt = useTimeTravel(system);\n * <button disabled={!$tt?.canUndo} on:click={() => $tt?.undo()}>Undo</button>\n * ```\n */\nexport function useTimeTravel(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n): Readable<TimeTravelState | null> {\n assertSystem(\"useTimeTravel\", system);\n return readable<TimeTravelState | null>(\n buildTimeTravelState(system),\n (set) => {\n return system.onTimeTravelChange(() => set(buildTimeTravelState(system)));\n },\n );\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 debug?: DebugConfig;\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 Svelte readable stores.\n *\n * @example\n * ```svelte\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 debug: config?.debug,\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 system.start();\n\n onDestroy(() => {\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 factsStore: Readable<InferFacts<M>> = subscribeAll\n ? readable(system.facts.$store.toObject() as InferFacts<M>, (set) => {\n return system.facts.$store.subscribeAll(() => {\n set(system.facts.$store.toObject() as InferFacts<M>);\n });\n })\n : readable(pickFacts(system, factKeys ?? []) as InferFacts<M>, (set) => {\n if (!factKeys || factKeys.length === 0) return () => {};\n return system.facts.$store.subscribe(factKeys, () => {\n set(pickFacts(system, factKeys) as InferFacts<M>);\n });\n });\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 derivedStore: Readable<InferDerivations<M>> =\n allDerivationKeys.length > 0\n ? readable(getDerived(), (set) => {\n return system.subscribe(allDerivationKeys, () => {\n set(getDerived());\n });\n })\n : readable(getDerived(), () => () => {});\n\n const events = system.events;\n const dispatch = (event: InferEvents<M>) => system.dispatch(event);\n\n return {\n system,\n facts: factsStore,\n derived: derivedStore,\n events,\n dispatch,\n statusPlugin,\n };\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 ) => Readable<InferFacts<M>[K] | undefined>;\n useDerived: <K extends keyof InferDerivations<M> & string>(\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => Readable<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: Cast for overload compatibility\n useFact(system as SingleModuleSystem<any>, factKey) as Readable<\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: Cast for overload compatibility\n useDerived(system as SingleModuleSystem<any>, derivationId) as Readable<\n InferDerivations<M>[K]\n >,\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: Cast 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 * Svelte readable store 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 * ```svelte\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): Readable<R> {\n return readable<R>(selector(system), (set) => {\n const unsubscribe = system.subscribe(keys, () => {\n set(selector(system));\n });\n\n return unsubscribe;\n });\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _directive_run_core from '@directive-run/core';
|
|
2
2
|
import { createRequirementStatusPlugin, SingleModuleSystem, SystemInspection, ModuleSchema, InferFacts, InferDerivations, InferEvents, ModuleDef, Plugin, DebugConfig, ErrorBoundaryConfig, RequirementTypeStatus, ModulesMap, NamespacedSystem, InferSelectorState, TimeTravelState } from '@directive-run/core';
|
|
3
3
|
export { RequirementTypeStatus } from '@directive-run/core';
|
|
4
|
-
import { Readable } from 'svelte/store';
|
|
5
4
|
import { ConstraintInfo, InspectState } from '@directive-run/core/adapter-utils';
|
|
6
5
|
export { ConstraintInfo, InspectState, shallowEqual } from '@directive-run/core/adapter-utils';
|
|
6
|
+
import { Readable } from 'svelte/store';
|
|
7
7
|
|
|
8
8
|
/** Type for the requirement status plugin return value */
|
|
9
9
|
type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _directive_run_core from '@directive-run/core';
|
|
2
2
|
import { createRequirementStatusPlugin, SingleModuleSystem, SystemInspection, ModuleSchema, InferFacts, InferDerivations, InferEvents, ModuleDef, Plugin, DebugConfig, ErrorBoundaryConfig, RequirementTypeStatus, ModulesMap, NamespacedSystem, InferSelectorState, TimeTravelState } from '@directive-run/core';
|
|
3
3
|
export { RequirementTypeStatus } from '@directive-run/core';
|
|
4
|
-
import { Readable } from 'svelte/store';
|
|
5
4
|
import { ConstraintInfo, InspectState } from '@directive-run/core/adapter-utils';
|
|
6
5
|
export { ConstraintInfo, InspectState, shallowEqual } from '@directive-run/core/adapter-utils';
|
|
6
|
+
import { Readable } from 'svelte/store';
|
|
7
7
|
|
|
8
8
|
/** Type for the requirement status plugin return value */
|
|
9
9
|
type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {createRequirementStatusPlugin,createSystem}from'@directive-run/core';import {defaultEquality,assertSystem,computeInspectState,createThrottle,buildTimeTravelState,pickFacts,runTrackedSelector,depsChanged}from'@directive-run/core/adapter-utils';export{shallowEqual}from'@directive-run/core/adapter-utils';import {onDestroy}from'svelte';import {readable}from'svelte/store';function C(e,t){return process.env.NODE_ENV!=="production"&&e.read(t)===void 0&&console.warn(`[Directive] createDerivedStore("${t}") returned undefined. Check that "${t}" is defined in your module's derive property.`),readable(e.read(t),n=>e.subscribe([t],()=>{n(e.read(t));}))}function E(e,t){let n=()=>{let s={};for(let r of t)s[r]=e.read(r);return s};return readable(n(),s=>e.subscribe(t,()=>{s(n());}))}function w(e,t){return process.env.NODE_ENV!=="production"&&(e.facts.$store.has(t)||console.warn(`[Directive] createFactStore("${t}") \u2014 fact not found in store. Check that "${t}" is defined in your module's schema.`)),readable(e.facts.$store.get(t),n=>e.facts.$store.subscribe([t],()=>{n(e.facts.$store.get(t));}))}function O(e){return readable(e.inspect(),t=>{let n=()=>t(e.inspect()),s=e.facts.$store.subscribeAll(n),r=e.onSettledChange(n);return ()=>{s(),r();}})}function V(e,t){return assertSystem("useFact",e),process.env.NODE_ENV!=="production"&&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)?$(e,t):w(e,t)}function $(e,t){let n=()=>{let s={};for(let r of t)s[r]=e.facts.$store.get(r);return s};return readable(n(),s=>e.facts.$store.subscribe(t,()=>{s(n());}))}function q(e,t){return assertSystem("useDerived",e),process.env.NODE_ENV!=="production"&&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(e,t):C(e,t)}function j(e,t,n=defaultEquality){assertSystem("useSelector",e);let s=new Set(Object.keys(e.derive??{})),r=()=>runTrackedSelector(e,s,t),o=r();return readable(o.value,l=>{let p=o.value,g=o.factKeys,S=o.deriveKeys,d=[],y=()=>{for(let c of d)c();d.length=0;let f=()=>{let c=r();n(p,c.value)||(p=c.value,l(c.value)),depsChanged(g,c.factKeys,S,c.deriveKeys)&&(g=c.factKeys,S=c.deriveKeys,y());};g.length>0?d.push(e.facts.$store.subscribe(g,f)):S.length===0&&d.push(e.facts.$store.subscribeAll(f)),S.length>0&&d.push(e.subscribe(S,f));};return y(),()=>{for(let f of d)f();}})}function z(e){return assertSystem("useDispatch",e),t=>{e.dispatch(t);}}function A(e){return assertSystem("useEvents",e),e.events}function P(e,t,n){assertSystem("useWatch",e);let s=e.watch(t,n);onDestroy(s);}function H(e,t){return assertSystem("useInspect",e),t?.throttleMs&&t.throttleMs>0?readable(computeInspectState(e),n=>{let{throttled:s,cleanup:r}=createThrottle(()=>{n(computeInspectState(e));},t.throttleMs),o=e.facts.$store.subscribeAll(s),l=e.onSettledChange(s);return ()=>{r(),o(),l();}}):readable(computeInspectState(e),n=>{let s=()=>n(computeInspectState(e)),r=e.facts.$store.subscribeAll(s),o=e.onSettledChange(s);return ()=>{r(),o();}})}function L(e,t){if(Array.isArray(t)){let n=()=>{let s={};for(let r of t)s[r]=e.getStatus(r);return s};return readable(n(),s=>e.subscribe(()=>{s(n());}))}return readable(e.getStatus(t),n=>e.subscribe(()=>{n(e.getStatus(t));}))}function G(e,t){return assertSystem("useExplain",e),readable(e.explain(t),n=>{let s=()=>n(e.explain(t)),r=e.facts.$store.subscribeAll(s),o=e.onSettledChange(s);return ()=>{r(),o();}})}function J(e,t){return assertSystem("useConstraintStatus",e),readable(x(e,t),n=>{let s=()=>n(x(e,t)),r=e.facts.$store.subscribeAll(s),o=e.onSettledChange(s);return ()=>{r(),o();}})}function x(e,t){let n=e.inspect();return t?n.constraints.find(s=>s.id===t)??null:n.constraints}function Q(e,t,n){assertSystem("useOptimisticUpdate",e);let s=false,r=null,o=null,l=null,p=new Set,g=new Set,S={subscribe(u){return u(s),p.add(u),()=>p.delete(u)}},d={subscribe(u){return u(r),g.add(u),()=>g.delete(u)}},y=u=>{s=u;for(let M of p)M(u);},f=u=>{r=u;for(let M of g)M(u);},c=()=>{o&&(e.restore(o),o=null),y(false),f(null),l?.(),l=null;},a=u=>{o=e.getSnapshot(),y(true),f(null),e.batch(u),t&&n&&(l?.(),l=t.subscribe(()=>{let M=t.getStatus(n);!M.isLoading&&!M.hasError?(o=null,y(false),l?.(),l=null):M.hasError&&(f(M.lastError),c());}));};return onDestroy(()=>{l?.();}),{mutate:a,isPending:S,error:d,rollback:c}}function X(e){return assertSystem("useTimeTravel",e),readable(buildTimeTravelState(e),t=>e.onTimeTravelChange(()=>t(buildTimeTravelState(e))))}function Y(e,t){let n=[...t?.plugins??[]],s;if(t?.status){let a=createRequirementStatusPlugin();s=a,n.push(a.plugin);}let r=createSystem({module:e,plugins:n.length>0?n:void 0,debug:t?.debug,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:t?.initialFacts});r.start(),onDestroy(()=>{r.destroy();});let o=t?.facts,l=t?.derived,p=!o&&!l,g=p?readable(r.facts.$store.toObject(),a=>r.facts.$store.subscribeAll(()=>{a(r.facts.$store.toObject());})):readable(pickFacts(r,o??[]),a=>!o||o.length===0?()=>{}:r.facts.$store.subscribe(o,()=>{a(pickFacts(r,o));})),S=p?Object.keys(r.derive??{}):l??[],d=()=>{let a={};for(let u of S)a[u]=r.read(u);return a},y=S.length>0?readable(d(),a=>r.subscribe(S,()=>{a(d());})):readable(d(),()=>()=>{}),f=r.events;return {system:r,facts:g,derived:y,events:f,dispatch:a=>r.dispatch(a),statusPlugin:s}}function Z(){return {useFact:(e,t)=>V(e,t),useDerived:(e,t)=>q(e,t),useDispatch:e=>t=>{e.dispatch(t);},useEvents:e=>A(e),useWatch:(e,t,n)=>P(e,t,n)}}function ee(e,t,n){return readable(n(e),s=>e.subscribe(t,()=>{s(n(e));}))}export{C as createDerivedStore,E as createDerivedsStore,w as createFactStore,O as createInspectStore,Z as createTypedHooks,J as useConstraintStatus,q as useDerived,Y as useDirective,z as useDispatch,A as useEvents,G as useExplain,V as useFact,H as useInspect,ee as useNamespacedSelector,Q as useOptimisticUpdate,L as useRequirementStatus,j as useSelector,X as useTimeTravel,P 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/index.ts"],"names":["createDerivedStore","system","derivationId","readable","set","createDerivedsStore","derivationIds","getValues","result","id","createFactStore","factKey","createInspectStore","update","unsubFacts","unsubSettled","useFact","keyOrKeys","assertSystem","_useFactMulti","factKeys","key","useDerived","idOrIds","useSelector","selector","equalityFn","defaultEquality","deriveKeySet","runWithTracking","runTrackedSelector","initial","currentSelected","trackedFactKeys","trackedDeriveKeys","unsubs","resubscribe","unsub","onUpdate","depsChanged","useDispatch","event","useEvents","useWatch","callback","unsubscribe","onDestroy","useInspect","options","computeInspectState","throttled","cleanup","createThrottle","useRequirementStatus","statusPlugin","typeOrTypes","type","useExplain","requirementId","useConstraintStatus","constraintId","_getConstraintValue","inspection","c","useOptimisticUpdate","requirementType","isPendingValue","errorValue","snapshot","statusUnsub","pendingSubscribers","errorSubscribers","isPending","fn","error","setPending","v","setError","rollback","mutate","updateFn","status","useTimeTravel","buildTimeTravelState","useDirective","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","createSystem","derivedKeys","subscribeAll","factsStore","pickFacts","allDerivationKeys","getDerived","derivedStore","events","createTypedHooks","useNamespacedSelector","keys"],"mappings":"0XA+DO,SAASA,CAAAA,CAEfC,CAAAA,CACAC,EACc,CACd,OAAI,OAAA,CAAQ,GAAA,CAAI,WAAa,YAAA,EACPD,CAAAA,CAAO,IAAA,CAAKC,CAAY,IACxB,MAAA,EACpB,OAAA,CAAQ,IAAA,CACP,CAAA,gCAAA,EAAmCA,CAAY,CAAA,mCAAA,EAChCA,CAAY,gDAC5B,CAAA,CAIKC,QAAAA,CAAYF,EAAO,IAAA,CAAKC,CAAY,CAAA,CAASE,CAAAA,EAC/BH,EAAO,SAAA,CAAU,CAACC,CAAY,CAAA,CAAG,IAAM,CAC1DE,CAAAA,CAAIH,CAAAA,CAAO,IAAA,CAAKC,CAAY,CAAM,EACnC,CAAC,CAED,CACF,CAKO,SAASG,CAAAA,CAEfJ,CAAAA,CACAK,CAAAA,CACc,CACd,IAAMC,CAAAA,CAAY,IAAS,CAC1B,IAAMC,CAAAA,CAAkC,EAAC,CACzC,IAAA,IAAWC,KAAMH,CAAAA,CAChBE,CAAAA,CAAOC,CAAE,CAAA,CAAIR,CAAAA,CAAO,KAAKQ,CAAE,CAAA,CAE5B,OAAOD,CACR,EAEA,OAAOL,QAAAA,CAAYI,CAAAA,EAAU,CAAIH,GACZH,CAAAA,CAAO,SAAA,CAAUK,CAAAA,CAAe,IAAM,CACzDF,CAAAA,CAAIG,CAAAA,EAAW,EAChB,CAAC,CAED,CACF,CAKO,SAASG,CAAAA,CAEfT,EACAU,CAAAA,CAC0B,CAC1B,OAAI,OAAA,CAAQ,IAAI,QAAA,GAAa,YAAA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AA,CACA,QAAA,CAPiBzD,GAA0BxC,CAAAA,CAAO,QAAA,CAASwC,CAAK,CAAA,CAQhE,aAAAa,CACD,CACD,CAMO,SAAS6C,GAgBd,CACD,OAAO,CACN,OAAA,CAAS,CAAyClG,EAA+BU,CAAAA,GAEhFK,CAAAA,CAAQf,CAAAA,CAAmCU,CAAO,EACnD,UAAA,CAAY,CAA+CV,CAAAA,CAA+BC,CAAAA,GAEzFoB,EAAWrB,CAAAA,CAAmCC,CAAY,CAAA,CAC3D,WAAA,CAAcD,GACLwC,CAAAA,EAA0B,CACjCxC,EAAO,QAAA,CAASwC,CAAK,EACtB,CAAA,CAED,SAAA,CAAYxC,CAAAA,EAAkCyC,CAAAA,CAAazC,CAAM,CAAA,CACjE,QAAA,CAAU,CACTA,CAAAA,CACAoB,EACAuB,CAAAA,GAGAD,CAAAA,CAAS1C,CAAAA,CAAmCoB,CAAAA,CAAKuB,CAAQ,CAC3D,CACD,CAmBO,SAASwD,EAAAA,CACfnG,EACAoG,CAAAA,CACA5E,CAAAA,CACc,CACd,OAAOtB,SAAYsB,CAAAA,CAASxB,CAAM,CAAA,CAAIG,CAAAA,EACjBH,EAAO,SAAA,CAAUoG,CAAAA,CAAM,IAAM,CAChDjG,EAAIqB,CAAAA,CAASxB,CAAM,CAAC,EACrB,CAAC,CAGD,CACF","file":"index.js","sourcesContent":["/**\n * Svelte Adapter - Consolidated Svelte stores for Directive\n *\n * 15 active exports: useFact, useDerived, useDispatch, useSelector,\n * useWatch, useInspect, useRequirementStatus, useEvents, useExplain,\n * useConstraintStatus, useOptimisticUpdate, useDirective, useTimeTravel,\n * createTypedHooks, shallowEqual\n *\n * Store factories: createDerivedStore, createDerivedsStore, createFactStore, createInspectStore\n */\n\nimport { onDestroy } from \"svelte\";\nimport { readable, type Readable } from \"svelte/store\";\nimport type {\n\tModuleSchema,\n\tModuleDef,\n\tModulesMap,\n\tPlugin,\n\tDebugConfig,\n\tErrorBoundaryConfig,\n\tInferFacts,\n\tInferDerivations,\n\tInferSelectorState,\n\tInferEvents,\n\tSingleModuleSystem,\n\tNamespacedSystem,\n\tSystemInspection,\n\tSystemSnapshot,\n\tTimeTravelState,\n} from \"@directive-run/core\";\nimport {\n\tcreateSystem,\n\tcreateRequirementStatusPlugin,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n\ttype InspectState,\n\ttype ConstraintInfo,\n\tcomputeInspectState,\n\tcreateThrottle,\n\tassertSystem,\n\tdefaultEquality,\n\tbuildTimeTravelState,\n\tpickFacts,\n\trunTrackedSelector,\n\tdepsChanged,\n\tshallowEqual,\n} from \"@directive-run/core/adapter-utils\";\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// Store Factories\n// ============================================================================\n\n/**\n * Create a Svelte store for a derived value.\n */\nexport function createDerivedStore<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tderivationId: string,\n): Readable<T> {\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tconst initialValue = system.read(derivationId);\n\t\tif (initialValue === undefined) {\n\t\t\tconsole.warn(\n\t\t\t\t`[Directive] createDerivedStore(\"${derivationId}\") returned undefined. ` +\n\t\t\t\t`Check that \"${derivationId}\" is defined in your module's derive property.`,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn readable<T>(system.read(derivationId) as T, (set) => {\n\t\tconst unsubscribe = system.subscribe([derivationId], () => {\n\t\t\tset(system.read(derivationId) as T);\n\t\t});\n\t\treturn unsubscribe;\n\t});\n}\n\n/**\n * Create a Svelte store for multiple derived values.\n */\nexport function createDerivedsStore<T extends Record<string, unknown>>(\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tderivationIds: string[],\n): Readable<T> {\n\tconst getValues = (): T => {\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const id of derivationIds) {\n\t\t\tresult[id] = system.read(id);\n\t\t}\n\t\treturn result as T;\n\t};\n\n\treturn readable<T>(getValues(), (set) => {\n\t\tconst unsubscribe = system.subscribe(derivationIds, () => {\n\t\t\tset(getValues());\n\t\t});\n\t\treturn unsubscribe;\n\t});\n}\n\n/**\n * Create a Svelte store for a single fact value.\n */\nexport function createFactStore<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tfactKey: string,\n): Readable<T | undefined> {\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tif (!system.facts.$store.has(factKey)) {\n\t\t\tconsole.warn(\n\t\t\t\t`[Directive] createFactStore(\"${factKey}\") — fact not found in store. ` +\n\t\t\t\t`Check that \"${factKey}\" is defined in your module's schema.`,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn readable<T | undefined>(\n\t\tsystem.facts.$store.get(factKey) as T | undefined,\n\t\t(set) => {\n\t\t\tconst unsubscribe = system.facts.$store.subscribe([factKey], () => {\n\t\t\t\tset(system.facts.$store.get(factKey) as T | undefined);\n\t\t\t});\n\t\t\treturn unsubscribe;\n\t\t},\n\t);\n}\n\n/**\n * Create a Svelte store for system inspection data.\n * NOTE: This updates on every fact change. Use sparingly in production.\n */\nexport function createInspectStore(\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n): Readable<SystemInspection> {\n\treturn readable<SystemInspection>(system.inspect(), (set) => {\n\t\tconst update = () => set(system.inspect());\n\t\tconst unsubFacts = system.facts.$store.subscribeAll(update);\n\t\tconst unsubSettled = system.onSettledChange(update);\n\t\treturn () => {\n\t\t\tunsubFacts();\n\t\t\tunsubSettled();\n\t\t};\n\t});\n}\n\n// ============================================================================\n// useFact — single key or multi key\n// ============================================================================\n\n/** Single key overload */\nexport function useFact<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(system: SingleModuleSystem<S>, factKey: K): Readable<InferFacts<S>[K] | undefined>;\n/** Multi-key overload */\nexport function useFact<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(system: SingleModuleSystem<S>, factKeys: K[]): Readable<Pick<InferFacts<S>, K>>;\n/** Implementation */\nexport function useFact(\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tsystem: SingleModuleSystem<any>,\n\tkeyOrKeys: string | string[],\n): Readable<unknown> {\n\tassertSystem(\"useFact\", system);\n\tif (process.env.NODE_ENV !== \"production\" && typeof keyOrKeys === \"function\") {\n\t\tconsole.error(\n\t\t\t\"[Directive] useFact() received a function. Did you mean useSelector()? \" +\n\t\t\t\t\"useFact() takes a string key or array of keys, not a selector function.\",\n\t\t);\n\t}\n\n\t// Multi-key path: useFact(system, [keys])\n\tif (Array.isArray(keyOrKeys)) {\n\t\treturn _useFactMulti(system, keyOrKeys);\n\t}\n\n\t// Single key path: useFact(system, key)\n\treturn createFactStore(system, keyOrKeys);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactMulti(system: SingleModuleSystem<any>, factKeys: string[]): Readable<Record<string, unknown>> {\n\tconst getValues = (): Record<string, unknown> => {\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const key of factKeys) {\n\t\t\tresult[key] = system.facts.$store.get(key);\n\t\t}\n\t\treturn result;\n\t};\n\n\treturn readable(getValues(), (set) => {\n\t\tconst unsubscribe = system.facts.$store.subscribe(factKeys, () => {\n\t\t\tset(getValues());\n\t\t});\n\t\treturn unsubscribe;\n\t});\n}\n\n// ============================================================================\n// useDerived — single key or multi key\n// ============================================================================\n\n/** Single key overload */\nexport function useDerived<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(system: SingleModuleSystem<S>, derivationId: K): Readable<InferDerivations<S>[K]>;\n/** Multi-key overload */\nexport function useDerived<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(system: SingleModuleSystem<S>, derivationIds: K[]): Readable<Pick<InferDerivations<S>, K>>;\n/** Implementation */\nexport function useDerived(\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tsystem: SingleModuleSystem<any>,\n\tidOrIds: string | string[],\n): Readable<unknown> {\n\tassertSystem(\"useDerived\", system);\n\tif (process.env.NODE_ENV !== \"production\" && typeof idOrIds === \"function\") {\n\t\tconsole.error(\n\t\t\t\"[Directive] useDerived() received a function. Did you mean useSelector()? \" +\n\t\t\t\t\"useDerived() takes a string key or array of keys, not a selector function.\",\n\t\t);\n\t}\n\n\t// Multi-key path\n\tif (Array.isArray(idOrIds)) {\n\t\treturn createDerivedsStore(system, idOrIds);\n\t}\n\n\t// Single key path\n\treturn createDerivedStore(system, idOrIds);\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>(system: SingleModuleSystem<S>, selector: (state: InferSelectorState<S>) => R, equalityFn?: (a: R, b: R) => boolean): Readable<R>;\nexport function useSelector(\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tsystem: SingleModuleSystem<any>,\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tselector: (state: any) => unknown,\n\tequalityFn: (a: unknown, b: unknown) => boolean = defaultEquality,\n): Readable<unknown> {\n\tassertSystem(\"useSelector\", system);\n\tconst deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n\t// Build a tracking-aware state proxy that exposes both facts and derivations\n\tconst runWithTracking = () => runTrackedSelector(system, deriveKeySet, selector);\n\n\tconst initial = runWithTracking();\n\n\treturn readable(initial.value, (set) => {\n\t\tlet currentSelected = initial.value;\n\t\tlet trackedFactKeys = initial.factKeys;\n\t\tlet trackedDeriveKeys = initial.deriveKeys;\n\t\tconst unsubs: Array<() => void> = [];\n\n\t\tconst resubscribe = () => {\n\t\t\tfor (const unsub of unsubs) unsub();\n\t\t\tunsubs.length = 0;\n\n\t\t\tconst onUpdate = () => {\n\t\t\t\tconst result = runWithTracking();\n\t\t\t\tif (!equalityFn(currentSelected, result.value)) {\n\t\t\t\t\tcurrentSelected = result.value;\n\t\t\t\t\tset(result.value);\n\t\t\t\t}\n\t\t\t\t// Re-track: check if deps changed\n\t\t\t\tif (depsChanged(trackedFactKeys, result.factKeys, trackedDeriveKeys, result.deriveKeys)) {\n\t\t\t\t\ttrackedFactKeys = result.factKeys;\n\t\t\t\t\ttrackedDeriveKeys = result.deriveKeys;\n\t\t\t\t\tresubscribe();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tif (trackedFactKeys.length > 0) {\n\t\t\t\tunsubs.push(system.facts.$store.subscribe(trackedFactKeys, onUpdate));\n\t\t\t} else if (trackedDeriveKeys.length === 0) {\n\t\t\t\tunsubs.push(system.facts.$store.subscribeAll(onUpdate));\n\t\t\t}\n\t\t\tif (trackedDeriveKeys.length > 0) {\n\t\t\t\tunsubs.push(system.subscribe(trackedDeriveKeys, onUpdate));\n\t\t\t}\n\t\t};\n\n\t\tresubscribe();\n\n\t\treturn () => {\n\t\t\tfor (const unsub of unsubs) unsub();\n\t\t};\n\t});\n}\n\n// ============================================================================\n// useDispatch\n// ============================================================================\n\nexport function useDispatch<S extends ModuleSchema>(\n\tsystem: SingleModuleSystem<S>,\n): (event: InferEvents<S>) => void {\n\tassertSystem(\"useDispatch\", system);\n\treturn (event: InferEvents<S>) => {\n\t\tsystem.dispatch(event);\n\t};\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\tsystem: SingleModuleSystem<S>,\n): SingleModuleSystem<S>[\"events\"] {\n\tassertSystem(\"useEvents\", system);\n\treturn 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<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(\n\tsystem: SingleModuleSystem<S>,\n\tkey: K,\n\tcallback: (newValue: InferDerivations<S>[K], previousValue: InferDerivations<S>[K] | undefined) => void,\n): void;\n/** Watch a fact key with auto-detection. */\nexport function useWatch<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(\n\tsystem: SingleModuleSystem<S>,\n\tkey: K,\n\tcallback: (newValue: InferFacts<S>[K] | undefined, previousValue: InferFacts<S>[K] | undefined) => void,\n): void;\n/** Implementation */\nexport function useWatch(\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tsystem: SingleModuleSystem<any>,\n\tkey: string,\n\tcallback: (newValue: unknown, prevValue: unknown) => void,\n): void {\n\tassertSystem(\"useWatch\", system);\n\n\tconst unsubscribe = system.watch(key, callback);\n\tonDestroy(unsubscribe);\n}\n\n// ============================================================================\n// useInspect — consolidated inspection hook\n// ============================================================================\n\n/** Options for useInspect */\nexport interface UseInspectOptions {\n\tthrottleMs?: number;\n}\n\n/**\n * Consolidated system inspection hook.\n * Returns Readable<InspectState> with optional throttling.\n */\nexport function useInspect(\n\t// biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n\tsystem: SingleModuleSystem<any>,\n\toptions?: UseInspectOptions,\n): Readable<InspectState> {\n\tassertSystem(\"useInspect\", system);\n\tif (options?.throttleMs && options.throttleMs > 0) {\n\t\treturn readable<InspectState>(computeInspectState(system), (set) => {\n\t\t\tconst { throttled, cleanup } = createThrottle(() => {\n\t\t\t\tset(computeInspectState(system));\n\t\t\t}, options.throttleMs!);\n\n\t\t\tconst unsubFacts = system.facts.$store.subscribeAll(throttled);\n\t\t\tconst unsubSettled = system.onSettledChange(throttled);\n\n\t\t\treturn () => {\n\t\t\t\tcleanup();\n\t\t\t\tunsubFacts();\n\t\t\t\tunsubSettled();\n\t\t\t};\n\t\t});\n\t}\n\n\treturn readable<InspectState>(computeInspectState(system), (set) => {\n\t\tconst update = () => set(computeInspectState(system));\n\t\tconst unsubFacts = system.facts.$store.subscribeAll(update);\n\t\tconst unsubSettled = system.onSettledChange(update);\n\n\t\treturn () => {\n\t\t\tunsubFacts();\n\t\t\tunsubSettled();\n\t\t};\n\t});\n}\n\n// ============================================================================\n// useRequirementStatus — single or multi\n// ============================================================================\n\n/** Single type overload */\nexport function useRequirementStatus(statusPlugin: StatusPlugin, type: string): Readable<RequirementTypeStatus>;\n/** Multi-type overload */\nexport function useRequirementStatus(statusPlugin: StatusPlugin, types: string[]): Readable<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useRequirementStatus(\n\tstatusPlugin: StatusPlugin,\n\ttypeOrTypes: string | string[],\n): Readable<RequirementTypeStatus> | Readable<Record<string, RequirementTypeStatus>> {\n\tif (Array.isArray(typeOrTypes)) {\n\t\tconst getValues = (): Record<string, RequirementTypeStatus> => {\n\t\t\tconst result: Record<string, RequirementTypeStatus> = {};\n\t\t\tfor (const type of typeOrTypes) {\n\t\t\t\tresult[type] = statusPlugin.getStatus(type);\n\t\t\t}\n\t\t\treturn result;\n\t\t};\n\n\t\treturn readable(getValues(), (set) => {\n\t\t\tconst unsubscribe = statusPlugin.subscribe(() => {\n\t\t\t\tset(getValues());\n\t\t\t});\n\t\t\treturn unsubscribe;\n\t\t});\n\t}\n\n\treturn readable<RequirementTypeStatus>(statusPlugin.getStatus(typeOrTypes), (set) => {\n\t\tconst unsubscribe = statusPlugin.subscribe(() => {\n\t\t\tset(statusPlugin.getStatus(typeOrTypes));\n\t\t});\n\t\treturn unsubscribe;\n\t});\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\t// biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n\tsystem: SingleModuleSystem<any>,\n\trequirementId: string,\n): Readable<string | null> {\n\tassertSystem(\"useExplain\", system);\n\treturn readable<string | null>(system.explain(requirementId), (set) => {\n\t\tconst update = () => set(system.explain(requirementId));\n\t\tconst unsubFacts = system.facts.$store.subscribeAll(update);\n\t\tconst unsubSettled = system.onSettledChange(update);\n\n\t\treturn () => {\n\t\t\tunsubFacts();\n\t\t\tunsubSettled();\n\t\t};\n\t});\n}\n\n// ============================================================================\n// useConstraintStatus — reactive constraint inspection\n// ============================================================================\n\n/** Get all constraints */\nexport function useConstraintStatus(\n\tsystem: SingleModuleSystem<any>,\n): Readable<ConstraintInfo[]>;\n/** Get a single constraint by ID */\nexport function useConstraintStatus(\n\tsystem: SingleModuleSystem<any>,\n\tconstraintId: string,\n): Readable<ConstraintInfo | null>;\n/** Implementation */\nexport function useConstraintStatus(\n\t// biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n\tsystem: SingleModuleSystem<any>,\n\tconstraintId?: string,\n): Readable<ConstraintInfo[] | ConstraintInfo | null> {\n\tassertSystem(\"useConstraintStatus\", system);\n\treturn readable<ConstraintInfo[] | ConstraintInfo | null>(\n\t\t_getConstraintValue(system, constraintId),\n\t\t(set) => {\n\t\t\tconst update = () => set(_getConstraintValue(system, constraintId));\n\t\t\tconst unsubFacts = system.facts.$store.subscribeAll(update);\n\t\t\tconst unsubSettled = system.onSettledChange(update);\n\n\t\t\treturn () => {\n\t\t\t\tunsubFacts();\n\t\t\t\tunsubSettled();\n\t\t\t};\n\t\t},\n\t);\n}\n\nfunction _getConstraintValue(\n\t// biome-ignore lint/suspicious/noExplicitAny: Internal\n\tsystem: SingleModuleSystem<any>,\n\tconstraintId?: string,\n): ConstraintInfo[] | ConstraintInfo | null {\n\tconst inspection = system.inspect();\n\tif (!constraintId) return inspection.constraints;\n\treturn inspection.constraints.find((c: ConstraintInfo) => c.id === constraintId) ?? null;\n}\n\n// ============================================================================\n// useOptimisticUpdate — batch with rollback on failure\n// ============================================================================\n\nexport interface OptimisticUpdateResult {\n\tmutate: (updateFn: () => void) => void;\n\tisPending: Readable<boolean>;\n\terror: Readable<Error | null>;\n\trollback: () => 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\t// biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n\tsystem: SingleModuleSystem<any>,\n\tstatusPlugin?: StatusPlugin,\n\trequirementType?: string,\n): OptimisticUpdateResult {\n\tassertSystem(\"useOptimisticUpdate\", system);\n\tlet isPendingValue = false;\n\tlet errorValue: Error | null = null;\n\tlet snapshot: SystemSnapshot | null = null;\n\tlet statusUnsub: (() => void) | null = null;\n\n\t// We track subscribers manually since we need imperative push\n\tconst pendingSubscribers = new Set<(v: boolean) => void>();\n\tconst errorSubscribers = new Set<(v: Error | null) => void>();\n\n\tconst isPending: Readable<boolean> = {\n\t\tsubscribe(fn) {\n\t\t\tfn(isPendingValue);\n\t\t\tpendingSubscribers.add(fn);\n\t\t\treturn () => pendingSubscribers.delete(fn);\n\t\t},\n\t};\n\n\tconst error: Readable<Error | null> = {\n\t\tsubscribe(fn) {\n\t\t\tfn(errorValue);\n\t\t\terrorSubscribers.add(fn);\n\t\t\treturn () => errorSubscribers.delete(fn);\n\t\t},\n\t};\n\n\tconst setPending = (v: boolean) => {\n\t\tisPendingValue = v;\n\t\tfor (const fn of pendingSubscribers) fn(v);\n\t};\n\n\tconst setError = (v: Error | null) => {\n\t\terrorValue = v;\n\t\tfor (const fn of errorSubscribers) fn(v);\n\t};\n\n\tconst rollback = () => {\n\t\tif (snapshot) {\n\t\t\tsystem.restore(snapshot);\n\t\t\tsnapshot = null;\n\t\t}\n\t\tsetPending(false);\n\t\tsetError(null);\n\t\tstatusUnsub?.();\n\t\tstatusUnsub = null;\n\t};\n\n\tconst mutate = (updateFn: () => void) => {\n\t\tsnapshot = system.getSnapshot();\n\t\tsetPending(true);\n\t\tsetError(null);\n\t\tsystem.batch(updateFn);\n\n\t\tif (statusPlugin && requirementType) {\n\t\t\tstatusUnsub?.();\n\t\t\tstatusUnsub = statusPlugin.subscribe(() => {\n\t\t\t\tconst status = statusPlugin.getStatus(requirementType);\n\t\t\t\tif (!status.isLoading && !status.hasError) {\n\t\t\t\t\tsnapshot = null;\n\t\t\t\t\tsetPending(false);\n\t\t\t\t\tstatusUnsub?.();\n\t\t\t\t\tstatusUnsub = null;\n\t\t\t\t} else if (status.hasError) {\n\t\t\t\t\tsetError(status.lastError);\n\t\t\t\t\trollback();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t};\n\n\tonDestroy(() => {\n\t\tstatusUnsub?.();\n\t});\n\n\treturn { mutate, isPending, error, rollback };\n}\n\n// ============================================================================\n// useTimeTravel — reactive time-travel store\n// ============================================================================\n\n/**\n * Reactive time-travel Svelte store. Returns a Readable that updates\n * when snapshots are taken or navigation occurs.\n *\n * @example\n * ```svelte\n * const tt = useTimeTravel(system);\n * <button disabled={!$tt?.canUndo} on:click={() => $tt?.undo()}>Undo</button>\n * ```\n */\nexport function useTimeTravel(\n\t// biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n\tsystem: SingleModuleSystem<any>,\n): Readable<TimeTravelState | null> {\n\tassertSystem(\"useTimeTravel\", system);\n\treturn readable<TimeTravelState | null>(buildTimeTravelState(system), (set) => {\n\t\treturn system.onTimeTravelChange(() => set(buildTimeTravelState(system)));\n\t});\n}\n\n// ============================================================================\n// Scoped System\n// ============================================================================\n\n/** Configuration for useDirective */\ninterface UseDirectiveConfig {\n\t// biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n\tplugins?: Plugin<any>[];\n\tdebug?: DebugConfig;\n\terrorBoundary?: ErrorBoundaryConfig;\n\ttickMs?: number;\n\tzeroConfig?: boolean;\n\t// biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n\tinitialFacts?: Record<string, any>;\n\tstatus?: boolean;\n\t/** Fact keys to subscribe to (omit for all) */\n\tfacts?: string[];\n\t/** Derivation keys to subscribe to (omit for all) */\n\tderived?: 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 Svelte readable stores.\n *\n * @example\n * ```svelte\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\tmoduleDef: ModuleDef<M>,\n\tconfig?: UseDirectiveConfig,\n) {\n\tconst allPlugins = [...(config?.plugins ?? [])];\n\tlet statusPlugin: StatusPlugin | undefined;\n\n\tif (config?.status) {\n\t\tconst sp = createRequirementStatusPlugin();\n\t\tstatusPlugin = sp;\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n\t\tallPlugins.push(sp.plugin as Plugin<any>);\n\t}\n\n\t// biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n\tconst system = createSystem({\n\t\tmodule: moduleDef,\n\t\tplugins: allPlugins.length > 0 ? allPlugins : undefined,\n\t\tdebug: config?.debug,\n\t\terrorBoundary: config?.errorBoundary,\n\t\ttickMs: config?.tickMs,\n\t\tzeroConfig: config?.zeroConfig,\n\t\tinitialFacts: config?.initialFacts,\n\t} as any) as unknown as SingleModuleSystem<M>;\n\n\tsystem.start();\n\n\tonDestroy(() => {\n\t\tsystem.destroy();\n\t});\n\n\tconst factKeys = config?.facts;\n\tconst derivedKeys = config?.derived;\n\tconst subscribeAll = !factKeys && !derivedKeys;\n\n\t// Subscribe to facts\n\tconst factsStore: Readable<InferFacts<M>> = subscribeAll\n\t\t? readable(system.facts.$store.toObject() as InferFacts<M>, (set) => {\n\t\t\treturn system.facts.$store.subscribeAll(() => {\n\t\t\t\tset(system.facts.$store.toObject() as InferFacts<M>);\n\t\t\t});\n\t\t})\n\t\t: readable(pickFacts(system, factKeys ?? []) as InferFacts<M>, (set) => {\n\t\t\tif (!factKeys || factKeys.length === 0) return () => {};\n\t\t\treturn system.facts.$store.subscribe(factKeys, () => {\n\t\t\t\tset(pickFacts(system, factKeys) as InferFacts<M>);\n\t\t\t});\n\t\t});\n\n\t// Subscribe to derivations\n\tconst allDerivationKeys = subscribeAll ? Object.keys(system.derive ?? {}) : (derivedKeys ?? []);\n\tconst getDerived = (): InferDerivations<M> => {\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const key of allDerivationKeys) {\n\t\t\tresult[key] = system.read(key);\n\t\t}\n\t\treturn result as InferDerivations<M>;\n\t};\n\tconst derivedStore: Readable<InferDerivations<M>> = allDerivationKeys.length > 0\n\t\t? readable(getDerived(), (set) => {\n\t\t\treturn system.subscribe(allDerivationKeys, () => {\n\t\t\t\tset(getDerived());\n\t\t\t});\n\t\t})\n\t\t: readable(getDerived(), () => () => {});\n\n\tconst events = system.events;\n\tconst dispatch = (event: InferEvents<M>) => system.dispatch(event);\n\n\treturn {\n\t\tsystem,\n\t\tfacts: factsStore,\n\t\tderived: derivedStore,\n\t\tevents,\n\t\tdispatch,\n\t\tstatusPlugin,\n\t};\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n\tuseFact: <K extends keyof InferFacts<M> & string>(\n\t\tsystem: SingleModuleSystem<M>,\n\t\tfactKey: K,\n\t) => Readable<InferFacts<M>[K] | undefined>;\n\tuseDerived: <K extends keyof InferDerivations<M> & string>(\n\t\tsystem: SingleModuleSystem<M>,\n\t\tderivationId: K,\n\t) => Readable<InferDerivations<M>[K]>;\n\tuseDispatch: (system: SingleModuleSystem<M>) => (event: InferEvents<M>) => void;\n\tuseEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n\tuseWatch: <K extends string>(\n\t\tsystem: SingleModuleSystem<M>,\n\t\tkey: K,\n\t\tcallback: (newValue: unknown, previousValue: unknown) => void,\n\t) => void;\n} {\n\treturn {\n\t\tuseFact: <K extends keyof InferFacts<M> & string>(system: SingleModuleSystem<M>, factKey: K) =>\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Cast for overload compatibility\n\t\t\tuseFact(system as SingleModuleSystem<any>, factKey) as Readable<InferFacts<M>[K] | undefined>,\n\t\tuseDerived: <K extends keyof InferDerivations<M> & string>(system: SingleModuleSystem<M>, derivationId: K) =>\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Cast for overload compatibility\n\t\t\tuseDerived(system as SingleModuleSystem<any>, derivationId) as Readable<InferDerivations<M>[K]>,\n\t\tuseDispatch: (system: SingleModuleSystem<M>) => {\n\t\t\treturn (event: InferEvents<M>) => {\n\t\t\t\tsystem.dispatch(event);\n\t\t\t};\n\t\t},\n\t\tuseEvents: (system: SingleModuleSystem<M>) => useEvents<M>(system),\n\t\tuseWatch: <K extends string>(\n\t\t\tsystem: SingleModuleSystem<M>,\n\t\t\tkey: K,\n\t\t\tcallback: (newValue: unknown, previousValue: unknown) => void,\n\t\t) =>\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Cast for overload compatibility\n\t\t\tuseWatch(system as SingleModuleSystem<any>, key, callback),\n\t};\n}\n\n// ============================================================================\n// useNamespacedSelector — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * Svelte readable store 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 * ```svelte\n * const token$ = useNamespacedSelector(system, [\"auth.token\"], (s) => s.facts.auth.token);\n * ```\n */\nexport function useNamespacedSelector<Modules extends ModulesMap, R>(\n\tsystem: NamespacedSystem<Modules>,\n\tkeys: string[],\n\tselector: (system: NamespacedSystem<Modules>) => R,\n): Readable<R> {\n\treturn readable<R>(selector(system), (set) => {\n\t\tconst unsubscribe = system.subscribe(keys, () => {\n\t\t\tset(selector(system));\n\t\t});\n\n\t\treturn unsubscribe;\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["createDerivedStore","system","derivationId","readable","set","createDerivedsStore","derivationIds","getValues","result","id","createFactStore","factKey","createInspectStore","update","unsubFacts","unsubSettled","useFact","keyOrKeys","assertSystem","_useFactMulti","factKeys","key","useDerived","idOrIds","useSelector","selector","equalityFn","defaultEquality","deriveKeySet","runWithTracking","runTrackedSelector","initial","currentSelected","trackedFactKeys","trackedDeriveKeys","unsubs","resubscribe","unsub","onUpdate","depsChanged","useDispatch","event","useEvents","useWatch","callback","unsubscribe","onDestroy","useInspect","options","computeInspectState","throttled","cleanup","createThrottle","useRequirementStatus","statusPlugin","typeOrTypes","type","useExplain","requirementId","useConstraintStatus","constraintId","_getConstraintValue","inspection","c","useOptimisticUpdate","requirementType","isPendingValue","errorValue","snapshot","statusUnsub","pendingSubscribers","errorSubscribers","isPending","fn","error","setPending","v","setError","rollback","mutate","updateFn","status","useTimeTravel","buildTimeTravelState","useDirective","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","createSystem","derivedKeys","subscribeAll","factsStore","pickFacts","allDerivationKeys","getDerived","derivedStore","events","createTypedHooks","useNamespacedSelector","keys"],"mappings":"0XA+DO,SAASA,CAAAA,CAEdC,CAAAA,CACAC,EACa,CACb,OAAI,OAAA,CAAQ,GAAA,CAAI,WAAa,YAAA,EACND,CAAAA,CAAO,IAAA,CAAKC,CAAY,IACxB,MAAA,EACnB,OAAA,CAAQ,IAAA,CACN,CAAA,gCAAA,EAAmCA,CAAY,CAAA,mCAAA,EAC9BA,CAAY,gDAC/B,CAAA,CAIGC,QAAAA,CAAYF,EAAO,IAAA,CAAKC,CAAY,CAAA,CAASE,CAAAA,EAC9BH,EAAO,SAAA,CAAU,CAACC,CAAY,CAAA,CAAG,IAAM,CACzDE,CAAAA,CAAIH,CAAAA,CAAO,IAAA,CAAKC,CAAY,CAAM,EACpC,CAAC,CAEF,CACH,CAKO,SAASG,CAAAA,CAEdJ,CAAAA,CACAK,CAAAA,CACa,CACb,IAAMC,CAAAA,CAAY,IAAS,CACzB,IAAMC,CAAAA,CAAkC,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svelte Adapter - Consolidated Svelte stores for Directive\n *\n * 15 active exports: useFact, useDerived, useDispatch, useSelector,\n * useWatch, useInspect, useRequirementStatus, useEvents, useExplain,\n * useConstraintStatus, useOptimisticUpdate, useDirective, useTimeTravel,\n * createTypedHooks, shallowEqual\n *\n * Store factories: createDerivedStore, createDerivedsStore, createFactStore, createInspectStore\n */\n\nimport type {\n DebugConfig,\n ErrorBoundaryConfig,\n InferDerivations,\n InferEvents,\n InferFacts,\n InferSelectorState,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemInspection,\n SystemSnapshot,\n TimeTravelState,\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 buildTimeTravelState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n pickFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport { onDestroy } from \"svelte\";\nimport { type Readable, readable } from \"svelte/store\";\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// Store Factories\n// ============================================================================\n\n/**\n * Create a Svelte store for a derived value.\n */\nexport function createDerivedStore<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n): Readable<T> {\n if (process.env.NODE_ENV !== \"production\") {\n const initialValue = system.read(derivationId);\n if (initialValue === undefined) {\n console.warn(\n `[Directive] createDerivedStore(\"${derivationId}\") returned undefined. ` +\n `Check that \"${derivationId}\" is defined in your module's derive property.`,\n );\n }\n }\n\n return readable<T>(system.read(derivationId) as T, (set) => {\n const unsubscribe = system.subscribe([derivationId], () => {\n set(system.read(derivationId) as T);\n });\n return unsubscribe;\n });\n}\n\n/**\n * Create a Svelte store for multiple derived values.\n */\nexport function createDerivedsStore<T extends Record<string, unknown>>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationIds: string[],\n): Readable<T> {\n const getValues = (): T => {\n const result: Record<string, unknown> = {};\n for (const id of derivationIds) {\n result[id] = system.read(id);\n }\n return result as T;\n };\n\n return readable<T>(getValues(), (set) => {\n const unsubscribe = system.subscribe(derivationIds, () => {\n set(getValues());\n });\n return unsubscribe;\n });\n}\n\n/**\n * Create a Svelte store for a single fact value.\n */\nexport function createFactStore<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): Readable<T | undefined> {\n if (process.env.NODE_ENV !== \"production\") {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] createFactStore(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n\n return readable<T | undefined>(\n system.facts.$store.get(factKey) as T | undefined,\n (set) => {\n const unsubscribe = system.facts.$store.subscribe([factKey], () => {\n set(system.facts.$store.get(factKey) as T | undefined);\n });\n return unsubscribe;\n },\n );\n}\n\n/**\n * Create a Svelte store for system inspection data.\n * NOTE: This updates on every fact change. Use sparingly in production.\n */\nexport function createInspectStore(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n): Readable<SystemInspection> {\n return readable<SystemInspection>(system.inspect(), (set) => {\n const update = () => set(system.inspect());\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n return () => {\n unsubFacts();\n unsubSettled();\n };\n });\n}\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): Readable<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): Readable<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): Readable<unknown> {\n assertSystem(\"useFact\", system);\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof keyOrKeys === \"function\"\n ) {\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: useFact(system, [keys])\n if (Array.isArray(keyOrKeys)) {\n return _useFactMulti(system, keyOrKeys);\n }\n\n // Single key path: useFact(system, key)\n return createFactStore(system, keyOrKeys);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactMulti(\n system: SingleModuleSystem<any>,\n factKeys: string[],\n): Readable<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\n return readable(getValues(), (set) => {\n const unsubscribe = system.facts.$store.subscribe(factKeys, () => {\n set(getValues());\n });\n return unsubscribe;\n });\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): Readable<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): Readable<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): Readable<unknown> {\n assertSystem(\"useDerived\", system);\n if (process.env.NODE_ENV !== \"production\" && 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 createDerivedsStore(system, idOrIds);\n }\n\n // Single key path\n return createDerivedStore(system, idOrIds);\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): Readable<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): Readable<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\n return readable(initial.value, (set) => {\n let currentSelected = initial.value;\n let trackedFactKeys = initial.factKeys;\n let trackedDeriveKeys = initial.deriveKeys;\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 if (!equalityFn(currentSelected, result.value)) {\n currentSelected = result.value;\n set(result.value);\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 return () => {\n for (const unsub of unsubs) unsub();\n };\n });\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 onDestroy(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 Readable<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): Readable<InspectState> {\n assertSystem(\"useInspect\", system);\n if (options?.throttleMs && options.throttleMs > 0) {\n return readable<InspectState>(computeInspectState(system), (set) => {\n const { throttled, cleanup } = createThrottle(() => {\n set(computeInspectState(system));\n }, options.throttleMs!);\n\n const unsubFacts = system.facts.$store.subscribeAll(throttled);\n const unsubSettled = system.onSettledChange(throttled);\n\n return () => {\n cleanup();\n unsubFacts();\n unsubSettled();\n };\n });\n }\n\n return readable<InspectState>(computeInspectState(system), (set) => {\n const update = () => set(computeInspectState(system));\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n\n return () => {\n unsubFacts();\n unsubSettled();\n };\n });\n}\n\n// ============================================================================\n// useRequirementStatus — single or multi\n// ============================================================================\n\n/** Single type overload */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n type: string,\n): Readable<RequirementTypeStatus>;\n/** Multi-type overload */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n types: string[],\n): Readable<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useRequirementStatus(\n statusPlugin: StatusPlugin,\n typeOrTypes: string | string[],\n):\n | Readable<RequirementTypeStatus>\n | Readable<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\n return readable(getValues(), (set) => {\n const unsubscribe = statusPlugin.subscribe(() => {\n set(getValues());\n });\n return unsubscribe;\n });\n }\n\n return readable<RequirementTypeStatus>(\n statusPlugin.getStatus(typeOrTypes),\n (set) => {\n const unsubscribe = statusPlugin.subscribe(() => {\n set(statusPlugin.getStatus(typeOrTypes));\n });\n return unsubscribe;\n },\n );\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): Readable<string | null> {\n assertSystem(\"useExplain\", system);\n return readable<string | null>(system.explain(requirementId), (set) => {\n const update = () => set(system.explain(requirementId));\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n\n return () => {\n unsubFacts();\n unsubSettled();\n };\n });\n}\n\n// ============================================================================\n// useConstraintStatus — reactive constraint inspection\n// ============================================================================\n\n/** Get all constraints */\nexport function useConstraintStatus(\n system: SingleModuleSystem<any>,\n): Readable<ConstraintInfo[]>;\n/** Get a single constraint by ID */\nexport function useConstraintStatus(\n system: SingleModuleSystem<any>,\n constraintId: string,\n): Readable<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): Readable<ConstraintInfo[] | ConstraintInfo | null> {\n assertSystem(\"useConstraintStatus\", system);\n return readable<ConstraintInfo[] | ConstraintInfo | null>(\n _getConstraintValue(system, constraintId),\n (set) => {\n const update = () => set(_getConstraintValue(system, constraintId));\n const unsubFacts = system.facts.$store.subscribeAll(update);\n const unsubSettled = system.onSettledChange(update);\n\n return () => {\n unsubFacts();\n unsubSettled();\n };\n },\n );\n}\n\nfunction _getConstraintValue(\n // biome-ignore lint/suspicious/noExplicitAny: Internal\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): ConstraintInfo[] | ConstraintInfo | null {\n const inspection = system.inspect();\n if (!constraintId) return inspection.constraints;\n return (\n inspection.constraints.find((c: ConstraintInfo) => c.id === constraintId) ??\n null\n );\n}\n\n// ============================================================================\n// useOptimisticUpdate — batch with rollback on failure\n// ============================================================================\n\nexport interface OptimisticUpdateResult {\n mutate: (updateFn: () => void) => void;\n isPending: Readable<boolean>;\n error: Readable<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 let isPendingValue = false;\n let errorValue: Error | null = null;\n let snapshot: SystemSnapshot | null = null;\n let statusUnsub: (() => void) | null = null;\n\n // We track subscribers manually since we need imperative push\n const pendingSubscribers = new Set<(v: boolean) => void>();\n const errorSubscribers = new Set<(v: Error | null) => void>();\n\n const isPending: Readable<boolean> = {\n subscribe(fn) {\n fn(isPendingValue);\n pendingSubscribers.add(fn);\n return () => pendingSubscribers.delete(fn);\n },\n };\n\n const error: Readable<Error | null> = {\n subscribe(fn) {\n fn(errorValue);\n errorSubscribers.add(fn);\n return () => errorSubscribers.delete(fn);\n },\n };\n\n const setPending = (v: boolean) => {\n isPendingValue = v;\n for (const fn of pendingSubscribers) fn(v);\n };\n\n const setError = (v: Error | null) => {\n errorValue = v;\n for (const fn of errorSubscribers) fn(v);\n };\n\n const rollback = () => {\n if (snapshot) {\n system.restore(snapshot);\n snapshot = null;\n }\n setPending(false);\n setError(null);\n statusUnsub?.();\n statusUnsub = null;\n };\n\n const mutate = (updateFn: () => void) => {\n snapshot = system.getSnapshot();\n setPending(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 setPending(false);\n statusUnsub?.();\n statusUnsub = null;\n } else if (status.hasError) {\n setError(status.lastError);\n rollback();\n }\n });\n }\n };\n\n onDestroy(() => {\n statusUnsub?.();\n });\n\n return { mutate, isPending, error, rollback };\n}\n\n// ============================================================================\n// useTimeTravel — reactive time-travel store\n// ============================================================================\n\n/**\n * Reactive time-travel Svelte store. Returns a Readable that updates\n * when snapshots are taken or navigation occurs.\n *\n * @example\n * ```svelte\n * const tt = useTimeTravel(system);\n * <button disabled={!$tt?.canUndo} on:click={() => $tt?.undo()}>Undo</button>\n * ```\n */\nexport function useTimeTravel(\n // biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n system: SingleModuleSystem<any>,\n): Readable<TimeTravelState | null> {\n assertSystem(\"useTimeTravel\", system);\n return readable<TimeTravelState | null>(\n buildTimeTravelState(system),\n (set) => {\n return system.onTimeTravelChange(() => set(buildTimeTravelState(system)));\n },\n );\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 debug?: DebugConfig;\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 Svelte readable stores.\n *\n * @example\n * ```svelte\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 debug: config?.debug,\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 system.start();\n\n onDestroy(() => {\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 factsStore: Readable<InferFacts<M>> = subscribeAll\n ? readable(system.facts.$store.toObject() as InferFacts<M>, (set) => {\n return system.facts.$store.subscribeAll(() => {\n set(system.facts.$store.toObject() as InferFacts<M>);\n });\n })\n : readable(pickFacts(system, factKeys ?? []) as InferFacts<M>, (set) => {\n if (!factKeys || factKeys.length === 0) return () => {};\n return system.facts.$store.subscribe(factKeys, () => {\n set(pickFacts(system, factKeys) as InferFacts<M>);\n });\n });\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 derivedStore: Readable<InferDerivations<M>> =\n allDerivationKeys.length > 0\n ? readable(getDerived(), (set) => {\n return system.subscribe(allDerivationKeys, () => {\n set(getDerived());\n });\n })\n : readable(getDerived(), () => () => {});\n\n const events = system.events;\n const dispatch = (event: InferEvents<M>) => system.dispatch(event);\n\n return {\n system,\n facts: factsStore,\n derived: derivedStore,\n events,\n dispatch,\n statusPlugin,\n };\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 ) => Readable<InferFacts<M>[K] | undefined>;\n useDerived: <K extends keyof InferDerivations<M> & string>(\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => Readable<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: Cast for overload compatibility\n useFact(system as SingleModuleSystem<any>, factKey) as Readable<\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: Cast for overload compatibility\n useDerived(system as SingleModuleSystem<any>, derivationId) as Readable<\n InferDerivations<M>[K]\n >,\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: Cast 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 * Svelte readable store 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 * ```svelte\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): Readable<R> {\n return readable<R>(selector(system), (set) => {\n const unsubscribe = system.subscribe(keys, () => {\n set(selector(system));\n });\n\n return unsubscribe;\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directive-run/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Svelte stores adapter for Directive.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jason Comes",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"svelte": "^4.2.0",
|
|
53
53
|
"tsup": "^8.3.5",
|
|
54
54
|
"typescript": "^5.7.2",
|
|
55
|
-
"@directive-run/core": "0.
|
|
55
|
+
"@directive-run/core": "0.4.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsup",
|