@lcap/nasl 2.18.0-beta.7 → 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 (336) 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 -53
  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 +41 -68
  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__.d.ts +1 -2
  36. package/out/concepts/CallLogic__.js +25 -89
  37. package/out/concepts/CallLogic__.js.map +1 -1
  38. package/out/concepts/CallQueryComponent__.js +1 -13
  39. package/out/concepts/CallQueryComponent__.js.map +1 -1
  40. package/out/concepts/CompletionProperty__.js +0 -3
  41. package/out/concepts/CompletionProperty__.js.map +1 -1
  42. package/out/concepts/ConfigGroup__.js.map +1 -1
  43. package/out/concepts/ConfigProperty__.js.map +1 -1
  44. package/out/concepts/Configuration__.js.map +1 -1
  45. package/out/concepts/DataSource__.d.ts +0 -6
  46. package/out/concepts/DataSource__.js +0 -41
  47. package/out/concepts/DataSource__.js.map +1 -1
  48. package/out/concepts/Destination__.d.ts +2 -11
  49. package/out/concepts/Destination__.js +48 -148
  50. package/out/concepts/Destination__.js.map +1 -1
  51. package/out/concepts/EntityProperty__.d.ts +8 -21
  52. package/out/concepts/EntityProperty__.js +23 -109
  53. package/out/concepts/EntityProperty__.js.map +1 -1
  54. package/out/concepts/Entity__.d.ts +0 -32
  55. package/out/concepts/Entity__.js +2 -117
  56. package/out/concepts/Entity__.js.map +1 -1
  57. package/out/concepts/Enum__.js +4 -0
  58. package/out/concepts/Enum__.js.map +1 -1
  59. package/out/concepts/Event__.js.map +1 -1
  60. package/out/concepts/ForEachStatement__.d.ts +4 -0
  61. package/out/concepts/ForEachStatement__.js +8 -4
  62. package/out/concepts/ForEachStatement__.js.map +1 -1
  63. package/out/concepts/Function__.js.map +1 -1
  64. package/out/concepts/Identifier__.js +4 -16
  65. package/out/concepts/Identifier__.js.map +1 -1
  66. package/out/concepts/IfStatement__.d.ts +0 -8
  67. package/out/concepts/IfStatement__.js +0 -22
  68. package/out/concepts/IfStatement__.js.map +1 -1
  69. package/out/concepts/InterfaceParam__.js.map +1 -1
  70. package/out/concepts/Interface__.js.map +1 -1
  71. package/out/concepts/LogicItem__.d.ts +1 -1
  72. package/out/concepts/LogicItem__.js.map +1 -1
  73. package/out/concepts/Logic__.d.ts +1 -6
  74. package/out/concepts/Logic__.js +50 -150
  75. package/out/concepts/Logic__.js.map +1 -1
  76. package/out/concepts/MatchCase__.d.ts +1 -1
  77. package/out/concepts/MatchCase__.js +8 -15
  78. package/out/concepts/MatchCase__.js.map +1 -1
  79. package/out/concepts/Match__.d.ts +19 -21
  80. package/out/concepts/Match__.js +25 -112
  81. package/out/concepts/Match__.js.map +1 -1
  82. package/out/concepts/MemberExpression__.d.ts +1 -4
  83. package/out/concepts/MemberExpression__.js +15 -30
  84. package/out/concepts/MemberExpression__.js.map +1 -1
  85. package/out/concepts/Module__.js.map +1 -1
  86. package/out/concepts/Namespace__.js.map +1 -1
  87. package/out/concepts/NumericLiteral__.js +1 -1
  88. package/out/concepts/NumericLiteral__.js.map +1 -1
  89. package/out/concepts/OqlQueryComponent__.d.ts +3 -7
  90. package/out/concepts/OqlQueryComponent__.js +95 -56
  91. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  92. package/out/concepts/Param__.d.ts +1 -1
  93. package/out/concepts/Param__.js +4 -40
  94. package/out/concepts/Param__.js.map +1 -1
  95. package/out/concepts/ProcessComponent__.js.map +1 -1
  96. package/out/concepts/ProcessElement__.js.map +1 -1
  97. package/out/concepts/Process__.js.map +1 -1
  98. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  99. package/out/concepts/QueryOrderByExpression__.d.ts +3 -3
  100. package/out/concepts/QueryOrderByExpression__.js +3 -3
  101. package/out/concepts/QueryOrderByExpression__.js.map +1 -1
  102. package/out/concepts/QuerySelectExpression__.js.map +1 -1
  103. package/out/concepts/Return__.js +2 -38
  104. package/out/concepts/Return__.js.map +1 -1
  105. package/out/concepts/SelectMembers__.d.ts +1 -1
  106. package/out/concepts/SelectMembers__.js +2 -2
  107. package/out/concepts/SelectMembers__.js.map +1 -1
  108. package/out/concepts/SqlQueryComponent__.d.ts +4 -2
  109. package/out/concepts/SqlQueryComponent__.js +88 -9
  110. package/out/concepts/SqlQueryComponent__.js.map +1 -1
  111. package/out/concepts/StringLiteral__.js +7 -0
  112. package/out/concepts/StringLiteral__.js.map +1 -1
  113. package/out/concepts/StructureProperty__.js.map +1 -1
  114. package/out/concepts/Structure__.js.map +1 -1
  115. package/out/concepts/TypeAnnotation__.d.ts +0 -1
  116. package/out/concepts/TypeAnnotation__.js +12 -25
  117. package/out/concepts/TypeAnnotation__.js.map +1 -1
  118. package/out/concepts/TypeParam__.d.ts +0 -1
  119. package/out/concepts/TypeParam__.js +0 -2
  120. package/out/concepts/TypeParam__.js.map +1 -1
  121. package/out/concepts/UnaryExpression__.js +9 -6
  122. package/out/concepts/UnaryExpression__.js.map +1 -1
  123. package/out/concepts/ValidationRule__.js +23 -88
  124. package/out/concepts/ValidationRule__.js.map +1 -1
  125. package/out/concepts/Variable__.js +2 -38
  126. package/out/concepts/Variable__.js.map +1 -1
  127. package/out/concepts/ViewComponent__.js.map +1 -1
  128. package/out/concepts/ViewElement__.d.ts +29 -30
  129. package/out/concepts/ViewElement__.js +52 -118
  130. package/out/concepts/ViewElement__.js.map +1 -1
  131. package/out/concepts/View__.d.ts +3 -4
  132. package/out/concepts/View__.js +83 -97
  133. package/out/concepts/View__.js.map +1 -1
  134. package/out/concepts/WhileStatement__.js +1 -1
  135. package/out/concepts/WhileStatement__.js.map +1 -1
  136. package/out/concepts/basics/stdlib/nasl.browser.js +0 -50
  137. package/out/concepts/basics/stdlib/nasl.browser.js.map +1 -1
  138. package/out/concepts/basics/stdlib/nasl.ui.js +4 -36
  139. package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
  140. package/out/concepts/basics/stdlib/nasl.util.js +43 -63
  141. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  142. package/out/concepts/index__.d.ts +0 -2
  143. package/out/concepts/index__.js +0 -2
  144. package/out/concepts/index__.js.map +1 -1
  145. package/out/generator/genBundleFiles.d.ts +2 -5
  146. package/out/generator/genBundleFiles.js +155 -108
  147. package/out/generator/genBundleFiles.js.map +1 -1
  148. package/out/generator/genMetaData.d.ts +10 -1
  149. package/out/generator/genMetaData.js +50 -189
  150. package/out/generator/genMetaData.js.map +1 -1
  151. package/out/generator/index.d.ts +0 -1
  152. package/out/generator/index.js +0 -1
  153. package/out/generator/index.js.map +1 -1
  154. package/out/index.d.ts +2 -3
  155. package/out/index.js +1 -5
  156. package/out/index.js.map +1 -1
  157. package/out/server/entity2LogicNamespace.js +11 -11
  158. package/out/server/entity2LogicNamespace.js.map +1 -1
  159. package/out/server/extendBaseNode.js +18 -4
  160. package/out/server/extendBaseNode.js.map +1 -1
  161. package/out/server/formatTsUtils.d.ts +2 -1
  162. package/out/server/formatTsUtils.js +64 -40
  163. package/out/server/formatTsUtils.js.map +1 -1
  164. package/out/server/getLogics.js +6 -13
  165. package/out/server/getLogics.js.map +1 -1
  166. package/out/server/getMemberIdentifier.js +7 -7
  167. package/out/server/getMemberIdentifier.js.map +1 -1
  168. package/out/server/getProcesses.d.ts +1 -1
  169. package/out/server/getProcesses.js +1 -1
  170. package/out/server/getProcesses.js.map +1 -1
  171. package/out/server/index.d.ts +1 -0
  172. package/out/server/index.js +27 -2
  173. package/out/server/index.js.map +1 -1
  174. package/out/server/naslServer.d.ts +7 -47
  175. package/out/server/naslServer.js +399 -604
  176. package/out/server/naslServer.js.map +1 -1
  177. package/out/server/naslStdlibMap.js +28 -30
  178. package/out/server/naslStdlibMap.js.map +1 -1
  179. package/out/server/translator.js +11 -59
  180. package/out/server/translator.js.map +1 -1
  181. package/out/service/storage/init.js +3 -33
  182. package/out/service/storage/init.js.map +1 -1
  183. package/out/templator/genCreateBlock.js +4 -6
  184. package/out/templator/genCreateBlock.js.map +1 -1
  185. package/out/templator/genCurdEditMultipleKeyBlock.js +4 -7
  186. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  187. package/out/templator/genCurdMultipleKeyBlock.js +5 -7
  188. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  189. package/out/templator/genEnumSelectBlock.js +2 -5
  190. package/out/templator/genEnumSelectBlock.js.map +1 -1
  191. package/out/templator/genGridViewBlock.js +2 -2
  192. package/out/templator/genGridViewBlock.js.map +1 -1
  193. package/out/templator/genListViewBlock.js +2 -2
  194. package/out/templator/genListViewBlock.js.map +1 -1
  195. package/out/templator/genQueryComponent.d.ts +2 -2
  196. package/out/templator/genQueryComponent.js +1 -4
  197. package/out/templator/genQueryComponent.js.map +1 -1
  198. package/out/templator/genTableBlock.js +2 -2
  199. package/out/templator/genTableBlock.js.map +1 -1
  200. package/out/templator/genUpdateBlock.js +3 -4
  201. package/out/templator/genUpdateBlock.js.map +1 -1
  202. package/out/templator/utils.js +1 -1
  203. package/out/templator/utils.js.map +1 -1
  204. package/out/test/integration/node-nasl-server.js +38 -10
  205. package/out/test/integration/node-nasl-server.js.map +1 -1
  206. package/out/translator/index.d.ts +0 -1
  207. package/out/translator/index.js +1 -1
  208. package/out/translator/index.js.map +1 -1
  209. package/out/utils/index.d.ts +0 -1
  210. package/out/utils/index.js +1 -38
  211. package/out/utils/index.js.map +1 -1
  212. package/out/utils/string.d.ts +2 -15
  213. package/out/utils/string.js +3 -18
  214. package/out/utils/string.js.map +1 -1
  215. package/package.json +2 -2
  216. package/sandbox/stdlib/nasl.auth.ts +1 -1
  217. package/sandbox/stdlib/nasl.core.ts +1 -0
  218. package/sandbox/stdlib/nasl.logging.ts +4 -4
  219. package/sandbox/stdlib/nasl.util.ts +8 -4
  220. package/src/automate/engine/index.js +4 -4
  221. package/src/automate/engine/uniqueName.js +3 -3
  222. package/src/automate/template/myProcess.js +1 -1
  223. package/src/automate/upgrader/2.20.js +41 -0
  224. package/src/bak/translator.js +4 -1
  225. package/src/concepts/AnonymousFunction__.ts +48 -2
  226. package/src/concepts/App__.ts +288 -615
  227. package/src/concepts/BatchAssignment__.ts +45 -1
  228. package/src/concepts/BindAttribute__.ts +18 -25
  229. package/src/concepts/BindDirective__.ts +7 -0
  230. package/src/concepts/BindEvent__.ts +7 -0
  231. package/src/concepts/BindStyle__.ts +7 -0
  232. package/src/concepts/CallFunction__.ts +34 -45
  233. package/src/concepts/CallInterface__.ts +2 -1
  234. package/src/concepts/CallLogic__.ts +61 -44
  235. package/src/concepts/CallQueryComponent__.ts +4 -1
  236. package/src/concepts/Constant__.ts +7 -0
  237. package/src/concepts/DataSource__.ts +57 -5
  238. package/src/concepts/Destination__.ts +8 -21
  239. package/src/concepts/Frontend__.ts +937 -0
  240. package/src/concepts/Identifier__.ts +18 -16
  241. package/src/concepts/LogicItem__.ts +8 -1
  242. package/src/concepts/Logic__.ts +128 -142
  243. package/src/concepts/Match__.ts +13 -29
  244. package/src/concepts/NewComposite__.ts +1357 -0
  245. package/src/concepts/NewList__.ts +440 -0
  246. package/src/concepts/NewMap__.ts +666 -0
  247. package/src/concepts/New__.ts +73 -0
  248. package/src/concepts/Param__.ts +245 -199
  249. package/src/concepts/ProcessElement__.ts +43 -36
  250. package/src/concepts/ProcessOutcomes__.ts +90 -0
  251. package/src/concepts/Process__.ts +1 -23
  252. package/src/concepts/Return__.ts +11 -1
  253. package/src/concepts/SelectMembers__.ts +3 -3
  254. package/src/concepts/Transactional__.ts +7 -0
  255. package/src/concepts/TypeAnnotation__.ts +54 -49
  256. package/src/concepts/ValidationRule__.ts +19 -1
  257. package/src/concepts/Variable__.ts +12 -6
  258. package/src/concepts/ViewElement__.ts +51 -7
  259. package/src/concepts/View__.ts +21 -25
  260. package/src/concepts/basics/stdlib/nasl.auth.ts +1 -1
  261. package/src/concepts/basics/stdlib/nasl.logging.ts +5 -0
  262. package/src/concepts/basics/stdlib/nasl.ui.ts +2 -0
  263. package/src/concepts/basics/stdlib/nasl.util.ts +153 -19
  264. package/src/concepts/index__.ts +7 -0
  265. package/src/enums/KEYWORDS.ts +9 -0
  266. package/src/generator/genBundleFiles.ts +43 -29
  267. package/src/generator/genMetaData.ts +5 -10
  268. package/src/generator/genReleaseBody.ts +77 -41
  269. package/src/generator/index.ts +1 -0
  270. package/src/generator/permission.ts +261 -0
  271. package/src/index.ts +1 -1
  272. package/src/server/entity2LogicNamespace.ts +90 -10
  273. package/src/server/extendBaseNode.ts +29 -3
  274. package/src/server/formatTsUtils.ts +6 -0
  275. package/src/server/getLogics.ts +13 -1
  276. package/src/server/getMemberIdentifier.ts +5 -5
  277. package/src/server/naslServer.ts +235 -58
  278. package/src/server/process2LogicNamespace.ts +8 -0
  279. package/src/server/translator.ts +33 -1
  280. package/src/service/creator/add.configs.js +4 -0
  281. package/src/service/datasource/api.js +11 -0
  282. package/src/service/datasource/index.js +6 -0
  283. package/src/service/storage/init.ts +12 -0
  284. package/src/service/video/VideoTranscribe.js +1 -0
  285. package/src/templator/genEditTableBlock.ts +8 -16
  286. package/src/templator/genGetBlock.ts +18 -19
  287. package/src/templator/genGridViewBlock.ts +18 -18
  288. package/src/templator/genListViewBlock.ts +8 -11
  289. package/src/templator/genTableBlock.ts +6 -10
  290. package/ts-worker/lib/tsserver.js +8 -1
  291. package/out/automate/engine/2.14-components.d.ts +0 -1115
  292. package/out/automate/engine/2.14-components.js +0 -1087
  293. package/out/automate/engine/2.14-components.js.map +0 -1
  294. package/out/concepts/ExternalDestination__.d.ts +0 -73
  295. package/out/concepts/ExternalDestination__.js +0 -264
  296. package/out/concepts/ExternalDestination__.js.map +0 -1
  297. package/out/concepts/MatchExpression__.d.ts +0 -97
  298. package/out/concepts/MatchExpression__.js +0 -281
  299. package/out/concepts/MatchExpression__.js.map +0 -1
  300. package/out/concepts/StringInterpolation__.d.ts +0 -113
  301. package/out/concepts/StringInterpolation__.js +0 -227
  302. package/out/concepts/StringInterpolation__.js.map +0 -1
  303. package/out/generator/genReleaseBody.d.ts +0 -41
  304. package/out/generator/genReleaseBody.js +0 -349
  305. package/out/generator/genReleaseBody.js.map +0 -1
  306. package/out/service/defaultErrorMessage.json +0 -97
  307. package/out/service/logic/api.d.ts +0 -9
  308. package/out/service/logic/api.js +0 -11
  309. package/out/service/logic/api.js.map +0 -1
  310. package/out/service/logic/index.d.ts +0 -2
  311. package/out/service/logic/index.js +0 -10
  312. package/out/service/logic/index.js.map +0 -1
  313. package/sandbox/stdlib/dist/nasl.logging.js +0 -0
  314. package/src/automate/engine/dist/index.dev.js +0 -517
  315. package/src/common/dist/BaseNode.js +0 -1101
  316. package/src/concepts/basics/stdlib/dist/nasl.util.js +0 -1503
  317. package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +0 -24
  318. package/src/concepts/dist/Anchor__.js +0 -179
  319. package/src/concepts/dist/Assignment__.js +0 -301
  320. package/src/concepts/dist/CallFunction__.js +0 -513
  321. package/src/concepts/dist/CallInterface__.js +0 -533
  322. package/src/concepts/dist/CallLogic__.js +0 -892
  323. package/src/concepts/dist/ForEachStatement__.js +0 -426
  324. package/src/concepts/dist/MatchCase__.js +0 -587
  325. package/src/concepts/dist/Match__.js +0 -631
  326. package/src/concepts/dist/MemberExpression__.js +0 -348
  327. package/src/concepts/dist/Param__.js +0 -538
  328. package/src/concepts/dist/Return__.js +0 -494
  329. package/src/concepts/dist/Variable__.js +0 -537
  330. package/src/concepts/dist/ViewElement__.js +0 -1680
  331. package/src/generator/dist/genBundleFiles.js +0 -261
  332. package/src/generator/dist/genMetaData.js +0 -249
  333. package/src/server/dist/formatTsUtils.js +0 -683
  334. package/src/server/dist/naslServer.js +0 -3474
  335. package/src/service/storage/dist/init.js +0 -572
  336. package/ts-worker/dist/webpack.config.dev.js +0 -108
@@ -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 {
@@ -189,7 +189,7 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
189
189
  const node = this;
190
190
 
191
191
  // 删除页面或者流程
192
- if (node instanceof View || node instanceof Process) {
192
+ if (node instanceof View || node instanceof Process || node instanceof Frontend) {
193
193
  /**
194
194
  * 查找这个页面是不是有依赖
195
195
  */
@@ -209,7 +209,33 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
209
209
  } else {
210
210
  this.delete();
211
211
  }
212
- 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
+ }
213
239
  }
214
240
  }
215
241
  callback = async () => {
@@ -513,6 +513,8 @@ export function formatVariableData(data: unknown | variableItem[], node: BaseNod
513
513
  item.expression = memberExpression;
514
514
  item.variableParent = parent;
515
515
  item.typeKey = typeKey;
516
+ // 标记实体属性是否是符合类型
517
+ item.isComplexType = item.typeAnnotation?.isComplexType();
516
518
  }
517
519
  // 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
518
520
  if (typeKey && !isNoChildType(typeKey)) {
@@ -532,6 +534,10 @@ export function formatVariableData(data: unknown | variableItem[], node: BaseNod
532
534
  // 如果是从实体或者数据结构取的属性,就需要重置一下类型
533
535
  item.concept = 'CompletionProperty';
534
536
  const completionProperty = new CompletionProperty(item);
537
+ // 标记实体属性是否是符合类型
538
+ if (typeof item.isComplexType === 'boolean') {
539
+ Object.assign(completionProperty, { isComplexType: item.isComplexType });
540
+ }
535
541
  if (!parent) {
536
542
  // 变量 param return 在这里添加图标
537
543
  completionProperty.icon = getNodeiconFromLogic(completionProperty, node);
@@ -1,3 +1,4 @@
1
+ import { Identifier } from './../concepts/Identifier__';
1
2
  import { CallLogic, BindEvent, App, Namespace, Entity, BaseNode, Logic, Param, TypeAnnotation, Return, Process, ViewElement, stdlibNamespace, EnumItem } from '..';
2
3
  import { process2LogicNamespace } from './process2LogicNamespace';
3
4
  import { moduleToLogicNamesapce } from './getExtensionModules';
@@ -56,7 +57,7 @@ function iterator(tree: FakeNode | FakeProcessNode, searchContent: string, fakeN
56
57
  function toHump(name: string): string {
57
58
  return name.replace(/\-(\w)/g, (all, letter) => letter.toUpperCase());
58
59
  }
59
- export async function getLogics(node: CallLogic | BindEvent, needAllLogic: boolean = true) {
60
+ export async function getLogics(node: CallLogic | BindEvent| Identifier, needAllLogic: boolean = true) {
60
61
  const app = node.rootNode as App;
61
62
  if (node.concept === 'CallLogic' || node.concept === 'BindEvent') {
62
63
  const result = [];
@@ -264,6 +265,17 @@ export async function getLogics(node: CallLogic | BindEvent, needAllLogic: boole
264
265
  result.push(systemTree);
265
266
  }
266
267
  return result;
268
+ } else if (node.concept === 'Identifier') {
269
+ const extensions = app.dependencies.map(moduleToLogicNamesapce).filter((item) => item.logics && item.logics.length);
270
+ const tree = new Namespace({
271
+ name: 'category`',
272
+ path: `${app.getNamespace()}.logics`,
273
+ title: '全局逻辑',
274
+ logics: app.logics,
275
+ children: [...extensions],
276
+ });
277
+
278
+ return [tree];
267
279
  }
268
280
  }
269
281
 
@@ -1,4 +1,4 @@
1
- import { BaseNode, CompletionProperty, App, Variable, Identifier, MemberExpression, Enum, NullLiteral, BooleanLiteral, Param, BindAttribute, LogicItem, TypeAnnotation, StructureProperty, Entity, Structure, EntityProperty } from '..';
1
+ import { BaseNode, CompletionProperty, App, Variable, Identifier, MemberExpression, Enum, NullLiteral, BooleanLiteral, Param, BindAttribute, LogicItem, TypeAnnotation, StructureProperty, Entity, Structure, EntityProperty, Frontend, View } from '..';
2
2
  import { formatVariableData, formatFrontEndVariables } from './formatTsUtils';
3
3
 
4
4
  // 简单实现一版本的格式化nums
@@ -191,7 +191,7 @@ export async function getMemberIdentifier(node: BaseNode) {
191
191
 
192
192
  // 这个可能需要自己算一下
193
193
  const result = [
194
- { name: '字面量', children: literals, expanded: true, icon: 'category' },
194
+ { name: '常量', children: literals, expanded: true, icon: 'category' },
195
195
  { name: '枚举', children: newEnums, expanded: false, icon: 'category' },
196
196
  { name: '变量', children: completionData, expanded: true, icon: 'category' },
197
197
  { name: '公共变量', children: globalVariable, expanded: false, icon: 'category' },
@@ -199,7 +199,7 @@ export async function getMemberIdentifier(node: BaseNode) {
199
199
  ];
200
200
  if ((node as Identifier).view) {
201
201
  // 获取前端全局变量
202
- const frontEndVariable = getFrontEndVariablesIdentifier(node);
202
+ const frontEndVariable = getFrontEndVariablesIdentifier((node as Identifier).view);
203
203
  result.push({ name: '前端全局变量', children: frontEndVariable, expanded: true, icon: 'category' });
204
204
  }
205
205
  getCurrentLogic(node, result);
@@ -208,8 +208,8 @@ export async function getMemberIdentifier(node: BaseNode) {
208
208
  }
209
209
 
210
210
  export function getFrontEndVariablesIdentifier(node: BaseNode) {
211
- const app = node.rootNode as App;
212
- const frontEndVariables = app?.frontendVariables;
211
+ const frontend = (node as View).frontend as Frontend;
212
+ const frontEndVariables = frontend?.variables;
213
213
  const newFrontEndVariables = frontEndVariables ? formatFrontEndVariables(frontEndVariables) : [];
214
214
  return newFrontEndVariables;
215
215
  }