flowerbi 1.21.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/QueryColumn.js +1 -0
- package/dist/QueryColumn.js.map +1 -1
- package/dist/QueryValues.js +1 -0
- package/dist/QueryValues.js.map +1 -1
- package/dist/arrayHelpers.js +2 -1
- package/dist/arrayHelpers.js.map +1 -1
- package/dist/executeQuery.js +6 -5
- package/dist/executeQuery.js.map +1 -1
- package/dist/executeQuery.test.js +6 -5
- package/dist/executeQuery.test.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +20 -10
- package/dist/index.js.map +1 -1
- package/dist/queryModel.d.ts +2 -2
- package/dist/queryModel.js +4 -3
- package/dist/queryModel.js.map +1 -1
- package/package.json +10 -15
- package/src/index.ts +0 -1
- package/src/queryModel.ts +1 -1
- package/dist/fillDates.d.ts +0 -99
- package/dist/fillDates.js +0 -169
- package/dist/fillDates.js.map +0 -1
- package/dist/fillDates.test.d.ts +0 -1
- package/dist/fillDates.test.js +0 -211
- package/dist/fillDates.test.js.map +0 -1
- package/src/fillDates.test.ts +0 -234
- package/src/fillDates.ts +0 -217
package/dist/QueryColumn.js
CHANGED
package/dist/QueryColumn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryColumn.js","sourceRoot":"","sources":["../src/QueryColumn.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"QueryColumn.js","sourceRoot":"","sources":["../src/QueryColumn.ts"],"names":[],"mappings":";;;AASA;;;GAGG;AACH;IAEI;;OAEG;IACH,qBAA4B,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAEpC,iCAAW,GAAnB,UAAoB,eAAgC,EAAE,OAAsB;QACxE,OAAO;YACH,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,QAAQ,EAAE,eAAe;YACzB,OAAO,SAAA;SACV,CAAC;IACN,CAAC;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E,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,iCAAW,GAAX,UAAY,KAAQ;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,8BAAQ,GAAR,UAAS,KAAQ;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;IAED;;;OAGG;IACH,0CAAoB,GAApB,UAAqB,KAAQ;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,uCAAiB,GAAjB,UAAkB,KAAQ;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,wBAAE,GAAF,UAAG,KAA4C;QAC3C,OAAO;YACH,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,QAAQ,EAAE,IAAI;YACd,KAAK,OAAA;SACR,CAAC;IACN,CAAC;IACL,kBAAC;AAAD,CAAC,AArID,IAqIC;AArIY,kCAAW"}
|
package/dist/QueryValues.js
CHANGED
package/dist/QueryValues.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryValues.js","sourceRoot":"","sources":["../src/QueryValues.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"QueryValues.js","sourceRoot":"","sources":["../src/QueryValues.ts"],"names":[],"mappings":";;;AAsBA;IACI,wBACoB,MAA8B,EAC9B,MAA0C;QAD1C,WAAM,GAAN,MAAM,CAAwB;QAC9B,WAAM,GAAN,MAAM,CAAoC;IAAG,CAAC;IAElE,mCAAU,GAAV,UAA4C,GAAM;;QAC9C,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,CAAC,CAAC;QAE3B,IAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClC,IAAM,KAAK,GAAG,MAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,mCAAI,CAAC,CAAC;QACpC,IAAM,OAAO,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;QAC3D,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;IAC3C,CAAC;IACL,qBAAC;AAAD,CAAC,AAbD,IAaC;AAbY,wCAAc;AAe3B;IAGI,0BAAY,MAA8B;QACtC,IAAI,CAAC,MAAM,GAAG,MAAmD,CAAC;IACtE,CAAC;IAED,qCAAU,GAAV;QACI,OAAO,GAAG,CAAC;IACf,CAAC;IACL,uBAAC;AAAD,CAAC,AAVD,IAUC;AAVY,4CAAgB"}
|
package/dist/arrayHelpers.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.keysOf = exports.distinct = void 0;
|
|
3
4
|
/**
|
|
4
5
|
* Returns the distinct (unique) values from an array. The comparison
|
|
5
6
|
* method is very simplistic: all values are converted to strings
|
|
@@ -10,7 +11,7 @@ function distinct(arr) {
|
|
|
10
11
|
var map = {};
|
|
11
12
|
for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
|
|
12
13
|
var item = arr_1[_i];
|
|
13
|
-
map[""
|
|
14
|
+
map["".concat(item)] = item;
|
|
14
15
|
}
|
|
15
16
|
return Object.values(map);
|
|
16
17
|
}
|
package/dist/arrayHelpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrayHelpers.js","sourceRoot":"","sources":["../src/arrayHelpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"arrayHelpers.js","sourceRoot":"","sources":["../src/arrayHelpers.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,SAAgB,QAAQ,CAAI,GAAQ;IAChC,IAAM,GAAG,GAAyB,EAAE,CAAC;IAErC,KAAmB,UAAG,EAAH,WAAG,EAAH,iBAAG,EAAH,IAAG,EAAE;QAAnB,IAAM,IAAI,YAAA;QACX,GAAG,CAAC,UAAG,IAAI,CAAE,CAAC,GAAG,IAAI,CAAC;KACzB;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC;AARD,4BAQC;AAED;;;;;;;;;GASG;AACH,SAAgB,MAAM,CAAI,GAAM;IAC5B,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAgB,CAAC;AAC3C,CAAC;AAFD,wBAEC"}
|
package/dist/executeQuery.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expandQueryResult = exports.getAggregateValuesOnly = exports.expandQueryRecord = exports.jsonifyQuery = void 0;
|
|
3
4
|
var queryModel_1 = require("./queryModel");
|
|
4
5
|
/**
|
|
5
6
|
* Converts a statically-typed {@link Query} into the {@link QueryJson}
|
|
@@ -9,8 +10,8 @@ var queryModel_1 = require("./queryModel");
|
|
|
9
10
|
function jsonifyQuery(query) {
|
|
10
11
|
var select = query.select, filters = query.filters, orderBy = query.orderBy, totals = query.totals, take = query.take, skip = query.skip;
|
|
11
12
|
return {
|
|
12
|
-
select: queryModel_1.getColumnPropsOnly(select).map(function (key) { return select[key].name; }),
|
|
13
|
-
aggregations: queryModel_1.getAggregatePropsOnly(select).map(function (key) { return select[key]; }),
|
|
13
|
+
select: (0, queryModel_1.getColumnPropsOnly)(select).map(function (key) { return select[key].name; }),
|
|
14
|
+
aggregations: (0, queryModel_1.getAggregatePropsOnly)(select).map(function (key) { return select[key]; }),
|
|
14
15
|
filters: filters !== null && filters !== void 0 ? filters : [],
|
|
15
16
|
orderBy: orderBy !== null && orderBy !== void 0 ? orderBy : [],
|
|
16
17
|
totals: totals !== null && totals !== void 0 ? totals : false,
|
|
@@ -29,12 +30,12 @@ exports.jsonifyQuery = jsonifyQuery;
|
|
|
29
30
|
function expandQueryRecord(select, record) {
|
|
30
31
|
var result = {};
|
|
31
32
|
var n = 0;
|
|
32
|
-
for (var _i = 0, _a = queryModel_1.getAggregatePropsOnly(select); _i < _a.length; _i++) {
|
|
33
|
+
for (var _i = 0, _a = (0, queryModel_1.getAggregatePropsOnly)(select); _i < _a.length; _i++) {
|
|
33
34
|
var key = _a[_i];
|
|
34
35
|
result[key] = record.aggregated[n++];
|
|
35
36
|
}
|
|
36
37
|
n = 0;
|
|
37
|
-
for (var _b = 0, _c = queryModel_1.getColumnPropsOnly(select); _b < _c.length; _b++) {
|
|
38
|
+
for (var _b = 0, _c = (0, queryModel_1.getColumnPropsOnly)(select); _b < _c.length; _b++) {
|
|
38
39
|
var key = _c[_b];
|
|
39
40
|
result[key] = record.selected[n++];
|
|
40
41
|
}
|
|
@@ -52,7 +53,7 @@ exports.expandQueryRecord = expandQueryRecord;
|
|
|
52
53
|
function getAggregateValuesOnly(select, record) {
|
|
53
54
|
var result = {};
|
|
54
55
|
var n = 0;
|
|
55
|
-
for (var _i = 0, _a = queryModel_1.getAggregatePropsOnly(select); _i < _a.length; _i++) {
|
|
56
|
+
for (var _i = 0, _a = (0, queryModel_1.getAggregatePropsOnly)(select); _i < _a.length; _i++) {
|
|
56
57
|
var key = _a[_i];
|
|
57
58
|
result[key] = record.aggregated[n++];
|
|
58
59
|
}
|
package/dist/executeQuery.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeQuery.js","sourceRoot":"","sources":["../src/executeQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"executeQuery.js","sourceRoot":"","sources":["../src/executeQuery.ts"],"names":[],"mappings":";;;AAAA,2CAAuI;AAiDvI;;;;GAIG;AACH,SAAgB,YA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AAC;IACN,KAAkB,UAA0B,EAA1B,SAAA,+BAAkB,EAAC,MAAM,CAAC,EAA1B,cAA0B,EAA1B,IAA0B,EAAE;QAAzC,IAAM,GAAG,SAAA;QACV,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;KACtC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAlBD,8CAkBC;AAED;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CAClC,MAAS,EACT,MAAuB;IAGvB,IAAM,MAAM,GAAQ,EAAE,CAAC;IAEvB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,KAAkB,UAA6B,EAA7B,SAAA,kCAAqB,EAAC,MAAM,CAAC,EAA7B,cAA6B,EAA7B,IAA6B,EAAE;QAA5C,IAAM,GAAG,SAAA;QACV,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;KACxC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAbD,wDAaC;AAoBD;;;;;GAKG;AACH,SAAgB,iBAAiB,CAC7B,MAAS,EACT,MAAuB;IAGvB,OAAO;QACH,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC,EAA5B,CAA4B,CAAC;QAC9D,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,sBAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;KACzE,CAAC;AACN,CAAC;AATD,8CASC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Bug = exports.Customer = void 0;
|
|
3
4
|
var executeQuery_1 = require("./executeQuery");
|
|
4
5
|
var QueryColumn_1 = require("./QueryColumn");
|
|
5
6
|
exports.Customer = {
|
|
@@ -11,7 +12,7 @@ exports.Bug = {
|
|
|
11
12
|
CustomerId: new QueryColumn_1.QueryColumn("Bug.CustomerId"),
|
|
12
13
|
};
|
|
13
14
|
test("jsonifies mixed columns", function () {
|
|
14
|
-
expect(executeQuery_1.jsonifyQuery({
|
|
15
|
+
expect((0, executeQuery_1.jsonifyQuery)({
|
|
15
16
|
select: {
|
|
16
17
|
customer: exports.Customer.CustomerName,
|
|
17
18
|
bugCount: exports.Bug.Id.count()
|
|
@@ -31,7 +32,7 @@ test("jsonifies mixed columns", function () {
|
|
|
31
32
|
});
|
|
32
33
|
});
|
|
33
34
|
test("jsonifies select", function () {
|
|
34
|
-
expect(executeQuery_1.jsonifyQuery({
|
|
35
|
+
expect((0, executeQuery_1.jsonifyQuery)({
|
|
35
36
|
select: {
|
|
36
37
|
customer: exports.Customer.CustomerName,
|
|
37
38
|
}
|
|
@@ -46,7 +47,7 @@ test("jsonifies select", function () {
|
|
|
46
47
|
});
|
|
47
48
|
});
|
|
48
49
|
test("jsonifies params", function () {
|
|
49
|
-
expect(executeQuery_1.jsonifyQuery({
|
|
50
|
+
expect((0, executeQuery_1.jsonifyQuery)({
|
|
50
51
|
select: {},
|
|
51
52
|
skip: 3,
|
|
52
53
|
take: 42,
|
|
@@ -62,7 +63,7 @@ test("jsonifies params", function () {
|
|
|
62
63
|
});
|
|
63
64
|
});
|
|
64
65
|
test("jsonifies filters", function () {
|
|
65
|
-
expect(executeQuery_1.jsonifyQuery({
|
|
66
|
+
expect((0, executeQuery_1.jsonifyQuery)({
|
|
66
67
|
select: {
|
|
67
68
|
bugCount: exports.Bug.Id.count([
|
|
68
69
|
exports.Customer.CustomerName.lessThan("z")
|
|
@@ -94,7 +95,7 @@ test("jsonifies filters", function () {
|
|
|
94
95
|
});
|
|
95
96
|
});
|
|
96
97
|
test("jsonifies orderBy", function () {
|
|
97
|
-
expect(executeQuery_1.jsonifyQuery({
|
|
98
|
+
expect((0, executeQuery_1.jsonifyQuery)({
|
|
98
99
|
select: {},
|
|
99
100
|
orderBy: [
|
|
100
101
|
exports.Customer.CustomerName.descending()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeQuery.test.js","sourceRoot":"","sources":["../src/executeQuery.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"executeQuery.test.js","sourceRoot":"","sources":["../src/executeQuery.test.ts"],"names":[],"mappings":";;;AAAA,+CAA8C;AAC9C,6CAA4C;AAE/B,QAAA,QAAQ,GAAG;IACpB,EAAE,EAAE,IAAI,yBAAW,CAAS,aAAa,CAAC;IAC1C,YAAY,EAAE,IAAI,yBAAW,CAAS,uBAAuB,CAAC;CACjE,CAAC;AAEW,QAAA,GAAG,GAAG;IACf,EAAE,EAAE,IAAI,yBAAW,CAAS,QAAQ,CAAC;IACrC,UAAU,EAAE,IAAI,yBAAW,CAAS,gBAAgB,CAAC;CACxD,CAAC;AAEF,IAAI,CAAC,yBAAyB,EAAE;IAC5B,MAAM,CAAC,IAAA,2BAAY,EAAC;QAChB,MAAM,EAAE;YACJ,QAAQ,EAAE,gBAAQ,CAAC,YAAY;YAC/B,QAAQ,EAAE,WAAG,CAAC,EAAE,CAAC,KAAK,EAAE;SAC3B;KACJ,CAAC,CAAC,CAAC,aAAa,CAAC;QACd,MAAM,EAAE,CAAC,uBAAuB,CAAC;QACjC,YAAY,EAAE,CAAC;gBACX,MAAM,EAAE,QAAQ;gBAChB,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,SAAS;aACrB,CAAC;QACF,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE;QACX,IAAI,EAAE,CAAC;QACP,IAAI,EAAE,GAAG;QACT,MAAM,EAAE,KAAK;KAChB,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,kBAAkB,EAAE;IACrB,MAAM,CAAC,IAAA,2BAAY,EAAC;QAChB,MAAM,EAAE;YACJ,QAAQ,EAAE,gBAAQ,CAAC,YAAY;SAClC;KACJ,CAA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AM,EAAE,uBAAuB;gBAC/B,QAAQ,EAAE,GAAG;gBACb,KAAK,EAAE,GAAG;aACb,CAAC;QACF,OAAO,EAAE,EAAE;QACX,IAAI,EAAE,CAAC;QACP,IAAI,EAAE,GAAG;QACT,MAAM,EAAE,KAAK;KAChB,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,mBAAmB,EAAE;IACtB,MAAM,CAAC,IAAA,2BAAY,EAAC;QAChB,MAAM,EAAE,EAAE;QACV,OAAO,EAAE;YACL,gBAAQ,CAAC,YAAY,CAAC,UAAU,EAAE;SACrC;KACJ,CAAC,CAAC,CAAC,aAAa,CAAC;QACd,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,EAAE;QAChB,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,CAAC;gBACN,MAAM,EAAE,uBAAuB;gBAC/B,UAAU,EAAE,IAAI;aACnB,CAAC;QACF,IAAI,EAAE,CAAC;QACP,IAAI,EAAE,GAAG;QACT,MAAM,EAAE,KAAK;KAChB,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
__export(require("./fillDates"));
|
|
17
|
+
__exportStar(require("./arrayHelpers"), exports);
|
|
18
|
+
__exportStar(require("./executeQuery"), exports);
|
|
19
|
+
__exportStar(require("./QueryColumn"), exports);
|
|
20
|
+
__exportStar(require("./QueryJson"), exports);
|
|
21
|
+
__exportStar(require("./queryModel"), exports);
|
|
22
|
+
__exportStar(require("./QueryValues"), exports);
|
|
13
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,iDAA+B;AAC/B,gDAA8B;AAC9B,8CAA4B;AAC5B,+CAA4B;AAC5B,gDAA8B"}
|
package/dist/queryModel.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export declare type AggregatePropsOnly<T extends QuerySelect> = AggregatePropsOn
|
|
|
53
53
|
*
|
|
54
54
|
* @param select the `select` object from a query
|
|
55
55
|
*/
|
|
56
|
-
export declare function getAggregatePropsOnly<T extends QuerySelect>(select: T):
|
|
56
|
+
export declare function getAggregatePropsOnly<T extends QuerySelect>(select: T): AggregatePropsOnly<T>[];
|
|
57
57
|
/**
|
|
58
58
|
* An object that contains a subset of the the named properties from a query's
|
|
59
59
|
* `select` object, those that refer to aggregated values (hence all are of
|
|
@@ -86,7 +86,7 @@ export declare type ColumnPropsOnly<T extends QuerySelect> = ColumnPropsOnlyHelp
|
|
|
86
86
|
*
|
|
87
87
|
* @param select the `select` object from a query
|
|
88
88
|
*/
|
|
89
|
-
export declare function getColumnPropsOnly<T extends QuerySelect>(select: T):
|
|
89
|
+
export declare function getColumnPropsOnly<T extends QuerySelect>(select: T): ColumnPropsOnly<T>[];
|
|
90
90
|
/**
|
|
91
91
|
* Returns the plain column objects referred to in a query, ignoring
|
|
92
92
|
* aggregated columns.
|
package/dist/queryModel.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getColumnsOnly = exports.getColumnPropsOnly = exports.getAggregatePropsOnly = void 0;
|
|
3
4
|
var arrayHelpers_1 = require("./arrayHelpers");
|
|
4
5
|
var QueryColumn_1 = require("./QueryColumn");
|
|
5
6
|
/**
|
|
@@ -16,7 +17,7 @@ var QueryColumn_1 = require("./QueryColumn");
|
|
|
16
17
|
* @param select the `select` object from a query
|
|
17
18
|
*/
|
|
18
19
|
function getAggregatePropsOnly(select) {
|
|
19
|
-
var keys = arrayHelpers_1.keysOf(select).filter(function (x) { return !(select[x] instanceof QueryColumn_1.QueryColumn); });
|
|
20
|
+
var keys = (0, arrayHelpers_1.keysOf)(select).filter(function (x) { return !(select[x] instanceof QueryColumn_1.QueryColumn); });
|
|
20
21
|
return keys;
|
|
21
22
|
}
|
|
22
23
|
exports.getAggregatePropsOnly = getAggregatePropsOnly;
|
|
@@ -34,7 +35,7 @@ exports.getAggregatePropsOnly = getAggregatePropsOnly;
|
|
|
34
35
|
* @param select the `select` object from a query
|
|
35
36
|
*/
|
|
36
37
|
function getColumnPropsOnly(select) {
|
|
37
|
-
var keys = arrayHelpers_1.keysOf(select).filter(function (x) { return select[x] instanceof QueryColumn_1.QueryColumn; });
|
|
38
|
+
var keys = (0, arrayHelpers_1.keysOf)(select).filter(function (x) { return select[x] instanceof QueryColumn_1.QueryColumn; });
|
|
38
39
|
return keys;
|
|
39
40
|
}
|
|
40
41
|
exports.getColumnPropsOnly = getColumnPropsOnly;
|
|
@@ -44,7 +45,7 @@ exports.getColumnPropsOnly = getColumnPropsOnly;
|
|
|
44
45
|
* @param select the `select` object from a query
|
|
45
46
|
*/
|
|
46
47
|
function getColumnsOnly(select) {
|
|
47
|
-
return arrayHelpers_1.keysOf(select)
|
|
48
|
+
return (0, arrayHelpers_1.keysOf)(select)
|
|
48
49
|
.map(function (k) { return select[k]; })
|
|
49
50
|
.filter(function (x) { return x instanceof QueryColumn_1.QueryColumn; })
|
|
50
51
|
.map(function (x) { return x; });
|
package/dist/queryModel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryModel.js","sourceRoot":"","sources":["../src/queryModel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"queryModel.js","sourceRoot":"","sources":["../src/queryModel.ts"],"names":[],"mappings":";;;AAAA,+CAAwC;AACxC,6CAA4C;AAkD5C;;;;;;;;;;;;GAYG;AACH,SAAgB,qBAAqB,CAAwB,MAAS;IAClE,IAAM,IAAI,GAAG,IAAA,qBAAM,EAAC,MAAM,CAAC,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,yBAAW,CAAC,EAAnC,CAAmC,CAAC,CAAA;IAC5E,OAAO,IAA+B,CAAC;AAC3C,CAAC;AAHD,sDAGC;AAwBD;;;;;;;;;;;;GAYG;AACH,SAAgB,kBAAkB,CAAwB,MAAS;IAC/D,IAAM,IAAI,GAAG,IAAA,qBAAM,EAAC,MAAM,CAAC,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,YAAY,yBAAW,EAAhC,CAAgC,CAAC,CAAA;IACzE,OAAO,IAA4B,CAAC;AACxC,CAAC;AAHD,gDAGC;AAED;;;;GAIG;AACH,SAAgB,cAAc,CAAC,MAAmB;IAC9C,OAAO,IAAA,qBAAM,EAAC,MAAM,CAAC;SAChB,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,EAAT,CAAS,CAAC;SACnB,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,YAAY,yBAAW,EAAxB,CAAwB,CAAC;SACrC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAC,CAAsB,EAAvB,CAAuB,CAAC,CAAC;AAC3C,CAAC;AALD,wCAKC"}
|
package/package.json
CHANGED
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flowerbi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"author": "Daniel Earwicker <dan@earwicker.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "FlowerBI: ultra-minimal BI analytics query and UI tools",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@types/jest": "^
|
|
11
|
-
"jest": "^
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
10
|
+
"@types/jest": "^27.4.0",
|
|
11
|
+
"jest": "^27.4.7",
|
|
12
|
+
"prettier": "^2.5.1",
|
|
13
|
+
"ts-jest": "^27.1.3",
|
|
14
|
+
"typedoc": "^0.22.11",
|
|
15
|
+
"typescript": "^4.5.5"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@types/json-stable-stringify": "^1.0.
|
|
19
|
-
"json-stable-stringify": "^1.0.1"
|
|
20
|
-
"prettier": "^2.0.5",
|
|
21
|
-
"typescript": "~3.8.3"
|
|
22
|
-
},
|
|
23
|
-
"peerDependencies": {
|
|
24
|
-
"moment": "^2.27.0"
|
|
18
|
+
"@types/json-stable-stringify": "^1.0.33",
|
|
19
|
+
"json-stable-stringify": "^1.0.1"
|
|
25
20
|
},
|
|
26
21
|
"scripts": {
|
|
27
22
|
"build": "tsc",
|
|
28
23
|
"watch": "tsc -w",
|
|
29
24
|
"test": "jest",
|
|
30
|
-
"docs": "typedoc --
|
|
25
|
+
"docs": "typedoc --excludePrivate --readme home.md --out ../../../docs/typedoc/flowerbi src",
|
|
31
26
|
"prepare": "npm run test && npm run build && npm run docs"
|
|
32
27
|
}
|
|
33
28
|
}
|
package/src/index.ts
CHANGED
package/src/queryModel.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { keysOf } from "./arrayHelpers";
|
|
2
2
|
import { QueryColumn } from "./QueryColumn";
|
|
3
|
-
import { AggregationJson,
|
|
3
|
+
import { AggregationJson, FilterJson, OrderingJson } from "./QueryJson";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Defines the kinds of member that can appear in the `select` object of a query.
|
package/dist/fillDates.d.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { Moment } from "moment";
|
|
2
|
-
export declare type FillDate = Date | string | number | Moment;
|
|
3
|
-
/**
|
|
4
|
-
* Three operations on dates used by {@link fillDates}.
|
|
5
|
-
*/
|
|
6
|
-
export declare type FillDateType = {
|
|
7
|
-
/** Round the given date down to the nearest whole unit (e.g. start of month, quarter, year) */
|
|
8
|
-
round(d: Moment): Moment;
|
|
9
|
-
/** Format the given date to a string */
|
|
10
|
-
format(d: Moment): string;
|
|
11
|
-
/** Increment the date by the unit. The given date will already be rounded down. */
|
|
12
|
-
increment(d: Moment): Moment;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Standard built-in date types. To customise, implement the {@link FillDateType} interface.
|
|
16
|
-
*/
|
|
17
|
-
export declare const dateTypes: {
|
|
18
|
-
readonly days: FillDateType;
|
|
19
|
-
readonly months: FillDateType;
|
|
20
|
-
readonly quarters: FillDateType;
|
|
21
|
-
readonly years: FillDateType;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Examines a set of dates and chooses the most specific type that includes them all. If
|
|
25
|
-
* all fall on Jan, 1 then `years` is chosen, and so on.
|
|
26
|
-
*/
|
|
27
|
-
export declare function detectDateType(dates: Moment[]): FillDateType;
|
|
28
|
-
/** Options for {@link fillDates} function. */
|
|
29
|
-
export interface FillDatesOptions<T, R> {
|
|
30
|
-
/** The records to base the filled list on. */
|
|
31
|
-
records: T[];
|
|
32
|
-
/** The operations to use for rounding, incrementing and formatting dates. */
|
|
33
|
-
type?: FillDateType;
|
|
34
|
-
/** Extracts a date value from a record in the input list. */
|
|
35
|
-
getDate(record: T): FillDate;
|
|
36
|
-
/**
|
|
37
|
-
* Generate a record for a date, from the formatted {@link dateText} and
|
|
38
|
-
* the input record for that date, if any.
|
|
39
|
-
*/
|
|
40
|
-
fill(dateText: string, record: T | undefined): R;
|
|
41
|
-
/**
|
|
42
|
-
* The minimum date to generate. It will be rounded down by the {@link type}
|
|
43
|
-
* so doesn't need to be on an exact boundary.
|
|
44
|
-
*/
|
|
45
|
-
min?: FillDate;
|
|
46
|
-
/**
|
|
47
|
-
* The maximum date to generate. It will be rounded down by the {@link type}
|
|
48
|
-
* so doesn't need to be on an exact boundary.
|
|
49
|
-
*/
|
|
50
|
-
max?: FillDate;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* When querying for a time series chart, e.g. x-axis is _Month_ and y-axis is
|
|
54
|
-
* _Total Sales_, there may be months where nothing was sold so they are
|
|
55
|
-
* missing from the list of records.
|
|
56
|
-
*
|
|
57
|
-
* To render a proper time-series, we need these gaps to be filled in with
|
|
58
|
-
* runs of fake records that give zero amounts for those months. e.g.
|
|
59
|
-
*
|
|
60
|
-
* ```ts
|
|
61
|
-
* const filled = fillDates({
|
|
62
|
-
* records: [
|
|
63
|
-
* { date: '2020-04-01', totalSales: 10 },
|
|
64
|
-
* { date: '2020-06-01', totalSales: 4 },
|
|
65
|
-
* { date: '2020-07-01', totalSales: 9 },
|
|
66
|
-
* ],
|
|
67
|
-
* type: dateTypes.months,
|
|
68
|
-
* getDate: rec => rec.date,
|
|
69
|
-
* fill: (label, rec) => ({
|
|
70
|
-
* label,
|
|
71
|
-
* totalSales: 0,
|
|
72
|
-
* ...rec
|
|
73
|
-
* })
|
|
74
|
-
* });
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* In the above example we add a `label` property to all the records, and
|
|
78
|
-
* for the records that fill the gaps we set the `totalSales` property to 0.
|
|
79
|
-
* For the real records, `...rec` will copy the real value of `totalSales`.
|
|
80
|
-
*
|
|
81
|
-
* To do this, we need to know:
|
|
82
|
-
*
|
|
83
|
-
* - how to round a date to the start of a unit (year, month, quarter),
|
|
84
|
-
* - how to increment a date by that unit,
|
|
85
|
-
* - how to format a date to a string for display.
|
|
86
|
-
*
|
|
87
|
-
* These operations are encapsulated by the {@link FillDateType} interface.
|
|
88
|
-
* Several built-in types are provided in {@link dateTypes}, but you can
|
|
89
|
-
* implement your own.
|
|
90
|
-
*
|
|
91
|
-
* Optionally you can also pass `min` and `max` dates, which will cause
|
|
92
|
-
* extra records to be added at the start and end of the range if necessary.
|
|
93
|
-
*
|
|
94
|
-
* If you don't pass a `type`, a suitable type will be detected based on
|
|
95
|
-
* how the input record dates fall on unit boundaries.
|
|
96
|
-
*/
|
|
97
|
-
export declare function fillDates<T, R>({ records, getDate, fill, min, max, type }: FillDatesOptions<T, R>): R[];
|
|
98
|
-
/** @deprecated */
|
|
99
|
-
export declare function smartDates<T, R>(records: T[], min: FillDate | undefined, max: FillDate | undefined, getDate: (record: T) => FillDate, fill: (dateText: string, record: T | undefined) => R): R[];
|
package/dist/fillDates.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
3
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
4
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
5
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
6
|
-
r[k] = a[j];
|
|
7
|
-
return r;
|
|
8
|
-
};
|
|
9
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
var moment_1 = __importDefault(require("moment"));
|
|
14
|
-
function parseDate(val) {
|
|
15
|
-
// Ensure a numeric year is not interpreted as offset from 1970!
|
|
16
|
-
if (typeof val === "number") {
|
|
17
|
-
val = "" + val;
|
|
18
|
-
}
|
|
19
|
-
return moment_1.default(val);
|
|
20
|
-
}
|
|
21
|
-
var days = {
|
|
22
|
-
round: function (d) {
|
|
23
|
-
return d.clone().startOf("day");
|
|
24
|
-
},
|
|
25
|
-
format: function (d) {
|
|
26
|
-
return d.format("ll");
|
|
27
|
-
},
|
|
28
|
-
increment: function (d) {
|
|
29
|
-
return d.clone().add(1, "day");
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
var months = {
|
|
33
|
-
round: function (d) {
|
|
34
|
-
return d.clone().startOf("month");
|
|
35
|
-
},
|
|
36
|
-
format: function (d) {
|
|
37
|
-
return d.format("MMM YYYY");
|
|
38
|
-
},
|
|
39
|
-
increment: function (d) {
|
|
40
|
-
return d.clone().add(1, "month");
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
var quarters = {
|
|
44
|
-
round: function (d) {
|
|
45
|
-
return d.clone().startOf("quarter");
|
|
46
|
-
},
|
|
47
|
-
format: function (d) {
|
|
48
|
-
var monthFirst = d.format("MMM");
|
|
49
|
-
var monthLast = d.clone().add(2, "months").format("MMM");
|
|
50
|
-
var year = d.format("YYYY");
|
|
51
|
-
return monthFirst + "-" + monthLast + " " + year;
|
|
52
|
-
},
|
|
53
|
-
increment: function (d) {
|
|
54
|
-
return d.clone().add(3, "months");
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
var years = {
|
|
58
|
-
round: function (d) {
|
|
59
|
-
return d.clone().startOf("year");
|
|
60
|
-
},
|
|
61
|
-
format: function (d) {
|
|
62
|
-
return d.format("YYYY");
|
|
63
|
-
},
|
|
64
|
-
increment: function (d) {
|
|
65
|
-
return d.clone().add(1, "year");
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Standard built-in date types. To customise, implement the {@link FillDateType} interface.
|
|
70
|
-
*/
|
|
71
|
-
exports.dateTypes = {
|
|
72
|
-
days: days, months: months, quarters: quarters, years: years
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Examines a set of dates and chooses the most specific type that includes them all. If
|
|
76
|
-
* all fall on Jan, 1 then `years` is chosen, and so on.
|
|
77
|
-
*/
|
|
78
|
-
function detectDateType(dates) {
|
|
79
|
-
return !dates.every(function (x) { return x.date() === 1; }) ? exports.dateTypes.days :
|
|
80
|
-
!dates.every(function (x) { return x.month() % 3 === 0; }) ? exports.dateTypes.months :
|
|
81
|
-
!dates.every(function (x) { return x.month() === 0; }) ? exports.dateTypes.quarters :
|
|
82
|
-
exports.dateTypes.years;
|
|
83
|
-
}
|
|
84
|
-
exports.detectDateType = detectDateType;
|
|
85
|
-
/**
|
|
86
|
-
* When querying for a time series chart, e.g. x-axis is _Month_ and y-axis is
|
|
87
|
-
* _Total Sales_, there may be months where nothing was sold so they are
|
|
88
|
-
* missing from the list of records.
|
|
89
|
-
*
|
|
90
|
-
* To render a proper time-series, we need these gaps to be filled in with
|
|
91
|
-
* runs of fake records that give zero amounts for those months. e.g.
|
|
92
|
-
*
|
|
93
|
-
* ```ts
|
|
94
|
-
* const filled = fillDates({
|
|
95
|
-
* records: [
|
|
96
|
-
* { date: '2020-04-01', totalSales: 10 },
|
|
97
|
-
* { date: '2020-06-01', totalSales: 4 },
|
|
98
|
-
* { date: '2020-07-01', totalSales: 9 },
|
|
99
|
-
* ],
|
|
100
|
-
* type: dateTypes.months,
|
|
101
|
-
* getDate: rec => rec.date,
|
|
102
|
-
* fill: (label, rec) => ({
|
|
103
|
-
* label,
|
|
104
|
-
* totalSales: 0,
|
|
105
|
-
* ...rec
|
|
106
|
-
* })
|
|
107
|
-
* });
|
|
108
|
-
* ```
|
|
109
|
-
*
|
|
110
|
-
* In the above example we add a `label` property to all the records, and
|
|
111
|
-
* for the records that fill the gaps we set the `totalSales` property to 0.
|
|
112
|
-
* For the real records, `...rec` will copy the real value of `totalSales`.
|
|
113
|
-
*
|
|
114
|
-
* To do this, we need to know:
|
|
115
|
-
*
|
|
116
|
-
* - how to round a date to the start of a unit (year, month, quarter),
|
|
117
|
-
* - how to increment a date by that unit,
|
|
118
|
-
* - how to format a date to a string for display.
|
|
119
|
-
*
|
|
120
|
-
* These operations are encapsulated by the {@link FillDateType} interface.
|
|
121
|
-
* Several built-in types are provided in {@link dateTypes}, but you can
|
|
122
|
-
* implement your own.
|
|
123
|
-
*
|
|
124
|
-
* Optionally you can also pass `min` and `max` dates, which will cause
|
|
125
|
-
* extra records to be added at the start and end of the range if necessary.
|
|
126
|
-
*
|
|
127
|
-
* If you don't pass a `type`, a suitable type will be detected based on
|
|
128
|
-
* how the input record dates fall on unit boundaries.
|
|
129
|
-
*/
|
|
130
|
-
function fillDates(_a) {
|
|
131
|
-
var records = _a.records, getDate = _a.getDate, fill = _a.fill, min = _a.min, max = _a.max, type = _a.type;
|
|
132
|
-
records = __spreadArrays(records);
|
|
133
|
-
records.sort(function (x, y) { return parseDate(getDate(x)).diff(parseDate(getDate(y))); });
|
|
134
|
-
type = type !== null && type !== void 0 ? type : detectDateType(records.map(function (d) { return parseDate(getDate(d)); }));
|
|
135
|
-
var results = [];
|
|
136
|
-
var latest = undefined;
|
|
137
|
-
var lower = min ? type.round(parseDate(min)) : undefined;
|
|
138
|
-
for (var _i = 0, records_1 = records; _i < records_1.length; _i++) {
|
|
139
|
-
var record = records_1[_i];
|
|
140
|
-
var current = parseDate(getDate(record));
|
|
141
|
-
for (;;) {
|
|
142
|
-
latest = latest ? type.increment(latest) : lower;
|
|
143
|
-
if (!latest || latest >= current) {
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
results.push(fill(type.format(latest), undefined));
|
|
147
|
-
}
|
|
148
|
-
results.push(fill(type.format(current), record));
|
|
149
|
-
latest = current;
|
|
150
|
-
}
|
|
151
|
-
if (latest && max) {
|
|
152
|
-
var upper = type.round(parseDate(max));
|
|
153
|
-
for (;;) {
|
|
154
|
-
latest = type.increment(latest);
|
|
155
|
-
if (latest > upper) {
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
results.push(fill(type.format(latest), undefined));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return results;
|
|
162
|
-
}
|
|
163
|
-
exports.fillDates = fillDates;
|
|
164
|
-
/** @deprecated */
|
|
165
|
-
function smartDates(records, min, max, getDate, fill) {
|
|
166
|
-
return fillDates({ records: records, min: min, max: max, getDate: getDate, fill: fill });
|
|
167
|
-
}
|
|
168
|
-
exports.smartDates = smartDates;
|
|
169
|
-
//# sourceMappingURL=fillDates.js.map
|
package/dist/fillDates.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fillDates.js","sourceRoot":"","sources":["../src/fillDates.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAwC;AAIxC,SAAS,SAAS,CAAC,GAAa;IAC5B,gEAAgE;IAChE,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QACzB,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC;KAClB;IAED,OAAO,gBAAM,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAcD,IAAM,IAAI,GAAiB;IACvB,KAAK,YAAC,CAAC;QACH,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,YAAC,CAAC;QACJ,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IACD,SAAS,YAAC,CAAC;QACP,OAAO,CAAC,CAAC,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