semanticdb-core 1.0.8 → 1.0.9
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/index.d.ts +0 -4
- package/dist/index.js +0 -4
- package/dist/logicform/logicform.utils.d.ts +1 -1
- package/dist/logicform/logicform.utils.js +23 -55
- package/dist/logicform/types/date.d.ts +15 -0
- package/dist/logicform/types/date.js +2 -0
- package/dist/logicform/types/query.d.ts +10 -0
- package/dist/logicform/types/query.js +2 -0
- package/dist/schema/schema.d.ts +0 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,3 @@ export * from './schema/schema.utils';
|
|
|
5
5
|
export { getDrilldownDimensions } from './schema/schema.utils/getDrilldownDimensions';
|
|
6
6
|
export * from './logicform/logicform';
|
|
7
7
|
export * from './logicform/logicform.utils';
|
|
8
|
-
export * from './logicform/types/query';
|
|
9
|
-
export * from './logicform/types/date';
|
|
10
|
-
export * from './logicform/types/compare-operator';
|
|
11
|
-
export * from './logicform/types/complex-operator';
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,3 @@ var getDrilldownDimensions_1 = require("./schema/schema.utils/getDrilldownDimens
|
|
|
23
23
|
Object.defineProperty(exports, "getDrilldownDimensions", { enumerable: true, get: function () { return getDrilldownDimensions_1.getDrilldownDimensions; } });
|
|
24
24
|
__exportStar(require("./logicform/logicform"), exports);
|
|
25
25
|
__exportStar(require("./logicform/logicform.utils"), exports);
|
|
26
|
-
__exportStar(require("./logicform/types/query"), exports);
|
|
27
|
-
__exportStar(require("./logicform/types/date"), exports);
|
|
28
|
-
__exportStar(require("./logicform/types/compare-operator"), exports);
|
|
29
|
-
__exportStar(require("./logicform/types/complex-operator"), exports);
|
|
@@ -33,4 +33,4 @@ export declare const isDimensionInLogicform: (logicform: LogicformType, dimensio
|
|
|
33
33
|
* }
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
export declare const getFlattenQuery: (query: QueryType) =>
|
|
36
|
+
export declare const getFlattenQuery: (query: QueryType) => QueryType;
|
|
@@ -13,56 +13,8 @@ exports.getFlattenQuery = exports.isDimensionInLogicform = exports.isDimensionIn
|
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
const isDimensionInQuery = (query, dimension) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let chainedQuery = query;
|
|
19
|
-
for (let i = 0; i < chain.length; i++) {
|
|
20
|
-
const item = chain[i];
|
|
21
|
-
// TBD: 如果是$or, $and怎么办呢?
|
|
22
|
-
if (item === '$or' || item === '$and')
|
|
23
|
-
return false;
|
|
24
|
-
if (typeof chainedQuery !== 'object')
|
|
25
|
-
return false;
|
|
26
|
-
if (!(chainedQuery && item in chainedQuery)) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
// last one
|
|
30
|
-
if (i === chain.length - 1) {
|
|
31
|
-
if (typeof chainedQuery[item] !== 'object' ||
|
|
32
|
-
!(chainedQuery[item] && 'schema' in chainedQuery[item])) {
|
|
33
|
-
if (typeof chainedQuery[item] === 'object' &&
|
|
34
|
-
chainedQuery[item] &&
|
|
35
|
-
'$exists' in chainedQuery[item]) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
// 接下去chainedQuery[item]都是LogicformType
|
|
41
|
-
if (chainedQuery[item].entity_id) {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
// TBD: 如果是$or, $and怎么办呢?
|
|
45
|
-
if (((_b = (_a = chainedQuery[item]) === null || _a === void 0 ? void 0 : _a.query) === null || _b === void 0 ? void 0 : _b.$or) || ((_d = (_c = chainedQuery[item]) === null || _c === void 0 ? void 0 : _c.query) === null || _d === void 0 ? void 0 : _d.$and))
|
|
46
|
-
return false;
|
|
47
|
-
// TODO: 如果是name property,也行的,现在先简单搞一个
|
|
48
|
-
if (chainedQuery[item].query &&
|
|
49
|
-
!('$or' in chainedQuery[item].query) &&
|
|
50
|
-
!('$and' in chainedQuery[item].query) &&
|
|
51
|
-
'别名' in chainedQuery[item].query // TODO: 这里是一个临时的方案,后面需要改成动态获取property
|
|
52
|
-
) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
if (typeof chainedQuery[item] !== 'object' ||
|
|
58
|
-
!(chainedQuery[item] && 'schema' in chainedQuery[item])) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
if (chainedQuery[item].query) {
|
|
62
|
-
chainedQuery = chainedQuery[item].query;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return false;
|
|
16
|
+
const flattenQuery = (0, exports.getFlattenQuery)(query);
|
|
17
|
+
return dimension in flattenQuery;
|
|
66
18
|
};
|
|
67
19
|
exports.isDimensionInQuery = isDimensionInQuery;
|
|
68
20
|
const isDimensionInGroupby = (groupby, dimension) => {
|
|
@@ -106,11 +58,16 @@ exports.isDimensionInLogicform = isDimensionInLogicform;
|
|
|
106
58
|
* ```
|
|
107
59
|
*/
|
|
108
60
|
const getFlattenQuery = (query) => {
|
|
109
|
-
|
|
61
|
+
let flattenQuery = {};
|
|
110
62
|
for (const [k, v] of Object.entries(query)) {
|
|
111
|
-
if (k === '$and' || k === '$or') {
|
|
112
|
-
|
|
113
|
-
|
|
63
|
+
if (Array.isArray(v) && (k === '$and' || k === '$or')) {
|
|
64
|
+
const tmp = [];
|
|
65
|
+
v.forEach((item) => {
|
|
66
|
+
if (typeof item === 'object' && item) {
|
|
67
|
+
tmp.push((0, exports.getFlattenQuery)(item));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
flattenQuery[k] = tmp;
|
|
114
71
|
}
|
|
115
72
|
else if (typeof v === 'object' &&
|
|
116
73
|
v &&
|
|
@@ -122,7 +79,18 @@ const getFlattenQuery = (query) => {
|
|
|
122
79
|
// 这里是一个logicform
|
|
123
80
|
const flattenSubQuery = (0, exports.getFlattenQuery)(v.query || {});
|
|
124
81
|
for (const [sk, sv] of Object.entries(flattenSubQuery)) {
|
|
125
|
-
|
|
82
|
+
if (Array.isArray(sv) &&
|
|
83
|
+
sv.length &&
|
|
84
|
+
(sk === '$or' || sk === '$and') &&
|
|
85
|
+
sv.every((item) => typeof item === 'object' && item)) {
|
|
86
|
+
const obj = Object.assign({}, ...sv);
|
|
87
|
+
for (let i in obj) {
|
|
88
|
+
flattenQuery[`${k}_${i}`] = obj[i];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
flattenQuery[`${k}_${sk}`] = sv;
|
|
93
|
+
}
|
|
126
94
|
}
|
|
127
95
|
}
|
|
128
96
|
else {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare type timewindow = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
|
|
2
|
+
declare type DateValueOffset = {
|
|
3
|
+
$offset: Partial<{
|
|
4
|
+
[K in timewindow]: number;
|
|
5
|
+
}>;
|
|
6
|
+
};
|
|
7
|
+
declare type DateValueBasic = Partial<{
|
|
8
|
+
[K in timewindow]: number;
|
|
9
|
+
}>;
|
|
10
|
+
declare type DateValuePartial = Partial<{
|
|
11
|
+
[K in timewindow as `$${K}`]: number;
|
|
12
|
+
}>;
|
|
13
|
+
declare type DateValueToDate = 'MTD' | 'YTD' | 'QTD' | 'WTD';
|
|
14
|
+
export declare type DateValue = `${number}-${number}-${number} ${number}:${number}:${number}` | DateValueOffset | DateValueBasic | DateValuePartial | DateValueToDate;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogicformType } from '../logicform';
|
|
2
|
+
import { DateValue } from './date';
|
|
3
|
+
export declare type CompareOperator = '$eq' | '$gt' | '$gte' | '$lt' | '$lte' | '$ne' | '$in' | '$nin' | '$exists' | '$regex' | '$options' | '$and' | '$or';
|
|
4
|
+
export declare type QueryValueType = null | string | number | boolean | DateValue | LogicformType | string[] | number[] | boolean[] | DateValue[] | LogicformType[];
|
|
5
|
+
export declare type QueryValueTypeWithCompareOperator = Partial<{
|
|
6
|
+
[K in CompareOperator]: QueryValueType;
|
|
7
|
+
}> & {
|
|
8
|
+
schema?: never;
|
|
9
|
+
};
|
|
10
|
+
export declare type QueryType = Record<string, QueryValueType | QueryValueTypeWithCompareOperator | QueryType[] | undefined>;
|
package/dist/schema/schema.d.ts
CHANGED