solve-engine 1.0.0-beta.7 → 1.0.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 (205) hide show
  1. package/dist/{BytecodeBuilder-3egMyuDi.d.cts → BytecodeBuilder-B0xskcv5.d.cts} +2 -1
  2. package/dist/{BytecodeBuilder-3egMyuDi.d.ts → BytecodeBuilder-B0xskcv5.d.ts} +2 -1
  3. package/dist/{Configuration-fVpd-HC-.d.cts → Configuration-B-G5gTRn.d.cts} +107 -29
  4. package/dist/{Configuration-fVpd-HC-.d.ts → Configuration-B-G5gTRn.d.ts} +107 -29
  5. package/dist/{EngineError-DvPSnhZi.d.cts → EngineError-LU7W7AgI.d.cts} +96 -16
  6. package/dist/{EngineError-DvPSnhZi.d.ts → EngineError-LU7W7AgI.d.ts} +96 -16
  7. package/dist/{Lexer-W9MBOP0V.d.ts → Lexer-BN5mt30n.d.ts} +16 -0
  8. package/dist/{Lexer-Cfm79Dak.d.cts → Lexer-D78E2yDW.d.cts} +16 -0
  9. package/dist/{PackageRegistry-CjDt-Jy_.d.ts → PackageRegistry-DFeINv2O.d.ts} +54 -13
  10. package/dist/{PackageRegistry-pHtKythi.d.cts → PackageRegistry-u2zdfFaj.d.cts} +54 -13
  11. package/dist/{Parselet-DEdF9I7n.d.ts → Parselet-BaySkMV3.d.ts} +37 -5
  12. package/dist/{Parselet-Cu0bLSis.d.cts → Parselet-DuI1Pjiq.d.cts} +37 -5
  13. package/dist/{ScopeManager-CKfQtl7l.d.cts → ScopeManager-B6GzdhVG.d.cts} +75 -6
  14. package/dist/{ScopeManager-B5k0nk05.d.ts → ScopeManager-udv4Twwq.d.ts} +75 -6
  15. package/dist/{VMCheckpoints-BmDwIXgK.d.ts → VMCheckpoints-BiaIlOOY.d.ts} +4 -4
  16. package/dist/{VMCheckpoints-CqFuLwrT.d.cts → VMCheckpoints-DwLjivM7.d.cts} +4 -4
  17. package/dist/{Value-KtAQNHur.d.cts → Value-CXJqDH9J.d.cts} +5 -2
  18. package/dist/{Value-KtAQNHur.d.ts → Value-CXJqDH9J.d.ts} +5 -2
  19. package/dist/{chunk-CSG5XVNJ.cjs → chunk-3AFRJYP4.cjs} +556 -414
  20. package/dist/chunk-3AFRJYP4.cjs.map +1 -0
  21. package/dist/chunk-3BOK2LDK.js +17 -0
  22. package/dist/chunk-3BOK2LDK.js.map +1 -0
  23. package/dist/{chunk-6RDSQURE.js → chunk-3D7V24DG.js} +57 -6
  24. package/dist/chunk-3D7V24DG.js.map +1 -0
  25. package/dist/{chunk-MEOHSQEH.js → chunk-3LAEG75D.js} +47 -15
  26. package/dist/chunk-3LAEG75D.js.map +1 -0
  27. package/dist/{chunk-P75775WC.js → chunk-3VNGREMU.js} +118 -41
  28. package/dist/chunk-3VNGREMU.js.map +1 -0
  29. package/dist/{chunk-4AVD7NZW.cjs → chunk-4B2CNWQU.cjs} +13 -7
  30. package/dist/chunk-4B2CNWQU.cjs.map +1 -0
  31. package/dist/{chunk-6GCKCWLB.js → chunk-526PMQOA.js} +126 -69
  32. package/dist/chunk-526PMQOA.js.map +1 -0
  33. package/dist/{chunk-2CS6OMZK.js → chunk-5F4C26RU.js} +8 -5
  34. package/dist/chunk-5F4C26RU.js.map +1 -0
  35. package/dist/{chunk-M4N5GA5Z.cjs → chunk-5KMIY374.cjs} +57 -6
  36. package/dist/chunk-5KMIY374.cjs.map +1 -0
  37. package/dist/{chunk-R24DI24X.cjs → chunk-5LI5EPGJ.cjs} +6 -5
  38. package/dist/chunk-5LI5EPGJ.cjs.map +1 -0
  39. package/dist/{chunk-BAMZT3GL.js → chunk-5WVP4YHP.js} +939 -134
  40. package/dist/chunk-5WVP4YHP.js.map +1 -0
  41. package/dist/{chunk-MZOVP3WI.cjs → chunk-6KFYJ6TD.cjs} +3 -2
  42. package/dist/chunk-6KFYJ6TD.cjs.map +1 -0
  43. package/dist/{chunk-BXKJLM5R.cjs → chunk-6WFMPTGB.cjs} +972 -636
  44. package/dist/chunk-6WFMPTGB.cjs.map +1 -0
  45. package/dist/{chunk-2MV4HBKC.cjs → chunk-A2N2GFCG.cjs} +10 -10
  46. package/dist/{chunk-2MV4HBKC.cjs.map → chunk-A2N2GFCG.cjs.map} +1 -1
  47. package/dist/chunk-ADBA3XBE.cjs +20 -0
  48. package/dist/chunk-ADBA3XBE.cjs.map +1 -0
  49. package/dist/{chunk-MBNQVDVC.cjs → chunk-AMOJYLG2.cjs} +16 -10
  50. package/dist/chunk-AMOJYLG2.cjs.map +1 -0
  51. package/dist/{chunk-CLVQBF5C.cjs → chunk-AQNHHJMJ.cjs} +5 -5
  52. package/dist/{chunk-CLVQBF5C.cjs.map → chunk-AQNHHJMJ.cjs.map} +1 -1
  53. package/dist/{chunk-AHCLWAM5.cjs → chunk-BHTNFEGZ.cjs} +13 -13
  54. package/dist/chunk-BHTNFEGZ.cjs.map +1 -0
  55. package/dist/{chunk-35IWNZPJ.cjs → chunk-E4NUZXVK.cjs} +58 -27
  56. package/dist/chunk-E4NUZXVK.cjs.map +1 -0
  57. package/dist/{chunk-P33SBYGG.js → chunk-GLG5ZMX7.js} +54 -23
  58. package/dist/chunk-GLG5ZMX7.js.map +1 -0
  59. package/dist/{chunk-BVAR5J2F.js → chunk-GQCOSXMG.js} +117 -6
  60. package/dist/chunk-GQCOSXMG.js.map +1 -0
  61. package/dist/{chunk-QDMPOAI7.cjs → chunk-HDP7VK3C.cjs} +1118 -313
  62. package/dist/chunk-HDP7VK3C.cjs.map +1 -0
  63. package/dist/{chunk-GVWHCL2N.js → chunk-HMOISHXR.js} +217 -75
  64. package/dist/chunk-HMOISHXR.js.map +1 -0
  65. package/dist/{chunk-MTX2KVU7.cjs → chunk-HVQFNJKE.cjs} +122 -90
  66. package/dist/chunk-HVQFNJKE.cjs.map +1 -0
  67. package/dist/{chunk-OC6LTXYS.cjs → chunk-JMXUNXQS.cjs} +126 -7
  68. package/dist/chunk-JMXUNXQS.cjs.map +1 -0
  69. package/dist/{chunk-WWOLFXTX.cjs → chunk-KBSXGXPM.cjs} +10 -7
  70. package/dist/chunk-KBSXGXPM.cjs.map +1 -0
  71. package/dist/{chunk-YU2CUNFO.js → chunk-KV7UW6T6.js} +11 -5
  72. package/dist/chunk-KV7UW6T6.js.map +1 -0
  73. package/dist/{chunk-CCJPSHGI.cjs → chunk-N7FNVFXW.cjs} +4 -12
  74. package/dist/chunk-N7FNVFXW.cjs.map +1 -0
  75. package/dist/{chunk-CYFK5SY2.js → chunk-O3ANBHSA.js} +169 -39
  76. package/dist/chunk-O3ANBHSA.js.map +1 -0
  77. package/dist/{chunk-NZFKROS7.cjs → chunk-PA4VC73I.cjs} +130 -72
  78. package/dist/chunk-PA4VC73I.cjs.map +1 -0
  79. package/dist/{chunk-NJTXJ5AG.cjs → chunk-PFUESQTW.cjs} +18 -18
  80. package/dist/{chunk-NJTXJ5AG.cjs.map → chunk-PFUESQTW.cjs.map} +1 -1
  81. package/dist/{chunk-SFQWJMKT.js → chunk-QY25VWBF.js} +51 -12
  82. package/dist/chunk-QY25VWBF.js.map +1 -0
  83. package/dist/{chunk-WC5FFSHB.js → chunk-R3PY4G7J.js} +3 -3
  84. package/dist/{chunk-WC5FFSHB.js.map → chunk-R3PY4G7J.js.map} +1 -1
  85. package/dist/{chunk-M5E34VG5.js → chunk-SBUFNJVE.js} +3 -3
  86. package/dist/{chunk-M5E34VG5.js.map → chunk-SBUFNJVE.js.map} +1 -1
  87. package/dist/{chunk-UKPGSAZW.js → chunk-TMA4RCEN.js} +3 -3
  88. package/dist/{chunk-UKPGSAZW.js.map → chunk-TMA4RCEN.js.map} +1 -1
  89. package/dist/{chunk-V6HA6JJZ.cjs → chunk-U5VAY32K.cjs} +215 -138
  90. package/dist/chunk-U5VAY32K.cjs.map +1 -0
  91. package/dist/{chunk-DUEZFTK2.js → chunk-UKQHXPGW.js} +4 -12
  92. package/dist/chunk-UKQHXPGW.js.map +1 -0
  93. package/dist/{chunk-4CVLFLOB.cjs → chunk-UM6BVY2S.cjs} +201 -69
  94. package/dist/chunk-UM6BVY2S.cjs.map +1 -0
  95. package/dist/{chunk-75JP4BZX.js → chunk-UQ3UIZJC.js} +3 -2
  96. package/dist/chunk-UQ3UIZJC.js.map +1 -0
  97. package/dist/{chunk-PCPX42KL.js → chunk-V4XG5QF6.js} +16 -10
  98. package/dist/chunk-V4XG5QF6.js.map +1 -0
  99. package/dist/{chunk-GPPLSM2Z.js → chunk-VB37OC6I.js} +6 -5
  100. package/dist/chunk-VB37OC6I.js.map +1 -0
  101. package/dist/{chunk-MVBEL57Q.js → chunk-Y7FT4IQT.js} +500 -170
  102. package/dist/chunk-Y7FT4IQT.js.map +1 -0
  103. package/dist/{chunk-OFXOTECC.js → chunk-YPPPYLSR.js} +7 -7
  104. package/dist/chunk-YPPPYLSR.js.map +1 -0
  105. package/dist/{chunk-M4F66R4O.cjs → chunk-YWQ6V4ZN.cjs} +121 -82
  106. package/dist/chunk-YWQ6V4ZN.cjs.map +1 -0
  107. package/dist/constants.cjs +5 -5
  108. package/dist/constants.d.cts +1 -1
  109. package/dist/constants.d.ts +1 -1
  110. package/dist/constants.js +2 -2
  111. package/dist/engine.cjs +31 -31
  112. package/dist/engine.d.cts +11 -11
  113. package/dist/engine.d.ts +11 -11
  114. package/dist/engine.js +21 -21
  115. package/dist/errors.cjs +19 -19
  116. package/dist/errors.d.cts +2 -2
  117. package/dist/errors.d.ts +2 -2
  118. package/dist/errors.js +1 -1
  119. package/dist/format.cjs +29 -22
  120. package/dist/format.cjs.map +1 -1
  121. package/dist/format.d.cts +1 -2
  122. package/dist/format.d.ts +1 -2
  123. package/dist/format.js +23 -16
  124. package/dist/format.js.map +1 -1
  125. package/dist/index.cjs +31 -31
  126. package/dist/index.d.cts +10 -10
  127. package/dist/index.d.ts +10 -10
  128. package/dist/index.js +22 -22
  129. package/dist/language.cjs +8 -8
  130. package/dist/language.cjs.map +1 -1
  131. package/dist/language.d.cts +10 -10
  132. package/dist/language.d.ts +10 -10
  133. package/dist/language.js +6 -6
  134. package/dist/language.js.map +1 -1
  135. package/dist/lexer.cjs +18 -18
  136. package/dist/lexer.d.cts +2 -2
  137. package/dist/lexer.d.ts +2 -2
  138. package/dist/lexer.js +6 -6
  139. package/dist/normalizer.cjs +12 -12
  140. package/dist/normalizer.js +6 -6
  141. package/dist/packages.cjs +39 -39
  142. package/dist/packages.d.cts +9 -9
  143. package/dist/packages.d.ts +9 -9
  144. package/dist/packages.js +16 -16
  145. package/dist/parser.cjs +15 -15
  146. package/dist/parser.d.cts +23 -9
  147. package/dist/parser.d.ts +23 -9
  148. package/dist/parser.js +5 -5
  149. package/dist/{pipeline-CrsRPmsv.d.ts → pipeline-B6k5lCB7.d.ts} +1 -1
  150. package/dist/{pipeline-DPUQt7yL.d.cts → pipeline-BEb3hujr.d.cts} +1 -1
  151. package/dist/resolvers.d.cts +2 -2
  152. package/dist/resolvers.d.ts +2 -2
  153. package/dist/uom.cjs +17 -17
  154. package/dist/uom.d.cts +2 -2
  155. package/dist/uom.d.ts +2 -2
  156. package/dist/uom.js +7 -7
  157. package/dist/utilities.cjs +8 -4
  158. package/dist/utilities.d.cts +19 -3
  159. package/dist/utilities.d.ts +19 -3
  160. package/dist/utilities.js +2 -2
  161. package/dist/vm.cjs +43 -31
  162. package/dist/vm.d.cts +105 -9
  163. package/dist/vm.d.ts +105 -9
  164. package/dist/vm.js +9 -9
  165. package/package.json +1 -1
  166. package/dist/chunk-2CS6OMZK.js.map +0 -1
  167. package/dist/chunk-35IWNZPJ.cjs.map +0 -1
  168. package/dist/chunk-4AVD7NZW.cjs.map +0 -1
  169. package/dist/chunk-4CVLFLOB.cjs.map +0 -1
  170. package/dist/chunk-6GCKCWLB.js.map +0 -1
  171. package/dist/chunk-6RDSQURE.js.map +0 -1
  172. package/dist/chunk-75JP4BZX.js.map +0 -1
  173. package/dist/chunk-AHCLWAM5.cjs.map +0 -1
  174. package/dist/chunk-BAMZT3GL.js.map +0 -1
  175. package/dist/chunk-BVAR5J2F.js.map +0 -1
  176. package/dist/chunk-BXKJLM5R.cjs.map +0 -1
  177. package/dist/chunk-CCJPSHGI.cjs.map +0 -1
  178. package/dist/chunk-CSG5XVNJ.cjs.map +0 -1
  179. package/dist/chunk-CYFK5SY2.js.map +0 -1
  180. package/dist/chunk-DUEZFTK2.js.map +0 -1
  181. package/dist/chunk-GPPLSM2Z.js.map +0 -1
  182. package/dist/chunk-GVWHCL2N.js.map +0 -1
  183. package/dist/chunk-M4F66R4O.cjs.map +0 -1
  184. package/dist/chunk-M4N5GA5Z.cjs.map +0 -1
  185. package/dist/chunk-MBNQVDVC.cjs.map +0 -1
  186. package/dist/chunk-MEOHSQEH.js.map +0 -1
  187. package/dist/chunk-MTX2KVU7.cjs.map +0 -1
  188. package/dist/chunk-MVBEL57Q.js.map +0 -1
  189. package/dist/chunk-MZOVP3WI.cjs.map +0 -1
  190. package/dist/chunk-N5YFR4UP.cjs +0 -10
  191. package/dist/chunk-N5YFR4UP.cjs.map +0 -1
  192. package/dist/chunk-NZFKROS7.cjs.map +0 -1
  193. package/dist/chunk-OC6LTXYS.cjs.map +0 -1
  194. package/dist/chunk-OFXOTECC.js.map +0 -1
  195. package/dist/chunk-P33SBYGG.js.map +0 -1
  196. package/dist/chunk-P75775WC.js.map +0 -1
  197. package/dist/chunk-PCPX42KL.js.map +0 -1
  198. package/dist/chunk-PFSDGGYL.js +0 -8
  199. package/dist/chunk-PFSDGGYL.js.map +0 -1
  200. package/dist/chunk-QDMPOAI7.cjs.map +0 -1
  201. package/dist/chunk-R24DI24X.cjs.map +0 -1
  202. package/dist/chunk-SFQWJMKT.js.map +0 -1
  203. package/dist/chunk-V6HA6JJZ.cjs.map +0 -1
  204. package/dist/chunk-WWOLFXTX.cjs.map +0 -1
  205. package/dist/chunk-YU2CUNFO.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lexer/units.ts"],"names":[],"mappings":";;;AAmCA,IAAM,uBAAA,uBAA2D,GAAA,CAAI;AAAA,EACnE,CAAC,MAA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,CAAK,UAAU,CAAA,CAAE,OAAO,YAAY,CAAA;AAAA,EAC9C,GAAG,MAAA,CAAO,IAAA,CAAK,cAAc,CAAA;AAAA,EAC7B,GAAG,aAAA;AAAA,EACH,GAAG,cAAA;AAAA,EACH,GAAG;AACL,CAAC;AAMM,SAAS,YAAY,IAAA,EAAuB;AACjD,EAAA,OAAO,UAAA,CAAW,IAAI,IAAI,CAAA;AAC5B","file":"chunk-M5E34VG5.js","sourcesContent":["/**\n * The set of unit identifiers the lexer will turn into a UNIT token.\n *\n * DERIVED, not hand-listed. This used to be a hand-maintained list of about a\n * hundred spellings, which existed only because the conversion tables lived\n * inside a third-party package and could not be enumerated. Every spelling had\n * to be transcribed by hand and kept in sync, and this file's own history\n * records the consequences: the IEC binary prefixes (`GiB`, `TiB`) were absent\n * for a long time, and the note explaining the fix said it was \"purely a lexer\n * allowlist gap, not a conversion-logic one\".\n *\n * The tables are now in-repo (see `uom/generated/UnitTable.generated.ts`), so\n * the allowlist is computed from them. Roughly 975 base spellings are\n * recognized instead of about 101, which is why `1 kilojoule to Wh`,\n * `5 arcminutes to deg` and `2 fortnights in days` work at all.\n *\n * Units are case-sensitive to eliminate ambiguity (`C` is Celsius and `c` is a\n * cup, `B` is bytes and `b` is bits). Nothing here normalizes or aliases.\n */\n\nimport { UNIT_TABLE } from \"@solve-js/uom/generated/UnitTable.generated\";\nimport { EXTENDED_UNITS } from \"@solve-js/uom/ExtendedUnits\";\n\n/**\n * Spellings the conversion tables accept but the lexer must not claim, each\n * with its reason. `UnitVocabulary.spec.ts` asserts every one of these still\n * fails to lex, so nobody can quietly delete an entry.\n *\n * Only three spellings in the whole table collide with an existing language\n * keyword (`in`, `min`, `dec`), and `min` is left alone because it has always\n * been a time unit here and works. The rest of this list is about ordinary\n * English: a unit spelling that is also a common word turns prose into\n * arithmetic. `shouldEvaluateLine`'s prose gate is a backstop, not a licence\n * to claim every word in the dictionary.\n */\nconst EXCLUDED_UNIT_SPELLINGS: ReadonlyMap<string, string> = new Map([\n [\"in\", \"the IN keyword owns this word (the conversion operator). ConvertParselet and friends special-case the IN token type directly and trust its text as a unit name, so inches still convert\"],\n [\"dec\", \"already a converter name, as in `255 as dec`\"],\n [\"M\", \"the millions magnitude suffix, as in `2.5M`. Nautical miles are still spelled `nmi` and `NM`\"],\n // Claimed by a normalizer rule rather than by the keyword table, which is why\n // scanning the locale keywords alone does not find it. Admitting `pm`\n // (picometre) broke every clock time in the suite: `4pm` lexed as 4\n // picometres. There is deliberately no entry for `am`: the table's SI\n // prefixes stop at femto, so attometres do not exist and an exclusion would\n // be dead weight. `UnitVocabularyCollisions.spec.ts` asserts that.\n [\"pm\", \"the meridiem marker, as in `4pm`. Picometres lose, and `picometre` still works\"],\n [\"are\", \"the English verb, against a 100-square-metre unit almost nobody writes\"],\n [\"ares\", \"the English verb in plural, same reasoning as `are` above\"],\n [\"turn\", \"ordinary English, against a full-rotation angle unit also spelled in gradians\"],\n [\"turns\", \"ordinary English in plural, same reasoning as `turn` above\"],\n [\"grade\", \"ordinary English. The angle unit is also spelled `gon` and `grad`\"],\n [\"grades\", \"ordinary English in plural, same reasoning as `grade` above\"],\n [\"point\", \"ordinary English. The typographic point is also reachable as `pica`\"],\n [\"points\", \"ordinary English in plural, same reasoning as `point` above\"],\n [\"moment\", \"ordinary English, against an obscure medieval time unit of 90 seconds\"],\n [\"moments\", \"ordinary English in plural, same reasoning as `moment` above\"],\n [\"shake\", \"ordinary English, against an obscure physics unit of ten nanoseconds\"],\n [\"shakes\", \"ordinary English in plural, same reasoning as `shake` above\"],\n]);\n\n/**\n * Whether a spelling can be a single UNIT token at all.\n *\n * The lexer reads a unit as one run of `[A-Za-z0-9_]`, so the 465 spellings\n * containing a space, a slash, a prime or a non-ASCII character cannot be\n * tokenized however well the converter understands them. `square metres`,\n * `cd/m2` and `µm²` all remain reachable through the conversion API (notably\n * the cooking package's free-text target unit), just not by typing them in an\n * expression.\n */\nfunction isTokenizableSpelling(spelling: string): boolean {\n return /^[A-Za-z0-9_]+$/.test(spelling);\n}\n\n/**\n * The single-character units that were already claimed before the vocabulary\n * was derived from the tables, and are therefore grandfathered in.\n *\n * No OTHER single character is admitted. A one-letter unit is indistinguishable\n * from the placeholder names people actually write (`x`, `y`, `n`), and the\n * table has ten more of them: `r a y c p S L N J R`. Admitting those turned\n * `x.y` into a unit expression and broke comparison-operator tests that had\n * deliberately picked letters which were not units. The upside was a handful of\n * spellings that all have an unambiguous longer form (`rad`, `year`, `cup`).\n */\nconst GRANDFATHERED_SINGLE_CHARACTER_UNITS = new Set([\n \"m\", \"g\", \"t\", \"s\", \"h\", \"d\", \"l\", \"b\", \"B\", \"C\", \"F\", \"K\", \"W\",\n]);\n\n/** Whether a base-table spelling should become a lexer token. */\nfunction isAdmissible(spelling: string): boolean {\n if (!isTokenizableSpelling(spelling)) return false;\n if (EXCLUDED_UNIT_SPELLINGS.has(spelling)) return false;\n if (spelling.length === 1) return GRANDFATHERED_SINGLE_CHARACTER_UNITS.has(spelling);\n return true;\n}\n\n/**\n * ISO 4217 codes and the crypto tickers handled alongside them.\n *\n * Hand-maintained on purpose: these are NOT units. They route through\n * CurrencyExchangeService, and `getMeasure()` deliberately returns undefined\n * for every one of them, which is how `VM.ts` tells a currency from a unit.\n * Must stay in sync with CurrencyExchangeService's `isCurrency()`: without a\n * lexer entry a code never becomes a UNIT token, so `1 BTC to USD` used to\n * fail at tokenization with \"Undefined variable: BTC\" before ever reaching\n * the currency service that could have handled it.\n */\nconst CURRENCY_CODES = [\n \"USD\", \"EUR\", \"GBP\", \"JPY\",\n \"AUD\", \"CAD\", \"CHF\", \"CNY\", \"SEK\", \"NOK\", \"DKK\", \"NZD\",\n \"KRW\", \"SGD\", \"HKD\", \"TWD\", \"INR\", \"BRL\", \"ZAR\", \"MXN\",\n \"RUB\", \"TRY\", \"SAR\", \"AED\", \"ILS\", \"PLN\", \"CZK\", \"HUF\",\n \"THB\", \"IDR\", \"MYR\", \"PHP\", \"CLP\", \"COP\", \"ARS\", \"NGN\",\n \"EGP\", \"PKR\", \"BDT\", \"VND\", \"KES\", \"XOF\", \"XAF\", \"MAD\",\n \"QAR\", \"KWD\", \"OMR\", \"BHD\", \"JOD\", \"LKR\", \"MMK\", \"UZS\",\n \"KZT\", \"RON\", \"BGN\", \"HRK\", \"ISK\", \"UAH\", \"GEL\", \"AZN\",\n \"BTN\", \"BND\", \"BOB\", \"BWP\", \"BYN\", \"BZD\", \"CDF\", \"CRC\",\n \"CUP\", \"DOP\", \"DZD\", \"ERN\", \"ETB\", \"FJD\", \"FKP\", \"GMD\",\n \"GNF\", \"GYD\", \"HNL\", \"HTG\", \"JMD\", \"KGZ\", \"KHR\", \"KMF\",\n \"KYD\", \"LAK\", \"LBP\", \"LRD\", \"LSL\", \"LYD\", \"MDL\", \"MGA\",\n \"MKD\", \"MNT\", \"MOP\", \"MRU\", \"MUR\", \"MVR\", \"MWK\", \"MZN\",\n \"NAD\", \"NIO\", \"NPR\", \"PGK\", \"PYG\", \"RSD\", \"RWF\", \"SBD\",\n \"SCR\", \"SDG\", \"SHP\", \"SLE\", \"SOS\", \"SRD\", \"SSP\", \"STN\",\n \"SVC\", \"SYP\", \"SZL\", \"TJS\", \"TMT\", \"TND\", \"TOP\", \"TTD\",\n \"TZS\", \"UGX\", \"UYU\", \"VEB\", \"VUV\", \"WST\", \"XCD\", \"XDR\",\n \"XPF\", \"YER\", \"ZMW\", \"ZWL\",\n \"BTC\", \"ETH\", \"SOL\", \"XRP\", \"ADA\", \"DOGE\", \"DOT\",\n];\n\n/**\n * Currency WORD forms, resolved to their canonical ISO code by\n * `UomLiteralParselet.ts` via `uom/CurrencyAliases.ts`.\n *\n * That table doc-comments every ambiguous choice (peso to MXN, franc to CHF,\n * krona to SEK) and explains why \"pound\"/\"pounds\" is deliberately absent: the\n * mass unit already claims it, and remapping would be exactly the kind of\n * guessing the case-sensitive, no-alias policy exists to prevent.\n */\nconst CURRENCY_WORD_FORMS = [\n \"dollar\", \"dollars\", \"euro\", \"euros\", \"yen\",\n \"ruble\", \"rubles\", \"rouble\", \"roubles\", \"won\",\n \"rupee\", \"rupees\", \"yuan\", \"renminbi\", \"franc\", \"francs\", \"rand\",\n \"krona\", \"kronor\", \"krone\", \"kroner\", \"real\", \"reais\", \"peso\", \"pesos\",\n \"shekel\", \"shekels\", \"lira\", \"hryvnia\", \"hryvnias\", \"zloty\", \"zlotys\",\n \"forint\", \"koruna\", \"dirham\", \"dirhams\", \"riyal\", \"riyals\", \"rial\", \"rials\",\n \"ringgit\", \"rupiah\", \"baht\", \"dong\", \"naira\",\n];\n\n/**\n * \"workday\" and \"workdays\", a business day (Mon-Fri).\n *\n * Backs the datetime package's `<date> + N workdays` arithmetic and\n * `$X/workday` Rate literals. Not a real unit (a business day has no fixed\n * physical duration, it depends on which dates are weekends), so it has no\n * entry in the conversion tables and is shimmed at a fixed 7/5 ratio for rate\n * math only. See `uom/UomConverter.ts`.\n *\n * Safe with respect to variable names: VariableParselet accepts UNIT-typed\n * tokens as names, so `:workday = 5` keeps working, exactly as `:b = 5`\n * already did for the bits unit.\n */\nconst WORKDAY_UNITS = [\"workday\", \"workdays\"];\n\n/**\n * Set of all known unit identifiers (case-sensitive).\n *\n * Base units come from the conversion table; the extended units (speed,\n * voltage, parts-per and the other categories the base table has no measure\n * for) come from ExtendedUnits.ts; currencies and workdays are listed above.\n *\n * Note ExtendedUnits deliberately omits bare `V` (collides with the stocks\n * package's Visa ticker), bare `var` (reads as a variable name) and `fps`\n * (the Time package needs it for frames per second, so speed uses `ft_s`).\n * Those exclusions live there rather than here because they are properties of\n * that table.\n */\nexport const knownUnits: ReadonlySet<string> = new Set([\n ...Object.keys(UNIT_TABLE).filter(isAdmissible),\n ...Object.keys(EXTENDED_UNITS),\n ...WORKDAY_UNITS,\n ...CURRENCY_CODES,\n ...CURRENCY_WORD_FORMS,\n]);\n\n/** The exclusion list, exported so the vocabulary spec can assert each entry. */\nexport const excludedUnitSpellings: ReadonlyMap<string, string> = EXCLUDED_UNIT_SPELLINGS;\n\n/** Units are case-sensitive to eliminate ambiguity (e.g. C=Celsius, c=cup). */\nexport function isKnownUnit(text: string): boolean {\n return knownUnits.has(text);\n}\n"]}
1
+ {"version":3,"sources":["../src/lexer/units.ts"],"names":[],"mappings":";;;AAmCA,IAAM,uBAAA,uBAA2D,GAAA,CAAI;AAAA,EACnE,CAAC,MAAM,yLAAyL,CAAA;AAAA,EAChM,CAAC,OAAO,8CAA8C,CAAA;AAAA,EACtD,CAAC,KAAK,8FAA8F,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOpG,CAAC,MAAM,gFAAgF,CAAA;AAAA,EACvF,CAAC,OAAO,wEAAwE,CAAA;AAAA,EAChF,CAAC,QAAQ,2DAA2D,CAAA;AAAA,EACpE,CAAC,QAAQ,+EAA+E,CAAA;AAAA,EACxF,CAAC,SAAS,4DAA4D,CAAA;AAAA,EACtE,CAAC,SAAS,mEAAmE,CAAA;AAAA,EAC7E,CAAC,UAAU,6DAA6D,CAAA;AAAA,EACxE,CAAC,SAAS,qEAAqE,CAAA;AAAA,EAC/E,CAAC,UAAU,6DAA6D,CAAA;AAAA,EACxE,CAAC,UAAU,uEAAuE,CAAA;AAAA,EAClF,CAAC,WAAW,8DAA8D,CAAA;AAAA,EAC1E,CAAC,SAAS,sEAAsE,CAAA;AAAA,EAChF,CAAC,UAAU,6DAA6D;AAC1E,CAAC,CAAA;AAYD,SAAS,sBAAsB,QAAA,EAA2B;AACxD,EAAA,OAAO,iBAAA,CAAkB,KAAK,QAAQ,CAAA;AACxC;AAaA,IAAM,oCAAA,uBAA2C,GAAA,CAAI;AAAA,EACnD,GAAA;AAAA,EAAK,GAAA;AAAA,EAAK,GAAA;AAAA,EAAK,GAAA;AAAA,EAAK,GAAA;AAAA,EAAK,GAAA;AAAA,EAAK,GAAA;AAAA,EAAK,GAAA;AAAA,EAAK,GAAA;AAAA,EAAK,GAAA;AAAA,EAAK,GAAA;AAAA,EAAK,GAAA;AAAA,EAA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A,EACpE,SAAA;AAAA,EAAW,QAAA;AAAA,EAAU,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ;AACvC,CAAA;AAeA,IAAM,aAAA,GAAgB,CAAC,SAAA,EAAW,UAAU,CAAA;AAerC,IAAM,UAAA,uBAAsC,GAAA,CAAI;AAAA,EACrD,GAAG,MAAA,CAAO,IAAA,CAAK,UAAU,CAAA,CAAE,OAAO,YAAY,CAAA;AAAA,EAC9C,GAAG,MAAA,CAAO,IAAA,CAAK,cAAc,CAAA;AAAA,EAC7B,GAAG,aAAA;AAAA,EACH,GAAG,cAAA;AAAA,EACH,GAAG;AACL,CAAC;AAMM,SAAS,YAAY,IAAA,EAAuB;AACjD,EAAA,OAAO,UAAA,CAAW,IAAI,IAAI,CAAA;AAC5B","file":"chunk-SBUFNJVE.js","sourcesContent":["/**\n * The set of unit identifiers the lexer will turn into a UNIT token.\n *\n * DERIVED, not hand-listed. This used to be a hand-maintained list of about a\n * hundred spellings, which existed only because the conversion tables lived\n * inside a third-party package and could not be enumerated. Every spelling had\n * to be transcribed by hand and kept in sync, and this file's own history\n * records the consequences: the IEC binary prefixes (`GiB`, `TiB`) were absent\n * for a long time, and the note explaining the fix said it was \"purely a lexer\n * allowlist gap, not a conversion-logic one\".\n *\n * The tables are now in-repo (see `uom/generated/UnitTable.generated.ts`), so\n * the allowlist is computed from them. Roughly 975 base spellings are\n * recognized instead of about 101, which is why `1 kilojoule to Wh`,\n * `5 arcminutes to deg` and `2 fortnights in days` work at all.\n *\n * Units are case-sensitive to eliminate ambiguity (`C` is Celsius and `c` is a\n * cup, `B` is bytes and `b` is bits). Nothing here normalizes or aliases.\n */\n\nimport { UNIT_TABLE } from \"@solve-js/uom/generated/UnitTable.generated\";\nimport { EXTENDED_UNITS } from \"@solve-js/uom/ExtendedUnits\";\n\n/**\n * Spellings the conversion tables accept but the lexer must not claim, each\n * with its reason. `UnitVocabulary.spec.ts` asserts every one of these still\n * fails to lex, so nobody can quietly delete an entry.\n *\n * Only three spellings in the whole table collide with an existing language\n * keyword (`in`, `min`, `dec`), and `min` is left alone because it has always\n * been a time unit here and works. The rest of this list is about ordinary\n * English: a unit spelling that is also a common word turns prose into\n * arithmetic. `shouldEvaluateLine`'s prose gate is a backstop, not a licence\n * to claim every word in the dictionary.\n */\nconst EXCLUDED_UNIT_SPELLINGS: ReadonlyMap<string, string> = new Map([\n [\"in\", \"the IN keyword owns this word (the conversion operator). ConvertParselet and friends special-case the IN token type directly and trust its text as a unit name, so inches still convert\"],\n [\"dec\", \"already a converter name, as in `255 as dec`\"],\n [\"M\", \"the millions magnitude suffix, as in `2.5M`. Nautical miles are still spelled `nmi` and `NM`\"],\n // Claimed by a normalizer rule rather than by the keyword table, which is why\n // scanning the locale keywords alone does not find it. Admitting `pm`\n // (picometre) broke every clock time in the suite: `4pm` lexed as 4\n // picometres. There is deliberately no entry for `am`: the table's SI\n // prefixes stop at femto, so attometres do not exist and an exclusion would\n // be dead weight. `UnitVocabularyCollisions.spec.ts` asserts that.\n [\"pm\", \"the meridiem marker, as in `4pm`. Picometres lose, and `picometre` still works\"],\n [\"are\", \"the English verb, against a 100-square-metre unit almost nobody writes\"],\n [\"ares\", \"the English verb in plural, same reasoning as `are` above\"],\n [\"turn\", \"ordinary English, against a full-rotation angle unit also spelled in gradians\"],\n [\"turns\", \"ordinary English in plural, same reasoning as `turn` above\"],\n [\"grade\", \"ordinary English. The angle unit is also spelled `gon` and `grad`\"],\n [\"grades\", \"ordinary English in plural, same reasoning as `grade` above\"],\n [\"point\", \"ordinary English. The typographic point is also reachable as `pica`\"],\n [\"points\", \"ordinary English in plural, same reasoning as `point` above\"],\n [\"moment\", \"ordinary English, against an obscure medieval time unit of 90 seconds\"],\n [\"moments\", \"ordinary English in plural, same reasoning as `moment` above\"],\n [\"shake\", \"ordinary English, against an obscure physics unit of ten nanoseconds\"],\n [\"shakes\", \"ordinary English in plural, same reasoning as `shake` above\"],\n]);\n\n/**\n * Whether a spelling can be a single UNIT token at all.\n *\n * The lexer reads a unit as one run of `[A-Za-z0-9_]`, so the 465 spellings\n * containing a space, a slash, a prime or a non-ASCII character cannot be\n * tokenized however well the converter understands them. `square metres`,\n * `cd/m2` and `µm²` all remain reachable through the conversion API (notably\n * the cooking package's free-text target unit), just not by typing them in an\n * expression.\n */\nfunction isTokenizableSpelling(spelling: string): boolean {\n return /^[A-Za-z0-9_]+$/.test(spelling);\n}\n\n/**\n * The single-character units that were already claimed before the vocabulary\n * was derived from the tables, and are therefore grandfathered in.\n *\n * No OTHER single character is admitted. A one-letter unit is indistinguishable\n * from the placeholder names people actually write (`x`, `y`, `n`), and the\n * table has ten more of them: `r a y c p S L N J R`. Admitting those turned\n * `x.y` into a unit expression and broke comparison-operator tests that had\n * deliberately picked letters which were not units. The upside was a handful of\n * spellings that all have an unambiguous longer form (`rad`, `year`, `cup`).\n */\nconst GRANDFATHERED_SINGLE_CHARACTER_UNITS = new Set([\n \"m\", \"g\", \"t\", \"s\", \"h\", \"d\", \"l\", \"b\", \"B\", \"C\", \"F\", \"K\", \"W\",\n]);\n\n/** Whether a base-table spelling should become a lexer token. */\nfunction isAdmissible(spelling: string): boolean {\n if (!isTokenizableSpelling(spelling)) return false;\n if (EXCLUDED_UNIT_SPELLINGS.has(spelling)) return false;\n if (spelling.length === 1) return GRANDFATHERED_SINGLE_CHARACTER_UNITS.has(spelling);\n return true;\n}\n\n/**\n * ISO 4217 codes and the crypto tickers handled alongside them.\n *\n * Hand-maintained on purpose: these are NOT units. They route through\n * CurrencyExchangeService, and `getMeasure()` deliberately returns undefined\n * for every one of them, which is how `VM.ts` tells a currency from a unit.\n * Must stay in sync with CurrencyExchangeService's `isCurrency()`: without a\n * lexer entry a code never becomes a UNIT token, so `1 BTC to USD` used to\n * fail at tokenization with \"Undefined variable: BTC\" before ever reaching\n * the currency service that could have handled it.\n */\nconst CURRENCY_CODES = [\n \"USD\", \"EUR\", \"GBP\", \"JPY\",\n \"AUD\", \"CAD\", \"CHF\", \"CNY\", \"SEK\", \"NOK\", \"DKK\", \"NZD\",\n \"KRW\", \"SGD\", \"HKD\", \"TWD\", \"INR\", \"BRL\", \"ZAR\", \"MXN\",\n \"RUB\", \"TRY\", \"SAR\", \"AED\", \"ILS\", \"PLN\", \"CZK\", \"HUF\",\n \"THB\", \"IDR\", \"MYR\", \"PHP\", \"CLP\", \"COP\", \"ARS\", \"NGN\",\n \"EGP\", \"PKR\", \"BDT\", \"VND\", \"KES\", \"XOF\", \"XAF\", \"MAD\",\n \"QAR\", \"KWD\", \"OMR\", \"BHD\", \"JOD\", \"LKR\", \"MMK\", \"UZS\",\n \"KZT\", \"RON\", \"BGN\", \"HRK\", \"ISK\", \"UAH\", \"GEL\", \"AZN\",\n \"BTN\", \"BND\", \"BOB\", \"BWP\", \"BYN\", \"BZD\", \"CDF\", \"CRC\",\n \"CUP\", \"DOP\", \"DZD\", \"ERN\", \"ETB\", \"FJD\", \"FKP\", \"GMD\",\n \"GNF\", \"GYD\", \"HNL\", \"HTG\", \"JMD\", \"KGZ\", \"KHR\", \"KMF\",\n \"KYD\", \"LAK\", \"LBP\", \"LRD\", \"LSL\", \"LYD\", \"MDL\", \"MGA\",\n \"MKD\", \"MNT\", \"MOP\", \"MRU\", \"MUR\", \"MVR\", \"MWK\", \"MZN\",\n \"NAD\", \"NIO\", \"NPR\", \"PGK\", \"PYG\", \"RSD\", \"RWF\", \"SBD\",\n \"SCR\", \"SDG\", \"SHP\", \"SLE\", \"SOS\", \"SRD\", \"SSP\", \"STN\",\n \"SVC\", \"SYP\", \"SZL\", \"TJS\", \"TMT\", \"TND\", \"TOP\", \"TTD\",\n \"TZS\", \"UGX\", \"UYU\", \"VEB\", \"VUV\", \"WST\", \"XCD\", \"XDR\",\n \"XPF\", \"YER\", \"ZMW\", \"ZWL\",\n \"BTC\", \"ETH\", \"SOL\", \"XRP\", \"ADA\", \"DOGE\", \"DOT\",\n];\n\n/**\n * Currency WORD forms, resolved to their canonical ISO code by\n * `UomLiteralParselet.ts` via `uom/CurrencyAliases.ts`.\n *\n * That table doc-comments every ambiguous choice (peso to MXN, franc to CHF,\n * krona to SEK) and explains why \"pound\"/\"pounds\" is deliberately absent: the\n * mass unit already claims it, and remapping would be exactly the kind of\n * guessing the case-sensitive, no-alias policy exists to prevent.\n */\nconst CURRENCY_WORD_FORMS = [\n \"dollar\", \"dollars\", \"euro\", \"euros\", \"yen\",\n \"ruble\", \"rubles\", \"rouble\", \"roubles\", \"won\",\n \"rupee\", \"rupees\", \"yuan\", \"renminbi\", \"franc\", \"francs\", \"rand\",\n \"krona\", \"kronor\", \"krone\", \"kroner\", \"real\", \"reais\", \"peso\", \"pesos\",\n \"shekel\", \"shekels\", \"lira\", \"hryvnia\", \"hryvnias\", \"zloty\", \"zlotys\",\n \"forint\", \"koruna\", \"dirham\", \"dirhams\", \"riyal\", \"riyals\", \"rial\", \"rials\",\n \"ringgit\", \"rupiah\", \"baht\", \"dong\", \"naira\",\n];\n\n/**\n * \"workday\" and \"workdays\", a business day (Mon-Fri).\n *\n * Backs the datetime package's `<date> + N workdays` arithmetic and\n * `$X/workday` Rate literals. Not a real unit (a business day has no fixed\n * physical duration, it depends on which dates are weekends), so it has no\n * entry in the conversion tables and is shimmed at a fixed 7/5 ratio for rate\n * math only. See `uom/UomConverter.ts`.\n *\n * Safe with respect to variable names: VariableParselet accepts UNIT-typed\n * tokens as names, so `:workday = 5` keeps working, exactly as `:b = 5`\n * already did for the bits unit.\n */\nconst WORKDAY_UNITS = [\"workday\", \"workdays\"];\n\n/**\n * Set of all known unit identifiers (case-sensitive).\n *\n * Base units come from the conversion table; the extended units (speed,\n * voltage, parts-per and the other categories the base table has no measure\n * for) come from ExtendedUnits.ts; currencies and workdays are listed above.\n *\n * Note ExtendedUnits deliberately omits bare `V` (collides with the stocks\n * package's Visa ticker), bare `var` (reads as a variable name) and `fps`\n * (the Time package needs it for frames per second, so speed uses `ft_s`).\n * Those exclusions live there rather than here because they are properties of\n * that table.\n */\nexport const knownUnits: ReadonlySet<string> = new Set([\n ...Object.keys(UNIT_TABLE).filter(isAdmissible),\n ...Object.keys(EXTENDED_UNITS),\n ...WORKDAY_UNITS,\n ...CURRENCY_CODES,\n ...CURRENCY_WORD_FORMS,\n]);\n\n/** The exclusion list, exported so the vocabulary spec can assert each entry. */\nexport const excludedUnitSpellings: ReadonlyMap<string, string> = EXCLUDED_UNIT_SPELLINGS;\n\n/** Units are case-sensitive to eliminate ambiguity (e.g. C=Celsius, c=cup). */\nexport function isKnownUnit(text: string): boolean {\n return knownUnits.has(text);\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { createTimeoutSignal } from './chunk-Z4X2RWOF.js';
2
- import { ErrorFactory } from './chunk-6RDSQURE.js';
2
+ import { ErrorFactory } from './chunk-3D7V24DG.js';
3
3
 
4
4
  // src/uom/Iso4217.ts
5
5
  var ISO_4217_CODES = /* @__PURE__ */ new Set([
@@ -451,5 +451,5 @@ var currencyExchangeService = new CurrencyExchangeService();
451
451
  var sharedCurrencyExchange = currencyExchangeService;
452
452
 
453
453
  export { CurrencyExchangeService, currencyExchangeService, sharedCurrencyExchange };
454
- //# sourceMappingURL=chunk-UKPGSAZW.js.map
455
- //# sourceMappingURL=chunk-UKPGSAZW.js.map
454
+ //# sourceMappingURL=chunk-TMA4RCEN.js.map
455
+ //# sourceMappingURL=chunk-TMA4RCEN.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/uom/Iso4217.ts","../src/uom/CurrencyExchange.ts"],"names":[],"mappings":";;;;AAyBO,IAAM,cAAA,uBAA0C,GAAA,CAAI;AAAA,EAC1D,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAC/D,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA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A/Sa,wBAAA,CAiBa,iBAAA,GAAoB,KAAK,EAAA,GAAK,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAjB3C,wBAAA,CA4Ba,UAAA,GAAqC;AAAA,EAC3D,GAAA,EAAK,SAAA;AAAA,EAAW,GAAA,EAAK,UAAA;AAAA,EAAY,GAAA,EAAK,QAAA;AAAA,EAAU,GAAA,EAAK,QAAA;AAAA,EACrD,GAAA,EAAK,SAAA;AAAA,EAAW,IAAA,EAAM,UAAA;AAAA,EAAY,GAAA,EAAK;AACzC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA/BW,wBAAA,CAkDa,gBAAA,GAAmB,GAAA;AAlDtC,IAAM,uBAAA,GAAN;AAsTA,IAAM,uBAAA,GAA0B,IAAI,uBAAA;AAIpC,IAAM,sBAAA,GAAyB","file":"chunk-UKPGSAZW.js","sourcesContent":["/**\n * Every active ISO 4217 currency code.\n *\n * This exists because `CurrencyExchange.isCurrency()` used to hold a\n * hand-written list of forty-six codes, and a code missing from it did not\n * error: `$100 in UAH` returned the original hundred dollars, unconverted, as\n * though the rate were 1. A wrong answer, not a missing feature.\n *\n * The list is the ISO 4217 active set, so \"is this a currency\" is answered by\n * the standard rather than by whichever codes happened to get added. Whether a\n * *rate* is available for one is a separate question, answered at resolution\n * time by whatever the exchange provider supports; conflating the two is what\n * produced the silent failure.\n *\n * Deliberately excluded:\n * - The historical/withdrawn codes (DEM, FRF, and the rest). They are not\n * active, no provider quotes them, and recognising them would only move the\n * failure later.\n * - The X-series non-currencies: XAU/XAG/XPT/XPD (metals), XDR (IMF special\n * drawing rights), XTS (reserved for testing) and XXX (explicitly \"no\n * currency\"). XXX in particular must never resolve.\n *\n * Cryptocurrencies are not here either. They are not ISO 4217 and are tracked\n * separately in `CurrencyExchangeService.CRYPTO_IDS`.\n */\nexport const ISO_4217_CODES: ReadonlySet<string> = new Set([\n\t\"AED\", \"AFN\", \"ALL\", \"AMD\", \"ANG\", \"AOA\", \"ARS\", \"AUD\", \"AWG\", \"AZN\",\n\t\"BAM\", \"BBD\", \"BDT\", \"BGN\", \"BHD\", \"BIF\", \"BMD\", \"BND\", \"BOB\", \"BOV\",\n\t\"BRL\", \"BSD\", \"BTN\", \"BWP\", \"BYN\", \"BZD\",\n\t\"CAD\", \"CDF\", \"CHE\", \"CHF\", \"CHW\", \"CLF\", \"CLP\", \"CNY\", \"COP\", \"COU\",\n\t\"CRC\", \"CUP\", \"CVE\", \"CZK\",\n\t\"DJF\", \"DKK\", \"DOP\", \"DZD\",\n\t\"EGP\", \"ERN\", \"ETB\", \"EUR\",\n\t\"FJD\", \"FKP\",\n\t\"GBP\", \"GEL\", \"GHS\", \"GIP\", \"GMD\", \"GNF\", \"GTQ\", \"GYD\",\n\t\"HKD\", \"HNL\", \"HTG\", \"HUF\",\n\t\"IDR\", \"ILS\", \"INR\", \"IQD\", \"IRR\", \"ISK\",\n\t\"JMD\", \"JOD\", \"JPY\",\n\t\"KES\", \"KGS\", \"KHR\", \"KMF\", \"KPW\", \"KRW\", \"KWD\", \"KYD\", \"KZT\",\n\t\"LAK\", \"LBP\", \"LKR\", \"LRD\", \"LSL\", \"LYD\",\n\t\"MAD\", \"MDL\", \"MGA\", \"MKD\", \"MMK\", \"MNT\", \"MOP\", \"MRU\", \"MUR\", \"MVR\",\n\t\"MWK\", \"MXN\", \"MXV\", \"MYR\", \"MZN\",\n\t\"NAD\", \"NGN\", \"NIO\", \"NOK\", \"NPR\", \"NZD\",\n\t\"OMR\",\n\t\"PAB\", \"PEN\", \"PGK\", \"PHP\", \"PKR\", \"PLN\", \"PYG\",\n\t\"QAR\",\n\t\"RON\", \"RSD\", \"RUB\", \"RWF\",\n\t\"SAR\", \"SBD\", \"SCR\", \"SDG\", \"SEK\", \"SGD\", \"SHP\", \"SLE\", \"SOS\", \"SRD\",\n\t\"SSP\", \"STN\", \"SVC\", \"SYP\", \"SZL\",\n\t\"THB\", \"TJS\", \"TMT\", \"TND\", \"TOP\", \"TRY\", \"TTD\", \"TWD\", \"TZS\",\n\t\"UAH\", \"UGX\", \"USD\", \"USN\", \"UYI\", \"UYU\", \"UYW\", \"UZS\",\n\t\"VED\", \"VES\", \"VND\", \"VUV\",\n\t\"WST\",\n\t\"XAF\", \"XCD\", \"XCG\", \"XOF\", \"XPF\",\n\t\"YER\",\n\t\"ZAR\", \"ZMW\", \"ZWG\",\n]);\n\n/**\n * Whether `code` is an active ISO 4217 currency code.\n *\n * @param code - A three-letter code, in any case.\n */\nexport function isIso4217(code: string): boolean {\n\treturn ISO_4217_CODES.has(code.toUpperCase());\n}\n","/**\n * Production-grade currency exchange service with scalable architecture\n * Integrates with DataQueryService for worker-based execution\n */\n\nimport { isIso4217 } from \"@solve-js/uom/Iso4217\";\nimport { createTimeoutSignal } from \"@solve-js/utilities/TimeoutSignal\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * Error codes for this service. Co-located rather than unioned into\n * `errors/ErrorCode.ts`'s core catalog (that catalog is scoped to the\n * parser/VM/engine/errors/config/lexer layers, not yet the ~17 domain\n * packages. See that file's module doc for the intended per-package\n * pattern this follows).\n */\nexport const CurrencyErrorCodes = {\n /** Frankfurter's rates endpoint returned a non-OK HTTP status. */\n API_ERROR: \"CURRENCY_API_ERROR\",\n /** A requested currency/crypto code isn't in the fetched rate table, an unrecognized code, not an API failure. */\n UNKNOWN_CODE: \"UNKNOWN_CURRENCY_CODE\",\n /** CoinGecko's simple-price endpoint returned a non-OK HTTP status. */\n CRYPTO_API_ERROR: \"CRYPTO_PRICE_API_ERROR\",\n} as const;\n\n// ============================================================================\n// CURRENCY EXCHANGE SERVICE\n// ============================================================================\n\n/**\n * Caches exchange rates fetched from an external source.\n *\n * Rates are global market data rather than per-engine configuration, which is\n * why one instance is shared. Two engines with private copies would fetch the\n * same endpoint twice and could disagree about one pair at one moment. See\n * `engine/EngineContext.ts`.\n */\nexport class CurrencyExchangeService {\n /**\n * Live rate tables cached from successful getRate() fetches, keyed by\n * uppercase base currency. Each table holds every rate the API returned\n * for that base (plus the base itself at 1), so any pair whose two codes\n * appear in one fresh table can be served synchronously, including\n * cross pairs via triangulation (EUR→GBP through a USD-base table).\n * Stale tables are ignored, not evicted; the next successful fetch for\n * the same base overwrites them.\n */\n private baseTables: Map<string, { fetchedAt: number; rates: Record<string, number> }> = new Map();\n\n /**\n * How long a fetched rate may be served synchronously by getRateSync().\n * Beyond this window callers fall through to the async path (expression\n * shows Pending until the fetch lands).\n */\n private static readonly RATE_FRESHNESS_MS = 15 * 60 * 1000;\n\n /**\n * Ticker → CoinGecko coin id, for the cryptocurrencies `isCurrency()`\n * recognizes. Frankfurter (the fiat rate source below) is ECB reference\n * rates only and has no concept of BTC/ETH/etc, routing a crypto code\n * through it as `base=BTC` fails outright, which is why crypto pairs\n * previously never resolved (see CurrencyAsyncResolver/VM.ts's ADD\n * handling for the two bugs that let that failure pass silently instead\n * of surfacing as a real fetch).\n */\n private static readonly CRYPTO_IDS: Record<string, string> = {\n BTC: \"bitcoin\", ETH: \"ethereum\", SOL: \"solana\", XRP: \"ripple\",\n ADA: \"cardano\", DOGE: \"dogecoin\", DOT: \"polkadot\",\n };\n\n private isCryptoCode(code: string): boolean {\n return code.toUpperCase() in CurrencyExchangeService.CRYPTO_IDS;\n }\n\n constructor() {}\n\n // ------------------------------------------------------------------------\n // RATE FETCHING\n // ------------------------------------------------------------------------\n\n /**\n * Timeout (ms) for currency exchange rate fetches.\n *\n * If the frankfurter API doesn't respond within this window, the fetch\n * is aborted, preventing indefinite \"Pending\" states in the playground\n * and Obsidian plugin when the exchange rate API is unreachable.\n */\n private static readonly FETCH_TIMEOUT_MS = 10_000;\n\n /**\n * Fetch the live exchange rate for converting 1 unit of `from` into `to`.\n *\n * Routes cryptocurrency codes (see {@link CRYPTO_IDS}) to CoinGecko and\n * everything else to Frankfurter (ECB reference rates, fiat-only). On\n * success, caches the whole returned rate table for `from` so subsequent\n * lookups, including cross-pairs via triangulation, can be served\n * synchronously by {@link getRateSync} within the freshness window.\n *\n * @throws If the currency code is unrecognized or the fetch fails/times out.\n */\n async getRate(from: string, to: string, signal?: AbortSignal): Promise<number> {\n const fromUpper = from.toUpperCase();\n const toUpper = to.toUpperCase();\n\n if (this.isCryptoCode(fromUpper) || this.isCryptoCode(toUpper)) {\n return this.getCryptoRate(fromUpper, toUpper, signal);\n }\n\n // Combine the caller's optional abort signal with a hard timeout so a\n // hanging currency API never blocks re-evaluation indefinitely.\n const { signal: fetchSignal, cleanup } = createTimeoutSignal(\n signal,\n CurrencyExchangeService.FETCH_TIMEOUT_MS,\n \"Currency API fetch\",\n );\n\n try {\n const response = await fetch(`https://api.frankfurter.dev/v2/rates?base=${fromUpper}`, { signal: fetchSignal });\n if (!response.ok) throw ErrorFactory.external(CurrencyErrorCodes.API_ERROR, `Currency API returned ${response.status}`, { status: response.status });\n const data = await response.json();\n // The v2 endpoint returns a flat array of { date, base, quote, rate }\n // entries (one per target currency) rather than the classic v1 shape\n // { base, date, rates: { CODE: rate } }. Reading data.rates against\n // the real response is always undefined, so every conversion used to\n // throw \"Unknown currency\" no matter which currencies were requested.\n // Accept both shapes so a future API revision back to the object form\n // doesn't silently break this again.\n const rates: Record<string, number> = Array.isArray(data)\n ? Object.fromEntries(\n data\n .filter((entry: unknown): entry is { quote: string; rate: number } => {\n if (typeof entry !== \"object\" || entry === null) return false;\n const candidate = entry as { quote?: unknown; rate?: unknown };\n return typeof candidate.quote === \"string\" && typeof candidate.rate === \"number\";\n })\n .map((entry: { quote: string; rate: number }) => [entry.quote.toUpperCase(), entry.rate])\n )\n : (data.rates ?? {});\n if (rates[toUpper] === undefined) throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${toUpper}`, { code: toUpper });\n\n // The API returns ALL rates for the base currency, cache the whole\n // table so subsequent conversions (including cross pairs via\n // triangulation) resolve synchronously within the freshness window\n // instead of going Pending again.\n this.baseTables.set(fromUpper, {\n fetchedAt: Date.now(),\n rates: { ...rates, [fromUpper]: 1 },\n });\n\n return rates[toUpper];\n } finally {\n cleanup();\n }\n }\n\n /**\n * Crypto rate fetch, routed through CoinGecko's no-auth simple-price\n * endpoint instead of Frankfurter (fiat-only, has no BTC/ETH concept).\n * Handles all three combinations, crypto→crypto, crypto→fiat\n * fiat→crypto, via prices denominated in USD (or the target fiat\n * directly, which CoinGecko's `vs_currencies` also accepts), then\n * caches the result as a same-shaped base table so getRateSync /\n * convertSync keep working unchanged for crypto pairs too.\n */\n private async getCryptoRate(fromUpper: string, toUpper: string, signal?: AbortSignal): Promise<number> {\n const { signal: fetchSignal, cleanup } = createTimeoutSignal(\n signal,\n CurrencyExchangeService.FETCH_TIMEOUT_MS,\n \"Crypto price API fetch\",\n );\n\n try {\n const fromIsCrypto = this.isCryptoCode(fromUpper);\n const toIsCrypto = this.isCryptoCode(toUpper);\n let rate: number;\n\n if (fromIsCrypto && toIsCrypto) {\n const fromId = CurrencyExchangeService.CRYPTO_IDS[fromUpper];\n const toId = CurrencyExchangeService.CRYPTO_IDS[toUpper];\n const data = await this.fetchCoinGeckoPrices([fromId, toId], \"usd\", fetchSignal);\n const fromUsd = data[fromId]?.usd;\n const toUsd = data[toId]?.usd;\n if (typeof fromUsd !== \"number\") throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${fromUpper}`, { code: fromUpper });\n if (typeof toUsd !== \"number\") throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${toUpper}`, { code: toUpper });\n rate = fromUsd / toUsd;\n } else if (fromIsCrypto) {\n const fromId = CurrencyExchangeService.CRYPTO_IDS[fromUpper];\n const vs = toUpper.toLowerCase();\n const data = await this.fetchCoinGeckoPrices([fromId], vs, fetchSignal);\n const value = data[fromId]?.[vs];\n if (typeof value !== \"number\") throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${toUpper}`, { code: toUpper });\n rate = value;\n } else {\n const toId = CurrencyExchangeService.CRYPTO_IDS[toUpper];\n const vs = fromUpper.toLowerCase();\n const data = await this.fetchCoinGeckoPrices([toId], vs, fetchSignal);\n const priceOfToInFrom = data[toId]?.[vs];\n if (typeof priceOfToInFrom !== \"number\") throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${fromUpper}`, { code: fromUpper });\n rate = 1 / priceOfToInFrom;\n }\n\n // Cache as a single-pair base table, same shape Frankfurter fetches\n // produce, so getRateSync/convertSync's triangulation logic doesn't\n // need to know or care which source a rate came from.\n this.baseTables.set(fromUpper, {\n fetchedAt: Date.now(),\n rates: { [fromUpper]: 1, [toUpper]: rate },\n });\n\n return rate;\n } finally {\n cleanup();\n }\n }\n\n private async fetchCoinGeckoPrices(ids: string[], vsCurrency: string, signal: AbortSignal): Promise<Record<string, Record<string, number>>> {\n const url = `https://api.coingecko.com/api/v3/simple/price?ids=${ids.join(\",\")}&vs_currencies=${vsCurrency}`;\n const response = await fetch(url, { signal });\n if (!response.ok) throw ErrorFactory.external(CurrencyErrorCodes.CRYPTO_API_ERROR, `Crypto price API returned ${response.status}`, { status: response.status });\n return response.json();\n }\n\n /**\n * Seed a base rate table without a network fetch.\n *\n * Intended for tests and for future user-provided offline rates\n * production live data always comes from {@link getRate}. Seeded rates\n * obey the same freshness window as fetched ones.\n *\n * @param base - Base currency code (e.g. \"USD\").\n * @param rates - Map of currency code → rate relative to the base.\n */\n primeRates(base: string, rates: Record<string, number>): void {\n const baseUpper = base.toUpperCase();\n this.baseTables.set(baseUpper, {\n fetchedAt: Date.now(),\n rates: { ...rates, [baseUpper]: 1 },\n });\n }\n\n /**\n * Drop every cached/primed rate table.\n *\n * Mainly for test isolation: {@link sharedCurrencyExchange} is a\n * module-level singleton, so a rate primed or fetched by one test can\n * silently leak into a later test in the same file. Also usable in\n * production if a caller ever wants to force a full re-fetch.\n */\n clearRates(): void {\n this.baseTables.clear();\n }\n\n /**\n * Synchronous rate lookup: `1` for same-currency pairs, a cached LIVE\n * rate if one was fetched within {@link RATE_FRESHNESS_MS}, otherwise\n * `null`, callers fall through to the async fetch path and the\n * expression shows Pending until real data arrives.\n *\n * There is deliberately no hardcoded fallback table: a stale made-up\n * rate presented as a real conversion is worse than a Pending state.\n */\n getRateSync(from: string, to: string): number | null {\n const fromUpper = from.toUpperCase();\n const toUpper = to.toUpperCase();\n if (fromUpper === toUpper) {\n return 1;\n }\n const now = Date.now();\n for (const table of this.baseTables.values()) {\n if (now - table.fetchedAt > CurrencyExchangeService.RATE_FRESHNESS_MS) continue;\n const fromRate = table.rates[fromUpper];\n const toRate = table.rates[toUpper];\n if (fromRate && toRate) {\n return toRate / fromRate;\n }\n }\n return null;\n }\n\n /** Convert `value` from `from` to `to` using a freshly-fetched live rate (see {@link getRate}). */\n async convert(value: number, from: string, to: string): Promise<number> {\n const rate = await this.getRate(from, to);\n return value * rate;\n }\n\n /**\n * Get all currently cached fresh rates, keyed \"FROM:TO\".\n * @returns Snapshot of fresh live rates, or null when none are cached.\n */\n getAllRates(): Record<string, number> | null {\n const now = Date.now();\n const snapshot: Record<string, number> = {};\n let any = false;\n for (const [base, table] of this.baseTables) {\n if (now - table.fetchedAt > CurrencyExchangeService.RATE_FRESHNESS_MS) continue;\n for (const [code, rate] of Object.entries(table.rates)) {\n snapshot[`${base}:${code}`] = rate;\n any = true;\n }\n }\n return any ? snapshot : null;\n }\n\n /**\n * Check whether any fresh live rates are currently cached.\n */\n hasRates(): boolean {\n return this.getAllRates() !== null;\n }\n\n /**\n * Synchronous conversion using cached rates only\n * Returns null if rate not in cache\n */\n convertSync(value: number, from: string, to: string): number | null {\n const rate = this.getRateSync(from, to);\n if (rate === null) return null;\n return value * rate;\n }\n\n // ------------------------------------------------------------------------\n // CURRENCY VALIDATION\n // ------------------------------------------------------------------------\n\n /**\n * Check whether `code` is a recognized currency code: any active ISO 4217\n * code, or one of the cryptocurrencies in {@link CRYPTO_IDS}.\n *\n * This used to be a hand-written list of forty-six codes, which meant\n * `$100 in UAH` returned an unconverted hundred dollars rather than saying\n * it could not convert. Answering from the standard rather than from\n * whichever codes happened to get added is what stops that class of bug.\n *\n * Recognising a code is not the same as having a rate for it. That is\n * answered later, by the exchange provider; conflating the two is what\n * produced the silent failure.\n */\n isCurrency(code: string): boolean {\n return isIso4217(code) || this.isCryptoCode(code);\n }\n}\n\n// ============================================================================\n// SINGLETON INSTANCE\n// ============================================================================\n\n/** The shared rate cache. See {@link CurrencyExchangeService} for why it is shared. */\nexport const currencyExchangeService = new CurrencyExchangeService();\n\n// Export for backward compatibility\n/** Alias for {@link currencyExchangeService}, kept for older imports. */\nexport const sharedCurrencyExchange = currencyExchangeService;\n\n// Default export\nexport default currencyExchangeService;\n"]}
1
+ {"version":3,"sources":["../src/uom/Iso4217.ts","../src/uom/CurrencyExchange.ts"],"names":[],"mappings":";;;;AAyBO,IAAM,cAAA,uBAA0C,GAAA,CAAI;AAAA,EAC1D,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAC/D,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAC/D,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EACnC,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,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AACzC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA/BW,wBAAA,CAkDa,gBAAA,GAAmB,GAAA;AAlDtC,IAAM,uBAAA,GAAN;AAsTA,IAAM,uBAAA,GAA0B,IAAI,uBAAA;AAIpC,IAAM,sBAAA,GAAyB","file":"chunk-TMA4RCEN.js","sourcesContent":["/**\n * Every active ISO 4217 currency code.\n *\n * This exists because `CurrencyExchange.isCurrency()` used to hold a\n * hand-written list of forty-six codes, and a code missing from it did not\n * error: `$100 in UAH` returned the original hundred dollars, unconverted, as\n * though the rate were 1. A wrong answer, not a missing feature.\n *\n * The list is the ISO 4217 active set, so \"is this a currency\" is answered by\n * the standard rather than by whichever codes happened to get added. Whether a\n * *rate* is available for one is a separate question, answered at resolution\n * time by whatever the exchange provider supports; conflating the two is what\n * produced the silent failure.\n *\n * Deliberately excluded:\n * - The historical/withdrawn codes (DEM, FRF, and the rest). They are not\n * active, no provider quotes them, and recognising them would only move the\n * failure later.\n * - The X-series non-currencies: XAU/XAG/XPT/XPD (metals), XDR (IMF special\n * drawing rights), XTS (reserved for testing) and XXX (explicitly \"no\n * currency\"). XXX in particular must never resolve.\n *\n * Cryptocurrencies are not here either. They are not ISO 4217 and are tracked\n * separately in `CurrencyExchangeService.CRYPTO_IDS`.\n */\nexport const ISO_4217_CODES: ReadonlySet<string> = new Set([\n\t\"AED\", \"AFN\", \"ALL\", \"AMD\", \"ANG\", \"AOA\", \"ARS\", \"AUD\", \"AWG\", \"AZN\",\n\t\"BAM\", \"BBD\", \"BDT\", \"BGN\", \"BHD\", \"BIF\", \"BMD\", \"BND\", \"BOB\", \"BOV\",\n\t\"BRL\", \"BSD\", \"BTN\", \"BWP\", \"BYN\", \"BZD\",\n\t\"CAD\", \"CDF\", \"CHE\", \"CHF\", \"CHW\", \"CLF\", \"CLP\", \"CNY\", \"COP\", \"COU\",\n\t\"CRC\", \"CUP\", \"CVE\", \"CZK\",\n\t\"DJF\", \"DKK\", \"DOP\", \"DZD\",\n\t\"EGP\", \"ERN\", \"ETB\", \"EUR\",\n\t\"FJD\", \"FKP\",\n\t\"GBP\", \"GEL\", \"GHS\", \"GIP\", \"GMD\", \"GNF\", \"GTQ\", \"GYD\",\n\t\"HKD\", \"HNL\", \"HTG\", \"HUF\",\n\t\"IDR\", \"ILS\", \"INR\", \"IQD\", \"IRR\", \"ISK\",\n\t\"JMD\", \"JOD\", \"JPY\",\n\t\"KES\", \"KGS\", \"KHR\", \"KMF\", \"KPW\", \"KRW\", \"KWD\", \"KYD\", \"KZT\",\n\t\"LAK\", \"LBP\", \"LKR\", \"LRD\", \"LSL\", \"LYD\",\n\t\"MAD\", \"MDL\", \"MGA\", \"MKD\", \"MMK\", \"MNT\", \"MOP\", \"MRU\", \"MUR\", \"MVR\",\n\t\"MWK\", \"MXN\", \"MXV\", \"MYR\", \"MZN\",\n\t\"NAD\", \"NGN\", \"NIO\", \"NOK\", \"NPR\", \"NZD\",\n\t\"OMR\",\n\t\"PAB\", \"PEN\", \"PGK\", \"PHP\", \"PKR\", \"PLN\", \"PYG\",\n\t\"QAR\",\n\t\"RON\", \"RSD\", \"RUB\", \"RWF\",\n\t\"SAR\", \"SBD\", \"SCR\", \"SDG\", \"SEK\", \"SGD\", \"SHP\", \"SLE\", \"SOS\", \"SRD\",\n\t\"SSP\", \"STN\", \"SVC\", \"SYP\", \"SZL\",\n\t\"THB\", \"TJS\", \"TMT\", \"TND\", \"TOP\", \"TRY\", \"TTD\", \"TWD\", \"TZS\",\n\t\"UAH\", \"UGX\", \"USD\", \"USN\", \"UYI\", \"UYU\", \"UYW\", \"UZS\",\n\t\"VED\", \"VES\", \"VND\", \"VUV\",\n\t\"WST\",\n\t\"XAF\", \"XCD\", \"XCG\", \"XOF\", \"XPF\",\n\t\"YER\",\n\t\"ZAR\", \"ZMW\", \"ZWG\",\n]);\n\n/**\n * Whether `code` is an active ISO 4217 currency code.\n *\n * @param code - A three-letter code, in any case.\n */\nexport function isIso4217(code: string): boolean {\n\treturn ISO_4217_CODES.has(code.toUpperCase());\n}\n","/**\n * Production-grade currency exchange service with scalable architecture\n * Integrates with DataQueryService for worker-based execution\n */\n\nimport { isIso4217 } from \"@solve-js/uom/Iso4217\";\nimport { createTimeoutSignal } from \"@solve-js/utilities/TimeoutSignal\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * Error codes for this service. Co-located rather than unioned into\n * `errors/ErrorCode.ts`'s core catalog (that catalog is scoped to the\n * parser/VM/engine/errors/config/lexer layers, not yet the ~17 domain\n * packages. See that file's module doc for the intended per-package\n * pattern this follows).\n */\nexport const CurrencyErrorCodes = {\n /** Frankfurter's rates endpoint returned a non-OK HTTP status. */\n API_ERROR: \"CURRENCY_API_ERROR\",\n /** A requested currency/crypto code isn't in the fetched rate table, an unrecognized code, not an API failure. */\n UNKNOWN_CODE: \"UNKNOWN_CURRENCY_CODE\",\n /** CoinGecko's simple-price endpoint returned a non-OK HTTP status. */\n CRYPTO_API_ERROR: \"CRYPTO_PRICE_API_ERROR\",\n} as const;\n\n// ============================================================================\n// CURRENCY EXCHANGE SERVICE\n// ============================================================================\n\n/**\n * Caches exchange rates fetched from an external source.\n *\n * Rates are global market data rather than per-engine configuration, which is\n * why one instance is shared. Two engines with private copies would fetch the\n * same endpoint twice and could disagree about one pair at one moment. See\n * `engine/EngineContext.ts`.\n */\nexport class CurrencyExchangeService {\n /**\n * Live rate tables cached from successful getRate() fetches, keyed by\n * uppercase base currency. Each table holds every rate the API returned\n * for that base (plus the base itself at 1), so any pair whose two codes\n * appear in one fresh table can be served synchronously, including\n * cross pairs via triangulation (EUR→GBP through a USD-base table).\n * Stale tables are ignored, not evicted; the next successful fetch for\n * the same base overwrites them.\n */\n private baseTables: Map<string, { fetchedAt: number; rates: Record<string, number> }> = new Map();\n\n /**\n * How long a fetched rate may be served synchronously by getRateSync().\n * Beyond this window callers fall through to the async path (expression\n * shows Pending until the fetch lands).\n */\n private static readonly RATE_FRESHNESS_MS = 15 * 60 * 1000;\n\n /**\n * Ticker → CoinGecko coin id, for the cryptocurrencies `isCurrency()`\n * recognizes. Frankfurter (the fiat rate source below) is ECB reference\n * rates only and has no concept of BTC/ETH/etc, routing a crypto code\n * through it as `base=BTC` fails outright, which is why crypto pairs\n * previously never resolved (see CurrencyAsyncResolver/VM.ts's ADD\n * handling for the two bugs that let that failure pass silently instead\n * of surfacing as a real fetch).\n */\n private static readonly CRYPTO_IDS: Record<string, string> = {\n BTC: \"bitcoin\", ETH: \"ethereum\", SOL: \"solana\", XRP: \"ripple\",\n ADA: \"cardano\", DOGE: \"dogecoin\", DOT: \"polkadot\",\n };\n\n private isCryptoCode(code: string): boolean {\n return code.toUpperCase() in CurrencyExchangeService.CRYPTO_IDS;\n }\n\n constructor() {}\n\n // ------------------------------------------------------------------------\n // RATE FETCHING\n // ------------------------------------------------------------------------\n\n /**\n * Timeout (ms) for currency exchange rate fetches.\n *\n * If the frankfurter API doesn't respond within this window, the fetch\n * is aborted, preventing indefinite \"Pending\" states in the playground\n * and Obsidian plugin when the exchange rate API is unreachable.\n */\n private static readonly FETCH_TIMEOUT_MS = 10_000;\n\n /**\n * Fetch the live exchange rate for converting 1 unit of `from` into `to`.\n *\n * Routes cryptocurrency codes (see {@link CRYPTO_IDS}) to CoinGecko and\n * everything else to Frankfurter (ECB reference rates, fiat-only). On\n * success, caches the whole returned rate table for `from` so subsequent\n * lookups, including cross-pairs via triangulation, can be served\n * synchronously by {@link getRateSync} within the freshness window.\n *\n * @throws If the currency code is unrecognized or the fetch fails/times out.\n */\n async getRate(from: string, to: string, signal?: AbortSignal): Promise<number> {\n const fromUpper = from.toUpperCase();\n const toUpper = to.toUpperCase();\n\n if (this.isCryptoCode(fromUpper) || this.isCryptoCode(toUpper)) {\n return this.getCryptoRate(fromUpper, toUpper, signal);\n }\n\n // Combine the caller's optional abort signal with a hard timeout so a\n // hanging currency API never blocks re-evaluation indefinitely.\n const { signal: fetchSignal, cleanup } = createTimeoutSignal(\n signal,\n CurrencyExchangeService.FETCH_TIMEOUT_MS,\n \"Currency API fetch\",\n );\n\n try {\n const response = await fetch(`https://api.frankfurter.dev/v2/rates?base=${fromUpper}`, { signal: fetchSignal });\n if (!response.ok) throw ErrorFactory.external(CurrencyErrorCodes.API_ERROR, `Currency API returned ${response.status}`, { status: response.status });\n const data = await response.json();\n // The v2 endpoint returns a flat array of { date, base, quote, rate }\n // entries (one per target currency) rather than the classic v1 shape\n // { base, date, rates: { CODE: rate } }. Reading data.rates against\n // the real response is always undefined, so every conversion used to\n // throw \"Unknown currency\" no matter which currencies were requested.\n // Accept both shapes so a future API revision back to the object form\n // doesn't silently break this again.\n const rates: Record<string, number> = Array.isArray(data)\n ? Object.fromEntries(\n data\n .filter((entry: unknown): entry is { quote: string; rate: number } => {\n if (typeof entry !== \"object\" || entry === null) return false;\n const candidate = entry as { quote?: unknown; rate?: unknown };\n return typeof candidate.quote === \"string\" && typeof candidate.rate === \"number\";\n })\n .map((entry: { quote: string; rate: number }) => [entry.quote.toUpperCase(), entry.rate])\n )\n : (data.rates ?? {});\n if (rates[toUpper] === undefined) throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${toUpper}`, { code: toUpper });\n\n // The API returns ALL rates for the base currency, cache the whole\n // table so subsequent conversions (including cross pairs via\n // triangulation) resolve synchronously within the freshness window\n // instead of going Pending again.\n this.baseTables.set(fromUpper, {\n fetchedAt: Date.now(),\n rates: { ...rates, [fromUpper]: 1 },\n });\n\n return rates[toUpper];\n } finally {\n cleanup();\n }\n }\n\n /**\n * Crypto rate fetch, routed through CoinGecko's no-auth simple-price\n * endpoint instead of Frankfurter (fiat-only, has no BTC/ETH concept).\n * Handles all three combinations, crypto→crypto, crypto→fiat\n * fiat→crypto, via prices denominated in USD (or the target fiat\n * directly, which CoinGecko's `vs_currencies` also accepts), then\n * caches the result as a same-shaped base table so getRateSync /\n * convertSync keep working unchanged for crypto pairs too.\n */\n private async getCryptoRate(fromUpper: string, toUpper: string, signal?: AbortSignal): Promise<number> {\n const { signal: fetchSignal, cleanup } = createTimeoutSignal(\n signal,\n CurrencyExchangeService.FETCH_TIMEOUT_MS,\n \"Crypto price API fetch\",\n );\n\n try {\n const fromIsCrypto = this.isCryptoCode(fromUpper);\n const toIsCrypto = this.isCryptoCode(toUpper);\n let rate: number;\n\n if (fromIsCrypto && toIsCrypto) {\n const fromId = CurrencyExchangeService.CRYPTO_IDS[fromUpper];\n const toId = CurrencyExchangeService.CRYPTO_IDS[toUpper];\n const data = await this.fetchCoinGeckoPrices([fromId, toId], \"usd\", fetchSignal);\n const fromUsd = data[fromId]?.usd;\n const toUsd = data[toId]?.usd;\n if (typeof fromUsd !== \"number\") throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${fromUpper}`, { code: fromUpper });\n if (typeof toUsd !== \"number\") throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${toUpper}`, { code: toUpper });\n rate = fromUsd / toUsd;\n } else if (fromIsCrypto) {\n const fromId = CurrencyExchangeService.CRYPTO_IDS[fromUpper];\n const vs = toUpper.toLowerCase();\n const data = await this.fetchCoinGeckoPrices([fromId], vs, fetchSignal);\n const value = data[fromId]?.[vs];\n if (typeof value !== \"number\") throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${toUpper}`, { code: toUpper });\n rate = value;\n } else {\n const toId = CurrencyExchangeService.CRYPTO_IDS[toUpper];\n const vs = fromUpper.toLowerCase();\n const data = await this.fetchCoinGeckoPrices([toId], vs, fetchSignal);\n const priceOfToInFrom = data[toId]?.[vs];\n if (typeof priceOfToInFrom !== \"number\") throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${fromUpper}`, { code: fromUpper });\n rate = 1 / priceOfToInFrom;\n }\n\n // Cache as a single-pair base table, same shape Frankfurter fetches\n // produce, so getRateSync/convertSync's triangulation logic doesn't\n // need to know or care which source a rate came from.\n this.baseTables.set(fromUpper, {\n fetchedAt: Date.now(),\n rates: { [fromUpper]: 1, [toUpper]: rate },\n });\n\n return rate;\n } finally {\n cleanup();\n }\n }\n\n private async fetchCoinGeckoPrices(ids: string[], vsCurrency: string, signal: AbortSignal): Promise<Record<string, Record<string, number>>> {\n const url = `https://api.coingecko.com/api/v3/simple/price?ids=${ids.join(\",\")}&vs_currencies=${vsCurrency}`;\n const response = await fetch(url, { signal });\n if (!response.ok) throw ErrorFactory.external(CurrencyErrorCodes.CRYPTO_API_ERROR, `Crypto price API returned ${response.status}`, { status: response.status });\n return response.json();\n }\n\n /**\n * Seed a base rate table without a network fetch.\n *\n * Intended for tests and for future user-provided offline rates\n * production live data always comes from {@link getRate}. Seeded rates\n * obey the same freshness window as fetched ones.\n *\n * @param base - Base currency code (e.g. \"USD\").\n * @param rates - Map of currency code → rate relative to the base.\n */\n primeRates(base: string, rates: Record<string, number>): void {\n const baseUpper = base.toUpperCase();\n this.baseTables.set(baseUpper, {\n fetchedAt: Date.now(),\n rates: { ...rates, [baseUpper]: 1 },\n });\n }\n\n /**\n * Drop every cached/primed rate table.\n *\n * Mainly for test isolation: {@link sharedCurrencyExchange} is a\n * module-level singleton, so a rate primed or fetched by one test can\n * silently leak into a later test in the same file. Also usable in\n * production if a caller ever wants to force a full re-fetch.\n */\n clearRates(): void {\n this.baseTables.clear();\n }\n\n /**\n * Synchronous rate lookup: `1` for same-currency pairs, a cached LIVE\n * rate if one was fetched within {@link RATE_FRESHNESS_MS}, otherwise\n * `null`, callers fall through to the async fetch path and the\n * expression shows Pending until real data arrives.\n *\n * There is deliberately no hardcoded fallback table: a stale made-up\n * rate presented as a real conversion is worse than a Pending state.\n */\n getRateSync(from: string, to: string): number | null {\n const fromUpper = from.toUpperCase();\n const toUpper = to.toUpperCase();\n if (fromUpper === toUpper) {\n return 1;\n }\n const now = Date.now();\n for (const table of this.baseTables.values()) {\n if (now - table.fetchedAt > CurrencyExchangeService.RATE_FRESHNESS_MS) continue;\n const fromRate = table.rates[fromUpper];\n const toRate = table.rates[toUpper];\n if (fromRate && toRate) {\n return toRate / fromRate;\n }\n }\n return null;\n }\n\n /** Convert `value` from `from` to `to` using a freshly-fetched live rate (see {@link getRate}). */\n async convert(value: number, from: string, to: string): Promise<number> {\n const rate = await this.getRate(from, to);\n return value * rate;\n }\n\n /**\n * Get all currently cached fresh rates, keyed \"FROM:TO\".\n * @returns Snapshot of fresh live rates, or null when none are cached.\n */\n getAllRates(): Record<string, number> | null {\n const now = Date.now();\n const snapshot: Record<string, number> = {};\n let any = false;\n for (const [base, table] of this.baseTables) {\n if (now - table.fetchedAt > CurrencyExchangeService.RATE_FRESHNESS_MS) continue;\n for (const [code, rate] of Object.entries(table.rates)) {\n snapshot[`${base}:${code}`] = rate;\n any = true;\n }\n }\n return any ? snapshot : null;\n }\n\n /**\n * Check whether any fresh live rates are currently cached.\n */\n hasRates(): boolean {\n return this.getAllRates() !== null;\n }\n\n /**\n * Synchronous conversion using cached rates only\n * Returns null if rate not in cache\n */\n convertSync(value: number, from: string, to: string): number | null {\n const rate = this.getRateSync(from, to);\n if (rate === null) return null;\n return value * rate;\n }\n\n // ------------------------------------------------------------------------\n // CURRENCY VALIDATION\n // ------------------------------------------------------------------------\n\n /**\n * Check whether `code` is a recognized currency code: any active ISO 4217\n * code, or one of the cryptocurrencies in {@link CRYPTO_IDS}.\n *\n * This used to be a hand-written list of forty-six codes, which meant\n * `$100 in UAH` returned an unconverted hundred dollars rather than saying\n * it could not convert. Answering from the standard rather than from\n * whichever codes happened to get added is what stops that class of bug.\n *\n * Recognising a code is not the same as having a rate for it. That is\n * answered later, by the exchange provider; conflating the two is what\n * produced the silent failure.\n */\n isCurrency(code: string): boolean {\n return isIso4217(code) || this.isCryptoCode(code);\n }\n}\n\n// ============================================================================\n// SINGLETON INSTANCE\n// ============================================================================\n\n/** The shared rate cache. See {@link CurrencyExchangeService} for why it is shared. */\nexport const currencyExchangeService = new CurrencyExchangeService();\n\n// Export for backward compatibility\n/** Alias for {@link currencyExchangeService}, kept for older imports. */\nexport const sharedCurrencyExchange = currencyExchangeService;\n\n// Default export\nexport default currencyExchangeService;\n"]}