@lcap/nasl 2.22.0-beta.5 → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/README.md +13 -0
  2. package/docs/classes/Module.html +15 -15
  3. package/docs/classes/Namespace.html +15 -15
  4. package/docs/classes/ViewComponent.html +19 -19
  5. package/out/automate/engine/utils.js +4 -0
  6. package/out/automate/engine/utils.js.map +1 -1
  7. package/out/breakpoint/generator/AfterStartNode.d.ts +7 -0
  8. package/out/breakpoint/generator/AfterStartNode.js +27 -0
  9. package/out/breakpoint/generator/AfterStartNode.js.map +1 -0
  10. package/out/breakpoint/generator/BeforeEndNode.d.ts +7 -0
  11. package/out/breakpoint/generator/BeforeEndNode.js +27 -0
  12. package/out/breakpoint/generator/BeforeEndNode.js.map +1 -0
  13. package/out/breakpoint/generator/BreakpointNode.d.ts +14 -0
  14. package/out/breakpoint/generator/BreakpointNode.js +166 -0
  15. package/out/breakpoint/generator/BreakpointNode.js.map +1 -0
  16. package/out/breakpoint/generator/index.d.ts +4 -0
  17. package/out/breakpoint/generator/index.js +98 -0
  18. package/out/breakpoint/generator/index.js.map +1 -0
  19. package/out/breakpoint/index.d.ts +3 -0
  20. package/out/breakpoint/index.js +20 -0
  21. package/out/breakpoint/index.js.map +1 -0
  22. package/out/breakpoint/shared/constants.d.ts +30 -0
  23. package/out/breakpoint/shared/constants.js +87 -0
  24. package/out/breakpoint/shared/constants.js.map +1 -0
  25. package/out/breakpoint/shared/index.d.ts +3 -0
  26. package/out/breakpoint/shared/index.js +33 -0
  27. package/out/breakpoint/shared/index.js.map +1 -0
  28. package/out/breakpoint/shared/operations.d.ts +10 -0
  29. package/out/breakpoint/shared/operations.js +25 -0
  30. package/out/breakpoint/shared/operations.js.map +1 -0
  31. package/out/breakpoint/shared/socket.d.ts +47 -0
  32. package/out/breakpoint/shared/socket.js +210 -0
  33. package/out/breakpoint/shared/socket.js.map +1 -0
  34. package/out/breakpoint/shared/utils.d.ts +20 -0
  35. package/out/breakpoint/shared/utils.js +133 -0
  36. package/out/breakpoint/shared/utils.js.map +1 -0
  37. package/out/breakpoint/store/core.d.ts +30 -0
  38. package/out/breakpoint/store/core.js +341 -0
  39. package/out/breakpoint/store/core.js.map +1 -0
  40. package/out/breakpoint/store/dock.d.ts +1 -0
  41. package/out/breakpoint/store/dock.js +127 -0
  42. package/out/breakpoint/store/dock.js.map +1 -0
  43. package/out/breakpoint/store/index.d.ts +2 -0
  44. package/out/breakpoint/store/index.js +19 -0
  45. package/out/breakpoint/store/index.js.map +1 -0
  46. package/out/common/BaseNode.d.ts +8 -0
  47. package/out/common/BaseNode.js +19 -0
  48. package/out/common/BaseNode.js.map +1 -1
  49. package/out/concepts/App__.d.ts +365 -16
  50. package/out/concepts/App__.js +431 -10
  51. package/out/concepts/App__.js.map +1 -1
  52. package/out/concepts/Assignment__.js +1 -1
  53. package/out/concepts/Assignment__.js.map +1 -1
  54. package/out/concepts/AuthInterface__.d.ts +37 -0
  55. package/out/concepts/AuthInterface__.js +141 -0
  56. package/out/concepts/AuthInterface__.js.map +1 -0
  57. package/out/concepts/AuthLogicForCallInterface__.d.ts +138 -0
  58. package/out/concepts/AuthLogicForCallInterface__.js +493 -0
  59. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -0
  60. package/out/concepts/AuthLogic__.d.ts +66 -0
  61. package/out/concepts/AuthLogic__.js +206 -0
  62. package/out/concepts/AuthLogic__.js.map +1 -0
  63. package/out/concepts/BackendVariable__.d.ts +137 -0
  64. package/out/concepts/BackendVariable__.js +422 -0
  65. package/out/concepts/BackendVariable__.js.map +1 -0
  66. package/out/concepts/Backend__.d.ts +134 -0
  67. package/out/concepts/Backend__.js +274 -0
  68. package/out/concepts/Backend__.js.map +1 -0
  69. package/out/concepts/BindAttribute__.d.ts +1 -1
  70. package/out/concepts/BindAttribute__.js +3 -1
  71. package/out/concepts/BindAttribute__.js.map +1 -1
  72. package/out/concepts/BindEvent__.d.ts +12 -0
  73. package/out/concepts/BindEvent__.js +68 -0
  74. package/out/concepts/BindEvent__.js.map +1 -1
  75. package/out/concepts/CallAuthInterface__.d.ts +126 -0
  76. package/out/concepts/CallAuthInterface__.js +408 -0
  77. package/out/concepts/CallAuthInterface__.js.map +1 -0
  78. package/out/concepts/CallInterface__.d.ts +6 -1
  79. package/out/concepts/CallInterface__.js +9 -1
  80. package/out/concepts/CallInterface__.js.map +1 -1
  81. package/out/concepts/CallLogic__.js +3 -1
  82. package/out/concepts/CallLogic__.js.map +1 -1
  83. package/out/concepts/CallQueryComponent__.js +9 -7
  84. package/out/concepts/CallQueryComponent__.js.map +1 -1
  85. package/out/concepts/Destination__.js +1 -1
  86. package/out/concepts/Destination__.js.map +1 -1
  87. package/out/concepts/End__.js +29 -2
  88. package/out/concepts/End__.js.map +1 -1
  89. package/out/concepts/EntityProperty__.js.map +1 -1
  90. package/out/concepts/Entity__.d.ts +1 -2
  91. package/out/concepts/Entity__.js +1 -31
  92. package/out/concepts/Entity__.js.map +1 -1
  93. package/out/concepts/ForEachStatement__.js +9 -4
  94. package/out/concepts/ForEachStatement__.js.map +1 -1
  95. package/out/concepts/FrontendLibrary__.d.ts +29 -29
  96. package/out/concepts/FrontendLibrary__.js +2 -2
  97. package/out/concepts/FrontendVariable__.d.ts +21 -0
  98. package/out/concepts/FrontendVariable__.js +64 -0
  99. package/out/concepts/FrontendVariable__.js.map +1 -0
  100. package/out/concepts/Frontend__.d.ts +151 -47
  101. package/out/concepts/Frontend__.js +188 -32
  102. package/out/concepts/Frontend__.js.map +1 -1
  103. package/out/concepts/Function__.js +1 -1
  104. package/out/concepts/Function__.js.map +1 -1
  105. package/out/concepts/Identifier__.js +1 -1
  106. package/out/concepts/Identifier__.js.map +1 -1
  107. package/out/concepts/Interface__.d.ts +1 -1
  108. package/out/concepts/Interface__.js.map +1 -1
  109. package/out/concepts/LogicItem__.d.ts +18 -3
  110. package/out/concepts/LogicItem__.js +22 -4
  111. package/out/concepts/LogicItem__.js.map +1 -1
  112. package/out/concepts/Logic__.d.ts +14 -9
  113. package/out/concepts/Logic__.js +43 -5
  114. package/out/concepts/Logic__.js.map +1 -1
  115. package/out/concepts/Module__.js.map +1 -1
  116. package/out/concepts/Namespace__.d.ts +29 -29
  117. package/out/concepts/Namespace__.js +2 -2
  118. package/out/concepts/NewComposite__.js +2 -2
  119. package/out/concepts/NewComposite__.js.map +1 -1
  120. package/out/concepts/OverriddenLogic__.d.ts +643 -0
  121. package/out/concepts/OverriddenLogic__.js +1602 -0
  122. package/out/concepts/OverriddenLogic__.js.map +1 -0
  123. package/out/concepts/Param__.d.ts +6 -0
  124. package/out/concepts/Param__.js +10 -0
  125. package/out/concepts/Param__.js.map +1 -1
  126. package/out/concepts/QueryFieldExpression__.d.ts +2 -0
  127. package/out/concepts/QueryFieldExpression__.js +9 -0
  128. package/out/concepts/QueryFieldExpression__.js.map +1 -1
  129. package/out/concepts/QuerySelectExpression__.d.ts +2 -2
  130. package/out/concepts/QuerySelectExpression__.js +2 -2
  131. package/out/concepts/QuerySelectExpression__.js.map +1 -1
  132. package/out/concepts/TypeAnnotation__.js +6 -6
  133. package/out/concepts/TypeAnnotation__.js.map +1 -1
  134. package/out/concepts/Variable__.d.ts +10 -0
  135. package/out/concepts/Variable__.js +12 -0
  136. package/out/concepts/Variable__.js.map +1 -1
  137. package/out/concepts/ViewComponent__.d.ts +33 -33
  138. package/out/concepts/ViewComponent__.js +7 -7
  139. package/out/concepts/ViewElement__.d.ts +6 -0
  140. package/out/concepts/ViewElement__.js +104 -1
  141. package/out/concepts/ViewElement__.js.map +1 -1
  142. package/out/concepts/View__.js +2 -2
  143. package/out/concepts/View__.js.map +1 -1
  144. package/out/concepts/basics/stdlib/index.js +2 -1
  145. package/out/concepts/basics/stdlib/index.js.map +1 -1
  146. package/out/concepts/basics/stdlib/nasl.auth.js +24 -0
  147. package/out/concepts/basics/stdlib/nasl.auth.js.map +1 -1
  148. package/out/concepts/basics/stdlib/nasl.http.d.ts +7 -0
  149. package/out/concepts/basics/stdlib/nasl.http.js +167 -0
  150. package/out/concepts/basics/stdlib/nasl.http.js.map +1 -0
  151. package/out/concepts/basics/stdlib/nasl.process.js +68 -0
  152. package/out/concepts/basics/stdlib/nasl.process.js.map +1 -1
  153. package/out/concepts/basics/stdlib/nasl.ui.js +4 -19
  154. package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
  155. package/out/concepts/basics/stdlib/nasl.util.js +83 -17
  156. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  157. package/out/concepts/basics/types/index.d.ts +1 -0
  158. package/out/concepts/basics/types/index.js +4 -1
  159. package/out/concepts/basics/types/index.js.map +1 -1
  160. package/out/concepts/index__.d.ts +8 -0
  161. package/out/concepts/index__.js +8 -0
  162. package/out/concepts/index__.js.map +1 -1
  163. package/out/enums/KEYWORDS.js +0 -1
  164. package/out/enums/KEYWORDS.js.map +1 -1
  165. package/out/generator/genBundleFiles.d.ts +1 -0
  166. package/out/generator/genBundleFiles.js +27 -0
  167. package/out/generator/genBundleFiles.js.map +1 -1
  168. package/out/generator/genMetaData.d.ts +4 -1
  169. package/out/generator/genMetaData.js +14 -0
  170. package/out/generator/genMetaData.js.map +1 -1
  171. package/out/generator/genReleaseBody.d.ts +2 -1
  172. package/out/generator/genReleaseBody.js +2 -1
  173. package/out/generator/genReleaseBody.js.map +1 -1
  174. package/out/index.d.ts +2 -1
  175. package/out/index.js +3 -1
  176. package/out/index.js.map +1 -1
  177. package/out/server/extendBaseNode.js +16 -4
  178. package/out/server/extendBaseNode.js.map +1 -1
  179. package/out/server/formatTsUtils.d.ts +2 -1
  180. package/out/server/formatTsUtils.js +39 -4
  181. package/out/server/formatTsUtils.js.map +1 -1
  182. package/out/server/getExtensionModules.d.ts +2 -2
  183. package/out/server/getExtensionModules.js +16 -2
  184. package/out/server/getExtensionModules.js.map +1 -1
  185. package/out/server/getLogics.js +5 -5
  186. package/out/server/getLogics.js.map +1 -1
  187. package/out/server/getMemberIdentifier.d.ts +1 -0
  188. package/out/server/getMemberIdentifier.js +34 -7
  189. package/out/server/getMemberIdentifier.js.map +1 -1
  190. package/out/server/naslServer.d.ts +64 -64
  191. package/out/server/naslServer.js +249 -121
  192. package/out/server/naslServer.js.map +1 -1
  193. package/out/server/naslStdlibMap.js +2 -0
  194. package/out/server/naslStdlibMap.js.map +1 -1
  195. package/out/server/translator.d.ts +1 -0
  196. package/out/server/translator.js +67 -2
  197. package/out/server/translator.js.map +1 -1
  198. package/out/service/defaultErrorMessage.json +1 -0
  199. package/out/service/storage/api.d.ts +10 -1
  200. package/out/service/storage/api.js +6 -0
  201. package/out/service/storage/api.js.map +1 -1
  202. package/out/service/storage/init.d.ts +4 -0
  203. package/out/service/storage/init.js +55 -35
  204. package/out/service/storage/init.js.map +1 -1
  205. package/out/service/storage/service.d.ts +3 -0
  206. package/out/service/storage/service.js +14 -0
  207. package/out/service/storage/service.js.map +1 -1
  208. package/out/utils/sortTsString.d.ts +1 -0
  209. package/out/utils/sortTsString.js +36 -0
  210. package/out/utils/sortTsString.js.map +1 -0
  211. package/out/utils/traverse.js +2 -2
  212. package/out/utils/traverse.js.map +1 -1
  213. package/package.json +7 -2
  214. package/sandbox/stdlib/nasl.auth.ts +8 -4
  215. package/sandbox/stdlib/nasl.core.d.ts +206 -0
  216. package/sandbox/stdlib/nasl.core.js +1 -0
  217. package/sandbox/stdlib/nasl.core.js.map +1 -0
  218. package/sandbox/stdlib/nasl.http.ts +35 -0
  219. package/sandbox/stdlib/nasl.process.ts +13 -0
  220. package/sandbox/stdlib/nasl.ui.ts +0 -5
  221. package/src/automate/engine/utils.js +4 -1
  222. package/src/breakpoint/generator/AfterStartNode.ts +27 -0
  223. package/src/breakpoint/generator/BeforeEndNode.ts +27 -0
  224. package/src/breakpoint/generator/BreakpointNode.ts +228 -0
  225. package/src/breakpoint/generator/index.ts +114 -0
  226. package/src/breakpoint/index.ts +3 -0
  227. package/src/breakpoint/shared/constants.ts +95 -0
  228. package/src/breakpoint/shared/index.ts +3 -0
  229. package/src/breakpoint/shared/operations.ts +25 -0
  230. package/src/breakpoint/shared/socket.ts +326 -0
  231. package/src/breakpoint/shared/utils.ts +195 -0
  232. package/src/breakpoint/store/core.ts +411 -0
  233. package/src/breakpoint/store/dock.ts +166 -0
  234. package/src/breakpoint/store/index.ts +2 -0
  235. package/src/breakpoint/types/index.d.ts +19 -0
  236. package/src/common/BaseNode.ts +19 -1
  237. package/src/concepts/App__.ts +828 -26
  238. package/src/concepts/Assignment__.ts +1 -1
  239. package/src/concepts/AuthInterface__.ts +148 -0
  240. package/src/concepts/AuthLogicForCallInterface__.ts +573 -0
  241. package/src/concepts/AuthLogic__.ts +225 -0
  242. package/src/concepts/BackendVariable__.ts +466 -0
  243. package/src/concepts/Backend__.ts +347 -0
  244. package/src/concepts/BindAttribute__.ts +4 -3
  245. package/src/concepts/BindEvent__.ts +71 -2
  246. package/src/concepts/CallAuthInterface__.ts +490 -0
  247. package/src/concepts/CallInterface__.ts +10 -2
  248. package/src/concepts/CallLogic__.ts +3 -1
  249. package/src/concepts/CallQueryComponent__.ts +67 -7
  250. package/src/concepts/Destination__.ts +19 -1
  251. package/src/concepts/End__.ts +31 -3
  252. package/src/concepts/EntityProperty__.ts +6 -0
  253. package/src/concepts/Entity__.ts +8 -31
  254. package/src/concepts/ForEachStatement__.ts +9 -4
  255. package/src/concepts/FrontendLibrary__.ts +30 -30
  256. package/src/concepts/FrontendVariable__.ts +76 -0
  257. package/src/concepts/Frontend__.ts +352 -89
  258. package/src/concepts/Function__.ts +1 -1
  259. package/src/concepts/Identifier__.ts +5 -5
  260. package/src/concepts/Interface__.ts +1 -1
  261. package/src/concepts/LogicItem__.ts +26 -6
  262. package/src/concepts/Logic__.ts +86 -8
  263. package/src/concepts/Module__.ts +32 -2
  264. package/src/concepts/Namespace__.ts +30 -30
  265. package/src/concepts/NewComposite__.ts +2 -3
  266. package/src/concepts/OverriddenLogic__.ts +2165 -0
  267. package/src/concepts/Param__.ts +13 -3
  268. package/src/concepts/QueryFieldExpression__.ts +18 -0
  269. package/src/concepts/QuerySelectExpression__.ts +11 -3
  270. package/src/concepts/TypeAnnotation__.ts +45 -6
  271. package/src/concepts/Variable__.ts +14 -0
  272. package/src/concepts/ViewComponent__.ts +35 -35
  273. package/src/concepts/ViewElement__.ts +104 -1
  274. package/src/concepts/View__.ts +24 -2
  275. package/src/concepts/basics/stdlib/index.ts +2 -1
  276. package/src/concepts/basics/stdlib/nasl.auth.ts +24 -0
  277. package/src/concepts/basics/stdlib/nasl.http.ts +166 -0
  278. package/src/concepts/basics/stdlib/nasl.process.ts +68 -0
  279. package/src/concepts/basics/stdlib/nasl.ui.ts +4 -19
  280. package/src/concepts/basics/stdlib/nasl.util.ts +83 -17
  281. package/src/concepts/basics/types/index.ts +5 -4
  282. package/src/concepts/index__.ts +8 -0
  283. package/src/enums/KEYWORDS.ts +0 -1
  284. package/src/generator/genBundleFiles.ts +36 -2
  285. package/src/generator/genMetaData.ts +16 -1
  286. package/src/generator/genReleaseBody.ts +4 -1
  287. package/src/index.ts +2 -1
  288. package/src/server/extendBaseNode.ts +18 -7
  289. package/src/server/formatTsUtils.ts +37 -5
  290. package/src/server/getExtensionModules.ts +18 -3
  291. package/src/server/getLogics.ts +6 -6
  292. package/src/server/getMemberIdentifier.ts +35 -9
  293. package/src/server/naslServer.ts +250 -124
  294. package/src/server/naslStdlibMap.ts +2 -0
  295. package/src/server/translator.ts +67 -1
  296. package/src/service/defaultErrorMessage.json +1 -0
  297. package/src/service/storage/api.js +7 -1
  298. package/src/service/storage/init.ts +66 -35
  299. package/src/service/storage/service.ts +18 -2
  300. package/src/utils/sortTsString.ts +32 -0
  301. package/src/utils/traverse.ts +2 -2
  302. package/test/examples/app-simple.json +73635 -0
  303. package/ts-worker/lib/tsserver.js +3 -3
  304. package/ts-worker/package.json +1 -1
@@ -0,0 +1,225 @@
1
+ //================================================================================
2
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
3
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
4
+ //================================================================================
5
+ import { EventPayload, Params } from '../common/EventEmitter';
6
+ import { concept, excludedInJSON, property } from '../decorators';
7
+
8
+ import * as utils from '../utils';
9
+ import { v4 as uuidv4 } from 'uuid';
10
+ import BaseNode from '../common/BaseNode';
11
+ import classMap from '../common/classMap';
12
+ import Module from './Module__';
13
+ import View from './View__';
14
+ import ProcessElement from './ProcessElement__';
15
+ import App from './App__';
16
+ import Frontend from './Frontend__';
17
+ import Process from './Process__';
18
+ import Logic from './Logic__';
19
+
20
+ /**
21
+ * 开放接口的鉴权逻辑
22
+ */
23
+ @concept('开放接口的鉴权逻辑')
24
+ export class AuthLogic extends Logic {
25
+ /**
26
+ * 产品概念
27
+ */
28
+ @property()
29
+ concept: 'AuthLogic' | 'AuthLogicForCallInterface' = 'AuthLogic';
30
+
31
+ /**
32
+ * 是否为默认鉴权逻辑
33
+ */
34
+ @property()
35
+ isDefault: boolean = undefined;
36
+
37
+ /**
38
+ * 祖先 Module
39
+ */
40
+ get module() {
41
+ return this.getAncestor('Module') as Module;
42
+ }
43
+ /**
44
+ * 祖先 App
45
+ */
46
+ get app() {
47
+ return this.getAncestor('App') as App;
48
+ }
49
+ /**
50
+ * 祖先 View
51
+ */
52
+ get view() {
53
+ return this.getAncestor('View') as View;
54
+ }
55
+ /**
56
+ * 祖先 Frontend
57
+ */
58
+ get frontend() {
59
+ return this.getAncestor('Frontend') as Frontend;
60
+ }
61
+ /**
62
+ * 祖先 ProcessElement
63
+ */
64
+ get processElement() {
65
+ return this.getAncestor('ProcessElement') as ProcessElement;
66
+ }
67
+ /**
68
+ * 祖先 Process
69
+ */
70
+ get process() {
71
+ return this.getAncestor('Process') as Process;
72
+ }
73
+
74
+ /**
75
+ * @param source 需要合并的部分参数
76
+ */
77
+ constructor(source?: Partial<AuthLogic>) {
78
+ source = Object.assign({}, AuthLogic.getDefaultOptions(), source);
79
+ super(source);
80
+ super.subConstructor(source);
81
+ }
82
+ getClassName() {
83
+ return 'AuthLogic';
84
+ }
85
+
86
+ static from(source: any, parentNode?: any, parentKey?: string): AuthLogic {
87
+ return super.from(source, parentNode, parentKey) as AuthLogic;
88
+ }
89
+
90
+
91
+ /**
92
+ * 设置是否为默认鉴权逻辑
93
+ */
94
+ setIsDefault(isDefault: boolean) {
95
+ const object = {
96
+ isDefault,
97
+ };
98
+ this.update({
99
+ ...object,
100
+ });
101
+ }
102
+
103
+
104
+
105
+
106
+
107
+ //================================================================================
108
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
109
+ // 自动生成的代码已结束。下面可以手动编写。
110
+ //================================================================================
111
+ public static getDefaultOptions(): Partial<{
112
+ body: Array<any>,
113
+ params: Array<any>,
114
+ returns: Array<any>,
115
+ }> {
116
+ return {
117
+ body: [
118
+ {
119
+ concept: 'Start',
120
+ label: '开始',
121
+ kind: 'Statement',
122
+ type: 'Start',
123
+ },
124
+ {
125
+ concept: 'End',
126
+ label: '结束',
127
+ kind: 'Statement',
128
+ type: 'End',
129
+ },
130
+ ],
131
+ params: [
132
+ {
133
+ concept: 'Param', // 产品概念
134
+ name: 'request', // 输入参数名称
135
+ description: '请求信息,系统自动注入,包含 method、url、header、cookie、body等', // 输入参数描述
136
+ typeAnnotation: {
137
+ concept: 'TypeAnnotation',
138
+ typeKind: 'generic',
139
+ typeNamespace: 'nasl.http',
140
+ typeName: 'HttpRequest',
141
+ typeArguments: [{
142
+ concept: 'TypeAnnotation',
143
+ typeKind: 'primitive',
144
+ typeNamespace: 'nasl.core',
145
+ typeName: 'String',
146
+ }],
147
+ }, // 类型
148
+ required: true, // 是否必填
149
+ },
150
+ {
151
+ concept: 'Param', // 产品概念
152
+ name: 'response', // 输入参数名称
153
+ description: '请求响应信息,系统自动注入,包含 status、header、cookie、body等', // 输入参数描述
154
+ typeAnnotation: {
155
+ concept: 'TypeAnnotation',
156
+ typeKind: 'generic',
157
+ typeNamespace: 'nasl.http',
158
+ typeName: 'HttpResponse',
159
+ typeArguments: [{
160
+ concept: 'TypeAnnotation',
161
+ typeKind: 'primitive',
162
+ typeNamespace: 'nasl.core',
163
+ typeName: 'String',
164
+ }],
165
+ }, // 类型
166
+ required: true, // 是否必填
167
+ },
168
+ ],
169
+ returns: [
170
+ {
171
+ concept: 'Return', // 产品概念
172
+ name: 'result', // 输出参数名称
173
+ description: '', // 输出参数描述
174
+ typeAnnotation: {
175
+ concept: 'TypeAnnotation',
176
+ typeKind: 'primitive',
177
+ typeNamespace: 'nasl.core',
178
+ typeName: 'Boolean',
179
+ },
180
+ },
181
+ ],
182
+ };
183
+ }
184
+
185
+ /**
186
+ * 生成宿主语言的文件路径
187
+ * @param name 一般不用传,用于 rename
188
+ */
189
+ getEmbeddedFilePath(name = this.name) {
190
+ const _path = this.module ? `/${this.module.parentKey}/${this.module.name}` : '';
191
+ return `/embedded/${this.app.name}${_path}/authLogics/${name}.ts`;
192
+ }
193
+
194
+ getTsNamespace(): string {
195
+ if (this.parentNode) {
196
+ const parentNamespace = (this.parentNode as any)?.getTsNamespace();
197
+ const parentName = this.parentNode.tsName || this.parentNode.name;
198
+ const arr = [parentNamespace];
199
+ if (this.parentNode.concept !== 'App' && parentName) {
200
+ arr.push(parentName);
201
+ }
202
+ let namespace = arr.join('.');
203
+ if (
204
+ !['nasl.ui', 'nasl.utils', 'nasl.util', 'nasl.browser', 'nasl.auth', 'nasl.configuration', 'nasl.process', 'nasl.logging', 'nasl.io'].includes(namespace)
205
+ && !namespace.includes('.authLogics')
206
+ ) {
207
+ namespace = `${namespace}.authLogics`;
208
+ }
209
+ return namespace;
210
+ } else
211
+ throw new Error('无法获取命名空间,请设置 parentNode!');
212
+ }
213
+
214
+ //================================================================================
215
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
216
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
217
+ //================================================================================
218
+ }
219
+
220
+ classMap.AuthLogic = AuthLogic;
221
+ export default AuthLogic;
222
+ //================================================================================
223
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
224
+ // 自动生成的代码已结束。下面可以手动编写。
225
+ //================================================================================
@@ -0,0 +1,466 @@
1
+ import { dataTypesMap } from './basics/types';
2
+ import { TranslatorState, shiftState, withSourceMap, createCompilerState, indent } from '../translator';
3
+ import { ElementToVueOptions } from './ViewElement__';
4
+ import EntityProperty from './EntityProperty__';
5
+ import StructureProperty from './StructureProperty__';
6
+ import Structure from './Structure__';
7
+ import { getNodeByNodeCallee, getNaslNodeByNodeCallee } from '../automate/engine/utils';
8
+ import Namespace from './Namespace__';
9
+
10
+ function tryJSONParse(str: string) {
11
+ let result;
12
+
13
+ try {
14
+ result = JSON.parse(str);
15
+ } catch (e) { }
16
+
17
+ return result;
18
+ }
19
+ //================================================================================
20
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
21
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
22
+ //================================================================================
23
+ import { EventPayload, Params } from '../common/EventEmitter';
24
+ import { concept, excludedInJSON, property } from '../decorators';
25
+
26
+ import * as utils from '../utils';
27
+ import { v4 as uuidv4 } from 'uuid';
28
+ import BaseNode from '../common/BaseNode';
29
+ import classMap from '../common/classMap';
30
+ import TypeAnnotation from './TypeAnnotation__';
31
+ import Backend from './Backend__';
32
+ import View from './View__';
33
+ import App from './App__';
34
+ import Module from './Module__';
35
+ import Frontend from './Frontend__';
36
+
37
+ /**
38
+ * 全局变量
39
+ */
40
+ @concept('全局变量')
41
+ export class BackendVariable extends BaseNode {
42
+ /**
43
+ * 产品概念
44
+ */
45
+ @property()
46
+ concept: 'BackendVariable' = 'BackendVariable';
47
+
48
+ /**
49
+ * 全局变量名称
50
+ */
51
+ @property()
52
+ name: string = undefined;
53
+
54
+ /**
55
+ * 全局变量描述
56
+ */
57
+ @property()
58
+ description: string = undefined;
59
+
60
+ /**
61
+ * 类型
62
+ */
63
+ @property('TypeAnnotation')
64
+ typeAnnotation: TypeAnnotation = undefined;
65
+
66
+ /**
67
+ * 默认值
68
+ */
69
+ @property()
70
+ defaultValue: string = undefined;
71
+
72
+ /**
73
+ * 作用域
74
+ */
75
+ @property()
76
+ scope: 'request' | 'applicaion' = undefined;
77
+
78
+ /**
79
+ * 祖先 Backend
80
+ */
81
+ get Backend() {
82
+ return this.getAncestor('Backend') as Backend;
83
+ }
84
+ /**
85
+ * 祖先 App
86
+ */
87
+ get app() {
88
+ return this.getAncestor('App') as App;
89
+ }
90
+ /**
91
+ * 祖先 View
92
+ */
93
+ get view() {
94
+ return this.getAncestor('View') as View;
95
+ }
96
+ /**
97
+ * 祖先 Module
98
+ */
99
+ get module() {
100
+ return this.getAncestor('Module') as Module;
101
+ }
102
+ /**
103
+ * 祖先 Frontend
104
+ */
105
+ get frontend() {
106
+ return this.getAncestor('Frontend') as Frontend;
107
+ }
108
+
109
+ /**
110
+ * @param source 需要合并的部分参数
111
+ */
112
+ constructor(source?: Partial<BackendVariable>) {
113
+ source = Object.assign({}, BackendVariable.getDefaultOptions(), source);
114
+ super(source);
115
+ super.subConstructor(source);
116
+ }
117
+ getClassName() {
118
+ return 'BackendVariable';
119
+ }
120
+
121
+ static from(source: any, parentNode?: any, parentKey?: string): BackendVariable {
122
+ return super.from(source, parentNode, parentKey) as BackendVariable;
123
+ }
124
+
125
+ /**
126
+ * 从父级删除该节点
127
+ * @internal
128
+ */
129
+ _delete() {
130
+ let params: Params = null;
131
+ if (this.parentNode) {
132
+ params = (this.parentNode as any)?.__removeBackendVariable?.(this);
133
+ }
134
+ return params;
135
+ }
136
+ /**
137
+ * 设置全局变量名称
138
+ */
139
+ setName(name: string) {
140
+ const object = {
141
+ name,
142
+ };
143
+ this.update({
144
+ ...object,
145
+ field: 'name',
146
+ });
147
+ }
148
+
149
+ /**
150
+ * 设置全局变量描述
151
+ */
152
+ setDescription(description: string) {
153
+ const object = {
154
+ description,
155
+ };
156
+ this.update({
157
+ ...object,
158
+ });
159
+ }
160
+
161
+ /**
162
+ * 设置默认值
163
+ */
164
+ setDefaultValue(defaultValue: string) {
165
+ const object = {
166
+ defaultValue,
167
+ };
168
+ this.update({
169
+ ...object,
170
+ });
171
+ }
172
+
173
+ /**
174
+ * 设置作用域
175
+ */
176
+ setScope(scope: 'request' | 'applicaion') {
177
+ const object = {
178
+ scope,
179
+ };
180
+ this.update({
181
+ ...object,
182
+ });
183
+ }
184
+
185
+
186
+
187
+
188
+
189
+ /**
190
+ * 删除类型标注
191
+ * @param name 类型标注名称
192
+ */
193
+ removeTypeAnnotation(name: string): void;
194
+
195
+ /**
196
+ * 删除类型标注
197
+ * @param typeAnnotation 已有的类型标注实例
198
+ */
199
+ removeTypeAnnotation(typeAnnotation: TypeAnnotation): void;
200
+
201
+ removeTypeAnnotation(options: string | TypeAnnotation) {
202
+ let typeAnnotation: TypeAnnotation;
203
+ if (typeof options === 'string') {
204
+ typeAnnotation = this.typeAnnotation;
205
+ if (!typeAnnotation) {
206
+ throw new Error('找不到类型标注 ' + options);
207
+ }
208
+ } else {
209
+ typeAnnotation = options;
210
+ }
211
+ return typeAnnotation.delete();
212
+ }
213
+
214
+ __removeTypeAnnotation(typeAnnotation: TypeAnnotation) {
215
+ const parentKey = typeAnnotation.parentKey;
216
+ const params: Params = {
217
+ parentNode: this,
218
+ parentKey,
219
+ index: -1,
220
+ object: null,
221
+ oldObject: typeAnnotation,
222
+ };
223
+ if (parentKey) {
224
+ params.parentKey = parentKey;
225
+ if (Array.isArray((this as any)[parentKey])) {
226
+ const index = (this as any)[parentKey].indexOf(typeAnnotation);
227
+ ~index && (this as any)[parentKey].splice(index, 1);
228
+ params.index = index;
229
+ } else if ((this as any)[parentKey] === typeAnnotation) {
230
+ params.index = 0;
231
+ (this as any)[parentKey] = undefined;
232
+ }
233
+ }
234
+ return params;
235
+ }
236
+
237
+ //================================================================================
238
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
239
+ // 自动生成的代码已结束。下面可以手动编写。
240
+ //================================================================================
241
+ /**
242
+ * 自动补全的属性列表
243
+ */
244
+ completionChildren: Array<EntityProperty | StructureProperty> = undefined;
245
+
246
+ toVue(options?: ElementToVueOptions): string {
247
+ return this.name;
248
+ }
249
+
250
+ toUI(): string {
251
+ return this.name;
252
+ }
253
+
254
+ toJS(state?: TranslatorState): string {
255
+ const context = this.view ? 'this' : 'Vue.prototype';
256
+ const typeAnnotation = this.typeAnnotation || this.__TypeAnnotation;
257
+ const needGenInitFromSchema = typeAnnotation && (
258
+ !['primitive', 'union'].includes(typeAnnotation.typeKind)
259
+ || typeAnnotation.typeName === 'DateTime'
260
+ );
261
+ let code = `${this.name} =`;
262
+ if (needGenInitFromSchema) {
263
+ code += `${context}.$genInitFromSchema('${typeAnnotation?.sortedTypeKey}',`;
264
+ }
265
+ const defaultValue = this.defaultValue;
266
+ const defaultValueType = Object.prototype.toString.call(defaultValue);
267
+ const { typeKind, typeNamespace, typeName } = typeAnnotation || {};
268
+ // 设置成null,才能同步给后端清除该值,但是null对checkbox组件是一种特殊状态
269
+ let parsedValue = defaultValue ?? undefined;
270
+ if (
271
+ defaultValueType === '[object String]'
272
+ && (
273
+ !(typeKind === 'primitive' && typeNamespace === 'nasl.core' && ['String', 'Text', 'Email'].includes(typeName))
274
+ && !(this.isEnum())
275
+ && !['union'].includes(typeKind)
276
+ )
277
+ ) {
278
+ // 一些特殊情况,特殊处理成undefined
279
+ // 1.defaultValue在nasl节点上错误得赋值给了空制符串
280
+ if ([''].includes(defaultValue)) {
281
+ parsedValue = undefined;
282
+ } else {
283
+ parsedValue = tryJSONParse(defaultValue) ?? defaultValue;
284
+ }
285
+ }
286
+ code += JSON.stringify(parsedValue);
287
+ if (needGenInitFromSchema) {
288
+ code += `)`;
289
+ }
290
+ return code;
291
+ }
292
+
293
+ @withSourceMap()
294
+ toEmbeddedTS(state?: TranslatorState): string {
295
+ let code = this.name;
296
+ if (this.typeAnnotation) {
297
+ code += ': ';
298
+ code += this.typeAnnotation.toEmbeddedTS(shiftState(state, code));
299
+ // toTS暂时只需要翻译引用数据类型的,因为值都是字符串
300
+ // 就不在这里赋值了,这里单纯就为了快速查找
301
+ // 并且屏蔽了一些异常的错误
302
+ if (this.typeAnnotation?.typeKind !== 'primitive' && this.defaultValue) {
303
+ if (this.isEnum()) {
304
+ code += `= ${this.typeAnnotation.typeKey}['${this.defaultValue}']`;
305
+ }
306
+ }
307
+ }
308
+ return code;
309
+ }
310
+ isEnum() {
311
+ return this.typeAnnotation?.typeNamespace?.endsWith('.enums');
312
+ }
313
+
314
+ /**
315
+ * 生成宿主语言的文件路径
316
+ * @param name 一般不用传,用于 rename
317
+ */
318
+ getEmbeddedFilePath(name = this.name) {
319
+ return `/embedded/${this.app.name}/Backend/${this.parentNode.name || 'backend'}/variables/${name}.ts`;
320
+ }
321
+ getNamespace() {
322
+ if (this.parentNode && (this.parentNode as Namespace).getNamespace) {
323
+ const parentNamespace = (this.parentNode as Namespace).getNamespace();
324
+ const parentName = this.parentNode.name;
325
+ const arr = [parentNamespace];
326
+ if (this.parentNode.concept !== 'App' && parentName) {
327
+ arr.push(parentName);
328
+ }
329
+ if (['App', 'Module', 'Namespace', 'Backend'].includes(this.parentNode?.concept) && this.parentKey === 'variables') {
330
+ // return `${arr.join('.')}.backendVariables`;
331
+ return `${arr.join('.')}.variables`;
332
+ } else {
333
+ return `${arr.join('.')}.variables`;
334
+ }
335
+ } else
336
+ throw new Error('无法获取命名空间,请设置 parentNode!');
337
+ }
338
+ toEmbeddedTSFile() {
339
+ let code = `namespace ${this.getNamespace()} {\n`;
340
+ code += `${indent(1)}export let `;
341
+ const state = createCompilerState(code, { tabSize: 1 });
342
+ try {
343
+ code += `${this.toEmbeddedTS(state)}\n`;
344
+ } catch (err) {
345
+ code += '\n';
346
+ }
347
+ code += '}\n';
348
+
349
+ return {
350
+ code,
351
+ filePath: this.getEmbeddedFilePath(),
352
+ sourceMap: state.sourceMap,
353
+ };
354
+ }
355
+
356
+ @withSourceMap()
357
+ toEmbeddedTSInProcess(state?: TranslatorState): string {
358
+ let code = this.name;
359
+ if (this.typeAnnotation) {
360
+ code += ': undefined as ';
361
+ code += this.typeAnnotation.toEmbeddedTS(shiftState(state, code));
362
+ }
363
+ // if (this.defaultValue) {
364
+ // code += `: ${this.defaultValue}`;
365
+ // }
366
+ return code;
367
+ }
368
+
369
+ /**
370
+ * 设置数据类型
371
+ * @param typeAnnotation 类型标注对象
372
+ */
373
+ async setDataType(typeAnnotation: TypeAnnotation): Promise<void>;
374
+ /**
375
+ * 设置数据类型
376
+ * @param typeAnnotation 类型唯一标识
377
+ */
378
+ async setDataType(typeKey: string): Promise<void>;
379
+ async setDataType(typeAnnotation: TypeAnnotation | string) {
380
+ if (typeAnnotation) {
381
+ if (typeof typeAnnotation === 'string') {
382
+ typeAnnotation = dataTypesMap[typeAnnotation];
383
+ if (!typeAnnotation)
384
+ throw new Error('找不到类型:' + typeAnnotation);
385
+ } else {
386
+ typeAnnotation._delete?.();
387
+ const relationOptions = { parentId: this.id, parentConcept: this.concept, parentNode: this };
388
+ Object.assign(typeAnnotation, relationOptions);
389
+ }
390
+
391
+ // 处理下拉属性
392
+ try {
393
+ this.completionChildren = this.getSelectRef(typeAnnotation, true);
394
+ } catch (err) {
395
+ this.completionChildren = [];
396
+ console.log(err);
397
+ }
398
+ } else {
399
+ this.completionChildren = [];
400
+ }
401
+ const object: any = {
402
+ typeAnnotation: typeAnnotation || null,
403
+ };
404
+ // 切换类型的时候如果有默认值就清除掉
405
+ if (this.defaultValue) {
406
+ object.defaultValue = '';
407
+ }
408
+
409
+ return this.update({
410
+ ...object,
411
+ });
412
+ }
413
+
414
+
415
+ async _setDataType(typeAnnotation: TypeAnnotation | string) {
416
+ if (typeAnnotation) {
417
+ if (typeof typeAnnotation === 'string') {
418
+ typeAnnotation = dataTypesMap[typeAnnotation];
419
+ if (!typeAnnotation)
420
+ throw new Error('找不到类型:' + typeAnnotation);
421
+ } else {
422
+ // typeAnnotation._delete?.();
423
+ const relationOptions = { parentId: this.id, parentConcept: this.concept, parentNode: this };
424
+ Object.assign(typeAnnotation, relationOptions);
425
+ }
426
+
427
+ // 处理下拉属性
428
+ try {
429
+ this.completionChildren = this.getSelectRef(typeAnnotation, true);
430
+ } catch (err) {
431
+ this.completionChildren = [];
432
+ console.log(err);
433
+ }
434
+ } else {
435
+ this.completionChildren = [];
436
+ }
437
+ const object: any = {
438
+ typeAnnotation: typeAnnotation || null,
439
+ };
440
+ // 切换类型的时候如果有默认值就清除掉
441
+ if (this.defaultValue) {
442
+ object.defaultValue = '';
443
+ }
444
+ }
445
+ public static getDefaultOptions() {
446
+ return {};
447
+ }
448
+
449
+ /**
450
+ * 是否可编辑
451
+ * */
452
+ get readonly() {
453
+ return !!this.module;
454
+ }
455
+ //================================================================================
456
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
457
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
458
+ //================================================================================
459
+ }
460
+
461
+ classMap.BackendVariable = BackendVariable;
462
+ export default BackendVariable;
463
+ //================================================================================
464
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
465
+ // 自动生成的代码已结束。下面可以手动编写。
466
+ //================================================================================