@lcap/nasl 3.8.0-beta.3 → 3.8.0-beta.5
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/automate/engine/utils.js +1 -2
- package/out/automate/engine/utils.js.map +1 -1
- package/out/bak/translator.js +1 -1
- package/out/bak/translator.js.map +1 -1
- package/out/common/BaseNode.js +7 -2
- package/out/common/BaseNode.js.map +1 -1
- package/out/concepts/App__.js +6 -1
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/Argument__.js +11 -5
- package/out/concepts/Argument__.js.map +1 -1
- package/out/concepts/AuthLogicForCallInterface__.js +3 -0
- package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
- package/out/concepts/BinaryExpression__.js +49 -2
- package/out/concepts/BinaryExpression__.js.map +1 -1
- package/out/concepts/BindAttribute__.d.ts +4 -3
- package/out/concepts/BindAttribute__.js +121 -42
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindEvent__.js +5 -42
- package/out/concepts/BindEvent__.js.map +1 -1
- package/out/concepts/BusinessComponent__.d.ts +1 -0
- package/out/concepts/BusinessComponent__.js +16 -0
- package/out/concepts/BusinessComponent__.js.map +1 -1
- package/out/concepts/BusinessLogic__.js +3 -0
- package/out/concepts/BusinessLogic__.js.map +1 -1
- package/out/concepts/CallConnector__.js +1 -1
- package/out/concepts/CallConnector__.js.map +1 -1
- package/out/concepts/CallFunction__.js +1 -1
- package/out/concepts/CallFunction__.js.map +1 -1
- package/out/concepts/CallLogic__.d.ts +6 -1
- package/out/concepts/CallLogic__.js +58 -17
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/Connection__.d.ts +4 -0
- package/out/concepts/Connection__.js +15 -0
- package/out/concepts/Connection__.js.map +1 -1
- package/out/concepts/DatabaseTypeAnnotation__.d.ts +2 -0
- package/out/concepts/DatabaseTypeAnnotation__.js +20 -0
- package/out/concepts/DatabaseTypeAnnotation__.js.map +1 -1
- package/out/concepts/End__.js +5 -1
- package/out/concepts/End__.js.map +1 -1
- package/out/concepts/EntityProperty__.js +2 -0
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/Entity__.d.ts +1 -0
- package/out/concepts/Entity__.js +24 -1
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/EnumItem__.d.ts +12 -0
- package/out/concepts/EnumItem__.js +49 -5
- package/out/concepts/EnumItem__.js.map +1 -1
- package/out/concepts/Enum__.js +4 -1
- package/out/concepts/Enum__.js.map +1 -1
- package/out/concepts/ForEachStatement__.js +1 -1
- package/out/concepts/ForEachStatement__.js.map +1 -1
- package/out/concepts/FrontendLibrary__.d.ts +46 -46
- package/out/concepts/FrontendLibrary__.js +34 -36
- package/out/concepts/FrontendLibrary__.js.map +1 -1
- package/out/concepts/I18nInfo__.d.ts +1 -0
- package/out/concepts/I18nInfo__.js +7 -0
- package/out/concepts/I18nInfo__.js.map +1 -1
- package/out/concepts/IfStatement__.js +2 -2
- package/out/concepts/IfStatement__.js.map +1 -1
- package/out/concepts/Interface__.js +4 -1
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/Logic__.d.ts +2 -3
- package/out/concepts/Logic__.js +33 -8
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MatchCase__.d.ts +2 -2
- package/out/concepts/MatchCase__.js +7 -7
- package/out/concepts/MatchCase__.js.map +1 -1
- package/out/concepts/NewComposite__.js +2 -1
- package/out/concepts/NewComposite__.js.map +1 -1
- package/out/concepts/NewList__.js +2 -1
- package/out/concepts/NewList__.js.map +1 -1
- package/out/concepts/NewMap__.js +2 -1
- package/out/concepts/NewMap__.js.map +1 -1
- package/out/concepts/OqlQueryComponent__.js +3 -11
- package/out/concepts/OqlQueryComponent__.js.map +1 -1
- package/out/concepts/OverriddenLogic__.js +7 -0
- package/out/concepts/OverriddenLogic__.js.map +1 -1
- package/out/concepts/Param__.js +2 -1
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/ProcessElementV2__.d.ts +4 -5
- package/out/concepts/ProcessElementV2__.js +12 -17
- package/out/concepts/ProcessElementV2__.js.map +1 -1
- package/out/concepts/ProcessElement__.d.ts +3 -4
- package/out/concepts/ProcessElement__.js +44 -46
- package/out/concepts/ProcessElement__.js.map +1 -1
- package/out/concepts/ProcessV2__.d.ts +5 -0
- package/out/concepts/ProcessV2__.js +30 -2
- package/out/concepts/ProcessV2__.js.map +1 -1
- package/out/concepts/Process__.d.ts +5 -0
- package/out/concepts/Process__.js +28 -0
- package/out/concepts/Process__.js.map +1 -1
- package/out/concepts/QueryFromExpression__.js +2 -2
- package/out/concepts/QueryFromExpression__.js.map +1 -1
- package/out/concepts/QueryJoinExpression__.js +2 -2
- package/out/concepts/QueryJoinExpression__.js.map +1 -1
- package/out/concepts/Return__.d.ts +1 -1
- package/out/concepts/Return__.js +2 -1
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/StaticString__.d.ts +4 -0
- package/out/concepts/StaticString__.js +11 -0
- package/out/concepts/StaticString__.js.map +1 -1
- package/out/concepts/StructureProperty__.js +5 -2
- package/out/concepts/StructureProperty__.js.map +1 -1
- package/out/concepts/Structure__.js +9 -3
- package/out/concepts/Structure__.js.map +1 -1
- package/out/concepts/SubLogic__.d.ts +1 -3
- package/out/concepts/SubLogic__.js +14 -8
- package/out/concepts/SubLogic__.js.map +1 -1
- package/out/concepts/Transactional__.d.ts +1 -0
- package/out/concepts/Transactional__.js +7 -0
- package/out/concepts/Transactional__.js.map +1 -1
- package/out/concepts/TypeParam__.d.ts +4 -0
- package/out/concepts/TypeParam__.js +3 -0
- package/out/concepts/TypeParam__.js.map +1 -1
- package/out/concepts/ValidationRule__.d.ts +1 -6
- package/out/concepts/ValidationRule__.js +9 -6
- package/out/concepts/ValidationRule__.js.map +1 -1
- package/out/concepts/Variable__.d.ts +1 -1
- package/out/concepts/Variable__.js +7 -2
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +2 -0
- package/out/concepts/ViewElement__.js +130 -47
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.d.ts +8 -0
- package/out/concepts/View__.js +123 -7
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.processV2.js +2 -2
- package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.ui.js +1 -1
- package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.validation.js +110 -4
- package/out/concepts/basics/stdlib/nasl.validation.js.map +1 -1
- package/out/generator/genBundleFiles.d.ts +2 -0
- package/out/generator/genBundleFiles.js +51 -37
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/genMetaData.js +20 -26
- package/out/generator/genMetaData.js.map +1 -1
- package/out/generator/release-body/body.js +8 -6
- package/out/generator/release-body/body.js.map +1 -1
- package/out/generator/release-body/index.d.ts +1 -0
- package/out/generator/release-body/index.js +1 -0
- package/out/generator/release-body/index.js.map +1 -1
- package/out/generator/release-body/utils.js +1 -1
- package/out/generator/release-body/utils.js.map +1 -1
- package/out/natural/genNaturalTS.d.ts +56 -24
- package/out/natural/genNaturalTS.js +182 -112
- package/out/natural/genNaturalTS.js.map +1 -1
- package/out/natural/getContext/getUILib.js +4 -2
- package/out/natural/getContext/getUILib.js.map +1 -1
- package/out/natural/getContext/index.d.ts +34 -25
- package/out/natural/getContext/index.js +304 -157
- package/out/natural/getContext/index.js.map +1 -1
- package/out/natural/index.d.ts +1 -0
- package/out/natural/index.js +1 -0
- package/out/natural/index.js.map +1 -1
- package/out/natural/tools.d.ts +11 -0
- package/out/natural/tools.js +155 -0
- package/out/natural/tools.js.map +1 -0
- package/out/natural/transformTS2UI.js +84 -22
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.js +83 -22
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/server/formatTsUtils.js +17 -1
- package/out/server/formatTsUtils.js.map +1 -1
- package/out/server/getLogics.js +1 -4
- package/out/server/getLogics.js.map +1 -1
- package/out/server/naslServer.js +285 -32
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.js +5 -1
- package/out/server/translator.js.map +1 -1
- package/out/templator/genCreateBlock.js +5 -18
- package/out/templator/genCreateBlock.js.map +1 -1
- package/out/templator/genCurdMultipleKeyBlock.js +11 -32
- package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
- package/out/templator/genGetBlock.js +1 -2
- package/out/templator/genGetBlock.js.map +1 -1
- package/out/templator/genListViewBlock.js +6 -4
- package/out/templator/genListViewBlock.js.map +1 -1
- package/out/templator/genSelectBlock.js +82 -59
- package/out/templator/genSelectBlock.js.map +1 -1
- package/out/templator/genTableBlock.js +4 -4
- package/out/templator/genTableBlock.js.map +1 -1
- package/out/templator/genUpdateBlock.js +2 -15
- package/out/templator/genUpdateBlock.js.map +1 -1
- package/out/templator/utils.d.ts +1 -1
- package/out/templator/utils.js +1 -1
- package/out/templator/utils.js.map +1 -1
- package/out/translator/types.d.ts +4 -0
- package/out/translator/utils.d.ts +1 -0
- package/out/translator/utils.js +6 -1
- package/out/translator/utils.js.map +1 -1
- package/out/utils/env.d.ts +4 -0
- package/out/utils/env.js +6 -3
- package/out/utils/env.js.map +1 -1
- package/out/utils/index.d.ts +19 -0
- package/out/utils/index.js +61 -1
- package/out/utils/index.js.map +1 -1
- package/out/utils/language-cache/constant.d.ts +18 -0
- package/out/utils/language-cache/constant.js +35 -0
- package/out/utils/language-cache/constant.js.map +1 -0
- package/out/utils/language-cache/index.d.ts +2 -0
- package/out/utils/language-cache/index.js +19 -0
- package/out/utils/language-cache/index.js.map +1 -0
- package/out/utils/language-cache/nasl.d.ts +10 -0
- package/out/utils/language-cache/nasl.js +98 -0
- package/out/utils/language-cache/nasl.js.map +1 -0
- package/out/utils/language-cache/types.d.ts +44 -0
- package/out/utils/language-cache/types.js +4 -0
- package/out/utils/language-cache/types.js.map +1 -0
- package/out/utils/time-slicing/controller.js.map +1 -1
- package/out/utils/types.d.ts +17 -0
- package/package.json +3 -2
- package/sandbox/stdlib/nasl.core.ts +15 -11
- package/sandbox/stdlib/nasl.oql.ts +5 -1
- package/sandbox/stdlib/nasl.processV2.ts +5 -4
- package/sandbox/stdlib/nasl.ui.components.pc.ts +225 -225
- package/sandbox/stdlib/nasl.ui.ts +10 -0
- package/sandbox/stdlib/nasl.util.ts +11 -0
- package/sandbox/stdlib/nasl.validation.ts +3 -2
- package/sandbox-natural/stdlib/nasl.ui.pre.d.ts +1 -1
- package/sandbox-natural/stdlib/nasl.ui.ts +2 -2
- package/sandbox-natural/stdlib/nasl.util.ts +2 -2
- package/src/automate/engine/utils.js +1 -2
- package/src/bak/translator.js +1 -1
- package/src/common/BaseNode.ts +7 -3
- package/src/concepts/App__.ts +9 -1
- package/src/concepts/Argument__.ts +10 -5
- package/src/concepts/AuthLogicForCallInterface__.ts +3 -0
- package/src/concepts/BinaryExpression__.ts +46 -2
- package/src/concepts/BindAttribute__.ts +144 -46
- package/src/concepts/BindEvent__.ts +8 -47
- package/src/concepts/BusinessComponent__.ts +17 -0
- package/src/concepts/BusinessLogic__.ts +3 -0
- package/src/concepts/CallConnector__.ts +1 -1
- package/src/concepts/CallFunction__.ts +1 -1
- package/src/concepts/CallLogic__.ts +63 -17
- package/src/concepts/Connection__.ts +16 -0
- package/src/concepts/DatabaseTypeAnnotation__.ts +11 -0
- package/src/concepts/End__.ts +5 -1
- package/src/concepts/EntityProperty__.ts +5 -0
- package/src/concepts/Entity__.ts +29 -1
- package/src/concepts/EnumItem__.ts +64 -1
- package/src/concepts/Enum__.ts +6 -1
- package/src/concepts/ForEachStatement__.ts +1 -1
- package/src/concepts/FrontendLibrary__.ts +78 -80
- package/src/concepts/I18nInfo__.ts +5 -0
- package/src/concepts/IfStatement__.ts +2 -2
- package/src/concepts/Interface__.ts +6 -1
- package/src/concepts/Logic__.ts +39 -10
- package/src/concepts/MatchCase__.ts +8 -9
- package/src/concepts/NewComposite__.ts +2 -1
- package/src/concepts/NewList__.ts +2 -1
- package/src/concepts/NewMap__.ts +2 -1
- package/src/concepts/OqlQueryComponent__.ts +3 -11
- package/src/concepts/OverriddenLogic__.ts +7 -0
- package/src/concepts/Param__.ts +1 -0
- package/src/concepts/ProcessElementV2__.ts +14 -16
- package/src/concepts/ProcessElement__.ts +16 -16
- package/src/concepts/ProcessV2__.ts +39 -3
- package/src/concepts/Process__.ts +36 -0
- package/src/concepts/QueryFromExpression__.ts +2 -2
- package/src/concepts/QueryJoinExpression__.ts +2 -2
- package/src/concepts/Return__.ts +2 -1
- package/src/concepts/StaticString__.ts +12 -0
- package/src/concepts/StructureProperty__.ts +7 -2
- package/src/concepts/Structure__.ts +11 -3
- package/src/concepts/SubLogic__.ts +15 -9
- package/src/concepts/Transactional__.ts +5 -0
- package/src/concepts/TypeParam__.ts +6 -0
- package/src/concepts/ValidationRule__.ts +7 -6
- package/src/concepts/Variable__.ts +7 -2
- package/src/concepts/ViewElement__.ts +130 -47
- package/src/concepts/View__.ts +157 -8
- package/src/concepts/basics/stdlib/nasl.processV2.ts +2 -2
- package/src/concepts/basics/stdlib/nasl.ui.ts +1 -1
- package/src/concepts/basics/stdlib/nasl.validation.ts +111 -4
- package/src/generator/genBundleFiles.ts +53 -39
- package/src/generator/genMetaData.ts +21 -26
- package/src/generator/release-body/body.ts +9 -6
- package/src/generator/release-body/index.ts +1 -0
- package/src/generator/release-body/utils.ts +4 -2
- package/src/natural/genNaturalTS.ts +327 -141
- package/src/natural/getContext/getUILib.ts +4 -2
- package/src/natural/getContext/index.ts +348 -171
- package/src/natural/index.ts +1 -0
- package/src/natural/tools.ts +130 -0
- package/src/natural/transformTS2UI.ts +84 -22
- package/src/natural/transformTSCode.ts +83 -22
- package/src/server/formatTsUtils.ts +21 -1
- package/src/server/getLogics.ts +1 -4
- package/src/server/naslServer.ts +302 -33
- package/src/server/translator.ts +5 -1
- package/src/templator/genCreateBlock.ts +5 -18
- package/src/templator/genCurdMultipleKeyBlock.ts +14 -32
- package/src/templator/genGetBlock.ts +2 -4
- package/src/templator/genListViewBlock.ts +6 -4
- package/src/templator/genSelectBlock.ts +88 -61
- package/src/templator/genTableBlock.ts +4 -4
- package/src/templator/genUpdateBlock.ts +2 -15
- package/src/templator/utils.ts +1 -1
- package/src/translator/types.ts +4 -0
- package/src/translator/utils.ts +6 -0
- package/src/utils/env.ts +5 -4
- package/src/utils/index.ts +50 -1
- package/src/utils/language-cache/constant.ts +37 -0
- package/src/utils/language-cache/index.ts +2 -0
- package/src/utils/language-cache/nasl.ts +83 -0
- package/src/utils/language-cache/types.ts +48 -0
- package/src/utils/time-slicing/controller.ts +0 -1
- package/src/utils/types.ts +20 -0
- package/test/concepts/call-logic/__snapshots__/getQuickInfoOffset.spec.ts.snap +13 -13
- package/test/concepts/call-logic/__snapshots__/toEmbeddedTS.spec.ts.snap +12 -12
- package/test/concepts/validation-rule/__snapshots__/toEmbeddedTS.spec.ts.snap +1 -2
- package/test/concepts/view-element/__snapshots__/toEmbeddedTS.spec.ts.snap +221 -217
- package/ts-worker/bundle.js +1 -1
- package/ts-worker/src/index.js +0 -1
- package/out/utils/delay/index.d.ts +0 -0
- package/out/utils/delay/index.js +0 -1
- package/out/utils/delay/index.js.map +0 -1
- package/src/utils/delay/index.ts +0 -0
package/src/natural/index.ts
CHANGED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { App, BaseNode } from "src/concepts";
|
|
2
|
+
import * as utils from '../utils';
|
|
3
|
+
|
|
4
|
+
// 获取当前逻辑的类型
|
|
5
|
+
export const getLogicType = (activeLogic: any) => {
|
|
6
|
+
const { parentNode } = activeLogic || {};
|
|
7
|
+
let logicType = 'global_logic';
|
|
8
|
+
if (parentNode?.concept === 'View') {
|
|
9
|
+
logicType = 'view_logic';
|
|
10
|
+
} else if (parentNode?.concept === 'BindEvent') {
|
|
11
|
+
logicType = 'event_logic';
|
|
12
|
+
}
|
|
13
|
+
if (activeLogic?.concept === 'BusinessLogic') {
|
|
14
|
+
logicType = 'business_Logic';
|
|
15
|
+
}
|
|
16
|
+
return logicType;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// 获取所有未使用的 module
|
|
20
|
+
export const getUsedModule = (json: BaseNode) => {
|
|
21
|
+
const useModule = [] as any;
|
|
22
|
+
const conceptMap = ['CallInterface', 'CallConnector', 'CallLogic'];
|
|
23
|
+
utils.traverse(({ node }: { node: any; }) => {
|
|
24
|
+
if (conceptMap.includes(node.concept)) {
|
|
25
|
+
if (/(apis\.|connector\.|extensions\.)/.test(node.calleeNamespace)) {
|
|
26
|
+
const symbol = node.calleeNamespace.match(/(\w+)(?=\.)|(\w+$)/g)[1];
|
|
27
|
+
const item = {
|
|
28
|
+
symbol,
|
|
29
|
+
key: symbol,
|
|
30
|
+
node,
|
|
31
|
+
} as any;
|
|
32
|
+
useModule.push(item);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (node.concept === 'ViewElement') {
|
|
36
|
+
const symbol = utils.kebab2Camel(node.tag);
|
|
37
|
+
const item = {
|
|
38
|
+
symbol,
|
|
39
|
+
key: symbol,
|
|
40
|
+
node,
|
|
41
|
+
} as any;
|
|
42
|
+
useModule.push(item);
|
|
43
|
+
}
|
|
44
|
+
}, { node: json }, { mode: 'anyObject' });
|
|
45
|
+
return useModule;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 根据生成的 NASL JSON,获取未导入的模块
|
|
51
|
+
* @param json: 当前生成的 NASL JSON
|
|
52
|
+
* @param app: 当前应用
|
|
53
|
+
* @param material: 召回的所有 Module
|
|
54
|
+
* @returns 需要导入的所有 Module 信息,包含 category、symbol、version
|
|
55
|
+
*/
|
|
56
|
+
export const getUnImportedModulesForLogic = (json: BaseNode, app: App, material: any) => {
|
|
57
|
+
const useModule = getUsedModule(json);
|
|
58
|
+
const needImportModule = {
|
|
59
|
+
interfaces: new Map(),
|
|
60
|
+
connectors: new Map(),
|
|
61
|
+
library: new Map(),
|
|
62
|
+
extensionMaterials: new Map(),
|
|
63
|
+
needImportConnector: false
|
|
64
|
+
} as any;
|
|
65
|
+
|
|
66
|
+
useModule.forEach((item: any) => {
|
|
67
|
+
if (item.node.concept === 'CallInterface') {
|
|
68
|
+
// 从app.interfaceDependencies中找到对应的接口
|
|
69
|
+
const interfaceNode = app.interfaceDependencies.find((node: any) => node.name === item.symbol);
|
|
70
|
+
if (!interfaceNode) {
|
|
71
|
+
item.category = 'interface';
|
|
72
|
+
const key = `${item.symbol}-${item?.node?.calleeName}`;
|
|
73
|
+
item.key = key;
|
|
74
|
+
needImportModule.interfaces.set(key, item);
|
|
75
|
+
}
|
|
76
|
+
} else if (item.node.concept === 'CallConnector') {
|
|
77
|
+
item.category = 'connector';
|
|
78
|
+
const connectorNode = app.connectorDependencies.find((node: any) => node.name === item.symbol);
|
|
79
|
+
|
|
80
|
+
// 如果 连接器 不存在,则需要导入并初始化连接
|
|
81
|
+
if (!connectorNode) {
|
|
82
|
+
item.operator = 'importAndInit';
|
|
83
|
+
item.version = material?.connectors.find((node: any) => node.name === item.symbol).version;
|
|
84
|
+
needImportModule.needImportConnector = true;
|
|
85
|
+
} else {
|
|
86
|
+
item.version = connectorNode.version;
|
|
87
|
+
// 查找连接
|
|
88
|
+
const connection = app.connections.find((conn: any) => conn.connector.name === item.symbol);
|
|
89
|
+
// 如果 连接器 已存在,且连接已经被初始化过,需要修改生成 logic 中的名字,utils.traverse 修改
|
|
90
|
+
// 如果 连接器 已存在,且连接未被初始化过,则需要初始化连接
|
|
91
|
+
if (connection) {
|
|
92
|
+
item.operator = 'rename';
|
|
93
|
+
item.rename = { newName: connection.name, oldName: item.node.calleeConnectionName };
|
|
94
|
+
} else {
|
|
95
|
+
item.operator = 'init';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
needImportModule.connectors.set(item.symbol, item);
|
|
100
|
+
} else if (item.node.concept === 'CallLogic') {
|
|
101
|
+
// 从app.logicDependencies中找到对应的逻辑
|
|
102
|
+
item.category = 'library';
|
|
103
|
+
const logicNode = app.dependencies.find((node: any) => node.name === item.symbol);
|
|
104
|
+
if (!logicNode) {
|
|
105
|
+
item.version = material?.dependencies.find((node: any) => node.name === item.symbol).version;
|
|
106
|
+
needImportModule.library.set(item.symbol, item);
|
|
107
|
+
}
|
|
108
|
+
} else if (item.node.concept === 'ViewElement') {
|
|
109
|
+
const name = utils.kebab2Camel(item.node.tag);
|
|
110
|
+
const module = material?.extensionMaterials.find((node: any) => utils.kebab2Camel(node.name) === name);
|
|
111
|
+
const imported = app.dependencies.find((node: any) => node.name === module?.libraryName);
|
|
112
|
+
if (module && module.libraryName && !imported) {
|
|
113
|
+
const { libraryName } = module;
|
|
114
|
+
item.category = 'library';
|
|
115
|
+
item.key = `${libraryName}-${name}`;
|
|
116
|
+
item.symbol = libraryName;
|
|
117
|
+
item.version = material?.dependencies.find((node: any) => node.name === libraryName).version;
|
|
118
|
+
needImportModule.extensionMaterials.set(name, item);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
needImportModule.interfaces = Array.from(needImportModule.interfaces.values());
|
|
124
|
+
needImportModule.connectors = Array.from(needImportModule.connectors.values());
|
|
125
|
+
needImportModule.library = Array.from(needImportModule.library.values());
|
|
126
|
+
needImportModule.extensionMaterials = Array.from(needImportModule.extensionMaterials.values());
|
|
127
|
+
|
|
128
|
+
return needImportModule;
|
|
129
|
+
};
|
|
130
|
+
|
|
@@ -19,6 +19,13 @@ function flatMemberExpression(node: babelTypes.Node): Array<babelTypes.Node> {
|
|
|
19
19
|
return [...flatMemberExpression(node.object), node.property];
|
|
20
20
|
return [node];
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
function flatMembers(node: naslTypes.MemberExpression): Array<naslTypes.MemberExpression> {
|
|
24
|
+
if (node.concept === 'MemberExpression')
|
|
25
|
+
return [...flatMembers(((node as any)?.object)), node];
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
function flatMatchPatternsExpression(node: any): Array<babelTypes.Node> {
|
|
23
30
|
if (node.concept === 'BinaryExpression') {
|
|
24
31
|
if (node.operator === '||') {
|
|
@@ -65,6 +72,13 @@ function transformTypeAnnotation(node: babelTypes.TSType): naslTypes.TypeAnnotat
|
|
|
65
72
|
typeNamespace: (node as any).typeNamespace,
|
|
66
73
|
});
|
|
67
74
|
}
|
|
75
|
+
|
|
76
|
+
if (['ValidateResult', 'ValidateEvent'].includes(typeName)) {
|
|
77
|
+
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
78
|
+
typeNamespace: 'nasl.ui'
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
68
82
|
if (typeName === 'Any' || typeName === 'any') {
|
|
69
83
|
return undefined;
|
|
70
84
|
}
|
|
@@ -89,7 +103,7 @@ function transformTypeAnnotation(node: babelTypes.TSType): naslTypes.TypeAnnotat
|
|
|
89
103
|
if (node?.typeName?.type === 'TSQualifiedName') {
|
|
90
104
|
const allTypeName = generate(node?.typeName?.left as any)?.code;
|
|
91
105
|
// 实体、枚举、结构体
|
|
92
|
-
if (/^app.dataSources|.enums|.structures/.test(allTypeName)) {
|
|
106
|
+
if (/^app.dataSources|.enums|.structures|nasl.ui/.test(allTypeName)) {
|
|
93
107
|
const curTypeName = (node?.typeName as any)?.right?.name;
|
|
94
108
|
return naslTypes.TypeAnnotation.createReference(curTypeName, {
|
|
95
109
|
typeNamespace: allTypeName,
|
|
@@ -127,6 +141,8 @@ function transformTypeAnnotation(node: babelTypes.TSType): naslTypes.TypeAnnotat
|
|
|
127
141
|
// 处理参数
|
|
128
142
|
function transformParam(node: babelTypes.Identifier): naslTypes.Param {
|
|
129
143
|
const typeAnnotation = (node.typeAnnotation as babelTypes.TSTypeAnnotation)?.typeAnnotation;
|
|
144
|
+
const exclude = ['event'];
|
|
145
|
+
if (exclude.includes(node.name)) return null;
|
|
130
146
|
return new naslTypes.Param({
|
|
131
147
|
name: node.name,
|
|
132
148
|
typeAnnotation: typeAnnotation ? transformTypeAnnotation(typeAnnotation) : null,
|
|
@@ -219,14 +235,29 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
|
|
|
219
235
|
const assignmentLines: any = [];
|
|
220
236
|
node?.arguments?.[0]?.properties.forEach((arg: any, index: number) => {
|
|
221
237
|
properties.push(transformNode2Expression(arg.key));
|
|
222
|
-
|
|
223
|
-
expression
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
rightIndex: [index],
|
|
238
|
+
if (arg.value.type === 'MemberExpression') {
|
|
239
|
+
const expression = flatMemberExpression(arg.value);
|
|
240
|
+
const members = flatMembers(transformNode2Expression(arg.value) as any);
|
|
241
|
+
rights.push(new naslTypes.SelectMembers({
|
|
242
|
+
expression: transformNode2Expression(expression[0]),
|
|
243
|
+
members,
|
|
229
244
|
}));
|
|
245
|
+
if (arg?.value) {
|
|
246
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
247
|
+
leftIndex: [0, index],
|
|
248
|
+
rightIndex: [index, index],
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
} else {
|
|
252
|
+
rights.push(new naslTypes.SelectMembers({
|
|
253
|
+
expression: transformNode2Expression(arg.value)
|
|
254
|
+
}));
|
|
255
|
+
if (arg?.value) {
|
|
256
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
257
|
+
leftIndex: [0, index],
|
|
258
|
+
rightIndex: [index],
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
230
261
|
}
|
|
231
262
|
});
|
|
232
263
|
const parameters = node?.typeParameters?.params?.[0] || {};
|
|
@@ -261,14 +292,29 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
|
|
|
261
292
|
const assignmentLines: any = [];
|
|
262
293
|
node?.arguments?.[0]?.properties.forEach((arg: any, index: number) => {
|
|
263
294
|
properties.push(transformNode2Expression(arg.key));
|
|
264
|
-
|
|
265
|
-
expression
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
rightIndex: [index],
|
|
295
|
+
if (arg.value.type === 'MemberExpression') {
|
|
296
|
+
const expression = flatMemberExpression(arg.value);
|
|
297
|
+
const members = flatMembers(transformNode2Expression(arg.value) as any);
|
|
298
|
+
rights.push(new naslTypes.SelectMembers({
|
|
299
|
+
expression: transformNode2Expression(expression[0]),
|
|
300
|
+
members,
|
|
271
301
|
}));
|
|
302
|
+
if (arg?.value) {
|
|
303
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
304
|
+
leftIndex: [0, index],
|
|
305
|
+
rightIndex: [index, index],
|
|
306
|
+
}));
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
rights.push(new naslTypes.SelectMembers({
|
|
310
|
+
expression: transformNode2Expression(arg.value)
|
|
311
|
+
}));
|
|
312
|
+
if (arg?.value) {
|
|
313
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
314
|
+
leftIndex: [0, index],
|
|
315
|
+
rightIndex: [index],
|
|
316
|
+
}));
|
|
317
|
+
}
|
|
272
318
|
}
|
|
273
319
|
});
|
|
274
320
|
const parameters = node?.typeParameters?.params?.[0] || {};
|
|
@@ -304,14 +350,29 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
|
|
|
304
350
|
const assignmentLines: any = [];
|
|
305
351
|
node?.arguments?.[0]?.properties?.forEach((arg: any, index: number) => {
|
|
306
352
|
properties.push(transformNode2Expression(arg.key));
|
|
307
|
-
|
|
308
|
-
expression
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
rightIndex: [index],
|
|
353
|
+
if (arg.value.type === 'MemberExpression') {
|
|
354
|
+
const expression = flatMemberExpression(arg.value);
|
|
355
|
+
const members = flatMembers(transformNode2Expression(arg.value) as any);
|
|
356
|
+
rights.push(new naslTypes.SelectMembers({
|
|
357
|
+
expression: transformNode2Expression(expression[0]),
|
|
358
|
+
members,
|
|
314
359
|
}));
|
|
360
|
+
if (arg?.value) {
|
|
361
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
362
|
+
leftIndex: [0, index],
|
|
363
|
+
rightIndex: [index, index],
|
|
364
|
+
}));
|
|
365
|
+
}
|
|
366
|
+
} else {
|
|
367
|
+
rights.push(new naslTypes.SelectMembers({
|
|
368
|
+
expression: transformNode2Expression(arg.value)
|
|
369
|
+
}));
|
|
370
|
+
if (arg?.value) {
|
|
371
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
372
|
+
leftIndex: [0, index],
|
|
373
|
+
rightIndex: [index],
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
315
376
|
}
|
|
316
377
|
structureProperties.push(new naslTypes.StructureProperty({
|
|
317
378
|
name: arg?.key?.name,
|
|
@@ -1187,6 +1248,7 @@ function transformNode2View(node: babelTypes.FunctionDeclaration, root?: ParseRe
|
|
|
1187
1248
|
if (item.type === 'ReturnStatement' && item?.argument?.type === 'ArrayExpression') {
|
|
1188
1249
|
viewItem?.forEach((element: any) => {
|
|
1189
1250
|
json.push(element.aiParams);
|
|
1251
|
+
view.addViewElement(element);
|
|
1190
1252
|
});
|
|
1191
1253
|
}
|
|
1192
1254
|
if (viewItem?.concept === 'Variable') {
|
|
@@ -29,6 +29,13 @@ function flatMemberExpression(node: babelTypes.Node): Array<babelTypes.Node> {
|
|
|
29
29
|
return [...flatMemberExpression(node.object), node.property];
|
|
30
30
|
return [node];
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
function flatMembers(node: naslTypes.MemberExpression): Array<naslTypes.MemberExpression> {
|
|
34
|
+
if (node.concept === 'MemberExpression')
|
|
35
|
+
return [...flatMembers(((node as any)?.object)), node];
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
function flatMatchPatternsExpression(node: any): Array<babelTypes.Node> {
|
|
33
40
|
if (node.concept === 'BinaryExpression') {
|
|
34
41
|
if (node.operator === '||') {
|
|
@@ -79,6 +86,13 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
79
86
|
typeNamespace: (node as any).typeNamespace,
|
|
80
87
|
});
|
|
81
88
|
}
|
|
89
|
+
|
|
90
|
+
if (['ValidateResult', 'ValidateEvent'].includes(typeName)) {
|
|
91
|
+
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
92
|
+
typeNamespace: 'nasl.ui'
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
82
96
|
if (typeName === 'Any' || typeName === 'any') {
|
|
83
97
|
return undefined;
|
|
84
98
|
}
|
|
@@ -103,7 +117,7 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
103
117
|
if (node?.typeName?.type === 'TSQualifiedName') {
|
|
104
118
|
const allTypeName = generate(node?.typeName?.left as any)?.code;
|
|
105
119
|
// 实体、枚举、结构体
|
|
106
|
-
if (/^app.dataSources|.enums|.structures/.test(allTypeName)) {
|
|
120
|
+
if (/^app.dataSources|.enums|.structures|nasl.ui/.test(allTypeName)) {
|
|
107
121
|
const curTypeName = (node?.typeName as any)?.right?.name;
|
|
108
122
|
return naslTypes.TypeAnnotation.createReference(curTypeName, {
|
|
109
123
|
typeNamespace: allTypeName,
|
|
@@ -139,6 +153,8 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
139
153
|
}
|
|
140
154
|
function transformParam(node: babelTypes.Identifier): naslTypes.Param {
|
|
141
155
|
const typeAnnotation = (node.typeAnnotation as babelTypes.TSTypeAnnotation)?.typeAnnotation;
|
|
156
|
+
const exclude = ['event'];
|
|
157
|
+
if (exclude.includes(node.name)) return null;
|
|
142
158
|
return new naslTypes.Param({
|
|
143
159
|
name: node.name,
|
|
144
160
|
typeAnnotation: typeAnnotation ? transformTypeAnnotation(typeAnnotation) : null,
|
|
@@ -204,14 +220,29 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
204
220
|
const assignmentLines: any = [];
|
|
205
221
|
node?.arguments?.[0]?.properties.forEach((arg: any, index: number) => {
|
|
206
222
|
properties.push(transformLogicNode(arg.key));
|
|
207
|
-
|
|
208
|
-
expression
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
223
|
+
if (arg.value.type === 'MemberExpression') {
|
|
224
|
+
const expression = flatMemberExpression(arg.value);
|
|
225
|
+
const members = flatMembers(transformLogicNode(arg.value) as any);
|
|
226
|
+
rights.push(new naslTypes.SelectMembers({
|
|
227
|
+
expression: transformLogicNode(expression[0]),
|
|
228
|
+
members,
|
|
229
|
+
}));
|
|
230
|
+
if (arg?.value) {
|
|
231
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
232
|
+
leftIndex: [0, index],
|
|
233
|
+
rightIndex: [index, index],
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
rights.push(new naslTypes.SelectMembers({
|
|
238
|
+
expression: transformLogicNode(arg.value)
|
|
214
239
|
}));
|
|
240
|
+
if (arg?.value) {
|
|
241
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
242
|
+
leftIndex: [0, index],
|
|
243
|
+
rightIndex: [index],
|
|
244
|
+
}));
|
|
245
|
+
}
|
|
215
246
|
}
|
|
216
247
|
});
|
|
217
248
|
const parameters = node?.typeParameters?.params?.[0] || {};
|
|
@@ -246,14 +277,29 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
246
277
|
const assignmentLines: any = [];
|
|
247
278
|
node?.arguments?.[0]?.properties.forEach((arg: any, index: number) => {
|
|
248
279
|
properties.push(transformLogicNode(arg.key));
|
|
249
|
-
|
|
250
|
-
expression
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
280
|
+
if (arg.value.type === 'MemberExpression') {
|
|
281
|
+
const expression = flatMemberExpression(arg.value);
|
|
282
|
+
const members = flatMembers(transformLogicNode(arg.value) as any);
|
|
283
|
+
rights.push(new naslTypes.SelectMembers({
|
|
284
|
+
expression: transformLogicNode(expression[0]),
|
|
285
|
+
members,
|
|
286
|
+
}));
|
|
287
|
+
if (arg?.value) {
|
|
288
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
289
|
+
leftIndex: [0, index],
|
|
290
|
+
rightIndex: [index, index],
|
|
291
|
+
}));
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
rights.push(new naslTypes.SelectMembers({
|
|
295
|
+
expression: transformLogicNode(arg.value)
|
|
256
296
|
}));
|
|
297
|
+
if (arg?.value) {
|
|
298
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
299
|
+
leftIndex: [0, index],
|
|
300
|
+
rightIndex: [index],
|
|
301
|
+
}));
|
|
302
|
+
}
|
|
257
303
|
}
|
|
258
304
|
});
|
|
259
305
|
const parameters = node?.typeParameters?.params?.[0] || {};
|
|
@@ -289,14 +335,29 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
289
335
|
const assignmentLines: any = [];
|
|
290
336
|
node?.arguments?.[0]?.properties?.forEach((arg: any, index: number) => {
|
|
291
337
|
properties.push(transformLogicNode(arg.key));
|
|
292
|
-
|
|
293
|
-
expression
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
rightIndex: [index],
|
|
338
|
+
if (arg.value.type === 'MemberExpression') {
|
|
339
|
+
const expression = flatMemberExpression(arg.value);
|
|
340
|
+
const members = flatMembers(transformLogicNode(arg.value) as any);
|
|
341
|
+
rights.push(new naslTypes.SelectMembers({
|
|
342
|
+
expression: transformLogicNode(expression[0]),
|
|
343
|
+
members,
|
|
299
344
|
}));
|
|
345
|
+
if (arg?.value) {
|
|
346
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
347
|
+
leftIndex: [0, index],
|
|
348
|
+
rightIndex: [index, index],
|
|
349
|
+
}));
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
rights.push(new naslTypes.SelectMembers({
|
|
353
|
+
expression: transformLogicNode(arg.value)
|
|
354
|
+
}));
|
|
355
|
+
if (arg?.value) {
|
|
356
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
357
|
+
leftIndex: [0, index],
|
|
358
|
+
rightIndex: [index],
|
|
359
|
+
}));
|
|
360
|
+
}
|
|
300
361
|
}
|
|
301
362
|
structureProperties.push(new naslTypes.StructureProperty({
|
|
302
363
|
name: arg?.key?.name,
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
BusinessLogic,
|
|
24
24
|
View,
|
|
25
25
|
Enum,
|
|
26
|
+
SubLogic
|
|
26
27
|
} from '..';
|
|
27
28
|
import { getNaslNodeByNodeCallee } from '../automate/engine/utils';
|
|
28
29
|
import { runGeneratorSync as runSync, getAncestorExistingParamNames } from '../utils';
|
|
@@ -701,6 +702,19 @@ function getNodeiconFromLogic(completionProperty: CompletionProperty, node: type
|
|
|
701
702
|
const likeComponent = node.getAncestor('View') as View || node.getAncestor('BusinessComponent') as BusinessComponent;
|
|
702
703
|
const logic = (node as Param).logic || node.getAncestor('BusinessLogic') as BusinessLogic || (node as Param).OverriddenLogic || (node as Param).AuthLogic || (node as Param).AuthLogicForCallInterface;
|
|
703
704
|
|
|
705
|
+
// 如果节点存在于SubLogic 中,则可能出现 SubLogic 嵌套 SubLogic 的情况
|
|
706
|
+
// 为此需要找全链路上的所有 SubLogic 及其对应的参数
|
|
707
|
+
let parentSubLogicNode = node.getAncestor('SubLogic');
|
|
708
|
+
const isInSubLogic = !!parentSubLogicNode;
|
|
709
|
+
const logicLikeList: (SubLogic | Logic)[] = [];
|
|
710
|
+
if (isInSubLogic) {
|
|
711
|
+
while(parentSubLogicNode) {
|
|
712
|
+
logicLikeList.push(parentSubLogicNode as SubLogic);
|
|
713
|
+
parentSubLogicNode = parentSubLogicNode.getAncestor('SubLogic');
|
|
714
|
+
}
|
|
715
|
+
logicLikeList.push(logic);
|
|
716
|
+
}
|
|
717
|
+
|
|
704
718
|
if (node.concept === 'Identifier' || node.concept === 'BindAttribute' || node.concept === 'MemberExpression') {
|
|
705
719
|
const ancestorParamNames = getAncestorExistingParamNames(node);
|
|
706
720
|
if (ancestorParamNames.has(propName)) {
|
|
@@ -718,7 +732,13 @@ function getNodeiconFromLogic(completionProperty: CompletionProperty, node: type
|
|
|
718
732
|
|
|
719
733
|
if (logic) {
|
|
720
734
|
const { returns } = logic;
|
|
721
|
-
|
|
735
|
+
|
|
736
|
+
let params: Param[] = logic.params;
|
|
737
|
+
if (isInSubLogic) {
|
|
738
|
+
// 保证局部作用域的变量优先级高于全局作用域
|
|
739
|
+
params = logicLikeList.reduce((acc, cur) => acc.concat(cur.params), []);
|
|
740
|
+
}
|
|
741
|
+
|
|
722
742
|
if (logic instanceof AuthLogicForCallInterface) {
|
|
723
743
|
const { authParams } = logic;
|
|
724
744
|
if (authParams.find((item) => item.name === completionProperty.name)) return 'api-auth-params';
|
package/src/server/getLogics.ts
CHANGED
|
@@ -511,12 +511,9 @@ export function getLogicsSync(node: CallLogic | BindEvent | Identifier | Logic,
|
|
|
511
511
|
return result;
|
|
512
512
|
}
|
|
513
513
|
if (node?.concept === 'Identifier') {
|
|
514
|
-
// 之前 连接器 Connector 相关也存在与 app.dependencies 下,
|
|
515
|
-
// 现在迁移到 app.connectorDependencies 下,
|
|
516
|
-
// 为保证上下游逻辑与之前保持一致,这边做相应的扩展
|
|
517
514
|
const extensions = [
|
|
518
515
|
...app.dependencies,
|
|
519
|
-
...(app.connectorDependencies || [])
|
|
516
|
+
// ...(app.connectorDependencies || [])
|
|
520
517
|
]
|
|
521
518
|
.map((dep) => moduleToLogicNamesapce(dep, app.overriddenLogics))
|
|
522
519
|
.filter((item) => item.logics && item.logics.length);
|