@lcap/nasl 2.18.0-beta.2 → 2.18.0-beta.4
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 +3 -3
- package/out/concepts/Logic__.js.map +1 -1
- 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 +1 -1
- package/out/concepts/Param__.js.map +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/View__.js +2 -2
- package/out/concepts/View__.js.map +1 -1
- package/out/generator/genReleaseBody.js +1 -1
- package/out/generator/genReleaseBody.js.map +1 -1
- package/out/server/naslServer.d.ts +2 -1
- package/out/server/naslServer.js +57 -7
- 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/package.json +1 -1
- package/src/bak/translator.js +1 -1
- 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 +3 -3
- package/src/concepts/Match__.ts +1 -1
- package/src/concepts/MemberExpression__.ts +11 -0
- package/src/concepts/OqlQueryComponent__.ts +7 -0
- package/src/concepts/Param__.ts +2 -1
- package/src/concepts/Return__.ts +4 -0
- package/src/concepts/StringInterpolation__.ts +26 -26
- package/src/concepts/UnaryExpression__.ts +4 -4
- package/src/concepts/ValidationRule__.ts +1 -1
- package/src/concepts/ViewElement__.ts +1 -1
- package/src/concepts/View__.ts +2 -2
- package/src/generator/genReleaseBody.ts +1 -1
- package/src/server/naslServer.ts +56 -8
- package/src/templator/genQueryComponent.ts +8 -3
- package/ts-worker/bin/replace-tsserver.js +1 -2
- package/ts-worker/lib/cancellationToken.js +67 -0
- package/ts-worker/lib/harness.js +1 -1
- package/ts-worker/src/start.js +1 -1
- package/ts-worker/webpack.config.js +3 -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方法,查询指定位置的详情
|
|
@@ -2330,7 +2372,6 @@ export class NaslServer {
|
|
|
2330
2372
|
const nodeTypeAnnotation = this.getCurrentNodeKnownTypeAnnotation(node);
|
|
2331
2373
|
if (nodeTypeAnnotation) {
|
|
2332
2374
|
types.set(node, nodeTypeAnnotation);
|
|
2333
|
-
node.__TypeAnnotation = nodeTypeAnnotation;
|
|
2334
2375
|
return;
|
|
2335
2376
|
}
|
|
2336
2377
|
// 要通过自己或者依赖关系拿的,二次遍历
|
|
@@ -2344,8 +2385,8 @@ export class NaslServer {
|
|
|
2344
2385
|
if ([
|
|
2345
2386
|
'Return',
|
|
2346
2387
|
'Variable',
|
|
2347
|
-
].includes(node.concept) && (node as
|
|
2348
|
-
node
|
|
2388
|
+
].includes(node.concept) && (node as Variable).typeAnnotation) {
|
|
2389
|
+
types.set(node, (node as Variable).typeAnnotation);
|
|
2349
2390
|
return;
|
|
2350
2391
|
}
|
|
2351
2392
|
if (![
|
|
@@ -2408,7 +2449,9 @@ export class NaslServer {
|
|
|
2408
2449
|
}
|
|
2409
2450
|
args.push(fileDetail);
|
|
2410
2451
|
});
|
|
2452
|
+
console.time('请求')
|
|
2411
2453
|
const resultMap: any = (await this.getNaslNodeTypeFull(args)).response;
|
|
2454
|
+
console.timeEnd('请求')
|
|
2412
2455
|
|
|
2413
2456
|
// console.log(resultMap);
|
|
2414
2457
|
|
|
@@ -2424,8 +2467,7 @@ export class NaslServer {
|
|
|
2424
2467
|
const nodeTypeAnnotation = type2TypeAnnotation(item?.[0]?.nodeType);
|
|
2425
2468
|
// console.log(newQuickInfoNodes[index].node, nodeTypeAnnotation, nodeTypeAnnotation?.typeKey);
|
|
2426
2469
|
types.set(newQuickInfoNodes[index].node, nodeTypeAnnotation);
|
|
2427
|
-
newQuickInfoNodes[index].node.
|
|
2428
|
-
(newQuickInfoNodes[index].node as any).__nodeType = item?.[0]?.nodeType;
|
|
2470
|
+
(newQuickInfoNodes[index].node as any).__nodeType = Object.freeze(item?.[0]?.nodeType);
|
|
2429
2471
|
|
|
2430
2472
|
// console.log('方案1:', displayString1);
|
|
2431
2473
|
});
|
|
@@ -2433,13 +2475,11 @@ export class NaslServer {
|
|
|
2433
2475
|
if (node instanceof Assignment) {
|
|
2434
2476
|
if (!types.get(node.left)) {
|
|
2435
2477
|
types.set(node.left, types.get(node.right));
|
|
2436
|
-
node.left.__TypeAnnotation = (types.get(node.right) as TypeAnnotation);
|
|
2437
2478
|
}
|
|
2438
2479
|
} else if (node instanceof Argument) {
|
|
2439
2480
|
// 如果Argument,但是没可以用的类型,就用原来logic的参数类型
|
|
2440
2481
|
const argType = this.getArgumentTypeAnnotation(node, newQuickInfoNodes, (types as any));
|
|
2441
2482
|
types.set(node, argType);
|
|
2442
|
-
node.__TypeAnnotation = argType.typeAnnotation;
|
|
2443
2483
|
} else if (node instanceof MatchCase) {
|
|
2444
2484
|
// matchCase的类型
|
|
2445
2485
|
// 直接从最后一项的返回值取,有就有没有就没有
|
|
@@ -2447,7 +2487,6 @@ export class NaslServer {
|
|
|
2447
2487
|
const last = node.body[node.body.length - 1];
|
|
2448
2488
|
if (last.__TypeAnnotation) {
|
|
2449
2489
|
types.set(node, last.__TypeAnnotation);
|
|
2450
|
-
node.__TypeAnnotation = last.__TypeAnnotation;
|
|
2451
2490
|
}
|
|
2452
2491
|
}
|
|
2453
2492
|
}
|
|
@@ -2456,6 +2495,13 @@ export class NaslServer {
|
|
|
2456
2495
|
// 重置类型状态
|
|
2457
2496
|
types.forEach((value, node) => {
|
|
2458
2497
|
node.__isCorrectTypeAnnotation = true;
|
|
2498
|
+
if (value) {
|
|
2499
|
+
if (value instanceof TypeAnnotation) {
|
|
2500
|
+
node.__TypeAnnotation = (Object.freeze(value) as TypeAnnotation);
|
|
2501
|
+
} else if (value.typeAnnotation) {
|
|
2502
|
+
node.__TypeAnnotation = (Object.freeze(value.typeAnnotation) as TypeAnnotation);
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2459
2505
|
});
|
|
2460
2506
|
// newQuickInfoNodes.forEach((itemDetail, index) => {
|
|
2461
2507
|
// const { node, filePath } = itemDetail;
|
|
@@ -2561,6 +2607,7 @@ export class NaslServer {
|
|
|
2561
2607
|
|
|
2562
2608
|
// 增量标注
|
|
2563
2609
|
async IncrementalAnnotationJSON(records: DiagnosticRecord[]) {
|
|
2610
|
+
console.time('增量标注');
|
|
2564
2611
|
const nodes: QuickInfoNodes = [];
|
|
2565
2612
|
records.forEach((record) => {
|
|
2566
2613
|
const fileNode = this.file2NodeMap.get(record.filePath);
|
|
@@ -2580,6 +2627,7 @@ export class NaslServer {
|
|
|
2580
2627
|
});
|
|
2581
2628
|
|
|
2582
2629
|
await this.getQuickInfoNodesTypeMap(nodes);
|
|
2630
|
+
console.timeEnd('增量标注');
|
|
2583
2631
|
}
|
|
2584
2632
|
|
|
2585
2633
|
annotationToJson(typesMap: Map<BaseNode, TypeAnnotation | {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as utils from '../utils';
|
|
2
|
-
import { App, Module, Namespace, Entity, Structure, QueryJoinExpression, CallQueryComponent, StructureProperty, DataSource } from '../concepts';
|
|
2
|
+
import { App, Module, Namespace, Entity, Structure, QueryJoinExpression, CallQueryComponent, StructureProperty, DataSource, TypeAnnotation } from '../concepts';
|
|
3
3
|
import { NameGroup, NaslCoreTypeAnnotation, NaslCollectionTypeAnnotation, NaslTypeAnnotation, NaslQueryExpression, NaslLogicItem, NaslNode } from './utils';
|
|
4
4
|
|
|
5
5
|
export function genQueryStructure(allEntities: Array<Entity>, nameGroup: NameGroup) {
|
|
@@ -205,7 +205,7 @@ export function genQueryLogic(allEntities: Array<Entity>, nameGroup: NameGroup,
|
|
|
205
205
|
return logic;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
export async function joinEntity(callQueryComponent: CallQueryComponent, entity: Entity, recordStructure: Structure) {
|
|
208
|
+
export async function joinEntity(callQueryComponent: CallQueryComponent, entity: Entity, recordStructure: Structure | TypeAnnotation) {
|
|
209
209
|
const dataSource = entity.parentNode as DataSource;
|
|
210
210
|
const from = callQueryComponent.from;
|
|
211
211
|
let joinInfo;
|
|
@@ -276,7 +276,12 @@ export async function joinEntity(callQueryComponent: CallQueryComponent, entity:
|
|
|
276
276
|
typeName: entity.name,
|
|
277
277
|
}),
|
|
278
278
|
}), recordStructure, 'properties');
|
|
279
|
-
|
|
279
|
+
|
|
280
|
+
if(recordStructure instanceof Structure)
|
|
281
|
+
recordStructure.addProperty(structureProperty);
|
|
282
|
+
else if(recordStructure instanceof TypeAnnotation)
|
|
283
|
+
recordStructure.properties.push(structureProperty);
|
|
284
|
+
|
|
280
285
|
const newJoinPartLogicItem = QueryJoinExpression.from(queryJoinExpression, callQueryComponent, 'joinParts');
|
|
281
286
|
from.addJoinPart(newJoinPartLogicItem);
|
|
282
287
|
callQueryComponent.saveStructure();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const fs = require('fs-extra');
|
|
2
|
-
const path = require('path');
|
|
3
2
|
|
|
4
|
-
const tsserverPath =
|
|
3
|
+
const tsserverPath = require.resolve('typescript/lib/tsserver.js');
|
|
5
4
|
let content = fs.readFileSync(tsserverPath, 'utf8');
|
|
6
5
|
content = content.replace(/\/\/ Cannot check process[\s\S]+addEventListener\("message", listener_1\);\s+\}/g, (m) => '/* ' + m.slice(3) + ' */');
|
|
7
6
|
fs.writeFileSync(tsserverPath, content, 'utf8');
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*! *****************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
5
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
8
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
9
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
10
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
11
|
+
|
|
12
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
13
|
+
and limitations under the License.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
"use strict";
|
|
18
|
+
var fs = require("fs");
|
|
19
|
+
function pipeExists(name) {
|
|
20
|
+
return fs.existsSync(name);
|
|
21
|
+
}
|
|
22
|
+
function createCancellationToken(args) {
|
|
23
|
+
var cancellationPipeName;
|
|
24
|
+
for (var i = 0; i < args.length - 1; i++) {
|
|
25
|
+
if (args[i] === "--cancellationPipeName") {
|
|
26
|
+
cancellationPipeName = args[i + 1];
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!cancellationPipeName) {
|
|
31
|
+
return {
|
|
32
|
+
isCancellationRequested: function () { return false; },
|
|
33
|
+
setRequest: function (_requestId) { return void 0; },
|
|
34
|
+
resetRequest: function (_requestId) { return void 0; }
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (cancellationPipeName.charAt(cancellationPipeName.length - 1) === "*") {
|
|
38
|
+
var namePrefix_1 = cancellationPipeName.slice(0, -1);
|
|
39
|
+
if (namePrefix_1.length === 0 || namePrefix_1.indexOf("*") >= 0) {
|
|
40
|
+
throw new Error("Invalid name for template cancellation pipe: it should have length greater than 2 characters and contain only one '*'.");
|
|
41
|
+
}
|
|
42
|
+
var perRequestPipeName_1;
|
|
43
|
+
var currentRequestId_1;
|
|
44
|
+
return {
|
|
45
|
+
isCancellationRequested: function () { return perRequestPipeName_1 !== undefined && pipeExists(perRequestPipeName_1); },
|
|
46
|
+
setRequest: function (requestId) {
|
|
47
|
+
currentRequestId_1 = requestId;
|
|
48
|
+
perRequestPipeName_1 = namePrefix_1 + requestId;
|
|
49
|
+
},
|
|
50
|
+
resetRequest: function (requestId) {
|
|
51
|
+
if (currentRequestId_1 !== requestId) {
|
|
52
|
+
throw new Error("Mismatched request id, expected ".concat(currentRequestId_1, ", actual ").concat(requestId));
|
|
53
|
+
}
|
|
54
|
+
perRequestPipeName_1 = undefined;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return {
|
|
60
|
+
isCancellationRequested: function () { return pipeExists(cancellationPipeName); },
|
|
61
|
+
setRequest: function (_requestId) { return void 0; },
|
|
62
|
+
resetRequest: function (_requestId) { return void 0; }
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
module.exports = createCancellationToken;
|
|
67
|
+
//# sourceMappingURL=cancellationToken.js.map
|
package/ts-worker/lib/harness.js
CHANGED
package/ts-worker/src/start.js
CHANGED
|
@@ -27,10 +27,12 @@ module.exports = {
|
|
|
27
27
|
// DISABLE Webpack's built-in process and Buffer polyfills!
|
|
28
28
|
fallback: {
|
|
29
29
|
fs: false,
|
|
30
|
+
os: false,
|
|
31
|
+
inspector: false,
|
|
30
32
|
// fs: 'browserfs/dist/shims/fs.js',
|
|
31
33
|
crypto: require.resolve('crypto-browserify'),
|
|
32
34
|
stream: require.resolve('stream-browserify'),
|
|
33
|
-
|
|
35
|
+
path: require.resolve('path-browserify'),
|
|
34
36
|
// processGlobal: 'browserfs/dist/shims/process.js',
|
|
35
37
|
// bufferGlobal: 'browserfs/dist/shims/bufferGlobal.js',
|
|
36
38
|
// bfsGlobal: require.resolve('browserfs'),
|