solve-engine 1.0.0-beta.0 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BytecodeBuilder-3egMyuDi.d.cts +274 -0
- package/dist/BytecodeBuilder-3egMyuDi.d.ts +274 -0
- package/dist/Configuration-fVpd-HC-.d.cts +228 -0
- package/dist/Configuration-fVpd-HC-.d.ts +228 -0
- package/dist/EngineError-DvPSnhZi.d.cts +304 -0
- package/dist/EngineError-DvPSnhZi.d.ts +304 -0
- package/dist/Lexer-BJdhlnej.d.cts +531 -0
- package/dist/Lexer-D9l4Yrk2.d.ts +531 -0
- package/dist/NormalizerRule-BrVoVjmP.d.cts +163 -0
- package/dist/NormalizerRule-CEjf1FyD.d.ts +163 -0
- package/dist/PackageRegistry-D-Tv_7ca.d.cts +2572 -0
- package/dist/PackageRegistry-DaH4aIKP.d.ts +2572 -0
- package/dist/Parselet-CK8cQu2a.d.cts +299 -0
- package/dist/Parselet-ConOIdRO.d.ts +299 -0
- package/dist/ScopeManager-B5k0nk05.d.ts +559 -0
- package/dist/ScopeManager-CKfQtl7l.d.cts +559 -0
- package/dist/Token-0jpvUdPY.d.cts +245 -0
- package/dist/Token-0jpvUdPY.d.ts +245 -0
- package/dist/VMCheckpoints-BmDwIXgK.d.ts +171 -0
- package/dist/VMCheckpoints-CqFuLwrT.d.cts +171 -0
- package/dist/Value-KtAQNHur.d.cts +295 -0
- package/dist/Value-KtAQNHur.d.ts +295 -0
- package/dist/chunk-2RWAXT6O.js +3 -0
- package/dist/chunk-2RWAXT6O.js.map +1 -0
- package/dist/chunk-34RRD7PC.js +1492 -0
- package/dist/chunk-34RRD7PC.js.map +1 -0
- package/dist/chunk-3PPFLFH4.js +5097 -0
- package/dist/chunk-3PPFLFH4.js.map +1 -0
- package/dist/chunk-3VGDNEE3.js +84 -0
- package/dist/chunk-3VGDNEE3.js.map +1 -0
- package/dist/chunk-3YNVWKR2.cjs +370 -0
- package/dist/chunk-3YNVWKR2.cjs.map +1 -0
- package/dist/chunk-47LRVGOT.cjs +316 -0
- package/dist/chunk-47LRVGOT.cjs.map +1 -0
- package/dist/chunk-4MG4XKO2.js +1644 -0
- package/dist/chunk-4MG4XKO2.js.map +1 -0
- package/dist/chunk-4QADQTWS.js +2392 -0
- package/dist/chunk-4QADQTWS.js.map +1 -0
- package/dist/chunk-53B6KDDJ.cjs +1651 -0
- package/dist/chunk-53B6KDDJ.cjs.map +1 -0
- package/dist/chunk-5X2PTP6F.cjs +104 -0
- package/dist/chunk-5X2PTP6F.cjs.map +1 -0
- package/dist/chunk-5YEMOYSE.js +264 -0
- package/dist/chunk-5YEMOYSE.js.map +1 -0
- package/dist/chunk-64W6GLLZ.js +481 -0
- package/dist/chunk-64W6GLLZ.js.map +1 -0
- package/dist/chunk-6BKTCEUP.cjs +233 -0
- package/dist/chunk-6BKTCEUP.cjs.map +1 -0
- package/dist/chunk-6NTVRDQV.cjs +1642 -0
- package/dist/chunk-6NTVRDQV.cjs.map +1 -0
- package/dist/chunk-6RDSQURE.js +290 -0
- package/dist/chunk-6RDSQURE.js.map +1 -0
- package/dist/chunk-75JP4BZX.js +93 -0
- package/dist/chunk-75JP4BZX.js.map +1 -0
- package/dist/chunk-B7LXJ6LC.cjs +36 -0
- package/dist/chunk-B7LXJ6LC.cjs.map +1 -0
- package/dist/chunk-BVAR5J2F.js +257 -0
- package/dist/chunk-BVAR5J2F.js.map +1 -0
- package/dist/chunk-C4XZV6E7.cjs +269 -0
- package/dist/chunk-C4XZV6E7.cjs.map +1 -0
- package/dist/chunk-CCJPSHGI.cjs +40 -0
- package/dist/chunk-CCJPSHGI.cjs.map +1 -0
- package/dist/chunk-CLL7RUQV.cjs +316 -0
- package/dist/chunk-CLL7RUQV.cjs.map +1 -0
- package/dist/chunk-DM3LMRBC.js +329 -0
- package/dist/chunk-DM3LMRBC.js.map +1 -0
- package/dist/chunk-DUEZFTK2.js +38 -0
- package/dist/chunk-DUEZFTK2.js.map +1 -0
- package/dist/chunk-EBSPLUW4.cjs +489 -0
- package/dist/chunk-EBSPLUW4.cjs.map +1 -0
- package/dist/chunk-EHAHVROS.cjs +261 -0
- package/dist/chunk-EHAHVROS.cjs.map +1 -0
- package/dist/chunk-EIGTWK5N.js +167 -0
- package/dist/chunk-EIGTWK5N.js.map +1 -0
- package/dist/chunk-EPOXXJBK.js +96 -0
- package/dist/chunk-EPOXXJBK.js.map +1 -0
- package/dist/chunk-FEAIOR7N.cjs +91 -0
- package/dist/chunk-FEAIOR7N.cjs.map +1 -0
- package/dist/chunk-G535KJEG.js +312 -0
- package/dist/chunk-G535KJEG.js.map +1 -0
- package/dist/chunk-GCM5JHMX.js +88 -0
- package/dist/chunk-GCM5JHMX.js.map +1 -0
- package/dist/chunk-GOLDJNMZ.js +368 -0
- package/dist/chunk-GOLDJNMZ.js.map +1 -0
- package/dist/chunk-GW32KPCU.cjs +360 -0
- package/dist/chunk-GW32KPCU.cjs.map +1 -0
- package/dist/chunk-HTXVVJRA.cjs +1549 -0
- package/dist/chunk-HTXVVJRA.cjs.map +1 -0
- package/dist/chunk-HWSZJQCI.js +311 -0
- package/dist/chunk-HWSZJQCI.js.map +1 -0
- package/dist/chunk-IF532O7C.js +101 -0
- package/dist/chunk-IF532O7C.js.map +1 -0
- package/dist/chunk-J73SJHR3.cjs +2415 -0
- package/dist/chunk-J73SJHR3.cjs.map +1 -0
- package/dist/chunk-JBSYC7BB.cjs +7473 -0
- package/dist/chunk-JBSYC7BB.cjs.map +1 -0
- package/dist/chunk-KVILKGMS.js +228 -0
- package/dist/chunk-KVILKGMS.js.map +1 -0
- package/dist/chunk-LIPPNDBE.js +258 -0
- package/dist/chunk-LIPPNDBE.js.map +1 -0
- package/dist/chunk-LR7YASZF.cjs +172 -0
- package/dist/chunk-LR7YASZF.cjs.map +1 -0
- package/dist/chunk-M4N5GA5Z.cjs +309 -0
- package/dist/chunk-M4N5GA5Z.cjs.map +1 -0
- package/dist/chunk-M5LX5AOO.js +7459 -0
- package/dist/chunk-M5LX5AOO.js.map +1 -0
- package/dist/chunk-MZOVP3WI.cjs +96 -0
- package/dist/chunk-MZOVP3WI.cjs.map +1 -0
- package/dist/chunk-N5YFR4UP.cjs +10 -0
- package/dist/chunk-N5YFR4UP.cjs.map +1 -0
- package/dist/chunk-NGBBNL4K.cjs +4 -0
- package/dist/chunk-NGBBNL4K.cjs.map +1 -0
- package/dist/chunk-NH2O2AUR.js +146 -0
- package/dist/chunk-NH2O2AUR.js.map +1 -0
- package/dist/chunk-NLNDMWZC.js +31 -0
- package/dist/chunk-NLNDMWZC.js.map +1 -0
- package/dist/chunk-NMCRQP3Z.cjs +778 -0
- package/dist/chunk-NMCRQP3Z.cjs.map +1 -0
- package/dist/chunk-NMD5VRN4.cjs +1327 -0
- package/dist/chunk-NMD5VRN4.cjs.map +1 -0
- package/dist/chunk-OC6LTXYS.cjs +286 -0
- package/dist/chunk-OC6LTXYS.cjs.map +1 -0
- package/dist/chunk-OT6OJY7C.cjs +114 -0
- package/dist/chunk-OT6OJY7C.cjs.map +1 -0
- package/dist/chunk-PFSDGGYL.js +8 -0
- package/dist/chunk-PFSDGGYL.js.map +1 -0
- package/dist/chunk-QNJ4ACRT.cjs +155 -0
- package/dist/chunk-QNJ4ACRT.cjs.map +1 -0
- package/dist/chunk-QWY3VEZN.js +1637 -0
- package/dist/chunk-QWY3VEZN.js.map +1 -0
- package/dist/chunk-RFYD5TJE.js +111 -0
- package/dist/chunk-RFYD5TJE.js.map +1 -0
- package/dist/chunk-RIN643A3.js +354 -0
- package/dist/chunk-RIN643A3.js.map +1 -0
- package/dist/chunk-RZCWSXTA.cjs +5122 -0
- package/dist/chunk-RZCWSXTA.cjs.map +1 -0
- package/dist/chunk-SDGRK7EP.js +774 -0
- package/dist/chunk-SDGRK7EP.js.map +1 -0
- package/dist/chunk-VEKIWQ3F.cjs +39 -0
- package/dist/chunk-VEKIWQ3F.cjs.map +1 -0
- package/dist/chunk-WQTTOGXC.cjs +99 -0
- package/dist/chunk-WQTTOGXC.cjs.map +1 -0
- package/dist/chunk-X6K3HUOY.cjs +86 -0
- package/dist/chunk-X6K3HUOY.cjs.map +1 -0
- package/dist/chunk-XJCMXB2E.cjs +333 -0
- package/dist/chunk-XJCMXB2E.cjs.map +1 -0
- package/dist/chunk-XVWCOTR6.js +1324 -0
- package/dist/chunk-XVWCOTR6.js.map +1 -0
- package/dist/chunk-YLJ4XMA6.js +33 -0
- package/dist/chunk-YLJ4XMA6.js.map +1 -0
- package/dist/chunk-Z2XP767T.cjs +35 -0
- package/dist/chunk-Z2XP767T.cjs.map +1 -0
- package/dist/chunk-Z4X2RWOF.js +37 -0
- package/dist/chunk-Z4X2RWOF.js.map +1 -0
- package/dist/constants.cjs +22 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +12 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/engine.cjs +79 -0
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +587 -0
- package/dist/engine.d.ts +587 -0
- package/dist/engine.js +34 -0
- package/dist/engine.js.map +1 -0
- package/dist/errors.cjs +81 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +95 -0
- package/dist/errors.d.ts +95 -0
- package/dist/errors.js +4 -0
- package/dist/errors.js.map +1 -0
- package/dist/format.cjs +171 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.d.cts +51 -0
- package/dist/format.d.ts +51 -0
- package/dist/format.js +168 -0
- package/dist/format.js.map +1 -0
- package/dist/index.cjs +97 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +152 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +75 -0
- package/dist/index.js.map +1 -0
- package/dist/language.cjs +308 -0
- package/dist/language.cjs.map +1 -0
- package/dist/language.d.cts +110 -0
- package/dist/language.d.ts +110 -0
- package/dist/language.js +287 -0
- package/dist/language.js.map +1 -0
- package/dist/lexer.cjs +64 -0
- package/dist/lexer.cjs.map +1 -0
- package/dist/lexer.d.cts +56 -0
- package/dist/lexer.d.ts +56 -0
- package/dist/lexer.js +11 -0
- package/dist/lexer.js.map +1 -0
- package/dist/normalizer.cjs +40 -0
- package/dist/normalizer.cjs.map +1 -0
- package/dist/normalizer.d.cts +364 -0
- package/dist/normalizer.d.ts +364 -0
- package/dist/normalizer.js +11 -0
- package/dist/normalizer.js.map +1 -0
- package/dist/packages.cjs +121 -0
- package/dist/packages.cjs.map +1 -0
- package/dist/packages.d.cts +691 -0
- package/dist/packages.d.ts +691 -0
- package/dist/packages.js +24 -0
- package/dist/packages.js.map +1 -0
- package/dist/parser.cjs +55 -0
- package/dist/parser.cjs.map +1 -0
- package/dist/parser.d.cts +46 -0
- package/dist/parser.d.ts +46 -0
- package/dist/parser.js +10 -0
- package/dist/parser.js.map +1 -0
- package/dist/pipeline-CrsRPmsv.d.ts +285 -0
- package/dist/pipeline-DPUQt7yL.d.cts +285 -0
- package/dist/resolvers.cjs +13 -0
- package/dist/resolvers.cjs.map +1 -0
- package/dist/resolvers.d.cts +111 -0
- package/dist/resolvers.d.ts +111 -0
- package/dist/resolvers.js +4 -0
- package/dist/resolvers.js.map +1 -0
- package/dist/services.cjs +21 -0
- package/dist/services.cjs.map +1 -0
- package/dist/services.d.cts +30 -0
- package/dist/services.d.ts +30 -0
- package/dist/services.js +4 -0
- package/dist/services.js.map +1 -0
- package/dist/uom.cjs +56 -0
- package/dist/uom.cjs.map +1 -0
- package/dist/uom.d.cts +224 -0
- package/dist/uom.d.ts +224 -0
- package/dist/uom.js +11 -0
- package/dist/uom.js.map +1 -0
- package/dist/utilities.cjs +32 -0
- package/dist/utilities.cjs.map +1 -0
- package/dist/utilities.d.cts +113 -0
- package/dist/utilities.d.ts +113 -0
- package/dist/utilities.js +7 -0
- package/dist/utilities.js.map +1 -0
- package/dist/variables.cjs +17 -0
- package/dist/variables.cjs.map +1 -0
- package/dist/variables.d.cts +87 -0
- package/dist/variables.d.ts +87 -0
- package/dist/variables.js +4 -0
- package/dist/variables.js.map +1 -0
- package/dist/vm.cjs +284 -0
- package/dist/vm.cjs.map +1 -0
- package/dist/vm.d.cts +68 -0
- package/dist/vm.d.ts +68 -0
- package/dist/vm.js +194 -0
- package/dist/vm.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
import { I as IEnginePackage } from './PackageRegistry-D-Tv_7ca.cjs';
|
|
2
|
+
import './Parselet-CK8cQu2a.cjs';
|
|
3
|
+
import './BytecodeBuilder-3egMyuDi.cjs';
|
|
4
|
+
import './Token-0jpvUdPY.cjs';
|
|
5
|
+
import './pipeline-DPUQt7yL.cjs';
|
|
6
|
+
import './Value-KtAQNHur.cjs';
|
|
7
|
+
import './variables.cjs';
|
|
8
|
+
import './Lexer-BJdhlnej.cjs';
|
|
9
|
+
import './resolvers.cjs';
|
|
10
|
+
import '@tanstack/query-core';
|
|
11
|
+
import './NormalizerRule-BrVoVjmP.cjs';
|
|
12
|
+
import './ScopeManager-CKfQtl7l.cjs';
|
|
13
|
+
import './EngineError-DvPSnhZi.cjs';
|
|
14
|
+
import './Configuration-fVpd-HC-.cjs';
|
|
15
|
+
|
|
16
|
+
/** Core arithmetic: numbers, `()` grouping, `pi`/`e` constants, `+ - * / % ^`, bitwise `<< >> & | ^`, and their `*_by` word forms. */
|
|
17
|
+
declare const ARITHMETIC_PACKAGE: IEnginePackage;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Percentage syntax: `50%`, `50% of 200`, `100 to 150` (percentage change),
|
|
21
|
+
* `increase 100 by 10%`/`decrease 100 by 10%` (prefix form), the
|
|
22
|
+
* `100 increase by 10%`/`100 decrease by 10%` infix form (fused from the
|
|
23
|
+
* "increase by"/"decrease by" phrases by the built-in normalizer. See
|
|
24
|
+
* BuiltinNormalizerRules.BUILTIN_PHRASES), and `5% of what is 6` (solve
|
|
25
|
+
* for the base value. See OfWhatIsParselet.ts's doc comment). "of what
|
|
26
|
+
* is" is phrase-fused (not a bare "what" keyword) for the same
|
|
27
|
+
* variable-name-collision reason "total"/"average"/etc. are fused
|
|
28
|
+
* elsewhere in this codebase, "what" is common enough to be worth
|
|
29
|
+
* protecting as a `:variableName`.
|
|
30
|
+
*/
|
|
31
|
+
declare const PERCENTAGE_PACKAGE: IEnginePackage;
|
|
32
|
+
|
|
33
|
+
/** Built-in function call syntax, e.g. `sqrt(2)`, `sin(pi)`, dispatches recognized function names to CALL_BUILTIN opcodes. */
|
|
34
|
+
declare const FUNCTION_PACKAGE: IEnginePackage;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Date/time keywords: `now`, `today`, `tomorrow`, `yesterday`,
|
|
38
|
+
* `next <Weekday>`/`last <Weekday>`, `<unit> until <Datetime>`/`<unit> since <Datetime>`.
|
|
39
|
+
* Uses the datetime arithmetic opcodes (`DATE_ADD`/`DATE_SUB`/`DATE_NEXT_WEEKDAY`/`DATE_LAST_WEEKDAY`)
|
|
40
|
+
* plus the shared UoM conversion opcode (`UOM_CONVERT_IN`) for until/since.
|
|
41
|
+
*
|
|
42
|
+
* Also: workdays/weekdays and timestamps/ISO8601
|
|
43
|
+
*
|
|
44
|
+
* - `workdays in <duration>`. See `WorkdaysInParselet.ts`.
|
|
45
|
+
* - `<date> + N workdays` / `<date> - N workdays`, plain "+"/"-"
|
|
46
|
+
* arithmetic, special-cased in `vm/VM.ts`'s ADD/SUB dispatch for the
|
|
47
|
+
* `workday`/`workdays` UNIT (see `lexer/units.ts`) since business-day
|
|
48
|
+
* math needs actual weekend-skipping, not a linear ms conversion.
|
|
49
|
+
* - `<amount>/workday x <duration>`, a Rate, exactly like `$99/week`
|
|
50
|
+
* already works, using `uom/UomConverter.ts`'s workday<->day shim so
|
|
51
|
+
* `getMeasure()`/`convertUnit()` treat "workday" as a Time-measure unit
|
|
52
|
+
* (5 workdays == 7 calendar days). See that file's doc comment. The
|
|
53
|
+
* bare-denominator syntax `$500/workday` (no explicit "1") additionally
|
|
54
|
+
* needs `workdayRateDenominatorNormalizerRule`. See its doc comment.
|
|
55
|
+
* - `day of the week on <date>` / `weekday on <date>`, and the
|
|
56
|
+
* natural-question forms over the same three date fields
|
|
57
|
+
* `what day is it`, `what day is it on <date>`, `what day is it in
|
|
58
|
+
* <duration>`, and the `month`/`week` equivalents. All one parselet, see
|
|
59
|
+
* `DateFieldQueryParselet.ts`. The same fields are also available
|
|
60
|
+
* composably as `<date> as weekday` / `as month` / `as week` via
|
|
61
|
+
* `asConverters` below.
|
|
62
|
+
* - `<unit> between <date> and <date>`, the two-explicit-endpoints
|
|
63
|
+
* sibling of `until`/`since`, see `DurationBetweenParselet.ts`. A
|
|
64
|
+
* leading `how many` is accepted for it and for `until`/`since`, see
|
|
65
|
+
* `BetweenUnitNormalizerRule.ts`.
|
|
66
|
+
* - `<date> is a weekend` / `is a workday`, postfix predicates, see
|
|
67
|
+
* `DayTypePredicateParselet.ts`. Mon-Fri only, matching the workday
|
|
68
|
+
* scope decision below.
|
|
69
|
+
* - `current timestamp` / `<date/time> to timestamp` / `<ISO8601 string
|
|
70
|
+
* or unix timestamp> to date`. See `CurrentTimestampParselet.ts` /
|
|
71
|
+
* `ToTimestampParselet.ts` / `ToDateParselet.ts` and
|
|
72
|
+
* `DatetimeTimestampPluginFunctions.ts`.
|
|
73
|
+
* - Bare numeric date literals, `25/12/2023` (European DD/MM/YYYY)
|
|
74
|
+
* `12-25-2023` (US MM-DD-YYYY), `2023-12-25` (ISO YYYY-MM-DD), and
|
|
75
|
+
* `25.12.2023` (dot-separated DD.MM.YYYY), fused into a single
|
|
76
|
+
* `DATETIME_LITERAL` token by `dateLiteralNormalizerRule()` and pushed by
|
|
77
|
+
* `DateLiteralParselet`. Ported from the sibling `feat/safety-limits-datetime-literals`
|
|
78
|
+
* branch referenced in `Iso8601.ts`'s and the Stocks package's
|
|
79
|
+
* `DatePhrase.ts`'s doc comments. This is that work, now merged.
|
|
80
|
+
* - `<date/time> as iso8601`, registered below via `asConverters`
|
|
81
|
+
* (the `Converters` package's `<expr> as <type>` extension point, see
|
|
82
|
+
* `api/PackageRegistry.ts`'s doc comment) rather than a new opcode or a
|
|
83
|
+
* `Converters`-package-owned built-in name: `asConverters` already
|
|
84
|
+
* exists precisely for a third-party/domain package to contribute a
|
|
85
|
+
* new `as <name>` target without touching `AsConverterParselet.ts` or
|
|
86
|
+
* `OpCode.ts` at all, and "iso8601" is inherently a datetime-package
|
|
87
|
+
* concept (needs `Iso8601.ts`'s formatting, which already lives here)
|
|
88
|
+
* simpler to keep it self-contained in this package than to split the
|
|
89
|
+
* feature across two packages for a marginal "which package owns the
|
|
90
|
+
* converter-name list" tidiness gain.
|
|
91
|
+
*
|
|
92
|
+
* SCOPE DECISION (workdays, both the count and the date-arithmetic forms):
|
|
93
|
+
* plain Mon-Fri business-day math, with NO public-holiday exclusion.
|
|
94
|
+
* SoulverCore's own workday calculations auto-exclude public holidays via
|
|
95
|
+
* a live-updating, region-configurable holiday database, picking which
|
|
96
|
+
* holidays/region and keeping such a database current is real, separate
|
|
97
|
+
* scope this pass deliberately does not take on (see `vm/VM.ts`'s
|
|
98
|
+
* `addBusinessDays()` doc comment for the fuller version of this note,
|
|
99
|
+
* matching this session's established pattern of documenting a scoped-down
|
|
100
|
+
* simplification rather than silently pretending to support something it
|
|
101
|
+
* doesn't, e.g. Finance's "no hardcoded tax rate" decision).
|
|
102
|
+
*/
|
|
103
|
+
declare const DATETIME_PACKAGE: IEnginePackage;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Clock-time-of-day arithmetic: `9:00am`, `16:00`, `4pm` (anchored to
|
|
107
|
+
* today's calendar date), `7:30 to 20:45` / `4pm to 3am` interval
|
|
108
|
+
* durations (midnight-rollover aware), `30 fps` frame-rate literals (a
|
|
109
|
+
* `Rate` value. See `vm/Value.ts`), and `03:04:05` / `00:00:01.5`
|
|
110
|
+
* lap-time/stopwatch-split durations (two colons, vs clock-time's one).
|
|
111
|
+
* Distinct from the Datetime package's calendar-date arithmetic. See
|
|
112
|
+
* `packages/time/` vs `packages/datetime/`.
|
|
113
|
+
*
|
|
114
|
+
* Full HH:MM:SS:FF video-timecode literal parsing + fps-aware carry
|
|
115
|
+
* arithmetic: `01:02:03:04 at 30 fps` / `... @ 30 fps` (a `Uom(totalFrames,
|
|
116
|
+
* "timecode@<fps>")` value. See `vm/Value.ts`'s timecode section)
|
|
117
|
+
* `timecode + N frames` / `+ <duration>` / `+ timecode` (sum) / `-
|
|
118
|
+
* timecode` (difference), all special-cased in `vm/VM.ts`'s ADD/SUB
|
|
119
|
+
* dispatch (`combineTimecode()`), plus `timecode in frames` and the
|
|
120
|
+
* reverse `<N> frames @ <fps>` -> `HH:MM:SS:FF` string conversion (see
|
|
121
|
+
* `parselets/VideoTimecodeParselet.ts`/`FrameCountParselet.ts` and
|
|
122
|
+
* `timecode/TimecodeMath.ts`). `30 fps × <duration>` frame-count math
|
|
123
|
+
* (below) composes with this unchanged, the fps literal itself is
|
|
124
|
+
* unaffected by any of the above. Likewise, pretty-printing a duration
|
|
125
|
+
* back as `"3 hours 15 min"` (`as timespan`) or `"03:04:05"` (`as
|
|
126
|
+
* laptime`) is a `converters` package (Phase 1c) concern. This package
|
|
127
|
+
* only produces the underlying `Uom` values.
|
|
128
|
+
*
|
|
129
|
+
* Also: timezone conversion (`6pm Sydney in Chicago`), current
|
|
130
|
+
* time/date-in-a-zone queries (`time in Paris`, `date in Vancouver`), and
|
|
131
|
+
* zone-offset deltas (`time difference between Seattle and Moscow`). See
|
|
132
|
+
* `timezones/CityZones.ts`/`ZoneMath.ts`. Built entirely on native
|
|
133
|
+
* `Intl.DateTimeFormat`/IANA data, no external dependency. Results are
|
|
134
|
+
* `String` values (formatted, human-readable), not `Datetime`. This
|
|
135
|
+
* engine's `Datetime` representation is a bare epoch-ms number with no
|
|
136
|
+
* zone tag, so there's no way to represent "this instant, but interpreted
|
|
137
|
+
* through zone X" as anything other than a pre-formatted string; see
|
|
138
|
+
* `ZoneMath.ts`'s doc comment.
|
|
139
|
+
*
|
|
140
|
+
* SCOPE DECISION: the alternate phrasing `<City> time` (e.g. "Tokyo
|
|
141
|
+
* time", city first) is deliberately NOT implemented, it would need
|
|
142
|
+
* "time" registered as a keyword reachable from a BARE city identifier's
|
|
143
|
+
* infix position, and "time" is exactly the kind of common noun this
|
|
144
|
+
* session found real trouble with (see MathPhrasesPackage.ts's "total"
|
|
145
|
+
* regression note). `time in <city>` covers the same need unambiguously.
|
|
146
|
+
*/
|
|
147
|
+
declare const TIME_PACKAGE: IEnginePackage;
|
|
148
|
+
|
|
149
|
+
/** `roll(min, max)`, returns a random integer in the inclusive `[min, max]` range. */
|
|
150
|
+
declare const DICE_PACKAGE: IEnginePackage;
|
|
151
|
+
|
|
152
|
+
/** Variable read/write: `:name = expr` to define, `name` to read, plus `global :name` for a document-spanning variable backed by the {@link GlobalVariableStore} instead of local VM scope. */
|
|
153
|
+
declare const VARIABLES_PACKAGE: IEnginePackage;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Units of measurement: `10 km`, `10 km to miles`, `convert 10 km to miles`,
|
|
157
|
+
* `cm to ?` (conversion-possibilities query). See {@link CURRENCY_PACKAGE}
|
|
158
|
+
* for money, which is a separate package.
|
|
159
|
+
*
|
|
160
|
+
* Also cooking/baking mass<->volume conversion (e.g. "300g butter in
|
|
161
|
+
* cups", "10 cups olive oil in grams"). See
|
|
162
|
+
* `parselets/CookingConversionParselet.ts`,
|
|
163
|
+
* `normalizer/IngredientNameNormalizerRule.ts`, and
|
|
164
|
+
* `data/IngredientDensities.ts` (the bundled, clearly-labeled-approximate
|
|
165
|
+
* ingredient-density table and its scope/accuracy doc comment) for the
|
|
166
|
+
* full design, including why US Customary is the only volume-unit
|
|
167
|
+
* convention supported so far.
|
|
168
|
+
*/
|
|
169
|
+
declare const UOM_PACKAGE: IEnginePackage;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Currency: `$10`, `£10`, `€10`, `¥10`, `₽10`, `₩10`, `₹10`, `₺10`, `₴10`,
|
|
173
|
+
* `₪10`, `₫10`, `₦10`, `₱10`, `10 USD in GBP`, and word forms like
|
|
174
|
+
* `10 euros`/`10 dollars` (see `uom/CurrencyAliases.ts` for the full
|
|
175
|
+
* symbol/word alias tables and the ambiguity decisions behind them)
|
|
176
|
+
* rates are fetched asynchronously (via {@link CurrencyAsyncResolver}) and
|
|
177
|
+
* the expression shows Pending until they resolve.
|
|
178
|
+
*/
|
|
179
|
+
declare const CURRENCY_PACKAGE: IEnginePackage;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Vector literals `vec2(x, y)`/`vec3(x, y, z)`/`vec4(x, y, z, w)` plus float
|
|
183
|
+
* literals, legacy construction sugar kept working after the Calca-parity
|
|
184
|
+
* Matrix rewrite; each just builds a 1xN row-vector `ValueType.Matrix` via
|
|
185
|
+
* `OpCode.MAT_NEW` (see vm/MatrixOps.ts). The bracket literal `[x, y, z]`
|
|
186
|
+
* (packages/matrix/) is the primary, Calca-parity construction syntax going
|
|
187
|
+
* forward.
|
|
188
|
+
*/
|
|
189
|
+
declare const VECTOR_PACKAGE: IEnginePackage;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Matrix literals `[1, 2; 3, 4]` and indexing `a[i]`/`a[row, col]`
|
|
193
|
+
* Calca-parity general matrix support (a vector is just a 1xN or Nx1
|
|
194
|
+
* matrix). See `vm/Value.ts`'s `MatrixData` and `vm/MatrixOps.ts`'s shared
|
|
195
|
+
* column-major storage helpers.
|
|
196
|
+
*
|
|
197
|
+
* `LBRACKET` is registered in BOTH prefix and infix slots, separate
|
|
198
|
+
* registry lookups keyed on parse position, not a collision: a literal
|
|
199
|
+
* opens in prefix position (right after `=`, `(`, an operator, ...) and an
|
|
200
|
+
* index opens in infix/postfix position, right after any value-producing
|
|
201
|
+
* expression.
|
|
202
|
+
*/
|
|
203
|
+
declare const MATRIX_PACKAGE: IEnginePackage;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* `map`/`reduce`/`sum`/`prod`, Calca-parity collection transforms over a
|
|
207
|
+
* Matrix or a bare Range. See `MapReduceShared.ts` for the shared
|
|
208
|
+
* transform-disambiguation/collection-parsing logic, and `vm/VM.ts`'s
|
|
209
|
+
* `MAP_INVOKE`/`REDUCE_INVOKE` opcode handlers for the runtime semantics.
|
|
210
|
+
*
|
|
211
|
+
* `map`/`reduce`/`sum`/`prod` are NOT bare keywordMap entries. See
|
|
212
|
+
* `MapReduceCallNormalizerRule.ts`, which fuses them into their own token
|
|
213
|
+
* types only when immediately followed by `(`, so `:map = [...]` etc.
|
|
214
|
+
* keep working as ordinary variable names.
|
|
215
|
+
*/
|
|
216
|
+
declare const MAPREDUCE_PACKAGE: IEnginePackage;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Symbolic algebra verbs: multiplying out, and (in later phases) factoring,
|
|
220
|
+
* solving and calculus.
|
|
221
|
+
*
|
|
222
|
+
* The algebra itself lives in `symbolic/`, which is pure mathematics over the
|
|
223
|
+
* expression tree. This package is only the grammar surface: which words become
|
|
224
|
+
* which tokens, and which parselet emits which builtin call.
|
|
225
|
+
*
|
|
226
|
+
* None of these words is a bare `keywordMap` entry. See
|
|
227
|
+
* `normalizer/SymbolicCallNormalizerRule.ts` for why that matters.
|
|
228
|
+
*/
|
|
229
|
+
declare const SYMBOLIC_PACKAGE: IEnginePackage;
|
|
230
|
+
|
|
231
|
+
/** Arbitrary-precision integer literals (suffixed, e.g. `123n`) that overflow a normal `number` without losing precision. */
|
|
232
|
+
declare const BIGINT_PACKAGE: IEnginePackage;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Comparisons (`==`, `!=`, `<`, `>`, `<=`, `>=`), boolean logic (`true`/
|
|
236
|
+
* `false`, `and`/`or`/`&&`/`||`), and `if <cond> then <val> else <val>`
|
|
237
|
+
* eager-ternary conditionals.
|
|
238
|
+
*
|
|
239
|
+
* The `and`/`or` split is deliberate, not an oversight: "and" already
|
|
240
|
+
* lexes as `PLUS` (a pre-existing arithmetic word-synonym, `en.ts`:
|
|
241
|
+
* `and: "PLUS"`), a Tier-1 hardcoded infix operator no registry-based
|
|
242
|
+
* parselet can intercept, `OpCode.ADD`'s own VM handler special-cases
|
|
243
|
+
* `Boolean && Boolean` instead (see `vm/VM.ts`). "or"/"&&"/"||" have no
|
|
244
|
+
* such collision and are handled normally here via `LogicalParselet`.
|
|
245
|
+
*
|
|
246
|
+
* KNOWN LIMITATION: because "and" is pinned to `PLUS`'s Tier-1 binding
|
|
247
|
+
* power (`Sum`, tighter than comparisons), an unparenthesized `X >= Y and
|
|
248
|
+
* Z < W` does NOT parse as `(X >= Y) and (Z < W)`, "and"'s fixed
|
|
249
|
+
* precedence grabs a comparison operand instead. Use `&&` (correct,
|
|
250
|
+
* dedicated `LogicalAnd` precedence, looser than comparisons) for that
|
|
251
|
+
* pattern, or wrap each side in parens if "and" is preferred:
|
|
252
|
+
* `(X >= Y) and (Z < W)`. "and" alone (no comparisons in the same
|
|
253
|
+
* unparenthesized expression) works fine, e.g. `discount and hasCoupon`.
|
|
254
|
+
*
|
|
255
|
+
* SCOPE DECISION: SoulverCore-style postfix `Y if X` / `Y unless X` (a
|
|
256
|
+
* ternary with no explicit else-branch) is deliberately NOT implemented.
|
|
257
|
+
* This VM's `Value` has no "empty"/"void" representation for the
|
|
258
|
+
* false-branch case (every expression must produce a concrete typed
|
|
259
|
+
* result), building it properly would mean adding a new sentinel
|
|
260
|
+
* `ValueType` and deciding how every consumer (formatting, DAG
|
|
261
|
+
* propagation, UOM/arithmetic ops) treats it, which is a bigger call than
|
|
262
|
+
* this package should make implicitly. `if X then Y else Z` (both
|
|
263
|
+
* branches required) covers the same need unambiguously today.
|
|
264
|
+
*/
|
|
265
|
+
declare const CONDITIONALS_PACKAGE: IEnginePackage;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* The general `<expr> as <type>` conversion/display mechanism, one
|
|
269
|
+
* unifying grammar point rather than N unrelated per-type features.
|
|
270
|
+
*
|
|
271
|
+
* Ships the built-in set immediately usable (see `BUILTIN_CONVERTERS` in
|
|
272
|
+
* `AsConverterParselet.ts`): `as %`/`as percent`, `as decimal`/`as dec`/
|
|
273
|
+
* `as number`, `as fraction`, `as multiplier`, `as sci`, `as hex`/
|
|
274
|
+
* `as binary`/`as octal`.
|
|
275
|
+
*
|
|
276
|
+
* This is also the other clearly SDK-shaped piece from the SoulverCore
|
|
277
|
+
* feature-parity work (alongside `PhrasePattern`/`createQueryResolver`):
|
|
278
|
+
* `IEnginePackage.asConverters` (see `api/PackageRegistry.ts`) lets a
|
|
279
|
+
* third-party package contribute its own `as <name>` target without
|
|
280
|
+
* touching this package at all, resolved at VM-execution time via
|
|
281
|
+
* `OpCode.CALL_AS_CONVERTER` against `vm/VMBuiltins.ts`'s
|
|
282
|
+
* `asConverterRegistry`.
|
|
283
|
+
*
|
|
284
|
+
* SCOPE DECISION: no `as x` alias for `as multiplier`, "x" is too likely
|
|
285
|
+
* to collide with ordinary variable names (algebraic use, `x = 5`) to
|
|
286
|
+
* justify claiming it as a global keyword for one converter's sake.
|
|
287
|
+
*/
|
|
288
|
+
declare const CONVERTERS_PACKAGE: IEnginePackage;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Phrase-grammar math functions: `average/median/total/count of X, Y, Z`,
|
|
292
|
+
* `larger/smaller of X and Y`, `half of X`, `midpoint between X and Y`,
|
|
293
|
+
* `random number between X and Y`, `clamp X between Y and Z`, and the
|
|
294
|
+
* unit-aware proportion form `A is to B as C is to what`.
|
|
295
|
+
*
|
|
296
|
+
* TRIGGER-WORD COLLISION DESIGN NOTE (real regression found and fixed
|
|
297
|
+
* during development): "average", "total", "count", "larger", "smaller",
|
|
298
|
+
* "half", and "midpoint" are all common, natural variable names (a
|
|
299
|
+
* shipped playground example uses `:total = :afterDiscount + :tax`).
|
|
300
|
+
* This codebase has a tested, intentional policy that a colon-prefixed
|
|
301
|
+
* variable name can't be a keyword-shaped word (see VariableParselet.ts's
|
|
302
|
+
* doc comment and its "reserved-keyword regression" test), so claiming
|
|
303
|
+
* any of those as a BARE global keyword would have permanently broken
|
|
304
|
+
* `:total = ...`-style usage, which is exactly what happened on the first
|
|
305
|
+
* pass of this package.
|
|
306
|
+
*
|
|
307
|
+
* The fix: fuse the full two-word phrase ("average of", "total of",
|
|
308
|
+
* "half of", "midpoint between", ...) into its own token via the
|
|
309
|
+
* `phrases` field below, instead of claiming the leading word alone. The
|
|
310
|
+
* bare word then never becomes its own token type, it stays a plain
|
|
311
|
+
* IDENT (usable as a variable) unless immediately followed by its
|
|
312
|
+
* qualifying keyword. `clamp` is the one exception, kept as a bare
|
|
313
|
+
* keyword: "clamp X between Y and Z" has the value X sitting between the
|
|
314
|
+
* trigger and "between"/"from", so the two words aren't adjacent and
|
|
315
|
+
* can't be phrase-fused. Same accepted risk profile as this codebase's
|
|
316
|
+
* existing bare "between"/"from"/"next"/"last"/"best" keywords.
|
|
317
|
+
*
|
|
318
|
+
* Most of the fused-trigger parselets are hand-written rather than built
|
|
319
|
+
* on `PhrasePattern`, for a related reason: once the leading keyword is
|
|
320
|
+
* fused away into the trigger token itself, the next thing in each
|
|
321
|
+
* grammar is an `expr` (the value), not a keyword, `definePhrasePattern`
|
|
322
|
+
* requires every alternative to start with a keyword slot. See
|
|
323
|
+
* `ClampParselet.ts`'s doc comment for the same structural point.
|
|
324
|
+
* `random number between X and Y` and `A is to B as C is to what` are the
|
|
325
|
+
* two exceptions that still have a genuine keyword after their own fused
|
|
326
|
+
* trigger ("between"/"as"), so `RandomNumberParselet` stays
|
|
327
|
+
* PhrasePattern-based.
|
|
328
|
+
*/
|
|
329
|
+
declare const MATHPHRASES_PACKAGE: IEnginePackage;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Money & finance phrase grammar: compound interest / investment growth,
|
|
333
|
+
* mortgage/loan repayment (standard amortization formula), sales tax/VAT
|
|
334
|
+
* add-and-remove, and CPI-based inflation-adjusted value. SoulverCore-
|
|
335
|
+
* inspired syntax where it could be confirmed (see each parselet's doc
|
|
336
|
+
* comment for exact worked examples and any deliberate deviations);
|
|
337
|
+
* function-call forms (`compoundInterest(...)`, `monthlyPayment(...)`,
|
|
338
|
+
* `taxAdd(...)`, `inflationAdjust(...)`, ...) are registered separately,
|
|
339
|
+
* in FUNCTION_PACKAGE's shared FUNC dispatch (see
|
|
340
|
+
* `packages/function/parselets/FunctionCallParselet.ts`'s
|
|
341
|
+
* `builtinNameToIndex` map) rather than here.
|
|
342
|
+
*
|
|
343
|
+
* TRIGGER-WORD COLLISION DESIGN NOTE (same regression class documented in
|
|
344
|
+
* MathPhrasesPackage.ts, and explicitly called out for this package
|
|
345
|
+
* up-front): "interest", "tax", "principal", "payment", "rate", "balance",
|
|
346
|
+
* "what", "worth", "value" are all common, plausible variable names, a
|
|
347
|
+
* shipped playground example already uses `:tax` (`:total = :subtotal +
|
|
348
|
+
* :tax`, see MathPhrasesPackage.ts's doc comment). None of those words are
|
|
349
|
+
* bare keywords anywhere in this package. Every trigger is either:
|
|
350
|
+
* - a full phrase fused via `phrases` below ("interest on", "tax on",
|
|
351
|
+
* "monthly repayment on", "what is", "what was", "value of", "worth
|
|
352
|
+
* in", ...), so the leading word alone never becomes its own token
|
|
353
|
+
* type and stays usable as `:interest`/`:tax`/`:what`/`:value`/etc., or
|
|
354
|
+
* - a genuine preposition ("over", "at") with near-zero plausibility as a
|
|
355
|
+
* variable name, the same accepted-risk category as this codebase's
|
|
356
|
+
* existing bare "between"/"from"/"next"/"last"/"best" keywords (see
|
|
357
|
+
* Token.ts's OVER/RATE_AT doc comment).
|
|
358
|
+
*
|
|
359
|
+
* Inflation-adjusted value (extends this package, see
|
|
360
|
+
* `parselets/InflationQueryParselet.ts`/`InflationFutureValueParselet.ts`/
|
|
361
|
+
* `InYearDollarsParselet.ts` and `data/CpiTable.ts` for the bundled,
|
|
362
|
+
* clearly-labeled-approximate CPI-U table and its doc comment on
|
|
363
|
+
* vintage/accuracy) was the one topic explicitly deferred from this
|
|
364
|
+
* package's original scope, now implemented.
|
|
365
|
+
*/
|
|
366
|
+
declare const FINANCE_PACKAGE: IEnginePackage;
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Weather lookups through Open-Meteo, a keyless public endpoint.
|
|
370
|
+
*
|
|
371
|
+
* The one built-in package that reaches the network. It needs no configuration,
|
|
372
|
+
* which is why it can be a default where stocks and knowledge cannot, but a
|
|
373
|
+
* host wanting no outbound traffic should assemble its own package list rather
|
|
374
|
+
* than using {@link BUILTIN_PACKAGES}.
|
|
375
|
+
*/
|
|
376
|
+
declare const WEATHER_PACKAGE: IEnginePackage;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Current conditions for one place, as returned by Open-Meteo.
|
|
380
|
+
*
|
|
381
|
+
* Temperatures are Celsius at this layer; conversion to the display unit
|
|
382
|
+
* happens later, so the shape stays independent of formatting settings.
|
|
383
|
+
*/
|
|
384
|
+
interface CityWeather {
|
|
385
|
+
/** The resolved place name Open-Meteo matched, e.g. "London" for input "london". */
|
|
386
|
+
resolvedName: string;
|
|
387
|
+
/** WMO weather code. See WmoWeatherCodes.ts. */
|
|
388
|
+
weatherCode: number;
|
|
389
|
+
/** Human-readable description derived from weatherCode, e.g. "overcast". */
|
|
390
|
+
description: string;
|
|
391
|
+
/** Current temperature, Celsius. */
|
|
392
|
+
temperature: number;
|
|
393
|
+
/** "Feels like" temperature, Celsius. */
|
|
394
|
+
apparentTemperature: number;
|
|
395
|
+
/** Today's forecast high, Celsius. */
|
|
396
|
+
high: number;
|
|
397
|
+
/** Today's forecast low, Celsius. */
|
|
398
|
+
low: number;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** The 5 SoulverCore-documented weather query kinds, encoded as the first
|
|
402
|
+
* segment of the query string this package's single async resolver caches
|
|
403
|
+
* on (see WeatherPackage.ts's `WEATHER_FN_IDX` / `createQueryResolver` call
|
|
404
|
+
*, one resolver, one plugin function, kind+city both folded into the
|
|
405
|
+
* query string it scans for). */
|
|
406
|
+
type WeatherQueryKind = "current" | "temperature" | "feelslike" | "high" | "low";
|
|
407
|
+
|
|
408
|
+
/** A current stock quote, as returned by a host-supplied `fetchQuote`. */
|
|
409
|
+
interface StockQuote {
|
|
410
|
+
/** Current price, in `currency` (default "USD"). */
|
|
411
|
+
price: number;
|
|
412
|
+
/** ISO 4217 currency code. Defaults to "USD" if omitted. */
|
|
413
|
+
currency?: string;
|
|
414
|
+
}
|
|
415
|
+
/** A historical stock quote for one calendar date, as returned by a host-supplied `fetchHistoricalQuote`. */
|
|
416
|
+
interface StockHistoricalQuote {
|
|
417
|
+
/** Closing price on the requested date, in `currency` (default "USD"). */
|
|
418
|
+
close: number;
|
|
419
|
+
/** Trading volume (share count) on the requested date, if available. */
|
|
420
|
+
volume?: number;
|
|
421
|
+
/** ISO 4217 currency code. Defaults to "USD" if omitted. */
|
|
422
|
+
currency?: string;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Configuration for {@link createStocksPackage}. See `StocksPackage.ts`'s
|
|
426
|
+
* module doc for the full "bring your own data source" rationale.
|
|
427
|
+
*/
|
|
428
|
+
interface StocksPackageConfig {
|
|
429
|
+
/**
|
|
430
|
+
* Fetch the current quote for `ticker` (already upper-cased). Required
|
|
431
|
+
* for `stock(TICKER)` / `N stock(TICKER)` to return real data, when
|
|
432
|
+
* omitted, those expressions resolve to an honest
|
|
433
|
+
* `STOCKS_NOT_CONFIGURED` error `Value`, never a faked/zero price.
|
|
434
|
+
*/
|
|
435
|
+
fetchQuote?: (ticker: string, signal: AbortSignal) => Promise<StockQuote>;
|
|
436
|
+
/**
|
|
437
|
+
* Fetch a historical quote for `ticker` on `isoDate` (`YYYY-MM-DD`).
|
|
438
|
+
* Required for the `on <date>` / `close on <date>` / `volume on <date>`
|
|
439
|
+
* forms, when omitted, those expressions resolve to an honest
|
|
440
|
+
* `STOCKS_NOT_CONFIGURED` error `Value`.
|
|
441
|
+
*/
|
|
442
|
+
fetchHistoricalQuote?: (ticker: string, isoDate: string, signal: AbortSignal) => Promise<StockHistoricalQuote>;
|
|
443
|
+
/**
|
|
444
|
+
* Enable the bare-ticker grammar (`AAPL` alone, no `stock(...)`
|
|
445
|
+
* wrapper) for the small bundled allow-list in `MajorTickers.ts`.
|
|
446
|
+
* Default `false`, a bare all-caps word is genuinely ambiguous with a
|
|
447
|
+
* variable name (`:AAPL = 5`), so this is opt-in even though the
|
|
448
|
+
* package itself is already opt-in. The `stock(TICKER)` function-call
|
|
449
|
+
* form works regardless of this setting and is the only ALWAYS-
|
|
450
|
+
* reachable syntax. See StocksPackage.ts's module doc.
|
|
451
|
+
*/
|
|
452
|
+
enableBareTickerRecognition?: boolean;
|
|
453
|
+
/**
|
|
454
|
+
* TanStack Query staleTime for CURRENT-price lookups, in ms. Default 60s
|
|
455
|
+
*, intraday quotes move continuously, so a short stale window keeps
|
|
456
|
+
* re-evaluation reasonably fresh without re-fetching on every keystroke.
|
|
457
|
+
*/
|
|
458
|
+
staleTimeMs?: number;
|
|
459
|
+
/**
|
|
460
|
+
* TanStack Query staleTime for HISTORICAL (`on <date>`) lookups, in ms.
|
|
461
|
+
* Default 30 days, a closing price for a specific past date is
|
|
462
|
+
* immutable, so this is set long purely to avoid pointless repeat
|
|
463
|
+
* fetches, not because the data could go stale.
|
|
464
|
+
*/
|
|
465
|
+
historicalStaleTimeMs?: number;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Live stock prices, `stock(TICKER)`, `stock(TICKER) on <date>`
|
|
470
|
+
* `stock(TICKER) close on <date>`, `stock(TICKER) volume on <date>`, plus
|
|
471
|
+
* an opt-in bare-ticker form (`AAPL`, `AAPL on April 12, 2005`, ...).
|
|
472
|
+
*
|
|
473
|
+
* **Why a factory, not a constant `STOCKS_PACKAGE` export**: unlike
|
|
474
|
+
* Weather's Open-Meteo, there is no free/keyless stock-quote API, every
|
|
475
|
+
* option surveyed (Alpha Vantage, Finnhub, Twelve Data, IEX Cloud, ...)
|
|
476
|
+
* requires the HOST application to sign up for its own API key. Baking in
|
|
477
|
+
* a specific paid provider (or worse, a hardcoded key) would either not
|
|
478
|
+
* work out of the box for most hosts or silently commit them to a vendor
|
|
479
|
+
* choice they didn't make. Instead this package is an extension point
|
|
480
|
+
* "packages are our approach, we're providing an SDK", a host supplies
|
|
481
|
+
* `fetchQuote`/`fetchHistoricalQuote` (backed by whichever provider and
|
|
482
|
+
* key THEY have) via {@link createStocksPackage}'s `config` argument. No
|
|
483
|
+
* config -> every stock expression resolves to a clearly-worded
|
|
484
|
+
* `STOCKS_NOT_CONFIGURED` error `Value`, never a faked or zero price (see
|
|
485
|
+
* `packages/finance/parselets/SalesTaxParselet.ts`'s doc comment for the
|
|
486
|
+
* same "never guess a number the caller didn't provide" principle applied
|
|
487
|
+
* to a different package).
|
|
488
|
+
*
|
|
489
|
+
* **Not a member of `BUILTIN_PACKAGES`** (see `packages/builtins.ts`)
|
|
490
|
+
* unconfigured, this package does nothing useful, exactly like
|
|
491
|
+
* `examples/osrs` is deliberately excluded from the built-in set. A host
|
|
492
|
+
* that wants it calls `createStocksPackage({ fetchQuote, ... })` and adds
|
|
493
|
+
* the result to their `ExpressionEngine`'s `packages` array themselves.
|
|
494
|
+
*
|
|
495
|
+
* **Ticker recognition**: the function-call form `stock(TICKER)` is the
|
|
496
|
+
* PRIMARY, always-reachable syntax, a bare all-caps word ("AAPL") is
|
|
497
|
+
* genuinely ambiguous with a variable name (`:AAPL = 5` is a reasonable
|
|
498
|
+
* thing to write), so it is never claimed unconditionally. The bare form
|
|
499
|
+
* is available only via `config.enableBareTickerRecognition`, gated to a
|
|
500
|
+
* small bundled allow-list of major tickers (`MajorTickers.ts`). See
|
|
501
|
+
* `normalizer/StockTickerNormalizerRule.ts`'s doc comment for the full
|
|
502
|
+
* reasoning, mirroring `time/timezones/CityZones.ts`'s known-table
|
|
503
|
+
* mitigation for the same class of ambiguity.
|
|
504
|
+
*
|
|
505
|
+
* **Two separate async resolvers** (`stocks-current`/`stocks-historical`,
|
|
506
|
+
* two distinct `CALL_PLUGIN` indices) rather than one shared one, unlike
|
|
507
|
+
* Weather's single shared resolver, current-price and historical-close
|
|
508
|
+
* lookups warrant genuinely different `staleTimeMs` (a live quote goes
|
|
509
|
+
* stale in seconds; a historical close for a fixed past date never goes
|
|
510
|
+
* stale at all), and `createQueryResolver` bakes `staleTimeMs` into the
|
|
511
|
+
* resolver instance, not the per-call query.
|
|
512
|
+
*/
|
|
513
|
+
declare function createStocksPackage(config?: StocksPackageConfig): IEnginePackage;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Configuration for {@link createKnowledgePackage}. See
|
|
517
|
+
* `KnowledgePackage.ts`'s module doc for the "bring your own answer
|
|
518
|
+
* engine" rationale (same pluggable-provider approach as `packages/stocks`).
|
|
519
|
+
*/
|
|
520
|
+
interface KnowledgePackageConfig {
|
|
521
|
+
/**
|
|
522
|
+
* Answer a free-text query verbatim (e.g. "distance to the moon",
|
|
523
|
+
* captured from `distance to the moon = ?`) and return a plain-text
|
|
524
|
+
* answer string. Required for `<query> = ?` to return real data, when
|
|
525
|
+
* omitted, that expression resolves to an honest `KNOWLEDGE_NOT_CONFIGURED`
|
|
526
|
+
* error `Value`, never a hallucinated/guessed answer.
|
|
527
|
+
*/
|
|
528
|
+
answerQuery?: (query: string, signal: AbortSignal) => Promise<string>;
|
|
529
|
+
/**
|
|
530
|
+
* TanStack Query staleTime for answered queries, in ms. Default 5
|
|
531
|
+
* minutes (matches `createQueryResolver`'s own default), most
|
|
532
|
+
* knowledge-style facts ("distance to the moon") don't change
|
|
533
|
+
* meaningfully within a session, but a short-ish default avoids
|
|
534
|
+
* treating a genuinely time-sensitive answer (e.g. "population of
|
|
535
|
+
* Tokyo = ?") as permanently fixed.
|
|
536
|
+
*/
|
|
537
|
+
staleTimeMs?: number;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Knowledge-assistant queries, open-ended questions answered by a
|
|
542
|
+
* host-supplied provider. Two supported surface forms, both producing the
|
|
543
|
+
* exact same `KNOWLEDGE_QUERY` token/behavior (see the two
|
|
544
|
+
* `rawLinePatterns` entries below):
|
|
545
|
+
*
|
|
546
|
+
* - **`search: <query>` / `ask: <query>` / `google: <query>`** (preferred,
|
|
547
|
+
* added this iteration), a clear, self-documenting leading verb, e.g.
|
|
548
|
+
* `search: distance to the moon`. Reads like an instruction, not a
|
|
549
|
+
* cryptic punctuation puzzle.
|
|
550
|
+
* - **`<query> = ?`** (the original form, kept for Calca-style
|
|
551
|
+
* compatibility. see the internal parity notes)
|
|
552
|
+
* e.g. `distance to the moon = ?`. Less discoverable (a bare trailing
|
|
553
|
+
* `= ?` doesn't read as "ask a question" the way a leading verb does),
|
|
554
|
+
* but harmless to keep alongside the clearer form. This package has no
|
|
555
|
+
* opinion about which one a host's users end up preferring.
|
|
556
|
+
*
|
|
557
|
+
* SoulverCore's own version of this feature calls out to Wolfram|Alpha;
|
|
558
|
+
* there is no free equivalent of comparable quality, so. Same
|
|
559
|
+
* pluggable-provider approach as `packages/stocks`, a host supplies
|
|
560
|
+
* `answerQuery` via {@link createKnowledgePackage}'s `config` argument. No
|
|
561
|
+
* config -> every query resolves to a clearly-worded
|
|
562
|
+
* `KNOWLEDGE_NOT_CONFIGURED` error `Value`, never a hallucinated/guessed
|
|
563
|
+
* answer.
|
|
564
|
+
*
|
|
565
|
+
* **Not a member of `BUILTIN_PACKAGES`**, unconfigured, this package does
|
|
566
|
+
* nothing useful, exactly like `packages/stocks` and `examples/osrs`.
|
|
567
|
+
*
|
|
568
|
+
* ## Why this package is architecturally different from every other one
|
|
569
|
+
*
|
|
570
|
+
* Every other package in this codebase (including its sibling
|
|
571
|
+
* `weather`/`stocks`) is "structured syntax evaluates to a value", the
|
|
572
|
+
* grammar is known in advance, and the lexer/parser tokenize it like any
|
|
573
|
+
* other expression. This package's grammar is "arbitrary free text,
|
|
574
|
+
* terminated (or introduced) by a fixed marker, gets shipped to an
|
|
575
|
+
* external function verbatim", `distance to the moon` is not valid Solve
|
|
576
|
+
* syntax (it would never parse as arithmetic), so it can't be
|
|
577
|
+
* tokenized-then-parsed the normal way at all.
|
|
578
|
+
*
|
|
579
|
+
* The fix lives one layer below the parser: `ExpressionLexer.ts` gained a
|
|
580
|
+
* new, generic extension point, `LexerVocabulary.rawLinePatterns` (see
|
|
581
|
+
* its doc comment there for the full design). A `rawLinePatterns` rule
|
|
582
|
+
* tests the RAW line text, before any per-character tokenization, and
|
|
583
|
+
* if it matches, the whole line becomes ONE synthetic token whose value
|
|
584
|
+
* is the matched capture group, verbatim. This package is that
|
|
585
|
+
* mechanism's reference/motivating use.
|
|
586
|
+
*
|
|
587
|
+
* **Why `search:`/`ask:`/`google:` require a literal trailing colon, not
|
|
588
|
+
* just a following space**: without it, `search 5` (a line reading the
|
|
589
|
+
* plain variable `search`, legitimately assignable via `:search = 5`
|
|
590
|
+
* since these are ordinary lowercase words, not reserved, followed by
|
|
591
|
+
* what would otherwise be implicit-multiply-adjacent text) would be
|
|
592
|
+
* silently hijacked into a knowledge query for `"5"` instead of failing
|
|
593
|
+
* or reading the variable. Requiring `:` immediately after the keyword
|
|
594
|
+
* (`search:`, not `search `) is not valid syntax ANYWHERE else in this
|
|
595
|
+
* grammar, so it introduces zero ambiguity with a real `:name = value`
|
|
596
|
+
* variable of the same name. See the regression test guarding this
|
|
597
|
+
* exact scenario.
|
|
598
|
+
*
|
|
599
|
+
* No existing Solve syntax uses a bare `= ?` marker either (the
|
|
600
|
+
* codebase's other "possibilities" feature, `cm to ?`, is a different
|
|
601
|
+
* token shape, `TO QUESTION`, not `EQUALS QUESTION`. See
|
|
602
|
+
* `packages/uom/normalizer/PossibilitiesNormalizerRule.ts`), so neither
|
|
603
|
+
* form claims any ambiguity with existing grammar; both only activate for
|
|
604
|
+
* lines a host has opted into via this package in the first place.
|
|
605
|
+
*/
|
|
606
|
+
declare function createKnowledgePackage(config?: KnowledgePackageConfig): IEnginePackage;
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Cross-line data access, reading another line's cached result from
|
|
610
|
+
* inside an expression. Confirmed by FOUR independent competitor apps
|
|
611
|
+
* wanting the exact same underlying capability (Numi's `prev`, Notes
|
|
612
|
+
* Calculator's `line<N>`, Numbr's `sum`/`total`-to-header, NumPad's
|
|
613
|
+
* `line<N>` plus range aggregation). See the internal parity notes'
|
|
614
|
+
* "Confirmed engine limitations" item 1, now closed.
|
|
615
|
+
*
|
|
616
|
+
* Built entirely on `vm/VM.ts`'s `LineExecutionContext`, threaded
|
|
617
|
+
* optionally through `CALL_PLUGIN`, every handler here explicitly checks
|
|
618
|
+
* for `Pending`/`Error`/unevaluated lines before doing arithmetic (see
|
|
619
|
+
* `LinesPluginFunctions.ts`'s module doc) rather than silently coercing
|
|
620
|
+
* via `.toNumber()` (which returns `0` for both `Pending` and `Error`).
|
|
621
|
+
*
|
|
622
|
+
* Trigger-word collision decisions (this codebase's established
|
|
623
|
+
* phrase-fusion-vs-bare-keyword policy, see `ARCHITECTURE.md` §5.1):
|
|
624
|
+
* - `prev`, bare keyword (nothing to phrase-fuse against, same shape as
|
|
625
|
+
* `clamp`). Accepted risk.
|
|
626
|
+
* - `line1`/`line 1`, normalizer-fused into `LINE_REF`, never claims
|
|
627
|
+
* bare `line` as a keyword (`:line = 5` stays untouched). The `l1`/`l 1`
|
|
628
|
+
* short alias documented by some competitors is deliberately NOT
|
|
629
|
+
* implemented in this pass, `l` is too common a variable name; ship
|
|
630
|
+
* `line<N>` first, add a narrower `l<N>` form later if real usage wants
|
|
631
|
+
* it.
|
|
632
|
+
* - `sum(`/`total(`/`average(`, normalizer-fused ONLY when immediately
|
|
633
|
+
* followed by `LPAREN`, so `:sum = 100` and MathPhrases' existing
|
|
634
|
+
* `"total of X, Y"` phrase (no paren after "of") are both unaffected.
|
|
635
|
+
* - "aggregate everything above until a blank line/heading"
|
|
636
|
+
* phrase-fused as `"total above"`/`"sum above"`/`"average above"`
|
|
637
|
+
* (deliberately NOT Numi/Numbr's bare `total`/`sum` wording, that's
|
|
638
|
+
* exactly the bare-keyword collision class this codebase already
|
|
639
|
+
* regressed on once, see `MathPhrasesPackage.ts`'s "total" note).
|
|
640
|
+
*/
|
|
641
|
+
declare const LINES_PACKAGE: IEnginePackage;
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Built-in packages.
|
|
645
|
+
*
|
|
646
|
+
* Each domain is a self-contained package (its own directory, its own
|
|
647
|
+
* `{Domain}Package.ts` defining an IEnginePackage, its own `index.ts`
|
|
648
|
+
* barrel), the same shape as third-party packages such as the OSRS
|
|
649
|
+
* example in `src/solve-js/examples/osrs/`. This file's only job is to
|
|
650
|
+
* assemble them into BUILTIN_PACKAGES; it re-exports each named package
|
|
651
|
+
* too, since existing call sites import them directly from here.
|
|
652
|
+
*
|
|
653
|
+
* This enables:
|
|
654
|
+
* - Selective disable of built-in packages
|
|
655
|
+
* - External packages to replace/extend built-in ones
|
|
656
|
+
*/
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* The packages an engine registers when the caller names none.
|
|
660
|
+
*
|
|
661
|
+
* Twenty of the twenty-two. Stocks and knowledge are excluded because both
|
|
662
|
+
* need a host-supplied data source and do nothing useful without one, so
|
|
663
|
+
* registering them by default would only produce NOT_CONFIGURED results.
|
|
664
|
+
*
|
|
665
|
+
* Pass a filtered copy to the {@link ExpressionEngine} constructor to opt out
|
|
666
|
+
* of a feature, or add to it to register your own alongside the built-ins.
|
|
667
|
+
*/
|
|
668
|
+
declare const BUILTIN_PACKAGES: IEnginePackage[];
|
|
669
|
+
|
|
670
|
+
/** A 2-component vector value, as produced by `vec2(x, y)`. */
|
|
671
|
+
interface IVector2 {
|
|
672
|
+
x: number;
|
|
673
|
+
y: number;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/** A 3-component vector value, as produced by `vec3(x, y, z)`. */
|
|
677
|
+
interface IVector3 {
|
|
678
|
+
x: number;
|
|
679
|
+
y: number;
|
|
680
|
+
z: number;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/** A 4-component vector value, as produced by `vec4(x, y, z, w)`. */
|
|
684
|
+
interface IVector4 {
|
|
685
|
+
x: number;
|
|
686
|
+
y: number;
|
|
687
|
+
z: number;
|
|
688
|
+
w: number;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
export { ARITHMETIC_PACKAGE, BIGINT_PACKAGE, BUILTIN_PACKAGES, CONDITIONALS_PACKAGE, CONVERTERS_PACKAGE, CURRENCY_PACKAGE, type CityWeather, DATETIME_PACKAGE, DICE_PACKAGE, FINANCE_PACKAGE, FUNCTION_PACKAGE, type IVector2, type IVector3, type IVector4, type KnowledgePackageConfig, LINES_PACKAGE, MAPREDUCE_PACKAGE, MATHPHRASES_PACKAGE, MATRIX_PACKAGE, PERCENTAGE_PACKAGE, SYMBOLIC_PACKAGE, type StockHistoricalQuote, type StockQuote, type StocksPackageConfig, TIME_PACKAGE, UOM_PACKAGE, VARIABLES_PACKAGE, VECTOR_PACKAGE, WEATHER_PACKAGE, type WeatherQueryKind, createKnowledgePackage, createStocksPackage };
|