semanticdb-core 1.1.45 → 1.1.47
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.
|
@@ -7,11 +7,8 @@ const buildExplainResult = (title, values) => ({
|
|
|
7
7
|
title,
|
|
8
8
|
values,
|
|
9
9
|
});
|
|
10
|
-
const buildExplainResultWithEntities = (title, values, entities = []) => ({
|
|
11
|
-
|
|
12
|
-
values,
|
|
13
|
-
entities,
|
|
14
|
-
});
|
|
10
|
+
const buildExplainResultWithEntities = (title, values, entities = []) => (Object.assign({ title,
|
|
11
|
+
values }, (entities.length > 0 ? { entities } : {})));
|
|
15
12
|
const normalizeExplainLogicformLocale = (locale) => {
|
|
16
13
|
if (locale === exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) {
|
|
17
14
|
return locale;
|
|
@@ -71,6 +68,40 @@ const stringifyExplainValue = (value, schemas) => {
|
|
|
71
68
|
}
|
|
72
69
|
return stringifyJson(value);
|
|
73
70
|
};
|
|
71
|
+
const LOGICAL_OPERATOR_LABELS = {
|
|
72
|
+
$and: '且',
|
|
73
|
+
$or: '或',
|
|
74
|
+
};
|
|
75
|
+
const stripExplainKeyPrefix = (segment, key) => {
|
|
76
|
+
const keyPrefix = `${key} `;
|
|
77
|
+
if (segment.startsWith(keyPrefix)) {
|
|
78
|
+
return segment.slice(keyPrefix.length);
|
|
79
|
+
}
|
|
80
|
+
return segment;
|
|
81
|
+
};
|
|
82
|
+
const explainLogicalComparedValue = (key, operator, operatorValue, schemas) => {
|
|
83
|
+
if (!Array.isArray(operatorValue)) {
|
|
84
|
+
return `${key} ${operator} ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
85
|
+
}
|
|
86
|
+
const explainedSegments = operatorValue
|
|
87
|
+
.map((item, index) => {
|
|
88
|
+
if (isCompareOperatorObject(item)) {
|
|
89
|
+
const comparedValue = explainComparedValue(key, item, schemas);
|
|
90
|
+
const normalizedValue = stripExplainKeyPrefix(comparedValue, key);
|
|
91
|
+
return `(${normalizedValue})`;
|
|
92
|
+
}
|
|
93
|
+
return `(= ${stringifyExplainValue(item, schemas)})`;
|
|
94
|
+
})
|
|
95
|
+
.filter((segment) => segment.length > 0);
|
|
96
|
+
if (explainedSegments.length === 0) {
|
|
97
|
+
return `${key} ${operator} []`;
|
|
98
|
+
}
|
|
99
|
+
const [firstSegment, ...restSegments] = explainedSegments;
|
|
100
|
+
const normalizedFirstSegment = firstSegment.startsWith('(= ')
|
|
101
|
+
? `${key} = (${firstSegment.slice(3, -1)})`
|
|
102
|
+
: `${key} ${firstSegment}`;
|
|
103
|
+
return [normalizedFirstSegment, ...restSegments].join(` ${LOGICAL_OPERATOR_LABELS[operator]} `);
|
|
104
|
+
};
|
|
74
105
|
const explainSingleComparedValue = (key, operator, operatorValue, schemas) => {
|
|
75
106
|
if ((operator === '$in' || operator === '$nin') &&
|
|
76
107
|
Array.isArray(operatorValue) &&
|
|
@@ -114,6 +145,9 @@ const explainSingleComparedValue = (key, operator, operatorValue, schemas) => {
|
|
|
114
145
|
if (operator === '$contains') {
|
|
115
146
|
return `${key} 包含 ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
116
147
|
}
|
|
148
|
+
if (operator === '$and' || operator === '$or') {
|
|
149
|
+
return explainLogicalComparedValue(key, operator, operatorValue, schemas);
|
|
150
|
+
}
|
|
117
151
|
return `${key} ${operator} ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
118
152
|
};
|
|
119
153
|
const explainNegatedComparedValue = (key, value, schemas) => {
|
|
@@ -286,7 +320,9 @@ const explainEntityID = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_L
|
|
|
286
320
|
if (!logicform.entity_id) {
|
|
287
321
|
return buildExplainResult('ID', []);
|
|
288
322
|
}
|
|
289
|
-
return
|
|
323
|
+
return buildExplainResultWithEntities('ID', [logicform.entity_id], [
|
|
324
|
+
{ schema: logicform.schema, id: logicform.entity_id },
|
|
325
|
+
]);
|
|
290
326
|
};
|
|
291
327
|
exports.explainEntityID = explainEntityID;
|
|
292
328
|
const explainPreds = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
|
|
@@ -2,8 +2,22 @@ import { LogicformType } from '../logicform';
|
|
|
2
2
|
import { DateValue } from './date';
|
|
3
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
|
+
export declare type QueryLogicalOperand = QueryValueType | QueryValueTypeWithCompareOperator;
|
|
5
6
|
export declare type QueryValueTypeWithCompareOperator = Partial<{
|
|
6
|
-
|
|
7
|
+
$eq: QueryValueType;
|
|
8
|
+
$gt: QueryValueType;
|
|
9
|
+
$gte: QueryValueType;
|
|
10
|
+
$lt: QueryValueType;
|
|
11
|
+
$lte: QueryValueType;
|
|
12
|
+
$ne: QueryValueType;
|
|
13
|
+
$in: QueryValueType;
|
|
14
|
+
$nin: QueryValueType;
|
|
15
|
+
$exists: QueryValueType;
|
|
16
|
+
$regex: QueryValueType;
|
|
17
|
+
$contains: QueryValueType;
|
|
18
|
+
$options: QueryValueType;
|
|
19
|
+
$and: QueryLogicalOperand[];
|
|
20
|
+
$or: QueryLogicalOperand[];
|
|
7
21
|
}> & {
|
|
8
22
|
schema?: never;
|
|
9
23
|
};
|