@lcap/nasl 3.13.1-beta.9 → 3.13.1-debug.2

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.
@@ -57,7 +57,6 @@ const translator_2 = require("./translator");
57
57
  const common_1 = require("../common");
58
58
  const diagnostic_1 = require("../manager/diagnostic");
59
59
  const naslStdlibMap_1 = __importDefault(require("./naslStdlibMap"));
60
- const vue_1 = require("../utils/vue");
61
60
  const utils_2 = require("../utils");
62
61
  const decorators_1 = require("../decorators");
63
62
  const nasl_concepts_1 = require("@lcap/nasl-concepts");
@@ -129,34 +128,24 @@ function belongVirtualParams(node) {
129
128
  return (0, utils_1.findConceptKeyWordIndexFromNodePath)(node?.nodePath, 'virtualParams') !== -1;
130
129
  }
131
130
  /**
132
- * 包含特定的关键字
131
+ * 是端事件下的参数
133
132
  * @param node
134
- * @param keywords
135
133
  * @returns
136
134
  */
137
- function containsSpecificKeywords(node, keywords) {
138
- return keywords.filter((keyword) => {
139
- return (0, utils_1.findConceptKeyWordIndexFromNodePath)(node?.nodePath, keyword) !== -1;
140
- })?.length;
141
- }
142
- /**
143
- * 方法下入参'_'
144
- * @param node
145
- * @returns
146
- */
147
- function isFunctionUnderlineParam(node) {
148
- return node?.name === '_' && node?.concept === 'Param' && node?.parentNode?.concept === 'Function';
149
- }
150
- /**
151
- * 是端类型下的参数
152
- * @param node
153
- * @returns
154
- */
155
- function isFrontendTypeEvent(node) {
135
+ function isFrontendEvent(node) {
136
+ let flag = false;
156
137
  if (node?.name === 'event') {
157
- return node.getAncestor('FrontendType');
138
+ flag = true;
139
+ let target = node;
140
+ const conceptList = ['Param', 'Logic', 'BindEvent', 'Frontend'];
141
+ conceptList.forEach((concept) => {
142
+ if (target?.concept !== concept) {
143
+ flag = false;
144
+ }
145
+ target = target?.parentNode;
146
+ });
158
147
  }
159
- return false;
148
+ return flag;
160
149
  }
161
150
  // 联合类型切割取出类型
162
151
  function getDisplayString2Type(displayString) {
@@ -1729,19 +1718,6 @@ let NaslServer = NaslServer_1 = class NaslServer {
1729
1718
  errorFRefNames,
1730
1719
  };
1731
1720
  }
1732
- _getDuplicateNames(node, getItems, getName) {
1733
- const items = getItems(node);
1734
- const nameSet = new Set();
1735
- const res = new Set();
1736
- for (const item of items) {
1737
- const name = getName(item);
1738
- if (!nameSet.has(name))
1739
- nameSet.add(name);
1740
- else
1741
- res.add(name);
1742
- }
1743
- return Array.from(res);
1744
- }
1745
1721
  /**
1746
1722
  * 额外的诊断
1747
1723
  * @param fileNode 文件级别的节点
@@ -2034,21 +2010,6 @@ let NaslServer = NaslServer_1 = class NaslServer {
2034
2010
  }
2035
2011
  }
2036
2012
  else if (node instanceof concepts_1.Logic) {
2037
- const duplicateVariables = self._getDuplicateNames(node, (logic) => [
2038
- ...logic.variables,
2039
- ...logic.params,
2040
- ...logic.returns,
2041
- ...likeComponent.variables,
2042
- ...likeComponent.params,
2043
- ], (item) => item.name);
2044
- if (duplicateVariables.length) {
2045
- const diagnostic = {
2046
- node,
2047
- severity: 'error',
2048
- message: `逻辑${node.name}存在重名变量:${duplicateVariables.join(', ')}`,
2049
- };
2050
- diagnostics.push(diagnostic);
2051
- }
2052
2013
  }
2053
2014
  else {
2054
2015
  self.checkNodeError(node, diagnostics);
@@ -2122,15 +2083,6 @@ let NaslServer = NaslServer_1 = class NaslServer {
2122
2083
  });
2123
2084
  }
2124
2085
  }
2125
- // 检查实体重名
2126
- const duplidateEntities = this._getDuplicateNames(fileNodeRaw, (dataSource) => dataSource.entities, (entity) => entity.name);
2127
- if (duplidateEntities.length) {
2128
- diagnostics.push({
2129
- node: fileNode,
2130
- severity: 'error',
2131
- message: `数据源${fileNodeRaw.name}存在重名实体:${duplidateEntities.join(', ')}`,
2132
- });
2133
- }
2134
2086
  }
2135
2087
  // 加上对实体属性存储类型的校验规则
2136
2088
  else if (fileNodeRaw instanceof concepts_1.Entity) {
@@ -2473,15 +2425,6 @@ let NaslServer = NaslServer_1 = class NaslServer {
2473
2425
  }
2474
2426
  }
2475
2427
  if (fileNodeRaw instanceof concepts_1.Logic && fileNodeRaw.calleewholeKey.startsWith('app.logics')) {
2476
- const duplicateLogics = this._getDuplicateNames(fileNodeRaw.rootNode, (app) => app.logics, (logic) => logic.name);
2477
- if (duplicateLogics.includes(fileNodeRaw.name)) {
2478
- const diagnostic = {
2479
- node: fileNode,
2480
- severity: 'error',
2481
- message: `存在重名服务端逻辑${fileNodeRaw.name}`,
2482
- };
2483
- diagnostics.push(diagnostic);
2484
- }
2485
2428
  if (fileNodeRaw.sharedScope?.scope === 'specifiedRange' && !fileNodeRaw.sharedScope?.specifiedRange?.length) {
2486
2429
  const diagnostic = {
2487
2430
  node: fileNode,
@@ -2911,16 +2854,11 @@ let NaslServer = NaslServer_1 = class NaslServer {
2911
2854
  // 校验节点名
2912
2855
  function* validateNodeName(node) {
2913
2856
  // 排除一些不需要校验的情况
2914
- if (isFrontendTypeEvent(node) || belongEntityLogic(node) || belongVirtualParams(node)
2915
- || containsSpecificKeywords(node, ['dependencies', 'interfaceDependencies'])
2916
- || isFunctionUnderlineParam(node)) {
2857
+ if (isFrontendEvent(node) || belongEntityLogic(node) || belongVirtualParams(node)) {
2917
2858
  return;
2918
2859
  }
2919
2860
  const { concept } = node || {};
2920
- let conceptValidator = validator_1.validator[concept];
2921
- if (concept === 'EnumItem' && node?.parentNode?.valueType?.typeName === 'Long') {
2922
- conceptValidator = validator_1.validator['EnumItemInteger'];
2923
- }
2861
+ const conceptValidator = validator_1.validator[concept];
2924
2862
  if (conceptValidator) {
2925
2863
  try {
2926
2864
  const vusionValidator = new validator_1.VusionValidator({}, {}, conceptValidator.rules(node), null) || {};
@@ -2945,21 +2883,17 @@ let NaslServer = NaslServer_1 = class NaslServer {
2945
2883
  message: `【${toBeVerifiedName}】命名非法:${res}`,
2946
2884
  };
2947
2885
  diagnostics.push(diagnostic);
2886
+ console.log(diagnostic);
2948
2887
  }
2949
2888
  }
2950
2889
  catch (err) {
2951
- if (utils.isDebugMode) {
2952
- self.logger.info(err);
2953
- }
2890
+ // console.log(err);
2954
2891
  }
2955
2892
  }
2956
2893
  }
2957
- /**
2958
- * 问题没有收敛,先注释
2959
- */
2960
- // yield* utils.wrapIteratorToGenerator(fileNodeRaw.sourceMap.entries(), function* ([node]: any) {
2961
- // yield* validateNodeName(node);
2962
- // });
2894
+ yield* utils.wrapIteratorToGenerator(fileNodeRaw.sourceMap.entries(), function* ([node]) {
2895
+ yield* validateNodeName(node);
2896
+ });
2963
2897
  return diagnostics;
2964
2898
  }
2965
2899
  timeoutCheck(fileNodeRaw, fileNode, diagnostics) {
@@ -5001,8 +4935,7 @@ let NaslServer = NaslServer_1 = class NaslServer {
5001
4935
  // 预留时间做 minor gc,减少峰值内存占用
5002
4936
  utils.delay(55);
5003
4937
  }
5004
- const { node: nodeOrigin, filePath, item } = itemDetail;
5005
- const node = (0, vue_1.toRaw)(nodeOrigin);
4938
+ const { node, filePath, item } = itemDetail;
5006
4939
  // 先按照顺序占位
5007
4940
  types.set(node, null);
5008
4941
  // 获取已知节点类型的类型
@@ -5287,7 +5220,7 @@ let NaslServer = NaslServer_1 = class NaslServer {
5287
5220
  const typesMap = await this.getQuickInfoNodesTypeMap(nodes, true);
5288
5221
  this.logger.time('app to AnnotatedJSON');
5289
5222
  const jsonMap = new Map();
5290
- const json = (0, vue_1.toRaw)(naslNode)._toJSON((newJson, oldNode) => {
5223
+ const json = naslNode._toJSON((newJson, oldNode) => {
5291
5224
  // 删除多余属性,降低全量数据
5292
5225
  delete newJson._aiUID;
5293
5226
  jsonMap.set(oldNode, newJson);
@@ -5626,74 +5559,70 @@ let NaslServer = NaslServer_1 = class NaslServer {
5626
5559
  // 有值而且没有类型再去设置
5627
5560
  // 但是Identifier 和 MemberExpression 都用标注出来的因为本身是变量,有类型也需要覆盖一下
5628
5561
  if (typ && (node instanceof concepts_1.Argument) && node.getAncestor('Connector')?.concept === 'Connector') {
5629
- const newJson = jsonMap.get((0, vue_1.toRaw)(node));
5562
+ const newJson = jsonMap.get(node);
5630
5563
  if (newJson) {
5631
5564
  newJson.typeAnnotation = typ?.toJSON?.() ?? typ;
5632
5565
  }
5633
5566
  }
5634
5567
  if (typ && (!node.typeAnnotation || node instanceof concepts_1.Identifier || node instanceof concepts_1.MemberExpression)) {
5635
- const newJson = jsonMap.get((0, vue_1.toRaw)(node));
5568
+ const newJson = jsonMap.get(node);
5636
5569
  if (newJson) {
5637
5570
  newJson.typeAnnotation = typ?.toJSON?.() ?? typ;
5638
5571
  }
5639
5572
  }
5640
5573
  // 旧版本数据查询需要确认是匿名数据结构的 ListTotal 类型
5641
5574
  if (node instanceof concepts_1.CallQueryComponent && !node.isAutoInfer()) {
5642
- const jsonNode = jsonMap.get((0, vue_1.toRaw)(node));
5643
- if (jsonNode) {
5644
- jsonNode.typeAnnotation = {
5645
- concept: 'TypeAnnotation',
5646
- typeKind: 'anonymousStructure',
5647
- typeNamespace: null,
5648
- typeName: null,
5649
- typeArguments: [],
5650
- inferred: false,
5651
- ruleMap: null,
5652
- properties: [
5653
- {
5654
- concept: 'StructureProperty',
5655
- name: 'list',
5656
- label: null,
5657
- description: null,
5658
- typeAnnotation: {
5659
- concept: 'TypeAnnotation',
5660
- typeKind: 'generic',
5661
- typeNamespace: 'nasl.collection',
5662
- typeName: 'List',
5663
- typeArguments: [jsonNode.typeAnnotation],
5664
- inferred: null,
5665
- },
5666
- required: null,
5667
- defaultValue: null,
5575
+ const newJson = jsonMap.get(node);
5576
+ newJson.typeAnnotation = {
5577
+ concept: 'TypeAnnotation',
5578
+ typeKind: 'anonymousStructure',
5579
+ typeNamespace: null,
5580
+ typeName: null,
5581
+ typeArguments: [],
5582
+ inferred: false,
5583
+ ruleMap: null,
5584
+ properties: [
5585
+ {
5586
+ concept: 'StructureProperty',
5587
+ name: 'list',
5588
+ label: null,
5589
+ description: null,
5590
+ typeAnnotation: {
5591
+ concept: 'TypeAnnotation',
5592
+ typeKind: 'generic',
5593
+ typeNamespace: 'nasl.collection',
5594
+ typeName: 'List',
5595
+ typeArguments: [newJson.typeAnnotation],
5596
+ inferred: null,
5668
5597
  },
5669
- {
5670
- concept: 'StructureProperty',
5671
- name: 'total',
5672
- label: null,
5673
- description: null,
5674
- typeAnnotation: {
5675
- concept: 'TypeAnnotation',
5676
- typeKind: 'primitive',
5677
- typeNamespace: 'nasl.core',
5678
- typeName: 'Long',
5679
- typeArguments: null,
5680
- inferred: null,
5681
- },
5682
- required: null,
5683
- defaultValue: null,
5598
+ required: null,
5599
+ defaultValue: null,
5600
+ },
5601
+ {
5602
+ concept: 'StructureProperty',
5603
+ name: 'total',
5604
+ label: null,
5605
+ description: null,
5606
+ typeAnnotation: {
5607
+ concept: 'TypeAnnotation',
5608
+ typeKind: 'primitive',
5609
+ typeNamespace: 'nasl.core',
5610
+ typeName: 'Long',
5611
+ typeArguments: null,
5612
+ inferred: null,
5684
5613
  },
5685
- ],
5686
- };
5687
- }
5614
+ required: null,
5615
+ defaultValue: null,
5616
+ },
5617
+ ],
5618
+ };
5688
5619
  }
5689
5620
  // 特殊处理param有类型错误的
5690
5621
  if (node instanceof concepts_1.Param) {
5691
5622
  // index在nasl foreach上有脏数据
5692
5623
  if (node.parentKey === 'index' && node.parentNode instanceof concepts_1.ForEachStatement) {
5693
- const jsonNode = jsonMap.get((0, vue_1.toRaw)(node));
5694
- if (jsonNode) {
5695
- jsonNode.typeAnnotation = concepts_1.TypeAnnotation.createPrimitive('Long').toJSON();
5696
- }
5624
+ const newJson = jsonMap.get(node);
5625
+ newJson.typeAnnotation = concepts_1.TypeAnnotation.createPrimitive('Long').toJSON();
5697
5626
  }
5698
5627
  }
5699
5628
  if (node instanceof concepts_1.Match) {
@@ -5705,10 +5634,8 @@ let NaslServer = NaslServer_1 = class NaslServer {
5705
5634
  fileNode.sourceMap.forEach((item, itemNode) => {
5706
5635
  const itemCode = this.getNodeCode(fileNode, item);
5707
5636
  if (itemNode.concept === matchExpression.concept && itemCode === currentCode) {
5708
- const newJson = jsonMap.get((0, vue_1.toRaw)(itemNode));
5709
- if (newJson) {
5710
- newJson.typeAnnotation = matchExpression.__TypeAnnotation;
5711
- }
5637
+ const newJson = jsonMap.get(itemNode);
5638
+ newJson.typeAnnotation = matchExpression.__TypeAnnotation;
5712
5639
  }
5713
5640
  });
5714
5641
  }
@@ -5717,17 +5644,13 @@ let NaslServer = NaslServer_1 = class NaslServer {
5717
5644
  if (typ && (node instanceof concepts_1.Param)) {
5718
5645
  // index在nasl foreach上有脏数据
5719
5646
  if (node.parentKey === 'index' && node.parentNode instanceof concepts_1.ForEachStatement) {
5720
- const newJson = jsonMap.get((0, vue_1.toRaw)(node));
5721
- if (newJson) {
5722
- newJson.typeAnnotation = typ?.toJSON?.() ?? typ;
5723
- }
5647
+ const newJson = jsonMap.get(node);
5648
+ newJson.typeAnnotation = typ?.toJSON?.() ?? typ;
5724
5649
  }
5725
5650
  }
5726
5651
  if (typ && (node instanceof concepts_1.NewComposite) && (node.typeAnnotation?.typeKind === 'anonymousStructure' || node.typeAnnotation?.typeKind === 'generic')) {
5727
- const newJson = jsonMap.get((0, vue_1.toRaw)(node));
5728
- if (newJson) {
5729
- newJson.typeAnnotation = typ?.toJSON?.() ?? typ;
5730
- }
5652
+ const newJson = jsonMap.get(node);
5653
+ newJson.typeAnnotation = typ?.toJSON?.() ?? typ;
5731
5654
  }
5732
5655
  // jsonSerializer 是 CallLogic,其余是 CallFunction
5733
5656
  if (node instanceof concepts_1.CallFunction || node instanceof concepts_1.CallLogic) {
@@ -5743,11 +5666,9 @@ let NaslServer = NaslServer_1 = class NaslServer {
5743
5666
  * 特殊处理,不想去查两次类型, 因为是从函数签名上拿类型,所以直接合并在一起,先这样
5744
5667
  */
5745
5668
  if (node instanceof concepts_1.CallLogic && node.__TypeArguments?.length) {
5746
- const newJson = jsonMap.get((0, vue_1.toRaw)(node));
5747
- if (newJson) {
5748
- newJson.typeArguments = node.__TypeArguments.map((type) => type?.toJSON?.() ?? type);
5749
- newJson.typeAnnotation = node.__TypeAnnotation?.toJSON?.() ?? node.__TypeAnnotation;
5750
- }
5669
+ const newJson = jsonMap.get(node);
5670
+ newJson.typeArguments = node.__TypeArguments.map((type) => type?.toJSON?.() ?? type);
5671
+ newJson.typeAnnotation = node.__TypeAnnotation?.toJSON?.() ?? node.__TypeAnnotation;
5751
5672
  }
5752
5673
  // 根据 https://projectmanage.netease-official.lcap.163yun.com/dashboard/FeatureDetail?id=2737356895760128&id1=null&iterationId=null&versionid=null&tab=info
5753
5674
  // 对CallFunction节点,若其callee为部分List/Map内置函数,则修改其argument类型标注以让服务端据此插入显式的类型转换。规则如下:
@@ -5776,10 +5697,8 @@ let NaslServer = NaslServer_1 = class NaslServer {
5776
5697
  if (itemExpression) {
5777
5698
  const listTypeArgument = list.__TypeAnnotation?.typeArguments?.[0]?.toJSON?.() ?? list.__TypeAnnotation?.typeArguments?.[0];
5778
5699
  if (listTypeArgument) {
5779
- const newJson = jsonMap.get((0, vue_1.toRaw)(item));
5780
- if (newJson) {
5781
- newJson.typeAnnotation = listTypeArgument;
5782
- }
5700
+ const newJson = jsonMap.get(item);
5701
+ newJson.typeAnnotation = listTypeArgument;
5783
5702
  }
5784
5703
  }
5785
5704
  }
@@ -5794,19 +5713,15 @@ let NaslServer = NaslServer_1 = class NaslServer {
5794
5713
  if (keyExpression) {
5795
5714
  const mapKeyTypeArgument = map.__TypeAnnotation?.typeArguments?.[0]?.toJSON?.() ?? map.__TypeAnnotation?.typeArguments?.[0];
5796
5715
  if (mapKeyTypeArgument) {
5797
- const newJson = jsonMap.get((0, vue_1.toRaw)(key));
5798
- if (newJson) {
5799
- newJson.typeAnnotation = mapKeyTypeArgument;
5800
- }
5716
+ const newJson = jsonMap.get(key);
5717
+ newJson.typeAnnotation = mapKeyTypeArgument;
5801
5718
  }
5802
5719
  }
5803
5720
  if (valueExpression) {
5804
5721
  const mapValueTypeArgument = map.__TypeAnnotation?.typeArguments?.[1]?.toJSON?.() ?? map.__TypeAnnotation?.typeArguments?.[1];
5805
5722
  if (mapValueTypeArgument) {
5806
- const newJson = jsonMap.get((0, vue_1.toRaw)(value));
5807
- if (newJson) {
5808
- newJson.typeAnnotation = mapValueTypeArgument;
5809
- }
5723
+ const newJson = jsonMap.get(value);
5724
+ newJson.typeAnnotation = mapValueTypeArgument;
5810
5725
  }
5811
5726
  }
5812
5727
  }
@@ -5816,7 +5731,7 @@ let NaslServer = NaslServer_1 = class NaslServer {
5816
5731
  }
5817
5732
  // 服务端需要默认值节点有类型来判断父节点是否是日期类型
5818
5733
  if (node instanceof concepts_1.DefaultValue && !typ) {
5819
- const newJson = jsonMap.get((0, vue_1.toRaw)(node));
5734
+ const newJson = jsonMap.get(node);
5820
5735
  const parentNodeType = node.parentNode?.typeAnnotation || node.parentNode?.__TypeAnnotation;
5821
5736
  if (parentNodeType && newJson) {
5822
5737
  newJson.typeAnnotation = parentNodeType?.toJSON?.() ?? parentNodeType;