semanticdb-core 1.1.42 → 1.1.44
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.
|
@@ -38,6 +38,7 @@ const stringifyJson = (value) => {
|
|
|
38
38
|
const stringified = JSON.stringify(value);
|
|
39
39
|
return stringified === undefined ? String(value) : stringified;
|
|
40
40
|
};
|
|
41
|
+
const formatExplainKey = (key) => key.split('_').join('.');
|
|
41
42
|
const isCompareOperatorObject = (value) => {
|
|
42
43
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
43
44
|
return false;
|
|
@@ -65,53 +66,103 @@ const stringifyExplainValue = (value, schemas) => {
|
|
|
65
66
|
}
|
|
66
67
|
return stringifyJson(value);
|
|
67
68
|
};
|
|
69
|
+
const explainSingleComparedValue = (key, operator, operatorValue, schemas) => {
|
|
70
|
+
if ((operator === '$in' || operator === '$nin') &&
|
|
71
|
+
Array.isArray(operatorValue) &&
|
|
72
|
+
operatorValue.every((item) => isSubQueryLikeValue(item))) {
|
|
73
|
+
const subQueryItems = operatorValue.map((item) => {
|
|
74
|
+
const queryValues = explainInlineQueryValues(item.query, schemas);
|
|
75
|
+
if (item.entity_id) {
|
|
76
|
+
queryValues.push(`ID为${item.entity_id}`);
|
|
77
|
+
}
|
|
78
|
+
return queryValues.join('、') || stringifyJson(item);
|
|
79
|
+
});
|
|
80
|
+
return `${key}${operator === '$in' ? ' 属于' : ' 不属于'}(${subQueryItems.join(';')})`;
|
|
81
|
+
}
|
|
82
|
+
if (operator === '$eq') {
|
|
83
|
+
return `${key} = ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
84
|
+
}
|
|
85
|
+
if (operator === '$gt') {
|
|
86
|
+
return `${key} > ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
87
|
+
}
|
|
88
|
+
if (operator === '$gte') {
|
|
89
|
+
return `${key} >= ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
90
|
+
}
|
|
91
|
+
if (operator === '$lt') {
|
|
92
|
+
return `${key} < ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
93
|
+
}
|
|
94
|
+
if (operator === '$lte') {
|
|
95
|
+
return `${key} <= ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
96
|
+
}
|
|
97
|
+
if (operator === '$exists') {
|
|
98
|
+
return `${key}${operatorValue ? '存在' : '不存在'}`;
|
|
99
|
+
}
|
|
100
|
+
if (operator === '$regex') {
|
|
101
|
+
return `${key} 匹配 ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
102
|
+
}
|
|
103
|
+
if (operator === '$in') {
|
|
104
|
+
return `${key} 属于 ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
105
|
+
}
|
|
106
|
+
if (operator === '$nin') {
|
|
107
|
+
return `${key} 不属于 ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
108
|
+
}
|
|
109
|
+
if (operator === '$contains') {
|
|
110
|
+
return `${key} 包含 ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
111
|
+
}
|
|
112
|
+
return `${key} ${operator} ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
113
|
+
};
|
|
114
|
+
const explainNegatedComparedValue = (key, value, schemas) => {
|
|
115
|
+
const entries = Object.entries(value).filter(([operator]) => operator !== '$options');
|
|
116
|
+
if (entries.length !== 1) {
|
|
117
|
+
return `${key} 不满足(${explainComparedValue(key, value, schemas)})`;
|
|
118
|
+
}
|
|
119
|
+
const [operator, operatorValue] = entries[0];
|
|
120
|
+
if (operator === '$eq') {
|
|
121
|
+
return `${key} != ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
122
|
+
}
|
|
123
|
+
if (operator === '$gt') {
|
|
124
|
+
return `${key} <= ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
125
|
+
}
|
|
126
|
+
if (operator === '$gte') {
|
|
127
|
+
return `${key} < ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
128
|
+
}
|
|
129
|
+
if (operator === '$lt') {
|
|
130
|
+
return `${key} >= ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
131
|
+
}
|
|
132
|
+
if (operator === '$lte') {
|
|
133
|
+
return `${key} > ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
134
|
+
}
|
|
135
|
+
if (operator === '$ne') {
|
|
136
|
+
return `${key} = ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
137
|
+
}
|
|
138
|
+
if (operator === '$exists') {
|
|
139
|
+
return `${key}${operatorValue ? '不存在' : '存在'}`;
|
|
140
|
+
}
|
|
141
|
+
if (operator === '$regex') {
|
|
142
|
+
return `${key} 不匹配 ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
143
|
+
}
|
|
144
|
+
if (operator === '$in') {
|
|
145
|
+
return `${key} 不属于 ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
146
|
+
}
|
|
147
|
+
if (operator === '$nin') {
|
|
148
|
+
return `${key} 属于 ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
149
|
+
}
|
|
150
|
+
if (operator === '$contains') {
|
|
151
|
+
return `${key} 不包含 ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
152
|
+
}
|
|
153
|
+
return `${key} 不满足 ${operator} ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
154
|
+
};
|
|
68
155
|
const explainComparedValue = (key, value, schemas) => {
|
|
69
156
|
const segments = Object.entries(value)
|
|
70
157
|
.filter(([operator]) => operator !== '$options')
|
|
71
158
|
.map(([operator, operatorValue]) => {
|
|
72
|
-
if ((operator === '$in' || operator === '$nin') &&
|
|
73
|
-
Array.isArray(operatorValue) &&
|
|
74
|
-
operatorValue.every((item) => isSubQueryLikeValue(item))) {
|
|
75
|
-
const subQueryItems = operatorValue.map((item) => {
|
|
76
|
-
const queryValues = explainInlineQueryValues(item.query, schemas);
|
|
77
|
-
if (item.entity_id) {
|
|
78
|
-
queryValues.push(`ID为${item.entity_id}`);
|
|
79
|
-
}
|
|
80
|
-
return queryValues.join('、') || stringifyJson(item);
|
|
81
|
-
});
|
|
82
|
-
return `${key}${operator === '$in' ? ' 属于' : ' 不属于'}(${subQueryItems.join(';')})`;
|
|
83
|
-
}
|
|
84
|
-
if (operator === '$eq') {
|
|
85
|
-
return `${key} = ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
86
|
-
}
|
|
87
|
-
if (operator === '$gt') {
|
|
88
|
-
return `${key} > ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
89
|
-
}
|
|
90
|
-
if (operator === '$gte') {
|
|
91
|
-
return `${key} >= ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
92
|
-
}
|
|
93
|
-
if (operator === '$lt') {
|
|
94
|
-
return `${key} < ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
95
|
-
}
|
|
96
|
-
if (operator === '$lte') {
|
|
97
|
-
return `${key} <= ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
98
|
-
}
|
|
99
159
|
if (operator === '$ne') {
|
|
160
|
+
if (isCompareOperatorObject(operatorValue)) {
|
|
161
|
+
return explainNegatedComparedValue(key, operatorValue, schemas);
|
|
162
|
+
}
|
|
100
163
|
return `${key} != ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
101
164
|
}
|
|
102
|
-
|
|
103
|
-
return `${key}${operatorValue ? '存在' : '不存在'}`;
|
|
104
|
-
}
|
|
105
|
-
if (operator === '$regex') {
|
|
106
|
-
return `${key} 匹配 ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
107
|
-
}
|
|
108
|
-
if (operator === '$in') {
|
|
109
|
-
return `${key} in ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
110
|
-
}
|
|
111
|
-
if (operator === '$nin') {
|
|
112
|
-
return `${key} not in ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
113
|
-
}
|
|
114
|
-
return `${key} ${operator} ${stringifyExplainValue(operatorValue, schemas)}`;
|
|
165
|
+
return explainSingleComparedValue(key, operator, operatorValue, schemas);
|
|
115
166
|
});
|
|
116
167
|
return segments.join(' 且 ');
|
|
117
168
|
};
|
|
@@ -132,7 +183,7 @@ const explainFilterLikeQuery = (query, prefix = '筛选', includeValue = false,
|
|
|
132
183
|
const values = Object.entries(query)
|
|
133
184
|
.filter(([k]) => includeValue || k !== 'entity_id')
|
|
134
185
|
.map(([k, v]) => {
|
|
135
|
-
const key = k
|
|
186
|
+
const key = formatExplainKey(k);
|
|
136
187
|
if (includeValue) {
|
|
137
188
|
if (k === 'entity_id') {
|
|
138
189
|
return `ID为${stringifyJson(v)}`;
|
|
@@ -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) {
|