@elaraai/east 1.0.83 → 1.0.85

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 (252) 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/index.d.ts +3 -0
  69. package/dist/src/index.d.ts.map +1 -1
  70. package/dist/src/index.js +3 -0
  71. package/dist/src/index.js.map +1 -1
  72. package/dist/src/internal.d.ts +4 -0
  73. package/dist/src/internal.d.ts.map +1 -1
  74. package/dist/src/internal.js +9 -0
  75. package/dist/src/internal.js.map +1 -1
  76. package/dist/src/location.d.ts +22 -0
  77. package/dist/src/location.d.ts.map +1 -1
  78. package/dist/src/location.js +31 -0
  79. package/dist/src/location.js.map +1 -1
  80. package/dist/src/naming.d.ts +12 -7
  81. package/dist/src/naming.d.ts.map +1 -1
  82. package/dist/src/naming.js +30 -13
  83. package/dist/src/naming.js.map +1 -1
  84. package/dist/src/naming.spec.js +49 -0
  85. package/dist/src/naming.spec.js.map +1 -1
  86. package/dist/src/portable.spec.d.ts +6 -0
  87. package/dist/src/portable.spec.d.ts.map +1 -0
  88. package/dist/src/portable.spec.js +181 -0
  89. package/dist/src/portable.spec.js.map +1 -0
  90. package/dist/src/query/evaluate.d.ts +98 -0
  91. package/dist/src/query/evaluate.d.ts.map +1 -0
  92. package/dist/src/query/evaluate.js +193 -0
  93. package/dist/src/query/evaluate.js.map +1 -0
  94. package/dist/src/query/index.d.ts +17 -0
  95. package/dist/src/query/index.d.ts.map +1 -0
  96. package/dist/src/query/index.js +17 -0
  97. package/dist/src/query/index.js.map +1 -0
  98. package/dist/src/query/jq/catalog.d.ts +174 -0
  99. package/dist/src/query/jq/catalog.d.ts.map +1 -0
  100. package/dist/src/query/jq/catalog.js +1740 -0
  101. package/dist/src/query/jq/catalog.js.map +1 -0
  102. package/dist/src/query/jq/check.d.ts +210 -0
  103. package/dist/src/query/jq/check.d.ts.map +1 -0
  104. package/dist/src/query/jq/check.js +2261 -0
  105. package/dist/src/query/jq/check.js.map +1 -0
  106. package/dist/src/query/jq/complete.d.ts +89 -0
  107. package/dist/src/query/jq/complete.d.ts.map +1 -0
  108. package/dist/src/query/jq/complete.js +320 -0
  109. package/dist/src/query/jq/complete.js.map +1 -0
  110. package/dist/src/query/jq/describe.d.ts +53 -0
  111. package/dist/src/query/jq/describe.d.ts.map +1 -0
  112. package/dist/src/query/jq/describe.js +149 -0
  113. package/dist/src/query/jq/describe.js.map +1 -0
  114. package/dist/src/query/jq/lex.d.ts +118 -0
  115. package/dist/src/query/jq/lex.d.ts.map +1 -0
  116. package/dist/src/query/jq/lex.js +371 -0
  117. package/dist/src/query/jq/lex.js.map +1 -0
  118. package/dist/src/query/jq/literals.d.ts +49 -0
  119. package/dist/src/query/jq/literals.d.ts.map +1 -0
  120. package/dist/src/query/jq/literals.js +78 -0
  121. package/dist/src/query/jq/literals.js.map +1 -0
  122. package/dist/src/query/jq/messages.d.ts +126 -0
  123. package/dist/src/query/jq/messages.d.ts.map +1 -0
  124. package/dist/src/query/jq/messages.js +172 -0
  125. package/dist/src/query/jq/messages.js.map +1 -0
  126. package/dist/src/query/jq/parse.d.ts +70 -0
  127. package/dist/src/query/jq/parse.d.ts.map +1 -0
  128. package/dist/src/query/jq/parse.js +1013 -0
  129. package/dist/src/query/jq/parse.js.map +1 -0
  130. package/dist/src/query/jq/print.d.ts +59 -0
  131. package/dist/src/query/jq/print.d.ts.map +1 -0
  132. package/dist/src/query/jq/print.js +587 -0
  133. package/dist/src/query/jq/print.js.map +1 -0
  134. package/dist/src/query/jq/shapes.d.ts +345 -0
  135. package/dist/src/query/jq/shapes.d.ts.map +1 -0
  136. package/dist/src/query/jq/shapes.js +584 -0
  137. package/dist/src/query/jq/shapes.js.map +1 -0
  138. package/dist/src/query/jq/spans.d.ts +133 -0
  139. package/dist/src/query/jq/spans.d.ts.map +1 -0
  140. package/dist/src/query/jq/spans.js +195 -0
  141. package/dist/src/query/jq/spans.js.map +1 -0
  142. package/dist/src/query/jq/split.d.ts +334 -0
  143. package/dist/src/query/jq/split.d.ts.map +1 -0
  144. package/dist/src/query/jq/split.js +2108 -0
  145. package/dist/src/query/jq/split.js.map +1 -0
  146. package/dist/src/query/jq/strftime.d.ts +20 -0
  147. package/dist/src/query/jq/strftime.d.ts.map +1 -0
  148. package/dist/src/query/jq/strftime.js +65 -0
  149. package/dist/src/query/jq/strftime.js.map +1 -0
  150. package/dist/src/query/jq/summary.d.ts +139 -0
  151. package/dist/src/query/jq/summary.d.ts.map +1 -0
  152. package/dist/src/query/jq/summary.js +222 -0
  153. package/dist/src/query/jq/summary.js.map +1 -0
  154. package/dist/src/query/jq/translate-builtins.d.ts +21 -0
  155. package/dist/src/query/jq/translate-builtins.d.ts.map +1 -0
  156. package/dist/src/query/jq/translate-builtins.js +1873 -0
  157. package/dist/src/query/jq/translate-builtins.js.map +1 -0
  158. package/dist/src/query/jq/translate.d.ts +627 -0
  159. package/dist/src/query/jq/translate.d.ts.map +1 -0
  160. package/dist/src/query/jq/translate.js +3364 -0
  161. package/dist/src/query/jq/translate.js.map +1 -0
  162. package/dist/src/query/types.d.ts +505 -0
  163. package/dist/src/query/types.d.ts.map +1 -0
  164. package/dist/src/query/types.js +231 -0
  165. package/dist/src/query/types.js.map +1 -0
  166. package/dist/src/runner_exec.d.ts +134 -0
  167. package/dist/src/runner_exec.d.ts.map +1 -0
  168. package/dist/src/runner_exec.js +371 -0
  169. package/dist/src/runner_exec.js.map +1 -0
  170. package/dist/src/runner_exec.spec.d.ts +6 -0
  171. package/dist/src/runner_exec.spec.d.ts.map +1 -0
  172. package/dist/src/runner_exec.spec.js +198 -0
  173. package/dist/src/runner_exec.spec.js.map +1 -0
  174. package/dist/src/runner_io.d.ts +370 -0
  175. package/dist/src/runner_io.d.ts.map +1 -0
  176. package/dist/src/runner_io.js +563 -0
  177. package/dist/src/runner_io.js.map +1 -0
  178. package/dist/src/runner_io.spec.d.ts +6 -0
  179. package/dist/src/runner_io.spec.d.ts.map +1 -0
  180. package/dist/src/runner_io.spec.js +224 -0
  181. package/dist/src/runner_io.spec.js.map +1 -0
  182. package/dist/src/runner_merge.d.ts +95 -0
  183. package/dist/src/runner_merge.d.ts.map +1 -0
  184. package/dist/src/runner_merge.js +238 -0
  185. package/dist/src/runner_merge.js.map +1 -0
  186. package/dist/src/runner_protocol.d.ts +60 -6
  187. package/dist/src/runner_protocol.d.ts.map +1 -1
  188. package/dist/src/runner_protocol.js +48 -6
  189. package/dist/src/runner_protocol.js.map +1 -1
  190. package/dist/src/serialization/beast2/index.d.ts +2 -2
  191. package/dist/src/serialization/beast2/index.d.ts.map +1 -1
  192. package/dist/src/serialization/beast2/index.js +1 -1
  193. package/dist/src/serialization/beast2/index.js.map +1 -1
  194. package/dist/src/serialization/beast2/v5/frames.d.ts +10 -6
  195. package/dist/src/serialization/beast2/v5/frames.d.ts.map +1 -1
  196. package/dist/src/serialization/beast2/v5/frames.js +10 -6
  197. package/dist/src/serialization/beast2/v5/frames.js.map +1 -1
  198. package/dist/src/serialization/beast2/v5/frames.spec.d.ts +6 -0
  199. package/dist/src/serialization/beast2/v5/frames.spec.d.ts.map +1 -0
  200. package/dist/src/serialization/beast2/v5/frames.spec.js +42 -0
  201. package/dist/src/serialization/beast2/v5/frames.spec.js.map +1 -0
  202. package/dist/src/serialization/beast2/v5/index.spec.js +108 -0
  203. package/dist/src/serialization/beast2/v5/index.spec.js.map +1 -1
  204. package/dist/src/serialization/beast2/v5/lazy.d.ts +74 -7
  205. package/dist/src/serialization/beast2/v5/lazy.d.ts.map +1 -1
  206. package/dist/src/serialization/beast2/v5/lazy.js +129 -27
  207. package/dist/src/serialization/beast2/v5/lazy.js.map +1 -1
  208. package/dist/src/serialization/beast2/v5/lazy.spec.js +251 -16
  209. package/dist/src/serialization/beast2/v5/lazy.spec.js.map +1 -1
  210. package/dist/src/serialization/beast2/v5/stream.d.ts +139 -23
  211. package/dist/src/serialization/beast2/v5/stream.d.ts.map +1 -1
  212. package/dist/src/serialization/beast2/v5/stream.js +196 -44
  213. package/dist/src/serialization/beast2/v5/stream.js.map +1 -1
  214. package/dist/src/serialization/beast2/v5/type-section.d.ts.map +1 -1
  215. package/dist/src/serialization/beast2/v5/type-section.js +25 -12
  216. package/dist/src/serialization/beast2/v5/type-section.js.map +1 -1
  217. package/dist/src/serialization/beast2/v5/type-section.spec.d.ts +6 -0
  218. package/dist/src/serialization/beast2/v5/type-section.spec.d.ts.map +1 -0
  219. package/dist/src/serialization/beast2/v5/type-section.spec.js +41 -0
  220. package/dist/src/serialization/beast2/v5/type-section.spec.js.map +1 -0
  221. package/dist/src/serialization/beast2/v5/weight.d.ts +36 -0
  222. package/dist/src/serialization/beast2/v5/weight.d.ts.map +1 -0
  223. package/dist/src/serialization/beast2/v5/weight.js +238 -0
  224. package/dist/src/serialization/beast2/v5/weight.js.map +1 -0
  225. package/dist/src/serialization/crc32.d.ts +38 -0
  226. package/dist/src/serialization/crc32.d.ts.map +1 -0
  227. package/dist/src/serialization/crc32.js +70 -0
  228. package/dist/src/serialization/crc32.js.map +1 -0
  229. package/dist/src/serialization/crc32.spec.d.ts +6 -0
  230. package/dist/src/serialization/crc32.spec.d.ts.map +1 -0
  231. package/dist/src/serialization/crc32.spec.js +92 -0
  232. package/dist/src/serialization/crc32.spec.js.map +1 -0
  233. package/dist/src/serialization/east-inferred.spec.js +4 -0
  234. package/dist/src/serialization/east-inferred.spec.js.map +1 -1
  235. package/dist/src/serialization/east.d.ts.map +1 -1
  236. package/dist/src/serialization/east.js +134 -110
  237. package/dist/src/serialization/east.js.map +1 -1
  238. package/dist/src/serialization/east.spec.js +185 -4
  239. package/dist/src/serialization/east.spec.js.map +1 -1
  240. package/dist/src/serialization/east_text.d.ts +25 -0
  241. package/dist/src/serialization/east_text.d.ts.map +1 -0
  242. package/dist/src/serialization/east_text.js +29 -0
  243. package/dist/src/serialization/east_text.js.map +1 -0
  244. package/dist/src/serialization/index.d.ts +1 -1
  245. package/dist/src/serialization/index.d.ts.map +1 -1
  246. package/dist/src/serialization/index.js +1 -1
  247. package/dist/src/serialization/index.js.map +1 -1
  248. package/dist/src/types.d.ts +1 -1
  249. package/dist/src/types.d.ts.map +1 -1
  250. package/dist/src/types.js +7 -6
  251. package/dist/src/types.js.map +1 -1
  252. package/package.json +7 -4
@@ -0,0 +1,133 @@
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
+ * Where the nodes of a jq program are in its text.
7
+ *
8
+ * A {@link JqType} value is an East value and carries no positions, so the
9
+ * parser and the printer return them beside it: a map from each node's path
10
+ * in the tree to its range of text.
11
+ *
12
+ * @packageDocumentation
13
+ */
14
+ import type { ValueTypeOf } from "../../types.js";
15
+ import type { JqPatternType, JqType, QuerySpanType } from "../types.js";
16
+ /** A node of a jq program. */
17
+ export type JqNode = ValueTypeOf<typeof JqType>;
18
+ /** A destructuring pattern of a jq program. */
19
+ export type JqPattern = ValueTypeOf<typeof JqPatternType>;
20
+ /** A range of text: `from` to `to`, exclusive, in UTF-16 code units. */
21
+ export interface JqRange {
22
+ /** Its first offset. */
23
+ from: number;
24
+ /** The offset after its last. */
25
+ to: number;
26
+ }
27
+ /**
28
+ * The ranges of text a program's nodes cover, by the nodes' paths.
29
+ *
30
+ * @remarks
31
+ * A node's path lists, from the root, each ancestor's case and the field or
32
+ * index that leads to the next node: `"pipe.left.call.args[1]"` is the second
33
+ * argument of the call on the left of the root pipe. The root's path is `""`.
34
+ * An option's payload is its case, `some`: `"array.some"` is the body of
35
+ * `[f]`. Patterns are nodes too: `"bind.patterns[0].array[1]"`.
36
+ */
37
+ export type JqSpans = ReadonlyMap<string, JqRange>;
38
+ /**
39
+ * A child of a node, with the step that leads to it.
40
+ *
41
+ * @internal
42
+ */
43
+ export type JqChild = {
44
+ step: string;
45
+ node: JqNode;
46
+ pattern?: undefined;
47
+ } | {
48
+ step: string;
49
+ pattern: JqPattern;
50
+ node?: undefined;
51
+ };
52
+ /**
53
+ * Joins a node's path and a step to a child.
54
+ *
55
+ * @param path - the node's path
56
+ * @param step - the step, as {@link jqChildren} gives it
57
+ * @returns the child's path
58
+ *
59
+ * @internal
60
+ */
61
+ export declare function childPath(path: string, step: string): string;
62
+ /**
63
+ * The children of a node, in the order they are written, with the steps that
64
+ * lead to them.
65
+ *
66
+ * @param node - a program node
67
+ * @returns its children
68
+ *
69
+ * @internal
70
+ */
71
+ export declare function jqChildren(node: JqNode): JqChild[];
72
+ /**
73
+ * The children of a pattern, with the steps that lead to them.
74
+ *
75
+ * @param pattern - a pattern
76
+ * @returns its sub-patterns
77
+ *
78
+ * @internal
79
+ */
80
+ export declare function jqPatternChildren(pattern: JqPattern): {
81
+ step: string;
82
+ pattern: JqPattern;
83
+ }[];
84
+ /**
85
+ * The range a node covers.
86
+ *
87
+ * @param spans - a program's spans, from the parser or the printer
88
+ * @param path - the node's path
89
+ * @returns its range, or `undefined` when the program has no such node
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const { spans } = parseJq(".orders | length");
94
+ * spanOf(spans, "pipe.right"); // { from: 10, to: 16 }
95
+ * ```
96
+ */
97
+ export declare function spanOf(spans: JqSpans, path: string): JqRange | undefined;
98
+ /**
99
+ * The innermost node covering an offset.
100
+ *
101
+ * @param spans - a program's spans, from the parser or the printer
102
+ * @param offset - an offset in the text, from 0 to its length
103
+ * @returns the path of the smallest range that holds the offset (its ends
104
+ * included), the deeper of two equal ranges; `undefined` when none does
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const { spans } = parseJq(".orders | length");
109
+ * pathAt(spans, 12); // "pipe.right"
110
+ * ```
111
+ */
112
+ export declare function pathAt(spans: JqSpans, offset: number): string | undefined;
113
+ /**
114
+ * Locates a range of text as a {@link QuerySpanType} value: its offset and
115
+ * length, and the line and column it starts at.
116
+ *
117
+ * @param text - the text
118
+ * @param from - the range's first offset, in UTF-16 code units
119
+ * @param to - the offset after its last
120
+ * @returns the span: `offset` 0-based, `line` and `column` 1-based, all in
121
+ * UTF-16 code units
122
+ *
123
+ * @remarks
124
+ * A line ends at `\n`, `\r\n` or a lone `\r`. A tab is one column, and a
125
+ * character outside the Basic Multilingual Plane is two.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * toQuerySpan(".a\n| .b", 5, 7); // { column: 3n, length: 2n, line: 2n, offset: 5n }
130
+ * ```
131
+ */
132
+ export declare function toQuerySpan(text: string, from: number, to: number): ValueTypeOf<typeof QuerySpanType>;
133
+ //# sourceMappingURL=spans.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spans.d.ts","sourceRoot":"","sources":["../../../../src/query/jq/spans.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAExE,8BAA8B;AAC9B,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,MAAM,CAAC,CAAC;AAEhD,+CAA+C;AAC/C,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,OAAO,aAAa,CAAC,CAAC;AAE1D,wEAAwE;AACxE,MAAM,WAAW,OAAO;IACtB,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnD;;;;GAIG;AACH,MAAM,MAAM,OAAO,GACf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,SAAS,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAE3D;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,CAmElD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,SAAS,CAAA;CAAE,EAAE,CAU5F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAExE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUzE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,WAAW,CAAC,OAAO,aAAa,CAAC,CAgBrG"}
@@ -0,0 +1,195 @@
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
+ * Joins a node's path and a step to a child.
7
+ *
8
+ * @param path - the node's path
9
+ * @param step - the step, as {@link jqChildren} gives it
10
+ * @returns the child's path
11
+ *
12
+ * @internal
13
+ */
14
+ export function childPath(path, step) {
15
+ return path === "" ? step : `${path}.${step}`;
16
+ }
17
+ /**
18
+ * The children of a node, in the order they are written, with the steps that
19
+ * lead to them.
20
+ *
21
+ * @param node - a program node
22
+ * @returns its children
23
+ *
24
+ * @internal
25
+ */
26
+ export function jqChildren(node) {
27
+ const n = (step, child) => ({ step, node: child });
28
+ const p = (step, child) => ({ step, pattern: child });
29
+ const some = (step, option) => option.type === "some" ? [n(`${step}.some`, option.value)] : [];
30
+ switch (node.type) {
31
+ case "alternative":
32
+ case "comma":
33
+ case "pipe":
34
+ case "binary":
35
+ return [n(`${node.type}.left`, node.value.left), n(`${node.type}.right`, node.value.right)];
36
+ case "array":
37
+ return some("array", node.value);
38
+ case "bind":
39
+ return [
40
+ n("bind.source", node.value.source),
41
+ ...node.value.patterns.map((pattern, i) => p(`bind.patterns[${i}]`, pattern)),
42
+ n("bind.body", node.value.body),
43
+ ];
44
+ case "call":
45
+ return node.value.args.map((arg, i) => n(`call.args[${i}]`, arg));
46
+ case "def":
47
+ return [n("def.body", node.value.body), n("def.rest", node.value.rest)];
48
+ case "field":
49
+ return [n("field.target", node.value.target)];
50
+ case "foreach":
51
+ return [
52
+ n("foreach.source", node.value.source), p("foreach.pattern", node.value.pattern),
53
+ n("foreach.init", node.value.init), n("foreach.update", node.value.update),
54
+ ...some("foreach.extract", node.value.extract),
55
+ ];
56
+ case "format":
57
+ return some("format.string", node.value.string);
58
+ case "if":
59
+ return [
60
+ ...node.value.branches.flatMap((branch, i) => [
61
+ n(`if.branches[${i}].condition`, branch.condition), n(`if.branches[${i}].then`, branch.then),
62
+ ]),
63
+ ...some("if.otherwise", node.value.otherwise),
64
+ ];
65
+ case "index":
66
+ return [n("index.target", node.value.target), n("index.index", node.value.index)];
67
+ case "iterate":
68
+ return [n("iterate.target", node.value.target)];
69
+ case "label":
70
+ return [n("label.body", node.value.body)];
71
+ case "negate":
72
+ return [n("negate", node.value)];
73
+ case "object":
74
+ return node.value.flatMap((entry, i) => [
75
+ ...(entry.key.type === "computed" ? [n(`object[${i}].key.computed`, entry.key.value)] : []),
76
+ ...some(`object[${i}].value`, entry.value),
77
+ ]);
78
+ case "reduce":
79
+ return [
80
+ n("reduce.source", node.value.source), p("reduce.pattern", node.value.pattern),
81
+ n("reduce.init", node.value.init), n("reduce.update", node.value.update),
82
+ ];
83
+ case "slice":
84
+ return [n("slice.target", node.value.target), ...some("slice.from", node.value.from), ...some("slice.to", node.value.to)];
85
+ case "string":
86
+ return node.value.flatMap((part, i) => part.type === "interpolate" ? [n(`string[${i}].interpolate`, part.value)] : []);
87
+ case "try":
88
+ return [n("try.body", node.value.body), ...some("try.catch", node.value.catch)];
89
+ case "update":
90
+ return [n("update.path", node.value.path), n("update.value", node.value.value)];
91
+ case "break":
92
+ case "descend":
93
+ case "identity":
94
+ case "literal":
95
+ case "variable":
96
+ return [];
97
+ }
98
+ }
99
+ /**
100
+ * The children of a pattern, with the steps that lead to them.
101
+ *
102
+ * @param pattern - a pattern
103
+ * @returns its sub-patterns
104
+ *
105
+ * @internal
106
+ */
107
+ export function jqPatternChildren(pattern) {
108
+ switch (pattern.type) {
109
+ case "array":
110
+ return pattern.value.map((item, i) => ({ step: `array[${i}]`, pattern: item }));
111
+ case "object":
112
+ return pattern.value.flatMap((entry, i) => entry.value.type === "some" ? [{ step: `object[${i}].value.some`, pattern: entry.value.value }] : []);
113
+ case "variable":
114
+ return [];
115
+ }
116
+ }
117
+ /**
118
+ * The range a node covers.
119
+ *
120
+ * @param spans - a program's spans, from the parser or the printer
121
+ * @param path - the node's path
122
+ * @returns its range, or `undefined` when the program has no such node
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * const { spans } = parseJq(".orders | length");
127
+ * spanOf(spans, "pipe.right"); // { from: 10, to: 16 }
128
+ * ```
129
+ */
130
+ export function spanOf(spans, path) {
131
+ return spans.get(path);
132
+ }
133
+ /**
134
+ * The innermost node covering an offset.
135
+ *
136
+ * @param spans - a program's spans, from the parser or the printer
137
+ * @param offset - an offset in the text, from 0 to its length
138
+ * @returns the path of the smallest range that holds the offset (its ends
139
+ * included), the deeper of two equal ranges; `undefined` when none does
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * const { spans } = parseJq(".orders | length");
144
+ * pathAt(spans, 12); // "pipe.right"
145
+ * ```
146
+ */
147
+ export function pathAt(spans, offset) {
148
+ let best;
149
+ for (const [path, { from, to }] of spans) {
150
+ if (offset < from || offset > to)
151
+ continue;
152
+ const width = to - from;
153
+ if (best === undefined || width < best.width || (width === best.width && path.length > best.path.length)) {
154
+ best = { path, width };
155
+ }
156
+ }
157
+ return best?.path;
158
+ }
159
+ /**
160
+ * Locates a range of text as a {@link QuerySpanType} value: its offset and
161
+ * length, and the line and column it starts at.
162
+ *
163
+ * @param text - the text
164
+ * @param from - the range's first offset, in UTF-16 code units
165
+ * @param to - the offset after its last
166
+ * @returns the span: `offset` 0-based, `line` and `column` 1-based, all in
167
+ * UTF-16 code units
168
+ *
169
+ * @remarks
170
+ * A line ends at `\n`, `\r\n` or a lone `\r`. A tab is one column, and a
171
+ * character outside the Basic Multilingual Plane is two.
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * toQuerySpan(".a\n| .b", 5, 7); // { column: 3n, length: 2n, line: 2n, offset: 5n }
176
+ * ```
177
+ */
178
+ export function toQuerySpan(text, from, to) {
179
+ let line = 1;
180
+ let lineStart = 0;
181
+ for (let i = 0; i < from && i < text.length; i++) {
182
+ const c = text.charCodeAt(i);
183
+ if (c === 10 || (c === 13 && text.charCodeAt(i + 1) !== 10)) {
184
+ line += 1;
185
+ lineStart = i + 1;
186
+ }
187
+ }
188
+ return {
189
+ column: BigInt(from - lineStart + 1),
190
+ length: BigInt(to - from),
191
+ line: BigInt(line),
192
+ offset: BigInt(from),
193
+ };
194
+ }
195
+ //# sourceMappingURL=spans.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spans.js","sourceRoot":"","sources":["../../../../src/query/jq/spans.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkDH;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,IAAY;IAClD,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC;AAChD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,CAAC,GAAG,CAAC,IAAY,EAAE,KAAa,EAAW,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,MAAM,CAAC,GAAG,CAAC,IAAY,EAAE,KAAgB,EAAW,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE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,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACjD,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC;YAC5D,IAAI,IAAI,CAAC,CAAC;YACV,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IACD,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,IAAI,GAAG,SAAS,GAAG,CAAC,CAAC;QACpC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC;QACzB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC;KACrB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,334 @@
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
+ import type { FunctionExpr } from "../../expr/function.js";
6
+ import { type EastType } from "../../types.js";
7
+ import type { CheckJqResult } from "./check.js";
8
+ import { type JqRange } from "./spans.js";
9
+ /** Options for {@link splitJq}. */
10
+ export interface SplitJqOptions {
11
+ /** A `many` query's limit, as `translateJq`'s: the final function keeps this many outputs, and one more, so a caller can tell they were cut short. */
12
+ maxOutputs?: number;
13
+ /**
14
+ * The rows a piece folds into its table before it sends the table's entries
15
+ * on; 32,768 when omitted. A test forces small flushes with it.
16
+ *
17
+ * @internal
18
+ */
19
+ flushRows?: number;
20
+ /**
21
+ * The share of a flush's rows its table's keys may be: at one key more, a
22
+ * piece sends the table on and the rest of its rows straight on; 1/32 when
23
+ * omitted. A test forces the bypass with 0, and stops it with 1.
24
+ *
25
+ * @internal
26
+ */
27
+ bypassRatio?: number;
28
+ }
29
+ /** A query split over one dataset's pieces, or why it runs as one unit. */
30
+ export type JqSplit = JqSplitCall | JqWhole;
31
+ /**
32
+ * A query split over one root dataset's pieces: the parts of a split call.
33
+ *
34
+ * @remarks
35
+ * A split call's arguments are the query's inputs, in {@link JqSplitCall.inputs}'
36
+ * order, the one named {@link JqSplitCall.over} partitioned. Each piece runs
37
+ * {@link JqSplitCall.piece} over its piece of that dataset and the other inputs
38
+ * whole, emitting into {@link JqSplitCall.output}'s kind; {@link JqSplitCall.then}
39
+ * runs once over the assembled output and then the inputs, and gives the
40
+ * query's result, exactly as `translateJq`'s translation gives it.
41
+ */
42
+ export interface JqSplitCall {
43
+ readonly kind: "split";
44
+ /** The root field whose dataset the pieces are cut from. */
45
+ readonly over: string;
46
+ /** The inputs the piece program and the final function take, in order: the root fields the query reads, as `translateJq`'s. */
47
+ readonly inputs: readonly {
48
+ readonly name: string;
49
+ readonly type: EastType;
50
+ }[];
51
+ /** The query's result type, as `translateJq`'s: `T`, `Option<T>` or `Array<T>` by its multiplicity. */
52
+ readonly resultType: EastType;
53
+ /** How the pieces' outputs combine: the split call's output kind. */
54
+ readonly output: JqSplitOutput;
55
+ /**
56
+ * The program each piece runs: a function of the inputs and then `emit`,
57
+ * which gives nothing; `over`'s input is the piece.
58
+ *
59
+ * @returns the function
60
+ */
61
+ piece(): FunctionExpr<any[], any>;
62
+ /**
63
+ * The final function, of the assembled output and then the inputs, which
64
+ * gives the query's result; `null` when the assembled output is the result.
65
+ *
66
+ * @returns the function, or `null`
67
+ */
68
+ then(): FunctionExpr<any[], any> | null;
69
+ /** What the split does, for its explanation. */
70
+ readonly stages: JqSplitStages;
71
+ /** The root fields bound before the stream: every piece reads each whole. */
72
+ readonly broadcast: readonly string[];
73
+ /**
74
+ * The root fields bound before the stream that the pieces read only at the
75
+ * row's key: dicts keyed as the dataset is, which a split call partitions
76
+ * with it, cut at the same keys (#942).
77
+ */
78
+ readonly copartitioned: readonly string[];
79
+ /**
80
+ * A join the pieces could read by key instead of whole: the split call's
81
+ * rows re-keyed first, then joined cut at the same keys; `null` when the
82
+ * query has none (#942).
83
+ */
84
+ readonly rekey: JqRekey | null;
85
+ /** The reads that skip what they don't need. */
86
+ readonly pruning: readonly JqPruning[];
87
+ }
88
+ /**
89
+ * A join a split can make by key instead of reading the other side whole in
90
+ * every piece (#942): when both datasets are large, the rows are first
91
+ * re-keyed by the join key in a split call of their own, and the query's
92
+ * split call then reads the re-keyed rows and the other side cut at the same
93
+ * keys, every row meeting its key in its piece.
94
+ *
95
+ * @remarks
96
+ * Re-keyed rows reach the pieces grouped by key, not in input order, so only
97
+ * a query whose combine does not depend on the rows' order re-keys: totals
98
+ * that count, add numbers, take the least or the greatest, test, or unite, a
99
+ * grouping by such totals, `unique`, and a `reduce` that adds numbers. The
100
+ * join call's answer is the split's: its output kind, programs and final
101
+ * function, a Float sum added in another grouping.
102
+ */
103
+ export interface JqRekey {
104
+ /** The root field the pieces read by key: the join's other side, a dict. */
105
+ readonly name: string;
106
+ /** The join key's jq: a field of the row, each lookup's. */
107
+ readonly key: JqRange;
108
+ /** The join key's type: the other side's keys'. */
109
+ readonly keyType: EastType;
110
+ /** The re-key call's output: each key's rows, concatenated in input order. */
111
+ readonly output: {
112
+ readonly kind: "dict";
113
+ readonly type: EastType;
114
+ merge(): FunctionExpr<any[], any>;
115
+ };
116
+ /**
117
+ * The program each piece of the re-key call runs: a function of the
118
+ * dataset's piece and then `emit`, which sends each row under its key.
119
+ *
120
+ * @returns the function
121
+ */
122
+ piece(): FunctionExpr<any[], any>;
123
+ /** The join call's inputs: the split's, the dataset's re-keyed. */
124
+ readonly inputs: readonly {
125
+ readonly name: string;
126
+ readonly type: EastType;
127
+ }[];
128
+ /**
129
+ * The program each piece of the join call runs: the split's, over the
130
+ * re-keyed rows, each key's in turn.
131
+ *
132
+ * @returns the function
133
+ */
134
+ joinPiece(): FunctionExpr<any[], any>;
135
+ /**
136
+ * The join call's final function: the split's, of the assembled output and
137
+ * then the join call's inputs; `null` when the assembled output is the
138
+ * result.
139
+ *
140
+ * @returns the function, or `null`
141
+ */
142
+ joinThen(): FunctionExpr<any[], any> | null;
143
+ }
144
+ /**
145
+ * How a split call's pieces combine: its output kind, with its programs and
146
+ * its zero.
147
+ *
148
+ * @remarks
149
+ * - `array`: the pieces' rows concatenated in input order.
150
+ * - `set`: the distinct rows.
151
+ * - `dict`: rows by key, the values of equal keys folded with `merge`, a
152
+ * function of the key and two values, in input order; no `merge` keeps the
153
+ * first.
154
+ * - `fold`: every piece's value folded with `combine`, a function of two
155
+ * values, starting from `zero`, in input order.
156
+ */
157
+ export type JqSplitOutput = {
158
+ readonly kind: "array";
159
+ readonly type: EastType;
160
+ } | {
161
+ readonly kind: "set";
162
+ readonly type: EastType;
163
+ } | {
164
+ readonly kind: "dict";
165
+ readonly type: EastType;
166
+ merge(): FunctionExpr<any[], any>;
167
+ } | {
168
+ readonly kind: "fold";
169
+ readonly type: EastType;
170
+ readonly zero: unknown;
171
+ combine(): FunctionExpr<any[], any>;
172
+ };
173
+ /** The parts of a query a split runs where, as ranges of its text. */
174
+ export interface JqSplitStages {
175
+ /** What each piece runs: from the read of the dataset through the last step done row by row. */
176
+ readonly piece: JqRange;
177
+ /** How the pieces' outputs combine. */
178
+ readonly combine: JqCombine;
179
+ /** What the final function runs once over the combined result; `null` when nothing follows the combine. */
180
+ readonly then: JqRange | null;
181
+ }
182
+ /**
183
+ * How a split's pieces' outputs combine, as its explanation says it.
184
+ *
185
+ * @remarks
186
+ * - `concat`: the rows, concatenated in input order.
187
+ * - `totals`: totals over every row, each combined by its rule.
188
+ * - `group`: rows grouped by a key, each group's totals combined by their
189
+ * rules; with no totals, each group's rows are collected.
190
+ * - `distinct`: the distinct rows (`unique`).
191
+ * - `distinct_by`: the first row of each key (`unique_by`).
192
+ * - `reduce`: a `reduce` into a dict, its updates combined by key, added
193
+ * (`+=`) or the last kept (`=`).
194
+ * - `top`: the first `rows` rows of a sort (`sort_by(g) | .[:n]`,
195
+ * `sort | first`), each piece's kept and merged by the key `g` gives
196
+ * (`null` for `sort`, by the row), then by input order (#942).
197
+ */
198
+ export type JqCombine = {
199
+ readonly kind: "concat";
200
+ } | {
201
+ readonly kind: "totals";
202
+ readonly range: JqRange;
203
+ readonly totals: readonly JqTotal[];
204
+ } | {
205
+ readonly kind: "group";
206
+ readonly range: JqRange;
207
+ readonly key: JqRange;
208
+ readonly totals: readonly JqTotal[] | null;
209
+ } | {
210
+ readonly kind: "distinct";
211
+ readonly range: JqRange;
212
+ } | {
213
+ readonly kind: "distinct_by";
214
+ readonly range: JqRange;
215
+ readonly key: JqRange;
216
+ } | {
217
+ readonly kind: "reduce";
218
+ readonly range: JqRange;
219
+ readonly key: JqRange;
220
+ readonly update: "add" | "replace";
221
+ } | {
222
+ readonly kind: "top";
223
+ readonly range: JqRange;
224
+ readonly key: JqRange | null;
225
+ readonly rows: number;
226
+ };
227
+ /**
228
+ * One total, and the rule its pieces' parts combine by: `count` counted,
229
+ * `add` added as `add` adds, `min` and `max` the least and the greatest (by a
230
+ * key, for `min_by` and `max_by`), `first` and `last`, `any` (or) and `all`
231
+ * (and), and `union`, the distinct values.
232
+ */
233
+ export interface JqTotal {
234
+ /** The total's jq. */
235
+ readonly range: JqRange;
236
+ /** How its parts combine. */
237
+ readonly rule: "count" | "add" | "min" | "max" | "first" | "last" | "any" | "all" | "union";
238
+ }
239
+ /** A query that runs as one unit, and why. */
240
+ export interface JqWhole {
241
+ readonly kind: "whole";
242
+ /** Why it is not split. */
243
+ readonly reason: JqWholeReason;
244
+ /** The reads that skip what they don't need. */
245
+ readonly pruning: readonly JqPruning[];
246
+ }
247
+ /**
248
+ * Why a query runs as one unit.
249
+ *
250
+ * @remarks
251
+ * - `no_stream`: it works through no dataset's rows: it reads a count, a key,
252
+ * or a value whole.
253
+ * - `nested`: it works through a dataset's rows inside an expression, not as
254
+ * its own pipeline.
255
+ * - `stops_early`: it keeps only its first outputs, which one unit stops for
256
+ * as soon as it has them; `range` is the step that keeps them, or `null`
257
+ * for a stream's own outputs, which a caller caps.
258
+ * - `position`: a step takes rows by their position, which one unit reads only
259
+ * as far as it needs.
260
+ * - `every_row`: a step needs every row at once, as a sort does, and no work
261
+ * is done row by row before it.
262
+ * - `state`: a step carries state from row to row.
263
+ * - `calls`: the work done row by row calls a function value, which may call a
264
+ * platform function the runner does not load.
265
+ * - `reads_again`: it reads the dataset it works through again, outside the
266
+ * stream.
267
+ * - `key`: it groups by a key that is not one value a dict can hold.
268
+ * - `shape`: it is not a pipeline the planner splits.
269
+ */
270
+ export interface JqWholeReason {
271
+ readonly code: "no_stream" | "nested" | "stops_early" | "position" | "every_row" | "state" | "calls" | "reads_again" | "key" | "shape";
272
+ /** The jq the reason is about, when it is about some. */
273
+ readonly range: JqRange | null;
274
+ /** The builtin or the dataset the reason names, when it names one. */
275
+ readonly name: string | null;
276
+ }
277
+ /**
278
+ * A read that skips what it doesn't need.
279
+ *
280
+ * @remarks
281
+ * - `count`: `.D | length` reads the count from the dataset's index, and no
282
+ * segment.
283
+ * - `seek`: `.D[k]` or `.D | has(k)` reads only the segment that holds the key.
284
+ * - `stop`: a stream that stops early reads only the segments it reaches.
285
+ */
286
+ export interface JqPruning {
287
+ readonly kind: "count" | "seek" | "stop";
288
+ /** The dataset, by its root field. */
289
+ readonly name: string;
290
+ /** The jq that reads it. */
291
+ readonly range: JqRange;
292
+ }
293
+ /**
294
+ * Splits a checked query over one dataset's pieces, or says why it runs as one
295
+ * unit.
296
+ *
297
+ * @param checked - what `checkJq` made of the query, checked as an e3 root; it
298
+ * must have no error
299
+ * @param options - `maxOutputs` for a `many` query's limit
300
+ * @returns the split call's parts, or the reason it runs as one unit, with the
301
+ * reads that skip what they don't need either way
302
+ * @throws {TranslationError} When the query does not check, or was not checked
303
+ * as an e3 root.
304
+ *
305
+ * @remarks
306
+ * A query splits when its pipeline reads one root dataset, `.D`, `.D[]` or
307
+ * `[.D[] | f]`, and works through its rows: `map(f)`, `[.[] | f]`, `flatten`,
308
+ * and every step of a stream. Then:
309
+ * - **totals** over the rows (`length`, `add`, `min` / `max` and `_by`,
310
+ * `.[0]` / `first`, `.[-1]` / `last`, `any`, `all`, `unique`, each perhaps
311
+ * after `map(g)`, inside any expression of them) fold;
312
+ * - `group_by(k) | map(E)` combines by key, `E`'s totals field by field, or
313
+ * each group's rows collected when `E` is not made of totals;
314
+ * - `unique` is a set, and `unique_by(g)` a dict keeping each key's first row;
315
+ * - `reduce .[] as $x ({}; .[k] += v)`, or `= v`, combines by key;
316
+ * - anything else after the row work runs once, over the rows concatenated.
317
+ *
318
+ * Bindings before the stream, `.C as $c | …`, reach every piece: each piece
319
+ * reads their datasets whole. A query whose row work stops early (a stream's
320
+ * own outputs, `first`, `limit`) runs as one unit, which reads only as far as
321
+ * it needs.
322
+ *
323
+ * @example
324
+ * ```ts
325
+ * const Order = StructType({ region: StringType, total: FloatType });
326
+ * const root = StructType({ orders: ArrayType(Order) });
327
+ * const checked = checkJq(".orders | group_by(.region) | map({region: .[0].region, revenue: map(.total) | add})", root, { root: true });
328
+ * const split = splitJq(checked);
329
+ * split.kind; // "split"
330
+ * split.output.kind; // "dict": revenue by region, added
331
+ * ```
332
+ */
333
+ export declare function splitJq(checked: CheckJqResult, options?: SplitJqOptions): JqSplit;
334
+ //# sourceMappingURL=split.d.ts.map