solve-engine 1.0.1 → 1.1.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.
Files changed (237) hide show
  1. package/dist/{BytecodeBuilder-B0xskcv5.d.cts → BytecodeBuilder-Bp9xeTmX.d.cts} +4 -0
  2. package/dist/{BytecodeBuilder-B0xskcv5.d.ts → BytecodeBuilder-Bp9xeTmX.d.ts} +4 -0
  3. package/dist/{Configuration-B-G5gTRn.d.cts → Configuration-C9W8tJv_.d.cts} +53 -1
  4. package/dist/{Configuration-B-G5gTRn.d.ts → Configuration-C9W8tJv_.d.ts} +53 -1
  5. package/dist/{EngineError-LU7W7AgI.d.cts → EngineError-B61GS1jp.d.cts} +14 -0
  6. package/dist/{EngineError-LU7W7AgI.d.ts → EngineError-B61GS1jp.d.ts} +14 -0
  7. package/dist/FormattingSettings-CJHyxcYu.d.cts +27 -0
  8. package/dist/FormattingSettings-CJHyxcYu.d.ts +27 -0
  9. package/dist/{Lexer-D78E2yDW.d.cts → Lexer-BOs7euZe.d.cts} +58 -1
  10. package/dist/{Lexer-BN5mt30n.d.ts → Lexer-CSI_lwbW.d.ts} +58 -1
  11. package/dist/PackageCompatibility-B-7rK1TD.d.cts +76 -0
  12. package/dist/PackageCompatibility-Dh59eF-X.d.ts +76 -0
  13. package/dist/{PackageRegistry-B37mRvvz.d.cts → PackageRegistry-BHWJP83F.d.cts} +449 -11
  14. package/dist/{PackageRegistry-DCUEzbQt.d.ts → PackageRegistry-_8rDlvxI.d.ts} +449 -11
  15. package/dist/{Parselet-BaySkMV3.d.ts → Parselet-BBT8riYh.d.ts} +12 -3
  16. package/dist/{Parselet-DuI1Pjiq.d.cts → Parselet-BHcgK9S7.d.cts} +12 -3
  17. package/dist/{ScopeManager-B6GzdhVG.d.cts → ScopeManager-8vf02dwj.d.cts} +56 -5
  18. package/dist/{ScopeManager-udv4Twwq.d.ts → ScopeManager-CxA24W5n.d.ts} +56 -5
  19. package/dist/{Token-BzG5G4ja.d.cts → Token-B1hdkedD.d.cts} +9 -0
  20. package/dist/{Token-BzG5G4ja.d.ts → Token-B1hdkedD.d.ts} +9 -0
  21. package/dist/{TokenNormalizer-t_GotBxr.d.ts → TokenNormalizer-C6VzZgHa.d.ts} +1 -1
  22. package/dist/{TokenNormalizer-DGVa24Q-.d.cts → TokenNormalizer-DRc1Js1V.d.cts} +1 -1
  23. package/dist/{VMCheckpoints-DwLjivM7.d.cts → VMCheckpoints-ELYqITdF.d.cts} +3 -3
  24. package/dist/{VMCheckpoints-BiaIlOOY.d.ts → VMCheckpoints-MK--EBH2.d.ts} +3 -3
  25. package/dist/{Value-CXJqDH9J.d.cts → Value-BUi1RA3S.d.cts} +124 -5
  26. package/dist/{Value-CXJqDH9J.d.ts → Value-BUi1RA3S.d.ts} +124 -5
  27. package/dist/WorkerError-_-RkoQ5P.d.ts +75 -0
  28. package/dist/WorkerError-gzmaopj2.d.cts +75 -0
  29. package/dist/{chunk-GQCOSXMG.js → chunk-267JPOTF.js} +43 -5
  30. package/dist/chunk-267JPOTF.js.map +1 -0
  31. package/dist/{chunk-JMXUNXQS.cjs → chunk-2TZKENDH.cjs} +51 -8
  32. package/dist/chunk-2TZKENDH.cjs.map +1 -0
  33. package/dist/chunk-3OWCDIPN.js +215 -0
  34. package/dist/chunk-3OWCDIPN.js.map +1 -0
  35. package/dist/{chunk-VB37OC6I.js → chunk-4D6NIHE2.js} +40 -3
  36. package/dist/chunk-4D6NIHE2.js.map +1 -0
  37. package/dist/{chunk-TY3TLZAW.cjs → chunk-536WPM2V.cjs} +18 -2
  38. package/dist/chunk-536WPM2V.cjs.map +1 -0
  39. package/dist/chunk-5HRB36DK.js +405 -0
  40. package/dist/chunk-5HRB36DK.js.map +1 -0
  41. package/dist/chunk-5ON7PUAZ.js +12 -0
  42. package/dist/chunk-5ON7PUAZ.js.map +1 -0
  43. package/dist/{chunk-KV7UW6T6.js → chunk-7KYSUDQO.js} +12 -5
  44. package/dist/chunk-7KYSUDQO.js.map +1 -0
  45. package/dist/{chunk-6WFMPTGB.cjs → chunk-7ZX6B7SY.cjs} +774 -528
  46. package/dist/chunk-7ZX6B7SY.cjs.map +1 -0
  47. package/dist/chunk-ALYRJ72W.cjs +434 -0
  48. package/dist/chunk-ALYRJ72W.cjs.map +1 -0
  49. package/dist/{chunk-5KMIY374.cjs → chunk-B4HBEFTB.cjs} +17 -2
  50. package/dist/chunk-B4HBEFTB.cjs.map +1 -0
  51. package/dist/chunk-B7NLZMQ3.cjs +74 -0
  52. package/dist/chunk-B7NLZMQ3.cjs.map +1 -0
  53. package/dist/{chunk-UQ3UIZJC.js → chunk-BLI4NIQY.js} +6 -2
  54. package/dist/chunk-BLI4NIQY.js.map +1 -0
  55. package/dist/{chunk-BHTNFEGZ.cjs → chunk-C75AFGVD.cjs} +11 -11
  56. package/dist/{chunk-BHTNFEGZ.cjs.map → chunk-C75AFGVD.cjs.map} +1 -1
  57. package/dist/{chunk-G535KJEG.js → chunk-CCBZZQAE.js} +2 -2
  58. package/dist/{chunk-G535KJEG.js.map → chunk-CCBZZQAE.js.map} +1 -1
  59. package/dist/chunk-CKQMXMHR.cjs +219 -0
  60. package/dist/chunk-CKQMXMHR.cjs.map +1 -0
  61. package/dist/{chunk-PFUESQTW.cjs → chunk-EJ3ILXX6.cjs} +48 -2
  62. package/dist/chunk-EJ3ILXX6.cjs.map +1 -0
  63. package/dist/{chunk-526PMQOA.js → chunk-ENKKJYD3.js} +10 -4
  64. package/dist/chunk-ENKKJYD3.js.map +1 -0
  65. package/dist/{chunk-5X2PTP6F.cjs → chunk-ENRIK36Q.cjs} +2 -12
  66. package/dist/chunk-ENRIK36Q.cjs.map +1 -0
  67. package/dist/{chunk-3D7V24DG.js → chunk-ERCOHGXD.js} +17 -2
  68. package/dist/chunk-ERCOHGXD.js.map +1 -0
  69. package/dist/{chunk-IF532O7C.js → chunk-FD5ZZHEU.js} +3 -12
  70. package/dist/chunk-FD5ZZHEU.js.map +1 -0
  71. package/dist/{chunk-TBN7DEHO.js → chunk-G7Z4HJQA.js} +11 -5
  72. package/dist/chunk-G7Z4HJQA.js.map +1 -0
  73. package/dist/{chunk-QY25VWBF.js → chunk-GQMUHVE3.js} +142 -6
  74. package/dist/chunk-GQMUHVE3.js.map +1 -0
  75. package/dist/chunk-GUG7SNSV.js +1764 -0
  76. package/dist/chunk-GUG7SNSV.js.map +1 -0
  77. package/dist/{chunk-UM6BVY2S.cjs → chunk-HIQ5HSZL.cjs} +175 -43
  78. package/dist/chunk-HIQ5HSZL.cjs.map +1 -0
  79. package/dist/{chunk-HVQFNJKE.cjs → chunk-HVRVSI2Z.cjs} +104 -86
  80. package/dist/chunk-HVRVSI2Z.cjs.map +1 -0
  81. package/dist/{chunk-3LAEG75D.js → chunk-I4GAWIPW.js} +24 -6
  82. package/dist/chunk-I4GAWIPW.js.map +1 -0
  83. package/dist/{chunk-PA4VC73I.cjs → chunk-J45BCEZ4.cjs} +33 -27
  84. package/dist/chunk-J45BCEZ4.cjs.map +1 -0
  85. package/dist/{chunk-V5PYO44Y.js → chunk-JIPATHVY.js} +1853 -2638
  86. package/dist/chunk-JIPATHVY.js.map +1 -0
  87. package/dist/{chunk-YPPPYLSR.js → chunk-JJIXHXFQ.js} +5 -5
  88. package/dist/{chunk-YPPPYLSR.js.map → chunk-JJIXHXFQ.js.map} +1 -1
  89. package/dist/chunk-L2TE7PMO.cjs +14 -0
  90. package/dist/chunk-L2TE7PMO.cjs.map +1 -0
  91. package/dist/{chunk-B7TLZABL.cjs → chunk-MG6Q3DUO.cjs} +1962 -2746
  92. package/dist/chunk-MG6Q3DUO.cjs.map +1 -0
  93. package/dist/{chunk-R3PY4G7J.js → chunk-MVTOCRV2.js} +48 -3
  94. package/dist/chunk-MVTOCRV2.js.map +1 -0
  95. package/dist/{chunk-Y7FT4IQT.js → chunk-NKW7LKYU.js} +266 -28
  96. package/dist/chunk-NKW7LKYU.js.map +1 -0
  97. package/dist/{chunk-O3ANBHSA.js → chunk-NNQ2TYDF.js} +123 -5
  98. package/dist/chunk-NNQ2TYDF.js.map +1 -0
  99. package/dist/{chunk-5F4C26RU.js → chunk-OADDUPT3.js} +4 -4
  100. package/dist/{chunk-5F4C26RU.js.map → chunk-OADDUPT3.js.map} +1 -1
  101. package/dist/{chunk-3AFRJYP4.cjs → chunk-OTN6SZOD.cjs} +1868 -393
  102. package/dist/chunk-OTN6SZOD.cjs.map +1 -0
  103. package/dist/{chunk-5LI5EPGJ.cjs → chunk-QFTDTX6K.cjs} +40 -3
  104. package/dist/chunk-QFTDTX6K.cjs.map +1 -0
  105. package/dist/{chunk-HMOISHXR.js → chunk-RRLHC37V.js} +1530 -57
  106. package/dist/chunk-RRLHC37V.js.map +1 -0
  107. package/dist/chunk-SNHVVOJK.cjs +1768 -0
  108. package/dist/chunk-SNHVVOJK.cjs.map +1 -0
  109. package/dist/{chunk-HDP7VK3C.cjs → chunk-SRGQ72IR.cjs} +649 -349
  110. package/dist/chunk-SRGQ72IR.cjs.map +1 -0
  111. package/dist/{chunk-4B2CNWQU.cjs → chunk-SSV46KFA.cjs} +14 -7
  112. package/dist/chunk-SSV46KFA.cjs.map +1 -0
  113. package/dist/{chunk-AJA6LUI7.js → chunk-UO6BUV6K.js} +18 -2
  114. package/dist/chunk-UO6BUV6K.js.map +1 -0
  115. package/dist/chunk-WWQEY7BV.js +67 -0
  116. package/dist/chunk-WWQEY7BV.js.map +1 -0
  117. package/dist/{chunk-5WVP4YHP.js → chunk-WXEHD6TT.js} +333 -33
  118. package/dist/chunk-WXEHD6TT.js.map +1 -0
  119. package/dist/{chunk-47LRVGOT.cjs → chunk-XA4CKRML.cjs} +2 -2
  120. package/dist/{chunk-47LRVGOT.cjs.map → chunk-XA4CKRML.cjs.map} +1 -1
  121. package/dist/{chunk-6KFYJ6TD.cjs → chunk-XIYYHA65.cjs} +6 -2
  122. package/dist/chunk-XIYYHA65.cjs.map +1 -0
  123. package/dist/{chunk-KBSXGXPM.cjs → chunk-XJGJCF2R.cjs} +6 -6
  124. package/dist/{chunk-KBSXGXPM.cjs.map → chunk-XJGJCF2R.cjs.map} +1 -1
  125. package/dist/{chunk-YWQ6V4ZN.cjs → chunk-YTIYVHL7.cjs} +211 -75
  126. package/dist/chunk-YTIYVHL7.cjs.map +1 -0
  127. package/dist/{chunk-TMA4RCEN.js → chunk-Z7XGGLI2.js} +3 -3
  128. package/dist/{chunk-TMA4RCEN.js.map → chunk-Z7XGGLI2.js.map} +1 -1
  129. package/dist/{chunk-A2N2GFCG.cjs → chunk-ZVTWQLK4.cjs} +10 -10
  130. package/dist/{chunk-A2N2GFCG.cjs.map → chunk-ZVTWQLK4.cjs.map} +1 -1
  131. package/dist/{chunk-2XLQPQKI.cjs → chunk-ZXCESUJS.cjs} +15 -9
  132. package/dist/chunk-ZXCESUJS.cjs.map +1 -0
  133. package/dist/constants.cjs +5 -5
  134. package/dist/constants.d.cts +1 -1
  135. package/dist/constants.d.ts +1 -1
  136. package/dist/constants.js +2 -2
  137. package/dist/engine.cjs +52 -35
  138. package/dist/engine.d.cts +13 -13
  139. package/dist/engine.d.ts +13 -13
  140. package/dist/engine.js +26 -21
  141. package/dist/errors.cjs +44 -19
  142. package/dist/errors.d.cts +3 -2
  143. package/dist/errors.d.ts +3 -2
  144. package/dist/errors.js +2 -1
  145. package/dist/format.cjs +19 -169
  146. package/dist/format.cjs.map +1 -1
  147. package/dist/format.d.cts +18 -26
  148. package/dist/format.d.ts +18 -26
  149. package/dist/format.js +7 -171
  150. package/dist/format.js.map +1 -1
  151. package/dist/index.cjs +250 -31
  152. package/dist/index.cjs.map +1 -1
  153. package/dist/index.d.cts +110 -74
  154. package/dist/index.d.ts +110 -74
  155. package/dist/index.js +228 -23
  156. package/dist/index.js.map +1 -1
  157. package/dist/language.cjs +9 -9
  158. package/dist/language.d.cts +12 -12
  159. package/dist/language.d.ts +12 -12
  160. package/dist/language.js +3 -3
  161. package/dist/lexer.cjs +16 -16
  162. package/dist/lexer.d.cts +3 -3
  163. package/dist/lexer.d.ts +3 -3
  164. package/dist/lexer.js +5 -5
  165. package/dist/normalizer.cjs +10 -10
  166. package/dist/normalizer.d.cts +3 -3
  167. package/dist/normalizer.d.ts +3 -3
  168. package/dist/normalizer.js +4 -4
  169. package/dist/packages.cjs +45 -36
  170. package/dist/packages.d.cts +135 -31
  171. package/dist/packages.d.ts +135 -31
  172. package/dist/packages.js +14 -13
  173. package/dist/parser.cjs +16 -16
  174. package/dist/parser.d.cts +6 -5
  175. package/dist/parser.d.ts +6 -5
  176. package/dist/parser.js +6 -6
  177. package/dist/{pipeline-BEb3hujr.d.cts → pipeline-CtfJtPQc.d.cts} +3 -3
  178. package/dist/{pipeline-B6k5lCB7.d.ts → pipeline-DCd5M6Gk.d.ts} +3 -3
  179. package/dist/resolvers.d.cts +3 -3
  180. package/dist/resolvers.d.ts +3 -3
  181. package/dist/testing.cjs +478 -0
  182. package/dist/testing.cjs.map +1 -0
  183. package/dist/testing.d.cts +271 -0
  184. package/dist/testing.d.ts +271 -0
  185. package/dist/testing.js +470 -0
  186. package/dist/testing.js.map +1 -0
  187. package/dist/uom.cjs +16 -16
  188. package/dist/uom.d.cts +3 -3
  189. package/dist/uom.d.ts +3 -3
  190. package/dist/uom.js +6 -6
  191. package/dist/utilities.cjs +6 -5
  192. package/dist/utilities.js +2 -1
  193. package/dist/vm.cjs +34 -34
  194. package/dist/vm.d.cts +8 -8
  195. package/dist/vm.d.ts +8 -8
  196. package/dist/vm.js +9 -9
  197. package/dist/worker.cjs +493 -0
  198. package/dist/worker.cjs.map +1 -0
  199. package/dist/worker.d.cts +509 -0
  200. package/dist/worker.d.ts +509 -0
  201. package/dist/worker.js +484 -0
  202. package/dist/worker.js.map +1 -0
  203. package/package.json +21 -1
  204. package/dist/chunk-2XLQPQKI.cjs.map +0 -1
  205. package/dist/chunk-3AFRJYP4.cjs.map +0 -1
  206. package/dist/chunk-3D7V24DG.js.map +0 -1
  207. package/dist/chunk-3LAEG75D.js.map +0 -1
  208. package/dist/chunk-4B2CNWQU.cjs.map +0 -1
  209. package/dist/chunk-526PMQOA.js.map +0 -1
  210. package/dist/chunk-5KMIY374.cjs.map +0 -1
  211. package/dist/chunk-5LI5EPGJ.cjs.map +0 -1
  212. package/dist/chunk-5WVP4YHP.js.map +0 -1
  213. package/dist/chunk-5X2PTP6F.cjs.map +0 -1
  214. package/dist/chunk-6KFYJ6TD.cjs.map +0 -1
  215. package/dist/chunk-6WFMPTGB.cjs.map +0 -1
  216. package/dist/chunk-AJA6LUI7.js.map +0 -1
  217. package/dist/chunk-B7TLZABL.cjs.map +0 -1
  218. package/dist/chunk-GQCOSXMG.js.map +0 -1
  219. package/dist/chunk-HDP7VK3C.cjs.map +0 -1
  220. package/dist/chunk-HMOISHXR.js.map +0 -1
  221. package/dist/chunk-HVQFNJKE.cjs.map +0 -1
  222. package/dist/chunk-IF532O7C.js.map +0 -1
  223. package/dist/chunk-JMXUNXQS.cjs.map +0 -1
  224. package/dist/chunk-KV7UW6T6.js.map +0 -1
  225. package/dist/chunk-O3ANBHSA.js.map +0 -1
  226. package/dist/chunk-PA4VC73I.cjs.map +0 -1
  227. package/dist/chunk-PFUESQTW.cjs.map +0 -1
  228. package/dist/chunk-QY25VWBF.js.map +0 -1
  229. package/dist/chunk-R3PY4G7J.js.map +0 -1
  230. package/dist/chunk-TBN7DEHO.js.map +0 -1
  231. package/dist/chunk-TY3TLZAW.cjs.map +0 -1
  232. package/dist/chunk-UM6BVY2S.cjs.map +0 -1
  233. package/dist/chunk-UQ3UIZJC.js.map +0 -1
  234. package/dist/chunk-V5PYO44Y.js.map +0 -1
  235. package/dist/chunk-VB37OC6I.js.map +0 -1
  236. package/dist/chunk-Y7FT4IQT.js.map +0 -1
  237. package/dist/chunk-YWQ6V4ZN.cjs.map +0 -1
@@ -0,0 +1,509 @@
1
+ import { E as EngineConfig } from './Configuration-C9W8tJv_.cjs';
2
+ import { U as UnifiedParsingOptions, I as IEnginePackage, N as ParsedLine, O as ParsingResult } from './PackageRegistry-BHWJP83F.cjs';
3
+ import { F as FormattingSettings } from './FormattingSettings-CJHyxcYu.cjs';
4
+ import { E as EngineError } from './EngineError-B61GS1jp.cjs';
5
+ import { b as ValueType, f as ColourFormat, V as Value } from './Value-BUi1RA3S.cjs';
6
+ import { a as DiagnosticReportJSON } from './pipeline-CtfJtPQc.cjs';
7
+ import { S as SerializedEngineError } from './WorkerError-gzmaopj2.cjs';
8
+ import './Parselet-BHcgK9S7.cjs';
9
+ import './BytecodeBuilder-Bp9xeTmX.cjs';
10
+ import './Token-B1hdkedD.cjs';
11
+ import './variables.cjs';
12
+ import './Lexer-BOs7euZe.cjs';
13
+ import './resolvers.cjs';
14
+ import '@tanstack/query-core';
15
+ import './TokenNormalizer-DRc1Js1V.cjs';
16
+ import './ScopeManager-8vf02dwj.cjs';
17
+
18
+ /**
19
+ * The seam between the harness and whatever actually carries messages.
20
+ *
21
+ * Both the client (`worker/client.ts`) and the runtime (`worker/runtime.ts`)
22
+ * talk to a {@link WorkerTransport} and nothing more, so the same code drives a
23
+ * browser `Worker`, a Node `worker_threads` port, or an in-process pair. The
24
+ * three factory functions below adapt each of those onto the interface; a host
25
+ * with a transport this file does not cover can implement the three methods
26
+ * directly.
27
+ */
28
+ /**
29
+ * A bidirectional message channel with a single receive handler.
30
+ *
31
+ * `onMessage` registers the one handler the harness needs; calling it again
32
+ * replaces the previous handler. `terminate` tears the channel down and is safe
33
+ * to call more than once.
34
+ */
35
+ interface WorkerTransport {
36
+ /** Send one message to the other end. The message must be clone-safe. */
37
+ postMessage(message: unknown): void;
38
+ /** Register the handler that receives messages from the other end. */
39
+ onMessage(handler: (message: unknown) => void): void;
40
+ /** Tear the channel down. Idempotent. */
41
+ terminate(): void;
42
+ }
43
+ /**
44
+ * A pair of linked in-process transports.
45
+ *
46
+ * `client` and `host` are two ends of one channel: a message posted on either
47
+ * is cloned at post time and delivered to the other on a microtask, so delivery
48
+ * is asynchronous (as a real worker's is) but deterministic (no timers, no I/O).
49
+ * Wire `client` into {@link createWorkerEngine} and `host` into
50
+ * {@link startWorkerRuntime} to run the whole protocol, DTO serialisation and
51
+ * cancellation included, without a second thread. This is the transport tests
52
+ * use, and a fit for a host that wants the message-passing shape on one thread.
53
+ */
54
+ declare function createLinkedTransports(): {
55
+ client: WorkerTransport;
56
+ host: WorkerTransport;
57
+ };
58
+ /** The `postMessage`/`onmessage`/event-listener shape a browser `Worker`, a worker's `self`, or a DOM `MessagePort` presents. */
59
+ interface EventTargetLike {
60
+ postMessage(message: unknown): void;
61
+ addEventListener?(type: "message", handler: (event: {
62
+ data: unknown;
63
+ }) => void): void;
64
+ onmessage?: ((event: {
65
+ data: unknown;
66
+ }) => void) | null;
67
+ terminate?(): void;
68
+ close?(): void;
69
+ start?(): void;
70
+ }
71
+ /**
72
+ * Adapt a browser-style message target onto a {@link WorkerTransport}.
73
+ *
74
+ * Covers the main-side `Worker`, the worker global `self`, and a DOM
75
+ * `MessagePort`: each posts with `postMessage` and receives a `MessageEvent`
76
+ * whose `data` is the payload. A `MessagePort` is `start`ed here so it begins
77
+ * dispatching. On the main side pass a `Worker`; inside a browser worker pass
78
+ * `self`.
79
+ */
80
+ declare function eventTargetTransport(target: EventTargetLike): WorkerTransport;
81
+ /** The `postMessage`/`on("message")` shape a Node `worker_threads` `Worker`, `parentPort`, or `MessagePort` presents. */
82
+ interface MessagePortLike {
83
+ postMessage(message: unknown): void;
84
+ on(event: "message", handler: (message: unknown) => void): void;
85
+ terminate?(): void;
86
+ close?(): void;
87
+ }
88
+ /**
89
+ * Adapt a Node `worker_threads` port onto a {@link WorkerTransport}.
90
+ *
91
+ * Covers the main-side `Worker`, the worker's `parentPort`, and a
92
+ * `worker_threads` `MessagePort`: each posts with `postMessage` and emits a
93
+ * `"message"` event whose argument IS the payload (no `.data` wrapper, unlike
94
+ * the DOM). On the main side pass the `Worker`; inside the worker pass
95
+ * `parentPort`.
96
+ */
97
+ declare function messagePortTransport(port: MessagePortLike): WorkerTransport;
98
+
99
+ /**
100
+ * The serialisable result shapes the worker harness posts back across the
101
+ * boundary, one clone-safe projection per public result type.
102
+ *
103
+ * A raw {@link Value} cannot be posted: it carries `bigint`, class-instance
104
+ * matrix cells, symbolic trees, and the exact-decimal/rational sidecars, none
105
+ * of which structured cloning reproduces faithfully (and `bigint` alone breaks
106
+ * `JSON.stringify`). These interfaces are what crosses instead. Every field is
107
+ * a string, number, boolean, or an object of those, so a whole
108
+ * {@link SerializedParsingResult} survives both `structuredClone` (what
109
+ * `postMessage` uses) and `JSON` (what a host may cache or log), which is the
110
+ * property `worker/serialize.ts` is built to guarantee.
111
+ */
112
+
113
+ /**
114
+ * A matrix flattened for transport.
115
+ *
116
+ * `cells` is column-major, the same order as {@link MatrixData.data}, so a host
117
+ * indexes it identically. Finite numeric and boolean cells pass through as
118
+ * themselves; a symbolic cell (a free-variable algebraic entry) becomes its
119
+ * formatted string, since a `SymbolicNode` is a class instance that would not
120
+ * survive the clone; and a non-finite numeric cell (`Infinity`/`-Infinity`/`NaN`,
121
+ * from e.g. a `[1/0, 2]`) becomes the same string tag the scalar
122
+ * {@link SerializedValue.nonFinite} uses, because a raw non-finite number does
123
+ * not survive `JSON` (it becomes `null`). A host reads a numeric string cell
124
+ * back with `Number(cell)`.
125
+ */
126
+ interface SerializedMatrix {
127
+ rows: number;
128
+ cols: number;
129
+ cells: Array<number | boolean | string>;
130
+ hasSymbolic: boolean;
131
+ }
132
+ /**
133
+ * A single evaluated value, projected onto clone-safe fields.
134
+ *
135
+ * `text` is the formatted display string a host renders, and `number` is the
136
+ * numeric reading ({@link Value.toNumber}), present for every type (0 where a
137
+ * value has no numeric meaning, matching the engine's own convention). The
138
+ * type-specific fields below carry the rest of the payload where it does not
139
+ * fit in a plain number: `bigint` as a base-ten string, `matrix` and `range`
140
+ * as their own shapes.
141
+ */
142
+ interface SerializedValue {
143
+ /** The {@link ValueType} discriminant (a number), so a host can branch on the kind. */
144
+ type: ValueType;
145
+ /** The formatted display string, what a host renders against the line. */
146
+ text: string;
147
+ /**
148
+ * The numeric reading via {@link Value.toNumber}: 0 for non-numeric types.
149
+ * Always finite so the DTO survives `JSON` (which turns `Infinity`/`NaN` into
150
+ * `null`): when the true reading is non-finite this is 0 and {@link nonFinite}
151
+ * names the real value. Read `nonFinite ? Number(nonFinite) : number` to
152
+ * recover it.
153
+ */
154
+ number: number;
155
+ /**
156
+ * Set only when the numeric reading is non-finite (`1/0`, `0/0`, an overflow),
157
+ * to a string a host turns back into the value with `Number(...)`. Carried
158
+ * separately because a non-finite number cannot cross `JSON`; see {@link number}.
159
+ */
160
+ nonFinite?: "Infinity" | "-Infinity" | "NaN";
161
+ /** Unit annotation for unit-of-measurement and non-decimal-base values, when present. */
162
+ unit?: string;
163
+ /** Base-ten string for a `bigint` payload, so no `BigInt` ever crosses `JSON`. */
164
+ bigint?: string;
165
+ /** Matrix shape and cells, present only for {@link ValueType.Matrix}. */
166
+ matrix?: SerializedMatrix;
167
+ /** Inclusive integer range bounds, present only for {@link ValueType.Range}. */
168
+ range?: {
169
+ min: number;
170
+ max: number;
171
+ };
172
+ /**
173
+ * Colour payload, present only for {@link ValueType.Colour}. `hex` is the
174
+ * canonical `#rrggbb`/`#rrggbbaa`; `r`,`g`,`b` are 0-255, `a` is 0-1;
175
+ * `format` is the authored form; `css` is a render-ready CSS string, so a
176
+ * host draws a swatch (e.g. `background: css`) with no recomputation.
177
+ */
178
+ colour?: {
179
+ hex: string;
180
+ r: number;
181
+ g: number;
182
+ b: number;
183
+ a: number;
184
+ format: ColourFormat;
185
+ css: string;
186
+ };
187
+ /** Whether an async fallback timed out, carried through when the engine set it. */
188
+ timedOut?: boolean;
189
+ }
190
+ /**
191
+ * One inline solve and its serialised result, mirroring
192
+ * {@link InlineSolvePosition} with the live `Value` replaced by a
193
+ * {@link SerializedValue}.
194
+ */
195
+ interface SerializedInlineSolve {
196
+ start: number;
197
+ end: number;
198
+ expression: string;
199
+ lineNumber: number;
200
+ columnNumber: number;
201
+ result: SerializedValue | null;
202
+ error: string | null;
203
+ }
204
+ /**
205
+ * One parsed line, mirroring {@link ParsedLine} with every live `Value`
206
+ * replaced by a {@link SerializedValue}.
207
+ */
208
+ interface SerializedParsedLine {
209
+ lineNumber: number;
210
+ text: string;
211
+ startPosition: number;
212
+ endPosition: number;
213
+ isEmpty: boolean;
214
+ hasInlineSolves: boolean;
215
+ inlineSolves: SerializedInlineSolve[];
216
+ expression: string | null;
217
+ result: SerializedValue | null;
218
+ error: string | null;
219
+ }
220
+ /**
221
+ * A whole parsed document, mirroring {@link ParsingResult}.
222
+ *
223
+ * `diagnostics` is already the JSON form the engine emits ({@link
224
+ * DiagnosticReportJSON}), so it crosses unchanged when a host asked for it.
225
+ */
226
+ interface SerializedParsingResult {
227
+ lines: SerializedParsedLine[];
228
+ totalLines: number;
229
+ errors: string[];
230
+ diagnostics?: DiagnosticReportJSON;
231
+ }
232
+
233
+ /**
234
+ * The main-side half of the harness: an async proxy of the core evaluate
235
+ * methods.
236
+ *
237
+ * {@link createWorkerEngine} performs the init handshake and resolves once the
238
+ * worker's engine is built, so the returned {@link WorkerEngine} is ready to
239
+ * call. Each call stamps a request id, tracks the pending promise, and settles
240
+ * it when the matching answer arrives, so several requests can be outstanding at
241
+ * once. An `AbortSignal` rejects the local promise and posts a `cancel` for the
242
+ * same id, mapping keystroke-level cancellation onto the boundary rather than
243
+ * re-inventing it.
244
+ */
245
+
246
+ /** Configuration for {@link createWorkerEngine}. */
247
+ interface WorkerEngineOptions {
248
+ /** The channel to the worker runtime. See `worker/transport.ts` for adapters. */
249
+ transport: WorkerTransport;
250
+ /** Locale for keywords and number formatting; defaults to English worker-side. */
251
+ localeCode?: string;
252
+ /** Whether the worker builds its engine with diagnostics enabled. */
253
+ diagnosticMode?: boolean;
254
+ /** Partial engine configuration, merged with the defaults worker-side. */
255
+ config?: Partial<EngineConfig>;
256
+ /**
257
+ * Names of built-in packages the worker should register. Omitted registers
258
+ * them all. Names rather than the packages themselves, since a package
259
+ * carries functions that cannot cross a `postMessage` boundary; a host with
260
+ * a custom package bakes it into its own worker entry and selects it here by
261
+ * name.
262
+ */
263
+ packages?: string[];
264
+ /** Formatting settings the worker uses when it renders a DTO's display text. */
265
+ formatting?: FormattingSettings;
266
+ }
267
+ /** Per-call options common to every proxied method. */
268
+ interface WorkerCallOptions {
269
+ /** Abort the request. Rejects the returned promise and cancels the work worker-side. */
270
+ signal?: AbortSignal;
271
+ }
272
+ /**
273
+ * One line whose result changed after a live value resolved worker-side, carried
274
+ * as its freshly re-evaluated {@link SerializedValue}. The value the host renders
275
+ * against `lineNumber`, recovered worker-side so the main thread needs no further
276
+ * round-trip to display it.
277
+ */
278
+ interface WorkerAsyncUpdate {
279
+ lineNumber: number;
280
+ value: SerializedValue;
281
+ }
282
+ /**
283
+ * A live-data resolution that failed worker-side. `error` is the same structured
284
+ * {@link EngineError} an in-process resolver failure would surface, rebuilt from
285
+ * its transported form, so a host branches on `code`/`category` as it always has.
286
+ */
287
+ interface WorkerAsyncError {
288
+ queryKey: string;
289
+ packageId: string;
290
+ error: EngineError;
291
+ }
292
+ /**
293
+ * An async proxy of {@link ExpressionEngine}'s core evaluate methods.
294
+ *
295
+ * Each method mirrors its synchronous counterpart but returns a Promise of the
296
+ * serialisable DTO rather than a live `Value`, and accepts an `AbortSignal`.
297
+ */
298
+ interface WorkerEngine {
299
+ /** Parse a whole document off-thread. Mirrors `ExpressionEngine.parseDocument`. */
300
+ parseDocument(input: string, options?: UnifiedParsingOptions & WorkerCallOptions): Promise<SerializedParsingResult>;
301
+ /** Evaluate an array of lines off-thread. Mirrors `ExpressionEngine.evaluateLines`. */
302
+ evaluateLines(lines: string[], options?: WorkerCallOptions): Promise<SerializedParsedLine[]>;
303
+ /** Evaluate a single expression off-thread. Mirrors `ExpressionEngine.evaluateExpression`. */
304
+ evaluateExpression(expression: string, options?: WorkerCallOptions): Promise<SerializedValue[]>;
305
+ /**
306
+ * Subscribe to live-data resolutions that land after a request already
307
+ * answered.
308
+ *
309
+ * A currency, weather or historical-rate value resolves inside the worker some
310
+ * time after `parseDocument` returned its pending result. When it does, the
311
+ * affected lines are re-evaluated worker-side and their fresh values arrive
312
+ * here as one batch. This is a subscription rather than a per-request promise
313
+ * because a resolution is tied to no single request: it belongs to whichever
314
+ * document is current when the value lands. Returns an unsubscribe function.
315
+ */
316
+ onResolved(listener: (lines: WorkerAsyncUpdate[]) => void): () => void;
317
+ /**
318
+ * Subscribe to live-data resolutions that failed. Returns an unsubscribe
319
+ * function. See {@link onResolved}; this is its failure channel.
320
+ */
321
+ onAsyncError(listener: (error: WorkerAsyncError) => void): () => void;
322
+ /** Reject every in-flight request and tear the transport down. Idempotent. */
323
+ terminate(): void;
324
+ }
325
+ /**
326
+ * Build a worker-backed engine and wait for it to be ready.
327
+ *
328
+ * ```ts
329
+ * const { client, host } = createLinkedTransports();
330
+ * startWorkerRuntime(host);
331
+ * const engine = await createWorkerEngine({ transport: client });
332
+ * const result = await engine.parseDocument(text);
333
+ * ```
334
+ *
335
+ * In production `client` wraps a real `Worker` (see `eventTargetTransport` /
336
+ * `messagePortTransport`), and `startWorkerRuntime` runs inside that worker.
337
+ */
338
+ declare function createWorkerEngine(options: WorkerEngineOptions): Promise<WorkerEngine>;
339
+
340
+ /**
341
+ * The worker-side half of the harness: it owns an {@link ExpressionEngine} and
342
+ * answers the protocol.
343
+ *
344
+ * {@link startWorkerRuntime} is transport-agnostic, so the same function runs
345
+ * behind a browser `Worker`, a Node `worker_threads` port, or an in-process
346
+ * link. A host's worker entry file is two lines: adapt the environment onto a
347
+ * {@link WorkerTransport} and call this.
348
+ *
349
+ * The runtime never posts a raw {@link Value}. Every result is projected onto a
350
+ * DTO first (`worker/serialize.ts`), and every failure is caught and flattened
351
+ * into a structured error, so a worker-side throw reaches the caller as an
352
+ * `EngineError` rather than a lost promise.
353
+ */
354
+
355
+ /** Options a host bakes into its own worker entry, chiefly its custom packages. */
356
+ interface WorkerRuntimeOptions {
357
+ /**
358
+ * The packages available to register, defaulting to {@link BUILTIN_PACKAGES}.
359
+ * A host with its own package authors a worker entry that passes them here,
360
+ * then selects among them by name from the main side. This is how a
361
+ * function-carrying package reaches the worker: baked into its bundle, never
362
+ * posted across the boundary.
363
+ */
364
+ packages?: IEnginePackage[];
365
+ }
366
+ /**
367
+ * Attach the runtime to a transport and start serving.
368
+ *
369
+ * Returns a teardown function that clears the engine and detaches, for a host
370
+ * that reuses a transport or shuts a worker down cleanly.
371
+ */
372
+ declare function startWorkerRuntime(transport: WorkerTransport, options?: WorkerRuntimeOptions): () => void;
373
+
374
+ /**
375
+ * Turn live engine results into the clone-safe DTOs the worker harness posts.
376
+ *
377
+ * These functions run on the worker side, just before a result crosses the
378
+ * boundary, and are also what the main side re-runs on a synchronous result to
379
+ * compare the two paths in tests. They are pure and deterministic given the
380
+ * same {@link FormattingSettings}, so a value serialised on either side is
381
+ * byte-for-byte the same DTO.
382
+ */
383
+
384
+ /**
385
+ * Project a {@link Value} onto a {@link SerializedValue}.
386
+ *
387
+ * `text` and `number` are set for every value; the type-specific fields are
388
+ * added only where the payload needs them, so the DTO stays minimal and a
389
+ * deep-equal between the two evaluation paths does not trip on a property one
390
+ * side left `undefined`.
391
+ */
392
+ declare function serializeValue(value: Value, settings?: FormattingSettings): SerializedValue;
393
+ /** Project a parsed line onto its DTO, serialising its result and every inline solve. */
394
+ declare function serializeParsedLine(line: ParsedLine, settings?: FormattingSettings): SerializedParsedLine;
395
+ /** Project a whole parsing result onto its DTO. */
396
+ declare function serializeParsingResult(result: ParsingResult, settings?: FormattingSettings): SerializedParsingResult;
397
+
398
+ /**
399
+ * The message protocol spoken across the worker boundary.
400
+ *
401
+ * One request-id space runs both directions: the main side stamps every
402
+ * `init`, `request` and `cancel` with an id, and the worker echoes that id back
403
+ * on the matching `ready`, `result` or `error`, so a caller can correlate an
404
+ * answer with the call that asked for it even with several requests in flight.
405
+ * Every payload here is clone-safe by construction (strings, numbers, plain
406
+ * option objects, and the DTOs from `worker/dto.ts`), so the whole protocol
407
+ * survives `postMessage`.
408
+ */
409
+
410
+ /** The core evaluate methods the harness proxies. */
411
+ type WorkerMethod = "parseDocument" | "evaluateLines" | "evaluateExpression";
412
+ /** Build the worker engine, sent once before any request. */
413
+ interface InitMessage {
414
+ kind: "init";
415
+ id: number;
416
+ /** Locale for keywords and number formatting; defaults to English worker-side. */
417
+ localeCode?: string;
418
+ /** Whether to build the engine with its diagnostic pipeline enabled. */
419
+ diagnosticMode?: boolean;
420
+ /** Partial engine configuration, merged with the defaults worker-side. */
421
+ config?: Partial<EngineConfig>;
422
+ /**
423
+ * Names of built-in packages to register, resolved against the runtime's
424
+ * available set. Omitted registers them all. Names rather than the packages
425
+ * themselves, since an `IEnginePackage` carries functions that cannot cross
426
+ * a `postMessage` boundary.
427
+ */
428
+ packages?: string[];
429
+ /** Formatting settings the runtime uses when it renders a DTO's display text. */
430
+ formatting?: FormattingSettings;
431
+ }
432
+ /** Invoke one proxied method. `args` positionally matches the method's own signature. */
433
+ interface RequestMessage {
434
+ kind: "request";
435
+ id: number;
436
+ method: WorkerMethod;
437
+ args: WorkerRequestArgs;
438
+ }
439
+ /**
440
+ * The positional arguments for each method, kept as a union so a request is
441
+ * type-checked against the method it names. An `AbortSignal` is never in here:
442
+ * it stays main-side and drives a {@link CancelMessage} instead.
443
+ */
444
+ type WorkerRequestArgs = [input: string, options?: UnifiedParsingOptions] | [lines: string[]] | [expression: string];
445
+ /** Ask the worker to abort the request with this id. */
446
+ interface CancelMessage {
447
+ kind: "cancel";
448
+ id: number;
449
+ }
450
+ /** Everything the main side sends. */
451
+ type MainToWorkerMessage = InitMessage | RequestMessage | CancelMessage;
452
+ /** The engine finished building and is ready to serve requests. */
453
+ interface ReadyMessage {
454
+ kind: "ready";
455
+ id: number;
456
+ }
457
+ /** A request or init succeeded; `value` is the serialised DTO for that method. */
458
+ interface ResultMessage {
459
+ kind: "result";
460
+ id: number;
461
+ value: unknown;
462
+ }
463
+ /** A request or init failed; `error` is the structured failure, flattened for transport. */
464
+ interface ErrorMessage {
465
+ kind: "error";
466
+ id: number;
467
+ error: SerializedEngineError;
468
+ }
469
+ /**
470
+ * One line whose result changed after a later async resolution settled, carried
471
+ * as its freshly re-evaluated {@link SerializedValue}. The value, not the line
472
+ * number alone: the engine's own event names only the affected lines and leaves
473
+ * the resolved value in its cache, so the worker re-reads each line before it
474
+ * posts, and the main side receives a value it can render without a round-trip.
475
+ */
476
+ interface AsyncResolvedLine {
477
+ lineNumber: number;
478
+ value: SerializedValue;
479
+ }
480
+ /**
481
+ * A later async resolution settled, and these lines now carry live data.
482
+ *
483
+ * Unlike a {@link ResultMessage} this has no `id`: a resolution is not the
484
+ * answer to one request, it arrives whenever the live value lands, so it is a
485
+ * broadcast the main side routes to its subscribers rather than to a pending
486
+ * promise. `lines` is a batch because the engine collapses every resolution that
487
+ * settles in one tick into a single update.
488
+ */
489
+ interface AsyncUpdateMessage {
490
+ kind: "async-update";
491
+ lines: AsyncResolvedLine[];
492
+ }
493
+ /**
494
+ * A later async resolution failed. Carries the query and package that failed,
495
+ * plus the structured error flattened the same way a {@link ErrorMessage} is, so
496
+ * the main side reads the same `code`/`category`/`message` it would in-process.
497
+ * Like {@link AsyncUpdateMessage} it has no `id`: a failed resolution is a
498
+ * broadcast, not the rejection of one request's promise.
499
+ */
500
+ interface AsyncErrorMessage {
501
+ kind: "async-error";
502
+ queryKey: string;
503
+ packageId: string;
504
+ error: SerializedEngineError;
505
+ }
506
+ /** Everything the worker sends back. */
507
+ type WorkerToMainMessage = ReadyMessage | ResultMessage | ErrorMessage | AsyncUpdateMessage | AsyncErrorMessage;
508
+
509
+ export { type AsyncErrorMessage, type AsyncResolvedLine, type AsyncUpdateMessage, type CancelMessage, type ErrorMessage, type InitMessage, type MainToWorkerMessage, type ReadyMessage, type RequestMessage, type ResultMessage, type SerializedInlineSolve, type SerializedMatrix, type SerializedParsedLine, type SerializedParsingResult, type SerializedValue, type WorkerAsyncError, type WorkerAsyncUpdate, type WorkerCallOptions, type WorkerEngine, type WorkerEngineOptions, type WorkerMethod, type WorkerRequestArgs, type WorkerRuntimeOptions, type WorkerToMainMessage, type WorkerTransport, createLinkedTransports, createWorkerEngine, eventTargetTransport, messagePortTransport, serializeParsedLine, serializeParsingResult, serializeValue, startWorkerRuntime };