semanticdb-core 1.1.46 → 1.1.48
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.
|
@@ -68,6 +68,40 @@ const stringifyExplainValue = (value, schemas) => {
|
|
|
68
68
|
}
|
|
69
69
|
return stringifyJson(value);
|
|
70
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
|
+
};
|
|
71
105
|
const explainSingleComparedValue = (key, operator, operatorValue, schemas) => {
|
|
72
106
|
if ((operator === '$in' || operator === '$nin') &&
|
|
73
107
|
Array.isArray(operatorValue) &&
|
|
@@ -111,6 +145,9 @@ const explainSingleComparedValue = (key, operator, operatorValue, schemas) => {
|
|
|
111
145
|
if (operator === '$contains') {
|
|
112
146
|
return `${key} 包含 ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
113
147
|
}
|
|
148
|
+
if (operator === '$and' || operator === '$or') {
|
|
149
|
+
return explainLogicalComparedValue(key, operator, operatorValue, schemas);
|
|
150
|
+
}
|
|
114
151
|
return `${key} ${operator} ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
115
152
|
};
|
|
116
153
|
const explainNegatedComparedValue = (key, value, schemas) => {
|
|
@@ -168,6 +205,28 @@ const explainComparedValue = (key, value, schemas) => {
|
|
|
168
205
|
});
|
|
169
206
|
return segments.join(' 且 ');
|
|
170
207
|
};
|
|
208
|
+
const explainTopLevelLogicalQuery = (operator, operatorValue, includeValue, schemas) => {
|
|
209
|
+
if (!Array.isArray(operatorValue)) {
|
|
210
|
+
return `${operator} ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
211
|
+
}
|
|
212
|
+
const explainedSegments = operatorValue
|
|
213
|
+
.map((item) => {
|
|
214
|
+
if (!isPlainObject(item)) {
|
|
215
|
+
return stringifyExplainValue(item, schemas);
|
|
216
|
+
}
|
|
217
|
+
const itemValues = explainFilterLikeQuery(item, '', includeValue, schemas).values;
|
|
218
|
+
if (itemValues.length === 0) {
|
|
219
|
+
return '';
|
|
220
|
+
}
|
|
221
|
+
return itemValues.join('、');
|
|
222
|
+
})
|
|
223
|
+
.filter((segment) => segment.length > 0)
|
|
224
|
+
.map((segment) => `(${segment})`);
|
|
225
|
+
if (explainedSegments.length === 0) {
|
|
226
|
+
return `${operator} []`;
|
|
227
|
+
}
|
|
228
|
+
return explainedSegments.join(` ${LOGICAL_OPERATOR_LABELS[operator]} `);
|
|
229
|
+
};
|
|
171
230
|
const getEntityIdFromValue = (value) => {
|
|
172
231
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
173
232
|
return undefined;
|
|
@@ -214,6 +273,9 @@ const explainFilterLikeQuery = (query, prefix = '筛选', includeValue = false,
|
|
|
214
273
|
const values = Object.entries(query)
|
|
215
274
|
.filter(([k]) => includeValue || k !== 'entity_id')
|
|
216
275
|
.map(([k, v]) => {
|
|
276
|
+
if (k === '$and' || k === '$or') {
|
|
277
|
+
return explainTopLevelLogicalQuery(k, v, includeValue, schemas);
|
|
278
|
+
}
|
|
217
279
|
const key = formatExplainKey(k);
|
|
218
280
|
if (includeValue) {
|
|
219
281
|
if (k === 'entity_id') {
|
|
@@ -2,9 +2,26 @@ 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
|
};
|
|
10
|
-
export declare type QueryType = Record<string, QueryValueType | QueryValueTypeWithCompareOperator | QueryType[] | undefined
|
|
24
|
+
export declare type QueryType = Record<string, QueryValueType | QueryValueTypeWithCompareOperator | QueryType[] | undefined> & Partial<{
|
|
25
|
+
$and: QueryType[];
|
|
26
|
+
$or: QueryType[];
|
|
27
|
+
}>;
|