@lcap/nasl 2.18.0-beta.3 → 2.18.0
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.
- package/out/bak/translator.js +1 -1
- package/out/bak/translator.js.map +1 -1
- package/out/concepts/LogicItem__.js.map +1 -1
- package/out/concepts/Logic__.js +4 -4
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MatchExpression__.d.ts +97 -0
- package/out/concepts/MatchExpression__.js +281 -0
- package/out/concepts/MatchExpression__.js.map +1 -0
- package/out/concepts/Match__.js +1 -1
- package/out/concepts/Match__.js.map +1 -1
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/OqlQueryComponent__.js.map +1 -1
- package/out/concepts/Param__.js +2 -2
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/Return__.js +1 -1
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/StringInterpolation__.d.ts +16 -16
- package/out/concepts/StringInterpolation__.js +12 -12
- package/out/concepts/StringInterpolation__.js.map +1 -1
- package/out/concepts/ValidationRule__.js.map +1 -1
- package/out/concepts/Variable__.js +1 -1
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/View__.js +2 -2
- package/out/concepts/View__.js.map +1 -1
- package/out/server/naslServer.d.ts +2 -1
- package/out/server/naslServer.js +84 -38
- package/out/server/naslServer.js.map +1 -1
- package/out/templator/genQueryComponent.d.ts +2 -2
- package/out/templator/genQueryComponent.js +4 -1
- package/out/templator/genQueryComponent.js.map +1 -1
- package/out/templator/sql-parser/index.d.ts +1 -0
- package/out/templator/sql-parser/index.js +228 -0
- package/out/templator/sql-parser/index.js.map +1 -0
- package/out/templator/sql-parser/parser.js +26664 -0
- package/out/templator/sql-parser/parser.js.map +1 -0
- package/package.json +3 -4
- package/src/automate/engine/dist/index.dev.js +517 -0
- package/src/bak/translator.js +1 -1
- package/src/common/dist/BaseNode.js +1101 -0
- package/src/concepts/CallInterface__.ts +9 -9
- package/src/concepts/Destination__.ts +9 -9
- package/src/concepts/ExternalDestination__.ts +5 -5
- package/src/concepts/LogicItem__.ts +4 -0
- package/src/concepts/Logic__.ts +42 -5
- package/src/concepts/Match__.ts +21 -1
- package/src/concepts/MemberExpression__.ts +11 -0
- package/src/concepts/OqlQueryComponent__.ts +7 -0
- package/src/concepts/Param__.ts +3 -2
- package/src/concepts/Return__.ts +5 -1
- package/src/concepts/StringInterpolation__.ts +26 -26
- package/src/concepts/UnaryExpression__.ts +4 -4
- package/src/concepts/ValidationRule__.ts +1 -1
- package/src/concepts/Variable__.ts +1 -1
- package/src/concepts/ViewElement__.ts +1 -1
- package/src/concepts/View__.ts +2 -2
- package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +24 -0
- package/src/concepts/dist/Anchor__.js +179 -0
- package/src/concepts/dist/Assignment__.js +301 -0
- package/src/concepts/dist/CallFunction__.js +473 -0
- package/src/concepts/dist/CallInterface__.js +533 -0
- package/src/concepts/dist/CallLogic__.js +864 -0
- package/src/concepts/dist/ForEachStatement__.js +426 -0
- package/src/concepts/dist/MatchCase__.js +587 -0
- package/src/concepts/dist/MemberExpression__.js +348 -0
- package/src/concepts/dist/Param__.js +537 -0
- package/src/concepts/dist/Return__.js +493 -0
- package/src/generator/dist/genBundleFiles.js +414 -0
- package/src/server/dist/formatTsUtils.js +683 -0
- package/src/server/dist/naslServer.js +3396 -0
- package/src/server/naslServer.ts +84 -39
- package/src/service/storage/dist/init.js +541 -0
- package/src/templator/genQueryComponent.ts +8 -3
- package/ts-worker/dist/webpack.config.dev.js +104 -0
- package/ts-worker/lib/cancellationToken.js +67 -0
- package/ts-worker/lib/dist/tsserver.dev.js +22953 -0
- package/ts-worker/lib/harness.js +1 -1
- package/ts-worker/sources/lib/dist/tsserver.dev.js +22912 -0
- package/ts-worker/src/start.js +1 -1
- package/ts-worker/webpack.config.js +3 -1
- package/dist/bundle.js +0 -3962
- package/dist/bundle.js.LICENSE.txt +0 -16
- package/out/generator/release.d.ts +0 -1
- package/out/generator/release.js +0 -51
- package/out/generator/release.js.map +0 -1
package/src/server/naslServer.ts
CHANGED
|
@@ -614,6 +614,48 @@ export class NaslServer {
|
|
|
614
614
|
}
|
|
615
615
|
return '';
|
|
616
616
|
}
|
|
617
|
+
async getDataSchemaStructureOrTypeAnnotation(node: ViewElement) {
|
|
618
|
+
if (!(node instanceof ViewElement)) return;
|
|
619
|
+
|
|
620
|
+
const { currentSource, fileNode } = this.getCurrentSource(node);
|
|
621
|
+
const quickInfo = await this._getTypeQuickinfo({
|
|
622
|
+
file: (fileNode as FileNode).getEmbeddedFilePath(),
|
|
623
|
+
line: lsp2tspNumber(currentSource.range.start.line),
|
|
624
|
+
offset: lsp2tspNumber(currentSource.range.start.character) + `new nasl.ui.`.length,
|
|
625
|
+
});
|
|
626
|
+
if (quickInfo.responseRequired) {
|
|
627
|
+
const displayString = quickInfo?.response?.displayString || '';
|
|
628
|
+
const flag = displayString.includes('<') && displayString.includes('>');
|
|
629
|
+
if(!flag) return;
|
|
630
|
+
|
|
631
|
+
const types = /\<([^()]+)\>/g.exec(displayString);
|
|
632
|
+
let typeStr = types && types[1];
|
|
633
|
+
const app = node.app;
|
|
634
|
+
if (typeStr.includes('__name: "AStructure_')) {
|
|
635
|
+
const properties: StructureProperty[] = [];
|
|
636
|
+
typeStr
|
|
637
|
+
.replace(/([^:\s]+):\s+([^;]+);/g, ($1, name, typeKey) => {
|
|
638
|
+
if(name === '__name') return;
|
|
639
|
+
|
|
640
|
+
typeKey = `app.${typeKey}`;
|
|
641
|
+
const keys = typeKey.split('.');
|
|
642
|
+
const typeName = keys.pop();
|
|
643
|
+
const typeNamespace = keys.join('.');
|
|
644
|
+
properties.push(StructureProperty.from({
|
|
645
|
+
name,
|
|
646
|
+
typeAnnotation: TypeAnnotation.from({
|
|
647
|
+
typeKind: 'reference',
|
|
648
|
+
typeName,
|
|
649
|
+
typeNamespace,
|
|
650
|
+
})
|
|
651
|
+
}))
|
|
652
|
+
return '';
|
|
653
|
+
});
|
|
654
|
+
return TypeAnnotation.createTypeAnonymousStructure(properties);
|
|
655
|
+
} else if(typeStr.startsWith('structures'))
|
|
656
|
+
return app.findNodeByCompleteName(`app.${typeStr}`);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
617
659
|
|
|
618
660
|
/**
|
|
619
661
|
* ts的 quickInfo方法,查询指定位置的详情
|
|
@@ -997,40 +1039,37 @@ export class NaslServer {
|
|
|
997
1039
|
const jsCode = nodeIn.toJS();
|
|
998
1040
|
if (!jsCode.includes(`${node.name} = `))
|
|
999
1041
|
return;
|
|
1000
|
-
//
|
|
1001
|
-
if (
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
return;
|
|
1006
|
-
if (node instanceof Variable
|
|
1007
|
-
&& node.parentNode instanceof View
|
|
1008
|
-
&& (nodeIn.logic?.params.find((param) => jsCode.includes(param.name))
|
|
1009
|
-
|| nodeIn.logic?.virtualParams.find((vParam) => jsCode.includes(vParam.name))
|
|
1010
|
-
|| nodeIn.logic?.variables.find((variable) => jsCode.includes(variable.name)))) {
|
|
1042
|
+
// 页面局部变量
|
|
1043
|
+
if (node instanceof Variable && node.parentNode instanceof View) {
|
|
1044
|
+
// 跟页面局部变量无关的赋值过滤
|
|
1045
|
+
if (!jsCode.includes(`this.${node.name} = `))
|
|
1046
|
+
return;
|
|
1011
1047
|
// 直接赋值 logic 内局部变量、输入参数直接提示系统无法推断类型
|
|
1012
|
-
if (
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
node: nodeIn,
|
|
1026
|
-
severity: 'error',
|
|
1027
|
-
message: `${nodeIn.label}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
|
|
1028
|
-
};
|
|
1029
|
-
nodeIn.tsErrorDetail = diagnostic;
|
|
1030
|
-
diagnostics.push(diagnostic);
|
|
1048
|
+
if (nodeIn.logic?.params.find((param) => jsCode.includes(param.name))
|
|
1049
|
+
|| nodeIn.logic?.virtualParams.find((vParam) => jsCode.includes(vParam.name))
|
|
1050
|
+
|| nodeIn.logic?.variables.find((variable) => jsCode.includes(variable.name))) {
|
|
1051
|
+
if (!nodeIn.tsErrorDetail) {
|
|
1052
|
+
const diagnostic = {
|
|
1053
|
+
node: nodeIn,
|
|
1054
|
+
severity: 'error',
|
|
1055
|
+
message: `页面${nodeTypeName} ${node.name} 赋值页面逻辑内局部变量或输入参数时,系统无法推导类型。`,
|
|
1056
|
+
};
|
|
1057
|
+
nodeIn.tsErrorDetail = diagnostic;
|
|
1058
|
+
diagnostics.push(diagnostic);
|
|
1059
|
+
}
|
|
1060
|
+
msg = '系统无法推断类型。';
|
|
1031
1061
|
}
|
|
1032
|
-
msg = '必须赋值有返回值的内容。';
|
|
1033
1062
|
}
|
|
1063
|
+
if (!nodeIn.tsErrorDetail) {
|
|
1064
|
+
const diagnostic = {
|
|
1065
|
+
node: nodeIn,
|
|
1066
|
+
severity: 'error',
|
|
1067
|
+
message: `${nodeIn.label}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
|
|
1068
|
+
};
|
|
1069
|
+
nodeIn.tsErrorDetail = diagnostic;
|
|
1070
|
+
diagnostics.push(diagnostic);
|
|
1071
|
+
}
|
|
1072
|
+
msg = '必须赋值有返回值的内容。';
|
|
1034
1073
|
}
|
|
1035
1074
|
});
|
|
1036
1075
|
if (!msg)
|
|
@@ -2330,7 +2369,6 @@ export class NaslServer {
|
|
|
2330
2369
|
const nodeTypeAnnotation = this.getCurrentNodeKnownTypeAnnotation(node);
|
|
2331
2370
|
if (nodeTypeAnnotation) {
|
|
2332
2371
|
types.set(node, nodeTypeAnnotation);
|
|
2333
|
-
node.__TypeAnnotation = nodeTypeAnnotation;
|
|
2334
2372
|
return;
|
|
2335
2373
|
}
|
|
2336
2374
|
// 要通过自己或者依赖关系拿的,二次遍历
|
|
@@ -2344,8 +2382,8 @@ export class NaslServer {
|
|
|
2344
2382
|
if ([
|
|
2345
2383
|
'Return',
|
|
2346
2384
|
'Variable',
|
|
2347
|
-
].includes(node.concept) && (node as
|
|
2348
|
-
node
|
|
2385
|
+
].includes(node.concept) && (node as Variable).typeAnnotation) {
|
|
2386
|
+
types.set(node, (node as Variable).typeAnnotation);
|
|
2349
2387
|
return;
|
|
2350
2388
|
}
|
|
2351
2389
|
if (![
|
|
@@ -2408,7 +2446,9 @@ export class NaslServer {
|
|
|
2408
2446
|
}
|
|
2409
2447
|
args.push(fileDetail);
|
|
2410
2448
|
});
|
|
2449
|
+
console.time('请求')
|
|
2411
2450
|
const resultMap: any = (await this.getNaslNodeTypeFull(args)).response;
|
|
2451
|
+
console.timeEnd('请求')
|
|
2412
2452
|
|
|
2413
2453
|
// console.log(resultMap);
|
|
2414
2454
|
|
|
@@ -2424,8 +2464,7 @@ export class NaslServer {
|
|
|
2424
2464
|
const nodeTypeAnnotation = type2TypeAnnotation(item?.[0]?.nodeType);
|
|
2425
2465
|
// console.log(newQuickInfoNodes[index].node, nodeTypeAnnotation, nodeTypeAnnotation?.typeKey);
|
|
2426
2466
|
types.set(newQuickInfoNodes[index].node, nodeTypeAnnotation);
|
|
2427
|
-
newQuickInfoNodes[index].node.
|
|
2428
|
-
(newQuickInfoNodes[index].node as any).__nodeType = item?.[0]?.nodeType;
|
|
2467
|
+
(newQuickInfoNodes[index].node as any).__nodeType = Object.freeze(item?.[0]?.nodeType);
|
|
2429
2468
|
|
|
2430
2469
|
// console.log('方案1:', displayString1);
|
|
2431
2470
|
});
|
|
@@ -2433,13 +2472,11 @@ export class NaslServer {
|
|
|
2433
2472
|
if (node instanceof Assignment) {
|
|
2434
2473
|
if (!types.get(node.left)) {
|
|
2435
2474
|
types.set(node.left, types.get(node.right));
|
|
2436
|
-
node.left.__TypeAnnotation = (types.get(node.right) as TypeAnnotation);
|
|
2437
2475
|
}
|
|
2438
2476
|
} else if (node instanceof Argument) {
|
|
2439
2477
|
// 如果Argument,但是没可以用的类型,就用原来logic的参数类型
|
|
2440
2478
|
const argType = this.getArgumentTypeAnnotation(node, newQuickInfoNodes, (types as any));
|
|
2441
2479
|
types.set(node, argType);
|
|
2442
|
-
node.__TypeAnnotation = argType.typeAnnotation;
|
|
2443
2480
|
} else if (node instanceof MatchCase) {
|
|
2444
2481
|
// matchCase的类型
|
|
2445
2482
|
// 直接从最后一项的返回值取,有就有没有就没有
|
|
@@ -2447,7 +2484,6 @@ export class NaslServer {
|
|
|
2447
2484
|
const last = node.body[node.body.length - 1];
|
|
2448
2485
|
if (last.__TypeAnnotation) {
|
|
2449
2486
|
types.set(node, last.__TypeAnnotation);
|
|
2450
|
-
node.__TypeAnnotation = last.__TypeAnnotation;
|
|
2451
2487
|
}
|
|
2452
2488
|
}
|
|
2453
2489
|
}
|
|
@@ -2456,6 +2492,13 @@ export class NaslServer {
|
|
|
2456
2492
|
// 重置类型状态
|
|
2457
2493
|
types.forEach((value, node) => {
|
|
2458
2494
|
node.__isCorrectTypeAnnotation = true;
|
|
2495
|
+
if (value) {
|
|
2496
|
+
if (value instanceof TypeAnnotation) {
|
|
2497
|
+
node.__TypeAnnotation = (Object.freeze(value) as TypeAnnotation);
|
|
2498
|
+
} else if (value.typeAnnotation) {
|
|
2499
|
+
node.__TypeAnnotation = (Object.freeze(value.typeAnnotation) as TypeAnnotation);
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2459
2502
|
});
|
|
2460
2503
|
// newQuickInfoNodes.forEach((itemDetail, index) => {
|
|
2461
2504
|
// const { node, filePath } = itemDetail;
|
|
@@ -2561,6 +2604,7 @@ export class NaslServer {
|
|
|
2561
2604
|
|
|
2562
2605
|
// 增量标注
|
|
2563
2606
|
async IncrementalAnnotationJSON(records: DiagnosticRecord[]) {
|
|
2607
|
+
console.time('增量标注');
|
|
2564
2608
|
const nodes: QuickInfoNodes = [];
|
|
2565
2609
|
records.forEach((record) => {
|
|
2566
2610
|
const fileNode = this.file2NodeMap.get(record.filePath);
|
|
@@ -2580,6 +2624,7 @@ export class NaslServer {
|
|
|
2580
2624
|
});
|
|
2581
2625
|
|
|
2582
2626
|
await this.getQuickInfoNodesTypeMap(nodes);
|
|
2627
|
+
console.timeEnd('增量标注');
|
|
2583
2628
|
}
|
|
2584
2629
|
|
|
2585
2630
|
annotationToJson(typesMap: Map<BaseNode, TypeAnnotation | {
|