@math.gl/sql 0.0.0-stage → 5.0.0-beta.12

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 (353) hide show
  1. package/LICENSE +249 -0
  2. package/README.md +26 -2
  3. package/THIRD-PARTY-NOTICES.md +5 -0
  4. package/dist/arrow/aggregates.d.ts +46 -0
  5. package/dist/arrow/aggregates.d.ts.map +1 -0
  6. package/dist/arrow/aggregates.js +289 -0
  7. package/dist/arrow/aggregates.js.map +1 -0
  8. package/dist/arrow/buffers.d.ts +30 -0
  9. package/dist/arrow/buffers.d.ts.map +1 -0
  10. package/dist/arrow/buffers.js +177 -0
  11. package/dist/arrow/buffers.js.map +1 -0
  12. package/dist/arrow/cast.d.ts +19 -0
  13. package/dist/arrow/cast.d.ts.map +1 -0
  14. package/dist/arrow/cast.js +138 -0
  15. package/dist/arrow/cast.js.map +1 -0
  16. package/dist/arrow/compiler.d.ts +10 -0
  17. package/dist/arrow/compiler.d.ts.map +1 -0
  18. package/dist/arrow/compiler.js +1538 -0
  19. package/dist/arrow/compiler.js.map +1 -0
  20. package/dist/arrow/float16.d.ts +7 -0
  21. package/dist/arrow/float16.d.ts.map +1 -0
  22. package/dist/arrow/float16.js +26 -0
  23. package/dist/arrow/float16.js.map +1 -0
  24. package/dist/arrow/index.cjs +3321 -0
  25. package/dist/arrow/index.cjs.map +6 -0
  26. package/dist/arrow/index.d.ts +5 -0
  27. package/dist/arrow/index.d.ts.map +1 -0
  28. package/dist/arrow/index.js +7 -0
  29. package/dist/arrow/index.js.map +1 -0
  30. package/dist/arrow/like.d.ts +3 -0
  31. package/dist/arrow/like.d.ts.map +1 -0
  32. package/dist/arrow/like.js +75 -0
  33. package/dist/arrow/like.js.map +1 -0
  34. package/dist/arrow/list-values.d.ts +14 -0
  35. package/dist/arrow/list-values.d.ts.map +1 -0
  36. package/dist/arrow/list-values.js +201 -0
  37. package/dist/arrow/list-values.js.map +1 -0
  38. package/dist/arrow/predicate.d.ts +7 -0
  39. package/dist/arrow/predicate.d.ts.map +1 -0
  40. package/dist/arrow/predicate.js +10 -0
  41. package/dist/arrow/predicate.js.map +1 -0
  42. package/dist/arrow/query-arrow-aggregate-snapshots.d.ts +24 -0
  43. package/dist/arrow/query-arrow-aggregate-snapshots.d.ts.map +1 -0
  44. package/dist/arrow/query-arrow-aggregate-snapshots.js +64 -0
  45. package/dist/arrow/query-arrow-aggregate-snapshots.js.map +1 -0
  46. package/dist/arrow/query-arrow-sql.d.ts +8 -0
  47. package/dist/arrow/query-arrow-sql.d.ts.map +1 -0
  48. package/dist/arrow/query-arrow-sql.js +223 -0
  49. package/dist/arrow/query-arrow-sql.js.map +1 -0
  50. package/dist/arrow/query-arrow-table.d.ts +36 -0
  51. package/dist/arrow/query-arrow-table.d.ts.map +1 -0
  52. package/dist/arrow/query-arrow-table.js +208 -0
  53. package/dist/arrow/query-arrow-table.js.map +1 -0
  54. package/dist/arrow/query-worker-entry.d.ts +2 -0
  55. package/dist/arrow/query-worker-entry.d.ts.map +1 -0
  56. package/dist/arrow/query-worker-entry.js +7 -0
  57. package/dist/arrow/query-worker-entry.js.map +1 -0
  58. package/dist/arrow/query-worker.d.ts +65 -0
  59. package/dist/arrow/query-worker.d.ts.map +1 -0
  60. package/dist/arrow/query-worker.js +135 -0
  61. package/dist/arrow/query-worker.js.map +1 -0
  62. package/dist/arrow/registry.d.ts +4 -0
  63. package/dist/arrow/registry.d.ts.map +1 -0
  64. package/dist/arrow/registry.js +66 -0
  65. package/dist/arrow/registry.js.map +1 -0
  66. package/dist/arrow/relational-query.d.ts +36 -0
  67. package/dist/arrow/relational-query.d.ts.map +1 -0
  68. package/dist/arrow/relational-query.js +174 -0
  69. package/dist/arrow/relational-query.js.map +1 -0
  70. package/dist/arrow/replace-arrow-columns.d.ts +8 -0
  71. package/dist/arrow/replace-arrow-columns.d.ts.map +1 -0
  72. package/dist/arrow/replace-arrow-columns.js +63 -0
  73. package/dist/arrow/replace-arrow-columns.js.map +1 -0
  74. package/dist/arrow/signature.d.ts +6 -0
  75. package/dist/arrow/signature.d.ts.map +1 -0
  76. package/dist/arrow/signature.js +51 -0
  77. package/dist/arrow/signature.js.map +1 -0
  78. package/dist/arrow/temporal-cast.d.ts +9 -0
  79. package/dist/arrow/temporal-cast.d.ts.map +1 -0
  80. package/dist/arrow/temporal-cast.js +60 -0
  81. package/dist/arrow/temporal-cast.js.map +1 -0
  82. package/dist/arrow/types.d.ts +62 -0
  83. package/dist/arrow/types.d.ts.map +1 -0
  84. package/dist/arrow/types.js +5 -0
  85. package/dist/arrow/types.js.map +1 -0
  86. package/dist/arrow/unnest-arrow-column.d.ts +22 -0
  87. package/dist/arrow/unnest-arrow-column.d.ts.map +1 -0
  88. package/dist/arrow/unnest-arrow-column.js +112 -0
  89. package/dist/arrow/unnest-arrow-column.js.map +1 -0
  90. package/dist/arrow/worker-entry.d.ts +2 -0
  91. package/dist/arrow/worker-entry.d.ts.map +1 -0
  92. package/dist/arrow/worker-entry.js +9 -0
  93. package/dist/arrow/worker-entry.js.map +1 -0
  94. package/dist/arrow/worker.cjs +4074 -0
  95. package/dist/arrow/worker.cjs.map +6 -0
  96. package/dist/arrow/worker.d.ts +58 -0
  97. package/dist/arrow/worker.d.ts.map +1 -0
  98. package/dist/arrow/worker.js +84 -0
  99. package/dist/arrow/worker.js.map +1 -0
  100. package/dist/color-functions/index.cjs +382 -0
  101. package/dist/color-functions/index.cjs.map +6 -0
  102. package/dist/color-functions/index.d.ts +26 -0
  103. package/dist/color-functions/index.d.ts.map +1 -0
  104. package/dist/color-functions/index.js +306 -0
  105. package/dist/color-functions/index.js.map +1 -0
  106. package/dist/diagnostic-log.d.ts +8 -0
  107. package/dist/diagnostic-log.d.ts.map +1 -0
  108. package/dist/diagnostic-log.js +15 -0
  109. package/dist/diagnostic-log.js.map +1 -0
  110. package/dist/expressions/ast.d.ts +12 -0
  111. package/dist/expressions/ast.d.ts.map +1 -0
  112. package/dist/expressions/ast.js +114 -0
  113. package/dist/expressions/ast.js.map +1 -0
  114. package/dist/expressions/columnar-predicate.d.ts +56 -0
  115. package/dist/expressions/columnar-predicate.d.ts.map +1 -0
  116. package/dist/expressions/columnar-predicate.js +176 -0
  117. package/dist/expressions/columnar-predicate.js.map +1 -0
  118. package/dist/expressions/evaluation-error.d.ts +14 -0
  119. package/dist/expressions/evaluation-error.d.ts.map +1 -0
  120. package/dist/expressions/evaluation-error.js +26 -0
  121. package/dist/expressions/evaluation-error.js.map +1 -0
  122. package/dist/expressions/expression-eval.d.ts +105 -0
  123. package/dist/expressions/expression-eval.d.ts.map +1 -0
  124. package/dist/expressions/expression-eval.js +330 -0
  125. package/dist/expressions/expression-eval.js.map +1 -0
  126. package/dist/expressions/function-libraries.d.ts +63 -0
  127. package/dist/expressions/function-libraries.d.ts.map +1 -0
  128. package/dist/expressions/function-libraries.js +69 -0
  129. package/dist/expressions/function-libraries.js.map +1 -0
  130. package/dist/expressions/function-registry.d.ts +93 -0
  131. package/dist/expressions/function-registry.d.ts.map +1 -0
  132. package/dist/expressions/function-registry.js +139 -0
  133. package/dist/expressions/function-registry.js.map +1 -0
  134. package/dist/expressions/get.d.ts +9 -0
  135. package/dist/expressions/get.d.ts.map +1 -0
  136. package/dist/expressions/get.js +32 -0
  137. package/dist/expressions/get.js.map +1 -0
  138. package/dist/expressions/index.cjs +1888 -0
  139. package/dist/expressions/index.cjs.map +6 -0
  140. package/dist/expressions/index.d.ts +13 -0
  141. package/dist/expressions/index.d.ts.map +1 -0
  142. package/dist/expressions/index.js +14 -0
  143. package/dist/expressions/index.js.map +1 -0
  144. package/dist/expressions/numeric-functions.d.ts +277 -0
  145. package/dist/expressions/numeric-functions.d.ts.map +1 -0
  146. package/dist/expressions/numeric-functions.js +52 -0
  147. package/dist/expressions/numeric-functions.js.map +1 -0
  148. package/dist/expressions/parse-expression-string.d.ts +21 -0
  149. package/dist/expressions/parse-expression-string.d.ts.map +1 -0
  150. package/dist/expressions/parse-expression-string.js +61 -0
  151. package/dist/expressions/parse-expression-string.js.map +1 -0
  152. package/dist/expressions/predicate-expression.d.ts +7 -0
  153. package/dist/expressions/predicate-expression.d.ts.map +1 -0
  154. package/dist/expressions/predicate-expression.js +112 -0
  155. package/dist/expressions/predicate-expression.js.map +1 -0
  156. package/dist/expressions/scalar-type.d.ts +6 -0
  157. package/dist/expressions/scalar-type.d.ts.map +1 -0
  158. package/dist/expressions/scalar-type.js +23 -0
  159. package/dist/expressions/scalar-type.js.map +1 -0
  160. package/dist/expressions/vendor/jsep/runtime.d.ts +3 -0
  161. package/dist/expressions/vendor/jsep/runtime.d.ts.map +1 -0
  162. package/dist/expressions/vendor/jsep/runtime.js +972 -0
  163. package/dist/expressions/vendor/jsep/runtime.js.map +1 -0
  164. package/dist/expressions/vendor/jsep/types.d.ts +148 -0
  165. package/dist/expressions/vendor/jsep/types.d.ts.map +1 -0
  166. package/dist/expressions/vendor/jsep/types.js +6 -0
  167. package/dist/expressions/vendor/jsep/types.js.map +1 -0
  168. package/dist/index.cjs +5294 -0
  169. package/dist/index.cjs.map +6 -0
  170. package/dist/index.d.ts +11 -0
  171. package/dist/index.d.ts.map +1 -0
  172. package/dist/index.js +11 -0
  173. package/dist/index.js.map +1 -0
  174. package/dist/math-functions/index.cjs +444 -0
  175. package/dist/math-functions/index.cjs.map +6 -0
  176. package/dist/math-functions/index.d.ts +44 -0
  177. package/dist/math-functions/index.d.ts.map +1 -0
  178. package/dist/math-functions/index.js +182 -0
  179. package/dist/math-functions/index.js.map +1 -0
  180. package/dist/parser/bind-sql-predicate.d.ts +4 -0
  181. package/dist/parser/bind-sql-predicate.d.ts.map +1 -0
  182. package/dist/parser/bind-sql-predicate.js +11 -0
  183. package/dist/parser/bind-sql-predicate.js.map +1 -0
  184. package/dist/parser/index.cjs +1807 -0
  185. package/dist/parser/index.cjs.map +6 -0
  186. package/dist/parser/index.d.ts +12 -0
  187. package/dist/parser/index.d.ts.map +1 -0
  188. package/dist/parser/index.js +11 -0
  189. package/dist/parser/index.js.map +1 -0
  190. package/dist/parser/parameter-snapshots.d.ts +21 -0
  191. package/dist/parser/parameter-snapshots.d.ts.map +1 -0
  192. package/dist/parser/parameter-snapshots.js +85 -0
  193. package/dist/parser/parameter-snapshots.js.map +1 -0
  194. package/dist/parser/parse-sql-expression.d.ts +50 -0
  195. package/dist/parser/parse-sql-expression.d.ts.map +1 -0
  196. package/dist/parser/parse-sql-expression.js +501 -0
  197. package/dist/parser/parse-sql-expression.js.map +1 -0
  198. package/dist/parser/parse-sql-predicate.d.ts +13 -0
  199. package/dist/parser/parse-sql-predicate.d.ts.map +1 -0
  200. package/dist/parser/parse-sql-predicate.js +365 -0
  201. package/dist/parser/parse-sql-predicate.js.map +1 -0
  202. package/dist/parser/parse-sql-query.d.ts +9 -0
  203. package/dist/parser/parse-sql-query.d.ts.map +1 -0
  204. package/dist/parser/parse-sql-query.js +81 -0
  205. package/dist/parser/parse-sql-query.js.map +1 -0
  206. package/dist/parser/parse-sql-select.d.ts +57 -0
  207. package/dist/parser/parse-sql-select.d.ts.map +1 -0
  208. package/dist/parser/parse-sql-select.js +247 -0
  209. package/dist/parser/parse-sql-select.js.map +1 -0
  210. package/dist/parser/parse-sql-statement.d.ts +54 -0
  211. package/dist/parser/parse-sql-statement.d.ts.map +1 -0
  212. package/dist/parser/parse-sql-statement.js +207 -0
  213. package/dist/parser/parse-sql-statement.js.map +1 -0
  214. package/dist/parser/query-types.d.ts +56 -0
  215. package/dist/parser/query-types.d.ts.map +1 -0
  216. package/dist/parser/query-types.js +5 -0
  217. package/dist/parser/query-types.js.map +1 -0
  218. package/dist/parser/sql-parameters.d.ts +29 -0
  219. package/dist/parser/sql-parameters.d.ts.map +1 -0
  220. package/dist/parser/sql-parameters.js +110 -0
  221. package/dist/parser/sql-parameters.js.map +1 -0
  222. package/dist/parser/sql-parse-error.d.ts +13 -0
  223. package/dist/parser/sql-parse-error.d.ts.map +1 -0
  224. package/dist/parser/sql-parse-error.js +20 -0
  225. package/dist/parser/sql-parse-error.js.map +1 -0
  226. package/dist/parser/sql-predicate-schema.d.ts +164 -0
  227. package/dist/parser/sql-predicate-schema.d.ts.map +1 -0
  228. package/dist/parser/sql-predicate-schema.js +249 -0
  229. package/dist/parser/sql-predicate-schema.js.map +1 -0
  230. package/dist/parser/sql-predicate-types.d.ts +48 -0
  231. package/dist/parser/sql-predicate-types.d.ts.map +1 -0
  232. package/dist/parser/sql-predicate-types.js +9 -0
  233. package/dist/parser/sql-predicate-types.js.map +1 -0
  234. package/dist/parser/sql-predicate.d.ts +6 -0
  235. package/dist/parser/sql-predicate.d.ts.map +1 -0
  236. package/dist/parser/sql-predicate.js +8 -0
  237. package/dist/parser/sql-predicate.js.map +1 -0
  238. package/dist/scales/arrow-domains.d.ts +22 -0
  239. package/dist/scales/arrow-domains.d.ts.map +1 -0
  240. package/dist/scales/arrow-domains.js +166 -0
  241. package/dist/scales/arrow-domains.js.map +1 -0
  242. package/dist/scales/arrow-scales.d.ts +44 -0
  243. package/dist/scales/arrow-scales.d.ts.map +1 -0
  244. package/dist/scales/arrow-scales.js +255 -0
  245. package/dist/scales/arrow-scales.js.map +1 -0
  246. package/dist/scales/compile-scale.d.ts +2 -0
  247. package/dist/scales/compile-scale.d.ts.map +1 -0
  248. package/dist/scales/compile-scale.js +5 -0
  249. package/dist/scales/compile-scale.js.map +1 -0
  250. package/dist/scales/conformance.cjs +180 -0
  251. package/dist/scales/conformance.cjs.map +6 -0
  252. package/dist/scales/conformance.d.ts +26 -0
  253. package/dist/scales/conformance.d.ts.map +1 -0
  254. package/dist/scales/conformance.js +164 -0
  255. package/dist/scales/conformance.js.map +1 -0
  256. package/dist/scales/hdr-colors.d.ts +2 -0
  257. package/dist/scales/hdr-colors.d.ts.map +1 -0
  258. package/dist/scales/hdr-colors.js +5 -0
  259. package/dist/scales/hdr-colors.js.map +1 -0
  260. package/dist/scales/index.cjs +4334 -0
  261. package/dist/scales/index.cjs.map +6 -0
  262. package/dist/scales/index.d.ts +10 -0
  263. package/dist/scales/index.d.ts.map +1 -0
  264. package/dist/scales/index.js +11 -0
  265. package/dist/scales/index.js.map +1 -0
  266. package/dist/scales/palettes.d.ts +2 -0
  267. package/dist/scales/palettes.d.ts.map +1 -0
  268. package/dist/scales/palettes.js +5 -0
  269. package/dist/scales/palettes.js.map +1 -0
  270. package/dist/scales/parse-sql-scale.d.ts +27 -0
  271. package/dist/scales/parse-sql-scale.d.ts.map +1 -0
  272. package/dist/scales/parse-sql-scale.js +257 -0
  273. package/dist/scales/parse-sql-scale.js.map +1 -0
  274. package/dist/scales/quantile-sketch.d.ts +2 -0
  275. package/dist/scales/quantile-sketch.d.ts.map +1 -0
  276. package/dist/scales/quantile-sketch.js +5 -0
  277. package/dist/scales/quantile-sketch.js.map +1 -0
  278. package/dist/scales/scale-types.d.ts +2 -0
  279. package/dist/scales/scale-types.d.ts.map +1 -0
  280. package/dist/scales/scale-types.js +5 -0
  281. package/dist/scales/scale-types.js.map +1 -0
  282. package/dist/scales/streaming-domains.d.ts +18 -0
  283. package/dist/scales/streaming-domains.d.ts.map +1 -0
  284. package/dist/scales/streaming-domains.js +115 -0
  285. package/dist/scales/streaming-domains.js.map +1 -0
  286. package/package.json +92 -4
  287. package/src/arrow/aggregates.ts +386 -0
  288. package/src/arrow/buffers.ts +177 -0
  289. package/src/arrow/cast.ts +160 -0
  290. package/src/arrow/compiler.ts +1778 -0
  291. package/src/arrow/float16.ts +25 -0
  292. package/src/arrow/index.ts +22 -0
  293. package/src/arrow/like.ts +72 -0
  294. package/src/arrow/list-values.ts +221 -0
  295. package/src/arrow/predicate.ts +19 -0
  296. package/src/arrow/query-arrow-aggregate-snapshots.ts +107 -0
  297. package/src/arrow/query-arrow-sql.ts +255 -0
  298. package/src/arrow/query-arrow-table.ts +298 -0
  299. package/src/arrow/query-worker-entry.ts +8 -0
  300. package/src/arrow/query-worker.ts +194 -0
  301. package/src/arrow/registry.ts +87 -0
  302. package/src/arrow/relational-query.ts +247 -0
  303. package/src/arrow/replace-arrow-columns.ts +71 -0
  304. package/src/arrow/signature.ts +50 -0
  305. package/src/arrow/temporal-cast.ts +66 -0
  306. package/src/arrow/types.ts +76 -0
  307. package/src/arrow/unnest-arrow-column.ts +145 -0
  308. package/src/arrow/worker-entry.ts +10 -0
  309. package/src/arrow/worker.ts +143 -0
  310. package/src/color-functions/index.ts +405 -0
  311. package/src/diagnostic-log.ts +20 -0
  312. package/src/expressions/ast.ts +143 -0
  313. package/src/expressions/columnar-predicate.ts +293 -0
  314. package/src/expressions/evaluation-error.ts +29 -0
  315. package/src/expressions/expression-eval.ts +489 -0
  316. package/src/expressions/function-libraries.ts +126 -0
  317. package/src/expressions/function-registry.ts +171 -0
  318. package/src/expressions/get.ts +37 -0
  319. package/src/expressions/index.ts +40 -0
  320. package/src/expressions/numeric-functions.ts +99 -0
  321. package/src/expressions/parse-expression-string.ts +80 -0
  322. package/src/expressions/predicate-expression.ts +128 -0
  323. package/src/expressions/scalar-type.ts +39 -0
  324. package/src/expressions/vendor/jsep/LICENSE.txt +23 -0
  325. package/src/expressions/vendor/jsep/runtime.ts +949 -0
  326. package/src/expressions/vendor/jsep/types.ts +191 -0
  327. package/src/index.ts +54 -0
  328. package/src/math-functions/index.ts +235 -0
  329. package/src/parser/bind-sql-predicate.ts +21 -0
  330. package/src/parser/index.ts +43 -0
  331. package/src/parser/parameter-snapshots.ts +103 -0
  332. package/src/parser/parse-sql-expression.ts +500 -0
  333. package/src/parser/parse-sql-predicate.ts +454 -0
  334. package/src/parser/parse-sql-query.ts +90 -0
  335. package/src/parser/parse-sql-select.ts +272 -0
  336. package/src/parser/parse-sql-statement.ts +260 -0
  337. package/src/parser/query-types.ts +71 -0
  338. package/src/parser/sql-parameters.ts +174 -0
  339. package/src/parser/sql-parse-error.ts +33 -0
  340. package/src/parser/sql-predicate-schema.ts +279 -0
  341. package/src/parser/sql-predicate-types.ts +91 -0
  342. package/src/parser/sql-predicate.ts +28 -0
  343. package/src/scales/arrow-domains.ts +190 -0
  344. package/src/scales/arrow-scales.ts +363 -0
  345. package/src/scales/compile-scale.ts +5 -0
  346. package/src/scales/conformance.ts +186 -0
  347. package/src/scales/hdr-colors.ts +5 -0
  348. package/src/scales/index.ts +37 -0
  349. package/src/scales/palettes.ts +5 -0
  350. package/src/scales/parse-sql-scale.ts +300 -0
  351. package/src/scales/quantile-sketch.ts +5 -0
  352. package/src/scales/scale-types.ts +5 -0
  353. package/src/scales/streaming-domains.ts +139 -0
@@ -0,0 +1,191 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: Copyright (c) 2013 Stephen Oney
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ // SPDX-FileComment: Extended types for portable AST inputs, including bigint literals and logical nodes.
5
+
6
+ declare namespace jsep {
7
+ export type baseTypes = string | number | bigint | boolean | RegExp | null | undefined | object;
8
+ export interface Expression {
9
+ type: string;
10
+ [key: string]: baseTypes | Expression | Array<baseTypes | Expression>;
11
+ }
12
+
13
+ export interface ArrayExpression extends Expression {
14
+ type: 'ArrayExpression';
15
+ /** The expression can be null in the case of array holes ([ , , ]) */
16
+ elements: Array<null | Expression>;
17
+ }
18
+
19
+ export interface BinaryExpression extends Expression {
20
+ type: 'BinaryExpression';
21
+ operator: string;
22
+ left: Expression;
23
+ right: Expression;
24
+ }
25
+
26
+ /** Logical node shape accepted from external expression AST producers. */
27
+ export interface LogicalExpression extends Expression {
28
+ type: 'LogicalExpression';
29
+ operator: '&&' | '||';
30
+ left: Expression;
31
+ right: Expression;
32
+ }
33
+
34
+ export interface CallExpression extends Expression {
35
+ type: 'CallExpression';
36
+ arguments: Expression[];
37
+ callee: Expression;
38
+ }
39
+
40
+ export interface Compound extends Expression {
41
+ type: 'Compound';
42
+ body: Expression[];
43
+ }
44
+
45
+ export interface SequenceExpression extends Expression {
46
+ type: 'SequenceExpression';
47
+ expressions: Expression[];
48
+ }
49
+
50
+ export interface ConditionalExpression extends Expression {
51
+ type: 'ConditionalExpression';
52
+ test: Expression;
53
+ consequent: Expression;
54
+ alternate: Expression;
55
+ }
56
+
57
+ export interface Identifier extends Expression {
58
+ type: 'Identifier';
59
+ name: string;
60
+ }
61
+
62
+ export interface Literal extends Expression {
63
+ type: 'Literal';
64
+ value: boolean | number | bigint | string | RegExp | null;
65
+ raw?: string;
66
+ }
67
+
68
+ export interface MemberExpression extends Expression {
69
+ type: 'MemberExpression';
70
+ computed: boolean;
71
+ object: Expression;
72
+ property: Expression;
73
+ optional?: boolean;
74
+ }
75
+
76
+ export interface ThisExpression extends Expression {
77
+ type: 'ThisExpression';
78
+ }
79
+
80
+ export interface UnaryExpression extends Expression {
81
+ type: 'UnaryExpression';
82
+ operator: string;
83
+ argument: Expression;
84
+ prefix?: boolean;
85
+ }
86
+
87
+ export type ExpressionType =
88
+ 'Compound'
89
+ | 'SequenceExpression'
90
+ | 'Identifier'
91
+ | 'MemberExpression'
92
+ | 'Literal'
93
+ | 'ThisExpression'
94
+ | 'CallExpression'
95
+ | 'UnaryExpression'
96
+ | 'BinaryExpression'
97
+ | 'ConditionalExpression'
98
+ | 'LogicalExpression'
99
+ | 'ArrayExpression';
100
+
101
+ export type CoreExpression =
102
+ ArrayExpression
103
+ | BinaryExpression
104
+ | LogicalExpression
105
+ | CallExpression
106
+ | Compound
107
+ | SequenceExpression
108
+ | ConditionalExpression
109
+ | Identifier
110
+ | Literal
111
+ | MemberExpression
112
+ | ThisExpression
113
+ | UnaryExpression;
114
+
115
+ export type PossibleExpression = Expression | undefined;
116
+ export interface HookScope {
117
+ index: number;
118
+ readonly expr: string;
119
+ readonly char: string; // current character of the expression
120
+ readonly code: number; // current character code of the expression
121
+ gobbleSpaces: () => void;
122
+ gobbleExpressions: (untilICode?: number) => Expression[];
123
+ gobbleExpression: () => Expression;
124
+ gobbleBinaryOp: () => PossibleExpression;
125
+ gobbleBinaryExpression: () => PossibleExpression;
126
+ gobbleToken: () => PossibleExpression;
127
+ gobbleTokenProperty: (node: Expression) => Expression
128
+ gobbleNumericLiteral: () => PossibleExpression;
129
+ gobbleStringLiteral: () => PossibleExpression;
130
+ gobbleIdentifier: () => PossibleExpression;
131
+ gobbleArguments: (untilICode: number) => PossibleExpression;
132
+ gobbleGroup: () => Expression;
133
+ gobbleArray: () => PossibleExpression;
134
+ throwError: (msg: string) => never;
135
+ }
136
+
137
+ export type HookType = 'gobble-expression' | 'after-expression' | 'gobble-token' | 'after-token' | 'gobble-spaces';
138
+ export type HookCallback = (this: HookScope, env: { node?: Expression }) => void;
139
+ type HookTypeObj = Partial<{ [key in HookType]: HookCallback}>
140
+
141
+ export interface IHooks extends HookTypeObj {
142
+ add(name: HookType, cb: HookCallback, first?: boolean): void;
143
+ add(obj: { [name in HookType]: HookCallback }, first?: boolean): void;
144
+ run(name: string, env: { context?: typeof jsep, node?: Expression }): void;
145
+ }
146
+ let hooks: IHooks;
147
+
148
+ export interface IPlugin {
149
+ name: string;
150
+ init: (this: typeof jsep) => void;
151
+ }
152
+ export interface IPlugins {
153
+ registered: { [name: string]: IPlugin };
154
+ register: (...plugins: IPlugin[]) => void;
155
+ }
156
+ let plugins: IPlugins;
157
+
158
+ let unary_ops: { [op: string]: any };
159
+ let binary_ops: { [op: string]: number };
160
+ let right_associative: Set<string>;
161
+ let additional_identifier_chars: Set<string>;
162
+ let literals: { [literal: string]: any };
163
+ let this_str: string;
164
+
165
+ function addBinaryOp(operatorName: string, precedence: number, rightToLeft?: boolean): void;
166
+
167
+ function addUnaryOp(operatorName: string): void;
168
+
169
+ function addLiteral(literalName: string, literalValue: any): void;
170
+
171
+ function addIdentifierChar(identifierName: string): void;
172
+
173
+ function removeBinaryOp(operatorName: string): void;
174
+
175
+ function removeUnaryOp(operatorName: string): void;
176
+
177
+ function removeLiteral(literalName: string): void;
178
+
179
+ function removeIdentifierChar(identifierName: string): void;
180
+
181
+ function removeAllBinaryOps(): void;
182
+
183
+ function removeAllUnaryOps(): void;
184
+
185
+ function removeAllLiterals(): void;
186
+
187
+ const version: string;
188
+ }
189
+
190
+ declare function jsep(val: string | jsep.Expression): jsep.Expression;
191
+ export type {jsep as Jsep};
package/src/index.ts ADDED
@@ -0,0 +1,54 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export {queryArrowSQL} from './arrow/query-arrow-sql';
6
+ export {
7
+ queryArrowTable,
8
+ queryArrowTableInBatches,
9
+ type ArrowBatchQuery,
10
+ type ArrowStreamingQuery,
11
+ type ArrowTableQuery
12
+ } from './arrow/query-arrow-table';
13
+ export type {ArrowQueryJoin, ArrowQueryOrder} from './arrow/relational-query';
14
+ export {
15
+ queryArrowAggregateSnapshots,
16
+ type ArrowAggregateSnapshot,
17
+ type ArrowAggregateSnapshotOptions
18
+ } from './arrow/query-arrow-aggregate-snapshots';
19
+ export {
20
+ compileArrowAggregates,
21
+ type ArrowAggregate,
22
+ type ArrowAggregateAccumulator,
23
+ type ArrowGroupedAggregateAccumulator,
24
+ type CompiledArrowAggregates
25
+ } from './arrow/aggregates';
26
+ export {replaceArrowColumns} from './arrow/replace-arrow-columns';
27
+ export type {
28
+ ArrowExpression,
29
+ ArrowExpressionOptions,
30
+ ArrowExpressionEvaluationOptions,
31
+ ArrowExpressionValue,
32
+ ArrowTableFunction,
33
+ ArrowTableFunctionPrototype,
34
+ ArrowTableFunctionType
35
+ } from './arrow/types';
36
+ export {
37
+ ExpressionEvaluationError,
38
+ isExpressionEvaluationError,
39
+ type ExpressionEvaluationErrorCode
40
+ } from './expressions/evaluation-error';
41
+
42
+ export type {
43
+ SQLParameterValue,
44
+ SQLParameters,
45
+ SQLParameterOptions,
46
+ SQLNumericArray,
47
+ SQLBinaryParameter
48
+ } from './parser/sql-parameters';
49
+ export {
50
+ prepareSQLParameters,
51
+ areSQLParametersEqual,
52
+ getSQLParameterNames,
53
+ type SQLParameterSnapshot
54
+ } from './parser/parameter-snapshots';
@@ -0,0 +1,235 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {
6
+ DataType,
7
+ Field,
8
+ Float16,
9
+ Float32,
10
+ Float64,
11
+ Int8,
12
+ Int16,
13
+ Int32,
14
+ Int64,
15
+ Uint8,
16
+ Uint16,
17
+ Uint32,
18
+ Uint64,
19
+ Precision,
20
+ makeData,
21
+ makeVector
22
+ } from 'apache-arrow';
23
+ import {NUMERIC_FUNCTION_DEFINITIONS, type ExpressionNumericType} from '../expressions';
24
+ import {ColumnReader, createValueValidator} from '../arrow/buffers';
25
+ import {ExpressionEvaluationError, isExpressionEvaluationError} from '../expressions';
26
+ import {float16Values, roundFloat16} from '../arrow/float16';
27
+ import type {ArrowTableFunction, ArrowExpressionValue} from '../arrow/types';
28
+
29
+ type Numeric = number | bigint;
30
+ type Operation = (x: Numeric, y: Numeric) => Numeric;
31
+ const types: Record<ExpressionNumericType, DataType> = {
32
+ int8: new Int8(),
33
+ int16: new Int16(),
34
+ int32: new Int32(),
35
+ int64: new Int64(),
36
+ uint8: new Uint8(),
37
+ uint16: new Uint16(),
38
+ uint32: new Uint32(),
39
+ uint64: new Uint64(),
40
+ float16: new Float16(),
41
+ float32: new Float32(),
42
+ float64: new Float64()
43
+ };
44
+
45
+ /** Internal declaration builder; public declarations take explicit numeric arguments. */
46
+ function declaration(
47
+ name: keyof typeof NUMERIC_FUNCTION_DEFINITIONS,
48
+ operation: Operation
49
+ ): ArrowTableFunction {
50
+ return {
51
+ name,
52
+ prototypes: NUMERIC_FUNCTION_DEFINITIONS[name].prototypes.map(prototype => {
53
+ const input = types[prototype.arguments[0]!];
54
+ const output = types[prototype.result];
55
+ const arity = prototype.arguments.length;
56
+ const validate = DataType.isInt(output) ? createValueValidator(output) : undefined;
57
+ let half: ((value: number) => number) | undefined;
58
+ function run(values: readonly ArrowExpressionValue[]): Numeric | null {
59
+ if (values.some(value => value === null)) return null;
60
+ if (values.some(value => typeof value === 'number' && Number.isNaN(value))) return NaN;
61
+ const x = values[0] as Numeric;
62
+ const y = values[1] as Numeric;
63
+ let result = operation(x, y);
64
+ if (DataType.isFloat(output)) {
65
+ result = Number(result);
66
+ if (output.precision === Precision.SINGLE) result = Math.fround(result);
67
+ if (output.precision === Precision.HALF) {
68
+ half ||= roundFloat16();
69
+ result = half(result);
70
+ }
71
+ const finiteInputs = values.every(
72
+ value => typeof value === 'bigint' || Number.isFinite(value)
73
+ );
74
+ if (finiteInputs && !Number.isFinite(result))
75
+ throw new ExpressionEvaluationError(
76
+ Number.isNaN(result) ? 'domain' : 'overflow',
77
+ `${name}: result outside ${output}`
78
+ );
79
+ if (
80
+ Number.isNaN(result) &&
81
+ !values.some(value => typeof value === 'number' && Number.isNaN(value))
82
+ )
83
+ throw new ExpressionEvaluationError('domain', `${name}: invalid argument`);
84
+ }
85
+ validate?.(result);
86
+ return result;
87
+ }
88
+ return {
89
+ arguments: Array.from(
90
+ {length: arity},
91
+ (_, index) => new Field(`arg${index + 1}`, input, true)
92
+ ),
93
+ result: new Field(name.toLowerCase(), output, false),
94
+ evaluateScalar: (...values) => run(values),
95
+ evaluate(vectors, {length, activeRows, reportError}) {
96
+ const readers = vectors.map(vector => new ColumnReader(vector));
97
+ const values: ArrowExpressionValue[] = new Array(arity);
98
+ const storage = new output.ArrayType(length);
99
+ const decoded =
100
+ DataType.isFloat(output) && output.precision === Precision.HALF
101
+ ? float16Values(storage as Uint16Array)
102
+ : storage;
103
+ const validity = new Uint8Array(Math.ceil(length / 8));
104
+ let nullCount = length;
105
+ for (let row = 0; row < length; row++) {
106
+ if (!activeRows[row]) continue;
107
+ for (let arg = 0; arg < arity; arg++) values[arg] = readers[arg]!.get(row);
108
+ let value: Numeric | null;
109
+ try {
110
+ value = run(values);
111
+ } catch (error) {
112
+ if (!reportError || !isExpressionEvaluationError(error)) throw error;
113
+ reportError(row, error);
114
+ continue;
115
+ }
116
+ if (value === null) continue;
117
+ // The prototype fixes both the output buffer and the scalar numeric kind.
118
+ (decoded as Float64Array)[row] = value as number;
119
+ validity[row >> 3] |= 1 << (row & 7);
120
+ nullCount--;
121
+ }
122
+ return makeVector(
123
+ makeData({
124
+ type: output,
125
+ length,
126
+ data: storage,
127
+ nullBitmap: validity,
128
+ nullCount
129
+ } as any)
130
+ );
131
+ }
132
+ };
133
+ })
134
+ };
135
+ }
136
+ function domain(condition: boolean, name: string): void {
137
+ if (condition) throw new ExpressionEvaluationError('domain', `${name}: invalid argument`);
138
+ }
139
+ function rounded(x: number): number {
140
+ if (Number.isInteger(x)) return x;
141
+ const truncated = Math.trunc(x);
142
+ return Math.abs(x - truncated) >= 0.5 ? truncated + Math.sign(x) : truncated;
143
+ }
144
+
145
+ /** Absolute value, preserving the argument type and checking integer overflow. */
146
+ export const ABS: ArrowTableFunction = /* @__PURE__ */ declaration('ABS', x =>
147
+ typeof x === 'bigint' ? (x < 0n ? -x : x) : Math.abs(x)
148
+ );
149
+ /** Sign (-1, 0, 1), preserving the argument type. */
150
+ export const SIGN: ArrowTableFunction = /* @__PURE__ */ declaration('SIGN', x =>
151
+ typeof x === 'bigint' ? (x < 0n ? -1n : x > 0n ? 1n : 0n) : Math.sign(x)
152
+ );
153
+ /** Round toward negative infinity. */
154
+ export const FLOOR: ArrowTableFunction = /* @__PURE__ */ declaration('FLOOR', x =>
155
+ typeof x === 'bigint' ? x : Math.floor(x)
156
+ );
157
+ /** Round toward positive infinity. */
158
+ export const CEILING: ArrowTableFunction = /* @__PURE__ */ declaration('CEILING', x =>
159
+ typeof x === 'bigint' ? x : Math.ceil(x)
160
+ );
161
+ /** Round to the nearest integer, with ties away from zero. */
162
+ export const ROUND: ArrowTableFunction = /* @__PURE__ */ declaration('ROUND', x =>
163
+ typeof x === 'bigint' ? x : rounded(x)
164
+ );
165
+ /** Truncate toward zero. */
166
+ export const TRUNC: ArrowTableFunction = /* @__PURE__ */ declaration('TRUNC', x =>
167
+ typeof x === 'bigint' ? x : Math.trunc(x)
168
+ );
169
+ /** Square root; negative arguments raise a domain error. */
170
+ export const SQRT: ArrowTableFunction = /* @__PURE__ */ declaration('SQRT', x => {
171
+ domain(x < 0, 'SQRT');
172
+ return Math.sqrt(Number(x));
173
+ });
174
+ /** Exponentiation; negative bases require integral exponents. */
175
+ export const POWER: ArrowTableFunction = /* @__PURE__ */ declaration('POWER', (x, y) => {
176
+ domain(
177
+ ((x === 0 || x === 0n) && y < 0) || (x < 0 && typeof y !== 'bigint' && !Number.isInteger(y)),
178
+ 'POWER'
179
+ );
180
+ // Preserve parity when a bigint exponent cannot be represented exactly as a number.
181
+ if (x < 0 && typeof y === 'bigint') return (y % 2n ? -1 : 1) * Math.pow(-Number(x), Number(y));
182
+ return Math.pow(Number(x), Number(y));
183
+ });
184
+ /** Natural exponential. */
185
+ export const EXP: ArrowTableFunction = /* @__PURE__ */ declaration('EXP', x => Math.exp(Number(x)));
186
+ /** Natural logarithm; arguments must be positive. */
187
+ export const LN: ArrowTableFunction = /* @__PURE__ */ declaration('LN', x => {
188
+ domain(x <= 0, 'LN');
189
+ return Math.log(Number(x));
190
+ });
191
+ /** Base-10 logarithm; arguments must be positive. */
192
+ export const LOG10: ArrowTableFunction = /* @__PURE__ */ declaration('LOG10', x => {
193
+ domain(x <= 0, 'LOG10');
194
+ return Math.log10(Number(x));
195
+ });
196
+ /** Sine of an angle in radians. */
197
+ export const SIN: ArrowTableFunction = /* @__PURE__ */ declaration('SIN', x => Math.sin(Number(x)));
198
+ /** Cosine of an angle in radians. */
199
+ export const COS: ArrowTableFunction = /* @__PURE__ */ declaration('COS', x => Math.cos(Number(x)));
200
+ /** Tangent of an angle in radians. */
201
+ export const TAN: ArrowTableFunction = /* @__PURE__ */ declaration('TAN', x => Math.tan(Number(x)));
202
+ /** Inverse sine in radians; arguments must be in [-1, 1]. */
203
+ export const ASIN: ArrowTableFunction = /* @__PURE__ */ declaration('ASIN', x => {
204
+ domain(x < -1 || x > 1, 'ASIN');
205
+ return Math.asin(Number(x));
206
+ });
207
+ /** Inverse cosine in radians; arguments must be in [-1, 1]. */
208
+ export const ACOS: ArrowTableFunction = /* @__PURE__ */ declaration('ACOS', x => {
209
+ domain(x < -1 || x > 1, 'ACOS');
210
+ return Math.acos(Number(x));
211
+ });
212
+ /** Inverse tangent in radians. */
213
+ export const ATAN: ArrowTableFunction = /* @__PURE__ */ declaration('ATAN', x =>
214
+ Math.atan(Number(x))
215
+ );
216
+ /** Angle of (x, y) in radians, with arguments ordered (y, x). */
217
+ export const ATAN2: ArrowTableFunction = /* @__PURE__ */ declaration('ATAN2', (y, x) =>
218
+ Math.atan2(Number(y), Number(x))
219
+ );
220
+ /** Convert radians to degrees. */
221
+ export const DEGREES: ArrowTableFunction = /* @__PURE__ */ declaration(
222
+ 'DEGREES',
223
+ x => Number(x) * (180 / Math.PI)
224
+ );
225
+ /** Convert degrees to radians. */
226
+ export const RADIANS: ArrowTableFunction = /* @__PURE__ */ declaration(
227
+ 'RADIANS',
228
+ x => Number(x) * (Math.PI / 180)
229
+ );
230
+ /** Remainder with the dividend's sign; a zero divisor raises divisionByZero. */
231
+ export const MOD: ArrowTableFunction = /* @__PURE__ */ declaration('MOD', (x, y) => {
232
+ if (y === 0 || y === 0n)
233
+ throw new ExpressionEvaluationError('divisionByZero', 'MOD: division by zero');
234
+ return typeof x === 'bigint' && typeof y === 'bigint' ? x % y : Number(x) % Number(y);
235
+ });
@@ -0,0 +1,21 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {bindColumnarPredicateParameters} from '../expressions/columnar-predicate';
6
+
7
+ import {validateSQLPredicate} from './sql-predicate-schema';
8
+ import {
9
+ type BoundSQLPredicate,
10
+ type SQLPredicate,
11
+ type SQLPredicateParameterValues
12
+ } from './sql-predicate-types';
13
+
14
+ /** Binds named parameter references in a portable SQL predicate without mutating the input AST. */
15
+ export function bindSQLPredicate(
16
+ predicate: SQLPredicate,
17
+ parameters: SQLPredicateParameterValues
18
+ ): BoundSQLPredicate {
19
+ validateSQLPredicate(predicate);
20
+ return bindColumnarPredicateParameters(predicate, parameters);
21
+ }
@@ -0,0 +1,43 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export {parseSQLQuery} from './parse-sql-query';
6
+ export {parseSQLSelect} from './parse-sql-select';
7
+ export type {SQLSelectParserOptions} from './parse-sql-select';
8
+ export * from './sql-predicate';
9
+ export type {
10
+ SQLQuery,
11
+ TableQuery,
12
+ TableSelection,
13
+ TableReference,
14
+ SQLCatalogQuery
15
+ } from './query-types';
16
+
17
+ export {parseSQLExpression} from './parse-sql-expression';
18
+
19
+ export {SQLParseError} from './sql-parse-error';
20
+ export {parseSQLSelectStatement, parseSQLSelectCompound} from './parse-sql-statement';
21
+ export type {
22
+ SQLSelectStatement,
23
+ SQLSelectStatementOptions,
24
+ SQLSelectCompound,
25
+ SQLTableBinding,
26
+ SQLJoin,
27
+ SQLSort
28
+ } from './parse-sql-statement';
29
+
30
+ export type {
31
+ SQLParameterValue,
32
+ SQLParameters,
33
+ SQLParameterOptions,
34
+ SQLNumericArray,
35
+ SQLBinaryParameter
36
+ } from './sql-parameters';
37
+
38
+ export {
39
+ prepareSQLParameters,
40
+ areSQLParametersEqual,
41
+ getSQLParameterNames,
42
+ type SQLParameterSnapshot
43
+ } from './parameter-snapshots';
@@ -0,0 +1,103 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {Expression} from '../expressions';
6
+ import {bindSQLParameter, type SQLParameters} from './sql-parameters';
7
+
8
+ /** Opaque immutable handle for validated, detached parameter values. */
9
+ export type SQLParameterSnapshot = Readonly<{kind: 'sql-parameter-snapshot'}>;
10
+ /** Private storage prevents consumers from mutating snapshot buffers. */
11
+ const snapshots = new WeakMap<SQLParameterSnapshot, ReadonlyMap<string, Expression>>();
12
+
13
+ /** Prepares values once, sharing unchanged entries with an optional previous snapshot. */
14
+ export function prepareSQLParameters(
15
+ parameters: SQLParameters,
16
+ options: {previous?: SQLParameterSnapshot} = {}
17
+ ): SQLParameterSnapshot {
18
+ const previous = options.previous && storage(options.previous);
19
+ const entries = new Map<string, Expression>();
20
+ for (const name of Object.keys(parameters)) {
21
+ const expression = bindSQLParameter(name, {parameters});
22
+ encodeStrings(expression);
23
+ const old = previous?.get(name);
24
+ entries.set(name, old && equalValue(old, expression) ? old : expression);
25
+ }
26
+ if (
27
+ options.previous &&
28
+ previous?.size === entries.size &&
29
+ [...entries].every(([name, value]) => previous.get(name) === value)
30
+ )
31
+ return options.previous;
32
+ const snapshot = Object.freeze({kind: 'sql-parameter-snapshot' as const});
33
+ snapshots.set(snapshot, entries);
34
+ return snapshot;
35
+ }
36
+
37
+ /** Compares all values, or only the names used by one query. Missing differs from present. */
38
+ export function areSQLParametersEqual(
39
+ a: SQLParameterSnapshot,
40
+ b: SQLParameterSnapshot,
41
+ options: {names?: readonly string[]} = {}
42
+ ): boolean {
43
+ const left = storage(a);
44
+ const right = storage(b);
45
+ if (a === b) return true;
46
+ if (!options.names && left.size !== right.size) return false;
47
+ return (options.names ?? [...left.keys()]).every(
48
+ name => left.has(name) === right.has(name) && equalValue(left.get(name), right.get(name))
49
+ );
50
+ }
51
+
52
+ /** Recognizes locally prepared handles without reserving any caller parameter names. */
53
+ export function isSQLParameterSnapshot(value: unknown): value is SQLParameterSnapshot {
54
+ return Boolean(
55
+ value && typeof value === 'object' && snapshots.has(value as SQLParameterSnapshot)
56
+ );
57
+ }
58
+
59
+ /** Returns a detached AST for binding while retaining exclusive ownership of cached buffers. */
60
+ export function snapshotParameter(snapshot: SQLParameterSnapshot, name: string): Expression {
61
+ const expression = storage(snapshot).get(name);
62
+ if (!expression) throw new Error(`SQL parameter ":${name}" requires a value`);
63
+ return structuredClone(expression);
64
+ }
65
+
66
+ /** Validates opaque handles, including handles accidentally serialized across a worker boundary. */
67
+ function storage(snapshot: SQLParameterSnapshot): ReadonlyMap<string, Expression> {
68
+ const values = snapshots.get(snapshot);
69
+ if (!values) throw new Error('Invalid SQL parameter snapshot');
70
+ return values;
71
+ }
72
+
73
+ /** Compares detached scalar/array AST contents and physical storage types. */
74
+ function equalValue(a: unknown, b: unknown): boolean {
75
+ if (Object.is(a, b)) return true;
76
+ if (!a || !b || typeof a !== 'object' || typeof b !== 'object' || a.constructor !== b.constructor)
77
+ return false;
78
+ if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
79
+ const left = Object.keys(a);
80
+ const right = Object.keys(b);
81
+ return (
82
+ left.length === right.length &&
83
+ left.every(key => Object.prototype.hasOwnProperty.call(b, key) && equalValue(a[key], b[key]))
84
+ );
85
+ }
86
+
87
+ /** Lists case-sensitive placeholders in first-use order, excluding quotes, comments and casts. */
88
+ export function getSQLParameterNames(sql: string): readonly string[] {
89
+ const names = new Set<string>();
90
+ const tokens =
91
+ /'(?:''|[^'])*'|"(?:""|[^"])*"|--[^\r\n]*|\/\*[\s\S]*?\*\/|::|:([A-Za-z_][A-Za-z0-9_]*)/g;
92
+ for (const match of sql.matchAll(tokens)) if (match[1]) names.add(match[1]);
93
+ return Object.freeze([...names]);
94
+ }
95
+
96
+ /** Pre-encodes text once when a snapshot is prepared for reuse by Arrow compilation. */
97
+ function encodeStrings(expression: Expression): void {
98
+ if (expression.type === 'Literal' && typeof expression.value === 'string' && !expression.utf8) {
99
+ expression.utf8 = new TextEncoder().encode(expression.value);
100
+ } else if (expression.type === 'ArrayExpression') {
101
+ for (const element of expression.elements) encodeStrings(element as Expression);
102
+ }
103
+ }