semanticdb-core 1.1.39 → 1.1.41
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.
|
@@ -2,13 +2,20 @@ import { LogicformType } from './logicform';
|
|
|
2
2
|
import { SchemaType } from '../schema/schema';
|
|
3
3
|
export declare const DEFAULT_EXPLAIN_LOGICFORM_LOCALE = "zh-CN";
|
|
4
4
|
export type ExplainLogicformSchemas = Record<string, SchemaType>;
|
|
5
|
+
export type ExplainLogicformResultItem = {
|
|
6
|
+
title: string;
|
|
7
|
+
values: string[];
|
|
8
|
+
};
|
|
9
|
+
export type ExplainFilterLikeResult = ExplainLogicformResultItem;
|
|
10
|
+
export type ExplainQueryResult = ExplainLogicformResultItem;
|
|
5
11
|
export declare const normalizeExplainLogicformLocale: (locale?: string) => string;
|
|
12
|
+
export declare const stringifyExplainFilterLikeResult: (result: ExplainLogicformResultItem, separator?: string) => string;
|
|
6
13
|
export declare const explainGroupbyLevel: (level?: string) => string;
|
|
7
|
-
export declare const explainSchema: (logicform: LogicformType, schemas: ExplainLogicformSchemas, locale?: string) =>
|
|
8
|
-
export declare const explainQuery: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) =>
|
|
9
|
-
export declare const explainEntityID: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) =>
|
|
10
|
-
export declare const explainPreds: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) =>
|
|
11
|
-
export declare const explainGroupby: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) =>
|
|
12
|
-
export declare const explainLimit: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) =>
|
|
13
|
-
export declare const explainHaving: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) =>
|
|
14
|
-
export declare const explainLogicform: (logicform: LogicformType, schemas: ExplainLogicformSchemas, locale?: string) =>
|
|
14
|
+
export declare const explainSchema: (logicform: LogicformType, schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem;
|
|
15
|
+
export declare const explainQuery: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => ExplainQueryResult;
|
|
16
|
+
export declare const explainEntityID: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem;
|
|
17
|
+
export declare const explainPreds: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem;
|
|
18
|
+
export declare const explainGroupby: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem;
|
|
19
|
+
export declare const explainLimit: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem;
|
|
20
|
+
export declare const explainHaving: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem;
|
|
21
|
+
export declare const explainLogicform: (logicform: LogicformType, schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem[];
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.explainLogicform = exports.explainHaving = exports.explainLimit = exports.explainGroupby = exports.explainPreds = exports.explainEntityID = exports.explainQuery = exports.explainSchema = exports.explainGroupbyLevel = exports.normalizeExplainLogicformLocale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE = void 0;
|
|
3
|
+
exports.explainLogicform = exports.explainHaving = exports.explainLimit = exports.explainGroupby = exports.explainPreds = exports.explainEntityID = exports.explainQuery = exports.explainSchema = exports.explainGroupbyLevel = exports.stringifyExplainFilterLikeResult = exports.normalizeExplainLogicformLocale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE = void 0;
|
|
4
|
+
const logicform_utils_1 = require("./logicform.utils");
|
|
4
5
|
exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE = 'zh-CN';
|
|
6
|
+
const buildExplainResult = (title, values) => ({
|
|
7
|
+
title,
|
|
8
|
+
values,
|
|
9
|
+
});
|
|
5
10
|
const normalizeExplainLogicformLocale = (locale) => {
|
|
6
11
|
if (locale === exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) {
|
|
7
12
|
return locale;
|
|
@@ -27,6 +32,9 @@ const stringifyJson = (value) => {
|
|
|
27
32
|
if (value === undefined) {
|
|
28
33
|
return '无';
|
|
29
34
|
}
|
|
35
|
+
if (typeof value === 'string') {
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
30
38
|
const stringified = JSON.stringify(value);
|
|
31
39
|
return stringified === undefined ? String(value) : stringified;
|
|
32
40
|
};
|
|
@@ -40,26 +48,39 @@ const getEntityIdFromValue = (value) => {
|
|
|
40
48
|
const entityId = value.entity_id;
|
|
41
49
|
return typeof entityId === 'string' && entityId ? entityId : undefined;
|
|
42
50
|
};
|
|
43
|
-
const explainFilterLikeQuery = (query, prefix = '筛选',
|
|
51
|
+
const explainFilterLikeQuery = (query, prefix = '筛选', includeValue = false) => {
|
|
44
52
|
if (!query || Object.keys(query).length === 0) {
|
|
45
|
-
return
|
|
53
|
+
return buildExplainResult(prefix, []);
|
|
46
54
|
}
|
|
47
|
-
const
|
|
48
|
-
.filter((k) => k !== 'entity_id')
|
|
49
|
-
.map((k) => {
|
|
55
|
+
const values = Object.entries(query)
|
|
56
|
+
.filter(([k]) => includeValue || k !== 'entity_id')
|
|
57
|
+
.map(([k, v]) => {
|
|
50
58
|
const key = k.split('_').pop() || '';
|
|
59
|
+
if (includeValue) {
|
|
60
|
+
if (k === 'entity_id') {
|
|
61
|
+
return `ID为${stringifyJson(v)}`;
|
|
62
|
+
}
|
|
63
|
+
return `${key} = ${stringifyJson(v)}`;
|
|
64
|
+
}
|
|
51
65
|
const entityId = getEntityIdFromValue(query[k]);
|
|
52
66
|
if (entityId) {
|
|
53
67
|
return `${key}(${entityId})`;
|
|
54
68
|
}
|
|
55
69
|
return key;
|
|
56
70
|
});
|
|
57
|
-
const queryEntityId = getEntityIdFromValue(query);
|
|
71
|
+
const queryEntityId = includeValue ? undefined : getEntityIdFromValue(query);
|
|
58
72
|
if (queryEntityId) {
|
|
59
|
-
|
|
73
|
+
values.push(`ID为${queryEntityId}`);
|
|
74
|
+
}
|
|
75
|
+
return buildExplainResult(prefix, values);
|
|
76
|
+
};
|
|
77
|
+
const stringifyExplainFilterLikeResult = (result, separator = ' ') => {
|
|
78
|
+
if (result.values.length === 0) {
|
|
79
|
+
return '';
|
|
60
80
|
}
|
|
61
|
-
return
|
|
81
|
+
return `${result.title}${separator}${result.values.join('、')}`;
|
|
62
82
|
};
|
|
83
|
+
exports.stringifyExplainFilterLikeResult = stringifyExplainFilterLikeResult;
|
|
63
84
|
const explainGroupbyLevel = (level) => {
|
|
64
85
|
if (!level) {
|
|
65
86
|
return '';
|
|
@@ -71,54 +92,65 @@ const explainSchema = (logicform, schemas, locale = exports.DEFAULT_EXPLAIN_LOGI
|
|
|
71
92
|
var _a;
|
|
72
93
|
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
73
94
|
if (!logicform.schema) {
|
|
74
|
-
return '
|
|
95
|
+
return buildExplainResult('主题', ['未指定']);
|
|
75
96
|
}
|
|
76
|
-
const
|
|
77
|
-
|
|
97
|
+
const schemaValues = [
|
|
98
|
+
((_a = schemas[logicform.schema]) === null || _a === void 0 ? void 0 : _a.name) || logicform.schema,
|
|
99
|
+
...(logicform.preds || [])
|
|
100
|
+
.map((pred) => {
|
|
101
|
+
var _a;
|
|
102
|
+
if (!pred || typeof pred !== 'object' || !pred.schema) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
return ((_a = schemas[pred.schema]) === null || _a === void 0 ? void 0 : _a.name) || pred.schema;
|
|
106
|
+
})
|
|
107
|
+
.filter((schemaName) => typeof schemaName === 'string' && schemaName.length > 0),
|
|
108
|
+
];
|
|
109
|
+
return buildExplainResult('主题', Array.from(new Set(schemaValues)));
|
|
78
110
|
};
|
|
79
111
|
exports.explainSchema = explainSchema;
|
|
80
112
|
const explainQuery = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
81
113
|
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
82
|
-
return explainFilterLikeQuery(logicform.query, '筛选');
|
|
114
|
+
return explainFilterLikeQuery(logicform.query ? (0, logicform_utils_1.getFlattenQuery)(logicform.query, _schemas) : undefined, '筛选', true);
|
|
83
115
|
};
|
|
84
116
|
exports.explainQuery = explainQuery;
|
|
85
117
|
const explainEntityID = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
86
118
|
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
87
119
|
if (!logicform.entity_id) {
|
|
88
|
-
return '';
|
|
120
|
+
return buildExplainResult('ID', []);
|
|
89
121
|
}
|
|
90
|
-
return
|
|
122
|
+
return buildExplainResult('ID', [logicform.entity_id]);
|
|
91
123
|
};
|
|
92
124
|
exports.explainEntityID = explainEntityID;
|
|
93
125
|
const explainPreds = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
94
126
|
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
95
127
|
if (!logicform.preds || logicform.preds.length === 0) {
|
|
96
|
-
return '';
|
|
128
|
+
return buildExplainResult('计算', []);
|
|
97
129
|
}
|
|
98
|
-
return
|
|
130
|
+
return buildExplainResult('计算', logicform.preds
|
|
131
|
+
.map((p) => p.name)
|
|
132
|
+
.filter((name) => typeof name === 'string' && name.length > 0));
|
|
99
133
|
};
|
|
100
134
|
exports.explainPreds = explainPreds;
|
|
101
135
|
const explainGroupby = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
102
136
|
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
103
137
|
if (!logicform.groupby || logicform.groupby.length === 0) {
|
|
104
|
-
return '';
|
|
138
|
+
return buildExplainResult('分组', []);
|
|
105
139
|
}
|
|
106
|
-
return
|
|
107
|
-
.map((gi) => (0, exports.explainGroupbyLevel)(gi.level) || gi.name || '')
|
|
108
|
-
.join('、')} 分组`;
|
|
140
|
+
return buildExplainResult('分组', logicform.groupby.map((gi) => (0, exports.explainGroupbyLevel)(gi.level) || gi.name || ''));
|
|
109
141
|
};
|
|
110
142
|
exports.explainGroupby = explainGroupby;
|
|
111
143
|
const explainLimit = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
112
144
|
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
113
145
|
if (typeof logicform.limit !== 'number') {
|
|
114
|
-
return '';
|
|
146
|
+
return buildExplainResult('限制', []);
|
|
115
147
|
}
|
|
116
|
-
return
|
|
148
|
+
return buildExplainResult('限制', [`${logicform.limit} 条记录`]);
|
|
117
149
|
};
|
|
118
150
|
exports.explainLimit = explainLimit;
|
|
119
151
|
const explainHaving = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
120
152
|
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
121
|
-
return explainFilterLikeQuery(logicform.having, '
|
|
153
|
+
return explainFilterLikeQuery(logicform.having, '结果过滤');
|
|
122
154
|
};
|
|
123
155
|
exports.explainHaving = explainHaving;
|
|
124
156
|
const explainLogicform = (logicform, schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
@@ -55,7 +55,7 @@ export declare const isDimensionInLogicform: (logicform: LogicformType, dimensio
|
|
|
55
55
|
* }
|
|
56
56
|
* ```
|
|
57
57
|
*/
|
|
58
|
-
export declare const getFlattenQuery: (query: QueryType) => QueryType;
|
|
58
|
+
export declare const getFlattenQuery: (query: QueryType, schemasDict?: Record<string, SchemaType>) => QueryType;
|
|
59
59
|
/**
|
|
60
60
|
* 根据链条字符串在查询对象中查找对应的值
|
|
61
61
|
* @param query - 查询对象
|
|
@@ -216,14 +216,14 @@ exports.isDimensionInLogicform = isDimensionInLogicform;
|
|
|
216
216
|
* }
|
|
217
217
|
* ```
|
|
218
218
|
*/
|
|
219
|
-
const getFlattenQuery = (query) => {
|
|
219
|
+
const getFlattenQuery = (query, schemasDict) => {
|
|
220
220
|
let flattenQuery = {};
|
|
221
221
|
for (const [k, v] of Object.entries(query)) {
|
|
222
222
|
if (Array.isArray(v) && (k === '$and' || k === '$or')) {
|
|
223
223
|
const tmp = [];
|
|
224
224
|
v.forEach((item) => {
|
|
225
225
|
if (typeof item === 'object' && item) {
|
|
226
|
-
tmp.push((0, exports.getFlattenQuery)(item));
|
|
226
|
+
tmp.push((0, exports.getFlattenQuery)(item, schemasDict));
|
|
227
227
|
}
|
|
228
228
|
});
|
|
229
229
|
flattenQuery[k] = tmp;
|
|
@@ -232,11 +232,16 @@ const getFlattenQuery = (query) => {
|
|
|
232
232
|
v &&
|
|
233
233
|
'schema' in v &&
|
|
234
234
|
'query' in v &&
|
|
235
|
-
!('groupby' in v)
|
|
236
|
-
!('entity_id' in v) // entity_id的话,也没必要收起来
|
|
235
|
+
!('groupby' in v) // 不是复合的logicform
|
|
237
236
|
) {
|
|
238
|
-
|
|
239
|
-
const
|
|
237
|
+
const subSchema = typeof v.schema === 'string' && schemasDict ? schemasDict[v.schema] : undefined;
|
|
238
|
+
const idProperty = subSchema ? (0, schema_utils_1.findPropertyByType)('ID', subSchema) : undefined;
|
|
239
|
+
if ('entity_id' in v && !idProperty) {
|
|
240
|
+
flattenQuery[k] = v;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
// 这里是一个logicform。传了schemas时,把entity_id临时映射成ID属性参与拍平。
|
|
244
|
+
const flattenSubQuery = (0, exports.getFlattenQuery)(Object.assign(Object.assign({}, (v.query || {})), ('entity_id' in v && idProperty ? { [idProperty.name]: v.entity_id } : {})), schemasDict);
|
|
240
245
|
for (const [sk, sv] of Object.entries(flattenSubQuery)) {
|
|
241
246
|
if (Array.isArray(sv) &&
|
|
242
247
|
sv.length &&
|