@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.
@@ -1,13 +1,13 @@
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"
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
- // 有${}包裹的表达式就识别为amis公式
9
- return /\$\{.+\}/.test(formula);
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
- let result = [];
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
- if (node.type === 'getter') {
41
- if (node.key && node.key.type === 'identifier') {
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
- for (const key in node) {
52
- if (typeof node[key] === 'object' && node[key] !== null && key !== 'host') {
53
- traverse(node[key], currentPath);
54
- }
55
- }
34
+ // 如果是变量节点,收集它的name
35
+ if (node.type === "variable") {
36
+ result.push(node.name);
37
+ }
56
38
 
57
- return currentPath;
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
- traverse(node, '');
61
- return result;
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
- if(isAmisFormula(formula)){
70
- const result = extractAmisFormulaVariableNames(parse(formula));
71
- return result;
72
- }
73
- return extract(formula);
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 (formulaObjectName: string, formulaFieldName: string, objectName: string, fieldNames?: Array<string>): Promise<boolean> => {
85
- const configs: Array<SteedosFieldFormulaTypeConfig> = await getObjectFieldFormulaConfigs(formulaObjectName, formulaFieldName);
86
- if (configs && configs.length) {
87
- return isFieldFormulaConfigQuotingObjectAndFields(configs[0], objectName, fieldNames);
88
- }
89
- else {
90
- // 没找到公式字段配置说明传入的参数不是公式字段
91
- return false;
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
+ };
@@ -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
  }