semanticdb-core 1.0.14 → 1.0.15

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.
@@ -34,3 +34,21 @@ export declare const isDimensionInLogicform: (logicform: LogicformType, dimensio
34
34
  * ```
35
35
  */
36
36
  export declare const getFlattenQuery: (query: QueryType) => QueryType;
37
+ /**
38
+ * 根据链条字符串在查询对象中查找对应的值
39
+ * @param query - 查询对象
40
+ * @param chain - 链条字符串(如:customer_name)
41
+ * @returns 查询对象中对应的值,如果未找到则返回undefined
42
+ * @example
43
+ * ```typescript
44
+ * // Input
45
+ * const query = {
46
+ * customer: {
47
+ * schema: 'customer',
48
+ * query: { name: '张三' }
49
+ * }
50
+ * };
51
+ * getValueByChain(query, 'customer_name') // 返回 '张三'
52
+ * ```
53
+ */
54
+ export declare const getValueByChain: (query: QueryType, chain: string) => any;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFlattenQuery = exports.isDimensionInLogicform = exports.isDimensionInGroupby = exports.isDimensionInQuery = void 0;
3
+ exports.getValueByChain = exports.getFlattenQuery = exports.isDimensionInLogicform = exports.isDimensionInGroupby = exports.isDimensionInQuery = void 0;
4
4
  /**
5
5
  * 判断一个维度是否在查询中被使用
6
6
  * @param query - 查询对象
@@ -107,3 +107,49 @@ const getFlattenQuery = (query) => {
107
107
  return flattenQuery;
108
108
  };
109
109
  exports.getFlattenQuery = getFlattenQuery;
110
+ /**
111
+ * 根据链条字符串在查询对象中查找对应的值
112
+ * @param query - 查询对象
113
+ * @param chain - 链条字符串(如:customer_name)
114
+ * @returns 查询对象中对应的值,如果未找到则返回undefined
115
+ * @example
116
+ * ```typescript
117
+ * // Input
118
+ * const query = {
119
+ * customer: {
120
+ * schema: 'customer',
121
+ * query: { name: '张三' }
122
+ * }
123
+ * };
124
+ * getValueByChain(query, 'customer_name') // 返回 '张三'
125
+ * ```
126
+ */
127
+ const getValueByChain = (query, chain) => {
128
+ // 处理特殊操作符
129
+ if (chain === '$and' || chain === '$or') {
130
+ return query[chain];
131
+ }
132
+ // 分割链条
133
+ const [prefix, ...rest] = chain.split('_');
134
+ const suffix = rest.join('_');
135
+ const value = query[prefix];
136
+ // 如果是logicform格式
137
+ if (typeof value === 'object' &&
138
+ value &&
139
+ 'schema' in value &&
140
+ 'query' in value &&
141
+ !('groupby' in value) &&
142
+ !('entity_id' in value)) {
143
+ return (0, exports.getValueByChain)(value.query || {}, suffix);
144
+ }
145
+ // 如果没有更多层级,直接返回值
146
+ if (!suffix) {
147
+ return value;
148
+ }
149
+ // 如果值是对象,继续递归查找
150
+ if (typeof value === 'object' && value) {
151
+ return (0, exports.getValueByChain)(value, suffix);
152
+ }
153
+ return undefined;
154
+ };
155
+ exports.getValueByChain = getValueByChain;
@@ -1,17 +1,25 @@
1
1
  declare type timewindow = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
2
+ declare type DateFunction = {
3
+ operator: string;
4
+ args: Record<string, any>;
5
+ };
2
6
  declare type DateValueOffset = {
3
7
  $offset: Partial<{
4
8
  [K in timewindow]: number;
5
9
  }>;
10
+ $functions?: DateFunction;
6
11
  };
7
12
  declare type DateValueBasic = Partial<{
8
13
  [K in timewindow]: number;
9
14
  }> | {
10
15
  period?: 'am' | 'pm';
16
+ $functions?: DateFunction;
11
17
  };
12
18
  declare type DateValuePartial = Partial<{
13
19
  [K in timewindow as `$${K}`]: number;
14
- }>;
20
+ }> | {
21
+ $functions?: DateFunction;
22
+ };
15
23
  declare type DateValueToDate = 'MTD' | 'YTD' | 'QTD' | 'WTD';
16
24
  export declare type DateValue = `${number}-${number}-${number} ${number}:${number}:${number}` | DateValueOffset | DateValueBasic | DateValuePartial | DateValueToDate;
17
25
  export {};
@@ -30,12 +30,12 @@ const findPropertyByName = (schemaID, propertyName, schemasDict) => {
30
30
  for (let i = 0; i < chain.length; i++) {
31
31
  const schema = schemasDict[currentSchemaID];
32
32
  if (!schema) {
33
- throw new Error(`[schema.utils.findPropertyByName]Schema with id ${currentSchemaID} not found`);
33
+ return undefined;
34
34
  }
35
35
  const chainItem = chain[i].split('(')[0]; // 去掉(level)
36
36
  const p = schema.properties.find((property) => property.name === chainItem);
37
37
  if (!p) {
38
- throw new Error(`[schema.utils.findPropertyByName]Property with name ${chainItem} not found`);
38
+ return undefined;
39
39
  }
40
40
  if (i === chain.length - 1) {
41
41
  property = p;
@@ -43,7 +43,7 @@ const findPropertyByName = (schemaID, propertyName, schemasDict) => {
43
43
  break;
44
44
  }
45
45
  if (!p.ref) {
46
- throw new Error(`[schema.utils.findPropertyByName]Property with name ${chainItem} do not have ref field`);
46
+ return undefined;
47
47
  }
48
48
  currentSchemaID = p.ref;
49
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semanticdb-core",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [