semanticdb-core 1.1.49 → 1.1.51

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.
@@ -79,28 +79,89 @@ const stripExplainKeyPrefix = (segment, key) => {
79
79
  }
80
80
  return segment;
81
81
  };
82
+ const startsWithExplainOperatorPhrase = (segment) => {
83
+ return [
84
+ '>= ',
85
+ '<= ',
86
+ '> ',
87
+ '< ',
88
+ '= ',
89
+ '不等于 ',
90
+ '不属于 ',
91
+ '属于 ',
92
+ '不包含 ',
93
+ '包含 ',
94
+ '不匹配 ',
95
+ '匹配 ',
96
+ '不存在',
97
+ '存在',
98
+ '不满足 ',
99
+ ].some((prefix) => segment.startsWith(prefix));
100
+ };
101
+ const startsWithExplainUnaryPhrase = (segment) => {
102
+ return [
103
+ '不等于 ',
104
+ '不属于 ',
105
+ '属于 ',
106
+ '不包含 ',
107
+ '包含 ',
108
+ '不匹配 ',
109
+ '匹配 ',
110
+ '不存在',
111
+ '存在',
112
+ '不满足 ',
113
+ ].some((prefix) => segment.startsWith(prefix));
114
+ };
115
+ const explainLogicalOperandValue = (key, item, schemas) => {
116
+ if (isCompareOperatorObject(item)) {
117
+ const comparedValue = explainComparedValue(key, item, schemas);
118
+ const normalizedValue = stripExplainKeyPrefix(comparedValue, key);
119
+ if (normalizedValue.startsWith('= ')) {
120
+ return {
121
+ value: normalizedValue.slice(2).trim(),
122
+ isEqualityLiteral: true,
123
+ };
124
+ }
125
+ return {
126
+ value: normalizedValue,
127
+ };
128
+ }
129
+ if (isSubQueryLikeValue(item)) {
130
+ return {
131
+ value: explainInlineQueryValues(item.query, schemas).join('、') || stringifyJson(item),
132
+ };
133
+ }
134
+ if (isPlainObject(item)) {
135
+ return {
136
+ value: explainFilterLikeQuery((0, logicform_utils_1.getFlattenQuery)(item, schemas), '', true, schemas).values.join('、') || stringifyJson(item),
137
+ };
138
+ }
139
+ return {
140
+ value: stringifyExplainValue(item, schemas),
141
+ isEqualityLiteral: true,
142
+ };
143
+ };
82
144
  const explainLogicalComparedValue = (key, operator, operatorValue, schemas) => {
83
145
  if (!Array.isArray(operatorValue)) {
84
146
  return `${key} ${operator} ${stringifyExplainValue(operatorValue, schemas)}`;
85
147
  }
86
148
  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);
149
+ .map((item) => explainLogicalOperandValue(key, item, schemas))
150
+ .filter((segment) => segment.value.length > 0);
96
151
  if (explainedSegments.length === 0) {
97
152
  return `${key} ${operator} []`;
98
153
  }
99
154
  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]} `);
155
+ let normalizedFirstSegment = `${key} = (${firstSegment.value})`;
156
+ if (firstSegment.isEqualityLiteral) {
157
+ normalizedFirstSegment = `${key} = (${firstSegment.value})`;
158
+ }
159
+ else if (startsWithExplainOperatorPhrase(firstSegment.value)) {
160
+ normalizedFirstSegment = startsWithExplainUnaryPhrase(firstSegment.value)
161
+ ? `${key} ${firstSegment.value}`
162
+ : `${key} (${firstSegment.value})`;
163
+ }
164
+ return [normalizedFirstSegment, ...restSegments.map((segment) => `(${segment.value})`)].join(` ${LOGICAL_OPERATOR_LABELS[operator]} `);
104
165
  };
105
166
  const explainSingleComparedValue = (key, operator, operatorValue, schemas) => {
106
167
  if ((operator === '$in' || operator === '$nin') &&
@@ -157,7 +218,7 @@ const explainNegatedComparedValue = (key, value, schemas) => {
157
218
  }
158
219
  const [operator, operatorValue] = entries[0];
159
220
  if (operator === '$eq') {
160
- return `${key} != ${stringifyExplainValue(operatorValue, schemas)}`;
221
+ return `${key} 不等于 ${stringifyExplainValue(operatorValue, schemas)}`;
161
222
  }
162
223
  if (operator === '$gt') {
163
224
  return `${key} <= ${stringifyExplainValue(operatorValue, schemas)}`;
@@ -199,7 +260,7 @@ const explainComparedValue = (key, value, schemas) => {
199
260
  if (isCompareOperatorObject(operatorValue)) {
200
261
  return explainNegatedComparedValue(key, operatorValue, schemas);
201
262
  }
202
- return `${key} != ${stringifyExplainValue(operatorValue, schemas)}`;
263
+ return `${key} 不等于 ${stringifyExplainValue(operatorValue, schemas)}`;
203
264
  }
204
265
  return explainSingleComparedValue(key, operator, operatorValue, schemas);
205
266
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semanticdb-core",
3
- "version": "1.1.49",
3
+ "version": "1.1.51",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [