@lcap/nasl 3.8.2-beta.8 → 3.8.3-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.
- package/ai-engineer.config.js +617 -0
- package/out/common/BaseNode.js +5 -3
- package/out/common/BaseNode.js.map +1 -1
- package/out/common/ComponentAPI.d.ts +9 -0
- package/out/concepts/AuthLogicForCallInterface__.js +21 -6
- package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
- package/out/concepts/BackendVariable__.js +16 -1
- package/out/concepts/BackendVariable__.js.map +1 -1
- package/out/concepts/BindAttribute__.js +12 -4
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindDirective__.js +1 -1
- package/out/concepts/BindDirective__.js.map +1 -1
- package/out/concepts/BindStyle__.js +1 -1
- package/out/concepts/BindStyle__.js.map +1 -1
- package/out/concepts/BusinessComponent__.js +24 -8
- package/out/concepts/BusinessComponent__.js.map +1 -1
- package/out/concepts/BusinessLogic__.js +21 -6
- package/out/concepts/BusinessLogic__.js.map +1 -1
- package/out/concepts/CallInterface__.js +2 -1
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.d.ts +1 -0
- package/out/concepts/CallLogic__.js +32 -11
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.d.ts +1 -0
- package/out/concepts/CallQueryComponent__.js +23 -12
- package/out/concepts/CallQueryComponent__.js.map +1 -1
- package/out/concepts/Destination__.js +11 -8
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/EntityProperty__.js +3 -2
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/Entity__.js +1 -1
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/Interface__.js +1 -1
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/Logic__.js +49 -17
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MemberExpression__.js +19 -13
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/OqlQueryComponent__.js +37 -12
- package/out/concepts/OqlQueryComponent__.js.map +1 -1
- package/out/concepts/OverriddenLogic__.js +21 -6
- package/out/concepts/OverriddenLogic__.js.map +1 -1
- package/out/concepts/Param__.js +5 -4
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/QueryOrderByExpression__.d.ts +0 -1
- package/out/concepts/QueryOrderByExpression__.js +0 -1
- package/out/concepts/QueryOrderByExpression__.js.map +1 -1
- package/out/concepts/Structure__.js +5 -7
- package/out/concepts/Structure__.js.map +1 -1
- package/out/concepts/Variable__.js +5 -0
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +1 -0
- package/out/concepts/ViewElement__.js +17 -7
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.js +70 -14
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.processV2.js +78 -0
- package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.ui.js +40 -40
- package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
- package/out/generator/genBundleFiles.js +1 -1
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/release-body/utils.js +1 -1
- package/out/natural/genNaturalTS.d.ts +45 -10
- package/out/natural/genNaturalTS.js +57 -33
- package/out/natural/genNaturalTS.js.map +1 -1
- package/out/natural/getContext/getUILib.js +6 -3
- package/out/natural/getContext/getUILib.js.map +1 -1
- package/out/natural/getContext/index.d.ts +20 -7
- package/out/natural/getContext/index.js +143 -23
- package/out/natural/getContext/index.js.map +1 -1
- package/out/natural/getContext/naslStdlibMap.js +8 -8
- package/out/natural/getContext/naslStdlibMap.js.map +1 -1
- package/out/natural/tools.d.ts +16 -0
- package/out/natural/tools.js +110 -2
- package/out/natural/tools.js.map +1 -1
- package/out/natural/transformTS2UI.js +361 -304
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.d.ts +3 -5
- package/out/natural/transformTSCode.js +30 -1089
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/natural/transforms/registerTransform.d.ts +7 -0
- package/out/natural/transforms/registerTransform.js +24 -0
- package/out/natural/transforms/registerTransform.js.map +1 -0
- package/out/natural/transforms/transform2LogicItem.d.ts +24 -0
- package/out/natural/transforms/transform2LogicItem.js +1240 -0
- package/out/natural/transforms/transform2LogicItem.js.map +1 -0
- package/out/natural/transforms/transform2TypeAnnotation.d.ts +2 -0
- package/out/natural/transforms/transform2TypeAnnotation.js +86 -0
- package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -0
- package/out/natural/transforms/utils.d.ts +8 -0
- package/out/natural/transforms/utils.js +59 -0
- package/out/natural/transforms/utils.js.map +1 -0
- package/out/server/getLogics.js +12 -12
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.js +11 -17
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/naslServer.d.ts +2 -2
- package/out/server/naslServer.js +38 -18
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.js +5 -0
- package/out/server/translator.js.map +1 -1
- package/out/templator/block2nasl/jsx2nasl/index.d.ts +5 -0
- package/out/templator/block2nasl/jsx2nasl/index.js +15 -0
- package/out/templator/block2nasl/jsx2nasl/index.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.d.ts +3 -0
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js +213 -0
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.d.ts +14 -0
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js +201 -0
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.d.ts +4 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js +186 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.d.ts +28 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js +336 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/utils.d.ts +2 -0
- package/out/templator/block2nasl/jsx2nasl/utils.js +26 -0
- package/out/templator/block2nasl/jsx2nasl/utils.js.map +1 -0
- package/out/templator/block2nasl/transformBlock2Nasl.d.ts +10 -0
- package/out/templator/block2nasl/transformBlock2Nasl.js +122 -0
- package/out/templator/block2nasl/transformBlock2Nasl.js.map +1 -0
- package/out/templator/block2nasl/viewMergeBlock.d.ts +9 -0
- package/out/templator/block2nasl/viewMergeBlock.js +110 -0
- package/out/templator/block2nasl/viewMergeBlock.js.map +1 -0
- package/out/translator/types.d.ts +2 -0
- package/out/translator/utils.js +1 -1
- package/out/translator/utils.js.map +1 -1
- package/out/utils/index.js +0 -4
- package/out/utils/index.js.map +1 -1
- package/out/utils/language-cache/constant.d.ts +2 -1
- package/out/utils/language-cache/constant.js +1 -0
- package/out/utils/language-cache/constant.js.map +1 -1
- package/out/utils/language-cache/nasl.d.ts +1 -0
- package/out/utils/language-cache/nasl.js +9 -1
- package/out/utils/language-cache/nasl.js.map +1 -1
- package/package.json +6 -2
- package/sandbox/stdlib/nasl.processV2.ts +19 -0
- package/sandbox/stdlib/nasl.ui.ts +8 -8
- package/sandbox-natural/stdlib/nasl.core.d.ts +54 -0
- package/sandbox-natural/stdlib/nasl.oql.d.ts +22 -0
- package/sandbox-natural/stdlib/nasl.ui.d.ts +78 -0
- package/sandbox-natural/stdlib/nasl.ui.h5.d.ts +1684 -1643
- package/sandbox-natural/stdlib/nasl.ui.h5.json +15746 -15045
- package/sandbox-natural/stdlib/nasl.ui.pc.d.ts +5341 -5154
- package/sandbox-natural/stdlib/nasl.ui.pc.json +31176 -30681
- package/sandbox-natural/stdlib/{nasl.util.ts → nasl.util.d.ts} +49 -43
- package/src/common/BaseNode.ts +5 -3
- package/src/common/ComponentAPI.ts +7 -0
- package/src/concepts/AuthLogicForCallInterface__.ts +23 -6
- package/src/concepts/BackendVariable__.ts +16 -1
- package/src/concepts/BindAttribute__.ts +18 -13
- package/src/concepts/BindDirective__.ts +1 -1
- package/src/concepts/BindStyle__.ts +1 -1
- package/src/concepts/BusinessComponent__.ts +26 -8
- package/src/concepts/BusinessLogic__.ts +23 -6
- package/src/concepts/CallInterface__.ts +2 -2
- package/src/concepts/CallLogic__.ts +50 -24
- package/src/concepts/CallQueryComponent__.ts +26 -12
- package/src/concepts/Destination__.ts +14 -12
- package/src/concepts/EntityProperty__.ts +5 -5
- package/src/concepts/Entity__.ts +1 -1
- package/src/concepts/Interface__.ts +1 -1
- package/src/concepts/Logic__.ts +62 -33
- package/src/concepts/MemberExpression__.ts +20 -13
- package/src/concepts/OqlQueryComponent__.ts +29 -5
- package/src/concepts/OverriddenLogic__.ts +23 -6
- package/src/concepts/Param__.ts +5 -4
- package/src/concepts/QueryOrderByExpression__.ts +0 -1
- package/src/concepts/Structure__.ts +5 -7
- package/src/concepts/Variable__.ts +9 -5
- package/src/concepts/ViewElement__.ts +25 -9
- package/src/concepts/View__.ts +97 -37
- package/src/concepts/basics/stdlib/nasl.processV2.ts +79 -0
- package/src/concepts/basics/stdlib/nasl.ui.ts +40 -40
- package/src/generator/genBundleFiles.ts +1 -1
- package/src/generator/release-body/utils.ts +1 -1
- package/src/natural/genNaturalTS.ts +88 -39
- package/src/natural/getContext/getUILib.ts +6 -3
- package/src/natural/getContext/index.ts +125 -23
- package/src/natural/getContext/naslStdlibMap.ts +8 -8
- package/src/natural/tools.ts +107 -2
- package/src/natural/transformTS2UI.ts +205 -147
- package/src/natural/transformTSCode.ts +29 -1055
- package/src/natural/transforms/registerTransform.ts +34 -0
- package/src/natural/transforms/transform2LogicItem.ts +1335 -0
- package/src/natural/transforms/transform2TypeAnnotation.ts +77 -0
- package/src/natural/transforms/utils.ts +25 -0
- package/src/server/getLogics.ts +12 -12
- package/src/server/getMemberIdentifier.ts +14 -14
- package/src/server/naslServer.ts +39 -19
- package/src/server/translator.ts +5 -0
- package/src/templator/block2nasl/jsx2nasl/index.ts +11 -0
- package/src/templator/block2nasl/jsx2nasl/transform-expression2nasl.ts +238 -0
- package/src/templator/block2nasl/jsx2nasl/transform-func2nasl.ts +241 -0
- package/src/templator/block2nasl/jsx2nasl/transform-tstype2nasl.ts +213 -0
- package/src/templator/block2nasl/jsx2nasl/transform-tsx2nasl.ts +422 -0
- package/src/templator/block2nasl/jsx2nasl/utils.ts +19 -0
- package/src/templator/block2nasl/transformBlock2Nasl.ts +99 -0
- package/src/templator/block2nasl/viewMergeBlock.ts +149 -0
- package/src/translator/types.ts +2 -0
- package/src/translator/utils.ts +1 -1
- package/src/utils/index.ts +0 -4
- package/src/utils/language-cache/constant.ts +1 -0
- package/src/utils/language-cache/nasl.ts +6 -0
- package/test/concepts/member-expression/__snapshots__/toJS.spec.ts.snap +1 -1
- package/test/concepts/member-expression/__snapshots__/toVue.spec.ts.snap +1 -1
- package/test/tdd/dataQuery/QueryFieldExpression/case1/ast.json +7 -0
- package/test/tdd/dataQuery/QueryFieldExpression/case1/natural.ts.txt +1 -0
- package/test/tdd/dataQuery/QueryFieldExpression/case2/ast.json +7 -0
- package/test/tdd/dataQuery/QueryFieldExpression/case2/natural.ts.txt +1 -0
- package/test/tdd/transform/case1/ast.json +243 -0
- package/test/tdd/transform/case1/natural.ts.md +20 -0
- package/test/tdd/transform/case2/ast.json +207 -0
- package/test/tdd/transform/case2/natural.ts.md +12 -0
- package/test/tdd.test.js +10 -0
- package/test/tdd.transform.test.js +38 -0
- package/test/utils.js +40 -0
- package/sandbox-natural/stdlib/nasl.core.ts +0 -36
- package/sandbox-natural/stdlib/nasl.oql.ts +0 -14
- package/sandbox-natural/stdlib/nasl.ui.pre.d.ts +0 -90
- package/sandbox-natural/stdlib/nasl.ui.ts +0 -63
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { babelTypes, naslTypes, generate, DEBUG, throwError, tryParseTS } from './utils';
|
|
2
|
+
|
|
3
|
+
export function transform2TypeAnnotation(node: babelTypes.TSType): naslTypes.TypeAnnotation {
|
|
4
|
+
if (!node) return null;
|
|
5
|
+
if (node.type === 'TSTypeReference') {
|
|
6
|
+
const typeName = (node.typeName as babelTypes.Identifier).name;
|
|
7
|
+
const primitiveType = naslTypes.primitiveTypeList.find((ta) => ta.typeName === typeName);
|
|
8
|
+
if ((node as any)?.typeNamespace) {
|
|
9
|
+
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
10
|
+
typeNamespace: (node as any).typeNamespace,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (['ValidateResult', 'ValidateEvent'].includes(typeName)) {
|
|
15
|
+
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
16
|
+
typeNamespace: 'nasl.ui'
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeName === 'Any' || typeName === 'any') {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
if (typeName === 'Integer') {
|
|
24
|
+
return naslTypes.TypeAnnotation.createPrimitive('Long');
|
|
25
|
+
}
|
|
26
|
+
if (primitiveType) {
|
|
27
|
+
return naslTypes.TypeAnnotation.createPrimitive(typeName);
|
|
28
|
+
}
|
|
29
|
+
if (['List', 'Map', 'Current'].includes(typeName) && node?.typeParameters) {
|
|
30
|
+
return naslTypes.TypeAnnotation.createGeneric(typeName, {
|
|
31
|
+
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (node?.typeName?.type === 'TSQualifiedName' && node?.typeParameters) {
|
|
35
|
+
const curTypeName = (node?.typeName as any)?.right?.name;
|
|
36
|
+
return naslTypes.TypeAnnotation.createGeneric(curTypeName, {
|
|
37
|
+
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (!node.typeParameters) {
|
|
41
|
+
if (node?.typeName?.type === 'TSQualifiedName') {
|
|
42
|
+
const allTypeName = generate(node?.typeName?.left as any)?.code;
|
|
43
|
+
// 实体、枚举、结构体
|
|
44
|
+
if (/^app.dataSources|.enums|.structures/.test(allTypeName)) {
|
|
45
|
+
const curTypeName = (node?.typeName as any)?.right?.name;
|
|
46
|
+
return naslTypes.TypeAnnotation.createReference(curTypeName, {
|
|
47
|
+
typeNamespace: allTypeName,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
52
|
+
typeNamespace: null,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
throwError(`Unhandled node ${node.type}`);
|
|
56
|
+
} else if (node.type === 'TSTypeLiteral') {
|
|
57
|
+
return naslTypes.TypeAnnotation.createTypeAnonymousStructure(node.members.map((member: babelTypes.TSPropertySignature) => new naslTypes.StructureProperty({
|
|
58
|
+
name: (member.key as babelTypes.Identifier).name,
|
|
59
|
+
typeAnnotation: transform2TypeAnnotation(member.typeAnnotation.typeAnnotation),
|
|
60
|
+
})));
|
|
61
|
+
} else if (node.type === 'TSBooleanKeyword') {
|
|
62
|
+
return naslTypes.TypeAnnotation.createPrimitive('Boolean');
|
|
63
|
+
} else if (node.type === 'TSStringKeyword') {
|
|
64
|
+
return naslTypes.TypeAnnotation.createPrimitive('String');
|
|
65
|
+
} else if (node.type === 'TSNumberKeyword') {
|
|
66
|
+
return naslTypes.TypeAnnotation.createPrimitive('Double');
|
|
67
|
+
} else if (node.type === 'TSUnionType') {
|
|
68
|
+
const union = naslTypes.TypeAnnotation.createPrimitive('Union');
|
|
69
|
+
union.typeArguments = [];
|
|
70
|
+
node.types.forEach((curType) => {
|
|
71
|
+
union.typeArguments.push(transform2TypeAnnotation(curType));
|
|
72
|
+
});
|
|
73
|
+
return union;
|
|
74
|
+
} else {
|
|
75
|
+
throwError(`Unhandled node ${node.type}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as babel from '@babel/core';
|
|
2
|
+
import * as babelTypes from '@babel/types';
|
|
3
|
+
import * as naslTypes from '../../concepts';
|
|
4
|
+
import generate from '@babel/generator';
|
|
5
|
+
|
|
6
|
+
export { babelTypes, naslTypes, generate };
|
|
7
|
+
|
|
8
|
+
export const DEBUG = false;
|
|
9
|
+
export function throwError(message: string) {
|
|
10
|
+
if (DEBUG) throw new Error(message);
|
|
11
|
+
else console.error(message);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function tryParseTS(tsCode: string) {
|
|
15
|
+
try {
|
|
16
|
+
const root = babel.parseSync(tsCode, {
|
|
17
|
+
filename: 'result.ts',
|
|
18
|
+
presets: [require('@babel/preset-typescript')],
|
|
19
|
+
});
|
|
20
|
+
// console.log((root as any).program.body[0].body.body.map((item) => item.trailingComments));
|
|
21
|
+
return root;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/server/getLogics.ts
CHANGED
|
@@ -213,19 +213,19 @@ export function getLogicsSync(node: CallLogic | BindEvent | Identifier | Logic,
|
|
|
213
213
|
path: `${app.getNamespace()}.logics`,
|
|
214
214
|
title: '服务端逻辑',
|
|
215
215
|
logics: javaLogicDataSourceLogics(app.logics).globalLogics,
|
|
216
|
-
children: [
|
|
217
|
-
...nc,
|
|
218
|
-
...extensions,
|
|
219
|
-
...dependEntityNs,
|
|
220
|
-
...ps,
|
|
221
|
-
new Namespace({
|
|
222
|
-
name: 'javalogicCategory',
|
|
223
|
-
title: '扩展逻辑',
|
|
224
|
-
logics: javaLogicDataSourceLogics(app.logics).javaLogics,
|
|
225
|
-
expanded: false,
|
|
226
|
-
}),
|
|
227
|
-
],
|
|
228
216
|
});
|
|
217
|
+
tree.children = [
|
|
218
|
+
...nc,
|
|
219
|
+
...extensions,
|
|
220
|
+
...dependEntityNs,
|
|
221
|
+
...ps,
|
|
222
|
+
new Namespace({
|
|
223
|
+
name: 'javalogicCategory',
|
|
224
|
+
title: '扩展逻辑',
|
|
225
|
+
logics: javaLogicDataSourceLogics(app.logics).javaLogics,
|
|
226
|
+
expanded: false,
|
|
227
|
+
}),
|
|
228
|
+
];
|
|
229
229
|
tree.expanded = false;
|
|
230
230
|
result.push(tree);
|
|
231
231
|
}
|
|
@@ -15,9 +15,9 @@ import {
|
|
|
15
15
|
types,
|
|
16
16
|
ViewElement,
|
|
17
17
|
PAGE_COMPONENT_INCLUDE_TAG_MAP,
|
|
18
|
-
ComponentCompletionPropertyMap,
|
|
19
18
|
configurationEnums,
|
|
20
19
|
processV2Enums,
|
|
20
|
+
config,
|
|
21
21
|
} from '..';
|
|
22
22
|
import { formatVariableData, formatFrontEndVariables, formatConfigProperties, formatBackendVariables } from './formatTsUtils';
|
|
23
23
|
|
|
@@ -422,8 +422,8 @@ export function getConfigsIdentifier(node: BaseNode): CompletionProperty[] {
|
|
|
422
422
|
}
|
|
423
423
|
function flatElements(elements: ViewElement[], componentList: CompletionProperty[], nodeParentElement: string, currentAttriBute: string, parentNodeNames: string[]) {
|
|
424
424
|
elements?.forEach((item) => {
|
|
425
|
-
// 根据
|
|
426
|
-
if (
|
|
425
|
+
// 根据readablePropsMap添加
|
|
426
|
+
if (config?.allNodesAPI[item.tag] && config?.allNodesAPI[item.tag].readablePropsMap) {
|
|
427
427
|
// 是否当前组件
|
|
428
428
|
const isCurrent = item.name === nodeParentElement;
|
|
429
429
|
const stashItem: any = {
|
|
@@ -436,9 +436,9 @@ function flatElements(elements: ViewElement[], componentList: CompletionProperty
|
|
|
436
436
|
children: [],
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
-
for (const key in
|
|
440
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
441
|
-
const property =
|
|
439
|
+
for (const key in config?.allNodesAPI[item.tag].readablePropsMap) {
|
|
440
|
+
if (Object.prototype.hasOwnProperty.call(config?.allNodesAPI[item.tag].readablePropsMap, key)) {
|
|
441
|
+
const property = config?.allNodesAPI[item.tag].readablePropsMap[key];
|
|
442
442
|
|
|
443
443
|
// 如果是当前组件,过滤掉当前属性
|
|
444
444
|
if (!isCurrent || currentAttriBute !== property.prop) {
|
|
@@ -454,7 +454,7 @@ function flatElements(elements: ViewElement[], componentList: CompletionProperty
|
|
|
454
454
|
})
|
|
455
455
|
})
|
|
456
456
|
|
|
457
|
-
completionProperty.name = `${key}(${property.
|
|
457
|
+
completionProperty.name = `${key}(${property.title})`;
|
|
458
458
|
completionProperty.icon = property.icon || 'attr'
|
|
459
459
|
stashItem.children.push(completionProperty)
|
|
460
460
|
}
|
|
@@ -511,21 +511,21 @@ function getCurrentElement(item: any): ViewElement | undefined {
|
|
|
511
511
|
if (!item?.parentNode) return undefined
|
|
512
512
|
if (item.parentNode?.concept === 'ViewElement') {
|
|
513
513
|
return item.parentNode
|
|
514
|
-
}
|
|
514
|
+
} if (item.parentNode?.concept === 'View') {
|
|
515
515
|
return undefined
|
|
516
|
-
} else {
|
|
517
|
-
return getCurrentElement(item.parentNode)
|
|
518
516
|
}
|
|
517
|
+
return getCurrentElement(item.parentNode)
|
|
518
|
+
|
|
519
519
|
}
|
|
520
520
|
|
|
521
521
|
function getCurrentAttriBute(item: any): BindAttribute | undefined {
|
|
522
522
|
if (item.concept === 'BindAttribute') {
|
|
523
523
|
return item
|
|
524
|
-
}
|
|
524
|
+
}
|
|
525
525
|
if (item?.parentNode && item.parentNode?.concept !== 'View') {
|
|
526
526
|
return getCurrentAttriBute(item.parentNode)
|
|
527
|
-
} else {
|
|
528
|
-
return undefined
|
|
529
527
|
}
|
|
530
|
-
|
|
528
|
+
return undefined
|
|
529
|
+
|
|
530
|
+
|
|
531
531
|
}
|
package/src/server/naslServer.ts
CHANGED
|
@@ -102,6 +102,7 @@ import {
|
|
|
102
102
|
ProcessBindV2,
|
|
103
103
|
ValidationRule,
|
|
104
104
|
SubLogic,
|
|
105
|
+
AuthLogicForCallInterface
|
|
105
106
|
} from '../concepts';
|
|
106
107
|
|
|
107
108
|
import * as utils from '../utils';
|
|
@@ -121,7 +122,7 @@ import { EventEmitter } from '../common/EventEmitter';
|
|
|
121
122
|
import { traverse, FileNode } from '../utils';
|
|
122
123
|
import { withQueueExecute } from '../decorators';
|
|
123
124
|
import { getNodeByNodeCallee } from '../automate/engine/utils';
|
|
124
|
-
import { isConnection, isConnector, isMsgTriggerEvent, isProcess, isProcessV2, isStrictLogic } from '../concepts/utils/asserts';
|
|
125
|
+
import { isApp, isConnection, isConnector, isMsgTriggerEvent, isProcess, isProcessV2, isStrictLogic } from '../concepts/utils/asserts';
|
|
125
126
|
|
|
126
127
|
const EmbeddedTSFileLineMap: { [name: string]: number } = {
|
|
127
128
|
Entity: 3,
|
|
@@ -653,7 +654,7 @@ class NaslServer {
|
|
|
653
654
|
app.naslServer = this;
|
|
654
655
|
const self = this;
|
|
655
656
|
this.performance = performance;
|
|
656
|
-
const results = await utils.
|
|
657
|
+
const results = await utils.runGeneratorAsync(getAllTsFiles());
|
|
657
658
|
const files = results.map((result) => ({
|
|
658
659
|
file: result.filePath,
|
|
659
660
|
fileContent: result.code,
|
|
@@ -3298,7 +3299,13 @@ class NaslServer {
|
|
|
3298
3299
|
});
|
|
3299
3300
|
refsList = [...newRefs.refs];
|
|
3300
3301
|
} else if (node instanceof Module && !(node instanceof Connector)) {
|
|
3301
|
-
|
|
3302
|
+
// 数组有长度的情况下,才去查找
|
|
3303
|
+
const { logics, structures, enums, interfaces } = node;
|
|
3304
|
+
const lists = (logics?.length && logics) ||
|
|
3305
|
+
(structures?.length && structures) ||
|
|
3306
|
+
(enums?.length && enums) ||
|
|
3307
|
+
(interfaces?.length && interfaces);
|
|
3308
|
+
// const lists = node.logics || node.structures || node.enums;
|
|
3302
3309
|
const moduleName = (fileNode as FileNode).getEmbeddedFilePath();
|
|
3303
3310
|
if (lists.length) {
|
|
3304
3311
|
const item = lists[0];
|
|
@@ -4900,39 +4907,52 @@ class NaslServer {
|
|
|
4900
4907
|
|
|
4901
4908
|
// 全量标注并且返回json
|
|
4902
4909
|
@withQueueExecute('annotation')
|
|
4903
|
-
async getNaslAnnotatedJSON(
|
|
4910
|
+
async getNaslAnnotatedJSON(naslNode: App | Logic | AuthLogicForCallInterface, releaseFlag: boolean) {
|
|
4911
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
4912
|
+
const isApp = asserts.isApp(naslNode);
|
|
4904
4913
|
if (this.changeStackList?.length) {
|
|
4905
4914
|
throw new Error(`当前还有${this.changeStackList.length}个文件还在执行更新操作`);
|
|
4906
4915
|
}
|
|
4907
|
-
this.logger.time('
|
|
4916
|
+
this.logger.time(`${ isApp ? '全量' : '单文件' }标注`);
|
|
4908
4917
|
const nodes: QuickInfoNodes = [];
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
item,
|
|
4917
|
-
});
|
|
4918
|
+
if (!isApp) {
|
|
4919
|
+
const filePath = naslNode?.getEmbeddedFilePath();
|
|
4920
|
+
naslNode.sourceMap.forEach((item, node) => {
|
|
4921
|
+
nodes.push({
|
|
4922
|
+
filePath,
|
|
4923
|
+
node,
|
|
4924
|
+
item,
|
|
4918
4925
|
});
|
|
4919
|
-
}
|
|
4920
|
-
}
|
|
4926
|
+
});
|
|
4927
|
+
} else {
|
|
4928
|
+
this.file2NodeMap.forEach((fileNode, filePath) => {
|
|
4929
|
+
// 先不排除view,传递给后端的时候,去除views下的标注
|
|
4930
|
+
if (!['DataSource','Enum', 'Role'].includes(fileNode.concept)) {
|
|
4931
|
+
fileNode.sourceMap.forEach((item, node) => {
|
|
4932
|
+
nodes.push({
|
|
4933
|
+
filePath,
|
|
4934
|
+
node,
|
|
4935
|
+
item,
|
|
4936
|
+
});
|
|
4937
|
+
});
|
|
4938
|
+
}
|
|
4939
|
+
});
|
|
4940
|
+
}
|
|
4921
4941
|
const typesMap = await this.getQuickInfoNodesTypeMap(nodes, true);
|
|
4922
4942
|
|
|
4923
4943
|
console.time('app toJSON');
|
|
4924
4944
|
const jsonMap = new Map();
|
|
4925
|
-
const json =
|
|
4945
|
+
const json = naslNode._toJSON((source, instance) => {
|
|
4926
4946
|
jsonMap.set(instance, source);
|
|
4927
4947
|
return source;
|
|
4928
4948
|
});
|
|
4929
4949
|
console.timeEnd('app toJSON');
|
|
4930
4950
|
|
|
4931
|
-
this.logger.timeEnd('
|
|
4951
|
+
this.logger.timeEnd(`${ isApp ? '全量' : '单文件' }标注`);
|
|
4932
4952
|
|
|
4933
4953
|
// 测试环境或者是调试模式打印数据
|
|
4934
4954
|
if (utils.isDebugMode || utils.isTestBrowser) {
|
|
4935
|
-
this.logger.info('
|
|
4955
|
+
this.logger.info(`${ isApp ? '全量' : '单文件' }标注数据`, json);
|
|
4936
4956
|
}
|
|
4937
4957
|
|
|
4938
4958
|
if (releaseFlag) {
|
package/src/server/translator.ts
CHANGED
|
@@ -332,6 +332,11 @@ const TS_RULES: Array<{
|
|
|
332
332
|
re: /Cannot find name '__UNSUPPORTED__ENTITY__FIELDS__'./,
|
|
333
333
|
result: '可能为实体属性别名,动态条件中仅支持使用变量',
|
|
334
334
|
},
|
|
335
|
+
{
|
|
336
|
+
re: /Cannot find name '__UNDEFINED__VARIABLE__(.+?)__'./,
|
|
337
|
+
result: '所选择的内容 $1 未定义。',
|
|
338
|
+
transforms: [outOriginalvalue],
|
|
339
|
+
},
|
|
335
340
|
{
|
|
336
341
|
re: /No value exists in scope for the shorthand property '__(?:IDENTIFIER|LEFT|RIGHT)__'. Either declare one or provide an initializer./,
|
|
337
342
|
result: '用户任务未关联页面',
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import transformExpression2nasl from './transform-expression2nasl';
|
|
2
|
+
import transformTsType2Nasl from './transform-tstype2nasl';
|
|
3
|
+
import transformFunc2Nasl from './transform-func2nasl';
|
|
4
|
+
import transformTSX2Nasl from './transform-tsx2nasl';
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
transformExpression2nasl,
|
|
8
|
+
transformTsType2Nasl,
|
|
9
|
+
transformFunc2Nasl,
|
|
10
|
+
transformTSX2Nasl,
|
|
11
|
+
};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/* eslint-disable no-use-before-define */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import {
|
|
4
|
+
ArrowFunctionExpression,
|
|
5
|
+
CallExpression,
|
|
6
|
+
Expression,
|
|
7
|
+
ObjectExpression,
|
|
8
|
+
} from '@babel/types';
|
|
9
|
+
import generate from '@babel/generator';
|
|
10
|
+
import { getNodeCode } from './utils';
|
|
11
|
+
import { transformParam2Nasl } from './transform-func2nasl';
|
|
12
|
+
import transformTypeAnnotation from './transform-tstype2nasl';
|
|
13
|
+
|
|
14
|
+
const getNamespace = (ast) => {
|
|
15
|
+
if (ast.object && ast.object.name === 'nasl' && ast.property && ast.property.name) {
|
|
16
|
+
return `nasl.${ast.property.name}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return '';
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function transformObjectExpression2Nasl(ast: ObjectExpression) {
|
|
23
|
+
const newMap: any = {
|
|
24
|
+
concept: 'NewMap',
|
|
25
|
+
keys: [],
|
|
26
|
+
values: [],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
ast.properties.forEach((property) => {
|
|
30
|
+
if (property.type === 'ObjectMethod' || property.type === 'SpreadElement' || property.key.type === 'PrivateName') {
|
|
31
|
+
throw new Error(`解析Expression失败,nasl未支持该表达式, ${getNodeCode(ast)}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
newMap.keys.push(transformExpression2Nasl(property.key));
|
|
35
|
+
newMap.values.push(transformExpression2Nasl(property.value as any));
|
|
36
|
+
});
|
|
37
|
+
return newMap;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getCallName(code: string) {
|
|
41
|
+
let namespace = '';
|
|
42
|
+
let name = '';
|
|
43
|
+
|
|
44
|
+
const arr = code.split('.');
|
|
45
|
+
|
|
46
|
+
if (code.startsWith('$refs.')) {
|
|
47
|
+
arr[0] = 'elements';
|
|
48
|
+
arr.splice(arr.length - 1, 0, 'logics');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
namespace = arr.slice(0, arr.length - 1).join('.');
|
|
52
|
+
name = arr[arr.length - 1];
|
|
53
|
+
|
|
54
|
+
const Entity = 'Entity';
|
|
55
|
+
if (namespace.endsWith(Entity)) {
|
|
56
|
+
namespace = `${namespace.substring(0, namespace.lastIndexOf(Entity))}.logics`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return { namespace, name };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function transformCallExpress2Nasl(ast: CallExpression) {
|
|
63
|
+
if (ast.callee.type === 'Super' || ast.callee.type === 'V8IntrinsicIdentifier') {
|
|
64
|
+
throw new Error(`解析CallExpression 失败,${getNodeCode(ast)}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const code = getNodeCode(ast.callee);
|
|
68
|
+
const { namespace, name } = getCallName(code);
|
|
69
|
+
|
|
70
|
+
const args = ast.arguments.map((arg) => {
|
|
71
|
+
if (arg.type === 'JSXNamespacedName' || arg.type === 'SpreadElement' || arg.type === 'ArgumentPlaceholder') {
|
|
72
|
+
throw new Error(`解析CallExpression 失败,不支持参数类型,${getNodeCode(ast)}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
concept: 'Argument',
|
|
77
|
+
keyword: '',
|
|
78
|
+
expression: transformExpression2Nasl(arg),
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const SHORTCUT_NAMES = ['consoleLog', 'jsonSerialize', 'jsonDeserialize'];
|
|
83
|
+
if (namespace === 'nasl.util') {
|
|
84
|
+
return {
|
|
85
|
+
concept: 'CallFunction',
|
|
86
|
+
calleeNamespace: namespace,
|
|
87
|
+
calleeName: name,
|
|
88
|
+
shortcut: SHORTCUT_NAMES.indexOf(name) !== -1,
|
|
89
|
+
arguments: args,
|
|
90
|
+
typeArguments: ast.typeParameters ? ast.typeParameters.params.map((tsType) => transformTypeAnnotation(tsType)) : [],
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
concept: 'CallLogic',
|
|
96
|
+
arguments: args,
|
|
97
|
+
calleeNamespace: namespace,
|
|
98
|
+
calleeName: name,
|
|
99
|
+
shortcut: namespace === 'nasl.ui',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function transformArrowFunctionExpression(ast: ArrowFunctionExpression) {
|
|
104
|
+
if (ast.body.type === 'BlockStatement') {
|
|
105
|
+
throw new Error(`解析Expression失败,箭头函数仅支持表达式, ${getNodeCode(ast)}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
concept: 'AnonymousFunction',
|
|
110
|
+
params: ast.params.map((p) => transformParam2Nasl(p)),
|
|
111
|
+
body: transformExpression2Nasl(ast.body),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function transformExpression2Nasl(ast: Expression, namespace = '') {
|
|
116
|
+
switch (ast.type) {
|
|
117
|
+
case 'MemberExpression':
|
|
118
|
+
// eslint-disable-next-line no-case-declarations
|
|
119
|
+
const ns = getNamespace(ast.object);
|
|
120
|
+
if (ast.property.type === 'PrivateName') {
|
|
121
|
+
throw new Error(`Expression 解析失败,不支持 PrivateName, ${getNodeCode(ast)}`);
|
|
122
|
+
}
|
|
123
|
+
// object如果返回字符串,则将它当成namespace处理
|
|
124
|
+
if (ns) {
|
|
125
|
+
return transformExpression2Nasl(ast.property, ns);
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
concept: 'MemberExpression',
|
|
129
|
+
name: '',
|
|
130
|
+
kind: 'Expression',
|
|
131
|
+
object: transformExpression2Nasl(ast.object),
|
|
132
|
+
property: transformExpression2Nasl(ast.property),
|
|
133
|
+
};
|
|
134
|
+
case 'Identifier':
|
|
135
|
+
return {
|
|
136
|
+
concept: 'Identifier',
|
|
137
|
+
namespace,
|
|
138
|
+
name: ast.name,
|
|
139
|
+
kind: 'Expression',
|
|
140
|
+
};
|
|
141
|
+
case 'TemplateLiteral':
|
|
142
|
+
return {
|
|
143
|
+
concept: 'StringInterpolation',
|
|
144
|
+
kind: 'Expression',
|
|
145
|
+
name: '',
|
|
146
|
+
expressions: [...(ast.quasis || []), ...(ast.expressions || [])]
|
|
147
|
+
.sort((node1: any, node2: any) => {
|
|
148
|
+
return node1.start - node2.start;
|
|
149
|
+
})
|
|
150
|
+
.map((n: any) => {
|
|
151
|
+
return transformExpression2Nasl(n);
|
|
152
|
+
}),
|
|
153
|
+
};
|
|
154
|
+
case 'StringLiteral':
|
|
155
|
+
return {
|
|
156
|
+
concept: 'StringLiteral',
|
|
157
|
+
kind: 'Expression',
|
|
158
|
+
name: '',
|
|
159
|
+
value: ast.value,
|
|
160
|
+
};
|
|
161
|
+
case 'NumericLiteral':
|
|
162
|
+
return {
|
|
163
|
+
concept: 'NumericLiteral',
|
|
164
|
+
value: String(ast.value),
|
|
165
|
+
typeAnnotation: {
|
|
166
|
+
concept: 'TypeAnnotation',
|
|
167
|
+
typeKind: 'primitive',
|
|
168
|
+
typeName: String(ast.value).includes('.') ? 'Decimal' : 'Long',
|
|
169
|
+
typeNamespace: 'nasl.core',
|
|
170
|
+
inferred: false,
|
|
171
|
+
ruleMap: new Map(),
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
case 'NullLiteral':
|
|
175
|
+
return {
|
|
176
|
+
concept: 'NullLiteral',
|
|
177
|
+
};
|
|
178
|
+
case 'BooleanLiteral':
|
|
179
|
+
return {
|
|
180
|
+
concept: 'BooleanLiteral',
|
|
181
|
+
value: String(ast.value),
|
|
182
|
+
};
|
|
183
|
+
case 'UnaryExpression':
|
|
184
|
+
if (ast.argument.type === 'NumericLiteral') {
|
|
185
|
+
return {
|
|
186
|
+
concept: 'NumericLiteral',
|
|
187
|
+
value: ast.operator + ast.argument.value,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
concept: 'UnaryExpression',
|
|
193
|
+
kind: 'Expression',
|
|
194
|
+
name: '',
|
|
195
|
+
operator: ast.operator,
|
|
196
|
+
argument: transformExpression2Nasl(ast.argument),
|
|
197
|
+
};
|
|
198
|
+
case 'LogicalExpression':
|
|
199
|
+
case 'BinaryExpression':
|
|
200
|
+
if (ast.left.type === 'PrivateName') {
|
|
201
|
+
throw new Error(`Expression 解析失败,不支持 PrivateName, ${getNodeCode(ast)}`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
concept: 'BinaryExpression',
|
|
206
|
+
operator: ast.operator,
|
|
207
|
+
left: transformExpression2Nasl(ast.left),
|
|
208
|
+
right: transformExpression2Nasl(ast.right),
|
|
209
|
+
};
|
|
210
|
+
case 'ArrayExpression':
|
|
211
|
+
return {
|
|
212
|
+
concept: 'NewList',
|
|
213
|
+
items: ast.elements.map((e) => {
|
|
214
|
+
if (!e || e.type === 'SpreadElement') {
|
|
215
|
+
throw new Error('解析Expression失败,数组中不允许出现 null, 或者 ...');
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return transformExpression2Nasl(e);
|
|
219
|
+
}),
|
|
220
|
+
};
|
|
221
|
+
case 'ObjectExpression':
|
|
222
|
+
return transformObjectExpression2Nasl(ast);
|
|
223
|
+
case 'AssignmentExpression':
|
|
224
|
+
return {
|
|
225
|
+
concept: 'Assignment',
|
|
226
|
+
left: transformExpression2Nasl(ast.left as any),
|
|
227
|
+
right: transformExpression2Nasl(ast.right),
|
|
228
|
+
};
|
|
229
|
+
case 'ArrowFunctionExpression':
|
|
230
|
+
return transformArrowFunctionExpression(ast);
|
|
231
|
+
case 'CallExpression':
|
|
232
|
+
return transformCallExpress2Nasl(ast);
|
|
233
|
+
default:
|
|
234
|
+
throw new Error(`解析Expression失败,nasl未支持该表达式, ${getNodeCode(ast)}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export default transformExpression2Nasl;
|