@steedos/service-metadata-objects 3.0.0-beta.2 → 3.0.0-beta.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/lib/actionsHandler.d.ts +2 -2
- package/lib/actionsHandler.js +6 -4
- package/lib/actionsHandler.js.map +1 -1
- package/lib/formula/core.js +7 -15
- package/lib/formula/core.js.map +1 -1
- package/lib/formula/field_formula.js.map +1 -1
- package/lib/formula/formulaActionHandler.js +49 -33
- package/lib/formula/formulaActionHandler.js.map +1 -1
- package/lib/formula/type.d.ts +7 -7
- package/lib/formula/type.js +1 -1
- package/lib/formula/type.js.map +1 -1
- package/lib/formula/util.js.map +1 -1
- package/lib/lookup/LookupActionHandler.js +18 -12
- package/lib/lookup/LookupActionHandler.js.map +1 -1
- package/lib/master-detail/masterDetailActionHandler.js +42 -28
- package/lib/master-detail/masterDetailActionHandler.js.map +1 -1
- package/lib/objects/fields/index.d.ts +12 -1
- package/lib/objects/fields/index.js +2 -3
- package/lib/objects/fields/index.js.map +1 -1
- package/lib/objects/index.js +5 -5
- package/lib/objects/index.js.map +1 -1
- package/lib/summary/summaryActionHandler.js +23 -15
- package/lib/summary/summaryActionHandler.js.map +1 -1
- package/lib/summary/type.d.ts +2 -2
- package/lib/summary/type.js +2 -2
- package/lib/summary/type.js.map +1 -1
- package/package.json +6 -6
- package/src/formula/core.ts +50 -55
- package/src/objects/index.ts +3 -3
package/src/formula/core.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { extract } from
|
|
2
|
-
import { getObjectFieldFormulaConfigs } from
|
|
3
|
-
import { isFieldFormulaConfigQuotingObjectAndFields } from
|
|
4
|
-
import { SteedosFieldFormulaTypeConfig } from
|
|
5
|
-
import { parse } from "amis-formula"
|
|
1
|
+
import { extract } from "@steedos/formula";
|
|
2
|
+
import { getObjectFieldFormulaConfigs } from "./field_formula";
|
|
3
|
+
import { isFieldFormulaConfigQuotingObjectAndFields } from "./util";
|
|
4
|
+
import { SteedosFieldFormulaTypeConfig } from "./type";
|
|
5
|
+
import { parse } from "amis-formula";
|
|
6
6
|
|
|
7
7
|
const isAmisFormula = (formula: string) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
8
|
+
// 有${}包裹的表达式就识别为amis公式
|
|
9
|
+
return /\$\{.+\}/.test(formula);
|
|
10
|
+
};
|
|
11
11
|
|
|
12
12
|
// const extractAmisFormulaVariableNames = (node, result = []) => {
|
|
13
13
|
// // 检查当前节点是否有 "type" 属性,并且这个类型是 "variable"
|
|
@@ -25,54 +25,40 @@ const isAmisFormula = (formula: string) => {
|
|
|
25
25
|
// return result;
|
|
26
26
|
// }
|
|
27
27
|
|
|
28
|
-
|
|
29
28
|
function extractAmisFormulaVariableNames(node) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function traverse(node, currentPath) {
|
|
33
|
-
if (!node) return;
|
|
34
|
-
|
|
35
|
-
if (node.type === 'variable') {
|
|
36
|
-
// 如果是变量,初始化当前路径为变量名
|
|
37
|
-
currentPath = node.name;
|
|
38
|
-
}
|
|
29
|
+
const result = [];
|
|
39
30
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// 如果有 getter,先递归其 host,构建路径
|
|
43
|
-
const newPath = traverse(node.host, currentPath);
|
|
44
|
-
currentPath = newPath ? `${newPath}.${node.key.name}` : `${currentPath}.${node.key.name}`;
|
|
45
|
-
// 只在完整路径构建结束后添加
|
|
46
|
-
result.push(currentPath);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
31
|
+
function traverse(node) {
|
|
32
|
+
if (!node) return;
|
|
49
33
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
}
|
|
34
|
+
// 如果是变量节点,收集它的name
|
|
35
|
+
if (node.type === "variable") {
|
|
36
|
+
result.push(node.name);
|
|
37
|
+
}
|
|
56
38
|
|
|
57
|
-
|
|
39
|
+
// 递归遍历所有子节点
|
|
40
|
+
for (const key in node) {
|
|
41
|
+
if (typeof node[key] === "object" && node[key] !== null) {
|
|
42
|
+
traverse(node[key]);
|
|
43
|
+
}
|
|
58
44
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
traverse(node);
|
|
48
|
+
return result;
|
|
62
49
|
}
|
|
63
50
|
|
|
64
51
|
/**
|
|
65
52
|
* 根据公式内容,取出其中{}中的变量
|
|
66
|
-
* @param formula
|
|
53
|
+
* @param formula
|
|
67
54
|
*/
|
|
68
55
|
export const pickFormulaVars = (formula: string): Array<string> => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
56
|
+
if (isAmisFormula(formula)) {
|
|
57
|
+
const result = extractAmisFormulaVariableNames(parse(formula));
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
return extract(formula);
|
|
61
|
+
};
|
|
76
62
|
|
|
77
63
|
/**
|
|
78
64
|
* 某个对象上的公式字段是否引用了某个对象和字段
|
|
@@ -81,13 +67,22 @@ export const pickFormulaVars = (formula: string): Array<string> => {
|
|
|
81
67
|
* @param object_name 是否引用了该对象
|
|
82
68
|
* @param field_name 是否引用了该字段
|
|
83
69
|
*/
|
|
84
|
-
export const isFormulaFieldQuotingObjectAndFields = async (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
70
|
+
export const isFormulaFieldQuotingObjectAndFields = async (
|
|
71
|
+
formulaObjectName: string,
|
|
72
|
+
formulaFieldName: string,
|
|
73
|
+
objectName: string,
|
|
74
|
+
fieldNames?: Array<string>,
|
|
75
|
+
): Promise<boolean> => {
|
|
76
|
+
const configs: Array<SteedosFieldFormulaTypeConfig> =
|
|
77
|
+
await getObjectFieldFormulaConfigs(formulaObjectName, formulaFieldName);
|
|
78
|
+
if (configs && configs.length) {
|
|
79
|
+
return isFieldFormulaConfigQuotingObjectAndFields(
|
|
80
|
+
configs[0],
|
|
81
|
+
objectName,
|
|
82
|
+
fieldNames,
|
|
83
|
+
);
|
|
84
|
+
} else {
|
|
85
|
+
// 没找到公式字段配置说明传入的参数不是公式字段
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
};
|
package/src/objects/index.ts
CHANGED
|
@@ -184,7 +184,7 @@ export async function refreshObject(ctx, objectApiName) {
|
|
|
184
184
|
if (mainConfigs.length == 1) {
|
|
185
185
|
mainConfig = mainConfigs[0];
|
|
186
186
|
} else if (mainConfigs.length > 1) {
|
|
187
|
-
let dbMainConfig = _.find(mainConfigs, (conf) => {
|
|
187
|
+
let dbMainConfig: any = _.find(mainConfigs, (conf) => {
|
|
188
188
|
return _.has(conf, "_id") && !_.has(conf, "__filename");
|
|
189
189
|
});
|
|
190
190
|
if (dbMainConfig) {
|
|
@@ -220,7 +220,7 @@ export async function refreshObject(ctx, objectApiName) {
|
|
|
220
220
|
objectApiName != MONGO_BASE_OBJECT &&
|
|
221
221
|
objectApiName != SQL_BASE_OBJECT
|
|
222
222
|
) {
|
|
223
|
-
_.each(objectConfig.actions, (action) => {
|
|
223
|
+
_.each(objectConfig.actions, (action: { _visible?: string, visible?: string }) => {
|
|
224
224
|
if (!_.has(action, "_visible") && _.has(action, "visible")) {
|
|
225
225
|
action._visible = `
|
|
226
226
|
function(){
|
|
@@ -289,7 +289,7 @@ export async function refreshObject(ctx, objectApiName) {
|
|
|
289
289
|
}
|
|
290
290
|
});
|
|
291
291
|
|
|
292
|
-
_.each(objectConfig.actions, (action, key) => {
|
|
292
|
+
_.each(objectConfig.actions, (action: { name?: string }, key) => {
|
|
293
293
|
if (!_.has(action, "name")) {
|
|
294
294
|
action.name = key;
|
|
295
295
|
}
|