semanticdb-core 1.1.42 → 1.1.43

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.
@@ -65,53 +65,103 @@ const stringifyExplainValue = (value, schemas) => {
65
65
  }
66
66
  return stringifyJson(value);
67
67
  };
68
+ const explainSingleComparedValue = (key, operator, operatorValue, schemas) => {
69
+ if ((operator === '$in' || operator === '$nin') &&
70
+ Array.isArray(operatorValue) &&
71
+ operatorValue.every((item) => isSubQueryLikeValue(item))) {
72
+ const subQueryItems = operatorValue.map((item) => {
73
+ const queryValues = explainInlineQueryValues(item.query, schemas);
74
+ if (item.entity_id) {
75
+ queryValues.push(`ID为${item.entity_id}`);
76
+ }
77
+ return queryValues.join('、') || stringifyJson(item);
78
+ });
79
+ return `${key}${operator === '$in' ? ' 属于' : ' 不属于'}(${subQueryItems.join(';')})`;
80
+ }
81
+ if (operator === '$eq') {
82
+ return `${key} = ${stringifyExplainValue(operatorValue, schemas)}`;
83
+ }
84
+ if (operator === '$gt') {
85
+ return `${key} > ${stringifyExplainValue(operatorValue, schemas)}`;
86
+ }
87
+ if (operator === '$gte') {
88
+ return `${key} >= ${stringifyExplainValue(operatorValue, schemas)}`;
89
+ }
90
+ if (operator === '$lt') {
91
+ return `${key} < ${stringifyExplainValue(operatorValue, schemas)}`;
92
+ }
93
+ if (operator === '$lte') {
94
+ return `${key} <= ${stringifyExplainValue(operatorValue, schemas)}`;
95
+ }
96
+ if (operator === '$exists') {
97
+ return `${key}${operatorValue ? '存在' : '不存在'}`;
98
+ }
99
+ if (operator === '$regex') {
100
+ return `${key} 匹配 ${stringifyExplainValue(operatorValue, schemas)}`;
101
+ }
102
+ if (operator === '$in') {
103
+ return `${key} 属于 ${stringifyExplainValue(operatorValue, schemas)}`;
104
+ }
105
+ if (operator === '$nin') {
106
+ return `${key} 不属于 ${stringifyExplainValue(operatorValue, schemas)}`;
107
+ }
108
+ if (operator === '$contains') {
109
+ return `${key} 包含 ${stringifyExplainValue(operatorValue, schemas)}`;
110
+ }
111
+ return `${key} ${operator} ${stringifyExplainValue(operatorValue, schemas)}`;
112
+ };
113
+ const explainNegatedComparedValue = (key, value, schemas) => {
114
+ const entries = Object.entries(value).filter(([operator]) => operator !== '$options');
115
+ if (entries.length !== 1) {
116
+ return `${key} 不满足(${explainComparedValue(key, value, schemas)})`;
117
+ }
118
+ const [operator, operatorValue] = entries[0];
119
+ if (operator === '$eq') {
120
+ return `${key} != ${stringifyExplainValue(operatorValue, schemas)}`;
121
+ }
122
+ if (operator === '$gt') {
123
+ return `${key} <= ${stringifyExplainValue(operatorValue, schemas)}`;
124
+ }
125
+ if (operator === '$gte') {
126
+ return `${key} < ${stringifyExplainValue(operatorValue, schemas)}`;
127
+ }
128
+ if (operator === '$lt') {
129
+ return `${key} >= ${stringifyExplainValue(operatorValue, schemas)}`;
130
+ }
131
+ if (operator === '$lte') {
132
+ return `${key} > ${stringifyExplainValue(operatorValue, schemas)}`;
133
+ }
134
+ if (operator === '$ne') {
135
+ return `${key} = ${stringifyExplainValue(operatorValue, schemas)}`;
136
+ }
137
+ if (operator === '$exists') {
138
+ return `${key}${operatorValue ? '不存在' : '存在'}`;
139
+ }
140
+ if (operator === '$regex') {
141
+ return `${key} 不匹配 ${stringifyExplainValue(operatorValue, schemas)}`;
142
+ }
143
+ if (operator === '$in') {
144
+ return `${key} 不属于 ${stringifyExplainValue(operatorValue, schemas)}`;
145
+ }
146
+ if (operator === '$nin') {
147
+ return `${key} 属于 ${stringifyExplainValue(operatorValue, schemas)}`;
148
+ }
149
+ if (operator === '$contains') {
150
+ return `${key} 不包含 ${stringifyExplainValue(operatorValue, schemas)}`;
151
+ }
152
+ return `${key} 不满足 ${operator} ${stringifyExplainValue(operatorValue, schemas)}`;
153
+ };
68
154
  const explainComparedValue = (key, value, schemas) => {
69
155
  const segments = Object.entries(value)
70
156
  .filter(([operator]) => operator !== '$options')
71
157
  .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
158
  if (operator === '$ne') {
159
+ if (isCompareOperatorObject(operatorValue)) {
160
+ return explainNegatedComparedValue(key, operatorValue, schemas);
161
+ }
100
162
  return `${key} != ${stringifyExplainValue(operatorValue, schemas)}`;
101
163
  }
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)}`;
164
+ return explainSingleComparedValue(key, operator, operatorValue, schemas);
115
165
  });
116
166
  return segments.join(' 且 ');
117
167
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semanticdb-core",
3
- "version": "1.1.42",
3
+ "version": "1.1.43",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [