@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,98 @@
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 { PlatformFunction } from "../platform.js";
6
+ import type { EastType, ValueTypeOf } from "../types.js";
7
+ import type { QueryErrorType } from "./types.js";
8
+ import { type CheckJqResult } from "./jq/check.js";
9
+ /** A diagnostic of a query: the checker's, or an error its run raised. */
10
+ export type QueryDiagnostic = ValueTypeOf<typeof QueryErrorType>;
11
+ /**
12
+ * A query that does not check, or whose run raised an error: its diagnostics,
13
+ * and a message that lists each error with its line and column in the jq text.
14
+ *
15
+ * @remarks
16
+ * `diagnostics` holds the checker's diagnostics, lints included, when the
17
+ * query does not check; for an error raised while it ran, one `runtime`
18
+ * diagnostic whose message is the East error's and whose span is the jq
19
+ * node that raised it.
20
+ */
21
+ export declare class QueryError extends Error {
22
+ /** The diagnostics, in the order found. */
23
+ readonly diagnostics: QueryDiagnostic[];
24
+ /**
25
+ * @param diagnostics - the diagnostics; the message lists those of error severity
26
+ */
27
+ constructor(diagnostics: QueryDiagnostic[]);
28
+ }
29
+ /** Options for {@link evaluateJq}. */
30
+ export interface EvaluateJqOptions {
31
+ /** The input's type: required with a program's text. */
32
+ inputType?: EastType;
33
+ /** The input is an e3 root, a struct of datasets: each field the query reads is passed alone, so a lazy one stays lazy. */
34
+ root?: boolean;
35
+ /** Allow the tooling-only builtins, whose platform functions `platform` gives (`devdocs/QUERY.md` §15.9). */
36
+ tooling?: boolean;
37
+ /** Platform functions, for function values in the input that need them. */
38
+ platform?: PlatformFunction[];
39
+ }
40
+ /**
41
+ * Checks, translates, compiles and runs a jq query over a value.
42
+ *
43
+ * @param program - the query's text, or what {@link checkJq} made of it
44
+ * @param input - the input: a decoded value, or a lazy one
45
+ * @param options - `inputType` with text; `root` for an e3 root; `tooling`;
46
+ * `platform` for function values that need one
47
+ * @returns the result: the element for a `one` query, an option for `maybe`,
48
+ * an array for `many`
49
+ * @throws {QueryError} When the query does not check, carrying the
50
+ * checker's diagnostics; or when its run raises an error, as one `runtime`
51
+ * diagnostic at the jq node that raised it.
52
+ *
53
+ * @remarks
54
+ * The compiled function is cached by the query's canonical text, its input
55
+ * type and the options, so a query run again compiles once. With `root`, the
56
+ * input is a struct and each field the query reads is its own argument.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const Order = StructType({ id: IntegerType, total: FloatType });
61
+ * const orders = [{ id: 1n, total: 250.0 }, { id: 2n, total: 1200.0 }];
62
+ * evaluateJq("[.[] | select(.total > 1000) | .id]", orders, { inputType: ArrayType(Order) });
63
+ * // [2n]
64
+ * ```
65
+ */
66
+ export declare function evaluateJq(program: string | CheckJqResult, input: unknown, options?: EvaluateJqOptions): unknown;
67
+ /**
68
+ * The `runtime` diagnostic for an error a query's run raised: its message, at
69
+ * the jq node that raised it.
70
+ *
71
+ * @param checked - what {@link checkJq} made of the query that ran
72
+ * @param message - the error's message, as the runtime raised it
73
+ * @param at - the 1-based line and column in the jq text the error names, when
74
+ * it names one: a translation's IR carries each node's place in the jq, which
75
+ * a runtime reports with the error (`at jq:2:26`)
76
+ * @returns the diagnostic: `runtime`, its message led by the code, and its span
77
+ * the node that raised it — `none` when the error names no place in the jq
78
+ *
79
+ * @remarks
80
+ * The node that raised it is the innermost that starts at that line and
81
+ * column and can raise: a literal, `.` or a variable, which can start at the
82
+ * same place, cannot. When no node that can raise starts there, the span is
83
+ * empty, at that place. {@link evaluateJq} places the errors of the runs it
84
+ * makes so, and a host that runs a query elsewhere — as one-shot runs a
85
+ * translation — places what the runtime reported the same way.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const checked = checkJq("[.[] | 10 / .]", ArrayType(IntegerType));
90
+ * runtimeErrorAt(checked, "Division by zero", { line: 1, column: 8 });
91
+ * // { code: "runtime", message: "runtime: Division by zero", span: some({ line: 1n, column: 8n, offset: 7n, length: 6n }), … }
92
+ * ```
93
+ */
94
+ export declare function runtimeErrorAt(checked: CheckJqResult, message: string, at?: {
95
+ readonly line: number;
96
+ readonly column: number;
97
+ }): QueryDiagnostic;
98
+ //# sourceMappingURL=evaluate.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MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,eAAe,CAahJ"}
@@ -0,0 +1,193 @@
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
+ * Running a jq query from a host: checked, translated to East IR, compiled
7
+ * once and cached, then called (`devdocs/QUERY.md` §15).
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ import { EastError } from "../error.js";
12
+ import { printFor } from "../serialization/east.js";
13
+ import { EastTypeType, canonicalTypeValue, toEastTypeValue } from "../type_of_type.js";
14
+ import { checkJq } from "./jq/check.js";
15
+ import { report } from "./jq/messages.js";
16
+ import { printJq } from "./jq/print.js";
17
+ import { childPath, jqChildren } from "./jq/spans.js";
18
+ import { translateJq } from "./jq/translate.js";
19
+ /**
20
+ * A query that does not check, or whose run raised an error: its diagnostics,
21
+ * and a message that lists each error with its line and column in the jq text.
22
+ *
23
+ * @remarks
24
+ * `diagnostics` holds the checker's diagnostics, lints included, when the
25
+ * query does not check; for an error raised while it ran, one `runtime`
26
+ * diagnostic whose message is the East error's and whose span is the jq
27
+ * node that raised it.
28
+ */
29
+ export class QueryError extends Error {
30
+ /** The diagnostics, in the order found. */
31
+ diagnostics;
32
+ /**
33
+ * @param diagnostics - the diagnostics; the message lists those of error severity
34
+ */
35
+ constructor(diagnostics) {
36
+ const errors = diagnostics.filter(d => d.severity.type === "error");
37
+ super((errors.length > 0 ? errors : diagnostics).map(d => {
38
+ const where = d.span.type === "some" ? `jq ${d.span.value.line}:${d.span.value.column}: ` : "";
39
+ return `${where}${d.message}`;
40
+ }).join("\n"));
41
+ this.name = "QueryError";
42
+ this.diagnostics = diagnostics;
43
+ }
44
+ }
45
+ /** Compiled queries by their canonical text, input type and options, the oldest dropped past {@link CACHE_SIZE}. */
46
+ const cache = new Map();
47
+ const CACHE_SIZE = 64;
48
+ const printTypeValue = printFor(EastTypeType);
49
+ /**
50
+ * Checks, translates, compiles and runs a jq query over a value.
51
+ *
52
+ * @param program - the query's text, or what {@link checkJq} made of it
53
+ * @param input - the input: a decoded value, or a lazy one
54
+ * @param options - `inputType` with text; `root` for an e3 root; `tooling`;
55
+ * `platform` for function values that need one
56
+ * @returns the result: the element for a `one` query, an option for `maybe`,
57
+ * an array for `many`
58
+ * @throws {QueryError} When the query does not check, carrying the
59
+ * checker's diagnostics; or when its run raises an error, as one `runtime`
60
+ * diagnostic at the jq node that raised it.
61
+ *
62
+ * @remarks
63
+ * The compiled function is cached by the query's canonical text, its input
64
+ * type and the options, so a query run again compiles once. With `root`, the
65
+ * input is a struct and each field the query reads is its own argument.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * const Order = StructType({ id: IntegerType, total: FloatType });
70
+ * const orders = [{ id: 1n, total: 250.0 }, { id: 2n, total: 1200.0 }];
71
+ * evaluateJq("[.[] | select(.total > 1000) | .id]", orders, { inputType: ArrayType(Order) });
72
+ * // [2n]
73
+ * ```
74
+ */
75
+ export function evaluateJq(program, input, options = {}) {
76
+ const compiled = compile(program, options);
77
+ const args = compiled.translation.inputs.map(i => i.name === null ? input : input[i.name]);
78
+ try {
79
+ return compiled.run(...args);
80
+ }
81
+ catch (e) {
82
+ if (e instanceof EastError) {
83
+ const at = e.location.find((l) => l.filename === "jq");
84
+ throw new QueryError([runtimeErrorAt(compiled.checked, e.eastMessage, at === undefined ? undefined : { line: Number(at.line), column: Number(at.column) })]);
85
+ }
86
+ throw e;
87
+ }
88
+ }
89
+ /** A query checked, translated and compiled, from the cache when it was before. */
90
+ function compile(program, options) {
91
+ let checked;
92
+ let key;
93
+ if (typeof program === "string") {
94
+ if (options.inputType === undefined)
95
+ throw new TypeError("evaluateJq: a query's text needs options.inputType");
96
+ const typeKey = printTypeValue(canonicalTypeValue(toEastTypeValue(options.inputType)));
97
+ key = `${program}\u0000${typeKey}\u0000${options.root === true}\u0000${options.tooling === true}`;
98
+ const hit = cache.get(key);
99
+ if (hit !== undefined)
100
+ return hit;
101
+ checked = checkJq(program, options.inputType, { root: options.root === true, tooling: options.tooling === true });
102
+ }
103
+ else {
104
+ checked = program;
105
+ if (checked.program === null)
106
+ throw new QueryError(checked.diagnostics);
107
+ const typeKey = printTypeValue(canonicalTypeValue(toEastTypeValue(checked.inputType)));
108
+ key = `${printJq(checked.program).text}\u0000${typeKey}\u0000${checked.source.root}\u0000${options.tooling === true}`;
109
+ const hit = cache.get(key);
110
+ if (hit !== undefined)
111
+ return hit;
112
+ }
113
+ if (checked.program === null)
114
+ throw new QueryError(checked.diagnostics);
115
+ const translation = translateJq(checked, { tooling: options.tooling === true });
116
+ const run = translation.fn().toIR().compile(options.platform ?? []);
117
+ const compiled = { translation, checked, run };
118
+ if (cache.size >= CACHE_SIZE)
119
+ cache.delete(cache.keys().next().value);
120
+ cache.set(key, compiled);
121
+ return compiled;
122
+ }
123
+ /**
124
+ * The `runtime` diagnostic for an error a query's run raised: its message, at
125
+ * the jq node that raised it.
126
+ *
127
+ * @param checked - what {@link checkJq} made of the query that ran
128
+ * @param message - the error's message, as the runtime raised it
129
+ * @param at - the 1-based line and column in the jq text the error names, when
130
+ * it names one: a translation's IR carries each node's place in the jq, which
131
+ * a runtime reports with the error (`at jq:2:26`)
132
+ * @returns the diagnostic: `runtime`, its message led by the code, and its span
133
+ * the node that raised it — `none` when the error names no place in the jq
134
+ *
135
+ * @remarks
136
+ * The node that raised it is the innermost that starts at that line and
137
+ * column and can raise: a literal, `.` or a variable, which can start at the
138
+ * same place, cannot. When no node that can raise starts there, the span is
139
+ * empty, at that place. {@link evaluateJq} places the errors of the runs it
140
+ * makes so, and a host that runs a query elsewhere — as one-shot runs a
141
+ * translation — places what the runtime reported the same way.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * const checked = checkJq("[.[] | 10 / .]", ArrayType(IntegerType));
146
+ * runtimeErrorAt(checked, "Division by zero", { line: 1, column: 8 });
147
+ * // { code: "runtime", message: "runtime: Division by zero", span: some({ line: 1n, column: 8n, offset: 7n, length: 6n }), … }
148
+ * ```
149
+ */
150
+ export function runtimeErrorAt(checked, message, at) {
151
+ const text = checked.source.text;
152
+ let range;
153
+ if (at !== undefined) {
154
+ const offset = offsetOf(text, at.line, at.column);
155
+ const kinds = checked.program === null ? new Map() : nodeKinds(checked.program);
156
+ for (const [path, span] of checked.source.spans) {
157
+ if (span.from !== offset || LEAVES.has(kinds.get(path) ?? ""))
158
+ continue;
159
+ if (range === undefined || span.to - span.from < range.to - range.from)
160
+ range = span;
161
+ }
162
+ range ??= { from: offset, to: offset };
163
+ }
164
+ return report(text, "runtime", range, `runtime: ${message}`);
165
+ }
166
+ /** The kinds of node that cannot raise an error. */
167
+ const LEAVES = new Set(["identity", "literal", "variable"]);
168
+ /** Each node's kind, by its path. */
169
+ function nodeKinds(program) {
170
+ const kinds = new Map();
171
+ const visit = (node, path) => {
172
+ kinds.set(path, node.type);
173
+ for (const child of jqChildren(node))
174
+ if (child.node !== undefined)
175
+ visit(child.node, childPath(path, child.step));
176
+ };
177
+ visit(program, "");
178
+ return kinds;
179
+ }
180
+ /** The offset of a line and column in a text, both 1-based, as `toQuerySpan` counts them. */
181
+ function offsetOf(text, line, column) {
182
+ let current = 1;
183
+ let start = 0;
184
+ for (let i = 0; i < text.length && current < line; i++) {
185
+ const c = text.charCodeAt(i);
186
+ if (c === 10 || (c === 13 && text.charCodeAt(i + 1) !== 10)) {
187
+ current += 1;
188
+ start = i + 1;
189
+ }
190
+ }
191
+ return Math.min(text.length, start + column - 1);
192
+ }
193
+ //# sourceMappingURL=evaluate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../../src/query/evaluate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,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AC;IAChB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,OAAO,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;QACvD,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;YAAC,OAAO,IAAI,CAAC,CAAC;YAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;QAAC,CAAC;IAC/F,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1,17 @@
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
+ export { JqLiteralType, JqPatternType, JqType, QueryMultiplicityType, QueryCallType, QuerySpanType, QueryEditType, QueryFixType, QueryErrorType, } from "./types.js";
6
+ export { QueryError, evaluateJq, runtimeErrorAt, type EvaluateJqOptions, type QueryDiagnostic } from "./evaluate.js";
7
+ export { translateJq, TranslationError, type JqTranslation, type TranslateJqOptions } from "./jq/translate.js";
8
+ export { splitJq, type JqCombine, type JqPruning, type JqSplit, type JqSplitCall, type JqSplitOutput, type JqSplitStages, type JqTotal, type JqWhole, type JqWholeReason, type SplitJqOptions, } from "./jq/split.js";
9
+ export { lexJq, type JqToken, type JqTokenKind } from "./jq/lex.js";
10
+ export { parseJq, type ParsedJq } from "./jq/parse.js";
11
+ export { printJq, type PrintJqOptions, type PrintedJq } from "./jq/print.js";
12
+ export { pathAt, spanOf, toQuerySpan, type JqNode, type JqPattern, type JqRange, type JqSpans } from "./jq/spans.js";
13
+ export { checkJq, type CheckJqOptions, type CheckJqResult, type CheckedNode, type CheckedStage, type JqMultiplicity, } from "./jq/check.js";
14
+ export { describeJqType, plainKind } from "./jq/describe.js";
15
+ export { SummaryLeafType, SummaryType, summaryProgram, type SummaryProgramOptions } from "./jq/summary.js";
16
+ export { completeJq, type CompleteJqOptions, type JqCompletion, type JqCompletionKind, type JqCompletions } from "./jq/complete.js";
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/query/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,aAAa,EAAE,aAAa,EAAE,MAAM,EACpC,qBAAqB,EAAE,aAAa,EACpC,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,GAC3D,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AACrH,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC/G,OAAO,EACL,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,OAAO,EAC7H,KAAK,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,cAAc,GACtD,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AACrH,OAAO,EACL,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,GAC3G,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAC3G,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,17 @@
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
+ export { JqLiteralType, JqPatternType, JqType, QueryMultiplicityType, QueryCallType, QuerySpanType, QueryEditType, QueryFixType, QueryErrorType, } from "./types.js";
6
+ export { QueryError, evaluateJq, runtimeErrorAt } from "./evaluate.js";
7
+ export { translateJq, TranslationError } from "./jq/translate.js";
8
+ export { splitJq, } from "./jq/split.js";
9
+ export { lexJq } from "./jq/lex.js";
10
+ export { parseJq } from "./jq/parse.js";
11
+ export { printJq } from "./jq/print.js";
12
+ export { pathAt, spanOf, toQuerySpan } from "./jq/spans.js";
13
+ export { checkJq, } from "./jq/check.js";
14
+ export { describeJqType, plainKind } from "./jq/describe.js";
15
+ export { SummaryLeafType, SummaryType, summaryProgram } from "./jq/summary.js";
16
+ export { completeJq } from "./jq/complete.js";
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/query/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,aAAa,EAAE,aAAa,EAAE,MAAM,EACpC,qBAAqB,EAAE,aAAa,EACpC,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,GAC3D,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAgD,MAAM,eAAe,CAAC;AACrH,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAA+C,MAAM,mBAAmB,CAAC;AAC/G,OAAO,EACL,OAAO,GAER,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAkC,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,OAAO,EAAiB,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,EAAuC,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAA2D,MAAM,eAAe,CAAC;AACrH,OAAO,EACL,OAAO,GACR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAA8B,MAAM,iBAAiB,CAAC;AAC3G,OAAO,EAAE,UAAU,EAAwF,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,174 @@
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 EastType } from "../../types.js";
6
+ import { type QueryFix } from "./messages.js";
7
+ import { type Proof, type Result } from "./shapes.js";
8
+ import type { JqNode, JqRange } from "./spans.js";
9
+ /**
10
+ * What a builtin's typing rule works with: the call, its input, and ways to
11
+ * check its arguments and report problems.
12
+ *
13
+ * @internal
14
+ */
15
+ export interface CallContext {
16
+ /** The builtin's name as called (`@base64` for a format). */
17
+ readonly name: string;
18
+ /** The call node's path. */
19
+ readonly path: string;
20
+ /** The call's input. */
21
+ readonly input: Result;
22
+ /** The arguments, as written. */
23
+ readonly args: readonly JqNode[];
24
+ /** Each argument's path. */
25
+ readonly argPaths: readonly string[];
26
+ /** The call's range. */
27
+ readonly range: JqRange | undefined;
28
+ /** The builtin being typed. */
29
+ readonly builtin: Builtin;
30
+ /** An argument's range. */
31
+ argRange(i: number): JqRange | undefined;
32
+ /** Checks argument `i` on an input: the call's input when none is given. */
33
+ arg(i: number, input?: Result): Result;
34
+ /** Argument `i`'s value when it is written as a literal. */
35
+ literal(i: number): {
36
+ type: EastType;
37
+ value: unknown;
38
+ } | undefined;
39
+ /** A literal node's value. */
40
+ literalOf(node: Extract<JqNode, {
41
+ type: "literal";
42
+ }>): {
43
+ type: EastType;
44
+ value: unknown;
45
+ };
46
+ /**
47
+ * Reads argument `i`, a literal, as `wanted` is written: an Integer as a
48
+ * Float, an ISO-8601 string as a DateTime, which its translation gives.
49
+ * Reports a string that is not an ISO-8601 date.
50
+ *
51
+ * @returns the type the literal is read as, or `undefined` when it is not
52
+ * such a literal
53
+ */
54
+ coerceArg(i: number, wanted: EastType): EastType | undefined;
55
+ /**
56
+ * Reads argument `i`, an array literal of literals, as an array of
57
+ * `wanted`: each element as {@link CallContext.coerceArg} reads one.
58
+ *
59
+ * @returns the array's new type, or `undefined` when it is not such an array
60
+ */
61
+ coerceArgElements(i: number, wanted: EastType): EastType | undefined;
62
+ /** How many problems have been reported so far: a rule's own tells it whether a coercion said why it failed. */
63
+ problems(): number;
64
+ /** Reports a problem at the call, or at argument `arg`. */
65
+ fail(code: string, message: string, options?: {
66
+ arg?: number;
67
+ suggestions?: string[];
68
+ fixes?: QueryFix[];
69
+ }): Result;
70
+ /** Reports a type error jq raises at run time; in a lenient place, no output instead. */
71
+ mismatch(code: string, message: string, arg?: number, fixes?: QueryFix[]): Result;
72
+ /** The fix that skips null inputs, `values | `, when the call can have a pipe put before it. */
73
+ skipNulls(): QueryFix | undefined;
74
+ /** Reports a lint at the call. */
75
+ warn(code: string, message: string, fixes?: QueryFix[]): void;
76
+ /** The call's text, or argument `i`'s. */
77
+ source(i?: number): string;
78
+ /** The one type a result's outputs share, or a reported `ambiguous_output`. */
79
+ collect(result: Result, arg?: number): EastType | undefined;
80
+ /** Refuses the call when its input is the whole root. */
81
+ refuseRoot(): boolean;
82
+ /** Adds what a condition proves to a result's shape. */
83
+ narrow(result: Result, proves: readonly Proof[]): Result;
84
+ /** Reports reading, un-narrowed, a payload field the call needs a value of, with the "Narrow first" fix. */
85
+ narrowFirst(type: EastType): Result;
86
+ /** Reports an array builtin run on each element of a stream, with the fix that collects it. */
87
+ onElement(type: EastType): Result;
88
+ /** The program's text. */
89
+ readonly text: string;
90
+ /** Any node's range, by its path. */
91
+ rangeAt(path: string): JqRange | undefined;
92
+ /** What checking a node gave, by its path, in this instance. */
93
+ resultAt(path: string): Result | undefined;
94
+ }
95
+ /**
96
+ * A catalog entry.
97
+ *
98
+ * @remarks
99
+ * - `status` — `supported`; `excluded` (host access and nondeterminism,
100
+ * §11); `unavailable` (no East definition, with `reason`); `not_yet`; or
101
+ * `tooling` (tooling-only, §9).
102
+ * - `arities` — the numbers of arguments it takes.
103
+ * - `east` — the East builtins or library functions that define it, for
104
+ * `QUERY.md`'s table and the translator.
105
+ * - `typing` — the checker's rule, for a builtin a query may call.
106
+ *
107
+ * @internal
108
+ */
109
+ export interface Builtin {
110
+ readonly status: "supported" | "excluded" | "unavailable" | "not_yet" | "tooling";
111
+ readonly arities: readonly number[];
112
+ readonly east: string;
113
+ readonly reason?: string;
114
+ /** What it takes and gives, for `QUERY.md`'s table. */
115
+ readonly rule?: string;
116
+ /** How many outputs it gives for one input, for `QUERY.md`'s table. */
117
+ readonly outputs?: string;
118
+ readonly typing?: (ctx: CallContext) => Result;
119
+ }
120
+ /**
121
+ * A step of a path `del` deletes at: a field, an index or key, a slice, every
122
+ * element (`.[]`), or the elements a `select` keeps.
123
+ *
124
+ * @internal
125
+ */
126
+ export type DelStep = {
127
+ readonly kind: "field";
128
+ readonly name: string;
129
+ } | {
130
+ readonly kind: "index";
131
+ readonly node: JqNode;
132
+ readonly path: string;
133
+ } | {
134
+ readonly kind: "slice";
135
+ readonly path: string;
136
+ } | {
137
+ readonly kind: "iterate";
138
+ } | {
139
+ readonly kind: "select";
140
+ readonly path: string;
141
+ };
142
+ /**
143
+ * The paths `del`'s argument names, each as its steps from `.`.
144
+ *
145
+ * @param node - the argument
146
+ * @param path - its node path
147
+ * @returns the paths, or `undefined` when the argument is not made of field
148
+ * reads, indexes, slices, `.[]`, `select`, `|` and `,`
149
+ *
150
+ * @internal
151
+ */
152
+ export declare function delPaths(node: JqNode, path: string): DelStep[][] | undefined;
153
+ /**
154
+ * The catalog: every builtin of jq 1.8 and East's additions, by name, and
155
+ * each format by `@name`.
156
+ *
157
+ * @internal
158
+ */
159
+ export declare const BUILTINS: ReadonlyMap<string, Builtin>;
160
+ /**
161
+ * Whether a name is a builtin a jq query can call: one of jq 1.8's, or one of
162
+ * East's additions, whether or not a query may use it.
163
+ *
164
+ * @param name - the name, as written in the query
165
+ * @returns `true` for a builtin's name
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * isJqBuiltin("select"); // true
170
+ * isJqBuiltin("revenue"); // false: a `def` could name it
171
+ * ```
172
+ */
173
+ export declare function isJqBuiltin(name: string): boolean;
174
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../../src/query/jq/catalog.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,EAEsC,KAAK,QAAQ,EACzD,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAEgD,KAAK,KAAK,EAAE,KAAK,MAAM,EAC7E,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE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