semanticdb-core 1.0.26 → 1.0.28

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,6 +1,6 @@
1
1
  export declare interface DataSourceItemType {
2
2
  id: string;
3
- client: 'clickhouse' | 'mysql' | 'postgres' | 'starrocks' | 'oracle' | 'impala' | 'sybase';
3
+ client: 'clickhouse' | 'mysql' | 'postgres' | 'starrocks' | 'oracle' | 'impala' | 'sybase' | 'databricks';
4
4
  connection: {
5
5
  database: string;
6
6
  host: string;
@@ -12,6 +12,9 @@ export declare interface DataSourceItemType {
12
12
  cluster?: string;
13
13
  shardingKey?: string;
14
14
  time?: string;
15
+ sid?: string;
16
+ path?: string;
17
+ token?: string;
15
18
  };
16
19
  readonly?: boolean;
17
20
  }
@@ -0,0 +1,19 @@
1
+ import { unitOfTime } from 'moment';
2
+ export declare const grans: unitOfTime.StartOf[];
3
+ export declare function getSupportedTimeWindows(): string[];
4
+ export declare function isStandardDateForm(dateValue: any): boolean;
5
+ /**
6
+ * year + offset形态
7
+ * @param {Object} dateValue e.g. {year: 2025, month: 2}
8
+ * @return {Boolean}
9
+ */
10
+ export declare function isRelativeDateForm(dateValue: any): boolean;
11
+ export declare function isDateForm(dateValue: any): boolean;
12
+ /**
13
+ * getMinGran
14
+ * 获得最细的粒度(通过从年到分钟的顺序,判断gte的startof和其自身是否相同 且 lte的endof和其自身是否相同来获得最小粒度)
15
+ * @param {Object} date
16
+ * @param {Boolean} flag 本函数是否在yoymomsplysplm.ts获得最小粒度时被调用
17
+ * @return {String}
18
+ */
19
+ export declare function getMinGran(date: any, flag?: boolean): "year" | "quarter" | "month" | "week" | "day" | "hour" | "minute" | "second" | "date" | "w" | "y" | "years" | "months" | "M" | "weeks" | "days" | "d" | "hours" | "h" | "minutes" | "m" | "seconds" | "s" | "millisecond" | "milliseconds" | "ms" | "quarters" | "Q" | "isoWeek" | "isoWeeks" | "W" | "dates" | "D" | null;
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.grans = void 0;
7
+ exports.getSupportedTimeWindows = getSupportedTimeWindows;
8
+ exports.isStandardDateForm = isStandardDateForm;
9
+ exports.isRelativeDateForm = isRelativeDateForm;
10
+ exports.isDateForm = isDateForm;
11
+ exports.getMinGran = getMinGran;
12
+ const moment_1 = __importDefault(require("moment"));
13
+ exports.grans = [
14
+ 'second',
15
+ 'minute',
16
+ 'hour',
17
+ 'day',
18
+ 'isoWeek',
19
+ 'month',
20
+ 'quarter',
21
+ 'year',
22
+ ];
23
+ function getSupportedTimeWindows() {
24
+ return ['second', 'minute', 'hour', 'weekday', 'day', 'week', 'month', 'quarter', 'year'];
25
+ }
26
+ function isStandardDateForm(dateValue) {
27
+ return typeof dateValue === 'object' && '$gte' in dateValue && '$lte' in dateValue;
28
+ }
29
+ /**
30
+ * year + offset形态
31
+ * @param {Object} dateValue e.g. {year: 2025, month: 2}
32
+ * @return {Boolean}
33
+ */
34
+ function isRelativeDateForm(dateValue) {
35
+ if (typeof dateValue !== 'object')
36
+ return false;
37
+ const complexOperators = ['$gte', '$gt', '$lte', '$lt', '$or', '$ne'];
38
+ for (const complexOperator of complexOperators) {
39
+ if (complexOperator in dateValue) {
40
+ return false;
41
+ }
42
+ }
43
+ if ('$offset' in dateValue) {
44
+ return true;
45
+ }
46
+ const tws = getSupportedTimeWindows();
47
+ for (const tw of tws) {
48
+ if (tw in dateValue)
49
+ return true;
50
+ }
51
+ return false;
52
+ }
53
+ function isDateForm(dateValue) {
54
+ return isRelativeDateForm(dateValue) || isStandardDateForm(dateValue);
55
+ }
56
+ /**
57
+ * getMinGran
58
+ * 获得最细的粒度(通过从年到分钟的顺序,判断gte的startof和其自身是否相同 且 lte的endof和其自身是否相同来获得最小粒度)
59
+ * @param {Object} date
60
+ * @param {Boolean} flag 本函数是否在yoymomsplysplm.ts获得最小粒度时被调用
61
+ * @return {String}
62
+ */
63
+ function getMinGran(date, flag = false) {
64
+ if (flag && typeof date === 'string' && date.endsWith('TD')) {
65
+ return 'day';
66
+ }
67
+ if (date === 'YTD') {
68
+ return 'year';
69
+ }
70
+ if (date === 'QTD') {
71
+ return 'quarter';
72
+ }
73
+ if (date === 'MTD') {
74
+ return 'month';
75
+ }
76
+ if (date === 'DTD') {
77
+ return 'day';
78
+ }
79
+ if (typeof date !== 'object') {
80
+ throw new Error('[getMinGran]不支持的date格式');
81
+ }
82
+ if (!date.$gte)
83
+ throw new Error('[getMinGran]date必须要有$gte参数');
84
+ if (!date.$lte)
85
+ throw new Error('[getMinGran]date必须要有$lte参数');
86
+ // relative date
87
+ if (date.$options) {
88
+ if (flag && typeof date.$options === 'string' && date.$options.endsWith('TD')) {
89
+ // 判断date.$gte和$lte是否是同一天
90
+ if ((0, moment_1.default)(date.$gte).isSame((0, moment_1.default)(date.$lte), 'day')) {
91
+ return 'day';
92
+ }
93
+ // 判断date.$gte和$lte是否是同一月份的开始和结尾
94
+ if ((0, moment_1.default)(date.$gte).month() === (0, moment_1.default)(date.$lte).month() &&
95
+ (0, moment_1.default)(date.$gte).isSame((0, moment_1.default)(date.$gte).startOf('month'), 'day') &&
96
+ (0, moment_1.default)(date.$lte).isSame((0, moment_1.default)(date.$lte).endOf('month'), 'day')) {
97
+ return 'month';
98
+ }
99
+ // 判断date.$gte和$lte是否是同一季度的开始和结尾
100
+ if ((0, moment_1.default)(date.$gte).quarter() === (0, moment_1.default)(date.$lte).quarter() &&
101
+ (0, moment_1.default)(date.$gte).isSame((0, moment_1.default)(date.$gte).startOf('quarter'), 'day') &&
102
+ (0, moment_1.default)(date.$lte).isSame((0, moment_1.default)(date.$lte).endOf('quarter'), 'day')) {
103
+ return 'quarter';
104
+ }
105
+ // 判断date.$gte和$lte是否是同一年的开始和结尾
106
+ if ((0, moment_1.default)(date.$gte).year() === (0, moment_1.default)(date.$lte).year() &&
107
+ (0, moment_1.default)(date.$gte).isSame((0, moment_1.default)(date.$gte).startOf('year'), 'day') &&
108
+ (0, moment_1.default)(date.$lte).isSame((0, moment_1.default)(date.$lte).endOf('year'), 'day')) {
109
+ return 'year';
110
+ }
111
+ return 'day';
112
+ }
113
+ if (date.$options === 'YTD') {
114
+ return 'year';
115
+ }
116
+ if (date.$options === 'QTD') {
117
+ return 'quarter';
118
+ }
119
+ if (date.$options === 'MTD') {
120
+ return 'month';
121
+ }
122
+ if (date.$options === 'DTD') {
123
+ return 'day';
124
+ }
125
+ for (const tw of exports.grans) {
126
+ if (tw && tw in date.$options) {
127
+ return tw;
128
+ }
129
+ if (tw === 'isoWeek' && 'week' in date.$options) {
130
+ return tw;
131
+ }
132
+ }
133
+ }
134
+ const gte = (0, moment_1.default)(date.$gte);
135
+ const lte = (0, moment_1.default)(date.$lte);
136
+ for (const tw of [...exports.grans].reverse()) {
137
+ if (gte.isSame((0, moment_1.default)(gte).startOf(tw), 'second') &&
138
+ lte.isSame((0, moment_1.default)(lte).endOf(tw), 'second')) {
139
+ return tw;
140
+ }
141
+ }
142
+ throw new Error('[getMinGran]错误的date' + JSON.stringify(date));
143
+ }
@@ -12,9 +12,18 @@ import { QueryType } from './types/query';
12
12
  * isDimensionInQuery({ "$or": [{ "a": "b" }] }, "$or") // false
13
13
  * ```
14
14
  */
15
- export declare const isDimensionInQuery: (query: QueryType, dimension: string, strictMode?: boolean) => boolean;
16
- export declare const isDimensionInGroupby: (groupby: GroupbyItemType[], dimension: string) => boolean;
17
- export declare const isDimensionInPred: (predItem: PredItemType, dimension: string, strictMode?: boolean) => boolean;
15
+ export declare const isDimensionInQuery: (query: QueryType, dimension: string | {
16
+ _id: string;
17
+ level: string;
18
+ }, strictMode?: boolean) => boolean;
19
+ export declare const isDimensionInGroupby: (groupby: GroupbyItemType[], dimension: string | {
20
+ _id: string;
21
+ level: string;
22
+ }) => boolean;
23
+ export declare const isDimensionInPred: (predItem: PredItemType, dimension: string | {
24
+ _id: string;
25
+ level: string;
26
+ }, strictMode?: boolean) => boolean;
18
27
  /**
19
28
  *
20
29
  * @param logicform
@@ -22,7 +31,10 @@ export declare const isDimensionInPred: (predItem: PredItemType, dimension: stri
22
31
  * @param strictMode 是否严格模式,严格模式下,只有完全匹配才返回true,非严格模式下,只要包含就返回true
23
32
  * @returns
24
33
  */
25
- export declare const isDimensionInLogicform: (logicform: LogicformType, dimension: string, strictMode?: boolean) => boolean;
34
+ export declare const isDimensionInLogicform: (logicform: LogicformType, dimension: string | {
35
+ _id: string;
36
+ level: string;
37
+ }, strictMode?: boolean) => boolean;
26
38
  /**
27
39
  * 将嵌套的查询对象扁平化
28
40
  * @param query - 查询对象
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getValueByChain = exports.getFlattenQuery = exports.isDimensionInLogicform = exports.isDimensionInPred = exports.isDimensionInGroupby = exports.isDimensionInQuery = void 0;
4
+ const date_1 = require("../common/date");
4
5
  /**
5
6
  * 判断一个维度是否在查询中被使用
6
7
  * @param query - 查询对象
@@ -16,7 +17,15 @@ exports.getValueByChain = exports.getFlattenQuery = exports.isDimensionInLogicfo
16
17
  const isDimensionInQuery = (query, dimension, strictMode = true) => {
17
18
  const flattenQuery = (0, exports.getFlattenQuery)(query);
18
19
  if (strictMode) {
19
- return dimension in flattenQuery;
20
+ if (typeof dimension === 'string') {
21
+ return dimension in flattenQuery;
22
+ }
23
+ else if (dimension._id in flattenQuery) {
24
+ if ((0, date_1.isStandardDateForm)(flattenQuery[dimension._id])) {
25
+ const minGran = (0, date_1.getMinGran)(flattenQuery[dimension._id]);
26
+ return minGran === dimension.level;
27
+ }
28
+ }
20
29
  }
21
30
  for (const k of Object.keys(flattenQuery)) {
22
31
  if (k.startsWith(`${dimension}_`) || k === dimension) {
@@ -28,6 +37,10 @@ const isDimensionInQuery = (query, dimension, strictMode = true) => {
28
37
  exports.isDimensionInQuery = isDimensionInQuery;
29
38
  const isDimensionInGroupby = (groupby, dimension) => {
30
39
  for (const groupbyItem of groupby) {
40
+ if (typeof dimension === 'object') {
41
+ return ((groupbyItem._id === dimension._id || groupbyItem._id.startsWith(`${dimension._id}_`)) &&
42
+ groupbyItem.level === dimension.level);
43
+ }
31
44
  if (groupbyItem._id === dimension) {
32
45
  return true;
33
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semanticdb-core",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [