@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
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
getStructures,
|
|
10
10
|
getLogics,
|
|
11
11
|
getModuleInterfaces,
|
|
12
|
+
getConnections,
|
|
12
13
|
getConnectors,
|
|
13
14
|
getDependencies,
|
|
14
15
|
getFrontendVariables,
|
|
@@ -16,224 +17,317 @@ import {
|
|
|
16
17
|
getCurrentNodeContext,
|
|
17
18
|
getCurrentNodeContextForUI,
|
|
18
19
|
getNaslUIOld,
|
|
20
|
+
getNaslUICode,
|
|
21
|
+
getEnumsCode,
|
|
22
|
+
getEntitiesCode,
|
|
23
|
+
getStructuresCode,
|
|
24
|
+
getLogicsCode,
|
|
25
|
+
getModuleInterfacesCode,
|
|
26
|
+
getConnectorsCode,
|
|
27
|
+
getDependenciesCode,
|
|
28
|
+
getFrontendViewsCode,
|
|
29
|
+
wrapTSBlock,
|
|
19
30
|
} from './getContext';
|
|
20
31
|
import { createCompilerState } from '../translator';
|
|
21
32
|
|
|
33
|
+
export * as getNaturalContext from './getContext';
|
|
34
|
+
|
|
22
35
|
export function genNaturalTS(app: App, currentNode?: BaseNode, focusedNodePath?: string) {
|
|
23
36
|
if (currentNode?.concept === 'Logic') {
|
|
24
37
|
const logic = currentNode as Logic;
|
|
25
|
-
const code = logic?.toNaturalTS(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
const code = logic?.toNaturalTS(
|
|
39
|
+
createCompilerState(undefined, {
|
|
40
|
+
focusedNodePath,
|
|
41
|
+
needNamespace: true,
|
|
42
|
+
autoPrefixName: true,
|
|
43
|
+
})
|
|
44
|
+
);
|
|
30
45
|
return code;
|
|
31
46
|
}
|
|
32
47
|
return getCurrentNodeContextForUI(currentNode).code;
|
|
33
48
|
}
|
|
34
49
|
|
|
35
|
-
|
|
50
|
+
// =========================== logic ===========================
|
|
51
|
+
export function genNaturalTSContextJSONForLogic(
|
|
36
52
|
app: App,
|
|
37
53
|
currentNode?: BaseNode,
|
|
38
54
|
focusedNodePath?: string,
|
|
39
|
-
|
|
55
|
+
material?: {
|
|
56
|
+
moduleInterfaces: any;
|
|
57
|
+
connectors: any;
|
|
58
|
+
dependencies: any;
|
|
59
|
+
}
|
|
40
60
|
) {
|
|
41
61
|
const frontend = currentNode?.getAncestor('Frontend') as Frontend;
|
|
42
62
|
const logicType = currentNode?.parentNode?.concept === 'App' ? 'global_logic' : 'view_logic';
|
|
43
63
|
const state = createCompilerState();
|
|
44
64
|
|
|
65
|
+
const { naslCore } = getNaslCore(logicType);
|
|
66
|
+
const { naslUtil } = getNaslUtil();
|
|
67
|
+
const { naslUI } = getNaslUIOld();
|
|
68
|
+
const { naslOql } = getNaslOQL();
|
|
69
|
+
const { enums } = getEnums(app, state);
|
|
70
|
+
const { entities } = getEntities(app, state);
|
|
71
|
+
const { structures } = getStructures(app, state);
|
|
72
|
+
const { appLogics } = getLogics(app, currentNode);
|
|
73
|
+
const { interfaceDependencies } = getModuleInterfaces(
|
|
74
|
+
material?.moduleInterfaces || app?.interfaceDependencies,
|
|
75
|
+
state
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
let connections = [];
|
|
79
|
+
if (material?.connectors?.length) {
|
|
80
|
+
connections = getConnectors(material.connectors, state).connectors;
|
|
81
|
+
} else {
|
|
82
|
+
connections = getConnections(material?.connectors || app.connections, state).connections;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const { dependencies } = getDependencies(
|
|
86
|
+
material?.dependencies || app?.dependencies,
|
|
87
|
+
state,
|
|
88
|
+
logicType,
|
|
89
|
+
frontend?.type
|
|
90
|
+
);
|
|
91
|
+
const { frontendVar, frontendVariables } = getFrontendVariables(
|
|
92
|
+
currentNode?.getAncestor('Frontend') as Frontend,
|
|
93
|
+
state
|
|
94
|
+
);
|
|
95
|
+
const { views } = getFrontendViews(frontend, state, currentNode, false);
|
|
96
|
+
const { currentLogic } = getCurrentNodeContext(currentNode, focusedNodePath);
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
naslCore,
|
|
100
|
+
naslUtil,
|
|
101
|
+
naslUI,
|
|
102
|
+
naslOql,
|
|
103
|
+
enums,
|
|
104
|
+
entities,
|
|
105
|
+
structures,
|
|
106
|
+
appLogics,
|
|
107
|
+
interfaceDependencies,
|
|
108
|
+
connections,
|
|
109
|
+
dependencies,
|
|
110
|
+
frontendVar, // @deprecated
|
|
111
|
+
frontendVariables,
|
|
112
|
+
views,
|
|
113
|
+
currentLogic,
|
|
114
|
+
logicType,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 生成 Logic 的 TypeScript 上下文
|
|
120
|
+
* @param tsContextJSON: 通过 genNaturalTSContextForLogic 获得到 tsContextJSON
|
|
121
|
+
* @param codeType: 'detail' | 'short'。detail 为详细代码,short 为简短代码
|
|
122
|
+
* 'detail' 将所有的code都返回(拼接成详细的code)。RAG召回,分析和执行阶段使用
|
|
123
|
+
* 'short' 只返回简短的code。模型召回,对应的分析阶段使用
|
|
124
|
+
* @param requiredIndexes?: 通过索引获取对应的 code。可挑选需要的 code
|
|
125
|
+
**/
|
|
126
|
+
export const genNaturalTSContextFromJSONForLogic = (
|
|
127
|
+
tsContextJSON: any,
|
|
128
|
+
codeType: 'detail' | 'short',
|
|
129
|
+
requiredIndexes?: string[]
|
|
130
|
+
) => {
|
|
131
|
+
const {
|
|
132
|
+
naslCore,
|
|
133
|
+
naslUtil,
|
|
134
|
+
naslUI,
|
|
135
|
+
naslOql,
|
|
136
|
+
enums,
|
|
137
|
+
entities,
|
|
138
|
+
structures,
|
|
139
|
+
appLogics,
|
|
140
|
+
interfaceDependencies,
|
|
141
|
+
connections,
|
|
142
|
+
dependencies,
|
|
143
|
+
frontendVariables,
|
|
144
|
+
views,
|
|
145
|
+
currentLogic,
|
|
146
|
+
logicType,
|
|
147
|
+
} = tsContextJSON;
|
|
148
|
+
|
|
45
149
|
let code = '';
|
|
46
150
|
code += '### [1] 标准库\n';
|
|
47
|
-
code +=
|
|
151
|
+
code += wrapTSBlock(naslCore);
|
|
48
152
|
|
|
49
153
|
code += '\n### [2] nasl.util\n';
|
|
50
|
-
code +=
|
|
154
|
+
code += wrapTSBlock(naslUtil);
|
|
51
155
|
|
|
52
|
-
if (
|
|
156
|
+
if (naslUI && logicType === 'view_logic') {
|
|
53
157
|
code += '\n### [3] nasl.ui\n';
|
|
54
|
-
|
|
158
|
+
if (typeof naslUI === 'string') {
|
|
159
|
+
code += wrapTSBlock(naslUI);
|
|
160
|
+
} else {
|
|
161
|
+
code += getNaslUICode(naslUI, codeType, requiredIndexes);
|
|
162
|
+
}
|
|
55
163
|
}
|
|
56
164
|
|
|
57
|
-
if (logicType === 'global_logic') {
|
|
165
|
+
if (naslOql && logicType === 'global_logic') {
|
|
58
166
|
code += '\n### [4] nasl.oql\n';
|
|
59
|
-
code +=
|
|
167
|
+
code += wrapTSBlock(naslOql);
|
|
60
168
|
}
|
|
61
169
|
|
|
62
170
|
code += '\n### [5] 全局上下文\n';
|
|
63
|
-
|
|
64
|
-
|
|
171
|
+
if (enums.data?.length) {
|
|
172
|
+
code += '\n#### [5-0] 枚举\n';
|
|
173
|
+
code += getEnumsCode(enums);
|
|
174
|
+
}
|
|
65
175
|
|
|
66
|
-
|
|
67
|
-
|
|
176
|
+
if (entities?.length) {
|
|
177
|
+
code += '\n#### [5-1] 实体\n';
|
|
178
|
+
code += getEntitiesCode(entities);
|
|
179
|
+
}
|
|
68
180
|
|
|
69
|
-
|
|
70
|
-
|
|
181
|
+
if (structures.data?.length) {
|
|
182
|
+
code += '\n#### [5-2] 可用的数据结构\n';
|
|
183
|
+
code += getStructuresCode(structures);
|
|
184
|
+
}
|
|
71
185
|
|
|
72
|
-
|
|
73
|
-
|
|
186
|
+
if (appLogics.data?.length) {
|
|
187
|
+
code += '\n### [6] 服务端逻辑\n';
|
|
188
|
+
code += getLogicsCode(appLogics, codeType, requiredIndexes);
|
|
189
|
+
}
|
|
74
190
|
|
|
75
|
-
|
|
76
|
-
|
|
191
|
+
if (interfaceDependencies) {
|
|
192
|
+
code += '\n### [7] 可调用的接口列表\n';
|
|
193
|
+
code += getModuleInterfacesCode(interfaceDependencies, codeType, requiredIndexes);
|
|
194
|
+
}
|
|
77
195
|
|
|
78
|
-
if (
|
|
196
|
+
if (logicType === 'global_logic' && connections) {
|
|
79
197
|
code += '\n### [8] 连接器逻辑列表\n';
|
|
80
|
-
code +=
|
|
198
|
+
code += getConnectorsCode(connections, codeType, requiredIndexes);
|
|
81
199
|
}
|
|
82
|
-
|
|
83
|
-
if (app?.dependencies?.length > 0) {
|
|
200
|
+
if (dependencies) {
|
|
84
201
|
code += '\n### [9] 依赖库逻辑列表\n';
|
|
85
|
-
code +=
|
|
202
|
+
code += getDependenciesCode(dependencies, codeType, requiredIndexes);
|
|
86
203
|
}
|
|
87
204
|
|
|
88
|
-
if (
|
|
205
|
+
if (logicType === 'view_logic') {
|
|
89
206
|
code += '\n### [10] 页面上下文\n';
|
|
90
|
-
if (
|
|
207
|
+
if (frontendVariables) {
|
|
91
208
|
code += '\n#### [10-0] 前端全局变量\n';
|
|
92
|
-
code +=
|
|
209
|
+
code += frontendVariables;
|
|
93
210
|
}
|
|
94
211
|
|
|
95
|
-
|
|
96
|
-
|
|
212
|
+
if (views?.data?.length) {
|
|
213
|
+
code += '\n#### [10-1] 前端页面列表\n';
|
|
214
|
+
code += getFrontendViewsCode(views);
|
|
215
|
+
}
|
|
97
216
|
}
|
|
98
217
|
|
|
99
218
|
code += '\n### 当前逻辑上下文\n';
|
|
100
|
-
code +=
|
|
101
|
-
return code;
|
|
102
|
-
}
|
|
219
|
+
code += wrapTSBlock(currentLogic);
|
|
103
220
|
|
|
104
|
-
|
|
221
|
+
return code;
|
|
222
|
+
};
|
|
105
223
|
|
|
106
|
-
export function
|
|
224
|
+
export function genNaturalTSContextForLogic(
|
|
107
225
|
app: App,
|
|
108
|
-
currentNode
|
|
226
|
+
currentNode?: BaseNode,
|
|
109
227
|
focusedNodePath?: string,
|
|
110
228
|
requiredIndexes?: string[],
|
|
111
|
-
material?: {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
code += getNaslCore('view_logic').code;
|
|
119
|
-
|
|
120
|
-
code += '\n### [2] nasl.util\n';
|
|
121
|
-
code += getNaslUtil().code;
|
|
122
|
-
|
|
123
|
-
if (frontend) {
|
|
124
|
-
code += '\n### [3] nasl.ui\n';
|
|
125
|
-
code += getNaslUI(app, frontend.type, material || frontend.type, requiredIndexes).code;
|
|
126
|
-
code += '\n';
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
code += '\n### [5] 全局上下文\n';
|
|
130
|
-
code += '\n#### [5-0] 枚举\n';
|
|
131
|
-
code += getEnums(app, state, requiredIndexes).code;
|
|
132
|
-
|
|
133
|
-
code += '\n#### [5-1] 实体\n';
|
|
134
|
-
code += getEntities(app, state, requiredIndexes).code;
|
|
135
|
-
|
|
136
|
-
code += '\n#### [5-2] 可用的数据结构\n';
|
|
137
|
-
code += getStructures(app, state, requiredIndexes).code;
|
|
138
|
-
|
|
139
|
-
code += '\n### [6] 服务端逻辑\n';
|
|
140
|
-
code += getLogics(app, currentNode, requiredIndexes).code;
|
|
141
|
-
|
|
142
|
-
code += '\n### [7] 可调用的接口列表\n';
|
|
143
|
-
code += getModuleInterfaces(app, state, requiredIndexes).code;
|
|
144
|
-
|
|
145
|
-
if (app?.dependencies?.length > 0) {
|
|
146
|
-
code += '\n### [9] 依赖库逻辑列表\n';
|
|
147
|
-
code += getDependencies(app, state, requiredIndexes).code;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (frontend) {
|
|
151
|
-
code += '\n### [10] 页面上下文\n';
|
|
152
|
-
if (frontend?.variables?.length > 0) {
|
|
153
|
-
code += '\n#### [10-0] 前端全局变量\n';
|
|
154
|
-
code += getFrontendVariables(frontend, state).code;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
code += '\n#### [10-1] 前端页面列表\n';
|
|
158
|
-
code += getFrontendViews(frontend, state, currentNode, true).code;
|
|
229
|
+
material?: {
|
|
230
|
+
moduleInterfaces: any;
|
|
231
|
+
connectors: any;
|
|
232
|
+
dependencies: any;
|
|
233
|
+
},
|
|
234
|
+
restParams?: {
|
|
235
|
+
codeType?: 'detail' | 'short';
|
|
159
236
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
237
|
+
) {
|
|
238
|
+
const tsContextJSON = genNaturalTSContextJSONForLogic(
|
|
239
|
+
app,
|
|
240
|
+
currentNode,
|
|
241
|
+
focusedNodePath,
|
|
242
|
+
material
|
|
243
|
+
);
|
|
244
|
+
const code = genNaturalTSContextFromJSONForLogic(
|
|
245
|
+
tsContextJSON,
|
|
246
|
+
restParams.codeType,
|
|
247
|
+
requiredIndexes
|
|
248
|
+
);
|
|
163
249
|
return code;
|
|
164
250
|
}
|
|
165
251
|
|
|
166
|
-
export
|
|
252
|
+
export const genNaturalTSContext = genNaturalTSContextForLogic;
|
|
253
|
+
export const genNaturalTsContextJson = genNaturalTSContextJSONForLogic;
|
|
254
|
+
|
|
255
|
+
// =========================== view ===========================
|
|
256
|
+
|
|
257
|
+
// 生成 View 的 tsJson
|
|
258
|
+
export function genNaturalTSContextJSONForUI(
|
|
167
259
|
app: App,
|
|
168
|
-
currentNode
|
|
169
|
-
|
|
260
|
+
currentNode: BaseNode,
|
|
261
|
+
material?: {
|
|
262
|
+
basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string };
|
|
263
|
+
extensionMaterials: {
|
|
264
|
+
name: string;
|
|
265
|
+
title: string;
|
|
266
|
+
description: string;
|
|
267
|
+
tsDescription: string;
|
|
268
|
+
}[];
|
|
269
|
+
moduleInterfaces: any;
|
|
270
|
+
connectors: any;
|
|
271
|
+
dependencies: any;
|
|
272
|
+
}
|
|
170
273
|
) {
|
|
171
|
-
const frontend = currentNode
|
|
172
|
-
const logicType = currentNode?.parentNode?.concept === 'App' ? 'global_logic' : 'view_logic';
|
|
274
|
+
const frontend = currentNode.getAncestor('Frontend') as Frontend;
|
|
173
275
|
const state = createCompilerState();
|
|
174
276
|
|
|
175
|
-
const { naslCore } = getNaslCore(
|
|
277
|
+
const { naslCore } = getNaslCore('view_logic');
|
|
176
278
|
const { naslUtil } = getNaslUtil();
|
|
177
|
-
const { naslUI } =
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const {
|
|
182
|
-
const {
|
|
183
|
-
const {
|
|
184
|
-
const {
|
|
185
|
-
const {
|
|
186
|
-
|
|
187
|
-
currentNode?.getAncestor('Frontend') as Frontend,
|
|
279
|
+
const { naslUI } = getNaslUI(app, frontend.type, {
|
|
280
|
+
basicMaterials: material?.basicMaterials,
|
|
281
|
+
extensionMaterials: material?.extensionMaterials,
|
|
282
|
+
});
|
|
283
|
+
const { enums } = getEnums(app, state);
|
|
284
|
+
const { entities } = getEntities(app, state);
|
|
285
|
+
const { structures } = getStructures(app, state);
|
|
286
|
+
const { appLogics } = getLogics(app, currentNode);
|
|
287
|
+
const { interfaceDependencies } = getModuleInterfaces(
|
|
288
|
+
material?.moduleInterfaces || app?.interfaceDependencies,
|
|
188
289
|
state
|
|
189
290
|
);
|
|
291
|
+
const { dependencies } = getDependencies(
|
|
292
|
+
material?.dependencies || app?.dependencies,
|
|
293
|
+
state,
|
|
294
|
+
'view_logic',
|
|
295
|
+
frontend?.type
|
|
296
|
+
);
|
|
297
|
+
const { frontendVariables } = getFrontendVariables(frontend, state);
|
|
190
298
|
const { views } = getFrontendViews(frontend, state, currentNode, false);
|
|
191
|
-
const { currentLogic } =
|
|
299
|
+
const { currentLogic } = getCurrentNodeContextForUI(currentNode);
|
|
192
300
|
|
|
193
301
|
return {
|
|
194
302
|
naslCore,
|
|
195
303
|
naslUtil,
|
|
196
304
|
naslUI,
|
|
197
|
-
naslOql,
|
|
198
305
|
enums,
|
|
199
306
|
entities,
|
|
200
307
|
structures,
|
|
201
308
|
appLogics,
|
|
202
309
|
interfaceDependencies,
|
|
203
|
-
connections,
|
|
204
310
|
dependencies,
|
|
205
|
-
frontendVar, // @deprecated
|
|
206
311
|
frontendVariables,
|
|
207
312
|
views,
|
|
208
|
-
currentLogic,
|
|
313
|
+
currentPage: currentLogic,
|
|
209
314
|
};
|
|
210
315
|
}
|
|
211
316
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const {
|
|
226
|
-
const { enums } = getEnums(app, state, requiredIndexes);
|
|
227
|
-
const { entities } = getEntities(app, state, requiredIndexes);
|
|
228
|
-
const { structures } = getStructures(app, state, requiredIndexes);
|
|
229
|
-
const { appLogics } = getLogics(app, currentNode, requiredIndexes);
|
|
230
|
-
const { interfaceDependencies } = getModuleInterfaces(app, state, requiredIndexes);
|
|
231
|
-
const { dependencies } = getDependencies(app, state, requiredIndexes);
|
|
232
|
-
const { frontendVariables } = getFrontendVariables(frontend, state);
|
|
233
|
-
const { views } = getFrontendViews(frontend, state, currentNode, true);
|
|
234
|
-
const { currentLogic } = getCurrentNodeContextForUI(currentNode);
|
|
235
|
-
|
|
236
|
-
return {
|
|
317
|
+
/**
|
|
318
|
+
* 根据 tsContextJSON 生成 View 的 TypeScript 上下文
|
|
319
|
+
* @param tsContextJSON: 通过 genNaturalTSContextJSONForUI 获得到 tsContextJSON
|
|
320
|
+
* @param codeType: 'detail' | 'short'。detail 为详细代码,short 为简短代码
|
|
321
|
+
* 'detail' 将所有的code都返回(拼接成详细的code)。RAG召回,分析和执行阶段使用
|
|
322
|
+
* 'short' 只返回简短的code。模型召回,对应的分析阶段使用
|
|
323
|
+
* @param requiredIndexes?: 通过索引获取对应的 code。可挑选需要的 code
|
|
324
|
+
**/
|
|
325
|
+
export const genNaturalTSContextFromJSONForUI = (
|
|
326
|
+
tsContextJSON: any,
|
|
327
|
+
codeType: 'detail' | 'short',
|
|
328
|
+
requiredIndexes?: string[]
|
|
329
|
+
) => {
|
|
330
|
+
const {
|
|
237
331
|
naslCore,
|
|
238
332
|
naslUtil,
|
|
239
333
|
naslUI,
|
|
@@ -245,8 +339,100 @@ export function genNaturalTSContextJSONForUI(
|
|
|
245
339
|
dependencies,
|
|
246
340
|
frontendVariables,
|
|
247
341
|
views,
|
|
248
|
-
currentPage
|
|
249
|
-
};
|
|
250
|
-
}
|
|
342
|
+
currentPage,
|
|
343
|
+
} = tsContextJSON;
|
|
251
344
|
|
|
252
|
-
|
|
345
|
+
let code = '';
|
|
346
|
+
code += '### [1] 标准库\n';
|
|
347
|
+
code += wrapTSBlock(naslCore);
|
|
348
|
+
|
|
349
|
+
code += '\n### [2] nasl.util\n';
|
|
350
|
+
code += wrapTSBlock(naslUtil);
|
|
351
|
+
|
|
352
|
+
if (naslUI) {
|
|
353
|
+
code += '\n### [3] nasl.ui\n';
|
|
354
|
+
if (typeof naslUI === 'string') {
|
|
355
|
+
code += wrapTSBlock(naslUI);
|
|
356
|
+
} else {
|
|
357
|
+
code += getNaslUICode(naslUI, codeType, requiredIndexes);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
code += '\n### [5] 全局上下文\n';
|
|
362
|
+
if (enums.data?.length) {
|
|
363
|
+
code += '\n#### [5-0] 枚举\n';
|
|
364
|
+
code += getEnumsCode(enums);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (entities?.length) {
|
|
368
|
+
code += '\n#### [5-1] 实体\n';
|
|
369
|
+
code += getEntitiesCode(entities);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (structures.data?.length) {
|
|
373
|
+
code += '\n#### [5-2] 可用的数据结构\n';
|
|
374
|
+
code += getStructuresCode(structures);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (appLogics.data?.length) {
|
|
378
|
+
code += '\n### [6] 服务端逻辑\n';
|
|
379
|
+
code += getLogicsCode(appLogics, codeType, requiredIndexes);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (interfaceDependencies) {
|
|
383
|
+
code += '\n### [7] 可调用的接口列表\n';
|
|
384
|
+
code += getModuleInterfacesCode(interfaceDependencies, codeType, requiredIndexes);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (dependencies) {
|
|
388
|
+
code += '\n### [9] 依赖库逻辑列表\n';
|
|
389
|
+
code += getDependenciesCode(dependencies, codeType, requiredIndexes);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
code += '\n### [10] 页面上下文\n';
|
|
393
|
+
if (frontendVariables) {
|
|
394
|
+
code += '\n#### [10-0] 前端全局变量\n';
|
|
395
|
+
code += frontendVariables;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (views?.data?.length) {
|
|
399
|
+
code += '\n#### [10-1] 前端页面列表\n';
|
|
400
|
+
code += getFrontendViewsCode(views);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
code += '\n### 当前页面上下文\n';
|
|
404
|
+
code += wrapTSBlock(currentPage);
|
|
405
|
+
|
|
406
|
+
return code;
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
// 兼容各版本,统一调用 genNaturalTSContextForUI 方法
|
|
410
|
+
export function genNaturalTSContextForUI(
|
|
411
|
+
app: App,
|
|
412
|
+
currentNode: BaseNode,
|
|
413
|
+
focusedNodePath?: string,
|
|
414
|
+
requiredIndexes?: string[],
|
|
415
|
+
material?: {
|
|
416
|
+
basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string };
|
|
417
|
+
extensionMaterials: {
|
|
418
|
+
name: string;
|
|
419
|
+
title: string;
|
|
420
|
+
description: string;
|
|
421
|
+
tsDescription: string;
|
|
422
|
+
}[];
|
|
423
|
+
moduleInterfaces: any;
|
|
424
|
+
connectors: any;
|
|
425
|
+
dependencies: any;
|
|
426
|
+
},
|
|
427
|
+
restParams?: {
|
|
428
|
+
codeType?: 'detail' | 'short';
|
|
429
|
+
}
|
|
430
|
+
) {
|
|
431
|
+
const tsContextJSON = genNaturalTSContextJSONForUI(app, currentNode, material);
|
|
432
|
+
const code = genNaturalTSContextFromJSONForUI(
|
|
433
|
+
tsContextJSON,
|
|
434
|
+
restParams.codeType,
|
|
435
|
+
requiredIndexes
|
|
436
|
+
);
|
|
437
|
+
return code;
|
|
438
|
+
}
|
|
@@ -42,6 +42,7 @@ export function handleMaterial({ json, tsDeclaration }: { json: Array<{ name: st
|
|
|
42
42
|
tsDeclaration = tsDeclaration.replace(/\/\/\/ *<reference types="@nasl\/types" *\/>\s*/g, '')
|
|
43
43
|
.replace(/\{\s+altKey[\s\S]+?\}/g, 'MouseEvent')
|
|
44
44
|
.replace(/\{\s+cancelBubble[\s\S]+?\}/g, 'FocusEvent')
|
|
45
|
+
.replace(/\{\s+rawValue[\s\S]+?\}/g, 'ValidateResult')
|
|
45
46
|
.replace(/\{\s+rawValue[\s\S]+?\}/g, 'ValidateEvent');
|
|
46
47
|
|
|
47
48
|
const snippets = tsDeclaration.split('declare namespace nasl.ui');
|
|
@@ -103,9 +104,10 @@ export function getExtensionsDeclaration(viewComponent: any) {
|
|
|
103
104
|
code += `${indent(state.tabSize + 1)}}\n`;
|
|
104
105
|
code += `${indent(state.tabSize + 1)}class ${componentName}Options extends ViewComponentOptions {\n`;
|
|
105
106
|
// props
|
|
106
|
-
viewComponent.props
|
|
107
|
+
const props = viewComponent.props || viewComponent.attrs || [];
|
|
108
|
+
props?.forEach((prop: any) => {
|
|
107
109
|
code += `${indent(state.tabSize + 2)}${utils.getDescription(prop.title, prop.description)}\n`;
|
|
108
|
-
code += `${indent(state.tabSize + 2)}${prop.name}?: ${prop?.type || prop?.tsType};\n`;
|
|
110
|
+
code += `${indent(state.tabSize + 2)}${camelCase(prop.name)}?: ${prop?.type || prop?.tsType};\n`;
|
|
109
111
|
});
|
|
110
112
|
// events
|
|
111
113
|
viewComponent.events?.forEach((event: any) => {
|