semanticdb-core 1.1.50 → 1.1.52

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.
@@ -56,6 +56,18 @@ const isSubQueryLikeValue = (value) => {
56
56
  'query' in value &&
57
57
  !('groupby' in value));
58
58
  };
59
+ const isCompositeLogicformValue = (value) => {
60
+ return Boolean(value &&
61
+ typeof value === 'object' &&
62
+ !Array.isArray(value) &&
63
+ 'schema' in value &&
64
+ ('preds' in value ||
65
+ 'groupby' in value ||
66
+ 'having' in value ||
67
+ 'limit' in value ||
68
+ 'skip' in value ||
69
+ 'sort' in value));
70
+ };
59
71
  const explainInlineQueryValues = (query, schemas) => {
60
72
  return explainFilterLikeQuery(query ? (0, logicform_utils_1.getFlattenQuery)(query, schemas) : undefined, '', true, schemas).values;
61
73
  };
@@ -79,28 +91,89 @@ const stripExplainKeyPrefix = (segment, key) => {
79
91
  }
80
92
  return segment;
81
93
  };
94
+ const startsWithExplainOperatorPhrase = (segment) => {
95
+ return [
96
+ '>= ',
97
+ '<= ',
98
+ '> ',
99
+ '< ',
100
+ '= ',
101
+ '不等于 ',
102
+ '不属于 ',
103
+ '属于 ',
104
+ '不包含 ',
105
+ '包含 ',
106
+ '不匹配 ',
107
+ '匹配 ',
108
+ '不存在',
109
+ '存在',
110
+ '不满足 ',
111
+ ].some((prefix) => segment.startsWith(prefix));
112
+ };
113
+ const startsWithExplainUnaryPhrase = (segment) => {
114
+ return [
115
+ '不等于 ',
116
+ '不属于 ',
117
+ '属于 ',
118
+ '不包含 ',
119
+ '包含 ',
120
+ '不匹配 ',
121
+ '匹配 ',
122
+ '不存在',
123
+ '存在',
124
+ '不满足 ',
125
+ ].some((prefix) => segment.startsWith(prefix));
126
+ };
127
+ const explainLogicalOperandValue = (key, item, schemas) => {
128
+ if (isCompareOperatorObject(item)) {
129
+ const comparedValue = explainComparedValue(key, item, schemas);
130
+ const normalizedValue = stripExplainKeyPrefix(comparedValue, key);
131
+ if (normalizedValue.startsWith('= ')) {
132
+ return {
133
+ value: normalizedValue.slice(2).trim(),
134
+ isEqualityLiteral: true,
135
+ };
136
+ }
137
+ return {
138
+ value: normalizedValue,
139
+ };
140
+ }
141
+ if (isSubQueryLikeValue(item)) {
142
+ return {
143
+ value: explainInlineQueryValues(item.query, schemas).join('、') || stringifyJson(item),
144
+ };
145
+ }
146
+ if (isPlainObject(item)) {
147
+ return {
148
+ value: explainFilterLikeQuery((0, logicform_utils_1.getFlattenQuery)(item, schemas), '', true, schemas).values.join('、') || stringifyJson(item),
149
+ };
150
+ }
151
+ return {
152
+ value: stringifyExplainValue(item, schemas),
153
+ isEqualityLiteral: true,
154
+ };
155
+ };
82
156
  const explainLogicalComparedValue = (key, operator, operatorValue, schemas) => {
83
157
  if (!Array.isArray(operatorValue)) {
84
158
  return `${key} ${operator} ${stringifyExplainValue(operatorValue, schemas)}`;
85
159
  }
86
160
  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);
161
+ .map((item) => explainLogicalOperandValue(key, item, schemas))
162
+ .filter((segment) => segment.value.length > 0);
96
163
  if (explainedSegments.length === 0) {
97
164
  return `${key} ${operator} []`;
98
165
  }
99
166
  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]} `);
167
+ let normalizedFirstSegment = `${key} = (${firstSegment.value})`;
168
+ if (firstSegment.isEqualityLiteral) {
169
+ normalizedFirstSegment = `${key} = (${firstSegment.value})`;
170
+ }
171
+ else if (startsWithExplainOperatorPhrase(firstSegment.value)) {
172
+ normalizedFirstSegment = startsWithExplainUnaryPhrase(firstSegment.value)
173
+ ? `${key} ${firstSegment.value}`
174
+ : `${key} (${firstSegment.value})`;
175
+ }
176
+ return [normalizedFirstSegment, ...restSegments.map((segment) => `(${segment.value})`)].join(` ${LOGICAL_OPERATOR_LABELS[operator]} `);
104
177
  };
105
178
  const explainSingleComparedValue = (key, operator, operatorValue, schemas) => {
106
179
  if ((operator === '$in' || operator === '$nin') &&
@@ -305,6 +378,12 @@ const stringifyExplainFilterLikeResult = (result, separator = ' ') => {
305
378
  return `${result.title}${separator}${result.values.join('、')}`;
306
379
  };
307
380
  exports.stringifyExplainFilterLikeResult = stringifyExplainFilterLikeResult;
381
+ const stringifyExplainLogicformInline = (logicform, schemas) => {
382
+ return (0, exports.explainLogicform)(logicform, schemas)
383
+ .map((item) => (0, exports.stringifyExplainFilterLikeResult)(item))
384
+ .filter((item) => item.length > 0)
385
+ .join(';');
386
+ };
308
387
  const explainGroupbyLevel = (level) => {
309
388
  if (!level) {
310
389
  return '';
@@ -335,9 +414,18 @@ const explainSchema = (logicform, schemas, locale = exports.DEFAULT_EXPLAIN_LOGI
335
414
  exports.explainSchema = explainSchema;
336
415
  const explainQuery = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
337
416
  (0, exports.normalizeExplainLogicformLocale)(locale);
338
- const query = logicform.query ? (0, logicform_utils_1.getFlattenQuery)(logicform.query, _schemas) : undefined;
339
417
  const entities = collectQueryEntities(logicform, logicform.query);
340
- return buildExplainResultWithEntities('筛选', explainFilterLikeQuery(query, '筛选', true, _schemas).values, entities);
418
+ const values = !logicform.query
419
+ ? []
420
+ : Object.entries(logicform.query)
421
+ .flatMap(([key, value]) => {
422
+ if (isCompositeLogicformValue(value)) {
423
+ return `${formatExplainKey(key)} = (${stringifyExplainLogicformInline(value, _schemas)})`;
424
+ }
425
+ return explainFilterLikeQuery((0, logicform_utils_1.getFlattenQuery)({ [key]: value }, _schemas), '筛选', true, _schemas).values;
426
+ })
427
+ .filter((value) => value.length > 0);
428
+ return buildExplainResultWithEntities('筛选', values, entities);
341
429
  };
342
430
  exports.explainQuery = explainQuery;
343
431
  const explainEntityID = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semanticdb-core",
3
- "version": "1.1.50",
3
+ "version": "1.1.52",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [