@ahoo-wang/wow-client 10.0.0-alpha.6 → 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 -115
- package/dist/problem.d.ts +76 -115
- package/dist/problem.es.js +45 -80
- 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 +23 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derived.cjs","names":["DerivedExpressionType","AggregationExpressionOperator","require_types","binary","derivedExpressionDsl","value","left","right","within","options"],"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 type { FieldSort, SortDirection } from '../sort.js';\nimport {\n AggregationExpressionOperator,\n DerivedExpressionType,\n type AggregationDateUnit,\n type DerivedExpression,\n type RunningFunction,\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: '
|
|
1
|
+
{"version":3,"file":"derived.cjs","names":["DerivedExpressionType","AggregationExpressionOperator","require_types","binary","derivedExpressionDsl","value","left","right","within","options"],"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 type { FieldSort, SortDirection } from '../sort.js';\nimport {\n AggregationExpressionOperator,\n DerivedExpressionType,\n type AggregationDateUnit,\n type DerivedExpression,\n type RunningFunction,\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 * `metric` summed over the groups sharing this group's `within` keys.\n * `{ type: 'total', metric, within }`.\n */\n total(metric: string, ...within: string[]): DerivedExpression;\n /**\n * `metric` accumulated along `order` within the groups sharing this group's\n * `within` keys; with `frame` and `function: 'avg'`, a moving average.\n */\n running(\n metric: string,\n order: FieldSort,\n options?: {\n within?: string[];\n frame?: number;\n function?: RunningFunction;\n },\n ): DerivedExpression;\n /**\n * `metric` of the group `shift` buckets (or `period`s) earlier along the\n * `DATE_HISTOGRAM` group `along`.\n */\n previous(\n metric: string,\n along: string,\n options?: { shift?: number; period?: AggregationDateUnit },\n ): DerivedExpression;\n /**\n * The dense rank of `metric` among the groups sharing this group's\n * `within` keys, `DESC` unless `direction` says otherwise.\n */\n rank(\n metric: string,\n options?: { within?: string[]; direction?: SortDirection },\n ): 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 total: (metric, ...within) => ({\n type: DerivedExpressionType.TOTAL,\n metric,\n ...(within.length > 0 && { within }),\n }),\n running: (metric, order, options = {}) => ({\n type: DerivedExpressionType.RUNNING,\n metric,\n order,\n ...options,\n }),\n previous: (metric, along, options = {}) => ({\n type: DerivedExpressionType.PREVIOUS,\n metric,\n along,\n ...options,\n }),\n rank: (metric, options = {}) => ({\n type: DerivedExpressionType.RANK,\n metric,\n ...options,\n }),\n};\n"],"mappings":"A,+BA+FA,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,EAC1D,OAAQ,EAAQ,GAAGC,KAAY,CAC7B,KAAMR,EAAAA,sBAAsB,MAC5B,SACA,GAAIQ,EAAO,OAAS,GAAK,CAAE,QAAO,CACpC,GACA,SAAU,EAAQ,EAAO,EAAU,CAAC,KAAO,CACzC,KAAMR,EAAAA,sBAAsB,QAC5B,SACA,QACA,GAAGS,CACL,GACA,UAAW,EAAQ,EAAO,EAAU,CAAC,KAAO,CAC1C,KAAMT,EAAAA,sBAAsB,SAC5B,SACA,QACA,GAAGS,CACL,GACA,MAAO,EAAQ,EAAU,CAAC,KAAO,CAC/B,KAAMT,EAAAA,sBAAsB,KAC5B,SACA,GAAGS,CACL,EACF,E"}
|
|
@@ -14,30 +14,30 @@ import { AggregationDateUnit, DerivedExpression, RunningFunction } from './types
|
|
|
14
14
|
* metric aggregates over, which name fields, not metrics.
|
|
15
15
|
*/
|
|
16
16
|
export interface DerivedExpressionDsl {
|
|
17
|
-
/** The value of another metric of the row. `{ type: '
|
|
17
|
+
/** The value of another metric of the row. `{ type: 'metric-ref', metric }`. */
|
|
18
18
|
ref(metric: string): DerivedExpression;
|
|
19
19
|
/**
|
|
20
|
-
* A number. `{ type: '
|
|
20
|
+
* A number. `{ type: 'constant', value }`.
|
|
21
21
|
*
|
|
22
22
|
* @throws TypeError when `value` is not finite.
|
|
23
23
|
*/
|
|
24
24
|
constant(value: number): DerivedExpression;
|
|
25
|
-
/** `left + right`. `{ type: '
|
|
25
|
+
/** `left + right`. `{ type: 'binary', operator: 'add', left, right }`. */
|
|
26
26
|
add(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
|
|
27
|
-
/** `left - right`. `{ type: '
|
|
27
|
+
/** `left - right`. `{ type: 'binary', operator: 'subtract', left, right }`. */
|
|
28
28
|
subtract(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
|
|
29
|
-
/** `left * right`. `{ type: '
|
|
29
|
+
/** `left * right`. `{ type: 'binary', operator: 'multiply', left, right }`. */
|
|
30
30
|
multiply(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
|
|
31
|
-
/** `left / right`. `{ type: '
|
|
31
|
+
/** `left / right`. `{ type: 'binary', operator: 'divide', left, right }`. */
|
|
32
32
|
divide(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
|
|
33
33
|
/**
|
|
34
34
|
* `metric` summed over the groups sharing this group's `within` keys.
|
|
35
|
-
* `{ type: '
|
|
35
|
+
* `{ type: 'total', metric, within }`.
|
|
36
36
|
*/
|
|
37
37
|
total(metric: string, ...within: string[]): DerivedExpression;
|
|
38
38
|
/**
|
|
39
39
|
* `metric` accumulated along `order` within the groups sharing this group's
|
|
40
|
-
* `within` keys; with `frame` and `function: '
|
|
40
|
+
* `within` keys; with `frame` and `function: 'avg'`, a moving average.
|
|
41
41
|
*/
|
|
42
42
|
running(metric: string, order: FieldSort, options?: {
|
|
43
43
|
within?: string[];
|
|
@@ -14,30 +14,30 @@ import { AggregationDateUnit, DerivedExpression, RunningFunction } from './types
|
|
|
14
14
|
* metric aggregates over, which name fields, not metrics.
|
|
15
15
|
*/
|
|
16
16
|
export interface DerivedExpressionDsl {
|
|
17
|
-
/** The value of another metric of the row. `{ type: '
|
|
17
|
+
/** The value of another metric of the row. `{ type: 'metric-ref', metric }`. */
|
|
18
18
|
ref(metric: string): DerivedExpression;
|
|
19
19
|
/**
|
|
20
|
-
* A number. `{ type: '
|
|
20
|
+
* A number. `{ type: 'constant', value }`.
|
|
21
21
|
*
|
|
22
22
|
* @throws TypeError when `value` is not finite.
|
|
23
23
|
*/
|
|
24
24
|
constant(value: number): DerivedExpression;
|
|
25
|
-
/** `left + right`. `{ type: '
|
|
25
|
+
/** `left + right`. `{ type: 'binary', operator: 'add', left, right }`. */
|
|
26
26
|
add(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
|
|
27
|
-
/** `left - right`. `{ type: '
|
|
27
|
+
/** `left - right`. `{ type: 'binary', operator: 'subtract', left, right }`. */
|
|
28
28
|
subtract(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
|
|
29
|
-
/** `left * right`. `{ type: '
|
|
29
|
+
/** `left * right`. `{ type: 'binary', operator: 'multiply', left, right }`. */
|
|
30
30
|
multiply(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
|
|
31
|
-
/** `left / right`. `{ type: '
|
|
31
|
+
/** `left / right`. `{ type: 'binary', operator: 'divide', left, right }`. */
|
|
32
32
|
divide(left: DerivedExpression, right: DerivedExpression): DerivedExpression;
|
|
33
33
|
/**
|
|
34
34
|
* `metric` summed over the groups sharing this group's `within` keys.
|
|
35
|
-
* `{ type: '
|
|
35
|
+
* `{ type: 'total', metric, within }`.
|
|
36
36
|
*/
|
|
37
37
|
total(metric: string, ...within: string[]): DerivedExpression;
|
|
38
38
|
/**
|
|
39
39
|
* `metric` accumulated along `order` within the groups sharing this group's
|
|
40
|
-
* `within` keys; with `frame` and `function: '
|
|
40
|
+
* `within` keys; with `frame` and `function: 'avg'`, a moving average.
|
|
41
41
|
*/
|
|
42
42
|
running(metric: string, order: FieldSort, options?: {
|
|
43
43
|
within?: string[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AggregationExpressionOperator as e, DerivedExpressionType as t } from "./types.es.js";
|
|
2
|
-
|
|
2
|
+
// src/dsl/aggregation/derived.ts
|
|
3
3
|
function n(e, n, r) {
|
|
4
4
|
return {
|
|
5
5
|
type: t.BINARY,
|
|
@@ -47,7 +47,6 @@ var r = {
|
|
|
47
47
|
...n
|
|
48
48
|
})
|
|
49
49
|
};
|
|
50
|
-
//#endregion
|
|
51
50
|
export { r as derivedExpressionDsl };
|
|
52
51
|
|
|
53
52
|
//# sourceMappingURL=derived.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derived.es.js","names":["binary","DerivedExpressionType","derivedExpressionDsl","value","AggregationExpressionOperator","left","right","within","options"],"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 type { FieldSort, SortDirection } from '../sort.js';\nimport {\n AggregationExpressionOperator,\n DerivedExpressionType,\n type AggregationDateUnit,\n type DerivedExpression,\n type RunningFunction,\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: '
|
|
1
|
+
{"version":3,"file":"derived.es.js","names":["binary","DerivedExpressionType","derivedExpressionDsl","value","AggregationExpressionOperator","left","right","within","options"],"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 type { FieldSort, SortDirection } from '../sort.js';\nimport {\n AggregationExpressionOperator,\n DerivedExpressionType,\n type AggregationDateUnit,\n type DerivedExpression,\n type RunningFunction,\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 * `metric` summed over the groups sharing this group's `within` keys.\n * `{ type: 'total', metric, within }`.\n */\n total(metric: string, ...within: string[]): DerivedExpression;\n /**\n * `metric` accumulated along `order` within the groups sharing this group's\n * `within` keys; with `frame` and `function: 'avg'`, a moving average.\n */\n running(\n metric: string,\n order: FieldSort,\n options?: {\n within?: string[];\n frame?: number;\n function?: RunningFunction;\n },\n ): DerivedExpression;\n /**\n * `metric` of the group `shift` buckets (or `period`s) earlier along the\n * `DATE_HISTOGRAM` group `along`.\n */\n previous(\n metric: string,\n along: string,\n options?: { shift?: number; period?: AggregationDateUnit },\n ): DerivedExpression;\n /**\n * The dense rank of `metric` among the groups sharing this group's\n * `within` keys, `DESC` unless `direction` says otherwise.\n */\n rank(\n metric: string,\n options?: { within?: string[]; direction?: SortDirection },\n ): 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 total: (metric, ...within) => ({\n type: DerivedExpressionType.TOTAL,\n metric,\n ...(within.length > 0 && { within }),\n }),\n running: (metric, order, options = {}) => ({\n type: DerivedExpressionType.RUNNING,\n metric,\n order,\n ...options,\n }),\n previous: (metric, along, options = {}) => ({\n type: DerivedExpressionType.PREVIOUS,\n metric,\n along,\n ...options,\n }),\n rank: (metric, options = {}) => ({\n type: DerivedExpressionType.RANK,\n metric,\n ...options,\n }),\n};\n"],"mappings":";;AA+FA,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;CAC1D,QAAQ,GAAQ,GAAGC,OAAY;EAC7B,MAAMN,EAAsB;EAC5B;EACA,GAAIM,EAAO,SAAS,KAAK,EAAE,UAAO;CACpC;CACA,UAAU,GAAQ,GAAO,IAAU,CAAC,OAAO;EACzC,MAAMN,EAAsB;EAC5B;EACA;EACA,GAAGO;CACL;CACA,WAAW,GAAQ,GAAO,IAAU,CAAC,OAAO;EAC1C,MAAMP,EAAsB;EAC5B;EACA;EACA,GAAGO;CACL;CACA,OAAO,GAAQ,IAAU,CAAC,OAAO;EAC/B,MAAMP,EAAsB;EAC5B;EACA,GAAGO;CACL;AACF"}
|
|
@@ -1 +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":"
|
|
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":"A,+BA8BA,SAAgBI,EACd,EACM,CACN,IAAMC,EAAUC,EAAY,IAAI,IAAe,CAAE,aAAY,MAAO,CAAE,EAAE,EACpEC,EAAQ,EACZ,KAAOF,EAAQ,OAAS,GAAG,CACzB,GAAM,CAAE,aAAY,SAAUA,EAAQ,IAAI,EAC1C,GAAIG,EAAQR,EAAAA,mBAAmB,qBAC7B,MAAU,UACR,gDAAgDA,EAAAA,mBAAmB,qBAAqB,EAC1F,EAGF,GADA,IACIO,EAAQP,EAAAA,mBAAmB,qBAC7B,MAAU,UACR,gDAAgDA,EAAAA,mBAAmB,qBAAqB,QAC1F,EAEF,OAAQS,EAAW,KAAnB,CACE,KAAKR,EAAAA,0BAA0B,MAC7B,MAIF,KAAKA,EAAAA,0BAA0B,SAC7B,GAAI,CAAC,OAAO,SAASQ,EAAW,KAAK,EACnC,MAAU,UAAU,sCAAsC,EAE5D,MACF,KAAKR,EAAAA,0BAA0B,UAC7B,GAAI,CAAC,OAAO,OAAOC,EAAAA,YAAY,CAAC,CAAC,SAASO,EAAW,IAAI,EACvD,MAAU,UAAU,4BAA4B,EAElD,MACF,KAAKR,EAAAA,0BAA0B,OAC7BI,EAAQ,KAAK,CAAE,WAAYI,EAAW,KAAM,MAAOD,EAAQ,CAAE,CAAC,EAC9DH,EAAQ,KAAK,CAAE,WAAYI,EAAW,MAAO,MAAOD,EAAQ,CAAE,CAAC,EAC/D,MACF,QACE,MAAU,UACR,uCAAuC,OAAQC,EAAiC,IAAI,EAAE,EACxF,CACJ,CACF,CACF,CAGA,SAAgBC,EAAiB,EAA6C,CAC5E,OAAQD,EAAW,KAAnB,CACE,KAAKR,EAAAA,0BAA0B,MAC7B,MAAO,CAACQ,EAAW,KAAK,EAC1B,KAAKR,EAAAA,0BAA0B,UAC7B,MAAO,CAACQ,EAAW,KAAMA,EAAW,EAAE,EACxC,KAAKR,EAAAA,0BAA0B,OAC7B,MAAO,CACL,GAAGS,EAAiBD,EAAW,IAAI,EACnC,GAAGC,EAAiBD,EAAW,KAAK,CACtC,EACF,QACE,MAAO,CAAC,CACZ,CACF,C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AGGREGATION_LIMITS as e, AggregationExpressionType as t, DateDiffUnit as n } from "./types.es.js";
|
|
2
|
-
|
|
2
|
+
// src/dsl/aggregation/expressionTrees.ts
|
|
3
3
|
function r(r) {
|
|
4
4
|
let i = r.map((e) => ({
|
|
5
5
|
expression: e,
|
|
@@ -38,7 +38,6 @@ function i(e) {
|
|
|
38
38
|
default: return [];
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
//#endregion
|
|
42
41
|
export { i as expressionFields, r as requireValidExpressionTrees };
|
|
43
42
|
|
|
44
43
|
//# sourceMappingURL=expressionTrees.es.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./types.cjs");function
|
|
1
|
+
const e=require("../constantName.cjs"),t=require("./types.cjs");function n(e,n,r){if(!Number.isFinite(r))throw TypeError(`having condition [${n}] value must be finite.`);return{type:t.HavingExpressionType.CONDITION,metric:n,operator:e,value:r}}function r(t,n){let[r,...i]=n;if(r===void 0)throw TypeError(`having ${e.constantName(t)} operands must not be empty.`);return{type:t,operands:[r,...i]}}var i={eq:(e,r)=>n(t.ComparisonOperator.EQ,e,r),ne:(e,r)=>n(t.ComparisonOperator.NE,e,r),gt:(e,r)=>n(t.ComparisonOperator.GT,e,r),gte:(e,r)=>n(t.ComparisonOperator.GTE,e,r),lt:(e,r)=>n(t.ComparisonOperator.LT,e,r),lte:(e,r)=>n(t.ComparisonOperator.LTE,e,r),between(e,n,r){if(!Number.isFinite(n)||!Number.isFinite(r))throw TypeError(`having between [${e}] bounds must be finite.`);if(n>r)throw TypeError(`having between [${e}] lower bound must not exceed upper bound.`);return{type:t.HavingExpressionType.BETWEEN,metric:e,lower:n,upper:r}},isIn(e,n){let[r,...i]=n;if(r===void 0)throw TypeError(`having in [${e}] values must not be empty.`);if(!n.every(Number.isFinite))throw TypeError(`having in [${e}] values must be finite.`);return{type:t.HavingExpressionType.IN,metric:e,values:[r,...i]}},isNull:e=>({type:t.HavingExpressionType.IS_NULL,metric:e}),isNotNull:e=>({type:t.HavingExpressionType.IS_NULL,metric:e,negated:!0}),and:e=>r(t.HavingExpressionType.AND,e),or:e=>r(t.HavingExpressionType.OR,e)};exports.havingDsl=i;
|
|
2
2
|
//# sourceMappingURL=having.cjs.map
|
|
@@ -1 +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: '
|
|
1
|
+
{"version":3,"file":"having.cjs","names":["HavingExpressionType","constantName","ComparisonOperator","require_constantName","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 { constantName } from '../constantName.js';\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(\n `having ${constantName(type)} operands must not be empty.`,\n );\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":"A,gEAiHA,SAASK,EACP,EACA,EACA,EACkB,CAClB,GAAI,CAAC,OAAO,SAASC,CAAK,EACxB,MAAU,UAAU,qBAAqBC,EAAO,wBAAwB,EAE1E,MAAO,CAAE,KAAMP,EAAAA,qBAAqB,UAAW,SAAQ,WAAU,OAAM,CACzE,CAEA,SAASQ,EACP,EACA,EACkB,CAClB,GAAM,CAACC,EAAO,GAAGC,GAAQC,EACzB,GAAIF,IAAU,IAAA,GACZ,MAAU,UACR,UAAUR,EAAAA,aAAaW,CAAI,EAAE,6BAC/B,EAEF,MAAO,CAAE,OAAM,SAAU,CAACH,EAAO,GAAGC,CAAI,CAAE,CAC5C,CAEA,IAAaG,EAAuB,CAClC,IAAK,EAAQ,IAAUR,EAAUH,EAAAA,mBAAmB,GAAIK,EAAQD,CAAK,EACrE,IAAK,EAAQ,IAAUD,EAAUH,EAAAA,mBAAmB,GAAIK,EAAQD,CAAK,EACrE,IAAK,EAAQ,IAAUD,EAAUH,EAAAA,mBAAmB,GAAIK,EAAQD,CAAK,EACrE,KAAM,EAAQ,IAAUD,EAAUH,EAAAA,mBAAmB,IAAKK,EAAQD,CAAK,EACvE,IAAK,EAAQ,IAAUD,EAAUH,EAAAA,mBAAmB,GAAIK,EAAQD,CAAK,EACrE,KAAM,EAAQ,IAAUD,EAAUH,EAAAA,mBAAmB,IAAKK,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,KAAMP,EAAAA,qBAAqB,QAAS,SAAQ,QAAO,OAAM,CACpE,EACA,KAAK,EAAQ,EAAQ,CACnB,GAAM,CAACS,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,KAAMP,EAAAA,qBAAqB,GAAI,SAAQ,OAAQ,CAACS,EAAO,GAAGC,CAAI,CAAE,CAC3E,EACA,OAAQ,IAAW,CAAE,KAAMV,EAAAA,qBAAqB,QAAS,QAAO,GAChE,UAAW,IAAW,CACpB,KAAMA,EAAAA,qBAAqB,QAC3B,SACA,QAAS,EACX,GACA,IAAK,GAAYQ,EAAQR,EAAAA,qBAAqB,IAAKW,CAAQ,EAC3D,GAAI,GAAYH,EAAQR,EAAAA,qBAAqB,GAAIW,CAAQ,CAC3D,E"}
|
|
@@ -10,7 +10,7 @@ import { HavingExpression } from './types.cjs';
|
|
|
10
10
|
*/
|
|
11
11
|
export interface HavingDsl {
|
|
12
12
|
/**
|
|
13
|
-
* `metric = value`. `{ type: '
|
|
13
|
+
* `metric = value`. `{ type: 'condition', metric, operator: 'eq', value }`.
|
|
14
14
|
*
|
|
15
15
|
* @param metric - The alias of a metric of the same query.
|
|
16
16
|
* @throws TypeError when `value` is not finite.
|
|
@@ -20,10 +20,10 @@ export interface HavingDsl {
|
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
eq(metric: string, value: number): HavingExpression;
|
|
23
|
-
/** `metric ≠ value`. `{ type: '
|
|
23
|
+
/** `metric ≠ value`. `{ type: 'condition', operator: 'ne', … }`. */
|
|
24
24
|
ne(metric: string, value: number): HavingExpression;
|
|
25
25
|
/**
|
|
26
|
-
* `metric > value`. `{ type: '
|
|
26
|
+
* `metric > value`. `{ type: 'condition', operator: 'gt', … }`.
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* ```typescript
|
|
@@ -31,14 +31,14 @@ export interface HavingDsl {
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
gt(metric: string, value: number): HavingExpression;
|
|
34
|
-
/** `metric ≥ value`. `{ type: '
|
|
34
|
+
/** `metric ≥ value`. `{ type: 'condition', operator: 'gte', … }`. */
|
|
35
35
|
gte(metric: string, value: number): HavingExpression;
|
|
36
|
-
/** `metric < value`. `{ type: '
|
|
36
|
+
/** `metric < value`. `{ type: 'condition', operator: 'lt', … }`. */
|
|
37
37
|
lt(metric: string, value: number): HavingExpression;
|
|
38
|
-
/** `metric ≤ value`. `{ type: '
|
|
38
|
+
/** `metric ≤ value`. `{ type: 'condition', operator: 'lte', … }`. */
|
|
39
39
|
lte(metric: string, value: number): HavingExpression;
|
|
40
40
|
/**
|
|
41
|
-
* `lower ≤ metric ≤ upper`. `{ type: '
|
|
41
|
+
* `lower ≤ metric ≤ upper`. `{ type: 'between', metric, lower, upper }`.
|
|
42
42
|
*
|
|
43
43
|
* @throws TypeError when a bound is not finite, or `lower` exceeds `upper`.
|
|
44
44
|
* @example
|
|
@@ -48,7 +48,7 @@ export interface HavingDsl {
|
|
|
48
48
|
*/
|
|
49
49
|
between(metric: string, lower: number, upper: number): HavingExpression;
|
|
50
50
|
/**
|
|
51
|
-
* `metric` is one of `values`. `{ type: '
|
|
51
|
+
* `metric` is one of `values`. `{ type: 'in', metric, values }` with a
|
|
52
52
|
* copy of `values`.
|
|
53
53
|
*
|
|
54
54
|
* @throws TypeError when `values` is empty or holds a non-finite number.
|
|
@@ -59,7 +59,7 @@ export interface HavingDsl {
|
|
|
59
59
|
*/
|
|
60
60
|
isIn(metric: string, values: readonly number[]): HavingExpression;
|
|
61
61
|
/**
|
|
62
|
-
* `metric` has no value in the row. `{ type: '
|
|
62
|
+
* `metric` has no value in the row. `{ type: 'is-null', metric }`.
|
|
63
63
|
*
|
|
64
64
|
* @example
|
|
65
65
|
* ```typescript
|
|
@@ -67,10 +67,10 @@ export interface HavingDsl {
|
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
69
|
isNull(metric: string): HavingExpression;
|
|
70
|
-
/** `metric` has a value. `{ type: '
|
|
70
|
+
/** `metric` has a value. `{ type: 'is-null', metric, negated: true }`. */
|
|
71
71
|
isNotNull(metric: string): HavingExpression;
|
|
72
72
|
/**
|
|
73
|
-
* All of `operands` hold. `{ type: '
|
|
73
|
+
* All of `operands` hold. `{ type: 'and', operands }` with a copy of
|
|
74
74
|
* `operands`.
|
|
75
75
|
*
|
|
76
76
|
* @throws TypeError when `operands` is empty.
|
|
@@ -84,7 +84,7 @@ export interface HavingDsl {
|
|
|
84
84
|
*/
|
|
85
85
|
and(operands: readonly HavingExpression[]): HavingExpression;
|
|
86
86
|
/**
|
|
87
|
-
* At least one of `operands` holds. `{ type: '
|
|
87
|
+
* At least one of `operands` holds. `{ type: 'or', operands }` with a copy
|
|
88
88
|
* of `operands`.
|
|
89
89
|
*
|
|
90
90
|
* @throws TypeError when `operands` is empty.
|
|
@@ -10,7 +10,7 @@ import { HavingExpression } from './types.js';
|
|
|
10
10
|
*/
|
|
11
11
|
export interface HavingDsl {
|
|
12
12
|
/**
|
|
13
|
-
* `metric = value`. `{ type: '
|
|
13
|
+
* `metric = value`. `{ type: 'condition', metric, operator: 'eq', value }`.
|
|
14
14
|
*
|
|
15
15
|
* @param metric - The alias of a metric of the same query.
|
|
16
16
|
* @throws TypeError when `value` is not finite.
|
|
@@ -20,10 +20,10 @@ export interface HavingDsl {
|
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
eq(metric: string, value: number): HavingExpression;
|
|
23
|
-
/** `metric ≠ value`. `{ type: '
|
|
23
|
+
/** `metric ≠ value`. `{ type: 'condition', operator: 'ne', … }`. */
|
|
24
24
|
ne(metric: string, value: number): HavingExpression;
|
|
25
25
|
/**
|
|
26
|
-
* `metric > value`. `{ type: '
|
|
26
|
+
* `metric > value`. `{ type: 'condition', operator: 'gt', … }`.
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* ```typescript
|
|
@@ -31,14 +31,14 @@ export interface HavingDsl {
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
gt(metric: string, value: number): HavingExpression;
|
|
34
|
-
/** `metric ≥ value`. `{ type: '
|
|
34
|
+
/** `metric ≥ value`. `{ type: 'condition', operator: 'gte', … }`. */
|
|
35
35
|
gte(metric: string, value: number): HavingExpression;
|
|
36
|
-
/** `metric < value`. `{ type: '
|
|
36
|
+
/** `metric < value`. `{ type: 'condition', operator: 'lt', … }`. */
|
|
37
37
|
lt(metric: string, value: number): HavingExpression;
|
|
38
|
-
/** `metric ≤ value`. `{ type: '
|
|
38
|
+
/** `metric ≤ value`. `{ type: 'condition', operator: 'lte', … }`. */
|
|
39
39
|
lte(metric: string, value: number): HavingExpression;
|
|
40
40
|
/**
|
|
41
|
-
* `lower ≤ metric ≤ upper`. `{ type: '
|
|
41
|
+
* `lower ≤ metric ≤ upper`. `{ type: 'between', metric, lower, upper }`.
|
|
42
42
|
*
|
|
43
43
|
* @throws TypeError when a bound is not finite, or `lower` exceeds `upper`.
|
|
44
44
|
* @example
|
|
@@ -48,7 +48,7 @@ export interface HavingDsl {
|
|
|
48
48
|
*/
|
|
49
49
|
between(metric: string, lower: number, upper: number): HavingExpression;
|
|
50
50
|
/**
|
|
51
|
-
* `metric` is one of `values`. `{ type: '
|
|
51
|
+
* `metric` is one of `values`. `{ type: 'in', metric, values }` with a
|
|
52
52
|
* copy of `values`.
|
|
53
53
|
*
|
|
54
54
|
* @throws TypeError when `values` is empty or holds a non-finite number.
|
|
@@ -59,7 +59,7 @@ export interface HavingDsl {
|
|
|
59
59
|
*/
|
|
60
60
|
isIn(metric: string, values: readonly number[]): HavingExpression;
|
|
61
61
|
/**
|
|
62
|
-
* `metric` has no value in the row. `{ type: '
|
|
62
|
+
* `metric` has no value in the row. `{ type: 'is-null', metric }`.
|
|
63
63
|
*
|
|
64
64
|
* @example
|
|
65
65
|
* ```typescript
|
|
@@ -67,10 +67,10 @@ export interface HavingDsl {
|
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
69
|
isNull(metric: string): HavingExpression;
|
|
70
|
-
/** `metric` has a value. `{ type: '
|
|
70
|
+
/** `metric` has a value. `{ type: 'is-null', metric, negated: true }`. */
|
|
71
71
|
isNotNull(metric: string): HavingExpression;
|
|
72
72
|
/**
|
|
73
|
-
* All of `operands` hold. `{ type: '
|
|
73
|
+
* All of `operands` hold. `{ type: 'and', operands }` with a copy of
|
|
74
74
|
* `operands`.
|
|
75
75
|
*
|
|
76
76
|
* @throws TypeError when `operands` is empty.
|
|
@@ -84,7 +84,7 @@ export interface HavingDsl {
|
|
|
84
84
|
*/
|
|
85
85
|
and(operands: readonly HavingExpression[]): HavingExpression;
|
|
86
86
|
/**
|
|
87
|
-
* At least one of `operands` holds. `{ type: '
|
|
87
|
+
* At least one of `operands` holds. `{ type: 'or', operands }` with a copy
|
|
88
88
|
* of `operands`.
|
|
89
89
|
*
|
|
90
90
|
* @throws TypeError when `operands` is empty.
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { constantName as e } from "../constantName.es.js";
|
|
2
|
+
import { ComparisonOperator as t, HavingExpressionType as n } from "./types.es.js";
|
|
3
|
+
// src/dsl/aggregation/having.ts
|
|
4
|
+
function r(e, t, r) {
|
|
5
|
+
if (!Number.isFinite(r)) throw TypeError(`having condition [${t}] value must be finite.`);
|
|
5
6
|
return {
|
|
6
|
-
type:
|
|
7
|
-
metric:
|
|
7
|
+
type: n.CONDITION,
|
|
8
|
+
metric: t,
|
|
8
9
|
operator: e,
|
|
9
10
|
value: r
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
-
let [
|
|
14
|
-
if (
|
|
13
|
+
function i(t, n) {
|
|
14
|
+
let [r, ...i] = n;
|
|
15
|
+
if (r === void 0) throw TypeError(`having ${e(t)} operands must not be empty.`);
|
|
15
16
|
return {
|
|
16
|
-
type:
|
|
17
|
-
operands: [
|
|
17
|
+
type: t,
|
|
18
|
+
operands: [r, ...i]
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
|
-
var
|
|
21
|
-
eq: (
|
|
22
|
-
ne: (
|
|
23
|
-
gt: (
|
|
24
|
-
gte: (
|
|
25
|
-
lt: (
|
|
26
|
-
lte: (
|
|
27
|
-
between(e,
|
|
28
|
-
if (!Number.isFinite(
|
|
29
|
-
if (
|
|
21
|
+
var a = {
|
|
22
|
+
eq: (e, n) => r(t.EQ, e, n),
|
|
23
|
+
ne: (e, n) => r(t.NE, e, n),
|
|
24
|
+
gt: (e, n) => r(t.GT, e, n),
|
|
25
|
+
gte: (e, n) => r(t.GTE, e, n),
|
|
26
|
+
lt: (e, n) => r(t.LT, e, n),
|
|
27
|
+
lte: (e, n) => r(t.LTE, e, n),
|
|
28
|
+
between(e, t, r) {
|
|
29
|
+
if (!Number.isFinite(t) || !Number.isFinite(r)) throw TypeError(`having between [${e}] bounds must be finite.`);
|
|
30
|
+
if (t > r) throw TypeError(`having between [${e}] lower bound must not exceed upper bound.`);
|
|
30
31
|
return {
|
|
31
|
-
type:
|
|
32
|
+
type: n.BETWEEN,
|
|
32
33
|
metric: e,
|
|
33
|
-
lower:
|
|
34
|
+
lower: t,
|
|
34
35
|
upper: r
|
|
35
36
|
};
|
|
36
37
|
},
|
|
37
|
-
isIn(e,
|
|
38
|
-
let [r, ...i] =
|
|
38
|
+
isIn(e, t) {
|
|
39
|
+
let [r, ...i] = t;
|
|
39
40
|
if (r === void 0) throw TypeError(`having in [${e}] values must not be empty.`);
|
|
40
|
-
if (!
|
|
41
|
+
if (!t.every(Number.isFinite)) throw TypeError(`having in [${e}] values must be finite.`);
|
|
41
42
|
return {
|
|
42
|
-
type:
|
|
43
|
+
type: n.IN,
|
|
43
44
|
metric: e,
|
|
44
45
|
values: [r, ...i]
|
|
45
46
|
};
|
|
46
47
|
},
|
|
47
48
|
isNull: (e) => ({
|
|
48
|
-
type:
|
|
49
|
+
type: n.IS_NULL,
|
|
49
50
|
metric: e
|
|
50
51
|
}),
|
|
51
52
|
isNotNull: (e) => ({
|
|
52
|
-
type:
|
|
53
|
+
type: n.IS_NULL,
|
|
53
54
|
metric: e,
|
|
54
55
|
negated: !0
|
|
55
56
|
}),
|
|
56
|
-
and: (e) =>
|
|
57
|
-
or: (e) =>
|
|
57
|
+
and: (e) => i(n.AND, e),
|
|
58
|
+
or: (e) => i(n.OR, e)
|
|
58
59
|
};
|
|
59
|
-
|
|
60
|
-
export { i as havingDsl };
|
|
60
|
+
export { a as havingDsl };
|
|
61
61
|
|
|
62
62
|
//# sourceMappingURL=having.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"having.es.js","names":["condition","value","metric","HavingExpressionType","logical","first","rest","operands","type","havingDsl","ComparisonOperator","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: '
|
|
1
|
+
{"version":3,"file":"having.es.js","names":["condition","value","metric","HavingExpressionType","logical","first","rest","operands","constantName","type","havingDsl","ComparisonOperator","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 { constantName } from '../constantName.js';\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(\n `having ${constantName(type)} operands must not be empty.`,\n );\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":";;;AAiHA,SAASA,EACP,GACA,GACA,GACkB;CAClB,IAAI,CAAC,OAAO,SAASC,CAAK,GACxB,MAAU,UAAU,qBAAqBC,EAAO,wBAAwB;CAE1E,OAAO;EAAE,MAAMC,EAAqB;EAAW;EAAQ;EAAU;CAAM;AACzE;AAEA,SAASC,EACP,GACA,GACkB;CAClB,IAAM,CAACC,GAAO,GAAGC,KAAQC;CACzB,IAAIF,MAAU,KAAA,GACZ,MAAU,UACR,UAAUG,EAAaC,CAAI,EAAE,6BAC/B;CAEF,OAAO;EAAE;EAAM,UAAU,CAACJ,GAAO,GAAGC,CAAI;CAAE;AAC5C;AAEA,IAAaI,IAAuB;CAClC,KAAK,GAAQ,MAAUV,EAAUW,EAAmB,IAAIT,GAAQD,CAAK;CACrE,KAAK,GAAQ,MAAUD,EAAUW,EAAmB,IAAIT,GAAQD,CAAK;CACrE,KAAK,GAAQ,MAAUD,EAAUW,EAAmB,IAAIT,GAAQD,CAAK;CACrE,MAAM,GAAQ,MAAUD,EAAUW,EAAmB,KAAKT,GAAQD,CAAK;CACvE,KAAK,GAAQ,MAAUD,EAAUW,EAAmB,IAAIT,GAAQD,CAAK;CACrE,MAAM,GAAQ,MAAUD,EAAUW,EAAmB,KAAKT,GAAQD,CAAK;CACvE,QAAQ,GAAQ,GAAO,GAAO;EAC5B,IAAI,CAAC,OAAO,SAASW,CAAK,KAAK,CAAC,OAAO,SAASC,CAAK,GACnD,MAAU,UAAU,mBAAmBX,EAAO,yBAAyB;EAEzE,IAAIU,IAAQC,GACV,MAAU,UACR,mBAAmBX,EAAO,2CAC5B;EAEF,OAAO;GAAE,MAAMC,EAAqB;GAAS;GAAQ;GAAO;EAAM;CACpE;CACA,KAAK,GAAQ,GAAQ;EACnB,IAAM,CAACE,GAAO,GAAGC,KAAQQ;EACzB,IAAIT,MAAU,KAAA,GACZ,MAAU,UAAU,cAAcH,EAAO,4BAA4B;EAEvE,IAAI,CAACY,EAAO,MAAM,OAAO,QAAQ,GAC/B,MAAU,UAAU,cAAcZ,EAAO,yBAAyB;EAEpE,OAAO;GAAE,MAAMC,EAAqB;GAAI;GAAQ,QAAQ,CAACE,GAAO,GAAGC,CAAI;EAAE;CAC3E;CACA,SAAQ,OAAW;EAAE,MAAMH,EAAqB;EAAS;CAAO;CAChE,YAAW,OAAW;EACpB,MAAMA,EAAqB;EAC3B;EACA,SAAS;CACX;CACA,MAAK,MAAYC,EAAQD,EAAqB,KAAKI,CAAQ;CAC3D,KAAI,MAAYH,EAAQD,EAAqB,IAAII,CAAQ;AAC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort.cjs","names":["asc","require_sort","effectiveSort","sort","query","sorted","entry","group","alias"],"sources":["../../../src/dsl/aggregation/sort.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\n// Internal: not re-exported by dsl/aggregation/index.ts.\nimport type { AggregationQuery } from './types.js';\nimport { asc, type FieldSort } from '../sort.js';\n\n/**\n * The sort Wow actually applies: what the query asked for, then each remaining\n * group ascending, so a page of grouped rows has one stable order.\n */\nexport function effectiveSort<FIELDS extends string = string>(\n query: Pick<AggregationQuery<string, FIELDS>, 'groupBy' | 'sort'>,\n): FieldSort[] {\n const sort = [...(query.sort ?? [])];\n const sorted = new Set(sort.map(entry => entry.field));\n return [\n ...sort,\n ...(query.groupBy ?? [])\n .map(group => group.alias)\n .filter(alias => !sorted.has(alias))\n .map(asc),\n ];\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"sort.cjs","names":["asc","require_sort","effectiveSort","sort","query","sorted","entry","group","alias"],"sources":["../../../src/dsl/aggregation/sort.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\n// Internal: not re-exported by dsl/aggregation/index.ts.\nimport type { AggregationQuery } from './types.js';\nimport { asc, type FieldSort } from '../sort.js';\n\n/**\n * The sort Wow actually applies: what the query asked for, then each remaining\n * group ascending, so a page of grouped rows has one stable order.\n */\nexport function effectiveSort<FIELDS extends string = string>(\n query: Pick<AggregationQuery<string, FIELDS>, 'groupBy' | 'sort'>,\n): FieldSort[] {\n const sort = [...(query.sort ?? [])];\n const sorted = new Set(sort.map(entry => entry.field));\n return [\n ...sort,\n ...(query.groupBy ?? [])\n .map(group => group.alias)\n .filter(alias => !sorted.has(alias))\n .map(asc),\n ];\n}\n"],"mappings":"A,+BAqBA,SAAgBE,EACd,EACa,CACb,IAAMC,EAAO,CAAC,GAAIC,EAAM,MAAQ,CAAC,CAAE,EAC7BC,EAAS,IAAI,IAAIF,EAAK,IAAI,GAASG,EAAM,KAAK,CAAC,EACrD,MAAO,CACL,GAAGH,EACH,IAAIC,EAAM,SAAW,CAAC,EAAA,CACnB,IAAI,GAASG,EAAM,KAAK,CAAC,CACzB,OAAO,GAAS,CAACF,EAAO,IAAIG,CAAK,CAAC,CAAC,CACnC,IAAIR,EAAAA,GAAG,CACZ,CACF,C"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { asc as e } from "../sort.es.js";
|
|
2
|
-
|
|
2
|
+
// src/dsl/aggregation/sort.ts
|
|
3
3
|
function t(t) {
|
|
4
4
|
let n = [...t.sort ?? []], r = new Set(n.map((e) => e.field));
|
|
5
5
|
return [...n, ...(t.groupBy ?? []).map((e) => e.alias).filter((e) => !r.has(e)).map(e)];
|
|
6
6
|
}
|
|
7
|
-
//#endregion
|
|
8
7
|
export { t as effectiveSort };
|
|
9
8
|
|
|
10
9
|
//# sourceMappingURL=sort.es.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=function(e){return e.TERMS=`
|
|
1
|
+
var e=function(e){return e.TERMS=`terms`,e.HISTOGRAM=`histogram`,e.DATE_HISTOGRAM=`date-histogram`,e.DATE_PART=`date-part`,e}({}),t=function(e){return e.ELEMENT=`element`,e.ROOT=`root`,e}({}),n=function(e){return e.COUNT=`count`,e.NUMERIC=`numeric`,e.ANY=`any`,e.DISTINCT_COUNT=`distinct-count`,e.PERCENTILE=`percentile`,e.DERIVED=`derived`,e.FIRST=`first`,e.LAST=`last`,e}({}),r=function(e){return e.FIELD=`field`,e.CONSTANT=`constant`,e.BINARY=`binary`,e.DATE_DIFF=`date-diff`,e}({}),i=function(e){return e.SECOND=`second`,e.MINUTE=`minute`,e.HOUR=`hour`,e.DAY=`day`,e}({}),a=function(e){return e.ADD=`add`,e.SUBTRACT=`subtract`,e.MULTIPLY=`multiply`,e.DIVIDE=`divide`,e}({}),o=function(e){return e.YEAR=`year`,e.QUARTER=`quarter`,e.MONTH=`month`,e.WEEK=`week`,e.DAY=`day`,e.HOUR=`hour`,e.MINUTE=`minute`,e.SECOND=`second`,e}({}),s=function(e){return e.DAY_OF_WEEK=`day-of-week`,e.DAY_OF_MONTH=`day-of-month`,e.HOUR_OF_DAY=`hour-of-day`,e.MONTH_OF_YEAR=`month-of-year`,e}({}),c=function(e){return e.SUM=`sum`,e.AVG=`avg`,e.MIN=`min`,e.MAX=`max`,e.STDDEV=`stddev`,e.VARIANCE=`variance`,e}({}),l=function(e){return e.METRIC_REF=`metric-ref`,e.CONSTANT=`constant`,e.BINARY=`binary`,e.TOTAL=`total`,e.RUNNING=`running`,e.PREVIOUS=`previous`,e.RANK=`rank`,e}({}),u=function(e){return e.TOTAL=`total`,e.RUNNING=`running`,e.PREVIOUS=`previous`,e.RANK=`rank`,e}({}),d=function(e){return e.SUM=`sum`,e.AVG=`avg`,e}({}),f=function(e){return e.CONDITION=`condition`,e.BETWEEN=`between`,e.IN=`in`,e.IS_NULL=`is-null`,e.AND=`and`,e.OR=`or`,e}({}),p=function(e){return e.EQ=`eq`,e.NE=`ne`,e.GT=`gt`,e.GTE=`gte`,e.LT=`lt`,e.LTE=`lte`,e}({}),m=Object.freeze({DEFAULT_LIMIT:100,MAX_LIMIT:1e4,MAX_ELEMENTS:5,MAX_GROUPS:32,MAX_METRICS:64,MAX_SORT_FIELDS:32,MAX_EXPRESSION_DEPTH:8,MAX_EXPRESSION_NODES:256,MAX_WINDOWS:8});exports.AGGREGATION_LIMITS=m,exports.AggregationDatePart=s,exports.AggregationDateUnit=o,exports.AggregationExpressionOperator=a,exports.AggregationExpressionType=r,exports.AggregationFunction=c,exports.AggregationGroupScope=t,exports.AggregationGroupType=e,exports.AggregationMetricType=n,exports.ComparisonOperator=p,exports.DateDiffUnit=i,exports.DerivedExpressionType=l,exports.HavingExpressionType=f,exports.RunningFunction=d,exports.WindowFunction=u;
|
|
2
2
|
//# sourceMappingURL=types.cjs.map
|