@directive-run/lit 1.11.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -2
- package/dist/index.d.ts +51 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
'use strict';var core=require('@directive-run/core'),adapterUtils=require('@directive-run/core/adapter-utils');var l=typeof process<"u"&&process.env?.NODE_ENV!=="production";var
|
|
1
|
+
'use strict';var core=require('@directive-run/core'),adapterUtils=require('@directive-run/core/adapter-utils');var l=typeof process<"u"&&process.env?.NODE_ENV!=="production";var N=Symbol("directive"),a=class{host;system;unsubscribe;constructor(e,t){this.host=e,this.system=t,e.addController(this);}hostConnected(){this.subscribe();}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}requestUpdate(){this.host.requestUpdate();}},h=class extends a{keys;isMulti;value;constructor(e,t,i){super(e,t),this.isMulti=Array.isArray(i),this.keys=this.isMulti?i:[i],this.value=this.getValues(),l&&!this.isMulti&&this.value===void 0&&console.warn(`[Directive] DerivedController("${this.keys[0]}") returned undefined. Check that "${this.keys[0]}" is defined in your module's derive property.`);}getValues(){if(this.isMulti){let e={};for(let t of this.keys)e[t]=this.system.read(t);return e}return this.system.read(this.keys[0])}subscribe(){this.value=this.getValues(),this.unsubscribe=this.system.subscribe(this.keys,()=>{this.value=this.getValues(),this.requestUpdate();});}},v=class extends a{factKey;value;constructor(e,t,i){super(e,t),this.factKey=i,this.value=t.facts.$store.get(i),l&&(t.facts.$store.has(i)||console.warn(`[Directive] FactController("${i}") \u2014 fact not found in store. Check that "${i}" is defined in your module's schema.`));}subscribe(){this.value=this.system.facts.$store.get(this.factKey),this.unsubscribe=this.system.facts.$store.subscribe([this.factKey],()=>{this.value=this.system.facts.$store.get(this.factKey),this.requestUpdate();});}},y=class extends a{value;throttleMs;throttleCleanup;unsubSettled;constructor(e,t,i){super(e,t),this.throttleMs=i?.throttleMs??0,this.value=adapterUtils.computeInspectState(t);}subscribe(){this.value=adapterUtils.computeInspectState(this.system);let e=()=>{this.value=adapterUtils.computeInspectState(this.system),this.requestUpdate();};if(this.throttleMs>0){let{throttled:t,cleanup:i}=adapterUtils.createThrottle(e,this.throttleMs);this.throttleCleanup=i,this.unsubscribe=this.system.facts.$store.subscribeAll(t),this.unsubSettled=this.system.onSettledChange(t);}else this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.throttleCleanup?.(),this.unsubSettled?.(),super.hostDisconnected();}},p=class{host;statusPlugin;type;unsubscribe;value;constructor(e,t,i){this.host=e,this.statusPlugin=t,this.type=i,this.value=t.getStatus(i),e.addController(this);}hostConnected(){this.value=this.statusPlugin.getStatus(this.type),this.unsubscribe=this.statusPlugin.subscribe(()=>{this.value=this.statusPlugin.getStatus(this.type),this.host.requestUpdate();});}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}},m=class extends a{selector;equalityFn;autoTrack;deriveKeySet;trackedFactKeys=[];trackedDeriveKeys=[];unsubs=[];value;constructor(e,t,i,n=adapterUtils.defaultEquality,r){super(e,t),this.selector=i,this.equalityFn=n,this.autoTrack=r?.autoTrack??true,this.deriveKeySet=new Set(Object.keys(t.derive??{}));let o=this.runWithTracking();this.value=o.value,this.trackedFactKeys=o.factKeys,this.trackedDeriveKeys=o.deriveKeys;}runWithTracking(){return adapterUtils.runTrackedSelector(this.system,this.deriveKeySet,this.selector)}resubscribe(){for(let t of this.unsubs)t();this.unsubs=[];let e=()=>{let t=this.runWithTracking();this.equalityFn(this.value,t.value)||(this.value=t.value,this.requestUpdate()),this.autoTrack&&adapterUtils.depsChanged(this.trackedFactKeys,t.factKeys,this.trackedDeriveKeys,t.deriveKeys)&&(this.trackedFactKeys=t.factKeys,this.trackedDeriveKeys=t.deriveKeys,this.resubscribe());};this.autoTrack?(this.trackedFactKeys.length>0?this.unsubs.push(this.system.facts.$store.subscribe(this.trackedFactKeys,e)):this.trackedDeriveKeys.length===0&&this.unsubs.push(this.system.facts.$store.subscribeAll(e)),this.trackedDeriveKeys.length>0&&this.unsubs.push(this.system.subscribe(this.trackedDeriveKeys,e))):this.unsubs.push(this.system.facts.$store.subscribeAll(e));}subscribe(){let e=this.runWithTracking();this.value=e.value,this.trackedFactKeys=e.factKeys,this.trackedDeriveKeys=e.deriveKeys,this.resubscribe();}hostDisconnected(){for(let e of this.unsubs)e();this.unsubs=[],super.hostDisconnected();}},g=class extends a{key;callback;constructor(e,t,i,n){super(e,t),this.key=i,this.callback=n;}subscribe(){this.unsubscribe=this.system.watch(this.key,this.callback);}},f=class extends a{requirementId;value;unsubSettled;constructor(e,t,i){super(e,t),this.requirementId=i,this.value=t.explain(i);}subscribe(){this.value=this.system.explain(this.requirementId);let e=()=>{this.value=this.system.explain(this.requirementId),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},S=class extends a{constraintId;value;unsubSettled;constructor(e,t,i){super(e,t),this.constraintId=i,this.value=this.getVal();}getVal(){let e=this.system.inspect();return this.constraintId?e.constraints.find(t=>t.id===this.constraintId)??null:e.constraints}subscribe(){this.value=this.getVal();let e=()=>{this.value=this.getVal(),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},b=class{host;system;statusPlugin;requirementType;snapshot=null;statusUnsub=null;isPending=false;error=null;constructor(e,t,i,n){this.host=e,this.system=t,this.statusPlugin=i,this.requirementType=n,e.addController(this);}hostConnected(){}hostDisconnected(){this.statusUnsub?.(),this.statusUnsub=null;}rollback(){this.snapshot&&(this.system.restore(this.snapshot),this.snapshot=null),this.isPending=false,this.error=null,this.statusUnsub?.(),this.statusUnsub=null,this.host.requestUpdate();}mutate(e){this.snapshot=this.system.getSnapshot(),this.isPending=true,this.error=null,this.system.batch(e),this.host.requestUpdate(),this.statusPlugin&&this.requirementType&&(this.statusUnsub?.(),this.statusUnsub=this.statusPlugin.subscribe(()=>{let t=this.statusPlugin.getStatus(this.requirementType);!t.isLoading&&!t.hasError?(this.snapshot=null,this.isPending=false,this.statusUnsub?.(),this.statusUnsub=null,this.host.requestUpdate()):t.hasError&&(this.error=t.lastError,this.rollback());}));}},k=class{options;_system=null;constructor(e,t){this.options=t,e.addController(this);}get system(){if(!this._system)throw new Error(`[Directive] SystemController.system is not available. This can happen if:
|
|
2
2
|
1. Accessed before hostConnected (e.g., in a class field initializer)
|
|
3
3
|
2. Accessed after hostDisconnected (system was destroyed)
|
|
4
|
-
Solution: Access system only in lifecycle methods (connectedCallback, render) or after the element is connected to the DOM.`);return this._system}hostConnected(){let t="id"in this.options&&"schema"in this.options?core.createSystem({module:this.options}):core.createSystem(this.options);this._system=t,this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},M=class{host;moduleDef;config;_system=null;unsubFacts;unsubDerived;facts={};derived={};statusPlugin;get system(){if(!this._system)throw new Error("[Directive] ModuleController.system is not available before hostConnected.");return this._system}get events(){return this.system.events}constructor(e,t,i){this.host=e,this.moduleDef=t,this.config=i,e.addController(this);}hostConnected(){let e=[...this.config?.plugins??[]];if(this.config?.status){let
|
|
4
|
+
Solution: Access system only in lifecycle methods (connectedCallback, render) or after the element is connected to the DOM.`);return this._system}hostConnected(){let t="id"in this.options&&"schema"in this.options?core.createSystem({module:this.options}):core.createSystem(this.options);this._system=t,this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},M=class{host;moduleDef;config;_system=null;unsubFacts;unsubDerived;facts={};derived={};statusPlugin;get system(){if(!this._system)throw new Error("[Directive] ModuleController.system is not available before hostConnected.");return this._system}get events(){return this.system.events}constructor(e,t,i){this.host=e,this.moduleDef=t,this.config=i,e.addController(this);}hostConnected(){let e=[...this.config?.plugins??[]];if(this.config?.status){let r=core.createRequirementStatusPlugin();this.statusPlugin=r,e.push(r.plugin);}let t=core.createSystem({module:this.moduleDef,plugins:e.length>0?e:void 0,trace:this.config?.trace,errorBoundary:this.config?.errorBoundary,tickMs:this.config?.tickMs,zeroConfig:this.config?.zeroConfig,initialFacts:this.config?.initialFacts});this._system=t,t.start(),this.facts=t.facts.$store.toObject(),this.unsubFacts=t.facts.$store.subscribeAll(()=>{this.facts=t.facts.$store.toObject(),this.host.requestUpdate();});let i=Object.keys(t.derive??{}),n=()=>{let r={};for(let o of i)r[o]=t.read(o);return r};this.derived=n(),i.length>0&&(this.unsubDerived=t.subscribe(i,()=>{this.derived=n(),this.host.requestUpdate();}));}hostDisconnected(){this.unsubFacts?.(),this.unsubDerived?.(),this._system?.destroy(),this._system=null;}dispatch(e){this.system.dispatch(e);}};function _(s,e,t){return new h(s,e,t)}function E(s,e,t){return new v(s,e,t)}function z(s,e,t){return new y(s,e,t)}function W(s,e,t){return new p(s,e,t)}function U(s,e,t,i){return new g(s,e,t,i)}function L(s,e,t,i=adapterUtils.defaultEquality,n){return new m(s,e,t,i,n)}function j(s,e,t){return new f(s,e,t)}function Q(s,e,t){return new S(s,e,t)}function J(s,e,t,i){return new b(s,e,t,i)}function G(s,e,t){return new M(s,e,t)}function X(s){return adapterUtils.assertSystem("useDispatch",s),e=>{s.dispatch(e);}}function Y(s){return adapterUtils.assertSystem("useEvents",s),s.events}var D=class{constructor(e,t){this._host=e;this._system=t;this._host.addController(this);}value=null;_unsub;hostConnected(){this.value=adapterUtils.buildHistoryState(this._system),this._unsub=this._system.onHistoryChange(()=>{this.value=adapterUtils.buildHistoryState(this._system),this._host.requestUpdate();});}hostDisconnected(){this._unsub?.(),this._unsub=void 0;}};function Z(s){return adapterUtils.assertSystem("useHistory",s),adapterUtils.buildHistoryState(s)}function ee(s,e){return ()=>s.read(e)}function te(s,e){return ()=>s.facts.$store.get(e)}function se(){return {createDerived:(s,e,t)=>_(s,e,t),createFact:(s,e,t)=>E(s,e,t),useDispatch:s=>e=>{s.dispatch(e);},useEvents:s=>s.events,createWatch:(s,e,t,i)=>U(s,e,t,i)}}var C=class{host;system;keys;selector;unsubscribe;value;constructor(e,t,i,n){this.host=e,this.system=t,this.keys=i,this.selector=n,this.value=n(t),e.addController(this);}hostConnected(){this.value=this.selector(this.system),this.unsubscribe=this.system.subscribe(this.keys,()=>{this.value=this.selector(this.system),this.host.requestUpdate();});}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}};function ie(s,e,t,i){return new C(s,e,t,i)}var T=class{_system=null;factory;constructor(e,t){this.factory=t,e.addController(this);}get system(){if(!this._system)throw new Error("[Directive] QuerySystemController.system is not available. Access it only in lifecycle methods or after the element is connected.");return this._system}hostConnected(){this._system=this.factory(),this._system.isRunning||this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},x=class{snapshot;systems=[];constructor(e,t){this.snapshot=t,e.addController(this);}hostConnected(){}hostDisconnected(){for(let e of this.systems)e.destroy();this.systems=[];}createSystem(e,t){let i=adapterUtils.mergeHydrationFacts(this.snapshot,t?.initialFacts),n=core.createSystem({module:e,plugins:t?.plugins,trace:t?.trace,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:i});return this.systems.push(n),typeof window<"u"&&n.start(),n}},I=class{host;ledger;filter;pollMs;intervalId=null;value;constructor(e,t,i={},n={}){this.host=e,this.ledger=t,this.filter=i;let r=n.pollMs??250;if(this.pollMs=Math.max(50,r),l&&(n.pollMs!==void 0&&n.pollMs<50&&console.warn(`[Directive] AuditLedgerController pollMs=${n.pollMs} is below the 50 ms floor; clamped to 50 ms.`),this.pollMs<100)){let o=t.toJSON().entries.length;o>1e3&&console.warn(`[Directive] AuditLedgerController polling every ${this.pollMs} ms against a ${o}-entry ledger \u2014 that's a lot of CPU per tick. Consider raising pollMs or tightening the filter.`);}this.value=t.query(i),e.addController(this);}hostConnected(){this.intervalId=setInterval(()=>{let e=this.ledger.query(this.filter),t=e[0]?.seq!==this.value[0]?.seq||e[e.length-1]?.seq!==this.value[this.value.length-1]?.seq;this.value=e,t&&this.host.requestUpdate();},this.pollMs);}hostDisconnected(){this.intervalId!==null&&(clearInterval(this.intervalId),this.intervalId=null);}};Object.defineProperty(exports,"shallowEqual",{enumerable:true,get:function(){return adapterUtils.shallowEqual}});exports.AuditLedgerController=I;exports.ConstraintStatusController=S;exports.DerivedController=h;exports.DirectiveSelectorController=m;exports.ExplainController=f;exports.FactController=v;exports.HistoryController=D;exports.HydrationController=x;exports.InspectController=y;exports.ModuleController=M;exports.NamespacedSelectorController=C;exports.OptimisticUpdateController=b;exports.QuerySystemController=T;exports.RequirementStatusController=p;exports.SystemController=k;exports.WatchController=g;exports.createConstraintStatus=Q;exports.createDerived=_;exports.createDirectiveSelector=L;exports.createExplain=j;exports.createFact=E;exports.createInspect=z;exports.createModule=G;exports.createNamespacedSelector=ie;exports.createOptimisticUpdate=J;exports.createRequirementStatus=W;exports.createTypedHooks=se;exports.createWatch=U;exports.directiveContext=N;exports.getDerived=ee;exports.getFact=te;exports.useDispatch=X;exports.useEvents=Y;exports.useHistory=Z;//# sourceMappingURL=index.cjs.map
|
|
5
5
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dev-true.ts","../src/index.ts"],"names":["dev_true_default","directiveContext","DirectiveController","host","system","DerivedController","key","result","id","FactController","factKey","InspectController","options","computeInspectState","update","throttled","cleanup","createThrottle","RequirementStatusController","statusPlugin","type","DirectiveSelectorController","selector","equalityFn","defaultEquality","initial","runTrackedSelector","unsub","onUpdate","depsChanged","WatchController","callback","ExplainController","requirementId","ConstraintStatusController","constraintId","inspection","c","OptimisticUpdateController","requirementType","updateFn","status","SystemController","createSystem","ModuleController","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","derivationKeys","getDerived","event","createDerived","createFact","createInspect","createRequirementStatus","createWatch","derivationId","createDirectiveSelector","createExplain","createConstraintStatus","createOptimisticUpdate","createModule","useDispatch","assertSystem","useEvents","HistoryController","_host","_system","buildHistoryState","useHistory","getFact","createTypedHooks","NamespacedSelectorController","keys","createNamespacedSelector","QuerySystemController","factory","HydrationController","snapshot","mergedFacts","mergeHydrationFacts"],"mappings":"+GAAA,IAAOA,CAAAA,CAAQ,OAAO,OAAA,CAAY,GAAA,EAChC,QAAQ,GAAA,EAAK,QAAA,GAAa,YAAA,CCmErB,IAAMC,CAAAA,CAAmB,MAAA,CAAO,WAAW,CAAA,CASnCC,CAAAA,CAAf,KAAiE,CACrD,IAAA,CAEA,MAAA,CACA,WAAA,CAGV,WAAA,CAAYC,CAAAA,CAA8BC,EAAiC,CACzE,IAAA,CAAK,IAAA,CAAOD,CAAAA,CACZ,IAAA,CAAK,MAAA,CAASC,CAAAA,CACdD,CAAAA,CAAK,cAAc,IAAI,EACzB,CAEA,aAAA,EAAsB,CACpB,IAAA,CAAK,SAAA,GACP,CAEA,gBAAA,EAAyB,CACvB,IAAA,CAAK,WAAA,IAAc,CACnB,IAAA,CAAK,WAAA,CAAc,OACrB,CAIU,aAAA,EAAsB,CAC9B,IAAA,CAAK,IAAA,CAAK,aAAA,GACZ,CACF,EAYaE,CAAAA,CAAN,cAAmCH,CAAoB,CACpD,IAAA,CACA,OAAA,CACR,KAAA,CAEA,WAAA,CACEC,EAEAC,CAAAA,CACAE,CAAAA,CACA,CACA,KAAA,CAAMH,CAAAA,CAAMC,CAAM,CAAA,CAClB,IAAA,CAAK,QAAU,KAAA,CAAM,OAAA,CAAQE,CAAG,CAAA,CAChC,IAAA,CAAK,IAAA,CAAO,IAAA,CAAK,OAAA,CAAWA,CAAAA,CAAmB,CAACA,CAAa,CAAA,CAC7D,IAAA,CAAK,KAAA,CAAQ,IAAA,CAAK,SAAA,GAEdN,CAAAA,EACE,CAAC,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,CACjB,KAAA,CAAOA,CAAAA,EAAQ,KAAA,CACf,cAAeA,CAAAA,EAAQ,aAAA,CACvB,OAAQA,CAAAA,EAAQ,MAAA,CAChB,WAAYA,CAAAA,EAAQ,UAAA,CACpB,YAAA,CAAcmC,CAChB,CAAQ,CAAA,CAER,YAAK,OAAA,CAAQ,IAAA,CAAK7E,CAAM,CAAA,CAEpB,OAAO,MAAA,CAAW,KACpBA,CAAAA,CAAO,KAAA,EAAM,CAGRA,CACT,CACF","file":"index.cjs","sourcesContent":["export default typeof process !== \"undefined\" &&\n process.env?.NODE_ENV !== \"production\";\n","/**\n * Lit Adapter - Consolidated Web Components integration for Directive\n *\n * Controllers: DerivedController, FactController,\n * InspectController (with throttle), RequirementStatusController,\n * DirectiveSelectorController,\n * WatchController (with fact mode), SystemController,\n * ExplainController, ConstraintStatusController, OptimisticUpdateController, ModuleController\n *\n * Factories: createDerived, createFact, createInspect,\n * createRequirementStatus, createWatch,\n * createDirectiveSelector, useDispatch, useEvents, useHistory,\n * getDerived, getFact, createTypedHooks, shallowEqual\n */\n\nimport type {\n CreateSystemOptionsSingle,\n ErrorBoundaryConfig,\n HistoryState,\n InferDerivations,\n InferEvents,\n InferFacts,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemSnapshot,\n TraceOption,\n} from \"@directive-run/core\";\nimport {\n createRequirementStatusPlugin,\n createSystem,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n type ConstraintInfo,\n type InspectState,\n type TrackedSelectorResult,\n assertSystem,\n buildHistoryState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n mergeHydrationFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport type { ReactiveController, ReactiveControllerHost } from \"lit\";\nimport isDevelopment from \"#is-development\";\n\n// Re-export for convenience\nexport type { RequirementTypeStatus, InspectState, ConstraintInfo };\nexport { shallowEqual };\n\n/** Type for the requirement status plugin return value */\nexport type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;\n\n// ============================================================================\n// Context\n// ============================================================================\n\n/**\n * Context key for Directive system.\n * Use with @lit/context for dependency injection across shadow DOM boundaries.\n */\nexport const directiveContext = Symbol(\"directive\");\n\n// ============================================================================\n// Base Controller\n// ============================================================================\n\n/**\n * Base controller that manages system subscription lifecycle.\n */\nabstract class DirectiveController implements ReactiveController {\n protected host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n protected system: SingleModuleSystem<any>;\n protected unsubscribe?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>) {\n this.host = host;\n this.system = system;\n host.addController(this);\n }\n\n hostConnected(): void {\n this.subscribe();\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n\n protected abstract subscribe(): void;\n\n protected requestUpdate(): void {\n this.host.requestUpdate();\n }\n}\n\n// ============================================================================\n// Core Controllers\n// ============================================================================\n\n/**\n * Reactive controller for derivations.\n * Accepts a single key (string) or an array of keys (string[]).\n * - Single key: `.value` returns `T`\n * - Array of keys: `.value` returns `Record<string, unknown>`\n */\nexport class DerivedController<T> extends DirectiveController {\n private keys: string[];\n private isMulti: boolean;\n value: T;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n ) {\n super(host, system);\n this.isMulti = Array.isArray(key);\n this.keys = this.isMulti ? (key as string[]) : [key as string];\n this.value = this.getValues();\n\n if (isDevelopment) {\n if (!this.isMulti && this.value === undefined) {\n console.warn(\n `[Directive] DerivedController(\"${this.keys[0]}\") returned undefined. ` +\n `Check that \"${this.keys[0]}\" is defined in your module's derive property.`,\n );\n }\n }\n }\n\n private getValues(): T {\n if (this.isMulti) {\n const result: Record<string, unknown> = {};\n for (const id of this.keys) {\n result[id] = this.system.read(id);\n }\n return result as T;\n }\n return this.system.read(this.keys[0]!) as T;\n }\n\n protected subscribe(): void {\n this.value = this.getValues();\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.getValues();\n this.requestUpdate();\n });\n }\n}\n\n/**\n * Reactive controller for a single fact value.\n */\nexport class FactController<T> extends DirectiveController {\n private factKey: string;\n value: T | undefined;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n ) {\n super(host, system);\n this.factKey = factKey;\n this.value = system.facts.$store.get(factKey) as T | undefined;\n\n if (isDevelopment) {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] FactController(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n }\n\n protected subscribe(): void {\n this.value = this.system.facts.$store.get(this.factKey) as T | undefined;\n this.unsubscribe = this.system.facts.$store.subscribe(\n [this.factKey],\n () => {\n this.value = this.system.facts.$store.get(this.factKey) as\n | T\n | undefined;\n this.requestUpdate();\n },\n );\n }\n}\n\n/**\n * Consolidated inspection controller.\n * Returns InspectState with optional throttling.\n */\nexport class InspectController extends DirectiveController {\n value: InspectState;\n private throttleMs: number;\n private throttleCleanup?: () => void;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n ) {\n super(host, system);\n this.throttleMs = options?.throttleMs ?? 0;\n this.value = computeInspectState(system);\n }\n\n protected subscribe(): void {\n this.value = computeInspectState(this.system);\n\n const update = () => {\n this.value = computeInspectState(this.system);\n this.requestUpdate();\n };\n\n if (this.throttleMs > 0) {\n const { throttled, cleanup } = createThrottle(update, this.throttleMs);\n this.throttleCleanup = cleanup;\n this.unsubscribe = this.system.facts.$store.subscribeAll(throttled);\n this.unsubSettled = this.system.onSettledChange(throttled);\n } else {\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n }\n\n hostDisconnected(): void {\n this.throttleCleanup?.();\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for requirement status.\n */\nexport class RequirementStatusController implements ReactiveController {\n private host: ReactiveControllerHost;\n private statusPlugin: StatusPlugin;\n private type: string;\n private unsubscribe?: () => void;\n value: RequirementTypeStatus;\n\n constructor(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n ) {\n this.host = host;\n this.statusPlugin = statusPlugin;\n this.type = type;\n this.value = statusPlugin.getStatus(type);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.statusPlugin.getStatus(this.type);\n this.unsubscribe = this.statusPlugin.subscribe(() => {\n this.value = this.statusPlugin.getStatus(this.type);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\n// ============================================================================\n// Selector Controllers\n// ============================================================================\n\n/**\n * Reactive controller for selecting across all facts.\n * Uses `withTracking()` for auto-tracking when constructed with `autoTrack: true`.\n */\nexport class DirectiveSelectorController<R> extends DirectiveController {\n private selector: (state: Record<string, unknown>) => R;\n private equalityFn: (a: R, b: R) => boolean;\n private autoTrack: boolean;\n private deriveKeySet: Set<string>;\n private trackedFactKeys: string[] = [];\n private trackedDeriveKeys: string[] = [];\n private unsubs: Array<() => void> = [];\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n ) {\n super(host, system);\n this.selector = selector;\n this.equalityFn = equalityFn;\n this.autoTrack = options?.autoTrack ?? true;\n this.deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n const initial = this.runWithTracking();\n this.value = initial.value;\n this.trackedFactKeys = initial.factKeys;\n this.trackedDeriveKeys = initial.deriveKeys;\n }\n\n private runWithTracking(): TrackedSelectorResult<R> {\n return runTrackedSelector(this.system, this.deriveKeySet, this.selector);\n }\n\n private resubscribe(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n\n const onUpdate = () => {\n const result = this.runWithTracking();\n if (!this.equalityFn(this.value, result.value)) {\n this.value = result.value;\n this.requestUpdate();\n }\n if (this.autoTrack) {\n // Re-track: check if deps changed\n if (\n depsChanged(\n this.trackedFactKeys,\n result.factKeys,\n this.trackedDeriveKeys,\n result.deriveKeys,\n )\n ) {\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n }\n };\n\n if (this.autoTrack) {\n if (this.trackedFactKeys.length > 0) {\n this.unsubs.push(\n this.system.facts.$store.subscribe(this.trackedFactKeys, onUpdate),\n );\n } else if (this.trackedDeriveKeys.length === 0) {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n if (this.trackedDeriveKeys.length > 0) {\n this.unsubs.push(\n this.system.subscribe(this.trackedDeriveKeys, onUpdate),\n );\n }\n } else {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n }\n\n protected subscribe(): void {\n const result = this.runWithTracking();\n this.value = result.value;\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n\n hostDisconnected(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller that watches a fact or derivation and calls a callback on change.\n * The key is auto-detected — works with both fact keys and derivation keys.\n */\nexport class WatchController<T> extends DirectiveController {\n private key: string;\n private callback: (newValue: T, previousValue: T | undefined) => void;\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. */\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n ) {\n super(host, system);\n this.key = key;\n this.callback = callback;\n }\n\n protected subscribe(): void {\n this.unsubscribe = this.system.watch<T>(this.key, this.callback);\n }\n}\n\n// ============================================================================\n// New Controllers\n// ============================================================================\n\n/**\n * Reactive controller for requirement explanations.\n */\nexport class ExplainController extends DirectiveController {\n private requirementId: string;\n value: string | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n requirementId: string,\n ) {\n super(host, system);\n this.requirementId = requirementId;\n this.value = system.explain(requirementId);\n }\n\n protected subscribe(): void {\n this.value = this.system.explain(this.requirementId);\n\n const update = () => {\n this.value = this.system.explain(this.requirementId);\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for constraint status.\n */\nexport class ConstraintStatusController extends DirectiveController {\n private constraintId?: string;\n value: ConstraintInfo[] | ConstraintInfo | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n constraintId?: string,\n ) {\n super(host, system);\n this.constraintId = constraintId;\n this.value = this.getVal();\n }\n\n private getVal(): ConstraintInfo[] | ConstraintInfo | null {\n const inspection = this.system.inspect();\n if (!this.constraintId) return inspection.constraints;\n return (\n inspection.constraints.find(\n (c: ConstraintInfo) => c.id === this.constraintId,\n ) ?? null\n );\n }\n\n protected subscribe(): void {\n this.value = this.getVal();\n\n const update = () => {\n this.value = this.getVal();\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for optimistic updates.\n */\nexport class OptimisticUpdateController implements ReactiveController {\n private host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private system: SingleModuleSystem<any>;\n private statusPlugin?: StatusPlugin;\n private requirementType?: string;\n private snapshot: SystemSnapshot | null = null;\n private statusUnsub: (() => void) | null = null;\n\n isPending = false;\n error: Error | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n ) {\n this.host = host;\n this.system = system;\n this.statusPlugin = statusPlugin;\n this.requirementType = requirementType;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n this.statusUnsub?.();\n this.statusUnsub = null;\n }\n\n rollback(): void {\n if (this.snapshot) {\n this.system.restore(this.snapshot);\n this.snapshot = null;\n }\n this.isPending = false;\n this.error = null;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n }\n\n mutate(updateFn: () => void): void {\n this.snapshot = this.system.getSnapshot();\n this.isPending = true;\n this.error = null;\n this.system.batch(updateFn);\n this.host.requestUpdate();\n\n if (this.statusPlugin && this.requirementType) {\n this.statusUnsub?.();\n this.statusUnsub = this.statusPlugin.subscribe(() => {\n const status = this.statusPlugin!.getStatus(this.requirementType!);\n if (!status.isLoading && !status.hasError) {\n this.snapshot = null;\n this.isPending = false;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n } else if (status.hasError) {\n this.error = status.lastError;\n this.rollback();\n }\n });\n }\n }\n}\n\n/**\n * Reactive controller that creates and manages a Directive system.\n * The system is automatically started when the host connects and destroyed when it disconnects.\n */\nexport class SystemController<M extends ModuleSchema>\n implements ReactiveController\n{\n private options: ModuleDef<M> | CreateSystemOptionsSingle<M>;\n private _system: SingleModuleSystem<M> | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n options: ModuleDef<M> | CreateSystemOptionsSingle<M>,\n ) {\n this.options = options;\n host.addController(this);\n }\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] SystemController.system is not available. \" +\n \"This can happen if:\\n\" +\n \" 1. Accessed before hostConnected (e.g., in a class field initializer)\\n\" +\n \" 2. Accessed after hostDisconnected (system was destroyed)\\n\" +\n \"Solution: Access system only in lifecycle methods (connectedCallback, render) \" +\n \"or after the element is connected to the DOM.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n const isModule = \"id\" in this.options && \"schema\" in this.options;\n const system = isModule\n ? createSystem({ module: this.options as ModuleDef<M> })\n : createSystem(this.options as CreateSystemOptionsSingle<M>);\n this._system = system as unknown as SingleModuleSystem<M>;\n this._system.start();\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n/**\n * Module controller — zero-config all-in-one.\n * Creates system, starts it, subscribes to all facts/derivations.\n */\nexport class ModuleController<M extends ModuleSchema>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private moduleDef: ModuleDef<M>;\n private config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n };\n\n private _system: SingleModuleSystem<M> | null = null;\n private unsubFacts?: () => void;\n private unsubDerived?: () => void;\n\n facts: InferFacts<M> = {} as InferFacts<M>;\n derived: InferDerivations<M> = {} as InferDerivations<M>;\n statusPlugin?: StatusPlugin;\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] ModuleController.system is not available before hostConnected.\",\n );\n }\n return this._system;\n }\n\n get events(): SingleModuleSystem<M>[\"events\"] {\n return this.system.events;\n }\n\n constructor(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n ) {\n this.host = host;\n this.moduleDef = moduleDef;\n this.config = config;\n host.addController(this);\n }\n\n hostConnected(): void {\n const allPlugins = [...(this.config?.plugins ?? [])];\n\n if (this.config?.status) {\n const sp = createRequirementStatusPlugin();\n this.statusPlugin = sp;\n // biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n allPlugins.push(sp.plugin as Plugin<any>);\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: this.moduleDef,\n plugins: allPlugins.length > 0 ? allPlugins : undefined,\n trace: this.config?.trace,\n errorBoundary: this.config?.errorBoundary,\n tickMs: this.config?.tickMs,\n zeroConfig: this.config?.zeroConfig,\n initialFacts: this.config?.initialFacts,\n } as any) as unknown as SingleModuleSystem<M>;\n\n this._system = system;\n system.start();\n\n // Subscribe to all facts\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.unsubFacts = system.facts.$store.subscribeAll(() => {\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.host.requestUpdate();\n });\n\n // Subscribe to all derivations\n const derivationKeys = Object.keys(system.derive ?? {});\n const getDerived = (): InferDerivations<M> => {\n const result: Record<string, unknown> = {};\n for (const key of derivationKeys) {\n result[key] = system.read(key);\n }\n return result as InferDerivations<M>;\n };\n this.derived = getDerived();\n\n if (derivationKeys.length > 0) {\n this.unsubDerived = system.subscribe(derivationKeys, () => {\n this.derived = getDerived();\n this.host.requestUpdate();\n });\n }\n }\n\n hostDisconnected(): void {\n this.unsubFacts?.();\n this.unsubDerived?.();\n this._system?.destroy();\n this._system = null;\n }\n\n dispatch(event: InferEvents<M>): void {\n this.system.dispatch(event);\n }\n}\n\n// ============================================================================\n// Factory Functions (active)\n// ============================================================================\n\nexport function createDerived<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n): DerivedController<T> {\n return new DerivedController<T>(host, system, key);\n}\n\nexport function createFact<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): FactController<T> {\n return new FactController<T>(host, system, factKey);\n}\n\n/**\n * Create an inspect controller.\n * Returns InspectState; pass `{ throttleMs }` for throttled updates.\n */\nexport function createInspect(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n): InspectController {\n return new InspectController(host, system, options);\n}\n\nexport function createRequirementStatus(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n): RequirementStatusController {\n return new RequirementStatusController(host, statusPlugin, type);\n}\n\nexport function createWatch<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n): WatchController<T> {\n return new WatchController<T>(host, system, derivationId, callback);\n}\n\nexport function createDirectiveSelector<R>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n): DirectiveSelectorController<R> {\n return new DirectiveSelectorController<R>(\n host,\n system,\n selector,\n equalityFn,\n options,\n );\n}\n\nexport function createExplain(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n requirementId: string,\n): ExplainController {\n return new ExplainController(host, system, requirementId);\n}\n\nexport function createConstraintStatus(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): ConstraintStatusController {\n return new ConstraintStatusController(host, system, constraintId);\n}\n\nexport function createOptimisticUpdate(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n): OptimisticUpdateController {\n return new OptimisticUpdateController(\n host,\n system,\n statusPlugin,\n requirementType,\n );\n}\n\nexport function createModule<M extends ModuleSchema>(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n): ModuleController<M> {\n return new ModuleController<M>(host, moduleDef, config);\n}\n\n// ============================================================================\n// Functional Helpers\n// ============================================================================\n\nexport function useDispatch<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): (event: InferEvents<M>) => void {\n assertSystem(\"useDispatch\", system);\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n}\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): SingleModuleSystem<M>[\"events\"] {\n assertSystem(\"useEvents\", system);\n return system.events;\n}\n\n/**\n * Reactive controller for history state.\n * Triggers host updates when snapshots change or navigation occurs.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private _history = new HistoryController(this, system);\n * render() {\n * const h = this._history.value;\n * return html`<button ?disabled=${!h?.canGoBack} @click=${() => h?.goBack()}>Undo</button>`;\n * }\n * }\n * ```\n */\nexport class HistoryController implements ReactiveController {\n value: HistoryState | null = null;\n private _unsub?: () => void;\n\n constructor(\n private _host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: SingleModuleSystem<any>,\n ) {\n this._host.addController(this);\n }\n\n hostConnected(): void {\n this.value = buildHistoryState(this._system);\n this._unsub = this._system.onHistoryChange(() => {\n this.value = buildHistoryState(this._system);\n this._host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this._unsub?.();\n this._unsub = undefined;\n }\n}\n\n/**\n * Functional helper for history state (non-reactive, snapshot).\n * For reactive updates, use HistoryController.\n */\n// biome-ignore lint/suspicious/noExplicitAny: System type varies\nexport function useHistory(\n system: SingleModuleSystem<any>,\n): HistoryState | null {\n assertSystem(\"useHistory\", system);\n return buildHistoryState(system);\n}\n\nexport function getDerived<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n): () => T {\n return () => system.read(derivationId) as T;\n}\n\nexport function getFact<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): () => T | undefined {\n return () => system.facts.$store.get(factKey) as T | undefined;\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => DerivedController<InferDerivations<M>[K]>;\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => FactController<InferFacts<M>[K]>;\n useDispatch: (\n system: SingleModuleSystem<M>,\n ) => (event: InferEvents<M>) => void;\n useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => WatchController<unknown>;\n} {\n return {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) =>\n createDerived<InferDerivations<M>[K]>(\n host,\n system,\n derivationId as string,\n ),\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => createFact<InferFacts<M>[K]>(host, system, factKey as string),\n useDispatch: (system: SingleModuleSystem<M>) => {\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n },\n useEvents: (system: SingleModuleSystem<M>) => system.events,\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => createWatch<unknown>(host, system, key, callback),\n };\n}\n\n// ============================================================================\n// NamespacedSelectorController — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * Reactive controller that selects from a NamespacedSystem.\n * Subscribes to specified keys and triggers host updates.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private token = new NamespacedSelectorController(\n * this, system, [\"auth.token\"], (s) => s.facts.auth.token,\n * );\n * render() {\n * return html`<span>${this.token.value}</span>`;\n * }\n * }\n * ```\n */\nexport class NamespacedSelectorController<Modules extends ModulesMap, R>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private system: NamespacedSystem<Modules>;\n private keys: string[];\n private selector: (system: NamespacedSystem<Modules>) => R;\n private unsubscribe?: () => void;\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n ) {\n this.host = host;\n this.system = system;\n this.keys = keys;\n this.selector = selector;\n this.value = selector(system);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.selector(this.system);\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.selector(this.system);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\nexport function createNamespacedSelector<Modules extends ModulesMap, R>(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n): NamespacedSelectorController<Modules, R> {\n return new NamespacedSelectorController(host, system, keys, selector);\n}\n\n// ============================================================================\n// QuerySystemController — Stable query system with Lit lifecycle\n// ============================================================================\n\n/**\n * Lit reactive controller that creates and manages a query system.\n * Starts on connect, destroys on disconnect.\n *\n * @example\n * ```typescript\n * import { LitElement, html } from \"lit\";\n * import { QuerySystemController } from \"@directive-run/lit\";\n * import { createQuerySystem } from \"@directive-run/query\";\n *\n * class MyApp extends LitElement {\n * private app = new QuerySystemController(this, () =>\n * createQuerySystem({\n * facts: { userId: \"\" },\n * queries: { user: { key: ..., fetcher: ... } },\n * autoStart: false,\n * })\n * );\n *\n * render() {\n * const user = this.app.system.read(\"user\");\n * return html`<div>${user.data?.name}</div>`;\n * }\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nexport class QuerySystemController<\n T extends {\n start: () => void;\n destroy: () => void;\n isRunning?: boolean;\n [key: string]: any;\n },\n> implements ReactiveController\n{\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: T | null = null;\n private factory: () => T;\n\n constructor(host: ReactiveControllerHost, factory: () => T) {\n this.factory = factory;\n host.addController(this);\n }\n\n get system(): T {\n if (!this._system) {\n throw new Error(\n \"[Directive] QuerySystemController.system is not available. \" +\n \"Access it only in lifecycle methods or after the element is connected.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n this._system = this.factory();\n if (!this._system.isRunning) {\n this._system.start();\n }\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n// ============================================================================\n// SSR Hydration\n// ============================================================================\n\n/**\n * Lit reactive controller for SSR hydration.\n * Accepts a DistributableSnapshot and creates a hydrated system.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private hydration = new HydrationController(this, serverSnapshot);\n * private system = this.hydration.createSystem(myModule);\n * }\n * ```\n */\nexport class HydrationController implements ReactiveController {\n private snapshot: Record<string, unknown> | undefined;\n // biome-ignore lint/suspicious/noExplicitAny: Systems vary by module schema\n private systems: SingleModuleSystem<any>[] = [];\n\n constructor(\n host: ReactiveControllerHost,\n snapshot?: Record<string, unknown>,\n ) {\n this.snapshot = snapshot;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n for (const system of this.systems) {\n system.destroy();\n }\n this.systems = [];\n }\n\n createSystem<S extends ModuleSchema>(\n moduleDef: ModuleDef<S>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n },\n ): SingleModuleSystem<S> {\n const mergedFacts = mergeHydrationFacts(\n this.snapshot,\n config?.initialFacts,\n );\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: moduleDef,\n plugins: config?.plugins,\n trace: config?.trace,\n errorBoundary: config?.errorBoundary,\n tickMs: config?.tickMs,\n zeroConfig: config?.zeroConfig,\n initialFacts: mergedFacts,\n } as any) as unknown as SingleModuleSystem<S>;\n\n this.systems.push(system);\n\n if (typeof window !== \"undefined\") {\n system.start();\n }\n\n return system;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/dev-true.ts","../src/index.ts"],"names":["dev_true_default","directiveContext","DirectiveController","host","system","DerivedController","key","result","id","FactController","factKey","InspectController","options","computeInspectState","update","throttled","cleanup","createThrottle","RequirementStatusController","statusPlugin","type","DirectiveSelectorController","selector","equalityFn","defaultEquality","initial","runTrackedSelector","unsub","onUpdate","depsChanged","WatchController","callback","ExplainController","requirementId","ConstraintStatusController","constraintId","inspection","c","OptimisticUpdateController","requirementType","updateFn","status","SystemController","createSystem","ModuleController","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","derivationKeys","getDerived","event","createDerived","createFact","createInspect","createRequirementStatus","createWatch","derivationId","createDirectiveSelector","createExplain","createConstraintStatus","createOptimisticUpdate","createModule","useDispatch","assertSystem","useEvents","HistoryController","_host","_system","buildHistoryState","useHistory","getFact","createTypedHooks","NamespacedSelectorController","keys","createNamespacedSelector","QuerySystemController","factory","HydrationController","snapshot","mergedFacts","mergeHydrationFacts","AuditLedgerController","ledger","filter","opts","requestedPollMs","entryCount","next","moved"],"mappings":"+GAAA,IAAOA,CAAAA,CAAQ,OAAO,OAAA,CAAY,GAAA,EAChC,QAAQ,GAAA,EAAK,QAAA,GAAa,YAAA,CCmErB,IAAMC,CAAAA,CAAmB,MAAA,CAAO,WAAW,CAAA,CASnCC,CAAAA,CAAf,KAAiE,CACrD,IAAA,CAEA,MAAA,CACA,WAAA,CAGV,WAAA,CAAYC,CAAAA,CAA8BC,EAAiC,CACzE,IAAA,CAAK,IAAA,CAAOD,CAAAA,CACZ,IAAA,CAAK,MAAA,CAASC,CAAAA,CACdD,CAAAA,CAAK,cAAc,IAAI,EACzB,CAEA,aAAA,EAAsB,CACpB,IAAA,CAAK,SAAA,GACP,CAEA,gBAAA,EAAyB,CACvB,IAAA,CAAK,WAAA,IAAc,CACnB,IAAA,CAAK,WAAA,CAAc,OACrB,CAIU,aAAA,EAAsB,CAC9B,IAAA,CAAK,IAAA,CAAK,aAAA,GACZ,CACF,EAYaE,CAAAA,CAAN,cAAmCH,CAAoB,CACpD,IAAA,CACA,OAAA,CACR,KAAA,CAEA,WAAA,CACEC,EAEAC,CAAAA,CACAE,CAAAA,CACA,CACA,KAAA,CAAMH,CAAAA,CAAMC,CAAM,CAAA,CAClB,IAAA,CAAK,QAAU,KAAA,CAAM,OAAA,CAAQE,CAAG,CA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AK,KAAA,CAAM,CAAC,CAAA,EAAG,GAAA,EAChCA,CAAAA,CAAKA,CAAAA,CAAK,MAAA,CAAS,CAAC,CAAA,EAAG,GAAA,GACrB,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,MAAA,CAAS,CAAC,CAAA,EAAG,GAAA,CACvC,IAAA,CAAK,KAAA,CAAQA,CAAAA,CACTC,CAAAA,EACF,IAAA,CAAK,IAAA,CAAK,aAAA,GAEd,CAAA,CAAG,IAAA,CAAK,MAAM,EAChB,CAEA,gBAAA,EAAyB,CACnB,IAAA,CAAK,UAAA,GAAe,IAAA,GACtB,aAAA,CAAc,IAAA,CAAK,UAAU,CAAA,CAC7B,IAAA,CAAK,UAAA,CAAa,IAAA,EAEtB,CACF","file":"index.cjs","sourcesContent":["export default typeof process !== \"undefined\" &&\n process.env?.NODE_ENV !== \"production\";\n","/**\n * Lit Adapter - Consolidated Web Components integration for Directive\n *\n * Controllers: DerivedController, FactController,\n * InspectController (with throttle), RequirementStatusController,\n * DirectiveSelectorController,\n * WatchController (with fact mode), SystemController,\n * ExplainController, ConstraintStatusController, OptimisticUpdateController, ModuleController\n *\n * Factories: createDerived, createFact, createInspect,\n * createRequirementStatus, createWatch,\n * createDirectiveSelector, useDispatch, useEvents, useHistory,\n * getDerived, getFact, createTypedHooks, shallowEqual\n */\n\nimport type {\n CreateSystemOptionsSingle,\n ErrorBoundaryConfig,\n HistoryState,\n InferDerivations,\n InferEvents,\n InferFacts,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemSnapshot,\n TraceOption,\n} from \"@directive-run/core\";\nimport {\n createRequirementStatusPlugin,\n createSystem,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n type ConstraintInfo,\n type InspectState,\n type TrackedSelectorResult,\n assertSystem,\n buildHistoryState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n mergeHydrationFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport type { ReactiveController, ReactiveControllerHost } from \"lit\";\nimport isDevelopment from \"#is-development\";\n\n// Re-export for convenience\nexport type { RequirementTypeStatus, InspectState, ConstraintInfo };\nexport { shallowEqual };\n\n/** Type for the requirement status plugin return value */\nexport type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;\n\n// ============================================================================\n// Context\n// ============================================================================\n\n/**\n * Context key for Directive system.\n * Use with @lit/context for dependency injection across shadow DOM boundaries.\n */\nexport const directiveContext = Symbol(\"directive\");\n\n// ============================================================================\n// Base Controller\n// ============================================================================\n\n/**\n * Base controller that manages system subscription lifecycle.\n */\nabstract class DirectiveController implements ReactiveController {\n protected host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n protected system: SingleModuleSystem<any>;\n protected unsubscribe?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>) {\n this.host = host;\n this.system = system;\n host.addController(this);\n }\n\n hostConnected(): void {\n this.subscribe();\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n\n protected abstract subscribe(): void;\n\n protected requestUpdate(): void {\n this.host.requestUpdate();\n }\n}\n\n// ============================================================================\n// Core Controllers\n// ============================================================================\n\n/**\n * Reactive controller for derivations.\n * Accepts a single key (string) or an array of keys (string[]).\n * - Single key: `.value` returns `T`\n * - Array of keys: `.value` returns `Record<string, unknown>`\n */\nexport class DerivedController<T> extends DirectiveController {\n private keys: string[];\n private isMulti: boolean;\n value: T;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n ) {\n super(host, system);\n this.isMulti = Array.isArray(key);\n this.keys = this.isMulti ? (key as string[]) : [key as string];\n this.value = this.getValues();\n\n if (isDevelopment) {\n if (!this.isMulti && this.value === undefined) {\n console.warn(\n `[Directive] DerivedController(\"${this.keys[0]}\") returned undefined. ` +\n `Check that \"${this.keys[0]}\" is defined in your module's derive property.`,\n );\n }\n }\n }\n\n private getValues(): T {\n if (this.isMulti) {\n const result: Record<string, unknown> = {};\n for (const id of this.keys) {\n result[id] = this.system.read(id);\n }\n return result as T;\n }\n return this.system.read(this.keys[0]!) as T;\n }\n\n protected subscribe(): void {\n this.value = this.getValues();\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.getValues();\n this.requestUpdate();\n });\n }\n}\n\n/**\n * Reactive controller for a single fact value.\n */\nexport class FactController<T> extends DirectiveController {\n private factKey: string;\n value: T | undefined;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n ) {\n super(host, system);\n this.factKey = factKey;\n this.value = system.facts.$store.get(factKey) as T | undefined;\n\n if (isDevelopment) {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] FactController(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n }\n\n protected subscribe(): void {\n this.value = this.system.facts.$store.get(this.factKey) as T | undefined;\n this.unsubscribe = this.system.facts.$store.subscribe(\n [this.factKey],\n () => {\n this.value = this.system.facts.$store.get(this.factKey) as\n | T\n | undefined;\n this.requestUpdate();\n },\n );\n }\n}\n\n/**\n * Consolidated inspection controller.\n * Returns InspectState with optional throttling.\n */\nexport class InspectController extends DirectiveController {\n value: InspectState;\n private throttleMs: number;\n private throttleCleanup?: () => void;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n ) {\n super(host, system);\n this.throttleMs = options?.throttleMs ?? 0;\n this.value = computeInspectState(system);\n }\n\n protected subscribe(): void {\n this.value = computeInspectState(this.system);\n\n const update = () => {\n this.value = computeInspectState(this.system);\n this.requestUpdate();\n };\n\n if (this.throttleMs > 0) {\n const { throttled, cleanup } = createThrottle(update, this.throttleMs);\n this.throttleCleanup = cleanup;\n this.unsubscribe = this.system.facts.$store.subscribeAll(throttled);\n this.unsubSettled = this.system.onSettledChange(throttled);\n } else {\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n }\n\n hostDisconnected(): void {\n this.throttleCleanup?.();\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for requirement status.\n */\nexport class RequirementStatusController implements ReactiveController {\n private host: ReactiveControllerHost;\n private statusPlugin: StatusPlugin;\n private type: string;\n private unsubscribe?: () => void;\n value: RequirementTypeStatus;\n\n constructor(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n ) {\n this.host = host;\n this.statusPlugin = statusPlugin;\n this.type = type;\n this.value = statusPlugin.getStatus(type);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.statusPlugin.getStatus(this.type);\n this.unsubscribe = this.statusPlugin.subscribe(() => {\n this.value = this.statusPlugin.getStatus(this.type);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\n// ============================================================================\n// Selector Controllers\n// ============================================================================\n\n/**\n * Reactive controller for selecting across all facts.\n * Uses `withTracking()` for auto-tracking when constructed with `autoTrack: true`.\n */\nexport class DirectiveSelectorController<R> extends DirectiveController {\n private selector: (state: Record<string, unknown>) => R;\n private equalityFn: (a: R, b: R) => boolean;\n private autoTrack: boolean;\n private deriveKeySet: Set<string>;\n private trackedFactKeys: string[] = [];\n private trackedDeriveKeys: string[] = [];\n private unsubs: Array<() => void> = [];\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n ) {\n super(host, system);\n this.selector = selector;\n this.equalityFn = equalityFn;\n this.autoTrack = options?.autoTrack ?? true;\n this.deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n const initial = this.runWithTracking();\n this.value = initial.value;\n this.trackedFactKeys = initial.factKeys;\n this.trackedDeriveKeys = initial.deriveKeys;\n }\n\n private runWithTracking(): TrackedSelectorResult<R> {\n return runTrackedSelector(this.system, this.deriveKeySet, this.selector);\n }\n\n private resubscribe(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n\n const onUpdate = () => {\n const result = this.runWithTracking();\n if (!this.equalityFn(this.value, result.value)) {\n this.value = result.value;\n this.requestUpdate();\n }\n if (this.autoTrack) {\n // Re-track: check if deps changed\n if (\n depsChanged(\n this.trackedFactKeys,\n result.factKeys,\n this.trackedDeriveKeys,\n result.deriveKeys,\n )\n ) {\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n }\n };\n\n if (this.autoTrack) {\n if (this.trackedFactKeys.length > 0) {\n this.unsubs.push(\n this.system.facts.$store.subscribe(this.trackedFactKeys, onUpdate),\n );\n } else if (this.trackedDeriveKeys.length === 0) {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n if (this.trackedDeriveKeys.length > 0) {\n this.unsubs.push(\n this.system.subscribe(this.trackedDeriveKeys, onUpdate),\n );\n }\n } else {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n }\n\n protected subscribe(): void {\n const result = this.runWithTracking();\n this.value = result.value;\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n\n hostDisconnected(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller that watches a fact or derivation and calls a callback on change.\n * The key is auto-detected — works with both fact keys and derivation keys.\n */\nexport class WatchController<T> extends DirectiveController {\n private key: string;\n private callback: (newValue: T, previousValue: T | undefined) => void;\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. */\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n ) {\n super(host, system);\n this.key = key;\n this.callback = callback;\n }\n\n protected subscribe(): void {\n this.unsubscribe = this.system.watch<T>(this.key, this.callback);\n }\n}\n\n// ============================================================================\n// New Controllers\n// ============================================================================\n\n/**\n * Reactive controller for requirement explanations.\n */\nexport class ExplainController extends DirectiveController {\n private requirementId: string;\n value: string | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n requirementId: string,\n ) {\n super(host, system);\n this.requirementId = requirementId;\n this.value = system.explain(requirementId);\n }\n\n protected subscribe(): void {\n this.value = this.system.explain(this.requirementId);\n\n const update = () => {\n this.value = this.system.explain(this.requirementId);\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for constraint status.\n */\nexport class ConstraintStatusController extends DirectiveController {\n private constraintId?: string;\n value: ConstraintInfo[] | ConstraintInfo | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n constraintId?: string,\n ) {\n super(host, system);\n this.constraintId = constraintId;\n this.value = this.getVal();\n }\n\n private getVal(): ConstraintInfo[] | ConstraintInfo | null {\n const inspection = this.system.inspect();\n if (!this.constraintId) return inspection.constraints;\n return (\n inspection.constraints.find(\n (c: ConstraintInfo) => c.id === this.constraintId,\n ) ?? null\n );\n }\n\n protected subscribe(): void {\n this.value = this.getVal();\n\n const update = () => {\n this.value = this.getVal();\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for optimistic updates.\n */\nexport class OptimisticUpdateController implements ReactiveController {\n private host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private system: SingleModuleSystem<any>;\n private statusPlugin?: StatusPlugin;\n private requirementType?: string;\n private snapshot: SystemSnapshot | null = null;\n private statusUnsub: (() => void) | null = null;\n\n isPending = false;\n error: Error | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n ) {\n this.host = host;\n this.system = system;\n this.statusPlugin = statusPlugin;\n this.requirementType = requirementType;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n this.statusUnsub?.();\n this.statusUnsub = null;\n }\n\n rollback(): void {\n if (this.snapshot) {\n this.system.restore(this.snapshot);\n this.snapshot = null;\n }\n this.isPending = false;\n this.error = null;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n }\n\n mutate(updateFn: () => void): void {\n this.snapshot = this.system.getSnapshot();\n this.isPending = true;\n this.error = null;\n this.system.batch(updateFn);\n this.host.requestUpdate();\n\n if (this.statusPlugin && this.requirementType) {\n this.statusUnsub?.();\n this.statusUnsub = this.statusPlugin.subscribe(() => {\n const status = this.statusPlugin!.getStatus(this.requirementType!);\n if (!status.isLoading && !status.hasError) {\n this.snapshot = null;\n this.isPending = false;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n } else if (status.hasError) {\n this.error = status.lastError;\n this.rollback();\n }\n });\n }\n }\n}\n\n/**\n * Reactive controller that creates and manages a Directive system.\n * The system is automatically started when the host connects and destroyed when it disconnects.\n */\nexport class SystemController<M extends ModuleSchema>\n implements ReactiveController\n{\n private options: ModuleDef<M> | CreateSystemOptionsSingle<M>;\n private _system: SingleModuleSystem<M> | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n options: ModuleDef<M> | CreateSystemOptionsSingle<M>,\n ) {\n this.options = options;\n host.addController(this);\n }\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] SystemController.system is not available. \" +\n \"This can happen if:\\n\" +\n \" 1. Accessed before hostConnected (e.g., in a class field initializer)\\n\" +\n \" 2. Accessed after hostDisconnected (system was destroyed)\\n\" +\n \"Solution: Access system only in lifecycle methods (connectedCallback, render) \" +\n \"or after the element is connected to the DOM.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n const isModule = \"id\" in this.options && \"schema\" in this.options;\n const system = isModule\n ? createSystem({ module: this.options as ModuleDef<M> })\n : createSystem(this.options as CreateSystemOptionsSingle<M>);\n this._system = system as unknown as SingleModuleSystem<M>;\n this._system.start();\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n/**\n * Module controller — zero-config all-in-one.\n * Creates system, starts it, subscribes to all facts/derivations.\n */\nexport class ModuleController<M extends ModuleSchema>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private moduleDef: ModuleDef<M>;\n private config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n };\n\n private _system: SingleModuleSystem<M> | null = null;\n private unsubFacts?: () => void;\n private unsubDerived?: () => void;\n\n facts: InferFacts<M> = {} as InferFacts<M>;\n derived: InferDerivations<M> = {} as InferDerivations<M>;\n statusPlugin?: StatusPlugin;\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] ModuleController.system is not available before hostConnected.\",\n );\n }\n return this._system;\n }\n\n get events(): SingleModuleSystem<M>[\"events\"] {\n return this.system.events;\n }\n\n constructor(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n ) {\n this.host = host;\n this.moduleDef = moduleDef;\n this.config = config;\n host.addController(this);\n }\n\n hostConnected(): void {\n const allPlugins = [...(this.config?.plugins ?? [])];\n\n if (this.config?.status) {\n const sp = createRequirementStatusPlugin();\n this.statusPlugin = sp;\n // biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n allPlugins.push(sp.plugin as Plugin<any>);\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: this.moduleDef,\n plugins: allPlugins.length > 0 ? allPlugins : undefined,\n trace: this.config?.trace,\n errorBoundary: this.config?.errorBoundary,\n tickMs: this.config?.tickMs,\n zeroConfig: this.config?.zeroConfig,\n initialFacts: this.config?.initialFacts,\n } as any) as unknown as SingleModuleSystem<M>;\n\n this._system = system;\n system.start();\n\n // Subscribe to all facts\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.unsubFacts = system.facts.$store.subscribeAll(() => {\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.host.requestUpdate();\n });\n\n // Subscribe to all derivations\n const derivationKeys = Object.keys(system.derive ?? {});\n const getDerived = (): InferDerivations<M> => {\n const result: Record<string, unknown> = {};\n for (const key of derivationKeys) {\n result[key] = system.read(key);\n }\n return result as InferDerivations<M>;\n };\n this.derived = getDerived();\n\n if (derivationKeys.length > 0) {\n this.unsubDerived = system.subscribe(derivationKeys, () => {\n this.derived = getDerived();\n this.host.requestUpdate();\n });\n }\n }\n\n hostDisconnected(): void {\n this.unsubFacts?.();\n this.unsubDerived?.();\n this._system?.destroy();\n this._system = null;\n }\n\n dispatch(event: InferEvents<M>): void {\n this.system.dispatch(event);\n }\n}\n\n// ============================================================================\n// Factory Functions (active)\n// ============================================================================\n\nexport function createDerived<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n): DerivedController<T> {\n return new DerivedController<T>(host, system, key);\n}\n\nexport function createFact<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): FactController<T> {\n return new FactController<T>(host, system, factKey);\n}\n\n/**\n * Create an inspect controller.\n * Returns InspectState; pass `{ throttleMs }` for throttled updates.\n */\nexport function createInspect(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n): InspectController {\n return new InspectController(host, system, options);\n}\n\nexport function createRequirementStatus(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n): RequirementStatusController {\n return new RequirementStatusController(host, statusPlugin, type);\n}\n\nexport function createWatch<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n): WatchController<T> {\n return new WatchController<T>(host, system, derivationId, callback);\n}\n\nexport function createDirectiveSelector<R>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n): DirectiveSelectorController<R> {\n return new DirectiveSelectorController<R>(\n host,\n system,\n selector,\n equalityFn,\n options,\n );\n}\n\nexport function createExplain(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n requirementId: string,\n): ExplainController {\n return new ExplainController(host, system, requirementId);\n}\n\nexport function createConstraintStatus(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): ConstraintStatusController {\n return new ConstraintStatusController(host, system, constraintId);\n}\n\nexport function createOptimisticUpdate(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n): OptimisticUpdateController {\n return new OptimisticUpdateController(\n host,\n system,\n statusPlugin,\n requirementType,\n );\n}\n\nexport function createModule<M extends ModuleSchema>(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n): ModuleController<M> {\n return new ModuleController<M>(host, moduleDef, config);\n}\n\n// ============================================================================\n// Functional Helpers\n// ============================================================================\n\nexport function useDispatch<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): (event: InferEvents<M>) => void {\n assertSystem(\"useDispatch\", system);\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n}\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): SingleModuleSystem<M>[\"events\"] {\n assertSystem(\"useEvents\", system);\n return system.events;\n}\n\n/**\n * Reactive controller for history state.\n * Triggers host updates when snapshots change or navigation occurs.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private _history = new HistoryController(this, system);\n * render() {\n * const h = this._history.value;\n * return html`<button ?disabled=${!h?.canGoBack} @click=${() => h?.goBack()}>Undo</button>`;\n * }\n * }\n * ```\n */\nexport class HistoryController implements ReactiveController {\n value: HistoryState | null = null;\n private _unsub?: () => void;\n\n constructor(\n private _host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: SingleModuleSystem<any>,\n ) {\n this._host.addController(this);\n }\n\n hostConnected(): void {\n this.value = buildHistoryState(this._system);\n this._unsub = this._system.onHistoryChange(() => {\n this.value = buildHistoryState(this._system);\n this._host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this._unsub?.();\n this._unsub = undefined;\n }\n}\n\n/**\n * Functional helper for history state (non-reactive, snapshot).\n * For reactive updates, use HistoryController.\n */\n// biome-ignore lint/suspicious/noExplicitAny: System type varies\nexport function useHistory(\n system: SingleModuleSystem<any>,\n): HistoryState | null {\n assertSystem(\"useHistory\", system);\n return buildHistoryState(system);\n}\n\nexport function getDerived<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n): () => T {\n return () => system.read(derivationId) as T;\n}\n\nexport function getFact<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): () => T | undefined {\n return () => system.facts.$store.get(factKey) as T | undefined;\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => DerivedController<InferDerivations<M>[K]>;\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => FactController<InferFacts<M>[K]>;\n useDispatch: (\n system: SingleModuleSystem<M>,\n ) => (event: InferEvents<M>) => void;\n useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => WatchController<unknown>;\n} {\n return {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) =>\n createDerived<InferDerivations<M>[K]>(\n host,\n system,\n derivationId as string,\n ),\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => createFact<InferFacts<M>[K]>(host, system, factKey as string),\n useDispatch: (system: SingleModuleSystem<M>) => {\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n },\n useEvents: (system: SingleModuleSystem<M>) => system.events,\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => createWatch<unknown>(host, system, key, callback),\n };\n}\n\n// ============================================================================\n// NamespacedSelectorController — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * Reactive controller that selects from a NamespacedSystem.\n * Subscribes to specified keys and triggers host updates.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private token = new NamespacedSelectorController(\n * this, system, [\"auth.token\"], (s) => s.facts.auth.token,\n * );\n * render() {\n * return html`<span>${this.token.value}</span>`;\n * }\n * }\n * ```\n */\nexport class NamespacedSelectorController<Modules extends ModulesMap, R>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private system: NamespacedSystem<Modules>;\n private keys: string[];\n private selector: (system: NamespacedSystem<Modules>) => R;\n private unsubscribe?: () => void;\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n ) {\n this.host = host;\n this.system = system;\n this.keys = keys;\n this.selector = selector;\n this.value = selector(system);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.selector(this.system);\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.selector(this.system);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\nexport function createNamespacedSelector<Modules extends ModulesMap, R>(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n): NamespacedSelectorController<Modules, R> {\n return new NamespacedSelectorController(host, system, keys, selector);\n}\n\n// ============================================================================\n// QuerySystemController — Stable query system with Lit lifecycle\n// ============================================================================\n\n/**\n * Lit reactive controller that creates and manages a query system.\n * Starts on connect, destroys on disconnect.\n *\n * @example\n * ```typescript\n * import { LitElement, html } from \"lit\";\n * import { QuerySystemController } from \"@directive-run/lit\";\n * import { createQuerySystem } from \"@directive-run/query\";\n *\n * class MyApp extends LitElement {\n * private app = new QuerySystemController(this, () =>\n * createQuerySystem({\n * facts: { userId: \"\" },\n * queries: { user: { key: ..., fetcher: ... } },\n * autoStart: false,\n * })\n * );\n *\n * render() {\n * const user = this.app.system.read(\"user\");\n * return html`<div>${user.data?.name}</div>`;\n * }\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nexport class QuerySystemController<\n T extends {\n start: () => void;\n destroy: () => void;\n isRunning?: boolean;\n [key: string]: any;\n },\n> implements ReactiveController\n{\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: T | null = null;\n private factory: () => T;\n\n constructor(host: ReactiveControllerHost, factory: () => T) {\n this.factory = factory;\n host.addController(this);\n }\n\n get system(): T {\n if (!this._system) {\n throw new Error(\n \"[Directive] QuerySystemController.system is not available. \" +\n \"Access it only in lifecycle methods or after the element is connected.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n this._system = this.factory();\n if (!this._system.isRunning) {\n this._system.start();\n }\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n// ============================================================================\n// SSR Hydration\n// ============================================================================\n\n/**\n * Lit reactive controller for SSR hydration.\n * Accepts a DistributableSnapshot and creates a hydrated system.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private hydration = new HydrationController(this, serverSnapshot);\n * private system = this.hydration.createSystem(myModule);\n * }\n * ```\n */\nexport class HydrationController implements ReactiveController {\n private snapshot: Record<string, unknown> | undefined;\n // biome-ignore lint/suspicious/noExplicitAny: Systems vary by module schema\n private systems: SingleModuleSystem<any>[] = [];\n\n constructor(\n host: ReactiveControllerHost,\n snapshot?: Record<string, unknown>,\n ) {\n this.snapshot = snapshot;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n for (const system of this.systems) {\n system.destroy();\n }\n this.systems = [];\n }\n\n createSystem<S extends ModuleSchema>(\n moduleDef: ModuleDef<S>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n },\n ): SingleModuleSystem<S> {\n const mergedFacts = mergeHydrationFacts(\n this.snapshot,\n config?.initialFacts,\n );\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: moduleDef,\n plugins: config?.plugins,\n trace: config?.trace,\n errorBoundary: config?.errorBoundary,\n tickMs: config?.tickMs,\n zeroConfig: config?.zeroConfig,\n initialFacts: mergedFacts,\n } as any) as unknown as SingleModuleSystem<S>;\n\n this.systems.push(system);\n\n if (typeof window !== \"undefined\") {\n system.start();\n }\n\n return system;\n }\n}\n\n// ============================================================================\n// AuditLedgerController — live ledger entries with filter (R4.I parity)\n// ============================================================================\n\nimport type {\n AuditEntry,\n AuditLedger,\n QueryFilter,\n} from \"@directive-run/core\";\n\n/**\n * Reactive controller exposing the latest audit-ledger entries matching\n * `filter` as `.value`. Polls (default 250 ms — override with `pollMs`)\n * and re-renders the host on each tick that brings new matches.\n *\n * **Polling floor:** `pollMs` is clamped to a minimum of 50 ms to prevent\n * accidental DoS from typos like `pollMs: 5`. Values below the floor are\n * silently clamped in production; dev mode logs a warning.\n *\n * @example\n * ```ts\n * import { AuditLedgerController } from \"@directive-run/lit\";\n *\n * class AuditLog extends LitElement {\n * private ledgerCtrl = new AuditLedgerController(\n * this,\n * ledger,\n * { kind: \"constraint.evaluate\", limit: 20 },\n * );\n *\n * render() {\n * return html`<ul>\n * ${this.ledgerCtrl.value.map(e => html`<li>${e.kind} @ ${e.ts}</li>`)}\n * </ul>`;\n * }\n * }\n * ```\n */\nexport class AuditLedgerController implements ReactiveController {\n private host: ReactiveControllerHost;\n private ledger: AuditLedger;\n private filter: QueryFilter;\n private pollMs: number;\n private intervalId: ReturnType<typeof setInterval> | null = null;\n\n /**\n * Latest matching audit entries. Updates on each poll tick when the\n * seq-window (first/last entry seq) changes. Lit `requestUpdate()` is\n * only called when the window moves — in-place tombstone replacement\n * within the visible window does NOT trigger re-render (use the ledger's\n * onWrite hook for revision-level updates when added).\n */\n value: readonly AuditEntry[];\n\n constructor(\n host: ReactiveControllerHost,\n ledger: AuditLedger,\n filter: QueryFilter = {},\n opts: { pollMs?: number } = {},\n ) {\n this.host = host;\n this.ledger = ledger;\n this.filter = filter;\n const requestedPollMs = opts.pollMs ?? 250;\n this.pollMs = Math.max(50, requestedPollMs);\n\n if (isDevelopment) {\n if (opts.pollMs !== undefined && opts.pollMs < 50) {\n console.warn(\n `[Directive] AuditLedgerController pollMs=${opts.pollMs} is below the 50 ms floor; clamped to 50 ms.`,\n );\n }\n if (this.pollMs < 100) {\n const entryCount = ledger.toJSON().entries.length;\n if (entryCount > 1000) {\n console.warn(\n `[Directive] AuditLedgerController polling every ${this.pollMs} ms against a ${entryCount}-entry ledger — that's a lot of CPU per tick. Consider raising pollMs or tightening the filter.`,\n );\n }\n }\n }\n\n this.value = ledger.query(filter);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.intervalId = setInterval(() => {\n const next = this.ledger.query(this.filter);\n // Always replace the array reference so consumers reading\n // `.value` see the latest snapshot, but only request a render\n // when the seq-window actually moved. At steady-state capacity\n // (e.g. 10k entries rolling over) the length is constant — using\n // length-diff alone misses every change. Compare the first and\n // last seq instead. (R4.C7)\n const moved =\n next[0]?.seq !== this.value[0]?.seq ||\n next[next.length - 1]?.seq !==\n this.value[this.value.length - 1]?.seq;\n this.value = next;\n if (moved) {\n this.host.requestUpdate();\n }\n }, this.pollMs);\n }\n\n hostDisconnected(): void {\n if (this.intervalId !== null) {\n clearInterval(this.intervalId);\n this.intervalId = null;\n }\n }\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SingleModuleSystem, HistoryState, ModuleSchema, ModuleDef, Plugin, TraceOption, ErrorBoundaryConfig, InferFacts, InferDerivations, createRequirementStatusPlugin, InferEvents, ModulesMap, NamespacedSystem, RequirementTypeStatus, CreateSystemOptionsSingle } from '@directive-run/core';
|
|
1
|
+
import { AuditEntry, AuditLedger, QueryFilter, SingleModuleSystem, HistoryState, ModuleSchema, ModuleDef, Plugin, TraceOption, ErrorBoundaryConfig, InferFacts, InferDerivations, createRequirementStatusPlugin, InferEvents, ModulesMap, NamespacedSystem, RequirementTypeStatus, CreateSystemOptionsSingle } from '@directive-run/core';
|
|
2
2
|
export { RequirementTypeStatus } from '@directive-run/core';
|
|
3
3
|
import { ConstraintInfo, InspectState } from '@directive-run/core/adapter-utils';
|
|
4
4
|
export { ConstraintInfo, InspectState, shallowEqual } from '@directive-run/core/adapter-utils';
|
|
@@ -368,4 +368,53 @@ declare class HydrationController implements ReactiveController {
|
|
|
368
368
|
}): SingleModuleSystem<S>;
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
-
|
|
371
|
+
/**
|
|
372
|
+
* Reactive controller exposing the latest audit-ledger entries matching
|
|
373
|
+
* `filter` as `.value`. Polls (default 250 ms — override with `pollMs`)
|
|
374
|
+
* and re-renders the host on each tick that brings new matches.
|
|
375
|
+
*
|
|
376
|
+
* **Polling floor:** `pollMs` is clamped to a minimum of 50 ms to prevent
|
|
377
|
+
* accidental DoS from typos like `pollMs: 5`. Values below the floor are
|
|
378
|
+
* silently clamped in production; dev mode logs a warning.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```ts
|
|
382
|
+
* import { AuditLedgerController } from "@directive-run/lit";
|
|
383
|
+
*
|
|
384
|
+
* class AuditLog extends LitElement {
|
|
385
|
+
* private ledgerCtrl = new AuditLedgerController(
|
|
386
|
+
* this,
|
|
387
|
+
* ledger,
|
|
388
|
+
* { kind: "constraint.evaluate", limit: 20 },
|
|
389
|
+
* );
|
|
390
|
+
*
|
|
391
|
+
* render() {
|
|
392
|
+
* return html`<ul>
|
|
393
|
+
* ${this.ledgerCtrl.value.map(e => html`<li>${e.kind} @ ${e.ts}</li>`)}
|
|
394
|
+
* </ul>`;
|
|
395
|
+
* }
|
|
396
|
+
* }
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
declare class AuditLedgerController implements ReactiveController {
|
|
400
|
+
private host;
|
|
401
|
+
private ledger;
|
|
402
|
+
private filter;
|
|
403
|
+
private pollMs;
|
|
404
|
+
private intervalId;
|
|
405
|
+
/**
|
|
406
|
+
* Latest matching audit entries. Updates on each poll tick when the
|
|
407
|
+
* seq-window (first/last entry seq) changes. Lit `requestUpdate()` is
|
|
408
|
+
* only called when the window moves — in-place tombstone replacement
|
|
409
|
+
* within the visible window does NOT trigger re-render (use the ledger's
|
|
410
|
+
* onWrite hook for revision-level updates when added).
|
|
411
|
+
*/
|
|
412
|
+
value: readonly AuditEntry[];
|
|
413
|
+
constructor(host: ReactiveControllerHost, ledger: AuditLedger, filter?: QueryFilter, opts?: {
|
|
414
|
+
pollMs?: number;
|
|
415
|
+
});
|
|
416
|
+
hostConnected(): void;
|
|
417
|
+
hostDisconnected(): void;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export { AuditLedgerController, ConstraintStatusController, DerivedController, DirectiveSelectorController, ExplainController, FactController, HistoryController, HydrationController, InspectController, ModuleController, NamespacedSelectorController, OptimisticUpdateController, QuerySystemController, RequirementStatusController, type StatusPlugin, SystemController, WatchController, createConstraintStatus, createDerived, createDirectiveSelector, createExplain, createFact, createInspect, createModule, createNamespacedSelector, createOptimisticUpdate, createRequirementStatus, createTypedHooks, createWatch, directiveContext, getDerived, getFact, useDispatch, useEvents, useHistory };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SingleModuleSystem, HistoryState, ModuleSchema, ModuleDef, Plugin, TraceOption, ErrorBoundaryConfig, InferFacts, InferDerivations, createRequirementStatusPlugin, InferEvents, ModulesMap, NamespacedSystem, RequirementTypeStatus, CreateSystemOptionsSingle } from '@directive-run/core';
|
|
1
|
+
import { AuditEntry, AuditLedger, QueryFilter, SingleModuleSystem, HistoryState, ModuleSchema, ModuleDef, Plugin, TraceOption, ErrorBoundaryConfig, InferFacts, InferDerivations, createRequirementStatusPlugin, InferEvents, ModulesMap, NamespacedSystem, RequirementTypeStatus, CreateSystemOptionsSingle } from '@directive-run/core';
|
|
2
2
|
export { RequirementTypeStatus } from '@directive-run/core';
|
|
3
3
|
import { ConstraintInfo, InspectState } from '@directive-run/core/adapter-utils';
|
|
4
4
|
export { ConstraintInfo, InspectState, shallowEqual } from '@directive-run/core/adapter-utils';
|
|
@@ -368,4 +368,53 @@ declare class HydrationController implements ReactiveController {
|
|
|
368
368
|
}): SingleModuleSystem<S>;
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
-
|
|
371
|
+
/**
|
|
372
|
+
* Reactive controller exposing the latest audit-ledger entries matching
|
|
373
|
+
* `filter` as `.value`. Polls (default 250 ms — override with `pollMs`)
|
|
374
|
+
* and re-renders the host on each tick that brings new matches.
|
|
375
|
+
*
|
|
376
|
+
* **Polling floor:** `pollMs` is clamped to a minimum of 50 ms to prevent
|
|
377
|
+
* accidental DoS from typos like `pollMs: 5`. Values below the floor are
|
|
378
|
+
* silently clamped in production; dev mode logs a warning.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```ts
|
|
382
|
+
* import { AuditLedgerController } from "@directive-run/lit";
|
|
383
|
+
*
|
|
384
|
+
* class AuditLog extends LitElement {
|
|
385
|
+
* private ledgerCtrl = new AuditLedgerController(
|
|
386
|
+
* this,
|
|
387
|
+
* ledger,
|
|
388
|
+
* { kind: "constraint.evaluate", limit: 20 },
|
|
389
|
+
* );
|
|
390
|
+
*
|
|
391
|
+
* render() {
|
|
392
|
+
* return html`<ul>
|
|
393
|
+
* ${this.ledgerCtrl.value.map(e => html`<li>${e.kind} @ ${e.ts}</li>`)}
|
|
394
|
+
* </ul>`;
|
|
395
|
+
* }
|
|
396
|
+
* }
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
declare class AuditLedgerController implements ReactiveController {
|
|
400
|
+
private host;
|
|
401
|
+
private ledger;
|
|
402
|
+
private filter;
|
|
403
|
+
private pollMs;
|
|
404
|
+
private intervalId;
|
|
405
|
+
/**
|
|
406
|
+
* Latest matching audit entries. Updates on each poll tick when the
|
|
407
|
+
* seq-window (first/last entry seq) changes. Lit `requestUpdate()` is
|
|
408
|
+
* only called when the window moves — in-place tombstone replacement
|
|
409
|
+
* within the visible window does NOT trigger re-render (use the ledger's
|
|
410
|
+
* onWrite hook for revision-level updates when added).
|
|
411
|
+
*/
|
|
412
|
+
value: readonly AuditEntry[];
|
|
413
|
+
constructor(host: ReactiveControllerHost, ledger: AuditLedger, filter?: QueryFilter, opts?: {
|
|
414
|
+
pollMs?: number;
|
|
415
|
+
});
|
|
416
|
+
hostConnected(): void;
|
|
417
|
+
hostDisconnected(): void;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export { AuditLedgerController, ConstraintStatusController, DerivedController, DirectiveSelectorController, ExplainController, FactController, HistoryController, HydrationController, InspectController, ModuleController, NamespacedSelectorController, OptimisticUpdateController, QuerySystemController, RequirementStatusController, type StatusPlugin, SystemController, WatchController, createConstraintStatus, createDerived, createDirectiveSelector, createExplain, createFact, createInspect, createModule, createNamespacedSelector, createOptimisticUpdate, createRequirementStatus, createTypedHooks, createWatch, directiveContext, getDerived, getFact, useDispatch, useEvents, useHistory };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {createSystem,createRequirementStatusPlugin}from'@directive-run/core';import {defaultEquality,computeInspectState,createThrottle,runTrackedSelector,assertSystem,buildHistoryState,mergeHydrationFacts,depsChanged}from'@directive-run/core/adapter-utils';export{shallowEqual}from'@directive-run/core/adapter-utils';var l=typeof process<"u"&&process.env?.NODE_ENV!=="production";var
|
|
1
|
+
import {createSystem,createRequirementStatusPlugin}from'@directive-run/core';import {defaultEquality,computeInspectState,createThrottle,runTrackedSelector,assertSystem,buildHistoryState,mergeHydrationFacts,depsChanged}from'@directive-run/core/adapter-utils';export{shallowEqual}from'@directive-run/core/adapter-utils';var l=typeof process<"u"&&process.env?.NODE_ENV!=="production";var N=Symbol("directive"),a=class{host;system;unsubscribe;constructor(e,t){this.host=e,this.system=t,e.addController(this);}hostConnected(){this.subscribe();}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}requestUpdate(){this.host.requestUpdate();}},h=class extends a{keys;isMulti;value;constructor(e,t,i){super(e,t),this.isMulti=Array.isArray(i),this.keys=this.isMulti?i:[i],this.value=this.getValues(),l&&!this.isMulti&&this.value===void 0&&console.warn(`[Directive] DerivedController("${this.keys[0]}") returned undefined. Check that "${this.keys[0]}" is defined in your module's derive property.`);}getValues(){if(this.isMulti){let e={};for(let t of this.keys)e[t]=this.system.read(t);return e}return this.system.read(this.keys[0])}subscribe(){this.value=this.getValues(),this.unsubscribe=this.system.subscribe(this.keys,()=>{this.value=this.getValues(),this.requestUpdate();});}},v=class extends a{factKey;value;constructor(e,t,i){super(e,t),this.factKey=i,this.value=t.facts.$store.get(i),l&&(t.facts.$store.has(i)||console.warn(`[Directive] FactController("${i}") \u2014 fact not found in store. Check that "${i}" is defined in your module's schema.`));}subscribe(){this.value=this.system.facts.$store.get(this.factKey),this.unsubscribe=this.system.facts.$store.subscribe([this.factKey],()=>{this.value=this.system.facts.$store.get(this.factKey),this.requestUpdate();});}},y=class extends a{value;throttleMs;throttleCleanup;unsubSettled;constructor(e,t,i){super(e,t),this.throttleMs=i?.throttleMs??0,this.value=computeInspectState(t);}subscribe(){this.value=computeInspectState(this.system);let e=()=>{this.value=computeInspectState(this.system),this.requestUpdate();};if(this.throttleMs>0){let{throttled:t,cleanup:i}=createThrottle(e,this.throttleMs);this.throttleCleanup=i,this.unsubscribe=this.system.facts.$store.subscribeAll(t),this.unsubSettled=this.system.onSettledChange(t);}else this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.throttleCleanup?.(),this.unsubSettled?.(),super.hostDisconnected();}},p=class{host;statusPlugin;type;unsubscribe;value;constructor(e,t,i){this.host=e,this.statusPlugin=t,this.type=i,this.value=t.getStatus(i),e.addController(this);}hostConnected(){this.value=this.statusPlugin.getStatus(this.type),this.unsubscribe=this.statusPlugin.subscribe(()=>{this.value=this.statusPlugin.getStatus(this.type),this.host.requestUpdate();});}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}},m=class extends a{selector;equalityFn;autoTrack;deriveKeySet;trackedFactKeys=[];trackedDeriveKeys=[];unsubs=[];value;constructor(e,t,i,n=defaultEquality,r){super(e,t),this.selector=i,this.equalityFn=n,this.autoTrack=r?.autoTrack??true,this.deriveKeySet=new Set(Object.keys(t.derive??{}));let o=this.runWithTracking();this.value=o.value,this.trackedFactKeys=o.factKeys,this.trackedDeriveKeys=o.deriveKeys;}runWithTracking(){return runTrackedSelector(this.system,this.deriveKeySet,this.selector)}resubscribe(){for(let t of this.unsubs)t();this.unsubs=[];let e=()=>{let t=this.runWithTracking();this.equalityFn(this.value,t.value)||(this.value=t.value,this.requestUpdate()),this.autoTrack&&depsChanged(this.trackedFactKeys,t.factKeys,this.trackedDeriveKeys,t.deriveKeys)&&(this.trackedFactKeys=t.factKeys,this.trackedDeriveKeys=t.deriveKeys,this.resubscribe());};this.autoTrack?(this.trackedFactKeys.length>0?this.unsubs.push(this.system.facts.$store.subscribe(this.trackedFactKeys,e)):this.trackedDeriveKeys.length===0&&this.unsubs.push(this.system.facts.$store.subscribeAll(e)),this.trackedDeriveKeys.length>0&&this.unsubs.push(this.system.subscribe(this.trackedDeriveKeys,e))):this.unsubs.push(this.system.facts.$store.subscribeAll(e));}subscribe(){let e=this.runWithTracking();this.value=e.value,this.trackedFactKeys=e.factKeys,this.trackedDeriveKeys=e.deriveKeys,this.resubscribe();}hostDisconnected(){for(let e of this.unsubs)e();this.unsubs=[],super.hostDisconnected();}},g=class extends a{key;callback;constructor(e,t,i,n){super(e,t),this.key=i,this.callback=n;}subscribe(){this.unsubscribe=this.system.watch(this.key,this.callback);}},f=class extends a{requirementId;value;unsubSettled;constructor(e,t,i){super(e,t),this.requirementId=i,this.value=t.explain(i);}subscribe(){this.value=this.system.explain(this.requirementId);let e=()=>{this.value=this.system.explain(this.requirementId),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},S=class extends a{constraintId;value;unsubSettled;constructor(e,t,i){super(e,t),this.constraintId=i,this.value=this.getVal();}getVal(){let e=this.system.inspect();return this.constraintId?e.constraints.find(t=>t.id===this.constraintId)??null:e.constraints}subscribe(){this.value=this.getVal();let e=()=>{this.value=this.getVal(),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},b=class{host;system;statusPlugin;requirementType;snapshot=null;statusUnsub=null;isPending=false;error=null;constructor(e,t,i,n){this.host=e,this.system=t,this.statusPlugin=i,this.requirementType=n,e.addController(this);}hostConnected(){}hostDisconnected(){this.statusUnsub?.(),this.statusUnsub=null;}rollback(){this.snapshot&&(this.system.restore(this.snapshot),this.snapshot=null),this.isPending=false,this.error=null,this.statusUnsub?.(),this.statusUnsub=null,this.host.requestUpdate();}mutate(e){this.snapshot=this.system.getSnapshot(),this.isPending=true,this.error=null,this.system.batch(e),this.host.requestUpdate(),this.statusPlugin&&this.requirementType&&(this.statusUnsub?.(),this.statusUnsub=this.statusPlugin.subscribe(()=>{let t=this.statusPlugin.getStatus(this.requirementType);!t.isLoading&&!t.hasError?(this.snapshot=null,this.isPending=false,this.statusUnsub?.(),this.statusUnsub=null,this.host.requestUpdate()):t.hasError&&(this.error=t.lastError,this.rollback());}));}},k=class{options;_system=null;constructor(e,t){this.options=t,e.addController(this);}get system(){if(!this._system)throw new Error(`[Directive] SystemController.system is not available. This can happen if:
|
|
2
2
|
1. Accessed before hostConnected (e.g., in a class field initializer)
|
|
3
3
|
2. Accessed after hostDisconnected (system was destroyed)
|
|
4
|
-
Solution: Access system only in lifecycle methods (connectedCallback, render) or after the element is connected to the DOM.`);return this._system}hostConnected(){let t="id"in this.options&&"schema"in this.options?createSystem({module:this.options}):createSystem(this.options);this._system=t,this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},M=class{host;moduleDef;config;_system=null;unsubFacts;unsubDerived;facts={};derived={};statusPlugin;get system(){if(!this._system)throw new Error("[Directive] ModuleController.system is not available before hostConnected.");return this._system}get events(){return this.system.events}constructor(e,t,i){this.host=e,this.moduleDef=t,this.config=i,e.addController(this);}hostConnected(){let e=[...this.config?.plugins??[]];if(this.config?.status){let
|
|
4
|
+
Solution: Access system only in lifecycle methods (connectedCallback, render) or after the element is connected to the DOM.`);return this._system}hostConnected(){let t="id"in this.options&&"schema"in this.options?createSystem({module:this.options}):createSystem(this.options);this._system=t,this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},M=class{host;moduleDef;config;_system=null;unsubFacts;unsubDerived;facts={};derived={};statusPlugin;get system(){if(!this._system)throw new Error("[Directive] ModuleController.system is not available before hostConnected.");return this._system}get events(){return this.system.events}constructor(e,t,i){this.host=e,this.moduleDef=t,this.config=i,e.addController(this);}hostConnected(){let e=[...this.config?.plugins??[]];if(this.config?.status){let r=createRequirementStatusPlugin();this.statusPlugin=r,e.push(r.plugin);}let t=createSystem({module:this.moduleDef,plugins:e.length>0?e:void 0,trace:this.config?.trace,errorBoundary:this.config?.errorBoundary,tickMs:this.config?.tickMs,zeroConfig:this.config?.zeroConfig,initialFacts:this.config?.initialFacts});this._system=t,t.start(),this.facts=t.facts.$store.toObject(),this.unsubFacts=t.facts.$store.subscribeAll(()=>{this.facts=t.facts.$store.toObject(),this.host.requestUpdate();});let i=Object.keys(t.derive??{}),n=()=>{let r={};for(let o of i)r[o]=t.read(o);return r};this.derived=n(),i.length>0&&(this.unsubDerived=t.subscribe(i,()=>{this.derived=n(),this.host.requestUpdate();}));}hostDisconnected(){this.unsubFacts?.(),this.unsubDerived?.(),this._system?.destroy(),this._system=null;}dispatch(e){this.system.dispatch(e);}};function _(s,e,t){return new h(s,e,t)}function E(s,e,t){return new v(s,e,t)}function z(s,e,t){return new y(s,e,t)}function W(s,e,t){return new p(s,e,t)}function U(s,e,t,i){return new g(s,e,t,i)}function L(s,e,t,i=defaultEquality,n){return new m(s,e,t,i,n)}function j(s,e,t){return new f(s,e,t)}function Q(s,e,t){return new S(s,e,t)}function J(s,e,t,i){return new b(s,e,t,i)}function G(s,e,t){return new M(s,e,t)}function X(s){return assertSystem("useDispatch",s),e=>{s.dispatch(e);}}function Y(s){return assertSystem("useEvents",s),s.events}var D=class{constructor(e,t){this._host=e;this._system=t;this._host.addController(this);}value=null;_unsub;hostConnected(){this.value=buildHistoryState(this._system),this._unsub=this._system.onHistoryChange(()=>{this.value=buildHistoryState(this._system),this._host.requestUpdate();});}hostDisconnected(){this._unsub?.(),this._unsub=void 0;}};function Z(s){return assertSystem("useHistory",s),buildHistoryState(s)}function ee(s,e){return ()=>s.read(e)}function te(s,e){return ()=>s.facts.$store.get(e)}function se(){return {createDerived:(s,e,t)=>_(s,e,t),createFact:(s,e,t)=>E(s,e,t),useDispatch:s=>e=>{s.dispatch(e);},useEvents:s=>s.events,createWatch:(s,e,t,i)=>U(s,e,t,i)}}var C=class{host;system;keys;selector;unsubscribe;value;constructor(e,t,i,n){this.host=e,this.system=t,this.keys=i,this.selector=n,this.value=n(t),e.addController(this);}hostConnected(){this.value=this.selector(this.system),this.unsubscribe=this.system.subscribe(this.keys,()=>{this.value=this.selector(this.system),this.host.requestUpdate();});}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}};function ie(s,e,t,i){return new C(s,e,t,i)}var T=class{_system=null;factory;constructor(e,t){this.factory=t,e.addController(this);}get system(){if(!this._system)throw new Error("[Directive] QuerySystemController.system is not available. Access it only in lifecycle methods or after the element is connected.");return this._system}hostConnected(){this._system=this.factory(),this._system.isRunning||this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},x=class{snapshot;systems=[];constructor(e,t){this.snapshot=t,e.addController(this);}hostConnected(){}hostDisconnected(){for(let e of this.systems)e.destroy();this.systems=[];}createSystem(e,t){let i=mergeHydrationFacts(this.snapshot,t?.initialFacts),n=createSystem({module:e,plugins:t?.plugins,trace:t?.trace,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:i});return this.systems.push(n),typeof window<"u"&&n.start(),n}},I=class{host;ledger;filter;pollMs;intervalId=null;value;constructor(e,t,i={},n={}){this.host=e,this.ledger=t,this.filter=i;let r=n.pollMs??250;if(this.pollMs=Math.max(50,r),l&&(n.pollMs!==void 0&&n.pollMs<50&&console.warn(`[Directive] AuditLedgerController pollMs=${n.pollMs} is below the 50 ms floor; clamped to 50 ms.`),this.pollMs<100)){let o=t.toJSON().entries.length;o>1e3&&console.warn(`[Directive] AuditLedgerController polling every ${this.pollMs} ms against a ${o}-entry ledger \u2014 that's a lot of CPU per tick. Consider raising pollMs or tightening the filter.`);}this.value=t.query(i),e.addController(this);}hostConnected(){this.intervalId=setInterval(()=>{let e=this.ledger.query(this.filter),t=e[0]?.seq!==this.value[0]?.seq||e[e.length-1]?.seq!==this.value[this.value.length-1]?.seq;this.value=e,t&&this.host.requestUpdate();},this.pollMs);}hostDisconnected(){this.intervalId!==null&&(clearInterval(this.intervalId),this.intervalId=null);}};export{I as AuditLedgerController,S as ConstraintStatusController,h as DerivedController,m as DirectiveSelectorController,f as ExplainController,v as FactController,D as HistoryController,x as HydrationController,y as InspectController,M as ModuleController,C as NamespacedSelectorController,b as OptimisticUpdateController,T as QuerySystemController,p as RequirementStatusController,k as SystemController,g as WatchController,Q as createConstraintStatus,_ as createDerived,L as createDirectiveSelector,j as createExplain,E as createFact,z as createInspect,G as createModule,ie as createNamespacedSelector,J as createOptimisticUpdate,W as createRequirementStatus,se as createTypedHooks,U as createWatch,N as directiveContext,ee as getDerived,te as getFact,X as useDispatch,Y as useEvents,Z as useHistory};//# sourceMappingURL=index.js.map
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dev-true.ts","../src/index.ts"],"names":["dev_true_default","directiveContext","DirectiveController","host","system","DerivedController","key","result","id","FactController","factKey","InspectController","options","computeInspectState","update","throttled","cleanup","createThrottle","RequirementStatusController","statusPlugin","type","DirectiveSelectorController","selector","equalityFn","defaultEquality","initial","runTrackedSelector","unsub","onUpdate","depsChanged","WatchController","callback","ExplainController","requirementId","ConstraintStatusController","constraintId","inspection","c","OptimisticUpdateController","requirementType","updateFn","status","SystemController","createSystem","ModuleController","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","derivationKeys","getDerived","event","createDerived","createFact","createInspect","createRequirementStatus","createWatch","derivationId","createDirectiveSelector","createExplain","createConstraintStatus","createOptimisticUpdate","createModule","useDispatch","assertSystem","useEvents","HistoryController","_host","_system","buildHistoryState","useHistory","getFact","createTypedHooks","NamespacedSelectorController","keys","createNamespacedSelector","QuerySystemController","factory","HydrationController","snapshot","mergedFacts","mergeHydrationFacts"],"mappings":"8TAAA,IAAOA,CAAAA,CAAQ,OAAO,OAAA,CAAY,GAAA,EAChC,QAAQ,GAAA,EAAK,QAAA,GAAa,YAAA,CCmErB,IAAMC,CAAAA,CAAmB,MAAA,CAAO,WAAW,CAAA,CASnCC,CAAAA,CAAf,KAAiE,CACrD,IAAA,CAEA,MAAA,CACA,WAAA,CAGV,WAAA,CAAYC,CAAAA,CAA8BC,EAAiC,CACzE,IAAA,CAAK,IAAA,CAAOD,CAAAA,CACZ,IAAA,CAAK,MAAA,CAASC,CAAAA,CACdD,CAAAA,CAAK,cAAc,IAAI,EACzB,CAEA,aAAA,EAAsB,CACpB,IAAA,CAAK,SAAA,GACP,CAEA,gBAAA,EAAyB,CACvB,IAAA,CAAK,WAAA,IAAc,CACnB,IAAA,CAAK,WAAA,CAAc,OACrB,CAIU,aAAA,EAAsB,CAC9B,IAAA,CAAK,IAAA,CAAK,aAAA,GACZ,CACF,EAYaE,CAAAA,CAAN,cAAmCH,CAAoB,CACpD,IAAA,CACA,OAAA,CACR,KAAA,CAEA,WAAA,CACEC,EAEAC,CAAAA,CACAE,CAAAA,CACA,CACA,KAAA,CAAMH,CAAAA,CAAMC,CAAM,CAAA,CAClB,IAAA,CAAK,QAAU,KAAA,CAAM,OAAA,CAAQE,CAAG,CAAA,CAChC,IAAA,CAAK,IAAA,CAAO,IAAA,CAAK,OAAA,CAAWA,CAAAA,CAAmB,CAACA,CAAa,CAAA,CAC7D,IAAA,CAAK,KAAA,CAAQ,IAAA,CAAK,SAAA,GAEdN,CAAAA,EACE,CAAC,IAAA,CAAK,OA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EAAQ,KAAA,CACf,cAAeA,CAAAA,EAAQ,aAAA,CACvB,OAAQA,CAAAA,EAAQ,MAAA,CAChB,WAAYA,CAAAA,EAAQ,UAAA,CACpB,YAAA,CAAcmC,CAChB,CAAQ,CAAA,CAER,YAAK,OAAA,CAAQ,IAAA,CAAK7E,CAAM,CAAA,CAEpB,OAAO,MAAA,CAAW,KACpBA,CAAAA,CAAO,KAAA,EAAM,CAGRA,CACT,CACF","file":"index.js","sourcesContent":["export default typeof process !== \"undefined\" &&\n process.env?.NODE_ENV !== \"production\";\n","/**\n * Lit Adapter - Consolidated Web Components integration for Directive\n *\n * Controllers: DerivedController, FactController,\n * InspectController (with throttle), RequirementStatusController,\n * DirectiveSelectorController,\n * WatchController (with fact mode), SystemController,\n * ExplainController, ConstraintStatusController, OptimisticUpdateController, ModuleController\n *\n * Factories: createDerived, createFact, createInspect,\n * createRequirementStatus, createWatch,\n * createDirectiveSelector, useDispatch, useEvents, useHistory,\n * getDerived, getFact, createTypedHooks, shallowEqual\n */\n\nimport type {\n CreateSystemOptionsSingle,\n ErrorBoundaryConfig,\n HistoryState,\n InferDerivations,\n InferEvents,\n InferFacts,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemSnapshot,\n TraceOption,\n} from \"@directive-run/core\";\nimport {\n createRequirementStatusPlugin,\n createSystem,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n type ConstraintInfo,\n type InspectState,\n type TrackedSelectorResult,\n assertSystem,\n buildHistoryState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n mergeHydrationFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport type { ReactiveController, ReactiveControllerHost } from \"lit\";\nimport isDevelopment from \"#is-development\";\n\n// Re-export for convenience\nexport type { RequirementTypeStatus, InspectState, ConstraintInfo };\nexport { shallowEqual };\n\n/** Type for the requirement status plugin return value */\nexport type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;\n\n// ============================================================================\n// Context\n// ============================================================================\n\n/**\n * Context key for Directive system.\n * Use with @lit/context for dependency injection across shadow DOM boundaries.\n */\nexport const directiveContext = Symbol(\"directive\");\n\n// ============================================================================\n// Base Controller\n// ============================================================================\n\n/**\n * Base controller that manages system subscription lifecycle.\n */\nabstract class DirectiveController implements ReactiveController {\n protected host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n protected system: SingleModuleSystem<any>;\n protected unsubscribe?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>) {\n this.host = host;\n this.system = system;\n host.addController(this);\n }\n\n hostConnected(): void {\n this.subscribe();\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n\n protected abstract subscribe(): void;\n\n protected requestUpdate(): void {\n this.host.requestUpdate();\n }\n}\n\n// ============================================================================\n// Core Controllers\n// ============================================================================\n\n/**\n * Reactive controller for derivations.\n * Accepts a single key (string) or an array of keys (string[]).\n * - Single key: `.value` returns `T`\n * - Array of keys: `.value` returns `Record<string, unknown>`\n */\nexport class DerivedController<T> extends DirectiveController {\n private keys: string[];\n private isMulti: boolean;\n value: T;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n ) {\n super(host, system);\n this.isMulti = Array.isArray(key);\n this.keys = this.isMulti ? (key as string[]) : [key as string];\n this.value = this.getValues();\n\n if (isDevelopment) {\n if (!this.isMulti && this.value === undefined) {\n console.warn(\n `[Directive] DerivedController(\"${this.keys[0]}\") returned undefined. ` +\n `Check that \"${this.keys[0]}\" is defined in your module's derive property.`,\n );\n }\n }\n }\n\n private getValues(): T {\n if (this.isMulti) {\n const result: Record<string, unknown> = {};\n for (const id of this.keys) {\n result[id] = this.system.read(id);\n }\n return result as T;\n }\n return this.system.read(this.keys[0]!) as T;\n }\n\n protected subscribe(): void {\n this.value = this.getValues();\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.getValues();\n this.requestUpdate();\n });\n }\n}\n\n/**\n * Reactive controller for a single fact value.\n */\nexport class FactController<T> extends DirectiveController {\n private factKey: string;\n value: T | undefined;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n ) {\n super(host, system);\n this.factKey = factKey;\n this.value = system.facts.$store.get(factKey) as T | undefined;\n\n if (isDevelopment) {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] FactController(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n }\n\n protected subscribe(): void {\n this.value = this.system.facts.$store.get(this.factKey) as T | undefined;\n this.unsubscribe = this.system.facts.$store.subscribe(\n [this.factKey],\n () => {\n this.value = this.system.facts.$store.get(this.factKey) as\n | T\n | undefined;\n this.requestUpdate();\n },\n );\n }\n}\n\n/**\n * Consolidated inspection controller.\n * Returns InspectState with optional throttling.\n */\nexport class InspectController extends DirectiveController {\n value: InspectState;\n private throttleMs: number;\n private throttleCleanup?: () => void;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n ) {\n super(host, system);\n this.throttleMs = options?.throttleMs ?? 0;\n this.value = computeInspectState(system);\n }\n\n protected subscribe(): void {\n this.value = computeInspectState(this.system);\n\n const update = () => {\n this.value = computeInspectState(this.system);\n this.requestUpdate();\n };\n\n if (this.throttleMs > 0) {\n const { throttled, cleanup } = createThrottle(update, this.throttleMs);\n this.throttleCleanup = cleanup;\n this.unsubscribe = this.system.facts.$store.subscribeAll(throttled);\n this.unsubSettled = this.system.onSettledChange(throttled);\n } else {\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n }\n\n hostDisconnected(): void {\n this.throttleCleanup?.();\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for requirement status.\n */\nexport class RequirementStatusController implements ReactiveController {\n private host: ReactiveControllerHost;\n private statusPlugin: StatusPlugin;\n private type: string;\n private unsubscribe?: () => void;\n value: RequirementTypeStatus;\n\n constructor(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n ) {\n this.host = host;\n this.statusPlugin = statusPlugin;\n this.type = type;\n this.value = statusPlugin.getStatus(type);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.statusPlugin.getStatus(this.type);\n this.unsubscribe = this.statusPlugin.subscribe(() => {\n this.value = this.statusPlugin.getStatus(this.type);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\n// ============================================================================\n// Selector Controllers\n// ============================================================================\n\n/**\n * Reactive controller for selecting across all facts.\n * Uses `withTracking()` for auto-tracking when constructed with `autoTrack: true`.\n */\nexport class DirectiveSelectorController<R> extends DirectiveController {\n private selector: (state: Record<string, unknown>) => R;\n private equalityFn: (a: R, b: R) => boolean;\n private autoTrack: boolean;\n private deriveKeySet: Set<string>;\n private trackedFactKeys: string[] = [];\n private trackedDeriveKeys: string[] = [];\n private unsubs: Array<() => void> = [];\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n ) {\n super(host, system);\n this.selector = selector;\n this.equalityFn = equalityFn;\n this.autoTrack = options?.autoTrack ?? true;\n this.deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n const initial = this.runWithTracking();\n this.value = initial.value;\n this.trackedFactKeys = initial.factKeys;\n this.trackedDeriveKeys = initial.deriveKeys;\n }\n\n private runWithTracking(): TrackedSelectorResult<R> {\n return runTrackedSelector(this.system, this.deriveKeySet, this.selector);\n }\n\n private resubscribe(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n\n const onUpdate = () => {\n const result = this.runWithTracking();\n if (!this.equalityFn(this.value, result.value)) {\n this.value = result.value;\n this.requestUpdate();\n }\n if (this.autoTrack) {\n // Re-track: check if deps changed\n if (\n depsChanged(\n this.trackedFactKeys,\n result.factKeys,\n this.trackedDeriveKeys,\n result.deriveKeys,\n )\n ) {\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n }\n };\n\n if (this.autoTrack) {\n if (this.trackedFactKeys.length > 0) {\n this.unsubs.push(\n this.system.facts.$store.subscribe(this.trackedFactKeys, onUpdate),\n );\n } else if (this.trackedDeriveKeys.length === 0) {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n if (this.trackedDeriveKeys.length > 0) {\n this.unsubs.push(\n this.system.subscribe(this.trackedDeriveKeys, onUpdate),\n );\n }\n } else {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n }\n\n protected subscribe(): void {\n const result = this.runWithTracking();\n this.value = result.value;\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n\n hostDisconnected(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller that watches a fact or derivation and calls a callback on change.\n * The key is auto-detected — works with both fact keys and derivation keys.\n */\nexport class WatchController<T> extends DirectiveController {\n private key: string;\n private callback: (newValue: T, previousValue: T | undefined) => void;\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. */\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n ) {\n super(host, system);\n this.key = key;\n this.callback = callback;\n }\n\n protected subscribe(): void {\n this.unsubscribe = this.system.watch<T>(this.key, this.callback);\n }\n}\n\n// ============================================================================\n// New Controllers\n// ============================================================================\n\n/**\n * Reactive controller for requirement explanations.\n */\nexport class ExplainController extends DirectiveController {\n private requirementId: string;\n value: string | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n requirementId: string,\n ) {\n super(host, system);\n this.requirementId = requirementId;\n this.value = system.explain(requirementId);\n }\n\n protected subscribe(): void {\n this.value = this.system.explain(this.requirementId);\n\n const update = () => {\n this.value = this.system.explain(this.requirementId);\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for constraint status.\n */\nexport class ConstraintStatusController extends DirectiveController {\n private constraintId?: string;\n value: ConstraintInfo[] | ConstraintInfo | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n constraintId?: string,\n ) {\n super(host, system);\n this.constraintId = constraintId;\n this.value = this.getVal();\n }\n\n private getVal(): ConstraintInfo[] | ConstraintInfo | null {\n const inspection = this.system.inspect();\n if (!this.constraintId) return inspection.constraints;\n return (\n inspection.constraints.find(\n (c: ConstraintInfo) => c.id === this.constraintId,\n ) ?? null\n );\n }\n\n protected subscribe(): void {\n this.value = this.getVal();\n\n const update = () => {\n this.value = this.getVal();\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for optimistic updates.\n */\nexport class OptimisticUpdateController implements ReactiveController {\n private host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private system: SingleModuleSystem<any>;\n private statusPlugin?: StatusPlugin;\n private requirementType?: string;\n private snapshot: SystemSnapshot | null = null;\n private statusUnsub: (() => void) | null = null;\n\n isPending = false;\n error: Error | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n ) {\n this.host = host;\n this.system = system;\n this.statusPlugin = statusPlugin;\n this.requirementType = requirementType;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n this.statusUnsub?.();\n this.statusUnsub = null;\n }\n\n rollback(): void {\n if (this.snapshot) {\n this.system.restore(this.snapshot);\n this.snapshot = null;\n }\n this.isPending = false;\n this.error = null;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n }\n\n mutate(updateFn: () => void): void {\n this.snapshot = this.system.getSnapshot();\n this.isPending = true;\n this.error = null;\n this.system.batch(updateFn);\n this.host.requestUpdate();\n\n if (this.statusPlugin && this.requirementType) {\n this.statusUnsub?.();\n this.statusUnsub = this.statusPlugin.subscribe(() => {\n const status = this.statusPlugin!.getStatus(this.requirementType!);\n if (!status.isLoading && !status.hasError) {\n this.snapshot = null;\n this.isPending = false;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n } else if (status.hasError) {\n this.error = status.lastError;\n this.rollback();\n }\n });\n }\n }\n}\n\n/**\n * Reactive controller that creates and manages a Directive system.\n * The system is automatically started when the host connects and destroyed when it disconnects.\n */\nexport class SystemController<M extends ModuleSchema>\n implements ReactiveController\n{\n private options: ModuleDef<M> | CreateSystemOptionsSingle<M>;\n private _system: SingleModuleSystem<M> | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n options: ModuleDef<M> | CreateSystemOptionsSingle<M>,\n ) {\n this.options = options;\n host.addController(this);\n }\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] SystemController.system is not available. \" +\n \"This can happen if:\\n\" +\n \" 1. Accessed before hostConnected (e.g., in a class field initializer)\\n\" +\n \" 2. Accessed after hostDisconnected (system was destroyed)\\n\" +\n \"Solution: Access system only in lifecycle methods (connectedCallback, render) \" +\n \"or after the element is connected to the DOM.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n const isModule = \"id\" in this.options && \"schema\" in this.options;\n const system = isModule\n ? createSystem({ module: this.options as ModuleDef<M> })\n : createSystem(this.options as CreateSystemOptionsSingle<M>);\n this._system = system as unknown as SingleModuleSystem<M>;\n this._system.start();\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n/**\n * Module controller — zero-config all-in-one.\n * Creates system, starts it, subscribes to all facts/derivations.\n */\nexport class ModuleController<M extends ModuleSchema>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private moduleDef: ModuleDef<M>;\n private config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n };\n\n private _system: SingleModuleSystem<M> | null = null;\n private unsubFacts?: () => void;\n private unsubDerived?: () => void;\n\n facts: InferFacts<M> = {} as InferFacts<M>;\n derived: InferDerivations<M> = {} as InferDerivations<M>;\n statusPlugin?: StatusPlugin;\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] ModuleController.system is not available before hostConnected.\",\n );\n }\n return this._system;\n }\n\n get events(): SingleModuleSystem<M>[\"events\"] {\n return this.system.events;\n }\n\n constructor(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n ) {\n this.host = host;\n this.moduleDef = moduleDef;\n this.config = config;\n host.addController(this);\n }\n\n hostConnected(): void {\n const allPlugins = [...(this.config?.plugins ?? [])];\n\n if (this.config?.status) {\n const sp = createRequirementStatusPlugin();\n this.statusPlugin = sp;\n // biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n allPlugins.push(sp.plugin as Plugin<any>);\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: this.moduleDef,\n plugins: allPlugins.length > 0 ? allPlugins : undefined,\n trace: this.config?.trace,\n errorBoundary: this.config?.errorBoundary,\n tickMs: this.config?.tickMs,\n zeroConfig: this.config?.zeroConfig,\n initialFacts: this.config?.initialFacts,\n } as any) as unknown as SingleModuleSystem<M>;\n\n this._system = system;\n system.start();\n\n // Subscribe to all facts\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.unsubFacts = system.facts.$store.subscribeAll(() => {\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.host.requestUpdate();\n });\n\n // Subscribe to all derivations\n const derivationKeys = Object.keys(system.derive ?? {});\n const getDerived = (): InferDerivations<M> => {\n const result: Record<string, unknown> = {};\n for (const key of derivationKeys) {\n result[key] = system.read(key);\n }\n return result as InferDerivations<M>;\n };\n this.derived = getDerived();\n\n if (derivationKeys.length > 0) {\n this.unsubDerived = system.subscribe(derivationKeys, () => {\n this.derived = getDerived();\n this.host.requestUpdate();\n });\n }\n }\n\n hostDisconnected(): void {\n this.unsubFacts?.();\n this.unsubDerived?.();\n this._system?.destroy();\n this._system = null;\n }\n\n dispatch(event: InferEvents<M>): void {\n this.system.dispatch(event);\n }\n}\n\n// ============================================================================\n// Factory Functions (active)\n// ============================================================================\n\nexport function createDerived<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n): DerivedController<T> {\n return new DerivedController<T>(host, system, key);\n}\n\nexport function createFact<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): FactController<T> {\n return new FactController<T>(host, system, factKey);\n}\n\n/**\n * Create an inspect controller.\n * Returns InspectState; pass `{ throttleMs }` for throttled updates.\n */\nexport function createInspect(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n): InspectController {\n return new InspectController(host, system, options);\n}\n\nexport function createRequirementStatus(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n): RequirementStatusController {\n return new RequirementStatusController(host, statusPlugin, type);\n}\n\nexport function createWatch<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n): WatchController<T> {\n return new WatchController<T>(host, system, derivationId, callback);\n}\n\nexport function createDirectiveSelector<R>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n): DirectiveSelectorController<R> {\n return new DirectiveSelectorController<R>(\n host,\n system,\n selector,\n equalityFn,\n options,\n );\n}\n\nexport function createExplain(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n requirementId: string,\n): ExplainController {\n return new ExplainController(host, system, requirementId);\n}\n\nexport function createConstraintStatus(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): ConstraintStatusController {\n return new ConstraintStatusController(host, system, constraintId);\n}\n\nexport function createOptimisticUpdate(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n): OptimisticUpdateController {\n return new OptimisticUpdateController(\n host,\n system,\n statusPlugin,\n requirementType,\n );\n}\n\nexport function createModule<M extends ModuleSchema>(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n): ModuleController<M> {\n return new ModuleController<M>(host, moduleDef, config);\n}\n\n// ============================================================================\n// Functional Helpers\n// ============================================================================\n\nexport function useDispatch<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): (event: InferEvents<M>) => void {\n assertSystem(\"useDispatch\", system);\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n}\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): SingleModuleSystem<M>[\"events\"] {\n assertSystem(\"useEvents\", system);\n return system.events;\n}\n\n/**\n * Reactive controller for history state.\n * Triggers host updates when snapshots change or navigation occurs.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private _history = new HistoryController(this, system);\n * render() {\n * const h = this._history.value;\n * return html`<button ?disabled=${!h?.canGoBack} @click=${() => h?.goBack()}>Undo</button>`;\n * }\n * }\n * ```\n */\nexport class HistoryController implements ReactiveController {\n value: HistoryState | null = null;\n private _unsub?: () => void;\n\n constructor(\n private _host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: SingleModuleSystem<any>,\n ) {\n this._host.addController(this);\n }\n\n hostConnected(): void {\n this.value = buildHistoryState(this._system);\n this._unsub = this._system.onHistoryChange(() => {\n this.value = buildHistoryState(this._system);\n this._host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this._unsub?.();\n this._unsub = undefined;\n }\n}\n\n/**\n * Functional helper for history state (non-reactive, snapshot).\n * For reactive updates, use HistoryController.\n */\n// biome-ignore lint/suspicious/noExplicitAny: System type varies\nexport function useHistory(\n system: SingleModuleSystem<any>,\n): HistoryState | null {\n assertSystem(\"useHistory\", system);\n return buildHistoryState(system);\n}\n\nexport function getDerived<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n): () => T {\n return () => system.read(derivationId) as T;\n}\n\nexport function getFact<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): () => T | undefined {\n return () => system.facts.$store.get(factKey) as T | undefined;\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => DerivedController<InferDerivations<M>[K]>;\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => FactController<InferFacts<M>[K]>;\n useDispatch: (\n system: SingleModuleSystem<M>,\n ) => (event: InferEvents<M>) => void;\n useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => WatchController<unknown>;\n} {\n return {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) =>\n createDerived<InferDerivations<M>[K]>(\n host,\n system,\n derivationId as string,\n ),\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => createFact<InferFacts<M>[K]>(host, system, factKey as string),\n useDispatch: (system: SingleModuleSystem<M>) => {\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n },\n useEvents: (system: SingleModuleSystem<M>) => system.events,\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => createWatch<unknown>(host, system, key, callback),\n };\n}\n\n// ============================================================================\n// NamespacedSelectorController — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * Reactive controller that selects from a NamespacedSystem.\n * Subscribes to specified keys and triggers host updates.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private token = new NamespacedSelectorController(\n * this, system, [\"auth.token\"], (s) => s.facts.auth.token,\n * );\n * render() {\n * return html`<span>${this.token.value}</span>`;\n * }\n * }\n * ```\n */\nexport class NamespacedSelectorController<Modules extends ModulesMap, R>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private system: NamespacedSystem<Modules>;\n private keys: string[];\n private selector: (system: NamespacedSystem<Modules>) => R;\n private unsubscribe?: () => void;\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n ) {\n this.host = host;\n this.system = system;\n this.keys = keys;\n this.selector = selector;\n this.value = selector(system);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.selector(this.system);\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.selector(this.system);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\nexport function createNamespacedSelector<Modules extends ModulesMap, R>(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n): NamespacedSelectorController<Modules, R> {\n return new NamespacedSelectorController(host, system, keys, selector);\n}\n\n// ============================================================================\n// QuerySystemController — Stable query system with Lit lifecycle\n// ============================================================================\n\n/**\n * Lit reactive controller that creates and manages a query system.\n * Starts on connect, destroys on disconnect.\n *\n * @example\n * ```typescript\n * import { LitElement, html } from \"lit\";\n * import { QuerySystemController } from \"@directive-run/lit\";\n * import { createQuerySystem } from \"@directive-run/query\";\n *\n * class MyApp extends LitElement {\n * private app = new QuerySystemController(this, () =>\n * createQuerySystem({\n * facts: { userId: \"\" },\n * queries: { user: { key: ..., fetcher: ... } },\n * autoStart: false,\n * })\n * );\n *\n * render() {\n * const user = this.app.system.read(\"user\");\n * return html`<div>${user.data?.name}</div>`;\n * }\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nexport class QuerySystemController<\n T extends {\n start: () => void;\n destroy: () => void;\n isRunning?: boolean;\n [key: string]: any;\n },\n> implements ReactiveController\n{\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: T | null = null;\n private factory: () => T;\n\n constructor(host: ReactiveControllerHost, factory: () => T) {\n this.factory = factory;\n host.addController(this);\n }\n\n get system(): T {\n if (!this._system) {\n throw new Error(\n \"[Directive] QuerySystemController.system is not available. \" +\n \"Access it only in lifecycle methods or after the element is connected.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n this._system = this.factory();\n if (!this._system.isRunning) {\n this._system.start();\n }\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n// ============================================================================\n// SSR Hydration\n// ============================================================================\n\n/**\n * Lit reactive controller for SSR hydration.\n * Accepts a DistributableSnapshot and creates a hydrated system.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private hydration = new HydrationController(this, serverSnapshot);\n * private system = this.hydration.createSystem(myModule);\n * }\n * ```\n */\nexport class HydrationController implements ReactiveController {\n private snapshot: Record<string, unknown> | undefined;\n // biome-ignore lint/suspicious/noExplicitAny: Systems vary by module schema\n private systems: SingleModuleSystem<any>[] = [];\n\n constructor(\n host: ReactiveControllerHost,\n snapshot?: Record<string, unknown>,\n ) {\n this.snapshot = snapshot;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n for (const system of this.systems) {\n system.destroy();\n }\n this.systems = [];\n }\n\n createSystem<S extends ModuleSchema>(\n moduleDef: ModuleDef<S>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n },\n ): SingleModuleSystem<S> {\n const mergedFacts = mergeHydrationFacts(\n this.snapshot,\n config?.initialFacts,\n );\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: moduleDef,\n plugins: config?.plugins,\n trace: config?.trace,\n errorBoundary: config?.errorBoundary,\n tickMs: config?.tickMs,\n zeroConfig: config?.zeroConfig,\n initialFacts: mergedFacts,\n } as any) as unknown as SingleModuleSystem<S>;\n\n this.systems.push(system);\n\n if (typeof window !== \"undefined\") {\n system.start();\n }\n\n return system;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/dev-true.ts","../src/index.ts"],"names":["dev_true_default","directiveContext","DirectiveController","host","system","DerivedController","key","result","id","FactController","factKey","InspectController","options","computeInspectState","update","throttled","cleanup","createThrottle","RequirementStatusController","statusPlugin","type","DirectiveSelectorController","selector","equalityFn","defaultEquality","initial","runTrackedSelector","unsub","onUpdate","depsChanged","WatchController","callback","ExplainController","requirementId","ConstraintStatusController","constraintId","inspection","c","OptimisticUpdateController","requirementType","updateFn","status","SystemController","createSystem","ModuleController","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","derivationKeys","getDerived","event","createDerived","createFact","createInspect","createRequirementStatus","createWatch","derivationId","createDirectiveSelector","createExplain","createConstraintStatus","createOptimisticUpdate","createModule","useDispatch","assertSystem","useEvents","HistoryController","_host","_system","buildHistoryState","useHistory","getFact","createTypedHooks","NamespacedSelectorController","keys","createNamespacedSelector","QuerySystemController","factory","HydrationController","snapshot","mergedFacts","mergeHydrationFacts","AuditLedgerController","ledger","filter","opts","requestedPollMs","entryCount","next","moved"],"mappings":"8TAAA,IAAOA,CAAAA,CAAQ,OAAO,OAAA,CAAY,GAAA,EAChC,QAAQ,GAAA,EAAK,QAAA,GAAa,YAAA,CCmErB,IAAMC,CAAAA,CAAmB,MAAA,CAAO,WAAW,CAAA,CASnCC,CAAAA,CAAf,KAAiE,CACrD,IAAA,CAEA,MAAA,CACA,WAAA,CAGV,WAAA,CAAYC,CAAAA,CAA8BC,EAAiC,CACzE,IAAA,CAAK,IAAA,CAAOD,CAAAA,CACZ,IAAA,CAAK,MAAA,CAASC,CAAAA,CACdD,CAAAA,CAAK,cAAc,IAAI,EACzB,CAEA,aAAA,EAAsB,CACpB,IAAA,CAAK,SAAA,GACP,CAEA,gBAAA,EAAyB,CACvB,IAAA,CAAK,WAAA,IAAc,CACnB,IAAA,CAAK,WAAA,CAAc,OACrB,CAIU,aAAA,EAAsB,CAC9B,IAAA,CAAK,IAAA,CAAK,aAAA,GACZ,CACF,EAYaE,CAAAA,CAAN,cAAmCH,CAAoB,CACpD,IAAA,CACA,OAAA,CACR,KAAA,CAEA,WAAA,CACEC,EAEAC,CAAAA,CACAE,CAAAA,CACA,CACA,KAAA,CAAMH,CAAAA,CAAMC,CAAM,CAAA,CAClB,IAAA,CAAK,QAAU,KAAA,CAAM,OAAA,CAAQE,CAAG,CAAA,CAChC,IAAA,CAAK,IAAA,CA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CA,CAAAA,CAAKA,CAAAA,CAAK,MAAA,CAAS,CAAC,CAAA,EAAG,GAAA,GACrB,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,MAAA,CAAS,CAAC,CAAA,EAAG,GAAA,CACvC,IAAA,CAAK,KAAA,CAAQA,CAAAA,CACTC,CAAAA,EACF,IAAA,CAAK,IAAA,CAAK,aAAA,GAEd,CAAA,CAAG,IAAA,CAAK,MAAM,EAChB,CAEA,gBAAA,EAAyB,CACnB,IAAA,CAAK,UAAA,GAAe,IAAA,GACtB,aAAA,CAAc,IAAA,CAAK,UAAU,CAAA,CAC7B,IAAA,CAAK,UAAA,CAAa,IAAA,EAEtB,CACF","file":"index.js","sourcesContent":["export default typeof process !== \"undefined\" &&\n process.env?.NODE_ENV !== \"production\";\n","/**\n * Lit Adapter - Consolidated Web Components integration for Directive\n *\n * Controllers: DerivedController, FactController,\n * InspectController (with throttle), RequirementStatusController,\n * DirectiveSelectorController,\n * WatchController (with fact mode), SystemController,\n * ExplainController, ConstraintStatusController, OptimisticUpdateController, ModuleController\n *\n * Factories: createDerived, createFact, createInspect,\n * createRequirementStatus, createWatch,\n * createDirectiveSelector, useDispatch, useEvents, useHistory,\n * getDerived, getFact, createTypedHooks, shallowEqual\n */\n\nimport type {\n CreateSystemOptionsSingle,\n ErrorBoundaryConfig,\n HistoryState,\n InferDerivations,\n InferEvents,\n InferFacts,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemSnapshot,\n TraceOption,\n} from \"@directive-run/core\";\nimport {\n createRequirementStatusPlugin,\n createSystem,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n type ConstraintInfo,\n type InspectState,\n type TrackedSelectorResult,\n assertSystem,\n buildHistoryState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n mergeHydrationFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport type { ReactiveController, ReactiveControllerHost } from \"lit\";\nimport isDevelopment from \"#is-development\";\n\n// Re-export for convenience\nexport type { RequirementTypeStatus, InspectState, ConstraintInfo };\nexport { shallowEqual };\n\n/** Type for the requirement status plugin return value */\nexport type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;\n\n// ============================================================================\n// Context\n// ============================================================================\n\n/**\n * Context key for Directive system.\n * Use with @lit/context for dependency injection across shadow DOM boundaries.\n */\nexport const directiveContext = Symbol(\"directive\");\n\n// ============================================================================\n// Base Controller\n// ============================================================================\n\n/**\n * Base controller that manages system subscription lifecycle.\n */\nabstract class DirectiveController implements ReactiveController {\n protected host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n protected system: SingleModuleSystem<any>;\n protected unsubscribe?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>) {\n this.host = host;\n this.system = system;\n host.addController(this);\n }\n\n hostConnected(): void {\n this.subscribe();\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n\n protected abstract subscribe(): void;\n\n protected requestUpdate(): void {\n this.host.requestUpdate();\n }\n}\n\n// ============================================================================\n// Core Controllers\n// ============================================================================\n\n/**\n * Reactive controller for derivations.\n * Accepts a single key (string) or an array of keys (string[]).\n * - Single key: `.value` returns `T`\n * - Array of keys: `.value` returns `Record<string, unknown>`\n */\nexport class DerivedController<T> extends DirectiveController {\n private keys: string[];\n private isMulti: boolean;\n value: T;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n ) {\n super(host, system);\n this.isMulti = Array.isArray(key);\n this.keys = this.isMulti ? (key as string[]) : [key as string];\n this.value = this.getValues();\n\n if (isDevelopment) {\n if (!this.isMulti && this.value === undefined) {\n console.warn(\n `[Directive] DerivedController(\"${this.keys[0]}\") returned undefined. ` +\n `Check that \"${this.keys[0]}\" is defined in your module's derive property.`,\n );\n }\n }\n }\n\n private getValues(): T {\n if (this.isMulti) {\n const result: Record<string, unknown> = {};\n for (const id of this.keys) {\n result[id] = this.system.read(id);\n }\n return result as T;\n }\n return this.system.read(this.keys[0]!) as T;\n }\n\n protected subscribe(): void {\n this.value = this.getValues();\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.getValues();\n this.requestUpdate();\n });\n }\n}\n\n/**\n * Reactive controller for a single fact value.\n */\nexport class FactController<T> extends DirectiveController {\n private factKey: string;\n value: T | undefined;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n ) {\n super(host, system);\n this.factKey = factKey;\n this.value = system.facts.$store.get(factKey) as T | undefined;\n\n if (isDevelopment) {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] FactController(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n }\n\n protected subscribe(): void {\n this.value = this.system.facts.$store.get(this.factKey) as T | undefined;\n this.unsubscribe = this.system.facts.$store.subscribe(\n [this.factKey],\n () => {\n this.value = this.system.facts.$store.get(this.factKey) as\n | T\n | undefined;\n this.requestUpdate();\n },\n );\n }\n}\n\n/**\n * Consolidated inspection controller.\n * Returns InspectState with optional throttling.\n */\nexport class InspectController extends DirectiveController {\n value: InspectState;\n private throttleMs: number;\n private throttleCleanup?: () => void;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n ) {\n super(host, system);\n this.throttleMs = options?.throttleMs ?? 0;\n this.value = computeInspectState(system);\n }\n\n protected subscribe(): void {\n this.value = computeInspectState(this.system);\n\n const update = () => {\n this.value = computeInspectState(this.system);\n this.requestUpdate();\n };\n\n if (this.throttleMs > 0) {\n const { throttled, cleanup } = createThrottle(update, this.throttleMs);\n this.throttleCleanup = cleanup;\n this.unsubscribe = this.system.facts.$store.subscribeAll(throttled);\n this.unsubSettled = this.system.onSettledChange(throttled);\n } else {\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n }\n\n hostDisconnected(): void {\n this.throttleCleanup?.();\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for requirement status.\n */\nexport class RequirementStatusController implements ReactiveController {\n private host: ReactiveControllerHost;\n private statusPlugin: StatusPlugin;\n private type: string;\n private unsubscribe?: () => void;\n value: RequirementTypeStatus;\n\n constructor(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n ) {\n this.host = host;\n this.statusPlugin = statusPlugin;\n this.type = type;\n this.value = statusPlugin.getStatus(type);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.statusPlugin.getStatus(this.type);\n this.unsubscribe = this.statusPlugin.subscribe(() => {\n this.value = this.statusPlugin.getStatus(this.type);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\n// ============================================================================\n// Selector Controllers\n// ============================================================================\n\n/**\n * Reactive controller for selecting across all facts.\n * Uses `withTracking()` for auto-tracking when constructed with `autoTrack: true`.\n */\nexport class DirectiveSelectorController<R> extends DirectiveController {\n private selector: (state: Record<string, unknown>) => R;\n private equalityFn: (a: R, b: R) => boolean;\n private autoTrack: boolean;\n private deriveKeySet: Set<string>;\n private trackedFactKeys: string[] = [];\n private trackedDeriveKeys: string[] = [];\n private unsubs: Array<() => void> = [];\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n ) {\n super(host, system);\n this.selector = selector;\n this.equalityFn = equalityFn;\n this.autoTrack = options?.autoTrack ?? true;\n this.deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n const initial = this.runWithTracking();\n this.value = initial.value;\n this.trackedFactKeys = initial.factKeys;\n this.trackedDeriveKeys = initial.deriveKeys;\n }\n\n private runWithTracking(): TrackedSelectorResult<R> {\n return runTrackedSelector(this.system, this.deriveKeySet, this.selector);\n }\n\n private resubscribe(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n\n const onUpdate = () => {\n const result = this.runWithTracking();\n if (!this.equalityFn(this.value, result.value)) {\n this.value = result.value;\n this.requestUpdate();\n }\n if (this.autoTrack) {\n // Re-track: check if deps changed\n if (\n depsChanged(\n this.trackedFactKeys,\n result.factKeys,\n this.trackedDeriveKeys,\n result.deriveKeys,\n )\n ) {\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n }\n };\n\n if (this.autoTrack) {\n if (this.trackedFactKeys.length > 0) {\n this.unsubs.push(\n this.system.facts.$store.subscribe(this.trackedFactKeys, onUpdate),\n );\n } else if (this.trackedDeriveKeys.length === 0) {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n if (this.trackedDeriveKeys.length > 0) {\n this.unsubs.push(\n this.system.subscribe(this.trackedDeriveKeys, onUpdate),\n );\n }\n } else {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n }\n\n protected subscribe(): void {\n const result = this.runWithTracking();\n this.value = result.value;\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n\n hostDisconnected(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller that watches a fact or derivation and calls a callback on change.\n * The key is auto-detected — works with both fact keys and derivation keys.\n */\nexport class WatchController<T> extends DirectiveController {\n private key: string;\n private callback: (newValue: T, previousValue: T | undefined) => void;\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. */\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n ) {\n super(host, system);\n this.key = key;\n this.callback = callback;\n }\n\n protected subscribe(): void {\n this.unsubscribe = this.system.watch<T>(this.key, this.callback);\n }\n}\n\n// ============================================================================\n// New Controllers\n// ============================================================================\n\n/**\n * Reactive controller for requirement explanations.\n */\nexport class ExplainController extends DirectiveController {\n private requirementId: string;\n value: string | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n requirementId: string,\n ) {\n super(host, system);\n this.requirementId = requirementId;\n this.value = system.explain(requirementId);\n }\n\n protected subscribe(): void {\n this.value = this.system.explain(this.requirementId);\n\n const update = () => {\n this.value = this.system.explain(this.requirementId);\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for constraint status.\n */\nexport class ConstraintStatusController extends DirectiveController {\n private constraintId?: string;\n value: ConstraintInfo[] | ConstraintInfo | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n constraintId?: string,\n ) {\n super(host, system);\n this.constraintId = constraintId;\n this.value = this.getVal();\n }\n\n private getVal(): ConstraintInfo[] | ConstraintInfo | null {\n const inspection = this.system.inspect();\n if (!this.constraintId) return inspection.constraints;\n return (\n inspection.constraints.find(\n (c: ConstraintInfo) => c.id === this.constraintId,\n ) ?? null\n );\n }\n\n protected subscribe(): void {\n this.value = this.getVal();\n\n const update = () => {\n this.value = this.getVal();\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for optimistic updates.\n */\nexport class OptimisticUpdateController implements ReactiveController {\n private host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private system: SingleModuleSystem<any>;\n private statusPlugin?: StatusPlugin;\n private requirementType?: string;\n private snapshot: SystemSnapshot | null = null;\n private statusUnsub: (() => void) | null = null;\n\n isPending = false;\n error: Error | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n ) {\n this.host = host;\n this.system = system;\n this.statusPlugin = statusPlugin;\n this.requirementType = requirementType;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n this.statusUnsub?.();\n this.statusUnsub = null;\n }\n\n rollback(): void {\n if (this.snapshot) {\n this.system.restore(this.snapshot);\n this.snapshot = null;\n }\n this.isPending = false;\n this.error = null;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n }\n\n mutate(updateFn: () => void): void {\n this.snapshot = this.system.getSnapshot();\n this.isPending = true;\n this.error = null;\n this.system.batch(updateFn);\n this.host.requestUpdate();\n\n if (this.statusPlugin && this.requirementType) {\n this.statusUnsub?.();\n this.statusUnsub = this.statusPlugin.subscribe(() => {\n const status = this.statusPlugin!.getStatus(this.requirementType!);\n if (!status.isLoading && !status.hasError) {\n this.snapshot = null;\n this.isPending = false;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n } else if (status.hasError) {\n this.error = status.lastError;\n this.rollback();\n }\n });\n }\n }\n}\n\n/**\n * Reactive controller that creates and manages a Directive system.\n * The system is automatically started when the host connects and destroyed when it disconnects.\n */\nexport class SystemController<M extends ModuleSchema>\n implements ReactiveController\n{\n private options: ModuleDef<M> | CreateSystemOptionsSingle<M>;\n private _system: SingleModuleSystem<M> | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n options: ModuleDef<M> | CreateSystemOptionsSingle<M>,\n ) {\n this.options = options;\n host.addController(this);\n }\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] SystemController.system is not available. \" +\n \"This can happen if:\\n\" +\n \" 1. Accessed before hostConnected (e.g., in a class field initializer)\\n\" +\n \" 2. Accessed after hostDisconnected (system was destroyed)\\n\" +\n \"Solution: Access system only in lifecycle methods (connectedCallback, render) \" +\n \"or after the element is connected to the DOM.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n const isModule = \"id\" in this.options && \"schema\" in this.options;\n const system = isModule\n ? createSystem({ module: this.options as ModuleDef<M> })\n : createSystem(this.options as CreateSystemOptionsSingle<M>);\n this._system = system as unknown as SingleModuleSystem<M>;\n this._system.start();\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n/**\n * Module controller — zero-config all-in-one.\n * Creates system, starts it, subscribes to all facts/derivations.\n */\nexport class ModuleController<M extends ModuleSchema>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private moduleDef: ModuleDef<M>;\n private config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n };\n\n private _system: SingleModuleSystem<M> | null = null;\n private unsubFacts?: () => void;\n private unsubDerived?: () => void;\n\n facts: InferFacts<M> = {} as InferFacts<M>;\n derived: InferDerivations<M> = {} as InferDerivations<M>;\n statusPlugin?: StatusPlugin;\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] ModuleController.system is not available before hostConnected.\",\n );\n }\n return this._system;\n }\n\n get events(): SingleModuleSystem<M>[\"events\"] {\n return this.system.events;\n }\n\n constructor(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n ) {\n this.host = host;\n this.moduleDef = moduleDef;\n this.config = config;\n host.addController(this);\n }\n\n hostConnected(): void {\n const allPlugins = [...(this.config?.plugins ?? [])];\n\n if (this.config?.status) {\n const sp = createRequirementStatusPlugin();\n this.statusPlugin = sp;\n // biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n allPlugins.push(sp.plugin as Plugin<any>);\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: this.moduleDef,\n plugins: allPlugins.length > 0 ? allPlugins : undefined,\n trace: this.config?.trace,\n errorBoundary: this.config?.errorBoundary,\n tickMs: this.config?.tickMs,\n zeroConfig: this.config?.zeroConfig,\n initialFacts: this.config?.initialFacts,\n } as any) as unknown as SingleModuleSystem<M>;\n\n this._system = system;\n system.start();\n\n // Subscribe to all facts\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.unsubFacts = system.facts.$store.subscribeAll(() => {\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.host.requestUpdate();\n });\n\n // Subscribe to all derivations\n const derivationKeys = Object.keys(system.derive ?? {});\n const getDerived = (): InferDerivations<M> => {\n const result: Record<string, unknown> = {};\n for (const key of derivationKeys) {\n result[key] = system.read(key);\n }\n return result as InferDerivations<M>;\n };\n this.derived = getDerived();\n\n if (derivationKeys.length > 0) {\n this.unsubDerived = system.subscribe(derivationKeys, () => {\n this.derived = getDerived();\n this.host.requestUpdate();\n });\n }\n }\n\n hostDisconnected(): void {\n this.unsubFacts?.();\n this.unsubDerived?.();\n this._system?.destroy();\n this._system = null;\n }\n\n dispatch(event: InferEvents<M>): void {\n this.system.dispatch(event);\n }\n}\n\n// ============================================================================\n// Factory Functions (active)\n// ============================================================================\n\nexport function createDerived<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n): DerivedController<T> {\n return new DerivedController<T>(host, system, key);\n}\n\nexport function createFact<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): FactController<T> {\n return new FactController<T>(host, system, factKey);\n}\n\n/**\n * Create an inspect controller.\n * Returns InspectState; pass `{ throttleMs }` for throttled updates.\n */\nexport function createInspect(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n): InspectController {\n return new InspectController(host, system, options);\n}\n\nexport function createRequirementStatus(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n): RequirementStatusController {\n return new RequirementStatusController(host, statusPlugin, type);\n}\n\nexport function createWatch<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n): WatchController<T> {\n return new WatchController<T>(host, system, derivationId, callback);\n}\n\nexport function createDirectiveSelector<R>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n): DirectiveSelectorController<R> {\n return new DirectiveSelectorController<R>(\n host,\n system,\n selector,\n equalityFn,\n options,\n );\n}\n\nexport function createExplain(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n requirementId: string,\n): ExplainController {\n return new ExplainController(host, system, requirementId);\n}\n\nexport function createConstraintStatus(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): ConstraintStatusController {\n return new ConstraintStatusController(host, system, constraintId);\n}\n\nexport function createOptimisticUpdate(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n): OptimisticUpdateController {\n return new OptimisticUpdateController(\n host,\n system,\n statusPlugin,\n requirementType,\n );\n}\n\nexport function createModule<M extends ModuleSchema>(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n): ModuleController<M> {\n return new ModuleController<M>(host, moduleDef, config);\n}\n\n// ============================================================================\n// Functional Helpers\n// ============================================================================\n\nexport function useDispatch<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): (event: InferEvents<M>) => void {\n assertSystem(\"useDispatch\", system);\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n}\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): SingleModuleSystem<M>[\"events\"] {\n assertSystem(\"useEvents\", system);\n return system.events;\n}\n\n/**\n * Reactive controller for history state.\n * Triggers host updates when snapshots change or navigation occurs.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private _history = new HistoryController(this, system);\n * render() {\n * const h = this._history.value;\n * return html`<button ?disabled=${!h?.canGoBack} @click=${() => h?.goBack()}>Undo</button>`;\n * }\n * }\n * ```\n */\nexport class HistoryController implements ReactiveController {\n value: HistoryState | null = null;\n private _unsub?: () => void;\n\n constructor(\n private _host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: SingleModuleSystem<any>,\n ) {\n this._host.addController(this);\n }\n\n hostConnected(): void {\n this.value = buildHistoryState(this._system);\n this._unsub = this._system.onHistoryChange(() => {\n this.value = buildHistoryState(this._system);\n this._host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this._unsub?.();\n this._unsub = undefined;\n }\n}\n\n/**\n * Functional helper for history state (non-reactive, snapshot).\n * For reactive updates, use HistoryController.\n */\n// biome-ignore lint/suspicious/noExplicitAny: System type varies\nexport function useHistory(\n system: SingleModuleSystem<any>,\n): HistoryState | null {\n assertSystem(\"useHistory\", system);\n return buildHistoryState(system);\n}\n\nexport function getDerived<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n): () => T {\n return () => system.read(derivationId) as T;\n}\n\nexport function getFact<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): () => T | undefined {\n return () => system.facts.$store.get(factKey) as T | undefined;\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => DerivedController<InferDerivations<M>[K]>;\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => FactController<InferFacts<M>[K]>;\n useDispatch: (\n system: SingleModuleSystem<M>,\n ) => (event: InferEvents<M>) => void;\n useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => WatchController<unknown>;\n} {\n return {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) =>\n createDerived<InferDerivations<M>[K]>(\n host,\n system,\n derivationId as string,\n ),\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => createFact<InferFacts<M>[K]>(host, system, factKey as string),\n useDispatch: (system: SingleModuleSystem<M>) => {\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n },\n useEvents: (system: SingleModuleSystem<M>) => system.events,\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => createWatch<unknown>(host, system, key, callback),\n };\n}\n\n// ============================================================================\n// NamespacedSelectorController — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * Reactive controller that selects from a NamespacedSystem.\n * Subscribes to specified keys and triggers host updates.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private token = new NamespacedSelectorController(\n * this, system, [\"auth.token\"], (s) => s.facts.auth.token,\n * );\n * render() {\n * return html`<span>${this.token.value}</span>`;\n * }\n * }\n * ```\n */\nexport class NamespacedSelectorController<Modules extends ModulesMap, R>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private system: NamespacedSystem<Modules>;\n private keys: string[];\n private selector: (system: NamespacedSystem<Modules>) => R;\n private unsubscribe?: () => void;\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n ) {\n this.host = host;\n this.system = system;\n this.keys = keys;\n this.selector = selector;\n this.value = selector(system);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.selector(this.system);\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.selector(this.system);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\nexport function createNamespacedSelector<Modules extends ModulesMap, R>(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n): NamespacedSelectorController<Modules, R> {\n return new NamespacedSelectorController(host, system, keys, selector);\n}\n\n// ============================================================================\n// QuerySystemController — Stable query system with Lit lifecycle\n// ============================================================================\n\n/**\n * Lit reactive controller that creates and manages a query system.\n * Starts on connect, destroys on disconnect.\n *\n * @example\n * ```typescript\n * import { LitElement, html } from \"lit\";\n * import { QuerySystemController } from \"@directive-run/lit\";\n * import { createQuerySystem } from \"@directive-run/query\";\n *\n * class MyApp extends LitElement {\n * private app = new QuerySystemController(this, () =>\n * createQuerySystem({\n * facts: { userId: \"\" },\n * queries: { user: { key: ..., fetcher: ... } },\n * autoStart: false,\n * })\n * );\n *\n * render() {\n * const user = this.app.system.read(\"user\");\n * return html`<div>${user.data?.name}</div>`;\n * }\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nexport class QuerySystemController<\n T extends {\n start: () => void;\n destroy: () => void;\n isRunning?: boolean;\n [key: string]: any;\n },\n> implements ReactiveController\n{\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: T | null = null;\n private factory: () => T;\n\n constructor(host: ReactiveControllerHost, factory: () => T) {\n this.factory = factory;\n host.addController(this);\n }\n\n get system(): T {\n if (!this._system) {\n throw new Error(\n \"[Directive] QuerySystemController.system is not available. \" +\n \"Access it only in lifecycle methods or after the element is connected.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n this._system = this.factory();\n if (!this._system.isRunning) {\n this._system.start();\n }\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n// ============================================================================\n// SSR Hydration\n// ============================================================================\n\n/**\n * Lit reactive controller for SSR hydration.\n * Accepts a DistributableSnapshot and creates a hydrated system.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private hydration = new HydrationController(this, serverSnapshot);\n * private system = this.hydration.createSystem(myModule);\n * }\n * ```\n */\nexport class HydrationController implements ReactiveController {\n private snapshot: Record<string, unknown> | undefined;\n // biome-ignore lint/suspicious/noExplicitAny: Systems vary by module schema\n private systems: SingleModuleSystem<any>[] = [];\n\n constructor(\n host: ReactiveControllerHost,\n snapshot?: Record<string, unknown>,\n ) {\n this.snapshot = snapshot;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n for (const system of this.systems) {\n system.destroy();\n }\n this.systems = [];\n }\n\n createSystem<S extends ModuleSchema>(\n moduleDef: ModuleDef<S>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n },\n ): SingleModuleSystem<S> {\n const mergedFacts = mergeHydrationFacts(\n this.snapshot,\n config?.initialFacts,\n );\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: moduleDef,\n plugins: config?.plugins,\n trace: config?.trace,\n errorBoundary: config?.errorBoundary,\n tickMs: config?.tickMs,\n zeroConfig: config?.zeroConfig,\n initialFacts: mergedFacts,\n } as any) as unknown as SingleModuleSystem<S>;\n\n this.systems.push(system);\n\n if (typeof window !== \"undefined\") {\n system.start();\n }\n\n return system;\n }\n}\n\n// ============================================================================\n// AuditLedgerController — live ledger entries with filter (R4.I parity)\n// ============================================================================\n\nimport type {\n AuditEntry,\n AuditLedger,\n QueryFilter,\n} from \"@directive-run/core\";\n\n/**\n * Reactive controller exposing the latest audit-ledger entries matching\n * `filter` as `.value`. Polls (default 250 ms — override with `pollMs`)\n * and re-renders the host on each tick that brings new matches.\n *\n * **Polling floor:** `pollMs` is clamped to a minimum of 50 ms to prevent\n * accidental DoS from typos like `pollMs: 5`. Values below the floor are\n * silently clamped in production; dev mode logs a warning.\n *\n * @example\n * ```ts\n * import { AuditLedgerController } from \"@directive-run/lit\";\n *\n * class AuditLog extends LitElement {\n * private ledgerCtrl = new AuditLedgerController(\n * this,\n * ledger,\n * { kind: \"constraint.evaluate\", limit: 20 },\n * );\n *\n * render() {\n * return html`<ul>\n * ${this.ledgerCtrl.value.map(e => html`<li>${e.kind} @ ${e.ts}</li>`)}\n * </ul>`;\n * }\n * }\n * ```\n */\nexport class AuditLedgerController implements ReactiveController {\n private host: ReactiveControllerHost;\n private ledger: AuditLedger;\n private filter: QueryFilter;\n private pollMs: number;\n private intervalId: ReturnType<typeof setInterval> | null = null;\n\n /**\n * Latest matching audit entries. Updates on each poll tick when the\n * seq-window (first/last entry seq) changes. Lit `requestUpdate()` is\n * only called when the window moves — in-place tombstone replacement\n * within the visible window does NOT trigger re-render (use the ledger's\n * onWrite hook for revision-level updates when added).\n */\n value: readonly AuditEntry[];\n\n constructor(\n host: ReactiveControllerHost,\n ledger: AuditLedger,\n filter: QueryFilter = {},\n opts: { pollMs?: number } = {},\n ) {\n this.host = host;\n this.ledger = ledger;\n this.filter = filter;\n const requestedPollMs = opts.pollMs ?? 250;\n this.pollMs = Math.max(50, requestedPollMs);\n\n if (isDevelopment) {\n if (opts.pollMs !== undefined && opts.pollMs < 50) {\n console.warn(\n `[Directive] AuditLedgerController pollMs=${opts.pollMs} is below the 50 ms floor; clamped to 50 ms.`,\n );\n }\n if (this.pollMs < 100) {\n const entryCount = ledger.toJSON().entries.length;\n if (entryCount > 1000) {\n console.warn(\n `[Directive] AuditLedgerController polling every ${this.pollMs} ms against a ${entryCount}-entry ledger — that's a lot of CPU per tick. Consider raising pollMs or tightening the filter.`,\n );\n }\n }\n }\n\n this.value = ledger.query(filter);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.intervalId = setInterval(() => {\n const next = this.ledger.query(this.filter);\n // Always replace the array reference so consumers reading\n // `.value` see the latest snapshot, but only request a render\n // when the seq-window actually moved. At steady-state capacity\n // (e.g. 10k entries rolling over) the length is constant — using\n // length-diff alone misses every change. Compare the first and\n // last seq instead. (R4.C7)\n const moved =\n next[0]?.seq !== this.value[0]?.seq ||\n next[next.length - 1]?.seq !==\n this.value[this.value.length - 1]?.seq;\n this.value = next;\n if (moved) {\n this.host.requestUpdate();\n }\n }, this.pollMs);\n }\n\n hostDisconnected(): void {\n if (this.intervalId !== null) {\n clearInterval(this.intervalId);\n this.intervalId = null;\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directive-run/lit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"imports": {
|
|
5
5
|
"#is-development": {
|
|
6
6
|
"production": "./src/dev-false.ts",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"lit": "^3.1.0",
|
|
59
59
|
"tsup": "^8.3.5",
|
|
60
60
|
"typescript": "^5.7.2",
|
|
61
|
-
"@directive-run/core": "1.
|
|
61
|
+
"@directive-run/core": "1.13.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "tsup",
|