semanticdb-core 1.1.41 → 1.1.42

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,83 @@ const stringifyJson = (value) => {
38
38
  const stringified = JSON.stringify(value);
39
39
  return stringified === undefined ? String(value) : stringified;
40
40
  };
41
+ const isCompareOperatorObject = (value) => {
42
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
43
+ return false;
44
+ }
45
+ const keys = Object.keys(value);
46
+ return keys.length > 0 && keys.every((key) => key.startsWith('$'));
47
+ };
48
+ const isSubQueryLikeValue = (value) => {
49
+ return Boolean(value &&
50
+ typeof value === 'object' &&
51
+ !Array.isArray(value) &&
52
+ 'schema' in value &&
53
+ 'query' in value &&
54
+ !('groupby' in value));
55
+ };
56
+ const explainInlineQueryValues = (query, schemas) => {
57
+ return explainFilterLikeQuery(query ? (0, logicform_utils_1.getFlattenQuery)(query, schemas) : undefined, '', true, schemas).values;
58
+ };
59
+ const stringifyExplainValue = (value, schemas) => {
60
+ if (Array.isArray(value)) {
61
+ return stringifyJson(value);
62
+ }
63
+ if (isCompareOperatorObject(value)) {
64
+ return stringifyJson(value);
65
+ }
66
+ return stringifyJson(value);
67
+ };
68
+ const explainComparedValue = (key, value, schemas) => {
69
+ const segments = Object.entries(value)
70
+ .filter(([operator]) => operator !== '$options')
71
+ .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
+ if (operator === '$ne') {
100
+ return `${key} != ${stringifyExplainValue(operatorValue, schemas)}`;
101
+ }
102
+ if (operator === '$exists') {
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)}`;
115
+ });
116
+ return segments.join(' 且 ');
117
+ };
41
118
  const getEntityIdFromValue = (value) => {
42
119
  if (!value || typeof value !== 'object' || Array.isArray(value)) {
43
120
  return undefined;
@@ -48,7 +125,7 @@ const getEntityIdFromValue = (value) => {
48
125
  const entityId = value.entity_id;
49
126
  return typeof entityId === 'string' && entityId ? entityId : undefined;
50
127
  };
51
- const explainFilterLikeQuery = (query, prefix = '筛选', includeValue = false) => {
128
+ const explainFilterLikeQuery = (query, prefix = '筛选', includeValue = false, schemas = {}) => {
52
129
  if (!query || Object.keys(query).length === 0) {
53
130
  return buildExplainResult(prefix, []);
54
131
  }
@@ -60,7 +137,10 @@ const explainFilterLikeQuery = (query, prefix = '筛选', includeValue = false)
60
137
  if (k === 'entity_id') {
61
138
  return `ID为${stringifyJson(v)}`;
62
139
  }
63
- return `${key} = ${stringifyJson(v)}`;
140
+ if (isCompareOperatorObject(v)) {
141
+ return explainComparedValue(key, v, schemas);
142
+ }
143
+ return `${key} = ${stringifyExplainValue(v, schemas)}`;
64
144
  }
65
145
  const entityId = getEntityIdFromValue(query[k]);
66
146
  if (entityId) {
@@ -111,7 +191,7 @@ const explainSchema = (logicform, schemas, locale = exports.DEFAULT_EXPLAIN_LOGI
111
191
  exports.explainSchema = explainSchema;
112
192
  const explainQuery = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
113
193
  (0, exports.normalizeExplainLogicformLocale)(locale);
114
- return explainFilterLikeQuery(logicform.query ? (0, logicform_utils_1.getFlattenQuery)(logicform.query, _schemas) : undefined, '筛选', true);
194
+ return explainFilterLikeQuery(logicform.query ? (0, logicform_utils_1.getFlattenQuery)(logicform.query, _schemas) : undefined, '筛选', true, _schemas);
115
195
  };
116
196
  exports.explainQuery = explainQuery;
117
197
  const explainEntityID = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
@@ -128,7 +208,16 @@ const explainPreds = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGI
128
208
  return buildExplainResult('计算', []);
129
209
  }
130
210
  return buildExplainResult('计算', logicform.preds
131
- .map((p) => p.name)
211
+ .map((p) => {
212
+ if (typeof p.name !== 'string' || p.name.length === 0) {
213
+ return null;
214
+ }
215
+ const predQueryExplanation = explainFilterLikeQuery(p.query ? (0, logicform_utils_1.getFlattenQuery)(p.query, _schemas) : undefined, '', true, _schemas).values.join('、');
216
+ if (!predQueryExplanation) {
217
+ return p.name;
218
+ }
219
+ return `${p.name}(${predQueryExplanation})`;
220
+ })
132
221
  .filter((name) => typeof name === 'string' && name.length > 0));
133
222
  };
134
223
  exports.explainPreds = explainPreds;
@@ -150,7 +239,7 @@ const explainLimit = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGI
150
239
  exports.explainLimit = explainLimit;
151
240
  const explainHaving = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
152
241
  (0, exports.normalizeExplainLogicformLocale)(locale);
153
- return explainFilterLikeQuery(logicform.having, '结果过滤');
242
+ return explainFilterLikeQuery(logicform.having, '结果过滤', false, _schemas);
154
243
  };
155
244
  exports.explainHaving = explainHaving;
156
245
  const explainLogicform = (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.41",
3
+ "version": "1.1.42",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [