solve-engine 2.23.0 → 2.25.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/{BytecodeBuilder-aqVa7Plx.d.cts → BytecodeBuilder-DSWKZi4f.d.cts} +11 -9
- package/dist/{BytecodeBuilder-aqVa7Plx.d.ts → BytecodeBuilder-DSWKZi4f.d.ts} +11 -9
- 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-fR1K1rvx.d.cts} +6 -0
- package/dist/{EngineError-DTk7I7hZ.d.ts → EngineError-fR1K1rvx.d.ts} +6 -0
- package/dist/{Lexer-CqagTewQ.d.ts → Lexer-Bmctxl0n.d.ts} +84 -35
- package/dist/{Lexer-CCHFDcgP.d.cts → Lexer-aB95pjoX.d.cts} +84 -35
- package/dist/{PackageCompatibility-BGXSFuL9.d.ts → PackageCompatibility-BludTs7v.d.ts} +1 -1
- package/dist/{PackageCompatibility-BZCqaTOO.d.cts → PackageCompatibility-CUVg8tmt.d.cts} +1 -1
- package/dist/{PackageRegistry-BRoVOYzg.d.ts → PackageRegistry-DT-x32OM.d.ts} +67 -14
- package/dist/{PackageRegistry-rMGnTh7W.d.cts → PackageRegistry-Dvn4i2QK.d.cts} +67 -14
- package/dist/{Parselet-Bkbp9CKD.d.cts → Parselet-BawfGuTF.d.cts} +8 -2
- package/dist/{Parselet-B-WyUtX4.d.ts → Parselet-DqTbbtWA.d.ts} +8 -2
- package/dist/{ScopeManager-gB9UengK.d.ts → ScopeManager-B636am7Y.d.ts} +39 -8
- package/dist/{ScopeManager-bCYewWVt.d.cts → ScopeManager-CdwX0VTw.d.cts} +39 -8
- package/dist/{TokenNormalizer-OTPS0Otq.d.ts → TokenNormalizer-CLBtiE8M.d.ts} +45 -26
- package/dist/{TokenNormalizer-MXaKLJ_m.d.cts → TokenNormalizer-CjTDmHgB.d.cts} +45 -26
- package/dist/{VMCheckpoints-DGar9Yg8.d.cts → VMCheckpoints-CYqeq8IV.d.cts} +3 -3
- package/dist/{VMCheckpoints-BDRY1Kx8.d.ts → VMCheckpoints-DDlxNssY.d.ts} +3 -3
- 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-DGBNM3gA.d.cts → WorkerError-B1dF3VYT.d.cts} +1 -1
- package/dist/{WorkerError-DpZgKRks.d.ts → WorkerError-dneODN-u.d.ts} +1 -1
- package/dist/{chunk-YAONCEAW.cjs → chunk-4BAUQE6A.cjs} +3 -3
- package/dist/{chunk-YAONCEAW.cjs.map → chunk-4BAUQE6A.cjs.map} +1 -1
- package/dist/chunk-4BRTUFTH.js +2 -0
- package/dist/chunk-4BRTUFTH.js.map +1 -0
- package/dist/chunk-4NZXCHQL.cjs +2 -0
- package/dist/chunk-4NZXCHQL.cjs.map +1 -0
- package/dist/chunk-57PSJQQW.js +3 -0
- package/dist/chunk-57PSJQQW.js.map +1 -0
- package/dist/chunk-634ILVMP.cjs +2 -0
- package/dist/chunk-634ILVMP.cjs.map +1 -0
- package/dist/{chunk-HMC7FJO7.js → chunk-63ZOOUOL.js} +2 -2
- package/dist/{chunk-HMC7FJO7.js.map → chunk-63ZOOUOL.js.map} +1 -1
- package/dist/chunk-72PYPENZ.js +2 -0
- package/dist/chunk-72PYPENZ.js.map +1 -0
- package/dist/chunk-77KI7AKJ.cjs +2 -0
- package/dist/chunk-77KI7AKJ.cjs.map +1 -0
- package/dist/chunk-7DP57BA7.js +2 -0
- package/dist/chunk-7DP57BA7.js.map +1 -0
- package/dist/chunk-7N3IJSWF.js +5 -0
- package/dist/chunk-7N3IJSWF.js.map +1 -0
- package/dist/chunk-BMXYR5LI.cjs +2 -0
- package/dist/chunk-BMXYR5LI.cjs.map +1 -0
- package/dist/chunk-DUYTXLO2.js +2 -0
- package/dist/chunk-DUYTXLO2.js.map +1 -0
- package/dist/chunk-EL2XUOWX.js +2 -0
- package/dist/chunk-EL2XUOWX.js.map +1 -0
- package/dist/chunk-FYAMQFZZ.cjs +3 -0
- package/dist/chunk-FYAMQFZZ.cjs.map +1 -0
- package/dist/chunk-FYTB7SDP.cjs +2 -0
- package/dist/chunk-FYTB7SDP.cjs.map +1 -0
- package/dist/chunk-GBCN7FNV.cjs +2 -0
- package/dist/chunk-GBCN7FNV.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-4ETS224G.js → chunk-JFZ5SLF7.js} +2 -2
- package/dist/{chunk-4ETS224G.js.map → chunk-JFZ5SLF7.js.map} +1 -1
- package/dist/chunk-JSM3O7EM.cjs +2 -0
- package/dist/chunk-JSM3O7EM.cjs.map +1 -0
- package/dist/chunk-MZMA32NE.js +3 -0
- package/dist/chunk-MZMA32NE.js.map +1 -0
- package/dist/chunk-N4SSR7Q6.js +2 -0
- package/dist/chunk-N4SSR7Q6.js.map +1 -0
- package/dist/{chunk-TL545PXW.cjs → chunk-NEGZZB7F.cjs} +2 -2
- package/dist/{chunk-TL545PXW.cjs.map → chunk-NEGZZB7F.cjs.map} +1 -1
- package/dist/{chunk-3GR46UOX.js → chunk-NMU5E7W7.js} +2 -2
- package/dist/{chunk-3GR46UOX.js.map → chunk-NMU5E7W7.js.map} +1 -1
- package/dist/chunk-OB2VX4IL.js +2 -0
- package/dist/chunk-OB2VX4IL.js.map +1 -0
- package/dist/{chunk-MRRMIBHE.js → chunk-OONQ3V3I.js} +2 -2
- package/dist/{chunk-MRRMIBHE.js.map → chunk-OONQ3V3I.js.map} +1 -1
- package/dist/{chunk-N37PUZJR.cjs → chunk-RAPEZR5L.cjs} +2 -2
- package/dist/{chunk-N37PUZJR.cjs.map → chunk-RAPEZR5L.cjs.map} +1 -1
- package/dist/{chunk-KEA5HRL3.js → chunk-RDYXH7ML.js} +2 -2
- package/dist/{chunk-KEA5HRL3.js.map → chunk-RDYXH7ML.js.map} +1 -1
- package/dist/{chunk-3SSMOVWB.cjs → chunk-SAF3B3AX.cjs} +2 -2
- package/dist/{chunk-3SSMOVWB.cjs.map → chunk-SAF3B3AX.cjs.map} +1 -1
- package/dist/chunk-SPOVFRZO.cjs +5 -0
- package/dist/chunk-SPOVFRZO.cjs.map +1 -0
- package/dist/{chunk-75JLWK4L.cjs → chunk-SQHBOWES.cjs} +2 -2
- package/dist/{chunk-75JLWK4L.cjs.map → chunk-SQHBOWES.cjs.map} +1 -1
- package/dist/chunk-UF5XMZTT.js +2 -0
- package/dist/chunk-UF5XMZTT.js.map +1 -0
- package/dist/chunk-UV3EUIBT.cjs +3 -0
- package/dist/chunk-UV3EUIBT.cjs.map +1 -0
- package/dist/chunk-VMSCRVNX.cjs +2 -0
- package/dist/chunk-VMSCRVNX.cjs.map +1 -0
- package/dist/{chunk-J7ABVGZH.cjs → chunk-WGP4UUO5.cjs} +2 -2
- package/dist/{chunk-J7ABVGZH.cjs.map → chunk-WGP4UUO5.cjs.map} +1 -1
- package/dist/chunk-XBGK3TTU.cjs +3 -0
- package/dist/chunk-XBGK3TTU.cjs.map +1 -0
- package/dist/chunk-XHQYHXRE.js +3 -0
- package/dist/chunk-XHQYHXRE.js.map +1 -0
- package/dist/chunk-XX55RR4Q.js +3 -0
- package/dist/chunk-XX55RR4Q.js.map +1 -0
- package/dist/chunk-YBQPEWT7.cjs +3 -0
- package/dist/chunk-YBQPEWT7.cjs.map +1 -0
- package/dist/{chunk-CHSO3DCS.js → chunk-ZDCZ5IDD.js} +3 -3
- package/dist/{chunk-CHSO3DCS.js.map → chunk-ZDCZ5IDD.js.map} +1 -1
- 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 +12 -12
- package/dist/engine.d.ts +12 -12
- 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 +14 -12
- package/dist/index.d.ts +14 -12
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/language.d.cts +11 -11
- package/dist/language.d.ts +11 -11
- package/dist/lexer.cjs +1 -1
- package/dist/lexer.cjs.map +1 -1
- package/dist/lexer.d.cts +8 -7
- package/dist/lexer.d.ts +8 -7
- package/dist/lexer.js +1 -1
- package/dist/lexer.js.map +1 -1
- package/dist/normalizer.cjs +1 -1
- package/dist/normalizer.d.cts +16 -10
- package/dist/normalizer.d.ts +16 -10
- package/dist/normalizer.js +1 -1
- package/dist/packages.cjs +1 -1
- package/dist/packages.d.cts +10 -10
- package/dist/packages.d.ts +10 -10
- package/dist/packages.js +1 -1
- package/dist/parser.cjs +1 -1
- package/dist/parser.d.cts +4 -4
- package/dist/parser.d.ts +4 -4
- 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 +19 -3
- package/dist/resolvers.d.ts +19 -3
- package/dist/resolvers.js +1 -1
- package/dist/testing.cjs +2 -2
- package/dist/testing.d.cts +11 -11
- package/dist/testing.d.ts +11 -11
- package/dist/testing.js +1 -1
- package/dist/uom.cjs +1 -1
- package/dist/uom.d.cts +2 -2
- package/dist/uom.d.ts +2 -2
- package/dist/uom.js +1 -1
- package/dist/vm.cjs +1 -1
- package/dist/vm.d.cts +8 -8
- package/dist/vm.d.ts +8 -8
- package/dist/vm.js +1 -1
- package/dist/worker.cjs +2 -2
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +34 -25
- package/dist/worker.d.ts +34 -25
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-42JXN3BH.js +0 -5
- package/dist/chunk-42JXN3BH.js.map +0 -1
- package/dist/chunk-4DJJIUQF.js +0 -2
- 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 +0 -2
- 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-EN3CDYOS.cjs +0 -2
- package/dist/chunk-EN3CDYOS.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-JVMINMAB.js +0 -2
- package/dist/chunk-JVMINMAB.js.map +0 -1
- package/dist/chunk-JYLNQOPU.cjs +0 -2
- package/dist/chunk-JYLNQOPU.cjs.map +0 -1
- package/dist/chunk-KRXO3MOW.cjs +0 -2
- 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-O3BDXOQJ.js +0 -2
- package/dist/chunk-O3BDXOQJ.js.map +0 -1
- package/dist/chunk-PIZQIQVM.js +0 -3
- package/dist/chunk-PIZQIQVM.js.map +0 -1
- package/dist/chunk-QTSDIDAS.js +0 -3
- package/dist/chunk-QTSDIDAS.js.map +0 -1
- package/dist/chunk-SGIDBZ4T.cjs +0 -2
- 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 +0 -2
- package/dist/chunk-USQ4KL6S.cjs.map +0 -1
- package/dist/chunk-XDXIPVZB.cjs +0 -2
- package/dist/chunk-XDXIPVZB.cjs.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var n=class{constructor(){this.resolvers=new Map;}register(e){this.resolvers.has(e.namespace)&&(console.warn(`[ResolverRegistry] Namespace "${e.namespace}" already registered. Destroying old resolver and overwriting. Use distinct namespaces (e.g., "${e.namespace}:sub1", "${e.namespace}:sub2") to avoid collisions when a package needs multiple async resolvers.`),this.resolvers.get(e.namespace).destroy()),this.resolvers.set(e.namespace,e);}unregister(e,r){let s=this.resolvers.get(e);s&&(s.destroy(),this.resolvers.delete(e)),r&&r.removeQueries({queryKey:[e]});}preflightAll(e,r,s,i,l){for(let t of this.resolvers.values()){if(!t.preflight)continue;let o=t.preflight(e,r,s,i,l);if(o)return o}return null}get(e){return this.resolvers.get(e)}get size(){return this.resolvers.size}has(e){return this.resolvers.has(e)}clear(){for(let e of this.resolvers.values())e.destroy();this.resolvers.clear();}};exports.a=n;//# sourceMappingURL=chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
'use strict';var n=class{constructor(){this.resolvers=new Map;}register(e){this.resolvers.has(e.namespace)&&(console.warn(`[ResolverRegistry] Namespace "${e.namespace}" already registered. Destroying old resolver and overwriting. Use distinct namespaces (e.g., "${e.namespace}:sub1", "${e.namespace}:sub2") to avoid collisions when a package needs multiple async resolvers.`),this.resolvers.get(e.namespace).destroy()),this.resolvers.set(e.namespace,e);}unregister(e,r){let s=this.resolvers.get(e);s&&(s.destroy(),this.resolvers.delete(e)),r&&r.removeQueries({queryKey:[e]});}preflightAll(e,r,s,i,l,a=true){for(let t of this.resolvers.values()){if(!t.preflight||!a&&!t.local)continue;let o=t.preflight(e,r,s,i,l);if(o)return o}return null}get(e){return this.resolvers.get(e)}get size(){return this.resolvers.size}has(e){return this.resolvers.has(e)}clear(){for(let e of this.resolvers.values())e.destroy();this.resolvers.clear();}};exports.a=n;//# sourceMappingURL=chunk-ZVPZQ66D.cjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-ZVPZQ66D.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/resolvers/ResolverRegistry.ts"],"names":["ResolverRegistry","resolver","namespace","queryClient","tokens","bytecode","packageId","signal","networkEnabled","result"],"mappings":"aAiGO,IAAMA,EAAN,KAAuB,CAAvB,WAAA,EAAA,CACN,IAAA,CAAQ,UAAY,IAAI,IAAA,CAWxB,QAAA,CAASC,CAAAA,CAAgC,CAEpC,IAAA,CAAK,SAAA,CAAU,IAAIA,C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AA,CAA4B,CAC/B,OAAO,IAAA,CAAK,SAAA,CAAU,GAAA,CAAIA,CAAS,CACpC,CAMA,KAAA,EAAc,CACb,IAAA,IAAWD,KAAY,IAAA,CAAK,SAAA,CAAU,MAAA,EAAO,CAC5CA,EAAS,OAAA,EAAQ,CAElB,KAAK,SAAA,CAAU,KAAA,GAChB,CACD","file":"chunk-ZVPZQ66D.cjs","sourcesContent":["import type { QueryClient } from \"@tanstack/query-core\";\nimport type { Token } from \"@solve-js/lexer\";\nimport type { BytecodeProgram } from \"@solve-js/parser/BytecodeBuilder\";\nimport type { Value } from \"@solve-js/vm/Value\";\n\n/**\n * Result from a resolver's preflight() check.\n * Returned when async data is needed, the orchestrator uses this\n * to subscribe to the resolver and return a Pending value immediately.\n */\nexport interface AsyncCheckResult {\n\t/** Unique cache key for deduplication (e.g., \"{packageId}:rates:USD:GBP\") */\n\tqueryKey: string;\n\t/** Promise that resolves to the final Value */\n\tresolver: Promise<Value>;\n\t/** Package owning this resolver */\n\tpackageId: string;\n\t/** AbortSignal for stale-data prevention */\n\tsignal: AbortSignal;\n\t/** Optional metadata for diagnostics */\n\tmetadata?: Record<string, unknown>;\n\t/**\n\t * Cadence, in ms, at which this value wants proactive background refresh\n\t * (a live quote every minute, an FX rate every few minutes). Absent, or\n\t * paired with no {@link refetch}, means pull-only: the value refreshes on\n\t * re-evaluation, never on its own. Only acted on when the host has enabled\n\t * background refresh; see {@link BackgroundRefreshConfig}.\n\t */\n\trefetchIntervalMs?: number;\n\t/**\n\t * Force a fresh fetch of this exact query, bypassing `staleTime`, and return\n\t * the new value. Supplied alongside {@link refetchIntervalMs} so the engine\n\t * can drive the background refresh without re-scanning bytecode.\n\t */\n\trefetch?: () => Promise<Value>;\n}\n\n/**\n * Interface for async resolvers registered by packages/plugins.\n *\n * Each resolver handles a domain of async data (currency rates,\n * weather, stock prices, etc.). The preflight() method is called\n * BEFORE VM execution to check if all data is cached. If not,\n * it returns an AsyncCheckResult and the engine skips the VM,\n * returning a Pending value instead.\n */\nexport interface IAsyncResolver {\n\t/** Unique namespace for cache key scoping (e.g., \"currency\", \"weather\") */\n\treadonly namespace: string;\n\n\t/**\n\t * True for a resolver that answers from engine state and never reaches a\n\t * network: it waits on a value another line will produce, or reads a table\n\t * the host loaded up front. Such a resolver keeps running when the host\n\t * has switched live data off (`network.enabled: false`); every other\n\t * resolver is skipped by that setting before its `preflight()` is called,\n\t * so no request is ever started. Leave it unset (the default) for anything\n\t * that fetches. The engine's own global-variable resolver is the built-in\n\t * case that sets it.\n\t */\n\treadonly local?: boolean;\n\n\t/**\n\t * Pre-flight check: called BEFORE VM execution.\n\t *\n\t * Returns null if all data for this expression is cached and ready.\n\t * Returns an AsyncCheckResult if async work is needed.\n\t *\n\t * This method is synchronous, it only checks caches, never fetches.\n\t * If data is missing, it creates a Promise and returns immediately.\n\t *\n\t * @param tokens - The lexed tokens for the expression\n\t * @param bytecode - The compiled bytecode program\n\t * @param pluginId - The plugin ID (for cache key scoping)\n\t * @param signal - AbortSignal for the current evaluation\n\t */\n\tpreflight?(tokens: Token[], bytecode: BytecodeProgram, packageId: string, signal: AbortSignal, queryClient: QueryClient): AsyncCheckResult | null;\n\n\t/**\n\t * Called when the resolver's namespace is being unregistered.\n\t * Clean up any in-flight promises, clear caches, unsubscribe.\n\t */\n\tdestroy(): void;\n}\n\n/**\n * Registry of async resolvers, keyed by namespace.\n *\n * Plugins/packages register resolvers alongside their parselets\n * and opcode handlers. The engine calls preflightAll() before\n * VM execution to short-circuit async expressions.\n *\n * Lifecycle:\n * - register(), when a package is loaded\n * - unregister(), when a package is unloaded (clears cache entries)\n * - clear(), on document switch (clears all resolvers)\n */\nexport class ResolverRegistry {\n\tprivate resolvers = new Map<string, IAsyncResolver>();\n\n\t/**\n\t * Register an async resolver.\n\t *\n\t * Each resolver must have a unique `namespace`. If a resolver with the\n\t * same namespace is already registered, the old one is destroyed and\n\t * replaced (with a console warning). Packages that need multiple async\n\t * operations should use `asyncResolvers: [...]` with distinct namespaces\n\t * (e.g., `\"weather:current\"`, `\"weather:forecast\"`).\n\t */\n\tregister(resolver: IAsyncResolver): void {\n\t\t// Clean up previous resolver with same namespace if any\n\t\tif (this.resolvers.has(resolver.namespace)) {\n\t\t\tconsole.warn(\n\t\t\t\t`[ResolverRegistry] Namespace \"${resolver.namespace}\" already registered. ` +\n\t\t\t\t`Destroying old resolver and overwriting. Use distinct namespaces ` +\n\t\t\t\t`(e.g., \"${resolver.namespace}:sub1\", \"${resolver.namespace}:sub2\") ` +\n\t\t\t\t`to avoid collisions when a package needs multiple async resolvers.`,\n\t\t\t);\n\t\t\tthis.resolvers.get(resolver.namespace)!.destroy();\n\t\t}\n\t\tthis.resolvers.set(resolver.namespace, resolver);\n\t}\n\n\t/**\n\t * Unregister a resolver by namespace.\n\t * Calls destroy() and clears all cache entries with that namespace prefix.\n\t */\n\tunregister(namespace: string, queryClient?: QueryClient): void {\n\t\tconst resolver = this.resolvers.get(namespace);\n\t\tif (resolver) {\n\t\t\tresolver.destroy();\n\t\t\tthis.resolvers.delete(namespace);\n\t\t}\n\t\t// Clear all cache entries for this namespace via TanStack Query\n\t\t// Hierarchical keys: [\"osrs\"] clears all [\"osrs\", ...] queries\n\t\tif (queryClient) {\n\t\t\tqueryClient.removeQueries({ queryKey: [namespace] });\n\t\t}\n\t}\n\n\t/**\n\t * Run all registered resolvers' preflight checks against compiled bytecode.\n\t *\n\t * Returns the first AsyncCheckResult found, or null if all data is ready.\n\t * Short-circuits on first pending, subsequent pending ops will be\n\t * discovered on re-evaluation when the first resolves.\n\t *\n\t * With `networkEnabled` false, only resolvers that declare themselves\n\t * {@link IAsyncResolver.local} are consulted. The skip happens here, before\n\t * `preflight()` runs, because a resolver's preflight is what starts the\n\t * fetch: refusing its promise afterwards would already be too late.\n\t */\n\tpreflightAll(tokens: Token[], bytecode: BytecodeProgram, packageId: string, signal: AbortSignal, queryClient: QueryClient, networkEnabled = true): AsyncCheckResult | null {\n\t\tfor (const resolver of this.resolvers.values()) {\n\t\t\tif (!resolver.preflight) continue;\n\t\t\tif (!networkEnabled && !resolver.local) continue;\n\t\t\tconst result = resolver.preflight(tokens, bytecode, packageId, signal, queryClient);\n\t\t\tif (result) return result;\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**\n\t * Get a resolver by namespace.\n\t * Returns undefined if no resolver is registered for that namespace.\n\t */\n\tget(namespace: string): IAsyncResolver | undefined {\n\t\treturn this.resolvers.get(namespace);\n\t}\n\n\t/** Number of registered resolvers. */\n\tget size(): number {\n\t\treturn this.resolvers.size;\n\t}\n\n\t/**\n\t * Check if a resolver is registered for the given namespace.\n\t */\n\thas(namespace: string): boolean {\n\t\treturn this.resolvers.has(namespace);\n\t}\n\n\t/**\n\t * Clear all resolvers (document switch, engine reset).\n\t * Calls destroy() on each resolver and clears the map.\n\t */\n\tclear(): void {\n\t\tfor (const resolver of this.resolvers.values()) {\n\t\t\tresolver.destroy();\n\t\t}\n\t\tthis.resolvers.clear();\n\t}\n}\n"]}
|
package/dist/constants.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk4NZXCHQL_cjs=require('./chunk-4NZXCHQL.cjs');require('./chunk-YBQPEWT7.cjs');Object.defineProperty(exports,"ConfigManager",{enumerable:true,get:function(){return chunk4NZXCHQL_cjs.d}});Object.defineProperty(exports,"DEFAULT_CONFIG",{enumerable:true,get:function(){return chunk4NZXCHQL_cjs.b}});Object.defineProperty(exports,"ENGINE_VERSION",{enumerable:true,get:function(){return chunk4NZXCHQL_cjs.a}});//# sourceMappingURL=constants.cjs.map
|
|
2
2
|
//# sourceMappingURL=constants.cjs.map
|
package/dist/constants.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as ConfigManager, D as DEFAULT_CONFIG, b as DateConfig, c as DiagnosticConfig, a as EngineConfig, E as EngineConfigOverride, H as HolidayCalendar, d as HolidayPredicate, P as PerformanceConfig, V as VMConfig, e as ValidationConfig, f as ValidationResult, W as WorkerConfig } from './Configuration-
|
|
1
|
+
export { C as ConfigManager, D as DEFAULT_CONFIG, b as DateConfig, c as DiagnosticConfig, a as EngineConfig, E as EngineConfigOverride, H as HolidayCalendar, d as HolidayPredicate, P as PerformanceConfig, V as VMConfig, e as ValidationConfig, f as ValidationResult, W as WorkerConfig } from './Configuration-DnzYPmoK.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The running engine's version, taken from package.json.
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as ConfigManager, D as DEFAULT_CONFIG, b as DateConfig, c as DiagnosticConfig, a as EngineConfig, E as EngineConfigOverride, H as HolidayCalendar, d as HolidayPredicate, P as PerformanceConfig, V as VMConfig, e as ValidationConfig, f as ValidationResult, W as WorkerConfig } from './Configuration-
|
|
1
|
+
export { C as ConfigManager, D as DEFAULT_CONFIG, b as DateConfig, c as DiagnosticConfig, a as EngineConfig, E as EngineConfigOverride, H as HolidayCalendar, d as HolidayPredicate, P as PerformanceConfig, V as VMConfig, e as ValidationConfig, f as ValidationResult, W as WorkerConfig } from './Configuration-DnzYPmoK.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The running engine's version, taken from package.json.
|
package/dist/constants.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{d as ConfigManager,b as DEFAULT_CONFIG,a as ENGINE_VERSION}from'./chunk-
|
|
1
|
+
export{d as ConfigManager,b as DEFAULT_CONFIG,a as ENGINE_VERSION}from'./chunk-DUYTXLO2.js';import'./chunk-57PSJQQW.js';//# sourceMappingURL=constants.js.map
|
|
2
2
|
//# sourceMappingURL=constants.js.map
|
package/dist/engine.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk4BAUQE6A_cjs=require('./chunk-4BAUQE6A.cjs');require('./chunk-EFJCC6FJ.cjs');var chunkSPOVFRZO_cjs=require('./chunk-SPOVFRZO.cjs');require('./chunk-VMSCRVNX.cjs'),require('./chunk-NGBBNL4K.cjs'),require('./chunk-ZVPZQ66D.cjs'),require('./chunk-TTFO4YDP.cjs'),require('./chunk-JSM3O7EM.cjs'),require('./chunk-HG4NPDN5.cjs'),require('./chunk-XBGK3TTU.cjs'),require('./chunk-R2SZFJTT.cjs'),require('./chunk-RAPEZR5L.cjs'),require('./chunk-FYTB7SDP.cjs'),require('./chunk-GBCN7FNV.cjs'),require('./chunk-UURM7P3P.cjs'),require('./chunk-ZLRJ7TDP.cjs'),require('./chunk-634ILVMP.cjs'),require('./chunk-FYAMQFZZ.cjs'),require('./chunk-ABVDKMNF.cjs'),require('./chunk-TLG7VZRX.cjs'),require('./chunk-5TVI2UPZ.cjs'),require('./chunk-WGP4UUO5.cjs'),require('./chunk-SQHBOWES.cjs'),require('./chunk-ZKFCKAIX.cjs'),require('./chunk-4NZXCHQL.cjs'),require('./chunk-BMXYR5LI.cjs'),require('./chunk-Y7O4D3BJ.cjs'),require('./chunk-77KI7AKJ.cjs'),require('./chunk-5IJD5L3O.cjs'),require('./chunk-S3DFU33X.cjs'),require('./chunk-J4LSAHCY.cjs'),require('./chunk-EZKR44MA.cjs'),require('./chunk-YBQPEWT7.cjs');Object.defineProperty(exports,"DocumentModel",{enumerable:true,get:function(){return chunk4BAUQE6A_cjs.a}});Object.defineProperty(exports,"EvalTier",{enumerable:true,get:function(){return chunk4BAUQE6A_cjs.b}});Object.defineProperty(exports,"ThreeTierEvaluator",{enumerable:true,get:function(){return chunk4BAUQE6A_cjs.c}});Object.defineProperty(exports,"evaluateDocument",{enumerable:true,get:function(){return chunk4BAUQE6A_cjs.d}});Object.defineProperty(exports,"AsyncResolutionBatcher",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.h}});Object.defineProperty(exports,"ExpressionEngine",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.n}});Object.defineProperty(exports,"SNAPSHOT_FORMAT",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.d}});Object.defineProperty(exports,"SNAPSHOT_VERSION",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.e}});Object.defineProperty(exports,"SnapshotErrorCodes",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.f}});Object.defineProperty(exports,"checkExpressionComplexity",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.j}});Object.defineProperty(exports,"checkExpressionLength",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.i}});Object.defineProperty(exports,"extractReadsAndWrites",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.k}});Object.defineProperty(exports,"findInlineSolvesInLine",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.m}});Object.defineProperty(exports,"isEmptyLine",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.l}});//# sourceMappingURL=engine.cjs.map
|
|
2
2
|
//# sourceMappingURL=engine.cjs.map
|
package/dist/engine.d.cts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { D as DocumentModel, E as ExpressionEngine, V as ViewportRange, r as LineChange, U as UnifiedParsingOptions, P as ParsingResult, s as InlineSolvePosition } from './PackageRegistry-
|
|
2
|
-
export { A as ApplyChangesResult, t as AsyncCachePackageInfo, u as AsyncErrorEvent, v as AsyncResolutionBatcher, w as AsyncResolutionEvent, B as BatcherMetrics, x as BytecodeCacheEntry, y as CacheSnapshot, z as CheckpointSnapshot, a as EngineOptions, b as EngineRestoreOptions, c as EngineSnapshot, d as Explanation, e as ExplanationStep, F as LineCacheEntryInfo, G as LineState, H as LinesUpdatedEvent, J as ParsedLine, S as SNAPSHOT_FORMAT, f as SNAPSHOT_VERSION, g as SerializedAnonymousBody, h as SerializedBytecode, i as SerializedDecimal, j as SerializedLineCacheEntry, k as SerializedNumber, l as SerializedRational, m as SerializedUserFunction, n as SerializedValue, o as SnapshotErrorCodes } from './PackageRegistry-
|
|
3
|
-
import { V as Value } from './Value-
|
|
4
|
-
import { a as VMCheckpointer } from './VMCheckpoints-
|
|
1
|
+
import { D as DocumentModel, E as ExpressionEngine, V as ViewportRange, r as LineChange, U as UnifiedParsingOptions, P as ParsingResult, s as InlineSolvePosition } from './PackageRegistry-Dvn4i2QK.cjs';
|
|
2
|
+
export { A as ApplyChangesResult, t as AsyncCachePackageInfo, u as AsyncErrorEvent, v as AsyncResolutionBatcher, w as AsyncResolutionEvent, B as BatcherMetrics, x as BytecodeCacheEntry, y as CacheSnapshot, z as CheckpointSnapshot, a as EngineOptions, b as EngineRestoreOptions, c as EngineSnapshot, d as Explanation, e as ExplanationStep, F as LineCacheEntryInfo, G as LineState, H as LinesUpdatedEvent, J as ParsedLine, S as SNAPSHOT_FORMAT, f as SNAPSHOT_VERSION, g as SerializedAnonymousBody, h as SerializedBytecode, i as SerializedDecimal, j as SerializedLineCacheEntry, k as SerializedNumber, l as SerializedRational, m as SerializedUserFunction, n as SerializedValue, o as SnapshotErrorCodes } from './PackageRegistry-Dvn4i2QK.cjs';
|
|
3
|
+
import { V as Value } from './Value-Ds3Gy07C.cjs';
|
|
4
|
+
import { a as VMCheckpointer } from './VMCheckpoints-CYqeq8IV.cjs';
|
|
5
5
|
import { T as Token } from './Token-CbP_OutD.cjs';
|
|
6
|
-
import { E as EngineError } from './EngineError-
|
|
7
|
-
import { a as BytecodeProgram } from './BytecodeBuilder-
|
|
8
|
-
export { a as DagSnapshot } from './ScopeManager-
|
|
9
|
-
import './Parselet-
|
|
10
|
-
import './pipeline-
|
|
11
|
-
import './Lexer-
|
|
6
|
+
import { E as EngineError } from './EngineError-fR1K1rvx.cjs';
|
|
7
|
+
import { a as BytecodeProgram } from './BytecodeBuilder-DSWKZi4f.cjs';
|
|
8
|
+
export { a as DagSnapshot } from './ScopeManager-CdwX0VTw.cjs';
|
|
9
|
+
import './Parselet-BawfGuTF.cjs';
|
|
10
|
+
import './pipeline-69q2tsLE.cjs';
|
|
11
|
+
import './Lexer-aB95pjoX.cjs';
|
|
12
12
|
import './resolvers.cjs';
|
|
13
13
|
import '@tanstack/query-core';
|
|
14
|
-
import './TokenNormalizer-
|
|
15
|
-
import './Configuration-
|
|
14
|
+
import './TokenNormalizer-CjTDmHgB.cjs';
|
|
15
|
+
import './Configuration-DnzYPmoK.cjs';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* PageManager, page-based LRU eviction + directional preloading.
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { D as DocumentModel, E as ExpressionEngine, V as ViewportRange, r as LineChange, U as UnifiedParsingOptions, P as ParsingResult, s as InlineSolvePosition } from './PackageRegistry-
|
|
2
|
-
export { A as ApplyChangesResult, t as AsyncCachePackageInfo, u as AsyncErrorEvent, v as AsyncResolutionBatcher, w as AsyncResolutionEvent, B as BatcherMetrics, x as BytecodeCacheEntry, y as CacheSnapshot, z as CheckpointSnapshot, a as EngineOptions, b as EngineRestoreOptions, c as EngineSnapshot, d as Explanation, e as ExplanationStep, F as LineCacheEntryInfo, G as LineState, H as LinesUpdatedEvent, J as ParsedLine, S as SNAPSHOT_FORMAT, f as SNAPSHOT_VERSION, g as SerializedAnonymousBody, h as SerializedBytecode, i as SerializedDecimal, j as SerializedLineCacheEntry, k as SerializedNumber, l as SerializedRational, m as SerializedUserFunction, n as SerializedValue, o as SnapshotErrorCodes } from './PackageRegistry-
|
|
3
|
-
import { V as Value } from './Value-
|
|
4
|
-
import { a as VMCheckpointer } from './VMCheckpoints-
|
|
1
|
+
import { D as DocumentModel, E as ExpressionEngine, V as ViewportRange, r as LineChange, U as UnifiedParsingOptions, P as ParsingResult, s as InlineSolvePosition } from './PackageRegistry-DT-x32OM.js';
|
|
2
|
+
export { A as ApplyChangesResult, t as AsyncCachePackageInfo, u as AsyncErrorEvent, v as AsyncResolutionBatcher, w as AsyncResolutionEvent, B as BatcherMetrics, x as BytecodeCacheEntry, y as CacheSnapshot, z as CheckpointSnapshot, a as EngineOptions, b as EngineRestoreOptions, c as EngineSnapshot, d as Explanation, e as ExplanationStep, F as LineCacheEntryInfo, G as LineState, H as LinesUpdatedEvent, J as ParsedLine, S as SNAPSHOT_FORMAT, f as SNAPSHOT_VERSION, g as SerializedAnonymousBody, h as SerializedBytecode, i as SerializedDecimal, j as SerializedLineCacheEntry, k as SerializedNumber, l as SerializedRational, m as SerializedUserFunction, n as SerializedValue, o as SnapshotErrorCodes } from './PackageRegistry-DT-x32OM.js';
|
|
3
|
+
import { V as Value } from './Value-Ds3Gy07C.js';
|
|
4
|
+
import { a as VMCheckpointer } from './VMCheckpoints-DDlxNssY.js';
|
|
5
5
|
import { T as Token } from './Token-CbP_OutD.js';
|
|
6
|
-
import { E as EngineError } from './EngineError-
|
|
7
|
-
import { a as BytecodeProgram } from './BytecodeBuilder-
|
|
8
|
-
export { a as DagSnapshot } from './ScopeManager-
|
|
9
|
-
import './Parselet-
|
|
10
|
-
import './pipeline-
|
|
11
|
-
import './Lexer-
|
|
6
|
+
import { E as EngineError } from './EngineError-fR1K1rvx.js';
|
|
7
|
+
import { a as BytecodeProgram } from './BytecodeBuilder-DSWKZi4f.js';
|
|
8
|
+
export { a as DagSnapshot } from './ScopeManager-B636am7Y.js';
|
|
9
|
+
import './Parselet-DqTbbtWA.js';
|
|
10
|
+
import './pipeline-DTqGLPsV.js';
|
|
11
|
+
import './Lexer-Bmctxl0n.js';
|
|
12
12
|
import './resolvers.js';
|
|
13
13
|
import '@tanstack/query-core';
|
|
14
|
-
import './TokenNormalizer-
|
|
15
|
-
import './Configuration-
|
|
14
|
+
import './TokenNormalizer-CLBtiE8M.js';
|
|
15
|
+
import './Configuration-DnzYPmoK.js';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* PageManager, page-based LRU eviction + directional preloading.
|
package/dist/engine.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as DocumentModel,b as EvalTier,c as ThreeTierEvaluator,d as evaluateDocument}from'./chunk-
|
|
1
|
+
export{a as DocumentModel,b as EvalTier,c as ThreeTierEvaluator,d as evaluateDocument}from'./chunk-ZDCZ5IDD.js';import'./chunk-RAF57WYO.js';export{h as AsyncResolutionBatcher,n as ExpressionEngine,d as SNAPSHOT_FORMAT,e as SNAPSHOT_VERSION,f as SnapshotErrorCodes,j as checkExpressionComplexity,i as checkExpressionLength,k as extractReadsAndWrites,m as findInlineSolvesInLine,l as isEmptyLine}from'./chunk-7N3IJSWF.js';import'./chunk-4BRTUFTH.js';import'./chunk-2RWAXT6O.js';import'./chunk-IJHL3LMH.js';import'./chunk-MIQBJGGR.js';import'./chunk-N4SSR7Q6.js';import'./chunk-JP4JMQOG.js';import'./chunk-XX55RR4Q.js';import'./chunk-XEIDV5JP.js';import'./chunk-63ZOOUOL.js';import'./chunk-EL2XUOWX.js';import'./chunk-72PYPENZ.js';import'./chunk-76F3LCIL.js';import'./chunk-TCZSPH4A.js';import'./chunk-UF5XMZTT.js';import'./chunk-XHQYHXRE.js';import'./chunk-TZYMXNIB.js';import'./chunk-HFKDWQUL.js';import'./chunk-5TCSFTZD.js';import'./chunk-RDYXH7ML.js';import'./chunk-NMU5E7W7.js';import'./chunk-4CNYGIND.js';import'./chunk-DUYTXLO2.js';import'./chunk-7DP57BA7.js';import'./chunk-JPFCXLJV.js';import'./chunk-OB2VX4IL.js';import'./chunk-IJMNVBIS.js';import'./chunk-LHLW7JLS.js';import'./chunk-CHVGFTO3.js';import'./chunk-PRSXXDTA.js';import'./chunk-57PSJQQW.js';//# sourceMappingURL=engine.js.map
|
|
2
2
|
//# sourceMappingURL=engine.js.map
|
package/dist/errors.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkSAF3B3AX_cjs=require('./chunk-SAF3B3AX.cjs'),chunkYBQPEWT7_cjs=require('./chunk-YBQPEWT7.cjs');Object.defineProperty(exports,"WorkerErrorCodes",{enumerable:true,get:function(){return chunkSAF3B3AX_cjs.a}});Object.defineProperty(exports,"deserializeEngineError",{enumerable:true,get:function(){return chunkSAF3B3AX_cjs.c}});Object.defineProperty(exports,"serializeEngineError",{enumerable:true,get:function(){return chunkSAF3B3AX_cjs.b}});Object.defineProperty(exports,"workerCancelledError",{enumerable:true,get:function(){return chunkSAF3B3AX_cjs.d}});Object.defineProperty(exports,"workerTerminatedError",{enumerable:true,get:function(){return chunkSAF3B3AX_cjs.e}});Object.defineProperty(exports,"workerTransportError",{enumerable:true,get:function(){return chunkSAF3B3AX_cjs.f}});Object.defineProperty(exports,"CoreErrorCodes",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.r}});Object.defineProperty(exports,"EngineError",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.b}});Object.defineProperty(exports,"ErrorCategory",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.a}});Object.defineProperty(exports,"ErrorFactory",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.c}});Object.defineProperty(exports,"andThen",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.k}});Object.defineProperty(exports,"combine",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.n}});Object.defineProperty(exports,"err",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.f}});Object.defineProperty(exports,"isErr",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.h}});Object.defineProperty(exports,"isOk",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.g}});Object.defineProperty(exports,"map",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.i}});Object.defineProperty(exports,"mapErr",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.j}});Object.defineProperty(exports,"match",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.m}});Object.defineProperty(exports,"normalizeUnknownError",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.d}});Object.defineProperty(exports,"ok",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.e}});Object.defineProperty(exports,"throwIfErr",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.o}});Object.defineProperty(exports,"tryCatch",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.p}});Object.defineProperty(exports,"tryCatchAsync",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.q}});Object.defineProperty(exports,"unwrapOr",{enumerable:true,get:function(){return chunkYBQPEWT7_cjs.l}});//# sourceMappingURL=errors.cjs.map
|
|
2
2
|
//# sourceMappingURL=errors.cjs.map
|
package/dist/errors.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { E as EngineError } from './EngineError-
|
|
2
|
-
export { C as CoreErrorCode, a as CoreErrorCodes, b as EngineErrorInit, c as ErrorCategory, d as ErrorCode, e as ErrorFactory, S as SourceSpan, n as normalizeUnknownError } from './EngineError-
|
|
3
|
-
export { S as SerializedEngineError, W as WorkerErrorCodes, d as deserializeEngineError, s as serializeEngineError, w as workerCancelledError, a as workerTerminatedError, b as workerTransportError } from './WorkerError-
|
|
1
|
+
import { E as EngineError } from './EngineError-fR1K1rvx.cjs';
|
|
2
|
+
export { C as CoreErrorCode, a as CoreErrorCodes, b as EngineErrorInit, c as ErrorCategory, d as ErrorCode, e as ErrorFactory, S as SourceSpan, n as normalizeUnknownError } from './EngineError-fR1K1rvx.cjs';
|
|
3
|
+
export { S as SerializedEngineError, W as WorkerErrorCodes, d as deserializeEngineError, s as serializeEngineError, w as workerCancelledError, a as workerTerminatedError, b as workerTransportError } from './WorkerError-B1dF3VYT.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A Rust-style `Result<T, E>`, the value half of this engine's error-handling
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { E as EngineError } from './EngineError-
|
|
2
|
-
export { C as CoreErrorCode, a as CoreErrorCodes, b as EngineErrorInit, c as ErrorCategory, d as ErrorCode, e as ErrorFactory, S as SourceSpan, n as normalizeUnknownError } from './EngineError-
|
|
3
|
-
export { S as SerializedEngineError, W as WorkerErrorCodes, d as deserializeEngineError, s as serializeEngineError, w as workerCancelledError, a as workerTerminatedError, b as workerTransportError } from './WorkerError-
|
|
1
|
+
import { E as EngineError } from './EngineError-fR1K1rvx.js';
|
|
2
|
+
export { C as CoreErrorCode, a as CoreErrorCodes, b as EngineErrorInit, c as ErrorCategory, d as ErrorCode, e as ErrorFactory, S as SourceSpan, n as normalizeUnknownError } from './EngineError-fR1K1rvx.js';
|
|
3
|
+
export { S as SerializedEngineError, W as WorkerErrorCodes, d as deserializeEngineError, s as serializeEngineError, w as workerCancelledError, a as workerTerminatedError, b as workerTransportError } from './WorkerError-dneODN-u.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A Rust-style `Result<T, E>`, the value half of this engine's error-handling
|
package/dist/errors.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as WorkerErrorCodes,c as deserializeEngineError,b as serializeEngineError,d as workerCancelledError,e as workerTerminatedError,f as workerTransportError}from'./chunk-
|
|
1
|
+
export{a as WorkerErrorCodes,c as deserializeEngineError,b as serializeEngineError,d as workerCancelledError,e as workerTerminatedError,f as workerTransportError}from'./chunk-JFZ5SLF7.js';export{r as CoreErrorCodes,b as EngineError,a as ErrorCategory,c as ErrorFactory,k as andThen,n as combine,f as err,h as isErr,g as isOk,i as map,j as mapErr,m as match,d as normalizeUnknownError,e as ok,o as throwIfErr,p as tryCatch,q as tryCatchAsync,l as unwrapOr}from'./chunk-57PSJQQW.js';//# sourceMappingURL=errors.js.map
|
|
2
2
|
//# sourceMappingURL=errors.js.map
|
package/dist/format.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkXBGK3TTU_cjs=require('./chunk-XBGK3TTU.cjs');require('./chunk-R2SZFJTT.cjs'),require('./chunk-5TVI2UPZ.cjs'),require('./chunk-WGP4UUO5.cjs'),require('./chunk-SQHBOWES.cjs'),require('./chunk-S3DFU33X.cjs'),require('./chunk-YBQPEWT7.cjs');Object.defineProperty(exports,"DEFAULT_FORMATTING_SETTINGS",{enumerable:true,get:function(){return chunkXBGK3TTU_cjs.a}});Object.defineProperty(exports,"formatMatrixAligned",{enumerable:true,get:function(){return chunkXBGK3TTU_cjs.b}});Object.defineProperty(exports,"formatValue",{enumerable:true,get:function(){return chunkXBGK3TTU_cjs.c}});//# sourceMappingURL=format.cjs.map
|
|
2
2
|
//# sourceMappingURL=format.cjs.map
|
package/dist/format.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { V as Value, M as MatrixData } from './Value-Ds3Gy07C.cjs';
|
|
2
2
|
import { F as FormattingSettings } from './FormattingSettings-bRKjU7wI.cjs';
|
|
3
3
|
export { D as DEFAULT_FORMATTING_SETTINGS } from './FormattingSettings-bRKjU7wI.cjs';
|
|
4
4
|
|
package/dist/format.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { V as Value, M as MatrixData } from './Value-Ds3Gy07C.js';
|
|
2
2
|
import { F as FormattingSettings } from './FormattingSettings-bRKjU7wI.js';
|
|
3
3
|
export { D as DEFAULT_FORMATTING_SETTINGS } from './FormattingSettings-bRKjU7wI.js';
|
|
4
4
|
|
package/dist/format.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as DEFAULT_FORMATTING_SETTINGS,b as formatMatrixAligned,c as formatValue}from'./chunk-
|
|
1
|
+
export{a as DEFAULT_FORMATTING_SETTINGS,b as formatMatrixAligned,c as formatValue}from'./chunk-XX55RR4Q.js';import'./chunk-XEIDV5JP.js';import'./chunk-5TCSFTZD.js';import'./chunk-RDYXH7ML.js';import'./chunk-NMU5E7W7.js';import'./chunk-LHLW7JLS.js';import'./chunk-57PSJQQW.js';//# sourceMappingURL=format.js.map
|
|
2
2
|
//# sourceMappingURL=format.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';require('./chunk-
|
|
1
|
+
'use strict';require('./chunk-4BAUQE6A.cjs'),require('./chunk-EFJCC6FJ.cjs');var chunkSPOVFRZO_cjs=require('./chunk-SPOVFRZO.cjs');require('./chunk-VMSCRVNX.cjs'),require('./chunk-NGBBNL4K.cjs'),require('./chunk-ZVPZQ66D.cjs'),require('./chunk-TTFO4YDP.cjs'),require('./chunk-JSM3O7EM.cjs'),require('./chunk-HG4NPDN5.cjs');var chunkXBGK3TTU_cjs=require('./chunk-XBGK3TTU.cjs');require('./chunk-R2SZFJTT.cjs');var chunkUV3EUIBT_cjs=require('./chunk-UV3EUIBT.cjs');require('./chunk-NEGZZB7F.cjs'),require('./chunk-RAPEZR5L.cjs');var chunkFYTB7SDP_cjs=require('./chunk-FYTB7SDP.cjs');require('./chunk-GBCN7FNV.cjs'),require('./chunk-UURM7P3P.cjs'),require('./chunk-ZLRJ7TDP.cjs'),require('./chunk-634ILVMP.cjs'),require('./chunk-FYAMQFZZ.cjs'),require('./chunk-ABVDKMNF.cjs'),require('./chunk-TLG7VZRX.cjs'),require('./chunk-5TVI2UPZ.cjs'),require('./chunk-WGP4UUO5.cjs');var chunkSQHBOWES_cjs=require('./chunk-SQHBOWES.cjs');require('./chunk-ZKFCKAIX.cjs');var chunk4NZXCHQL_cjs=require('./chunk-4NZXCHQL.cjs');require('./chunk-BMXYR5LI.cjs'),require('./chunk-Y7O4D3BJ.cjs'),require('./chunk-77KI7AKJ.cjs'),require('./chunk-5IJD5L3O.cjs'),require('./chunk-S3DFU33X.cjs'),require('./chunk-J4LSAHCY.cjs'),require('./chunk-EZKR44MA.cjs');var chunkYBQPEWT7_cjs=require('./chunk-YBQPEWT7.cjs');var r={DEFINE_FUNCTION_INVALID_NAME:"DEFINE_FUNCTION_INVALID_NAME",DEFINE_FUNCTION_INVALID_SPEC:"DEFINE_FUNCTION_INVALID_SPEC",DEFINE_FUNCTION_ARITY_MISMATCH:"DEFINE_FUNCTION_ARITY_MISMATCH",DEFINE_FUNCTION_ARGUMENT_TYPE:"DEFINE_FUNCTION_ARGUMENT_TYPE",DEFINE_FUNCTION_RETURN_TYPE:"DEFINE_FUNCTION_RETURN_TYPE"},P=/^[a-z_][a-z0-9_]*$/i,N=new Set(["number","string","boolean"]);function u(e){return e===1?"1 argument":`${e} arguments`}function d(e){switch(e.type){case 0:case 1:return "a number";case 3:return "a string";case 10:return "a boolean";case 2:return "a big integer";case 5:return "a percentage";case 6:return "a value with a unit";case 4:return "a date";case 7:return "a matrix";case 8:return "a range";case 9:return "a symbolic expression";default:return "an unsupported value"}}function V(e,n,t){switch(n.type){case "number":if(e.type===0||e.type===1)return e.toNumber();break;case "string":if(e.type===3)return e.value;break;case "boolean":if(e.type===10)return e.value;break}throw chunkYBQPEWT7_cjs.c.execution({code:r.DEFINE_FUNCTION_ARGUMENT_TYPE,message:`${t}() expects "${n.name}" to be a ${n.type}, but was given ${d(e)}`,expected:`a ${n.type}`,found:d(e),context:{functionName:t,argName:n.name,expectedType:n.type}})}function O(e,n,t){switch(n){case "number":if(typeof e=="number")return chunkSQHBOWES_cjs.n(e);break;case "string":if(typeof e=="string")return chunkSQHBOWES_cjs.t(e);break;case "boolean":if(typeof e=="boolean")return chunkSQHBOWES_cjs.L(e);break}throw chunkYBQPEWT7_cjs.c.internal({code:r.DEFINE_FUNCTION_RETURN_TYPE,message:`${t}() is declared to return a ${n}, but its implementation returned ${typeof e}`,expected:`a ${n}`,found:typeof e,context:{functionName:t,expectedType:n}})}var p=class{constructor(n){this.fnName=n;this.category="Function";}parse(n,t,a){n.consume("LPAREN");let i=0;if(n.peek()?.type!=="RPAREN")for(n.parseExpression(chunkFYTB7SDP_cjs.a.Lowest,a),i++;n.match("COMMA");)n.parseExpression(chunkFYTB7SDP_cjs.a.Lowest,a),i++;n.consume("RPAREN"),a.emitPluginCall(this.fnName,i);}};function h(e){let n=e.args.length;return t=>{if(t.length!==n)throw chunkYBQPEWT7_cjs.c.execution({code:r.DEFINE_FUNCTION_ARITY_MISMATCH,message:`${e.name}() takes ${u(n)}, but was given ${t.length===0?"none":u(t.length)}`,expected:u(n),found:t.length===0?"none":u(t.length),context:{functionName:e.name,expected:n,actual:t.length}});let a=new Array(n);for(let s=0;s<n;s++)a[s]=V(t[s],e.args[s],e.name);let i=e.call(...a);return O(i,e.returns,e.name)}}function R(e){if(typeof e?.name!="string"||!P.test(e.name))throw chunkYBQPEWT7_cjs.c.config({code:r.DEFINE_FUNCTION_INVALID_NAME,message:`defineFunction: name must be a single identifier, got ${JSON.stringify(e?.name)}`,suggestion:'e.g. "vat" or "net_price"',context:{name:e?.name}});if(!Array.isArray(e.args))throw chunkYBQPEWT7_cjs.c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" args must be an array`,context:{name:e.name}});for(let n of e.args){if(typeof n?.name!="string"||n.name.length===0)throw chunkYBQPEWT7_cjs.c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" has an argument with no name`,context:{name:e.name}});if(!N.has(n.type))throw chunkYBQPEWT7_cjs.c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" argument "${n.name}" has unsupported type ${JSON.stringify(n.type)}`,suggestion:"supported argument types are number, string, boolean",context:{name:e.name,argName:n.name,type:n.type}})}if(!N.has(e.returns))throw chunkYBQPEWT7_cjs.c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" has unsupported return type ${JSON.stringify(e.returns)}`,suggestion:"supported return types are number, string, boolean",context:{name:e.name,returns:e.returns}});if(typeof e.call!="function")throw chunkYBQPEWT7_cjs.c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" is missing a call implementation`,context:{name:e.name}})}function k(e){R(e);let n=e.name,t=`DEFINE_FN_${n.toUpperCase()}`;return {name:`solve-fn-${n}`,lexerVocabulary:{keywords:{[n.toLowerCase()]:t}},prefixParselets:{[t]:new p(n)},pluginFunctions:{[n]:h(e)}}}function D(e={}){let{extraPackages:n=[],...t}=e;return new chunkSPOVFRZO_cjs.n({...t,packages:n.length>0?[...chunkUV3EUIBT_cjs.z,...n]:chunkUV3EUIBT_cjs.z})}Object.defineProperty(exports,"ExpressionEngine",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.n}});Object.defineProperty(exports,"SNAPSHOT_FORMAT",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.d}});Object.defineProperty(exports,"SNAPSHOT_VERSION",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.e}});Object.defineProperty(exports,"SnapshotErrorCodes",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.f}});Object.defineProperty(exports,"assertEngineVersionCompatible",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.c}});Object.defineProperty(exports,"checkEngineVersionCompatibility",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.b}});Object.defineProperty(exports,"checkPackageCompatibility",{enumerable:true,get:function(){return chunkSPOVFRZO_cjs.a}});Object.defineProperty(exports,"formatValue",{enumerable:true,get:function(){return chunkXBGK3TTU_cjs.c}});Object.defineProperty(exports,"Value",{enumerable:true,get:function(){return chunkSQHBOWES_cjs.m}});Object.defineProperty(exports,"ValueType",{enumerable:true,get:function(){return chunkSQHBOWES_cjs.g}});Object.defineProperty(exports,"ENGINE_VERSION",{enumerable:true,get:function(){return chunk4NZXCHQL_cjs.a}});exports.DefineFunctionErrorCodes=r;exports.createEngine=D;exports.defineFunction=k;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api/defineFunction.ts","../src/api/createEngine.ts"],"names":["DefineFunctionErrorCodes","NAME_PATTERN","SUPPORTED_TYPES","plural","count","describeValueType","v","coerceArgument","value","arg","fnName","ErrorFactory","wrapReturn","result","returns","numberValue","stringValue","boolValue","DefinedFunctionParselet","parser","_token","builder","argCount","BindingPower","makeHandler","spec","arity","args","jsArgs","i","validateSpec","defineFunction","name","tokenType","createEngine","options","extraPackages","engineOptions","ExpressionEngine","BUILTIN_PACKAGES"],"mappings":"ivCAkFO,IAAMA,EAA2B,CAEtC,4BAAA,CAA8B,+BAE9B,4BAAA,CAA8B,8BAAA,CAE9B,+BAAgC,gCAAA,CAEhC,6BAAA,CAA+B,+BAAA,CAE/B,2BAAA,CAA6B,6BAC/B,CAAA,CAGMC,CAAAA,CAAe,sBAEfC,CAAAA,CAAuC,IAAI,IAAI,CAAC,QAAA,CAAU,QAAA,CAAU,SAAS,CAAC,EAGpF,SAASC,EAAOC,CAAAA,CAAuB,CACrC,OAAOA,CAAAA,GAAU,CAAA,CAAI,aAAe,CAAA,EAAGA,CAAK,YAC9C,CAQA,SAASC,EAAkBC,CAAAA,CAAkB,CAC3C,OAAQA,CAAAA,CAAE,IAAA,EACR,KAAA,CAAA,CACA,OACE,OAAO,UAAA,CACT,OACE,OAAO,UAAA,CACT,QACE,OAAO,WAAA,CACT,KAAA,CAAA,CACE,OAAO,gBACT,KAAA,CAAA,CACE,OAAO,eACT,KAAA,CAAA,CACE,OAAO,sBACT,KAAA,CAAA,CACE,OAAO,QAAA,CACT,KAAA,CAAA,CACE,OAAO,UAAA,CACT,KAAA,CAAA,CACE,OAAO,SAAA,CACT,KAAA,CAAA,CACE,OAAO,uBAAA,CACT,QACE,OAAO,sBACX,CACF,CAYA,SAASC,CAAAA,CACPC,EACAC,CAAAA,CACAC,CAAAA,CAC2B,CAC3B,OAAQD,CAAAA,CAAI,IAAA,EACV,KAAK,QAAA,CAEH,GAAID,EAAM,IAAA,GAAS,CAAA,EAAoBA,EAAM,IAAA,GAAS,CAAA,CACpD,OAAOA,CAAAA,CAAM,UAAS,CAExB,MACF,KAAK,QAAA,CACH,GAAIA,EAAM,IAAA,GAAS,CAAA,CAAkB,OAAOA,CAAAA,CAAM,MAClD,MACF,KAAK,UACH,GAAIA,CAAAA,CAAM,OAAS,EAAA,CAAmB,OAAOA,EAAM,KAAA,CAC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AAA,iBAAA,EAAoByB,CAAAA,CAAK,IAAI,CAAA,kCAAA,CAAA,CACtC,OAAA,CAAS,CAAE,IAAA,CAAMA,CAAAA,CAAK,IAAK,CAC7B,CAAC,CAEL,CA0CO,SAASM,CAAAA,CAGdN,CAAAA,CAA0C,CAC1CK,CAAAA,CAAaL,CAAoB,EAEjC,IAAMO,CAAAA,CAAOP,EAAK,IAAA,CAIZQ,CAAAA,CAAY,CAAA,UAAA,EAAaD,CAAAA,CAAK,aAAa,CAAA,CAAA,CAEjD,OAAO,CACL,IAAA,CAAM,YAAYA,CAAI,CAAA,CAAA,CACtB,eAAA,CAAiB,CAGf,SAAU,CAAE,CAACA,EAAK,WAAA,EAAa,EAAGC,CAAU,CAC9C,EACA,eAAA,CAAiB,CACf,CAACA,CAAS,EAAG,IAAIf,CAAAA,CAAwBc,CAAI,CAC/C,CAAA,CACA,eAAA,CAAiB,CACf,CAACA,CAAI,EAAGR,CAAAA,CAAYC,CAAoB,CAC1C,CACF,CACF,CCrWO,SAASS,EAAaC,CAAAA,CAA+B,GAAsB,CACjF,GAAM,CAAE,aAAA,CAAAC,CAAAA,CAAgB,EAAC,CAAG,GAAGC,CAAc,CAAA,CAAIF,EACjD,OAAO,IAAIG,oBAAiB,CAC3B,GAAGD,EACH,QAAA,CAAUD,CAAAA,CAAc,OAAS,CAAA,CAAI,CAAC,GAAGG,mBAAAA,CAAkB,GAAGH,CAAa,CAAA,CAAIG,mBAChF,CAAC,CACF","file":"index.cjs","sourcesContent":["import type { IEnginePackage } from \"@solve-js/api/PackageRegistry\";\nimport type { PrefixParselet } from \"@solve-js/parser/Parselet\";\nimport type { Parser } from \"@solve-js/parser/Parser\";\nimport type { Token } from \"@solve-js/lexer/Token\";\nimport type { BytecodeBuilder } from \"@solve-js/parser/BytecodeBuilder\";\nimport { BindingPower } from \"@solve-js/parser/BindingPower\";\nimport {\n Value,\n ValueType,\n numberValue,\n stringValue,\n boolValue,\n} from \"@solve-js/vm/Value\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * A higher-level, declarative way to contribute a single `name(args)`\n * function, sitting ON TOP OF the package contract rather than replacing it.\n *\n * The low-level contract (allocate a plugin function index, write a parselet,\n * emit `CALL_PLUGIN`) stays exactly as it was and remains the way to add\n * anything that needs custom parsing. This module derives that same wiring\n * from a declaration for the common case, a function called with parenthesised\n * arguments, so adding `vat(x)` costs a spec object rather than an\n * understanding of the parser and the VM. See `defineFunction`.\n */\n\n/** The value types a declared argument or return may take. */\nexport type FunctionValueType = \"number\" | \"string\" | \"boolean\";\n\n/** The JavaScript type a {@link FunctionValueType} maps to at the `call` boundary. */\ntype JsValue<T extends FunctionValueType> = T extends \"number\"\n ? number\n : T extends \"string\"\n ? string\n : boolean;\n\n/** One declared parameter: a name (for error messages) and a value type. */\nexport interface FunctionArg {\n /** Parameter name, used only in the generated type-mismatch messages. */\n name: string;\n /** The value type this parameter accepts. */\n type: FunctionValueType;\n}\n\n/** Map a tuple of {@link FunctionArg} specs to the tuple of JS values `call` receives. */\ntype CallArgs<A extends readonly FunctionArg[]> = {\n [K in keyof A]: JsValue<A[K][\"type\"]>;\n};\n\n/**\n * A declarative function definition.\n *\n * `A` and `R` are inferred from the literal `args`/`returns` (via\n * `defineFunction`'s `const` type parameter), so `call`'s parameters and\n * return are typed from the declaration with no annotations: an\n * `{ type: \"number\" }` argument arrives as a `number`, and a `returns:\n * \"string\"` demands a `string` back.\n */\nexport interface FunctionSpec<\n A extends readonly FunctionArg[] = readonly FunctionArg[],\n R extends FunctionValueType = FunctionValueType,\n> {\n /**\n * The call name, a single identifier (`/^[a-z_][a-z0-9_]*$/i`). Registered\n * as a lexer keyword, so it is matched case-insensitively and cannot collide\n * with a built-in keyword (that collision throws at registration time).\n */\n name: string;\n /** The parameters, in order. A fixed-length list: variadic and optional args are out of scope (see {@link defineFunction}). */\n args: A;\n /** The value type the function returns. */\n returns: R;\n /** The implementation, receiving plain JS values and returning one. Must be synchronous (see {@link defineFunction}). */\n call: (...args: CallArgs<A>) => JsValue<R>;\n}\n\n/**\n * Error codes the declarative function API raises. Kept as a co-located const\n * (the convention `errors/ErrorCode.ts` documents for a domain's own codes) so\n * the strings have one source of truth.\n */\nexport const DefineFunctionErrorCodes = {\n /** The spec's `name` is not a single identifier. Thrown by `defineFunction`, before any engine sees it. */\n DEFINE_FUNCTION_INVALID_NAME: \"DEFINE_FUNCTION_INVALID_NAME\",\n /** The spec is otherwise malformed (bad `args`, unsupported type, missing `call`). Thrown by `defineFunction`. */\n DEFINE_FUNCTION_INVALID_SPEC: \"DEFINE_FUNCTION_INVALID_SPEC\",\n /** The call site passed the wrong number of arguments. Raised at evaluation time. */\n DEFINE_FUNCTION_ARITY_MISMATCH: \"DEFINE_FUNCTION_ARITY_MISMATCH\",\n /** An argument was the wrong value type. Raised at evaluation time. */\n DEFINE_FUNCTION_ARGUMENT_TYPE: \"DEFINE_FUNCTION_ARGUMENT_TYPE\",\n /** The `call` implementation returned a value that did not match `returns`. Raised at evaluation time, an authoring bug rather than a user one. */\n DEFINE_FUNCTION_RETURN_TYPE: \"DEFINE_FUNCTION_RETURN_TYPE\",\n} as const;\n\n/** A single identifier: a letter or underscore, then letters, digits, or underscores. */\nconst NAME_PATTERN = /^[a-z_][a-z0-9_]*$/i;\n\nconst SUPPORTED_TYPES: ReadonlySet<string> = new Set([\"number\", \"string\", \"boolean\"]);\n\n/** \"1 argument\" / \"2 arguments\", so a count reads as English either way. Mirrors `VMBuiltinArity.ts`. */\nfunction plural(count: number): string {\n return count === 1 ? \"1 argument\" : `${count} arguments`;\n}\n\n/**\n * A human noun for the type a Value actually carries, for the \"was given ...\"\n * half of a mismatch message. Covers the three declarable types by their own\n * names and everything else by a readable category, so the message never reads\n * \"given a 6\".\n */\nfunction describeValueType(v: Value): string {\n switch (v.type) {\n case ValueType.Number:\n case ValueType.Hex:\n return \"a number\";\n case ValueType.String:\n return \"a string\";\n case ValueType.Boolean:\n return \"a boolean\";\n case ValueType.BigInt:\n return \"a big integer\";\n case ValueType.Percentage:\n return \"a percentage\";\n case ValueType.Uom:\n return \"a value with a unit\";\n case ValueType.Datetime:\n return \"a date\";\n case ValueType.Matrix:\n return \"a matrix\";\n case ValueType.Range:\n return \"a range\";\n case ValueType.Symbolic:\n return \"a symbolic expression\";\n default:\n return \"an unsupported value\";\n }\n}\n\n/**\n * Read one runtime Value as the JS primitive its declared type promises, or\n * raise the engine's structured type error.\n *\n * A \"number\" accepts a plain number or a based literal (`0xFF`), both of which\n * ARE numbers written differently, and reads it with `toNumber()`. Nothing\n * else is coerced: a percentage, a unit-bearing value or a string is a\n * genuinely different kind of value, and silently reinterpreting it is the\n * class of wrong-answer this API exists to avoid.\n */\nfunction coerceArgument(\n value: Value,\n arg: FunctionArg,\n fnName: string,\n): number | string | boolean {\n switch (arg.type) {\n case \"number\":\n // Hex is a number in another base (see `hexValue`), so it reads as one here.\n if (value.type === ValueType.Number || value.type === ValueType.Hex) {\n return value.toNumber();\n }\n break;\n case \"string\":\n if (value.type === ValueType.String) return value.value as string;\n break;\n case \"boolean\":\n if (value.type === ValueType.Boolean) return value.value as boolean;\n break;\n }\n throw ErrorFactory.execution({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_ARGUMENT_TYPE,\n message: `${fnName}() expects \"${arg.name}\" to be a ${arg.type}, but was given ${describeValueType(value)}`,\n expected: `a ${arg.type}`,\n found: describeValueType(value),\n context: { functionName: fnName, argName: arg.name, expectedType: arg.type },\n });\n}\n\n/**\n * Wrap the `call` result back into a Value of the declared return type, or\n * raise a structured error if the implementation handed back something else.\n *\n * The type check here catches an authoring mistake (a function declared to\n * return a number that returns `undefined`, or a Promise from an accidental\n * `async`), turning it into a named error rather than a Value that lies about\n * its own type downstream.\n */\nfunction wrapReturn(result: unknown, returns: FunctionValueType, fnName: string): Value {\n switch (returns) {\n case \"number\":\n if (typeof result === \"number\") return numberValue(result);\n break;\n case \"string\":\n if (typeof result === \"string\") return stringValue(result);\n break;\n case \"boolean\":\n if (typeof result === \"boolean\") return boolValue(result);\n break;\n }\n throw ErrorFactory.internal({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_RETURN_TYPE,\n message: `${fnName}() is declared to return a ${returns}, but its implementation returned ${typeof result}`,\n expected: `a ${returns}`,\n found: typeof result,\n context: { functionName: fnName, expectedType: returns },\n });\n}\n\n/**\n * The call-syntax parselet generated for one declared function.\n *\n * Identical in shape to the built-in `FunctionCallParselet`: consume the open\n * paren, parse a comma-separated argument list, then emit `CALL_PLUGIN` with\n * the function's index and the argument count. The count is whatever was\n * written, arity is checked at the dispatch point (see {@link makeHandler}),\n * the same place the built-in arity check lives.\n */\nclass DefinedFunctionParselet implements PrefixParselet {\n readonly category = \"Function\";\n\n constructor(\n private readonly fnName: string,\n ) {}\n\n parse(parser: Parser, _token: Token, builder: BytecodeBuilder): void {\n parser.consume(\"LPAREN\");\n\n let argCount = 0;\n if (parser.peek()?.type !== \"RPAREN\") {\n parser.parseExpression(BindingPower.Lowest, builder);\n argCount++;\n while (parser.match(\"COMMA\")) {\n parser.parseExpression(BindingPower.Lowest, builder);\n argCount++;\n }\n }\n\n parser.consume(\"RPAREN\");\n\n builder.emitPluginCall(this.fnName, argCount);\n }\n}\n\n/**\n * Build the plugin function that checks arity and argument types, calls the\n * host implementation, and wraps the result.\n *\n * The VM has already screened out faulted arguments (an errored or still\n * pending operand short-circuits before the handler runs, see\n * `VM.ts`'s `CALL_PLUGIN` case), so every Value reaching here carries a real\n * result. Arity is checked first, before any argument is read, so a wrong\n * count is reported as a wrong count rather than as a type error on a missing\n * argument.\n */\nfunction makeHandler(spec: FunctionSpec): (args: Value[]) => Value {\n const arity = spec.args.length;\n return (args: Value[]): Value => {\n if (args.length !== arity) {\n throw ErrorFactory.execution({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_ARITY_MISMATCH,\n message: `${spec.name}() takes ${plural(arity)}, but was given ${args.length === 0 ? \"none\" : plural(args.length)}`,\n expected: plural(arity),\n found: args.length === 0 ? \"none\" : plural(args.length),\n context: { functionName: spec.name, expected: arity, actual: args.length },\n });\n }\n\n const jsArgs: (number | string | boolean)[] = new Array(arity);\n for (let i = 0; i < arity; i++) {\n jsArgs[i] = coerceArgument(args[i], spec.args[i], spec.name);\n }\n\n const result = (spec.call as (...a: (number | string | boolean)[]) => unknown)(...jsArgs);\n return wrapReturn(result, spec.returns, spec.name);\n };\n}\n\n/** Reject a spec that could not produce a working function, before any engine sees it. */\nfunction validateSpec(spec: FunctionSpec): void {\n if (typeof spec?.name !== \"string\" || !NAME_PATTERN.test(spec.name)) {\n throw ErrorFactory.config({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_INVALID_NAME,\n message: `defineFunction: name must be a single identifier, got ${JSON.stringify(spec?.name)}`,\n suggestion: 'e.g. \"vat\" or \"net_price\"',\n context: { name: spec?.name },\n });\n }\n if (!Array.isArray(spec.args)) {\n throw ErrorFactory.config({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_INVALID_SPEC,\n message: `defineFunction: \"${spec.name}\" args must be an array`,\n context: { name: spec.name },\n });\n }\n for (const arg of spec.args) {\n if (typeof arg?.name !== \"string\" || arg.name.length === 0) {\n throw ErrorFactory.config({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_INVALID_SPEC,\n message: `defineFunction: \"${spec.name}\" has an argument with no name`,\n context: { name: spec.name },\n });\n }\n if (!SUPPORTED_TYPES.has(arg.type)) {\n throw ErrorFactory.config({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_INVALID_SPEC,\n message: `defineFunction: \"${spec.name}\" argument \"${arg.name}\" has unsupported type ${JSON.stringify(arg.type)}`,\n suggestion: \"supported argument types are number, string, boolean\",\n context: { name: spec.name, argName: arg.name, type: arg.type },\n });\n }\n }\n if (!SUPPORTED_TYPES.has(spec.returns)) {\n throw ErrorFactory.config({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_INVALID_SPEC,\n message: `defineFunction: \"${spec.name}\" has unsupported return type ${JSON.stringify(spec.returns)}`,\n suggestion: \"supported return types are number, string, boolean\",\n context: { name: spec.name, returns: spec.returns },\n });\n }\n if (typeof spec.call !== \"function\") {\n throw ErrorFactory.config({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_INVALID_SPEC,\n message: `defineFunction: \"${spec.name}\" is missing a call implementation`,\n context: { name: spec.name },\n });\n }\n}\n\n/**\n * Turn a declarative {@link FunctionSpec} into a ready-to-register\n * {@link IEnginePackage}.\n *\n * This is the higher-level API from issue #102. It derives, from the\n * declaration alone, everything the low-level contract asks an author to write\n * by hand: a named plugin function (the engine assigns its `CALL_PLUGIN`\n * index), a lexer keyword so the name tokenises, a call-syntax parselet emitting\n * that call by name, and a handler that checks arity and argument types (yielding\n * the engine's own structured errors) before invoking `call` and wrapping its\n * result. Anything needing custom parsing keeps writing a raw parselet exactly\n * as before, this sits on top of that contract and does not change it.\n *\n * @example\n * ```ts\n * const engine = new ExpressionEngine({ packages: [\n * ...BUILTIN_PACKAGES,\n * defineFunction({\n * name: \"vat\",\n * args: [{ name: \"amount\", type: \"number\" }],\n * returns: \"number\",\n * call: (amount) => amount * 1.2,\n * }),\n * ] });\n * engine.evaluateExpression(\"vat(100)\"); // 120\n * ```\n *\n * The returned package is self-contained and composes with any others through\n * the engine's `packages` array; register several functions by passing several\n * packages. Its name is `solve-fn-<name>`.\n *\n * Scope: arguments are a fixed-length list of `number`/`string`/`boolean`, and\n * `call` is synchronous. Variadic and optional arguments, other value types\n * (units, percentages, dates, matrices), and async work are deliberately out\n * of scope, a function needing any of those keeps using the low-level\n * contract, whose parselets and async resolvers are unchanged.\n *\n * @throws {EngineError} (category CONFIG) if the spec is malformed, at the\n * point `defineFunction` is called, before the package reaches an engine.\n */\nexport function defineFunction<\n const A extends readonly FunctionArg[],\n R extends FunctionValueType,\n>(spec: FunctionSpec<A, R>): IEnginePackage {\n validateSpec(spec as FunctionSpec);\n\n const name = spec.name;\n // Uppercased so the generated type is a valid, collision-resistant token\n // type; the name pattern guarantees it forms one. Distinct from the\n // built-in FUNC type, so this never routes through the builtin name map.\n const tokenType = `DEFINE_FN_${name.toUpperCase()}`;\n\n return {\n name: `solve-fn-${name}`,\n lexerVocabulary: {\n // Lowercased because the lexer lowercases input before lookup, so the\n // call is matched case-insensitively.\n keywords: { [name.toLowerCase()]: tokenType },\n },\n prefixParselets: {\n [tokenType]: new DefinedFunctionParselet(name),\n },\n pluginFunctions: {\n [name]: makeHandler(spec as FunctionSpec),\n },\n };\n}\n","import { ExpressionEngine, type EngineOptions } from \"@solve-js/engine/ExpressionEngine\";\nimport { BUILTIN_PACKAGES } from \"@solve-js/packages/builtins\";\nimport type { IEnginePackage } from \"@solve-js/api/PackageRegistry\";\n\n/** Options for {@link createEngine}: the engine options, minus `packages` (the\n * built-in set is always registered), plus `extraPackages` to add your own. */\nexport interface CreateEngineOptions extends Omit<EngineOptions, \"packages\"> {\n\t/** Packages to register ON TOP of the built-in set (e.g. an OSRS or stocks package). */\n\textraPackages?: IEnginePackage[];\n}\n\n/**\n * A batteries-included {@link ExpressionEngine} with every built-in package\n * registered.\n *\n * The constructor registers only the packages it is given, so a consumer's\n * bundler can tree-shake away the built-ins they never use: an engine built\n * with `new ExpressionEngine({ packages: [ARITHMETIC_PACKAGE] })` carries no\n * finance, colour or weather code. This convenience is the opposite trade: it\n * pulls the FULL built-in set (`BUILTIN_PACKAGES`) for the common \"I want\n * everything\" case, so importing it defeats that tree-shaking. Reach for the\n * constructor with an explicit package list when bundle size matters, and for\n * `createEngine` when it does not.\n *\n * @param options - Engine options ({@link EngineOptions}) minus `packages`, plus\n * an optional `extraPackages` to register alongside the built-in set.\n * @returns An engine with the built-in packages (and any extras) registered.\n *\n * @example\n * ```typescript\n * import { createEngine } from \"solve-engine\";\n * const engine = createEngine();\n * const value = engine.evaluateExpression(\"2 + 2 * 10\");\n * console.log(value.toNumber()); // 22\n * ```\n */\nexport function createEngine(options: CreateEngineOptions = {}): ExpressionEngine {\n\tconst { extraPackages = [], ...engineOptions } = options;\n\treturn new ExpressionEngine({\n\t\t...engineOptions,\n\t\tpackages: extraPackages.length > 0 ? [...BUILTIN_PACKAGES, ...extraPackages] : BUILTIN_PACKAGES,\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/api/defineFunction.ts","../src/api/createEngine.ts"],"names":["DefineFunctionErrorCodes","NAME_PATTERN","SUPPORTED_TYPES","plural","count","describeValueType","v","coerceArgument","value","arg","fnName","ErrorFactory","wrapReturn","result","returns","numberValue","stringValue","boolValue","DefinedFunctionParselet","parser","_token","builder","argCount","BindingPower","makeHandler","spec","arity","args","jsArgs","i","validateSpec","defineFunction","name","tokenType","createEngine","options","extraPackages","engineOptions","ExpressionEngine","BUILTIN_PACKAGES"],"mappings":"uwCAkFO,IAAMA,EAA2B,CAEtC,4BAAA,CAA8B,+BAE9B,4BAAA,CAA8B,8BAAA,CAE9B,+BAAgC,gCAAA,CAEhC,6BAAA,CAA+B,+BAAA,CAE/B,2BAAA,CAA6B,6BAC/B,CAAA,CAGMC,CAAAA,CAAe,sBAEfC,CAAAA,CAAuC,IAAI,IAAI,CAAC,QAAA,CAAU,QAAA,CAAU,SAAS,CAAC,EAGpF,SAASC,EAAOC,CAAAA,CAAuB,CACrC,OAAOA,CAAAA,GAAU,CAAA,CAAI,aAAe,CAAA,EAAGA,CAAK,YAC9C,CAQA,SAASC,EAAkBC,CAAAA,CAAkB,CAC3C,OAAQA,CAAAA,CAAE,IAAA,EACR,KAAA,CAAA,CACA,OACE,OAAO,UAAA,CACT,OACE,OAAO,UAAA,CACT,QACE,OAAO,WAAA,CACT,KAAA,CAAA,CACE,OAAO,gBACT,KAAA,CAAA,CACE,OAAO,eACT,KAAA,CAAA,CACE,OAAO,sBACT,KAAA,CAAA,CACE,OAAO,QAAA,CACT,KAAA,CAAA,CACE,OAAO,UAAA,CACT,KAAA,CAAA,CACE,OAAO,SAAA,CACT,KAAA,CAAA,CACE,OAAO,uBAAA,CACT,QACE,OAAO,sBACX,CACF,CA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AAAA,CAAkB,GAAGH,CAAa,CAAA,CAAIG,mBAChF,CAAC,CACF","file":"index.cjs","sourcesContent":["import type { IEnginePackage } from \"@solve-js/api/PackageRegistry\";\nimport type { PrefixParselet } from \"@solve-js/parser/Parselet\";\nimport type { Parser } from \"@solve-js/parser/Parser\";\nimport type { Token } from \"@solve-js/lexer/Token\";\nimport type { BytecodeBuilder } from \"@solve-js/parser/BytecodeBuilder\";\nimport { BindingPower } from \"@solve-js/parser/BindingPower\";\nimport {\n Value,\n ValueType,\n numberValue,\n stringValue,\n boolValue,\n} from \"@solve-js/vm/Value\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * A higher-level, declarative way to contribute a single `name(args)`\n * function, sitting ON TOP OF the package contract rather than replacing it.\n *\n * The low-level contract (allocate a plugin function index, write a parselet,\n * emit `CALL_PLUGIN`) stays exactly as it was and remains the way to add\n * anything that needs custom parsing. This module derives that same wiring\n * from a declaration for the common case, a function called with parenthesised\n * arguments, so adding `vat(x)` costs a spec object rather than an\n * understanding of the parser and the VM. See `defineFunction`.\n */\n\n/** The value types a declared argument or return may take. */\nexport type FunctionValueType = \"number\" | \"string\" | \"boolean\";\n\n/** The JavaScript type a {@link FunctionValueType} maps to at the `call` boundary. */\ntype JsValue<T extends FunctionValueType> = T extends \"number\"\n ? number\n : T extends \"string\"\n ? string\n : boolean;\n\n/** One declared parameter: a name (for error messages) and a value type. */\nexport interface FunctionArg {\n /** Parameter name, used only in the generated type-mismatch messages. */\n name: string;\n /** The value type this parameter accepts. */\n type: FunctionValueType;\n}\n\n/** Map a tuple of {@link FunctionArg} specs to the tuple of JS values `call` receives. */\ntype CallArgs<A extends readonly FunctionArg[]> = {\n [K in keyof A]: JsValue<A[K][\"type\"]>;\n};\n\n/**\n * A declarative function definition.\n *\n * `A` and `R` are inferred from the literal `args`/`returns` (via\n * `defineFunction`'s `const` type parameter), so `call`'s parameters and\n * return are typed from the declaration with no annotations: an\n * `{ type: \"number\" }` argument arrives as a `number`, and a `returns:\n * \"string\"` demands a `string` back.\n */\nexport interface FunctionSpec<\n A extends readonly FunctionArg[] = readonly FunctionArg[],\n R extends FunctionValueType = FunctionValueType,\n> {\n /**\n * The call name, a single identifier (`/^[a-z_][a-z0-9_]*$/i`). Registered\n * as a lexer keyword, so it is matched case-insensitively and cannot collide\n * with a built-in keyword (that collision throws at registration time).\n */\n name: string;\n /** The parameters, in order. A fixed-length list: variadic and optional args are out of scope (see {@link defineFunction}). */\n args: A;\n /** The value type the function returns. */\n returns: R;\n /** The implementation, receiving plain JS values and returning one. Must be synchronous (see {@link defineFunction}). */\n call: (...args: CallArgs<A>) => JsValue<R>;\n}\n\n/**\n * Error codes the declarative function API raises. Kept as a co-located const\n * (the convention `errors/ErrorCode.ts` documents for a domain's own codes) so\n * the strings have one source of truth.\n */\nexport const DefineFunctionErrorCodes = {\n /** The spec's `name` is not a single identifier. Thrown by `defineFunction`, before any engine sees it. */\n DEFINE_FUNCTION_INVALID_NAME: \"DEFINE_FUNCTION_INVALID_NAME\",\n /** The spec is otherwise malformed (bad `args`, unsupported type, missing `call`). Thrown by `defineFunction`. */\n DEFINE_FUNCTION_INVALID_SPEC: \"DEFINE_FUNCTION_INVALID_SPEC\",\n /** The call site passed the wrong number of arguments. Raised at evaluation time. */\n DEFINE_FUNCTION_ARITY_MISMATCH: \"DEFINE_FUNCTION_ARITY_MISMATCH\",\n /** An argument was the wrong value type. Raised at evaluation time. */\n DEFINE_FUNCTION_ARGUMENT_TYPE: \"DEFINE_FUNCTION_ARGUMENT_TYPE\",\n /** The `call` implementation returned a value that did not match `returns`. Raised at evaluation time, an authoring bug rather than a user one. */\n DEFINE_FUNCTION_RETURN_TYPE: \"DEFINE_FUNCTION_RETURN_TYPE\",\n} as const;\n\n/** A single identifier: a letter or underscore, then letters, digits, or underscores. */\nconst NAME_PATTERN = /^[a-z_][a-z0-9_]*$/i;\n\nconst SUPPORTED_TYPES: ReadonlySet<string> = new Set([\"number\", \"string\", \"boolean\"]);\n\n/** \"1 argument\" / \"2 arguments\", so a count reads as English either way. Mirrors `VMBuiltinArity.ts`. */\nfunction plural(count: number): string {\n return count === 1 ? \"1 argument\" : `${count} arguments`;\n}\n\n/**\n * A human noun for the type a Value actually carries, for the \"was given ...\"\n * half of a mismatch message. Covers the three declarable types by their own\n * names and everything else by a readable category, so the message never reads\n * \"given a 6\".\n */\nfunction describeValueType(v: Value): string {\n switch (v.type) {\n case ValueType.Number:\n case ValueType.Hex:\n return \"a number\";\n case ValueType.String:\n return \"a string\";\n case ValueType.Boolean:\n return \"a boolean\";\n case ValueType.BigInt:\n return \"a big integer\";\n case ValueType.Percentage:\n return \"a percentage\";\n case ValueType.Uom:\n return \"a value with a unit\";\n case ValueType.Datetime:\n return \"a date\";\n case ValueType.Matrix:\n return \"a matrix\";\n case ValueType.Range:\n return \"a range\";\n case ValueType.Symbolic:\n return \"a symbolic expression\";\n default:\n return \"an unsupported value\";\n }\n}\n\n/**\n * Read one runtime Value as the JS primitive its declared type promises, or\n * raise the engine's structured type error.\n *\n * A \"number\" accepts a plain number or a based literal (`0xFF`), both of which\n * ARE numbers written differently, and reads it with `toNumber()`. Nothing\n * else is coerced: a percentage, a unit-bearing value or a string is a\n * genuinely different kind of value, and silently reinterpreting it is the\n * class of wrong-answer this API exists to avoid.\n */\nfunction coerceArgument(\n value: Value,\n arg: FunctionArg,\n fnName: string,\n): number | string | boolean {\n switch (arg.type) {\n case \"number\":\n // Hex is a number in another base (see `hexValue`), so it reads as one here.\n if (value.type === ValueType.Number || value.type === ValueType.Hex) {\n return value.toNumber();\n }\n break;\n case \"string\":\n if (value.type === ValueType.String) return value.value as string;\n break;\n case \"boolean\":\n if (value.type === ValueType.Boolean) return value.value as boolean;\n break;\n }\n throw ErrorFactory.execution({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_ARGUMENT_TYPE,\n message: `${fnName}() expects \"${arg.name}\" to be a ${arg.type}, but was given ${describeValueType(value)}`,\n expected: `a ${arg.type}`,\n found: describeValueType(value),\n context: { functionName: fnName, argName: arg.name, expectedType: arg.type },\n });\n}\n\n/**\n * Wrap the `call` result back into a Value of the declared return type, or\n * raise a structured error if the implementation handed back something else.\n *\n * The type check here catches an authoring mistake (a function declared to\n * return a number that returns `undefined`, or a Promise from an accidental\n * `async`), turning it into a named error rather than a Value that lies about\n * its own type downstream.\n */\nfunction wrapReturn(result: unknown, returns: FunctionValueType, fnName: string): Value {\n switch (returns) {\n case \"number\":\n if (typeof result === \"number\") return numberValue(result);\n break;\n case \"string\":\n if (typeof result === \"string\") return stringValue(result);\n break;\n case \"boolean\":\n if (typeof result === \"boolean\") return boolValue(result);\n break;\n }\n throw ErrorFactory.internal({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_RETURN_TYPE,\n message: `${fnName}() is declared to return a ${returns}, but its implementation returned ${typeof result}`,\n expected: `a ${returns}`,\n found: typeof result,\n context: { functionName: fnName, expectedType: returns },\n });\n}\n\n/**\n * The call-syntax parselet generated for one declared function.\n *\n * Identical in shape to the built-in `FunctionCallParselet`: consume the open\n * paren, parse a comma-separated argument list, then emit `CALL_PLUGIN` with\n * the function's index and the argument count. The count is whatever was\n * written, arity is checked at the dispatch point (see {@link makeHandler}),\n * the same place the built-in arity check lives.\n */\nclass DefinedFunctionParselet implements PrefixParselet {\n readonly category = \"Function\";\n\n constructor(\n private readonly fnName: string,\n ) {}\n\n parse(parser: Parser, _token: Token, builder: BytecodeBuilder): void {\n parser.consume(\"LPAREN\");\n\n let argCount = 0;\n if (parser.peek()?.type !== \"RPAREN\") {\n parser.parseExpression(BindingPower.Lowest, builder);\n argCount++;\n while (parser.match(\"COMMA\")) {\n parser.parseExpression(BindingPower.Lowest, builder);\n argCount++;\n }\n }\n\n parser.consume(\"RPAREN\");\n\n builder.emitPluginCall(this.fnName, argCount);\n }\n}\n\n/**\n * Build the plugin function that checks arity and argument types, calls the\n * host implementation, and wraps the result.\n *\n * The VM has already screened out faulted arguments (an errored or still\n * pending operand short-circuits before the handler runs, see\n * `VM.ts`'s `CALL_PLUGIN` case), so every Value reaching here carries a real\n * result. Arity is checked first, before any argument is read, so a wrong\n * count is reported as a wrong count rather than as a type error on a missing\n * argument.\n */\nfunction makeHandler(spec: FunctionSpec): (args: Value[]) => Value {\n const arity = spec.args.length;\n return (args: Value[]): Value => {\n if (args.length !== arity) {\n throw ErrorFactory.execution({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_ARITY_MISMATCH,\n message: `${spec.name}() takes ${plural(arity)}, but was given ${args.length === 0 ? \"none\" : plural(args.length)}`,\n expected: plural(arity),\n found: args.length === 0 ? \"none\" : plural(args.length),\n context: { functionName: spec.name, expected: arity, actual: args.length },\n });\n }\n\n const jsArgs: (number | string | boolean)[] = new Array(arity);\n for (let i = 0; i < arity; i++) {\n jsArgs[i] = coerceArgument(args[i], spec.args[i], spec.name);\n }\n\n const result = (spec.call as (...a: (number | string | boolean)[]) => unknown)(...jsArgs);\n return wrapReturn(result, spec.returns, spec.name);\n };\n}\n\n/** Reject a spec that could not produce a working function, before any engine sees it. */\nfunction validateSpec(spec: FunctionSpec): void {\n if (typeof spec?.name !== \"string\" || !NAME_PATTERN.test(spec.name)) {\n throw ErrorFactory.config({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_INVALID_NAME,\n message: `defineFunction: name must be a single identifier, got ${JSON.stringify(spec?.name)}`,\n suggestion: 'e.g. \"vat\" or \"net_price\"',\n context: { name: spec?.name },\n });\n }\n if (!Array.isArray(spec.args)) {\n throw ErrorFactory.config({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_INVALID_SPEC,\n message: `defineFunction: \"${spec.name}\" args must be an array`,\n context: { name: spec.name },\n });\n }\n for (const arg of spec.args) {\n if (typeof arg?.name !== \"string\" || arg.name.length === 0) {\n throw ErrorFactory.config({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_INVALID_SPEC,\n message: `defineFunction: \"${spec.name}\" has an argument with no name`,\n context: { name: spec.name },\n });\n }\n if (!SUPPORTED_TYPES.has(arg.type)) {\n throw ErrorFactory.config({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_INVALID_SPEC,\n message: `defineFunction: \"${spec.name}\" argument \"${arg.name}\" has unsupported type ${JSON.stringify(arg.type)}`,\n suggestion: \"supported argument types are number, string, boolean\",\n context: { name: spec.name, argName: arg.name, type: arg.type },\n });\n }\n }\n if (!SUPPORTED_TYPES.has(spec.returns)) {\n throw ErrorFactory.config({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_INVALID_SPEC,\n message: `defineFunction: \"${spec.name}\" has unsupported return type ${JSON.stringify(spec.returns)}`,\n suggestion: \"supported return types are number, string, boolean\",\n context: { name: spec.name, returns: spec.returns },\n });\n }\n if (typeof spec.call !== \"function\") {\n throw ErrorFactory.config({\n code: DefineFunctionErrorCodes.DEFINE_FUNCTION_INVALID_SPEC,\n message: `defineFunction: \"${spec.name}\" is missing a call implementation`,\n context: { name: spec.name },\n });\n }\n}\n\n/**\n * Turn a declarative {@link FunctionSpec} into a ready-to-register\n * {@link IEnginePackage}.\n *\n * This is the higher-level API from issue #102. It derives, from the\n * declaration alone, everything the low-level contract asks an author to write\n * by hand: a named plugin function (the engine assigns its `CALL_PLUGIN`\n * index), a lexer keyword so the name tokenises, a call-syntax parselet emitting\n * that call by name, and a handler that checks arity and argument types (yielding\n * the engine's own structured errors) before invoking `call` and wrapping its\n * result. Anything needing custom parsing keeps writing a raw parselet exactly\n * as before, this sits on top of that contract and does not change it.\n *\n * @example\n * ```ts\n * const engine = new ExpressionEngine({ packages: [\n * ...BUILTIN_PACKAGES,\n * defineFunction({\n * name: \"vat\",\n * args: [{ name: \"amount\", type: \"number\" }],\n * returns: \"number\",\n * call: (amount) => amount * 1.2,\n * }),\n * ] });\n * engine.evaluateExpression(\"vat(100)\"); // 120\n * ```\n *\n * The returned package is self-contained and composes with any others through\n * the engine's `packages` array; register several functions by passing several\n * packages. Its name is `solve-fn-<name>`.\n *\n * Scope: arguments are a fixed-length list of `number`/`string`/`boolean`, and\n * `call` is synchronous. Variadic and optional arguments, other value types\n * (units, percentages, dates, matrices), and async work are deliberately out\n * of scope, a function needing any of those keeps using the low-level\n * contract, whose parselets and async resolvers are unchanged.\n *\n * @throws {EngineError} (category CONFIG) if the spec is malformed, at the\n * point `defineFunction` is called, before the package reaches an engine.\n */\nexport function defineFunction<\n const A extends readonly FunctionArg[],\n R extends FunctionValueType,\n>(spec: FunctionSpec<A, R>): IEnginePackage {\n validateSpec(spec as FunctionSpec);\n\n const name = spec.name;\n // Uppercased so the generated type is a valid, collision-resistant token\n // type; the name pattern guarantees it forms one. Distinct from the\n // built-in FUNC type, so this never routes through the builtin name map.\n const tokenType = `DEFINE_FN_${name.toUpperCase()}`;\n\n return {\n name: `solve-fn-${name}`,\n lexerVocabulary: {\n // Lowercased because the lexer lowercases input before lookup, so the\n // call is matched case-insensitively.\n keywords: { [name.toLowerCase()]: tokenType },\n },\n prefixParselets: {\n [tokenType]: new DefinedFunctionParselet(name),\n },\n pluginFunctions: {\n [name]: makeHandler(spec as FunctionSpec),\n },\n };\n}\n","import { ExpressionEngine, type EngineOptions } from \"@solve-js/engine/ExpressionEngine\";\nimport { BUILTIN_PACKAGES } from \"@solve-js/packages/builtins\";\nimport type { IEnginePackage } from \"@solve-js/api/PackageRegistry\";\n\n/** Options for {@link createEngine}: the engine options, minus `packages` (the\n * built-in set is always registered), plus `extraPackages` to add your own. */\nexport interface CreateEngineOptions extends Omit<EngineOptions, \"packages\"> {\n\t/** Packages to register ON TOP of the built-in set (e.g. an OSRS or stocks package). */\n\textraPackages?: IEnginePackage[];\n}\n\n/**\n * A batteries-included {@link ExpressionEngine} with every built-in package\n * registered.\n *\n * The constructor registers only the packages it is given, so a consumer's\n * bundler can tree-shake away the built-ins they never use: an engine built\n * with `new ExpressionEngine({ packages: [ARITHMETIC_PACKAGE] })` carries no\n * finance, colour or weather code. This convenience is the opposite trade: it\n * pulls the FULL built-in set (`BUILTIN_PACKAGES`) for the common \"I want\n * everything\" case, so importing it defeats that tree-shaking. Reach for the\n * constructor with an explicit package list when bundle size matters, and for\n * `createEngine` when it does not.\n *\n * @param options - Engine options ({@link EngineOptions}) minus `packages`, plus\n * an optional `extraPackages` to register alongside the built-in set.\n * @returns An engine with the built-in packages (and any extras) registered.\n *\n * @example\n * ```typescript\n * import { createEngine } from \"solve-engine\";\n * const engine = createEngine();\n * const value = engine.evaluateExpression(\"2 + 2 * 10\");\n * console.log(value.toNumber()); // 22\n * ```\n */\nexport function createEngine(options: CreateEngineOptions = {}): ExpressionEngine {\n\tconst { extraPackages = [], ...engineOptions } = options;\n\treturn new ExpressionEngine({\n\t\t...engineOptions,\n\t\tpackages: extraPackages.length > 0 ? [...BUILTIN_PACKAGES, ...extraPackages] : BUILTIN_PACKAGES,\n\t});\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { I as IEnginePackage, a as EngineOptions, E as ExpressionEngine } from './PackageRegistry-
|
|
2
|
-
export { b as EngineRestoreOptions, c as EngineSnapshot, d as Explanation, e as ExplanationStep, S as SNAPSHOT_FORMAT, f as SNAPSHOT_VERSION, g as SerializedAnonymousBody, h as SerializedBytecode, i as SerializedDecimal, j as SerializedLineCacheEntry, k as SerializedNumber, l as SerializedRational, m as SerializedUserFunction, n as SerializedValue, o as SnapshotErrorCodes } from './PackageRegistry-
|
|
3
|
-
export { a as CompatibilityConflict, b as CompatibilityConflictKind, C as CompatibilityReport, c as CompatibilitySeverity, d as checkPackageCompatibility } from './PackageCompatibility-
|
|
4
|
-
export { E as EngineConfigOverride } from './Configuration-
|
|
1
|
+
import { I as IEnginePackage, a as EngineOptions, E as ExpressionEngine } from './PackageRegistry-Dvn4i2QK.cjs';
|
|
2
|
+
export { b as EngineRestoreOptions, c as EngineSnapshot, d as Explanation, e as ExplanationStep, S as SNAPSHOT_FORMAT, f as SNAPSHOT_VERSION, g as SerializedAnonymousBody, h as SerializedBytecode, i as SerializedDecimal, j as SerializedLineCacheEntry, k as SerializedNumber, l as SerializedRational, m as SerializedUserFunction, n as SerializedValue, o as SnapshotErrorCodes } from './PackageRegistry-Dvn4i2QK.cjs';
|
|
3
|
+
export { a as CompatibilityConflict, b as CompatibilityConflictKind, C as CompatibilityReport, c as CompatibilitySeverity, d as checkPackageCompatibility } from './PackageCompatibility-CUVg8tmt.cjs';
|
|
4
|
+
export { E as EngineConfigOverride } from './Configuration-DnzYPmoK.cjs';
|
|
5
|
+
export { V as Value, a as ValueType } from './Value-Ds3Gy07C.cjs';
|
|
6
|
+
export { formatValue } from './format.cjs';
|
|
7
|
+
export { F as FormattingSettings } from './FormattingSettings-bRKjU7wI.cjs';
|
|
5
8
|
export { ENGINE_VERSION } from './constants.cjs';
|
|
6
|
-
import './Parselet-
|
|
7
|
-
import './BytecodeBuilder-
|
|
9
|
+
import './Parselet-BawfGuTF.cjs';
|
|
10
|
+
import './BytecodeBuilder-DSWKZi4f.cjs';
|
|
8
11
|
import './Token-CbP_OutD.cjs';
|
|
9
|
-
import './pipeline-
|
|
10
|
-
import './
|
|
11
|
-
import './
|
|
12
|
+
import './pipeline-69q2tsLE.cjs';
|
|
13
|
+
import './Lexer-aB95pjoX.cjs';
|
|
14
|
+
import './EngineError-fR1K1rvx.cjs';
|
|
12
15
|
import './resolvers.cjs';
|
|
13
16
|
import '@tanstack/query-core';
|
|
14
|
-
import './TokenNormalizer-
|
|
15
|
-
import './ScopeManager-
|
|
16
|
-
import './EngineError-DTk7I7hZ.cjs';
|
|
17
|
+
import './TokenNormalizer-CjTDmHgB.cjs';
|
|
18
|
+
import './ScopeManager-CdwX0VTw.cjs';
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* A higher-level, declarative way to contribute a single `name(args)`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { I as IEnginePackage, a as EngineOptions, E as ExpressionEngine } from './PackageRegistry-
|
|
2
|
-
export { b as EngineRestoreOptions, c as EngineSnapshot, d as Explanation, e as ExplanationStep, S as SNAPSHOT_FORMAT, f as SNAPSHOT_VERSION, g as SerializedAnonymousBody, h as SerializedBytecode, i as SerializedDecimal, j as SerializedLineCacheEntry, k as SerializedNumber, l as SerializedRational, m as SerializedUserFunction, n as SerializedValue, o as SnapshotErrorCodes } from './PackageRegistry-
|
|
3
|
-
export { a as CompatibilityConflict, b as CompatibilityConflictKind, C as CompatibilityReport, c as CompatibilitySeverity, d as checkPackageCompatibility } from './PackageCompatibility-
|
|
4
|
-
export { E as EngineConfigOverride } from './Configuration-
|
|
1
|
+
import { I as IEnginePackage, a as EngineOptions, E as ExpressionEngine } from './PackageRegistry-DT-x32OM.js';
|
|
2
|
+
export { b as EngineRestoreOptions, c as EngineSnapshot, d as Explanation, e as ExplanationStep, S as SNAPSHOT_FORMAT, f as SNAPSHOT_VERSION, g as SerializedAnonymousBody, h as SerializedBytecode, i as SerializedDecimal, j as SerializedLineCacheEntry, k as SerializedNumber, l as SerializedRational, m as SerializedUserFunction, n as SerializedValue, o as SnapshotErrorCodes } from './PackageRegistry-DT-x32OM.js';
|
|
3
|
+
export { a as CompatibilityConflict, b as CompatibilityConflictKind, C as CompatibilityReport, c as CompatibilitySeverity, d as checkPackageCompatibility } from './PackageCompatibility-BludTs7v.js';
|
|
4
|
+
export { E as EngineConfigOverride } from './Configuration-DnzYPmoK.js';
|
|
5
|
+
export { V as Value, a as ValueType } from './Value-Ds3Gy07C.js';
|
|
6
|
+
export { formatValue } from './format.js';
|
|
7
|
+
export { F as FormattingSettings } from './FormattingSettings-bRKjU7wI.js';
|
|
5
8
|
export { ENGINE_VERSION } from './constants.js';
|
|
6
|
-
import './Parselet-
|
|
7
|
-
import './BytecodeBuilder-
|
|
9
|
+
import './Parselet-DqTbbtWA.js';
|
|
10
|
+
import './BytecodeBuilder-DSWKZi4f.js';
|
|
8
11
|
import './Token-CbP_OutD.js';
|
|
9
|
-
import './pipeline-
|
|
10
|
-
import './
|
|
11
|
-
import './
|
|
12
|
+
import './pipeline-DTqGLPsV.js';
|
|
13
|
+
import './Lexer-Bmctxl0n.js';
|
|
14
|
+
import './EngineError-fR1K1rvx.js';
|
|
12
15
|
import './resolvers.js';
|
|
13
16
|
import '@tanstack/query-core';
|
|
14
|
-
import './TokenNormalizer-
|
|
15
|
-
import './ScopeManager-
|
|
16
|
-
import './EngineError-DTk7I7hZ.js';
|
|
17
|
+
import './TokenNormalizer-CLBtiE8M.js';
|
|
18
|
+
import './ScopeManager-B636am7Y.js';
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* A higher-level, declarative way to contribute a single `name(args)`
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import'./chunk-
|
|
1
|
+
import'./chunk-ZDCZ5IDD.js';import'./chunk-RAF57WYO.js';import {n}from'./chunk-7N3IJSWF.js';export{n as ExpressionEngine,d as SNAPSHOT_FORMAT,e as SNAPSHOT_VERSION,f as SnapshotErrorCodes,c as assertEngineVersionCompatible,b as checkEngineVersionCompatibility,a as checkPackageCompatibility}from'./chunk-7N3IJSWF.js';import'./chunk-4BRTUFTH.js';import'./chunk-2RWAXT6O.js';import'./chunk-IJHL3LMH.js';import'./chunk-MIQBJGGR.js';import'./chunk-N4SSR7Q6.js';import'./chunk-JP4JMQOG.js';export{c as formatValue}from'./chunk-XX55RR4Q.js';import'./chunk-XEIDV5JP.js';import {z}from'./chunk-MZMA32NE.js';import'./chunk-OONQ3V3I.js';import'./chunk-63ZOOUOL.js';import {a}from'./chunk-EL2XUOWX.js';import'./chunk-72PYPENZ.js';import'./chunk-76F3LCIL.js';import'./chunk-TCZSPH4A.js';import'./chunk-UF5XMZTT.js';import'./chunk-XHQYHXRE.js';import'./chunk-TZYMXNIB.js';import'./chunk-HFKDWQUL.js';import'./chunk-5TCSFTZD.js';import'./chunk-RDYXH7ML.js';import {L,t,n as n$1}from'./chunk-NMU5E7W7.js';export{m as Value,g as ValueType}from'./chunk-NMU5E7W7.js';import'./chunk-4CNYGIND.js';export{a as ENGINE_VERSION}from'./chunk-DUYTXLO2.js';import'./chunk-7DP57BA7.js';import'./chunk-JPFCXLJV.js';import'./chunk-OB2VX4IL.js';import'./chunk-IJMNVBIS.js';import'./chunk-LHLW7JLS.js';import'./chunk-CHVGFTO3.js';import'./chunk-PRSXXDTA.js';import {c}from'./chunk-57PSJQQW.js';var r={DEFINE_FUNCTION_INVALID_NAME:"DEFINE_FUNCTION_INVALID_NAME",DEFINE_FUNCTION_INVALID_SPEC:"DEFINE_FUNCTION_INVALID_SPEC",DEFINE_FUNCTION_ARITY_MISMATCH:"DEFINE_FUNCTION_ARITY_MISMATCH",DEFINE_FUNCTION_ARGUMENT_TYPE:"DEFINE_FUNCTION_ARGUMENT_TYPE",DEFINE_FUNCTION_RETURN_TYPE:"DEFINE_FUNCTION_RETURN_TYPE"},P=/^[a-z_][a-z0-9_]*$/i,N=new Set(["number","string","boolean"]);function u(e){return e===1?"1 argument":`${e} arguments`}function d(e){switch(e.type){case 0:case 1:return "a number";case 3:return "a string";case 10:return "a boolean";case 2:return "a big integer";case 5:return "a percentage";case 6:return "a value with a unit";case 4:return "a date";case 7:return "a matrix";case 8:return "a range";case 9:return "a symbolic expression";default:return "an unsupported value"}}function V(e,n,t){switch(n.type){case "number":if(e.type===0||e.type===1)return e.toNumber();break;case "string":if(e.type===3)return e.value;break;case "boolean":if(e.type===10)return e.value;break}throw c.execution({code:r.DEFINE_FUNCTION_ARGUMENT_TYPE,message:`${t}() expects "${n.name}" to be a ${n.type}, but was given ${d(e)}`,expected:`a ${n.type}`,found:d(e),context:{functionName:t,argName:n.name,expectedType:n.type}})}function O(e,n,t$1){switch(n){case "number":if(typeof e=="number")return n$1(e);break;case "string":if(typeof e=="string")return t(e);break;case "boolean":if(typeof e=="boolean")return L(e);break}throw c.internal({code:r.DEFINE_FUNCTION_RETURN_TYPE,message:`${t$1}() is declared to return a ${n}, but its implementation returned ${typeof e}`,expected:`a ${n}`,found:typeof e,context:{functionName:t$1,expectedType:n}})}var p=class{constructor(n){this.fnName=n;this.category="Function";}parse(n,t,a$1){n.consume("LPAREN");let i=0;if(n.peek()?.type!=="RPAREN")for(n.parseExpression(a.Lowest,a$1),i++;n.match("COMMA");)n.parseExpression(a.Lowest,a$1),i++;n.consume("RPAREN"),a$1.emitPluginCall(this.fnName,i);}};function h(e){let n=e.args.length;return t=>{if(t.length!==n)throw c.execution({code:r.DEFINE_FUNCTION_ARITY_MISMATCH,message:`${e.name}() takes ${u(n)}, but was given ${t.length===0?"none":u(t.length)}`,expected:u(n),found:t.length===0?"none":u(t.length),context:{functionName:e.name,expected:n,actual:t.length}});let a=new Array(n);for(let s=0;s<n;s++)a[s]=V(t[s],e.args[s],e.name);let i=e.call(...a);return O(i,e.returns,e.name)}}function R(e){if(typeof e?.name!="string"||!P.test(e.name))throw c.config({code:r.DEFINE_FUNCTION_INVALID_NAME,message:`defineFunction: name must be a single identifier, got ${JSON.stringify(e?.name)}`,suggestion:'e.g. "vat" or "net_price"',context:{name:e?.name}});if(!Array.isArray(e.args))throw c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" args must be an array`,context:{name:e.name}});for(let n of e.args){if(typeof n?.name!="string"||n.name.length===0)throw c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" has an argument with no name`,context:{name:e.name}});if(!N.has(n.type))throw c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" argument "${n.name}" has unsupported type ${JSON.stringify(n.type)}`,suggestion:"supported argument types are number, string, boolean",context:{name:e.name,argName:n.name,type:n.type}})}if(!N.has(e.returns))throw c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" has unsupported return type ${JSON.stringify(e.returns)}`,suggestion:"supported return types are number, string, boolean",context:{name:e.name,returns:e.returns}});if(typeof e.call!="function")throw c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" is missing a call implementation`,context:{name:e.name}})}function k(e){R(e);let n=e.name,t=`DEFINE_FN_${n.toUpperCase()}`;return {name:`solve-fn-${n}`,lexerVocabulary:{keywords:{[n.toLowerCase()]:t}},prefixParselets:{[t]:new p(n)},pluginFunctions:{[n]:h(e)}}}function D(e={}){let{extraPackages:n$1=[],...t}=e;return new n({...t,packages:n$1.length>0?[...z,...n$1]:z})}export{r as DefineFunctionErrorCodes,D as createEngine,k as defineFunction};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|