universal-physics-tensor 8.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/README.md +8 -6
  2. package/data/atlas/atlas.json +21 -21
  3. package/data/atlas/atlas.jsonld +1 -1
  4. package/data/atlas/diffusion.json +5 -5
  5. package/data/atlas/oscillators.json +7 -7
  6. package/data/atlas/waves.json +11 -11
  7. package/data/bridge-catalog.json +490 -338
  8. package/data/bridge-catalog.schema.json +566 -40
  9. package/data/quantities.json +230 -218
  10. package/data/quantities.schema.json +52 -0
  11. package/data/units.json +1149 -0
  12. package/data/units.schema.json +124 -0
  13. package/dist/atlas/association.d.ts +1 -1
  14. package/dist/atlas/benchmark/hybrid-retrieval.d.ts.map +1 -1
  15. package/dist/atlas/benchmark/hybrid-retrieval.js +2 -5
  16. package/dist/atlas/benchmark/hybrid-retrieval.js.map +1 -1
  17. package/dist/atlas/physjs-entries.generated.d.ts +1601 -220
  18. package/dist/atlas/physjs-entries.generated.d.ts.map +1 -1
  19. package/dist/atlas/physjs-entries.generated.js +1854 -345
  20. package/dist/atlas/physjs-entries.generated.js.map +1 -1
  21. package/dist/atlas/physjs-ref.d.ts +89 -89
  22. package/dist/atlas/physjs-ref.d.ts.map +1 -1
  23. package/dist/atlas/physjs-ref.js +128 -176
  24. package/dist/atlas/physjs-ref.js.map +1 -1
  25. package/dist/atlas/proof-target.d.ts +16 -8
  26. package/dist/atlas/proof-target.d.ts.map +1 -1
  27. package/dist/atlas/proof-target.js +34 -31
  28. package/dist/atlas/proof-target.js.map +1 -1
  29. package/dist/bridges/catalog-adapter.d.ts.map +1 -1
  30. package/dist/bridges/catalog-adapter.js +5 -5
  31. package/dist/bridges/catalog-adapter.js.map +1 -1
  32. package/dist/bridges/catalog-load.d.ts +7 -0
  33. package/dist/bridges/catalog-load.d.ts.map +1 -1
  34. package/dist/bridges/catalog-load.js +69 -13
  35. package/dist/bridges/catalog-load.js.map +1 -1
  36. package/dist/bridges/catalog-types.d.ts +51 -6
  37. package/dist/bridges/catalog-types.d.ts.map +1 -1
  38. package/dist/bridges/evaluation-errors.d.ts +76 -0
  39. package/dist/bridges/evaluation-errors.d.ts.map +1 -0
  40. package/dist/bridges/evaluation-errors.js +118 -0
  41. package/dist/bridges/evaluation-errors.js.map +1 -0
  42. package/dist/bridges/evaluator-inputs.d.ts +5 -3
  43. package/dist/bridges/evaluator-inputs.d.ts.map +1 -1
  44. package/dist/bridges/evaluator-inputs.js +24 -24
  45. package/dist/bridges/evaluator-inputs.js.map +1 -1
  46. package/dist/bridges/evaluators.d.ts +32 -7
  47. package/dist/bridges/evaluators.d.ts.map +1 -1
  48. package/dist/bridges/evaluators.js +131 -29
  49. package/dist/bridges/evaluators.js.map +1 -1
  50. package/dist/bridges/expr-parse.d.ts +11 -3
  51. package/dist/bridges/expr-parse.d.ts.map +1 -1
  52. package/dist/bridges/expr-parse.js +46 -153
  53. package/dist/bridges/expr-parse.js.map +1 -1
  54. package/dist/bridges/holds.d.ts +11 -7
  55. package/dist/bridges/holds.d.ts.map +1 -1
  56. package/dist/bridges/holds.js +113 -234
  57. package/dist/bridges/holds.js.map +1 -1
  58. package/dist/bridges/input-contract.d.ts +65 -0
  59. package/dist/bridges/input-contract.d.ts.map +1 -0
  60. package/dist/bridges/input-contract.js +97 -0
  61. package/dist/bridges/input-contract.js.map +1 -0
  62. package/dist/bridges/notices.d.ts +11 -0
  63. package/dist/bridges/notices.d.ts.map +1 -0
  64. package/dist/bridges/notices.js +22 -0
  65. package/dist/bridges/notices.js.map +1 -0
  66. package/dist/canonical/canonical-equation.d.ts +31 -0
  67. package/dist/canonical/canonical-equation.d.ts.map +1 -1
  68. package/dist/canonical/entries/atomic.d.ts.map +1 -1
  69. package/dist/canonical/entries/atomic.js +11 -1
  70. package/dist/canonical/entries/atomic.js.map +1 -1
  71. package/dist/canonical/entries/condensed-matter.d.ts.map +1 -1
  72. package/dist/canonical/entries/condensed-matter.js +3 -0
  73. package/dist/canonical/entries/condensed-matter.js.map +1 -1
  74. package/dist/canonical/entries/dimensional-classics.d.ts.map +1 -1
  75. package/dist/canonical/entries/dimensional-classics.js +48 -0
  76. package/dist/canonical/entries/dimensional-classics.js.map +1 -1
  77. package/dist/canonical/entries/electromagnetism.d.ts.map +1 -1
  78. package/dist/canonical/entries/electromagnetism.js +30 -0
  79. package/dist/canonical/entries/electromagnetism.js.map +1 -1
  80. package/dist/canonical/entries/fluids-waves.d.ts.map +1 -1
  81. package/dist/canonical/entries/fluids-waves.js +34 -0
  82. package/dist/canonical/entries/fluids-waves.js.map +1 -1
  83. package/dist/canonical/entries/mechanics.d.ts.map +1 -1
  84. package/dist/canonical/entries/mechanics.js +24 -0
  85. package/dist/canonical/entries/mechanics.js.map +1 -1
  86. package/dist/canonical/entries/nonmonomial.d.ts.map +1 -1
  87. package/dist/canonical/entries/nonmonomial.js +15 -4
  88. package/dist/canonical/entries/nonmonomial.js.map +1 -1
  89. package/dist/canonical/entries/relativity.d.ts.map +1 -1
  90. package/dist/canonical/entries/relativity.js +6 -0
  91. package/dist/canonical/entries/relativity.js.map +1 -1
  92. package/dist/canonical/entries/statistical-mechanics.d.ts.map +1 -1
  93. package/dist/canonical/entries/statistical-mechanics.js +19 -0
  94. package/dist/canonical/entries/statistical-mechanics.js.map +1 -1
  95. package/dist/canonical/entries/thermo-nuclear-cosmo.d.ts.map +1 -1
  96. package/dist/canonical/entries/thermo-nuclear-cosmo.js +15 -0
  97. package/dist/canonical/entries/thermo-nuclear-cosmo.js.map +1 -1
  98. package/dist/cases/index.d.ts +9 -2
  99. package/dist/cases/index.d.ts.map +1 -1
  100. package/dist/cases/index.js +26 -7
  101. package/dist/cases/index.js.map +1 -1
  102. package/dist/cases/kepler-rv.js +6 -6
  103. package/dist/cases/kepler-rv.js.map +1 -1
  104. package/dist/cli/commands/_discovery-opts.d.ts +2 -1
  105. package/dist/cli/commands/_discovery-opts.d.ts.map +1 -1
  106. package/dist/cli/commands/_discovery-opts.js +7 -12
  107. package/dist/cli/commands/_discovery-opts.js.map +1 -1
  108. package/dist/cli/commands/atlas.d.ts.map +1 -1
  109. package/dist/cli/commands/atlas.js +6 -9
  110. package/dist/cli/commands/atlas.js.map +1 -1
  111. package/dist/cli/commands/audit.d.ts.map +1 -1
  112. package/dist/cli/commands/audit.js +1 -2
  113. package/dist/cli/commands/audit.js.map +1 -1
  114. package/dist/cli/commands/connectors.d.ts.map +1 -1
  115. package/dist/cli/commands/connectors.js +8 -9
  116. package/dist/cli/commands/connectors.js.map +1 -1
  117. package/dist/cli/commands/derive.js +9 -10
  118. package/dist/cli/commands/derive.js.map +1 -1
  119. package/dist/cli/commands/discover.d.ts.map +1 -1
  120. package/dist/cli/commands/discover.js +3 -4
  121. package/dist/cli/commands/discover.js.map +1 -1
  122. package/dist/cli/commands/eval.d.ts.map +1 -1
  123. package/dist/cli/commands/eval.js +17 -17
  124. package/dist/cli/commands/eval.js.map +1 -1
  125. package/dist/cli/commands/evaluate.d.ts +1 -35
  126. package/dist/cli/commands/evaluate.d.ts.map +1 -1
  127. package/dist/cli/commands/evaluate.js +56 -187
  128. package/dist/cli/commands/evaluate.js.map +1 -1
  129. package/dist/cli/commands/explain.d.ts.map +1 -1
  130. package/dist/cli/commands/explain.js +43 -38
  131. package/dist/cli/commands/explain.js.map +1 -1
  132. package/dist/cli/commands/ground.js +1 -1
  133. package/dist/cli/commands/ground.js.map +1 -1
  134. package/dist/cli/commands/map.js +3 -4
  135. package/dist/cli/commands/map.js.map +1 -1
  136. package/dist/cli/commands/metric.d.ts.map +1 -1
  137. package/dist/cli/commands/metric.js +3 -0
  138. package/dist/cli/commands/metric.js.map +1 -1
  139. package/dist/cli/commands/regime.js +1 -1
  140. package/dist/cli/commands/regime.js.map +1 -1
  141. package/dist/cli/commands/symbolic.d.ts.map +1 -1
  142. package/dist/cli/commands/symbolic.js +5 -2
  143. package/dist/cli/commands/symbolic.js.map +1 -1
  144. package/dist/cli/commands/testplan.js +3 -3
  145. package/dist/cli/commands/testplan.js.map +1 -1
  146. package/dist/cli/conventions.d.ts +6 -7
  147. package/dist/cli/conventions.d.ts.map +1 -1
  148. package/dist/cli/conventions.js +19 -28
  149. package/dist/cli/conventions.js.map +1 -1
  150. package/dist/cli/euler-guard.d.ts +13 -2
  151. package/dist/cli/euler-guard.d.ts.map +1 -1
  152. package/dist/cli/euler-guard.js +17 -3
  153. package/dist/cli/euler-guard.js.map +1 -1
  154. package/dist/cli/eval-numbers.d.ts +4 -9
  155. package/dist/cli/eval-numbers.d.ts.map +1 -1
  156. package/dist/cli/eval-numbers.js +11 -41
  157. package/dist/cli/eval-numbers.js.map +1 -1
  158. package/dist/cli/published-url.d.ts +2 -0
  159. package/dist/cli/published-url.d.ts.map +1 -1
  160. package/dist/cli/published-url.js +5 -0
  161. package/dist/cli/published-url.js.map +1 -1
  162. package/dist/cli/record-tables.d.ts +2 -1
  163. package/dist/cli/record-tables.d.ts.map +1 -1
  164. package/dist/cli/record-tables.js +8 -3
  165. package/dist/cli/record-tables.js.map +1 -1
  166. package/dist/cli-api.d.ts +45 -12
  167. package/dist/cli-api.d.ts.map +1 -1
  168. package/dist/cli-api.js +38 -11
  169. package/dist/cli-api.js.map +1 -1
  170. package/dist/composition/adjudication.d.ts +8 -30
  171. package/dist/composition/adjudication.d.ts.map +1 -1
  172. package/dist/composition/adjudication.js +15 -67
  173. package/dist/composition/adjudication.js.map +1 -1
  174. package/dist/composition/aliases.d.ts +1 -1
  175. package/dist/composition/aliases.d.ts.map +1 -1
  176. package/dist/composition/aliases.js +10 -20
  177. package/dist/composition/aliases.js.map +1 -1
  178. package/dist/composition/bridge-analysis.d.ts +4 -0
  179. package/dist/composition/bridge-analysis.d.ts.map +1 -1
  180. package/dist/composition/bridge-analysis.js +13 -14
  181. package/dist/composition/bridge-analysis.js.map +1 -1
  182. package/dist/composition/canonical-graph.d.ts +7 -9
  183. package/dist/composition/canonical-graph.d.ts.map +1 -1
  184. package/dist/composition/canonical-graph.js +35 -19
  185. package/dist/composition/canonical-graph.js.map +1 -1
  186. package/dist/composition/canonical-prefactors.d.ts +10 -29
  187. package/dist/composition/canonical-prefactors.d.ts.map +1 -1
  188. package/dist/composition/canonical-prefactors.js +15 -202
  189. package/dist/composition/canonical-prefactors.js.map +1 -1
  190. package/dist/composition/compose.js +2 -1
  191. package/dist/composition/compose.js.map +1 -1
  192. package/dist/composition/discovery.d.ts +50 -0
  193. package/dist/composition/discovery.d.ts.map +1 -1
  194. package/dist/composition/discovery.js +2 -2
  195. package/dist/composition/discovery.js.map +1 -1
  196. package/dist/composition/edge.d.ts +0 -14
  197. package/dist/composition/edge.d.ts.map +1 -1
  198. package/dist/composition/edge.js +1 -17
  199. package/dist/composition/edge.js.map +1 -1
  200. package/dist/composition/evaluate-relation.d.ts +29 -5
  201. package/dist/composition/evaluate-relation.d.ts.map +1 -1
  202. package/dist/composition/evaluate-relation.js +100 -72
  203. package/dist/composition/evaluate-relation.js.map +1 -1
  204. package/dist/composition/explain.d.ts +5 -0
  205. package/dist/composition/explain.d.ts.map +1 -1
  206. package/dist/composition/explain.js +9 -8
  207. package/dist/composition/explain.js.map +1 -1
  208. package/dist/composition/expr-eval.d.ts.map +1 -1
  209. package/dist/composition/expr-eval.js +2 -1
  210. package/dist/composition/expr-eval.js.map +1 -1
  211. package/dist/composition/index.d.ts +3 -1
  212. package/dist/composition/index.d.ts.map +1 -1
  213. package/dist/composition/index.js +3 -1
  214. package/dist/composition/index.js.map +1 -1
  215. package/dist/composition/proposed-bridges.d.ts.map +1 -1
  216. package/dist/composition/proposed-bridges.js +3 -2
  217. package/dist/composition/proposed-bridges.js.map +1 -1
  218. package/dist/composition/retrodiction.d.ts +8 -0
  219. package/dist/composition/retrodiction.d.ts.map +1 -1
  220. package/dist/composition/retrodiction.js +5 -0
  221. package/dist/composition/retrodiction.js.map +1 -1
  222. package/dist/composition/user-equation.d.ts +11 -7
  223. package/dist/composition/user-equation.d.ts.map +1 -1
  224. package/dist/composition/user-equation.js +24 -26
  225. package/dist/composition/user-equation.js.map +1 -1
  226. package/dist/core/constants.d.ts +27 -4
  227. package/dist/core/constants.d.ts.map +1 -1
  228. package/dist/core/constants.js +38 -5
  229. package/dist/core/constants.js.map +1 -1
  230. package/dist/core/data-file.d.ts +27 -0
  231. package/dist/core/data-file.d.ts.map +1 -0
  232. package/dist/core/data-file.js +48 -0
  233. package/dist/core/data-file.js.map +1 -0
  234. package/dist/core/json-schema.d.ts +27 -0
  235. package/dist/core/json-schema.d.ts.map +1 -0
  236. package/dist/core/json-schema.js +153 -0
  237. package/dist/core/json-schema.js.map +1 -0
  238. package/dist/core/types.d.ts +3 -2
  239. package/dist/core/types.d.ts.map +1 -1
  240. package/dist/core/types.js +16 -14
  241. package/dist/core/types.js.map +1 -1
  242. package/dist/diff/bridge-ast-gradient.d.ts.map +1 -1
  243. package/dist/diff/bridge-ast-gradient.js +6 -17
  244. package/dist/diff/bridge-ast-gradient.js.map +1 -1
  245. package/dist/diff/bridge-specs.d.ts +2 -1
  246. package/dist/diff/bridge-specs.d.ts.map +1 -1
  247. package/dist/diff/bridge-specs.js +1 -1
  248. package/dist/diff/bridge-specs.js.map +1 -1
  249. package/dist/dimensional/bridge-check.d.ts.map +1 -1
  250. package/dist/dimensional/bridge-check.js +3 -5
  251. package/dist/dimensional/bridge-check.js.map +1 -1
  252. package/dist/dimensional/constant-rows.d.ts +54 -0
  253. package/dist/dimensional/constant-rows.d.ts.map +1 -0
  254. package/dist/dimensional/constant-rows.js +111 -0
  255. package/dist/dimensional/constant-rows.js.map +1 -0
  256. package/dist/dimensional/constants.d.ts +4 -13
  257. package/dist/dimensional/constants.d.ts.map +1 -1
  258. package/dist/dimensional/constants.js +11 -19
  259. package/dist/dimensional/constants.js.map +1 -1
  260. package/dist/dimensional/dimension-spec.d.ts +12 -3
  261. package/dist/dimensional/dimension-spec.d.ts.map +1 -1
  262. package/dist/dimensional/dimension-spec.js +114 -150
  263. package/dist/dimensional/dimension-spec.js.map +1 -1
  264. package/dist/dimensional/exact-scale.d.ts +79 -0
  265. package/dist/dimensional/exact-scale.d.ts.map +1 -0
  266. package/dist/dimensional/exact-scale.js +222 -0
  267. package/dist/dimensional/exact-scale.js.map +1 -0
  268. package/dist/dimensional/formula-names.d.ts +13 -12
  269. package/dist/dimensional/formula-names.d.ts.map +1 -1
  270. package/dist/dimensional/formula-names.js +28 -51
  271. package/dist/dimensional/formula-names.js.map +1 -1
  272. package/dist/dimensional/quantity-registry.d.ts +10 -1
  273. package/dist/dimensional/quantity-registry.d.ts.map +1 -1
  274. package/dist/dimensional/quantity-registry.js +45 -16
  275. package/dist/dimensional/quantity-registry.js.map +1 -1
  276. package/dist/dimensional/symbolic-constants.d.ts +63 -19
  277. package/dist/dimensional/symbolic-constants.d.ts.map +1 -1
  278. package/dist/dimensional/symbolic-constants.js +109 -92
  279. package/dist/dimensional/symbolic-constants.js.map +1 -1
  280. package/dist/dimensional/unit-data.d.ts +70 -0
  281. package/dist/dimensional/unit-data.d.ts.map +1 -0
  282. package/dist/dimensional/unit-data.js +135 -0
  283. package/dist/dimensional/unit-data.js.map +1 -0
  284. package/dist/dimensional/units.d.ts +87 -24
  285. package/dist/dimensional/units.d.ts.map +1 -1
  286. package/dist/dimensional/units.js +253 -276
  287. package/dist/dimensional/units.js.map +1 -1
  288. package/dist/index.d.ts +15 -13
  289. package/dist/index.d.ts.map +1 -1
  290. package/dist/index.js +7 -4
  291. package/dist/index.js.map +1 -1
  292. package/dist/numerical/binding-value.d.ts +21 -1
  293. package/dist/numerical/binding-value.d.ts.map +1 -1
  294. package/dist/numerical/binding-value.js +123 -118
  295. package/dist/numerical/binding-value.js.map +1 -1
  296. package/dist/numerical/evaluator-uncertainty.d.ts +34 -0
  297. package/dist/numerical/evaluator-uncertainty.d.ts.map +1 -0
  298. package/dist/numerical/evaluator-uncertainty.js +117 -0
  299. package/dist/numerical/evaluator-uncertainty.js.map +1 -0
  300. package/dist/numerical/formula-contract.d.ts +4 -0
  301. package/dist/numerical/formula-contract.d.ts.map +1 -1
  302. package/dist/numerical/formula-contract.js +7 -0
  303. package/dist/numerical/formula-contract.js.map +1 -1
  304. package/dist/numerical/formula-dimension.d.ts +9 -0
  305. package/dist/numerical/formula-dimension.d.ts.map +1 -1
  306. package/dist/numerical/formula-dimension.js +64 -10
  307. package/dist/numerical/formula-dimension.js.map +1 -1
  308. package/dist/numerical/formula-mathts.d.ts.map +1 -1
  309. package/dist/numerical/formula-mathts.js +6 -2
  310. package/dist/numerical/formula-mathts.js.map +1 -1
  311. package/dist/numerical/gl4-integrator.d.ts.map +1 -1
  312. package/dist/numerical/gl4-integrator.js +3 -3
  313. package/dist/numerical/gl4-integrator.js.map +1 -1
  314. package/dist/numerical/spacetime-metrics.d.ts +4 -0
  315. package/dist/numerical/spacetime-metrics.d.ts.map +1 -1
  316. package/dist/numerical/spacetime-metrics.js +34 -4
  317. package/dist/numerical/spacetime-metrics.js.map +1 -1
  318. package/dist/relations/types.d.ts +8 -1
  319. package/dist/relations/types.d.ts.map +1 -1
  320. package/dist/relations/types.js +10 -0
  321. package/dist/relations/types.js.map +1 -1
  322. package/package.json +1 -1
@@ -2,263 +2,142 @@
2
2
  * Interpreter for a catalog validity condition.
3
3
  *
4
4
  * A condition is a boolean expression over quantity names, the registered
5
- * constants, `finite`, and `integer`. It is not JavaScript `eval`.
5
+ * constants, `isFinite` and `isInteger`, written in MathTS's grammar
6
+ * (`and`, `or`, `not`, `<`, `<=`, `>`, `>=`, `==`, `!=`). MathTS parses it,
7
+ * and MathTS evaluates every arithmetic sub-expression. The comparisons and
8
+ * the logical operators are evaluated here, exactly: MathTS's own comparison
9
+ * operators are tolerance-based (`absTol` 1e-15), so under them `1e-18 > 0`
10
+ * is false, which no condition over SI magnitudes can accept.
11
+ *
12
+ * It is not JavaScript `eval`.
6
13
  *
7
14
  * @module bridges/holds
8
15
  */
16
+ import { parse as parseMathTs } from '@danielsimonjr/mathts-functions';
17
+ import { rewriteCatalogHyphens } from '../dimensional/hyphen-names.js';
18
+ /** A condition could not be evaluated: it names an unbound symbol, or its text does not parse. @internal */
9
19
  export class HoldsError extends Error {
10
20
  constructor(message) {
11
21
  super(message);
12
22
  this.name = 'HoldsError';
13
23
  }
14
24
  }
15
- const OPS = ['>=', '<=', '===', '!==', '==', '!=', '&&', '||', '>', '<', '!'];
16
- function tokenize(source) {
17
- const out = [];
18
- let i = 0;
19
- while (i < source.length) {
20
- const c = source[i];
21
- if (c === ' ' || c === '\n' || c === '\t' || c === '\r') {
22
- i += 1;
23
- continue;
24
- }
25
- if (c === '(') {
26
- out.push({ t: 'lp' });
27
- i += 1;
28
- continue;
29
- }
30
- if (c === ')') {
31
- out.push({ t: 'rp' });
32
- i += 1;
33
- continue;
34
- }
35
- const op = OPS.find((candidate) => source.startsWith(candidate, i));
36
- if (op !== undefined) {
37
- out.push({ t: 'op', v: op });
38
- i += op.length;
39
- continue;
40
- }
41
- if (c === '+' || c === '-' || c === '*' || c === '/' || c === '^') {
42
- out.push({ t: 'op', v: c });
43
- i += 1;
44
- continue;
25
+ const COMPARISONS = {
26
+ '<': (a, b) => a < b,
27
+ '<=': (a, b) => a <= b,
28
+ '>': (a, b) => a > b,
29
+ '>=': (a, b) => a >= b,
30
+ '==': (a, b) => a === b,
31
+ '!=': (a, b) => a !== b,
32
+ };
33
+ const PREDICATES = {
34
+ isFinite: (x) => Number.isFinite(x),
35
+ isInteger: (x) => Number.isInteger(x),
36
+ };
37
+ function functionName(node) {
38
+ return typeof node.fn === 'string' ? node.fn : (node.fn?.name ?? node.name ?? '');
39
+ }
40
+ /** Evaluate an arithmetic sub-tree through MathTS; the result must be a number. */
41
+ function arithmetic(node, source) {
42
+ return (scope) => {
43
+ let v;
44
+ try {
45
+ v = node.evaluate(scope);
45
46
  }
46
- if (/[0-9.]/.test(c)) {
47
- const m = /^[0-9]*\.?[0-9]+(?:[eE][+-]?[0-9]+)?/.exec(source.slice(i));
48
- if (m === null)
49
- throw new HoldsError(`bad number at ${i} in ${source}`);
50
- out.push({ t: 'num', v: Number(m[0]) });
51
- i += m[0].length;
52
- continue;
47
+ catch (error) {
48
+ throw new HoldsError(`${error instanceof Error ? error.message : String(error)} in ${source}`);
53
49
  }
54
- if (/[A-Za-z_]/.test(c)) {
55
- const m = /^[A-Za-z_][A-Za-z0-9_]*/.exec(source.slice(i));
56
- if (m === null)
57
- throw new HoldsError(`bad name at ${i} in ${source}`);
58
- out.push({ t: 'id', v: m[0] });
59
- i += m[0].length;
60
- continue;
61
- }
62
- throw new HoldsError(`unexpected '${c}' in ${source}`);
63
- }
64
- return out;
65
- }
66
- /**
67
- * Names in `holds` may contain hyphens. Rewrite the declared names to
68
- * underscores, longest first, before the lexer treats `-` as subtraction.
69
- */
70
- export function rewriteHoldsNames(source, names) {
71
- const ordered = [...names].sort((a, b) => b.length - a.length);
72
- let out = source;
73
- for (const name of ordered) {
74
- if (!name.includes('-'))
75
- continue;
76
- out = out.split(name).join(name.replace(/-/g, '_'));
77
- }
78
- return out;
79
- }
80
- function peek(p) {
81
- return p.toks[p.i];
82
- }
83
- function peekOp(p) {
84
- const tok = peek(p);
85
- return tok !== undefined && tok.t === 'op' ? tok.v : undefined;
86
- }
87
- function eat(p) {
88
- const tok = p.toks[p.i];
89
- if (tok === undefined)
90
- throw new HoldsError('unexpected end of condition');
91
- p.i += 1;
92
- return tok;
93
- }
94
- function asBool(value, op) {
95
- if (typeof value !== 'boolean')
96
- throw new HoldsError(`${op} needs a condition`);
97
- return value;
98
- }
99
- function parseOr(p, env) {
100
- let left = parseAnd(p, env);
101
- while (peekOp(p) === '||') {
102
- eat(p);
103
- const right = parseAnd(p, env);
104
- left = asBool(left, '||') || asBool(right, '||');
105
- }
106
- return left;
107
- }
108
- function parseAnd(p, env) {
109
- let left = parseNot(p, env);
110
- while (peekOp(p) === '&&') {
111
- eat(p);
112
- const right = parseNot(p, env);
113
- left = asBool(left, '&&') && asBool(right, '&&');
114
- }
115
- return left;
116
- }
117
- function parseNot(p, env) {
118
- if (peekOp(p) === '!') {
119
- eat(p);
120
- return !asBool(parseNot(p, env), '!');
121
- }
122
- return parseCmp(p, env);
123
- }
124
- function parseCmp(p, env) {
125
- const left = parseAdd(p, env);
126
- const op = peek(p);
127
- if (op?.t === 'op' && ['>', '<', '>=', '<=', '==', '!=', '===', '!=='].includes(op.v)) {
128
- eat(p);
129
- const right = parseAdd(p, env);
130
- if (typeof left === 'boolean' || typeof right === 'boolean') {
131
- throw new HoldsError('comparison of a condition');
132
- }
133
- switch (op.v) {
134
- case '>':
135
- return left > right;
136
- case '<':
137
- return left < right;
138
- case '>=':
139
- return left >= right;
140
- case '<=':
141
- return left <= right;
142
- case '==':
143
- case '===':
144
- return left === right;
145
- case '!=':
146
- case '!==':
147
- return left !== right;
148
- default:
149
- throw new HoldsError(`bad comparison ${op.v}`);
50
+ if (typeof v !== 'number')
51
+ throw new HoldsError(`operand is not a number: ${node.toString()} in ${source}`);
52
+ return v;
53
+ };
54
+ }
55
+ function compile(node, source) {
56
+ switch (node.type) {
57
+ case 'ParenthesisNode':
58
+ return compile(node.content, source);
59
+ case 'ConstantNode':
60
+ if (typeof node.value === 'boolean')
61
+ return () => node.value;
62
+ return arithmetic(node, source);
63
+ case 'OperatorNode': {
64
+ const op = node.op ?? '';
65
+ const args = node.args ?? [];
66
+ if (op === 'and' || op === 'or') {
67
+ const parts = args.map((a) => compile(a, source));
68
+ return (scope) => {
69
+ const values = parts.map((p) => p(scope));
70
+ if (values.some((v) => typeof v !== 'boolean'))
71
+ throw new HoldsError(`'${op}' of a number in ${source}`);
72
+ return op === 'and' ? values.every(Boolean) : values.some(Boolean);
73
+ };
74
+ }
75
+ if (op === 'not') {
76
+ const inner = compile(args[0], source);
77
+ return (scope) => {
78
+ const v = inner(scope);
79
+ if (typeof v !== 'boolean')
80
+ throw new HoldsError(`'not' of a number in ${source}`);
81
+ return !v;
82
+ };
83
+ }
84
+ const compare = COMPARISONS[op];
85
+ if (compare !== undefined) {
86
+ const [left, right] = args.map((a) => compile(a, source));
87
+ return (scope) => {
88
+ const a = left(scope);
89
+ const b = right(scope);
90
+ if (typeof a !== 'number' || typeof b !== 'number')
91
+ throw new HoldsError(`'${op}' of a boolean in ${source}`);
92
+ return compare(a, b);
93
+ };
94
+ }
95
+ return arithmetic(node, source);
150
96
  }
151
- }
152
- return left;
153
- }
154
- function parseAdd(p, env) {
155
- let left = parseMul(p, env);
156
- while (peekOp(p) === '+' || peekOp(p) === '-') {
157
- const op = eat(p);
158
- const right = parseMul(p, env);
159
- if (typeof left !== 'number' || typeof right !== 'number' || op.t !== 'op') {
160
- throw new HoldsError('arithmetic on a condition');
97
+ case 'FunctionNode': {
98
+ const predicate = PREDICATES[functionName(node)];
99
+ if (predicate !== undefined) {
100
+ const arg = compile(node.args[0], source);
101
+ return (scope) => {
102
+ const v = arg(scope);
103
+ if (typeof v !== 'number')
104
+ throw new HoldsError(`${functionName(node)} of a boolean in ${source}`);
105
+ return predicate(v);
106
+ };
107
+ }
108
+ return arithmetic(node, source);
161
109
  }
162
- left = op.v === '+' ? left + right : left - right;
110
+ default:
111
+ return arithmetic(node, source);
163
112
  }
164
- return left;
165
113
  }
166
- function parseMul(p, env) {
167
- let left = parseUnary(p, env);
168
- while (peekOp(p) === '*' || peekOp(p) === '/') {
169
- const op = eat(p);
170
- const right = parseUnary(p, env);
171
- if (typeof left !== 'number' || typeof right !== 'number' || op.t !== 'op') {
172
- throw new HoldsError('arithmetic on a condition');
173
- }
174
- left = op.v === '*' ? left * right : left / right;
114
+ const COMPILED = new Map();
115
+ function compiled(rewritten, source) {
116
+ const hit = COMPILED.get(rewritten);
117
+ if (hit !== undefined)
118
+ return hit;
119
+ let node;
120
+ try {
121
+ node = parseMathTs(rewritten);
175
122
  }
176
- return left;
177
- }
178
- function parseUnary(p, env) {
179
- if (peekOp(p) === '-') {
180
- eat(p);
181
- const v = parsePow(p, env);
182
- if (typeof v !== 'number')
183
- throw new HoldsError('negation of a condition');
184
- return -v;
185
- }
186
- if (peekOp(p) === '+') {
187
- eat(p);
188
- return parsePow(p, env);
189
- }
190
- return parsePow(p, env);
191
- }
192
- function parsePow(p, env) {
193
- const base = parsePrimary(p, env);
194
- if (peekOp(p) === '^') {
195
- eat(p);
196
- const exp = parseUnary(p, env);
197
- if (typeof base !== 'number' || typeof exp !== 'number')
198
- throw new HoldsError('power of a condition');
199
- return base ** exp;
200
- }
201
- return base;
202
- }
203
- function parsePrimary(p, env) {
204
- const tok = peek(p);
205
- if (tok?.t === 'num') {
206
- eat(p);
207
- return tok.v;
208
- }
209
- if (tok?.t === 'id') {
210
- eat(p);
211
- if (tok.v === 'true')
212
- return true;
213
- if (tok.v === 'false')
214
- return false;
215
- if (peek(p)?.t === 'lp') {
216
- eat(p);
217
- const arg = parseAdd(p, env);
218
- if (peek(p)?.t !== 'rp')
219
- throw new HoldsError(`unclosed ${tok.v}`);
220
- eat(p);
221
- if (typeof arg !== 'number')
222
- throw new HoldsError(`${tok.v} needs a number`);
223
- if (tok.v === 'finite')
224
- return Number.isFinite(arg);
225
- if (tok.v === 'integer')
226
- return Number.isInteger(arg);
227
- if (tok.v === 'sqrt')
228
- return Math.sqrt(arg);
229
- if (tok.v === 'abs')
230
- return Math.abs(arg);
231
- throw new HoldsError(`unknown predicate ${tok.v}`);
232
- }
233
- if (Object.hasOwn(env.values, tok.v))
234
- return env.values[tok.v];
235
- if (Object.hasOwn(env.constants, tok.v))
236
- return env.constants[tok.v];
237
- throw new HoldsError(`unbound '${tok.v}'`);
238
- }
239
- if (tok?.t === 'lp') {
240
- eat(p);
241
- const v = parseOr(p, env);
242
- if (peek(p)?.t !== 'rp')
243
- throw new HoldsError('unclosed group');
244
- eat(p);
245
- return v;
123
+ catch (error) {
124
+ throw new HoldsError(`${error instanceof Error ? error.message : String(error)} in ${source}`);
246
125
  }
247
- throw new HoldsError('expected a value');
126
+ const fn = compile(node, source);
127
+ COMPILED.set(rewritten, fn);
128
+ return fn;
248
129
  }
249
130
  /**
250
131
  * Whether `holds` is true for `values`.
251
- * Hyphenated quantity names are rewritten with `names` before parsing.
132
+ * Hyphenated quantity names are rewritten with `names` before parsing; an
133
+ * unbound name, a non-boolean result, and a syntax error are a {@link HoldsError}.
252
134
  */
253
135
  export function holds(source, values, constants, names) {
254
- const rewritten = rewriteHoldsNames(source, names);
255
- const folded = {};
136
+ const rewritten = rewriteCatalogHyphens(source, names);
137
+ const scope = { ...constants };
256
138
  for (const [key, value] of Object.entries(values))
257
- folded[key.replace(/-/g, '_')] = value;
258
- const p = { toks: tokenize(rewritten), i: 0 };
259
- const result = parseOr(p, { values: folded, constants });
260
- if (p.i !== p.toks.length)
261
- throw new HoldsError(`trailing input in ${source}`);
139
+ scope[key.replace(/-/g, '_')] = value;
140
+ const result = compiled(rewritten, source)(scope);
262
141
  if (typeof result !== 'boolean')
263
142
  throw new HoldsError(`condition is not boolean: ${source}`);
264
143
  return result;
@@ -1 +1 @@
1
- {"version":3,"file":"holds.js","sourceRoot":"","sources":["../../src/bridges/holds.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AASD,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAE9E,SAAS,QAAQ,CAAC,MAAc;IAC9B,MAAM,GAAG,GAAU,EAAE,CAAC;IACtB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAE,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAA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AK,CAAC,CAAC;IAClD,IAAI,OAAO,MAAM,KAAK,SAAS;QAAE,MAAM,IAAI,UAAU,CAAC,6BAA6B,MAAM,EAAE,CAAC,CAAC;IAC7F,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The one check of a binding record against an id's declared inputs.
3
+ *
4
+ * Every evaluation runs it before any domain check: `evaluateRelation`, the
5
+ * CLI's `upt evaluate`, an evaluator's `run`, the uncertainty probes that
6
+ * call `run`, and an applied case. It refuses an unknown key, a non-number, a
7
+ * number that is not finite and a key given twice, converts a declared
8
+ * alternate onto its key, and names every absent required input, in that
9
+ * order.
10
+ *
11
+ * A spelling binds one slot. {@link inputContract} builds a contract and
12
+ * refuses one whose spellings or alternates name two slots, so an ambiguous
13
+ * key fails when the contract is built, not when a caller happens to use it.
14
+ *
15
+ * What is required depends on what the caller asks for. A slot is read by the
16
+ * value (it owns a source of the relation) or only by the extra outputs. A
17
+ * caller who wants the value alone (`evaluateRelation`, the graph edge) need
18
+ * not give an output-only input; a caller who wants every output must.
19
+ *
20
+ * @module bridges/input-contract
21
+ */
22
+ /** A second key that converts into a slot's key by a factor. @public */
23
+ export interface ContractAlternate {
24
+ readonly key: string;
25
+ readonly toKey: number;
26
+ }
27
+ /** One declared input: the key the evaluation reads, and every spelling that binds it. @public */
28
+ export interface InputSlot {
29
+ readonly key: string;
30
+ /** Spellings that bind this slot as given (the key, its quantity, its source and aliases). */
31
+ readonly spellings: readonly string[];
32
+ readonly alternates: readonly ContractAlternate[];
33
+ readonly optional: boolean;
34
+ /** `'value'` when the relation's value reads this slot; `'outputs'` when only an extra output does. */
35
+ readonly readBy: 'value' | 'outputs';
36
+ /** Listed in a message as one of "the inputs". A constant a caller may override is not. */
37
+ readonly listed: boolean;
38
+ }
39
+ /** What the caller wants back: the relation's value alone, or the value and every extra output. @public */
40
+ export type EvaluationWant = 'value' | 'all';
41
+ /** The declared inputs of one id. @public */
42
+ export interface InputContract {
43
+ readonly id: string;
44
+ readonly slots: readonly InputSlot[];
45
+ }
46
+ /**
47
+ * A contract for `id` with `slots`, checked once here: every spelling and
48
+ * alternate binds exactly one slot.
49
+ *
50
+ * @throws Error when a spelling or an alternate names two slots.
51
+ * @public
52
+ */
53
+ export declare function inputContract(id: string, slots: readonly InputSlot[]): InputContract;
54
+ /**
55
+ * `bindings` keyed by slot key, after the contract's checks.
56
+ *
57
+ * @throws UnknownInputError a key no slot spells.
58
+ * @throws InputTypeError a value that is not a number.
59
+ * @throws NonFiniteInputError a number that is `NaN`, `Infinity` or `-Infinity`.
60
+ * @throws DuplicateInputError one slot bound under two spellings.
61
+ * @throws MissingInputError a required slot left unbound (every one is named).
62
+ * With `want` `'value'`, a slot only an extra output reads is not required.
63
+ */
64
+ export declare function checkInputs(contract: InputContract, bindings: Readonly<Record<string, unknown>>, want?: EvaluationWant): Record<string, number>;
65
+ //# sourceMappingURL=input-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-contract.d.ts","sourceRoot":"","sources":["../../src/bridges/input-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAUH,wEAAwE;AACxE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,kGAAkG;AAClG,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,8FAA8F;IAC9F,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAClD,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,uGAAuG;IACvG,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IACrC,2FAA2F;IAC3F,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED,2GAA2G;AAC3G,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,KAAK,CAAC;AAE7C,6CAA6C;AAC7C,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAC;CACtC;AA8BD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,aAAa,CAIpF;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,aAAa,EACvB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC3C,IAAI,GAAE,cAAsB,GAC3B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmBxB"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The one check of a binding record against an id's declared inputs.
3
+ *
4
+ * Every evaluation runs it before any domain check: `evaluateRelation`, the
5
+ * CLI's `upt evaluate`, an evaluator's `run`, the uncertainty probes that
6
+ * call `run`, and an applied case. It refuses an unknown key, a non-number, a
7
+ * number that is not finite and a key given twice, converts a declared
8
+ * alternate onto its key, and names every absent required input, in that
9
+ * order.
10
+ *
11
+ * A spelling binds one slot. {@link inputContract} builds a contract and
12
+ * refuses one whose spellings or alternates name two slots, so an ambiguous
13
+ * key fails when the contract is built, not when a caller happens to use it.
14
+ *
15
+ * What is required depends on what the caller asks for. A slot is read by the
16
+ * value (it owns a source of the relation) or only by the extra outputs. A
17
+ * caller who wants the value alone (`evaluateRelation`, the graph edge) need
18
+ * not give an output-only input; a caller who wants every output must.
19
+ *
20
+ * @module bridges/input-contract
21
+ */
22
+ import { DuplicateInputError, InputTypeError, MissingInputError, NonFiniteInputError, UnknownInputError, } from './evaluation-errors.js';
23
+ const INDEX = new WeakMap();
24
+ /**
25
+ * Every spelling and alternate of `contract`, each onto its one slot.
26
+ * @throws Error when one spelling names two slots.
27
+ */
28
+ function spellingIndex(contract) {
29
+ const cached = INDEX.get(contract);
30
+ if (cached !== undefined)
31
+ return cached;
32
+ const index = new Map();
33
+ const bind = (spelling, slot, factor) => {
34
+ const earlier = index.get(spelling);
35
+ if (earlier !== undefined && earlier.slot !== slot) {
36
+ throw new Error(`${contract.id}: input contract spells '${spelling}' for both '${earlier.slot.key}' and '${slot.key}'`);
37
+ }
38
+ if (earlier === undefined)
39
+ index.set(spelling, { slot, factor });
40
+ };
41
+ for (const slot of contract.slots)
42
+ for (const spelling of slot.spellings)
43
+ bind(spelling, slot, 1);
44
+ for (const slot of contract.slots)
45
+ for (const alt of slot.alternates)
46
+ bind(alt.key, slot, alt.toKey);
47
+ INDEX.set(contract, index);
48
+ return index;
49
+ }
50
+ /**
51
+ * A contract for `id` with `slots`, checked once here: every spelling and
52
+ * alternate binds exactly one slot.
53
+ *
54
+ * @throws Error when a spelling or an alternate names two slots.
55
+ * @public
56
+ */
57
+ export function inputContract(id, slots) {
58
+ const contract = { id, slots };
59
+ spellingIndex(contract);
60
+ return contract;
61
+ }
62
+ /**
63
+ * `bindings` keyed by slot key, after the contract's checks.
64
+ *
65
+ * @throws UnknownInputError a key no slot spells.
66
+ * @throws InputTypeError a value that is not a number.
67
+ * @throws NonFiniteInputError a number that is `NaN`, `Infinity` or `-Infinity`.
68
+ * @throws DuplicateInputError one slot bound under two spellings.
69
+ * @throws MissingInputError a required slot left unbound (every one is named).
70
+ * With `want` `'value'`, a slot only an extra output reads is not required.
71
+ */
72
+ export function checkInputs(contract, bindings, want = 'all') {
73
+ const listed = contract.slots.filter((slot) => slot.listed).map((slot) => slot.key);
74
+ const bySpelling = spellingIndex(contract);
75
+ const out = {};
76
+ const givenAs = new Map();
77
+ for (const [key, value] of Object.entries(bindings)) {
78
+ const found = bySpelling.get(key);
79
+ if (found === undefined)
80
+ throw new UnknownInputError(contract.id, key, listed);
81
+ if (typeof value !== 'number')
82
+ throw new InputTypeError(contract.id, key, typeof value);
83
+ if (!Number.isFinite(value))
84
+ throw new NonFiniteInputError(contract.id, key, value);
85
+ const earlier = givenAs.get(found.slot.key);
86
+ if (earlier !== undefined)
87
+ throw new DuplicateInputError(contract.id, found.slot.key, [earlier, key]);
88
+ givenAs.set(found.slot.key, key);
89
+ out[found.slot.key] = value * found.factor;
90
+ }
91
+ const required = (slot) => !slot.optional && (want === 'all' || slot.readBy === 'value');
92
+ const missing = contract.slots.filter((slot) => required(slot) && !givenAs.has(slot.key)).map((slot) => slot.key);
93
+ if (missing.length > 0)
94
+ throw new MissingInputError(contract.id, missing, listed);
95
+ return out;
96
+ }
97
+ //# sourceMappingURL=input-contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-contract.js","sourceRoot":"","sources":["../../src/bridges/input-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAiChC,MAAM,KAAK,GAAG,IAAI,OAAO,EAAgC,CAAC;AAE1D;;;GAGG;AACH,SAAS,aAAa,CAAC,QAAuB;IAC5C,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACnC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACxC,MAAM,KAAK,GAAG,IAAI,GAAG,EAA+C,CAAC;IACrE,MAAM,IAAI,GAAG,CAAC,QAAgB,EAAE,IAAe,EAAE,MAAc,EAAQ,EAAE;QACvE,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACpC,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CACb,GAAG,QAAQ,CAAC,EAAE,4BAA4B,QAAQ,e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C;IAC7G,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClH,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,iBAAiB,CAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAClF,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The caveats printed beside a relation's value: the record's own notice, and
3
+ * the note of every registered constant its expression names. No caller
4
+ * switches on a notice; the text is the record's or the constant's.
5
+ *
6
+ * @module bridges/notices
7
+ */
8
+ import type { CatalogRelation } from './catalog-types.js';
9
+ /** The caveats to print beside `relation`'s value. @internal */
10
+ export declare function relationNotices(relation: CatalogRelation): string[];
11
+ //# sourceMappingURL=notices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notices.d.ts","sourceRoot":"","sources":["../../src/bridges/notices.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAO1D,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,EAAE,CAKnE"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The caveats printed beside a relation's value: the record's own notice, and
3
+ * the note of every registered constant its expression names. No caller
4
+ * switches on a notice; the text is the record's or the constant's.
5
+ *
6
+ * @module bridges/notices
7
+ */
8
+ import { constantNotes } from '../dimensional/symbolic-constants.js';
9
+ /** Identifiers in an expression, in order of first appearance. */
10
+ function identifiers(expression) {
11
+ return [...new Set(expression.match(/[A-Za-z_][A-Za-z0-9_]*/g) ?? [])];
12
+ }
13
+ /** The caveats to print beside `relation`'s value. @internal */
14
+ export function relationNotices(relation) {
15
+ const notes = [];
16
+ if (relation.notice !== undefined)
17
+ notes.push(relation.notice.text);
18
+ for (const note of constantNotes(identifiers(relation.expression)))
19
+ notes.push(`note: ${note}`);
20
+ return notes;
21
+ }
22
+ //# sourceMappingURL=notices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notices.js","sourceRoot":"","sources":["../../src/bridges/notices.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAGrE,kEAAkE;AAClE,SAAS,WAAW,CAAC,UAAkB;IACrC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,yBAAyB,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,eAAe,CAAC,QAAyB;IACvD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpE,KAAK,MAAM,IAAI,IAAI,aAAa,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IAChG,OAAO,KAAK,CAAC;AACf,CAAC"}