solve-engine 2.23.0 → 2.24.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/README.md +82 -32
- package/dist/{Configuration-BGQn-cJ8.d.cts → Configuration-DnzYPmoK.d.cts} +33 -0
- package/dist/{Configuration-BGQn-cJ8.d.ts → Configuration-DnzYPmoK.d.ts} +33 -0
- package/dist/{EngineError-DTk7I7hZ.d.cts → EngineError-D1kXsjIj.d.cts} +4 -0
- package/dist/{EngineError-DTk7I7hZ.d.ts → EngineError-D1kXsjIj.d.ts} +4 -0
- package/dist/{PackageCompatibility-BGXSFuL9.d.ts → PackageCompatibility-Bq82y0ZN.d.ts} +1 -1
- package/dist/{PackageCompatibility-BZCqaTOO.d.cts → PackageCompatibility-CeAPVHZr.d.cts} +1 -1
- package/dist/{PackageRegistry-rMGnTh7W.d.cts → PackageRegistry-B9-7fJGH.d.cts} +16 -11
- package/dist/{PackageRegistry-BRoVOYzg.d.ts → PackageRegistry-CDEgfhT_.d.ts} +16 -11
- package/dist/{Parselet-Bkbp9CKD.d.cts → Parselet-4oH5OuRt.d.cts} +1 -1
- package/dist/{Parselet-B-WyUtX4.d.ts → Parselet-BwDqKFfK.d.ts} +1 -1
- package/dist/{ScopeManager-gB9UengK.d.ts → ScopeManager-BQBhlDAu.d.ts} +38 -7
- package/dist/{ScopeManager-bCYewWVt.d.cts → ScopeManager-DrXB3Nvm.d.cts} +38 -7
- package/dist/{VMCheckpoints-DGar9Yg8.d.cts → VMCheckpoints-BK32PTl2.d.cts} +2 -2
- package/dist/{VMCheckpoints-BDRY1Kx8.d.ts → VMCheckpoints-C5jC92o3.d.ts} +2 -2
- package/dist/{Value-DCTqTSeP.d.cts → Value-Ds3Gy07C.d.cts} +1 -1
- package/dist/{Value-DCTqTSeP.d.ts → Value-Ds3Gy07C.d.ts} +1 -1
- package/dist/{WorkerError-DpZgKRks.d.ts → WorkerError-CVQbs6_D.d.ts} +1 -1
- package/dist/{WorkerError-DGBNM3gA.d.cts → WorkerError-DaNWQFp1.d.cts} +1 -1
- package/dist/chunk-2BXNZM3G.js +2 -0
- package/dist/chunk-2BXNZM3G.js.map +1 -0
- package/dist/chunk-2JSNWYYA.cjs +3 -0
- package/dist/chunk-2JSNWYYA.cjs.map +1 -0
- package/dist/{chunk-J7ABVGZH.cjs → chunk-2VE4OW4A.cjs} +2 -2
- package/dist/{chunk-J7ABVGZH.cjs.map → chunk-2VE4OW4A.cjs.map} +1 -1
- package/dist/{chunk-HMC7FJO7.js → chunk-3SHWTGTP.js} +2 -2
- package/dist/{chunk-HMC7FJO7.js.map → chunk-3SHWTGTP.js.map} +1 -1
- package/dist/{chunk-EN3CDYOS.cjs → chunk-5GL4SAVH.cjs} +2 -2
- package/dist/{chunk-EN3CDYOS.cjs.map → chunk-5GL4SAVH.cjs.map} +1 -1
- package/dist/{chunk-SGIDBZ4T.cjs → chunk-72N3ZRVE.cjs} +2 -2
- package/dist/chunk-72N3ZRVE.cjs.map +1 -0
- package/dist/{chunk-CHSO3DCS.js → chunk-7EP36NXE.js} +3 -3
- package/dist/{chunk-CHSO3DCS.js.map → chunk-7EP36NXE.js.map} +1 -1
- package/dist/chunk-A4JV7HRB.js +3 -0
- package/dist/chunk-A4JV7HRB.js.map +1 -0
- package/dist/chunk-AUOE7MFI.cjs +2 -0
- package/dist/chunk-AUOE7MFI.cjs.map +1 -0
- package/dist/chunk-BDF4VCQX.js +3 -0
- package/dist/chunk-BDF4VCQX.js.map +1 -0
- package/dist/{chunk-3SSMOVWB.cjs → chunk-CDNJZBM3.cjs} +2 -2
- package/dist/{chunk-3SSMOVWB.cjs.map → chunk-CDNJZBM3.cjs.map} +1 -1
- package/dist/{chunk-YAONCEAW.cjs → chunk-CMZSK6FY.cjs} +3 -3
- package/dist/{chunk-YAONCEAW.cjs.map → chunk-CMZSK6FY.cjs.map} +1 -1
- package/dist/chunk-D2Q2VFJ6.js +2 -0
- package/dist/chunk-D2Q2VFJ6.js.map +1 -0
- package/dist/{chunk-75JLWK4L.cjs → chunk-DA7M6H63.cjs} +2 -2
- package/dist/{chunk-75JLWK4L.cjs.map → chunk-DA7M6H63.cjs.map} +1 -1
- package/dist/chunk-ELQQKZN3.cjs +3 -0
- package/dist/{chunk-PIZQIQVM.js.map → chunk-ELQQKZN3.cjs.map} +1 -1
- package/dist/chunk-F7QIBC4B.cjs +3 -0
- package/dist/chunk-F7QIBC4B.cjs.map +1 -0
- package/dist/chunk-GP4H5OIT.js +3 -0
- package/dist/chunk-GP4H5OIT.js.map +1 -0
- package/dist/chunk-HQ7BKXG7.js +2 -0
- package/dist/chunk-HQ7BKXG7.js.map +1 -0
- package/dist/{chunk-KRXO3MOW.cjs → chunk-IHAZL4EF.cjs} +2 -2
- package/dist/chunk-IHAZL4EF.cjs.map +1 -0
- package/dist/{chunk-7E7NXKQ5.js → chunk-IJHL3LMH.js} +2 -2
- package/dist/chunk-IJHL3LMH.js.map +1 -0
- package/dist/{chunk-3GR46UOX.js → chunk-IPSOWFCA.js} +2 -2
- package/dist/{chunk-3GR46UOX.js.map → chunk-IPSOWFCA.js.map} +1 -1
- package/dist/chunk-LM6ZQUEU.js +2 -0
- package/dist/chunk-LM6ZQUEU.js.map +1 -0
- package/dist/{chunk-N37PUZJR.cjs → chunk-LTJV3VJE.cjs} +2 -2
- package/dist/{chunk-N37PUZJR.cjs.map → chunk-LTJV3VJE.cjs.map} +1 -1
- package/dist/chunk-MWWAKZOD.cjs +3 -0
- package/dist/chunk-MWWAKZOD.cjs.map +1 -0
- package/dist/chunk-NUF66H57.js +5 -0
- package/dist/chunk-NUF66H57.js.map +1 -0
- package/dist/{chunk-MRRMIBHE.js → chunk-OMHRBKAT.js} +2 -2
- package/dist/{chunk-MRRMIBHE.js.map → chunk-OMHRBKAT.js.map} +1 -1
- package/dist/{chunk-4ETS224G.js → chunk-PTQCHMYA.js} +2 -2
- package/dist/{chunk-4ETS224G.js.map → chunk-PTQCHMYA.js.map} +1 -1
- package/dist/{chunk-4DJJIUQF.js → chunk-PWWQZFAE.js} +2 -2
- package/dist/chunk-PWWQZFAE.js.map +1 -0
- package/dist/chunk-RE6AIU6Y.js +3 -0
- package/dist/chunk-RE6AIU6Y.js.map +1 -0
- package/dist/chunk-RECRD45C.cjs +5 -0
- package/dist/chunk-RECRD45C.cjs.map +1 -0
- package/dist/{chunk-O3BDXOQJ.js → chunk-RENO2AWO.js} +2 -2
- package/dist/{chunk-O3BDXOQJ.js.map → chunk-RENO2AWO.js.map} +1 -1
- package/dist/chunk-RMCN5WFO.cjs +2 -0
- package/dist/chunk-RMCN5WFO.cjs.map +1 -0
- package/dist/{chunk-TL545PXW.cjs → chunk-RN3ISTM3.cjs} +2 -2
- package/dist/{chunk-TL545PXW.cjs.map → chunk-RN3ISTM3.cjs.map} +1 -1
- package/dist/{chunk-JYLNQOPU.cjs → chunk-S46R5QZP.cjs} +2 -2
- package/dist/{chunk-JYLNQOPU.cjs.map → chunk-S46R5QZP.cjs.map} +1 -1
- package/dist/{chunk-USQ4KL6S.cjs → chunk-UPH22K2T.cjs} +2 -2
- package/dist/chunk-UPH22K2T.cjs.map +1 -0
- package/dist/{chunk-KEA5HRL3.js → chunk-UXR7JIPX.js} +2 -2
- package/dist/{chunk-KEA5HRL3.js.map → chunk-UXR7JIPX.js.map} +1 -1
- package/dist/chunk-UY3ID6JF.cjs +2 -0
- package/dist/chunk-UY3ID6JF.cjs.map +1 -0
- package/dist/{chunk-JVMINMAB.js → chunk-WFOQRPA6.js} +2 -2
- package/dist/{chunk-JVMINMAB.js.map → chunk-WFOQRPA6.js.map} +1 -1
- package/dist/{chunk-AF7HQN6I.js → chunk-XFJABR3B.js} +2 -2
- package/dist/chunk-XFJABR3B.js.map +1 -0
- package/dist/{chunk-LNZNJSRW.cjs → chunk-ZVPZQ66D.cjs} +2 -2
- package/dist/chunk-ZVPZQ66D.cjs.map +1 -0
- package/dist/constants.cjs +1 -1
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/engine.cjs +1 -1
- package/dist/engine.d.cts +9 -9
- package/dist/engine.d.ts +9 -9
- package/dist/engine.js +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.d.cts +3 -3
- package/dist/errors.d.ts +3 -3
- package/dist/errors.js +1 -1
- package/dist/format.cjs +1 -1
- package/dist/format.d.cts +1 -1
- package/dist/format.d.ts +1 -1
- package/dist/format.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -9
- package/dist/index.d.ts +11 -9
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/language.d.cts +8 -8
- package/dist/language.d.ts +8 -8
- package/dist/lexer.cjs +1 -1
- package/dist/lexer.js +1 -1
- package/dist/normalizer.cjs +1 -1
- package/dist/normalizer.d.cts +14 -8
- package/dist/normalizer.d.ts +14 -8
- package/dist/normalizer.js +1 -1
- package/dist/packages.cjs +1 -1
- package/dist/packages.d.cts +7 -7
- package/dist/packages.d.ts +7 -7
- package/dist/packages.js +1 -1
- package/dist/parser.cjs +1 -1
- package/dist/parser.d.cts +3 -3
- package/dist/parser.d.ts +3 -3
- package/dist/parser.js +1 -1
- package/dist/{pipeline-B4wf3M1h.d.cts → pipeline-69q2tsLE.d.cts} +1 -1
- package/dist/{pipeline-QIT4iD8f.d.ts → pipeline-DTqGLPsV.d.ts} +1 -1
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.d.cts +18 -2
- package/dist/resolvers.d.ts +18 -2
- package/dist/resolvers.js +1 -1
- package/dist/testing.cjs +2 -2
- package/dist/testing.d.cts +8 -8
- package/dist/testing.d.ts +8 -8
- package/dist/testing.js +1 -1
- package/dist/uom.cjs +1 -1
- package/dist/uom.d.cts +1 -1
- package/dist/uom.d.ts +1 -1
- package/dist/uom.js +1 -1
- package/dist/vm.cjs +1 -1
- package/dist/vm.d.cts +7 -7
- package/dist/vm.d.ts +7 -7
- package/dist/vm.js +1 -1
- package/dist/worker.cjs +2 -2
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +31 -22
- package/dist/worker.d.ts +31 -22
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-42JXN3BH.js +0 -5
- package/dist/chunk-42JXN3BH.js.map +0 -1
- package/dist/chunk-4DJJIUQF.js.map +0 -1
- package/dist/chunk-6YM67DWH.cjs +0 -3
- package/dist/chunk-6YM67DWH.cjs.map +0 -1
- package/dist/chunk-7E7NXKQ5.js.map +0 -1
- package/dist/chunk-7SZBEE5R.cjs +0 -2
- package/dist/chunk-7SZBEE5R.cjs.map +0 -1
- package/dist/chunk-A5M4QZIK.js +0 -2
- package/dist/chunk-A5M4QZIK.js.map +0 -1
- package/dist/chunk-AF7HQN6I.js.map +0 -1
- package/dist/chunk-ALY4ZMYO.js +0 -2
- package/dist/chunk-ALY4ZMYO.js.map +0 -1
- package/dist/chunk-BRJ4RT5U.js +0 -2
- package/dist/chunk-BRJ4RT5U.js.map +0 -1
- package/dist/chunk-CO2BI6WL.cjs +0 -3
- package/dist/chunk-CO2BI6WL.cjs.map +0 -1
- package/dist/chunk-EQDT42JG.js +0 -3
- package/dist/chunk-EQDT42JG.js.map +0 -1
- package/dist/chunk-FMMT5C5H.cjs +0 -3
- package/dist/chunk-FMMT5C5H.cjs.map +0 -1
- package/dist/chunk-FP6Z6PYR.js +0 -2
- package/dist/chunk-FP6Z6PYR.js.map +0 -1
- package/dist/chunk-H3JXNH7X.cjs +0 -3
- package/dist/chunk-H3JXNH7X.cjs.map +0 -1
- package/dist/chunk-HZOLIL5T.js +0 -3
- package/dist/chunk-HZOLIL5T.js.map +0 -1
- package/dist/chunk-KRXO3MOW.cjs.map +0 -1
- package/dist/chunk-KVLJDOZ7.cjs +0 -5
- package/dist/chunk-KVLJDOZ7.cjs.map +0 -1
- package/dist/chunk-LNZNJSRW.cjs.map +0 -1
- package/dist/chunk-PIZQIQVM.js +0 -3
- package/dist/chunk-QTSDIDAS.js +0 -3
- package/dist/chunk-QTSDIDAS.js.map +0 -1
- package/dist/chunk-SGIDBZ4T.cjs.map +0 -1
- package/dist/chunk-UNKSCVIL.cjs +0 -2
- package/dist/chunk-UNKSCVIL.cjs.map +0 -1
- package/dist/chunk-USQ4KL6S.cjs.map +0 -1
- package/dist/chunk-XDXIPVZB.cjs +0 -2
- package/dist/chunk-XDXIPVZB.cjs.map +0 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var i=(N=>(N.PARSING="PARSING",N.EXECUTION="EXECUTION",N.VALIDATION="VALIDATION",N.EXTERNAL="EXTERNAL",N.INTERNAL="INTERNAL",N.CONFIG="CONFIG",N))(i||{}),t=class t extends Error{constructor(r,_){let e=_.recoverable??true,n=e&&!t.captureRecoverableStacks,I=Error,N=I.stackTraceLimit;n&&(I.stackTraceLimit=0),super(_.message),n&&(I.stackTraceLimit=N),this.name="EngineError",this.category=r,this.code=_.code,this.expected=_.expected,this.found=_.found,this.suggestion=_.suggestion,this.recoverable=e,this.span=_.span,this.context=_.context,this.cause=_.cause,this.timestamp=new Date,!n&&Error.captureStackTrace&&Error.captureStackTrace(this,t);}isFatal(){return !this.recoverable}causeChain(){let r=[this],_=this.cause;for(;_!=null;)r.push(_),_=_ instanceof Error?_.cause:void 0;return r}format(){let r=[`error[${this.code}]: ${this.message}`];return this.expected&&r.push(` expected: ${this.expected}`),this.found&&r.push(` found: ${this.found}`),this.suggestion&&r.push(` suggestion: ${this.suggestion}`),r.join(`
|
|
2
|
+
`)}toJSON(){return {name:this.name,category:this.category,code:this.code,message:this.message,expected:this.expected,found:this.found,suggestion:this.suggestion,recoverable:this.recoverable,span:this.span,context:this.context,timestamp:this.timestamp.toISOString()}}};t.captureRecoverableStacks=false;var O=t,T=class E{static build(r,_,e,n,I){let N=typeof e=="string"?{code:e,message:n,context:I}:e;return new O(r,{recoverable:_,...N})}static validation(r,_,e){return E.build("VALIDATION",true,r,_,e)}static parsing(r,_,e){return E.build("PARSING",true,r,_,e)}static execution(r,_,e){return E.build("EXECUTION",true,r,_,e)}static external(r,_,e){return E.build("EXTERNAL",true,r,_,e)}static internal(r,_,e){return E.build("INTERNAL",true,r,_,e)}static config(r,_,e){return E.build("CONFIG",false,r,_,e)}};function R(E){return E instanceof O?E:E instanceof Error?T.internal({code:"UNEXPECTED_ERROR",message:E.message,context:{originalErrorName:E.name},cause:E,recoverable:true}):T.internal({code:"UNKNOWN_ERROR",message:"An unknown error occurred",context:{error:String(E)},recoverable:true})}function o(E){return {ok:true,value:E}}function A(E){return {ok:false,error:E}}function s(E){return E.ok}function S(E){return !E.ok}function C(E,r){return E.ok?o(r(E.value)):E}function D(E,r){return E.ok?E:A(r(E.error))}function L(E,r){return E.ok?r(E.value):E}function a(E,r){return E.ok?E.value:r}function U(E,r){return E.ok?r.ok(E.value):r.err(E.error)}function u(E){let r=[];for(let _ of E){if(!_.ok)return _;r.push(_.value);}return o(r)}function c(E){if(E.ok)return E.value;throw E.error}function P(E,r=R){try{return o(E())}catch(_){return A(r(_))}}async function M(E,r=R){try{return o(await E())}catch(_){return A(r(_))}}var g={INVALID_NUMBER_LITERAL:"INVALID_NUMBER_LITERAL",UNTERMINATED_STRING:"UNTERMINATED_STRING",NO_PREFIX_PARSELET:"NO_PREFIX_PARSELET",UNEXPECTED_END_OF_INPUT:"UNEXPECTED_END_OF_INPUT",UNEXPECTED_TOKEN_TYPE:"UNEXPECTED_TOKEN_TYPE",NESTING_DEPTH_EXCEEDED:"NESTING_DEPTH_EXCEEDED",UNEXPECTED_END:"UNEXPECTED_END",UNEXPECTED_TRAILING_TOKEN:"UNEXPECTED_TRAILING_TOKEN",PARSE_ERROR:"PARSE_ERROR",TOO_MANY_NUMERIC_CONSTANTS:"TOO_MANY_NUMERIC_CONSTANTS",TOO_MANY_STRING_CONSTANTS:"TOO_MANY_STRING_CONSTANTS",NO_MATCHING_PHRASE_ALTERNATIVE:"NO_MATCHING_PHRASE_ALTERNATIVE",INVALID_PHRASE_PATTERN:"INVALID_PHRASE_PATTERN",PHRASE_KEYWORD_MISMATCH:"PHRASE_KEYWORD_MISMATCH",USER_FUNCTION_INVALID_PARAM_NAME:"USER_FUNCTION_INVALID_PARAM_NAME",USER_FUNCTION_NO_PARAMS:"USER_FUNCTION_NO_PARAMS",FUNCTION_BODY_MUST_BE_SYNCHRONOUS:"FUNCTION_BODY_MUST_BE_SYNCHRONOUS",TOO_MANY_FUNCTION_DEFINITIONS:"TOO_MANY_FUNCTION_DEFINITIONS",TOO_MANY_ANONYMOUS_BODIES:"TOO_MANY_ANONYMOUS_BODIES",UNKNOWN_PLUGIN_FUNCTION:"UNKNOWN_PLUGIN_FUNCTION",EVALUATION_ERROR:"EVALUATION_ERROR",INSTRUCTION_LIMIT_EXCEEDED:"INSTRUCTION_LIMIT_EXCEEDED",STACK_LIMIT_EXCEEDED:"STACK_LIMIT_EXCEEDED",ALLOCATION_LIMIT_EXCEEDED:"ALLOCATION_LIMIT_EXCEEDED",STACK_UNDERFLOW:"STACK_UNDERFLOW",UNDEFINED_VARIABLE:"UNDEFINED_VARIABLE",GLOBAL_VARIABLE_NOT_RESOLVED:"GLOBAL_VARIABLE_NOT_RESOLVED",UNKNOWN_FUNCTION:"UNKNOWN_FUNCTION",UNEXPECTED_PENDING_RESULT:"UNEXPECTED_PENDING_RESULT",UNDEFINED_FUNCTION:"UNDEFINED_FUNCTION",FUNCTION_ARITY_MISMATCH:"FUNCTION_ARITY_MISMATCH",BUILTIN_ARITY_MISMATCH:"BUILTIN_ARITY_MISMATCH",USER_FUNCTION_ASYNC_UNSUPPORTED:"USER_FUNCTION_ASYNC_UNSUPPORTED",MAP_REDUCE_ASYNC_UNSUPPORTED:"MAP_REDUCE_ASYNC_UNSUPPORTED",SYMBOLIC_ASYNC_UNSUPPORTED:"SYMBOLIC_ASYNC_UNSUPPORTED",EXPLAIN_ASYNC_UNSUPPORTED:"EXPLAIN_ASYNC_UNSUPPORTED",FUNCTION_RECURSION_LIMIT_EXCEEDED:"FUNCTION_RECURSION_LIMIT_EXCEEDED",FUNCTION_CALL_LIMIT_EXCEEDED:"FUNCTION_CALL_LIMIT_EXCEEDED",DATE_OFFSET_LIMIT_EXCEEDED:"DATE_OFFSET_LIMIT_EXCEEDED",WORKDAY_OFFSET_EXPECTED_DATE:"WORKDAY_OFFSET_EXPECTED_DATE",WORKDAYS_BETWEEN_EXPECTED_DATES:"WORKDAYS_BETWEEN_EXPECTED_DATES",WORKDAYS_BETWEEN_RANGE_TOO_LARGE:"WORKDAYS_BETWEEN_RANGE_TOO_LARGE",BIGINT_SHIFT_LIMIT_EXCEEDED:"BIGINT_SHIFT_LIMIT_EXCEEDED",BIGINT_POW_LIMIT_EXCEEDED:"BIGINT_POW_LIMIT_EXCEEDED",BIGINT_INEXACT_OPERAND:"BIGINT_INEXACT_OPERAND",BIGINT_DIVISION_BY_ZERO:"BIGINT_DIVISION_BY_ZERO",INTERNAL_MISSING_FUNCTION_BODY:"INTERNAL_MISSING_FUNCTION_BODY",INTERNAL_MISSING_ANONYMOUS_BODY:"INTERNAL_MISSING_ANONYMOUS_BODY",UNKNOWN_BUILTIN_FUNCTION:"UNKNOWN_BUILTIN_FUNCTION",MALFORMED_BYTECODE_TRUNCATED:"MALFORMED_BYTECODE_TRUNCATED",MALFORMED_BYTECODE_CONSTANT_INDEX:"MALFORMED_BYTECODE_CONSTANT_INDEX",MALFORMED_BYTECODE_OPERAND_TYPE:"MALFORMED_BYTECODE_OPERAND_TYPE",MALFORMED_BYTECODE_BODY_KIND:"MALFORMED_BYTECODE_BODY_KIND",MALFORMED_BYTECODE_BIGINT_LITERAL:"MALFORMED_BYTECODE_BIGINT_LITERAL",MALFORMED_BYTECODE_PROGRAM:"MALFORMED_BYTECODE_PROGRAM",SYMBOLIC_RATIONAL_OVERFLOW:"SYMBOLIC_RATIONAL_OVERFLOW",SYMBOLIC_NONFINITE_OPERAND:"SYMBOLIC_NONFINITE_OPERAND",SYMBOLIC_DIVISION_BY_ZERO:"SYMBOLIC_DIVISION_BY_ZERO",SYMBOLIC_NODE_LIMIT_EXCEEDED:"SYMBOLIC_NODE_LIMIT_EXCEEDED",SYMBOLIC_UNSUPPORTED_FUNCTION:"SYMBOLIC_UNSUPPORTED_FUNCTION",SYMBOLIC_FACTOR_LIMIT_EXCEEDED:"SYMBOLIC_FACTOR_LIMIT_EXCEEDED",SYMBOLIC_SOLVE_UNSUPPORTED:"SYMBOLIC_SOLVE_UNSUPPORTED",SYMBOLIC_SOLVE_INCOMPLETE:"SYMBOLIC_SOLVE_INCOMPLETE",SOLVE_REQUIRES_VARIABLE_NAME:"SOLVE_REQUIRES_VARIABLE_NAME",SYMBOLIC_DERIVATIVE_ORDER_LIMIT:"SYMBOLIC_DERIVATIVE_ORDER_LIMIT",SYMBOLIC_INTEGRAL_UNSUPPORTED:"SYMBOLIC_INTEGRAL_UNSUPPORTED",SYMBOLIC_TAYLOR_DEGREE_LIMIT:"SYMBOLIC_TAYLOR_DEGREE_LIMIT",SYMBOLIC_TAYLOR_INEXACT:"SYMBOLIC_TAYLOR_INEXACT",SYMBOLIC_REQUIRES_VARIABLE_NAME:"SYMBOLIC_REQUIRES_VARIABLE_NAME",SYMBOLIC_JACOBIAN_NO_VARIABLES:"SYMBOLIC_JACOBIAN_NO_VARIABLES",INTERNAL_RATIONAL_PARSE:"INTERNAL_RATIONAL_PARSE",EXPRESSION_TOO_LONG:"EXPRESSION_TOO_LONG",EXPRESSION_TOO_COMPLEX:"EXPRESSION_TOO_COMPLEX",DOCUMENT_TOO_LARGE:"DOCUMENT_TOO_LARGE",NORMALIZED_TOKEN_LIMIT_EXCEEDED:"NORMALIZED_TOKEN_LIMIT_EXCEEDED",THEREFORE_REQUIRES_EXPRESSION:"THEREFORE_REQUIRES_EXPRESSION",THEREFORE_ASYNC_UNSUPPORTED:"THEREFORE_ASYNC_UNSUPPORTED",COMPOUND_ASSIGN_REQUIRES_EXPRESSION:"COMPOUND_ASSIGN_REQUIRES_EXPRESSION",COMPOUND_ASSIGN_ASYNC_UNSUPPORTED:"COMPOUND_ASSIGN_ASYNC_UNSUPPORTED",UNKNOWN_SAVINGS_PERIOD:"UNKNOWN_SAVINGS_PERIOD",INVALID_TIME_LITERAL:"INVALID_TIME_LITERAL",NETWORK_DISABLED:"NETWORK_DISABLED",SNAPSHOT_VERSION_MISMATCH:"SNAPSHOT_VERSION_MISMATCH",SNAPSHOT_MALFORMED:"SNAPSHOT_MALFORMED",SNAPSHOT_UNSUPPORTED_VALUE:"SNAPSHOT_UNSUPPORTED_VALUE",CONFIG_PATH_NOT_FOUND:"CONFIG_PATH_NOT_FOUND",INVALID_CONFIG_PATH:"INVALID_CONFIG_PATH",CONFIG_SECTION_NOT_FOUND:"CONFIG_SECTION_NOT_FOUND",CONFIG_PROPERTY_NOT_FOUND:"CONFIG_PROPERTY_NOT_FOUND",PLUGIN_OPERATOR_COLLISION:"PLUGIN_OPERATOR_COLLISION",PLUGIN_KEYWORD_COLLISION:"PLUGIN_KEYWORD_COLLISION",PLUGIN_UNIT_COLLISION:"PLUGIN_UNIT_COLLISION",PACKAGE_ENGINE_VERSION_MISMATCH:"PACKAGE_ENGINE_VERSION_MISMATCH",PACKAGE_ENGINE_VERSION_INVALID_RANGE:"PACKAGE_ENGINE_VERSION_INVALID_RANGE",OPCODE_POOL_EXHAUSTED:"OPCODE_POOL_EXHAUSTED",PLUGIN_FUNCTION_INDEX_POOL_EXHAUSTED:"PLUGIN_FUNCTION_INDEX_POOL_EXHAUSTED",PLUGIN_FUNCTION_INDEX_TOO_LARGE:"PLUGIN_FUNCTION_INDEX_TOO_LARGE",INVALID_RATE_UNIT:"INVALID_RATE_UNIT",INVALID_TIMECODE_UNIT:"INVALID_TIMECODE_UNIT",UNEXPECTED_ERROR:"UNEXPECTED_ERROR",UNKNOWN_ERROR:"UNKNOWN_ERROR"};export{i as a,O as b,T as c,R as d,o as e,A as f,s as g,S as h,C as i,D as j,L as k,a as l,U as m,u as n,c as o,P as p,M as q,g as r};//# sourceMappingURL=chunk-BDF4VCQX.js.map
|
|
3
|
+
//# sourceMappingURL=chunk-BDF4VCQX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors/EngineError.ts","../src/errors/Result.ts","../src/errors/ErrorCode.ts"],"names":["ErrorCategory","_EngineError","category","init","recoverable","skipStack","errorCtor","previousLimit","chain","current","lines","EngineError","ErrorFactory","_ErrorFactory","defaultRecoverable","codeOrInit","message","context","normalizeUnknownError","error","ok","value","err","isOk","r","isErr","map","fn","mapErr","andThen","unwrapOr","fallback","match","arms","combine","results","values","throwIfErr","tryCatch","normalize","e","tryCatchAsync","CoreErrorCodes"],"mappings":"AA6BO,IAAKA,OAEVA,CAAAA,CAAA,OAAA,CAAU,UAEVA,CAAAA,CAAA,SAAA,CAAY,YAEZA,CAAAA,CAAA,UAAA,CAAa,aAEbA,CAAAA,CAAA,QAAA,CAAW,WAEXA,CAAAA,CAAA,QAAA,CAAW,WAEXA,CAAAA,CAAA,MAAA,CAAS,SAZCA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA,CAAA,CAmECC,CAAAA,CAAN,MAAMA,UAAoB,KAAM,CA+CrC,YAAYC,CAAAA,CAAyBC,CAAAA,CAAuB,CAK1D,IAAMC,CAAAA,CAAcD,EAAK,WAAA,EAAe,IAAA,CAClCE,EAAYD,CAAAA,EAAe,CAACH,EAAY,wBAAA,CAMxCK,CAAAA,CAAY,MACZC,CAAAA,CAAgBD,CAAAA,CAAU,eAAA,CAC5BD,CAAAA,GAAWC,EAAU,eAAA,CAAkB,CAAA,CAAA,CAC3C,MAAMH,CAAAA,CAAK,OAAO,EACdE,CAAAA,GAAWC,CAAAA,CAAU,gBAAkBC,CAAAA,CAAAA,CAE3C,IAAA,CAAK,KAAO,aAAA,CACZ,IAAA,CAAK,SAAWL,CAAAA,CAChB,IAAA,CAAK,KAAOC,CAAAA,CAAK,IAAA,CACjB,KAAK,QAAA,CAAWA,CAAAA,CAAK,S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,qCAAA,CAErC,kCAAmC,mCAAA,CAEnC,sBAAA,CAAwB,yBAExB,oBAAA,CAAsB,sBAAA,CAEtB,gBAAA,CAAkB,kBAAA,CAIlB,0BAA2B,2BAAA,CAE3B,kBAAA,CAAoB,oBAAA,CAEpB,0BAAA,CAA4B,6BAG5B,qBAAA,CAAuB,uBAAA,CACvB,mBAAA,CAAqB,qBAAA,CACrB,yBAA0B,0BAAA,CAC1B,yBAAA,CAA2B,2BAAA,CAG3B,yBAAA,CAA2B,4BAC3B,wBAAA,CAA0B,0BAAA,CAC1B,qBAAA,CAAuB,uBAAA,CAEvB,gCAAiC,iCAAA,CAEjC,oCAAA,CAAsC,sCAAA,CAEtC,qBAAA,CAAuB,wBAEvB,oCAAA,CAAsC,sCAAA,CAEtC,+BAAA,CAAiC,iCAAA,CAGjC,kBAAmB,mBAAA,CACnB,qBAAA,CAAuB,wBAGvB,gBAAA,CAAkB,kBAAA,CAClB,cAAe,eACjB","file":"chunk-BDF4VCQX.js","sourcesContent":["/**\n * The engine's structured error type, the \"Rust/Go-style, verbose, easy to\n * tell the issue\" half of the error-handling redesign (the other half is\n * `Result.ts`).\n *\n * Historical note: an earlier version of this class (`UnifiedErrorFramework.ts`,\n * still the import path most of the codebase uses. See that file, now a\n * pure re-export barrel) had a much larger field set (`severity`,\n * `recovery`, a 5-value enum, `ErrorRecoveryManager`) that was almost\n * entirely dead: nothing downstream ever read `.severity`/`.recovery`,\n * only `.message` reliably survived to a caller. This version is smaller\n * and deliberately keeps only fields something actually consumes.\n */\n\nimport type { ErrorCode } from \"@solve-js/errors/ErrorCode\";\n\n/** A character-offset (and optional line/col) span into the original expression text, for a future \"underline the offending token\" UI, not yet wired to one. */\nexport interface SourceSpan {\n start: number;\n end: number;\n line?: number;\n col?: number;\n}\n\n/**\n * Error classification, kept from the original framework, now actually\n * consulted: it's the `format()` header and lets host code group errors\n * by pipeline stage without string-matching `.code`.\n */\nexport enum ErrorCategory {\n /** Errors during expression parsing. */\n PARSING = \"PARSING\",\n /** Errors during bytecode execution. */\n EXECUTION = \"EXECUTION\",\n /** Errors from input validation (safety limits, config). */\n VALIDATION = \"VALIDATION\",\n /** Errors from external services/APIs (currency rates, weather, stocks). */\n EXTERNAL = \"EXTERNAL\",\n /** Internal engine invariant violations. See `recoverable`'s doc comment. */\n INTERNAL = \"INTERNAL\",\n /** Configuration errors. */\n CONFIG = \"CONFIG\",\n}\n\n/** Fields accepted when constructing an {@link EngineError}. */\nexport interface EngineErrorInit {\n /** Catalog code. See `errors/ErrorCode.ts`. Not a free string: every code used by a BUILT-IN package should be registered there so `ErrorCodeCatalog.spec.ts` can catch collisions/typos. Third-party packages may still use any string here, `EngineError.code`'s runtime type is `string`. */\n code: ErrorCode | (string & {});\n /** Short, single-line, `Error.message`-compatible. Existing `.toThrow(/pattern/)`/`.message` assertions keep working against this field, richer detail goes in `expected`/`found`/`suggestion`, not crammed into this string. */\n message: string;\n /** What the parser/validator/VM expected to see, in plain words, e.g. \"a city name\", \"a 4-digit year\", \"end of expression\". */\n expected?: string;\n /** What was actually found instead, e.g. \"end of expression\", `NUMBER \"5\"`, the offending token's literal text. */\n found?: string;\n /** An actionable, worked-example fix, e.g. `e.g. \"weather in London\"`. Mirrors this codebase's best existing messages (`WEATHER_EXPECTED_CITY`, `AS_CONVERTER_EXPECTED_NAME`). */\n suggestion?: string;\n /**\n * Whether this engine instance is still usable. `true` for everything that\n * went wrong on ONE line, whether the line's fault (bad syntax, an unknown\n * variable, a safety limit exceeded), the environment's (an external API\n * down), or the engine's own (corrupted bytecode, a stack underflow from a\n * buggy plugin). `false` is for the far rarer case where there is no working\n * engine to go on with: a configuration or package-registration failure,\n * which is what `ErrorFactory.config()` is for and the only factory method\n * that still defaults to it.\n *\n * The category answers a different question, and the two used to be answered\n * as one. Category INTERNAL says whose fault this is, the engine's, worth\n * reporting as a bug. `recoverable` says whether the host may carry on, and\n * after an internal slip on one line it may:\n * `__tests__/hardening/RobustnessEngineLifecycle.spec.ts` alternates a\n * throwing line with a good one five hundred times and every answer stays\n * correct. Reporting that as `isFatal()` told a host the opposite, and a host\n * that honours the name would tear a document down over one bad line.\n *\n * This has never gated \"does evaluation of the rest of the document\n * continue\"; with this engine's per-line containment it always does, even for\n * a `recoverable: false` error (see `ARCHITECTURE.md`'s async-batcher/Tier-2\n * hardening notes). It gates what a host is TOLD. See\n * {@link EngineError.isFatal}.\n */\n recoverable?: boolean;\n /** Character-offset span into the source expression, when available. Not yet threaded through every call site, populate opportunistically, don't block on retrofitting every existing throw site. */\n span?: SourceSpan;\n /** Free-form structured context. The one field the pre-existing framework's real consumer (`ThreeTierEvaluator.ts`'s DAG-preservation-on-compile-error path) actually reads, kept name- and shape-compatible on purpose. */\n context?: Record<string, unknown>;\n /** The underlying error this one wraps, if any, passed straight through to native `Error.cause` (ES2022), so Node's default printer, most loggers, and `instanceof Error` tooling understand the chain for free. */\n cause?: unknown;\n}\n\n/**\n * The engine's structured error type. Still a real `Error` subclass (so\n * `throw`/`catch`/`instanceof Error` all keep working exactly as before),\n * but now every field except the removed `severity`/`recovery` pair is\n * something real code reads.\n */\nexport class EngineError extends Error {\n readonly category: ErrorCategory;\n readonly code: string;\n readonly expected?: string;\n readonly found?: string;\n readonly suggestion?: string;\n readonly recoverable: boolean;\n readonly span?: SourceSpan;\n readonly context?: Record<string, unknown>;\n readonly timestamp: Date;\n /**\n * Set explicitly (not via `super(message, {cause})`). This repo's\n * `tsconfig.json` targets ES6/ES5-ES7 lib, which predates TypeScript's\n * ES2022 `Error` constructor `cause`-option overload. `Error.prototype.cause`\n * is still a real runtime feature in every target this engine actually\n * runs in (Node 16.9+, all evergreen browsers, Electron/Obsidian's\n * bundled Chromium) regardless of the TS lib target used to type-check\n * against it, assigning it directly gets the same Node-printer/logger\n * interop with no build-config change needed.\n */\n readonly cause?: unknown;\n\n /**\n * Whether a recoverable error captures a JavaScript stack trace.\n *\n * Off, because a recoverable EngineError is a value rather than a fault. A\n * line of prose in a notepad is not an expression, so parsing it fails, and\n * that failure is the answer for that line rather than a bug to debug. The\n * engine builds one such error per non-expression line.\n *\n * Capturing a stack is not cheap, and its cost grows with how deep the stack\n * is when it happens. Measured through `parseDocument`, where the throw site\n * sits about a dozen frames down, each capture cost around 62 microseconds\n * and a 250-line document built 74 of them: a CPU profile put the\n * constructor at 46% of the whole pipeline, more than lexing, normalising,\n * parsing and executing put together.\n *\n * Turn it on to debug where a recoverable error is raised from. Errors that\n * are NOT recoverable always capture, since those are the genuine faults.\n *\n * @example\n * ```ts\n * EngineError.captureRecoverableStacks = true;\n * ```\n */\n static captureRecoverableStacks = false;\n\n constructor(category: ErrorCategory, init: EngineErrorInit) {\n // Before super(), which is legal as long as `this` is untouched. V8 reads\n // `Error.stackTraceLimit` while constructing the Error, so zeroing it\n // across the super() call is what actually skips the capture; there is no\n // per-instance switch for it.\n const recoverable = init.recoverable ?? true;\n const skipStack = recoverable && !EngineError.captureRecoverableStacks;\n // `stackTraceLimit` is a V8 extension, present in Node and every\n // Chromium-based browser but absent from the DOM lib, so it is reached\n // through a narrow local view rather than by widening the global type.\n // Where it does not exist, reading and writing it are both harmless and\n // the stack is captured as before.\n const errorCtor = Error as unknown as { stackTraceLimit?: number };\n const previousLimit = errorCtor.stackTraceLimit;\n if (skipStack) errorCtor.stackTraceLimit = 0;\n super(init.message);\n if (skipStack) errorCtor.stackTraceLimit = previousLimit;\n\n this.name = \"EngineError\";\n this.category = category;\n this.code = init.code;\n this.expected = init.expected;\n this.found = init.found;\n this.suggestion = init.suggestion;\n this.recoverable = recoverable;\n this.span = init.span;\n this.context = init.context;\n this.cause = init.cause;\n this.timestamp = new Date();\n // Only for the faults. super() has already captured a stack for those, and\n // this second call recaptures it purely to drop this constructor's own\n // frame; doing that for every error meant paying the whole cost twice.\n if (!skipStack && Error.captureStackTrace) {\n Error.captureStackTrace(this, EngineError);\n }\n }\n\n /** `!recoverable`. See `EngineErrorInit.recoverable`'s doc comment for what this actually gates (message framing/telemetry, not whether evaluation continues). */\n isFatal(): boolean {\n return !this.recoverable;\n }\n\n /** Walk `.cause` repeatedly, collecting the full chain (this error first). */\n causeChain(): unknown[] {\n const chain: unknown[] = [this];\n let current: unknown = this.cause;\n while (current !== undefined && current !== null) {\n chain.push(current);\n current = current instanceof Error ? (current as Error & { cause?: unknown }).cause : undefined;\n }\n return chain;\n }\n\n /**\n * Rust/Go-style multi-line renderer, the NEW thing a host/CLI/test\n * reaches for when it wants the full, verbose picture, as distinct from\n * `.message` (kept short and stable for existing assertions). Example:\n *\n * ```\n * error[WEATHER_EXPECTED_CITY]: Expected a city name after \"weather in\"\n * expected: a city name\n * found: end of expression\n * suggestion: e.g. \"weather in London\"\n * ```\n */\n format(): string {\n const lines = [`error[${this.code}]: ${this.message}`];\n if (this.expected) lines.push(` expected: ${this.expected}`);\n if (this.found) lines.push(` found: ${this.found}`);\n if (this.suggestion) lines.push(` suggestion: ${this.suggestion}`);\n return lines.join(\"\\n\");\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n category: this.category,\n code: this.code,\n message: this.message,\n expected: this.expected,\n found: this.found,\n suggestion: this.suggestion,\n recoverable: this.recoverable,\n span: this.span,\n context: this.context,\n timestamp: this.timestamp.toISOString(),\n };\n }\n}\n\n/**\n * Factory for creating classified `EngineError`s. Every method accepts\n * EITHER the original, minimal 3-arg shape (`code, message, context?`\n * every existing call site across the codebase keeps compiling unchanged)\n * OR the richer `EngineErrorInit` object (for `expected`/`found`/\n * `suggestion`/`recoverable`/`span`/`cause`), upgrade a call site to the\n * richer form only when you're already touching it, no separate churn\n * pass required.\n */\nexport class ErrorFactory {\n private static build(\n category: ErrorCategory,\n defaultRecoverable: boolean,\n codeOrInit: string | EngineErrorInit,\n message?: string,\n context?: Record<string, unknown>,\n ): EngineError {\n const init: EngineErrorInit =\n typeof codeOrInit === \"string\"\n ? { code: codeOrInit, message: message!, context }\n : codeOrInit;\n return new EngineError(category, { recoverable: defaultRecoverable, ...init });\n }\n\n static validation(code: string, message: string, context?: Record<string, unknown>): EngineError;\n static validation(init: EngineErrorInit): EngineError;\n static validation(codeOrInit: string | EngineErrorInit, message?: string, context?: Record<string, unknown>): EngineError {\n return ErrorFactory.build(ErrorCategory.VALIDATION, true, codeOrInit, message, context);\n }\n\n static parsing(code: string, message: string, context?: Record<string, unknown>): EngineError;\n static parsing(init: EngineErrorInit): EngineError;\n static parsing(codeOrInit: string | EngineErrorInit, message?: string, context?: Record<string, unknown>): EngineError {\n return ErrorFactory.build(ErrorCategory.PARSING, true, codeOrInit, message, context);\n }\n\n static execution(code: string, message: string, context?: Record<string, unknown>): EngineError;\n static execution(init: EngineErrorInit): EngineError;\n static execution(codeOrInit: string | EngineErrorInit, message?: string, context?: Record<string, unknown>): EngineError {\n return ErrorFactory.build(ErrorCategory.EXECUTION, true, codeOrInit, message, context);\n }\n\n static external(code: string, message: string, context?: Record<string, unknown>): EngineError;\n static external(init: EngineErrorInit): EngineError;\n static external(codeOrInit: string | EngineErrorInit, message?: string, context?: Record<string, unknown>): EngineError {\n return ErrorFactory.build(ErrorCategory.EXTERNAL, true, codeOrInit, message, context);\n }\n\n /**\n * Reserve for genuine engine-internal invariant violations (corrupted\n * bytecode, a stack underflow from a buggy plugin, an \"impossible\" state),\n * not for user-input errors: the category is a bug report.\n *\n * Defaults `recoverable: true` all the same, because every one of these sites\n * is an invariant that failed on ONE line and none of them leaves the engine\n * unusable. This used to default to `false`, which conflated \"the engine's\n * fault\" with \"the engine is finished\" and told a host to tear a document\n * down over a line it could simply have shown an error against. A site that\n * has looked at its own case and concluded the instance really is gone can\n * still pass `recoverable: false` explicitly. See {@link\n * EngineErrorInit.recoverable}.\n */\n static internal(code: string, message: string, context?: Record<string, unknown>): EngineError;\n static internal(init: EngineErrorInit): EngineError;\n static internal(codeOrInit: string | EngineErrorInit, message?: string, context?: Record<string, unknown>): EngineError {\n return ErrorFactory.build(ErrorCategory.INTERNAL, true, codeOrInit, message, context);\n }\n\n /** Defaults `recoverable: false`, and is now the only method that does: a configuration or package-registration failure is the one class that leaves no working engine to carry on with, rather than one bad line in a document. */\n static config(code: string, message: string, context?: Record<string, unknown>): EngineError;\n static config(init: EngineErrorInit): EngineError;\n static config(codeOrInit: string | EngineErrorInit, message?: string, context?: Record<string, unknown>): EngineError {\n return ErrorFactory.build(ErrorCategory.CONFIG, false, codeOrInit, message, context);\n }\n}\n\n/**\n * Normalize any thrown value into an `EngineError`, an `EngineError`\n * passes through as-is; a plain `Error` gets wrapped (message preserved,\n * original attached via `cause`); anything else becomes a generic\n * \"unknown error\" wrapping the stringified value. Used at every\n * throw-space/Result-space boundary (`Result.tryCatch`'s default\n * `normalize`, the VM's outer execution try/catch, `AsyncResolutionBatcher`'s\n * per-line containment) so a raw `TypeError` from a genuine engine bug\n * still surfaces as a structured, catalogued error instead of an opaque\n * uncaught exception.\n *\n * Both branches state RECOVERABLE explicitly, while keeping the INTERNAL\n * category. The two fields answer different questions and were previously\n * answering the same one:\n *\n * category INTERNAL whose fault is this? The engine's. Worth reporting.\n * recoverable is this engine instance still usable? Yes.\n *\n * Everything reaching here is by definition something the engine did not\n * anticipate on ONE line, and per-line containment means the next line\n * evaluates normally, which `__tests__/hardening/RobustnessEngineLifecycle`\n * demonstrates over hundreds of alternating failure/success pairs. Reporting\n * that as `isFatal()` told a host the opposite, and a host that honours the\n * name would tear a document down over a single bad line. The \"this is an\n * engine bug rather than your syntax\" signal a caller wants for telemetry is\n * the CATEGORY, which is unchanged.\n *\n * The flag is written out here rather than inherited from\n * `ErrorFactory.internal()`, which now defaults the same way, so that this\n * function's contract survives a future change to that default.\n */\nexport function normalizeUnknownError(error: unknown): EngineError {\n if (error instanceof EngineError) return error;\n if (error instanceof Error) {\n return ErrorFactory.internal({\n code: \"UNEXPECTED_ERROR\",\n message: error.message,\n context: { originalErrorName: error.name },\n cause: error,\n recoverable: true,\n });\n }\n return ErrorFactory.internal({\n code: \"UNKNOWN_ERROR\",\n message: \"An unknown error occurred\",\n context: { error: String(error) },\n recoverable: true,\n });\n}\n","import { type EngineError, normalizeUnknownError } from \"@solve-js/errors/EngineError\";\n\n/**\n * A Rust-style `Result<T, E>`, the value half of this engine's error-handling\n * redesign. `E` defaults to `EngineError` (this engine's structured error\n * type) but every combinator here is generic over `E`, so `Result` works\n * equally well for a domain that isn't `EngineError`-shaped.\n *\n * This exact shape used to live in `errors/UnifiedErrorFramework.ts` (kept\n * there as a barrel re-export for backward compatibility), moved here as\n * its own module because it's genuinely generic (no dependency on\n * `EngineError` beyond the default type parameter) and because the engine\n * is migrating callers to it incrementally: parsing/VM/package code that\n * expects \"a failure is a possibility, not an exception\" returns\n * `Result<T, EngineError>` instead of throwing; two explicit adapters\n * {@link throwIfErr} and {@link tryCatch}, are the sanctioned way to cross\n * the boundary between Result-based code and still-throw-based code during\n * the migration (and permanently, at the public API boundary. See\n * `ExpressionEngine.evaluateExpression()`'s documented throw contract).\n */\nexport type Result<T, E = EngineError> =\n | { ok: true; value: T }\n | { ok: false; error: E };\n\n/** Wrap a successful value. */\nexport function ok<T>(value: T): Result<T, never> {\n return { ok: true, value };\n}\n\n/** Wrap a failure. */\nexport function err<E>(error: E): Result<never, E> {\n return { ok: false, error };\n}\n\n/**\n * Narrow a {@link Result} to its success arm.\n *\n * @param r - The result to test.\n * @returns True when it succeeded, narrowing `r` so `r.value` is reachable.\n */\nexport function isOk<T, E>(r: Result<T, E>): r is { ok: true; value: T } {\n return r.ok;\n}\n\n/**\n * Narrow a {@link Result} to its failure arm.\n *\n * @param r - The result to test.\n * @returns True when it failed, narrowing `r` so `r.error` is reachable.\n */\nexport function isErr<T, E>(r: Result<T, E>): r is { ok: false; error: E } {\n return !r.ok;\n}\n\n/** Transform the success value; a failure passes through untouched. */\nexport function map<T, U, E>(r: Result<T, E>, fn: (value: T) => U): Result<U, E> {\n return r.ok ? ok(fn(r.value)) : r;\n}\n\n/** Transform the error; a success passes through untouched. */\nexport function mapErr<T, E, F>(r: Result<T, E>, fn: (error: E) => F): Result<T, F> {\n return r.ok ? r : err(fn(r.error));\n}\n\n/** Chain a Result-returning operation onto a success (a.k.a. flatMap/bind). */\nexport function andThen<T, U, E>(r: Result<T, E>, fn: (value: T) => Result<U, E>): Result<U, E> {\n return r.ok ? fn(r.value) : r;\n}\n\n/** Unwrap a success, or return `fallback` for a failure. Never throws. */\nexport function unwrapOr<T, E>(r: Result<T, E>, fallback: T): T {\n return r.ok ? r.value : fallback;\n}\n\n/** Exhaustive pattern-match, the `match`/`switch` a Rust enum gets for free. */\nexport function match<T, E, R>(r: Result<T, E>, arms: { ok: (value: T) => R; err: (error: E) => R }): R {\n return r.ok ? arms.ok(r.value) : arms.err(r.error);\n}\n\n/**\n * Combine several Results into one, succeeds with a tuple of all values\n * iff every input succeeded; otherwise fails with the FIRST error\n * encountered (left-to-right), matching this codebase's existing\n * fail-fast convention elsewhere (e.g. `BytecodeBuilder`'s constant-pool\n * limit checks).\n */\nexport function combine<T extends readonly unknown[], E>(\n results: { [K in keyof T]: Result<T[K], E> },\n): Result<T, E> {\n const values: unknown[] = [];\n for (const r of results as readonly Result<unknown, E>[]) {\n if (!r.ok) return r;\n values.push(r.value);\n }\n return ok(values as unknown as T);\n}\n\n/**\n * Cross from Result-space back to throw-space, the sanctioned boundary\n * adapter for callers (public API surface, older not-yet-migrated code,\n * tests) that still want exception-based control flow. Throws `r.error`\n * as-is (an `EngineError` is already a real `Error` subclass, so this\n * needs no wrapping).\n */\nexport function throwIfErr<T, E>(r: Result<T, E>): T {\n if (r.ok) return r.value;\n throw r.error;\n}\n\n/**\n * Cross from throw-space into Result-space, runs `fn`, converting any\n * thrown value into a Result via `normalize` (defaults to\n * {@link normalizeUnknownError}). The inverse of {@link throwIfErr}; the\n * pairing that lets Result-based and throw-based code interoperate during\n * an incremental migration instead of requiring a single flag-day rewrite.\n */\nexport function tryCatch<T>(\n fn: () => T,\n normalize: (e: unknown) => EngineError = normalizeUnknownError,\n): Result<T, EngineError> {\n try {\n return ok(fn());\n } catch (e) {\n return err(normalize(e));\n }\n}\n\n/** Async sibling of {@link tryCatch}. */\nexport async function tryCatchAsync<T>(\n fn: () => Promise<T>,\n normalize: (e: unknown) => EngineError = normalizeUnknownError,\n): Promise<Result<T, EngineError>> {\n try {\n return ok(await fn());\n } catch (e) {\n return err(normalize(e));\n }\n}\n","/**\n * The built-in error-code catalog, one typed const object per domain\n * unioned together here for autocomplete/exhaustiveness in core engine\n * code. Deliberately NOT one central enum: `IEnginePackage` is documented\n * public SDK surface for third-party packages (see `api/PackageRegistry.ts`),\n * and a closed enum would block an external package author from defining\n * their own codes without editing this file. `EngineError.code`'s runtime\n * type stays `string` for exactly that reason. This catalog is for the\n * codes THIS repo owns and wants collision/typo checking on (see\n * `__tests__/errors/ErrorCodeCatalog.spec.ts`), not a hard runtime\n * whitelist.\n *\n * As each package migrates to `Result<void, EngineError>` (see this\n * session's error-handling-refactor plan, Phase 5), it should export its\n * own small `XxxErrorCodes` const object co-located with its parselets\n * exactly like `CoreErrorCodes` below, just scoped to one domain, and get\n * unioned into `ErrorCode` here. Until a package migrates, its existing\n * free-string codes keep working (ErrorFactory accepts any string); they\n * just aren't caught by the catalog's uniqueness/orphan checks yet.\n */\n\n/**\n * Codes used directly by the parser/VM/engine/errors layers themselves\n * confirmed against the current source, not aspirational. Grouped by\n * pipeline stage via the comments, not a naming prefix (these predate any\n * naming convention and renaming them is out of scope for introducing the\n * catalog, only NEW codes need to follow a scoped/prefixed style, see\n * `STACK_UNDERFLOW` etc. below).\n */\nexport const CoreErrorCodes = {\n // ── Parser (parser/PrecedenceParser.ts, parser/BytecodeBuilder.ts, parser/PhrasePattern.ts) ──\n INVALID_NUMBER_LITERAL: \"INVALID_NUMBER_LITERAL\",\n /** A `\"` that never meets its closing partner (`lexer/ExpressionLexer.ts`'s `tokenizeString()`). Previously the tokenizer ran off the end of the input and returned what it had, so `\"abc` lexed to an ordinary String and an unterminated literal was indistinguishable from a terminated one. */\n UNTERMINATED_STRING: \"UNTERMINATED_STRING\",\n NO_PREFIX_PARSELET: \"NO_PREFIX_PARSELET\",\n UNEXPECTED_END_OF_INPUT: \"UNEXPECTED_END_OF_INPUT\",\n UNEXPECTED_TOKEN_TYPE: \"UNEXPECTED_TOKEN_TYPE\",\n NESTING_DEPTH_EXCEEDED: \"NESTING_DEPTH_EXCEEDED\",\n UNEXPECTED_END: \"UNEXPECTED_END\",\n UNEXPECTED_TRAILING_TOKEN: \"UNEXPECTED_TRAILING_TOKEN\",\n PARSE_ERROR: \"PARSE_ERROR\",\n TOO_MANY_NUMERIC_CONSTANTS: \"TOO_MANY_NUMERIC_CONSTANTS\",\n TOO_MANY_STRING_CONSTANTS: \"TOO_MANY_STRING_CONSTANTS\",\n NO_MATCHING_PHRASE_ALTERNATIVE: \"NO_MATCHING_PHRASE_ALTERNATIVE\",\n INVALID_PHRASE_PATTERN: \"INVALID_PHRASE_PATTERN\",\n PHRASE_KEYWORD_MISMATCH: \"PHRASE_KEYWORD_MISMATCH\",\n /** User-defined-function definition parsing (`f(x, y) = ...`), an invalid token where a parameter name was expected. */\n USER_FUNCTION_INVALID_PARAM_NAME: \"USER_FUNCTION_INVALID_PARAM_NAME\",\n /** `f() = ...` with zero parameters, indistinguishable from a plain no-arg function call, so rejected at definition time. */\n USER_FUNCTION_NO_PARAMS: \"USER_FUNCTION_NO_PARAMS\",\n /** A user-defined function body calling an async plugin (weather/stocks/currency/...), rejected at definition time; v1 scope excludes async function bodies. */\n FUNCTION_BODY_MUST_BE_SYNCHRONOUS: \"FUNCTION_BODY_MUST_BE_SYNCHRONOUS\",\n /** `BytecodeBuilder`'s `userFunctionBodies` side-table exceeding its capacity. Same class as `TOO_MANY_NUMERIC_CONSTANTS`/`TOO_MANY_STRING_CONSTANTS` below. */\n TOO_MANY_FUNCTION_DEFINITIONS: \"TOO_MANY_FUNCTION_DEFINITIONS\",\n /** `BytecodeBuilder`'s `anonymousBodies` side-table (map/reduce inline transform bodies) exceeding its capacity. Same class as `TOO_MANY_FUNCTION_DEFINITIONS` above. */\n TOO_MANY_ANONYMOUS_BODIES: \"TOO_MANY_ANONYMOUS_BODIES\",\n /** New with the 2.0 descriptor redesign: a parselet emits a plugin call by NAME (`BytecodeBuilder.emitPluginCall(name, argCount)`) and the engine resolves that name to the index it assigned at registration. This fires when the name is absent from the builder's name->index map: the package used a `pluginFunctions` name it never declared, or the expression was parsed before that package registered. Not a user-input error; a package-authoring/registration fault. See `parser/BytecodeBuilder.ts`'s `emitPluginCall()`. */\n UNKNOWN_PLUGIN_FUNCTION: \"UNKNOWN_PLUGIN_FUNCTION\",\n\n // ── VM (vm/VM.ts, vm/OpRegistry.ts, vm/VMBuiltins.ts) ──\n EVALUATION_ERROR: \"EVALUATION_ERROR\",\n INSTRUCTION_LIMIT_EXCEEDED: \"INSTRUCTION_LIMIT_EXCEEDED\",\n STACK_LIMIT_EXCEEDED: \"STACK_LIMIT_EXCEEDED\",\n /** One evaluation asking for more elements (collection Values, matrix cells) than `vm.maxAllocatedElements` allows. The counter the two limits above cannot be: both are checked between opcodes, so neither can see what a single opcode allocates inside a loop of its own. See `vm/AllocationBudget.ts`. Recoverable, since it describes this expression rather than the engine. */\n ALLOCATION_LIMIT_EXCEEDED: \"ALLOCATION_LIMIT_EXCEEDED\",\n /** New this phase. See `VM.ts`'s `safePop()`: a stack-underflow (corrupted bytecode, a buggy plugin) is now a controlled EngineError instead of a raw TypeError. Category INTERNAL, since it is an engine or plugin fault rather than a typed line, but recoverable: it happened on one line and the engine is still usable. */\n STACK_UNDERFLOW: \"STACK_UNDERFLOW\",\n UNDEFINED_VARIABLE: \"UNDEFINED_VARIABLE\",\n /** New this phase, the Tier-2/`LOAD_GLOBAL_VAR` hardening: a global variable read before its async preflight resolved, surfaced as a controlled error instead of pushing `undefined`. */\n GLOBAL_VARIABLE_NOT_RESOLVED: \"GLOBAL_VARIABLE_NOT_RESOLVED\",\n UNKNOWN_FUNCTION: \"UNKNOWN_FUNCTION\",\n /** `unwrapEvalResult()`'s pending-when-expecting-value case, a caller-contract violation, not user-input. */\n UNEXPECTED_PENDING_RESULT: \"UNEXPECTED_PENDING_RESULT\",\n /** User-defined-function call/definition errors (`CALL_USER_FUNCTION`/`DEFINE_USER_FUNCTION` opcodes), calling a name with no matching definition, calling with the wrong argument count, and the deliberate v1 restriction that a function body can't itself contain async work. */\n UNDEFINED_FUNCTION: \"UNDEFINED_FUNCTION\",\n FUNCTION_ARITY_MISMATCH: \"FUNCTION_ARITY_MISMATCH\",\n /** The same mistake against a BUILT-IN rather than a user-defined function (`sqrt()`, `atan2(1)`, `sqrt(1,2,3)`). Separate from `FUNCTION_ARITY_MISMATCH` above because the two are raised by different opcodes and a host may want to word them differently. Checked at the `CALL_BUILTIN` dispatch against `vm/VMBuiltinArity.ts`; recoverable, since it is a typo in the line, not an engine fault. */\n BUILTIN_ARITY_MISMATCH: \"BUILTIN_ARITY_MISMATCH\",\n USER_FUNCTION_ASYNC_UNSUPPORTED: \"USER_FUNCTION_ASYNC_UNSUPPORTED\",\n /** A map/reduce transform body (inline expression or user-defined function) calling an async plugin. Same v1 scope restriction as `USER_FUNCTION_ASYNC_UNSUPPORTED` above, enforced both at parse time (`MAP_REDUCE_TRANSFORM_MUST_BE_SYNCHRONOUS`, packages/mapreduce/) and as a defense-in-depth runtime backstop here. */\n MAP_REDUCE_ASYNC_UNSUPPORTED: \"MAP_REDUCE_ASYNC_UNSUPPORTED\",\n /** An algebra verb's expression argument (`BIND_UNKNOWN`'s body) calling an async plugin. Same v1 scope restriction as the two above, and likewise refused at parse time first (`SYMBOLIC_ARGUMENT_MUST_BE_SYNCHRONOUS`, packages/symbolic/). */\n SYMBOLIC_ASYNC_UNSUPPORTED: \"SYMBOLIC_ASYNC_UNSUPPORTED\",\n /** `explainLine()` asked to derive a line that resolves data asynchronously (a live-data or async-plugin line). A derivation is a sequence of settled intermediate values, which a pending result has none of, so the line is refused rather than explained with a hole in it. */\n EXPLAIN_ASYNC_UNSUPPORTED: \"EXPLAIN_ASYNC_UNSUPPORTED\",\n /** `pushCallFrame()`'s recursion guard, a nested `CALL_USER_FUNCTION` re-enters `executeBytecode()`, so `maxInstructions` alone can't catch e.g. `f(x) = f(x)`; this is the dedicated backstop. `recoverable: true` (the default for `.execution()`), ordinary user-written infinite recursion, not an engine bug; the guard exists precisely so it surfaces as a clear error instead of overflowing the native call stack uncatchably. */\n FUNCTION_RECURSION_LIMIT_EXCEEDED: \"FUNCTION_RECURSION_LIMIT_EXCEEDED\",\n /** The companion to the code above, and the half it could never see: how MANY user-defined-function calls one evaluation makes, rather than how deeply they nest. A twenty-two-line doubling chain nests twenty-two deep (legal) and makes two million calls (a fatal heap abort). Counted in `vm/AllocationBudget.ts`, because the tally has to survive `executeBytecode()` re-entering itself. Recoverable. */\n FUNCTION_CALL_LIMIT_EXCEEDED: \"FUNCTION_CALL_LIMIT_EXCEEDED\",\n /** A `<date> + N workdays` offset outside `date.maxOffsetYears`/`minOffsetYears`. Workdays are the one date offset that walks the calendar a day at a time, so the one whose cost is the offset; every other one moves a Date field once. Recoverable. */\n DATE_OFFSET_LIMIT_EXCEEDED: \"DATE_OFFSET_LIMIT_EXCEEDED\",\n /** The anchor of `N working days after/before/from <expr>` was not a date (e.g. `5 working days after 3`). The grammar guarantees the count is a number, so this only fires on the anchor. Emitted as a recoverable Error value, not thrown, matching the datetime package's other type guards. See `vm/VM.ts`'s `DATE_WORKDAY_OFFSET` case. */\n WORKDAY_OFFSET_EXPECTED_DATE: \"WORKDAY_OFFSET_EXPECTED_DATE\",\n /** An endpoint of `working days between <expr> and <expr>` was not a date. Recoverable Error value. See `vm/VM.ts`'s `DATE_WORKDAYS_BETWEEN` case. */\n WORKDAYS_BETWEEN_EXPECTED_DATES: \"WORKDAYS_BETWEEN_EXPECTED_DATES\",\n /** The two endpoints of `working days between <expr> and <expr>` are further apart than `date.maxOffsetYears`/`minOffsetYears` allow the count's calendar walk to run. Recoverable Error value, the between-count's equivalent of `DATE_OFFSET_LIMIT_EXCEEDED`. See `vm/VM.ts`'s `DATE_WORKDAYS_BETWEEN` case. */\n WORKDAYS_BETWEEN_RANGE_TOO_LARGE: \"WORKDAYS_BETWEEN_RANGE_TOO_LARGE\",\n /** A `<<`/`>>` with a bigint operand whose exact result would pass `MAX_EXACT_SHIFT_BITS`, whichever operand is the bigint. Both spellings refuse as of 1.0.0: a bigint on the left used to fall through to `x * 2^n` in doubles and report a 19,870-digit integer as Infinity. See `vm/VM.ts`'s `bigIntShift()`. Recoverable. */\n BIGINT_SHIFT_LIMIT_EXCEEDED: \"BIGINT_SHIFT_LIMIT_EXCEEDED\",\n /** The same ceiling for `^`, the operator it was written for: `2n ^ 100000` asks for the same 100,001-bit integer `1n << 100000` does, so the two spellings answer the same way. Also new in 1.0.0, and for the same reason: this used to fall through to the double path and answer Infinity. A fractional or negative exponent (`4n ^ 0.5`, `2n ^ -1`) has no exact answer to bound and still uses the double path. See `vm/VM.ts`'s `MAX_EXACT_POW_BITS`. Recoverable. */\n BIGINT_POW_LIMIT_EXCEEDED: \"BIGINT_POW_LIMIT_EXCEEDED\",\n /** An operand with no whole-number form (a fraction, an infinity, a NaN) meeting a bigint: `1n + 0.5`, `1n & 1.5`, `5n/pi`. `BigInt()` answers those with a raw RangeError, which the VM relabelled UNEXPECTED_ERROR, so a typo in the line was reported as an engine fault. Recoverable; see `vm/VMConversion.ts`'s `toBigIntOperand()`. */\n BIGINT_INEXACT_OPERAND: \"BIGINT_INEXACT_OPERAND\",\n /** `10n / 0n` and `10n mod 0n`. Deliberately NOT what `1 / 0` does, which is Infinity: a bigint division is exact integer division (`7n / 2n` is 3n), and integer division by zero has no answer, exactly as it has none in C, Java, Python or JavaScript's own BigInt. Previously V8's own RangeError, relabelled UNEXPECTED_ERROR. Recoverable; see `vm/VMConversion.ts`'s `bigIntDivisionByZero()`. */\n BIGINT_DIVISION_BY_ZERO: \"BIGINT_DIVISION_BY_ZERO\",\n /** `DEFINE_USER_FUNCTION`'s body-index lookup failing, a compiler/VM invariant violation (the opcode stream referenced a `userFunctionBodies` slot that doesn't exist), never a user-input error. */\n INTERNAL_MISSING_FUNCTION_BODY: \"INTERNAL_MISSING_FUNCTION_BODY\",\n /** `MAP_INVOKE`/`REDUCE_INVOKE`'s anonymous-body-index lookup failing. Same class as `INTERNAL_MISSING_FUNCTION_BODY` above, for the `anonymousBodies` side-table instead of `userFunctionBodies`. */\n INTERNAL_MISSING_ANONYMOUS_BODY: \"INTERNAL_MISSING_ANONYMOUS_BODY\",\n /** `CALL_BUILTIN` naming an index no builtin is registered at. It used to pop its arguments and push nothing, so the opcode after it read a neighbour's operand as its own; now an Error value on the stack, the shape `map`/`reduce` already used for the same fault. Bytecode-level, so unreachable from source without a compiler or snapshot fault. */\n UNKNOWN_BUILTIN_FUNCTION: \"UNKNOWN_BUILTIN_FUNCTION\",\n\n // ── Malformed bytecode on the public `./vm` surface (vm/VM.ts) ──\n //\n // `executeBytecode` is exported, so a bytecode program is caller input in\n // the same sense an expression string is, and these five say so. They are\n // VALIDATION rather than INTERNAL for exactly that reason: before they\n // existed, every one of these cases reached a raw TypeError (`BigInt(undefined)`,\n // `code.toUpperCase()` on a boolean, destructuring a program that was not\n // there), which normalised to UNEXPECTED_ERROR and told the caller the\n // engine was broken when their eleven bytes were. Reachable from ordinary\n // source only through a compiler bug, which is why the messages name the\n // opcode and the operand rather than the user's line.\n /** An operand byte read past the end of the stream: the program ends in the middle of an instruction. */\n MALFORMED_BYTECODE_TRUNCATED: \"MALFORMED_BYTECODE_TRUNCATED\",\n /** A constant-pool operand indexing a `numbers`/`strings` entry that does not exist, or that is not of the pool's type. */\n MALFORMED_BYTECODE_CONSTANT_INDEX: \"MALFORMED_BYTECODE_CONSTANT_INDEX\",\n /** A unit or converter name read off the value stack that is not a string. Distinct from the pool case above: the operand is a Value another opcode pushed, not a pool entry. */\n MALFORMED_BYTECODE_OPERAND_TYPE: \"MALFORMED_BYTECODE_OPERAND_TYPE\",\n /** `MAP_INVOKE`/`REDUCE_INVOKE` carrying a body kind other than 0/1/2. Used to fall through every arm with no body and recurse into `executeBytecode(undefined)`. */\n MALFORMED_BYTECODE_BODY_KIND: \"MALFORMED_BYTECODE_BODY_KIND\",\n /** A `PUSH_BIGINT` pool entry that is not a whole number, e.g. `\"1.000\"`. `BigInt()` answers that with a raw SyntaxError. */\n MALFORMED_BYTECODE_BIGINT_LITERAL: \"MALFORMED_BYTECODE_BIGINT_LITERAL\",\n /** `executeBytecode()` called with something that is not a runnable program at all. Checked before the destructure that used to throw outside the function's own try/catch. */\n MALFORMED_BYTECODE_PROGRAM: \"MALFORMED_BYTECODE_PROGRAM\",\n\n // ── Symbolic algebra (symbolic/, vm/SymbolicOps.ts) ──\n /** A coefficient grew past `RATIONAL_MAX_BITS`, e.g. repeated exact elimination multiplying denominators together. */\n SYMBOLIC_RATIONAL_OVERFLOW: \"SYMBOLIC_RATIONAL_OVERFLOW\",\n /** `NaN` or `±Infinity` reaching a symbolic expression, neither of which has an exact rational value. */\n SYMBOLIC_NONFINITE_OPERAND: \"SYMBOLIC_NONFINITE_OPERAND\",\n /** Division by an exactly-zero rational. Exact, unlike the double comparison it replaced, which could not distinguish a true zero from `5.551e-17`. */\n SYMBOLIC_DIVISION_BY_ZERO: \"SYMBOLIC_DIVISION_BY_ZERO\",\n /** A tree exceeding `SYMBOLIC_MAX_NODES` entering the simplifier. */\n SYMBOLIC_NODE_LIMIT_EXCEEDED: \"SYMBOLIC_NODE_LIMIT_EXCEEDED\",\n /** A builtin with no symbolic reading (`min`, `random`, the finance block, ...) applied to an expression still containing an unknown. Returned rather than computing against `toNumber()`'s placeholder zero. */\n SYMBOLIC_UNSUPPORTED_FUNCTION: \"SYMBOLIC_UNSUPPORTED_FUNCTION\",\n /** The rational-root search exceeding `FACTOR_MAX_ROOT_CANDIDATES`. The candidate set is the product of two divisor sets, so a highly-composite coefficient escapes quickly. */\n SYMBOLIC_FACTOR_LIMIT_EXCEEDED: \"SYMBOLIC_FACTOR_LIMIT_EXCEEDED\",\n /** An equation outside what the solver attempts: not a polynomial, above the degree ceiling, or non-linear in the unknown while another unknown is present. */\n SYMBOLIC_SOLVE_UNSUPPORTED: \"SYMBOLIC_SOLVE_UNSUPPORTED\",\n /** Some but not all of an equation's roots were found. Reported rather than returned, because a partial list of roots looks exactly like a complete one. */\n SYMBOLIC_SOLVE_INCOMPLETE: \"SYMBOLIC_SOLVE_INCOMPLETE\",\n /** `solve`'s second argument not being a bare name. */\n SOLVE_REQUIRES_VARIABLE_NAME: \"SOLVE_REQUIRES_VARIABLE_NAME\",\n /** A derivative order outside 0..`DERIVATIVE_MAX_ORDER`. */\n SYMBOLIC_DERIVATIVE_ORDER_LIMIT: \"SYMBOLIC_DERIVATIVE_ORDER_LIMIT\",\n /** An expression with no known elementary antiderivative. Reported rather than approximated, since a wrong integral is indistinguishable from a right one at the point of use. */\n SYMBOLIC_INTEGRAL_UNSUPPORTED: \"SYMBOLIC_INTEGRAL_UNSUPPORTED\",\n /** A Taylor degree outside 0..`TAYLOR_MAX_DEGREE`. */\n SYMBOLIC_TAYLOR_DEGREE_LIMIT: \"SYMBOLIC_TAYLOR_DEGREE_LIMIT\",\n /** A Taylor coefficient that does not reduce to an exact number at the expansion point. */\n SYMBOLIC_TAYLOR_INEXACT: \"SYMBOLIC_TAYLOR_INEXACT\",\n /** An algebra verb's variable-name argument not being a bare name. */\n SYMBOLIC_REQUIRES_VARIABLE_NAME: \"SYMBOLIC_REQUIRES_VARIABLE_NAME\",\n /** `jacobian` called with expressions containing no unknown to differentiate against. */\n SYMBOLIC_JACOBIAN_NO_VARIABLES: \"SYMBOLIC_JACOBIAN_NO_VARIABLES\",\n /** A finite number whose decimal form could not be read back, which the regex covering every `Number.prototype.toString` output should make unreachable. */\n INTERNAL_RATIONAL_PARSE: \"INTERNAL_RATIONAL_PARSE\",\n\n // ── Engine (engine/ExpressionEngine.ts, engine/ExpressionEngineSafety.ts, engine/AsyncResolutionBatcher.ts) ──\n EXPRESSION_TOO_LONG: \"EXPRESSION_TOO_LONG\",\n EXPRESSION_TOO_COMPLEX: \"EXPRESSION_TOO_COMPLEX\",\n /** A document with more lines than `performance.maxDocumentLines`. The per-line limits above bound what one line may ask for and say nothing about how many lines there are; two hundred thousand of `1 + 1` exhausted the heap on the line records alone. Recoverable. */\n DOCUMENT_TOO_LARGE: \"DOCUMENT_TOO_LARGE\",\n NORMALIZED_TOKEN_LIMIT_EXCEEDED: \"NORMALIZED_TOKEN_LIMIT_EXCEEDED\",\n /** `\"=>\"` with nothing before it, needs an expression or variable name to solve/simplify. */\n THEREFORE_REQUIRES_EXPRESSION: \"THEREFORE_REQUIRES_EXPRESSION\",\n /** A `\"=>\"`-triggered expression called an async plugin (weather/stocks/currency). Same v1 scope restriction as user-function/map-reduce bodies. */\n THEREFORE_ASYNC_UNSUPPORTED: \"THEREFORE_ASYNC_UNSUPPORTED\",\n /** A compound assignment (`name += expr` / `name -= expr`) with nothing on the right, a line half-typed on the way to `total += 5`. */\n COMPOUND_ASSIGN_REQUIRES_EXPRESSION: \"COMPOUND_ASSIGN_REQUIRES_EXPRESSION\",\n /** A running total (`+= / -=`) whose right-hand side calls an async plugin (weather/stocks/currency). The same v1 scope restriction as the `\"=>\"` and user-function bodies. */\n COMPOUND_ASSIGN_ASYNC_UNSUPPORTED: \"COMPOUND_ASSIGN_ASYNC_UNSUPPORTED\",\n /** A savings-goal contribution period that is not one of daily/weekly/monthly/yearly (`how long to save $X at $Y <period>`). Names the accepted set. */\n UNKNOWN_SAVINGS_PERIOD: \"UNKNOWN_SAVINGS_PERIOD\",\n /** Colon-separated numbers that are not a time any clock can show (\"24:00\", \"9:60\", \"100:5\"). Raised by the labeled-line fallback, which used to answer them with whatever stood after the colon. */\n INVALID_TIME_LITERAL: \"INVALID_TIME_LITERAL\",\n /** A live-data form evaluated on an engine whose host switched the network off (`network.enabled: false`, see `constants/Configuration.ts`'s `NetworkConfig`). A recoverable Error value, raised by the VM for a currency conversion with no primed rate and for a plugin function that returned a promise, and by `createQueryResolver`'s plugin function when its preflight was skipped. Names the setting, so the reader knows it is policy rather than an outage. */\n NETWORK_DISABLED: \"NETWORK_DISABLED\",\n\n // ── Snapshot / restore (engine/EngineSnapshot.ts, engine/ExpressionEngine.ts) ──\n /** `fromJSON()` handed an object that is not a snapshot at all, or whose serialised-shape version does not match this engine's reader. The versioning gate that refuses an incompatible snapshot clearly rather than restoring it wrongly. See `engine/EngineSnapshot.ts`'s `assertRestorable()`. */\n SNAPSHOT_VERSION_MISMATCH: \"SNAPSHOT_VERSION_MISMATCH\",\n /** A snapshot with the right envelope but internally inconsistent contents (an unrecognised number sentinel, an unknown value tag). Distinct from a version mismatch: the format is right, the payload is not. */\n SNAPSHOT_MALFORMED: \"SNAPSHOT_MALFORMED\",\n /** A value the v1 snapshot format cannot yet represent (a symbolic/algebra value, a symbolic matrix cell). Deferred to a follow-up; refused by name rather than dropped silently. */\n SNAPSHOT_UNSUPPORTED_VALUE: \"SNAPSHOT_UNSUPPORTED_VALUE\",\n\n // ── Config (constants/Configuration.ts) ──\n CONFIG_PATH_NOT_FOUND: \"CONFIG_PATH_NOT_FOUND\",\n INVALID_CONFIG_PATH: \"INVALID_CONFIG_PATH\",\n CONFIG_SECTION_NOT_FOUND: \"CONFIG_SECTION_NOT_FOUND\",\n CONFIG_PROPERTY_NOT_FOUND: \"CONFIG_PROPERTY_NOT_FOUND\",\n\n // ── Package/lexer registration-time collisions (lexer/ExpressionLexer.ts) ──\n PLUGIN_OPERATOR_COLLISION: \"PLUGIN_OPERATOR_COLLISION\",\n PLUGIN_KEYWORD_COLLISION: \"PLUGIN_KEYWORD_COLLISION\",\n PLUGIN_UNIT_COLLISION: \"PLUGIN_UNIT_COLLISION\",\n /** A package's declared `IEnginePackage.engineVersion` semver range doesn't satisfy the running engine's ENGINE_VERSION. See api/EngineVersionCompatibility.ts. */\n PACKAGE_ENGINE_VERSION_MISMATCH: \"PACKAGE_ENGINE_VERSION_MISMATCH\",\n /** A package's declared `IEnginePackage.engineVersion` isn't a parseable semver range at all (a typo in the package's own descriptor). */\n PACKAGE_ENGINE_VERSION_INVALID_RANGE: \"PACKAGE_ENGINE_VERSION_INVALID_RANGE\",\n /** `OpRegistry.allocateOpcode()`'s dynamic opcode pool (started at 201) exhausted, too many packages calling it. */\n OPCODE_POOL_EXHAUSTED: \"OPCODE_POOL_EXHAUSTED\",\n /** `VMBuiltins.allocatePluginFunctionIndex()`'s index pool (up to 65536, two opcode-stream bytes) exhausted. */\n PLUGIN_FUNCTION_INDEX_POOL_EXHAUSTED: \"PLUGIN_FUNCTION_INDEX_POOL_EXHAUSTED\",\n /** A plugin-function index exceeds the two-byte (65535) `CALL_PLUGIN_WIDE` bytecode operand. */\n PLUGIN_FUNCTION_INDEX_TOO_LARGE: \"PLUGIN_FUNCTION_INDEX_TOO_LARGE\",\n\n // ── vm/Value.ts caller-contract violations (check isRateUnit()/isTimecodeUnit() first) ──\n INVALID_RATE_UNIT: \"INVALID_RATE_UNIT\",\n INVALID_TIMECODE_UNIT: \"INVALID_TIMECODE_UNIT\",\n\n // ── errors/EngineError.ts's own fallback normalization ──\n UNEXPECTED_ERROR: \"UNEXPECTED_ERROR\",\n UNKNOWN_ERROR: \"UNKNOWN_ERROR\",\n} as const;\n\n/** Every error code the engine's own layers can produce, from {@link CoreErrorCodes}. */\nexport type CoreErrorCode = (typeof CoreErrorCodes)[keyof typeof CoreErrorCodes];\n\n/**\n * The aggregated catalog type. Currently just `CoreErrorCode`, union in\n * each package's own code-object type here as Phase 5 converts it, e.g.\n * `CoreErrorCode | WeatherErrorCode | StocksErrorCode | ...`.\n */\nexport type ErrorCode = CoreErrorCode;\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
'use strict';var chunkELQQKZN3_cjs=require('./chunk-ELQQKZN3.cjs');var o={WORKER_CANCELLED:"WORKER_CANCELLED",WORKER_TERMINATED:"WORKER_TERMINATED",WORKER_TRANSPORT_FAILED:"WORKER_TRANSPORT_FAILED",WORKER_UNKNOWN_METHOD:"WORKER_UNKNOWN_METHOD",WORKER_NOT_INITIALISED:"WORKER_NOT_INITIALISED",WORKER_UNKNOWN_PACKAGE:"WORKER_UNKNOWN_PACKAGE"};function t(r){let e={name:r.name,category:r.category,code:r.code,message:r.message,recoverable:r.recoverable};return r.expected!==void 0&&(e.expected=r.expected),r.found!==void 0&&(e.found=r.found),r.suggestion!==void 0&&(e.suggestion=r.suggestion),r.span!==void 0&&(e.span=r.span),e}function a(r){let e=Object.values(chunkELQQKZN3_cjs.a).includes(r.category)?r.category:"INTERNAL";return new chunkELQQKZN3_cjs.b(e,{code:r.code,message:r.message,expected:r.expected,found:r.found,suggestion:r.suggestion,recoverable:r.recoverable,span:r.span})}function s(r){return chunkELQQKZN3_cjs.c.execution(o.WORKER_CANCELLED,r?`The worker request "${r}" was cancelled`:"The worker request was cancelled",r?{method:r}:void 0)}function c(){return chunkELQQKZN3_cjs.c.execution(o.WORKER_TERMINATED,"The worker engine was terminated before this request completed")}function g(r){return chunkELQQKZN3_cjs.c.external(o.WORKER_TRANSPORT_FAILED,`The worker transport failed: ${r}`,{detail:r})}exports.a=o;exports.b=t;exports.c=a;exports.d=s;exports.e=c;exports.f=g;//# sourceMappingURL=chunk-CDNJZBM3.cjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-CDNJZBM3.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors/WorkerError.ts"],"names":["WorkerErrorCodes","serializeEngineError","error","dto","deserializeEngineError","category","ErrorCategory","EngineError","workerCancelledError","method","ErrorFactory","workerTerminatedError","workerTransportError","detail"],"mappings":"mEAoBO,IAAMA,EAAmB,CAE/B,gBAAA,CAAkB,kBAAA,CAElB,iBAAA,CAAmB,oBAEnB,uBAAA,CAAyB,yBAAA,CAEzB,qBAAA,CAAuB,uBAAA,CAEvB,uBAAwB,wBAAA,CAExB,sBAAA,CAAwB,wBACzB,EAyBO,SAASC,CAAAA,CAAqBC,CAAAA,CAA2C,CAC/E,IAAMC,EAA6B,CAClC,I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D,CAGO,SAASE,CAAAA,EAAqC,CACpD,OAAOD,mBAAAA,CAAa,UACnBV,CAAAA,CAAiB,iBAAA,CACjB,gEACD,CACD,CAGO,SAASY,CAAAA,CAAqBC,CAAAA,CAA6B,CACjE,OAAOH,mBAAAA,CAAa,QAAA,CACnBV,CAAAA,CAAiB,uBAAA,CACjB,gCAAgCa,CAAM,CAAA,CAAA,CACtC,CAAE,MAAA,CAAAA,CAAO,CACV,CACD","file":"chunk-
|
|
1
|
+
{"version":3,"sources":["../src/errors/WorkerError.ts"],"names":["WorkerErrorCodes","serializeEngineError","error","dto","deserializeEngineError","category","ErrorCategory","EngineError","workerCancelledError","method","ErrorFactory","workerTerminatedError","workerTransportError","detail"],"mappings":"mEAoBO,IAAMA,EAAmB,CAE/B,gBAAA,CAAkB,kBAAA,CAElB,iBAAA,CAAmB,oBAEnB,uBAAA,CAAyB,yBAAA,CAEzB,qBAAA,CAAuB,uBAAA,CAEvB,uBAAwB,wBAAA,CAExB,sBAAA,CAAwB,wBACzB,EAyBO,SAASC,CAAAA,CAAqBC,CAAAA,CAA2C,CAC/E,IAAMC,EAA6B,CAClC,IAAA,CAAMD,CAAAA,CAAM,IAAA,CACZ,SAAUA,CAAAA,CAAM,QAAA,CAChB,IAAA,CAAMA,CAAAA,CAAM,KACZ,OAAA,CAASA,CAAAA,CAAM,QACf,WAAA,CAAaA,CAAAA,CAAM,WACpB,CAAA,CAIA,OAAIA,CAAAA,CAAM,QAAA,GAAa,SAAWC,CAAAA,CAAI,QAAA,CAAWD,CAAAA,CAAM,QAAA,CAAA,CACnDA,EAAM,KAAA,GAAU,MAAA,GAAWC,CAAAA,CAAI,KAAA,CAAQD,EAAM,KAAA,CAAA,CAC7CA,CAAAA,CAAM,aAAe,MAAA,GAAWC,CAAAA,CAAI,WAAaD,CAAAA,CAAM,UAAA,CAAA,CAGvDA,CAAAA,CAAM,IAAA,GAAS,SAAWC,CAAAA,CAAI,IAAA,CAAOD,CAAAA,CAAM,IAAA,CAAA,CACxCC,CACR,CAWO,SAASC,CAAAA,CAAuBD,CAAAA,CAAyC,CAC/E,IAAME,CAAAA,CAAW,OAAO,MAAA,CAAOC,mBAAa,EAAE,QAAA,CAASH,CAAAA,CAAI,QAAQ,CAAA,CAChEA,EAAI,QAAA,CAAA,UAAA,CAEP,OAAO,IAAII,mBAAAA,CAAYF,EAAU,CAChC,IAAA,CAAMF,CAAAA,CAAI,IAAA,CACV,QAASA,CAAAA,CAAI,OAAA,CACb,SAAUA,CAAAA,CAAI,QAAA,CACd,MAAOA,CAAAA,CAAI,KAAA,CACX,UAAA,CAAYA,CAAAA,CAAI,WAChB,WAAA,CAAaA,CAAAA,CAAI,WAAA,CACjB,IAAA,CAAMA,EAAI,IACX,CAAC,CACF,CAGO,SAASK,CAAAA,CAAqBC,CAAAA,CAA8B,CAClE,OAAOC,mBAAAA,CAAa,UACnBV,CAAAA,CAAiB,gBAAA,CACjBS,CAAAA,CACG,CAAA,oBAAA,EAAuBA,CAAM,CAAA,eAAA,CAAA,CAC7B,kCAAA,CACHA,CAAAA,CAAS,CAAE,OAAAA,CAAO,CAAA,CAAI,MACvB,CACD,CAGO,SAASE,CAAAA,EAAqC,CACpD,OAAOD,mBAAAA,CAAa,UACnBV,CAAAA,CAAiB,iBAAA,CACjB,gEACD,CACD,CAGO,SAASY,CAAAA,CAAqBC,CAAAA,CAA6B,CACjE,OAAOH,mBAAAA,CAAa,QAAA,CACnBV,CAAAA,CAAiB,uBAAA,CACjB,gCAAgCa,CAAM,CAAA,CAAA,CACtC,CAAE,MAAA,CAAAA,CAAO,CACV,CACD","file":"chunk-CDNJZBM3.cjs","sourcesContent":["/**\n * Structured errors for the off-main-thread worker harness, and the pair of\n * functions that carry an {@link EngineError} across a `postMessage` boundary.\n *\n * A worker runs in another thread, so a failure there cannot be `throw`n back\n * into the caller's stack. It has to be encoded, posted, and rebuilt on the\n * main side, and it must arrive as a real structured error rather than a lost\n * promise or an opaque string. {@link serializeEngineError} projects an\n * `EngineError` onto a plain, clone-safe object; {@link deserializeEngineError}\n * rebuilds one from that object so the main-side `catch` sees the same\n * `code`/`category`/`message` it would have seen in-process.\n */\n\nimport { EngineError, ErrorCategory, ErrorFactory, type SourceSpan } from \"./EngineError\";\n\n/**\n * Codes the worker harness owns, co-located here rather than unioned into the\n * core catalog, matching the convention `errors/ErrorCode.ts` documents for a\n * domain that keeps its own small code object.\n */\nexport const WorkerErrorCodes = {\n\t/** The caller aborted the request through its `AbortSignal`. */\n\tWORKER_CANCELLED: \"WORKER_CANCELLED\",\n\t/** The worker engine was torn down while a request was still in flight. */\n\tWORKER_TERMINATED: \"WORKER_TERMINATED\",\n\t/** The transport failed or the worker exited before answering. */\n\tWORKER_TRANSPORT_FAILED: \"WORKER_TRANSPORT_FAILED\",\n\t/** A request named a method the runtime does not expose. */\n\tWORKER_UNKNOWN_METHOD: \"WORKER_UNKNOWN_METHOD\",\n\t/** A request arrived before the runtime finished building its engine. */\n\tWORKER_NOT_INITIALISED: \"WORKER_NOT_INITIALISED\",\n\t/** An init named a package the runtime could not resolve. */\n\tWORKER_UNKNOWN_PACKAGE: \"WORKER_UNKNOWN_PACKAGE\",\n} as const;\n\n/**\n * A structured error flattened for transport.\n *\n * Every field is a string, a boolean, or an object of numbers, so the whole\n * thing survives both `structuredClone` (what `postMessage` uses) and\n * `JSON.stringify` (what a host may log). `context`, `cause` and `timestamp`\n * are deliberately dropped rather than posted: a context can hold a value that\n * is not clone-safe, and none of the three is part of what a main-side handler\n * branches on.\n */\nexport interface SerializedEngineError {\n\tname: string;\n\tcategory: ErrorCategory;\n\tcode: string;\n\tmessage: string;\n\texpected?: string;\n\tfound?: string;\n\tsuggestion?: string;\n\trecoverable: boolean;\n\tspan?: SourceSpan;\n}\n\n/** Flatten an {@link EngineError} into a clone-safe {@link SerializedEngineError}. */\nexport function serializeEngineError(error: EngineError): SerializedEngineError {\n\tconst dto: SerializedEngineError = {\n\t\tname: error.name,\n\t\tcategory: error.category,\n\t\tcode: error.code,\n\t\tmessage: error.message,\n\t\trecoverable: error.recoverable,\n\t};\n\t// Only the optional string fields that were actually set cross the wire, so\n\t// a rebuilt error has `undefined` exactly where the original did rather than\n\t// an explicit `undefined` property a deep-equal would trip on.\n\tif (error.expected !== undefined) dto.expected = error.expected;\n\tif (error.found !== undefined) dto.found = error.found;\n\tif (error.suggestion !== undefined) dto.suggestion = error.suggestion;\n\t// A span is character offsets (plain numbers), so it is safe to carry and\n\t// useful for a host that highlights the failing range.\n\tif (error.span !== undefined) dto.span = error.span;\n\treturn dto;\n}\n\n/**\n * Rebuild an {@link EngineError} from its transported form.\n *\n * The category string round-trips straight back into the `ErrorCategory` enum\n * (its members ARE their own string values), so a main-side `catch` reads the\n * same category the worker raised. A malformed category (a message that was not\n * produced by {@link serializeEngineError}) falls back to `INTERNAL` rather than\n * constructing an error with an invalid category.\n */\nexport function deserializeEngineError(dto: SerializedEngineError): EngineError {\n\tconst category = Object.values(ErrorCategory).includes(dto.category)\n\t\t? dto.category\n\t\t: ErrorCategory.INTERNAL;\n\treturn new EngineError(category, {\n\t\tcode: dto.code,\n\t\tmessage: dto.message,\n\t\texpected: dto.expected,\n\t\tfound: dto.found,\n\t\tsuggestion: dto.suggestion,\n\t\trecoverable: dto.recoverable,\n\t\tspan: dto.span,\n\t});\n}\n\n/** The error a request rejects with when its caller aborts through an `AbortSignal`. */\nexport function workerCancelledError(method?: string): EngineError {\n\treturn ErrorFactory.execution(\n\t\tWorkerErrorCodes.WORKER_CANCELLED,\n\t\tmethod\n\t\t\t? `The worker request \"${method}\" was cancelled`\n\t\t\t: \"The worker request was cancelled\",\n\t\tmethod ? { method } : undefined,\n\t);\n}\n\n/** The error every pending request rejects with when the worker engine is terminated. */\nexport function workerTerminatedError(): EngineError {\n\treturn ErrorFactory.execution(\n\t\tWorkerErrorCodes.WORKER_TERMINATED,\n\t\t\"The worker engine was terminated before this request completed\",\n\t);\n}\n\n/** The error a request rejects with when the transport fails or the worker exits early. */\nexport function workerTransportError(detail: string): EngineError {\n\treturn ErrorFactory.external(\n\t\tWorkerErrorCodes.WORKER_TRANSPORT_FAILED,\n\t\t`The worker transport failed: ${detail}`,\n\t\t{ detail },\n\t);\n}\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var chunkEFJCC6FJ_cjs=require('./chunk-EFJCC6FJ.cjs'),
|
|
2
|
-
`),r=new Array(n.length);for(let s=0;s<n.length;s++){let i=this.nextLineId++;r[s]=i,this.lines.set(i,{lineId:i,textHash:chunkEFJCC6FJ_cjs.a(n[s]),text:n[s],expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:n[s].trim().length===0,inlineSolveCount:0});}this.orderTree.replaceAll(r);for(let s of r)this.dirtyLineIds.add(s);}applyChanges(e){let t=[],n=[],r=[...e].sort((s,i)=>i.startLine-s.startLine);for(let s of r){let i=s.startLine-1,a=[];for(let o of s.insertLines){let c=this.nextLineId++;a.push(c),t.push(c),this.lines.set(c,{lineId:c,textHash:chunkEFJCC6FJ_cjs.a(o),text:o,expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:o.trim().length===0,inlineSolveCount:0});}for(let o of a)this.dirtyLineIds.add(o);let l=this.orderTree.spliceAt(i,s.deleteCount,a);for(let o of l)n.push(o),this.lines.delete(o),this.dirtyLineIds.delete(o);}return this._positionCache=null,{inserted:t,removed:n}}insertLines(e,t){let n={startLine:e,deleteCount:0,insertLines:t};return this.applyChanges([n]).inserted}deleteLines(e,t){let n={startLine:e,deleteCount:t-e+1,insertLines:[]};return this.applyChanges([n]).removed}editLine(e,t){let n=this.getLineAt(e);if(!n)return false;let r=chunkEFJCC6FJ_cjs.a(t);return r===n.textHash?false:(n.text=t,n.textHash=r,n.expressions=[],n.bytecodes=[],n.results=[],n.result=null,n.inlineSolveCount=0,n.dirty=true,this.dirtyLineIds.add(n.lineId),n.isEmpty=t.trim().length===0,true)}getLineAt(e){let t=e-1,n=this.orderTree.getAt(t);if(n!==void 0)return this.lines.get(n)}getLinePosition(e){if(this._positionCache)return this._positionCache.get(e)??-1;this._positionCache=new Map;let t=1;for(let n of this.orderTree)this._positionCache.set(n,t++);return this._positionCache.get(e)??-1}getVisibleLines(e,t){let n=this.orderTree.getRange(e-1,t-1),r=[];for(let s of n){let i=this.lines.get(s);i&&r.push(i);}return r}getAllLines(){return this.getVisibleLines(1,this.lineCount)}getLineById(e){return this.lines.get(e)}getDirtyLines(){let e=[];for(let t of this.lines.values())t.dirty&&e.push(t);return e}hasAnyDirtyLineBefore(e){for(let t of this.dirtyLineIds){let n=this.getLinePosition(t);if(n>=1&&n<e)return true}return false}hasAnyDirtyVariableDefLineBefore(e){for(let t of this.dirtyLineIds){let n=this.lines.get(t);if(!n||!n.isVariableDef)continue;let r=this.getLinePosition(t);if(r>=1&&r<e)return true}return false}get dirtyCount(){return this.dirtyLineIds.size}isBytecodeValid(e,t){let n=this.lines.get(e);return n!==void 0&&n.textHash===t}markClean(e){let t=this.lines.get(e);t&&(t.dirty=false,this.dirtyLineIds.delete(e));}markDirtyByLineNumber(e){let t=this.getLineAt(e);t&&(t.dirty=true,this.dirtyLineIds.add(t.lineId));}markDirty(e){let t=this.lines.get(e);t&&(t.dirty=true,this.dirtyLineIds.add(e));}invalidateAll(){for(let e of this.lines.values())e.dirty=true;this.dirtyLineIds=new Set(this.lines.keys());}updateLineResult(e,t,n,r,s,i,a,l=0){let o=this.lines.get(e);o&&(o.results=t,o.result=t[0]?.[0]??null,o.bytecodes=n,o.expressions=r,o.reads=s,o.writes=i,o.isVariableDef=a,o.inlineSolveCount=l,o.dirty=false,this.dirtyLineIds.delete(e));}updateLineCompiled(e,t,n,r,s,i,a=0){let l=this.lines.get(e);l&&(l.expressions=t,l.bytecodes=n,l.reads=r,l.writes=s,l.isVariableDef=i,l.inlineSolveCount=a);}get lineCount(){return this.orderTree.length}get isEmpty(){return this.orderTree.isEmpty}*[Symbol.iterator](){for(let e of this.orderTree){let t=this.lines.get(e);t&&(yield t);}}clear(){this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.nextLineId=1;}toJSON(){return {lineCount:this.lineCount,lines:this.getAllLines().map(e=>({lineId:e.lineId,text:e.text.substring(0,80),textHash:e.textHash,dirty:e.dirty,isVariableDef:e.isVariableDef,isEmpty:e.isEmpty,hasBytecode:e.bytecodes.length>0,hasResult:e.results.length>0,inlineSolveCount:e.inlineSolveCount,reads:e.reads,writes:e.writes}))}}};var A=class{constructor(){this.worker=null;this.nextId=1;this.pending=new Map;}ensureWorker(){return this.worker?this.worker:(this.worker=chunkKVLJDOZ7_cjs.g(),this.worker.onmessage=e=>{let t=e.data;if(!t||t.type!=="COMPILE_RESULT")return;let n=this.pending.get(t.id);if(!n)return;this.pending.delete(t.id);let r=[];for(let s of t.results)r.push(this.reconstructResult(s));n.resolve(r);},this.worker.onerror=e=>{for(let[t,n]of this.pending)n.reject(new Error(`Compilation worker error: ${e.message}`)),this.pending.delete(t);},this.worker)}async compileBatch(e){if(e.length===0)return [];let t=this.ensureWorker(),n=this.nextId++;return new Promise((r,s)=>{this.pending.set(n,{resolve:r,reject:s}),t.postMessage({type:"COMPILE_BATCH",id:n,items:e});})}storeResults(e,t){let n=new Map;for(let i of e){if(i.error)continue;let a=t.getLineById(i.lineId);if(!a||a.textHash!==i.compiledAgainstHash)continue;let l=n.get(i.lineId);l||(l={bytecodes:[],reads:new Set,writes:new Set,isVariableDef:false,expressions:a.expressions.length>0?[...a.expressions]:[],textHash:i.compiledAgainstHash},n.set(i.lineId,l)),l.bytecodes.push(i.program);for(let o of i.reads)l.reads.add(o);for(let o of i.writes)l.writes.add(o);i.isVariableDef&&(l.isVariableDef=true);}let s=0;for(let[i,a]of n){if(a.bytecodes.length===0)continue;let o=t.getLineById(i)?.inlineSolveCount??0;t.updateLineCompiled(i,a.expressions,a.bytecodes,[...a.reads],[...a.writes],a.isVariableDef,o),s+=a.bytecodes.length;}return s}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.pending.clear());}get isActive(){return this.worker!==null}reconstructResult(e){if(e.error)return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:{opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false},reads:[],writes:[],isVariableDef:false,error:e.error};let t=e.opcodesLength>0?new Uint8Array(e.opcodesBuffer,0,e.opcodesLength):new Uint8Array(0),n=e.numbersLength>0?new Float64Array(e.numbersBuffer,0,e.numbersLength):new Float64Array(0),r={opcodes:t,numbers:n,strings:e.strings,hasAsync:false};return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:r,reads:e.reads,writes:e.writes,isVariableDef:e.isVariableDef,error:null}}};var U=128,k=3,Z=6,Q=2,X=k,H=class u{constructor(){this.lastViewportStart=null;this.savedDirection=null;this.pageAccess=new Map;this.accessSeq=0;}static pageForLine(e){return Math.floor((e-1)/U)}static pageRange(e,t){return {startLine:e*U+1,endLine:Math.min((e+1)*U,t)}}detectDirection(e){return this.lastViewportStart===null?null:e.startLine>this.lastViewportStart?"down":e.startLine<this.lastViewportStart?"up":null}maintainAfterEval(e,t){this.savedDirection=this.detectDirection(e),this.lastViewportStart=e.startLine;let n=t.lineCount,r=u.pageForLine(e.startLine),s=u.pageForLine(e.endLine),i=u.pageForLine(n),a=Math.max(0,r-k),l=Math.min(i,s+k),o=Math.max(0,r-Z),c=Math.min(i,s+Z);for(let h=a;h<=l;h++)this.touchPage(h);for(let h=o;h<=c;h++)h>=a&&h<=l||this.evictPageResults(h,t,n);let d=o-1,p=Math.max(0,d-X+1);for(let h=p;h<=d;h++)this.evictPageBytecode(h,t,n);let f=c+1,g=Math.min(i,f+X-1);for(let h=f;h<=g;h++)this.evictPageBytecode(h,t,n);}getPreloadTargets(e,t){let n=this.savedDirection;if(!n)return [];let r=[],s=u.pageForLine(e.endLine),i=u.pageForLine(e.startLine),a=u.pageForLine(t.lineCount),l=[];if(n==="down"){let o=s+k+1,c=Math.min(o+Q-1,a);for(let d=o;d<=c&&d<=a;d++)l.push(d);}else {let o=i-k-1;for(let c=o;c>o-Q&&c>=0;c--)l.push(c);}for(let o of l){let c=u.pageRange(o,t.lineCount);for(let d=c.startLine;d<=c.endLine;d++){let p=t.getLineAt(d);if(p&&p.dirty&&!(p.bytecodes.length>0&&!p.isVariableDef)&&!p.isEmpty)if(p.expressions.length>0)for(let f of p.expressions)f.trim()&&r.push({lineId:p.lineId,expression:f,textHash:p.textHash});else {let f=chunkKRXO3MOW_cjs.c.findInlineSolves(p.text);if(f.length>0)for(let g of f)g.expression.trim()&&r.push({lineId:p.lineId,expression:g.expression,textHash:p.textHash});else {let g=p.text.trim();g&&r.push({lineId:p.lineId,expression:g,textHash:p.textHash});}}}}return r}clear(){this.pageAccess.clear(),this.accessSeq=0,this.lastViewportStart=null,this.savedDirection=null;}touchPage(e){this.pageAccess.set(e,++this.accessSeq);}evictPageResults(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);i&&!i.isVariableDef&&i.results.length>0&&(i.results=[],i.result=null);}}evictPageBytecode(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);!i||i.isVariableDef||(i.bytecodes.length>0||i.results.length>0)&&(i.bytecodes=[],i.results=[],i.result=null,t.markDirty(i.lineId));}}};var Y=(r=>(r[r.Tier1=1]="Tier1",r[r.Tier2=2]="Tier2",r[r.Tier3=3]="Tier3",r[r.Skipped=0]="Skipped",r))(Y||{}),w=class{constructor(e,t,n){this.compilationWorker=null;this.globalUnsubscribe=null;this.doc=e,this.engine=t,this.dag=t.getDag(),this.checkpointer=n??null,this.pageManager=new H,this.engine.setDocumentModel(this.doc),this.globalUnsubscribe=chunkXDXIPVZB_cjs.J.subscribe(r=>{for(let s of this.dag.getAffectedLines(chunkXDXIPVZB_cjs.K(r)))this.doc.markDirtyByLineNumber(s);});}evaluate(e,t){this.engine.setKeystrokeSignal(t??null),chunk75JLWK4L_cjs.h();try{this.reseedAccumulators();let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(e.endLine,i);for(let l=1;l<=a;l++){let o=this.doc.getLineAt(l);if(!o){s.skipped++;continue}let c=l>=e.startLine&&l<=e.endLine,d=this.evaluateSingleLine(o,l,c);n.push(d),d.tier===1?s.tier1++:d.tier===2?s.tier2++:d.tier===3?s.tier3++:s.skipped++,d.results&&c&&r.set(l,d.results.flat());}return this.pageManager.maintainAfterEval(e,this.doc),{lines:n,resultMap:r,tierCounts:s}}finally{this.engine.setKeystrokeSignal(null),chunk75JLWK4L_cjs.i();}}backgroundCompile(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef)continue;let a=this.evaluateSingleLine(i,s,false);t.push(a);}return t}dispatchBackgroundCompiles(e){let t=this.collectInvisibleCompileTargets(e);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}terminateWorker(){this.compilationWorker&&(this.compilationWorker.terminate(),this.compilationWorker=null),this.globalUnsubscribe&&(this.globalUnsubscribe(),this.globalUnsubscribe=null);}getDoc(){return this.doc}evaluateAll(e){let t={startLine:1,endLine:this.doc.lineCount};return this.evaluate(t,e)}setViewport(e,t){if(this.engine.setKeystrokeSignal(t??null),e.startLine>1&&this.hasDirtyLinesBefore(e.startLine))return this.checkpointer?.clear(),this.evaluate(e,t);this.pageManager.maintainAfterEval(e,this.doc),this.preloadNextPages(e),this.restoreTo(e.startLine-1),chunk75JLWK4L_cjs.h();try{return this.collectEvalResults(e.startLine,e.endLine)}finally{this.engine.setKeystrokeSignal(null),chunk75JLWK4L_cjs.i();}}applyTransaction(e){let t=new Set;for(let s of e)for(let i=0;i<s.deleteCount;i++){let a=s.startLine+i,l=this.dag.getWrites(a);for(let o of l)t.add(o);this.dag.removeLine(a),this.engine.getLineCache().removeAllForLine(a);}let n=new Set;for(let s of t){let i=this.dag.getAffectedLines(s);for(let a of i){let l=this.doc.getLineAt(a);l&&n.add(l.lineId);}}let r=this.doc.applyChanges(e);this.checkpointer?.clear();for(let s of n)this.doc.markDirty(s);return this.dag.clear(),{inserted:r.inserted,removed:r.removed}}reseedAccumulators(){let e=this.engine.resetAccumulators();if(e.size===0)return;let t=this.doc.lineCount;for(let n=1;n<=t;n++){let r=this.dag.getWrites(n);if(r.size!==0){for(let s of r)if(e.has(s)){this.doc.markDirtyByLineNumber(n);break}}}}collectEvalResults(e,t){let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(t,i);for(let l=e;l<=a;l++){let o=this.doc.getLineAt(l);if(!o)continue;let c=this.evaluateSingleLine(o,l,true);n.push(c),c.tier===1?s.tier1++:c.tier===2?s.tier2++:c.tier===3?s.tier3++:s.skipped++,c.results&&r.set(l,c.results.flat());}return {lines:n,resultMap:r,tierCounts:s}}hasDirtyLinesBefore(e){return this.doc.hasAnyDirtyVariableDefLineBefore(e)}evaluateSingleLine(e,t,n){let r={lineId:e.lineId,lineNumber:t};if(e.isEmpty||chunkKVLJDOZ7_cjs.l(e.text))return e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null};let{expressions:s,inlineSolveCount:i}=this.extractExpressions(e);return s.length===0?(e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null}):e.dirty?n?this.evaluateTier1(e,t,s,i,r):e.bytecodes.length>0&&e.bytecodes.length===s.length&&!e.isVariableDef?{...r,tier:0,result:null,error:null}:this.evaluateTier3(e,t,s,i,r):n&&e.bytecodes.length>0?this.evaluateTier2(e,t,r):{...r,tier:0,result:null,error:null}}evaluateTier1(e,t,n,r,s){let i=[],a=[],l=new Set,o=new Set,c=false,d=null,p=null,f=false,g=false;for(let y of n){if(!y.trim())continue;let b=null,L;try{let m=this.engine.evaluateLine(t,y);b=[m],d=m,L=this.engine.getLineCache().get(t,y);}catch(m){let x=m instanceof Error?m.message:String(m);p||(p=x),f=true,b=null;}if(b&&b.some(m=>m.type===12)&&(g=true),b?i.push(b):i.push([chunk75JLWK4L_cjs.P("eval_failed",p??"unknown error")]),L){a.push(L.bytecode);for(let m of L.readVariables)l.add(m);L.writeVariable&&(o.add(L.writeVariable),c=true);}else try{let{program:m,reads:x,writes:E}=this.engine.compileExpression(y);a.push(m);for(let S of x)l.add(S);for(let S of E)o.add(S);E.length>0&&(c=!0);}catch(m){if(a.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),m instanceof chunkCO2BI6WL_cjs.b&&m.context){let x=m.context.reads,E=m.context.writes;if(Array.isArray(x))for(let S of x)l.add(S);if(Array.isArray(E))for(let S of E)o.add(S);}}}let h=[...l],v=[...o];return f||g?(this.doc.updateLineCompiled(e.lineId,n,a,h,v,c,r),e.results=i,e.result=i[0]?.[0]??null,e.inlineSolveCount=r,e.expressions=n):this.doc.updateLineResult(e.lineId,i,a,n,h,v,c,r),this.dag.registerLine(t,h,v),this.checkpointer&&v.length>0&&!f&&!g&&this.checkpointer.snapshot(t,e.lineId,v),{...s,tier:1,result:d,results:i,error:p}}evaluateTier2(e,t,n){if(e.bytecodes.length===0)return {...n,tier:0,result:null,error:null};let r=[],s=null,i=null,a=false;for(let l of e.bytecodes)if(l.opcodes.length!==0)try{let o=this.engine.executeCached(l,t);s=o,r.push([o]);}catch(o){let c=o instanceof Error?o.message:String(o);i||(i=c),a=true,r.push([chunk75JLWK4L_cjs.P("exec_failed",c)]);}return this.dag.registerLine(t,e.reads,e.writes),e.results=r,e.result=r[0]?.[0]??null,a&&this.doc.markDirty(e.lineId),{...n,tier:2,result:s,results:r,error:i}}evaluateTier3(e,t,n,r,s){let i=[],a=new Set,l=new Set,o=false,c=null,d=null,p=false,f=false;for(let v of n)if(v.trim())try{let{program:y,reads:b,writes:L}=this.engine.compileExpression(v);i.push(y);for(let m of b)a.add(m);for(let m of L)l.add(m);L.length>0&&(o=!0),L.length>0&&y.opcodes.length>0&&(c=this.engine.executeCached(y,t),c&&c.type===12&&(f=!0));}catch(y){let b=y instanceof Error?y.message:String(y);d||(d=b),p=true,i.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false});}let g=[...a],h=[...l];return this.doc.updateLineCompiled(e.lineId,n,i,g,h,o,r),this.dag.registerLine(t,g,h),o&&c&&!p&&!f&&(e.results=[[c]],e.result=c,this.doc.markClean(e.lineId),this.checkpointer&&this.checkpointer.snapshot(t,e.lineId,h)),{...s,tier:3,result:c,results:o&&c&&!p&&!f?[[c]]:void 0,error:d}}restoreTo(e){this.checkpointer&&this.checkpointer.restoreTo(e);}getCheckpointer(){return this.checkpointer}getPageManager(){return this.pageManager}preloadNextPages(e){let t=this.pageManager.getPreloadTargets(e,this.doc);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}collectInvisibleCompileTargets(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef||i.isEmpty||chunkKVLJDOZ7_cjs.l(i.text))continue;let{expressions:a}=this.extractExpressions(i);if(a.length!==0)for(let l of a)l.trim()&&t.push({lineId:i.lineId,expression:l,textHash:i.textHash});}return t}extractExpressions(e){if(e.expressions.length>0)return {expressions:e.expressions,inlineSolveCount:e.inlineSolveCount};let t=e.text.trim();if(t.length===0)return {expressions:[],inlineSolveCount:0};let n=chunkKRXO3MOW_cjs.c.findInlineSolves(e.text);return n.length>0?{expressions:n.map(r=>r.expression),inlineSolveCount:n.length}:{expressions:[t],inlineSolveCount:0}}};function ee(u){return typeof u.unit=="string"?u.unit:String(u.value)}function ie(u,e,t={inputType:"markdown"}){let n=u.getDocumentModel(),r=new R;r.setDocument(e);let s=new w(r,u);try{let i=r.lineCount;s.evaluate({startLine:1,endLine:i});let a=[],l=[],o=0;for(let c=1;c<=i;c++){let d=r.getLineAt(c),p=d.text,f=o,g=o+p.length;o=g+1;let h=d.inlineSolveCount>0,v=[],y=null,b=null;d.isEmpty||(h?v=chunkKVLJDOZ7_cjs.m(p,c).map((L,m)=>{let x=d.results[m]?.[0]??null;if(x&&x.type===13){let E=ee(x);return l.push(`Line ${c}: ${E}`),{...L,result:null,error:E}}return {...L,result:x,error:null}}):(y=d.expressions[0]??null,b=d.result??null,b&&b.type===13&&l.push(`Line ${c}: ${ee(b)}`))),a.push({lineNumber:c,text:p,startPosition:f,endPosition:g,isEmpty:d.isEmpty,hasInlineSolves:h,inlineSolves:v,expression:y,error:null,result:b});}return {lines:a,totalLines:i,errors:l}}finally{s.terminateWorker(),u.setDocumentModel(n);}}exports.a=R;exports.b=Y;exports.c=w;exports.d=ie;//# sourceMappingURL=chunk-YAONCEAW.cjs.map
|
|
3
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
'use strict';var chunkEFJCC6FJ_cjs=require('./chunk-EFJCC6FJ.cjs'),chunkRECRD45C_cjs=require('./chunk-RECRD45C.cjs'),chunkUURM7P3P_cjs=require('./chunk-UURM7P3P.cjs'),chunkAUOE7MFI_cjs=require('./chunk-AUOE7MFI.cjs'),chunkDA7M6H63_cjs=require('./chunk-DA7M6H63.cjs'),chunkUY3ID6JF_cjs=require('./chunk-UY3ID6JF.cjs'),chunkIHAZL4EF_cjs=require('./chunk-IHAZL4EF.cjs'),chunkELQQKZN3_cjs=require('./chunk-ELQQKZN3.cjs');var P=class{constructor(){this.root=null;}get length(){return this.root?this.root.size:0}get isEmpty(){return this.root===null}getAt(e){if(!(e<0||e>=(this.root?.size??0)))return this.nodeAt(this.root,e).lineId}insertAt(e,t){let[n,r]=I(this.root,e);this.root=C(C(n,te(t)),r);}deleteAt(e){if(e<0||e>=(this.root?.size??0))return;let[t,n]=I(this.root,e),[r,s]=I(n,1),i=r?r.lineId:void 0;return this.root=C(t,s),i}spliceAt(e,t,n){let r=Math.max(0,e),s=Math.min(Math.max(0,t),(this.root?.size??0)-r),[i,a]=I(this.root,r),[l,o]=I(a,s),c=ne(l),d=B(n,0,n.length);return this.root=C(C(i,d),o),c}replaceAll(e){this.root=B(e,0,e.length);}getRange(e,t){let n=Math.max(0,e),r=Math.min((this.root?.size??0)-1,t);if(n>r)return [];let s=[];return this.collectRange(this.root,n,r,0,s),s}clear(){this.root=null;}*[Symbol.iterator](){yield*this.inOrder(this.root);}*inOrder(e){e&&(yield*this.inOrder(e.left),yield e.lineId,yield*this.inOrder(e.right));}nodeAt(e,t){let n=e.left?e.left.size:0;return t<n?this.nodeAt(e.left,t):t===n?e:this.nodeAt(e.right,t-n-1)}collectRange(e,t,n,r,s){if(!e)return;let i=e.left?e.left.size:0,a=r+i;a>t&&e.left&&this.collectRange(e.left,t,n,r,s),a>=t&&a<=n&&s.push(e.lineId),a<n&&e.right&&this.collectRange(e.right,t,n,a+1,s);}};function te(u){return {lineId:u,size:1,priority:Math.random(),left:null,right:null}}function T(u){u.size=1+(u.left?u.left.size:0)+(u.right?u.right.size:0);}function C(u,e){return u?e?u.priority>e.priority?(u.right=C(u.right,e),T(u),u):(e.left=C(u,e.left),T(e),e):u:e}function I(u,e){if(!u)return [null,null];let t=u.left?u.left.size:0;if(e<=t){let[n,r]=I(u.left,e);return u.left=r,T(u),[n,u]}else {let[n,r]=I(u.right,e-t-1);return u.right=n,T(u),[u,r]}}function ne(u){let e=[];return F(u,e),e}function F(u,e){u&&(F(u.left,e),e.push(u.lineId),F(u.right,e));}function B(u,e,t){if(e>=t)return null;let n=Math.floor((e+t)/2),r=re(n);return {lineId:u[n],size:t-e,priority:r,left:B(u,e,n),right:B(u,n+1,t)}}function re(u){let e=u;return e=(e>>16^e)*73244475,e=(e>>16^e)*73244475,e=e>>16^e,e/4294967295}var R=class{constructor(e=chunkUY3ID6JF_cjs.b.performance.maxDocumentLines){this.lines=new Map;this.orderTree=new P;this.nextLineId=1;this._positionCache=null;this.dirtyLineIds=new Set;this.maxLines=e;}setDocument(e){if(chunkUURM7P3P_cjs.b(e,this.maxLines)>this.maxLines)throw chunkELQQKZN3_cjs.c.execution("DOCUMENT_TOO_LARGE",`This document has more than ${this.maxLines.toLocaleString("en-US")} lines, which is the most the engine will hold at once`,{maxLines:this.maxLines});this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.dirtyLineIds.clear(),this.nextLineId=1;let n=e.split(`
|
|
2
|
+
`),r=new Array(n.length);for(let s=0;s<n.length;s++){let i=this.nextLineId++;r[s]=i,this.lines.set(i,{lineId:i,textHash:chunkEFJCC6FJ_cjs.a(n[s]),text:n[s],expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:n[s].trim().length===0,inlineSolveCount:0});}this.orderTree.replaceAll(r);for(let s of r)this.dirtyLineIds.add(s);}applyChanges(e){let t=[],n=[],r=[...e].sort((s,i)=>i.startLine-s.startLine);for(let s of r){let i=s.startLine-1,a=[];for(let o of s.insertLines){let c=this.nextLineId++;a.push(c),t.push(c),this.lines.set(c,{lineId:c,textHash:chunkEFJCC6FJ_cjs.a(o),text:o,expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:o.trim().length===0,inlineSolveCount:0});}for(let o of a)this.dirtyLineIds.add(o);let l=this.orderTree.spliceAt(i,s.deleteCount,a);for(let o of l)n.push(o),this.lines.delete(o),this.dirtyLineIds.delete(o);}return this._positionCache=null,{inserted:t,removed:n}}insertLines(e,t){let n={startLine:e,deleteCount:0,insertLines:t};return this.applyChanges([n]).inserted}deleteLines(e,t){let n={startLine:e,deleteCount:t-e+1,insertLines:[]};return this.applyChanges([n]).removed}editLine(e,t){let n=this.getLineAt(e);if(!n)return false;let r=chunkEFJCC6FJ_cjs.a(t);return r===n.textHash?false:(n.text=t,n.textHash=r,n.expressions=[],n.bytecodes=[],n.results=[],n.result=null,n.inlineSolveCount=0,n.dirty=true,this.dirtyLineIds.add(n.lineId),n.isEmpty=t.trim().length===0,true)}getLineAt(e){let t=e-1,n=this.orderTree.getAt(t);if(n!==void 0)return this.lines.get(n)}getLinePosition(e){if(this._positionCache)return this._positionCache.get(e)??-1;this._positionCache=new Map;let t=1;for(let n of this.orderTree)this._positionCache.set(n,t++);return this._positionCache.get(e)??-1}getVisibleLines(e,t){let n=this.orderTree.getRange(e-1,t-1),r=[];for(let s of n){let i=this.lines.get(s);i&&r.push(i);}return r}getAllLines(){return this.getVisibleLines(1,this.lineCount)}getLineById(e){return this.lines.get(e)}getDirtyLines(){let e=[];for(let t of this.lines.values())t.dirty&&e.push(t);return e}hasAnyDirtyLineBefore(e){for(let t of this.dirtyLineIds){let n=this.getLinePosition(t);if(n>=1&&n<e)return true}return false}hasAnyDirtyVariableDefLineBefore(e){for(let t of this.dirtyLineIds){let n=this.lines.get(t);if(!n||!n.isVariableDef)continue;let r=this.getLinePosition(t);if(r>=1&&r<e)return true}return false}get dirtyCount(){return this.dirtyLineIds.size}isBytecodeValid(e,t){let n=this.lines.get(e);return n!==void 0&&n.textHash===t}markClean(e){let t=this.lines.get(e);t&&(t.dirty=false,this.dirtyLineIds.delete(e));}markDirtyByLineNumber(e){let t=this.getLineAt(e);t&&(t.dirty=true,this.dirtyLineIds.add(t.lineId));}markDirty(e){let t=this.lines.get(e);t&&(t.dirty=true,this.dirtyLineIds.add(e));}invalidateAll(){for(let e of this.lines.values())e.dirty=true;this.dirtyLineIds=new Set(this.lines.keys());}updateLineResult(e,t,n,r,s,i,a,l=0){let o=this.lines.get(e);o&&(o.results=t,o.result=t[0]?.[0]??null,o.bytecodes=n,o.expressions=r,o.reads=s,o.writes=i,o.isVariableDef=a,o.inlineSolveCount=l,o.dirty=false,this.dirtyLineIds.delete(e));}updateLineCompiled(e,t,n,r,s,i,a=0){let l=this.lines.get(e);l&&(l.expressions=t,l.bytecodes=n,l.reads=r,l.writes=s,l.isVariableDef=i,l.inlineSolveCount=a);}get lineCount(){return this.orderTree.length}get isEmpty(){return this.orderTree.isEmpty}*[Symbol.iterator](){for(let e of this.orderTree){let t=this.lines.get(e);t&&(yield t);}}clear(){this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.nextLineId=1;}toJSON(){return {lineCount:this.lineCount,lines:this.getAllLines().map(e=>({lineId:e.lineId,text:e.text.substring(0,80),textHash:e.textHash,dirty:e.dirty,isVariableDef:e.isVariableDef,isEmpty:e.isEmpty,hasBytecode:e.bytecodes.length>0,hasResult:e.results.length>0,inlineSolveCount:e.inlineSolveCount,reads:e.reads,writes:e.writes}))}}};var A=class{constructor(){this.worker=null;this.nextId=1;this.pending=new Map;}ensureWorker(){return this.worker?this.worker:(this.worker=chunkRECRD45C_cjs.g(),this.worker.onmessage=e=>{let t=e.data;if(!t||t.type!=="COMPILE_RESULT")return;let n=this.pending.get(t.id);if(!n)return;this.pending.delete(t.id);let r=[];for(let s of t.results)r.push(this.reconstructResult(s));n.resolve(r);},this.worker.onerror=e=>{for(let[t,n]of this.pending)n.reject(new Error(`Compilation worker error: ${e.message}`)),this.pending.delete(t);},this.worker)}async compileBatch(e){if(e.length===0)return [];let t=this.ensureWorker(),n=this.nextId++;return new Promise((r,s)=>{this.pending.set(n,{resolve:r,reject:s}),t.postMessage({type:"COMPILE_BATCH",id:n,items:e});})}storeResults(e,t){let n=new Map;for(let i of e){if(i.error)continue;let a=t.getLineById(i.lineId);if(!a||a.textHash!==i.compiledAgainstHash)continue;let l=n.get(i.lineId);l||(l={bytecodes:[],reads:new Set,writes:new Set,isVariableDef:false,expressions:a.expressions.length>0?[...a.expressions]:[],textHash:i.compiledAgainstHash},n.set(i.lineId,l)),l.bytecodes.push(i.program);for(let o of i.reads)l.reads.add(o);for(let o of i.writes)l.writes.add(o);i.isVariableDef&&(l.isVariableDef=true);}let s=0;for(let[i,a]of n){if(a.bytecodes.length===0)continue;let o=t.getLineById(i)?.inlineSolveCount??0;t.updateLineCompiled(i,a.expressions,a.bytecodes,[...a.reads],[...a.writes],a.isVariableDef,o),s+=a.bytecodes.length;}return s}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.pending.clear());}get isActive(){return this.worker!==null}reconstructResult(e){if(e.error)return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:{opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false},reads:[],writes:[],isVariableDef:false,error:e.error};let t=e.opcodesLength>0?new Uint8Array(e.opcodesBuffer,0,e.opcodesLength):new Uint8Array(0),n=e.numbersLength>0?new Float64Array(e.numbersBuffer,0,e.numbersLength):new Float64Array(0),r={opcodes:t,numbers:n,strings:e.strings,hasAsync:false};return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:r,reads:e.reads,writes:e.writes,isVariableDef:e.isVariableDef,error:null}}};var U=128,k=3,Z=6,Q=2,X=k,H=class u{constructor(){this.lastViewportStart=null;this.savedDirection=null;this.pageAccess=new Map;this.accessSeq=0;}static pageForLine(e){return Math.floor((e-1)/U)}static pageRange(e,t){return {startLine:e*U+1,endLine:Math.min((e+1)*U,t)}}detectDirection(e){return this.lastViewportStart===null?null:e.startLine>this.lastViewportStart?"down":e.startLine<this.lastViewportStart?"up":null}maintainAfterEval(e,t){this.savedDirection=this.detectDirection(e),this.lastViewportStart=e.startLine;let n=t.lineCount,r=u.pageForLine(e.startLine),s=u.pageForLine(e.endLine),i=u.pageForLine(n),a=Math.max(0,r-k),l=Math.min(i,s+k),o=Math.max(0,r-Z),c=Math.min(i,s+Z);for(let h=a;h<=l;h++)this.touchPage(h);for(let h=o;h<=c;h++)h>=a&&h<=l||this.evictPageResults(h,t,n);let d=o-1,p=Math.max(0,d-X+1);for(let h=p;h<=d;h++)this.evictPageBytecode(h,t,n);let f=c+1,g=Math.min(i,f+X-1);for(let h=f;h<=g;h++)this.evictPageBytecode(h,t,n);}getPreloadTargets(e,t){let n=this.savedDirection;if(!n)return [];let r=[],s=u.pageForLine(e.endLine),i=u.pageForLine(e.startLine),a=u.pageForLine(t.lineCount),l=[];if(n==="down"){let o=s+k+1,c=Math.min(o+Q-1,a);for(let d=o;d<=c&&d<=a;d++)l.push(d);}else {let o=i-k-1;for(let c=o;c>o-Q&&c>=0;c--)l.push(c);}for(let o of l){let c=u.pageRange(o,t.lineCount);for(let d=c.startLine;d<=c.endLine;d++){let p=t.getLineAt(d);if(p&&p.dirty&&!(p.bytecodes.length>0&&!p.isVariableDef)&&!p.isEmpty)if(p.expressions.length>0)for(let f of p.expressions)f.trim()&&r.push({lineId:p.lineId,expression:f,textHash:p.textHash});else {let f=chunkIHAZL4EF_cjs.c.findInlineSolves(p.text);if(f.length>0)for(let g of f)g.expression.trim()&&r.push({lineId:p.lineId,expression:g.expression,textHash:p.textHash});else {let g=p.text.trim();g&&r.push({lineId:p.lineId,expression:g,textHash:p.textHash});}}}}return r}clear(){this.pageAccess.clear(),this.accessSeq=0,this.lastViewportStart=null,this.savedDirection=null;}touchPage(e){this.pageAccess.set(e,++this.accessSeq);}evictPageResults(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);i&&!i.isVariableDef&&i.results.length>0&&(i.results=[],i.result=null);}}evictPageBytecode(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);!i||i.isVariableDef||(i.bytecodes.length>0||i.results.length>0)&&(i.bytecodes=[],i.results=[],i.result=null,t.markDirty(i.lineId));}}};var Y=(r=>(r[r.Tier1=1]="Tier1",r[r.Tier2=2]="Tier2",r[r.Tier3=3]="Tier3",r[r.Skipped=0]="Skipped",r))(Y||{}),w=class{constructor(e,t,n){this.compilationWorker=null;this.globalUnsubscribe=null;this.doc=e,this.engine=t,this.dag=t.getDag(),this.checkpointer=n??null,this.pageManager=new H,this.engine.setDocumentModel(this.doc),this.globalUnsubscribe=chunkAUOE7MFI_cjs.J.subscribe(r=>{for(let s of this.dag.getAffectedLines(chunkAUOE7MFI_cjs.K(r)))this.doc.markDirtyByLineNumber(s);});}evaluate(e,t){this.engine.setKeystrokeSignal(t??null),chunkDA7M6H63_cjs.h();try{this.reseedAccumulators();let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(e.endLine,i);for(let l=1;l<=a;l++){let o=this.doc.getLineAt(l);if(!o){s.skipped++;continue}let c=l>=e.startLine&&l<=e.endLine,d=this.evaluateSingleLine(o,l,c);n.push(d),d.tier===1?s.tier1++:d.tier===2?s.tier2++:d.tier===3?s.tier3++:s.skipped++,d.results&&c&&r.set(l,d.results.flat());}return this.pageManager.maintainAfterEval(e,this.doc),{lines:n,resultMap:r,tierCounts:s}}finally{this.engine.setKeystrokeSignal(null),chunkDA7M6H63_cjs.i();}}backgroundCompile(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef)continue;let a=this.evaluateSingleLine(i,s,false);t.push(a);}return t}dispatchBackgroundCompiles(e){let t=this.collectInvisibleCompileTargets(e);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}terminateWorker(){this.compilationWorker&&(this.compilationWorker.terminate(),this.compilationWorker=null),this.globalUnsubscribe&&(this.globalUnsubscribe(),this.globalUnsubscribe=null);}getDoc(){return this.doc}evaluateAll(e){let t={startLine:1,endLine:this.doc.lineCount};return this.evaluate(t,e)}setViewport(e,t){if(this.engine.setKeystrokeSignal(t??null),e.startLine>1&&this.hasDirtyLinesBefore(e.startLine))return this.checkpointer?.clear(),this.evaluate(e,t);this.pageManager.maintainAfterEval(e,this.doc),this.preloadNextPages(e),this.restoreTo(e.startLine-1),chunkDA7M6H63_cjs.h();try{return this.collectEvalResults(e.startLine,e.endLine)}finally{this.engine.setKeystrokeSignal(null),chunkDA7M6H63_cjs.i();}}applyTransaction(e){let t=new Set;for(let s of e)for(let i=0;i<s.deleteCount;i++){let a=s.startLine+i,l=this.dag.getWrites(a);for(let o of l)t.add(o);this.dag.removeLine(a),this.engine.getLineCache().removeAllForLine(a);}let n=new Set;for(let s of t){let i=this.dag.getAffectedLines(s);for(let a of i){let l=this.doc.getLineAt(a);l&&n.add(l.lineId);}}let r=this.doc.applyChanges(e);this.checkpointer?.clear();for(let s of n)this.doc.markDirty(s);return this.dag.clear(),{inserted:r.inserted,removed:r.removed}}reseedAccumulators(){let e=this.engine.resetAccumulators();if(e.size===0)return;let t=this.doc.lineCount;for(let n=1;n<=t;n++){let r=this.dag.getWrites(n);if(r.size!==0){for(let s of r)if(e.has(s)){this.doc.markDirtyByLineNumber(n);break}}}}collectEvalResults(e,t){let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(t,i);for(let l=e;l<=a;l++){let o=this.doc.getLineAt(l);if(!o)continue;let c=this.evaluateSingleLine(o,l,true);n.push(c),c.tier===1?s.tier1++:c.tier===2?s.tier2++:c.tier===3?s.tier3++:s.skipped++,c.results&&r.set(l,c.results.flat());}return {lines:n,resultMap:r,tierCounts:s}}hasDirtyLinesBefore(e){return this.doc.hasAnyDirtyVariableDefLineBefore(e)}evaluateSingleLine(e,t,n){let r={lineId:e.lineId,lineNumber:t};if(e.isEmpty||chunkRECRD45C_cjs.l(e.text))return e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null};let{expressions:s,inlineSolveCount:i}=this.extractExpressions(e);return s.length===0?(e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null}):e.dirty?n?this.evaluateTier1(e,t,s,i,r):e.bytecodes.length>0&&e.bytecodes.length===s.length&&!e.isVariableDef?{...r,tier:0,result:null,error:null}:this.evaluateTier3(e,t,s,i,r):n&&e.bytecodes.length>0?this.evaluateTier2(e,t,r):{...r,tier:0,result:null,error:null}}evaluateTier1(e,t,n,r,s){let i=[],a=[],l=new Set,o=new Set,c=false,d=null,p=null,f=false,g=false;for(let y of n){if(!y.trim())continue;let b=null,L;try{let m=this.engine.evaluateLine(t,y);b=[m],d=m,L=this.engine.getLineCache().get(t,y);}catch(m){let x=m instanceof Error?m.message:String(m);p||(p=x),f=true,b=null;}if(b&&b.some(m=>m.type===12)&&(g=true),b?i.push(b):i.push([chunkDA7M6H63_cjs.P("eval_failed",p??"unknown error")]),L){a.push(L.bytecode);for(let m of L.readVariables)l.add(m);L.writeVariable&&(o.add(L.writeVariable),c=true);}else try{let{program:m,reads:x,writes:E}=this.engine.compileExpression(y);a.push(m);for(let S of x)l.add(S);for(let S of E)o.add(S);E.length>0&&(c=!0);}catch(m){if(a.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),m instanceof chunkELQQKZN3_cjs.b&&m.context){let x=m.context.reads,E=m.context.writes;if(Array.isArray(x))for(let S of x)l.add(S);if(Array.isArray(E))for(let S of E)o.add(S);}}}let h=[...l],v=[...o];return f||g?(this.doc.updateLineCompiled(e.lineId,n,a,h,v,c,r),e.results=i,e.result=i[0]?.[0]??null,e.inlineSolveCount=r,e.expressions=n):this.doc.updateLineResult(e.lineId,i,a,n,h,v,c,r),this.dag.registerLine(t,h,v),this.checkpointer&&v.length>0&&!f&&!g&&this.checkpointer.snapshot(t,e.lineId,v),{...s,tier:1,result:d,results:i,error:p}}evaluateTier2(e,t,n){if(e.bytecodes.length===0)return {...n,tier:0,result:null,error:null};let r=[],s=null,i=null,a=false;for(let l of e.bytecodes)if(l.opcodes.length!==0)try{let o=this.engine.executeCached(l,t);s=o,r.push([o]);}catch(o){let c=o instanceof Error?o.message:String(o);i||(i=c),a=true,r.push([chunkDA7M6H63_cjs.P("exec_failed",c)]);}return this.dag.registerLine(t,e.reads,e.writes),e.results=r,e.result=r[0]?.[0]??null,a&&this.doc.markDirty(e.lineId),{...n,tier:2,result:s,results:r,error:i}}evaluateTier3(e,t,n,r,s){let i=[],a=new Set,l=new Set,o=false,c=null,d=null,p=false,f=false;for(let v of n)if(v.trim())try{let{program:y,reads:b,writes:L}=this.engine.compileExpression(v);i.push(y);for(let m of b)a.add(m);for(let m of L)l.add(m);L.length>0&&(o=!0),L.length>0&&y.opcodes.length>0&&(c=this.engine.executeCached(y,t),c&&c.type===12&&(f=!0));}catch(y){let b=y instanceof Error?y.message:String(y);d||(d=b),p=true,i.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false});}let g=[...a],h=[...l];return this.doc.updateLineCompiled(e.lineId,n,i,g,h,o,r),this.dag.registerLine(t,g,h),o&&c&&!p&&!f&&(e.results=[[c]],e.result=c,this.doc.markClean(e.lineId),this.checkpointer&&this.checkpointer.snapshot(t,e.lineId,h)),{...s,tier:3,result:c,results:o&&c&&!p&&!f?[[c]]:void 0,error:d}}restoreTo(e){this.checkpointer&&this.checkpointer.restoreTo(e);}getCheckpointer(){return this.checkpointer}getPageManager(){return this.pageManager}preloadNextPages(e){let t=this.pageManager.getPreloadTargets(e,this.doc);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}collectInvisibleCompileTargets(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef||i.isEmpty||chunkRECRD45C_cjs.l(i.text))continue;let{expressions:a}=this.extractExpressions(i);if(a.length!==0)for(let l of a)l.trim()&&t.push({lineId:i.lineId,expression:l,textHash:i.textHash});}return t}extractExpressions(e){if(e.expressions.length>0)return {expressions:e.expressions,inlineSolveCount:e.inlineSolveCount};let t=e.text.trim();if(t.length===0)return {expressions:[],inlineSolveCount:0};let n=chunkIHAZL4EF_cjs.c.findInlineSolves(e.text);return n.length>0?{expressions:n.map(r=>r.expression),inlineSolveCount:n.length}:{expressions:[t],inlineSolveCount:0}}};function ee(u){return typeof u.unit=="string"?u.unit:String(u.value)}function ie(u,e,t={inputType:"markdown"}){let n=u.getDocumentModel(),r=new R;r.setDocument(e);let s=new w(r,u);try{let i=r.lineCount;s.evaluate({startLine:1,endLine:i});let a=[],l=[],o=0;for(let c=1;c<=i;c++){let d=r.getLineAt(c),p=d.text,f=o,g=o+p.length;o=g+1;let h=d.inlineSolveCount>0,v=[],y=null,b=null;d.isEmpty||(h?v=chunkRECRD45C_cjs.m(p,c).map((L,m)=>{let x=d.results[m]?.[0]??null;if(x&&x.type===13){let E=ee(x);return l.push(`Line ${c}: ${E}`),{...L,result:null,error:E}}return {...L,result:x,error:null}}):(y=d.expressions[0]??null,b=d.result??null,b&&b.type===13&&l.push(`Line ${c}: ${ee(b)}`))),a.push({lineNumber:c,text:p,startPosition:f,endPosition:g,isEmpty:d.isEmpty,hasInlineSolves:h,inlineSolves:v,expression:y,error:null,result:b});}return {lines:a,totalLines:i,errors:l}}finally{s.terminateWorker(),u.setDocumentModel(n);}}exports.a=R;exports.b=Y;exports.c=w;exports.d=ie;//# sourceMappingURL=chunk-CMZSK6FY.cjs.map
|
|
3
|
+
//# sourceMappingURL=chunk-CMZSK6FY.cjs.map
|