@directive-run/vue 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jason Comes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @directive-run/vue
2
+
3
+ Vue 3 composition API adapter for Directive. Provides reactive `ref` and `shallowRef` composables for reading facts, derivations, and dispatching events.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @directive-run/core @directive-run/vue
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```vue
14
+ <script setup>
15
+ import { useFact, useDerived, useEvents } from "@directive-run/vue";
16
+
17
+ const count = useFact(system, "count");
18
+ const doubled = useDerived(system, "doubled");
19
+ const events = useEvents(system);
20
+ </script>
21
+
22
+ <template>
23
+ <p>Count: {{ count }} (doubled: {{ doubled }})</p>
24
+ <button @click="events.increment()">+</button>
25
+ </template>
26
+ ```
27
+
28
+ ## Exports
29
+
30
+ `useFact`, `useDerived`, `useSelector`, `useDispatch`, `useEvents`, `useWatch`, `useInspect`, `useRequirementStatus`, `useExplain`, `useConstraintStatus`, `useOptimisticUpdate`, `useTimeTravel`, `useDirective`, `createTypedHooks`, `shallowEqual`
31
+
32
+ ## Peer Dependencies
33
+
34
+ - `vue >= 3`
35
+ - `@directive-run/core`
36
+
37
+ ## License
38
+
39
+ MIT
40
+
41
+ [Full documentation](https://directive.run/docs)
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';var vue=require('vue'),core=require('@directive-run/core'),adapterUtils=require('@directive-run/core/adapter-utils');function C(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)?V(e,t):T(e,t)}function T(e,t){process.env.NODE_ENV!=="production"&&(e.facts.$store.has(t)||console.warn(`[Directive] useFact("${t}") \u2014 fact not found in store. Check that "${t}" is defined in your module's schema.`));let s=vue.ref(e.facts.$store.get(t)),o=e.facts.$store.subscribe([t],()=>{s.value=e.facts.$store.get(t);});return vue.onScopeDispose(o),s}function V(e,t){let s=()=>{let u={};for(let r of t)u[r]=e.facts.$store.get(r);return u},o=vue.shallowRef(s()),n=e.facts.$store.subscribe(t,()=>{o.value=s();});return vue.onScopeDispose(n),o}function $(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)?A(e,t):q(e,t)}function q(e,t){process.env.NODE_ENV!=="production"&&e.read(t)===void 0&&console.warn(`[Directive] useDerived("${t}") returned undefined. Check that "${t}" is defined in your module's derive property.`);let s=vue.ref(e.read(t)),o=e.subscribe([t],()=>{s.value=e.read(t);});return vue.onScopeDispose(o),s}function A(e,t){let s=()=>{let u={};for(let r of t)u[r]=e.read(r);return u},o=vue.shallowRef(s()),n=e.subscribe(t,()=>{o.value=s();});return vue.onScopeDispose(n),o}function O(e,t,s=adapterUtils.defaultEquality){adapterUtils.assertSystem("useSelector",e);let o=new Set(Object.keys(e.derive??{})),n=()=>adapterUtils.runTrackedSelector(e,o,t),u=n(),r=u.factKeys,i=u.deriveKeys,l=vue.ref(u.value),S=[],c=()=>{for(let d of S)d();S.length=0;let g=()=>{let d=n();s(l.value,d.value)||(l.value=d.value),adapterUtils.depsChanged(r,d.factKeys,i,d.deriveKeys)&&(r=d.factKeys,i=d.deriveKeys,c());};r.length>0?S.push(e.facts.$store.subscribe(r,g)):i.length===0&&S.push(e.facts.$store.subscribeAll(g)),i.length>0&&S.push(e.subscribe(i,g));};return c(),vue.onScopeDispose(()=>{for(let g of S)g();}),l}function H(e){return adapterUtils.assertSystem("useDispatch",e),t=>{e.dispatch(t);}}function P(e){return adapterUtils.assertSystem("useEvents",e),e.events}function U(e,t,s,o){adapterUtils.assertSystem("useWatch",e);let n=t==="fact"&&typeof s=="string"&&typeof o=="function",u=n?s:t,r=n?o:s,i=e.watch(u,r);vue.onScopeDispose(i);}function W(e,t){adapterUtils.assertSystem("useInspect",e);let s=vue.shallowRef(adapterUtils.computeInspectState(e)),o=()=>{s.value=adapterUtils.computeInspectState(e);};if(t?.throttleMs&&t.throttleMs>0){let{throttled:n,cleanup:u}=adapterUtils.createThrottle(o,t.throttleMs),r=e.facts.$store.subscribeAll(n),i=e.onSettledChange(n);vue.onScopeDispose(()=>{u(),r(),i();});}else {let n=e.facts.$store.subscribeAll(o),u=e.onSettledChange(o);vue.onScopeDispose(()=>{n(),u();});}return s}function L(e,t){if(Array.isArray(t)){let n=()=>{let i={};for(let l of t)i[l]=e.getStatus(l);return i},u=vue.shallowRef(n()),r=e.subscribe(()=>{u.value=n();});return vue.onScopeDispose(r),u}let s=vue.shallowRef(e.getStatus(t)),o=e.subscribe(()=>{s.value=e.getStatus(t);});return vue.onScopeDispose(o),s}function G(e,t){adapterUtils.assertSystem("useExplain",e);let s=vue.ref(e.explain(t)),o=()=>{s.value=e.explain(t);},n=e.facts.$store.subscribeAll(o),u=e.onSettledChange(o);return vue.onScopeDispose(()=>{n(),u();}),s}function J(e,t){adapterUtils.assertSystem("useConstraintStatus",e);let s=W(e);return vue.computed(()=>{s.value;let o=e.inspect();return t?o.constraints.find(n=>n.id===t)??null:o.constraints})}function Q(e,t,s){adapterUtils.assertSystem("useOptimisticUpdate",e);let o=vue.ref(false),n=vue.ref(null),u=null,r=null,i=()=>{u&&(e.restore(u),u=null),o.value=false,n.value=null,r?.(),r=null;},l=S=>{u=e.getSnapshot(),o.value=true,n.value=null,e.batch(S),t&&s&&(r?.(),r=t.subscribe(()=>{let c=t.getStatus(s);!c.isLoading&&!c.hasError?(u=null,o.value=false,r?.(),r=null):c.hasError&&(n.value=c.lastError,i());}));};return vue.onScopeDispose(()=>{r?.();}),{mutate:l,isPending:o,error:n,rollback:i}}function X(e){adapterUtils.assertSystem("useTimeTravel",e);let t=vue.shallowRef(adapterUtils.buildTimeTravelState(e)),s=e.onTimeTravelChange(()=>{t.value=adapterUtils.buildTimeTravelState(e);});return vue.onScopeDispose(s),t}function Y(e,t){let s=[...t?.plugins??[]],o;if(t?.status){let v=core.createRequirementStatusPlugin();o=v,s.push(v.plugin);}let n=core.createSystem({module:e,plugins:s.length>0?s:void 0,debug:t?.debug,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:t?.initialFacts});n.start(),vue.onScopeDispose(()=>{n.destroy();});let u=t?.facts,r=t?.derived,i=!u&&!r,l=vue.shallowRef(i?n.facts.$store.toObject():adapterUtils.pickFacts(n,u??[])),S=i?n.facts.$store.subscribeAll(()=>{l.value=n.facts.$store.toObject();}):u&&u.length>0?n.facts.$store.subscribe(u,()=>{l.value=adapterUtils.pickFacts(n,u);}):null,c=i?Object.keys(n.derive??{}):r??[],g=()=>{let v={};for(let M of c)v[M]=n.read(M);return v},d=vue.shallowRef(g()),R=c.length>0?n.subscribe(c,()=>{d.value=g();}):null;vue.onScopeDispose(()=>{S?.(),R?.();});let k=n.events;return {system:n,facts:l,derived:d,events:k,dispatch:v=>n.dispatch(v),statusPlugin:o}}function Z(){return {useFact:(e,t)=>C(e,t),useDerived:(e,t)=>$(e,t),useDispatch:e=>t=>{e.dispatch(t);},useEvents:e=>P(e),useWatch:(e,t,s)=>U(e,t,s)}}Object.defineProperty(exports,"shallowEqual",{enumerable:true,get:function(){return adapterUtils.shallowEqual}});exports.createTypedHooks=Z;exports.useConstraintStatus=J;exports.useDerived=$;exports.useDirective=Y;exports.useDispatch=H;exports.useEvents=P;exports.useExplain=G;exports.useFact=C;exports.useInspect=W;exports.useOptimisticUpdate=Q;exports.useRequirementStatus=L;exports.useSelector=O;exports.useTimeTravel=X;exports.useWatch=U;//# sourceMappingURL=index.cjs.map
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["useFact","system","keyOrKeys","assertSystem","_useFactMulti","_useFactSingle","factKey","value","ref","unsubscribe","onScopeDispose","factKeys","getValues","result","key","state","shallowRef","useDerived","idOrIds","_useDerivedMulti","_useDerivedSingle","derivationId","derivationIds","id","useSelector","selector","equalityFn","defaultEquality","deriveKeySet","runWithTracking","runTrackedSelector","initial","trackedFactKeys","trackedDeriveKeys","selected","unsubs","resubscribe","unsub","onUpdate","depsChanged","useDispatch","event","useEvents","useWatch","derivationIdOrKind","callbackOrFactKey","maybeCallback","isFact","callback","useInspect","options","computeInspectState","update","throttled","cleanup","createThrottle","unsubFacts","unsubSettled","useRequirementStatus","statusPlugin","typeOrTypes","type","status","useExplain","requirementId","explanation","useConstraintStatus","constraintId","inspectState","computed","fullInspection","c","useOptimisticUpdate","requirementType","isPending","error","snapshot","rollback","mutate","updateFn","useTimeTravel","buildTimeTravelState","useDirective","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","createSystem","derivedKeys","subscribeAll","factsState","pickFacts","allDerivationKeys","getDerived","derivedState","unsubDerived","events","createTypedHooks"],"mappings":"kIAkEO,SAASA,CAAAA,CAEfC,CAAAA,CACAC,CAAAA,CACqC,CAUrC,OATAC,yBAAAA,CAAa,UAAWF,CAAM,CAAA,CAC1B,OAAA,CAAQ,GAAA,CAAI,WAAa,YAAA,EAAgB,OAAOC,CAAAA,EAAc,UAAA,EACjE,QAAQ,KAAA,CACP,gJAED,CAAA,CAIG,KAAA,CAAM,OAAA,CAAQA,CAAS,CAAA,CACnBE,CAAAA,CAAcH,EAAQC,CAAS,CAAA,CAIhCG,CAAAA,CAAeJ,CAAAA,CAAQC,CAAS,CACxC,CAGA,SAASG,CAAAA,CAAeJ,EAAiCK,CAAAA,CAA+B,CACnF,OAAA,CAAQ,GAAA,CAAI,QAAA,GAAa,YAAA,GACvBL,CAAAA,CAAO,KAAA,CAAM,OAAO,GAAA,CAAIK,CAAO,CAAA,EACnC,OAAA,CAAQ,KACP,CAAA,qBAAA,EAAwBA,CAAO,CAAA,+CAAA,EAChBA,CAAO,uCACvB,CAAA,CAAA,CAIF,IAAMC,CAAAA,CAAQC,OAAAA,CAAIP,CAAAA,CAAO,KAAA,CAAM,MAAA,CAAO,GAAA,CAAIK,CAAO,CAAC,CAAA,CAC5CG,CAAAA,CAAcR,CAAAA,CAAO,MAAM,MAAA,CAAO,SAAA,CAAU,CAACK,CAAO,EAAG,IAAM,CAClEC,CAAAA,CAAM,KAAA,CAAQN,CAAAA,CAAO,KAAA,CAAM,MAAA,CAAO,GAAA,CAAIK,CAAO,EAC9C,CAAC,CAAA,CACD,OAAAI,mBAAeD,CAAW,CAAA,CACnBF,CACR,CAGA,SAASH,CAAAA,CAAcH,CAAAA,CAAiCU,CAAAA,CAAyD,CAChH,IAAMC,CAAAA,CAAY,IAA+B,CAChD,IAAMC,CAAAA,CAAkC,E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CAAO,QAAA,CAASwC,CAAK,EACtB,EAED,SAAA,CAAYxC,CAAAA,EAAkCyC,CAAAA,CAAazC,CAAM,EACjE,QAAA,CAAU,CACTA,CAAAA,CACAa,CAAAA,CACAkC,IAGAL,CAAAA,CAAS1C,CAAAA,CAAmCa,CAAAA,CAAKkC,CAAQ,CAC3D,CACD","file":"index.cjs","sourcesContent":["/**\n * Vue Adapter - Vue 3 composables for Directive\n *\n * Exports: useFact, useDerived, useDispatch, useSelector,\n * useWatch, useInspect, useRequirementStatus, useEvents, useExplain,\n * useConstraintStatus, useOptimisticUpdate, useDirective, useTimeTravel,\n * createTypedHooks, shallowEqual\n */\n\nimport {\n\tcomputed,\n\tonScopeDispose,\n\tref,\n\tshallowRef,\n\ttype ComputedRef,\n\ttype Ref,\n\ttype ShallowRef,\n} from \"vue\";\nimport type {\n\tModuleSchema,\n\tModuleDef,\n\tPlugin,\n\tDebugConfig,\n\tErrorBoundaryConfig,\n\tInferFacts,\n\tInferDerivations,\n\tInferSelectorState,\n\tInferEvents,\n\tSingleModuleSystem,\n\tSystemSnapshot,\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// 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): Ref<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[]): ShallowRef<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): Ref<unknown> | ShallowRef<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 _useFactSingle(system, keyOrKeys);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactSingle(system: SingleModuleSystem<any>, factKey: string): Ref<unknown> {\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] useFact(\"${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\tconst value = ref(system.facts.$store.get(factKey));\n\tconst unsubscribe = system.facts.$store.subscribe([factKey], () => {\n\t\tvalue.value = system.facts.$store.get(factKey);\n\t});\n\tonScopeDispose(unsubscribe);\n\treturn value;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactMulti(system: SingleModuleSystem<any>, factKeys: string[]): ShallowRef<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\tconst state = shallowRef(getValues());\n\tconst unsubscribe = system.facts.$store.subscribe(factKeys, () => {\n\t\tstate.value = getValues();\n\t});\n\tonScopeDispose(unsubscribe);\n\treturn state;\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): Ref<InferDerivations<S>[K]>;\n/** Multi-key overload */\nexport function useDerived<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(system: SingleModuleSystem<S>, derivationIds: K[]): ShallowRef<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): Ref<unknown> | ShallowRef<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 _useDerivedMulti(system, idOrIds);\n\t}\n\n\t// Single key path\n\treturn _useDerivedSingle(system, idOrIds);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useDerivedSingle(system: SingleModuleSystem<any>, derivationId: string): Ref<unknown> {\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] useDerived(\"${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\tconst value = ref(system.read(derivationId));\n\tconst unsubscribe = system.subscribe([derivationId], () => {\n\t\tvalue.value = system.read(derivationId);\n\t});\n\tonScopeDispose(unsubscribe);\n\treturn value;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useDerivedMulti(system: SingleModuleSystem<any>, derivationIds: string[]): ShallowRef<Record<string, unknown>> {\n\tconst getValues = (): Record<string, unknown> => {\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;\n\t};\n\tconst state = shallowRef(getValues());\n\tconst unsubscribe = system.subscribe(derivationIds, () => {\n\t\tstate.value = getValues();\n\t});\n\tonScopeDispose(unsubscribe);\n\treturn state;\n}\n\n// ============================================================================\n// useSelector — auto-tracking selector over facts and derivations\n// ============================================================================\n\n/**\n * Auto-tracking selector over facts and derivations.\n * Uses `withTracking()` to detect which facts the selector accesses,\n * then subscribes only to those keys.\n */\nexport function useSelector<S extends ModuleSchema, R>(system: SingleModuleSystem<S>, selector: (state: InferSelectorState<S>) => R, equalityFn?: (a: R, b: R) => boolean): Ref<R>;\nexport function useSelector<R>(\n\t// biome-ignore lint/suspicious/noExplicitAny: Backward-compatible fallback\n\tsystem: SingleModuleSystem<any>,\n\t// biome-ignore lint/suspicious/noExplicitAny: Selector receives dynamic state\n\tselector: (state: Record<string, any>) => R,\n\tequalityFn?: (a: R, b: R) => boolean,\n): Ref<R>;\nexport function useSelector(\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tsystem: SingleModuleSystem<any>,\n\tselector: (state: Record<string, unknown>) => unknown,\n\tequalityFn: (a: unknown, b: unknown) => boolean = defaultEquality,\n): Ref<unknown> {\n\tassertSystem(\"useSelector\", system);\n\tconst deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n\tconst runWithTracking = () => runTrackedSelector(system, deriveKeySet, selector);\n\n\tconst initial = runWithTracking();\n\tlet trackedFactKeys = initial.factKeys;\n\tlet trackedDeriveKeys = initial.deriveKeys;\n\tconst selected = ref(initial.value);\n\n\tconst unsubs: Array<() => void> = [];\n\n\tconst resubscribe = () => {\n\t\tfor (const unsub of unsubs) unsub();\n\t\tunsubs.length = 0;\n\n\t\tconst onUpdate = () => {\n\t\t\tconst result = runWithTracking();\n\t\t\tif (!equalityFn(selected.value, result.value)) {\n\t\t\t\tselected.value = result.value;\n\t\t\t}\n\t\t\t// Re-track: check if deps changed\n\t\t\tif (depsChanged(trackedFactKeys, result.factKeys, trackedDeriveKeys, result.deriveKeys)) {\n\t\t\t\ttrackedFactKeys = result.factKeys;\n\t\t\t\ttrackedDeriveKeys = result.deriveKeys;\n\t\t\t\tresubscribe();\n\t\t\t}\n\t\t};\n\n\t\tif (trackedFactKeys.length > 0) {\n\t\t\tunsubs.push(system.facts.$store.subscribe(trackedFactKeys, onUpdate));\n\t\t} else if (trackedDeriveKeys.length === 0) {\n\t\t\tunsubs.push(system.facts.$store.subscribeAll(onUpdate));\n\t\t}\n\t\tif (trackedDeriveKeys.length > 0) {\n\t\t\tunsubs.push(system.subscribe(trackedDeriveKeys, onUpdate));\n\t\t}\n\t};\n\n\tresubscribe();\n\n\tonScopeDispose(() => {\n\t\tfor (const unsub of unsubs) unsub();\n\t});\n\n\treturn selected;\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/**\n * Watch a fact by explicit \"fact\" discriminator.\n * @deprecated Use `useWatch(system, key, callback)` instead — facts are now auto-detected.\n */\nexport function useWatch<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(\n\tsystem: SingleModuleSystem<S>,\n\tkind: \"fact\",\n\tfactKey: K,\n\tcallback: (newValue: InferFacts<S>[K] | undefined, previousValue: InferFacts<S>[K] | undefined) => void,\n): void;\n/** Watch a fact or derivation (generic fallback) */\nexport function useWatch<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: Backward-compatible fallback\n\tsystem: SingleModuleSystem<any>,\n\tkey: string,\n\tcallback: (newValue: T, previousValue: T | undefined) => void,\n): void;\n/** Implementation */\nexport function useWatch(\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tsystem: SingleModuleSystem<any>,\n\tderivationIdOrKind: string,\n\tcallbackOrFactKey: string | ((newValue: unknown, prevValue: unknown) => void),\n\tmaybeCallback?: (newValue: unknown, prevValue: unknown) => void,\n): void {\n\tassertSystem(\"useWatch\", system);\n\t// Backward compat: useWatch(system, \"fact\", factKey, callback)\n\tconst isFact =\n\t\tderivationIdOrKind === \"fact\" &&\n\t\ttypeof callbackOrFactKey === \"string\" &&\n\t\ttypeof maybeCallback === \"function\";\n\n\tconst key = isFact ? (callbackOrFactKey as string) : derivationIdOrKind;\n\tconst callback = isFact\n\t\t? maybeCallback!\n\t\t: (callbackOrFactKey as (newValue: unknown, prevValue: unknown) => void);\n\n\tconst unsubscribe = system.watch(key, callback);\n\tonScopeDispose(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 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): ShallowRef<InspectState> {\n\tassertSystem(\"useInspect\", system);\n\tconst state = shallowRef<InspectState>(computeInspectState(system));\n\n\tconst update = () => {\n\t\tstate.value = computeInspectState(system);\n\t};\n\n\tif (options?.throttleMs && options.throttleMs > 0) {\n\t\tconst { throttled, cleanup } = createThrottle(update, options.throttleMs);\n\t\tconst unsubFacts = system.facts.$store.subscribeAll(throttled);\n\t\tconst unsubSettled = system.onSettledChange(throttled);\n\t\tonScopeDispose(() => {\n\t\t\tcleanup();\n\t\t\tunsubFacts();\n\t\t\tunsubSettled();\n\t\t});\n\t} else {\n\t\tconst unsubFacts = system.facts.$store.subscribeAll(update);\n\t\tconst unsubSettled = system.onSettledChange(update);\n\t\tonScopeDispose(() => {\n\t\t\tunsubFacts();\n\t\t\tunsubSettled();\n\t\t});\n\t}\n\n\treturn state;\n}\n\n// ============================================================================\n// useRequirementStatus — single or multi\n// ============================================================================\n\n/** Single type overload */\nexport function useRequirementStatus(statusPlugin: StatusPlugin, type: string): ShallowRef<RequirementTypeStatus>;\n/** Multi-type overload */\nexport function useRequirementStatus(statusPlugin: StatusPlugin, types: string[]): ShallowRef<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useRequirementStatus(\n\tstatusPlugin: StatusPlugin,\n\ttypeOrTypes: string | string[],\n): ShallowRef<RequirementTypeStatus> | ShallowRef<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\t\tconst state = shallowRef(getValues());\n\t\tconst unsubscribe = statusPlugin.subscribe(() => {\n\t\t\tstate.value = getValues();\n\t\t});\n\t\tonScopeDispose(unsubscribe);\n\t\treturn state;\n\t}\n\n\tconst status = shallowRef<RequirementTypeStatus>(statusPlugin.getStatus(typeOrTypes));\n\tconst unsubscribe = statusPlugin.subscribe(() => {\n\t\tstatus.value = statusPlugin.getStatus(typeOrTypes);\n\t});\n\tonScopeDispose(unsubscribe);\n\treturn status;\n}\n\n// ============================================================================\n// useExplain — reactive requirement explanation\n// ============================================================================\n\n/**\n * Reactively returns the explanation string for a requirement.\n */\nexport function useExplain(\n\t// biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n\tsystem: SingleModuleSystem<any>,\n\trequirementId: string,\n): Ref<string | null> {\n\tassertSystem(\"useExplain\", system);\n\tconst explanation = ref<string | null>(system.explain(requirementId)) as Ref<string | null>;\n\n\tconst update = () => {\n\t\texplanation.value = system.explain(requirementId);\n\t};\n\n\tconst unsubFacts = system.facts.$store.subscribeAll(update);\n\tconst unsubSettled = system.onSettledChange(update);\n\tonScopeDispose(() => {\n\t\tunsubFacts();\n\t\tunsubSettled();\n\t});\n\n\treturn explanation;\n}\n\n// ============================================================================\n// useConstraintStatus — reactive constraint inspection\n// ============================================================================\n\n/** Get all constraints */\nexport function useConstraintStatus(\n\tsystem: SingleModuleSystem<any>,\n): ComputedRef<ConstraintInfo[]>;\n/** Get a single constraint by ID */\nexport function useConstraintStatus(\n\tsystem: SingleModuleSystem<any>,\n\tconstraintId: string,\n): ComputedRef<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): ComputedRef<ConstraintInfo[] | ConstraintInfo | null> {\n\tassertSystem(\"useConstraintStatus\", system);\n\tconst inspectState = useInspect(system);\n\n\treturn computed(() => {\n\t\t// Track reactivity via inspectState, but use full inspect() for constraint list\n\t\tvoid inspectState.value;\n\t\tconst fullInspection = system.inspect();\n\t\tif (!constraintId) return fullInspection.constraints;\n\t\treturn fullInspection.constraints.find((c) => c.id === constraintId) ?? null;\n\t});\n}\n\n// ============================================================================\n// useOptimisticUpdate — batch with rollback on failure\n// ============================================================================\n\nexport interface OptimisticUpdateResult {\n\tmutate: (updateFn: () => void) => void;\n\tisPending: Ref<boolean>;\n\terror: Ref<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\tconst isPending = ref(false);\n\tconst error = ref<Error | null>(null) as Ref<Error | null>;\n\tlet snapshot: SystemSnapshot | null = null;\n\tlet unsubscribe: (() => void) | null = null;\n\n\tconst rollback = () => {\n\t\tif (snapshot) {\n\t\t\tsystem.restore(snapshot);\n\t\t\tsnapshot = null;\n\t\t}\n\t\tisPending.value = false;\n\t\terror.value = null;\n\t\tunsubscribe?.();\n\t\tunsubscribe = null;\n\t};\n\n\tconst mutate = (updateFn: () => void) => {\n\t\tsnapshot = system.getSnapshot();\n\t\tisPending.value = true;\n\t\terror.value = null;\n\t\tsystem.batch(updateFn);\n\n\t\t// Watch for resolver completion/failure\n\t\tif (statusPlugin && requirementType) {\n\t\t\tunsubscribe?.();\n\t\t\tunsubscribe = 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\tisPending.value = false;\n\t\t\t\t\tunsubscribe?.();\n\t\t\t\t\tunsubscribe = null;\n\t\t\t\t} else if (status.hasError) {\n\t\t\t\t\terror.value = status.lastError;\n\t\t\t\t\trollback();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t};\n\n\tonScopeDispose(() => {\n\t\tunsubscribe?.();\n\t});\n\n\treturn { mutate, isPending, error, rollback };\n}\n\n// ============================================================================\n// useTimeTravel — reactive time-travel state\n// ============================================================================\n\n/**\n * Reactive time-travel composable. Returns a ShallowRef that updates\n * when snapshots are taken or navigation occurs.\n *\n * @example\n * ```vue\n * const tt = useTimeTravel(system);\n * <button :disabled=\"!tt.value?.canUndo\" @click=\"tt.value?.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): ShallowRef<ReturnType<typeof buildTimeTravelState>> {\n\tassertSystem(\"useTimeTravel\", system);\n\tconst state = shallowRef<ReturnType<typeof buildTimeTravelState>>(buildTimeTravelState(system));\n\tconst unsub = system.onTimeTravelChange(() => {\n\t\tstate.value = buildTimeTravelState(system);\n\t});\n\tonScopeDispose(unsub);\n\treturn state;\n}\n\n// ============================================================================\n// Scoped System Composable\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 reactive state.\n *\n * @example\n * ```vue\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\tonScopeDispose(() => {\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 factsState = shallowRef(\n\t\tsubscribeAll\n\t\t\t? (system.facts.$store.toObject() as InferFacts<M>)\n\t\t\t: pickFacts(system, factKeys ?? []),\n\t);\n\tconst unsubFacts = subscribeAll\n\t\t? system.facts.$store.subscribeAll(() => {\n\t\t\tfactsState.value = system.facts.$store.toObject() as InferFacts<M>;\n\t\t})\n\t\t: factKeys && factKeys.length > 0\n\t\t\t? system.facts.$store.subscribe(factKeys, () => {\n\t\t\t\tfactsState.value = pickFacts(system, factKeys) as InferFacts<M>;\n\t\t\t})\n\t\t\t: null;\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 derivedState = shallowRef(getDerived());\n\tconst unsubDerived = allDerivationKeys.length > 0\n\t\t? system.subscribe(allDerivationKeys, () => { derivedState.value = getDerived(); })\n\t\t: null;\n\n\tonScopeDispose(() => {\n\t\tunsubFacts?.();\n\t\tunsubDerived?.();\n\t});\n\n\tconst events = system.events;\n\tconst dispatch = (event: InferEvents<M>) => system.dispatch(event);\n\n\treturn {\n\t\tsystem,\n\t\tfacts: factsState as ShallowRef<InferFacts<M>>,\n\t\tderived: derivedState as ShallowRef<InferDerivations<M>>,\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) => Ref<InferFacts<M>[K] | undefined>;\n\tuseDerived: <K extends keyof InferDerivations<M> & string>(\n\t\tsystem: SingleModuleSystem<M>,\n\t\tderivationId: K,\n\t) => Ref<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: Type narrowing for internal call\n\t\t\tuseFact(system as SingleModuleSystem<any>, factKey) as Ref<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: Type narrowing for internal call\n\t\t\tuseDerived(system as SingleModuleSystem<any>, derivationId) as Ref<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: Type narrowing for internal call\n\t\t\tuseWatch(system as SingleModuleSystem<any>, key, callback),\n\t};\n}\n"]}
@@ -0,0 +1,144 @@
1
+ import { Ref, ComputedRef, ShallowRef } from 'vue';
2
+ import { createRequirementStatusPlugin, ModuleSchema, InferFacts, SingleModuleSystem, InferDerivations, InferEvents, ModuleDef, Plugin, DebugConfig, ErrorBoundaryConfig, RequirementTypeStatus, InferSelectorState } from '@directive-run/core';
3
+ export { RequirementTypeStatus } from '@directive-run/core';
4
+ import { ConstraintInfo, InspectState, buildTimeTravelState } from '@directive-run/core/adapter-utils';
5
+ export { ConstraintInfo, InspectState, shallowEqual } from '@directive-run/core/adapter-utils';
6
+
7
+ /**
8
+ * Vue Adapter - Vue 3 composables for Directive
9
+ *
10
+ * Exports: useFact, useDerived, useDispatch, useSelector,
11
+ * useWatch, useInspect, useRequirementStatus, useEvents, useExplain,
12
+ * useConstraintStatus, useOptimisticUpdate, useDirective, useTimeTravel,
13
+ * createTypedHooks, shallowEqual
14
+ */
15
+
16
+ /** Type for the requirement status plugin return value */
17
+ type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;
18
+ /** Single key overload */
19
+ declare function useFact<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(system: SingleModuleSystem<S>, factKey: K): Ref<InferFacts<S>[K] | undefined>;
20
+ /** Multi-key overload */
21
+ declare function useFact<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(system: SingleModuleSystem<S>, factKeys: K[]): ShallowRef<Pick<InferFacts<S>, K>>;
22
+ /** Single key overload */
23
+ declare function useDerived<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(system: SingleModuleSystem<S>, derivationId: K): Ref<InferDerivations<S>[K]>;
24
+ /** Multi-key overload */
25
+ declare function useDerived<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(system: SingleModuleSystem<S>, derivationIds: K[]): ShallowRef<Pick<InferDerivations<S>, K>>;
26
+ /**
27
+ * Auto-tracking selector over facts and derivations.
28
+ * Uses `withTracking()` to detect which facts the selector accesses,
29
+ * then subscribes only to those keys.
30
+ */
31
+ declare function useSelector<S extends ModuleSchema, R>(system: SingleModuleSystem<S>, selector: (state: InferSelectorState<S>) => R, equalityFn?: (a: R, b: R) => boolean): Ref<R>;
32
+ declare function useSelector<R>(system: SingleModuleSystem<any>, selector: (state: Record<string, any>) => R, equalityFn?: (a: R, b: R) => boolean): Ref<R>;
33
+ declare function useDispatch<S extends ModuleSchema>(system: SingleModuleSystem<S>): (event: InferEvents<S>) => void;
34
+ /**
35
+ * Returns the system's events dispatcher.
36
+ */
37
+ declare function useEvents<S extends ModuleSchema>(system: SingleModuleSystem<S>): SingleModuleSystem<S>["events"];
38
+ /** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */
39
+ declare function useWatch<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(system: SingleModuleSystem<S>, key: K, callback: (newValue: InferDerivations<S>[K], previousValue: InferDerivations<S>[K] | undefined) => void): void;
40
+ /** Watch a fact key with auto-detection. */
41
+ declare function useWatch<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(system: SingleModuleSystem<S>, key: K, callback: (newValue: InferFacts<S>[K] | undefined, previousValue: InferFacts<S>[K] | undefined) => void): void;
42
+ /**
43
+ * Watch a fact by explicit "fact" discriminator.
44
+ * @deprecated Use `useWatch(system, key, callback)` instead — facts are now auto-detected.
45
+ */
46
+ declare function useWatch<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(system: SingleModuleSystem<S>, kind: "fact", factKey: K, callback: (newValue: InferFacts<S>[K] | undefined, previousValue: InferFacts<S>[K] | undefined) => void): void;
47
+ /** Watch a fact or derivation (generic fallback) */
48
+ declare function useWatch<T>(system: SingleModuleSystem<any>, key: string, callback: (newValue: T, previousValue: T | undefined) => void): void;
49
+ /** Options for useInspect */
50
+ interface UseInspectOptions {
51
+ throttleMs?: number;
52
+ }
53
+ /**
54
+ * Consolidated system inspection hook.
55
+ * Returns InspectState with optional throttling.
56
+ */
57
+ declare function useInspect(system: SingleModuleSystem<any>, options?: UseInspectOptions): ShallowRef<InspectState>;
58
+ /** Single type overload */
59
+ declare function useRequirementStatus(statusPlugin: StatusPlugin, type: string): ShallowRef<RequirementTypeStatus>;
60
+ /** Multi-type overload */
61
+ declare function useRequirementStatus(statusPlugin: StatusPlugin, types: string[]): ShallowRef<Record<string, RequirementTypeStatus>>;
62
+ /**
63
+ * Reactively returns the explanation string for a requirement.
64
+ */
65
+ declare function useExplain(system: SingleModuleSystem<any>, requirementId: string): Ref<string | null>;
66
+ /** Get all constraints */
67
+ declare function useConstraintStatus(system: SingleModuleSystem<any>): ComputedRef<ConstraintInfo[]>;
68
+ /** Get a single constraint by ID */
69
+ declare function useConstraintStatus(system: SingleModuleSystem<any>, constraintId: string): ComputedRef<ConstraintInfo | null>;
70
+ interface OptimisticUpdateResult {
71
+ mutate: (updateFn: () => void) => void;
72
+ isPending: Ref<boolean>;
73
+ error: Ref<Error | null>;
74
+ rollback: () => void;
75
+ }
76
+ /**
77
+ * Optimistic update hook. Saves a snapshot before mutating, monitors
78
+ * a requirement type via statusPlugin, and rolls back on failure.
79
+ */
80
+ declare function useOptimisticUpdate(system: SingleModuleSystem<any>, statusPlugin?: StatusPlugin, requirementType?: string): OptimisticUpdateResult;
81
+ /**
82
+ * Reactive time-travel composable. Returns a ShallowRef that updates
83
+ * when snapshots are taken or navigation occurs.
84
+ *
85
+ * @example
86
+ * ```vue
87
+ * const tt = useTimeTravel(system);
88
+ * <button :disabled="!tt.value?.canUndo" @click="tt.value?.undo()">Undo</button>
89
+ * ```
90
+ */
91
+ declare function useTimeTravel(system: SingleModuleSystem<any>): ShallowRef<ReturnType<typeof buildTimeTravelState>>;
92
+ /** Configuration for useDirective */
93
+ interface UseDirectiveConfig {
94
+ plugins?: Plugin<any>[];
95
+ debug?: DebugConfig;
96
+ errorBoundary?: ErrorBoundaryConfig;
97
+ tickMs?: number;
98
+ zeroConfig?: boolean;
99
+ initialFacts?: Record<string, any>;
100
+ status?: boolean;
101
+ /** Fact keys to subscribe to (omit for all) */
102
+ facts?: string[];
103
+ /** Derivation keys to subscribe to (omit for all) */
104
+ derived?: string[];
105
+ }
106
+ /**
107
+ * Create a scoped Directive system with automatic lifecycle management.
108
+ * When no `facts` or `derived` keys are specified, subscribes to ALL
109
+ * facts and derivations and returns reactive state.
110
+ *
111
+ * @example
112
+ * ```vue
113
+ * // Subscribe to everything
114
+ * const { facts, derived, events, dispatch } = useDirective(counterModule);
115
+ *
116
+ * // Selective keys
117
+ * const { facts, derived } = useDirective(counterModule, { facts: ["count"], derived: ["doubled"] });
118
+ * ```
119
+ */
120
+ declare function useDirective<M extends ModuleSchema>(moduleDef: ModuleDef<M>, config?: UseDirectiveConfig): {
121
+ system: SingleModuleSystem<M>;
122
+ facts: ShallowRef<InferFacts<M>>;
123
+ derived: ShallowRef<InferDerivations<M>>;
124
+ events: M["events"] extends Record<string, unknown> ? { [E in keyof M["events"]]: M["events"][E] extends Record<string, unknown> ? keyof M["events"][E] extends never ? () => void : (payload: M["events"][E] extends infer T ? T extends M["events"][E] ? T extends Record<string, unknown> ? { [K in keyof T]: T[K] extends {
125
+ _type: infer T_1;
126
+ } ? T_1 : T[K]; } : never : never : never) => void : () => void; } : Record<string, never>;
127
+ dispatch: (event: InferEvents<M>) => void;
128
+ statusPlugin: {
129
+ plugin: Plugin<never>;
130
+ getStatus: (type: string) => RequirementTypeStatus;
131
+ getAllStatus: () => Map<string, RequirementTypeStatus>;
132
+ subscribe: (listener: () => void) => () => void;
133
+ reset: () => void;
134
+ } | undefined;
135
+ };
136
+ declare function createTypedHooks<M extends ModuleSchema>(): {
137
+ useFact: <K extends keyof InferFacts<M> & string>(system: SingleModuleSystem<M>, factKey: K) => Ref<InferFacts<M>[K] | undefined>;
138
+ useDerived: <K extends keyof InferDerivations<M> & string>(system: SingleModuleSystem<M>, derivationId: K) => Ref<InferDerivations<M>[K]>;
139
+ useDispatch: (system: SingleModuleSystem<M>) => (event: InferEvents<M>) => void;
140
+ useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>["events"];
141
+ useWatch: <K extends string>(system: SingleModuleSystem<M>, key: K, callback: (newValue: unknown, previousValue: unknown) => void) => void;
142
+ };
143
+
144
+ export { type OptimisticUpdateResult, type StatusPlugin, type UseInspectOptions, createTypedHooks, useConstraintStatus, useDerived, useDirective, useDispatch, useEvents, useExplain, useFact, useInspect, useOptimisticUpdate, useRequirementStatus, useSelector, useTimeTravel, useWatch };
@@ -0,0 +1,144 @@
1
+ import { Ref, ComputedRef, ShallowRef } from 'vue';
2
+ import { createRequirementStatusPlugin, ModuleSchema, InferFacts, SingleModuleSystem, InferDerivations, InferEvents, ModuleDef, Plugin, DebugConfig, ErrorBoundaryConfig, RequirementTypeStatus, InferSelectorState } from '@directive-run/core';
3
+ export { RequirementTypeStatus } from '@directive-run/core';
4
+ import { ConstraintInfo, InspectState, buildTimeTravelState } from '@directive-run/core/adapter-utils';
5
+ export { ConstraintInfo, InspectState, shallowEqual } from '@directive-run/core/adapter-utils';
6
+
7
+ /**
8
+ * Vue Adapter - Vue 3 composables for Directive
9
+ *
10
+ * Exports: useFact, useDerived, useDispatch, useSelector,
11
+ * useWatch, useInspect, useRequirementStatus, useEvents, useExplain,
12
+ * useConstraintStatus, useOptimisticUpdate, useDirective, useTimeTravel,
13
+ * createTypedHooks, shallowEqual
14
+ */
15
+
16
+ /** Type for the requirement status plugin return value */
17
+ type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;
18
+ /** Single key overload */
19
+ declare function useFact<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(system: SingleModuleSystem<S>, factKey: K): Ref<InferFacts<S>[K] | undefined>;
20
+ /** Multi-key overload */
21
+ declare function useFact<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(system: SingleModuleSystem<S>, factKeys: K[]): ShallowRef<Pick<InferFacts<S>, K>>;
22
+ /** Single key overload */
23
+ declare function useDerived<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(system: SingleModuleSystem<S>, derivationId: K): Ref<InferDerivations<S>[K]>;
24
+ /** Multi-key overload */
25
+ declare function useDerived<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(system: SingleModuleSystem<S>, derivationIds: K[]): ShallowRef<Pick<InferDerivations<S>, K>>;
26
+ /**
27
+ * Auto-tracking selector over facts and derivations.
28
+ * Uses `withTracking()` to detect which facts the selector accesses,
29
+ * then subscribes only to those keys.
30
+ */
31
+ declare function useSelector<S extends ModuleSchema, R>(system: SingleModuleSystem<S>, selector: (state: InferSelectorState<S>) => R, equalityFn?: (a: R, b: R) => boolean): Ref<R>;
32
+ declare function useSelector<R>(system: SingleModuleSystem<any>, selector: (state: Record<string, any>) => R, equalityFn?: (a: R, b: R) => boolean): Ref<R>;
33
+ declare function useDispatch<S extends ModuleSchema>(system: SingleModuleSystem<S>): (event: InferEvents<S>) => void;
34
+ /**
35
+ * Returns the system's events dispatcher.
36
+ */
37
+ declare function useEvents<S extends ModuleSchema>(system: SingleModuleSystem<S>): SingleModuleSystem<S>["events"];
38
+ /** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */
39
+ declare function useWatch<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(system: SingleModuleSystem<S>, key: K, callback: (newValue: InferDerivations<S>[K], previousValue: InferDerivations<S>[K] | undefined) => void): void;
40
+ /** Watch a fact key with auto-detection. */
41
+ declare function useWatch<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(system: SingleModuleSystem<S>, key: K, callback: (newValue: InferFacts<S>[K] | undefined, previousValue: InferFacts<S>[K] | undefined) => void): void;
42
+ /**
43
+ * Watch a fact by explicit "fact" discriminator.
44
+ * @deprecated Use `useWatch(system, key, callback)` instead — facts are now auto-detected.
45
+ */
46
+ declare function useWatch<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(system: SingleModuleSystem<S>, kind: "fact", factKey: K, callback: (newValue: InferFacts<S>[K] | undefined, previousValue: InferFacts<S>[K] | undefined) => void): void;
47
+ /** Watch a fact or derivation (generic fallback) */
48
+ declare function useWatch<T>(system: SingleModuleSystem<any>, key: string, callback: (newValue: T, previousValue: T | undefined) => void): void;
49
+ /** Options for useInspect */
50
+ interface UseInspectOptions {
51
+ throttleMs?: number;
52
+ }
53
+ /**
54
+ * Consolidated system inspection hook.
55
+ * Returns InspectState with optional throttling.
56
+ */
57
+ declare function useInspect(system: SingleModuleSystem<any>, options?: UseInspectOptions): ShallowRef<InspectState>;
58
+ /** Single type overload */
59
+ declare function useRequirementStatus(statusPlugin: StatusPlugin, type: string): ShallowRef<RequirementTypeStatus>;
60
+ /** Multi-type overload */
61
+ declare function useRequirementStatus(statusPlugin: StatusPlugin, types: string[]): ShallowRef<Record<string, RequirementTypeStatus>>;
62
+ /**
63
+ * Reactively returns the explanation string for a requirement.
64
+ */
65
+ declare function useExplain(system: SingleModuleSystem<any>, requirementId: string): Ref<string | null>;
66
+ /** Get all constraints */
67
+ declare function useConstraintStatus(system: SingleModuleSystem<any>): ComputedRef<ConstraintInfo[]>;
68
+ /** Get a single constraint by ID */
69
+ declare function useConstraintStatus(system: SingleModuleSystem<any>, constraintId: string): ComputedRef<ConstraintInfo | null>;
70
+ interface OptimisticUpdateResult {
71
+ mutate: (updateFn: () => void) => void;
72
+ isPending: Ref<boolean>;
73
+ error: Ref<Error | null>;
74
+ rollback: () => void;
75
+ }
76
+ /**
77
+ * Optimistic update hook. Saves a snapshot before mutating, monitors
78
+ * a requirement type via statusPlugin, and rolls back on failure.
79
+ */
80
+ declare function useOptimisticUpdate(system: SingleModuleSystem<any>, statusPlugin?: StatusPlugin, requirementType?: string): OptimisticUpdateResult;
81
+ /**
82
+ * Reactive time-travel composable. Returns a ShallowRef that updates
83
+ * when snapshots are taken or navigation occurs.
84
+ *
85
+ * @example
86
+ * ```vue
87
+ * const tt = useTimeTravel(system);
88
+ * <button :disabled="!tt.value?.canUndo" @click="tt.value?.undo()">Undo</button>
89
+ * ```
90
+ */
91
+ declare function useTimeTravel(system: SingleModuleSystem<any>): ShallowRef<ReturnType<typeof buildTimeTravelState>>;
92
+ /** Configuration for useDirective */
93
+ interface UseDirectiveConfig {
94
+ plugins?: Plugin<any>[];
95
+ debug?: DebugConfig;
96
+ errorBoundary?: ErrorBoundaryConfig;
97
+ tickMs?: number;
98
+ zeroConfig?: boolean;
99
+ initialFacts?: Record<string, any>;
100
+ status?: boolean;
101
+ /** Fact keys to subscribe to (omit for all) */
102
+ facts?: string[];
103
+ /** Derivation keys to subscribe to (omit for all) */
104
+ derived?: string[];
105
+ }
106
+ /**
107
+ * Create a scoped Directive system with automatic lifecycle management.
108
+ * When no `facts` or `derived` keys are specified, subscribes to ALL
109
+ * facts and derivations and returns reactive state.
110
+ *
111
+ * @example
112
+ * ```vue
113
+ * // Subscribe to everything
114
+ * const { facts, derived, events, dispatch } = useDirective(counterModule);
115
+ *
116
+ * // Selective keys
117
+ * const { facts, derived } = useDirective(counterModule, { facts: ["count"], derived: ["doubled"] });
118
+ * ```
119
+ */
120
+ declare function useDirective<M extends ModuleSchema>(moduleDef: ModuleDef<M>, config?: UseDirectiveConfig): {
121
+ system: SingleModuleSystem<M>;
122
+ facts: ShallowRef<InferFacts<M>>;
123
+ derived: ShallowRef<InferDerivations<M>>;
124
+ events: M["events"] extends Record<string, unknown> ? { [E in keyof M["events"]]: M["events"][E] extends Record<string, unknown> ? keyof M["events"][E] extends never ? () => void : (payload: M["events"][E] extends infer T ? T extends M["events"][E] ? T extends Record<string, unknown> ? { [K in keyof T]: T[K] extends {
125
+ _type: infer T_1;
126
+ } ? T_1 : T[K]; } : never : never : never) => void : () => void; } : Record<string, never>;
127
+ dispatch: (event: InferEvents<M>) => void;
128
+ statusPlugin: {
129
+ plugin: Plugin<never>;
130
+ getStatus: (type: string) => RequirementTypeStatus;
131
+ getAllStatus: () => Map<string, RequirementTypeStatus>;
132
+ subscribe: (listener: () => void) => () => void;
133
+ reset: () => void;
134
+ } | undefined;
135
+ };
136
+ declare function createTypedHooks<M extends ModuleSchema>(): {
137
+ useFact: <K extends keyof InferFacts<M> & string>(system: SingleModuleSystem<M>, factKey: K) => Ref<InferFacts<M>[K] | undefined>;
138
+ useDerived: <K extends keyof InferDerivations<M> & string>(system: SingleModuleSystem<M>, derivationId: K) => Ref<InferDerivations<M>[K]>;
139
+ useDispatch: (system: SingleModuleSystem<M>) => (event: InferEvents<M>) => void;
140
+ useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>["events"];
141
+ useWatch: <K extends string>(system: SingleModuleSystem<M>, key: K, callback: (newValue: unknown, previousValue: unknown) => void) => void;
142
+ };
143
+
144
+ export { type OptimisticUpdateResult, type StatusPlugin, type UseInspectOptions, createTypedHooks, useConstraintStatus, useDerived, useDirective, useDispatch, useEvents, useExplain, useFact, useInspect, useOptimisticUpdate, useRequirementStatus, useSelector, useTimeTravel, useWatch };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import {ref,onScopeDispose,shallowRef,computed}from'vue';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';function C(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)?V(e,t):T(e,t)}function T(e,t){process.env.NODE_ENV!=="production"&&(e.facts.$store.has(t)||console.warn(`[Directive] useFact("${t}") \u2014 fact not found in store. Check that "${t}" is defined in your module's schema.`));let s=ref(e.facts.$store.get(t)),o=e.facts.$store.subscribe([t],()=>{s.value=e.facts.$store.get(t);});return onScopeDispose(o),s}function V(e,t){let s=()=>{let u={};for(let r of t)u[r]=e.facts.$store.get(r);return u},o=shallowRef(s()),n=e.facts.$store.subscribe(t,()=>{o.value=s();});return onScopeDispose(n),o}function $(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)?A(e,t):q(e,t)}function q(e,t){process.env.NODE_ENV!=="production"&&e.read(t)===void 0&&console.warn(`[Directive] useDerived("${t}") returned undefined. Check that "${t}" is defined in your module's derive property.`);let s=ref(e.read(t)),o=e.subscribe([t],()=>{s.value=e.read(t);});return onScopeDispose(o),s}function A(e,t){let s=()=>{let u={};for(let r of t)u[r]=e.read(r);return u},o=shallowRef(s()),n=e.subscribe(t,()=>{o.value=s();});return onScopeDispose(n),o}function O(e,t,s=defaultEquality){assertSystem("useSelector",e);let o=new Set(Object.keys(e.derive??{})),n=()=>runTrackedSelector(e,o,t),u=n(),r=u.factKeys,i=u.deriveKeys,l=ref(u.value),S=[],c=()=>{for(let d of S)d();S.length=0;let g=()=>{let d=n();s(l.value,d.value)||(l.value=d.value),depsChanged(r,d.factKeys,i,d.deriveKeys)&&(r=d.factKeys,i=d.deriveKeys,c());};r.length>0?S.push(e.facts.$store.subscribe(r,g)):i.length===0&&S.push(e.facts.$store.subscribeAll(g)),i.length>0&&S.push(e.subscribe(i,g));};return c(),onScopeDispose(()=>{for(let g of S)g();}),l}function H(e){return assertSystem("useDispatch",e),t=>{e.dispatch(t);}}function P(e){return assertSystem("useEvents",e),e.events}function U(e,t,s,o){assertSystem("useWatch",e);let n=t==="fact"&&typeof s=="string"&&typeof o=="function",u=n?s:t,r=n?o:s,i=e.watch(u,r);onScopeDispose(i);}function W(e,t){assertSystem("useInspect",e);let s=shallowRef(computeInspectState(e)),o=()=>{s.value=computeInspectState(e);};if(t?.throttleMs&&t.throttleMs>0){let{throttled:n,cleanup:u}=createThrottle(o,t.throttleMs),r=e.facts.$store.subscribeAll(n),i=e.onSettledChange(n);onScopeDispose(()=>{u(),r(),i();});}else {let n=e.facts.$store.subscribeAll(o),u=e.onSettledChange(o);onScopeDispose(()=>{n(),u();});}return s}function L(e,t){if(Array.isArray(t)){let n=()=>{let i={};for(let l of t)i[l]=e.getStatus(l);return i},u=shallowRef(n()),r=e.subscribe(()=>{u.value=n();});return onScopeDispose(r),u}let s=shallowRef(e.getStatus(t)),o=e.subscribe(()=>{s.value=e.getStatus(t);});return onScopeDispose(o),s}function G(e,t){assertSystem("useExplain",e);let s=ref(e.explain(t)),o=()=>{s.value=e.explain(t);},n=e.facts.$store.subscribeAll(o),u=e.onSettledChange(o);return onScopeDispose(()=>{n(),u();}),s}function J(e,t){assertSystem("useConstraintStatus",e);let s=W(e);return computed(()=>{s.value;let o=e.inspect();return t?o.constraints.find(n=>n.id===t)??null:o.constraints})}function Q(e,t,s){assertSystem("useOptimisticUpdate",e);let o=ref(false),n=ref(null),u=null,r=null,i=()=>{u&&(e.restore(u),u=null),o.value=false,n.value=null,r?.(),r=null;},l=S=>{u=e.getSnapshot(),o.value=true,n.value=null,e.batch(S),t&&s&&(r?.(),r=t.subscribe(()=>{let c=t.getStatus(s);!c.isLoading&&!c.hasError?(u=null,o.value=false,r?.(),r=null):c.hasError&&(n.value=c.lastError,i());}));};return onScopeDispose(()=>{r?.();}),{mutate:l,isPending:o,error:n,rollback:i}}function X(e){assertSystem("useTimeTravel",e);let t=shallowRef(buildTimeTravelState(e)),s=e.onTimeTravelChange(()=>{t.value=buildTimeTravelState(e);});return onScopeDispose(s),t}function Y(e,t){let s=[...t?.plugins??[]],o;if(t?.status){let v=createRequirementStatusPlugin();o=v,s.push(v.plugin);}let n=createSystem({module:e,plugins:s.length>0?s:void 0,debug:t?.debug,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:t?.initialFacts});n.start(),onScopeDispose(()=>{n.destroy();});let u=t?.facts,r=t?.derived,i=!u&&!r,l=shallowRef(i?n.facts.$store.toObject():pickFacts(n,u??[])),S=i?n.facts.$store.subscribeAll(()=>{l.value=n.facts.$store.toObject();}):u&&u.length>0?n.facts.$store.subscribe(u,()=>{l.value=pickFacts(n,u);}):null,c=i?Object.keys(n.derive??{}):r??[],g=()=>{let v={};for(let M of c)v[M]=n.read(M);return v},d=shallowRef(g()),R=c.length>0?n.subscribe(c,()=>{d.value=g();}):null;onScopeDispose(()=>{S?.(),R?.();});let k=n.events;return {system:n,facts:l,derived:d,events:k,dispatch:v=>n.dispatch(v),statusPlugin:o}}function Z(){return {useFact:(e,t)=>C(e,t),useDerived:(e,t)=>$(e,t),useDispatch:e=>t=>{e.dispatch(t);},useEvents:e=>P(e),useWatch:(e,t,s)=>U(e,t,s)}}export{Z as createTypedHooks,J as useConstraintStatus,$ as useDerived,Y as useDirective,H as useDispatch,P as useEvents,G as useExplain,C as useFact,W as useInspect,Q as useOptimisticUpdate,L as useRequirementStatus,O as useSelector,X as useTimeTravel,U as useWatch};//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["useFact","system","keyOrKeys","assertSystem","_useFactMulti","_useFactSingle","factKey","value","ref","unsubscribe","onScopeDispose","factKeys","getValues","result","key","state","shallowRef","useDerived","idOrIds","_useDerivedMulti","_useDerivedSingle","derivationId","derivationIds","id","useSelector","selector","equalityFn","defaultEquality","deriveKeySet","runWithTracking","runTrackedSelector","initial","trackedFactKeys","trackedDeriveKeys","selected","unsubs","resubscribe","unsub","onUpdate","depsChanged","useDispatch","event","useEvents","useWatch","derivationIdOrKind","callbackOrFactKey","maybeCallback","isFact","callback","useInspect","options","computeInspectState","update","throttled","cleanup","createThrottle","unsubFacts","unsubSettled","useRequirementStatus","statusPlugin","typeOrTypes","type","status","useExplain","requirementId","explanation","useConstraintStatus","constraintId","inspectState","computed","fullInspection","c","useOptimisticUpdate","requirementType","isPending","error","snapshot","rollback","mutate","updateFn","useTimeTravel","buildTimeTravelState","useDirective","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","createSystem","derivedKeys","subscribeAll","factsState","pickFacts","allDerivationKeys","getDerived","derivedState","unsubDerived","events","createTypedHooks"],"mappings":"gXAkEO,SAASA,CAAAA,CAEfC,CAAAA,CACAC,CAAAA,CACqC,CAUrC,OATAC,YAAAA,CAAa,UAAWF,CAAM,CAAA,CAC1B,OAAA,CAAQ,GAAA,CAAI,WAAa,YAAA,EAAgB,OAAOC,CAAAA,EAAc,UAAA,EACjE,QAAQ,KAAA,CACP,gJAED,CAAA,CAIG,KAAA,CAAM,OAAA,CAAQA,CAAS,CAAA,CACnBE,CAAAA,CAAcH,EAAQC,CAAS,CAAA,CAIhCG,CAAAA,CAAeJ,CAAAA,CAAQC,CAAS,CACxC,CAGA,SAASG,CAAAA,CAAeJ,EAAiCK,CAAAA,CAA+B,CACnF,OAAA,CAAQ,GAAA,CAAI,QAAA,GAAa,YAAA,GACvBL,CAAAA,CAAO,KAAA,CAAM,OAAO,GAAA,CAAIK,CAAO,CAAA,EACnC,OAAA,CAAQ,KACP,CAAA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OAAO,CACN,MAAA,CAAAA,CAAAA,CACA,KAAA,CAAO0F,CAAAA,CACP,QAASI,CAAAA,CACT,MAAA,CAAAE,CAAAA,CACA,QAAA,CAPiBxD,CAAAA,EAA0BxC,CAAAA,CAAO,QAAA,CAASwC,CAAK,EAQhE,YAAA,CAAAkB,CACD,CACD,CAMO,SAASuC,CAAAA,EAgBd,CACD,OAAO,CACN,QAAS,CAAyCjG,CAAAA,CAA+BK,CAAAA,GAEhFN,CAAAA,CAAQC,CAAAA,CAAmCK,CAAO,CAAA,CACnD,UAAA,CAAY,CAA+CL,CAAAA,CAA+BoB,CAAAA,GAEzFJ,CAAAA,CAAWhB,CAAAA,CAAmCoB,CAAY,CAAA,CAC3D,WAAA,CAAcpB,CAAAA,EACLwC,CAAAA,EAA0B,CACjCxC,CAAAA,CAAO,QAAA,CAASwC,CAAK,EACtB,EAED,SAAA,CAAYxC,CAAAA,EAAkCyC,CAAAA,CAAazC,CAAM,EACjE,QAAA,CAAU,CACTA,CAAAA,CACAa,CAAAA,CACAkC,IAGAL,CAAAA,CAAS1C,CAAAA,CAAmCa,CAAAA,CAAKkC,CAAQ,CAC3D,CACD","file":"index.js","sourcesContent":["/**\n * Vue Adapter - Vue 3 composables for Directive\n *\n * Exports: useFact, useDerived, useDispatch, useSelector,\n * useWatch, useInspect, useRequirementStatus, useEvents, useExplain,\n * useConstraintStatus, useOptimisticUpdate, useDirective, useTimeTravel,\n * createTypedHooks, shallowEqual\n */\n\nimport {\n\tcomputed,\n\tonScopeDispose,\n\tref,\n\tshallowRef,\n\ttype ComputedRef,\n\ttype Ref,\n\ttype ShallowRef,\n} from \"vue\";\nimport type {\n\tModuleSchema,\n\tModuleDef,\n\tPlugin,\n\tDebugConfig,\n\tErrorBoundaryConfig,\n\tInferFacts,\n\tInferDerivations,\n\tInferSelectorState,\n\tInferEvents,\n\tSingleModuleSystem,\n\tSystemSnapshot,\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// 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): Ref<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[]): ShallowRef<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): Ref<unknown> | ShallowRef<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 _useFactSingle(system, keyOrKeys);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactSingle(system: SingleModuleSystem<any>, factKey: string): Ref<unknown> {\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] useFact(\"${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\tconst value = ref(system.facts.$store.get(factKey));\n\tconst unsubscribe = system.facts.$store.subscribe([factKey], () => {\n\t\tvalue.value = system.facts.$store.get(factKey);\n\t});\n\tonScopeDispose(unsubscribe);\n\treturn value;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useFactMulti(system: SingleModuleSystem<any>, factKeys: string[]): ShallowRef<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\tconst state = shallowRef(getValues());\n\tconst unsubscribe = system.facts.$store.subscribe(factKeys, () => {\n\t\tstate.value = getValues();\n\t});\n\tonScopeDispose(unsubscribe);\n\treturn state;\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): Ref<InferDerivations<S>[K]>;\n/** Multi-key overload */\nexport function useDerived<S extends ModuleSchema, K extends keyof InferDerivations<S> & string>(system: SingleModuleSystem<S>, derivationIds: K[]): ShallowRef<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): Ref<unknown> | ShallowRef<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 _useDerivedMulti(system, idOrIds);\n\t}\n\n\t// Single key path\n\treturn _useDerivedSingle(system, idOrIds);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useDerivedSingle(system: SingleModuleSystem<any>, derivationId: string): Ref<unknown> {\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] useDerived(\"${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\tconst value = ref(system.read(derivationId));\n\tconst unsubscribe = system.subscribe([derivationId], () => {\n\t\tvalue.value = system.read(derivationId);\n\t});\n\tonScopeDispose(unsubscribe);\n\treturn value;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: Internal\nfunction _useDerivedMulti(system: SingleModuleSystem<any>, derivationIds: string[]): ShallowRef<Record<string, unknown>> {\n\tconst getValues = (): Record<string, unknown> => {\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;\n\t};\n\tconst state = shallowRef(getValues());\n\tconst unsubscribe = system.subscribe(derivationIds, () => {\n\t\tstate.value = getValues();\n\t});\n\tonScopeDispose(unsubscribe);\n\treturn state;\n}\n\n// ============================================================================\n// useSelector — auto-tracking selector over facts and derivations\n// ============================================================================\n\n/**\n * Auto-tracking selector over facts and derivations.\n * Uses `withTracking()` to detect which facts the selector accesses,\n * then subscribes only to those keys.\n */\nexport function useSelector<S extends ModuleSchema, R>(system: SingleModuleSystem<S>, selector: (state: InferSelectorState<S>) => R, equalityFn?: (a: R, b: R) => boolean): Ref<R>;\nexport function useSelector<R>(\n\t// biome-ignore lint/suspicious/noExplicitAny: Backward-compatible fallback\n\tsystem: SingleModuleSystem<any>,\n\t// biome-ignore lint/suspicious/noExplicitAny: Selector receives dynamic state\n\tselector: (state: Record<string, any>) => R,\n\tequalityFn?: (a: R, b: R) => boolean,\n): Ref<R>;\nexport function useSelector(\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tsystem: SingleModuleSystem<any>,\n\tselector: (state: Record<string, unknown>) => unknown,\n\tequalityFn: (a: unknown, b: unknown) => boolean = defaultEquality,\n): Ref<unknown> {\n\tassertSystem(\"useSelector\", system);\n\tconst deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n\tconst runWithTracking = () => runTrackedSelector(system, deriveKeySet, selector);\n\n\tconst initial = runWithTracking();\n\tlet trackedFactKeys = initial.factKeys;\n\tlet trackedDeriveKeys = initial.deriveKeys;\n\tconst selected = ref(initial.value);\n\n\tconst unsubs: Array<() => void> = [];\n\n\tconst resubscribe = () => {\n\t\tfor (const unsub of unsubs) unsub();\n\t\tunsubs.length = 0;\n\n\t\tconst onUpdate = () => {\n\t\t\tconst result = runWithTracking();\n\t\t\tif (!equalityFn(selected.value, result.value)) {\n\t\t\t\tselected.value = result.value;\n\t\t\t}\n\t\t\t// Re-track: check if deps changed\n\t\t\tif (depsChanged(trackedFactKeys, result.factKeys, trackedDeriveKeys, result.deriveKeys)) {\n\t\t\t\ttrackedFactKeys = result.factKeys;\n\t\t\t\ttrackedDeriveKeys = result.deriveKeys;\n\t\t\t\tresubscribe();\n\t\t\t}\n\t\t};\n\n\t\tif (trackedFactKeys.length > 0) {\n\t\t\tunsubs.push(system.facts.$store.subscribe(trackedFactKeys, onUpdate));\n\t\t} else if (trackedDeriveKeys.length === 0) {\n\t\t\tunsubs.push(system.facts.$store.subscribeAll(onUpdate));\n\t\t}\n\t\tif (trackedDeriveKeys.length > 0) {\n\t\t\tunsubs.push(system.subscribe(trackedDeriveKeys, onUpdate));\n\t\t}\n\t};\n\n\tresubscribe();\n\n\tonScopeDispose(() => {\n\t\tfor (const unsub of unsubs) unsub();\n\t});\n\n\treturn selected;\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/**\n * Watch a fact by explicit \"fact\" discriminator.\n * @deprecated Use `useWatch(system, key, callback)` instead — facts are now auto-detected.\n */\nexport function useWatch<S extends ModuleSchema, K extends keyof InferFacts<S> & string>(\n\tsystem: SingleModuleSystem<S>,\n\tkind: \"fact\",\n\tfactKey: K,\n\tcallback: (newValue: InferFacts<S>[K] | undefined, previousValue: InferFacts<S>[K] | undefined) => void,\n): void;\n/** Watch a fact or derivation (generic fallback) */\nexport function useWatch<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: Backward-compatible fallback\n\tsystem: SingleModuleSystem<any>,\n\tkey: string,\n\tcallback: (newValue: T, previousValue: T | undefined) => void,\n): void;\n/** Implementation */\nexport function useWatch(\n\t// biome-ignore lint/suspicious/noExplicitAny: Implementation signature\n\tsystem: SingleModuleSystem<any>,\n\tderivationIdOrKind: string,\n\tcallbackOrFactKey: string | ((newValue: unknown, prevValue: unknown) => void),\n\tmaybeCallback?: (newValue: unknown, prevValue: unknown) => void,\n): void {\n\tassertSystem(\"useWatch\", system);\n\t// Backward compat: useWatch(system, \"fact\", factKey, callback)\n\tconst isFact =\n\t\tderivationIdOrKind === \"fact\" &&\n\t\ttypeof callbackOrFactKey === \"string\" &&\n\t\ttypeof maybeCallback === \"function\";\n\n\tconst key = isFact ? (callbackOrFactKey as string) : derivationIdOrKind;\n\tconst callback = isFact\n\t\t? maybeCallback!\n\t\t: (callbackOrFactKey as (newValue: unknown, prevValue: unknown) => void);\n\n\tconst unsubscribe = system.watch(key, callback);\n\tonScopeDispose(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 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): ShallowRef<InspectState> {\n\tassertSystem(\"useInspect\", system);\n\tconst state = shallowRef<InspectState>(computeInspectState(system));\n\n\tconst update = () => {\n\t\tstate.value = computeInspectState(system);\n\t};\n\n\tif (options?.throttleMs && options.throttleMs > 0) {\n\t\tconst { throttled, cleanup } = createThrottle(update, options.throttleMs);\n\t\tconst unsubFacts = system.facts.$store.subscribeAll(throttled);\n\t\tconst unsubSettled = system.onSettledChange(throttled);\n\t\tonScopeDispose(() => {\n\t\t\tcleanup();\n\t\t\tunsubFacts();\n\t\t\tunsubSettled();\n\t\t});\n\t} else {\n\t\tconst unsubFacts = system.facts.$store.subscribeAll(update);\n\t\tconst unsubSettled = system.onSettledChange(update);\n\t\tonScopeDispose(() => {\n\t\t\tunsubFacts();\n\t\t\tunsubSettled();\n\t\t});\n\t}\n\n\treturn state;\n}\n\n// ============================================================================\n// useRequirementStatus — single or multi\n// ============================================================================\n\n/** Single type overload */\nexport function useRequirementStatus(statusPlugin: StatusPlugin, type: string): ShallowRef<RequirementTypeStatus>;\n/** Multi-type overload */\nexport function useRequirementStatus(statusPlugin: StatusPlugin, types: string[]): ShallowRef<Record<string, RequirementTypeStatus>>;\n/** Implementation */\nexport function useRequirementStatus(\n\tstatusPlugin: StatusPlugin,\n\ttypeOrTypes: string | string[],\n): ShallowRef<RequirementTypeStatus> | ShallowRef<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\t\tconst state = shallowRef(getValues());\n\t\tconst unsubscribe = statusPlugin.subscribe(() => {\n\t\t\tstate.value = getValues();\n\t\t});\n\t\tonScopeDispose(unsubscribe);\n\t\treturn state;\n\t}\n\n\tconst status = shallowRef<RequirementTypeStatus>(statusPlugin.getStatus(typeOrTypes));\n\tconst unsubscribe = statusPlugin.subscribe(() => {\n\t\tstatus.value = statusPlugin.getStatus(typeOrTypes);\n\t});\n\tonScopeDispose(unsubscribe);\n\treturn status;\n}\n\n// ============================================================================\n// useExplain — reactive requirement explanation\n// ============================================================================\n\n/**\n * Reactively returns the explanation string for a requirement.\n */\nexport function useExplain(\n\t// biome-ignore lint/suspicious/noExplicitAny: Must work with any schema\n\tsystem: SingleModuleSystem<any>,\n\trequirementId: string,\n): Ref<string | null> {\n\tassertSystem(\"useExplain\", system);\n\tconst explanation = ref<string | null>(system.explain(requirementId)) as Ref<string | null>;\n\n\tconst update = () => {\n\t\texplanation.value = system.explain(requirementId);\n\t};\n\n\tconst unsubFacts = system.facts.$store.subscribeAll(update);\n\tconst unsubSettled = system.onSettledChange(update);\n\tonScopeDispose(() => {\n\t\tunsubFacts();\n\t\tunsubSettled();\n\t});\n\n\treturn explanation;\n}\n\n// ============================================================================\n// useConstraintStatus — reactive constraint inspection\n// ============================================================================\n\n/** Get all constraints */\nexport function useConstraintStatus(\n\tsystem: SingleModuleSystem<any>,\n): ComputedRef<ConstraintInfo[]>;\n/** Get a single constraint by ID */\nexport function useConstraintStatus(\n\tsystem: SingleModuleSystem<any>,\n\tconstraintId: string,\n): ComputedRef<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): ComputedRef<ConstraintInfo[] | ConstraintInfo | null> {\n\tassertSystem(\"useConstraintStatus\", system);\n\tconst inspectState = useInspect(system);\n\n\treturn computed(() => {\n\t\t// Track reactivity via inspectState, but use full inspect() for constraint list\n\t\tvoid inspectState.value;\n\t\tconst fullInspection = system.inspect();\n\t\tif (!constraintId) return fullInspection.constraints;\n\t\treturn fullInspection.constraints.find((c) => c.id === constraintId) ?? null;\n\t});\n}\n\n// ============================================================================\n// useOptimisticUpdate — batch with rollback on failure\n// ============================================================================\n\nexport interface OptimisticUpdateResult {\n\tmutate: (updateFn: () => void) => void;\n\tisPending: Ref<boolean>;\n\terror: Ref<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\tconst isPending = ref(false);\n\tconst error = ref<Error | null>(null) as Ref<Error | null>;\n\tlet snapshot: SystemSnapshot | null = null;\n\tlet unsubscribe: (() => void) | null = null;\n\n\tconst rollback = () => {\n\t\tif (snapshot) {\n\t\t\tsystem.restore(snapshot);\n\t\t\tsnapshot = null;\n\t\t}\n\t\tisPending.value = false;\n\t\terror.value = null;\n\t\tunsubscribe?.();\n\t\tunsubscribe = null;\n\t};\n\n\tconst mutate = (updateFn: () => void) => {\n\t\tsnapshot = system.getSnapshot();\n\t\tisPending.value = true;\n\t\terror.value = null;\n\t\tsystem.batch(updateFn);\n\n\t\t// Watch for resolver completion/failure\n\t\tif (statusPlugin && requirementType) {\n\t\t\tunsubscribe?.();\n\t\t\tunsubscribe = 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\tisPending.value = false;\n\t\t\t\t\tunsubscribe?.();\n\t\t\t\t\tunsubscribe = null;\n\t\t\t\t} else if (status.hasError) {\n\t\t\t\t\terror.value = status.lastError;\n\t\t\t\t\trollback();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t};\n\n\tonScopeDispose(() => {\n\t\tunsubscribe?.();\n\t});\n\n\treturn { mutate, isPending, error, rollback };\n}\n\n// ============================================================================\n// useTimeTravel — reactive time-travel state\n// ============================================================================\n\n/**\n * Reactive time-travel composable. Returns a ShallowRef that updates\n * when snapshots are taken or navigation occurs.\n *\n * @example\n * ```vue\n * const tt = useTimeTravel(system);\n * <button :disabled=\"!tt.value?.canUndo\" @click=\"tt.value?.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): ShallowRef<ReturnType<typeof buildTimeTravelState>> {\n\tassertSystem(\"useTimeTravel\", system);\n\tconst state = shallowRef<ReturnType<typeof buildTimeTravelState>>(buildTimeTravelState(system));\n\tconst unsub = system.onTimeTravelChange(() => {\n\t\tstate.value = buildTimeTravelState(system);\n\t});\n\tonScopeDispose(unsub);\n\treturn state;\n}\n\n// ============================================================================\n// Scoped System Composable\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 reactive state.\n *\n * @example\n * ```vue\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\tonScopeDispose(() => {\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 factsState = shallowRef(\n\t\tsubscribeAll\n\t\t\t? (system.facts.$store.toObject() as InferFacts<M>)\n\t\t\t: pickFacts(system, factKeys ?? []),\n\t);\n\tconst unsubFacts = subscribeAll\n\t\t? system.facts.$store.subscribeAll(() => {\n\t\t\tfactsState.value = system.facts.$store.toObject() as InferFacts<M>;\n\t\t})\n\t\t: factKeys && factKeys.length > 0\n\t\t\t? system.facts.$store.subscribe(factKeys, () => {\n\t\t\t\tfactsState.value = pickFacts(system, factKeys) as InferFacts<M>;\n\t\t\t})\n\t\t\t: null;\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 derivedState = shallowRef(getDerived());\n\tconst unsubDerived = allDerivationKeys.length > 0\n\t\t? system.subscribe(allDerivationKeys, () => { derivedState.value = getDerived(); })\n\t\t: null;\n\n\tonScopeDispose(() => {\n\t\tunsubFacts?.();\n\t\tunsubDerived?.();\n\t});\n\n\tconst events = system.events;\n\tconst dispatch = (event: InferEvents<M>) => system.dispatch(event);\n\n\treturn {\n\t\tsystem,\n\t\tfacts: factsState as ShallowRef<InferFacts<M>>,\n\t\tderived: derivedState as ShallowRef<InferDerivations<M>>,\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) => Ref<InferFacts<M>[K] | undefined>;\n\tuseDerived: <K extends keyof InferDerivations<M> & string>(\n\t\tsystem: SingleModuleSystem<M>,\n\t\tderivationId: K,\n\t) => Ref<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: Type narrowing for internal call\n\t\t\tuseFact(system as SingleModuleSystem<any>, factKey) as Ref<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: Type narrowing for internal call\n\t\t\tuseDerived(system as SingleModuleSystem<any>, derivationId) as Ref<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: Type narrowing for internal call\n\t\t\tuseWatch(system as SingleModuleSystem<any>, key, callback),\n\t};\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@directive-run/vue",
3
+ "version": "0.1.1",
4
+ "description": "Vue composition API adapter for Directive.",
5
+ "license": "MIT",
6
+ "author": "Jason Comes",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/directive-run/directive",
10
+ "directory": "packages/vue"
11
+ },
12
+ "homepage": "https://directive.run",
13
+ "bugs": {
14
+ "url": "https://github.com/directive-run/directive/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public",
18
+ "registry": "https://registry.npmjs.org"
19
+ },
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "keywords": [
24
+ "directive",
25
+ "vue",
26
+ "composition-api",
27
+ "state-management",
28
+ "reactive",
29
+ "constraint-driven"
30
+ ],
31
+ "sideEffects": false,
32
+ "type": "module",
33
+ "main": "./dist/index.cjs",
34
+ "module": "./dist/index.js",
35
+ "types": "./dist/index.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "types": "./dist/index.d.ts",
39
+ "require": "./dist/index.cjs",
40
+ "import": "./dist/index.js"
41
+ }
42
+ },
43
+ "files": [
44
+ "dist"
45
+ ],
46
+ "peerDependencies": {
47
+ "vue": ">=3",
48
+ "@directive-run/core": "0.1.1"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^25.2.0",
52
+ "vue": "^3.4.0",
53
+ "tsup": "^8.3.5",
54
+ "typescript": "^5.7.2",
55
+ "@directive-run/core": "0.1.1"
56
+ },
57
+ "scripts": {
58
+ "build": "tsup",
59
+ "dev": "tsup --watch",
60
+ "test": "vitest run",
61
+ "typecheck": "tsc --noEmit",
62
+ "clean": "rm -rf dist"
63
+ }
64
+ }