@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,347 @@
1
+ import Namespace from './Namespace__';
2
+ import { TranslatorState, shiftState, withSourceMap, indent, createCompilerState } from '../translator';
3
+
4
+ //================================================================================
5
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
6
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
7
+ //================================================================================
8
+ import { EventPayload, Params } from '../common/EventEmitter';
9
+ import { concept, excludedInJSON, property } from '../decorators';
10
+
11
+ import * as utils from '../utils';
12
+ import { v4 as uuidv4 } from 'uuid';
13
+ import BaseNode from '../common/BaseNode';
14
+ import classMap from '../common/classMap';
15
+ import BackendVariable from './BackendVariable__';
16
+ import App from './App__';
17
+
18
+ /**
19
+ * 后端
20
+ */
21
+ @concept('后端')
22
+ export class Backend extends BaseNode {
23
+ /**
24
+ * 产品概念
25
+ */
26
+ @property()
27
+ concept: 'Backend' = 'Backend';
28
+
29
+ /**
30
+ * 后端标识
31
+ */
32
+ @property()
33
+ name: string = undefined;
34
+
35
+ /**
36
+ * 全局变量列表
37
+ */
38
+ @property('BackendVariable')
39
+ variables: Array<BackendVariable> = [];
40
+
41
+ /**
42
+ * 祖先 App
43
+ */
44
+ get app() {
45
+ return this.getAncestor('App') as App;
46
+ }
47
+
48
+ /**
49
+ * @param source 需要合并的部分参数
50
+ */
51
+ constructor(source?: Partial<Backend>) {
52
+ source = Object.assign({}, Backend.getDefaultOptions(), source);
53
+ super(source);
54
+ super.subConstructor(source);
55
+ }
56
+ getClassName() {
57
+ return 'Backend';
58
+ }
59
+
60
+ static from(source: any, parentNode?: any, parentKey?: string): Backend {
61
+ return super.from(source, parentNode, parentKey) as Backend;
62
+ }
63
+
64
+ /**
65
+ * 从父级删除该节点
66
+ * @internal
67
+ */
68
+ _delete() {
69
+ let params: Params = null;
70
+ if (this.parentNode) {
71
+ params = (this.parentNode as any)?.__removeBackend?.(this);
72
+ }
73
+ return params;
74
+ }
75
+ /**
76
+ * 设置后端标识
77
+ */
78
+ setName(name: string) {
79
+ const object = {
80
+ name,
81
+ };
82
+ this.update({
83
+ ...object,
84
+ field: 'name',
85
+ });
86
+ }
87
+
88
+ getVarExistingNames(excludedList: Array<BackendVariable> = []) {
89
+ const excludedSet = new Set(excludedList);
90
+ return ((this.variables as BackendVariable[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
91
+ }
92
+ getBackendVariableUniqueName(name = 'backendVariable1') {
93
+ return utils.unique(name, this.getVarExistingNames(), undefined, true);
94
+ }
95
+
96
+ /**
97
+ * 插入全局变量
98
+ * @internal
99
+ * @param name 全局变量名称,如果不填会自动生成一个唯一名称
100
+ */
101
+ _insertBackendVariableAt(name: string, index: number): BackendVariable;
102
+
103
+ /**
104
+ * 插入全局变量
105
+ * @internal
106
+ * @param backendVariableOptions 全局变量参数
107
+ */
108
+ _insertBackendVariableAt(backendVariableOptions: Partial<BackendVariable>, index: number): BackendVariable;
109
+
110
+ /**
111
+ * 插入全局变量
112
+ * @internal
113
+ * @param backendVariable 已有的全局变量实例
114
+ */
115
+ _insertBackendVariableAt(backendVariable: BackendVariable, index: number): BackendVariable;
116
+
117
+ _insertBackendVariableAt(options: string | Partial<BackendVariable> | BackendVariable, index: number) {
118
+ const backendVariableOptions: any = {};
119
+ const relationOptions = { parentNode: this, parentKey: 'variables' };
120
+ let backendVariable: BackendVariable;
121
+ if (!options) {
122
+ backendVariable = BackendVariable.from({
123
+ ...backendVariableOptions,
124
+ name: this.getBackendVariableUniqueName(),
125
+ }, this, 'variables');
126
+ } else if (typeof options === 'string') {
127
+ backendVariable = BackendVariable.from({
128
+ ...backendVariableOptions,
129
+ name: options,
130
+ }, this, 'variables');
131
+ } else if (options instanceof BackendVariable) {
132
+ options.ensureDelete(); // 同一实例不支持多处存在
133
+ backendVariable = options;
134
+ Object.assign(backendVariable, relationOptions);
135
+ } else {
136
+ backendVariable = BackendVariable.from({
137
+ ...backendVariableOptions,
138
+ ...options,
139
+ }, this, 'variables');
140
+ }
141
+ this.variables.splice(index, 0, backendVariable);
142
+ return backendVariable;
143
+ }
144
+
145
+ /**
146
+ * 插入全局变量
147
+ * @param name 全局变量名称,如果不填会自动生成一个唯一名称
148
+ */
149
+ insertBackendVariableAt(name: string, index: number): BackendVariable;
150
+
151
+ /**
152
+ * 插入全局变量
153
+ * @param backendVariableOptions 全局变量参数
154
+ */
155
+ insertBackendVariableAt(backendVariableOptions: Partial<BackendVariable>, index: number): BackendVariable;
156
+
157
+ /**
158
+ * 插入全局变量
159
+ * @param backendVariable 已有的全局变量实例
160
+ */
161
+ insertBackendVariableAt(backendVariable: BackendVariable, index: number): BackendVariable;
162
+
163
+ insertBackendVariableAt(options: string | Partial<BackendVariable> | BackendVariable, index: number) {
164
+ const node = this._insertBackendVariableAt(options as any, index);
165
+ node.create({
166
+ index,
167
+ parentNode: this,
168
+ parentKey: 'variables',
169
+ });
170
+ return node;
171
+ }
172
+
173
+ /**
174
+ * 添加全局变量
175
+ * @internal
176
+ * @param name 全局变量名称,如果不填会自动生成一个唯一名称
177
+ */
178
+ _addBackendVariable(name?: string): BackendVariable;
179
+
180
+ /**
181
+ * 添加全局变量
182
+ * @internal
183
+ * @param backendVariableOptions 全局变量参数
184
+ */
185
+ _addBackendVariable(backendVariableOptions: Partial<BackendVariable>): BackendVariable;
186
+
187
+ /**
188
+ * 添加全局变量
189
+ * @internal
190
+ * @param backendVariable 已有的全局变量实例
191
+ */
192
+ _addBackendVariable(backendVariable: BackendVariable): BackendVariable;
193
+
194
+ _addBackendVariable(options?: string | Partial<BackendVariable> | BackendVariable) {
195
+ const index = this.variables.length;
196
+ return this._insertBackendVariableAt(options as any, index);
197
+ }
198
+
199
+ /**
200
+ * 添加全局变量
201
+ * @internal
202
+ * @param name 全局变量名称,如果不填会自动生成一个唯一名称
203
+ */
204
+ addBackendVariable(name?: string): BackendVariable;
205
+
206
+ /**
207
+ * 添加全局变量
208
+ * @param backendVariableOptions 全局变量参数
209
+ */
210
+ addBackendVariable(backendVariableOptions: Partial<BackendVariable>): BackendVariable;
211
+
212
+ /**
213
+ * 添加全局变量
214
+ * @param backendVariable 已有的全局变量实例
215
+ */
216
+ addBackendVariable(backendVariable: BackendVariable): BackendVariable;
217
+
218
+ addBackendVariable(options?: string | Partial<BackendVariable> | BackendVariable) {
219
+ const node = this._addBackendVariable(options as any);
220
+ const index = this.variables.indexOf(node);
221
+ node.create({
222
+ index,
223
+ parentNode: this,
224
+ parentKey: 'variables',
225
+ });
226
+ return node;
227
+ }
228
+
229
+
230
+
231
+
232
+ /**
233
+ * 删除全局变量
234
+ * @param name 全局变量名称
235
+ */
236
+ removeBackendVariable(name: string): void;
237
+
238
+ /**
239
+ * 删除全局变量
240
+ * @param backendVariable 已有的全局变量实例
241
+ */
242
+ removeBackendVariable(backendVariable: BackendVariable): void;
243
+
244
+ removeBackendVariable(options: string | BackendVariable) {
245
+ let backendVariable: BackendVariable;
246
+ if (typeof options === 'string') {
247
+ backendVariable = (this.variables as BackendVariable[]).find((item) => item.name === options);
248
+ if (!backendVariable) {
249
+ throw new Error('找不到全局变量 ' + options);
250
+ }
251
+ } else {
252
+ backendVariable = options;
253
+ }
254
+ return backendVariable.delete();
255
+ }
256
+
257
+ __removeBackendVariable(backendVariable: BackendVariable) {
258
+ const parentKey = backendVariable.parentKey;
259
+ const params: Params = {
260
+ parentNode: this,
261
+ parentKey,
262
+ index: -1,
263
+ object: null,
264
+ oldObject: backendVariable,
265
+ };
266
+ if (parentKey) {
267
+ params.parentKey = parentKey;
268
+ if (Array.isArray((this as any)[parentKey])) {
269
+ const index = (this as any)[parentKey].indexOf(backendVariable);
270
+ ~index && (this as any)[parentKey].splice(index, 1);
271
+ params.index = index;
272
+ } else if ((this as any)[parentKey] === backendVariable) {
273
+ params.index = 0;
274
+ (this as any)[parentKey] = undefined;
275
+ }
276
+ }
277
+ return params;
278
+ }
279
+
280
+ //================================================================================
281
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
282
+ // 自动生成的代码已结束。下面可以手动编写。
283
+ //================================================================================
284
+ getNamespace() {
285
+ if (this.parentNode && (this.parentNode as Namespace).getNamespace) {
286
+ const parentNamespace = (this.parentNode as Namespace).getNamespace();
287
+ const parentName = this.parentNode.name;
288
+ const arr = [parentNamespace];
289
+ if (this.parentNode.concept !== 'App' && parentName) {
290
+ arr.push(parentName);
291
+ }
292
+ return `${arr.join('.')}.backend`;
293
+ } else
294
+ throw new Error('无法获取命名空间,请设置 parentNode!');
295
+ }
296
+ /**
297
+ * 生成宿主语言的文件路径
298
+ * @param name 一般不用传,用于 rename
299
+ */
300
+ getEmbeddedFilePath(name = this.name) {
301
+ return `/embedded/${this.rootNode?.name || this.parentNode.name}/Backend/backend.ts`;
302
+ }
303
+
304
+ @withSourceMap()
305
+ toEmbeddedTS(state?: TranslatorState): string {
306
+ let code = `export namespace ${this.name} {\n`;
307
+ code += 'const name = ';
308
+ code += '"' + this.name + '";\n';
309
+ code += '}\n';
310
+ return code;
311
+ }
312
+
313
+ // getPath() {
314
+ // const path = this.path;
315
+ // const finalPath = path && path !== '/' ? path : '';
316
+ // return finalPath;
317
+ // }
318
+ toEmbeddedTSFile() {
319
+ let code = `namespace ${this.getNamespace()} {\n`;
320
+
321
+ const state = createCompilerState(code, { tabSize: 1 });
322
+ try {
323
+ code += this.toEmbeddedTS(state);
324
+ } catch (err) {
325
+ code += '';
326
+ console.log(err);
327
+ }
328
+ code += '}\n';
329
+
330
+ return {
331
+ code,
332
+ filePath: this.getEmbeddedFilePath(),
333
+ sourceMap: state.sourceMap,
334
+ };
335
+ }
336
+ //================================================================================
337
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
338
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
339
+ //================================================================================
340
+ }
341
+
342
+ classMap.Backend = Backend;
343
+ export default Backend;
344
+ //================================================================================
345
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
346
+ // 自动生成的代码已结束。下面可以手动编写。
347
+ //================================================================================
@@ -684,7 +684,7 @@ export class BindAttribute extends BaseNode {
684
684
  this.emit('change', $event);
685
685
  }
686
686
 
687
- updateSource(source?: Partial<BaseNode>) {
687
+ updateSource(source?: Partial<BindAttribute>) {
688
688
  const object = {
689
689
  ...source,
690
690
  };
@@ -946,8 +946,9 @@ export class BindAttribute extends BaseNode {
946
946
  // fix-bug: http://projectmanage.netease-official.lcap.163yun.com/dashboard/BugDetail?id=2613580902909440
947
947
  if (
948
948
  (
949
- this.name === 'destination' || (this.name === 'href' && value.startsWith('/'))
950
- ) && this.frontend?.prefixPath && value
949
+ // fix: 2647986781937408 导航栏项中配置链接,取消动态绑定,直接配置为外部链接,无法跳转,且导航栏项消失
950
+ (this.name === 'destination' || this.name === 'href') && value && value.startsWith('/')
951
+ ) && this.frontend?.prefixPath
951
952
  ) {
952
953
  value = `${this.frontend?.prefixPath}${value}`;
953
954
  } else if (
@@ -1,7 +1,7 @@
1
1
  import * as babel from '@babel/core';
2
2
  import LogicItem from './LogicItem__';
3
3
  import Namespace from './Namespace__';
4
- import { TranslatorState, shiftState, withSourceMap, indent } from '../translator';
4
+ import { TranslatorState, shiftState, withSourceMap, indent, createCompilerState } from '../translator';
5
5
  import { ElementToVueOptions } from './ViewElement__';
6
6
  import { elementsEventsMap } from '../server/createUiTs';
7
7
  import Param from './Param__';
@@ -862,13 +862,82 @@ export class BindEvent extends BaseNode {
862
862
  // 名称规则:组件的名称 + 组件的事件 + 逻辑本身的事件 用下划线链接
863
863
  const parentNode = this.parentNode;
864
864
  const newName = this.name.replace(/-/g, '');
865
-
866
865
  if (parentNode instanceof ViewElement) {
867
866
  return `${parentNode.name}_${newName}`;
868
867
  } else if (parentNode instanceof View) {
869
868
  return `${this.view.name}_${newName}`;
869
+ } else {
870
+ // 这里编译成这个名字了 后续pctemplate 里也得按这个调用?
871
+ // 或者说因为会编译在不同的端里 直接 name好了
872
+ // return `${this.parentNode.name}_${newName}`;
873
+ return newName;
874
+ }
875
+ }
876
+ toFunction(state?: TranslatorState): string {
877
+ // shiftState(state, code)
878
+ // 和 toJS一样的 只是下一行增加了 function 关键字
879
+ // let code = `async function ${this.getViewEventName()} (`;
880
+ let code = `window.${this.getViewEventName()} = async (`;
881
+ const params = this.getContextLogicParams();
882
+ code += params.map((item: Param) => item.name).toString();
883
+ // code += ') { \n';
884
+ code += ') => { \n';
885
+ this.logics.forEach((logic) => {
886
+ code += logic.toJS(shiftState(state, code), 'IIFE');
887
+ });
888
+ code += '}\n';
889
+ return code;
890
+ }
891
+ getTsNamespace() {
892
+ if (this.parentNode && (this.parentNode as Namespace).getNamespace) {
893
+ const parentNamespace = (this.parentNode as Namespace).getNamespace();
894
+ const parentName = this.parentNode.name;
895
+ const arr = [parentNamespace];
896
+
897
+ if (this.parentNode.concept !== 'App' && parentName) {
898
+ arr.push(parentName);
899
+ }
900
+ return `${arr.join('.')}.bindEvents`;
901
+ } else
902
+ throw new Error('无法获取命名空间,请设置 parentNode!');
903
+ }
904
+ toEmbeddedTSFile() {
905
+ let code = `namespace ${this.getTsNamespace()} {\n`;
906
+ const state = createCompilerState(code, {
907
+ tabSize: 1,
908
+ });
909
+
910
+ try {
911
+ code += this.toEmbeddedTS(state);
912
+ } catch (err) {
913
+ code += '';
914
+ console.log(err);
915
+ }
916
+
917
+ code += '}\n';
918
+
919
+ return {
920
+ code,
921
+ filePath: this.getEmbeddedFilePath(),
922
+ sourceMap: state.sourceMap,
923
+ };
924
+ }
925
+ /**
926
+ * 生成宿主语言的文件路径
927
+ * @param name 一般不用传,用于 rename
928
+ */
929
+ getEmbeddedFilePath(name = this.name) {
930
+ let pathName = name;
931
+ let parent = this.parentNode;
932
+ if (parent) {
933
+ while (parent && parent instanceof View) {
934
+ pathName = parent.name + '/' + pathName;
935
+ parent = parent.parentNode;
936
+ }
870
937
  }
938
+ return `/embedded/${this.app.name}/frontends/${this.frontend.name}/bindEvents/${pathName}.ts`;
871
939
  }
940
+
872
941
  //================================================================================
873
942
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
874
943
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓