@lcap/nasl 3.8.2-alpha.2 → 3.8.2-alpha.4

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.
Files changed (88) hide show
  1. package/out/common/ComponentAPI.d.ts +9 -0
  2. package/out/concepts/AuthLogicForCallInterface__.js +21 -6
  3. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
  4. package/out/concepts/BindAttribute__.js +11 -3
  5. package/out/concepts/BindAttribute__.js.map +1 -1
  6. package/out/concepts/BusinessComponent__.js +24 -8
  7. package/out/concepts/BusinessComponent__.js.map +1 -1
  8. package/out/concepts/BusinessLogic__.js +21 -6
  9. package/out/concepts/BusinessLogic__.js.map +1 -1
  10. package/out/concepts/CallInterface__.js +2 -1
  11. package/out/concepts/CallInterface__.js.map +1 -1
  12. package/out/concepts/CallLogic__.js +1 -1
  13. package/out/concepts/CallLogic__.js.map +1 -1
  14. package/out/concepts/Logic__.js +43 -16
  15. package/out/concepts/Logic__.js.map +1 -1
  16. package/out/concepts/MemberExpression__.js +19 -13
  17. package/out/concepts/MemberExpression__.js.map +1 -1
  18. package/out/concepts/OverriddenLogic__.js +21 -6
  19. package/out/concepts/OverriddenLogic__.js.map +1 -1
  20. package/out/concepts/Param__.js +5 -4
  21. package/out/concepts/Param__.js.map +1 -1
  22. package/out/concepts/Structure__.js +4 -4
  23. package/out/concepts/Structure__.js.map +1 -1
  24. package/out/concepts/ViewElement__.js +0 -5
  25. package/out/concepts/ViewElement__.js.map +1 -1
  26. package/out/concepts/View__.js +50 -19
  27. package/out/concepts/View__.js.map +1 -1
  28. package/out/concepts/basics/stdlib/nasl.processV2.js +78 -0
  29. package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
  30. package/out/generator/genBundleFiles.js +1 -1
  31. package/out/generator/genBundleFiles.js.map +1 -1
  32. package/out/natural/genNaturalTS.d.ts +10 -5
  33. package/out/natural/genNaturalTS.js +34 -25
  34. package/out/natural/genNaturalTS.js.map +1 -1
  35. package/out/natural/getContext/getUILib.js +6 -3
  36. package/out/natural/getContext/getUILib.js.map +1 -1
  37. package/out/natural/getContext/index.d.ts +5 -2
  38. package/out/natural/getContext/index.js +105 -12
  39. package/out/natural/getContext/index.js.map +1 -1
  40. package/out/natural/getContext/naslStdlibMap.js +8 -8
  41. package/out/natural/getContext/naslStdlibMap.js.map +1 -1
  42. package/out/natural/tools.d.ts +16 -0
  43. package/out/natural/tools.js +103 -1
  44. package/out/natural/tools.js.map +1 -1
  45. package/out/server/getMemberIdentifier.js +11 -17
  46. package/out/server/getMemberIdentifier.js.map +1 -1
  47. package/out/server/naslServer.js +1 -1
  48. package/out/server/naslServer.js.map +1 -1
  49. package/out/translator/types.d.ts +2 -0
  50. package/package.json +1 -1
  51. package/sandbox/stdlib/nasl.processV2.ts +19 -0
  52. package/sandbox-natural/stdlib/nasl.core.d.ts +54 -0
  53. package/sandbox-natural/stdlib/nasl.oql.d.ts +22 -0
  54. package/sandbox-natural/stdlib/{nasl.ui.pre.d.ts → nasl.ui.d.ts} +20 -44
  55. package/sandbox-natural/stdlib/nasl.ui.h5.d.ts +1684 -1643
  56. package/sandbox-natural/stdlib/nasl.ui.h5.json +15746 -15045
  57. package/sandbox-natural/stdlib/nasl.ui.pc.d.ts +5341 -5154
  58. package/sandbox-natural/stdlib/nasl.ui.pc.json +31176 -30681
  59. package/sandbox-natural/stdlib/{nasl.util.ts → nasl.util.d.ts} +43 -37
  60. package/src/common/ComponentAPI.ts +7 -0
  61. package/src/concepts/AuthLogicForCallInterface__.ts +23 -6
  62. package/src/concepts/BindAttribute__.ts +17 -12
  63. package/src/concepts/BusinessComponent__.ts +26 -8
  64. package/src/concepts/BusinessLogic__.ts +23 -6
  65. package/src/concepts/CallInterface__.ts +2 -2
  66. package/src/concepts/CallLogic__.ts +1 -1
  67. package/src/concepts/Logic__.ts +58 -32
  68. package/src/concepts/MemberExpression__.ts +20 -13
  69. package/src/concepts/OverriddenLogic__.ts +23 -6
  70. package/src/concepts/Param__.ts +5 -4
  71. package/src/concepts/Structure__.ts +4 -4
  72. package/src/concepts/ViewElement__.ts +1 -7
  73. package/src/concepts/View__.ts +55 -21
  74. package/src/concepts/basics/stdlib/nasl.processV2.ts +79 -0
  75. package/src/generator/genBundleFiles.ts +1 -1
  76. package/src/natural/genNaturalTS.ts +43 -27
  77. package/src/natural/getContext/getUILib.ts +6 -3
  78. package/src/natural/getContext/index.ts +85 -10
  79. package/src/natural/getContext/naslStdlibMap.ts +8 -8
  80. package/src/natural/tools.ts +100 -1
  81. package/src/server/getMemberIdentifier.ts +14 -14
  82. package/src/server/naslServer.ts +1 -1
  83. package/src/translator/types.ts +2 -0
  84. package/test/concepts/member-expression/__snapshots__/toJS.spec.ts.snap +1 -1
  85. package/test/concepts/member-expression/__snapshots__/toVue.spec.ts.snap +1 -1
  86. package/sandbox-natural/stdlib/nasl.core.ts +0 -47
  87. package/sandbox-natural/stdlib/nasl.oql.ts +0 -14
  88. package/sandbox-natural/stdlib/nasl.ui.ts +0 -63
@@ -1,19 +1,27 @@
1
+ /** 循环函数ForEach
2
+ * 这是唯一一个可以在逻辑中使用的循环函数,用于遍历列表中的元素,禁止使用for、forEach等其他循环语句。
3
+ */
4
+ declare function ForEach<T>(list: List<T>, start: Integer, end: Integer, fn: (item: T, index: Integer) => void): void;
5
+
6
+ /* 基本运算函数,用于数学计算 */
7
+ declare function plus(left: Decimal, right: Decimal): Decimal;
8
+ declare function minus(left: Decimal, right: Decimal): Decimal;
9
+ declare function multiply(left: Decimal, right: Decimal): Decimal;
10
+ declare function divide(left: Decimal, right: Decimal): Decimal;
11
+ declare function remainder(left: Decimal, right: Decimal): Decimal;
12
+
1
13
  declare namespace nasl.util {
2
- // 类型转换与格式化函数
14
+ /* 类型转换与格式化函数 */
3
15
  export function Convert(value: null): <T extends never>() => T;
4
16
  export function FormatNumber(doubleValue: Decimal | Long, digits: Long, showGroups: Boolean): String;
5
- /**
6
- * @example nasl.util.FormatDateTime(dataTime1, 'yyyy-MM-dd HH:mm:ss', 'global')
7
- */
17
+ // @example nasl.util.FormatDateTime(dataTime1, 'yyyy-MM-dd HH:mm:ss', 'global')
8
18
  export function FormatDateTime(dateTime: DateTime, formatter: String, timeZone: string): String;
9
19
  export function FormatDate(date: Date, formatter: String): String;
10
- /**
11
- * @example nasl.util.FromString<Date>(variable1)
12
- */
20
+ // @example nasl.util.FromString<Date>(variable1)
13
21
  export function FromString<T extends Decimal | Date | Time | DateTime | Long | Boolean>(value: String): T;
14
22
  export function ToString(value: Any): String;
15
23
 
16
- // 字符串函数
24
+ /* 字符串函数 */
17
25
  export function Length(str1: String): Decimal;
18
26
  export function Length<K, V>(str1: Map<K, V>): Decimal;
19
27
  export function Length<T>(str1: List<T>): Decimal;
@@ -27,19 +35,23 @@ declare namespace nasl.util {
27
35
  export function ToUpper(str1: String): String;
28
36
  export function Trim(str1: String): String;
29
37
 
30
- // 日期与时间函数
38
+ /* 日期与时间函数 */
31
39
  export function CurrDate(): Date;
32
40
  export function CurrDateTime(): DateTime;
33
41
  export function CurrTime(): Time;
34
- export function DateDiff<T extends Date | Time | DateTime>(dateTime1: T, dateTime2: T, calcType: 'd' | 'h' | 'm' | 's', isAbs: Boolean): Decimal;
35
- /* 为指定日期时间调整增加(减少)时间 */
42
+ // 计算两个日期时间之间的差值,calcType 支持年、季度、月、周、天、时分秒,默认为 'd'
43
+ export function DateDiff<T extends Date | Time | DateTime>(dateTime1: T, dateTime2: T, calcType: 'y' | 'q' | 'M' | 'w' | 'd' | 'h' | 'm' | 's', isAbs: Boolean): Decimal;
44
+ // 为指定日期时间调整增加(减少)时间
36
45
  export function AlterDateTime<T extends Date | DateTime>(dateTime: T, option: 'Increase' | 'Decrease', amount: Long, unit: 'day' | 'week' | 'month' | 'quarter' | 'year'): T;
37
- /* 按指定维度计算日期,如“所在年-第几周”。当输入为 DateTime 类型时,会把数据转到提供的时区的当地时间进行计算。*/
38
- export function GetDateCount<T extends Date | DateTime>(dateTime: T, metric: 'week-year', timeZone: string): Time;
39
- /* 按“星期几”获取指定日期范围内的日子。当输入为 DateTime 类型时,会把数据转到提供的时区的当地时间进行计算。target 取值范围 [1,2,3,4,5,6,7] */
40
- export function GetSpecificDaysOfWeek<T extends Date | DateTime>(startDate: T, endDate: T, target: List<Long>, timeZone?: String): List<T>;
46
+ /** 按指定维度计算日期的序号。当输入为 DateTime 类型时,会把数据转到提供的时区的当地时间进行计算
47
+ * @param dateTime: 日期或日期时间
48
+ * @param metric: 计算维度,格式为'小日期单位-大日期单位'。日期单位包括:'year'、'quarter'、'month'、'week'、'day'。如设置 'week-year',则返回当前日期是所在年的第几周, 'day-week',则返回当前日期是所在周的第几天。
49
+ */
50
+ export function GetDateCount<T extends Date | DateTime>(dateTime: T, metric: 'week-year'): Time;
51
+ // 按“星期几”获取指定日期范围内的日子。当输入为 DateTime 类型时,会把数据转到提供的时区的当地时间进行计算。target 取值范围 [1,2,3,4,5,6,7]
52
+ export function GetSpecificDaysOfWeek<T extends Date | DateTime>(startDate: T, endDate: T, target: List<Long>): List<T>;
41
53
 
42
- // 列表(List)函数
54
+ /* 列表(List)函数 */
43
55
  export function Add<T, K extends T>(list: List<T>, item: K): void;
44
56
  export function AddAll<T>(list: List<T>, addList: List<T>): Decimal;
45
57
  export function Contains<T, K extends T>(list: List<T>, item: K): Boolean;
@@ -66,7 +78,7 @@ declare namespace nasl.util {
66
78
  export function RemoveAt<T>(list: List<T>, index: Long): T;
67
79
  export function Set<T, K extends T>(list: List<T>, index: Decimal, item: K): T;
68
80
 
69
- // 映射(Map)函数
81
+ /* 映射(Map)函数 */
70
82
  export function MapContains<K, V>(map: Map<K, V>, key: K): Boolean;
71
83
  export function MapGet<K, V>(map: Map<K, V>, key: K): V;
72
84
  export function MapPut<K, V>(map: Map<K, V>, key: K, value: V): void;
@@ -74,62 +86,56 @@ declare namespace nasl.util {
74
86
  export function MapRemove<K, V>(map: Map<K, V>, key: K): void;
75
87
  export function MapValues<K, V>(map: Map<K, V>): List<V>;
76
88
 
77
- // 枚举函数
78
- /**
79
- * @example nasl.util.EnumToList<app.enums.aEnum>();
89
+ /* 枚举函数,项目中可使用的枚举类型均定义在 app.enums 中 */
90
+ /** 将指定枚举转换枚举value和text的List集合
91
+ * @example nasl.util.EnumToList<app.enums.UserSourceEnum>();
80
92
  */
81
93
  export function EnumToList<T extends Enums>(): List<{ text: String, value: String; }>;
82
- // 将指定枚举值转换为文本
94
+ // 返回枚举指定value的标题字符串
83
95
  export function EnumValueToText<T extends Enums>(value: any): String;
84
96
  // 在指定枚举中找到与参数相同的枚举值并返回
85
97
  export function StringToEnumValue<T extends Enums>(value: String): T;
86
98
 
87
- // 数学函数
88
- /**
89
- * 整数/小数 操作
99
+ /* 数学函数 */
100
+ /** 整数/小数 操作
90
101
  * @param mode: 'HalfUp' | 'TowardsZero' | 'TowardsInfinity' === '四舍五入' | '截断、向零取整,如 -2.6 取整为 -2' | '进位、向正负无穷取整,如 -1.1 取整为 -2'
91
102
  */
92
103
  export function Round(value: Decimal, mode: 'HalfUp' | 'TowardsZero' | 'TowardsInfinity'): Decimal;
93
-
94
- // 其他函数
104
+ /* 其他函数 */
95
105
  export function Clear<T>(struct: T): T;
96
106
  export function Clone<T>(struct: T): T;
107
+ // 判断参数是否为有效值,null、空字符串、纯空格、长度为0的集合均不被视为有效值,传入多个参数时,判断是否全部都是有效值 */
97
108
  export function HasValue(...args: Any[]): Boolean;
98
109
  // RandomInt 生成的数字为整数,如果需要指定位数的随机数,需要在数字前按照位数要求补 0
99
110
  export function RandomInt(start: Long, end: Long): Long;
100
111
 
101
112
  // New 系列函数使用
102
- /**
103
- * T 类型必填
113
+ /** 生成新的列表,T 类型必填
104
114
  * @example const variable1 = nasl.util.NewList<Boolean | Long>([true, false, 1])
105
115
  */
106
116
  export function NewList<T>(args: T[]): List<T>;
107
- /**
108
- * T 类型必填
117
+ /** 生成新的映射,K、T 类型必填
109
118
  * @example const variable1 = nasl.util.NewMap<String, Long>({'123': 456})
110
119
  */
111
120
  export function NewMap<K, T>(args: any): Map<K, T>;
112
- /**
113
- * T 类型必填
121
+ /** 生成新的数据实体,T 类型必填
114
122
  * class Entity1 { id: Long; property1: String; property2: String;}
115
123
  * @example const variable1 = nasl.util.NewEntity<Entity1>({id: 123, property1: '123', property2: '456'})
116
124
  */
117
125
  export function NewEntity<T>(arg: T): T;
118
- /**
119
- * T 类型必填
126
+ /** 生成新的结构体,T 类型必填
120
127
  * class Structure1 { id: Long; property1: String; property2: String;}
121
128
  * @example const variable1 = nasl.util.NewStructure<Structure1>({id: 123, property1: '123', property2: '456'})
122
129
  */
123
130
  export function NewStructure<T>(arg: T): T;
124
- /**
131
+ /** 生成新的匿名结构体, 无需定义类型
125
132
  * @example const variable1 = nasl.util.NewAnonymousStructure({property1: '123', property2: '456'})
126
133
  */
127
134
  export function NewAnonymousStructure(arg: Any): Any;
128
135
 
129
136
  export function consoleLog(arg: Any): void;
130
137
  export function jsonSerialize(arg: Any): String;
131
- /**
132
- * T 为返回值类型,必填
138
+ /** JSON 反序列化, T 为返回值类型,必填
133
139
  * @example nasl.util.jsonDeserialize<Boolean>(variable1);
134
140
  */
135
141
  export function jsonDeserialize<T>(arg: String): T;
@@ -103,4 +103,11 @@ export default interface ComponentAPI {
103
103
  aria?: Array<AriaAPI>;
104
104
 
105
105
  tsTypeParams?: string;
106
+ readablePropsMap?: { [name: string]: {
107
+ name: string;
108
+ title: string;
109
+ state: string;
110
+ prop: string;
111
+ icon?: string;
112
+ } };
106
113
  }
@@ -542,22 +542,39 @@ export class AuthLogicForCallInterface extends AuthLogic {
542
542
  ],
543
543
  function* warpForEachGenerator({ key, node: itemNode }) {
544
544
  if (itemNode) {
545
- code += `const __${key}_${node?.name} = `;
545
+ code += `let __${key}_${node?.name}`;
546
546
  let itemCode = '';
547
+ // 匿名数据结构 / 未设置类型的List/map 才进getInitCode
547
548
  if (
548
- asserts.isNewComposite(itemNode)
549
- || asserts.isNewList(itemNode)
550
- || asserts.isNewMap(itemNode)
549
+ (
550
+ asserts.isNewComposite(itemNode)
551
+ && itemNode.typeAnnotation?.typeKind === 'anonymousStructure'
552
+ )
553
+ || (
554
+ (asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
555
+ && !(itemNode?.typeAnnotation)
556
+ )
551
557
  ) {
552
- itemCode += yield* itemNode?.getInitCode(shiftState(state, code, {
558
+ code += ' = ';
559
+ itemCode += yield* itemNode?.getInitCode?.(shiftState(state, code, {
553
560
  inline: true
554
561
  })) ??
555
562
  returnOrigin('');
563
+ } else if (asserts.isNewComposite(itemNode) && itemNode.typeAnnotation?.typeKind === 'generic') { // new 带泛型的数据结构/实体 进这里
564
+ code += ' = ';
565
+ itemCode += (yield* itemNode?.getNewCompositeCode?.(shiftState(state, code, { inline: true }))) || 'null';
566
+ } else if ((itemNode as any)?.typeAnnotation && !(asserts.isCallQueryComponent(itemNode) && !itemNode.isAutoInfer())) {
567
+ code += ': ';
568
+ code += yield* (itemNode as any)?.typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
569
+ returnOrigin('');
556
570
  } else {
571
+ code += ' = ';
557
572
  itemCode = yield* itemNode?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
558
573
  returnOrigin('');
559
574
  }
560
- code += yield* self.getRightCode(itemCode, assignment, itemNode);
575
+ if (itemCode) {
576
+ code += yield* self.getRightCode(itemCode, assignment, itemNode);
577
+ }
561
578
  code += ';\n';
562
579
  }
563
580
  },
@@ -165,7 +165,7 @@ export class BindAttribute extends BaseNode {
165
165
  * @param source 需要合并的部分参数
166
166
  */
167
167
  constructor(source?: Partial<BindAttribute>) {
168
- source = { ...BindAttribute.getDefaultOptions(), ...source};
168
+ source = { ...BindAttribute.getDefaultOptions(), ...source };
169
169
  super(source);
170
170
  super.subConstructor(source);
171
171
  }
@@ -546,7 +546,7 @@ export class BindAttribute extends BaseNode {
546
546
  if (typeof options === 'string') {
547
547
  validationRule = (this.rules as ValidationRule[]).find((item) => item.name === options);
548
548
  if (!validationRule) {
549
- throw new Error(`找不到验证规则 ${ options}`);
549
+ throw new Error(`找不到验证规则 ${options}`);
550
550
  }
551
551
  } else {
552
552
  validationRule = options;
@@ -938,7 +938,7 @@ export class BindAttribute extends BaseNode {
938
938
  transfromUnionTypeAnnotation(expTypeAnnotation, this.app);
939
939
  if (expTypeAnnotation?.typeNamespace?.endsWith('.metadataTypes')) {
940
940
  const referenceNode =
941
- this.app.findNodeByCompleteName(`${expTypeAnnotation.typeNamespace }.${ expTypeAnnotation.typeName}`)
941
+ this.app.findNodeByCompleteName(`${expTypeAnnotation.typeNamespace}.${expTypeAnnotation.typeName}`)
942
942
  ?.typeAnnotation || {};
943
943
  value = `$utils['ToString']('${referenceNode?.typeNamespace}.${referenceNode.typeName}', ${value})`;
944
944
  } else {
@@ -970,7 +970,7 @@ export class BindAttribute extends BaseNode {
970
970
  }
971
971
 
972
972
  @withSourceMapGenerator
973
- *toEmbeddedTS(state = createCompilerState(), options: { carryName: boolean } = { carryName: false }): TranslatorGenerator {
973
+ *toEmbeddedTS(state = createCompilerState(), options: { carryName: boolean; } = { carryName: false }): TranslatorGenerator {
974
974
  const self = this;
975
975
  const { name, type, value, rules, expression, playground } = self;
976
976
  const humpName = self.toHump(name);
@@ -1037,7 +1037,7 @@ export class BindAttribute extends BaseNode {
1037
1037
 
1038
1038
  'dataSource',
1039
1039
  'converter',
1040
- ]
1040
+ ];
1041
1041
 
1042
1042
  // @ts-ignore
1043
1043
  if (prop?.implicitToString) {
@@ -1185,17 +1185,22 @@ export class BindAttribute extends BaseNode {
1185
1185
  ) {
1186
1186
  return node.parentNode;
1187
1187
  }
1188
- return this.findCurrentElementParent(node.parentNode);
1188
+ return this.findCurrentElementParent(node.parentNode);
1189
1189
 
1190
1190
  }
1191
- return undefined;
1191
+ return undefined;
1192
1192
 
1193
1193
  }
1194
1194
 
1195
1195
  @withSourceMap()
1196
1196
  toNaturalTS(state = createCompilerState()): string {
1197
1197
  let code = `${utils.firstLowerCase(utils.kebab2Camel(this.name))}: `;
1198
-
1198
+ if (['dataSchema'].includes(this.name)) {
1199
+ if (state?.typeMap?.[this.nodePath]) {
1200
+ code += `'${state?.typeMap?.[this.nodePath]}'`;
1201
+ return code;
1202
+ }
1203
+ }
1199
1204
  if (['destination', 'externalDestination'].includes(this.name) && this.type === 'dynamic') {
1200
1205
  code += (this as any)[this.name].toNaturalTS(
1201
1206
  shiftState(state, code, { tabSize: state.tabSize + 1, inline: true }),
@@ -1208,9 +1213,9 @@ export class BindAttribute extends BaseNode {
1208
1213
  });
1209
1214
  code += `\n${indent(state.tabSize)}]`;
1210
1215
  } else if (this.type === 'dynamic' && this.sync) {
1211
- code += 'sync('
1212
- code += this.expression?.toNaturalTS(shiftState(state, code, { tabSize: state.tabSize, inline: true }));
1213
- code += ')';
1216
+ const value = this.expression?.toNaturalTS(shiftState(state, code, { tabSize: state.tabSize, inline: true }));
1217
+ if (value) code += `sync(${value})`;
1218
+ else code += value;
1214
1219
  } else {
1215
1220
  if (this.type === 'string') code += `'${this.value?.replace(/'/g, "\\'")}'`;
1216
1221
  else if (this.type === 'static') code += `${this.value}`;
@@ -1275,7 +1280,7 @@ export function attrConvertCamelCase(str: string) {
1275
1280
  if (index === 0) {
1276
1281
  return strItem;
1277
1282
  }
1278
- return `${strItem.slice(0, 1).toUpperCase()}${strItem.slice(1)}`;
1283
+ return `${strItem.slice(0, 1).toUpperCase()}${strItem.slice(1)}`;
1279
1284
 
1280
1285
  });
1281
1286
  return strList.join('');
@@ -15,7 +15,7 @@ import type Match from './Match__';
15
15
  import type Logic from './Logic__';
16
16
  import type Param from './Param__';
17
17
  import { ElementToVueOptions } from './ViewElement__';
18
- import { ComponentCompletionPropertyMap } from './View__';
18
+ import { config } from '../config';
19
19
  import translator from '../bak/translator';
20
20
 
21
21
  type AttrObject = {
@@ -1903,7 +1903,8 @@ export class BusinessComponent extends BaseNode {
1903
1903
  if (item.tag === 'template' && item.haveScope()) {
1904
1904
  index += 1;
1905
1905
  }
1906
- if (ComponentCompletionPropertyMap[item.tag]) {
1906
+ if (config?.allNodesAPI && config?.allNodesAPI[item.tag] &&
1907
+ config?.allNodesAPI[item.tag].readablePropsMap) {
1907
1908
  componentList.push(item);
1908
1909
  }
1909
1910
  item.currentIndex = index;
@@ -2145,22 +2146,39 @@ export class BusinessComponent extends BaseNode {
2145
2146
  ],
2146
2147
  function* warpForEachGenerator({ key, node: itemNode }) {
2147
2148
  if (itemNode) {
2148
- code += `const __${key}_${node?.name} = `;
2149
+ code += `let __${key}_${node?.name}`;
2149
2150
  let itemCode = '';
2151
+ // 匿名数据结构 / 未设置类型的List/map 才进getInitCode
2150
2152
  if (
2151
- asserts.isNewComposite(itemNode)
2152
- || asserts.isNewList(itemNode)
2153
- || asserts.isNewMap(itemNode)
2153
+ (
2154
+ asserts.isNewComposite(itemNode)
2155
+ && itemNode.typeAnnotation?.typeKind === 'anonymousStructure'
2156
+ )
2157
+ || (
2158
+ (asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
2159
+ && !(itemNode?.typeAnnotation)
2160
+ )
2154
2161
  ) {
2155
- itemCode += yield* itemNode?.getInitCode(shiftState(state, code, {
2162
+ code += ' = ';
2163
+ itemCode += yield* itemNode?.getInitCode?.(shiftState(state, code, {
2156
2164
  inline: true
2157
2165
  })) ??
2158
2166
  returnOrigin('');
2167
+ } else if (asserts.isNewComposite(itemNode) && itemNode.typeAnnotation?.typeKind === 'generic') { // new 带泛型的数据结构/实体 进这里
2168
+ code += ' = ';
2169
+ itemCode += (yield* itemNode?.getNewCompositeCode?.(shiftState(state, code, { inline: true }))) || 'null';
2170
+ } else if ((itemNode as any)?.typeAnnotation && !(asserts.isCallQueryComponent(itemNode) && !itemNode.isAutoInfer())) {
2171
+ code += ': ';
2172
+ code += yield* (itemNode as any)?.typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2173
+ returnOrigin('');
2159
2174
  } else {
2175
+ code += ' = ';
2160
2176
  itemCode = yield* itemNode?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2161
2177
  returnOrigin('');
2162
2178
  }
2163
- code += yield* self.getRightCode(itemCode, assignment, itemNode);
2179
+ if (itemCode) {
2180
+ code += yield* self.getRightCode(itemCode, assignment, itemNode);
2181
+ }
2164
2182
  code += ';\n';
2165
2183
  }
2166
2184
  },
@@ -351,22 +351,39 @@ export class BusinessLogic extends Logic {
351
351
  ],
352
352
  function* warpForEachGenerator({ key, node: itemNode }) {
353
353
  if (itemNode) {
354
- code += `const __${key}_${node?.name} = `;
354
+ code += `let __${key}_${node?.name}`;
355
355
  let itemCode = '';
356
+ // 匿名数据结构 / 未设置类型的List/map 才进getInitCode
356
357
  if (
357
- asserts.isNewComposite(itemNode)
358
- || asserts.isNewList(itemNode)
359
- || asserts.isNewMap(itemNode)
358
+ (
359
+ asserts.isNewComposite(itemNode)
360
+ && itemNode.typeAnnotation?.typeKind === 'anonymousStructure'
361
+ )
362
+ || (
363
+ (asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
364
+ && !(itemNode?.typeAnnotation)
365
+ )
360
366
  ) {
361
- itemCode += yield* itemNode?.getInitCode(shiftState(state, code, {
367
+ code += ' = ';
368
+ itemCode += yield* itemNode?.getInitCode?.(shiftState(state, code, {
362
369
  inline: true
363
370
  })) ??
364
371
  returnOrigin('');
372
+ } else if (asserts.isNewComposite(itemNode) && itemNode.typeAnnotation?.typeKind === 'generic') { // new 带泛型的数据结构/实体 进这里
373
+ code += ' = ';
374
+ itemCode += (yield* itemNode?.getNewCompositeCode?.(shiftState(state, code, { inline: true }))) || 'null';
375
+ } else if ((itemNode as any)?.typeAnnotation && !(asserts.isCallQueryComponent(itemNode) && !itemNode.isAutoInfer())) {
376
+ code += ': ';
377
+ code += yield* (itemNode as any)?.typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
378
+ returnOrigin('');
365
379
  } else {
380
+ code += ' = ';
366
381
  itemCode = yield* itemNode?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
367
382
  returnOrigin('');
368
383
  }
369
- code += yield* self.getRightCode(itemCode, assignment, itemNode);
384
+ if (itemCode) {
385
+ code += yield* self.getRightCode(itemCode, assignment, itemNode);
386
+ }
370
387
  code += ';\n';
371
388
  }
372
389
  },
@@ -716,8 +716,8 @@ export class CallInterface extends LogicItem {
716
716
  if (!arg) return;
717
717
  const idx = logicParam.findIndex((params) => arg.keyword === params.name);
718
718
  const param = logicParam[idx];
719
-
720
- arg.paramRequired = param?.required;
719
+ const hasDefaultValue = Boolean(param?.defaultValue?.expression);
720
+ arg.paramRequired = hasDefaultValue ? false : param?.required;
721
721
  arg.paramTypeAnnotation = undefined;
722
722
  arg.paramDefaultValue = undefined;
723
723
  // 取到是不是必填放入参数中
@@ -1511,7 +1511,7 @@ export class CallLogic extends LogicItem {
1511
1511
  }
1512
1512
  };
1513
1513
  // 调用实体逻辑特殊处理
1514
- if (tsCalleeNamespace.endsWith('.logics')) calleeKey = calleeKey.replace('.logics', 'Entity');
1514
+ if (tsCalleeNamespace.startsWith('app.dataSources.') && tsCalleeNamespace.endsWith('.logics')) calleeKey = calleeKey.replace('.logics', 'Entity');
1515
1515
  code += calleeKey;
1516
1516
  setTypeArguments();
1517
1517
  setInputParam();
@@ -1276,7 +1276,7 @@ export class Logic extends Annotatable {
1276
1276
  }
1277
1277
 
1278
1278
  get __isVirtual() {
1279
- const isDisabled = !!this.getAncestor('HistoryProcessV2') || ['enabled', 'history'].includes(this.processV2?.status)
1279
+ const isDisabled = !!this.getAncestor('HistoryProcessV2') || ['enabled', 'history'].includes(this.processV2?.status);
1280
1280
  return isDisabled || this.process?.__isVirtual || false;
1281
1281
  }
1282
1282
 
@@ -1551,7 +1551,7 @@ export class Logic extends Annotatable {
1551
1551
  const self = this;
1552
1552
 
1553
1553
  // 获取所有子节点用于树上填充
1554
- self.getSubLogics()
1554
+ self.getSubLogics();
1555
1555
 
1556
1556
  yield waitOqlQueryComponentChildrenFinish(self);
1557
1557
  let code = '';
@@ -1610,7 +1610,7 @@ export class Logic extends Annotatable {
1610
1610
  leftIndex.length === 1
1611
1611
  ? yield* el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
1612
1612
  : yield* el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
1613
- returnOrigin('');
1613
+ returnOrigin('');
1614
1614
  const advanceVar = self.variables?.find(
1615
1615
  (variable) => !variable.typeAnnotation && leftCode === variable.name,
1616
1616
  );
@@ -1663,7 +1663,7 @@ export class Logic extends Annotatable {
1663
1663
  leftIndex.length === 1
1664
1664
  ? yield* assignment.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
1665
1665
  : yield* assignment.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
1666
- returnOrigin('');
1666
+ returnOrigin('');
1667
1667
  if (leftCode === node.name) {
1668
1668
  const rightNode: any =
1669
1669
  rightIndex.length === 1
@@ -1934,7 +1934,7 @@ export class Logic extends Annotatable {
1934
1934
  leftIndex.length === 1
1935
1935
  ? yield* el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
1936
1936
  : yield* el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
1937
- returnOrigin('');
1937
+ returnOrigin('');
1938
1938
  const advanceVar = self.variables?.find(
1939
1939
  (variable) => !variable.typeAnnotation && leftCode === variable.name,
1940
1940
  );
@@ -2049,7 +2049,7 @@ export class Logic extends Annotatable {
2049
2049
  leftIndex.length === 1
2050
2050
  ? yield* assignment.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
2051
2051
  : yield* assignment.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2052
- returnOrigin('');
2052
+ returnOrigin('');
2053
2053
  if (leftCode === node.name) {
2054
2054
  const rightNode: any =
2055
2055
  rightIndex.length === 1
@@ -2151,22 +2151,39 @@ export class Logic extends Annotatable {
2151
2151
  ],
2152
2152
  function* warpForEachGenerator({ key, node: itemNode }) {
2153
2153
  if (itemNode) {
2154
- code += `const __${key}_${node?.name} = `;
2154
+ code += `let __${key}_${node?.name}`;
2155
2155
  let itemCode = '';
2156
+ // 匿名数据结构 / 未设置类型的List/map 才进getInitCode
2156
2157
  if (
2157
- asserts.isNewComposite(itemNode)
2158
- || asserts.isNewList(itemNode)
2159
- || asserts.isNewMap(itemNode)
2158
+ (
2159
+ asserts.isNewComposite(itemNode)
2160
+ && itemNode.typeAnnotation?.typeKind === 'anonymousStructure'
2161
+ )
2162
+ || (
2163
+ (asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
2164
+ && !(itemNode?.typeAnnotation)
2165
+ )
2160
2166
  ) {
2161
- itemCode += yield* itemNode?.getInitCode(shiftState(state, code, {
2167
+ code += ' = ';
2168
+ itemCode += yield* itemNode?.getInitCode?.(shiftState(state, code, {
2162
2169
  inline: true
2163
2170
  })) ??
2164
- returnOrigin('');
2171
+ returnOrigin('');
2172
+ } else if (asserts.isNewComposite(itemNode) && itemNode.typeAnnotation?.typeKind === 'generic') { // new 带泛型的数据结构/实体 进这里
2173
+ code += ' = ';
2174
+ itemCode += (yield* itemNode?.getNewCompositeCode?.(shiftState(state, code, { inline: true }))) || 'null';
2175
+ } else if ((itemNode as any)?.typeAnnotation && !(asserts.isCallQueryComponent(itemNode) && !itemNode.isAutoInfer())) {
2176
+ code += ': ';
2177
+ code += yield* (itemNode as any)?.typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2178
+ returnOrigin('');
2165
2179
  } else {
2180
+ code += ' = ';
2166
2181
  itemCode = yield* itemNode?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2167
2182
  returnOrigin('');
2168
2183
  }
2169
- code += yield* self.getRightCode(itemCode, assignment, itemNode);
2184
+ if (itemCode) {
2185
+ code += yield* self.getRightCode(itemCode, assignment, itemNode);
2186
+ }
2170
2187
  code += ';\n';
2171
2188
  }
2172
2189
  },
@@ -2277,19 +2294,29 @@ export class Logic extends Annotatable {
2277
2294
  }
2278
2295
 
2279
2296
  code += `(`;
2280
- if (this.parentNode?.concept === 'BindEvent') {
2281
- code += `event`;
2297
+ if (state?.typeMap?.[this.nodePath]) {
2298
+ code += state?.typeMap?.[this.nodePath];
2299
+ } else {
2300
+ if (this.parentNode?.concept === 'BindEvent') {
2301
+ code += `event`;
2302
+ }
2303
+ this.params.forEach((param, index) => {
2304
+ code += param.toNaturalTS(shiftState(state, code, { inline: true }));
2305
+ if (index !== this.params.length - 1) code += ', ';
2306
+ });
2282
2307
  }
2283
- this.params.forEach((param, index) => {
2284
- code += param.toNaturalTS(shiftState(state, code, { inline: true }));
2285
- if (index !== this.params.length - 1) code += ', ';
2286
- });
2287
2308
  code += ')';
2288
2309
 
2289
2310
  // 兼容 return 没有类型情况
2290
- if (this.returns.length && (this.returns[0].typeAnnotation || this.returns[0].__TypeAnnotation)) {
2291
- code += ': ';
2292
- code += this.returns[0].typeAnnotation?.toNaturalTS(shiftState(state, code, { inline: true })) || this.returns[0].__TypeAnnotation?.toNaturalTS(shiftState(state, code, { inline: true }));
2311
+ if (this.returns.length) {
2312
+ if (state?.typeMap?.[this.returns[0]?.nodePath]) {
2313
+ code += ': ';
2314
+ code += state?.typeMap?.[this.returns[0]?.nodePath];
2315
+ } else if (this.returns[0].typeAnnotation || this.returns[0].__TypeAnnotation) {
2316
+ code += ': ';
2317
+ const typeAnnotation = this.returns[0].typeAnnotation || this.returns[0].__TypeAnnotation;
2318
+ code += typeAnnotation?.toNaturalTS(shiftState(state, code, { inline: true }));
2319
+ }
2293
2320
  }
2294
2321
 
2295
2322
  if (state.declaration) {
@@ -2372,17 +2399,17 @@ export class Logic extends Annotatable {
2372
2399
  code += ';';
2373
2400
  } else {
2374
2401
  code += ' {\n';
2375
-
2402
+
2376
2403
  this.variables.forEach((variable) => {
2377
2404
  code += `${indent(state.tabSize + 1)}let `;
2378
2405
  code += variable.toTextualNASL(shiftState(state, code, { inline: true }));
2379
2406
  code += ';\n';
2380
2407
  });
2381
2408
  if (this.variables.length) code += '\n';
2382
-
2409
+
2383
2410
  this.body.forEach((item) => {
2384
2411
  let partialCode = '';
2385
-
2412
+
2386
2413
  // if (!state.focusedNodePath && item.concept === 'End') code += `${indent(state.tabSize + 1)}/* 当前位置 */\n`;
2387
2414
  if (item.toTextualNASL) {
2388
2415
  partialCode = item.toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1 }));
@@ -2515,8 +2542,8 @@ export class Logic extends Annotatable {
2515
2542
  collectionTSCode === '__IDENTIFIER__'
2516
2543
  ? collectionTSCode
2517
2544
  : callFunction.isLoopMap && index === 0
2518
- ? `${collectionTSCode}.__getKey(0)`
2519
- : `${collectionTSCode}.__get(0)`,
2545
+ ? `${collectionTSCode}.__getKey(0)`
2546
+ : `${collectionTSCode}.__get(0)`,
2520
2547
  );
2521
2548
  }
2522
2549
  });
@@ -2658,9 +2685,8 @@ export class Logic extends Annotatable {
2658
2685
  if (asserts.isFrontendLibrary(this.parentNode)) {
2659
2686
  _path += `/frontends/${this.parentNode.type}`;
2660
2687
  } else if (this.parentNode.concept === 'BindEvent' && this.getAncestor('Frontend')) {
2661
- _path += `/frontendTypes/${this.getAncestor('FrontendType')?.name}/frontends/${
2662
- this.getAncestor('Frontend')?.name
2663
- }/bindEvents/${name}.ts`;
2688
+ _path += `/frontendTypes/${this.getAncestor('FrontendType')?.name}/frontends/${this.getAncestor('Frontend')?.name
2689
+ }/bindEvents/${name}.ts`;
2664
2690
  }
2665
2691
  return `/embedded/${this.getAncestor('App')?.name}${_path}/logics/${name}.ts`;
2666
2692
  }
@@ -2750,9 +2776,9 @@ export class Logic extends Annotatable {
2750
2776
  super.delete();
2751
2777
  this.body.forEach((el) => {
2752
2778
  if (asserts.isCallInterface(el)) {
2753
- el.deleteCallNode()
2779
+ el.deleteCallNode();
2754
2780
  }
2755
- })
2781
+ });
2756
2782
  this.traverseChildren(async (el) => {
2757
2783
  if (el?.concept === 'CallQueryComponent') (el as CallQueryComponent).removeStructure();
2758
2784
  // 仅仅针对 自定义连接器下的 Loigc,其他需要界定边界