solve-engine 1.0.0-beta.0 → 1.0.0-beta.2
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/BytecodeBuilder-3egMyuDi.d.cts +274 -0
- package/dist/BytecodeBuilder-3egMyuDi.d.ts +274 -0
- package/dist/Configuration-fVpd-HC-.d.cts +228 -0
- package/dist/Configuration-fVpd-HC-.d.ts +228 -0
- package/dist/EngineError-DvPSnhZi.d.cts +304 -0
- package/dist/EngineError-DvPSnhZi.d.ts +304 -0
- package/dist/Lexer-BJdhlnej.d.cts +531 -0
- package/dist/Lexer-D9l4Yrk2.d.ts +531 -0
- package/dist/NormalizerRule-BrVoVjmP.d.cts +163 -0
- package/dist/NormalizerRule-CEjf1FyD.d.ts +163 -0
- package/dist/PackageRegistry-D-Tv_7ca.d.cts +2572 -0
- package/dist/PackageRegistry-DaH4aIKP.d.ts +2572 -0
- package/dist/Parselet-CK8cQu2a.d.cts +299 -0
- package/dist/Parselet-ConOIdRO.d.ts +299 -0
- package/dist/ScopeManager-B5k0nk05.d.ts +559 -0
- package/dist/ScopeManager-CKfQtl7l.d.cts +559 -0
- package/dist/Token-0jpvUdPY.d.cts +245 -0
- package/dist/Token-0jpvUdPY.d.ts +245 -0
- package/dist/VMCheckpoints-BmDwIXgK.d.ts +171 -0
- package/dist/VMCheckpoints-CqFuLwrT.d.cts +171 -0
- package/dist/Value-KtAQNHur.d.cts +295 -0
- package/dist/Value-KtAQNHur.d.ts +295 -0
- package/dist/chunk-2RWAXT6O.js +3 -0
- package/dist/chunk-2RWAXT6O.js.map +1 -0
- package/dist/chunk-34RRD7PC.js +1492 -0
- package/dist/chunk-34RRD7PC.js.map +1 -0
- package/dist/chunk-3PPFLFH4.js +5097 -0
- package/dist/chunk-3PPFLFH4.js.map +1 -0
- package/dist/chunk-3VGDNEE3.js +84 -0
- package/dist/chunk-3VGDNEE3.js.map +1 -0
- package/dist/chunk-3YNVWKR2.cjs +370 -0
- package/dist/chunk-3YNVWKR2.cjs.map +1 -0
- package/dist/chunk-47LRVGOT.cjs +316 -0
- package/dist/chunk-47LRVGOT.cjs.map +1 -0
- package/dist/chunk-4MG4XKO2.js +1644 -0
- package/dist/chunk-4MG4XKO2.js.map +1 -0
- package/dist/chunk-4QADQTWS.js +2392 -0
- package/dist/chunk-4QADQTWS.js.map +1 -0
- package/dist/chunk-53B6KDDJ.cjs +1651 -0
- package/dist/chunk-53B6KDDJ.cjs.map +1 -0
- package/dist/chunk-5X2PTP6F.cjs +104 -0
- package/dist/chunk-5X2PTP6F.cjs.map +1 -0
- package/dist/chunk-5YEMOYSE.js +264 -0
- package/dist/chunk-5YEMOYSE.js.map +1 -0
- package/dist/chunk-64W6GLLZ.js +481 -0
- package/dist/chunk-64W6GLLZ.js.map +1 -0
- package/dist/chunk-6BKTCEUP.cjs +233 -0
- package/dist/chunk-6BKTCEUP.cjs.map +1 -0
- package/dist/chunk-6NTVRDQV.cjs +1642 -0
- package/dist/chunk-6NTVRDQV.cjs.map +1 -0
- package/dist/chunk-6RDSQURE.js +290 -0
- package/dist/chunk-6RDSQURE.js.map +1 -0
- package/dist/chunk-75JP4BZX.js +93 -0
- package/dist/chunk-75JP4BZX.js.map +1 -0
- package/dist/chunk-B7LXJ6LC.cjs +36 -0
- package/dist/chunk-B7LXJ6LC.cjs.map +1 -0
- package/dist/chunk-BVAR5J2F.js +257 -0
- package/dist/chunk-BVAR5J2F.js.map +1 -0
- package/dist/chunk-C4XZV6E7.cjs +269 -0
- package/dist/chunk-C4XZV6E7.cjs.map +1 -0
- package/dist/chunk-CCJPSHGI.cjs +40 -0
- package/dist/chunk-CCJPSHGI.cjs.map +1 -0
- package/dist/chunk-CLL7RUQV.cjs +316 -0
- package/dist/chunk-CLL7RUQV.cjs.map +1 -0
- package/dist/chunk-DM3LMRBC.js +329 -0
- package/dist/chunk-DM3LMRBC.js.map +1 -0
- package/dist/chunk-DUEZFTK2.js +38 -0
- package/dist/chunk-DUEZFTK2.js.map +1 -0
- package/dist/chunk-EBSPLUW4.cjs +489 -0
- package/dist/chunk-EBSPLUW4.cjs.map +1 -0
- package/dist/chunk-EHAHVROS.cjs +261 -0
- package/dist/chunk-EHAHVROS.cjs.map +1 -0
- package/dist/chunk-EIGTWK5N.js +167 -0
- package/dist/chunk-EIGTWK5N.js.map +1 -0
- package/dist/chunk-EPOXXJBK.js +96 -0
- package/dist/chunk-EPOXXJBK.js.map +1 -0
- package/dist/chunk-FEAIOR7N.cjs +91 -0
- package/dist/chunk-FEAIOR7N.cjs.map +1 -0
- package/dist/chunk-G535KJEG.js +312 -0
- package/dist/chunk-G535KJEG.js.map +1 -0
- package/dist/chunk-GCM5JHMX.js +88 -0
- package/dist/chunk-GCM5JHMX.js.map +1 -0
- package/dist/chunk-GOLDJNMZ.js +368 -0
- package/dist/chunk-GOLDJNMZ.js.map +1 -0
- package/dist/chunk-GW32KPCU.cjs +360 -0
- package/dist/chunk-GW32KPCU.cjs.map +1 -0
- package/dist/chunk-HTXVVJRA.cjs +1549 -0
- package/dist/chunk-HTXVVJRA.cjs.map +1 -0
- package/dist/chunk-HWSZJQCI.js +311 -0
- package/dist/chunk-HWSZJQCI.js.map +1 -0
- package/dist/chunk-IF532O7C.js +101 -0
- package/dist/chunk-IF532O7C.js.map +1 -0
- package/dist/chunk-J73SJHR3.cjs +2415 -0
- package/dist/chunk-J73SJHR3.cjs.map +1 -0
- package/dist/chunk-JBSYC7BB.cjs +7473 -0
- package/dist/chunk-JBSYC7BB.cjs.map +1 -0
- package/dist/chunk-KVILKGMS.js +228 -0
- package/dist/chunk-KVILKGMS.js.map +1 -0
- package/dist/chunk-LIPPNDBE.js +258 -0
- package/dist/chunk-LIPPNDBE.js.map +1 -0
- package/dist/chunk-LR7YASZF.cjs +172 -0
- package/dist/chunk-LR7YASZF.cjs.map +1 -0
- package/dist/chunk-M4N5GA5Z.cjs +309 -0
- package/dist/chunk-M4N5GA5Z.cjs.map +1 -0
- package/dist/chunk-M5LX5AOO.js +7459 -0
- package/dist/chunk-M5LX5AOO.js.map +1 -0
- package/dist/chunk-MZOVP3WI.cjs +96 -0
- package/dist/chunk-MZOVP3WI.cjs.map +1 -0
- package/dist/chunk-N5YFR4UP.cjs +10 -0
- package/dist/chunk-N5YFR4UP.cjs.map +1 -0
- package/dist/chunk-NGBBNL4K.cjs +4 -0
- package/dist/chunk-NGBBNL4K.cjs.map +1 -0
- package/dist/chunk-NH2O2AUR.js +146 -0
- package/dist/chunk-NH2O2AUR.js.map +1 -0
- package/dist/chunk-NLNDMWZC.js +31 -0
- package/dist/chunk-NLNDMWZC.js.map +1 -0
- package/dist/chunk-NMCRQP3Z.cjs +778 -0
- package/dist/chunk-NMCRQP3Z.cjs.map +1 -0
- package/dist/chunk-NMD5VRN4.cjs +1327 -0
- package/dist/chunk-NMD5VRN4.cjs.map +1 -0
- package/dist/chunk-OC6LTXYS.cjs +286 -0
- package/dist/chunk-OC6LTXYS.cjs.map +1 -0
- package/dist/chunk-OT6OJY7C.cjs +114 -0
- package/dist/chunk-OT6OJY7C.cjs.map +1 -0
- package/dist/chunk-PFSDGGYL.js +8 -0
- package/dist/chunk-PFSDGGYL.js.map +1 -0
- package/dist/chunk-QNJ4ACRT.cjs +155 -0
- package/dist/chunk-QNJ4ACRT.cjs.map +1 -0
- package/dist/chunk-QWY3VEZN.js +1637 -0
- package/dist/chunk-QWY3VEZN.js.map +1 -0
- package/dist/chunk-RFYD5TJE.js +111 -0
- package/dist/chunk-RFYD5TJE.js.map +1 -0
- package/dist/chunk-RIN643A3.js +354 -0
- package/dist/chunk-RIN643A3.js.map +1 -0
- package/dist/chunk-RZCWSXTA.cjs +5122 -0
- package/dist/chunk-RZCWSXTA.cjs.map +1 -0
- package/dist/chunk-SDGRK7EP.js +774 -0
- package/dist/chunk-SDGRK7EP.js.map +1 -0
- package/dist/chunk-VEKIWQ3F.cjs +39 -0
- package/dist/chunk-VEKIWQ3F.cjs.map +1 -0
- package/dist/chunk-WQTTOGXC.cjs +99 -0
- package/dist/chunk-WQTTOGXC.cjs.map +1 -0
- package/dist/chunk-X6K3HUOY.cjs +86 -0
- package/dist/chunk-X6K3HUOY.cjs.map +1 -0
- package/dist/chunk-XJCMXB2E.cjs +333 -0
- package/dist/chunk-XJCMXB2E.cjs.map +1 -0
- package/dist/chunk-XVWCOTR6.js +1324 -0
- package/dist/chunk-XVWCOTR6.js.map +1 -0
- package/dist/chunk-YLJ4XMA6.js +33 -0
- package/dist/chunk-YLJ4XMA6.js.map +1 -0
- package/dist/chunk-Z2XP767T.cjs +35 -0
- package/dist/chunk-Z2XP767T.cjs.map +1 -0
- package/dist/chunk-Z4X2RWOF.js +37 -0
- package/dist/chunk-Z4X2RWOF.js.map +1 -0
- package/dist/constants.cjs +22 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +12 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/engine.cjs +79 -0
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +587 -0
- package/dist/engine.d.ts +587 -0
- package/dist/engine.js +34 -0
- package/dist/engine.js.map +1 -0
- package/dist/errors.cjs +81 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +95 -0
- package/dist/errors.d.ts +95 -0
- package/dist/errors.js +4 -0
- package/dist/errors.js.map +1 -0
- package/dist/format.cjs +171 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.d.cts +51 -0
- package/dist/format.d.ts +51 -0
- package/dist/format.js +168 -0
- package/dist/format.js.map +1 -0
- package/dist/index.cjs +97 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +152 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +75 -0
- package/dist/index.js.map +1 -0
- package/dist/language.cjs +308 -0
- package/dist/language.cjs.map +1 -0
- package/dist/language.d.cts +110 -0
- package/dist/language.d.ts +110 -0
- package/dist/language.js +287 -0
- package/dist/language.js.map +1 -0
- package/dist/lexer.cjs +64 -0
- package/dist/lexer.cjs.map +1 -0
- package/dist/lexer.d.cts +56 -0
- package/dist/lexer.d.ts +56 -0
- package/dist/lexer.js +11 -0
- package/dist/lexer.js.map +1 -0
- package/dist/normalizer.cjs +40 -0
- package/dist/normalizer.cjs.map +1 -0
- package/dist/normalizer.d.cts +364 -0
- package/dist/normalizer.d.ts +364 -0
- package/dist/normalizer.js +11 -0
- package/dist/normalizer.js.map +1 -0
- package/dist/packages.cjs +121 -0
- package/dist/packages.cjs.map +1 -0
- package/dist/packages.d.cts +691 -0
- package/dist/packages.d.ts +691 -0
- package/dist/packages.js +24 -0
- package/dist/packages.js.map +1 -0
- package/dist/parser.cjs +55 -0
- package/dist/parser.cjs.map +1 -0
- package/dist/parser.d.cts +46 -0
- package/dist/parser.d.ts +46 -0
- package/dist/parser.js +10 -0
- package/dist/parser.js.map +1 -0
- package/dist/pipeline-CrsRPmsv.d.ts +285 -0
- package/dist/pipeline-DPUQt7yL.d.cts +285 -0
- package/dist/resolvers.cjs +13 -0
- package/dist/resolvers.cjs.map +1 -0
- package/dist/resolvers.d.cts +111 -0
- package/dist/resolvers.d.ts +111 -0
- package/dist/resolvers.js +4 -0
- package/dist/resolvers.js.map +1 -0
- package/dist/services.cjs +21 -0
- package/dist/services.cjs.map +1 -0
- package/dist/services.d.cts +30 -0
- package/dist/services.d.ts +30 -0
- package/dist/services.js +4 -0
- package/dist/services.js.map +1 -0
- package/dist/uom.cjs +56 -0
- package/dist/uom.cjs.map +1 -0
- package/dist/uom.d.cts +224 -0
- package/dist/uom.d.ts +224 -0
- package/dist/uom.js +11 -0
- package/dist/uom.js.map +1 -0
- package/dist/utilities.cjs +32 -0
- package/dist/utilities.cjs.map +1 -0
- package/dist/utilities.d.cts +113 -0
- package/dist/utilities.d.ts +113 -0
- package/dist/utilities.js +7 -0
- package/dist/utilities.js.map +1 -0
- package/dist/variables.cjs +17 -0
- package/dist/variables.cjs.map +1 -0
- package/dist/variables.d.cts +87 -0
- package/dist/variables.d.ts +87 -0
- package/dist/variables.js +4 -0
- package/dist/variables.js.map +1 -0
- package/dist/vm.cjs +284 -0
- package/dist/vm.cjs.map +1 -0
- package/dist/vm.d.cts +68 -0
- package/dist/vm.d.ts +68 -0
- package/dist/vm.js +194 -0
- package/dist/vm.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Module for solve-js Engine
|
|
3
|
+
*
|
|
4
|
+
* This module provides the **single source of truth** for all engine configuration.
|
|
5
|
+
* Every configurable aspect of the engine, from safety limits and performance
|
|
6
|
+
* budgets to VM constraints and worker pool sizing, is defined here.
|
|
7
|
+
*
|
|
8
|
+
* ### Design principles
|
|
9
|
+
*
|
|
10
|
+
* 1. **Engine owns its config.** The engine defines its own config shape and defaults.
|
|
11
|
+
* Consumers (e.g., the Obsidian plugin) pass partial overrides; all unspecified
|
|
12
|
+
* fields fall back to `DEFAULT_CONFIG`.
|
|
13
|
+
*
|
|
14
|
+
* 2. **Self-documenting.** Every interface and field has descriptive JSDoc so the
|
|
15
|
+
* config is understandable at a glance, whether you're using the engine as an
|
|
16
|
+
* npm package or reading the source.
|
|
17
|
+
*
|
|
18
|
+
* 3. **Minimal consumer knowledge.** Consumers only need to pass `Partial<EngineConfig>`.
|
|
19
|
+
* They don't need to replicate the full config shape, just the fields they
|
|
20
|
+
* want to override.
|
|
21
|
+
*
|
|
22
|
+
* @module Configuration
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Date-related configuration.
|
|
26
|
+
* Controls the bounds and formatting for date/time expression evaluation
|
|
27
|
+
* (e.g., `today + 20 days`, `last monday`).
|
|
28
|
+
*/
|
|
29
|
+
interface DateConfig {
|
|
30
|
+
/** Default offset in days for relative date calculations when no offset is specified */
|
|
31
|
+
readonly defaultOffsetDays: number;
|
|
32
|
+
/** Maximum allowed positive offset in years (safety limit) */
|
|
33
|
+
readonly maxOffsetYears: number;
|
|
34
|
+
/** Maximum allowed negative offset in years (safety limit) */
|
|
35
|
+
readonly minOffsetYears: number;
|
|
36
|
+
/** Default date string format for display (moment.js format string) */
|
|
37
|
+
readonly defaultFormat: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Dice-related configuration.
|
|
41
|
+
* Controls dice expression evaluation (e.g., `roll(1, 100)`, `3d6`).
|
|
42
|
+
*/
|
|
43
|
+
interface DiceConfig {
|
|
44
|
+
/** Default number of sides on a die when not specified */
|
|
45
|
+
readonly defaultSides: number;
|
|
46
|
+
/** Maximum allowed sides per die (prevents excessive allocation) */
|
|
47
|
+
readonly maxSides: number;
|
|
48
|
+
/** Maximum number of dice in a single roll expression */
|
|
49
|
+
readonly maxDice: number;
|
|
50
|
+
/** Default number of dice when not specified */
|
|
51
|
+
readonly defaultDice: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Performance-related configuration.
|
|
55
|
+
* Controls caching, timeouts, and processing limits to prevent runaway
|
|
56
|
+
* resource consumption on large documents.
|
|
57
|
+
*/
|
|
58
|
+
interface PerformanceConfig {
|
|
59
|
+
/**
|
|
60
|
+
* Maximum number of entries in {@link ExpressionEngine}'s bytecode cache
|
|
61
|
+
* (per-instance, keyed by expression text) before the oldest entry is
|
|
62
|
+
* evicted. Raise this for documents with many distinct expressions if
|
|
63
|
+
* repeated re-evaluation (e.g. scrolling) is re-parsing instead of
|
|
64
|
+
* hitting cache, bug fix (release hardening pass): this field used to
|
|
65
|
+
* be read nowhere; the cache size was a hardcoded, unconfigurable
|
|
66
|
+
* constant. Note this does NOT bound {@link LineCache}, which has no
|
|
67
|
+
* size limit of its own.
|
|
68
|
+
*/
|
|
69
|
+
readonly defaultCacheSize: number;
|
|
70
|
+
/** Maximum number of document lines processed in a single pass */
|
|
71
|
+
readonly maxDocumentLines: number;
|
|
72
|
+
/** Maximum time (ms) allowed for parsing a single expression before timeout */
|
|
73
|
+
readonly parseTimeoutMs: number;
|
|
74
|
+
/** Maximum time (ms) allowed for executing a single expression before timeout */
|
|
75
|
+
readonly executionTimeoutMs: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Validation / safety-limit configuration.
|
|
79
|
+
* Protects against runaway expressions that could cause excessive memory use
|
|
80
|
+
* or stack overflow. These limits are checked during lexing and parsing.
|
|
81
|
+
*/
|
|
82
|
+
/** Bounds on untrusted input: expression length and nesting depth. */
|
|
83
|
+
interface ValidationConfig {
|
|
84
|
+
/** Maximum expression length in characters. Prevents excessively long strings from entering the pipeline. */
|
|
85
|
+
readonly maxExpressionLength: number;
|
|
86
|
+
/** Maximum expression complexity score (`tokens + functionCalls×5 + nestingDepth×10`). Protects against deeply nested or combinatorially complex expressions. */
|
|
87
|
+
readonly maxComplexity: number;
|
|
88
|
+
/** Maximum parentheses nesting depth. Prevents stack overflow in the recursive-descent parser. */
|
|
89
|
+
readonly maxNestingDepth: number;
|
|
90
|
+
/**
|
|
91
|
+
* Auto-balance unmatched parentheses by appending missing closing parens
|
|
92
|
+
* or prepending missing opening parens. When disabled, unbalanced expressions
|
|
93
|
+
* cause parse errors instead of being silently corrected.
|
|
94
|
+
*
|
|
95
|
+
* Disabled by default for strict parsing. Enable for forgiving user input
|
|
96
|
+
* (e.g., chat-style calculators where users often omit closing parens).
|
|
97
|
+
* Has zero overhead when disabled, the O(n) paren-count scan is skipped.
|
|
98
|
+
*/
|
|
99
|
+
readonly autoBalanceParens: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Worker pool configuration.
|
|
103
|
+
* Controls the parallel execution workers used for batch evaluation.
|
|
104
|
+
*/
|
|
105
|
+
interface WorkerConfig {
|
|
106
|
+
/** Maximum number of concurrent Web Workers allowed */
|
|
107
|
+
readonly maxConcurrentWorkers: number;
|
|
108
|
+
/** Time (ms) a worker stays alive while idle before being terminated */
|
|
109
|
+
readonly idleTimeoutMs: number;
|
|
110
|
+
/** Maximum retry attempts for a failed worker operation */
|
|
111
|
+
readonly maxRetries: number;
|
|
112
|
+
/** Base backoff delay (ms) between retries (exponential backoff applied on top) */
|
|
113
|
+
readonly baseBackoffMs: number;
|
|
114
|
+
} /**
|
|
115
|
+
* Diagnostic / telemetry configuration.
|
|
116
|
+
* Controls the diagnostic event pipeline for profiling and debugging.
|
|
117
|
+
* All diagnostics are disabled by default for maximum production performance.
|
|
118
|
+
*/
|
|
119
|
+
interface DiagnosticConfig {
|
|
120
|
+
/** Master switch: enable the diagnostic pipeline (collectors receive events for all pipeline stages) */
|
|
121
|
+
readonly enabled: boolean;
|
|
122
|
+
/** Enable VM trace mode, emits per-opcode execution events (very verbose; disables some optimizations) */
|
|
123
|
+
readonly vmTraceEnabled: boolean;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Virtual Machine configuration.
|
|
127
|
+
* Controls the internal bytecode VM that executes compiled expressions.
|
|
128
|
+
*/
|
|
129
|
+
interface VMConfig {
|
|
130
|
+
/** Maximum stack depth (value slots) for VM execution, prevents stack overflow in recursive/pratt-parser generated bytecode */
|
|
131
|
+
readonly maxStackDepth: number;
|
|
132
|
+
/** Maximum opcodes executed per expression, halts runaway infinite loops */
|
|
133
|
+
readonly maxInstructions: number;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Complete engine configuration.
|
|
137
|
+
*
|
|
138
|
+
* Every field has a default in `DEFAULT_CONFIG`. To customize, pass a
|
|
139
|
+
* `Partial<EngineConfig>` when constructing `ExpressionEngine`. Only the
|
|
140
|
+
* sections/fields you supply are overridden; all others use their defaults.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* import { ExpressionEngine } from "solve-js";
|
|
145
|
+
*
|
|
146
|
+
* const engine = new ExpressionEngine("en", false, {
|
|
147
|
+
* validation: {
|
|
148
|
+
* maxExpressionLength: 1000,
|
|
149
|
+
* maxComplexity: 200,
|
|
150
|
+
* },
|
|
151
|
+
* // date, dice, performance, vm, worker, diagnostic all use defaults
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
interface EngineConfig {
|
|
156
|
+
/** Date/time expression evaluation bounds and formatting */
|
|
157
|
+
readonly date: DateConfig;
|
|
158
|
+
/** Dice roll expression controls */
|
|
159
|
+
readonly dice: DiceConfig;
|
|
160
|
+
/** Performance budgets and cache sizing */
|
|
161
|
+
readonly performance: PerformanceConfig;
|
|
162
|
+
/** Safety limits for expression complexity */
|
|
163
|
+
readonly validation: ValidationConfig;
|
|
164
|
+
/** Internal bytecode VM configuration */
|
|
165
|
+
readonly vm: VMConfig;
|
|
166
|
+
/** Parallel worker pool configuration */
|
|
167
|
+
readonly worker: WorkerConfig;
|
|
168
|
+
/** Diagnostic pipeline configuration */
|
|
169
|
+
readonly diagnostic: DiagnosticConfig;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Default configuration values
|
|
173
|
+
*/
|
|
174
|
+
declare const DEFAULT_CONFIG: EngineConfig;
|
|
175
|
+
/**
|
|
176
|
+
* Configuration manager for engine settings
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const configManager = new ConfigManager();
|
|
181
|
+
* configManager.set('performance.defaultCacheSize', 2000);
|
|
182
|
+
* const cacheSize = configManager.get('performance.defaultCacheSize');
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
declare class ConfigManager {
|
|
186
|
+
private config;
|
|
187
|
+
constructor(config?: Partial<EngineConfig>);
|
|
188
|
+
/**
|
|
189
|
+
* Get configuration value by path
|
|
190
|
+
*
|
|
191
|
+
* @param path - Dot-notation path to config value
|
|
192
|
+
* @returns Configuration value
|
|
193
|
+
*/
|
|
194
|
+
get<T>(path: string): T;
|
|
195
|
+
/**
|
|
196
|
+
* Set configuration value by path
|
|
197
|
+
*
|
|
198
|
+
* @param path - Dot-notation path to config value
|
|
199
|
+
* @param value - New value
|
|
200
|
+
*/
|
|
201
|
+
set<T>(path: string, value: T): void;
|
|
202
|
+
/**
|
|
203
|
+
* Get complete configuration
|
|
204
|
+
*/
|
|
205
|
+
getConfig(): EngineConfig;
|
|
206
|
+
/**
|
|
207
|
+
* Update multiple configuration values
|
|
208
|
+
*/
|
|
209
|
+
update(config: Partial<EngineConfig>): void;
|
|
210
|
+
/**
|
|
211
|
+
* Reset to default configuration
|
|
212
|
+
*/
|
|
213
|
+
reset(): void;
|
|
214
|
+
/**
|
|
215
|
+
* Validate configuration values
|
|
216
|
+
*/
|
|
217
|
+
validate(): ValidationResult;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Result type for {@link ConfigManager.validate}.
|
|
221
|
+
*/
|
|
222
|
+
interface ValidationResult {
|
|
223
|
+
valid: boolean;
|
|
224
|
+
error?: string;
|
|
225
|
+
warnings?: string[];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { ConfigManager as C, DEFAULT_CONFIG as D, type EngineConfig as E, type PerformanceConfig as P, type VMConfig as V, type WorkerConfig as W, type DateConfig as a, type DiagnosticConfig as b, type DiceConfig as c, type ValidationConfig as d, type ValidationResult as e };
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Module for solve-js Engine
|
|
3
|
+
*
|
|
4
|
+
* This module provides the **single source of truth** for all engine configuration.
|
|
5
|
+
* Every configurable aspect of the engine, from safety limits and performance
|
|
6
|
+
* budgets to VM constraints and worker pool sizing, is defined here.
|
|
7
|
+
*
|
|
8
|
+
* ### Design principles
|
|
9
|
+
*
|
|
10
|
+
* 1. **Engine owns its config.** The engine defines its own config shape and defaults.
|
|
11
|
+
* Consumers (e.g., the Obsidian plugin) pass partial overrides; all unspecified
|
|
12
|
+
* fields fall back to `DEFAULT_CONFIG`.
|
|
13
|
+
*
|
|
14
|
+
* 2. **Self-documenting.** Every interface and field has descriptive JSDoc so the
|
|
15
|
+
* config is understandable at a glance, whether you're using the engine as an
|
|
16
|
+
* npm package or reading the source.
|
|
17
|
+
*
|
|
18
|
+
* 3. **Minimal consumer knowledge.** Consumers only need to pass `Partial<EngineConfig>`.
|
|
19
|
+
* They don't need to replicate the full config shape, just the fields they
|
|
20
|
+
* want to override.
|
|
21
|
+
*
|
|
22
|
+
* @module Configuration
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Date-related configuration.
|
|
26
|
+
* Controls the bounds and formatting for date/time expression evaluation
|
|
27
|
+
* (e.g., `today + 20 days`, `last monday`).
|
|
28
|
+
*/
|
|
29
|
+
interface DateConfig {
|
|
30
|
+
/** Default offset in days for relative date calculations when no offset is specified */
|
|
31
|
+
readonly defaultOffsetDays: number;
|
|
32
|
+
/** Maximum allowed positive offset in years (safety limit) */
|
|
33
|
+
readonly maxOffsetYears: number;
|
|
34
|
+
/** Maximum allowed negative offset in years (safety limit) */
|
|
35
|
+
readonly minOffsetYears: number;
|
|
36
|
+
/** Default date string format for display (moment.js format string) */
|
|
37
|
+
readonly defaultFormat: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Dice-related configuration.
|
|
41
|
+
* Controls dice expression evaluation (e.g., `roll(1, 100)`, `3d6`).
|
|
42
|
+
*/
|
|
43
|
+
interface DiceConfig {
|
|
44
|
+
/** Default number of sides on a die when not specified */
|
|
45
|
+
readonly defaultSides: number;
|
|
46
|
+
/** Maximum allowed sides per die (prevents excessive allocation) */
|
|
47
|
+
readonly maxSides: number;
|
|
48
|
+
/** Maximum number of dice in a single roll expression */
|
|
49
|
+
readonly maxDice: number;
|
|
50
|
+
/** Default number of dice when not specified */
|
|
51
|
+
readonly defaultDice: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Performance-related configuration.
|
|
55
|
+
* Controls caching, timeouts, and processing limits to prevent runaway
|
|
56
|
+
* resource consumption on large documents.
|
|
57
|
+
*/
|
|
58
|
+
interface PerformanceConfig {
|
|
59
|
+
/**
|
|
60
|
+
* Maximum number of entries in {@link ExpressionEngine}'s bytecode cache
|
|
61
|
+
* (per-instance, keyed by expression text) before the oldest entry is
|
|
62
|
+
* evicted. Raise this for documents with many distinct expressions if
|
|
63
|
+
* repeated re-evaluation (e.g. scrolling) is re-parsing instead of
|
|
64
|
+
* hitting cache, bug fix (release hardening pass): this field used to
|
|
65
|
+
* be read nowhere; the cache size was a hardcoded, unconfigurable
|
|
66
|
+
* constant. Note this does NOT bound {@link LineCache}, which has no
|
|
67
|
+
* size limit of its own.
|
|
68
|
+
*/
|
|
69
|
+
readonly defaultCacheSize: number;
|
|
70
|
+
/** Maximum number of document lines processed in a single pass */
|
|
71
|
+
readonly maxDocumentLines: number;
|
|
72
|
+
/** Maximum time (ms) allowed for parsing a single expression before timeout */
|
|
73
|
+
readonly parseTimeoutMs: number;
|
|
74
|
+
/** Maximum time (ms) allowed for executing a single expression before timeout */
|
|
75
|
+
readonly executionTimeoutMs: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Validation / safety-limit configuration.
|
|
79
|
+
* Protects against runaway expressions that could cause excessive memory use
|
|
80
|
+
* or stack overflow. These limits are checked during lexing and parsing.
|
|
81
|
+
*/
|
|
82
|
+
/** Bounds on untrusted input: expression length and nesting depth. */
|
|
83
|
+
interface ValidationConfig {
|
|
84
|
+
/** Maximum expression length in characters. Prevents excessively long strings from entering the pipeline. */
|
|
85
|
+
readonly maxExpressionLength: number;
|
|
86
|
+
/** Maximum expression complexity score (`tokens + functionCalls×5 + nestingDepth×10`). Protects against deeply nested or combinatorially complex expressions. */
|
|
87
|
+
readonly maxComplexity: number;
|
|
88
|
+
/** Maximum parentheses nesting depth. Prevents stack overflow in the recursive-descent parser. */
|
|
89
|
+
readonly maxNestingDepth: number;
|
|
90
|
+
/**
|
|
91
|
+
* Auto-balance unmatched parentheses by appending missing closing parens
|
|
92
|
+
* or prepending missing opening parens. When disabled, unbalanced expressions
|
|
93
|
+
* cause parse errors instead of being silently corrected.
|
|
94
|
+
*
|
|
95
|
+
* Disabled by default for strict parsing. Enable for forgiving user input
|
|
96
|
+
* (e.g., chat-style calculators where users often omit closing parens).
|
|
97
|
+
* Has zero overhead when disabled, the O(n) paren-count scan is skipped.
|
|
98
|
+
*/
|
|
99
|
+
readonly autoBalanceParens: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Worker pool configuration.
|
|
103
|
+
* Controls the parallel execution workers used for batch evaluation.
|
|
104
|
+
*/
|
|
105
|
+
interface WorkerConfig {
|
|
106
|
+
/** Maximum number of concurrent Web Workers allowed */
|
|
107
|
+
readonly maxConcurrentWorkers: number;
|
|
108
|
+
/** Time (ms) a worker stays alive while idle before being terminated */
|
|
109
|
+
readonly idleTimeoutMs: number;
|
|
110
|
+
/** Maximum retry attempts for a failed worker operation */
|
|
111
|
+
readonly maxRetries: number;
|
|
112
|
+
/** Base backoff delay (ms) between retries (exponential backoff applied on top) */
|
|
113
|
+
readonly baseBackoffMs: number;
|
|
114
|
+
} /**
|
|
115
|
+
* Diagnostic / telemetry configuration.
|
|
116
|
+
* Controls the diagnostic event pipeline for profiling and debugging.
|
|
117
|
+
* All diagnostics are disabled by default for maximum production performance.
|
|
118
|
+
*/
|
|
119
|
+
interface DiagnosticConfig {
|
|
120
|
+
/** Master switch: enable the diagnostic pipeline (collectors receive events for all pipeline stages) */
|
|
121
|
+
readonly enabled: boolean;
|
|
122
|
+
/** Enable VM trace mode, emits per-opcode execution events (very verbose; disables some optimizations) */
|
|
123
|
+
readonly vmTraceEnabled: boolean;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Virtual Machine configuration.
|
|
127
|
+
* Controls the internal bytecode VM that executes compiled expressions.
|
|
128
|
+
*/
|
|
129
|
+
interface VMConfig {
|
|
130
|
+
/** Maximum stack depth (value slots) for VM execution, prevents stack overflow in recursive/pratt-parser generated bytecode */
|
|
131
|
+
readonly maxStackDepth: number;
|
|
132
|
+
/** Maximum opcodes executed per expression, halts runaway infinite loops */
|
|
133
|
+
readonly maxInstructions: number;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Complete engine configuration.
|
|
137
|
+
*
|
|
138
|
+
* Every field has a default in `DEFAULT_CONFIG`. To customize, pass a
|
|
139
|
+
* `Partial<EngineConfig>` when constructing `ExpressionEngine`. Only the
|
|
140
|
+
* sections/fields you supply are overridden; all others use their defaults.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* import { ExpressionEngine } from "solve-js";
|
|
145
|
+
*
|
|
146
|
+
* const engine = new ExpressionEngine("en", false, {
|
|
147
|
+
* validation: {
|
|
148
|
+
* maxExpressionLength: 1000,
|
|
149
|
+
* maxComplexity: 200,
|
|
150
|
+
* },
|
|
151
|
+
* // date, dice, performance, vm, worker, diagnostic all use defaults
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
interface EngineConfig {
|
|
156
|
+
/** Date/time expression evaluation bounds and formatting */
|
|
157
|
+
readonly date: DateConfig;
|
|
158
|
+
/** Dice roll expression controls */
|
|
159
|
+
readonly dice: DiceConfig;
|
|
160
|
+
/** Performance budgets and cache sizing */
|
|
161
|
+
readonly performance: PerformanceConfig;
|
|
162
|
+
/** Safety limits for expression complexity */
|
|
163
|
+
readonly validation: ValidationConfig;
|
|
164
|
+
/** Internal bytecode VM configuration */
|
|
165
|
+
readonly vm: VMConfig;
|
|
166
|
+
/** Parallel worker pool configuration */
|
|
167
|
+
readonly worker: WorkerConfig;
|
|
168
|
+
/** Diagnostic pipeline configuration */
|
|
169
|
+
readonly diagnostic: DiagnosticConfig;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Default configuration values
|
|
173
|
+
*/
|
|
174
|
+
declare const DEFAULT_CONFIG: EngineConfig;
|
|
175
|
+
/**
|
|
176
|
+
* Configuration manager for engine settings
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const configManager = new ConfigManager();
|
|
181
|
+
* configManager.set('performance.defaultCacheSize', 2000);
|
|
182
|
+
* const cacheSize = configManager.get('performance.defaultCacheSize');
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
declare class ConfigManager {
|
|
186
|
+
private config;
|
|
187
|
+
constructor(config?: Partial<EngineConfig>);
|
|
188
|
+
/**
|
|
189
|
+
* Get configuration value by path
|
|
190
|
+
*
|
|
191
|
+
* @param path - Dot-notation path to config value
|
|
192
|
+
* @returns Configuration value
|
|
193
|
+
*/
|
|
194
|
+
get<T>(path: string): T;
|
|
195
|
+
/**
|
|
196
|
+
* Set configuration value by path
|
|
197
|
+
*
|
|
198
|
+
* @param path - Dot-notation path to config value
|
|
199
|
+
* @param value - New value
|
|
200
|
+
*/
|
|
201
|
+
set<T>(path: string, value: T): void;
|
|
202
|
+
/**
|
|
203
|
+
* Get complete configuration
|
|
204
|
+
*/
|
|
205
|
+
getConfig(): EngineConfig;
|
|
206
|
+
/**
|
|
207
|
+
* Update multiple configuration values
|
|
208
|
+
*/
|
|
209
|
+
update(config: Partial<EngineConfig>): void;
|
|
210
|
+
/**
|
|
211
|
+
* Reset to default configuration
|
|
212
|
+
*/
|
|
213
|
+
reset(): void;
|
|
214
|
+
/**
|
|
215
|
+
* Validate configuration values
|
|
216
|
+
*/
|
|
217
|
+
validate(): ValidationResult;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Result type for {@link ConfigManager.validate}.
|
|
221
|
+
*/
|
|
222
|
+
interface ValidationResult {
|
|
223
|
+
valid: boolean;
|
|
224
|
+
error?: string;
|
|
225
|
+
warnings?: string[];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { ConfigManager as C, DEFAULT_CONFIG as D, type EngineConfig as E, type PerformanceConfig as P, type VMConfig as V, type WorkerConfig as W, type DateConfig as a, type DiagnosticConfig as b, type DiceConfig as c, type ValidationConfig as d, type ValidationResult as e };
|