@lcap/nasl 3.8.0-beta.5 → 3.8.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/.mocharc.js +1 -0
  2. package/out/common/BaseNode.d.ts +21 -5
  3. package/out/common/BaseNode.js +94 -12
  4. package/out/common/BaseNode.js.map +1 -1
  5. package/out/concepts/AbstractInterface__.js.map +1 -1
  6. package/out/concepts/Annotation__.js +1 -1
  7. package/out/concepts/Annotation__.js.map +1 -1
  8. package/out/concepts/App__.d.ts +3 -0
  9. package/out/concepts/App__.js +985 -6
  10. package/out/concepts/App__.js.map +1 -1
  11. package/out/concepts/Argument__.js +3 -3
  12. package/out/concepts/Argument__.js.map +1 -1
  13. package/out/concepts/BatchAssignment__.d.ts +1 -1
  14. package/out/concepts/BatchAssignment__.js +2 -2
  15. package/out/concepts/BatchAssignment__.js.map +1 -1
  16. package/out/concepts/BindAttribute__.js +7 -7
  17. package/out/concepts/BindAttribute__.js.map +1 -1
  18. package/out/concepts/BindDirective__.js +3 -4
  19. package/out/concepts/BindDirective__.js.map +1 -1
  20. package/out/concepts/BindStyle__.js +1 -1
  21. package/out/concepts/BindStyle__.js.map +1 -1
  22. package/out/concepts/BusinessComponent__.d.ts +2 -0
  23. package/out/concepts/BusinessComponent__.js +48 -0
  24. package/out/concepts/BusinessComponent__.js.map +1 -1
  25. package/out/concepts/BusinessLogic__.d.ts +1 -0
  26. package/out/concepts/BusinessLogic__.js +10 -0
  27. package/out/concepts/BusinessLogic__.js.map +1 -1
  28. package/out/concepts/CallEvent__.d.ts +2 -0
  29. package/out/concepts/CallEvent__.js +75 -0
  30. package/out/concepts/CallEvent__.js.map +1 -1
  31. package/out/concepts/CallInterface__.d.ts +1 -0
  32. package/out/concepts/CallInterface__.js +26 -15
  33. package/out/concepts/CallInterface__.js.map +1 -1
  34. package/out/concepts/CallLogic__.d.ts +4 -0
  35. package/out/concepts/CallLogic__.js +65 -5
  36. package/out/concepts/CallLogic__.js.map +1 -1
  37. package/out/concepts/Entity__.d.ts +3 -3
  38. package/out/concepts/Entity__.js +4 -0
  39. package/out/concepts/Entity__.js.map +1 -1
  40. package/out/concepts/EnumItem__.d.ts +13 -0
  41. package/out/concepts/EnumItem__.js +31 -0
  42. package/out/concepts/EnumItem__.js.map +1 -1
  43. package/out/concepts/Event__.d.ts +2 -0
  44. package/out/concepts/Event__.js +30 -0
  45. package/out/concepts/Event__.js.map +1 -1
  46. package/out/concepts/FrontendType__.d.ts +2 -0
  47. package/out/concepts/FrontendType__.js +32 -0
  48. package/out/concepts/FrontendType__.js.map +1 -1
  49. package/out/concepts/Frontend__.d.ts +2 -0
  50. package/out/concepts/Frontend__.js +48 -0
  51. package/out/concepts/Frontend__.js.map +1 -1
  52. package/out/concepts/IfStatement__.js +6 -6
  53. package/out/concepts/IfStatement__.js.map +1 -1
  54. package/out/concepts/InterfaceParam__.d.ts +1 -0
  55. package/out/concepts/InterfaceParam__.js +23 -4
  56. package/out/concepts/InterfaceParam__.js.map +1 -1
  57. package/out/concepts/Interface__.d.ts +2 -1
  58. package/out/concepts/Interface__.js +29 -5
  59. package/out/concepts/Interface__.js.map +1 -1
  60. package/out/concepts/JSBlock__.d.ts +1 -0
  61. package/out/concepts/JSBlock__.js +6 -0
  62. package/out/concepts/JSBlock__.js.map +1 -1
  63. package/out/concepts/LogicDeclaration__.d.ts +1 -0
  64. package/out/concepts/LogicDeclaration__.js +58 -7
  65. package/out/concepts/LogicDeclaration__.js.map +1 -1
  66. package/out/concepts/Logic__.js +46 -27
  67. package/out/concepts/Logic__.js.map +1 -1
  68. package/out/concepts/MatchCase__.js +1 -2
  69. package/out/concepts/MatchCase__.js.map +1 -1
  70. package/out/concepts/Match__.js +3 -18
  71. package/out/concepts/Match__.js.map +1 -1
  72. package/out/concepts/MemberExpression__.js +4 -4
  73. package/out/concepts/MemberExpression__.js.map +1 -1
  74. package/out/concepts/Module__.d.ts +4 -0
  75. package/out/concepts/Module__.js +92 -0
  76. package/out/concepts/Module__.js.map +1 -1
  77. package/out/concepts/NewComposite__.d.ts +1 -1
  78. package/out/concepts/NewComposite__.js +2 -2
  79. package/out/concepts/NewComposite__.js.map +1 -1
  80. package/out/concepts/NullLiteral__.js +6 -0
  81. package/out/concepts/NullLiteral__.js.map +1 -1
  82. package/out/concepts/Paginate__.d.ts +1 -0
  83. package/out/concepts/Paginate__.js +15 -7
  84. package/out/concepts/Paginate__.js.map +1 -1
  85. package/out/concepts/QueryFromExpression__.js +2 -2
  86. package/out/concepts/QueryFromExpression__.js.map +1 -1
  87. package/out/concepts/StringLiteral__.js +3 -4
  88. package/out/concepts/StringLiteral__.js.map +1 -1
  89. package/out/concepts/StructureProperty__.d.ts +13 -0
  90. package/out/concepts/StructureProperty__.js +31 -0
  91. package/out/concepts/StructureProperty__.js.map +1 -1
  92. package/out/concepts/TypeAnnotation__.js +1 -0
  93. package/out/concepts/TypeAnnotation__.js.map +1 -1
  94. package/out/concepts/ViewElement__.d.ts +2 -0
  95. package/out/concepts/ViewElement__.js +61 -41
  96. package/out/concepts/ViewElement__.js.map +1 -1
  97. package/out/concepts/View__.d.ts +1 -0
  98. package/out/concepts/View__.js +55 -1
  99. package/out/concepts/View__.js.map +1 -1
  100. package/out/concepts/basics/stdlib/nasl.processV2.js +1 -1
  101. package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
  102. package/out/generator/genBundleFiles.js +36 -22
  103. package/out/generator/genBundleFiles.js.map +1 -1
  104. package/out/generator/genHash.d.ts +2 -2
  105. package/out/generator/genHash.js +30 -30
  106. package/out/generator/genHash.js.map +1 -1
  107. package/out/generator/genMetaData.js +7 -49
  108. package/out/generator/genMetaData.js.map +1 -1
  109. package/out/generator/permission.d.ts +8 -1
  110. package/out/generator/permission.js +321 -23
  111. package/out/generator/permission.js.map +1 -1
  112. package/out/generator/release-body/body.d.ts +5 -0
  113. package/out/generator/release-body/body.js +62 -12
  114. package/out/generator/release-body/body.js.map +1 -1
  115. package/out/generator/release-body/data.js +6 -2
  116. package/out/generator/release-body/data.js.map +1 -1
  117. package/out/generator/release-body/index.d.ts +1 -0
  118. package/out/generator/release-body/index.js +1 -0
  119. package/out/generator/release-body/index.js.map +1 -1
  120. package/out/generator/release-body/utils.js +3 -3
  121. package/out/generator/release-body/utils.js.map +1 -1
  122. package/out/generator/release-body/validation.js +2 -2
  123. package/out/generator/release-body/validation.js.map +1 -1
  124. package/out/index.d.ts +1 -1
  125. package/out/index.js.map +1 -1
  126. package/out/natural/genNaturalTS.d.ts +24 -56
  127. package/out/natural/genNaturalTS.js +116 -184
  128. package/out/natural/genNaturalTS.js.map +1 -1
  129. package/out/natural/getContext/getUILib.js +2 -3
  130. package/out/natural/getContext/getUILib.js.map +1 -1
  131. package/out/natural/getContext/index.d.ts +26 -35
  132. package/out/natural/getContext/index.js +172 -311
  133. package/out/natural/getContext/index.js.map +1 -1
  134. package/out/natural/index.d.ts +0 -1
  135. package/out/natural/index.js +0 -1
  136. package/out/natural/index.js.map +1 -1
  137. package/out/natural/transformTS2UI.js +31 -14
  138. package/out/natural/transformTS2UI.js.map +1 -1
  139. package/out/natural/transformTSCode.js +26 -10
  140. package/out/natural/transformTSCode.js.map +1 -1
  141. package/out/server/entity2LogicNamespace.d.ts +2 -2
  142. package/out/server/entity2LogicNamespace.js +321 -310
  143. package/out/server/entity2LogicNamespace.js.map +1 -1
  144. package/out/server/extendBaseNode.js +25 -0
  145. package/out/server/extendBaseNode.js.map +1 -1
  146. package/out/server/getLogics.js +1 -1
  147. package/out/server/getLogics.js.map +1 -1
  148. package/out/server/naslServer.d.ts +10 -4
  149. package/out/server/naslServer.js +77 -19
  150. package/out/server/naslServer.js.map +1 -1
  151. package/out/server/translator.js +12 -0
  152. package/out/server/translator.js.map +1 -1
  153. package/out/templator/genCreateBlock.js +3 -3
  154. package/out/templator/genCreateBlock.js.map +1 -1
  155. package/out/templator/genCurdEditMultipleKeyBlock.js +2 -2
  156. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  157. package/out/templator/genCurdMultipleKeyBlock.js +5 -5
  158. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  159. package/out/templator/genEditTableBlock.js +1 -1
  160. package/out/templator/genEditTableBlock.js.map +1 -1
  161. package/out/templator/genGetBlock.js.map +1 -1
  162. package/out/templator/genGridViewBlock.js.map +1 -1
  163. package/out/templator/genSelectBlock.js.map +1 -1
  164. package/out/templator/genTableBlock.js.map +1 -1
  165. package/out/templator/genUpdateBlock.js +3 -3
  166. package/out/templator/genUpdateBlock.js.map +1 -1
  167. package/out/templator/utils.js +1 -1
  168. package/out/templator/utils.js.map +1 -1
  169. package/out/translator/types.d.ts +2 -0
  170. package/package.json +5 -5
  171. package/sandbox/stdlib/nasl.processV2.ts +1 -1
  172. package/sandbox/stdlib/nasl.ui.definition.ts +0 -18
  173. package/src/common/BaseNode.ts +100 -16
  174. package/src/concepts/AbstractInterface__.ts +1 -0
  175. package/src/concepts/Annotation__.ts +1 -1
  176. package/src/concepts/App__.ts +126 -6
  177. package/src/concepts/Argument__.ts +3 -3
  178. package/src/concepts/BatchAssignment__.ts +2 -2
  179. package/src/concepts/BindAttribute__.ts +7 -7
  180. package/src/concepts/BindDirective__.ts +3 -4
  181. package/src/concepts/BindStyle__.ts +1 -1
  182. package/src/concepts/BusinessComponent__.ts +54 -1
  183. package/src/concepts/BusinessLogic__.ts +10 -1
  184. package/src/concepts/CallEvent__.ts +66 -0
  185. package/src/concepts/CallInterface__.ts +21 -9
  186. package/src/concepts/CallLogic__.ts +66 -5
  187. package/src/concepts/Entity__.ts +7 -1
  188. package/src/concepts/EnumItem__.ts +40 -1
  189. package/src/concepts/Event__.ts +32 -0
  190. package/src/concepts/FrontendType__.ts +34 -1
  191. package/src/concepts/Frontend__.ts +51 -0
  192. package/src/concepts/IfStatement__.ts +6 -6
  193. package/src/concepts/InterfaceParam__.ts +23 -4
  194. package/src/concepts/Interface__.ts +29 -5
  195. package/src/concepts/JSBlock__.ts +5 -0
  196. package/src/concepts/LogicDeclaration__.ts +65 -7
  197. package/src/concepts/Logic__.ts +49 -31
  198. package/src/concepts/MatchCase__.ts +1 -2
  199. package/src/concepts/Match__.ts +3 -21
  200. package/src/concepts/MemberExpression__.ts +4 -4
  201. package/src/concepts/Module__.ts +109 -0
  202. package/src/concepts/NewComposite__.ts +2 -2
  203. package/src/concepts/NullLiteral__.ts +7 -0
  204. package/src/concepts/Paginate__.ts +14 -7
  205. package/src/concepts/QueryFromExpression__.ts +2 -2
  206. package/src/concepts/StringLiteral__.ts +3 -4
  207. package/src/concepts/StructureProperty__.ts +41 -0
  208. package/src/concepts/TypeAnnotation__.ts +1 -0
  209. package/src/concepts/ViewElement__.ts +40 -19
  210. package/src/concepts/View__.ts +56 -1
  211. package/src/concepts/basics/stdlib/nasl.processV2.ts +1 -1
  212. package/src/generator/genBundleFiles.ts +39 -26
  213. package/src/generator/genHash.ts +32 -6
  214. package/src/generator/genMetaData.ts +11 -32
  215. package/src/generator/permission.ts +333 -23
  216. package/src/generator/release-body/body.ts +74 -15
  217. package/src/generator/release-body/data.ts +7 -2
  218. package/src/generator/release-body/index.ts +1 -0
  219. package/src/generator/release-body/utils.ts +3 -3
  220. package/src/generator/release-body/validation.ts +1 -1
  221. package/src/index.ts +13 -1
  222. package/src/natural/genNaturalTS.ts +148 -330
  223. package/src/natural/getContext/getUILib.ts +2 -3
  224. package/src/natural/getContext/index.ts +188 -357
  225. package/src/natural/index.ts +0 -1
  226. package/src/natural/transformTS2UI.ts +28 -14
  227. package/src/natural/transformTSCode.ts +25 -10
  228. package/src/server/entity2LogicNamespace.ts +13 -1
  229. package/src/server/extendBaseNode.ts +31 -0
  230. package/src/server/getLogics.ts +1 -1
  231. package/src/server/naslServer.ts +107 -27
  232. package/src/server/translator.ts +15 -0
  233. package/src/templator/genCreateBlock.ts +4 -4
  234. package/src/templator/genCurdEditMultipleKeyBlock.ts +2 -2
  235. package/src/templator/genCurdMultipleKeyBlock.ts +8 -8
  236. package/src/templator/genEditTableBlock.ts +4 -4
  237. package/src/templator/genGetBlock.ts +1 -1
  238. package/src/templator/genGridViewBlock.ts +2 -2
  239. package/src/templator/genSelectBlock.ts +3 -3
  240. package/src/templator/genTableBlock.ts +2 -2
  241. package/src/templator/genUpdateBlock.ts +6 -6
  242. package/src/templator/utils.ts +1 -1
  243. package/src/translator/types.ts +2 -0
  244. package/test/concepts/string-literal/__snapshots__/toVue.spec.ts.snap +1 -1
  245. package/test/concepts/view-element/__snapshots__/toVue.spec.ts.snap +6 -2
  246. package/out/natural/tools.d.ts +0 -11
  247. package/out/natural/tools.js +0 -155
  248. package/out/natural/tools.js.map +0 -1
  249. package/src/natural/tools.ts +0 -130
@@ -31,9 +31,9 @@ export async function getCallLogicData(app: App, validations: InputServerValidat
31
31
 
32
32
  nasl.traverseStrictChildren((node) => {
33
33
  if (
34
- 'uuid' in node &&
35
34
  node.concept === 'CallLogic' &&
36
35
  node.validation &&
36
+ 'uuid' in node &&
37
37
  map.has(node.uuid)
38
38
  ) {
39
39
  const data = map.get(node.uuid)!;
package/src/index.ts CHANGED
@@ -8,7 +8,19 @@ export * as utils from './utils';
8
8
  export * from './config';
9
9
  export * from './eventBus';
10
10
  export * as breakpoint from './breakpoint';
11
- export { getOperationRecords, operationRecordInfoMap, doOperationRecord, operationRecordQuery, operationRecordPlayback, loadApp, loadAppSync, handleApp, batchAction, batchQuery, mountDatabaseTypes } from './service/storage/init';
11
+ export {
12
+ getOperationRecords,
13
+ operationRecordInfoMap,
14
+ doOperationRecord,
15
+ operationRecordQuery,
16
+ operationRecordPlayback,
17
+ loadApp,
18
+ loadAppSync,
19
+ handleApp,
20
+ batchAction,
21
+ batchQuery,
22
+ mountDatabaseTypes,
23
+ } from './service/storage/init';
12
24
  export { createService } from './service/creator';
13
25
  export { stepRecorder } from './manager/stepRecorder';
14
26
  export * from './natural';
@@ -9,7 +9,6 @@ import {
9
9
  getStructures,
10
10
  getLogics,
11
11
  getModuleInterfaces,
12
- getConnections,
13
12
  getConnectors,
14
13
  getDependencies,
15
14
  getFrontendVariables,
@@ -17,317 +16,228 @@ import {
17
16
  getCurrentNodeContext,
18
17
  getCurrentNodeContextForUI,
19
18
  getNaslUIOld,
20
- getNaslUICode,
21
- getEnumsCode,
22
- getEntitiesCode,
23
- getStructuresCode,
24
- getLogicsCode,
25
- getModuleInterfacesCode,
26
- getConnectorsCode,
27
- getDependenciesCode,
28
- getFrontendViewsCode,
29
- wrapTSBlock,
30
19
  } from './getContext';
31
20
  import { createCompilerState } from '../translator';
32
21
 
33
- export * as getNaturalContext from './getContext';
34
-
35
22
  export function genNaturalTS(app: App, currentNode?: BaseNode, focusedNodePath?: string) {
36
23
  if (currentNode?.concept === 'Logic') {
37
24
  const logic = currentNode as Logic;
38
- const code = logic?.toNaturalTS(
39
- createCompilerState(undefined, {
40
- focusedNodePath,
41
- needNamespace: true,
42
- autoPrefixName: true,
43
- })
44
- );
25
+ const code = logic?.toNaturalTS(createCompilerState(undefined, {
26
+ focusedNodePath,
27
+ needNamespace: true,
28
+ autoPrefixName: true,
29
+ }));
45
30
  return code;
46
31
  }
47
32
  return getCurrentNodeContextForUI(currentNode).code;
48
33
  }
49
34
 
50
- // =========================== logic ===========================
51
- export function genNaturalTSContextJSONForLogic(
35
+ export function genNaturalTSContextForLogic(
52
36
  app: App,
53
37
  currentNode?: BaseNode,
54
38
  focusedNodePath?: string,
55
- material?: {
56
- moduleInterfaces: any;
57
- connectors: any;
58
- dependencies: any;
59
- }
39
+ requiredIndexes?: string[],
40
+ experimental?: boolean
60
41
  ) {
61
42
  const frontend = currentNode?.getAncestor('Frontend') as Frontend;
62
43
  const logicType = currentNode?.parentNode?.concept === 'App' ? 'global_logic' : 'view_logic';
63
- const state = createCompilerState();
64
-
65
- const { naslCore } = getNaslCore(logicType);
66
- const { naslUtil } = getNaslUtil();
67
- const { naslUI } = getNaslUIOld();
68
- const { naslOql } = getNaslOQL();
69
- const { enums } = getEnums(app, state);
70
- const { entities } = getEntities(app, state);
71
- const { structures } = getStructures(app, state);
72
- const { appLogics } = getLogics(app, currentNode);
73
- const { interfaceDependencies } = getModuleInterfaces(
74
- material?.moduleInterfaces || app?.interfaceDependencies,
75
- state
76
- );
77
-
78
- let connections = [];
79
- if (material?.connectors?.length) {
80
- connections = getConnectors(material.connectors, state).connectors;
81
- } else {
82
- connections = getConnections(material?.connectors || app.connections, state).connections;
83
- }
84
-
85
- const { dependencies } = getDependencies(
86
- material?.dependencies || app?.dependencies,
87
- state,
88
- logicType,
89
- frontend?.type
90
- );
91
- const { frontendVar, frontendVariables } = getFrontendVariables(
92
- currentNode?.getAncestor('Frontend') as Frontend,
93
- state
94
- );
95
- const { views } = getFrontendViews(frontend, state, currentNode, false);
96
- const { currentLogic } = getCurrentNodeContext(currentNode, focusedNodePath);
97
-
98
- return {
99
- naslCore,
100
- naslUtil,
101
- naslUI,
102
- naslOql,
103
- enums,
104
- entities,
105
- structures,
106
- appLogics,
107
- interfaceDependencies,
108
- connections,
109
- dependencies,
110
- frontendVar, // @deprecated
111
- frontendVariables,
112
- views,
113
- currentLogic,
114
- logicType,
115
- };
116
- }
117
-
118
- /**
119
- * 生成 Logic 的 TypeScript 上下文
120
- * @param tsContextJSON: 通过 genNaturalTSContextForLogic 获得到 tsContextJSON
121
- * @param codeType: 'detail' | 'short'。detail 为详细代码,short 为简短代码
122
- * 'detail' 将所有的code都返回(拼接成详细的code)。RAG召回,分析和执行阶段使用
123
- * 'short' 只返回简短的code。模型召回,对应的分析阶段使用
124
- * @param requiredIndexes?: 通过索引获取对应的 code。可挑选需要的 code
125
- **/
126
- export const genNaturalTSContextFromJSONForLogic = (
127
- tsContextJSON: any,
128
- codeType: 'detail' | 'short',
129
- requiredIndexes?: string[]
130
- ) => {
131
- const {
132
- naslCore,
133
- naslUtil,
134
- naslUI,
135
- naslOql,
136
- enums,
137
- entities,
138
- structures,
139
- appLogics,
140
- interfaceDependencies,
141
- connections,
142
- dependencies,
143
- frontendVariables,
144
- views,
145
- currentLogic,
146
- logicType,
147
- } = tsContextJSON;
44
+ const state = createCompilerState('', { descriptionComment: true });
148
45
 
149
46
  let code = '';
150
47
  code += '### [1] 标准库\n';
151
- code += wrapTSBlock(naslCore);
48
+ code += getNaslCore(logicType).code;
152
49
 
153
50
  code += '\n### [2] nasl.util\n';
154
- code += wrapTSBlock(naslUtil);
51
+ code += getNaslUtil().code;
155
52
 
156
- if (naslUI && logicType === 'view_logic') {
53
+ if (frontend) {
157
54
  code += '\n### [3] nasl.ui\n';
158
- if (typeof naslUI === 'string') {
159
- code += wrapTSBlock(naslUI);
160
- } else {
161
- code += getNaslUICode(naslUI, codeType, requiredIndexes);
162
- }
55
+ code += getNaslUIOld().code;
163
56
  }
164
57
 
165
- if (naslOql && logicType === 'global_logic') {
58
+ if (logicType === 'global_logic') {
166
59
  code += '\n### [4] nasl.oql\n';
167
- code += wrapTSBlock(naslOql);
60
+ code += getNaslOQL().code;
168
61
  }
169
62
 
170
63
  code += '\n### [5] 全局上下文\n';
171
- if (enums.data?.length) {
172
- code += '\n#### [5-0] 枚举\n';
173
- code += getEnumsCode(enums);
174
- }
64
+ code += '\n#### [5-0] 枚举\n';
65
+ code += getEnums(app, state, requiredIndexes).code;
175
66
 
176
- if (entities?.length) {
177
- code += '\n#### [5-1] 实体\n';
178
- code += getEntitiesCode(entities);
179
- }
67
+ code += '\n#### [5-1] 实体\n';
68
+ code += getEntities(app, state, requiredIndexes).code;
180
69
 
181
- if (structures.data?.length) {
182
- code += '\n#### [5-2] 可用的数据结构\n';
183
- code += getStructuresCode(structures);
184
- }
70
+ code += '\n#### [5-2] 可用的数据结构\n';
71
+ code += getStructures(app, state, requiredIndexes).code;
185
72
 
186
- if (appLogics.data?.length) {
187
- code += '\n### [6] 服务端逻辑\n';
188
- code += getLogicsCode(appLogics, codeType, requiredIndexes);
189
- }
73
+ code += '\n### [6] 服务端逻辑\n';
74
+ code += getLogics(app, currentNode, requiredIndexes).code;
190
75
 
191
- if (interfaceDependencies) {
192
- code += '\n### [7] 可调用的接口列表\n';
193
- code += getModuleInterfacesCode(interfaceDependencies, codeType, requiredIndexes);
194
- }
76
+ code += '\n### [7] 可调用的接口列表\n';
77
+ code += getModuleInterfaces(app, state, requiredIndexes).code;
195
78
 
196
- if (logicType === 'global_logic' && connections) {
79
+ if (app?.connections?.length > 0 && logicType === 'global_logic') {
197
80
  code += '\n### [8] 连接器逻辑列表\n';
198
- code += getConnectorsCode(connections, codeType, requiredIndexes);
81
+ code += getConnectors(app, state, requiredIndexes).code;
199
82
  }
200
- if (dependencies) {
83
+
84
+ if (app?.dependencies?.length > 0) {
201
85
  code += '\n### [9] 依赖库逻辑列表\n';
202
- code += getDependenciesCode(dependencies, codeType, requiredIndexes);
86
+ code += getDependencies(app, state, requiredIndexes).code;
203
87
  }
204
88
 
205
- if (logicType === 'view_logic') {
89
+ if (frontend) {
206
90
  code += '\n### [10] 页面上下文\n';
207
- if (frontendVariables) {
91
+ if (frontend?.variables?.length > 0) {
208
92
  code += '\n#### [10-0] 前端全局变量\n';
209
- code += frontendVariables;
93
+ code += getFrontendVariables(frontend, state).code;
210
94
  }
211
95
 
212
- if (views?.data?.length) {
213
- code += '\n#### [10-1] 前端页面列表\n';
214
- code += getFrontendViewsCode(views);
215
- }
96
+ code += '\n#### [10-1] 前端页面列表\n';
97
+ code += getFrontendViews(frontend, state, currentNode, true).code;
216
98
  }
217
99
 
218
- code += '\n### 当前逻辑上下文\n';
219
- code += wrapTSBlock(currentLogic);
220
-
100
+ if (focusedNodePath) {
101
+ code += '\n### 当前逻辑上下文\n';
102
+ code += getCurrentNodeContext(currentNode, focusedNodePath, experimental).code;
103
+ }
221
104
  return code;
222
- };
105
+ }
223
106
 
224
- export function genNaturalTSContextForLogic(
107
+ export const genNaturalTSContext = genNaturalTSContextForLogic;
108
+
109
+ export function genNaturalTSContextForUI(
225
110
  app: App,
226
- currentNode?: BaseNode,
111
+ currentNode: BaseNode,
227
112
  focusedNodePath?: string,
228
113
  requiredIndexes?: string[],
229
- material?: {
230
- moduleInterfaces: any;
231
- connectors: any;
232
- dependencies: any;
233
- },
234
- restParams?: {
235
- codeType?: 'detail' | 'short';
236
- }
114
+ material?: { basicMaterials: { json: any; tsDeclaration: string; }, extensionMaterials: { name: string; title: string; description: string; tsDescription: string; }[]; },
237
115
  ) {
238
- const tsContextJSON = genNaturalTSContextJSONForLogic(
239
- app,
240
- currentNode,
241
- focusedNodePath,
242
- material
243
- );
244
- const code = genNaturalTSContextFromJSONForLogic(
245
- tsContextJSON,
246
- restParams.codeType,
247
- requiredIndexes
248
- );
249
- return code;
250
- }
116
+ const frontend = currentNode.getAncestor('Frontend') as Frontend;
117
+ const state = createCompilerState('', { descriptionComment: true });
251
118
 
252
- export const genNaturalTSContext = genNaturalTSContextForLogic;
253
- export const genNaturalTsContextJson = genNaturalTSContextJSONForLogic;
119
+ let code = '';
120
+ code += '### [1] 标准库\n';
121
+ code += getNaslCore('view_logic').code;
254
122
 
255
- // =========================== view ===========================
123
+ code += '\n### [2] nasl.util\n';
124
+ code += getNaslUtil().code;
256
125
 
257
- // 生成 View 的 tsJson
258
- export function genNaturalTSContextJSONForUI(
259
- app: App,
260
- currentNode: BaseNode,
261
- material?: {
262
- basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string };
263
- extensionMaterials: {
264
- name: string;
265
- title: string;
266
- description: string;
267
- tsDescription: string;
268
- }[];
269
- moduleInterfaces: any;
270
- connectors: any;
271
- dependencies: any;
126
+ if (frontend) {
127
+ code += '\n### [3] nasl.ui\n';
128
+ code += getNaslUI(app, frontend.type, material || frontend.type, requiredIndexes).code;
129
+ code += '\n';
272
130
  }
131
+
132
+ code += '\n### [5] 全局上下文\n';
133
+ code += '\n#### [5-0] 枚举\n';
134
+ code += getEnums(app, state, requiredIndexes).code;
135
+
136
+ code += '\n#### [5-1] 实体\n';
137
+ code += getEntities(app, state, requiredIndexes).code;
138
+
139
+ code += '\n#### [5-2] 可用的数据结构\n';
140
+ code += getStructures(app, state, requiredIndexes).code;
141
+
142
+ code += '\n### [6] 服务端逻辑\n';
143
+ code += getLogics(app, currentNode, requiredIndexes).code;
144
+
145
+ code += '\n### [7] 可调用的接口列表\n';
146
+ code += getModuleInterfaces(app, state, requiredIndexes).code;
147
+
148
+ if (app?.dependencies?.length > 0) {
149
+ code += '\n### [9] 依赖库逻辑列表\n';
150
+ code += getDependencies(app, state, requiredIndexes).code;
151
+ }
152
+
153
+ if (frontend) {
154
+ code += '\n### [10] 页面上下文\n';
155
+ if (frontend?.variables?.length > 0) {
156
+ code += '\n#### [10-0] 前端全局变量\n';
157
+ code += getFrontendVariables(frontend, state).code;
158
+ }
159
+
160
+ code += '\n#### [10-1] 前端页面列表\n';
161
+ code += getFrontendViews(frontend, state, currentNode, true).code;
162
+ }
163
+
164
+ code += '\n### 当前页面上下文\n';
165
+ code += getCurrentNodeContextForUI(currentNode).code;
166
+ return code;
167
+ }
168
+
169
+ export function genNaturalTSContextJSONForLogic(
170
+ app: App,
171
+ currentNode?: BaseNode,
172
+ focusedNodePath?: string,
173
+ experimental?: boolean
273
174
  ) {
274
- const frontend = currentNode.getAncestor('Frontend') as Frontend;
275
- const state = createCompilerState();
175
+ const frontend = currentNode?.getAncestor('Frontend') as Frontend;
176
+ const logicType = currentNode?.parentNode?.concept === 'App' ? 'global_logic' : 'view_logic';
177
+ const state = createCompilerState('', { descriptionComment: true });
276
178
 
277
- const { naslCore } = getNaslCore('view_logic');
179
+ const { naslCore } = getNaslCore(logicType);
278
180
  const { naslUtil } = getNaslUtil();
279
- const { naslUI } = getNaslUI(app, frontend.type, {
280
- basicMaterials: material?.basicMaterials,
281
- extensionMaterials: material?.extensionMaterials,
282
- });
283
- const { enums } = getEnums(app, state);
284
- const { entities } = getEntities(app, state);
285
- const { structures } = getStructures(app, state);
286
- const { appLogics } = getLogics(app, currentNode);
287
- const { interfaceDependencies } = getModuleInterfaces(
288
- material?.moduleInterfaces || app?.interfaceDependencies,
181
+ const { naslUI } = getNaslUIOld();
182
+ const { naslOql } = getNaslOQL();
183
+ const { enums } = getEnums(app, state, []);
184
+ const { entities } = getEntities(app, state, []);
185
+ const { structures } = getStructures(app, state, []);
186
+ const { appLogics } = getLogics(app, currentNode, []);
187
+ const { interfaceDependencies } = getModuleInterfaces(app, state, []);
188
+ const { connections } = getConnectors(app, state, []);
189
+ const { dependencies } = getDependencies(app, state, []);
190
+ const { frontendVar, frontendVariables } = getFrontendVariables(
191
+ currentNode?.getAncestor('Frontend') as Frontend,
289
192
  state
290
193
  );
291
- const { dependencies } = getDependencies(
292
- material?.dependencies || app?.dependencies,
293
- state,
294
- 'view_logic',
295
- frontend?.type
296
- );
297
- const { frontendVariables } = getFrontendVariables(frontend, state);
298
194
  const { views } = getFrontendViews(frontend, state, currentNode, false);
299
- const { currentLogic } = getCurrentNodeContextForUI(currentNode);
195
+ const { currentLogic } = getCurrentNodeContext(currentNode, focusedNodePath, experimental);
300
196
 
301
197
  return {
302
198
  naslCore,
303
199
  naslUtil,
304
200
  naslUI,
201
+ naslOql,
305
202
  enums,
306
203
  entities,
307
204
  structures,
308
205
  appLogics,
309
206
  interfaceDependencies,
207
+ connections,
310
208
  dependencies,
209
+ frontendVar, // @deprecated
311
210
  frontendVariables,
312
211
  views,
313
- currentPage: currentLogic,
212
+ currentLogic,
314
213
  };
315
214
  }
316
215
 
317
- /**
318
- * 根据 tsContextJSON 生成 View 的 TypeScript 上下文
319
- * @param tsContextJSON: 通过 genNaturalTSContextJSONForUI 获得到 tsContextJSON
320
- * @param codeType: 'detail' | 'short'。detail 为详细代码,short 为简短代码
321
- * 'detail' 将所有的code都返回(拼接成详细的code)。RAG召回,分析和执行阶段使用
322
- * 'short' 只返回简短的code。模型召回,对应的分析阶段使用
323
- * @param requiredIndexes?: 通过索引获取对应的 code。可挑选需要的 code
324
- **/
325
- export const genNaturalTSContextFromJSONForUI = (
326
- tsContextJSON: any,
327
- codeType: 'detail' | 'short',
328
- requiredIndexes?: string[]
329
- ) => {
330
- const {
216
+ export const genNaturalTsContextJson = genNaturalTSContextJSONForLogic;
217
+
218
+ export function genNaturalTSContextJSONForUI(
219
+ app: App,
220
+ currentNode: BaseNode,
221
+ material?: { basicMaterials: { json: any; tsDeclaration: string; }, extensionMaterials: { name: string; title: string; description: string; tsDescription: string; }[]; },
222
+ requiredIndexes?: string[],
223
+ ) {
224
+ const frontend = currentNode.getAncestor('Frontend') as Frontend;
225
+ const state = createCompilerState();
226
+
227
+ const { naslCore } = getNaslCore('view_logic');
228
+ const { naslUtil } = getNaslUtil();
229
+ const { naslUI } = getNaslUI(app, frontend.type, material || frontend.type, requiredIndexes);
230
+ const { enums } = getEnums(app, state, requiredIndexes);
231
+ const { entities } = getEntities(app, state, requiredIndexes);
232
+ const { structures } = getStructures(app, state, requiredIndexes);
233
+ const { appLogics } = getLogics(app, currentNode, requiredIndexes);
234
+ const { interfaceDependencies } = getModuleInterfaces(app, state, requiredIndexes);
235
+ const { dependencies } = getDependencies(app, state, requiredIndexes);
236
+ const { frontendVariables } = getFrontendVariables(frontend, state);
237
+ const { views } = getFrontendViews(frontend, state, currentNode, true);
238
+ const { currentLogic } = getCurrentNodeContextForUI(currentNode);
239
+
240
+ return {
331
241
  naslCore,
332
242
  naslUtil,
333
243
  naslUI,
@@ -339,100 +249,8 @@ export const genNaturalTSContextFromJSONForUI = (
339
249
  dependencies,
340
250
  frontendVariables,
341
251
  views,
342
- currentPage,
343
- } = tsContextJSON;
344
-
345
- let code = '';
346
- code += '### [1] 标准库\n';
347
- code += wrapTSBlock(naslCore);
348
-
349
- code += '\n### [2] nasl.util\n';
350
- code += wrapTSBlock(naslUtil);
351
-
352
- if (naslUI) {
353
- code += '\n### [3] nasl.ui\n';
354
- if (typeof naslUI === 'string') {
355
- code += wrapTSBlock(naslUI);
356
- } else {
357
- code += getNaslUICode(naslUI, codeType, requiredIndexes);
358
- }
359
- }
360
-
361
- code += '\n### [5] 全局上下文\n';
362
- if (enums.data?.length) {
363
- code += '\n#### [5-0] 枚举\n';
364
- code += getEnumsCode(enums);
365
- }
366
-
367
- if (entities?.length) {
368
- code += '\n#### [5-1] 实体\n';
369
- code += getEntitiesCode(entities);
370
- }
371
-
372
- if (structures.data?.length) {
373
- code += '\n#### [5-2] 可用的数据结构\n';
374
- code += getStructuresCode(structures);
375
- }
376
-
377
- if (appLogics.data?.length) {
378
- code += '\n### [6] 服务端逻辑\n';
379
- code += getLogicsCode(appLogics, codeType, requiredIndexes);
380
- }
381
-
382
- if (interfaceDependencies) {
383
- code += '\n### [7] 可调用的接口列表\n';
384
- code += getModuleInterfacesCode(interfaceDependencies, codeType, requiredIndexes);
385
- }
386
-
387
- if (dependencies) {
388
- code += '\n### [9] 依赖库逻辑列表\n';
389
- code += getDependenciesCode(dependencies, codeType, requiredIndexes);
390
- }
391
-
392
- code += '\n### [10] 页面上下文\n';
393
- if (frontendVariables) {
394
- code += '\n#### [10-0] 前端全局变量\n';
395
- code += frontendVariables;
396
- }
397
-
398
- if (views?.data?.length) {
399
- code += '\n#### [10-1] 前端页面列表\n';
400
- code += getFrontendViewsCode(views);
401
- }
402
-
403
- code += '\n### 当前页面上下文\n';
404
- code += wrapTSBlock(currentPage);
405
-
406
- return code;
407
- };
408
-
409
- // 兼容各版本,统一调用 genNaturalTSContextForUI 方法
410
- export function genNaturalTSContextForUI(
411
- app: App,
412
- currentNode: BaseNode,
413
- focusedNodePath?: string,
414
- requiredIndexes?: string[],
415
- material?: {
416
- basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string };
417
- extensionMaterials: {
418
- name: string;
419
- title: string;
420
- description: string;
421
- tsDescription: string;
422
- }[];
423
- moduleInterfaces: any;
424
- connectors: any;
425
- dependencies: any;
426
- },
427
- restParams?: {
428
- codeType?: 'detail' | 'short';
429
- }
430
- ) {
431
- const tsContextJSON = genNaturalTSContextJSONForUI(app, currentNode, material);
432
- const code = genNaturalTSContextFromJSONForUI(
433
- tsContextJSON,
434
- restParams.codeType,
435
- requiredIndexes
436
- );
437
- return code;
252
+ currentPage: currentLogic,
253
+ };
438
254
  }
255
+
256
+ export * as getNaturalContext from './getContext';
@@ -104,10 +104,9 @@ export function getExtensionsDeclaration(viewComponent: any) {
104
104
  code += `${indent(state.tabSize + 1)}}\n`;
105
105
  code += `${indent(state.tabSize + 1)}class ${componentName}Options extends ViewComponentOptions {\n`;
106
106
  // props
107
- const props = viewComponent.props || viewComponent.attrs || [];
108
- props?.forEach((prop: any) => {
107
+ viewComponent.props?.forEach((prop: any) => {
109
108
  code += `${indent(state.tabSize + 2)}${utils.getDescription(prop.title, prop.description)}\n`;
110
- code += `${indent(state.tabSize + 2)}${camelCase(prop.name)}?: ${prop?.type || prop?.tsType};\n`;
109
+ code += `${indent(state.tabSize + 2)}${prop.name}?: ${prop?.type || prop?.tsType};\n`;
111
110
  });
112
111
  // events
113
112
  viewComponent.events?.forEach((event: any) => {