solve-engine 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2HQWM5OB.js +3 -0
- package/dist/chunk-2HQWM5OB.js.map +1 -0
- package/dist/{chunk-UGQM6ZXU.js → chunk-7RTKJMYS.js} +2 -2
- package/dist/{chunk-UGQM6ZXU.js.map → chunk-7RTKJMYS.js.map} +1 -1
- package/dist/chunk-ANJPS6FF.cjs +2 -0
- package/dist/chunk-ANJPS6FF.cjs.map +1 -0
- package/dist/chunk-CT5TC3JX.cjs +3 -0
- package/dist/chunk-CT5TC3JX.cjs.map +1 -0
- package/dist/{chunk-WYAY6WPQ.cjs → chunk-D5MTMRHS.cjs} +4 -4
- package/dist/{chunk-WYAY6WPQ.cjs.map → chunk-D5MTMRHS.cjs.map} +1 -1
- package/dist/chunk-LBNX7TXI.js +2 -0
- package/dist/chunk-LBNX7TXI.js.map +1 -0
- package/dist/{chunk-UA3BGOYT.js → chunk-LOM3H5ZD.js} +3 -3
- package/dist/{chunk-UA3BGOYT.js.map → chunk-LOM3H5ZD.js.map} +1 -1
- package/dist/{chunk-E2ZSMJEL.cjs → chunk-NGJMCVH4.cjs} +3 -3
- package/dist/{chunk-E2ZSMJEL.cjs.map → chunk-NGJMCVH4.cjs.map} +1 -1
- package/dist/chunk-QEYTENAK.js +2 -0
- package/dist/chunk-QEYTENAK.js.map +1 -0
- package/dist/{chunk-5R7S5KJJ.js → chunk-RDMJNRDO.js} +3 -3
- package/dist/{chunk-5R7S5KJJ.js.map → chunk-RDMJNRDO.js.map} +1 -1
- package/dist/chunk-YFWAR766.cjs +2 -0
- package/dist/chunk-YFWAR766.cjs.map +1 -0
- package/dist/{chunk-MMT2LS5I.cjs → chunk-YUJNMUKM.cjs} +2 -2
- package/dist/{chunk-MMT2LS5I.cjs.map → chunk-YUJNMUKM.cjs.map} +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/engine.cjs +1 -1
- package/dist/engine.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/packages.cjs +1 -1
- package/dist/packages.js +1 -1
- package/dist/testing.cjs +2 -2
- package/dist/testing.js +1 -1
- package/dist/vm.cjs +1 -1
- package/dist/vm.js +1 -1
- package/dist/worker.cjs +2 -2
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-GALZNKW7.js +0 -3
- package/dist/chunk-GALZNKW7.js.map +0 -1
- package/dist/chunk-JAK3RAFA.cjs +0 -2
- package/dist/chunk-JAK3RAFA.cjs.map +0 -1
- package/dist/chunk-NAMMTJBE.cjs +0 -3
- package/dist/chunk-NAMMTJBE.cjs.map +0 -1
- package/dist/chunk-SYYE3QAX.cjs +0 -2
- package/dist/chunk-SYYE3QAX.cjs.map +0 -1
- package/dist/chunk-W2JAR233.js +0 -2
- package/dist/chunk-W2JAR233.js.map +0 -1
- package/dist/chunk-YJ2OPULK.js +0 -2
- package/dist/chunk-YJ2OPULK.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {c as c$1}from'./chunk-MPB7KUN5.js';var d="2.
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import {c as c$1}from'./chunk-MPB7KUN5.js';var d="2.5.0";var m=d;var l={date:{maxOffsetYears:100,minOffsetYears:-100,defaultFormat:"YYYY-MM-DD",inputOrder:"auto"},performance:{defaultCacheSize:2e3,maxDocumentLines:1e5},validation:{maxExpressionLength:2e3,maxComplexity:500,maxNestingDepth:50,autoBalanceParens:false},vm:{maxStackDepth:200,maxInstructions:5e4,maxCollectionSize:1e5,maxAllocatedElements:2e6,maxFunctionCalls:1e4,maxGoalSeekIterations:100},worker:{maxConcurrentWorkers:4,idleTimeoutMs:3e4,maxRetries:3,baseBackoffMs:1e3},diagnostic:{enabled:false,vmTraceEnabled:false},backgroundRefresh:{enabled:false}};function r(s,e){return {date:{...s.date,...e.date},performance:{...s.performance,...e.performance},validation:{...s.validation,...e.validation},vm:{...s.vm,...e.vm},worker:{...s.worker,...e.worker},diagnostic:{...s.diagnostic,...e.diagnostic},backgroundRefresh:{...s.backgroundRefresh,...e.backgroundRefresh}}}var c=class{constructor(e={}){this.config=r(l,e);}get(e){let o=e.split("."),t=this.config;for(let i of o)if(t&&typeof t=="object"&&i in t)t=t[i];else throw c$1.config("CONFIG_PATH_NOT_FOUND",`Configuration path not found: ${e}`,{path:e});return t}set(e,o){let t=e.split(".");if(t.length<2)throw c$1.config("INVALID_CONFIG_PATH",`Invalid path: ${e}. Must be in format 'section.property'`,{path:e});let i=t[0],u=t[1];if(!(i in this.config))throw c$1.config("CONFIG_SECTION_NOT_FOUND",`Configuration section not found: ${i}`,{section:i,path:e});let a=this.config[i];if(a&&typeof a=="object")a[u]=o;else throw c$1.config("CONFIG_PROPERTY_NOT_FOUND",`Configuration property not found: ${e}`,{path:e})}getConfig(){return r(this.config,{})}update(e){this.config=r(this.config,e);}reset(){this.config=r(l,{});}validate(){let e=[];return this.config.performance.maxDocumentLines>1e5&&e.push("maxDocumentLines cannot exceed 100,000"),this.config.date.maxOffsetYears>1e3&&e.push("maxOffsetYears cannot exceed 1000"),{valid:e.length===0,error:e.join("; "),warnings:[]}}};export{m as a,l as b,r as c,c as d};//# sourceMappingURL=chunk-7RTKJMYS.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-7RTKJMYS.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/constants/version.ts","../src/constants/Configuration.ts"],"names":["version","ENGINE_VERSION","DEFAULT_CONFIG","mergeEngineConfig","base","override","ConfigManager","config","path","keys","current","key","ErrorFactory","value","section","property","sectionConfig","errors"],"mappings":"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","file":"chunk-UGQM6ZXU.js","sourcesContent":["{\n \"name\": \"solve-engine\",\n \"version\": \"2.4.0\",\n \"description\": \"An embeddable expression engine for natural-language calculations: units, currencies, percentages, dates and matrices, with the parsing and evaluation plumbing already built.\",\n \"keywords\": [\n \"expression-evaluator\",\n \"calculator\",\n \"bytecode-vm\",\n \"parser\",\n \"lexer\",\n \"dsl\",\n \"markdown\",\n \"obsidian\"\n ],\n \"license\": \"MIT\",\n \"author\": \"Liam Riddell\",\n \"homepage\": \"https://liamriddell.github.io/solve-engine/\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/LiamRiddell/solve-engine.git\",\n \"directory\": \"packages/engine\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/LiamRiddell/solve-engine/issues\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"type\": \"module\",\n \"engines\": {\n \"node\": \">=22\"\n },\n \"files\": [\n \"dist\",\n \"LICENSE\"\n ],\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.cts\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"./engine\": {\n \"import\": {\n \"types\": \"./dist/engine.d.ts\",\n \"default\": \"./dist/engine.js\"\n },\n \"require\": {\n \"types\": \"./dist/engine.d.cts\",\n \"default\": \"./dist/engine.cjs\"\n }\n },\n \"./vm\": {\n \"import\": {\n \"types\": \"./dist/vm.d.ts\",\n \"default\": \"./dist/vm.js\"\n },\n \"require\": {\n \"types\": \"./dist/vm.d.cts\",\n \"default\": \"./dist/vm.cjs\"\n }\n },\n \"./format\": {\n \"import\": {\n \"types\": \"./dist/format.d.ts\",\n \"default\": \"./dist/format.js\"\n },\n \"require\": {\n \"types\": \"./dist/format.d.cts\",\n \"default\": \"./dist/format.cjs\"\n }\n },\n \"./language\": {\n \"import\": {\n \"types\": \"./dist/language.d.ts\",\n \"default\": \"./dist/language.js\"\n },\n \"require\": {\n \"types\": \"./dist/language.d.cts\",\n \"default\": \"./dist/language.cjs\"\n }\n },\n \"./packages\": {\n \"import\": {\n \"types\": \"./dist/packages.d.ts\",\n \"default\": \"./dist/packages.js\"\n },\n \"require\": {\n \"types\": \"./dist/packages.d.cts\",\n \"default\": \"./dist/packages.cjs\"\n }\n },\n \"./constants\": {\n \"import\": {\n \"types\": \"./dist/constants.d.ts\",\n \"default\": \"./dist/constants.js\"\n },\n \"require\": {\n \"types\": \"./dist/constants.d.cts\",\n \"default\": \"./dist/constants.cjs\"\n }\n },\n \"./lexer\": {\n \"import\": {\n \"types\": \"./dist/lexer.d.ts\",\n \"default\": \"./dist/lexer.js\"\n },\n \"require\": {\n \"types\": \"./dist/lexer.d.cts\",\n \"default\": \"./dist/lexer.cjs\"\n }\n },\n \"./parser\": {\n \"import\": {\n \"types\": \"./dist/parser.d.ts\",\n \"default\": \"./dist/parser.js\"\n },\n \"require\": {\n \"types\": \"./dist/parser.d.cts\",\n \"default\": \"./dist/parser.cjs\"\n }\n },\n \"./normalizer\": {\n \"import\": {\n \"types\": \"./dist/normalizer.d.ts\",\n \"default\": \"./dist/normalizer.js\"\n },\n \"require\": {\n \"types\": \"./dist/normalizer.d.cts\",\n \"default\": \"./dist/normalizer.cjs\"\n }\n },\n \"./resolvers\": {\n \"import\": {\n \"types\": \"./dist/resolvers.d.ts\",\n \"default\": \"./dist/resolvers.js\"\n },\n \"require\": {\n \"types\": \"./dist/resolvers.d.cts\",\n \"default\": \"./dist/resolvers.cjs\"\n }\n },\n \"./errors\": {\n \"import\": {\n \"types\": \"./dist/errors.d.ts\",\n \"default\": \"./dist/errors.js\"\n },\n \"require\": {\n \"types\": \"./dist/errors.d.cts\",\n \"default\": \"./dist/errors.cjs\"\n }\n },\n \"./utilities\": {\n \"import\": {\n \"types\": \"./dist/utilities.d.ts\",\n \"default\": \"./dist/utilities.js\"\n },\n \"require\": {\n \"types\": \"./dist/utilities.d.cts\",\n \"default\": \"./dist/utilities.cjs\"\n }\n },\n \"./uom\": {\n \"import\": {\n \"types\": \"./dist/uom.d.ts\",\n \"default\": \"./dist/uom.js\"\n },\n \"require\": {\n \"types\": \"./dist/uom.d.cts\",\n \"default\": \"./dist/uom.cjs\"\n }\n },\n \"./services\": {\n \"import\": {\n \"types\": \"./dist/services.d.ts\",\n \"default\": \"./dist/services.js\"\n },\n \"require\": {\n \"types\": \"./dist/services.d.cts\",\n \"default\": \"./dist/services.cjs\"\n }\n },\n \"./worker\": {\n \"import\": {\n \"types\": \"./dist/worker.d.ts\",\n \"default\": \"./dist/worker.js\"\n },\n \"require\": {\n \"types\": \"./dist/worker.d.cts\",\n \"default\": \"./dist/worker.cjs\"\n }\n },\n \"./testing\": {\n \"import\": {\n \"types\": \"./dist/testing.d.ts\",\n \"default\": \"./dist/testing.js\"\n },\n \"require\": {\n \"types\": \"./dist/testing.d.cts\",\n \"default\": \"./dist/testing.cjs\"\n }\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"prepublishOnly\": \"npm run build && node ../../scripts/assert-publishable.mjs .\",\n \"dev\": \"tsup --watch\",\n \"test\": \"jest --config jest.config.cjs --no-coverage\",\n \"typecheck\": \"tsgo --noEmit --skipLibCheck\",\n \"typecheck:tsc\": \"tsc --noEmit --skipLibCheck\"\n },\n \"dependencies\": {\n \"@tanstack/query-core\": \"^5.100.10\"\n },\n \"devDependencies\": {\n \"@jest/globals\": \"^30.4.1\",\n \"@types/node\": \"^26.2.0\",\n \"convert\": \"^7.0.0\",\n \"jest\": \"^30.4.2\",\n \"ts-jest\": \"^29.4.12\",\n \"tsup\": \"8.5.1\",\n \"typescript\": \"5.9.3\"\n },\n \"//sideEffects\": \"Load-bearing claim, not boilerplate. tsup's splitting emits bare chunk imports at the top of dist/index.js, and this field tells Rollup, webpack and Vite they may delete them, which esbuild reports as [ignored-bare-import] once per import during `npm run size`. The engine does have module-level work to lose: registerAllTokenTypes(), _PrecedenceParser.BP_TABLE and its cached token ids, and several process-wide registries. It is safe because every chunk doing that work is also imported for its bindings somewhere, so no bundler can drop it. That is a property of how tsup currently splits the code rather than a design guarantee, so `npm run smoke:bundled` (scripts/check-tree-shaking.mjs) proves it on every run of `npm run verify` instead of assuming it, and its header explains the two fixes if it ever stops holding.\",\n \"sideEffects\": false\n}\n","/**\n * The running engine's own semver version, sourced directly from this\n * package's package.json so it can never drift from what's actually\n * published. Exists so IEnginePackage.engineVersion range checks\n * (api/EngineVersionCompatibility.ts) have something real to check\n * against.\n */\nimport { version } from \"../../package.json\";\n\n/**\n * The running engine's version, taken from package.json.\n *\n * What a package's `engineVersion` range is checked against at registration.\n * A prerelease is compared by its coerced release version, so a 1.0.0 beta\n * satisfies `^1.0.0`. See `api/EngineVersionCompatibility.ts`.\n */\nexport const ENGINE_VERSION: string = version;\n","/**\n * Configuration Module for solve-js Engine\n * \n * This module provides the **single source of truth** for all engine configuration.\n * Every configurable aspect of the engine, from safety limits and performance\n * budgets to VM constraints and worker pool sizing, is defined here.\n * \n * ### Design principles\n * \n * 1. **Engine owns its config.** The engine defines its own config shape and defaults.\n * Consumers (e.g., the Obsidian plugin) pass partial overrides; all unspecified\n * fields fall back to `DEFAULT_CONFIG`.\n * \n * 2. **Self-documenting.** Every interface and field has descriptive JSDoc so the\n * config is understandable at a glance, whether you're using the engine as an\n * npm package or reading the source.\n * \n * 3. **Minimal consumer knowledge.** Consumers only need to pass `Partial<EngineConfig>`.\n * They don't need to replicate the full config shape, just the fields they\n * want to override.\n * \n * @module Configuration\n */\n\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * A host's test for whether a calendar date is a public holiday, given the\n * `Date` for that day at local midnight. Return `true` to exclude it from\n * working-day arithmetic.\n */\nexport type HolidayPredicate = (date: Date) => boolean;\n\n/**\n * The host-supplied public-holiday calendar, in the same \"bring your own data\"\n * shape the stocks and weather packages already use for a host callback (see\n * `packages/stocks/StocksPackage.ts`): weekends are decidable from the date\n * alone, holidays are not, so they come from the host or not at all.\n *\n * Either a {@link HolidayPredicate}, for a host that computes holidays itself\n * (an existing library, a region rule), or an iterable of specific dates as\n * `YYYY-MM-DD` strings, epoch-millisecond numbers or `Date` objects, for a host\n * that just has a list. Resolved to one internal predicate by\n * `vm/HolidayCalendar.ts`'s `resolveHolidayPredicate()`.\n *\n * Left unset, working-day arithmetic skips weekends only, which is the honest\n * default: the engine excludes exactly the days it can prove are non-working.\n */\nexport type HolidayCalendar = HolidayPredicate | Iterable<string | number | Date>;\n\n/**\n * Date-related configuration.\n * Controls the bounds and formatting for date/time expression evaluation\n * (e.g., `today + 20 days`, `last monday`).\n */\n/**\n * How an ambiguous all-numeric date literal is read.\n *\n * - `'auto'`: by separator, the historic behaviour. A slash date is\n * day-first (`25/12/2023`), a hyphen date is month-first (`12-25-2023`)\n * unless its first group is four digits, which makes it ISO (`2023-12-25`).\n * - `'DMY'` / `'MDY'` / `'YMD'`: a fixed order for every numeric separator, so\n * a host can match its readers' locale. `'MDY'` is what lets a US reader's\n * `12/25/2023` parse, which `'auto'` refuses because the slash defaults to\n * day-first.\n *\n * Only the all-numeric literals are affected. A spelled-out month (`March 9,\n * 2024`) is never ambiguous, and an ISO timestamp is always read as ISO.\n */\nexport type DateInputOrder = 'auto' | 'DMY' | 'MDY' | 'YMD';\n\n/** Date-related engine configuration: offset limits, input order, holidays. */\nexport interface DateConfig {\n /**\n * The order an ambiguous all-numeric date literal is read in. Defaults to\n * `'auto'` (by separator, the historic behaviour). See {@link DateInputOrder}.\n */\n readonly inputOrder: DateInputOrder;\n /**\n * How far forward a date offset whose COST grows with the offset may reach,\n * in years. Enforced by `vm/VM.ts`'s `addBusinessDays()`.\n *\n * Bounds the walk, not the calendar. Every other date offset in the engine\n * is arithmetic on a Date field, so `today + 100000 days` costs exactly what\n * one day costs and needs no ceiling; workdays are the one offset that has\n * to step day by day, because which days are skipped depends on where each\n * step lands. `today + 100000000 workdays` therefore froze the host for\n * thirteen seconds inside a single ADD opcode (where `vm.maxInstructions`\n * cannot see it) and then answered \"Invalid Date\", and a trillion never\n * returned at all.\n *\n * Release hardening: this field was declared, documented as a \"safety\n * limit\", and read nowhere, so it bounded nothing. A limit a host can\n * configure and the engine ignores is worse than no limit, because it reads\n * as protection that is not there.\n */\n readonly maxOffsetYears: number;\n /** How far BACK the same walk may reach, in years, as a negative number. See {@link maxOffsetYears}. */\n readonly minOffsetYears: number;\n /** Default date string format for display (moment.js format string) */\n readonly defaultFormat: string;\n /**\n * Public-holiday calendar for working-day arithmetic (`N working days after\n * <date>`, `working days between <date> and <date>`, `<date> + N workdays`).\n * See {@link HolidayCalendar}.\n *\n * Optional and unset by default: with no calendar, working-day arithmetic\n * skips weekends only. A host that wants holidays excluded too supplies one\n * here (`new ExpressionEngine({ config: { date: { holidays } } })`), the\n * same way stocks and weather take a host data source. Threaded into the VM\n * by `engine/ExpressionEngine.ts` exactly as {@link maxOffsetYears} is,\n * because working-day math is a VM operation several grammar forms share, so\n * the calendar has to be one source the VM owns rather than per-package state\n * the VM cannot see.\n */\n readonly holidays?: HolidayCalendar;\n}\n\n/**\n * Performance-related configuration.\n * Controls caching, timeouts, and processing limits to prevent runaway\n * resource consumption on large documents.\n */\nexport interface PerformanceConfig {\n /**\n * Maximum number of entries in {@link ExpressionEngine}'s bytecode cache\n * (per-instance, keyed by expression text) before the oldest entry is\n * evicted. Raise this for documents with many distinct expressions if\n * repeated re-evaluation (e.g. scrolling) is re-parsing instead of\n * hitting cache, bug fix (release hardening pass): this field used to\n * be read nowhere; the cache size was a hardcoded, unconfigurable\n * constant. Note this does NOT bound {@link LineCache}, which has no\n * size limit of its own.\n */\n readonly defaultCacheSize: number;\n /**\n * Maximum lines a document may have for the engine to process it in one\n * pass. Enforced by `ExpressionEngine.parseDocument()` and by\n * `engine/DocumentModel.ts`'s `setDocument()`, the two entry points that\n * take a whole document.\n *\n * A document costs memory per line whatever each line says: a parsed line\n * record, a cache entry, a dependency-graph node. Two hundred thousand\n * lines of `1 + 1` therefore exhausted the heap and aborted the process\n * before any per-line limit had anything to object to, which is the same\n * shape of hole as an unbounded expression and needs the same kind of\n * ceiling. Refusing the document names the limit; a host that genuinely has\n * a larger one raises this field.\n *\n * Release hardening: declared and read nowhere until now.\n */\n readonly maxDocumentLines: number;\n}\n\n/**\n * Validation / safety-limit configuration.\n * Protects against runaway expressions that could cause excessive memory use\n * or stack overflow. These limits are checked during lexing and parsing.\n */\n/** Bounds on untrusted input: expression length and nesting depth. */\nexport interface ValidationConfig {\n /** Maximum expression length in characters. Prevents excessively long strings from entering the pipeline. */\n readonly maxExpressionLength: number;\n /** Maximum expression complexity score (`tokens + functionCalls×5 + nestingDepth×10`). Protects against deeply nested or combinatorially complex expressions. */\n readonly maxComplexity: number;\n /** Maximum parentheses nesting depth. Prevents stack overflow in the recursive-descent parser. */\n readonly maxNestingDepth: number;\n /**\n * Auto-balance unmatched parentheses by appending missing closing parens\n * or prepending missing opening parens. When disabled, unbalanced expressions\n * cause parse errors instead of being silently corrected.\n *\n * Disabled by default for strict parsing. Enable for forgiving user input\n * (e.g., chat-style calculators where users often omit closing parens).\n * Has zero overhead when disabled, the O(n) paren-count scan is skipped.\n */\n readonly autoBalanceParens: boolean;\n}\n\n/**\n * Worker pool configuration.\n * Controls the parallel execution workers used for batch evaluation.\n */\nexport interface WorkerConfig {\n /** Maximum number of concurrent Web Workers allowed */\n readonly maxConcurrentWorkers: number;\n /** Time (ms) a worker stays alive while idle before being terminated */\n readonly idleTimeoutMs: number;\n /** Maximum retry attempts for a failed worker operation */\n readonly maxRetries: number;\n /** Base backoff delay (ms) between retries (exponential backoff applied on top) */\n readonly baseBackoffMs: number;\n} /**\n * Diagnostic / telemetry configuration.\n * Controls the diagnostic event pipeline for profiling and debugging.\n * All diagnostics are disabled by default for maximum production performance.\n */\n export interface DiagnosticConfig {\n /** Master switch: enable the diagnostic pipeline (collectors receive events for all pipeline stages) */\n readonly enabled: boolean;\n /** Enable VM trace mode, emits per-opcode execution events (very verbose; disables some optimizations) */\n readonly vmTraceEnabled: boolean;\n }\n\n /**\n * Proactive background refresh of live async values.\n *\n * Off by default. When a live value (a stock quote, an FX rate) has gone\n * stale, today it only refetches on the next re-evaluation (a keystroke), so a\n * note left open silently ages. With this enabled, the engine drives a refetch\n * on each such value's own cadence (the resolver's `refetchIntervalMs`) for the\n * values currently on screen, and pushes the fresh result to the host through\n * the same event stream the pull path uses. It needs timers and a live editor\n * consuming that stream, so a headless or batch host leaves it off.\n */\n export interface BackgroundRefreshConfig {\n /** Master switch. When false, no timers run and every value refreshes only on re-evaluation. */\n readonly enabled: boolean;\n }\n\n /**\n * Virtual Machine configuration.\n * Controls the internal bytecode VM that executes compiled expressions.\n */\n export interface VMConfig {\n /** Maximum stack depth (value slots) for VM execution, prevents stack overflow in recursive/pratt-parser generated bytecode */\n readonly maxStackDepth: number;\n /** Maximum opcodes executed per expression, halts runaway infinite loops */\n readonly maxInstructions: number;\n /**\n * Maximum elements a collection may be expanded to before `map`/`reduce`/\n * `sum`/`prod` will iterate it.\n *\n * A Range is stored as its two bounds and costs nothing until something\n * materializes it, at which point it becomes one Value per element. Twenty\n * characters (`sum(x, 1:100000000)`) therefore asked for a hundred million\n * of them, and neither `maxInstructions` nor `maxStackDepth` could see it:\n * the expansion happens inside a single opcode, so the instruction counter\n * is never consulted while it runs, and the elements never reach the value\n * stack. V8 aborted the whole process with \"Reached heap limit\", which a\n * host embedding the engine cannot catch.\n */\n readonly maxCollectionSize: number;\n /**\n * Maximum elements (collection Values, matrix cells) one evaluation may\n * materialize in total.\n *\n * `maxCollectionSize` above bounds a single collection. This bounds the sum\n * of everything an expression asks for, which is a different question and\n * the one that actually protects the host: two collections that are\n * individually legal are legal together, and an operation whose result is\n * the PRODUCT of two legal operands is bounded by neither of them. A matrix\n * multiply is exactly that shape, so three lines within every other limit\n * (`:a = map(1*x, 0:20000)`, `:b = transpose(a)`, `b * a`) asked for four\n * hundred million cells and aborted the process.\n *\n * Counted in elements rather than bytes, because a count is what a call\n * site has before it allocates. An element is 8 bytes as a numeric matrix\n * cell and closer to a hundred as a full Value, so the default is worth\n * roughly 16 MB of matrix or 200 MB of expanded collection: far past any\n * document and far short of what an editor cannot survive.\n */\n readonly maxAllocatedElements: number;\n /**\n * Maximum user-defined-function calls one evaluation may make in TOTAL,\n * however deeply or widely they nest.\n *\n * `maxFunctionRecursionDepth` bounds how DEEP calls nest and cannot see\n * how MANY there are, and those are different numbers. Twenty-two lines of\n * `f(n)(v) = f(n-1)(v) + f(n-1)(v)` reach a depth of only 22 against a\n * limit of 50, and make 2,097,152 calls doing it: a fatal heap abort in\n * under a second. `maxInstructions` cannot bound it either, because\n * `executeBytecode()` re-enters itself per call and each reentrant call\n * gets its OWN instruction count, so recursion refreshes its allowance on\n * the way in. This is the tally that does not refresh; see\n * `vm/AllocationBudget.ts`, which holds it for the same reason it holds\n * the element tally.\n *\n * Counted in calls rather than in the instructions they run, because the\n * call is the thing that multiplies: every call allocates a frame, its\n * arguments and its result whatever its body says.\n */\n readonly maxFunctionCalls: number;\n /**\n * Hard ceiling on how many bisection steps goal seek (`solve line N for\n * <var> = <target>`, see `packages/goalseek/`) may take before it gives up\n * with a structured error rather than continuing.\n *\n * Goal seek re-evaluates the target line's expression once per step while\n * narrowing an interval, and an untrusted document must never be able to\n * make that loop spin. `maxInstructions` bounds each individual\n * re-evaluation, but not how many of them the search performs, so this is\n * the tally that bounds the search itself, the same reason `maxFunctionCalls`\n * exists alongside `maxInstructions`. Bisection halves the interval every\n * step, so a hundred steps resolves an input to roughly one part in 2^100:\n * far past any precision a document needs, and a definite stop either way.\n */\n readonly maxGoalSeekIterations: number;\n }\n\n/**\n * Complete engine configuration.\n *\n * Every field has a default in `DEFAULT_CONFIG`. To customize, pass a\n * `Partial<EngineConfig>` when constructing `ExpressionEngine`. Only the\n * sections/fields you supply are overridden; all others use their defaults.\n *\n * @example\n * ```typescript\n * import { ExpressionEngine } from \"solve-js\";\n *\n * const engine = new ExpressionEngine({ config: {\n * validation: {\n * maxExpressionLength: 1000,\n * maxComplexity: 200,\n * },\n * // date, performance, vm, worker, diagnostic all use defaults\n * } });\n * ```\n */\nexport interface EngineConfig {\n /** Date/time expression evaluation bounds and formatting */\n readonly date: DateConfig;\n /** Performance budgets and cache sizing */\n readonly performance: PerformanceConfig;\n /** Safety limits for expression complexity */\n readonly validation: ValidationConfig;\n /** Internal bytecode VM configuration */\n readonly vm: VMConfig;\n /** Parallel worker pool configuration */\n readonly worker: WorkerConfig;\n /** Diagnostic pipeline configuration */\n readonly diagnostic: DiagnosticConfig;\n /** Proactive background refresh of live async values */\n readonly backgroundRefresh: BackgroundRefreshConfig;\n }\n\n/**\n * A partial {@link EngineConfig} override, one section at a time.\n *\n * Overrides are merged per section over {@link DEFAULT_CONFIG}, so you can set a\n * single field of one section (`{ validation: { maxExpressionLength: 1000 } }`)\n * and keep every other default in that section. A plain `Partial<EngineConfig>`\n * cannot express that, it demands a whole section object, which is why the\n * documented overrides never typechecked against it. This is the type the\n * constructor and {@link createEngine} accept.\n */\nexport type EngineConfigOverride = {\n readonly [K in keyof EngineConfig]?: Partial<EngineConfig[K]>;\n};\n\n/**\n * Default configuration values\n */\nexport const DEFAULT_CONFIG: EngineConfig = {\n date: {\n // A century of workdays is about 26,000 steps, which is microseconds,\n // and past any offset a person means. The walk is what these bound; see\n // DateConfig above for why no other date offset needs a ceiling.\n maxOffsetYears: 100,\n minOffsetYears: -100,\n defaultFormat: 'YYYY-MM-DD',\n inputOrder: 'auto',\n },\n performance: {\n // Preserves the effective cache size the hardcoded (now-removed)\n // BYTECODE_CACHE_MAX_ENTRIES constant had, so wiring this field up\n // doesn't silently shrink the default cache for existing consumers.\n defaultCacheSize: 2000,\n // Raised from the 10,000 this field was declared with, which was never\n // enforced and turned out to be under what this engine already supports:\n // its paging design is tested against a 20,000-line document\n // (`engine/PageManager.ts` and its spec) and its throughput benchmark\n // parses a 50,000-line one. Twice the largest of those, and the same\n // number `ConfigManager.validate()` already refuses to go above.\n //\n // Measured under a 256MB heap: setting a 100,000-line document costs\n // 64MB, evaluating every line of a 20,000-line one costs 106MB, and\n // 200,000 lines aborts the process before a single expression is looked\n // at. A host with a small heap should lower this; the ceiling is here to\n // stop the size that cannot work anywhere.\n maxDocumentLines: 100000,\n },\n validation: {\n maxExpressionLength: 2000,\n maxComplexity: 500,\n maxNestingDepth: 50,\n autoBalanceParens: false,\n },\n vm: {\n maxStackDepth: 200,\n maxInstructions: 50000,\n // Two orders of magnitude above anything a person types by hand (the\n // longest range in the test suite is 1000 elements) and small enough\n // that expanding it is measured in milliseconds rather than in whether\n // the host survives.\n maxCollectionSize: 100000,\n // Twenty times the single-collection ceiling above, so an expression may\n // legitimately handle a number of large collections, and two hundred\n // times below the allocation that took the process down.\n maxAllocatedElements: 2000000,\n // Six hundred times the largest call count any test or example makes\n // (five levels of composition is sixteen calls), and small enough that\n // the calls it does allow cost single-digit megabytes rather than the\n // heap. A document that needs more than ten thousand calls on one line\n // is doing something a calculator was not built for.\n maxFunctionCalls: 10000,\n // A hundred bisection steps resolve an input to one part in 2^100, far\n // finer than any document needs and a firm stop for an untrusted one. A\n // continuous, monotonic relationship converges in tens of steps, well\n // under this; hitting it means the target is unreachable or the\n // relationship is not the smooth one goal seek assumes.\n maxGoalSeekIterations: 100,\n },\n worker: {\n maxConcurrentWorkers: 4,\n idleTimeoutMs: 30000,\n maxRetries: 3,\n baseBackoffMs: 1000,\n },\n diagnostic: {\n enabled: false,\n vmTraceEnabled: false,\n },\n backgroundRefresh: {\n enabled: false,\n },\n };\n\n/**\n * Merge a partial config override onto a base `EngineConfig`, section by\n * section, `{ ...base.section, ...override.section }` for each of the 7\n * top-level sections, not a single top-level spread.\n *\n * A shallow `{ ...base, ...override }` at the TOP level replaces an entire\n * section wholesale the moment a caller overrides even one field in it\n * (e.g. `{ performance: { defaultCacheSize: 500 } }` would silently drop\n * every other `performance.*` field back to `undefined`, not to its\n * default). This function exists specifically so every config consumer\n * shares one correct merge instead of each hand-rolling (and risking) its\n * own. `ConfigManager` and `ExpressionEngine` both call this rather than\n * either duplicating the section list or instantiating a whole\n * `ConfigManager` just to reuse its private merge logic.\n */\nexport function mergeEngineConfig(\n base: EngineConfig,\n override: EngineConfigOverride\n): EngineConfig {\n return {\n date: { ...base.date, ...override.date },\n performance: { ...base.performance, ...override.performance },\n validation: { ...base.validation, ...override.validation },\n vm: { ...base.vm, ...override.vm },\n worker: { ...base.worker, ...override.worker },\n diagnostic: { ...base.diagnostic, ...override.diagnostic },\n backgroundRefresh: { ...base.backgroundRefresh, ...override.backgroundRefresh },\n };\n}\n\n/**\n * Configuration manager for engine settings\n *\n * @example\n * ```typescript\n * const configManager = new ConfigManager();\n * configManager.set('performance.defaultCacheSize', 2000);\n * const cacheSize = configManager.get('performance.defaultCacheSize');\n * ```\n */\nexport class ConfigManager {\n private config: EngineConfig;\n\n constructor(config: Partial<EngineConfig> = {}) {\n this.config = mergeEngineConfig(DEFAULT_CONFIG, config);\n }\n\n /**\n * Get configuration value by path\n * \n * @param path - Dot-notation path to config value\n * @returns Configuration value\n */\n get<T>(path: string): T {\n const keys = path.split('.');\n let current: unknown = this.config;\n\n for (const key of keys) {\n if (current && typeof current === 'object' && key in current) {\n current = (current as Record<string, unknown>)[key];\n } else {\n throw ErrorFactory.config(\n \"CONFIG_PATH_NOT_FOUND\",\n `Configuration path not found: ${path}`,\n { path }\n );\n }\n }\n\n return current as T;\n }\n\n /**\n * Set configuration value by path\n * \n * @param path - Dot-notation path to config value\n * @param value - New value\n */\n set<T>(path: string, value: T): void {\n const keys = path.split('.');\n if (keys.length < 2) {\n throw ErrorFactory.config(\n \"INVALID_CONFIG_PATH\",\n `Invalid path: ${path}. Must be in format 'section.property'`,\n { path }\n );\n }\n \n const section = keys[0];\n const property = keys[1];\n \n if (!(section in this.config)) {\n throw ErrorFactory.config(\n \"CONFIG_SECTION_NOT_FOUND\",\n `Configuration section not found: ${section}`,\n { section, path }\n );\n }\n \n const sectionConfig = this.config[section as keyof EngineConfig];\n if (sectionConfig && typeof sectionConfig === 'object') {\n (sectionConfig as unknown as Record<string, unknown>)[property] = value;\n } else {\n throw ErrorFactory.config(\n \"CONFIG_PROPERTY_NOT_FOUND\",\n `Configuration property not found: ${path}`,\n { path }\n );\n }\n }\n\n /**\n * Get complete configuration.\n *\n * A detached copy, section objects included. A top-level spread would hand\n * the caller this manager's own section objects, so `getConfig().vm.x = 1`\n * would be an undeclared back door into {@link set}, bypassing its path\n * validation and reaching every later {@link get}.\n */\n getConfig(): EngineConfig {\n return mergeEngineConfig(this.config, {});\n }\n\n /**\n * Update multiple configuration values\n */\n update(config: Partial<EngineConfig>): void {\n this.config = mergeEngineConfig(this.config, config);\n }\n\n /**\n * Reset to default configuration.\n *\n * Goes through {@link mergeEngineConfig} for the same reason the constructor\n * does. A top-level `{ ...DEFAULT_CONFIG }` copies the six section\n * references, not the sections, so after a reset this manager's\n * `performance` object WAS `DEFAULT_CONFIG.performance` and the next\n * `set('performance.x', ...)` wrote into the module constant. That constant\n * is what every `ExpressionEngine` is built from, so one manager's reset\n * could change the cache size, instruction ceiling or allocation budget of\n * every engine constructed later in the process.\n */\n reset(): void {\n this.config = mergeEngineConfig(DEFAULT_CONFIG, {});\n }\n\n /**\n * Validate configuration values\n */\n validate(): ValidationResult {\n const errors: string[] = [];\n\n // Validate performance config\n if (this.config.performance.maxDocumentLines > 100000) {\n errors.push('maxDocumentLines cannot exceed 100,000');\n }\n\n // Validate date config\n if (this.config.date.maxOffsetYears > 1000) {\n errors.push('maxOffsetYears cannot exceed 1000');\n }\n\n return {\n valid: errors.length === 0,\n error: errors.join('; '),\n warnings: []\n };\n }\n}\n\n/**\n * Result type for {@link ConfigManager.validate}.\n */\nexport interface ValidationResult {\n valid: boolean;\n error?: string;\n warnings?: string[];\n}\n\n"]}
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/constants/version.ts","../src/constants/Configuration.ts"],"names":["version","ENGINE_VERSION","DEFAULT_CONFIG","mergeEngineConfig","base","override","ConfigManager","config","path","keys","current","key","ErrorFactory","value","section","property","sectionConfig","errors"],"mappings":"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","file":"chunk-7RTKJMYS.js","sourcesContent":["{\n \"name\": \"solve-engine\",\n \"version\": \"2.5.0\",\n \"description\": \"An embeddable expression engine for natural-language calculations: units, currencies, percentages, dates and matrices, with the parsing and evaluation plumbing already built.\",\n \"keywords\": [\n \"expression-evaluator\",\n \"calculator\",\n \"bytecode-vm\",\n \"parser\",\n \"lexer\",\n \"dsl\",\n \"markdown\",\n \"obsidian\"\n ],\n \"license\": \"MIT\",\n \"author\": \"Liam Riddell\",\n \"homepage\": \"https://liamriddell.github.io/solve-engine/\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/LiamRiddell/solve-engine.git\",\n \"directory\": \"packages/engine\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/LiamRiddell/solve-engine/issues\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"type\": \"module\",\n \"engines\": {\n \"node\": \">=22\"\n },\n \"files\": [\n \"dist\",\n \"LICENSE\"\n ],\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.cts\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"./engine\": {\n \"import\": {\n \"types\": \"./dist/engine.d.ts\",\n \"default\": \"./dist/engine.js\"\n },\n \"require\": {\n \"types\": \"./dist/engine.d.cts\",\n \"default\": \"./dist/engine.cjs\"\n }\n },\n \"./vm\": {\n \"import\": {\n \"types\": \"./dist/vm.d.ts\",\n \"default\": \"./dist/vm.js\"\n },\n \"require\": {\n \"types\": \"./dist/vm.d.cts\",\n \"default\": \"./dist/vm.cjs\"\n }\n },\n \"./format\": {\n \"import\": {\n \"types\": \"./dist/format.d.ts\",\n \"default\": \"./dist/format.js\"\n },\n \"require\": {\n \"types\": \"./dist/format.d.cts\",\n \"default\": \"./dist/format.cjs\"\n }\n },\n \"./language\": {\n \"import\": {\n \"types\": \"./dist/language.d.ts\",\n \"default\": \"./dist/language.js\"\n },\n \"require\": {\n \"types\": \"./dist/language.d.cts\",\n \"default\": \"./dist/language.cjs\"\n }\n },\n \"./packages\": {\n \"import\": {\n \"types\": \"./dist/packages.d.ts\",\n \"default\": \"./dist/packages.js\"\n },\n \"require\": {\n \"types\": \"./dist/packages.d.cts\",\n \"default\": \"./dist/packages.cjs\"\n }\n },\n \"./constants\": {\n \"import\": {\n \"types\": \"./dist/constants.d.ts\",\n \"default\": \"./dist/constants.js\"\n },\n \"require\": {\n \"types\": \"./dist/constants.d.cts\",\n \"default\": \"./dist/constants.cjs\"\n }\n },\n \"./lexer\": {\n \"import\": {\n \"types\": \"./dist/lexer.d.ts\",\n \"default\": \"./dist/lexer.js\"\n },\n \"require\": {\n \"types\": \"./dist/lexer.d.cts\",\n \"default\": \"./dist/lexer.cjs\"\n }\n },\n \"./parser\": {\n \"import\": {\n \"types\": \"./dist/parser.d.ts\",\n \"default\": \"./dist/parser.js\"\n },\n \"require\": {\n \"types\": \"./dist/parser.d.cts\",\n \"default\": \"./dist/parser.cjs\"\n }\n },\n \"./normalizer\": {\n \"import\": {\n \"types\": \"./dist/normalizer.d.ts\",\n \"default\": \"./dist/normalizer.js\"\n },\n \"require\": {\n \"types\": \"./dist/normalizer.d.cts\",\n \"default\": \"./dist/normalizer.cjs\"\n }\n },\n \"./resolvers\": {\n \"import\": {\n \"types\": \"./dist/resolvers.d.ts\",\n \"default\": \"./dist/resolvers.js\"\n },\n \"require\": {\n \"types\": \"./dist/resolvers.d.cts\",\n \"default\": \"./dist/resolvers.cjs\"\n }\n },\n \"./errors\": {\n \"import\": {\n \"types\": \"./dist/errors.d.ts\",\n \"default\": \"./dist/errors.js\"\n },\n \"require\": {\n \"types\": \"./dist/errors.d.cts\",\n \"default\": \"./dist/errors.cjs\"\n }\n },\n \"./utilities\": {\n \"import\": {\n \"types\": \"./dist/utilities.d.ts\",\n \"default\": \"./dist/utilities.js\"\n },\n \"require\": {\n \"types\": \"./dist/utilities.d.cts\",\n \"default\": \"./dist/utilities.cjs\"\n }\n },\n \"./uom\": {\n \"import\": {\n \"types\": \"./dist/uom.d.ts\",\n \"default\": \"./dist/uom.js\"\n },\n \"require\": {\n \"types\": \"./dist/uom.d.cts\",\n \"default\": \"./dist/uom.cjs\"\n }\n },\n \"./services\": {\n \"import\": {\n \"types\": \"./dist/services.d.ts\",\n \"default\": \"./dist/services.js\"\n },\n \"require\": {\n \"types\": \"./dist/services.d.cts\",\n \"default\": \"./dist/services.cjs\"\n }\n },\n \"./worker\": {\n \"import\": {\n \"types\": \"./dist/worker.d.ts\",\n \"default\": \"./dist/worker.js\"\n },\n \"require\": {\n \"types\": \"./dist/worker.d.cts\",\n \"default\": \"./dist/worker.cjs\"\n }\n },\n \"./testing\": {\n \"import\": {\n \"types\": \"./dist/testing.d.ts\",\n \"default\": \"./dist/testing.js\"\n },\n \"require\": {\n \"types\": \"./dist/testing.d.cts\",\n \"default\": \"./dist/testing.cjs\"\n }\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"prepublishOnly\": \"npm run build && node ../../scripts/assert-publishable.mjs .\",\n \"dev\": \"tsup --watch\",\n \"test\": \"jest --config jest.config.cjs --no-coverage\",\n \"typecheck\": \"tsgo --noEmit --skipLibCheck\",\n \"typecheck:tsc\": \"tsc --noEmit --skipLibCheck\"\n },\n \"dependencies\": {\n \"@tanstack/query-core\": \"^5.100.10\"\n },\n \"devDependencies\": {\n \"@jest/globals\": \"^30.4.1\",\n \"@types/node\": \"^26.2.0\",\n \"convert\": \"^7.0.0\",\n \"jest\": \"^30.4.2\",\n \"ts-jest\": \"^29.4.12\",\n \"tsup\": \"8.5.1\",\n \"typescript\": \"5.9.3\"\n },\n \"//sideEffects\": \"Load-bearing claim, not boilerplate. tsup's splitting emits bare chunk imports at the top of dist/index.js, and this field tells Rollup, webpack and Vite they may delete them, which esbuild reports as [ignored-bare-import] once per import during `npm run size`. The engine does have module-level work to lose: registerAllTokenTypes(), _PrecedenceParser.BP_TABLE and its cached token ids, and several process-wide registries. It is safe because every chunk doing that work is also imported for its bindings somewhere, so no bundler can drop it. That is a property of how tsup currently splits the code rather than a design guarantee, so `npm run smoke:bundled` (scripts/check-tree-shaking.mjs) proves it on every run of `npm run verify` instead of assuming it, and its header explains the two fixes if it ever stops holding.\",\n \"sideEffects\": false\n}\n","/**\n * The running engine's own semver version, sourced directly from this\n * package's package.json so it can never drift from what's actually\n * published. Exists so IEnginePackage.engineVersion range checks\n * (api/EngineVersionCompatibility.ts) have something real to check\n * against.\n */\nimport { version } from \"../../package.json\";\n\n/**\n * The running engine's version, taken from package.json.\n *\n * What a package's `engineVersion` range is checked against at registration.\n * A prerelease is compared by its coerced release version, so a 1.0.0 beta\n * satisfies `^1.0.0`. See `api/EngineVersionCompatibility.ts`.\n */\nexport const ENGINE_VERSION: string = version;\n","/**\n * Configuration Module for solve-js Engine\n * \n * This module provides the **single source of truth** for all engine configuration.\n * Every configurable aspect of the engine, from safety limits and performance\n * budgets to VM constraints and worker pool sizing, is defined here.\n * \n * ### Design principles\n * \n * 1. **Engine owns its config.** The engine defines its own config shape and defaults.\n * Consumers (e.g., the Obsidian plugin) pass partial overrides; all unspecified\n * fields fall back to `DEFAULT_CONFIG`.\n * \n * 2. **Self-documenting.** Every interface and field has descriptive JSDoc so the\n * config is understandable at a glance, whether you're using the engine as an\n * npm package or reading the source.\n * \n * 3. **Minimal consumer knowledge.** Consumers only need to pass `Partial<EngineConfig>`.\n * They don't need to replicate the full config shape, just the fields they\n * want to override.\n * \n * @module Configuration\n */\n\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * A host's test for whether a calendar date is a public holiday, given the\n * `Date` for that day at local midnight. Return `true` to exclude it from\n * working-day arithmetic.\n */\nexport type HolidayPredicate = (date: Date) => boolean;\n\n/**\n * The host-supplied public-holiday calendar, in the same \"bring your own data\"\n * shape the stocks and weather packages already use for a host callback (see\n * `packages/stocks/StocksPackage.ts`): weekends are decidable from the date\n * alone, holidays are not, so they come from the host or not at all.\n *\n * Either a {@link HolidayPredicate}, for a host that computes holidays itself\n * (an existing library, a region rule), or an iterable of specific dates as\n * `YYYY-MM-DD` strings, epoch-millisecond numbers or `Date` objects, for a host\n * that just has a list. Resolved to one internal predicate by\n * `vm/HolidayCalendar.ts`'s `resolveHolidayPredicate()`.\n *\n * Left unset, working-day arithmetic skips weekends only, which is the honest\n * default: the engine excludes exactly the days it can prove are non-working.\n */\nexport type HolidayCalendar = HolidayPredicate | Iterable<string | number | Date>;\n\n/**\n * Date-related configuration.\n * Controls the bounds and formatting for date/time expression evaluation\n * (e.g., `today + 20 days`, `last monday`).\n */\n/**\n * How an ambiguous all-numeric date literal is read.\n *\n * - `'auto'`: by separator, the historic behaviour. A slash date is\n * day-first (`25/12/2023`), a hyphen date is month-first (`12-25-2023`)\n * unless its first group is four digits, which makes it ISO (`2023-12-25`).\n * - `'DMY'` / `'MDY'` / `'YMD'`: a fixed order for every numeric separator, so\n * a host can match its readers' locale. `'MDY'` is what lets a US reader's\n * `12/25/2023` parse, which `'auto'` refuses because the slash defaults to\n * day-first.\n *\n * Only the all-numeric literals are affected. A spelled-out month (`March 9,\n * 2024`) is never ambiguous, and an ISO timestamp is always read as ISO.\n */\nexport type DateInputOrder = 'auto' | 'DMY' | 'MDY' | 'YMD';\n\n/** Date-related engine configuration: offset limits, input order, holidays. */\nexport interface DateConfig {\n /**\n * The order an ambiguous all-numeric date literal is read in. Defaults to\n * `'auto'` (by separator, the historic behaviour). See {@link DateInputOrder}.\n */\n readonly inputOrder: DateInputOrder;\n /**\n * How far forward a date offset whose COST grows with the offset may reach,\n * in years. Enforced by `vm/VM.ts`'s `addBusinessDays()`.\n *\n * Bounds the walk, not the calendar. Every other date offset in the engine\n * is arithmetic on a Date field, so `today + 100000 days` costs exactly what\n * one day costs and needs no ceiling; workdays are the one offset that has\n * to step day by day, because which days are skipped depends on where each\n * step lands. `today + 100000000 workdays` therefore froze the host for\n * thirteen seconds inside a single ADD opcode (where `vm.maxInstructions`\n * cannot see it) and then answered \"Invalid Date\", and a trillion never\n * returned at all.\n *\n * Release hardening: this field was declared, documented as a \"safety\n * limit\", and read nowhere, so it bounded nothing. A limit a host can\n * configure and the engine ignores is worse than no limit, because it reads\n * as protection that is not there.\n */\n readonly maxOffsetYears: number;\n /** How far BACK the same walk may reach, in years, as a negative number. See {@link maxOffsetYears}. */\n readonly minOffsetYears: number;\n /** Default date string format for display (moment.js format string) */\n readonly defaultFormat: string;\n /**\n * Public-holiday calendar for working-day arithmetic (`N working days after\n * <date>`, `working days between <date> and <date>`, `<date> + N workdays`).\n * See {@link HolidayCalendar}.\n *\n * Optional and unset by default: with no calendar, working-day arithmetic\n * skips weekends only. A host that wants holidays excluded too supplies one\n * here (`new ExpressionEngine({ config: { date: { holidays } } })`), the\n * same way stocks and weather take a host data source. Threaded into the VM\n * by `engine/ExpressionEngine.ts` exactly as {@link maxOffsetYears} is,\n * because working-day math is a VM operation several grammar forms share, so\n * the calendar has to be one source the VM owns rather than per-package state\n * the VM cannot see.\n */\n readonly holidays?: HolidayCalendar;\n}\n\n/**\n * Performance-related configuration.\n * Controls caching, timeouts, and processing limits to prevent runaway\n * resource consumption on large documents.\n */\nexport interface PerformanceConfig {\n /**\n * Maximum number of entries in {@link ExpressionEngine}'s bytecode cache\n * (per-instance, keyed by expression text) before the oldest entry is\n * evicted. Raise this for documents with many distinct expressions if\n * repeated re-evaluation (e.g. scrolling) is re-parsing instead of\n * hitting cache, bug fix (release hardening pass): this field used to\n * be read nowhere; the cache size was a hardcoded, unconfigurable\n * constant. Note this does NOT bound {@link LineCache}, which has no\n * size limit of its own.\n */\n readonly defaultCacheSize: number;\n /**\n * Maximum lines a document may have for the engine to process it in one\n * pass. Enforced by `ExpressionEngine.parseDocument()` and by\n * `engine/DocumentModel.ts`'s `setDocument()`, the two entry points that\n * take a whole document.\n *\n * A document costs memory per line whatever each line says: a parsed line\n * record, a cache entry, a dependency-graph node. Two hundred thousand\n * lines of `1 + 1` therefore exhausted the heap and aborted the process\n * before any per-line limit had anything to object to, which is the same\n * shape of hole as an unbounded expression and needs the same kind of\n * ceiling. Refusing the document names the limit; a host that genuinely has\n * a larger one raises this field.\n *\n * Release hardening: declared and read nowhere until now.\n */\n readonly maxDocumentLines: number;\n}\n\n/**\n * Validation / safety-limit configuration.\n * Protects against runaway expressions that could cause excessive memory use\n * or stack overflow. These limits are checked during lexing and parsing.\n */\n/** Bounds on untrusted input: expression length and nesting depth. */\nexport interface ValidationConfig {\n /** Maximum expression length in characters. Prevents excessively long strings from entering the pipeline. */\n readonly maxExpressionLength: number;\n /** Maximum expression complexity score (`tokens + functionCalls×5 + nestingDepth×10`). Protects against deeply nested or combinatorially complex expressions. */\n readonly maxComplexity: number;\n /** Maximum parentheses nesting depth. Prevents stack overflow in the recursive-descent parser. */\n readonly maxNestingDepth: number;\n /**\n * Auto-balance unmatched parentheses by appending missing closing parens\n * or prepending missing opening parens. When disabled, unbalanced expressions\n * cause parse errors instead of being silently corrected.\n *\n * Disabled by default for strict parsing. Enable for forgiving user input\n * (e.g., chat-style calculators where users often omit closing parens).\n * Has zero overhead when disabled, the O(n) paren-count scan is skipped.\n */\n readonly autoBalanceParens: boolean;\n}\n\n/**\n * Worker pool configuration.\n * Controls the parallel execution workers used for batch evaluation.\n */\nexport interface WorkerConfig {\n /** Maximum number of concurrent Web Workers allowed */\n readonly maxConcurrentWorkers: number;\n /** Time (ms) a worker stays alive while idle before being terminated */\n readonly idleTimeoutMs: number;\n /** Maximum retry attempts for a failed worker operation */\n readonly maxRetries: number;\n /** Base backoff delay (ms) between retries (exponential backoff applied on top) */\n readonly baseBackoffMs: number;\n} /**\n * Diagnostic / telemetry configuration.\n * Controls the diagnostic event pipeline for profiling and debugging.\n * All diagnostics are disabled by default for maximum production performance.\n */\n export interface DiagnosticConfig {\n /** Master switch: enable the diagnostic pipeline (collectors receive events for all pipeline stages) */\n readonly enabled: boolean;\n /** Enable VM trace mode, emits per-opcode execution events (very verbose; disables some optimizations) */\n readonly vmTraceEnabled: boolean;\n }\n\n /**\n * Proactive background refresh of live async values.\n *\n * Off by default. When a live value (a stock quote, an FX rate) has gone\n * stale, today it only refetches on the next re-evaluation (a keystroke), so a\n * note left open silently ages. With this enabled, the engine drives a refetch\n * on each such value's own cadence (the resolver's `refetchIntervalMs`) for the\n * values currently on screen, and pushes the fresh result to the host through\n * the same event stream the pull path uses. It needs timers and a live editor\n * consuming that stream, so a headless or batch host leaves it off.\n */\n export interface BackgroundRefreshConfig {\n /** Master switch. When false, no timers run and every value refreshes only on re-evaluation. */\n readonly enabled: boolean;\n }\n\n /**\n * Virtual Machine configuration.\n * Controls the internal bytecode VM that executes compiled expressions.\n */\n export interface VMConfig {\n /** Maximum stack depth (value slots) for VM execution, prevents stack overflow in recursive/pratt-parser generated bytecode */\n readonly maxStackDepth: number;\n /** Maximum opcodes executed per expression, halts runaway infinite loops */\n readonly maxInstructions: number;\n /**\n * Maximum elements a collection may be expanded to before `map`/`reduce`/\n * `sum`/`prod` will iterate it.\n *\n * A Range is stored as its two bounds and costs nothing until something\n * materializes it, at which point it becomes one Value per element. Twenty\n * characters (`sum(x, 1:100000000)`) therefore asked for a hundred million\n * of them, and neither `maxInstructions` nor `maxStackDepth` could see it:\n * the expansion happens inside a single opcode, so the instruction counter\n * is never consulted while it runs, and the elements never reach the value\n * stack. V8 aborted the whole process with \"Reached heap limit\", which a\n * host embedding the engine cannot catch.\n */\n readonly maxCollectionSize: number;\n /**\n * Maximum elements (collection Values, matrix cells) one evaluation may\n * materialize in total.\n *\n * `maxCollectionSize` above bounds a single collection. This bounds the sum\n * of everything an expression asks for, which is a different question and\n * the one that actually protects the host: two collections that are\n * individually legal are legal together, and an operation whose result is\n * the PRODUCT of two legal operands is bounded by neither of them. A matrix\n * multiply is exactly that shape, so three lines within every other limit\n * (`:a = map(1*x, 0:20000)`, `:b = transpose(a)`, `b * a`) asked for four\n * hundred million cells and aborted the process.\n *\n * Counted in elements rather than bytes, because a count is what a call\n * site has before it allocates. An element is 8 bytes as a numeric matrix\n * cell and closer to a hundred as a full Value, so the default is worth\n * roughly 16 MB of matrix or 200 MB of expanded collection: far past any\n * document and far short of what an editor cannot survive.\n */\n readonly maxAllocatedElements: number;\n /**\n * Maximum user-defined-function calls one evaluation may make in TOTAL,\n * however deeply or widely they nest.\n *\n * `maxFunctionRecursionDepth` bounds how DEEP calls nest and cannot see\n * how MANY there are, and those are different numbers. Twenty-two lines of\n * `f(n)(v) = f(n-1)(v) + f(n-1)(v)` reach a depth of only 22 against a\n * limit of 50, and make 2,097,152 calls doing it: a fatal heap abort in\n * under a second. `maxInstructions` cannot bound it either, because\n * `executeBytecode()` re-enters itself per call and each reentrant call\n * gets its OWN instruction count, so recursion refreshes its allowance on\n * the way in. This is the tally that does not refresh; see\n * `vm/AllocationBudget.ts`, which holds it for the same reason it holds\n * the element tally.\n *\n * Counted in calls rather than in the instructions they run, because the\n * call is the thing that multiplies: every call allocates a frame, its\n * arguments and its result whatever its body says.\n */\n readonly maxFunctionCalls: number;\n /**\n * Hard ceiling on how many bisection steps goal seek (`solve line N for\n * <var> = <target>`, see `packages/goalseek/`) may take before it gives up\n * with a structured error rather than continuing.\n *\n * Goal seek re-evaluates the target line's expression once per step while\n * narrowing an interval, and an untrusted document must never be able to\n * make that loop spin. `maxInstructions` bounds each individual\n * re-evaluation, but not how many of them the search performs, so this is\n * the tally that bounds the search itself, the same reason `maxFunctionCalls`\n * exists alongside `maxInstructions`. Bisection halves the interval every\n * step, so a hundred steps resolves an input to roughly one part in 2^100:\n * far past any precision a document needs, and a definite stop either way.\n */\n readonly maxGoalSeekIterations: number;\n }\n\n/**\n * Complete engine configuration.\n *\n * Every field has a default in `DEFAULT_CONFIG`. To customize, pass a\n * `Partial<EngineConfig>` when constructing `ExpressionEngine`. Only the\n * sections/fields you supply are overridden; all others use their defaults.\n *\n * @example\n * ```typescript\n * import { ExpressionEngine } from \"solve-js\";\n *\n * const engine = new ExpressionEngine({ config: {\n * validation: {\n * maxExpressionLength: 1000,\n * maxComplexity: 200,\n * },\n * // date, performance, vm, worker, diagnostic all use defaults\n * } });\n * ```\n */\nexport interface EngineConfig {\n /** Date/time expression evaluation bounds and formatting */\n readonly date: DateConfig;\n /** Performance budgets and cache sizing */\n readonly performance: PerformanceConfig;\n /** Safety limits for expression complexity */\n readonly validation: ValidationConfig;\n /** Internal bytecode VM configuration */\n readonly vm: VMConfig;\n /** Parallel worker pool configuration */\n readonly worker: WorkerConfig;\n /** Diagnostic pipeline configuration */\n readonly diagnostic: DiagnosticConfig;\n /** Proactive background refresh of live async values */\n readonly backgroundRefresh: BackgroundRefreshConfig;\n }\n\n/**\n * A partial {@link EngineConfig} override, one section at a time.\n *\n * Overrides are merged per section over {@link DEFAULT_CONFIG}, so you can set a\n * single field of one section (`{ validation: { maxExpressionLength: 1000 } }`)\n * and keep every other default in that section. A plain `Partial<EngineConfig>`\n * cannot express that, it demands a whole section object, which is why the\n * documented overrides never typechecked against it. This is the type the\n * constructor and {@link createEngine} accept.\n */\nexport type EngineConfigOverride = {\n readonly [K in keyof EngineConfig]?: Partial<EngineConfig[K]>;\n};\n\n/**\n * Default configuration values\n */\nexport const DEFAULT_CONFIG: EngineConfig = {\n date: {\n // A century of workdays is about 26,000 steps, which is microseconds,\n // and past any offset a person means. The walk is what these bound; see\n // DateConfig above for why no other date offset needs a ceiling.\n maxOffsetYears: 100,\n minOffsetYears: -100,\n defaultFormat: 'YYYY-MM-DD',\n inputOrder: 'auto',\n },\n performance: {\n // Preserves the effective cache size the hardcoded (now-removed)\n // BYTECODE_CACHE_MAX_ENTRIES constant had, so wiring this field up\n // doesn't silently shrink the default cache for existing consumers.\n defaultCacheSize: 2000,\n // Raised from the 10,000 this field was declared with, which was never\n // enforced and turned out to be under what this engine already supports:\n // its paging design is tested against a 20,000-line document\n // (`engine/PageManager.ts` and its spec) and its throughput benchmark\n // parses a 50,000-line one. Twice the largest of those, and the same\n // number `ConfigManager.validate()` already refuses to go above.\n //\n // Measured under a 256MB heap: setting a 100,000-line document costs\n // 64MB, evaluating every line of a 20,000-line one costs 106MB, and\n // 200,000 lines aborts the process before a single expression is looked\n // at. A host with a small heap should lower this; the ceiling is here to\n // stop the size that cannot work anywhere.\n maxDocumentLines: 100000,\n },\n validation: {\n maxExpressionLength: 2000,\n maxComplexity: 500,\n maxNestingDepth: 50,\n autoBalanceParens: false,\n },\n vm: {\n maxStackDepth: 200,\n maxInstructions: 50000,\n // Two orders of magnitude above anything a person types by hand (the\n // longest range in the test suite is 1000 elements) and small enough\n // that expanding it is measured in milliseconds rather than in whether\n // the host survives.\n maxCollectionSize: 100000,\n // Twenty times the single-collection ceiling above, so an expression may\n // legitimately handle a number of large collections, and two hundred\n // times below the allocation that took the process down.\n maxAllocatedElements: 2000000,\n // Six hundred times the largest call count any test or example makes\n // (five levels of composition is sixteen calls), and small enough that\n // the calls it does allow cost single-digit megabytes rather than the\n // heap. A document that needs more than ten thousand calls on one line\n // is doing something a calculator was not built for.\n maxFunctionCalls: 10000,\n // A hundred bisection steps resolve an input to one part in 2^100, far\n // finer than any document needs and a firm stop for an untrusted one. A\n // continuous, monotonic relationship converges in tens of steps, well\n // under this; hitting it means the target is unreachable or the\n // relationship is not the smooth one goal seek assumes.\n maxGoalSeekIterations: 100,\n },\n worker: {\n maxConcurrentWorkers: 4,\n idleTimeoutMs: 30000,\n maxRetries: 3,\n baseBackoffMs: 1000,\n },\n diagnostic: {\n enabled: false,\n vmTraceEnabled: false,\n },\n backgroundRefresh: {\n enabled: false,\n },\n };\n\n/**\n * Merge a partial config override onto a base `EngineConfig`, section by\n * section, `{ ...base.section, ...override.section }` for each of the 7\n * top-level sections, not a single top-level spread.\n *\n * A shallow `{ ...base, ...override }` at the TOP level replaces an entire\n * section wholesale the moment a caller overrides even one field in it\n * (e.g. `{ performance: { defaultCacheSize: 500 } }` would silently drop\n * every other `performance.*` field back to `undefined`, not to its\n * default). This function exists specifically so every config consumer\n * shares one correct merge instead of each hand-rolling (and risking) its\n * own. `ConfigManager` and `ExpressionEngine` both call this rather than\n * either duplicating the section list or instantiating a whole\n * `ConfigManager` just to reuse its private merge logic.\n */\nexport function mergeEngineConfig(\n base: EngineConfig,\n override: EngineConfigOverride\n): EngineConfig {\n return {\n date: { ...base.date, ...override.date },\n performance: { ...base.performance, ...override.performance },\n validation: { ...base.validation, ...override.validation },\n vm: { ...base.vm, ...override.vm },\n worker: { ...base.worker, ...override.worker },\n diagnostic: { ...base.diagnostic, ...override.diagnostic },\n backgroundRefresh: { ...base.backgroundRefresh, ...override.backgroundRefresh },\n };\n}\n\n/**\n * Configuration manager for engine settings\n *\n * @example\n * ```typescript\n * const configManager = new ConfigManager();\n * configManager.set('performance.defaultCacheSize', 2000);\n * const cacheSize = configManager.get('performance.defaultCacheSize');\n * ```\n */\nexport class ConfigManager {\n private config: EngineConfig;\n\n constructor(config: Partial<EngineConfig> = {}) {\n this.config = mergeEngineConfig(DEFAULT_CONFIG, config);\n }\n\n /**\n * Get configuration value by path\n * \n * @param path - Dot-notation path to config value\n * @returns Configuration value\n */\n get<T>(path: string): T {\n const keys = path.split('.');\n let current: unknown = this.config;\n\n for (const key of keys) {\n if (current && typeof current === 'object' && key in current) {\n current = (current as Record<string, unknown>)[key];\n } else {\n throw ErrorFactory.config(\n \"CONFIG_PATH_NOT_FOUND\",\n `Configuration path not found: ${path}`,\n { path }\n );\n }\n }\n\n return current as T;\n }\n\n /**\n * Set configuration value by path\n * \n * @param path - Dot-notation path to config value\n * @param value - New value\n */\n set<T>(path: string, value: T): void {\n const keys = path.split('.');\n if (keys.length < 2) {\n throw ErrorFactory.config(\n \"INVALID_CONFIG_PATH\",\n `Invalid path: ${path}. Must be in format 'section.property'`,\n { path }\n );\n }\n \n const section = keys[0];\n const property = keys[1];\n \n if (!(section in this.config)) {\n throw ErrorFactory.config(\n \"CONFIG_SECTION_NOT_FOUND\",\n `Configuration section not found: ${section}`,\n { section, path }\n );\n }\n \n const sectionConfig = this.config[section as keyof EngineConfig];\n if (sectionConfig && typeof sectionConfig === 'object') {\n (sectionConfig as unknown as Record<string, unknown>)[property] = value;\n } else {\n throw ErrorFactory.config(\n \"CONFIG_PROPERTY_NOT_FOUND\",\n `Configuration property not found: ${path}`,\n { path }\n );\n }\n }\n\n /**\n * Get complete configuration.\n *\n * A detached copy, section objects included. A top-level spread would hand\n * the caller this manager's own section objects, so `getConfig().vm.x = 1`\n * would be an undeclared back door into {@link set}, bypassing its path\n * validation and reaching every later {@link get}.\n */\n getConfig(): EngineConfig {\n return mergeEngineConfig(this.config, {});\n }\n\n /**\n * Update multiple configuration values\n */\n update(config: Partial<EngineConfig>): void {\n this.config = mergeEngineConfig(this.config, config);\n }\n\n /**\n * Reset to default configuration.\n *\n * Goes through {@link mergeEngineConfig} for the same reason the constructor\n * does. A top-level `{ ...DEFAULT_CONFIG }` copies the six section\n * references, not the sections, so after a reset this manager's\n * `performance` object WAS `DEFAULT_CONFIG.performance` and the next\n * `set('performance.x', ...)` wrote into the module constant. That constant\n * is what every `ExpressionEngine` is built from, so one manager's reset\n * could change the cache size, instruction ceiling or allocation budget of\n * every engine constructed later in the process.\n */\n reset(): void {\n this.config = mergeEngineConfig(DEFAULT_CONFIG, {});\n }\n\n /**\n * Validate configuration values\n */\n validate(): ValidationResult {\n const errors: string[] = [];\n\n // Validate performance config\n if (this.config.performance.maxDocumentLines > 100000) {\n errors.push('maxDocumentLines cannot exceed 100,000');\n }\n\n // Validate date config\n if (this.config.date.maxOffsetYears > 1000) {\n errors.push('maxOffsetYears cannot exceed 1000');\n }\n\n return {\n valid: errors.length === 0,\n error: errors.join('; '),\n warnings: []\n };\n }\n}\n\n/**\n * Result type for {@link ConfigManager.validate}.\n */\nexport interface ValidationResult {\n valid: boolean;\n error?: string;\n warnings?: string[];\n}\n\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var chunkAXMQG5TS_cjs=require('./chunk-AXMQG5TS.cjs'),chunkYFWAR766_cjs=require('./chunk-YFWAR766.cjs'),chunk4BZIYU7S_cjs=require('./chunk-4BZIYU7S.cjs'),chunkJFAJN3C2_cjs=require('./chunk-JFAJN3C2.cjs'),chunkN7N7MPMK_cjs=require('./chunk-N7N7MPMK.cjs'),chunkPS272DZJ_cjs=require('./chunk-PS272DZJ.cjs'),chunkIANAMBJQ_cjs=require('./chunk-IANAMBJQ.cjs'),chunkCIQOK7Q4_cjs=require('./chunk-CIQOK7Q4.cjs'),chunkSOMGSIO4_cjs=require('./chunk-SOMGSIO4.cjs');var At=class{constructor(){this.consumers=new Map;this.dependencies=new Map;this.writes=new Map;this.lineReads=new Map;this.dataSourceDependencies=new Map;this.dataSourceConsumers=new Map;}registerLine(a,o,u){let m=this.lineReads.get(a);if(m)for(let h of m){let b=this.consumers.get(h);b&&b.delete(a);}this.lineReads.set(a,new Set(o));for(let h of o)this.consumers.has(h)||this.consumers.set(h,new Set),this.consumers.get(h).add(a);if(u.length>0){this.dependencies.set(a,new Set(o)),this.writes.set(a,new Set(u));for(let h of u){let b=this.consumers.get(h);b&&b.delete(a);}}}registerLineDataSourceDependency(a,o,u){let m=JSON.stringify(u),h=`${o}:${m}`;this.dataSourceDependencies.has(a)||this.dataSourceDependencies.set(a,new Set),this.dataSourceDependencies.get(a).add(h),this.dataSourceConsumers.has(h)||this.dataSourceConsumers.set(h,new Set),this.dataSourceConsumers.get(h).add(a);}getAffectedLines(a){let o=new Set,u=[a];for(;u.length>0;){let m=u.pop(),h=this.consumers.get(m);if(h)for(let b of h){if(o.has(b))continue;o.add(b);let d=this.writes.get(b);if(d)for(let y of d)u.push(y);}}return o}getAffectedLinesInOrder(a){let o=this.getAffectedLines(a);if(o.size===0)return [];let u=new Map,m=new Map;for(let y of o)u.has(y)||u.set(y,0),m.has(y)||m.set(y,[]);let h=new Map;for(let y of o){let x=this.writes.get(y);if(x)for(let S of x)h.set(S,y);}for(let y of o){let x=this.lineReads.get(y);if(x)for(let S of x){let A=h.get(S);A!==void 0&&A!==y&&(m.get(A).push(y),u.set(y,(u.get(y)??0)+1));}}let b=[];for(let[y,x]of u)x===0&&b.push(y);if(b.length===0&&o.size>0){let y=Array.from(o).sort((x,S)=>x-S);b.push(y[0]);}let d=[];for(;b.length>0;){let y=b.shift();d.push(y);for(let x of m.get(y)??[]){let S=(u.get(x)??1)-1;u.set(x,S),S===0&&b.push(x);}}if(d.length<o.size){let y=new Set(d),x=Array.from(o).filter(S=>!y.has(S)).sort((S,A)=>S-A);d.push(...x);}return d}getAffectedLinesByDataSource(a,o){let u=JSON.stringify(o),m=`${a}:${u}`;return this.dataSourceConsumers.get(m)??new Set}removeLine(a){let o=this.lineReads.get(a);if(o){for(let m of o){let h=this.consumers.get(m);h&&h.delete(a);}this.lineReads.delete(a);}this.dependencies.delete(a),this.writes.delete(a);let u=this.dataSourceDependencies.get(a);if(u){for(let m of u)this.dataSourceConsumers.get(m)?.delete(a);this.dataSourceDependencies.delete(a);}}getConsumers(a){return this.consumers.get(a)??new Set}getDependencies(a){return this.dependencies.get(a)??new Set}getWrites(a){return this.writes.get(a)??new Set}getSnapshot(){let a={};for(let[b,d]of this.consumers)a[b]=Array.from(d);let o={};for(let[b,d]of this.writes)o[b]=Array.from(d);let u={};for(let[b,d]of this.lineReads)u[b]=Array.from(d);let m={};for(let[b,d]of this.dataSourceDependencies)m[b]=Array.from(d);let h={};for(let[b,d]of this.dataSourceConsumers)h[b]=Array.from(d);return {consumers:a,writes:o,reads:u,dataSourceDeps:m,dataSourceConsumers:h}}clear(){this.consumers.clear(),this.dependencies.clear(),this.writes.clear(),this.lineReads.clear(),this.dataSourceDependencies.clear(),this.dataSourceConsumers.clear();}};var wt=class{constructor(){this.definitions=new Map;}write(a,o,u){this.definitions.has(a)||this.definitions.set(a,[]);let m=this.definitions.get(a);m.push({line:o,expr:u}),m.sort((h,b)=>h.line-b.line);}read(a,o){let u=this.definitions.get(a);if(u){for(let m=u.length-1;m>=0;m--)if(u[m].line<=o)return u[m].expr.lastResult}}invalidateDownstream(a,o){let u=this.definitions.get(a);if(!u)return;let m=u.findIndex(h=>h.line===o);m!==-1&&u.splice(m+1);}clear(){this.definitions.clear();}};function zt(r){let a=new Date(r).getDay();return a===0||a===6}function Ut(r,a){return zt(r)?false:a?!a(r):true}function Ct(r){let a=new Date(r);return new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime()}function vt(r,a,o,u){let m=Math.trunc(Math.abs(a)),h=a>=0?1:-1,b=new Date(r),d=0;for(;m>0;){if(b.setDate(b.getDate()+h),d++,d>u)return null;Ut(b.getTime(),o)&&m--;}return b.getTime()}function Ot(r,a,o,u){let m=Ct(Math.min(r,a)),h=Ct(Math.max(r,a)),b=Math.round((h-m)/864e5);if(b>u)return null;let d=0,y=new Date(m);for(let x=0;x<=b;x++)Ut(y.getTime(),o)&&d++,y.setDate(y.getDate()+1);return d}var Qt={0:{name:"sqrt",min:1,max:1},1:{name:"abs",min:1,max:1},2:{name:"sin",min:1,max:1},3:{name:"cos",min:1,max:1},4:{name:"tan",min:1,max:1},5:{name:"log",min:1,max:1},6:{name:"ceil",min:1,max:1},7:{name:"floor",min:1,max:1},8:{name:"round",min:1,max:2},9:{name:"min",min:1,max:1/0},10:{name:"max",min:1,max:1/0},11:{name:"asin",min:1,max:1},12:{name:"acos",min:1,max:1},13:{name:"atan",min:1,max:1},14:{name:"atan2",min:2,max:2},15:{name:"sinh",min:1,max:1},16:{name:"cosh",min:1,max:1},17:{name:"tanh",min:1,max:1},18:{name:"asinh",min:1,max:1},19:{name:"acosh",min:1,max:1},20:{name:"atanh",min:1,max:1},21:{name:"cbrt",min:1,max:1},22:{name:"clz32",min:1,max:1},23:{name:"expm1",min:1,max:1},24:{name:"exp",min:1,max:1},25:{name:"fround",min:1,max:1},26:{name:"hypot",min:1,max:1/0},27:{name:"imul",min:2,max:2},28:{name:"log10",min:1,max:1},29:{name:"log1p",min:1,max:1},30:{name:"log2",min:1,max:1},31:{name:"pow",min:2,max:2},32:{name:"random",min:0,max:0},33:{name:"sign",min:1,max:1},34:{name:"trunc",min:1,max:1},35:{name:"degtorad",min:1,max:1},36:{name:"radtodeg",min:1,max:1},37:{name:"roll",min:2,max:2},38:{name:"gcd",min:2,max:2},39:{name:"lcm",min:2,max:2},40:{name:"permutation",min:2,max:2},41:{name:"combination",min:2,max:2},42:{name:"average",min:0,max:1/0},43:{name:"median",min:0,max:1/0},44:{name:"total",min:0,max:1/0},45:{name:"count",min:0,max:1/0},46:{name:"proportion",min:3,max:3},47:{name:"clamp",min:3,max:3},48:{name:"hex",min:1,max:1},49:{name:"bin",min:1,max:1},50:{name:"int",min:1,max:1},51:{name:"compoundInterest",min:3,max:3},52:{name:"interestEarned",min:3,max:3},53:{name:"compoundInterestRate",min:3,max:3},54:{name:"compoundInterestYears",min:3,max:3},55:{name:"loanRepayment",min:4,max:4},56:{name:"loanInterest",min:4,max:4},57:{name:"monthlyPayment",min:3,max:3},58:{name:"taxAdd",min:2,max:2},59:{name:"taxRemove",min:2,max:2},60:{name:"inflationAdjust",min:3,max:3},61:{name:"root",min:2,max:2},62:{name:"fact",min:1,max:1},63:{name:"transpose",min:1,max:1},64:{name:"det",min:1,max:1},65:{name:"inv",min:1,max:1},66:{name:"dot",min:2,max:2},67:{name:"expand",min:1,max:1},68:{name:"factor",min:1,max:1},69:{name:"solve",min:3,max:3},70:{name:"der",min:2,max:3},71:{name:"integral",min:2,max:2},72:{name:"taylor",min:4,max:4},73:{name:"jacobian",min:1,max:1/0},74:{name:"imaginary",min:1,max:1},75:{name:"conj",min:1,max:1},76:{name:"re",min:1,max:1},77:{name:"im",min:1,max:1},78:{name:"cancel",min:1,max:1},79:{name:"apart",min:1,max:1},80:{name:"compoundInterestEvery",min:4,max:4},81:{name:"compoundInterestEarnedEvery",min:4,max:4},82:{name:"presentValue",min:3,max:3},83:{name:"roi",min:2,max:2},84:{name:"annualisedReturn",min:3,max:3},85:{name:"taxIn",min:2,max:2},86:{name:"taxOn",min:2,max:2},87:{name:"sind",min:1,max:1},88:{name:"cosd",min:1,max:1},89:{name:"tand",min:1,max:1},90:{name:"asind",min:1,max:1},91:{name:"acosd",min:1,max:1},92:{name:"atand",min:1,max:1},93:{name:"daysCount",min:1,max:1},94:{name:"asTwoUnits",min:3,max:3},95:{name:"makeRate",min:2,max:2},96:{name:"atRate",min:2,max:2},97:{name:"roundToPlaces",min:2,max:2},98:{name:"splitEach",min:2,max:2},99:{name:"savingsGoalPayment",min:3,max:3},100:{name:"savingsGoalPeriods",min:5,max:5},101:{name:"standardDeviation",min:0,max:1/0},102:{name:"sampleStandardDeviation",min:0,max:1/0},103:{name:"variance",min:0,max:1/0},104:{name:"sampleVariance",min:0,max:1/0},105:{name:"spread",min:0,max:1/0},106:{name:"mode",min:0,max:1/0},107:{name:"weightedAverage",min:2,max:1/0}};function ke(r){return r===1?"1 argument":`${r} arguments`}function Jt(r){return r.max===1/0?`at least ${ke(r.min)}`:r.min===r.max?ke(r.min):`${r.min} to ${ke(r.max)}`}function Rt(r,a){let o=Qt[r];if(o!==void 0&&!(a>=o.min&&a<=o.max))return chunkSOMGSIO4_cjs.c.execution("BUILTIN_ARITY_MISMATCH",`${o.name}() takes ${Jt(o)}, but was given ${a===0?"none":ke(a)}`,{functionName:o.name,expectedMin:o.min,expectedMax:o.max,actual:a})}function Hn(r,a=200,o=5e4,u=50,m=1e5,h=2e6,b=1e4,d=100,y=-100,x=chunkYFWAR766_cjs.y,S){let A=[],I=new Map,L=0,j,$,n=[],Q=new Map,W=new Map,K=new Map;return {push(f){A.length<a&&A.push(f);},getMaxStackDepth(){return a},getMaxCollectionSize(){return m},getMaxAllocatedElements(){return h},getMaxFunctionCalls(){return b},getMaxDateOffsetYears(){return d},getMinDateOffsetYears(){return y},isHoliday(f){return S?S(f):false},pop(){return A.length===0?chunkPS272DZJ_cjs.n(0):A.pop()},popNumber(){return c(A).toNumber()},popString(){return q(c(A),"VM.popString()")},peek(){return A[A.length-1]},getStack(){return A},registry:r,getVar(f){if(n.length>0){let e=n[n.length-1].get(f);if(e!==void 0)return e}return I.get(f)},setVar(f,e){I.set(f,e);},deleteVar(f){I.delete(f);},pushCallFrame(f){if(n.length>=u)throw chunkSOMGSIO4_cjs.c.execution("FUNCTION_RECURSION_LIMIT_EXCEEDED",`Function call nesting exceeded maximum depth of ${u} (possible infinite recursion, e.g. f(x) = f(x))`,{maxFunctionRecursionDepth:u});n.push(f);},popCallFrame(){n.pop();},getCallFrame(){return n.length>0?n[n.length-1]:void 0},defineUserFunction(f,e,t){Q.set(f,{name:f,params:e,program:t});},getUserFunction(f){return Q.get(f)},hasUserFunction(f){return Q.has(f)},getVariableEntries(){return Array.from(I.entries())},getUserFunctionDefs(){return Array.from(Q.values())},defineEquation(f,e,t){W.set(f,{variable:f,factorNames:e,rhsProgram:t});},getEquation(f){return W.get(f)},hasEquation(f){return W.has(f)},defineScalarEquation(f,e,t){K.set(f,{variable:f,lhsProgram:e,rhsProgram:t});},getScalarEquation(f){return K.get(f)},hasScalarEquation(f){return K.has(f)},reset(){A.length=0,I.clear(),n.length=0,Q.clear(),W.clear(),K.clear(),L=0,$&&($(),$=void 0),j=void 0;},get activeSignal(){return j},set activeSignal(f){j=f;},get abortCurrent(){return $},set abortCurrent(f){$=f;},context:x,getMaxInstructions(){return o},getInstructionCount(){return L},incrementInstructions(f){if(L+=f,L>o)throw chunkSOMGSIO4_cjs.c.execution("INSTRUCTION_LIMIT_EXCEEDED",`Execution exceeded maximum of ${o} instructions`)}}}function Zt(r,a){return r.rows===1&&r.cols===1?a.data.length:a.rows===1&&a.cols===1?r.data.length:r.cols!==a.rows?0:r.rows*a.cols}function en(r,a){return !Number.isInteger(a)||a<0?0:r.rows*r.cols*(1+(a<2?1:2*Math.floor(Math.log2(a))))}function c(r){if(r.length===0)throw chunkSOMGSIO4_cjs.c.internal({code:"STACK_UNDERFLOW",message:"Stack underflow: an opcode expected a value on the stack but it was empty",expected:"at least one value on the VM stack",found:"an empty stack",suggestion:"this indicates corrupted bytecode or a bug in a package's parselet (mismatched push/pop counts), not a user-input error"});return r.pop()}var Ht="bytecode is caller input on this entry point: rebuild the program with the engine's compiler, or fix the hand-assembled stream";function tn(r){return typeof r=="number"?chunkJFAJN3C2_cjs.b(r):r}function se(r,a,o,u,m,h={}){let b=tn(a);return chunkSOMGSIO4_cjs.c.validation({code:r,message:`Malformed bytecode: ${b} ${o}`,expected:u,found:m,suggestion:Ht,context:typeof a=="number"?{opcode:a,opcodeName:b,...h}:{site:b,...h}})}function O(r,a,o,u){if(a>=r.length)throw se("MALFORMED_BYTECODE_TRUNCATED",o,`is missing its ${u}: the program ends mid-instruction`,`an operand byte at offset ${a}`,`a program only ${r.length} byte(s) long`,{offset:a,length:r.length,role:u});return r[a]}function qe(r,a,o,u,m,h){let b=O(r,a,o,u);if(b>=m)throw se("MALFORMED_BYTECODE_CONSTANT_INDEX",o,`reads ${h} entry ${b}, which does not exist`,`an index below ${m}`,`${b}`,{index:b,poolSize:m,pool:h});return b}function z(r,a,o,u,m){return Qe(o,O(r,a,u,m),u)}function Qe(r,a,o){let u=r[a];if(typeof u!="string")throw se("MALFORMED_BYTECODE_CONSTANT_INDEX",o,`reads string-pool entry ${a}, which is ${a>=r.length?"past the end of the pool":"not a string"}`,`an index below ${r.length}, holding a string`,a>=r.length?`${a}`:typeof u,{index:a,poolSize:r.length,pool:"string-pool"});return u}function q(r,a,o){if(typeof r.value!="string")throw se("MALFORMED_BYTECODE_OPERAND_TYPE",a,`expected a ${o??"string"} on the stack`,o?`a string value holding the ${o}`:"a string value",`a ${chunkPS272DZJ_cjs.g[r.type]??"unknown"} value`,o?{role:o,valueType:r.type}:{valueType:r.type});return r.value}function Vt(r,a,o){if(r!==0&&r!==1&&r!==2)throw se("MALFORMED_BYTECODE_BODY_KIND",o,`has body kind ${r}, which is not one this VM knows`,"0 (inline body), 1 (builtin function) or 2 (user-defined function)",`${r}`,{kind:r,ref:a})}function nn(r,a){try{return BigInt(r)}catch{throw se("MALFORMED_BYTECODE_BIGINT_LITERAL",a,`cannot read "${r}" as a whole number`,"a string holding an integer, with no decimal point or separators",`"${r}"`,{literal:r})}}function an(r){if(r===null||typeof r!="object")return `expected a bytecode program, got ${r===null?"null":typeof r}`;let a=r;return typeof a.opcodes?.length!="number"?"the program has no `opcodes` array":typeof a.numbers?.length!="number"?"the program has no `numbers` pool":typeof a.strings?.length!="number"?"the program has no `strings` pool":null}function Bt(r,a,o,u,m,h,b,d){let y=new Map;for(let S=0;S<r.length;S++)y.set(r[S],o[S]);u.pushCallFrame(y);let x;try{x=Je(a,u,m,h,b,d);}finally{u.popCallFrame();}if(x.type==="pending")throw chunkSOMGSIO4_cjs.c.execution("MAP_REDUCE_ASYNC_UNSUPPORTED","map/reduce transform bodies calling an async operation (weather, stocks, currency, ...) aren't supported");if(x.type==="error")throw x.error;return x.value}function rn(r,a,o,u,m,h,b){let d=new Map(o.getCallFrame());d.set(r,chunkPS272DZJ_cjs.I(chunkN7N7MPMK_cjs.q(r))),o.pushCallFrame(d);let y;try{y=Je(a,o,u,m,h,b);}finally{o.popCallFrame();}if(y.type==="pending")throw chunkSOMGSIO4_cjs.c.execution("SYMBOLIC_ASYNC_UNSUPPORTED","an algebra verb's expression cannot call an async operation (weather, stocks, currency, ...)");if(y.type==="error")throw y.error;return y.value}function Ft(r,a){if(r.type!==6||a.type!==6)return null;let o=r.unit,u=a.unit;if(o===void 0||u===void 0)return null;let m=o.indexOf("/"),h=u.indexOf("/");if(m<0||h<0||o.slice(0,m)!==u.slice(0,h))return null;let b=chunkCIQOK7Q4_cjs.a[o.slice(m+1).toLowerCase()],d=chunkCIQOK7Q4_cjs.a[u.slice(h+1).toLowerCase()];return b===void 0||d===void 0||b[0]!==d[0]?null:r.toNumber()*(d[1]/b[1])}function Lt(r,a){if(r.type!==6||a.type!==6)return null;let o=r.unit,u=a.unit;if(o===void 0||u===void 0||o.includes("/")||u.includes("/"))return null;let m=chunkN7N7MPMK_cjs.ua[o.toUpperCase()]!==void 0,h=chunkN7N7MPMK_cjs.ua[u.toUpperCase()]!==void 0;return m===h?null:chunkPS272DZJ_cjs.u(r.toNumber()*a.toNumber(),m?o:u)}function $t(r,a,o){if(r.type===5)return a.type===6&&a.unit!==void 0?chunkYFWAR766_cjs.c(a,a.unit,r.toNumber(),o):a.type!==5&&a.type!==0?null:chunkPS272DZJ_cjs.L(r.toNumber()+o*a.toNumber());if(a.type!==5)return null;let u=1+o*a.toNumber();if(r.type===0){let m=r.toNumber()*u;return r.uncertainty!==void 0?chunkPS272DZJ_cjs.q(m,Math.abs(r.uncertainty*u)):chunkPS272DZJ_cjs.n(m)}return r.type===6&&r.unit!==void 0?chunkYFWAR766_cjs.c(r,r.unit,a.toNumber(),o):null}function on(r,a){let o=r.type===5?r:a.type===5?a:null;if(o===null)return null;let u=o===r?a:r;if(u.type!==0||u.uncertainty===void 0)return null;let m=o.toNumber();return chunkPS272DZJ_cjs.q(u.toNumber()*m,Math.abs(u.uncertainty*m))}function sn(r,a){let o=r.type===6?r:a,u=r.type===6?a:r;return o.type!==6||o.unit===void 0||!chunk4BZIYU7S_cjs.c.isCurrency(o.unit)||u.type!==0&&u.type!==5||u.rational!==void 0?null:chunkYFWAR766_cjs.b(o,u.toNumber(),o.unit)}function un(r,a){if(a.type===5&&r.type===0&&r.uncertainty!==void 0){let o=a.toNumber();return o===0?null:chunkPS272DZJ_cjs.q(r.toNumber()/o,Math.abs(r.uncertainty/o))}if(r.type===5&&a.type===0&&a.uncertainty!==void 0){let o=a.toNumber();return o===0?null:chunkPS272DZJ_cjs.q(r.toNumber()/o,Math.abs(r.toNumber()*a.uncertainty/(o*o)))}return null}function ln(r){if(r.type===6){let a=r.unit;if(a&&chunkIANAMBJQ_cjs.c(a)==="time")try{return chunkIANAMBJQ_cjs.e(r.toNumber(),a,"ms")}catch{}return 0}return r.toNumber()}var Pt=260;function qt(r,a,o){let u=Math.trunc(Math.abs(a)),h=(a>=0?1:-1)>0?o.getMaxDateOffsetYears():-o.getMinDateOffsetYears(),b=Math.floor(h*Pt);if(u>b)throw chunkSOMGSIO4_cjs.c.execution("DATE_OFFSET_LIMIT_EXCEEDED",`A date offset of ${u.toLocaleString("en-US")} workdays is about ${Math.round(u/Pt).toLocaleString("en-US")} years, past the limit of ${h} years for a workday offset`,{requestedWorkdays:u,limitYears:h,limitWorkdays:b});let d=b*7+7,y=vt(r,a,x=>o.isHoliday(x),d);if(y===null)throw chunkSOMGSIO4_cjs.c.execution("DATE_OFFSET_LIMIT_EXCEEDED",`A working-day offset of ${u.toLocaleString("en-US")} could not be reached within the ${h}-year limit; the configured holiday calendar leaves too few working days`,{requestedWorkdays:u,limitYears:h,maxCalendarSteps:d});return y}var Yt=864e5,cn={month:1,months:1,mo:1,year:12,years:12,yr:12,y:12,a:12,decade:120,decades:120,dec:120,century:1200,centuries:1200,millennium:12e3,millennia:12e3};function mn(r,a){return new Date(r,a+1,0).getDate()}function jt(r,a){let o=Math.trunc(a),u=new Date(r);u.setDate(u.getDate()+o);let m=u.getTime();return Number.isNaN(m)?r+a*Yt:m+(a-o)*Yt}function pn(r,a){let o=Math.trunc(a),u=new Date(r),m=u.getDate();u.setDate(1),u.setMonth(u.getMonth()+o),u.setDate(Math.min(m,mn(u.getFullYear(),u.getMonth())));let h=u.getTime(),b=chunkIANAMBJQ_cjs.e(1,"month","ms");return Number.isNaN(h)?r+a*b:h+(a-o)*b}function he(r,a,o,u){if(a.type===6&&a.unit!==void 0){let m=a.unit,h=o*a.toNumber();if(chunkIANAMBJQ_cjs.a(m))return qt(r,h,u);let b=cn[m];if(b!==void 0)return pn(r,h*b);if(chunkIANAMBJQ_cjs.c(m)==="time"){let d=0;try{d=chunkIANAMBJQ_cjs.e(1,m,"day");}catch{}if(Number.isInteger(d)&&d>=1)return jt(r,h*d)}}return r+o*ln(a)}function Xt(r,a,o){let u=chunkPS272DZJ_cjs.B(r.unit);if(a.type===6&&chunkPS272DZJ_cjs.A(a.unit)){let m=chunkPS272DZJ_cjs.B(a.unit);return m!==u?chunkPS272DZJ_cjs.N("TIMECODE_FPS_MISMATCH",`Cannot combine timecodes at different frame rates (${u} fps vs ${m} fps)`):o===1?chunkPS272DZJ_cjs.u(r.toNumber()+a.toNumber(),r.unit):chunkPS272DZJ_cjs.u(r.toNumber()-a.toNumber(),"frames")}if(a.type===6&&a.unit==="frames")return chunkPS272DZJ_cjs.u(r.toNumber()+o*a.toNumber(),r.unit);if(a.type===6&&a.unit&&chunkIANAMBJQ_cjs.c(a.unit)==="time"){let m=chunkIANAMBJQ_cjs.e(a.toNumber(),a.unit,"s");return chunkPS272DZJ_cjs.u(r.toNumber()+o*m*u,r.unit)}return chunkPS272DZJ_cjs.u(r.toNumber()+o*a.toNumber(),r.unit)}function ge(r){return r.type===10?r.value:r.toNumber()!==0}function Gt(r,a){let o=chunkYFWAR766_cjs.l(r,a);return chunkPS272DZJ_cjs.N("INCOMPATIBLE_UNITS",o??`Cannot convert ${r} to ${a}: they do not measure the same thing`)}var Se=65536;function fn(r,a){if(!Number.isInteger(a)||a<0)return null;if(a===0)return 1;let o=Math.abs(r.toNumber());return o<=1?1:(o<=2?1:Math.log2(o))*a}function dn(r,a){let o=1n,u=r,m=a;for(;m>0n;)m%2n===1n&&(o*=u),m/=2n,m>0n&&(u*=u);return o}var je=Se;function Wt(r){let a=r<0n?-r:r;if(a===0n)return 0;let o=Number(a);return Number.isFinite(o)?Math.floor(Math.log2(o))+1:a.toString(16).length*4}function Kt(r,a,o){let u=chunkYFWAR766_cjs.n(r),m=chunkYFWAR766_cjs.n(a);if(u===0n)return chunkPS272DZJ_cjs.s(0n);let h=o*Number(m);if(h<=0||Wt(u)+h<=je)return chunkPS272DZJ_cjs.s(o===1?u<<m:u>>m);throw chunkSOMGSIO4_cjs.c.execution("BIGINT_SHIFT_LIMIT_EXCEEDED",`Shifting by ${m} would build an exact integer of about ${(Wt(u)+h).toLocaleString("en-US")} bits, past the limit of ${je.toLocaleString("en-US")} bits`,{shift:String(m),limitBits:je})}function ze(r,a){let{numerator:o,denominator:u}=chunkPS272DZJ_cjs.y(r.unit),m=chunkIANAMBJQ_cjs.c(u),h=chunkIANAMBJQ_cjs.c(a.unit);if(!m||m!==h)return chunkPS272DZJ_cjs.N("RATE_MUL_MEASURE_MISMATCH",`Cannot multiply a "${u}"-denominated rate by "${a.unit}" \u2014 different measures`);let b=chunkIANAMBJQ_cjs.e(a.toNumber(),a.unit,u),d=r.toNumber()*b;return o?chunkPS272DZJ_cjs.u(d,o):chunkPS272DZJ_cjs.n(d)}function bn(r){if(Number.isNaN(r))return "NaN";if(!isFinite(r))return r>0?"Infinity":"-Infinity";let a=r<0,o=Math.abs(r),u=Math.floor(o),m=o-u;if(m<1e-9)return `${a?"-":""}${u}`;let h=0,b=1,d=1,y=0,x=m,S=1e6;for(let I=0;I<30;I++){let L=Math.floor(x+1e-9),j=L*b+h,$=L*y+d;if($>S||(h=b,b=j,d=y,y=$,Math.abs(m-b/y)<1e-9))break;let n=x-L;if(n<1e-9)break;x=1/n;}let A=u*y+b;return `${a?"-":""}${A}/${y}`}function hn(r){return r.d===1n?String(r.n):`${r.n}/${r.d}`}function gn(r){let a=r.toNumber(),o=r.type===5?1+a:a;return `${Math.round(o*1e6)/1e6}x`}function yn(r){if(!Number.isFinite(r))return String(r);if(r===0)return "0e+0";let[a,o]=r.toExponential().split("e");return `${a.includes(".")?a.replace(/0+$/,"").replace(/\.$/,""):a}e${o}`}function Je(r,a,o,u,m,h){let b=an(r);if(b)return {type:"error",error:chunkSOMGSIO4_cjs.c.validation({code:"MALFORMED_BYTECODE_PROGRAM",message:`Malformed bytecode: ${b}`,expected:"a BytecodeProgram with opcodes, numbers and strings",found:b,suggestion:Ht})};let{opcodes:d,numbers:y,strings:x,userFunctionBodies:S,anonymousBodies:A}=r,I=0,L=0,j=a.getMaxInstructions(),$=a.getMaxStackDepth(),n=a.getStack(),Q=o?.hasCollectors??false,W=chunkPS272DZJ_cjs.j();if(d.length===0)return {type:"value",value:chunkPS272DZJ_cjs.n(0)};chunkPS272DZJ_cjs.a(a);try{for(;I<d.length;){if(++L>j)throw chunkSOMGSIO4_cjs.c.execution("INSTRUCTION_LIMIT_EXCEEDED",`Execution exceeded maximum of ${j} instructions`);if(n.length>$)throw chunkSOMGSIO4_cjs.c.execution("STACK_LIMIT_EXCEEDED",`Execution exceeded maximum stack depth of ${$}`);let f=d[I++];if(Q){let e=n.map(t=>({type:t.type,value:t.value,unit:t.unit}));o.fireVmStep({type:chunkAXMQG5TS_cjs.c.VmStep,elapsedNs:0,expression:u??"",opcode:f,opcodeName:chunkJFAJN3C2_cjs.b(f),ip:I-1,stackDepth:n.length,instructionNumber:L,stack:e});}switch(f){case 0:break;case 1:{let e=c(n);return {type:"value",value:W?chunkPS272DZJ_cjs.k(e):e}}case 3:{let e=c(n);n.push(e),n.push(e);break}case 2:{let e=c(n),t=c(n);n.push(e),n.push(t);break}case 10:n.push(chunkPS272DZJ_cjs.n(y[qe(d,I++,f,"constant-pool index",y.length,"number-pool")]));break;case 11:n.push(chunkPS272DZJ_cjs.s(nn(z(d,I++,x,f,"constant-pool index"),f)));break;case 16:{let e=chunkN7N7MPMK_cjs.ia(z(d,I++,x,f,"constant-pool index"));n.push(chunkPS272DZJ_cjs.o(chunkN7N7MPMK_cjs.ra(e),e));break}case 12:n.push(chunkPS272DZJ_cjs.r(y[qe(d,I++,f,"constant-pool index",y.length,"number-pool")]));break;case 13:n.push(chunkPS272DZJ_cjs.t(z(d,I++,x,f,"constant-pool index")));break;case 14:n.push(chunkPS272DZJ_cjs.J(O(d,I++,f,"boolean operand")===1));break;case 20:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(t.uncertainty!==void 0||e.uncertainty!==void 0){let p=chunkYFWAR766_cjs.s(t,e,"add");if(p){n.push(p);break}}if(t.rational!==void 0||e.rational!==void 0){let p=chunkYFWAR766_cjs.r(t,e,"add");if(p){n.push(p);break}}let i=$t(t,e,1),l=i===null?Ft(t,e):null;i!==null?n.push(i):l!==null?n.push(chunkPS272DZJ_cjs.u(l+e.toNumber(),e.unit)):t.type===0&&e.type===0?n.push(chunkPS272DZJ_cjs.n(t.value+e.value)):t.type===10&&e.type===10?n.push(chunkPS272DZJ_cjs.J(t.value&&e.value)):t.type===4?e.type===4?n.push(chunkPS272DZJ_cjs.N("INVALID_DATETIME_OP","Cannot add two datetimes together")):n.push(chunkPS272DZJ_cjs.K(he(t.toNumber(),e,1,a))):t.type===6&&chunkPS272DZJ_cjs.A(t.unit)?n.push(Xt(t,e,1)):e.type===4?n.push(chunkPS272DZJ_cjs.K(he(e.toNumber(),t,1,a))):n.push(chunkYFWAR766_cjs.u(t,e,(p,g)=>p+g,(p,g)=>p+g,"add"));break}case 21:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(t.uncertainty!==void 0||e.uncertainty!==void 0){let p=chunkYFWAR766_cjs.s(t,e,"sub");if(p){n.push(p);break}}if(t.rational!==void 0||e.rational!==void 0){let p=chunkYFWAR766_cjs.r(t,e,"sub");if(p){n.push(p);break}}let i=$t(t,e,-1),l=i===null?Ft(t,e):null;i!==null?n.push(i):l!==null?n.push(chunkPS272DZJ_cjs.u(l-e.toNumber(),e.unit)):t.type===0&&e.type===0?n.push(chunkPS272DZJ_cjs.n(t.value-e.value)):t.type===4?e.type===4?n.push(chunkPS272DZJ_cjs.u(t.toNumber()-e.toNumber(),"ms")):n.push(chunkPS272DZJ_cjs.K(he(t.toNumber(),e,-1,a))):t.type===6&&chunkPS272DZJ_cjs.A(t.unit)?n.push(Xt(t,e,-1)):e.type===4?n.push(chunkPS272DZJ_cjs.N("INVALID_DATETIME_OP","Cannot subtract a datetime from a value that is not a datetime")):n.push(chunkYFWAR766_cjs.u(t,e,(p,g)=>p-g,(p,g)=>p-g,"sub"));break}case 22:{let e=c(n),t=c(n),s=on(t,e);if(s){n.push(s);break}if(t.uncertainty!==void 0||e.uncertainty!==void 0){let l=chunkYFWAR766_cjs.s(t,e,"mul");if(l){n.push(l);break}}if(t.rational!==void 0||e.rational!==void 0){let l=chunkYFWAR766_cjs.r(t,e,"mul");if(l){n.push(l);break}}let i=sn(t,e);if(i){n.push(i);break}t.type===0&&e.type===0?n.push(chunkPS272DZJ_cjs.n(t.value*e.value)):t.type===7&&e.type===7?(chunkPS272DZJ_cjs.d(Zt(t.value,e.value),"matrix cells"),n.push(chunkN7N7MPMK_cjs._(t.value,e.value))):t.type===6&&chunkPS272DZJ_cjs.x(t.unit)&&e.type===6&&e.unit?n.push(ze(t,e)):e.type===6&&chunkPS272DZJ_cjs.x(e.unit)&&t.type===6&&t.unit?n.push(ze(e,t)):Lt(t,e)!==null?n.push(Lt(t,e)):n.push(chunkYFWAR766_cjs.u(t,e,(l,p)=>l*p,(l,p)=>l*p,"mul"));break}case 23:{let e=c(n),t=c(n),s=un(t,e);if(s){n.push(s);break}if(t.uncertainty!==void 0||e.uncertainty!==void 0){let i=chunkYFWAR766_cjs.s(t,e,"div");if(i){n.push(i);break}}if(t.type===6&&e.type===6){let{lv:i,rv:l,sameMeasure:p}=chunkYFWAR766_cjs.j(t,e);p?n.push(chunkPS272DZJ_cjs.n(i/l)):chunk4BZIYU7S_cjs.c.isCurrency(t.unit)&&chunk4BZIYU7S_cjs.c.isCurrency(e.unit)?n.push(chunkPS272DZJ_cjs.N("INCOMPATIBLE_UNITS",`Cannot combine incompatible units: ${t.unit} and ${e.unit}`)):n.push(chunkPS272DZJ_cjs.w(i/l,t.unit,e.unit));}else {let i=chunkYFWAR766_cjs.r(t,e,"div");if(i){n.push(i);break}n.push(chunkYFWAR766_cjs.u(t,e,(l,p)=>l/p,(l,p)=>{if(p===0n)throw chunkYFWAR766_cjs.o();return l/p},"div"));}break}case 24:{let e=c(n),t=c(n);n.push(chunkYFWAR766_cjs.u(t,e,(s,i)=>s%i,(s,i)=>{if(i===0n)throw chunkYFWAR766_cjs.o();return s%i}));break}case 25:{let e=c(n),t=c(n);if(t.type===13){n.push(t);break}if(e.type===13){n.push(e);break}if(t.type===12){n.push(t);break}if(e.type===12){n.push(e);break}if(t.type===0&&e.type===0){n.push(chunkPS272DZJ_cjs.n(chunkYFWAR766_cjs.q(t.value,e.value)));break}if(t.type===7||e.type===7){if(t.type!==7||e.type!==0){n.push(chunkPS272DZJ_cjs.N("MATRIX_POWER_UNSUPPORTED",`^: a matrix may only be the base, raised to a whole number (as in "[1,2;3,4]^2"); "${chunkPS272DZJ_cjs.g[t.type]} ^ ${chunkPS272DZJ_cjs.g[e.type]}" has no matrix reading.`));break}chunkPS272DZJ_cjs.d(en(t.value,e.value),"matrix cells"),n.push(chunkN7N7MPMK_cjs.$(t.value,e.value));break}if(t.type===9||e.type===9){n.push(chunkYFWAR766_cjs.f(t,e));break}if(t.type===2||e.type===2){let s=fn(t,e.toNumber());if(s!==null){if(s>Se)throw chunkSOMGSIO4_cjs.c.execution("BIGINT_POW_LIMIT_EXCEEDED",`That power would build an exact integer of about ${Math.round(s).toLocaleString("en-US")} bits, past the limit of ${Se.toLocaleString("en-US")} bits`,{limitBits:Se});n.push(chunkPS272DZJ_cjs.s(dn(chunkYFWAR766_cjs.n(t),chunkYFWAR766_cjs.n(e))));break}}n.push(chunkPS272DZJ_cjs.n(chunkYFWAR766_cjs.q(t.toNumber(),e.toNumber())));break}case 26:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}e.type===2?n.push(chunkPS272DZJ_cjs.s(-e.value)):e.type===6&&e.exact!==void 0?n.push(chunkPS272DZJ_cjs.v(-e.toNumber(),e.unit,chunkN7N7MPMK_cjs.ma(e.exact))):e.type===6?n.push(chunkPS272DZJ_cjs.u(-e.toNumber(),e.unit)):e.type===5?n.push(chunkPS272DZJ_cjs.L(-e.toNumber())):e.type===9?n.push(chunkYFWAR766_cjs.g(e)):e.type===0&&e.rational!==void 0?n.push(chunkPS272DZJ_cjs.p(-e.toNumber(),chunkN7N7MPMK_cjs.j(e.rational))):e.type===0&&e.exact!==void 0?n.push(chunkPS272DZJ_cjs.o(-e.toNumber(),chunkN7N7MPMK_cjs.ma(e.exact))):n.push(chunkPS272DZJ_cjs.n(-e.toNumber()));break}case 27:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}e.type===6&&e.exact!==void 0?n.push(chunkPS272DZJ_cjs.v(e.toNumber(),e.unit,e.exact)):e.type===6?n.push(chunkPS272DZJ_cjs.u(e.toNumber(),e.unit)):e.type===5?n.push(chunkPS272DZJ_cjs.L(e.toNumber())):e.type===0&&e.rational!==void 0?n.push(chunkPS272DZJ_cjs.p(e.toNumber(),e.rational)):e.type===0&&e.exact!==void 0?n.push(chunkPS272DZJ_cjs.o(e.toNumber(),e.exact)):n.push(chunkPS272DZJ_cjs.n(e.toNumber()));break}case 28:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}n.push(chunkPS272DZJ_cjs.q(t.toNumber(),Math.abs(e.toNumber())));break}case 30:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}t.type===2||e.type===2?n.push(Kt(t,e,1)):n.push(chunkPS272DZJ_cjs.n(t.toNumber()<<e.toNumber()));break}case 31:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}t.type===2||e.type===2?n.push(Kt(t,e,-1)):n.push(chunkPS272DZJ_cjs.n(t.toNumber()>>e.toNumber()));break}case 32:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}n.push(chunkPS272DZJ_cjs.n(t.toNumber()>>>e.toNumber()));break}case 33:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}t.type===2||e.type===2?n.push(chunkPS272DZJ_cjs.s(chunkYFWAR766_cjs.n(t)&chunkYFWAR766_cjs.n(e))):n.push(chunkPS272DZJ_cjs.n(t.toNumber()&e.toNumber()));break}case 34:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}t.type===2||e.type===2?n.push(chunkPS272DZJ_cjs.s(chunkYFWAR766_cjs.n(t)|chunkYFWAR766_cjs.n(e))):n.push(chunkPS272DZJ_cjs.n(t.toNumber()|e.toNumber()));break}case 35:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}t.type===2||e.type===2?n.push(chunkPS272DZJ_cjs.s(chunkYFWAR766_cjs.n(t)^chunkYFWAR766_cjs.n(e))):n.push(chunkPS272DZJ_cjs.n(t.toNumber()^e.toNumber()));break}case 36:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}e.type===2?n.push(chunkPS272DZJ_cjs.s(~e.value)):n.push(chunkPS272DZJ_cjs.n(~e.toNumber()));break}case 40:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(t.rational!==void 0||e.rational!==void 0){let i=chunkYFWAR766_cjs.t(t,e);if(i!==null){n.push(chunkPS272DZJ_cjs.J(i===0));break}}if(t.type===0&&e.type===0)n.push(chunkPS272DZJ_cjs.J(t.value===e.value));else if(t.type===2||e.type===2){let i=chunkYFWAR766_cjs.p(t,e);n.push(chunkPS272DZJ_cjs.J(i===null?t.toNumber()===e.toNumber():i===0));}else if(t.type===3&&e.type===3)n.push(chunkPS272DZJ_cjs.J(t.value===e.value));else if(t.type===6&&e.type===6){let{equal:i,sameMeasure:l}=chunkYFWAR766_cjs.k(t,e);n.push(chunkPS272DZJ_cjs.J(l&&i));}else if(t.type===7&&e.type===7)n.push(chunkN7N7MPMK_cjs.aa(t.value,e.value,(i,l)=>i===l));else if(t.type===14||e.type===14)if(t.type===14&&e.type===14){let i=t.value,l=e.value;n.push(chunkPS272DZJ_cjs.J(i.r===l.r&&i.g===l.g&&i.b===l.b&&i.a===l.a));}else n.push(chunkPS272DZJ_cjs.J(!1));else n.push(chunkPS272DZJ_cjs.J(t.toNumber()===e.toNumber()));break}case 41:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(t.rational!==void 0||e.rational!==void 0){let i=chunkYFWAR766_cjs.t(t,e);if(i!==null){n.push(chunkPS272DZJ_cjs.J(i!==0));break}}if(t.type===0&&e.type===0)n.push(chunkPS272DZJ_cjs.J(t.value!==e.value));else if(t.type===2||e.type===2){let i=chunkYFWAR766_cjs.p(t,e);n.push(chunkPS272DZJ_cjs.J(i===null?t.toNumber()!==e.toNumber():i!==0));}else if(t.type===3&&e.type===3)n.push(chunkPS272DZJ_cjs.J(t.value!==e.value));else if(t.type===6&&e.type===6){let{equal:i,sameMeasure:l}=chunkYFWAR766_cjs.k(t,e);n.push(chunkPS272DZJ_cjs.J(!l||!i));}else if(t.type===7&&e.type===7)n.push(chunkN7N7MPMK_cjs.aa(t.value,e.value,(i,l)=>i!==l));else if(t.type===14||e.type===14)if(t.type===14&&e.type===14){let i=t.value,l=e.value;n.push(chunkPS272DZJ_cjs.J(!(i.r===l.r&&i.g===l.g&&i.b===l.b&&i.a===l.a)));}else n.push(chunkPS272DZJ_cjs.J(!0));else n.push(chunkPS272DZJ_cjs.J(t.toNumber()!==e.toNumber()));break}case 42:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(t.rational!==void 0||e.rational!==void 0){let i=chunkYFWAR766_cjs.t(t,e);if(i!==null){n.push(chunkPS272DZJ_cjs.J(i<0));break}}if(t.type===0&&e.type===0)n.push(chunkPS272DZJ_cjs.J(t.value<e.value));else if(t.type===2||e.type===2){let i=chunkYFWAR766_cjs.p(t,e);n.push(chunkPS272DZJ_cjs.J(i===null?t.toNumber()<e.toNumber():i<0));}else if(t.type===6&&e.type===6){let{lv:i,rv:l,equal:p,sameMeasure:g}=chunkYFWAR766_cjs.k(t,e);n.push(g?chunkPS272DZJ_cjs.J(!p&&i<l):chunkYFWAR766_cjs.m(t,e));}else t.type===7&&e.type===7?n.push(chunkN7N7MPMK_cjs.aa(t.value,e.value,(i,l)=>i<l)):n.push(chunkPS272DZJ_cjs.J(t.toNumber()<e.toNumber()));break}case 43:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(t.rational!==void 0||e.rational!==void 0){let i=chunkYFWAR766_cjs.t(t,e);if(i!==null){n.push(chunkPS272DZJ_cjs.J(i<=0));break}}if(t.type===0&&e.type===0)n.push(chunkPS272DZJ_cjs.J(t.value<=e.value));else if(t.type===2||e.type===2){let i=chunkYFWAR766_cjs.p(t,e);n.push(chunkPS272DZJ_cjs.J(i===null?t.toNumber()<=e.toNumber():i<=0));}else if(t.type===6&&e.type===6){let{lv:i,rv:l,equal:p,sameMeasure:g}=chunkYFWAR766_cjs.k(t,e);n.push(g?chunkPS272DZJ_cjs.J(p||i<=l):chunkYFWAR766_cjs.m(t,e));}else t.type===7&&e.type===7?n.push(chunkN7N7MPMK_cjs.aa(t.value,e.value,(i,l)=>i<=l)):n.push(chunkPS272DZJ_cjs.J(t.toNumber()<=e.toNumber()));break}case 44:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(t.rational!==void 0||e.rational!==void 0){let i=chunkYFWAR766_cjs.t(t,e);if(i!==null){n.push(chunkPS272DZJ_cjs.J(i>0));break}}if(t.type===0&&e.type===0)n.push(chunkPS272DZJ_cjs.J(t.value>e.value));else if(t.type===2||e.type===2){let i=chunkYFWAR766_cjs.p(t,e);n.push(chunkPS272DZJ_cjs.J(i===null?t.toNumber()>e.toNumber():i>0));}else if(t.type===6&&e.type===6){let{lv:i,rv:l,equal:p,sameMeasure:g}=chunkYFWAR766_cjs.k(t,e);n.push(g?chunkPS272DZJ_cjs.J(!p&&i>l):chunkYFWAR766_cjs.m(t,e));}else t.type===7&&e.type===7?n.push(chunkN7N7MPMK_cjs.aa(t.value,e.value,(i,l)=>i>l)):n.push(chunkPS272DZJ_cjs.J(t.toNumber()>e.toNumber()));break}case 45:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(t.rational!==void 0||e.rational!==void 0){let i=chunkYFWAR766_cjs.t(t,e);if(i!==null){n.push(chunkPS272DZJ_cjs.J(i>=0));break}}if(t.type===0&&e.type===0)n.push(chunkPS272DZJ_cjs.J(t.value>=e.value));else if(t.type===2||e.type===2){let i=chunkYFWAR766_cjs.p(t,e);n.push(chunkPS272DZJ_cjs.J(i===null?t.toNumber()>=e.toNumber():i>=0));}else if(t.type===6&&e.type===6){let{lv:i,rv:l,equal:p,sameMeasure:g}=chunkYFWAR766_cjs.k(t,e);n.push(g?chunkPS272DZJ_cjs.J(p||i>=l):chunkYFWAR766_cjs.m(t,e));}else t.type===7&&e.type===7?n.push(chunkN7N7MPMK_cjs.aa(t.value,e.value,(i,l)=>i>=l)):n.push(chunkPS272DZJ_cjs.J(t.toNumber()>=e.toNumber()));break}case 130:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}n.push(chunkPS272DZJ_cjs.J(ge(t)&&ge(e)));break}case 131:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}n.push(chunkPS272DZJ_cjs.J(ge(t)||ge(e)));break}case 132:{let e=c(n),t=c(n),s=c(n),i=chunkPS272DZJ_cjs.O(s);if(i){n.push(i);break}n.push(ge(s)?t:e);break}case 50:{let e=O(d,I++,f,"plugin-function index"),t=O(d,I++,f,"argument count"),s=[];for(let p=0;p<t;p++)s.push(c(n));s.reverse();let i=a.context.pluginFunctions[e],l=chunkPS272DZJ_cjs.P(s);if(l)n.push(l);else if(!i)n.push(chunkPS272DZJ_cjs.n(0));else {let p=i(s,m);if(p instanceof Promise){let g=`plugin:${e}:${s.map(V=>String(V.value??"")).join("|")}`,M=a.activeSignal,U=a.context.pluginFunctionOwners[e]??"";return {type:"pending",queryKey:g,resolver:p,packageId:U,signal:M}}n.push(p);}break}case 51:{let e=O(d,I++,f,"builtin-function index"),t=O(d,I++,f,"argument count"),s=Rt(e,t);if(s)throw s;let i=[],l=!1;for(let M=0;M<t;M++){let U=c(n);U.type===9&&(l=!0),i.push(U);}let p=chunkPS272DZJ_cjs.P(i);if(p){n.push(p);break}let g=chunkYFWAR766_cjs.C[e];if(g){let M=i.reverse(),U=l&&!chunkYFWAR766_cjs.e.has(e);n.push(U?chunkYFWAR766_cjs.h(e,M):g(M));}break}case 150:{let e=O(d,I++,f,"function-body index"),t=S?.[e];if(!t)throw chunkSOMGSIO4_cjs.c.internal("INTERNAL_MISSING_FUNCTION_BODY",`Internal error: DEFINE_USER_FUNCTION referenced missing body index ${e}`,{bodyIdx:e});a.defineUserFunction(t.name,t.params,t.program);break}case 151:{let e=z(d,I++,x,f,"function-name index"),t=O(d,I++,f,"argument count"),s=[];for(let g=0;g<t;g++)s.push(c(n));s.reverse();let i=a.getUserFunction(e);if(!i)throw chunkSOMGSIO4_cjs.c.execution("UNDEFINED_FUNCTION",`Undefined function: ${e}`,{name:e});if(t!==i.params.length)throw chunkSOMGSIO4_cjs.c.execution("FUNCTION_ARITY_MISMATCH",`${e} expects ${i.params.length} argument(s) but got ${t}`,{name:e,expected:i.params.length,actual:t});let l=new Map;for(let g=0;g<i.params.length;g++)l.set(i.params[g],s[g]);chunkPS272DZJ_cjs.f(),a.pushCallFrame(l);let p;try{p=Je(i.program,a,o,u,m);}finally{a.popCallFrame();}if(p.type==="pending")throw chunkSOMGSIO4_cjs.c.execution("USER_FUNCTION_ASYNC_UNSUPPORTED",`${e}: user-defined functions with async bodies (weather, stocks, currency, ...) aren't supported`,{name:e});if(p.type==="error")throw p.error;n.push(p.value);break}case 60:{let e=z(d,I++,x,f,"variable-name index"),t=a.getVar(e);if(t!==void 0)n.push(t);else if(h)n.push(chunkPS272DZJ_cjs.I(chunkN7N7MPMK_cjs.q(e)));else throw chunkSOMGSIO4_cjs.c.execution("UNDEFINED_VARIABLE",`Undefined variable: ${e}`,{varName:e});break}case 61:{let e=c(n),t=z(d,I++,x,f,"variable-name index");a.setVar(t,W?chunkPS272DZJ_cjs.k(e):e),n.push(e);break}case 62:{let e=z(d,I++,x,f,"variable-name index"),t=chunkYFWAR766_cjs.J.get(e);if(t===void 0)throw chunkSOMGSIO4_cjs.c.internal({code:"GLOBAL_VARIABLE_NOT_RESOLVED",message:`Global variable "${e}" was read before it resolved`,expected:`global variable "${e}" to already be resolved (async preflight should guarantee this)`,found:"no value in the global variable store",context:{varName:e}});n.push(t);break}case 63:{let e=c(n),t=z(d,I++,x,f,"variable-name index");chunkYFWAR766_cjs.J.set(t,W?chunkPS272DZJ_cjs.k(e):e),n.push(e);break}case 70:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}n.push(chunkPS272DZJ_cjs.n(e.toNumber()));break}case 71:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}if(e.type===14){let s=e.value;n.push(chunkPS272DZJ_cjs.G({r:s.r,g:s.g,b:s.b,a:s.a,format:"hex"}));break}n.push(chunkPS272DZJ_cjs.r(e.type===2?e.value:e.toNumber()));break}case 74:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}n.push(chunkPS272DZJ_cjs.L(e.toNumber()));break}case 140:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}n.push(chunkPS272DZJ_cjs.t(e.rational!==void 0?hn(e.rational):bn(e.toNumber())));break}case 141:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}n.push(chunkPS272DZJ_cjs.t(gn(e)));break}case 142:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}n.push(chunkPS272DZJ_cjs.t(yn(e.toNumber())));break}case 143:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}n.push(chunkPS272DZJ_cjs.r(e.type===2?e.value:e.toNumber(),"bin"));break}case 144:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}n.push(chunkPS272DZJ_cjs.r(e.type===2?e.value:e.toNumber(),"oct"));break}case 145:{let e=q(c(n),f,"converter name").toLowerCase(),t=c(n),s=chunkPS272DZJ_cjs.O(t);if(s){n.push(s);break}let i=chunkYFWAR766_cjs.G.get(e);i?n.push(i(t)):n.push(chunkPS272DZJ_cjs.N("UNKNOWN_AS_CONVERTER",`Unknown converter "as ${e}"`));break}case 80:{let e=q(c(n),f,"unit name"),t=c(n),s=chunkPS272DZJ_cjs.O(t);if(s){n.push(s);break}let i=chunkYFWAR766_cjs.a(t,e);i?n.push(chunkPS272DZJ_cjs.v(t.toNumber(),e,i)):n.push(chunkPS272DZJ_cjs.u(t.toNumber(),e));break}case 81:{let e=q(c(n),f,"target unit name"),t=q(c(n),f,"source unit name"),s=c(n),i=chunkPS272DZJ_cjs.O(s);if(i){n.push(i);break}let l=s.toNumber(),p=chunkIANAMBJQ_cjs.c(t),g=chunk4BZIYU7S_cjs.c.isCurrency(t)&&chunk4BZIYU7S_cjs.c.isCurrency(e);if(p&&chunkIANAMBJQ_cjs.c(e)===p)n.push(chunkPS272DZJ_cjs.u(chunkIANAMBJQ_cjs.e(l,t,e),e));else if(g){let M=chunk4BZIYU7S_cjs.c.convertSync(l,t,e);M!==null?n.push(chunkPS272DZJ_cjs.u(M,e)):n.push(chunkPS272DZJ_cjs.N("CURRENCY_RATE_UNAVAILABLE",`No exchange rate available for ${t} to ${e}`));}else {let M=chunkIANAMBJQ_cjs.i(l,t,e);M!==null?n.push(chunkPS272DZJ_cjs.u(M,e)):n.push(Gt(t,e));}break}case 85:{let e=q(c(n),f,"unit name"),t=chunkIANAMBJQ_cjs.f(e);n.push(chunkPS272DZJ_cjs.t(t.length>0?t.join(", "):`No known units for "${e}"`));break}case 83:{let e=q(c(n),f,"unit name"),t=c(n),s=chunkPS272DZJ_cjs.O(t);if(s){n.push(s);break}let{value:i,unit:l}=chunkIANAMBJQ_cjs.h(t.toNumber(),e);n.push(chunkPS272DZJ_cjs.u(i,l));break}case 84:{let e=q(c(n),f,"target unit name"),t=c(n),s=chunkPS272DZJ_cjs.O(t);if(s){n.push(s);break}if(t.type===6){let i=t.unit,l=t.toNumber(),p=chunkIANAMBJQ_cjs.c(i),g=chunk4BZIYU7S_cjs.c.isCurrency(i)&&chunk4BZIYU7S_cjs.c.isCurrency(e);if(p&&chunkIANAMBJQ_cjs.c(e)===p)n.push(chunkPS272DZJ_cjs.u(chunkIANAMBJQ_cjs.e(l,i,e),e));else if(g){let M=chunk4BZIYU7S_cjs.c.convertSync(l,i,e);M!==null?n.push(chunkPS272DZJ_cjs.u(M,e)):n.push(chunkPS272DZJ_cjs.N("CURRENCY_RATE_UNAVAILABLE",`No exchange rate available for ${i} to ${e}`));}else {let M=chunkIANAMBJQ_cjs.i(l,i,e);M!==null?n.push(chunkPS272DZJ_cjs.u(M,e)):n.push(Gt(i,e));}}else n.push(chunkPS272DZJ_cjs.u(t.toNumber(),e));break}case 82:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}n.push(chunkPS272DZJ_cjs.n(e.toNumber()));break}case 110:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(e.type!==6||!e.unit){n.push(chunkPS272DZJ_cjs.N("RATE_MISSING_DENOMINATOR_UNIT",'Cannot build a rate: the right-hand side of "/" has no unit'));break}let i=t.type===6?t.unit??"":"";n.push(chunkPS272DZJ_cjs.w(t.toNumber()/e.toNumber(),i,e.unit));break}case 111:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(t.type!==6||!chunkPS272DZJ_cjs.x(t.unit)){n.push(chunkPS272DZJ_cjs.N("RATE_MUL_LEFT_NOT_A_RATE",'Left-hand side of a rate multiplication must be a rate (e.g. "$50/week")'));break}if(e.type!==6||!e.unit){n.push(chunkPS272DZJ_cjs.N("RATE_MUL_RIGHT_MISSING_UNIT","Right-hand side of a rate multiplication must have a unit matching the rate's denominator"));break}n.push(ze(t,e));break}case 112:{let e=q(c(n),f,"denominator unit name"),t=c(n),s=chunkPS272DZJ_cjs.O(t);if(s){n.push(s);break}if(t.type!==6||!chunkPS272DZJ_cjs.x(t.unit)){n.push(chunkPS272DZJ_cjs.N("RATE_CONVERT_NOT_A_RATE","Cannot convert a non-rate value's denominator"));break}let{numerator:i,denominator:l}=chunkPS272DZJ_cjs.y(t.unit),p=chunkIANAMBJQ_cjs.c(l),g=chunkIANAMBJQ_cjs.c(e);if(!p||p!==g){n.push(chunkPS272DZJ_cjs.N("RATE_CONVERT_MEASURE_MISMATCH",`Cannot convert a "${l}"-denominated rate to "${e}" \u2014 different measures`));break}let M=chunkIANAMBJQ_cjs.e(1,e,l);n.push(chunkPS272DZJ_cjs.w(t.toNumber()*M,i,e));break}case 120:{let e=c(n),t=chunkPS272DZJ_cjs.O(e);if(t){n.push(t);break}let s=e.toNumber(),i=new Date,l=new Date(i.getFullYear(),i.getMonth(),i.getDate(),0,0,0,0);l.setMinutes(s),n.push(chunkPS272DZJ_cjs.K(l.getTime()));break}case 90:n.push(chunkPS272DZJ_cjs.K(Date.now()));break;case 95:n.push(chunkPS272DZJ_cjs.K(y[qe(d,I++,f,"constant-pool index",y.length,"number-pool")]));break;case 91:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}n.push(chunkPS272DZJ_cjs.K(he(t.toNumber(),e,1,a)));break}case 92:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}n.push(chunkPS272DZJ_cjs.K(he(t.toNumber(),e,-1,a)));break}case 96:{let e=O(d,I++,f,"workday offset direction")===1?-1:1,t=c(n),s=c(n),i=chunkPS272DZJ_cjs.O(s,t);if(i){n.push(i);break}if(t.type!==4){n.push(chunkPS272DZJ_cjs.N(chunkSOMGSIO4_cjs.r.WORKDAY_OFFSET_EXPECTED_DATE,`"working days after/before/from" expects a date to count from, got ${chunkPS272DZJ_cjs.g[t.type]??"an unsupported value"}`));break}n.push(chunkPS272DZJ_cjs.K(qt(t.toNumber(),e*s.toNumber(),a)));break}case 97:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(t.type!==4||e.type!==4){n.push(chunkPS272DZJ_cjs.N(chunkSOMGSIO4_cjs.r.WORKDAYS_BETWEEN_EXPECTED_DATES,`"working days between" expects two dates, got ${chunkPS272DZJ_cjs.g[t.type]??"an unsupported value"} and ${chunkPS272DZJ_cjs.g[e.type]??"an unsupported value"}`));break}let i=Math.ceil((a.getMaxDateOffsetYears()-a.getMinDateOffsetYears())*366),l=Ot(t.toNumber(),e.toNumber(),p=>a.isHoliday(p),i);if(l===null){n.push(chunkPS272DZJ_cjs.N(chunkSOMGSIO4_cjs.r.WORKDAYS_BETWEEN_RANGE_TOO_LARGE,`The two dates are more than ${a.getMaxDateOffsetYears()-a.getMinDateOffsetYears()} years apart, past the working-day count's limit`));break}n.push(chunkPS272DZJ_cjs.n(l));break}case 93:case 94:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}let i=e.toNumber(),l=t.toNumber(),p=new Date(l).getDay(),g=f===93?(i-p+7)%7:(p-i+7)%7;g===0&&(g=7),n.push(chunkPS272DZJ_cjs.K(jt(l,f===93?g:-g)));break}case 152:{let e=O(d,I++,f,"row count"),t=O(d,I++,f,"column count"),s=e*t,i=chunkPS272DZJ_cjs.e(s,"matrix cells"),l=null;for(let p=s-1;p>=0;p--){let g=c(n);l===null&&(l=chunkPS272DZJ_cjs.O(g)),i[p]=g.type===10||g.type===9?g.value:g.toNumber();}if(l){n.push(l);break}n.push(chunkPS272DZJ_cjs.C(e,t,chunkN7N7MPMK_cjs.Y(e,t,i)));break}case 153:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(t.type!==7){n.push(chunkPS272DZJ_cjs.N("MATRIX_INDEX_NOT_A_MATRIX",'Cannot index a non-matrix value with "[...]".'));break}let i=t.value,l=Math.trunc(e.toNumber());if(l<0||l>=i.data.length){n.push(chunkPS272DZJ_cjs.N("MATRIX_INDEX_OUT_OF_BOUNDS",`Index ${l} is out of bounds for a ${i.rows}x${i.cols} matrix (valid range: 0-${i.data.length-1}).`));break}let p=chunkN7N7MPMK_cjs.S(i,l);n.push(chunkN7N7MPMK_cjs.X(p));break}case 154:{let e=c(n),t=c(n),s=c(n),i=chunkPS272DZJ_cjs.O(s,t,e);if(i){n.push(i);break}if(s.type!==7){n.push(chunkPS272DZJ_cjs.N("MATRIX_INDEX_NOT_A_MATRIX",'Cannot index a non-matrix value with "[...]".'));break}let l=s.value,p=Math.trunc(t.toNumber()),g=Math.trunc(e.toNumber());if(!chunkN7N7MPMK_cjs.U(l,p,g)){n.push(chunkPS272DZJ_cjs.N("MATRIX_INDEX_OUT_OF_BOUNDS",`[${p}, ${g}] is out of bounds for a ${l.rows}x${l.cols} matrix.`));break}let M=chunkN7N7MPMK_cjs.T(l,p,g);n.push(chunkN7N7MPMK_cjs.X(M));break}case 156:{let e=c(n),t=c(n),s=chunkPS272DZJ_cjs.O(t,e);if(s){n.push(s);break}if(t.type!==0||e.type!==0){n.push(chunkPS272DZJ_cjs.N("INVALID_RANGE_BOUND",`A range's bounds must be plain numbers (e.g. "0:3").`));break}let i=t.value,l=e.value;if(!Number.isInteger(i)||!Number.isInteger(l)){n.push(chunkPS272DZJ_cjs.N("NON_INTEGER_RANGE_BOUND",`A range's bounds must be whole numbers, got "${i}:${l}".`));break}if(i>l){n.push(chunkPS272DZJ_cjs.N("DESCENDING_RANGE",`A range's min (${i}) cannot be greater than its max (${l}) \u2014 did you mean "${l}:${i}"?`));break}n.push(chunkPS272DZJ_cjs.F(i,l));break}case 155:{let e=c(n),t=c(n),s=c(n),i=chunkPS272DZJ_cjs.O(s,t,e);if(i){n.push(i);break}if(s.type!==7){n.push(chunkPS272DZJ_cjs.N("MATRIX_INDEX_NOT_A_MATRIX",'Cannot slice a non-matrix value with "[...]".'));break}if(t.type!==8||e.type!==8){n.push(chunkPS272DZJ_cjs.N("INVALID_MATRIX_SLICE_BOUND",'Matrix slicing needs range bounds (e.g. "a[0:1, 1:2]").'));break}let l=s.value,p=t.value,g=e.value;if(p.min<0||p.max>=l.rows||g.min<0||g.max>=l.cols){n.push(chunkPS272DZJ_cjs.N("MATRIX_INDEX_OUT_OF_BOUNDS",`Slice [${p.min}:${p.max}, ${g.min}:${g.max}] is out of bounds for a ${l.rows}x${l.cols} matrix.`));break}let M=p.max-p.min+1,U=g.max-g.min+1,V=chunkPS272DZJ_cjs.e(M*U,"matrix cells");for(let B=0;B<M;B++)for(let w=0;w<U;w++)V[B+w*M]=chunkN7N7MPMK_cjs.T(l,p.min+B,g.min+w);n.push(chunkPS272DZJ_cjs.C(M,U,V));break}case 157:{let e=O(d,I++,f,"body kind"),t=O(d,I++,f,"body reference"),s=O(d,I++,f,"collection count");Vt(e,t,f);let i=new Array(s);for(let T=s-1;T>=0;T--)i[T]=c(n);let l=[],p;if(e===0){let T=A?.[t];if(!T)throw chunkSOMGSIO4_cjs.c.internal("INTERNAL_MISSING_ANONYMOUS_BODY",`Internal error: MAP_INVOKE referenced missing anonymous body index ${t}`,{ref:t});l=T.params,p=T.program;}else if(e===2){let T=Qe(x,t,f),v=a.getUserFunction(T);if(!v){n.push(chunkPS272DZJ_cjs.N("UNDEFINED_FUNCTION",`map: undefined function "${T}"`));break}if(v.params.length!==s){n.push(chunkPS272DZJ_cjs.N("FUNCTION_ARITY_MISMATCH",`map: "${T}" expects ${v.params.length} argument(s) but ${s} collection(s) were given`));break}l=v.params,p=v.program;}let g=-1,M=new Array(s),U;for(let T=0;T<s;T++){let v=chunkN7N7MPMK_cjs.ea(i[T],a.getMaxCollectionSize());if(!Array.isArray(v)){U=v;break}if(chunkPS272DZJ_cjs.c(v.length,"collection elements"),g===-1)g=v.length;else if(v.length!==g){U=chunkPS272DZJ_cjs.N("MAP_COLLECTION_LENGTH_MISMATCH",`map: all collections must have the same length (got ${g} and ${v.length}).`);break}M[T]=v;}if(U){n.push(U);break}let V=chunkPS272DZJ_cjs.e(g,"matrix cells"),B;for(let T=0;T<g;T++){let v=new Array(s);for(let ye=0;ye<s;ye++)v[ye]=M[ye][T];let ae=e===1?chunkYFWAR766_cjs.C[t]?.(v)??chunkPS272DZJ_cjs.N("UNKNOWN_BUILTIN_FUNCTION",`map: unknown builtin function index ${t}`):Bt(l,p,v,a,o,u,m,!!h),Ze=chunkPS272DZJ_cjs.O(ae);if(Ze){B=Ze;break}V[T]=ae.type===10||ae.type===9?ae.value:ae.toNumber();}if(B){n.push(B);break}let w=i[0],R=w?.type===7?w.value:void 0;R&&R.rows*R.cols===g?n.push(chunkPS272DZJ_cjs.C(R.rows,R.cols,V)):n.push(chunkPS272DZJ_cjs.C(1,g,V));break}case 158:{let e=O(d,I++,f,"body kind"),t=O(d,I++,f,"body reference"),s=O(d,I++,f,"initial-value flag");Vt(e,t,f);let i=s?c(n):void 0,l=c(n),p=[],g;if(e===0){let w=A?.[t];if(!w)throw chunkSOMGSIO4_cjs.c.internal("INTERNAL_MISSING_ANONYMOUS_BODY",`Internal error: REDUCE_INVOKE referenced missing anonymous body index ${t}`,{ref:t});p=w.params,g=w.program;}else if(e===2){let w=Qe(x,t,f),R=a.getUserFunction(w);if(!R){n.push(chunkPS272DZJ_cjs.N("UNDEFINED_FUNCTION",`reduce: undefined function "${w}"`));break}if(R.params.length!==2){n.push(chunkPS272DZJ_cjs.N("FUNCTION_ARITY_MISMATCH",`reduce: "${w}" must take exactly 2 arguments (accumulator, element), got ${R.params.length}`));break}p=R.params,g=R.program;}let M=chunkN7N7MPMK_cjs.ea(l,a.getMaxCollectionSize());if(!Array.isArray(M)){n.push(M);break}chunkPS272DZJ_cjs.c(M.length,"collection elements");let U,V;if(i!==void 0){let w=chunkPS272DZJ_cjs.O(i);if(w){n.push(w);break}U=i,V=0;}else {if(M.length===0){n.push(chunkPS272DZJ_cjs.N("REDUCE_EMPTY_COLLECTION","reduce: cannot reduce an empty collection without an initial value."));break}U=M[0],V=1;}let B;for(let w=V;w<M.length;w++){let R=[U,M[w]],T=e===1?chunkYFWAR766_cjs.C[t]?.(R)??chunkPS272DZJ_cjs.N("UNKNOWN_BUILTIN_FUNCTION",`reduce: unknown builtin function index ${t}`):Bt(p,g,R,a,o,u,m,!!h),v=chunkPS272DZJ_cjs.O(T);if(v){B=v;break}U=T;}if(B){n.push(B);break}n.push(U);break}case 159:{let e=O(d,I++,f,"body reference"),t=A?.[e];if(!t)throw chunkSOMGSIO4_cjs.c.internal("INTERNAL_MISSING_ANONYMOUS_BODY",`Internal error: BIND_UNKNOWN referenced missing anonymous body index ${e}`,{ref:e});n.push(rn(t.params[0],t.program,a,o,u,m,!!h));break}}}let K=c(n);return {type:"value",value:W?chunkPS272DZJ_cjs.k(K):K}}catch(K){return {type:"error",error:chunkSOMGSIO4_cjs.d(K)}}finally{chunkPS272DZJ_cjs.b();}}exports.a=At;exports.b=wt;exports.c=Hn;exports.d=Je;//# sourceMappingURL=chunk-ANJPS6FF.cjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-ANJPS6FF.cjs.map
|