@lcap/nasl 2.22.0-beta.5 → 3.0.0-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 (304) hide show
  1. package/README.md +13 -0
  2. package/docs/classes/Module.html +15 -15
  3. package/docs/classes/Namespace.html +15 -15
  4. package/docs/classes/ViewComponent.html +19 -19
  5. package/out/automate/engine/utils.js +4 -0
  6. package/out/automate/engine/utils.js.map +1 -1
  7. package/out/breakpoint/generator/AfterStartNode.d.ts +7 -0
  8. package/out/breakpoint/generator/AfterStartNode.js +27 -0
  9. package/out/breakpoint/generator/AfterStartNode.js.map +1 -0
  10. package/out/breakpoint/generator/BeforeEndNode.d.ts +7 -0
  11. package/out/breakpoint/generator/BeforeEndNode.js +27 -0
  12. package/out/breakpoint/generator/BeforeEndNode.js.map +1 -0
  13. package/out/breakpoint/generator/BreakpointNode.d.ts +14 -0
  14. package/out/breakpoint/generator/BreakpointNode.js +166 -0
  15. package/out/breakpoint/generator/BreakpointNode.js.map +1 -0
  16. package/out/breakpoint/generator/index.d.ts +4 -0
  17. package/out/breakpoint/generator/index.js +98 -0
  18. package/out/breakpoint/generator/index.js.map +1 -0
  19. package/out/breakpoint/index.d.ts +3 -0
  20. package/out/breakpoint/index.js +20 -0
  21. package/out/breakpoint/index.js.map +1 -0
  22. package/out/breakpoint/shared/constants.d.ts +30 -0
  23. package/out/breakpoint/shared/constants.js +87 -0
  24. package/out/breakpoint/shared/constants.js.map +1 -0
  25. package/out/breakpoint/shared/index.d.ts +3 -0
  26. package/out/breakpoint/shared/index.js +33 -0
  27. package/out/breakpoint/shared/index.js.map +1 -0
  28. package/out/breakpoint/shared/operations.d.ts +10 -0
  29. package/out/breakpoint/shared/operations.js +25 -0
  30. package/out/breakpoint/shared/operations.js.map +1 -0
  31. package/out/breakpoint/shared/socket.d.ts +47 -0
  32. package/out/breakpoint/shared/socket.js +210 -0
  33. package/out/breakpoint/shared/socket.js.map +1 -0
  34. package/out/breakpoint/shared/utils.d.ts +20 -0
  35. package/out/breakpoint/shared/utils.js +133 -0
  36. package/out/breakpoint/shared/utils.js.map +1 -0
  37. package/out/breakpoint/store/core.d.ts +30 -0
  38. package/out/breakpoint/store/core.js +341 -0
  39. package/out/breakpoint/store/core.js.map +1 -0
  40. package/out/breakpoint/store/dock.d.ts +1 -0
  41. package/out/breakpoint/store/dock.js +127 -0
  42. package/out/breakpoint/store/dock.js.map +1 -0
  43. package/out/breakpoint/store/index.d.ts +2 -0
  44. package/out/breakpoint/store/index.js +19 -0
  45. package/out/breakpoint/store/index.js.map +1 -0
  46. package/out/common/BaseNode.d.ts +8 -0
  47. package/out/common/BaseNode.js +19 -0
  48. package/out/common/BaseNode.js.map +1 -1
  49. package/out/concepts/App__.d.ts +365 -16
  50. package/out/concepts/App__.js +431 -10
  51. package/out/concepts/App__.js.map +1 -1
  52. package/out/concepts/Assignment__.js +1 -1
  53. package/out/concepts/Assignment__.js.map +1 -1
  54. package/out/concepts/AuthInterface__.d.ts +37 -0
  55. package/out/concepts/AuthInterface__.js +141 -0
  56. package/out/concepts/AuthInterface__.js.map +1 -0
  57. package/out/concepts/AuthLogicForCallInterface__.d.ts +138 -0
  58. package/out/concepts/AuthLogicForCallInterface__.js +493 -0
  59. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -0
  60. package/out/concepts/AuthLogic__.d.ts +66 -0
  61. package/out/concepts/AuthLogic__.js +206 -0
  62. package/out/concepts/AuthLogic__.js.map +1 -0
  63. package/out/concepts/BackendVariable__.d.ts +137 -0
  64. package/out/concepts/BackendVariable__.js +422 -0
  65. package/out/concepts/BackendVariable__.js.map +1 -0
  66. package/out/concepts/Backend__.d.ts +134 -0
  67. package/out/concepts/Backend__.js +274 -0
  68. package/out/concepts/Backend__.js.map +1 -0
  69. package/out/concepts/BindAttribute__.d.ts +1 -1
  70. package/out/concepts/BindAttribute__.js +3 -1
  71. package/out/concepts/BindAttribute__.js.map +1 -1
  72. package/out/concepts/BindEvent__.d.ts +12 -0
  73. package/out/concepts/BindEvent__.js +68 -0
  74. package/out/concepts/BindEvent__.js.map +1 -1
  75. package/out/concepts/CallAuthInterface__.d.ts +126 -0
  76. package/out/concepts/CallAuthInterface__.js +408 -0
  77. package/out/concepts/CallAuthInterface__.js.map +1 -0
  78. package/out/concepts/CallInterface__.d.ts +6 -1
  79. package/out/concepts/CallInterface__.js +9 -1
  80. package/out/concepts/CallInterface__.js.map +1 -1
  81. package/out/concepts/CallLogic__.js +3 -1
  82. package/out/concepts/CallLogic__.js.map +1 -1
  83. package/out/concepts/CallQueryComponent__.js +9 -7
  84. package/out/concepts/CallQueryComponent__.js.map +1 -1
  85. package/out/concepts/Destination__.js +1 -1
  86. package/out/concepts/Destination__.js.map +1 -1
  87. package/out/concepts/End__.js +29 -2
  88. package/out/concepts/End__.js.map +1 -1
  89. package/out/concepts/EntityProperty__.js.map +1 -1
  90. package/out/concepts/Entity__.d.ts +1 -2
  91. package/out/concepts/Entity__.js +1 -31
  92. package/out/concepts/Entity__.js.map +1 -1
  93. package/out/concepts/ForEachStatement__.js +9 -4
  94. package/out/concepts/ForEachStatement__.js.map +1 -1
  95. package/out/concepts/FrontendLibrary__.d.ts +29 -29
  96. package/out/concepts/FrontendLibrary__.js +2 -2
  97. package/out/concepts/FrontendVariable__.d.ts +21 -0
  98. package/out/concepts/FrontendVariable__.js +64 -0
  99. package/out/concepts/FrontendVariable__.js.map +1 -0
  100. package/out/concepts/Frontend__.d.ts +151 -47
  101. package/out/concepts/Frontend__.js +188 -32
  102. package/out/concepts/Frontend__.js.map +1 -1
  103. package/out/concepts/Function__.js +1 -1
  104. package/out/concepts/Function__.js.map +1 -1
  105. package/out/concepts/Identifier__.js +1 -1
  106. package/out/concepts/Identifier__.js.map +1 -1
  107. package/out/concepts/Interface__.d.ts +1 -1
  108. package/out/concepts/Interface__.js.map +1 -1
  109. package/out/concepts/LogicItem__.d.ts +18 -3
  110. package/out/concepts/LogicItem__.js +22 -4
  111. package/out/concepts/LogicItem__.js.map +1 -1
  112. package/out/concepts/Logic__.d.ts +14 -9
  113. package/out/concepts/Logic__.js +43 -5
  114. package/out/concepts/Logic__.js.map +1 -1
  115. package/out/concepts/Module__.js.map +1 -1
  116. package/out/concepts/Namespace__.d.ts +29 -29
  117. package/out/concepts/Namespace__.js +2 -2
  118. package/out/concepts/NewComposite__.js +2 -2
  119. package/out/concepts/NewComposite__.js.map +1 -1
  120. package/out/concepts/OverriddenLogic__.d.ts +643 -0
  121. package/out/concepts/OverriddenLogic__.js +1602 -0
  122. package/out/concepts/OverriddenLogic__.js.map +1 -0
  123. package/out/concepts/Param__.d.ts +6 -0
  124. package/out/concepts/Param__.js +10 -0
  125. package/out/concepts/Param__.js.map +1 -1
  126. package/out/concepts/QueryFieldExpression__.d.ts +2 -0
  127. package/out/concepts/QueryFieldExpression__.js +9 -0
  128. package/out/concepts/QueryFieldExpression__.js.map +1 -1
  129. package/out/concepts/QuerySelectExpression__.d.ts +2 -2
  130. package/out/concepts/QuerySelectExpression__.js +2 -2
  131. package/out/concepts/QuerySelectExpression__.js.map +1 -1
  132. package/out/concepts/TypeAnnotation__.js +6 -6
  133. package/out/concepts/TypeAnnotation__.js.map +1 -1
  134. package/out/concepts/Variable__.d.ts +10 -0
  135. package/out/concepts/Variable__.js +12 -0
  136. package/out/concepts/Variable__.js.map +1 -1
  137. package/out/concepts/ViewComponent__.d.ts +33 -33
  138. package/out/concepts/ViewComponent__.js +7 -7
  139. package/out/concepts/ViewElement__.d.ts +6 -0
  140. package/out/concepts/ViewElement__.js +104 -1
  141. package/out/concepts/ViewElement__.js.map +1 -1
  142. package/out/concepts/View__.js +2 -2
  143. package/out/concepts/View__.js.map +1 -1
  144. package/out/concepts/basics/stdlib/index.js +2 -1
  145. package/out/concepts/basics/stdlib/index.js.map +1 -1
  146. package/out/concepts/basics/stdlib/nasl.auth.js +24 -0
  147. package/out/concepts/basics/stdlib/nasl.auth.js.map +1 -1
  148. package/out/concepts/basics/stdlib/nasl.http.d.ts +7 -0
  149. package/out/concepts/basics/stdlib/nasl.http.js +167 -0
  150. package/out/concepts/basics/stdlib/nasl.http.js.map +1 -0
  151. package/out/concepts/basics/stdlib/nasl.process.js +68 -0
  152. package/out/concepts/basics/stdlib/nasl.process.js.map +1 -1
  153. package/out/concepts/basics/stdlib/nasl.ui.js +4 -19
  154. package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
  155. package/out/concepts/basics/stdlib/nasl.util.js +83 -17
  156. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  157. package/out/concepts/basics/types/index.d.ts +1 -0
  158. package/out/concepts/basics/types/index.js +4 -1
  159. package/out/concepts/basics/types/index.js.map +1 -1
  160. package/out/concepts/index__.d.ts +8 -0
  161. package/out/concepts/index__.js +8 -0
  162. package/out/concepts/index__.js.map +1 -1
  163. package/out/enums/KEYWORDS.js +0 -1
  164. package/out/enums/KEYWORDS.js.map +1 -1
  165. package/out/generator/genBundleFiles.d.ts +1 -0
  166. package/out/generator/genBundleFiles.js +27 -0
  167. package/out/generator/genBundleFiles.js.map +1 -1
  168. package/out/generator/genMetaData.d.ts +4 -1
  169. package/out/generator/genMetaData.js +14 -0
  170. package/out/generator/genMetaData.js.map +1 -1
  171. package/out/generator/genReleaseBody.d.ts +2 -1
  172. package/out/generator/genReleaseBody.js +2 -1
  173. package/out/generator/genReleaseBody.js.map +1 -1
  174. package/out/index.d.ts +2 -1
  175. package/out/index.js +3 -1
  176. package/out/index.js.map +1 -1
  177. package/out/server/extendBaseNode.js +16 -4
  178. package/out/server/extendBaseNode.js.map +1 -1
  179. package/out/server/formatTsUtils.d.ts +2 -1
  180. package/out/server/formatTsUtils.js +39 -4
  181. package/out/server/formatTsUtils.js.map +1 -1
  182. package/out/server/getExtensionModules.d.ts +2 -2
  183. package/out/server/getExtensionModules.js +16 -2
  184. package/out/server/getExtensionModules.js.map +1 -1
  185. package/out/server/getLogics.js +5 -5
  186. package/out/server/getLogics.js.map +1 -1
  187. package/out/server/getMemberIdentifier.d.ts +1 -0
  188. package/out/server/getMemberIdentifier.js +34 -7
  189. package/out/server/getMemberIdentifier.js.map +1 -1
  190. package/out/server/naslServer.d.ts +64 -64
  191. package/out/server/naslServer.js +249 -121
  192. package/out/server/naslServer.js.map +1 -1
  193. package/out/server/naslStdlibMap.js +2 -0
  194. package/out/server/naslStdlibMap.js.map +1 -1
  195. package/out/server/translator.d.ts +1 -0
  196. package/out/server/translator.js +67 -2
  197. package/out/server/translator.js.map +1 -1
  198. package/out/service/defaultErrorMessage.json +1 -0
  199. package/out/service/storage/api.d.ts +10 -1
  200. package/out/service/storage/api.js +6 -0
  201. package/out/service/storage/api.js.map +1 -1
  202. package/out/service/storage/init.d.ts +4 -0
  203. package/out/service/storage/init.js +55 -35
  204. package/out/service/storage/init.js.map +1 -1
  205. package/out/service/storage/service.d.ts +3 -0
  206. package/out/service/storage/service.js +14 -0
  207. package/out/service/storage/service.js.map +1 -1
  208. package/out/utils/sortTsString.d.ts +1 -0
  209. package/out/utils/sortTsString.js +36 -0
  210. package/out/utils/sortTsString.js.map +1 -0
  211. package/out/utils/traverse.js +2 -2
  212. package/out/utils/traverse.js.map +1 -1
  213. package/package.json +7 -2
  214. package/sandbox/stdlib/nasl.auth.ts +8 -4
  215. package/sandbox/stdlib/nasl.core.d.ts +206 -0
  216. package/sandbox/stdlib/nasl.core.js +1 -0
  217. package/sandbox/stdlib/nasl.core.js.map +1 -0
  218. package/sandbox/stdlib/nasl.http.ts +35 -0
  219. package/sandbox/stdlib/nasl.process.ts +13 -0
  220. package/sandbox/stdlib/nasl.ui.ts +0 -5
  221. package/src/automate/engine/utils.js +4 -1
  222. package/src/breakpoint/generator/AfterStartNode.ts +27 -0
  223. package/src/breakpoint/generator/BeforeEndNode.ts +27 -0
  224. package/src/breakpoint/generator/BreakpointNode.ts +228 -0
  225. package/src/breakpoint/generator/index.ts +114 -0
  226. package/src/breakpoint/index.ts +3 -0
  227. package/src/breakpoint/shared/constants.ts +95 -0
  228. package/src/breakpoint/shared/index.ts +3 -0
  229. package/src/breakpoint/shared/operations.ts +25 -0
  230. package/src/breakpoint/shared/socket.ts +326 -0
  231. package/src/breakpoint/shared/utils.ts +195 -0
  232. package/src/breakpoint/store/core.ts +411 -0
  233. package/src/breakpoint/store/dock.ts +166 -0
  234. package/src/breakpoint/store/index.ts +2 -0
  235. package/src/breakpoint/types/index.d.ts +19 -0
  236. package/src/common/BaseNode.ts +19 -1
  237. package/src/concepts/App__.ts +828 -26
  238. package/src/concepts/Assignment__.ts +1 -1
  239. package/src/concepts/AuthInterface__.ts +148 -0
  240. package/src/concepts/AuthLogicForCallInterface__.ts +573 -0
  241. package/src/concepts/AuthLogic__.ts +225 -0
  242. package/src/concepts/BackendVariable__.ts +466 -0
  243. package/src/concepts/Backend__.ts +347 -0
  244. package/src/concepts/BindAttribute__.ts +4 -3
  245. package/src/concepts/BindEvent__.ts +71 -2
  246. package/src/concepts/CallAuthInterface__.ts +490 -0
  247. package/src/concepts/CallInterface__.ts +10 -2
  248. package/src/concepts/CallLogic__.ts +3 -1
  249. package/src/concepts/CallQueryComponent__.ts +67 -7
  250. package/src/concepts/Destination__.ts +19 -1
  251. package/src/concepts/End__.ts +31 -3
  252. package/src/concepts/EntityProperty__.ts +6 -0
  253. package/src/concepts/Entity__.ts +8 -31
  254. package/src/concepts/ForEachStatement__.ts +9 -4
  255. package/src/concepts/FrontendLibrary__.ts +30 -30
  256. package/src/concepts/FrontendVariable__.ts +76 -0
  257. package/src/concepts/Frontend__.ts +352 -89
  258. package/src/concepts/Function__.ts +1 -1
  259. package/src/concepts/Identifier__.ts +5 -5
  260. package/src/concepts/Interface__.ts +1 -1
  261. package/src/concepts/LogicItem__.ts +26 -6
  262. package/src/concepts/Logic__.ts +86 -8
  263. package/src/concepts/Module__.ts +32 -2
  264. package/src/concepts/Namespace__.ts +30 -30
  265. package/src/concepts/NewComposite__.ts +2 -3
  266. package/src/concepts/OverriddenLogic__.ts +2165 -0
  267. package/src/concepts/Param__.ts +13 -3
  268. package/src/concepts/QueryFieldExpression__.ts +18 -0
  269. package/src/concepts/QuerySelectExpression__.ts +11 -3
  270. package/src/concepts/TypeAnnotation__.ts +45 -6
  271. package/src/concepts/Variable__.ts +14 -0
  272. package/src/concepts/ViewComponent__.ts +35 -35
  273. package/src/concepts/ViewElement__.ts +104 -1
  274. package/src/concepts/View__.ts +24 -2
  275. package/src/concepts/basics/stdlib/index.ts +2 -1
  276. package/src/concepts/basics/stdlib/nasl.auth.ts +24 -0
  277. package/src/concepts/basics/stdlib/nasl.http.ts +166 -0
  278. package/src/concepts/basics/stdlib/nasl.process.ts +68 -0
  279. package/src/concepts/basics/stdlib/nasl.ui.ts +4 -19
  280. package/src/concepts/basics/stdlib/nasl.util.ts +83 -17
  281. package/src/concepts/basics/types/index.ts +5 -4
  282. package/src/concepts/index__.ts +8 -0
  283. package/src/enums/KEYWORDS.ts +0 -1
  284. package/src/generator/genBundleFiles.ts +36 -2
  285. package/src/generator/genMetaData.ts +16 -1
  286. package/src/generator/genReleaseBody.ts +4 -1
  287. package/src/index.ts +2 -1
  288. package/src/server/extendBaseNode.ts +18 -7
  289. package/src/server/formatTsUtils.ts +37 -5
  290. package/src/server/getExtensionModules.ts +18 -3
  291. package/src/server/getLogics.ts +6 -6
  292. package/src/server/getMemberIdentifier.ts +35 -9
  293. package/src/server/naslServer.ts +250 -124
  294. package/src/server/naslStdlibMap.ts +2 -0
  295. package/src/server/translator.ts +67 -1
  296. package/src/service/defaultErrorMessage.json +1 -0
  297. package/src/service/storage/api.js +7 -1
  298. package/src/service/storage/init.ts +66 -35
  299. package/src/service/storage/service.ts +18 -2
  300. package/src/utils/sortTsString.ts +32 -0
  301. package/src/utils/traverse.ts +2 -2
  302. package/test/examples/app-simple.json +73635 -0
  303. package/ts-worker/lib/tsserver.js +3 -3
  304. package/ts-worker/package.json +1 -1
@@ -0,0 +1,573 @@
1
+ import { TranslatorState, shiftState, withSourceMap, indent, createCompilerState, embeddedTSEmitter } from '../translator';
2
+ import Namespace from './Namespace__';
3
+ import CallQueryComponent from './CallQueryComponent__';
4
+ import Assignment from './Assignment__';
5
+ import Identifier from './Identifier__';
6
+ import BatchAssignment from './BatchAssignment__';
7
+ import OqlQueryComponent from './OqlQueryComponent__';
8
+ import Return from './Return__';
9
+ import Variable from './Variable__';
10
+ import TypeParam from './TypeParam__';
11
+ import TypeAnnotation from './TypeAnnotation__';
12
+
13
+ //================================================================================
14
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
15
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
16
+ //================================================================================
17
+ import { EventPayload, Params } from '../common/EventEmitter';
18
+ import { concept, excludedInJSON, property } from '../decorators';
19
+
20
+ import * as utils from '../utils';
21
+ import { v4 as uuidv4 } from 'uuid';
22
+ import BaseNode from '../common/BaseNode';
23
+ import classMap from '../common/classMap';
24
+ import Param from './Param__';
25
+ import AuthLogic from './AuthLogic__';
26
+
27
+ /**
28
+ * 调用的鉴权逻辑
29
+ */
30
+ @concept('调用的鉴权逻辑')
31
+ export class AuthLogicForCallInterface extends AuthLogic {
32
+ /**
33
+ * 产品概念
34
+ */
35
+ @property()
36
+ concept: 'AuthLogicForCallInterface' = 'AuthLogicForCallInterface';
37
+
38
+ /**
39
+ * 鉴权配置参数, 调用接口鉴权独有
40
+ */
41
+ @property('Param')
42
+ authParams: Array<Param> = [];
43
+
44
+
45
+
46
+ /**
47
+ * @param source 需要合并的部分参数
48
+ */
49
+ constructor(source?: Partial<AuthLogicForCallInterface>) {
50
+ source = Object.assign({}, AuthLogicForCallInterface.getDefaultOptions(), source);
51
+ super(source);
52
+ super.subConstructor(source);
53
+ }
54
+ getClassName() {
55
+ return 'AuthLogicForCallInterface';
56
+ }
57
+
58
+ static from(source: any, parentNode?: any, parentKey?: string): AuthLogicForCallInterface {
59
+ return super.from(source, parentNode, parentKey) as AuthLogicForCallInterface;
60
+ }
61
+
62
+
63
+
64
+
65
+ getParamExistingNames(excludedList: Array<Param> = []) {
66
+ const excludedSet = new Set(excludedList);
67
+ return ((this.authParams as Param[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
68
+ }
69
+ getParamUniqueName(name = 'param1') {
70
+ return utils.unique(name, this.getParamExistingNames(), undefined, false);
71
+ }
72
+
73
+ /**
74
+ * 插入输入参数
75
+ * @internal
76
+ * @param name 输入参数名称,如果不填会自动生成一个唯一名称
77
+ */
78
+ _insertParamAt(name: string, index: number): Param;
79
+
80
+ /**
81
+ * 插入输入参数
82
+ * @internal
83
+ * @param paramOptions 输入参数参数
84
+ */
85
+ _insertParamAt(paramOptions: Partial<Param>, index: number): Param;
86
+
87
+ /**
88
+ * 插入输入参数
89
+ * @internal
90
+ * @param param 已有的输入参数实例
91
+ */
92
+ _insertParamAt(param: Param, index: number): Param;
93
+
94
+ _insertParamAt(options: string | Partial<Param> | Param, index: number) {
95
+ const paramOptions: any = {};
96
+ const relationOptions = { parentNode: this, parentKey: 'authParams' };
97
+ let param: Param;
98
+ if (!options) {
99
+ param = Param.from({
100
+ ...paramOptions,
101
+ name: this.getParamUniqueName(),
102
+ }, this, 'authParams');
103
+ } else if (typeof options === 'string') {
104
+ param = Param.from({
105
+ ...paramOptions,
106
+ name: options,
107
+ }, this, 'authParams');
108
+ } else if (options instanceof Param) {
109
+ options.ensureDelete(); // 同一实例不支持多处存在
110
+ param = options;
111
+ Object.assign(param, relationOptions);
112
+ } else {
113
+ param = Param.from({
114
+ ...paramOptions,
115
+ ...options,
116
+ }, this, 'authParams');
117
+ }
118
+ this.authParams.splice(index, 0, param);
119
+ return param;
120
+ }
121
+
122
+ /**
123
+ * 插入输入参数
124
+ * @param name 输入参数名称,如果不填会自动生成一个唯一名称
125
+ */
126
+ insertParamAt(name: string, index: number): Param;
127
+
128
+ /**
129
+ * 插入输入参数
130
+ * @param paramOptions 输入参数参数
131
+ */
132
+ insertParamAt(paramOptions: Partial<Param>, index: number): Param;
133
+
134
+ /**
135
+ * 插入输入参数
136
+ * @param param 已有的输入参数实例
137
+ */
138
+ insertParamAt(param: Param, index: number): Param;
139
+
140
+ insertParamAt(options: string | Partial<Param> | Param, index: number) {
141
+ const node = this._insertParamAt(options as any, index);
142
+ node.create({
143
+ index,
144
+ parentNode: this,
145
+ parentKey: 'authParams',
146
+ });
147
+ return node;
148
+ }
149
+
150
+ /**
151
+ * 添加输入参数
152
+ * @internal
153
+ * @param name 输入参数名称,如果不填会自动生成一个唯一名称
154
+ */
155
+ _addParam(name?: string): Param;
156
+
157
+ /**
158
+ * 添加输入参数
159
+ * @internal
160
+ * @param paramOptions 输入参数参数
161
+ */
162
+ _addParam(paramOptions: Partial<Param>): Param;
163
+
164
+ /**
165
+ * 添加输入参数
166
+ * @internal
167
+ * @param param 已有的输入参数实例
168
+ */
169
+ _addParam(param: Param): Param;
170
+
171
+ _addParam(options?: string | Partial<Param> | Param) {
172
+ const index = this.authParams.length;
173
+ return this._insertParamAt(options as any, index);
174
+ }
175
+
176
+ /**
177
+ * 添加输入参数
178
+ * @internal
179
+ * @param name 输入参数名称,如果不填会自动生成一个唯一名称
180
+ */
181
+ addParam(name?: string): Param;
182
+
183
+ /**
184
+ * 添加输入参数
185
+ * @param paramOptions 输入参数参数
186
+ */
187
+ addParam(paramOptions: Partial<Param>): Param;
188
+
189
+ /**
190
+ * 添加输入参数
191
+ * @param param 已有的输入参数实例
192
+ */
193
+ addParam(param: Param): Param;
194
+
195
+ addParam(options?: string | Partial<Param> | Param) {
196
+ const node = this._addParam(options as any);
197
+ const index = this.authParams.indexOf(node);
198
+ node.create({
199
+ index,
200
+ parentNode: this,
201
+ parentKey: 'authParams',
202
+ });
203
+ return node;
204
+ }
205
+
206
+
207
+
208
+
209
+ /**
210
+ * 删除输入参数
211
+ * @param name 输入参数名称
212
+ */
213
+ removeParam(name: string): void;
214
+
215
+ /**
216
+ * 删除输入参数
217
+ * @param param 已有的输入参数实例
218
+ */
219
+ removeParam(param: Param): void;
220
+
221
+ removeParam(options: string | Param) {
222
+ let param: Param;
223
+ if (typeof options === 'string') {
224
+ param = (this.authParams as Param[]).find((item) => item.name === options);
225
+ if (!param) {
226
+ throw new Error('找不到输入参数 ' + options);
227
+ }
228
+ } else {
229
+ param = options;
230
+ }
231
+ return param.delete();
232
+ }
233
+
234
+ __removeParam(param: Param) {
235
+ const parentKey = param.parentKey;
236
+ const params: Params = {
237
+ parentNode: this,
238
+ parentKey,
239
+ index: -1,
240
+ object: null,
241
+ oldObject: param,
242
+ };
243
+ if (parentKey) {
244
+ params.parentKey = parentKey;
245
+ if (Array.isArray((this as any)[parentKey])) {
246
+ const index = (this as any)[parentKey].indexOf(param);
247
+ ~index && (this as any)[parentKey].splice(index, 1);
248
+ params.index = index;
249
+ } else if ((this as any)[parentKey] === param) {
250
+ params.index = 0;
251
+ (this as any)[parentKey] = undefined;
252
+ }
253
+ }
254
+ return params;
255
+ }
256
+
257
+ //================================================================================
258
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
259
+ // 自动生成的代码已结束。下面可以手动编写。
260
+ //================================================================================
261
+
262
+ @withSourceMap()
263
+ toEmbeddedTS(state?: TranslatorState, prefix?: string): string {
264
+ // 如果传了不要前缀那就为空, 要不用传进来的,要是都没有就默认导出
265
+ let code = '';
266
+ if (!prefix) {
267
+ // T、U分别用来定义 api 入参和返回值
268
+ code += `export function ${this.name}`;
269
+ } else if (prefix === 'noExport') {
270
+ code += `function ${this.name}`;
271
+ } else if (prefix === 'inObject') {
272
+ code += `${this.name}`;
273
+ }
274
+ const typeParams = [
275
+ ...(this.typeParams || []),
276
+ new TypeParam({
277
+ name: 'ApiParams',
278
+ }),
279
+ new TypeParam({
280
+ name: 'ApiReturn',
281
+ }),
282
+ ];
283
+ if (typeParams?.length) {
284
+ code += '<';
285
+ typeParams.forEach((typeParam, typeParamIndex) => {
286
+ code += typeParam.toEmbeddedTS(shiftState(state, code, { inline: true }));
287
+ if (typeParamIndex !== typeParams.length - 1) {
288
+ code += ', ';
289
+ }
290
+ });
291
+ code += '>';
292
+ }
293
+ // 有参数长度 && 鉴权参数
294
+ if (this.authParams.length) {
295
+ // const params = [...this.authParams, ...this.params];
296
+ const params = [...this.authParams];
297
+ params.forEach((param, index) => {
298
+ if (index === 0) {
299
+ code += '({';
300
+ }
301
+ code += param.tsName;
302
+ if (index !== params.length - 1) {
303
+ code += ', ';
304
+ } else {
305
+ code += ', api}:';
306
+ }
307
+ });
308
+ params.forEach((param, index) => {
309
+ if (index === 0) {
310
+ code += '{';
311
+ }
312
+ code += param.toEmbeddedTS(shiftState(state, code), !(param).required);
313
+ if (index !== params.length - 1) {
314
+ code += ', ';
315
+ } else {
316
+ code += ', api?: ApiReturn}';
317
+ }
318
+ });
319
+ code += '): ApiReturn';
320
+ } else {
321
+ // 没有参数的
322
+ code += '({api}: {api?: ApiReturn}): ApiReturn';
323
+ }
324
+
325
+ // 需要类型推导的局部变量/返回值需要调整申明顺序
326
+ const advanceMap: Map<Return | Variable, Assignment | BatchAssignment> = new Map();
327
+ const needGetSourceMapOqlList: Promise<any>[] = [];
328
+ this.traverseChildren((el) => {
329
+ if (el && (el instanceof BatchAssignment || (el instanceof Assignment && el.left?.name))) {
330
+ if (el instanceof Assignment) {
331
+ const advanceVar = this.variables?.find((variable) => !variable.typeAnnotation && (el.left?.name === variable.name));
332
+ if (advanceVar && !advanceMap.get(advanceVar)) {
333
+ advanceMap.set(advanceVar, el);
334
+ }
335
+ const advanceRn = this.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
336
+ if (advanceRn && !advanceMap.get(advanceRn)) {
337
+ advanceMap.set(advanceRn, el);
338
+ }
339
+ } else if (el instanceof BatchAssignment) {
340
+ el.assignmentLines.forEach(({ leftIndex }) => {
341
+ const leftCode
342
+ = leftIndex.length === 1 ? el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true })) : el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true }));
343
+ const advanceVar = this.variables?.find((variable) => !variable.typeAnnotation && (leftCode === variable.name));
344
+ if (advanceVar && !advanceMap.get(advanceVar)) {
345
+ advanceMap.set(advanceVar, el);
346
+ }
347
+ const advanceRn = this.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
348
+ if (advanceRn && !advanceMap.get(advanceRn)) {
349
+ advanceMap.set(advanceRn, el);
350
+ }
351
+ });
352
+ }
353
+ }
354
+ // 如果有sql查询组件就需要把他们存起来
355
+ if (el instanceof OqlQueryComponent) {
356
+ if (!el.codeSourceMap) {
357
+ needGetSourceMapOqlList.push(el.requestEmbeddedTS());
358
+ }
359
+ }
360
+ });
361
+
362
+ if (needGetSourceMapOqlList.length) {
363
+ Promise.all(needGetSourceMapOqlList).then(() => {
364
+ // 触发一下更新重新生成代码
365
+ (this.app as any)?.naslServer?.embeddedTSEmitter.emit('change', {
366
+ value: [
367
+ {
368
+ originEvent: {
369
+ action: 'update',
370
+ target: this,
371
+ },
372
+ },
373
+ ],
374
+ });
375
+ });
376
+ }
377
+
378
+ code += '{\n';
379
+
380
+ // 用于虚拟节点的查找引用
381
+ this.virtualParams
382
+ && Array.isArray(this.virtualParams)
383
+ && this.virtualParams.forEach((param) => {
384
+ code += indent((state?.tabSize || 0) + 1);
385
+ code += param.toEmbeddedNameTS(shiftState(state, code, { inline: true }));
386
+ code += '\n';
387
+ });
388
+
389
+ const variables = [
390
+ ...this.variables,
391
+ new Variable({ // 将默认参数加为变量 用于参数选择校验
392
+ name: 'request',
393
+ typeAnnotation: new TypeAnnotation({
394
+ concept: 'TypeAnnotation',
395
+ typeKind: 'generic',
396
+ typeNamespace: 'nasl.http',
397
+ typeName: 'HttpRequest',
398
+ typeArguments: [{
399
+ concept: 'TypeAnnotation',
400
+ typeKind: 'primitive',
401
+ typeNamespace: 'nasl.core',
402
+ typeName: 'String',
403
+ } as TypeAnnotation],
404
+ }),
405
+ }),
406
+ ];
407
+ variables.forEach((variable) => {
408
+ if (!advanceMap.get(variable)) {
409
+ code += indent((state?.tabSize || 0) + 1) + 'let ';
410
+ code += variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
411
+ code += ';\n';
412
+ }
413
+ });
414
+
415
+ advanceMap.forEach((assignment, node) => {
416
+ code += indent((state?.tabSize || 0) + 1) + '// @ts-ignore\n';
417
+ code += indent((state?.tabSize || 0) + 1) + 'let ';
418
+ code += node.toEmbeddedTS(shiftState(state, code, { inline: true }));
419
+ if (assignment instanceof BatchAssignment) {
420
+ assignment.assignmentLines.forEach(({ leftIndex, rightIndex }) => {
421
+ const leftCode
422
+ = leftIndex.length === 1 ? assignment.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true })) : assignment.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true }));
423
+ if (leftCode === node.name) {
424
+ const rightNode: any = rightIndex.length === 1 ? assignment.rights[rightIndex[0]]?.expression : assignment.rights[rightIndex[0]]?.members[rightIndex[1]];
425
+ // 当右边有明确类型时,直接使用其类型。旧版本数据查询不能直接使用其 typeAnnotation
426
+ if (rightNode?.typeAnnotation && !(rightNode instanceof CallQueryComponent && rightNode.ideVersion !== '2.11')) {
427
+ code += ': ';
428
+ code += rightNode.typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) || 'null';
429
+ } else {
430
+ code += ' = ';
431
+ const rightCode = rightNode?.toEmbeddedTS(shiftState(state, code, { inline: true }));
432
+ code += this.getRightCode(rightCode, assignment, rightNode);
433
+ }
434
+ }
435
+ });
436
+ } else if (['NewList', 'NewMap'].includes(assignment.right?.concept) && !(assignment.right as any)?.typeAnnotation) {
437
+ const rightNode: any = assignment.right;
438
+ code += ' = ';
439
+ code += rightNode.getInitCode(shiftState(state, code, { inline: true }));
440
+ } else if (assignment.right?.concept === 'NewComposite' && (assignment.right as any)?.typeAnnotation?.typeKind === 'anonymousStructure') {
441
+ const rightNode: any = assignment.right;
442
+ code += ' = ';
443
+ code += rightNode.getInitCode(shiftState(state, code, { inline: true }));
444
+ } else {
445
+ const rightNode: any = assignment.right;
446
+ // 当右边有明确类型时,直接使用其类型。旧版本数据查询不能直接使用其 typeAnnotation
447
+ if (rightNode?.typeAnnotation && !(rightNode instanceof CallQueryComponent && rightNode.ideVersion !== '2.11')) {
448
+ code += ': ';
449
+ code += rightNode.typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) || 'null';
450
+ } else {
451
+ code += ' = ';
452
+ let rightCode = '';
453
+ // 因为右侧枚举要赋值就得new 一下;
454
+ if (rightNode && rightNode instanceof Identifier && rightNode.namespace && rightNode.namespace.endsWith('enums')) {
455
+ rightCode += 'new ';
456
+ }
457
+ rightCode += rightNode && rightNode.toEmbeddedTS ? rightNode.toEmbeddedTS(shiftState(state, code, { inline: true })) : '__RIGHT__';
458
+ code += this.getRightCode(rightCode, assignment, rightNode);
459
+ }
460
+ }
461
+ code += ';\n';
462
+ });
463
+
464
+ if (!this.body.length) {
465
+ // 必有返回值,且返回值为 api 对应的返回参数
466
+ code += `${indent((state?.tabSize || 0) + 1)}let ${this.name}Result: ApiReturn; \n ${indent((state?.tabSize || 0) + 1)}return ${this.name}Result;\n`;
467
+ } else {
468
+ // 如果长度小于2 并且不是虚拟节点就 加 报错,
469
+ if (this.body.length <= 2 && !(this.parentNode instanceof Namespace)) {
470
+ code += indent((state?.tabSize || 0) + 1);
471
+ code += 'const __LogicEmpty: any = null;';
472
+ }
473
+ this.body.forEach((item) => {
474
+ code += item.toEmbeddedTS && item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
475
+ code += ';\n';
476
+ });
477
+ }
478
+
479
+ // 在body渲染完成之后把其余的节点放到下面
480
+ this.playground.forEach((item) => {
481
+ code += item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
482
+ code += ';\n';
483
+ });
484
+
485
+ code += indent(state?.tabSize || 0) + '}';
486
+ if (prefix === 'inObject') {
487
+ code += `,`;
488
+ }
489
+ code += '\n';
490
+ return code;
491
+ }
492
+
493
+ public static getDefaultOptions() {
494
+ return {
495
+ body: [
496
+ {
497
+ concept: 'Start',
498
+ label: '开始',
499
+ kind: 'Statement',
500
+ type: 'Start',
501
+ },
502
+ {
503
+ concept: 'End',
504
+ label: '结束',
505
+ kind: 'Statement',
506
+ type: 'End',
507
+ },
508
+ ],
509
+ params: [
510
+ {
511
+ concept: 'Param', // 产品概念
512
+ name: 'request', // 输入参数名称
513
+ description: '请求信息,系统自动注入,包含 method、url、header、cookie、body等', // 输入参数描述
514
+ typeAnnotation: {
515
+ concept: 'TypeAnnotation',
516
+ typeKind: 'generic',
517
+ typeNamespace: 'nasl.http',
518
+ typeName: 'HttpRequest',
519
+ typeArguments: [{
520
+ concept: 'TypeAnnotation',
521
+ typeKind: 'primitive',
522
+ typeNamespace: 'nasl.core',
523
+ typeName: 'String',
524
+ }],
525
+ }, // 类型
526
+ required: false, // 是否必填
527
+ },
528
+ ],
529
+ returns: [] as Array<any>,
530
+ };
531
+ }
532
+
533
+ /**
534
+ * 生成宿主语言的文件路径
535
+ * @param name 一般不用传,用于 rename
536
+ */
537
+ getEmbeddedFilePath(name = this.name) {
538
+ const _path = this.module ? `/${this.module.parentKey}/${this.module.name}` : '';
539
+ return `/embedded/${this.app.name}${_path}/authLogicsForCallInterface/${name}.ts`;
540
+ }
541
+
542
+ getTsNamespace(): string {
543
+ if (this.parentNode) {
544
+ const parentNamespace = (this.parentNode as any)?.getTsNamespace();
545
+ const parentName = this.parentNode.tsName || this.parentNode.name;
546
+ const arr = [parentNamespace];
547
+ if (this.parentNode.concept !== 'App' && parentName) {
548
+ arr.push(parentName);
549
+ }
550
+ let namespace = arr.join('.');
551
+ if (
552
+ !['nasl.ui', 'nasl.utils', 'nasl.util', 'nasl.browser', 'nasl.auth', 'nasl.configuration', 'nasl.process', 'nasl.logging', 'nasl.io'].includes(namespace)
553
+ && !namespace.includes('.authLogicsForCallInterface')
554
+ ) {
555
+ namespace = `${namespace}.authLogicsForCallInterface`;
556
+ }
557
+ return namespace;
558
+ } else
559
+ throw new Error('无法获取命名空间,请设置 parentNode!');
560
+ }
561
+
562
+ //================================================================================
563
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
564
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
565
+ //================================================================================
566
+ }
567
+
568
+ classMap.AuthLogicForCallInterface = AuthLogicForCallInterface;
569
+ export default AuthLogicForCallInterface;
570
+ //================================================================================
571
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
572
+ // 自动生成的代码已结束。下面可以手动编写。
573
+ //================================================================================