@uwdata/mosaic-sql 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (429) hide show
  1. package/LICENSE +47 -0
  2. package/README.md +0 -2
  3. package/dist/src/ast/aggregate.d.ts +82 -0
  4. package/dist/src/ast/aggregate.d.ts.map +1 -0
  5. package/dist/src/ast/aggregate.js +180 -0
  6. package/dist/src/ast/aggregate.js.map +1 -0
  7. package/dist/src/ast/between-op.d.ts +46 -0
  8. package/dist/src/ast/between-op.d.ts.map +1 -0
  9. package/dist/src/ast/between-op.js +60 -0
  10. package/dist/src/ast/between-op.js.map +1 -0
  11. package/dist/src/ast/binary-op.d.ts +21 -0
  12. package/dist/src/ast/binary-op.d.ts.map +1 -0
  13. package/dist/src/ast/binary-op.js +29 -0
  14. package/dist/src/ast/binary-op.js.map +1 -0
  15. package/dist/src/ast/case.d.ts +53 -0
  16. package/dist/src/ast/case.d.ts.map +1 -0
  17. package/dist/src/ast/case.js +75 -0
  18. package/dist/src/ast/case.js.map +1 -0
  19. package/dist/src/ast/cast.d.ts +18 -0
  20. package/dist/src/ast/cast.d.ts.map +1 -0
  21. package/dist/src/ast/cast.js +26 -0
  22. package/dist/src/ast/cast.js.map +1 -0
  23. package/dist/src/ast/collate.d.ts +18 -0
  24. package/dist/src/ast/collate.d.ts.map +1 -0
  25. package/dist/src/ast/collate.js +25 -0
  26. package/dist/src/ast/collate.js.map +1 -0
  27. package/dist/src/ast/column-param.d.ts +23 -0
  28. package/dist/src/ast/column-param.d.ts.map +1 -0
  29. package/dist/src/ast/column-param.js +29 -0
  30. package/dist/src/ast/column-param.js.map +1 -0
  31. package/dist/src/ast/column-ref.d.ts +40 -0
  32. package/dist/src/ast/column-ref.d.ts.map +1 -0
  33. package/dist/src/ast/column-ref.js +58 -0
  34. package/dist/src/ast/column-ref.js.map +1 -0
  35. package/dist/src/ast/fragment.d.ts +20 -0
  36. package/dist/src/ast/fragment.d.ts.map +1 -0
  37. package/dist/src/ast/fragment.js +26 -0
  38. package/dist/src/ast/fragment.js.map +1 -0
  39. package/dist/src/ast/from.d.ts +22 -0
  40. package/dist/src/ast/from.d.ts.map +1 -0
  41. package/dist/src/ast/from.js +37 -0
  42. package/dist/src/ast/from.js.map +1 -0
  43. package/dist/src/ast/function.d.ts +18 -0
  44. package/dist/src/ast/function.d.ts.map +1 -0
  45. package/dist/src/ast/function.js +26 -0
  46. package/dist/src/ast/function.js.map +1 -0
  47. package/dist/src/ast/in-op.d.ts +18 -0
  48. package/dist/src/ast/in-op.d.ts.map +1 -0
  49. package/dist/src/ast/in-op.js +25 -0
  50. package/dist/src/ast/in-op.js.map +1 -0
  51. package/dist/src/ast/interval.d.ts +18 -0
  52. package/dist/src/ast/interval.d.ts.map +1 -0
  53. package/dist/src/ast/interval.js +25 -0
  54. package/dist/src/ast/interval.js.map +1 -0
  55. package/dist/src/ast/list.d.ts +15 -0
  56. package/dist/src/ast/list.d.ts.map +1 -0
  57. package/dist/src/ast/list.js +21 -0
  58. package/dist/src/ast/list.js.map +1 -0
  59. package/dist/src/ast/literal.d.ts +16 -0
  60. package/dist/src/ast/literal.d.ts.map +1 -0
  61. package/dist/src/ast/literal.js +53 -0
  62. package/dist/src/ast/literal.js.map +1 -0
  63. package/dist/src/ast/logical-op.d.ts +32 -0
  64. package/dist/src/ast/logical-op.d.ts.map +1 -0
  65. package/dist/src/ast/logical-op.js +46 -0
  66. package/dist/src/ast/logical-op.js.map +1 -0
  67. package/dist/src/ast/node.d.ts +25 -0
  68. package/dist/src/ast/node.d.ts.map +1 -0
  69. package/dist/src/ast/node.js +36 -0
  70. package/dist/src/ast/node.js.map +1 -0
  71. package/dist/src/ast/order-by.d.ts +21 -0
  72. package/dist/src/ast/order-by.d.ts.map +1 -0
  73. package/dist/src/ast/order-by.js +36 -0
  74. package/dist/src/ast/order-by.js.map +1 -0
  75. package/dist/src/ast/param.d.ts +20 -0
  76. package/dist/src/ast/param.d.ts.map +1 -0
  77. package/dist/src/ast/param.js +28 -0
  78. package/dist/src/ast/param.js.map +1 -0
  79. package/dist/src/ast/query.d.ts +334 -0
  80. package/dist/src/ast/query.d.ts.map +1 -0
  81. package/dist/src/ast/query.js +640 -0
  82. package/dist/src/ast/query.js.map +1 -0
  83. package/dist/src/ast/sample.d.ts +27 -0
  84. package/dist/src/ast/sample.d.ts.map +1 -0
  85. package/dist/src/ast/sample.js +38 -0
  86. package/dist/src/ast/sample.js.map +1 -0
  87. package/dist/src/ast/select.d.ts +19 -0
  88. package/dist/src/ast/select.d.ts.map +1 -0
  89. package/dist/src/ast/select.js +35 -0
  90. package/dist/src/ast/select.js.map +1 -0
  91. package/dist/src/ast/subquery.d.ts +16 -0
  92. package/dist/src/ast/subquery.d.ts.map +1 -0
  93. package/dist/src/ast/subquery.js +21 -0
  94. package/dist/src/ast/subquery.js.map +1 -0
  95. package/dist/src/ast/table-ref.d.ts +24 -0
  96. package/dist/src/ast/table-ref.d.ts.map +1 -0
  97. package/dist/src/ast/table-ref.js +35 -0
  98. package/dist/src/ast/table-ref.js.map +1 -0
  99. package/dist/src/ast/unary-op.d.ts +40 -0
  100. package/dist/src/ast/unary-op.d.ts.map +1 -0
  101. package/dist/src/ast/unary-op.js +52 -0
  102. package/dist/src/ast/unary-op.js.map +1 -0
  103. package/dist/src/ast/unnest.d.ts +19 -0
  104. package/dist/src/ast/unnest.d.ts.map +1 -0
  105. package/dist/src/ast/unnest.js +29 -0
  106. package/dist/src/ast/unnest.js.map +1 -0
  107. package/dist/src/ast/verbatim.d.ts +18 -0
  108. package/dist/src/ast/verbatim.d.ts.map +1 -0
  109. package/dist/src/ast/verbatim.js +25 -0
  110. package/dist/src/ast/verbatim.js.map +1 -0
  111. package/dist/src/ast/window-frame.d.ts +54 -0
  112. package/dist/src/ast/window-frame.d.ts.map +1 -0
  113. package/dist/src/ast/window-frame.js +79 -0
  114. package/dist/src/ast/window-frame.js.map +1 -0
  115. package/dist/src/ast/window.d.ts +128 -0
  116. package/dist/src/ast/window.d.ts.map +1 -0
  117. package/dist/src/ast/window.js +194 -0
  118. package/dist/src/ast/window.js.map +1 -0
  119. package/dist/src/ast/with.d.ts +25 -0
  120. package/dist/src/ast/with.d.ts.map +1 -0
  121. package/dist/src/ast/with.js +36 -0
  122. package/dist/src/ast/with.js.map +1 -0
  123. package/dist/src/constants.d.ts +40 -0
  124. package/dist/src/constants.d.ts.map +1 -0
  125. package/dist/src/constants.js +40 -0
  126. package/dist/src/constants.js.map +1 -0
  127. package/dist/src/functions/aggregate.d.ts +236 -0
  128. package/dist/src/functions/aggregate.d.ts.map +1 -0
  129. package/dist/src/functions/aggregate.js +308 -0
  130. package/dist/src/functions/aggregate.js.map +1 -0
  131. package/dist/src/functions/case.d.ts +13 -0
  132. package/dist/src/functions/case.d.ts.map +1 -0
  133. package/dist/src/functions/case.js +17 -0
  134. package/dist/src/functions/case.js.map +1 -0
  135. package/dist/src/functions/cast.d.ts +23 -0
  136. package/dist/src/functions/cast.d.ts.map +1 -0
  137. package/dist/src/functions/cast.js +32 -0
  138. package/dist/src/functions/cast.js.map +1 -0
  139. package/dist/src/functions/collate.d.ts +10 -0
  140. package/dist/src/functions/collate.d.ts.map +1 -0
  141. package/dist/src/functions/collate.js +12 -0
  142. package/dist/src/functions/collate.js.map +1 -0
  143. package/dist/src/functions/column.d.ts +10 -0
  144. package/dist/src/functions/column.d.ts.map +1 -0
  145. package/dist/src/functions/column.js +17 -0
  146. package/dist/src/functions/column.js.map +1 -0
  147. package/dist/src/functions/cte.d.ts +13 -0
  148. package/dist/src/functions/cte.d.ts.map +1 -0
  149. package/dist/src/functions/cte.js +14 -0
  150. package/dist/src/functions/cte.js.map +1 -0
  151. package/dist/src/functions/datetime.d.ts +32 -0
  152. package/dist/src/functions/datetime.d.ts.map +1 -0
  153. package/dist/src/functions/datetime.js +45 -0
  154. package/dist/src/functions/datetime.js.map +1 -0
  155. package/dist/src/functions/interval.d.ts +48 -0
  156. package/dist/src/functions/interval.d.ts.map +1 -0
  157. package/dist/src/functions/interval.js +66 -0
  158. package/dist/src/functions/interval.js.map +1 -0
  159. package/dist/src/functions/list.d.ts +31 -0
  160. package/dist/src/functions/list.d.ts.map +1 -0
  161. package/dist/src/functions/list.js +49 -0
  162. package/dist/src/functions/list.js.map +1 -0
  163. package/dist/src/functions/literal.d.ts +16 -0
  164. package/dist/src/functions/literal.d.ts.map +1 -0
  165. package/dist/src/functions/literal.js +20 -0
  166. package/dist/src/functions/literal.js.map +1 -0
  167. package/dist/src/functions/numeric.d.ts +80 -0
  168. package/dist/src/functions/numeric.d.ts.map +1 -0
  169. package/dist/src/functions/numeric.js +110 -0
  170. package/dist/src/functions/numeric.js.map +1 -0
  171. package/dist/src/functions/operators.d.ts +169 -0
  172. package/dist/src/functions/operators.d.ts.map +1 -0
  173. package/dist/src/functions/operators.js +235 -0
  174. package/dist/src/functions/operators.js.map +1 -0
  175. package/dist/src/functions/order-by.d.ts +15 -0
  176. package/dist/src/functions/order-by.d.ts.map +1 -0
  177. package/dist/src/functions/order-by.js +19 -0
  178. package/dist/src/functions/order-by.js.map +1 -0
  179. package/dist/src/functions/spatial.d.ts +32 -0
  180. package/dist/src/functions/spatial.d.ts.map +1 -0
  181. package/dist/src/functions/spatial.js +44 -0
  182. package/dist/src/functions/spatial.js.map +1 -0
  183. package/dist/src/functions/sql-template-tag.d.ts +13 -0
  184. package/dist/src/functions/sql-template-tag.d.ts.map +1 -0
  185. package/dist/src/functions/sql-template-tag.js +44 -0
  186. package/dist/src/functions/sql-template-tag.js.map +1 -0
  187. package/dist/src/functions/string.d.ts +49 -0
  188. package/dist/src/functions/string.d.ts.map +1 -0
  189. package/dist/src/functions/string.js +67 -0
  190. package/dist/src/functions/string.js.map +1 -0
  191. package/dist/src/functions/table-ref.d.ts +10 -0
  192. package/dist/src/functions/table-ref.d.ts.map +1 -0
  193. package/dist/src/functions/table-ref.js +13 -0
  194. package/dist/src/functions/table-ref.js.map +1 -0
  195. package/dist/src/functions/unnest.d.ts +10 -0
  196. package/dist/src/functions/unnest.d.ts.map +1 -0
  197. package/dist/src/functions/unnest.js +12 -0
  198. package/dist/src/functions/unnest.js.map +1 -0
  199. package/dist/src/functions/util.d.ts +7 -0
  200. package/dist/src/functions/util.d.ts.map +1 -0
  201. package/dist/src/functions/util.js +9 -0
  202. package/dist/src/functions/util.js.map +1 -0
  203. package/dist/src/functions/window-frame.d.ts +41 -0
  204. package/dist/src/functions/window-frame.d.ts.map +1 -0
  205. package/dist/src/functions/window-frame.js +52 -0
  206. package/dist/src/functions/window-frame.js.map +1 -0
  207. package/dist/src/functions/window.d.ts +74 -0
  208. package/dist/src/functions/window.d.ts.map +1 -0
  209. package/dist/src/functions/window.js +96 -0
  210. package/dist/src/functions/window.js.map +1 -0
  211. package/dist/src/index.d.ts +73 -0
  212. package/dist/src/index.d.ts.map +1 -0
  213. package/{src → dist/src}/index.js +8 -8
  214. package/dist/src/index.js.map +1 -0
  215. package/dist/src/load/create.d.ts +10 -0
  216. package/dist/src/load/create.d.ts.map +1 -0
  217. package/dist/src/load/create.js +14 -0
  218. package/dist/src/load/create.js.map +1 -0
  219. package/dist/src/load/extension.d.ts +2 -0
  220. package/dist/src/load/extension.d.ts.map +1 -0
  221. package/dist/src/load/extension.js +4 -0
  222. package/dist/src/load/extension.js.map +1 -0
  223. package/dist/src/load/load.d.ts +18 -0
  224. package/dist/src/load/load.d.ts.map +1 -0
  225. package/dist/src/load/load.js +80 -0
  226. package/dist/src/load/load.js.map +1 -0
  227. package/dist/src/load/sql-from.d.ts +14 -0
  228. package/dist/src/load/sql-from.d.ts.map +1 -0
  229. package/dist/src/load/sql-from.js +29 -0
  230. package/dist/src/load/sql-from.js.map +1 -0
  231. package/dist/src/transforms/bin-1d.d.ts +16 -0
  232. package/dist/src/transforms/bin-1d.d.ts.map +1 -0
  233. package/dist/src/transforms/bin-1d.js +21 -0
  234. package/dist/src/transforms/bin-1d.js.map +1 -0
  235. package/dist/src/transforms/bin-2d.d.ts +19 -0
  236. package/dist/src/transforms/bin-2d.d.ts.map +1 -0
  237. package/dist/src/transforms/bin-2d.js +27 -0
  238. package/dist/src/transforms/bin-2d.js.map +1 -0
  239. package/dist/src/transforms/bin-date.d.ts +31 -0
  240. package/dist/src/transforms/bin-date.d.ts.map +1 -0
  241. package/dist/src/transforms/bin-date.js +20 -0
  242. package/dist/src/transforms/bin-date.js.map +1 -0
  243. package/dist/src/transforms/bin-histogram.d.ts +37 -0
  244. package/dist/src/transforms/bin-histogram.d.ts.map +1 -0
  245. package/dist/src/transforms/bin-histogram.js +32 -0
  246. package/dist/src/transforms/bin-histogram.js.map +1 -0
  247. package/dist/src/transforms/bin-linear-1d.d.ts +11 -0
  248. package/dist/src/transforms/bin-linear-1d.d.ts.map +1 -0
  249. package/dist/src/transforms/bin-linear-1d.js +25 -0
  250. package/dist/src/transforms/bin-linear-1d.js.map +1 -0
  251. package/dist/src/transforms/bin-linear-2d.d.ts +20 -0
  252. package/dist/src/transforms/bin-linear-2d.d.ts.map +1 -0
  253. package/dist/src/transforms/bin-linear-2d.js +49 -0
  254. package/dist/src/transforms/bin-linear-2d.js.map +1 -0
  255. package/dist/src/transforms/filter-query.d.ts +12 -0
  256. package/dist/src/transforms/filter-query.d.ts.map +1 -0
  257. package/dist/src/transforms/filter-query.js +39 -0
  258. package/dist/src/transforms/filter-query.js.map +1 -0
  259. package/dist/src/transforms/line-density.d.ts +24 -0
  260. package/dist/src/transforms/line-density.d.ts.map +1 -0
  261. package/dist/src/transforms/line-density.js +98 -0
  262. package/dist/src/transforms/line-density.js.map +1 -0
  263. package/dist/src/transforms/m4.d.ts +19 -0
  264. package/dist/src/transforms/m4.d.ts.map +1 -0
  265. package/dist/src/transforms/m4.js +38 -0
  266. package/dist/src/transforms/m4.js.map +1 -0
  267. package/dist/src/transforms/scales.d.ts +30 -0
  268. package/dist/src/transforms/scales.d.ts.map +1 -0
  269. package/dist/src/transforms/scales.js +103 -0
  270. package/dist/src/transforms/scales.js.map +1 -0
  271. package/dist/src/transforms/util/bin-step.d.ts +50 -0
  272. package/dist/src/transforms/util/bin-step.d.ts.map +1 -0
  273. package/dist/src/transforms/util/bin-step.js +53 -0
  274. package/dist/src/transforms/util/bin-step.js.map +1 -0
  275. package/dist/src/transforms/util/time-interval.d.ts +14 -0
  276. package/dist/src/transforms/util/time-interval.d.ts.map +1 -0
  277. package/dist/src/transforms/util/time-interval.js +88 -0
  278. package/dist/src/transforms/util/time-interval.js.map +1 -0
  279. package/dist/src/types.d.ts +49 -0
  280. package/dist/src/types.d.ts.map +1 -0
  281. package/dist/src/types.js +2 -0
  282. package/dist/src/types.js.map +1 -0
  283. package/dist/src/util/ast.d.ts +62 -0
  284. package/dist/src/util/ast.d.ts.map +1 -0
  285. package/{src → dist/src}/util/ast.js +36 -41
  286. package/dist/src/util/ast.js.map +1 -0
  287. package/dist/src/util/function.d.ts +56 -0
  288. package/dist/src/util/function.d.ts.map +1 -0
  289. package/dist/src/util/function.js +73 -0
  290. package/dist/src/util/function.js.map +1 -0
  291. package/dist/src/util/identity.d.ts +6 -0
  292. package/dist/src/util/identity.d.ts.map +1 -0
  293. package/dist/src/util/identity.js +8 -0
  294. package/dist/src/util/identity.js.map +1 -0
  295. package/dist/src/util/string.d.ts +4 -0
  296. package/dist/src/util/string.d.ts.map +1 -0
  297. package/dist/src/util/string.js +14 -0
  298. package/dist/src/util/string.js.map +1 -0
  299. package/dist/src/util/type-check.d.ts +17 -0
  300. package/dist/src/util/type-check.d.ts.map +1 -0
  301. package/dist/src/util/type-check.js +28 -0
  302. package/dist/src/util/type-check.js.map +1 -0
  303. package/dist/src/visit/clone.d.ts +7 -0
  304. package/dist/src/visit/clone.d.ts.map +1 -0
  305. package/dist/src/visit/clone.js +52 -0
  306. package/dist/src/visit/clone.js.map +1 -0
  307. package/dist/src/visit/recurse.d.ts +2 -0
  308. package/dist/src/visit/recurse.d.ts.map +1 -0
  309. package/dist/src/visit/recurse.js +37 -0
  310. package/dist/src/visit/recurse.js.map +1 -0
  311. package/dist/src/visit/rewrite.d.ts +9 -0
  312. package/dist/src/visit/rewrite.d.ts.map +1 -0
  313. package/dist/src/visit/rewrite.js +39 -0
  314. package/dist/src/visit/rewrite.js.map +1 -0
  315. package/dist/src/visit/visitors.d.ts +32 -0
  316. package/dist/src/visit/visitors.d.ts.map +1 -0
  317. package/dist/src/visit/visitors.js +95 -0
  318. package/dist/src/visit/visitors.js.map +1 -0
  319. package/dist/src/visit/walk.d.ts +21 -0
  320. package/dist/src/visit/walk.d.ts.map +1 -0
  321. package/dist/src/visit/walk.js +32 -0
  322. package/dist/src/visit/walk.js.map +1 -0
  323. package/package.json +13 -7
  324. package/src/ast/{aggregate.js → aggregate.ts} +49 -60
  325. package/src/ast/{between-op.js → between-op.ts} +19 -26
  326. package/src/ast/binary-op.ts +31 -0
  327. package/src/ast/{case.js → case.ts} +29 -44
  328. package/src/ast/{cast.js → cast.ts} +8 -14
  329. package/src/ast/{collate.js → collate.ts} +8 -14
  330. package/src/ast/column-param.ts +34 -0
  331. package/src/ast/{column-ref.js → column-ref.ts} +16 -25
  332. package/src/ast/fragment.ts +28 -0
  333. package/src/ast/{from.js → from.ts} +12 -21
  334. package/src/ast/{function.js → function.ts} +8 -14
  335. package/src/ast/{in-op.js → in-op.ts} +8 -14
  336. package/src/ast/{interval.js → interval.ts} +8 -14
  337. package/src/ast/list.ts +23 -0
  338. package/src/ast/{literal.js → literal.ts} +6 -9
  339. package/src/ast/logical-op.ts +50 -0
  340. package/src/ast/{node.js → node.ts} +10 -13
  341. package/src/ast/order-by.ts +38 -0
  342. package/src/ast/{param.js → param.ts} +6 -12
  343. package/src/ast/{query.js → query.ts} +224 -204
  344. package/src/ast/sample.ts +47 -0
  345. package/src/ast/{select.js → select.ts} +10 -16
  346. package/src/ast/{subquery.js → subquery.ts} +9 -8
  347. package/src/ast/{table-ref.js → table-ref.ts} +7 -12
  348. package/src/ast/{unary-op.js → unary-op.ts} +16 -23
  349. package/src/ast/unnest.ts +31 -0
  350. package/src/ast/verbatim.ts +27 -0
  351. package/src/ast/{window-frame.js → window-frame.ts} +37 -47
  352. package/src/ast/window.ts +246 -0
  353. package/src/ast/{with.js → with.ts} +19 -20
  354. package/src/{constants.js → constants.ts} +2 -0
  355. package/src/functions/aggregate.ts +344 -0
  356. package/src/functions/{case.js → case.ts} +5 -8
  357. package/src/functions/{cast.js → cast.ts} +9 -13
  358. package/src/functions/{collate.js → collate.ts} +4 -7
  359. package/src/functions/{column.js → column.ts} +9 -10
  360. package/src/functions/{cte.js → cte.ts} +9 -6
  361. package/src/functions/{datetime.js → datetime.ts} +12 -20
  362. package/src/functions/interval.ts +74 -0
  363. package/src/functions/list.ts +63 -0
  364. package/src/functions/{literal.js → literal.ts} +5 -7
  365. package/src/functions/numeric.ts +125 -0
  366. package/src/functions/operators.ts +272 -0
  367. package/src/functions/order-by.ts +21 -0
  368. package/src/functions/spatial.ts +50 -0
  369. package/src/functions/{sql-template-tag.js → sql-template-tag.ts} +16 -13
  370. package/src/functions/string.ts +79 -0
  371. package/src/functions/{table-ref.js → table-ref.ts} +4 -4
  372. package/src/functions/unnest.ts +13 -0
  373. package/src/functions/util.ts +10 -0
  374. package/src/functions/window-frame.ts +58 -0
  375. package/src/functions/{window.js → window.ts} +18 -35
  376. package/src/index.ts +79 -0
  377. package/src/load/{create.js → create.ts} +9 -3
  378. package/src/load/extension.ts +3 -0
  379. package/src/load/{load.js → load.ts} +25 -10
  380. package/src/load/{sql-from.js → sql-from.ts} +14 -7
  381. package/src/transforms/{bin-1d.js → bin-1d.ts} +13 -9
  382. package/src/transforms/{bin-2d.js → bin-2d.ts} +17 -13
  383. package/src/transforms/bin-date.ts +48 -0
  384. package/src/transforms/bin-histogram.ts +61 -0
  385. package/src/transforms/{bin-linear-1d.js → bin-linear-1d.ts} +16 -11
  386. package/src/transforms/{bin-linear-2d.js → bin-linear-2d.ts} +23 -35
  387. package/src/transforms/{filter-query.js → filter-query.ts} +10 -14
  388. package/src/transforms/{line-density.js → line-density.ts} +19 -17
  389. package/src/transforms/{m4.js → m4.ts} +17 -14
  390. package/src/transforms/{scales.js → scales.ts} +57 -14
  391. package/src/transforms/util/bin-step.ts +100 -0
  392. package/src/transforms/util/{time-interval.js → time-interval.ts} +32 -21
  393. package/src/types.ts +5 -39
  394. package/src/util/ast.ts +104 -0
  395. package/src/util/{function.js → function.ts} +40 -31
  396. package/src/util/identity.ts +7 -0
  397. package/src/util/{string.js → string.ts} +4 -4
  398. package/src/util/type-check.ts +31 -0
  399. package/src/visit/{clone.js → clone.ts} +10 -10
  400. package/src/visit/{recurse.js → recurse.ts} +3 -1
  401. package/src/visit/{rewrite.js → rewrite.ts} +7 -7
  402. package/src/visit/{visitors.js → visitors.ts} +22 -30
  403. package/src/visit/walk.ts +46 -0
  404. package/src/ast/binary-op.js +0 -40
  405. package/src/ast/column-param.js +0 -40
  406. package/src/ast/fragment.js +0 -26
  407. package/src/ast/logical-op.js +0 -67
  408. package/src/ast/order-by.js +0 -48
  409. package/src/ast/sample.js +0 -53
  410. package/src/ast/verbatim.js +0 -33
  411. package/src/ast/window.js +0 -260
  412. package/src/functions/aggregate.js +0 -347
  413. package/src/functions/interval.js +0 -83
  414. package/src/functions/numeric.js +0 -143
  415. package/src/functions/operators.js +0 -301
  416. package/src/functions/order-by.js +0 -27
  417. package/src/functions/spatial.js +0 -59
  418. package/src/functions/string.js +0 -85
  419. package/src/functions/util.js +0 -14
  420. package/src/functions/window-frame.js +0 -61
  421. package/src/index-types.ts +0 -2
  422. package/src/load/extension.js +0 -3
  423. package/src/transforms/bin-date.js +0 -38
  424. package/src/transforms/bin-histogram.js +0 -52
  425. package/src/transforms/util/bin-step.js +0 -79
  426. package/src/util/type-check.js +0 -33
  427. package/src/visit/walk.js +0 -34
  428. package/tsconfig.json +0 -8
  429. package/vitest.config.ts +0 -3
@@ -0,0 +1,9 @@
1
+ import { type ExprNode } from '../ast/node.js';
2
+ /**
3
+ * Rewrite a SQL expression, based on a map of nodes to replace.
4
+ * This method copies nodes as needed; it does not modify the input node.
5
+ * @param node The root AST node of the expression.
6
+ * @param map The rewrite map. When encountered, key nodes are replaced by value nodes.
7
+ */
8
+ export declare function rewrite(node: ExprNode, map: Map<ExprNode, ExprNode>): ExprNode | undefined;
9
+ //# sourceMappingURL=rewrite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rewrite.d.ts","sourceRoot":"","sources":["../../../src/visit/rewrite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAU,MAAM,gBAAgB,CAAC;AAGvD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,wBA2BnE"}
@@ -0,0 +1,39 @@
1
+ import { isNode } from '../ast/node.js';
2
+ import { recurse } from './recurse.js';
3
+ /**
4
+ * Rewrite a SQL expression, based on a map of nodes to replace.
5
+ * This method copies nodes as needed; it does not modify the input node.
6
+ * @param node The root AST node of the expression.
7
+ * @param map The rewrite map. When encountered, key nodes are replaced by value nodes.
8
+ */
9
+ export function rewrite(node, map) {
10
+ if (map.has(node)) {
11
+ return map.get(node);
12
+ }
13
+ else if (isNode(node)) {
14
+ const props = recurse[node.type];
15
+ const n = props?.length ?? 0;
16
+ if (n > 0) {
17
+ node = node.clone();
18
+ for (let i = 0; i < n; ++i) {
19
+ const prop = props[i];
20
+ // @ts-expect-error lookup valid property
21
+ const child = node[prop];
22
+ if (Array.isArray(child)) {
23
+ // @ts-expect-error rewrite known property
24
+ const a = (node[prop] = child.slice());
25
+ const m = child.length;
26
+ for (let j = 0; j < m; ++j) {
27
+ a[j] = rewrite(child[j], map);
28
+ }
29
+ }
30
+ else if (child) {
31
+ // @ts-expect-error rewrite known property
32
+ node[prop] = rewrite(child, map);
33
+ }
34
+ }
35
+ }
36
+ }
37
+ return node;
38
+ }
39
+ //# sourceMappingURL=rewrite.js.map
@@ -0,0 +1 @@
1
+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AC,EAAE,GAAG,CAAC,CAAC;oBAChC,CAAC;gBACH,CAAC;qBAAM,IAAI,KAAK,EAAE,CAAC;oBACjB,0CAA0C;oBAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;gBACnC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { type AggregateNode } from '../ast/aggregate.js';
2
+ import type { ColumnRefNode } from '../ast/column-ref.js';
3
+ import type { SQLNode } from '../ast/node.js';
4
+ import type { ParamLike } from '../types.js';
5
+ /**
6
+ * Indicate if the input AST contains an aggregate expression.
7
+ * The string content of verbatim nodes is analyzed to try to identify
8
+ * unparsed aggregate functions calls within SQL strings.
9
+ * @param root The root of the AST to search.
10
+ * @returns Return 0 if no aggregate functions are found.
11
+ * Sets bit 1 if an AggregateFunction instance is found.
12
+ * Sets bit 2 if an aggregate embedded in verbatim text is found.
13
+ */
14
+ export declare function isAggregateExpression(root: SQLNode): number;
15
+ /**
16
+ * Collect all aggregate function nodes.
17
+ * @param root The root of the AST to search.
18
+ */
19
+ export declare function collectAggregates(root: SQLNode): AggregateNode[];
20
+ /**
21
+ * Collect all unique column references.
22
+ * Multiple references to the same column are de-duplicated, even if
23
+ * they are not object-equal node instances.
24
+ * @param root The root of the AST to search.
25
+ */
26
+ export declare function collectColumns(root: SQLNode): ColumnRefNode[];
27
+ /**
28
+ * Collect all unique dynamic parameter instances.
29
+ * @param root The root of the AST to search.
30
+ */
31
+ export declare function collectParams(root: SQLNode): ParamLike[];
32
+ //# sourceMappingURL=visitors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visitors.d.ts","sourceRoot":"","sources":["../../../src/visit/visitors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,qBAAqB,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAkB7C;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,UA4BlD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,mBAQ9C;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,mBAS3C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,eAQ1C"}
@@ -0,0 +1,95 @@
1
+ import { aggregateNames } from '../ast/aggregate.js';
2
+ import { AGGREGATE, COLUMN_PARAM, COLUMN_REF, FRAGMENT, PARAM, VERBATIM, WINDOW } from '../constants.js';
3
+ import { walk } from './walk.js';
4
+ // regexp to match valid aggregate function names
5
+ const aggrRegExp = new RegExp(`^(${aggregateNames.join('|')})$`);
6
+ // regexp to tokenize sql text in order to find function calls
7
+ // includes checks to avoid analyzing text within quoted strings
8
+ // function call tokens will have a pattern like "name(".
9
+ const funcRegExp = /(\\'|\\"|"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\w+\()/g;
10
+ function hasVerbatimAggregate(s) {
11
+ return s
12
+ .split(funcRegExp)
13
+ .some(tok => tok.endsWith('(') && aggrRegExp.test(tok.slice(0, -1)));
14
+ }
15
+ /**
16
+ * Indicate if the input AST contains an aggregate expression.
17
+ * The string content of verbatim nodes is analyzed to try to identify
18
+ * unparsed aggregate functions calls within SQL strings.
19
+ * @param root The root of the AST to search.
20
+ * @returns Return 0 if no aggregate functions are found.
21
+ * Sets bit 1 if an AggregateFunction instance is found.
22
+ * Sets bit 2 if an aggregate embedded in verbatim text is found.
23
+ */
24
+ export function isAggregateExpression(root) {
25
+ let agg = 0;
26
+ walk(root, (node) => {
27
+ switch (node.type) {
28
+ case WINDOW:
29
+ return -1; // aggs can't include windows
30
+ case AGGREGATE:
31
+ agg |= 1;
32
+ return -1;
33
+ case FRAGMENT:
34
+ case VERBATIM: {
35
+ let s = `${node}`.toLowerCase();
36
+ // strip away scalar subquery content
37
+ const sub = s.indexOf('(select ');
38
+ if (sub >= 0)
39
+ s = s.slice(0, sub);
40
+ // exit if expression includes windowing
41
+ if (s.includes(') over '))
42
+ return -1;
43
+ if (hasVerbatimAggregate(s)) {
44
+ agg |= 2;
45
+ return -1;
46
+ }
47
+ return 1; // don't recurse
48
+ }
49
+ }
50
+ });
51
+ return agg;
52
+ }
53
+ /**
54
+ * Collect all aggregate function nodes.
55
+ * @param root The root of the AST to search.
56
+ */
57
+ export function collectAggregates(root) {
58
+ const aggs = new Set();
59
+ walk(root, (node) => {
60
+ if (node.type === AGGREGATE) {
61
+ aggs.add(node);
62
+ }
63
+ });
64
+ return Array.from(aggs);
65
+ }
66
+ /**
67
+ * Collect all unique column references.
68
+ * Multiple references to the same column are de-duplicated, even if
69
+ * they are not object-equal node instances.
70
+ * @param root The root of the AST to search.
71
+ */
72
+ export function collectColumns(root) {
73
+ const cols = {};
74
+ walk(root, (node) => {
75
+ if (node.type === COLUMN_REF || node.type === COLUMN_PARAM) {
76
+ // key on string-coerced node
77
+ cols[`${node}`] = node;
78
+ }
79
+ });
80
+ return Object.values(cols);
81
+ }
82
+ /**
83
+ * Collect all unique dynamic parameter instances.
84
+ * @param root The root of the AST to search.
85
+ */
86
+ export function collectParams(root) {
87
+ const params = new Set;
88
+ walk(root, (node) => {
89
+ if (node.type === PARAM) {
90
+ params.add(node.param);
91
+ }
92
+ });
93
+ return Array.from(params);
94
+ }
95
+ //# sourceMappingURL=visitors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visitors.js","sourceRoot":"","sources":["../../../src/visit/visitors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKzE,OAAO,EAAE,SAAS,EAAE,YAAY,EA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,CAAC;IAClC,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;QAClB,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACxB,MAAM,CAAC,GAAG,CAAE,IAAkB,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { SQLNode } from '../ast/node.js';
2
+ /**
3
+ * SQL AST traversal visitor callback result.
4
+ * A falsy value (including `undefined`, `null`, `false`, and `0`) indicates
5
+ * that traversal should continue.
6
+ * A negative number values indicates that traversal should stop immediately.
7
+ * Any other truthy value indicates that traversal should not recurse on the
8
+ * current node, but should otherwise continue.
9
+ */
10
+ export type VisitorResult = boolean | number | null | undefined | void;
11
+ /**
12
+ * SQL AST traversal callback function.
13
+ */
14
+ export type VisitorCallback = (node: SQLNode) => VisitorResult;
15
+ /**
16
+ * Perform a traversal of a SQL expression AST.
17
+ * @param node Root node for AST traversal.
18
+ * @param visit Visitor callback function.
19
+ */
20
+ export declare function walk(node: unknown, visit: VisitorCallback): VisitorResult;
21
+ //# sourceMappingURL=walk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../../src/visit/walk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAI9C;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,aAAa,CAAC;AAE/D;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,GAAG,aAAa,CAqBzE"}
@@ -0,0 +1,32 @@
1
+ import { isNode } from '../ast/node.js';
2
+ import { recurse } from './recurse.js';
3
+ /**
4
+ * Perform a traversal of a SQL expression AST.
5
+ * @param node Root node for AST traversal.
6
+ * @param visit Visitor callback function.
7
+ */
8
+ export function walk(node, visit) {
9
+ if (!isNode(node))
10
+ return;
11
+ const result = visit(node);
12
+ if (result)
13
+ return result;
14
+ const props = recurse[node.type];
15
+ const n = props?.length ?? 0;
16
+ for (let i = 0; i < n; ++i) {
17
+ // @ts-expect-error lookup of valid property
18
+ const value = node[props[i]];
19
+ if (Array.isArray(value)) {
20
+ const m = value.length;
21
+ for (let j = 0; j < m; ++j) {
22
+ if (value[j] && Number(walk(value[j], visit)) < 0) {
23
+ return result;
24
+ }
25
+ }
26
+ }
27
+ else if (value && Number(walk(value, visit)) < 0) {
28
+ return -1;
29
+ }
30
+ }
31
+ }
32
+ //# sourceMappingURL=walk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.js","sourceRoot":"","sources":["../../../src/visit/walk.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAiBvC;;;;GAIG;AACH,MAAM,UAAU,IAAI,CAAC,IAAa,EAAE,KAAsB;IACxD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;QAAE,OAAO;IAC1B,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,CAAC,GAAG,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;QAC3B,4CAA4C;QAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;YACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;gBAC3B,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;oBAClD,OAAO,MAAM,CAAC;gBAChB,CAAC;YACH,CAAC;QACH,CAAC;aAAM,IAAI,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;YACnD,OAAO,CAAC,CAAC,CAAC;QACZ,CAAC;IACH,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uwdata/mosaic-sql",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "description": "SQL query construction and analysis.",
5
5
  "keywords": [
6
6
  "sql",
@@ -11,17 +11,23 @@
11
11
  "author": "Jeffrey Heer (https://idl.uw.edu)",
12
12
  "type": "module",
13
13
  "exports": {
14
- "types": "./dist/src/index-types.d.ts",
15
- "default": "./src/index.js"
14
+ "types": "./dist/src/index.d.ts",
15
+ "default": "./dist/src/index.js"
16
16
  },
17
+ "files": [
18
+ "dist",
19
+ "!dist/tsconfig.tsbuildinfo",
20
+ "src"
21
+ ],
17
22
  "repository": {
18
23
  "type": "git",
19
24
  "url": "https://github.com/uwdata/mosaic.git"
20
25
  },
21
26
  "scripts": {
22
- "prebuild": "rimraf dist && mkdir dist",
27
+ "clean": "rimraf dist && mkdir dist",
23
28
  "lint": "eslint src test",
24
- "test": "vitest run && tsc",
25
- "prepublishOnly": "npm run test && npm run lint && tsc"
26
- }
29
+ "test": "vitest run",
30
+ "prepublishOnly": "npm run test && npm run lint && tsc --build"
31
+ },
32
+ "gitHead": "0ba4f2d710ca2fa53da7ff02a370e39a32dc2ce4"
27
33
  }
@@ -1,88 +1,78 @@
1
- /**
2
- * @import { ExprVarArgs, OrderByExpr } from '../types.js'
3
- * @import { WindowFrameNode } from './window-frame.js'
4
- */
1
+ import type { ExprVarArgs, OrderByExpr } from '../types.js';
2
+ import type { WindowFrameNode } from './window-frame.js';
5
3
  import { AGGREGATE } from '../constants.js';
6
4
  import { asVerbatim } from '../util/ast.js';
7
- import { exprList } from '../util/function.js';
5
+ import { nodeList } from '../util/function.js';
8
6
  import { isString } from '../util/type-check.js';
9
7
  import { ExprNode } from './node.js';
10
8
  import { WindowNode } from './window.js';
11
9
 
12
10
  export class AggregateNode extends ExprNode {
11
+ /** The aggregate function name. */
12
+ readonly name: string;
13
+ /** The aggregate function arguments. */
14
+ readonly args: ExprNode[];
15
+ /** The distinct flag. */
16
+ readonly isDistinct: boolean;
17
+ /** Filter criteria. */
18
+ readonly filter: ExprNode | null;
19
+ /** Order by expression for order-sensitive aggregates. */
20
+ readonly order: ExprNode[];
21
+
13
22
  /**
14
23
  * Instantiate an aggregate function node.
15
- * @param {string} name The aggregate function name.
16
- * @param {ExprNode[]} args The aggregate function arguments.
17
- * @param {boolean} [distinct] The distinct flag.
18
- * @param {ExprNode} [filter] Filter expression.
19
- * @param {OrderByExpr} [argOrder] Order by expression.
24
+ * @param name The aggregate function name.
25
+ * @param args The aggregate function arguments.
26
+ * @param distinct The distinct flag.
27
+ * @param filter Filter expression.
28
+ * @param argOrder Order by expression.
20
29
  */
21
- constructor(name, args, distinct = false, filter = null, argOrder = []) {
30
+ constructor(
31
+ name: string,
32
+ args: ExprNode[],
33
+ distinct: boolean = false,
34
+ filter: ExprNode | null = null,
35
+ argOrder: OrderByExpr = []
36
+ ) {
22
37
  super(AGGREGATE);
23
- /**
24
- * The aggregate function name.
25
- * @type {string}
26
- * @readonly
27
- */
28
38
  this.name = name;
29
- /**
30
- * The aggregate function arguments.
31
- * @type {ExprNode[]}
32
- * @readonly
33
- */
34
39
  this.args = args;
35
- /**
36
- * The distinct flag.
37
- * @type {boolean}
38
- * @readonly
39
- */
40
40
  this.isDistinct = distinct;
41
- /**
42
- * Filter criteria.
43
- * @type {ExprNode}
44
- * @readonly
45
- */
46
41
  this.filter = filter;
47
- /**
48
- * Order by expression for order-sensitive aggregates.
49
- * @type {ExprNode[]}
50
- * @readonly
51
- */
52
- this.order = exprList([argOrder]);
42
+ this.order = nodeList([argOrder]);
53
43
  }
54
44
 
55
45
  /**
56
46
  * Return a new derived aggregate over distinct values.
57
- * @param {boolean} [isDistinct=true] The distinct flag.
58
- * @returns {AggregateNode} A new aggregate node.
47
+ * @param isDistinct The distinct flag.
48
+ * @returns A new aggregate node.
59
49
  */
60
- distinct(isDistinct = true) {
50
+ distinct(isDistinct: boolean = true) {
61
51
  return new AggregateNode(this.name, this.args, isDistinct, this.filter, this.order);
62
52
  }
63
53
 
64
54
  /**
65
55
  * Return a new derived aggregate function that filters values.
66
- * @param {ExprNode | string} filter The filter expression.
67
- * @returns {AggregateNode} A new aggregate node.
56
+ * @param The filter expression.
57
+ * @returns A new aggregate node.
68
58
  */
69
- where(filter) {
59
+ where(filter: ExprNode | string) {
70
60
  if (isString(filter)) filter = asVerbatim(filter);
71
61
  return new AggregateNode(this.name, this.args, this.isDistinct, filter, this.order);
72
62
  }
73
63
 
74
64
  /**
75
65
  * Return a new derived aggregate function that sorts values prior to aggregation.
76
- * @param {OrderByExpr} order The order by expression.
77
- * @returns {AggregateNode} A new aggregate node.
66
+ * @param order The order by expression.
67
+ * @returns A new aggregate node.
78
68
  */
79
- argOrder(order) {
69
+ argOrder(order: OrderByExpr) {
80
70
  return new AggregateNode(this.name, this.args, this.isDistinct, this.filter, order);
81
71
  }
82
72
 
83
73
  /**
84
74
  * Return a new window function over this aggregate.
85
- * @returns {WindowNode} A new window node.
75
+ * @returns A new window node.
86
76
  */
87
77
  window() {
88
78
  return new WindowNode(this);
@@ -90,34 +80,33 @@ export class AggregateNode extends ExprNode {
90
80
 
91
81
  /**
92
82
  * Return a new window function over this aggregate with the given partitions.
93
- * @param {...ExprVarArgs} expr The partition by criteria.
94
- * @returns {WindowNode} A new window node.
83
+ * @param expr The partition by criteria.
84
+ * @returns A new window node.
95
85
  */
96
- partitionby(...expr) {
86
+ partitionby(...expr: ExprVarArgs[]) {
97
87
  return this.window().partitionby(...expr);
98
88
  }
99
89
 
100
90
  /**
101
91
  * Return a new window function over this aggregate with the given ordering.
102
- * @param {...ExprVarArgs} expr The order by criteria.
103
- * @returns {WindowNode} A new window node.
92
+ * @param expr The order by criteria.
93
+ * @returns A new window node.
104
94
  */
105
- orderby(...expr) {
95
+ orderby(...expr: ExprVarArgs[]) {
106
96
  return this.window().orderby(...expr);
107
97
  }
108
98
 
109
99
  /**
110
100
  * Return a new window function over this aggregate with the given frame.
111
- * @param {WindowFrameNode} framedef The window frame definition.
112
- * @returns {WindowNode} A new window node.
101
+ * @param framedef The window frame definition.
102
+ * @returns A new window node.
113
103
  */
114
- frame(framedef) {
104
+ frame(framedef: WindowFrameNode) {
115
105
  return this.window().frame(framedef);
116
106
  }
117
107
 
118
108
  /**
119
109
  * Generate a SQL query string for this node.
120
- * @returns {string}
121
110
  */
122
111
  toString() {
123
112
  const { name, args, isDistinct, filter, order } = this;
@@ -135,10 +124,10 @@ export class AggregateNode extends ExprNode {
135
124
 
136
125
  /**
137
126
  * Check if a function name corresponds to an aggregate function.
138
- * @param {string} name The function name to check
139
- * @returns {boolean} True if a known aggregate function, false otherwise.
127
+ * @param name The function name to check
128
+ * @returns True if a known aggregate function, false otherwise.
140
129
  */
141
- export function isAggregateFunction(name) {
130
+ export function isAggregateFunction(name: string) {
142
131
  return aggregateNames.includes(name.toLowerCase());
143
132
  }
144
133
 
@@ -1,34 +1,31 @@
1
1
  import { BETWEEN_OPERATOR, NOT_BETWEEN_OPERATOR } from '../constants.js';
2
2
  import { ExprNode } from './node.js';
3
3
 
4
+ export type Extent = [ExprNode, ExprNode] | null;
5
+
4
6
  class AbstractBetweenOpNode extends ExprNode {
7
+ /** The input expression. */
8
+ readonly expr: ExprNode;
9
+ /** The range extent. */
10
+ readonly extent?: Extent;
11
+
5
12
  /**
6
13
  * Instantiate an abstract between operator node.
7
- * @param {string} type The node type.
8
- * @param {ExprNode} expr The input expression.
9
- * @param {[ExprNode, ExprNode]} extent The range extent.
14
+ * @param type The node type.
15
+ * @param expr The input expression.
16
+ * @param extent The range extent.
10
17
  */
11
- constructor(type, expr, extent) {
18
+ constructor(type: string, expr: ExprNode, extent?: Extent) {
12
19
  super(type);
13
- /**
14
- * The input expression.
15
- * @type {ExprNode}
16
- * @readonly
17
- */
18
20
  this.expr = expr;
19
- /**
20
- * The range extent.
21
- * @type {[ExprNode, ExprNode]}
22
- * @readonly
23
- */
24
21
  this.extent = extent;
25
22
  }
26
23
 
27
24
  /**
28
25
  * Generate a SQL query string for this node.
29
- * @returns {string}
26
+ * @param op The operator to apply.
30
27
  */
31
- toSQL(op) {
28
+ toSQL(op: string) {
32
29
  const { extent: r, expr } = this;
33
30
  return r ? `(${expr} ${op} ${r[0]} AND ${r[1]})` : '';
34
31
  }
@@ -37,17 +34,15 @@ class AbstractBetweenOpNode extends ExprNode {
37
34
  export class BetweenOpNode extends AbstractBetweenOpNode {
38
35
  /**
39
36
  * Instantiate a between operator node.
40
- * @param {ExprNode} expr The input expression.
41
- * @param {[ExprNode, ExprNode]} extent
42
- * The range extent.
37
+ * @param expr The input expression.
38
+ * @param extent The range extent.
43
39
  */
44
- constructor(expr, extent) {
40
+ constructor(expr: ExprNode, extent?: Extent) {
45
41
  super(BETWEEN_OPERATOR, expr, extent);
46
42
  }
47
43
 
48
44
  /**
49
45
  * Generate a SQL query string for this node.
50
- * @returns {string}
51
46
  */
52
47
  toString() {
53
48
  return super.toSQL('BETWEEN');
@@ -57,17 +52,15 @@ export class BetweenOpNode extends AbstractBetweenOpNode {
57
52
  export class NotBetweenOpNode extends AbstractBetweenOpNode {
58
53
  /**
59
54
  * Instantiate a not between operator node.
60
- * @param {ExprNode} expr The input expression.
61
- * @param {[ExprNode, ExprNode]} extent
62
- * The range extent.
55
+ * @param expr The input expression.
56
+ * @param extent The range extent.
63
57
  */
64
- constructor(expr, extent) {
58
+ constructor(expr: ExprNode, extent?: Extent) {
65
59
  super(NOT_BETWEEN_OPERATOR, expr, extent);
66
60
  }
67
61
 
68
62
  /**
69
63
  * Generate a SQL query string for this node.
70
- * @returns {string}
71
64
  */
72
65
  toString() {
73
66
  return super.toSQL('NOT BETWEEN');
@@ -0,0 +1,31 @@
1
+ import { BINARY_OPERATOR } from '../constants.js';
2
+ import { ExprNode } from './node.js';
3
+
4
+ export class BinaryOpNode extends ExprNode {
5
+ /** The operator type. */
6
+ readonly op: string;
7
+ /** The left input expression. */
8
+ readonly left: ExprNode;
9
+ /** The right input expression. */
10
+ readonly right: ExprNode;
11
+
12
+ /**
13
+ * Instantiate a binary operator node.
14
+ * @param op The operator type.
15
+ * @param left The left input expression.
16
+ * @param right The right input expression.
17
+ */
18
+ constructor(op: string, left: ExprNode, right: ExprNode) {
19
+ super(BINARY_OPERATOR);
20
+ this.op = op;
21
+ this.left = left;
22
+ this.right = right;
23
+ }
24
+
25
+ /**
26
+ * Generate a SQL query string for this node.
27
+ */
28
+ toString() {
29
+ return `(${this.left} ${this.op} ${this.right})`;
30
+ }
31
+ }