@lcap/nasl 3.8.2-beta.8 → 3.8.3-beta.1

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 (223) hide show
  1. package/ai-engineer.config.js +617 -0
  2. package/out/common/BaseNode.js +5 -3
  3. package/out/common/BaseNode.js.map +1 -1
  4. package/out/common/ComponentAPI.d.ts +9 -0
  5. package/out/concepts/AuthLogicForCallInterface__.js +21 -6
  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 +24 -8
  16. package/out/concepts/BusinessComponent__.js.map +1 -1
  17. package/out/concepts/BusinessLogic__.js +21 -6
  18. package/out/concepts/BusinessLogic__.js.map +1 -1
  19. package/out/concepts/CallInterface__.js +2 -1
  20. package/out/concepts/CallInterface__.js.map +1 -1
  21. package/out/concepts/CallLogic__.d.ts +1 -0
  22. package/out/concepts/CallLogic__.js +32 -11
  23. package/out/concepts/CallLogic__.js.map +1 -1
  24. package/out/concepts/CallQueryComponent__.d.ts +1 -0
  25. package/out/concepts/CallQueryComponent__.js +23 -12
  26. package/out/concepts/CallQueryComponent__.js.map +1 -1
  27. package/out/concepts/Destination__.js +11 -8
  28. package/out/concepts/Destination__.js.map +1 -1
  29. package/out/concepts/EntityProperty__.js +3 -2
  30. package/out/concepts/EntityProperty__.js.map +1 -1
  31. package/out/concepts/Entity__.js +1 -1
  32. package/out/concepts/Entity__.js.map +1 -1
  33. package/out/concepts/Interface__.js +1 -1
  34. package/out/concepts/Interface__.js.map +1 -1
  35. package/out/concepts/Logic__.js +49 -17
  36. package/out/concepts/Logic__.js.map +1 -1
  37. package/out/concepts/MemberExpression__.js +19 -13
  38. package/out/concepts/MemberExpression__.js.map +1 -1
  39. package/out/concepts/OqlQueryComponent__.js +37 -12
  40. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  41. package/out/concepts/OverriddenLogic__.js +21 -6
  42. package/out/concepts/OverriddenLogic__.js.map +1 -1
  43. package/out/concepts/Param__.js +5 -4
  44. package/out/concepts/Param__.js.map +1 -1
  45. package/out/concepts/QueryOrderByExpression__.d.ts +0 -1
  46. package/out/concepts/QueryOrderByExpression__.js +0 -1
  47. package/out/concepts/QueryOrderByExpression__.js.map +1 -1
  48. package/out/concepts/Structure__.js +5 -7
  49. package/out/concepts/Structure__.js.map +1 -1
  50. package/out/concepts/Variable__.js +5 -0
  51. package/out/concepts/Variable__.js.map +1 -1
  52. package/out/concepts/ViewElement__.d.ts +1 -0
  53. package/out/concepts/ViewElement__.js +17 -7
  54. package/out/concepts/ViewElement__.js.map +1 -1
  55. package/out/concepts/View__.js +70 -14
  56. package/out/concepts/View__.js.map +1 -1
  57. package/out/concepts/basics/stdlib/nasl.processV2.js +78 -0
  58. package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
  59. package/out/concepts/basics/stdlib/nasl.ui.js +40 -40
  60. package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
  61. package/out/generator/genBundleFiles.js +1 -1
  62. package/out/generator/genBundleFiles.js.map +1 -1
  63. package/out/generator/release-body/utils.js +1 -1
  64. package/out/natural/genNaturalTS.d.ts +45 -10
  65. package/out/natural/genNaturalTS.js +57 -33
  66. package/out/natural/genNaturalTS.js.map +1 -1
  67. package/out/natural/getContext/getUILib.js +6 -3
  68. package/out/natural/getContext/getUILib.js.map +1 -1
  69. package/out/natural/getContext/index.d.ts +20 -7
  70. package/out/natural/getContext/index.js +143 -23
  71. package/out/natural/getContext/index.js.map +1 -1
  72. package/out/natural/getContext/naslStdlibMap.js +8 -8
  73. package/out/natural/getContext/naslStdlibMap.js.map +1 -1
  74. package/out/natural/tools.d.ts +16 -0
  75. package/out/natural/tools.js +110 -2
  76. package/out/natural/tools.js.map +1 -1
  77. package/out/natural/transformTS2UI.js +361 -304
  78. package/out/natural/transformTS2UI.js.map +1 -1
  79. package/out/natural/transformTSCode.d.ts +3 -5
  80. package/out/natural/transformTSCode.js +30 -1089
  81. package/out/natural/transformTSCode.js.map +1 -1
  82. package/out/natural/transforms/registerTransform.d.ts +7 -0
  83. package/out/natural/transforms/registerTransform.js +24 -0
  84. package/out/natural/transforms/registerTransform.js.map +1 -0
  85. package/out/natural/transforms/transform2LogicItem.d.ts +24 -0
  86. package/out/natural/transforms/transform2LogicItem.js +1240 -0
  87. package/out/natural/transforms/transform2LogicItem.js.map +1 -0
  88. package/out/natural/transforms/transform2TypeAnnotation.d.ts +2 -0
  89. package/out/natural/transforms/transform2TypeAnnotation.js +86 -0
  90. package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -0
  91. package/out/natural/transforms/utils.d.ts +8 -0
  92. package/out/natural/transforms/utils.js +59 -0
  93. package/out/natural/transforms/utils.js.map +1 -0
  94. package/out/server/getLogics.js +12 -12
  95. package/out/server/getLogics.js.map +1 -1
  96. package/out/server/getMemberIdentifier.js +11 -17
  97. package/out/server/getMemberIdentifier.js.map +1 -1
  98. package/out/server/naslServer.d.ts +2 -2
  99. package/out/server/naslServer.js +38 -18
  100. package/out/server/naslServer.js.map +1 -1
  101. package/out/server/translator.js +5 -0
  102. package/out/server/translator.js.map +1 -1
  103. package/out/templator/block2nasl/jsx2nasl/index.d.ts +5 -0
  104. package/out/templator/block2nasl/jsx2nasl/index.js +15 -0
  105. package/out/templator/block2nasl/jsx2nasl/index.js.map +1 -0
  106. package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.d.ts +3 -0
  107. package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js +213 -0
  108. package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js.map +1 -0
  109. package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.d.ts +14 -0
  110. package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js +201 -0
  111. package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js.map +1 -0
  112. package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.d.ts +4 -0
  113. package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js +186 -0
  114. package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js.map +1 -0
  115. package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.d.ts +28 -0
  116. package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js +336 -0
  117. package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js.map +1 -0
  118. package/out/templator/block2nasl/jsx2nasl/utils.d.ts +2 -0
  119. package/out/templator/block2nasl/jsx2nasl/utils.js +26 -0
  120. package/out/templator/block2nasl/jsx2nasl/utils.js.map +1 -0
  121. package/out/templator/block2nasl/transformBlock2Nasl.d.ts +10 -0
  122. package/out/templator/block2nasl/transformBlock2Nasl.js +122 -0
  123. package/out/templator/block2nasl/transformBlock2Nasl.js.map +1 -0
  124. package/out/templator/block2nasl/viewMergeBlock.d.ts +9 -0
  125. package/out/templator/block2nasl/viewMergeBlock.js +110 -0
  126. package/out/templator/block2nasl/viewMergeBlock.js.map +1 -0
  127. package/out/translator/types.d.ts +2 -0
  128. package/out/translator/utils.js +1 -1
  129. package/out/translator/utils.js.map +1 -1
  130. package/out/utils/index.js +0 -4
  131. package/out/utils/index.js.map +1 -1
  132. package/out/utils/language-cache/constant.d.ts +2 -1
  133. package/out/utils/language-cache/constant.js +1 -0
  134. package/out/utils/language-cache/constant.js.map +1 -1
  135. package/out/utils/language-cache/nasl.d.ts +1 -0
  136. package/out/utils/language-cache/nasl.js +9 -1
  137. package/out/utils/language-cache/nasl.js.map +1 -1
  138. package/package.json +6 -2
  139. package/sandbox/stdlib/nasl.processV2.ts +19 -0
  140. package/sandbox/stdlib/nasl.ui.ts +8 -8
  141. package/sandbox-natural/stdlib/nasl.core.d.ts +54 -0
  142. package/sandbox-natural/stdlib/nasl.oql.d.ts +22 -0
  143. package/sandbox-natural/stdlib/nasl.ui.d.ts +78 -0
  144. package/sandbox-natural/stdlib/nasl.ui.h5.d.ts +1684 -1643
  145. package/sandbox-natural/stdlib/nasl.ui.h5.json +15746 -15045
  146. package/sandbox-natural/stdlib/nasl.ui.pc.d.ts +5341 -5154
  147. package/sandbox-natural/stdlib/nasl.ui.pc.json +31176 -30681
  148. package/sandbox-natural/stdlib/{nasl.util.ts → nasl.util.d.ts} +49 -43
  149. package/src/common/BaseNode.ts +5 -3
  150. package/src/common/ComponentAPI.ts +7 -0
  151. package/src/concepts/AuthLogicForCallInterface__.ts +23 -6
  152. package/src/concepts/BackendVariable__.ts +16 -1
  153. package/src/concepts/BindAttribute__.ts +18 -13
  154. package/src/concepts/BindDirective__.ts +1 -1
  155. package/src/concepts/BindStyle__.ts +1 -1
  156. package/src/concepts/BusinessComponent__.ts +26 -8
  157. package/src/concepts/BusinessLogic__.ts +23 -6
  158. package/src/concepts/CallInterface__.ts +2 -2
  159. package/src/concepts/CallLogic__.ts +50 -24
  160. package/src/concepts/CallQueryComponent__.ts +26 -12
  161. package/src/concepts/Destination__.ts +14 -12
  162. package/src/concepts/EntityProperty__.ts +5 -5
  163. package/src/concepts/Entity__.ts +1 -1
  164. package/src/concepts/Interface__.ts +1 -1
  165. package/src/concepts/Logic__.ts +62 -33
  166. package/src/concepts/MemberExpression__.ts +20 -13
  167. package/src/concepts/OqlQueryComponent__.ts +29 -5
  168. package/src/concepts/OverriddenLogic__.ts +23 -6
  169. package/src/concepts/Param__.ts +5 -4
  170. package/src/concepts/QueryOrderByExpression__.ts +0 -1
  171. package/src/concepts/Structure__.ts +5 -7
  172. package/src/concepts/Variable__.ts +9 -5
  173. package/src/concepts/ViewElement__.ts +25 -9
  174. package/src/concepts/View__.ts +97 -37
  175. package/src/concepts/basics/stdlib/nasl.processV2.ts +79 -0
  176. package/src/concepts/basics/stdlib/nasl.ui.ts +40 -40
  177. package/src/generator/genBundleFiles.ts +1 -1
  178. package/src/generator/release-body/utils.ts +1 -1
  179. package/src/natural/genNaturalTS.ts +88 -39
  180. package/src/natural/getContext/getUILib.ts +6 -3
  181. package/src/natural/getContext/index.ts +125 -23
  182. package/src/natural/getContext/naslStdlibMap.ts +8 -8
  183. package/src/natural/tools.ts +107 -2
  184. package/src/natural/transformTS2UI.ts +205 -147
  185. package/src/natural/transformTSCode.ts +29 -1055
  186. package/src/natural/transforms/registerTransform.ts +34 -0
  187. package/src/natural/transforms/transform2LogicItem.ts +1335 -0
  188. package/src/natural/transforms/transform2TypeAnnotation.ts +77 -0
  189. package/src/natural/transforms/utils.ts +25 -0
  190. package/src/server/getLogics.ts +12 -12
  191. package/src/server/getMemberIdentifier.ts +14 -14
  192. package/src/server/naslServer.ts +39 -19
  193. package/src/server/translator.ts +5 -0
  194. package/src/templator/block2nasl/jsx2nasl/index.ts +11 -0
  195. package/src/templator/block2nasl/jsx2nasl/transform-expression2nasl.ts +238 -0
  196. package/src/templator/block2nasl/jsx2nasl/transform-func2nasl.ts +241 -0
  197. package/src/templator/block2nasl/jsx2nasl/transform-tstype2nasl.ts +213 -0
  198. package/src/templator/block2nasl/jsx2nasl/transform-tsx2nasl.ts +422 -0
  199. package/src/templator/block2nasl/jsx2nasl/utils.ts +19 -0
  200. package/src/templator/block2nasl/transformBlock2Nasl.ts +99 -0
  201. package/src/templator/block2nasl/viewMergeBlock.ts +149 -0
  202. package/src/translator/types.ts +2 -0
  203. package/src/translator/utils.ts +1 -1
  204. package/src/utils/index.ts +0 -4
  205. package/src/utils/language-cache/constant.ts +1 -0
  206. package/src/utils/language-cache/nasl.ts +6 -0
  207. package/test/concepts/member-expression/__snapshots__/toJS.spec.ts.snap +1 -1
  208. package/test/concepts/member-expression/__snapshots__/toVue.spec.ts.snap +1 -1
  209. package/test/tdd/dataQuery/QueryFieldExpression/case1/ast.json +7 -0
  210. package/test/tdd/dataQuery/QueryFieldExpression/case1/natural.ts.txt +1 -0
  211. package/test/tdd/dataQuery/QueryFieldExpression/case2/ast.json +7 -0
  212. package/test/tdd/dataQuery/QueryFieldExpression/case2/natural.ts.txt +1 -0
  213. package/test/tdd/transform/case1/ast.json +243 -0
  214. package/test/tdd/transform/case1/natural.ts.md +20 -0
  215. package/test/tdd/transform/case2/ast.json +207 -0
  216. package/test/tdd/transform/case2/natural.ts.md +12 -0
  217. package/test/tdd.test.js +10 -0
  218. package/test/tdd.transform.test.js +38 -0
  219. package/test/utils.js +40 -0
  220. package/sandbox-natural/stdlib/nasl.core.ts +0 -36
  221. package/sandbox-natural/stdlib/nasl.oql.ts +0 -14
  222. package/sandbox-natural/stdlib/nasl.ui.pre.d.ts +0 -90
  223. package/sandbox-natural/stdlib/nasl.ui.ts +0 -63
@@ -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
+ }
@@ -4,20 +4,20 @@ export const getNASLStdlibMap = (key?: string) => {
4
4
  if (globalThis.process) { // For TS build
5
5
  const fs = require('fs');
6
6
  naslStdlibMap = {
7
- 'nasl.core.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.core.ts'), 'utf8'),
8
- 'nasl.util.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.util.ts'), 'utf8'),
9
- 'nasl.ui.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.ui.ts'), 'utf8'),
10
- 'nasl.oql.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.oql.ts'), 'utf8'),
7
+ 'nasl.core.d.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.core.d.ts'), 'utf8'),
8
+ 'nasl.util.d.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.util.d.ts'), 'utf8'),
9
+ 'nasl.ui.d.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.ui.d.ts'), 'utf8'),
10
+ 'nasl.oql.d.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.oql.d.ts'), 'utf8'),
11
11
  };
12
12
  }
13
13
  /// #endif
14
14
  /// #if process.env.BUILD_TARGET !== 'node'
15
15
  if (globalThis.window) { // For TS build
16
16
  naslStdlibMap = {
17
- 'nasl.core.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.core.ts').default,
18
- 'nasl.util.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.util.ts').default,
19
- 'nasl.ui.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.ui.ts').default,
20
- 'nasl.oql.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.oql.ts').default
17
+ 'nasl.core.d.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.core.d.ts').default,
18
+ 'nasl.util.d.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.util.d.ts').default,
19
+ 'nasl.ui.d.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.ui.d.ts').default,
20
+ 'nasl.oql.d.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.oql.d.ts').default
21
21
  };
22
22
  }
23
23
  /// #endif
@@ -1,5 +1,6 @@
1
1
  import { App, BaseNode } from "src/concepts";
2
2
  import * as utils from '../utils';
3
+ import { createCompilerState } from '../translator';
3
4
 
4
5
  // 获取当前逻辑的类型
5
6
  export const getLogicType = (activeLogic: any) => {
@@ -32,7 +33,7 @@ export const getUsedModule = (json: BaseNode) => {
32
33
  useModule.push(item);
33
34
  }
34
35
  }
35
- if (node.concept === 'ViewElement') {
36
+ if (node.concept === 'ViewElement' && node?.tag) {
36
37
  const symbol = utils.kebab2Camel(node.tag);
37
38
  const item = {
38
39
  symbol,
@@ -80,7 +81,7 @@ export const getUnImportedModulesForLogic = (json: BaseNode, app: App, material:
80
81
  // 如果 连接器 不存在,则需要导入并初始化连接
81
82
  if (!connectorNode) {
82
83
  item.operator = 'importAndInit';
83
- const curDep = material?.connectors?.find((node: any) => node.name === item.symbol)
84
+ const curDep = material?.connectors?.find((node: any) => node.name === item.symbol);
84
85
  item.version = curDep?.version;
85
86
  item.provider = curDep?.provider || '资产中心';
86
87
  needImportModule.needImportConnector = true;
@@ -136,3 +137,107 @@ export const getUnImportedModulesForLogic = (json: BaseNode, app: App, material:
136
137
  return needImportModule;
137
138
  };
138
139
 
140
+
141
+
142
+ /**
143
+ * 找到当前节点所使用的当前逻辑、服务端逻辑、组件相关的推导类型
144
+ * @param app: 当前应用
145
+ * @returns 推导类型集合
146
+ */
147
+ export const deduceType = async (app: App, activeDesignerNode: any) => {
148
+ const typeMap = {} as any;
149
+ const { logics } = app;
150
+ const state = createCompilerState('', { descriptionComment: true, needNamespace: true });
151
+
152
+ logics.forEach((logic: any) => {
153
+ if (logic?.returns?.length && !logic.name.startsWith('LCAP')) {
154
+ const ret = logic.returns[0];
155
+ const typeAnnotation = ret?.typeAnnotation || ret?.__TypeAnnotation;
156
+ if (typeAnnotation)
157
+ typeMap[ret.nodePath] = typeAnnotation.toNaturalTS(state);
158
+ }
159
+ });
160
+
161
+ const params = activeDesignerNode?.params.concat(activeDesignerNode?.virtualParams || []);
162
+ if (params?.length) {
163
+ let code = '';
164
+ params?.forEach((param: any, index: number) => {
165
+ let curCode = '';
166
+ if (param.name === 'event') curCode += '';
167
+ else curCode += param.toNaturalTS(state);
168
+ if (curCode && index !== params.length - 1) curCode += ', ';
169
+ code += curCode;
170
+ });
171
+ if (code)
172
+ typeMap[activeDesignerNode.nodePath] = code;
173
+ }
174
+ const view = activeDesignerNode?.concept === 'View' ? activeDesignerNode?.elements?.[0] : (activeDesignerNode.getAncestor('View') as any)?.elements?.[0];
175
+ if (view) {
176
+ const dataSchemaMap = {} as any;
177
+ utils.traverse(({ node }: { node: any; }) => {
178
+ if (node.concept === 'ViewElement') {
179
+ const dataSchema = node.bindAttrs.find((_: any) => _.name === 'dataSchema');
180
+ if (dataSchema) dataSchemaMap[dataSchema.nodePath] = node;
181
+ }
182
+ }, { node: view });
183
+ await Promise.all(Object.entries(dataSchemaMap).map(async ([nodePath, node]) => {
184
+ const res = await app.naslServer.getDataSchemaStructureOrTypeAnnotation(node as any);
185
+ if (res) {
186
+ const dataSchemaTs = res.toNaturalTS(state);
187
+ typeMap[nodePath] = dataSchemaTs;
188
+ }
189
+ }));
190
+ }
191
+ return { typeMap };
192
+ };
193
+
194
+ /**
195
+ * 组合所有的可推导类型
196
+ * @param app: 当前应用
197
+ * @returns 推导类型集合
198
+ */
199
+ export const deduceTypeAll = async (app: App) => {
200
+ const typeMap = {} as any;
201
+ const { logics } = app;
202
+ const state = createCompilerState('', { descriptionComment: true, needNamespace: true });
203
+
204
+ logics.forEach((logic: any) => {
205
+ if (logic?.returns?.length && !logic.name.startsWith('LCAP')) {
206
+ const ret = logic.returns[0];
207
+ const typeAnnotation = ret?.typeAnnotation || ret?.__TypeAnnotation;
208
+ if (typeAnnotation)
209
+ typeMap[ret.nodePath] = typeAnnotation.toNaturalTS(state);
210
+ }
211
+ });
212
+ const dataSchemaMap = {} as any;
213
+ utils.traverse(({ node }: { node: any; }) => {
214
+ if (node?.concept === 'ViewElement') {
215
+ const dataSchema = node.bindAttrs.find((_: any) => _.name === 'dataSchema');
216
+ if (dataSchema) dataSchemaMap[dataSchema.nodePath] = node;
217
+ }
218
+ if (node?.concept === 'Logic' && node?.parentNode?.concept === 'BindEvent') {
219
+ const params = node?.params.concat(node?.virtualParams || []);
220
+ if (params?.length) {
221
+ let code = '';
222
+ params?.forEach((param: any, index: number) => {
223
+ let curCode = '';
224
+ if (param.name === 'event') curCode += '';
225
+ else curCode += param.toNaturalTS(state);
226
+ if (curCode && index !== params.length - 1) curCode += ', ';
227
+ code += curCode;
228
+ });
229
+ if (code)
230
+ typeMap[node.nodePath] = code;
231
+ }
232
+ }
233
+ }, { node: app }, { mode: 'onlyArray' });
234
+ await Promise.all(Object.entries(dataSchemaMap).map(async ([nodePath, node]) => {
235
+ const res = await app.naslServer.getDataSchemaStructureOrTypeAnnotation(node as any);
236
+ if (res) {
237
+ const dataSchemaTs = res.toNaturalTS(state);
238
+ typeMap[nodePath] = dataSchemaTs;
239
+ }
240
+ }));
241
+
242
+ return { typeMapAll: typeMap };
243
+ };