semanticdb-core 1.1.43 → 1.1.45
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,9 +2,14 @@ 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 ExplainLogicformEntityRef = {
|
|
6
|
+
schema: string;
|
|
7
|
+
id: string;
|
|
8
|
+
};
|
|
5
9
|
export type ExplainLogicformResultItem = {
|
|
6
10
|
title: string;
|
|
7
11
|
values: string[];
|
|
12
|
+
entities?: ExplainLogicformEntityRef[];
|
|
8
13
|
};
|
|
9
14
|
export type ExplainFilterLikeResult = ExplainLogicformResultItem;
|
|
10
15
|
export type ExplainQueryResult = ExplainLogicformResultItem;
|
|
@@ -7,6 +7,11 @@ const buildExplainResult = (title, values) => ({
|
|
|
7
7
|
title,
|
|
8
8
|
values,
|
|
9
9
|
});
|
|
10
|
+
const buildExplainResultWithEntities = (title, values, entities = []) => ({
|
|
11
|
+
title,
|
|
12
|
+
values,
|
|
13
|
+
entities,
|
|
14
|
+
});
|
|
10
15
|
const normalizeExplainLogicformLocale = (locale) => {
|
|
11
16
|
if (locale === exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) {
|
|
12
17
|
return locale;
|
|
@@ -38,6 +43,7 @@ const stringifyJson = (value) => {
|
|
|
38
43
|
const stringified = JSON.stringify(value);
|
|
39
44
|
return stringified === undefined ? String(value) : stringified;
|
|
40
45
|
};
|
|
46
|
+
const formatExplainKey = (key) => key.split('_').join('.');
|
|
41
47
|
const isCompareOperatorObject = (value) => {
|
|
42
48
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
43
49
|
return false;
|
|
@@ -175,6 +181,35 @@ const getEntityIdFromValue = (value) => {
|
|
|
175
181
|
const entityId = value.entity_id;
|
|
176
182
|
return typeof entityId === 'string' && entityId ? entityId : undefined;
|
|
177
183
|
};
|
|
184
|
+
const isPlainObject = (value) => {
|
|
185
|
+
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
186
|
+
};
|
|
187
|
+
const collectQueryEntitiesFromValue = (value, fallbackSchema, entities) => {
|
|
188
|
+
if (!isPlainObject(value)) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const schema = typeof value.schema === 'string' && value.schema ? value.schema : fallbackSchema;
|
|
192
|
+
const entityId = getEntityIdFromValue(value);
|
|
193
|
+
if (schema && entityId) {
|
|
194
|
+
entities.push({ schema, id: entityId });
|
|
195
|
+
}
|
|
196
|
+
for (const nestedValue of Object.values(value)) {
|
|
197
|
+
if (Array.isArray(nestedValue)) {
|
|
198
|
+
for (const item of nestedValue) {
|
|
199
|
+
collectQueryEntitiesFromValue(item, schema, entities);
|
|
200
|
+
}
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
collectQueryEntitiesFromValue(nestedValue, schema, entities);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const collectQueryEntities = (logicform, query) => {
|
|
207
|
+
const entities = [];
|
|
208
|
+
if (query) {
|
|
209
|
+
collectQueryEntitiesFromValue(query, logicform.schema, entities);
|
|
210
|
+
}
|
|
211
|
+
return entities.filter((entity, index, allEntities) => allEntities.findIndex((item) => item.schema === entity.schema && item.id === entity.id) === index);
|
|
212
|
+
};
|
|
178
213
|
const explainFilterLikeQuery = (query, prefix = '筛选', includeValue = false, schemas = {}) => {
|
|
179
214
|
if (!query || Object.keys(query).length === 0) {
|
|
180
215
|
return buildExplainResult(prefix, []);
|
|
@@ -182,7 +217,7 @@ const explainFilterLikeQuery = (query, prefix = '筛选', includeValue = false,
|
|
|
182
217
|
const values = Object.entries(query)
|
|
183
218
|
.filter(([k]) => includeValue || k !== 'entity_id')
|
|
184
219
|
.map(([k, v]) => {
|
|
185
|
-
const key = k
|
|
220
|
+
const key = formatExplainKey(k);
|
|
186
221
|
if (includeValue) {
|
|
187
222
|
if (k === 'entity_id') {
|
|
188
223
|
return `ID为${stringifyJson(v)}`;
|
|
@@ -241,7 +276,9 @@ const explainSchema = (logicform, schemas, locale = exports.DEFAULT_EXPLAIN_LOGI
|
|
|
241
276
|
exports.explainSchema = explainSchema;
|
|
242
277
|
const explainQuery = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
243
278
|
(0, exports.normalizeExplainLogicformLocale)(locale);
|
|
244
|
-
|
|
279
|
+
const query = logicform.query ? (0, logicform_utils_1.getFlattenQuery)(logicform.query, _schemas) : undefined;
|
|
280
|
+
const entities = collectQueryEntities(logicform, logicform.query);
|
|
281
|
+
return buildExplainResultWithEntities('筛选', explainFilterLikeQuery(query, '筛选', true, _schemas).values, entities);
|
|
245
282
|
};
|
|
246
283
|
exports.explainQuery = explainQuery;
|
|
247
284
|
const explainEntityID = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
@@ -2,6 +2,11 @@ import { RepresentationType } from '../common/representation';
|
|
|
2
2
|
import { PropertyType } from '../schema/property';
|
|
3
3
|
import { SchemaType } from '../schema/schema';
|
|
4
4
|
import { QueryType } from './types/query';
|
|
5
|
+
export type LogicformOutputTypeValue = 'url' | 'data' | 'export' | 'sql' | 'sqlComponents';
|
|
6
|
+
export interface LogicformOutputType {
|
|
7
|
+
type: LogicformOutputTypeValue;
|
|
8
|
+
filename?: string;
|
|
9
|
+
}
|
|
5
10
|
export interface PredItemType {
|
|
6
11
|
operator?: string;
|
|
7
12
|
pred?: string | PredItemType;
|
|
@@ -35,6 +40,7 @@ export interface LogicformType {
|
|
|
35
40
|
[key: string]: 1 | -1;
|
|
36
41
|
};
|
|
37
42
|
having?: QueryType;
|
|
43
|
+
output?: LogicformOutputType;
|
|
38
44
|
limit?: number;
|
|
39
45
|
limitBy?: number;
|
|
40
46
|
skip?: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LogicformType } from '../logicform';
|
|
2
2
|
import { DateValue } from './date';
|
|
3
|
-
export declare type CompareOperator = '$eq' | '$gt' | '$gte' | '$lt' | '$lte' | '$ne' | '$in' | '$nin' | '$exists' | '$regex' | '$options' | '$and' | '$or';
|
|
3
|
+
export declare type CompareOperator = '$eq' | '$gt' | '$gte' | '$lt' | '$lte' | '$ne' | '$in' | '$nin' | '$exists' | '$regex' | '$contains' | '$options' | '$and' | '$or';
|
|
4
4
|
export declare type QueryValueType = null | string | number | boolean | DateValue | LogicformType | string[] | number[] | boolean[] | DateValue[] | LogicformType[];
|
|
5
5
|
export declare type QueryValueTypeWithCompareOperator = Partial<{
|
|
6
6
|
[K in CompareOperator]: QueryValueType;
|
|
@@ -239,6 +239,27 @@ const formatWithNumeralSafely = (value, format) => {
|
|
|
239
239
|
const formattedValue = (0, numeral_1.default)(value).format(format);
|
|
240
240
|
return formattedValue === 'NaN' ? `${value}` : formattedValue;
|
|
241
241
|
};
|
|
242
|
+
const formatObjectValue = (schema, value) => {
|
|
243
|
+
var _a, _b;
|
|
244
|
+
const nameProperty = getNameProperty(schema);
|
|
245
|
+
if (Array.isArray(value)) {
|
|
246
|
+
return value
|
|
247
|
+
.map((item) => {
|
|
248
|
+
var _a, _b;
|
|
249
|
+
if (item === null || item === undefined)
|
|
250
|
+
return '';
|
|
251
|
+
if (typeof item !== 'object')
|
|
252
|
+
return `${item}`;
|
|
253
|
+
return (_b = (_a = item[nameProperty.name]) !== null && _a !== void 0 ? _a : item._id) !== null && _b !== void 0 ? _b : JSON.stringify(item);
|
|
254
|
+
})
|
|
255
|
+
.filter((item) => item !== '')
|
|
256
|
+
.join('、');
|
|
257
|
+
}
|
|
258
|
+
if (value && typeof value === 'object') {
|
|
259
|
+
return (_b = (_a = value[nameProperty.name]) !== null && _a !== void 0 ? _a : value._id) !== null && _b !== void 0 ? _b : JSON.stringify(value);
|
|
260
|
+
}
|
|
261
|
+
return `${value}`;
|
|
262
|
+
};
|
|
242
263
|
/**
|
|
243
264
|
*
|
|
244
265
|
* @param schema
|
|
@@ -256,8 +277,7 @@ const formatWithProperty = (schema, property, value, withUnit = false) => {
|
|
|
256
277
|
const formatter = (0, exports.getFormatter)(property);
|
|
257
278
|
let finalValue = `${value}`;
|
|
258
279
|
if (property.type === 'object' && typeof value === 'object') {
|
|
259
|
-
|
|
260
|
-
finalValue = value[nameProperty.name];
|
|
280
|
+
finalValue = formatObjectValue(schema, value);
|
|
261
281
|
}
|
|
262
282
|
else if (property.primal_type === 'date') {
|
|
263
283
|
if (formatter) {
|