semanticdb-core 1.0.28 → 1.0.30

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.
@@ -1,3 +1,4 @@
1
+ import { SchemaType } from '../schema/schema';
1
2
  import { GroupbyItemType, LogicformType, PredItemType } from './logicform';
2
3
  import { QueryType } from './types/query';
3
4
  /**
@@ -73,3 +74,11 @@ export declare const getFlattenQuery: (query: QueryType) => QueryType;
73
74
  * ```
74
75
  */
75
76
  export declare const getValueByChain: (query: QueryType, chain: string) => any;
77
+ /**
78
+ * 肯定是返回flatten的dimension
79
+ * @param logicform
80
+ */
81
+ export declare const getDimensionsInLogicform: (logicform: LogicformType, schemasDict: Record<string, SchemaType>) => {
82
+ _id: string;
83
+ level?: string;
84
+ }[];
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getValueByChain = exports.getFlattenQuery = exports.isDimensionInLogicform = exports.isDimensionInPred = exports.isDimensionInGroupby = exports.isDimensionInQuery = void 0;
3
+ exports.getDimensionsInLogicform = exports.getValueByChain = exports.getFlattenQuery = exports.isDimensionInLogicform = exports.isDimensionInPred = exports.isDimensionInGroupby = exports.isDimensionInQuery = void 0;
4
4
  const date_1 = require("../common/date");
5
+ const schema_utils_1 = require("../schema/schema.utils");
6
+ const tws = (0, date_1.getSupportedTimeWindows)();
5
7
  /**
6
8
  * 判断一个维度是否在查询中被使用
7
9
  * @param query - 查询对象
@@ -23,7 +25,9 @@ const isDimensionInQuery = (query, dimension, strictMode = true) => {
23
25
  else if (dimension._id in flattenQuery) {
24
26
  if ((0, date_1.isStandardDateForm)(flattenQuery[dimension._id])) {
25
27
  const minGran = (0, date_1.getMinGran)(flattenQuery[dimension._id]);
26
- return minGran === dimension.level;
28
+ if (!minGran)
29
+ return false;
30
+ return tws.indexOf(minGran) >= tws.indexOf(dimension.level);
27
31
  }
28
32
  }
29
33
  }
@@ -38,8 +42,22 @@ exports.isDimensionInQuery = isDimensionInQuery;
38
42
  const isDimensionInGroupby = (groupby, dimension) => {
39
43
  for (const groupbyItem of groupby) {
40
44
  if (typeof dimension === 'object') {
41
- return ((groupbyItem._id === dimension._id || groupbyItem._id.startsWith(`${dimension._id}_`)) &&
42
- groupbyItem.level === dimension.level);
45
+ // predItem check
46
+ if (groupbyItem._id === dimension._id || groupbyItem._id.startsWith(`${dimension._id}_`)) {
47
+ if (groupbyItem.level) {
48
+ // level check
49
+ if (tws.indexOf(groupbyItem.level) < 0) {
50
+ return groupbyItem.level === dimension.level;
51
+ }
52
+ else {
53
+ return tws.indexOf(groupbyItem.level) >= tws.indexOf(dimension.level);
54
+ }
55
+ }
56
+ else {
57
+ return true;
58
+ }
59
+ }
60
+ return false;
43
61
  }
44
62
  if (groupbyItem._id === dimension) {
45
63
  return true;
@@ -194,3 +212,28 @@ const getValueByChain = (query, chain) => {
194
212
  return undefined;
195
213
  };
196
214
  exports.getValueByChain = getValueByChain;
215
+ /**
216
+ * 肯定是返回flatten的dimension
217
+ * @param logicform
218
+ */
219
+ const getDimensionsInLogicform = (logicform, schemasDict) => {
220
+ const dimensions = [];
221
+ if (logicform.query) {
222
+ const flattenQuery = (0, exports.getFlattenQuery)(logicform.query);
223
+ for (const [k, v] of Object.entries(flattenQuery)) {
224
+ const property = (0, schema_utils_1.findPropertyByName)(logicform.schema, k, schemasDict);
225
+ if ((property === null || property === void 0 ? void 0 : property.primal_type) === 'date') {
226
+ const gran = (0, date_1.getMinGran)(v);
227
+ dimensions.push({ _id: k, level: gran || 'day' });
228
+ }
229
+ else {
230
+ dimensions.push({ _id: k });
231
+ }
232
+ }
233
+ }
234
+ if (logicform.groupby) {
235
+ dimensions.push(...logicform.groupby);
236
+ }
237
+ return dimensions;
238
+ };
239
+ exports.getDimensionsInLogicform = getDimensionsInLogicform;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semanticdb-core",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [