@elaraai/east 1.0.84 → 1.0.86

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 (247) hide show
  1. package/dist/src/analyze.d.ts.map +1 -1
  2. package/dist/src/analyze.js +48 -0
  3. package/dist/src/analyze.js.map +1 -1
  4. package/dist/src/ast_to_ir.coerce_to.spec.js +4 -4
  5. package/dist/src/ast_to_ir.coerce_to.spec.js.map +1 -1
  6. package/dist/src/ast_to_ir.d.ts +6 -1
  7. package/dist/src/ast_to_ir.d.ts.map +1 -1
  8. package/dist/src/ast_to_ir.js +20 -7
  9. package/dist/src/ast_to_ir.js.map +1 -1
  10. package/dist/src/builtins.d.ts +1 -1
  11. package/dist/src/builtins.d.ts.map +1 -1
  12. package/dist/src/builtins.js +52 -0
  13. package/dist/src/builtins.js.map +1 -1
  14. package/dist/src/codegen/canonical.d.ts +37 -0
  15. package/dist/src/codegen/canonical.d.ts.map +1 -0
  16. package/dist/src/codegen/canonical.js +208 -0
  17. package/dist/src/codegen/canonical.js.map +1 -0
  18. package/dist/src/codegen/codegen.spec.js +132 -201
  19. package/dist/src/codegen/codegen.spec.js.map +1 -1
  20. package/dist/src/codegen/printer.d.ts.map +1 -1
  21. package/dist/src/codegen/printer.js +142 -24
  22. package/dist/src/codegen/printer.js.map +1 -1
  23. package/dist/src/codegen/spellings.d.ts +4 -1
  24. package/dist/src/codegen/spellings.d.ts.map +1 -1
  25. package/dist/src/codegen/spellings.js +5 -1
  26. package/dist/src/codegen/spellings.js.map +1 -1
  27. package/dist/src/compile/builtins/index.d.ts.map +1 -1
  28. package/dist/src/compile/builtins/index.js +2 -0
  29. package/dist/src/compile/builtins/index.js.map +1 -1
  30. package/dist/src/compile/builtins/primitives.d.ts.map +1 -1
  31. package/dist/src/compile/builtins/primitives.js +2 -1
  32. package/dist/src/compile/builtins/primitives.js.map +1 -1
  33. package/dist/src/compile/builtins/query.d.ts +10 -0
  34. package/dist/src/compile/builtins/query.d.ts.map +1 -0
  35. package/dist/src/compile/builtins/query.js +5 -0
  36. package/dist/src/compile/builtins/query.js.map +1 -0
  37. package/dist/src/expr/block.d.ts.map +1 -1
  38. package/dist/src/expr/block.js +2 -1
  39. package/dist/src/expr/block.js.map +1 -1
  40. package/dist/src/expr/index.d.ts +75 -47
  41. package/dist/src/expr/index.d.ts.map +1 -1
  42. package/dist/src/expr/index.js +31 -0
  43. package/dist/src/expr/index.js.map +1 -1
  44. package/dist/src/expr/libs/datetime.d.ts +20 -20
  45. package/dist/src/expr/libs/datetime.d.ts.map +1 -1
  46. package/dist/src/expr/libs/datetime.js +208 -167
  47. package/dist/src/expr/libs/datetime.js.map +1 -1
  48. package/dist/src/expr/libs/float.d.ts +15 -15
  49. package/dist/src/expr/libs/float.d.ts.map +1 -1
  50. package/dist/src/expr/libs/float.js +298 -267
  51. package/dist/src/expr/libs/float.js.map +1 -1
  52. package/dist/src/expr/libs/integer.d.ts +12 -12
  53. package/dist/src/expr/libs/integer.d.ts.map +1 -1
  54. package/dist/src/expr/libs/integer.js +219 -194
  55. package/dist/src/expr/libs/integer.js.map +1 -1
  56. package/dist/src/expr/libs/lazy.d.ts +28 -0
  57. package/dist/src/expr/libs/lazy.d.ts.map +1 -0
  58. package/dist/src/expr/libs/lazy.js +55 -0
  59. package/dist/src/expr/libs/lazy.js.map +1 -0
  60. package/dist/src/expr/libs/lazy.spec.d.ts +6 -0
  61. package/dist/src/expr/libs/lazy.spec.d.ts.map +1 -0
  62. package/dist/src/expr/libs/lazy.spec.js +102 -0
  63. package/dist/src/expr/libs/lazy.spec.js.map +1 -0
  64. package/dist/src/expr/query.d.ts +60 -0
  65. package/dist/src/expr/query.d.ts.map +1 -0
  66. package/dist/src/expr/query.js +84 -0
  67. package/dist/src/expr/query.js.map +1 -0
  68. package/dist/src/functions.crossimport.spec.js +8 -0
  69. package/dist/src/functions.crossimport.spec.js.map +1 -1
  70. package/dist/src/functions.d.ts +45 -8
  71. package/dist/src/functions.d.ts.map +1 -1
  72. package/dist/src/functions.js +138 -28
  73. package/dist/src/functions.js.map +1 -1
  74. package/dist/src/functions.spec.js +60 -2
  75. package/dist/src/functions.spec.js.map +1 -1
  76. package/dist/src/index.d.ts +3 -0
  77. package/dist/src/index.d.ts.map +1 -1
  78. package/dist/src/index.js +3 -0
  79. package/dist/src/index.js.map +1 -1
  80. package/dist/src/internal.d.ts +4 -0
  81. package/dist/src/internal.d.ts.map +1 -1
  82. package/dist/src/internal.js +9 -0
  83. package/dist/src/internal.js.map +1 -1
  84. package/dist/src/location.d.ts +22 -0
  85. package/dist/src/location.d.ts.map +1 -1
  86. package/dist/src/location.js +31 -0
  87. package/dist/src/location.js.map +1 -1
  88. package/dist/src/naming.d.ts +5 -3
  89. package/dist/src/naming.d.ts.map +1 -1
  90. package/dist/src/naming.js.map +1 -1
  91. package/dist/src/portable.spec.d.ts +6 -0
  92. package/dist/src/portable.spec.d.ts.map +1 -0
  93. package/dist/src/portable.spec.js +181 -0
  94. package/dist/src/portable.spec.js.map +1 -0
  95. package/dist/src/query/evaluate.d.ts +98 -0
  96. package/dist/src/query/evaluate.d.ts.map +1 -0
  97. package/dist/src/query/evaluate.js +193 -0
  98. package/dist/src/query/evaluate.js.map +1 -0
  99. package/dist/src/query/index.d.ts +17 -0
  100. package/dist/src/query/index.d.ts.map +1 -0
  101. package/dist/src/query/index.js +17 -0
  102. package/dist/src/query/index.js.map +1 -0
  103. package/dist/src/query/jq/catalog.d.ts +174 -0
  104. package/dist/src/query/jq/catalog.d.ts.map +1 -0
  105. package/dist/src/query/jq/catalog.js +1740 -0
  106. package/dist/src/query/jq/catalog.js.map +1 -0
  107. package/dist/src/query/jq/check.d.ts +210 -0
  108. package/dist/src/query/jq/check.d.ts.map +1 -0
  109. package/dist/src/query/jq/check.js +2261 -0
  110. package/dist/src/query/jq/check.js.map +1 -0
  111. package/dist/src/query/jq/complete.d.ts +89 -0
  112. package/dist/src/query/jq/complete.d.ts.map +1 -0
  113. package/dist/src/query/jq/complete.js +320 -0
  114. package/dist/src/query/jq/complete.js.map +1 -0
  115. package/dist/src/query/jq/describe.d.ts +53 -0
  116. package/dist/src/query/jq/describe.d.ts.map +1 -0
  117. package/dist/src/query/jq/describe.js +149 -0
  118. package/dist/src/query/jq/describe.js.map +1 -0
  119. package/dist/src/query/jq/lex.d.ts +118 -0
  120. package/dist/src/query/jq/lex.d.ts.map +1 -0
  121. package/dist/src/query/jq/lex.js +371 -0
  122. package/dist/src/query/jq/lex.js.map +1 -0
  123. package/dist/src/query/jq/literals.d.ts +49 -0
  124. package/dist/src/query/jq/literals.d.ts.map +1 -0
  125. package/dist/src/query/jq/literals.js +78 -0
  126. package/dist/src/query/jq/literals.js.map +1 -0
  127. package/dist/src/query/jq/messages.d.ts +126 -0
  128. package/dist/src/query/jq/messages.d.ts.map +1 -0
  129. package/dist/src/query/jq/messages.js +172 -0
  130. package/dist/src/query/jq/messages.js.map +1 -0
  131. package/dist/src/query/jq/parse.d.ts +70 -0
  132. package/dist/src/query/jq/parse.d.ts.map +1 -0
  133. package/dist/src/query/jq/parse.js +1013 -0
  134. package/dist/src/query/jq/parse.js.map +1 -0
  135. package/dist/src/query/jq/print.d.ts +59 -0
  136. package/dist/src/query/jq/print.d.ts.map +1 -0
  137. package/dist/src/query/jq/print.js +587 -0
  138. package/dist/src/query/jq/print.js.map +1 -0
  139. package/dist/src/query/jq/shapes.d.ts +345 -0
  140. package/dist/src/query/jq/shapes.d.ts.map +1 -0
  141. package/dist/src/query/jq/shapes.js +584 -0
  142. package/dist/src/query/jq/shapes.js.map +1 -0
  143. package/dist/src/query/jq/spans.d.ts +133 -0
  144. package/dist/src/query/jq/spans.d.ts.map +1 -0
  145. package/dist/src/query/jq/spans.js +195 -0
  146. package/dist/src/query/jq/spans.js.map +1 -0
  147. package/dist/src/query/jq/split.d.ts +334 -0
  148. package/dist/src/query/jq/split.d.ts.map +1 -0
  149. package/dist/src/query/jq/split.js +2108 -0
  150. package/dist/src/query/jq/split.js.map +1 -0
  151. package/dist/src/query/jq/strftime.d.ts +20 -0
  152. package/dist/src/query/jq/strftime.d.ts.map +1 -0
  153. package/dist/src/query/jq/strftime.js +65 -0
  154. package/dist/src/query/jq/strftime.js.map +1 -0
  155. package/dist/src/query/jq/summary.d.ts +139 -0
  156. package/dist/src/query/jq/summary.d.ts.map +1 -0
  157. package/dist/src/query/jq/summary.js +222 -0
  158. package/dist/src/query/jq/summary.js.map +1 -0
  159. package/dist/src/query/jq/translate-builtins.d.ts +21 -0
  160. package/dist/src/query/jq/translate-builtins.d.ts.map +1 -0
  161. package/dist/src/query/jq/translate-builtins.js +1873 -0
  162. package/dist/src/query/jq/translate-builtins.js.map +1 -0
  163. package/dist/src/query/jq/translate.d.ts +627 -0
  164. package/dist/src/query/jq/translate.d.ts.map +1 -0
  165. package/dist/src/query/jq/translate.js +3364 -0
  166. package/dist/src/query/jq/translate.js.map +1 -0
  167. package/dist/src/query/types.d.ts +505 -0
  168. package/dist/src/query/types.d.ts.map +1 -0
  169. package/dist/src/query/types.js +231 -0
  170. package/dist/src/query/types.js.map +1 -0
  171. package/dist/src/runner_exec.d.ts +134 -0
  172. package/dist/src/runner_exec.d.ts.map +1 -0
  173. package/dist/src/runner_exec.js +371 -0
  174. package/dist/src/runner_exec.js.map +1 -0
  175. package/dist/src/runner_exec.spec.d.ts +6 -0
  176. package/dist/src/runner_exec.spec.d.ts.map +1 -0
  177. package/dist/src/runner_exec.spec.js +198 -0
  178. package/dist/src/runner_exec.spec.js.map +1 -0
  179. package/dist/src/runner_io.d.ts +370 -0
  180. package/dist/src/runner_io.d.ts.map +1 -0
  181. package/dist/src/runner_io.js +563 -0
  182. package/dist/src/runner_io.js.map +1 -0
  183. package/dist/src/runner_io.spec.d.ts +6 -0
  184. package/dist/src/runner_io.spec.d.ts.map +1 -0
  185. package/dist/src/runner_io.spec.js +224 -0
  186. package/dist/src/runner_io.spec.js.map +1 -0
  187. package/dist/src/runner_merge.d.ts +95 -0
  188. package/dist/src/runner_merge.d.ts.map +1 -0
  189. package/dist/src/runner_merge.js +238 -0
  190. package/dist/src/runner_merge.js.map +1 -0
  191. package/dist/src/runner_protocol.d.ts +11 -4
  192. package/dist/src/runner_protocol.d.ts.map +1 -1
  193. package/dist/src/runner_protocol.js +11 -4
  194. package/dist/src/runner_protocol.js.map +1 -1
  195. package/dist/src/serialization/beast2/index.d.ts +1 -1
  196. package/dist/src/serialization/beast2/index.d.ts.map +1 -1
  197. package/dist/src/serialization/beast2/index.js.map +1 -1
  198. package/dist/src/serialization/beast2/v5/frames.d.ts +10 -6
  199. package/dist/src/serialization/beast2/v5/frames.d.ts.map +1 -1
  200. package/dist/src/serialization/beast2/v5/frames.js +10 -6
  201. package/dist/src/serialization/beast2/v5/frames.js.map +1 -1
  202. package/dist/src/serialization/beast2/v5/frames.spec.d.ts +6 -0
  203. package/dist/src/serialization/beast2/v5/frames.spec.d.ts.map +1 -0
  204. package/dist/src/serialization/beast2/v5/frames.spec.js +42 -0
  205. package/dist/src/serialization/beast2/v5/frames.spec.js.map +1 -0
  206. package/dist/src/serialization/beast2/v5/index.spec.js +108 -0
  207. package/dist/src/serialization/beast2/v5/index.spec.js.map +1 -1
  208. package/dist/src/serialization/beast2/v5/lazy.d.ts +12 -7
  209. package/dist/src/serialization/beast2/v5/lazy.d.ts.map +1 -1
  210. package/dist/src/serialization/beast2/v5/lazy.js +16 -6
  211. package/dist/src/serialization/beast2/v5/lazy.js.map +1 -1
  212. package/dist/src/serialization/beast2/v5/lazy.spec.js +159 -18
  213. package/dist/src/serialization/beast2/v5/lazy.spec.js.map +1 -1
  214. package/dist/src/serialization/beast2/v5/stream.d.ts +110 -21
  215. package/dist/src/serialization/beast2/v5/stream.d.ts.map +1 -1
  216. package/dist/src/serialization/beast2/v5/stream.js +153 -42
  217. package/dist/src/serialization/beast2/v5/stream.js.map +1 -1
  218. package/dist/src/serialization/beast2/v5/weight.d.ts +36 -0
  219. package/dist/src/serialization/beast2/v5/weight.d.ts.map +1 -0
  220. package/dist/src/serialization/beast2/v5/weight.js +238 -0
  221. package/dist/src/serialization/beast2/v5/weight.js.map +1 -0
  222. package/dist/src/serialization/crc32.d.ts +38 -0
  223. package/dist/src/serialization/crc32.d.ts.map +1 -0
  224. package/dist/src/serialization/crc32.js +70 -0
  225. package/dist/src/serialization/crc32.js.map +1 -0
  226. package/dist/src/serialization/crc32.spec.d.ts +6 -0
  227. package/dist/src/serialization/crc32.spec.d.ts.map +1 -0
  228. package/dist/src/serialization/crc32.spec.js +92 -0
  229. package/dist/src/serialization/crc32.spec.js.map +1 -0
  230. package/dist/src/serialization/east-inferred.spec.js +4 -0
  231. package/dist/src/serialization/east-inferred.spec.js.map +1 -1
  232. package/dist/src/serialization/east.d.ts.map +1 -1
  233. package/dist/src/serialization/east.js +134 -110
  234. package/dist/src/serialization/east.js.map +1 -1
  235. package/dist/src/serialization/east.spec.js +185 -4
  236. package/dist/src/serialization/east.spec.js.map +1 -1
  237. package/dist/src/serialization/east_text.d.ts +25 -0
  238. package/dist/src/serialization/east_text.d.ts.map +1 -0
  239. package/dist/src/serialization/east_text.js +29 -0
  240. package/dist/src/serialization/east_text.js.map +1 -0
  241. package/dist/src/serialization/index.d.ts +1 -1
  242. package/dist/src/serialization/index.d.ts.map +1 -1
  243. package/dist/src/types.d.ts +1 -1
  244. package/dist/src/types.d.ts.map +1 -1
  245. package/dist/src/types.js +7 -6
  246. package/dist/src/types.js.map +1 -1
  247. package/package.json +6 -3
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ /**
6
+ * The wire types of typed jq queries over East values.
7
+ *
8
+ * A query's text is parsed into a {@link JqType} tree, the program as
9
+ * written, each constant in it a typed East value. A query's types are never
10
+ * kept with it: they are what checking the program against the data it reads
11
+ * gives, and every place that needs them checks the program (#1138). In code,
12
+ * the `Query` builtin carries the program and a root's input names
13
+ * ({@link QueryCallType}) beside the query's translation, whose function type
14
+ * carries the types, and a runtime runs the translation (#1041), so no
15
+ * runtime reads query text.
16
+ *
17
+ * Struct fields are declared alphabetically, as `FunctionManifestType`'s are,
18
+ * and the python twins in `east/query/types.py` declare the same types, so a
19
+ * type encodes to the same bytes in either language. `devdocs/QUERY.md` is the
20
+ * normative account of what the values mean.
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+ import { ArrayType, BooleanType, FloatType, IntegerType, NullType, OptionType, RecursiveType, StringType, StructType, VariantType } from "../types.js";
25
+ /**
26
+ * A constant a jq program writes, as the East value it is.
27
+ *
28
+ * @remarks
29
+ * - `boolean` — `true` or `false`.
30
+ * - `float` — a number written with a `.` or an exponent: `1001.0`, `1e2`.
31
+ * - `integer` — a number written as digits alone, `1001`: a 64-bit Integer.
32
+ * - `null` — `null`.
33
+ * - `string` — a string with no interpolation, `"C01"`.
34
+ *
35
+ * A literal is the constant as written. Where the checker reads it as
36
+ * another type — an Integer where a Float is, an ISO-8601 string where a
37
+ * DateTime is — the program still holds it as written, and its translation
38
+ * gives the value that type has (`devdocs/QUERY.md` §7).
39
+ */
40
+ export const JqLiteralType = VariantType({
41
+ boolean: BooleanType,
42
+ float: FloatType,
43
+ integer: IntegerType,
44
+ null: NullType,
45
+ string: StringType,
46
+ });
47
+ /**
48
+ * A destructuring pattern, as `as`, `reduce` and `foreach` bind one.
49
+ *
50
+ * @remarks
51
+ * - `array` — `[$a, $b]`: each element pattern matches the element at its
52
+ * index.
53
+ * - `object` — `{name: $n, $id}`: each entry reads the field named by `key`
54
+ * and matches it against `value`; an entry with no `value` binds the
55
+ * variable named `key` (`$id` reads `.id`). Keys are literal in this version.
56
+ * - `variable` — `$x`, named without its `$`.
57
+ *
58
+ * `?//` alternatives are a list of patterns on the binding that uses them
59
+ * (see {@link JqType}'s `bind` case).
60
+ */
61
+ export const JqPatternType = RecursiveType(pattern => VariantType({
62
+ array: ArrayType(pattern),
63
+ object: ArrayType(StructType({ key: StringType, value: OptionType(pattern) })),
64
+ variable: StringType,
65
+ }));
66
+ /**
67
+ * A jq program, as a tree.
68
+ *
69
+ * @remarks
70
+ * The parser keeps jq's sugar rather than desugaring it, so printing a parsed
71
+ * program gives back what was written: `.a.b` is two `field` nodes and `f?` is
72
+ * a `try` with no `catch`. Operators, builtin names and error codes are
73
+ * strings, so a new one never changes this type.
74
+ *
75
+ * - `alternative` — `left // right`.
76
+ * - `array` — `[f]`, or `[]` when there is no body.
77
+ * - `binary` — `left op right`, for `op` one of `+ - * / % == != < <= > >=
78
+ * and or`.
79
+ * - `bind` — `source as $p ?// $q | body`: the first of `patterns` that
80
+ * matches binds.
81
+ * - `break` — `break $name`, named without its `$`.
82
+ * - `call` — a builtin or a `def` by name, with its `;`-separated arguments.
83
+ * - `comma` — `left, right`.
84
+ * - `def` — `def name(params): body; rest`.
85
+ * - `descend` — `..`, every nested value in pre-order.
86
+ * - `field` — `target.name`, or `target.name?` when `optional`.
87
+ * - `foreach` — `foreach source as pattern (init; update; extract)`.
88
+ * - `format` — `@name`, or `@name "…"` applied to a string.
89
+ * - `identity` — `.`.
90
+ * - `if` — `if c then t elif … else e end`; `otherwise` is the `else`.
91
+ * - `index` — `target[index]`: an index on an array, a key on a dict,
92
+ * decided by the target's type; `optional` is a trailing `?`.
93
+ * - `iterate` — `target[]`, or `target[]?` when `optional`.
94
+ * - `label` — `label $name | body`, named without its `$`.
95
+ * - `literal` — a constant, as the typed East value it is
96
+ * ({@link JqLiteralType}): `1001` is an Integer, `1001.0` a Float.
97
+ * - `negate` — `-f`.
98
+ * - `object` — `{…}`: a key is a `name` (`{a: f}`, or `{a}` with no value),
99
+ * a `variable` (`{$x}`, named without its `$`) or `computed` (`{(k): v}`).
100
+ * - `pipe` — `left | right`.
101
+ * - `reduce` — `reduce source as pattern (init; update)`.
102
+ * - `slice` — `target[from:to]`, either bound optional.
103
+ * - `string` — a string with interpolations, `"a\(f)b"`, as its parts.
104
+ * - `try` — `try body catch handler`; `f?` is `try f` with no `catch`.
105
+ * - `update` — `path op value`, for `op` one of `= |= += -= *= /= %= //=`.
106
+ * - `variable` — `$x`, named without its `$`.
107
+ */
108
+ export const JqType = RecursiveType(jq => VariantType({
109
+ alternative: StructType({ left: jq, right: jq }),
110
+ array: OptionType(jq),
111
+ binary: StructType({ left: jq, op: StringType, right: jq }),
112
+ bind: StructType({ body: jq, patterns: ArrayType(JqPatternType), source: jq }),
113
+ break: StringType,
114
+ call: StructType({ args: ArrayType(jq), name: StringType }),
115
+ comma: StructType({ left: jq, right: jq }),
116
+ def: StructType({ body: jq, name: StringType, params: ArrayType(StringType), rest: jq }),
117
+ descend: NullType,
118
+ field: StructType({ name: StringType, optional: BooleanType, target: jq }),
119
+ foreach: StructType({ extract: OptionType(jq), init: jq, pattern: JqPatternType, source: jq, update: jq }),
120
+ format: StructType({ name: StringType, string: OptionType(jq) }),
121
+ identity: NullType,
122
+ if: StructType({ branches: ArrayType(StructType({ condition: jq, then: jq })), otherwise: OptionType(jq) }),
123
+ index: StructType({ index: jq, optional: BooleanType, target: jq }),
124
+ iterate: StructType({ optional: BooleanType, target: jq }),
125
+ label: StructType({ body: jq, name: StringType }),
126
+ literal: JqLiteralType,
127
+ negate: jq,
128
+ object: ArrayType(StructType({
129
+ key: VariantType({ computed: jq, name: StringType, variable: StringType }),
130
+ value: OptionType(jq),
131
+ })),
132
+ pipe: StructType({ left: jq, right: jq }),
133
+ reduce: StructType({ init: jq, pattern: JqPatternType, source: jq, update: jq }),
134
+ slice: StructType({ from: OptionType(jq), optional: BooleanType, target: jq, to: OptionType(jq) }),
135
+ string: ArrayType(VariantType({ interpolate: jq, text: StringType })),
136
+ try: StructType({ body: jq, catch: OptionType(jq) }),
137
+ update: StructType({ op: StringType, path: jq, value: jq }),
138
+ variable: StringType,
139
+ }));
140
+ /**
141
+ * How many outputs a query gives: `one` exactly, `maybe` none or one, or
142
+ * `many`.
143
+ *
144
+ * @remarks
145
+ * A checked query's result is its element type `T` for `one`, `Option<T>` for
146
+ * `maybe`, and `Array<T>` (the stream collected in order) for `many`. A
147
+ * runtime enforces the multiplicity: a `one` query that yields no output, or
148
+ * two, is a runtime error.
149
+ */
150
+ export const QueryMultiplicityType = VariantType({ many: NullType, maybe: NullType, one: NullType });
151
+ /**
152
+ * A query as the `Query` builtin carries it in code (#1041): the program as
153
+ * written, and a root's input names.
154
+ *
155
+ * @remarks
156
+ * - `inputs` — the names of a root's fields, one per input of the
157
+ * translation, in order; `none` for a query of one input.
158
+ * - `program` — the program as written ({@link JqType}).
159
+ *
160
+ * The builtin's type parameter, the translation's function type, carries the
161
+ * query's input and result types, so they are not held twice. A structural
162
+ * change is a new case that sorts after `v1` (a variant's cases are ordered
163
+ * by name, and inserting one before an existing case renumbers it), and
164
+ * readers accept every released version.
165
+ */
166
+ export const QueryCallType = VariantType({
167
+ v1: StructType({
168
+ inputs: OptionType(ArrayType(StringType)),
169
+ program: JqType,
170
+ }),
171
+ });
172
+ /**
173
+ * A range of query text.
174
+ *
175
+ * @remarks
176
+ * Offsets and lengths count UTF-16 code units, the unit browsers and
177
+ * TypeScript index strings in; python converts from code points, so a program
178
+ * holding characters outside the Basic Multilingual Plane gets the same span
179
+ * in both front ends.
180
+ *
181
+ * - `column` — 1-based, in UTF-16 code units of its line.
182
+ * - `length` — in UTF-16 code units.
183
+ * - `line` — 1-based.
184
+ * - `offset` — 0-based, in UTF-16 code units of the whole text.
185
+ */
186
+ export const QuerySpanType = StructType({
187
+ column: IntegerType,
188
+ length: IntegerType,
189
+ line: IntegerType,
190
+ offset: IntegerType,
191
+ });
192
+ /**
193
+ * One text edit: replace `length` UTF-16 code units at `offset` with
194
+ * `insert`.
195
+ */
196
+ export const QueryEditType = StructType({ insert: StringType, length: IntegerType, offset: IntegerType });
197
+ /**
198
+ * A one-click fix for a diagnostic: its `label` ("Use .demand") and the text
199
+ * `edits` that make it, applied together.
200
+ *
201
+ * @remarks
202
+ * A fix is text edits so every client applies it the same way. The edits of
203
+ * one fix do not overlap.
204
+ */
205
+ export const QueryFixType = StructType({ edits: ArrayType(QueryEditType), label: StringType });
206
+ /**
207
+ * A diagnostic from checking a query, or an error from evaluating one.
208
+ *
209
+ * @remarks
210
+ * - `code` — `syntax`, `unknown_field`, `unknown_case`, `unknown_function`,
211
+ * `type_mismatch`, `not_iterable`, `not_indexable`, `arity`,
212
+ * `ambiguous_output`, `cannot_infer`, `unsupported` or
213
+ * `array_builtin_on_element`, or a lint (`duplicate_outputs`,
214
+ * `duplicate_key`, `never_missing`, `long_range`); `devdocs/QUERY.md` §12
215
+ * lists each message's template. An error a query raised as it ran is
216
+ * `runtime` (§15).
217
+ * - `fixes` — one-click fixes, best first.
218
+ * - `message` — one sentence, the same wherever the checker runs.
219
+ * - `severity` — `error`, or `warning` for a lint.
220
+ * - `span` — the text it is about, when it is about some.
221
+ * - `suggestions` — replacement texts for the span, best first.
222
+ */
223
+ export const QueryErrorType = StructType({
224
+ code: StringType,
225
+ fixes: ArrayType(QueryFixType),
226
+ message: StringType,
227
+ severity: VariantType({ error: NullType, warning: NullType }),
228
+ span: OptionType(QuerySpanType),
229
+ suggestions: ArrayType(StringType),
230
+ });
231
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/query/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEvJ;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;IACvC,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,SAAS;IAChB,OAAO,EAAE,WAAW;IACpB,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE,UAAU;CACnB,CAAC,CAAC;AAE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tC,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,IAAI,EAAE,WAAW;IACjB,MAAM,EAAE,WAAW;CACpB,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;AAE1G;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;AAE/F;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;IACvC,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,SAAS,CAAC,YAAY,CAAC;IAC9B,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,WAAW,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IAC7D,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC;IAC/B,WAAW,EAAE,SAAS,CAAC,UAAU,CAAC;CACnC,CAAC,CAAC"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ /**
6
+ * Executing a unit of the runner protocol: {@link executeUnit}, the one
7
+ * TypeScript unit runner, over a {@link UnitIO}.
8
+ *
9
+ * A unit (`UnitType`) runs a program on its inputs, merges the parts of one
10
+ * output that earlier units wrote, or takes a delivered collection in, and
11
+ * names where its output and its result go. A program's output is written by
12
+ * its kind:
13
+ * - a value as one blob, or as a manifest directory when it is a collection;
14
+ * - an array through the Writer;
15
+ * - a set or a dict through the RunSorter, as sorted runs;
16
+ * - a fold by folding every emitted value into an accumulator.
17
+ *
18
+ * A delivery taken in is read a segment at a time from its file, and written
19
+ * through the Writer as a manifest directory (`intakeBeast2For`).
20
+ *
21
+ * Collections are written as manifest directories, which a store takes in by
22
+ * linking their files. The result (`UnitResultType`) records the outcome —
23
+ * `ok`, or the failure's message and source locations — with where the time
24
+ * went and the host's peak memory. east-c and east-py implement the same
25
+ * protocol, and the conformance corpus holds the three to the same output
26
+ * bytes and outcomes.
27
+ *
28
+ * The work reaches its files only through the UnitIO it is given, its
29
+ * platform functions only through the host's resolver, and the host's memory
30
+ * only through the gauges it is given, so the same code runs as east-node's
31
+ * `exec` over this machine's files and in a browser's Web Worker over an
32
+ * `InMemoryUnitIO` — east-c's shape (`east/unit.h`), where the unit machinery
33
+ * is library code and its CLI wires it to files.
34
+ */
35
+ import { type EastTypeValue } from "./type_of_type.js";
36
+ import type { PlatformFunction } from "./platform.js";
37
+ import { type Beast2LazyStats } from "./serialization/beast2/index.js";
38
+ import type { Unit, UnitResult } from "./runner_protocol.js";
39
+ import { type UnitIO, type UnitInputReport } from "./runner_io.js";
40
+ /** One input of a run unit, as a report names it. */
41
+ export interface UnitRunInput {
42
+ /** The input's file, as the unit names it. */
43
+ readonly path: string;
44
+ /** The type the input is read as: its parameter's. */
45
+ readonly type: EastTypeValue;
46
+ }
47
+ /**
48
+ * What a host hears of a run unit's inputs as its work goes: the account a
49
+ * runner's `exec -v` prints, which reaches a task's log.
50
+ *
51
+ * @remarks
52
+ * The report says what happened and the host says it in its own words:
53
+ * east-node's prints the lines east-c and east-py print. A merge or intake
54
+ * unit reads no program inputs, and reports nothing.
55
+ */
56
+ export interface UnitRunReport extends UnitInputReport {
57
+ /**
58
+ * The program is loaded and its signature fits the unit: it is about to run
59
+ * on `inputs`, none read yet.
60
+ *
61
+ * @param program - the program's file, as the unit names it
62
+ * @param inputs - the inputs, in parameter order
63
+ */
64
+ running(program: string, inputs: readonly UnitRunInput[]): void;
65
+ /**
66
+ * The program ran, and its output was written — or either failed: what
67
+ * reading lazy input `index` came to. Inputs decoded whole have no reads to
68
+ * account for.
69
+ *
70
+ * @param index - the input's position
71
+ * @param path - the input's file, as the unit names it
72
+ * @param stats - its segment decodes and fence probes, and whether an
73
+ * operation the pager cannot serve read it whole
74
+ * @param bytesRead - the bytes its reads read from its files
75
+ */
76
+ lazyReads(index: number, path: string, stats: Beast2LazyStats, bytesRead: number): void;
77
+ }
78
+ /** What a host gives {@link executeUnit} besides the unit and its files. */
79
+ export interface ExecuteUnitOptions {
80
+ /**
81
+ * Resolves the platform functions of one package the unit lists, as the
82
+ * runner names it. Asked once per package, in the unit's order, before the
83
+ * work begins; a package it cannot resolve fails the unit with its message.
84
+ *
85
+ * @param name - the package's name
86
+ * @returns its platform functions
87
+ */
88
+ platforms(name: string): readonly PlatformFunction[] | Promise<readonly PlatformFunction[]>;
89
+ /** The host's resident memory now, in bytes: what a lazily opened input
90
+ * weighs a read of it whole by, and what the report says an input decoded
91
+ * whole added. Without it, both come to 0. east-node's reads
92
+ * `process.memoryUsage.rss()`. */
93
+ resident?: () => number;
94
+ /** The host's peak resident memory in bytes, read once the work is done:
95
+ * the result's `peakBytes`. Without it the result says 0 — the host does
96
+ * not measure memory, as a browser does not. */
97
+ peakBytes?: () => bigint;
98
+ /** The decoded weight, in bytes, each lazily opened input's pager keeps of
99
+ * the segments its keyed and index reads decode (v5/SPEC.md, "The pager's
100
+ * cache"): 256 MiB without it. east-node's reads it from
101
+ * `EAST_PAGED_CACHE_BYTES`, as east-c's pager does. */
102
+ cacheBytes?: number;
103
+ /** Hears how a run unit reads its inputs: without it, nothing is reported
104
+ * and nothing is measured for a report. */
105
+ report?: UnitRunReport;
106
+ }
107
+ /**
108
+ * Executes a unit: does its work over `io`, writes its output there, and says
109
+ * how it went.
110
+ *
111
+ * @param unit - the unit; the files it names are read and written through `io`
112
+ * @param io - the unit's files
113
+ * @param options - the host's platform resolver, its memory gauges, the
114
+ * decoded weight a lazy input's pager keeps, and who hears how the inputs
115
+ * are read
116
+ * @returns the result — a failure is its outcome, never a throw. The host
117
+ * writes it where the unit's `result` says, if it keeps it
118
+ *
119
+ * @remarks
120
+ * The unit's thread grant caps the frame pool for the rest of the process: a
121
+ * grant of one frames every output inline. A unit whose host places its
122
+ * segments as they are read (`fetch`) has `io` asked for each segment of a
123
+ * staged manifest before it is read ({@link UnitIO.segment}).
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * const io = new InMemoryUnitIO(files); // the unit and every file it names
128
+ * const unit = decodeBeast2For(UnitType)(io.read("unit.beast2"));
129
+ * const result = await executeUnit(unit, io, { platforms: (name) => packages.get(name)! });
130
+ * if (result.outcome.type === "ok") io.files.get("output.beast2"); // the output
131
+ * ```
132
+ */
133
+ export declare function executeUnit(unit: Unit, io: UnitIO, options: ExecuteUnitOptions): Promise<UnitResult>;
134
+ //# sourceMappingURL=runner_exec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner_exec.d.ts","sourceRoot":"","sources":["../../src/runner_exec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAuC,MAAM,mBAAmB,CAAC;AAM5F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAQL,KAAK,eAAe,EAGrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,IAAI,EAA2B,UAAU,EAAe,MAAM,sBAAsB,CAAC;AACnG,OAAO,EACL,KAAK,MAAM,EACX,KAAK,eAAe,EAMrB,MAAM,gBAAgB,CAAC;AAexB,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B,8CAA8C;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;CAC9B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD;;;;;;OAMG;IACH,OAAO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