@lcap/nasl 3.8.2-beta.9 → 3.8.3-beta.2

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 (233) hide show
  1. package/ai-engineer.config.js +617 -0
  2. package/out/common/BaseNode.d.ts +9 -4
  3. package/out/common/BaseNode.js +43 -10
  4. package/out/common/BaseNode.js.map +1 -1
  5. package/out/concepts/AuthLogicForCallInterface__.js +2 -50
  6. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
  7. package/out/concepts/BackendVariable__.js +16 -1
  8. package/out/concepts/BackendVariable__.js.map +1 -1
  9. package/out/concepts/BindAttribute__.js +12 -4
  10. package/out/concepts/BindAttribute__.js.map +1 -1
  11. package/out/concepts/BindDirective__.js +1 -1
  12. package/out/concepts/BindDirective__.js.map +1 -1
  13. package/out/concepts/BindStyle__.js +1 -1
  14. package/out/concepts/BindStyle__.js.map +1 -1
  15. package/out/concepts/BusinessComponent__.js +2 -42
  16. package/out/concepts/BusinessComponent__.js.map +1 -1
  17. package/out/concepts/BusinessLogic__.js +2 -50
  18. package/out/concepts/BusinessLogic__.js.map +1 -1
  19. package/out/concepts/CallFunction__.d.ts +1 -1
  20. package/out/concepts/CallFunction__.js +1 -1
  21. package/out/concepts/CallLogic__.js +7 -1
  22. package/out/concepts/CallLogic__.js.map +1 -1
  23. package/out/concepts/CallQueryComponent__.d.ts +1 -0
  24. package/out/concepts/CallQueryComponent__.js +23 -12
  25. package/out/concepts/CallQueryComponent__.js.map +1 -1
  26. package/out/concepts/Destination__.js +11 -8
  27. package/out/concepts/Destination__.js.map +1 -1
  28. package/out/concepts/EntityProperty__.js +3 -2
  29. package/out/concepts/EntityProperty__.js.map +1 -1
  30. package/out/concepts/Entity__.js +1 -1
  31. package/out/concepts/Entity__.js.map +1 -1
  32. package/out/concepts/Identifier__.d.ts +2 -0
  33. package/out/concepts/Identifier__.js +51 -5
  34. package/out/concepts/Identifier__.js.map +1 -1
  35. package/out/concepts/Interface__.js +1 -1
  36. package/out/concepts/Interface__.js.map +1 -1
  37. package/out/concepts/Logic__.js +33 -111
  38. package/out/concepts/Logic__.js.map +1 -1
  39. package/out/concepts/MemberExpression__.d.ts +1 -1
  40. package/out/concepts/MemberExpression__.js +15 -3
  41. package/out/concepts/MemberExpression__.js.map +1 -1
  42. package/out/concepts/OqlQueryComponent__.js +37 -12
  43. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  44. package/out/concepts/OverriddenLogic__.js +2 -50
  45. package/out/concepts/OverriddenLogic__.js.map +1 -1
  46. package/out/concepts/Param__.js +5 -4
  47. package/out/concepts/Param__.js.map +1 -1
  48. package/out/concepts/ProcessElementV2__.js +4 -0
  49. package/out/concepts/ProcessElementV2__.js.map +1 -1
  50. package/out/concepts/ProcessElement__.js +4 -0
  51. package/out/concepts/ProcessElement__.js.map +1 -1
  52. package/out/concepts/ProcessV2__.js +4 -0
  53. package/out/concepts/ProcessV2__.js.map +1 -1
  54. package/out/concepts/Process__.js +4 -0
  55. package/out/concepts/Process__.js.map +1 -1
  56. package/out/concepts/QueryOrderByExpression__.d.ts +0 -1
  57. package/out/concepts/QueryOrderByExpression__.js +0 -1
  58. package/out/concepts/QueryOrderByExpression__.js.map +1 -1
  59. package/out/concepts/Structure__.js +5 -7
  60. package/out/concepts/Structure__.js.map +1 -1
  61. package/out/concepts/SubLogic__.js +5 -50
  62. package/out/concepts/SubLogic__.js.map +1 -1
  63. package/out/concepts/Variable__.js +5 -0
  64. package/out/concepts/Variable__.js.map +1 -1
  65. package/out/concepts/ViewElement__.d.ts +1 -0
  66. package/out/concepts/ViewElement__.js +16 -6
  67. package/out/concepts/ViewElement__.js.map +1 -1
  68. package/out/concepts/View__.js +48 -49
  69. package/out/concepts/View__.js.map +1 -1
  70. package/out/natural/genNaturalTS.d.ts +45 -10
  71. package/out/natural/genNaturalTS.js +57 -33
  72. package/out/natural/genNaturalTS.js.map +1 -1
  73. package/out/natural/getContext/getUILib.js +6 -3
  74. package/out/natural/getContext/getUILib.js.map +1 -1
  75. package/out/natural/getContext/index.d.ts +20 -7
  76. package/out/natural/getContext/index.js +143 -23
  77. package/out/natural/getContext/index.js.map +1 -1
  78. package/out/natural/getContext/naslStdlibMap.js +8 -8
  79. package/out/natural/getContext/naslStdlibMap.js.map +1 -1
  80. package/out/natural/tools.d.ts +16 -0
  81. package/out/natural/tools.js +110 -2
  82. package/out/natural/tools.js.map +1 -1
  83. package/out/natural/transformTS2UI.js +343 -292
  84. package/out/natural/transformTS2UI.js.map +1 -1
  85. package/out/natural/transformTSCode.d.ts +3 -5
  86. package/out/natural/transformTSCode.js +30 -1089
  87. package/out/natural/transformTSCode.js.map +1 -1
  88. package/out/natural/transforms/registerTransform.d.ts +7 -0
  89. package/out/natural/transforms/registerTransform.js +24 -0
  90. package/out/natural/transforms/registerTransform.js.map +1 -0
  91. package/out/natural/transforms/transform2LogicItem.d.ts +24 -0
  92. package/out/natural/transforms/transform2LogicItem.js +1240 -0
  93. package/out/natural/transforms/transform2LogicItem.js.map +1 -0
  94. package/out/natural/transforms/transform2TypeAnnotation.d.ts +2 -0
  95. package/out/natural/transforms/transform2TypeAnnotation.js +86 -0
  96. package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -0
  97. package/out/natural/transforms/utils.d.ts +8 -0
  98. package/out/natural/transforms/utils.js +59 -0
  99. package/out/natural/transforms/utils.js.map +1 -0
  100. package/out/server/getLogics.js +12 -12
  101. package/out/server/getLogics.js.map +1 -1
  102. package/out/server/naslServer.d.ts +2 -2
  103. package/out/server/naslServer.js +48 -18
  104. package/out/server/naslServer.js.map +1 -1
  105. package/out/server/semanticData.d.ts +32 -0
  106. package/out/server/semanticData.js +371 -0
  107. package/out/server/semanticData.js.map +1 -0
  108. package/out/server/translator.js +5 -0
  109. package/out/server/translator.js.map +1 -1
  110. package/out/templator/block2nasl/jsx2nasl/index.d.ts +5 -0
  111. package/out/templator/block2nasl/jsx2nasl/index.js +15 -0
  112. package/out/templator/block2nasl/jsx2nasl/index.js.map +1 -0
  113. package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.d.ts +3 -0
  114. package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js +213 -0
  115. package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js.map +1 -0
  116. package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.d.ts +14 -0
  117. package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js +201 -0
  118. package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js.map +1 -0
  119. package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.d.ts +4 -0
  120. package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js +186 -0
  121. package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js.map +1 -0
  122. package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.d.ts +28 -0
  123. package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js +336 -0
  124. package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js.map +1 -0
  125. package/out/templator/block2nasl/jsx2nasl/utils.d.ts +2 -0
  126. package/out/templator/block2nasl/jsx2nasl/utils.js +26 -0
  127. package/out/templator/block2nasl/jsx2nasl/utils.js.map +1 -0
  128. package/out/templator/block2nasl/transformBlock2Nasl.d.ts +10 -0
  129. package/out/templator/block2nasl/transformBlock2Nasl.js +122 -0
  130. package/out/templator/block2nasl/transformBlock2Nasl.js.map +1 -0
  131. package/out/templator/block2nasl/viewMergeBlock.d.ts +9 -0
  132. package/out/templator/block2nasl/viewMergeBlock.js +111 -0
  133. package/out/templator/block2nasl/viewMergeBlock.js.map +1 -0
  134. package/out/translator/types.d.ts +2 -0
  135. package/out/translator/utils.js +1 -1
  136. package/out/translator/utils.js.map +1 -1
  137. package/out/utils/index.js +0 -4
  138. package/out/utils/index.js.map +1 -1
  139. package/out/utils/language-cache/constant.d.ts +2 -1
  140. package/out/utils/language-cache/constant.js +1 -0
  141. package/out/utils/language-cache/constant.js.map +1 -1
  142. package/out/utils/language-cache/nasl.d.ts +1 -0
  143. package/out/utils/language-cache/nasl.js +9 -1
  144. package/out/utils/language-cache/nasl.js.map +1 -1
  145. package/package.json +6 -2
  146. package/sandbox-natural/stdlib/nasl.core.d.ts +54 -0
  147. package/sandbox-natural/stdlib/nasl.oql.d.ts +22 -0
  148. package/sandbox-natural/stdlib/nasl.ui.d.ts +78 -0
  149. package/sandbox-natural/stdlib/nasl.ui.h5.d.ts +1684 -1643
  150. package/sandbox-natural/stdlib/nasl.ui.h5.json +15746 -15045
  151. package/sandbox-natural/stdlib/nasl.ui.pc.d.ts +5341 -5154
  152. package/sandbox-natural/stdlib/nasl.ui.pc.json +31176 -30681
  153. package/sandbox-natural/stdlib/{nasl.util.ts → nasl.util.d.ts} +49 -43
  154. package/src/common/BaseNode.ts +50 -8
  155. package/src/concepts/AuthLogicForCallInterface__.ts +3 -56
  156. package/src/concepts/BackendVariable__.ts +16 -1
  157. package/src/concepts/BindAttribute__.ts +18 -13
  158. package/src/concepts/BindDirective__.ts +1 -1
  159. package/src/concepts/BindStyle__.ts +1 -1
  160. package/src/concepts/BusinessComponent__.ts +6 -51
  161. package/src/concepts/BusinessLogic__.ts +4 -56
  162. package/src/concepts/CallFunction__.ts +1 -1
  163. package/src/concepts/CallLogic__.ts +21 -16
  164. package/src/concepts/CallQueryComponent__.ts +26 -12
  165. package/src/concepts/Destination__.ts +14 -12
  166. package/src/concepts/EntityProperty__.ts +5 -5
  167. package/src/concepts/Entity__.ts +1 -1
  168. package/src/concepts/Identifier__.ts +57 -6
  169. package/src/concepts/Interface__.ts +1 -1
  170. package/src/concepts/Logic__.ts +44 -134
  171. package/src/concepts/MemberExpression__.ts +21 -7
  172. package/src/concepts/OqlQueryComponent__.ts +29 -5
  173. package/src/concepts/OverriddenLogic__.ts +4 -56
  174. package/src/concepts/Param__.ts +5 -4
  175. package/src/concepts/ProcessElementV2__.ts +4 -0
  176. package/src/concepts/ProcessElement__.ts +4 -0
  177. package/src/concepts/ProcessV2__.ts +5 -0
  178. package/src/concepts/Process__.ts +4 -0
  179. package/src/concepts/QueryOrderByExpression__.ts +0 -1
  180. package/src/concepts/Structure__.ts +5 -7
  181. package/src/concepts/SubLogic__.ts +6 -56
  182. package/src/concepts/Variable__.ts +9 -5
  183. package/src/concepts/ViewElement__.ts +24 -7
  184. package/src/concepts/View__.ts +75 -76
  185. package/src/natural/genNaturalTS.ts +88 -39
  186. package/src/natural/getContext/getUILib.ts +6 -3
  187. package/src/natural/getContext/index.ts +125 -23
  188. package/src/natural/getContext/naslStdlibMap.ts +8 -8
  189. package/src/natural/tools.ts +107 -2
  190. package/src/natural/transformTS2UI.ts +190 -137
  191. package/src/natural/transformTSCode.ts +29 -1055
  192. package/src/natural/transforms/registerTransform.ts +34 -0
  193. package/src/natural/transforms/transform2LogicItem.ts +1335 -0
  194. package/src/natural/transforms/transform2TypeAnnotation.ts +77 -0
  195. package/src/natural/transforms/utils.ts +25 -0
  196. package/src/server/getLogics.ts +12 -12
  197. package/src/server/naslServer.ts +54 -19
  198. package/src/server/semanticData.ts +447 -0
  199. package/src/server/translator.ts +5 -0
  200. package/src/templator/block2nasl/jsx2nasl/index.ts +11 -0
  201. package/src/templator/block2nasl/jsx2nasl/transform-expression2nasl.ts +238 -0
  202. package/src/templator/block2nasl/jsx2nasl/transform-func2nasl.ts +241 -0
  203. package/src/templator/block2nasl/jsx2nasl/transform-tstype2nasl.ts +213 -0
  204. package/src/templator/block2nasl/jsx2nasl/transform-tsx2nasl.ts +422 -0
  205. package/src/templator/block2nasl/jsx2nasl/utils.ts +19 -0
  206. package/src/templator/block2nasl/transformBlock2Nasl.ts +99 -0
  207. package/src/templator/block2nasl/viewMergeBlock.ts +150 -0
  208. package/src/translator/types.ts +2 -0
  209. package/src/translator/utils.ts +2 -2
  210. package/src/utils/index.ts +0 -4
  211. package/src/utils/language-cache/constant.ts +1 -0
  212. package/src/utils/language-cache/nasl.ts +6 -0
  213. package/test/concepts/logic/__snapshots__/toEmbeddedTS.spec.ts.snap +182 -0
  214. package/test/concepts/logic/constant.ts +5 -0
  215. package/test/concepts/logic/fixtures/variable-host-call-logic-member-expression.json +267 -0
  216. package/test/concepts/logic/fixtures/variable-host-call-logic-nested-member-expression copy.json +457 -0
  217. package/test/concepts/logic/fixtures/variable-host-call-logic-with-handle-error-member-expression.json +267 -0
  218. package/test/concepts/logic/toEmbeddedTS.spec.ts +15 -0
  219. package/test/tdd/dataQuery/QueryFieldExpression/case1/ast.json +7 -0
  220. package/test/tdd/dataQuery/QueryFieldExpression/case1/natural.ts.txt +1 -0
  221. package/test/tdd/dataQuery/QueryFieldExpression/case2/ast.json +7 -0
  222. package/test/tdd/dataQuery/QueryFieldExpression/case2/natural.ts.txt +1 -0
  223. package/test/tdd/transform/case1/ast.json +243 -0
  224. package/test/tdd/transform/case1/natural.ts.md +20 -0
  225. package/test/tdd/transform/case2/ast.json +207 -0
  226. package/test/tdd/transform/case2/natural.ts.md +12 -0
  227. package/test/tdd.test.js +10 -0
  228. package/test/tdd.transform.test.js +38 -0
  229. package/test/utils.js +40 -0
  230. package/sandbox-natural/stdlib/nasl.core.ts +0 -36
  231. package/sandbox-natural/stdlib/nasl.oql.ts +0 -14
  232. package/sandbox-natural/stdlib/nasl.ui.pre.d.ts +0 -90
  233. 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
- export function FormatNumber(doubleValue: Decimal | Integer, digits: Integer, showGroups: Boolean): String;
5
- /**
6
- * @example nasl.util.FormatDateTime(dataTime1, 'yyyy-MM-dd HH:mm:ss', 'global')
7
- */
16
+ export function FormatNumber(doubleValue: Decimal | Long, digits: Long, showGroups: Boolean): String;
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
- */
13
- export function FromString<T extends Decimal | Date | Time | DateTime | Integer | Boolean>(value: String): T;
20
+ // @example nasl.util.FromString<Date>(variable1)
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;
@@ -22,24 +30,28 @@ declare namespace nasl.util {
22
30
  export function LastIndexOf(str: String, search: String, ignoreCase: Boolean): Decimal;
23
31
  export function Replace(str: String, search: String, replace: String): String;
24
32
  export function Split(str: String, seperator: String): List<String>;
25
- export function SubString(str: String, start: Decimal, length: Integer): String;
33
+ export function SubString(str: String, start: Decimal, length: Long): String;
26
34
  export function ToLower(str1: String): String;
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;
@@ -58,15 +70,15 @@ declare namespace nasl.util {
58
70
  export function ListReverse<T>(list: List<T>): void;
59
71
  export function ListSlice<T>(list: List<T>, start: Decimal, end: Decimal): List<T>;
60
72
  export function ListSort<T>(list: List<T>, by: (item: T) => any, sort: Boolean): void;
61
- export function ListSum<T extends Integer | Decimal>(list: List<T>): T;
73
+ export function ListSum<T extends Long | Decimal>(list: List<T>): T;
62
74
  export function ListToMap<T, K extends Boolean | Decimal | Decimal | String, V>(map: List<T>, byKey: (elem: T) => K, byVal: (elem: T) => V): Map<K, V>;
63
75
  export function ListTransform<T0, T>(list: List<T0>, by: (elem: T0) => T): List<T>;
64
76
  export function Get<T>(list: List<T>, index: Decimal): T;
65
77
  export function Remove<T, K extends T>(list: List<T>, item: K): void;
66
- export function RemoveAt<T>(list: List<T>, index: Integer): T;
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
- export function RandomInt(start: Integer, end: Integer): Integer;
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;
@@ -20,6 +20,8 @@ export function setActionable(value: boolean) {
20
20
  actionable = value;
21
21
  }
22
22
 
23
+ import { subLogicCtx, varScopeCtx } from '../../../nasl/src/server/semanticData';
24
+
23
25
  const patchCompose = (node: BaseNode, type = 'add') => {
24
26
  if (node?.composedBy) {
25
27
  const app = (node as any)?.app;
@@ -942,7 +944,7 @@ export class BaseNode extends EventEmitter {
942
944
  }
943
945
 
944
946
  get app() {
945
- return this.getAncestor('App') as App;
947
+ return varScopeCtx.isFirstScreen ? varScopeCtx.app : this.getAncestor('App') as App;
946
948
  }
947
949
 
948
950
  /**
@@ -1493,21 +1495,21 @@ export class BaseNode extends EventEmitter {
1493
1495
  }, whitelist);
1494
1496
  }
1495
1497
 
1496
- /**
1498
+ /**
1497
1499
  * 迭代所有子节点
1498
1500
  *
1499
- * @description 严格迭代所有子节点!排除属性!条件满足时可提前终止!
1501
+ * @description 严格迭代所有子节点!排除属性!条件满足时整个遍历全部终止!
1500
1502
  */
1501
1503
  traverseStrictChildrenStopWhen(cb: (el: types.SyntaxNode) => void, setStopFlag: (el: types.SyntaxNode) => boolean, whitelist?: string[]): void {
1502
1504
  let shouldStop = false;
1503
1505
 
1504
- // if ((node instanceof View || node instanceof ViewElement) && node.auth) flag = true;
1505
- function traverse(node: any) {
1506
+ function __traverse(node: any) {
1506
1507
  if (asserts.isBaseNode(node)) {
1507
1508
  cb(node as types.SyntaxNode);
1508
1509
  }
1509
1510
 
1510
1511
  shouldStop = shouldStop || setStopFlag(node);
1512
+
1511
1513
  if (shouldStop) {
1512
1514
  return;
1513
1515
  }
@@ -1522,14 +1524,54 @@ export class BaseNode extends EventEmitter {
1522
1524
  for (const property of propertyKeys) {
1523
1525
  const child = node[property as keyof BaseNode];
1524
1526
  if (!child) continue;
1525
- else if (Array.isArray(child)) child?.forEach?.((node: types.SyntaxNode) => traverse(node));
1526
- else traverse(child);
1527
+ else if (Array.isArray(child)) child?.forEach?.((node: types.SyntaxNode) => __traverse(node));
1528
+ else __traverse(child);
1529
+ }
1530
+ }
1531
+
1532
+ __traverse(this);
1533
+ }
1534
+
1535
+ /**
1536
+ * 迭代所有子节点
1537
+ * @description 严格迭代所有子节点,排除属性;多函数特化版本,不做额外检查
1538
+ */
1539
+ *traverseStrictChildrenDoMultiTasks(
1540
+ tasks: Array<(_: BaseNode) => Generator<any, any, any>>,
1541
+ cleanups: Array<(_: BaseNode) => Generator<any, any, any>>): Generator<any, any, any> {
1542
+
1543
+ function __traverse(nd: BaseNode) {
1544
+ if (!(nd instanceof BaseNode)) {
1545
+ return;
1546
+ }
1547
+ tasks.forEach(task => utils.runGeneratorSync(task(nd)));
1548
+
1549
+ const props = getConceptPropertyMap(nd?.concept)?.keys();
1550
+ if (!props) {
1551
+ cleanups.forEach(task => utils.runGeneratorSync(task(nd)));
1552
+ return;
1553
+ }
1554
+
1555
+ for (const p of props) {
1556
+ const child = nd[p as keyof BaseNode];
1557
+ if (!child) {
1558
+ continue;
1559
+ } else if (Array.isArray(child)) {
1560
+ child?.forEach?.((node: types.SyntaxNode) => {
1561
+ __traverse(node);
1562
+ });
1563
+ } else {
1564
+ __traverse(child);
1565
+ }
1527
1566
  }
1567
+
1568
+ cleanups.forEach(task => utils.runGeneratorSync(task(nd)));
1528
1569
  }
1529
1570
 
1530
- traverse(this);
1571
+ __traverse(this);
1531
1572
  }
1532
1573
 
1574
+
1533
1575
  /**
1534
1576
  * 获取当前节点在nasl标注节点上的节点
1535
1577
  */
@@ -42,6 +42,7 @@ import * as asserts from './utils/asserts';
42
42
 
43
43
  import Param from './Param__';
44
44
  import AuthLogic from './AuthLogic__';
45
+ import { reCollectTyInferCtx } from '../../../nasl/src/server/semanticData';
45
46
 
46
47
  /**
47
48
  * 调用接口的鉴权逻辑
@@ -352,61 +353,7 @@ export class AuthLogicForCallInterface extends AuthLogic {
352
353
  // 需要类型推导的局部变量/返回值需要调整申明顺序
353
354
  const advanceMap: Map<Return | Variable, Assignment | BatchAssignment> = new Map();
354
355
  const callFunctionAdvanceMap: Map<Return | Variable, CallFunction> = new Map();
355
- yield* self.traverseChildrenGenerator(function* traverseChildrenGenerator(el) {
356
- if (
357
- el &&
358
- // 批量赋值
359
- (asserts.isBatchAssignment(el) ||
360
- // 赋值
361
- (asserts.isAssignment(el) && el.left?.name) ||
362
- // 内置函数对集合类型的推导
363
- (asserts.isCallFunction(el) && el.derivablecollection?.name))
364
- ) {
365
- if (el?.getAncestor('SubLogic')) {
366
- return;
367
- }
368
- if (asserts.isAssignment(el)) {
369
- const advanceVar = self.variables?.find(
370
- (variable) => !variable.typeAnnotation && el.left?.name === variable.name,
371
- );
372
- if (advanceVar && !advanceMap.get(advanceVar)) {
373
- advanceMap.set(advanceVar, el);
374
- }
375
- const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
376
- if (advanceRn && !advanceMap.get(advanceRn)) {
377
- advanceMap.set(advanceRn, el);
378
- }
379
- } else if (asserts.isCallFunction(el)) {
380
- // 需要被推导的集合
381
- const expression = el.derivablecollection;
382
- // 宽泛意义上的变量(变量+出参)
383
- const advanceVar = [...(self.variables || []), ...(self.returns || [])].find((variable) => {
384
- return !variable.typeAnnotation && expression?.name === variable.name;
385
- });
386
- if (advanceVar && !callFunctionAdvanceMap.get(advanceVar)) {
387
- callFunctionAdvanceMap.set(advanceVar, el);
388
- }
389
- } else if (asserts.isBatchAssignment(el)) {
390
- yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
391
- const leftCode =
392
- leftIndex.length === 1
393
- ? yield* el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
394
- : yield* el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
395
- returnOrigin('');
396
- const advanceVar = self.variables?.find(
397
- (variable) => !variable.typeAnnotation && leftCode === variable.name,
398
- );
399
- if (advanceVar && !advanceMap.get(advanceVar)) {
400
- advanceMap.set(advanceVar, el);
401
- }
402
- const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
403
- if (advanceRn && !advanceMap.get(advanceRn)) {
404
- advanceMap.set(advanceRn, el);
405
- }
406
- });
407
- }
408
- }
409
- });
356
+ yield* reCollectTyInferCtx(advanceMap, callFunctionAdvanceMap, self);
410
357
  code += '{\n';
411
358
  // 用于虚拟节点的查找引用
412
359
  if (Array.isArray(self.virtualParams)) {
@@ -551,7 +498,7 @@ export class AuthLogicForCallInterface extends AuthLogic {
551
498
  && itemNode.typeAnnotation?.typeKind === 'anonymousStructure'
552
499
  )
553
500
  || (
554
- (asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
501
+ (asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
555
502
  && !(itemNode?.typeAnnotation)
556
503
  )
557
504
  ) {
@@ -438,7 +438,22 @@ export class BackendVariable extends BaseNode {
438
438
 
439
439
  @withSourceMap()
440
440
  toNaturalTS(state = createCompilerState()): string {
441
- return '';
441
+ let code = this.name;
442
+ if (state?.needNamespace) {
443
+ const namespace = this.getNamespace();
444
+ const prefix = ['Backend']?.includes(this?.parentNode?.concept) ? `${namespace}.` : '';
445
+ code = `${prefix}${code}`;
446
+ }
447
+ if (this?.typeAnnotation) {
448
+ code += ': ';
449
+ code += this.typeAnnotation?.toNaturalTS(shiftState(state, code));
450
+ if (this.typeAnnotation?.typeKind !== 'primitive' && this.defaultValue) {
451
+ if (this.isEnum()) {
452
+ code += `= ${this.typeAnnotation?.typeKey}['${this.defaultValue}']`;
453
+ }
454
+ }
455
+ }
456
+ return code;
442
457
  }
443
458
  //================================================================================
444
459
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
@@ -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,19 +1185,24 @@ 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
- code += (this as any)[this.name].toNaturalTS(
1205
+ code += (this as any)?.[this.name]?.toNaturalTS(
1201
1206
  shiftState(state, code, { tabSize: state.tabSize + 1, inline: true }),
1202
1207
  );
1203
1208
  } else if (this.name === 'rules') {
@@ -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('');
@@ -570,7 +570,7 @@ export class BindDirective extends BaseNode {
570
570
 
571
571
  @withSourceMap()
572
572
  toNaturalTS(state = createCompilerState()): string {
573
- let code = `${this.name}: `;
573
+ let code = `_${this.name}: `;
574
574
 
575
575
  code += this.expression?.toNaturalTS(shiftState(state, code, { tabSize: state.tabSize, inline: true }));
576
576
 
@@ -471,7 +471,7 @@ export class BindStyle extends BaseNode {
471
471
 
472
472
  @withSourceMap()
473
473
  toNaturalTS(state = createCompilerState()): string {
474
- let code = `${this.name}: `;
474
+ let code = `_${this.name}: `;
475
475
 
476
476
  code += this.expression?.toNaturalTS(shiftState(state, code, { tabSize: state.tabSize, inline: true }));
477
477
 
@@ -46,6 +46,7 @@ import Variable from './Variable__';
46
46
  import BindEvent from './BindEvent__';
47
47
  import BusinessLogic from './BusinessLogic__';
48
48
  import ViewElement from './ViewElement__';
49
+ import { reCollectTyInferCtx } from '../../../nasl/src/server/semanticData';
49
50
 
50
51
  /**
51
52
  * 业务组件
@@ -1999,53 +2000,7 @@ export class BusinessComponent extends BaseNode {
1999
2000
 
2000
2001
  const advanceMap: Map<Variable, Assignment | BatchAssignment> = new Map();
2001
2002
  const callFunctionAdvanceMap: Map<Variable, CallFunction> = new Map();
2002
- yield* self.traverseChildrenGenerator(function* traverseChildrenGenerator(el) {
2003
- if (
2004
- el &&
2005
- // 批量赋值
2006
- (asserts.isBatchAssignment(el) ||
2007
- // 赋值
2008
- (asserts.isAssignment(el) && el.left?.name) ||
2009
- // 内置函数对集合类型的推导
2010
- (asserts.isCallFunction(el) && el.derivablecollection?.name))
2011
- ) {
2012
- if (el?.getAncestor('SubLogic')) {
2013
- return;
2014
- }
2015
- if (asserts.isAssignment(el)) {
2016
- const advanceVar = self.variables?.find(
2017
- (variable) => !variable.typeAnnotation && el.left?.name === variable.name,
2018
- );
2019
- if (advanceVar && !advanceMap.get(advanceVar)) {
2020
- advanceMap.set(advanceVar, el);
2021
- }
2022
- } else if (asserts.isCallFunction(el)) {
2023
- // 需要被推导的集合
2024
- const expression = el.derivablecollection;
2025
- const advanceVar = self.variables?.find((variable) => {
2026
- return !variable.typeAnnotation && expression?.name === variable.name;
2027
- });
2028
- if (advanceVar && !callFunctionAdvanceMap.get(advanceVar)) {
2029
- callFunctionAdvanceMap.set(advanceVar, el);
2030
- }
2031
- } else if (asserts.isBatchAssignment(el)) {
2032
- yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
2033
- const leftCode =
2034
- leftIndex.length === 1
2035
- ? yield* el.left?.expression?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2036
- returnOrigin('')
2037
- : yield* el.left?.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2038
- returnOrigin('');
2039
- const advanceVar = self.variables?.find(
2040
- (variable) => !variable.typeAnnotation && leftCode === variable.name,
2041
- );
2042
- if (advanceVar && !advanceMap.get(advanceVar)) {
2043
- advanceMap.set(advanceVar, el);
2044
- }
2045
- });
2046
- }
2047
- }
2048
- });
2003
+ yield* reCollectTyInferCtx(advanceMap, callFunctionAdvanceMap, self);
2049
2004
 
2050
2005
  // 用来储存默认值翻译结构是__IDENTIFIER__或者__IDENTIFIER__()的节点
2051
2006
  const IDENTIFIERMAP = new Set<Variable>();
@@ -2155,7 +2110,7 @@ export class BusinessComponent extends BaseNode {
2155
2110
  && itemNode.typeAnnotation?.typeKind === 'anonymousStructure'
2156
2111
  )
2157
2112
  || (
2158
- (asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
2113
+ (asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
2159
2114
  && !(itemNode?.typeAnnotation)
2160
2115
  )
2161
2116
  ) {
@@ -2523,11 +2478,11 @@ export class BusinessComponent extends BaseNode {
2523
2478
  @withSourceMap()
2524
2479
  toTextualNASL(state = createCompilerState()): string {
2525
2480
  let code = '';
2526
-
2481
+
2527
2482
  code += createDecoratorCode(state, this, ['title', 'description']);
2528
2483
 
2529
2484
  code += `viewComponent ${this.name}`;
2530
-
2485
+
2531
2486
  code += `(\n`;
2532
2487
  this.params.forEach((param, index) => {
2533
2488
  code += param.toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1 }));
@@ -2551,7 +2506,7 @@ export class BusinessComponent extends BaseNode {
2551
2506
  code += '\n';
2552
2507
  });
2553
2508
  if (this.logics.length) code += '\n';
2554
-
2509
+
2555
2510
  code += this.elements[0].toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1 }));
2556
2511
 
2557
2512
  code += `\n${indent(state.tabSize)}}`;