@directive-run/core 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter-utils.cjs +1 -1
- package/dist/adapter-utils.js +1 -1
- package/dist/chunk-4AN3P4W5.cjs +3 -0
- package/dist/chunk-4AN3P4W5.cjs.map +1 -0
- package/dist/chunk-GSXCAMNZ.js +2 -0
- package/dist/chunk-GSXCAMNZ.js.map +1 -0
- package/dist/{chunk-MPOV2REO.js → chunk-MXIBBD7Z.js} +3 -3
- package/dist/{chunk-MPOV2REO.js.map → chunk-MXIBBD7Z.js.map} +1 -1
- package/dist/chunk-PUZVNO5U.js +3 -0
- package/dist/chunk-PUZVNO5U.js.map +1 -0
- package/dist/{chunk-3H24Z7WM.cjs → chunk-SLHKLDQR.cjs} +3 -3
- package/dist/{chunk-3H24Z7WM.cjs.map → chunk-SLHKLDQR.cjs.map} +1 -1
- package/dist/chunk-WFIJ6OST.cjs +2 -0
- package/dist/chunk-WFIJ6OST.cjs.map +1 -0
- package/dist/{helpers-CU3Il0tz.d.cts → helpers-Akay-GZq.d.cts} +1 -7
- package/dist/{helpers-Bd_P3ZTY.d.ts → helpers-CDNl3Rd2.d.ts} +1 -7
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/internals.cjs +1 -1
- package/dist/internals.d.cts +9 -11
- package/dist/internals.d.ts +9 -11
- package/dist/internals.js +1 -1
- package/dist/system-CWUYJT43.cjs +2 -0
- package/dist/{system-QQYBNE7A.cjs.map → system-CWUYJT43.cjs.map} +1 -1
- package/dist/system-TM7ZQZYW.js +2 -0
- package/dist/{system-AGVKMAYF.js.map → system-TM7ZQZYW.js.map} +1 -1
- package/dist/testing.cjs +1 -1
- package/dist/testing.js +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-AUSBUCOL.cjs +0 -3
- package/dist/chunk-AUSBUCOL.cjs.map +0 -1
- package/dist/chunk-EFBBEXDA.js +0 -2
- package/dist/chunk-EFBBEXDA.js.map +0 -1
- package/dist/chunk-ER6QUYTL.cjs +0 -2
- package/dist/chunk-ER6QUYTL.cjs.map +0 -1
- package/dist/chunk-YWKFNZQV.js +0 -3
- package/dist/chunk-YWKFNZQV.js.map +0 -1
- package/dist/system-AGVKMAYF.js +0 -2
- package/dist/system-QQYBNE7A.cjs +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function o(t,e,r){t[e]=r;}function i(t,e){return t[e]}function s(t,e){return {name:t,onRequirementCreated:e.onRequirementCreated?r=>e.onRequirementCreated(r.requirement):void 0,onRequirementMet:e.onRequirementResolved?r=>e.onRequirementResolved(r.requirement):void 0,onError:e.onError}}function a(t){return e=>e.type===t}function u(t){let e=new Set(t);return r=>e.has(r.type)}var n=[];function d(){let t=n.length;return t===0?null:n[t-1]}function R(){return n.length>0}function m(t){let e=new Set;n.push(e);try{return {value:t(),deps:e}}finally{n.pop();}}function p(t){let e=n.splice(0,n.length);try{return t()}finally{for(let r of e)n.push(r);}}function l(t){let e=n.length;e!==0&&n[e-1].add(t);}var q=Object.freeze(new Set(["__proto__","constructor","prototype"]));export{o as a,i as b,s as c,a as d,u as e,d as f,R as g,m as h,p as i,l as j,q as k};//# sourceMappingURL=chunk-GSXCAMNZ.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-GSXCAMNZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/types/adapter-utils.ts","../src/core/tracking.ts"],"names":["setBridgeFact","facts","key","value","getBridgeFact","createCallbackPlugin","name","callbacks","req","requirementGuard","type","requirementGuardMultiple","types","typeSet","depStack","getCurrentDeps","len","isTracking","withTracking","fn","deps","withoutTracking","saved","ctx","trackAccess","BLOCKED_PROPS"],"mappings":"AA8FO,SAASA,CAAAA,CACdC,EACAC,CAAAA,CACAC,CAAAA,CACM,CACLF,CAAAA,CAAkCC,CAAG,EAAIC,EAC5C,CAWO,SAASC,CAAAA,CAAiBH,CAAAA,CAAsBC,EAAgB,CACrE,OAAQD,EAAkCC,CAAG,CAC/C,CAyJO,SAASG,CAAAA,CACdC,CAAAA,CACAC,EACa,CACb,OAAO,CACL,IAAA,CAAAD,CAAAA,CACA,qBAAsBC,CAAAA,CAAU,oBAAA,CAC3BC,GAAQD,CAAAA,CAAU,oBAAA,CAAsBC,EAAI,WAAW,CAAA,CACxD,OACJ,gBAAA,CAAkBD,CAAAA,CAAU,sBACvBC,CAAAA,EAAQD,CAAAA,CAAU,qBAAA,CAAuBC,CAAAA,CAAI,WAAW,CAAA,CACzD,OACJ,OAAA,CAASD,CAAAA,CAAU,OACrB,CACF,CAyCO,SAASE,CAAAA,CACdC,CAAAA,CACgC,CAChC,OAAQF,CAAAA,EAAkBA,EAAI,IAAA,GAASE,CACzC,CAUO,SAASC,CAAAA,CACdC,EACgC,CAChC,IAAMC,CAAAA,CAAU,IAAI,GAAA,CAAID,CAAK,EAC7B,OAAQJ,CAAAA,EAAkBK,EAAQ,GAAA,CAAIL,CAAAA,CAAI,IAAI,CAChD,CC5UA,IAAMM,CAAAA,CAA0B,GASzB,SAASC,CAAAA,EAAqC,CACnD,IAAMC,CAAAA,CAAMF,EAAS,MAAA,CACrB,OAAOE,CAAAA,GAAQ,CAAA,CAAI,IAAA,CAAOF,CAAAA,CAASE,EAAM,CAAC,CAC5C,CASO,SAASC,CAAAA,EAAsB,CACpC,OAAOH,CAAAA,CAAS,OAAS,CAC3B,CAgBO,SAASI,CAAAA,CAAgBC,CAAAA,CAA8C,CAC5E,IAAMC,CAAAA,CAAO,IAAI,GAAA,CACjBN,CAAAA,CAAS,IAAA,CAAKM,CAAI,CAAA,CAElB,GAAI,CAEF,OAAO,CAAE,MADKD,CAAAA,EAAG,CACD,KAAAC,CAAK,CACvB,QAAE,CACAN,CAAAA,CAAS,MACX,CACF,CAgBO,SAASO,CAAAA,CAAmBF,EAAgB,CACjD,IAAMG,CAAAA,CAAQR,CAAAA,CAAS,MAAA,CAAO,CAAA,CAAGA,EAAS,MAAM,CAAA,CAEhD,GAAI,CACF,OAAOK,GACT,CAAA,OAAE,CACA,IAAA,IAAWI,CAAAA,IAAOD,EAChBR,CAAAA,CAAS,IAAA,CAAKS,CAAG,EAErB,CACF,CAYO,SAASC,CAAAA,CAAYtB,CAAAA,CAAmB,CAC7C,IAAMc,CAAAA,CAAMF,EAAS,MAAA,CACjBE,CAAAA,GAAQ,GAGZF,CAAAA,CAASE,CAAAA,CAAM,CAAC,CAAA,CAAG,GAAA,CAAId,CAAG,EAC5B,KAYauB,CAAAA,CAAqC,MAAA,CAAO,OACvD,IAAI,GAAA,CAAI,CAAC,WAAA,CAAa,aAAA,CAAe,WAAW,CAAC,CACnD","file":"chunk-GSXCAMNZ.js","sourcesContent":["/**\n * Adapter Type Utilities - Shared types and helpers for framework adapters\n *\n * These utilities reduce type assertions in adapters by providing:\n * - Schema composition types\n * - Constraint/resolver converters\n * - Plugin factory helpers\n */\n\nimport type { Facts } from \"./facts.js\";\nimport type { Plugin } from \"./plugins.js\";\nimport type { ConstraintDef, Requirement } from \"./requirements.js\";\nimport type { ResolverContext, ResolverDef } from \"./resolvers.js\";\nimport type { InferSchema, Schema } from \"./schema.js\";\n\n// ============================================================================\n// Schema Composition Types\n// ============================================================================\n\n/**\n * Merge two schemas into one.\n * Useful for adapters that add bridge-specific facts to user schemas.\n *\n * @example\n * ```typescript\n * type BridgeFields = { __state: SchemaType<Record<string, unknown>> };\n * type Combined = MergedSchema<UserSchema, BridgeFields>;\n * ```\n */\nexport type MergedSchema<Base extends Schema, Extra extends Schema> = Base &\n Extra;\n\n/**\n * Create a schema type from a fields definition.\n * Helper for defining adapter bridge schemas.\n *\n * @example\n * ```typescript\n * type AdapterBridgeSchema = BridgeSchema<{\n * __adapterState: SchemaType<Record<string, unknown>>;\n * }>;\n * ```\n */\nexport type BridgeSchema<Fields extends Schema> = Fields;\n\n// ============================================================================\n// Bridge Schema Helper\n// ============================================================================\n\n/**\n * Create a bridge schema definition for adapters.\n * Returns a schema object compatible with createModule().\n *\n * @example\n * ```typescript\n * const bridgeSchema = createBridgeSchema({\n * __state: t.object<Record<string, unknown>>(),\n * });\n * ```\n */\nexport function createBridgeSchema<S extends Schema>(schema: S): S {\n return schema;\n}\n\n// ============================================================================\n// Type-Safe Fact Mutation\n// ============================================================================\n\n/**\n * Type-safe fact setter for known schema keys.\n * Use when you have a typed schema and want to set a specific fact.\n *\n * @example\n * ```typescript\n * setFact(facts, \"count\", 10); // Type-checked\n * ```\n */\nexport function setFact<S extends Schema, K extends keyof InferSchema<S>>(\n facts: Facts<S>,\n key: K,\n value: InferSchema<S>[K],\n): void {\n (facts as Record<string, unknown>)[key as string] = value;\n}\n\n/**\n * Set a bridge fact without strict typing.\n * Use for adapter-internal bridge fields like `__adapterState`.\n *\n * @example\n * ```typescript\n * setBridgeFact(facts, \"__adapterState\", currentState);\n * ```\n */\nexport function setBridgeFact<V>(\n facts: Facts<Schema>,\n key: string,\n value: V,\n): void {\n (facts as Record<string, unknown>)[key] = value;\n}\n\n/**\n * Get a bridge fact without strict typing.\n * Use for adapter-internal bridge fields.\n *\n * @example\n * ```typescript\n * const state = getBridgeFact<MyState>(facts, \"__adapterState\");\n * ```\n */\nexport function getBridgeFact<V>(facts: Facts<Schema>, key: string): V {\n return (facts as Record<string, unknown>)[key] as V;\n}\n\n// ============================================================================\n// Constraint Converters\n// ============================================================================\n\n/**\n * Adapter constraint definition (generic form used by adapters).\n */\nexport interface AdapterConstraint<TState> {\n when: (state: TState) => boolean | Promise<boolean>;\n require: Requirement | ((state: TState) => Requirement | null);\n priority?: number;\n}\n\n/**\n * Convert adapter-style constraints to Directive format.\n * Maps adapter constraints that work with external state (TState) to\n * Directive constraints that work with Facts<Schema>.\n *\n * @param constraints - Adapter constraints keyed by name\n * @param extractState - Function to extract adapter state from facts\n *\n * @example\n * ```typescript\n * const directiveConstraints = convertConstraints<MyState, BridgeSchema>(\n * adapterConstraints,\n * (facts) => getBridgeFact<MyState>(facts, \"__state\"),\n * );\n * ```\n */\nexport function convertConstraints<TState, S extends Schema>(\n constraints: Record<string, AdapterConstraint<TState>>,\n extractState: (facts: Facts<S>) => TState,\n): Record<string, ConstraintDef<S, Requirement>> {\n const result: Record<string, ConstraintDef<S, Requirement>> = {};\n\n for (const [id, constraint] of Object.entries(constraints)) {\n result[id] = {\n priority: constraint.priority ?? 0,\n when: (facts) => constraint.when(extractState(facts)),\n require: (facts) => {\n const req =\n typeof constraint.require === \"function\"\n ? constraint.require(extractState(facts))\n : constraint.require;\n return req;\n },\n };\n }\n\n return result;\n}\n\n// ============================================================================\n// Resolver Converters\n// ============================================================================\n\n/**\n * Adapter resolver context (generic form used by adapters).\n */\nexport interface AdapterResolverContext<TContext> {\n context: TContext;\n signal: AbortSignal;\n}\n\n/**\n * Adapter resolver definition (generic form used by adapters).\n */\nexport interface AdapterResolver<\n TContext,\n R extends Requirement = Requirement,\n> {\n requirement: (req: Requirement) => req is R;\n key?: (req: R) => string;\n resolve: (\n req: R,\n ctx: AdapterResolverContext<TContext>,\n ) => void | Promise<void>;\n}\n\n/**\n * Convert adapter-style resolvers to Directive format.\n * Maps adapter resolvers that work with external context (TContext) to\n * Directive resolvers that work with ResolverContext<Schema>.\n *\n * @param resolvers - Adapter resolvers keyed by name\n * @param createContext - Function to create adapter context from Directive context\n *\n * @example\n * ```typescript\n * const directiveResolvers = convertResolvers<MyContext, BridgeSchema>(\n * adapterResolvers,\n * (ctx) => ({\n * getState: () => getBridgeFact<MyState>(ctx.facts, \"__state\"),\n * setState: (update) => setBridgeFact(ctx.facts, \"__state\", update),\n * signal: ctx.signal,\n * }),\n * );\n * ```\n */\nexport function convertResolvers<TContext, S extends Schema>(\n resolvers: Record<string, AdapterResolver<TContext, Requirement>>,\n createContext: (ctx: ResolverContext<S>) => TContext,\n): Record<string, ResolverDef<S, Requirement>> {\n const result: Record<string, ResolverDef<S, Requirement>> = {};\n\n for (const [id, resolver] of Object.entries(resolvers)) {\n result[id] = {\n requirement: resolver.requirement,\n key: resolver.key,\n resolve: async (req, ctx) => {\n const adapterCtx = createContext(ctx);\n await resolver.resolve(req, {\n context: adapterCtx,\n signal: ctx.signal,\n });\n },\n };\n }\n\n return result;\n}\n\n// ============================================================================\n// Plugin Factory\n// ============================================================================\n\n/**\n * Callback definitions for adapter plugins.\n */\nexport interface AdapterCallbacks {\n onRequirementCreated?: (req: Requirement) => void;\n onRequirementResolved?: (req: Requirement) => void;\n onError?: (error: Error) => void;\n}\n\n/**\n * Create a callback plugin for adapter events.\n * Wraps adapter callbacks in a Directive plugin.\n *\n * @param name - Plugin name (for debugging)\n * @param callbacks - Callback functions to invoke\n *\n * @example\n * ```typescript\n * const callbackPlugin = createCallbackPlugin(\"adapter-callbacks\", {\n * onRequirementCreated: (req) => console.log(\"Created:\", req),\n * onRequirementResolved: (req) => console.log(\"Resolved:\", req),\n * });\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Plugins work with any schema type\nexport function createCallbackPlugin(\n name: string,\n callbacks: AdapterCallbacks,\n): Plugin<any> {\n return {\n name,\n onRequirementCreated: callbacks.onRequirementCreated\n ? (req) => callbacks.onRequirementCreated!(req.requirement)\n : undefined,\n onRequirementMet: callbacks.onRequirementResolved\n ? (req) => callbacks.onRequirementResolved!(req.requirement)\n : undefined,\n onError: callbacks.onError,\n };\n}\n\n// ============================================================================\n// Module Config Helpers\n// ============================================================================\n\n/**\n * Cast constraints to the correct type for createModule.\n * Use this when TypeScript can't infer the constraint types correctly.\n */\nexport function asConstraints<S extends Schema>(\n constraints: Record<string, ConstraintDef<S, Requirement>>,\n): Record<string, ConstraintDef<S, Requirement>> {\n return constraints;\n}\n\n/**\n * Cast resolvers to the correct type for createModule.\n * Use this when TypeScript can't infer the resolver types correctly.\n */\nexport function asResolvers<S extends Schema>(\n resolvers: Record<string, ResolverDef<S, Requirement>>,\n): Record<string, ResolverDef<S, Requirement>> {\n return resolvers;\n}\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\n/**\n * Create a type guard for a specific requirement type.\n * Simplifies the common pattern of checking req.type.\n *\n * @example\n * ```typescript\n * const isResetReq = requirementGuard<ResetReq>(\"RESET\");\n * // Use in resolver:\n * { requirement: isResetReq, resolve: ... }\n * ```\n */\nexport function requirementGuard<R extends Requirement>(\n type: R[\"type\"],\n): (req: Requirement) => req is R {\n return (req): req is R => req.type === type;\n}\n\n/**\n * Create a type guard that matches multiple requirement types.\n *\n * @example\n * ```typescript\n * const isDataReq = requirementGuardMultiple<FetchReq | RefreshReq>([\"FETCH\", \"REFRESH\"]);\n * ```\n */\nexport function requirementGuardMultiple<R extends Requirement>(\n types: Array<R[\"type\"]>,\n): (req: Requirement) => req is R {\n const typeSet = new Set(types);\n return (req): req is R => typeSet.has(req.type);\n}\n","/**\n * Dependency tracking context for auto-tracking derivations\n *\n * Uses a stack-based approach to handle nested derivation computations.\n * When a derivation accesses a fact, the tracking context records it.\n */\n\n/** Stack of active dependency sets (bare Sets for zero-allocation hot path) */\nconst depStack: Set<string>[] = [];\n\n/**\n * Get the current dependency set, or null if not tracking.\n *\n * @returns The active dependency Set, or `null` if no tracking is active.\n *\n * @internal\n */\nexport function getCurrentDeps(): Set<string> | null {\n const len = depStack.length;\n return len === 0 ? null : depStack[len - 1]!;\n}\n\n/**\n * Check if dependency tracking is currently active.\n *\n * @returns `true` if inside a {@link withTracking} call, `false` otherwise.\n *\n * @internal\n */\nexport function isTracking(): boolean {\n return depStack.length > 0;\n}\n\n/**\n * Run a function with dependency tracking.\n *\n * @remarks\n * Pushes a fresh Set onto the stack, executes `fn`, then pops it.\n * Any fact reads inside `fn` are recorded as dependencies.\n * Nesting is supported — inner calls get their own independent Set.\n *\n * @param fn - The function to execute under tracking.\n * @returns An object with the computed `value` and a `deps` Set of accessed\n * fact keys.\n *\n * @internal\n */\nexport function withTracking<T>(fn: () => T): { value: T; deps: Set<string> } {\n const deps = new Set<string>();\n depStack.push(deps);\n\n try {\n const value = fn();\n return { value, deps };\n } finally {\n depStack.pop();\n }\n}\n\n/**\n * Run a function without tracking.\n *\n * @remarks\n * Temporarily clears the tracking stack so that fact reads inside `fn` do\n * not register as dependencies. The stack is restored after `fn` returns\n * (even on error). Useful for side-effect reads that should not trigger\n * derivation invalidation.\n *\n * @param fn - The function to execute without tracking.\n * @returns The return value of `fn`.\n *\n * @internal\n */\nexport function withoutTracking<T>(fn: () => T): T {\n const saved = depStack.splice(0, depStack.length);\n\n try {\n return fn();\n } finally {\n for (const ctx of saved) {\n depStack.push(ctx);\n }\n }\n}\n\n/**\n * Track a specific key in the current context.\n *\n * @remarks\n * No-op if no tracking context is active.\n *\n * @param key - The fact key to record as a dependency.\n *\n * @internal\n */\nexport function trackAccess(key: string): void {\n const len = depStack.length;\n if (len === 0) {\n return;\n }\n depStack[len - 1]!.add(key);\n}\n\n/**\n * Prototype pollution guard — shared across all proxy handlers.\n *\n * @remarks\n * Contains `__proto__`, `constructor`, and `prototype`. Every proxy `get`\n * and `has` trap checks this set and returns `undefined` / `false` for\n * matching keys, preventing prototype pollution via proxy-based objects.\n *\n * @internal\n */\nexport const BLOCKED_PROPS: ReadonlySet<string> = Object.freeze(\n new Set([\"__proto__\", \"constructor\", \"prototype\"]),\n);\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {z as z$1,a}from'./chunk-
|
|
1
|
+
import {z as z$1,a}from'./chunk-PUZVNO5U.js';import {k}from'./chunk-GSXCAMNZ.js';import {c}from'./chunk-4CMO5OVZ.js';var y="::";function S(n){return new Proxy({},{get(e,t){if(typeof t!="symbol"&&!k.has(t))return n.get(t)},set(e,t,o){return typeof t=="symbol"||k.has(t)?false:n.set?n.set(t,o):false},has(e,t){return typeof t=="symbol"||k.has(t)?false:n.has?n.has(t):false},deleteProperty(e,t){return typeof t=="symbol"||k.has(t)?false:n.delete?n.delete(t):false},ownKeys(){return n.ownKeys?n.ownKeys():[]},getOwnPropertyDescriptor(e,t){if(typeof t!="symbol"&&n.has&&typeof t=="string"&&n.has(t))return {configurable:true,enumerable:true}},defineProperty(){return false},getPrototypeOf(){return null},setPrototypeOf(){return false}})}var I=new WeakMap,H=new WeakMap,V=new WeakMap,W=new WeakMap,z=new WeakMap,U=new WeakMap;function D(n,e){let t=I.get(n);if(t){let r=t.get(e);if(r)return r}else t=new Map,I.set(n,t);let o=S({get:r=>r==="$store"||r==="$snapshot"?n[r]:n[`${e}${y}${r}`],set:(r,a)=>(n[`${e}${y}${r}`]=a,true),has:r=>`${e}${y}${r}`in n,delete:r=>(delete n[`${e}${y}${r}`],true)});return t.set(e,o),o}function G(n,e,t){let o=H.get(n);if(o)return o;let r=S({get:a=>{if(Object.hasOwn(e,a))return D(n,a)},has:a=>Object.hasOwn(e,a),ownKeys:()=>t()});return H.set(n,r),r}function L(n,e,t){let o=`${e}|${t.join(",")}`,r=z.get(n);if(r){let i=r.get(o);if(i)return i}else r=new Map,z.set(n,r);let a=new Set(t),u=["self",...t],f=S({get:i=>{if(i==="self")return D(n,e);if(a.has(i))return D(n,i);process.env.NODE_ENV!=="production"&&console.warn(`[Directive] Module "${e}" accessed undeclared cross-module property "${i}". Add it to crossModuleDeps or use "facts.self.${i}" for own module facts.`);},has:i=>i==="self"||a.has(i),ownKeys:()=>u});return r.set(o,f),f}function F(n,e){let t=W.get(n);if(t){let r=t.get(e);if(r)return r}else t=new Map,W.set(n,t);let o=S({get:r=>n[`${e}${y}${r}`],has:r=>`${e}${y}${r}`in n});return t.set(e,o),o}function Z(n,e,t){let o=V.get(n);if(o)return o;let r=S({get:a=>{if(Object.hasOwn(e,a))return F(n,a)},has:a=>Object.hasOwn(e,a),ownKeys:()=>t()});return V.set(n,r),r}function J(n,e,t){let o=U.get(n);return o||(o=new Map,U.set(n,o)),S({get:r=>{if(!Object.hasOwn(e,r))return;let a=o.get(r);if(a)return a;let u=S({get:f=>i=>{n.dispatch({type:`${r}${y}${f}`,...i});}});return o.set(r,u),u},has:r=>Object.hasOwn(e,r),ownKeys:()=>t()})}function v(n){if(n.includes(".")){let[e,...t]=n.split(".");return `${e}${y}${t.join(y)}`}return n}function A(n){let e={};for(let[t,o]of Object.entries(n)){let r=t.indexOf(y);if(r>0){let a=t.slice(0,r),u=t.slice(r+y.length);e[a]||(e[a]={}),e[a][u]=o;}else e._root||(e._root={}),e._root[t]=o;}return e}function O(n,e,t,o){return t?L(n,e,o):D(n,e)}function M(n,e){return `${n}${y}${e}`}function $(n){return Object.keys(n).length>0?n:void 0}function re(n,e){let t={};for(let[o,r]of Object.entries(n.schema.facts))t[M(e,o)]=r;return t}function se(n,e){if(n.init)return t=>{let o=D(t,e);n.init(o);}}function oe(n,e,t,o){if(!n.derive)return;let r={};for(let[a$1,u]of Object.entries(n.derive)){let f=a(u),i=f?u.compute:u,w=f?u.meta:void 0,g=(d,m)=>{let b=O(d,e,t,o),h=F(m,e);return i(b,h)};r[M(e,a$1)]=w?{compute:g,meta:w}:g;}return $(r)}function ie(n,e){if(!n.events)return;let t={};for(let[o,r]of Object.entries(n.events)){let a=typeof r=="object"&&r!==null&&Object.hasOwn(r,"handler"),u=a?r.handler:r,f=a?r.meta:void 0,i=(w,g)=>{let d=D(w,e);u(d,g);};t[M(e,o)]=f?{handler:i,meta:f}:i;}return $(t)}function ae(n,e,t,o){if(!n.constraints)return;let r={};for(let[a,u]of Object.entries(n.constraints)){let f=u;r[M(e,a)]={...f,deps:f.deps?.map(i=>M(e,i)),after:f.after?.map(i=>i.includes(y)?i:M(e,i)),when:i=>{let w=O(i,e,t,o);return f.when(w)},require:typeof f.require=="function"?i=>{let w=O(i,e,t,o);return f.require(w)}:f.require};}return $(r)}function ce(n,e,t,o){if(!n.resolvers)return;let r={};for(let[u,f]of Object.entries(n.resolvers)){let w=function(g){return {facts:O(g.facts,e,t,o),signal:g.signal}};let i=f;r[M(e,u)]={...i,...i.resolve&&{resolve:async(g,d)=>{await i.resolve(g,w(d));}},...i.resolveBatch&&{resolveBatch:async(g,d)=>{await i.resolveBatch(g,w(d));}},...i.resolveBatchWithResults&&{resolveBatchWithResults:async(g,d)=>i.resolveBatchWithResults(g,w(d))}};}return $(r)}function ue(n,e,t,o){if(!n.effects)return;let r={};for(let[a,u]of Object.entries(n.effects)){let f=u;r[M(e,a)]={...f,run:(i,w)=>{let g=O(i,e,t,o),d=w?O(w,e,t,o):void 0;return f.run(g,d)},deps:f.deps?.map(i=>M(e,i))};}return $(r)}function de(n,e,t){return {snapshotEvents:t&&!t.has(e)?[]:n.history?.snapshotEvents?.map(o=>M(e,o))}}function T(n){let{mod:e,namespace:t,snapshotModulesSet:o}=n,r=!!(e.crossModuleDeps&&Object.keys(e.crossModuleDeps).length>0),a=r?Object.keys(e.crossModuleDeps):[];return {id:e.id,schema:re(e,t),requirements:e.schema.requirements??{},init:se(e,t),derive:oe(e,t,r,a),events:ie(e,t),effects:ue(e,t,r,a),constraints:ae(e,t,r,a),resolvers:ce(e,t,r,a),hooks:e.hooks,meta:e.meta,history:de(e,t,o)}}function le(n){let e=Object.keys(n),t=new Set(e),o=new Set,r=new Set,a=[],u=[];function f(i){if(o.has(i))return;if(r.has(i)){let g=u.indexOf(i),d=[...u.slice(g),i].join(" \u2192 ");throw new Error(`[Directive] Circular dependency detected: ${d}. Modules cannot have circular crossModuleDeps. Break the cycle by removing one of the cross-module references.`)}r.add(i),u.push(i);let w=n[i];if(w?.crossModuleDeps)for(let g of Object.keys(w.crossModuleDeps))t.has(g)&&f(g);u.pop(),r.delete(i),o.add(i),a.push(i);}for(let i of e)f(i);return a}function Q(n,e){let t=[];for(let o of Object.keys(e.schema.facts))t.push(`${n}${y}${o}`);if(e.schema.derivations)for(let o of Object.keys(e.schema.derivations))t.push(`${n}${y}${o}`);return t}function Se(n){if("module"in n){if(!n.module)throw new Error("[Directive] createSystem requires a module. Got: "+typeof n.module);return ye(n)}let e=n;if(Array.isArray(e.modules))throw new Error(`[Directive] createSystem expects modules as an object, not an array.
|
|
2
2
|
|
|
3
3
|
Instead of:
|
|
4
4
|
createSystem({ modules: [authModule, dataModule] })
|
|
@@ -12,5 +12,5 @@ Or for a single module:
|
|
|
12
12
|
createSystem({ module: myModule })
|
|
13
13
|
|
|
14
14
|
For multiple modules, wrap in an object:
|
|
15
|
-
createSystem({ modules: { myName: myModule } })`);return fe(e)}function fe(n){let e=n.modules,t=new Set(Object.keys(e)),o=typeof n.history=="object"?n.history:null,r=o?.snapshotModules?new Set(o.snapshotModules):null;if(n.tickMs!==void 0&&n.tickMs<=0)throw new Error("[Directive] tickMs must be a positive number");if(process.env.NODE_ENV!=="production"){for(let[s,c]of Object.entries(e))if(c.crossModuleDeps)for(let l of Object.keys(c.crossModuleDeps))l===s?console.warn(`[Directive] Module "${s}" references itself in crossModuleDeps. Use "facts.self" to access own module's facts instead.`):t.has(l)||console.warn(`[Directive] Module "${s}" declares crossModuleDeps.${l}, but no module with namespace "${l}" exists in the system. Available modules: ${[...t].join(", ")}`);}if(process.env.NODE_ENV!=="production"&&o?.snapshotModules)for(let s of o.snapshotModules)t.has(s)||console.warn(`[Directive] history.snapshotModules entry "${s}" doesn't match any module. Available modules: ${[...t].join(", ")}`);let a,u=n.initOrder??"auto";if(Array.isArray(u)){let s=u,c=Object.keys(e).filter(l=>!s.includes(l));if(c.length>0)throw new Error(`[Directive] initOrder is missing modules: ${c.join(", ")}. All modules must be included in the explicit order.`);a=s;}else u==="declaration"?a=Object.keys(e):a=le(e);let{history:f,trace:i,errorBoundary:w}=X(n);for(let s of Object.keys(e)){if(s.includes(y))throw new Error(`[Directive] Module name "${s}" contains the reserved separator "${y}". Module names cannot contain "${y}".`);let c=e[s];if(c){for(let l of Object.keys(c.schema.facts))if(l.includes(y))throw new Error(`[Directive] Schema key "${l}" in module "${s}" contains the reserved separator "${y}". Schema keys cannot contain "${y}".`)}}let g={names:null};function d(){return g.names===null&&(g.names=Object.keys(e)),g.names}let m=a.map(s=>{let c=e[s];return c?T({mod:c,namespace:s,snapshotModulesSet:r}):null}).filter(s=>s!==null);process.env.NODE_ENV!=="production"&&n.tickMs&&n.tickMs>0&&(m.some(c=>c.events&&Object.keys(c.events).some(l=>l.endsWith(`${y}tick`)))||console.warn(`[Directive] tickMs is set to ${n.tickMs}ms but no module defines a "tick" event handler.`));let b=null,h=null;function _(s){for(let[c$1,l]of Object.entries(s)){if(k.has(c$1)){process.env.NODE_ENV!=="production"&&console.warn(`[Directive] initialFacts/hydrate contains blocked namespace "${c$1}". Skipping.`);continue}if(!t.has(c$1)){process.env.NODE_ENV!=="production"&&console.warn(`[Directive] initialFacts/hydrate contains unknown namespace "${c$1}". Available modules: ${[...t].join(", ")}`);continue}if(l&&typeof l=="object"&&!c(l))throw new Error(`[Directive] initialFacts/hydrate for namespace "${c$1}" contains potentially dangerous keys (__proto__, constructor, or prototype). This may indicate a prototype pollution attack.`);for(let[p,R]of Object.entries(l))k.has(p)||(h.facts[`${c$1}${y}${p}`]=R);}}h=z$1({modules:m,plugins:n.plugins,history:f,trace:i,errorBoundary:w,tickMs:n.tickMs,cloud:n.cloud,onAfterModuleInit:()=>{n.initialFacts&&_(n.initialFacts),b&&(_(b),b=null);}});let x=new Map;for(let s of Object.keys(e)){let c=e[s];c&&x.set(s,Q(s,c));}let B=G(h.facts,e,d),ne=Z(h.derive,e,d),te=J(h,e,d),E=null,j=n.tickMs,N={_mode:"namespaced",facts:B,history:h.history,derive:ne,events:te,constraints:h.constraints,effects:h.effects,resolvers:h.resolvers,async hydrate(s){if(h.isRunning)throw new Error("[Directive] hydrate() must be called before start(). The system is already running.");let c=await s();c&&typeof c=="object"&&(b=c);},initialize(){h.initialize();},start(){if(h.start(),j&&j>0){let s;for(let c of m)if(c?.events&&(s=Object.keys(c.events).find(l=>l.endsWith(`${y}tick`)),s))break;if(s){let c=s;E=setInterval(()=>{h.dispatch({type:c});},j);}}},stop(){E&&(clearInterval(E),E=null),h.stop();},destroy(){this.stop(),h.destroy();},dispatch(s){h.dispatch(s);},read(s){return h.read(v(s))},subscribe(s,c){let l=[];for(let p of s)if(p.endsWith(".*")){let R=p.slice(0,-2),K=x.get(R);K?l.push(...K):process.env.NODE_ENV!=="production"&&console.warn(`[Directive] subscribe wildcard "${p}" \u2014 namespace "${R}" not found.`);}else l.push(v(p));return h.subscribe(l,c)},subscribeModule(s,c){let l=x.get(s);return !l||l.length===0?(process.env.NODE_ENV!=="production"&&console.warn(`[Directive] subscribeModule("${s}") \u2014 namespace not found. Available: ${[...x.keys()].join(", ")}`),()=>{}):h.subscribe(l,c)},watch(s,c,l){return h.watch(v(s),c,l)},when(s,c){return h.when(()=>s(B),c)},getDistributableSnapshot(s){let c={...s,includeDerivations:s?.includeDerivations?.map(v),excludeDerivations:s?.excludeDerivations?.map(v),includeFacts:s?.includeFacts?.map(v)},l=h.getDistributableSnapshot(c);return {...l,data:A(l.data)}},watchDistributableSnapshot(s,c){let l={...s,includeDerivations:s?.includeDerivations?.map(v),excludeDerivations:s?.excludeDerivations?.map(v),includeFacts:s?.includeFacts?.map(v)};return h.watchDistributableSnapshot(l,p=>{c({...p,data:A(p.data)});})},registerModule(s,c){if(t.has(s))throw new Error(`[Directive] Module namespace "${s}" already exists. Cannot register a duplicate namespace.`);if(s.includes(y))throw new Error(`[Directive] Module name "${s}" contains the reserved separator "${y}".`);if(k.has(s))throw new Error(`[Directive] Module name "${s}" is a blocked property.`);for(let R of Object.keys(c.schema.facts))if(R.includes(y))throw new Error(`[Directive] Schema key "${R}" in module "${s}" contains the reserved separator "${y}".`);let l=c,p=T({mod:l,namespace:s,snapshotModulesSet:r});t.add(s),e[s]=l,g.names=null,x.set(s,Q(s,l)),h.registerModule(p);}};return Y(N,h),ee(N),N}function X(n){let e=n.history,t=n.trace,o=n.errorBoundary;if(n.zeroConfig){let r=process.env.NODE_ENV!=="production";e=e??r,o={onConstraintError:"skip",onResolverError:"skip",onEffectError:"skip",onDerivationError:"skip",...n.errorBoundary};}return {history:e,trace:t,errorBoundary:o}}function Y(n,e){Object.defineProperties(n,{trace:{get(){return e.trace},enumerable:true,configurable:true},meta:{value:e.meta,enumerable:true,configurable:true},isRunning:{get(){return e.isRunning},enumerable:true,configurable:true},isSettled:{get(){return e.isSettled},enumerable:true,configurable:true},isInitialized:{get(){return e.isInitialized},enumerable:true,configurable:true},isReady:{get(){return e.isReady},enumerable:true,configurable:true}}),n.whenReady=e.whenReady.bind(e),n.batch=e.batch.bind(e),n.onSettledChange=e.onSettledChange.bind(e),n.onHistoryChange=e.onHistoryChange.bind(e),n.inspect=e.inspect.bind(e),n.settle=e.settle.bind(e),n.explain=e.explain.bind(e),n.getSnapshot=e.getSnapshot.bind(e),n.restore=e.restore.bind(e);let t=["dispatch","read","subscribe","watch","when","getDistributableSnapshot","watchDistributableSnapshot"];for(let o of t)o in n||(n[o]=e[o].bind(e));}function ee(n){process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&setTimeout(()=>{!n.isRunning&&!n.isInitialized&&console.warn("[Directive] System created but start() was never called. Constraints, resolvers, and effects will not run until you call system.start().");},0);}function ye(n){let e=n.module;if(!e)throw new Error("[Directive] createSystem requires a module. Got: "+typeof e);if(n.tickMs!==void 0&&n.tickMs<=0)throw new Error("[Directive] tickMs must be a positive number");if(n.initialFacts&&!c(n.initialFacts))throw new Error("[Directive] initialFacts contains potentially dangerous keys (__proto__, constructor, or prototype). This may indicate a prototype pollution attack.");process.env.NODE_ENV!=="production"&&(e.crossModuleDeps&&Object.keys(e.crossModuleDeps).length>0&&console.warn("[Directive] Single module mode ignores crossModuleDeps. Use multiple modules if cross-module access is needed: createSystem({ modules: { ... } })"),n.tickMs&&n.tickMs>0&&(e.events&&"tick"in e.events||console.warn(`[Directive] tickMs is set to ${n.tickMs}ms but module has no "tick" event handler.`)),(typeof n.history=="object"?n.history:null)?.snapshotModules&&console.warn("[Directive] history.snapshotModules has no effect in single-module mode. Use history.snapshotEvents on the module definition instead, or switch to createSystem({ modules: { ... } }) for multi-module filtering."));let{history:t,trace:o,errorBoundary:r}=X(n),a=null,u=null;u=z$1({modules:[{id:e.id,schema:e.schema.facts,requirements:e.schema.requirements,init:e.init,derive:e.derive,events:e.events,effects:e.effects,constraints:e.constraints,resolvers:e.resolvers,hooks:e.hooks,meta:e.meta,history:e.history}],plugins:n.plugins,history:t,trace:o,errorBoundary:r,tickMs:n.tickMs,cloud:n.cloud,onAfterModuleInit:()=>{if(n.initialFacts)for(let[d,m]of Object.entries(n.initialFacts))k.has(d)||(u.facts[d]=m);if(a){if(!c(a))process.env.NODE_ENV!=="production"&&console.warn("[Directive] hydrate() data contains potentially dangerous keys. Skipping.");else for(let[d,m]of Object.entries(a))k.has(d)||(u.facts[d]=m);a=null;}}});let f=new Proxy({},{get(d,m){if(typeof m!="symbol"&&!k.has(m))return b=>{u.dispatch({type:m,...b});}},has(d,m){return typeof m=="symbol"||k.has(m)?false:e.events?m in e.events:false},ownKeys(){return e.events?Object.keys(e.events):[]},getOwnPropertyDescriptor(d,m){if(typeof m!="symbol"&&!k.has(m)&&e.events&&m in e.events)return {configurable:true,enumerable:true}},set(){return false},deleteProperty(){return false},defineProperty(){return false},getPrototypeOf(){return null},setPrototypeOf(){return false}}),i=null,w=n.tickMs,g={_mode:"single",facts:u.facts,history:u.history,derive:u.derive,events:f,constraints:u.constraints,effects:u.effects,resolvers:u.resolvers,async hydrate(d){if(u.isRunning)throw new Error("[Directive] hydrate() must be called before start(). The system is already running.");let m=await d();m&&typeof m=="object"&&(a=m);},initialize(){u.initialize();},start(){u.start(),w&&w>0&&e.events&&"tick"in e.events&&(i=setInterval(()=>{u.dispatch({type:"tick"});},w));},stop(){i&&(clearInterval(i),i=null),u.stop();},destroy(){this.stop(),u.destroy();},registerModule(d){u.registerModule({id:d.id,schema:d.schema.facts,requirements:d.schema.requirements,init:d.init,derive:d.derive,events:d.events,effects:d.effects,constraints:d.constraints,resolvers:d.resolvers,hooks:d.hooks,history:d.history});}};return Y(g,u),ee(g),g}export{Se as a};//# sourceMappingURL=chunk-MPOV2REO.js.map
|
|
16
|
-
//# sourceMappingURL=chunk-
|
|
15
|
+
createSystem({ modules: { myName: myModule } })`);return fe(e)}function fe(n){let e=n.modules,t=new Set(Object.keys(e)),o=typeof n.history=="object"?n.history:null,r=o?.snapshotModules?new Set(o.snapshotModules):null;if(n.tickMs!==void 0&&n.tickMs<=0)throw new Error("[Directive] tickMs must be a positive number");if(process.env.NODE_ENV!=="production"){for(let[s,c]of Object.entries(e))if(c.crossModuleDeps)for(let l of Object.keys(c.crossModuleDeps))l===s?console.warn(`[Directive] Module "${s}" references itself in crossModuleDeps. Use "facts.self" to access own module's facts instead.`):t.has(l)||console.warn(`[Directive] Module "${s}" declares crossModuleDeps.${l}, but no module with namespace "${l}" exists in the system. Available modules: ${[...t].join(", ")}`);}if(process.env.NODE_ENV!=="production"&&o?.snapshotModules)for(let s of o.snapshotModules)t.has(s)||console.warn(`[Directive] history.snapshotModules entry "${s}" doesn't match any module. Available modules: ${[...t].join(", ")}`);let a,u=n.initOrder??"auto";if(Array.isArray(u)){let s=u,c=Object.keys(e).filter(l=>!s.includes(l));if(c.length>0)throw new Error(`[Directive] initOrder is missing modules: ${c.join(", ")}. All modules must be included in the explicit order.`);a=s;}else u==="declaration"?a=Object.keys(e):a=le(e);let{history:f,trace:i,errorBoundary:w}=X(n);for(let s of Object.keys(e)){if(s.includes(y))throw new Error(`[Directive] Module name "${s}" contains the reserved separator "${y}". Module names cannot contain "${y}".`);let c=e[s];if(c){for(let l of Object.keys(c.schema.facts))if(l.includes(y))throw new Error(`[Directive] Schema key "${l}" in module "${s}" contains the reserved separator "${y}". Schema keys cannot contain "${y}".`)}}let g={names:null};function d(){return g.names===null&&(g.names=Object.keys(e)),g.names}let m=a.map(s=>{let c=e[s];return c?T({mod:c,namespace:s,snapshotModulesSet:r}):null}).filter(s=>s!==null);process.env.NODE_ENV!=="production"&&n.tickMs&&n.tickMs>0&&(m.some(c=>c.events&&Object.keys(c.events).some(l=>l.endsWith(`${y}tick`)))||console.warn(`[Directive] tickMs is set to ${n.tickMs}ms but no module defines a "tick" event handler.`));let b=null,h=null;function _(s){for(let[c$1,l]of Object.entries(s)){if(k.has(c$1)){process.env.NODE_ENV!=="production"&&console.warn(`[Directive] initialFacts/hydrate contains blocked namespace "${c$1}". Skipping.`);continue}if(!t.has(c$1)){process.env.NODE_ENV!=="production"&&console.warn(`[Directive] initialFacts/hydrate contains unknown namespace "${c$1}". Available modules: ${[...t].join(", ")}`);continue}if(l&&typeof l=="object"&&!c(l))throw new Error(`[Directive] initialFacts/hydrate for namespace "${c$1}" contains potentially dangerous keys (__proto__, constructor, or prototype). This may indicate a prototype pollution attack.`);for(let[p,R]of Object.entries(l))k.has(p)||(h.facts[`${c$1}${y}${p}`]=R);}}h=z$1({modules:m,plugins:n.plugins,history:f,trace:i,errorBoundary:w,tickMs:n.tickMs,cloud:n.cloud,onAfterModuleInit:()=>{n.initialFacts&&_(n.initialFacts),b&&(_(b),b=null);}});let x=new Map;for(let s of Object.keys(e)){let c=e[s];c&&x.set(s,Q(s,c));}let B=G(h.facts,e,d),ne=Z(h.derive,e,d),te=J(h,e,d),E=null,j=n.tickMs,N={_mode:"namespaced",facts:B,history:h.history,derive:ne,events:te,constraints:h.constraints,effects:h.effects,resolvers:h.resolvers,async hydrate(s){if(h.isRunning)throw new Error("[Directive] hydrate() must be called before start(). The system is already running.");let c=await s();c&&typeof c=="object"&&(b=c);},initialize(){h.initialize();},start(){if(h.start(),j&&j>0){let s;for(let c of m)if(c?.events&&(s=Object.keys(c.events).find(l=>l.endsWith(`${y}tick`)),s))break;if(s){let c=s;E=setInterval(()=>{h.dispatch({type:c});},j);}}},stop(){E&&(clearInterval(E),E=null),h.stop();},destroy(){this.stop(),h.destroy();},dispatch(s){h.dispatch(s);},read(s){return h.read(v(s))},subscribe(s,c){let l=[];for(let p of s)if(p.endsWith(".*")){let R=p.slice(0,-2),K=x.get(R);K?l.push(...K):process.env.NODE_ENV!=="production"&&console.warn(`[Directive] subscribe wildcard "${p}" \u2014 namespace "${R}" not found.`);}else l.push(v(p));return h.subscribe(l,c)},subscribeModule(s,c){let l=x.get(s);return !l||l.length===0?(process.env.NODE_ENV!=="production"&&console.warn(`[Directive] subscribeModule("${s}") \u2014 namespace not found. Available: ${[...x.keys()].join(", ")}`),()=>{}):h.subscribe(l,c)},watch(s,c,l){return h.watch(v(s),c,l)},when(s,c){return h.when(()=>s(B),c)},getDistributableSnapshot(s){let c={...s,includeDerivations:s?.includeDerivations?.map(v),excludeDerivations:s?.excludeDerivations?.map(v),includeFacts:s?.includeFacts?.map(v)},l=h.getDistributableSnapshot(c);return {...l,data:A(l.data)}},watchDistributableSnapshot(s,c){let l={...s,includeDerivations:s?.includeDerivations?.map(v),excludeDerivations:s?.excludeDerivations?.map(v),includeFacts:s?.includeFacts?.map(v)};return h.watchDistributableSnapshot(l,p=>{c({...p,data:A(p.data)});})},registerModule(s,c){if(t.has(s))throw new Error(`[Directive] Module namespace "${s}" already exists. Cannot register a duplicate namespace.`);if(s.includes(y))throw new Error(`[Directive] Module name "${s}" contains the reserved separator "${y}".`);if(k.has(s))throw new Error(`[Directive] Module name "${s}" is a blocked property.`);for(let R of Object.keys(c.schema.facts))if(R.includes(y))throw new Error(`[Directive] Schema key "${R}" in module "${s}" contains the reserved separator "${y}".`);let l=c,p=T({mod:l,namespace:s,snapshotModulesSet:r});t.add(s),e[s]=l,g.names=null,x.set(s,Q(s,l)),h.registerModule(p);}};return Y(N,h),ee(N),N}function X(n){let e=n.history,t=n.trace,o=n.errorBoundary;if(n.zeroConfig){let r=process.env.NODE_ENV!=="production";e=e??r,o={onConstraintError:"skip",onResolverError:"skip",onEffectError:"skip",onDerivationError:"skip",...n.errorBoundary};}return {history:e,trace:t,errorBoundary:o}}function Y(n,e){Object.defineProperties(n,{trace:{get(){return e.trace},enumerable:true,configurable:true},meta:{value:e.meta,enumerable:true,configurable:true},isRunning:{get(){return e.isRunning},enumerable:true,configurable:true},isSettled:{get(){return e.isSettled},enumerable:true,configurable:true},isInitialized:{get(){return e.isInitialized},enumerable:true,configurable:true},isReady:{get(){return e.isReady},enumerable:true,configurable:true}}),n.whenReady=e.whenReady.bind(e),n.batch=e.batch.bind(e),n.onSettledChange=e.onSettledChange.bind(e),n.onHistoryChange=e.onHistoryChange.bind(e),n.inspect=e.inspect.bind(e),n.settle=e.settle.bind(e),n.explain=e.explain.bind(e),n.getSnapshot=e.getSnapshot.bind(e),n.restore=e.restore.bind(e);let t=["dispatch","read","subscribe","watch","when","getDistributableSnapshot","watchDistributableSnapshot"];for(let o of t)o in n||(n[o]=e[o].bind(e));}function ee(n){process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&setTimeout(()=>{!n.isRunning&&!n.isInitialized&&console.warn("[Directive] System created but start() was never called. Constraints, resolvers, and effects will not run until you call system.start().");},0);}function ye(n){let e=n.module;if(!e)throw new Error("[Directive] createSystem requires a module. Got: "+typeof e);if(n.tickMs!==void 0&&n.tickMs<=0)throw new Error("[Directive] tickMs must be a positive number");if(n.initialFacts&&!c(n.initialFacts))throw new Error("[Directive] initialFacts contains potentially dangerous keys (__proto__, constructor, or prototype). This may indicate a prototype pollution attack.");process.env.NODE_ENV!=="production"&&(e.crossModuleDeps&&Object.keys(e.crossModuleDeps).length>0&&console.warn("[Directive] Single module mode ignores crossModuleDeps. Use multiple modules if cross-module access is needed: createSystem({ modules: { ... } })"),n.tickMs&&n.tickMs>0&&(e.events&&"tick"in e.events||console.warn(`[Directive] tickMs is set to ${n.tickMs}ms but module has no "tick" event handler.`)),(typeof n.history=="object"?n.history:null)?.snapshotModules&&console.warn("[Directive] history.snapshotModules has no effect in single-module mode. Use history.snapshotEvents on the module definition instead, or switch to createSystem({ modules: { ... } }) for multi-module filtering."));let{history:t,trace:o,errorBoundary:r}=X(n),a=null,u=null;u=z$1({modules:[{id:e.id,schema:e.schema.facts,requirements:e.schema.requirements,init:e.init,derive:e.derive,events:e.events,effects:e.effects,constraints:e.constraints,resolvers:e.resolvers,hooks:e.hooks,meta:e.meta,history:e.history}],plugins:n.plugins,history:t,trace:o,errorBoundary:r,tickMs:n.tickMs,cloud:n.cloud,onAfterModuleInit:()=>{if(n.initialFacts)for(let[d,m]of Object.entries(n.initialFacts))k.has(d)||(u.facts[d]=m);if(a){if(!c(a))process.env.NODE_ENV!=="production"&&console.warn("[Directive] hydrate() data contains potentially dangerous keys. Skipping.");else for(let[d,m]of Object.entries(a))k.has(d)||(u.facts[d]=m);a=null;}}});let f=new Proxy({},{get(d,m){if(typeof m!="symbol"&&!k.has(m))return b=>{u.dispatch({type:m,...b});}},has(d,m){return typeof m=="symbol"||k.has(m)?false:e.events?m in e.events:false},ownKeys(){return e.events?Object.keys(e.events):[]},getOwnPropertyDescriptor(d,m){if(typeof m!="symbol"&&!k.has(m)&&e.events&&m in e.events)return {configurable:true,enumerable:true}},set(){return false},deleteProperty(){return false},defineProperty(){return false},getPrototypeOf(){return null},setPrototypeOf(){return false}}),i=null,w=n.tickMs,g={_mode:"single",facts:u.facts,history:u.history,derive:u.derive,events:f,constraints:u.constraints,effects:u.effects,resolvers:u.resolvers,async hydrate(d){if(u.isRunning)throw new Error("[Directive] hydrate() must be called before start(). The system is already running.");let m=await d();m&&typeof m=="object"&&(a=m);},initialize(){u.initialize();},start(){u.start(),w&&w>0&&e.events&&"tick"in e.events&&(i=setInterval(()=>{u.dispatch({type:"tick"});},w));},stop(){i&&(clearInterval(i),i=null),u.stop();},destroy(){this.stop(),u.destroy();},registerModule(d){u.registerModule({id:d.id,schema:d.schema.facts,requirements:d.schema.requirements,init:d.init,derive:d.derive,events:d.events,effects:d.effects,constraints:d.constraints,resolvers:d.resolvers,hooks:d.hooks,history:d.history});}};return Y(g,u),ee(g),g}export{Se as a};//# sourceMappingURL=chunk-MXIBBD7Z.js.map
|
|
16
|
+
//# sourceMappingURL=chunk-MXIBBD7Z.js.map
|