semanticdb-core 1.1.5 → 1.1.7
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/schema/property.utils.js +185 -150
- package/dist/schema/schema.utils.d.ts +10 -0
- package/dist/schema/schema.utils.js +38 -0
- package/package.json +1 -1
|
@@ -9,159 +9,194 @@ const moment_1 = __importDefault(require("moment"));
|
|
|
9
9
|
const numeral_1 = __importDefault(require("numeral"));
|
|
10
10
|
// 覆盖numeral的一些逻辑。
|
|
11
11
|
// 这里覆盖mk主要是为了去掉单位。单位由另外的地方提供,这样可以灵活一点
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
12
|
+
try {
|
|
13
|
+
numeral_1.default.register('format', 'million', {
|
|
14
|
+
regexps: {
|
|
15
|
+
format: /(m)/,
|
|
16
|
+
unformat: /(m)/,
|
|
17
|
+
},
|
|
18
|
+
format: function (value, format, roundingFunction) {
|
|
19
|
+
return numeral_1.default._.numberToFormat(value / 1000000, format.substring(0, format.length - 1), roundingFunction);
|
|
20
|
+
},
|
|
21
|
+
unformat: function (string) {
|
|
22
|
+
return numeral_1.default._.stringToNumber(string) * 1000000;
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
// ignore
|
|
28
|
+
}
|
|
24
29
|
// billion的b在numeral里是预设字符,用来处理bytes的,改用z了
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
numeral_1.default.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
}
|
|
30
|
+
try {
|
|
31
|
+
numeral_1.default.register('format', 'billion', {
|
|
32
|
+
regexps: {
|
|
33
|
+
format: /(z)/,
|
|
34
|
+
unformat: /(z)/,
|
|
35
|
+
},
|
|
36
|
+
format: function (value, format, roundingFunction) {
|
|
37
|
+
return numeral_1.default._.numberToFormat(value / 1000000000, format.substring(0, format.length - 1), roundingFunction);
|
|
38
|
+
},
|
|
39
|
+
unformat: function (string) {
|
|
40
|
+
return numeral_1.default._.stringToNumber(string) * 1000000000;
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
// ignore
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
numeral_1.default.register('format', 'thousand', {
|
|
49
|
+
regexps: {
|
|
50
|
+
format: /(k)/,
|
|
51
|
+
unformat: /(k)/,
|
|
52
|
+
},
|
|
53
|
+
format: function (value, format, roundingFunction) {
|
|
54
|
+
return numeral_1.default._.numberToFormat(value / 1000, format.substring(0, format.length - 1), roundingFunction);
|
|
55
|
+
},
|
|
56
|
+
unformat: function (string) {
|
|
57
|
+
return numeral_1.default._.stringToNumber(string) * 1000;
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
// ignore
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
numeral_1.default.register('format', 'tenthousand', {
|
|
66
|
+
regexps: {
|
|
67
|
+
format: /(w)/,
|
|
68
|
+
unformat: /(w)/,
|
|
69
|
+
},
|
|
70
|
+
format: function (value, format, roundingFunction) {
|
|
71
|
+
return numeral_1.default._.numberToFormat(value / 10000, format.substring(0, format.length - 1), roundingFunction);
|
|
72
|
+
},
|
|
73
|
+
unformat: function (string) {
|
|
74
|
+
return numeral_1.default._.stringToNumber(string) * 10000;
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
// ignore
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
numeral_1.default.register('format', 'yi', {
|
|
83
|
+
regexps: {
|
|
84
|
+
format: /(y)/,
|
|
85
|
+
unformat: /(y)/,
|
|
86
|
+
},
|
|
87
|
+
format: function (value, format, roundingFunction) {
|
|
88
|
+
return numeral_1.default._.numberToFormat(value / 100000000, format.substring(0, format.length - 1), roundingFunction);
|
|
89
|
+
},
|
|
90
|
+
unformat: function (string) {
|
|
91
|
+
return numeral_1.default._.stringToNumber(string) * 100000000;
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
// ignore
|
|
97
|
+
}
|
|
73
98
|
// 中国的缩略,目前分为:元、万、亿,三个等级
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
99
|
+
try {
|
|
100
|
+
numeral_1.default.register('format', 'chineseabbreviation', {
|
|
101
|
+
regexps: {
|
|
102
|
+
format: /(A)/,
|
|
103
|
+
unformat: /(A)/,
|
|
104
|
+
},
|
|
105
|
+
format: function (value, format, roundingFunction) {
|
|
106
|
+
const wan = 10000.0; // 万
|
|
107
|
+
const yi = 100000000.0; // 亿
|
|
108
|
+
const abs = Math.abs(value);
|
|
109
|
+
let adjValue;
|
|
110
|
+
let unit = '';
|
|
111
|
+
if (abs < wan) {
|
|
112
|
+
adjValue = value;
|
|
113
|
+
}
|
|
114
|
+
else if (abs < yi) {
|
|
115
|
+
adjValue = value / wan;
|
|
116
|
+
unit = '万';
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
adjValue = value / yi;
|
|
120
|
+
unit = '亿';
|
|
121
|
+
}
|
|
122
|
+
return numeral_1.default._.numberToFormat(adjValue, format.substring(0, format.length - 1), roundingFunction) + unit;
|
|
123
|
+
},
|
|
124
|
+
unformat: function (string) {
|
|
125
|
+
const wan = 10000.0; // 万
|
|
126
|
+
const yi = 100000000.0; // 亿
|
|
127
|
+
let scale = 1.0;
|
|
128
|
+
let numberString = string;
|
|
129
|
+
if (string.endsWith('万')) {
|
|
130
|
+
scale = wan;
|
|
131
|
+
numberString = string.substring(0, string.length - 1);
|
|
132
|
+
}
|
|
133
|
+
else if (string.endsWith('亿')) {
|
|
134
|
+
scale = yi;
|
|
135
|
+
numberString = string.substring(0, string.length - 1);
|
|
136
|
+
}
|
|
137
|
+
return numeral_1.default._.stringToNumber(numberString) * scale;
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
// ignore
|
|
143
|
+
}
|
|
114
144
|
// 国外的缩略,分为:个位数、k,m,b,四个等级
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
145
|
+
try {
|
|
146
|
+
numeral_1.default.register('format', 'engabbreviation', {
|
|
147
|
+
regexps: {
|
|
148
|
+
format: /(a)/,
|
|
149
|
+
unformat: /(a)/,
|
|
150
|
+
},
|
|
151
|
+
format: function (value, format, roundingFunction) {
|
|
152
|
+
const thousand = 1000.0; // 千
|
|
153
|
+
const million = 1000000.0; // 百万
|
|
154
|
+
const billion = 1000000000.0; // 十亿
|
|
155
|
+
const abs = Math.abs(value);
|
|
156
|
+
let adjValue;
|
|
157
|
+
let unit = '';
|
|
158
|
+
if (abs < thousand) {
|
|
159
|
+
adjValue = value;
|
|
160
|
+
}
|
|
161
|
+
else if (abs < million) {
|
|
162
|
+
adjValue = value / thousand;
|
|
163
|
+
unit = 'k';
|
|
164
|
+
}
|
|
165
|
+
else if (abs < billion) {
|
|
166
|
+
adjValue = value / million;
|
|
167
|
+
unit = 'm';
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
adjValue = value / billion;
|
|
171
|
+
unit = 'b';
|
|
172
|
+
}
|
|
173
|
+
return numeral_1.default._.numberToFormat(adjValue, format.substring(0, format.length - 1), roundingFunction) + unit;
|
|
174
|
+
},
|
|
175
|
+
unformat: function (string) {
|
|
176
|
+
const thousand = 1000.0; // 千
|
|
177
|
+
const million = 1000000.0; // 百万
|
|
178
|
+
const billion = 1000000000.0; // 十亿
|
|
179
|
+
let scale = 1.0;
|
|
180
|
+
let numberString = string;
|
|
181
|
+
if (string.endsWith('k')) {
|
|
182
|
+
scale = thousand;
|
|
183
|
+
numberString = string.substring(0, string.length - 1);
|
|
184
|
+
}
|
|
185
|
+
else if (string.endsWith('m')) {
|
|
186
|
+
scale = million;
|
|
187
|
+
numberString = string.substring(0, string.length - 1);
|
|
188
|
+
}
|
|
189
|
+
else if (string.endsWith('b')) {
|
|
190
|
+
scale = billion;
|
|
191
|
+
numberString = string.substring(0, string.length - 1);
|
|
192
|
+
}
|
|
193
|
+
return numeral_1.default._.stringToNumber(numberString) * scale;
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
catch (e) {
|
|
198
|
+
// ignore
|
|
199
|
+
}
|
|
165
200
|
function getNameProperty(schema) {
|
|
166
201
|
let nameProp = schema.properties.find((p) => { var _a; return p.is_name || ((_a = p.ui) === null || _a === void 0 ? void 0 : _a.name); });
|
|
167
202
|
if (!nameProp) {
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { PropertyType } from './property';
|
|
2
2
|
import { SchemaType } from './schema';
|
|
3
3
|
import { LogicformType } from '../logicform/logicform';
|
|
4
|
+
export interface SchemaValidationResult {
|
|
5
|
+
valid: boolean;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 检查 schema 是否有效
|
|
10
|
+
* @param schema - 要检查的 schema
|
|
11
|
+
* @returns 验证结果,包含 valid 和 message
|
|
12
|
+
*/
|
|
13
|
+
export declare function isSchemaValid(schema: Partial<SchemaType>): SchemaValidationResult;
|
|
4
14
|
export declare const findPropertyByType: (type: string, schema: SchemaType) => PropertyType | undefined;
|
|
5
15
|
/**
|
|
6
16
|
* Find a property by name within a specific schema
|
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRefChain = exports.getHierarchyCodeLength = exports.findPropertyForOtherSchema = exports.findTimestampLikeProperty = exports.findDisplayNameProperty = exports.findPropertyByName = exports.findPropertyByType = void 0;
|
|
4
|
+
exports.isSchemaValid = isSchemaValid;
|
|
5
|
+
/**
|
|
6
|
+
* 检查 schema 是否有效
|
|
7
|
+
* @param schema - 要检查的 schema
|
|
8
|
+
* @returns 验证结果,包含 valid 和 message
|
|
9
|
+
*/
|
|
10
|
+
function isSchemaValid(schema) {
|
|
11
|
+
if (!schema.name) {
|
|
12
|
+
return { valid: false, message: '缺少名称' };
|
|
13
|
+
}
|
|
14
|
+
if (!schema.type) {
|
|
15
|
+
return { valid: false, message: '缺少类型' };
|
|
16
|
+
}
|
|
17
|
+
if (!schema.db) {
|
|
18
|
+
return { valid: false, message: '缺少数据库配置' };
|
|
19
|
+
}
|
|
20
|
+
if (!schema.properties || schema.properties.length === 0) {
|
|
21
|
+
return { valid: false, message: '缺少属性定义' };
|
|
22
|
+
}
|
|
23
|
+
const validProperties = schema.properties.filter((property) => property.name && property.type);
|
|
24
|
+
if (validProperties.length === 0) {
|
|
25
|
+
return { valid: false, message: '没有有效的属性' };
|
|
26
|
+
}
|
|
27
|
+
// entity和event各自必须的字段
|
|
28
|
+
if (schema.type === 'entity') {
|
|
29
|
+
const IDProp = validProperties.find((property) => property.type === 'ID');
|
|
30
|
+
if (!IDProp) {
|
|
31
|
+
return { valid: false, message: 'entity类型必须有一个type为ID的属性' };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (schema.type === 'event') {
|
|
35
|
+
const timestampProps = validProperties.filter((property) => property.type === 'timestamp');
|
|
36
|
+
if (timestampProps.length === 0) {
|
|
37
|
+
return { valid: false, message: 'event类型必须有一个type为timestamp的属性' };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { valid: true, message: '' };
|
|
41
|
+
}
|
|
4
42
|
const findPropertyByType = (type, schema) => {
|
|
5
43
|
return schema.properties.find((property) => property.type === type);
|
|
6
44
|
};
|