semanticdb-core 1.1.46 → 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.
|
@@ -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) => {
|
|
@@ -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
|
};
|