@azx-pbc/axiom-runtime 0.0.0-stage → 0.0.5

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 (755) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +714 -2
  3. package/dist/cache/index.d.ts +191 -0
  4. package/dist/cache/index.d.ts.map +1 -0
  5. package/dist/cache/index.js +361 -0
  6. package/dist/cache/index.js.map +1 -0
  7. package/dist/canonical/jcs.d.ts +78 -0
  8. package/dist/canonical/jcs.d.ts.map +1 -0
  9. package/dist/canonical/jcs.js +500 -0
  10. package/dist/canonical/jcs.js.map +1 -0
  11. package/dist/canonical/restricted-json.d.ts +7 -0
  12. package/dist/canonical/restricted-json.d.ts.map +1 -0
  13. package/dist/canonical/restricted-json.js +318 -0
  14. package/dist/canonical/restricted-json.js.map +1 -0
  15. package/dist/canonical/restricted-value.d.ts +59 -0
  16. package/dist/canonical/restricted-value.d.ts.map +1 -0
  17. package/dist/canonical/restricted-value.js +156 -0
  18. package/dist/canonical/restricted-value.js.map +1 -0
  19. package/dist/canonical/restricted.d.ts +85 -0
  20. package/dist/canonical/restricted.d.ts.map +1 -0
  21. package/dist/canonical/restricted.js +163 -0
  22. package/dist/canonical/restricted.js.map +1 -0
  23. package/dist/canonical/signature.d.ts +38 -0
  24. package/dist/canonical/signature.d.ts.map +1 -0
  25. package/dist/canonical/signature.js +47 -0
  26. package/dist/canonical/signature.js.map +1 -0
  27. package/dist/eval/access/delivery.d.ts +63 -0
  28. package/dist/eval/access/delivery.d.ts.map +1 -0
  29. package/dist/eval/access/delivery.js +98 -0
  30. package/dist/eval/access/delivery.js.map +1 -0
  31. package/dist/eval/access/overlay.d.ts +72 -0
  32. package/dist/eval/access/overlay.d.ts.map +1 -0
  33. package/dist/eval/access/overlay.js +402 -0
  34. package/dist/eval/access/overlay.js.map +1 -0
  35. package/dist/eval/access/projection.d.ts +159 -0
  36. package/dist/eval/access/projection.d.ts.map +1 -0
  37. package/dist/eval/access/projection.js +211 -0
  38. package/dist/eval/access/projection.js.map +1 -0
  39. package/dist/eval/access/window.d.ts +128 -0
  40. package/dist/eval/access/window.d.ts.map +1 -0
  41. package/dist/eval/access/window.js +254 -0
  42. package/dist/eval/access/window.js.map +1 -0
  43. package/dist/eval/access/write.d.ts +113 -0
  44. package/dist/eval/access/write.d.ts.map +1 -0
  45. package/dist/eval/access/write.js +119 -0
  46. package/dist/eval/access/write.js.map +1 -0
  47. package/dist/eval/addressing.d.ts +131 -0
  48. package/dist/eval/addressing.d.ts.map +1 -0
  49. package/dist/eval/addressing.js +270 -0
  50. package/dist/eval/addressing.js.map +1 -0
  51. package/dist/eval/budget.d.ts +143 -0
  52. package/dist/eval/budget.d.ts.map +1 -0
  53. package/dist/eval/budget.js +387 -0
  54. package/dist/eval/budget.js.map +1 -0
  55. package/dist/eval/computed.d.ts +46 -0
  56. package/dist/eval/computed.d.ts.map +1 -0
  57. package/dist/eval/computed.js +89 -0
  58. package/dist/eval/computed.js.map +1 -0
  59. package/dist/eval/denials.d.ts +64 -0
  60. package/dist/eval/denials.d.ts.map +1 -0
  61. package/dist/eval/denials.js +87 -0
  62. package/dist/eval/denials.js.map +1 -0
  63. package/dist/eval/engine/cancellation.d.ts +12 -0
  64. package/dist/eval/engine/cancellation.d.ts.map +1 -0
  65. package/dist/eval/engine/cancellation.js +56 -0
  66. package/dist/eval/engine/cancellation.js.map +1 -0
  67. package/dist/eval/engine/delta.d.ts +104 -0
  68. package/dist/eval/engine/delta.d.ts.map +1 -0
  69. package/dist/eval/engine/delta.js +466 -0
  70. package/dist/eval/engine/delta.js.map +1 -0
  71. package/dist/eval/engine/deps.d.ts +136 -0
  72. package/dist/eval/engine/deps.d.ts.map +1 -0
  73. package/dist/eval/engine/deps.js +345 -0
  74. package/dist/eval/engine/deps.js.map +1 -0
  75. package/dist/eval/engine/identity.d.ts +128 -0
  76. package/dist/eval/engine/identity.d.ts.map +1 -0
  77. package/dist/eval/engine/identity.js +398 -0
  78. package/dist/eval/engine/identity.js.map +1 -0
  79. package/dist/eval/engine/index.d.ts +200 -0
  80. package/dist/eval/engine/index.d.ts.map +1 -0
  81. package/dist/eval/engine/index.js +1242 -0
  82. package/dist/eval/engine/index.js.map +1 -0
  83. package/dist/eval/engine/measurement.d.ts +23 -0
  84. package/dist/eval/engine/measurement.d.ts.map +1 -0
  85. package/dist/eval/engine/measurement.js +42 -0
  86. package/dist/eval/engine/measurement.js.map +1 -0
  87. package/dist/eval/engine/naive.d.ts +19 -0
  88. package/dist/eval/engine/naive.d.ts.map +1 -0
  89. package/dist/eval/engine/naive.js +59 -0
  90. package/dist/eval/engine/naive.js.map +1 -0
  91. package/dist/eval/engine/ops.d.ts +214 -0
  92. package/dist/eval/engine/ops.d.ts.map +1 -0
  93. package/dist/eval/engine/ops.js +1422 -0
  94. package/dist/eval/engine/ops.js.map +1 -0
  95. package/dist/eval/engine/patches.d.ts +40 -0
  96. package/dist/eval/engine/patches.d.ts.map +1 -0
  97. package/dist/eval/engine/patches.js +125 -0
  98. package/dist/eval/engine/patches.js.map +1 -0
  99. package/dist/eval/engine/ports.d.ts +71 -0
  100. package/dist/eval/engine/ports.d.ts.map +1 -0
  101. package/dist/eval/engine/ports.js +2 -0
  102. package/dist/eval/engine/ports.js.map +1 -0
  103. package/dist/eval/engine/session.d.ts +116 -0
  104. package/dist/eval/engine/session.d.ts.map +1 -0
  105. package/dist/eval/engine/session.js +653 -0
  106. package/dist/eval/engine/session.js.map +1 -0
  107. package/dist/eval/engine/snapshot.d.ts +97 -0
  108. package/dist/eval/engine/snapshot.d.ts.map +1 -0
  109. package/dist/eval/engine/snapshot.js +221 -0
  110. package/dist/eval/engine/snapshot.js.map +1 -0
  111. package/dist/eval/engine/subscriptions.d.ts +47 -0
  112. package/dist/eval/engine/subscriptions.d.ts.map +1 -0
  113. package/dist/eval/engine/subscriptions.js +103 -0
  114. package/dist/eval/engine/subscriptions.js.map +1 -0
  115. package/dist/eval/engine/trace.d.ts +77 -0
  116. package/dist/eval/engine/trace.d.ts.map +1 -0
  117. package/dist/eval/engine/trace.js +140 -0
  118. package/dist/eval/engine/trace.js.map +1 -0
  119. package/dist/eval/error-diagnostic.d.ts +26 -0
  120. package/dist/eval/error-diagnostic.d.ts.map +1 -0
  121. package/dist/eval/error-diagnostic.js +63 -0
  122. package/dist/eval/error-diagnostic.js.map +1 -0
  123. package/dist/eval/evaluate-expr.d.ts +44 -0
  124. package/dist/eval/evaluate-expr.d.ts.map +1 -0
  125. package/dist/eval/evaluate-expr.js +149 -0
  126. package/dist/eval/evaluate-expr.js.map +1 -0
  127. package/dist/eval/evaluate.d.ts +282 -0
  128. package/dist/eval/evaluate.d.ts.map +1 -0
  129. package/dist/eval/evaluate.js +391 -0
  130. package/dist/eval/evaluate.js.map +1 -0
  131. package/dist/eval/evolution/relocate.d.ts +72 -0
  132. package/dist/eval/evolution/relocate.d.ts.map +1 -0
  133. package/dist/eval/evolution/relocate.js +427 -0
  134. package/dist/eval/evolution/relocate.js.map +1 -0
  135. package/dist/eval/evolution/select.d.ts +11 -0
  136. package/dist/eval/evolution/select.d.ts.map +1 -0
  137. package/dist/eval/evolution/select.js +53 -0
  138. package/dist/eval/evolution/select.js.map +1 -0
  139. package/dist/eval/evolution/upcast.d.ts +13 -0
  140. package/dist/eval/evolution/upcast.d.ts.map +1 -0
  141. package/dist/eval/evolution/upcast.js +88 -0
  142. package/dist/eval/evolution/upcast.js.map +1 -0
  143. package/dist/eval/expr/aggregates.d.ts +75 -0
  144. package/dist/eval/expr/aggregates.d.ts.map +1 -0
  145. package/dist/eval/expr/aggregates.js +991 -0
  146. package/dist/eval/expr/aggregates.js.map +1 -0
  147. package/dist/eval/expr/arithmetic.d.ts +26 -0
  148. package/dist/eval/expr/arithmetic.d.ts.map +1 -0
  149. package/dist/eval/expr/arithmetic.js +387 -0
  150. package/dist/eval/expr/arithmetic.js.map +1 -0
  151. package/dist/eval/expr/between.d.ts +17 -0
  152. package/dist/eval/expr/between.d.ts.map +1 -0
  153. package/dist/eval/expr/between.js +46 -0
  154. package/dist/eval/expr/between.js.map +1 -0
  155. package/dist/eval/expr/binder.d.ts +96 -0
  156. package/dist/eval/expr/binder.d.ts.map +1 -0
  157. package/dist/eval/expr/binder.js +253 -0
  158. package/dist/eval/expr/binder.js.map +1 -0
  159. package/dist/eval/expr/call-dispatch.d.ts +28 -0
  160. package/dist/eval/expr/call-dispatch.d.ts.map +1 -0
  161. package/dist/eval/expr/call-dispatch.js +114 -0
  162. package/dist/eval/expr/call-dispatch.js.map +1 -0
  163. package/dist/eval/expr/collections.d.ts +20 -0
  164. package/dist/eval/expr/collections.d.ts.map +1 -0
  165. package/dist/eval/expr/collections.js +66 -0
  166. package/dist/eval/expr/collections.js.map +1 -0
  167. package/dist/eval/expr/compare.d.ts +36 -0
  168. package/dist/eval/expr/compare.d.ts.map +1 -0
  169. package/dist/eval/expr/compare.js +115 -0
  170. package/dist/eval/expr/compare.js.map +1 -0
  171. package/dist/eval/expr/datasets.d.ts +28 -0
  172. package/dist/eval/expr/datasets.d.ts.map +1 -0
  173. package/dist/eval/expr/datasets.js +304 -0
  174. package/dist/eval/expr/datasets.js.map +1 -0
  175. package/dist/eval/expr/digest.d.ts +23 -0
  176. package/dist/eval/expr/digest.d.ts.map +1 -0
  177. package/dist/eval/expr/digest.js +89 -0
  178. package/dist/eval/expr/digest.js.map +1 -0
  179. package/dist/eval/expr/domains.d.ts +19 -0
  180. package/dist/eval/expr/domains.d.ts.map +1 -0
  181. package/dist/eval/expr/domains.js +18 -0
  182. package/dist/eval/expr/domains.js.map +1 -0
  183. package/dist/eval/expr/host.d.ts +152 -0
  184. package/dist/eval/expr/host.d.ts.map +1 -0
  185. package/dist/eval/expr/host.js +36 -0
  186. package/dist/eval/expr/host.js.map +1 -0
  187. package/dist/eval/expr/lists.d.ts +24 -0
  188. package/dist/eval/expr/lists.d.ts.map +1 -0
  189. package/dist/eval/expr/lists.js +155 -0
  190. package/dist/eval/expr/lists.js.map +1 -0
  191. package/dist/eval/expr/member.d.ts +15 -0
  192. package/dist/eval/expr/member.d.ts.map +1 -0
  193. package/dist/eval/expr/member.js +32 -0
  194. package/dist/eval/expr/member.js.map +1 -0
  195. package/dist/eval/expr/money-ops.d.ts +10 -0
  196. package/dist/eval/expr/money-ops.d.ts.map +1 -0
  197. package/dist/eval/expr/money-ops.js +17 -0
  198. package/dist/eval/expr/money-ops.js.map +1 -0
  199. package/dist/eval/expr/operands.d.ts +27 -0
  200. package/dist/eval/expr/operands.d.ts.map +1 -0
  201. package/dist/eval/expr/operands.js +167 -0
  202. package/dist/eval/expr/operands.js.map +1 -0
  203. package/dist/eval/expr/presence.d.ts +27 -0
  204. package/dist/eval/expr/presence.d.ts.map +1 -0
  205. package/dist/eval/expr/presence.js +140 -0
  206. package/dist/eval/expr/presence.js.map +1 -0
  207. package/dist/eval/expr/records.d.ts +22 -0
  208. package/dist/eval/expr/records.d.ts.map +1 -0
  209. package/dist/eval/expr/records.js +101 -0
  210. package/dist/eval/expr/records.js.map +1 -0
  211. package/dist/eval/expr/rule-refs.d.ts +25 -0
  212. package/dist/eval/expr/rule-refs.d.ts.map +1 -0
  213. package/dist/eval/expr/rule-refs.js +60 -0
  214. package/dist/eval/expr/rule-refs.js.map +1 -0
  215. package/dist/eval/expr/sequences.d.ts +26 -0
  216. package/dist/eval/expr/sequences.d.ts.map +1 -0
  217. package/dist/eval/expr/sequences.js +151 -0
  218. package/dist/eval/expr/sequences.js.map +1 -0
  219. package/dist/eval/expr/value.d.ts +99 -0
  220. package/dist/eval/expr/value.d.ts.map +1 -0
  221. package/dist/eval/expr/value.js +14 -0
  222. package/dist/eval/expr/value.js.map +1 -0
  223. package/dist/eval/expression.d.ts +142 -0
  224. package/dist/eval/expression.d.ts.map +1 -0
  225. package/dist/eval/expression.js +446 -0
  226. package/dist/eval/expression.js.map +1 -0
  227. package/dist/eval/firing.d.ts +68 -0
  228. package/dist/eval/firing.d.ts.map +1 -0
  229. package/dist/eval/firing.js +222 -0
  230. package/dist/eval/firing.js.map +1 -0
  231. package/dist/eval/gate.d.ts +110 -0
  232. package/dist/eval/gate.d.ts.map +1 -0
  233. package/dist/eval/gate.js +278 -0
  234. package/dist/eval/gate.js.map +1 -0
  235. package/dist/eval/layout-visibility.d.ts +18 -0
  236. package/dist/eval/layout-visibility.d.ts.map +1 -0
  237. package/dist/eval/layout-visibility.js +61 -0
  238. package/dist/eval/layout-visibility.js.map +1 -0
  239. package/dist/eval/option-availability.d.ts +26 -0
  240. package/dist/eval/option-availability.d.ts.map +1 -0
  241. package/dist/eval/option-availability.js +580 -0
  242. package/dist/eval/option-availability.js.map +1 -0
  243. package/dist/eval/options-boundary.d.ts +15 -0
  244. package/dist/eval/options-boundary.d.ts.map +1 -0
  245. package/dist/eval/options-boundary.js +40 -0
  246. package/dist/eval/options-boundary.js.map +1 -0
  247. package/dist/eval/options.d.ts +99 -0
  248. package/dist/eval/options.d.ts.map +1 -0
  249. package/dist/eval/options.js +96 -0
  250. package/dist/eval/options.js.map +1 -0
  251. package/dist/eval/overrides.d.ts +116 -0
  252. package/dist/eval/overrides.d.ts.map +1 -0
  253. package/dist/eval/overrides.js +176 -0
  254. package/dist/eval/overrides.js.map +1 -0
  255. package/dist/eval/paths.d.ts +25 -0
  256. package/dist/eval/paths.d.ts.map +1 -0
  257. package/dist/eval/paths.js +47 -0
  258. package/dist/eval/paths.js.map +1 -0
  259. package/dist/eval/presentation-reads.d.ts +20 -0
  260. package/dist/eval/presentation-reads.d.ts.map +1 -0
  261. package/dist/eval/presentation-reads.js +2 -0
  262. package/dist/eval/presentation-reads.js.map +1 -0
  263. package/dist/eval/presentation.d.ts +122 -0
  264. package/dist/eval/presentation.d.ts.map +1 -0
  265. package/dist/eval/presentation.js +255 -0
  266. package/dist/eval/presentation.js.map +1 -0
  267. package/dist/eval/reader/context-value.d.ts +41 -0
  268. package/dist/eval/reader/context-value.d.ts.map +1 -0
  269. package/dist/eval/reader/context-value.js +129 -0
  270. package/dist/eval/reader/context-value.js.map +1 -0
  271. package/dist/eval/reader/covered.d.ts +53 -0
  272. package/dist/eval/reader/covered.d.ts.map +1 -0
  273. package/dist/eval/reader/covered.js +139 -0
  274. package/dist/eval/reader/covered.js.map +1 -0
  275. package/dist/eval/reader/declarations.d.ts +182 -0
  276. package/dist/eval/reader/declarations.d.ts.map +1 -0
  277. package/dist/eval/reader/declarations.js +153 -0
  278. package/dist/eval/reader/declarations.js.map +1 -0
  279. package/dist/eval/reader/member-access.d.ts +87 -0
  280. package/dist/eval/reader/member-access.d.ts.map +1 -0
  281. package/dist/eval/reader/member-access.js +212 -0
  282. package/dist/eval/reader/member-access.js.map +1 -0
  283. package/dist/eval/reader/memo.d.ts +34 -0
  284. package/dist/eval/reader/memo.d.ts.map +1 -0
  285. package/dist/eval/reader/memo.js +67 -0
  286. package/dist/eval/reader/memo.js.map +1 -0
  287. package/dist/eval/reader/overlay.d.ts +74 -0
  288. package/dist/eval/reader/overlay.d.ts.map +1 -0
  289. package/dist/eval/reader/overlay.js +365 -0
  290. package/dist/eval/reader/overlay.js.map +1 -0
  291. package/dist/eval/reader/questions.d.ts +37 -0
  292. package/dist/eval/reader/questions.d.ts.map +1 -0
  293. package/dist/eval/reader/questions.js +78 -0
  294. package/dist/eval/reader/questions.js.map +1 -0
  295. package/dist/eval/reader/resolve.d.ts +84 -0
  296. package/dist/eval/reader/resolve.d.ts.map +1 -0
  297. package/dist/eval/reader/resolve.js +310 -0
  298. package/dist/eval/reader/resolve.js.map +1 -0
  299. package/dist/eval/reader/value-read.d.ts +50 -0
  300. package/dist/eval/reader/value-read.d.ts.map +1 -0
  301. package/dist/eval/reader/value-read.js +133 -0
  302. package/dist/eval/reader/value-read.js.map +1 -0
  303. package/dist/eval/reader/withheld.d.ts +48 -0
  304. package/dist/eval/reader/withheld.d.ts.map +1 -0
  305. package/dist/eval/reader/withheld.js +108 -0
  306. package/dist/eval/reader/withheld.js.map +1 -0
  307. package/dist/eval/reader-paths.d.ts +24 -0
  308. package/dist/eval/reader-paths.d.ts.map +1 -0
  309. package/dist/eval/reader-paths.js +23 -0
  310. package/dist/eval/reader-paths.js.map +1 -0
  311. package/dist/eval/reader.d.ts +281 -0
  312. package/dist/eval/reader.d.ts.map +1 -0
  313. package/dist/eval/reader.js +560 -0
  314. package/dist/eval/reader.js.map +1 -0
  315. package/dist/eval/receipt.d.ts +37 -0
  316. package/dist/eval/receipt.d.ts.map +1 -0
  317. package/dist/eval/receipt.js +222 -0
  318. package/dist/eval/receipt.js.map +1 -0
  319. package/dist/eval/report/assemble.d.ts +84 -0
  320. package/dist/eval/report/assemble.d.ts.map +1 -0
  321. package/dist/eval/report/assemble.js +277 -0
  322. package/dist/eval/report/assemble.js.map +1 -0
  323. package/dist/eval/report/fold.d.ts +18 -0
  324. package/dist/eval/report/fold.d.ts.map +1 -0
  325. package/dist/eval/report/fold.js +58 -0
  326. package/dist/eval/report/fold.js.map +1 -0
  327. package/dist/eval/rule/alternatives.d.ts +23 -0
  328. package/dist/eval/rule/alternatives.d.ts.map +1 -0
  329. package/dist/eval/rule/alternatives.js +46 -0
  330. package/dist/eval/rule/alternatives.js.map +1 -0
  331. package/dist/eval/rule/behaviour.d.ts +47 -0
  332. package/dist/eval/rule/behaviour.d.ts.map +1 -0
  333. package/dist/eval/rule/behaviour.js +249 -0
  334. package/dist/eval/rule/behaviour.js.map +1 -0
  335. package/dist/eval/rule/compute.d.ts +46 -0
  336. package/dist/eval/rule/compute.d.ts.map +1 -0
  337. package/dist/eval/rule/compute.js +158 -0
  338. package/dist/eval/rule/compute.js.map +1 -0
  339. package/dist/eval/rule/create-state.d.ts +42 -0
  340. package/dist/eval/rule/create-state.d.ts.map +1 -0
  341. package/dist/eval/rule/create-state.js +134 -0
  342. package/dist/eval/rule/create-state.js.map +1 -0
  343. package/dist/eval/rule/diagnostics.d.ts +24 -0
  344. package/dist/eval/rule/diagnostics.d.ts.map +1 -0
  345. package/dist/eval/rule/diagnostics.js +45 -0
  346. package/dist/eval/rule/diagnostics.js.map +1 -0
  347. package/dist/eval/rule/execution.d.ts +24 -0
  348. package/dist/eval/rule/execution.d.ts.map +1 -0
  349. package/dist/eval/rule/execution.js +495 -0
  350. package/dist/eval/rule/execution.js.map +1 -0
  351. package/dist/eval/rule/gate.d.ts +12 -0
  352. package/dist/eval/rule/gate.d.ts.map +1 -0
  353. package/dist/eval/rule/gate.js +34 -0
  354. package/dist/eval/rule/gate.js.map +1 -0
  355. package/dist/eval/rule/item.d.ts +11 -0
  356. package/dist/eval/rule/item.d.ts.map +1 -0
  357. package/dist/eval/rule/item.js +265 -0
  358. package/dist/eval/rule/item.js.map +1 -0
  359. package/dist/eval/rule/prepare.d.ts +64 -0
  360. package/dist/eval/rule/prepare.d.ts.map +1 -0
  361. package/dist/eval/rule/prepare.js +131 -0
  362. package/dist/eval/rule/prepare.js.map +1 -0
  363. package/dist/eval/rule/result.d.ts +97 -0
  364. package/dist/eval/rule/result.d.ts.map +1 -0
  365. package/dist/eval/rule/result.js +347 -0
  366. package/dist/eval/rule/result.js.map +1 -0
  367. package/dist/eval/rule/runner.d.ts +128 -0
  368. package/dist/eval/rule/runner.d.ts.map +1 -0
  369. package/dist/eval/rule/runner.js +296 -0
  370. package/dist/eval/rule/runner.js.map +1 -0
  371. package/dist/eval/rule/screen.d.ts +32 -0
  372. package/dist/eval/rule/screen.d.ts.map +1 -0
  373. package/dist/eval/rule/screen.js +73 -0
  374. package/dist/eval/rule/screen.js.map +1 -0
  375. package/dist/eval/rule/state.d.ts +137 -0
  376. package/dist/eval/rule/state.d.ts.map +1 -0
  377. package/dist/eval/rule/state.js +2 -0
  378. package/dist/eval/rule/state.js.map +1 -0
  379. package/dist/eval/rule/steps.d.ts +44 -0
  380. package/dist/eval/rule/steps.d.ts.map +1 -0
  381. package/dist/eval/rule/steps.js +367 -0
  382. package/dist/eval/rule/steps.js.map +1 -0
  383. package/dist/eval/rule/visibility.d.ts +18 -0
  384. package/dist/eval/rule/visibility.d.ts.map +1 -0
  385. package/dist/eval/rule/visibility.js +79 -0
  386. package/dist/eval/rule/visibility.js.map +1 -0
  387. package/dist/eval/seal.d.ts +74 -0
  388. package/dist/eval/seal.d.ts.map +1 -0
  389. package/dist/eval/seal.js +154 -0
  390. package/dist/eval/seal.js.map +1 -0
  391. package/dist/eval/signature-coverage.d.ts +19 -0
  392. package/dist/eval/signature-coverage.d.ts.map +1 -0
  393. package/dist/eval/signature-coverage.js +160 -0
  394. package/dist/eval/signature-coverage.js.map +1 -0
  395. package/dist/eval/state/derive.d.ts +72 -0
  396. package/dist/eval/state/derive.d.ts.map +1 -0
  397. package/dist/eval/state/derive.js +61 -0
  398. package/dist/eval/state/derive.js.map +1 -0
  399. package/dist/eval/state/describe.d.ts +18 -0
  400. package/dist/eval/state/describe.d.ts.map +1 -0
  401. package/dist/eval/state/describe.js +19 -0
  402. package/dist/eval/state/describe.js.map +1 -0
  403. package/dist/eval/state/field-state.d.ts +471 -0
  404. package/dist/eval/state/field-state.d.ts.map +1 -0
  405. package/dist/eval/state/field-state.js +1604 -0
  406. package/dist/eval/state/field-state.js.map +1 -0
  407. package/dist/eval/state/measurement.d.ts +136 -0
  408. package/dist/eval/state/measurement.d.ts.map +1 -0
  409. package/dist/eval/state/measurement.js +209 -0
  410. package/dist/eval/state/measurement.js.map +1 -0
  411. package/dist/eval/state/options.d.ts +21 -0
  412. package/dist/eval/state/options.d.ts.map +1 -0
  413. package/dist/eval/state/options.js +3 -0
  414. package/dist/eval/state/options.js.map +1 -0
  415. package/dist/eval/state/readiness.d.ts +400 -0
  416. package/dist/eval/state/readiness.d.ts.map +1 -0
  417. package/dist/eval/state/readiness.js +1067 -0
  418. package/dist/eval/state/readiness.js.map +1 -0
  419. package/dist/eval/state/snapshot.d.ts +130 -0
  420. package/dist/eval/state/snapshot.d.ts.map +1 -0
  421. package/dist/eval/state/snapshot.js +35 -0
  422. package/dist/eval/state/snapshot.js.map +1 -0
  423. package/dist/eval/state/unavailable-options.d.ts +54 -0
  424. package/dist/eval/state/unavailable-options.d.ts.map +1 -0
  425. package/dist/eval/state/unavailable-options.js +82 -0
  426. package/dist/eval/state/unavailable-options.js.map +1 -0
  427. package/dist/eval/state/value-state.d.ts +38 -0
  428. package/dist/eval/state/value-state.d.ts.map +1 -0
  429. package/dist/eval/state/value-state.js +52 -0
  430. package/dist/eval/state/value-state.js.map +1 -0
  431. package/dist/eval/submission/admission.d.ts +50 -0
  432. package/dist/eval/submission/admission.d.ts.map +1 -0
  433. package/dist/eval/submission/admission.js +174 -0
  434. package/dist/eval/submission/admission.js.map +1 -0
  435. package/dist/eval/submission/authority.d.ts +71 -0
  436. package/dist/eval/submission/authority.d.ts.map +1 -0
  437. package/dist/eval/submission/authority.js +118 -0
  438. package/dist/eval/submission/authority.js.map +1 -0
  439. package/dist/eval/submission/datasets.d.ts +28 -0
  440. package/dist/eval/submission/datasets.d.ts.map +1 -0
  441. package/dist/eval/submission/datasets.js +109 -0
  442. package/dist/eval/submission/datasets.js.map +1 -0
  443. package/dist/eval/submission/index.d.ts +15 -0
  444. package/dist/eval/submission/index.d.ts.map +1 -0
  445. package/dist/eval/submission/index.js +13 -0
  446. package/dist/eval/submission/index.js.map +1 -0
  447. package/dist/eval/submission/refusals.d.ts +103 -0
  448. package/dist/eval/submission/refusals.d.ts.map +1 -0
  449. package/dist/eval/submission/refusals.js +15 -0
  450. package/dist/eval/submission/refusals.js.map +1 -0
  451. package/dist/eval/submission/signatures.d.ts +7 -0
  452. package/dist/eval/submission/signatures.d.ts.map +1 -0
  453. package/dist/eval/submission/signatures.js +215 -0
  454. package/dist/eval/submission/signatures.js.map +1 -0
  455. package/dist/eval/submission/writes.d.ts +51 -0
  456. package/dist/eval/submission/writes.d.ts.map +1 -0
  457. package/dist/eval/submission/writes.js +203 -0
  458. package/dist/eval/submission/writes.js.map +1 -0
  459. package/dist/eval/submission.d.ts +53 -0
  460. package/dist/eval/submission.d.ts.map +1 -0
  461. package/dist/eval/submission.js +521 -0
  462. package/dist/eval/submission.js.map +1 -0
  463. package/dist/eval/suggestions-to-engine.d.ts +18 -0
  464. package/dist/eval/suggestions-to-engine.d.ts.map +1 -0
  465. package/dist/eval/suggestions-to-engine.js +40 -0
  466. package/dist/eval/suggestions-to-engine.js.map +1 -0
  467. package/dist/eval/suggestions.d.ts +17 -0
  468. package/dist/eval/suggestions.d.ts.map +1 -0
  469. package/dist/eval/suggestions.js +314 -0
  470. package/dist/eval/suggestions.js.map +1 -0
  471. package/dist/eval/undecided.d.ts +64 -0
  472. package/dist/eval/undecided.d.ts.map +1 -0
  473. package/dist/eval/undecided.js +101 -0
  474. package/dist/eval/undecided.js.map +1 -0
  475. package/dist/eval/verdict.d.ts +66 -0
  476. package/dist/eval/verdict.d.ts.map +1 -0
  477. package/dist/eval/verdict.js +106 -0
  478. package/dist/eval/verdict.js.map +1 -0
  479. package/dist/eval/verify-signature.d.ts +78 -0
  480. package/dist/eval/verify-signature.d.ts.map +1 -0
  481. package/dist/eval/verify-signature.js +185 -0
  482. package/dist/eval/verify-signature.js.map +1 -0
  483. package/dist/eval/version-dispatch.d.ts +38 -0
  484. package/dist/eval/version-dispatch.d.ts.map +1 -0
  485. package/dist/eval/version-dispatch.js +61 -0
  486. package/dist/eval/version-dispatch.js.map +1 -0
  487. package/dist/eval/visibility.d.ts +33 -0
  488. package/dist/eval/visibility.d.ts.map +1 -0
  489. package/dist/eval/visibility.js +83 -0
  490. package/dist/eval/visibility.js.map +1 -0
  491. package/dist/evaluate.d.ts +24 -0
  492. package/dist/evaluate.d.ts.map +1 -0
  493. package/dist/evaluate.js +18 -0
  494. package/dist/evaluate.js.map +1 -0
  495. package/dist/expr/builtin-docs.d.ts +51 -0
  496. package/dist/expr/builtin-docs.d.ts.map +1 -0
  497. package/dist/expr/builtin-docs.js +874 -0
  498. package/dist/expr/builtin-docs.js.map +1 -0
  499. package/dist/expr/builtins.d.ts +50 -0
  500. package/dist/expr/builtins.d.ts.map +1 -0
  501. package/dist/expr/builtins.js +966 -0
  502. package/dist/expr/builtins.js.map +1 -0
  503. package/dist/expr/decimal-precision.d.ts +39 -0
  504. package/dist/expr/decimal-precision.d.ts.map +1 -0
  505. package/dist/expr/decimal-precision.js +62 -0
  506. package/dist/expr/decimal-precision.js.map +1 -0
  507. package/dist/expr/decimal.d.ts +172 -0
  508. package/dist/expr/decimal.d.ts.map +1 -0
  509. package/dist/expr/decimal.js +782 -0
  510. package/dist/expr/decimal.js.map +1 -0
  511. package/dist/expr/deprecations.d.ts +34 -0
  512. package/dist/expr/deprecations.d.ts.map +1 -0
  513. package/dist/expr/deprecations.js +17 -0
  514. package/dist/expr/deprecations.js.map +1 -0
  515. package/dist/expr/diagnostics.d.ts +21 -0
  516. package/dist/expr/diagnostics.d.ts.map +1 -0
  517. package/dist/expr/diagnostics.js +231 -0
  518. package/dist/expr/diagnostics.js.map +1 -0
  519. package/dist/expr/direction.d.ts +30 -0
  520. package/dist/expr/direction.d.ts.map +1 -0
  521. package/dist/expr/direction.js +77 -0
  522. package/dist/expr/direction.js.map +1 -0
  523. package/dist/expr/example-expression.d.ts +62 -0
  524. package/dist/expr/example-expression.d.ts.map +1 -0
  525. package/dist/expr/example-expression.js +670 -0
  526. package/dist/expr/example-expression.js.map +1 -0
  527. package/dist/expr/instant.d.ts +49 -0
  528. package/dist/expr/instant.d.ts.map +1 -0
  529. package/dist/expr/instant.js +111 -0
  530. package/dist/expr/instant.js.map +1 -0
  531. package/dist/expr/logic.d.ts +17 -0
  532. package/dist/expr/logic.d.ts.map +1 -0
  533. package/dist/expr/logic.js +65 -0
  534. package/dist/expr/logic.js.map +1 -0
  535. package/dist/expr/messages.d.ts +45 -0
  536. package/dist/expr/messages.d.ts.map +1 -0
  537. package/dist/expr/messages.js +280 -0
  538. package/dist/expr/messages.js.map +1 -0
  539. package/dist/expr/money.d.ts +38 -0
  540. package/dist/expr/money.d.ts.map +1 -0
  541. package/dist/expr/money.js +127 -0
  542. package/dist/expr/money.js.map +1 -0
  543. package/dist/expr/ordering.d.ts +56 -0
  544. package/dist/expr/ordering.d.ts.map +1 -0
  545. package/dist/expr/ordering.js +167 -0
  546. package/dist/expr/ordering.js.map +1 -0
  547. package/dist/expr/pattern.d.ts +44 -0
  548. package/dist/expr/pattern.d.ts.map +1 -0
  549. package/dist/expr/pattern.js +458 -0
  550. package/dist/expr/pattern.js.map +1 -0
  551. package/dist/expr/plain-date.d.ts +90 -0
  552. package/dist/expr/plain-date.d.ts.map +1 -0
  553. package/dist/expr/plain-date.js +230 -0
  554. package/dist/expr/plain-date.js.map +1 -0
  555. package/dist/expr/plural-categories.d.ts +8 -0
  556. package/dist/expr/plural-categories.d.ts.map +1 -0
  557. package/dist/expr/plural-categories.js +15 -0
  558. package/dist/expr/plural-categories.js.map +1 -0
  559. package/dist/expr/plural-keys.d.ts +39 -0
  560. package/dist/expr/plural-keys.d.ts.map +1 -0
  561. package/dist/expr/plural-keys.js +46 -0
  562. package/dist/expr/plural-keys.js.map +1 -0
  563. package/dist/expr/plural.d.ts +33 -0
  564. package/dist/expr/plural.d.ts.map +1 -0
  565. package/dist/expr/plural.js +50 -0
  566. package/dist/expr/plural.js.map +1 -0
  567. package/dist/expr/quantity.d.ts +31 -0
  568. package/dist/expr/quantity.d.ts.map +1 -0
  569. package/dist/expr/quantity.js +83 -0
  570. package/dist/expr/quantity.js.map +1 -0
  571. package/dist/expr/reduce.d.ts +50 -0
  572. package/dist/expr/reduce.d.ts.map +1 -0
  573. package/dist/expr/reduce.js +236 -0
  574. package/dist/expr/reduce.js.map +1 -0
  575. package/dist/expr/regex.d.ts +108 -0
  576. package/dist/expr/regex.d.ts.map +1 -0
  577. package/dist/expr/regex.js +1210 -0
  578. package/dist/expr/regex.js.map +1 -0
  579. package/dist/expr/select-locale.d.ts +67 -0
  580. package/dist/expr/select-locale.d.ts.map +1 -0
  581. package/dist/expr/select-locale.js +219 -0
  582. package/dist/expr/select-locale.js.map +1 -0
  583. package/dist/expr/sequences.d.ts +123 -0
  584. package/dist/expr/sequences.d.ts.map +1 -0
  585. package/dist/expr/sequences.js +234 -0
  586. package/dist/expr/sequences.js.map +1 -0
  587. package/dist/expr/strings.d.ts +50 -0
  588. package/dist/expr/strings.d.ts.map +1 -0
  589. package/dist/expr/strings.js +184 -0
  590. package/dist/expr/strings.js.map +1 -0
  591. package/dist/expr/validation.d.ts +32 -0
  592. package/dist/expr/validation.d.ts.map +1 -0
  593. package/dist/expr/validation.js +182 -0
  594. package/dist/expr/validation.js.map +1 -0
  595. package/dist/graph/freeze.d.ts +4 -0
  596. package/dist/graph/freeze.d.ts.map +1 -0
  597. package/dist/graph/freeze.js +52 -0
  598. package/dist/graph/freeze.js.map +1 -0
  599. package/dist/graph/index.d.ts +15 -0
  600. package/dist/graph/index.d.ts.map +1 -0
  601. package/dist/graph/index.js +13 -0
  602. package/dist/graph/index.js.map +1 -0
  603. package/dist/graph/inspect.d.ts +76 -0
  604. package/dist/graph/inspect.d.ts.map +1 -0
  605. package/dist/graph/inspect.js +263 -0
  606. package/dist/graph/inspect.js.map +1 -0
  607. package/dist/graph/read-walk.d.ts +101 -0
  608. package/dist/graph/read-walk.d.ts.map +1 -0
  609. package/dist/graph/read-walk.js +358 -0
  610. package/dist/graph/read-walk.js.map +1 -0
  611. package/dist/graph/record-index.d.ts +24 -0
  612. package/dist/graph/record-index.d.ts.map +1 -0
  613. package/dist/graph/record-index.js +35 -0
  614. package/dist/graph/record-index.js.map +1 -0
  615. package/dist/index.d.ts +104 -0
  616. package/dist/index.d.ts.map +1 -0
  617. package/dist/index.js +139 -0
  618. package/dist/index.js.map +1 -0
  619. package/dist/lookup/digest.d.ts +51 -0
  620. package/dist/lookup/digest.d.ts.map +1 -0
  621. package/dist/lookup/digest.js +46 -0
  622. package/dist/lookup/digest.js.map +1 -0
  623. package/dist/lookup/index.d.ts +28 -0
  624. package/dist/lookup/index.d.ts.map +1 -0
  625. package/dist/lookup/index.js +27 -0
  626. package/dist/lookup/index.js.map +1 -0
  627. package/dist/lookup/install.d.ts +48 -0
  628. package/dist/lookup/install.d.ts.map +1 -0
  629. package/dist/lookup/install.js +315 -0
  630. package/dist/lookup/install.js.map +1 -0
  631. package/dist/lookup/pass.d.ts +55 -0
  632. package/dist/lookup/pass.d.ts.map +1 -0
  633. package/dist/lookup/pass.js +212 -0
  634. package/dist/lookup/pass.js.map +1 -0
  635. package/dist/lookup/pins.d.ts +34 -0
  636. package/dist/lookup/pins.d.ts.map +1 -0
  637. package/dist/lookup/pins.js +39 -0
  638. package/dist/lookup/pins.js.map +1 -0
  639. package/dist/lookup/provenance.d.ts +23 -0
  640. package/dist/lookup/provenance.d.ts.map +1 -0
  641. package/dist/lookup/provenance.js +78 -0
  642. package/dist/lookup/provenance.js.map +1 -0
  643. package/dist/lookup/readiness.d.ts +13 -0
  644. package/dist/lookup/readiness.d.ts.map +1 -0
  645. package/dist/lookup/readiness.js +57 -0
  646. package/dist/lookup/readiness.js.map +1 -0
  647. package/dist/lookup/resolve.d.ts +24 -0
  648. package/dist/lookup/resolve.d.ts.map +1 -0
  649. package/dist/lookup/resolve.js +201 -0
  650. package/dist/lookup/resolve.js.map +1 -0
  651. package/dist/lookup/store.d.ts +41 -0
  652. package/dist/lookup/store.d.ts.map +1 -0
  653. package/dist/lookup/store.js +74 -0
  654. package/dist/lookup/store.js.map +1 -0
  655. package/dist/model/access.d.ts +200 -0
  656. package/dist/model/access.d.ts.map +1 -0
  657. package/dist/model/access.js +125 -0
  658. package/dist/model/access.js.map +1 -0
  659. package/dist/model/artifact-members.d.ts +3 -0
  660. package/dist/model/artifact-members.d.ts.map +1 -0
  661. package/dist/model/artifact-members.js +38 -0
  662. package/dist/model/artifact-members.js.map +1 -0
  663. package/dist/model/composition.d.ts +47 -0
  664. package/dist/model/composition.d.ts.map +1 -0
  665. package/dist/model/composition.js +66 -0
  666. package/dist/model/composition.js.map +1 -0
  667. package/dist/model/domain.d.ts +51 -0
  668. package/dist/model/domain.d.ts.map +1 -0
  669. package/dist/model/domain.js +75 -0
  670. package/dist/model/domain.js.map +1 -0
  671. package/dist/model/duration.d.ts +31 -0
  672. package/dist/model/duration.d.ts.map +1 -0
  673. package/dist/model/duration.js +136 -0
  674. package/dist/model/duration.js.map +1 -0
  675. package/dist/model/errors.d.ts +58 -0
  676. package/dist/model/errors.d.ts.map +1 -0
  677. package/dist/model/errors.js +81 -0
  678. package/dist/model/errors.js.map +1 -0
  679. package/dist/model/evolution.d.ts +177 -0
  680. package/dist/model/evolution.d.ts.map +1 -0
  681. package/dist/model/evolution.js +5 -0
  682. package/dist/model/evolution.js.map +1 -0
  683. package/dist/model/expr-children.d.ts +15 -0
  684. package/dist/model/expr-children.d.ts.map +1 -0
  685. package/dist/model/expr-children.js +45 -0
  686. package/dist/model/expr-children.js.map +1 -0
  687. package/dist/model/guards.d.ts +9 -0
  688. package/dist/model/guards.d.ts.map +1 -0
  689. package/dist/model/guards.js +11 -0
  690. package/dist/model/guards.js.map +1 -0
  691. package/dist/model/input.d.ts +42 -0
  692. package/dist/model/input.d.ts.map +1 -0
  693. package/dist/model/input.js +26 -0
  694. package/dist/model/input.js.map +1 -0
  695. package/dist/model/integer.d.ts +14 -0
  696. package/dist/model/integer.d.ts.map +1 -0
  697. package/dist/model/integer.js +16 -0
  698. package/dist/model/integer.js.map +1 -0
  699. package/dist/model/intrinsic.d.ts +18 -0
  700. package/dist/model/intrinsic.d.ts.map +1 -0
  701. package/dist/model/intrinsic.js +21 -0
  702. package/dist/model/intrinsic.js.map +1 -0
  703. package/dist/model/layout.d.ts +129 -0
  704. package/dist/model/layout.d.ts.map +1 -0
  705. package/dist/model/layout.js +2 -0
  706. package/dist/model/layout.js.map +1 -0
  707. package/dist/model/media.d.ts +33 -0
  708. package/dist/model/media.d.ts.map +1 -0
  709. package/dist/model/media.js +86 -0
  710. package/dist/model/media.js.map +1 -0
  711. package/dist/model/members.generated.d.ts +11 -0
  712. package/dist/model/members.generated.d.ts.map +1 -0
  713. package/dist/model/members.generated.js +71 -0
  714. package/dist/model/members.generated.js.map +1 -0
  715. package/dist/model/row-address.d.ts +27 -0
  716. package/dist/model/row-address.d.ts.map +1 -0
  717. package/dist/model/row-address.js +146 -0
  718. package/dist/model/row-address.js.map +1 -0
  719. package/dist/model/schema.d.ts +108 -0
  720. package/dist/model/schema.d.ts.map +1 -0
  721. package/dist/model/schema.js +2 -0
  722. package/dist/model/schema.js.map +1 -0
  723. package/dist/model/shape.d.ts +193 -0
  724. package/dist/model/shape.d.ts.map +1 -0
  725. package/dist/model/shape.js +2 -0
  726. package/dist/model/shape.js.map +1 -0
  727. package/dist/model/time.d.ts +61 -0
  728. package/dist/model/time.d.ts.map +1 -0
  729. package/dist/model/time.js +110 -0
  730. package/dist/model/time.js.map +1 -0
  731. package/dist/model/types.d.ts +1329 -0
  732. package/dist/model/types.d.ts.map +1 -0
  733. package/dist/model/types.js +424 -0
  734. package/dist/model/types.js.map +1 -0
  735. package/dist/model/values.d.ts +91 -0
  736. package/dist/model/values.d.ts.map +1 -0
  737. package/dist/model/values.js +195 -0
  738. package/dist/model/values.js.map +1 -0
  739. package/dist/model/wire.d.ts +356 -0
  740. package/dist/model/wire.d.ts.map +1 -0
  741. package/dist/model/wire.js +1504 -0
  742. package/dist/model/wire.js.map +1 -0
  743. package/dist/offline/index.d.ts +374 -0
  744. package/dist/offline/index.d.ts.map +1 -0
  745. package/dist/offline/index.js +422 -0
  746. package/dist/offline/index.js.map +1 -0
  747. package/dist/testing.d.ts +30 -0
  748. package/dist/testing.d.ts.map +1 -0
  749. package/dist/testing.js +42 -0
  750. package/dist/testing.js.map +1 -0
  751. package/dist/version.d.ts +30 -0
  752. package/dist/version.d.ts.map +1 -0
  753. package/dist/version.js +116 -0
  754. package/dist/version.js.map +1 -0
  755. package/package.json +98 -3
@@ -0,0 +1,1210 @@
1
+ import { AxiomError } from '../model/errors.js';
2
+ import { codePointLength } from './strings.js';
3
+ /**
4
+ * `matches(s, pattern, flags?)`: JavaScript regular-expression search with Unicode semantics,
5
+ * `spec/semantics/expr-v1.md` `EXPR-14.1.12` to `EXPR-14.1.14`.
6
+ *
7
+ * Four properties make this operator defensible to ship:
8
+ *
9
+ * 1. **One dialect.** The pattern is an ECMAScript regular expression with the `u` flag always
10
+ * set, so `\p{L}`, `\p{Script=Han}` and an astral character are one expression each and the
11
+ * answer never depends on the host locale. `i`, `m` and `s` are the only other flags the
12
+ * language admits; `g`, `y` and `d` describe state or indices a boolean test has no use for.
13
+ * 2. **A bounded subject.** A subject longer than {@link REGEX_SUBJECT_LIMIT} code points is
14
+ * refused before the engine runs, so no authored pattern can be used to scan a document
15
+ * field of unbounded size.
16
+ * 3. **The classic exponential shapes are refused.** {@link unsafePattern} refuses a repeated
17
+ * group whose body is variable or whose alternation overlaps, and a run of adjacent variable
18
+ * quantifiers whose operands can match the same text (`a?a?…`, `\d*\d*…`). A pattern that
19
+ * arrives as a value is analysed by the same scan before the engine runs.
20
+ * 4. **Every call has a work ceiling.** A family scan can always be beaten by a shape it does
21
+ * not name, so the engine is never handed a pattern whose conservative backtracking bound at
22
+ * this subject length exceeds {@link REGEX_MATCH_WORK_LIMIT}. The bound is computed from the
23
+ * parsed source and the subject length, not measured after the fact, so a hostile computed
24
+ * pattern is refused with `unsafe-pattern` instead of spending a request's latency.
25
+ *
26
+ * The compiled `RegExp` is cached per `(pattern, flags)`, so an item-scoped rule over a
27
+ * thousand rows compiles one pattern and tests a thousand subjects.
28
+ */
29
+ /** The subject cap in code points: a longer input is refused, never scanned and never `false`. */
30
+ export const REGEX_SUBJECT_LIMIT = 4096;
31
+ /**
32
+ * The per-call work ceiling, in backtracking steps.
33
+ *
34
+ * A step stands for one path the engine may try or one character it may revisit. The estimate
35
+ * below is deliberately conservative, so a pattern can be refused while its ordinary cost is
36
+ * lower; the alternative, running an unbounded engine on the renderer's thread, is the failure
37
+ * this ceiling exists to prevent. The value matches the `ascii_match` matcher's budget, so the
38
+ * two pattern operators refuse at the same order of work.
39
+ */
40
+ const REGEX_MATCH_WORK_LIMIT = 24_000_000;
41
+ /** The optional flags an author may write, in the canonical order the cache keys on. */
42
+ export const REGEX_FLAGS = ['i', 'm', 's'];
43
+ /** The flag string every compiled pattern carries: `u` is not optional. */
44
+ export const BASE_REGEX_FLAGS = 'u';
45
+ /** How many `(pattern, flags)` pairs the evaluator keeps compiled at once. */
46
+ const REGEX_CACHE_LIMIT = 256;
47
+ /**
48
+ * The canonical flag string for one authored `flags` operand, or the refusal naming the
49
+ * offending flag.
50
+ *
51
+ * The author writes a subset of `ims`; `u` is added here rather than accepted, so a document
52
+ * cannot opt out of Unicode semantics by writing `g` or by writing nothing.
53
+ */
54
+ export function canonicalFlags(flags) {
55
+ const seen = new Set();
56
+ let canonical = BASE_REGEX_FLAGS;
57
+ for (const flag of flags) {
58
+ if (!REGEX_FLAGS.includes(flag)) {
59
+ return {
60
+ kind: 'invalid-flags',
61
+ detail: `\`${flag}\` is not a supported flag; write \`i\`, \`m\`, \`s\` or omit the operand (the \`u\` flag is always on, and \`g\`, \`y\` and \`d\` are not available)`,
62
+ };
63
+ }
64
+ if (seen.has(flag)) {
65
+ return {
66
+ kind: 'invalid-flags',
67
+ detail: `flag \`${flag}\` is written twice; a flag may appear once`,
68
+ };
69
+ }
70
+ seen.add(flag);
71
+ }
72
+ // Canonicalising the order keeps `im` and `mi` one cache entry, exactly as `RegExp` treats
73
+ // them as one flag set.
74
+ for (const flag of REGEX_FLAGS) {
75
+ if (seen.has(flag))
76
+ canonical += flag;
77
+ }
78
+ return { kind: 'ok', flags: canonical };
79
+ }
80
+ /** The length of a quantifier at `index`, or 0 when the character there is a literal. */
81
+ function quantifierLength(source, index) {
82
+ const character = source[index];
83
+ if (character === '*' || character === '+' || character === '?')
84
+ return 1;
85
+ if (character !== '{')
86
+ return 0;
87
+ const match = /^\{[0-9]+(?:,[0-9]*)?\}/.exec(source.slice(index));
88
+ return match === null ? 0 : match[0].length;
89
+ }
90
+ function quantifierBounds(source, index) {
91
+ const character = source[index];
92
+ if (character === '?')
93
+ return { min: 0, max: 1, variable: true };
94
+ if (character === '*')
95
+ return { min: 0, max: Number.POSITIVE_INFINITY, variable: true };
96
+ if (character === '+')
97
+ return { min: 1, max: Number.POSITIVE_INFINITY, variable: true };
98
+ if (character !== '{')
99
+ return undefined;
100
+ const match = /^\{([0-9]+)(?:,([0-9]*))?\}/.exec(source.slice(index));
101
+ if (match === null)
102
+ return undefined;
103
+ const min = Number(match[1]);
104
+ // `{n}` is one count; `{n,}` and `{n,m}` vary.
105
+ if (match[2] === undefined)
106
+ return { min, max: min, variable: false };
107
+ const max = match[2] === '' ? Number.POSITIVE_INFINITY : Number(match[2]);
108
+ return { min, max, variable: true };
109
+ }
110
+ /**
111
+ * Whether the construct at `index` repeats its operand at least twice, which is what turns a
112
+ * nested ambiguity into exponential work. `?` is absent: it repeats zero or one time.
113
+ */
114
+ function quantifierRepeats(source, index) {
115
+ const bounds = quantifierBounds(source, index);
116
+ if (bounds === undefined)
117
+ return false;
118
+ return bounds.max === Number.POSITIVE_INFINITY || bounds.max >= 2;
119
+ }
120
+ /** The index of the first body character after a `(` at `index`, skipping a group prefix. */
121
+ function afterGroupPrefix(source, index) {
122
+ let cursor = index + 1;
123
+ if (source[cursor] !== '?')
124
+ return cursor;
125
+ cursor += 1;
126
+ const marker = source[cursor];
127
+ if (marker === ':')
128
+ return cursor + 1;
129
+ if (marker === '=' || marker === '!')
130
+ return cursor + 1;
131
+ if (marker === '<') {
132
+ const next = source[cursor + 1];
133
+ // `(?<=` and `(?<!` are lookbehind assertions, not named groups: the `>` belongs to no
134
+ // prefix here, and searching for one would swallow the body.
135
+ if (next === '=' || next === '!')
136
+ return cursor + 2;
137
+ const close = source.indexOf('>', cursor);
138
+ return close === -1 ? cursor + 1 : close + 1;
139
+ }
140
+ return cursor;
141
+ }
142
+ /** Whether a group at `index` is a lookahead or lookbehind assertion, which consumes nothing. */
143
+ function groupIsLookaround(source, index) {
144
+ if (source[index + 1] !== '?')
145
+ return false;
146
+ const marker = source[index + 2];
147
+ return (marker === '=' ||
148
+ marker === '!' ||
149
+ (marker === '<' && (source[index + 3] === '=' || source[index + 3] === '!')));
150
+ }
151
+ /**
152
+ * Whether `(` at `index` opens an ES2025 inline modifier group (`(?i:...)`, `(?-m:...)`,
153
+ * `(?im-s:...)`).
154
+ *
155
+ * Inline modifier groups are outside the ES2023 / Hermes V1 runtime floor and change `i`/`m`/`s`
156
+ * scoping mid-pattern, so the safety scan refuses them explicitly.
157
+ */
158
+ function isInlineModifierGroup(source, index) {
159
+ if (source[index + 1] !== '?')
160
+ return false;
161
+ return /^\(\?(?:[ims]+(?:-[ims]*)?|-[ims]+):/.test(source.slice(index));
162
+ }
163
+ const DIGIT_RANGES = [[0x30, 0x39]];
164
+ const WORD_RANGES = [
165
+ [0x30, 0x39],
166
+ [0x41, 0x5a],
167
+ [0x5f, 0x5f],
168
+ [0x61, 0x7a],
169
+ ];
170
+ /** The ECMAScript `\s` set: WhiteSpace and LineTerminator, as ranges of code points. */
171
+ const SPACE_RANGES = [
172
+ [0x09, 0x0d],
173
+ [0x20, 0x20],
174
+ [0xa0, 0xa0],
175
+ [0x1680, 0x1680],
176
+ [0x2000, 0x200a],
177
+ [0x2028, 0x2029],
178
+ [0x202f, 0x202f],
179
+ [0x205f, 0x205f],
180
+ [0x3000, 0x3000],
181
+ [0xfeff, 0xfeff],
182
+ ];
183
+ /** The branch being written in one frame, or `undefined` outside every group. */
184
+ function currentBranch(frame) {
185
+ if (frame.open === -1)
186
+ return undefined;
187
+ return frame.branches[frame.branches.length - 1];
188
+ }
189
+ /** The active branch of `frame`, including the top-level root frame. */
190
+ function activeBranch(frame) {
191
+ const branch = frame.branches[frame.branches.length - 1];
192
+ if (branch === undefined) {
193
+ const created = newBranch();
194
+ frame.branches.push(created);
195
+ return created;
196
+ }
197
+ return branch;
198
+ }
199
+ function newBranch() {
200
+ return {
201
+ leadingPrefix: '',
202
+ acceptingPrefix: true,
203
+ closed: true,
204
+ lastPrefixStart: 0,
205
+ atStart: true,
206
+ anchoredStart: false,
207
+ items: [],
208
+ };
209
+ }
210
+ /** Whether any two alternation branches can match the same input prefix. */
211
+ function branchesOverlap(frame, caseInsensitive) {
212
+ if (frame.branches.length < 2)
213
+ return false;
214
+ // One non-closed construct is enough: `.`, a character class, a shorthand escape (`\d`, `\w`,
215
+ // `\s`), a backreference, a quantified atom, or a multi-branch nested group can match text
216
+ // another branch begins with. Only closed literal branches can be proven disjoint.
217
+ if (frame.branches.some((branch) => !branch.closed))
218
+ return true;
219
+ for (let left = 0; left < frame.branches.length; left += 1) {
220
+ for (let right = left + 1; right < frame.branches.length; right += 1) {
221
+ const leftBranch = frame.branches[left]?.leadingPrefix ?? '';
222
+ const rightBranch = frame.branches[right]?.leadingPrefix ?? '';
223
+ if (textPrefixesOverlap(leftBranch, rightBranch, caseInsensitive))
224
+ return true;
225
+ }
226
+ }
227
+ return false;
228
+ }
229
+ /** The guaranteed leading literal text every branch begins with, compared by code point. */
230
+ function commonPrefix(branches) {
231
+ let prefix = branches[0]?.leadingPrefix ?? '';
232
+ for (const branch of branches.slice(1)) {
233
+ let index = 0;
234
+ while (index < prefix.length && index < branch.leadingPrefix.length) {
235
+ const left = prefix.codePointAt(index) ?? 0;
236
+ const right = branch.leadingPrefix.codePointAt(index) ?? 0;
237
+ if (left !== right)
238
+ break;
239
+ index += left > 0xffff ? 2 : 1;
240
+ }
241
+ prefix = prefix.slice(0, index);
242
+ if (prefix === '')
243
+ break;
244
+ }
245
+ return prefix;
246
+ }
247
+ /**
248
+ * Whether an escape names literal text rather than a character set. `\.`, `\/` and `\-` are one
249
+ * character each; `\d`, `\w`, `\s`, `\p{…}`, `\u{…}` and a backreference are not, so they are
250
+ * treated as open.
251
+ */
252
+ function escapedLiteral(escaped) {
253
+ return escaped !== '' && !/[A-Za-z0-9]/.test(escaped);
254
+ }
255
+ /** The text one escape stands for, or `undefined` when its first character set is not known. */
256
+ function escapeText(escaped) {
257
+ switch (escaped) {
258
+ case 'n':
259
+ return '\n';
260
+ case 'r':
261
+ return '\r';
262
+ case 't':
263
+ return '\t';
264
+ case 'f':
265
+ return '\f';
266
+ case 'v':
267
+ return '\v';
268
+ case '0':
269
+ return '\0';
270
+ default:
271
+ return escapedLiteral(escaped) ? escaped : undefined;
272
+ }
273
+ }
274
+ function inRanges(ranges, code) {
275
+ for (const [from, to] of ranges) {
276
+ if (code >= from && code <= to)
277
+ return true;
278
+ }
279
+ return false;
280
+ }
281
+ /** Whether every code point of `inner` is a member of one of `outer`'s ranges. */
282
+ function rangesCoveredBy(inner, outer) {
283
+ for (const [from, to] of inner) {
284
+ let cursor = from;
285
+ while (cursor <= to) {
286
+ let next = -1;
287
+ for (const [outerFrom, outerTo] of outer) {
288
+ if (cursor >= outerFrom && cursor <= outerTo) {
289
+ next = outerTo + 1;
290
+ break;
291
+ }
292
+ }
293
+ if (next === -1)
294
+ return false;
295
+ cursor = next;
296
+ }
297
+ }
298
+ return true;
299
+ }
300
+ function setsOverlap(left, right) {
301
+ if (!left.negated && !right.negated) {
302
+ for (const [leftFrom, leftTo] of left.ranges) {
303
+ for (const [rightFrom, rightTo] of right.ranges) {
304
+ if (leftFrom <= rightTo && rightFrom <= leftTo)
305
+ return true;
306
+ }
307
+ }
308
+ return false;
309
+ }
310
+ // A negated set overlaps unless the positive side lies wholly inside the excluded ranges.
311
+ if (left.negated && !right.negated)
312
+ return !rangesCoveredBy(right.ranges, left.ranges);
313
+ if (!left.negated && right.negated)
314
+ return !rangesCoveredBy(left.ranges, right.ranges);
315
+ return true;
316
+ }
317
+ function isAsciiLetter(code) {
318
+ return (code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a);
319
+ }
320
+ function isAsciiNonLetter(code) {
321
+ return code >= 0 && code <= 0x7f && !isAsciiLetter(code);
322
+ }
323
+ function isAsciiNonLetterRange(from, to) {
324
+ if (from < 0 || to > 0x7f)
325
+ return false;
326
+ if (from <= 0x5a && to >= 0x41)
327
+ return false;
328
+ if (from <= 0x7a && to >= 0x61)
329
+ return false;
330
+ return true;
331
+ }
332
+ /**
333
+ * Whether two literal prefixes can match text beginning the same way under the active `i` flag.
334
+ *
335
+ * Under `/iu`, ASCII non-letters participate in no Unicode simple case folding, so a mismatch
336
+ * involving one proves disjointness. Any other differing pair (ASCII letters or non-ASCII code
337
+ * points such as `\u017f` or `\u212a`) is treated conservatively as overlapping without relying
338
+ * on `.toLowerCase()`.
339
+ */
340
+ function textPrefixesOverlap(left, right, caseInsensitive) {
341
+ if (left === '' || right === '')
342
+ return true;
343
+ if (!caseInsensitive) {
344
+ return left.startsWith(right) || right.startsWith(left);
345
+ }
346
+ let leftIndex = 0;
347
+ let rightIndex = 0;
348
+ while (leftIndex < left.length && rightIndex < right.length) {
349
+ const leftCode = left.codePointAt(leftIndex) ?? 0;
350
+ const rightCode = right.codePointAt(rightIndex) ?? 0;
351
+ if (leftCode !== rightCode) {
352
+ return !(isAsciiNonLetter(leftCode) || isAsciiNonLetter(rightCode));
353
+ }
354
+ leftIndex += leftCode > 0xffff ? 2 : 1;
355
+ rightIndex += rightCode > 0xffff ? 2 : 1;
356
+ }
357
+ return true;
358
+ }
359
+ /**
360
+ * Whether an operand matches only ASCII non-letter code points, which participate in no Unicode
361
+ * simple case folding under the `iu` flags.
362
+ */
363
+ function isCaseInvariantOperand(operand) {
364
+ if (operand.kind === 'text') {
365
+ if (operand.text === '')
366
+ return false;
367
+ const code = operand.text.codePointAt(0) ?? 0;
368
+ return isAsciiNonLetter(code);
369
+ }
370
+ if (operand.kind === 'set' && !operand.negated) {
371
+ return operand.ranges.every(([from, to]) => isAsciiNonLetterRange(from, to));
372
+ }
373
+ return false;
374
+ }
375
+ /** Whether two quantified operands can match text that begins the same way. */
376
+ function operandsOverlap(left, right) {
377
+ if (left.kind === 'unknown' || right.kind === 'unknown')
378
+ return true;
379
+ if (left.kind === 'any' || right.kind === 'any')
380
+ return true;
381
+ if (left.kind === 'text' && right.kind === 'text') {
382
+ return textPrefixesOverlap(left.text, right.text, false);
383
+ }
384
+ if (left.kind === 'text' && right.kind === 'set') {
385
+ const first = left.text.codePointAt(0) ?? 0;
386
+ return inRanges(right.ranges, first) !== right.negated;
387
+ }
388
+ if (left.kind === 'set' && right.kind === 'text') {
389
+ const first = right.text.codePointAt(0) ?? 0;
390
+ return inRanges(left.ranges, first) !== left.negated;
391
+ }
392
+ if (left.kind === 'set' && right.kind === 'set')
393
+ return setsOverlap(left, right);
394
+ return true;
395
+ }
396
+ /** Whether two operands can match text beginning the same way under the active `i` flag. */
397
+ function operandsOverlapWithFlags(left, right, caseInsensitive) {
398
+ if (!caseInsensitive)
399
+ return operandsOverlap(left, right);
400
+ if (left.kind === 'text' && right.kind === 'text') {
401
+ return textPrefixesOverlap(left.text, right.text, true);
402
+ }
403
+ if (isCaseInvariantOperand(left) || isCaseInvariantOperand(right)) {
404
+ return operandsOverlap(left, right);
405
+ }
406
+ return true;
407
+ }
408
+ /** The operand one group body presents: its guaranteed leading literal prefix, or unknown. */
409
+ function operandFromBody(body) {
410
+ return body.leadingPrefix === ''
411
+ ? { kind: 'unknown' }
412
+ : { kind: 'text', text: body.leadingPrefix };
413
+ }
414
+ /** The pattern cap in code units: analysis reads every character, so a longer value is refused. */
415
+ const REGEX_PATTERN_LIMIT = 4096;
416
+ const WORK_CAP = REGEX_MATCH_WORK_LIMIT + 1;
417
+ /** Adds two work estimates, saturating at one above the ceiling rather than overflowing. */
418
+ function addWork(left, right) {
419
+ if (left >= WORK_CAP || right >= WORK_CAP)
420
+ return WORK_CAP;
421
+ const sum = left + right;
422
+ return sum >= WORK_CAP ? WORK_CAP : sum;
423
+ }
424
+ /** Multiplies two work estimates, saturating at one above the ceiling rather than overflowing. */
425
+ function multiplyWork(left, right) {
426
+ if (left <= 0 || right <= 0)
427
+ return 0;
428
+ if (left >= WORK_CAP || right >= WORK_CAP)
429
+ return WORK_CAP;
430
+ return left > WORK_CAP / right ? WORK_CAP : left * right;
431
+ }
432
+ /** The number of repetition counts one quantifier can choose, capped by subject length. */
433
+ function quantifierWork(bounds, subjectLength) {
434
+ if (!bounds.variable)
435
+ return 1;
436
+ if (bounds.min > subjectLength)
437
+ return 1;
438
+ const maxRepeats = bounds.max === Number.POSITIVE_INFINITY ? subjectLength : Math.min(bounds.max, subjectLength);
439
+ return Math.max(1, maxRepeats - bounds.min + 1);
440
+ }
441
+ function composeWork(first, then) {
442
+ return {
443
+ overhead: addWork(first.overhead, multiplyWork(first.multiplier, then.overhead)),
444
+ multiplier: multiplyWork(first.multiplier, then.multiplier),
445
+ };
446
+ }
447
+ /** Composes one affine work profile with itself `count` times, saturating at `WORK_CAP`. */
448
+ function repeatWork(profile, count) {
449
+ if (count <= 0)
450
+ return { overhead: 0, multiplier: 1 };
451
+ let result = { overhead: 0, multiplier: 1 };
452
+ let base = profile;
453
+ let remaining = count;
454
+ while (remaining > 0) {
455
+ if ((remaining & 1) === 1) {
456
+ result = composeWork(result, base);
457
+ if (result.overhead >= WORK_CAP && result.multiplier >= WORK_CAP) {
458
+ return { overhead: WORK_CAP, multiplier: WORK_CAP };
459
+ }
460
+ }
461
+ remaining = Math.floor(remaining / 2);
462
+ if (remaining > 0)
463
+ base = composeWork(base, base);
464
+ }
465
+ return result;
466
+ }
467
+ function sumWork(branches, disjoint = false) {
468
+ let overhead = 0;
469
+ let multiplier = 0;
470
+ for (const branch of branches) {
471
+ overhead = addWork(overhead, branch.overhead);
472
+ multiplier = disjoint
473
+ ? Math.max(multiplier, branch.multiplier)
474
+ : addWork(multiplier, branch.multiplier);
475
+ }
476
+ return { overhead, multiplier };
477
+ }
478
+ /** The first code point of a guaranteed leading literal prefix, or `undefined` when empty. */
479
+ function leadingOperandFromPrefix(prefix) {
480
+ if (prefix === '')
481
+ return undefined;
482
+ const codePoint = prefix.codePointAt(0);
483
+ if (codePoint === undefined)
484
+ return undefined;
485
+ return { kind: 'text', text: String.fromCodePoint(codePoint) };
486
+ }
487
+ /** Whether a parsed branch item can never consume input. */
488
+ function isZeroWidthItem(item) {
489
+ switch (item.kind) {
490
+ case 'assertion':
491
+ return true;
492
+ case 'atom':
493
+ case 'backref':
494
+ return item.bounds?.max === 0;
495
+ case 'group':
496
+ return item.lookaround || item.zeroWidth || item.bounds?.max === 0;
497
+ }
498
+ }
499
+ function allAssertionsFrom(items, startIndex) {
500
+ for (let index = startIndex; index < items.length; index += 1) {
501
+ if (items[index]?.kind !== 'assertion')
502
+ return false;
503
+ }
504
+ return true;
505
+ }
506
+ function isDisjointBarrier(item, items, nextIndex, atPatternEnd, caseInsensitive) {
507
+ if (!item.singleChar)
508
+ return false;
509
+ const next = items[nextIndex];
510
+ if (next === undefined)
511
+ return false;
512
+ if (next.kind === 'atom') {
513
+ if (!next.singleChar)
514
+ return false;
515
+ if (next.bounds !== undefined && next.bounds.min < 1)
516
+ return false;
517
+ return !operandsOverlapWithFlags(item.operand, next.operand, caseInsensitive);
518
+ }
519
+ if (next.kind === 'group') {
520
+ if (next.lookaround || next.leadingOperand === undefined || next.bounds?.max === 0) {
521
+ return false;
522
+ }
523
+ const required = next.bounds === undefined || next.bounds.min >= 1;
524
+ const tailOnlyAssertions = atPatternEnd && allAssertionsFrom(items, nextIndex + 1);
525
+ if (!required && !tailOnlyAssertions)
526
+ return false;
527
+ return !operandsOverlapWithFlags(item.operand, next.leadingOperand, caseInsensitive);
528
+ }
529
+ return false;
530
+ }
531
+ function itemWorkProfile(item, items, nextIndex, atPatternEnd, subjectLength, caseInsensitive) {
532
+ switch (item.kind) {
533
+ case 'assertion':
534
+ return { overhead: 0, multiplier: 1 };
535
+ case 'backref': {
536
+ const base = subjectLength + 1;
537
+ const factor = item.bounds?.variable === true
538
+ ? multiplyWork(base, quantifierWork(item.bounds, subjectLength))
539
+ : base;
540
+ return { overhead: 0, multiplier: factor };
541
+ }
542
+ case 'group': {
543
+ if (item.lookaround) {
544
+ const inner = addWork(item.profile.overhead, item.profile.multiplier);
545
+ if (item.bounds?.variable === true) {
546
+ const repeats = quantifierWork(item.bounds, subjectLength);
547
+ return { overhead: multiplyWork(repeats, inner), multiplier: repeats };
548
+ }
549
+ if (item.bounds !== undefined) {
550
+ if (item.bounds.max === 0)
551
+ return { overhead: 0, multiplier: 1 };
552
+ if (item.bounds.min > 1) {
553
+ return { overhead: multiplyWork(item.bounds.min, inner), multiplier: 1 };
554
+ }
555
+ }
556
+ return { overhead: inner, multiplier: 1 };
557
+ }
558
+ if (item.bounds?.variable === true) {
559
+ const repeats = quantifierWork(item.bounds, subjectLength);
560
+ const maxRepeats = item.bounds.max === Number.POSITIVE_INFINITY
561
+ ? subjectLength
562
+ : Math.min(item.bounds.max, subjectLength);
563
+ const repeated = repeatWork(item.profile, maxRepeats);
564
+ return {
565
+ overhead: repeated.overhead,
566
+ multiplier: multiplyWork(repeats, repeated.multiplier),
567
+ };
568
+ }
569
+ if (item.bounds !== undefined) {
570
+ if (item.bounds.max === 0)
571
+ return { overhead: 0, multiplier: 1 };
572
+ if (item.bounds.min > 1) {
573
+ return repeatWork(item.profile, item.bounds.min);
574
+ }
575
+ }
576
+ return item.profile;
577
+ }
578
+ case 'atom': {
579
+ if (item.bounds === undefined || !item.bounds.variable) {
580
+ return { overhead: 1, multiplier: 1 };
581
+ }
582
+ const repeats = quantifierWork(item.bounds, subjectLength);
583
+ if (isDisjointBarrier(item, items, nextIndex, atPatternEnd, caseInsensitive)) {
584
+ // A quantified single-char atom followed by a disjoint required atom, a disjoint required
585
+ // group, or a disjoint optional group at the end of the pattern can enter the continuation
586
+ // at most once per entry, so its scan and failback steps are additive.
587
+ return { overhead: repeats, multiplier: 1 };
588
+ }
589
+ return { overhead: 0, multiplier: repeats };
590
+ }
591
+ }
592
+ }
593
+ function branchWork(items, subjectLength, caseInsensitive, atPatternEnd) {
594
+ let profile = { overhead: 0, multiplier: 1 };
595
+ for (let index = items.length - 1; index >= 0; index -= 1) {
596
+ const item = items[index];
597
+ if (item === undefined)
598
+ continue;
599
+ profile = composeWork(itemWorkProfile(item, items, index + 1, atPatternEnd, subjectLength, caseInsensitive), profile);
600
+ }
601
+ return profile;
602
+ }
603
+ function newFrame(open, lookaround) {
604
+ return {
605
+ open,
606
+ branches: [newBranch()],
607
+ variableQuantifier: false,
608
+ nestedVariableQuantifier: false,
609
+ nestedOverlappingAlternation: false,
610
+ current: undefined,
611
+ previous: undefined,
612
+ lookaround,
613
+ };
614
+ }
615
+ /** Records that the current branch encountered a non-literal construct. */
616
+ function markOpen(frame) {
617
+ const branch = currentBranch(frame);
618
+ if (branch === undefined)
619
+ return;
620
+ branch.closed = false;
621
+ branch.acceptingPrefix = false;
622
+ branch.lastPrefixStart = branch.leadingPrefix.length;
623
+ }
624
+ /** Prevents a trailing quantifier on a zero-width construct from rolling back an earlier literal. */
625
+ function resetPrefixAnchor(frame) {
626
+ const branch = currentBranch(frame);
627
+ if (branch !== undefined)
628
+ branch.lastPrefixStart = branch.leadingPrefix.length;
629
+ }
630
+ /** Appends literal text to the current branch's guaranteed leading prefix when still accepting. */
631
+ function appendLiteral(frame, text) {
632
+ const branch = currentBranch(frame);
633
+ if (branch === undefined)
634
+ return;
635
+ branch.lastPrefixStart = branch.leadingPrefix.length;
636
+ if (branch.acceptingPrefix)
637
+ branch.leadingPrefix += text;
638
+ }
639
+ /**
640
+ * Updates branch prefix and closedness when a quantifier applies to the previous atom.
641
+ *
642
+ * Any quantifier other than an exact `{1}` opens the branch for alternation overlap and stops
643
+ * extending `leadingPrefix` (so `a{2}b` cannot masquerade as `ab`). When `min === 0`, the
644
+ * optional atom's contribution to `leadingPrefix` is removed.
645
+ */
646
+ function applyQuantifierToBranch(frame, bounds) {
647
+ if (!bounds.variable && bounds.min === 1 && bounds.max === 1)
648
+ return;
649
+ const branch = currentBranch(frame);
650
+ if (branch === undefined)
651
+ return;
652
+ branch.closed = false;
653
+ branch.acceptingPrefix = false;
654
+ if (bounds.min === 0) {
655
+ branch.leadingPrefix = branch.leadingPrefix.slice(0, branch.lastPrefixStart);
656
+ }
657
+ branch.lastPrefixStart = branch.leadingPrefix.length;
658
+ }
659
+ /** Starts a new consuming atom at this level, keeping the previous one for an adjacency test. */
660
+ function noteAtom(frame, operand) {
661
+ frame.previous = frame.current?.variable === true ? frame.current : undefined;
662
+ frame.current = { operand, variable: false };
663
+ }
664
+ /**
665
+ * Records that the current atom carries a quantifier, and refuses a run of adjacent variable
666
+ * quantifiers whose operands can match the same text.
667
+ *
668
+ * Two optional `a`s in a row are the same exponential family as `(a+)+`: the engine chooses how
669
+ * each of them partitions the same input, so `n` optionals have 2ⁿ paths. A separator neither
670
+ * operand can match, such as the digits after the letters in `[A-Za-z]+[0-9]+`, leaves only one
671
+ * partition and is admitted.
672
+ */
673
+ function markQuantified(frame, bounds, caseInsensitive, refusal) {
674
+ if (bounds === undefined || !bounds.variable)
675
+ return;
676
+ frame.variableQuantifier = true;
677
+ const current = frame.current;
678
+ if (current === undefined)
679
+ return;
680
+ current.variable = true;
681
+ const previous = frame.previous;
682
+ if (previous !== undefined &&
683
+ operandsOverlapWithFlags(previous.operand, current.operand, caseInsensitive)) {
684
+ refusal.adjacent ??=
685
+ 'a run of adjacent variable quantifiers can match the same text, which backtracks exponentially as the run grows; separate them with a character one operand cannot match, such as `[A-Za-z]+[0-9]+` instead of `[A-Za-z0-9]+[A-Za-z0-9]+`';
686
+ }
687
+ }
688
+ /**
689
+ * The classic catastrophic-backtracking shapes, as a structural scan of the source text.
690
+ *
691
+ * The three families are the ones an author can write by accident and an engine cannot escape:
692
+ *
693
+ * - **A repeated group whose body is itself variable** (`(a+)+`, `(\w*)*`, `(a?)+`): the inner
694
+ * repetition is free to re-partition the same text, so the outer one explores an exponential
695
+ * number of partitions.
696
+ * - **A repeated group whose alternation has branches that can match the same prefix**
697
+ * (`(a|ab)+`, `(?:(?:a|aa))*`): the same text is reachable two ways, which is the same
698
+ * exponential multiplicity written differently.
699
+ * - **A run of adjacent variable quantifiers over overlapping operands** (`a?a?…a{n}b`,
700
+ * `\d*\d*…`): each quantifier partitions the same text again, which is the first family with
701
+ * no group to hang it on.
702
+ *
703
+ * This is a conservative analysis of a literal pattern, not a proof: it walks groups, escapes
704
+ * and character classes so that `[{]` is not read as a group, and it refuses only constructs it
705
+ * can name. A pattern it passes is still bounded by the per-call work ceiling. It runs at compile
706
+ * time for a literal and, for a computed pattern, before every call.
707
+ */
708
+ export function unsafePattern(pattern, flags) {
709
+ return analysePattern(pattern, 0, flags ?? '').unsafe;
710
+ }
711
+ function classElement(source, index) {
712
+ const character = source[index] ?? '';
713
+ if (character !== '\\') {
714
+ const code = source.codePointAt(index) ?? 0;
715
+ return { next: index + (code > 0xffff ? 2 : 1), code };
716
+ }
717
+ const escaped = source[index + 1] ?? '';
718
+ if (escaped === 'd')
719
+ return { next: index + 2, ranges: DIGIT_RANGES };
720
+ if (escaped === 'w')
721
+ return { next: index + 2, ranges: WORD_RANGES };
722
+ if (escaped === 's')
723
+ return { next: index + 2, ranges: SPACE_RANGES };
724
+ if (escaped === 'p' || escaped === 'P') {
725
+ const close = source.indexOf('}', index + 2);
726
+ return { next: close === -1 ? index + 2 : close + 1, unknown: true };
727
+ }
728
+ const text = escapeText(escaped);
729
+ if (text === undefined)
730
+ return { next: index + 2, unknown: true };
731
+ return { next: index + 2, code: text.codePointAt(0) ?? 0 };
732
+ }
733
+ function readCharacterClass(source, start) {
734
+ let index = start + 1;
735
+ let negated = false;
736
+ if (source[index] === '^') {
737
+ negated = true;
738
+ index += 1;
739
+ }
740
+ const ranges = [];
741
+ let unknown = false;
742
+ while (index < source.length) {
743
+ // In ECMAScript `/u` mode, `]` closes a character class even as its first element (`[]` and `[^]`).
744
+ if (source[index] === ']') {
745
+ return { next: index + 1, ranges, negated, unknown };
746
+ }
747
+ const element = classElement(source, index);
748
+ index = element.next;
749
+ if (element.unknown === true) {
750
+ unknown = true;
751
+ continue;
752
+ }
753
+ if (element.ranges !== undefined) {
754
+ for (const range of element.ranges)
755
+ ranges.push(range);
756
+ continue;
757
+ }
758
+ const from = element.code ?? 0;
759
+ if (source[index] === '-' && source[index + 1] !== undefined && source[index + 1] !== ']') {
760
+ const toElement = classElement(source, index + 1);
761
+ index = toElement.next;
762
+ if (toElement.unknown === true || toElement.ranges !== undefined) {
763
+ ranges.push([from, from]);
764
+ unknown = true;
765
+ continue;
766
+ }
767
+ const to = toElement.code ?? 0;
768
+ ranges.push(to >= from ? [from, to] : [from, from]);
769
+ continue;
770
+ }
771
+ ranges.push([from, from]);
772
+ }
773
+ return { next: index, ranges, negated, unknown };
774
+ }
775
+ /** The operand a class read states, or `unknown` when it named a set the scan cannot compare. */
776
+ function operandFromClass(read) {
777
+ return read.unknown
778
+ ? { kind: 'unknown' }
779
+ : { kind: 'set', ranges: read.ranges, negated: read.negated };
780
+ }
781
+ /** Skips `{...}` after a `\p`, `\P` or `\u` escape, or the single character of a short escape. */
782
+ function skipBraced(source, index) {
783
+ const close = source.indexOf('}', index);
784
+ return close === -1 ? source.length : close + 1;
785
+ }
786
+ function skipAngle(source, index) {
787
+ const close = source.indexOf('>', index);
788
+ return close === -1 ? source.length : close + 1;
789
+ }
790
+ /** The index after the operand of an escape whose first set the scan does not decode. */
791
+ function skipUnknownEscape(source, index, escaped) {
792
+ const afterEscape = index + 2;
793
+ switch (escaped) {
794
+ case 'p':
795
+ case 'P':
796
+ return skipBraced(source, afterEscape);
797
+ case 'k':
798
+ return skipAngle(source, afterEscape);
799
+ case 'u':
800
+ return source[afterEscape] === '{'
801
+ ? skipBraced(source, afterEscape + 1)
802
+ : Math.min(afterEscape + 4, source.length);
803
+ case 'x':
804
+ return Math.min(afterEscape + 2, source.length);
805
+ case 'c':
806
+ return Math.min(afterEscape + 1, source.length);
807
+ default:
808
+ if (/^[1-9]$/.test(escaped)) {
809
+ let cursor = afterEscape;
810
+ while (cursor < source.length && /^[0-9]$/.test(source[cursor] ?? '')) {
811
+ cursor += 1;
812
+ }
813
+ return cursor;
814
+ }
815
+ return afterEscape;
816
+ }
817
+ }
818
+ /**
819
+ * Walks a pattern once, stating the first family it refuses and a conservative work bound.
820
+ *
821
+ * The walk understands the constructs that hide a parenthesis, a quantifier or a character set:
822
+ * an escape (`\(`, `\{`, `\d`), a character class (`[{]`), a group prefix (`(?:`, `(?<=`), and a
823
+ * quantifier (`{2,}`). Everything else is read one code point at a time. A group's proven prefix
824
+ * travels to the enclosing branch, so one level of nesting cannot hide an outer repetition's
825
+ * shape, and the same walk records which adjacent quantifiers share an operand set.
826
+ */
827
+ function analysePattern(pattern, subjectLength, flags = '') {
828
+ if (pattern.length > REGEX_PATTERN_LIMIT) {
829
+ return {
830
+ unsafe: `the pattern is ${String(pattern.length)} code units, longer than the ${String(REGEX_PATTERN_LIMIT)}-code-unit limit for a bounded match`,
831
+ work: WORK_CAP,
832
+ };
833
+ }
834
+ const multiline = flags.includes('m');
835
+ const caseInsensitive = flags.includes('i');
836
+ const groups = [];
837
+ const root = newFrame(-1, false);
838
+ const stack = [];
839
+ const top = () => stack[stack.length - 1] ?? root;
840
+ const refusal = { adjacent: undefined };
841
+ let previousWasQuantifier = false;
842
+ let index = 0;
843
+ while (index < pattern.length) {
844
+ const character = pattern[index] ?? '';
845
+ if (character === '\\') {
846
+ const escaped = pattern[index + 1] ?? '';
847
+ const frame = top();
848
+ const branch = activeBranch(frame);
849
+ if (escaped === 'd' || escaped === 'D') {
850
+ const operand = { kind: 'set', ranges: DIGIT_RANGES, negated: escaped === 'D' };
851
+ noteAtom(frame, operand);
852
+ markOpen(frame);
853
+ branch.atStart = false;
854
+ branch.items.push({ kind: 'atom', operand, singleChar: true, bounds: undefined });
855
+ }
856
+ else if (escaped === 'w' || escaped === 'W') {
857
+ const operand = { kind: 'set', ranges: WORD_RANGES, negated: escaped === 'W' };
858
+ noteAtom(frame, operand);
859
+ markOpen(frame);
860
+ branch.atStart = false;
861
+ branch.items.push({ kind: 'atom', operand, singleChar: true, bounds: undefined });
862
+ }
863
+ else if (escaped === 's' || escaped === 'S') {
864
+ const operand = { kind: 'set', ranges: SPACE_RANGES, negated: escaped === 'S' };
865
+ noteAtom(frame, operand);
866
+ markOpen(frame);
867
+ branch.atStart = false;
868
+ branch.items.push({ kind: 'atom', operand, singleChar: true, bounds: undefined });
869
+ }
870
+ else if (escaped === 'b' || escaped === 'B') {
871
+ // Word boundaries consume no input and do not separate adjacent variable quantifiers
872
+ // (for example, `a?\Ba?` still lets both quantifiers partition the same text).
873
+ resetPrefixAnchor(frame);
874
+ branch.atStart = false;
875
+ branch.items.push({ kind: 'assertion' });
876
+ }
877
+ else if (/^[1-9]$/.test(escaped) || escaped === 'k') {
878
+ // A backreference matches whatever an earlier group captured; its length is not a
879
+ // property of the source, so it joins the bound as a variable of the subject length.
880
+ noteAtom(frame, { kind: 'unknown' });
881
+ markOpen(frame);
882
+ branch.atStart = false;
883
+ branch.items.push({ kind: 'backref', bounds: undefined });
884
+ }
885
+ else if (escapeText(escaped) !== undefined) {
886
+ const text = escapeText(escaped) ?? escaped;
887
+ const operand = { kind: 'text', text };
888
+ noteAtom(frame, operand);
889
+ appendLiteral(frame, text);
890
+ branch.atStart = false;
891
+ branch.items.push({ kind: 'atom', operand, singleChar: true, bounds: undefined });
892
+ }
893
+ else {
894
+ const operand = { kind: 'unknown' };
895
+ noteAtom(frame, operand);
896
+ markOpen(frame);
897
+ branch.atStart = false;
898
+ branch.items.push({ kind: 'atom', operand, singleChar: false, bounds: undefined });
899
+ }
900
+ previousWasQuantifier = false;
901
+ index = skipUnknownEscape(pattern, index, escaped);
902
+ continue;
903
+ }
904
+ if (character === '[') {
905
+ const read = readCharacterClass(pattern, index);
906
+ const frame = top();
907
+ const operand = operandFromClass(read);
908
+ noteAtom(frame, operand);
909
+ markOpen(frame);
910
+ const branch = activeBranch(frame);
911
+ branch.atStart = false;
912
+ branch.items.push({
913
+ kind: 'atom',
914
+ operand,
915
+ singleChar: !read.unknown,
916
+ bounds: undefined,
917
+ });
918
+ previousWasQuantifier = false;
919
+ index = read.next;
920
+ continue;
921
+ }
922
+ if (character === '.') {
923
+ const frame = top();
924
+ const operand = { kind: 'any' };
925
+ noteAtom(frame, operand);
926
+ markOpen(frame);
927
+ const branch = activeBranch(frame);
928
+ branch.atStart = false;
929
+ branch.items.push({ kind: 'atom', operand, singleChar: false, bounds: undefined });
930
+ previousWasQuantifier = false;
931
+ index += 1;
932
+ continue;
933
+ }
934
+ if (character === '(') {
935
+ if (isInlineModifierGroup(pattern, index)) {
936
+ return {
937
+ unsafe: 'inline modifier groups such as `(?i:...)` are not supported; pass `i`, `m`, or `s` in the `flags` argument instead',
938
+ work: WORK_CAP,
939
+ };
940
+ }
941
+ stack.push(newFrame(index, groupIsLookaround(pattern, index)));
942
+ previousWasQuantifier = false;
943
+ index = afterGroupPrefix(pattern, index);
944
+ continue;
945
+ }
946
+ if (character === ')') {
947
+ const frame = stack.pop();
948
+ if (frame === undefined) {
949
+ previousWasQuantifier = false;
950
+ index += 1;
951
+ continue;
952
+ }
953
+ const leadingPrefix = commonPrefix(frame.branches);
954
+ const closed = frame.branches.length === 1 && frame.branches[0]?.closed === true;
955
+ const overlapping = branchesOverlap(frame, caseInsensitive);
956
+ const body = {
957
+ hasQuantifier: frame.variableQuantifier || frame.nestedVariableQuantifier,
958
+ hasOverlappingAlternation: overlapping || frame.nestedOverlappingAlternation,
959
+ leadingPrefix,
960
+ closed,
961
+ };
962
+ groups.push({
963
+ source: pattern.slice(afterGroupPrefix(pattern, frame.open), index),
964
+ quantified: quantifierRepeats(pattern, index + 1),
965
+ body,
966
+ });
967
+ const bounds = quantifierBounds(pattern, index + 1);
968
+ const parent = top();
969
+ const parentBranch = activeBranch(parent);
970
+ const bodyZeroWidth = frame.branches.every((branch) => branch.items.every(isZeroWidthItem));
971
+ const groupZeroWidth = frame.lookaround || bodyZeroWidth || bounds?.max === 0;
972
+ if (!groupZeroWidth)
973
+ noteAtom(parent, operandFromBody(body));
974
+ const groupProfile = sumWork(frame.branches.map((branch) => branchWork(branch.items, subjectLength, caseInsensitive, false)), !overlapping);
975
+ if (!frame.lookaround) {
976
+ const groupAnchored = !multiline &&
977
+ frame.branches.length > 0 &&
978
+ frame.branches.every((branch) => branch.anchoredStart);
979
+ const groupRequired = bounds === undefined || bounds.min >= 1;
980
+ if (parentBranch.atStart && groupAnchored && groupRequired) {
981
+ parentBranch.anchoredStart = true;
982
+ }
983
+ }
984
+ parentBranch.atStart = false;
985
+ parentBranch.items.push({
986
+ kind: 'group',
987
+ profile: groupProfile,
988
+ lookaround: frame.lookaround,
989
+ zeroWidth: bodyZeroWidth,
990
+ leadingOperand: frame.lookaround ? undefined : leadingOperandFromPrefix(body.leadingPrefix),
991
+ bounds,
992
+ });
993
+ if (!groupZeroWidth)
994
+ markQuantified(parent, bounds, caseInsensitive, refusal);
995
+ else if (bounds?.variable === true && bounds.max > 0)
996
+ parent.variableQuantifier = true;
997
+ if (body.hasQuantifier)
998
+ parent.nestedVariableQuantifier = true;
999
+ if (body.hasOverlappingAlternation)
1000
+ parent.nestedOverlappingAlternation = true;
1001
+ if (frame.lookaround) {
1002
+ resetPrefixAnchor(parent);
1003
+ }
1004
+ else {
1005
+ const groupQuantified = bounds !== undefined && (bounds.variable || bounds.min !== 1 || bounds.max !== 1);
1006
+ const enclosing = currentBranch(parent);
1007
+ if (enclosing !== undefined) {
1008
+ if (bounds !== undefined && bounds.min === 0) {
1009
+ markOpen(parent);
1010
+ }
1011
+ else if (body.closed && !groupQuantified) {
1012
+ appendLiteral(parent, body.leadingPrefix);
1013
+ }
1014
+ else {
1015
+ if (enclosing.acceptingPrefix && body.leadingPrefix !== '') {
1016
+ enclosing.leadingPrefix += body.leadingPrefix;
1017
+ }
1018
+ markOpen(parent);
1019
+ }
1020
+ }
1021
+ }
1022
+ previousWasQuantifier = bounds !== undefined;
1023
+ index += 1 + quantifierLength(pattern, index + 1);
1024
+ continue;
1025
+ }
1026
+ if (character === '|') {
1027
+ const frame = top();
1028
+ frame.current = undefined;
1029
+ frame.previous = undefined;
1030
+ frame.branches.push(newBranch());
1031
+ previousWasQuantifier = false;
1032
+ index += 1;
1033
+ continue;
1034
+ }
1035
+ const bounds = quantifierBounds(pattern, index);
1036
+ if (bounds !== undefined) {
1037
+ // A `?` directly after an actual quantifier token is the lazy marker, not a second
1038
+ // repetition. Tracking the prior token explicitly avoids mistaking an escaped literal
1039
+ // (`\??`, `\*?`, `\+?`, `\}?`) or property escape (`\p{L}?`) for a lazy quantifier.
1040
+ if (character === '?' && previousWasQuantifier) {
1041
+ previousWasQuantifier = false;
1042
+ index += 1;
1043
+ continue;
1044
+ }
1045
+ const frame = top();
1046
+ if (bounds.max === 0) {
1047
+ // A `{0}` (or `{0,0}`) repetition consumes nothing; keep any preceding variable
1048
+ // quantifier as the active predecessor so a zero-width atom cannot split a run.
1049
+ frame.current = frame.previous;
1050
+ frame.previous = undefined;
1051
+ }
1052
+ else {
1053
+ markQuantified(frame, bounds, caseInsensitive, refusal);
1054
+ }
1055
+ applyQuantifierToBranch(frame, bounds);
1056
+ const branch = activeBranch(frame);
1057
+ const lastItem = branch.items[branch.items.length - 1];
1058
+ if (lastItem !== undefined && lastItem.kind !== 'assertion') {
1059
+ lastItem.bounds = bounds;
1060
+ }
1061
+ previousWasQuantifier = true;
1062
+ index += quantifierLength(pattern, index);
1063
+ continue;
1064
+ }
1065
+ if (character === '^' || character === '$') {
1066
+ // An assertion consumes nothing; it separates runs that would otherwise look adjacent.
1067
+ const frame = top();
1068
+ frame.current = undefined;
1069
+ frame.previous = undefined;
1070
+ resetPrefixAnchor(frame);
1071
+ const branch = activeBranch(frame);
1072
+ if (character === '^' && !multiline && branch.atStart) {
1073
+ branch.anchoredStart = true;
1074
+ }
1075
+ else if (character === '$') {
1076
+ branch.atStart = false;
1077
+ }
1078
+ branch.items.push({ kind: 'assertion' });
1079
+ previousWasQuantifier = false;
1080
+ index += 1;
1081
+ continue;
1082
+ }
1083
+ const codePoint = pattern.codePointAt(index) ?? 0;
1084
+ const text = String.fromCodePoint(codePoint);
1085
+ const frame = top();
1086
+ const operand = { kind: 'text', text };
1087
+ noteAtom(frame, operand);
1088
+ appendLiteral(frame, text);
1089
+ const branch = activeBranch(frame);
1090
+ branch.atStart = false;
1091
+ branch.items.push({ kind: 'atom', operand, singleChar: true, bounds: undefined });
1092
+ previousWasQuantifier = false;
1093
+ index += text.length;
1094
+ }
1095
+ const rootProfile = sumWork(root.branches.map((branch) => branchWork(branch.items, subjectLength, caseInsensitive, true)));
1096
+ const perStartWork = Math.max(1, addWork(rootProfile.overhead, rootProfile.multiplier));
1097
+ const anchoredAtStart = !multiline && root.branches.length > 0 && root.branches.every((branch) => branch.anchoredStart);
1098
+ const startPositions = anchoredAtStart ? 1 : subjectLength + 1;
1099
+ let unsafe = refusal.adjacent;
1100
+ if (unsafe === undefined) {
1101
+ for (const group of groups) {
1102
+ if (!group.quantified)
1103
+ continue;
1104
+ if (group.body.hasQuantifier) {
1105
+ unsafe = `a repeated group contains a variable quantifier (\`(${group.source})\`), which backtracks exponentially over repeated input; make one repetition do the work, such as \`[A-Za-z]+[0-9]+\` instead of \`([A-Za-z]+[0-9])+\``;
1106
+ break;
1107
+ }
1108
+ if (group.body.hasOverlappingAlternation) {
1109
+ unsafe = `a repeated group has alternation branches that can match the same prefix (\`(${group.source})\`), which backtracks exponentially; make the branches disjoint, such as \`(?:ab|ac)+\` instead of \`(a|ab)+\``;
1110
+ break;
1111
+ }
1112
+ }
1113
+ }
1114
+ return {
1115
+ unsafe,
1116
+ work: multiplyWork(startPositions, perStartWork),
1117
+ };
1118
+ }
1119
+ /** The `(pattern, flags)` pairs already compiled, oldest first for bounded eviction. */
1120
+ const COMPILED = new Map();
1121
+ function cacheKey(pattern, flags) {
1122
+ return `${flags}\u0000${pattern}`;
1123
+ }
1124
+ /**
1125
+ * Compiles one pattern, or states why it cannot be compiled.
1126
+ *
1127
+ * A `SyntaxError` from the engine is data: a computed pattern that does not parse is a
1128
+ * value-stated refusal the report can name, not an exception a host sees. The cache is bounded
1129
+ * because a document can write an unbounded number of distinct computed patterns, and a
1130
+ * process-global map an input can grow is a leak.
1131
+ */
1132
+ export function compileRegex(pattern, canonical) {
1133
+ const key = cacheKey(pattern, canonical);
1134
+ const cached = COMPILED.get(key);
1135
+ if (cached !== undefined) {
1136
+ // Refresh the recency of a hit, so the entries evicted are the least recently used.
1137
+ COMPILED.delete(key);
1138
+ COMPILED.set(key, cached);
1139
+ return { kind: 'ok', regex: cached.regex };
1140
+ }
1141
+ let regex;
1142
+ try {
1143
+ regex = new RegExp(pattern, canonical);
1144
+ }
1145
+ catch (error) {
1146
+ const detail = error instanceof Error ? error.message : String(error);
1147
+ return { kind: 'invalid-pattern', detail };
1148
+ }
1149
+ COMPILED.set(key, { regex });
1150
+ if (COMPILED.size > REGEX_CACHE_LIMIT) {
1151
+ const oldest = COMPILED.keys().next();
1152
+ if (!oldest.done)
1153
+ COMPILED.delete(oldest.value);
1154
+ }
1155
+ return { kind: 'ok', regex };
1156
+ }
1157
+ /** A refusal as the `ENGINE_ERROR` the evaluator reports at the call's path. */
1158
+ export function regexRefusalError(refusal, path) {
1159
+ switch (refusal.kind) {
1160
+ case 'invalid-flags':
1161
+ return new AxiomError('ENGINE_ERROR', `matches: ${refusal.detail}`, path);
1162
+ case 'invalid-pattern':
1163
+ // Host engines word RegExp SyntaxError messages differently across V8, Hermes, JSC and
1164
+ // SpiderMonkey. This detail enters `report.diagnostics[].params.detail` and therefore
1165
+ // `reportHash`, so the runtime refusal must stay engine-independent.
1166
+ return new AxiomError('ENGINE_ERROR', 'matches: the pattern is not a valid regular expression', path);
1167
+ case 'unsafe-pattern':
1168
+ return new AxiomError('ENGINE_ERROR', `matches: ${refusal.detail}`, path);
1169
+ case 'subject-too-long':
1170
+ return new AxiomError('ENGINE_ERROR', `matches: ${refusal.detail}`, path);
1171
+ }
1172
+ }
1173
+ /**
1174
+ * `matches(s, pattern, flags?)`: an unanchored Unicode search, or the refusal that stops it.
1175
+ *
1176
+ * The subject cap is checked before compilation, so an oversized input is refused whether or
1177
+ * not the pattern would have matched, and the answer is never a silent `false`. The work ceiling
1178
+ * is checked at this call's subject length, so a pattern that is ordinary over a short value is
1179
+ * not refused for it, and a shape the structural scan did not name still cannot outlast the
1180
+ * budget.
1181
+ */
1182
+ export function matchRegex(subject, pattern, flags) {
1183
+ const length = codePointLength(subject);
1184
+ if (length > REGEX_SUBJECT_LIMIT) {
1185
+ return {
1186
+ kind: 'subject-too-long',
1187
+ detail: `the subject is ${String(length)} code points, longer than the ${String(REGEX_SUBJECT_LIMIT)}-code-point limit for a pattern check`,
1188
+ };
1189
+ }
1190
+ const canonical = canonicalFlags(flags);
1191
+ if (canonical.kind !== 'ok')
1192
+ return canonical;
1193
+ const analysis = analysePattern(pattern, length, canonical.flags);
1194
+ // A pattern the artifact states literally was analysed at compile time; a pattern that
1195
+ // arrived as a value is analysed here, with the same rule.
1196
+ if (analysis.unsafe !== undefined) {
1197
+ return { kind: 'unsafe-pattern', detail: analysis.unsafe };
1198
+ }
1199
+ const compiled = compileRegex(pattern, canonical.flags);
1200
+ if (compiled.kind !== 'ok')
1201
+ return compiled;
1202
+ if (analysis.work > REGEX_MATCH_WORK_LIMIT) {
1203
+ return {
1204
+ kind: 'unsafe-pattern',
1205
+ detail: `the pattern exceeds the ${String(REGEX_MATCH_WORK_LIMIT)}-step work budget on a ${String(length)}-code-point subject; shorten the subject or simplify the pattern`,
1206
+ };
1207
+ }
1208
+ return { kind: 'tested', matched: compiled.regex.test(subject) };
1209
+ }
1210
+ //# sourceMappingURL=regex.js.map