@cchistory/lite 0.4.5 → 0.6.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 (556) hide show
  1. package/INSTALL.md +1 -1
  2. package/apps/lite-cli/dist/agent-contract.d.ts +7 -5
  3. package/apps/lite-cli/dist/agent-contract.d.ts.map +1 -1
  4. package/apps/lite-cli/dist/agent-contract.js +36 -25
  5. package/apps/lite-cli/dist/agent-contract.js.map +1 -1
  6. package/apps/lite-cli/dist/bin.js +2 -2
  7. package/apps/lite-cli/dist/bin.js.map +1 -1
  8. package/apps/lite-cli/dist/index.d.ts.map +1 -1
  9. package/apps/lite-cli/dist/index.js +151 -66
  10. package/apps/lite-cli/dist/index.js.map +1 -1
  11. package/apps/lite-cli/dist/index.test.js +59 -89
  12. package/apps/lite-cli/dist/index.test.js.map +1 -1
  13. package/apps/lite-cli/dist/query.d.ts +4 -1
  14. package/apps/lite-cli/dist/query.d.ts.map +1 -1
  15. package/apps/lite-cli/dist/query.js +45 -29
  16. package/apps/lite-cli/dist/query.js.map +1 -1
  17. package/apps/lite-cli/dist/resource-errors.d.ts +3 -0
  18. package/apps/lite-cli/dist/resource-errors.d.ts.map +1 -0
  19. package/apps/lite-cli/dist/resource-errors.js +17 -0
  20. package/apps/lite-cli/dist/resource-errors.js.map +1 -0
  21. package/apps/lite-cli/dist/shell.d.ts +12 -2
  22. package/apps/lite-cli/dist/shell.d.ts.map +1 -1
  23. package/apps/lite-cli/dist/shell.js +129 -57
  24. package/apps/lite-cli/dist/shell.js.map +1 -1
  25. package/apps/lite-cli/dist/sql-query.test.d.ts +2 -0
  26. package/apps/lite-cli/dist/sql-query.test.d.ts.map +1 -0
  27. package/apps/lite-cli/dist/sql-query.test.js +290 -0
  28. package/apps/lite-cli/dist/sql-query.test.js.map +1 -0
  29. package/apps/lite-cli/dist/version.d.ts +1 -1
  30. package/apps/lite-cli/dist/version.js +1 -1
  31. package/apps/lite-tui/dist/bin.js +2 -2
  32. package/apps/lite-tui/dist/bin.js.map +1 -1
  33. package/apps/lite-tui/dist/index.d.ts.map +1 -1
  34. package/apps/lite-tui/dist/index.js +6 -2
  35. package/apps/lite-tui/dist/index.js.map +1 -1
  36. package/apps/lite-tui/dist/index.test.js +10 -8
  37. package/apps/lite-tui/dist/index.test.js.map +1 -1
  38. package/apps/lite-tui/dist/render.d.ts +1 -1
  39. package/apps/lite-tui/dist/version.d.ts +1 -1
  40. package/apps/lite-tui/dist/version.js +1 -1
  41. package/bin/cchistory-lite-tui.mjs +2 -2
  42. package/bin/cchistory-lite.mjs +2 -2
  43. package/docs/guide/for-agents.md +66 -46
  44. package/docs/guide/lite.md +53 -11
  45. package/docs/guide/queries/latest-sessions.sql +4 -0
  46. package/docs/guide/queries/latest-turns.sql +1 -0
  47. package/docs/guide/queries/list-sessions.sql +2 -0
  48. package/docs/guide/query.md +153 -0
  49. package/node_modules/@cchistory/canonical/dist/directory-scope.d.ts +7 -0
  50. package/node_modules/@cchistory/canonical/dist/directory-scope.d.ts.map +1 -1
  51. package/node_modules/@cchistory/canonical/dist/directory-scope.js +11 -0
  52. package/node_modules/@cchistory/canonical/dist/directory-scope.js.map +1 -1
  53. package/node_modules/@cchistory/canonical/dist/index.d.ts +5 -1
  54. package/node_modules/@cchistory/canonical/dist/index.d.ts.map +1 -1
  55. package/node_modules/@cchistory/canonical/dist/index.js +5 -1
  56. package/node_modules/@cchistory/canonical/dist/index.js.map +1 -1
  57. package/node_modules/@cchistory/canonical/dist/query.d.ts +15 -0
  58. package/node_modules/@cchistory/canonical/dist/query.d.ts.map +1 -0
  59. package/node_modules/@cchistory/canonical/dist/query.js +208 -0
  60. package/node_modules/@cchistory/canonical/dist/query.js.map +1 -0
  61. package/node_modules/@cchistory/canonical/dist/session-family.d.ts +1 -0
  62. package/node_modules/@cchistory/canonical/dist/session-family.d.ts.map +1 -1
  63. package/node_modules/@cchistory/canonical/dist/session-family.js +3 -0
  64. package/node_modules/@cchistory/canonical/dist/session-family.js.map +1 -1
  65. package/node_modules/@cchistory/canonical/dist/session-family.test.js +61 -0
  66. package/node_modules/@cchistory/canonical/dist/session-family.test.js.map +1 -1
  67. package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts +30 -0
  68. package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts.map +1 -0
  69. package/node_modules/@cchistory/canonical/dist/session-interpreter.js +713 -0
  70. package/node_modules/@cchistory/canonical/dist/session-interpreter.js.map +1 -0
  71. package/node_modules/@cchistory/canonical/dist/session-interpreter.test.d.ts +2 -0
  72. package/node_modules/@cchistory/canonical/dist/session-interpreter.test.d.ts.map +1 -0
  73. package/node_modules/@cchistory/canonical/dist/session-interpreter.test.js +56 -0
  74. package/node_modules/@cchistory/canonical/dist/session-interpreter.test.js.map +1 -0
  75. package/node_modules/@cchistory/canonical/package.json +1 -1
  76. package/node_modules/@cchistory/domain/dist/evidence-atoms.d.ts +7 -0
  77. package/node_modules/@cchistory/domain/dist/evidence-atoms.d.ts.map +1 -0
  78. package/node_modules/@cchistory/domain/dist/evidence-atoms.js +36 -0
  79. package/node_modules/@cchistory/domain/dist/evidence-atoms.js.map +1 -0
  80. package/node_modules/@cchistory/domain/dist/evidence-values.d.ts +26 -0
  81. package/node_modules/@cchistory/domain/dist/evidence-values.d.ts.map +1 -0
  82. package/node_modules/@cchistory/domain/dist/evidence-values.js +80 -0
  83. package/node_modules/@cchistory/domain/dist/evidence-values.js.map +1 -0
  84. package/node_modules/@cchistory/domain/dist/index.d.ts +6 -0
  85. package/node_modules/@cchistory/domain/dist/index.d.ts.map +1 -1
  86. package/node_modules/@cchistory/domain/dist/index.js +5 -0
  87. package/node_modules/@cchistory/domain/dist/index.js.map +1 -1
  88. package/node_modules/@cchistory/domain/dist/masks.d.ts +31 -0
  89. package/node_modules/@cchistory/domain/dist/masks.d.ts.map +1 -0
  90. package/node_modules/@cchistory/domain/dist/masks.js +342 -0
  91. package/node_modules/@cchistory/domain/dist/masks.js.map +1 -0
  92. package/node_modules/@cchistory/domain/dist/parsed-session.d.ts +58 -0
  93. package/node_modules/@cchistory/domain/dist/parsed-session.d.ts.map +1 -0
  94. package/node_modules/@cchistory/domain/dist/parsed-session.js +2 -0
  95. package/node_modules/@cchistory/domain/dist/parsed-session.js.map +1 -0
  96. package/node_modules/@cchistory/domain/dist/query.d.ts +67 -0
  97. package/node_modules/@cchistory/domain/dist/query.d.ts.map +1 -0
  98. package/node_modules/@cchistory/domain/dist/query.js +2 -0
  99. package/node_modules/@cchistory/domain/dist/query.js.map +1 -0
  100. package/node_modules/@cchistory/domain/dist/token-evidence.d.ts +14 -0
  101. package/node_modules/@cchistory/domain/dist/token-evidence.d.ts.map +1 -0
  102. package/node_modules/@cchistory/domain/dist/token-evidence.js +247 -0
  103. package/node_modules/@cchistory/domain/dist/token-evidence.js.map +1 -0
  104. package/node_modules/@cchistory/domain/package.json +1 -1
  105. package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts +1 -1
  106. package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts.map +1 -1
  107. package/node_modules/@cchistory/live-runtime/dist/bootstrap.js +1 -1
  108. package/node_modules/@cchistory/live-runtime/dist/bootstrap.js.map +1 -1
  109. package/node_modules/@cchistory/live-runtime/dist/index.d.ts +30 -9
  110. package/node_modules/@cchistory/live-runtime/dist/index.d.ts.map +1 -1
  111. package/node_modules/@cchistory/live-runtime/dist/index.js +314 -143
  112. package/node_modules/@cchistory/live-runtime/dist/index.js.map +1 -1
  113. package/node_modules/@cchistory/live-runtime/dist/index.test.js +177 -20
  114. package/node_modules/@cchistory/live-runtime/dist/index.test.js.map +1 -1
  115. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.d.ts +12 -0
  116. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.d.ts.map +1 -0
  117. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.js +44 -0
  118. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.js.map +1 -0
  119. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.test.d.ts +2 -0
  120. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.test.d.ts.map +1 -0
  121. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.test.js +20 -0
  122. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.test.js.map +1 -0
  123. package/node_modules/@cchistory/live-runtime/dist/live-read-recovery.test.d.ts +2 -0
  124. package/node_modules/@cchistory/live-runtime/dist/live-read-recovery.test.d.ts.map +1 -0
  125. package/node_modules/@cchistory/live-runtime/dist/live-read-recovery.test.js +92 -0
  126. package/node_modules/@cchistory/live-runtime/dist/live-read-recovery.test.js.map +1 -0
  127. package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.d.ts +16 -0
  128. package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.d.ts.map +1 -0
  129. package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.js +55 -0
  130. package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.js.map +1 -0
  131. package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.d.ts +2 -0
  132. package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.d.ts.map +1 -0
  133. package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.js +192 -0
  134. package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.js.map +1 -0
  135. package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts +22 -22
  136. package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts.map +1 -1
  137. package/node_modules/@cchistory/live-runtime/dist/scan-guard.js +53 -47
  138. package/node_modules/@cchistory/live-runtime/dist/scan-guard.js.map +1 -1
  139. package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js +287 -83
  140. package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js.map +1 -1
  141. package/node_modules/@cchistory/live-runtime/dist/selective-query.d.ts +47 -0
  142. package/node_modules/@cchistory/live-runtime/dist/selective-query.d.ts.map +1 -0
  143. package/node_modules/@cchistory/live-runtime/dist/selective-query.js +15 -0
  144. package/node_modules/@cchistory/live-runtime/dist/selective-query.js.map +1 -0
  145. package/node_modules/@cchistory/live-runtime/dist/selective-query.test.d.ts +2 -0
  146. package/node_modules/@cchistory/live-runtime/dist/selective-query.test.d.ts.map +1 -0
  147. package/node_modules/@cchistory/live-runtime/dist/selective-query.test.js +171 -0
  148. package/node_modules/@cchistory/live-runtime/dist/selective-query.test.js.map +1 -0
  149. package/node_modules/@cchistory/live-runtime/dist/sql-query.d.ts +37 -0
  150. package/node_modules/@cchistory/live-runtime/dist/sql-query.d.ts.map +1 -0
  151. package/node_modules/@cchistory/live-runtime/dist/sql-query.js +301 -0
  152. package/node_modules/@cchistory/live-runtime/dist/sql-query.js.map +1 -0
  153. package/node_modules/@cchistory/live-runtime/dist/sql-query.test.d.ts +2 -0
  154. package/node_modules/@cchistory/live-runtime/dist/sql-query.test.d.ts.map +1 -0
  155. package/node_modules/@cchistory/live-runtime/dist/sql-query.test.js +67 -0
  156. package/node_modules/@cchistory/live-runtime/dist/sql-query.test.js.map +1 -0
  157. package/node_modules/@cchistory/live-runtime/dist/sql-worker.d.ts +2 -0
  158. package/node_modules/@cchistory/live-runtime/dist/sql-worker.d.ts.map +1 -0
  159. package/node_modules/@cchistory/live-runtime/dist/sql-worker.js +14 -0
  160. package/node_modules/@cchistory/live-runtime/dist/sql-worker.js.map +1 -0
  161. package/node_modules/@cchistory/live-runtime/dist/system-memory.d.ts +13 -10
  162. package/node_modules/@cchistory/live-runtime/dist/system-memory.d.ts.map +1 -1
  163. package/node_modules/@cchistory/live-runtime/dist/system-memory.js +61 -34
  164. package/node_modules/@cchistory/live-runtime/dist/system-memory.js.map +1 -1
  165. package/node_modules/@cchistory/live-runtime/dist/system-memory.test.d.ts +2 -0
  166. package/node_modules/@cchistory/live-runtime/dist/system-memory.test.d.ts.map +1 -0
  167. package/node_modules/@cchistory/live-runtime/dist/system-memory.test.js +76 -0
  168. package/node_modules/@cchistory/live-runtime/dist/system-memory.test.js.map +1 -0
  169. package/node_modules/@cchistory/live-runtime/package.json +1 -1
  170. package/node_modules/@cchistory/source-adapters/dist/core/discovery.test.js +2 -1
  171. package/node_modules/@cchistory/source-adapters/dist/core/discovery.test.js.map +1 -1
  172. package/node_modules/@cchistory/source-adapters/dist/core/factories.d.ts +2 -4
  173. package/node_modules/@cchistory/source-adapters/dist/core/factories.d.ts.map +1 -1
  174. package/node_modules/@cchistory/source-adapters/dist/core/factories.js +1 -23
  175. package/node_modules/@cchistory/source-adapters/dist/core/factories.js.map +1 -1
  176. package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.d.ts +25 -0
  177. package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.d.ts.map +1 -0
  178. package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.js +81 -0
  179. package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.js.map +1 -0
  180. package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.d.ts +2 -0
  181. package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.d.ts.map +1 -0
  182. package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.js +122 -0
  183. package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.js.map +1 -0
  184. package/node_modules/@cchistory/source-adapters/dist/core/git-project.d.ts +1 -1
  185. package/node_modules/@cchistory/source-adapters/dist/core/git-project.d.ts.map +1 -1
  186. package/node_modules/@cchistory/source-adapters/dist/core/git-project.js +2 -11
  187. package/node_modules/@cchistory/source-adapters/dist/core/git-project.js.map +1 -1
  188. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.test.js +31 -1
  189. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.test.js.map +1 -1
  190. package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts +4 -3
  191. package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts.map +1 -1
  192. package/node_modules/@cchistory/source-adapters/dist/core/parser.js +32 -13
  193. package/node_modules/@cchistory/source-adapters/dist/core/parser.js.map +1 -1
  194. package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts +8 -6
  195. package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts.map +1 -1
  196. package/node_modules/@cchistory/source-adapters/dist/core/probe.js +46 -45
  197. package/node_modules/@cchistory/source-adapters/dist/core/probe.js.map +1 -1
  198. package/node_modules/@cchistory/source-adapters/dist/core/projections.d.ts +2 -28
  199. package/node_modules/@cchistory/source-adapters/dist/core/projections.d.ts.map +1 -1
  200. package/node_modules/@cchistory/source-adapters/dist/core/projections.js +2 -695
  201. package/node_modules/@cchistory/source-adapters/dist/core/projections.js.map +1 -1
  202. package/node_modules/@cchistory/source-adapters/dist/core/projections.test.js +2 -1
  203. package/node_modules/@cchistory/source-adapters/dist/core/projections.test.js.map +1 -1
  204. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.d.ts +18 -0
  205. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.d.ts.map +1 -0
  206. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.js +27 -0
  207. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.js.map +1 -0
  208. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.d.ts +2 -0
  209. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.d.ts.map +1 -0
  210. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.js +76 -0
  211. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.js.map +1 -0
  212. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.d.ts +6 -0
  213. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.d.ts.map +1 -1
  214. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js +1 -1
  215. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js.map +1 -1
  216. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.test.js +1 -1
  217. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.test.js.map +1 -1
  218. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts +1 -1
  219. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts.map +1 -1
  220. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js +1 -1
  221. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js.map +1 -1
  222. package/node_modules/@cchistory/source-adapters/dist/core/token-usage.d.ts +1 -13
  223. package/node_modules/@cchistory/source-adapters/dist/core/token-usage.d.ts.map +1 -1
  224. package/node_modules/@cchistory/source-adapters/dist/core/token-usage.js +1 -246
  225. package/node_modules/@cchistory/source-adapters/dist/core/token-usage.js.map +1 -1
  226. package/node_modules/@cchistory/source-adapters/dist/core/tokens.test.js +1 -1
  227. package/node_modules/@cchistory/source-adapters/dist/core/tokens.test.js.map +1 -1
  228. package/node_modules/@cchistory/source-adapters/dist/core/type-guards.d.ts +1 -25
  229. package/node_modules/@cchistory/source-adapters/dist/core/type-guards.d.ts.map +1 -1
  230. package/node_modules/@cchistory/source-adapters/dist/core/type-guards.js +1 -79
  231. package/node_modules/@cchistory/source-adapters/dist/core/type-guards.js.map +1 -1
  232. package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts +6 -35
  233. package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts.map +1 -1
  234. package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.d.ts +2 -1
  235. package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.d.ts.map +1 -1
  236. package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.js +14 -10
  237. package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.js.map +1 -1
  238. package/node_modules/@cchistory/source-adapters/dist/index.d.ts +6 -0
  239. package/node_modules/@cchistory/source-adapters/dist/index.d.ts.map +1 -1
  240. package/node_modules/@cchistory/source-adapters/dist/index.js +4 -0
  241. package/node_modules/@cchistory/source-adapters/dist/index.js.map +1 -1
  242. package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts +2 -0
  243. package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts.map +1 -1
  244. package/node_modules/@cchistory/source-adapters/dist/index.test.js +2 -0
  245. package/node_modules/@cchistory/source-adapters/dist/index.test.js.map +1 -1
  246. package/node_modules/@cchistory/source-adapters/dist/masks.d.ts +1 -30
  247. package/node_modules/@cchistory/source-adapters/dist/masks.d.ts.map +1 -1
  248. package/node_modules/@cchistory/source-adapters/dist/masks.js +1 -341
  249. package/node_modules/@cchistory/source-adapters/dist/masks.js.map +1 -1
  250. package/node_modules/@cchistory/source-adapters/dist/platforms/accio.test.js +1 -1
  251. package/node_modules/@cchistory/source-adapters/dist/platforms/accio.test.js.map +1 -1
  252. package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.js +1 -1
  253. package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.js.map +1 -1
  254. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.test.js +2 -1
  255. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.test.js.map +1 -1
  256. package/node_modules/@cchistory/source-adapters/dist/platforms/claude.test.js +1 -1
  257. package/node_modules/@cchistory/source-adapters/dist/platforms/claude.test.js.map +1 -1
  258. package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.test.js +1 -1
  259. package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.test.js.map +1 -1
  260. package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.d.ts +14 -0
  261. package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.d.ts.map +1 -0
  262. package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.js +103 -0
  263. package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.js.map +1 -0
  264. package/node_modules/@cchistory/source-adapters/dist/platforms/codex.test.js +1 -1
  265. package/node_modules/@cchistory/source-adapters/dist/platforms/codex.test.js.map +1 -1
  266. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.d.ts +2 -1
  267. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.d.ts.map +1 -1
  268. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.js +5 -3
  269. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.js.map +1 -1
  270. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js +2 -1
  271. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js.map +1 -1
  272. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.test.js +2 -1
  273. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.test.js.map +1 -1
  274. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.test.js +1 -1
  275. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.test.js.map +1 -1
  276. package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.test.js +2 -1
  277. package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.test.js.map +1 -1
  278. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.d.ts.map +1 -1
  279. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.js +24 -1
  280. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.js.map +1 -1
  281. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.test.js +2 -1
  282. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.test.js.map +1 -1
  283. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.test.js +2 -1
  284. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.test.js.map +1 -1
  285. package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.test.js +1 -1
  286. package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.test.js.map +1 -1
  287. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.test.js +1 -1
  288. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.test.js.map +1 -1
  289. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.test.js +2 -1
  290. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.test.js.map +1 -1
  291. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.d.ts +2 -1
  292. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.d.ts.map +1 -1
  293. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.js +11 -9
  294. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.js.map +1 -1
  295. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.test.js +2 -1
  296. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.test.js.map +1 -1
  297. package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.d.ts +8 -0
  298. package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.d.ts.map +1 -0
  299. package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.js +7 -0
  300. package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.js.map +1 -0
  301. package/node_modules/@cchistory/source-adapters/dist/test-helpers.js.map +1 -1
  302. package/node_modules/@cchistory/source-adapters/package.json +1 -1
  303. package/node_modules/commander/LICENSE +22 -0
  304. package/node_modules/commander/Readme.md +428 -0
  305. package/node_modules/commander/index.js +1224 -0
  306. package/node_modules/commander/package.json +38 -0
  307. package/node_modules/commander/typings/index.d.ts +310 -0
  308. package/node_modules/discontinuous-range/.npmignore +28 -0
  309. package/node_modules/discontinuous-range/.travis.yml +4 -0
  310. package/node_modules/discontinuous-range/LICENSE +21 -0
  311. package/node_modules/discontinuous-range/README.md +23 -0
  312. package/node_modules/discontinuous-range/index.js +144 -0
  313. package/node_modules/discontinuous-range/package.json +27 -0
  314. package/node_modules/discontinuous-range/test/main-test.js +96 -0
  315. package/node_modules/moo/LICENSE +29 -0
  316. package/node_modules/moo/README.md +385 -0
  317. package/node_modules/moo/moo.js +645 -0
  318. package/node_modules/moo/package.json +29 -0
  319. package/node_modules/nearley/LICENSE.txt +21 -0
  320. package/node_modules/nearley/README.md +80 -0
  321. package/node_modules/nearley/bin/nearley-railroad.js +121 -0
  322. package/node_modules/nearley/bin/nearley-test.js +64 -0
  323. package/node_modules/nearley/bin/nearley-unparse.js +29 -0
  324. package/node_modules/nearley/bin/nearleyc.js +38 -0
  325. package/node_modules/nearley/builtin/cow.ne +2 -0
  326. package/node_modules/nearley/builtin/number.ne +51 -0
  327. package/node_modules/nearley/builtin/postprocessors.ne +36 -0
  328. package/node_modules/nearley/builtin/string.ne +26 -0
  329. package/node_modules/nearley/builtin/whitespace.ne +5 -0
  330. package/node_modules/nearley/lib/compile.js +307 -0
  331. package/node_modules/nearley/lib/generate.js +244 -0
  332. package/node_modules/nearley/lib/lint.js +28 -0
  333. package/node_modules/nearley/lib/nearley-language-bootstrapped.js +132 -0
  334. package/node_modules/nearley/lib/nearley-language-bootstrapped.ne +126 -0
  335. package/node_modules/nearley/lib/nearley.js +564 -0
  336. package/node_modules/nearley/lib/stream.js +18 -0
  337. package/node_modules/nearley/lib/unparse.js +139 -0
  338. package/node_modules/nearley/package.json +63 -0
  339. package/node_modules/pgsql-ast-parser/ast-mapper.d.ts +237 -0
  340. package/node_modules/pgsql-ast-parser/ast-mapper.d.ts.map +1 -0
  341. package/node_modules/pgsql-ast-parser/ast-mapper.spec.d.ts +3 -0
  342. package/node_modules/pgsql-ast-parser/ast-mapper.spec.d.ts.map +1 -0
  343. package/node_modules/pgsql-ast-parser/ast-visitor.d.ts +33 -0
  344. package/node_modules/pgsql-ast-parser/ast-visitor.d.ts.map +1 -0
  345. package/node_modules/pgsql-ast-parser/ast-visitor.spec.d.ts +3 -0
  346. package/node_modules/pgsql-ast-parser/ast-visitor.spec.d.ts.map +1 -0
  347. package/node_modules/pgsql-ast-parser/index.d.ts +11 -0
  348. package/node_modules/pgsql-ast-parser/index.d.ts.map +1 -0
  349. package/node_modules/pgsql-ast-parser/index.js +6484 -0
  350. package/node_modules/pgsql-ast-parser/index.js.map +1 -0
  351. package/node_modules/pgsql-ast-parser/interfaces.d.ts +1 -0
  352. package/node_modules/pgsql-ast-parser/interfaces.d.ts.map +1 -0
  353. package/node_modules/pgsql-ast-parser/keywords.d.ts +2 -0
  354. package/node_modules/pgsql-ast-parser/keywords.d.ts.map +1 -0
  355. package/node_modules/pgsql-ast-parser/lexer.d.ts +15 -0
  356. package/node_modules/pgsql-ast-parser/lexer.d.ts.map +1 -0
  357. package/node_modules/pgsql-ast-parser/lexer.spec.d.ts +3 -0
  358. package/node_modules/pgsql-ast-parser/lexer.spec.d.ts.map +1 -0
  359. package/node_modules/pgsql-ast-parser/literal-syntaxes/array-lexer.d.ts +3 -0
  360. package/node_modules/pgsql-ast-parser/literal-syntaxes/array-lexer.d.ts.map +1 -0
  361. package/node_modules/pgsql-ast-parser/literal-syntaxes/array.ne.d.ts +29 -0
  362. package/node_modules/pgsql-ast-parser/literal-syntaxes/array.ne.d.ts.map +1 -0
  363. package/node_modules/pgsql-ast-parser/literal-syntaxes/array.spec.d.ts +3 -0
  364. package/node_modules/pgsql-ast-parser/literal-syntaxes/array.spec.d.ts.map +1 -0
  365. package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric-lexer.d.ts +3 -0
  366. package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric-lexer.d.ts.map +1 -0
  367. package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.ne.d.ts +29 -0
  368. package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.ne.d.ts.map +1 -0
  369. package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.spec.d.ts +3 -0
  370. package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.spec.d.ts.map +1 -0
  371. package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-builder.d.ts +10 -0
  372. package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-builder.d.ts.map +1 -0
  373. package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso-lexer.d.ts +3 -0
  374. package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso-lexer.d.ts.map +1 -0
  375. package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso.ne.d.ts +29 -0
  376. package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso.ne.d.ts.map +1 -0
  377. package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-lexer.d.ts +3 -0
  378. package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-lexer.d.ts.map +1 -0
  379. package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.ne.d.ts +29 -0
  380. package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.ne.d.ts.map +1 -0
  381. package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.spec.d.ts +3 -0
  382. package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.spec.d.ts.map +1 -0
  383. package/node_modules/pgsql-ast-parser/package.json +69 -0
  384. package/node_modules/pgsql-ast-parser/parser.d.ts +33 -0
  385. package/node_modules/pgsql-ast-parser/parser.d.ts.map +1 -0
  386. package/node_modules/pgsql-ast-parser/pg-escape.d.ts +2 -0
  387. package/node_modules/pgsql-ast-parser/pg-escape.d.ts.map +1 -0
  388. package/node_modules/pgsql-ast-parser/readme.md +255 -0
  389. package/node_modules/pgsql-ast-parser/src/ast-mapper.spec.ts +296 -0
  390. package/node_modules/pgsql-ast-parser/src/ast-mapper.ts +1378 -0
  391. package/node_modules/pgsql-ast-parser/src/ast-visitor.spec.ts +57 -0
  392. package/node_modules/pgsql-ast-parser/src/ast-visitor.ts +101 -0
  393. package/node_modules/pgsql-ast-parser/src/index.ts +10 -0
  394. package/node_modules/pgsql-ast-parser/src/interfaces.ts +0 -0
  395. package/node_modules/pgsql-ast-parser/src/keywords.ts +8 -0
  396. package/node_modules/pgsql-ast-parser/src/lexer.spec.ts +245 -0
  397. package/node_modules/pgsql-ast-parser/src/lexer.ts +267 -0
  398. package/node_modules/pgsql-ast-parser/src/literal-syntaxes/array-lexer.ts +27 -0
  399. package/node_modules/pgsql-ast-parser/src/literal-syntaxes/array.ne +18 -0
  400. package/node_modules/pgsql-ast-parser/src/literal-syntaxes/array.spec.ts +55 -0
  401. package/node_modules/pgsql-ast-parser/src/literal-syntaxes/geometric-lexer.ts +26 -0
  402. package/node_modules/pgsql-ast-parser/src/literal-syntaxes/geometric.ne +88 -0
  403. package/node_modules/pgsql-ast-parser/src/literal-syntaxes/geometric.spec.ts +131 -0
  404. package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-builder.ts +148 -0
  405. package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-iso-lexer.ts +17 -0
  406. package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-iso.ne +53 -0
  407. package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-lexer.ts +26 -0
  408. package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval.ne +54 -0
  409. package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval.spec.ts +106 -0
  410. package/node_modules/pgsql-ast-parser/src/parser.ts +142 -0
  411. package/node_modules/pgsql-ast-parser/src/pg-escape.ts +14 -0
  412. package/node_modules/pgsql-ast-parser/src/syntax/alter-index.ne +29 -0
  413. package/node_modules/pgsql-ast-parser/src/syntax/alter-index.spec.ts +35 -0
  414. package/node_modules/pgsql-ast-parser/src/syntax/alter-table.ne +123 -0
  415. package/node_modules/pgsql-ast-parser/src/syntax/alter-table.spec.ts +476 -0
  416. package/node_modules/pgsql-ast-parser/src/syntax/alter-type.ne +33 -0
  417. package/node_modules/pgsql-ast-parser/src/syntax/alter-type.spec.ts +29 -0
  418. package/node_modules/pgsql-ast-parser/src/syntax/ast.ts +1150 -0
  419. package/node_modules/pgsql-ast-parser/src/syntax/base.ne +369 -0
  420. package/node_modules/pgsql-ast-parser/src/syntax/create-extension.ne +17 -0
  421. package/node_modules/pgsql-ast-parser/src/syntax/create-extension.spec.ts +37 -0
  422. package/node_modules/pgsql-ast-parser/src/syntax/create-index.ne +62 -0
  423. package/node_modules/pgsql-ast-parser/src/syntax/create-index.spec.ts +245 -0
  424. package/node_modules/pgsql-ast-parser/src/syntax/create-table.ne +174 -0
  425. package/node_modules/pgsql-ast-parser/src/syntax/create-table.spec.ts +761 -0
  426. package/node_modules/pgsql-ast-parser/src/syntax/create-type.ne +40 -0
  427. package/node_modules/pgsql-ast-parser/src/syntax/create-type.spec.ts +32 -0
  428. package/node_modules/pgsql-ast-parser/src/syntax/create-view.ne +68 -0
  429. package/node_modules/pgsql-ast-parser/src/syntax/create-view.spec.ts +187 -0
  430. package/node_modules/pgsql-ast-parser/src/syntax/deallocate.ne +13 -0
  431. package/node_modules/pgsql-ast-parser/src/syntax/deallocate.spec.ts +19 -0
  432. package/node_modules/pgsql-ast-parser/src/syntax/delete.ne +36 -0
  433. package/node_modules/pgsql-ast-parser/src/syntax/delete.spec.ts +71 -0
  434. package/node_modules/pgsql-ast-parser/src/syntax/drop.ne +28 -0
  435. package/node_modules/pgsql-ast-parser/src/syntax/drop.spec.ts +77 -0
  436. package/node_modules/pgsql-ast-parser/src/syntax/edge-cases.spec.ts +41 -0
  437. package/node_modules/pgsql-ast-parser/src/syntax/expr.ne +350 -0
  438. package/node_modules/pgsql-ast-parser/src/syntax/expr.spec.ts +1638 -0
  439. package/node_modules/pgsql-ast-parser/src/syntax/functions.ne +114 -0
  440. package/node_modules/pgsql-ast-parser/src/syntax/functions.spec.ts +235 -0
  441. package/node_modules/pgsql-ast-parser/src/syntax/insert.ne +63 -0
  442. package/node_modules/pgsql-ast-parser/src/syntax/insert.spec.ts +292 -0
  443. package/node_modules/pgsql-ast-parser/src/syntax/main.ne +77 -0
  444. package/node_modules/pgsql-ast-parser/src/syntax/nearley.d.ts +3 -0
  445. package/node_modules/pgsql-ast-parser/src/syntax/prepare.ne +8 -0
  446. package/node_modules/pgsql-ast-parser/src/syntax/prepare.spec.ts +44 -0
  447. package/node_modules/pgsql-ast-parser/src/syntax/refresh-materialized-view.ne +19 -0
  448. package/node_modules/pgsql-ast-parser/src/syntax/refresh-materialized-view.spec.ts +42 -0
  449. package/node_modules/pgsql-ast-parser/src/syntax/select.ne +223 -0
  450. package/node_modules/pgsql-ast-parser/src/syntax/select.spec.ts +1063 -0
  451. package/node_modules/pgsql-ast-parser/src/syntax/sequence.ne +101 -0
  452. package/node_modules/pgsql-ast-parser/src/syntax/sequence.spec.ts +103 -0
  453. package/node_modules/pgsql-ast-parser/src/syntax/simple-statements.ne +168 -0
  454. package/node_modules/pgsql-ast-parser/src/syntax/simple-statements.spec.ts +327 -0
  455. package/node_modules/pgsql-ast-parser/src/syntax/spec-utils.ts +333 -0
  456. package/node_modules/pgsql-ast-parser/src/syntax/union.ne +18 -0
  457. package/node_modules/pgsql-ast-parser/src/syntax/union.spec.ts +125 -0
  458. package/node_modules/pgsql-ast-parser/src/syntax/update.ne +56 -0
  459. package/node_modules/pgsql-ast-parser/src/syntax/update.spec.ts +87 -0
  460. package/node_modules/pgsql-ast-parser/src/syntax/with.ne +41 -0
  461. package/node_modules/pgsql-ast-parser/src/syntax/with.spec.ts +155 -0
  462. package/node_modules/pgsql-ast-parser/src/to-sql.spec.ts +85 -0
  463. package/node_modules/pgsql-ast-parser/src/to-sql.ts +1555 -0
  464. package/node_modules/pgsql-ast-parser/src/utils.ts +47 -0
  465. package/node_modules/pgsql-ast-parser/syntax/alter-index.spec.d.ts +3 -0
  466. package/node_modules/pgsql-ast-parser/syntax/alter-index.spec.d.ts.map +1 -0
  467. package/node_modules/pgsql-ast-parser/syntax/alter-table.spec.d.ts +3 -0
  468. package/node_modules/pgsql-ast-parser/syntax/alter-table.spec.d.ts.map +1 -0
  469. package/node_modules/pgsql-ast-parser/syntax/alter-type.spec.d.ts +3 -0
  470. package/node_modules/pgsql-ast-parser/syntax/alter-type.spec.d.ts.map +1 -0
  471. package/node_modules/pgsql-ast-parser/syntax/ast.d.ts +826 -0
  472. package/node_modules/pgsql-ast-parser/syntax/ast.d.ts.map +1 -0
  473. package/node_modules/pgsql-ast-parser/syntax/create-extension.spec.d.ts +3 -0
  474. package/node_modules/pgsql-ast-parser/syntax/create-extension.spec.d.ts.map +1 -0
  475. package/node_modules/pgsql-ast-parser/syntax/create-index.spec.d.ts +3 -0
  476. package/node_modules/pgsql-ast-parser/syntax/create-index.spec.d.ts.map +1 -0
  477. package/node_modules/pgsql-ast-parser/syntax/create-table.spec.d.ts +3 -0
  478. package/node_modules/pgsql-ast-parser/syntax/create-table.spec.d.ts.map +1 -0
  479. package/node_modules/pgsql-ast-parser/syntax/create-type.spec.d.ts +3 -0
  480. package/node_modules/pgsql-ast-parser/syntax/create-type.spec.d.ts.map +1 -0
  481. package/node_modules/pgsql-ast-parser/syntax/create-view.spec.d.ts +3 -0
  482. package/node_modules/pgsql-ast-parser/syntax/create-view.spec.d.ts.map +1 -0
  483. package/node_modules/pgsql-ast-parser/syntax/deallocate.spec.d.ts +3 -0
  484. package/node_modules/pgsql-ast-parser/syntax/deallocate.spec.d.ts.map +1 -0
  485. package/node_modules/pgsql-ast-parser/syntax/delete.spec.d.ts +3 -0
  486. package/node_modules/pgsql-ast-parser/syntax/delete.spec.d.ts.map +1 -0
  487. package/node_modules/pgsql-ast-parser/syntax/drop.spec.d.ts +3 -0
  488. package/node_modules/pgsql-ast-parser/syntax/drop.spec.d.ts.map +1 -0
  489. package/node_modules/pgsql-ast-parser/syntax/edge-cases.spec.d.ts +3 -0
  490. package/node_modules/pgsql-ast-parser/syntax/edge-cases.spec.d.ts.map +1 -0
  491. package/node_modules/pgsql-ast-parser/syntax/expr.spec.d.ts +3 -0
  492. package/node_modules/pgsql-ast-parser/syntax/expr.spec.d.ts.map +1 -0
  493. package/node_modules/pgsql-ast-parser/syntax/functions.spec.d.ts +3 -0
  494. package/node_modules/pgsql-ast-parser/syntax/functions.spec.d.ts.map +1 -0
  495. package/node_modules/pgsql-ast-parser/syntax/insert.spec.d.ts +3 -0
  496. package/node_modules/pgsql-ast-parser/syntax/insert.spec.d.ts.map +1 -0
  497. package/node_modules/pgsql-ast-parser/syntax/main.ne.d.ts +29 -0
  498. package/node_modules/pgsql-ast-parser/syntax/main.ne.d.ts.map +1 -0
  499. package/node_modules/pgsql-ast-parser/syntax/prepare.spec.d.ts +3 -0
  500. package/node_modules/pgsql-ast-parser/syntax/prepare.spec.d.ts.map +1 -0
  501. package/node_modules/pgsql-ast-parser/syntax/refresh-materialized-view.spec.d.ts +3 -0
  502. package/node_modules/pgsql-ast-parser/syntax/refresh-materialized-view.spec.d.ts.map +1 -0
  503. package/node_modules/pgsql-ast-parser/syntax/select.spec.d.ts +3 -0
  504. package/node_modules/pgsql-ast-parser/syntax/select.spec.d.ts.map +1 -0
  505. package/node_modules/pgsql-ast-parser/syntax/sequence.spec.d.ts +3 -0
  506. package/node_modules/pgsql-ast-parser/syntax/sequence.spec.d.ts.map +1 -0
  507. package/node_modules/pgsql-ast-parser/syntax/simple-statements.spec.d.ts +3 -0
  508. package/node_modules/pgsql-ast-parser/syntax/simple-statements.spec.d.ts.map +1 -0
  509. package/node_modules/pgsql-ast-parser/syntax/spec-utils.d.ts +35 -0
  510. package/node_modules/pgsql-ast-parser/syntax/spec-utils.d.ts.map +1 -0
  511. package/node_modules/pgsql-ast-parser/syntax/union.spec.d.ts +3 -0
  512. package/node_modules/pgsql-ast-parser/syntax/union.spec.d.ts.map +1 -0
  513. package/node_modules/pgsql-ast-parser/syntax/update.spec.d.ts +3 -0
  514. package/node_modules/pgsql-ast-parser/syntax/update.spec.d.ts.map +1 -0
  515. package/node_modules/pgsql-ast-parser/syntax/with.spec.d.ts +3 -0
  516. package/node_modules/pgsql-ast-parser/syntax/with.spec.d.ts.map +1 -0
  517. package/node_modules/pgsql-ast-parser/to-sql.d.ts +7 -0
  518. package/node_modules/pgsql-ast-parser/to-sql.d.ts.map +1 -0
  519. package/node_modules/pgsql-ast-parser/to-sql.spec.d.ts +3 -0
  520. package/node_modules/pgsql-ast-parser/to-sql.spec.d.ts.map +1 -0
  521. package/node_modules/pgsql-ast-parser/utils.d.ts +16 -0
  522. package/node_modules/pgsql-ast-parser/utils.d.ts.map +1 -0
  523. package/node_modules/railroad-diagrams/.gitattributes +22 -0
  524. package/node_modules/railroad-diagrams/.npmignore +163 -0
  525. package/node_modules/railroad-diagrams/README.md +86 -0
  526. package/node_modules/railroad-diagrams/css-example.py-js +183 -0
  527. package/node_modules/railroad-diagrams/example.html +141 -0
  528. package/node_modules/railroad-diagrams/generator.html +59 -0
  529. package/node_modules/railroad-diagrams/package.json +23 -0
  530. package/node_modules/railroad-diagrams/railroad-diagrams.css +23 -0
  531. package/node_modules/railroad-diagrams/railroad-diagrams.js +524 -0
  532. package/node_modules/railroad-diagrams/railroad_diagrams.py +427 -0
  533. package/node_modules/randexp/LICENSE +19 -0
  534. package/node_modules/randexp/README.md +134 -0
  535. package/node_modules/randexp/lib/randexp.js +245 -0
  536. package/node_modules/randexp/package.json +48 -0
  537. package/node_modules/ret/LICENSE +19 -0
  538. package/node_modules/ret/README.md +183 -0
  539. package/node_modules/ret/lib/index.js +282 -0
  540. package/node_modules/ret/lib/positions.js +17 -0
  541. package/node_modules/ret/lib/sets.js +82 -0
  542. package/node_modules/ret/lib/types.js +10 -0
  543. package/node_modules/ret/lib/util.js +111 -0
  544. package/node_modules/ret/package.json +35 -0
  545. package/package.json +22 -6
  546. package/schemas/cchistory-lite-agent-v1.schema.json +6 -7
  547. package/schemas/cchistory-lite-error-v1.schema.json +58 -8
  548. package/schemas/cchistory-lite-query-result-v2.schema.json +66 -11
  549. package/schemas/cchistory-lite-query-result-v3.schema.json +219 -0
  550. package/schemas/cchistory-lite-query-v3.schema.json +57 -0
  551. package/schemas/cchistory-lite-source-inventory-v1.schema.json +72 -0
  552. package/skills/using-cchistory-lite/SKILL.md +126 -55
  553. package/node_modules/@cchistory/live-runtime/dist/node-memory.d.ts +0 -8
  554. package/node_modules/@cchistory/live-runtime/dist/node-memory.d.ts.map +0 -1
  555. package/node_modules/@cchistory/live-runtime/dist/node-memory.js +0 -110
  556. package/node_modules/@cchistory/live-runtime/dist/node-memory.js.map +0 -1
@@ -0,0 +1,1638 @@
1
+ import 'mocha';
2
+ import 'chai';
3
+ import { checkTreeExpr, checkInvalidExpr, checkInvalid, checkTreeExprLoc, starCol, star, col, ref, tbl, name, numeric } from './spec-utils';
4
+ import { toSql } from '../to-sql';
5
+ import { expect } from 'chai';
6
+ import { parse } from '../parser';
7
+
8
+
9
+
10
+ describe('Expressions', () => {
11
+
12
+ // ====================================
13
+ // =============== VALUES =============
14
+ // ====================================
15
+
16
+ describe('Comments', () => {
17
+ checkTreeExpr(['2 /* yo */ + 2', '2 +/* yo */ 2', '2+-- yo \n2', '2-- yo \n+2', '2+-- yo \n \n2'], {
18
+ type: 'binary',
19
+ op: '+',
20
+ left: { type: 'integer', value: 2 },
21
+ right: { type: 'integer', value: 2 },
22
+ });
23
+
24
+ });
25
+
26
+ // ====================================
27
+ // =============== VALUES =============
28
+ // ====================================
29
+
30
+ describe('Simple values & arithmetic precedence', () => {
31
+
32
+ checkTreeExpr(['42'], {
33
+ type: 'integer',
34
+ value: 42,
35
+ });
36
+
37
+ checkTreeExprLoc(['(42)'], {
38
+ _location: { start: 1, end: 3 },
39
+ type: 'integer',
40
+ value: 42,
41
+ });
42
+
43
+ checkTreeExpr(['0.5', '.5'], {
44
+ type: 'numeric',
45
+ value: 0.5,
46
+ });
47
+
48
+ checkTreeExpr(['-0.5', '-.5'], {
49
+ type: 'numeric',
50
+ value: -0.5,
51
+ });
52
+
53
+ checkTreeExpr(['-42.', '-42.0'], {
54
+ type: 'numeric',
55
+ value: -42,
56
+ });
57
+
58
+ checkInvalidExpr('42. 51');
59
+
60
+ checkInvalidExpr('42.-51');
61
+
62
+ checkTreeExprLoc(['null'], {
63
+ _location: { start: 0, end: 4 },
64
+ type: 'null',
65
+ });
66
+
67
+ checkTreeExpr(['true'], {
68
+ type: 'boolean',
69
+ value: true,
70
+ });
71
+
72
+ checkTreeExprLoc(['(true)'], {
73
+ _location: { start: 1, end: 5 },
74
+ type: 'boolean',
75
+ value: true,
76
+ });
77
+
78
+ checkTreeExpr(['false'], {
79
+ type: 'boolean',
80
+ value: false,
81
+ });
82
+
83
+
84
+ checkTreeExprLoc(['(false)'], {
85
+ _location: { start: 1, end: 6 },
86
+ type: 'boolean',
87
+ value: false,
88
+ });
89
+
90
+ checkTreeExprLoc([`'test'`], {
91
+ _location: { start: 0, end: 6 },
92
+ type: 'string',
93
+ value: 'test',
94
+ });
95
+
96
+ checkTreeExpr([`'te''st'`], {
97
+ type: 'string',
98
+ value: `te'st`,
99
+ });
100
+
101
+ checkTreeExpr([`E'escaped'`], {
102
+ type: 'string',
103
+ value: `escaped`,
104
+ });
105
+
106
+ checkTreeExpr([`E'new
107
+ line'`], {
108
+ type: 'string',
109
+ value: `new
110
+ line`,
111
+ });
112
+
113
+
114
+ checkTreeExpr([`E'some\\twide\ttabs'`], {
115
+ type: 'string',
116
+ value: `some\twide\ttabs`,
117
+ });
118
+
119
+
120
+ checkTreeExpr([`E'new\\nline'`], {
121
+ type: 'string',
122
+ value: `new
123
+ line`,
124
+ });
125
+
126
+
127
+ checkTreeExpr([`E'new\\\\
128
+ line'`], {
129
+ type: 'string',
130
+ value: `new\\
131
+ line`,
132
+ });
133
+
134
+
135
+
136
+ checkTreeExpr([`E'new\\
137
+ line'`], {
138
+ type: 'string',
139
+ value: `new
140
+ line`,
141
+ });
142
+
143
+ checkTreeExpr([`E'"double quote"'`], {
144
+ type: 'string',
145
+ value: `"double quote"`,
146
+ });
147
+
148
+ checkTreeExpr([`E'single''quote'`], {
149
+ type: 'string',
150
+ value: `single'quote`,
151
+ });
152
+
153
+ checkTreeExpr([`E'"antislash"\\\\
154
+ "return"\\n
155
+ "quote" ''
156
+ "tab"\t\\t'`], {
157
+ type: 'string',
158
+ value: `"antislash"\\
159
+ "return"
160
+
161
+ "quote" '
162
+ "tab"\t\t`,
163
+ });
164
+
165
+ checkTreeExpr([`'te"s\\\\t'`], {
166
+ type: 'string',
167
+ value: `te"s\\\\t`,
168
+ });
169
+
170
+ checkTreeExpr([`'te\\n\\tst'`], {
171
+ type: 'string',
172
+ value: `te\\n\\tst`,
173
+ });
174
+
175
+ checkTreeExpr('*', {
176
+ type: 'ref',
177
+ name: '*',
178
+ });
179
+
180
+ checkTreeExpr('a.*', {
181
+ type: 'ref',
182
+ table: { name: 'a' },
183
+ name: '*',
184
+ });
185
+
186
+ checkTreeExpr('a.b', {
187
+ type: 'ref',
188
+ table: { name: 'a' },
189
+ name: 'b',
190
+ });
191
+
192
+ checkTreeExpr('a.b.c', {
193
+ type: 'ref',
194
+ table: { name: 'b', schema: 'a' },
195
+ name: 'c',
196
+ });
197
+
198
+ checkTreeExpr([`a->>'b'`], {
199
+ type: 'member',
200
+ op: '->>',
201
+ member: 'b',
202
+ operand: {
203
+ type: 'ref',
204
+ name: 'a',
205
+ }
206
+ });
207
+
208
+
209
+ checkTreeExprLoc([`a ->> 'b'`], {
210
+ _location: { start: 0, end: 9 },
211
+ type: 'member',
212
+ op: '->>',
213
+ member: 'b',
214
+ operand: {
215
+ _location: { start: 0, end: 1 },
216
+ type: 'ref',
217
+ name: 'a',
218
+ }
219
+ });
220
+
221
+ checkTreeExpr([`t.a->'b'`, `t."a" -> 'b'`], {
222
+ type: 'member',
223
+ op: '->',
224
+ member: 'b',
225
+ operand: {
226
+ type: 'ref',
227
+ name: 'a',
228
+ table: { name: 't' },
229
+ }
230
+ });
231
+
232
+ checkTreeExpr([`data::jsonb->'b'`, `("data"::jsonb)->'b'`, `("data")::jsonb->'b'`, `(data::jsonb) -> 'b'`], {
233
+ type: 'member',
234
+ op: '->',
235
+ member: 'b',
236
+ operand: {
237
+ type: 'cast',
238
+ to: { name: 'jsonb' },
239
+ operand: {
240
+ type: 'ref',
241
+ name: 'data',
242
+ }
243
+ }
244
+ });
245
+
246
+ checkTreeExpr([`data::jsonb->'b'::json`, `((data::jsonb) -> 'b')::json`], {
247
+ type: 'cast',
248
+ to: { name: 'json' },
249
+ operand: {
250
+ type: 'member',
251
+ op: '->',
252
+ member: 'b',
253
+ operand: {
254
+ type: 'cast',
255
+ to: { name: 'jsonb' },
256
+ operand: {
257
+ type: 'ref',
258
+ name: 'data',
259
+ }
260
+ }
261
+ }
262
+ });
263
+
264
+ checkTreeExprLoc(`ARRAY[1, '2']`, {
265
+ _location: { start: 0, end: 13 },
266
+ type: 'array',
267
+ expressions: [
268
+ {
269
+ _location: { start: 6, end: 7 },
270
+ type: 'integer', value: 1,
271
+ },
272
+ {
273
+ _location: { start: 9, end: 12 },
274
+ type: 'string', value: '2'
275
+ },
276
+ ]
277
+ });
278
+
279
+ checkTreeExprLoc(`ARRAY[]`, {
280
+ _location: { start: 0, end: 7 },
281
+ type: 'array',
282
+ expressions: [
283
+ ]
284
+ });
285
+
286
+ checkTreeExpr(`ARRAY[['a', 'b']]`, {
287
+ type: 'array',
288
+ expressions: [{
289
+ type: 'array',
290
+ expressions: [{
291
+ type: 'string',
292
+ value: 'a',
293
+ }, {
294
+ type: 'string',
295
+ value: 'b',
296
+ }]
297
+ }]
298
+ });
299
+
300
+
301
+ checkTreeExpr(`ARRAY[ARRAY['a', 'b']]`, {
302
+ type: 'array',
303
+ expressions: [{
304
+ type: 'array',
305
+ expressions: [{
306
+ type: 'string',
307
+ value: 'a',
308
+ }, {
309
+ type: 'string',
310
+ value: 'b',
311
+ }]
312
+ }]
313
+ });
314
+
315
+ checkTreeExpr(`ARRAY[['a'], ['b']]`, {
316
+ type: 'array',
317
+ expressions: [{
318
+ type: 'array',
319
+ expressions: [{
320
+ type: 'string',
321
+ value: 'a',
322
+ }]
323
+ }, {
324
+ type: 'array',
325
+ expressions: [{
326
+ type: 'string',
327
+ value: 'b',
328
+ }]
329
+ }]
330
+ })
331
+
332
+ checkInvalidExpr(`ARRAY[ARRAY['a'], ['b']]`);
333
+ checkInvalidExpr(`ARRAY[['a'], ARRAY['b']]`);
334
+
335
+ checkTreeExpr(`a->>42`, {
336
+ type: 'member',
337
+ op: '->>',
338
+ member: 42,
339
+ operand: {
340
+ type: 'ref',
341
+ name: 'a',
342
+ }
343
+ });
344
+
345
+
346
+ checkTreeExpr(`a#>>b`, {
347
+ type: 'binary',
348
+ op: '#>>',
349
+ left: {
350
+ type: 'ref',
351
+ name: 'a',
352
+ },
353
+ right: {
354
+ type: 'ref',
355
+ name: 'b',
356
+ },
357
+ });
358
+
359
+ checkTreeExpr(`a->>-1`, {
360
+ type: 'member',
361
+ op: '->>',
362
+ member: -1,
363
+ operand: {
364
+ type: 'ref',
365
+ name: 'a',
366
+ }
367
+ });
368
+
369
+ checkTreeExpr(`a.b->-1`, {
370
+ type: 'member',
371
+ op: '->',
372
+ member: -1,
373
+ operand: {
374
+ type: 'ref',
375
+ name: 'b',
376
+ table: { name: 'a' },
377
+ }
378
+ });
379
+
380
+ checkTreeExpr(['42.', '42.0'], {
381
+ type: 'numeric',
382
+ value: 42,
383
+ });
384
+
385
+ checkTreeExpr(['.42', '0.42'], {
386
+ type: 'numeric',
387
+ value: .42,
388
+ });
389
+
390
+ checkTreeExpr(['42+51', '42 + 51'], {
391
+ type: 'binary',
392
+ op: '+',
393
+ left: {
394
+ type: 'integer',
395
+ value: 42,
396
+ },
397
+ right: {
398
+ type: 'integer',
399
+ value: 51,
400
+ }
401
+ });
402
+
403
+ checkTreeExpr(['42*51', '42 * 51'], {
404
+ type: 'binary',
405
+ op: '*',
406
+ left: {
407
+ type: 'integer',
408
+ value: 42,
409
+ },
410
+ right: {
411
+ type: 'integer',
412
+ value: 51,
413
+ }
414
+ });
415
+
416
+
417
+ checkTreeExpr('42 + 51 - 30', {
418
+ type: 'binary',
419
+ op: '-',
420
+ left: {
421
+ type: 'binary',
422
+ op: '+',
423
+ left: {
424
+ type: 'integer',
425
+ value: 42,
426
+ },
427
+ right: {
428
+ type: 'integer',
429
+ value: 51,
430
+ }
431
+ },
432
+ right: {
433
+ type: 'integer',
434
+ value: 30,
435
+ },
436
+ });
437
+
438
+
439
+
440
+ checkTreeExpr('2 + 3 * 4', {
441
+ type: 'binary',
442
+ op: '+',
443
+ left: {
444
+ type: 'integer',
445
+ value: 2,
446
+ },
447
+ right: {
448
+ type: 'binary',
449
+ op: '*',
450
+ left: {
451
+ type: 'integer',
452
+ value: 3,
453
+ },
454
+ right: {
455
+ type: 'integer',
456
+ value: 4,
457
+ }
458
+ }
459
+ });
460
+
461
+ checkTreeExpr('2 * 3 + 4', {
462
+ type: 'binary',
463
+ op: '+',
464
+ left: {
465
+ type: 'binary',
466
+ op: '*',
467
+ left: {
468
+ type: 'integer',
469
+ value: 2,
470
+ },
471
+ right: {
472
+ type: 'integer',
473
+ value: 3,
474
+ }
475
+ },
476
+ right: {
477
+ type: 'integer',
478
+ value: 4,
479
+ },
480
+ });
481
+
482
+
483
+ checkTreeExpr('2. * .3 + 4.5', {
484
+ type: 'binary',
485
+ op: '+',
486
+ left: {
487
+ type: 'binary',
488
+ op: '*',
489
+ left: {
490
+ type: 'numeric',
491
+ value: 2,
492
+ },
493
+ right: {
494
+ type: 'numeric',
495
+ value: 0.3,
496
+ }
497
+ },
498
+ right: {
499
+ type: 'numeric',
500
+ value: 4.5,
501
+ },
502
+ });
503
+
504
+
505
+ checkTreeExpr(['2 * (3 + 4)', '2*(3+4)'], {
506
+ type: 'binary',
507
+ op: '*',
508
+ left: {
509
+ type: 'integer',
510
+ value: 2,
511
+ },
512
+ right: {
513
+ type: 'binary',
514
+ op: '+',
515
+ left: {
516
+ type: 'integer',
517
+ value: 3,
518
+ },
519
+ right: {
520
+ type: 'integer',
521
+ value: 4,
522
+ }
523
+ },
524
+ });
525
+ })
526
+
527
+
528
+ // ====================================
529
+ // =============== LOGIC ==============
530
+ // ====================================
531
+
532
+ describe('Logic', () => {
533
+ checkTreeExpr(['a and b OR c', '"a"AND"b"or"c"', '"a"and "b"or "c"'], {
534
+ type: 'binary',
535
+ op: 'OR',
536
+ left: {
537
+ type: 'binary',
538
+ op: 'AND',
539
+ left: { type: 'ref', name: 'a' },
540
+ right: { type: 'ref', name: 'b' },
541
+ },
542
+ right: { type: 'ref', name: 'c' }
543
+ });
544
+
545
+ checkTreeExpr(['a or b AND c', '"a"OR"b"and"c"', '"a"or "b"and "c"'], {
546
+ type: 'binary',
547
+ op: 'OR',
548
+ left: { type: 'ref', name: 'a' },
549
+ right: {
550
+ type: 'binary',
551
+ op: 'AND',
552
+ left: { type: 'ref', name: 'b' },
553
+ right: { type: 'ref', name: 'c' },
554
+ },
555
+ });
556
+
557
+ checkTreeExprLoc('a.b or c', {
558
+ _location: { start: 0, end: 8 },
559
+ type: 'binary',
560
+ op: 'OR',
561
+ left: {
562
+ _location: { start: 0, end: 3 },
563
+ type: 'ref',
564
+ table: {
565
+ _location: { start: 0, end: 1 },
566
+ name: 'a'
567
+ },
568
+ name: 'b',
569
+ },
570
+ right: {
571
+ _location: { start: 7, end: 8 },
572
+ type: 'ref',
573
+ name: 'c'
574
+ },
575
+ });
576
+ });
577
+
578
+
579
+ // ====================================
580
+ // =============== CASTS ==============
581
+ // ====================================
582
+
583
+ describe('Cast', () => {
584
+ checkTreeExpr(['a + b::jsonb', 'a + b::JSONB'], {
585
+ type: 'binary',
586
+ op: '+',
587
+ left: {
588
+ type: 'ref',
589
+ name: 'a',
590
+ },
591
+ right: {
592
+ type: 'cast',
593
+ to: { name: 'jsonb' },
594
+ operand: {
595
+ type: 'ref',
596
+ name: 'b',
597
+ },
598
+ },
599
+ });
600
+
601
+ checkTreeExpr(`'1'::double precision`, {
602
+ type: 'cast',
603
+ operand: { type: 'string', value: '1' },
604
+ to: { name: 'double precision' },
605
+ });
606
+
607
+ checkTreeExpr(`CAST('1' AS INTEGER)`, {
608
+ type: 'cast',
609
+ operand: { type: 'string', value: '1' },
610
+ to: { name: 'integer' },
611
+ });
612
+
613
+ checkTreeExpr(`CAST('1' AS DOUBLE PRECISION)`, {
614
+ type: 'cast',
615
+ operand: { type: 'string', value: '1' },
616
+ to: { name: 'double precision' },
617
+ });
618
+
619
+ checkTreeExprLoc(`ARRAY[]::text[]`, {
620
+ _location: { start: 0, end: 15 },
621
+ type: 'cast',
622
+ to: {
623
+ _location: { start: 9, end: 15 },
624
+ kind: 'array',
625
+ arrayOf: {
626
+ _location: { start: 9, end: 13 },
627
+ name: 'text',
628
+ }
629
+ },
630
+ operand: {
631
+ _location: { start: 0, end: 7 },
632
+ type: 'array',
633
+ expressions: []
634
+ },
635
+ });
636
+
637
+ checkTreeExprLoc(`timestamp 'value'`, {
638
+ _location: { start: 0, end: 17 },
639
+ type: 'cast',
640
+ to: {
641
+ _location: { start: 0, end: 9 },
642
+ name: 'timestamp',
643
+ },
644
+ operand: {
645
+ _location: { start: 10, end: 17 },
646
+ type: 'string',
647
+ value: 'value',
648
+ },
649
+ });
650
+
651
+ checkTreeExpr(`time 'value'`, {
652
+ type: 'cast',
653
+ to: { name: 'time' },
654
+ operand: {
655
+ type: 'string',
656
+ value: 'value'
657
+ },
658
+ });
659
+
660
+
661
+ checkTreeExpr(`interval 'value'`, {
662
+ type: 'cast',
663
+ to: { name: 'interval' },
664
+ operand: { type: 'string', value: 'value' },
665
+ });
666
+
667
+ checkTreeExpr(['"a"+"b"::"JSONB"'], {
668
+ type: 'binary',
669
+ op: '+',
670
+ left: {
671
+ type: 'ref',
672
+ name: 'a',
673
+ },
674
+ right: {
675
+ type: 'cast',
676
+ to: { name: 'JSONB', doubleQuoted: true },
677
+ operand: {
678
+ type: 'ref',
679
+ name: 'b',
680
+ },
681
+ },
682
+ });
683
+
684
+ checkTreeExpr(['(a + b)::"jsonb"'], {
685
+ type: 'cast',
686
+ to: { name: 'jsonb', doubleQuoted: true },
687
+ operand: {
688
+ type: 'binary',
689
+ op: '+',
690
+ left: {
691
+ type: 'ref',
692
+ name: 'a',
693
+ },
694
+ right: {
695
+ type: 'ref',
696
+ name: 'b',
697
+ }
698
+ },
699
+ });
700
+
701
+ checkTreeExpr(['(a + b)::jsonb'], {
702
+ type: 'cast',
703
+ to: { name: 'jsonb' },
704
+ operand: {
705
+ type: 'binary',
706
+ op: '+',
707
+ left: {
708
+ type: 'ref',
709
+ name: 'a',
710
+ },
711
+ right: {
712
+ type: 'ref',
713
+ name: 'b',
714
+ }
715
+ },
716
+ });
717
+
718
+ checkTreeExpr(`('now'::text)::timestamp(4) with time zone`, {
719
+ type: 'cast',
720
+ to: {
721
+ name: 'timestamp with time zone',
722
+ config: [4],
723
+ },
724
+ operand: {
725
+ type: 'cast',
726
+ to: { name: 'text' },
727
+ operand: { type: 'string', value: 'now' },
728
+ },
729
+ });
730
+ });
731
+
732
+
733
+ // ====================================
734
+ // =============== UNARIES ============
735
+ // ====================================
736
+ describe('Unaries', () => {
737
+ checkTreeExprLoc(['not e and b'], {
738
+ _location: { start: 0, end: 11 },
739
+ type: 'binary',
740
+ op: 'AND',
741
+ left: {
742
+ _location: { start: 0, end: 5 },
743
+ type: 'unary',
744
+ op: 'NOT',
745
+ operand: {
746
+ _location: { start: 4, end: 5 },
747
+ type: 'ref', name: 'e'
748
+ },
749
+ },
750
+ right: {
751
+ _location: { start: 10, end: 11 },
752
+ type: 'ref', name: 'b'
753
+ },
754
+ });
755
+
756
+ checkTreeExpr(['NOT"e"and"b"'], {
757
+ type: 'binary',
758
+ op: 'AND',
759
+ left: {
760
+ type: 'unary',
761
+ op: 'NOT',
762
+ operand: { type: 'ref', name: 'e' },
763
+ },
764
+ right: { type: 'ref', name: 'b' },
765
+ });
766
+
767
+ checkInvalidExpr('"*"');
768
+ checkInvalidExpr('(*)');
769
+
770
+ checkTreeExpr(['not a is null', 'not"a"is null', 'not a isnull', 'not"a"isnull'], {
771
+ type: 'unary',
772
+ op: 'NOT',
773
+ operand: {
774
+ type: 'unary',
775
+ op: 'IS NULL',
776
+ operand: { type: 'ref', name: 'a' }
777
+ }
778
+ });
779
+
780
+ checkTreeExpr(['a is not null', 'a notnull', '"a"notnull'], {
781
+ type: 'unary',
782
+ op: 'IS NOT NULL',
783
+ operand: { type: 'ref', name: 'a' }
784
+ });
785
+
786
+
787
+ checkTreeExpr(['a is null is null', '(a is null) is null', 'a isnull isnull', '(a isnull) isnull', 'a is null isnull', 'a isnull is null'], {
788
+ type: 'unary',
789
+ op: 'IS NULL',
790
+ operand: {
791
+ type: 'unary',
792
+ op: 'IS NULL',
793
+ operand: { type: 'ref', name: 'a' },
794
+ }
795
+ });
796
+
797
+ checkTreeExpr(['a is false is true'], {
798
+ type: 'unary',
799
+ op: 'IS TRUE',
800
+ operand: {
801
+ type: 'unary',
802
+ op: 'IS FALSE',
803
+ operand: { type: 'ref', name: 'a' },
804
+ }
805
+ });
806
+
807
+ checkTreeExpr(['a is not false is not true'], {
808
+ type: 'unary',
809
+ op: 'IS NOT TRUE',
810
+ operand: {
811
+ type: 'unary',
812
+ op: 'IS NOT FALSE',
813
+ operand: { type: 'ref', name: 'a' },
814
+ }
815
+ });
816
+
817
+
818
+ checkTreeExpr(['+a', '+ a', '+"a"'], {
819
+ type: 'unary',
820
+ op: '+',
821
+ operand: { type: 'ref', name: 'a' }
822
+ });
823
+
824
+ checkTreeExpr(['-a', '- a', '-"a"'], {
825
+ type: 'unary',
826
+ op: '-',
827
+ operand: { type: 'ref', name: 'a' }
828
+ });
829
+
830
+
831
+ checkTreeExpr('operator(pg_catalog.-) a', {
832
+ type: 'unary',
833
+ op: '-',
834
+ opSchema: 'pg_catalog',
835
+ operand: { type: 'ref', name: 'a' }
836
+ });
837
+
838
+ });
839
+
840
+
841
+ // ====================================
842
+ // ============== BINARIES ============
843
+ // ====================================
844
+ describe('Binaries', () => {
845
+ checkTreeExpr(['a > b', 'a>b', '"a">"b"'], {
846
+ type: 'binary',
847
+ op: '>',
848
+ left: { type: 'ref', name: 'a' },
849
+ right: { type: 'ref', name: 'b' },
850
+ });
851
+
852
+ checkTreeExpr(['a @@ b'], {
853
+ type: 'binary',
854
+ op: '@@',
855
+ left: { type: 'ref', name: 'a' },
856
+ right: { type: 'ref', name: 'b' },
857
+ });
858
+
859
+
860
+ checkTreeExpr(['a like b', '"a"LIKE"b"', 'a ~~ b', 'a~~b'], {
861
+ type: 'binary',
862
+ op: 'LIKE',
863
+ left: { type: 'ref', name: 'a' },
864
+ right: { type: 'ref', name: 'b' },
865
+ });
866
+
867
+ checkTreeExpr(['a not like b', 'a!~~b', '"a"not LIKE"b"'], {
868
+ type: 'binary',
869
+ op: 'NOT LIKE',
870
+ left: { type: 'ref', name: 'a' },
871
+ right: { type: 'ref', name: 'b' },
872
+ });
873
+
874
+ checkTreeExpr(['a ilike b', 'a~~*b'], {
875
+ type: 'binary',
876
+ op: 'ILIKE',
877
+ left: { type: 'ref', name: 'a' },
878
+ right: { type: 'ref', name: 'b' },
879
+ });
880
+
881
+ checkTreeExpr(['a not ilike b', 'a!~~*b'], {
882
+ type: 'binary',
883
+ op: 'NOT ILIKE',
884
+ left: { type: 'ref', name: 'a' },
885
+ right: { type: 'ref', name: 'b' },
886
+ });
887
+
888
+ checkTreeExpr(['a in b', '"a"IN"b"'], {
889
+ type: 'binary',
890
+ op: 'IN',
891
+ left: { type: 'ref', name: 'a' },
892
+ right: { type: 'ref', name: 'b' },
893
+ });
894
+
895
+ checkTreeExpr(['a not in b', '"a"NOT IN"b"'], {
896
+ type: 'binary',
897
+ op: 'NOT IN',
898
+ left: { type: 'ref', name: 'a' },
899
+ right: { type: 'ref', name: 'b' },
900
+ });
901
+
902
+ checkTreeExpr(['a = b', '"a"="b"'], {
903
+ type: 'binary',
904
+ op: '=',
905
+ left: { type: 'ref', name: 'a' },
906
+ right: { type: 'ref', name: 'b' },
907
+ });
908
+
909
+
910
+ checkTreeExpr([`$1 ~ '.*'`], {
911
+ type: 'binary',
912
+ op: '~',
913
+ left: { type: 'parameter', name: '$1' },
914
+ right: { type: 'string', value: '.*' },
915
+ });
916
+
917
+ checkTreeExpr([`$1 ~* '.*'`], {
918
+ type: 'binary',
919
+ op: '~*',
920
+ left: { type: 'parameter', name: '$1' },
921
+ right: { type: 'string', value: '.*' },
922
+ });
923
+
924
+ checkTreeExpr([`$1 !~ '.*'`], {
925
+ type: 'binary',
926
+ op: '!~',
927
+ left: { type: 'parameter', name: '$1' },
928
+ right: { type: 'string', value: '.*' },
929
+ });
930
+
931
+ checkTreeExpr([`$1 !~* '.*'`], {
932
+ type: 'binary',
933
+ op: '!~*',
934
+ left: { type: 'parameter', name: '$1' },
935
+ right: { type: 'string', value: '.*' },
936
+ });
937
+
938
+ checkTreeExpr(['a != b', '"a"!="b"', 'a<>b'], {
939
+ type: 'binary',
940
+ op: '!=',
941
+ left: { type: 'ref', name: 'a' },
942
+ right: { type: 'ref', name: 'b' },
943
+ });
944
+
945
+ checkTreeExpr(['(a, b, c)', '( a , b, c )'], {
946
+ type: 'list',
947
+ expressions: [
948
+ { type: 'ref', name: 'a' },
949
+ { type: 'ref', name: 'b' },
950
+ { type: 'ref', name: 'c' },
951
+ ]
952
+ });
953
+
954
+ checkTreeExpr(['a in (a, b, c)', 'a in ( a , b, c )'], {
955
+ type: 'binary',
956
+ op: 'IN',
957
+ left: { type: 'ref', name: 'a' },
958
+ right: {
959
+ type: 'list',
960
+ expressions: [
961
+ { type: 'ref', name: 'a' },
962
+ { type: 'ref', name: 'b' },
963
+ { type: 'ref', name: 'c' },
964
+ ]
965
+ },
966
+ });
967
+
968
+ it('does not wrap list expressions in parenthesis', () => {
969
+ const generated = toSql.expr({
970
+ type: 'binary',
971
+ op: 'IN',
972
+ left: { type: 'ref', name: 'a' },
973
+ right: {
974
+ type: 'list',
975
+ expressions: [
976
+ { type: 'ref', name: 'a' },
977
+ { type: 'ref', name: 'b' },
978
+ { type: 'ref', name: 'c' },
979
+ ]
980
+ },
981
+ });
982
+
983
+ expect(generated).to.equal('(a IN (a, b, c))');
984
+ })
985
+
986
+ checkTreeExpr(['a in (b)', 'a in ( b )'], {
987
+ type: 'binary',
988
+ op: 'IN',
989
+ left: { type: 'ref', name: 'a' },
990
+ right: { type: 'ref', name: 'b' },
991
+ });
992
+
993
+ checkTreeExpr(['a^b', '"a"^"b"', 'a ^ b'], {
994
+ type: 'binary',
995
+ op: '^',
996
+ left: { type: 'ref', name: 'a' },
997
+ right: { type: 'ref', name: 'b' },
998
+ });
999
+
1000
+ checkTreeExpr(['a&b'], {
1001
+ type: 'binary',
1002
+ op: '&',
1003
+ left: { type: 'ref', name: 'a' },
1004
+ right: { type: 'ref', name: 'b' },
1005
+ });
1006
+
1007
+ checkTreeExpr(['a>>b'], {
1008
+ type: 'binary',
1009
+ op: '>>',
1010
+ left: { type: 'ref', name: 'a' },
1011
+ right: { type: 'ref', name: 'b' },
1012
+ });
1013
+
1014
+ checkTreeExpr(`a operator(pg_catalog.+) b`, {
1015
+ type: 'binary',
1016
+ op: '+',
1017
+ opSchema: 'pg_catalog',
1018
+ left: { type: 'ref', name: 'a' },
1019
+ right: { type: 'ref', name: 'b' },
1020
+ })
1021
+ });
1022
+
1023
+
1024
+ // ====================================
1025
+ // =============== TERNARIES ==========
1026
+ // ====================================
1027
+ describe('Ternaries', () => {
1028
+
1029
+ // === RANGE: between
1030
+ checkTreeExpr(['"a"between"b"and 42'], {
1031
+ type: 'ternary',
1032
+ op: 'BETWEEN',
1033
+ value: { type: 'ref', name: 'a' },
1034
+ lo: { type: 'ref', name: 'b' },
1035
+ hi: { type: 'integer', value: 42 },
1036
+ });
1037
+
1038
+ checkTreeExprLoc(['a between b and 42'], {
1039
+ _location: { start: 0, end: 18 },
1040
+ type: 'ternary',
1041
+ op: 'BETWEEN',
1042
+ value: {
1043
+ _location: { start: 0, end: 1 },
1044
+ type: 'ref', name: 'a'
1045
+ },
1046
+ lo: {
1047
+ _location: { start: 10, end: 11 },
1048
+ type: 'ref', name: 'b'
1049
+ },
1050
+ hi: {
1051
+ _location: { start: 16, end: 18 },
1052
+ type: 'integer', value: 42
1053
+ },
1054
+ });
1055
+
1056
+
1057
+ checkTreeExpr(['a not between b and 42', 'a not between b and 42', '"a"not between"b"and 42'], {
1058
+ type: 'ternary',
1059
+ op: 'NOT BETWEEN',
1060
+ value: { type: 'ref', name: 'a' },
1061
+ lo: { type: 'ref', name: 'b' },
1062
+ hi: { type: 'integer', value: 42 },
1063
+ });
1064
+
1065
+ // SUBSTRING FROM-FOR
1066
+ checkTreeExprLoc(`substring('val' from 2 for 3)`, {
1067
+ _location: { start: 0, end: 29 },
1068
+ type: 'substring',
1069
+ value: {
1070
+ _location: { start: 10, end: 15 },
1071
+ type: 'string', value: 'val'
1072
+ },
1073
+ from: {
1074
+ _location: { start: 21, end: 22 },
1075
+ type: 'integer', value: 2,
1076
+ },
1077
+ for: {
1078
+ _location: { start: 27, end: 28 },
1079
+ type: 'integer', value: 3
1080
+ },
1081
+ });
1082
+ checkTreeExpr(`substring('val' from 2)`, {
1083
+ type: 'substring',
1084
+ value: { type: 'string', value: 'val' },
1085
+ from: { type: 'integer', value: 2 },
1086
+ });
1087
+
1088
+ checkTreeExpr(`substring('val' for 2)`, {
1089
+ type: 'substring',
1090
+ value: { type: 'string', value: 'val' },
1091
+ for: { type: 'integer', value: 2 },
1092
+ });
1093
+
1094
+ // OVERLAY
1095
+ checkTreeExpr(`overlay('12345678' placing 'ab' from 2 for 4)`, {
1096
+ type: 'overlay',
1097
+ value: { type: 'string', value: '12345678' },
1098
+ placing: { type: 'string', value: 'ab' },
1099
+ from: { type: 'integer', value: 2 },
1100
+ for: { type: 'integer', value: 4 },
1101
+ });
1102
+ checkTreeExprLoc(`overlay('12345678' placing 'ab' from 2)`, {
1103
+ _location: { start: 0, end: 39 },
1104
+ type: 'overlay',
1105
+ value: {
1106
+ _location: { start: 8, end: 18 },
1107
+ type: 'string', value: '12345678'
1108
+ },
1109
+ placing: {
1110
+ _location: { start: 27, end: 31 },
1111
+ type: 'string', value: 'ab'
1112
+ },
1113
+ from: {
1114
+ _location: { start: 37, end: 38 },
1115
+ type: 'integer', value: 2
1116
+ },
1117
+ });
1118
+ checkInvalid(`overlay('12345678' placing 'ab' for 4)`);
1119
+ checkInvalid(`overlay('12345678' from 2 for 4)`);
1120
+ });
1121
+
1122
+
1123
+ // ====================================
1124
+ // =============== MEMBERS ============
1125
+ // ====================================
1126
+
1127
+ describe('Member access', () => {
1128
+
1129
+ checkTreeExprLoc(['a.b[c]'], {
1130
+ _location: { start: 0, end: 6 },
1131
+ type: 'arrayIndex',
1132
+ array: {
1133
+ _location: { start: 0, end: 3 },
1134
+ type: 'ref',
1135
+ table: {
1136
+ _location: { start: 0, end: 1 },
1137
+ name: 'a'
1138
+ },
1139
+ name: 'b',
1140
+ },
1141
+ index: {
1142
+ _location: { start: 4, end: 5 },
1143
+ type: 'ref', name: 'c'
1144
+ }
1145
+ })
1146
+
1147
+ checkTreeExpr(['a . b[c]', 'a."b"["c"]', '(("a"."b")[("c")] )'], {
1148
+ type: 'arrayIndex',
1149
+ array: {
1150
+ type: 'ref',
1151
+ table: { name: 'a' },
1152
+ name: 'b',
1153
+ },
1154
+ index: { type: 'ref', name: 'c' }
1155
+ })
1156
+
1157
+ checkTreeExpr(['a[c+2]', '"a"["c"+2]', '(("a")[("c"+2)] )'], {
1158
+ type: 'arrayIndex',
1159
+ array: {
1160
+ type: 'ref',
1161
+ name: 'a',
1162
+ },
1163
+ index: {
1164
+ type: 'binary',
1165
+ op: '+',
1166
+ left: { type: 'ref', name: 'c' },
1167
+ right: { type: 'integer', value: 2 },
1168
+ }
1169
+ })
1170
+ });
1171
+
1172
+
1173
+ // ====================================
1174
+ // ============== FUNCTIONS ===========
1175
+ // ====================================
1176
+
1177
+ describe('Function calls', () => {
1178
+ checkTreeExpr(['ab (c)', '"ab"( "c" )', 'AB(c)'], {
1179
+ type: 'call',
1180
+ function: { name: 'ab' },
1181
+ args: [{ type: 'ref', name: 'c' }],
1182
+ });
1183
+
1184
+ checkTreeExprLoc('"ab" ( "c" )', {
1185
+ _location: { start: 0, end: 12 },
1186
+ type: 'call',
1187
+ function: {
1188
+ _location: { start: 0, end: 4 },
1189
+ name: 'ab'
1190
+ },
1191
+ args: [{
1192
+ _location: { start: 7, end: 10 },
1193
+ type: 'ref',
1194
+ name: 'c'
1195
+ }],
1196
+ });
1197
+
1198
+ checkTreeExprLoc([`any(c)`], {
1199
+ _location: { start: 0, end: 6 },
1200
+ type: 'call',
1201
+ function: {
1202
+ _location: { start: 0, end: 3 },
1203
+ name: 'any'
1204
+ },
1205
+ args: [{
1206
+ _location: { start: 4, end: 5 },
1207
+ type: 'ref',
1208
+ name: 'c'
1209
+ }],
1210
+ });
1211
+
1212
+ checkTreeExprLoc([`some(c)`], { // alias for any
1213
+ _location: { start: 0, end: 7 },
1214
+ type: 'call',
1215
+ function: {
1216
+ _location: { start: 0, end: 4 },
1217
+ name: 'some'
1218
+ },
1219
+ args: [{
1220
+ _location: { start: 5, end: 6 },
1221
+ type: 'ref',
1222
+ name: 'c'
1223
+ }],
1224
+ });
1225
+
1226
+ checkTreeExprLoc([`all(c)`], {
1227
+ _location: { start: 0, end: 6 },
1228
+ type: 'call',
1229
+ function: {
1230
+ _location: { start: 0, end: 3 },
1231
+ name: 'all'
1232
+ },
1233
+ args: [{
1234
+ _location: { start: 4, end: 5 },
1235
+ type: 'ref',
1236
+ name: 'c'
1237
+ }],
1238
+ });
1239
+
1240
+ checkTreeExprLoc([`now()`], {
1241
+ _location: { start: 0, end: 5 },
1242
+ type: 'call',
1243
+ function: {
1244
+ _location: { start: 0, end: 3 },
1245
+ name: 'now'
1246
+ },
1247
+ args: [],
1248
+ });
1249
+
1250
+ checkTreeExprLoc([`left('foo')`], {
1251
+ _location: { start: 0, end: 11 },
1252
+ type: 'call',
1253
+ function: {
1254
+ _location: { start: 0, end: 4 },
1255
+ name: 'left'
1256
+ },
1257
+ args: [{
1258
+ _location: { start: 5, end: 10 },
1259
+ type: 'string',
1260
+ value: 'foo'
1261
+ }],
1262
+ });
1263
+
1264
+ checkTreeExprLoc([`pg_catalog.col_description(23208,4)`], {
1265
+ _location: { start: 0, end: 35 },
1266
+ type: 'call',
1267
+ function: {
1268
+ _location: { start: 0, end: 26 },
1269
+ name: 'col_description',
1270
+ schema: 'pg_catalog'
1271
+ },
1272
+ args: [{
1273
+ _location: { start: 27, end: 32 },
1274
+ type: 'integer',
1275
+ value: 23208,
1276
+ }, {
1277
+ _location: { start: 33, end: 34 },
1278
+ type: 'integer',
1279
+ value: 4,
1280
+ }]
1281
+ })
1282
+
1283
+ checkTreeExpr([`pg_catalog.set_config('search_path', '', false)`], {
1284
+ type: 'call',
1285
+ function: { name: 'set_config', schema: 'pg_catalog' },
1286
+ args: [{
1287
+ type: 'string',
1288
+ value: 'search_path',
1289
+ }, {
1290
+ type: 'string',
1291
+ value: '',
1292
+ }, {
1293
+ type: 'boolean',
1294
+ value: false,
1295
+ }]
1296
+ })
1297
+
1298
+ checkTreeExpr([`extract (century from timestamp 'value')`], {
1299
+ type: 'extract',
1300
+ field: { name: 'century' },
1301
+ from: {
1302
+ type: 'cast',
1303
+ to: { name: 'timestamp' },
1304
+ operand: { type: 'string', value: 'value' },
1305
+ },
1306
+ });
1307
+
1308
+ checkTreeExprLoc([`EXTRACT (CENTURY FROM 'value'::TIMESTAMP)`], {
1309
+ _location: { start: 0, end: 41 },
1310
+ type: 'extract',
1311
+ field: {
1312
+ _location: { start: 9, end: 16 },
1313
+ name: 'century'
1314
+ },
1315
+ from: {
1316
+ _location: { start: 22, end: 40 },
1317
+ type: 'cast',
1318
+ to: {
1319
+ _location: { start: 31, end: 40 },
1320
+ name: 'timestamp',
1321
+ },
1322
+ operand: {
1323
+ _location: { start: 22, end: 29 },
1324
+ type: 'string',
1325
+ value: 'value',
1326
+ },
1327
+ },
1328
+ });
1329
+ });
1330
+
1331
+
1332
+
1333
+
1334
+ // ====================================
1335
+ // ================ CASE ==============
1336
+ // ====================================
1337
+
1338
+ describe('Case expression', () => {
1339
+ checkTreeExprLoc(['case a when b then 1 end'], {
1340
+ _location: { start: 0, end: 24 },
1341
+ type: 'case',
1342
+ value: {
1343
+ _location: { start: 5, end: 6 },
1344
+ type: 'ref', name: 'a'
1345
+ },
1346
+ whens: [
1347
+ {
1348
+ _location: { start: 7, end: 20 },
1349
+ when: {
1350
+ _location: { start: 12, end: 13 },
1351
+ type: 'ref', name: 'b'
1352
+ },
1353
+ value: {
1354
+ _location: { start: 19, end: 20 },
1355
+ type: 'integer', value: 1
1356
+ }
1357
+ }],
1358
+ });
1359
+
1360
+ checkTreeExpr(['case when b then 1 end'], {
1361
+ type: 'case',
1362
+ whens: [{ when: { type: 'ref', name: 'b' }, value: { type: 'integer', value: 1 } }],
1363
+ });
1364
+
1365
+ checkTreeExprLoc(['case when b then 1 else 2 end'], {
1366
+ _location: { start: 0, end: 29 },
1367
+ type: 'case',
1368
+ whens: [{
1369
+ _location: { start: 5, end: 18 },
1370
+ when: {
1371
+ _location: { start: 10, end: 11 },
1372
+ type: 'ref', name: 'b'
1373
+ },
1374
+ value: {
1375
+ _location: { start: 17, end: 18 },
1376
+ type: 'integer', value: 1
1377
+ }
1378
+ }],
1379
+ else: {
1380
+ _location: { start: 24, end: 25 },
1381
+ type: 'integer', value: 2
1382
+ },
1383
+ });
1384
+
1385
+ // bugfix (was taking E'FALSE' as an escaped string)
1386
+ checkTreeExpr([`case when b then 1 ELSE'FALSE' end`], {
1387
+ type: 'case',
1388
+ whens: [{
1389
+ when: { type: 'ref', name: 'b' },
1390
+ value: { type: 'integer', value: 1 }
1391
+ }],
1392
+ else: {
1393
+ type: 'string',
1394
+ value: 'FALSE',
1395
+ }
1396
+ });
1397
+ });
1398
+
1399
+
1400
+
1401
+
1402
+ // ====================================
1403
+ // ============= SUBSELCT =============
1404
+ // ====================================
1405
+ describe('Selection expressions', () => {
1406
+
1407
+ checkTreeExprLoc(['a = any(select * from tbl)'], {
1408
+ _location: { start: 0, end: 26 },
1409
+ type: 'binary',
1410
+ op: '=',
1411
+ left: {
1412
+ _location: { start: 0, end: 1 },
1413
+ type: 'ref', name: 'a',
1414
+ },
1415
+ right: {
1416
+ _location: { start: 4, end: 26 },
1417
+ type: 'call',
1418
+ function: {
1419
+ _location: { start: 4, end: 7 },
1420
+ name: 'any'
1421
+ },
1422
+ args: [{
1423
+ _location: { start: 8, end: 25 },
1424
+ type: 'select',
1425
+ columns: [{
1426
+ _location: { start: 15, end: 16 },
1427
+ expr: {
1428
+ _location: { start: 15, end: 16 },
1429
+ type: 'ref', name: '*'
1430
+ }
1431
+ }],
1432
+ from: [{
1433
+ _location: { start: 22, end: 25 },
1434
+ type: 'table',
1435
+ name: {
1436
+ _location: { start: 22, end: 25 },
1437
+ name: 'tbl'
1438
+ },
1439
+ }],
1440
+ }]
1441
+ }
1442
+ });
1443
+
1444
+
1445
+ checkTreeExpr(['a in (select * from tb)'], {
1446
+ type: 'binary',
1447
+ op: 'IN',
1448
+ left: { type: 'ref', name: 'a' },
1449
+ right: {
1450
+ type: 'select',
1451
+ columns: [starCol],
1452
+ from: [tbl('tb')],
1453
+ }
1454
+ });
1455
+
1456
+
1457
+ checkTreeExpr(`array( select 1 )`, {
1458
+ type: 'array select',
1459
+ select: {
1460
+ type: 'select',
1461
+ columns: [{ expr: { type: 'integer', value: 1 } }],
1462
+ },
1463
+ })
1464
+ });
1465
+
1466
+
1467
+
1468
+ describe('Aggregation expressions', () => {
1469
+ checkTreeExpr(`count(*)`, {
1470
+ type: 'call',
1471
+ args: [star],
1472
+ function: { name: 'count' },
1473
+ })
1474
+
1475
+ checkTreeExpr(`count(ALL *)`, {
1476
+ type: 'call',
1477
+ args: [star],
1478
+ function: { name: 'count' },
1479
+ distinct: 'all',
1480
+ })
1481
+
1482
+
1483
+ checkTreeExpr(`count(DISTINCT *)`, {
1484
+ type: 'call',
1485
+ args: [star],
1486
+ function: { name: 'count' },
1487
+ distinct: 'distinct',
1488
+ })
1489
+
1490
+
1491
+ checkTreeExpr(`string_agg(distinct a, b)`, {
1492
+ type: 'call',
1493
+ args: [ref('a'), ref('b')],
1494
+ function: { name: 'string_agg' },
1495
+ distinct: 'distinct',
1496
+ })
1497
+
1498
+ checkTreeExpr(`count(distinct (a, b))`, {
1499
+ type: 'call',
1500
+ args: [{
1501
+ type: 'list',
1502
+ expressions: [ref('a'), ref('b')],
1503
+ }],
1504
+ function: { name: 'count' },
1505
+ distinct: 'distinct',
1506
+ });
1507
+
1508
+ checkInvalidExpr(`string_agg(distinct a, distinct b)`);
1509
+
1510
+
1511
+ checkTreeExpr(`count(DISTINCT a, b)`, {
1512
+ type: 'call',
1513
+ args: [ref('a'), ref('b')],
1514
+ function: { name: 'count' },
1515
+ distinct: 'distinct',
1516
+ })
1517
+
1518
+ checkTreeExpr(`count(*) filter (where val)`, {
1519
+ type: 'call',
1520
+ args: [star],
1521
+ function: { name: 'count' },
1522
+ filter: ref('val'),
1523
+ });
1524
+
1525
+ checkTreeExpr(`ROW_NUMBER() OVER (ORDER BY v DESC)`, {
1526
+ type: 'call',
1527
+ args: [],
1528
+ function: { name: 'row_number' },
1529
+ over: {
1530
+ orderBy: [{ by: ref('v'), order: 'DESC' }],
1531
+ }
1532
+ })
1533
+
1534
+ checkTreeExpr(`ROW_NUMBER() OVER (PARTITION BY v)`, {
1535
+ type: 'call',
1536
+ args: [],
1537
+ function: { name: 'row_number' },
1538
+ over: {
1539
+ partitionBy: [ref('v')],
1540
+ }
1541
+ })
1542
+
1543
+ checkTreeExpr(`ROW_NUMBER() OVER ()`, {
1544
+ type: 'call',
1545
+ args: [],
1546
+ function: { name: 'row_number' },
1547
+ over: {
1548
+ }
1549
+ })
1550
+
1551
+ checkTreeExpr(`ROW_NUMBER() OVER (PARTITION BY a ORDER BY b DESC)`, {
1552
+ type: 'call',
1553
+ args: [],
1554
+ function: { name: 'row_number' },
1555
+ over: {
1556
+ partitionBy: [ref('a')],
1557
+ orderBy: [{ by: ref('b'), order: 'DESC' }],
1558
+ }
1559
+ })
1560
+
1561
+ checkTreeExpr(`pg_catalog.count(*) filter (where val)`, {
1562
+ type: 'call',
1563
+ args: [star],
1564
+ function: { name: 'count', schema: 'pg_catalog' },
1565
+ filter: ref('val'),
1566
+ });
1567
+
1568
+ checkInvalidExpr(`count(*) filter where val`);
1569
+
1570
+ checkTreeExpr(`count(a,b order by c) filter (where val)`, {
1571
+ type: 'call',
1572
+ function: { name: 'count' },
1573
+ args: [ref('a'), ref('b')],
1574
+ orderBy: [{ by: ref('c') }],
1575
+ filter: ref('val'),
1576
+ });
1577
+
1578
+ checkTreeExpr(`count(a order by b, c)`, {
1579
+ type: 'call',
1580
+ function: { name: 'count' },
1581
+ args: [ref('a')],
1582
+ orderBy: [{ by: ref('b') }, { by: ref('c') }]
1583
+ });
1584
+
1585
+ checkTreeExpr(`count(c order by o)`, {
1586
+ type: 'call',
1587
+ function: { name: 'count' },
1588
+ args: [ref('c')],
1589
+ orderBy: [{ by: ref('o') }]
1590
+ });
1591
+
1592
+ checkTreeExpr(`PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY a)`, {
1593
+ type: 'call',
1594
+ function: { name: 'percentile_disc' },
1595
+ args: [numeric(0.5)],
1596
+ withinGroup: { by: ref('a') }
1597
+ });
1598
+ })
1599
+
1600
+
1601
+ describe('Value keywords', () => {
1602
+ checkTreeExprLoc(['LOCALTIMESTAMP'], {
1603
+ _location: { start: 0, end: 14 },
1604
+ type: 'keyword',
1605
+ keyword: 'localtimestamp',
1606
+ });
1607
+
1608
+ checkTreeExprLoc(['LOCALTIMESTAMP(5)'], {
1609
+ _location: { start: 0, end: 14 + 3 },
1610
+ type: 'call',
1611
+ function: {
1612
+ _location: { start: 0, end: 14 },
1613
+ name: 'localtimestamp',
1614
+ },
1615
+ args: [{
1616
+ _location: { start: 15, end: 16 },
1617
+ type: 'integer',
1618
+ value: 5,
1619
+ }],
1620
+ });
1621
+
1622
+ checkTreeExprLoc(['current_schema'], {
1623
+ _location: { start: 0, end: 14 },
1624
+ type: 'keyword',
1625
+ keyword: 'current_schema',
1626
+ });
1627
+
1628
+ checkTreeExprLoc(['current_schema()'], {
1629
+ _location: { start: 0, end: 14 + 2 },
1630
+ type: 'call',
1631
+ function: {
1632
+ _location: { start: 0, end: 14 },
1633
+ name: 'current_schema',
1634
+ },
1635
+ args: [],
1636
+ });
1637
+ })
1638
+ });