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.
Files changed (253) hide show
  1. package/dist/BytecodeBuilder-3egMyuDi.d.cts +274 -0
  2. package/dist/BytecodeBuilder-3egMyuDi.d.ts +274 -0
  3. package/dist/Configuration-fVpd-HC-.d.cts +228 -0
  4. package/dist/Configuration-fVpd-HC-.d.ts +228 -0
  5. package/dist/EngineError-DvPSnhZi.d.cts +304 -0
  6. package/dist/EngineError-DvPSnhZi.d.ts +304 -0
  7. package/dist/Lexer-BJdhlnej.d.cts +531 -0
  8. package/dist/Lexer-D9l4Yrk2.d.ts +531 -0
  9. package/dist/NormalizerRule-BrVoVjmP.d.cts +163 -0
  10. package/dist/NormalizerRule-CEjf1FyD.d.ts +163 -0
  11. package/dist/PackageRegistry-D-Tv_7ca.d.cts +2572 -0
  12. package/dist/PackageRegistry-DaH4aIKP.d.ts +2572 -0
  13. package/dist/Parselet-CK8cQu2a.d.cts +299 -0
  14. package/dist/Parselet-ConOIdRO.d.ts +299 -0
  15. package/dist/ScopeManager-B5k0nk05.d.ts +559 -0
  16. package/dist/ScopeManager-CKfQtl7l.d.cts +559 -0
  17. package/dist/Token-0jpvUdPY.d.cts +245 -0
  18. package/dist/Token-0jpvUdPY.d.ts +245 -0
  19. package/dist/VMCheckpoints-BmDwIXgK.d.ts +171 -0
  20. package/dist/VMCheckpoints-CqFuLwrT.d.cts +171 -0
  21. package/dist/Value-KtAQNHur.d.cts +295 -0
  22. package/dist/Value-KtAQNHur.d.ts +295 -0
  23. package/dist/chunk-2RWAXT6O.js +3 -0
  24. package/dist/chunk-2RWAXT6O.js.map +1 -0
  25. package/dist/chunk-34RRD7PC.js +1492 -0
  26. package/dist/chunk-34RRD7PC.js.map +1 -0
  27. package/dist/chunk-3PPFLFH4.js +5097 -0
  28. package/dist/chunk-3PPFLFH4.js.map +1 -0
  29. package/dist/chunk-3VGDNEE3.js +84 -0
  30. package/dist/chunk-3VGDNEE3.js.map +1 -0
  31. package/dist/chunk-3YNVWKR2.cjs +370 -0
  32. package/dist/chunk-3YNVWKR2.cjs.map +1 -0
  33. package/dist/chunk-47LRVGOT.cjs +316 -0
  34. package/dist/chunk-47LRVGOT.cjs.map +1 -0
  35. package/dist/chunk-4MG4XKO2.js +1644 -0
  36. package/dist/chunk-4MG4XKO2.js.map +1 -0
  37. package/dist/chunk-4QADQTWS.js +2392 -0
  38. package/dist/chunk-4QADQTWS.js.map +1 -0
  39. package/dist/chunk-53B6KDDJ.cjs +1651 -0
  40. package/dist/chunk-53B6KDDJ.cjs.map +1 -0
  41. package/dist/chunk-5X2PTP6F.cjs +104 -0
  42. package/dist/chunk-5X2PTP6F.cjs.map +1 -0
  43. package/dist/chunk-5YEMOYSE.js +264 -0
  44. package/dist/chunk-5YEMOYSE.js.map +1 -0
  45. package/dist/chunk-64W6GLLZ.js +481 -0
  46. package/dist/chunk-64W6GLLZ.js.map +1 -0
  47. package/dist/chunk-6BKTCEUP.cjs +233 -0
  48. package/dist/chunk-6BKTCEUP.cjs.map +1 -0
  49. package/dist/chunk-6NTVRDQV.cjs +1642 -0
  50. package/dist/chunk-6NTVRDQV.cjs.map +1 -0
  51. package/dist/chunk-6RDSQURE.js +290 -0
  52. package/dist/chunk-6RDSQURE.js.map +1 -0
  53. package/dist/chunk-75JP4BZX.js +93 -0
  54. package/dist/chunk-75JP4BZX.js.map +1 -0
  55. package/dist/chunk-B7LXJ6LC.cjs +36 -0
  56. package/dist/chunk-B7LXJ6LC.cjs.map +1 -0
  57. package/dist/chunk-BVAR5J2F.js +257 -0
  58. package/dist/chunk-BVAR5J2F.js.map +1 -0
  59. package/dist/chunk-C4XZV6E7.cjs +269 -0
  60. package/dist/chunk-C4XZV6E7.cjs.map +1 -0
  61. package/dist/chunk-CCJPSHGI.cjs +40 -0
  62. package/dist/chunk-CCJPSHGI.cjs.map +1 -0
  63. package/dist/chunk-CLL7RUQV.cjs +316 -0
  64. package/dist/chunk-CLL7RUQV.cjs.map +1 -0
  65. package/dist/chunk-DM3LMRBC.js +329 -0
  66. package/dist/chunk-DM3LMRBC.js.map +1 -0
  67. package/dist/chunk-DUEZFTK2.js +38 -0
  68. package/dist/chunk-DUEZFTK2.js.map +1 -0
  69. package/dist/chunk-EBSPLUW4.cjs +489 -0
  70. package/dist/chunk-EBSPLUW4.cjs.map +1 -0
  71. package/dist/chunk-EHAHVROS.cjs +261 -0
  72. package/dist/chunk-EHAHVROS.cjs.map +1 -0
  73. package/dist/chunk-EIGTWK5N.js +167 -0
  74. package/dist/chunk-EIGTWK5N.js.map +1 -0
  75. package/dist/chunk-EPOXXJBK.js +96 -0
  76. package/dist/chunk-EPOXXJBK.js.map +1 -0
  77. package/dist/chunk-FEAIOR7N.cjs +91 -0
  78. package/dist/chunk-FEAIOR7N.cjs.map +1 -0
  79. package/dist/chunk-G535KJEG.js +312 -0
  80. package/dist/chunk-G535KJEG.js.map +1 -0
  81. package/dist/chunk-GCM5JHMX.js +88 -0
  82. package/dist/chunk-GCM5JHMX.js.map +1 -0
  83. package/dist/chunk-GOLDJNMZ.js +368 -0
  84. package/dist/chunk-GOLDJNMZ.js.map +1 -0
  85. package/dist/chunk-GW32KPCU.cjs +360 -0
  86. package/dist/chunk-GW32KPCU.cjs.map +1 -0
  87. package/dist/chunk-HTXVVJRA.cjs +1549 -0
  88. package/dist/chunk-HTXVVJRA.cjs.map +1 -0
  89. package/dist/chunk-HWSZJQCI.js +311 -0
  90. package/dist/chunk-HWSZJQCI.js.map +1 -0
  91. package/dist/chunk-IF532O7C.js +101 -0
  92. package/dist/chunk-IF532O7C.js.map +1 -0
  93. package/dist/chunk-J73SJHR3.cjs +2415 -0
  94. package/dist/chunk-J73SJHR3.cjs.map +1 -0
  95. package/dist/chunk-JBSYC7BB.cjs +7473 -0
  96. package/dist/chunk-JBSYC7BB.cjs.map +1 -0
  97. package/dist/chunk-KVILKGMS.js +228 -0
  98. package/dist/chunk-KVILKGMS.js.map +1 -0
  99. package/dist/chunk-LIPPNDBE.js +258 -0
  100. package/dist/chunk-LIPPNDBE.js.map +1 -0
  101. package/dist/chunk-LR7YASZF.cjs +172 -0
  102. package/dist/chunk-LR7YASZF.cjs.map +1 -0
  103. package/dist/chunk-M4N5GA5Z.cjs +309 -0
  104. package/dist/chunk-M4N5GA5Z.cjs.map +1 -0
  105. package/dist/chunk-M5LX5AOO.js +7459 -0
  106. package/dist/chunk-M5LX5AOO.js.map +1 -0
  107. package/dist/chunk-MZOVP3WI.cjs +96 -0
  108. package/dist/chunk-MZOVP3WI.cjs.map +1 -0
  109. package/dist/chunk-N5YFR4UP.cjs +10 -0
  110. package/dist/chunk-N5YFR4UP.cjs.map +1 -0
  111. package/dist/chunk-NGBBNL4K.cjs +4 -0
  112. package/dist/chunk-NGBBNL4K.cjs.map +1 -0
  113. package/dist/chunk-NH2O2AUR.js +146 -0
  114. package/dist/chunk-NH2O2AUR.js.map +1 -0
  115. package/dist/chunk-NLNDMWZC.js +31 -0
  116. package/dist/chunk-NLNDMWZC.js.map +1 -0
  117. package/dist/chunk-NMCRQP3Z.cjs +778 -0
  118. package/dist/chunk-NMCRQP3Z.cjs.map +1 -0
  119. package/dist/chunk-NMD5VRN4.cjs +1327 -0
  120. package/dist/chunk-NMD5VRN4.cjs.map +1 -0
  121. package/dist/chunk-OC6LTXYS.cjs +286 -0
  122. package/dist/chunk-OC6LTXYS.cjs.map +1 -0
  123. package/dist/chunk-OT6OJY7C.cjs +114 -0
  124. package/dist/chunk-OT6OJY7C.cjs.map +1 -0
  125. package/dist/chunk-PFSDGGYL.js +8 -0
  126. package/dist/chunk-PFSDGGYL.js.map +1 -0
  127. package/dist/chunk-QNJ4ACRT.cjs +155 -0
  128. package/dist/chunk-QNJ4ACRT.cjs.map +1 -0
  129. package/dist/chunk-QWY3VEZN.js +1637 -0
  130. package/dist/chunk-QWY3VEZN.js.map +1 -0
  131. package/dist/chunk-RFYD5TJE.js +111 -0
  132. package/dist/chunk-RFYD5TJE.js.map +1 -0
  133. package/dist/chunk-RIN643A3.js +354 -0
  134. package/dist/chunk-RIN643A3.js.map +1 -0
  135. package/dist/chunk-RZCWSXTA.cjs +5122 -0
  136. package/dist/chunk-RZCWSXTA.cjs.map +1 -0
  137. package/dist/chunk-SDGRK7EP.js +774 -0
  138. package/dist/chunk-SDGRK7EP.js.map +1 -0
  139. package/dist/chunk-VEKIWQ3F.cjs +39 -0
  140. package/dist/chunk-VEKIWQ3F.cjs.map +1 -0
  141. package/dist/chunk-WQTTOGXC.cjs +99 -0
  142. package/dist/chunk-WQTTOGXC.cjs.map +1 -0
  143. package/dist/chunk-X6K3HUOY.cjs +86 -0
  144. package/dist/chunk-X6K3HUOY.cjs.map +1 -0
  145. package/dist/chunk-XJCMXB2E.cjs +333 -0
  146. package/dist/chunk-XJCMXB2E.cjs.map +1 -0
  147. package/dist/chunk-XVWCOTR6.js +1324 -0
  148. package/dist/chunk-XVWCOTR6.js.map +1 -0
  149. package/dist/chunk-YLJ4XMA6.js +33 -0
  150. package/dist/chunk-YLJ4XMA6.js.map +1 -0
  151. package/dist/chunk-Z2XP767T.cjs +35 -0
  152. package/dist/chunk-Z2XP767T.cjs.map +1 -0
  153. package/dist/chunk-Z4X2RWOF.js +37 -0
  154. package/dist/chunk-Z4X2RWOF.js.map +1 -0
  155. package/dist/constants.cjs +22 -0
  156. package/dist/constants.cjs.map +1 -0
  157. package/dist/constants.d.cts +12 -0
  158. package/dist/constants.d.ts +12 -0
  159. package/dist/constants.js +5 -0
  160. package/dist/constants.js.map +1 -0
  161. package/dist/engine.cjs +79 -0
  162. package/dist/engine.cjs.map +1 -0
  163. package/dist/engine.d.cts +587 -0
  164. package/dist/engine.d.ts +587 -0
  165. package/dist/engine.js +34 -0
  166. package/dist/engine.js.map +1 -0
  167. package/dist/errors.cjs +81 -0
  168. package/dist/errors.cjs.map +1 -0
  169. package/dist/errors.d.cts +95 -0
  170. package/dist/errors.d.ts +95 -0
  171. package/dist/errors.js +4 -0
  172. package/dist/errors.js.map +1 -0
  173. package/dist/format.cjs +171 -0
  174. package/dist/format.cjs.map +1 -0
  175. package/dist/format.d.cts +51 -0
  176. package/dist/format.d.ts +51 -0
  177. package/dist/format.js +168 -0
  178. package/dist/format.js.map +1 -0
  179. package/dist/index.cjs +97 -0
  180. package/dist/index.cjs.map +1 -0
  181. package/dist/index.d.cts +152 -0
  182. package/dist/index.d.ts +152 -0
  183. package/dist/index.js +75 -0
  184. package/dist/index.js.map +1 -0
  185. package/dist/language.cjs +308 -0
  186. package/dist/language.cjs.map +1 -0
  187. package/dist/language.d.cts +110 -0
  188. package/dist/language.d.ts +110 -0
  189. package/dist/language.js +287 -0
  190. package/dist/language.js.map +1 -0
  191. package/dist/lexer.cjs +64 -0
  192. package/dist/lexer.cjs.map +1 -0
  193. package/dist/lexer.d.cts +56 -0
  194. package/dist/lexer.d.ts +56 -0
  195. package/dist/lexer.js +11 -0
  196. package/dist/lexer.js.map +1 -0
  197. package/dist/normalizer.cjs +40 -0
  198. package/dist/normalizer.cjs.map +1 -0
  199. package/dist/normalizer.d.cts +364 -0
  200. package/dist/normalizer.d.ts +364 -0
  201. package/dist/normalizer.js +11 -0
  202. package/dist/normalizer.js.map +1 -0
  203. package/dist/packages.cjs +121 -0
  204. package/dist/packages.cjs.map +1 -0
  205. package/dist/packages.d.cts +691 -0
  206. package/dist/packages.d.ts +691 -0
  207. package/dist/packages.js +24 -0
  208. package/dist/packages.js.map +1 -0
  209. package/dist/parser.cjs +55 -0
  210. package/dist/parser.cjs.map +1 -0
  211. package/dist/parser.d.cts +46 -0
  212. package/dist/parser.d.ts +46 -0
  213. package/dist/parser.js +10 -0
  214. package/dist/parser.js.map +1 -0
  215. package/dist/pipeline-CrsRPmsv.d.ts +285 -0
  216. package/dist/pipeline-DPUQt7yL.d.cts +285 -0
  217. package/dist/resolvers.cjs +13 -0
  218. package/dist/resolvers.cjs.map +1 -0
  219. package/dist/resolvers.d.cts +111 -0
  220. package/dist/resolvers.d.ts +111 -0
  221. package/dist/resolvers.js +4 -0
  222. package/dist/resolvers.js.map +1 -0
  223. package/dist/services.cjs +21 -0
  224. package/dist/services.cjs.map +1 -0
  225. package/dist/services.d.cts +30 -0
  226. package/dist/services.d.ts +30 -0
  227. package/dist/services.js +4 -0
  228. package/dist/services.js.map +1 -0
  229. package/dist/uom.cjs +56 -0
  230. package/dist/uom.cjs.map +1 -0
  231. package/dist/uom.d.cts +224 -0
  232. package/dist/uom.d.ts +224 -0
  233. package/dist/uom.js +11 -0
  234. package/dist/uom.js.map +1 -0
  235. package/dist/utilities.cjs +32 -0
  236. package/dist/utilities.cjs.map +1 -0
  237. package/dist/utilities.d.cts +113 -0
  238. package/dist/utilities.d.ts +113 -0
  239. package/dist/utilities.js +7 -0
  240. package/dist/utilities.js.map +1 -0
  241. package/dist/variables.cjs +17 -0
  242. package/dist/variables.cjs.map +1 -0
  243. package/dist/variables.d.cts +87 -0
  244. package/dist/variables.d.ts +87 -0
  245. package/dist/variables.js +4 -0
  246. package/dist/variables.js.map +1 -0
  247. package/dist/vm.cjs +284 -0
  248. package/dist/vm.cjs.map +1 -0
  249. package/dist/vm.d.cts +68 -0
  250. package/dist/vm.d.ts +68 -0
  251. package/dist/vm.js +194 -0
  252. package/dist/vm.js.map +1 -0
  253. 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 };