semanticdb-core 1.0.53 → 1.1.0

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.
@@ -24,7 +24,7 @@ function getSupportedTimeWindows() {
24
24
  return ['second', 'minute', 'hour', 'weekday', 'day', 'week', 'month', 'quarter', 'year'];
25
25
  }
26
26
  function isStandardDateForm(dateValue) {
27
- return typeof dateValue === 'object' && '$gte' in dateValue && '$lte' in dateValue;
27
+ return typeof dateValue === 'object' && dateValue !== null && '$gte' in dateValue && '$lte' in dateValue;
28
28
  }
29
29
  /**
30
30
  * year + offset形态
@@ -32,7 +32,7 @@ function isStandardDateForm(dateValue) {
32
32
  * @return {Boolean}
33
33
  */
34
34
  function isRelativeDateForm(dateValue) {
35
- if (typeof dateValue !== 'object')
35
+ if (typeof dateValue !== 'object' || dateValue === null)
36
36
  return false;
37
37
  const complexOperators = ['$gte', '$gt', '$lte', '$lt', '$or', '$ne'];
38
38
  for (const complexOperator of complexOperators) {
@@ -1,5 +1,6 @@
1
1
  import { PropertyType } from './property';
2
2
  import { SchemaType } from './schema';
3
+ import { LogicformType } from '../logicform/logicform';
3
4
  export declare const findPropertyByType: (type: string, schema: SchemaType) => PropertyType | undefined;
4
5
  /**
5
6
  * Find a property by name within a specific schema
@@ -15,6 +16,12 @@ export declare const findPropertyByName: (schemaID: string, propertyName: string
15
16
  * @returns The property marked as display name (is_name=true or ui.name=true) or undefined if not found
16
17
  */
17
18
  export declare const findDisplayNameProperty: (schema: SchemaType) => PropertyType | undefined;
19
+ /**
20
+ * 找到schema中的timestamp属性
21
+ * @param schema - The runtime schema to search in
22
+ * @returns The property with type 'timestamp' or undefined if not found
23
+ */
24
+ export declare const findTimestampLikeProperty: (schema: SchemaType) => PropertyType | undefined;
18
25
  /**
19
26
  * 以fromSchema为基础,找到toSchema中对应的property
20
27
  * @param propertyName
@@ -22,3 +29,24 @@ export declare const findDisplayNameProperty: (schema: SchemaType) => PropertyTy
22
29
  * @param toSchema
23
30
  */
24
31
  export declare const findPropertyForOtherSchema: (propertyName: string, fromSchemaID: string, toSchemaID: string, schemasDict: Record<string, SchemaType>) => PropertyType | undefined;
32
+ /**
33
+ * 获取hierarchy指定层级的累加代码长度
34
+ * @param schema - The schema with hierarchy
35
+ * @param name - The hierarchy level name to get accumulated code length for
36
+ * @returns The accumulated code length up to and including the specified level
37
+ * @throws Error if the level name is not found in the hierarchy
38
+ */
39
+ export declare const getHierarchyCodeLength: (schema: SchemaType, name: string) => number;
40
+ /**
41
+ * 获取从fromNode到toNode的引用链
42
+ * @param fromNode - 起始节点的logicform
43
+ * @param toNode - 目标节点的logicform
44
+ * @param schemas - Schema字典
45
+ * @returns 引用链数组或包含错误信息的对象
46
+ */
47
+ export declare const getRefChain: (fromNode: LogicformType, toNode: LogicformType, schemas: Record<string, SchemaType>) => {
48
+ property: PropertyType;
49
+ schema?: SchemaType;
50
+ }[] | {
51
+ error: string;
52
+ } | null;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findPropertyForOtherSchema = exports.findDisplayNameProperty = exports.findPropertyByName = exports.findPropertyByType = void 0;
3
+ exports.getRefChain = exports.getHierarchyCodeLength = exports.findPropertyForOtherSchema = exports.findTimestampLikeProperty = exports.findDisplayNameProperty = exports.findPropertyByName = exports.findPropertyByType = void 0;
4
4
  const findPropertyByType = (type, schema) => {
5
5
  return schema.properties.find((property) => property.type === type);
6
6
  };
@@ -65,6 +65,15 @@ const findDisplayNameProperty = (schema) => {
65
65
  return undefined;
66
66
  };
67
67
  exports.findDisplayNameProperty = findDisplayNameProperty;
68
+ /**
69
+ * 找到schema中的timestamp属性
70
+ * @param schema - The runtime schema to search in
71
+ * @returns The property with type 'timestamp' or undefined if not found
72
+ */
73
+ const findTimestampLikeProperty = (schema) => {
74
+ return schema.properties.find((property) => property.type === 'timestamp');
75
+ };
76
+ exports.findTimestampLikeProperty = findTimestampLikeProperty;
68
77
  /**
69
78
  * 以fromSchema为基础,找到toSchema中对应的property
70
79
  * @param propertyName
@@ -98,3 +107,123 @@ const findPropertyForOtherSchema = (propertyName, fromSchemaID, toSchemaID, sche
98
107
  return undefined;
99
108
  };
100
109
  exports.findPropertyForOtherSchema = findPropertyForOtherSchema;
110
+ /**
111
+ * 获取hierarchy指定层级的累加代码长度
112
+ * @param schema - The schema with hierarchy
113
+ * @param name - The hierarchy level name to get accumulated code length for
114
+ * @returns The accumulated code length up to and including the specified level
115
+ * @throws Error if the level name is not found in the hierarchy
116
+ */
117
+ const getHierarchyCodeLength = (schema, name) => {
118
+ if (!schema.hierarchy) {
119
+ throw new Error(`${schema.name}中没有hierarchy`);
120
+ }
121
+ let codeLength = 0;
122
+ let nameFound = false;
123
+ for (const hierarchyItem of schema.hierarchy) {
124
+ codeLength += hierarchyItem.code_length;
125
+ if (hierarchyItem.name === name) {
126
+ nameFound = true;
127
+ break;
128
+ }
129
+ }
130
+ if (!nameFound)
131
+ throw new Error(`${schema.name}中没有此level:${name}`);
132
+ return codeLength;
133
+ };
134
+ exports.getHierarchyCodeLength = getHierarchyCodeLength;
135
+ /**
136
+ * 获取从fromNode到toNode的引用链
137
+ * @param fromNode - 起始节点的logicform
138
+ * @param toNode - 目标节点的logicform
139
+ * @param schemas - Schema字典
140
+ * @returns 引用链数组或包含错误信息的对象
141
+ */
142
+ const getRefChain = (fromNode, toNode, schemas) => {
143
+ const getError = (p) => {
144
+ // granularity check
145
+ if (p.granularity && schemas[fromNode.schema].hierarchy) {
146
+ let levelLength;
147
+ if (fromNode.entity_id) {
148
+ levelLength = fromNode.entity_id.length;
149
+ }
150
+ else if (fromNode.groupby && fromNode.groupby.find((gi) => gi.level)) {
151
+ const levelGI = fromNode.groupby.find((gi) => gi.level);
152
+ if (levelGI === null || levelGI === void 0 ? void 0 : levelGI.level) {
153
+ levelLength = (0, exports.getHierarchyCodeLength)(schemas[fromNode.schema], levelGI.level);
154
+ }
155
+ }
156
+ if (levelLength && p.granularity) {
157
+ // granularity check
158
+ const maxCodeLength = (0, exports.getHierarchyCodeLength)(schemas[fromNode.schema], p.granularity);
159
+ if (maxCodeLength && maxCodeLength < levelLength) {
160
+ return `**${schemas[toNode.schema].name}**中,**${p.name}**要求为${p.granularity}以上。暂无法回答此问题。请联系技术支持。`;
161
+ }
162
+ }
163
+ }
164
+ return null;
165
+ };
166
+ let error = null;
167
+ // 优先拿直接能找到的,找不到再用一个dfs来找
168
+ const directFound = schemas[toNode.schema].properties.find((p) => {
169
+ if (!p.ref)
170
+ return false;
171
+ if (p.is_supplementary)
172
+ return false;
173
+ if (getError(p))
174
+ return false;
175
+ if (p.ref !== fromNode.schema)
176
+ return false;
177
+ const constraintsWithRole = p.constraints;
178
+ const fromNodeWithRole = fromNode;
179
+ if ((constraintsWithRole === null || constraintsWithRole === void 0 ? void 0 : constraintsWithRole.role) &&
180
+ (fromNodeWithRole === null || fromNodeWithRole === void 0 ? void 0 : fromNodeWithRole._role) &&
181
+ !Object.keys(constraintsWithRole.role).every((k) => constraintsWithRole.role[k] === fromNodeWithRole._role[k])) {
182
+ return false;
183
+ }
184
+ return true;
185
+ });
186
+ if (directFound) {
187
+ return [{ property: directFound }];
188
+ }
189
+ // 一个dfs
190
+ const fromTo = (from, to, chain = []) => {
191
+ // max depth
192
+ if (chain.length > 10)
193
+ return null;
194
+ const schema = schemas[from];
195
+ for (const property of schema.properties) {
196
+ if (property.type === 'object' && !property.is_supplementary && property.ref && schemas[property.ref]) {
197
+ if (chain.length > 0) {
198
+ const lastItem = chain[chain.length - 1];
199
+ if (lastItem.schema._id === schema._id && lastItem.property.name === property.name) {
200
+ continue;
201
+ }
202
+ }
203
+ const newChain = [...chain, { property, schema: schemas[property.ref] }];
204
+ if (property.ref === to) {
205
+ // sanity check
206
+ const errorMsg = getError(property);
207
+ if (errorMsg) {
208
+ error = errorMsg;
209
+ continue;
210
+ }
211
+ return newChain;
212
+ }
213
+ else {
214
+ const nestedChain = fromTo(property.ref, to, newChain);
215
+ if (nestedChain) {
216
+ return nestedChain;
217
+ }
218
+ }
219
+ }
220
+ }
221
+ return null;
222
+ };
223
+ const chain = fromTo(toNode.schema, fromNode.schema);
224
+ if (!chain && error) {
225
+ return { error };
226
+ }
227
+ return chain;
228
+ };
229
+ exports.getRefChain = getRefChain;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semanticdb-core",
3
- "version": "1.0.53",
3
+ "version": "1.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [