@directive-run/core 1.6.1 → 1.7.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/{chunk-HJ3CDQGB.cjs → chunk-2OS4RCLV.cjs} +3 -3
- package/dist/{chunk-HJ3CDQGB.cjs.map → chunk-2OS4RCLV.cjs.map} +1 -1
- package/dist/chunk-FCOZCTLY.js +16 -0
- package/dist/{chunk-2PLP22ZU.js.map → chunk-FCOZCTLY.js.map} +1 -1
- package/dist/{chunk-BWBPR34Z.cjs → chunk-WIZHZF4G.cjs} +2 -2
- package/dist/{chunk-BWBPR34Z.cjs.map → chunk-WIZHZF4G.cjs.map} +1 -1
- package/dist/{chunk-JFUK5NIO.js → chunk-ZE2RY5KP.js} +2 -2
- package/dist/{chunk-JFUK5NIO.js.map → chunk-ZE2RY5KP.js.map} +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +124 -1
- package/dist/index.d.ts +124 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +1 -1
- package/dist/internals.js +1 -1
- package/dist/system-DEMPYZHI.cjs +2 -0
- package/dist/{system-WNO6PRHB.cjs.map → system-DEMPYZHI.cjs.map} +1 -1
- package/dist/system-R4JL6U4S.js +2 -0
- package/dist/{system-K6OITF5B.js.map → system-R4JL6U4S.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-2PLP22ZU.js +0 -16
- package/dist/system-K6OITF5B.js +0 -2
- package/dist/system-WNO6PRHB.cjs +0 -2
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
'use strict';var chunkHJ3CDQGB_cjs=require('./chunk-HJ3CDQGB.cjs'),chunkBWBPR34Z_cjs=require('./chunk-BWBPR34Z.cjs'),chunkN4KTCKOI_cjs=require('./chunk-N4KTCKOI.cjs'),chunkEOLY64E6_cjs=require('./chunk-EOLY64E6.cjs');var f=1e6;function I(e,t){try{chunkBWBPR34Z_cjs.f(e);}catch(r){let i=r instanceof Error?r.message:String(r);throw new Error(`[Directive] replayUnder: the ${t} predicate is invalid \u2014 ${i}`)}if(!chunkBWBPR34Z_cjs.c(e)){let r=e===null||typeof e!="object"?`${typeof e} \u2014 ${JSON.stringify(e)}`:JSON.stringify(e).slice(0,80);throw new Error(`[Directive] replayUnder: the ${t} predicate is not a valid FactPredicate (got ${r})`)}let n;if(chunkBWBPR34Z_cjs.d(e,{operator(r,i){n===void 0&&i.startsWith("$")&&!chunkBWBPR34Z_cjs.a.has(i)&&(n=i);},strayOperatorKey(r){n===void 0&&!chunkBWBPR34Z_cjs.a.has(r)&&!chunkBWBPR34Z_cjs.b.has(r)&&(n=r);}}),n!==void 0)throw new Error(`[Directive] replayUnder: the ${t} predicate uses an unknown operator "${n}" \u2014 known operators: ${[...chunkBWBPR34Z_cjs.a].join(", ")}`)}function N(e){if(e&&typeof e=="object"&&!Array.isArray(e)&&Array.isArray(e.snapshots))return W(e);let t=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.frames)?e.frames:null;if(!t)throw new Error("[Directive] toReplayFrames: history must be a JSON array of frames, an object with a `frames` array, or a history export with a `snapshots` array");if(t.length>f)throw new Error(`[Directive] toReplayFrames: history has ${t.length} frames, exceeds the MAX_REPLAY_FRAMES limit (${f}) \u2014 split or down-sample the history`);return t.map((n,r)=>{if(n&&typeof n=="object"&&"facts"in n){let i=n,o={id:i.id??`#${r}`,facts:i.facts??{}};return typeof i.timestamp=="number"&&(o.timestamp=i.timestamp),o}return {id:`#${r}`,facts:n??{}}})}function W(e){let t=typeof e=="string"?JSON.parse(e):e;if(Array.isArray(t))return O(t);if(!t||typeof t!="object")throw new Error("[Directive] framesFromHistory: expected a history export object with a `snapshots` array (from system.history.export())");let n=t;if(n.version!==void 0&&n.version!==1)throw new Error(`[Directive] framesFromHistory: unsupported history export version ${JSON.stringify(n.version)} \u2014 expected 1`);if(!Array.isArray(n.snapshots))throw new Error("[Directive] framesFromHistory: expected a history export object with a `snapshots` array (from system.history.export())");return O(n.snapshots)}function O(e){if(!Array.isArray(e))throw new Error("[Directive] framesFromSnapshots: expected an array of fact-state snapshots");if(e.length>f)throw new Error(`[Directive] framesFromSnapshots: history has ${e.length} snapshots, exceeds the MAX_REPLAY_FRAMES limit (${f}) \u2014 split or down-sample the history`);for(let t=0;t<e.length;t++){let n=e[t];if(!n||typeof n!="object"||!("facts"in n))throw new Error(`[Directive] framesFromSnapshots: snapshot at index ${t} is not a { facts, ... } object`)}return N(e)}function we(e){let{frames:t,original:n,proposed:r,entityKey:i}=e,o=e.maxSamples??20,a=o>0?o:0;if(t.length>f)throw new Error(`[Directive] replayUnder: history has ${t.length} frames, exceeds the MAX_REPLAY_FRAMES limit (${f}) \u2014 split or down-sample the history`);I(n,"original"),I(r,"proposed");let p=0,s=0,u=0,l=0,d=0,m=[],y=[],h=i?new Set:void 0,x=i?new Set:void 0,g;for(let k of t){let T=k.facts,R=chunkBWBPR34Z_cjs.g(n,T,g),E=chunkBWBPR34Z_cjs.g(r,T,g);R&&(p++,h?.add(T[i])),E&&(s++,x?.add(T[i])),R===E?d++:!R&&E?(u++,m.length<a&&m.push(U(k,n,r,g))):(l++,y.length<a&&y.push(U(k,n,r,g))),g=T;}let C={framesEvaluated:t.length,original:{matched:p},proposed:{matched:s},delta:s-p,newMatchCount:u,lostMatchCount:l,unchanged:d,newMatches:m,lostMatches:y};return h&&x&&(C.original.matchedEntities=h.size,C.proposed.matchedEntities=x.size),C}function U(e,t,n,r){let i=e.facts,o={frameId:e.id,facts:i,originalExplain:chunkBWBPR34Z_cjs.h(t,i,r),proposedExplain:chunkBWBPR34Z_cjs.h(n,i,r)};return e.timestamp!==void 0&&(o.timestamp=e.timestamp),o}function D(e=[],t,n,r,i,o,a){return {_type:void 0,_validators:e,_typeName:t,_default:n,_transform:r,_description:i,_refinements:o,_meta:a,validate(p){return D([...e,p],t,n,r,i,o,a)}}}function c(e,t,n,r,i,o,a){return {...D(e,t,n,r,i,o,a),default(s){return c(e,t,s,r,i,o,a)},transform(s){return c([],t,void 0,l=>{let d=r?r(l):l;return s(d)},i,void 0,a)},brand(){return c(e,`Branded<${t}>`,n,r,i,o,a)},describe(s){return c(e,t,n,r,s,o,a)},refine(s,u){let l=[...o??[],{predicate:s,message:u}];return c([...e,s],t,n,r,i,l,a)},nullable(){return c([s=>s===null||e.every(u=>u(s))],`${t} | null`,n,r,i,void 0,a)},optional(){return c([s=>s===void 0||e.every(u=>u(s))],`${t} | undefined`,n,r,i,void 0,a)},meta(s){return c(e,t,n,r,i,o,s)}}}var xe=((...e)=>{if(e.length===0)return c([],"union");let t=e.map(n=>n._typeName??"unknown");return c([n=>e.some(r=>r._validators.every(i=>i(n)))],t.join(" | "))}),Ce={string(){let e=(t,n,r,i,o,a)=>({...c(t,"string",n,r,i,o,a),minLength(s){return e([...t,u=>u.length>=s],n,r,i,o,a)},maxLength(s){return e([...t,u=>u.length<=s],n,r,i,o,a)},pattern(s){return e([...t,u=>s.test(u)],n,r,i,o,a)},default(s){return e(t,s,r,i,o,a)},describe(s){return e(t,n,r,s,o,a)},refine(s,u){let l=[...o??[],{predicate:s,message:u}];return e([...t,s],n,r,i,l,a)},meta(s){return e(t,n,r,i,o,s)}});return e([t=>typeof t=="string"])},number(){let e=(t,n,r,i,o,a)=>({...c(t,"number",n,r,i,o,a),min(s){return e([...t,u=>u>=s],n,r,i,o,a)},max(s){return e([...t,u=>u<=s],n,r,i,o,a)},default(s){return e(t,s,r,i,o,a)},describe(s){return e(t,n,r,s,o,a)},refine(s,u){let l=[...o??[],{predicate:s,message:u}];return e([...t,s],n,r,i,l,a)},meta(s){return e(t,n,r,i,o,s)}});return e([t=>typeof t=="number"])},boolean(){return c([e=>typeof e=="boolean"],"boolean")},array(){let e=(t,n,r,i,o,a)=>{let p=c(t,"array",r,void 0,i,void 0,a),s=o??{value:-1};return {...p,get _lastFailedIndex(){return s.value},set _lastFailedIndex(l){s.value=l;},of(l){let d={value:-1};return e([...t,m=>{for(let y=0;y<m.length;y++)if(!l._validators.every(h=>h(m[y])))return d.value=y,false;return true}],l,r,i,d,a)},nonEmpty(){return e([...t,l=>l.length>0],n,r,i,s,a)},maxLength(l){return e([...t,d=>d.length<=l],n,r,i,s,a)},minLength(l){return e([...t,d=>d.length>=l],n,r,i,s,a)},default(l){return e(t,n,l,i,s,a)},describe(l){return e(t,n,r,l,s,a)},meta(l){return e(t,n,r,i,s,l)}}};return e([t=>Array.isArray(t)])},object(){let e=(t,n,r,i)=>({...c(t,"object",n,void 0,r,void 0,i),shape(a){return e([...t,p=>{for(let[s,u]of Object.entries(a)){let l=p[s],d=u;if(d&&!d._validators.every(m=>m(l)))return false}return true}],n,r,i)},nonNull(){return e([...t,a=>a!=null],n,r,i)},hasKeys(...a){return e([...t,p=>a.every(s=>s in p)],n,r,i)},default(a){return e(t,a,r,i)},describe(a){return e(t,n,a,i)},meta(a){return e(t,n,r,a)}});return e([t=>typeof t=="object"&&t!==null&&!Array.isArray(t)])},enum(...e){chunkN4KTCKOI_cjs.a&&e.length===0&&console.warn("[Directive] t.enum() called with no values - this will reject all strings");let t=new Set(e);return c([n=>typeof n=="string"&&t.has(n)],`enum(${e.join("|")})`)},literal(e){return c([t=>t===e],`literal(${String(e)})`)},nullable(e){let t=e._typeName??"unknown";return D([n=>n===null?true:e._validators.every(r=>r(n))],`${t} | null`)},optional(e){let t=e._typeName??"unknown";return D([n=>n===void 0?true:e._validators.every(r=>r(n))],`${t} | undefined`)},union:xe,record(e){let t=e._typeName??"unknown";return c([n=>typeof n!="object"||n===null||Array.isArray(n)?false:Object.values(n).every(r=>e._validators.every(i=>i(r)))],`Record<string, ${t}>`)},tuple(...e){chunkN4KTCKOI_cjs.a&&e.length===0&&console.warn("[Directive] t.tuple() called with no types - this will only accept empty arrays");let t=e.map(n=>n._typeName??"unknown");return c([n=>!Array.isArray(n)||n.length!==e.length?false:e.every((r,i)=>r._validators.every(o=>o(n[i])))],`[${t.join(", ")}]`)},date(){return c([e=>e instanceof Date&&!Number.isNaN(e.getTime())],"Date")},uuid(){let e=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;return c([t=>typeof t=="string"&&e.test(t)],"uuid")},email(){let e=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;return c([t=>typeof t=="string"&&e.test(t)],"email")},url(){return c([e=>{if(typeof e!="string")return false;try{return new URL(e),!0}catch{return false}}],"url")},bigint(){return c([e=>typeof e=="bigint"],"bigint")},any(){return c([],"any")},unknown(){return c([],"unknown")}};function ke(e){if(!e||typeof e!="string"){console.warn("[Directive] Module ID must be a non-empty string");return}/^(__[a-z][a-z0-9_-]*|[a-z][a-z0-9-]*)$/i.test(e)||console.warn(`[Directive] Module ID "${e}" should follow kebab-case convention (e.g., "my-module")`);}function K(e,t,n,r,i){for(let o of e)t.has(o)||console.warn(`[Directive] ${n} "${o}" not declared in ${r}`);for(let o of t)e.has(o)||console.warn(`[Directive] ${r}["${o}"] ${i}`);}function Re(e,t){e.length===0&&console.warn("[Directive] history.snapshotEvents is an empty array \u2014 no events will create history snapshots. Omit history.snapshotEvents entirely to snapshot all events, or list specific events.");let n=new Set(Object.keys(t));for(let r of e)n.has(r)||console.warn(`[Directive] history.snapshotEvents entry "${r}" not declared in schema.events. Available events: ${[...n].join(", ")||"(none)"}`);}function Ee(e,t){let n=new Set(Object.keys(t));for(let[r,i]of Object.entries(e)){let o=i;typeof o.requirement=="string"&&!n.has(o.requirement)&&console.warn(`[Directive] Resolver "${r}" references unknown requirement type "${o.requirement}". Available types: ${[...n].join(", ")||"(none)"}`);}}function Ae(e,t){let n=t.schema?.facts??{},r=Object.keys(n);if(r.length===0)return;let i=new Set(["self","prev","current"]),o="crossModuleDeps"in t&&t.crossModuleDeps?Object.keys(t.crossModuleDeps):[];for(let a of o)i.add(a);for(let a of r)if(i.has(a))throw new Error(`[Directive] module '${e}': fact key '${a}' conflicts with a reserved namespace pivot or evaluation alias (self / prev / current / a crossModuleDep namespace). Three fixes:
|
|
2
|
-
1. Rename the fact (e.g. ${
|
|
3
|
-
2. Remove '${
|
|
4
|
-
3. Move the fact under a wrapping namespace (t.object({ inner: ... }))`)}function
|
|
1
|
+
'use strict';var chunk2OS4RCLV_cjs=require('./chunk-2OS4RCLV.cjs'),chunkWIZHZF4G_cjs=require('./chunk-WIZHZF4G.cjs'),chunkN4KTCKOI_cjs=require('./chunk-N4KTCKOI.cjs'),chunkEOLY64E6_cjs=require('./chunk-EOLY64E6.cjs');var b=1e6;function K(e,t){try{chunkWIZHZF4G_cjs.g(e);}catch(r){let i=r instanceof Error?r.message:String(r);throw new Error(`[Directive] replayUnder: the ${t} predicate is invalid \u2014 ${i}`)}if(!chunkWIZHZF4G_cjs.d(e)){let r=e===null||typeof e!="object"?`${typeof e} \u2014 ${JSON.stringify(e)}`:JSON.stringify(e).slice(0,80);throw new Error(`[Directive] replayUnder: the ${t} predicate is not a valid FactPredicate (got ${r})`)}let n;if(chunkWIZHZF4G_cjs.e(e,{operator(r,i){n===void 0&&i.startsWith("$")&&!chunkWIZHZF4G_cjs.a.has(i)&&(n=i);},strayOperatorKey(r){n===void 0&&!chunkWIZHZF4G_cjs.a.has(r)&&!chunkWIZHZF4G_cjs.b.has(r)&&(n=r);}}),n!==void 0)throw new Error(`[Directive] replayUnder: the ${t} predicate uses an unknown operator "${n}" \u2014 known operators: ${[...chunkWIZHZF4G_cjs.a].join(", ")}`)}function z(e){if(e&&typeof e=="object"&&!Array.isArray(e)&&Array.isArray(e.snapshots))return X(e);let t=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.frames)?e.frames:null;if(!t)throw new Error("[Directive] toReplayFrames: history must be a JSON array of frames, an object with a `frames` array, or a history export with a `snapshots` array");if(t.length>b)throw new Error(`[Directive] toReplayFrames: history has ${t.length} frames, exceeds the MAX_REPLAY_FRAMES limit (${b}) \u2014 split or down-sample the history`);return t.map((n,r)=>{if(n&&typeof n=="object"&&"facts"in n){let i=n,a={id:i.id??`#${r}`,facts:i.facts??{}};return typeof i.timestamp=="number"&&(a.timestamp=i.timestamp),a}return {id:`#${r}`,facts:n??{}}})}function X(e){let t=typeof e=="string"?JSON.parse(e):e;if(Array.isArray(t))return $(t);if(!t||typeof t!="object")throw new Error("[Directive] framesFromHistory: expected a history export object with a `snapshots` array (from system.history.export())");let n=t;if(n.version!==void 0&&n.version!==1)throw new Error(`[Directive] framesFromHistory: unsupported history export version ${JSON.stringify(n.version)} \u2014 expected 1`);if(!Array.isArray(n.snapshots))throw new Error("[Directive] framesFromHistory: expected a history export object with a `snapshots` array (from system.history.export())");return $(n.snapshots)}function $(e){if(!Array.isArray(e))throw new Error("[Directive] framesFromSnapshots: expected an array of fact-state snapshots");if(e.length>b)throw new Error(`[Directive] framesFromSnapshots: history has ${e.length} snapshots, exceeds the MAX_REPLAY_FRAMES limit (${b}) \u2014 split or down-sample the history`);for(let t=0;t<e.length;t++){let n=e[t];if(!n||typeof n!="object"||!("facts"in n))throw new Error(`[Directive] framesFromSnapshots: snapshot at index ${t} is not a { facts, ... } object`)}return z(e)}function C(e){let{frames:t,original:n,proposed:r,entityKey:i}=e,a=e.maxSamples??20,o=a>0?a:0;if(t.length>b)throw new Error(`[Directive] replayUnder: history has ${t.length} frames, exceeds the MAX_REPLAY_FRAMES limit (${b}) \u2014 split or down-sample the history`);K(n,"original"),K(r,"proposed");let d=0,s=0,u=0,l=0,c=0,m=[],y=[],M=i?new Set:void 0,T=i?new Set:void 0,g;for(let v of t){let f=v.facts,h=chunkWIZHZF4G_cjs.h(n,f,g),S=chunkWIZHZF4G_cjs.h(r,f,g);h&&(d++,M?.add(f[i])),S&&(s++,T?.add(f[i])),h===S?c++:!h&&S?(u++,m.length<o&&m.push(L(v,n,r,g))):(l++,y.length<o&&y.push(L(v,n,r,g))),g=f;}let w={framesEvaluated:t.length,original:{matched:d},proposed:{matched:s},delta:s-d,newMatchCount:u,lostMatchCount:l,unchanged:c,newMatches:m,lostMatches:y};return M&&T&&(w.original.matchedEntities=M.size,w.proposed.matchedEntities=T.size),w}function L(e,t,n,r){let i=e.facts,a={frameId:e.id,facts:i,originalExplain:chunkWIZHZF4G_cjs.i(t,i,r),proposedExplain:chunkWIZHZF4G_cjs.i(n,i,r)};return e.timestamp!==void 0&&(a.timestamp=e.timestamp),a}var I=1e4,Y=5e7;function Fe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length===1&&typeof e.$hole=="string"}function B(e,t,n=new Set,r=0){if(r>chunkWIZHZF4G_cjs.c)throw new Error(`[Directive] sweepUnder: template exceeds MAX_PREDICATE_DEPTH (${chunkWIZHZF4G_cjs.c}) \u2014 flatten the template or split the sweep`);if(Fe(e)){let i=e.$hole;if(!(i in t))throw new Error(`[Directive] sweepUnder: template references hole "${i}" but sweep has no values for it`);return t[i]}if(e===null||typeof e!="object")return e;if(n.has(e))throw new Error("[Directive] sweepUnder: template contains a cycle \u2014 predicate templates must be a tree");n.add(e);try{if(Array.isArray(e))return e.map(a=>B(a,t,n,r+1));let i={};for(let[a,o]of Object.entries(e))i[a]=B(o,t,n,r+1);return i}finally{n.delete(e);}}function*J(e,t){if(e.length===0){yield {};return}let n=e[0],r=e.slice(1),i=t[n]??[];for(let a of i)for(let o of J(r,t))yield {[n]:a,...o};}function Pe(e){let t=1;for(let n of Object.values(e))t*=n.length;return t}function je(e){let{frames:t,original:n,template:r,sweep:i,objective:a=f=>f.proposed.matched,entityKey:o,maxSamples:d=0}=e,s=Object.keys(i);if(s.length===0)throw new Error("[Directive] sweepUnder: `sweep` must contain at least one hole name");let u=Pe(i);if(u>I)throw new Error(`[Directive] sweepUnder: grid has ${u} points, exceeds the MAX_SWEEP_POINTS limit (${I}) \u2014 narrow the sweep ranges or split the run`);if(u===0)throw new Error("[Directive] sweepUnder: at least one hole has zero candidate values");let l=u*t.length;if(l>Y)throw new Error(`[Directive] sweepUnder: ${u} points \xD7 ${t.length} frames = ${l} per-frame evaluations, exceeds the MAX_SWEEP_EVALUATIONS limit (${Y}) \u2014 narrow the sweep, down-sample the history, or split the run`);let c=false,m=f=>{let h;try{h=a(f);}catch(S){return c||(c=true,console.warn(`[Directive] sweepUnder: objective threw \u2014 point will not rank (${S.message})`)),Number.NEGATIVE_INFINITY}return typeof h!="number"||!Number.isFinite(h)?(c||(c=true,console.warn(`[Directive] sweepUnder: objective returned a non-finite number (${String(h)}) \u2014 point will not rank`)),Number.NEGATIVE_INFINITY):h},y=C({frames:t,original:n,proposed:n,entityKey:o,maxSamples:d}),M={values:{},report:y,score:m(y)},T=[],g=0,w=Number.NEGATIVE_INFINITY;for(let f of J(s,i)){let h=B(r,f),S=C({frames:t,original:n,proposed:h,entityKey:o,maxSamples:d}),F=m(S);F>w&&(w=F,g=T.length),T.push({values:f,report:S,score:F});}let v=T[g];return {points:T,bestIndex:g,best:v,baseline:M}}function E(e=[],t,n,r,i,a,o){return {_type:void 0,_validators:e,_typeName:t,_default:n,_transform:r,_description:i,_refinements:a,_meta:o,validate(d){return E([...e,d],t,n,r,i,a,o)}}}function p(e,t,n,r,i,a,o){return {...E(e,t,n,r,i,a,o),default(s){return p(e,t,s,r,i,a,o)},transform(s){return p([],t,void 0,l=>{let c=r?r(l):l;return s(c)},i,void 0,o)},brand(){return p(e,`Branded<${t}>`,n,r,i,a,o)},describe(s){return p(e,t,n,r,s,a,o)},refine(s,u){let l=[...a??[],{predicate:s,message:u}];return p([...e,s],t,n,r,i,l,o)},nullable(){return p([s=>s===null||e.every(u=>u(s))],`${t} | null`,n,r,i,void 0,o)},optional(){return p([s=>s===void 0||e.every(u=>u(s))],`${t} | undefined`,n,r,i,void 0,o)},meta(s){return p(e,t,n,r,i,a,s)}}}var Oe=((...e)=>{if(e.length===0)return p([],"union");let t=e.map(n=>n._typeName??"unknown");return p([n=>e.some(r=>r._validators.every(i=>i(n)))],t.join(" | "))}),_e={string(){let e=(t,n,r,i,a,o)=>({...p(t,"string",n,r,i,a,o),minLength(s){return e([...t,u=>u.length>=s],n,r,i,a,o)},maxLength(s){return e([...t,u=>u.length<=s],n,r,i,a,o)},pattern(s){return e([...t,u=>s.test(u)],n,r,i,a,o)},default(s){return e(t,s,r,i,a,o)},describe(s){return e(t,n,r,s,a,o)},refine(s,u){let l=[...a??[],{predicate:s,message:u}];return e([...t,s],n,r,i,l,o)},meta(s){return e(t,n,r,i,a,s)}});return e([t=>typeof t=="string"])},number(){let e=(t,n,r,i,a,o)=>({...p(t,"number",n,r,i,a,o),min(s){return e([...t,u=>u>=s],n,r,i,a,o)},max(s){return e([...t,u=>u<=s],n,r,i,a,o)},default(s){return e(t,s,r,i,a,o)},describe(s){return e(t,n,r,s,a,o)},refine(s,u){let l=[...a??[],{predicate:s,message:u}];return e([...t,s],n,r,i,l,o)},meta(s){return e(t,n,r,i,a,s)}});return e([t=>typeof t=="number"])},boolean(){return p([e=>typeof e=="boolean"],"boolean")},array(){let e=(t,n,r,i,a,o)=>{let d=p(t,"array",r,void 0,i,void 0,o),s=a??{value:-1};return {...d,get _lastFailedIndex(){return s.value},set _lastFailedIndex(l){s.value=l;},of(l){let c={value:-1};return e([...t,m=>{for(let y=0;y<m.length;y++)if(!l._validators.every(M=>M(m[y])))return c.value=y,false;return true}],l,r,i,c,o)},nonEmpty(){return e([...t,l=>l.length>0],n,r,i,s,o)},maxLength(l){return e([...t,c=>c.length<=l],n,r,i,s,o)},minLength(l){return e([...t,c=>c.length>=l],n,r,i,s,o)},default(l){return e(t,n,l,i,s,o)},describe(l){return e(t,n,r,l,s,o)},meta(l){return e(t,n,r,i,s,l)}}};return e([t=>Array.isArray(t)])},object(){let e=(t,n,r,i)=>({...p(t,"object",n,void 0,r,void 0,i),shape(o){return e([...t,d=>{for(let[s,u]of Object.entries(o)){let l=d[s],c=u;if(c&&!c._validators.every(m=>m(l)))return false}return true}],n,r,i)},nonNull(){return e([...t,o=>o!=null],n,r,i)},hasKeys(...o){return e([...t,d=>o.every(s=>s in d)],n,r,i)},default(o){return e(t,o,r,i)},describe(o){return e(t,n,o,i)},meta(o){return e(t,n,r,o)}});return e([t=>typeof t=="object"&&t!==null&&!Array.isArray(t)])},enum(...e){chunkN4KTCKOI_cjs.a&&e.length===0&&console.warn("[Directive] t.enum() called with no values - this will reject all strings");let t=new Set(e);return p([n=>typeof n=="string"&&t.has(n)],`enum(${e.join("|")})`)},literal(e){return p([t=>t===e],`literal(${String(e)})`)},nullable(e){let t=e._typeName??"unknown";return E([n=>n===null?true:e._validators.every(r=>r(n))],`${t} | null`)},optional(e){let t=e._typeName??"unknown";return E([n=>n===void 0?true:e._validators.every(r=>r(n))],`${t} | undefined`)},union:Oe,record(e){let t=e._typeName??"unknown";return p([n=>typeof n!="object"||n===null||Array.isArray(n)?false:Object.values(n).every(r=>e._validators.every(i=>i(r)))],`Record<string, ${t}>`)},tuple(...e){chunkN4KTCKOI_cjs.a&&e.length===0&&console.warn("[Directive] t.tuple() called with no types - this will only accept empty arrays");let t=e.map(n=>n._typeName??"unknown");return p([n=>!Array.isArray(n)||n.length!==e.length?false:e.every((r,i)=>r._validators.every(a=>a(n[i])))],`[${t.join(", ")}]`)},date(){return p([e=>e instanceof Date&&!Number.isNaN(e.getTime())],"Date")},uuid(){let e=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;return p([t=>typeof t=="string"&&e.test(t)],"uuid")},email(){let e=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;return p([t=>typeof t=="string"&&e.test(t)],"email")},url(){return p([e=>{if(typeof e!="string")return false;try{return new URL(e),!0}catch{return false}}],"url")},bigint(){return p([e=>typeof e=="bigint"],"bigint")},any(){return p([],"any")},unknown(){return p([],"unknown")}};function $e(e){if(!e||typeof e!="string"){console.warn("[Directive] Module ID must be a non-empty string");return}/^(__[a-z][a-z0-9_-]*|[a-z][a-z0-9-]*)$/i.test(e)||console.warn(`[Directive] Module ID "${e}" should follow kebab-case convention (e.g., "my-module")`);}function G(e,t,n,r,i){for(let a of e)t.has(a)||console.warn(`[Directive] ${n} "${a}" not declared in ${r}`);for(let a of t)e.has(a)||console.warn(`[Directive] ${r}["${a}"] ${i}`);}function Ie(e,t){e.length===0&&console.warn("[Directive] history.snapshotEvents is an empty array \u2014 no events will create history snapshots. Omit history.snapshotEvents entirely to snapshot all events, or list specific events.");let n=new Set(Object.keys(t));for(let r of e)n.has(r)||console.warn(`[Directive] history.snapshotEvents entry "${r}" not declared in schema.events. Available events: ${[...n].join(", ")||"(none)"}`);}function Be(e,t){let n=new Set(Object.keys(t));for(let[r,i]of Object.entries(e)){let a=i;typeof a.requirement=="string"&&!n.has(a.requirement)&&console.warn(`[Directive] Resolver "${r}" references unknown requirement type "${a.requirement}". Available types: ${[...n].join(", ")||"(none)"}`);}}function Ne(e,t){let n=t.schema?.facts??{},r=Object.keys(n);if(r.length===0)return;let i=new Set(["self","prev","current"]),a="crossModuleDeps"in t&&t.crossModuleDeps?Object.keys(t.crossModuleDeps):[];for(let o of a)i.add(o);for(let o of r)if(i.has(o))throw new Error(`[Directive] module '${e}': fact key '${o}' conflicts with a reserved namespace pivot or evaluation alias (self / prev / current / a crossModuleDep namespace). Three fixes:
|
|
2
|
+
1. Rename the fact (e.g. ${o}_)
|
|
3
|
+
2. Remove '${o}' from this module's crossModuleDeps if it's not actually needed
|
|
4
|
+
3. Move the fact under a wrapping namespace (t.object({ inner: ... }))`)}function Ue(e,t){let n=t.constraints;if(n)for(let[r,i]of Object.entries(n)){let a=i?.owns;if(a){for(let o of a)if(chunkN4KTCKOI_cjs.l.has(o)||o.startsWith("$"))throw new Error(`[Directive] module '${e}' constraint '${r}': owns key '${o}' is reserved (BLOCKED_PROPS or $-prefixed)`)}}}function qe(e,t){$e(e),t.schema?t.schema.facts||console.warn("[Directive] Module schema.facts is required"):console.warn("[Directive] Module schema is required"),G(new Set(Object.keys(t.derive??{})),new Set(Object.keys(t.schema?.derivations??{})),"Derivation","schema.derivations","has no matching implementation in derive"),G(new Set(Object.keys(t.events??{})),new Set(Object.keys(t.schema?.events??{})),"Event","schema.events","has no matching handler in events"),t.history?.snapshotEvents&&Ie(t.history.snapshotEvents,t.schema?.events??{}),t.resolvers&&t.schema?.requirements&&Be(t.resolvers,t.schema.requirements);}function Q(e,t){Ne(e,t),Ue(e,t),chunkN4KTCKOI_cjs.a&&qe(e,t);let n="crossModuleDeps"in t?t.crossModuleDeps:void 0;return {id:e,schema:t.schema,init:t.init,derive:t.derive??{},events:t.events??{},effects:t.effects,constraints:t.constraints,resolvers:t.resolvers,hooks:t.hooks,meta:t.meta,history:t.history,crossModuleDeps:n}}function We(e){return t=>Q(t,e)}function N(){let e={pending:new Map,inflight:new Map,failed:new Map,errors:new Map,listeners:new Set};function t(){for(let s of e.listeners)s();}function n(s,u){let l=s.get(u);return l||(l=new Set,s.set(u,l)),l}function r(s){let u=e.pending.get(s)??new Set,l=e.inflight.get(s)??new Set,c=e.failed.get(s)??new Set,m=e.errors.get(s)??null;return {pending:u.size,inflight:l.size,failed:c.size,isLoading:u.size>0||l.size>0,hasError:c.size>0,lastError:m}}function i(){let s=new Set([...e.pending.keys(),...e.inflight.keys(),...e.failed.keys()]),u=new Map;for(let l of s)u.set(l,r(l));return u}function a(s){return e.listeners.add(s),()=>e.listeners.delete(s)}function o(){e.pending.clear(),e.inflight.clear(),e.failed.clear(),e.errors.clear(),t();}return {plugin:{name:"requirement-status",onRequirementCreated(s){let u=s.requirement.type;n(e.pending,u).add(s.id),e.failed.get(u)?.delete(s.id),t();},onResolverStart(s,u){let l=u.requirement.type;e.pending.get(l)?.delete(u.id),n(e.inflight,l).add(u.id),t();},onResolverComplete(s,u){let l=u.requirement.type;e.inflight.get(l)?.delete(u.id),e.pending.get(l)?.delete(u.id),t();},onResolverError(s,u,l){let c=u.requirement.type;e.inflight.get(c)?.delete(u.id),n(e.failed,c).add(u.id),e.errors.set(c,l instanceof Error?l:new Error(String(l))),t();},onResolverCancel(s,u){let l=u.requirement.type;e.pending.get(l)?.delete(u.id),e.inflight.get(l)?.delete(u.id),t();},onRequirementMet(s){let u=s.requirement.type;e.pending.get(u)?.delete(s.id),e.inflight.get(u)?.delete(s.id),t();}},getStatus:r,getAllStatus:i,subscribe:a,reset:o}}function He(e){return t=>e.getStatus(t)}function Ke(e){let t=N(),r=[...e.plugins??[],t.plugin];return {system:chunk2OS4RCLV_cjs.a({module:e.module,plugins:r,trace:e.trace,errorBoundary:e.errorBoundary,tickMs:e.tickMs,zeroConfig:e.zeroConfig,initialFacts:e.initialFacts}),statusPlugin:t}}function Z(){return {now:()=>Date.now(),setTimeout:(e,t)=>{let n=globalThis.setTimeout(e,t);return ()=>globalThis.clearTimeout(n)}}}function Le(e=0){let t=e,n=0,r=[];return {now:()=>t,setTimeout:(i,a)=>{let o={id:n++,deadlineMs:t+a,cb:i,canceled:false};return r.push(o),()=>{o.canceled=true;}},advanceBy:i=>{let a=t+i;for(;;){let o=r.filter(s=>!s.canceled&&s.deadlineMs<=a).sort((s,u)=>s.deadlineMs!==u.deadlineMs?s.deadlineMs-u.deadlineMs:s.id-u.id);if(o.length===0)break;let d=o[0];t=Math.max(t,d.deadlineMs),d.canceled=true,d.cb();}t=Math.max(t,a);}}}function ze(){return Z()}function U(){return {startedAtMs:null,pausedDurationMs:0,pausedAtMs:null,status:"idle",repeats:0}}function A(e,t){return e.startedAtMs===null?0:e.status==="paused"&&e.pausedAtMs!==null?Math.max(0,e.pausedAtMs-e.startedAtMs-e.pausedDurationMs):Math.max(0,t-e.startedAtMs-e.pausedDurationMs)}function V(e,t,n){return Math.max(0,n-A(e,t))}function ee(e,t){return e.status==="running"||e.status==="paused"?e:{...e,startedAtMs:t,pausedDurationMs:0,pausedAtMs:null,status:"running",repeats:0}}function te(e,t){return e.status!=="running"?e:{...e,pausedAtMs:t,status:"paused"}}function ne(e,t){if(e.status!=="paused"||e.pausedAtMs===null)return e;let n=Math.max(0,t-e.pausedAtMs);return {...e,pausedDurationMs:e.pausedDurationMs+n,pausedAtMs:null,status:"running"}}function re(){return U()}function se(e){return {...e,status:"completed"}}function ie(e,t){return e.startedAtMs===null||e.status==="paused"?e:{...e,startedAtMs:e.startedAtMs+t,pausedDurationMs:0,pausedAtMs:null,repeats:e.repeats+1}}function oe(e,t,n){if(e.status!=="running")return {kind:"no-op"};let r=A(e,t);return n.mode==="up"?{kind:"no-op"}:n.mode==="repeat"?r>=n.ms?{kind:"repeat"}:{kind:"no-op"}:r>=n.ms?{kind:"complete"}:{kind:"no-op"}}function Xe(e){return {initial:U,start:ee,pause:te,resume:ne,reset:re,complete:se,registerRepeat:t=>ie(t,e.ms),tick:(t,n)=>oe(t,n,e),elapsedMs:A,remainingMs:(t,n)=>V(t,n,e.ms)}}var pt={None:"none",Linear:"linear",Exponential:"exponential"};Object.defineProperty(exports,"createSystem",{enumerable:true,get:function(){return chunk2OS4RCLV_cjs.a}});Object.defineProperty(exports,"DirectiveError",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.q}});Object.defineProperty(exports,"RequirementSet",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.D}});Object.defineProperty(exports,"applyPatch",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.o}});Object.defineProperty(exports,"evaluateKeySelector",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.n}});Object.defineProperty(exports,"evaluatePredicate",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.h}});Object.defineProperty(exports,"evaluatePredicateExplained",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.i}});Object.defineProperty(exports,"evaluateTemplate",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.l}});Object.defineProperty(exports,"extractDeps",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.k}});Object.defineProperty(exports,"extractTemplateKeys",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.m}});Object.defineProperty(exports,"forType",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.C}});Object.defineProperty(exports,"generateRequirementId",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.z}});Object.defineProperty(exports,"isNamespacedSystem",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.w}});Object.defineProperty(exports,"isPredicate",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.d}});Object.defineProperty(exports,"isRequirementType",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.B}});Object.defineProperty(exports,"isSingleModuleSystem",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.v}});Object.defineProperty(exports,"isTemplate",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.f}});Object.defineProperty(exports,"memoizePredicate",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.j}});Object.defineProperty(exports,"req",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.A}});Object.defineProperty(exports,"typedConstraint",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.t}});Object.defineProperty(exports,"typedResolver",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.u}});Object.defineProperty(exports,"validatePredicate",{enumerable:true,get:function(){return chunkWIZHZF4G_cjs.g}});Object.defineProperty(exports,"diffSnapshots",{enumerable:true,get:function(){return chunkEOLY64E6_cjs.j}});Object.defineProperty(exports,"isSignedSnapshot",{enumerable:true,get:function(){return chunkEOLY64E6_cjs.k}});Object.defineProperty(exports,"isSnapshotExpired",{enumerable:true,get:function(){return chunkEOLY64E6_cjs.h}});Object.defineProperty(exports,"shallowEqual",{enumerable:true,get:function(){return chunkEOLY64E6_cjs.f}});Object.defineProperty(exports,"signSnapshot",{enumerable:true,get:function(){return chunkEOLY64E6_cjs.l}});Object.defineProperty(exports,"validateSnapshot",{enumerable:true,get:function(){return chunkEOLY64E6_cjs.i}});Object.defineProperty(exports,"verifySnapshotSignature",{enumerable:true,get:function(){return chunkEOLY64E6_cjs.m}});exports.Backoff=pt;exports.MAX_REPLAY_FRAMES=b;exports.MAX_SWEEP_POINTS=I;exports.completeTimer=se;exports.createModule=Q;exports.createModuleFactory=We;exports.createRequirementStatusPlugin=N;exports.createStatusHook=He;exports.createSystemWithStatus=Ke;exports.defaultClock=ze;exports.elapsedMs=A;exports.framesFromHistory=X;exports.framesFromSnapshots=$;exports.initialTimerState=U;exports.pauseTimer=te;exports.realClock=Z;exports.registerRepeat=ie;exports.remainingMs=V;exports.replayUnder=C;exports.resetTimer=re;exports.resumeTimer=ne;exports.startTimer=ee;exports.sweepUnder=je;exports.t=_e;exports.tickTimer=oe;exports.timerOps=Xe;exports.toReplayFrames=z;exports.virtualClock=Le;//# sourceMappingURL=index.cjs.map
|
|
5
5
|
//# sourceMappingURL=index.cjs.map
|