@lcap/nasl-concepts 3.13.0-alpha.microapp-1 → 3.13.0-beta.10

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 (261) hide show
  1. package/out/common/BaseNode.d.ts +3 -3
  2. package/out/common/BaseNode.d.ts.map +1 -1
  3. package/out/common/BaseNode.js +11 -7
  4. package/out/common/BaseNode.js.map +1 -1
  5. package/out/concepts/Abort__.js +1 -1
  6. package/out/concepts/Abort__.js.map +1 -1
  7. package/out/concepts/App__.d.ts +83 -0
  8. package/out/concepts/App__.d.ts.map +1 -1
  9. package/out/concepts/App__.js +106 -2
  10. package/out/concepts/App__.js.map +1 -1
  11. package/out/concepts/AuthLogicForCallInterface__.js +1 -1
  12. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
  13. package/out/concepts/BackendVariable__.js +2 -2
  14. package/out/concepts/BackendVariable__.js.map +1 -1
  15. package/out/concepts/Backend__.js +1 -1
  16. package/out/concepts/Backend__.js.map +1 -1
  17. package/out/concepts/BatchAssignment__.d.ts +25 -2
  18. package/out/concepts/BatchAssignment__.d.ts.map +1 -1
  19. package/out/concepts/BatchAssignment__.js +436 -69
  20. package/out/concepts/BatchAssignment__.js.map +1 -1
  21. package/out/concepts/BindAttribute__.d.ts.map +1 -1
  22. package/out/concepts/BindAttribute__.js +9 -2
  23. package/out/concepts/BindAttribute__.js.map +1 -1
  24. package/out/concepts/BindDirective__.d.ts.map +1 -1
  25. package/out/concepts/BindDirective__.js +7 -1
  26. package/out/concepts/BindDirective__.js.map +1 -1
  27. package/out/concepts/BindEvent__.js +1 -1
  28. package/out/concepts/BindEvent__.js.map +1 -1
  29. package/out/concepts/Break__.d.ts +33 -0
  30. package/out/concepts/Break__.d.ts.map +1 -0
  31. package/out/concepts/Break__.js +120 -0
  32. package/out/concepts/Break__.js.map +1 -0
  33. package/out/concepts/BusinessComponent__.d.ts.map +1 -1
  34. package/out/concepts/BusinessComponent__.js +3 -2
  35. package/out/concepts/BusinessComponent__.js.map +1 -1
  36. package/out/concepts/CallLogic__.d.ts +1 -0
  37. package/out/concepts/CallLogic__.d.ts.map +1 -1
  38. package/out/concepts/CallLogic__.js +16 -3
  39. package/out/concepts/CallLogic__.js.map +1 -1
  40. package/out/concepts/CallQueryComponent__.d.ts +14 -5
  41. package/out/concepts/CallQueryComponent__.d.ts.map +1 -1
  42. package/out/concepts/CallQueryComponent__.js +90 -56
  43. package/out/concepts/CallQueryComponent__.js.map +1 -1
  44. package/out/concepts/CompletionProperty__.d.ts.map +1 -1
  45. package/out/concepts/CompletionProperty__.js +7 -0
  46. package/out/concepts/CompletionProperty__.js.map +1 -1
  47. package/out/concepts/ConfigProperty__.js +2 -2
  48. package/out/concepts/ConfigProperty__.js.map +1 -1
  49. package/out/concepts/Connection__.js +2 -2
  50. package/out/concepts/Connection__.js.map +1 -1
  51. package/out/concepts/ConnectorTrigger__.js +1 -1
  52. package/out/concepts/ConnectorTrigger__.js.map +1 -1
  53. package/out/concepts/Continue__.d.ts +33 -0
  54. package/out/concepts/Continue__.d.ts.map +1 -0
  55. package/out/concepts/Continue__.js +120 -0
  56. package/out/concepts/Continue__.js.map +1 -0
  57. package/out/concepts/DataSource__.d.ts +12 -1
  58. package/out/concepts/DataSource__.d.ts.map +1 -1
  59. package/out/concepts/DataSource__.js +58 -5
  60. package/out/concepts/DataSource__.js.map +1 -1
  61. package/out/concepts/DefaultValue__.d.ts +1 -0
  62. package/out/concepts/DefaultValue__.d.ts.map +1 -1
  63. package/out/concepts/DefaultValue__.js +9 -0
  64. package/out/concepts/DefaultValue__.js.map +1 -1
  65. package/out/concepts/Dependency__.js +1 -1
  66. package/out/concepts/Dependency__.js.map +1 -1
  67. package/out/concepts/Destination__.js +1 -1
  68. package/out/concepts/End__.d.ts.map +1 -1
  69. package/out/concepts/End__.js +34 -2
  70. package/out/concepts/End__.js.map +1 -1
  71. package/out/concepts/Entity__.d.ts +13 -0
  72. package/out/concepts/Entity__.d.ts.map +1 -1
  73. package/out/concepts/Entity__.js +49 -9
  74. package/out/concepts/Entity__.js.map +1 -1
  75. package/out/concepts/Enum__.js +2 -2
  76. package/out/concepts/Enum__.js.map +1 -1
  77. package/out/concepts/ExternalDestination__.js +1 -1
  78. package/out/concepts/ForEachStatement__.d.ts.map +1 -1
  79. package/out/concepts/ForEachStatement__.js +10 -8
  80. package/out/concepts/ForEachStatement__.js.map +1 -1
  81. package/out/concepts/FrontendType__.js +1 -1
  82. package/out/concepts/FrontendType__.js.map +1 -1
  83. package/out/concepts/Frontend__.d.ts +0 -3
  84. package/out/concepts/Frontend__.d.ts.map +1 -1
  85. package/out/concepts/Frontend__.js +1 -25
  86. package/out/concepts/Frontend__.js.map +1 -1
  87. package/out/concepts/InterfaceParam__.d.ts +1 -0
  88. package/out/concepts/InterfaceParam__.d.ts.map +1 -1
  89. package/out/concepts/InterfaceParam__.js +35 -0
  90. package/out/concepts/InterfaceParam__.js.map +1 -1
  91. package/out/concepts/Interface__.d.ts +1 -0
  92. package/out/concepts/Interface__.d.ts.map +1 -1
  93. package/out/concepts/Interface__.js +45 -2
  94. package/out/concepts/Interface__.js.map +1 -1
  95. package/out/concepts/JSBlock__.d.ts.map +1 -1
  96. package/out/concepts/JSBlock__.js +1 -3
  97. package/out/concepts/JSBlock__.js.map +1 -1
  98. package/out/concepts/LogicItem__.d.ts +1 -1
  99. package/out/concepts/LogicItem__.d.ts.map +1 -1
  100. package/out/concepts/LogicItem__.js.map +1 -1
  101. package/out/concepts/Logic__.d.ts +12 -1
  102. package/out/concepts/Logic__.d.ts.map +1 -1
  103. package/out/concepts/Logic__.js +56 -21
  104. package/out/concepts/Logic__.js.map +1 -1
  105. package/out/concepts/MemberExpression__.d.ts +4 -0
  106. package/out/concepts/MemberExpression__.d.ts.map +1 -1
  107. package/out/concepts/MemberExpression__.js +16 -0
  108. package/out/concepts/MemberExpression__.js.map +1 -1
  109. package/out/concepts/MetadataType__.js +2 -2
  110. package/out/concepts/MetadataType__.js.map +1 -1
  111. package/out/concepts/Module__.d.ts +7 -1
  112. package/out/concepts/Module__.d.ts.map +1 -1
  113. package/out/concepts/Module__.js +40 -2
  114. package/out/concepts/Module__.js.map +1 -1
  115. package/out/concepts/Namespace__.js +1 -1
  116. package/out/concepts/Namespace__.js.map +1 -1
  117. package/out/concepts/NewComposite__.d.ts +35 -3
  118. package/out/concepts/NewComposite__.d.ts.map +1 -1
  119. package/out/concepts/NewComposite__.js +465 -67
  120. package/out/concepts/NewComposite__.js.map +1 -1
  121. package/out/concepts/OperatePermissionV2__.d.ts +9 -1
  122. package/out/concepts/OperatePermissionV2__.d.ts.map +1 -1
  123. package/out/concepts/OperatePermissionV2__.js +24 -3
  124. package/out/concepts/OperatePermissionV2__.js.map +1 -1
  125. package/out/concepts/OqlQueryComponent__.d.ts +2 -0
  126. package/out/concepts/OqlQueryComponent__.d.ts.map +1 -1
  127. package/out/concepts/OqlQueryComponent__.js +10 -0
  128. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  129. package/out/concepts/OverriddenLogic__.d.ts.map +1 -1
  130. package/out/concepts/OverriddenLogic__.js +2 -1
  131. package/out/concepts/OverriddenLogic__.js.map +1 -1
  132. package/out/concepts/Param__.d.ts +1 -0
  133. package/out/concepts/Param__.d.ts.map +1 -1
  134. package/out/concepts/Param__.js +38 -2
  135. package/out/concepts/Param__.js.map +1 -1
  136. package/out/concepts/PermissionForSharedScope__.d.ts +34 -0
  137. package/out/concepts/PermissionForSharedScope__.d.ts.map +1 -0
  138. package/out/concepts/PermissionForSharedScope__.js +73 -0
  139. package/out/concepts/PermissionForSharedScope__.js.map +1 -0
  140. package/out/concepts/ProcessElementV2__.d.ts +4 -0
  141. package/out/concepts/ProcessElementV2__.d.ts.map +1 -1
  142. package/out/concepts/ProcessElementV2__.js +75 -10
  143. package/out/concepts/ProcessElementV2__.js.map +1 -1
  144. package/out/concepts/ProcessElement__.js +1 -1
  145. package/out/concepts/ProcessElement__.js.map +1 -1
  146. package/out/concepts/ProcessV2__.d.ts.map +1 -1
  147. package/out/concepts/ProcessV2__.js +1 -8
  148. package/out/concepts/ProcessV2__.js.map +1 -1
  149. package/out/concepts/Process__.js +1 -1
  150. package/out/concepts/Process__.js.map +1 -1
  151. package/out/concepts/QueryFieldExpression__.d.ts +5 -0
  152. package/out/concepts/QueryFieldExpression__.d.ts.map +1 -1
  153. package/out/concepts/QueryFieldExpression__.js +15 -4
  154. package/out/concepts/QueryFieldExpression__.js.map +1 -1
  155. package/out/concepts/QueryFromExpression__.d.ts +1 -0
  156. package/out/concepts/QueryFromExpression__.d.ts.map +1 -1
  157. package/out/concepts/QueryFromExpression__.js +3 -0
  158. package/out/concepts/QueryFromExpression__.js.map +1 -1
  159. package/out/concepts/QueryJoinExpression__.d.ts +1 -0
  160. package/out/concepts/QueryJoinExpression__.d.ts.map +1 -1
  161. package/out/concepts/QueryJoinExpression__.js +3 -0
  162. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  163. package/out/concepts/Return__.d.ts +1 -0
  164. package/out/concepts/Return__.d.ts.map +1 -1
  165. package/out/concepts/Return__.js +39 -2
  166. package/out/concepts/Return__.js.map +1 -1
  167. package/out/concepts/Role__.js +1 -1
  168. package/out/concepts/Role__.js.map +1 -1
  169. package/out/concepts/SelectMembers__.d.ts +5 -0
  170. package/out/concepts/SelectMembers__.d.ts.map +1 -1
  171. package/out/concepts/SelectMembers__.js +66 -0
  172. package/out/concepts/SelectMembers__.js.map +1 -1
  173. package/out/concepts/SharedScope__.d.ts +38 -0
  174. package/out/concepts/SharedScope__.d.ts.map +1 -0
  175. package/out/concepts/SharedScope__.js +79 -0
  176. package/out/concepts/SharedScope__.js.map +1 -0
  177. package/out/concepts/StructureProperty__.d.ts +1 -0
  178. package/out/concepts/StructureProperty__.d.ts.map +1 -1
  179. package/out/concepts/StructureProperty__.js +37 -0
  180. package/out/concepts/StructureProperty__.js.map +1 -1
  181. package/out/concepts/Structure__.d.ts +1 -1
  182. package/out/concepts/Structure__.d.ts.map +1 -1
  183. package/out/concepts/Structure__.js +23 -30
  184. package/out/concepts/Structure__.js.map +1 -1
  185. package/out/concepts/SubLogic__.d.ts +3 -1
  186. package/out/concepts/SubLogic__.d.ts.map +1 -1
  187. package/out/concepts/SubLogic__.js +127 -2
  188. package/out/concepts/SubLogic__.js.map +1 -1
  189. package/out/concepts/TypeAnnotation__.d.ts +21 -0
  190. package/out/concepts/TypeAnnotation__.d.ts.map +1 -1
  191. package/out/concepts/TypeAnnotation__.js +82 -0
  192. package/out/concepts/TypeAnnotation__.js.map +1 -1
  193. package/out/concepts/TypeParam__.d.ts +1 -0
  194. package/out/concepts/TypeParam__.d.ts.map +1 -1
  195. package/out/concepts/TypeParam__.js +32 -0
  196. package/out/concepts/TypeParam__.js.map +1 -1
  197. package/out/concepts/Variable__.js +1 -1
  198. package/out/concepts/Variable__.js.map +1 -1
  199. package/out/concepts/ViewElement__.d.ts.map +1 -1
  200. package/out/concepts/ViewElement__.js +29 -1
  201. package/out/concepts/ViewElement__.js.map +1 -1
  202. package/out/concepts/View__.d.ts.map +1 -1
  203. package/out/concepts/View__.js +5 -2
  204. package/out/concepts/View__.js.map +1 -1
  205. package/out/concepts/basics/stdlib/nasl.processV2.d.ts.map +1 -1
  206. package/out/concepts/basics/stdlib/nasl.processV2.js +279 -129
  207. package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
  208. package/out/concepts/basics/stdlib/nasl.util.d.ts.map +1 -1
  209. package/out/concepts/basics/stdlib/nasl.util.js +238 -0
  210. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  211. package/out/concepts/index__.d.ts +2 -0
  212. package/out/concepts/index__.d.ts.map +1 -1
  213. package/out/concepts/index__.js +2 -0
  214. package/out/concepts/index__.js.map +1 -1
  215. package/out/concepts/utils/asserts.d.ts +204 -0
  216. package/out/concepts/utils/asserts.d.ts.map +1 -1
  217. package/out/concepts/utils/asserts.js +286 -15
  218. package/out/concepts/utils/asserts.js.map +1 -1
  219. package/out/concepts/utils/types.d.ts +16 -2
  220. package/out/concepts/utils/types.d.ts.map +1 -1
  221. package/out/semantics/localVarCollector.d.ts +11 -0
  222. package/out/semantics/localVarCollector.d.ts.map +1 -0
  223. package/out/semantics/localVarCollector.js +41 -0
  224. package/out/semantics/localVarCollector.js.map +1 -0
  225. package/out/semantics/semanticData.d.ts +6 -5
  226. package/out/semantics/semanticData.d.ts.map +1 -1
  227. package/out/semantics/semanticData.js +69 -62
  228. package/out/semantics/semanticData.js.map +1 -1
  229. package/out/service/engine.d.ts.map +1 -1
  230. package/out/service/engine.js +4 -0
  231. package/out/service/engine.js.map +1 -1
  232. package/out/service/entity2LogicNamespace.d.ts.map +1 -1
  233. package/out/service/entity2LogicNamespace.js +20 -9
  234. package/out/service/entity2LogicNamespace.js.map +1 -1
  235. package/out/service/formatTsUtils.d.ts +1 -1
  236. package/out/service/formatTsUtils.d.ts.map +1 -1
  237. package/out/service/formatTsUtils.js +38 -25
  238. package/out/service/formatTsUtils.js.map +1 -1
  239. package/out/service/genSlotVarRef.d.ts +3 -0
  240. package/out/service/genSlotVarRef.d.ts.map +1 -0
  241. package/out/service/genSlotVarRef.js +154 -0
  242. package/out/service/genSlotVarRef.js.map +1 -0
  243. package/out/service/getExtensionModules.d.ts.map +1 -1
  244. package/out/service/getExtensionModules.js +12 -0
  245. package/out/service/getExtensionModules.js.map +1 -1
  246. package/out/service/getLogics.d.ts.map +1 -1
  247. package/out/service/getLogics.js +24 -26
  248. package/out/service/getLogics.js.map +1 -1
  249. package/out/service/getMemberIdentifier.d.ts.map +1 -1
  250. package/out/service/getMemberIdentifier.js +104 -255
  251. package/out/service/getMemberIdentifier.js.map +1 -1
  252. package/out/service/getProcesses.d.ts.map +1 -1
  253. package/out/service/getProcesses.js +31 -29
  254. package/out/service/getProcesses.js.map +1 -1
  255. package/out/service/getProcessesV2.js +1 -1
  256. package/out/service/getProcessesV2.js.map +1 -1
  257. package/out/utils/traverse.d.ts +14 -2
  258. package/out/utils/traverse.d.ts.map +1 -1
  259. package/out/utils/traverse.js +28 -10
  260. package/out/utils/traverse.js.map +1 -1
  261. package/package.json +5 -5
@@ -37,6 +37,13 @@ exports.NewComposite = void 0;
37
37
  const utils_1 = require("../utils");
38
38
  const nasl_translator_1 = require("@lcap/nasl-translator");
39
39
  const quick_info_1 = require("./utils/quick-info");
40
+ var MatchingStrategies;
41
+ (function (MatchingStrategies) {
42
+ MatchingStrategies["BY_NAME"] = "BY_NAME";
43
+ MatchingStrategies["BY_TYPE"] = "BY_TYPE";
44
+ MatchingStrategies["BY_NAME_AND_TYPE"] = "BY_NAME_AND_TYPE";
45
+ MatchingStrategies["BY_TOP_DOWN"] = "BY_TOP_DOWN";
46
+ })(MatchingStrategies || (MatchingStrategies = {}));
40
47
  const decorators_1 = require("../decorators");
41
48
  const utils = __importStar(require("../utils"));
42
49
  const asserts = __importStar(require("./utils/asserts"));
@@ -85,6 +92,8 @@ let NewComposite = class NewComposite extends LogicItem__1.default {
85
92
  * 自动连线
86
93
  */
87
94
  this.autoConnection = true;
95
+ // 匹配策略
96
+ this.matchingStrategy = MatchingStrategies.BY_TOP_DOWN;
88
97
  super.subConstructor(source);
89
98
  }
90
99
  static from(source, parentNode, parentKey) {
@@ -384,11 +393,84 @@ let NewComposite = class NewComposite extends LogicItem__1.default {
384
393
  // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
385
394
  // 自动生成的代码已结束。下面可以手动编写。
386
395
  //================================================================================
396
+ /**
397
+ * 删除左边项
398
+ * @param property
399
+ */
400
+ deleteProperty(property) {
401
+ let index = -1;
402
+ const properties = this.properties.filter((p, i) => {
403
+ if (p === property) {
404
+ index = i;
405
+ return false;
406
+ }
407
+ return true;
408
+ });
409
+ const newLines = [];
410
+ this.assignmentLines.forEach((line) => {
411
+ const targetIndex = line?.leftIndex;
412
+ if (targetIndex[1] < index) {
413
+ newLines.push(line);
414
+ }
415
+ else if (targetIndex[1] > index) {
416
+ const newLine = {
417
+ ...line?.toJSON(),
418
+ leftIndex: [targetIndex[0], targetIndex[1] - 1],
419
+ };
420
+ newLines.push(newLine);
421
+ }
422
+ });
423
+ this.app.emit('collect:start', {
424
+ actionMsg: '删除左边项',
425
+ });
426
+ this.update({
427
+ properties,
428
+ assignmentLines: newLines,
429
+ });
430
+ this.app.emit('collect:end');
431
+ }
387
432
  get lines() {
388
433
  return this.assignmentLines.length;
389
434
  }
390
- newConnection(addRightIndex) {
435
+ checkConditions({ isAnnotation, leftName, rightName, leftTypeAnnotation, rightTypeAnnotation, }) {
436
+ // 条件数组
437
+ const conditions = [];
438
+ if ([
439
+ MatchingStrategies.BY_NAME,
440
+ MatchingStrategies.BY_NAME_AND_TYPE,
441
+ ].includes(this.matchingStrategy)) {
442
+ conditions.push(() => {
443
+ return leftName === rightName;
444
+ });
445
+ }
446
+ if ([
447
+ MatchingStrategies.BY_TYPE,
448
+ MatchingStrategies.BY_NAME_AND_TYPE,
449
+ ].includes(this.matchingStrategy)) {
450
+ conditions.push(() => {
451
+ return isAnnotation || rightTypeAnnotation?.sortedTypeKey === leftTypeAnnotation.sortedTypeKey;
452
+ });
453
+ }
454
+ if ([
455
+ MatchingStrategies.BY_TOP_DOWN,
456
+ ].includes(this.matchingStrategy)) {
457
+ conditions.push(() => {
458
+ return true;
459
+ });
460
+ }
461
+ return conditions.every(condition => condition());
462
+ }
463
+ /**
464
+ * 自动连线算法
465
+ * @param param0
466
+ */
467
+ batchAutoConnection({ targetRightIndex, reservedRightIndex, reservedLeftIndex, }) {
391
468
  const leftLineSet = new Set();
469
+ if (Array.isArray(reservedLeftIndex)) {
470
+ reservedLeftIndex.forEach((index) => {
471
+ leftLineSet.add(index);
472
+ });
473
+ }
392
474
  const lineArr = [];
393
475
  const AssignmentLine = (0, decorators_1.getConceptConstructor)('AssignmentLine');
394
476
  // 系统属性不可自动连线
@@ -399,75 +481,135 @@ let NewComposite = class NewComposite extends LogicItem__1.default {
399
481
  leftLineSet.add(Number(line.leftIndex[1]));
400
482
  });
401
483
  const autoConnection = () => {
402
- const isAnnotation = this.typeAnnotation.typeKind === 'anonymousStructure';
484
+ // 匿名数据结构
485
+ const isAnnotation = this.typeAnnotation?.typeKind === 'anonymousStructure';
403
486
  this.app.emit('collect:start', {
404
487
  actionMsg: '自动连线',
405
488
  });
406
- this.properties.forEach((property, leftSecondIndex) => {
407
- const leftName = property.name;
408
- const leftTypeAnnotation = !isAnnotation && property.__TypeAnnotation;
409
- if (leftLineSet.has(leftSecondIndex) || leftLineSet.has(leftName))
410
- return;
411
- this.rights.forEach((selectMember, rightFirstIndex) => {
412
- const { members, expression } = selectMember;
413
- if (leftLineSet.has(leftSecondIndex))
414
- return;
415
- if (![-1, null, undefined].includes(addRightIndex) && addRightIndex !== rightFirstIndex)
416
- return;
417
- // 右侧父节点也不允许自动连线
418
- const rightLineSet = new Set();
489
+ // 目标右侧
490
+ const targetRights = [-1, null, undefined].includes(targetRightIndex) ? this.rights.map((right, index) => {
491
+ return {
492
+ right,
493
+ index,
494
+ };
495
+ }) : [
496
+ {
497
+ right: this.rights?.[targetRightIndex],
498
+ index: targetRightIndex,
499
+ },
500
+ ];
501
+ // 右侧父节点也不允许自动连线
502
+ const rightLineSet = new Set();
503
+ if (Array.isArray(reservedRightIndex) && reservedRightIndex.length) {
504
+ reservedRightIndex.forEach((rightIndex) => {
505
+ rightLineSet.add(rightIndex);
506
+ });
507
+ }
508
+ if (targetRights) {
509
+ targetRights.forEach(({ right: targetRight, index, }) => {
510
+ const { members } = targetRight;
419
511
  for (let i = 0; i < members.length - 1; i++) {
420
512
  const { completeName } = members[i];
421
513
  const preCompleteName = members[i + 1].completeName;
422
514
  if (preCompleteName.includes(completeName) &&
423
- completeName.split('.').length !== preCompleteName.split('.').length)
424
- rightLineSet.add(i);
515
+ completeName.split('.').length !== preCompleteName.split('.').length) {
516
+ rightLineSet.add(`${index}_${i}`);
517
+ }
518
+ }
519
+ });
520
+ }
521
+ this.assignmentLines.forEach((assignmentLine) => {
522
+ const { rightIndex } = assignmentLine;
523
+ if (rightIndex.length === 1) {
524
+ rightLineSet.add(`${rightIndex?.[0]}`);
525
+ }
526
+ else if (rightIndex.length === 2) {
527
+ const [firstIndex, secondIndex] = rightIndex || [];
528
+ rightLineSet.add(`${firstIndex}_${secondIndex}`);
529
+ }
530
+ });
531
+ this.properties.forEach((property, leftSecondIndex) => {
532
+ const leftName = property.name;
533
+ const leftTypeAnnotation = !isAnnotation && property.__TypeAnnotation;
534
+ targetRights.forEach(({ right: targetRight, index: rightFirstIndex, }) => {
535
+ // 已经有连线的不需要自动连线
536
+ if (leftLineSet.has(leftSecondIndex) || leftLineSet.has(leftName)) {
537
+ return;
425
538
  }
426
- if (leftName === expression.name &&
427
- (isAnnotation || expression.__TypeAnnotation.typeKind === leftTypeAnnotation.typeKind)) {
539
+ const { members, expression } = targetRight;
540
+ if (members?.length) {
541
+ members.forEach((rightMember, rightSecondIndex) => {
542
+ // 已经有连线的不需要自动连线
543
+ if (leftLineSet.has(leftSecondIndex) || leftLineSet.has(leftName)) {
544
+ return;
545
+ }
546
+ if (rightLineSet.has(`${rightFirstIndex}_${rightSecondIndex}`)) {
547
+ return;
548
+ }
549
+ const rightName = rightMember?.property.name;
550
+ if (this.checkConditions({
551
+ isAnnotation,
552
+ leftName,
553
+ rightName,
554
+ leftTypeAnnotation,
555
+ rightTypeAnnotation: rightMember.__TypeAnnotation,
556
+ })) {
557
+ const leftIndex = [0, leftSecondIndex];
558
+ const rightIndex = [rightFirstIndex, rightSecondIndex];
559
+ const Line = new AssignmentLine({ leftIndex, rightIndex });
560
+ lineArr.push(Line);
561
+ leftLineSet.add(leftSecondIndex);
562
+ rightLineSet.add(`${rightFirstIndex}_${rightSecondIndex}`);
563
+ }
564
+ });
565
+ }
566
+ else if (this.checkConditions({
567
+ isAnnotation,
568
+ leftName,
569
+ rightName: expression.name,
570
+ leftTypeAnnotation,
571
+ rightTypeAnnotation: expression.__TypeAnnotation,
572
+ })) {
573
+ if (rightLineSet.has(`${rightFirstIndex}`)) {
574
+ return;
575
+ }
428
576
  const Line = new AssignmentLine({
429
577
  leftIndex: [0, leftSecondIndex],
430
578
  rightIndex: [rightFirstIndex],
431
579
  });
432
580
  lineArr.push(Line);
433
581
  leftLineSet.add(leftSecondIndex);
434
- return;
582
+ rightLineSet.add(`${rightFirstIndex}`);
435
583
  }
436
- members.forEach((rightMember, rightSecondIndex) => {
437
- const rightName = rightMember.property.name;
438
- if (rightLineSet.has(rightSecondIndex) || leftLineSet.has(leftSecondIndex))
439
- return;
440
- if (leftName === rightName) {
441
- const rightTypeAnnotation = rightMember.__TypeAnnotation;
442
- if (!isAnnotation && leftTypeAnnotation.typeName !== rightTypeAnnotation.typeName)
443
- return;
444
- const leftIndex = [0, leftSecondIndex];
445
- const rightIndex = [rightFirstIndex, rightSecondIndex];
446
- const Line = new AssignmentLine({ leftIndex, rightIndex });
447
- lineArr.push(Line);
448
- leftLineSet.add(leftSecondIndex);
449
- }
450
- });
451
584
  });
452
585
  });
453
586
  lineArr.length && this.setAssignmentLines([...this.assignmentLines, ...lineArr]);
454
587
  this.app.emit('collect:end');
455
588
  };
456
- let count = 0;
457
- const typeAnnotationEnd = () => {
458
- const l = this.properties.every((item) => item.__isCorrectTypeAnnotation);
459
- const r = this.rights.every((right) => right.members.every((item) => item.__isCorrectTypeAnnotation) && right.expression.__isCorrectTypeAnnotation);
460
- count++;
461
- if (r && l) {
462
- autoConnection();
463
- }
464
- else if (count <= 10) {
465
- setTimeout(() => {
466
- typeAnnotationEnd();
467
- }, 100);
468
- }
469
- };
470
- typeAnnotationEnd();
589
+ // 跟类型相关的才需要等待
590
+ if ([
591
+ MatchingStrategies.BY_TYPE,
592
+ MatchingStrategies.BY_NAME_AND_TYPE,
593
+ ].includes(this.matchingStrategy)) {
594
+ let count = 0;
595
+ const typeAnnotationEnd = () => {
596
+ const l = this.properties.every((item) => item.__isCorrectTypeAnnotation);
597
+ const r = this.rights.every((right) => right.members.every((item) => item.__isCorrectTypeAnnotation) && right.expression.__isCorrectTypeAnnotation);
598
+ count++;
599
+ if (r && l) {
600
+ autoConnection();
601
+ }
602
+ else if (count <= 10) {
603
+ setTimeout(() => {
604
+ typeAnnotationEnd();
605
+ }, 100);
606
+ }
607
+ };
608
+ typeAnnotationEnd();
609
+ }
610
+ else {
611
+ autoConnection();
612
+ }
471
613
  }
472
614
  connection(leftItem, rightItem, rightToLeft) {
473
615
  let newLeftIndex = [0];
@@ -543,14 +685,207 @@ let NewComposite = class NewComposite extends LogicItem__1.default {
543
685
  });
544
686
  }
545
687
  }
546
- changeMembers(oldNode, members, keepMembers, expression) {
688
+ // 替换变量
689
+ async replaceIdentifier(oldNode, expression, members) {
690
+ // 关闭定时
691
+ this.app._noTimer = true;
692
+ this.app.emit('collect:start', {
693
+ actionMsg: '替换变量',
694
+ });
695
+ // 被替换的第一层属性
696
+ const oldSelectMember = oldNode.parentNode;
697
+ const firstRightIndex = this.rights.findIndex((right) => {
698
+ return oldSelectMember === right;
699
+ });
700
+ const newSelectMember = {
701
+ ...(oldSelectMember?.toJSON?.() ?? oldSelectMember),
702
+ expression,
703
+ members: [],
704
+ };
705
+ // 待定的连线(保留的属性的连线也要保留)
706
+ const pendingLinesMap = new Map();
707
+ const newLines = this.assignmentLines.filter((line) => {
708
+ const { rightIndex } = line;
709
+ const [first, second] = rightIndex || [];
710
+ if (rightIndex.length === 2 && first === firstRightIndex) {
711
+ if (!pendingLinesMap.get(second)) {
712
+ pendingLinesMap.set(second, []);
713
+ }
714
+ const lines = pendingLinesMap.get(second);
715
+ lines.push(line);
716
+ return false;
717
+ }
718
+ return true;
719
+ });
720
+ // 先用变量替换右侧的属性
721
+ this.update({
722
+ assignmentLines: newLines,
723
+ rights: [
724
+ ...this.rights.slice(0, firstRightIndex),
725
+ newSelectMember,
726
+ ...this.rights.slice(firstRightIndex + 1, this.rights.length),
727
+ ],
728
+ });
729
+ // 触发ts类型标注
730
+ this.app.naslServer?.embeddedTSEmitter.emit('change', {
731
+ value: [
732
+ {
733
+ originEvent: {
734
+ action: 'update',
735
+ target: this,
736
+ },
737
+ },
738
+ ],
739
+ });
740
+ const memberInfoMap = new Map();
741
+ // 获取拖入表达式的类型
742
+ const currTypeAnnotation = await newSelectMember.expression?.getCurrentTypeAnnotation(30000);
743
+ // 当前类型下的所有属性(递归)
744
+ const propertyMap = currTypeAnnotation?.collectPropertyMap?.(this.app);
745
+ if (propertyMap) {
746
+ oldSelectMember?.members.forEach((member, index) => {
747
+ // 完整属性名
748
+ const oldCompletePropertyName = member.completePropertyName;
749
+ const { typeAnnotation, __TypeAnnotation } = member || {};
750
+ // 属性类型
751
+ const memberTypeAnnotation = typeAnnotation || __TypeAnnotation;
752
+ if (propertyMap.get(oldCompletePropertyName)?.typeKey === memberTypeAnnotation?.typeKey) {
753
+ memberInfoMap.set(oldCompletePropertyName, {
754
+ orginIndex: index,
755
+ member,
756
+ });
757
+ }
758
+ });
759
+ }
760
+ members.forEach((member) => {
761
+ const { completePropertyName } = member || {};
762
+ if (!memberInfoMap.has(completePropertyName)) {
763
+ memberInfoMap.set(completePropertyName, {
764
+ orginIndex: -1,
765
+ member,
766
+ });
767
+ }
768
+ });
769
+ const memberInfos = [...memberInfoMap.values()];
770
+ if (propertyMap) {
771
+ memberInfos.sort((member1, member2) => {
772
+ return propertyMap.get(member1?.member?.completePropertyName)?.index - propertyMap.get(member2?.member?.completePropertyName)?.index;
773
+ });
774
+ }
775
+ // 保留的属性
776
+ const reservedRightIndex = [];
777
+ memberInfos.forEach(({ orginIndex, }, index) => {
778
+ if (orginIndex !== -1) {
779
+ reservedRightIndex.push(`${firstRightIndex}_${index}`);
780
+ const pendingLines = pendingLinesMap.get(orginIndex);
781
+ if (Array.isArray(pendingLines)) {
782
+ pendingLines.forEach((pendingLine) => {
783
+ const newLine = {
784
+ ...(pendingLine?.toJSON?.() ?? pendingLine),
785
+ rightIndex: [pendingLine.rightIndex[0], index],
786
+ };
787
+ newLines.push(newLine);
788
+ });
789
+ }
790
+ }
791
+ });
792
+ const right = this.rights[firstRightIndex];
793
+ const MemberExpression = (0, decorators_1.getConceptConstructor)('MemberExpression');
794
+ right.update({
795
+ members: memberInfos.map(({ member, }) => {
796
+ return new MemberExpression({
797
+ ...(member?.firstMemberExpressionNode?.()?.toJSON() || {}),
798
+ object: expression?.toJSON(),
799
+ });
800
+ }),
801
+ });
802
+ // 更新属性和连线
803
+ this.update({
804
+ assignmentLines: newLines,
805
+ });
806
+ this.autoConnection && this.batchAutoConnection({
807
+ targetRightIndex: firstRightIndex,
808
+ reservedRightIndex,
809
+ });
810
+ this.app.emit('collect:end');
811
+ }
812
+ changeLeft({ typeAnnotation, batchExpression, }) {
813
+ const properties = [];
814
+ // 新的实体/数据结构下,与原实体/数据结构的属性一致时,保持原有连线状态; -一致即名称和类型均一致
815
+ const newLines = [];
816
+ const reservedLeftIndex = [];
817
+ let autoConnection = this.autoConnection;
818
+ if (typeAnnotation) {
819
+ const propertyMap = typeAnnotation.collectPropertyMap(this.app);
820
+ batchExpression.sort((a, b) => {
821
+ return (propertyMap.get(a.completeName)?.index - propertyMap.get(b.completeName)?.index);
822
+ });
823
+ // 之前的结构属性
824
+ const keepPropertyMap = new Map();
825
+ this.properties.forEach((property) => {
826
+ const typeAnnotation = property?.__TypeAnnotation || property?.typeAnnotation;
827
+ const lines = this.findlines(property, this);
828
+ keepPropertyMap.set(property?.completeName, {
829
+ property,
830
+ lines,
831
+ sortedTypeKey: typeAnnotation?.sortedTypeKey,
832
+ });
833
+ });
834
+ // 需要清除引用,否则nodePath会引用到旧的member节点
835
+ batchExpression.map(({ expression }, index) => {
836
+ const Identifier = (0, decorators_1.getConceptConstructor)('Identifier');
837
+ const ident = new Identifier({
838
+ name: expression.name,
839
+ });
840
+ properties.push(ident);
841
+ const oldPropertyInfo = keepPropertyMap.get(expression.name);
842
+ if (oldPropertyInfo) {
843
+ reservedLeftIndex.push(index);
844
+ const { lines } = oldPropertyInfo || {};
845
+ lines.forEach((line) => {
846
+ const newLine = {
847
+ ...line?.toJSON(),
848
+ leftIndex: [line.leftIndex[0], index],
849
+ };
850
+ newLines.push(newLine);
851
+ });
852
+ }
853
+ });
854
+ }
855
+ else {
856
+ autoConnection = false;
857
+ }
858
+ this.update({
859
+ typeAnnotation,
860
+ properties,
861
+ assignmentLines: newLines,
862
+ });
863
+ autoConnection && this.batchAutoConnection({
864
+ targetRightIndex: -1,
865
+ reservedLeftIndex,
866
+ });
867
+ }
868
+ async changeMembers(oldNode, members, expression) {
869
+ // 关闭定时
870
+ this.app._noTimer = true;
547
871
  this.app.emit('collect:start', {
548
872
  actionMsg: 'New初始赋值修改变量',
549
873
  });
550
- const selectMember = oldNode.parentNode;
551
- const autoConnectionIndex = this.rights.findIndex((right) => right === selectMember);
552
- const newSelectMember = { ...(selectMember?.toJSON?.() ?? selectMember), expression, members };
553
- const splitIndex = this.rights.findIndex((right) => selectMember === right);
874
+ const oldSelectMember = oldNode.parentNode;
875
+ // 之前的结构属性
876
+ const keepPropertyMap = new Map();
877
+ oldSelectMember.members.forEach((member) => {
878
+ if (asserts.isMemberExpression(member)) {
879
+ const typeAnnotation = member?.__TypeAnnotation || member?.typeAnnotation;
880
+ const lines = this.findlines(member, oldSelectMember);
881
+ keepPropertyMap.set(member?.completePropertyName, {
882
+ member,
883
+ lines,
884
+ sortedTypeKey: typeAnnotation?.sortedTypeKey,
885
+ });
886
+ }
887
+ });
888
+ const targetRightIndex = this.rights.findIndex((right) => right === oldSelectMember);
554
889
  let keepLines = false;
555
890
  if (this?.concept === 'NewComposite' &&
556
891
  this?.typeAnnotation?.typeKind === 'anonymousStructure' &&
@@ -559,28 +894,85 @@ let NewComposite = class NewComposite extends LogicItem__1.default {
559
894
  if (tempNode && tempNode?.calleeName === 'ListSort')
560
895
  keepLines = true;
561
896
  }
562
- const newLines = keepLines ? this.assignmentLines : this.assignmentLines.filter(({ rightIndex }) => rightIndex[0] !== splitIndex);
563
- let oldLines = this.assignmentLines.filter(({ rightIndex }) => rightIndex[0] === splitIndex);
897
+ const newLines = keepLines ? this.assignmentLines : this.assignmentLines.filter(({ rightIndex, }) => {
898
+ return (rightIndex[0] !== targetRightIndex) || (rightIndex?.length === 1);
899
+ });
900
+ this.update({
901
+ assignmentLines: newLines,
902
+ rights: [
903
+ ...this.rights.slice(0, targetRightIndex),
904
+ {
905
+ ...(oldSelectMember?.toJSON?.() ?? oldSelectMember),
906
+ expression,
907
+ members,
908
+ },
909
+ ...this.rights.slice(targetRightIndex + 1, this.rights.length),
910
+ ],
911
+ });
912
+ // 触发ts类型标注
913
+ this.app.naslServer?.embeddedTSEmitter.emit('change', {
914
+ value: [
915
+ {
916
+ originEvent: {
917
+ action: 'update',
918
+ target: this,
919
+ },
920
+ },
921
+ ],
922
+ });
923
+ // 表达式的类型
924
+ await expression?.getCurrentTypeAnnotation(30000);
925
+ const propertyMap = new Map();
926
+ if (asserts.isIdentifier(expression)) {
927
+ const { namespace, name } = expression;
928
+ const completeList = [];
929
+ if (namespace) {
930
+ completeList.push(namespace);
931
+ }
932
+ completeList.push(name);
933
+ const completeName = completeList.join('.');
934
+ const count = propertyMap.size;
935
+ // 获取类型注解并提取其结构
936
+ const typeAnnotation = expression?.__TypeAnnotation || expression?.typeAnnotation;
937
+ // 将完整属性名添加到属性映射表中
938
+ propertyMap.set(completeName, {
939
+ index: count,
940
+ typeKey: typeAnnotation?.typeKey,
941
+ });
942
+ let depth = 0;
943
+ typeAnnotation?.collectPropertyMap(this.app, completeName, propertyMap, depth);
944
+ }
945
+ if (propertyMap.size) {
946
+ members.sort((a, b) => {
947
+ return (propertyMap.get(a.completeName)?.index - propertyMap.get(b.completeName)?.index);
948
+ });
949
+ }
950
+ const reservedRightIndex = [];
564
951
  // 右侧变量改变后,修改连线
565
952
  members.forEach((item, index) => {
566
- if (keepMembers?.has(item.completeName)) {
567
- const lines = this.findlines(item, selectMember);
953
+ const oldPropertyInfo = keepPropertyMap.get(item?.completePropertyName);
954
+ const { sortedTypeKey } = oldPropertyInfo || {};
955
+ const typeAnnotation = item?.__TypeAnnotation || item?.typeAnnotation;
956
+ if (sortedTypeKey === typeAnnotation?.sortedTypeKey) {
957
+ reservedRightIndex.push(`${targetRightIndex}_${index}`);
958
+ const { lines } = oldPropertyInfo || {};
568
959
  lines.forEach((line) => {
569
- const newLine = { ...(line?.toJSON?.() ?? line), rightIndex: [line.rightIndex[0], index] };
960
+ const newLine = { ...line?.toJSON(), rightIndex: [line.rightIndex[0], index] };
570
961
  newLines.push(newLine);
571
- oldLines = oldLines.filter(({ leftIndex }) => leftIndex[1] !== line.leftIndex[1]);
572
962
  });
573
963
  }
574
964
  });
965
+ const newSelectMember = this.rights.find((right, index) => index === targetRightIndex);
966
+ newSelectMember.update({
967
+ members,
968
+ });
575
969
  this.update({
576
970
  assignmentLines: newLines,
577
- rights: [
578
- ...this.rights.slice(0, splitIndex),
579
- newSelectMember,
580
- ...this.rights.slice(splitIndex + 1, this.rights.length),
581
- ],
582
971
  });
583
- this.autoConnection && this.newConnection(autoConnectionIndex);
972
+ this.autoConnection && this.batchAutoConnection({
973
+ targetRightIndex,
974
+ reservedRightIndex,
975
+ });
584
976
  this.app.emit('collect:end');
585
977
  }
586
978
  findlines(member, selectMember) {
@@ -1187,12 +1579,18 @@ let NewComposite = class NewComposite extends LogicItem__1.default {
1187
1579
  this.app.emit('collect:start', {
1188
1580
  actionMsg: '添加匿名数据结构属性',
1189
1581
  });
1582
+ const reservedLeftIndex = Array.from({
1583
+ length: this.properties.length,
1584
+ }, (v, i) => i);
1190
1585
  const node = this.addIdentifier({ name: this.getIdentifierUniqueName(newName) });
1191
1586
  const struct = StructureProperty.from({
1192
1587
  name: node.name,
1193
1588
  typeAnnotation: newType,
1194
1589
  });
1195
1590
  this.typeAnnotation.addStructureProperty(struct);
1591
+ this.autoConnection && this.batchAutoConnection({
1592
+ reservedLeftIndex,
1593
+ });
1196
1594
  this.app.emit('collect:end');
1197
1595
  }
1198
1596
  __deleteIdentifier(property) {