solve-engine 1.2.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -17
- package/dist/{BytecodeBuilder-Bp9xeTmX.d.cts → BytecodeBuilder-DGGeByAP.d.cts} +18 -0
- package/dist/{BytecodeBuilder-Bp9xeTmX.d.ts → BytecodeBuilder-DGGeByAP.d.ts} +18 -0
- package/dist/{Configuration-C9W8tJv_.d.cts → Configuration-B6W0-T67.d.cts} +17 -4
- package/dist/{Configuration-C9W8tJv_.d.ts → Configuration-B6W0-T67.d.ts} +17 -4
- package/dist/{EngineError-CNA_rHY-.d.cts → EngineError-Ce1lPkjZ.d.cts} +2 -0
- package/dist/{EngineError-CNA_rHY-.d.ts → EngineError-Ce1lPkjZ.d.ts} +2 -0
- package/dist/{PackageCompatibility-B6NX9IaN.d.cts → PackageCompatibility-Bn5jnBtA.d.cts} +2 -2
- package/dist/{PackageCompatibility-Ceg5XdAp.d.ts → PackageCompatibility-CIvq2MP5.d.ts} +2 -2
- package/dist/{PackageRegistry-DrCPQNyy.d.ts → PackageRegistry-DzeiWcv4.d.ts} +93 -172
- package/dist/{PackageRegistry-DnJYVw9G.d.cts → PackageRegistry-dpdurBVO.d.cts} +93 -172
- package/dist/{Parselet-Bhf7d0_W.d.ts → Parselet-B-zoPrTa.d.ts} +8 -5
- package/dist/{Parselet-Cv7S7KRt.d.cts → Parselet-C4Wu055_.d.cts} +8 -5
- package/dist/{ScopeManager-Bzq87GfA.d.ts → ScopeManager-C2LDOrDx.d.ts} +7 -16
- package/dist/{ScopeManager-DRDBVfan.d.cts → ScopeManager-D7uMXbhS.d.cts} +7 -16
- package/dist/{VMCheckpoints-C6c17Hbo.d.ts → VMCheckpoints-CGyFhivM.d.ts} +3 -3
- package/dist/{VMCheckpoints-dZxSMGHG.d.cts → VMCheckpoints-I9jg3jWR.d.cts} +3 -3
- package/dist/{Value-DZNQ_PU7.d.cts → Value-CCi_Eecs.d.cts} +40 -0
- package/dist/{Value-DZNQ_PU7.d.ts → Value-CCi_Eecs.d.ts} +40 -0
- package/dist/{WorkerError-Djd7GGGa.d.cts → WorkerError-B4p6PNfx.d.cts} +1 -1
- package/dist/{WorkerError-B7t7R2-m.d.ts → WorkerError-Dhj9BQ_A.d.ts} +1 -1
- package/dist/chunk-2JMFUQZH.js +2 -0
- package/dist/chunk-2JMFUQZH.js.map +1 -0
- package/dist/chunk-2LFLR3VZ.cjs +2 -0
- package/dist/chunk-2LFLR3VZ.cjs.map +1 -0
- package/dist/chunk-2RWAXT6O.js +0 -1
- package/dist/chunk-32GC2FHC.cjs +2 -0
- package/dist/chunk-32GC2FHC.cjs.map +1 -0
- package/dist/chunk-4BZIYU7S.cjs +3 -0
- package/dist/chunk-4BZIYU7S.cjs.map +1 -0
- package/dist/chunk-4E4YVQKK.js +5 -0
- package/dist/chunk-4E4YVQKK.js.map +1 -0
- package/dist/chunk-4QVBSG6B.cjs +2 -0
- package/dist/chunk-4QVBSG6B.cjs.map +1 -0
- package/dist/chunk-5FO4PDIG.js +2 -0
- package/dist/chunk-5FO4PDIG.js.map +1 -0
- package/dist/chunk-5IJD5L3O.cjs +2 -0
- package/dist/chunk-5IJD5L3O.cjs.map +1 -0
- package/dist/chunk-62LMTO4F.js +2 -0
- package/dist/chunk-62LMTO4F.js.map +1 -0
- package/dist/chunk-6G3PMEPA.js +2 -0
- package/dist/chunk-6G3PMEPA.js.map +1 -0
- package/dist/chunk-6INX773F.cjs +2 -0
- package/dist/chunk-6INX773F.cjs.map +1 -0
- package/dist/chunk-76F3LCIL.js +4 -0
- package/dist/chunk-76F3LCIL.js.map +1 -0
- package/dist/chunk-7BXPCWKM.cjs +2 -0
- package/dist/chunk-7BXPCWKM.cjs.map +1 -0
- package/dist/chunk-7GK3XEZF.js +2 -0
- package/dist/chunk-7GK3XEZF.js.map +1 -0
- package/dist/chunk-AXMQG5TS.cjs +2 -0
- package/dist/chunk-AXMQG5TS.cjs.map +1 -0
- package/dist/chunk-CIQOK7Q4.cjs +2 -0
- package/dist/chunk-CIQOK7Q4.cjs.map +1 -0
- package/dist/chunk-E2Q3PQ2G.js +3 -0
- package/dist/chunk-E2Q3PQ2G.js.map +1 -0
- package/dist/chunk-E6Z4NQAS.js +2 -0
- package/dist/chunk-E6Z4NQAS.js.map +1 -0
- package/dist/chunk-EFJCC6FJ.cjs +2 -0
- package/dist/chunk-EFJCC6FJ.cjs.map +1 -0
- package/dist/chunk-ESUN2THE.cjs +2 -0
- package/dist/chunk-ESUN2THE.cjs.map +1 -0
- package/dist/chunk-EVAOPEO4.js +2 -0
- package/dist/chunk-EVAOPEO4.js.map +1 -0
- package/dist/chunk-EVI6OHQH.cjs +2 -0
- package/dist/chunk-EVI6OHQH.cjs.map +1 -0
- package/dist/chunk-FDE5HWDI.cjs +2 -0
- package/dist/chunk-FDE5HWDI.cjs.map +1 -0
- package/dist/chunk-FWW3M36J.cjs +2 -0
- package/dist/chunk-FWW3M36J.cjs.map +1 -0
- package/dist/chunk-G7TBEQRQ.js +2 -0
- package/dist/chunk-G7TBEQRQ.js.map +1 -0
- package/dist/chunk-GK2OHWRF.cjs +5 -0
- package/dist/chunk-GK2OHWRF.cjs.map +1 -0
- package/dist/chunk-HFKDWQUL.js +2 -0
- package/dist/chunk-HFKDWQUL.js.map +1 -0
- package/dist/chunk-HLBYHXQD.cjs +3 -0
- package/dist/chunk-HLBYHXQD.cjs.map +1 -0
- package/dist/chunk-I52MYCVI.js +3 -0
- package/dist/chunk-I52MYCVI.js.map +1 -0
- package/dist/chunk-IANAMBJQ.cjs +2 -0
- package/dist/chunk-IANAMBJQ.cjs.map +1 -0
- package/dist/chunk-IJMNVBIS.js +2 -0
- package/dist/chunk-IJMNVBIS.js.map +1 -0
- package/dist/chunk-J4LZD4ZY.js +3 -0
- package/dist/chunk-J4LZD4ZY.js.map +1 -0
- package/dist/chunk-JAK3RAFA.cjs +2 -0
- package/dist/chunk-JAK3RAFA.cjs.map +1 -0
- package/dist/chunk-JFAJN3C2.cjs +2 -0
- package/dist/chunk-JFAJN3C2.cjs.map +1 -0
- package/dist/chunk-JPFCXLJV.js +2 -0
- package/dist/chunk-JPFCXLJV.js.map +1 -0
- package/dist/chunk-JUIJ6NRD.cjs +3 -0
- package/dist/chunk-JUIJ6NRD.cjs.map +1 -0
- package/dist/chunk-MIQBJGGR.js +2 -0
- package/dist/chunk-MIQBJGGR.js.map +1 -0
- package/dist/chunk-MPB7KUN5.js +3 -0
- package/dist/chunk-MPB7KUN5.js.map +1 -0
- package/dist/chunk-MSYX32PF.cjs +2 -0
- package/dist/chunk-MSYX32PF.cjs.map +1 -0
- package/dist/chunk-MVZUTETT.js +2 -0
- package/dist/chunk-MVZUTETT.js.map +1 -0
- package/dist/chunk-N7N7MPMK.cjs +2 -0
- package/dist/chunk-N7N7MPMK.cjs.map +1 -0
- package/dist/chunk-NGBBNL4K.cjs +1 -3
- package/dist/chunk-OVKDDTXO.cjs +3 -0
- package/dist/chunk-OVKDDTXO.cjs.map +1 -0
- package/dist/chunk-P6WPEUAJ.cjs +2 -0
- package/dist/chunk-P6WPEUAJ.cjs.map +1 -0
- package/dist/chunk-PS272DZJ.cjs +2 -0
- package/dist/chunk-PS272DZJ.cjs.map +1 -0
- package/dist/chunk-R2ENWQ76.js +2 -0
- package/dist/chunk-R2ENWQ76.js.map +1 -0
- package/dist/chunk-R2SZFJTT.cjs +2 -0
- package/dist/chunk-R2SZFJTT.cjs.map +1 -0
- package/dist/chunk-RAF57WYO.js +2 -0
- package/dist/chunk-RAF57WYO.js.map +1 -0
- package/dist/chunk-RSF25YSJ.js +2 -0
- package/dist/chunk-RSF25YSJ.js.map +1 -0
- package/dist/chunk-SOMGSIO4.cjs +3 -0
- package/dist/chunk-SOMGSIO4.cjs.map +1 -0
- package/dist/chunk-SYYE3QAX.cjs +2 -0
- package/dist/chunk-SYYE3QAX.cjs.map +1 -0
- package/dist/chunk-TCZSPH4A.js +2 -0
- package/dist/chunk-TCZSPH4A.js.map +1 -0
- package/dist/chunk-TLG7VZRX.cjs +2 -0
- package/dist/chunk-TLG7VZRX.cjs.map +1 -0
- package/dist/chunk-TN5E6JU6.js +2 -0
- package/dist/chunk-TN5E6JU6.js.map +1 -0
- package/dist/chunk-TRBXW6HW.js +2 -0
- package/dist/{chunk-AQNHHJMJ.cjs.map → chunk-TRBXW6HW.js.map} +1 -1
- package/dist/chunk-TTFO4YDP.cjs +2 -0
- package/dist/chunk-TTFO4YDP.cjs.map +1 -0
- package/dist/chunk-TWC7K3ZX.js +2 -0
- package/dist/chunk-TWC7K3ZX.js.map +1 -0
- package/dist/chunk-U4AEVL5Z.js +2 -0
- package/dist/chunk-U4AEVL5Z.js.map +1 -0
- package/dist/chunk-UURM7P3P.cjs +4 -0
- package/dist/chunk-UURM7P3P.cjs.map +1 -0
- package/dist/chunk-VAGS5JS7.cjs +2 -0
- package/dist/chunk-VAGS5JS7.cjs.map +1 -0
- package/dist/chunk-W2JAR233.js +2 -0
- package/dist/chunk-W2JAR233.js.map +1 -0
- package/dist/chunk-WGZ3FNHI.js +2 -0
- package/dist/chunk-WGZ3FNHI.js.map +1 -0
- package/dist/chunk-XEIDV5JP.js +2 -0
- package/dist/chunk-XEIDV5JP.js.map +1 -0
- package/dist/chunk-XNIWQHXY.js +2 -0
- package/dist/chunk-XNIWQHXY.js.map +1 -0
- package/dist/chunk-Y7O4D3BJ.cjs +2 -0
- package/dist/chunk-Y7O4D3BJ.cjs.map +1 -0
- package/dist/chunk-YAHGSBMC.js +2 -0
- package/dist/chunk-YAHGSBMC.js.map +1 -0
- package/dist/chunk-YAYBVVG2.js +3 -0
- package/dist/chunk-YAYBVVG2.js.map +1 -0
- package/dist/chunk-YJ2OPULK.js +2 -0
- package/dist/chunk-YJ2OPULK.js.map +1 -0
- package/dist/chunk-YVKHEAFT.js +2 -0
- package/dist/chunk-YVKHEAFT.js.map +1 -0
- package/dist/chunk-ZCNBT44X.cjs +2 -0
- package/dist/chunk-ZCNBT44X.cjs.map +1 -0
- package/dist/chunk-ZLRJ7TDP.cjs +2 -0
- package/dist/chunk-ZLRJ7TDP.cjs.map +1 -0
- package/dist/constants.cjs +1 -21
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -4
- package/dist/engine.cjs +1 -94
- package/dist/engine.d.cts +10 -11
- package/dist/engine.d.ts +10 -11
- package/dist/engine.js +1 -37
- package/dist/errors.cjs +1 -105
- package/dist/errors.d.cts +3 -3
- package/dist/errors.d.ts +3 -3
- package/dist/errors.js +1 -4
- package/dist/format.cjs +1 -26
- package/dist/format.d.cts +2 -2
- package/dist/format.d.ts +2 -2
- package/dist/format.js +1 -9
- package/dist/index.cjs +1 -314
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -20
- package/dist/index.d.ts +52 -20
- package/dist/index.js +1 -278
- package/dist/index.js.map +1 -1
- package/dist/language.cjs +1 -369
- package/dist/language.cjs.map +1 -1
- package/dist/language.d.cts +9 -10
- package/dist/language.d.ts +9 -10
- package/dist/language.js +1 -348
- package/dist/language.js.map +1 -1
- package/dist/lexer.cjs +1 -63
- package/dist/lexer.js +1 -10
- package/dist/normalizer.cjs +1 -39
- package/dist/normalizer.js +1 -10
- package/dist/packages.cjs +1 -132
- package/dist/packages.d.cts +8 -9
- package/dist/packages.d.ts +8 -9
- package/dist/packages.js +1 -23
- package/dist/parser.cjs +1 -54
- package/dist/parser.d.cts +8 -8
- package/dist/parser.d.ts +8 -8
- package/dist/parser.js +1 -9
- package/dist/{pipeline-D-PS9gVw.d.ts → pipeline-72QmQlGx.d.ts} +1 -1
- package/dist/{pipeline-DtSBJ8TS.d.cts → pipeline-DCQicwWX.d.cts} +1 -1
- package/dist/resolvers.cjs +1 -12
- package/dist/resolvers.d.cts +2 -2
- package/dist/resolvers.d.ts +2 -2
- package/dist/resolvers.js +1 -3
- package/dist/services.cjs +1 -20
- package/dist/services.js +1 -3
- package/dist/testing.cjs +3 -477
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +9 -10
- package/dist/testing.d.ts +9 -10
- package/dist/testing.js +3 -469
- package/dist/testing.js.map +1 -1
- package/dist/uom.cjs +1 -55
- package/dist/uom.d.cts +2 -2
- package/dist/uom.d.ts +2 -2
- package/dist/uom.js +1 -10
- package/dist/utilities.cjs +1 -36
- package/dist/utilities.js +1 -7
- package/dist/vm.cjs +1 -295
- package/dist/vm.cjs.map +1 -1
- package/dist/vm.d.cts +22 -10
- package/dist/vm.d.ts +22 -10
- package/dist/vm.js +1 -193
- package/dist/vm.js.map +1 -1
- package/dist/worker.cjs +2 -492
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +16 -17
- package/dist/worker.d.ts +16 -17
- package/dist/worker.js +2 -483
- package/dist/worker.js.map +1 -1
- package/package.json +1 -13
- package/dist/chunk-3BOK2LDK.js +0 -17
- package/dist/chunk-3BOK2LDK.js.map +0 -1
- package/dist/chunk-3VGDNEE3.js +0 -84
- package/dist/chunk-3VGDNEE3.js.map +0 -1
- package/dist/chunk-4K5W7EH2.cjs +0 -112
- package/dist/chunk-4K5W7EH2.cjs.map +0 -1
- package/dist/chunk-5EFKSKMA.js +0 -413
- package/dist/chunk-5EFKSKMA.js.map +0 -1
- package/dist/chunk-5HRB36DK.js +0 -405
- package/dist/chunk-5HRB36DK.js.map +0 -1
- package/dist/chunk-5ON7PUAZ.js +0 -12
- package/dist/chunk-5ON7PUAZ.js.map +0 -1
- package/dist/chunk-7AXJNQMF.cjs +0 -297
- package/dist/chunk-7AXJNQMF.cjs.map +0 -1
- package/dist/chunk-7JM3F4KL.js +0 -1795
- package/dist/chunk-7JM3F4KL.js.map +0 -1
- package/dist/chunk-7USV76HV.cjs +0 -341
- package/dist/chunk-7USV76HV.cjs.map +0 -1
- package/dist/chunk-A2DZ5BEJ.cjs +0 -1930
- package/dist/chunk-A2DZ5BEJ.cjs.map +0 -1
- package/dist/chunk-ADBA3XBE.cjs +0 -20
- package/dist/chunk-ADBA3XBE.cjs.map +0 -1
- package/dist/chunk-AKNGX4TZ.cjs +0 -236
- package/dist/chunk-AKNGX4TZ.cjs.map +0 -1
- package/dist/chunk-ALYRJ72W.cjs +0 -434
- package/dist/chunk-ALYRJ72W.cjs.map +0 -1
- package/dist/chunk-AMOJYLG2.cjs +0 -1692
- package/dist/chunk-AMOJYLG2.cjs.map +0 -1
- package/dist/chunk-AOH6UR2L.js +0 -825
- package/dist/chunk-AOH6UR2L.js.map +0 -1
- package/dist/chunk-AQNHHJMJ.cjs +0 -261
- package/dist/chunk-B7LXJ6LC.cjs +0 -36
- package/dist/chunk-B7LXJ6LC.cjs.map +0 -1
- package/dist/chunk-BESTLPRK.cjs +0 -6919
- package/dist/chunk-BESTLPRK.cjs.map +0 -1
- package/dist/chunk-BLI4NIQY.js +0 -98
- package/dist/chunk-BLI4NIQY.js.map +0 -1
- package/dist/chunk-BSPXMGIS.js +0 -455
- package/dist/chunk-BSPXMGIS.js.map +0 -1
- package/dist/chunk-C2OMO3WN.cjs +0 -2806
- package/dist/chunk-C2OMO3WN.cjs.map +0 -1
- package/dist/chunk-CSDQMDU2.js +0 -204
- package/dist/chunk-CSDQMDU2.js.map +0 -1
- package/dist/chunk-EJ3ILXX6.cjs +0 -223
- package/dist/chunk-EJ3ILXX6.cjs.map +0 -1
- package/dist/chunk-ENRIK36Q.cjs +0 -94
- package/dist/chunk-ENRIK36Q.cjs.map +0 -1
- package/dist/chunk-F4UB4XIL.js +0 -109
- package/dist/chunk-F4UB4XIL.js.map +0 -1
- package/dist/chunk-FD5ZZHEU.js +0 -92
- package/dist/chunk-FD5ZZHEU.js.map +0 -1
- package/dist/chunk-FE4RC37D.js +0 -2801
- package/dist/chunk-FE4RC37D.js.map +0 -1
- package/dist/chunk-FEAIOR7N.cjs +0 -91
- package/dist/chunk-FEAIOR7N.cjs.map +0 -1
- package/dist/chunk-FR7RNOPT.cjs +0 -3303
- package/dist/chunk-FR7RNOPT.cjs.map +0 -1
- package/dist/chunk-G2YPPLGX.cjs +0 -484
- package/dist/chunk-G2YPPLGX.cjs.map +0 -1
- package/dist/chunk-GCM5JHMX.js +0 -88
- package/dist/chunk-GCM5JHMX.js.map +0 -1
- package/dist/chunk-GDEU72RG.cjs +0 -829
- package/dist/chunk-GDEU72RG.cjs.map +0 -1
- package/dist/chunk-HKTQCQ4Z.cjs +0 -8383
- package/dist/chunk-HKTQCQ4Z.cjs.map +0 -1
- package/dist/chunk-HWHU642X.cjs +0 -316
- package/dist/chunk-HWHU642X.cjs.map +0 -1
- package/dist/chunk-ICEKS6YC.cjs +0 -507
- package/dist/chunk-ICEKS6YC.cjs.map +0 -1
- package/dist/chunk-IJGOFP2J.js +0 -6904
- package/dist/chunk-IJGOFP2J.js.map +0 -1
- package/dist/chunk-IQJGDZOP.js +0 -333
- package/dist/chunk-IQJGDZOP.js.map +0 -1
- package/dist/chunk-IT74O4BE.cjs +0 -456
- package/dist/chunk-IT74O4BE.cjs.map +0 -1
- package/dist/chunk-KXDQKVNX.cjs +0 -459
- package/dist/chunk-KXDQKVNX.cjs.map +0 -1
- package/dist/chunk-L2TE7PMO.cjs +0 -14
- package/dist/chunk-L2TE7PMO.cjs.map +0 -1
- package/dist/chunk-L5YHV6BQ.js +0 -499
- package/dist/chunk-L5YHV6BQ.js.map +0 -1
- package/dist/chunk-LO7HU5WB.cjs +0 -209
- package/dist/chunk-LO7HU5WB.cjs.map +0 -1
- package/dist/chunk-LSALB3IN.js +0 -292
- package/dist/chunk-LSALB3IN.js.map +0 -1
- package/dist/chunk-MI7OTUHL.cjs +0 -339
- package/dist/chunk-MI7OTUHL.cjs.map +0 -1
- package/dist/chunk-MIGXCBXT.cjs +0 -381
- package/dist/chunk-MIGXCBXT.cjs.map +0 -1
- package/dist/chunk-MVTOCRV2.js +0 -213
- package/dist/chunk-MVTOCRV2.js.map +0 -1
- package/dist/chunk-N7FNVFXW.cjs +0 -32
- package/dist/chunk-N7FNVFXW.cjs.map +0 -1
- package/dist/chunk-N7OA4WPJ.js +0 -362
- package/dist/chunk-N7OA4WPJ.js.map +0 -1
- package/dist/chunk-NAWZATKT.js +0 -478
- package/dist/chunk-NAWZATKT.js.map +0 -1
- package/dist/chunk-NLNDMWZC.js +0 -31
- package/dist/chunk-NLNDMWZC.js.map +0 -1
- package/dist/chunk-ORM7CHYZ.js +0 -1531
- package/dist/chunk-ORM7CHYZ.js.map +0 -1
- package/dist/chunk-OUHT5Z36.cjs +0 -393
- package/dist/chunk-OUHT5Z36.cjs.map +0 -1
- package/dist/chunk-PCZVMMWU.cjs +0 -74
- package/dist/chunk-PCZVMMWU.cjs.map +0 -1
- package/dist/chunk-RNKDIXDV.js +0 -336
- package/dist/chunk-RNKDIXDV.js.map +0 -1
- package/dist/chunk-SBUFNJVE.js +0 -258
- package/dist/chunk-SBUFNJVE.js.map +0 -1
- package/dist/chunk-TC6BTUSU.cjs +0 -1799
- package/dist/chunk-TC6BTUSU.cjs.map +0 -1
- package/dist/chunk-TPOK3UNI.js +0 -8355
- package/dist/chunk-TPOK3UNI.js.map +0 -1
- package/dist/chunk-UF6JG5SG.js +0 -312
- package/dist/chunk-UF6JG5SG.js.map +0 -1
- package/dist/chunk-UKQHXPGW.js +0 -30
- package/dist/chunk-UKQHXPGW.js.map +0 -1
- package/dist/chunk-V4XG5QF6.js +0 -1685
- package/dist/chunk-V4XG5QF6.js.map +0 -1
- package/dist/chunk-VEKIWQ3F.cjs +0 -39
- package/dist/chunk-VEKIWQ3F.cjs.map +0 -1
- package/dist/chunk-WMQRJTAO.js +0 -3266
- package/dist/chunk-WMQRJTAO.js.map +0 -1
- package/dist/chunk-X6K3HUOY.cjs +0 -86
- package/dist/chunk-X6K3HUOY.cjs.map +0 -1
- package/dist/chunk-XBTEO4OB.js +0 -391
- package/dist/chunk-XBTEO4OB.js.map +0 -1
- package/dist/chunk-XIYYHA65.cjs +0 -101
- package/dist/chunk-XIYYHA65.cjs.map +0 -1
- package/dist/chunk-YJHY7CMN.cjs +0 -1534
- package/dist/chunk-YJHY7CMN.cjs.map +0 -1
- package/dist/chunk-YLJ4XMA6.js +0 -33
- package/dist/chunk-YLJ4XMA6.js.map +0 -1
- package/dist/chunk-YNIWOYW6.js +0 -232
- package/dist/chunk-YNIWOYW6.js.map +0 -1
- package/dist/chunk-Z2XP767T.cjs +0 -35
- package/dist/chunk-Z2XP767T.cjs.map +0 -1
- package/dist/chunk-Z4X2RWOF.js +0 -37
- package/dist/chunk-Z4X2RWOF.js.map +0 -1
- package/dist/chunk-ZN6YYPIW.js +0 -67
- package/dist/chunk-ZN6YYPIW.js.map +0 -1
- package/dist/chunk-ZNFFTYWH.js +0 -1854
- package/dist/chunk-ZNFFTYWH.js.map +0 -1
- package/dist/variables.cjs +0 -17
- package/dist/variables.cjs.map +0 -1
- package/dist/variables.d.cts +0 -87
- package/dist/variables.d.ts +0 -87
- package/dist/variables.js +0 -4
- package/dist/variables.js.map +0 -1
package/dist/chunk-BLI4NIQY.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// src/parser/OpCode.ts
|
|
2
|
-
var OpCode = /* @__PURE__ */ ((OpCode2) => {
|
|
3
|
-
OpCode2[OpCode2["NOP"] = 0] = "NOP";
|
|
4
|
-
OpCode2[OpCode2["HALT"] = 1] = "HALT";
|
|
5
|
-
OpCode2[OpCode2["SWAP"] = 2] = "SWAP";
|
|
6
|
-
OpCode2[OpCode2["DUP"] = 3] = "DUP";
|
|
7
|
-
OpCode2[OpCode2["PUSH_NUMBER"] = 10] = "PUSH_NUMBER";
|
|
8
|
-
OpCode2[OpCode2["PUSH_BIGINT"] = 11] = "PUSH_BIGINT";
|
|
9
|
-
OpCode2[OpCode2["PUSH_HEX"] = 12] = "PUSH_HEX";
|
|
10
|
-
OpCode2[OpCode2["PUSH_STRING"] = 13] = "PUSH_STRING";
|
|
11
|
-
OpCode2[OpCode2["PUSH_BOOLEAN"] = 14] = "PUSH_BOOLEAN";
|
|
12
|
-
OpCode2[OpCode2["PUSH_VARIABLE"] = 15] = "PUSH_VARIABLE";
|
|
13
|
-
OpCode2[OpCode2["PUSH_DECIMAL"] = 16] = "PUSH_DECIMAL";
|
|
14
|
-
OpCode2[OpCode2["ADD"] = 20] = "ADD";
|
|
15
|
-
OpCode2[OpCode2["SUB"] = 21] = "SUB";
|
|
16
|
-
OpCode2[OpCode2["MUL"] = 22] = "MUL";
|
|
17
|
-
OpCode2[OpCode2["DIV"] = 23] = "DIV";
|
|
18
|
-
OpCode2[OpCode2["MOD"] = 24] = "MOD";
|
|
19
|
-
OpCode2[OpCode2["EXP"] = 25] = "EXP";
|
|
20
|
-
OpCode2[OpCode2["NEG"] = 26] = "NEG";
|
|
21
|
-
OpCode2[OpCode2["POS"] = 27] = "POS";
|
|
22
|
-
OpCode2[OpCode2["MAKE_UNCERTAIN"] = 28] = "MAKE_UNCERTAIN";
|
|
23
|
-
OpCode2[OpCode2["LSHIFT"] = 30] = "LSHIFT";
|
|
24
|
-
OpCode2[OpCode2["RSHIFT"] = 31] = "RSHIFT";
|
|
25
|
-
OpCode2[OpCode2["URSHIFT"] = 32] = "URSHIFT";
|
|
26
|
-
OpCode2[OpCode2["BIT_AND"] = 33] = "BIT_AND";
|
|
27
|
-
OpCode2[OpCode2["BIT_OR"] = 34] = "BIT_OR";
|
|
28
|
-
OpCode2[OpCode2["BIT_XOR"] = 35] = "BIT_XOR";
|
|
29
|
-
OpCode2[OpCode2["BIT_NOT"] = 36] = "BIT_NOT";
|
|
30
|
-
OpCode2[OpCode2["EQ"] = 40] = "EQ";
|
|
31
|
-
OpCode2[OpCode2["NEQ"] = 41] = "NEQ";
|
|
32
|
-
OpCode2[OpCode2["LT"] = 42] = "LT";
|
|
33
|
-
OpCode2[OpCode2["LTE"] = 43] = "LTE";
|
|
34
|
-
OpCode2[OpCode2["GT"] = 44] = "GT";
|
|
35
|
-
OpCode2[OpCode2["GTE"] = 45] = "GTE";
|
|
36
|
-
OpCode2[OpCode2["CALL_PLUGIN"] = 50] = "CALL_PLUGIN";
|
|
37
|
-
OpCode2[OpCode2["CALL_BUILTIN"] = 51] = "CALL_BUILTIN";
|
|
38
|
-
OpCode2[OpCode2["RETURN"] = 52] = "RETURN";
|
|
39
|
-
OpCode2[OpCode2["LOAD_VAR"] = 60] = "LOAD_VAR";
|
|
40
|
-
OpCode2[OpCode2["STORE_VAR"] = 61] = "STORE_VAR";
|
|
41
|
-
OpCode2[OpCode2["LOAD_GLOBAL_VAR"] = 62] = "LOAD_GLOBAL_VAR";
|
|
42
|
-
OpCode2[OpCode2["STORE_GLOBAL_VAR"] = 63] = "STORE_GLOBAL_VAR";
|
|
43
|
-
OpCode2[OpCode2["TO_NUMBER"] = 70] = "TO_NUMBER";
|
|
44
|
-
OpCode2[OpCode2["TO_HEX"] = 71] = "TO_HEX";
|
|
45
|
-
OpCode2[OpCode2["TO_PERCENTAGE"] = 74] = "TO_PERCENTAGE";
|
|
46
|
-
OpCode2[OpCode2["UOM_CONVERT"] = 80] = "UOM_CONVERT";
|
|
47
|
-
OpCode2[OpCode2["UOM_CONVERT_TO"] = 81] = "UOM_CONVERT_TO";
|
|
48
|
-
OpCode2[OpCode2["UOM_GET_VALUE"] = 82] = "UOM_GET_VALUE";
|
|
49
|
-
OpCode2[OpCode2["UOM_BEST"] = 83] = "UOM_BEST";
|
|
50
|
-
OpCode2[OpCode2["UOM_CONVERT_IN"] = 84] = "UOM_CONVERT_IN";
|
|
51
|
-
OpCode2[OpCode2["UOM_POSSIBILITIES"] = 85] = "UOM_POSSIBILITIES";
|
|
52
|
-
OpCode2[OpCode2["DATE_NOW"] = 90] = "DATE_NOW";
|
|
53
|
-
OpCode2[OpCode2["DATE_ADD"] = 91] = "DATE_ADD";
|
|
54
|
-
OpCode2[OpCode2["DATE_SUB"] = 92] = "DATE_SUB";
|
|
55
|
-
OpCode2[OpCode2["DATE_NEXT_WEEKDAY"] = 93] = "DATE_NEXT_WEEKDAY";
|
|
56
|
-
OpCode2[OpCode2["DATE_LAST_WEEKDAY"] = 94] = "DATE_LAST_WEEKDAY";
|
|
57
|
-
OpCode2[OpCode2["DATE_LITERAL"] = 95] = "DATE_LITERAL";
|
|
58
|
-
OpCode2[OpCode2["DATE_WORKDAY_OFFSET"] = 96] = "DATE_WORKDAY_OFFSET";
|
|
59
|
-
OpCode2[OpCode2["DATE_WORKDAYS_BETWEEN"] = 97] = "DATE_WORKDAYS_BETWEEN";
|
|
60
|
-
OpCode2[OpCode2["RATE_DIV"] = 110] = "RATE_DIV";
|
|
61
|
-
OpCode2[OpCode2["RATE_MUL"] = 111] = "RATE_MUL";
|
|
62
|
-
OpCode2[OpCode2["RATE_CONVERT"] = 112] = "RATE_CONVERT";
|
|
63
|
-
OpCode2[OpCode2["CLOCK_TIME_TODAY"] = 120] = "CLOCK_TIME_TODAY";
|
|
64
|
-
OpCode2[OpCode2["LOGICAL_AND"] = 130] = "LOGICAL_AND";
|
|
65
|
-
OpCode2[OpCode2["LOGICAL_OR"] = 131] = "LOGICAL_OR";
|
|
66
|
-
OpCode2[OpCode2["SELECT"] = 132] = "SELECT";
|
|
67
|
-
OpCode2[OpCode2["TO_FRACTION"] = 140] = "TO_FRACTION";
|
|
68
|
-
OpCode2[OpCode2["TO_MULTIPLIER"] = 141] = "TO_MULTIPLIER";
|
|
69
|
-
OpCode2[OpCode2["TO_SCI"] = 142] = "TO_SCI";
|
|
70
|
-
OpCode2[OpCode2["TO_BINARY"] = 143] = "TO_BINARY";
|
|
71
|
-
OpCode2[OpCode2["TO_OCTAL"] = 144] = "TO_OCTAL";
|
|
72
|
-
OpCode2[OpCode2["CALL_AS_CONVERTER"] = 145] = "CALL_AS_CONVERTER";
|
|
73
|
-
OpCode2[OpCode2["DEFINE_USER_FUNCTION"] = 150] = "DEFINE_USER_FUNCTION";
|
|
74
|
-
OpCode2[OpCode2["CALL_USER_FUNCTION"] = 151] = "CALL_USER_FUNCTION";
|
|
75
|
-
OpCode2[OpCode2["MAT_NEW"] = 152] = "MAT_NEW";
|
|
76
|
-
OpCode2[OpCode2["MAT_INDEX1"] = 153] = "MAT_INDEX1";
|
|
77
|
-
OpCode2[OpCode2["MAT_INDEX2"] = 154] = "MAT_INDEX2";
|
|
78
|
-
OpCode2[OpCode2["MAT_SLICE"] = 155] = "MAT_SLICE";
|
|
79
|
-
OpCode2[OpCode2["RANGE_NEW"] = 156] = "RANGE_NEW";
|
|
80
|
-
OpCode2[OpCode2["MAP_INVOKE"] = 157] = "MAP_INVOKE";
|
|
81
|
-
OpCode2[OpCode2["REDUCE_INVOKE"] = 158] = "REDUCE_INVOKE";
|
|
82
|
-
OpCode2[OpCode2["BIND_UNKNOWN"] = 159] = "BIND_UNKNOWN";
|
|
83
|
-
return OpCode2;
|
|
84
|
-
})(OpCode || {});
|
|
85
|
-
var OP_CODE_NAMES = (() => {
|
|
86
|
-
const map = /* @__PURE__ */ new Map();
|
|
87
|
-
for (const [key, value] of Object.entries(OpCode)) {
|
|
88
|
-
if (typeof value === "number") map.set(value, key);
|
|
89
|
-
}
|
|
90
|
-
return map;
|
|
91
|
-
})();
|
|
92
|
-
function getOpCodeName(op) {
|
|
93
|
-
return OP_CODE_NAMES.get(op) ?? `UNKNOWN_${op}`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export { OpCode, getOpCodeName };
|
|
97
|
-
//# sourceMappingURL=chunk-BLI4NIQY.js.map
|
|
98
|
-
//# sourceMappingURL=chunk-BLI4NIQY.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parser/OpCode.ts"],"names":["OpCode"],"mappings":";AAcO,IAAK,MAAA,qBAAAA,OAAAA,KAAL;AAEN,EAAAA,OAAAA,CAAAA,OAAAA,CAAA,SAAM,CAAA,CAAA,GAAN,KAAA;AACA,EAAAA,OAAAA,CAAAA,OAAAA,CAAA,UAAO,CAAA,CAAA,GAAP,MAAA;AACA,EAAAA,OAAAA,CAAAA,OAAAA,CAAA,UAAO,CAAA,CAAA,GAAP,MAAA;AACA,EAAAA,OAAAA,CAAAA,OAAAA,CAAA,S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,aAAU,GAAA,CAAA,GAAV,SAAA;AACA,EAAAA,OAAAA,CAAAA,OAAAA,CAAA,gBAAa,GAAA,CAAA,GAAb,YAAA;AACA,EAAAA,OAAAA,CAAAA,OAAAA,CAAA,gBAAa,GAAA,CAAA,GAAb,YAAA;AACA,EAAAA,OAAAA,CAAAA,OAAAA,CAAA,eAAY,GAAA,CAAA,GAAZ,WAAA;AACA,EAAAA,OAAAA,CAAAA,OAAAA,CAAA,eAAY,GAAA,CAAA,GAAZ,WAAA;AACA,EAAAA,OAAAA,CAAAA,OAAAA,CAAA,gBAAa,GAAA,CAAA,GAAb,YAAA;AACA,EAAAA,OAAAA,CAAAA,OAAAA,CAAA,mBAAgB,GAAA,CAAA,GAAhB,eAAA;AAOA,EAAAA,OAAAA,CAAAA,OAAAA,CAAA,kBAAe,GAAA,CAAA,GAAf,cAAA;AArJW,EAAA,OAAAA,OAAAA;AAAA,CAAA,EAAA,MAAA,IAAA,EAAA;AAsKZ,IAAM,iBAA8C,MAAM;AACzD,EAAA,MAAM,GAAA,uBAAU,GAAA,EAAoB;AACpC,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,EAAG;AAClD,IAAA,IAAI,OAAO,KAAA,KAAU,QAAA,EAAU,GAAA,CAAI,GAAA,CAAI,OAAO,GAAG,CAAA;AAAA,EAClD;AACA,EAAA,OAAO,GAAA;AACR,CAAA,GAAG;AAOI,SAAS,cAAc,EAAA,EAAoB;AACjD,EAAA,OAAO,aAAA,CAAc,GAAA,CAAI,EAAE,CAAA,IAAK,WAAW,EAAE,CAAA,CAAA;AAC9C","file":"chunk-BLI4NIQY.js","sourcesContent":["/**\n * The VM's bytecode instruction set.\n *\n * Emitted by parselets (via {@link BytecodeBuilder}) during parsing and\n * consumed by the VM's dispatch loop during execution. Values are grouped\n * into numeric bands by category (0-9 stack ops, 10-19 push-literal, 20-29\n * arithmetic, ...) purely for readability, the VM dispatches on the exact\n * numeric value, not the band.\n *\n * Third-party packages emit `CALL_PLUGIN` (with a plugin-function index\n * from {@link allocatePluginFunctionIndex}) to invoke their own logic\n * see `IEnginePackage.pluginFunctions`. The other opcodes are used\n * internally by the built-in packages' parselets.\n */\nexport enum OpCode {\n\t// Stack operations\n\tNOP = 0,\n\tHALT = 1,\n\tSWAP = 2,\n\tDUP = 3,\n\n\t// Push literals\n\tPUSH_NUMBER = 10,\n\tPUSH_BIGINT = 11,\n\tPUSH_HEX = 12,\n\tPUSH_STRING = 13,\n\tPUSH_BOOLEAN = 14,\n\tPUSH_VARIABLE = 15,\n\t// A decimal-point literal, pushed with the exact base-ten value it was\n\t// written as alongside the nearest double. The operand is a string-pool\n\t// index holding the normalized \".\" decimal text (thousands grouping already\n\t// stripped), read back into a Number-typed Value whose `exact` sidecar makes\n\t// money that combines with it exact. See vm/Value.ts's numberValueExact().\n\tPUSH_DECIMAL = 16,\n\n\t// Arithmetic (BinaryOperator)\n\tADD = 20,\n\tSUB = 21,\n\tMUL = 22,\n\tDIV = 23,\n\tMOD = 24,\n\tEXP = 25,\n\tNEG = 26,\n\tPOS = 27,\n\t// `a ± b` (or the ASCII `a +/- b`): pops the spread then the center off the\n\t// stack and pushes a Number carrying a one-sigma uncertainty (`vm/Value.ts`'s\n\t// numberValueUncertain). Takes no operand byte, like the other arithmetic\n\t// ops. See packages/uncertainty/ for the parselet that emits it and\n\t// vm/VMConversion.ts's uncertainOp for how the four arithmetic ops propagate.\n\tMAKE_UNCERTAIN = 28,\n\n\t// Bitwise\n\tLSHIFT = 30,\n\tRSHIFT = 31,\n\tURSHIFT = 32,\n\tBIT_AND = 33,\n\tBIT_OR = 34,\n\tBIT_XOR = 35,\n\tBIT_NOT = 36,\n\n\t// Comparison\n\tEQ = 40,\n\tNEQ = 41,\n\tLT = 42,\n\tLTE = 43,\n\tGT = 44,\n\tGTE = 45,\n\n\t// Functions\n\tCALL_PLUGIN = 50, // Plugin-registered functions (may be async — pre-resolved by orchestrator)\n\tCALL_BUILTIN = 51, // Sync built-in functions (sqrt, sin, diceRoll, matmul)\n\tRETURN = 52, // Reserved for future user-defined functions\n\n\t// Variables\n\tLOAD_VAR = 60,\n\tSTORE_VAR = 61,\n\tLOAD_GLOBAL_VAR = 62, // Reads from the process-wide GlobalVariableStore, not the VM's local scope\n\tSTORE_GLOBAL_VAR = 63, // Writes to the process-wide GlobalVariableStore, visible to every document\n\n\t// Type conversion\n\tTO_NUMBER = 70,\n\tTO_HEX = 71,\n\tTO_PERCENTAGE = 74,\n\n\t// UoM\n\tUOM_CONVERT = 80,\n\tUOM_CONVERT_TO = 81,\n\tUOM_GET_VALUE = 82,\n\tUOM_BEST = 83,\n\tUOM_CONVERT_IN = 84,\n\tUOM_POSSIBILITIES = 85, // \"sourceUnit to ?\" — list units convertible from sourceUnit\n\n\t// Datetime\n\tDATE_NOW = 90,\n\tDATE_ADD = 91,\n\tDATE_SUB = 92,\n\tDATE_NEXT_WEEKDAY = 93, // \"next <Weekday>\" — the next occurrence strictly after now\n\tDATE_LAST_WEEKDAY = 94, // \"last <Weekday>\" — the previous occurrence strictly before now\n\tDATE_LITERAL = 95, // Push a datetime literal whose epoch-ms was already resolved at parse time (see DateLiteralParselet)\n\tDATE_WORKDAY_OFFSET = 96, // \"N working days after/before/from <date>\" — a business-day walk from the anchor date. One operand byte: 0 forward, 1 backward. Same walk as `<date> + N workdays` (vm/VM.ts's addBusinessDays). See WorkdayOffsetParselet.\n\tDATE_WORKDAYS_BETWEEN = 97, // \"working days between <date> and <date>\" — the count of working days in the inclusive span. See WorkdaysBetweenParselet and vm/BusinessDays.ts's countBusinessDaysBetween.\n\n\t// Rate, \"quantity per unit of something\" ($99/week, 30 fps). See\n\t// vm/Value.ts's rateValue()/isRateUnit()/splitRateUnit() for the\n\t// representation these opcodes operate on.\n\tRATE_DIV = 110, // Uom ÷ Uom (different measures) -> Rate — the construction op\n\tRATE_MUL = 111, // Rate × Uom (same measure as denominator) -> plain Uom (denominator cancels)\n\tRATE_CONVERT = 112, // Rate -> Rate with a rescaled denominator unit (keeps the same real-world rate)\n\n\t// Time, clock-time-of-day, lap times, video timecode (distinct from\n\t// the Datetime band's calendar-date arithmetic).\n\tCLOCK_TIME_TODAY = 120, // minutes-since-midnight -> Datetime anchored to today's calendar date\n\n\t// Conditionals, boolean logic and eager-evaluated ternary selection.\n\t// EQ/NEQ/LT/LTE/GT/GTE (40-45, above) already existed as dead opcodes\n\t// before this band was wired up; see vm/VM.ts for their handlers.\n\tLOGICAL_AND = 130, // Boolean && Boolean -> Boolean\n\tLOGICAL_OR = 131, // Boolean || Boolean -> Boolean\n\tSELECT = 132, // (thenVal, elseVal, condition) -> thenVal if condition else elseVal — EAGER (both\n\t // branches already evaluated by the time this runs; no real branching/short-circuit,\n\t // a deliberate simplification for a side-effect-free expression language, see\n\t // packages/conditionals/parselets/IfThenElseParselet.ts)\n\n\t// Converters, the general \"as <type>\" mechanism. TO_NUMBER/TO_HEX/\n\t// TO_PERCENTAGE (70/71/74, above) cover the simplest cases; these cover\n\t// the ones with no existing opcode. CALL_AS_CONVERTER is the SDK\n\t// extension point. See IEnginePackage.asConverters and\n\t// vm/VMBuiltins.ts's asConverterRegistry.\n\tTO_FRACTION = 140, // Number -> String, simplified fraction (\"0.5\" -> \"1/2\")\n\tTO_MULTIPLIER = 141, // Number -> String, \"1 + n\" growth multiplier (\"0.5\" -> \"1.5x\")\n\tTO_SCI = 142, // Number -> String, scientific notation (\"1500000\" -> \"1.5e+6\")\n\tTO_BINARY = 143, // Number -> String, base-2 display (\"10\" -> \"0b1010\")\n\tTO_OCTAL = 144, // Number -> String, base-8 display (\"10\" -> \"0o12\")\n\tCALL_AS_CONVERTER = 145, // (value, name) -> runtime asConverterRegistry lookup + call\n\n\t// User-defined, parameterized, reusable functions (f(x) = expr, then\n\t// f(5). See parser/PrecedenceParser.ts's IDENT_ID case\n\t// parser/BytecodeBuilder.ts's UserFunctionDef/emitUserFunctionBody, and\n\t// vm/VM.ts's VM.userFunctions/callFrames). Parameter references inside a\n\t// function body are ORDINARY LOAD_VAR opcodes, not a dedicated\n\t// parameter-load opcode, CALL_USER_FUNCTION binds arguments into a\n\t// name-keyed call frame at runtime, and LOAD_VAR checks the innermost\n\t// call frame before the flat variable store (see VM.getVar()).\n\tDEFINE_USER_FUNCTION = 150, // (operand = index into bytecode.userFunctionBodies) -> register name/params/program into vm.userFunctions. Registration happens at VM-EXECUTION time, not parse time, so a diagnostic/lookahead parse that compiles but never executes a definition line has no side effect on the shared registry.\n\tCALL_USER_FUNCTION = 151, // (N arg values already on stack) -> pop N args, bind by NAME into a new call frame, execute the named function's stored body (reentrant executeBytecode), push its result\n\n\t// Matrix (Calca-parity, replaces the old ARR_* vector-only opcodes\n\t// which were never emitted by any registered parselet; see\n\t// vm/MatrixOps.ts for the shared column-major storage helpers this band\n\t// operates on, and vm/Value.ts's MatrixData for the representation).\n\tMAT_NEW = 152, // (rows, cols operands; rows*cols values already on stack, ROW-MAJOR push order) -> pop rows*cols values, transpose to column-major, push a Matrix\n\tMAT_INDEX1 = 153, // (matrix, index already on stack) -> column-major single-index read `a[i]`\n\tMAT_INDEX2 = 154, // (matrix, row, col already on stack) -> `a[row, col]` read\n\tMAT_SLICE = 155, // (matrix, rowRange, colRange already on stack) -> sub-matrix via two Range values\n\tRANGE_NEW = 156, // (min, max already on stack) -> push a Range value `min:max`\n\tMAP_INVOKE = 157, // map(...) — see parser/BytecodeBuilder.ts's `anonymousBodies` side-table\n\tREDUCE_INVOKE = 158, // reduce(...) — same anonymousBodies mechanism as MAP_INVOKE\n\t// An algebra verb's expression argument, evaluated with the verb's own\n\t// named unknown bound to itself (`der(x^2, x)` reads `x` as the unknown\n\t// even where the document also has a value for it). Operand = an index\n\t// into `anonymousBodies`, whose `params[0]` carries the name to bind, the\n\t// same side-table and the same call-frame shadowing MAP_INVOKE uses for a\n\t// transform body's parameters. See vm/VM.ts's handler.\n\tBIND_UNKNOWN = 159,\n\t// 159 and 160 were THEREFORE_SOLVE and STORE_EQUATION_OR_ASSIGNMENT, declared\n\t// but never emitted by any parselet nor handled in the VM switch. Both shapes\n\t// have effects (a stored equation, a direct vm.setVar()) that a cached\n\t// bytecode program cannot represent, so engine/ExpressionEngine.ts intercepts\n\t// them before compilation and always will. 159 has since been reused above;\n\t// 160 is still free.\n}\n\n// Reverse lookup built once at module load, getOpCodeName() is called once\n// per VM instruction whenever a diagnostic collector is attached (VM.ts's\n// trace path), so a per-call linear scan of every enum entry (TS numeric\n// enums are bidirectional at runtime, so Object.entries(OpCode) yields both\n// \"NOP\" -> 0 and \"0\" -> \"NOP\" style entries) would otherwise redo the same\n// scan every single traced instruction. Only the numeric-valued entries are\n// kept, the string-valued reverse entries TS also generates aren't needed\n// here.\nconst OP_CODE_NAMES: ReadonlyMap<number, string> = (() => {\n\tconst map = new Map<number, string>();\n\tfor (const [key, value] of Object.entries(OpCode)) {\n\t\tif (typeof value === \"number\") map.set(value, key);\n\t}\n\treturn map;\n})();\n\n/**\n * Gets the name of an OpCode as a string.\n * @param op The OpCode value\n * @returns The enum name as a string, or \"UNKNOWN_<value>\" if not found\n */\nexport function getOpCodeName(op: number): string {\n\treturn OP_CODE_NAMES.get(op) ?? `UNKNOWN_${op}`;\n}\n"]}
|
package/dist/chunk-BSPXMGIS.js
DELETED
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
import { createTimeoutSignal } from './chunk-Z4X2RWOF.js';
|
|
2
|
-
import { ErrorFactory } from './chunk-N7OA4WPJ.js';
|
|
3
|
-
|
|
4
|
-
// src/uom/Iso4217.ts
|
|
5
|
-
var ISO_4217_CODES = /* @__PURE__ */ new Set([
|
|
6
|
-
"AED",
|
|
7
|
-
"AFN",
|
|
8
|
-
"ALL",
|
|
9
|
-
"AMD",
|
|
10
|
-
"ANG",
|
|
11
|
-
"AOA",
|
|
12
|
-
"ARS",
|
|
13
|
-
"AUD",
|
|
14
|
-
"AWG",
|
|
15
|
-
"AZN",
|
|
16
|
-
"BAM",
|
|
17
|
-
"BBD",
|
|
18
|
-
"BDT",
|
|
19
|
-
"BGN",
|
|
20
|
-
"BHD",
|
|
21
|
-
"BIF",
|
|
22
|
-
"BMD",
|
|
23
|
-
"BND",
|
|
24
|
-
"BOB",
|
|
25
|
-
"BOV",
|
|
26
|
-
"BRL",
|
|
27
|
-
"BSD",
|
|
28
|
-
"BTN",
|
|
29
|
-
"BWP",
|
|
30
|
-
"BYN",
|
|
31
|
-
"BZD",
|
|
32
|
-
"CAD",
|
|
33
|
-
"CDF",
|
|
34
|
-
"CHE",
|
|
35
|
-
"CHF",
|
|
36
|
-
"CHW",
|
|
37
|
-
"CLF",
|
|
38
|
-
"CLP",
|
|
39
|
-
"CNY",
|
|
40
|
-
"COP",
|
|
41
|
-
"COU",
|
|
42
|
-
"CRC",
|
|
43
|
-
"CUP",
|
|
44
|
-
"CVE",
|
|
45
|
-
"CZK",
|
|
46
|
-
"DJF",
|
|
47
|
-
"DKK",
|
|
48
|
-
"DOP",
|
|
49
|
-
"DZD",
|
|
50
|
-
"EGP",
|
|
51
|
-
"ERN",
|
|
52
|
-
"ETB",
|
|
53
|
-
"EUR",
|
|
54
|
-
"FJD",
|
|
55
|
-
"FKP",
|
|
56
|
-
"GBP",
|
|
57
|
-
"GEL",
|
|
58
|
-
"GHS",
|
|
59
|
-
"GIP",
|
|
60
|
-
"GMD",
|
|
61
|
-
"GNF",
|
|
62
|
-
"GTQ",
|
|
63
|
-
"GYD",
|
|
64
|
-
"HKD",
|
|
65
|
-
"HNL",
|
|
66
|
-
"HTG",
|
|
67
|
-
"HUF",
|
|
68
|
-
"IDR",
|
|
69
|
-
"ILS",
|
|
70
|
-
"INR",
|
|
71
|
-
"IQD",
|
|
72
|
-
"IRR",
|
|
73
|
-
"ISK",
|
|
74
|
-
"JMD",
|
|
75
|
-
"JOD",
|
|
76
|
-
"JPY",
|
|
77
|
-
"KES",
|
|
78
|
-
"KGS",
|
|
79
|
-
"KHR",
|
|
80
|
-
"KMF",
|
|
81
|
-
"KPW",
|
|
82
|
-
"KRW",
|
|
83
|
-
"KWD",
|
|
84
|
-
"KYD",
|
|
85
|
-
"KZT",
|
|
86
|
-
"LAK",
|
|
87
|
-
"LBP",
|
|
88
|
-
"LKR",
|
|
89
|
-
"LRD",
|
|
90
|
-
"LSL",
|
|
91
|
-
"LYD",
|
|
92
|
-
"MAD",
|
|
93
|
-
"MDL",
|
|
94
|
-
"MGA",
|
|
95
|
-
"MKD",
|
|
96
|
-
"MMK",
|
|
97
|
-
"MNT",
|
|
98
|
-
"MOP",
|
|
99
|
-
"MRU",
|
|
100
|
-
"MUR",
|
|
101
|
-
"MVR",
|
|
102
|
-
"MWK",
|
|
103
|
-
"MXN",
|
|
104
|
-
"MXV",
|
|
105
|
-
"MYR",
|
|
106
|
-
"MZN",
|
|
107
|
-
"NAD",
|
|
108
|
-
"NGN",
|
|
109
|
-
"NIO",
|
|
110
|
-
"NOK",
|
|
111
|
-
"NPR",
|
|
112
|
-
"NZD",
|
|
113
|
-
"OMR",
|
|
114
|
-
"PAB",
|
|
115
|
-
"PEN",
|
|
116
|
-
"PGK",
|
|
117
|
-
"PHP",
|
|
118
|
-
"PKR",
|
|
119
|
-
"PLN",
|
|
120
|
-
"PYG",
|
|
121
|
-
"QAR",
|
|
122
|
-
"RON",
|
|
123
|
-
"RSD",
|
|
124
|
-
"RUB",
|
|
125
|
-
"RWF",
|
|
126
|
-
"SAR",
|
|
127
|
-
"SBD",
|
|
128
|
-
"SCR",
|
|
129
|
-
"SDG",
|
|
130
|
-
"SEK",
|
|
131
|
-
"SGD",
|
|
132
|
-
"SHP",
|
|
133
|
-
"SLE",
|
|
134
|
-
"SOS",
|
|
135
|
-
"SRD",
|
|
136
|
-
"SSP",
|
|
137
|
-
"STN",
|
|
138
|
-
"SVC",
|
|
139
|
-
"SYP",
|
|
140
|
-
"SZL",
|
|
141
|
-
"THB",
|
|
142
|
-
"TJS",
|
|
143
|
-
"TMT",
|
|
144
|
-
"TND",
|
|
145
|
-
"TOP",
|
|
146
|
-
"TRY",
|
|
147
|
-
"TTD",
|
|
148
|
-
"TWD",
|
|
149
|
-
"TZS",
|
|
150
|
-
"UAH",
|
|
151
|
-
"UGX",
|
|
152
|
-
"USD",
|
|
153
|
-
"USN",
|
|
154
|
-
"UYI",
|
|
155
|
-
"UYU",
|
|
156
|
-
"UYW",
|
|
157
|
-
"UZS",
|
|
158
|
-
"VED",
|
|
159
|
-
"VES",
|
|
160
|
-
"VND",
|
|
161
|
-
"VUV",
|
|
162
|
-
"WST",
|
|
163
|
-
"XAF",
|
|
164
|
-
"XCD",
|
|
165
|
-
"XCG",
|
|
166
|
-
"XOF",
|
|
167
|
-
"XPF",
|
|
168
|
-
"YER",
|
|
169
|
-
"ZAR",
|
|
170
|
-
"ZMW",
|
|
171
|
-
"ZWG"
|
|
172
|
-
]);
|
|
173
|
-
function isIso4217(code) {
|
|
174
|
-
return ISO_4217_CODES.has(code.toUpperCase());
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// src/uom/CurrencyExchange.ts
|
|
178
|
-
var CurrencyErrorCodes = {
|
|
179
|
-
/** Frankfurter's rates endpoint returned a non-OK HTTP status. */
|
|
180
|
-
API_ERROR: "CURRENCY_API_ERROR",
|
|
181
|
-
/** A requested currency/crypto code isn't in the fetched rate table, an unrecognized code, not an API failure. */
|
|
182
|
-
UNKNOWN_CODE: "UNKNOWN_CURRENCY_CODE",
|
|
183
|
-
/** CoinGecko's simple-price endpoint returned a non-OK HTTP status. */
|
|
184
|
-
CRYPTO_API_ERROR: "CRYPTO_PRICE_API_ERROR"
|
|
185
|
-
};
|
|
186
|
-
var _CurrencyExchangeService = class _CurrencyExchangeService {
|
|
187
|
-
constructor() {
|
|
188
|
-
/**
|
|
189
|
-
* Live rate tables cached from successful getRate() fetches, keyed by
|
|
190
|
-
* uppercase base currency. Each table holds every rate the API returned
|
|
191
|
-
* for that base (plus the base itself at 1), so any pair whose two codes
|
|
192
|
-
* appear in one fresh table can be served synchronously, including
|
|
193
|
-
* cross pairs via triangulation (EUR→GBP through a USD-base table).
|
|
194
|
-
* Stale tables are ignored, not evicted; the next successful fetch for
|
|
195
|
-
* the same base overwrites them.
|
|
196
|
-
*/
|
|
197
|
-
this.baseTables = /* @__PURE__ */ new Map();
|
|
198
|
-
}
|
|
199
|
-
isCryptoCode(code) {
|
|
200
|
-
return code.toUpperCase() in _CurrencyExchangeService.CRYPTO_IDS;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Fetch the live exchange rate for converting 1 unit of `from` into `to`.
|
|
204
|
-
*
|
|
205
|
-
* Routes cryptocurrency codes (see {@link CRYPTO_IDS}) to CoinGecko and
|
|
206
|
-
* everything else to Frankfurter (ECB reference rates, fiat-only). On
|
|
207
|
-
* success, caches the whole returned rate table for `from` so subsequent
|
|
208
|
-
* lookups, including cross-pairs via triangulation, can be served
|
|
209
|
-
* synchronously by {@link getRateSync} within the freshness window.
|
|
210
|
-
*
|
|
211
|
-
* @throws If the currency code is unrecognized or the fetch fails/times out.
|
|
212
|
-
*/
|
|
213
|
-
async getRate(from, to, signal) {
|
|
214
|
-
const fromUpper = from.toUpperCase();
|
|
215
|
-
const toUpper = to.toUpperCase();
|
|
216
|
-
if (this.isCryptoCode(fromUpper) || this.isCryptoCode(toUpper)) {
|
|
217
|
-
return this.getCryptoRate(fromUpper, toUpper, signal);
|
|
218
|
-
}
|
|
219
|
-
const { signal: fetchSignal, cleanup } = createTimeoutSignal(
|
|
220
|
-
signal,
|
|
221
|
-
_CurrencyExchangeService.FETCH_TIMEOUT_MS,
|
|
222
|
-
"Currency API fetch"
|
|
223
|
-
);
|
|
224
|
-
try {
|
|
225
|
-
const response = await fetch(`https://api.frankfurter.dev/v2/rates?base=${fromUpper}`, { signal: fetchSignal });
|
|
226
|
-
if (!response.ok) throw ErrorFactory.external(CurrencyErrorCodes.API_ERROR, `Currency API returned ${response.status}`, { status: response.status });
|
|
227
|
-
const data = await response.json();
|
|
228
|
-
const rates = Array.isArray(data) ? Object.fromEntries(
|
|
229
|
-
data.filter((entry) => {
|
|
230
|
-
if (typeof entry !== "object" || entry === null) return false;
|
|
231
|
-
const candidate = entry;
|
|
232
|
-
return typeof candidate.quote === "string" && typeof candidate.rate === "number";
|
|
233
|
-
}).map((entry) => [entry.quote.toUpperCase(), entry.rate])
|
|
234
|
-
) : data.rates ?? {};
|
|
235
|
-
if (rates[toUpper] === void 0) throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${toUpper}`, { code: toUpper });
|
|
236
|
-
this.baseTables.set(fromUpper, {
|
|
237
|
-
fetchedAt: Date.now(),
|
|
238
|
-
rates: { ...rates, [fromUpper]: 1 }
|
|
239
|
-
});
|
|
240
|
-
return rates[toUpper];
|
|
241
|
-
} finally {
|
|
242
|
-
cleanup();
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Crypto rate fetch, routed through CoinGecko's no-auth simple-price
|
|
247
|
-
* endpoint instead of Frankfurter (fiat-only, has no BTC/ETH concept).
|
|
248
|
-
* Handles all three combinations, crypto→crypto, crypto→fiat
|
|
249
|
-
* fiat→crypto, via prices denominated in USD (or the target fiat
|
|
250
|
-
* directly, which CoinGecko's `vs_currencies` also accepts), then
|
|
251
|
-
* caches the result as a same-shaped base table so getRateSync /
|
|
252
|
-
* convertSync keep working unchanged for crypto pairs too.
|
|
253
|
-
*/
|
|
254
|
-
async getCryptoRate(fromUpper, toUpper, signal) {
|
|
255
|
-
const { signal: fetchSignal, cleanup } = createTimeoutSignal(
|
|
256
|
-
signal,
|
|
257
|
-
_CurrencyExchangeService.FETCH_TIMEOUT_MS,
|
|
258
|
-
"Crypto price API fetch"
|
|
259
|
-
);
|
|
260
|
-
try {
|
|
261
|
-
const fromIsCrypto = this.isCryptoCode(fromUpper);
|
|
262
|
-
const toIsCrypto = this.isCryptoCode(toUpper);
|
|
263
|
-
let rate;
|
|
264
|
-
if (fromIsCrypto && toIsCrypto) {
|
|
265
|
-
const fromId = _CurrencyExchangeService.CRYPTO_IDS[fromUpper];
|
|
266
|
-
const toId = _CurrencyExchangeService.CRYPTO_IDS[toUpper];
|
|
267
|
-
const data = await this.fetchCoinGeckoPrices([fromId, toId], "usd", fetchSignal);
|
|
268
|
-
const fromUsd = data[fromId]?.usd;
|
|
269
|
-
const toUsd = data[toId]?.usd;
|
|
270
|
-
if (typeof fromUsd !== "number") throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${fromUpper}`, { code: fromUpper });
|
|
271
|
-
if (typeof toUsd !== "number") throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${toUpper}`, { code: toUpper });
|
|
272
|
-
rate = fromUsd / toUsd;
|
|
273
|
-
} else if (fromIsCrypto) {
|
|
274
|
-
const fromId = _CurrencyExchangeService.CRYPTO_IDS[fromUpper];
|
|
275
|
-
const vs = toUpper.toLowerCase();
|
|
276
|
-
const data = await this.fetchCoinGeckoPrices([fromId], vs, fetchSignal);
|
|
277
|
-
const value = data[fromId]?.[vs];
|
|
278
|
-
if (typeof value !== "number") throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${toUpper}`, { code: toUpper });
|
|
279
|
-
rate = value;
|
|
280
|
-
} else {
|
|
281
|
-
const toId = _CurrencyExchangeService.CRYPTO_IDS[toUpper];
|
|
282
|
-
const vs = fromUpper.toLowerCase();
|
|
283
|
-
const data = await this.fetchCoinGeckoPrices([toId], vs, fetchSignal);
|
|
284
|
-
const priceOfToInFrom = data[toId]?.[vs];
|
|
285
|
-
if (typeof priceOfToInFrom !== "number") throw ErrorFactory.validation(CurrencyErrorCodes.UNKNOWN_CODE, `Unknown currency: ${fromUpper}`, { code: fromUpper });
|
|
286
|
-
rate = 1 / priceOfToInFrom;
|
|
287
|
-
}
|
|
288
|
-
this.baseTables.set(fromUpper, {
|
|
289
|
-
fetchedAt: Date.now(),
|
|
290
|
-
rates: { [fromUpper]: 1, [toUpper]: rate }
|
|
291
|
-
});
|
|
292
|
-
return rate;
|
|
293
|
-
} finally {
|
|
294
|
-
cleanup();
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
async fetchCoinGeckoPrices(ids, vsCurrency, signal) {
|
|
298
|
-
const url = `https://api.coingecko.com/api/v3/simple/price?ids=${ids.join(",")}&vs_currencies=${vsCurrency}`;
|
|
299
|
-
const response = await fetch(url, { signal });
|
|
300
|
-
if (!response.ok) throw ErrorFactory.external(CurrencyErrorCodes.CRYPTO_API_ERROR, `Crypto price API returned ${response.status}`, { status: response.status });
|
|
301
|
-
return response.json();
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Seed a base rate table without a network fetch.
|
|
305
|
-
*
|
|
306
|
-
* Intended for tests and for future user-provided offline rates
|
|
307
|
-
* production live data always comes from {@link getRate}. Seeded rates
|
|
308
|
-
* obey the same freshness window as fetched ones.
|
|
309
|
-
*
|
|
310
|
-
* @param base - Base currency code (e.g. "USD").
|
|
311
|
-
* @param rates - Map of currency code → rate relative to the base.
|
|
312
|
-
*/
|
|
313
|
-
primeRates(base, rates) {
|
|
314
|
-
const baseUpper = base.toUpperCase();
|
|
315
|
-
this.baseTables.set(baseUpper, {
|
|
316
|
-
fetchedAt: Date.now(),
|
|
317
|
-
rates: { ...rates, [baseUpper]: 1 }
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Drop every cached/primed rate table.
|
|
322
|
-
*
|
|
323
|
-
* Mainly for test isolation: {@link sharedCurrencyExchange} is a
|
|
324
|
-
* module-level singleton, so a rate primed or fetched by one test can
|
|
325
|
-
* silently leak into a later test in the same file. Also usable in
|
|
326
|
-
* production if a caller ever wants to force a full re-fetch.
|
|
327
|
-
*/
|
|
328
|
-
clearRates() {
|
|
329
|
-
this.baseTables.clear();
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Synchronous rate lookup: `1` for same-currency pairs, a cached LIVE
|
|
333
|
-
* rate if one was fetched within {@link RATE_FRESHNESS_MS}, otherwise
|
|
334
|
-
* `null`, callers fall through to the async fetch path and the
|
|
335
|
-
* expression shows Pending until real data arrives.
|
|
336
|
-
*
|
|
337
|
-
* There is deliberately no hardcoded fallback table: a stale made-up
|
|
338
|
-
* rate presented as a real conversion is worse than a Pending state.
|
|
339
|
-
*/
|
|
340
|
-
getRateSync(from, to) {
|
|
341
|
-
const fromUpper = from.toUpperCase();
|
|
342
|
-
const toUpper = to.toUpperCase();
|
|
343
|
-
if (fromUpper === toUpper) {
|
|
344
|
-
return 1;
|
|
345
|
-
}
|
|
346
|
-
const now = Date.now();
|
|
347
|
-
for (const table of this.baseTables.values()) {
|
|
348
|
-
if (now - table.fetchedAt > _CurrencyExchangeService.RATE_FRESHNESS_MS) continue;
|
|
349
|
-
const fromRate = table.rates[fromUpper];
|
|
350
|
-
const toRate = table.rates[toUpper];
|
|
351
|
-
if (fromRate && toRate) {
|
|
352
|
-
return toRate / fromRate;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return null;
|
|
356
|
-
}
|
|
357
|
-
/** Convert `value` from `from` to `to` using a freshly-fetched live rate (see {@link getRate}). */
|
|
358
|
-
async convert(value, from, to) {
|
|
359
|
-
const rate = await this.getRate(from, to);
|
|
360
|
-
return value * rate;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Get all currently cached fresh rates, keyed "FROM:TO".
|
|
364
|
-
* @returns Snapshot of fresh live rates, or null when none are cached.
|
|
365
|
-
*/
|
|
366
|
-
getAllRates() {
|
|
367
|
-
const now = Date.now();
|
|
368
|
-
const snapshot = {};
|
|
369
|
-
let any = false;
|
|
370
|
-
for (const [base, table] of this.baseTables) {
|
|
371
|
-
if (now - table.fetchedAt > _CurrencyExchangeService.RATE_FRESHNESS_MS) continue;
|
|
372
|
-
for (const [code, rate] of Object.entries(table.rates)) {
|
|
373
|
-
snapshot[`${base}:${code}`] = rate;
|
|
374
|
-
any = true;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
return any ? snapshot : null;
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Check whether any fresh live rates are currently cached.
|
|
381
|
-
*/
|
|
382
|
-
hasRates() {
|
|
383
|
-
return this.getAllRates() !== null;
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Synchronous conversion using cached rates only
|
|
387
|
-
* Returns null if rate not in cache
|
|
388
|
-
*/
|
|
389
|
-
convertSync(value, from, to) {
|
|
390
|
-
const rate = this.getRateSync(from, to);
|
|
391
|
-
if (rate === null) return null;
|
|
392
|
-
return value * rate;
|
|
393
|
-
}
|
|
394
|
-
// ------------------------------------------------------------------------
|
|
395
|
-
// CURRENCY VALIDATION
|
|
396
|
-
// ------------------------------------------------------------------------
|
|
397
|
-
/**
|
|
398
|
-
* Check whether `code` is a recognized currency code: any active ISO 4217
|
|
399
|
-
* code, or one of the cryptocurrencies in {@link CRYPTO_IDS}.
|
|
400
|
-
*
|
|
401
|
-
* This used to be a hand-written list of forty-six codes, which meant
|
|
402
|
-
* `$100 in UAH` returned an unconverted hundred dollars rather than saying
|
|
403
|
-
* it could not convert. Answering from the standard rather than from
|
|
404
|
-
* whichever codes happened to get added is what stops that class of bug.
|
|
405
|
-
*
|
|
406
|
-
* Recognising a code is not the same as having a rate for it. That is
|
|
407
|
-
* answered later, by the exchange provider; conflating the two is what
|
|
408
|
-
* produced the silent failure.
|
|
409
|
-
*/
|
|
410
|
-
isCurrency(code) {
|
|
411
|
-
return isIso4217(code) || this.isCryptoCode(code);
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
/**
|
|
415
|
-
* How long a fetched rate may be served synchronously by getRateSync().
|
|
416
|
-
* Beyond this window callers fall through to the async path (expression
|
|
417
|
-
* shows Pending until the fetch lands).
|
|
418
|
-
*/
|
|
419
|
-
_CurrencyExchangeService.RATE_FRESHNESS_MS = 15 * 60 * 1e3;
|
|
420
|
-
/**
|
|
421
|
-
* Ticker → CoinGecko coin id, for the cryptocurrencies `isCurrency()`
|
|
422
|
-
* recognizes. Frankfurter (the fiat rate source below) is ECB reference
|
|
423
|
-
* rates only and has no concept of BTC/ETH/etc, routing a crypto code
|
|
424
|
-
* through it as `base=BTC` fails outright, which is why crypto pairs
|
|
425
|
-
* previously never resolved (see CurrencyAsyncResolver/VM.ts's ADD
|
|
426
|
-
* handling for the two bugs that let that failure pass silently instead
|
|
427
|
-
* of surfacing as a real fetch).
|
|
428
|
-
*/
|
|
429
|
-
_CurrencyExchangeService.CRYPTO_IDS = {
|
|
430
|
-
BTC: "bitcoin",
|
|
431
|
-
ETH: "ethereum",
|
|
432
|
-
SOL: "solana",
|
|
433
|
-
XRP: "ripple",
|
|
434
|
-
ADA: "cardano",
|
|
435
|
-
DOGE: "dogecoin",
|
|
436
|
-
DOT: "polkadot"
|
|
437
|
-
};
|
|
438
|
-
// ------------------------------------------------------------------------
|
|
439
|
-
// RATE FETCHING
|
|
440
|
-
// ------------------------------------------------------------------------
|
|
441
|
-
/**
|
|
442
|
-
* Timeout (ms) for currency exchange rate fetches.
|
|
443
|
-
*
|
|
444
|
-
* If the frankfurter API doesn't respond within this window, the fetch
|
|
445
|
-
* is aborted, preventing indefinite "Pending" states in the playground
|
|
446
|
-
* and Obsidian plugin when the exchange rate API is unreachable.
|
|
447
|
-
*/
|
|
448
|
-
_CurrencyExchangeService.FETCH_TIMEOUT_MS = 1e4;
|
|
449
|
-
var CurrencyExchangeService = _CurrencyExchangeService;
|
|
450
|
-
var currencyExchangeService = new CurrencyExchangeService();
|
|
451
|
-
var sharedCurrencyExchange = currencyExchangeService;
|
|
452
|
-
|
|
453
|
-
export { CurrencyExchangeService, currencyExchangeService, sharedCurrencyExchange };
|
|
454
|
-
//# sourceMappingURL=chunk-BSPXMGIS.js.map
|
|
455
|
-
//# sourceMappingURL=chunk-BSPXMGIS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/uom/Iso4217.ts","../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A,IAAI,IAAA,KAAS,MAAM,OAAO,IAAA;AAC1B,IAAA,OAAO,KAAA,GAAQ,IAAA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,WAAW,IAAA,EAAuB;AAChC,IAAA,OAAO,SAAA,CAAU,IAAI,CAAA,IAAK,IAAA,CAAK,aAAa,IAAI,CAAA;AAAA,EAClD;AACF,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA/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-BSPXMGIS.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"]}
|