@lcap/nasl 2.13.0 → 2.13.1-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 (114) hide show
  1. package/out/concepts/CompletionProperty__.d.ts +0 -1
  2. package/out/concepts/CompletionProperty__.js +0 -1
  3. package/out/concepts/CompletionProperty__.js.map +1 -1
  4. package/out/concepts/InterfaceParam__.js +6 -3
  5. package/out/concepts/InterfaceParam__.js.map +1 -1
  6. package/out/concepts/Param__.js +6 -3
  7. package/out/concepts/Param__.js.map +1 -1
  8. package/out/concepts/Return__.js +6 -3
  9. package/out/concepts/Return__.js.map +1 -1
  10. package/out/concepts/TypeAnnotation__.js +3 -14
  11. package/out/concepts/TypeAnnotation__.js.map +1 -1
  12. package/out/concepts/Unparsed__.js +3 -3
  13. package/out/concepts/Unparsed__.js.map +1 -1
  14. package/out/concepts/Variable__.js +6 -3
  15. package/out/concepts/Variable__.js.map +1 -1
  16. package/out/concepts/basics/stdlib/nasl.collection.js +12 -0
  17. package/out/concepts/basics/stdlib/nasl.collection.js.map +1 -1
  18. package/out/concepts/basics/stdlib/nasl.util.js +187 -5
  19. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  20. package/out/concepts/basics/stdlib/reference2TypeAnnotationList.js +1 -1
  21. package/out/concepts/basics/stdlib/reference2TypeAnnotationList.js.map +1 -1
  22. package/out/enums/KEYWORDS.d.ts +1 -0
  23. package/out/enums/KEYWORDS.js +16 -1
  24. package/out/enums/KEYWORDS.js.map +1 -1
  25. package/out/generator/genBundleFiles.js +25 -1
  26. package/out/generator/genBundleFiles.js.map +1 -1
  27. package/out/server/createUiTs.js +12 -12
  28. package/out/server/createUiTs.js.map +1 -1
  29. package/out/server/formatTsUtils.d.ts +21 -0
  30. package/out/server/formatTsUtils.js +323 -0
  31. package/out/server/formatTsUtils.js.map +1 -0
  32. package/out/server/getLogics.js +18 -17
  33. package/out/server/getLogics.js.map +1 -1
  34. package/out/server/getMemberIdentifier.d.ts +1 -12
  35. package/out/server/getMemberIdentifier.js +11 -264
  36. package/out/server/getMemberIdentifier.js.map +1 -1
  37. package/out/server/getProcesses.js +9 -18
  38. package/out/server/getProcesses.js.map +1 -1
  39. package/out/server/naslServer.js +7 -4
  40. package/out/server/naslServer.js.map +1 -1
  41. package/out/server/stdlib/nasl.annotation.d.ts +4 -0
  42. package/out/server/stdlib/nasl.annotation.js +1 -0
  43. package/out/server/stdlib/nasl.annotation.js.map +1 -0
  44. package/out/server/stdlib/nasl.auth.d.ts +30 -0
  45. package/out/server/stdlib/nasl.auth.js +1 -0
  46. package/out/server/stdlib/nasl.auth.js.map +1 -0
  47. package/out/server/stdlib/nasl.browser.d.ts +5 -0
  48. package/out/server/stdlib/nasl.browser.js +1 -0
  49. package/out/server/stdlib/nasl.browser.js.map +1 -0
  50. package/out/server/stdlib/nasl.collection.d.ts +22 -0
  51. package/out/server/stdlib/nasl.collection.js +1 -0
  52. package/out/server/stdlib/nasl.collection.js.map +1 -0
  53. package/out/server/stdlib/nasl.configuration.d.ts +3 -0
  54. package/out/server/stdlib/nasl.configuration.js +1 -0
  55. package/out/server/stdlib/nasl.configuration.js.map +1 -0
  56. package/out/server/stdlib/nasl.core.d.ts +104 -0
  57. package/out/server/stdlib/nasl.core.js +1 -0
  58. package/out/server/stdlib/nasl.core.js.map +1 -0
  59. package/out/server/stdlib/nasl.interface.d.ts +7 -0
  60. package/out/server/stdlib/nasl.interface.js +1 -0
  61. package/out/server/stdlib/nasl.interface.js.map +1 -0
  62. package/out/server/stdlib/nasl.langUtil.d.ts +28 -0
  63. package/out/server/stdlib/nasl.langUtil.js +1 -0
  64. package/out/server/stdlib/nasl.langUtil.js.map +1 -0
  65. package/out/server/stdlib/nasl.process.d.ts +50 -0
  66. package/out/server/stdlib/nasl.process.js +1 -0
  67. package/out/server/stdlib/nasl.process.js.map +1 -0
  68. package/out/server/stdlib/nasl.ui.d.ts +186 -0
  69. package/out/server/stdlib/nasl.ui.definition.d.ts +1072 -0
  70. package/out/server/stdlib/nasl.ui.definition.js +632 -0
  71. package/out/server/stdlib/nasl.ui.definition.js.map +1 -0
  72. package/out/server/stdlib/nasl.ui.js +1 -0
  73. package/out/server/stdlib/nasl.ui.js.map +1 -0
  74. package/out/server/stdlib/nasl.util.d.ts +74 -0
  75. package/out/server/stdlib/nasl.util.js +4 -0
  76. package/out/server/stdlib/nasl.util.js.map +1 -0
  77. package/out/server/stdlib/nasl.validation.d.ts +32 -0
  78. package/out/server/stdlib/nasl.validation.js +1 -0
  79. package/out/server/stdlib/nasl.validation.js.map +1 -0
  80. package/out/templator/genQueryComponent.js +8 -8
  81. package/out/templator/genQueryComponent.js.map +1 -1
  82. package/package.json +1 -1
  83. package/src/concepts/CompletionProperty__.ts +0 -1
  84. package/src/concepts/InterfaceParam__.ts +6 -3
  85. package/src/concepts/Param__.ts +5 -3
  86. package/src/concepts/Return__.ts +5 -3
  87. package/src/concepts/TypeAnnotation__.ts +3 -30
  88. package/src/concepts/Unparsed__.ts +3 -10
  89. package/src/concepts/Variable__.ts +5 -3
  90. package/src/concepts/basics/stdlib/nasl.collection.ts +12 -0
  91. package/src/concepts/basics/stdlib/nasl.util.ts +187 -5
  92. package/src/concepts/basics/stdlib/reference2TypeAnnotationList.ts +1 -1
  93. package/src/enums/KEYWORDS.ts +16 -0
  94. package/src/generator/genBundleFiles.ts +24 -1
  95. package/src/server/createUiTs.ts +12 -12
  96. package/src/server/formatTsUtils.ts +319 -0
  97. package/src/server/getLogics.ts +18 -17
  98. package/src/server/getMemberIdentifier.ts +10 -264
  99. package/src/server/getProcesses.ts +10 -19
  100. package/src/server/naslServer.ts +6 -3
  101. package/src/server/stdlib/nasl.annotation.ts +4 -0
  102. package/src/server/stdlib/nasl.auth.ts +31 -0
  103. package/src/server/stdlib/nasl.browser.ts +5 -0
  104. package/src/server/stdlib/nasl.collection.ts +22 -0
  105. package/src/server/stdlib/nasl.configuration.ts +3 -0
  106. package/src/server/stdlib/nasl.core.ts +128 -0
  107. package/src/server/stdlib/nasl.interface.ts +7 -0
  108. package/src/server/stdlib/nasl.langUtil.ts +31 -0
  109. package/src/server/stdlib/nasl.process.ts +87 -0
  110. package/src/server/stdlib/nasl.ui.definition.ts +1760 -0
  111. package/src/server/stdlib/nasl.ui.ts +189 -0
  112. package/src/server/stdlib/nasl.util.ts +84 -0
  113. package/src/server/stdlib/nasl.validation.ts +33 -0
  114. package/src/templator/genQueryComponent.ts +8 -8
@@ -221,7 +221,7 @@ export default new Namespace({
221
221
  typeAnnotation: TypeAnnotation.createPrimitive('String'),
222
222
  }),
223
223
  new Param({
224
- name: 'seperator',
224
+ name: 'separator',
225
225
  typeAnnotation: TypeAnnotation.createPrimitive('String'),
226
226
  }),
227
227
  ],
@@ -244,7 +244,7 @@ export default new Namespace({
244
244
  }),
245
245
  }),
246
246
  new Param({
247
- name: 'seperator',
247
+ name: 'separator',
248
248
  typeAnnotation: TypeAnnotation.createPrimitive('String'),
249
249
  }),
250
250
  ],
@@ -275,10 +275,10 @@ export default new Namespace({
275
275
  }),
276
276
  new Function({
277
277
  name: 'Length',
278
- description: '返回字符串长度',
278
+ description: '获得String、Map、List的长度',
279
279
  params: [
280
280
  new Param({
281
- name: 'str1',
281
+ name: 'param',
282
282
  typeAnnotation: TypeAnnotation.createPrimitive('String'),
283
283
  }),
284
284
  ],
@@ -427,7 +427,7 @@ export default new Namespace({
427
427
  }),
428
428
  }),
429
429
  new Param({
430
- name: 'addlist',
430
+ name: 'addList',
431
431
  typeAnnotation: TypeAnnotation.createGeneric('List', {
432
432
  typeArguments: [TypeAnnotation.createTypeParam('T')],
433
433
  }),
@@ -496,6 +496,188 @@ export default new Namespace({
496
496
  }),
497
497
  ],
498
498
  }),
499
+ new Function({
500
+ name: 'MapGet',
501
+ description: '查询出Map中key为指定值的value值列表',
502
+ params: [
503
+ new Param({
504
+ name: 'map',
505
+ typeAnnotation: TypeAnnotation.createGeneric('map', {
506
+ typeArguments: [
507
+ TypeAnnotation.createTypeParam('K'),
508
+ TypeAnnotation.createTypeParam('V'),
509
+ ],
510
+ }),
511
+ }),
512
+ new Param({
513
+ name: 'key',
514
+ typeAnnotation: TypeAnnotation.createTypeParam('K'),
515
+ }),
516
+ ],
517
+ returns: [
518
+ new Return({
519
+ typeAnnotation: TypeAnnotation.createTypeParam('V'),
520
+ }),
521
+ ],
522
+ }),
523
+ new Function({
524
+ name: 'MapPut',
525
+ description: '为Map中添加键值对',
526
+ params: [
527
+ new Param({
528
+ name: 'map',
529
+ typeAnnotation: TypeAnnotation.createGeneric('map', {
530
+ typeArguments: [
531
+ TypeAnnotation.createTypeParam('K'),
532
+ TypeAnnotation.createTypeParam('V'),
533
+ ],
534
+ }),
535
+ }),
536
+ new Param({
537
+ name: 'key',
538
+ typeAnnotation: TypeAnnotation.createTypeParam('K'),
539
+ }),
540
+ new Param({
541
+ name: 'value',
542
+ typeAnnotation: TypeAnnotation.createTypeParam('V'),
543
+ }),
544
+ ],
545
+ }),
546
+ new Function({
547
+ name: 'MapRemove',
548
+ description: '删除Map中的键值对',
549
+ params: [
550
+ new Param({
551
+ name: 'map',
552
+ typeAnnotation: TypeAnnotation.createGeneric('map', {
553
+ typeArguments: [
554
+ TypeAnnotation.createTypeParam('K'),
555
+ TypeAnnotation.createTypeParam('V'),
556
+ ],
557
+ }),
558
+ }),
559
+ new Param({
560
+ name: 'key',
561
+ typeAnnotation: TypeAnnotation.createTypeParam('K'),
562
+ }),
563
+ ],
564
+ }),
565
+ new Function({
566
+ name: 'MapContains',
567
+ description: '指定Map中是否存在参数key的键值对',
568
+ params: [
569
+ new Param({
570
+ name: 'map',
571
+ typeAnnotation: TypeAnnotation.createGeneric('map', {
572
+ typeArguments: [
573
+ TypeAnnotation.createTypeParam('K'),
574
+ TypeAnnotation.createTypeParam('V'),
575
+ ],
576
+ }),
577
+ }),
578
+ new Param({
579
+ name: 'key',
580
+ typeAnnotation: TypeAnnotation.createTypeParam('K'),
581
+ }),
582
+ ],
583
+ returns: [
584
+ new Return({
585
+ typeAnnotation: TypeAnnotation.createTypeParam('Boolean'),
586
+ }),
587
+ ],
588
+ }),
589
+ new Function({
590
+ name: 'MapKeys',
591
+ description: '输出Map中key集合',
592
+ params: [
593
+ new Param({
594
+ name: 'map',
595
+ typeAnnotation: TypeAnnotation.createGeneric('map', {
596
+ typeArguments: [
597
+ TypeAnnotation.createTypeParam('K'),
598
+ TypeAnnotation.createTypeParam('V'),
599
+ ],
600
+ }),
601
+ }),
602
+ ],
603
+ returns: [
604
+ new Return({
605
+ typeAnnotation: TypeAnnotation.createGeneric('List', {
606
+ typeArguments: [TypeAnnotation.createTypeParam('K')],
607
+ }),
608
+ }),
609
+ ],
610
+ }),
611
+ new Function({
612
+ name: 'MapValues',
613
+ description: '输出Map中value集合',
614
+ params: [
615
+ new Param({
616
+ name: 'map',
617
+ typeAnnotation: TypeAnnotation.createGeneric('map', {
618
+ typeArguments: [
619
+ TypeAnnotation.createTypeParam('K'),
620
+ TypeAnnotation.createTypeParam('V'),
621
+ ],
622
+ }),
623
+ }),
624
+ ],
625
+ returns: [
626
+ new Return({
627
+ typeAnnotation: TypeAnnotation.createGeneric('List', {
628
+ typeArguments: [TypeAnnotation.createTypeParam('V')],
629
+ }),
630
+ }),
631
+ ],
632
+ }),
633
+ new Function({
634
+ name: 'MapFilter',
635
+ description: '在指定Map中过滤出符合条件参数的Map集合',
636
+ params: [
637
+ new Param({
638
+ name: 'map',
639
+ typeAnnotation: TypeAnnotation.createGeneric('map', {
640
+ typeArguments: [
641
+ TypeAnnotation.createTypeParam('K'),
642
+ TypeAnnotation.createTypeParam('V'),
643
+ ],
644
+ }),
645
+ }),
646
+ new Param({
647
+ name: 'byKey',
648
+ defaultExpression: new Function({
649
+ name: 'byKey',
650
+ description: '',
651
+ params: [
652
+ new Param({
653
+ name: 'key',
654
+ typeAnnotation: null,
655
+ }),
656
+ ],
657
+ }),
658
+ }),
659
+ new Param({
660
+ name: 'byValue',
661
+ defaultExpression: new Function({
662
+ name: 'byValue',
663
+ description: '',
664
+ params: [
665
+ new Param({
666
+ name: 'value',
667
+ typeAnnotation: null,
668
+ }),
669
+ ],
670
+ }),
671
+ }),
672
+ ],
673
+ returns: [
674
+ new Return({
675
+ typeAnnotation: TypeAnnotation.createGeneric('List', {
676
+ typeArguments: [TypeAnnotation.createTypeParam('K')],
677
+ }),
678
+ }),
679
+ ],
680
+ }),
499
681
  new Function({
500
682
  name: 'CurrDate',
501
683
  description: '返回当前日期',
@@ -15,7 +15,7 @@ export function reference2TypeAnnotationList(list: Array<Entity | Structure | En
15
15
  return TypeAnnotation.createReference(item.name, {
16
16
  typeKind: 'generic',
17
17
  typeNamespace: namespace,
18
- typeArguments: item.typeParams.map((typeParam) => new TypeAnnotation()),
18
+ typeArguments: item.typeParams.map((typeParam) => new TypeAnnotation({ name: typeParam.name })),
19
19
  });
20
20
  } else {
21
21
  return TypeAnnotation.createReference(item.name, {
@@ -1198,3 +1198,19 @@ export const ENTITY_PROPERTY_KEYWORDS = [
1198
1198
  'STATIC',
1199
1199
  'YIELD',
1200
1200
  ];
1201
+
1202
+ export const USER_CUSTOM_KEYWORDS = [
1203
+ 'annotation',
1204
+ 'app',
1205
+ 'component',
1206
+ 'components',
1207
+ 'config',
1208
+ 'configuration',
1209
+ 'dataSource',
1210
+ 'element',
1211
+ 'elements',
1212
+ 'function',
1213
+ 'match',
1214
+ 'operator',
1215
+ 'system',
1216
+ ];
@@ -132,6 +132,29 @@ export async function genBundleFiles(app: App,
132
132
  if (view.isIndex) {
133
133
  indexName = view.name;
134
134
  }
135
+ function getAuth(data: View) {
136
+ if (!data) return
137
+ let res:any = {};
138
+ if( data.children.length === 0) {
139
+ res.name = data.name;
140
+ res.auth = data.auth;
141
+ res.children = [];
142
+ } else {
143
+ res.name = data.name;
144
+ res.auth = data.auth;
145
+ res.children = [];
146
+ data.children.forEach(item => {
147
+ res.children.push(getAuth(item));
148
+ })
149
+ }
150
+ return res;
151
+ }
152
+
153
+ let filterChildren: any[];
154
+ filterChildren = [];
155
+ view.children.forEach(item => {
156
+ filterChildren.push(getAuth(item));
157
+ });
135
158
  pages[view.name] = {
136
159
  title: view.title,
137
160
  name: view.name,
@@ -140,7 +163,7 @@ export async function genBundleFiles(app: App,
140
163
  hasAuth: app.hasAuth,
141
164
  domainName: app.name,
142
165
  auth: view.auth,
143
- subPage: view.children,
166
+ subPage: filterChildren,
144
167
  documentTitle: app.documentTitle,
145
168
  router: {
146
169
  notFound: '/',
@@ -1,18 +1,18 @@
1
1
  import { Logic, TypeAnnotation, Param, LogicItem, NumericLiteral, BooleanLiteral, StringLiteral, Identifier, MemberExpression } from '..';
2
2
 
3
3
  const naslStdlibMap: any = {
4
- 'nasl.core.ts': require('!!raw-loader!../../../file-storage/data/stdlib/nasl.core.ts').default,
5
- 'nasl.collection.ts': require('!!raw-loader!../../../file-storage/data/stdlib/nasl.collection.ts').default,
6
- 'nasl.interface.ts': require('!!raw-loader!../../../file-storage/data/stdlib/nasl.interface.ts').default,
7
- 'nasl.util.ts': require('!!raw-loader!../../../file-storage/data/stdlib/nasl.util.ts').default,
8
- 'nasl.ui.ts': require('!!raw-loader!../../../file-storage/data/stdlib/nasl.ui.ts').default,
9
- 'nasl.browser.ts': require('!!raw-loader!../../../file-storage/data/stdlib/nasl.browser.ts').default,
10
- 'nasl.auth.ts': require('!!raw-loader!../../../file-storage/data/stdlib/nasl.auth.ts').default,
11
- 'nasl.configuration.ts': require('!!raw-loader!../../../file-storage/data/stdlib/nasl.configuration.ts').default,
12
- 'nasl.langUtil.ts': require('!!raw-loader!../../../file-storage/data/stdlib/nasl.langUtil.ts').default,
13
- 'nasl.annotation.ts': require('!!raw-loader!../../../file-storage/data/stdlib/nasl.annotation.ts').default,
14
- 'nasl.validation.ts': require('!!raw-loader!../../../file-storage/data/stdlib/nasl.validation.ts').default,
15
- 'nasl.process.ts': require('!!raw-loader!../../../file-storage/data/stdlib/nasl.process.ts').default,
4
+ 'nasl.core.ts': require('!!raw-loader!./stdlib/nasl.core.ts').default,
5
+ 'nasl.collection.ts': require('!!raw-loader!./stdlib/nasl.collection.ts').default,
6
+ 'nasl.interface.ts': require('!!raw-loader!./stdlib/nasl.interface.ts').default,
7
+ 'nasl.util.ts': require('!!raw-loader!./stdlib/nasl.util.ts').default,
8
+ 'nasl.ui.ts': require('!!raw-loader!./stdlib/nasl.ui.ts').default,
9
+ 'nasl.browser.ts': require('!!raw-loader!./stdlib/nasl.browser.ts').default,
10
+ 'nasl.auth.ts': require('!!raw-loader!./stdlib/nasl.auth.ts').default,
11
+ 'nasl.configuration.ts': require('!!raw-loader!./stdlib/nasl.configuration.ts').default,
12
+ 'nasl.langUtil.ts': require('!!raw-loader!./stdlib/nasl.langUtil.ts').default,
13
+ 'nasl.annotation.ts': require('!!raw-loader!./stdlib/nasl.annotation.ts').default,
14
+ 'nasl.validation.ts': require('!!raw-loader!./stdlib/nasl.validation.ts').default,
15
+ 'nasl.process.ts': require('!!raw-loader!./stdlib/nasl.process.ts').default,
16
16
  };
17
17
 
18
18
  export default function formatUiTs(allComponent: any) {
@@ -0,0 +1,319 @@
1
+ import { BaseNode, Identifier, TypeAnnotation, StructureProperty, Entity, Structure, EntityProperty, Param, MemberExpression, CompletionProperty } from '..';
2
+ import { getNaslNodeByNodeCallee } from '../automate/engine/utils';
3
+
4
+ interface variableItem {
5
+ text: string;
6
+ completionDetail: any;
7
+ children?: variableItem[] | any;
8
+ name?: string;
9
+ value?: string;
10
+ expression: MemberExpression | Identifier;
11
+ }
12
+ /**
13
+ * 把ts返回的详细信息截取成一个类型字符串
14
+ * @param displayParts ts返回的key value
15
+ * // 0: {text: 'let', kind: 'keyword'}
16
+ // 1: {text: ' ', kind: 'space'}
17
+ // 2: {text: 'bindRoles', kind: 'text'}
18
+ // 3: {text: ':', kind: 'punctuation'}
19
+ // 4: {text: ' ', kind: 'space'}
20
+ // 5: {text: 'roles', kind: 'moduleName'}
21
+ // 6: {text: '.', kind: 'punctuation'}
22
+ // 7: {text: 'DEV_AdminRole', kind: 'enumName'}
23
+ * @returns type roles.DEV_AdminRole
24
+ */
25
+ function formatTs2TypeString(displayParts: Array<{ text: string; kind: string }>) {
26
+ let str = '';
27
+ displayParts.forEach((item) => {
28
+ str += item.text;
29
+ });
30
+ const strTypes = str.split(': ');
31
+ const type = strTypes[1];
32
+ return type;
33
+ }
34
+ /**
35
+ * 把当前类型转成typeAnnotation
36
+ * @param type app
37
+ * @returns typeAnnotation
38
+ */
39
+ function getCompletionDetailType(type: string): TypeAnnotation {
40
+ let typeAnnotation;
41
+ try {
42
+ if (type.includes('<') && type.includes('>')) {
43
+ // 泛型的处理
44
+ typeAnnotation = createGenericTypeAnnotation(type);
45
+ } else {
46
+ typeAnnotation = createType2Annotation(type);
47
+ }
48
+ } catch (err) {
49
+ console.log(err);
50
+ }
51
+ return typeAnnotation;
52
+ }
53
+
54
+ function createGenericTypeAnnotation(type: string) {
55
+ // 取出匹配的内容
56
+
57
+ const childType = type.substring(0, type.indexOf('<'));
58
+ const typeAnnotation = createType2Annotation(childType);
59
+ // 如果还有匹配到的多层泛型;
60
+ // 取出匹配到的内容
61
+ const types = /\<([^()]+)\>/g.exec(type);
62
+ const newtext = types[1];
63
+ // 把匹配的值,的内容在,检索一遍,看是不是泛型套泛型
64
+ const newTypes = /\<([^()]+)\>/g.exec(newtext);
65
+ // 如果是的话就去递归
66
+ if (newTypes) {
67
+ const argTypeAnnotation = createGenericTypeAnnotation(newtext);
68
+ typeAnnotation.typeArguments = [argTypeAnnotation];
69
+ } else {
70
+ // 如果不是就创造内部的真正类型
71
+ const argTypeAnnotation = createType2Annotation(newtext);
72
+ typeAnnotation.typeArguments = [argTypeAnnotation];
73
+ }
74
+ return typeAnnotation;
75
+ }
76
+ function createType2Annotation(type: string): TypeAnnotation {
77
+ let typeAnnotation;
78
+ // 没有泛型类型的
79
+ const types = type.split('.');
80
+ if (types.length === 1) {
81
+ typeAnnotation = TypeAnnotation.createPrimitive(types[0]);
82
+ } else {
83
+ if (type.startsWith('nasl.core')) {
84
+ typeAnnotation = TypeAnnotation.createPrimitive(types[types.length - 1]);
85
+ } else if (type.startsWith('nasl.ui')) {
86
+ typeAnnotation = TypeAnnotation.createReference(types[types.length - 1], {
87
+ typeNamespace: 'nasl.ui',
88
+ });
89
+ } else if (type.startsWith('nasl.process')) {
90
+ typeAnnotation = TypeAnnotation.createReference(types[types.length - 1], {
91
+ typeNamespace: 'nasl.process',
92
+ });
93
+ } else if (type.startsWith('nasl.collection')) {
94
+ typeAnnotation = TypeAnnotation.createGeneric(types[types.length - 1], {
95
+ typeNamespace: 'nasl.collection',
96
+ });
97
+ } else if (type.startsWith('entities.')) {
98
+ typeAnnotation = TypeAnnotation.createReference(types[types.length - 1], {
99
+ typeNamespace: 'app.entities',
100
+ });
101
+ } else if (type.startsWith('structures.')) {
102
+ typeAnnotation = TypeAnnotation.createReference(types[types.length - 1], {
103
+ typeNamespace: 'app.structures',
104
+ });
105
+ } else if (type.startsWith('enums.')) {
106
+ typeAnnotation = TypeAnnotation.createReference(types[types.length - 1], {
107
+ typeNamespace: 'app.enums',
108
+ });
109
+ }
110
+ }
111
+ return typeAnnotation;
112
+ }
113
+ export function getPlatformType(tsType: string): string {
114
+ const namespacePrefix = ['app', 'extensions', 'apis', 'components', 'nasl'];
115
+ if (tsType === 'String') {
116
+ return 'nasl.core.String';
117
+ } else if (tsType === 'Boolean') {
118
+ return 'nasl.core.Boolean';
119
+ }
120
+
121
+ const strTypes = tsType.split('.');
122
+ if (strTypes.length) {
123
+ const first = strTypes[0];
124
+ // 如果不是这几个前缀就加一个namespace
125
+ if (!namespacePrefix.includes(first)) {
126
+ return 'app.' + tsType;
127
+ }
128
+ }
129
+ return tsType;
130
+ }
131
+ export function isNoChildType(type: String) {
132
+ return type?.startsWith('nasl.core') || type?.startsWith('app.enums');
133
+ }
134
+ function findNode(typeKey: string, node: BaseNode) {
135
+ let newType: Structure | Entity;
136
+ if (typeKey.startsWith('nasl.') && typeKey.includes('<')) {
137
+ const findGenericsIndex = typeKey.indexOf('<');
138
+ typeKey = typeKey.substring(0, findGenericsIndex);
139
+ const typeIndex = typeKey.lastIndexOf('.');
140
+ newType = getNaslNodeByNodeCallee(typeKey.substring(0, typeIndex), typeKey.substring(typeIndex + 1, typeKey.length));
141
+ } else if (typeKey.startsWith('nasl.')) {
142
+ const typeIndex = typeKey.lastIndexOf('.');
143
+ newType = getNaslNodeByNodeCallee(typeKey.substring(0, typeIndex), typeKey.substring(typeIndex + 1, typeKey.length));
144
+ } else {
145
+ newType = (node as Identifier)?.app?.findNodeByCompleteName(typeKey);
146
+ }
147
+ return newType;
148
+ }
149
+
150
+ /**
151
+ * 获取下一级的节点进行递归
152
+ * @param typeKey 当前节点的类型,主要为了取出内部的 T中的实际类型
153
+ * @param item 当前节点的内容
154
+ * @param parent 父级节点的内容
155
+ * @param node 获取变量框的位置
156
+ */
157
+ export function nextFindTypeChild(typeKey: string, item: any, parent: any, node: BaseNode) {
158
+ // 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
159
+ const nodeMap = parent ? parent.nodeMap : new Map();
160
+ item.nodeMap = nodeMap;
161
+ const newType = findNode(typeKey, node);
162
+ if (newType?.properties && newType.properties.length) {
163
+ // 处理泛型的内容要取到值
164
+ const StructureJson = newType.toJSON();
165
+ const newStructure = new Structure(StructureJson);
166
+ newStructure.properties.forEach((item: StructureProperty | EntityProperty) => {
167
+ const itemType = item?.typeAnnotation?.typeKey;
168
+ if (itemType === 'T' && /\<([^()]+)\>/g.exec(typeKey)) {
169
+ const newTypes = /\<([^()]+)\>/g.exec(typeKey);
170
+ // 找到当前原来的类型
171
+ const contentType = getPlatformType(newTypes[1]);
172
+ const typeNamespace = contentType.substring(0, contentType.lastIndexOf('.'));
173
+ const typeName = contentType.substring(contentType.lastIndexOf('.') + 1, contentType.length);
174
+ item.typeAnnotation = new TypeAnnotation({
175
+ typeKind: 'reference',
176
+ typeNamespace,
177
+ typeName,
178
+ });
179
+ }
180
+ });
181
+ const index = nodeMap.get(newType) || 0;
182
+ if (index) {
183
+ nodeMap.set(newType, index + 1);
184
+ } else {
185
+ nodeMap.set(newType, 1);
186
+ }
187
+ // 最多保留3层
188
+ if (index < 3) {
189
+ item.children = formatVariableData(newStructure.properties, node, item);
190
+ }
191
+ }
192
+ }
193
+
194
+ // 格式化变量数据
195
+ export function formatVariableData(data: unknown | variableItem[], node: BaseNode, parent?: any) {
196
+ if (Array.isArray(data)) {
197
+ let result = data.map((item) => {
198
+ item.children = [];
199
+ // 当前结构的typeAnnotation
200
+ let typeAnnotation;
201
+ // 当前的类型如 app.entitys.entity1 nasl.core.String
202
+ let typeKey: string;
203
+
204
+ if (item.completionDetail) {
205
+ // 当前节点的完整类型,主要是在有T的内容使用 nasl.list<Enum1> 内部匹配内容给里面子集的T赋值类型
206
+ const currentType: string = formatTs2TypeString(item.completionDetail.displayParts as Array<{ text: string; kind: string }>);
207
+ typeAnnotation = getCompletionDetailType(currentType);
208
+ typeKey = getPlatformType(currentType);
209
+ } else if (item instanceof StructureProperty) {
210
+ typeKey = item?.typeAnnotation?.typeKey;
211
+ }
212
+ // 如果没有父节点就是Identifier
213
+ if (!parent) {
214
+ // value需要拼接生成
215
+ item.value = parent ? `${parent.value}.${item.text}` : item.text;
216
+ item.name = item.text;
217
+ const identifier = new Identifier({ name: item.name });
218
+ // 携带上当前的类型
219
+ identifier.typeAnnotation = typeAnnotation;
220
+ item.expression = identifier;
221
+ } else {
222
+ item.value = `${parent.value}.${item.name}`;
223
+ const memberExpression = new MemberExpression({
224
+ object: parent.expression,
225
+ property: new Identifier({ name: item.name }),
226
+ });
227
+ // 携带上当前的类型
228
+ memberExpression.typeAnnotation = typeAnnotation;
229
+ item.expression = memberExpression;
230
+ }
231
+ // 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
232
+ if (typeKey && !isNoChildType(typeKey)) {
233
+ nextFindTypeChild(typeKey, item, parent, node);
234
+ }
235
+ const completionProperty = new CompletionProperty(item);
236
+ if (!parent) {
237
+ // 变量 param return 在这里添加图标
238
+ completionProperty.icon = getNodeiconFromLogic(completionProperty, node);
239
+ } else {
240
+ completionProperty.icon = 'refProperty';
241
+ }
242
+ return completionProperty;
243
+ });
244
+
245
+ /**
246
+ * 排序result
247
+ * 如果没有父级就是第一集就排序一下当前result,用户体验优化
248
+ */
249
+ if (!parent) {
250
+ result = sortFirstVariableData(result, node);
251
+ }
252
+ return result;
253
+ }
254
+ }
255
+
256
+ // 从logic获取节点的icon
257
+ function getNodeiconFromLogic(completionProperty: CompletionProperty, node: BaseNode): string {
258
+ const logic = (node as Param).logic;
259
+ const view = (node as Param).view;
260
+ if (view) {
261
+ const { params } = view;
262
+ if (params.find((item) => item.name === completionProperty.name))
263
+ return 'param';
264
+ }
265
+ if (logic) {
266
+ const { params, returns } = logic;
267
+ if (params.find((item) => item.name === completionProperty.name))
268
+ return 'param';
269
+
270
+ if (returns.find((item) => item.name === completionProperty.name))
271
+ return 'return';
272
+ // if (variables.find((item) => item.name === completionProperty.name))
273
+ // return 'variable';
274
+
275
+ // 其余的全部按variable展示
276
+ return 'variable';
277
+ }
278
+ return 'variable';
279
+ }
280
+
281
+
282
+ /**
283
+ * 把要返回去的数据做一下排序
284
+ * @param result 要返回数据
285
+ * @param node 当前内容的上下级
286
+ * @returns 返回排序后的数组
287
+ * 因为ts会按照 a-z的顺序进行排序
288
+ * 但是影响用户体验,需要先按照页面排序,其次按照logic进行排序
289
+ * 流程的韬哥自己解决了,所以先解决这两部分
290
+ */
291
+ function sortFirstVariableData(result: CompletionProperty[], node: BaseNode) {
292
+ const newResult: CompletionProperty[] = [];
293
+ const logic = (node as Param).logic;
294
+ const view = (node as Param).view;
295
+ if (view) {
296
+ const { params, variables } = view;
297
+ const list = [...params, ...variables];
298
+ list.forEach((item) => {
299
+ const findIndex = result.findIndex((findItem) => findItem.name === item.name);
300
+ if (findIndex === 0 || findIndex) {
301
+ newResult.push(result[findIndex]);
302
+ result.splice(findIndex, 1);
303
+ }
304
+ });
305
+ }
306
+ if (logic) {
307
+ const { params, returns, variables } = logic;
308
+ const list = [...params, ...returns, ...variables];
309
+ list.forEach((item) => {
310
+ const findIndex = result.findIndex((findItem) => findItem.name === item.name);
311
+ if (findIndex === 0 || findIndex) {
312
+ newResult.push(result[findIndex]);
313
+ result.splice(findIndex, 1);
314
+ }
315
+ });
316
+ }
317
+ newResult.push(...result);
318
+ return newResult;
319
+ }