@ahoo-wang/wow-client 9.2.0-rc.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 (404) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +291 -0
  3. package/README.zh-CN.md +267 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorate.cjs +1 -0
  5. package/dist/_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorate.es.js +9 -0
  6. package/dist/_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorateMetadata.cjs +1 -0
  7. package/dist/_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorateMetadata.es.js +6 -0
  8. package/dist/_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorateParam.cjs +1 -0
  9. package/dist/_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorateParam.es.js +8 -0
  10. package/dist/client/bindMethods.cjs +2 -0
  11. package/dist/client/bindMethods.cjs.map +1 -0
  12. package/dist/client/bindMethods.d.cts +13 -0
  13. package/dist/client/bindMethods.d.ts +13 -0
  14. package/dist/client/bindMethods.es.js +19 -0
  15. package/dist/client/bindMethods.es.js.map +1 -0
  16. package/dist/client/command/commandClient.cjs +2 -0
  17. package/dist/client/command/commandClient.cjs.map +1 -0
  18. package/dist/client/command/commandClient.d.cts +67 -0
  19. package/dist/client/command/commandClient.d.ts +67 -0
  20. package/dist/client/command/commandClient.es.js +38 -0
  21. package/dist/client/command/commandClient.es.js.map +1 -0
  22. package/dist/client/command/commandHeaders.cjs +2 -0
  23. package/dist/client/command/commandHeaders.cjs.map +1 -0
  24. package/dist/client/command/commandHeaders.d.cts +75 -0
  25. package/dist/client/command/commandHeaders.d.ts +75 -0
  26. package/dist/client/command/commandHeaders.es.js +31 -0
  27. package/dist/client/command/commandHeaders.es.js.map +1 -0
  28. package/dist/client/command/commandRequest.cjs +2 -0
  29. package/dist/client/command/commandRequest.cjs.map +1 -0
  30. package/dist/client/command/commandRequest.d.cts +180 -0
  31. package/dist/client/command/commandRequest.d.ts +180 -0
  32. package/dist/client/command/commandRequest.es.js +31 -0
  33. package/dist/client/command/commandRequest.es.js.map +1 -0
  34. package/dist/client/command/commandResult.d.cts +15 -0
  35. package/dist/client/command/commandResult.d.ts +15 -0
  36. package/dist/client/command/index.d.cts +5 -0
  37. package/dist/client/command/index.d.ts +5 -0
  38. package/dist/client/command/types.d.cts +71 -0
  39. package/dist/client/command/types.d.ts +71 -0
  40. package/dist/client/metadata/index.d.cts +2 -0
  41. package/dist/client/metadata/index.d.ts +2 -0
  42. package/dist/client/metadata/wowMetadata.d.cts +48 -0
  43. package/dist/client/metadata/wowMetadata.d.ts +48 -0
  44. package/dist/client/metadata/wowMetadataClient.cjs +2 -0
  45. package/dist/client/metadata/wowMetadataClient.cjs.map +1 -0
  46. package/dist/client/metadata/wowMetadataClient.d.cts +23 -0
  47. package/dist/client/metadata/wowMetadataClient.d.ts +23 -0
  48. package/dist/client/metadata/wowMetadataClient.es.js +25 -0
  49. package/dist/client/metadata/wowMetadataClient.es.js.map +1 -0
  50. package/dist/client/query/descriptor/descriptorEndpoints.cjs +2 -0
  51. package/dist/client/query/descriptor/descriptorEndpoints.cjs.map +1 -0
  52. package/dist/client/query/descriptor/descriptorEndpoints.d.cts +29 -0
  53. package/dist/client/query/descriptor/descriptorEndpoints.d.ts +29 -0
  54. package/dist/client/query/descriptor/descriptorEndpoints.es.js +69 -0
  55. package/dist/client/query/descriptor/descriptorEndpoints.es.js.map +1 -0
  56. package/dist/client/query/descriptor/endpointPaths.cjs +2 -0
  57. package/dist/client/query/descriptor/endpointPaths.cjs.map +1 -0
  58. package/dist/client/query/descriptor/endpointPaths.d.cts +4 -0
  59. package/dist/client/query/descriptor/endpointPaths.d.ts +4 -0
  60. package/dist/client/query/descriptor/endpointPaths.es.js +9 -0
  61. package/dist/client/query/descriptor/endpointPaths.es.js.map +1 -0
  62. package/dist/client/query/descriptor/index.d.cts +2 -0
  63. package/dist/client/query/descriptor/index.d.ts +2 -0
  64. package/dist/client/query/descriptor/queryDescriptorApi.d.cts +58 -0
  65. package/dist/client/query/descriptor/queryDescriptorApi.d.ts +58 -0
  66. package/dist/client/query/descriptor/queryDescriptorClient.cjs +2 -0
  67. package/dist/client/query/descriptor/queryDescriptorClient.cjs.map +1 -0
  68. package/dist/client/query/descriptor/queryDescriptorClient.d.cts +61 -0
  69. package/dist/client/query/descriptor/queryDescriptorClient.d.ts +61 -0
  70. package/dist/client/query/descriptor/queryDescriptorClient.es.js +20 -0
  71. package/dist/client/query/descriptor/queryDescriptorClient.es.js.map +1 -0
  72. package/dist/client/query/event/domainEventStream.cjs +2 -0
  73. package/dist/client/query/event/domainEventStream.cjs.map +1 -0
  74. package/dist/client/query/event/domainEventStream.d.cts +105 -0
  75. package/dist/client/query/event/domainEventStream.d.ts +105 -0
  76. package/dist/client/query/event/domainEventStream.es.js +23 -0
  77. package/dist/client/query/event/domainEventStream.es.js.map +1 -0
  78. package/dist/client/query/event/endpointPaths.cjs +2 -0
  79. package/dist/client/query/event/endpointPaths.cjs.map +1 -0
  80. package/dist/client/query/event/endpointPaths.d.cts +8 -0
  81. package/dist/client/query/event/endpointPaths.d.ts +8 -0
  82. package/dist/client/query/event/endpointPaths.es.js +13 -0
  83. package/dist/client/query/event/endpointPaths.es.js.map +1 -0
  84. package/dist/client/query/event/eventStreamQueryApi.d.cts +29 -0
  85. package/dist/client/query/event/eventStreamQueryApi.d.ts +29 -0
  86. package/dist/client/query/event/eventStreamQueryClient.cjs +2 -0
  87. package/dist/client/query/event/eventStreamQueryClient.cjs.map +1 -0
  88. package/dist/client/query/event/eventStreamQueryClient.d.cts +190 -0
  89. package/dist/client/query/event/eventStreamQueryClient.d.ts +190 -0
  90. package/dist/client/query/event/eventStreamQueryClient.es.js +160 -0
  91. package/dist/client/query/event/eventStreamQueryClient.es.js.map +1 -0
  92. package/dist/client/query/event/index.d.cts +3 -0
  93. package/dist/client/query/event/index.d.ts +3 -0
  94. package/dist/client/query/factory.cjs +2 -0
  95. package/dist/client/query/factory.cjs.map +1 -0
  96. package/dist/client/query/factory.d.cts +165 -0
  97. package/dist/client/query/factory.d.ts +165 -0
  98. package/dist/client/query/factory.es.js +45 -0
  99. package/dist/client/query/factory.es.js.map +1 -0
  100. package/dist/client/query/index.d.cts +6 -0
  101. package/dist/client/query/index.d.ts +6 -0
  102. package/dist/client/query/queryApi.d.cts +68 -0
  103. package/dist/client/query/queryApi.d.ts +68 -0
  104. package/dist/client/query/requests.d.cts +24 -0
  105. package/dist/client/query/requests.d.ts +24 -0
  106. package/dist/client/query/snapshot/endpointPaths.cjs +2 -0
  107. package/dist/client/query/snapshot/endpointPaths.cjs.map +1 -0
  108. package/dist/client/query/snapshot/endpointPaths.d.cts +12 -0
  109. package/dist/client/query/snapshot/endpointPaths.d.ts +12 -0
  110. package/dist/client/query/snapshot/endpointPaths.es.js +17 -0
  111. package/dist/client/query/snapshot/endpointPaths.es.js.map +1 -0
  112. package/dist/client/query/snapshot/index.d.cts +3 -0
  113. package/dist/client/query/snapshot/index.d.ts +3 -0
  114. package/dist/client/query/snapshot/snapshot.cjs +2 -0
  115. package/dist/client/query/snapshot/snapshot.cjs.map +1 -0
  116. package/dist/client/query/snapshot/snapshot.d.cts +51 -0
  117. package/dist/client/query/snapshot/snapshot.d.ts +51 -0
  118. package/dist/client/query/snapshot/snapshot.es.js +20 -0
  119. package/dist/client/query/snapshot/snapshot.es.js.map +1 -0
  120. package/dist/client/query/snapshot/snapshotQueryApi.d.cts +101 -0
  121. package/dist/client/query/snapshot/snapshotQueryApi.d.ts +101 -0
  122. package/dist/client/query/snapshot/snapshotQueryClient.cjs +2 -0
  123. package/dist/client/query/snapshot/snapshotQueryClient.cjs.map +1 -0
  124. package/dist/client/query/snapshot/snapshotQueryClient.d.cts +369 -0
  125. package/dist/client/query/snapshot/snapshotQueryClient.d.ts +369 -0
  126. package/dist/client/query/snapshot/snapshotQueryClient.es.js +239 -0
  127. package/dist/client/query/snapshot/snapshotQueryClient.es.js.map +1 -0
  128. package/dist/client/query/state/endpointPaths.cjs +2 -0
  129. package/dist/client/query/state/endpointPaths.cjs.map +1 -0
  130. package/dist/client/query/state/endpointPaths.d.cts +10 -0
  131. package/dist/client/query/state/endpointPaths.d.ts +10 -0
  132. package/dist/client/query/state/endpointPaths.es.js +14 -0
  133. package/dist/client/query/state/endpointPaths.es.js.map +1 -0
  134. package/dist/client/query/state/index.d.cts +4 -0
  135. package/dist/client/query/state/index.d.ts +4 -0
  136. package/dist/client/query/state/loadOwnerStateAggregateApi.d.cts +36 -0
  137. package/dist/client/query/state/loadOwnerStateAggregateApi.d.ts +36 -0
  138. package/dist/client/query/state/loadOwnerStateAggregateClient.cjs +2 -0
  139. package/dist/client/query/state/loadOwnerStateAggregateClient.cjs.map +1 -0
  140. package/dist/client/query/state/loadOwnerStateAggregateClient.d.cts +58 -0
  141. package/dist/client/query/state/loadOwnerStateAggregateClient.d.ts +58 -0
  142. package/dist/client/query/state/loadOwnerStateAggregateClient.es.js +56 -0
  143. package/dist/client/query/state/loadOwnerStateAggregateClient.es.js.map +1 -0
  144. package/dist/client/query/state/loadStateAggregateApi.d.cts +37 -0
  145. package/dist/client/query/state/loadStateAggregateApi.d.ts +37 -0
  146. package/dist/client/query/state/loadStateAggregateClient.cjs +2 -0
  147. package/dist/client/query/state/loadStateAggregateClient.cjs.map +1 -0
  148. package/dist/client/query/state/loadStateAggregateClient.d.cts +62 -0
  149. package/dist/client/query/state/loadStateAggregateClient.d.ts +62 -0
  150. package/dist/client/query/state/loadStateAggregateClient.es.js +65 -0
  151. package/dist/client/query/state/loadStateAggregateClient.es.js.map +1 -0
  152. package/dist/client/routing.cjs +2 -0
  153. package/dist/client/routing.cjs.map +1 -0
  154. package/dist/client/routing.d.cts +47 -0
  155. package/dist/client/routing.d.ts +47 -0
  156. package/dist/client/routing.es.js +8 -0
  157. package/dist/client/routing.es.js.map +1 -0
  158. package/dist/dsl/aggregation/admit.cjs +2 -0
  159. package/dist/dsl/aggregation/admit.cjs.map +1 -0
  160. package/dist/dsl/aggregation/admit.d.cts +6 -0
  161. package/dist/dsl/aggregation/admit.d.ts +6 -0
  162. package/dist/dsl/aggregation/admit.es.js +142 -0
  163. package/dist/dsl/aggregation/admit.es.js.map +1 -0
  164. package/dist/dsl/aggregation/builders.cjs +2 -0
  165. package/dist/dsl/aggregation/builders.cjs.map +1 -0
  166. package/dist/dsl/aggregation/builders.d.cts +309 -0
  167. package/dist/dsl/aggregation/builders.d.ts +309 -0
  168. package/dist/dsl/aggregation/builders.es.js +188 -0
  169. package/dist/dsl/aggregation/builders.es.js.map +1 -0
  170. package/dist/dsl/aggregation/derived.cjs +2 -0
  171. package/dist/dsl/aggregation/derived.cjs.map +1 -0
  172. package/dist/dsl/aggregation/derived.d.cts +33 -0
  173. package/dist/dsl/aggregation/derived.d.ts +33 -0
  174. package/dist/dsl/aggregation/derived.es.js +31 -0
  175. package/dist/dsl/aggregation/derived.es.js.map +1 -0
  176. package/dist/dsl/aggregation/expressionTrees.cjs +2 -0
  177. package/dist/dsl/aggregation/expressionTrees.cjs.map +1 -0
  178. package/dist/dsl/aggregation/expressionTrees.d.cts +10 -0
  179. package/dist/dsl/aggregation/expressionTrees.d.ts +10 -0
  180. package/dist/dsl/aggregation/expressionTrees.es.js +44 -0
  181. package/dist/dsl/aggregation/expressionTrees.es.js.map +1 -0
  182. package/dist/dsl/aggregation/having.cjs +2 -0
  183. package/dist/dsl/aggregation/having.cjs.map +1 -0
  184. package/dist/dsl/aggregation/having.d.cts +94 -0
  185. package/dist/dsl/aggregation/having.d.ts +94 -0
  186. package/dist/dsl/aggregation/having.es.js +62 -0
  187. package/dist/dsl/aggregation/having.es.js.map +1 -0
  188. package/dist/dsl/aggregation/index.d.cts +4 -0
  189. package/dist/dsl/aggregation/index.d.ts +4 -0
  190. package/dist/dsl/aggregation/sort.cjs +2 -0
  191. package/dist/dsl/aggregation/sort.cjs.map +1 -0
  192. package/dist/dsl/aggregation/sort.d.cts +7 -0
  193. package/dist/dsl/aggregation/sort.d.ts +7 -0
  194. package/dist/dsl/aggregation/sort.es.js +10 -0
  195. package/dist/dsl/aggregation/sort.es.js.map +1 -0
  196. package/dist/dsl/aggregation/types.cjs +2 -0
  197. package/dist/dsl/aggregation/types.cjs.map +1 -0
  198. package/dist/dsl/aggregation/types.d.cts +608 -0
  199. package/dist/dsl/aggregation/types.d.ts +608 -0
  200. package/dist/dsl/aggregation/types.es.js +37 -0
  201. package/dist/dsl/aggregation/types.es.js.map +1 -0
  202. package/dist/dsl/cursorQuery.cjs +2 -0
  203. package/dist/dsl/cursorQuery.cjs.map +1 -0
  204. package/dist/dsl/cursorQuery.d.cts +69 -0
  205. package/dist/dsl/cursorQuery.d.ts +69 -0
  206. package/dist/dsl/cursorQuery.es.js +19 -0
  207. package/dist/dsl/cursorQuery.es.js.map +1 -0
  208. package/dist/dsl/deletionState.cjs +2 -0
  209. package/dist/dsl/deletionState.cjs.map +1 -0
  210. package/dist/dsl/deletionState.d.cts +19 -0
  211. package/dist/dsl/deletionState.d.ts +19 -0
  212. package/dist/dsl/deletionState.es.js +8 -0
  213. package/dist/dsl/deletionState.es.js.map +1 -0
  214. package/dist/dsl/descriptor.cjs +2 -0
  215. package/dist/dsl/descriptor.cjs.map +1 -0
  216. package/dist/dsl/descriptor.d.cts +629 -0
  217. package/dist/dsl/descriptor.d.ts +629 -0
  218. package/dist/dsl/descriptor.es.js +37 -0
  219. package/dist/dsl/descriptor.es.js.map +1 -0
  220. package/dist/dsl/documents.d.cts +8 -0
  221. package/dist/dsl/documents.d.ts +8 -0
  222. package/dist/dsl/field.cjs +2 -0
  223. package/dist/dsl/field.cjs.map +1 -0
  224. package/dist/dsl/field.d.cts +2 -0
  225. package/dist/dsl/field.d.ts +2 -0
  226. package/dist/dsl/field.es.js +10 -0
  227. package/dist/dsl/field.es.js.map +1 -0
  228. package/dist/dsl/filter/builders.cjs +2 -0
  229. package/dist/dsl/filter/builders.cjs.map +1 -0
  230. package/dist/dsl/filter/builders.d.cts +962 -0
  231. package/dist/dsl/filter/builders.d.ts +962 -0
  232. package/dist/dsl/filter/builders.es.js +289 -0
  233. package/dist/dsl/filter/builders.es.js.map +1 -0
  234. package/dist/dsl/filter/datePattern.cjs +2 -0
  235. package/dist/dsl/filter/datePattern.cjs.map +1 -0
  236. package/dist/dsl/filter/datePattern.d.cts +8 -0
  237. package/dist/dsl/filter/datePattern.d.ts +8 -0
  238. package/dist/dsl/filter/datePattern.es.js +100 -0
  239. package/dist/dsl/filter/datePattern.es.js.map +1 -0
  240. package/dist/dsl/filter/index.d.cts +3 -0
  241. package/dist/dsl/filter/index.d.ts +3 -0
  242. package/dist/dsl/filter/operator.cjs +2 -0
  243. package/dist/dsl/filter/operator.cjs.map +1 -0
  244. package/dist/dsl/filter/operator.d.cts +113 -0
  245. package/dist/dsl/filter/operator.d.ts +113 -0
  246. package/dist/dsl/filter/operator.es.js +14 -0
  247. package/dist/dsl/filter/operator.es.js.map +1 -0
  248. package/dist/dsl/filter/scope.cjs +2 -0
  249. package/dist/dsl/filter/scope.cjs.map +1 -0
  250. package/dist/dsl/filter/scope.d.cts +15 -0
  251. package/dist/dsl/filter/scope.d.ts +15 -0
  252. package/dist/dsl/filter/scope.es.js +32 -0
  253. package/dist/dsl/filter/scope.es.js.map +1 -0
  254. package/dist/dsl/filter/types.d.cts +274 -0
  255. package/dist/dsl/filter/types.d.ts +274 -0
  256. package/dist/dsl/filter/validate.cjs +2 -0
  257. package/dist/dsl/filter/validate.cjs.map +1 -0
  258. package/dist/dsl/filter/validate.d.cts +18 -0
  259. package/dist/dsl/filter/validate.d.ts +18 -0
  260. package/dist/dsl/filter/validate.es.js +56 -0
  261. package/dist/dsl/filter/validate.es.js.map +1 -0
  262. package/dist/dsl/pagination.cjs +2 -0
  263. package/dist/dsl/pagination.cjs.map +1 -0
  264. package/dist/dsl/pagination.d.cts +28 -0
  265. package/dist/dsl/pagination.d.ts +28 -0
  266. package/dist/dsl/pagination.es.js +15 -0
  267. package/dist/dsl/pagination.es.js.map +1 -0
  268. package/dist/dsl/projection.cjs +2 -0
  269. package/dist/dsl/projection.cjs.map +1 -0
  270. package/dist/dsl/projection.d.cts +27 -0
  271. package/dist/dsl/projection.d.ts +27 -0
  272. package/dist/dsl/projection.es.js +12 -0
  273. package/dist/dsl/projection.es.js.map +1 -0
  274. package/dist/dsl/queryable.cjs +2 -0
  275. package/dist/dsl/queryable.cjs.map +1 -0
  276. package/dist/dsl/queryable.d.cts +101 -0
  277. package/dist/dsl/queryable.d.ts +101 -0
  278. package/dist/dsl/queryable.es.js +40 -0
  279. package/dist/dsl/queryable.es.js.map +1 -0
  280. package/dist/dsl/sort.cjs +2 -0
  281. package/dist/dsl/sort.cjs.map +1 -0
  282. package/dist/dsl/sort.d.cts +33 -0
  283. package/dist/dsl/sort.d.ts +33 -0
  284. package/dist/dsl/sort.es.js +21 -0
  285. package/dist/dsl/sort.es.js.map +1 -0
  286. package/dist/dsl.cjs +1 -0
  287. package/dist/dsl.d.cts +23 -0
  288. package/dist/dsl.d.ts +23 -0
  289. package/dist/dsl.es.js +14 -0
  290. package/dist/error/errorInfo.cjs +2 -0
  291. package/dist/error/errorInfo.cjs.map +1 -0
  292. package/dist/error/errorInfo.d.cts +139 -0
  293. package/dist/error/errorInfo.d.ts +139 -0
  294. package/dist/error/errorInfo.es.js +32 -0
  295. package/dist/error/errorInfo.es.js.map +1 -0
  296. package/dist/error/headers.cjs +2 -0
  297. package/dist/error/headers.cjs.map +1 -0
  298. package/dist/error/headers.d.cts +38 -0
  299. package/dist/error/headers.d.ts +38 -0
  300. package/dist/error/headers.es.js +10 -0
  301. package/dist/error/headers.es.js.map +1 -0
  302. package/dist/error/index.d.cts +21 -0
  303. package/dist/error/index.d.ts +21 -0
  304. package/dist/error/queryErrorCodes.cjs +2 -0
  305. package/dist/error/queryErrorCodes.cjs.map +1 -0
  306. package/dist/error/queryErrorCodes.d.cts +199 -0
  307. package/dist/error/queryErrorCodes.d.ts +199 -0
  308. package/dist/error/queryErrorCodes.es.js +53 -0
  309. package/dist/error/queryErrorCodes.es.js.map +1 -0
  310. package/dist/error/wowError.cjs +2 -0
  311. package/dist/error/wowError.cjs.map +1 -0
  312. package/dist/error/wowError.d.cts +99 -0
  313. package/dist/error/wowError.d.ts +99 -0
  314. package/dist/error/wowError.es.js +53 -0
  315. package/dist/error/wowError.es.js.map +1 -0
  316. package/dist/index.cjs +1 -0
  317. package/dist/index.d.cts +17 -0
  318. package/dist/index.d.ts +17 -0
  319. package/dist/index.es.js +34 -0
  320. package/dist/legacy/condition.cjs +2 -0
  321. package/dist/legacy/condition.cjs.map +1 -0
  322. package/dist/legacy/condition.d.cts +517 -0
  323. package/dist/legacy/condition.d.ts +517 -0
  324. package/dist/legacy/condition.es.js +338 -0
  325. package/dist/legacy/condition.es.js.map +1 -0
  326. package/dist/legacy/index.d.cts +16 -0
  327. package/dist/legacy/index.d.ts +16 -0
  328. package/dist/legacy/locale/en_US.cjs +2 -0
  329. package/dist/legacy/locale/en_US.cjs.map +1 -0
  330. package/dist/legacy/locale/en_US.d.cts +7 -0
  331. package/dist/legacy/locale/en_US.d.ts +7 -0
  332. package/dist/legacy/locale/en_US.es.js +50 -0
  333. package/dist/legacy/locale/en_US.es.js.map +1 -0
  334. package/dist/legacy/locale/operatorLocale.d.cts +10 -0
  335. package/dist/legacy/locale/operatorLocale.d.ts +10 -0
  336. package/dist/legacy/locale/zh_CN.cjs +2 -0
  337. package/dist/legacy/locale/zh_CN.cjs.map +1 -0
  338. package/dist/legacy/locale/zh_CN.d.cts +7 -0
  339. package/dist/legacy/locale/zh_CN.d.ts +7 -0
  340. package/dist/legacy/locale/zh_CN.es.js +50 -0
  341. package/dist/legacy/locale/zh_CN.es.js.map +1 -0
  342. package/dist/legacy/operator.cjs +2 -0
  343. package/dist/legacy/operator.cjs.map +1 -0
  344. package/dist/legacy/operator.d.cts +218 -0
  345. package/dist/legacy/operator.d.ts +218 -0
  346. package/dist/legacy/operator.es.js +25 -0
  347. package/dist/legacy/operator.es.js.map +1 -0
  348. package/dist/legacy/queryable.cjs +2 -0
  349. package/dist/legacy/queryable.cjs.map +1 -0
  350. package/dist/legacy/queryable.d.cts +61 -0
  351. package/dist/legacy/queryable.d.ts +61 -0
  352. package/dist/legacy/queryable.es.js +34 -0
  353. package/dist/legacy/queryable.es.js.map +1 -0
  354. package/dist/legacy.cjs +1 -0
  355. package/dist/legacy.es.js +6 -0
  356. package/dist/model/abac.cjs +2 -0
  357. package/dist/model/abac.cjs.map +1 -0
  358. package/dist/model/abac.d.cts +33 -0
  359. package/dist/model/abac.d.ts +33 -0
  360. package/dist/model/abac.es.js +6 -0
  361. package/dist/model/abac.es.js.map +1 -0
  362. package/dist/model/bi.cjs +2 -0
  363. package/dist/model/bi.cjs.map +1 -0
  364. package/dist/model/bi.d.cts +12 -0
  365. package/dist/model/bi.d.ts +12 -0
  366. package/dist/model/bi.es.js +8 -0
  367. package/dist/model/bi.es.js.map +1 -0
  368. package/dist/model/command.cjs +2 -0
  369. package/dist/model/command.cjs.map +1 -0
  370. package/dist/model/command.d.cts +137 -0
  371. package/dist/model/command.d.ts +137 -0
  372. package/dist/model/command.es.js +8 -0
  373. package/dist/model/command.es.js.map +1 -0
  374. package/dist/model/common.d.cts +19 -0
  375. package/dist/model/common.d.ts +19 -0
  376. package/dist/model/function.cjs +2 -0
  377. package/dist/model/function.cjs.map +1 -0
  378. package/dist/model/function.d.cts +41 -0
  379. package/dist/model/function.d.ts +41 -0
  380. package/dist/model/function.es.js +8 -0
  381. package/dist/model/function.es.js.map +1 -0
  382. package/dist/model/index.d.cts +22 -0
  383. package/dist/model/index.d.ts +22 -0
  384. package/dist/model/messaging.d.cts +5 -0
  385. package/dist/model/messaging.d.ts +5 -0
  386. package/dist/model/modeling.d.cts +145 -0
  387. package/dist/model/modeling.d.ts +145 -0
  388. package/dist/model/naming.d.cts +27 -0
  389. package/dist/model/naming.d.ts +27 -0
  390. package/dist/transport/endpoints.cjs +2 -0
  391. package/dist/transport/endpoints.cjs.map +1 -0
  392. package/dist/transport/endpoints.d.cts +79 -0
  393. package/dist/transport/endpoints.d.ts +79 -0
  394. package/dist/transport/endpoints.es.js +14 -0
  395. package/dist/transport/endpoints.es.js.map +1 -0
  396. package/dist/transport/eventStreams.cjs +2 -0
  397. package/dist/transport/eventStreams.cjs.map +1 -0
  398. package/dist/transport/eventStreams.d.cts +23 -0
  399. package/dist/transport/eventStreams.d.ts +23 -0
  400. package/dist/transport/eventStreams.es.js +22 -0
  401. package/dist/transport/eventStreams.es.js.map +1 -0
  402. package/dist/transport/index.d.cts +1 -0
  403. package/dist/transport/index.d.ts +1 -0
  404. package/package.json +110 -0
@@ -0,0 +1,188 @@
1
+ import { AggregationDatePart as e, AggregationDateUnit as t, AggregationExpressionOperator as n, AggregationExpressionType as r, AggregationFunction as i, AggregationGroupType as a, AggregationMetricType as o, DateDiffUnit as s } from "./types.es.js";
2
+ import { requireValidExpressionTrees as c } from "./expressionTrees.es.js";
3
+ import { queryField as l } from "../field.es.js";
4
+ import { requireElementScopedFilter as u } from "../filter/scope.es.js";
5
+ import { admitAggregationQuery as d } from "./admit.es.js";
6
+ import { derivedExpressionDsl as f } from "./derived.es.js";
7
+ import { havingDsl as p } from "./having.es.js";
8
+ //#region src/dsl/aggregation/builders.ts
9
+ function m(e) {
10
+ return l(e);
11
+ }
12
+ function h(e) {
13
+ if (m(e), e.includes(".")) throw TypeError("aggregation alias must contain one segment.");
14
+ if (e.startsWith("__wow")) throw TypeError("aggregation alias must not use the reserved __wow prefix.");
15
+ return e;
16
+ }
17
+ function g(e, t, n) {
18
+ return {
19
+ type: r.BINARY,
20
+ operator: e,
21
+ left: t,
22
+ right: n
23
+ };
24
+ }
25
+ function _(e, t, n, { filter: r } = {}) {
26
+ return {
27
+ type: o.NUMERIC,
28
+ ...r === void 0 ? {} : { filter: r },
29
+ function: e,
30
+ expression: t,
31
+ alias: h(n)
32
+ };
33
+ }
34
+ function v(e, t, n, { orderBy: r, filter: i }) {
35
+ return {
36
+ type: e,
37
+ field: m(t),
38
+ alias: h(n),
39
+ ...r === void 0 ? {} : { orderBy: m(r) },
40
+ ...i === void 0 ? {} : { filter: i }
41
+ };
42
+ }
43
+ function y(e, t) {
44
+ if (typeof e == "string") return { field: m(e) };
45
+ if (typeof e != "object" || !e) throw TypeError(`${t} group requires exactly one of field and expression.`);
46
+ return c([e]), { expression: e };
47
+ }
48
+ var b = {
49
+ element(e, t) {
50
+ let n = m(e);
51
+ return t === void 0 ? { path: n } : (u(t, "Aggregation element filter", !1), {
52
+ path: n,
53
+ filter: t
54
+ });
55
+ },
56
+ field(e) {
57
+ return {
58
+ type: r.FIELD,
59
+ field: m(e)
60
+ };
61
+ },
62
+ constant(e) {
63
+ if (!Number.isFinite(e)) throw TypeError("aggregation constant must be finite.");
64
+ return {
65
+ type: r.CONSTANT,
66
+ value: e
67
+ };
68
+ },
69
+ dateDiff(e, t, n) {
70
+ if (!Object.values(s).includes(n)) throw TypeError("date diff unit is invalid.");
71
+ return {
72
+ type: r.DATE_DIFF,
73
+ from: m(e),
74
+ to: m(t),
75
+ unit: n
76
+ };
77
+ },
78
+ add: (e, t) => g(n.ADD, e, t),
79
+ subtract: (e, t) => g(n.SUBTRACT, e, t),
80
+ multiply: (e, t) => g(n.MULTIPLY, e, t),
81
+ divide: (e, t) => g(n.DIVIDE, e, t),
82
+ terms(e, t, { missingKey: n } = {}) {
83
+ if (n !== void 0 && (typeof n != "string" || !n.trim())) throw TypeError("terms missingKey must not be blank.");
84
+ let r = y(e, "TERMS");
85
+ if (n !== void 0 && r.expression) throw TypeError("terms missingKey requires a field input.");
86
+ return {
87
+ type: a.TERMS,
88
+ ...n === void 0 ? {} : { missingKey: n },
89
+ ...r,
90
+ alias: h(t)
91
+ };
92
+ },
93
+ histogram(e, t, { interval: n }) {
94
+ if (!Number.isFinite(n) || n <= 0) throw TypeError("histogram interval must be finite and greater than 0.");
95
+ return {
96
+ type: a.HISTOGRAM,
97
+ ...y(e, "HISTOGRAM"),
98
+ interval: n,
99
+ alias: h(t)
100
+ };
101
+ },
102
+ dateHistogram(e, n, { unit: r, timeZone: i = "UTC", dense: o }) {
103
+ if (o !== void 0 && typeof o != "boolean") throw TypeError("date histogram dense must be boolean.");
104
+ if (!Object.values(t).includes(r)) throw TypeError("date histogram unit is invalid.");
105
+ if (typeof i != "string" || !i.trim()) throw TypeError("date histogram timeZone cannot be blank.");
106
+ return {
107
+ type: a.DATE_HISTOGRAM,
108
+ ...o === void 0 ? {} : { dense: o },
109
+ field: m(e),
110
+ unit: r,
111
+ alias: h(n),
112
+ timeZone: i
113
+ };
114
+ },
115
+ datePart(t, n, { part: r, timeZone: i = "UTC", dense: o }) {
116
+ if (o !== void 0 && typeof o != "boolean") throw TypeError("date part dense must be boolean.");
117
+ if (!Object.values(e).includes(r)) throw TypeError("date part is invalid.");
118
+ if (typeof i != "string" || !i.trim()) throw TypeError("date part timeZone cannot be blank.");
119
+ return {
120
+ type: a.DATE_PART,
121
+ ...o === void 0 ? {} : { dense: o },
122
+ field: m(t),
123
+ part: r,
124
+ alias: h(n),
125
+ timeZone: i
126
+ };
127
+ },
128
+ any(e, t, { filter: n } = {}) {
129
+ return {
130
+ type: o.ANY,
131
+ ...n === void 0 ? {} : { filter: n },
132
+ field: m(e),
133
+ alias: h(t)
134
+ };
135
+ },
136
+ first(e, t, n = {}) {
137
+ return v(o.FIRST, e, t, n);
138
+ },
139
+ last(e, t, n = {}) {
140
+ return v(o.LAST, e, t, n);
141
+ },
142
+ count(e, { filter: t } = {}) {
143
+ return {
144
+ type: o.COUNT,
145
+ ...t === void 0 ? {} : { filter: t },
146
+ alias: h(e)
147
+ };
148
+ },
149
+ sum: (e, t, n) => _(i.SUM, e, t, n),
150
+ avg: (e, t, n) => _(i.AVG, e, t, n),
151
+ min: (e, t, n) => _(i.MIN, e, t, n),
152
+ max: (e, t, n) => _(i.MAX, e, t, n),
153
+ stddev: (e, t, n) => _(i.STDDEV, e, t, n),
154
+ variance: (e, t, n) => _(i.VARIANCE, e, t, n),
155
+ distinctCount(e, t, { filter: n } = {}) {
156
+ return {
157
+ type: o.DISTINCT_COUNT,
158
+ expression: e,
159
+ alias: h(t),
160
+ ...n === void 0 ? {} : { filter: n }
161
+ };
162
+ },
163
+ percentile(e, t, { percentile: n, filter: r }) {
164
+ if (!Number.isFinite(n) || n <= 0 || n >= 100) throw TypeError("percentile must be finite and within (0, 100).");
165
+ return {
166
+ type: o.PERCENTILE,
167
+ expression: e,
168
+ percentile: n,
169
+ alias: h(t),
170
+ ...r === void 0 ? {} : { filter: r }
171
+ };
172
+ },
173
+ derived(e, t) {
174
+ return {
175
+ type: o.DERIVED,
176
+ expression: typeof e == "function" ? e(f) : e,
177
+ alias: h(t)
178
+ };
179
+ },
180
+ having: p,
181
+ query(e) {
182
+ return d(e);
183
+ }
184
+ };
185
+ //#endregion
186
+ export { b as aggregation };
187
+
188
+ //# sourceMappingURL=builders.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builders.es.js","names":["aggregationField","queryField","field","aggregationAlias","alias","binary","AggregationExpressionType","numeric","predicate","AggregationMetricType","fn","edge","orderBy","groupInput","input","type","requireValidExpressionTrees","aggregation","validPath","path","requireElementScopedFilter","value","DateDiffUnit","unit","from","to","AggregationExpressionOperator","left","right","missingKey","source","AggregationGroupType","interval","dense","AggregationDateUnit","timeZone","AggregationDatePart","part","options","AggregationFunction","expression","percentile","derivedExpressionDsl","havingDsl","admitAggregationQuery","query"],"sources":["../../../src/dsl/aggregation/builders.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { queryField } from '../field.js';\nimport type {\n ElementFilterExpression,\n ExpressionFilter,\n} from '../filter/index.js';\nimport { requireElementScopedFilter } from '../filter/scope.js';\nimport { admitAggregationQuery } from './admit.js';\nimport { requireValidExpressionTrees } from './expressionTrees.js';\nimport { derivedExpressionDsl, type DerivedExpressionDsl } from './derived.js';\nimport { havingDsl } from './having.js';\nimport {\n DateDiffUnit,\n AggregationDatePart,\n AggregationDateUnit,\n AggregationExpressionOperator,\n AggregationExpressionType,\n AggregationFunction,\n AggregationGroupType,\n AggregationMetricType,\n type AggregationElement,\n type AggregationExpression,\n type AggregationGroupInput,\n type DateDiffAggregationExpression,\n type AggregationMetricOptions,\n type AggregationQuery,\n type AnyAggregationMetric,\n type EdgeAggregationMetric,\n type EdgeAggregationOptions,\n type BinaryAggregationExpression,\n type ConstantAggregationExpression,\n type CountAggregationMetric,\n type DateHistogramAggregationGroup,\n type DateHistogramAggregationOptions,\n type DatePartAggregationGroup,\n type DatePartAggregationOptions,\n type DerivedAggregationMetric,\n type DerivedExpression,\n type DistinctCountAggregationMetric,\n type FieldAggregationExpression,\n type HistogramAggregationGroup,\n type HistogramAggregationOptions,\n type NumericAggregationMetric,\n type PercentileAggregationMetric,\n type PercentileAggregationOptions,\n type TermsAggregationGroup,\n type TermsAggregationOptions,\n} from './types.js';\n\nfunction aggregationField<FIELDS extends string>(field: FIELDS): FIELDS {\n return queryField(field);\n}\n\nfunction aggregationAlias(alias: string): string {\n aggregationField(alias);\n if (alias.includes('.')) {\n throw new TypeError('aggregation alias must contain one segment.');\n }\n if (alias.startsWith('__wow')) {\n throw new TypeError(\n 'aggregation alias must not use the reserved __wow prefix.',\n );\n }\n return alias;\n}\n\nfunction binary<FIELDS extends string>(\n operator: AggregationExpressionOperator,\n left: AggregationExpression<FIELDS>,\n right: AggregationExpression<FIELDS>,\n): BinaryAggregationExpression<FIELDS> {\n return { type: AggregationExpressionType.BINARY, operator, left, right };\n}\n\nfunction numeric<FIELDS extends string>(\n fn: AggregationFunction,\n expression: AggregationExpression<FIELDS>,\n alias: string,\n { filter: predicate }: AggregationMetricOptions<FIELDS> = {},\n): NumericAggregationMetric<FIELDS> {\n return {\n type: AggregationMetricType.NUMERIC,\n ...(predicate === undefined ? {} : { filter: predicate }),\n function: fn,\n expression,\n alias: aggregationAlias(alias),\n };\n}\n\n/** Builds a `FIRST` or `LAST` metric; {@link aggregation.first}. */\nfunction edge<FIELDS extends string>(\n type: AggregationMetricType.FIRST | AggregationMetricType.LAST,\n field: FIELDS,\n alias: string,\n { orderBy, filter: predicate }: EdgeAggregationOptions<FIELDS>,\n): EdgeAggregationMetric<FIELDS> {\n return {\n type,\n field: aggregationField(field),\n alias: aggregationAlias(alias),\n ...(orderBy === undefined ? {} : { orderBy: aggregationField(orderBy) }),\n ...(predicate === undefined ? {} : { filter: predicate }),\n };\n}\n\n/**\n * The input of a TERMS or HISTOGRAM group: a field path, or an expression in\n * its place, never both, as Wow's `requireGroupInput` has it.\n */\nfunction groupInput<FIELDS extends string>(\n input: FIELDS | AggregationExpression<FIELDS>,\n type: string,\n): AggregationGroupInput<FIELDS> {\n if (typeof input === 'string') return { field: aggregationField(input) };\n if (input === null || typeof input !== 'object') {\n throw new TypeError(\n `${type} group requires exactly one of field and expression.`,\n );\n }\n requireValidExpressionTrees([input]);\n return { expression: input };\n}\n\n/**\n * Builders of an `AggregationQuery`: its elements, groups, metrics and the\n * arithmetic expressions metrics compute over. Each builder checks its own\n * part and throws a `TypeError` naming what is wrong; {@link aggregation.query}\n * checks the parts against each other.\n *\n * Every group and metric takes its target first, its alias second, and any\n * further options as a trailing object.\n */\nexport const aggregation = {\n /**\n * Aggregates over the elements of an array field instead of the root\n * documents. `{ path, filter? }`.\n *\n * @param path - The array field, a query field path.\n * @param predicate - Keeps only the elements that match; may not contain\n * root filters (id, owner, tenant, space, deletion) or any search, even\n * one that names its fields. An `EXPRESSION` filter is allowed.\n * @throws TypeError when `path` is not a valid field path or `predicate`\n * contains a root filter.\n * @example\n * ```typescript\n * aggregation.element('items', filter.gt('quantity', 0));\n * ```\n */\n element(\n path: string,\n predicate?: ElementFilterExpression | ExpressionFilter,\n ): AggregationElement {\n const validPath = aggregationField(path);\n if (predicate === undefined) return { path: validPath };\n requireElementScopedFilter(predicate, 'Aggregation element filter', false);\n return { path: validPath, filter: predicate };\n },\n /**\n * The value of a field, as an operand. `{ type: 'FIELD', field }`.\n *\n * @throws TypeError when `field` is not a valid field path.\n * @example\n * ```typescript\n * aggregation.sum(aggregation.field('state.amount'), 'amount');\n * ```\n */\n field<FIELDS extends string>(\n field: FIELDS,\n ): FieldAggregationExpression<FIELDS> {\n return {\n type: AggregationExpressionType.FIELD,\n field: aggregationField(field),\n };\n },\n /**\n * A number, as an operand. `{ type: 'CONSTANT', value }`.\n *\n * @throws TypeError when `value` is not finite.\n * @example\n * ```typescript\n * aggregation.multiply(aggregation.field('price'), aggregation.constant(100));\n * ```\n */\n constant(value: number): ConstantAggregationExpression {\n if (!Number.isFinite(value)) {\n throw new TypeError('aggregation constant must be finite.');\n }\n return { type: AggregationExpressionType.CONSTANT, value };\n },\n /**\n * The time from the instant in `from` to the instant in `to`, `to − from`,\n * in `unit`, as a signed decimal: negative when `to` is earlier, and no\n * value when either instant is absent. A `DAY` is exactly 24 hours.\n * `{ type: 'DATE_DIFF', from, to, unit }`. Both fields must be\n * single-valued time fields, those whose `aggregate.groups` list\n * `DATE_HISTOGRAM` in the descriptor, and `unit` one of its\n * `analysis.dateDiffUnits`. Wow 9.2 and later.\n *\n * @throws TypeError when `from` or `to` is not a valid field path, or\n * `unit` is not a {@link DateDiffUnit}.\n * @example\n * ```typescript\n * // Hours from payment to shipping, averaged per warehouse.\n * aggregation.avg(\n * aggregation.dateDiff('state.paidAt', 'state.shippedAt', DateDiffUnit.HOUR),\n * 'hoursToShip',\n * );\n * ```\n */\n dateDiff<FIELDS extends string>(\n from: FIELDS,\n to: FIELDS,\n unit: DateDiffUnit,\n ): DateDiffAggregationExpression<FIELDS> {\n if (!Object.values(DateDiffUnit).includes(unit)) {\n throw new TypeError('date diff unit is invalid.');\n }\n return {\n type: AggregationExpressionType.DATE_DIFF,\n from: aggregationField(from),\n to: aggregationField(to),\n unit,\n };\n },\n /** `left + right`. `{ type: 'BINARY', operator: 'ADD', left, right }`. */\n add: <FIELDS extends string>(\n left: AggregationExpression<FIELDS>,\n right: AggregationExpression<FIELDS>,\n ) => binary(AggregationExpressionOperator.ADD, left, right),\n /** `left - right`. `{ type: 'BINARY', operator: 'SUBTRACT', left, right }`. */\n subtract: <FIELDS extends string>(\n left: AggregationExpression<FIELDS>,\n right: AggregationExpression<FIELDS>,\n ) => binary(AggregationExpressionOperator.SUBTRACT, left, right),\n /** `left * right`. `{ type: 'BINARY', operator: 'MULTIPLY', left, right }`. */\n multiply: <FIELDS extends string>(\n left: AggregationExpression<FIELDS>,\n right: AggregationExpression<FIELDS>,\n ) => binary(AggregationExpressionOperator.MULTIPLY, left, right),\n /** `left / right`. `{ type: 'BINARY', operator: 'DIVIDE', left, right }`. */\n divide: <FIELDS extends string>(\n left: AggregationExpression<FIELDS>,\n right: AggregationExpression<FIELDS>,\n ) => binary(AggregationExpressionOperator.DIVIDE, left, right),\n /**\n * Groups by each distinct value of a field, or of a computed expression.\n * `{ type: 'TERMS', field, alias, missingKey? }`, or\n * `{ type: 'TERMS', expression, alias }`.\n *\n * @param input - The field to group by, or an expression in its place\n * (Wow 9.2 and later, an expensive computation).\n * @param alias - The name of the group column in the result rows.\n * @param options.missingKey - The key of the rows without a value; only\n * with a field.\n * @throws TypeError when `input` or `alias` is invalid, `missingKey` is\n * blank, or `missingKey` is given with an expression.\n * @example\n * ```typescript\n * aggregation.terms('state.status', 'status', { missingKey: 'NONE' });\n * aggregation.terms(\n * aggregation.dateDiff('state.paidAt', 'state.shippedAt', DateDiffUnit.DAY),\n * 'daysToShip',\n * );\n * ```\n */\n terms<FIELDS extends string>(\n input: FIELDS | AggregationExpression<FIELDS>,\n alias: string,\n { missingKey }: TermsAggregationOptions = {},\n ): TermsAggregationGroup<FIELDS> {\n if (\n missingKey !== undefined &&\n (typeof missingKey !== 'string' || !missingKey.trim())\n ) {\n throw new TypeError('terms missingKey must not be blank.');\n }\n const source = groupInput(input, 'TERMS');\n if (missingKey !== undefined && source.expression) {\n throw new TypeError('terms missingKey requires a field input.');\n }\n return {\n type: AggregationGroupType.TERMS,\n ...(missingKey === undefined ? {} : { missingKey }),\n ...source,\n alias: aggregationAlias(alias),\n };\n },\n /**\n * Groups a number field, or a computed expression, into buckets of equal\n * width. `{ type: 'HISTOGRAM', field | expression, interval, alias }`.\n *\n * @param input - The number field to bucket, or an expression in its\n * place (Wow 9.2 and later, an expensive computation).\n * @param alias - The name of the bucket column in the result rows.\n * @param options.interval - The bucket width.\n * @throws TypeError when `interval` is not finite and greater than 0, or\n * `field` or `alias` is invalid.\n * @example\n * ```typescript\n * aggregation.histogram('state.amount', 'amountBand', { interval: 100 });\n * ```\n */\n histogram<FIELDS extends string>(\n input: FIELDS | AggregationExpression<FIELDS>,\n alias: string,\n { interval }: HistogramAggregationOptions,\n ): HistogramAggregationGroup<FIELDS> {\n if (!Number.isFinite(interval) || interval <= 0) {\n throw new TypeError(\n 'histogram interval must be finite and greater than 0.',\n );\n }\n return {\n type: AggregationGroupType.HISTOGRAM,\n ...groupInput(input, 'HISTOGRAM'),\n interval,\n alias: aggregationAlias(alias),\n };\n },\n /**\n * Groups a time field into calendar buckets.\n * `{ type: 'DATE_HISTOGRAM', field, unit, alias, timeZone, dense? }`.\n *\n * @param field - The time field (epoch milliseconds) to bucket.\n * @param alias - The name of the bucket column in the result rows.\n * @param options.unit - The calendar unit of a bucket.\n * @param options.timeZone - The zone buckets are cut in. Defaults to `UTC`.\n * @param options.dense - Whether the empty buckets of the range are filled\n * in.\n * @throws TypeError when `unit` is not an `AggregationDateUnit`,\n * `timeZone` is blank, `dense` is not a boolean, or `field` or `alias` is\n * invalid.\n * @example\n * ```typescript\n * aggregation.dateHistogram('createTime', 'day', {\n * unit: AggregationDateUnit.DAY,\n * timeZone: 'Asia/Shanghai',\n * });\n * ```\n */\n dateHistogram<FIELDS extends string>(\n field: FIELDS,\n alias: string,\n { unit, timeZone = 'UTC', dense }: DateHistogramAggregationOptions,\n ): DateHistogramAggregationGroup<FIELDS> {\n if (dense !== undefined && typeof dense !== 'boolean') {\n throw new TypeError('date histogram dense must be boolean.');\n }\n if (!Object.values(AggregationDateUnit).includes(unit)) {\n throw new TypeError('date histogram unit is invalid.');\n }\n if (typeof timeZone !== 'string' || !timeZone.trim()) {\n throw new TypeError('date histogram timeZone cannot be blank.');\n }\n return {\n type: AggregationGroupType.DATE_HISTOGRAM,\n ...(dense === undefined ? {} : { dense }),\n field: aggregationField(field),\n unit,\n alias: aggregationAlias(alias),\n timeZone,\n };\n },\n /**\n * Groups a time field by one calendar part of each instant, such as the\n * weekday or the hour, so records from different days share a bucket.\n * `{ type: 'DATE_PART', field, part, alias, timeZone, dense? }`.\n *\n * The group's keys in the result rows are integers: `DAY_OF_WEEK` is the\n * ISO weekday, 1 (Monday) to 7 (Sunday); `DAY_OF_MONTH` 1 to 31;\n * `HOUR_OF_DAY` 0 to 23 on the wall clock of `timeZone`; `MONTH_OF_YEAR`\n * 1 to 12. With `dense`, every key of that domain comes back, those\n * without records carrying each metric's empty value; `dense` needs the\n * group to be the query's only one. Wow 9.2 and later.\n *\n * @param field - The time field (epoch milliseconds) to read the part of.\n * @param alias - The name of the part column in the result rows.\n * @param options.part - The calendar part to group by.\n * @param options.timeZone - The zone the part is read in. Defaults to\n * `UTC`.\n * @param options.dense - Whether every key of the part's domain is\n * returned.\n * @throws TypeError when `part` is not an `AggregationDatePart`,\n * `timeZone` is blank, `dense` is not a boolean, or `field` or `alias` is\n * invalid.\n * @example\n * ```typescript\n * aggregation.datePart('createTime', 'weekday', {\n * part: AggregationDatePart.DAY_OF_WEEK,\n * timeZone: 'Asia/Shanghai',\n * });\n * ```\n */\n datePart<FIELDS extends string>(\n field: FIELDS,\n alias: string,\n { part, timeZone = 'UTC', dense }: DatePartAggregationOptions,\n ): DatePartAggregationGroup<FIELDS> {\n if (dense !== undefined && typeof dense !== 'boolean') {\n throw new TypeError('date part dense must be boolean.');\n }\n if (!Object.values(AggregationDatePart).includes(part)) {\n throw new TypeError('date part is invalid.');\n }\n if (typeof timeZone !== 'string' || !timeZone.trim()) {\n throw new TypeError('date part timeZone cannot be blank.');\n }\n return {\n type: AggregationGroupType.DATE_PART,\n ...(dense === undefined ? {} : { dense }),\n field: aggregationField(field),\n part,\n alias: aggregationAlias(alias),\n timeZone,\n };\n },\n /**\n * Any one value of a field within each group, of any type.\n * `{ type: 'ANY', field, alias, filter? }`.\n *\n * @throws TypeError when `field` or `alias` is invalid.\n * @example\n * ```typescript\n * aggregation.any('state.customerName', 'customer');\n * ```\n */\n any<FIELDS extends string>(\n field: FIELDS,\n alias: string,\n { filter: predicate }: AggregationMetricOptions<FIELDS> = {},\n ): AnyAggregationMetric<FIELDS> {\n return {\n type: AggregationMetricType.ANY,\n ...(predicate === undefined ? {} : { filter: predicate }),\n field: aggregationField(field),\n alias: aggregationAlias(alias),\n };\n },\n /**\n * The value of `field` on each group's earliest record by `orderBy`.\n * `{ type: 'FIRST', field, alias, orderBy?, filter? }`.\n *\n * The value comes back in the field's own type, or `null` when no record\n * of the group has both a value and an `orderBy` position. Without\n * `orderBy` the server orders by the model's event time, which the\n * descriptor names as `analysis.firstLastOrderBy`. Neither a derived\n * metric nor `having` may refer to it. Wow 9.2 and later.\n *\n * @throws TypeError when `field`, `orderBy` or `alias` is invalid.\n * @example\n * ```typescript\n * aggregation.first('state.price', 'open', { orderBy: 'createTime' });\n * ```\n */\n first<FIELDS extends string>(\n field: FIELDS,\n alias: string,\n options: EdgeAggregationOptions<FIELDS> = {},\n ): EdgeAggregationMetric<FIELDS> {\n return edge(AggregationMetricType.FIRST, field, alias, options);\n },\n /**\n * The value of `field` on each group's latest record by `orderBy`.\n * `{ type: 'LAST', field, alias, orderBy?, filter? }`. As\n * {@link aggregation.first}, from the other end.\n *\n * @throws TypeError when `field`, `orderBy` or `alias` is invalid.\n * @example\n * ```typescript\n * aggregation.last('state.price', 'close', { orderBy: 'createTime' });\n * ```\n */\n last<FIELDS extends string>(\n field: FIELDS,\n alias: string,\n options: EdgeAggregationOptions<FIELDS> = {},\n ): EdgeAggregationMetric<FIELDS> {\n return edge(AggregationMetricType.LAST, field, alias, options);\n },\n /**\n * The number of rows in each group. `{ type: 'COUNT', alias, filter? }`.\n *\n * @param alias - The name of the metric column in the result rows.\n * @param options.filter - Counts only the rows that match.\n * @throws TypeError when `alias` is invalid.\n * @example\n * ```typescript\n * aggregation.count('paid', { filter: filter.eq('state.status', 'PAID') });\n * ```\n */\n count<FIELDS extends string = string>(\n alias: string,\n { filter: predicate }: AggregationMetricOptions<FIELDS> = {},\n ): CountAggregationMetric<FIELDS> {\n return {\n type: AggregationMetricType.COUNT,\n ...(predicate === undefined ? {} : { filter: predicate }),\n alias: aggregationAlias(alias),\n };\n },\n /**\n * The sum of an expression. `{ type: 'NUMERIC', function: 'SUM',\n * expression, alias, filter? }`.\n *\n * @example\n * ```typescript\n * aggregation.sum(aggregation.field('state.amount'), 'revenue');\n * ```\n */\n sum: <FIELDS extends string>(\n expression: AggregationExpression<FIELDS>,\n alias: string,\n options?: AggregationMetricOptions<FIELDS>,\n ) => numeric(AggregationFunction.SUM, expression, alias, options),\n /** The average of an expression; see {@link aggregation.sum}. */\n avg: <FIELDS extends string>(\n expression: AggregationExpression<FIELDS>,\n alias: string,\n options?: AggregationMetricOptions<FIELDS>,\n ) => numeric(AggregationFunction.AVG, expression, alias, options),\n /** The least value of an expression; see {@link aggregation.sum}. */\n min: <FIELDS extends string>(\n expression: AggregationExpression<FIELDS>,\n alias: string,\n options?: AggregationMetricOptions<FIELDS>,\n ) => numeric(AggregationFunction.MIN, expression, alias, options),\n /** The greatest value of an expression; see {@link aggregation.sum}. */\n max: <FIELDS extends string>(\n expression: AggregationExpression<FIELDS>,\n alias: string,\n options?: AggregationMetricOptions<FIELDS>,\n ) => numeric(AggregationFunction.MAX, expression, alias, options),\n /** The standard deviation of an expression; see {@link aggregation.sum}. */\n stddev: <FIELDS extends string>(\n expression: AggregationExpression<FIELDS>,\n alias: string,\n options?: AggregationMetricOptions<FIELDS>,\n ) => numeric(AggregationFunction.STDDEV, expression, alias, options),\n /** The variance of an expression; see {@link aggregation.sum}. */\n variance: <FIELDS extends string>(\n expression: AggregationExpression<FIELDS>,\n alias: string,\n options?: AggregationMetricOptions<FIELDS>,\n ) => numeric(AggregationFunction.VARIANCE, expression, alias, options),\n /**\n * The number of distinct values of an expression.\n * `{ type: 'DISTINCT_COUNT', expression, alias, filter? }`.\n *\n * @example\n * ```typescript\n * aggregation.distinctCount(aggregation.field('ownerId'), 'customers');\n * ```\n */\n distinctCount<FIELDS extends string>(\n expression: AggregationExpression<FIELDS>,\n alias: string,\n { filter: predicate }: AggregationMetricOptions<FIELDS> = {},\n ): DistinctCountAggregationMetric<FIELDS> {\n return {\n type: AggregationMetricType.DISTINCT_COUNT,\n expression,\n alias: aggregationAlias(alias),\n ...(predicate === undefined ? {} : { filter: predicate }),\n };\n },\n /**\n * A percentile of an expression.\n * `{ type: 'PERCENTILE', expression, percentile, alias, filter? }`.\n *\n * @param options.percentile - Which percentile, within (0, 100).\n * @throws TypeError when `percentile` is not finite and within (0, 100), or\n * `alias` is invalid.\n * @example\n * ```typescript\n * aggregation.percentile(aggregation.field('latency'), 'p95', { percentile: 95 });\n * ```\n */\n percentile<FIELDS extends string>(\n expression: AggregationExpression<FIELDS>,\n alias: string,\n { percentile, filter: predicate }: PercentileAggregationOptions<FIELDS>,\n ): PercentileAggregationMetric<FIELDS> {\n if (!Number.isFinite(percentile) || percentile <= 0 || percentile >= 100) {\n throw new TypeError('percentile must be finite and within (0, 100).');\n }\n return {\n type: AggregationMetricType.PERCENTILE,\n expression,\n percentile,\n alias: aggregationAlias(alias),\n ...(predicate === undefined ? {} : { filter: predicate }),\n };\n },\n /**\n * A metric computed from other metrics of the same row, by their aliases.\n * `{ type: 'DERIVED', expression, alias }`. `aggregation.query()` checks\n * that it refers only to metrics declared before it.\n *\n * @param expression - The arithmetic: a callback that builds it from the\n * {@link DerivedExpressionDsl} it is handed (`ref`, `constant`, `add`,\n * `subtract`, `multiply`, `divide`), or an already-built tree.\n * @throws TypeError when `alias` is invalid, or a `constant` is not finite.\n * @example\n * ```typescript\n * aggregation.derived(\n * d => d.divide(d.ref('revenue'), d.ref('orders')),\n * 'averageOrder',\n * );\n * ```\n */\n derived(\n expression:\n DerivedExpression | ((d: DerivedExpressionDsl) => DerivedExpression),\n alias: string,\n ): DerivedAggregationMetric {\n return {\n type: AggregationMetricType.DERIVED,\n expression:\n typeof expression === 'function'\n ? expression(derivedExpressionDsl)\n : expression,\n alias: aggregationAlias(alias),\n };\n },\n /**\n * The builders of the query's `having`: conditions on the metric columns of\n * the grouped rows (`eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `between`, `isIn`,\n * `isNull`, `isNotNull`) and their `and`/`or`. See `HavingDsl`.\n *\n * @example\n * ```typescript\n * aggregation.query({\n * groupBy: [aggregation.terms('state.status', 'status')],\n * metrics: [aggregation.count('orders')],\n * having: aggregation.having.gt('orders', 10),\n * });\n * ```\n */\n having: havingDsl,\n\n /**\n * Admits a whole aggregation query against the rules Wow enforces on arrival.\n *\n * The factories above each check their own part; only the assembled query\n * can answer the questions that span parts — whether two aliases collide,\n * whether a sort names one of them, whether `having` has rows to filter.\n * Wow checks all of it in `AggregationQuery`'s constructor and answers a\n * query that fails with a 400, so the same rules run here against the object\n * about to be sent.\n */\n query<\n ROOT_FIELDS extends string = string,\n AGGREGATION_FIELDS extends string = ROOT_FIELDS,\n >(\n query: AggregationQuery<ROOT_FIELDS, AGGREGATION_FIELDS>,\n ): AggregationQuery<ROOT_FIELDS, AGGREGATION_FIELDS> {\n return admitAggregationQuery(query);\n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AEtE,OAAO;GACL,MAAMhC,EAAsB;GAC5B;GACA;GACA,OAAON,EAAiBC,CAAK;GAC7B,GAAII,MAAc,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQA,EAAU;EACzD;CACF;CAkBA,QACE,GAEA,GAC0B;EAC1B,OAAO;GACL,MAAMC,EAAsB;GAC5B,YACE,OAAO+B,KAAe,aAClBA,EAAWE,CAAoB,IAC/BF;GACN,OAAOrC,EAAiBC,CAAK;EAC/B;CACF;CAeA,QAAQuC;CAYR,MAIE,GACmD;EACnD,OAAOC,EAAsBC,CAAK;CACpC;AACF"}
@@ -0,0 +1,2 @@
1
+ const e=require("./types.cjs");function t(t,n,r){return{type:e.DerivedExpressionType.BINARY,operator:t,left:n,right:r}}var n={ref:t=>({type:e.DerivedExpressionType.METRIC_REF,metric:t}),constant(t){if(!Number.isFinite(t))throw TypeError(`derived constant must be finite.`);return{type:e.DerivedExpressionType.CONSTANT,value:t}},add:(n,r)=>t(e.AggregationExpressionOperator.ADD,n,r),subtract:(n,r)=>t(e.AggregationExpressionOperator.SUBTRACT,n,r),multiply:(n,r)=>t(e.AggregationExpressionOperator.MULTIPLY,n,r),divide:(n,r)=>t(e.AggregationExpressionOperator.DIVIDE,n,r)};exports.derivedExpressionDsl=n;
2
+ //# sourceMappingURL=derived.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derived.cjs","names":["DerivedExpressionType","AggregationExpressionOperator","require_types","binary","derivedExpressionDsl","value","left","right"],"sources":["../../../src/dsl/aggregation/derived.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AggregationExpressionOperator,\n DerivedExpressionType,\n type DerivedExpression,\n} from './types.js';\n\n/**\n * The builders of a derived metric's arithmetic, handed to the callback of\n * `aggregation.derived(d => …, alias)`: references to other metrics of the\n * same row, numbers, and the four operators. Mirrors Kotlin's\n * `DerivedExpressionDsl` (`wow-query`, `AggregationQueryDsl.kt`).\n *\n * `constant` checks its number here; `aggregation.query()` checks what\n * spans the query: that each `ref` names a non-ANY metric declared before the\n * derived one, and the depth and size of the tree.\n *\n * These are not `aggregation.add` and friends: those build the expressions a\n * metric aggregates over, which name fields, not metrics.\n */\nexport interface DerivedExpressionDsl {\n /** The value of another metric of the row. `{ type: 'METRIC_REF', metric }`. */\n ref(metric: string): DerivedExpression;\n /**\n * A number. `{ type: 'CONSTANT', value }`.\n *\n * @throws TypeError when `value` is not finite.\n */\n constant(value: number): DerivedExpression;\n /** `left + right`. `{ type: 'BINARY', operator: 'ADD', left, right }`. */\n add(left: DerivedExpression, right: DerivedExpression): DerivedExpression;\n /** `left - right`. `{ type: 'BINARY', operator: 'SUBTRACT', left, right }`. */\n subtract(\n left: DerivedExpression,\n right: DerivedExpression,\n ): DerivedExpression;\n /** `left * right`. `{ type: 'BINARY', operator: 'MULTIPLY', left, right }`. */\n multiply(\n left: DerivedExpression,\n right: DerivedExpression,\n ): DerivedExpression;\n /** `left / right`. `{ type: 'BINARY', operator: 'DIVIDE', left, right }`. */\n divide(left: DerivedExpression, right: DerivedExpression): DerivedExpression;\n}\n\nfunction binary(\n operator: AggregationExpressionOperator,\n left: DerivedExpression,\n right: DerivedExpression,\n): DerivedExpression {\n return { type: DerivedExpressionType.BINARY, operator, left, right };\n}\n\nexport const derivedExpressionDsl: DerivedExpressionDsl = {\n ref: metric => ({ type: DerivedExpressionType.METRIC_REF, metric }),\n constant(value) {\n if (!Number.isFinite(value)) {\n throw new TypeError('derived constant must be finite.');\n }\n return { type: DerivedExpressionType.CONSTANT, value };\n },\n add: (left, right) => binary(AggregationExpressionOperator.ADD, left, right),\n subtract: (left, right) =>\n binary(AggregationExpressionOperator.SUBTRACT, left, right),\n multiply: (left, right) =>\n binary(AggregationExpressionOperator.MULTIPLY, left, right),\n divide: (left, right) =>\n binary(AggregationExpressionOperator.DIVIDE, left, right),\n};\n"],"mappings":"+BAyDA,SAASG,EACP,EACA,EACA,EACmB,CACnB,MAAO,CAAE,KAAMH,EAAAA,sBAAsB,OAAQ,WAAU,OAAM,OAAM,CACrE,CAEA,IAAaI,EAA6C,CACxD,IAAK,IAAW,CAAE,KAAMJ,EAAAA,sBAAsB,WAAY,QAAO,GACjE,SAAS,EAAO,CACd,GAAI,CAAC,OAAO,SAASK,CAAK,EACxB,MAAU,UAAU,kCAAkC,EAExD,MAAO,CAAE,KAAML,EAAAA,sBAAsB,SAAU,OAAM,CACvD,EACA,KAAM,EAAM,IAAUG,EAAOF,EAAAA,8BAA8B,IAAKK,EAAMC,CAAK,EAC3E,UAAW,EAAM,IACfJ,EAAOF,EAAAA,8BAA8B,SAAUK,EAAMC,CAAK,EAC5D,UAAW,EAAM,IACfJ,EAAOF,EAAAA,8BAA8B,SAAUK,EAAMC,CAAK,EAC5D,QAAS,EAAM,IACbJ,EAAOF,EAAAA,8BAA8B,OAAQK,EAAMC,CAAK,CAC5D"}
@@ -0,0 +1,33 @@
1
+ import { DerivedExpression } from './types.cjs';
2
+ /**
3
+ * The builders of a derived metric's arithmetic, handed to the callback of
4
+ * `aggregation.derived(d => …, alias)`: references to other metrics of the
5
+ * same row, numbers, and the four operators. Mirrors Kotlin's
6
+ * `DerivedExpressionDsl` (`wow-query`, `AggregationQueryDsl.kt`).
7
+ *
8
+ * `constant` checks its number here; `aggregation.query()` checks what
9
+ * spans the query: that each `ref` names a non-ANY metric declared before the
10
+ * derived one, and the depth and size of the tree.
11
+ *
12
+ * These are not `aggregation.add` and friends: those build the expressions a
13
+ * metric aggregates over, which name fields, not metrics.
14
+ */
15
+ export interface DerivedExpressionDsl {
16
+ /** The value of another metric of the row. `{ type: 'METRIC_REF', metric }`. */
17
+ ref(metric: string): DerivedExpression;
18
+ /**
19
+ * A number. `{ type: 'CONSTANT', value }`.
20
+ *
21
+ * @throws TypeError when `value` is not finite.
22
+ */
23
+ constant(value: number): DerivedExpression;
24
+ /** `left + right`. `{ type: 'BINARY', operator: 'ADD', left, right }`. */
25
+ add(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
26
+ /** `left - right`. `{ type: 'BINARY', operator: 'SUBTRACT', left, right }`. */
27
+ subtract(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
28
+ /** `left * right`. `{ type: 'BINARY', operator: 'MULTIPLY', left, right }`. */
29
+ multiply(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
30
+ /** `left / right`. `{ type: 'BINARY', operator: 'DIVIDE', left, right }`. */
31
+ divide(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
32
+ }
33
+ export declare const derivedExpressionDsl: DerivedExpressionDsl;
@@ -0,0 +1,33 @@
1
+ import { DerivedExpression } from './types.js';
2
+ /**
3
+ * The builders of a derived metric's arithmetic, handed to the callback of
4
+ * `aggregation.derived(d => …, alias)`: references to other metrics of the
5
+ * same row, numbers, and the four operators. Mirrors Kotlin's
6
+ * `DerivedExpressionDsl` (`wow-query`, `AggregationQueryDsl.kt`).
7
+ *
8
+ * `constant` checks its number here; `aggregation.query()` checks what
9
+ * spans the query: that each `ref` names a non-ANY metric declared before the
10
+ * derived one, and the depth and size of the tree.
11
+ *
12
+ * These are not `aggregation.add` and friends: those build the expressions a
13
+ * metric aggregates over, which name fields, not metrics.
14
+ */
15
+ export interface DerivedExpressionDsl {
16
+ /** The value of another metric of the row. `{ type: 'METRIC_REF', metric }`. */
17
+ ref(metric: string): DerivedExpression;
18
+ /**
19
+ * A number. `{ type: 'CONSTANT', value }`.
20
+ *
21
+ * @throws TypeError when `value` is not finite.
22
+ */
23
+ constant(value: number): DerivedExpression;
24
+ /** `left + right`. `{ type: 'BINARY', operator: 'ADD', left, right }`. */
25
+ add(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
26
+ /** `left - right`. `{ type: 'BINARY', operator: 'SUBTRACT', left, right }`. */
27
+ subtract(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
28
+ /** `left * right`. `{ type: 'BINARY', operator: 'MULTIPLY', left, right }`. */
29
+ multiply(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
30
+ /** `left / right`. `{ type: 'BINARY', operator: 'DIVIDE', left, right }`. */
31
+ divide(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
32
+ }
33
+ export declare const derivedExpressionDsl: DerivedExpressionDsl;
@@ -0,0 +1,31 @@
1
+ import { AggregationExpressionOperator as e, DerivedExpressionType as t } from "./types.es.js";
2
+ //#region src/dsl/aggregation/derived.ts
3
+ function n(e, n, r) {
4
+ return {
5
+ type: t.BINARY,
6
+ operator: e,
7
+ left: n,
8
+ right: r
9
+ };
10
+ }
11
+ var r = {
12
+ ref: (e) => ({
13
+ type: t.METRIC_REF,
14
+ metric: e
15
+ }),
16
+ constant(e) {
17
+ if (!Number.isFinite(e)) throw TypeError("derived constant must be finite.");
18
+ return {
19
+ type: t.CONSTANT,
20
+ value: e
21
+ };
22
+ },
23
+ add: (t, r) => n(e.ADD, t, r),
24
+ subtract: (t, r) => n(e.SUBTRACT, t, r),
25
+ multiply: (t, r) => n(e.MULTIPLY, t, r),
26
+ divide: (t, r) => n(e.DIVIDE, t, r)
27
+ };
28
+ //#endregion
29
+ export { r as derivedExpressionDsl };
30
+
31
+ //# sourceMappingURL=derived.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derived.es.js","names":["binary","DerivedExpressionType","derivedExpressionDsl","value","AggregationExpressionOperator","left","right"],"sources":["../../../src/dsl/aggregation/derived.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AggregationExpressionOperator,\n DerivedExpressionType,\n type DerivedExpression,\n} from './types.js';\n\n/**\n * The builders of a derived metric's arithmetic, handed to the callback of\n * `aggregation.derived(d => …, alias)`: references to other metrics of the\n * same row, numbers, and the four operators. Mirrors Kotlin's\n * `DerivedExpressionDsl` (`wow-query`, `AggregationQueryDsl.kt`).\n *\n * `constant` checks its number here; `aggregation.query()` checks what\n * spans the query: that each `ref` names a non-ANY metric declared before the\n * derived one, and the depth and size of the tree.\n *\n * These are not `aggregation.add` and friends: those build the expressions a\n * metric aggregates over, which name fields, not metrics.\n */\nexport interface DerivedExpressionDsl {\n /** The value of another metric of the row. `{ type: 'METRIC_REF', metric }`. */\n ref(metric: string): DerivedExpression;\n /**\n * A number. `{ type: 'CONSTANT', value }`.\n *\n * @throws TypeError when `value` is not finite.\n */\n constant(value: number): DerivedExpression;\n /** `left + right`. `{ type: 'BINARY', operator: 'ADD', left, right }`. */\n add(left: DerivedExpression, right: DerivedExpression): DerivedExpression;\n /** `left - right`. `{ type: 'BINARY', operator: 'SUBTRACT', left, right }`. */\n subtract(\n left: DerivedExpression,\n right: DerivedExpression,\n ): DerivedExpression;\n /** `left * right`. `{ type: 'BINARY', operator: 'MULTIPLY', left, right }`. */\n multiply(\n left: DerivedExpression,\n right: DerivedExpression,\n ): DerivedExpression;\n /** `left / right`. `{ type: 'BINARY', operator: 'DIVIDE', left, right }`. */\n divide(left: DerivedExpression, right: DerivedExpression): DerivedExpression;\n}\n\nfunction binary(\n operator: AggregationExpressionOperator,\n left: DerivedExpression,\n right: DerivedExpression,\n): DerivedExpression {\n return { type: DerivedExpressionType.BINARY, operator, left, right };\n}\n\nexport const derivedExpressionDsl: DerivedExpressionDsl = {\n ref: metric => ({ type: DerivedExpressionType.METRIC_REF, metric }),\n constant(value) {\n if (!Number.isFinite(value)) {\n throw new TypeError('derived constant must be finite.');\n }\n return { type: DerivedExpressionType.CONSTANT, value };\n },\n add: (left, right) => binary(AggregationExpressionOperator.ADD, left, right),\n subtract: (left, right) =>\n binary(AggregationExpressionOperator.SUBTRACT, left, right),\n multiply: (left, right) =>\n binary(AggregationExpressionOperator.MULTIPLY, left, right),\n divide: (left, right) =>\n binary(AggregationExpressionOperator.DIVIDE, left, right),\n};\n"],"mappings":";;AAyDA,SAASA,EACP,GACA,GACA,GACmB;CACnB,OAAO;EAAE,MAAMC,EAAsB;EAAQ;EAAU;EAAM;CAAM;AACrE;AAEA,IAAaC,IAA6C;CACxD,MAAK,OAAW;EAAE,MAAMD,EAAsB;EAAY;CAAO;CACjE,SAAS,GAAO;EACd,IAAI,CAAC,OAAO,SAASE,CAAK,GACxB,MAAU,UAAU,kCAAkC;EAExD,OAAO;GAAE,MAAMF,EAAsB;GAAU;EAAM;CACvD;CACA,MAAM,GAAM,MAAUD,EAAOI,EAA8B,KAAKC,GAAMC,CAAK;CAC3E,WAAW,GAAM,MACfN,EAAOI,EAA8B,UAAUC,GAAMC,CAAK;CAC5D,WAAW,GAAM,MACfN,EAAOI,EAA8B,UAAUC,GAAMC,CAAK;CAC5D,SAAS,GAAM,MACbN,EAAOI,EAA8B,QAAQC,GAAMC,CAAK;AAC5D"}
@@ -0,0 +1,2 @@
1
+ const e=require("./types.cjs");function t(t){let n=t.map(e=>({expression:e,depth:1})),r=0;for(;n.length>0;){let{expression:t,depth:i}=n.pop();if(i>e.AGGREGATION_LIMITS.MAX_EXPRESSION_DEPTH)throw TypeError(`aggregation expression depth must be at most ${e.AGGREGATION_LIMITS.MAX_EXPRESSION_DEPTH}.`);if(r++,r>e.AGGREGATION_LIMITS.MAX_EXPRESSION_NODES)throw TypeError(`aggregation expressions must contain at most ${e.AGGREGATION_LIMITS.MAX_EXPRESSION_NODES} nodes.`);switch(t.type){case e.AggregationExpressionType.FIELD:break;case e.AggregationExpressionType.CONSTANT:if(!Number.isFinite(t.value))throw TypeError(`aggregation constant must be finite.`);break;case e.AggregationExpressionType.DATE_DIFF:if(!Object.values(e.DateDiffUnit).includes(t.unit))throw TypeError(`date diff unit is invalid.`);break;case e.AggregationExpressionType.BINARY:n.push({expression:t.left,depth:i+1}),n.push({expression:t.right,depth:i+1});break;default:throw TypeError(`Unsupported aggregation expression: ${String(t.type)}.`)}}}function n(t){switch(t.type){case e.AggregationExpressionType.FIELD:return[t.field];case e.AggregationExpressionType.DATE_DIFF:return[t.from,t.to];case e.AggregationExpressionType.BINARY:return[...n(t.left),...n(t.right)];default:return[]}}exports.expressionFields=n,exports.requireValidExpressionTrees=t;
2
+ //# sourceMappingURL=expressionTrees.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expressionTrees.cjs","names":["AGGREGATION_LIMITS","AggregationExpressionType","DateDiffUnit","require_types","requireValidExpressionTrees","pending","expressions","nodes","depth","expression","expressionFields"],"sources":["../../../src/dsl/aggregation/expressionTrees.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AGGREGATION_LIMITS,\n AggregationExpressionType,\n DateDiffUnit,\n type AggregationExpression,\n} from './types.js';\n\n// Internal: the one walk over aggregation expression trees that metrics,\n// expression groups and `EXPRESSION` filters share. index.ts does not\n// re-export this file.\n\n/**\n * Bounds the depth of each tree and the nodes of all of them together, as\n * Wow's `requireValidExpressionTrees` does: depth is per expression and the\n * node count is one budget over the list, so a query cannot slip past by\n * spreading a large tree across many metrics.\n */\nexport function requireValidExpressionTrees(\n expressions: readonly AggregationExpression[],\n): void {\n const pending = expressions.map(expression => ({ expression, depth: 1 }));\n let nodes = 0;\n while (pending.length > 0) {\n const { expression, depth } = pending.pop()!;\n if (depth > AGGREGATION_LIMITS.MAX_EXPRESSION_DEPTH) {\n throw new TypeError(\n `aggregation expression depth must be at most ${AGGREGATION_LIMITS.MAX_EXPRESSION_DEPTH}.`,\n );\n }\n nodes++;\n if (nodes > AGGREGATION_LIMITS.MAX_EXPRESSION_NODES) {\n throw new TypeError(\n `aggregation expressions must contain at most ${AGGREGATION_LIMITS.MAX_EXPRESSION_NODES} nodes.`,\n );\n }\n switch (expression.type) {\n case AggregationExpressionType.FIELD:\n break;\n // `aggregation.constant` refuses these, but a query rebuilt from a\n // stored config never passed through it, and JSON has no NaN: the value\n // would serialise to null and be refused on arrival instead.\n case AggregationExpressionType.CONSTANT:\n if (!Number.isFinite(expression.value)) {\n throw new TypeError('aggregation constant must be finite.');\n }\n break;\n case AggregationExpressionType.DATE_DIFF:\n if (!Object.values(DateDiffUnit).includes(expression.unit)) {\n throw new TypeError('date diff unit is invalid.');\n }\n break;\n case AggregationExpressionType.BINARY:\n pending.push({ expression: expression.left, depth: depth + 1 });\n pending.push({ expression: expression.right, depth: depth + 1 });\n break;\n default:\n throw new TypeError(\n `Unsupported aggregation expression: ${String((expression as { type: unknown }).type)}.`,\n );\n }\n }\n}\n\n/** The fields an expression reads, in tree order. */\nexport function expressionFields(expression: AggregationExpression): string[] {\n switch (expression.type) {\n case AggregationExpressionType.FIELD:\n return [expression.field];\n case AggregationExpressionType.DATE_DIFF:\n return [expression.from, expression.to];\n case AggregationExpressionType.BINARY:\n return [\n ...expressionFields(expression.left),\n ...expressionFields(expression.right),\n ];\n default:\n return [];\n }\n}\n"],"mappings":"+BA8BA,SAAgBI,EACd,EACM,CACN,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AAO,CAAC,CACZ,CACF"}
@@ -0,0 +1,10 @@
1
+ import { AggregationExpression } from './types.cjs';
2
+ /**
3
+ * Bounds the depth of each tree and the nodes of all of them together, as
4
+ * Wow's `requireValidExpressionTrees` does: depth is per expression and the
5
+ * node count is one budget over the list, so a query cannot slip past by
6
+ * spreading a large tree across many metrics.
7
+ */
8
+ export declare function requireValidExpressionTrees(expressions: readonly AggregationExpression[]): void;
9
+ /** The fields an expression reads, in tree order. */
10
+ export declare function expressionFields(expression: AggregationExpression): string[];
@@ -0,0 +1,10 @@
1
+ import { AggregationExpression } from './types.js';
2
+ /**
3
+ * Bounds the depth of each tree and the nodes of all of them together, as
4
+ * Wow's `requireValidExpressionTrees` does: depth is per expression and the
5
+ * node count is one budget over the list, so a query cannot slip past by
6
+ * spreading a large tree across many metrics.
7
+ */
8
+ export declare function requireValidExpressionTrees(expressions: readonly AggregationExpression[]): void;
9
+ /** The fields an expression reads, in tree order. */
10
+ export declare function expressionFields(expression: AggregationExpression): string[];
@@ -0,0 +1,44 @@
1
+ import { AGGREGATION_LIMITS as e, AggregationExpressionType as t, DateDiffUnit as n } from "./types.es.js";
2
+ //#region src/dsl/aggregation/expressionTrees.ts
3
+ function r(r) {
4
+ let i = r.map((e) => ({
5
+ expression: e,
6
+ depth: 1
7
+ })), a = 0;
8
+ for (; i.length > 0;) {
9
+ let { expression: r, depth: o } = i.pop();
10
+ if (o > e.MAX_EXPRESSION_DEPTH) throw TypeError(`aggregation expression depth must be at most ${e.MAX_EXPRESSION_DEPTH}.`);
11
+ if (a++, a > e.MAX_EXPRESSION_NODES) throw TypeError(`aggregation expressions must contain at most ${e.MAX_EXPRESSION_NODES} nodes.`);
12
+ switch (r.type) {
13
+ case t.FIELD: break;
14
+ case t.CONSTANT:
15
+ if (!Number.isFinite(r.value)) throw TypeError("aggregation constant must be finite.");
16
+ break;
17
+ case t.DATE_DIFF:
18
+ if (!Object.values(n).includes(r.unit)) throw TypeError("date diff unit is invalid.");
19
+ break;
20
+ case t.BINARY:
21
+ i.push({
22
+ expression: r.left,
23
+ depth: o + 1
24
+ }), i.push({
25
+ expression: r.right,
26
+ depth: o + 1
27
+ });
28
+ break;
29
+ default: throw TypeError(`Unsupported aggregation expression: ${String(r.type)}.`);
30
+ }
31
+ }
32
+ }
33
+ function i(e) {
34
+ switch (e.type) {
35
+ case t.FIELD: return [e.field];
36
+ case t.DATE_DIFF: return [e.from, e.to];
37
+ case t.BINARY: return [...i(e.left), ...i(e.right)];
38
+ default: return [];
39
+ }
40
+ }
41
+ //#endregion
42
+ export { i as expressionFields, r as requireValidExpressionTrees };
43
+
44
+ //# sourceMappingURL=expressionTrees.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expressionTrees.es.js","names":["requireValidExpressionTrees","pending","expressions","nodes","depth","AGGREGATION_LIMITS","expression","AggregationExpressionType","DateDiffUnit","expressionFields"],"sources":["../../../src/dsl/aggregation/expressionTrees.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AGGREGATION_LIMITS,\n AggregationExpressionType,\n DateDiffUnit,\n type AggregationExpression,\n} from './types.js';\n\n// Internal: the one walk over aggregation expression trees that metrics,\n// expression groups and `EXPRESSION` filters share. index.ts does not\n// re-export this file.\n\n/**\n * Bounds the depth of each tree and the nodes of all of them together, as\n * Wow's `requireValidExpressionTrees` does: depth is per expression and the\n * node count is one budget over the list, so a query cannot slip past by\n * spreading a large tree across many metrics.\n */\nexport function requireValidExpressionTrees(\n expressions: readonly AggregationExpression[],\n): void {\n const pending = expressions.map(expression => ({ expression, depth: 1 }));\n let nodes = 0;\n while (pending.length > 0) {\n const { expression, depth } = pending.pop()!;\n if (depth > AGGREGATION_LIMITS.MAX_EXPRESSION_DEPTH) {\n throw new TypeError(\n `aggregation expression depth must be at most ${AGGREGATION_LIMITS.MAX_EXPRESSION_DEPTH}.`,\n );\n }\n nodes++;\n if (nodes > AGGREGATION_LIMITS.MAX_EXPRESSION_NODES) {\n throw new TypeError(\n `aggregation expressions must contain at most ${AGGREGATION_LIMITS.MAX_EXPRESSION_NODES} nodes.`,\n );\n }\n switch (expression.type) {\n case AggregationExpressionType.FIELD:\n break;\n // `aggregation.constant` refuses these, but a query rebuilt from a\n // stored config never passed through it, and JSON has no NaN: the value\n // would serialise to null and be refused on arrival instead.\n case AggregationExpressionType.CONSTANT:\n if (!Number.isFinite(expression.value)) {\n throw new TypeError('aggregation constant must be finite.');\n }\n break;\n case AggregationExpressionType.DATE_DIFF:\n if (!Object.values(DateDiffUnit).includes(expression.unit)) {\n throw new TypeError('date diff unit is invalid.');\n }\n break;\n case AggregationExpressionType.BINARY:\n pending.push({ expression: expression.left, depth: depth + 1 });\n pending.push({ expression: expression.right, depth: depth + 1 });\n break;\n default:\n throw new TypeError(\n `Unsupported aggregation expression: ${String((expression as { type: unknown }).type)}.`,\n );\n }\n }\n}\n\n/** The fields an expression reads, in tree order. */\nexport function expressionFields(expression: AggregationExpression): string[] {\n switch (expression.type) {\n case AggregationExpressionType.FIELD:\n return [expression.field];\n case AggregationExpressionType.DATE_DIFF:\n return [expression.from, expression.to];\n case AggregationExpressionType.BINARY:\n return [\n ...expressionFields(expression.left),\n ...expressionFields(expression.right),\n ];\n default:\n return [];\n }\n}\n"],"mappings":";;AA8BA,SAAgBA,EACd,GACM;CACN,IAAMC,IAAUC,EAAY,KAAI,OAAe;EAAE;EAAY,OAAO;CAAE,EAAE,GACpEC,IAAQ;CACZ,OAAOF,EAAQ,SAAS,IAAG;EACzB,IAAM,EAAE,eAAY,aAAUA,EAAQ,IAAI;EAC1C,IAAIG,IAAQC,EAAmB,sBAC7B,MAAU,UACR,gDAAgDA,EAAmB,qBAAqB,EAC1F;EAGF,IADA,KACIF,IAAQE,EAAmB,sBAC7B,MAAU,UACR,gDAAgDA,EAAmB,qBAAqB,QAC1F;EAEF,QAAQC,EAAW,MAAnB;GACE,KAAKC,EAA0B,OAC7B;GAIF,KAAKA,EAA0B;IAC7B,IAAI,CAAC,OAAO,SAASD,EAAW,KAAK,GACnC,MAAU,UAAU,sCAAsC;IAE5D;GACF,KAAKC,EAA0B;IAC7B,IAAI,CAAC,OAAO,OAAOC,CAAY,CAAC,CAAC,SAASF,EAAW,IAAI,GACvD,MAAU,UAAU,4BAA4B;IAElD;GACF,KAAKC,EAA0B;IAE7B,AADAN,EAAQ,KAAK;KAAE,YAAYK,EAAW;KAAM,OAAOF,IAAQ;IAAE,CAAC,GAC9DH,EAAQ,KAAK;KAAE,YAAYK,EAAW;KAAO,OAAOF,IAAQ;IAAE,CAAC;IAC/D;GACF,SACE,MAAU,UACR,uCAAuC,OAAQE,EAAiC,IAAI,EAAE,EACxF;EACJ;CACF;AACF;AAGA,SAAgBG,EAAiB,GAA6C;CAC5E,QAAQH,EAAW,MAAnB;EACE,KAAKC,EAA0B,OAC7B,OAAO,CAACD,EAAW,KAAK;EAC1B,KAAKC,EAA0B,WAC7B,OAAO,CAACD,EAAW,MAAMA,EAAW,EAAE;EACxC,KAAKC,EAA0B,QAC7B,OAAO,CACL,GAAGE,EAAiBH,EAAW,IAAI,GACnC,GAAGG,EAAiBH,EAAW,KAAK,CACtC;EACF,SACE,OAAO,CAAC;CACZ;AACF"}
@@ -0,0 +1,2 @@
1
+ const e=require("./types.cjs");function t(t,n,r){if(!Number.isFinite(r))throw TypeError(`having condition [${n}] value must be finite.`);return{type:e.HavingExpressionType.CONDITION,metric:n,operator:t,value:r}}function n(e,t){let[n,...r]=t;if(n===void 0)throw TypeError(`having ${e} operands must not be empty.`);return{type:e,operands:[n,...r]}}var r={eq:(n,r)=>t(e.ComparisonOperator.EQ,n,r),ne:(n,r)=>t(e.ComparisonOperator.NE,n,r),gt:(n,r)=>t(e.ComparisonOperator.GT,n,r),gte:(n,r)=>t(e.ComparisonOperator.GTE,n,r),lt:(n,r)=>t(e.ComparisonOperator.LT,n,r),lte:(n,r)=>t(e.ComparisonOperator.LTE,n,r),between(t,n,r){if(!Number.isFinite(n)||!Number.isFinite(r))throw TypeError(`having between [${t}] bounds must be finite.`);if(n>r)throw TypeError(`having between [${t}] lower bound must not exceed upper bound.`);return{type:e.HavingExpressionType.BETWEEN,metric:t,lower:n,upper:r}},isIn(t,n){let[r,...i]=n;if(r===void 0)throw TypeError(`having in [${t}] values must not be empty.`);if(!n.every(Number.isFinite))throw TypeError(`having in [${t}] values must be finite.`);return{type:e.HavingExpressionType.IN,metric:t,values:[r,...i]}},isNull:t=>({type:e.HavingExpressionType.IS_NULL,metric:t}),isNotNull:t=>({type:e.HavingExpressionType.IS_NULL,metric:t,negated:!0}),and:t=>n(e.HavingExpressionType.AND,t),or:t=>n(e.HavingExpressionType.OR,t)};exports.havingDsl=r;
2
+ //# sourceMappingURL=having.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"having.cjs","names":["HavingExpressionType","ComparisonOperator","require_types","condition","value","metric","logical","first","rest","operands","type","havingDsl","lower","upper","values"],"sources":["../../../src/dsl/aggregation/having.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ComparisonOperator,\n HavingExpressionType,\n type HavingExpression,\n} from './types.js';\n\n/**\n * The builders of a `having` expression, `aggregation.having.*`: conditions on\n * the metric columns of the grouped rows, and their `and`/`or`. Mirrors\n * Kotlin's `HavingDsl` (`wow-query`, `AggregationQueryDsl.kt`).\n *\n * Each builder checks its own numbers and throws a `TypeError` with the\n * message Wow answers; `aggregation.query()` checks what spans the query:\n * that `metric` names a declared, non-ANY metric, and that the query groups.\n */\nexport interface HavingDsl {\n /**\n * `metric = value`. `{ type: 'CONDITION', metric, operator: 'EQ', value }`.\n *\n * @param metric - The alias of a metric of the same query.\n * @throws TypeError when `value` is not finite.\n * @example\n * ```typescript\n * aggregation.having.eq('orders', 1);\n * ```\n */\n eq(metric: string, value: number): HavingExpression;\n /** `metric ≠ value`. `{ type: 'CONDITION', operator: 'NE', … }`. */\n ne(metric: string, value: number): HavingExpression;\n /**\n * `metric > value`. `{ type: 'CONDITION', operator: 'GT', … }`.\n *\n * @example\n * ```typescript\n * aggregation.having.gt('revenue', 100);\n * ```\n */\n gt(metric: string, value: number): HavingExpression;\n /** `metric ≥ value`. `{ type: 'CONDITION', operator: 'GTE', … }`. */\n gte(metric: string, value: number): HavingExpression;\n /** `metric < value`. `{ type: 'CONDITION', operator: 'LT', … }`. */\n lt(metric: string, value: number): HavingExpression;\n /** `metric ≤ value`. `{ type: 'CONDITION', operator: 'LTE', … }`. */\n lte(metric: string, value: number): HavingExpression;\n /**\n * `lower ≤ metric ≤ upper`. `{ type: 'BETWEEN', metric, lower, upper }`.\n *\n * @throws TypeError when a bound is not finite, or `lower` exceeds `upper`.\n * @example\n * ```typescript\n * aggregation.having.between('revenue', 10, 1000);\n * ```\n */\n between(metric: string, lower: number, upper: number): HavingExpression;\n /**\n * `metric` is one of `values`. `{ type: 'IN', metric, values }` with a\n * copy of `values`.\n *\n * @throws TypeError when `values` is empty or holds a non-finite number.\n * @example\n * ```typescript\n * aggregation.having.isIn('orders', [2, 3]);\n * ```\n */\n isIn(metric: string, values: readonly number[]): HavingExpression;\n /**\n * `metric` has no value in the row. `{ type: 'IS_NULL', metric }`.\n *\n * @example\n * ```typescript\n * aggregation.having.isNull('averageOrder');\n * ```\n */\n isNull(metric: string): HavingExpression;\n /** `metric` has a value. `{ type: 'IS_NULL', metric, negated: true }`. */\n isNotNull(metric: string): HavingExpression;\n /**\n * All of `operands` hold. `{ type: 'AND', operands }` with a copy of\n * `operands`.\n *\n * @throws TypeError when `operands` is empty.\n * @example\n * ```typescript\n * aggregation.having.and([\n * aggregation.having.gt('orders', 1),\n * aggregation.having.isNotNull('revenue'),\n * ]);\n * ```\n */\n and(operands: readonly HavingExpression[]): HavingExpression;\n /**\n * At least one of `operands` holds. `{ type: 'OR', operands }` with a copy\n * of `operands`.\n *\n * @throws TypeError when `operands` is empty.\n */\n or(operands: readonly HavingExpression[]): HavingExpression;\n}\n\nfunction condition(\n operator: ComparisonOperator,\n metric: string,\n value: number,\n): HavingExpression {\n if (!Number.isFinite(value)) {\n throw new TypeError(`having condition [${metric}] value must be finite.`);\n }\n return { type: HavingExpressionType.CONDITION, metric, operator, value };\n}\n\nfunction logical(\n type: HavingExpressionType.AND | HavingExpressionType.OR,\n operands: readonly HavingExpression[],\n): HavingExpression {\n const [first, ...rest] = operands;\n if (first === undefined) {\n throw new TypeError(`having ${type} operands must not be empty.`);\n }\n return { type, operands: [first, ...rest] };\n}\n\nexport const havingDsl: HavingDsl = {\n eq: (metric, value) => condition(ComparisonOperator.EQ, metric, value),\n ne: (metric, value) => condition(ComparisonOperator.NE, metric, value),\n gt: (metric, value) => condition(ComparisonOperator.GT, metric, value),\n gte: (metric, value) => condition(ComparisonOperator.GTE, metric, value),\n lt: (metric, value) => condition(ComparisonOperator.LT, metric, value),\n lte: (metric, value) => condition(ComparisonOperator.LTE, metric, value),\n between(metric, lower, upper) {\n if (!Number.isFinite(lower) || !Number.isFinite(upper)) {\n throw new TypeError(`having between [${metric}] bounds must be finite.`);\n }\n if (lower > upper) {\n throw new TypeError(\n `having between [${metric}] lower bound must not exceed upper bound.`,\n );\n }\n return { type: HavingExpressionType.BETWEEN, metric, lower, upper };\n },\n isIn(metric, values) {\n const [first, ...rest] = values;\n if (first === undefined) {\n throw new TypeError(`having in [${metric}] values must not be empty.`);\n }\n if (!values.every(Number.isFinite)) {\n throw new TypeError(`having in [${metric}] values must be finite.`);\n }\n return { type: HavingExpressionType.IN, metric, values: [first, ...rest] };\n },\n isNull: metric => ({ type: HavingExpressionType.IS_NULL, metric }),\n isNotNull: metric => ({\n type: HavingExpressionType.IS_NULL,\n metric,\n negated: true,\n }),\n and: operands => logical(HavingExpressionType.AND, operands),\n or: operands => logical(HavingExpressionType.OR, operands),\n};\n"],"mappings":"+BAgHA,SAASG,EACP,EACA,EACA,EACkB,CAClB,GAAI,CAAC,OAAO,SAASC,CAAK,EACxB,MAAU,UAAU,qBAAqBC,EAAO,wBAAwB,EAE1E,MAAO,CAAE,KAAML,EAAAA,qBAAqB,UAAW,SAAQ,WAAU,OAAM,CACzE,CAEA,SAASM,EACP,EACA,EACkB,CAClB,GAAM,CAACC,EAAO,GAAGC,GAAQC,EACzB,GAAIF,IAAU,IAAA,GACZ,MAAU,UAAU,UAAUG,EAAK,6BAA6B,EAElE,MAAO,CAAE,OAAM,SAAU,CAACH,EAAO,GAAGC,CAAI,CAAE,CAC5C,CAEA,IAAaG,EAAuB,CAClC,IAAK,EAAQ,IAAUR,EAAUF,EAAAA,mBAAmB,GAAII,EAAQD,CAAK,EACrE,IAAK,EAAQ,IAAUD,EAAUF,EAAAA,mBAAmB,GAAII,EAAQD,CAAK,EACrE,IAAK,EAAQ,IAAUD,EAAUF,EAAAA,mBAAmB,GAAII,EAAQD,CAAK,EACrE,KAAM,EAAQ,IAAUD,EAAUF,EAAAA,mBAAmB,IAAKI,EAAQD,CAAK,EACvE,IAAK,EAAQ,IAAUD,EAAUF,EAAAA,mBAAmB,GAAII,EAAQD,CAAK,EACrE,KAAM,EAAQ,IAAUD,EAAUF,EAAAA,mBAAmB,IAAKI,EAAQD,CAAK,EACvE,QAAQ,EAAQ,EAAO,EAAO,CAC5B,GAAI,CAAC,OAAO,SAASQ,CAAK,GAAK,CAAC,OAAO,SAASC,CAAK,EACnD,MAAU,UAAU,mBAAmBR,EAAO,yBAAyB,EAEzE,GAAIO,EAAQC,EACV,MAAU,UACR,mBAAmBR,EAAO,2CAC5B,EAEF,MAAO,CAAE,KAAML,EAAAA,qBAAqB,QAAS,SAAQ,QAAO,OAAM,CACpE,EACA,KAAK,EAAQ,EAAQ,CACnB,GAAM,CAACO,EAAO,GAAGC,GAAQM,EACzB,GAAIP,IAAU,IAAA,GACZ,MAAU,UAAU,cAAcF,EAAO,4BAA4B,EAEvE,GAAI,CAACS,EAAO,MAAM,OAAO,QAAQ,EAC/B,MAAU,UAAU,cAAcT,EAAO,yBAAyB,EAEpE,MAAO,CAAE,KAAML,EAAAA,qBAAqB,GAAI,SAAQ,OAAQ,CAACO,EAAO,GAAGC,CAAI,CAAE,CAC3E,EACA,OAAQ,IAAW,CAAE,KAAMR,EAAAA,qBAAqB,QAAS,QAAO,GAChE,UAAW,IAAW,CACpB,KAAMA,EAAAA,qBAAqB,QAC3B,SACA,QAAS,EACX,GACA,IAAK,GAAYM,EAAQN,EAAAA,qBAAqB,IAAKS,CAAQ,EAC3D,GAAI,GAAYH,EAAQN,EAAAA,qBAAqB,GAAIS,CAAQ,CAC3D"}
@@ -0,0 +1,94 @@
1
+ import { HavingExpression } from './types.cjs';
2
+ /**
3
+ * The builders of a `having` expression, `aggregation.having.*`: conditions on
4
+ * the metric columns of the grouped rows, and their `and`/`or`. Mirrors
5
+ * Kotlin's `HavingDsl` (`wow-query`, `AggregationQueryDsl.kt`).
6
+ *
7
+ * Each builder checks its own numbers and throws a `TypeError` with the
8
+ * message Wow answers; `aggregation.query()` checks what spans the query:
9
+ * that `metric` names a declared, non-ANY metric, and that the query groups.
10
+ */
11
+ export interface HavingDsl {
12
+ /**
13
+ * `metric = value`. `{ type: 'CONDITION', metric, operator: 'EQ', value }`.
14
+ *
15
+ * @param metric - The alias of a metric of the same query.
16
+ * @throws TypeError when `value` is not finite.
17
+ * @example
18
+ * ```typescript
19
+ * aggregation.having.eq('orders', 1);
20
+ * ```
21
+ */
22
+ eq(metric: string, value: number): HavingExpression;
23
+ /** `metric ≠ value`. `{ type: 'CONDITION', operator: 'NE', … }`. */
24
+ ne(metric: string, value: number): HavingExpression;
25
+ /**
26
+ * `metric > value`. `{ type: 'CONDITION', operator: 'GT', … }`.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * aggregation.having.gt('revenue', 100);
31
+ * ```
32
+ */
33
+ gt(metric: string, value: number): HavingExpression;
34
+ /** `metric ≥ value`. `{ type: 'CONDITION', operator: 'GTE', … }`. */
35
+ gte(metric: string, value: number): HavingExpression;
36
+ /** `metric < value`. `{ type: 'CONDITION', operator: 'LT', … }`. */
37
+ lt(metric: string, value: number): HavingExpression;
38
+ /** `metric ≤ value`. `{ type: 'CONDITION', operator: 'LTE', … }`. */
39
+ lte(metric: string, value: number): HavingExpression;
40
+ /**
41
+ * `lower ≤ metric ≤ upper`. `{ type: 'BETWEEN', metric, lower, upper }`.
42
+ *
43
+ * @throws TypeError when a bound is not finite, or `lower` exceeds `upper`.
44
+ * @example
45
+ * ```typescript
46
+ * aggregation.having.between('revenue', 10, 1000);
47
+ * ```
48
+ */
49
+ between(metric: string, lower: number, upper: number): HavingExpression;
50
+ /**
51
+ * `metric` is one of `values`. `{ type: 'IN', metric, values }` with a
52
+ * copy of `values`.
53
+ *
54
+ * @throws TypeError when `values` is empty or holds a non-finite number.
55
+ * @example
56
+ * ```typescript
57
+ * aggregation.having.isIn('orders', [2, 3]);
58
+ * ```
59
+ */
60
+ isIn(metric: string, values: readonly number[]): HavingExpression;
61
+ /**
62
+ * `metric` has no value in the row. `{ type: 'IS_NULL', metric }`.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * aggregation.having.isNull('averageOrder');
67
+ * ```
68
+ */
69
+ isNull(metric: string): HavingExpression;
70
+ /** `metric` has a value. `{ type: 'IS_NULL', metric, negated: true }`. */
71
+ isNotNull(metric: string): HavingExpression;
72
+ /**
73
+ * All of `operands` hold. `{ type: 'AND', operands }` with a copy of
74
+ * `operands`.
75
+ *
76
+ * @throws TypeError when `operands` is empty.
77
+ * @example
78
+ * ```typescript
79
+ * aggregation.having.and([
80
+ * aggregation.having.gt('orders', 1),
81
+ * aggregation.having.isNotNull('revenue'),
82
+ * ]);
83
+ * ```
84
+ */
85
+ and(operands: readonly HavingExpression[]): HavingExpression;
86
+ /**
87
+ * At least one of `operands` holds. `{ type: 'OR', operands }` with a copy
88
+ * of `operands`.
89
+ *
90
+ * @throws TypeError when `operands` is empty.
91
+ */
92
+ or(operands: readonly HavingExpression[]): HavingExpression;
93
+ }
94
+ export declare const havingDsl: HavingDsl;