semanticdb-core 1.1.1 → 1.1.3
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.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/logicform/logicform.d.ts +1 -0
- package/dist/logicform/preds/nameForPredItem.d.ts +24 -0
- package/dist/logicform/{nameForPredNode.js → preds/nameForPredItem.js} +64 -60
- package/dist/logicform/preds/propertyForPredItem.d.ts +27 -0
- package/dist/logicform/preds/propertyForPredItem.js +231 -0
- package/dist/schema/property.d.ts +7 -1
- package/package.json +1 -1
- package/dist/logicform/nameForPredNode.d.ts +0 -20
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { getDrilldownDimensions } from './schema/schema.utils/getDrilldownDimens
|
|
|
9
9
|
export * from './logicform/logicform';
|
|
10
10
|
export * from './logicform/logicform.utils';
|
|
11
11
|
export * from './logicform/types/query';
|
|
12
|
-
export * from './logicform/
|
|
12
|
+
export * from './logicform/preds/nameForPredItem';
|
|
13
|
+
export * from './logicform/preds/propertyForPredItem';
|
|
13
14
|
export * from './custom-function/utils';
|
|
14
15
|
export * from './result/index';
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ Object.defineProperty(exports, "getDrilldownDimensions", { enumerable: true, get
|
|
|
27
27
|
__exportStar(require("./logicform/logicform"), exports);
|
|
28
28
|
__exportStar(require("./logicform/logicform.utils"), exports);
|
|
29
29
|
__exportStar(require("./logicform/types/query"), exports);
|
|
30
|
-
__exportStar(require("./logicform/
|
|
30
|
+
__exportStar(require("./logicform/preds/nameForPredItem"), exports);
|
|
31
|
+
__exportStar(require("./logicform/preds/propertyForPredItem"), exports);
|
|
31
32
|
__exportStar(require("./custom-function/utils"), exports);
|
|
32
33
|
__exportStar(require("./result/index"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SchemaType } from '../../schema/schema';
|
|
2
|
+
import { PredItemType } from '../logicform';
|
|
3
|
+
import { QueryType } from '../types/query';
|
|
4
|
+
export interface ctx {
|
|
5
|
+
schemas: Record<string, SchemaType>;
|
|
6
|
+
customFunctions: Record<string, any>;
|
|
7
|
+
locale?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 给Query起名
|
|
11
|
+
*/
|
|
12
|
+
export declare const nameForQuery: (query: QueryType, schema: SchemaType, schemas: Record<string, SchemaType>) => string;
|
|
13
|
+
/**
|
|
14
|
+
* 给pred item起名, normalize阶段用到
|
|
15
|
+
* @param predItem - PredItemType
|
|
16
|
+
* @param s - schema object
|
|
17
|
+
* @param ctx - 上下文对象
|
|
18
|
+
* @returns 名称字符串
|
|
19
|
+
*/
|
|
20
|
+
export declare const nameForPredItem: (predItem: PredItemType, s: SchemaType, ctx: ctx) => string | null;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated 请使用 nameForPredItem 代替
|
|
23
|
+
*/
|
|
24
|
+
export declare const nameForPredNode: (predItem: PredItemType, s: SchemaType, ctx: ctx) => string | null;
|
|
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.nameForPredNode = exports.nameForQuery = void 0;
|
|
6
|
+
exports.nameForPredNode = exports.nameForPredItem = exports.nameForQuery = void 0;
|
|
7
7
|
const moment_1 = __importDefault(require("moment"));
|
|
8
|
-
const schema_utils_1 = require("
|
|
9
|
-
const utils_1 = require("
|
|
10
|
-
const date_1 = require("
|
|
8
|
+
const schema_utils_1 = require("../../schema/schema.utils");
|
|
9
|
+
const utils_1 = require("../../custom-function/utils");
|
|
10
|
+
const date_1 = require("../../common/date");
|
|
11
11
|
// ============== 辅助函数 ==============
|
|
12
12
|
const getPropertyName = (property) => {
|
|
13
13
|
var _a;
|
|
@@ -627,35 +627,35 @@ const nameForQuery = (query, schema, schemas) => {
|
|
|
627
627
|
return name;
|
|
628
628
|
};
|
|
629
629
|
exports.nameForQuery = nameForQuery;
|
|
630
|
-
// ==============
|
|
630
|
+
// ============== nameForPredItem ==============
|
|
631
631
|
/**
|
|
632
|
-
* 给pred
|
|
633
|
-
* @param
|
|
632
|
+
* 给pred item起名, normalize阶段用到
|
|
633
|
+
* @param predItem - PredItemType
|
|
634
634
|
* @param s - schema object
|
|
635
635
|
* @param ctx - 上下文对象
|
|
636
636
|
* @returns 名称字符串
|
|
637
637
|
*/
|
|
638
|
-
const
|
|
638
|
+
const nameForPredItem = (predItem, s, ctx) => {
|
|
639
639
|
var _a, _b, _c, _d;
|
|
640
640
|
const { schemas, customFunctions, locale = 'zh-CN' } = ctx;
|
|
641
|
-
if (typeof
|
|
641
|
+
if (typeof predItem !== 'object')
|
|
642
642
|
return null;
|
|
643
|
-
const schema =
|
|
643
|
+
const schema = predItem.schema ? schemas[predItem.schema] : s;
|
|
644
644
|
let name = '';
|
|
645
645
|
// query
|
|
646
|
-
if (
|
|
647
|
-
name += (0, exports.nameForQuery)(
|
|
646
|
+
if (predItem.query) {
|
|
647
|
+
name += (0, exports.nameForQuery)(predItem.query, schema, schemas);
|
|
648
648
|
}
|
|
649
649
|
// operator
|
|
650
650
|
let useAggKey = false;
|
|
651
|
-
if (
|
|
651
|
+
if (predItem.query && schema.agg_key && schema.agg_key.key in predItem.query) {
|
|
652
652
|
let keyName;
|
|
653
|
-
if (typeof
|
|
654
|
-
|
|
655
|
-
keyName = Object.values(
|
|
653
|
+
if (typeof predItem.query[schema.agg_key.key] === 'object' &&
|
|
654
|
+
predItem.query[schema.agg_key.key].query) {
|
|
655
|
+
keyName = Object.values(predItem.query[schema.agg_key.key].query)[0];
|
|
656
656
|
}
|
|
657
657
|
else {
|
|
658
|
-
keyName =
|
|
658
|
+
keyName = predItem.query[schema.agg_key.key];
|
|
659
659
|
}
|
|
660
660
|
useAggKey = true;
|
|
661
661
|
let onlyValue = keyName;
|
|
@@ -665,26 +665,26 @@ const nameForPredNode = (predNode, s, ctx) => {
|
|
|
665
665
|
name += onlyValue;
|
|
666
666
|
}
|
|
667
667
|
let defaultNameCalled = false;
|
|
668
|
-
if (
|
|
669
|
-
const func = (0, utils_1.findOneCustomFunction)(
|
|
668
|
+
if (predItem.operator) {
|
|
669
|
+
const func = (0, utils_1.findOneCustomFunction)(predItem.schema || schema._id, predItem.operator, customFunctions);
|
|
670
670
|
if (!func) {
|
|
671
|
-
throw new Error(`未注册的函数:${
|
|
671
|
+
throw new Error(`未注册的函数:${predItem.operator}`);
|
|
672
672
|
}
|
|
673
673
|
let basePredName = null;
|
|
674
674
|
let baseProperty = null;
|
|
675
|
-
if (typeof
|
|
676
|
-
basePredName = (0, exports.
|
|
675
|
+
if (typeof predItem.pred === 'object') {
|
|
676
|
+
basePredName = (0, exports.nameForPredItem)(predItem.pred, schema, ctx);
|
|
677
677
|
}
|
|
678
|
-
else if (
|
|
679
|
-
baseProperty = (0, schema_utils_1.findPropertyByName)(schema._id,
|
|
678
|
+
else if (predItem.pred) {
|
|
679
|
+
baseProperty = (0, schema_utils_1.findPropertyByName)(schema._id, predItem.pred, schemas);
|
|
680
680
|
if (baseProperty) {
|
|
681
681
|
basePredName = getPropertyName(baseProperty);
|
|
682
682
|
}
|
|
683
683
|
else {
|
|
684
|
-
basePredName =
|
|
684
|
+
basePredName = predItem.pred;
|
|
685
685
|
}
|
|
686
686
|
}
|
|
687
|
-
if (
|
|
687
|
+
if (predItem.by) {
|
|
688
688
|
const addNameForByItem = (byItem) => {
|
|
689
689
|
if ([
|
|
690
690
|
'$year',
|
|
@@ -734,28 +734,28 @@ const nameForPredNode = (predNode, s, ctx) => {
|
|
|
734
734
|
name += byItem;
|
|
735
735
|
}
|
|
736
736
|
};
|
|
737
|
-
if (typeof
|
|
738
|
-
addNameForByItem(
|
|
737
|
+
if (typeof predItem.by === 'string') {
|
|
738
|
+
addNameForByItem(predItem.by);
|
|
739
739
|
}
|
|
740
|
-
else if (Array.isArray(
|
|
741
|
-
|
|
740
|
+
else if (Array.isArray(predItem.by)) {
|
|
741
|
+
predItem.by.forEach((byItem) => addNameForByItem(byItem));
|
|
742
742
|
}
|
|
743
743
|
name += zhCNToOthers('均', locale);
|
|
744
744
|
}
|
|
745
745
|
if (func && func.defaultName) {
|
|
746
746
|
if (func.name === '$sql') {
|
|
747
|
-
name += func.defaultName(Object.assign(Object.assign({},
|
|
747
|
+
name += func.defaultName(Object.assign(Object.assign({}, predItem), { schema }), locale, Object.assign(Object.assign({}, ctx), { nameForPredItem: exports.nameForPredItem }));
|
|
748
748
|
}
|
|
749
749
|
else if (func.name === '$count_recent' || func.name === '$count_repeat' || func.name === '$sql') {
|
|
750
|
-
name = func.defaultName(Object.assign(Object.assign({},
|
|
750
|
+
name = func.defaultName(Object.assign(Object.assign({}, predItem), { name: basePredName, schema }), locale, Object.assign(Object.assign({}, ctx), { nameForPredItem: exports.nameForPredItem }));
|
|
751
751
|
}
|
|
752
|
-
else if (!(useAggKey &&
|
|
753
|
-
name += func.defaultName(Object.assign(Object.assign(Object.assign({},
|
|
752
|
+
else if (!(useAggKey && predItem.pred === ((_a = schema.agg_key) === null || _a === void 0 ? void 0 : _a.value))) {
|
|
753
|
+
name += func.defaultName(Object.assign(Object.assign(Object.assign({}, predItem), (baseProperty || {})), { name: basePredName, schema }), locale, Object.assign(Object.assign({}, ctx), { nameForPredItem: exports.nameForPredItem }));
|
|
754
754
|
}
|
|
755
755
|
defaultNameCalled = true;
|
|
756
756
|
}
|
|
757
757
|
else {
|
|
758
|
-
switch (
|
|
758
|
+
switch (predItem.operator) {
|
|
759
759
|
case '$hour':
|
|
760
760
|
name += `${zhCNToOthers('每小时', locale)}${basePredName}`;
|
|
761
761
|
break;
|
|
@@ -800,51 +800,51 @@ const nameForPredNode = (predNode, s, ctx) => {
|
|
|
800
800
|
$splm: '环期',
|
|
801
801
|
$splw: '周环期',
|
|
802
802
|
};
|
|
803
|
-
if (map[
|
|
803
|
+
if (map[predItem.operator] === '环期') {
|
|
804
804
|
name += `${zhCNToOthers('上期', locale)}${basePredName}`;
|
|
805
805
|
}
|
|
806
|
-
else if (map[
|
|
807
|
-
name += `${zhCNToOthers(map[
|
|
806
|
+
else if (map[predItem.operator] === '同期') {
|
|
807
|
+
name += `${zhCNToOthers(map[predItem.operator], locale)}${basePredName}`;
|
|
808
808
|
}
|
|
809
809
|
else {
|
|
810
|
-
name += `${basePredName}${zhCNToOthers(map[
|
|
810
|
+
name += `${basePredName}${zhCNToOthers(map[predItem.operator], locale)}`;
|
|
811
811
|
}
|
|
812
|
-
if (
|
|
813
|
-
if ((_b =
|
|
812
|
+
if (predItem.params) {
|
|
813
|
+
if ((_b = predItem.params[0]) === null || _b === void 0 ? void 0 : _b.time) {
|
|
814
814
|
const timestampProp = (0, schema_utils_1.findTimestampLikeProperty)(schema);
|
|
815
815
|
if (timestampProp) {
|
|
816
816
|
name += (0, exports.nameForQuery)({
|
|
817
|
-
[timestampProp.name]:
|
|
817
|
+
[timestampProp.name]: predItem.params[0].time,
|
|
818
818
|
}, schema, schemas);
|
|
819
819
|
}
|
|
820
820
|
}
|
|
821
|
-
if (((_c =
|
|
821
|
+
if (((_c = predItem.params[0]) === null || _c === void 0 ? void 0 : _c.by) === 'lunar') {
|
|
822
822
|
name += zhCNToOthers('按农历', locale);
|
|
823
823
|
}
|
|
824
|
-
else if (((_d =
|
|
824
|
+
else if (((_d = predItem.params[0]) === null || _d === void 0 ? void 0 : _d.by) === 'weekday') {
|
|
825
825
|
name += zhCNToOthers('按星期', locale);
|
|
826
826
|
}
|
|
827
827
|
}
|
|
828
828
|
break;
|
|
829
829
|
}
|
|
830
830
|
case '$percentage':
|
|
831
|
-
if (
|
|
832
|
-
if (typeof
|
|
833
|
-
name += (0, exports.
|
|
831
|
+
if (predItem.pred) {
|
|
832
|
+
if (typeof predItem.pred === 'object') {
|
|
833
|
+
name += (0, exports.nameForPredItem)(predItem.pred, schema, ctx);
|
|
834
834
|
}
|
|
835
835
|
else {
|
|
836
|
-
name +=
|
|
836
|
+
name += predItem.pred;
|
|
837
837
|
}
|
|
838
838
|
}
|
|
839
839
|
name += zhCNToOthers('占比', locale);
|
|
840
840
|
break;
|
|
841
841
|
case '$uniq':
|
|
842
|
-
if (
|
|
843
|
-
if (typeof
|
|
844
|
-
name += (0, exports.
|
|
842
|
+
if (predItem.pred) {
|
|
843
|
+
if (typeof predItem.pred === 'object') {
|
|
844
|
+
name += (0, exports.nameForPredItem)(predItem.pred, schema, ctx);
|
|
845
845
|
}
|
|
846
846
|
else {
|
|
847
|
-
name +=
|
|
847
|
+
name += predItem.pred;
|
|
848
848
|
}
|
|
849
849
|
}
|
|
850
850
|
name += zhCNToOthers('数量', locale);
|
|
@@ -877,23 +877,23 @@ const nameForPredNode = (predNode, s, ctx) => {
|
|
|
877
877
|
name += `${basePredName}${zhCNToOthers('段', locale)}`;
|
|
878
878
|
break;
|
|
879
879
|
default:
|
|
880
|
-
name +=
|
|
880
|
+
name += predItem.operator;
|
|
881
881
|
break;
|
|
882
882
|
}
|
|
883
883
|
}
|
|
884
884
|
}
|
|
885
|
-
else if (
|
|
886
|
-
if (
|
|
885
|
+
else if (predItem.pred) {
|
|
886
|
+
if (predItem.pred === '*') {
|
|
887
887
|
return null;
|
|
888
888
|
}
|
|
889
|
-
name +=
|
|
889
|
+
name += predItem.pred;
|
|
890
890
|
}
|
|
891
891
|
// level
|
|
892
|
-
if (!defaultNameCalled &&
|
|
893
|
-
name += `(${
|
|
892
|
+
if (!defaultNameCalled && predItem.level) {
|
|
893
|
+
name += `(${predItem.level})`;
|
|
894
894
|
}
|
|
895
895
|
// accumulate
|
|
896
|
-
if (
|
|
896
|
+
if (predItem.accumulate) {
|
|
897
897
|
if (locale.startsWith('en')) {
|
|
898
898
|
// do nothing
|
|
899
899
|
}
|
|
@@ -904,4 +904,8 @@ const nameForPredNode = (predNode, s, ctx) => {
|
|
|
904
904
|
// feat: name 不能有下划线
|
|
905
905
|
return name.replace(/_/g, '');
|
|
906
906
|
};
|
|
907
|
-
exports.
|
|
907
|
+
exports.nameForPredItem = nameForPredItem;
|
|
908
|
+
/**
|
|
909
|
+
* @deprecated 请使用 nameForPredItem 代替
|
|
910
|
+
*/
|
|
911
|
+
exports.nameForPredNode = exports.nameForPredItem;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SchemaType } from '../../schema/schema';
|
|
2
|
+
import { PropertyType } from '../../schema/property';
|
|
3
|
+
import { PredItemType, LogicformType } from '../logicform';
|
|
4
|
+
import { ctx } from './nameForPredItem';
|
|
5
|
+
export interface PropertyForPredItemCtx extends ctx {
|
|
6
|
+
logicform: LogicformType;
|
|
7
|
+
permissions?: Record<string, {
|
|
8
|
+
blacklist?: string[];
|
|
9
|
+
whitelist?: string[];
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export interface PredItemProperty extends PropertyType {
|
|
13
|
+
baseProperty?: PropertyType | null;
|
|
14
|
+
auth?: boolean;
|
|
15
|
+
is_delta?: boolean;
|
|
16
|
+
components?: any[];
|
|
17
|
+
componentProperties?: (PredItemProperty | undefined)[];
|
|
18
|
+
from?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 根据PredItemType生成对应的PropertyType
|
|
22
|
+
* @param predItem - PredItemType
|
|
23
|
+
* @param s - schema object
|
|
24
|
+
* @param ctx - 上下文对象
|
|
25
|
+
* @returns PropertyType或undefined
|
|
26
|
+
*/
|
|
27
|
+
export declare const propertyForPredItem: (predItem: PredItemType, s: SchemaType, ctx: PropertyForPredItemCtx) => PredItemProperty | undefined;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.propertyForPredItem = void 0;
|
|
4
|
+
const schema_utils_1 = require("../../schema/schema.utils");
|
|
5
|
+
const utils_1 = require("../../custom-function/utils");
|
|
6
|
+
const nameForPredItem_1 = require("./nameForPredItem");
|
|
7
|
+
// ============== 辅助函数 ==============
|
|
8
|
+
/**
|
|
9
|
+
* 根据operator获取property的类型信息
|
|
10
|
+
*/
|
|
11
|
+
const getPropertyTypeFromOperator = (operator, baseProperty) => {
|
|
12
|
+
// 百分比类算子
|
|
13
|
+
if (['$yoy', '$mom', '$wow', '$qoq', '$percentage'].includes(operator)) {
|
|
14
|
+
return {
|
|
15
|
+
type: 'percentage',
|
|
16
|
+
primal_type: 'number',
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
// 差值类算子
|
|
20
|
+
if (['$yoyd', '$momd'].includes(operator)) {
|
|
21
|
+
return {
|
|
22
|
+
type: (baseProperty === null || baseProperty === void 0 ? void 0 : baseProperty.type) || 'number',
|
|
23
|
+
primal_type: 'number',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
// 计数类算子
|
|
27
|
+
if (['$count', '$uniq', '$count_recent', '$count_repeat'].includes(operator)) {
|
|
28
|
+
return {
|
|
29
|
+
type: 'int',
|
|
30
|
+
primal_type: 'number',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// 日期提取类算子
|
|
34
|
+
if (['$year', '$month', '$day', '$hour', '$minute', '$second', '$week', '$weekday', '$quarter'].includes(operator)) {
|
|
35
|
+
return {
|
|
36
|
+
type: 'int',
|
|
37
|
+
primal_type: 'number',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// 平均值类算子,保持原类型
|
|
41
|
+
if (['$avg', '$dailyavg', '$monthlyavg', '$weeklyavg'].includes(operator)) {
|
|
42
|
+
return {
|
|
43
|
+
type: (baseProperty === null || baseProperty === void 0 ? void 0 : baseProperty.type) || 'number',
|
|
44
|
+
primal_type: 'number',
|
|
45
|
+
is_additive: false, // 平均值不可加
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
// 求和/最大/最小等,保持原类型
|
|
49
|
+
if (['$sum', '$max', '$min'].includes(operator)) {
|
|
50
|
+
return {
|
|
51
|
+
type: (baseProperty === null || baseProperty === void 0 ? void 0 : baseProperty.type) || 'number',
|
|
52
|
+
primal_type: 'number',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// 分段算子
|
|
56
|
+
if (operator === '$piecewise') {
|
|
57
|
+
return {
|
|
58
|
+
type: 'category',
|
|
59
|
+
primal_type: 'string',
|
|
60
|
+
is_categorical: true,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// 默认返回number类型
|
|
64
|
+
return {
|
|
65
|
+
type: 'number',
|
|
66
|
+
primal_type: 'number',
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* 从PredItemType生成PropertyType
|
|
71
|
+
*/
|
|
72
|
+
const getPropertyFromPredItem = (predItem, ctx) => {
|
|
73
|
+
const { schemas, customFunctions, logicform } = ctx;
|
|
74
|
+
const schemaID = predItem.schema || logicform.schema;
|
|
75
|
+
const schema = schemas[schemaID];
|
|
76
|
+
// 尝试找到自定义函数
|
|
77
|
+
const func = predItem.operator
|
|
78
|
+
? (0, utils_1.findOneCustomFunction)(schemaID, predItem.operator, customFunctions)
|
|
79
|
+
: null;
|
|
80
|
+
// 如果自定义函数有genProperty方法,使用它
|
|
81
|
+
if (func && func.genProperty) {
|
|
82
|
+
return func.genProperty(predItem, {
|
|
83
|
+
schema,
|
|
84
|
+
schemas,
|
|
85
|
+
logicform,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// 找到基础property
|
|
89
|
+
let baseProperty = null;
|
|
90
|
+
if (predItem.pred && typeof predItem.pred === 'string') {
|
|
91
|
+
baseProperty = (0, schema_utils_1.findPropertyByName)(schemaID, predItem.pred, schemas);
|
|
92
|
+
}
|
|
93
|
+
// 根据operator推断类型
|
|
94
|
+
const typeInfo = predItem.operator
|
|
95
|
+
? getPropertyTypeFromOperator(predItem.operator, baseProperty)
|
|
96
|
+
: {};
|
|
97
|
+
return Object.assign(Object.assign({ name: predItem.name || '' }, typeInfo), { _sid: predItem.name || '', _id: predItem.name || '', constraints: {}, ui: (baseProperty === null || baseProperty === void 0 ? void 0 : baseProperty.ui) || {} });
|
|
98
|
+
};
|
|
99
|
+
// ============== propertyForPredItem ==============
|
|
100
|
+
/**
|
|
101
|
+
* 根据PredItemType生成对应的PropertyType
|
|
102
|
+
* @param predItem - PredItemType
|
|
103
|
+
* @param s - schema object
|
|
104
|
+
* @param ctx - 上下文对象
|
|
105
|
+
* @returns PropertyType或undefined
|
|
106
|
+
*/
|
|
107
|
+
const propertyForPredItem = (predItem, s, ctx) => {
|
|
108
|
+
const { schemas, customFunctions, logicform, permissions } = ctx;
|
|
109
|
+
// 特殊情况处理
|
|
110
|
+
if (predItem.pred === '*')
|
|
111
|
+
return undefined;
|
|
112
|
+
if (!predItem.name)
|
|
113
|
+
throw new Error('pred item必须要有name');
|
|
114
|
+
if (predItem.name === '_id')
|
|
115
|
+
return undefined;
|
|
116
|
+
const schema = predItem.schema ? schemas[predItem.schema] : s;
|
|
117
|
+
let targetProperty;
|
|
118
|
+
let baseProperty = null;
|
|
119
|
+
// 找基础property
|
|
120
|
+
if (predItem.pred) {
|
|
121
|
+
if (typeof predItem.pred === 'string') {
|
|
122
|
+
baseProperty = (0, schema_utils_1.findPropertyByName)(schema._id, predItem.pred, schemas);
|
|
123
|
+
}
|
|
124
|
+
else if (typeof predItem.pred === 'object') {
|
|
125
|
+
// 针对嵌套pred时,内层pred没有pred字段导致无法找到prop的场景
|
|
126
|
+
const innerProperty = (0, exports.propertyForPredItem)(Object.assign({ schema: schema._id }, predItem.pred), schema, ctx);
|
|
127
|
+
if (innerProperty) {
|
|
128
|
+
baseProperty = innerProperty;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (baseProperty) {
|
|
132
|
+
baseProperty.from = schema._id;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// 生成targetProperty
|
|
136
|
+
if (!predItem.operator && predItem.pred) {
|
|
137
|
+
// 没有operator,直接使用baseProperty
|
|
138
|
+
targetProperty = Object.assign(Object.assign({}, baseProperty), { name: predItem.name });
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
// 有operator,通过operator推断property
|
|
142
|
+
const generatedProperty = getPropertyFromPredItem(Object.assign(Object.assign({}, predItem), { schema: predItem.schema || schema._id }), ctx);
|
|
143
|
+
targetProperty = Object.assign({ _sid: predItem.name, _id: predItem.name, name: predItem.name, type: 'number', primal_type: 'number', constraints: {}, ui: {} }, generatedProperty);
|
|
144
|
+
}
|
|
145
|
+
targetProperty.baseProperty = baseProperty;
|
|
146
|
+
// 处理ref和schema
|
|
147
|
+
if (targetProperty.primal_type !== 'object') {
|
|
148
|
+
delete targetProperty.ref;
|
|
149
|
+
delete targetProperty.schema;
|
|
150
|
+
}
|
|
151
|
+
if (targetProperty.ref && schemas[targetProperty.ref]) {
|
|
152
|
+
targetProperty.schema = JSON.parse(JSON.stringify(schemas[targetProperty.ref]));
|
|
153
|
+
}
|
|
154
|
+
// 权限处理
|
|
155
|
+
targetProperty.auth = true;
|
|
156
|
+
const schemaID = (baseProperty === null || baseProperty === void 0 ? void 0 : baseProperty.schemaID) || logicform.schema;
|
|
157
|
+
if (baseProperty && permissions && permissions[schemaID]) {
|
|
158
|
+
const blacklist = permissions[schemaID].blacklist || [];
|
|
159
|
+
if (blacklist.find((black) => black === baseProperty.name)) {
|
|
160
|
+
targetProperty.auth = false;
|
|
161
|
+
}
|
|
162
|
+
if (permissions[schemaID].whitelist && permissions[schemaID].whitelist.length > 0) {
|
|
163
|
+
if (!permissions[schemaID].whitelist.find((white) => white === baseProperty.name)) {
|
|
164
|
+
targetProperty.auth = false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// 检查groupby权限
|
|
169
|
+
const isGroupbyPred = logicform.groupby && logicform.groupby.find((g) => g.name === predItem.name);
|
|
170
|
+
if (!targetProperty.auth && isGroupbyPred) {
|
|
171
|
+
throw new Error(`您无权限查看:${targetProperty.name} 相关数据`);
|
|
172
|
+
}
|
|
173
|
+
// 处理components
|
|
174
|
+
const func = predItem.operator
|
|
175
|
+
? (0, utils_1.findOneCustomFunction)(predItem.schema || logicform.schema, predItem.operator, customFunctions)
|
|
176
|
+
: null;
|
|
177
|
+
if (func && func.genComponents) {
|
|
178
|
+
let genComponentsFn = func.genComponents;
|
|
179
|
+
if (typeof genComponentsFn === 'string') {
|
|
180
|
+
genComponentsFn = new Function(`return ${genComponentsFn}`)();
|
|
181
|
+
}
|
|
182
|
+
targetProperty.components = genComponentsFn(predItem, {
|
|
183
|
+
schema,
|
|
184
|
+
logicform: JSON.parse(JSON.stringify(logicform)),
|
|
185
|
+
nameForPredItem: nameForPredItem_1.nameForPredItem,
|
|
186
|
+
schemas,
|
|
187
|
+
customFunctions,
|
|
188
|
+
});
|
|
189
|
+
// 处理name_postfix和name_prefix
|
|
190
|
+
if (predItem.name_postfix) {
|
|
191
|
+
targetProperty.components.forEach((c) => {
|
|
192
|
+
c.name = `${c.name}${predItem.name_postfix}`;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
else if (predItem.name_prefix) {
|
|
196
|
+
targetProperty.components.forEach((c) => {
|
|
197
|
+
c.name = `${predItem.name_prefix}${c.name}`;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// 处理差值类operator
|
|
202
|
+
if (predItem.operator && predItem.operator.match(/^\$[a-z]o[a-z]d$/)) {
|
|
203
|
+
targetProperty.is_delta = true;
|
|
204
|
+
}
|
|
205
|
+
// 除法导致不可加
|
|
206
|
+
if (predItem.by) {
|
|
207
|
+
targetProperty.is_additive = false;
|
|
208
|
+
}
|
|
209
|
+
// 递归处理componentProperties
|
|
210
|
+
if (targetProperty.components) {
|
|
211
|
+
targetProperty.componentProperties = targetProperty.components.map((c) => {
|
|
212
|
+
try {
|
|
213
|
+
if (!c.name) {
|
|
214
|
+
c.name = (0, nameForPredItem_1.nameForPredItem)(c, schema, ctx);
|
|
215
|
+
}
|
|
216
|
+
return (0, exports.propertyForPredItem)(c, schema, ctx);
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
console.error('in propertyForPredItem componentProperties', error);
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
// 清理不需要的字段
|
|
225
|
+
delete targetProperty.run;
|
|
226
|
+
delete targetProperty.genComponents;
|
|
227
|
+
delete targetProperty.mergeComponents;
|
|
228
|
+
delete targetProperty.shouldSplitGroupby;
|
|
229
|
+
return targetProperty;
|
|
230
|
+
};
|
|
231
|
+
exports.propertyForPredItem = propertyForPredItem;
|
|
@@ -49,7 +49,11 @@ export interface PropertyTypeDraft {
|
|
|
49
49
|
avg?: number;
|
|
50
50
|
distincts?: any[];
|
|
51
51
|
};
|
|
52
|
-
cases?:
|
|
52
|
+
cases?: {
|
|
53
|
+
name: string;
|
|
54
|
+
syno?: string[];
|
|
55
|
+
sql?: string;
|
|
56
|
+
}[];
|
|
53
57
|
ui?: {
|
|
54
58
|
name?: boolean;
|
|
55
59
|
title?: string;
|
|
@@ -75,6 +79,8 @@ export interface PropertyTypeDraft {
|
|
|
75
79
|
};
|
|
76
80
|
recommend_kpis?: any[];
|
|
77
81
|
components?: any[];
|
|
82
|
+
quantifier?: string;
|
|
83
|
+
quantifiers?: Record<string, number>;
|
|
78
84
|
}
|
|
79
85
|
export interface PropertyType extends Omit<PropertyTypeDraft, '_sid' | '_id' | 'constraints' | 'primal_type' | 'ui'>, Required<Pick<PropertyTypeDraft, '_sid' | '_id' | 'constraints' | 'primal_type' | 'ui'>> {
|
|
80
86
|
schemaID?: string;
|
package/package.json
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { SchemaType } from '../schema/schema';
|
|
2
|
-
import { PredItemType } from './logicform';
|
|
3
|
-
import { QueryType } from './types/query';
|
|
4
|
-
export interface ctx {
|
|
5
|
-
schemas: Record<string, SchemaType>;
|
|
6
|
-
customFunctions: Record<string, any>;
|
|
7
|
-
locale?: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* 给Query起名
|
|
11
|
-
*/
|
|
12
|
-
export declare const nameForQuery: (query: QueryType, schema: SchemaType, schemas: Record<string, SchemaType>) => string;
|
|
13
|
-
/**
|
|
14
|
-
* 给pred node起名, normalize阶段用到
|
|
15
|
-
* @param predNode - PredItemType
|
|
16
|
-
* @param s - schema object
|
|
17
|
-
* @param ctx - 上下文对象
|
|
18
|
-
* @returns 名称字符串
|
|
19
|
-
*/
|
|
20
|
-
export declare const nameForPredNode: (predNode: PredItemType, s: SchemaType, ctx: ctx) => string | null;
|