semanticdb-core 1.1.38 → 1.1.40
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,12 +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
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
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.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}`);
|
|
60
74
|
}
|
|
61
|
-
return
|
|
75
|
+
return buildExplainResult(prefix, values);
|
|
62
76
|
};
|
|
77
|
+
const stringifyExplainFilterLikeResult = (result, separator = ' ') => {
|
|
78
|
+
if (result.values.length === 0) {
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
return `${result.title}${separator}${result.values.join('、')}`;
|
|
82
|
+
};
|
|
83
|
+
exports.stringifyExplainFilterLikeResult = stringifyExplainFilterLikeResult;
|
|
63
84
|
const explainGroupbyLevel = (level) => {
|
|
64
85
|
if (!level) {
|
|
65
86
|
return '';
|
|
@@ -71,46 +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) : undefined, '筛选', true);
|
|
83
115
|
};
|
|
84
116
|
exports.explainQuery = explainQuery;
|
|
117
|
+
const explainEntityID = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
118
|
+
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
119
|
+
if (!logicform.entity_id) {
|
|
120
|
+
return buildExplainResult('ID', []);
|
|
121
|
+
}
|
|
122
|
+
return buildExplainResult('ID', [logicform.entity_id]);
|
|
123
|
+
};
|
|
124
|
+
exports.explainEntityID = explainEntityID;
|
|
85
125
|
const explainPreds = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
86
126
|
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
87
127
|
if (!logicform.preds || logicform.preds.length === 0) {
|
|
88
|
-
return '';
|
|
128
|
+
return buildExplainResult('计算', []);
|
|
89
129
|
}
|
|
90
|
-
return
|
|
130
|
+
return buildExplainResult('计算', logicform.preds
|
|
131
|
+
.map((p) => p.name)
|
|
132
|
+
.filter((name) => typeof name === 'string' && name.length > 0));
|
|
91
133
|
};
|
|
92
134
|
exports.explainPreds = explainPreds;
|
|
93
135
|
const explainGroupby = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
94
136
|
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
95
137
|
if (!logicform.groupby || logicform.groupby.length === 0) {
|
|
96
|
-
return '';
|
|
138
|
+
return buildExplainResult('分组', []);
|
|
97
139
|
}
|
|
98
|
-
return
|
|
99
|
-
.map((gi) => (0, exports.explainGroupbyLevel)(gi.level) || gi.name || '')
|
|
100
|
-
.join('、')} 分组`;
|
|
140
|
+
return buildExplainResult('分组', logicform.groupby.map((gi) => (0, exports.explainGroupbyLevel)(gi.level) || gi.name || ''));
|
|
101
141
|
};
|
|
102
142
|
exports.explainGroupby = explainGroupby;
|
|
103
143
|
const explainLimit = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
104
144
|
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
105
145
|
if (typeof logicform.limit !== 'number') {
|
|
106
|
-
return '';
|
|
146
|
+
return buildExplainResult('限制', []);
|
|
107
147
|
}
|
|
108
|
-
return
|
|
148
|
+
return buildExplainResult('限制', [`${logicform.limit} 条记录`]);
|
|
109
149
|
};
|
|
110
150
|
exports.explainLimit = explainLimit;
|
|
111
151
|
const explainHaving = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
112
152
|
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
113
|
-
return explainFilterLikeQuery(logicform.having, '
|
|
153
|
+
return explainFilterLikeQuery(logicform.having, '结果过滤');
|
|
114
154
|
};
|
|
115
155
|
exports.explainHaving = explainHaving;
|
|
116
156
|
const explainLogicform = (logicform, schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
@@ -118,6 +158,7 @@ const explainLogicform = (logicform, schemas, locale = exports.DEFAULT_EXPLAIN_L
|
|
|
118
158
|
return [
|
|
119
159
|
(0, exports.explainSchema)(logicform, schemas, normalizedLocale),
|
|
120
160
|
(0, exports.explainQuery)(logicform, schemas, normalizedLocale),
|
|
161
|
+
(0, exports.explainEntityID)(logicform, schemas, normalizedLocale),
|
|
121
162
|
(0, exports.explainPreds)(logicform, schemas, normalizedLocale),
|
|
122
163
|
(0, exports.explainGroupby)(logicform, schemas, normalizedLocale),
|
|
123
164
|
(0, exports.explainLimit)(logicform, schemas, normalizedLocale),
|