@steedos/service-metadata-objects 3.0.0-beta.9 → 3.0.0-beta.90
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.js +45 -21
- package/lib/actionsHandler.js.map +1 -1
- package/lib/formula/core.js +35 -8
- package/lib/formula/core.js.map +1 -1
- package/lib/formula/formulaActionHandler.d.ts +1 -1
- package/lib/formula/formulaActionHandler.js +40 -23
- package/lib/formula/formulaActionHandler.js.map +1 -1
- package/lib/summary/summaryActionHandler.d.ts +2 -2
- package/lib/summary/summaryActionHandler.js +21 -11
- package/lib/summary/summaryActionHandler.js.map +1 -1
- package/package.json +5 -5
- package/src/actionsHandler.ts +335 -258
- package/src/formula/core.ts +44 -10
- package/src/formula/formulaActionHandler.ts +499 -379
- package/src/summary/summaryActionHandler.ts +279 -208
package/src/formula/core.ts
CHANGED
|
@@ -25,27 +25,60 @@ const isAmisFormula = (formula: string) => {
|
|
|
25
25
|
// return result;
|
|
26
26
|
// }
|
|
27
27
|
|
|
28
|
-
function extractAmisFormulaVariableNames(
|
|
29
|
-
const
|
|
28
|
+
function extractAmisFormulaVariableNames(data) {
|
|
29
|
+
const variables = new Set();
|
|
30
30
|
|
|
31
31
|
function traverse(node) {
|
|
32
|
-
if (!node) return;
|
|
32
|
+
if (!node || typeof node !== "object") return;
|
|
33
33
|
|
|
34
|
-
//
|
|
35
|
-
if (node.type === "variable") {
|
|
36
|
-
|
|
34
|
+
// 处理普通变量(排除作为getter host的情况)
|
|
35
|
+
if (node.type === "variable" && !isGetterHost(node)) {
|
|
36
|
+
variables.add(node.name);
|
|
37
|
+
}
|
|
38
|
+
// 处理最外层的getter(不处理嵌套的getter host)
|
|
39
|
+
else if (node.type === "getter" && !isGetterHost(node)) {
|
|
40
|
+
const path = getFullGetterPath(node);
|
|
41
|
+
if (path) variables.add(path);
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
// 递归遍历所有子节点
|
|
40
45
|
for (const key in node) {
|
|
41
|
-
if (
|
|
46
|
+
if (key !== "parent" && typeof node[key] === "object") {
|
|
47
|
+
// 设置父节点引用
|
|
48
|
+
node[key].parent = node;
|
|
42
49
|
traverse(node[key]);
|
|
43
50
|
}
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
53
|
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
function isGetterHost(node) {
|
|
55
|
+
return (
|
|
56
|
+
node.parent && node.parent.type === "getter" && node.parent.host === node
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getFullGetterPath(getterNode) {
|
|
61
|
+
const parts = [getterNode.key.name];
|
|
62
|
+
let current = getterNode.host;
|
|
63
|
+
|
|
64
|
+
// 向上追溯host
|
|
65
|
+
while (current) {
|
|
66
|
+
if (current.type === "getter") {
|
|
67
|
+
parts.unshift(current.key.name);
|
|
68
|
+
current = current.host;
|
|
69
|
+
} else if (current.type === "variable") {
|
|
70
|
+
parts.unshift(current.name);
|
|
71
|
+
return parts.join(".");
|
|
72
|
+
} else {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
traverse(data);
|
|
81
|
+
return Array.from(variables);
|
|
49
82
|
}
|
|
50
83
|
|
|
51
84
|
/**
|
|
@@ -55,7 +88,8 @@ function extractAmisFormulaVariableNames(node) {
|
|
|
55
88
|
export const pickFormulaVars = (formula: string): Array<string> => {
|
|
56
89
|
if (isAmisFormula(formula)) {
|
|
57
90
|
const result = extractAmisFormulaVariableNames(parse(formula));
|
|
58
|
-
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
+
return result as any;
|
|
59
93
|
}
|
|
60
94
|
return extract(formula);
|
|
61
95
|
};
|