@ahoo-wang/wow-client 10.0.0-beta.1 → 10.0.0-beta.3
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 +4 -2
- package/README.zh-CN.md +1 -1
- package/dist/commands.cjs +1 -1
- package/dist/commands.cjs.map +1 -1
- package/dist/commands.d.cts +1 -8
- package/dist/commands.d.ts +1 -8
- package/dist/commands.es.js +45 -51
- package/dist/commands.es.js.map +1 -1
- package/dist/dsl/aggregation/admit.cjs +1 -1
- package/dist/dsl/aggregation/admit.cjs.map +1 -1
- package/dist/dsl/aggregation/admit.es.js +73 -69
- package/dist/dsl/aggregation/admit.es.js.map +1 -1
- package/dist/dsl/aggregation/aliases.cjs +2 -0
- package/dist/dsl/aggregation/aliases.cjs.map +1 -0
- package/dist/dsl/aggregation/aliases.d.cts +2 -0
- package/dist/dsl/aggregation/aliases.d.ts +2 -0
- package/dist/dsl/aggregation/aliases.es.js +13 -0
- package/dist/dsl/aggregation/aliases.es.js.map +1 -0
- package/dist/dsl/aggregation/builders.cjs +1 -1
- package/dist/dsl/aggregation/builders.cjs.map +1 -1
- package/dist/dsl/aggregation/builders.d.cts +17 -243
- package/dist/dsl/aggregation/builders.d.ts +17 -243
- package/dist/dsl/aggregation/builders.es.js +36 -171
- package/dist/dsl/aggregation/builders.es.js.map +1 -1
- package/dist/dsl/aggregation/derived.cjs +1 -1
- package/dist/dsl/aggregation/derived.cjs.map +1 -1
- package/dist/dsl/aggregation/derived.d.cts +123 -1
- package/dist/dsl/aggregation/derived.d.ts +123 -1
- package/dist/dsl/aggregation/derived.es.js +43 -28
- package/dist/dsl/aggregation/derived.es.js.map +1 -1
- package/dist/dsl/aggregation/groups.cjs +2 -0
- package/dist/dsl/aggregation/groups.cjs.map +1 -0
- package/dist/dsl/aggregation/groups.d.cts +325 -0
- package/dist/dsl/aggregation/groups.d.ts +325 -0
- package/dist/dsl/aggregation/groups.es.js +80 -0
- package/dist/dsl/aggregation/groups.es.js.map +1 -0
- package/dist/dsl/aggregation/having.cjs +1 -1
- package/dist/dsl/aggregation/having.cjs.map +1 -1
- package/dist/dsl/aggregation/having.d.cts +63 -1
- package/dist/dsl/aggregation/having.d.ts +63 -1
- package/dist/dsl/aggregation/having.es.js +33 -30
- package/dist/dsl/aggregation/having.es.js.map +1 -1
- package/dist/dsl/aggregation/index.d.cts +4 -2
- package/dist/dsl/aggregation/index.d.ts +4 -2
- package/dist/dsl/aggregation/metrics.cjs +2 -0
- package/dist/dsl/aggregation/metrics.cjs.map +1 -0
- package/dist/dsl/aggregation/metrics.d.cts +279 -0
- package/dist/dsl/aggregation/metrics.d.ts +279 -0
- package/dist/dsl/aggregation/metrics.es.js +75 -0
- package/dist/dsl/aggregation/metrics.es.js.map +1 -0
- package/dist/dsl/aggregation/types.cjs +1 -1
- package/dist/dsl/aggregation/types.cjs.map +1 -1
- package/dist/dsl/aggregation/types.d.cts +4 -524
- package/dist/dsl/aggregation/types.d.ts +4 -524
- package/dist/dsl/aggregation/types.es.js +5 -25
- package/dist/dsl/aggregation/types.es.js.map +1 -1
- package/dist/dsl/cursorQuery.cjs +1 -1
- package/dist/dsl/cursorQuery.cjs.map +1 -1
- package/dist/dsl/cursorQuery.d.cts +18 -7
- package/dist/dsl/cursorQuery.d.ts +18 -7
- package/dist/dsl/cursorQuery.es.js +13 -12
- package/dist/dsl/cursorQuery.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 +17 -379
- package/dist/dsl/descriptor.d.ts +17 -379
- package/dist/dsl/descriptor.es.js +4 -31
- package/dist/dsl/descriptor.es.js.map +1 -1
- package/dist/dsl/fieldDescriptor.cjs +2 -0
- package/dist/dsl/fieldDescriptor.cjs.map +1 -0
- package/dist/dsl/fieldDescriptor.d.cts +246 -0
- package/dist/dsl/fieldDescriptor.d.ts +246 -0
- package/dist/dsl/fieldDescriptor.es.js +24 -0
- package/dist/dsl/fieldDescriptor.es.js.map +1 -0
- package/dist/dsl/filter/builders.cjs +1 -1
- package/dist/dsl/filter/builders.cjs.map +1 -1
- package/dist/dsl/filter/builders.d.cts +7 -949
- package/dist/dsl/filter/builders.d.ts +7 -949
- package/dist/dsl/filter/builders.es.js +14 -285
- package/dist/dsl/filter/builders.es.js.map +1 -1
- package/dist/dsl/filter/expressionFilter.cjs +2 -0
- package/dist/dsl/filter/expressionFilter.cjs.map +1 -0
- package/dist/dsl/filter/expressionFilter.d.cts +35 -0
- package/dist/dsl/filter/expressionFilter.d.ts +35 -0
- package/dist/dsl/filter/expressionFilter.es.js +18 -0
- package/dist/dsl/filter/expressionFilter.es.js.map +1 -0
- package/dist/dsl/filter/fieldFilters.cjs +2 -0
- package/dist/dsl/filter/fieldFilters.cjs.map +1 -0
- package/dist/dsl/filter/fieldFilters.d.cts +297 -0
- package/dist/dsl/filter/fieldFilters.d.ts +297 -0
- package/dist/dsl/filter/fieldFilters.es.js +110 -0
- package/dist/dsl/filter/fieldFilters.es.js.map +1 -0
- package/dist/dsl/filter/index.d.cts +2 -1
- package/dist/dsl/filter/index.d.ts +2 -1
- package/dist/dsl/filter/logicalFilters.cjs +2 -0
- package/dist/dsl/filter/logicalFilters.cjs.map +1 -0
- package/dist/dsl/filter/logicalFilters.d.cts +109 -0
- package/dist/dsl/filter/logicalFilters.d.ts +109 -0
- package/dist/dsl/filter/logicalFilters.es.js +36 -0
- package/dist/dsl/filter/logicalFilters.es.js.map +1 -0
- package/dist/dsl/filter/metadataFilters.cjs +2 -0
- package/dist/dsl/filter/metadataFilters.cjs.map +1 -0
- package/dist/dsl/filter/metadataFilters.d.cts +132 -0
- package/dist/dsl/filter/metadataFilters.d.ts +132 -0
- package/dist/dsl/filter/metadataFilters.es.js +56 -0
- package/dist/dsl/filter/metadataFilters.es.js.map +1 -0
- package/dist/dsl/filter/operator.cjs +1 -1
- package/dist/dsl/filter/operator.cjs.map +1 -1
- package/dist/dsl/filter/operator.d.cts +11 -9
- package/dist/dsl/filter/operator.d.ts +11 -9
- package/dist/dsl/filter/operator.es.js +1 -1
- package/dist/dsl/filter/operator.es.js.map +1 -1
- package/dist/dsl/filter/searchFilter.cjs +2 -0
- package/dist/dsl/filter/searchFilter.cjs.map +1 -0
- package/dist/dsl/filter/searchFilter.d.cts +39 -0
- package/dist/dsl/filter/searchFilter.d.ts +39 -0
- package/dist/dsl/filter/searchFilter.es.js +19 -0
- package/dist/dsl/filter/searchFilter.es.js.map +1 -0
- package/dist/dsl/filter/timeFilters.cjs +2 -0
- package/dist/dsl/filter/timeFilters.cjs.map +1 -0
- package/dist/dsl/filter/timeFilters.d.cts +290 -0
- package/dist/dsl/filter/timeFilters.d.ts +290 -0
- package/dist/dsl/filter/timeFilters.es.js +89 -0
- package/dist/dsl/filter/timeFilters.es.js.map +1 -0
- package/dist/dsl/filter/types.d.cts +4 -14
- package/dist/dsl/filter/types.d.ts +4 -14
- package/dist/dsl/filter/validate.cjs +1 -1
- package/dist/dsl/filter/validate.cjs.map +1 -1
- package/dist/dsl/filter/validate.d.cts +2 -4
- package/dist/dsl/filter/validate.d.ts +2 -4
- package/dist/dsl/filter/validate.es.js +25 -31
- package/dist/dsl/filter/validate.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 +0 -2
- package/dist/dsl/queryErrorCodes.d.ts +0 -2
- package/dist/dsl/queryErrorCodes.es.js +0 -1
- package/dist/dsl/queryErrorCodes.es.js.map +1 -1
- package/dist/dsl/queryFilter.cjs +2 -0
- package/dist/dsl/queryFilter.cjs.map +1 -0
- package/dist/dsl/queryFilter.d.cts +3 -0
- package/dist/dsl/queryFilter.d.ts +3 -0
- package/dist/dsl/queryFilter.es.js +9 -0
- package/dist/dsl/queryFilter.es.js.map +1 -0
- package/dist/dsl/queryable.cjs +1 -1
- package/dist/dsl/queryable.cjs.map +1 -1
- package/dist/dsl/queryable.es.js +12 -16
- package/dist/dsl/queryable.es.js.map +1 -1
- package/dist/dsl/semanticTypes.cjs +2 -0
- package/dist/dsl/semanticTypes.cjs.map +1 -0
- package/dist/dsl/semanticTypes.d.cts +128 -0
- package/dist/dsl/semanticTypes.d.ts +128 -0
- package/dist/dsl/semanticTypes.es.js +13 -0
- package/dist/dsl/semanticTypes.es.js.map +1 -0
- package/dist/dsl.cjs +1 -1
- package/dist/dsl.d.cts +2 -0
- package/dist/dsl.d.ts +2 -0
- package/dist/dsl.es.js +14 -8
- package/dist/exactJson.cjs +2 -2
- package/dist/exactJson.cjs.map +1 -1
- package/dist/exactJson.d.cts +41 -16
- package/dist/exactJson.d.ts +41 -16
- package/dist/exactJson.es.js +104 -102
- package/dist/exactJson.es.js.map +1 -1
- package/dist/frameworkErrors.cjs.map +1 -1
- package/dist/frameworkErrors.d.cts +4 -4
- package/dist/frameworkErrors.d.ts +4 -4
- package/dist/frameworkErrors.es.js.map +1 -1
- package/dist/http.cjs +1 -1
- package/dist/http.cjs.map +1 -1
- package/dist/http.d.cts +29 -9
- package/dist/http.d.ts +29 -9
- package/dist/http.es.js +24 -19
- package/dist/http.es.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.es.js +12 -12
- package/dist/manifest.cjs +1 -1
- package/dist/manifest.cjs.map +1 -1
- package/dist/manifest.d.cts +24 -0
- package/dist/manifest.d.ts +24 -0
- package/dist/manifest.es.js +34 -6
- package/dist/manifest.es.js.map +1 -1
- package/dist/manifestTypes.d.cts +16 -1
- package/dist/manifestTypes.d.ts +16 -1
- package/dist/queries.cjs +1 -1
- package/dist/queries.cjs.map +1 -1
- package/dist/queries.d.cts +18 -8
- package/dist/queries.d.ts +18 -8
- package/dist/queries.es.js +46 -35
- package/dist/queries.es.js.map +1 -1
- package/dist/routes.cjs +1 -1
- package/dist/routes.cjs.map +1 -1
- package/dist/routes.d.cts +16 -3
- package/dist/routes.d.ts +16 -3
- package/dist/routes.es.js +24 -25
- package/dist/routes.es.js.map +1 -1
- package/dist/state.cjs +1 -1
- package/dist/state.cjs.map +1 -1
- package/dist/state.d.cts +21 -19
- package/dist/state.d.ts +21 -19
- package/dist/state.es.js +27 -22
- 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 +14 -7
- package/dist/streams.d.ts +14 -7
- package/dist/streams.es.js +65 -50
- package/dist/streams.es.js.map +1 -1
- package/dist/testing/wire.cjs +1 -1
- package/dist/testing/wire.cjs.map +1 -1
- package/dist/testing/wire.es.js +1 -1
- package/dist/testing/wire.es.js.map +1 -1
- package/dist/wait.cjs +1 -1
- package/dist/wait.cjs.map +1 -1
- package/dist/wait.d.cts +17 -4
- package/dist/wait.d.ts +17 -4
- package/dist/wait.es.js +36 -34
- 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 +75 -31
- package/dist/wire.d.ts +75 -31
- package/dist/wire.es.js +1 -3
- package/dist/wire.es.js.map +1 -1
- package/package.json +5 -5
- package/dist/dsl/filter/datePattern.cjs +0 -2
- package/dist/dsl/filter/datePattern.cjs.map +0 -1
- package/dist/dsl/filter/datePattern.d.cts +0 -8
- package/dist/dsl/filter/datePattern.d.ts +0 -8
- package/dist/dsl/filter/datePattern.es.js +0 -96
- package/dist/dsl/filter/datePattern.es.js.map +0 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { requireValidExpressionTrees as e } from "./expressionTrees.es.js";
|
|
2
|
+
import { constantName as t } from "../constantName.es.js";
|
|
3
|
+
import { aggregationAlias as n, aggregationField as r } from "./aliases.es.js";
|
|
4
|
+
// src/dsl/aggregation/groups.ts
|
|
5
|
+
var i = /* @__PURE__ */ function(e) {
|
|
6
|
+
return e.TERMS = "terms", e.HISTOGRAM = "histogram", e.DATE_HISTOGRAM = "date-histogram", e.DATE_PART = "date-part", e;
|
|
7
|
+
}({}), a = /* @__PURE__ */ function(e) {
|
|
8
|
+
return e.ELEMENT = "element", e.ROOT = "root", e;
|
|
9
|
+
}({}), o = /* @__PURE__ */ function(e) {
|
|
10
|
+
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;
|
|
11
|
+
}({}), s = /* @__PURE__ */ function(e) {
|
|
12
|
+
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;
|
|
13
|
+
}({});
|
|
14
|
+
function c(n, i) {
|
|
15
|
+
if (typeof n == "string") return { field: r(n) };
|
|
16
|
+
if (typeof n != "object" || !n) throw TypeError(`${t(i)} group requires exactly one of field and expression.`);
|
|
17
|
+
return e([n]), { expression: n };
|
|
18
|
+
}
|
|
19
|
+
function l(e, n, r) {
|
|
20
|
+
if (e === void 0) return {};
|
|
21
|
+
if (!Object.values(a).includes(e)) throw TypeError(`${t(n)} group scope is invalid.`);
|
|
22
|
+
if (e === "root" && r.expression) throw TypeError(`${t(n)} with a ROOT scope requires a field input.`);
|
|
23
|
+
return { scope: e };
|
|
24
|
+
}
|
|
25
|
+
var u = {
|
|
26
|
+
terms(e, t, { missingKey: r, scope: i } = {}) {
|
|
27
|
+
if (r !== void 0 && (typeof r != "string" || !r.trim())) throw TypeError("terms missingKey must not be blank.");
|
|
28
|
+
let a = c(e, "terms");
|
|
29
|
+
if (r !== void 0 && a.expression) throw TypeError("terms missingKey requires a field input.");
|
|
30
|
+
return {
|
|
31
|
+
type: "terms",
|
|
32
|
+
...r === void 0 ? {} : { missingKey: r },
|
|
33
|
+
...a,
|
|
34
|
+
...l(i, "terms", a),
|
|
35
|
+
alias: n(t)
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
histogram(e, t, { interval: r, scope: i }) {
|
|
39
|
+
if (!Number.isFinite(r) || r <= 0) throw TypeError("histogram interval must be finite and greater than 0.");
|
|
40
|
+
let a = c(e, "histogram");
|
|
41
|
+
return {
|
|
42
|
+
type: "histogram",
|
|
43
|
+
...a,
|
|
44
|
+
...l(i, "histogram", a),
|
|
45
|
+
interval: r,
|
|
46
|
+
alias: n(t)
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
dateHistogram(e, t, { unit: i, timeZone: a, dense: s, scope: c }) {
|
|
50
|
+
if (s !== void 0 && typeof s != "boolean") throw TypeError("date histogram dense must be boolean.");
|
|
51
|
+
if (!Object.values(o).includes(i)) throw TypeError("date histogram unit is invalid.");
|
|
52
|
+
if (a !== void 0 && (typeof a != "string" || !a.trim())) throw TypeError("date histogram timeZone cannot be blank.");
|
|
53
|
+
return {
|
|
54
|
+
type: "date-histogram",
|
|
55
|
+
...s === void 0 ? {} : { dense: s },
|
|
56
|
+
field: r(e),
|
|
57
|
+
...l(c, "date-histogram", {}),
|
|
58
|
+
unit: i,
|
|
59
|
+
alias: n(t),
|
|
60
|
+
...a === void 0 ? {} : { timeZone: a }
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
datePart(e, t, { part: i, timeZone: a, dense: o, scope: c }) {
|
|
64
|
+
if (o !== void 0 && typeof o != "boolean") throw TypeError("date part dense must be boolean.");
|
|
65
|
+
if (!Object.values(s).includes(i)) throw TypeError("date part is invalid.");
|
|
66
|
+
if (a !== void 0 && (typeof a != "string" || !a.trim())) throw TypeError("date part timeZone cannot be blank.");
|
|
67
|
+
return {
|
|
68
|
+
type: "date-part",
|
|
69
|
+
...o === void 0 ? {} : { dense: o },
|
|
70
|
+
field: r(e),
|
|
71
|
+
...l(c, "date-part", {}),
|
|
72
|
+
part: i,
|
|
73
|
+
alias: n(t),
|
|
74
|
+
...a === void 0 ? {} : { timeZone: a }
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
export { s as AggregationDatePart, o as AggregationDateUnit, a as AggregationGroupScope, i as AggregationGroupType, u as groupBuilders, c as groupInput, l as groupScope };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=groups.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groups.es.js","names":["AggregationGroupType","\"TERMS\"","\"HISTOGRAM\"","\"DATE_HISTOGRAM\"","\"DATE_PART\"","AggregationGroupScope","\"ELEMENT\"","\"ROOT\"","AggregationDateUnit","\"YEAR\"","\"QUARTER\"","\"MONTH\"","\"WEEK\"","\"DAY\"","\"HOUR\"","\"MINUTE\"","\"SECOND\"","AggregationDatePart","\"DAY_OF_WEEK\"","\"DAY_OF_MONTH\"","\"HOUR_OF_DAY\"","\"MONTH_OF_YEAR\"","groupInput","input","aggregationField","constantName","type","requireValidExpressionTrees","groupScope","scope","source","groupBuilders","missingKey","aggregationAlias","alias","interval","dense","unit","timeZone","field","part"],"sources":["../../../src/dsl/aggregation/groups.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 type { QueryField } from '../filter/index.js';\nimport { aggregationField } from './aliases.js';\nimport { requireValidExpressionTrees } from './expressionTrees.js';\nimport type { AggregationExpression } from './types.js';\nimport { aggregationAlias } from './aliases.js';\n\n/** The kind of an {@link AggregationGroup}, sent as its `type`. */\nexport enum AggregationGroupType {\n /** One group per distinct value; {@link groupBuilders.terms | `aggregation.terms`}. */\n TERMS = 'terms',\n /** Number buckets of equal width; {@link groupBuilders.histogram | `aggregation.histogram`}. */\n HISTOGRAM = 'histogram',\n /** Calendar buckets of a time field; {@link groupBuilders.dateHistogram | `aggregation.dateHistogram`}. */\n DATE_HISTOGRAM = 'date-histogram',\n /**\n * One calendar part of a time field, such as the weekday or the hour;\n * {@link groupBuilders.datePart | `aggregation.datePart`}. Wow 9.2 and later.\n */\n DATE_PART = 'date-part',\n}\n\n/**\n * What an {@link AggregationGroup}'s field is relative to when the query\n * expands elements, sent as its `scope`. Wow 9.9 and later.\n */\nexport enum AggregationGroupScope {\n /** The innermost expanded element; the default. */\n ELEMENT = 'element',\n /** The root record, so the elements are grouped by a field of their root. */\n ROOT = 'root',\n}\n\n/**\n * The calendar unit of a `DATE_HISTOGRAM` bucket, cut in the group's\n * `timeZone`.\n */\nexport enum AggregationDateUnit {\n YEAR = 'year',\n QUARTER = 'quarter',\n MONTH = 'month',\n WEEK = 'week',\n DAY = 'day',\n HOUR = 'hour',\n MINUTE = 'minute',\n SECOND = 'second',\n}\n\n/**\n * The calendar part a `DATE_PART` group takes of each instant, read in the\n * group's `timeZone`. Its keys are integers from a fixed domain, so records\n * from different days, weeks or years fall into one bucket.\n */\nexport enum AggregationDatePart {\n /** The ISO weekday: 1 is Monday, 7 is Sunday. */\n DAY_OF_WEEK = 'day-of-week',\n /**\n * The day of the month, 1 to 31; days 29 to 31 exist only in the months\n * that have them.\n */\n DAY_OF_MONTH = 'day-of-month',\n /** The hour on the wall clock of the group's `timeZone`, 0 to 23. */\n HOUR_OF_DAY = 'hour-of-day',\n /** The month of the year, 1 (January) to 12. */\n MONTH_OF_YEAR = 'month-of-year',\n}\n\n/** What every {@link AggregationGroup} has. */\ninterface AggregationGroupBase<FIELDS extends string = string> {\n /** The field the rows are grouped by. */\n field: QueryField<FIELDS>;\n /** The name of the group's column in the result rows. */\n alias: string;\n /**\n * What `field` is relative to when the query expands elements: the\n * innermost element (`ELEMENT`, the default) or the root record (`ROOT`).\n * A `ROOT` group names a field, never an expression. Wow 9.9 and later,\n * where `analysis.rootGroups` is `true`.\n */\n scope?: AggregationGroupScope;\n}\n\n/**\n * What a TERMS or HISTOGRAM group groups by: a field, or a computed\n * expression in its place (Wow 9.2 and later), never both. An expression\n * input is an expensive computation the server admits only where\n * `analysis.expressions` is `true`.\n */\nexport type AggregationGroupInput<FIELDS extends string = string> =\n | {\n /** The field the rows are grouped by. */\n field: QueryField<FIELDS>;\n expression?: undefined;\n }\n | {\n field?: undefined;\n /** The per-row value the rows are grouped by, such as a `DATE_DIFF`. */\n expression: AggregationExpression<FIELDS>;\n };\n\n/**\n * One group per distinct value of a field, or of an expression;\n * {@link groupBuilders.terms | `aggregation.terms`}. `missingKey` needs a field.\n */\nexport type TermsAggregationGroup<FIELDS extends string = string> = {\n type: AggregationGroupType.TERMS;\n /** The name of the group's column in the result rows. */\n alias: string;\n /** The key the rows without a value are grouped under. Wow 9.1 and later. */\n missingKey?: string;\n /**\n * What `field` is relative to when the query expands elements: the\n * innermost element (`ELEMENT`, the default) or the root record (`ROOT`).\n * A `ROOT` group names a field, never an expression. Wow 9.9 and later,\n * where `analysis.rootGroups` is `true`.\n */\n scope?: AggregationGroupScope;\n} & AggregationGroupInput<FIELDS>;\n\n/**\n * Buckets of equal width over a number field, or over an expression;\n * {@link groupBuilders.histogram | `aggregation.histogram`}.\n */\nexport type HistogramAggregationGroup<FIELDS extends string = string> = {\n type: AggregationGroupType.HISTOGRAM;\n /** The name of the group's column in the result rows. */\n alias: string;\n /** The width of each bucket, greater than 0. */\n interval: number;\n /**\n * What `field` is relative to when the query expands elements: the\n * innermost element (`ELEMENT`, the default) or the root record (`ROOT`).\n * A `ROOT` group names a field, never an expression. Wow 9.9 and later,\n * where `analysis.rootGroups` is `true`.\n */\n scope?: AggregationGroupScope;\n} & AggregationGroupInput<FIELDS>;\n\n/**\n * Calendar buckets over a time field in epoch milliseconds;\n * {@link groupBuilders.dateHistogram | `aggregation.dateHistogram`}.\n */\nexport interface DateHistogramAggregationGroup<\n FIELDS extends string = string,\n> extends AggregationGroupBase<FIELDS> {\n type: AggregationGroupType.DATE_HISTOGRAM;\n /** The calendar unit of each bucket. */\n unit: AggregationDateUnit;\n /** The IANA zone the buckets are cut in; `UTC` when absent. */\n timeZone?: string;\n /**\n * Whether the server fills in the empty buckets of the range. Wow 9.1 and\n * later, and only when this is the query's only group.\n */\n dense?: boolean;\n}\n\n/**\n * One calendar part of a time field in epoch milliseconds, such as the\n * weekday or the hour; {@link groupBuilders.datePart | `aggregation.datePart`}. Its keys in the result\n * rows are integers from the part's domain, such as 1 (Monday) to 7 (Sunday)\n * for `DAY_OF_WEEK`. Wow 9.2 and later.\n */\nexport interface DatePartAggregationGroup<\n FIELDS extends string = string,\n> extends AggregationGroupBase<FIELDS> {\n type: AggregationGroupType.DATE_PART;\n /** The calendar part each row is grouped by. */\n part: AggregationDatePart;\n /** The IANA zone the part is read in; `UTC` when absent. */\n timeZone?: string;\n /**\n * Whether the server returns every key of the part's domain, filling a\n * key with no records with each metric's empty value. Only when this is\n * the query's only group.\n */\n dense?: boolean;\n}\n\n/**\n * One dimension of an {@link AggregationQuery}'s `groupBy`: each result row\n * is one combination of the groups' keys.\n */\nexport type AggregationGroup<FIELDS extends string = string> =\n | TermsAggregationGroup<FIELDS>\n | HistogramAggregationGroup<FIELDS>\n | DateHistogramAggregationGroup<FIELDS>\n | DatePartAggregationGroup<FIELDS>;\n\n/** The option every group builder takes. */\nexport interface AggregationGroupScopeOptions {\n /**\n * What the field is relative to when the query expands elements; the\n * innermost element when absent. `ROOT` needs a field input. Wow 9.9 and\n * later.\n */\n scope?: AggregationGroupScope;\n}\n\n/** The options of {@link groupBuilders.terms | `aggregation.terms`}. */\nexport interface TermsAggregationOptions extends AggregationGroupScopeOptions {\n /** The key rows without a value are grouped under; must not be blank. */\n missingKey?: string;\n}\n\n/** The options of {@link groupBuilders.histogram | `aggregation.histogram`}. */\nexport interface HistogramAggregationOptions extends AggregationGroupScopeOptions {\n /** The width of each bucket: finite and greater than 0. */\n interval: number;\n}\n\n/** The options of {@link groupBuilders.dateHistogram | `aggregation.dateHistogram`}. */\nexport interface DateHistogramAggregationOptions extends AggregationGroupScopeOptions {\n /** The calendar unit of each bucket. */\n unit: AggregationDateUnit;\n /** The zone the buckets are cut in, an IANA id. Sent only when set; the server reads none as `UTC`. */\n timeZone?: string;\n /**\n * Whether the server fills in the empty buckets of the range. Only when\n * this is the only group.\n */\n dense?: boolean;\n}\n\n/** The options of {@link groupBuilders.datePart | `aggregation.datePart`}. */\nexport interface DatePartAggregationOptions extends AggregationGroupScopeOptions {\n /** The calendar part each row is grouped by. */\n part: AggregationDatePart;\n /** The zone the part is read in, an IANA id. Sent only when set; the server reads none as `UTC`. */\n timeZone?: string;\n /**\n * Whether the server returns every key of the part's domain, the empty\n * ones filled in. Only when this is the only group.\n */\n dense?: boolean;\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 */\nexport function 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. */\nexport function 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/** The builders of the groups of an aggregation query: terms, histograms, date histograms and date parts. */\nexport const groupBuilders = {\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. Sent only when\n * set; the server reads none as `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, 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 (\n timeZone !== undefined &&\n (typeof timeZone !== 'string' || !timeZone.trim())\n ) {\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 === undefined ? {} : { 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. Sent only when\n * set; the server reads none as `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, 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 (\n timeZone !== undefined &&\n (typeof timeZone !== 'string' || !timeZone.trim())\n ) {\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 === undefined ? {} : { timeZone }),\n };\n },\n};\n"],"mappings":"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("
|
|
1
|
+
const e=require("./types.cjs"),t=require("../constantName.cjs");var n=function(e){return e.CONDITION=`condition`,e.BETWEEN=`between`,e.IN=`in`,e.IS_NULL=`is-null`,e.AND=`and`,e.OR=`or`,e}({});function r(e,t,n){if(!Number.isFinite(n))throw TypeError(`having condition [${t}] value must be finite.`);return{type:`condition`,metric:t,operator:e,value:n}}function i(e,n){let[r,...i]=n;if(r===void 0)throw TypeError(`having ${t.constantName(e)} operands must not be empty.`);return{type:e,operands:[r,...i]}}var a={eq:(t,n)=>r(e.ComparisonOperator.EQ,t,n),ne:(t,n)=>r(e.ComparisonOperator.NE,t,n),gt:(t,n)=>r(e.ComparisonOperator.GT,t,n),gte:(t,n)=>r(e.ComparisonOperator.GTE,t,n),lt:(t,n)=>r(e.ComparisonOperator.LT,t,n),lte:(t,n)=>r(e.ComparisonOperator.LTE,t,n),between(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n))throw TypeError(`having between [${e}] bounds must be finite.`);if(t>n)throw TypeError(`having between [${e}] lower bound must not exceed upper bound.`);return{type:`between`,metric:e,lower:t,upper:n}},isIn(e,t){let[n,...r]=t;if(n===void 0)throw TypeError(`having in [${e}] values must not be empty.`);if(!t.every(Number.isFinite))throw TypeError(`having in [${e}] values must be finite.`);return{type:`in`,metric:e,values:[n,...r]}},isNull:e=>({type:`is-null`,metric:e}),isNotNull:e=>({type:`is-null`,metric:e,negated:!0}),and:e=>i(`and`,e),or:e=>i(`or`,e)},o={having:a};exports.HavingExpressionType=n,exports.havingBuilders=o,exports.havingDsl=a;
|
|
2
2
|
//# sourceMappingURL=having.cjs.map
|
|
@@ -1 +1 @@
|
|
|
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"}
|
|
1
|
+
{"version":3,"file":"having.cjs","names":["constantName","ComparisonOperator","require_types","require_constantName","HavingExpressionType","\"CONDITION\"","\"BETWEEN\"","\"IN\"","\"IS_NULL\"","\"AND\"","\"OR\"","condition","value","metric","logical","first","rest","operands","type","havingDsl","lower","upper","values","havingBuilders"],"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 { ComparisonOperator } from './types.js';\n\n/** The kind of a {@link HavingExpression} node, sent as its `type`. */\nexport enum HavingExpressionType {\n /** A metric compared with a number; `aggregation.having.eq` … `lte`. */\n CONDITION = 'condition',\n /** A metric within bounds, inclusive; `aggregation.having.between`. */\n BETWEEN = 'between',\n /** A metric equal to one of the numbers; `aggregation.having.isIn`. */\n IN = 'in',\n /**\n * A metric without a value, or with one when `negated`;\n * `aggregation.having.isNull`, `isNotNull`.\n */\n IS_NULL = 'is-null',\n /** All operands hold; `aggregation.having.and`. */\n AND = 'and',\n /** At least one operand holds; `aggregation.having.or`. */\n OR = 'or',\n}\n\n/**\n * Filters grouped results by metric aliases, before sorting/limit; never an\n * `ANY`, `FIRST` or `LAST` metric.\n */\nexport type HavingExpression =\n | {\n type: HavingExpressionType.CONDITION;\n metric: string;\n operator: ComparisonOperator;\n value: number;\n }\n | {\n type: HavingExpressionType.BETWEEN;\n metric: string;\n lower: number;\n upper: number;\n }\n | {\n type: HavingExpressionType.IN;\n metric: string;\n values: [number, ...number[]];\n }\n | { type: HavingExpressionType.IS_NULL; metric: string; negated?: boolean }\n | {\n type: HavingExpressionType.AND | HavingExpressionType.OR;\n operands: [HavingExpression, ...HavingExpression[]];\n };\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\n/** The builders of the query's `having`. */\nexport const havingBuilders = {\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"],"mappings":"A,gEAiBA,IAAYI,EAAL,SAAA,EAAA,C,MAEL,GAAAC,UAAA,YAEA,EAAAC,QAAA,UAEA,EAAAC,GAAA,KAKA,EAAAC,QAAA,UAEA,EAAAC,IAAA,MAEA,EAAAC,GAAA,K,CACF,EAAA,CAAA,CAAA,EA2HA,SAASC,EACP,EACA,EACA,EACkB,CAClB,GAAI,CAAC,OAAO,SAASC,CAAK,EACxB,MAAU,UAAU,qBAAqBC,EAAO,wBAAwB,EAE1E,MAAO,CAAE,KAAA,YAAsC,SAAQ,WAAU,OAAM,CACzE,CAEA,SAASC,EACP,EACA,EACkB,CAClB,GAAM,CAACC,EAAO,GAAGC,GAAQC,EACzB,GAAIF,IAAU,IAAA,GACZ,MAAU,UACR,UAAUf,EAAAA,aAAakB,CAAI,EAAE,6BAC/B,EAEF,MAAO,CAAE,OAAM,SAAU,CAACH,EAAO,GAAGC,CAAI,CAAE,CAC5C,CAEA,IAAaG,EAAuB,CAClC,IAAK,EAAQ,IAAUR,EAAUV,EAAAA,mBAAmB,GAAIY,EAAQD,CAAK,EACrE,IAAK,EAAQ,IAAUD,EAAUV,EAAAA,mBAAmB,GAAIY,EAAQD,CAAK,EACrE,IAAK,EAAQ,IAAUD,EAAUV,EAAAA,mBAAmB,GAAIY,EAAQD,CAAK,EACrE,KAAM,EAAQ,IAAUD,EAAUV,EAAAA,mBAAmB,IAAKY,EAAQD,CAAK,EACvE,IAAK,EAAQ,IAAUD,EAAUV,EAAAA,mBAAmB,GAAIY,EAAQD,CAAK,EACrE,KAAM,EAAQ,IAAUD,EAAUV,EAAAA,mBAAmB,IAAKY,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,KAAA,UAAoC,SAAQ,QAAO,OAAM,CACpE,EACA,KAAK,EAAQ,EAAQ,CACnB,GAAM,CAACE,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,KAAA,KAA+B,SAAQ,OAAQ,CAACE,EAAO,GAAGC,CAAI,CAAE,CAC3E,EACA,OAAQ,IAAW,CAAE,KAAA,UAAoC,QAAO,GAChE,UAAW,IAAW,CACpB,KAAA,UACA,SACA,QAAS,EACX,GACA,IAAK,GAAYF,EAAA,MAAkCG,CAAQ,EAC3D,GAAI,GAAYH,EAAA,KAAiCG,CAAQ,CAC3D,EAGaM,EAAiB,CAe5B,OAAQJ,CACV,E"}
|
|
@@ -1,4 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComparisonOperator } from './types.cjs';
|
|
2
|
+
/** The kind of a {@link HavingExpression} node, sent as its `type`. */
|
|
3
|
+
export declare enum HavingExpressionType {
|
|
4
|
+
/** A metric compared with a number; `aggregation.having.eq` … `lte`. */
|
|
5
|
+
CONDITION = "condition",
|
|
6
|
+
/** A metric within bounds, inclusive; `aggregation.having.between`. */
|
|
7
|
+
BETWEEN = "between",
|
|
8
|
+
/** A metric equal to one of the numbers; `aggregation.having.isIn`. */
|
|
9
|
+
IN = "in",
|
|
10
|
+
/**
|
|
11
|
+
* A metric without a value, or with one when `negated`;
|
|
12
|
+
* `aggregation.having.isNull`, `isNotNull`.
|
|
13
|
+
*/
|
|
14
|
+
IS_NULL = "is-null",
|
|
15
|
+
/** All operands hold; `aggregation.having.and`. */
|
|
16
|
+
AND = "and",
|
|
17
|
+
/** At least one operand holds; `aggregation.having.or`. */
|
|
18
|
+
OR = "or"
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Filters grouped results by metric aliases, before sorting/limit; never an
|
|
22
|
+
* `ANY`, `FIRST` or `LAST` metric.
|
|
23
|
+
*/
|
|
24
|
+
export type HavingExpression = {
|
|
25
|
+
type: HavingExpressionType.CONDITION;
|
|
26
|
+
metric: string;
|
|
27
|
+
operator: ComparisonOperator;
|
|
28
|
+
value: number;
|
|
29
|
+
} | {
|
|
30
|
+
type: HavingExpressionType.BETWEEN;
|
|
31
|
+
metric: string;
|
|
32
|
+
lower: number;
|
|
33
|
+
upper: number;
|
|
34
|
+
} | {
|
|
35
|
+
type: HavingExpressionType.IN;
|
|
36
|
+
metric: string;
|
|
37
|
+
values: [number, ...number[]];
|
|
38
|
+
} | {
|
|
39
|
+
type: HavingExpressionType.IS_NULL;
|
|
40
|
+
metric: string;
|
|
41
|
+
negated?: boolean;
|
|
42
|
+
} | {
|
|
43
|
+
type: HavingExpressionType.AND | HavingExpressionType.OR;
|
|
44
|
+
operands: [HavingExpression, ...HavingExpression[]];
|
|
45
|
+
};
|
|
2
46
|
/**
|
|
3
47
|
* The builders of a `having` expression, `aggregation.having.*`: conditions on
|
|
4
48
|
* the metric columns of the grouped rows, and their `and`/`or`. Mirrors
|
|
@@ -92,3 +136,21 @@ export interface HavingDsl {
|
|
|
92
136
|
or(operands: readonly HavingExpression[]): HavingExpression;
|
|
93
137
|
}
|
|
94
138
|
export declare const havingDsl: HavingDsl;
|
|
139
|
+
/** The builders of the query's `having`. */
|
|
140
|
+
export declare const havingBuilders: {
|
|
141
|
+
/**
|
|
142
|
+
* The builders of the query's `having`: conditions on the metric columns of
|
|
143
|
+
* the grouped rows (`eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `between`, `isIn`,
|
|
144
|
+
* `isNull`, `isNotNull`) and their `and`/`or`. See `HavingDsl`.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* aggregation.query({
|
|
149
|
+
* groupBy: [aggregation.terms('state.status', 'status')],
|
|
150
|
+
* metrics: [aggregation.count('orders')],
|
|
151
|
+
* having: aggregation.having.gt('orders', 10),
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
having: HavingDsl;
|
|
156
|
+
};
|
|
@@ -1,4 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComparisonOperator } from './types.js';
|
|
2
|
+
/** The kind of a {@link HavingExpression} node, sent as its `type`. */
|
|
3
|
+
export declare enum HavingExpressionType {
|
|
4
|
+
/** A metric compared with a number; `aggregation.having.eq` … `lte`. */
|
|
5
|
+
CONDITION = "condition",
|
|
6
|
+
/** A metric within bounds, inclusive; `aggregation.having.between`. */
|
|
7
|
+
BETWEEN = "between",
|
|
8
|
+
/** A metric equal to one of the numbers; `aggregation.having.isIn`. */
|
|
9
|
+
IN = "in",
|
|
10
|
+
/**
|
|
11
|
+
* A metric without a value, or with one when `negated`;
|
|
12
|
+
* `aggregation.having.isNull`, `isNotNull`.
|
|
13
|
+
*/
|
|
14
|
+
IS_NULL = "is-null",
|
|
15
|
+
/** All operands hold; `aggregation.having.and`. */
|
|
16
|
+
AND = "and",
|
|
17
|
+
/** At least one operand holds; `aggregation.having.or`. */
|
|
18
|
+
OR = "or"
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Filters grouped results by metric aliases, before sorting/limit; never an
|
|
22
|
+
* `ANY`, `FIRST` or `LAST` metric.
|
|
23
|
+
*/
|
|
24
|
+
export type HavingExpression = {
|
|
25
|
+
type: HavingExpressionType.CONDITION;
|
|
26
|
+
metric: string;
|
|
27
|
+
operator: ComparisonOperator;
|
|
28
|
+
value: number;
|
|
29
|
+
} | {
|
|
30
|
+
type: HavingExpressionType.BETWEEN;
|
|
31
|
+
metric: string;
|
|
32
|
+
lower: number;
|
|
33
|
+
upper: number;
|
|
34
|
+
} | {
|
|
35
|
+
type: HavingExpressionType.IN;
|
|
36
|
+
metric: string;
|
|
37
|
+
values: [number, ...number[]];
|
|
38
|
+
} | {
|
|
39
|
+
type: HavingExpressionType.IS_NULL;
|
|
40
|
+
metric: string;
|
|
41
|
+
negated?: boolean;
|
|
42
|
+
} | {
|
|
43
|
+
type: HavingExpressionType.AND | HavingExpressionType.OR;
|
|
44
|
+
operands: [HavingExpression, ...HavingExpression[]];
|
|
45
|
+
};
|
|
2
46
|
/**
|
|
3
47
|
* The builders of a `having` expression, `aggregation.having.*`: conditions on
|
|
4
48
|
* the metric columns of the grouped rows, and their `and`/`or`. Mirrors
|
|
@@ -92,3 +136,21 @@ export interface HavingDsl {
|
|
|
92
136
|
or(operands: readonly HavingExpression[]): HavingExpression;
|
|
93
137
|
}
|
|
94
138
|
export declare const havingDsl: HavingDsl;
|
|
139
|
+
/** The builders of the query's `having`. */
|
|
140
|
+
export declare const havingBuilders: {
|
|
141
|
+
/**
|
|
142
|
+
* The builders of the query's `having`: conditions on the metric columns of
|
|
143
|
+
* the grouped rows (`eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `between`, `isIn`,
|
|
144
|
+
* `isNull`, `isNotNull`) and their `and`/`or`. See `HavingDsl`.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* aggregation.query({
|
|
149
|
+
* groupBy: [aggregation.terms('state.status', 'status')],
|
|
150
|
+
* metrics: [aggregation.count('orders')],
|
|
151
|
+
* having: aggregation.having.gt('orders', 10),
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
having: HavingDsl;
|
|
156
|
+
};
|
|
@@ -1,62 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ComparisonOperator as e } from "./types.es.js";
|
|
2
|
+
import { constantName as t } from "../constantName.es.js";
|
|
3
3
|
// src/dsl/aggregation/having.ts
|
|
4
|
-
function
|
|
5
|
-
|
|
4
|
+
var n = /* @__PURE__ */ function(e) {
|
|
5
|
+
return e.CONDITION = "condition", e.BETWEEN = "between", e.IN = "in", e.IS_NULL = "is-null", e.AND = "and", e.OR = "or", e;
|
|
6
|
+
}({});
|
|
7
|
+
function r(e, t, n) {
|
|
8
|
+
if (!Number.isFinite(n)) throw TypeError(`having condition [${t}] value must be finite.`);
|
|
6
9
|
return {
|
|
7
|
-
type:
|
|
10
|
+
type: "condition",
|
|
8
11
|
metric: t,
|
|
9
12
|
operator: e,
|
|
10
|
-
value:
|
|
13
|
+
value: n
|
|
11
14
|
};
|
|
12
15
|
}
|
|
13
|
-
function i(
|
|
16
|
+
function i(e, n) {
|
|
14
17
|
let [r, ...i] = n;
|
|
15
|
-
if (r === void 0) throw TypeError(`having ${e
|
|
18
|
+
if (r === void 0) throw TypeError(`having ${t(e)} operands must not be empty.`);
|
|
16
19
|
return {
|
|
17
|
-
type:
|
|
20
|
+
type: e,
|
|
18
21
|
operands: [r, ...i]
|
|
19
22
|
};
|
|
20
23
|
}
|
|
21
24
|
var a = {
|
|
22
|
-
eq: (
|
|
23
|
-
ne: (
|
|
24
|
-
gt: (
|
|
25
|
-
gte: (
|
|
26
|
-
lt: (
|
|
27
|
-
lte: (
|
|
28
|
-
between(e, t,
|
|
29
|
-
if (!Number.isFinite(t) || !Number.isFinite(
|
|
30
|
-
if (t >
|
|
25
|
+
eq: (t, n) => r(e.EQ, t, n),
|
|
26
|
+
ne: (t, n) => r(e.NE, t, n),
|
|
27
|
+
gt: (t, n) => r(e.GT, t, n),
|
|
28
|
+
gte: (t, n) => r(e.GTE, t, n),
|
|
29
|
+
lt: (t, n) => r(e.LT, t, n),
|
|
30
|
+
lte: (t, n) => r(e.LTE, t, n),
|
|
31
|
+
between(e, t, n) {
|
|
32
|
+
if (!Number.isFinite(t) || !Number.isFinite(n)) throw TypeError(`having between [${e}] bounds must be finite.`);
|
|
33
|
+
if (t > n) throw TypeError(`having between [${e}] lower bound must not exceed upper bound.`);
|
|
31
34
|
return {
|
|
32
|
-
type:
|
|
35
|
+
type: "between",
|
|
33
36
|
metric: e,
|
|
34
37
|
lower: t,
|
|
35
|
-
upper:
|
|
38
|
+
upper: n
|
|
36
39
|
};
|
|
37
40
|
},
|
|
38
41
|
isIn(e, t) {
|
|
39
|
-
let [
|
|
40
|
-
if (
|
|
42
|
+
let [n, ...r] = t;
|
|
43
|
+
if (n === void 0) throw TypeError(`having in [${e}] values must not be empty.`);
|
|
41
44
|
if (!t.every(Number.isFinite)) throw TypeError(`having in [${e}] values must be finite.`);
|
|
42
45
|
return {
|
|
43
|
-
type:
|
|
46
|
+
type: "in",
|
|
44
47
|
metric: e,
|
|
45
|
-
values: [
|
|
48
|
+
values: [n, ...r]
|
|
46
49
|
};
|
|
47
50
|
},
|
|
48
51
|
isNull: (e) => ({
|
|
49
|
-
type:
|
|
52
|
+
type: "is-null",
|
|
50
53
|
metric: e
|
|
51
54
|
}),
|
|
52
55
|
isNotNull: (e) => ({
|
|
53
|
-
type:
|
|
56
|
+
type: "is-null",
|
|
54
57
|
metric: e,
|
|
55
58
|
negated: !0
|
|
56
59
|
}),
|
|
57
|
-
and: (e) => i(
|
|
58
|
-
or: (e) => i(
|
|
59
|
-
};
|
|
60
|
-
export { a as havingDsl };
|
|
60
|
+
and: (e) => i("and", e),
|
|
61
|
+
or: (e) => i("or", e)
|
|
62
|
+
}, o = { having: a };
|
|
63
|
+
export { n as HavingExpressionType, o as havingBuilders, a as havingDsl };
|
|
61
64
|
|
|
62
65
|
//# sourceMappingURL=having.es.js.map
|
|
@@ -1 +1 @@
|
|
|
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
|
+
{"version":3,"file":"having.es.js","names":["HavingExpressionType","\"CONDITION\"","\"BETWEEN\"","\"IN\"","\"IS_NULL\"","\"AND\"","\"OR\"","condition","value","metric","logical","first","rest","operands","constantName","type","havingDsl","ComparisonOperator","lower","upper","values","havingBuilders"],"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 { ComparisonOperator } from './types.js';\n\n/** The kind of a {@link HavingExpression} node, sent as its `type`. */\nexport enum HavingExpressionType {\n /** A metric compared with a number; `aggregation.having.eq` … `lte`. */\n CONDITION = 'condition',\n /** A metric within bounds, inclusive; `aggregation.having.between`. */\n BETWEEN = 'between',\n /** A metric equal to one of the numbers; `aggregation.having.isIn`. */\n IN = 'in',\n /**\n * A metric without a value, or with one when `negated`;\n * `aggregation.having.isNull`, `isNotNull`.\n */\n IS_NULL = 'is-null',\n /** All operands hold; `aggregation.having.and`. */\n AND = 'and',\n /** At least one operand holds; `aggregation.having.or`. */\n OR = 'or',\n}\n\n/**\n * Filters grouped results by metric aliases, before sorting/limit; never an\n * `ANY`, `FIRST` or `LAST` metric.\n */\nexport type HavingExpression =\n | {\n type: HavingExpressionType.CONDITION;\n metric: string;\n operator: ComparisonOperator;\n value: number;\n }\n | {\n type: HavingExpressionType.BETWEEN;\n metric: string;\n lower: number;\n upper: number;\n }\n | {\n type: HavingExpressionType.IN;\n metric: string;\n values: [number, ...number[]];\n }\n | { type: HavingExpressionType.IS_NULL; metric: string; negated?: boolean }\n | {\n type: HavingExpressionType.AND | HavingExpressionType.OR;\n operands: [HavingExpression, ...HavingExpression[]];\n };\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\n/** The builders of the query's `having`. */\nexport const havingBuilders = {\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"],"mappings":";;;AAiBA,IAAYA,IAAL,yBAAA,GAAA;C,OAEL,EAAAC,YAAA,aAEA,EAAAC,UAAA,WAEA,EAAAC,KAAA,MAKA,EAAAC,UAAA,WAEA,EAAAC,MAAA,OAEA,EAAAC,KAAA,M;AACF,EAAA,CAAA,CAAA;AA2HA,SAASC,EACP,GACA,GACA,GACkB;CAClB,IAAI,CAAC,OAAO,SAASC,CAAK,GACxB,MAAU,UAAU,qBAAqBC,EAAO,wBAAwB;CAE1E,OAAO;EAAE,MAAA;EAAsC;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,MAAUT,EAAUU,EAAmB,IAAIR,GAAQD,CAAK;CACrE,KAAK,GAAQ,MAAUD,EAAUU,EAAmB,IAAIR,GAAQD,CAAK;CACrE,KAAK,GAAQ,MAAUD,EAAUU,EAAmB,IAAIR,GAAQD,CAAK;CACrE,MAAM,GAAQ,MAAUD,EAAUU,EAAmB,KAAKR,GAAQD,CAAK;CACvE,KAAK,GAAQ,MAAUD,EAAUU,EAAmB,IAAIR,GAAQD,CAAK;CACrE,MAAM,GAAQ,MAAUD,EAAUU,EAAmB,KAAKR,GAAQD,CAAK;CACvE,QAAQ,GAAQ,GAAO,GAAO;EAC5B,IAAI,CAAC,OAAO,SAASU,CAAK,KAAK,CAAC,OAAO,SAASC,CAAK,GACnD,MAAU,UAAU,mBAAmBV,EAAO,yBAAyB;EAEzE,IAAIS,IAAQC,GACV,MAAU,UACR,mBAAmBV,EAAO,2CAC5B;EAEF,OAAO;GAAE,MAAA;GAAoC;GAAQ;GAAO;EAAM;CACpE;CACA,KAAK,GAAQ,GAAQ;EACnB,IAAM,CAACE,GAAO,GAAGC,KAAQQ;EACzB,IAAIT,MAAU,KAAA,GACZ,MAAU,UAAU,cAAcF,EAAO,4BAA4B;EAEvE,IAAI,CAACW,EAAO,MAAM,OAAO,QAAQ,GAC/B,MAAU,UAAU,cAAcX,EAAO,yBAAyB;EAEpE,OAAO;GAAE,MAAA;GAA+B;GAAQ,QAAQ,CAACE,GAAO,GAAGC,CAAI;EAAE;CAC3E;CACA,SAAQ,OAAW;EAAE,MAAA;EAAoC;CAAO;CAChE,YAAW,OAAW;EACpB,MAAA;EACA;EACA,SAAS;CACX;CACA,MAAK,MAAYF,EAAA,OAAkCG,CAAQ;CAC3D,KAAI,MAAYH,EAAA,MAAiCG,CAAQ;AAC3D,GAGaQ,IAAiB,EAe5B,QAAQL,EACV"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './types.cjs';
|
|
2
|
+
export { AggregationDatePart, AggregationDateUnit, AggregationGroupScope, AggregationGroupType, type AggregationGroup, type AggregationGroupInput, type AggregationGroupScopeOptions, type DateHistogramAggregationGroup, type DateHistogramAggregationOptions, type DatePartAggregationGroup, type DatePartAggregationOptions, type HistogramAggregationGroup, type HistogramAggregationOptions, type TermsAggregationGroup, type TermsAggregationOptions, } from './groups.cjs';
|
|
3
|
+
export { AggregationFunction, AggregationMetricType, type AggregationMetric, type AggregationMetricOptions, type AnyAggregationMetric, type CountAggregationMetric, type DistinctCountAggregationMetric, type EdgeAggregationMetric, type EdgeAggregationOptions, type NumericAggregationMetric, type PercentileAggregationMetric, type PercentileAggregationOptions, } from './metrics.cjs';
|
|
4
|
+
export { DerivedExpressionType, RunningFunction, WindowFunction, type DerivedAggregationMetric, type DerivedExpression, type DerivedExpressionDsl, type DerivedWindow, } from './derived.cjs';
|
|
5
|
+
export { HavingExpressionType, type HavingDsl, type HavingExpression, } from './having.cjs';
|
|
2
6
|
export { aggregation } from './builders.cjs';
|
|
3
|
-
export type { DerivedExpressionDsl } from './derived.cjs';
|
|
4
|
-
export type { HavingDsl } from './having.cjs';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
|
+
export { AggregationDatePart, AggregationDateUnit, AggregationGroupScope, AggregationGroupType, type AggregationGroup, type AggregationGroupInput, type AggregationGroupScopeOptions, type DateHistogramAggregationGroup, type DateHistogramAggregationOptions, type DatePartAggregationGroup, type DatePartAggregationOptions, type HistogramAggregationGroup, type HistogramAggregationOptions, type TermsAggregationGroup, type TermsAggregationOptions, } from './groups.js';
|
|
3
|
+
export { AggregationFunction, AggregationMetricType, type AggregationMetric, type AggregationMetricOptions, type AnyAggregationMetric, type CountAggregationMetric, type DistinctCountAggregationMetric, type EdgeAggregationMetric, type EdgeAggregationOptions, type NumericAggregationMetric, type PercentileAggregationMetric, type PercentileAggregationOptions, } from './metrics.js';
|
|
4
|
+
export { DerivedExpressionType, RunningFunction, WindowFunction, type DerivedAggregationMetric, type DerivedExpression, type DerivedExpressionDsl, type DerivedWindow, } from './derived.js';
|
|
5
|
+
export { HavingExpressionType, type HavingDsl, type HavingExpression, } from './having.js';
|
|
2
6
|
export { aggregation } from './builders.js';
|
|
3
|
-
export type { DerivedExpressionDsl } from './derived.js';
|
|
4
|
-
export type { HavingDsl } from './having.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./aliases.cjs");var t=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}({}),n=function(e){return e.SUM=`sum`,e.AVG=`avg`,e.MIN=`min`,e.MAX=`max`,e.STDDEV=`stddev`,e.VARIANCE=`variance`,e}({});function r(t,n,r,{filter:i}={}){return{type:`numeric`,...i===void 0?{}:{filter:i},function:t,expression:n,alias:e.aggregationAlias(r)}}function i(t,n,r,{orderBy:i,filter:a}){return{type:t,field:e.aggregationField(n),alias:e.aggregationAlias(r),...i===void 0?{}:{orderBy:e.aggregationField(i)},...a===void 0?{}:{filter:a}}}var a={any(t,n,{filter:r}={}){return{type:`any`,...r===void 0?{}:{filter:r},field:e.aggregationField(t),alias:e.aggregationAlias(n)}},first(e,t,n={}){return i(`first`,e,t,n)},last(e,t,n={}){return i(`last`,e,t,n)},count(t,{filter:n}={}){return{type:`count`,...n===void 0?{}:{filter:n},alias:e.aggregationAlias(t)}},sum:(e,t,n)=>r(`sum`,e,t,n),avg:(e,t,n)=>r(`avg`,e,t,n),min:(e,t,n)=>r(`min`,e,t,n),max:(e,t,n)=>r(`max`,e,t,n),stddev:(e,t,n)=>r(`stddev`,e,t,n),variance:(e,t,n)=>r(`variance`,e,t,n),distinctCount(t,n,{filter:r}={}){return{type:`distinct-count`,expression:t,alias:e.aggregationAlias(n),...r===void 0?{}:{filter:r}}},percentile(t,n,{percentile:r,filter:i}){if(!Number.isFinite(r)||r<=0||r>=100)throw TypeError(`percentile must be finite and within (0, 100).`);return{type:`percentile`,expression:t,percentile:r,alias:e.aggregationAlias(n),...i===void 0?{}:{filter:i}}}};exports.AggregationFunction=n,exports.AggregationMetricType=t,exports.edge=i,exports.metricBuilders=a,exports.numeric=r;
|
|
2
|
+
//# sourceMappingURL=metrics.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.cjs","names":["aggregationAlias","aggregationField","require_aliases","AggregationMetricType","\"COUNT\"","\"NUMERIC\"","\"ANY\"","\"DISTINCT_COUNT\"","\"PERCENTILE\"","\"DERIVED\"","\"FIRST\"","\"LAST\"","AggregationFunction","\"SUM\"","\"AVG\"","\"MIN\"","\"MAX\"","\"STDDEV\"","\"VARIANCE\"","numeric","predicate","fn","alias","edge","field","orderBy","metricBuilders","options","expression","percentile"],"sources":["../../../src/dsl/aggregation/metrics.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 { FilterExpression, QueryField } from '../filter/index.js';\nimport type { DerivedAggregationMetric } from './derived.js';\nimport { aggregationAlias, aggregationField } from './aliases.js';\nimport type { AggregationExpression } from './types.js';\n\n/**\n * The kind of an {@link AggregationMetric}, sent as its `type`. Wow 8.12\n * knows `COUNT` and `NUMERIC`, Wow 9.0 adds `ANY`, and the other three need\n * Wow 9.1.\n */\nexport enum AggregationMetricType {\n /** The number of rows; {@link metricBuilders.count | `aggregation.count`}. */\n COUNT = 'count',\n /**\n * An {@link AggregationFunction} of an expression; {@link metricBuilders.sum | `aggregation.sum`}\n * and its siblings.\n */\n NUMERIC = 'numeric',\n /** Any one value of a field; {@link metricBuilders.any | `aggregation.any`}. Wow 9.0 and later. */\n ANY = 'any',\n /**\n * The number of distinct values; {@link metricBuilders.distinctCount | `aggregation.distinctCount`}. Wow 9.1\n * and later.\n */\n DISTINCT_COUNT = 'distinct-count',\n /**\n * A percentile of an expression; {@link metricBuilders.percentile | `aggregation.percentile`}. Wow 9.1\n * and later.\n */\n PERCENTILE = 'percentile',\n /**\n * Arithmetic over other metrics; {@link aggregation.derived}. Wow 9.1 and\n * later.\n */\n DERIVED = 'derived',\n /**\n * A field's value on the group's earliest record; {@link metricBuilders.first | `aggregation.first`}.\n * Wow 9.2 and later.\n */\n FIRST = 'first',\n /**\n * A field's value on the group's latest record; {@link metricBuilders.last | `aggregation.last`}.\n * Wow 9.2 and later.\n */\n LAST = 'last',\n}\n\n/**\n * What a `NUMERIC` metric computes over its expression; each has a builder,\n * {@link metricBuilders.sum | `aggregation.sum`} through {@link metricBuilders.variance | `aggregation.variance`}.\n */\nexport enum AggregationFunction {\n /** The sum */\n SUM = 'sum',\n /** The average */\n AVG = 'avg',\n /** The least value */\n MIN = 'min',\n /** The greatest value */\n MAX = 'max',\n /** The standard deviation */\n STDDEV = 'stddev',\n /** The variance */\n VARIANCE = 'variance',\n}\n\n/** The number of rows in each group; {@link metricBuilders.count | `aggregation.count`}. */\nexport interface CountAggregationMetric<FIELDS extends string = string> {\n /** Counts only the rows that match. Wow 9.1 and later. */\n filter?: FilterExpression<FIELDS>;\n type: AggregationMetricType.COUNT;\n /** The name of the metric's column in the result rows. */\n alias: string;\n}\n\n/**\n * An {@link AggregationFunction} of an expression; {@link metricBuilders.sum | `aggregation.sum`},\n * `avg`, `min`, `max`, `stddev`, `variance`.\n */\nexport interface NumericAggregationMetric<FIELDS extends string = string> {\n /** Aggregates only the rows that match. Wow 9.1 and later. */\n filter?: FilterExpression<FIELDS>;\n type: AggregationMetricType.NUMERIC;\n /** What is computed. */\n function: AggregationFunction;\n /** The per-row value it is computed over. */\n expression: AggregationExpression<FIELDS>;\n /** The name of the metric's column in the result rows. */\n alias: string;\n}\n\n/**\n * Any one value of a field within each group, of any type;\n * {@link metricBuilders.any | `aggregation.any`}. Wow 9.0 and later. Neither a derived metric nor\n * `having` may refer to it.\n */\nexport interface AnyAggregationMetric<FIELDS extends string = string> {\n /** Aggregates only the rows that match. Wow 9.1 and later. */\n filter?: FilterExpression<FIELDS>;\n type: AggregationMetricType.ANY;\n /** The field whose value is taken. */\n field: QueryField<FIELDS>;\n /** The name of the metric's column in the result rows. */\n alias: string;\n}\n\n/**\n * A field's value on the earliest (`FIRST`) or latest (`LAST`) record of\n * each group, ordered by `orderBy`; {@link metricBuilders.first | `aggregation.first`} and\n * {@link metricBuilders.last | `aggregation.last`}. Wow 9.2 and later.\n *\n * The value comes back in the field's own type, not as a number, and is\n * `null` when no record of the group has both a value and an `orderBy`\n * position. Without `orderBy` the server orders by the model's event time,\n * the field the descriptor names as `analysis.firstLastOrderBy`. Records\n * tied on `orderBy` may yield any one of their values. Like `ANY`, neither a\n * derived metric nor `having` may refer to it.\n */\nexport interface EdgeAggregationMetric<FIELDS extends string = string> {\n type: AggregationMetricType.FIRST | AggregationMetricType.LAST;\n /** The single-valued field whose value is taken. */\n field: QueryField<FIELDS>;\n /**\n * The single-valued, sortable field that orders the records; the model's\n * event time when absent.\n */\n orderBy?: QueryField<FIELDS>;\n /** The name of the metric's column in the result rows. */\n alias: string;\n /** Aggregates only the rows that match. */\n filter?: FilterExpression<FIELDS>;\n}\n\n/**\n * The number of distinct values of an expression;\n * {@link metricBuilders.distinctCount | `aggregation.distinctCount`}. Wow 9.1 and later.\n */\nexport interface DistinctCountAggregationMetric<\n FIELDS extends string = string,\n> {\n type: AggregationMetricType.DISTINCT_COUNT;\n /** The per-row value whose distinct values are counted. */\n expression: AggregationExpression<FIELDS>;\n /** The name of the metric's column in the result rows. */\n alias: string;\n /** Aggregates only the rows that match. */\n filter?: FilterExpression<FIELDS>;\n}\n\n/**\n * A percentile of an expression; {@link metricBuilders.percentile | `aggregation.percentile`}. Wow 9.1 and\n * later.\n */\nexport interface PercentileAggregationMetric<FIELDS extends string = string> {\n type: AggregationMetricType.PERCENTILE;\n /** The per-row value the percentile is taken over. */\n expression: AggregationExpression<FIELDS>;\n /** Which percentile, within (0, 100). */\n percentile: number;\n /** The name of the metric's column in the result rows. */\n alias: string;\n /** Aggregates only the rows that match. */\n filter?: FilterExpression<FIELDS>;\n}\n\n/**\n * One column an {@link AggregationQuery} computes for each group; a query\n * takes 1 to `AGGREGATION_LIMITS.MAX_METRICS` of them.\n */\nexport type AggregationMetric<FIELDS extends string = string> =\n | CountAggregationMetric<FIELDS>\n | NumericAggregationMetric<FIELDS>\n | AnyAggregationMetric<FIELDS>\n | DistinctCountAggregationMetric<FIELDS>\n | PercentileAggregationMetric<FIELDS>\n | DerivedAggregationMetric\n | EdgeAggregationMetric<FIELDS>;\n\n/**\n * The options every metric builder takes after its target and alias.\n */\nexport interface AggregationMetricOptions<FIELDS extends string = string> {\n /** Counts only the rows that match; sent as the metric's `filter`. */\n filter?: FilterExpression<FIELDS>;\n}\n\n/** The options of {@link metricBuilders.first | `aggregation.first`} and {@link metricBuilders.last | `aggregation.last`}. */\nexport interface EdgeAggregationOptions<\n FIELDS extends string = string,\n> extends AggregationMetricOptions<FIELDS> {\n /**\n * The single-valued, sortable field that orders the records. Defaults to\n * the model's event time, `analysis.firstLastOrderBy` in the descriptor.\n */\n orderBy?: FIELDS;\n}\n\n/** The options of {@link metricBuilders.percentile | `aggregation.percentile`}. */\nexport interface PercentileAggregationOptions<\n FIELDS extends string = string,\n> extends AggregationMetricOptions<FIELDS> {\n /** Which percentile: finite and within (0, 100). */\n percentile: number;\n}\n\nexport function 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 metricBuilders.first | `aggregation.first`}. */\nexport function 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/** The builders of the metrics of an aggregation query: any, first, last, count, the numeric functions, distinct count and percentile. */\nexport const metricBuilders = {\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 metricBuilders.first | `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 metricBuilders.sum | `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 metricBuilders.sum | `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 metricBuilders.sum | `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 metricBuilders.sum | `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 metricBuilders.sum | `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"],"mappings":"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"}
|