@ahoo-wang/wow-client 10.0.0-alpha.5 → 10.0.0-alpha.7
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.
- package/README.md +76 -23
- package/README.zh-CN.md +66 -19
- package/dist/commands.cjs +1 -1
- package/dist/commands.cjs.map +1 -1
- package/dist/commands.d.cts +131 -61
- package/dist/commands.d.ts +131 -61
- package/dist/commands.es.js +117 -59
- package/dist/commands.es.js.map +1 -1
- package/dist/developmentCaller.cjs +2 -0
- package/dist/developmentCaller.cjs.map +1 -0
- package/dist/developmentCaller.d.cts +61 -0
- package/dist/developmentCaller.d.ts +61 -0
- package/dist/developmentCaller.es.js +26 -0
- package/dist/developmentCaller.es.js.map +1 -0
- package/dist/dsl/aggregation/admit.cjs +1 -1
- package/dist/dsl/aggregation/admit.cjs.map +1 -1
- package/dist/dsl/aggregation/admit.es.js +93 -93
- package/dist/dsl/aggregation/admit.es.js.map +1 -1
- package/dist/dsl/aggregation/builders.cjs +1 -1
- package/dist/dsl/aggregation/builders.cjs.map +1 -1
- package/dist/dsl/aggregation/builders.d.cts +20 -20
- package/dist/dsl/aggregation/builders.d.ts +20 -20
- package/dist/dsl/aggregation/builders.es.js +88 -88
- package/dist/dsl/aggregation/builders.es.js.map +1 -1
- package/dist/dsl/aggregation/derived.cjs.map +1 -1
- package/dist/dsl/aggregation/derived.d.cts +8 -8
- package/dist/dsl/aggregation/derived.d.ts +8 -8
- package/dist/dsl/aggregation/derived.es.js +1 -2
- package/dist/dsl/aggregation/derived.es.js.map +1 -1
- package/dist/dsl/aggregation/expressionTrees.cjs.map +1 -1
- package/dist/dsl/aggregation/expressionTrees.es.js +1 -2
- package/dist/dsl/aggregation/having.cjs +1 -1
- package/dist/dsl/aggregation/having.cjs.map +1 -1
- package/dist/dsl/aggregation/having.d.cts +12 -12
- package/dist/dsl/aggregation/having.d.ts +12 -12
- package/dist/dsl/aggregation/having.es.js +33 -33
- package/dist/dsl/aggregation/having.es.js.map +1 -1
- package/dist/dsl/aggregation/sort.cjs.map +1 -1
- package/dist/dsl/aggregation/sort.es.js +1 -2
- package/dist/dsl/aggregation/types.cjs +1 -1
- package/dist/dsl/aggregation/types.cjs.map +1 -1
- package/dist/dsl/aggregation/types.d.cts +69 -69
- package/dist/dsl/aggregation/types.d.ts +69 -69
- package/dist/dsl/aggregation/types.es.js +15 -16
- package/dist/dsl/aggregation/types.es.js.map +1 -1
- package/dist/dsl/constantName.cjs +2 -0
- package/dist/dsl/constantName.cjs.map +1 -0
- package/dist/dsl/constantName.d.cts +9 -0
- package/dist/dsl/constantName.d.ts +9 -0
- package/dist/dsl/constantName.es.js +7 -0
- package/dist/dsl/constantName.es.js.map +1 -0
- package/dist/dsl/cursorQuery.cjs.map +1 -1
- package/dist/dsl/cursorQuery.es.js +1 -2
- package/dist/dsl/deletionState.cjs +1 -1
- package/dist/dsl/deletionState.cjs.map +1 -1
- package/dist/dsl/deletionState.d.cts +3 -3
- package/dist/dsl/deletionState.d.ts +3 -3
- package/dist/dsl/deletionState.es.js +2 -3
- package/dist/dsl/deletionState.es.js.map +1 -1
- package/dist/dsl/descriptor.cjs +1 -1
- package/dist/dsl/descriptor.cjs.map +1 -1
- package/dist/dsl/descriptor.d.cts +92 -42
- package/dist/dsl/descriptor.d.ts +92 -42
- package/dist/dsl/descriptor.es.js +36 -29
- package/dist/dsl/descriptor.es.js.map +1 -1
- package/dist/dsl/field.cjs.map +1 -1
- package/dist/dsl/field.es.js +1 -2
- package/dist/dsl/filter/builders.cjs +1 -1
- package/dist/dsl/filter/builders.cjs.map +1 -1
- package/dist/dsl/filter/builders.d.cts +53 -53
- package/dist/dsl/filter/builders.d.ts +53 -53
- package/dist/dsl/filter/builders.es.js +111 -111
- package/dist/dsl/filter/builders.es.js.map +1 -1
- package/dist/dsl/filter/datePattern.cjs.map +1 -1
- package/dist/dsl/filter/datePattern.es.js +1 -2
- package/dist/dsl/filter/operator.cjs +1 -1
- package/dist/dsl/filter/operator.cjs.map +1 -1
- package/dist/dsl/filter/operator.d.cts +57 -57
- package/dist/dsl/filter/operator.d.ts +57 -57
- package/dist/dsl/filter/operator.es.js +4 -5
- package/dist/dsl/filter/operator.es.js.map +1 -1
- package/dist/dsl/filter/scope.cjs +1 -1
- package/dist/dsl/filter/scope.cjs.map +1 -1
- package/dist/dsl/filter/scope.es.js +12 -12
- package/dist/dsl/filter/scope.es.js.map +1 -1
- package/dist/dsl/filter/validate.cjs +1 -1
- package/dist/dsl/filter/validate.cjs.map +1 -1
- package/dist/dsl/filter/validate.es.js +23 -23
- package/dist/dsl/filter/validate.es.js.map +1 -1
- package/dist/dsl/pagination.cjs.map +1 -1
- package/dist/dsl/pagination.es.js +1 -2
- package/dist/dsl/projection.cjs.map +1 -1
- package/dist/dsl/projection.d.cts +1 -1
- package/dist/dsl/projection.d.ts +1 -1
- package/dist/dsl/projection.es.js +1 -2
- package/dist/dsl/projection.es.js.map +1 -1
- package/dist/dsl/queryErrorCodes.cjs +1 -1
- package/dist/dsl/queryErrorCodes.cjs.map +1 -1
- package/dist/dsl/queryErrorCodes.d.cts +59 -48
- package/dist/dsl/queryErrorCodes.d.ts +59 -48
- package/dist/dsl/queryErrorCodes.es.js +51 -50
- package/dist/dsl/queryErrorCodes.es.js.map +1 -1
- package/dist/dsl/queryable.cjs +1 -1
- package/dist/dsl/queryable.cjs.map +1 -1
- package/dist/dsl/queryable.d.cts +25 -21
- package/dist/dsl/queryable.d.ts +25 -21
- package/dist/dsl/queryable.es.js +5 -5
- package/dist/dsl/queryable.es.js.map +1 -1
- package/dist/dsl/sort.cjs +1 -1
- package/dist/dsl/sort.cjs.map +1 -1
- package/dist/dsl/sort.d.cts +2 -2
- package/dist/dsl/sort.d.ts +2 -2
- package/dist/dsl/sort.es.js +4 -5
- package/dist/dsl/sort.es.js.map +1 -1
- package/dist/dsl.cjs +1 -1
- package/dist/dsl.es.js +3 -3
- package/dist/exactJson.cjs.map +1 -1
- package/dist/exactJson.d.cts +4 -4
- package/dist/exactJson.d.ts +4 -4
- package/dist/exactJson.es.js +1 -2
- package/dist/exactJson.es.js.map +1 -1
- package/dist/frameworkErrors.cjs +2 -0
- package/dist/frameworkErrors.cjs.map +1 -0
- package/dist/frameworkErrors.d.cts +121 -0
- package/dist/frameworkErrors.d.ts +121 -0
- package/dist/frameworkErrors.es.js +95 -0
- package/dist/frameworkErrors.es.js.map +1 -0
- package/dist/http.cjs +1 -1
- package/dist/http.cjs.map +1 -1
- package/dist/http.d.cts +4 -7
- package/dist/http.d.ts +4 -7
- package/dist/http.es.js +12 -20
- package/dist/http.es.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +9 -7
- package/dist/index.d.ts +9 -7
- package/dist/index.es.js +11 -9
- package/dist/manifest.cjs +1 -1
- package/dist/manifest.cjs.map +1 -1
- package/dist/manifest.d.cts +33 -95
- package/dist/manifest.d.ts +33 -95
- package/dist/manifest.es.js +12 -7
- package/dist/manifest.es.js.map +1 -1
- package/dist/manifestTypes.d.cts +193 -0
- package/dist/manifestTypes.d.ts +193 -0
- package/dist/problem.cjs +1 -1
- package/dist/problem.cjs.map +1 -1
- package/dist/problem.d.cts +76 -111
- package/dist/problem.d.ts +76 -111
- package/dist/problem.es.js +45 -78
- package/dist/problem.es.js.map +1 -1
- package/dist/queries.cjs +1 -1
- package/dist/queries.cjs.map +1 -1
- package/dist/queries.d.cts +28 -51
- package/dist/queries.d.ts +28 -51
- package/dist/queries.es.js +49 -40
- package/dist/queries.es.js.map +1 -1
- package/dist/routes.cjs +2 -0
- package/dist/routes.cjs.map +1 -0
- package/dist/routes.d.cts +49 -0
- package/dist/routes.d.ts +49 -0
- package/dist/routes.es.js +33 -0
- package/dist/routes.es.js.map +1 -0
- package/dist/state.cjs +1 -1
- package/dist/state.cjs.map +1 -1
- package/dist/state.d.cts +56 -11
- package/dist/state.d.ts +56 -11
- package/dist/state.es.js +56 -21
- package/dist/state.es.js.map +1 -1
- package/dist/streams.cjs +1 -1
- package/dist/streams.cjs.map +1 -1
- package/dist/streams.d.cts +17 -13
- package/dist/streams.d.ts +17 -13
- package/dist/streams.es.js +50 -50
- package/dist/streams.es.js.map +1 -1
- package/dist/testing/wire.cjs +2 -0
- package/dist/testing/wire.cjs.map +1 -0
- package/dist/testing/wire.d.cts +29 -0
- package/dist/testing/wire.d.ts +29 -0
- package/dist/testing/wire.es.js +88 -0
- package/dist/testing/wire.es.js.map +1 -0
- package/dist/testing.cjs +1 -0
- package/dist/testing.d.cts +12 -0
- package/dist/testing.d.ts +12 -0
- package/dist/testing.es.js +3 -0
- package/dist/wait.cjs +1 -1
- package/dist/wait.cjs.map +1 -1
- package/dist/wait.d.cts +67 -18
- package/dist/wait.d.ts +67 -18
- package/dist/wait.es.js +59 -12
- package/dist/wait.es.js.map +1 -1
- package/dist/wire.cjs +1 -1
- package/dist/wire.cjs.map +1 -1
- package/dist/wire.d.cts +100 -50
- package/dist/wire.d.ts +100 -50
- package/dist/wire.es.js +17 -6
- package/dist/wire.es.js.map +1 -1
- package/package.json +26 -7
|
@@ -28,7 +28,7 @@ export declare const aggregation: {
|
|
|
28
28
|
*/
|
|
29
29
|
element(path: string, predicate?: ElementFilterExpression | ExpressionFilter): AggregationElement;
|
|
30
30
|
/**
|
|
31
|
-
* The value of a field, as an operand. `{ type: '
|
|
31
|
+
* The value of a field, as an operand. `{ type: 'field', field }`.
|
|
32
32
|
*
|
|
33
33
|
* @throws TypeError when `field` is not a valid field path.
|
|
34
34
|
* @example
|
|
@@ -38,7 +38,7 @@ export declare const aggregation: {
|
|
|
38
38
|
*/
|
|
39
39
|
field<FIELDS extends string>(field: FIELDS): FieldAggregationExpression<FIELDS>;
|
|
40
40
|
/**
|
|
41
|
-
* A number, as an operand. `{ type: '
|
|
41
|
+
* A number, as an operand. `{ type: 'constant', value }`.
|
|
42
42
|
*
|
|
43
43
|
* @throws TypeError when `value` is not finite.
|
|
44
44
|
* @example
|
|
@@ -51,7 +51,7 @@ export declare const aggregation: {
|
|
|
51
51
|
* The time from the instant in `from` to the instant in `to`, `to − from`,
|
|
52
52
|
* in `unit`, as a signed decimal: negative when `to` is earlier, and no
|
|
53
53
|
* value when either instant is absent. A `DAY` is exactly 24 hours.
|
|
54
|
-
* `{ type: '
|
|
54
|
+
* `{ type: 'date-diff', from, to, unit }`. Both fields must be
|
|
55
55
|
* single-valued time fields, those whose `aggregate.groups` list
|
|
56
56
|
* `DATE_HISTOGRAM` in the descriptor, and `unit` one of its
|
|
57
57
|
* `analysis.dateDiffUnits`. Wow 9.2 and later.
|
|
@@ -68,18 +68,18 @@ export declare const aggregation: {
|
|
|
68
68
|
* ```
|
|
69
69
|
*/
|
|
70
70
|
dateDiff<FIELDS extends string>(from: FIELDS, to: FIELDS, unit: DateDiffUnit): DateDiffAggregationExpression<FIELDS>;
|
|
71
|
-
/** `left + right`. `{ type: '
|
|
71
|
+
/** `left + right`. `{ type: 'binary', operator: 'add', left, right }`. */
|
|
72
72
|
add: <FIELDS extends string>(left: AggregationExpression<FIELDS>, right: AggregationExpression<FIELDS>) => BinaryAggregationExpression<FIELDS>;
|
|
73
|
-
/** `left - right`. `{ type: '
|
|
73
|
+
/** `left - right`. `{ type: 'binary', operator: 'subtract', left, right }`. */
|
|
74
74
|
subtract: <FIELDS extends string>(left: AggregationExpression<FIELDS>, right: AggregationExpression<FIELDS>) => BinaryAggregationExpression<FIELDS>;
|
|
75
|
-
/** `left * right`. `{ type: '
|
|
75
|
+
/** `left * right`. `{ type: 'binary', operator: 'multiply', left, right }`. */
|
|
76
76
|
multiply: <FIELDS extends string>(left: AggregationExpression<FIELDS>, right: AggregationExpression<FIELDS>) => BinaryAggregationExpression<FIELDS>;
|
|
77
|
-
/** `left / right`. `{ type: '
|
|
77
|
+
/** `left / right`. `{ type: 'binary', operator: 'divide', left, right }`. */
|
|
78
78
|
divide: <FIELDS extends string>(left: AggregationExpression<FIELDS>, right: AggregationExpression<FIELDS>) => BinaryAggregationExpression<FIELDS>;
|
|
79
79
|
/**
|
|
80
80
|
* Groups by each distinct value of a field, or of a computed expression.
|
|
81
|
-
* `{ type: '
|
|
82
|
-
* `{ type: '
|
|
81
|
+
* `{ type: 'terms', field, alias, missingKey? }`, or
|
|
82
|
+
* `{ type: 'terms', expression, alias }`.
|
|
83
83
|
*
|
|
84
84
|
* @param input - The field to group by, or an expression in its place
|
|
85
85
|
* (Wow 9.2 and later, an expensive computation).
|
|
@@ -103,7 +103,7 @@ export declare const aggregation: {
|
|
|
103
103
|
terms<FIELDS extends string>(input: FIELDS | AggregationExpression<FIELDS>, alias: string, { missingKey, scope }?: TermsAggregationOptions): TermsAggregationGroup<FIELDS>;
|
|
104
104
|
/**
|
|
105
105
|
* Groups a number field, or a computed expression, into buckets of equal
|
|
106
|
-
* width. `{ type: '
|
|
106
|
+
* width. `{ type: 'histogram', field | expression, interval, alias }`.
|
|
107
107
|
*
|
|
108
108
|
* @param input - The number field to bucket, or an expression in its
|
|
109
109
|
* place (Wow 9.2 and later, an expensive computation).
|
|
@@ -122,7 +122,7 @@ export declare const aggregation: {
|
|
|
122
122
|
histogram<FIELDS extends string>(input: FIELDS | AggregationExpression<FIELDS>, alias: string, { interval, scope }: HistogramAggregationOptions): HistogramAggregationGroup<FIELDS>;
|
|
123
123
|
/**
|
|
124
124
|
* Groups a time field into calendar buckets.
|
|
125
|
-
* `{ type: '
|
|
125
|
+
* `{ type: 'date-histogram', field, unit, alias, timeZone, dense? }`.
|
|
126
126
|
*
|
|
127
127
|
* @param field - The time field (epoch milliseconds) to bucket.
|
|
128
128
|
* @param alias - The name of the bucket column in the result rows.
|
|
@@ -148,7 +148,7 @@ export declare const aggregation: {
|
|
|
148
148
|
/**
|
|
149
149
|
* Groups a time field by one calendar part of each instant, such as the
|
|
150
150
|
* weekday or the hour, so records from different days share a bucket.
|
|
151
|
-
* `{ type: '
|
|
151
|
+
* `{ type: 'date-part', field, part, alias, timeZone, dense? }`.
|
|
152
152
|
*
|
|
153
153
|
* The group's keys in the result rows are integers: `DAY_OF_WEEK` is the
|
|
154
154
|
* ISO weekday, 1 (Monday) to 7 (Sunday); `DAY_OF_MONTH` 1 to 31;
|
|
@@ -181,7 +181,7 @@ export declare const aggregation: {
|
|
|
181
181
|
datePart<FIELDS extends string>(field: FIELDS, alias: string, { part, timeZone, dense, scope }: DatePartAggregationOptions): DatePartAggregationGroup<FIELDS>;
|
|
182
182
|
/**
|
|
183
183
|
* Any one value of a field within each group, of any type.
|
|
184
|
-
* `{ type: '
|
|
184
|
+
* `{ type: 'any', field, alias, filter? }`.
|
|
185
185
|
*
|
|
186
186
|
* @throws TypeError when `field` or `alias` is invalid.
|
|
187
187
|
* @example
|
|
@@ -192,7 +192,7 @@ export declare const aggregation: {
|
|
|
192
192
|
any<FIELDS extends string>(field: FIELDS, alias: string, { filter: predicate }?: AggregationMetricOptions<FIELDS>): AnyAggregationMetric<FIELDS>;
|
|
193
193
|
/**
|
|
194
194
|
* The value of `field` on each group's earliest record by `orderBy`.
|
|
195
|
-
* `{ type: '
|
|
195
|
+
* `{ type: 'first', field, alias, orderBy?, filter? }`.
|
|
196
196
|
*
|
|
197
197
|
* The value comes back in the field's own type, or `null` when no record
|
|
198
198
|
* of the group has both a value and an `orderBy` position. Without
|
|
@@ -209,7 +209,7 @@ export declare const aggregation: {
|
|
|
209
209
|
first<FIELDS extends string>(field: FIELDS, alias: string, options?: EdgeAggregationOptions<FIELDS>): EdgeAggregationMetric<FIELDS>;
|
|
210
210
|
/**
|
|
211
211
|
* The value of `field` on each group's latest record by `orderBy`.
|
|
212
|
-
* `{ type: '
|
|
212
|
+
* `{ type: 'last', field, alias, orderBy?, filter? }`. As
|
|
213
213
|
* {@link aggregation.first}, from the other end.
|
|
214
214
|
*
|
|
215
215
|
* @throws TypeError when `field`, `orderBy` or `alias` is invalid.
|
|
@@ -220,7 +220,7 @@ export declare const aggregation: {
|
|
|
220
220
|
*/
|
|
221
221
|
last<FIELDS extends string>(field: FIELDS, alias: string, options?: EdgeAggregationOptions<FIELDS>): EdgeAggregationMetric<FIELDS>;
|
|
222
222
|
/**
|
|
223
|
-
* The number of rows in each group. `{ type: '
|
|
223
|
+
* The number of rows in each group. `{ type: 'count', alias, filter? }`.
|
|
224
224
|
*
|
|
225
225
|
* @param alias - The name of the metric column in the result rows.
|
|
226
226
|
* @param options.filter - Counts only the rows that match.
|
|
@@ -232,7 +232,7 @@ export declare const aggregation: {
|
|
|
232
232
|
*/
|
|
233
233
|
count<FIELDS extends string = string>(alias: string, { filter: predicate }?: AggregationMetricOptions<FIELDS>): CountAggregationMetric<FIELDS>;
|
|
234
234
|
/**
|
|
235
|
-
* The sum of an expression. `{ type: '
|
|
235
|
+
* The sum of an expression. `{ type: 'numeric', function: 'sum',
|
|
236
236
|
* expression, alias, filter? }`.
|
|
237
237
|
*
|
|
238
238
|
* @example
|
|
@@ -253,7 +253,7 @@ export declare const aggregation: {
|
|
|
253
253
|
variance: <FIELDS extends string>(expression: AggregationExpression<FIELDS>, alias: string, options?: AggregationMetricOptions<FIELDS>) => NumericAggregationMetric<FIELDS>;
|
|
254
254
|
/**
|
|
255
255
|
* The number of distinct values of an expression.
|
|
256
|
-
* `{ type: '
|
|
256
|
+
* `{ type: 'distinct-count', expression, alias, filter? }`.
|
|
257
257
|
*
|
|
258
258
|
* @example
|
|
259
259
|
* ```typescript
|
|
@@ -263,7 +263,7 @@ export declare const aggregation: {
|
|
|
263
263
|
distinctCount<FIELDS extends string>(expression: AggregationExpression<FIELDS>, alias: string, { filter: predicate }?: AggregationMetricOptions<FIELDS>): DistinctCountAggregationMetric<FIELDS>;
|
|
264
264
|
/**
|
|
265
265
|
* A percentile of an expression.
|
|
266
|
-
* `{ type: '
|
|
266
|
+
* `{ type: 'percentile', expression, percentile, alias, filter? }`.
|
|
267
267
|
*
|
|
268
268
|
* @param options.percentile - Which percentile, within (0, 100).
|
|
269
269
|
* @throws TypeError when `percentile` is not finite and within (0, 100), or
|
|
@@ -276,7 +276,7 @@ export declare const aggregation: {
|
|
|
276
276
|
percentile<FIELDS extends string>(expression: AggregationExpression<FIELDS>, alias: string, { percentile, filter: predicate }: PercentileAggregationOptions<FIELDS>): PercentileAggregationMetric<FIELDS>;
|
|
277
277
|
/**
|
|
278
278
|
* A metric computed from other metrics of the same row, by their aliases.
|
|
279
|
-
* `{ type: '
|
|
279
|
+
* `{ type: 'derived', expression, alias }`. `aggregation.query()` checks
|
|
280
280
|
* that it refers only to metrics declared before it.
|
|
281
281
|
*
|
|
282
282
|
* @param expression - The arithmetic: a callback that builds it from the
|
|
@@ -1,199 +1,199 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return u(e);
|
|
11
|
-
}
|
|
1
|
+
import { constantName as e } from "../constantName.es.js";
|
|
2
|
+
import { AggregationDatePart as t, AggregationDateUnit as n, AggregationExpressionOperator as r, AggregationExpressionType as i, AggregationFunction as a, AggregationGroupScope as o, AggregationGroupType as s, AggregationMetricType as c, DateDiffUnit as l } from "./types.es.js";
|
|
3
|
+
import { requireValidExpressionTrees as u } from "./expressionTrees.es.js";
|
|
4
|
+
import { queryField as d } from "../field.es.js";
|
|
5
|
+
import { requireElementScopedFilter as f } from "../filter/scope.es.js";
|
|
6
|
+
import { admitAggregationQuery as p } from "./admit.es.js";
|
|
7
|
+
import { derivedExpressionDsl as m } from "./derived.es.js";
|
|
8
|
+
import { havingDsl as h } from "./having.es.js";
|
|
9
|
+
// src/dsl/aggregation/builders.ts
|
|
12
10
|
function g(e) {
|
|
13
|
-
|
|
11
|
+
return d(e);
|
|
12
|
+
}
|
|
13
|
+
function _(e) {
|
|
14
|
+
if (g(e), e.includes(".")) throw TypeError("aggregation alias must contain one segment.");
|
|
14
15
|
if (e.startsWith("__wow")) throw TypeError("aggregation alias must not use the reserved __wow prefix.");
|
|
15
16
|
return e;
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
+
function v(e, t, n) {
|
|
18
19
|
return {
|
|
19
|
-
type:
|
|
20
|
+
type: i.BINARY,
|
|
20
21
|
operator: e,
|
|
21
22
|
left: t,
|
|
22
23
|
right: n
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
|
-
function
|
|
26
|
+
function y(e, t, n, { filter: r } = {}) {
|
|
26
27
|
return {
|
|
27
|
-
type:
|
|
28
|
+
type: c.NUMERIC,
|
|
28
29
|
...r === void 0 ? {} : { filter: r },
|
|
29
30
|
function: e,
|
|
30
31
|
expression: t,
|
|
31
|
-
alias:
|
|
32
|
+
alias: _(n)
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
|
-
function
|
|
35
|
+
function b(e, t, n, { orderBy: r, filter: i }) {
|
|
35
36
|
return {
|
|
36
37
|
type: e,
|
|
37
|
-
field:
|
|
38
|
-
alias:
|
|
39
|
-
...r === void 0 ? {} : { orderBy:
|
|
38
|
+
field: g(t),
|
|
39
|
+
alias: _(n),
|
|
40
|
+
...r === void 0 ? {} : { orderBy: g(r) },
|
|
40
41
|
...i === void 0 ? {} : { filter: i }
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
-
if (typeof
|
|
45
|
-
if (typeof
|
|
46
|
-
return
|
|
44
|
+
function x(t, n) {
|
|
45
|
+
if (typeof t == "string") return { field: g(t) };
|
|
46
|
+
if (typeof t != "object" || !t) throw TypeError(`${e(n)} group requires exactly one of field and expression.`);
|
|
47
|
+
return u([t]), { expression: t };
|
|
47
48
|
}
|
|
48
|
-
function
|
|
49
|
-
if (
|
|
50
|
-
if (!Object.values(
|
|
51
|
-
if (
|
|
52
|
-
return { scope:
|
|
49
|
+
function S(t, n, r) {
|
|
50
|
+
if (t === void 0) return {};
|
|
51
|
+
if (!Object.values(o).includes(t)) throw TypeError(`${e(n)} group scope is invalid.`);
|
|
52
|
+
if (t === o.ROOT && r.expression) throw TypeError(`${e(n)} with a ROOT scope requires a field input.`);
|
|
53
|
+
return { scope: t };
|
|
53
54
|
}
|
|
54
|
-
var
|
|
55
|
+
var C = {
|
|
55
56
|
element(e, t) {
|
|
56
|
-
let n =
|
|
57
|
-
return t === void 0 ? { path: n } : (
|
|
57
|
+
let n = g(e);
|
|
58
|
+
return t === void 0 ? { path: n } : (f(t, "Aggregation element filter", !1), {
|
|
58
59
|
path: n,
|
|
59
60
|
filter: t
|
|
60
61
|
});
|
|
61
62
|
},
|
|
62
63
|
field(e) {
|
|
63
64
|
return {
|
|
64
|
-
type:
|
|
65
|
-
field:
|
|
65
|
+
type: i.FIELD,
|
|
66
|
+
field: g(e)
|
|
66
67
|
};
|
|
67
68
|
},
|
|
68
69
|
constant(e) {
|
|
69
70
|
if (!Number.isFinite(e)) throw TypeError("aggregation constant must be finite.");
|
|
70
71
|
return {
|
|
71
|
-
type:
|
|
72
|
+
type: i.CONSTANT,
|
|
72
73
|
value: e
|
|
73
74
|
};
|
|
74
75
|
},
|
|
75
76
|
dateDiff(e, t, n) {
|
|
76
|
-
if (!Object.values(
|
|
77
|
+
if (!Object.values(l).includes(n)) throw TypeError("date diff unit is invalid.");
|
|
77
78
|
return {
|
|
78
|
-
type:
|
|
79
|
-
from:
|
|
80
|
-
to:
|
|
79
|
+
type: i.DATE_DIFF,
|
|
80
|
+
from: g(e),
|
|
81
|
+
to: g(t),
|
|
81
82
|
unit: n
|
|
82
83
|
};
|
|
83
84
|
},
|
|
84
|
-
add: (e, t) =>
|
|
85
|
-
subtract: (e, t) =>
|
|
86
|
-
multiply: (e, t) =>
|
|
87
|
-
divide: (e, t) =>
|
|
85
|
+
add: (e, t) => v(r.ADD, e, t),
|
|
86
|
+
subtract: (e, t) => v(r.SUBTRACT, e, t),
|
|
87
|
+
multiply: (e, t) => v(r.MULTIPLY, e, t),
|
|
88
|
+
divide: (e, t) => v(r.DIVIDE, e, t),
|
|
88
89
|
terms(e, t, { missingKey: n, scope: r } = {}) {
|
|
89
90
|
if (n !== void 0 && (typeof n != "string" || !n.trim())) throw TypeError("terms missingKey must not be blank.");
|
|
90
|
-
let i =
|
|
91
|
+
let i = x(e, "terms");
|
|
91
92
|
if (n !== void 0 && i.expression) throw TypeError("terms missingKey requires a field input.");
|
|
92
93
|
return {
|
|
93
|
-
type:
|
|
94
|
+
type: s.TERMS,
|
|
94
95
|
...n === void 0 ? {} : { missingKey: n },
|
|
95
96
|
...i,
|
|
96
|
-
...
|
|
97
|
-
alias:
|
|
97
|
+
...S(r, "terms", i),
|
|
98
|
+
alias: _(t)
|
|
98
99
|
};
|
|
99
100
|
},
|
|
100
101
|
histogram(e, t, { interval: n, scope: r }) {
|
|
101
102
|
if (!Number.isFinite(n) || n <= 0) throw TypeError("histogram interval must be finite and greater than 0.");
|
|
102
|
-
let i =
|
|
103
|
+
let i = x(e, "histogram");
|
|
103
104
|
return {
|
|
104
|
-
type:
|
|
105
|
+
type: s.HISTOGRAM,
|
|
105
106
|
...i,
|
|
106
|
-
...
|
|
107
|
+
...S(r, "histogram", i),
|
|
107
108
|
interval: n,
|
|
108
|
-
alias:
|
|
109
|
+
alias: _(t)
|
|
109
110
|
};
|
|
110
111
|
},
|
|
111
|
-
dateHistogram(e,
|
|
112
|
+
dateHistogram(e, t, { unit: r, timeZone: i = "UTC", dense: a, scope: o }) {
|
|
112
113
|
if (a !== void 0 && typeof a != "boolean") throw TypeError("date histogram dense must be boolean.");
|
|
113
|
-
if (!Object.values(
|
|
114
|
+
if (!Object.values(n).includes(r)) throw TypeError("date histogram unit is invalid.");
|
|
114
115
|
if (typeof i != "string" || !i.trim()) throw TypeError("date histogram timeZone cannot be blank.");
|
|
115
116
|
return {
|
|
116
|
-
type:
|
|
117
|
+
type: s.DATE_HISTOGRAM,
|
|
117
118
|
...a === void 0 ? {} : { dense: a },
|
|
118
|
-
field:
|
|
119
|
-
...
|
|
119
|
+
field: g(e),
|
|
120
|
+
...S(o, "date-histogram", {}),
|
|
120
121
|
unit: r,
|
|
121
|
-
alias:
|
|
122
|
+
alias: _(t),
|
|
122
123
|
timeZone: i
|
|
123
124
|
};
|
|
124
125
|
},
|
|
125
|
-
datePart(
|
|
126
|
+
datePart(e, n, { part: r, timeZone: i = "UTC", dense: a, scope: o }) {
|
|
126
127
|
if (a !== void 0 && typeof a != "boolean") throw TypeError("date part dense must be boolean.");
|
|
127
|
-
if (!Object.values(
|
|
128
|
+
if (!Object.values(t).includes(r)) throw TypeError("date part is invalid.");
|
|
128
129
|
if (typeof i != "string" || !i.trim()) throw TypeError("date part timeZone cannot be blank.");
|
|
129
130
|
return {
|
|
130
|
-
type:
|
|
131
|
+
type: s.DATE_PART,
|
|
131
132
|
...a === void 0 ? {} : { dense: a },
|
|
132
|
-
field:
|
|
133
|
-
...
|
|
133
|
+
field: g(e),
|
|
134
|
+
...S(o, "date-part", {}),
|
|
134
135
|
part: r,
|
|
135
|
-
alias:
|
|
136
|
+
alias: _(n),
|
|
136
137
|
timeZone: i
|
|
137
138
|
};
|
|
138
139
|
},
|
|
139
140
|
any(e, t, { filter: n } = {}) {
|
|
140
141
|
return {
|
|
141
|
-
type:
|
|
142
|
+
type: c.ANY,
|
|
142
143
|
...n === void 0 ? {} : { filter: n },
|
|
143
|
-
field:
|
|
144
|
-
alias:
|
|
144
|
+
field: g(e),
|
|
145
|
+
alias: _(t)
|
|
145
146
|
};
|
|
146
147
|
},
|
|
147
148
|
first(e, t, n = {}) {
|
|
148
|
-
return
|
|
149
|
+
return b(c.FIRST, e, t, n);
|
|
149
150
|
},
|
|
150
151
|
last(e, t, n = {}) {
|
|
151
|
-
return
|
|
152
|
+
return b(c.LAST, e, t, n);
|
|
152
153
|
},
|
|
153
154
|
count(e, { filter: t } = {}) {
|
|
154
155
|
return {
|
|
155
|
-
type:
|
|
156
|
+
type: c.COUNT,
|
|
156
157
|
...t === void 0 ? {} : { filter: t },
|
|
157
|
-
alias:
|
|
158
|
+
alias: _(e)
|
|
158
159
|
};
|
|
159
160
|
},
|
|
160
|
-
sum: (e, t, n) =>
|
|
161
|
-
avg: (e, t, n) =>
|
|
162
|
-
min: (e, t, n) =>
|
|
163
|
-
max: (e, t, n) =>
|
|
164
|
-
stddev: (e, t, n) =>
|
|
165
|
-
variance: (e, t, n) =>
|
|
161
|
+
sum: (e, t, n) => y(a.SUM, e, t, n),
|
|
162
|
+
avg: (e, t, n) => y(a.AVG, e, t, n),
|
|
163
|
+
min: (e, t, n) => y(a.MIN, e, t, n),
|
|
164
|
+
max: (e, t, n) => y(a.MAX, e, t, n),
|
|
165
|
+
stddev: (e, t, n) => y(a.STDDEV, e, t, n),
|
|
166
|
+
variance: (e, t, n) => y(a.VARIANCE, e, t, n),
|
|
166
167
|
distinctCount(e, t, { filter: n } = {}) {
|
|
167
168
|
return {
|
|
168
|
-
type:
|
|
169
|
+
type: c.DISTINCT_COUNT,
|
|
169
170
|
expression: e,
|
|
170
|
-
alias:
|
|
171
|
+
alias: _(t),
|
|
171
172
|
...n === void 0 ? {} : { filter: n }
|
|
172
173
|
};
|
|
173
174
|
},
|
|
174
175
|
percentile(e, t, { percentile: n, filter: r }) {
|
|
175
176
|
if (!Number.isFinite(n) || n <= 0 || n >= 100) throw TypeError("percentile must be finite and within (0, 100).");
|
|
176
177
|
return {
|
|
177
|
-
type:
|
|
178
|
+
type: c.PERCENTILE,
|
|
178
179
|
expression: e,
|
|
179
180
|
percentile: n,
|
|
180
|
-
alias:
|
|
181
|
+
alias: _(t),
|
|
181
182
|
...r === void 0 ? {} : { filter: r }
|
|
182
183
|
};
|
|
183
184
|
},
|
|
184
185
|
derived(e, t) {
|
|
185
186
|
return {
|
|
186
|
-
type:
|
|
187
|
-
expression: typeof e == "function" ? e(
|
|
188
|
-
alias:
|
|
187
|
+
type: c.DERIVED,
|
|
188
|
+
expression: typeof e == "function" ? e(m) : e,
|
|
189
|
+
alias: _(t)
|
|
189
190
|
};
|
|
190
191
|
},
|
|
191
|
-
having:
|
|
192
|
+
having: h,
|
|
192
193
|
query(e) {
|
|
193
|
-
return
|
|
194
|
+
return p(e);
|
|
194
195
|
}
|
|
195
196
|
};
|
|
196
|
-
|
|
197
|
-
export { S as aggregation };
|
|
197
|
+
export { C as aggregation };
|
|
198
198
|
|
|
199
199
|
//# sourceMappingURL=builders.es.js.map
|
|
@@ -1 +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","groupScope","scope","AggregationGroupScope","source","aggregation","validPath","path","requireElementScopedFilter","value","DateDiffUnit","unit","from","to","AggregationExpressionOperator","left","right","missingKey","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 AggregationGroupScope,\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/** A group's `scope`, sent only when given; `ROOT` needs a field input. */\nfunction groupScope(\n scope: AggregationGroupScope | undefined,\n type: string,\n source: { expression?: unknown },\n): { scope?: AggregationGroupScope } {\n if (scope === undefined) return {};\n if (!Object.values(AggregationGroupScope).includes(scope)) {\n throw new TypeError(`${type} group scope is invalid.`);\n }\n if (scope === AggregationGroupScope.ROOT && source.expression) {\n throw new TypeError(`${type} with a ROOT scope requires a field input.`);\n }\n return { scope };\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 * @param options.scope - What the field is relative to when the query\n * expands elements: `ROOT` groups the elements by a field of their root\n * record. Wow 9.9 and later.\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, scope }: 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 ...groupScope(scope, 'TERMS', 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 * @param options.scope - What the field is relative to when the query\n * expands elements: `ROOT` groups the elements by a field of their root\n * record. Wow 9.9 and later.\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, scope }: 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 const source = groupInput(input, 'HISTOGRAM');\n return {\n type: AggregationGroupType.HISTOGRAM,\n ...source,\n ...groupScope(scope, 'HISTOGRAM', source),\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 * @param options.scope - What the field is relative to when the query\n * expands elements: `ROOT` groups the elements by a field of their root\n * record. Wow 9.9 and later.\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, scope }: 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 ...groupScope(scope, 'DATE_HISTOGRAM', {}),\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 * @param options.scope - What the field is relative to when the query\n * expands elements: `ROOT` groups the elements by a field of their root\n * record. Wow 9.9 and later.\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, scope }: 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 ...groupScope(scope, 'DATE_PART', {}),\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 },\n};\n"],"mappings":";;;;;;;;AA8DA,SAASA,EAAwC,GAAuB;CACtE,OAAOC,EAAWC,CAAK;AACzB;AAEA,SAASC,EAAiB,GAAuB;CAE/C,IADAH,EAAiBI,CAAK,GAClBA,EAAM,SAAS,GAAG,GACpB,MAAU,UAAU,6CAA6C;CAEnE,IAAIA,EAAM,WAAW,OAAO,GAC1B,MAAU,UACR,2DACF;CAEF,OAAOA;AACT;AAEA,SAASC,EACP,GACA,GACA,GACqC;CACrC,OAAO;EAAE,MAAMC,EAA0B;EAAQ;EAAU;EAAM;CAAM;AACzE;AAEA,SAASC,EACP,GACA,GACA,GACA,EAAE,QAAQC,MAAgD,CAAC,GACzB;CAClC,OAAO;EACL,MAAMC,EAAsB;EAC5B,GAAID,MAAc,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQA,EAAU;EACvD,UAAUE;EACV;EACA,OAAOP,EAAiBC,CAAK;CAC/B;AACF;AAGA,SAASO,EACP,GACA,GACA,GACA,EAAE,YAAS,QAAQH,KACY;CAC/B,OAAO;EACL;EACA,OAAOR,EAAiBE,CAAK;EAC7B,OAAOC,EAAiBC,CAAK;EAC7B,GAAIQ,MAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAASZ,EAAiBY,CAAO,EAAE;EACtE,GAAIJ,MAAc,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQA,EAAU;CACzD;AACF;AAMA,SAASK,EACP,GACA,GAC+B;CAC/B,IAAI,OAAOC,KAAU,UAAU,OAAO,EAAE,OAAOd,EAAiBc,CAA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;CACF;CAUA,MACE,GACA,GACA,MACGG,EAAQmC,EAAoB,KAAKC,GAAYvC,GAAOqC,CAAO;CAEhE,MACE,GACA,GACA,MACGlC,EAAQmC,EAAoB,KAAKC,GAAYvC,GAAOqC,CAAO;CAEhE,MACE,GACA,GACA,MACGlC,EAAQmC,EAAoB,KAAKC,GAAYvC,GAAOqC,CAAO;CAEhE,MACE,GACA,GACA,MACGlC,EAAQmC,EAAoB,KAAKC,GAAYvC,GAAOqC,CAAO;CAEhE,SACE,GACA,GACA,MACGlC,EAAQmC,EAAoB,QAAQC,GAAYvC,GAAOqC,CAAO;CAEnE,WACE,GACA,GACA,MACGlC,EAAQmC,EAAoB,UAAUC,GAAYvC,GAAOqC,CAAO;CAUrE,cACE,GACA,GACA,EAAE,QAAQjC,MAAgD,CAAC,GACnB;EACxC,OAAO;GACL,MAAMC,EAAsB;GAC5B;GACA,OAAON,EAAiBC,CAAK;GAC7B,GAAII,MAAc,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQA,EAAU;EACzD;CACF;CAaA,WACE,GACA,GACA,EAAE,eAAY,QAAQA,KACe;EACrC,IAAI,CAAC,OAAO,SAASoC,CAAU,KAAKA,KAAc,KAAKA,KAAc,KACnE,MAAU,UAAU,gDAAgD;EAEtE,OAAO;GACL,MAAMnC,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,OAAOkC,KAAe,aAClBA,EAAWE,CAAoB,IAC/BF;GACN,OAAOxC,EAAiBC,CAAK;EAC/B;CACF;CAeA,QAAQ0C;CAYR,MAIE,GACmD;EACnD,OAAOC,EAAsBC,CAAK;CACpC;AACF"}
|
|
1
|
+
{"version":3,"file":"builders.es.js","names":["aggregationField","queryField","field","aggregationAlias","alias","binary","AggregationExpressionType","numeric","predicate","AggregationMetricType","fn","edge","orderBy","groupInput","input","constantName","type","requireValidExpressionTrees","groupScope","scope","AggregationGroupScope","source","aggregation","validPath","path","requireElementScopedFilter","value","DateDiffUnit","unit","from","to","AggregationExpressionOperator","left","right","missingKey","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 { constantName } from '../constantName.js';\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 AggregationGroupScope,\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 `${constantName(type)} group requires exactly one of field and expression.`,\n );\n }\n requireValidExpressionTrees([input]);\n return { expression: input };\n}\n\n/** A group's `scope`, sent only when given; `ROOT` needs a field input. */\nfunction groupScope(\n scope: AggregationGroupScope | undefined,\n type: string,\n source: { expression?: unknown },\n): { scope?: AggregationGroupScope } {\n if (scope === undefined) return {};\n if (!Object.values(AggregationGroupScope).includes(scope)) {\n throw new TypeError(`${constantName(type)} group scope is invalid.`);\n }\n if (scope === AggregationGroupScope.ROOT && source.expression) {\n throw new TypeError(\n `${constantName(type)} with a ROOT scope requires a field input.`,\n );\n }\n return { scope };\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 * @param options.scope - What the field is relative to when the query\n * expands elements: `ROOT` groups the elements by a field of their root\n * record. Wow 9.9 and later.\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, scope }: 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 ...groupScope(scope, 'terms', 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 * @param options.scope - What the field is relative to when the query\n * expands elements: `ROOT` groups the elements by a field of their root\n * record. Wow 9.9 and later.\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, scope }: 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 const source = groupInput(input, 'histogram');\n return {\n type: AggregationGroupType.HISTOGRAM,\n ...source,\n ...groupScope(scope, 'histogram', source),\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 * @param options.scope - What the field is relative to when the query\n * expands elements: `ROOT` groups the elements by a field of their root\n * record. Wow 9.9 and later.\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, scope }: 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 ...groupScope(scope, 'date-histogram', {}),\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 * @param options.scope - What the field is relative to when the query\n * expands elements: `ROOT` groups the elements by a field of their root\n * record. Wow 9.9 and later.\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, scope }: 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 ...groupScope(scope, 'date-part', {}),\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 },\n};\n"],"m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