@lcap/nasl 3.2.0-beta.3 → 3.3.0-alpha

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 (842) hide show
  1. package/out/automate/engine/utils.js +4 -0
  2. package/out/automate/engine/utils.js.map +1 -1
  3. package/out/automate/upgrader/2.20.js +1 -1
  4. package/out/automate/upgrader/2.20.js.map +1 -1
  5. package/out/bak/translator.js +11 -15
  6. package/out/bak/translator.js.map +1 -1
  7. package/out/breakpoint/generator/AfterStartNode.js +3 -1
  8. package/out/breakpoint/generator/AfterStartNode.js.map +1 -1
  9. package/out/breakpoint/generator/BeforeEndNode.js.map +1 -1
  10. package/out/breakpoint/generator/BreakpointNode.d.ts +1 -0
  11. package/out/breakpoint/generator/BreakpointNode.js +48 -15
  12. package/out/breakpoint/generator/BreakpointNode.js.map +1 -1
  13. package/out/breakpoint/generator/CallbackNode.d.ts +4 -0
  14. package/out/breakpoint/generator/CallbackNode.js +22 -0
  15. package/out/breakpoint/generator/CallbackNode.js.map +1 -0
  16. package/out/breakpoint/generator/FragmentNode.d.ts +4 -0
  17. package/out/breakpoint/generator/FragmentNode.js +18 -0
  18. package/out/breakpoint/generator/FragmentNode.js.map +1 -0
  19. package/out/breakpoint/generator/index.js +25 -4
  20. package/out/breakpoint/generator/index.js.map +1 -1
  21. package/out/breakpoint/shared/constants.d.ts +3 -0
  22. package/out/breakpoint/shared/constants.js +6 -1
  23. package/out/breakpoint/shared/constants.js.map +1 -1
  24. package/out/breakpoint/shared/operations.js.map +1 -1
  25. package/out/breakpoint/shared/socket.d.ts +1 -1
  26. package/out/breakpoint/shared/socket.js +36 -7
  27. package/out/breakpoint/shared/socket.js.map +1 -1
  28. package/out/breakpoint/shared/utils.d.ts +2 -0
  29. package/out/breakpoint/shared/utils.js +15 -2
  30. package/out/breakpoint/shared/utils.js.map +1 -1
  31. package/out/breakpoint/store/core.d.ts +48 -2
  32. package/out/breakpoint/store/core.js +58 -32
  33. package/out/breakpoint/store/core.js.map +1 -1
  34. package/out/breakpoint/store/dock.js +1 -1
  35. package/out/breakpoint/store/dock.js.map +1 -1
  36. package/out/common/BaseNode.d.ts +2 -2
  37. package/out/common/BaseNode.js +110 -53
  38. package/out/common/BaseNode.js.map +1 -1
  39. package/out/common/Command.d.ts +13 -2
  40. package/out/common/Command.js +37 -9
  41. package/out/common/Command.js.map +1 -1
  42. package/out/common/EventEmitter.js.map +1 -1
  43. package/out/common/Messager.d.ts +3 -3
  44. package/out/common/Messager.js +6 -7
  45. package/out/common/Messager.js.map +1 -1
  46. package/out/common/asyncFuncMap.js.map +1 -1
  47. package/out/concepts/Abort__.js +6 -5
  48. package/out/concepts/Abort__.js.map +1 -1
  49. package/out/concepts/Anchor__.d.ts +4 -3
  50. package/out/concepts/Anchor__.js +24 -7
  51. package/out/concepts/Anchor__.js.map +1 -1
  52. package/out/concepts/AnonymousFunction__.d.ts +22 -21
  53. package/out/concepts/AnonymousFunction__.js +48 -22
  54. package/out/concepts/AnonymousFunction__.js.map +1 -1
  55. package/out/concepts/App__.d.ts +421 -247
  56. package/out/concepts/App__.js +288 -54
  57. package/out/concepts/App__.js.map +1 -1
  58. package/out/concepts/Argument__.d.ts +4 -3
  59. package/out/concepts/Argument__.js +42 -11
  60. package/out/concepts/Argument__.js.map +1 -1
  61. package/out/concepts/Assignee__.d.ts +45 -45
  62. package/out/concepts/Assignee__.js +15 -15
  63. package/out/concepts/Assignee__.js.map +1 -1
  64. package/out/concepts/AssignmentLine__.js +6 -5
  65. package/out/concepts/AssignmentLine__.js.map +1 -1
  66. package/out/concepts/Assignment__.d.ts +7 -6
  67. package/out/concepts/Assignment__.js +41 -23
  68. package/out/concepts/Assignment__.js.map +1 -1
  69. package/out/concepts/Attribute__.d.ts +3 -3
  70. package/out/concepts/Attribute__.js +8 -7
  71. package/out/concepts/Attribute__.js.map +1 -1
  72. package/out/concepts/AuthInterface__.js +4 -3
  73. package/out/concepts/AuthInterface__.js.map +1 -1
  74. package/out/concepts/AuthLogicForCallInterface__.d.ts +15 -15
  75. package/out/concepts/AuthLogicForCallInterface__.js +46 -27
  76. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
  77. package/out/concepts/AuthLogic__.js +27 -13
  78. package/out/concepts/AuthLogic__.js.map +1 -1
  79. package/out/concepts/BackendVariable__.d.ts +5 -5
  80. package/out/concepts/BackendVariable__.js +23 -26
  81. package/out/concepts/BackendVariable__.js.map +1 -1
  82. package/out/concepts/Backend__.d.ts +18 -18
  83. package/out/concepts/Backend__.js +13 -13
  84. package/out/concepts/Backend__.js.map +1 -1
  85. package/out/concepts/BatchAssignment__.d.ts +34 -33
  86. package/out/concepts/BatchAssignment__.js +83 -43
  87. package/out/concepts/BatchAssignment__.js.map +1 -1
  88. package/out/concepts/BinaryExpression__.d.ts +7 -6
  89. package/out/concepts/BinaryExpression__.js +60 -24
  90. package/out/concepts/BinaryExpression__.js.map +1 -1
  91. package/out/concepts/BindAttribute__.d.ts +37 -37
  92. package/out/concepts/BindAttribute__.js +102 -58
  93. package/out/concepts/BindAttribute__.js.map +1 -1
  94. package/out/concepts/BindDirective__.d.ts +13 -13
  95. package/out/concepts/BindDirective__.js +23 -21
  96. package/out/concepts/BindDirective__.js.map +1 -1
  97. package/out/concepts/BindEvent__.d.ts +28 -28
  98. package/out/concepts/BindEvent__.js +150 -57
  99. package/out/concepts/BindEvent__.js.map +1 -1
  100. package/out/concepts/BindStyle__.d.ts +14 -15
  101. package/out/concepts/BindStyle__.js +16 -16
  102. package/out/concepts/BindStyle__.js.map +1 -1
  103. package/out/concepts/BooleanLiteral__.d.ts +1 -0
  104. package/out/concepts/BooleanLiteral__.js +12 -5
  105. package/out/concepts/BooleanLiteral__.js.map +1 -1
  106. package/out/concepts/CallAuthInterface__.d.ts +15 -15
  107. package/out/concepts/CallAuthInterface__.js +23 -22
  108. package/out/concepts/CallAuthInterface__.js.map +1 -1
  109. package/out/concepts/CallConnector__.d.ts +11 -9
  110. package/out/concepts/CallConnector__.js +79 -36
  111. package/out/concepts/CallConnector__.js.map +1 -1
  112. package/out/concepts/CallFunction__.d.ts +17 -16
  113. package/out/concepts/CallFunction__.js +95 -63
  114. package/out/concepts/CallFunction__.js.map +1 -1
  115. package/out/concepts/CallInterface__.d.ts +9 -8
  116. package/out/concepts/CallInterface__.js +109 -80
  117. package/out/concepts/CallInterface__.js.map +1 -1
  118. package/out/concepts/CallLogic__.d.ts +24 -20
  119. package/out/concepts/CallLogic__.js +209 -162
  120. package/out/concepts/CallLogic__.js.map +1 -1
  121. package/out/concepts/CallQueryComponent__.d.ts +51 -51
  122. package/out/concepts/CallQueryComponent__.js +66 -63
  123. package/out/concepts/CallQueryComponent__.js.map +1 -1
  124. package/out/concepts/Comment__.d.ts +1 -0
  125. package/out/concepts/Comment__.js +13 -6
  126. package/out/concepts/Comment__.js.map +1 -1
  127. package/out/concepts/CompletionProperty__.d.ts +3 -3
  128. package/out/concepts/CompletionProperty__.js +16 -8
  129. package/out/concepts/CompletionProperty__.js.map +1 -1
  130. package/out/concepts/ConfigGroup__.d.ts +15 -15
  131. package/out/concepts/ConfigGroup__.js +9 -9
  132. package/out/concepts/ConfigGroup__.js.map +1 -1
  133. package/out/concepts/ConfigPropertyValue__.js +4 -3
  134. package/out/concepts/ConfigPropertyValue__.js.map +1 -1
  135. package/out/concepts/ConfigProperty__.d.ts +15 -15
  136. package/out/concepts/ConfigProperty__.js +10 -10
  137. package/out/concepts/ConfigProperty__.js.map +1 -1
  138. package/out/concepts/Configuration__.d.ts +15 -15
  139. package/out/concepts/Configuration__.js +9 -9
  140. package/out/concepts/Configuration__.js.map +1 -1
  141. package/out/concepts/Connection__.d.ts +166 -0
  142. package/out/concepts/Connection__.js +332 -0
  143. package/out/concepts/Connection__.js.map +1 -0
  144. package/out/concepts/ConnectorTrigger__.js +4 -3
  145. package/out/concepts/ConnectorTrigger__.js.map +1 -1
  146. package/out/concepts/Connector__.d.ts +66 -66
  147. package/out/concepts/Connector__.js +16 -15
  148. package/out/concepts/Connector__.js.map +1 -1
  149. package/out/concepts/Constant__.d.ts +3 -3
  150. package/out/concepts/Constant__.js +8 -7
  151. package/out/concepts/Constant__.js.map +1 -1
  152. package/out/concepts/DataElement__.d.ts +3 -3
  153. package/out/concepts/DataElement__.js +6 -5
  154. package/out/concepts/DataElement__.js.map +1 -1
  155. package/out/concepts/DataSource__.d.ts +15 -15
  156. package/out/concepts/DataSource__.js +55 -39
  157. package/out/concepts/DataSource__.js.map +1 -1
  158. package/out/concepts/DatabaseTypeAnnotation__.js +4 -3
  159. package/out/concepts/DatabaseTypeAnnotation__.js.map +1 -1
  160. package/out/concepts/Destination__.d.ts +12 -11
  161. package/out/concepts/Destination__.js +93 -36
  162. package/out/concepts/Destination__.js.map +1 -1
  163. package/out/concepts/End__.js +15 -13
  164. package/out/concepts/End__.js.map +1 -1
  165. package/out/concepts/EntityIndex__.d.ts +1 -1
  166. package/out/concepts/EntityIndex__.js +6 -5
  167. package/out/concepts/EntityIndex__.js.map +1 -1
  168. package/out/concepts/EntityProperty__.d.ts +8 -7
  169. package/out/concepts/EntityProperty__.js +39 -24
  170. package/out/concepts/EntityProperty__.js.map +1 -1
  171. package/out/concepts/Entity__.d.ts +31 -30
  172. package/out/concepts/Entity__.js +40 -16
  173. package/out/concepts/Entity__.js.map +1 -1
  174. package/out/concepts/EnumItem__.d.ts +1 -0
  175. package/out/concepts/EnumItem__.js +12 -5
  176. package/out/concepts/EnumItem__.js.map +1 -1
  177. package/out/concepts/Enum__.d.ts +9 -8
  178. package/out/concepts/Enum__.js +24 -11
  179. package/out/concepts/Enum__.js.map +1 -1
  180. package/out/concepts/Event__.d.ts +15 -15
  181. package/out/concepts/Event__.js +6 -5
  182. package/out/concepts/Event__.js.map +1 -1
  183. package/out/concepts/ExternalDestination__.d.ts +6 -6
  184. package/out/concepts/ExternalDestination__.js +12 -11
  185. package/out/concepts/ExternalDestination__.js.map +1 -1
  186. package/out/concepts/ForEachStatement__.d.ts +25 -24
  187. package/out/concepts/ForEachStatement__.js +101 -36
  188. package/out/concepts/ForEachStatement__.js.map +1 -1
  189. package/out/concepts/FrontendLibrary__.d.ts +30 -30
  190. package/out/concepts/FrontendLibrary__.js +12 -13
  191. package/out/concepts/FrontendLibrary__.js.map +1 -1
  192. package/out/concepts/FrontendVariable__.js +4 -3
  193. package/out/concepts/FrontendVariable__.js.map +1 -1
  194. package/out/concepts/Frontend__.d.ts +64 -65
  195. package/out/concepts/Frontend__.js +23 -27
  196. package/out/concepts/Frontend__.js.map +1 -1
  197. package/out/concepts/Function__.d.ts +64 -63
  198. package/out/concepts/Function__.js +49 -21
  199. package/out/concepts/Function__.js.map +1 -1
  200. package/out/concepts/Identifier__.js +37 -31
  201. package/out/concepts/Identifier__.js.map +1 -1
  202. package/out/concepts/IfStatement__.d.ts +20 -19
  203. package/out/concepts/IfStatement__.js +64 -34
  204. package/out/concepts/IfStatement__.js.map +1 -1
  205. package/out/concepts/Integration__.d.ts +3 -3
  206. package/out/concepts/Integration__.js +8 -7
  207. package/out/concepts/Integration__.js.map +1 -1
  208. package/out/concepts/InterfaceParam__.d.ts +3 -3
  209. package/out/concepts/InterfaceParam__.js +7 -6
  210. package/out/concepts/InterfaceParam__.js.map +1 -1
  211. package/out/concepts/Interface__.d.ts +33 -33
  212. package/out/concepts/Interface__.js +19 -20
  213. package/out/concepts/Interface__.js.map +1 -1
  214. package/out/concepts/JSBlock__.d.ts +1 -0
  215. package/out/concepts/JSBlock__.js +12 -5
  216. package/out/concepts/JSBlock__.js.map +1 -1
  217. package/out/concepts/JavaLogic__.js +10 -9
  218. package/out/concepts/JavaLogic__.js.map +1 -1
  219. package/out/concepts/LogicItem__.d.ts +6 -0
  220. package/out/concepts/LogicItem__.js +14 -5
  221. package/out/concepts/LogicItem__.js.map +1 -1
  222. package/out/concepts/Logic__.d.ts +80 -79
  223. package/out/concepts/Logic__.js +204 -58
  224. package/out/concepts/Logic__.js.map +1 -1
  225. package/out/concepts/MatchCase__.d.ts +39 -38
  226. package/out/concepts/MatchCase__.js +122 -37
  227. package/out/concepts/MatchCase__.js.map +1 -1
  228. package/out/concepts/Match__.d.ts +13 -11
  229. package/out/concepts/Match__.js +128 -60
  230. package/out/concepts/Match__.js.map +1 -1
  231. package/out/concepts/MemberExpression__.d.ts +7 -6
  232. package/out/concepts/MemberExpression__.js +52 -22
  233. package/out/concepts/MemberExpression__.js.map +1 -1
  234. package/out/concepts/MicroApp__.js +4 -3
  235. package/out/concepts/MicroApp__.js.map +1 -1
  236. package/out/concepts/Module__.d.ts +242 -154
  237. package/out/concepts/Module__.js +139 -33
  238. package/out/concepts/Module__.js.map +1 -1
  239. package/out/concepts/MsgTriggerEvent__.d.ts +15 -15
  240. package/out/concepts/MsgTriggerEvent__.js +6 -5
  241. package/out/concepts/MsgTriggerEvent__.js.map +1 -1
  242. package/out/concepts/MsgTriggerLauncher__.d.ts +23 -15
  243. package/out/concepts/MsgTriggerLauncher__.js +24 -5
  244. package/out/concepts/MsgTriggerLauncher__.js.map +1 -1
  245. package/out/concepts/Namespace__.d.ts +180 -180
  246. package/out/concepts/Namespace__.js +33 -34
  247. package/out/concepts/Namespace__.js.map +1 -1
  248. package/out/concepts/NewComposite__.d.ts +49 -48
  249. package/out/concepts/NewComposite__.js +164 -49
  250. package/out/concepts/NewComposite__.js.map +1 -1
  251. package/out/concepts/NewList__.d.ts +19 -18
  252. package/out/concepts/NewList__.js +29 -12
  253. package/out/concepts/NewList__.js.map +1 -1
  254. package/out/concepts/NewMap__.d.ts +34 -33
  255. package/out/concepts/NewMap__.js +81 -72
  256. package/out/concepts/NewMap__.js.map +1 -1
  257. package/out/concepts/New__.js +6 -5
  258. package/out/concepts/New__.js.map +1 -1
  259. package/out/concepts/NullLiteral__.js +6 -5
  260. package/out/concepts/NullLiteral__.js.map +1 -1
  261. package/out/concepts/NumericLiteral__.d.ts +4 -3
  262. package/out/concepts/NumericLiteral__.js +15 -8
  263. package/out/concepts/NumericLiteral__.js.map +1 -1
  264. package/out/concepts/OqlQueryComponent__.d.ts +4 -3
  265. package/out/concepts/OqlQueryComponent__.js +25 -16
  266. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  267. package/out/concepts/OverriddenLogic__.d.ts +79 -79
  268. package/out/concepts/OverriddenLogic__.js +79 -58
  269. package/out/concepts/OverriddenLogic__.js.map +1 -1
  270. package/out/concepts/Param__.d.ts +6 -5
  271. package/out/concepts/Param__.js +66 -29
  272. package/out/concepts/Param__.js.map +1 -1
  273. package/out/concepts/Point__.js +4 -3
  274. package/out/concepts/Point__.js.map +1 -1
  275. package/out/concepts/ProcessComponent__.d.ts +30 -30
  276. package/out/concepts/ProcessComponent__.js +8 -7
  277. package/out/concepts/ProcessComponent__.js.map +1 -1
  278. package/out/concepts/ProcessElement__.d.ts +96 -96
  279. package/out/concepts/ProcessElement__.js +34 -34
  280. package/out/concepts/ProcessElement__.js.map +1 -1
  281. package/out/concepts/ProcessOutcome__.js +6 -5
  282. package/out/concepts/ProcessOutcome__.js.map +1 -1
  283. package/out/concepts/ProcessOutcomes__.js +6 -5
  284. package/out/concepts/ProcessOutcomes__.js.map +1 -1
  285. package/out/concepts/Process__.d.ts +75 -75
  286. package/out/concepts/Process__.js +33 -30
  287. package/out/concepts/Process__.js.map +1 -1
  288. package/out/concepts/QueryAggregateExpression__.d.ts +3 -3
  289. package/out/concepts/QueryAggregateExpression__.js +8 -7
  290. package/out/concepts/QueryAggregateExpression__.js.map +1 -1
  291. package/out/concepts/QueryFieldExpression__.js +7 -6
  292. package/out/concepts/QueryFieldExpression__.js.map +1 -1
  293. package/out/concepts/QueryFromExpression__.d.ts +8 -8
  294. package/out/concepts/QueryFromExpression__.js +8 -7
  295. package/out/concepts/QueryFromExpression__.js.map +1 -1
  296. package/out/concepts/QueryGroupByExpression__.d.ts +3 -3
  297. package/out/concepts/QueryGroupByExpression__.js +9 -10
  298. package/out/concepts/QueryGroupByExpression__.js.map +1 -1
  299. package/out/concepts/QueryJoinExpression__.d.ts +23 -23
  300. package/out/concepts/QueryJoinExpression__.js +11 -10
  301. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  302. package/out/concepts/QueryLimitExpression__.d.ts +6 -6
  303. package/out/concepts/QueryLimitExpression__.js +9 -8
  304. package/out/concepts/QueryLimitExpression__.js.map +1 -1
  305. package/out/concepts/QueryOrderByExpression__.d.ts +6 -6
  306. package/out/concepts/QueryOrderByExpression__.js +9 -8
  307. package/out/concepts/QueryOrderByExpression__.js.map +1 -1
  308. package/out/concepts/QuerySelectExpression__.d.ts +30 -30
  309. package/out/concepts/QuerySelectExpression__.js +9 -8
  310. package/out/concepts/QuerySelectExpression__.js.map +1 -1
  311. package/out/concepts/Rect__.js +4 -3
  312. package/out/concepts/Rect__.js.map +1 -1
  313. package/out/concepts/Return__.d.ts +4 -3
  314. package/out/concepts/Return__.js +37 -18
  315. package/out/concepts/Return__.js.map +1 -1
  316. package/out/concepts/Role__.js +9 -9
  317. package/out/concepts/Role__.js.map +1 -1
  318. package/out/concepts/SelectMembers__.d.ts +18 -18
  319. package/out/concepts/SelectMembers__.js +10 -9
  320. package/out/concepts/SelectMembers__.js.map +1 -1
  321. package/out/concepts/Slot__.d.ts +3 -3
  322. package/out/concepts/Slot__.js +6 -5
  323. package/out/concepts/Slot__.js.map +1 -1
  324. package/out/concepts/SqlQueryComponent__.d.ts +4 -3
  325. package/out/concepts/SqlQueryComponent__.js +21 -12
  326. package/out/concepts/SqlQueryComponent__.js.map +1 -1
  327. package/out/concepts/Start__.js +6 -5
  328. package/out/concepts/Start__.js.map +1 -1
  329. package/out/concepts/StringInterpolation__.d.ts +16 -15
  330. package/out/concepts/StringInterpolation__.js +37 -14
  331. package/out/concepts/StringInterpolation__.js.map +1 -1
  332. package/out/concepts/StringLiteral__.d.ts +1 -0
  333. package/out/concepts/StringLiteral__.js +13 -8
  334. package/out/concepts/StringLiteral__.js.map +1 -1
  335. package/out/concepts/StructureProperty__.d.ts +4 -3
  336. package/out/concepts/StructureProperty__.js +22 -9
  337. package/out/concepts/StructureProperty__.js.map +1 -1
  338. package/out/concepts/Structure__.d.ts +31 -30
  339. package/out/concepts/Structure__.js +27 -15
  340. package/out/concepts/Structure__.js.map +1 -1
  341. package/out/concepts/SwitchCase__.d.ts +12 -11
  342. package/out/concepts/SwitchCase__.js +69 -31
  343. package/out/concepts/SwitchCase__.js.map +1 -1
  344. package/out/concepts/SwitchStatement__.d.ts +9 -8
  345. package/out/concepts/SwitchStatement__.js +27 -7
  346. package/out/concepts/SwitchStatement__.js.map +1 -1
  347. package/out/concepts/Theme__.js +4 -3
  348. package/out/concepts/Theme__.js.map +1 -1
  349. package/out/concepts/Transactional__.js +4 -3
  350. package/out/concepts/Transactional__.js.map +1 -1
  351. package/out/concepts/TriggerEvent__.d.ts +15 -15
  352. package/out/concepts/TriggerEvent__.js +6 -5
  353. package/out/concepts/TriggerEvent__.js.map +1 -1
  354. package/out/concepts/TriggerLauncher__.d.ts +15 -10
  355. package/out/concepts/TriggerLauncher__.js +54 -32
  356. package/out/concepts/TriggerLauncher__.js.map +1 -1
  357. package/out/concepts/TypeAnnotation__.d.ts +28 -27
  358. package/out/concepts/TypeAnnotation__.js +144 -124
  359. package/out/concepts/TypeAnnotation__.js.map +1 -1
  360. package/out/concepts/TypeParam__.d.ts +1 -0
  361. package/out/concepts/TypeParam__.js +12 -5
  362. package/out/concepts/TypeParam__.js.map +1 -1
  363. package/out/concepts/UnaryExpression__.d.ts +4 -3
  364. package/out/concepts/UnaryExpression__.js +31 -20
  365. package/out/concepts/UnaryExpression__.js.map +1 -1
  366. package/out/concepts/Unparsed__.d.ts +1 -0
  367. package/out/concepts/Unparsed__.js +12 -5
  368. package/out/concepts/Unparsed__.js.map +1 -1
  369. package/out/concepts/UseComponent__.js +4 -3
  370. package/out/concepts/UseComponent__.js.map +1 -1
  371. package/out/concepts/ValidationRule__.d.ts +14 -14
  372. package/out/concepts/ValidationRule__.js +19 -17
  373. package/out/concepts/ValidationRule__.js.map +1 -1
  374. package/out/concepts/Variable__.d.ts +4 -3
  375. package/out/concepts/Variable__.js +39 -23
  376. package/out/concepts/Variable__.js.map +1 -1
  377. package/out/concepts/ViewBlock__.js +4 -3
  378. package/out/concepts/ViewBlock__.js.map +1 -1
  379. package/out/concepts/ViewComponent__.d.ts +90 -90
  380. package/out/concepts/ViewComponent__.js +16 -15
  381. package/out/concepts/ViewComponent__.js.map +1 -1
  382. package/out/concepts/ViewElement__.d.ts +92 -86
  383. package/out/concepts/ViewElement__.js +258 -200
  384. package/out/concepts/ViewElement__.js.map +1 -1
  385. package/out/concepts/View__.d.ts +92 -92
  386. package/out/concepts/View__.js +173 -63
  387. package/out/concepts/View__.js.map +1 -1
  388. package/out/concepts/WhileStatement__.d.ts +12 -11
  389. package/out/concepts/WhileStatement__.js +46 -23
  390. package/out/concepts/WhileStatement__.js.map +1 -1
  391. package/out/concepts/basics/stdlib/index.js +17 -1
  392. package/out/concepts/basics/stdlib/index.js.map +1 -1
  393. package/out/concepts/basics/stdlib/nasl.browser.js +36 -0
  394. package/out/concepts/basics/stdlib/nasl.browser.js.map +1 -1
  395. package/out/concepts/basics/stdlib/nasl.event.d.ts +3 -0
  396. package/out/concepts/basics/stdlib/nasl.event.js +23 -0
  397. package/out/concepts/basics/stdlib/nasl.event.js.map +1 -0
  398. package/out/concepts/basics/stdlib/nasl.ui.js +45 -0
  399. package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
  400. package/out/concepts/basics/stdlib/nasl.util.js +6 -22
  401. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  402. package/out/concepts/index__.d.ts +2 -1
  403. package/out/concepts/index__.js +2 -1
  404. package/out/concepts/index__.js.map +1 -1
  405. package/out/concepts/types__.d.ts +2 -1
  406. package/out/decorators/index.d.ts +1 -1
  407. package/out/decorators/index.js +20 -7
  408. package/out/decorators/index.js.map +1 -1
  409. package/out/decorators/promise.d.ts +7 -0
  410. package/out/decorators/promise.js +28 -0
  411. package/out/decorators/promise.js.map +1 -0
  412. package/out/enums/KEYWORDS.js.map +1 -1
  413. package/out/enums/LEVEL_NAME_MAP.js.map +1 -1
  414. package/out/generator/compileComponent.js.map +1 -1
  415. package/out/generator/genBundleFiles.d.ts +4 -1
  416. package/out/generator/genBundleFiles.js +15 -11
  417. package/out/generator/genBundleFiles.js.map +1 -1
  418. package/out/generator/genHash.js.map +1 -1
  419. package/out/generator/genMetaData.js +12 -8
  420. package/out/generator/genMetaData.js.map +1 -1
  421. package/out/generator/genReleaseBody.js +33 -35
  422. package/out/generator/genReleaseBody.js.map +1 -1
  423. package/out/generator/microApp.js +2 -1
  424. package/out/generator/microApp.js.map +1 -1
  425. package/out/generator/permission.js +31 -30
  426. package/out/generator/permission.js.map +1 -1
  427. package/out/generator/styleReplacer.js +4 -7
  428. package/out/generator/styleReplacer.js.map +1 -1
  429. package/out/index.d.ts +0 -2
  430. package/out/index.js +0 -3
  431. package/out/index.js.map +1 -1
  432. package/out/manager/diagnostic.d.ts +1 -1
  433. package/out/manager/diagnostic.js.map +1 -1
  434. package/out/manager/stepRecorder.js +13 -9
  435. package/out/manager/stepRecorder.js.map +1 -1
  436. package/out/natural/RequirementAnalyzer.d.ts +22 -0
  437. package/out/natural/RequirementAnalyzer.js +196 -0
  438. package/out/natural/RequirementAnalyzer.js.map +1 -0
  439. package/out/natural/RequirementExecutor.d.ts +51 -0
  440. package/out/natural/RequirementExecutor.js +692 -0
  441. package/out/natural/RequirementExecutor.js.map +1 -0
  442. package/out/natural/componentData.d.ts +31 -0
  443. package/out/natural/componentData.js +85 -0
  444. package/out/natural/componentData.js.map +1 -0
  445. package/out/natural/genNaturalTS.d.ts +3 -0
  446. package/out/natural/genNaturalTS.js +76 -0
  447. package/out/natural/genNaturalTS.js.map +1 -0
  448. package/out/natural/index.d.ts +4 -0
  449. package/out/natural/index.js +21 -0
  450. package/out/natural/index.js.map +1 -0
  451. package/out/natural/knowledgeMap.d.ts +4 -0
  452. package/out/natural/knowledgeMap.js +40 -0
  453. package/out/natural/knowledgeMap.js.map +1 -0
  454. package/out/natural/naslStdlibMap.d.ts +2 -0
  455. package/out/natural/naslStdlibMap.js +26 -0
  456. package/out/natural/naslStdlibMap.js.map +1 -0
  457. package/out/natural/transformTSCode.d.ts +7 -0
  458. package/out/natural/transformTSCode.js +760 -0
  459. package/out/natural/transformTSCode.js.map +1 -0
  460. package/out/sentry/index.d.ts +2 -1
  461. package/out/sentry/index.js.map +1 -1
  462. package/out/server/createUiTs.js +28 -16
  463. package/out/server/createUiTs.js.map +1 -1
  464. package/out/server/entity2LogicNamespace.js +24 -22
  465. package/out/server/entity2LogicNamespace.js.map +1 -1
  466. package/out/server/event.d.ts +12 -0
  467. package/out/server/event.js +52 -28
  468. package/out/server/event.js.map +1 -1
  469. package/out/server/extendBaseNode.js +55 -70
  470. package/out/server/extendBaseNode.js.map +1 -1
  471. package/out/server/formatTsUtils.js +46 -50
  472. package/out/server/formatTsUtils.js.map +1 -1
  473. package/out/server/getConnector.d.ts +3 -3
  474. package/out/server/getConnector.js +7 -8
  475. package/out/server/getConnector.js.map +1 -1
  476. package/out/server/getExtensionModules.js +2 -2
  477. package/out/server/getExtensionModules.js.map +1 -1
  478. package/out/server/getFunctions.js.map +1 -1
  479. package/out/server/getInterfaces.js.map +1 -1
  480. package/out/server/getLogging.js.map +1 -1
  481. package/out/server/getLogics.d.ts +1 -1
  482. package/out/server/getLogics.js +55 -8
  483. package/out/server/getLogics.js.map +1 -1
  484. package/out/server/getMemberIdentifier.js +13 -10
  485. package/out/server/getMemberIdentifier.js.map +1 -1
  486. package/out/server/getProcessComponents.js.map +1 -1
  487. package/out/server/getProcesses.js +21 -29
  488. package/out/server/getProcesses.js.map +1 -1
  489. package/out/server/getScope.js.map +1 -1
  490. package/out/server/getValidates.js.map +1 -1
  491. package/out/server/index.js +0 -1
  492. package/out/server/index.js.map +1 -1
  493. package/out/server/naslServer.d.ts +99 -94
  494. package/out/server/naslServer.js +490 -469
  495. package/out/server/naslServer.js.map +1 -1
  496. package/out/server/naslStdlibMap.js +6 -2
  497. package/out/server/naslStdlibMap.js.map +1 -1
  498. package/out/server/process2LogicNamespace.js.map +1 -1
  499. package/out/server/translator.d.ts +1 -1
  500. package/out/server/translator.js +52 -47
  501. package/out/server/translator.js.map +1 -1
  502. package/out/service/storage/init.d.ts +15 -1
  503. package/out/service/storage/init.js +65 -56
  504. package/out/service/storage/init.js.map +1 -1
  505. package/out/templator/genCallComponentLogic.js +1 -2
  506. package/out/templator/genCallComponentLogic.js.map +1 -1
  507. package/out/templator/genCreateBlock.js +14 -9
  508. package/out/templator/genCreateBlock.js.map +1 -1
  509. package/out/templator/genCurdEditMultipleKeyBlock.js +23 -14
  510. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  511. package/out/templator/genCurdMultipleKeyBlock.js +26 -30
  512. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  513. package/out/templator/genEditTableBlock.d.ts +1 -1
  514. package/out/templator/genEditTableBlock.js +14 -19
  515. package/out/templator/genEditTableBlock.js.map +1 -1
  516. package/out/templator/genEnumSelectBlock.js +1 -1
  517. package/out/templator/genEnumSelectBlock.js.map +1 -1
  518. package/out/templator/genGetBlock.js +2 -2
  519. package/out/templator/genGetBlock.js.map +1 -1
  520. package/out/templator/genGridViewBlock.d.ts +2 -2
  521. package/out/templator/genGridViewBlock.js +18 -28
  522. package/out/templator/genGridViewBlock.js.map +1 -1
  523. package/out/templator/genListViewBlock.d.ts +2 -2
  524. package/out/templator/genListViewBlock.js +9 -16
  525. package/out/templator/genListViewBlock.js.map +1 -1
  526. package/out/templator/genQueryComponent.js +22 -15
  527. package/out/templator/genQueryComponent.js.map +1 -1
  528. package/out/templator/genSelectBlock.d.ts +2 -2
  529. package/out/templator/genSelectBlock.js +21 -48
  530. package/out/templator/genSelectBlock.js.map +1 -1
  531. package/out/templator/genTableBlock.d.ts +1 -1
  532. package/out/templator/genTableBlock.js +11 -17
  533. package/out/templator/genTableBlock.js.map +1 -1
  534. package/out/templator/genUpdateBlock.js +13 -8
  535. package/out/templator/genUpdateBlock.js.map +1 -1
  536. package/out/templator/index.d.ts +4 -2
  537. package/out/templator/index.js +2 -2
  538. package/out/templator/index.js.map +1 -1
  539. package/out/templator/utils.d.ts +9 -2
  540. package/out/templator/utils.js +22 -22
  541. package/out/templator/utils.js.map +1 -1
  542. package/out/translator/index.js +27 -28
  543. package/out/translator/index.js.map +1 -1
  544. package/out/utils/index.d.ts +2 -1
  545. package/out/utils/index.js +8 -14
  546. package/out/utils/index.js.map +1 -1
  547. package/out/utils/logger.js.map +1 -1
  548. package/out/utils/sortTsString.js +3 -1
  549. package/out/utils/sortTsString.js.map +1 -1
  550. package/out/utils/string.js +8 -11
  551. package/out/utils/string.js.map +1 -1
  552. package/out/utils/time-slicing.d.ts +41 -0
  553. package/out/utils/time-slicing.js +81 -0
  554. package/out/utils/time-slicing.js.map +1 -0
  555. package/out/utils/traverse.js +4 -6
  556. package/out/utils/traverse.js.map +1 -1
  557. package/package.json +22 -20
  558. package/sandbox/stdlib/nasl.auth.ts +49 -46
  559. package/sandbox/stdlib/nasl.browser.ts +1 -0
  560. package/sandbox/stdlib/nasl.event.ts +4 -0
  561. package/sandbox/stdlib/nasl.http.ts +29 -31
  562. package/sandbox/stdlib/nasl.ui.definition.ts +13 -1
  563. package/sandbox/stdlib/nasl.ui.ts +11 -0
  564. package/sandbox-natural/stdlib/nasl.core.ts +36 -0
  565. package/sandbox-natural/stdlib/nasl.oql.ts +8 -0
  566. package/sandbox-natural/stdlib/nasl.ui.ts +56 -0
  567. package/sandbox-natural/stdlib/nasl.util.ts +26 -0
  568. package/sandbox-natural/tsconfig.json +12 -0
  569. package/src/automate/engine/utils.js +3 -0
  570. package/src/automate/upgrader/2.20.js +1 -1
  571. package/src/bak/translator.js +92 -99
  572. package/src/breakpoint/generator/AfterStartNode.ts +19 -17
  573. package/src/breakpoint/generator/BeforeEndNode.ts +17 -17
  574. package/src/breakpoint/generator/BreakpointNode.ts +243 -195
  575. package/src/breakpoint/generator/CallbackNode.ts +20 -0
  576. package/src/breakpoint/generator/FragmentNode.ts +14 -0
  577. package/src/breakpoint/generator/index.ts +107 -80
  578. package/src/breakpoint/shared/constants.ts +59 -53
  579. package/src/breakpoint/shared/operations.ts +6 -6
  580. package/src/breakpoint/shared/socket.ts +277 -223
  581. package/src/breakpoint/shared/utils.ts +166 -146
  582. package/src/breakpoint/store/core.ts +326 -297
  583. package/src/breakpoint/store/dock.ts +103 -103
  584. package/src/breakpoint/types/index.d.ts +11 -11
  585. package/src/common/BaseNode.ts +1103 -1020
  586. package/src/common/Command.ts +46 -16
  587. package/src/common/ComponentAPI.ts +72 -72
  588. package/src/common/EventEmitter.ts +80 -76
  589. package/src/common/Messager.ts +223 -224
  590. package/src/common/asyncFuncMap.ts +12 -12
  591. package/src/concepts/Abort__.ts +53 -60
  592. package/src/concepts/Anchor__.ts +158 -149
  593. package/src/concepts/AnonymousFunction__.ts +584 -551
  594. package/src/concepts/App__.ts +4278 -3669
  595. package/src/concepts/Argument__.ts +234 -210
  596. package/src/concepts/Assignee__.ts +680 -656
  597. package/src/concepts/AssignmentLine__.ts +80 -84
  598. package/src/concepts/Assignment__.ts +276 -264
  599. package/src/concepts/Attribute__.ts +183 -184
  600. package/src/concepts/AuthInterface__.ts +61 -63
  601. package/src/concepts/AuthLogicForCallInterface__.ts +540 -511
  602. package/src/concepts/AuthLogic__.ts +210 -194
  603. package/src/concepts/BackendVariable__.ts +414 -415
  604. package/src/concepts/Backend__.ts +317 -303
  605. package/src/concepts/BatchAssignment__.ts +987 -939
  606. package/src/concepts/BinaryExpression__.ts +370 -341
  607. package/src/concepts/BindAttribute__.ts +1056 -1011
  608. package/src/concepts/BindDirective__.ts +540 -542
  609. package/src/concepts/BindEvent__.ts +992 -866
  610. package/src/concepts/BindStyle__.ts +442 -451
  611. package/src/concepts/BooleanLiteral__.ts +89 -90
  612. package/src/concepts/CallAuthInterface__.ts +458 -433
  613. package/src/concepts/CallConnector__.ts +209 -164
  614. package/src/concepts/CallFunction__.ts +600 -600
  615. package/src/concepts/CallInterface__.ts +752 -725
  616. package/src/concepts/CallLogic__.ts +1328 -1236
  617. package/src/concepts/CallQueryComponent__.ts +1580 -1501
  618. package/src/concepts/Comment__.ts +69 -68
  619. package/src/concepts/CompletionProperty__.ts +250 -250
  620. package/src/concepts/ConfigGroup__.ts +312 -296
  621. package/src/concepts/ConfigPropertyValue__.ts +81 -82
  622. package/src/concepts/ConfigProperty__.ts +374 -357
  623. package/src/concepts/Configuration__.ts +288 -276
  624. package/src/concepts/Connection__.ts +426 -0
  625. package/src/concepts/ConnectorTrigger__.ts +146 -142
  626. package/src/concepts/Connector__.ts +1090 -1048
  627. package/src/concepts/Constant__.ts +226 -219
  628. package/src/concepts/DataElement__.ts +108 -115
  629. package/src/concepts/DataSource__.ts +508 -472
  630. package/src/concepts/DatabaseTypeAnnotation__.ts +53 -59
  631. package/src/concepts/Destination__.ts +808 -746
  632. package/src/concepts/End__.ts +85 -89
  633. package/src/concepts/EntityIndex__.ts +206 -202
  634. package/src/concepts/EntityProperty__.ts +825 -791
  635. package/src/concepts/Entity__.ts +921 -864
  636. package/src/concepts/EnumItem__.ts +133 -125
  637. package/src/concepts/Enum__.ts +347 -337
  638. package/src/concepts/Event__.ts +305 -292
  639. package/src/concepts/ExternalDestination__.ts +269 -280
  640. package/src/concepts/ForEachStatement__.ts +583 -531
  641. package/src/concepts/FrontendLibrary__.ts +507 -485
  642. package/src/concepts/FrontendVariable__.ts +44 -49
  643. package/src/concepts/Frontend__.ts +1239 -1187
  644. package/src/concepts/Function__.ts +1110 -1045
  645. package/src/concepts/Identifier__.ts +276 -272
  646. package/src/concepts/IfStatement__.ts +467 -436
  647. package/src/concepts/Integration__.ts +136 -137
  648. package/src/concepts/InterfaceParam__.ts +239 -238
  649. package/src/concepts/Interface__.ts +969 -948
  650. package/src/concepts/JSBlock__.ts +83 -83
  651. package/src/concepts/JavaLogic__.ts +101 -106
  652. package/src/concepts/LogicItem__.ts +307 -237
  653. package/src/concepts/Logic__.ts +2301 -2088
  654. package/src/concepts/MatchCase__.ts +886 -779
  655. package/src/concepts/Match__.ts +728 -659
  656. package/src/concepts/MemberExpression__.ts +330 -311
  657. package/src/concepts/MicroApp__.ts +91 -97
  658. package/src/concepts/Module__.ts +2590 -2275
  659. package/src/concepts/MsgTriggerEvent__.ts +297 -281
  660. package/src/concepts/MsgTriggerLauncher__.ts +286 -256
  661. package/src/concepts/Namespace__.ts +2579 -2466
  662. package/src/concepts/NewComposite__.ts +1487 -1350
  663. package/src/concepts/NewList__.ts +464 -450
  664. package/src/concepts/NewMap__.ts +691 -674
  665. package/src/concepts/New__.ts +42 -49
  666. package/src/concepts/NullLiteral__.ts +66 -72
  667. package/src/concepts/NumericLiteral__.ts +169 -169
  668. package/src/concepts/OqlQueryComponent__.ts +282 -279
  669. package/src/concepts/OverriddenLogic__.ts +2142 -2097
  670. package/src/concepts/Param__.ts +500 -442
  671. package/src/concepts/Point__.ts +53 -59
  672. package/src/concepts/ProcessComponent__.ts +497 -475
  673. package/src/concepts/ProcessElement__.ts +1852 -1780
  674. package/src/concepts/ProcessOutcome__.ts +59 -64
  675. package/src/concepts/ProcessOutcomes__.ts +59 -64
  676. package/src/concepts/Process__.ts +1491 -1428
  677. package/src/concepts/QueryAggregateExpression__.ts +135 -142
  678. package/src/concepts/QueryFieldExpression__.ts +138 -142
  679. package/src/concepts/QueryFromExpression__.ts +246 -254
  680. package/src/concepts/QueryGroupByExpression__.ts +130 -136
  681. package/src/concepts/QueryJoinExpression__.ts +441 -438
  682. package/src/concepts/QueryLimitExpression__.ts +159 -166
  683. package/src/concepts/QueryOrderByExpression__.ts +173 -180
  684. package/src/concepts/QuerySelectExpression__.ts +464 -439
  685. package/src/concepts/Rect__.ts +73 -79
  686. package/src/concepts/Return__.ts +366 -345
  687. package/src/concepts/Role__.ts +146 -147
  688. package/src/concepts/SelectMembers__.ts +358 -350
  689. package/src/concepts/Slot__.ts +152 -153
  690. package/src/concepts/SqlQueryComponent__.ts +230 -228
  691. package/src/concepts/Start__.ts +45 -52
  692. package/src/concepts/StringInterpolation__.ts +323 -296
  693. package/src/concepts/StringLiteral__.ts +113 -115
  694. package/src/concepts/StructureProperty__.ts +306 -295
  695. package/src/concepts/Structure__.ts +615 -578
  696. package/src/concepts/SwitchCase__.ts +326 -290
  697. package/src/concepts/SwitchStatement__.ts +236 -229
  698. package/src/concepts/Theme__.ts +64 -68
  699. package/src/concepts/Transactional__.ts +159 -153
  700. package/src/concepts/TriggerEvent__.ts +285 -274
  701. package/src/concepts/TriggerLauncher__.ts +232 -196
  702. package/src/concepts/TypeAnnotation__.ts +1049 -1011
  703. package/src/concepts/TypeParam__.ts +48 -50
  704. package/src/concepts/UnaryExpression__.ts +163 -153
  705. package/src/concepts/Unparsed__.ts +81 -82
  706. package/src/concepts/UseComponent__.ts +53 -59
  707. package/src/concepts/ValidationRule__.ts +524 -544
  708. package/src/concepts/Variable__.ts +419 -397
  709. package/src/concepts/ViewBlock__.ts +58 -64
  710. package/src/concepts/ViewComponent__.ts +1323 -1261
  711. package/src/concepts/ViewElement__.ts +2537 -2351
  712. package/src/concepts/View__.ts +2461 -2245
  713. package/src/concepts/WhileStatement__.ts +293 -272
  714. package/src/concepts/basics/stdlib/index.ts +17 -1
  715. package/src/concepts/basics/stdlib/nasl.browser.ts +36 -0
  716. package/src/concepts/basics/stdlib/nasl.event.ts +18 -0
  717. package/src/concepts/basics/stdlib/nasl.ui.ts +45 -0
  718. package/src/concepts/basics/stdlib/nasl.util.ts +6 -22
  719. package/src/concepts/index__.ts +2 -1
  720. package/src/concepts/types__.ts +123 -121
  721. package/src/decorators/index.ts +75 -77
  722. package/src/decorators/promise.ts +28 -0
  723. package/src/enums/KEYWORDS.ts +1228 -1228
  724. package/src/enums/LEVEL_NAME_MAP.ts +24 -24
  725. package/src/generator/compileComponent.ts +10 -10
  726. package/src/generator/genBundleFiles.ts +300 -291
  727. package/src/generator/genHash.ts +2 -2
  728. package/src/generator/genMetaData.ts +280 -261
  729. package/src/generator/genReleaseBody.ts +312 -291
  730. package/src/generator/icestark.ts +1 -1
  731. package/src/generator/microApp.ts +17 -20
  732. package/src/generator/permission.ts +241 -232
  733. package/src/generator/qiankun.ts +1 -1
  734. package/src/generator/styleReplacer.ts +28 -31
  735. package/src/index.ts +0 -3
  736. package/src/manager/diagnostic.ts +84 -82
  737. package/src/manager/stepRecorder.ts +106 -94
  738. package/src/natural/RequirementAnalyzer.ts +208 -0
  739. package/src/natural/RequirementExecutor.ts +685 -0
  740. package/src/natural/componentData.ts +81 -0
  741. package/src/natural/genNaturalTS.ts +77 -0
  742. package/src/natural/index.ts +4 -0
  743. package/src/natural/knowledgeMap.ts +39 -0
  744. package/src/natural/naslStdlibMap.ts +24 -0
  745. package/src/natural/transformTSCode.ts +692 -0
  746. package/src/sentry/index.ts +109 -104
  747. package/src/server/createUiTs.ts +190 -184
  748. package/src/server/entity2LogicNamespace.ts +379 -359
  749. package/src/server/event.js +145 -121
  750. package/src/server/extendBaseNode.ts +461 -456
  751. package/src/server/formatTsUtils.ts +712 -713
  752. package/src/server/getConnector.ts +33 -33
  753. package/src/server/getExtensionModules.ts +23 -22
  754. package/src/server/getFunctions.ts +6 -6
  755. package/src/server/getInterfaces.ts +38 -37
  756. package/src/server/getLogging.ts +1 -1
  757. package/src/server/getLogics.ts +391 -312
  758. package/src/server/getMemberIdentifier.ts +286 -281
  759. package/src/server/getProcessComponents.ts +2 -2
  760. package/src/server/getProcesses.ts +548 -534
  761. package/src/server/getScope.ts +51 -51
  762. package/src/server/getValidates.ts +3 -3
  763. package/src/server/index.ts +29 -30
  764. package/src/server/naslServer.ts +4303 -4222
  765. package/src/server/naslStdlibMap.ts +43 -39
  766. package/src/server/process2LogicNamespace.ts +97 -97
  767. package/src/server/translator.ts +740 -746
  768. package/src/service/storage/init.ts +761 -728
  769. package/src/templator/genCallComponentLogic.ts +14 -15
  770. package/src/templator/genCreateBlock.ts +257 -229
  771. package/src/templator/genCurdEditMultipleKeyBlock.ts +333 -317
  772. package/src/templator/genCurdMultipleKeyBlock.ts +503 -475
  773. package/src/templator/genEditTableBlock.ts +194 -187
  774. package/src/templator/genEnumSelectBlock.ts +13 -7
  775. package/src/templator/genGetBlock.ts +57 -55
  776. package/src/templator/genGridViewBlock.ts +195 -211
  777. package/src/templator/genListViewBlock.ts +62 -72
  778. package/src/templator/genQueryComponent.ts +337 -287
  779. package/src/templator/genSelectBlock.ts +283 -297
  780. package/src/templator/genTableBlock.ts +160 -166
  781. package/src/templator/genUpdateBlock.ts +269 -255
  782. package/src/templator/index.ts +4 -4
  783. package/src/templator/utils.ts +491 -463
  784. package/src/translator/index.ts +84 -84
  785. package/src/translator/lsp.ts +22 -22
  786. package/src/translator/tsp.ts +6 -6
  787. package/src/utils/index.ts +115 -117
  788. package/src/utils/logger.ts +3 -4
  789. package/src/utils/sortTsString.ts +34 -32
  790. package/src/utils/string.ts +47 -48
  791. package/src/utils/time-slicing.ts +109 -0
  792. package/src/utils/traverse.ts +114 -126
  793. package/test/concepts/call-interface/__snapshots__/toEmbeddedTS.spec.ts.snap +71 -0
  794. package/test/concepts/call-interface/__snapshots__/toJS.spec.ts.snap +140 -0
  795. package/test/concepts/call-interface/constant.ts +5 -0
  796. package/test/concepts/call-interface/fixtures/only-interface.json +158 -0
  797. package/test/concepts/call-interface/fixtures/with-body-complex-argument.json +455 -0
  798. package/test/concepts/call-interface/fixtures/with-body-no-argument.json +187 -0
  799. package/test/concepts/call-interface/fixtures/with-body-simple-argument.json +225 -0
  800. package/test/concepts/call-interface/fixtures/with-headers-no-argument.json +213 -0
  801. package/test/concepts/call-interface/fixtures/with-headers.json +192 -0
  802. package/test/concepts/call-interface/fixtures/with-query-no-argument.json +213 -0
  803. package/test/concepts/call-interface/fixtures/with-query.json +192 -0
  804. package/test/concepts/call-interface/toEmbeddedTS.spec.ts +14 -0
  805. package/test/concepts/call-interface/toJS.spec.ts +14 -0
  806. package/test/concepts/call-logic/__snapshots__/toEmbeddedTS.spec.ts.snap +74 -0
  807. package/test/concepts/call-logic/__snapshots__/toJS.spec.ts.snap +141 -0
  808. package/test/concepts/call-logic/constant.ts +5 -0
  809. package/test/concepts/call-logic/fixtures/entries-get-with-arguments.json +223 -0
  810. package/test/concepts/call-logic/fixtures/entries-update-with-arguments.json +359 -0
  811. package/test/concepts/call-logic/fixtures/global-logic-argument-no-expression.json +209 -0
  812. package/test/concepts/call-logic/fixtures/global-logic-argument-some-expression.json +311 -0
  813. package/test/concepts/call-logic/fixtures/only-call-logic.json +10 -0
  814. package/test/concepts/call-logic/fixtures/view-buildin-logic-with-argument.json +128 -0
  815. package/test/concepts/call-logic/fixtures/view-component-logic-no-argument.json +126 -0
  816. package/test/concepts/call-logic/fixtures/view-component-with-validation.json +244 -0
  817. package/test/concepts/call-logic/toEmbeddedTS.spec.ts +14 -0
  818. package/test/concepts/call-logic/toJS.spec.ts +14 -0
  819. package/test/concepts/match/__snapshots__/toEmbeddedTS.spec.ts.snap +66 -0
  820. package/test/concepts/match/__snapshots__/toJS.spec.ts.snap +40 -0
  821. package/test/concepts/match/constant.ts +5 -0
  822. package/test/concepts/match/fixtures/isExpression.json +259 -0
  823. package/test/concepts/match/fixtures/lastBodyIf.json +268 -0
  824. package/test/concepts/match/fixtures/noExpression.json +176 -0
  825. package/test/concepts/match/toEmbeddedTS.spec.ts +14 -0
  826. package/test/concepts/match/toJS.spec.ts +14 -0
  827. package/test/concepts/utils.ts +76 -3
  828. package/test/concepts/validation-rule/__snapshots__/toEmbeddedTS.spec.ts.snap +3 -3
  829. package/test/concepts/validation-rule/__snapshots__/toJS.spec.ts.snap +16 -0
  830. package/test/concepts/validation-rule/constant.ts +5 -0
  831. package/test/concepts/validation-rule/toEmbeddedTS.spec.ts +10 -17
  832. package/test/concepts/validation-rule/toJS.spec.ts +14 -0
  833. package/test/concepts/view-element/__snapshots__/toEmbeddedTS.spec.ts.snap +68 -0
  834. package/test/concepts/view-element/__snapshots__/toVue.spec.ts.snap +44 -0
  835. package/test/concepts/view-element/constant.ts +5 -0
  836. package/test/concepts/view-element/fixtures/default-not-found.json +322 -0
  837. package/test/concepts/view-element/toEmbeddedTS.spec.ts +14 -0
  838. package/test/concepts/view-element/toVue.spec.ts +14 -0
  839. package/test/setup.ts +7 -0
  840. package/ts-worker/src/index.js +0 -2
  841. package/tsconfig.json +21 -21
  842. package/bin/naslc +0 -3
@@ -1,3 +1,4 @@
1
+ import { v4 as uuidv4 } from 'uuid';
1
2
  import { FrontendLibrary } from './FrontendLibrary__';
2
3
  import { TranslatorState, shiftState, withSourceMap, indent, createCompilerState, embeddedTSEmitter } from '../translator';
3
4
  import Namespace from './Namespace__';
@@ -13,17 +14,17 @@ import MatchCase from './MatchCase__';
13
14
  import TypeAnnotation from './TypeAnnotation__';
14
15
  import CallInterface from './CallInterface__';
15
16
  import CallLogic from './CallLogic__';
17
+ import ViewElement from './ViewElement__';
16
18
  import { SynatxNode } from './types__';
17
19
 
18
- //================================================================================
20
+ //= ===============================================================================
19
21
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
20
22
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
21
- //================================================================================
23
+ //= ===============================================================================
22
24
  import { EventPayload, Params } from '../common/EventEmitter';
23
25
  import { concept, excludedInJSON, property } from '../decorators';
24
26
 
25
27
  import * as utils from '../utils';
26
- import { v4 as uuidv4 } from 'uuid';
27
28
  import BaseNode from '../common/BaseNode';
28
29
  import classMap from '../common/classMap';
29
30
  import Transactional from './Transactional__';
@@ -45,2120 +46,2332 @@ import Process from './Process__';
45
46
  */
46
47
  @concept('逻辑')
47
48
  export class Logic extends BaseNode {
48
- /**
49
- * 产品概念
50
- */
51
- @property()
52
- concept: 'Logic' | 'AuthLogic' | 'AuthLogicForCallInterface' = 'Logic';
53
-
54
- /**
55
- * 逻辑名称
56
- */
57
- @property()
58
- name: string = undefined;
59
-
60
- /**
61
- * 逻辑描述
62
- */
63
- @property()
64
- description: string = undefined;
65
-
66
- /**
67
- * triggerType
68
- */
69
- @property()
70
- triggerType: string = undefined;
71
-
72
- /**
73
- * cron
74
- */
75
- @property()
76
- cron: string = undefined;
77
-
78
- /**
79
- * overridable
80
- */
81
- @property()
82
- overridable: boolean = undefined;
83
-
84
- /**
85
- * 事务
86
- */
87
- @property('Transactional')
88
- transactional: Transactional = undefined;
89
-
90
- /**
91
- * 编译器信息
92
- */
93
- @property()
94
- compilerInfoMap: { java?: { packageName: string, className: string } } = undefined;
95
-
96
- /**
97
- * 类型参数列表
98
- */
99
- @property('TypeParam')
100
- typeParams: Array<TypeParam> = null;
101
-
102
- /**
103
- * 输入参数列表
104
- */
105
- @property('Param')
106
- params: Array<Param> = [];
107
-
108
- /**
109
- * 输出参数列表
110
- */
111
- @property('Return')
112
- returns: Array<Return> = [];
113
-
114
- /**
115
- * 变量列表
116
- */
117
- @property('Variable')
118
- variables: Array<Variable> = [];
119
-
120
- /**
121
- * 逻辑项列表
122
- */
123
- @property('LogicItem')
124
- body: Array<LogicItem> = [];
125
-
126
- /**
127
- * 逻辑项列表
128
- */
129
- @property('LogicItem')
130
- playground: Array<LogicItem> = [];
131
-
132
- /**
133
- * 祖先 Module
134
- */
135
- get module() {
136
- return this.getAncestor('Module') as Module;
137
- }
138
- /**
139
- * 祖先 App
140
- */
141
- get app() {
142
- return this.getAncestor('App') as App;
143
- }
144
- /**
145
- * 祖先 Connector
146
- */
147
- get connector() {
148
- return this.getAncestor('Connector') as Connector;
149
- }
150
- /**
151
- * 祖先 View
152
- */
153
- get view() {
154
- return this.getAncestor('View') as View;
155
- }
156
- /**
157
- * 祖先 Frontend
158
- */
159
- get frontend() {
160
- return this.getAncestor('Frontend') as Frontend;
161
- }
162
- /**
163
- * 祖先 ProcessElement
164
- */
165
- get processElement() {
166
- return this.getAncestor('ProcessElement') as ProcessElement;
167
- }
168
- /**
169
- * 祖先 Process
170
- */
171
- get process() {
172
- return this.getAncestor('Process') as Process;
173
- }
174
-
175
- /**
176
- * @param source 需要合并的部分参数
177
- */
178
- constructor(source?: Partial<Logic>) {
179
- source = Object.assign({}, Logic.getDefaultOptions(), source);
180
- super(source);
181
- super.subConstructor(source);
182
- }
183
- getClassName() {
184
- return 'Logic';
185
- }
186
-
187
- static from(source: any, parentNode?: any, parentKey?: string): Logic {
188
- return super.from(source, parentNode, parentKey) as Logic;
189
- }
190
-
191
- /**
192
- * 从父级删除该节点
193
- * @internal
194
- */
195
- _delete() {
196
- let params: Params = null;
197
- if (this.parentNode) {
198
- params = (this.parentNode as any)?.__removeLogic?.(this);
49
+ /**
50
+ * 产品概念
51
+ */
52
+ @property()
53
+ concept: 'Logic' | 'AuthLogic' | 'AuthLogicForCallInterface' = 'Logic';
54
+
55
+ /**
56
+ * 逻辑名称
57
+ */
58
+ @property()
59
+ name: string = undefined;
60
+
61
+ /**
62
+ * 逻辑描述
63
+ */
64
+ @property()
65
+ description: string = undefined;
66
+
67
+ /**
68
+ * triggerType
69
+ */
70
+ @property()
71
+ triggerType: string = undefined;
72
+
73
+ /**
74
+ * cron
75
+ */
76
+ @property()
77
+ cron: string = undefined;
78
+
79
+ /**
80
+ * overridable
81
+ */
82
+ @property()
83
+ overridable: boolean = undefined;
84
+
85
+ /**
86
+ * 事务
87
+ */
88
+ @property('Transactional')
89
+ transactional: Transactional = undefined;
90
+
91
+ /**
92
+ * 编译器信息
93
+ */
94
+ @property()
95
+ compilerInfoMap: { java?: { packageName: string; className: string } } = undefined;
96
+
97
+ /**
98
+ * 类型参数列表
99
+ */
100
+ @property('TypeParam')
101
+ typeParams: Array<TypeParam> = null;
102
+
103
+ /**
104
+ * 输入参数列表
105
+ */
106
+ @property('Param')
107
+ params: Array<Param> = [];
108
+
109
+ /**
110
+ * 输出参数列表
111
+ */
112
+ @property('Return')
113
+ returns: Array<Return> = [];
114
+
115
+ /**
116
+ * 变量列表
117
+ */
118
+ @property('Variable')
119
+ variables: Array<Variable> = [];
120
+
121
+ /**
122
+ * 逻辑项列表
123
+ */
124
+ @property('LogicItem')
125
+ body: Array<LogicItem> = [];
126
+
127
+ /**
128
+ * 逻辑项列表
129
+ */
130
+ @property('LogicItem')
131
+ playground: Array<LogicItem> = [];
132
+
133
+ /**
134
+ * 祖先 Module
135
+ */
136
+ get module() {
137
+ return this.getAncestor('Module') as Module;
138
+ }
139
+
140
+ /**
141
+ * 祖先 App
142
+ */
143
+ get app() {
144
+ return this.getAncestor('App') as App;
145
+ }
146
+
147
+ /**
148
+ * 祖先 Connector
149
+ */
150
+ get connector() {
151
+ return this.getAncestor('Connector') as Connector;
152
+ }
153
+
154
+ /**
155
+ * 祖先 View
156
+ */
157
+ get view() {
158
+ return this.getAncestor('View') as View;
159
+ }
160
+
161
+ /**
162
+ * 祖先 Frontend
163
+ */
164
+ get frontend() {
165
+ return this.getAncestor('Frontend') as Frontend;
166
+ }
167
+
168
+ /**
169
+ * 祖先 ProcessElement
170
+ */
171
+ get processElement() {
172
+ return this.getAncestor('ProcessElement') as ProcessElement;
173
+ }
174
+
175
+ /**
176
+ * 祖先 Process
177
+ */
178
+ get process() {
179
+ return this.getAncestor('Process') as Process;
180
+ }
181
+
182
+ /**
183
+ * @param source 需要合并的部分参数
184
+ */
185
+ constructor(source?: Partial<Logic>) {
186
+ // @ts-ignore
187
+ source = { ...Logic.getDefaultOptions(), ...source };
188
+ super(source);
189
+ super.subConstructor(source);
190
+ }
191
+
192
+ getClassName() {
193
+ return 'Logic';
194
+ }
195
+
196
+ static from(source: any, parentNode?: any, parentKey?: string): Logic {
197
+ return super.from(source, parentNode, parentKey) as Logic;
198
+ }
199
+
200
+ /**
201
+ * 从父级删除该节点
202
+ * @internal
203
+ */
204
+ _delete() {
205
+ let params: Params = null;
206
+ if (this.parentNode) {
207
+ params = (this.parentNode as any)?.__removeLogic?.(this);
208
+ }
209
+ return params;
210
+ }
211
+
212
+ /**
213
+ * 设置逻辑名称
214
+ */
215
+ setName(name: string) {
216
+ const object = {
217
+ name,
218
+ };
219
+ this.update({
220
+ ...object,
221
+ field: 'name',
222
+ });
223
+ }
224
+
225
+ /**
226
+ * 设置逻辑描述
227
+ */
228
+ setDescription(description: string) {
229
+ const object = {
230
+ description,
231
+ };
232
+ this.update({
233
+ ...object,
234
+ });
235
+ }
236
+
237
+ /**
238
+ * 设置triggerType
239
+ */
240
+ setTriggerType(triggerType: string) {
241
+ const object = {
242
+ triggerType,
243
+ };
244
+ this.update({
245
+ ...object,
246
+ });
247
+ }
248
+
249
+ /**
250
+ * 设置cron
251
+ */
252
+ setCron(cron: string) {
253
+ const object = {
254
+ cron,
255
+ };
256
+ this.update({
257
+ ...object,
258
+ });
259
+ }
260
+
261
+ /**
262
+ * 设置overridable
263
+ */
264
+ setOverridable(overridable: boolean) {
265
+ const object = {
266
+ overridable,
267
+ };
268
+ this.update({
269
+ ...object,
270
+ });
271
+ }
272
+
273
+ /**
274
+ * 设置事务
275
+ */
276
+ setTransactional(transactional: Transactional) {
277
+ transactional._delete();
278
+ const relationOptions = { parentNode: this, parentKey: 'transactional' };
279
+ Object.assign(transactional, relationOptions);
280
+ const object = {
281
+ transactional,
282
+ };
283
+ this.update({
284
+ ...object,
285
+ });
286
+ }
287
+
288
+ getTypeParamExistingNames(excludedList: Array<TypeParam> = []) {
289
+ const excludedSet = new Set(excludedList);
290
+ return ((this.typeParams as TypeParam[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
291
+ }
292
+
293
+ getTypeParamUniqueName(name = 'typeParam1') {
294
+ return utils.unique(name, this.getTypeParamExistingNames(), undefined, false);
295
+ }
296
+
297
+ /**
298
+ * 插入类型参数
299
+ * @internal
300
+ * @param name 类型参数名称,如果不填会自动生成一个唯一名称
301
+ */
302
+ _insertTypeParamAt(name: string, index: number): TypeParam;
303
+
304
+ /**
305
+ * 插入类型参数
306
+ * @internal
307
+ * @param typeParamOptions 类型参数参数
308
+ */
309
+ _insertTypeParamAt(typeParamOptions: Partial<TypeParam>, index: number): TypeParam;
310
+
311
+ /**
312
+ * 插入类型参数
313
+ * @internal
314
+ * @param typeParam 已有的类型参数实例
315
+ */
316
+ _insertTypeParamAt(typeParam: TypeParam, index: number): TypeParam;
317
+
318
+ _insertTypeParamAt(options: string | Partial<TypeParam> | TypeParam, index: number) {
319
+ const typeParamOptions: any = {};
320
+ const relationOptions = { parentNode: this, parentKey: 'typeParams' };
321
+ let typeParam: TypeParam;
322
+ if (!options) {
323
+ typeParam = TypeParam.from(
324
+ {
325
+ ...typeParamOptions,
326
+ name: this.getTypeParamUniqueName(),
327
+ },
328
+ this,
329
+ 'typeParams'
330
+ );
331
+ } else if (typeof options === 'string') {
332
+ typeParam = TypeParam.from(
333
+ {
334
+ ...typeParamOptions,
335
+ name: options,
336
+ },
337
+ this,
338
+ 'typeParams'
339
+ );
340
+ } else if (options instanceof TypeParam) {
341
+ options.ensureDelete(); // 同一实例不支持多处存在
342
+ typeParam = options;
343
+ Object.assign(typeParam, relationOptions);
344
+ } else {
345
+ typeParam = TypeParam.from(
346
+ {
347
+ ...typeParamOptions,
348
+ ...options,
349
+ },
350
+ this,
351
+ 'typeParams'
352
+ );
353
+ }
354
+ this.typeParams.splice(index, 0, typeParam);
355
+ return typeParam;
356
+ }
357
+
358
+ /**
359
+ * 插入类型参数
360
+ * @param name 类型参数名称,如果不填会自动生成一个唯一名称
361
+ */
362
+ insertTypeParamAt(name: string, index: number): TypeParam;
363
+
364
+ /**
365
+ * 插入类型参数
366
+ * @param typeParamOptions 类型参数参数
367
+ */
368
+ insertTypeParamAt(typeParamOptions: Partial<TypeParam>, index: number): TypeParam;
369
+
370
+ /**
371
+ * 插入类型参数
372
+ * @param typeParam 已有的类型参数实例
373
+ */
374
+ insertTypeParamAt(typeParam: TypeParam, index: number): TypeParam;
375
+
376
+ insertTypeParamAt(options: string | Partial<TypeParam> | TypeParam, index: number) {
377
+ const node = this._insertTypeParamAt(options as any, index);
378
+ node.create({
379
+ index,
380
+ parentNode: this,
381
+ parentKey: 'typeParams',
382
+ });
383
+ return node;
384
+ }
385
+
386
+ /**
387
+ * 添加类型参数
388
+ * @internal
389
+ * @param name 类型参数名称,如果不填会自动生成一个唯一名称
390
+ */
391
+ _addTypeParam(name?: string): TypeParam;
392
+
393
+ /**
394
+ * 添加类型参数
395
+ * @internal
396
+ * @param typeParamOptions 类型参数参数
397
+ */
398
+ _addTypeParam(typeParamOptions: Partial<TypeParam>): TypeParam;
399
+
400
+ /**
401
+ * 添加类型参数
402
+ * @internal
403
+ * @param typeParam 已有的类型参数实例
404
+ */
405
+ _addTypeParam(typeParam: TypeParam): TypeParam;
406
+
407
+ _addTypeParam(options?: string | Partial<TypeParam> | TypeParam) {
408
+ const index = this.typeParams.length;
409
+ return this._insertTypeParamAt(options as any, index);
410
+ }
411
+
412
+ /**
413
+ * 添加类型参数
414
+ * @internal
415
+ * @param name 类型参数名称,如果不填会自动生成一个唯一名称
416
+ */
417
+ addTypeParam(name?: string): TypeParam;
418
+
419
+ /**
420
+ * 添加类型参数
421
+ * @param typeParamOptions 类型参数参数
422
+ */
423
+ addTypeParam(typeParamOptions: Partial<TypeParam>): TypeParam;
424
+
425
+ /**
426
+ * 添加类型参数
427
+ * @param typeParam 已有的类型参数实例
428
+ */
429
+ addTypeParam(typeParam: TypeParam): TypeParam;
430
+
431
+ addTypeParam(options?: string | Partial<TypeParam> | TypeParam) {
432
+ const node = this._addTypeParam(options as any);
433
+ const index = this.typeParams.indexOf(node);
434
+ node.create({
435
+ index,
436
+ parentNode: this,
437
+ parentKey: 'typeParams',
438
+ });
439
+ return node;
440
+ }
441
+
442
+ getParamUniqueName(name = 'param1') {
443
+ return utils.unique(name, this.getVarExistingNames(), undefined, false);
444
+ }
445
+
446
+ /**
447
+ * 插入输入参数
448
+ * @internal
449
+ * @param name 输入参数名称,如果不填会自动生成一个唯一名称
450
+ */
451
+ _insertParamAt(name: string, index: number): Param;
452
+
453
+ /**
454
+ * 插入输入参数
455
+ * @internal
456
+ * @param paramOptions 输入参数参数
457
+ */
458
+ _insertParamAt(paramOptions: Partial<Param>, index: number): Param;
459
+
460
+ /**
461
+ * 插入输入参数
462
+ * @internal
463
+ * @param param 已有的输入参数实例
464
+ */
465
+ _insertParamAt(param: Param, index: number): Param;
466
+
467
+ _insertParamAt(options: string | Partial<Param> | Param, index: number) {
468
+ const paramOptions: any = {};
469
+ const relationOptions = { parentNode: this, parentKey: 'params' };
470
+ let param: Param;
471
+ if (!options) {
472
+ param = Param.from(
473
+ {
474
+ ...paramOptions,
475
+ name: this.getParamUniqueName(),
476
+ },
477
+ this,
478
+ 'params'
479
+ );
480
+ } else if (typeof options === 'string') {
481
+ param = Param.from(
482
+ {
483
+ ...paramOptions,
484
+ name: options,
485
+ },
486
+ this,
487
+ 'params'
488
+ );
489
+ } else if (options instanceof Param) {
490
+ options.ensureDelete(); // 同一实例不支持多处存在
491
+ param = options;
492
+ Object.assign(param, relationOptions);
493
+ } else {
494
+ param = Param.from(
495
+ {
496
+ ...paramOptions,
497
+ ...options,
498
+ },
499
+ this,
500
+ 'params'
501
+ );
502
+ }
503
+ this.params.splice(index, 0, param);
504
+ return param;
505
+ }
506
+
507
+ /**
508
+ * 插入输入参数
509
+ * @param name 输入参数名称,如果不填会自动生成一个唯一名称
510
+ */
511
+ insertParamAt(name: string, index: number): Param;
512
+
513
+ /**
514
+ * 插入输入参数
515
+ * @param paramOptions 输入参数参数
516
+ */
517
+ insertParamAt(paramOptions: Partial<Param>, index: number): Param;
518
+
519
+ /**
520
+ * 插入输入参数
521
+ * @param param 已有的输入参数实例
522
+ */
523
+ insertParamAt(param: Param, index: number): Param;
524
+
525
+ insertParamAt(options: string | Partial<Param> | Param, index: number) {
526
+ const node = this._insertParamAt(options as any, index);
527
+ node.create({
528
+ index,
529
+ parentNode: this,
530
+ parentKey: 'params',
531
+ });
532
+ return node;
533
+ }
534
+
535
+ /**
536
+ * 添加输入参数
537
+ * @internal
538
+ * @param name 输入参数名称,如果不填会自动生成一个唯一名称
539
+ */
540
+ _addParam(name?: string): Param;
541
+
542
+ /**
543
+ * 添加输入参数
544
+ * @internal
545
+ * @param paramOptions 输入参数参数
546
+ */
547
+ _addParam(paramOptions: Partial<Param>): Param;
548
+
549
+ /**
550
+ * 添加输入参数
551
+ * @internal
552
+ * @param param 已有的输入参数实例
553
+ */
554
+ _addParam(param: Param): Param;
555
+
556
+ _addParam(options?: string | Partial<Param> | Param) {
557
+ const index = this.params.length;
558
+ return this._insertParamAt(options as any, index);
559
+ }
560
+
561
+ /**
562
+ * 添加输入参数
563
+ * @internal
564
+ * @param name 输入参数名称,如果不填会自动生成一个唯一名称
565
+ */
566
+ addParam(name?: string): Param;
567
+
568
+ /**
569
+ * 添加输入参数
570
+ * @param paramOptions 输入参数参数
571
+ */
572
+ addParam(paramOptions: Partial<Param>): Param;
573
+
574
+ /**
575
+ * 添加输入参数
576
+ * @param param 已有的输入参数实例
577
+ */
578
+ addParam(param: Param): Param;
579
+
580
+ addParam(options?: string | Partial<Param> | Param) {
581
+ const node = this._addParam(options as any);
582
+ const index = this.params.indexOf(node);
583
+ node.create({
584
+ index,
585
+ parentNode: this,
586
+ parentKey: 'params',
587
+ });
588
+ return node;
589
+ }
590
+
591
+ getReturnUniqueName(name = 'result') {
592
+ return utils.unique(name, this.getVarExistingNames(), undefined, false);
593
+ }
594
+
595
+ /**
596
+ * 插入输出参数
597
+ * @internal
598
+ * @param name 输出参数名称,如果不填会自动生成一个唯一名称
599
+ */
600
+ _insertReturnAt(name: string, index: number): Return;
601
+
602
+ /**
603
+ * 插入输出参数
604
+ * @internal
605
+ * @param retOptions 输出参数参数
606
+ */
607
+ _insertReturnAt(retOptions: Partial<Return>, index: number): Return;
608
+
609
+ /**
610
+ * 插入输出参数
611
+ * @internal
612
+ * @param ret 已有的输出参数实例
613
+ */
614
+ _insertReturnAt(ret: Return, index: number): Return;
615
+
616
+ _insertReturnAt(options: string | Partial<Return> | Return, index: number) {
617
+ const retOptions: any = {};
618
+ const relationOptions = { parentNode: this, parentKey: 'returns' };
619
+ let ret: Return;
620
+ if (!options) {
621
+ ret = Return.from(
622
+ {
623
+ ...retOptions,
624
+ name: this.getReturnUniqueName(),
625
+ },
626
+ this,
627
+ 'returns'
628
+ );
629
+ } else if (typeof options === 'string') {
630
+ ret = Return.from(
631
+ {
632
+ ...retOptions,
633
+ name: options,
634
+ },
635
+ this,
636
+ 'returns'
637
+ );
638
+ } else if (options instanceof Return) {
639
+ options.ensureDelete(); // 同一实例不支持多处存在
640
+ ret = options;
641
+ Object.assign(ret, relationOptions);
642
+ } else {
643
+ ret = Return.from(
644
+ {
645
+ ...retOptions,
646
+ ...options,
647
+ },
648
+ this,
649
+ 'returns'
650
+ );
651
+ }
652
+ this.returns.splice(index, 0, ret);
653
+ return ret;
654
+ }
655
+
656
+ /**
657
+ * 插入输出参数
658
+ * @param name 输出参数名称,如果不填会自动生成一个唯一名称
659
+ */
660
+ insertReturnAt(name: string, index: number): Return;
661
+
662
+ /**
663
+ * 插入输出参数
664
+ * @param retOptions 输出参数参数
665
+ */
666
+ insertReturnAt(retOptions: Partial<Return>, index: number): Return;
667
+
668
+ /**
669
+ * 插入输出参数
670
+ * @param ret 已有的输出参数实例
671
+ */
672
+ insertReturnAt(ret: Return, index: number): Return;
673
+
674
+ insertReturnAt(options: string | Partial<Return> | Return, index: number) {
675
+ const node = this._insertReturnAt(options as any, index);
676
+ node.create({
677
+ index,
678
+ parentNode: this,
679
+ parentKey: 'returns',
680
+ });
681
+ return node;
682
+ }
683
+
684
+ /**
685
+ * 添加输出参数
686
+ * @internal
687
+ * @param name 输出参数名称,如果不填会自动生成一个唯一名称
688
+ */
689
+ _addReturn(name?: string): Return;
690
+
691
+ /**
692
+ * 添加输出参数
693
+ * @internal
694
+ * @param retOptions 输出参数参数
695
+ */
696
+ _addReturn(retOptions: Partial<Return>): Return;
697
+
698
+ /**
699
+ * 添加输出参数
700
+ * @internal
701
+ * @param ret 已有的输出参数实例
702
+ */
703
+ _addReturn(ret: Return): Return;
704
+
705
+ _addReturn(options?: string | Partial<Return> | Return) {
706
+ const index = this.returns.length;
707
+ return this._insertReturnAt(options as any, index);
708
+ }
709
+
710
+ /**
711
+ * 添加输出参数
712
+ * @internal
713
+ * @param name 输出参数名称,如果不填会自动生成一个唯一名称
714
+ */
715
+ addReturn(name?: string): Return;
716
+
717
+ /**
718
+ * 添加输出参数
719
+ * @param retOptions 输出参数参数
720
+ */
721
+ addReturn(retOptions: Partial<Return>): Return;
722
+
723
+ /**
724
+ * 添加输出参数
725
+ * @param ret 已有的输出参数实例
726
+ */
727
+ addReturn(ret: Return): Return;
728
+
729
+ addReturn(options?: string | Partial<Return> | Return) {
730
+ const node = this._addReturn(options as any);
731
+ const index = this.returns.indexOf(node);
732
+ node.create({
733
+ index,
734
+ parentNode: this,
735
+ parentKey: 'returns',
736
+ });
737
+ return node;
738
+ }
739
+
740
+ getVariableUniqueName(name = 'variable1') {
741
+ return utils.unique(name, this.getVarExistingNames(), undefined, false);
742
+ }
743
+
744
+ /**
745
+ * 插入变量
746
+ * @internal
747
+ * @param name 变量名称,如果不填会自动生成一个唯一名称
748
+ */
749
+ _insertVariableAt(name: string, index: number): Variable;
750
+
751
+ /**
752
+ * 插入变量
753
+ * @internal
754
+ * @param variableOptions 变量参数
755
+ */
756
+ _insertVariableAt(variableOptions: Partial<Variable>, index: number): Variable;
757
+
758
+ /**
759
+ * 插入变量
760
+ * @internal
761
+ * @param variable 已有的变量实例
762
+ */
763
+ _insertVariableAt(variable: Variable, index: number): Variable;
764
+
765
+ _insertVariableAt(options: string | Partial<Variable> | Variable, index: number) {
766
+ const variableOptions: any = {};
767
+ const relationOptions = { parentNode: this, parentKey: 'variables' };
768
+ let variable: Variable;
769
+ if (!options) {
770
+ variable = Variable.from(
771
+ {
772
+ ...variableOptions,
773
+ name: this.getVariableUniqueName(),
774
+ },
775
+ this,
776
+ 'variables'
777
+ );
778
+ } else if (typeof options === 'string') {
779
+ variable = Variable.from(
780
+ {
781
+ ...variableOptions,
782
+ name: options,
783
+ },
784
+ this,
785
+ 'variables'
786
+ );
787
+ } else if (options instanceof Variable) {
788
+ options.ensureDelete(); // 同一实例不支持多处存在
789
+ variable = options;
790
+ Object.assign(variable, relationOptions);
791
+ } else {
792
+ variable = Variable.from(
793
+ {
794
+ ...variableOptions,
795
+ ...options,
796
+ },
797
+ this,
798
+ 'variables'
799
+ );
800
+ }
801
+ this.variables.splice(index, 0, variable);
802
+ return variable;
803
+ }
804
+
805
+ /**
806
+ * 插入变量
807
+ * @param name 变量名称,如果不填会自动生成一个唯一名称
808
+ */
809
+ insertVariableAt(name: string, index: number): Variable;
810
+
811
+ /**
812
+ * 插入变量
813
+ * @param variableOptions 变量参数
814
+ */
815
+ insertVariableAt(variableOptions: Partial<Variable>, index: number): Variable;
816
+
817
+ /**
818
+ * 插入变量
819
+ * @param variable 已有的变量实例
820
+ */
821
+ insertVariableAt(variable: Variable, index: number): Variable;
822
+
823
+ insertVariableAt(options: string | Partial<Variable> | Variable, index: number) {
824
+ const node = this._insertVariableAt(options as any, index);
825
+ node.create({
826
+ index,
827
+ parentNode: this,
828
+ parentKey: 'variables',
829
+ });
830
+ return node;
831
+ }
832
+
833
+ /**
834
+ * 添加变量
835
+ * @internal
836
+ * @param name 变量名称,如果不填会自动生成一个唯一名称
837
+ */
838
+ _addVariable(name?: string): Variable;
839
+
840
+ /**
841
+ * 添加变量
842
+ * @internal
843
+ * @param variableOptions 变量参数
844
+ */
845
+ _addVariable(variableOptions: Partial<Variable>): Variable;
846
+
847
+ /**
848
+ * 添加变量
849
+ * @internal
850
+ * @param variable 已有的变量实例
851
+ */
852
+ _addVariable(variable: Variable): Variable;
853
+
854
+ _addVariable(options?: string | Partial<Variable> | Variable) {
855
+ const index = this.variables.length;
856
+ return this._insertVariableAt(options as any, index);
857
+ }
858
+
859
+ /**
860
+ * 添加变量
861
+ * @internal
862
+ * @param name 变量名称,如果不填会自动生成一个唯一名称
863
+ */
864
+ addVariable(name?: string): Variable;
865
+
866
+ /**
867
+ * 添加变量
868
+ * @param variableOptions 变量参数
869
+ */
870
+ addVariable(variableOptions: Partial<Variable>): Variable;
871
+
872
+ /**
873
+ * 添加变量
874
+ * @param variable 已有的变量实例
875
+ */
876
+ addVariable(variable: Variable): Variable;
877
+
878
+ addVariable(options?: string | Partial<Variable> | Variable) {
879
+ const node = this._addVariable(options as any);
880
+ const index = this.variables.indexOf(node);
881
+ node.create({
882
+ index,
883
+ parentNode: this,
884
+ parentKey: 'variables',
885
+ });
886
+ return node;
887
+ }
888
+
889
+ /**
890
+ * 插入逻辑项
891
+ * @internal
892
+ * @param logicItemOptions 逻辑项参数
893
+ */
894
+ _insertItemInBodyAt(logicItemOptions: Partial<LogicItem>, index: number): LogicItem;
895
+
896
+ /**
897
+ * 插入逻辑项
898
+ * @internal
899
+ * @param logicItem 已有的逻辑项实例
900
+ */
901
+ _insertItemInBodyAt(logicItem: LogicItem, index: number): LogicItem;
902
+
903
+ _insertItemInBodyAt(options: Partial<LogicItem> | LogicItem, index: number) {
904
+ const logicItemOptions: any = {};
905
+ const relationOptions = { parentNode: this, parentKey: 'body' };
906
+ let logicItem: LogicItem;
907
+ if (options instanceof LogicItem) {
908
+ options.ensureDelete(); // 同一实例不支持多处存在
909
+ logicItem = options;
910
+ Object.assign(logicItem, relationOptions);
911
+ } else {
912
+ logicItem = LogicItem.from(
913
+ {
914
+ ...logicItemOptions,
915
+ ...options,
916
+ },
917
+ this,
918
+ 'body'
919
+ );
920
+ }
921
+ this.body.splice(index, 0, logicItem);
922
+ return logicItem;
923
+ }
924
+
925
+ /**
926
+ * 插入逻辑项
927
+ * @param logicItemOptions 逻辑项参数
928
+ */
929
+ insertItemInBodyAt(logicItemOptions: Partial<LogicItem>, index: number): LogicItem;
930
+
931
+ /**
932
+ * 插入逻辑项
933
+ * @param logicItem 已有的逻辑项实例
934
+ */
935
+ insertItemInBodyAt(logicItem: LogicItem, index: number): LogicItem;
936
+
937
+ insertItemInBodyAt(options: Partial<LogicItem> | LogicItem, index: number) {
938
+ const node = this._insertItemInBodyAt(options as any, index);
939
+ node.create({
940
+ index,
941
+ parentNode: this,
942
+ parentKey: 'body',
943
+ });
944
+ return node;
945
+ }
946
+
947
+ /**
948
+ * 添加逻辑项
949
+ * @internal
950
+ * @param logicItemOptions 逻辑项参数
951
+ */
952
+ _addItemInBody(logicItemOptions: Partial<LogicItem>): LogicItem;
953
+
954
+ /**
955
+ * 添加逻辑项
956
+ * @internal
957
+ * @param logicItem 已有的逻辑项实例
958
+ */
959
+ _addItemInBody(logicItem: LogicItem): LogicItem;
960
+
961
+ _addItemInBody(options?: Partial<LogicItem> | LogicItem) {
962
+ const index = this.body.length;
963
+ return this._insertItemInBodyAt(options as any, index);
964
+ }
965
+
966
+ /**
967
+ * 添加逻辑项
968
+ * @param logicItemOptions 逻辑项参数
969
+ */
970
+ addItemInBody(logicItemOptions: Partial<LogicItem>): LogicItem;
971
+
972
+ /**
973
+ * 添加逻辑项
974
+ * @param logicItem 已有的逻辑项实例
975
+ */
976
+ addItemInBody(logicItem: LogicItem): LogicItem;
977
+
978
+ addItemInBody(options?: Partial<LogicItem> | LogicItem) {
979
+ const node = this._addItemInBody(options as any);
980
+ const index = this.body.indexOf(node);
981
+ node.create({
982
+ index,
983
+ parentNode: this,
984
+ parentKey: 'body',
985
+ });
986
+ return node;
987
+ }
988
+
989
+ /**
990
+ * 插入逻辑项
991
+ * @internal
992
+ * @param logicItemOptions 逻辑项参数
993
+ */
994
+ _insertItemInPlaygroundAt(logicItemOptions: Partial<LogicItem>, index: number): LogicItem;
995
+
996
+ /**
997
+ * 插入逻辑项
998
+ * @internal
999
+ * @param logicItem 已有的逻辑项实例
1000
+ */
1001
+ _insertItemInPlaygroundAt(logicItem: LogicItem, index: number): LogicItem;
1002
+
1003
+ _insertItemInPlaygroundAt(options: Partial<LogicItem> | LogicItem, index: number) {
1004
+ const logicItemOptions: any = {};
1005
+ const relationOptions = { parentNode: this, parentKey: 'playground' };
1006
+ let logicItem: LogicItem;
1007
+ if (options instanceof LogicItem) {
1008
+ options.ensureDelete(); // 同一实例不支持多处存在
1009
+ logicItem = options;
1010
+ Object.assign(logicItem, relationOptions);
1011
+ } else {
1012
+ logicItem = LogicItem.from(
1013
+ {
1014
+ ...logicItemOptions,
1015
+ ...options,
1016
+ },
1017
+ this,
1018
+ 'playground'
1019
+ );
1020
+ }
1021
+ this.playground.splice(index, 0, logicItem);
1022
+ return logicItem;
1023
+ }
1024
+
1025
+ /**
1026
+ * 插入逻辑项
1027
+ * @param logicItemOptions 逻辑项参数
1028
+ */
1029
+ insertItemInPlaygroundAt(logicItemOptions: Partial<LogicItem>, index: number): LogicItem;
1030
+
1031
+ /**
1032
+ * 插入逻辑项
1033
+ * @param logicItem 已有的逻辑项实例
1034
+ */
1035
+ insertItemInPlaygroundAt(logicItem: LogicItem, index: number): LogicItem;
1036
+
1037
+ insertItemInPlaygroundAt(options: Partial<LogicItem> | LogicItem, index: number) {
1038
+ const node = this._insertItemInPlaygroundAt(options as any, index);
1039
+ node.create({
1040
+ index,
1041
+ parentNode: this,
1042
+ parentKey: 'playground',
1043
+ });
1044
+ return node;
1045
+ }
1046
+
1047
+ /**
1048
+ * 添加逻辑项
1049
+ * @internal
1050
+ * @param logicItemOptions 逻辑项参数
1051
+ */
1052
+ _addItemInPlayground(logicItemOptions: Partial<LogicItem>): LogicItem;
1053
+
1054
+ /**
1055
+ * 添加逻辑项
1056
+ * @internal
1057
+ * @param logicItem 已有的逻辑项实例
1058
+ */
1059
+ _addItemInPlayground(logicItem: LogicItem): LogicItem;
1060
+
1061
+ _addItemInPlayground(options?: Partial<LogicItem> | LogicItem) {
1062
+ const index = this.playground.length;
1063
+ return this._insertItemInPlaygroundAt(options as any, index);
1064
+ }
1065
+
1066
+ /**
1067
+ * 添加逻辑项
1068
+ * @param logicItemOptions 逻辑项参数
1069
+ */
1070
+ addItemInPlayground(logicItemOptions: Partial<LogicItem>): LogicItem;
1071
+
1072
+ /**
1073
+ * 添加逻辑项
1074
+ * @param logicItem 已有的逻辑项实例
1075
+ */
1076
+ addItemInPlayground(logicItem: LogicItem): LogicItem;
1077
+
1078
+ addItemInPlayground(options?: Partial<LogicItem> | LogicItem) {
1079
+ const node = this._addItemInPlayground(options as any);
1080
+ const index = this.playground.indexOf(node);
1081
+ node.create({
1082
+ index,
1083
+ parentNode: this,
1084
+ parentKey: 'playground',
1085
+ });
1086
+ return node;
1087
+ }
1088
+
1089
+ /**
1090
+ * 删除事务
1091
+ * @param name 事务名称
1092
+ */
1093
+ removeTransactional(name: string): void;
1094
+
1095
+ /**
1096
+ * 删除事务
1097
+ * @param transactional 已有的事务实例
1098
+ */
1099
+ removeTransactional(transactional: Transactional): void;
1100
+
1101
+ removeTransactional(options: string | Transactional) {
1102
+ let transactional: Transactional;
1103
+ if (typeof options === 'string') {
1104
+ transactional = this.transactional;
1105
+ if (!transactional) {
1106
+ throw new Error(`找不到事务 ${options}`);
1107
+ }
1108
+ } else {
1109
+ transactional = options;
1110
+ }
1111
+ return transactional.delete();
1112
+ }
1113
+
1114
+ __removeTransactional(transactional: Transactional) {
1115
+ const { parentKey } = transactional;
1116
+ const params: Params = {
1117
+ parentNode: this,
1118
+ parentKey,
1119
+ index: -1,
1120
+ object: null,
1121
+ oldObject: transactional,
1122
+ };
1123
+ if (parentKey) {
1124
+ params.parentKey = parentKey;
1125
+ if (Array.isArray((this as any)[parentKey])) {
1126
+ const index = (this as any)[parentKey].indexOf(transactional);
1127
+ ~index && (this as any)[parentKey].splice(index, 1);
1128
+ params.index = index;
1129
+ } else if ((this as any)[parentKey] === transactional) {
1130
+ params.index = 0;
1131
+ (this as any)[parentKey] = undefined;
1132
+ }
1133
+ }
1134
+ return params;
1135
+ }
1136
+
1137
+ /**
1138
+ * 删除类型参数
1139
+ * @param name 类型参数名称
1140
+ */
1141
+ removeTypeParam(name: string): void;
1142
+
1143
+ /**
1144
+ * 删除类型参数
1145
+ * @param typeParam 已有的类型参数实例
1146
+ */
1147
+ removeTypeParam(typeParam: TypeParam): void;
1148
+
1149
+ removeTypeParam(options: string | TypeParam) {
1150
+ let typeParam: TypeParam;
1151
+ if (typeof options === 'string') {
1152
+ typeParam = (this.typeParams as TypeParam[]).find((item) => item.name === options);
1153
+ if (!typeParam) {
1154
+ throw new Error(`找不到类型参数 ${options}`);
1155
+ }
1156
+ } else {
1157
+ typeParam = options;
1158
+ }
1159
+ return typeParam.delete();
1160
+ }
1161
+
1162
+ __removeTypeParam(typeParam: TypeParam) {
1163
+ const { parentKey } = typeParam;
1164
+ const params: Params = {
1165
+ parentNode: this,
1166
+ parentKey,
1167
+ index: -1,
1168
+ object: null,
1169
+ oldObject: typeParam,
1170
+ };
1171
+ if (parentKey) {
1172
+ params.parentKey = parentKey;
1173
+ if (Array.isArray((this as any)[parentKey])) {
1174
+ const index = (this as any)[parentKey].indexOf(typeParam);
1175
+ ~index && (this as any)[parentKey].splice(index, 1);
1176
+ params.index = index;
1177
+ } else if ((this as any)[parentKey] === typeParam) {
1178
+ params.index = 0;
1179
+ (this as any)[parentKey] = undefined;
1180
+ }
1181
+ }
1182
+ return params;
1183
+ }
1184
+
1185
+ /**
1186
+ * 删除输入参数
1187
+ * @param name 输入参数名称
1188
+ */
1189
+ removeParam(name: string): void;
1190
+
1191
+ /**
1192
+ * 删除输入参数
1193
+ * @param param 已有的输入参数实例
1194
+ */
1195
+ removeParam(param: Param): void;
1196
+
1197
+ removeParam(options: string | Param) {
1198
+ let param: Param;
1199
+ if (typeof options === 'string') {
1200
+ param = (this.params as Param[]).find((item) => item.name === options);
1201
+ if (!param) {
1202
+ throw new Error(`找不到输入参数 ${options}`);
1203
+ }
1204
+ } else {
1205
+ param = options;
1206
+ }
1207
+ return param.delete();
1208
+ }
1209
+
1210
+ __removeParam(param: Param) {
1211
+ const { parentKey } = param;
1212
+ const params: Params = {
1213
+ parentNode: this,
1214
+ parentKey,
1215
+ index: -1,
1216
+ object: null,
1217
+ oldObject: param,
1218
+ };
1219
+ if (parentKey) {
1220
+ params.parentKey = parentKey;
1221
+ if (Array.isArray((this as any)[parentKey])) {
1222
+ const index = (this as any)[parentKey].indexOf(param);
1223
+ ~index && (this as any)[parentKey].splice(index, 1);
1224
+ params.index = index;
1225
+ } else if ((this as any)[parentKey] === param) {
1226
+ params.index = 0;
1227
+ (this as any)[parentKey] = undefined;
1228
+ }
1229
+ }
1230
+ return params;
1231
+ }
1232
+
1233
+ /**
1234
+ * 删除输出参数
1235
+ * @param name 输出参数名称
1236
+ */
1237
+ removeReturn(name: string): void;
1238
+
1239
+ /**
1240
+ * 删除输出参数
1241
+ * @param ret 已有的输出参数实例
1242
+ */
1243
+ removeReturn(ret: Return): void;
1244
+
1245
+ removeReturn(options: string | Return) {
1246
+ let ret: Return;
1247
+ if (typeof options === 'string') {
1248
+ ret = (this.returns as Return[]).find((item) => item.name === options);
1249
+ if (!ret) {
1250
+ throw new Error(`找不到输出参数 ${options}`);
1251
+ }
1252
+ } else {
1253
+ ret = options;
1254
+ }
1255
+ return ret.delete();
1256
+ }
1257
+
1258
+ __removeReturn(ret: Return) {
1259
+ const { parentKey } = ret;
1260
+ const params: Params = {
1261
+ parentNode: this,
1262
+ parentKey,
1263
+ index: -1,
1264
+ object: null,
1265
+ oldObject: ret,
1266
+ };
1267
+ if (parentKey) {
1268
+ params.parentKey = parentKey;
1269
+ if (Array.isArray((this as any)[parentKey])) {
1270
+ const index = (this as any)[parentKey].indexOf(ret);
1271
+ ~index && (this as any)[parentKey].splice(index, 1);
1272
+ params.index = index;
1273
+ } else if ((this as any)[parentKey] === ret) {
1274
+ params.index = 0;
1275
+ (this as any)[parentKey] = undefined;
1276
+ }
1277
+ }
1278
+ return params;
1279
+ }
1280
+
1281
+ /**
1282
+ * 删除变量
1283
+ * @param name 变量名称
1284
+ */
1285
+ removeVariable(name: string): void;
1286
+
1287
+ /**
1288
+ * 删除变量
1289
+ * @param variable 已有的变量实例
1290
+ */
1291
+ removeVariable(variable: Variable): void;
1292
+
1293
+ removeVariable(options: string | Variable) {
1294
+ let variable: Variable;
1295
+ if (typeof options === 'string') {
1296
+ variable = (this.variables as Variable[]).find((item) => item.name === options);
1297
+ if (!variable) {
1298
+ throw new Error(`找不到变量 ${options}`);
1299
+ }
1300
+ } else {
1301
+ variable = options;
1302
+ }
1303
+ return variable.delete();
1304
+ }
1305
+
1306
+ __removeVariable(variable: Variable) {
1307
+ const { parentKey } = variable;
1308
+ const params: Params = {
1309
+ parentNode: this,
1310
+ parentKey,
1311
+ index: -1,
1312
+ object: null,
1313
+ oldObject: variable,
1314
+ };
1315
+ if (parentKey) {
1316
+ params.parentKey = parentKey;
1317
+ if (Array.isArray((this as any)[parentKey])) {
1318
+ const index = (this as any)[parentKey].indexOf(variable);
1319
+ ~index && (this as any)[parentKey].splice(index, 1);
1320
+ params.index = index;
1321
+ } else if ((this as any)[parentKey] === variable) {
1322
+ params.index = 0;
1323
+ (this as any)[parentKey] = undefined;
1324
+ }
1325
+ }
1326
+ return params;
1327
+ }
1328
+
1329
+ /**
1330
+ * 删除逻辑项
1331
+ * @param logicItem 已有的逻辑项实例
1332
+ */
1333
+ removeItemInBody(logicItem: LogicItem): void;
1334
+
1335
+ removeItemInBody(options: LogicItem) {
1336
+ const logicItem: LogicItem = options;
1337
+ return logicItem.delete();
1338
+ }
1339
+
1340
+ /**
1341
+ * 删除逻辑项
1342
+ * @param logicItem 已有的逻辑项实例
1343
+ */
1344
+ removeItemInPlayground(logicItem: LogicItem): void;
1345
+
1346
+ removeItemInPlayground(options: LogicItem) {
1347
+ const logicItem: LogicItem = options;
1348
+ return logicItem.delete();
1349
+ }
1350
+
1351
+ __removeLogicItem(logicItem: LogicItem) {
1352
+ const { parentKey } = logicItem;
1353
+ const params: Params = {
1354
+ parentNode: this,
1355
+ parentKey,
1356
+ index: -1,
1357
+ object: null,
1358
+ oldObject: logicItem,
1359
+ };
1360
+ if (parentKey) {
1361
+ params.parentKey = parentKey;
1362
+ if (Array.isArray((this as any)[parentKey])) {
1363
+ const index = (this as any)[parentKey].indexOf(logicItem);
1364
+ ~index && (this as any)[parentKey].splice(index, 1);
1365
+ params.index = index;
1366
+ } else if ((this as any)[parentKey] === logicItem) {
1367
+ params.index = 0;
1368
+ (this as any)[parentKey] = undefined;
1369
+ }
1370
+ }
1371
+ return params;
1372
+ }
1373
+
1374
+ //= ===============================================================================
1375
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
1376
+ // 自动生成的代码已结束。下面可以手动编写。
1377
+ //= ===============================================================================
1378
+ // 用于calllogic树中定位是那个logic,回显
1379
+ get calleewholeKey() {
1380
+ return `${this.getNamespace()}.${this.name}`;
1381
+ }
1382
+
1383
+ // 设置定时任务
1384
+ setCronAndTriggerType(cron: string, triggerType: string) {
1385
+ const object = {
1386
+ cron,
1387
+ triggerType,
1388
+ };
1389
+ this.update({
1390
+ ...object,
1391
+ });
1392
+ }
1393
+
1394
+ /**
1395
+ * 创建的时候 打开事务 通过开关设置数据库事务
1396
+ */
1397
+ openTransactional(flag: boolean) {
1398
+ if (flag) {
1399
+ const transactional = new Transactional({
1400
+ enabled: flag,
1401
+ });
1402
+ transactional._delete();
1403
+ const relationOptions = { parentNode: this, parentKey: 'transactional' };
1404
+ Object.assign(transactional, relationOptions);
1405
+ this.transactional = transactional;
1406
+ }
1407
+ }
1408
+
1409
+ findLogicItemByConcept(concept: string) {
1410
+ let result: any;
1411
+
1412
+ utils.traverse(
1413
+ (current) => {
1414
+ if ((current.node as any).concept === concept) return (result = current.node);
1415
+ },
1416
+ { node: this },
1417
+ {
1418
+ mode: 'anyObject',
1419
+ excludedKeySet: this.JSON_EXCLUDED_KEYS,
1420
+ }
1421
+ );
1422
+
1423
+ return result as LogicItem;
1424
+ }
1425
+
1426
+ onChange($event?: EventPayload): void {
1427
+ this.emit('change', $event);
1428
+ }
1429
+
1430
+ getVarExistingNames(excludedList: Array<Param | Return | Variable> = []) {
1431
+ const excludedSet = new Set(excludedList);
1432
+ const varList: any[] = [];
1433
+ if (Array.isArray(this.params)) {
1434
+ varList.push(...this.params);
1435
+ }
1436
+ if (Array.isArray(this.returns)) {
1437
+ varList.push(...this.returns);
1438
+ }
1439
+ if (Array.isArray(this.variables)) {
1440
+ varList.push(...this.variables);
1441
+ }
1442
+ if (this.view) {
1443
+ if (Array.isArray(this.view.params)) {
1444
+ varList.push(...this.view.params);
1445
+ }
1446
+ if (Array.isArray(this.view.variables)) {
1447
+ varList.push(...this.view.variables);
1448
+ }
1449
+ }
1450
+
1451
+ this.traverseChildren((el) => {
1452
+ if (el?.concept === 'ForEachStatement') {
1453
+ if ((el as ForEachStatement)?.item) {
1454
+ varList.push((el as ForEachStatement)?.item);
199
1455
  }
200
- return params;
201
- }
202
- /**
203
- * 设置逻辑名称
204
- */
205
- setName(name: string) {
206
- const object = {
207
- name,
208
- };
209
- this.update({
210
- ...object,
211
- field: 'name',
212
- });
213
- }
214
-
215
- /**
216
- * 设置逻辑描述
217
- */
218
- setDescription(description: string) {
219
- const object = {
220
- description,
221
- };
222
- this.update({
223
- ...object,
224
- });
225
- }
226
-
227
- /**
228
- * 设置triggerType
229
- */
230
- setTriggerType(triggerType: string) {
231
- const object = {
232
- triggerType,
233
- };
234
- this.update({
235
- ...object,
236
- });
237
- }
238
-
239
- /**
240
- * 设置cron
241
- */
242
- setCron(cron: string) {
243
- const object = {
244
- cron,
245
- };
246
- this.update({
247
- ...object,
248
- });
249
- }
250
-
251
- /**
252
- * 设置overridable
253
- */
254
- setOverridable(overridable: boolean) {
255
- const object = {
256
- overridable,
257
- };
258
- this.update({
259
- ...object,
260
- });
261
- }
262
-
263
- /**
264
- * 设置事务
265
- */
266
- setTransactional(transactional: Transactional) {
267
- transactional._delete();
268
- const relationOptions = { parentNode: this, parentKey: 'transactional' };
269
- Object.assign(transactional, relationOptions);
270
- const object = {
271
- transactional,
272
- };
273
- this.update({
274
- ...object,
275
- });
276
- }
277
-
278
- getTypeParamExistingNames(excludedList: Array<TypeParam> = []) {
279
- const excludedSet = new Set(excludedList);
280
- return ((this.typeParams as TypeParam[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
281
- }
282
- getTypeParamUniqueName(name = 'typeParam1') {
283
- return utils.unique(name, this.getTypeParamExistingNames(), undefined, false);
284
- }
285
-
286
- /**
287
- * 插入类型参数
288
- * @internal
289
- * @param name 类型参数名称,如果不填会自动生成一个唯一名称
290
- */
291
- _insertTypeParamAt(name: string, index: number): TypeParam;
292
-
293
- /**
294
- * 插入类型参数
295
- * @internal
296
- * @param typeParamOptions 类型参数参数
297
- */
298
- _insertTypeParamAt(typeParamOptions: Partial<TypeParam>, index: number): TypeParam;
299
-
300
- /**
301
- * 插入类型参数
302
- * @internal
303
- * @param typeParam 已有的类型参数实例
304
- */
305
- _insertTypeParamAt(typeParam: TypeParam, index: number): TypeParam;
306
-
307
- _insertTypeParamAt(options: string | Partial<TypeParam> | TypeParam, index: number) {
308
- const typeParamOptions: any = {};
309
- const relationOptions = { parentNode: this, parentKey: 'typeParams' };
310
- let typeParam: TypeParam;
311
- if (!options) {
312
- typeParam = TypeParam.from({
313
- ...typeParamOptions,
314
- name: this.getTypeParamUniqueName(),
315
- }, this, 'typeParams');
316
- } else if (typeof options === 'string') {
317
- typeParam = TypeParam.from({
318
- ...typeParamOptions,
319
- name: options,
320
- }, this, 'typeParams');
321
- } else if (options instanceof TypeParam) {
322
- options.ensureDelete(); // 同一实例不支持多处存在
323
- typeParam = options;
324
- Object.assign(typeParam, relationOptions);
325
- } else {
326
- typeParam = TypeParam.from({
327
- ...typeParamOptions,
328
- ...options,
329
- }, this, 'typeParams');
330
- }
331
- this.typeParams.splice(index, 0, typeParam);
332
- return typeParam;
333
- }
334
-
335
- /**
336
- * 插入类型参数
337
- * @param name 类型参数名称,如果不填会自动生成一个唯一名称
338
- */
339
- insertTypeParamAt(name: string, index: number): TypeParam;
340
-
341
- /**
342
- * 插入类型参数
343
- * @param typeParamOptions 类型参数参数
344
- */
345
- insertTypeParamAt(typeParamOptions: Partial<TypeParam>, index: number): TypeParam;
346
-
347
- /**
348
- * 插入类型参数
349
- * @param typeParam 已有的类型参数实例
350
- */
351
- insertTypeParamAt(typeParam: TypeParam, index: number): TypeParam;
352
-
353
- insertTypeParamAt(options: string | Partial<TypeParam> | TypeParam, index: number) {
354
- const node = this._insertTypeParamAt(options as any, index);
355
- node.create({
356
- index,
357
- parentNode: this,
358
- parentKey: 'typeParams',
359
- });
360
- return node;
361
- }
362
-
363
- /**
364
- * 添加类型参数
365
- * @internal
366
- * @param name 类型参数名称,如果不填会自动生成一个唯一名称
367
- */
368
- _addTypeParam(name?: string): TypeParam;
369
-
370
- /**
371
- * 添加类型参数
372
- * @internal
373
- * @param typeParamOptions 类型参数参数
374
- */
375
- _addTypeParam(typeParamOptions: Partial<TypeParam>): TypeParam;
376
-
377
- /**
378
- * 添加类型参数
379
- * @internal
380
- * @param typeParam 已有的类型参数实例
381
- */
382
- _addTypeParam(typeParam: TypeParam): TypeParam;
383
-
384
- _addTypeParam(options?: string | Partial<TypeParam> | TypeParam) {
385
- const index = this.typeParams.length;
386
- return this._insertTypeParamAt(options as any, index);
387
- }
388
-
389
- /**
390
- * 添加类型参数
391
- * @internal
392
- * @param name 类型参数名称,如果不填会自动生成一个唯一名称
393
- */
394
- addTypeParam(name?: string): TypeParam;
395
-
396
- /**
397
- * 添加类型参数
398
- * @param typeParamOptions 类型参数参数
399
- */
400
- addTypeParam(typeParamOptions: Partial<TypeParam>): TypeParam;
401
-
402
- /**
403
- * 添加类型参数
404
- * @param typeParam 已有的类型参数实例
405
- */
406
- addTypeParam(typeParam: TypeParam): TypeParam;
407
-
408
- addTypeParam(options?: string | Partial<TypeParam> | TypeParam) {
409
- const node = this._addTypeParam(options as any);
410
- const index = this.typeParams.indexOf(node);
411
- node.create({
412
- index,
413
- parentNode: this,
414
- parentKey: 'typeParams',
415
- });
416
- return node;
417
- }
418
-
419
- getParamUniqueName(name = 'param1') {
420
- return utils.unique(name, this.getVarExistingNames(), undefined, false);
421
- }
422
-
423
- /**
424
- * 插入输入参数
425
- * @internal
426
- * @param name 输入参数名称,如果不填会自动生成一个唯一名称
427
- */
428
- _insertParamAt(name: string, index: number): Param;
429
-
430
- /**
431
- * 插入输入参数
432
- * @internal
433
- * @param paramOptions 输入参数参数
434
- */
435
- _insertParamAt(paramOptions: Partial<Param>, index: number): Param;
436
-
437
- /**
438
- * 插入输入参数
439
- * @internal
440
- * @param param 已有的输入参数实例
441
- */
442
- _insertParamAt(param: Param, index: number): Param;
443
-
444
- _insertParamAt(options: string | Partial<Param> | Param, index: number) {
445
- const paramOptions: any = {};
446
- const relationOptions = { parentNode: this, parentKey: 'params' };
447
- let param: Param;
448
- if (!options) {
449
- param = Param.from({
450
- ...paramOptions,
451
- name: this.getParamUniqueName(),
452
- }, this, 'params');
453
- } else if (typeof options === 'string') {
454
- param = Param.from({
455
- ...paramOptions,
456
- name: options,
457
- }, this, 'params');
458
- } else if (options instanceof Param) {
459
- options.ensureDelete(); // 同一实例不支持多处存在
460
- param = options;
461
- Object.assign(param, relationOptions);
462
- } else {
463
- param = Param.from({
464
- ...paramOptions,
465
- ...options,
466
- }, this, 'params');
1456
+ if ((el as ForEachStatement)?.index) {
1457
+ varList.push((el as ForEachStatement)?.index);
467
1458
  }
468
- this.params.splice(index, 0, param);
469
- return param;
470
- }
471
-
472
- /**
473
- * 插入输入参数
474
- * @param name 输入参数名称,如果不填会自动生成一个唯一名称
475
- */
476
- insertParamAt(name: string, index: number): Param;
477
-
478
- /**
479
- * 插入输入参数
480
- * @param paramOptions 输入参数参数
481
- */
482
- insertParamAt(paramOptions: Partial<Param>, index: number): Param;
483
-
484
- /**
485
- * 插入输入参数
486
- * @param param 已有的输入参数实例
487
- */
488
- insertParamAt(param: Param, index: number): Param;
489
-
490
- insertParamAt(options: string | Partial<Param> | Param, index: number) {
491
- const node = this._insertParamAt(options as any, index);
492
- node.create({
493
- index,
494
- parentNode: this,
495
- parentKey: 'params',
496
- });
497
- return node;
498
- }
499
-
500
- /**
501
- * 添加输入参数
502
- * @internal
503
- * @param name 输入参数名称,如果不填会自动生成一个唯一名称
504
- */
505
- _addParam(name?: string): Param;
506
-
507
- /**
508
- * 添加输入参数
509
- * @internal
510
- * @param paramOptions 输入参数参数
511
- */
512
- _addParam(paramOptions: Partial<Param>): Param;
513
-
514
- /**
515
- * 添加输入参数
516
- * @internal
517
- * @param param 已有的输入参数实例
518
- */
519
- _addParam(param: Param): Param;
520
-
521
- _addParam(options?: string | Partial<Param> | Param) {
522
- const index = this.params.length;
523
- return this._insertParamAt(options as any, index);
524
- }
525
-
526
- /**
527
- * 添加输入参数
528
- * @internal
529
- * @param name 输入参数名称,如果不填会自动生成一个唯一名称
530
- */
531
- addParam(name?: string): Param;
532
-
533
- /**
534
- * 添加输入参数
535
- * @param paramOptions 输入参数参数
536
- */
537
- addParam(paramOptions: Partial<Param>): Param;
538
-
539
- /**
540
- * 添加输入参数
541
- * @param param 已有的输入参数实例
542
- */
543
- addParam(param: Param): Param;
544
-
545
- addParam(options?: string | Partial<Param> | Param) {
546
- const node = this._addParam(options as any);
547
- const index = this.params.indexOf(node);
548
- node.create({
549
- index,
550
- parentNode: this,
551
- parentKey: 'params',
552
- });
553
- return node;
554
- }
555
-
556
- getReturnUniqueName(name = 'result') {
557
- return utils.unique(name, this.getVarExistingNames(), undefined, false);
558
- }
559
-
560
- /**
561
- * 插入输出参数
562
- * @internal
563
- * @param name 输出参数名称,如果不填会自动生成一个唯一名称
564
- */
565
- _insertReturnAt(name: string, index: number): Return;
566
-
567
- /**
568
- * 插入输出参数
569
- * @internal
570
- * @param retOptions 输出参数参数
571
- */
572
- _insertReturnAt(retOptions: Partial<Return>, index: number): Return;
573
-
574
- /**
575
- * 插入输出参数
576
- * @internal
577
- * @param ret 已有的输出参数实例
578
- */
579
- _insertReturnAt(ret: Return, index: number): Return;
580
-
581
- _insertReturnAt(options: string | Partial<Return> | Return, index: number) {
582
- const retOptions: any = {};
583
- const relationOptions = { parentNode: this, parentKey: 'returns' };
584
- let ret: Return;
585
- if (!options) {
586
- ret = Return.from({
587
- ...retOptions,
588
- name: this.getReturnUniqueName(),
589
- }, this, 'returns');
590
- } else if (typeof options === 'string') {
591
- ret = Return.from({
592
- ...retOptions,
593
- name: options,
594
- }, this, 'returns');
595
- } else if (options instanceof Return) {
596
- options.ensureDelete(); // 同一实例不支持多处存在
597
- ret = options;
598
- Object.assign(ret, relationOptions);
599
- } else {
600
- ret = Return.from({
601
- ...retOptions,
602
- ...options,
603
- }, this, 'returns');
604
- }
605
- this.returns.splice(index, 0, ret);
606
- return ret;
607
- }
608
-
609
- /**
610
- * 插入输出参数
611
- * @param name 输出参数名称,如果不填会自动生成一个唯一名称
612
- */
613
- insertReturnAt(name: string, index: number): Return;
614
-
615
- /**
616
- * 插入输出参数
617
- * @param retOptions 输出参数参数
618
- */
619
- insertReturnAt(retOptions: Partial<Return>, index: number): Return;
620
-
621
- /**
622
- * 插入输出参数
623
- * @param ret 已有的输出参数实例
624
- */
625
- insertReturnAt(ret: Return, index: number): Return;
626
-
627
- insertReturnAt(options: string | Partial<Return> | Return, index: number) {
628
- const node = this._insertReturnAt(options as any, index);
629
- node.create({
630
- index,
631
- parentNode: this,
632
- parentKey: 'returns',
633
- });
634
- return node;
635
- }
636
-
637
- /**
638
- * 添加输出参数
639
- * @internal
640
- * @param name 输出参数名称,如果不填会自动生成一个唯一名称
641
- */
642
- _addReturn(name?: string): Return;
643
-
644
- /**
645
- * 添加输出参数
646
- * @internal
647
- * @param retOptions 输出参数参数
648
- */
649
- _addReturn(retOptions: Partial<Return>): Return;
650
-
651
- /**
652
- * 添加输出参数
653
- * @internal
654
- * @param ret 已有的输出参数实例
655
- */
656
- _addReturn(ret: Return): Return;
657
-
658
- _addReturn(options?: string | Partial<Return> | Return) {
659
- const index = this.returns.length;
660
- return this._insertReturnAt(options as any, index);
661
- }
662
-
663
- /**
664
- * 添加输出参数
665
- * @internal
666
- * @param name 输出参数名称,如果不填会自动生成一个唯一名称
667
- */
668
- addReturn(name?: string): Return;
669
-
670
- /**
671
- * 添加输出参数
672
- * @param retOptions 输出参数参数
673
- */
674
- addReturn(retOptions: Partial<Return>): Return;
675
-
676
- /**
677
- * 添加输出参数
678
- * @param ret 已有的输出参数实例
679
- */
680
- addReturn(ret: Return): Return;
681
-
682
- addReturn(options?: string | Partial<Return> | Return) {
683
- const node = this._addReturn(options as any);
684
- const index = this.returns.indexOf(node);
685
- node.create({
686
- index,
687
- parentNode: this,
688
- parentKey: 'returns',
689
- });
690
- return node;
691
- }
692
-
693
- getVariableUniqueName(name = 'variable1') {
694
- return utils.unique(name, this.getVarExistingNames(), undefined, false);
695
- }
696
-
697
- /**
698
- * 插入变量
699
- * @internal
700
- * @param name 变量名称,如果不填会自动生成一个唯一名称
701
- */
702
- _insertVariableAt(name: string, index: number): Variable;
703
-
704
- /**
705
- * 插入变量
706
- * @internal
707
- * @param variableOptions 变量参数
708
- */
709
- _insertVariableAt(variableOptions: Partial<Variable>, index: number): Variable;
710
-
711
- /**
712
- * 插入变量
713
- * @internal
714
- * @param variable 已有的变量实例
715
- */
716
- _insertVariableAt(variable: Variable, index: number): Variable;
717
-
718
- _insertVariableAt(options: string | Partial<Variable> | Variable, index: number) {
719
- const variableOptions: any = {};
720
- const relationOptions = { parentNode: this, parentKey: 'variables' };
721
- let variable: Variable;
722
- if (!options) {
723
- variable = Variable.from({
724
- ...variableOptions,
725
- name: this.getVariableUniqueName(),
726
- }, this, 'variables');
727
- } else if (typeof options === 'string') {
728
- variable = Variable.from({
729
- ...variableOptions,
730
- name: options,
731
- }, this, 'variables');
732
- } else if (options instanceof Variable) {
733
- options.ensureDelete(); // 同一实例不支持多处存在
734
- variable = options;
735
- Object.assign(variable, relationOptions);
736
- } else {
737
- variable = Variable.from({
738
- ...variableOptions,
739
- ...options,
740
- }, this, 'variables');
741
- }
742
- this.variables.splice(index, 0, variable);
743
- return variable;
744
- }
745
-
746
- /**
747
- * 插入变量
748
- * @param name 变量名称,如果不填会自动生成一个唯一名称
749
- */
750
- insertVariableAt(name: string, index: number): Variable;
751
-
752
- /**
753
- * 插入变量
754
- * @param variableOptions 变量参数
755
- */
756
- insertVariableAt(variableOptions: Partial<Variable>, index: number): Variable;
757
-
758
- /**
759
- * 插入变量
760
- * @param variable 已有的变量实例
761
- */
762
- insertVariableAt(variable: Variable, index: number): Variable;
763
-
764
- insertVariableAt(options: string | Partial<Variable> | Variable, index: number) {
765
- const node = this._insertVariableAt(options as any, index);
766
- node.create({
767
- index,
768
- parentNode: this,
769
- parentKey: 'variables',
770
- });
771
- return node;
772
- }
773
-
774
- /**
775
- * 添加变量
776
- * @internal
777
- * @param name 变量名称,如果不填会自动生成一个唯一名称
778
- */
779
- _addVariable(name?: string): Variable;
780
-
781
- /**
782
- * 添加变量
783
- * @internal
784
- * @param variableOptions 变量参数
785
- */
786
- _addVariable(variableOptions: Partial<Variable>): Variable;
787
-
788
- /**
789
- * 添加变量
790
- * @internal
791
- * @param variable 已有的变量实例
792
- */
793
- _addVariable(variable: Variable): Variable;
794
-
795
- _addVariable(options?: string | Partial<Variable> | Variable) {
796
- const index = this.variables.length;
797
- return this._insertVariableAt(options as any, index);
798
- }
799
-
800
- /**
801
- * 添加变量
802
- * @internal
803
- * @param name 变量名称,如果不填会自动生成一个唯一名称
804
- */
805
- addVariable(name?: string): Variable;
806
-
807
- /**
808
- * 添加变量
809
- * @param variableOptions 变量参数
810
- */
811
- addVariable(variableOptions: Partial<Variable>): Variable;
812
-
813
- /**
814
- * 添加变量
815
- * @param variable 已有的变量实例
816
- */
817
- addVariable(variable: Variable): Variable;
818
-
819
- addVariable(options?: string | Partial<Variable> | Variable) {
820
- const node = this._addVariable(options as any);
821
- const index = this.variables.indexOf(node);
822
- node.create({
823
- index,
824
- parentNode: this,
825
- parentKey: 'variables',
826
- });
827
- return node;
828
- }
829
-
830
- /**
831
- * 插入逻辑项
832
- * @internal
833
- * @param logicItemOptions 逻辑项参数
834
- */
835
- _insertItemInBodyAt(logicItemOptions: Partial<LogicItem>, index: number): LogicItem;
836
-
837
- /**
838
- * 插入逻辑项
839
- * @internal
840
- * @param logicItem 已有的逻辑项实例
841
- */
842
- _insertItemInBodyAt(logicItem: LogicItem, index: number): LogicItem;
843
-
844
- _insertItemInBodyAt(options: Partial<LogicItem> | LogicItem, index: number) {
845
- const logicItemOptions: any = {};
846
- const relationOptions = { parentNode: this, parentKey: 'body' };
847
- let logicItem: LogicItem;
848
- if (options instanceof LogicItem) {
849
- options.ensureDelete(); // 同一实例不支持多处存在
850
- logicItem = options;
851
- Object.assign(logicItem, relationOptions);
852
- } else {
853
- logicItem = LogicItem.from({
854
- ...logicItemOptions,
855
- ...options,
856
- }, this, 'body');
857
- }
858
- this.body.splice(index, 0, logicItem);
859
- return logicItem;
860
- }
861
-
862
- /**
863
- * 插入逻辑项
864
- * @param logicItemOptions 逻辑项参数
865
- */
866
- insertItemInBodyAt(logicItemOptions: Partial<LogicItem>, index: number): LogicItem;
867
-
868
- /**
869
- * 插入逻辑项
870
- * @param logicItem 已有的逻辑项实例
871
- */
872
- insertItemInBodyAt(logicItem: LogicItem, index: number): LogicItem;
873
-
874
- insertItemInBodyAt(options: Partial<LogicItem> | LogicItem, index: number) {
875
- const node = this._insertItemInBodyAt(options as any, index);
876
- node.create({
877
- index,
878
- parentNode: this,
879
- parentKey: 'body',
880
- });
881
- return node;
882
- }
883
-
884
- /**
885
- * 添加逻辑项
886
- * @internal
887
- * @param logicItemOptions 逻辑项参数
888
- */
889
- _addItemInBody(logicItemOptions: Partial<LogicItem>): LogicItem;
890
-
891
- /**
892
- * 添加逻辑项
893
- * @internal
894
- * @param logicItem 已有的逻辑项实例
895
- */
896
- _addItemInBody(logicItem: LogicItem): LogicItem;
897
-
898
- _addItemInBody(options?: Partial<LogicItem> | LogicItem) {
899
- const index = this.body.length;
900
- return this._insertItemInBodyAt(options as any, index);
901
- }
902
-
903
- /**
904
- * 添加逻辑项
905
- * @param logicItemOptions 逻辑项参数
906
- */
907
- addItemInBody(logicItemOptions: Partial<LogicItem>): LogicItem;
908
-
909
- /**
910
- * 添加逻辑项
911
- * @param logicItem 已有的逻辑项实例
912
- */
913
- addItemInBody(logicItem: LogicItem): LogicItem;
914
-
915
- addItemInBody(options?: Partial<LogicItem> | LogicItem) {
916
- const node = this._addItemInBody(options as any);
917
- const index = this.body.indexOf(node);
918
- node.create({
919
- index,
920
- parentNode: this,
921
- parentKey: 'body',
922
- });
923
- return node;
924
- }
925
-
926
- /**
927
- * 插入逻辑项
928
- * @internal
929
- * @param logicItemOptions 逻辑项参数
930
- */
931
- _insertItemInPlaygroundAt(logicItemOptions: Partial<LogicItem>, index: number): LogicItem;
932
-
933
- /**
934
- * 插入逻辑项
935
- * @internal
936
- * @param logicItem 已有的逻辑项实例
937
- */
938
- _insertItemInPlaygroundAt(logicItem: LogicItem, index: number): LogicItem;
939
-
940
- _insertItemInPlaygroundAt(options: Partial<LogicItem> | LogicItem, index: number) {
941
- const logicItemOptions: any = {};
942
- const relationOptions = { parentNode: this, parentKey: 'playground' };
943
- let logicItem: LogicItem;
944
- if (options instanceof LogicItem) {
945
- options.ensureDelete(); // 同一实例不支持多处存在
946
- logicItem = options;
947
- Object.assign(logicItem, relationOptions);
948
- } else {
949
- logicItem = LogicItem.from({
950
- ...logicItemOptions,
951
- ...options,
952
- }, this, 'playground');
953
- }
954
- this.playground.splice(index, 0, logicItem);
955
- return logicItem;
956
- }
957
-
958
- /**
959
- * 插入逻辑项
960
- * @param logicItemOptions 逻辑项参数
961
- */
962
- insertItemInPlaygroundAt(logicItemOptions: Partial<LogicItem>, index: number): LogicItem;
963
-
964
- /**
965
- * 插入逻辑项
966
- * @param logicItem 已有的逻辑项实例
967
- */
968
- insertItemInPlaygroundAt(logicItem: LogicItem, index: number): LogicItem;
969
-
970
- insertItemInPlaygroundAt(options: Partial<LogicItem> | LogicItem, index: number) {
971
- const node = this._insertItemInPlaygroundAt(options as any, index);
972
- node.create({
973
- index,
974
- parentNode: this,
975
- parentKey: 'playground',
976
- });
977
- return node;
978
- }
979
-
980
- /**
981
- * 添加逻辑项
982
- * @internal
983
- * @param logicItemOptions 逻辑项参数
984
- */
985
- _addItemInPlayground(logicItemOptions: Partial<LogicItem>): LogicItem;
986
-
987
- /**
988
- * 添加逻辑项
989
- * @internal
990
- * @param logicItem 已有的逻辑项实例
991
- */
992
- _addItemInPlayground(logicItem: LogicItem): LogicItem;
993
-
994
- _addItemInPlayground(options?: Partial<LogicItem> | LogicItem) {
995
- const index = this.playground.length;
996
- return this._insertItemInPlaygroundAt(options as any, index);
997
- }
998
-
999
- /**
1000
- * 添加逻辑项
1001
- * @param logicItemOptions 逻辑项参数
1002
- */
1003
- addItemInPlayground(logicItemOptions: Partial<LogicItem>): LogicItem;
1004
-
1005
- /**
1006
- * 添加逻辑项
1007
- * @param logicItem 已有的逻辑项实例
1008
- */
1009
- addItemInPlayground(logicItem: LogicItem): LogicItem;
1010
-
1011
- addItemInPlayground(options?: Partial<LogicItem> | LogicItem) {
1012
- const node = this._addItemInPlayground(options as any);
1013
- const index = this.playground.indexOf(node);
1014
- node.create({
1015
- index,
1016
- parentNode: this,
1017
- parentKey: 'playground',
1018
- });
1019
- return node;
1020
- }
1021
- /**
1022
- * 删除事务
1023
- * @param name 事务名称
1024
- */
1025
- removeTransactional(name: string): void;
1026
-
1027
- /**
1028
- * 删除事务
1029
- * @param transactional 已有的事务实例
1030
- */
1031
- removeTransactional(transactional: Transactional): void;
1032
-
1033
- removeTransactional(options: string | Transactional) {
1034
- let transactional: Transactional;
1035
- if (typeof options === 'string') {
1036
- transactional = this.transactional;
1037
- if (!transactional) {
1038
- throw new Error('找不到事务 ' + options);
1039
- }
1040
- } else {
1041
- transactional = options;
1042
- }
1043
- return transactional.delete();
1044
- }
1045
-
1046
- __removeTransactional(transactional: Transactional) {
1047
- const parentKey = transactional.parentKey;
1048
- const params: Params = {
1049
- parentNode: this,
1050
- parentKey,
1051
- index: -1,
1052
- object: null,
1053
- oldObject: transactional,
1054
- };
1055
- if (parentKey) {
1056
- params.parentKey = parentKey;
1057
- if (Array.isArray((this as any)[parentKey])) {
1058
- const index = (this as any)[parentKey].indexOf(transactional);
1059
- ~index && (this as any)[parentKey].splice(index, 1);
1060
- params.index = index;
1061
- } else if ((this as any)[parentKey] === transactional) {
1062
- params.index = 0;
1063
- (this as any)[parentKey] = undefined;
1064
- }
1065
- }
1066
- return params;
1067
- }
1068
-
1069
- /**
1070
- * 删除类型参数
1071
- * @param name 类型参数名称
1072
- */
1073
- removeTypeParam(name: string): void;
1074
-
1075
- /**
1076
- * 删除类型参数
1077
- * @param typeParam 已有的类型参数实例
1078
- */
1079
- removeTypeParam(typeParam: TypeParam): void;
1080
-
1081
- removeTypeParam(options: string | TypeParam) {
1082
- let typeParam: TypeParam;
1083
- if (typeof options === 'string') {
1084
- typeParam = (this.typeParams as TypeParam[]).find((item) => item.name === options);
1085
- if (!typeParam) {
1086
- throw new Error('找不到类型参数 ' + options);
1087
- }
1088
- } else {
1089
- typeParam = options;
1090
- }
1091
- return typeParam.delete();
1092
- }
1093
-
1094
- __removeTypeParam(typeParam: TypeParam) {
1095
- const parentKey = typeParam.parentKey;
1096
- const params: Params = {
1097
- parentNode: this,
1098
- parentKey,
1099
- index: -1,
1100
- object: null,
1101
- oldObject: typeParam,
1102
- };
1103
- if (parentKey) {
1104
- params.parentKey = parentKey;
1105
- if (Array.isArray((this as any)[parentKey])) {
1106
- const index = (this as any)[parentKey].indexOf(typeParam);
1107
- ~index && (this as any)[parentKey].splice(index, 1);
1108
- params.index = index;
1109
- } else if ((this as any)[parentKey] === typeParam) {
1110
- params.index = 0;
1111
- (this as any)[parentKey] = undefined;
1112
- }
1113
- }
1114
- return params;
1115
- }
1116
-
1117
- /**
1118
- * 删除输入参数
1119
- * @param name 输入参数名称
1120
- */
1121
- removeParam(name: string): void;
1122
-
1123
- /**
1124
- * 删除输入参数
1125
- * @param param 已有的输入参数实例
1126
- */
1127
- removeParam(param: Param): void;
1128
-
1129
- removeParam(options: string | Param) {
1130
- let param: Param;
1131
- if (typeof options === 'string') {
1132
- param = (this.params as Param[]).find((item) => item.name === options);
1133
- if (!param) {
1134
- throw new Error('找不到输入参数 ' + options);
1135
- }
1136
- } else {
1137
- param = options;
1138
- }
1139
- return param.delete();
1140
- }
1141
-
1142
- __removeParam(param: Param) {
1143
- const parentKey = param.parentKey;
1144
- const params: Params = {
1145
- parentNode: this,
1146
- parentKey,
1147
- index: -1,
1148
- object: null,
1149
- oldObject: param,
1150
- };
1151
- if (parentKey) {
1152
- params.parentKey = parentKey;
1153
- if (Array.isArray((this as any)[parentKey])) {
1154
- const index = (this as any)[parentKey].indexOf(param);
1155
- ~index && (this as any)[parentKey].splice(index, 1);
1156
- params.index = index;
1157
- } else if ((this as any)[parentKey] === param) {
1158
- params.index = 0;
1159
- (this as any)[parentKey] = undefined;
1160
- }
1161
- }
1162
- return params;
1163
- }
1164
-
1165
- /**
1166
- * 删除输出参数
1167
- * @param name 输出参数名称
1168
- */
1169
- removeReturn(name: string): void;
1170
-
1171
- /**
1172
- * 删除输出参数
1173
- * @param ret 已有的输出参数实例
1174
- */
1175
- removeReturn(ret: Return): void;
1176
-
1177
- removeReturn(options: string | Return) {
1178
- let ret: Return;
1179
- if (typeof options === 'string') {
1180
- ret = (this.returns as Return[]).find((item) => item.name === options);
1181
- if (!ret) {
1182
- throw new Error('找不到输出参数 ' + options);
1183
- }
1184
- } else {
1185
- ret = options;
1186
- }
1187
- return ret.delete();
1188
- }
1189
-
1190
- __removeReturn(ret: Return) {
1191
- const parentKey = ret.parentKey;
1192
- const params: Params = {
1193
- parentNode: this,
1194
- parentKey,
1195
- index: -1,
1196
- object: null,
1197
- oldObject: ret,
1198
- };
1199
- if (parentKey) {
1200
- params.parentKey = parentKey;
1201
- if (Array.isArray((this as any)[parentKey])) {
1202
- const index = (this as any)[parentKey].indexOf(ret);
1203
- ~index && (this as any)[parentKey].splice(index, 1);
1204
- params.index = index;
1205
- } else if ((this as any)[parentKey] === ret) {
1206
- params.index = 0;
1207
- (this as any)[parentKey] = undefined;
1208
- }
1209
- }
1210
- return params;
1211
- }
1212
-
1213
- /**
1214
- * 删除变量
1215
- * @param name 变量名称
1216
- */
1217
- removeVariable(name: string): void;
1218
-
1219
- /**
1220
- * 删除变量
1221
- * @param variable 已有的变量实例
1222
- */
1223
- removeVariable(variable: Variable): void;
1224
-
1225
- removeVariable(options: string | Variable) {
1226
- let variable: Variable;
1227
- if (typeof options === 'string') {
1228
- variable = (this.variables as Variable[]).find((item) => item.name === options);
1229
- if (!variable) {
1230
- throw new Error('找不到变量 ' + options);
1231
- }
1232
- } else {
1233
- variable = options;
1234
- }
1235
- return variable.delete();
1236
- }
1237
-
1238
- __removeVariable(variable: Variable) {
1239
- const parentKey = variable.parentKey;
1240
- const params: Params = {
1241
- parentNode: this,
1242
- parentKey,
1243
- index: -1,
1244
- object: null,
1245
- oldObject: variable,
1246
- };
1247
- if (parentKey) {
1248
- params.parentKey = parentKey;
1249
- if (Array.isArray((this as any)[parentKey])) {
1250
- const index = (this as any)[parentKey].indexOf(variable);
1251
- ~index && (this as any)[parentKey].splice(index, 1);
1252
- params.index = index;
1253
- } else if ((this as any)[parentKey] === variable) {
1254
- params.index = 0;
1255
- (this as any)[parentKey] = undefined;
1256
- }
1257
- }
1258
- return params;
1259
- }
1260
-
1261
- /**
1262
- * 删除逻辑项
1263
- * @param logicItem 已有的逻辑项实例
1264
- */
1265
- removeItemInBody(logicItem: LogicItem): void;
1266
-
1267
- removeItemInBody(options: LogicItem) {
1268
- const logicItem: LogicItem = options;
1269
- return logicItem.delete();
1270
- }
1271
- /**
1272
- * 删除逻辑项
1273
- * @param logicItem 已有的逻辑项实例
1274
- */
1275
- removeItemInPlayground(logicItem: LogicItem): void;
1276
-
1277
- removeItemInPlayground(options: LogicItem) {
1278
- const logicItem: LogicItem = options;
1279
- return logicItem.delete();
1280
- }
1281
-
1282
- __removeLogicItem(logicItem: LogicItem) {
1283
- const parentKey = logicItem.parentKey;
1284
- const params: Params = {
1285
- parentNode: this,
1286
- parentKey,
1287
- index: -1,
1288
- object: null,
1289
- oldObject: logicItem,
1290
- };
1291
- if (parentKey) {
1292
- params.parentKey = parentKey;
1293
- if (Array.isArray((this as any)[parentKey])) {
1294
- const index = (this as any)[parentKey].indexOf(logicItem);
1295
- ~index && (this as any)[parentKey].splice(index, 1);
1296
- params.index = index;
1297
- } else if ((this as any)[parentKey] === logicItem) {
1298
- params.index = 0;
1299
- (this as any)[parentKey] = undefined;
1300
- }
1301
- }
1302
- return params;
1303
- }
1304
-
1305
- //================================================================================
1306
- // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
1307
- // 自动生成的代码已结束。下面可以手动编写。
1308
- //================================================================================
1309
- // 用于calllogic树中定位是那个logic,回显
1310
- get calleewholeKey() {
1311
- return this.getNamespace() + '.' + this.name;
1312
- }
1313
- // 设置定时任务
1314
- setCronAndTriggerType(cron: string, triggerType: string) {
1315
- const object = {
1316
- cron,
1317
- triggerType,
1318
- };
1319
- this.update({
1320
- ...object,
1321
- });
1322
- }
1323
-
1324
- /**
1325
- * 创建的时候 打开事务 通过开关设置数据库事务
1326
- */
1327
- openTransactional(flag: boolean) {
1328
- if (flag) {
1329
- const transactional = new Transactional({
1330
- enabled: flag,
1331
- });
1332
- transactional._delete();
1333
- const relationOptions = { parentNode: this, parentKey: 'transactional' };
1334
- Object.assign(transactional, relationOptions);
1335
- this.transactional = transactional;
1336
- }
1337
- }
1338
- findLogicItemByConcept(concept: string) {
1339
- let result: any;
1340
-
1341
- utils.traverse((current) => {
1342
- if ((current.node as any).concept === concept)
1343
- return (result = current.node);
1344
- }, { node: this }, {
1345
- mode: 'anyObject',
1346
- excludedKeySet: this.JSON_EXCLUDED_KEYS,
1347
- });
1348
-
1349
- return result as LogicItem;
1350
- }
1351
-
1352
- onChange($event?: EventPayload): void {
1353
- this.emit('change', $event);
1354
- }
1355
-
1356
- getVarExistingNames(excludedList: Array<Param | Return | Variable> = []) {
1357
- const excludedSet = new Set(excludedList);
1358
- const varList: any[] = [];
1359
- if (Array.isArray(this.params)) {
1360
- varList.push(...this.params);
1361
- }
1362
- if (Array.isArray(this.returns)) {
1363
- varList.push(...this.returns);
1364
- }
1365
- if (Array.isArray(this.variables)) {
1366
- varList.push(...this.variables);
1459
+ }
1460
+ });
1461
+ return varList.filter((item) => !excludedSet.has(item)).map((item) => item?.name);
1462
+ }
1463
+
1464
+ toJSContent(code: string, state?: TranslatorState): string {
1465
+ // params
1466
+ if (Array.isArray(this.params)) {
1467
+ this.params.forEach((param) => {
1468
+ code += `${indent((state?.tabSize || 0) + 1)}`;
1469
+ code += param.toJS(shiftState(state, code, { inline: true }));
1470
+ code += ';\n';
1471
+ });
1472
+ }
1473
+ // variables
1474
+ if (Array.isArray(this.variables)) {
1475
+ this.variables.forEach((variable) => {
1476
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1477
+ code += variable.toJS(shiftState(state, code, { inline: true }));
1478
+ code += ';\n';
1479
+ });
1480
+ }
1481
+
1482
+ // returns
1483
+ if (Array.isArray(this.returns)) {
1484
+ this.returns.forEach((ret) => {
1485
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1486
+ code += ret.toJS(shiftState(state, code, { inline: true }));
1487
+ code += ';\n';
1488
+ });
1489
+ }
1490
+ if (Array.isArray(this.body)) {
1491
+ this.body.forEach((item) => {
1492
+ code += item.toJS && item.toJS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1493
+ code += '\n';
1494
+ });
1495
+ }
1496
+
1497
+ return code;
1498
+ }
1499
+
1500
+ toJS(state?: TranslatorState, type?: string): string {
1501
+ let code = '';
1502
+ if (type === 'IIFE') {
1503
+ code += `await (async () => {\n`;
1504
+ code = this.toJSContent(code, state);
1505
+ code += `${indent(state?.tabSize || 0)}})();\n`;
1506
+ return code;
1507
+ }
1508
+ code += `async ${this.name} (`;
1509
+
1510
+ if (this.params?.length) {
1511
+ this.params.forEach((param, index) => {
1512
+ code += param.name;
1513
+ if (index !== this.params.length - 1) code += ', ';
1514
+ });
1515
+ }
1516
+ code += ') {\n';
1517
+
1518
+ code = this.toJSContent(code, state);
1519
+ code += `${indent(state?.tabSize || 0)}}\n`;
1520
+ return code;
1521
+ }
1522
+
1523
+ toProcessService() {
1524
+ return {
1525
+ config: {
1526
+ serviceType: 'micro',
1527
+ },
1528
+ url: {
1529
+ method: 'POST',
1530
+ path: this.getPath(),
1531
+ },
1532
+ };
1533
+ }
1534
+
1535
+ toService() {
1536
+ const { parentNode } = this;
1537
+ const { concept, name: entityName } = parentNode || {};
1538
+ const logicName = this.name;
1539
+ let serviceType = 'micro';
1540
+ let method = 'POST';
1541
+ let path = `/api/lcplogics/${logicName}`;
1542
+ if (concept === 'Module') {
1543
+ path = `/api/${entityName.replace('-', '_')}/${logicName}`;
1544
+ } else if (concept === 'Namespace') {
1545
+ serviceType = 'entity';
1546
+ let entityPath = entityName.replace(/[A-Z]/g, (char, index) => {
1547
+ const lowerChar = char.toLowerCase();
1548
+ return index === 0 ? lowerChar : `-${lowerChar}`;
1549
+ });
1550
+ const dataSource = parentNode.getAncestor('DataSource');
1551
+ // 默认数据源不动,其他数据源需要拼接数据源信息
1552
+ if (dataSource && dataSource.name !== 'defaultDS') {
1553
+ entityPath = `${dataSource.name}/${entityPath}`;
1554
+ }
1555
+ path = `/api/${entityPath}`;
1556
+ switch (this.name) {
1557
+ case 'get':
1558
+ method = 'GET';
1559
+ path = `/api/${entityPath}`;
1560
+ break;
1561
+ case 'create':
1562
+ method = 'POST';
1563
+ break;
1564
+ case 'update':
1565
+ method = 'PUT';
1566
+ break;
1567
+ case 'delete':
1568
+ method = 'DELETE';
1569
+ path = `/api/${entityPath}`;
1570
+ break;
1571
+ case 'createOrUpdate':
1572
+ method = 'POST';
1573
+ path = `/api/${entityPath}/createOrUpdate`;
1574
+ break;
1575
+ case 'updateBy':
1576
+ method = 'PUT';
1577
+ path = `/api/${entityPath}/by`;
1578
+ break;
1579
+ case 'deleteBy':
1580
+ method = 'DELETE';
1581
+ path = `/api/${entityPath}/by`;
1582
+ break;
1583
+ case 'batchCreate':
1584
+ method = 'POST';
1585
+ path = `/api/${entityPath}/batch`;
1586
+ break;
1587
+ case 'batchUpdate':
1588
+ method = 'PUT';
1589
+ path = `/api/${entityPath}/batch`;
1590
+ break;
1591
+ case 'batchDelete':
1592
+ method = 'DELETE';
1593
+ path = `/api/${entityPath}/batch`;
1594
+ break;
1595
+ case 'import':
1596
+ method = 'POST';
1597
+ path = `/api/${entityPath}/import`;
1598
+ break;
1599
+ default:
1600
+ break;
1601
+ }
1602
+ }
1603
+
1604
+ return {
1605
+ config: {
1606
+ serviceType,
1607
+ },
1608
+ url: {
1609
+ method,
1610
+ path,
1611
+ },
1612
+ };
1613
+ }
1614
+
1615
+ @withSourceMap()
1616
+ toEmbeddedTSInProcess(state?: TranslatorState, prependCode?: string, noName?: boolean, prefix?: boolean): string {
1617
+ let code = '';
1618
+ if (!prefix) code += `${noName ? '' : `${this.name}:`} function(`;
1619
+ else code += `function ${this.name}(`; // 加空格会导致无法查询到引用
1620
+ this.params.forEach((param, index) => {
1621
+ code += param.toEmbeddedTS(shiftState(state, code, { inline: true }));
1622
+ if (index !== this.params.length - 1) code += ', ';
1623
+ });
1624
+ code += `) {\n`;
1625
+ code += prependCode || '';
1626
+ code += '\n';
1627
+ this.variables.forEach((variable) => {
1628
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1629
+ code += variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
1630
+ code += ';\n';
1631
+ });
1632
+
1633
+ this.returns.forEach((ret) => {
1634
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1635
+ code += ret.toEmbeddedTS(shiftState(state, code, { inline: true }));
1636
+ code += ';\n';
1637
+ });
1638
+
1639
+ if (!this.body.length && this.returns.length) {
1640
+ code += `${indent((state?.tabSize || 0) + 1)}return ${this.returns[0].name};\n`;
1641
+ } else {
1642
+ if ((this.parentNode as any).type === 'ExclusiveGateway') {
1643
+ if (this.body.length <= 1) {
1644
+ code += indent((state?.tabSize || 0) + 1);
1645
+ code += 'const __LogicEmpty: any = null;';
1367
1646
  }
1368
- if (this.view) {
1369
- if (Array.isArray(this.view.params)) {
1370
- varList.push(...this.view.params);
1647
+ } else if (this.body.length <= 2 && !(this.parentNode instanceof Namespace) && !(this.parentNode instanceof Process)) {
1648
+ code += indent((state?.tabSize || 0) + 1);
1649
+ code += `${indent(state?.tabSize || 0 + 4)}const __LogicEmpty: any = null;`;
1650
+ }
1651
+ this.body.forEach((item) => {
1652
+ code += item.toEmbeddedTS && item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1653
+ code += ';\n';
1654
+ });
1655
+ }
1656
+
1657
+ // 在body渲染完成之后把其余的节点放到下面
1658
+ this.playground.forEach((item) => {
1659
+ code += item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1660
+ code += '\n';
1661
+ });
1662
+
1663
+ code += `${indent(state?.tabSize || 0 + 4)}}`;
1664
+ code += '\n';
1665
+ return code;
1666
+ }
1667
+
1668
+ toEmbeddedTSNoExport(state?: TranslatorState): string {
1669
+ return this.toEmbeddedTS(state, 'noExport');
1670
+ }
1671
+
1672
+ @withSourceMap()
1673
+ toEmbeddedTS(state?: TranslatorState, prefix?: string): string {
1674
+ // 如果传了不要前缀那就为空, 要不用传进来的,要是都没有就默认导出
1675
+ let code = '';
1676
+ if (!prefix) {
1677
+ code += `export function ${this.name}`;
1678
+ } else if (prefix === 'noExport') {
1679
+ code += `function ${this.name}`;
1680
+ } else if (prefix === 'inObject') {
1681
+ code += `${this.name}`;
1682
+ }
1683
+ if (this.typeParams?.length) {
1684
+ code += '<';
1685
+ this.typeParams.forEach((typeParam, typeParamIndex) => {
1686
+ code += typeParam.toEmbeddedTS(shiftState(state, code, { inline: true }));
1687
+ if (typeParamIndex !== this.typeParams.length - 1) code += ', ';
1688
+ });
1689
+ code += '>';
1690
+ }
1691
+ // 有参数长度
1692
+ if (this.params.length) {
1693
+ code += '(';
1694
+ this.params.forEach((param, index) => {
1695
+ code += param.toEmbeddedTS(shiftState(state, code));
1696
+ if (index !== this.params.length - 1) code += ', ';
1697
+ });
1698
+ code += ')';
1699
+ } else {
1700
+ // 没有参数的
1701
+ code += '()';
1702
+ }
1703
+
1704
+ // 需要类型推导的局部变量/返回值需要调整申明顺序
1705
+ const advanceMap: Map<Return | Variable, Assignment | BatchAssignment> = new Map();
1706
+ const needGetSourceMapOqlList: Promise<any>[] = [];
1707
+ this.traverseChildren((el) => {
1708
+ if (el && (el instanceof BatchAssignment || (el instanceof Assignment && el.left?.name))) {
1709
+ if (el instanceof Assignment) {
1710
+ const advanceVar = this.variables?.find((variable) => !variable.typeAnnotation && el.left?.name === variable.name);
1711
+ if (advanceVar && !advanceMap.get(advanceVar)) {
1712
+ advanceMap.set(advanceVar, el);
1713
+ }
1714
+ const advanceRn = this.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
1715
+ if (advanceRn && !advanceMap.get(advanceRn)) {
1716
+ advanceMap.set(advanceRn, el);
1717
+ }
1718
+ } else if (el instanceof BatchAssignment) {
1719
+ el.assignmentLines.forEach(({ leftIndex }) => {
1720
+ const leftCode =
1721
+ leftIndex.length === 1
1722
+ ? el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
1723
+ : el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true }));
1724
+ const advanceVar = this.variables?.find((variable) => !variable.typeAnnotation && leftCode === variable.name);
1725
+ if (advanceVar && !advanceMap.get(advanceVar)) {
1726
+ advanceMap.set(advanceVar, el);
1371
1727
  }
1372
- if (Array.isArray(this.view.variables)) {
1373
- varList.push(...this.view.variables);
1728
+ const advanceRn = this.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
1729
+ if (advanceRn && !advanceMap.get(advanceRn)) {
1730
+ advanceMap.set(advanceRn, el);
1374
1731
  }
1732
+ });
1375
1733
  }
1376
-
1377
- this.traverseChildren((el) => {
1378
- if (el?.concept === 'ForEachStatement') {
1379
- if ((el as ForEachStatement)?.item) {
1380
- varList.push((el as ForEachStatement)?.item);
1381
- }
1382
- if ((el as ForEachStatement)?.index) {
1383
- varList.push((el as ForEachStatement)?.index);
1384
- }
1385
- }
1386
- });
1387
- return varList.filter((item) => !excludedSet.has(item)).map((item) => item?.name);
1388
- }
1389
-
1390
- toJSContent(code: string, state?: TranslatorState): string {
1391
- // params
1392
- if (Array.isArray(this.params)) {
1393
- this.params.forEach((param) => {
1394
- code += indent((state?.tabSize || 0) + 1) + '';
1395
- code += param.toJS(shiftState(state, code, { inline: true }));
1396
- code += ';\n';
1397
- });
1398
- }
1399
- // variables
1400
- if (Array.isArray(this.variables)) {
1401
- this.variables.forEach((variable) => {
1402
- code += indent((state?.tabSize || 0) + 1) + 'let ';
1403
- code += variable.toJS(shiftState(state, code, { inline: true }));
1404
- code += ';\n';
1405
- });
1406
- }
1407
-
1408
- // returns
1409
- if (Array.isArray(this.returns)) {
1410
- this.returns.forEach((ret) => {
1411
- code += indent((state?.tabSize || 0) + 1) + 'let ';
1412
- code += ret.toJS(shiftState(state, code, { inline: true }));
1413
- code += ';\n';
1414
- });
1415
- }
1416
- if (Array.isArray(this.body)) {
1417
- this.body.forEach((item) => {
1418
- code += item.toJS && item.toJS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1419
- code += '\n';
1420
- });
1421
- }
1422
-
1423
- return code;
1424
- }
1425
- toJS(state?: TranslatorState, type?: string): string {
1426
- let code = '';
1427
- if (type === 'IIFE') {
1428
- code += `await (async () => {\n`;
1429
- code = this.toJSContent(code, state);
1430
- code += indent(state?.tabSize || 0) + '})();\n';
1431
- return code;
1432
- }
1433
- code += `async ${this.name} (`;
1434
-
1435
- if (this.params?.length) {
1436
- this.params.forEach((param, index) => {
1437
- code += param.name;
1438
- if (index !== this.params.length - 1)
1439
- code += ', ';
1440
- });
1734
+ }
1735
+ // 如果有sql查询组件就需要把他们存起来
1736
+ if (el instanceof OqlQueryComponent) {
1737
+ if (!el.codeSourceMap) {
1738
+ needGetSourceMapOqlList.push(el.requestEmbeddedTS());
1441
1739
  }
1442
- code += ') {\n';
1443
-
1444
- code = this.toJSContent(code, state);
1445
- code += indent(state?.tabSize || 0) + '}\n';
1446
- return code;
1447
- }
1448
-
1449
- toProcessService() {
1450
- return {
1451
- config: {
1452
- serviceType: 'micro',
1740
+ }
1741
+ });
1742
+
1743
+ if (needGetSourceMapOqlList.length) {
1744
+ Promise.all(needGetSourceMapOqlList).then(() => {
1745
+ // 触发一下更新重新生成代码
1746
+ (this.app as any)?.naslServer?.embeddedTSEmitter.emit('change', {
1747
+ value: [
1748
+ {
1749
+ originEvent: {
1750
+ action: 'update',
1751
+ target: this,
1752
+ },
1453
1753
  },
1454
- url: {
1455
- method: 'POST',
1456
- path: this.getPath(),
1457
- },
1458
- };
1459
- }
1460
-
1461
- toService() {
1462
- const parentNode = this.parentNode;
1463
- const { concept, name: entityName } = parentNode || {};
1464
- const logicName = this.name;
1465
- let serviceType = 'micro';
1466
- let method = 'POST';
1467
- let path = `/api/lcplogics/${logicName}`;
1468
- if (concept === 'Module') {
1469
- path = `/api/${entityName.replace('-', '_')}/${logicName}`;
1470
- } else if (concept === 'Namespace') {
1471
- serviceType = 'entity';
1472
- let entityPath = entityName.replace(/[A-Z]/g, (char, index) => {
1473
- const lowerChar = char.toLowerCase();
1474
- return index === 0 ? lowerChar : `-${lowerChar}`;
1475
- });
1476
- const dataSource = parentNode.getAncestor('DataSource');
1477
- // 默认数据源不动,其他数据源需要拼接数据源信息
1478
- if (dataSource && dataSource.name !== 'defaultDS') {
1479
- entityPath = dataSource.name + '/' + entityPath;
1480
- }
1481
- path = `/api/${entityPath}`;
1482
- switch (this.name) {
1483
- case 'get':
1484
- method = 'GET';
1485
- path = `/api/${entityPath}`;
1486
- break;
1487
- case 'create':
1488
- method = 'POST';
1489
- break;
1490
- case 'update':
1491
- method = 'PUT';
1492
- break;
1493
- case 'delete':
1494
- method = 'DELETE';
1495
- path = `/api/${entityPath}`;
1496
- break;
1497
- case 'createOrUpdate':
1498
- method = 'POST';
1499
- path = `/api/${entityPath}/createOrUpdate`;
1500
- break;
1501
- case 'updateBy':
1502
- method = 'PUT';
1503
- path = `/api/${entityPath}/by`;
1504
- break;
1505
- case 'deleteBy':
1506
- method = 'DELETE';
1507
- path = `/api/${entityPath}/by`;
1508
- break;
1509
- case 'batchCreate':
1510
- method = 'POST';
1511
- path = `/api/${entityPath}/batch`;
1512
- break;
1513
- case 'batchUpdate':
1514
- method = 'PUT';
1515
- path = `/api/${entityPath}/batch`;
1516
- break;
1517
- case 'batchDelete':
1518
- method = 'DELETE';
1519
- path = `/api/${entityPath}/batch`;
1520
- break;
1521
- case 'import':
1522
- method = 'POST';
1523
- path = `/api/${entityPath}/import`;
1524
- break;
1525
- default:
1526
- break;
1527
- }
1528
- }
1529
-
1530
- return {
1531
- config: {
1532
- serviceType,
1533
- },
1534
- url: {
1535
- method,
1536
- path,
1537
- },
1538
- };
1539
- }
1540
-
1541
- @withSourceMap()
1542
- toEmbeddedTSInProcess(state?: TranslatorState, prependCode?: string, noName?: boolean, prefix?: boolean): string {
1543
- let code = '';
1544
- if (!prefix)
1545
- code += `${noName ? '' : `${this.name}:`} function(`;
1546
- else
1547
- code += `function ${this.name}(`; //加空格会导致无法查询到引用
1548
- this.params.forEach((param, index) => {
1549
- code += param.toEmbeddedTS(shiftState(state, code, { inline: true }));
1550
- if (index !== this.params.length - 1)
1551
- code += ', ';
1552
- });
1553
- code += `) {\n`;
1554
- code += prependCode || '';
1555
- code += '\n';
1556
- this.variables.forEach((variable) => {
1557
- code += indent((state?.tabSize || 0) + 1) + 'let ';
1558
- code += variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
1559
- code += ';\n';
1754
+ ],
1560
1755
  });
1561
-
1562
- this.returns.forEach((ret) => {
1563
- code += indent((state?.tabSize || 0) + 1) + 'let ';
1564
- code += ret.toEmbeddedTS(shiftState(state, code, { inline: true }));
1565
- code += ';\n';
1566
- });
1567
-
1568
- if (!this.body.length && this.returns.length) {
1569
- code += indent((state?.tabSize || 0) + 1) + `return ${this.returns[0].name};\n`;
1570
- } else {
1571
- if ((this.parentNode as any).type === 'ExclusiveGateway') {
1572
- if (this.body.length <= 1) {
1573
- code += indent((state?.tabSize || 0) + 1);
1574
- code += 'const __LogicEmpty: any = null;';
1575
- }
1576
- } else if (this.body.length <= 2 && !(this.parentNode instanceof Namespace) && !(this.parentNode instanceof Process)) {
1577
- code += indent((state?.tabSize || 0) + 1);
1578
- code += indent(state?.tabSize || 0 + 4) + 'const __LogicEmpty: any = null;';
1579
- }
1580
- this.body.forEach((item) => {
1581
- code += item.toEmbeddedTS && item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1582
- code += ';\n';
1583
- });
1584
- }
1585
-
1586
- // 在body渲染完成之后把其余的节点放到下面
1587
- this.playground.forEach((item) => {
1588
- code += item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1589
- code += '\n';
1590
- });
1591
-
1592
- code += indent(state?.tabSize || 0 + 4) + '}';
1593
- code += '\n';
1594
- return code;
1756
+ });
1595
1757
  }
1596
-
1597
- toEmbeddedTSNoExport(state?: TranslatorState): string {
1598
- return this.toEmbeddedTS(state, 'noExport');
1758
+ // 兼容 return 没有类型情况
1759
+ if (this.returns.length && this.returns[0].typeAnnotation) {
1760
+ code += ': ';
1761
+ code += this.returns[0].typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true }));
1599
1762
  }
1763
+ code += '{\n';
1600
1764
 
1601
- @withSourceMap()
1602
- toEmbeddedTS(state?: TranslatorState, prefix?: string): string {
1603
- // 如果传了不要前缀那就为空, 要不用传进来的,要是都没有就默认导出
1604
- let code = '';
1605
- if (!prefix) {
1606
- code += `export function ${this.name}`;
1607
- } else if (prefix === 'noExport') {
1608
- code += `function ${this.name}`;
1609
- } else if (prefix === 'inObject') {
1610
- code += `${this.name}`;
1611
- }
1612
- if (this.typeParams?.length) {
1613
- code += '<';
1614
- this.typeParams.forEach((typeParam, typeParamIndex) => {
1615
- code += typeParam.toEmbeddedTS(shiftState(state, code, { inline: true }));
1616
- if (typeParamIndex !== this.typeParams.length - 1)
1617
- code += ', ';
1618
- });
1619
- code += '>';
1620
- }
1621
- // 有参数长度
1622
- if (this.params.length) {
1623
- code += '(';
1624
- this.params.forEach((param, index) => {
1625
- code += param.toEmbeddedTS(shiftState(state, code));
1626
- if (index !== this.params.length - 1)
1627
- code += ', ';
1628
- });
1629
- code += ')';
1630
- } else {
1631
- // 没有参数的
1632
- code += '()';
1633
- }
1634
-
1635
- // 需要类型推导的局部变量/返回值需要调整申明顺序
1636
- const advanceMap: Map<Return | Variable, Assignment | BatchAssignment> = new Map();
1637
- const needGetSourceMapOqlList: Promise<any>[] = [];
1638
- this.traverseChildren((el) => {
1639
- if (el && (el instanceof BatchAssignment || (el instanceof Assignment && el.left?.name))) {
1640
- if (el instanceof Assignment) {
1641
- const advanceVar = this.variables?.find((variable) => !variable.typeAnnotation && (el.left?.name === variable.name));
1642
- if (advanceVar && !advanceMap.get(advanceVar)) {
1643
- advanceMap.set(advanceVar, el);
1644
- }
1645
- const advanceRn = this.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
1646
- if (advanceRn && !advanceMap.get(advanceRn)) {
1647
- advanceMap.set(advanceRn, el);
1648
- }
1649
- } else if (el instanceof BatchAssignment) {
1650
- el.assignmentLines.forEach(({ leftIndex }) => {
1651
- const leftCode
1652
- = leftIndex.length === 1 ? el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true })) : el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true }));
1653
- const advanceVar = this.variables?.find((variable) => !variable.typeAnnotation && (leftCode === variable.name));
1654
- if (advanceVar && !advanceMap.get(advanceVar)) {
1655
- advanceMap.set(advanceVar, el);
1656
- }
1657
- const advanceRn = this.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
1658
- if (advanceRn && !advanceMap.get(advanceRn)) {
1659
- advanceMap.set(advanceRn, el);
1660
- }
1661
- });
1662
- }
1663
- }
1664
- // 如果有sql查询组件就需要把他们存起来
1665
- if (el instanceof OqlQueryComponent) {
1666
- if (!el.codeSourceMap) {
1667
- needGetSourceMapOqlList.push(el.requestEmbeddedTS());
1668
- }
1669
- }
1670
- });
1671
-
1672
- if (needGetSourceMapOqlList.length) {
1673
- Promise.all(needGetSourceMapOqlList).then(() => {
1674
- // 触发一下更新重新生成代码
1675
- (this.app as any)?.naslServer?.embeddedTSEmitter.emit('change', {
1676
- value: [
1677
- {
1678
- originEvent: {
1679
- action: 'update',
1680
- target: this,
1681
- },
1682
- },
1683
- ],
1684
- });
1685
- });
1686
- }
1687
- // 兼容 return 没有类型情况
1688
- if (this.returns.length && this.returns[0].typeAnnotation) {
1689
- code += ': ';
1690
- code += this.returns[0].typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true }));
1691
- }
1692
- code += '{\n';
1693
-
1694
- // 用于虚拟节点的查找引用
1695
- this.virtualParams
1696
- && Array.isArray(this.virtualParams)
1697
- && this.virtualParams.forEach((param) => {
1698
- code += indent((state?.tabSize || 0) + 1);
1699
- code += param.toEmbeddedNameTS(shiftState(state, code, { inline: true }));
1700
- code += '\n';
1701
- });
1702
-
1703
- this.variables.forEach((variable) => {
1704
- if (!advanceMap.get(variable)) {
1705
- code += indent((state?.tabSize || 0) + 1) + 'let ';
1706
- code += variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
1707
- code += ';\n';
1708
- }
1709
- });
1710
-
1711
- this.returns.forEach((ret) => {
1712
- if (!advanceMap.get(ret)) {
1713
- code += indent((state?.tabSize || 0) + 1) + 'let ';
1714
- code += ret.toEmbeddedTS(shiftState(state, code, { inline: true }));
1715
- code += ';\n';
1716
- }
1717
- });
1718
-
1719
- advanceMap.forEach((assignment, node) => {
1720
- code += indent((state?.tabSize || 0) + 1) + '// @ts-ignore\n';
1721
- code += indent((state?.tabSize || 0) + 1) + 'let ';
1722
- code += node.toEmbeddedTS(shiftState(state, code, { inline: true }));
1723
- if (assignment instanceof BatchAssignment) {
1724
- assignment.assignmentLines.forEach(({ leftIndex, rightIndex }) => {
1725
- const leftCode
1726
- = leftIndex.length === 1 ? assignment.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true })) : assignment.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true }));
1727
- if (leftCode === node.name) {
1728
- const rightNode: any = rightIndex.length === 1 ? assignment.rights[rightIndex[0]]?.expression : assignment.rights[rightIndex[0]]?.members[rightIndex[1]];
1729
- // 当右边有明确类型时,直接使用其类型。旧版本数据查询不能直接使用其 typeAnnotation
1730
- if (rightNode?.typeAnnotation && !(rightNode instanceof CallQueryComponent && !rightNode.isAutoInfer())) {
1731
- if (rightNode.concept === 'NewComposite' && rightNode.typeAnnotation?.typeKind === 'anonymousStructure') {
1732
- code += '= ';
1733
- code += rightNode.getInitCode(shiftState(state, code, { inline: true })) || 'null';
1734
- } else if (rightNode.concept === 'NewComposite' && rightNode.typeAnnotation?.typeKind === 'generic') {
1735
- code += '= ';
1736
- code += rightNode.getNewCompositeCode(shiftState(state, code, { inline: true })) || 'null';
1737
- } else {
1738
- code += ': ';
1739
- code += rightNode.typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) || 'null';
1740
- }
1741
- } else {
1742
- code += ' = ';
1743
- const rightCode = rightNode?.toEmbeddedTS(shiftState(state, code, { inline: true }));
1744
- code += this.getRightCode(rightCode, assignment, rightNode);
1745
- }
1746
- }
1747
- });
1748
- } else if (['NewList', 'NewMap'].includes(assignment.right?.concept) && !(assignment.right as any)?.typeAnnotation) {
1749
- const rightNode: any = assignment.right;
1750
- code += ' = ';
1751
- code += rightNode.getInitCode(shiftState(state, code, { inline: true }));
1752
- } else if (assignment.right?.concept === 'NewComposite' && (assignment.right as any)?.typeAnnotation?.typeKind === 'anonymousStructure') {
1753
- const rightNode: any = assignment.right;
1754
- code += ' = ';
1755
- code += rightNode.getInitCode(shiftState(state, code, { inline: true }));
1756
- } else if (assignment.right?.concept === 'NewComposite' && (assignment.right as any)?.typeAnnotation?.typeKind === 'generic') {
1757
- const rightNode: any = assignment.right;
1758
- code += ' = ';
1759
- code += rightNode.getNewCompositeCode(shiftState(state, code, { inline: true }));
1765
+ // 用于虚拟节点的查找引用
1766
+ this.virtualParams &&
1767
+ Array.isArray(this.virtualParams) &&
1768
+ this.virtualParams.forEach((param) => {
1769
+ code += indent((state?.tabSize || 0) + 1);
1770
+ code += param.toEmbeddedNameTS(shiftState(state, code, { inline: true }));
1771
+ code += '\n';
1772
+ });
1773
+
1774
+ this.variables.forEach((variable) => {
1775
+ if (!advanceMap.get(variable)) {
1776
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1777
+ code += variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
1778
+ code += ';\n';
1779
+ }
1780
+ });
1781
+
1782
+ this.returns.forEach((ret) => {
1783
+ if (!advanceMap.get(ret)) {
1784
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1785
+ code += ret.toEmbeddedTS(shiftState(state, code, { inline: true }));
1786
+ code += ';\n';
1787
+ }
1788
+ });
1789
+
1790
+ advanceMap.forEach((assignment, node) => {
1791
+ code += `${indent((state?.tabSize || 0) + 1)}// @ts-ignore\n`;
1792
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1793
+ code += node.toEmbeddedTS(shiftState(state, code, { inline: true }));
1794
+ if (assignment instanceof BatchAssignment) {
1795
+ assignment.assignmentLines.forEach(({ leftIndex, rightIndex }) => {
1796
+ const leftCode =
1797
+ leftIndex.length === 1
1798
+ ? assignment.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
1799
+ : assignment.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true }));
1800
+ if (leftCode === node.name) {
1801
+ const rightNode: any =
1802
+ rightIndex.length === 1 ? assignment.rights[rightIndex[0]]?.expression : assignment.rights[rightIndex[0]]?.members[rightIndex[1]];
1803
+ // 当右边有明确类型时,直接使用其类型。旧版本数据查询不能直接使用其 typeAnnotation
1804
+ if (rightNode?.typeAnnotation && !(rightNode instanceof CallQueryComponent && !rightNode.isAutoInfer())) {
1805
+ if (rightNode.concept === 'NewComposite' && rightNode.typeAnnotation?.typeKind === 'anonymousStructure') {
1806
+ code += '= ';
1807
+ code += rightNode.getInitCode(shiftState(state, code, { inline: true })) || 'null';
1808
+ } else if (rightNode.concept === 'NewComposite' && rightNode.typeAnnotation?.typeKind === 'generic') {
1809
+ code += '= ';
1810
+ code += rightNode.getNewCompositeCode(shiftState(state, code, { inline: true })) || 'null';
1811
+ } else {
1812
+ code += ': ';
1813
+ code += rightNode.typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) || 'null';
1814
+ }
1760
1815
  } else {
1761
- const rightNode: any = assignment.right;
1762
- // 当右边有明确类型时,直接使用其类型。旧版本数据查询不能直接使用其 typeAnnotation
1763
- if (rightNode?.typeAnnotation && !(rightNode instanceof CallQueryComponent && !rightNode.isAutoInfer())) {
1764
- code += ': ';
1765
- code += rightNode.typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) || 'null';
1766
- } else {
1767
- code += ' = ';
1768
- let rightCode = '';
1769
- // 因为右侧枚举要赋值就得new 一下;
1770
- if (rightNode && rightNode instanceof Identifier && rightNode.namespace && rightNode.namespace.endsWith('enums')) {
1771
- rightCode += 'new ';
1772
- }
1773
- rightCode += rightNode && rightNode.toEmbeddedTS ? rightNode.toEmbeddedTS(shiftState(state, code, { inline: true })) : '__RIGHT__';
1774
- code += this.getRightCode(rightCode, assignment, rightNode);
1775
- }
1816
+ code += ' = ';
1817
+ const rightCode = rightNode?.toEmbeddedTS(shiftState(state, code, { inline: true }));
1818
+ code += this.getRightCode(rightCode, assignment, rightNode);
1776
1819
  }
1777
- code += ';\n';
1820
+ }
1778
1821
  });
1779
-
1780
- if (!this.body.length && this.returns.length) {
1781
- code += indent((state?.tabSize || 0) + 1) + `return ${this.returns[0].name};\n`;
1822
+ } else if (['NewList', 'NewMap'].includes(assignment.right?.concept) && !(assignment.right as any)?.typeAnnotation) {
1823
+ const rightNode: any = assignment.right;
1824
+ code += ' = ';
1825
+ code += rightNode.getInitCode(shiftState(state, code, { inline: true }));
1826
+ } else if (assignment.right?.concept === 'NewComposite' && (assignment.right as any)?.typeAnnotation?.typeKind === 'anonymousStructure') {
1827
+ const rightNode: any = assignment.right;
1828
+ code += ' = ';
1829
+ code += rightNode.getInitCode(shiftState(state, code, { inline: true }));
1830
+ } else if (assignment.right?.concept === 'NewComposite' && (assignment.right as any)?.typeAnnotation?.typeKind === 'generic') {
1831
+ const rightNode: any = assignment.right;
1832
+ code += ' = ';
1833
+ code += rightNode.getNewCompositeCode(shiftState(state, code, { inline: true }));
1834
+ } else {
1835
+ const rightNode: any = assignment.right;
1836
+ // 当右边有明确类型时,直接使用其类型。旧版本数据查询不能直接使用其 typeAnnotation
1837
+ if (rightNode?.typeAnnotation && !(rightNode instanceof CallQueryComponent && !rightNode.isAutoInfer())) {
1838
+ code += ': ';
1839
+ code += rightNode.typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) || 'null';
1782
1840
  } else {
1783
- // 如果长度小于2 并且不是虚拟节点就 报错,
1784
- if (this.body.length <= 2 && !(this.parentNode instanceof Namespace)) {
1785
- if (this.body.length && this.body[0].concept === 'JavaLogic') {
1786
- code += '';
1787
- } else {
1788
- code += indent((state?.tabSize || 0) + 1);
1789
- code += 'const __LogicEmpty: any = null;';
1790
- }
1791
- }
1792
- this.body.forEach((item) => {
1793
- code += item.toEmbeddedTS && item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1794
- code += ';\n';
1795
- });
1796
- }
1797
-
1798
- // 在body渲染完成之后把其余的节点放到下面
1799
- this.playground.forEach((item) => {
1800
- code += item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1801
- code += ';\n';
1802
- });
1803
-
1804
- code += indent(state?.tabSize || 0) + '}';
1805
- if (prefix === 'inObject') {
1806
- code += `,`;
1841
+ code += ' = ';
1842
+ let rightCode = '';
1843
+ // 因为右侧枚举要赋值就得new 一下;
1844
+ if (rightNode && rightNode instanceof Identifier && rightNode.namespace && rightNode.namespace.endsWith('enums')) {
1845
+ rightCode += 'new ';
1846
+ }
1847
+ rightCode += rightNode && rightNode.toEmbeddedTS ? rightNode.toEmbeddedTS(shiftState(state, code, { inline: true })) : '__RIGHT__';
1848
+ code += this.getRightCode(rightCode, assignment, rightNode);
1807
1849
  }
1808
- code += '\n';
1809
- return code;
1810
- }
1811
-
1812
- getRightCode(code: string, assignment: Assignment | BatchAssignment, rightNode: any): string {
1813
- code = code.replaceAll('\n', ' ');
1814
- if (assignment instanceof Assignment && !assignment.right)
1815
- return code;
1816
-
1817
- // 调用接口,参数替换成 null
1818
- if (rightNode instanceof CallInterface) {
1819
- const { _interface } = rightNode.getModuleInterface();
1820
- return _interface ? `${rightNode.tsCalleeKey}(${_interface.params.map(() => 'null').join(',')})` : null;
1821
- }
1822
-
1823
- // 调用服务端逻辑,参数替换成 null
1824
- if (rightNode instanceof CallLogic && rightNode.calleeNamespace === 'app.logics') {
1825
- const calleeName = rightNode?.calleeName;
1826
- const calleeLogic = this.app.logics.find((l) => l.name === calleeName);
1827
- return calleeLogic ? `app.logics.${calleeName}(${calleeLogic.params.map(() => 'null').join(',')})` : null;
1828
- }
1829
-
1830
- // ForEachStatement 内部变量需要替换处理,如 item、index
1831
- const forEachStatement = assignment.getAncestor('ForEachStatement') as ForEachStatement;
1832
- if (forEachStatement) {
1833
- code = this.handleForEachCode(code, forEachStatement);
1834
- }
1835
- // Match 需要针对分支缩小类型范围
1836
- const matchCase = assignment.getAncestor('MatchCase') as MatchCase;
1837
- if (matchCase) {
1838
- code = this.handleMatchCaseCode(code, matchCase);
1839
- }
1840
- return code;
1841
- }
1842
-
1843
- handleReplaceCode(code: string, variable: string, replaceCode: string) {
1844
- return code.replace(/\S+/g, ($1) => {
1845
- if ($1 === `${variable},`)
1846
- return `${replaceCode},`;
1847
- if ($1 === variable)
1848
- return replaceCode;
1849
-
1850
- let fnCode = $1;
1851
- if ($1.startsWith(`${variable}.`))
1852
- fnCode = $1.replaceAll(`${variable}.`, `${replaceCode}.`);
1853
- if ($1.startsWith(`${variable},`))
1854
- fnCode = $1.replaceAll(`${variable},`, `${replaceCode},`);
1855
- if ($1.includes(`(${variable},`))
1856
- fnCode = $1.replaceAll(`(${variable},`, `(${replaceCode},`);
1857
- if ($1.includes(`(${variable}.`))
1858
- fnCode = $1.replaceAll(`(${variable}.`, `(${replaceCode}.`);
1859
- if ($1.includes(`(${variable})`))
1860
- fnCode = $1.replaceAll(`(${variable})`, `(${replaceCode})`);
1861
- if ($1.includes(`,${variable},`))
1862
- fnCode = $1.replaceAll(`,${variable},`, `,${replaceCode},`);
1863
- if ($1.includes(`,${variable}.`))
1864
- fnCode = $1.replaceAll(`,${variable}.`, `,${replaceCode}.`);
1865
- if ($1.includes(`,${variable})`))
1866
- fnCode = $1.replaceAll(`,${variable})`, `,${replaceCode})`);
1867
- return fnCode;
1868
- });
1869
- }
1870
-
1871
- handleForEachCode(code: string, forEachStatement: ForEachStatement): string {
1872
- const { item, index, each } = forEachStatement;
1873
- if (code.includes(item.name)) {
1874
- const eachTSCode = each.toEmbeddedTS();
1875
- code = this.handleReplaceCode(code, item.name, eachTSCode === '__IDENTIFIER__' ? eachTSCode : `${eachTSCode}.__get(0)`);
1876
- }
1877
- if (code.includes(index.name))
1878
- code = this.handleReplaceCode(code, index.name, 'new nasl.core.Long(0)');
1879
-
1880
- const parentForEachStatement = forEachStatement.getAncestor('ForEachStatement') as ForEachStatement;
1881
- if (parentForEachStatement) {
1882
- this.handleForEachCode(code, parentForEachStatement);
1883
- }
1884
- return code;
1885
- }
1886
-
1887
- handleMatchCaseCode(code: string, matchCase: MatchCase): string {
1888
- const match = matchCase.getAncestor('Match') as Match;
1889
- const expressionTsCode = match.expression.toEmbeddedTS();
1890
- if (code.includes(expressionTsCode)) {
1891
- let typeCode = '';
1892
- matchCase.patterns.forEach((pattern, index) => {
1893
- if (pattern instanceof TypeAnnotation) {
1894
- if (index === 0) {
1895
- typeCode += pattern.toEmbeddedTS();
1896
- } else {
1897
- typeCode += '|';
1898
- typeCode += pattern.toEmbeddedTS();
1899
- }
1900
- }
1901
- });
1902
- if (typeCode) {
1903
- code = this.handleReplaceCode(code, expressionTsCode, `(${expressionTsCode} as ${typeCode})`);
1904
- }
1905
- }
1906
- const parentMatchCase = match.getAncestor('MatchCase') as MatchCase;
1907
- if (parentMatchCase) {
1908
- code = this.handleMatchCaseCode(code, parentMatchCase);
1909
- }
1910
- return code;
1911
- }
1912
-
1913
- getNamespace(): string {
1914
- if (this.parentNode) {
1915
- const parentNamespace = (this.parentNode as any)?.getNamespace();
1916
- // 针对Connector, 其对应的引入入口只有连接器。且唯一标识由
1917
- // calleeName、calleeNamespace、calleeConnectorName 三个字段组合确认,
1918
- // 故这里只返回 Connector 对应的nameSpace 且 三字段组合默认会含带logic 字段
1919
- // 因此最后 CallConnector 的 calleewholeKey 为 : `${calleeNamespace}.${calleeConnectorName}.logics.${calleeName}`
1920
- if (this.parentNode.concept === 'Connector') {
1921
- return parentNamespace;
1922
- }
1923
- const parentName = this.parentNode.name;
1924
- const arr = [parentNamespace];
1925
- if (this.parentNode.concept !== 'App' && parentName) {
1926
- arr.push(parentName);
1927
- }
1928
- let namespace = arr.join('.');
1929
- if (
1930
- !['nasl.ui', 'nasl.utils', 'nasl.util', 'nasl.browser', 'nasl.auth', 'nasl.configuration', 'nasl.process', 'nasl.logging', 'nasl.io'].includes(namespace)
1931
- && !namespace.includes('.logics')
1932
- ) {
1933
- namespace = `${namespace}.logics`;
1934
- }
1935
- return namespace;
1936
- } else
1937
- throw new Error('无法获取命名空间,请设置 parentNode!');
1938
- }
1939
-
1940
- getTsNamespace(): string {
1941
- if (this.parentNode) {
1942
- const parentNamespace = (this.parentNode as any)?.getTsNamespace();
1943
- const parentName = this.parentNode.tsName || this.parentNode.name;
1944
- const arr = [parentNamespace];
1945
- if (this.parentNode.concept !== 'App' && parentName) {
1946
- arr.push(parentName);
1947
- }
1948
- let namespace = arr.join('.');
1949
- if (
1950
- !['nasl.ui', 'nasl.utils', 'nasl.util', 'nasl.browser', 'nasl.auth', 'nasl.configuration', 'nasl.process', 'nasl.logging', 'nasl.io'].includes(namespace)
1951
- && !namespace.includes('.logics')
1952
- ) {
1953
- namespace = `${namespace}.logics`;
1954
- }
1955
- return namespace;
1956
- } else
1957
- throw new Error('无法获取命名空间,请设置 parentNode!');
1958
- }
1959
-
1960
- /**
1961
- * 生成宿主语言的文件路径
1962
- * @param name 一般不用传,用于 rename
1963
- */
1964
- getEmbeddedFilePath(name = this.name) {
1965
- let _path = '';
1966
- if (this.module) {
1967
- _path = `/${this.module.parentKey}/${this.module.name}`;
1968
- } else if (this.connector) {
1969
- _path = `/${this.connector.parentKey}/${this.connector.name}`;
1850
+ }
1851
+ code += ';\n';
1852
+ });
1853
+
1854
+ if (!this.body.length && this.returns.length) {
1855
+ code += `${indent((state?.tabSize || 0) + 1)}return ${this.returns[0].name};\n`;
1856
+ } else {
1857
+ // 如果长度小于2 并且不是虚拟节点就 加 报错,
1858
+ if (this.body.length <= 2 && !(this.parentNode instanceof Namespace)) {
1859
+ if (this.body.length && this.body[0].concept === 'JavaLogic') {
1860
+ code += '';
1861
+ } else {
1862
+ code += indent((state?.tabSize || 0) + 1);
1863
+ code += 'const __LogicEmpty: any = null;';
1970
1864
  }
1971
- if (this.parentNode instanceof FrontendLibrary) {
1972
- _path += `/frontends/${this.parentNode.type}`;
1973
- } else if (this.parentNode.concept === 'BindEvent' && this.parentNode?.parentNode.concept === 'Frontend') {
1974
- _path += `/frontends/${this.parentNode.parentNode.name}/bindEvents/${name}.ts`;
1865
+ }
1866
+ this.body.forEach((item) => {
1867
+ code += item.toEmbeddedTS && item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1868
+ code += ';\n';
1869
+ });
1870
+ }
1871
+
1872
+ // 在body渲染完成之后把其余的节点放到下面
1873
+ this.playground.forEach((item) => {
1874
+ code += item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1875
+ code += ';\n';
1876
+ });
1877
+
1878
+ code += `${indent(state?.tabSize || 0)}}`;
1879
+ if (prefix === 'inObject') {
1880
+ code += `,`;
1881
+ }
1882
+ code += '\n';
1883
+ return code;
1884
+ }
1885
+
1886
+ @withSourceMap()
1887
+ toNaturalTS(state?: TranslatorState, prefix?: string, logicName?: string): string {
1888
+ if (!logicName) {
1889
+ if (this.parentNode instanceof BindEvent && this.parentNode.parentNode instanceof View) {
1890
+ logicName = `on_view_${this.name}`;
1891
+ } else if (this.parentNode instanceof BindEvent && this.parentNode.parentNode instanceof ViewElement) {
1892
+ logicName = `on_${(this.parentNode as BindEvent).element.name}_${this.name}`;
1893
+ } else {
1894
+ logicName = this.name;
1895
+ }
1896
+ }
1897
+
1898
+ // 如果传了不要前缀那就为空, 要不用传进来的,要是都没有就默认导出
1899
+ let code = '';
1900
+ if (!prefix) {
1901
+ code += `export function ${logicName}`;
1902
+ } else if (prefix === 'noExport') {
1903
+ code += `function ${logicName}`;
1904
+ } else if (prefix === 'inObject') {
1905
+ code += `${logicName}`;
1906
+ }
1907
+ if (this.typeParams?.length) {
1908
+ code += '<';
1909
+ this.typeParams.forEach((typeParam, typeParamIndex) => {
1910
+ code += typeParam.toNaturalTS(shiftState(state, code, { inline: true }));
1911
+ if (typeParamIndex !== this.typeParams.length - 1)
1912
+ code += ', ';
1913
+ });
1914
+ code += '>';
1915
+ }
1916
+ // 有参数长度
1917
+ code += '(';
1918
+ this.params.forEach((param, index) => {
1919
+ code += param.toNaturalTS(shiftState(state, code, { inline: true }));
1920
+ if (index !== this.params.length - 1)
1921
+ code += ', ';
1922
+ });
1923
+
1924
+ code += ')';
1925
+
1926
+ // 需要类型推导的局部变量/返回值需要调整申明顺序
1927
+ const advanceMap: Map<Return | Variable, Assignment | BatchAssignment> = new Map();
1928
+ const needGetSourceMapOqlList: Promise<any>[] = [];
1929
+ this.traverseChildren((el) => {
1930
+ if (el && (el instanceof BatchAssignment || (el instanceof Assignment && el.left?.name))) {
1931
+ const jsCode = el.toJS();
1932
+ const advanceVar = this.variables?.find((variable) =>
1933
+ !variable.typeAnnotation && jsCode.includes(`${variable.name} = `));
1934
+ if (advanceVar && !advanceMap.get(advanceVar)) {
1935
+ advanceMap.set(advanceVar, el);
1975
1936
  }
1976
- return `/embedded/${this.app.name}${_path}/logics/${name}.ts`;
1977
- }
1978
-
1979
- toEmbeddedTSFile() {
1980
- let code = `namespace ${this.getTsNamespace()} {\n`;
1981
-
1982
- const state = createCompilerState(code, { tabSize: 1 });
1983
- try {
1984
- code += this.toEmbeddedTS(state);
1985
- } catch (err) {
1986
- console.log(err, `有问题翻译失败:${this.getTsNamespace()}.${this.name}`);
1987
- code += '';
1988
- console.log(err);
1937
+ const advanceRn = this.returns?.find((ret) =>
1938
+ !ret.typeAnnotation && jsCode.includes(`${ret.name} = `));
1939
+ if (advanceRn && !advanceMap.get(advanceRn)) {
1940
+ advanceMap.set(advanceRn, el);
1989
1941
  }
1990
- code += '}\n';
1991
- return {
1992
- code,
1993
- filePath: this.getEmbeddedFilePath(),
1994
- sourceMap: state.sourceMap,
1995
- };
1996
- }
1997
-
1998
- public static getDefaultOptions(): Partial<{
1999
- body: Array<any>,
2000
- params: Array<any>,
2001
- returns: Array<any>,
2002
- }> {
2003
- return {
2004
- body: [
2005
- {
2006
- concept: 'Start',
2007
- label: '开始',
2008
- kind: 'Statement',
2009
- type: 'Start',
2010
- },
2011
- {
2012
- concept: 'End',
2013
- label: '结束',
2014
- kind: 'Statement',
2015
- type: 'End',
2016
- },
2017
- ],
2018
- };
2019
- }
2020
-
2021
- async saveStructureOfCallQueryComponents(root?: BaseNode | Logic) {
2022
- if (!root)
2023
- root = this;
2024
- const set = new Set();
2025
- utils.traverse(({ node }) => {
2026
- if (node instanceof CallQueryComponent) {
2027
- set.add(node);
2028
- }
2029
- }, { node: root }, {
2030
- mode: 'anyObject',
2031
- excludedKeySet: new Set(['parentNode', '__assignment__']),
2032
- });
2033
- for (const node of set) {
2034
- (<CallQueryComponent>node).saveStructure();
1942
+ }
1943
+ // 如果有sql查询组件就需要把他们存起来
1944
+ if (el instanceof OqlQueryComponent) {
1945
+ if (!el.codeSourceMap) {
1946
+ needGetSourceMapOqlList.push(el.requestEmbeddedTS());
2035
1947
  }
2036
- }
2037
-
2038
- // 通过开关设置数据库事务
2039
- setTransactionEnabled(flag: boolean) {
2040
- this.setTransactional(new Transactional({
2041
- enabled: flag,
2042
- }));
2043
- }
2044
- fake: boolean;
2045
-
2046
- getPath: () => string;
2047
-
2048
- delete() {
2049
- let actionMsg = '删除逻辑项';
2050
- if (this.name)
2051
- actionMsg += `“${this.name}”`;
2052
- this.app?.emit('collect:start', {
2053
- actionMsg,
2054
- });
2055
- super.delete();
2056
- this.traverseChildren((el) => {
2057
- if (el?.concept === 'CallQueryComponent')
2058
- (el as CallQueryComponent).removeStructure();
1948
+ }
1949
+ });
1950
+
1951
+ if (needGetSourceMapOqlList.length) {
1952
+ Promise.all(needGetSourceMapOqlList).then(() => {
1953
+ // 触发一下更新重新生成代码
1954
+ (this.app as any)?.naslServer?.embeddedTSEmitter.emit('change', {
1955
+ value: [{
1956
+ originEvent: {
1957
+ action: 'update',
1958
+ target: this,
1959
+ },
1960
+ }],
2059
1961
  });
2060
- this.app?.emit('collect:end');
2061
- }
2062
-
2063
- // 是不是内部有错误
2064
- haveError: boolean = false;
2065
-
2066
- // 是否body为空
2067
- isSmpty: boolean = false;
2068
-
2069
- get exportInterface() {
2070
- return (this.rootNode as App)?.interfaces?.find((item) => item.originLogicName === this.name);
2071
- }
2072
-
2073
- get pathName(): string {
2074
- if (this.view) {
2075
- return this.getEventLogicName('chinese');
2076
- } else if (this.parentNode.concept === 'BindEvent' && this.parentNode.parentNode.concept === 'Frontend') {
2077
- const frontEndEventNameMap = {
2078
- rendered: '应用进入后',
2079
- preRequest: '调用服务端逻辑前',
2080
- postRequest: '调用服务端逻辑后',
2081
- beforeRouter: '页面切换前',
2082
- afterRouter: '页面切换后',
2083
- };
2084
- const pathName = [this.name];
2085
- let parentNode: SynatxNode = this.parentNode;
2086
- while (parentNode && parentNode.concept !== 'Frontend') {
2087
- const name = (frontEndEventNameMap as any)[parentNode.name] || parentNode.name;
2088
- pathName.unshift(name);
2089
- parentNode = parentNode.parentNode;
2090
- }
2091
- return pathName.join('-');
2092
- }
2093
-
2094
- const nameMap = {
2095
- OnProcessStart: '流程开始时',
2096
- OnTasksCreate: '任务创建时',
2097
- OnTasksOpen: '任务打开时',
2098
- OnTasksClose: '任务关闭时',
2099
- OnCreate: '用户任务创建时',
2100
- OnOpen: '用户任务打开时',
2101
- OnClose: '用户任务关闭时',
2102
- };
2103
- const pathName = [this.name];
2104
- let parentNode = this.parentNode;
2105
- while (parentNode && parentNode.concept !== 'Process') {
2106
- const name = (nameMap as any)[parentNode.name] || parentNode.name;
2107
- pathName.unshift(name);
2108
- parentNode = parentNode.parentNode;
1962
+ });
1963
+ }
1964
+ // 兼容 return 没有类型情况
1965
+ if (this.returns.length && this.returns[0].typeAnnotation) {
1966
+ code += ': ';
1967
+ code += this.returns[0].typeAnnotation?.toNaturalTS(shiftState(state, code, { inline: true }));
1968
+ }
1969
+ code += ' {\n';
1970
+ this.variables.forEach((variable) => {
1971
+ code += `${indent(state.tabSize + 1)}let `;
1972
+ code += variable.toNaturalTS(shiftState(state, code, { inline: true }));
1973
+ code += ';\n';
1974
+ });
1975
+
1976
+ this.returns.forEach((ret) => {
1977
+ code += `${indent(state.tabSize + 1)}let `;
1978
+ code += ret.toNaturalTS(shiftState(state, code, { inline: true }));
1979
+ code += ';\n';
1980
+ });
1981
+
1982
+ code += `${indent(state.tabSize + 1)}// 当前位置\n`;
1983
+ if (!this.body.length && this.returns.length) {
1984
+ code += `${indent(state.tabSize + 1)}return ${this.returns[0].name};\n`;
1985
+ } else {
1986
+ this.body.forEach((item) => {
1987
+ let partialCode = '';
1988
+ if (item.toNaturalTS) {
1989
+ partialCode = item.toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1 }));
1990
+ } else if (item.toEmbeddedTS) {
1991
+ partialCode = item.toEmbeddedTS(shiftState(state, code, { tabSize: state.tabSize + 1 }));
2109
1992
  }
2110
- return pathName.join('-');
2111
- }
2112
- // 获取bindEvent下的logic的名称
2113
- getEventLogicName(type?: string) {
2114
- if (this.parentNode instanceof BindEvent) {
2115
- if (type === 'chinese') {
2116
- const bindEvent = this.parentNode;
2117
- const bindChineseName = bindEvent.getPageViewEventChineseName();
2118
- return `${bindChineseName} -${this.name} `;
2119
- }
1993
+ if (partialCode.trim()) {
1994
+ code += partialCode;
1995
+ code += '\n';
2120
1996
  }
2121
- return this.name;
2122
- }
2123
-
2124
- // 虚拟输入参数列表
2125
- virtualParams: Array<Param> = [];
2126
-
2127
- get getLogicBelongTo() {
2128
- const [, belongTo] = this.calleewholeKey.split('.');
2129
- return belongTo;
2130
- }
2131
-
2132
- // 校验logic的返回值是不是有error类型
2133
- static checkLogicReturnTypeHasError(logic: Logic) {
2134
- let findHasError = false;
2135
- if (!logic) {
2136
- return findHasError;
1997
+ });
1998
+ }
1999
+
2000
+ code += `${indent(state.tabSize)}}`;
2001
+ if (prefix === 'inObject') {
2002
+ code += `,`;
2003
+ }
2004
+ code += '\n';
2005
+ return code;
2006
+ }
2007
+
2008
+ getRightCode(code: string, assignment: Assignment | BatchAssignment, rightNode: any): string {
2009
+ code = code.replaceAll('\n', ' ');
2010
+ if (assignment instanceof Assignment && !assignment.right) return code;
2011
+
2012
+ // 调用接口,参数替换成 null
2013
+ if (rightNode instanceof CallInterface) {
2014
+ const { _interface } = rightNode.getModuleInterface();
2015
+ return _interface ? `${rightNode.tsCalleeKey}(${_interface.params.map(() => 'null').join(',')})` : null;
2016
+ }
2017
+
2018
+ // 调用服务端逻辑,参数替换成 null
2019
+ if (rightNode instanceof CallLogic && rightNode.calleeNamespace === 'app.logics') {
2020
+ const calleeName = rightNode?.calleeName;
2021
+ const calleeLogic = this.app.logics.find((l) => l.name === calleeName);
2022
+ return calleeLogic ? `app.logics.${calleeName}(${calleeLogic.params.map(() => 'null').join(',')})` : null;
2023
+ }
2024
+
2025
+ // ForEachStatement 内部变量需要替换处理,如 item、index
2026
+ const forEachStatement = assignment.getAncestor('ForEachStatement') as ForEachStatement;
2027
+ if (forEachStatement) {
2028
+ code = this.handleForEachCode(code, forEachStatement);
2029
+ }
2030
+ // Match 需要针对分支缩小类型范围
2031
+ const matchCase = assignment.getAncestor('MatchCase') as MatchCase;
2032
+ if (matchCase) {
2033
+ code = this.handleMatchCaseCode(code, matchCase);
2034
+ }
2035
+ return code;
2036
+ }
2037
+
2038
+ handleReplaceCode(code: string, variable: string, replaceCode: string) {
2039
+ return code.replace(/\S+/g, ($1) => {
2040
+ if ($1 === `${variable},`) return `${replaceCode},`;
2041
+ if ($1 === variable) return replaceCode;
2042
+
2043
+ let fnCode = $1;
2044
+ if ($1.startsWith(`${variable}.`)) fnCode = $1.replaceAll(`${variable}.`, `${replaceCode}.`);
2045
+ if ($1.startsWith(`${variable},`)) fnCode = $1.replaceAll(`${variable},`, `${replaceCode},`);
2046
+ if ($1.includes(`(${variable},`)) fnCode = $1.replaceAll(`(${variable},`, `(${replaceCode},`);
2047
+ if ($1.includes(`(${variable}.`)) fnCode = $1.replaceAll(`(${variable}.`, `(${replaceCode}.`);
2048
+ if ($1.includes(`(${variable})`)) fnCode = $1.replaceAll(`(${variable})`, `(${replaceCode})`);
2049
+ if ($1.includes(`,${variable},`)) fnCode = $1.replaceAll(`,${variable},`, `,${replaceCode},`);
2050
+ if ($1.includes(`,${variable}.`)) fnCode = $1.replaceAll(`,${variable}.`, `,${replaceCode}.`);
2051
+ if ($1.includes(`,${variable})`)) fnCode = $1.replaceAll(`,${variable})`, `,${replaceCode})`);
2052
+ return fnCode;
2053
+ });
2054
+ }
2055
+
2056
+ handleForEachCode(code: string, forEachStatement: ForEachStatement): string {
2057
+ const { item, index, each } = forEachStatement;
2058
+ if (code.includes(item.name)) {
2059
+ const eachTSCode = each.toEmbeddedTS();
2060
+ code = this.handleReplaceCode(code, item.name, eachTSCode === '__IDENTIFIER__' ? eachTSCode : `${eachTSCode}.__get(0)`);
2061
+ }
2062
+ if (code.includes(index.name)) code = this.handleReplaceCode(code, index.name, 'new nasl.core.Long(0)');
2063
+
2064
+ const parentForEachStatement = forEachStatement.getAncestor('ForEachStatement') as ForEachStatement;
2065
+ if (parentForEachStatement) {
2066
+ this.handleForEachCode(code, parentForEachStatement);
2067
+ }
2068
+ return code;
2069
+ }
2070
+
2071
+ handleMatchCaseCode(code: string, matchCase: MatchCase): string {
2072
+ const match = matchCase.getAncestor('Match') as Match;
2073
+ const expressionTsCode = match.expression.toEmbeddedTS();
2074
+ if (code.includes(expressionTsCode)) {
2075
+ let typeCode = '';
2076
+ matchCase.patterns.forEach((pattern, index) => {
2077
+ if (pattern instanceof TypeAnnotation) {
2078
+ if (index === 0) {
2079
+ typeCode += pattern.toEmbeddedTS();
2080
+ } else {
2081
+ typeCode += '|';
2082
+ typeCode += pattern.toEmbeddedTS();
2083
+ }
2137
2084
  }
2138
- if (logic.returns?.length && logic.returns[0]?.typeAnnotation) {
2139
- // 如果新导入的logic还有Error类型
2140
- const logicType = logic.returns[0].typeAnnotation;
2141
- if (logicType.typeNamespace === 'nasl.ui' && logicType.typeName === 'Error') {
2142
- findHasError = true;
2143
- } else if (logicType.typeNamespace === 'nasl.core' && logicType.typeKind === 'union') {
2144
- // 如果 logic 有 returns 而且,也有typeArguments的长度
2145
- findHasError = Boolean(logicType.typeArguments?.find((item) => (
2146
- item?.typeNamespace === 'nasl.ui' && item?.typeName === 'Error'
2147
- )));
2148
- }
2085
+ });
2086
+ if (typeCode) {
2087
+ code = this.handleReplaceCode(code, expressionTsCode, `(${expressionTsCode} as ${typeCode})`);
2088
+ }
2089
+ }
2090
+ const parentMatchCase = match.getAncestor('MatchCase') as MatchCase;
2091
+ if (parentMatchCase) {
2092
+ code = this.handleMatchCaseCode(code, parentMatchCase);
2093
+ }
2094
+ return code;
2095
+ }
2096
+
2097
+ getNamespace(): string {
2098
+ if (this.parentNode) {
2099
+ const parentNamespace = (this.parentNode as any)?.getNamespace();
2100
+ // 针对Connector, 其对应的引入入口只有连接器。且唯一标识由
2101
+ // calleeName、calleeNamespace 两个字段组合确认,
2102
+ // 故这里只返回 Connector 对应的nameSpace 且 俩字段组合默认会含带logic 字段
2103
+ // 因此最后 CallConnector 的 calleewholeKey 为 : `${calleeNamespace}.logics.${calleeName}`
2104
+ if (this.parentNode.concept === 'Connector') {
2105
+ return parentNamespace;
2106
+ }
2107
+ const parentName = this.parentNode.name;
2108
+ const arr = [parentNamespace];
2109
+ if (this.parentNode.concept !== 'App' && parentName) {
2110
+ arr.push(parentName);
2111
+ }
2112
+ let namespace = arr.join('.');
2113
+ if (
2114
+ ![
2115
+ 'nasl.ui',
2116
+ 'nasl.utils',
2117
+ 'nasl.util',
2118
+ 'nasl.browser',
2119
+ 'nasl.auth',
2120
+ 'nasl.configuration',
2121
+ 'nasl.process',
2122
+ 'nasl.logging',
2123
+ 'nasl.io',
2124
+ 'nasl.event',
2125
+ ].includes(namespace) &&
2126
+ !namespace.includes('.logics')
2127
+ ) {
2128
+ namespace = `${namespace}.logics`;
2129
+ }
2130
+ return namespace;
2131
+ }
2132
+ throw new Error('无法获取命名空间,请设置 parentNode!');
2133
+ }
2134
+
2135
+ getTsNamespace(): string {
2136
+ if (this.parentNode) {
2137
+ const parentNamespace = (this.parentNode as any)?.getTsNamespace();
2138
+ const parentName = this.parentNode.tsName || this.parentNode.name;
2139
+ const arr = [parentNamespace];
2140
+ if (this.parentNode.concept !== 'App' && parentName) {
2141
+ arr.push(parentName);
2142
+ }
2143
+ let namespace = arr.join('.');
2144
+ if (
2145
+ ![
2146
+ 'nasl.ui',
2147
+ 'nasl.utils',
2148
+ 'nasl.util',
2149
+ 'nasl.browser',
2150
+ 'nasl.auth',
2151
+ 'nasl.configuration',
2152
+ 'nasl.process',
2153
+ 'nasl.logging',
2154
+ 'nasl.io',
2155
+ ].includes(namespace) &&
2156
+ !namespace.includes('.logics')
2157
+ ) {
2158
+ namespace = `${namespace}.logics`;
2159
+ }
2160
+ return namespace;
2161
+ }
2162
+ throw new Error('无法获取命名空间,请设置 parentNode!');
2163
+ }
2164
+
2165
+ /**
2166
+ * 生成宿主语言的文件路径
2167
+ * @param name 一般不用传,用于 rename
2168
+ */
2169
+ getEmbeddedFilePath(name = this.name) {
2170
+ let _path = '';
2171
+ if (this.module) {
2172
+ _path = `/${this.module.parentKey}/${this.module.name}`;
2173
+ } else if (this.connector) {
2174
+ _path = `/${this.connector.parentKey}/${this.connector.name}`;
2175
+ }
2176
+ if (this.parentNode instanceof FrontendLibrary) {
2177
+ _path += `/frontends/${this.parentNode.type}`;
2178
+ } else if (this.parentNode.concept === 'BindEvent' && this.parentNode?.parentNode.concept === 'Frontend') {
2179
+ _path += `/frontends/${this.parentNode.parentNode.name}/bindEvents/${name}.ts`;
2180
+ }
2181
+ return `/embedded/${this.app.name}${_path}/logics/${name}.ts`;
2182
+ }
2183
+
2184
+ toEmbeddedTSFile() {
2185
+ let code = `namespace ${this.getTsNamespace()} {\n`;
2186
+
2187
+ const state = createCompilerState(code, { tabSize: 1 });
2188
+ try {
2189
+ code += this.toEmbeddedTS(state);
2190
+ } catch (err) {
2191
+ console.log(err, `有问题翻译失败:${this.getTsNamespace()}.${this.name}`);
2192
+ code += '';
2193
+ console.log(err);
2194
+ }
2195
+ code += '}\n';
2196
+ return {
2197
+ code,
2198
+ filePath: this.getEmbeddedFilePath(),
2199
+ sourceMap: state.sourceMap,
2200
+ };
2201
+ }
2202
+
2203
+ public static getDefaultOptions(): Partial<{
2204
+ body: Array<any>;
2205
+ params: Array<any>;
2206
+ returns: Array<any>;
2207
+ }> {
2208
+ return {
2209
+ body: [
2210
+ {
2211
+ concept: 'Start',
2212
+ label: '开始',
2213
+ kind: 'Statement',
2214
+ type: 'Start',
2215
+ },
2216
+ {
2217
+ concept: 'End',
2218
+ label: '结束',
2219
+ kind: 'Statement',
2220
+ type: 'End',
2221
+ },
2222
+ ],
2223
+ };
2224
+ }
2225
+
2226
+ async saveStructureOfCallQueryComponents(root?: BaseNode | Logic) {
2227
+ if (!root) root = this;
2228
+ const set = new Set();
2229
+ utils.traverse(
2230
+ ({ node }) => {
2231
+ if (node instanceof CallQueryComponent) {
2232
+ set.add(node);
2149
2233
  }
2150
- return findHasError;
2151
- }
2152
-
2153
- //================================================================================
2154
- // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
2155
- // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
2156
- //================================================================================
2234
+ },
2235
+ { node: root },
2236
+ {
2237
+ mode: 'anyObject',
2238
+ excludedKeySet: new Set(['parentNode', '__assignment__']),
2239
+ }
2240
+ );
2241
+ for (const node of set) {
2242
+ (<CallQueryComponent>node).saveStructure();
2243
+ }
2244
+ }
2245
+
2246
+ // 通过开关设置数据库事务
2247
+ setTransactionEnabled(flag: boolean) {
2248
+ this.setTransactional(
2249
+ new Transactional({
2250
+ enabled: flag,
2251
+ })
2252
+ );
2253
+ }
2254
+
2255
+ fake: boolean;
2256
+
2257
+ getPath: () => string;
2258
+
2259
+ delete() {
2260
+ let actionMsg = '删除逻辑项';
2261
+ if (this.name) actionMsg += `“${this.name}”`;
2262
+ this.app?.emit('collect:start', {
2263
+ actionMsg,
2264
+ });
2265
+ super.delete();
2266
+ this.traverseChildren((el) => {
2267
+ if (el?.concept === 'CallQueryComponent') (el as CallQueryComponent).removeStructure();
2268
+ });
2269
+ this.app?.emit('collect:end');
2270
+ }
2271
+
2272
+ // 是不是内部有错误
2273
+ haveError: boolean = false;
2274
+
2275
+ // 是否body为空
2276
+ isSmpty: boolean = false;
2277
+
2278
+ get exportInterface() {
2279
+ return (this.rootNode as App)?.interfaces?.find((item) => item.originLogicName === this.name);
2280
+ }
2281
+
2282
+ get pathName(): string {
2283
+ if (this.view) {
2284
+ return this.getEventLogicName('chinese');
2285
+ }
2286
+
2287
+ let { parentNode } = this;
2288
+
2289
+ if (parentNode.concept === 'BindEvent' && parentNode.parentNode.concept === 'Frontend') {
2290
+ const frontEndEventNameMap = {
2291
+ rendered: '应用进入后',
2292
+ preRequest: '调用服务端逻辑前',
2293
+ postRequest: '调用服务端逻辑后',
2294
+ beforeRouter: '页面切换前',
2295
+ afterRouter: '页面切换后',
2296
+ };
2297
+ const pathName = [this.name];
2298
+ while (parentNode && parentNode.concept !== 'Frontend') {
2299
+ const name = (frontEndEventNameMap as any)[parentNode.name] || parentNode.name;
2300
+ pathName.unshift(name);
2301
+ parentNode = parentNode.parentNode;
2302
+ }
2303
+ return pathName.join('-');
2304
+ }
2305
+
2306
+ const nameMap = {
2307
+ OnProcessStart: '流程开始时',
2308
+ OnTasksCreate: '任务创建时',
2309
+ OnTasksOpen: '任务打开时',
2310
+ OnTasksClose: '任务关闭时',
2311
+ OnCreate: '用户任务创建时',
2312
+ OnOpen: '用户任务打开时',
2313
+ OnClose: '用户任务关闭时',
2314
+ };
2315
+ const pathName = [this.name];
2316
+
2317
+ parentNode = this.parentNode;
2318
+
2319
+ while (parentNode && parentNode.concept !== 'Process') {
2320
+ const name = (nameMap as any)[parentNode.name] || parentNode.name;
2321
+ pathName.unshift(name);
2322
+ parentNode = parentNode.parentNode;
2323
+ }
2324
+ return pathName.join('-');
2325
+ }
2326
+
2327
+ // 获取bindEvent下的logic的名称
2328
+ getEventLogicName(type?: string) {
2329
+ if (this.parentNode instanceof BindEvent) {
2330
+ if (type === 'chinese') {
2331
+ const bindEvent = this.parentNode;
2332
+ const bindChineseName = bindEvent.getPageViewEventChineseName();
2333
+ return `${bindChineseName} -${this.name} `;
2334
+ }
2335
+ }
2336
+ return this.name;
2337
+ }
2338
+
2339
+ // 虚拟输入参数列表
2340
+ virtualParams: Array<Param> = [];
2341
+
2342
+ get getLogicBelongTo() {
2343
+ const [, belongTo] = this.calleewholeKey.split('.');
2344
+ return belongTo;
2345
+ }
2346
+
2347
+ // 校验logic的返回值是不是有error类型
2348
+ static checkLogicReturnTypeHasError(logic: Logic) {
2349
+ let findHasError = false;
2350
+ if (!logic) {
2351
+ return findHasError;
2352
+ }
2353
+ if (logic.returns?.length && logic.returns[0]?.typeAnnotation) {
2354
+ // 如果新导入的logic还有Error类型
2355
+ const logicType = logic.returns[0].typeAnnotation;
2356
+ if (logicType.typeNamespace === 'nasl.ui' && logicType.typeName === 'Error') {
2357
+ findHasError = true;
2358
+ } else if (logicType.typeNamespace === 'nasl.core' && logicType.typeKind === 'union') {
2359
+ // 如果 logic 有 returns 而且,也有typeArguments的长度
2360
+ findHasError = Boolean(logicType.typeArguments?.find((item) => item?.typeNamespace === 'nasl.ui' && item?.typeName === 'Error'));
2361
+ }
2362
+ }
2363
+ return findHasError;
2364
+ }
2365
+
2366
+ //= ===============================================================================
2367
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
2368
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
2369
+ //= ===============================================================================
2157
2370
  }
2158
2371
 
2159
2372
  classMap.Logic = Logic;
2160
2373
  export default Logic;
2161
- //================================================================================
2374
+ //= ===============================================================================
2162
2375
  // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
2163
2376
  // 自动生成的代码已结束。下面可以手动编写。
2164
- //================================================================================
2377
+ //= ===============================================================================