@lcap/nasl 2.18.0 → 2.20.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (326) hide show
  1. package/out/automate/engine/index.js +3 -3
  2. package/out/automate/engine/index.js.map +1 -1
  3. package/out/bak/translator.js +85 -37
  4. package/out/bak/translator.js.map +1 -1
  5. package/out/common/BaseNode.d.ts +6 -10
  6. package/out/common/BaseNode.js +7 -52
  7. package/out/common/BaseNode.js.map +1 -1
  8. package/out/concepts/AnonymousFunction__.js.map +1 -1
  9. package/out/concepts/App__.d.ts +0 -10
  10. package/out/concepts/App__.js +0 -74
  11. package/out/concepts/App__.js.map +1 -1
  12. package/out/concepts/Assignee__.js.map +1 -1
  13. package/out/concepts/AssignmentLine__.d.ts +5 -5
  14. package/out/concepts/AssignmentLine__.js +6 -6
  15. package/out/concepts/AssignmentLine__.js.map +1 -1
  16. package/out/concepts/Assignment__.js +2 -1
  17. package/out/concepts/Assignment__.js.map +1 -1
  18. package/out/concepts/BatchAssignment__.d.ts +60 -60
  19. package/out/concepts/BatchAssignment__.js +11 -21
  20. package/out/concepts/BatchAssignment__.js.map +1 -1
  21. package/out/concepts/BindAttribute__.d.ts +0 -19
  22. package/out/concepts/BindAttribute__.js +2 -39
  23. package/out/concepts/BindAttribute__.js.map +1 -1
  24. package/out/concepts/BindEvent__.js.map +1 -1
  25. package/out/concepts/BindStyle__.d.ts +2 -2
  26. package/out/concepts/BindStyle__.js +3 -3
  27. package/out/concepts/BindStyle__.js.map +1 -1
  28. package/out/concepts/BooleanLiteral__.js +8 -0
  29. package/out/concepts/BooleanLiteral__.js.map +1 -1
  30. package/out/concepts/CallFunction__.js +25 -58
  31. package/out/concepts/CallFunction__.js.map +1 -1
  32. package/out/concepts/CallInterface__.d.ts +0 -7
  33. package/out/concepts/CallInterface__.js +7 -53
  34. package/out/concepts/CallInterface__.js.map +1 -1
  35. package/out/concepts/CallLogic__.js +14 -63
  36. package/out/concepts/CallLogic__.js.map +1 -1
  37. package/out/concepts/CallQueryComponent__.js +1 -13
  38. package/out/concepts/CallQueryComponent__.js.map +1 -1
  39. package/out/concepts/CompletionProperty__.js +0 -3
  40. package/out/concepts/CompletionProperty__.js.map +1 -1
  41. package/out/concepts/ConfigGroup__.js.map +1 -1
  42. package/out/concepts/ConfigProperty__.js.map +1 -1
  43. package/out/concepts/Configuration__.js.map +1 -1
  44. package/out/concepts/DataSource__.d.ts +0 -6
  45. package/out/concepts/DataSource__.js +0 -41
  46. package/out/concepts/DataSource__.js.map +1 -1
  47. package/out/concepts/Destination__.d.ts +1 -9
  48. package/out/concepts/Destination__.js +29 -61
  49. package/out/concepts/Destination__.js.map +1 -1
  50. package/out/concepts/EntityProperty__.d.ts +8 -21
  51. package/out/concepts/EntityProperty__.js +23 -109
  52. package/out/concepts/EntityProperty__.js.map +1 -1
  53. package/out/concepts/Entity__.d.ts +0 -32
  54. package/out/concepts/Entity__.js +2 -117
  55. package/out/concepts/Entity__.js.map +1 -1
  56. package/out/concepts/Enum__.js +4 -0
  57. package/out/concepts/Enum__.js.map +1 -1
  58. package/out/concepts/Event__.js.map +1 -1
  59. package/out/concepts/ForEachStatement__.d.ts +4 -0
  60. package/out/concepts/ForEachStatement__.js +8 -4
  61. package/out/concepts/ForEachStatement__.js.map +1 -1
  62. package/out/concepts/Function__.js.map +1 -1
  63. package/out/concepts/Identifier__.js +4 -16
  64. package/out/concepts/Identifier__.js.map +1 -1
  65. package/out/concepts/IfStatement__.d.ts +0 -8
  66. package/out/concepts/IfStatement__.js +0 -22
  67. package/out/concepts/IfStatement__.js.map +1 -1
  68. package/out/concepts/InterfaceParam__.js.map +1 -1
  69. package/out/concepts/Interface__.js.map +1 -1
  70. package/out/concepts/LogicItem__.d.ts +1 -1
  71. package/out/concepts/LogicItem__.js.map +1 -1
  72. package/out/concepts/Logic__.d.ts +1 -6
  73. package/out/concepts/Logic__.js +43 -144
  74. package/out/concepts/Logic__.js.map +1 -1
  75. package/out/concepts/MatchCase__.d.ts +1 -1
  76. package/out/concepts/MatchCase__.js +8 -15
  77. package/out/concepts/MatchCase__.js.map +1 -1
  78. package/out/concepts/Match__.d.ts +19 -21
  79. package/out/concepts/Match__.js +25 -112
  80. package/out/concepts/Match__.js.map +1 -1
  81. package/out/concepts/MemberExpression__.d.ts +1 -4
  82. package/out/concepts/MemberExpression__.js +15 -30
  83. package/out/concepts/MemberExpression__.js.map +1 -1
  84. package/out/concepts/Module__.js.map +1 -1
  85. package/out/concepts/Namespace__.js.map +1 -1
  86. package/out/concepts/NumericLiteral__.js +1 -1
  87. package/out/concepts/NumericLiteral__.js.map +1 -1
  88. package/out/concepts/OqlQueryComponent__.d.ts +3 -7
  89. package/out/concepts/OqlQueryComponent__.js +95 -56
  90. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  91. package/out/concepts/Param__.d.ts +1 -1
  92. package/out/concepts/Param__.js +4 -40
  93. package/out/concepts/Param__.js.map +1 -1
  94. package/out/concepts/ProcessComponent__.js.map +1 -1
  95. package/out/concepts/ProcessElement__.js.map +1 -1
  96. package/out/concepts/Process__.js.map +1 -1
  97. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  98. package/out/concepts/QueryOrderByExpression__.d.ts +3 -3
  99. package/out/concepts/QueryOrderByExpression__.js +3 -3
  100. package/out/concepts/QueryOrderByExpression__.js.map +1 -1
  101. package/out/concepts/QuerySelectExpression__.js.map +1 -1
  102. package/out/concepts/Return__.js +2 -38
  103. package/out/concepts/Return__.js.map +1 -1
  104. package/out/concepts/SelectMembers__.d.ts +1 -1
  105. package/out/concepts/SelectMembers__.js +2 -2
  106. package/out/concepts/SelectMembers__.js.map +1 -1
  107. package/out/concepts/SqlQueryComponent__.d.ts +4 -2
  108. package/out/concepts/SqlQueryComponent__.js +88 -9
  109. package/out/concepts/SqlQueryComponent__.js.map +1 -1
  110. package/out/concepts/StringLiteral__.js +7 -0
  111. package/out/concepts/StringLiteral__.js.map +1 -1
  112. package/out/concepts/StructureProperty__.js.map +1 -1
  113. package/out/concepts/Structure__.js.map +1 -1
  114. package/out/concepts/TypeAnnotation__.d.ts +0 -1
  115. package/out/concepts/TypeAnnotation__.js +12 -25
  116. package/out/concepts/TypeAnnotation__.js.map +1 -1
  117. package/out/concepts/TypeParam__.d.ts +0 -1
  118. package/out/concepts/TypeParam__.js +0 -2
  119. package/out/concepts/TypeParam__.js.map +1 -1
  120. package/out/concepts/UnaryExpression__.js +9 -6
  121. package/out/concepts/UnaryExpression__.js.map +1 -1
  122. package/out/concepts/ValidationRule__.js +23 -88
  123. package/out/concepts/ValidationRule__.js.map +1 -1
  124. package/out/concepts/Variable__.js +2 -38
  125. package/out/concepts/Variable__.js.map +1 -1
  126. package/out/concepts/ViewComponent__.js.map +1 -1
  127. package/out/concepts/ViewElement__.d.ts +29 -30
  128. package/out/concepts/ViewElement__.js +51 -117
  129. package/out/concepts/ViewElement__.js.map +1 -1
  130. package/out/concepts/View__.d.ts +3 -4
  131. package/out/concepts/View__.js +83 -93
  132. package/out/concepts/View__.js.map +1 -1
  133. package/out/concepts/WhileStatement__.js +1 -1
  134. package/out/concepts/WhileStatement__.js.map +1 -1
  135. package/out/concepts/basics/stdlib/nasl.browser.js +0 -50
  136. package/out/concepts/basics/stdlib/nasl.browser.js.map +1 -1
  137. package/out/concepts/basics/stdlib/nasl.ui.js +4 -36
  138. package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
  139. package/out/concepts/basics/stdlib/nasl.util.js +43 -63
  140. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  141. package/out/concepts/index__.d.ts +0 -2
  142. package/out/concepts/index__.js +0 -2
  143. package/out/concepts/index__.js.map +1 -1
  144. package/out/generator/genBundleFiles.d.ts +2 -5
  145. package/out/generator/genBundleFiles.js +45 -148
  146. package/out/generator/genBundleFiles.js.map +1 -1
  147. package/out/generator/index.d.ts +0 -1
  148. package/out/generator/index.js +0 -1
  149. package/out/generator/index.js.map +1 -1
  150. package/out/index.d.ts +2 -3
  151. package/out/index.js +1 -5
  152. package/out/index.js.map +1 -1
  153. package/out/server/entity2LogicNamespace.js +11 -11
  154. package/out/server/entity2LogicNamespace.js.map +1 -1
  155. package/out/server/extendBaseNode.js.map +1 -1
  156. package/out/server/formatTsUtils.js +17 -10
  157. package/out/server/formatTsUtils.js.map +1 -1
  158. package/out/server/getLogics.js +6 -13
  159. package/out/server/getLogics.js.map +1 -1
  160. package/out/server/getMemberIdentifier.js +7 -7
  161. package/out/server/getMemberIdentifier.js.map +1 -1
  162. package/out/server/getProcesses.d.ts +1 -1
  163. package/out/server/index.d.ts +1 -0
  164. package/out/server/index.js +27 -2
  165. package/out/server/index.js.map +1 -1
  166. package/out/server/naslServer.d.ts +7 -47
  167. package/out/server/naslServer.js +393 -591
  168. package/out/server/naslServer.js.map +1 -1
  169. package/out/server/naslStdlibMap.js +28 -30
  170. package/out/server/naslStdlibMap.js.map +1 -1
  171. package/out/server/translator.js +7 -40
  172. package/out/server/translator.js.map +1 -1
  173. package/out/service/storage/init.js +3 -33
  174. package/out/service/storage/init.js.map +1 -1
  175. package/out/templator/genCreateBlock.js +4 -6
  176. package/out/templator/genCreateBlock.js.map +1 -1
  177. package/out/templator/genCurdEditMultipleKeyBlock.js +4 -7
  178. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  179. package/out/templator/genCurdMultipleKeyBlock.js +5 -7
  180. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  181. package/out/templator/genEnumSelectBlock.js +2 -5
  182. package/out/templator/genEnumSelectBlock.js.map +1 -1
  183. package/out/templator/genGridViewBlock.js +2 -2
  184. package/out/templator/genGridViewBlock.js.map +1 -1
  185. package/out/templator/genListViewBlock.js +2 -2
  186. package/out/templator/genListViewBlock.js.map +1 -1
  187. package/out/templator/genQueryComponent.d.ts +2 -2
  188. package/out/templator/genQueryComponent.js +1 -4
  189. package/out/templator/genQueryComponent.js.map +1 -1
  190. package/out/templator/genTableBlock.js +2 -2
  191. package/out/templator/genTableBlock.js.map +1 -1
  192. package/out/templator/genUpdateBlock.js +3 -4
  193. package/out/templator/genUpdateBlock.js.map +1 -1
  194. package/out/templator/utils.js +1 -1
  195. package/out/templator/utils.js.map +1 -1
  196. package/out/test/integration/node-nasl-server.js +38 -10
  197. package/out/test/integration/node-nasl-server.js.map +1 -1
  198. package/out/translator/index.d.ts +0 -1
  199. package/out/translator/index.js +1 -1
  200. package/out/translator/index.js.map +1 -1
  201. package/out/utils/index.d.ts +0 -1
  202. package/out/utils/index.js +1 -38
  203. package/out/utils/index.js.map +1 -1
  204. package/out/utils/string.d.ts +2 -15
  205. package/out/utils/string.js +3 -18
  206. package/out/utils/string.js.map +1 -1
  207. package/package.json +2 -2
  208. package/sandbox/stdlib/nasl.auth.ts +1 -1
  209. package/sandbox/stdlib/nasl.core.ts +1 -0
  210. package/sandbox/stdlib/nasl.logging.ts +4 -4
  211. package/sandbox/stdlib/nasl.util.ts +9 -5
  212. package/src/automate/engine/index.js +4 -4
  213. package/src/automate/engine/uniqueName.js +3 -3
  214. package/src/automate/template/myProcess.js +1 -1
  215. package/src/automate/upgrader/2.20.js +41 -0
  216. package/src/bak/translator.js +4 -1
  217. package/src/common/BaseNode.ts +1 -0
  218. package/src/concepts/AnonymousFunction__.ts +48 -2
  219. package/src/concepts/App__.ts +288 -615
  220. package/src/concepts/BatchAssignment__.ts +111 -51
  221. package/src/concepts/BindAttribute__.ts +18 -25
  222. package/src/concepts/BindDirective__.ts +7 -0
  223. package/src/concepts/BindEvent__.ts +7 -0
  224. package/src/concepts/BindStyle__.ts +7 -0
  225. package/src/concepts/CallFunction__.ts +34 -45
  226. package/src/concepts/CallInterface__.ts +2 -1
  227. package/src/concepts/CallLogic__.ts +87 -55
  228. package/src/concepts/CallQueryComponent__.ts +4 -1
  229. package/src/concepts/Constant__.ts +7 -0
  230. package/src/concepts/DataSource__.ts +57 -5
  231. package/src/concepts/Destination__.ts +100 -43
  232. package/src/concepts/Frontend__.ts +937 -0
  233. package/src/concepts/Identifier__.ts +18 -16
  234. package/src/concepts/LogicItem__.ts +8 -1
  235. package/src/concepts/Logic__.ts +134 -149
  236. package/src/concepts/Match__.ts +13 -29
  237. package/src/concepts/NewComposite__.ts +1357 -0
  238. package/src/concepts/NewList__.ts +440 -0
  239. package/src/concepts/NewMap__.ts +666 -0
  240. package/src/concepts/New__.ts +73 -0
  241. package/src/concepts/Param__.ts +245 -199
  242. package/src/concepts/ProcessElement__.ts +43 -36
  243. package/src/concepts/ProcessOutcomes__.ts +90 -0
  244. package/src/concepts/Process__.ts +1 -23
  245. package/src/concepts/Return__.ts +11 -1
  246. package/src/concepts/SelectMembers__.ts +3 -3
  247. package/src/concepts/Transactional__.ts +7 -0
  248. package/src/concepts/TypeAnnotation__.ts +54 -49
  249. package/src/concepts/ValidationRule__.ts +19 -1
  250. package/src/concepts/Variable__.ts +12 -6
  251. package/src/concepts/ViewElement__.ts +26 -3
  252. package/src/concepts/View__.ts +25 -25
  253. package/src/concepts/basics/stdlib/nasl.auth.ts +1 -1
  254. package/src/concepts/basics/stdlib/nasl.logging.ts +5 -0
  255. package/src/concepts/basics/stdlib/nasl.ui.ts +2 -0
  256. package/src/concepts/basics/stdlib/nasl.util.ts +153 -19
  257. package/src/concepts/index__.ts +7 -0
  258. package/src/enums/KEYWORDS.ts +9 -0
  259. package/src/generator/genBundleFiles.ts +74 -245
  260. package/src/generator/genMetaData.ts +178 -78
  261. package/src/generator/genReleaseBody.ts +87 -44
  262. package/src/generator/index.ts +1 -0
  263. package/src/generator/permission.ts +261 -0
  264. package/src/index.ts +1 -1
  265. package/src/server/entity2LogicNamespace.ts +90 -10
  266. package/src/server/extendBaseNode.ts +33 -22
  267. package/src/server/formatTsUtils.ts +36 -46
  268. package/src/server/getLogics.ts +13 -1
  269. package/src/server/getMemberIdentifier.ts +5 -5
  270. package/src/server/getProcesses.ts +1 -1
  271. package/src/server/naslServer.ts +254 -71
  272. package/src/server/process2LogicNamespace.ts +8 -0
  273. package/src/server/translator.ts +51 -5
  274. package/src/service/creator/add.configs.js +4 -0
  275. package/src/service/datasource/api.js +11 -0
  276. package/src/service/datasource/index.js +6 -0
  277. package/src/service/storage/init.ts +12 -0
  278. package/src/service/video/VideoTranscribe.js +1 -0
  279. package/src/templator/genEditTableBlock.ts +8 -16
  280. package/src/templator/genGetBlock.ts +18 -19
  281. package/src/templator/genGridViewBlock.ts +18 -18
  282. package/src/templator/genListViewBlock.ts +8 -11
  283. package/src/templator/genTableBlock.ts +6 -10
  284. package/ts-worker/lib/tsserver.js +8 -1
  285. package/out/automate/engine/2.14-components.d.ts +0 -1115
  286. package/out/automate/engine/2.14-components.js +0 -1087
  287. package/out/automate/engine/2.14-components.js.map +0 -1
  288. package/out/concepts/ExternalDestination__.d.ts +0 -73
  289. package/out/concepts/ExternalDestination__.js +0 -264
  290. package/out/concepts/ExternalDestination__.js.map +0 -1
  291. package/out/concepts/MatchExpression__.d.ts +0 -97
  292. package/out/concepts/MatchExpression__.js +0 -281
  293. package/out/concepts/MatchExpression__.js.map +0 -1
  294. package/out/concepts/StringInterpolation__.d.ts +0 -113
  295. package/out/concepts/StringInterpolation__.js +0 -227
  296. package/out/concepts/StringInterpolation__.js.map +0 -1
  297. package/out/generator/genReleaseBody.d.ts +0 -41
  298. package/out/generator/genReleaseBody.js +0 -340
  299. package/out/generator/genReleaseBody.js.map +0 -1
  300. package/out/service/defaultErrorMessage.json +0 -97
  301. package/out/service/logic/api.d.ts +0 -9
  302. package/out/service/logic/api.js +0 -11
  303. package/out/service/logic/api.js.map +0 -1
  304. package/out/service/logic/index.d.ts +0 -2
  305. package/out/service/logic/index.js +0 -10
  306. package/out/service/logic/index.js.map +0 -1
  307. package/src/automate/engine/dist/index.dev.js +0 -517
  308. package/src/common/dist/BaseNode.js +0 -1101
  309. package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +0 -24
  310. package/src/concepts/dist/Anchor__.js +0 -179
  311. package/src/concepts/dist/Assignment__.js +0 -301
  312. package/src/concepts/dist/CallFunction__.js +0 -473
  313. package/src/concepts/dist/CallInterface__.js +0 -533
  314. package/src/concepts/dist/CallLogic__.js +0 -864
  315. package/src/concepts/dist/ForEachStatement__.js +0 -426
  316. package/src/concepts/dist/MatchCase__.js +0 -587
  317. package/src/concepts/dist/MemberExpression__.js +0 -348
  318. package/src/concepts/dist/Param__.js +0 -537
  319. package/src/concepts/dist/Return__.js +0 -493
  320. package/src/generator/dist/genBundleFiles.js +0 -414
  321. package/src/server/dist/formatTsUtils.js +0 -683
  322. package/src/server/dist/naslServer.js +0 -3396
  323. package/src/service/storage/dist/init.js +0 -541
  324. package/ts-worker/dist/webpack.config.dev.js +0 -104
  325. package/ts-worker/lib/dist/tsserver.dev.js +0 -22953
  326. package/ts-worker/sources/lib/dist/tsserver.dev.js +0 -22912
@@ -0,0 +1,261 @@
1
+ import { Logic, View, BaseNode, CallLogic, ViewElement, BindEvent, BindAttribute, App, Entity, Module, Frontend } from '../concepts';
2
+ import { processToTreeFragment } from '@nasl/server/process2LogicNamespace';
3
+
4
+ type Usage = {
5
+ node: BaseNode,
6
+ children?: Usage[],
7
+ }
8
+ type ResourceNode = {
9
+ path: string,
10
+ type: 'component' | 'page',
11
+ };
12
+
13
+ function isReadOnly(logic: Logic) {
14
+ return !!logic.module
15
+ || logic.parentNode?.concept === 'Namespace'
16
+ || logic.parentKey === 'readonly'; // process logic
17
+ }
18
+
19
+ const cache = new Map();
20
+ let useCache = false;
21
+ async function findUsage(logic: Logic) {
22
+ if (useCache && cache.has(logic))
23
+ return cache.get(logic);
24
+
25
+ const res = isReadOnly(logic) ? await logic.findReadOnlyLogicUsage() : await logic.findUsage();
26
+ if (useCache)
27
+ cache.set(logic, res);
28
+ return res;
29
+ }
30
+
31
+ function openCache() {
32
+ useCache = true;
33
+ cache.clear();
34
+ }
35
+ function closeCache() {
36
+ useCache = false;
37
+ cache.clear();
38
+ }
39
+
40
+ async function findViewLogicReferences(logic: Logic, vis: Set<Logic> = new Set()) {
41
+ const usageMap: Map<BaseNode, Usage> = await findUsage(logic);
42
+ const usages: Usage[] = [];
43
+ usageMap.forEach((usage: Usage, node: BaseNode) => {
44
+ if (node instanceof Frontend)
45
+ usages.push(usage);
46
+ });
47
+
48
+ async function dfs(usage: Usage) {
49
+ if (usage.node instanceof CallLogic) {
50
+ const logic = usage.node.logic;
51
+ if (!vis.has(logic)) {
52
+ vis.add(logic);
53
+ await findViewLogicReferences(logic, vis);
54
+ }
55
+ }
56
+
57
+ if (usage.children) {
58
+ for (const child of usage.children) {
59
+ await dfs(child);
60
+ }
61
+ }
62
+ }
63
+
64
+ for (const usage of usages) {
65
+ await dfs(usage);
66
+ }
67
+
68
+ return Array.from(vis);
69
+ }
70
+
71
+ async function findUIReferences(logic: Logic) {
72
+ const usageMap: Map<BaseNode, Usage> = await findUsage(logic);
73
+ const usages: Usage[] = [];
74
+ usageMap.forEach((usage: Usage, node: BaseNode) => {
75
+ if (node instanceof Frontend)
76
+ usages.push(usage);
77
+ });
78
+
79
+ const res: Array<View | ViewElement> = [];
80
+ function dfs(usage: Usage, parent: Usage = null) {
81
+ if ((usage.node instanceof BindEvent || usage.node instanceof BindAttribute)
82
+ && (parent.node instanceof View || parent.node instanceof ViewElement))
83
+ res.push(parent.node);
84
+
85
+ usage.children?.forEach((child) => {
86
+ dfs(child, usage);
87
+ });
88
+ }
89
+
90
+ usages.forEach((usage) => {
91
+ dfs(usage);
92
+ });
93
+ return res;
94
+ }
95
+
96
+ function findResourcesOfUI(view: View | ViewElement) {
97
+ const res: ResourceNode[] = [];
98
+ let node: BaseNode = view;
99
+ while (node) {
100
+ if (node instanceof View && node.auth)
101
+ res.push({
102
+ path: node.authPath,
103
+ type: 'page',
104
+ });
105
+ else if (node instanceof ViewElement) {
106
+ const hasAuth = node.bindDirectives.find((directive) => directive.name === 'auth');
107
+ if (hasAuth)
108
+ res.push({
109
+ path: node.authPath,
110
+ type: 'component',
111
+ });
112
+ }
113
+ node = node.parentNode;
114
+ }
115
+ return res;
116
+ }
117
+
118
+ function optimizeResourceData(resources: ResourceNode[][]) {
119
+ let res = removeRedundantResourceData(resources);
120
+ res = removeRedundantResourceData2(res);
121
+ return res;
122
+ }
123
+
124
+ // [['b'], ['a' ,'b']] 只需要保留 [['b']]
125
+ function removeRedundantResourceData(resources: ResourceNode[][]) {
126
+ const wm: WeakMap<ResourceNode[], string> = new WeakMap();
127
+ for (const resource of resources) {
128
+ const hash = resource.map(({ path, type }) => `${path}_${type}`)
129
+ .join();
130
+ wm.set(resource, hash);
131
+ }
132
+
133
+ resources.sort((a, b) => wm.get(a).length - wm.get(b).length);
134
+
135
+ const res: ResourceNode[][] = [];
136
+ const hashs: string[] = [];
137
+
138
+ for (const resource of resources) {
139
+ const hash = wm.get(resource);
140
+ if (hashs.some((h) => hash.endsWith(h)))
141
+ continue;
142
+
143
+ res.push(resource);
144
+ hashs.push(hash);
145
+ }
146
+ return res;
147
+ }
148
+
149
+ // 子页面有权限,父页面默认也有权限,所以不需要记录父页面权限;
150
+ // 组件有权限,组件所在的页面默认也有权限,所以不需要记录页面权限
151
+ function removeRedundantResourceData2(resources: ResourceNode[][]) {
152
+ return resources.map((resource) => {
153
+ if (resource.length <= 1)
154
+ return resource;
155
+
156
+ if (resource[0].type === 'page')
157
+ return resource.slice(0, 1);
158
+ else if (resource[0].type === 'component')
159
+ return resource.filter((item) => item.type === 'component');
160
+ });
161
+ }
162
+
163
+ async function findResourcesOfLogic(logic: Logic) {
164
+ const logics = await findViewLogicReferences(logic);
165
+ logics.push(logic);
166
+
167
+ let UIs: Array<View | ViewElement> = [];
168
+ for (const logic of logics) {
169
+ UIs = UIs.concat(await findUIReferences(logic));
170
+ }
171
+ UIs = Array.from(new Set(UIs));
172
+
173
+ const res = UIs.map((ui) => findResourcesOfUI(ui));
174
+
175
+ return optimizeResourceData(res);
176
+ }
177
+
178
+ function getAllLogics(app: App) {
179
+ const modules: Module[] = [];
180
+ const entities: Entity[] = [];
181
+ const logics: Logic[] = [];
182
+
183
+ if (Array.isArray(app.dataSources)) {
184
+ app.dataSources.forEach((dataSource) => {
185
+ if (Array.isArray(dataSource.entities)) {
186
+ entities.push(...dataSource.entities);
187
+ }
188
+ });
189
+ }
190
+ app.logics && logics.push(...app.logics);
191
+
192
+ app.dependencies && modules.push(...app.dependencies);
193
+ app.interfaceDependencies && modules.push(...app.interfaceDependencies);
194
+
195
+ modules.forEach((module: Module) => {
196
+ module.logics && logics.push(...module.logics);
197
+ if (Array.isArray(module.dataSources)) {
198
+ module.dataSources.forEach((dataSource) => {
199
+ if (Array.isArray(dataSource.entities)) {
200
+ entities.push(...dataSource.entities);
201
+ }
202
+ });
203
+ }
204
+ });
205
+
206
+ const allLogics: Logic[] = [];
207
+
208
+ if (Array.isArray(entities)) {
209
+ entities.forEach((entity) => {
210
+ const ns = entity.ns;
211
+ if (Array.isArray(ns?.logics)) {
212
+ allLogics.push(...ns.logics);
213
+ }
214
+ });
215
+ }
216
+ if (Array.isArray(logics)) {
217
+ allLogics.push(...logics);
218
+ }
219
+
220
+ const processLogics: Logic[] = [];
221
+ const processTreeFragments = (app.processes || [])
222
+ .map(processToTreeFragment);
223
+ processTreeFragments.forEach((tree) => {
224
+ processLogics.push(...tree.logics);
225
+ tree.elements.forEach((element) => {
226
+ processLogics.push(...element.logics);
227
+ });
228
+ });
229
+
230
+ return {
231
+ logics: allLogics,
232
+ processLogics,
233
+ };
234
+ }
235
+
236
+ export async function genPermissionData(app: App) {
237
+ // console.time('xxx');
238
+ openCache();
239
+ const logicPageResourceDtoList: { [key: string]: ResourceNode[][] } = {};
240
+ const resourceList: string[] = [];
241
+ const resourceDataList: { value: string, type: 'logic', description: string }[] = [];
242
+ const { logics, processLogics } = getAllLogics(app);
243
+ for (const logic of [...logics, ...processLogics]) {
244
+ const resources = await findResourcesOfLogic(logic);
245
+ if (resources.length === 0)
246
+ continue;
247
+
248
+ const service = logics.includes(logic) ? logic.toService() : logic.toProcessService() as { url: { method: string, path: string } };
249
+ const key = `${service.url.path}:${service.url.method}`;
250
+ logicPageResourceDtoList[key] = resources;
251
+ resourceList.push(key);
252
+ resourceDataList.push({
253
+ value: key,
254
+ type: 'logic',
255
+ description: logic.description,
256
+ });
257
+ }
258
+ closeCache();
259
+ // console.timeEnd('xxx');
260
+ return { logicPageResourceDtoList, resourceList, resourceDataList };
261
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { EventEmitter, EventPayload, BaseNode } from './common';
2
2
  export * from './concepts';
3
- export { genBundleFiles, genMetaData, genReleaseBody } from './generator';
3
+ export { genBundleFiles, genFrontendBundleFiles, genMetaData, genReleaseBody, genPermissionData } from './generator';
4
4
  export * from './translator';
5
5
  // export { default as diagnosticManager } from './manager/diagnostic';
6
6
  export { default as server, NaslServer } from './server';
@@ -1,4 +1,4 @@
1
- import { CallLogic, EntityProperty, BindEvent, App, Namespace, Entity, BaseNode, Logic, Param, TypeAnnotation, Function, Return } from '..';
1
+ import { CallLogic, EntityProperty, BindEvent, App, Namespace, Entity, BaseNode, Logic, Param, TypeAnnotation, Function, Return, AnonymousFunction, NewList } from '..';
2
2
 
3
3
  export function entity2LogicNamespace(entity: Entity) {
4
4
  const properties = entity.properties;
@@ -86,6 +86,26 @@ export function entity2LogicNamespace(entity: Entity) {
86
86
  }),
87
87
  required: true,
88
88
  }),
89
+ new Param({
90
+ name: 'properties',
91
+ defaultExpression: new AnonymousFunction({
92
+ description: '',
93
+ params: [
94
+ new Param({
95
+ name: 'item',
96
+ typeAnnotation: new TypeAnnotation({
97
+ typeKind: 'reference',
98
+ typeNamespace: entity.getNamespace(),
99
+ typeName: entity.name,
100
+ }),
101
+ }),
102
+ ],
103
+ body: new NewList({
104
+ concept: 'NewList',
105
+ }),
106
+ }),
107
+ required: false,
108
+ }),
89
109
  ],
90
110
  returns: [
91
111
  new Return({
@@ -118,6 +138,26 @@ export function entity2LogicNamespace(entity: Entity) {
118
138
  }),
119
139
  required: true,
120
140
  }),
141
+ new Param({
142
+ name: 'properties',
143
+ defaultExpression: new AnonymousFunction({
144
+ description: '',
145
+ params: [
146
+ new Param({
147
+ name: 'item',
148
+ typeAnnotation: new TypeAnnotation({
149
+ typeKind: 'reference',
150
+ typeNamespace: entity.getNamespace(),
151
+ typeName: entity.name,
152
+ }),
153
+ }),
154
+ ],
155
+ body: new NewList({
156
+ concept: 'NewList',
157
+ }),
158
+ }),
159
+ required: false,
160
+ }),
121
161
  ],
122
162
  body: [],
123
163
  returns: [
@@ -135,15 +175,6 @@ export function entity2LogicNamespace(entity: Entity) {
135
175
  name: 'updateBy',
136
176
  description: '根据条件,将body除id外所有属性更新到数据记录',
137
177
  params: [
138
- new Param({
139
- name: 'body',
140
- typeAnnotation: new TypeAnnotation({
141
- typeKind: 'reference',
142
- typeNamespace: entity.getNamespace(),
143
- typeName: entity.name,
144
- }),
145
- required: true,
146
- }),
147
178
  new Param({
148
179
  name: 'filter',
149
180
  defaultExpression: new Function({
@@ -167,6 +198,35 @@ export function entity2LogicNamespace(entity: Entity) {
167
198
  }),
168
199
  required: true,
169
200
  }),
201
+ new Param({
202
+ name: 'body',
203
+ typeAnnotation: new TypeAnnotation({
204
+ typeKind: 'reference',
205
+ typeNamespace: entity.getNamespace(),
206
+ typeName: entity.name,
207
+ }),
208
+ required: true,
209
+ }),
210
+ new Param({
211
+ name: 'properties',
212
+ defaultExpression: new AnonymousFunction({
213
+ description: '',
214
+ params: [
215
+ new Param({
216
+ name: 'item',
217
+ typeAnnotation: new TypeAnnotation({
218
+ typeKind: 'reference',
219
+ typeNamespace: entity.getNamespace(),
220
+ typeName: entity.name,
221
+ }),
222
+ }),
223
+ ],
224
+ body: new NewList({
225
+ concept: 'NewList',
226
+ }),
227
+ }),
228
+ required: false,
229
+ }),
170
230
  ],
171
231
  returns: [
172
232
  new Return({
@@ -257,6 +317,26 @@ export function entity2LogicNamespace(entity: Entity) {
257
317
  }),
258
318
  required: true,
259
319
  }),
320
+ new Param({
321
+ name: 'properties',
322
+ defaultExpression: new AnonymousFunction({
323
+ description: '',
324
+ params: [
325
+ new Param({
326
+ name: 'item',
327
+ typeAnnotation: new TypeAnnotation({
328
+ typeKind: 'reference',
329
+ typeNamespace: entity.getNamespace(),
330
+ typeName: entity.name,
331
+ }),
332
+ }),
333
+ ],
334
+ body: new NewList({
335
+ concept: 'NewList',
336
+ }),
337
+ }),
338
+ required: false,
339
+ }),
260
340
  ],
261
341
  returns: [
262
342
  new Return({
@@ -1,7 +1,7 @@
1
1
  import { FileNode, NaslServer } from './naslServer';
2
2
  import * as tsProtocol from 'typescript/lib/protocol';
3
3
  import { MinRange } from './translator';
4
- import { BaseNode, CallLogic, Destination, EnumItem, Interface, Logic, Param, Process, Role, Structure, View, ViewElement } from '../concepts';
4
+ import { BaseNode, CallLogic, Destination, EnumItem, Interface, Logic, Param, Process, Role, Structure, View, ViewElement, Frontend } from '../concepts';
5
5
  import { EventPayload, invokeCommand, registerCommand } from '../common';
6
6
 
7
7
  interface SetNameNode extends BaseNode {
@@ -161,19 +161,6 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
161
161
  refsList = refsList.filter((item) =>
162
162
  // 因为ui组件本身会多渲染一次,就先过滤一个
163
163
  !(item.lineText.includes(': nasl.ui.')));
164
- // 删除参数单独处理
165
- if (node instanceof Param) {
166
- const methodRefs: tsProtocol.ReferencesResponseItem[] = [];
167
- refsList.forEach((item) => {
168
- // 入参查找引用,查到logic 和自己,内容完全一样,就保留一个
169
- const find = methodRefs.find((findItem) => item.lineText === findItem.lineText);
170
- if (!find) {
171
- methodRefs.push(item);
172
- }
173
- });
174
- refsList = methodRefs;
175
- }
176
-
177
164
  // delete的弹框展示
178
165
  const confirmParms = {
179
166
  actionType: 'delete',
@@ -182,7 +169,7 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
182
169
  icon: 'warning',
183
170
  };
184
171
  let callback = null;
185
- if (refsList.length <= 1) {
172
+ if (refsList.length <= 1 || (node instanceof Param && node.parentNode instanceof Logic && refsList.length <= 2)) {
186
173
  // 页面组件直接删除然后return
187
174
  if (node instanceof ViewElement) {
188
175
  this.delete();
@@ -202,7 +189,7 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
202
189
  const node = this;
203
190
 
204
191
  // 删除页面或者流程
205
- if (node instanceof View || node instanceof Process) {
192
+ if (node instanceof View || node instanceof Process || node instanceof Frontend) {
206
193
  /**
207
194
  * 查找这个页面是不是有依赖
208
195
  */
@@ -222,7 +209,33 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
222
209
  } else {
223
210
  this.delete();
224
211
  }
225
- return;
212
+ } else {
213
+ if (node instanceof Frontend) {
214
+ let viewPath = (this as FileNode).getEmbeddedFilePath();
215
+ viewPath = viewPath.slice(0, viewPath.length - 3);
216
+ const refsTempList = refsList.filter((record) => !record.file.includes(viewPath));
217
+ // 删除流程节点绑定的该端的页面跳转
218
+ const result = refsTempList
219
+ .map((record) => {
220
+ const fileNode = naslServer.file2NodeMap.get(record.file);
221
+ if (fileNode) {
222
+ const minRange = naslServer._findMinRange(record, fileNode as FileNode);
223
+ if (minRange?.node?.parentNode?.parentNode?.concept === 'ProcessElement') {
224
+ return minRange.node.parentNode;
225
+ }
226
+ }
227
+ return null;
228
+ }).filter((record) => !!record);
229
+ console.log(result);
230
+ const App = this.rootNode;
231
+ App.emit('collect:start', {
232
+ actionMsg: `删除端${node.name}`,
233
+ });
234
+ await Promise.all(result.map((ele) => ele.delete()));
235
+ this.delete();
236
+ App.emit('collect:end');
237
+ return;
238
+ }
226
239
  }
227
240
  }
228
241
  callback = async () => {
@@ -235,6 +248,7 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
235
248
  App.emit('collect:start', {
236
249
  actionMsg: '删除参数',
237
250
  });
251
+ const Index = node.getIndexOfParent();
238
252
  this.delete();
239
253
  refsList.forEach((record) => {
240
254
  const fileNode = naslServer.file2NodeMap.get(record.file);
@@ -242,11 +256,8 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
242
256
  return null;
243
257
  const minRange: MinRange = naslServer._findMinRange(record, fileNode as FileNode);
244
258
  if (minRange) {
245
- if (minRange.node instanceof CallLogic) {
246
- minRange.node.setCalleeArgName(parentNode as Logic);
247
- }
248
- if (minRange.node instanceof Destination) {
249
- minRange.node.setViewArgument(parentNode as View);
259
+ if (minRange.node instanceof CallLogic || minRange.node instanceof Destination) {
260
+ minRange.node.deleteCalleeArg(Index);
250
261
  }
251
262
  }
252
263
  });
@@ -247,13 +247,9 @@ function findNode(typeKey: string, node: BaseNode) {
247
247
  * 获取下一级的节点进行递归
248
248
  * @param typeKey 当前节点的类型,主要为了取出内部的 T中的实际类型
249
249
  * @param item 当前节点的内容
250
- * @param parent 父级节点的内容
251
250
  * @param node 获取变量框的位置
252
251
  */
253
- export function nextFindTypeChild(typeKey: string, item: any, parent: any, node: BaseNode) {
254
- // 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
255
- const nodeMap = parent ? parent.nodeMap : new Map();
256
- item.nodeMap = nodeMap;
252
+ export function nextFindTypeChild(typeKey: string, item: any, node: BaseNode) {
257
253
  const newType = findNode(typeKey, node);
258
254
  if ((newType as Structure)?.properties && (newType as Structure).properties.length) {
259
255
  // 处理泛型的内容要取到值
@@ -274,16 +270,7 @@ export function nextFindTypeChild(typeKey: string, item: any, parent: any, node:
274
270
  });
275
271
  }
276
272
  });
277
- const index = nodeMap.get(newType) || 0;
278
- if (index) {
279
- nodeMap.set(newType, index + 1);
280
- } else {
281
- nodeMap.set(newType, 1);
282
- }
283
- // 最多保留3层
284
- if (index < 3) {
285
- item.children = formatVariableData(newStructure.properties, node, item);
286
- }
273
+ item.children = formatVariableData(newStructure.properties, node, item);
287
274
  }
288
275
  }
289
276
 
@@ -359,7 +346,7 @@ function getAStructureScopeType(type: string, parent: any, node: BaseNode) {
359
346
  newItem.concept = 'CompletionProperty';
360
347
  // 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
361
348
  if (item.typeKey && !isNoChildType(item.typeKey)) {
362
- newItem.children = nextObjectTypeChild(item.typeKey, newItem, parentItem, node);
349
+ newItem.children = nextObjectTypeChild(item.typeKey, newItem, node);
363
350
  }
364
351
  const completionProperty = new CompletionProperty(newItem);
365
352
  completionProperty.icon = 'refProperty';
@@ -395,9 +382,6 @@ function getAStructureScopeType(type: string, parent: any, node: BaseNode) {
395
382
  function getAStructureObjectStringType(type: string, parent: any, node: BaseNode) {
396
383
  let newType = type.replaceAll(' ', '').replaceAll('\n', '').replace(/__name:"AStructure_\w{8}";/g, '');
397
384
  newType = newType.substring(1, newType.length - 1);
398
- if (!parent.keyMap) {
399
- parent.keyMap = new Map();
400
- }
401
385
  if (/\{([^()]+)\}/.exec(newType)) {
402
386
  newType = newType.replace(/\{([^()]+)\}/, '');
403
387
  }
@@ -437,7 +421,7 @@ function getAStructureObjectStringType(type: string, parent: any, node: BaseNode
437
421
  newItem.concept = 'CompletionProperty';
438
422
  // 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
439
423
  if (item.typeKey && !isNoChildType(item.typeKey)) {
440
- newItem.children = nextObjectTypeChild(getPlatformType(item.typeKey), newItem, parentItem, node);
424
+ newItem.children = nextObjectTypeChild(getPlatformType(item.typeKey), newItem, node);
441
425
  }
442
426
  const completionProperty = new CompletionProperty(newItem);
443
427
 
@@ -451,13 +435,7 @@ function getAStructureObjectStringType(type: string, parent: any, node: BaseNode
451
435
  completionProperty.icon = getNodeiconFromLogic(completionProperty, node);
452
436
  return completionProperty;
453
437
  }
454
- function nextObjectTypeChild(typeKey: string, item: any, parent: any, node: BaseNode) {
455
- // 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
456
- const nodeMap = parent.nodeMap || new Map();
457
- item.nodeMap = nodeMap; // 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
458
-
459
- const keyMap = parent.keyMap;
460
- item.keyMap = keyMap;
438
+ function nextObjectTypeChild(typeKey: string, item: any, node: BaseNode) {
461
439
  const newType = findNode(typeKey, node);
462
440
  if ((newType as Structure)?.properties && (newType as Structure).properties.length) {
463
441
  // 处理泛型的内容要取到值
@@ -478,16 +456,7 @@ function nextObjectTypeChild(typeKey: string, item: any, parent: any, node: Base
478
456
  });
479
457
  }
480
458
  });
481
- const index = nodeMap.get(newType) || 0;
482
- if (index) {
483
- nodeMap.set(newType, index + 1);
484
- } else {
485
- nodeMap.set(newType, 1);
486
- }
487
- // 最多保留3层
488
- if (index < 3) {
489
- return formatVariableData(newStructure.properties, node, item);
490
- }
459
+ return formatVariableData(newStructure.properties, node, item);
491
460
  }
492
461
  }
493
462
 
@@ -533,21 +502,42 @@ export function formatVariableData(data: unknown | variableItem[], node: BaseNod
533
502
  item.name = item.text;
534
503
  const identifier = new Identifier({ name: item.name });
535
504
  item.expression = identifier;
505
+ item.typeKey = typeKey;
536
506
  } else {
537
507
  item.value = `${parent.value}.${item.name}`;
508
+ const object: any = BaseNode.from(parent.expression.toJSON());
538
509
  const memberExpression = new MemberExpression({
539
- object: parent.expression,
510
+ object,
540
511
  property: new Identifier({ name: item.name }),
541
512
  });
542
513
  item.expression = memberExpression;
514
+ item.variableParent = parent;
515
+ item.typeKey = typeKey;
516
+ // 标记实体属性是否是符合类型
517
+ item.isComplexType = item.typeAnnotation?.isComplexType();
543
518
  }
544
519
  // 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
545
520
  if (typeKey && !isNoChildType(typeKey)) {
546
- nextFindTypeChild(typeKey, item, parent, node);
521
+ let currentParent = item;
522
+ let typeKeyIndex = 0;
523
+ while (currentParent.variableParent) {
524
+ currentParent = currentParent.variableParent;
525
+ if (currentParent.typeKey === typeKey) {
526
+ typeKeyIndex++;
527
+ }
528
+ }
529
+ // 向上找到3次一样的就结束
530
+ if (typeKeyIndex < 3) {
531
+ nextFindTypeChild(typeKey, item, node);
532
+ }
547
533
  }
548
534
  // 如果是从实体或者数据结构取的属性,就需要重置一下类型
549
535
  item.concept = 'CompletionProperty';
550
536
  const completionProperty = new CompletionProperty(item);
537
+ // 标记实体属性是否是符合类型
538
+ if (typeof item.isComplexType === 'boolean') {
539
+ Object.assign(completionProperty, { isComplexType: item.isComplexType });
540
+ }
551
541
  if (!parent) {
552
542
  // 变量 param return 在这里添加图标
553
543
  completionProperty.icon = getNodeiconFromLogic(completionProperty, node);
@@ -633,20 +623,20 @@ function sortFirstVariableData(result: CompletionProperty[], node: BaseNode) {
633
623
  }
634
624
 
635
625
  export function formatFrontEndVariables(frontEndVariables: Array<Variable>) {
636
- const result = frontEndVariables.map((item) => {
637
- const namespace = item.getNamespace();
626
+ const result = frontEndVariables.map((itemNode) => {
627
+ const namespace = itemNode.getNamespace();
638
628
  const newItem: any = {
639
- name: item.name,
640
- value: item.name,
629
+ name: itemNode.name,
630
+ value: itemNode.name,
641
631
  expression: new Identifier({
642
- name: item.name,
632
+ name: itemNode.name,
643
633
  namespace,
644
634
  }),
645
635
  };
646
- const noChildType = isNoChildType(item.typeAnnotation.typeKey);
636
+ const noChildType = isNoChildType(itemNode.typeAnnotation.typeKey);
647
637
 
648
638
  if (!noChildType) {
649
- nextFindTypeChild(item.typeAnnotation.typeKey, newItem, null, item);
639
+ nextFindTypeChild(itemNode.typeAnnotation.typeKey, newItem, itemNode);
650
640
  }
651
641
  const completionProperty = new CompletionProperty(newItem);
652
642
  completionProperty.icon = 'frontendVariable';