@lcap/nasl 2.18.0 → 2.19.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 (283) hide show
  1. package/out/automate/template/myProcess.js +1 -1
  2. package/out/automate/template/myProcess.js.map +1 -1
  3. package/out/bak/translator.js +2 -1
  4. package/out/bak/translator.js.map +1 -1
  5. package/out/common/BaseNode.js +1 -0
  6. package/out/common/BaseNode.js.map +1 -1
  7. package/out/common/Command.d.ts +1 -0
  8. package/out/common/Command.js +5 -1
  9. package/out/common/Command.js.map +1 -1
  10. package/out/concepts/AnonymousFunction__.d.ts +1 -0
  11. package/out/concepts/AnonymousFunction__.js +40 -2
  12. package/out/concepts/AnonymousFunction__.js.map +1 -1
  13. package/out/concepts/App__.d.ts +10 -0
  14. package/out/concepts/App__.js +132 -0
  15. package/out/concepts/App__.js.map +1 -1
  16. package/out/concepts/Assignee__.js +4 -3
  17. package/out/concepts/Assignee__.js.map +1 -1
  18. package/out/concepts/BatchAssignment__.d.ts +2 -0
  19. package/out/concepts/BatchAssignment__.js +108 -47
  20. package/out/concepts/BatchAssignment__.js.map +1 -1
  21. package/out/concepts/BindAttribute__.js +8 -1
  22. package/out/concepts/BindAttribute__.js.map +1 -1
  23. package/out/concepts/CallFunction__.js +51 -18
  24. package/out/concepts/CallFunction__.js.map +1 -1
  25. package/out/concepts/CallInterface__.js +6 -4
  26. package/out/concepts/CallInterface__.js.map +1 -1
  27. package/out/concepts/CallLogic__.d.ts +2 -1
  28. package/out/concepts/CallLogic__.js +113 -26
  29. package/out/concepts/CallLogic__.js.map +1 -1
  30. package/out/concepts/CallQueryComponent__.js +4 -1
  31. package/out/concepts/CallQueryComponent__.js.map +1 -1
  32. package/out/concepts/DataSource__.d.ts +2 -0
  33. package/out/concepts/DataSource__.js +55 -1
  34. package/out/concepts/DataSource__.js.map +1 -1
  35. package/out/concepts/Destination__.d.ts +2 -1
  36. package/out/concepts/Destination__.js +90 -22
  37. package/out/concepts/Destination__.js.map +1 -1
  38. package/out/concepts/ForEachStatement__.js +2 -0
  39. package/out/concepts/ForEachStatement__.js.map +1 -1
  40. package/out/concepts/Identifier__.d.ts +1 -0
  41. package/out/concepts/Identifier__.js +18 -7
  42. package/out/concepts/Identifier__.js.map +1 -1
  43. package/out/concepts/LogicItem__.d.ts +1 -1
  44. package/out/concepts/LogicItem__.js.map +1 -1
  45. package/out/concepts/Logic__.d.ts +1 -0
  46. package/out/concepts/Logic__.js +33 -21
  47. package/out/concepts/Logic__.js.map +1 -1
  48. package/out/concepts/Match__.js +13 -8
  49. package/out/concepts/Match__.js.map +1 -1
  50. package/out/concepts/NewComposite__.d.ts +345 -0
  51. package/out/concepts/NewComposite__.js +1067 -0
  52. package/out/concepts/NewComposite__.js.map +1 -0
  53. package/out/concepts/NewList__.d.ts +130 -0
  54. package/out/concepts/NewList__.js +353 -0
  55. package/out/concepts/NewList__.js.map +1 -0
  56. package/out/concepts/NewMap__.d.ts +221 -0
  57. package/out/concepts/NewMap__.js +492 -0
  58. package/out/concepts/NewMap__.js.map +1 -0
  59. package/out/concepts/New__.d.ts +19 -0
  60. package/out/concepts/New__.js +66 -0
  61. package/out/concepts/New__.js.map +1 -0
  62. package/out/concepts/Param__.d.ts +2 -0
  63. package/out/concepts/Param__.js +40 -3
  64. package/out/concepts/Param__.js.map +1 -1
  65. package/out/concepts/ProcessElement__.js +31 -10
  66. package/out/concepts/ProcessElement__.js.map +1 -1
  67. package/out/concepts/ProcessOutcome__.js +1 -1
  68. package/out/concepts/ProcessOutcome__.js.map +1 -1
  69. package/out/concepts/ProcessOutcomes__.d.ts +30 -0
  70. package/out/concepts/{ConstructArgument__.js → ProcessOutcomes__.js} +27 -48
  71. package/out/concepts/ProcessOutcomes__.js.map +1 -0
  72. package/out/concepts/Return__.js +2 -1
  73. package/out/concepts/Return__.js.map +1 -1
  74. package/out/concepts/SelectMembers__.js +3 -3
  75. package/out/concepts/SelectMembers__.js.map +1 -1
  76. package/out/concepts/StringInterpolation__.js +12 -2
  77. package/out/concepts/StringInterpolation__.js.map +1 -1
  78. package/out/concepts/TypeAnnotation__.d.ts +4 -0
  79. package/out/concepts/TypeAnnotation__.js +66 -12
  80. package/out/concepts/TypeAnnotation__.js.map +1 -1
  81. package/out/concepts/ValidationRule__.js +1 -1
  82. package/out/concepts/ValidationRule__.js.map +1 -1
  83. package/out/concepts/Variable__.js +2 -1
  84. package/out/concepts/Variable__.js.map +1 -1
  85. package/out/concepts/ViewElement__.js +13 -1
  86. package/out/concepts/ViewElement__.js.map +1 -1
  87. package/out/concepts/View__.d.ts +1 -0
  88. package/out/concepts/View__.js +13 -0
  89. package/out/concepts/View__.js.map +1 -1
  90. package/out/concepts/basics/stdlib/nasl.auth.js +1 -1
  91. package/out/concepts/basics/stdlib/nasl.auth.js.map +1 -1
  92. package/out/concepts/basics/stdlib/nasl.logging.js +5 -0
  93. package/out/concepts/basics/stdlib/nasl.logging.js.map +1 -1
  94. package/out/concepts/basics/stdlib/nasl.ui.js +2 -0
  95. package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
  96. package/out/concepts/basics/stdlib/nasl.util.js +151 -19
  97. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  98. package/out/concepts/index__.d.ts +5 -0
  99. package/out/concepts/index__.js +5 -0
  100. package/out/concepts/index__.js.map +1 -1
  101. package/out/enums/KEYWORDS.js +1 -0
  102. package/out/enums/KEYWORDS.js.map +1 -1
  103. package/out/generator/genBundleFiles.js +32 -182
  104. package/out/generator/genBundleFiles.js.map +1 -1
  105. package/out/generator/genMetaData.d.ts +1 -10
  106. package/out/generator/genMetaData.js +184 -50
  107. package/out/generator/genMetaData.js.map +1 -1
  108. package/out/generator/genReleaseBody.d.ts +2 -0
  109. package/out/generator/genReleaseBody.js +29 -3
  110. package/out/generator/genReleaseBody.js.map +1 -1
  111. package/out/generator/index.d.ts +1 -0
  112. package/out/generator/index.js +1 -0
  113. package/out/generator/index.js.map +1 -1
  114. package/out/generator/permission.d.ts +9 -0
  115. package/out/generator/permission.js +235 -0
  116. package/out/generator/permission.js.map +1 -0
  117. package/out/index.d.ts +1 -1
  118. package/out/index.js +2 -1
  119. package/out/index.js.map +1 -1
  120. package/out/server/entity2LogicNamespace.js +69 -9
  121. package/out/server/entity2LogicNamespace.js.map +1 -1
  122. package/out/server/extendBaseNode.js +10 -20
  123. package/out/server/extendBaseNode.js.map +1 -1
  124. package/out/server/formatTsUtils.d.ts +1 -2
  125. package/out/server/formatTsUtils.js +36 -47
  126. package/out/server/formatTsUtils.js.map +1 -1
  127. package/out/server/getLogics.d.ts +2 -1
  128. package/out/server/getLogics.js +11 -0
  129. package/out/server/getLogics.js.map +1 -1
  130. package/out/server/getMemberIdentifier.js +1 -1
  131. package/out/server/getMemberIdentifier.js.map +1 -1
  132. package/out/server/getProcesses.js +1 -1
  133. package/out/server/getProcesses.js.map +1 -1
  134. package/out/server/naslServer.d.ts +1 -1
  135. package/out/server/naslServer.js +181 -35
  136. package/out/server/naslServer.js.map +1 -1
  137. package/out/server/process2LogicNamespace.js +8 -0
  138. package/out/server/process2LogicNamespace.js.map +1 -1
  139. package/out/server/translator.js +66 -6
  140. package/out/server/translator.js.map +1 -1
  141. package/out/service/creator/add.configs.js +4 -0
  142. package/out/service/creator/add.configs.js.map +1 -1
  143. package/out/service/datasource/api.d.ts +12 -0
  144. package/out/service/datasource/api.js +14 -0
  145. package/out/service/datasource/api.js.map +1 -0
  146. package/out/service/datasource/index.d.ts +2 -0
  147. package/out/service/datasource/index.js +10 -0
  148. package/out/service/datasource/index.js.map +1 -0
  149. package/out/service/storage/init.js +8 -1
  150. package/out/service/storage/init.js.map +1 -1
  151. package/out/templator/genEditTableBlock.js +4 -5
  152. package/out/templator/genEditTableBlock.js.map +1 -1
  153. package/out/templator/genGetBlock.js +4 -3
  154. package/out/templator/genGetBlock.js.map +1 -1
  155. package/out/templator/genGridViewBlock.js +16 -14
  156. package/out/templator/genGridViewBlock.js.map +1 -1
  157. package/out/templator/genListViewBlock.js +5 -5
  158. package/out/templator/genListViewBlock.js.map +1 -1
  159. package/out/templator/genTableBlock.js +6 -10
  160. package/out/templator/genTableBlock.js.map +1 -1
  161. package/package.json +1 -1
  162. package/sandbox/stdlib/dist/nasl.logging.js +0 -0
  163. package/sandbox/stdlib/dist/nasl.util.js +0 -0
  164. package/sandbox/stdlib/nasl.auth.ts +1 -1
  165. package/sandbox/stdlib/nasl.core.ts +4 -0
  166. package/sandbox/stdlib/nasl.logging.ts +4 -4
  167. package/sandbox/stdlib/nasl.util.ts +14 -5
  168. package/src/automate/template/myProcess.js +1 -1
  169. package/src/bak/translator.js +4 -1
  170. package/src/common/BaseNode.ts +1 -0
  171. package/src/common/Command.ts +4 -0
  172. package/src/concepts/AnonymousFunction__.ts +48 -2
  173. package/src/concepts/App__.ts +140 -41
  174. package/src/concepts/Assignee__.ts +4 -3
  175. package/src/concepts/BatchAssignment__.ts +111 -51
  176. package/src/concepts/BindAttribute__.ts +9 -2
  177. package/src/concepts/CallFunction__.ts +65 -31
  178. package/src/concepts/CallInterface__.ts +6 -22
  179. package/src/concepts/CallLogic__.ts +88 -24
  180. package/src/concepts/CallQueryComponent__.ts +4 -1
  181. package/src/concepts/DataSource__.ts +56 -1
  182. package/src/concepts/Destination__.ts +92 -22
  183. package/src/concepts/ForEachStatement__.ts +2 -0
  184. package/src/concepts/Identifier__.ts +18 -7
  185. package/src/concepts/LogicItem__.ts +1 -1
  186. package/src/concepts/Logic__.ts +54 -39
  187. package/src/concepts/Match__.ts +12 -8
  188. package/src/concepts/NewComposite__.ts +1356 -0
  189. package/src/concepts/NewList__.ts +444 -0
  190. package/src/concepts/NewMap__.ts +678 -0
  191. package/src/concepts/New__.ts +73 -0
  192. package/src/concepts/Param__.ts +238 -199
  193. package/src/concepts/ProcessElement__.ts +32 -10
  194. package/src/concepts/ProcessOutcome__.ts +1 -1
  195. package/src/concepts/ProcessOutcomes__.ts +90 -0
  196. package/src/concepts/Return__.ts +4 -1
  197. package/src/concepts/SelectMembers__.ts +3 -3
  198. package/src/concepts/StringInterpolation__.ts +21 -11
  199. package/src/concepts/TypeAnnotation__.ts +71 -50
  200. package/src/concepts/ValidationRule__.ts +19 -1
  201. package/src/concepts/Variable__.ts +4 -1
  202. package/src/concepts/ViewElement__.ts +23 -7
  203. package/src/concepts/View__.ts +16 -2
  204. package/src/concepts/basics/stdlib/dist/nasl.util.js +1602 -0
  205. package/src/concepts/basics/stdlib/nasl.auth.ts +1 -1
  206. package/src/concepts/basics/stdlib/nasl.logging.ts +5 -0
  207. package/src/concepts/basics/stdlib/nasl.ui.ts +2 -0
  208. package/src/concepts/basics/stdlib/nasl.util.ts +153 -19
  209. package/src/concepts/dist/BindAttribute__.js +760 -0
  210. package/src/concepts/dist/BindEvent__.js +732 -0
  211. package/src/concepts/dist/CallFunction__.js +82 -28
  212. package/src/concepts/dist/CallLogic__.js +95 -27
  213. package/src/concepts/dist/Identifier__.js +311 -0
  214. package/src/concepts/dist/StringInterpolation__.js +231 -0
  215. package/src/concepts/dist/TypeAnnotation__.js +834 -0
  216. package/src/concepts/dist/ViewElement__.js +1692 -0
  217. package/src/concepts/dist/View__.js +1601 -0
  218. package/src/concepts/index__.ts +5 -0
  219. package/src/enums/KEYWORDS.ts +1 -0
  220. package/src/generator/dist/genBundleFiles.js +23 -176
  221. package/src/generator/dist/genMetaData.js +245 -0
  222. package/src/generator/dist/permission.js +392 -0
  223. package/src/generator/genBundleFiles.ts +34 -219
  224. package/src/generator/genMetaData.ts +177 -77
  225. package/src/generator/genReleaseBody.ts +30 -5
  226. package/src/generator/index.ts +1 -0
  227. package/src/generator/permission.ts +271 -0
  228. package/src/index.ts +1 -1
  229. package/src/server/dist/naslServer.js +443 -249
  230. package/src/server/entity2LogicNamespace.ts +70 -10
  231. package/src/server/extendBaseNode.ts +10 -21
  232. package/src/server/formatTsUtils.ts +36 -46
  233. package/src/server/getLogics.ts +13 -1
  234. package/src/server/getMemberIdentifier.ts +1 -1
  235. package/src/server/getProcesses.ts +1 -1
  236. package/src/server/naslServer.ts +181 -42
  237. package/src/server/process2LogicNamespace.ts +8 -0
  238. package/src/server/translator.ts +64 -7
  239. package/src/service/creator/add.configs.js +4 -0
  240. package/src/service/dataSource/api.js +11 -0
  241. package/src/service/dataSource/index.js +6 -0
  242. package/src/service/storage/dist/init.js +48 -10
  243. package/src/service/storage/init.ts +9 -2
  244. package/src/service/video/VideoTranscribe.js +1 -0
  245. package/src/templator/dist/genEditTableBlock.js +204 -0
  246. package/src/templator/dist/genGridViewBlock.js +265 -0
  247. package/src/templator/dist/genListViewBlock.js +84 -0
  248. package/src/templator/dist/genTableBlock.js +209 -0
  249. package/src/templator/dist/utils.js +527 -0
  250. package/src/templator/genEditTableBlock.ts +8 -16
  251. package/src/templator/genGetBlock.ts +18 -19
  252. package/src/templator/genGridViewBlock.ts +18 -18
  253. package/src/templator/genListViewBlock.ts +8 -11
  254. package/src/templator/genTableBlock.ts +6 -10
  255. package/ts-worker/dist/webpack.config.dev.js +3 -1
  256. package/ts-worker/lib/tsserver.js +8 -1
  257. package/out/automate/engine/2.14-components.d.ts +0 -1115
  258. package/out/automate/engine/2.14-components.js +0 -1087
  259. package/out/automate/engine/2.14-components.js.map +0 -1
  260. package/out/concepts/ConstructArgument__.d.ts +0 -40
  261. package/out/concepts/ConstructArgument__.js.map +0 -1
  262. package/out/concepts/Construct__.d.ts +0 -189
  263. package/out/concepts/Construct__.js +0 -340
  264. package/out/concepts/Construct__.js.map +0 -1
  265. package/out/concepts/MatchExpression__.d.ts +0 -97
  266. package/out/concepts/MatchExpression__.js +0 -281
  267. package/out/concepts/MatchExpression__.js.map +0 -1
  268. package/out/templator/sql-parser/index.d.ts +0 -1
  269. package/out/templator/sql-parser/index.js +0 -228
  270. package/out/templator/sql-parser/index.js.map +0 -1
  271. package/out/templator/sql-parser/parser.js +0 -26664
  272. package/out/templator/sql-parser/parser.js.map +0 -1
  273. package/src/concepts/dist/Anchor__.js +0 -179
  274. package/src/concepts/dist/Assignment__.js +0 -301
  275. package/src/concepts/dist/CallInterface__.js +0 -533
  276. package/src/concepts/dist/ForEachStatement__.js +0 -426
  277. package/src/concepts/dist/MatchCase__.js +0 -587
  278. package/src/concepts/dist/MemberExpression__.js +0 -348
  279. package/src/concepts/dist/Param__.js +0 -537
  280. package/src/concepts/dist/Return__.js +0 -493
  281. package/src/server/dist/formatTsUtils.js +0 -683
  282. package/ts-worker/lib/dist/tsserver.dev.js +0 -22953
  283. package/ts-worker/sources/lib/dist/tsserver.dev.js +0 -22912
@@ -0,0 +1,1067 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __importDefault = (this && this.__importDefault) || function (mod) {
32
+ return (mod && mod.__esModule) ? mod : { "default": mod };
33
+ };
34
+ var NewComposite_1;
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.NewComposite = void 0;
37
+ const translator_1 = require("../translator");
38
+ const StructureProperty__1 = __importDefault(require("./StructureProperty__"));
39
+ const decorators_1 = require("../decorators");
40
+ const utils = __importStar(require("../utils"));
41
+ const classMap_1 = __importDefault(require("../common/classMap"));
42
+ const TypeAnnotation__1 = __importDefault(require("./TypeAnnotation__"));
43
+ const Identifier__1 = __importDefault(require("./Identifier__"));
44
+ const SelectMembers__1 = __importDefault(require("./SelectMembers__"));
45
+ const AssignmentLine__1 = __importDefault(require("./AssignmentLine__"));
46
+ const LogicItem__1 = __importDefault(require("./LogicItem__"));
47
+ /**
48
+ * 实体/(匿名)数据结构构造器
49
+ */
50
+ let NewComposite = NewComposite_1 = class NewComposite extends LogicItem__1.default {
51
+ /**
52
+ * 产品概念
53
+ */
54
+ concept = 'NewComposite';
55
+ /**
56
+ * 类型
57
+ */
58
+ typeAnnotation = undefined;
59
+ /**
60
+ * 左边项
61
+ */
62
+ properties = [];
63
+ /**
64
+ * 右边项
65
+ */
66
+ rights = [];
67
+ /**
68
+ * 赋值线
69
+ */
70
+ assignmentLines = [];
71
+ /**
72
+ * hideProperties
73
+ */
74
+ hideProperties = false;
75
+ /**
76
+ * hideDefaults
77
+ */
78
+ hideDefaults = false;
79
+ /**
80
+ * 自动连线
81
+ */
82
+ autoConnection = true;
83
+ /**
84
+ * @param source 需要合并的部分参数
85
+ */
86
+ constructor(source) {
87
+ source = Object.assign({}, NewComposite_1.getDefaultOptions(), source);
88
+ super(source);
89
+ super.subConstructor(source);
90
+ }
91
+ static from(source, parentNode, parentKey) {
92
+ return super.from(source, parentNode, parentKey);
93
+ }
94
+ /**
95
+ * 设置类型
96
+ */
97
+ setTypeAnnotation(typeAnnotation) {
98
+ typeAnnotation._delete();
99
+ const relationOptions = { parentNode: this, parentKey: 'typeAnnotation' };
100
+ Object.assign(typeAnnotation, relationOptions);
101
+ const object = {
102
+ typeAnnotation,
103
+ };
104
+ this.update({
105
+ ...object,
106
+ });
107
+ }
108
+ /**
109
+ * 设置左边项
110
+ */
111
+ setProperties(properties) {
112
+ const object = {
113
+ properties,
114
+ };
115
+ this.update({
116
+ ...object,
117
+ });
118
+ }
119
+ /**
120
+ * 设置右边项
121
+ */
122
+ setRights(rights) {
123
+ const object = {
124
+ rights,
125
+ };
126
+ this.update({
127
+ ...object,
128
+ });
129
+ }
130
+ /**
131
+ * 设置赋值线
132
+ */
133
+ setAssignmentLines(assignmentLines) {
134
+ const object = {
135
+ assignmentLines,
136
+ };
137
+ this.update({
138
+ ...object,
139
+ });
140
+ }
141
+ /**
142
+ * 设置hideProperties
143
+ */
144
+ setHideProperties(hideProperties) {
145
+ const object = {
146
+ hideProperties,
147
+ };
148
+ this.update({
149
+ ...object,
150
+ });
151
+ }
152
+ /**
153
+ * 设置hideDefaults
154
+ */
155
+ setHideDefaults(hideDefaults) {
156
+ const object = {
157
+ hideDefaults,
158
+ };
159
+ this.update({
160
+ ...object,
161
+ });
162
+ }
163
+ /**
164
+ * 设置自动连线
165
+ */
166
+ setAutoConnection(autoConnection) {
167
+ const object = {
168
+ autoConnection,
169
+ };
170
+ this.update({
171
+ ...object,
172
+ });
173
+ }
174
+ getIdentifierExistingNames(excludedList = []) {
175
+ const excludedSet = new Set(excludedList);
176
+ return (this.properties || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
177
+ }
178
+ getIdentifierUniqueName(name = 'identifier1') {
179
+ return utils.unique(name, this.getIdentifierExistingNames(), undefined, false);
180
+ }
181
+ _insertIdentifierAt(options, index) {
182
+ const identifierOptions = {};
183
+ const relationOptions = { parentNode: this, parentKey: 'properties' };
184
+ let identifier;
185
+ if (!options) {
186
+ identifier = Identifier__1.default.from({
187
+ ...identifierOptions,
188
+ name: this.getIdentifierUniqueName(),
189
+ }, this, 'properties');
190
+ }
191
+ else if (typeof options === 'string') {
192
+ identifier = Identifier__1.default.from({
193
+ ...identifierOptions,
194
+ name: options,
195
+ }, this, 'properties');
196
+ }
197
+ else if (options instanceof Identifier__1.default) {
198
+ options.ensureDelete(); // 同一实例不支持多处存在
199
+ identifier = options;
200
+ Object.assign(identifier, relationOptions);
201
+ }
202
+ else {
203
+ identifier = Identifier__1.default.from({
204
+ ...identifierOptions,
205
+ ...options,
206
+ }, this, 'properties');
207
+ }
208
+ this.properties.splice(index, 0, identifier);
209
+ return identifier;
210
+ }
211
+ insertIdentifierAt(options, index) {
212
+ const node = this._insertIdentifierAt(options, index);
213
+ node.create({
214
+ index,
215
+ parentNode: this,
216
+ parentKey: 'properties',
217
+ });
218
+ return node;
219
+ }
220
+ _addIdentifier(options) {
221
+ const index = this.properties.length;
222
+ return this._insertIdentifierAt(options, index);
223
+ }
224
+ addIdentifier(options) {
225
+ const node = this._addIdentifier(options);
226
+ const index = this.properties.indexOf(node);
227
+ node.create({
228
+ index,
229
+ parentNode: this,
230
+ parentKey: 'properties',
231
+ });
232
+ return node;
233
+ }
234
+ getSelectMembersExistingNames(excludedList = []) {
235
+ const excludedSet = new Set(excludedList);
236
+ return (this.rights || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
237
+ }
238
+ getSelectMembersUniqueName(name = 'selectMembers1') {
239
+ return utils.unique(name, this.getSelectMembersExistingNames(), undefined, false);
240
+ }
241
+ _insertSelectMembersAt(options, index) {
242
+ const selectMembersOptions = {};
243
+ const relationOptions = { parentNode: this, parentKey: 'rights' };
244
+ let selectMembers;
245
+ if (!options) {
246
+ selectMembers = SelectMembers__1.default.from({
247
+ ...selectMembersOptions,
248
+ name: this.getSelectMembersUniqueName(),
249
+ }, this, 'rights');
250
+ }
251
+ else if (typeof options === 'string') {
252
+ selectMembers = SelectMembers__1.default.from({
253
+ ...selectMembersOptions,
254
+ name: options,
255
+ }, this, 'rights');
256
+ }
257
+ else if (options instanceof SelectMembers__1.default) {
258
+ options.ensureDelete(); // 同一实例不支持多处存在
259
+ selectMembers = options;
260
+ Object.assign(selectMembers, relationOptions);
261
+ }
262
+ else {
263
+ selectMembers = SelectMembers__1.default.from({
264
+ ...selectMembersOptions,
265
+ ...options,
266
+ }, this, 'rights');
267
+ }
268
+ this.rights.splice(index, 0, selectMembers);
269
+ return selectMembers;
270
+ }
271
+ insertSelectMembersAt(options, index) {
272
+ const node = this._insertSelectMembersAt(options, index);
273
+ node.create({
274
+ index,
275
+ parentNode: this,
276
+ parentKey: 'rights',
277
+ });
278
+ return node;
279
+ }
280
+ _addSelectMembers(options) {
281
+ const index = this.rights.length;
282
+ return this._insertSelectMembersAt(options, index);
283
+ }
284
+ addSelectMembers(options) {
285
+ const node = this._addSelectMembers(options);
286
+ const index = this.rights.indexOf(node);
287
+ node.create({
288
+ index,
289
+ parentNode: this,
290
+ parentKey: 'rights',
291
+ });
292
+ return node;
293
+ }
294
+ getAssignmentLineExistingNames(excludedList = []) {
295
+ const excludedSet = new Set(excludedList);
296
+ return (this.assignmentLines || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
297
+ }
298
+ getAssignmentLineUniqueName(name = 'assignmentLine1') {
299
+ return utils.unique(name, this.getAssignmentLineExistingNames(), undefined, false);
300
+ }
301
+ _insertAssignmentLineAt(options, index) {
302
+ const assignmentLineOptions = {};
303
+ const relationOptions = { parentNode: this, parentKey: 'assignmentLines' };
304
+ let assignmentLine;
305
+ if (!options) {
306
+ assignmentLine = AssignmentLine__1.default.from({
307
+ ...assignmentLineOptions,
308
+ name: this.getAssignmentLineUniqueName(),
309
+ }, this, 'assignmentLines');
310
+ }
311
+ else if (typeof options === 'string') {
312
+ assignmentLine = AssignmentLine__1.default.from({
313
+ ...assignmentLineOptions,
314
+ name: options,
315
+ }, this, 'assignmentLines');
316
+ }
317
+ else if (options instanceof AssignmentLine__1.default) {
318
+ options.ensureDelete(); // 同一实例不支持多处存在
319
+ assignmentLine = options;
320
+ Object.assign(assignmentLine, relationOptions);
321
+ }
322
+ else {
323
+ assignmentLine = AssignmentLine__1.default.from({
324
+ ...assignmentLineOptions,
325
+ ...options,
326
+ }, this, 'assignmentLines');
327
+ }
328
+ this.assignmentLines.splice(index, 0, assignmentLine);
329
+ return assignmentLine;
330
+ }
331
+ insertAssignmentLineAt(options, index) {
332
+ const node = this._insertAssignmentLineAt(options, index);
333
+ node.create({
334
+ index,
335
+ parentNode: this,
336
+ parentKey: 'assignmentLines',
337
+ });
338
+ return node;
339
+ }
340
+ _addAssignmentLine(options) {
341
+ const index = this.assignmentLines.length;
342
+ return this._insertAssignmentLineAt(options, index);
343
+ }
344
+ addAssignmentLine(options) {
345
+ const node = this._addAssignmentLine(options);
346
+ const index = this.assignmentLines.indexOf(node);
347
+ node.create({
348
+ index,
349
+ parentNode: this,
350
+ parentKey: 'assignmentLines',
351
+ });
352
+ return node;
353
+ }
354
+ removeTypeAnnotation(options) {
355
+ let typeAnnotation;
356
+ if (typeof options === 'string') {
357
+ typeAnnotation = this.typeAnnotation;
358
+ if (!typeAnnotation) {
359
+ throw new Error('找不到类型标注 ' + options);
360
+ }
361
+ }
362
+ else {
363
+ typeAnnotation = options;
364
+ }
365
+ return typeAnnotation.delete();
366
+ }
367
+ __removeTypeAnnotation(typeAnnotation) {
368
+ const parentKey = typeAnnotation.parentKey;
369
+ const params = {
370
+ parentNode: this,
371
+ parentKey,
372
+ index: -1,
373
+ object: null,
374
+ oldObject: typeAnnotation,
375
+ };
376
+ if (parentKey) {
377
+ params.parentKey = parentKey;
378
+ if (Array.isArray(this[parentKey])) {
379
+ const index = this[parentKey].indexOf(typeAnnotation);
380
+ ~index && this[parentKey].splice(index, 1);
381
+ params.index = index;
382
+ }
383
+ else if (this[parentKey] === typeAnnotation) {
384
+ params.index = 0;
385
+ this[parentKey] = undefined;
386
+ }
387
+ }
388
+ return params;
389
+ }
390
+ removeIdentifier(options) {
391
+ let identifier;
392
+ if (typeof options === 'string') {
393
+ identifier = this.properties.find((item) => item.name === options);
394
+ if (!identifier) {
395
+ throw new Error('找不到标识符 ' + options);
396
+ }
397
+ }
398
+ else {
399
+ identifier = options;
400
+ }
401
+ return identifier.delete();
402
+ }
403
+ __removeLogicItem(logicItem) {
404
+ const parentKey = logicItem.parentKey;
405
+ const params = {
406
+ parentNode: this,
407
+ parentKey,
408
+ index: -1,
409
+ object: null,
410
+ oldObject: logicItem,
411
+ };
412
+ if (parentKey) {
413
+ params.parentKey = parentKey;
414
+ if (Array.isArray(this[parentKey])) {
415
+ const index = this[parentKey].indexOf(logicItem);
416
+ ~index && this[parentKey].splice(index, 1);
417
+ params.index = index;
418
+ }
419
+ else if (this[parentKey] === logicItem) {
420
+ params.index = 0;
421
+ this[parentKey] = undefined;
422
+ }
423
+ }
424
+ return params;
425
+ }
426
+ removeSelectMembers(options) {
427
+ let selectMembers;
428
+ if (typeof options === 'string') {
429
+ selectMembers = this.rights.find((item) => item.name === options);
430
+ if (!selectMembers) {
431
+ throw new Error('找不到选择成员 ' + options);
432
+ }
433
+ }
434
+ else {
435
+ selectMembers = options;
436
+ }
437
+ return selectMembers.delete();
438
+ }
439
+ __removeSelectMembers(selectMembers) {
440
+ const parentKey = selectMembers.parentKey;
441
+ const params = {
442
+ parentNode: this,
443
+ parentKey,
444
+ index: -1,
445
+ object: null,
446
+ oldObject: selectMembers,
447
+ };
448
+ if (parentKey) {
449
+ params.parentKey = parentKey;
450
+ if (Array.isArray(this[parentKey])) {
451
+ const index = this[parentKey].indexOf(selectMembers);
452
+ ~index && this[parentKey].splice(index, 1);
453
+ params.index = index;
454
+ }
455
+ else if (this[parentKey] === selectMembers) {
456
+ params.index = 0;
457
+ this[parentKey] = undefined;
458
+ }
459
+ }
460
+ return params;
461
+ }
462
+ removeAssignmentLine(options) {
463
+ let assignmentLine;
464
+ if (typeof options === 'string') {
465
+ assignmentLine = this.assignmentLines.find((item) => item.name === options);
466
+ if (!assignmentLine) {
467
+ throw new Error('找不到赋值连线 ' + options);
468
+ }
469
+ }
470
+ else {
471
+ assignmentLine = options;
472
+ }
473
+ return assignmentLine.delete();
474
+ }
475
+ __removeAssignmentLine(assignmentLine) {
476
+ const parentKey = assignmentLine.parentKey;
477
+ const params = {
478
+ parentNode: this,
479
+ parentKey,
480
+ index: -1,
481
+ object: null,
482
+ oldObject: assignmentLine,
483
+ };
484
+ if (parentKey) {
485
+ params.parentKey = parentKey;
486
+ if (Array.isArray(this[parentKey])) {
487
+ const index = this[parentKey].indexOf(assignmentLine);
488
+ ~index && this[parentKey].splice(index, 1);
489
+ params.index = index;
490
+ }
491
+ else if (this[parentKey] === assignmentLine) {
492
+ params.index = 0;
493
+ this[parentKey] = undefined;
494
+ }
495
+ }
496
+ return params;
497
+ }
498
+ //================================================================================
499
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
500
+ // 自动生成的代码已结束。下面可以手动编写。
501
+ //================================================================================
502
+ get lines() {
503
+ return this.assignmentLines.length;
504
+ }
505
+ async newConnection(addRightIndex) {
506
+ const leftLineSet = new Set();
507
+ const lineArr = [];
508
+ const connectionArr = [];
509
+ // 系统属性不可自动连线
510
+ ['id', 'createdTime', 'updatedTime', 'createdBy', 'updatedBy'].forEach((name) => leftLineSet.add(name));
511
+ // 左边已连线的下标
512
+ this.assignmentLines.forEach((line) => {
513
+ if (line.leftIndex.length > 1)
514
+ leftLineSet.add(Number(line.leftIndex[1]));
515
+ });
516
+ const autoConnection = () => {
517
+ let structure;
518
+ const isAnnotation = this.typeAnnotation.typeKind === 'anonymousStructure';
519
+ if (!isAnnotation)
520
+ structure = this.app.findNodeByCompleteName(this.typeAnnotation.typeNamespace + '.' + this.typeAnnotation.typeName);
521
+ this.app.emit('collect:start', {
522
+ actionMsg: '自动连线',
523
+ });
524
+ this.properties.forEach((property, leftSecondIndex) => {
525
+ const leftName = property.name;
526
+ const leftTypeAnnotation = !isAnnotation && structure.properties.find((p) => p.name === property.name).typeAnnotation;
527
+ const typeStruct = isAnnotation && this.typeAnnotation.properties[leftSecondIndex]; // 获取匿名数据结构typeAnnotation的具体property
528
+ if (leftLineSet.has(leftSecondIndex) || leftLineSet.has(leftName))
529
+ return;
530
+ this.rights.forEach((selectMember, rightFirstIndex) => {
531
+ const { members, expression } = selectMember;
532
+ if (leftLineSet.has(leftSecondIndex))
533
+ return;
534
+ if (addRightIndex !== -1 && addRightIndex !== rightFirstIndex)
535
+ return;
536
+ // 右侧父节点也不允许自动连线
537
+ const rightLineSet = new Set();
538
+ for (let i = 0; i < members.length - 1; i++) {
539
+ const completeName = members[i].completeName;
540
+ const preCompleteName = members[i + 1].completeName;
541
+ if (preCompleteName.includes(completeName) && completeName.split('.').length !== preCompleteName.split('.').length)
542
+ rightLineSet.add(i);
543
+ }
544
+ if (leftName === expression.name && (isAnnotation || expression.__TypeAnnotation.typeKind === leftTypeAnnotation.typeKind)) {
545
+ const Line = new AssignmentLine__1.default({
546
+ leftIndex: [0, leftSecondIndex],
547
+ rightIndex: [rightFirstIndex],
548
+ });
549
+ lineArr.push(Line);
550
+ connectionArr.push({
551
+ leftItem: typeStruct,
552
+ rightItem: expression,
553
+ });
554
+ leftLineSet.add(leftSecondIndex);
555
+ return;
556
+ }
557
+ members.forEach((rightMember, rightSecondIndex) => {
558
+ const rightName = rightMember.property.name;
559
+ if (rightLineSet.has(rightSecondIndex))
560
+ return;
561
+ if (leftName === rightName) {
562
+ const rightTypeAnnotation = rightMember.__TypeAnnotation;
563
+ if (!isAnnotation && leftTypeAnnotation.typeKind !== rightTypeAnnotation.typeKind)
564
+ return;
565
+ const leftIndex = [0, leftSecondIndex];
566
+ const rightIndex = [rightFirstIndex, rightSecondIndex];
567
+ const Line = new AssignmentLine__1.default({ leftIndex, rightIndex });
568
+ lineArr.push(Line);
569
+ connectionArr.push({
570
+ leftItem: typeStruct,
571
+ rightItem: rightMember,
572
+ });
573
+ leftLineSet.add(leftSecondIndex);
574
+ }
575
+ });
576
+ });
577
+ });
578
+ lineArr.length && this.setAssignmentLines([...this.assignmentLines, ...lineArr]);
579
+ if (this.typeAnnotation.typeKind === 'anonymousStructure') {
580
+ connectionArr.forEach(({ leftItem, rightItem }) => {
581
+ if (rightItem.__TypeAnnotation) {
582
+ leftItem.update({
583
+ typeAnnotation: TypeAnnotation__1.default.from({ ...rightItem.__TypeAnnotation.toJSON() }),
584
+ });
585
+ }
586
+ });
587
+ }
588
+ this.app.emit('collect:end');
589
+ };
590
+ let count = 0;
591
+ const typeAnnotationEnd = () => {
592
+ const r = this.rights.every((right) => right.members.every((item) => item.__isCorrectTypeAnnotation));
593
+ count++;
594
+ if (r) {
595
+ autoConnection();
596
+ }
597
+ else if (count <= 10) {
598
+ setTimeout(() => {
599
+ typeAnnotationEnd();
600
+ }, 100);
601
+ }
602
+ };
603
+ typeAnnotationEnd();
604
+ }
605
+ connection(leftItem, rightItem, rightToLeft) {
606
+ let newLeftIndex = [0];
607
+ let newRightIndex = [];
608
+ let newLines = [...this.assignmentLines];
609
+ let newProperties = this.properties;
610
+ if (leftItem.concept === 'Identifier') {
611
+ const members = this.properties;
612
+ const secondIndex = members.findIndex((ident) => ident === leftItem);
613
+ // 连线左边的坐标。
614
+ newLeftIndex = [0, secondIndex];
615
+ }
616
+ else {
617
+ newLines = [];
618
+ newProperties = [];
619
+ }
620
+ if (rightItem.concept === 'SelectMembers') {
621
+ newRightIndex = [this.rights.findIndex((right) => right === rightItem)];
622
+ }
623
+ else {
624
+ const selectMember = rightItem.getAncestor('SelectMembers');
625
+ const firstIndex = this.rights.findIndex((right) => right === selectMember);
626
+ const secondIndex = this.rights[firstIndex].members.findIndex((exp) => exp === rightItem);
627
+ newRightIndex = [firstIndex, secondIndex];
628
+ }
629
+ // 左边同一个属性只能有一个连线
630
+ if (rightToLeft) {
631
+ newLines = newLines.filter(({ leftIndex: index }) => !(newLeftIndex[0] === index[0] && newLeftIndex[1] === index[1]));
632
+ }
633
+ const Line = new AssignmentLine__1.default({
634
+ leftIndex: newLeftIndex,
635
+ rightIndex: newRightIndex,
636
+ });
637
+ newLines.push(Line);
638
+ if (this.typeAnnotation.typeKind !== 'anonymousStructure') {
639
+ this.update({
640
+ assignmentLines: newLines,
641
+ properties: newProperties,
642
+ });
643
+ }
644
+ else {
645
+ this.app.emit('collect:start', {
646
+ actionMsg: '匿名数据结构连线',
647
+ });
648
+ // 匿名数据结构typeAnnotation变化
649
+ const structureProperty = this.typeAnnotation.properties.find(({ name }) => name === leftItem.name);
650
+ const exp = rightItem.concept === 'SelectMembers' ? rightItem.expression : rightItem;
651
+ // 场景:右侧连接是非匿名数据
652
+ if (exp.__TypeAnnotation && exp.__TypeAnnotation.typeKey !== 'nasl.core.Null') {
653
+ structureProperty.update({
654
+ typeAnnotation: TypeAnnotation__1.default.from({ ...exp.__TypeAnnotation.toJSON() }),
655
+ });
656
+ }
657
+ this.update({
658
+ assignmentLines: newLines,
659
+ properties: newProperties,
660
+ });
661
+ this.app.emit('collect:end');
662
+ }
663
+ }
664
+ deleteAssignmentLine(assignmentLine) {
665
+ const newLine = this.assignmentLines.filter((line) => line !== assignmentLine);
666
+ this.app.emit('collect:start', {
667
+ actionMsg: '删除连线',
668
+ });
669
+ if (this.typeAnnotation.typeKind === 'anonymousStructure') {
670
+ const typeStructureProperty = this.findMember(assignmentLine.leftIndex, 'left', true);
671
+ typeStructureProperty.update({
672
+ typeAnnotation: null,
673
+ });
674
+ }
675
+ this.update({
676
+ assignmentLines: newLine,
677
+ });
678
+ this.app.emit('collect:end');
679
+ }
680
+ changeLinesLocation(selectMember) {
681
+ if (selectMember.concept !== 'SelectMembers')
682
+ return;
683
+ if (this.rights.findIndex((member) => selectMember === member) !== -1) {
684
+ const index = this.rights.findIndex((member) => selectMember === member);
685
+ const newRights = this.rights.filter((member) => selectMember !== member);
686
+ const filterLine = this.assignmentLines.filter((line) => line.rightIndex[0] !== index);
687
+ const newLines = [];
688
+ const oldLines = this.assignmentLines.filter(({ rightIndex }) => rightIndex[0] === index);
689
+ filterLine.forEach((line) => {
690
+ if (line.rightIndex[0] > index) {
691
+ if (line.rightIndex[1] === undefined) {
692
+ const newLine = Object.assign({}, line, { rightIndex: [line.rightIndex[0] - 1] });
693
+ newLines.push(newLine);
694
+ }
695
+ else {
696
+ const newLine = Object.assign({}, line, { rightIndex: [line.rightIndex[0] - 1, line.rightIndex[1]] });
697
+ newLines.push(newLine);
698
+ }
699
+ }
700
+ else {
701
+ newLines.push(line);
702
+ }
703
+ });
704
+ this.app.emit('collect:start', {
705
+ actionMsg: '匿名数据结构删除右侧变量',
706
+ });
707
+ if (this.typeAnnotation.typeKind === 'anonymousStructure') {
708
+ oldLines.forEach(({ leftIndex }) => {
709
+ const leftItem = this.typeAnnotation.properties[leftIndex[1]];
710
+ leftItem.update({
711
+ typeAnnotation: null,
712
+ });
713
+ });
714
+ }
715
+ this.update({
716
+ rights: newRights,
717
+ assignmentLines: newLines,
718
+ });
719
+ this.app.emit('collect:end');
720
+ }
721
+ }
722
+ changeMembers(oldNode, members, keepMembers, expression) {
723
+ this.app.emit('collect:start', {
724
+ actionMsg: 'New初始赋值修改变量',
725
+ });
726
+ const selectMember = oldNode.parentNode;
727
+ const autoConnectionIndex = this.rights.findIndex((right) => right === selectMember);
728
+ const newSelectMember = Object.assign({}, selectMember, { expression, members });
729
+ const splitIndex = this.rights.findIndex((right) => selectMember === right);
730
+ const newLines = this.assignmentLines.filter(({ rightIndex }) => rightIndex[0] !== splitIndex);
731
+ let oldLines = this.assignmentLines.filter(({ rightIndex }) => rightIndex[0] === splitIndex);
732
+ // 右侧变量改变后,修改连线
733
+ members.forEach((item, index) => {
734
+ if (keepMembers.has(item.completeName)) {
735
+ const lines = this.findlines(item, selectMember);
736
+ lines.forEach((line) => {
737
+ const newLine = Object.assign({}, line, { rightIndex: [line.rightIndex[0], index] });
738
+ newLines.push(newLine);
739
+ oldLines = oldLines.filter(({ leftIndex }) => leftIndex[1] !== line.leftIndex[1]);
740
+ });
741
+ }
742
+ });
743
+ if (this.typeAnnotation.typeKind === 'anonymousStructure') {
744
+ oldLines.forEach(({ leftIndex }) => {
745
+ const leftItem = this.typeAnnotation.properties[leftIndex[1]];
746
+ leftItem.update({
747
+ typeAnnotation: null,
748
+ });
749
+ });
750
+ }
751
+ this.update({
752
+ assignmentLines: newLines,
753
+ rights: [...this.rights.slice(0, splitIndex), newSelectMember, ...this.rights.slice(splitIndex + 1, this.rights.length)],
754
+ });
755
+ this.autoConnection && this.newConnection(autoConnectionIndex);
756
+ this.app.emit('collect:end');
757
+ }
758
+ findlines(member, selectMember) {
759
+ const lines = [];
760
+ // 根节点的情况
761
+ if (selectMember === this) {
762
+ if (member === this.typeAnnotation)
763
+ return this.assignmentLines;
764
+ else {
765
+ const index2 = this.properties.findIndex((item) => item.completeName === member.completeName);
766
+ this.assignmentLines.forEach((line) => {
767
+ if (line.leftIndex[1] === index2)
768
+ lines.push(line);
769
+ });
770
+ }
771
+ }
772
+ else {
773
+ const index1 = this.rights.findIndex((right) => right === selectMember);
774
+ const index2 = selectMember.members.findIndex((item) => item.completeName === member.completeName);
775
+ this.assignmentLines.forEach((line) => {
776
+ if (line.rightIndex[0] === index1 && line.rightIndex[1] === index2)
777
+ lines.push(line);
778
+ });
779
+ }
780
+ return lines;
781
+ }
782
+ findMember(arrIndex, place, isAnnotation) {
783
+ const [firstIndex, secondIndex] = [arrIndex[0], arrIndex[1]];
784
+ if (isAnnotation) {
785
+ return this.typeAnnotation.properties[secondIndex];
786
+ }
787
+ if (place === 'left') {
788
+ if (secondIndex === undefined) {
789
+ return this.typeAnnotation;
790
+ }
791
+ return this.properties[secondIndex];
792
+ }
793
+ else {
794
+ if (secondIndex === undefined) {
795
+ return this.rights[firstIndex].expression;
796
+ }
797
+ return this.rights[firstIndex].members[secondIndex];
798
+ }
799
+ }
800
+ toUI(state) {
801
+ let code = '';
802
+ const typeAnnotation = this.typeAnnotation;
803
+ const leftTopIndex = this.assignmentLines.findIndex(({ leftIndex }) => leftIndex[1] === undefined);
804
+ if (!this.typeAnnotation)
805
+ return null;
806
+ code += 'await (async () => { \n';
807
+ if (leftTopIndex !== -1) {
808
+ const rightIndex = this.assignmentLines[leftTopIndex].rightIndex;
809
+ const obj = rightIndex[1] !== undefined ? this.rights[rightIndex[0]].members[rightIndex[1]] : this.rights[rightIndex[0]].expression;
810
+ code += `return ${obj};\n`;
811
+ }
812
+ else if (typeAnnotation.typeKind !== 'anonymousStructure') {
813
+ code += `const obj = this.$genInitFromSchema('${typeAnnotation.sortedTypeKey}', this.$utils['New'](${typeAnnotation.toUI((0, translator_1.shiftState)(state, code, { inline: true }))}));\n`;
814
+ this.assignmentLines.forEach(({ leftIndex, rightIndex }, index) => {
815
+ const leftSecondIndex = leftIndex[1];
816
+ const [rightFirst, rightSecond] = [rightIndex[0], rightIndex[1]];
817
+ const leftItem = this.properties[leftSecondIndex];
818
+ const rightItem = rightSecond !== undefined ? this.rights[rightFirst].members[rightSecond] : this.rights[rightFirst].expression;
819
+ code += `obj.${leftItem.name} = ${rightItem.toUI((0, translator_1.shiftState)(state, code, { inline: true }))}`;
820
+ code += ';\n';
821
+ });
822
+ code += 'return obj;\n';
823
+ }
824
+ else {
825
+ code += `const obj = {};\n`;
826
+ this.properties.forEach((property) => {
827
+ code += `obj.${property.name} = null;\n`;
828
+ });
829
+ this.assignmentLines.forEach(({ leftIndex, rightIndex }, index) => {
830
+ const leftSecondIndex = leftIndex[1];
831
+ const [rightFirst, rightSecond] = [rightIndex[0], rightIndex[1]];
832
+ const leftItem = this.properties[leftSecondIndex];
833
+ const rightItem = rightSecond !== undefined ? this.rights[rightFirst].members[rightSecond] : this.rights[rightFirst].expression;
834
+ code += `obj.${leftItem.name} = ${rightItem.toUI((0, translator_1.shiftState)(state, code, { inline: true }))}`;
835
+ code += ';\n';
836
+ });
837
+ code += 'return obj;\n';
838
+ }
839
+ code += '})()';
840
+ return code;
841
+ }
842
+ toJS(state) {
843
+ let code = '';
844
+ const typeAnnotation = this.typeAnnotation;
845
+ const leftTopIndex = this.assignmentLines.findIndex(({ leftIndex }) => leftIndex[1] === undefined);
846
+ if (!this.typeAnnotation)
847
+ return null;
848
+ code += 'await (async () => { \n';
849
+ if (leftTopIndex !== -1) {
850
+ const rightIndex = this.assignmentLines[leftTopIndex].rightIndex;
851
+ const obj = rightIndex[1] !== undefined ? this.rights[rightIndex[0]].members[rightIndex[1]] : this.rights[rightIndex[0]].expression;
852
+ code += `return ${obj.toJS((0, translator_1.shiftState)(state, code, { inline: true }))};\n`;
853
+ }
854
+ else if (typeAnnotation.typeKind !== 'anonymousStructure') {
855
+ code += `const obj = this.$genInitFromSchema('${typeAnnotation.sortedTypeKey}', this.$utils['New'](${typeAnnotation.toJS((0, translator_1.shiftState)(state, code, { inline: true }))}));\n`;
856
+ this.assignmentLines.forEach(({ leftIndex, rightIndex }, index) => {
857
+ const leftSecondIndex = leftIndex[1];
858
+ const [rightFirst, rightSecond] = [rightIndex[0], rightIndex[1]];
859
+ const leftItem = this.properties[leftSecondIndex];
860
+ const rightItem = rightSecond !== undefined ? this.rights[rightFirst].members[rightSecond] : this.rights[rightFirst].expression;
861
+ code += `obj.${leftItem.name} = ${rightItem.toJS((0, translator_1.shiftState)(state, code, { inline: true }))}`;
862
+ code += ';\n';
863
+ });
864
+ code += 'return obj;\n';
865
+ }
866
+ else {
867
+ code += `const obj = {};\n`;
868
+ this.properties.forEach((property) => {
869
+ code += `obj.${property.name} = null;\n`;
870
+ });
871
+ this.assignmentLines.forEach(({ leftIndex, rightIndex }, index) => {
872
+ const leftSecondIndex = leftIndex[1];
873
+ const [rightFirst, rightSecond] = [rightIndex[0], rightIndex[1]];
874
+ const leftItem = this.properties[leftSecondIndex];
875
+ const rightItem = rightSecond !== undefined ? this.rights[rightFirst].members[rightSecond] : this.rights[rightFirst].expression;
876
+ code += `obj.${leftItem.name} = ${rightItem.toJS((0, translator_1.shiftState)(state, code, { inline: true }))}`;
877
+ code += ';\n';
878
+ });
879
+ code += 'return obj;\n';
880
+ }
881
+ code += '})()';
882
+ return code;
883
+ }
884
+ toEmbeddedTS(state) {
885
+ let code = '';
886
+ if (!this.typeAnnotation) {
887
+ code += '__IDENTIFIER__';
888
+ }
889
+ else if (this.typeAnnotation.typeKind !== 'anonymousStructure') {
890
+ const rightMap = new Map();
891
+ code += '(() => { \n';
892
+ // 提供sourcemap,获取类型标注和上下文可选变量
893
+ this.rights.forEach((right) => {
894
+ rightMap.set(right.expression, right.expression.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })));
895
+ code += rightMap.get(right.expression);
896
+ code += ';\n';
897
+ right.members.forEach((member) => {
898
+ rightMap.set(member, member.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })));
899
+ code += rightMap.get(member);
900
+ code += '; ';
901
+ });
902
+ code += right.members.length ? '\n' : '';
903
+ });
904
+ // 方便ts报错检查
905
+ code += 'function __newComposite() {\n';
906
+ code += `let __obj = nasl.util.New<${this.typeAnnotation.sortedTypeKey}>();`;
907
+ code += '\n';
908
+ // 是否是左边的顶层连线
909
+ const leftTopIndex = this.assignmentLines.findIndex(({ leftIndex }) => leftIndex[1] === undefined);
910
+ if (leftTopIndex !== -1) {
911
+ const rightIndex = this.assignmentLines[leftTopIndex].rightIndex;
912
+ const rightExpression = rightIndex[1] !== undefined ? this.rights[rightIndex[0]].members[rightIndex[1]] : this.rights[rightIndex[0]].expression;
913
+ code += `__obj = ${rightExpression.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }))};`;
914
+ code += '\n';
915
+ }
916
+ else {
917
+ // 左侧properties的identifier的类型标注
918
+ this.properties.forEach((item) => {
919
+ code += `const `;
920
+ code += `${item.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }))} = __obj.${item.name};\n`;
921
+ });
922
+ this.assignmentLines.forEach(({ leftIndex, rightIndex }) => {
923
+ const leftSecondIndex = leftIndex[1];
924
+ const [rightFirst, rightSecond] = [rightIndex[0], rightIndex[1]];
925
+ const leftItem = this.properties[leftSecondIndex];
926
+ const rightItem = rightSecond !== undefined ? this.rights[rightFirst].members[rightSecond] : this.rights[rightFirst].expression;
927
+ const rightTs = rightMap.get(rightItem);
928
+ code += `nasl.core.compare2(`;
929
+ code += `${['__IDENTIFIER__', '__IDENTIFIER__()'].includes(rightTs) ? 'null' : rightMap.get(rightItem)}, `;
930
+ code += `${leftItem.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }))});\n`;
931
+ });
932
+ }
933
+ code += 'return __obj;\n';
934
+ code += '};\n';
935
+ code += 'return __newComposite();\n';
936
+ code += '})()';
937
+ }
938
+ else {
939
+ const nameMap = new Map();
940
+ const rightMap = new Map();
941
+ this.assignmentLines.forEach(({ leftIndex, rightIndex }) => {
942
+ const leftSecondIndex = leftIndex[1];
943
+ const [rightFirst, rightSecond] = [rightIndex[0], rightIndex[1]];
944
+ const leftItem = this.properties[leftSecondIndex];
945
+ const rightItem = rightSecond !== undefined ? this.rights[rightFirst].members[rightSecond] : this.rights[rightFirst].expression;
946
+ nameMap.set(leftItem.name, rightItem);
947
+ rightMap.set(rightItem, null);
948
+ });
949
+ code += '(() => { \n';
950
+ // 提供sourcemap,获取类型标注和上下文可选变量
951
+ this.rights.forEach((right) => {
952
+ let ts = right.expression.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
953
+ if (rightMap.has(right.expression))
954
+ rightMap.set(right.expression, ts);
955
+ code += ts;
956
+ code += ';\n';
957
+ right.members.forEach((member) => {
958
+ ts = member.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
959
+ if (rightMap.has(member))
960
+ rightMap.set(member, ts);
961
+ code += ts;
962
+ code += '; ';
963
+ });
964
+ code += right.members.length ? '\n' : '';
965
+ });
966
+ // 方便ts报错检查
967
+ code += 'function __newComposite(): ';
968
+ code += this.typeAnnotation.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
969
+ code += '{\n';
970
+ this.properties.forEach((property) => {
971
+ const name = property.name;
972
+ const rightItem = nameMap.get(name);
973
+ if (rightMap.get(rightItem) !== undefined) {
974
+ code += `{ const x = ${rightMap.get(rightItem)}; const `;
975
+ code += property.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
976
+ code += `: nasl.core.Incompatible<typeof x, void> = x`;
977
+ code += '; }\n';
978
+ }
979
+ else {
980
+ code += '{ const ';
981
+ code += property.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
982
+ code += '; }\n';
983
+ }
984
+ });
985
+ code += 'return;\n';
986
+ code += '};\n';
987
+ code += 'return __newComposite();\n';
988
+ code += '})()';
989
+ }
990
+ return code;
991
+ }
992
+ __addIdentifier(App) {
993
+ const app = this.app || App;
994
+ app.emit('collect:start', {
995
+ actionMsg: '添加匿名数据结构属性',
996
+ });
997
+ const node = this.addIdentifier({ name: this.getIdentifierUniqueName('property1') });
998
+ const struct = StructureProperty__1.default.from({
999
+ name: node.name,
1000
+ typeAnnotation: null,
1001
+ });
1002
+ this.typeAnnotation.addStructureProperty(struct);
1003
+ app.emit('collect:end');
1004
+ }
1005
+ __deleteIdentifier(property) {
1006
+ const index = this.properties.findIndex((p) => p === property);
1007
+ const newLines = [];
1008
+ const newProperties = [...this.typeAnnotation.properties.slice(0, index), ...this.typeAnnotation.properties.slice(index + 1, this.properties.length)];
1009
+ this.assignmentLines.forEach((line) => {
1010
+ const { leftIndex } = line;
1011
+ if (leftIndex[1] < index) {
1012
+ newLines.push(line);
1013
+ }
1014
+ else if (leftIndex[1] > index) {
1015
+ const newLine = Object.assign({}, line, { leftIndex: [leftIndex[0], leftIndex[1] - 1] });
1016
+ newLines.push(newLine);
1017
+ }
1018
+ });
1019
+ this.app.emit('collect:start', {
1020
+ actionMsg: '删除匿名数据结属性',
1021
+ });
1022
+ this.setAssignmentLines(newLines);
1023
+ this.typeAnnotation.update({
1024
+ properties: newProperties,
1025
+ });
1026
+ property.delete();
1027
+ this.app.emit('collect:end');
1028
+ }
1029
+ };
1030
+ __decorate([
1031
+ (0, decorators_1.property)()
1032
+ ], NewComposite.prototype, "concept", void 0);
1033
+ __decorate([
1034
+ (0, decorators_1.property)('TypeAnnotation')
1035
+ ], NewComposite.prototype, "typeAnnotation", void 0);
1036
+ __decorate([
1037
+ (0, decorators_1.property)('Identifier')
1038
+ ], NewComposite.prototype, "properties", void 0);
1039
+ __decorate([
1040
+ (0, decorators_1.property)('SelectMembers')
1041
+ ], NewComposite.prototype, "rights", void 0);
1042
+ __decorate([
1043
+ (0, decorators_1.property)('AssignmentLine')
1044
+ ], NewComposite.prototype, "assignmentLines", void 0);
1045
+ __decorate([
1046
+ (0, decorators_1.property)()
1047
+ ], NewComposite.prototype, "hideProperties", void 0);
1048
+ __decorate([
1049
+ (0, decorators_1.property)()
1050
+ ], NewComposite.prototype, "hideDefaults", void 0);
1051
+ __decorate([
1052
+ (0, decorators_1.property)()
1053
+ ], NewComposite.prototype, "autoConnection", void 0);
1054
+ __decorate([
1055
+ (0, translator_1.withSourceMap)()
1056
+ ], NewComposite.prototype, "toEmbeddedTS", null);
1057
+ NewComposite = NewComposite_1 = __decorate([
1058
+ (0, decorators_1.concept)('实体/(匿名)数据结构构造器')
1059
+ ], NewComposite);
1060
+ exports.NewComposite = NewComposite;
1061
+ classMap_1.default.NewComposite = NewComposite;
1062
+ exports.default = NewComposite;
1063
+ //================================================================================
1064
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
1065
+ // 自动生成的代码已结束。下面可以手动编写。
1066
+ //================================================================================
1067
+ //# sourceMappingURL=NewComposite__.js.map