@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
@@ -13,6 +13,8 @@ import {
13
13
  getConnectors,
14
14
  getDependencies,
15
15
  getFrontendVariables,
16
+ getServerVariables,
17
+ getVariablesCode,
16
18
  getFrontendViews,
17
19
  getCurrentNodeContext,
18
20
  getCurrentNodeContextForUI,
@@ -26,6 +28,7 @@ import {
26
28
  getConnectorsCode,
27
29
  getDependenciesCode,
28
30
  getFrontendViewsCode,
31
+ getCurrentComponentDeclaration,
29
32
  wrapTSBlock,
30
33
  } from './getContext';
31
34
  import { createCompilerState } from '../translator';
@@ -57,20 +60,35 @@ export function genNaturalTSContextJSONForLogic(
57
60
  moduleInterfaces: any;
58
61
  connectors: any;
59
62
  dependencies: any;
60
- }
63
+ basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
64
+ extensionMaterials: 'pc' | 'h5' | {
65
+ name: string;
66
+ title: string;
67
+ description: string;
68
+ tsDescription: string;
69
+ }[];
70
+ },
71
+ restParams?: any
61
72
  ) {
62
73
  const frontend = currentNode?.getAncestor('Frontend') as Frontend;
63
74
  const logicType = currentNode?.parentNode?.concept === 'App' ? 'global_logic' : 'view_logic';
64
- const state = createCompilerState('', { descriptionComment: true });
75
+ const state = createCompilerState('', { descriptionComment: true, typeMap: restParams?.typeMap });
65
76
 
66
77
  const { naslCore } = getNaslCore(logicType);
67
78
  const { naslUtil } = getNaslUtil();
68
79
  const { naslUI } = getNaslUIOld();
80
+ let components = [];
81
+ if (logicType === 'view_logic' && material?.basicMaterials && material?.extensionMaterials) {
82
+ components = getNaslUI(app, frontend.type, {
83
+ basicMaterials: material?.basicMaterials,
84
+ extensionMaterials: material?.extensionMaterials,
85
+ }).naslUI;
86
+ }
69
87
  const { naslOql } = getNaslOQL();
70
88
  const { enums } = getEnums(app, state);
71
89
  const { entities } = getEntities(app, state);
72
90
  const { structures } = getStructures(app, state);
73
- const { appLogics } = getLogics(app, currentNode);
91
+ const { appLogics } = getLogics(app, currentNode, state);
74
92
  const { interfaceDependencies } = getModuleInterfaces(
75
93
  material?.moduleInterfaces || app?.interfaceDependencies,
76
94
  state
@@ -89,17 +107,21 @@ export function genNaturalTSContextJSONForLogic(
89
107
  logicType,
90
108
  frontend?.type
91
109
  );
92
- const { frontendVar, frontendVariables } = getFrontendVariables(
110
+ const { frontendVariables } = getFrontendVariables(
93
111
  currentNode?.getAncestor('Frontend') as Frontend,
94
112
  state
95
113
  );
96
- const { views } = getFrontendViews(frontend, state, currentNode, false);
97
- const { currentLogic } = getCurrentNodeContext(currentNode, focusedNodePath, experimental);
98
114
 
115
+ const { backendVariables } = getServerVariables(app, state);
116
+
117
+ const { views } = getFrontendViews(frontend, state, currentNode, false);
118
+ const { currentLogic } = getCurrentNodeContext(currentNode, focusedNodePath, experimental, restParams?.typeMap);
119
+ const { componentDeclaration } = getCurrentComponentDeclaration(currentNode, components);
99
120
  return {
100
121
  naslCore,
101
122
  naslUtil,
102
123
  naslUI,
124
+ components,
103
125
  naslOql,
104
126
  enums,
105
127
  entities,
@@ -108,11 +130,12 @@ export function genNaturalTSContextJSONForLogic(
108
130
  interfaceDependencies,
109
131
  connections,
110
132
  dependencies,
111
- frontendVar, // @deprecated
112
133
  frontendVariables,
134
+ backendVariables,
113
135
  views,
114
136
  currentLogic,
115
137
  logicType,
138
+ componentDeclaration
116
139
  };
117
140
  }
118
141
 
@@ -142,16 +165,18 @@ export const genNaturalTSContextFromJSONForLogic = (
142
165
  connections,
143
166
  dependencies,
144
167
  frontendVariables,
168
+ backendVariables,
145
169
  views,
146
170
  currentLogic,
147
171
  logicType,
172
+ componentDeclaration
148
173
  } = tsContextJSON;
149
174
 
150
175
  let code = '';
151
- code += '### [1] 标准库\n';
176
+ code += '### [1]标准库与类型定义\n';
152
177
  code += wrapTSBlock(naslCore);
153
178
 
154
- code += '\n### [2] nasl.util\n';
179
+ code += '\n### [2]平台内置函数库\n';
155
180
  code += wrapTSBlock(naslUtil);
156
181
 
157
182
  if (naslUI && logicType === 'view_logic') {
@@ -161,10 +186,14 @@ export const genNaturalTSContextFromJSONForLogic = (
161
186
  } else {
162
187
  code += getNaslUICode(naslUI, codeType, requiredIndexes);
163
188
  }
189
+ if (componentDeclaration) {
190
+ code += '\n#### [3-1] 组件声明\n';
191
+ code += wrapTSBlock(`declare namespace nasl.ui {\n${componentDeclaration}}`);
192
+ }
164
193
  }
165
194
 
166
195
  if (naslOql && logicType === 'global_logic') {
167
- code += '\n### [4] nasl.oql\n';
196
+ code += '\n### [4]数据查询定义\n';
168
197
  code += wrapTSBlock(naslOql);
169
198
  }
170
199
 
@@ -205,15 +234,20 @@ export const genNaturalTSContextFromJSONForLogic = (
205
234
 
206
235
  if (logicType === 'view_logic') {
207
236
  code += '\n### [10] 页面上下文\n';
208
- if (frontendVariables) {
237
+ if (frontendVariables?.data?.length) {
209
238
  code += '\n#### [10-0] 前端全局变量\n';
210
- code += frontendVariables;
239
+ code += getVariablesCode(frontendVariables);
211
240
  }
212
241
 
213
242
  if (views?.data?.length) {
214
243
  code += '\n#### [10-1] 前端页面列表\n';
215
244
  code += getFrontendViewsCode(views);
216
245
  }
246
+ } else {
247
+ code += '\n### [10] 全局变量\n';
248
+ if (backendVariables?.data?.length) {
249
+ code += getVariablesCode(backendVariables);
250
+ }
217
251
  }
218
252
 
219
253
  code += '\n### 当前逻辑上下文\n';
@@ -232,9 +266,17 @@ export function genNaturalTSContextForLogic(
232
266
  moduleInterfaces: any;
233
267
  connectors: any;
234
268
  dependencies: any;
269
+ basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
270
+ extensionMaterials: 'pc' | 'h5' | {
271
+ name: string;
272
+ title: string;
273
+ description: string;
274
+ tsDescription: string;
275
+ }[];
235
276
  },
236
277
  restParams?: {
237
- codeType?: 'detail' | 'short';
278
+ codeType: 'detail' | 'short';
279
+ typeMap?: any;
238
280
  }
239
281
  ) {
240
282
  const tsContextJSON = genNaturalTSContextJSONForLogic(
@@ -242,11 +284,12 @@ export function genNaturalTSContextForLogic(
242
284
  currentNode,
243
285
  focusedNodePath,
244
286
  experimental,
245
- material
287
+ material,
288
+ restParams
246
289
  );
247
290
  const code = genNaturalTSContextFromJSONForLogic(
248
291
  tsContextJSON,
249
- restParams.codeType,
292
+ restParams?.codeType || 'short',
250
293
  requiredIndexes
251
294
  );
252
295
  return code;
@@ -262,8 +305,8 @@ export function genNaturalTSContextJSONForUI(
262
305
  app: App,
263
306
  currentNode: BaseNode,
264
307
  material?: {
265
- basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string };
266
- extensionMaterials: {
308
+ basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
309
+ extensionMaterials: 'pc' | 'h5' | {
267
310
  name: string;
268
311
  title: string;
269
312
  description: string;
@@ -272,21 +315,23 @@ export function genNaturalTSContextJSONForUI(
272
315
  moduleInterfaces: any;
273
316
  connectors: any;
274
317
  dependencies: any;
275
- }
318
+ },
319
+ restParams?: any
276
320
  ) {
277
321
  const frontend = currentNode.getAncestor('Frontend') as Frontend;
278
- const state = createCompilerState();
322
+ const state = createCompilerState('', { descriptionComment: true, needNamespace: true, typeMap: restParams?.typeMap });
279
323
 
280
324
  const { naslCore } = getNaslCore('view_logic');
281
325
  const { naslUtil } = getNaslUtil();
282
- const { naslUI } = getNaslUI(app, frontend.type, {
326
+ const { naslUI } = getNaslUIOld();
327
+ const components = getNaslUI(app, frontend.type, {
283
328
  basicMaterials: material?.basicMaterials,
284
329
  extensionMaterials: material?.extensionMaterials,
285
- });
330
+ }).naslUI;
286
331
  const { enums } = getEnums(app, state);
287
332
  const { entities } = getEntities(app, state);
288
333
  const { structures } = getStructures(app, state);
289
- const { appLogics } = getLogics(app, currentNode);
334
+ const { appLogics } = getLogics(app, currentNode, state);
290
335
  const { interfaceDependencies } = getModuleInterfaces(
291
336
  material?.moduleInterfaces || app?.interfaceDependencies,
292
337
  state
@@ -299,12 +344,15 @@ export function genNaturalTSContextJSONForUI(
299
344
  );
300
345
  const { frontendVariables } = getFrontendVariables(frontend, state);
301
346
  const { views } = getFrontendViews(frontend, state, currentNode, false);
302
- const { currentLogic } = getCurrentNodeContextForUI(currentNode);
347
+ const { currentLogic } = getCurrentNodeContextForUI(currentNode, restParams?.typeMap);
348
+ const { componentDeclaration } = getCurrentComponentDeclaration(currentNode, components);
303
349
 
304
350
  return {
305
351
  naslCore,
306
352
  naslUtil,
307
353
  naslUI,
354
+ components,
355
+ componentDeclaration,
308
356
  enums,
309
357
  entities,
310
358
  structures,
@@ -333,7 +381,8 @@ export const genNaturalTSContextFromJSONForUI = (
333
381
  const {
334
382
  naslCore,
335
383
  naslUtil,
336
- naslUI,
384
+ components,
385
+ componentDeclaration,
337
386
  enums,
338
387
  entities,
339
388
  structures,
@@ -346,18 +395,18 @@ export const genNaturalTSContextFromJSONForUI = (
346
395
  } = tsContextJSON;
347
396
 
348
397
  let code = '';
349
- code += '### [1] 标准库\n';
398
+ code += '### [1] 标准库与类型定义\n';
350
399
  code += wrapTSBlock(naslCore);
351
400
 
352
- code += '\n### [2] nasl.util\n';
401
+ code += '\n### [2] 平台内置函数库\n';
353
402
  code += wrapTSBlock(naslUtil);
354
403
 
355
- if (naslUI) {
404
+ if (components) {
356
405
  code += '\n### [3] nasl.ui\n';
357
- if (typeof naslUI === 'string') {
358
- code += wrapTSBlock(naslUI);
359
- } else {
360
- code += getNaslUICode(naslUI, codeType, requiredIndexes);
406
+ code += getNaslUICode(components, codeType, requiredIndexes);
407
+ if (componentDeclaration) {
408
+ code += '\n#### [3-1] 组件声明\n';
409
+ code += wrapTSBlock(`declare namespace nasl.ui {\n${componentDeclaration}\n}`);
361
410
  }
362
411
  }
363
412
 
@@ -393,11 +442,10 @@ export const genNaturalTSContextFromJSONForUI = (
393
442
  }
394
443
 
395
444
  code += '\n### [10] 页面上下文\n';
396
- if (frontendVariables) {
445
+ if (frontendVariables?.data?.length) {
397
446
  code += '\n#### [10-0] 前端全局变量\n';
398
- code += frontendVariables;
447
+ code += getVariablesCode(frontendVariables);
399
448
  }
400
-
401
449
  if (views?.data?.length) {
402
450
  code += '\n#### [10-1] 前端页面列表\n';
403
451
  code += getFrontendViewsCode(views);
@@ -416,8 +464,8 @@ export function genNaturalTSContextForUI(
416
464
  focusedNodePath?: string,
417
465
  requiredIndexes?: string[],
418
466
  material?: {
419
- basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string };
420
- extensionMaterials: {
467
+ basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
468
+ extensionMaterials: 'pc' | 'h5' | {
421
469
  name: string;
422
470
  title: string;
423
471
  description: string;
@@ -428,13 +476,14 @@ export function genNaturalTSContextForUI(
428
476
  dependencies: any;
429
477
  },
430
478
  restParams?: {
431
- codeType?: 'detail' | 'short';
479
+ codeType: 'detail' | 'short';
480
+ typeMap?: any;
432
481
  }
433
482
  ) {
434
- const tsContextJSON = genNaturalTSContextJSONForUI(app, currentNode, material);
483
+ const tsContextJSON = genNaturalTSContextJSONForUI(app, currentNode, material, restParams);
435
484
  const code = genNaturalTSContextFromJSONForUI(
436
485
  tsContextJSON,
437
- restParams.codeType,
486
+ restParams?.codeType || 'short',
438
487
  requiredIndexes
439
488
  );
440
489
  return code;
@@ -50,7 +50,10 @@ export function handleMaterial({ json, tsDeclaration }: { json: Array<{ name: st
50
50
  snippets.forEach((code) => {
51
51
  const cap = code.match(/class ([a-zA-Z]+).+?extends ViewComponent/);
52
52
  if (cap) {
53
- snippetMap[cap[1]] = `declare namespace nasl.ui${code}`;
53
+ const newCode = code
54
+ .replace(/nasl\.core\./g, "")
55
+ .replace(/Integer/g, "Long");
56
+ snippetMap[cap[1]] = `declare namespace nasl.ui${newCode}`;
54
57
  }
55
58
  });
56
59
  json.forEach((item) => {
@@ -79,12 +82,12 @@ export function getPreDeclaration() {
79
82
  /// #if process.env.BUILD_TARGET === 'node'
80
83
  if (globalThis.process) { // For TS build
81
84
  const fs = require('fs');
82
- code = fs.readFileSync(require.resolve(`../../../sandbox-natural/stdlib/nasl.ui.pre.d.ts`), 'utf8');
85
+ code = fs.readFileSync(require.resolve(`../../../sandbox-natural/stdlib/nasl.ui.d.ts`), 'utf8');
83
86
  }
84
87
  /// #endif
85
88
  /// #if process.env.BUILD_TARGET !== 'node'
86
89
  if (globalThis.window) { // For TS build
87
- code = require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.ui.pre.d.ts').default;
90
+ code = require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.ui.d.ts').default;
88
91
  }
89
92
  /// #endif
90
93
  return code;
@@ -1,3 +1,4 @@
1
+ import * as utils from '../../utils';
1
2
  import { App, View, Logic, BaseNode, Frontend, Namespace, Module, TypeAnnotation, Structure, Connection, Connector } from '../../concepts';
2
3
  import { shiftState, createCompilerState, TranslatorState, indent } from '../../translator';
3
4
  import { getPreDeclaration, getUILib, handleMaterial, getExtensionsMaterial } from './getUILib';
@@ -86,7 +87,7 @@ export function getLogicWithStructuresCode(logic: Logic, type: string, desc: { d
86
87
 
87
88
  newRelationStructures?.forEach((reference: { typeNamespace: string; typeName: string; }) => {
88
89
  const { typeName } = reference || {};
89
- const state = createCompilerState();
90
+ const state = createCompilerState('', { descriptionComment: true });
90
91
  const tabSize = namespace ? shiftState(state, code, { tabSize: 1 }) : undefined;
91
92
  structures?.filter((structure: any) => structure?.name === typeName)
92
93
  ?.forEach((structure: any) => {
@@ -96,15 +97,15 @@ export function getLogicWithStructuresCode(logic: Logic, type: string, desc: { d
96
97
  if (namespace && newRelationStructures?.length) {
97
98
  code += `}\n`;
98
99
  }
99
- const { description, codeStr } = desc || {};
100
- if (description) code += `// ${description}\n`;
100
+ const { codeStr } = desc || {};
101
+ // if (description) code += `// ${description}\n`;
101
102
  if (codeStr) code += `${codeStr}\n`;
102
103
  code = wrapTSBlock(code);
103
104
  return code;
104
105
  }
105
106
 
106
107
  export function getNaslCore(logicType: string) {
107
- let naslCore = `${getNASLStdlibMap('nasl.core.ts')}\n`;
108
+ let naslCore = `${getNASLStdlibMap('nasl.core.d.ts')}\n`;
108
109
  if (logicType === 'global_logic')
109
110
  naslCore += `// 分页组件函数,用于分页
110
111
  declare function PAGINATE<T>(list: List<T>, page: Integer, size: Integer): { list: List<T>, total: Integer; };
@@ -114,7 +115,7 @@ declare function PAGINATE<T>(list: List<T>, page: Integer, size: Integer): { lis
114
115
  }
115
116
 
116
117
  export function getNaslUtil() {
117
- const naslUtil = `${getNASLStdlibMap('nasl.util.ts')}\n`;
118
+ const naslUtil = `${getNASLStdlibMap('nasl.util.d.ts')}\n`;
118
119
  const code = wrapTSBlock(naslUtil);
119
120
  return { code, naslUtil };
120
121
  }
@@ -125,7 +126,7 @@ export const getNaslUI = (
125
126
  material:
126
127
  {
127
128
  basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
128
- extensionMaterials: {
129
+ extensionMaterials: 'pc' | 'h5' | {
129
130
  name: string;
130
131
  title: string;
131
132
  description: string;
@@ -170,19 +171,20 @@ export const getNaslUICode = (naslUI: any, codeType: 'detail' | 'short', require
170
171
  */
171
172
  ${item.tsDeclaration}`).join('\n')}`);
172
173
  } else {
174
+ code += wrapTSBlock(preDeclaration);
173
175
  code += uiLib.map((item: any, index: number) => `[3-${index}] ${item.name} | ${item.title} | ${item.description}`).join('\n');
174
176
  }
175
177
  return code;
176
178
  };
177
179
 
178
180
  export const getNaslUIOld = () => {
179
- const naslUI = `${getNASLStdlibMap('nasl.ui.ts')}\n`;
181
+ const naslUI = `${getNASLStdlibMap('nasl.ui.d.ts')}\n`;
180
182
  const code = wrapTSBlock(naslUI);
181
183
  return { code, naslUI };
182
184
  };
183
185
 
184
186
  export function getNaslOQL() {
185
- const naslOql = `${getNASLStdlibMap('nasl.oql.ts')}\n`;
187
+ const naslOql = `${getNASLStdlibMap('nasl.oql.d.ts')}\n`;
186
188
  const code = wrapTSBlock(naslOql);
187
189
  return { code, naslOql };
188
190
  }
@@ -215,7 +217,7 @@ export function getEntities(app: App, state: TranslatorState) {
215
217
  const data = [] as Snippet[];
216
218
  const namespace = `app.dataSources.${dataSource?.name}.entities`;
217
219
  dataSource.entities
218
- .filter((entity) => !entity.name.startsWith('LCAP') || entity.name === 'LCAPUser')
220
+ // .filter((entity) => !entity.name.startsWith('LCAP') || entity.name === 'LCAPUser')
219
221
  .forEach((entity) => {
220
222
  const entityName = `app.dataSources.${dataSource?.name}.entities.${entity?.name}`;
221
223
  const tempCode = `${entity?.toNaturalTS({ ...state, needNamespace: true }, entityName)}`;
@@ -231,7 +233,7 @@ export const getEntitiesCode = (entities: any) => {
231
233
  entities?.forEach((entity: any) => {
232
234
  code += `declare namespace ${entity?.namespace} {\n`;
233
235
  entity?.data?.forEach((item: any) => {
234
- code += item?.description ? `/* ${item.description} */ \n` : '';
236
+ // code += item?.description ? `/* ${item.description} */ \n` : '';
235
237
  code += `${item.code}\n`;
236
238
  });
237
239
  code += `}\n`;
@@ -244,7 +246,7 @@ export function getStructures(app: App, state: TranslatorState) {
244
246
  const data = [] as Snippet[];
245
247
  const namespace = `app.structures`;
246
248
  app.structures
247
- .filter((entity) => !entity.name.startsWith('LCAP'))
249
+ // .filter((entity) => !entity.name.startsWith('LCAP'))
248
250
  .forEach((structure) => {
249
251
  const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}`;
250
252
  data.push({ description: structure?.description || structure?.name, code: tempCode });
@@ -256,7 +258,7 @@ export const getStructuresCode = (structures: any) => {
256
258
  let code = '';
257
259
  code += `declare namespace ${structures?.namespace} {\n`;
258
260
  structures?.data?.forEach((item: any) => {
259
- code += item?.description ? `/* ${item.description} */ \n` : '';
261
+ // code += item?.description ? `/* ${item.description} */ \n` : '';
260
262
  code += `${item.code}\n`;
261
263
  });
262
264
  code += `}\n`;
@@ -265,14 +267,14 @@ export const getStructuresCode = (structures: any) => {
265
267
  };
266
268
 
267
269
 
268
- export function getLogics(app: App, currentNode: BaseNode) {
270
+ export function getLogics(app: App, currentNode: BaseNode, state: TranslatorState) {
269
271
  const data = [] as Snippet[];
270
272
  const namespace = `app.logics`;
271
273
  app?.logics
272
274
  ?.filter((logic) => logic !== currentNode && !logic.name.startsWith('LCAP'))
273
275
  ?.forEach((logic) => {
274
276
  const rename = logic?.calleewholeKey;
275
- const tempCode = `${logic?.toNaturalTS({ needNamespace: true, rename, declaration: true })}`;
277
+ const tempCode = `${logic?.toNaturalTS({ ...state, needNamespace: true, rename, declaration: true })}`;
276
278
  const description = logic?.description || '';
277
279
 
278
280
  data.push({ description, code: tempCode });
@@ -287,7 +289,8 @@ export const getLogicsCode = (appLogics: any, codeType: 'detail' | 'short', requ
287
289
  const logicIndex = `6-${index}`;
288
290
  if (requiredIndexes?.length && !requiredIndexes?.includes(logicIndex)) return;
289
291
  const tempCode = codeType === 'short' ? item.code.replace(`${appLogics.namespace}.`, '') : item.code;
290
- code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
292
+ code += `[${logicIndex}] \`${tempCode}\`\n`;
293
+ // code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
291
294
  });
292
295
  return code;
293
296
  };
@@ -338,8 +341,8 @@ export const getModuleInterfacesCode = (interfaceDependencies: any, codeType: 'd
338
341
  if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex)) return;
339
342
  if (codeType === 'short') {
340
343
  const tempCode = item.code.replace(`${interfaceDependency?.logics.namespace}.`, '');
341
- // code += `[${interfaceIndex}] \`${tempCode}\`\n`;
342
- code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
344
+ code += `[${interfaceIndex}] \`${tempCode}\`\n`;
345
+ // code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
343
346
  } else {
344
347
  code += item.codeWithDetail;
345
348
  }
@@ -542,13 +545,37 @@ export const getDependenciesCode = (dependencies: any, codeType: 'detail' | 'sho
542
545
 
543
546
  export function getFrontendVariables(frontend: Frontend, state: TranslatorState) {
544
547
  let code = '';
548
+ const data = [] as Snippet[];
549
+ const namespace = frontend?.variables?.[0]?.getNamespace() || '';
545
550
  frontend?.variables?.forEach((variable) => {
546
- const tempCode = `let ${variable?.toNaturalTS(shiftState(state, code, { inline: true }))};\n`;
551
+ const tempCode = `let ${variable?.toNaturalTS(shiftState(state, code, { inline: true, needNamespace: true, }))};\n`;
552
+ data.push({ description: variable?.description || '', code: tempCode });
553
+ code += tempCode;
554
+ });
555
+ return { namespace, frontendVariables: { namespace, data } };
556
+ }
557
+
558
+ export function getServerVariables(app: App, state: TranslatorState) {
559
+ let code = '';
560
+ const data = [] as Snippet[];
561
+ const namespace = 'app.backend.variables';
562
+ app.backend?.variables?.forEach((variable) => {
563
+ const tempCode = `let ${variable?.toNaturalTS(shiftState(state, code, { inline: true, needNamespace: true, }))};\n`;
564
+ data.push({ description: variable?.description || '', code: tempCode });
547
565
  code += tempCode;
548
566
  });
549
- return { code: wrapTSBlock(code), frontendVar: code, frontendVariables: code };
567
+ return { namespace, backendVariables: { namespace, data } };
550
568
  }
551
569
 
570
+ export const getVariablesCode = (variables: any) => {
571
+ let code = '';
572
+ variables?.data?.forEach((item: any) => {
573
+ code += item.description ? `/* ${item.description} */ \n` : '';
574
+ code += item.code;
575
+ });
576
+ return wrapTSBlock(code);
577
+ };
578
+
552
579
  export function getChildrenViews(view: View, currentNode: BaseNode, convertChildren: boolean, prefix: string) {
553
580
  const data = [] as Snippet[];
554
581
  if (view?.children?.length > 0) {
@@ -606,7 +633,7 @@ export const getFrontendViewsCode = (views: any) => {
606
633
  return wrapTSBlock(code);
607
634
  };
608
635
 
609
- export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: string, experimental?: boolean) {
636
+ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: string, experimental?: boolean, typeMap?: any) {
610
637
  let code = '';
611
638
  let view: View;
612
639
  if (currentNode?.concept === 'View') {
@@ -631,14 +658,16 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
631
658
  createCompilerState('', {
632
659
  focusedNodePath,
633
660
  needNamespace: true,
661
+ typeMap,
634
662
  }),
635
663
  function (state) {
636
664
  let code = '';
637
665
  code += `\n${indent(state.tabSize)}`;
638
-
666
+
639
667
  if (experimental) {
640
668
  code += this.elements[0].toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1 }));
641
669
  } else {
670
+ code += `${indent(state.tabSize + 1)}`;
642
671
  code += `const $refs = {\n`;
643
672
  // 生成所有的name和类型定义
644
673
  this.elements.forEach((element) => {
@@ -653,17 +682,36 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
653
682
  // 逻辑
654
683
  if (currentNode?.concept === 'Logic') {
655
684
  code += '\n';
685
+ this.bindEvents.forEach((bindEvent) => {
686
+ bindEvent.logics.forEach((logic) => {
687
+ if (logic === currentNode) return;
688
+ const logicCode = logic.toNaturalTS(
689
+ shiftState(state, code, {
690
+ tabSize: state.tabSize + 1,
691
+ // declaration: true,
692
+ autoPrefixName: true,
693
+ })
694
+ );
695
+ code += logicCode.replace('function ', 'private function ');
696
+ code += '\n';
697
+ });
698
+ if (bindEvent.logics.length) code += '\n';
699
+ });
700
+
656
701
  this.logics.forEach((logic) => {
657
702
  if (logic === currentNode) return;
658
- code += logic.toNaturalTS(
703
+ const logicCode = logic.toNaturalTS(
659
704
  shiftState(state, code, {
660
705
  tabSize: state.tabSize + 1,
661
706
  declaration: true,
662
707
  autoPrefixName: true,
663
708
  })
664
709
  );
710
+ code += logicCode.replace('declare function', 'function');
665
711
  code += '\n';
666
712
  });
713
+ if (this.logics.length) code += '\n';
714
+
667
715
  // 包含了事件逻辑的处理
668
716
  code += `${indent(state.tabSize + 1)}/* 当前逻辑 */\n`;
669
717
  code += (currentNode as Logic).toNaturalTS(
@@ -700,13 +748,14 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
700
748
  needNamespace: true,
701
749
  declaration: logic !== currentNode,
702
750
  autoPrefixName: true,
751
+ typeMap
703
752
  })
704
753
  );
705
754
  }
706
755
  return { code: wrapTSBlock(code), currentLogic: code };
707
756
  }
708
757
 
709
- export function getCurrentNodeContextForUI(currentNode: BaseNode) {
758
+ export function getCurrentNodeContextForUI(currentNode: BaseNode, typeMap?: any) {
710
759
  let code = '';
711
760
  let view: View;
712
761
  if (currentNode?.concept === 'View') {
@@ -725,9 +774,62 @@ export function getCurrentNodeContextForUI(currentNode: BaseNode) {
725
774
  code += view?.toNaturalTS(
726
775
  createCompilerState('', {
727
776
  needNamespace: true,
777
+ typeMap,
728
778
  })
729
779
  );
730
780
  }
731
781
 
732
782
  return { code: wrapTSBlock(code), currentLogic: code };
733
783
  }
784
+
785
+
786
+ const calcComponent = (activeDesignerNode: any) => {
787
+ const view = activeDesignerNode?.concept === 'View' ? activeDesignerNode?.elements?.[0] : (activeDesignerNode.getAncestor('View') as any)?.elements?.[0];
788
+ const componentSet = new Set();
789
+ if (view) {
790
+ utils.traverse(({ node }: { node: any; }) => {
791
+ if (node.concept === 'ViewElement') {
792
+ const name = utils.kebab2Camel(node.tag);
793
+ componentSet.add(name);
794
+ }
795
+ }, { node: view });
796
+ }
797
+ return componentSet;
798
+ };
799
+
800
+
801
+ const extractUFormClass = (tsDeclaration: string) => {
802
+ const regex = /class\s+(\w+)(?:<[^>]+>)?\s+extends\s+(\w+)\s*\{(.*?)\}/s;
803
+ const match = tsDeclaration.match(regex);
804
+ let code = '';
805
+ if (match) {
806
+ const [, className, baseClassName, classBody] = match;
807
+ const methodRegex = /\s*(\w+)\(([^)]*)\):\s*(\w+)/g;
808
+ code = `export class ${className} extends ${baseClassName} {`;
809
+ const newClassBody = classBody.replace(/nasl\.core\./g, "")
810
+ .replace(/Integer/g, "Long");
811
+ const body = newClassBody.replace(methodRegex, (method) => {
812
+ code += `${method};`;
813
+ return '';
814
+ });
815
+ code += `\n}\n`;
816
+ if (body === classBody) {
817
+ return '';
818
+ }
819
+ }
820
+ return code;
821
+ };
822
+
823
+ export function getCurrentComponentDeclaration(activeDesignerNode: any, components: any) {
824
+ let code = '';
825
+ const componentSet = calcComponent(activeDesignerNode);
826
+ if (!componentSet.size) return { componentDeclaration: '' };
827
+ // 遍历map,找到对应的组件
828
+ const result = components.filter((component: any) => componentSet.has(component.name));
829
+ result.forEach((component: any) => {
830
+ const newTsDeclaration = component.tsDeclaration;
831
+ const uFormClass = extractUFormClass(newTsDeclaration);
832
+ code += uFormClass;
833
+ });
834
+ return { componentDeclaration: code };
835
+ }