@variojs/core 0.1.7 → 0.1.8
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.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {parse}from'@babel/parser';function
|
|
1
|
+
import {parse}from'@babel/parser';function B(e,t){let r=["$event","$item","$index","$self","$parent","$siblings","$children"],n=o=>{if(typeof o=="symbol")return false;let i=o;return !i.startsWith("$")&&!i.startsWith("_")};return new Proxy(e,{set(o,i,s){let a=String(i);if(a.startsWith("$")||a.startsWith("_")){if(r.includes(a))return Reflect.set(o,i,s);throw new Error(`Cannot override system API: ${a}. Properties starting with "$" or "_" are protected.`)}return t&&n(i)?(t.setProperty(a,s),true):Reflect.set(o,i,s)},get(o,i){return t&&typeof i=="string"&&n(i)&&t.has(i)?t.getProperty(i):Reflect.get(o,i)},has(o,i){return t&&typeof i=="string"&&n(i)&&t.has(i)?true:Reflect.has(o,i)},ownKeys(o){let i=Reflect.ownKeys(o);if(t){let s=t.keys(),a=new Set(i);for(let u of s)a.add(u);return [...a]}return i},getOwnPropertyDescriptor(o,i){return t&&typeof i=="string"&&n(i)&&t.has(i)?{configurable:true,enumerable:true,writable:true,value:t.getProperty(i)}:Reflect.getOwnPropertyDescriptor(o,i)},deleteProperty(o,i){let s=String(i);if(s.startsWith("$")||s.startsWith("_")){if(r.includes(s))return Reflect.deleteProperty(o,i);throw new Error(`Cannot delete system API: ${s}`)}return Reflect.deleteProperty(o,i)}})}var _=class e extends Error{code;context;constructor(t,r,n={}){super(t),this.name="VarioError",this.code=r,this.context=n,Error.captureStackTrace&&Error.captureStackTrace(this,e);}getFriendlyMessage(){let t=[this.message];return this.context.schemaPath&&t.push(`
|
|
2
2
|
Schema \u8DEF\u5F84: ${this.context.schemaPath}`),this.context.expression&&t.push(`
|
|
3
3
|
\u8868\u8FBE\u5F0F: ${this.context.expression}`),this.context.action&&t.push(`
|
|
4
|
-
\u52A8\u4F5C\u7C7B\u578B: ${this.context.action.type}`),t.join("")}toJSON(){return {name:this.name,message:this.message,code:this.code,context:this.context,stack:this.stack}}},
|
|
4
|
+
\u52A8\u4F5C\u7C7B\u578B: ${this.context.action.type}`),t.join("")}toJSON(){return {name:this.name,message:this.message,code:this.code,context:this.context,stack:this.stack}}},h=class extends _{constructor(t,r,n="ACTION_ERROR",o={}){super(r,n,{...o,action:t}),this.name="ActionError";}},S=class extends _{constructor(t,r,n="EXPRESSION_ERROR",o={}){super(r,n,{...o,expression:t}),this.name="ExpressionError";}},I=class extends _{service;originalError;constructor(t,r,n,o={}){super(r,"SERVICE_ERROR",o),this.name="ServiceError",this.service=t,this.originalError=n;}},j=class extends _{failedActions;constructor(t,r,n={}){super(r,"BATCH_ERROR",n),this.name="BatchError",this.failedActions=t;}},l={ACTION_UNKNOWN_TYPE:"ACTION_UNKNOWN_TYPE",ACTION_EXECUTION_ERROR:"ACTION_EXECUTION_ERROR",ACTION_ABORTED:"ACTION_ABORTED",ACTION_TIMEOUT:"ACTION_TIMEOUT",ACTION_MAX_STEPS_EXCEEDED:"ACTION_MAX_STEPS_EXCEEDED",ACTION_MISSING_PARAM:"ACTION_MISSING_PARAM",ACTION_INVALID_PARAM:"ACTION_INVALID_PARAM",EXPRESSION_PARSE_ERROR:"EXPRESSION_PARSE_ERROR",EXPRESSION_VALIDATION_ERROR:"EXPRESSION_VALIDATION_ERROR",EXPRESSION_EVALUATION_ERROR:"EXPRESSION_EVALUATION_ERROR",EXPRESSION_TIMEOUT:"EXPRESSION_TIMEOUT",EXPRESSION_MAX_STEPS_EXCEEDED:"EXPRESSION_MAX_STEPS_EXCEEDED",EXPRESSION_UNSAFE_ACCESS:"EXPRESSION_UNSAFE_ACCESS",EXPRESSION_FUNCTION_NOT_WHITELISTED:"EXPRESSION_FUNCTION_NOT_WHITELISTED",SERVICE_NOT_FOUND:"SERVICE_NOT_FOUND",SERVICE_CALL_ERROR:"SERVICE_CALL_ERROR",BATCH_ERROR:"BATCH_ERROR",SCHEMA_VALIDATION_ERROR:"SCHEMA_VALIDATION_ERROR",SCHEMA_INVALID_ACTION:"SCHEMA_INVALID_ACTION"};function q(e){try{let r=parse(`(${e})`,{plugins:["typescript"],sourceType:"module",allowReturnOutsideFunction:!0}).program.body[0];if(r?.type==="ExpressionStatement")return r.expression;throw new S(e,`Failed to parse expression: ${e}`,l.EXPRESSION_PARSE_ERROR)}catch(t){if(t instanceof S)throw t;let r=t instanceof Error?t.message:String(t);throw new S(e,`Expression parse error: ${r}`,l.EXPRESSION_PARSE_ERROR,{metadata:{originalError:t instanceof Error?t.name:"Unknown"}})}}var pe=new Set(["String","Number","Boolean","BigInt","Symbol","Array","Object","Math","Date"]),Fe=new Set(["Array.isArray","Object.is","Number.isFinite","Number.isInteger","Number.isNaN","Number.isSafeInteger","Math.abs","Math.round","Math.floor","Math.ceil","Math.random","Math.max","Math.min","Date.now"]);function Be(e){return ["window","document","global","globalThis","self"].includes(e)}var qe=new Set(["MemberExpression","OptionalMemberExpression","ArrayExpression","ObjectExpression","ObjectProperty","Literal","NumericLiteral","StringLiteral","BooleanLiteral","NullLiteral","Identifier","BinaryExpression","LogicalExpression","UnaryExpression","ConditionalExpression","CallExpression","TemplateLiteral","SequenceExpression","NullishCoalescingExpression"]),Je=new Set(["AssignmentExpression","UpdateExpression","FunctionExpression","ArrowFunctionExpression","ThisExpression","NewExpression","YieldExpression","AwaitExpression","ImportExpression","MetaProperty","SpreadElement"]),ze=50;function J(e,t){let r=t?.allowGlobals===true,n=t?.maxNestingDepth??ze,o=[];function i(a){if(a.type==="Identifier")return a.name;if(a.type==="MemberExpression"){let u=a;if(u.object.type==="Identifier"&&u.property.type==="Identifier")return `${u.object.name}.${u.property.name}`}return null}function s(a,u="root",d=0){if(d>n){o.push(`Maximum nesting depth (${n}) exceeded at ${u}`);return}if(Je.has(a.type)){o.push(`Forbidden node type "${a.type}" at ${u}`);return}if(a.type==="CallExpression"){let y=a,E=i(y.callee);if(E){if(["eval","Function","setTimeout","setInterval","execScript"].includes(E)||E.startsWith("eval")||E.startsWith("Function")){o.push(`Dangerous function "${E}" is not allowed at ${u}`);return}if(!r){let m=Fe.has(E)||pe.has(E.split(".")[0]),v=false;if(y.callee.type==="MemberExpression"){let f=y.callee;if(f.object.type==="Identifier"){let p=f.object.name;!pe.has(p)&&!Be(p)&&(v=true);}}if(!m&&!v&&!E.startsWith("$")){o.push(`Function "${E}" is not in whitelist at ${u}`);return}}}}if(!qe.has(a.type)&&a.type!=="Program"){o.push(`Unknown node type "${a.type}" at ${u}`);return}for(let y in a){let E=a[y];E!=null&&(Array.isArray(E)?E.forEach((g,m)=>{g&&typeof g=="object"&&"type"in g&&s(g,`${u}[${m}]`,d+1);}):E&&typeof E=="object"&&"type"in E&&s(E,`${u}.${y}`,d+1));}}if(s(e,"root",0),o.length>0)throw new S(JSON.stringify(e),`AST validation failed:
|
|
5
5
|
${o.join(`
|
|
6
|
-
`)}`,c.EXPRESSION_VALIDATION_ERROR,{metadata:{errors:o,nodeType:e.type}})}function fe(e){return {...e}}function q(e,t,n={}){return !(!(n.allowGlobals??t.$exprOptions?.allowGlobals??false)&&["window","document","global","globalThis","self"].includes(e))}var ee=new Set(["String","Number","Boolean","BigInt","Symbol","Array","Object","Math","Date"]),de=new Set(["Array.isArray","Object.is","Number.isFinite","Number.isInteger","Number.isNaN","Number.isSafeInteger","Math.abs","Math.round","Math.floor","Math.ceil","Math.random","Math.max","Math.min","Date.now"]),he=new Set(["slice","concat","filter","map","flat","flatMap","toReversed","toSorted","toSpliced","with","indexOf","lastIndexOf","includes","find","findIndex","findLast","findLastIndex","every","some","at","join","toString","toLocaleString","reverse","sort"]),Qe=new Set(["constructor","prototype","__proto__"]);function ge(e){return typeof e=="string"&&Qe.has(e)}var L={$truncate:(e,t)=>{if(typeof e!="string")return e;let n=typeof t=="number"?t:0;return e.length>n?e.slice(0,n)+"...":e},$format:(e,t)=>(typeof e=="number"?new Date(e):e).toISOString()};function J(e,t,n={}){let r={...t.$exprOptions,...n},o=r.allowGlobals===true,i=r.maxSteps??1e3,s=r.timeout??100,a=0,p=Date.now();function h(y){if(o)return y==="globalThis"?globalThis:y==="window"&&typeof window<"u"?window:y==="document"&&typeof document<"u"?document:y==="global"&&typeof global<"u"?global:y==="self"&&typeof self<"u"?self:globalThis[y]}function f(y){return ["window","document","global","globalThis","self"].includes(y)}function S(){if(a++,a>i)throw new E(JSON.stringify(e),`Expression evaluation exceeded max steps (${i})`,c.EXPRESSION_MAX_STEPS_EXCEEDED,{metadata:{maxSteps:i,currentSteps:a}});if(Date.now()-p>s)throw new E(JSON.stringify(e),`Expression evaluation exceeded timeout (${s}ms)`,c.EXPRESSION_TIMEOUT,{metadata:{timeout:s,elapsedTime:Date.now()-p}})}function g(y){switch(S(),y.type){case "NumericLiteral":case "StringLiteral":case "BooleanLiteral":case "BigIntLiteral":case "DecimalLiteral":case "RegExpLiteral":return y.value;case "NullLiteral":return null;case "Literal":{let m=y;return "value"in m&&m.value!==void 0?m.value:m.type==="NullLiteral"?null:m.value??void 0}case "Identifier":{let m=y.name;if(f(m)&&!o)throw new E(m,`Access to global "${m}" is not allowed in expressions`,c.EXPRESSION_UNSAFE_ACCESS);if(m in t&&!f(m))return t[m];if(o){let u=h(m);if(u!==void 0)return u}return ee.has(m)?globalThis[m]:void 0}case "MemberExpression":{let m=y,u=g(m.object);if(u==null)return;if(!o&&(u===globalThis||typeof window<"u"&&u===window||typeof global<"u"&&u===global||typeof self<"u"&&u===self))throw new E(JSON.stringify(y),"Access to global object is not allowed in expressions",c.EXPRESSION_UNSAFE_ACCESS);let l;if(m.computed?l=g(m.property):l=m.property.name,!o&&ge(l))throw new E(String(l),`Access to "${l}" is not allowed in expressions`,c.EXPRESSION_UNSAFE_ACCESS);return u[l]}case "OptionalMemberExpression":{let m=y,u=g(m.object);if(u==null)return;if(!o&&(u===globalThis||typeof window<"u"&&u===window||typeof global<"u"&&u===global||typeof self<"u"&&u===self))throw new E(JSON.stringify(y),"Access to global object is not allowed in expressions",c.EXPRESSION_UNSAFE_ACCESS);let l;if(m.computed?l=g(m.property):l=m.property.name,!o&&ge(l))throw new E(String(l),`Access to "${l}" is not allowed in expressions`,c.EXPRESSION_UNSAFE_ACCESS);return u?.[l]}case "BinaryExpression":{let m=y,u=g(m.left),l=g(m.right),b=m.operator;switch(b){case "+":return u+l;case "-":return u-l;case "*":return u*l;case "/":return u/l;case "%":return u%l;case "**":return u**l;case "==":return u==l;case "!=":return u!=l;case "===":return u===l;case "!==":return u!==l;case "<":return u<l;case "<=":return u<=l;case ">":return u>l;case ">=":return u>=l;case "<<":return u<<l;case ">>":return u>>l;case ">>>":return u>>>l;case "&":return u&l;case "|":return u|l;case "^":return u^l;case "in":return u in l;case "instanceof":{if(typeof l!="function"&&typeof l!="object")throw new E(JSON.stringify(y),"Right-hand side of instanceof must be a constructor",c.EXPRESSION_EVALUATION_ERROR);return u instanceof l}default:throw new E(JSON.stringify(y),`Unsupported binary operator: ${b}`,c.EXPRESSION_EVALUATION_ERROR)}}case "LogicalExpression":{let m=y,u=g(m.left),l=m.operator;if(l==="&&")return u&&g(m.right);if(l==="||")return u||g(m.right);if(l==="??")return u??g(m.right);throw new E(JSON.stringify(y),`Unsupported logical operator: ${l}`,c.EXPRESSION_EVALUATION_ERROR)}case "UnaryExpression":{let m=y,u=g(m.argument),l=m.operator;switch(l){case "+":return +u;case "-":return -u;case "!":return !u;case "~":return ~u;case "typeof":return typeof u;case "void":return;case "delete":throw new E(JSON.stringify(y),"delete operator is not allowed",c.EXPRESSION_EVALUATION_ERROR);default:throw new E(JSON.stringify(y),`Unsupported unary operator: ${l}`,c.EXPRESSION_EVALUATION_ERROR)}}case "ConditionalExpression":{let m=y,u=g(m.test);return g(u?m.consequent:m.alternate)}case "CallExpression":{let m=y,u=m.callee,l,b,_;if(u.type==="Identifier"){if(l=u.name,!q(l,t,{allowGlobals:o}))throw new E(l,`Access to global "${l}" is not allowed in expressions`,"UNSAFE_ACCESS");let w=ee.has(l)||de.has(l)||L[l]!==void 0;if(!o&&!w)throw new E(l,`Function "${l}" is not in whitelist`,c.EXPRESSION_FUNCTION_NOT_WHITELISTED);w?b=L[l]??globalThis[l]:b=t[l]??globalThis[l],_=null;}else if(u.type==="MemberExpression"){let w=u,R=g(w.object);if(R==null)throw new E(JSON.stringify(y),`Cannot call method on ${R===null?"null":"undefined"}`,c.EXPRESSION_EVALUATION_ERROR);if(!o&&(R===globalThis||typeof window<"u"&&R===window||typeof global<"u"&&R===global||typeof self<"u"&&R===self))throw new E(JSON.stringify(y),"Access to global object is not allowed in expressions",c.EXPRESSION_UNSAFE_ACCESS);if(Array.isArray(R)&&!w.computed&&w.property.type==="Identifier"){let T=w.property.name;he.has(T)?(b=R[T],l=`Array.${T}`,_=R):(l=`${w.object.type==="Identifier"?w.object.name:String(R)}.${T}`,b=R?.[T],_=R);}else {let T=w.object.type==="Identifier"?w.object.name:String(R);if(w.computed){let M=g(w.property);l=`${T}[${String(M)}]`,b=R?.[M],_=R;}else {let M=w.property.name;l=`${T}.${M}`,b=R?.[M],_=R;}}}else throw new E(JSON.stringify(y),"Invalid function call: only Identifier and MemberExpression are allowed",c.EXPRESSION_EVALUATION_ERROR);let Fe=l.startsWith("Array.")&&he.has(l.split(".")[1])||de.has(l)||ee.has(l.split(".")[0])||L[l]!==void 0;if(!o&&!Fe)throw new E(l,`Function "${l}" is not in whitelist`,c.EXPRESSION_FUNCTION_NOT_WHITELISTED);let Z=m.arguments.map(w=>{if(w.type==="SpreadElement")throw new E(JSON.stringify(y),"Spread operator is not allowed",c.EXPRESSION_EVALUATION_ERROR);return g(w)});if(L[l])return L[l](...Z);if(typeof b=="function")try{return _!==null?b.apply(_,Z):b(...Z)}catch(w){let R=w instanceof Error?w.message:String(w);throw new E(l,`Error calling "${l}": ${R}`,c.EXPRESSION_EVALUATION_ERROR)}throw new E(l,`"${l}" is not a function${b===void 0?" (undefined)":b===null?" (null)":""}`,c.EXPRESSION_EVALUATION_ERROR)}case "ArrayExpression":return y.elements.map(u=>{if(u==null)return null;if(u.type==="SpreadElement")throw new E(JSON.stringify(y),"Spread operator is not allowed",c.EXPRESSION_EVALUATION_ERROR);return g(u)});case "ObjectExpression":{let m=y,u={};for(let l of m.properties){if(l.type==="ObjectMethod"||l.type==="SpreadElement")throw new E(JSON.stringify(y),"Object methods and spread are not allowed",c.EXPRESSION_EVALUATION_ERROR);let b=l.key.type==="Identifier"?l.key.name:String(g(l.key));u[b]=g(l.value);}return u}case "TemplateLiteral":{let m=y,u="";for(let l=0;l<m.quasis.length;l++)u+=m.quasis[l].value.cooked,l<m.expressions.length&&(u+=String(g(m.expressions[l])));return u}default:throw new E(JSON.stringify(y),`Unsupported node type: ${y.type}`,c.EXPRESSION_EVALUATION_ERROR)}}return g(e)}function D(e){let t=new Set;function n(r,o=""){switch(r.type){case "Identifier":{let i=r;Ye(i.name)||t.add(i.name);break}case "MemberExpression":{let i=r,s=i.object;if(s.type==="Identifier"){let a=s.name;if(i.computed)t.add(`${a}.*`),n(i.property,o);else {let p=i.property.name;t.add(`${a}.${p}`),t.add(`${a}.*`);}}else n(s,o);break}case "OptionalMemberExpression":{let i=r,s=i.object;if(s.type==="Identifier"){let a=s.name;if(i.computed)t.add(`${a}.*`),n(i.property,o);else {let p=i.property.name;t.add(`${a}.${p}`),t.add(`${a}.*`);}}else n(s,o);break}default:for(let i in r){let s=r[i];s!=null&&(Array.isArray(s)?s.forEach(a=>{a&&typeof a=="object"&&"type"in a&&n(a,o);}):s&&typeof s=="object"&&"type"in s&&n(s,o));}}}return n(e),Array.from(t)}function Ye(e){return new Set(["String","Number","Boolean","BigInt","Symbol","Array","Object","Math","Date","console","JSON","parseInt","parseFloat","isNaN","isFinite"]).has(e)}var te=new Map,Ze=["constructor","prototype","__proto__"];function et(e){return e.split(".").some(n=>Ze.includes(n))}function ye(e){if(e.type==="Identifier")return e.name;if(e.type==="MemberExpression"){let t=ye(e.object);if(!t)return null;if(e.computed){if(e.property.type==="NumericLiteral"){let n=e.property.value;return `${t}.${String(n)}`}if(e.property.type==="StringLiteral"){let n=e.property.value;return `${t}.${String(n)}`}return null}else return e.property.type==="Identifier"?`${t}.${e.property.name}`:null}return null}function Ee(e){if(e.type==="NumericLiteral"){let n=e.value;return ()=>n}if(e.type==="StringLiteral"){let n=e.value;return ()=>n}if(e.type==="BooleanLiteral"){let n=e.value;return ()=>n}if(e.type==="NullLiteral")return ()=>null;if(e.type==="Identifier"){let n=e.name;return n.startsWith("$")||n.startsWith("_")||["window","document","global","globalThis","self"].includes(n)?null:o=>o._get(n)}let t=ye(e);if(t){let n=t.split(".")[0];return n.startsWith("$")||n.startsWith("_")||["window","document","global","globalThis","self"].includes(n)||et(t)?null:o=>o._get(t)}return null}function ne(e,t){if(te.has(e))return te.get(e)||null;let n=Ee(t);return te.set(e,n),n}var oe={parsed:new Map};function ie(e){if(!e||e.length===0)return [];let t=[],n="",r=0;for(;r<e.length;){let o=e[r];if(o===".")n&&(t.push(re(n)),n=""),r++;else if(o==="["){n&&(t.push(re(n)),n="");let i=e.indexOf("]",r);if(i===-1)n+=o,r++;else {let s=e.slice(r+1,i);s===""?t.push(-1):/^\d+$/.test(s)?t.push(parseInt(s,10)):t.push(s),r=i+1,e[r]==="."&&r++;}}else n+=o,r++;}return n&&t.push(re(n)),t}function re(e){return /^\d+$/.test(e)?parseInt(e,10):e}function $(e){if(!e||e.length===0)return [];let t=oe.parsed.get(e);if(t)return t;let n=ie(e);return oe.parsed.set(e,n),n}function Se(){oe.parsed.clear();}function se(e){return e.map(String).join(".")}function k(e,t){let n=typeof t=="string"?$(t):t;if(n.length===0)return e;let r=e;for(let o of n){if(r==null)return;if(typeof o=="number"){if(!Array.isArray(r))return;r=r[o];}else {if(typeof r!="object")return;r=r[o];}}return r}function z(e,t,n,r={}){let{createIntermediate:o=true,createObject:i=()=>({}),createArray:s=()=>[]}=r,a=typeof t=="string"?$(t):t;if(a.length===0)return false;let p=a[a.length-1],h=a.slice(0,-1),f=e;for(let S=0;S<h.length;S++){let g=h[S],O=typeof(h[S+1]??p)=="number";if(typeof g=="number"){if(!Array.isArray(f))return false;for(;f.length<=g;)f.push(void 0);if(f[g]==null||typeof f[g]!="object"){if(!o)return false;f[g]=O?s():i();}f=f[g];}else {if(typeof f!="object"||f===null)return false;let m=f;if(m[g]==null||typeof m[g]!="object"){if(!o)return false;m[g]=O?s():i();}f=m[g];}}if(typeof p=="number"){if(!Array.isArray(f))return false;for(;f.length<=p;)f.push(void 0);f[p]=n;}else {if(typeof f!="object"||f===null)return false;f[p]=n;}return true}function V(e,t){if(e===t||t.startsWith(e+"."))return true;if(e.includes("*")){let n=e.split(".*")[0];return t.startsWith(n+".")||t===n}return !!e.startsWith(t+".")}function xe(e){let t=$(e);return t.length<=1?"":se(t.slice(0,-1))}function Ae(e){let t=$(e);return t[t.length-1]}var we=new WeakMap,ae={maxSize:100};function U(e){let t=we.get(e);return t||(t=new Map,we.set(e,t)),t}function tt(e,t){return e.dependencies.every(n=>{if(n.includes("*")){let r=n.split(".*")[0];return t._get(r)!=null}return t._get(n)!==void 0})}function nt(e){let t=null,n=1/0;for(let[r,o]of e.entries())o.timestamp<n&&(n=o.timestamp,t=r);t&&e.delete(t);}function K(e,t){let n=U(t),r=n.get(e);return r?tt(r,t)?(r.timestamp=Date.now(),r.result):(n.delete(e),null):null}function W(e,t,n,r){let o=U(r);o.size>=ae.maxSize&&nt(o),o.set(e,{expr:e,result:t,dependencies:n,timestamp:Date.now()});}function x(e,t){let n=U(t),r=[];for(let[o,i]of n.entries())i.dependencies.some(a=>V(a,e)||V(e,a))&&r.push(o);for(let o of r)n.delete(o);}function Re(e){U(e).clear();}function be(e){let t=U(e);return {size:t.size,expressions:Array.from(t.keys())}}function A(e,t,n={}){try{let r={...t.$exprOptions,...n},o=K(e,t);if(o!==null)return o;let i=H(e);B(i,{allowGlobals:r.allowGlobals,maxNestingDepth:r.maxNestingDepth});let s=ne(e,i);if(s){let h=s(t),f=D(i);return W(e,h,f,t),h}let a=J(i,t,r),p=D(i);return W(e,a,p,t),a}catch(r){if(r instanceof E)throw r;let o=r instanceof Error?r.message:String(r);throw new E(e,`Expression evaluation failed: ${o}`,c.EXPRESSION_EVALUATION_ERROR,{metadata:{originalError:r instanceof Error?r.name:"Unknown",stack:r instanceof Error?r.stack?.split(`
|
|
7
|
-
`).slice(0,5):void 0}})}}async function Ce(e,t){let{path:
|
|
8
|
-
`).slice(0,5):void 0}})}}}async function Oe(e,t){let{cond:n,then:r,else:o}=t;if(!n||typeof n!="string")throw new d(t,'if action requires "cond" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"cond"}});let i=Q(n);A(i,e)?r&&Array.isArray(r)&&await N(r,e):o&&Array.isArray(o)&&await N(o,e);}var ce=class{pool=[];maxSize;constructor(t=10){this.maxSize=t;}acquire(){return this.pool.length>0?this.pool.pop():{}}release(t){"$item"in t&&delete t.$item,"$index"in t&&delete t.$index;let n=[];for(let r in t)!r.startsWith("$")&&!r.startsWith("_")&&n.push(r);for(let r of n)delete t[r];this.pool.length<this.maxSize&&this.pool.push(t);}clear(){this.pool.length=0;}get size(){return this.pool.length}},le=null;function ue(){return le||(le=new ce),le}function X(e,t,n){let o=ue().acquire(),i=Object.create(e);return Object.assign(i,o),i.$item=t,i.$index=n,i}function G(e){ue().release(e);}async function Ie(e,t){let{var:n,in:r,body:o}=t;if(!n||typeof n!="string")throw new d(t,'loop action requires "var" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"var"}});if(!r||typeof r!="string")throw new d(t,'loop action requires "in" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"in"}});if(!o||!Array.isArray(o))throw new d(t,'loop action requires "body" parameter (array of actions)',c.ACTION_MISSING_PARAM,{metadata:{param:"body"}});let i=A(r,e);if(i!=null)if(Array.isArray(i))for(let s=0;s<i.length;s++){let a=X(e,i[s],s);a[n]=i[s];try{x(n,a),await N(o,a);}finally{G(a);}}else if(typeof i=="object"&&i!==null){let s=Object.entries(i);for(let a=0;a<s.length;a++){let[,p]=s[a],h=X(e,p,a);h[n]=p;try{x(n,h),await N(o,h);}finally{G(h);}}}else throw new d(t,`loop "in" expression must evaluate to an array or object, got ${typeof i}`,c.ACTION_INVALID_PARAM,{metadata:{param:"in",actualType:typeof i}})}async function Pe(e,t){let{method:n,params:r,resultTo:o}=t;if(!n||typeof n!="string")throw new d(t,'call action requires "method" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"method"}});let i=e.$methods[n];if(!i)throw new C(n,`Method "${n}" not found in $methods`,void 0,{metadata:{method:n}});let s;try{if(r==null)s={};else if(typeof r=="string"&&r.startsWith("{{")&&r.endsWith("}}")){let p=r.slice(2,-2).trim();s=A(p,e);}else if(Array.isArray(r)){let p=[];for(let h of r)if(typeof h=="string"&&h.startsWith("{{")&&h.endsWith("}}")){let f=h.slice(2,-2).trim();p.push(A(f,e));}else p.push(h);s=p;}else if(typeof r=="object"){let p={};for(let[h,f]of Object.entries(r))if(typeof f=="string"&&f.startsWith("{{")&&f.endsWith("}}")){let S=f.slice(2,-2).trim();p[h]=A(S,e);}else p[h]=f;s=p;}else s=r;let a=await i(e,s);return o&&(e._set(o,a),x(o,e)),a}catch(a){if(a instanceof C)throw a;let p=a instanceof Error?a.message:String(a),h=a instanceof Error?a:void 0;throw new C(n,`Service call failed: ${p}`,h,{metadata:{method:n,params:s}})}}async function _e(e,t){let{actions:n}=t;if(!n||!Array.isArray(n))throw new d(t,'batch action requires "actions" parameter (array)',c.ACTION_MISSING_PARAM,{metadata:{param:"actions"}});let r=[];for(let o of n)try{await N([o],e);}catch(i){r.push({action:o,error:i instanceof Error?i:new Error(String(i))});}if(r.length>0)throw new v(r,`${r.length} actions failed in batch`,{metadata:{failedCount:r.length,totalCount:n.length}})}async function ve(e,t){let{to:n}=t;if(!n||typeof n!="string")throw new d(t,'navigate action requires "to" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"to"}});let r=n;if(n.startsWith("{{")&&n.endsWith("}}")){let i=n.slice(2,-2).trim(),s=A(i,e);if(typeof s!="string")throw new d(t,`navigate "to" expression must evaluate to a string, got ${typeof s}`,c.ACTION_INVALID_PARAM,{metadata:{param:"to",actualType:typeof s}});r=s;}let o=e.$methods.$navigate||e.$methods.$router;if(o)await o(e,{to:r});else if(typeof window<"u"&&window.location)window.location.href=r;else throw new d(t,"navigate method not registered and window.location is not available",c.ACTION_EXECUTION_ERROR,{metadata:{reason:"navigate_not_available"}})}async function ke(e,t){let{level:n="info",message:r}=t;if(!r)throw new d(t,'log action requires "message" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"message"}});let o=r;if(typeof r=="string"&&r.startsWith("{{")&&r.endsWith("}}")){let a=r.slice(2,-2).trim();o=A(a,e);}let i=String(n).toLowerCase(),s=String(o);if(typeof console<"u")switch(i){case "error":console.error("[Vario]",s);break;case "warn":console.warn("[Vario]",s);break;default:console.log("[Vario]",s);break}}function P(e,t){if(typeof e=="string"){if(e.startsWith("{{")&&e.endsWith("}}")){let n=e.slice(2,-2).trim();return A(n,t)}return e}if(Array.isArray(e))return e.map(n=>P(n,t));if(e&&typeof e=="object"){let n={};for(let[r,o]of Object.entries(e))n[r]=P(o,t);return n}return e}async function Me(e,t){let{path:n,value:r,items:o}=t;if(!n||typeof n!="string")throw new d(t,'push action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let i=e._get(n);if(!Array.isArray(i))throw new d(t,`Path "${n}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:n,actualType:typeof i}});let s=o!==void 0?o:r;if(s===void 0)throw new d(t,'push action requires "value" or "items" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"value|items"}});let a=P(s,e);Array.isArray(a)?i.push(...a):i.push(a),x(n,e),x(`${n}.*`,e);}async function $e(e,t){let{path:n}=t;if(!n||typeof n!="string")throw new d(t,'pop action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let r=e._get(n);if(!Array.isArray(r))throw new d(t,`Path "${n}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:n,actualType:typeof r}});r.pop(),x(n,e),x(`${n}.*`,e);}async function je(e,t){let{path:n}=t;if(!n||typeof n!="string")throw new d(t,'shift action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let r=e._get(n);if(!Array.isArray(r))throw new d(t,`Path "${n}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:n,actualType:typeof r}});r.shift(),x(n,e),x(`${n}.*`,e);}async function Le(e,t){let{path:n,value:r,items:o}=t;if(!n||typeof n!="string")throw new d(t,'unshift action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let i=e._get(n);if(!Array.isArray(i))throw new d(t,`Path "${n}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:n,actualType:typeof i}});let s=o!==void 0?o:r;if(s===void 0)throw new d(t,'unshift action requires "value" or "items" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"value|items"}});let a=P(s,e);Array.isArray(a)?i.unshift(...a):i.unshift(a),x(n,e),x(`${n}.*`,e);}async function De(e,t){let{path:n,start:r,deleteCount:o=0,items:i}=t;if(!n||typeof n!="string")throw new d(t,'splice action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let s=e._get(n);if(!Array.isArray(s))throw new d(t,`Path "${n}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:n,actualType:typeof s}});let a;if(typeof r=="string"&&r.startsWith("{{")&&r.endsWith("}}")){let f=r.slice(2,-2).trim();a=Number(A(f,e));}else a=Number(r);let p;if(typeof o=="string"&&o.startsWith("{{")&&o.endsWith("}}")){let f=o.slice(2,-2).trim();p=Number(A(f,e));}else p=Number(o);let h=[];if(i!=null){let f=P(i,e);Array.isArray(f)?h=f:h=[f];}s.splice(a,p,...h),x(n,e),x(`${n}.*`,e);}var rt={set:Ce,emit:Ne,navigate:ve,log:ke,if:Oe,loop:Ie,call:Pe,batch:_e,push:Me,pop:$e,shift:je,unshift:Le,splice:De};function Y(e){for(let[t,n]of Object.entries(rt))t in e.$methods||(e.$methods[t]=n);}function Ve(e={},t={}){ot(e);let{onEmit:n,methods:r={},onStateChange:o,createObject:i=()=>({}),createArray:s=()=>[],exprOptions:a,adapter:p}=t,h=null,f={...p?{}:e,$emit:(g,y)=>{n&&n(g,y);},$methods:r,$exprOptions:a,_get:g=>p?p.get(g):k(f,g),_set:(g,y,O)=>{p?p.set(g,y):z(f,g,y,{createObject:i,createArray:s}),x(g,h||f),o&&!O?.skipCallback&&o(g,y,h||f);}};Y(f);let S=F(f,p);return h=S,S}function ot(e){for(let t in e)if(t.startsWith("$")||t.startsWith("_"))throw new Error(`Property name "${t}" conflicts with system API. Properties starting with "$" or "_" are reserved. Use a different name.`)}function j(e,t,n="."){function r(o,i,s,a){if(!(!o||typeof o!="object"||t(o,i,s,a)===false)&&o.children){if(Array.isArray(o.children))o.children.forEach((h,f)=>{if(h&&typeof h=="object"){let S=i?`${i}${n}children${n}${f}`:`children${n}${f}`;r(h,S,s+1,o);}});else if(typeof o.children=="object"){let h=i?`${i}${n}children`:"children";r(o.children,h,s+1,o);}}}r(e,"",0,null);}function Ue(e,t={}){let n={nodeCount:0,maxDepth:0},r=new Map,o=t.buildPathMap?new Map:void 0;return j(e,(i,s,a)=>{n.nodeCount++,a>n.maxDepth&&(n.maxDepth=a);let p=i;p.id&&typeof p.id=="string"&&r.set(p.id,s),o&&o.set(s,i),t.onNode?.(i,s,a);}),{stats:n,index:{idMap:r,pathMap:o}}}function We(e,t){let n=[];return j(e,(r,o)=>{t(r)&&n.push({node:r,path:o});}),n}function pe(e,t){let n=null;return j(e,(r,o)=>{if(t(r))return n={node:r,path:o},false}),n}function Xe(e,t){return pe(e,r=>r.id===t)?.path||null}function Ge(e){let{schema:t,index:n}=e;return {findById:i=>{if(n?.idMap){let s=n.idMap.get(i);if(!s)return null;if(n.pathMap){let p=n.pathMap.get(s);return p?{node:p,path:s}:null}let a=k(t,s);return a?{node:a,path:s}:null}return null},getParent:i=>{if(!i||!i.includes("."))return null;let s=i;for(;;){let a=s.lastIndexOf(".");if(a===-1)return {node:t,path:""};s=s.substring(0,a);let p=s.split(".").pop();if(p&&["children","definitions","items"].includes(p))continue;let h=k(t,s);if(!(Array.isArray(h)||typeof h=="string")&&h&&typeof h=="object")return {node:h,path:s}}}}}export{d as ActionError,v as BatchError,c as ErrorCodes,E as ExpressionError,C as ServiceError,I as VarioError,Ue as analyzeSchema,Re as clearCache,Se as clearPathCache,fe as createExpressionSandbox,X as createLoopContext,F as createProxy,Ge as createQueryEngine,Ve as createRuntimeContext,A as evaluate,J as evaluateExpression,N as execute,D as extractDependencies,Q as extractExpression,pe as findNode,We as findNodes,Xe as findPathById,be as getCacheStats,K as getCachedExpression,Ae as getLastSegment,xe as getParentPath,k as getPathValue,x as invalidateCache,q as isSafePropertyAccess,V as matchPath,H as parseExpression,ie as parsePath,$ as parsePathCached,Y as registerBuiltinMethods,G as releaseLoopContext,W as setCachedExpression,z as setPathValue,se as stringifyPath,j as traverseSchema,B as validateAST};//# sourceMappingURL=index.js.map
|
|
6
|
+
`)}`,l.EXPRESSION_VALIDATION_ERROR,{metadata:{errors:o,nodeType:e.type}})}function me(e){return {...e}}function z(e,t,r={}){return !(!(r.allowGlobals??t.$exprOptions?.allowGlobals??false)&&["window","document","global","globalThis","self"].includes(e))}var re=new Set(["String","Number","Boolean","BigInt","Symbol","Array","Object","Math","Date"]),fe=new Set(["Array.isArray","Object.is","Number.isFinite","Number.isInteger","Number.isNaN","Number.isSafeInteger","Math.abs","Math.round","Math.floor","Math.ceil","Math.random","Math.max","Math.min","Date.now"]),de=new Set(["slice","concat","filter","map","flat","flatMap","toReversed","toSorted","toSpliced","with","indexOf","lastIndexOf","includes","find","findIndex","findLast","findLastIndex","every","some","at","join","toString","toLocaleString","reverse","sort"]),Ke=new Set(["constructor","prototype","__proto__"]);function he(e){return typeof e=="string"&&Ke.has(e)}var L={$truncate:(e,t)=>{if(typeof e!="string")return e;let r=typeof t=="number"?t:0;return e.length>r?e.slice(0,r)+"...":e},$format:(e,t)=>(typeof e=="number"?new Date(e):e).toISOString()};function K(e,t,r={}){let n={...t.$exprOptions,...r},o=n.allowGlobals===true,i=n.maxSteps??1e3,s=n.timeout??100,a=0,u=Date.now();function d(m){if(o)return m==="globalThis"?globalThis:m==="window"&&typeof window<"u"?window:m==="document"&&typeof document<"u"?document:m==="global"&&typeof global<"u"?global:m==="self"&&typeof self<"u"?self:globalThis[m]}function y(m){return ["window","document","global","globalThis","self"].includes(m)}function E(){if(a++,a>i)throw new S(JSON.stringify(e),`Expression evaluation exceeded max steps (${i})`,l.EXPRESSION_MAX_STEPS_EXCEEDED,{metadata:{maxSteps:i,currentSteps:a}});if(Date.now()-u>s)throw new S(JSON.stringify(e),`Expression evaluation exceeded timeout (${s}ms)`,l.EXPRESSION_TIMEOUT,{metadata:{timeout:s,elapsedTime:Date.now()-u}})}function g(m){switch(E(),m.type){case "NumericLiteral":case "StringLiteral":case "BooleanLiteral":case "BigIntLiteral":case "DecimalLiteral":case "RegExpLiteral":return m.value;case "NullLiteral":return null;case "Literal":{let f=m;return "value"in f&&f.value!==void 0?f.value:f.type==="NullLiteral"?null:f.value??void 0}case "Identifier":{let f=m.name;if(y(f)&&!o)throw new S(f,`Access to global "${f}" is not allowed in expressions`,l.EXPRESSION_UNSAFE_ACCESS);if(f in t&&!y(f))return t[f];if(o){let p=d(f);if(p!==void 0)return p}return re.has(f)?globalThis[f]:void 0}case "MemberExpression":{let f=m,p=g(f.object);if(p==null)return;if(!o&&(p===globalThis||typeof window<"u"&&p===window||typeof global<"u"&&p===global||typeof self<"u"&&p===self))throw new S(JSON.stringify(m),"Access to global object is not allowed in expressions",l.EXPRESSION_UNSAFE_ACCESS);let c;if(f.computed?c=g(f.property):c=f.property.name,!o&&he(c))throw new S(String(c),`Access to "${c}" is not allowed in expressions`,l.EXPRESSION_UNSAFE_ACCESS);return p[c]}case "OptionalMemberExpression":{let f=m,p=g(f.object);if(p==null)return;if(!o&&(p===globalThis||typeof window<"u"&&p===window||typeof global<"u"&&p===global||typeof self<"u"&&p===self))throw new S(JSON.stringify(m),"Access to global object is not allowed in expressions",l.EXPRESSION_UNSAFE_ACCESS);let c;if(f.computed?c=g(f.property):c=f.property.name,!o&&he(c))throw new S(String(c),`Access to "${c}" is not allowed in expressions`,l.EXPRESSION_UNSAFE_ACCESS);return p?.[c]}case "BinaryExpression":{let f=m,p=g(f.left),c=g(f.right),C=f.operator;switch(C){case "+":return p+c;case "-":return p-c;case "*":return p*c;case "/":return p/c;case "%":return p%c;case "**":return p**c;case "==":return p==c;case "!=":return p!=c;case "===":return p===c;case "!==":return p!==c;case "<":return p<c;case "<=":return p<=c;case ">":return p>c;case ">=":return p>=c;case "<<":return p<<c;case ">>":return p>>c;case ">>>":return p>>>c;case "&":return p&c;case "|":return p|c;case "^":return p^c;case "in":{if(c==null||typeof c!="object"&&typeof c!="function")throw new S(JSON.stringify(m),"Right-hand side of 'in' must be an object",l.EXPRESSION_EVALUATION_ERROR);return p in c}case "instanceof":{if(typeof c!="function"&&typeof c!="object")throw new S(JSON.stringify(m),"Right-hand side of instanceof must be a constructor",l.EXPRESSION_EVALUATION_ERROR);return p instanceof c}default:throw new S(JSON.stringify(m),`Unsupported binary operator: ${C}`,l.EXPRESSION_EVALUATION_ERROR)}}case "LogicalExpression":{let f=m,p=g(f.left),c=f.operator;if(c==="&&")return p&&g(f.right);if(c==="||")return p||g(f.right);if(c==="??")return p??g(f.right);throw new S(JSON.stringify(m),`Unsupported logical operator: ${c}`,l.EXPRESSION_EVALUATION_ERROR)}case "UnaryExpression":{let f=m,p=g(f.argument),c=f.operator;switch(c){case "+":return +p;case "-":return -p;case "!":return !p;case "~":return ~p;case "typeof":return typeof p;case "void":return;case "delete":throw new S(JSON.stringify(m),"delete operator is not allowed",l.EXPRESSION_EVALUATION_ERROR);default:throw new S(JSON.stringify(m),`Unsupported unary operator: ${c}`,l.EXPRESSION_EVALUATION_ERROR)}}case "ConditionalExpression":{let f=m,p=g(f.test);return g(p?f.consequent:f.alternate)}case "CallExpression":{let f=m,p=f.callee,c,C,O;if(p.type==="Identifier"){if(c=p.name,!z(c,t,{allowGlobals:o}))throw new S(c,`Access to global "${c}" is not allowed in expressions`,"UNSAFE_ACCESS");let w=re.has(c)||fe.has(c)||L[c]!==void 0;if(!o&&!w)throw new S(c,`Function "${c}" is not in whitelist`,l.EXPRESSION_FUNCTION_NOT_WHITELISTED);w?C=L[c]??globalThis[c]:C=t[c]??globalThis[c],O=null;}else if(p.type==="MemberExpression"){let w=p,R=g(w.object);if(R==null)throw new S(JSON.stringify(m),`Cannot call method on ${R===null?"null":"undefined"}`,l.EXPRESSION_EVALUATION_ERROR);if(!o&&(R===globalThis||typeof window<"u"&&R===window||typeof global<"u"&&R===global||typeof self<"u"&&R===self))throw new S(JSON.stringify(m),"Access to global object is not allowed in expressions",l.EXPRESSION_UNSAFE_ACCESS);if(Array.isArray(R)&&!w.computed&&w.property.type==="Identifier"){let N=w.property.name;de.has(N)?(C=R[N],c=`Array.${N}`,O=R):(c=`${w.object.type==="Identifier"?w.object.name:String(R)}.${N}`,C=R?.[N],O=R);}else {let N=w.object.type==="Identifier"?w.object.name:String(R);if(w.computed){let M=g(w.property);c=`${N}[${String(M)}]`,C=R?.[M],O=R;}else {let M=w.property.name;c=`${N}.${M}`,C=R?.[M],O=R;}}}else throw new S(JSON.stringify(m),"Invalid function call: only Identifier and MemberExpression are allowed",l.EXPRESSION_EVALUATION_ERROR);let Ge=c.startsWith("Array.")&&de.has(c.split(".")[1])||fe.has(c)||re.has(c.split(".")[0])||L[c]!==void 0;if(!o&&!Ge)throw new S(c,`Function "${c}" is not in whitelist`,l.EXPRESSION_FUNCTION_NOT_WHITELISTED);let te=f.arguments.map(w=>{if(w.type==="SpreadElement")throw new S(JSON.stringify(m),"Spread operator is not allowed",l.EXPRESSION_EVALUATION_ERROR);return g(w)});if(L[c])return L[c](...te);if(typeof C=="function")try{return O!==null?C.apply(O,te):C(...te)}catch(w){let R=w instanceof Error?w.message:String(w);throw new S(c,`Error calling "${c}": ${R}`,l.EXPRESSION_EVALUATION_ERROR)}throw new S(c,`"${c}" is not a function${C===void 0?" (undefined)":C===null?" (null)":""}`,l.EXPRESSION_EVALUATION_ERROR)}case "ArrayExpression":return m.elements.map(p=>{if(p==null)return null;if(p.type==="SpreadElement")throw new S(JSON.stringify(m),"Spread operator is not allowed",l.EXPRESSION_EVALUATION_ERROR);return g(p)});case "ObjectExpression":{let f=m,p={};for(let c of f.properties){if(c.type==="ObjectMethod"||c.type==="SpreadElement")throw new S(JSON.stringify(m),"Object methods and spread are not allowed",l.EXPRESSION_EVALUATION_ERROR);let C=c.key.type==="Identifier"?c.key.name:String(g(c.key));p[C]=g(c.value);}return p}case "TemplateLiteral":{let f=m,p="";for(let c=0;c<f.quasis.length;c++)p+=f.quasis[c].value.cooked,c<f.expressions.length&&(p+=String(g(f.expressions[c])));return p}default:throw new S(JSON.stringify(m),`Unsupported node type: ${m.type}`,l.EXPRESSION_EVALUATION_ERROR)}}return g(e)}function D(e){let t=new Set;function r(n,o=""){switch(n.type){case "Identifier":{let i=n;Qe(i.name)||t.add(i.name);break}case "MemberExpression":{let i=n,s=i.object;if(s.type==="Identifier"){let a=s.name;if(i.computed)t.add(`${a}.*`),r(i.property,o);else {let u=i.property.name;t.add(`${a}.${u}`),t.add(`${a}.*`);}}else r(s,o);break}case "OptionalMemberExpression":{let i=n,s=i.object;if(s.type==="Identifier"){let a=s.name;if(i.computed)t.add(`${a}.*`),r(i.property,o);else {let u=i.property.name;t.add(`${a}.${u}`),t.add(`${a}.*`);}}else r(s,o);break}default:for(let i in n){let s=n[i];s!=null&&(Array.isArray(s)?s.forEach(a=>{a&&typeof a=="object"&&"type"in a&&r(a,o);}):s&&typeof s=="object"&&"type"in s&&r(s,o));}}}return r(e),Array.from(t)}function Qe(e){return new Set(["String","Number","Boolean","BigInt","Symbol","Array","Object","Math","Date","console","JSON","parseInt","parseFloat","isNaN","isFinite"]).has(e)}var U=new Map,Ye=["constructor","prototype","__proto__"];function Ze(e){return e.split(".").some(r=>Ye.includes(r))}function Ee(e){if(e.type==="Identifier")return e.name;if(e.type==="MemberExpression"){let t=Ee(e.object);if(!t)return null;if(e.computed){if(e.property.type==="NumericLiteral"){let r=e.property.value;return `${t}.${String(r)}`}if(e.property.type==="StringLiteral"){let r=e.property.value;return `${t}.${String(r)}`}return null}else return e.property.type==="Identifier"?`${t}.${e.property.name}`:null}return null}function et(e){if(e.type==="NumericLiteral"){let r=e.value;return ()=>r}if(e.type==="StringLiteral"){let r=e.value;return ()=>r}if(e.type==="BooleanLiteral"){let r=e.value;return ()=>r}if(e.type==="NullLiteral")return ()=>null;if(e.type==="Identifier"){let r=e.name;return r.startsWith("$")||r.startsWith("_")||["window","document","global","globalThis","self"].includes(r)?null:o=>o._get(r)}let t=Ee(e);if(t){let r=t.split(".")[0];return r.startsWith("$")||r.startsWith("_")||["window","document","global","globalThis","self"].includes(r)||Ze(t)?null:o=>o._get(t)}return null}function ye(e,t){if(U.has(e))return U.get(e)||null;let r=et(t);return U.size>=2e3&&U.clear(),U.set(e,r),r}var X={parsed:new Map};function oe(e){if(!e||e.length===0)return [];let t=[],r="",n=0;for(;n<e.length;){let o=e[n];if(o===".")r&&(t.push(ne(r)),r=""),n++;else if(o==="["){r&&(t.push(ne(r)),r="");let i=e.indexOf("]",n);if(i===-1)r+=o,n++;else {let s=e.slice(n+1,i);s===""?t.push(-1):/^\d+$/.test(s)?t.push(parseInt(s,10)):t.push(s),n=i+1,e[n]==="."&&n++;}}else r+=o,n++;}return r&&t.push(ne(r)),t}function ne(e){return /^\d+$/.test(e)?parseInt(e,10):e}function k(e){if(!e||e.length===0)return [];let t=X.parsed.get(e);if(t)return t;let r=oe(e);return X.parsed.size>=2e3&&X.parsed.clear(),X.parsed.set(e,r),r}function ge(){X.parsed.clear();}function ie(e){return e.map(String).join(".")}function P(e,t){let r=typeof t=="string"?k(t):t;if(r.length===0)return e;let n=e;for(let o of r){if(n==null)return;if(typeof o=="number"){if(!Array.isArray(n))return;n=n[o];}else {if(typeof n!="object")return;n=n[o];}}return n}function Q(e,t,r,n={}){let{createIntermediate:o=true,createObject:i=()=>({}),createArray:s=()=>[]}=n,a=typeof t=="string"?k(t):t;if(a.length===0||a.length>20)return false;let d=a[a.length-1],y=a.slice(0,-1),E=e;for(let g=0;g<y.length;g++){let m=y[g],f=typeof(y[g+1]??d)=="number";if(typeof m=="number"){if(!Array.isArray(E))return false;for(;E.length<=m;)E.push(void 0);if(E[m]==null||typeof E[m]!="object"){if(!o)return false;E[m]=f?s():i();}E=E[m];}else {if(typeof E!="object"||E===null)return false;let p=E;if(p[m]==null||typeof p[m]!="object"){if(!o)return false;p[m]=f?s():i();}E=p[m];}}if(typeof d=="number"){if(!Array.isArray(E))return false;for(;E.length<=d;)E.push(void 0);E[d]=r;}else {if(typeof E!="object"||E===null)return false;E[d]=r;}return true}function V(e,t){if(e===t||t.startsWith(e+"."))return true;if(e.includes("*")){let r=e.split(".*")[0];return t.startsWith(r+".")||t===r}return !!e.startsWith(t+".")}function Se(e){let t=k(e);return t.length<=1?"":ie(t.slice(0,-1))}function xe(e){let t=k(e);return t[t.length-1]}var Ae=new WeakMap,se={maxSize:100};function W(e){let t=Ae.get(e);return t||(t=new Map,Ae.set(e,t)),t}function tt(e,t){return e.dependencies.every(r=>{if(r.includes("*")){let n=r.split(".*")[0];return t._get(n)!=null}return t._get(r)!==void 0})}function rt(e){let t=null,r=1/0;for(let[n,o]of e.entries())o.timestamp<r&&(r=o.timestamp,t=n);t&&e.delete(t);}function Y(e,t){let r=W(t),n=r.get(e);return n?tt(n,t)?(n.timestamp=Date.now(),n.result):(r.delete(e),null):null}function G(e,t,r,n){let o=W(n);o.size>=se.maxSize&&rt(o),o.set(e,{expr:e,result:t,dependencies:r,timestamp:Date.now()});}function x(e,t){let r=W(t),n=[];for(let[o,i]of r.entries())i.dependencies.some(a=>V(a,e)||V(e,a))&&n.push(o);for(let o of n)r.delete(o);}function we(e){W(e).clear();}function Re(e){let t=W(e);return {size:t.size,expressions:Array.from(t.keys())}}function A(e,t,r={}){try{let n={...t.$exprOptions,...r},o=Y(e,t);if(o!==null)return o;let i=q(e);J(i,{allowGlobals:n.allowGlobals,maxNestingDepth:n.maxNestingDepth});let s=ye(e,i);if(s){let d=s(t),y=D(i);return G(e,d,y,t),d}let a=K(i,t,n),u=D(i);return G(e,a,u,t),a}catch(n){if(n instanceof S)throw n;let o=n instanceof Error?n.message:String(n);throw new S(e,`Expression evaluation failed: ${o}`,l.EXPRESSION_EVALUATION_ERROR,{metadata:{originalError:n instanceof Error?n.name:"Unknown",stack:n instanceof Error?n.stack?.split(`
|
|
7
|
+
`).slice(0,5):void 0}})}}async function Ce(e,t){let{path:r,value:n}=t;if(!r||typeof r!="string")throw new h(t,'set action requires "path" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let o=n;if(typeof n=="string"&&n.startsWith("{{")&&n.endsWith("}}")){let i=n.slice(2,-2).trim();o=A(i,e);}e._set(r,o);}async function be(e,t){let{event:r,data:n}=t;if(!r||typeof r!="string")throw new h(t,'emit action requires "event" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"event"}});let o=n;if(typeof n=="string"&&n.startsWith("{{")&&n.endsWith("}}")){let i=n.slice(2,-2).trim();o=A(i,e);}e.$emit(r,o);}function Z(e){return typeof e!="string"?String(e):e.startsWith("{{")&&e.endsWith("}}")?e.slice(2,-2).trim():e.trim()}async function b(e,t,r={}){let n=r.timeout??5e3,o=r.maxSteps??1e4,i=Date.now(),s=0,a=null;if(typeof AbortController<"u"){a=new AbortController;let u=setTimeout(()=>{a?.abort();},n),d=()=>clearTimeout(u);try{await Ne(e,t,a.signal,o,()=>{if(s++,s>o)throw new h(e[e.length-1]||{type:"unknown"},`Action execution exceeded max steps (${o})`,l.ACTION_MAX_STEPS_EXCEEDED,{metadata:{maxSteps:o,currentSteps:s}});if(Date.now()-i>n)throw new h(e[e.length-1]||{type:"unknown"},`Action execution exceeded timeout (${n}ms)`,l.ACTION_TIMEOUT,{metadata:{timeout:n,elapsedTime:Date.now()-i}})},n),d();}catch(y){throw d(),y}}else await Ne(e,t,null,o,()=>{if(s++,s>o)throw new h(e[e.length-1]||{type:"unknown"},`Action execution exceeded max steps (${o})`,l.ACTION_MAX_STEPS_EXCEEDED,{metadata:{maxSteps:o,currentSteps:s}});if(Date.now()-i>n)throw new h(e[e.length-1]||{type:"unknown"},`Action execution exceeded timeout (${n}ms)`,l.ACTION_TIMEOUT,{metadata:{timeout:n,elapsedTime:Date.now()-i}})},n);if(Date.now()-i>n)throw new h(e[e.length-1]||{type:"unknown"},`Action execution exceeded timeout (${n}ms)`,l.ACTION_TIMEOUT,{metadata:{timeout:n,elapsedTime:Date.now()-i,actionCount:e.length}})}function nt(e,t){let r;return {promise:new Promise((o,i)=>{r=setTimeout(()=>{i(new h(e,`Action handler exceeded forced timeout (${t}ms)`,l.ACTION_TIMEOUT,{metadata:{timeout:t,forcedTimeout:true}}));},t);}),clear:()=>clearTimeout(r)}}async function Ne(e,t,r,n,o,i=5e3){for(let s of e){if(r?.aborted)throw new h(s,"Action execution was aborted",l.ACTION_ABORTED);o();let a=t.$methods[s.type];if(!a)throw new h(s,`Unknown action type: ${s.type}. Make sure the action is registered in $methods`,l.ACTION_UNKNOWN_TYPE);try{let u=a(t,s);if(u&&typeof u.then=="function"){let d=nt(s,i);try{await Promise.race([u,d.promise]);}finally{d.clear();}}else await u;}catch(u){if(u instanceof h||u instanceof I)throw u;let d=u instanceof Error?u.message:String(u);throw new h(s,`Action execution failed: ${d}`,l.ACTION_EXECUTION_ERROR,{metadata:{originalError:u instanceof Error?u.name:"Unknown",stack:u instanceof Error?u.stack?.split(`
|
|
8
|
+
`).slice(0,5):void 0}})}}}async function Ie(e,t){let{cond:r,then:n,else:o}=t;if(!r||typeof r!="string")throw new h(t,'if action requires "cond" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"cond"}});let i=Z(r);A(i,e)?n&&Array.isArray(n)&&await b(n,e):o&&Array.isArray(o)&&await b(o,e);}var ce=class{pool=[];maxSize;constructor(t=100){this.maxSize=t;}acquire(){return this.pool.length>0?this.pool.pop():{}}release(t){"$item"in t&&delete t.$item,"$index"in t&&delete t.$index;let r=[];for(let n in t)!n.startsWith("$")&&!n.startsWith("_")&&r.push(n);for(let n of r)delete t[n];this.pool.length<this.maxSize&&this.pool.push(t);}clear(){this.pool.length=0;}get size(){return this.pool.length}},ae=null;function le(){return ae||(ae=new ce),ae}function H(e,t,r){let o=le().acquire(),i=Object.create(e);return Object.assign(i,o),i.$item=t,i.$index=r,i}function F(e){le().release(e);}async function Te(e,t){let{var:r,in:n,body:o}=t;if(!r||typeof r!="string")throw new h(t,'loop action requires "var" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"var"}});if(!n||typeof n!="string")throw new h(t,'loop action requires "in" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"in"}});if(!o||!Array.isArray(o))throw new h(t,'loop action requires "body" parameter (array of actions)',l.ACTION_MISSING_PARAM,{metadata:{param:"body"}});let i=A(n,e);if(i!=null)if(Array.isArray(i))for(let s=0;s<i.length;s++){let a=H(e,i[s],s);a[r]=i[s];try{x(r,a),await b(o,a);}finally{F(a);}}else if(typeof i=="object"&&i!==null){let s=Object.entries(i);for(let a=0;a<s.length;a++){let[,u]=s[a],d=H(e,u,a);d[r]=u;try{x(r,d),await b(o,d);}finally{F(d);}}}else throw new h(t,`loop "in" expression must evaluate to an array or object, got ${typeof i}`,l.ACTION_INVALID_PARAM,{metadata:{param:"in",actualType:typeof i}})}async function Oe(e,t){let{method:r,params:n,resultTo:o}=t;if(!r||typeof r!="string")throw new h(t,'call action requires "method" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"method"}});let i=e.$methods[r];if(!i)throw new I(r,`Method "${r}" not found in $methods`,void 0,{metadata:{method:r}});let s;try{if(n==null)s={};else if(typeof n=="string"&&n.startsWith("{{")&&n.endsWith("}}")){let u=n.slice(2,-2).trim();s=A(u,e);}else if(Array.isArray(n)){let u=[];for(let d of n)if(typeof d=="string"&&d.startsWith("{{")&&d.endsWith("}}")){let y=d.slice(2,-2).trim();u.push(A(y,e));}else u.push(d);s=u;}else if(typeof n=="object"){let u={};for(let[d,y]of Object.entries(n))if(typeof y=="string"&&y.startsWith("{{")&&y.endsWith("}}")){let E=y.slice(2,-2).trim();u[d]=A(E,e);}else u[d]=y;s=u;}else s=n;let a=await i(e,s);return o&&(e._set(o,a),x(o,e)),a}catch(a){if(a instanceof I)throw a;let u=a instanceof Error?a.message:String(a),d=a instanceof Error?a:void 0;throw new I(r,`Service call failed: ${u}`,d,{metadata:{method:r,params:s}})}}async function _e(e,t){let{actions:r}=t;if(!r||!Array.isArray(r))throw new h(t,'batch action requires "actions" parameter (array)',l.ACTION_MISSING_PARAM,{metadata:{param:"actions"}});let n=[];for(let o of r)try{await b([o],e);}catch(i){n.push({action:o,error:i instanceof Error?i:new Error(String(i))});}if(n.length>0)throw new j(n,`${n.length} actions failed in batch`,{metadata:{failedCount:n.length,totalCount:r.length}})}async function Pe(e,t){let{to:r}=t;if(!r||typeof r!="string")throw new h(t,'navigate action requires "to" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"to"}});let n=r;if(r.startsWith("{{")&&r.endsWith("}}")){let i=r.slice(2,-2).trim(),s=A(i,e);if(typeof s!="string")throw new h(t,`navigate "to" expression must evaluate to a string, got ${typeof s}`,l.ACTION_INVALID_PARAM,{metadata:{param:"to",actualType:typeof s}});n=s;}let o=e.$methods.$navigate||e.$methods.$router;if(o)await o(e,{to:n});else if(typeof window<"u"&&window.location)window.location.href=n;else throw new h(t,"navigate method not registered and window.location is not available",l.ACTION_EXECUTION_ERROR,{metadata:{reason:"navigate_not_available"}})}async function ve(e,t){let{level:r="info",message:n}=t;if(!n)throw new h(t,'log action requires "message" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"message"}});let o=n;if(typeof n=="string"&&n.startsWith("{{")&&n.endsWith("}}")){let a=n.slice(2,-2).trim();o=A(a,e);}let i=String(r).toLowerCase(),s=String(o);if(typeof console<"u")switch(i){case "error":console.error("[Vario]",s);break;case "warn":console.warn("[Vario]",s);break;default:console.log("[Vario]",s);break}}function T(e,t){if(typeof e=="string"){if(e.startsWith("{{")&&e.endsWith("}}")){let r=e.slice(2,-2).trim();return A(r,t)}return e}if(Array.isArray(e))return e.map(r=>T(r,t));if(e&&typeof e=="object"){let r={};for(let[n,o]of Object.entries(e))r[n]=T(o,t);return r}return e}async function Me(e,t){let{path:r,value:n,items:o}=t;if(!r||typeof r!="string")throw new h(t,'push action requires "path" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let i=e._get(r);if(!Array.isArray(i))throw new h(t,`Path "${r}" does not point to an array`,l.ACTION_INVALID_PARAM,{metadata:{param:"path",path:r,actualType:typeof i}});let s=o!==void 0?o:n;if(s===void 0)throw new h(t,'push action requires "value" or "items" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"value|items"}});let a=T(s,e);Array.isArray(a)?i.push(...a):i.push(a),x(r,e),x(`${r}.*`,e);}async function ke(e,t){let{path:r}=t;if(!r||typeof r!="string")throw new h(t,'pop action requires "path" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let n=e._get(r);if(!Array.isArray(n))throw new h(t,`Path "${r}" does not point to an array`,l.ACTION_INVALID_PARAM,{metadata:{param:"path",path:r,actualType:typeof n}});n.pop(),x(r,e),x(`${r}.*`,e);}async function $e(e,t){let{path:r}=t;if(!r||typeof r!="string")throw new h(t,'shift action requires "path" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let n=e._get(r);if(!Array.isArray(n))throw new h(t,`Path "${r}" does not point to an array`,l.ACTION_INVALID_PARAM,{metadata:{param:"path",path:r,actualType:typeof n}});n.shift(),x(r,e),x(`${r}.*`,e);}async function je(e,t){let{path:r,value:n,items:o}=t;if(!r||typeof r!="string")throw new h(t,'unshift action requires "path" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let i=e._get(r);if(!Array.isArray(i))throw new h(t,`Path "${r}" does not point to an array`,l.ACTION_INVALID_PARAM,{metadata:{param:"path",path:r,actualType:typeof i}});let s=o!==void 0?o:n;if(s===void 0)throw new h(t,'unshift action requires "value" or "items" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"value|items"}});let a=T(s,e);Array.isArray(a)?i.unshift(...a):i.unshift(a),x(r,e),x(`${r}.*`,e);}async function Le(e,t){let{path:r,start:n,deleteCount:o=0,items:i}=t;if(!r||typeof r!="string")throw new h(t,'splice action requires "path" parameter',l.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let s=e._get(r);if(!Array.isArray(s))throw new h(t,`Path "${r}" does not point to an array`,l.ACTION_INVALID_PARAM,{metadata:{param:"path",path:r,actualType:typeof s}});let a;if(typeof n=="string"&&n.startsWith("{{")&&n.endsWith("}}")){let y=n.slice(2,-2).trim();a=Number(A(y,e));}else a=Number(n);let u;if(typeof o=="string"&&o.startsWith("{{")&&o.endsWith("}}")){let y=o.slice(2,-2).trim();u=Number(A(y,e));}else u=Number(o);let d=[];if(i!=null){let y=T(i,e);Array.isArray(y)?d=y:d=[y];}s.splice(a,u,...d),x(r,e),x(`${r}.*`,e);}var ot={set:Ce,emit:be,navigate:Pe,log:ve,if:Ie,loop:Te,call:Oe,batch:_e,push:Me,pop:ke,shift:$e,unshift:je,splice:Le};function ee(e){for(let[t,r]of Object.entries(ot))t in e.$methods||(e.$methods[t]=r);}function De(e={},t={}){it(e);let{onEmit:r,methods:n={},onStateChange:o,createObject:i=()=>({}),createArray:s=()=>[],exprOptions:a,adapter:u}=t,d=null,y={...u?{}:e,$emit:(g,m)=>{r&&r(g,m);},$methods:n,$exprOptions:a,_get:g=>u?u.get(g):P(y,g),_set:(g,m,v)=>{u?u.set(g,m):Q(y,g,m,{createObject:i,createArray:s}),x(g,d||y),o&&!v?.skipCallback&&o(g,m,d||y);}};ee(y);let E=B(y,u);return d=E,E}function it(e){for(let t in e)if(t.startsWith("$")||t.startsWith("_"))throw new Error(`Property name "${t}" conflicts with system API. Properties starting with "$" or "_" are reserved. Use a different name.`)}function $(e,t,r="."){function n(o,i,s,a){if(!(!o||typeof o!="object"||t(o,i,s,a)===false)&&o.children){if(Array.isArray(o.children))o.children.forEach((d,y)=>{if(d&&typeof d=="object"){let E=i?`${i}${r}children${r}${y}`:`children${r}${y}`;n(d,E,s+1,o);}});else if(typeof o.children=="object"){let d=i?`${i}${r}children`:"children";n(o.children,d,s+1,o);}}}n(e,"",0,null);}function Ue(e,t={}){let r={nodeCount:0,maxDepth:0},n=new Map,o=t.buildPathMap?new Map:void 0;return $(e,(i,s,a)=>{r.nodeCount++,a>r.maxDepth&&(r.maxDepth=a);let u=i;u.id&&typeof u.id=="string"&&n.set(u.id,s),o&&o.set(s,i),t.onNode?.(i,s,a);}),{stats:r,index:{idMap:n,pathMap:o}}}function Xe(e,t){let r=[];return $(e,(n,o)=>{t(n)&&r.push({node:n,path:o});}),r}function ue(e,t){let r=null;return $(e,(n,o)=>{if(t(n))return r={node:n,path:o},false}),r}function Ve(e,t){return ue(e,n=>n.id===t)?.path||null}function We(e){let{schema:t,index:r}=e;return {findById:i=>{if(r?.idMap){let s=r.idMap.get(i);if(!s)return null;if(r.pathMap){let u=r.pathMap.get(s);return u?{node:u,path:s}:null}let a=P(t,s);return a?{node:a,path:s}:null}return null},getParent:i=>{if(!i||!i.includes("."))return null;let s=i;for(;;){let a=s.lastIndexOf(".");if(a===-1)return {node:t,path:""};s=s.substring(0,a);let u=s.split(".").pop();if(u&&["children","definitions","items"].includes(u))continue;let d=P(t,s);if(!(Array.isArray(d)||typeof d=="string")&&d&&typeof d=="object")return {node:d,path:s}}}}}export{h as ActionError,j as BatchError,l as ErrorCodes,S as ExpressionError,I as ServiceError,_ as VarioError,Ue as analyzeSchema,we as clearCache,ge as clearPathCache,me as createExpressionSandbox,H as createLoopContext,B as createProxy,We as createQueryEngine,De as createRuntimeContext,A as evaluate,K as evaluateExpression,b as execute,D as extractDependencies,Z as extractExpression,ue as findNode,Xe as findNodes,Ve as findPathById,Re as getCacheStats,Y as getCachedExpression,xe as getLastSegment,Se as getParentPath,P as getPathValue,x as invalidateCache,z as isSafePropertyAccess,V as matchPath,q as parseExpression,oe as parsePath,k as parsePathCached,ee as registerBuiltinMethods,F as releaseLoopContext,G as setCachedExpression,Q as setPathValue,ie as stringifyPath,$ as traverseSchema,J as validateAST};//# sourceMappingURL=index.js.map
|
|
9
9
|
//# sourceMappingURL=index.js.map
|