@lcap/nasl 3.7.3-beta.1 → 3.8.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/.mocharc.js +0 -1
  2. package/out/automate/engine/utils.js +6 -1
  3. package/out/automate/engine/utils.js.map +1 -1
  4. package/out/bak/translator.js +37 -0
  5. package/out/bak/translator.js.map +1 -1
  6. package/out/breakpoint/shared/utils.d.ts +1 -0
  7. package/out/breakpoint/shared/utils.js +1 -1
  8. package/out/breakpoint/shared/utils.js.map +1 -1
  9. package/out/common/BaseNode.d.ts +11 -0
  10. package/out/common/BaseNode.js +101 -5
  11. package/out/common/BaseNode.js.map +1 -1
  12. package/out/concepts/Annotatable__.d.ts +109 -0
  13. package/out/concepts/Annotatable__.js +161 -0
  14. package/out/concepts/Annotatable__.js.map +1 -0
  15. package/out/concepts/AnnotationProperty__.d.ts +48 -0
  16. package/out/concepts/AnnotationProperty__.js +74 -0
  17. package/out/concepts/AnnotationProperty__.js.map +1 -0
  18. package/out/concepts/Annotation__.d.ts +128 -0
  19. package/out/concepts/Annotation__.js +248 -0
  20. package/out/concepts/Annotation__.js.map +1 -0
  21. package/out/concepts/App__.d.ts +14 -26
  22. package/out/concepts/App__.js +50 -20
  23. package/out/concepts/App__.js.map +1 -1
  24. package/out/concepts/ApplyAnnotation__.d.ts +87 -0
  25. package/out/concepts/ApplyAnnotation__.js +140 -0
  26. package/out/concepts/ApplyAnnotation__.js.map +1 -0
  27. package/out/concepts/Argument__.d.ts +19 -0
  28. package/out/concepts/Argument__.js +126 -0
  29. package/out/concepts/Argument__.js.map +1 -1
  30. package/out/concepts/AssigneeV2__.d.ts +169 -0
  31. package/out/concepts/AssigneeV2__.js +176 -1
  32. package/out/concepts/AssigneeV2__.js.map +1 -1
  33. package/out/concepts/AuthLogicForCallInterface__.js +1 -1
  34. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
  35. package/out/concepts/AuthLogic__.js +1 -1
  36. package/out/concepts/AuthLogic__.js.map +1 -1
  37. package/out/concepts/BooleanLiteral__.d.ts +1 -0
  38. package/out/concepts/BooleanLiteral__.js +9 -0
  39. package/out/concepts/BooleanLiteral__.js.map +1 -1
  40. package/out/concepts/BusinessLogic__.js +1 -1
  41. package/out/concepts/BusinessLogic__.js.map +1 -1
  42. package/out/concepts/CallFunction__.js +1 -1
  43. package/out/concepts/CallFunction__.js.map +1 -1
  44. package/out/concepts/CallLogic__.d.ts +15 -0
  45. package/out/concepts/CallLogic__.js +149 -17
  46. package/out/concepts/CallLogic__.js.map +1 -1
  47. package/out/concepts/ConnectorLogic__.js +1 -1
  48. package/out/concepts/ConnectorLogic__.js.map +1 -1
  49. package/out/concepts/DatabaseTypeAnnotation__.d.ts +0 -2
  50. package/out/concepts/DatabaseTypeAnnotation__.js +0 -20
  51. package/out/concepts/DatabaseTypeAnnotation__.js.map +1 -1
  52. package/out/concepts/DepartmentManagerV2__.d.ts +29 -0
  53. package/out/concepts/DepartmentManagerV2__.js +56 -0
  54. package/out/concepts/DepartmentManagerV2__.js.map +1 -0
  55. package/out/concepts/DepartmentV2__.d.ts +33 -0
  56. package/out/concepts/DepartmentV2__.js +63 -0
  57. package/out/concepts/DepartmentV2__.js.map +1 -0
  58. package/out/concepts/DirectManagerV2__.d.ts +25 -0
  59. package/out/concepts/DirectManagerV2__.js +53 -0
  60. package/out/concepts/DirectManagerV2__.js.map +1 -0
  61. package/out/concepts/End__.js +9 -1
  62. package/out/concepts/End__.js.map +1 -1
  63. package/out/concepts/EntityProperty__.js +0 -2
  64. package/out/concepts/EntityProperty__.js.map +1 -1
  65. package/out/concepts/Entity__.d.ts +2 -2
  66. package/out/concepts/Entity__.js +4 -7
  67. package/out/concepts/Entity__.js.map +1 -1
  68. package/out/concepts/EnumItem__.d.ts +1 -12
  69. package/out/concepts/EnumItem__.js +17 -49
  70. package/out/concepts/EnumItem__.js.map +1 -1
  71. package/out/concepts/EnumSelectSetter__.d.ts +4 -0
  72. package/out/concepts/EnumSelectSetter__.js +7 -0
  73. package/out/concepts/EnumSelectSetter__.js.map +1 -1
  74. package/out/concepts/Enum__.js +1 -4
  75. package/out/concepts/Enum__.js.map +1 -1
  76. package/out/concepts/ForEachStatement__.js +1 -1
  77. package/out/concepts/ForEachStatement__.js.map +1 -1
  78. package/out/concepts/FrontendLibrary__.d.ts +52 -48
  79. package/out/concepts/FrontendLibrary__.js +45 -36
  80. package/out/concepts/FrontendLibrary__.js.map +1 -1
  81. package/out/concepts/FrontendType__.d.ts +4 -0
  82. package/out/concepts/FrontendType__.js +7 -0
  83. package/out/concepts/FrontendType__.js.map +1 -1
  84. package/out/concepts/Frontend__.d.ts +2 -0
  85. package/out/concepts/Frontend__.js +21 -2
  86. package/out/concepts/Frontend__.js.map +1 -1
  87. package/out/concepts/HistoryProcessV2__.js +4 -1
  88. package/out/concepts/HistoryProcessV2__.js.map +1 -1
  89. package/out/concepts/I18nInfo__.d.ts +0 -1
  90. package/out/concepts/I18nInfo__.js +0 -7
  91. package/out/concepts/I18nInfo__.js.map +1 -1
  92. package/out/concepts/Identifier__.d.ts +2 -0
  93. package/out/concepts/Identifier__.js +31 -0
  94. package/out/concepts/Identifier__.js.map +1 -1
  95. package/out/concepts/IfStatement__.js +2 -2
  96. package/out/concepts/IfStatement__.js.map +1 -1
  97. package/out/concepts/Interface__.js +1 -4
  98. package/out/concepts/Interface__.js.map +1 -1
  99. package/out/concepts/LogicItem__.d.ts +1 -1
  100. package/out/concepts/LogicItem__.js.map +1 -1
  101. package/out/concepts/Logic__.d.ts +16 -1
  102. package/out/concepts/Logic__.js +133 -15
  103. package/out/concepts/Logic__.js.map +1 -1
  104. package/out/concepts/ManagerV2__.d.ts +34 -0
  105. package/out/concepts/ManagerV2__.js +61 -0
  106. package/out/concepts/ManagerV2__.js.map +1 -0
  107. package/out/concepts/MatchCase__.d.ts +2 -2
  108. package/out/concepts/MatchCase__.js +7 -7
  109. package/out/concepts/MatchCase__.js.map +1 -1
  110. package/out/concepts/MemberExpression__.js +1 -0
  111. package/out/concepts/MemberExpression__.js.map +1 -1
  112. package/out/concepts/Module__.d.ts +88 -0
  113. package/out/concepts/Module__.js +85 -0
  114. package/out/concepts/Module__.js.map +1 -1
  115. package/out/concepts/OperatePermissionV2__.d.ts +1 -1
  116. package/out/concepts/OperatePermissionV2__.js.map +1 -1
  117. package/out/concepts/Param__.d.ts +4 -0
  118. package/out/concepts/Param__.js +13 -21
  119. package/out/concepts/Param__.js.map +1 -1
  120. package/out/concepts/ProcessElementV2__.d.ts +6 -1
  121. package/out/concepts/ProcessElementV2__.js +20 -0
  122. package/out/concepts/ProcessElementV2__.js.map +1 -1
  123. package/out/concepts/ProcessElement__.d.ts +7 -0
  124. package/out/concepts/ProcessElement__.js +47 -0
  125. package/out/concepts/ProcessElement__.js.map +1 -1
  126. package/out/concepts/ProcessV2__.d.ts +1 -34
  127. package/out/concepts/ProcessV2__.js +3 -70
  128. package/out/concepts/ProcessV2__.js.map +1 -1
  129. package/out/concepts/QueryFromExpression__.js +2 -2
  130. package/out/concepts/QueryFromExpression__.js.map +1 -1
  131. package/out/concepts/QueryJoinExpression__.js +2 -2
  132. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  133. package/out/concepts/StaticString__.d.ts +0 -4
  134. package/out/concepts/StaticString__.js +0 -11
  135. package/out/concepts/StaticString__.js.map +1 -1
  136. package/out/concepts/StructureProperty__.d.ts +1 -0
  137. package/out/concepts/StructureProperty__.js +14 -5
  138. package/out/concepts/StructureProperty__.js.map +1 -1
  139. package/out/concepts/Structure__.d.ts +4 -0
  140. package/out/concepts/Structure__.js +6 -9
  141. package/out/concepts/Structure__.js.map +1 -1
  142. package/out/concepts/SubLogic__.d.ts +418 -0
  143. package/out/concepts/SubLogic__.js +992 -0
  144. package/out/concepts/SubLogic__.js.map +1 -0
  145. package/out/concepts/Theme__.d.ts +9 -0
  146. package/out/concepts/Theme__.js +10 -0
  147. package/out/concepts/Theme__.js.map +1 -1
  148. package/out/concepts/Transactional__.d.ts +0 -1
  149. package/out/concepts/Transactional__.js +0 -7
  150. package/out/concepts/Transactional__.js.map +1 -1
  151. package/out/concepts/TypeAnnotation__.js +18 -0
  152. package/out/concepts/TypeAnnotation__.js.map +1 -1
  153. package/out/concepts/TypeParam__.d.ts +1 -0
  154. package/out/concepts/TypeParam__.js.map +1 -1
  155. package/out/concepts/ValidationRule__.d.ts +6 -1
  156. package/out/concepts/ValidationRule__.js +6 -1
  157. package/out/concepts/ValidationRule__.js.map +1 -1
  158. package/out/concepts/ViewElement__.d.ts +8 -2
  159. package/out/concepts/ViewElement__.js +213 -32
  160. package/out/concepts/ViewElement__.js.map +1 -1
  161. package/out/concepts/View__.d.ts +10 -2
  162. package/out/concepts/View__.js +129 -17
  163. package/out/concepts/View__.js.map +1 -1
  164. package/out/concepts/basics/stdlib/nasl.processV2.d.ts +2 -0
  165. package/out/concepts/basics/stdlib/nasl.processV2.js +50 -4
  166. package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
  167. package/out/concepts/basics/types/index.d.ts +1 -1
  168. package/out/concepts/basics/types/index.js +2 -1
  169. package/out/concepts/basics/types/index.js.map +1 -1
  170. package/out/concepts/index__.d.ts +9 -0
  171. package/out/concepts/index__.js +9 -0
  172. package/out/concepts/index__.js.map +1 -1
  173. package/out/concepts/utils/asserts.d.ts +409 -0
  174. package/out/concepts/utils/asserts.js +564 -14
  175. package/out/concepts/utils/asserts.js.map +1 -1
  176. package/out/concepts/utils/types.d.ts +33 -2
  177. package/out/generator/genBundleFiles.d.ts +13 -9
  178. package/out/generator/genBundleFiles.js +383 -63
  179. package/out/generator/genBundleFiles.js.map +1 -1
  180. package/out/generator/genMetaData.js +2 -0
  181. package/out/generator/genMetaData.js.map +1 -1
  182. package/out/generator/release-body/body.js +1 -0
  183. package/out/generator/release-body/body.js.map +1 -1
  184. package/out/generator/release-body/utils.d.ts +15 -7
  185. package/out/generator/release-body/utils.js +50 -7
  186. package/out/generator/release-body/utils.js.map +1 -1
  187. package/out/natural/genNaturalTS.js +2 -4
  188. package/out/natural/genNaturalTS.js.map +1 -1
  189. package/out/natural/getContext/index.js +0 -2
  190. package/out/natural/getContext/index.js.map +1 -1
  191. package/out/natural/transformTS2UI.js.map +1 -1
  192. package/out/natural/transformTSCode.d.ts +1 -1
  193. package/out/natural/transformTSCode.js.map +1 -1
  194. package/out/server/extendBaseNode.js +9 -0
  195. package/out/server/extendBaseNode.js.map +1 -1
  196. package/out/server/getLogics.js +10 -6
  197. package/out/server/getLogics.js.map +1 -1
  198. package/out/server/getMemberIdentifier.js +6 -0
  199. package/out/server/getMemberIdentifier.js.map +1 -1
  200. package/out/server/getProcessesV2.d.ts +3 -2
  201. package/out/server/getProcessesV2.js +15 -6
  202. package/out/server/getProcessesV2.js.map +1 -1
  203. package/out/server/naslServer.d.ts +5 -1
  204. package/out/server/naslServer.js +120 -30
  205. package/out/server/naslServer.js.map +1 -1
  206. package/out/server/translator.js +4 -0
  207. package/out/server/translator.js.map +1 -1
  208. package/out/service/storage/init.d.ts +2 -1
  209. package/out/service/storage/init.js +28 -71
  210. package/out/service/storage/init.js.map +1 -1
  211. package/out/templator/genCreateBlock.d.ts +6 -2
  212. package/out/templator/genCreateBlock.js +25 -8
  213. package/out/templator/genCreateBlock.js.map +1 -1
  214. package/out/templator/genCurdEditMultipleKeyBlock.d.ts +22 -0
  215. package/out/templator/genCurdEditMultipleKeyBlock.js +60 -1
  216. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  217. package/out/templator/genCurdMultipleKeyBlock.d.ts +13 -3
  218. package/out/templator/genCurdMultipleKeyBlock.js +29 -23
  219. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  220. package/out/templator/genGetBlock.d.ts +1 -1
  221. package/out/templator/genGetBlock.js +3 -2
  222. package/out/templator/genGetBlock.js.map +1 -1
  223. package/out/templator/genListViewBlock.d.ts +1 -1
  224. package/out/templator/genListViewBlock.js +3 -2
  225. package/out/templator/genListViewBlock.js.map +1 -1
  226. package/out/templator/genSelectBlock.d.ts +1 -1
  227. package/out/templator/genSelectBlock.js +3 -2
  228. package/out/templator/genSelectBlock.js.map +1 -1
  229. package/out/templator/genTableBlock.d.ts +9 -4
  230. package/out/templator/genTableBlock.js +31 -17
  231. package/out/templator/genTableBlock.js.map +1 -1
  232. package/out/templator/genUpdateBlock.d.ts +2 -2
  233. package/out/templator/genUpdateBlock.js +11 -11
  234. package/out/templator/genUpdateBlock.js.map +1 -1
  235. package/out/translator/types.d.ts +0 -4
  236. package/out/translator/utils.d.ts +0 -1
  237. package/out/translator/utils.js +1 -6
  238. package/out/translator/utils.js.map +1 -1
  239. package/out/utils/delay/index.d.ts +0 -0
  240. package/out/utils/delay/index.js +1 -0
  241. package/out/utils/delay/index.js.map +1 -0
  242. package/out/utils/env.d.ts +0 -4
  243. package/out/utils/env.js +3 -6
  244. package/out/utils/env.js.map +1 -1
  245. package/out/utils/index.d.ts +3 -2
  246. package/out/utils/index.js +18 -14
  247. package/out/utils/index.js.map +1 -1
  248. package/out/utils/time-slicing/controller.js.map +1 -1
  249. package/out/utils/types.d.ts +0 -17
  250. package/package.json +27 -20
  251. package/sandbox/stdlib/extension.component.ts +29 -0
  252. package/sandbox/stdlib/nasl.process.ts +17 -0
  253. package/sandbox/stdlib/nasl.processV2.ts +10 -5
  254. package/sandbox/stdlib/nasl.util.ts +3 -1
  255. package/src/automate/engine/utils.js +7 -2
  256. package/src/bak/translator.js +42 -1
  257. package/src/breakpoint/shared/utils.ts +2 -1
  258. package/src/common/BaseNode.ts +117 -5
  259. package/src/concepts/Annotatable__.ts +263 -0
  260. package/src/concepts/AnnotationProperty__.ts +102 -0
  261. package/src/concepts/Annotation__.ts +344 -0
  262. package/src/concepts/App__.ts +917 -26
  263. package/src/concepts/ApplyAnnotation__.ts +198 -0
  264. package/src/concepts/Argument__.ts +145 -1
  265. package/src/concepts/AssigneeV2__.ts +387 -1
  266. package/src/concepts/AuthLogicForCallInterface__.ts +1 -1
  267. package/src/concepts/AuthLogic__.ts +1 -1
  268. package/src/concepts/BooleanLiteral__.ts +9 -1
  269. package/src/concepts/BusinessLogic__.ts +1 -1
  270. package/src/concepts/CallFunction__.ts +1 -1
  271. package/src/concepts/CallLogic__.ts +153 -16
  272. package/src/concepts/ConnectorLogic__.ts +1 -1
  273. package/src/concepts/DatabaseTypeAnnotation__.ts +0 -11
  274. package/src/concepts/DepartmentManagerV2__.ts +70 -0
  275. package/src/concepts/DepartmentV2__.ts +75 -0
  276. package/src/concepts/DirectManagerV2__.ts +65 -0
  277. package/src/concepts/End__.ts +10 -1
  278. package/src/concepts/EntityProperty__.ts +0 -5
  279. package/src/concepts/Entity__.ts +5 -9
  280. package/src/concepts/EnumItem__.ts +16 -65
  281. package/src/concepts/EnumSelectSetter__.ts +6 -0
  282. package/src/concepts/Enum__.ts +1 -6
  283. package/src/concepts/ForEachStatement__.ts +1 -1
  284. package/src/concepts/FrontendLibrary__.ts +88 -80
  285. package/src/concepts/FrontendType__.ts +6 -0
  286. package/src/concepts/Frontend__.ts +26 -3
  287. package/src/concepts/HistoryProcessV2__.ts +5 -0
  288. package/src/concepts/I18nInfo__.ts +0 -5
  289. package/src/concepts/Identifier__.ts +32 -0
  290. package/src/concepts/IfStatement__.ts +2 -2
  291. package/src/concepts/Interface__.ts +1 -6
  292. package/src/concepts/LogicItem__.ts +1 -0
  293. package/src/concepts/Logic__.ts +140 -17
  294. package/src/concepts/ManagerV2__.ts +78 -0
  295. package/src/concepts/MatchCase__.ts +9 -8
  296. package/src/concepts/MemberExpression__.ts +1 -0
  297. package/src/concepts/Module__.ts +194 -0
  298. package/src/concepts/OperatePermissionV2__.ts +1 -1
  299. package/src/concepts/Param__.ts +17 -20
  300. package/src/concepts/ProcessElementV2__.ts +23 -0
  301. package/src/concepts/ProcessElement__.ts +18 -0
  302. package/src/concepts/ProcessV2__.ts +4 -70
  303. package/src/concepts/QueryFromExpression__.ts +2 -2
  304. package/src/concepts/QueryJoinExpression__.ts +2 -2
  305. package/src/concepts/StaticString__.ts +0 -13
  306. package/src/concepts/StructureProperty__.ts +16 -7
  307. package/src/concepts/Structure__.ts +10 -11
  308. package/src/concepts/SubLogic__.ts +1516 -0
  309. package/src/concepts/Theme__.ts +9 -0
  310. package/src/concepts/Transactional__.ts +0 -5
  311. package/src/concepts/TriggerLauncher__.ts +1 -1
  312. package/src/concepts/TypeAnnotation__.ts +17 -0
  313. package/src/concepts/TypeParam__.ts +3 -0
  314. package/src/concepts/ValidationRule__.ts +6 -1
  315. package/src/concepts/ViewElement__.ts +224 -34
  316. package/src/concepts/View__.ts +135 -22
  317. package/src/concepts/basics/stdlib/nasl.processV2.ts +56 -3
  318. package/src/concepts/basics/types/index.ts +1 -1
  319. package/src/concepts/index__.ts +9 -0
  320. package/src/concepts/utils/asserts.ts +595 -0
  321. package/src/concepts/utils/types.ts +53 -0
  322. package/src/generator/genBundleFiles.ts +408 -68
  323. package/src/generator/genMetaData.ts +3 -0
  324. package/src/generator/release-body/body.ts +1 -0
  325. package/src/generator/release-body/utils.ts +159 -55
  326. package/src/natural/genNaturalTS.ts +3 -5
  327. package/src/natural/getContext/index.ts +0 -2
  328. package/src/natural/transformTS2UI.ts +5 -2
  329. package/src/natural/transformTSCode.ts +2 -2
  330. package/src/server/extendBaseNode.ts +11 -2
  331. package/src/server/getLogics.ts +9 -7
  332. package/src/server/getMemberIdentifier.ts +7 -0
  333. package/src/server/getProcessesV2.ts +16 -6
  334. package/src/server/naslServer.ts +133 -30
  335. package/src/server/translator.ts +4 -0
  336. package/src/service/storage/init.ts +52 -97
  337. package/src/templator/genCreateBlock.ts +35 -14
  338. package/src/templator/genCurdEditMultipleKeyBlock.ts +65 -1
  339. package/src/templator/genCurdMultipleKeyBlock.ts +42 -23
  340. package/src/templator/genGetBlock.ts +4 -3
  341. package/src/templator/genListViewBlock.ts +3 -3
  342. package/src/templator/genSelectBlock.ts +4 -2
  343. package/src/templator/genTableBlock.ts +32 -17
  344. package/src/templator/genUpdateBlock.ts +21 -18
  345. package/src/translator/types.ts +0 -4
  346. package/src/translator/utils.ts +0 -6
  347. package/src/utils/delay/index.ts +0 -0
  348. package/src/utils/env.ts +4 -5
  349. package/src/utils/index.ts +16 -4
  350. package/src/utils/time-slicing/controller.ts +1 -0
  351. package/src/utils/types.ts +0 -20
  352. package/test/concepts/validation-rule/__snapshots__/toEmbeddedTS.spec.ts.snap +2 -1
  353. package/ts-worker/bundle.js +1 -1
  354. package/ts-worker/src/index.js +1 -0
  355. package/out/utils/language-cache/constant.d.ts +0 -18
  356. package/out/utils/language-cache/constant.js +0 -35
  357. package/out/utils/language-cache/constant.js.map +0 -1
  358. package/out/utils/language-cache/index.d.ts +0 -2
  359. package/out/utils/language-cache/index.js +0 -19
  360. package/out/utils/language-cache/index.js.map +0 -1
  361. package/out/utils/language-cache/nasl.d.ts +0 -10
  362. package/out/utils/language-cache/nasl.js +0 -98
  363. package/out/utils/language-cache/nasl.js.map +0 -1
  364. package/out/utils/language-cache/types.d.ts +0 -44
  365. package/out/utils/language-cache/types.js +0 -4
  366. package/out/utils/language-cache/types.js.map +0 -1
  367. package/src/utils/language-cache/constant.ts +0 -37
  368. package/src/utils/language-cache/index.ts +0 -2
  369. package/src/utils/language-cache/nasl.ts +0 -83
  370. package/src/utils/language-cache/types.ts +0 -48
@@ -0,0 +1,992 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __importDefault = (this && this.__importDefault) || function (mod) {
32
+ return (mod && mod.__esModule) ? mod : { "default": mod };
33
+ };
34
+ var SubLogic_1;
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.SubLogic = void 0;
37
+ const time_slicing_1 = require("../utils/time-slicing");
38
+ const common_1 = require("../common");
39
+ const translator_1 = require("../translator");
40
+ const decorators_1 = require("../decorators");
41
+ const utils = __importStar(require("../utils"));
42
+ const asserts = __importStar(require("./utils/asserts"));
43
+ const LogicItem__1 = __importDefault(require("./LogicItem__"));
44
+ /**
45
+ * 子逻辑
46
+ */
47
+ let SubLogic = SubLogic_1 = class SubLogic extends LogicItem__1.default {
48
+ /**
49
+ * @param source 需要合并的部分参数
50
+ */
51
+ constructor(source) {
52
+ source = Object.assign({}, SubLogic_1.getDefaultOptions(), source);
53
+ super(source);
54
+ /**
55
+ * 逻辑名称
56
+ */
57
+ this.name = '';
58
+ /**
59
+ * 输入参数列表
60
+ */
61
+ this.params = [];
62
+ /**
63
+ * 输出参数列表
64
+ */
65
+ this.returns = [];
66
+ /**
67
+ * 变量列表
68
+ */
69
+ this.variables = [];
70
+ /**
71
+ * 逻辑项列表
72
+ */
73
+ this.body = [];
74
+ /**
75
+ * 逻辑项列表
76
+ */
77
+ this.playground = [];
78
+ //================================================================================
79
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
80
+ // 自动生成的代码已结束。下面可以手动编写。
81
+ //================================================================================
82
+ this.completionChildren = [];
83
+ this.subLogics = [];
84
+ super.subConstructor(source);
85
+ }
86
+ static from(source, parentNode, parentKey) {
87
+ return super.from(source, parentNode, parentKey);
88
+ }
89
+ /**
90
+ * 设置逻辑名称
91
+ */
92
+ setName(name) {
93
+ const object = {
94
+ name,
95
+ };
96
+ this.update({
97
+ ...object,
98
+ field: 'name',
99
+ });
100
+ }
101
+ getParamUniqueName(name = 'param1') {
102
+ return utils.unique(name, this.getVarExistingNames(), undefined, false);
103
+ }
104
+ _insertParamAt(options, index) {
105
+ const paramOptions = {};
106
+ const relationOptions = { parentNode: this, parentKey: 'params' };
107
+ const Param = (0, decorators_1.getConceptConstructor)('Param');
108
+ let param;
109
+ if (!options) {
110
+ param = Param.from({
111
+ ...paramOptions,
112
+ name: this.getParamUniqueName(),
113
+ }, this, 'params');
114
+ }
115
+ else if (typeof options === 'string') {
116
+ param = Param.from({
117
+ ...paramOptions,
118
+ name: options,
119
+ }, this, 'params');
120
+ }
121
+ else if (asserts.isParam(options)) {
122
+ options.ensureDelete(); // 同一实例不支持多处存在
123
+ param = options;
124
+ Object.assign(param, relationOptions);
125
+ }
126
+ else {
127
+ param = Param.from({
128
+ ...paramOptions,
129
+ ...options,
130
+ }, this, 'params');
131
+ }
132
+ this.params.splice(index, 0, param);
133
+ return param;
134
+ }
135
+ insertParamAt(options, index) {
136
+ const node = this._insertParamAt(options, index);
137
+ node.create({
138
+ index,
139
+ parentNode: this,
140
+ parentKey: 'params',
141
+ });
142
+ return node;
143
+ }
144
+ _addParam(options) {
145
+ const index = this.params.length;
146
+ return this._insertParamAt(options, index);
147
+ }
148
+ addParam(options) {
149
+ const node = this._addParam(options);
150
+ const index = this.params.indexOf(node);
151
+ node.create({
152
+ index,
153
+ parentNode: this,
154
+ parentKey: 'params',
155
+ });
156
+ return node;
157
+ }
158
+ getReturnUniqueName(name = 'result') {
159
+ return utils.unique(name, this.getVarExistingNames(), undefined, false);
160
+ }
161
+ _insertReturnAt(options, index) {
162
+ const retOptions = {};
163
+ const relationOptions = { parentNode: this, parentKey: 'returns' };
164
+ const Return = (0, decorators_1.getConceptConstructor)('Return');
165
+ let ret;
166
+ if (!options) {
167
+ ret = Return.from({
168
+ ...retOptions,
169
+ name: this.getReturnUniqueName(),
170
+ }, this, 'returns');
171
+ }
172
+ else if (typeof options === 'string') {
173
+ ret = Return.from({
174
+ ...retOptions,
175
+ name: options,
176
+ }, this, 'returns');
177
+ }
178
+ else if (asserts.isReturn(options)) {
179
+ options.ensureDelete(); // 同一实例不支持多处存在
180
+ ret = options;
181
+ Object.assign(ret, relationOptions);
182
+ }
183
+ else {
184
+ ret = Return.from({
185
+ ...retOptions,
186
+ ...options,
187
+ }, this, 'returns');
188
+ }
189
+ this.returns.splice(index, 0, ret);
190
+ return ret;
191
+ }
192
+ insertReturnAt(options, index) {
193
+ const node = this._insertReturnAt(options, index);
194
+ node.create({
195
+ index,
196
+ parentNode: this,
197
+ parentKey: 'returns',
198
+ });
199
+ return node;
200
+ }
201
+ _addReturn(options) {
202
+ const index = this.returns.length;
203
+ return this._insertReturnAt(options, index);
204
+ }
205
+ addReturn(options) {
206
+ const node = this._addReturn(options);
207
+ const index = this.returns.indexOf(node);
208
+ node.create({
209
+ index,
210
+ parentNode: this,
211
+ parentKey: 'returns',
212
+ });
213
+ return node;
214
+ }
215
+ getVariableUniqueName(name = 'variable1') {
216
+ return utils.unique(name, this.getVarExistingNames(), undefined, false);
217
+ }
218
+ _insertVariableAt(options, index) {
219
+ const variableOptions = {};
220
+ const relationOptions = { parentNode: this, parentKey: 'variables' };
221
+ const Variable = (0, decorators_1.getConceptConstructor)('Variable');
222
+ let variable;
223
+ if (!options) {
224
+ variable = Variable.from({
225
+ ...variableOptions,
226
+ name: this.getVariableUniqueName(),
227
+ }, this, 'variables');
228
+ }
229
+ else if (typeof options === 'string') {
230
+ variable = Variable.from({
231
+ ...variableOptions,
232
+ name: options,
233
+ }, this, 'variables');
234
+ }
235
+ else if (asserts.isVariable(options)) {
236
+ options.ensureDelete(); // 同一实例不支持多处存在
237
+ variable = options;
238
+ Object.assign(variable, relationOptions);
239
+ }
240
+ else {
241
+ variable = Variable.from({
242
+ ...variableOptions,
243
+ ...options,
244
+ }, this, 'variables');
245
+ }
246
+ this.variables.splice(index, 0, variable);
247
+ return variable;
248
+ }
249
+ insertVariableAt(options, index) {
250
+ const node = this._insertVariableAt(options, index);
251
+ node.create({
252
+ index,
253
+ parentNode: this,
254
+ parentKey: 'variables',
255
+ });
256
+ return node;
257
+ }
258
+ _addVariable(options) {
259
+ const index = this.variables.length;
260
+ return this._insertVariableAt(options, index);
261
+ }
262
+ addVariable(options) {
263
+ const node = this._addVariable(options);
264
+ const index = this.variables.indexOf(node);
265
+ node.create({
266
+ index,
267
+ parentNode: this,
268
+ parentKey: 'variables',
269
+ });
270
+ return node;
271
+ }
272
+ _insertItemInBodyAt(options, index) {
273
+ const logicItemOptions = {};
274
+ const relationOptions = { parentNode: this, parentKey: 'body' };
275
+ const LogicItem = (0, decorators_1.getConceptConstructor)('LogicItem');
276
+ let logicItem;
277
+ if (asserts.isLogicItem(options)) {
278
+ options.ensureDelete(); // 同一实例不支持多处存在
279
+ logicItem = options;
280
+ Object.assign(logicItem, relationOptions);
281
+ }
282
+ else {
283
+ logicItem = LogicItem.from({
284
+ ...logicItemOptions,
285
+ ...options,
286
+ }, this, 'body');
287
+ }
288
+ this.body.splice(index, 0, logicItem);
289
+ return logicItem;
290
+ }
291
+ insertItemInBodyAt(options, index) {
292
+ const node = this._insertItemInBodyAt(options, index);
293
+ node.create({
294
+ index,
295
+ parentNode: this,
296
+ parentKey: 'body',
297
+ });
298
+ return node;
299
+ }
300
+ _addItemInBody(options) {
301
+ const index = this.body.length;
302
+ return this._insertItemInBodyAt(options, index);
303
+ }
304
+ addItemInBody(options) {
305
+ const node = this._addItemInBody(options);
306
+ const index = this.body.indexOf(node);
307
+ node.create({
308
+ index,
309
+ parentNode: this,
310
+ parentKey: 'body',
311
+ });
312
+ return node;
313
+ }
314
+ _insertItemInPlaygroundAt(options, index) {
315
+ const logicItemOptions = {};
316
+ const relationOptions = { parentNode: this, parentKey: 'playground' };
317
+ const LogicItem = (0, decorators_1.getConceptConstructor)('LogicItem');
318
+ let logicItem;
319
+ if (asserts.isLogicItem(options)) {
320
+ options.ensureDelete(); // 同一实例不支持多处存在
321
+ logicItem = options;
322
+ Object.assign(logicItem, relationOptions);
323
+ }
324
+ else {
325
+ logicItem = LogicItem.from({
326
+ ...logicItemOptions,
327
+ ...options,
328
+ }, this, 'playground');
329
+ }
330
+ this.playground.splice(index, 0, logicItem);
331
+ return logicItem;
332
+ }
333
+ insertItemInPlaygroundAt(options, index) {
334
+ const node = this._insertItemInPlaygroundAt(options, index);
335
+ node.create({
336
+ index,
337
+ parentNode: this,
338
+ parentKey: 'playground',
339
+ });
340
+ return node;
341
+ }
342
+ _addItemInPlayground(options) {
343
+ const index = this.playground.length;
344
+ return this._insertItemInPlaygroundAt(options, index);
345
+ }
346
+ addItemInPlayground(options) {
347
+ const node = this._addItemInPlayground(options);
348
+ const index = this.playground.indexOf(node);
349
+ node.create({
350
+ index,
351
+ parentNode: this,
352
+ parentKey: 'playground',
353
+ });
354
+ return node;
355
+ }
356
+ removeParam(options) {
357
+ let param;
358
+ if (typeof options === 'string') {
359
+ param = this.params.find((item) => item.name === options);
360
+ if (!param) {
361
+ throw new Error('找不到输入参数 ' + options);
362
+ }
363
+ }
364
+ else {
365
+ param = options;
366
+ }
367
+ return param.delete();
368
+ }
369
+ removeReturn(options) {
370
+ let ret;
371
+ if (typeof options === 'string') {
372
+ ret = this.returns.find((item) => item.name === options);
373
+ if (!ret) {
374
+ throw new Error('找不到输出参数 ' + options);
375
+ }
376
+ }
377
+ else {
378
+ ret = options;
379
+ }
380
+ return ret.delete();
381
+ }
382
+ removeVariable(options) {
383
+ let variable;
384
+ if (typeof options === 'string') {
385
+ variable = this.variables.find((item) => item.name === options);
386
+ if (!variable) {
387
+ throw new Error('找不到变量 ' + options);
388
+ }
389
+ }
390
+ else {
391
+ variable = options;
392
+ }
393
+ return variable.delete();
394
+ }
395
+ removeItemInBody(options) {
396
+ let logicItem = options;
397
+ return logicItem.delete();
398
+ }
399
+ removeItemInPlayground(options) {
400
+ let logicItem = options;
401
+ return logicItem.delete();
402
+ }
403
+ getVarExistingNames(excludedList = []) {
404
+ const excludedSet = new Set(excludedList);
405
+ return [...this.params].filter((item) => !excludedSet.has(item)).map((item) => item.name);
406
+ }
407
+ toJSContent(code, state) {
408
+ // params
409
+ if (Array.isArray(this.params)) {
410
+ this.params.forEach((param) => {
411
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}`;
412
+ code += param.toJS(state);
413
+ code += ';\n';
414
+ });
415
+ }
416
+ // variables
417
+ if (Array.isArray(this.variables)) {
418
+ this.variables.forEach((variable) => {
419
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}let `;
420
+ code += variable.toJS(state);
421
+ code += ';\n';
422
+ });
423
+ }
424
+ // returns
425
+ if (Array.isArray(this.returns)) {
426
+ this.returns.forEach((ret) => {
427
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}let `;
428
+ code += ret.toJS(state);
429
+ code += ';\n';
430
+ });
431
+ }
432
+ if (Array.isArray(this.body)) {
433
+ this.body.forEach((item) => {
434
+ code += item.toJS && item.toJS((0, translator_1.shiftState)(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
435
+ code += '\n';
436
+ });
437
+ }
438
+ return code;
439
+ }
440
+ toJS(state, type) {
441
+ let code = '';
442
+ code += `async (`;
443
+ if (this.params?.length) {
444
+ this.params.forEach((param, index) => {
445
+ code += param.name;
446
+ if (index !== this.params.length - 1)
447
+ code += ', ';
448
+ });
449
+ }
450
+ code += ') => {\n';
451
+ code = this.toJSContent(code, state);
452
+ code += `${(0, translator_1.indent)(state?.tabSize || 0)}}\n`;
453
+ return code;
454
+ }
455
+ static getDefaultOptions() {
456
+ return {
457
+ body: [
458
+ {
459
+ concept: 'Start',
460
+ label: '开始',
461
+ kind: 'Statement',
462
+ type: 'Start',
463
+ },
464
+ {
465
+ concept: 'End',
466
+ label: '结束',
467
+ kind: 'Statement',
468
+ type: 'End',
469
+ },
470
+ ],
471
+ };
472
+ }
473
+ *getRightCode(code, assignment, rightNode) {
474
+ code = code.replaceAll('\n', ' ');
475
+ // 赋值语句的右侧或者集合内置函数的参数
476
+ if ((asserts.isAssignment(assignment) && !assignment.right) ||
477
+ (asserts.isCallFunction(assignment) &&
478
+ ((assignment.isDerivableList && !assignment.itemOfCollection) ||
479
+ (assignment.isDerivableMap && !(assignment.keyOfCollection && assignment.itemOfCollection))))) {
480
+ return code;
481
+ }
482
+ // 调用接口,参数替换成 null
483
+ if (asserts.isCallInterface(rightNode)) {
484
+ const { _interface } = rightNode.getModuleInterface();
485
+ return _interface
486
+ ? `${rightNode.tsCalleeKey}(${_interface.params.map(() => 'null').join(',')})`
487
+ : null;
488
+ }
489
+ // 调用服务端逻辑,参数替换成 null
490
+ if (asserts.isCallLogic(rightNode) && rightNode.calleeNamespace === 'app.logics') {
491
+ const calleeName = rightNode?.calleeName;
492
+ const calleeLogic = this.app.logics.find((l) => l.name === calleeName);
493
+ return calleeLogic ? `app.logics.${calleeName}(${calleeLogic.params.map(() => 'null').join(',')})` : null;
494
+ }
495
+ // ForEachStatement 内部变量需要替换处理,如 item、index
496
+ const forEachStatement = assignment.getAncestor('ForEachStatement');
497
+ if (forEachStatement) {
498
+ code = yield* this.handleForEachCode(code, forEachStatement);
499
+ }
500
+ // 可迭代的集合
501
+ const callFunction = assignment.getAncestor('CallFunction');
502
+ if (callFunction && callFunction.isLoopCollection) {
503
+ const anonymousFunction = assignment.getAncestor('AnonymousFunction');
504
+ code = yield* this.handleCollectionCode(code, anonymousFunction, callFunction);
505
+ }
506
+ // Match 需要针对分支缩小类型范围
507
+ const matchCase = assignment.getAncestor('MatchCase');
508
+ if (matchCase) {
509
+ code = yield* this.handleMatchCaseCode(code, matchCase);
510
+ }
511
+ return code;
512
+ }
513
+ *handleForEachCode(code, forEachStatement) {
514
+ const { item, index, each } = forEachStatement;
515
+ if (code.includes(item.name)) {
516
+ const eachTSCode = each ? yield* each.toEmbeddedTS() : '__IDENTIFIER__';
517
+ code = this.handleReplaceCode(code, item.name, eachTSCode === '__IDENTIFIER__' ? eachTSCode : `${eachTSCode}.__get(0)`);
518
+ }
519
+ if (code.includes(index.name)) {
520
+ code = this.handleReplaceCode(code, index.name, 'new nasl.core.Long(0)');
521
+ }
522
+ const parentForEachStatement = forEachStatement.getAncestor('ForEachStatement');
523
+ if (parentForEachStatement) {
524
+ code = yield* this.handleForEachCode(code, parentForEachStatement);
525
+ }
526
+ return code;
527
+ }
528
+ *handleCollectionCode(code, anonymousFunction, callFunction) {
529
+ const { collection } = callFunction;
530
+ const self = this;
531
+ yield* (0, time_slicing_1.wrapForEachToGenerator)(anonymousFunction.params, function* warpForEachGenerator(param, index) {
532
+ if (code.includes(param?.name)) {
533
+ const collectionTSCode = collection ? yield* collection.toEmbeddedTS() : '__IDENTIFIER__';
534
+ code = self.handleReplaceCode(code, param.name, collectionTSCode === '__IDENTIFIER__'
535
+ ? collectionTSCode
536
+ : callFunction.isLoopMap && index === 0
537
+ ? `${collectionTSCode}.__getKey(0)`
538
+ : `${collectionTSCode}.__get(0)`);
539
+ }
540
+ });
541
+ const parentForEachStatement = callFunction.getAncestor('ForEachStatement');
542
+ if (parentForEachStatement) {
543
+ code = yield* this.handleForEachCode(code, parentForEachStatement);
544
+ }
545
+ const parentCallFunction = callFunction.getAncestor('CallFunction');
546
+ if (parentCallFunction?.isLoopCollection) {
547
+ const parentAnonymousFunction = callFunction.getAncestor('AnonymousFunction');
548
+ code = yield* this.handleCollectionCode(code, parentAnonymousFunction, parentCallFunction);
549
+ }
550
+ return code;
551
+ }
552
+ handleReplaceCode(code, variable, replaceCode) {
553
+ return code.replace(/\S+/g, ($1) => {
554
+ if ($1 === `${variable},`)
555
+ return `${replaceCode},`;
556
+ if ($1 === variable)
557
+ return replaceCode;
558
+ let fnCode = $1;
559
+ if ($1.startsWith(`${variable}.`))
560
+ fnCode = $1.replaceAll(`${variable}.`, `${replaceCode}.`);
561
+ if ($1.startsWith(`${variable},`))
562
+ fnCode = $1.replaceAll(`${variable},`, `${replaceCode},`);
563
+ if ($1.includes(`(${variable},`))
564
+ fnCode = $1.replaceAll(`(${variable},`, `(${replaceCode},`);
565
+ if ($1.includes(`(${variable}.`))
566
+ fnCode = $1.replaceAll(`(${variable}.`, `(${replaceCode}.`);
567
+ if ($1.includes(`(${variable})`))
568
+ fnCode = $1.replaceAll(`(${variable})`, `(${replaceCode})`);
569
+ if ($1.includes(`,${variable},`))
570
+ fnCode = $1.replaceAll(`,${variable},`, `,${replaceCode},`);
571
+ if ($1.includes(`,${variable}.`))
572
+ fnCode = $1.replaceAll(`,${variable}.`, `,${replaceCode}.`);
573
+ if ($1.includes(`,${variable})`))
574
+ fnCode = $1.replaceAll(`,${variable})`, `,${replaceCode})`);
575
+ if ($1.includes(`...[${variable}.`))
576
+ fnCode = $1.replaceAll(`...[${variable}.`, `...[${replaceCode}.`);
577
+ return fnCode;
578
+ });
579
+ }
580
+ *handleMatchCaseCode(code, matchCase) {
581
+ const match = matchCase.getAncestor('Match');
582
+ const expressionTsCode = yield* match.expression.toEmbeddedTS();
583
+ if (code.includes(expressionTsCode)) {
584
+ let typeCode = '';
585
+ yield* (0, time_slicing_1.wrapForEachToGenerator)(matchCase.patterns, function* wrapForEach(pattern, index) {
586
+ if (asserts.isTypeAnnotation(pattern)) {
587
+ if (index === 0) {
588
+ typeCode += yield* pattern.toEmbeddedTS();
589
+ }
590
+ else {
591
+ typeCode += '|';
592
+ typeCode += yield* pattern.toEmbeddedTS();
593
+ }
594
+ }
595
+ });
596
+ if (typeCode) {
597
+ code = this.handleReplaceCode(code, expressionTsCode, `(${expressionTsCode} as ${typeCode})`);
598
+ }
599
+ }
600
+ const parentMatchCase = match.getAncestor('MatchCase');
601
+ if (parentMatchCase) {
602
+ code = yield* this.handleMatchCaseCode(code, parentMatchCase);
603
+ }
604
+ return code;
605
+ }
606
+ *toEmbeddedTS(state = (0, translator_1.createCompilerState)(), prefix, hideDefaultValue) {
607
+ const self = this;
608
+ // 获取所有子节点用于树上填充
609
+ self.getSubLogics();
610
+ // 如果传了不要前缀那就为空, 要不用传进来的,要是都没有就默认导出
611
+ let code = '';
612
+ // 用来储存默认值翻译结构是__IDENTIFIER__或者__IDENTIFIER__()的节点
613
+ const IDENTIFIERMAP = new Set();
614
+ code += `function ${self.tsName}`;
615
+ code += '(';
616
+ // 有参数长度
617
+ if (self.params.length) {
618
+ yield* (0, time_slicing_1.wrapForEachToGenerator)(self.params, function* warpForEachGenerator(param, index) {
619
+ code += yield* param.toEmbeddedTS((0, translator_1.shiftState)(state, code));
620
+ if (index !== self.params.length - 1)
621
+ code += ', ';
622
+ });
623
+ }
624
+ code += ')';
625
+ const advanceMap = new Map();
626
+ const callFunctionAdvanceMap = new Map();
627
+ yield* self.traverseChildrenGenerator(function* traverseChildrenGenerator(el) {
628
+ if (el &&
629
+ // 批量赋值
630
+ (asserts.isBatchAssignment(el) ||
631
+ // 赋值
632
+ (asserts.isAssignment(el) && el.left?.name) ||
633
+ // 内置函数对集合类型的推导
634
+ (asserts.isCallFunction(el) && el.derivablecollection?.name))) {
635
+ if (asserts.isAssignment(el)) {
636
+ const advanceVar = self.variables?.find((variable) => !variable.typeAnnotation && el.left?.name === variable.name);
637
+ if (advanceVar && !advanceMap.get(advanceVar)) {
638
+ advanceMap.set(advanceVar, el);
639
+ }
640
+ const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
641
+ if (advanceRn && !advanceMap.get(advanceRn)) {
642
+ advanceMap.set(advanceRn, el);
643
+ }
644
+ }
645
+ else if (asserts.isCallFunction(el)) {
646
+ // 需要被推导的集合
647
+ const expression = el.derivablecollection;
648
+ // 宽泛意义上的变量(变量+出参)
649
+ const advanceVar = [...(self.variables || []), ...(self.returns || [])].find((variable) => {
650
+ return !variable.typeAnnotation && expression?.name === variable.name;
651
+ });
652
+ if (advanceVar && !callFunctionAdvanceMap.get(advanceVar)) {
653
+ callFunctionAdvanceMap.set(advanceVar, el);
654
+ }
655
+ }
656
+ else if (asserts.isBatchAssignment(el)) {
657
+ yield* (0, time_slicing_1.wrapForEachToGenerator)(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
658
+ const leftCode = leftIndex.length === 1
659
+ ? yield* el.left.expression.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }))
660
+ : yield* el.left.members[leftIndex[1]]?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) ??
661
+ (0, time_slicing_1.returnOrigin)('');
662
+ const advanceVar = self.variables?.find((variable) => !variable.typeAnnotation && leftCode === variable.name);
663
+ if (advanceVar && !advanceMap.get(advanceVar)) {
664
+ advanceMap.set(advanceVar, el);
665
+ }
666
+ const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
667
+ if (advanceRn && !advanceMap.get(advanceRn)) {
668
+ advanceMap.set(advanceRn, el);
669
+ }
670
+ });
671
+ }
672
+ }
673
+ });
674
+ // 兼容 return 没有类型情况
675
+ if (self.returns.length && self.returns[0].typeAnnotation) {
676
+ code += ': ';
677
+ code += yield* self.returns[0].typeAnnotation?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) ??
678
+ (0, time_slicing_1.returnOrigin)('');
679
+ }
680
+ code += '{\n';
681
+ for (const variable of self.variables) {
682
+ const ts = yield* variable.defaultValue?.toEmbeddedTS?.() ?? utils.returnOrigin('');
683
+ if (['__IDENTIFIER__', '__IDENTIFIER__()'].includes(ts)) {
684
+ IDENTIFIERMAP.add(variable);
685
+ }
686
+ if (!advanceMap.get(variable) && !callFunctionAdvanceMap.get(variable)) {
687
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}let `;
688
+ code += yield* variable.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
689
+ code += ';\n';
690
+ }
691
+ }
692
+ for (const ret of self.returns) {
693
+ const ts = yield* ret.defaultValue?.toEmbeddedTS?.() ?? (0, time_slicing_1.returnOrigin)('');
694
+ if (['__IDENTIFIER__', '__IDENTIFIER__()'].includes(ts)) {
695
+ IDENTIFIERMAP.add(ret);
696
+ }
697
+ if (!advanceMap.get(ret) && !callFunctionAdvanceMap.get(ret)) {
698
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}let `;
699
+ code += yield* ret.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
700
+ code += ';\n';
701
+ }
702
+ }
703
+ // 变量提升
704
+ state.isVariableHost = true;
705
+ yield* (0, time_slicing_1.wrapIteratorToGenerator)(advanceMap.entries(), function* warpForEachGenerator([node, assignment]) {
706
+ // 有默认值的用默认值来推导类型, 但是如果是__IDENTIFIER__或者__IDENTIFIER__(),就不需要默认值来推导了
707
+ if (node.defaultValue?.expression && !IDENTIFIERMAP.has(node)) {
708
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}let `;
709
+ code += yield* node.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
710
+ return;
711
+ }
712
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}// @ts-ignore\n`;
713
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}let `;
714
+ code += yield* node.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
715
+ if (asserts.isBatchAssignment(assignment)) {
716
+ yield* (0, time_slicing_1.wrapForEachToGenerator)(assignment.assignmentLines, function* warpForEachGenerator({ leftIndex, rightIndex }) {
717
+ const leftCode = leftIndex.length === 1
718
+ ? yield* assignment.left.expression.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }))
719
+ : yield* assignment.left.members[leftIndex[1]]?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) ??
720
+ (0, time_slicing_1.returnOrigin)('');
721
+ if (leftCode === node.name) {
722
+ const rightNode = rightIndex.length === 1
723
+ ? assignment.rights[rightIndex[0]]?.expression
724
+ : assignment.rights[rightIndex[0]]?.members[rightIndex[1]];
725
+ // 当右边有明确类型时,直接使用其类型。旧版本数据查询不能直接使用其 typeAnnotation
726
+ if (rightNode?.typeAnnotation && !(asserts.isCallQueryComponent(rightNode) && !rightNode.isAutoInfer())) {
727
+ if (rightNode.concept === 'NewComposite' && rightNode.typeAnnotation?.typeKind === 'anonymousStructure') {
728
+ code += '= ';
729
+ code += (yield* rightNode.getInitCode((0, translator_1.shiftState)(state, code, { inline: true }))) || 'null';
730
+ }
731
+ else if (rightNode.concept === 'NewComposite' && rightNode.typeAnnotation?.typeKind === 'generic') {
732
+ code += '= ';
733
+ code += (yield* rightNode.getNewCompositeCode((0, translator_1.shiftState)(state, code, { inline: true }))) || 'null';
734
+ }
735
+ else {
736
+ code += ': ';
737
+ code += yield* rightNode.typeAnnotation?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) ??
738
+ (0, time_slicing_1.returnOrigin)('null');
739
+ }
740
+ }
741
+ else {
742
+ code += ' = ';
743
+ const rightCode = yield* rightNode?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) ??
744
+ (0, time_slicing_1.returnOrigin)('');
745
+ code += yield* self.getRightCode(rightCode, assignment, rightNode);
746
+ }
747
+ }
748
+ });
749
+ }
750
+ else if (['NewList', 'NewMap'].includes(assignment.right?.concept) &&
751
+ !assignment.right?.typeAnnotation) {
752
+ const rightNode = assignment.right;
753
+ code += ' = ';
754
+ code += yield* rightNode.getInitCode((0, translator_1.shiftState)(state, code, { inline: true }));
755
+ }
756
+ else if (assignment.right?.concept === 'NewComposite' &&
757
+ assignment.right?.typeAnnotation?.typeKind === 'anonymousStructure') {
758
+ const rightNode = assignment.right;
759
+ code += ' = ';
760
+ code += yield* rightNode.getInitCode((0, translator_1.shiftState)(state, code, { inline: true }));
761
+ }
762
+ else if (assignment.right?.concept === 'NewComposite' &&
763
+ assignment.right?.typeAnnotation?.typeKind === 'generic') {
764
+ const rightNode = assignment.right;
765
+ code += ' = ';
766
+ code += yield* rightNode.getNewCompositeCode((0, translator_1.shiftState)(state, code, { inline: true }));
767
+ }
768
+ else {
769
+ const rightNode = assignment.right;
770
+ // 当右边有明确类型时,直接使用其类型。旧版本数据查询不能直接使用其 typeAnnotation
771
+ if (rightNode?.typeAnnotation && !(asserts.isCallQueryComponent(rightNode) && !rightNode.isAutoInfer())) {
772
+ code += ': ';
773
+ code += yield* rightNode.typeAnnotation?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) ??
774
+ (0, time_slicing_1.returnOrigin)('null');
775
+ }
776
+ else {
777
+ code += ' = ';
778
+ let rightCode = '';
779
+ // 因为右侧枚举要赋值就得new 一下;
780
+ if (rightNode &&
781
+ asserts.isIdentifier(rightNode) &&
782
+ rightNode.namespace &&
783
+ rightNode.namespace.endsWith('enums')) {
784
+ rightCode += 'new ';
785
+ }
786
+ rightCode +=
787
+ rightNode && rightNode.toEmbeddedTS
788
+ ? yield* rightNode.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }))
789
+ : '__RIGHT__';
790
+ code += yield* self.getRightCode(rightCode, assignment, rightNode);
791
+ }
792
+ }
793
+ code += ';\n';
794
+ });
795
+ yield* (0, time_slicing_1.wrapIteratorToGenerator)(callFunctionAdvanceMap.entries(), function* warpForEachGenerator([node, assignment]) {
796
+ //
797
+ if (advanceMap.get(node)) {
798
+ return;
799
+ }
800
+ // 有默认值的用默认值来推导类型, 但是如果是__IDENTIFIER__或者__IDENTIFIER__(),就不需要默认值来推导了
801
+ if (node.defaultValue?.expression && !IDENTIFIERMAP.has(node)) {
802
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}let `;
803
+ code += yield* node.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
804
+ return;
805
+ }
806
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}// @ts-ignore\n`;
807
+ yield* (0, time_slicing_1.wrapForEachToGenerator)([
808
+ {
809
+ key: 'key',
810
+ node: assignment.keyOfCollection,
811
+ },
812
+ {
813
+ key: 'item',
814
+ node: assignment.itemOfCollection,
815
+ },
816
+ ], function* warpForEachGenerator({ key, node: itemNode }) {
817
+ if (itemNode) {
818
+ code += `const __${key}_${node?.name} = `;
819
+ const itemCode = yield* itemNode?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) ??
820
+ (0, time_slicing_1.returnOrigin)('');
821
+ code += yield* self.getRightCode(itemCode, assignment, itemNode);
822
+ code += ';\n';
823
+ }
824
+ });
825
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}let `;
826
+ code += yield* node.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
827
+ const nodeName = node?.name;
828
+ const keyNode = assignment.keyOfCollection;
829
+ const itemNode = assignment.itemOfCollection;
830
+ if (assignment.isDerivableMap && keyNode && itemNode) {
831
+ code += `: nasl.collection.Map<typeof __key_${nodeName}, typeof __item_${nodeName}>`;
832
+ }
833
+ else if (assignment.isDerivableList && itemNode) {
834
+ code += `: nasl.collection.List<typeof __item_${nodeName}>;`;
835
+ }
836
+ code += ';\n';
837
+ });
838
+ // 变量提升结束
839
+ delete state.isVariableHost;
840
+ // 参数的默认值是__IDENTIFIER__或者__IDENTIFIER__()时不赋默认值,但是需要ts翻译出来进行报错校验
841
+ if (!hideDefaultValue) {
842
+ for (const node of IDENTIFIERMAP.values()) {
843
+ code += yield* node.defaultValue.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
844
+ code += '; ';
845
+ }
846
+ code += '\n';
847
+ }
848
+ if (!this.body.length && this.returns.length) {
849
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}return ${this.returns[0].name};\n`;
850
+ }
851
+ else {
852
+ // 如果长度小于2 并且不是虚拟节点就 加 报错,
853
+ if (self.body.length <= 2 && !asserts.isNamespace(self.parentNode)) {
854
+ if (self.body.length && self.body[0].concept === 'JavaLogic') {
855
+ code += '';
856
+ }
857
+ else {
858
+ code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
859
+ code += 'const __LogicEmpty: any = null;';
860
+ }
861
+ }
862
+ yield* (0, time_slicing_1.wrapForEachToGenerator)(self.body, function* warpForEachGenerator(item) {
863
+ code += yield* item.toEmbeddedTS?.((0, translator_1.shiftState)(state, code, { tabSize: (state?.tabSize || 0) + 1 })) ??
864
+ (0, time_slicing_1.returnOrigin)('');
865
+ code += ';\n';
866
+ });
867
+ }
868
+ // 在body渲染完成之后把其余的节点放到下面
869
+ yield* (0, time_slicing_1.wrapForEachToGenerator)(self.playground, function* warpForEachGenerator(item) {
870
+ code += yield* item.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
871
+ code += ';\n';
872
+ });
873
+ if (!hideDefaultValue) {
874
+ function* setPlaygroundCode(arr, name) {
875
+ if (arr.length) {
876
+ code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}/* -----以下是 ${name} 的默认值草稿------ */\n`;
877
+ }
878
+ for (const item1 of arr) {
879
+ for (const item of item1.defaultValue?.playground ?? []) {
880
+ code += yield* item.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
881
+ code += ';\n';
882
+ }
883
+ }
884
+ }
885
+ yield* setPlaygroundCode(self.variables, 'variables');
886
+ yield* setPlaygroundCode(self.returns, 'returns');
887
+ yield* setPlaygroundCode(self.params, 'params');
888
+ }
889
+ code += `${(0, translator_1.indent)(state?.tabSize || 0)}}`;
890
+ if (prefix === 'inObject') {
891
+ code += `,`;
892
+ }
893
+ code += '\n';
894
+ return code;
895
+ }
896
+ async saveStructureOfCallQueryComponents(root) {
897
+ if (!root)
898
+ root = this;
899
+ const set = new Set();
900
+ utils.traverse(({ node }) => {
901
+ if (asserts.isCallQueryComponent(node)) {
902
+ set.add(node);
903
+ }
904
+ }, { node: root }, {
905
+ mode: 'anyObject',
906
+ excludedKeySet: new Set(['parentNode', '__assignment__']),
907
+ });
908
+ for (const node of set) {
909
+ node.saveStructure();
910
+ }
911
+ }
912
+ getSubLogics() {
913
+ const subLogics = this.findNaslNodeByBFS((node) => {
914
+ if (asserts.isSubLogic(node)) {
915
+ return true;
916
+ }
917
+ });
918
+ this.subLogics = subLogics;
919
+ }
920
+ genActionListener($event) {
921
+ super.genActionListener($event);
922
+ (0, common_1.invokeCommand)('logic.update', this);
923
+ }
924
+ // 用于展示的名称
925
+ get __name__() {
926
+ const callLogic = this.getAncestor('CallLogic');
927
+ return `${callLogic?.calleeName || ''}_${this.name}`;
928
+ }
929
+ };
930
+ /** 类名 */
931
+ SubLogic.ConceptName = 'SubLogic';
932
+ /**
933
+ * 是否为抽象类
934
+ * 抽象类不能产生 concept: string
935
+ */
936
+ SubLogic.isAbstract = false;
937
+ /** 继承链 */
938
+ SubLogic.inheritanceChain = ['LogicItem', 'BaseNode'];
939
+ __decorate([
940
+ (0, decorators_1.property)('concept')
941
+ ], SubLogic.prototype, "concept", void 0);
942
+ __decorate([
943
+ (0, decorators_1.property)()
944
+ ], SubLogic.prototype, "name", void 0);
945
+ __decorate([
946
+ (0, decorators_1.property)({
947
+ objectRef: 'Param',
948
+ isArray: true,
949
+ defaultValue: [],
950
+ })
951
+ ], SubLogic.prototype, "params", void 0);
952
+ __decorate([
953
+ (0, decorators_1.property)({
954
+ objectRef: 'Return',
955
+ isArray: true,
956
+ defaultValue: [],
957
+ })
958
+ ], SubLogic.prototype, "returns", void 0);
959
+ __decorate([
960
+ (0, decorators_1.property)({
961
+ objectRef: 'Variable',
962
+ isArray: true,
963
+ defaultValue: [],
964
+ })
965
+ ], SubLogic.prototype, "variables", void 0);
966
+ __decorate([
967
+ (0, decorators_1.property)({
968
+ objectRef: 'LogicItem',
969
+ isArray: true,
970
+ defaultValue: [],
971
+ })
972
+ ], SubLogic.prototype, "body", void 0);
973
+ __decorate([
974
+ (0, decorators_1.property)({
975
+ objectRef: 'LogicItem',
976
+ isArray: true,
977
+ defaultValue: [],
978
+ })
979
+ ], SubLogic.prototype, "playground", void 0);
980
+ __decorate([
981
+ translator_1.withSourceMapGenerator
982
+ ], SubLogic.prototype, "toEmbeddedTS", null);
983
+ SubLogic = SubLogic_1 = __decorate([
984
+ (0, decorators_1.concept)('子逻辑')
985
+ ], SubLogic);
986
+ exports.SubLogic = SubLogic;
987
+ exports.default = SubLogic;
988
+ //================================================================================
989
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
990
+ // 自动生成的代码已结束。下面可以手动编写。
991
+ //================================================================================
992
+ //# sourceMappingURL=SubLogic__.js.map