@lcap/nasl 3.8.2-beta.9 → 3.8.3-beta.2
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.d.ts +9 -4
- package/out/common/BaseNode.js +43 -10
- package/out/common/BaseNode.js.map +1 -1
- package/out/concepts/AuthLogicForCallInterface__.js +2 -50
- 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 +2 -42
- package/out/concepts/BusinessComponent__.js.map +1 -1
- package/out/concepts/BusinessLogic__.js +2 -50
- package/out/concepts/BusinessLogic__.js.map +1 -1
- package/out/concepts/CallFunction__.d.ts +1 -1
- package/out/concepts/CallFunction__.js +1 -1
- package/out/concepts/CallLogic__.js +7 -1
- 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/Identifier__.d.ts +2 -0
- package/out/concepts/Identifier__.js +51 -5
- package/out/concepts/Identifier__.js.map +1 -1
- package/out/concepts/Interface__.js +1 -1
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/Logic__.js +33 -111
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MemberExpression__.d.ts +1 -1
- package/out/concepts/MemberExpression__.js +15 -3
- 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 +2 -50
- 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/ProcessElementV2__.js +4 -0
- package/out/concepts/ProcessElementV2__.js.map +1 -1
- package/out/concepts/ProcessElement__.js +4 -0
- package/out/concepts/ProcessElement__.js.map +1 -1
- package/out/concepts/ProcessV2__.js +4 -0
- package/out/concepts/ProcessV2__.js.map +1 -1
- package/out/concepts/Process__.js +4 -0
- package/out/concepts/Process__.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/SubLogic__.js +5 -50
- package/out/concepts/SubLogic__.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 +16 -6
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.js +48 -49
- package/out/concepts/View__.js.map +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 +343 -292
- 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/naslServer.d.ts +2 -2
- package/out/server/naslServer.js +48 -18
- package/out/server/naslServer.js.map +1 -1
- package/out/server/semanticData.d.ts +32 -0
- package/out/server/semanticData.js +371 -0
- package/out/server/semanticData.js.map +1 -0
- 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 +111 -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-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 +50 -8
- package/src/concepts/AuthLogicForCallInterface__.ts +3 -56
- 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 +6 -51
- package/src/concepts/BusinessLogic__.ts +4 -56
- package/src/concepts/CallFunction__.ts +1 -1
- package/src/concepts/CallLogic__.ts +21 -16
- 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/Identifier__.ts +57 -6
- package/src/concepts/Interface__.ts +1 -1
- package/src/concepts/Logic__.ts +44 -134
- package/src/concepts/MemberExpression__.ts +21 -7
- package/src/concepts/OqlQueryComponent__.ts +29 -5
- package/src/concepts/OverriddenLogic__.ts +4 -56
- package/src/concepts/Param__.ts +5 -4
- package/src/concepts/ProcessElementV2__.ts +4 -0
- package/src/concepts/ProcessElement__.ts +4 -0
- package/src/concepts/ProcessV2__.ts +5 -0
- package/src/concepts/Process__.ts +4 -0
- package/src/concepts/QueryOrderByExpression__.ts +0 -1
- package/src/concepts/Structure__.ts +5 -7
- package/src/concepts/SubLogic__.ts +6 -56
- package/src/concepts/Variable__.ts +9 -5
- package/src/concepts/ViewElement__.ts +24 -7
- package/src/concepts/View__.ts +75 -76
- 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 +190 -137
- 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/naslServer.ts +54 -19
- package/src/server/semanticData.ts +447 -0
- 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 +150 -0
- package/src/translator/types.ts +2 -0
- package/src/translator/utils.ts +2 -2
- 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/logic/__snapshots__/toEmbeddedTS.spec.ts.snap +182 -0
- package/test/concepts/logic/constant.ts +5 -0
- package/test/concepts/logic/fixtures/variable-host-call-logic-member-expression.json +267 -0
- package/test/concepts/logic/fixtures/variable-host-call-logic-nested-member-expression copy.json +457 -0
- package/test/concepts/logic/fixtures/variable-host-call-logic-with-handle-error-member-expression.json +267 -0
- package/test/concepts/logic/toEmbeddedTS.spec.ts +15 -0
- 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
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
getConnectors,
|
|
14
14
|
getDependencies,
|
|
15
15
|
getFrontendVariables,
|
|
16
|
+
getServerVariables,
|
|
17
|
+
getVariablesCode,
|
|
16
18
|
getFrontendViews,
|
|
17
19
|
getCurrentNodeContext,
|
|
18
20
|
getCurrentNodeContextForUI,
|
|
@@ -26,6 +28,7 @@ import {
|
|
|
26
28
|
getConnectorsCode,
|
|
27
29
|
getDependenciesCode,
|
|
28
30
|
getFrontendViewsCode,
|
|
31
|
+
getCurrentComponentDeclaration,
|
|
29
32
|
wrapTSBlock,
|
|
30
33
|
} from './getContext';
|
|
31
34
|
import { createCompilerState } from '../translator';
|
|
@@ -57,20 +60,35 @@ export function genNaturalTSContextJSONForLogic(
|
|
|
57
60
|
moduleInterfaces: any;
|
|
58
61
|
connectors: any;
|
|
59
62
|
dependencies: any;
|
|
60
|
-
|
|
63
|
+
basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
|
|
64
|
+
extensionMaterials: 'pc' | 'h5' | {
|
|
65
|
+
name: string;
|
|
66
|
+
title: string;
|
|
67
|
+
description: string;
|
|
68
|
+
tsDescription: string;
|
|
69
|
+
}[];
|
|
70
|
+
},
|
|
71
|
+
restParams?: any
|
|
61
72
|
) {
|
|
62
73
|
const frontend = currentNode?.getAncestor('Frontend') as Frontend;
|
|
63
74
|
const logicType = currentNode?.parentNode?.concept === 'App' ? 'global_logic' : 'view_logic';
|
|
64
|
-
const state = createCompilerState('', { descriptionComment: true });
|
|
75
|
+
const state = createCompilerState('', { descriptionComment: true, typeMap: restParams?.typeMap });
|
|
65
76
|
|
|
66
77
|
const { naslCore } = getNaslCore(logicType);
|
|
67
78
|
const { naslUtil } = getNaslUtil();
|
|
68
79
|
const { naslUI } = getNaslUIOld();
|
|
80
|
+
let components = [];
|
|
81
|
+
if (logicType === 'view_logic' && material?.basicMaterials && material?.extensionMaterials) {
|
|
82
|
+
components = getNaslUI(app, frontend.type, {
|
|
83
|
+
basicMaterials: material?.basicMaterials,
|
|
84
|
+
extensionMaterials: material?.extensionMaterials,
|
|
85
|
+
}).naslUI;
|
|
86
|
+
}
|
|
69
87
|
const { naslOql } = getNaslOQL();
|
|
70
88
|
const { enums } = getEnums(app, state);
|
|
71
89
|
const { entities } = getEntities(app, state);
|
|
72
90
|
const { structures } = getStructures(app, state);
|
|
73
|
-
const { appLogics } = getLogics(app, currentNode);
|
|
91
|
+
const { appLogics } = getLogics(app, currentNode, state);
|
|
74
92
|
const { interfaceDependencies } = getModuleInterfaces(
|
|
75
93
|
material?.moduleInterfaces || app?.interfaceDependencies,
|
|
76
94
|
state
|
|
@@ -89,17 +107,21 @@ export function genNaturalTSContextJSONForLogic(
|
|
|
89
107
|
logicType,
|
|
90
108
|
frontend?.type
|
|
91
109
|
);
|
|
92
|
-
const {
|
|
110
|
+
const { frontendVariables } = getFrontendVariables(
|
|
93
111
|
currentNode?.getAncestor('Frontend') as Frontend,
|
|
94
112
|
state
|
|
95
113
|
);
|
|
96
|
-
const { views } = getFrontendViews(frontend, state, currentNode, false);
|
|
97
|
-
const { currentLogic } = getCurrentNodeContext(currentNode, focusedNodePath, experimental);
|
|
98
114
|
|
|
115
|
+
const { backendVariables } = getServerVariables(app, state);
|
|
116
|
+
|
|
117
|
+
const { views } = getFrontendViews(frontend, state, currentNode, false);
|
|
118
|
+
const { currentLogic } = getCurrentNodeContext(currentNode, focusedNodePath, experimental, restParams?.typeMap);
|
|
119
|
+
const { componentDeclaration } = getCurrentComponentDeclaration(currentNode, components);
|
|
99
120
|
return {
|
|
100
121
|
naslCore,
|
|
101
122
|
naslUtil,
|
|
102
123
|
naslUI,
|
|
124
|
+
components,
|
|
103
125
|
naslOql,
|
|
104
126
|
enums,
|
|
105
127
|
entities,
|
|
@@ -108,11 +130,12 @@ export function genNaturalTSContextJSONForLogic(
|
|
|
108
130
|
interfaceDependencies,
|
|
109
131
|
connections,
|
|
110
132
|
dependencies,
|
|
111
|
-
frontendVar, // @deprecated
|
|
112
133
|
frontendVariables,
|
|
134
|
+
backendVariables,
|
|
113
135
|
views,
|
|
114
136
|
currentLogic,
|
|
115
137
|
logicType,
|
|
138
|
+
componentDeclaration
|
|
116
139
|
};
|
|
117
140
|
}
|
|
118
141
|
|
|
@@ -142,16 +165,18 @@ export const genNaturalTSContextFromJSONForLogic = (
|
|
|
142
165
|
connections,
|
|
143
166
|
dependencies,
|
|
144
167
|
frontendVariables,
|
|
168
|
+
backendVariables,
|
|
145
169
|
views,
|
|
146
170
|
currentLogic,
|
|
147
171
|
logicType,
|
|
172
|
+
componentDeclaration
|
|
148
173
|
} = tsContextJSON;
|
|
149
174
|
|
|
150
175
|
let code = '';
|
|
151
|
-
code += '### [1]
|
|
176
|
+
code += '### [1]标准库与类型定义\n';
|
|
152
177
|
code += wrapTSBlock(naslCore);
|
|
153
178
|
|
|
154
|
-
code += '\n### [2]
|
|
179
|
+
code += '\n### [2]平台内置函数库\n';
|
|
155
180
|
code += wrapTSBlock(naslUtil);
|
|
156
181
|
|
|
157
182
|
if (naslUI && logicType === 'view_logic') {
|
|
@@ -161,10 +186,14 @@ export const genNaturalTSContextFromJSONForLogic = (
|
|
|
161
186
|
} else {
|
|
162
187
|
code += getNaslUICode(naslUI, codeType, requiredIndexes);
|
|
163
188
|
}
|
|
189
|
+
if (componentDeclaration) {
|
|
190
|
+
code += '\n#### [3-1] 组件声明\n';
|
|
191
|
+
code += wrapTSBlock(`declare namespace nasl.ui {\n${componentDeclaration}}`);
|
|
192
|
+
}
|
|
164
193
|
}
|
|
165
194
|
|
|
166
195
|
if (naslOql && logicType === 'global_logic') {
|
|
167
|
-
code += '\n### [4]
|
|
196
|
+
code += '\n### [4]数据查询定义\n';
|
|
168
197
|
code += wrapTSBlock(naslOql);
|
|
169
198
|
}
|
|
170
199
|
|
|
@@ -205,15 +234,20 @@ export const genNaturalTSContextFromJSONForLogic = (
|
|
|
205
234
|
|
|
206
235
|
if (logicType === 'view_logic') {
|
|
207
236
|
code += '\n### [10] 页面上下文\n';
|
|
208
|
-
if (frontendVariables) {
|
|
237
|
+
if (frontendVariables?.data?.length) {
|
|
209
238
|
code += '\n#### [10-0] 前端全局变量\n';
|
|
210
|
-
code += frontendVariables;
|
|
239
|
+
code += getVariablesCode(frontendVariables);
|
|
211
240
|
}
|
|
212
241
|
|
|
213
242
|
if (views?.data?.length) {
|
|
214
243
|
code += '\n#### [10-1] 前端页面列表\n';
|
|
215
244
|
code += getFrontendViewsCode(views);
|
|
216
245
|
}
|
|
246
|
+
} else {
|
|
247
|
+
code += '\n### [10] 全局变量\n';
|
|
248
|
+
if (backendVariables?.data?.length) {
|
|
249
|
+
code += getVariablesCode(backendVariables);
|
|
250
|
+
}
|
|
217
251
|
}
|
|
218
252
|
|
|
219
253
|
code += '\n### 当前逻辑上下文\n';
|
|
@@ -232,9 +266,17 @@ export function genNaturalTSContextForLogic(
|
|
|
232
266
|
moduleInterfaces: any;
|
|
233
267
|
connectors: any;
|
|
234
268
|
dependencies: any;
|
|
269
|
+
basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
|
|
270
|
+
extensionMaterials: 'pc' | 'h5' | {
|
|
271
|
+
name: string;
|
|
272
|
+
title: string;
|
|
273
|
+
description: string;
|
|
274
|
+
tsDescription: string;
|
|
275
|
+
}[];
|
|
235
276
|
},
|
|
236
277
|
restParams?: {
|
|
237
|
-
codeType
|
|
278
|
+
codeType: 'detail' | 'short';
|
|
279
|
+
typeMap?: any;
|
|
238
280
|
}
|
|
239
281
|
) {
|
|
240
282
|
const tsContextJSON = genNaturalTSContextJSONForLogic(
|
|
@@ -242,11 +284,12 @@ export function genNaturalTSContextForLogic(
|
|
|
242
284
|
currentNode,
|
|
243
285
|
focusedNodePath,
|
|
244
286
|
experimental,
|
|
245
|
-
material
|
|
287
|
+
material,
|
|
288
|
+
restParams
|
|
246
289
|
);
|
|
247
290
|
const code = genNaturalTSContextFromJSONForLogic(
|
|
248
291
|
tsContextJSON,
|
|
249
|
-
restParams
|
|
292
|
+
restParams?.codeType || 'short',
|
|
250
293
|
requiredIndexes
|
|
251
294
|
);
|
|
252
295
|
return code;
|
|
@@ -262,8 +305,8 @@ export function genNaturalTSContextJSONForUI(
|
|
|
262
305
|
app: App,
|
|
263
306
|
currentNode: BaseNode,
|
|
264
307
|
material?: {
|
|
265
|
-
basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string };
|
|
266
|
-
extensionMaterials: {
|
|
308
|
+
basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
|
|
309
|
+
extensionMaterials: 'pc' | 'h5' | {
|
|
267
310
|
name: string;
|
|
268
311
|
title: string;
|
|
269
312
|
description: string;
|
|
@@ -272,21 +315,23 @@ export function genNaturalTSContextJSONForUI(
|
|
|
272
315
|
moduleInterfaces: any;
|
|
273
316
|
connectors: any;
|
|
274
317
|
dependencies: any;
|
|
275
|
-
}
|
|
318
|
+
},
|
|
319
|
+
restParams?: any
|
|
276
320
|
) {
|
|
277
321
|
const frontend = currentNode.getAncestor('Frontend') as Frontend;
|
|
278
|
-
const state = createCompilerState();
|
|
322
|
+
const state = createCompilerState('', { descriptionComment: true, needNamespace: true, typeMap: restParams?.typeMap });
|
|
279
323
|
|
|
280
324
|
const { naslCore } = getNaslCore('view_logic');
|
|
281
325
|
const { naslUtil } = getNaslUtil();
|
|
282
|
-
const { naslUI } =
|
|
326
|
+
const { naslUI } = getNaslUIOld();
|
|
327
|
+
const components = getNaslUI(app, frontend.type, {
|
|
283
328
|
basicMaterials: material?.basicMaterials,
|
|
284
329
|
extensionMaterials: material?.extensionMaterials,
|
|
285
|
-
});
|
|
330
|
+
}).naslUI;
|
|
286
331
|
const { enums } = getEnums(app, state);
|
|
287
332
|
const { entities } = getEntities(app, state);
|
|
288
333
|
const { structures } = getStructures(app, state);
|
|
289
|
-
const { appLogics } = getLogics(app, currentNode);
|
|
334
|
+
const { appLogics } = getLogics(app, currentNode, state);
|
|
290
335
|
const { interfaceDependencies } = getModuleInterfaces(
|
|
291
336
|
material?.moduleInterfaces || app?.interfaceDependencies,
|
|
292
337
|
state
|
|
@@ -299,12 +344,15 @@ export function genNaturalTSContextJSONForUI(
|
|
|
299
344
|
);
|
|
300
345
|
const { frontendVariables } = getFrontendVariables(frontend, state);
|
|
301
346
|
const { views } = getFrontendViews(frontend, state, currentNode, false);
|
|
302
|
-
const { currentLogic } = getCurrentNodeContextForUI(currentNode);
|
|
347
|
+
const { currentLogic } = getCurrentNodeContextForUI(currentNode, restParams?.typeMap);
|
|
348
|
+
const { componentDeclaration } = getCurrentComponentDeclaration(currentNode, components);
|
|
303
349
|
|
|
304
350
|
return {
|
|
305
351
|
naslCore,
|
|
306
352
|
naslUtil,
|
|
307
353
|
naslUI,
|
|
354
|
+
components,
|
|
355
|
+
componentDeclaration,
|
|
308
356
|
enums,
|
|
309
357
|
entities,
|
|
310
358
|
structures,
|
|
@@ -333,7 +381,8 @@ export const genNaturalTSContextFromJSONForUI = (
|
|
|
333
381
|
const {
|
|
334
382
|
naslCore,
|
|
335
383
|
naslUtil,
|
|
336
|
-
|
|
384
|
+
components,
|
|
385
|
+
componentDeclaration,
|
|
337
386
|
enums,
|
|
338
387
|
entities,
|
|
339
388
|
structures,
|
|
@@ -346,18 +395,18 @@ export const genNaturalTSContextFromJSONForUI = (
|
|
|
346
395
|
} = tsContextJSON;
|
|
347
396
|
|
|
348
397
|
let code = '';
|
|
349
|
-
code += '### [1]
|
|
398
|
+
code += '### [1] 标准库与类型定义\n';
|
|
350
399
|
code += wrapTSBlock(naslCore);
|
|
351
400
|
|
|
352
|
-
code += '\n### [2]
|
|
401
|
+
code += '\n### [2] 平台内置函数库\n';
|
|
353
402
|
code += wrapTSBlock(naslUtil);
|
|
354
403
|
|
|
355
|
-
if (
|
|
404
|
+
if (components) {
|
|
356
405
|
code += '\n### [3] nasl.ui\n';
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
code +=
|
|
406
|
+
code += getNaslUICode(components, codeType, requiredIndexes);
|
|
407
|
+
if (componentDeclaration) {
|
|
408
|
+
code += '\n#### [3-1] 组件声明\n';
|
|
409
|
+
code += wrapTSBlock(`declare namespace nasl.ui {\n${componentDeclaration}\n}`);
|
|
361
410
|
}
|
|
362
411
|
}
|
|
363
412
|
|
|
@@ -393,11 +442,10 @@ export const genNaturalTSContextFromJSONForUI = (
|
|
|
393
442
|
}
|
|
394
443
|
|
|
395
444
|
code += '\n### [10] 页面上下文\n';
|
|
396
|
-
if (frontendVariables) {
|
|
445
|
+
if (frontendVariables?.data?.length) {
|
|
397
446
|
code += '\n#### [10-0] 前端全局变量\n';
|
|
398
|
-
code += frontendVariables;
|
|
447
|
+
code += getVariablesCode(frontendVariables);
|
|
399
448
|
}
|
|
400
|
-
|
|
401
449
|
if (views?.data?.length) {
|
|
402
450
|
code += '\n#### [10-1] 前端页面列表\n';
|
|
403
451
|
code += getFrontendViewsCode(views);
|
|
@@ -416,8 +464,8 @@ export function genNaturalTSContextForUI(
|
|
|
416
464
|
focusedNodePath?: string,
|
|
417
465
|
requiredIndexes?: string[],
|
|
418
466
|
material?: {
|
|
419
|
-
basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string };
|
|
420
|
-
extensionMaterials: {
|
|
467
|
+
basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
|
|
468
|
+
extensionMaterials: 'pc' | 'h5' | {
|
|
421
469
|
name: string;
|
|
422
470
|
title: string;
|
|
423
471
|
description: string;
|
|
@@ -428,13 +476,14 @@ export function genNaturalTSContextForUI(
|
|
|
428
476
|
dependencies: any;
|
|
429
477
|
},
|
|
430
478
|
restParams?: {
|
|
431
|
-
codeType
|
|
479
|
+
codeType: 'detail' | 'short';
|
|
480
|
+
typeMap?: any;
|
|
432
481
|
}
|
|
433
482
|
) {
|
|
434
|
-
const tsContextJSON = genNaturalTSContextJSONForUI(app, currentNode, material);
|
|
483
|
+
const tsContextJSON = genNaturalTSContextJSONForUI(app, currentNode, material, restParams);
|
|
435
484
|
const code = genNaturalTSContextFromJSONForUI(
|
|
436
485
|
tsContextJSON,
|
|
437
|
-
restParams
|
|
486
|
+
restParams?.codeType || 'short',
|
|
438
487
|
requiredIndexes
|
|
439
488
|
);
|
|
440
489
|
return code;
|
|
@@ -50,7 +50,10 @@ export function handleMaterial({ json, tsDeclaration }: { json: Array<{ name: st
|
|
|
50
50
|
snippets.forEach((code) => {
|
|
51
51
|
const cap = code.match(/class ([a-zA-Z]+).+?extends ViewComponent/);
|
|
52
52
|
if (cap) {
|
|
53
|
-
|
|
53
|
+
const newCode = code
|
|
54
|
+
.replace(/nasl\.core\./g, "")
|
|
55
|
+
.replace(/Integer/g, "Long");
|
|
56
|
+
snippetMap[cap[1]] = `declare namespace nasl.ui${newCode}`;
|
|
54
57
|
}
|
|
55
58
|
});
|
|
56
59
|
json.forEach((item) => {
|
|
@@ -79,12 +82,12 @@ export function getPreDeclaration() {
|
|
|
79
82
|
/// #if process.env.BUILD_TARGET === 'node'
|
|
80
83
|
if (globalThis.process) { // For TS build
|
|
81
84
|
const fs = require('fs');
|
|
82
|
-
code = fs.readFileSync(require.resolve(`../../../sandbox-natural/stdlib/nasl.ui.
|
|
85
|
+
code = fs.readFileSync(require.resolve(`../../../sandbox-natural/stdlib/nasl.ui.d.ts`), 'utf8');
|
|
83
86
|
}
|
|
84
87
|
/// #endif
|
|
85
88
|
/// #if process.env.BUILD_TARGET !== 'node'
|
|
86
89
|
if (globalThis.window) { // For TS build
|
|
87
|
-
code = require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.ui.
|
|
90
|
+
code = require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.ui.d.ts').default;
|
|
88
91
|
}
|
|
89
92
|
/// #endif
|
|
90
93
|
return code;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as utils from '../../utils';
|
|
1
2
|
import { App, View, Logic, BaseNode, Frontend, Namespace, Module, TypeAnnotation, Structure, Connection, Connector } from '../../concepts';
|
|
2
3
|
import { shiftState, createCompilerState, TranslatorState, indent } from '../../translator';
|
|
3
4
|
import { getPreDeclaration, getUILib, handleMaterial, getExtensionsMaterial } from './getUILib';
|
|
@@ -86,7 +87,7 @@ export function getLogicWithStructuresCode(logic: Logic, type: string, desc: { d
|
|
|
86
87
|
|
|
87
88
|
newRelationStructures?.forEach((reference: { typeNamespace: string; typeName: string; }) => {
|
|
88
89
|
const { typeName } = reference || {};
|
|
89
|
-
const state = createCompilerState();
|
|
90
|
+
const state = createCompilerState('', { descriptionComment: true });
|
|
90
91
|
const tabSize = namespace ? shiftState(state, code, { tabSize: 1 }) : undefined;
|
|
91
92
|
structures?.filter((structure: any) => structure?.name === typeName)
|
|
92
93
|
?.forEach((structure: any) => {
|
|
@@ -96,15 +97,15 @@ export function getLogicWithStructuresCode(logic: Logic, type: string, desc: { d
|
|
|
96
97
|
if (namespace && newRelationStructures?.length) {
|
|
97
98
|
code += `}\n`;
|
|
98
99
|
}
|
|
99
|
-
const {
|
|
100
|
-
if (description) code += `// ${description}\n`;
|
|
100
|
+
const { codeStr } = desc || {};
|
|
101
|
+
// if (description) code += `// ${description}\n`;
|
|
101
102
|
if (codeStr) code += `${codeStr}\n`;
|
|
102
103
|
code = wrapTSBlock(code);
|
|
103
104
|
return code;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
export function getNaslCore(logicType: string) {
|
|
107
|
-
let naslCore = `${getNASLStdlibMap('nasl.core.ts')}\n`;
|
|
108
|
+
let naslCore = `${getNASLStdlibMap('nasl.core.d.ts')}\n`;
|
|
108
109
|
if (logicType === 'global_logic')
|
|
109
110
|
naslCore += `// 分页组件函数,用于分页
|
|
110
111
|
declare function PAGINATE<T>(list: List<T>, page: Integer, size: Integer): { list: List<T>, total: Integer; };
|
|
@@ -114,7 +115,7 @@ declare function PAGINATE<T>(list: List<T>, page: Integer, size: Integer): { lis
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
export function getNaslUtil() {
|
|
117
|
-
const naslUtil = `${getNASLStdlibMap('nasl.util.ts')}\n`;
|
|
118
|
+
const naslUtil = `${getNASLStdlibMap('nasl.util.d.ts')}\n`;
|
|
118
119
|
const code = wrapTSBlock(naslUtil);
|
|
119
120
|
return { code, naslUtil };
|
|
120
121
|
}
|
|
@@ -125,7 +126,7 @@ export const getNaslUI = (
|
|
|
125
126
|
material:
|
|
126
127
|
{
|
|
127
128
|
basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
|
|
128
|
-
extensionMaterials: {
|
|
129
|
+
extensionMaterials: 'pc' | 'h5' | {
|
|
129
130
|
name: string;
|
|
130
131
|
title: string;
|
|
131
132
|
description: string;
|
|
@@ -170,19 +171,20 @@ export const getNaslUICode = (naslUI: any, codeType: 'detail' | 'short', require
|
|
|
170
171
|
*/
|
|
171
172
|
${item.tsDeclaration}`).join('\n')}`);
|
|
172
173
|
} else {
|
|
174
|
+
code += wrapTSBlock(preDeclaration);
|
|
173
175
|
code += uiLib.map((item: any, index: number) => `[3-${index}] ${item.name} | ${item.title} | ${item.description}`).join('\n');
|
|
174
176
|
}
|
|
175
177
|
return code;
|
|
176
178
|
};
|
|
177
179
|
|
|
178
180
|
export const getNaslUIOld = () => {
|
|
179
|
-
const naslUI = `${getNASLStdlibMap('nasl.ui.ts')}\n`;
|
|
181
|
+
const naslUI = `${getNASLStdlibMap('nasl.ui.d.ts')}\n`;
|
|
180
182
|
const code = wrapTSBlock(naslUI);
|
|
181
183
|
return { code, naslUI };
|
|
182
184
|
};
|
|
183
185
|
|
|
184
186
|
export function getNaslOQL() {
|
|
185
|
-
const naslOql = `${getNASLStdlibMap('nasl.oql.ts')}\n`;
|
|
187
|
+
const naslOql = `${getNASLStdlibMap('nasl.oql.d.ts')}\n`;
|
|
186
188
|
const code = wrapTSBlock(naslOql);
|
|
187
189
|
return { code, naslOql };
|
|
188
190
|
}
|
|
@@ -215,7 +217,7 @@ export function getEntities(app: App, state: TranslatorState) {
|
|
|
215
217
|
const data = [] as Snippet[];
|
|
216
218
|
const namespace = `app.dataSources.${dataSource?.name}.entities`;
|
|
217
219
|
dataSource.entities
|
|
218
|
-
.filter((entity) => !entity.name.startsWith('LCAP') || entity.name === 'LCAPUser')
|
|
220
|
+
// .filter((entity) => !entity.name.startsWith('LCAP') || entity.name === 'LCAPUser')
|
|
219
221
|
.forEach((entity) => {
|
|
220
222
|
const entityName = `app.dataSources.${dataSource?.name}.entities.${entity?.name}`;
|
|
221
223
|
const tempCode = `${entity?.toNaturalTS({ ...state, needNamespace: true }, entityName)}`;
|
|
@@ -231,7 +233,7 @@ export const getEntitiesCode = (entities: any) => {
|
|
|
231
233
|
entities?.forEach((entity: any) => {
|
|
232
234
|
code += `declare namespace ${entity?.namespace} {\n`;
|
|
233
235
|
entity?.data?.forEach((item: any) => {
|
|
234
|
-
code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
236
|
+
// code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
235
237
|
code += `${item.code}\n`;
|
|
236
238
|
});
|
|
237
239
|
code += `}\n`;
|
|
@@ -244,7 +246,7 @@ export function getStructures(app: App, state: TranslatorState) {
|
|
|
244
246
|
const data = [] as Snippet[];
|
|
245
247
|
const namespace = `app.structures`;
|
|
246
248
|
app.structures
|
|
247
|
-
.filter((entity) => !entity.name.startsWith('LCAP'))
|
|
249
|
+
// .filter((entity) => !entity.name.startsWith('LCAP'))
|
|
248
250
|
.forEach((structure) => {
|
|
249
251
|
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}`;
|
|
250
252
|
data.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
@@ -256,7 +258,7 @@ export const getStructuresCode = (structures: any) => {
|
|
|
256
258
|
let code = '';
|
|
257
259
|
code += `declare namespace ${structures?.namespace} {\n`;
|
|
258
260
|
structures?.data?.forEach((item: any) => {
|
|
259
|
-
code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
261
|
+
// code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
260
262
|
code += `${item.code}\n`;
|
|
261
263
|
});
|
|
262
264
|
code += `}\n`;
|
|
@@ -265,14 +267,14 @@ export const getStructuresCode = (structures: any) => {
|
|
|
265
267
|
};
|
|
266
268
|
|
|
267
269
|
|
|
268
|
-
export function getLogics(app: App, currentNode: BaseNode) {
|
|
270
|
+
export function getLogics(app: App, currentNode: BaseNode, state: TranslatorState) {
|
|
269
271
|
const data = [] as Snippet[];
|
|
270
272
|
const namespace = `app.logics`;
|
|
271
273
|
app?.logics
|
|
272
274
|
?.filter((logic) => logic !== currentNode && !logic.name.startsWith('LCAP'))
|
|
273
275
|
?.forEach((logic) => {
|
|
274
276
|
const rename = logic?.calleewholeKey;
|
|
275
|
-
const tempCode = `${logic?.toNaturalTS({ needNamespace: true, rename, declaration: true })}`;
|
|
277
|
+
const tempCode = `${logic?.toNaturalTS({ ...state, needNamespace: true, rename, declaration: true })}`;
|
|
276
278
|
const description = logic?.description || '';
|
|
277
279
|
|
|
278
280
|
data.push({ description, code: tempCode });
|
|
@@ -287,7 +289,8 @@ export const getLogicsCode = (appLogics: any, codeType: 'detail' | 'short', requ
|
|
|
287
289
|
const logicIndex = `6-${index}`;
|
|
288
290
|
if (requiredIndexes?.length && !requiredIndexes?.includes(logicIndex)) return;
|
|
289
291
|
const tempCode = codeType === 'short' ? item.code.replace(`${appLogics.namespace}.`, '') : item.code;
|
|
290
|
-
code += `[${logicIndex}]
|
|
292
|
+
code += `[${logicIndex}] \`${tempCode}\`\n`;
|
|
293
|
+
// code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
291
294
|
});
|
|
292
295
|
return code;
|
|
293
296
|
};
|
|
@@ -338,8 +341,8 @@ export const getModuleInterfacesCode = (interfaceDependencies: any, codeType: 'd
|
|
|
338
341
|
if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex)) return;
|
|
339
342
|
if (codeType === 'short') {
|
|
340
343
|
const tempCode = item.code.replace(`${interfaceDependency?.logics.namespace}.`, '');
|
|
341
|
-
|
|
342
|
-
code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
344
|
+
code += `[${interfaceIndex}] \`${tempCode}\`\n`;
|
|
345
|
+
// code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
343
346
|
} else {
|
|
344
347
|
code += item.codeWithDetail;
|
|
345
348
|
}
|
|
@@ -542,13 +545,37 @@ export const getDependenciesCode = (dependencies: any, codeType: 'detail' | 'sho
|
|
|
542
545
|
|
|
543
546
|
export function getFrontendVariables(frontend: Frontend, state: TranslatorState) {
|
|
544
547
|
let code = '';
|
|
548
|
+
const data = [] as Snippet[];
|
|
549
|
+
const namespace = frontend?.variables?.[0]?.getNamespace() || '';
|
|
545
550
|
frontend?.variables?.forEach((variable) => {
|
|
546
|
-
const tempCode = `let ${variable?.toNaturalTS(shiftState(state, code, { inline: true }))};\n`;
|
|
551
|
+
const tempCode = `let ${variable?.toNaturalTS(shiftState(state, code, { inline: true, needNamespace: true, }))};\n`;
|
|
552
|
+
data.push({ description: variable?.description || '', code: tempCode });
|
|
553
|
+
code += tempCode;
|
|
554
|
+
});
|
|
555
|
+
return { namespace, frontendVariables: { namespace, data } };
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
export function getServerVariables(app: App, state: TranslatorState) {
|
|
559
|
+
let code = '';
|
|
560
|
+
const data = [] as Snippet[];
|
|
561
|
+
const namespace = 'app.backend.variables';
|
|
562
|
+
app.backend?.variables?.forEach((variable) => {
|
|
563
|
+
const tempCode = `let ${variable?.toNaturalTS(shiftState(state, code, { inline: true, needNamespace: true, }))};\n`;
|
|
564
|
+
data.push({ description: variable?.description || '', code: tempCode });
|
|
547
565
|
code += tempCode;
|
|
548
566
|
});
|
|
549
|
-
return {
|
|
567
|
+
return { namespace, backendVariables: { namespace, data } };
|
|
550
568
|
}
|
|
551
569
|
|
|
570
|
+
export const getVariablesCode = (variables: any) => {
|
|
571
|
+
let code = '';
|
|
572
|
+
variables?.data?.forEach((item: any) => {
|
|
573
|
+
code += item.description ? `/* ${item.description} */ \n` : '';
|
|
574
|
+
code += item.code;
|
|
575
|
+
});
|
|
576
|
+
return wrapTSBlock(code);
|
|
577
|
+
};
|
|
578
|
+
|
|
552
579
|
export function getChildrenViews(view: View, currentNode: BaseNode, convertChildren: boolean, prefix: string) {
|
|
553
580
|
const data = [] as Snippet[];
|
|
554
581
|
if (view?.children?.length > 0) {
|
|
@@ -606,7 +633,7 @@ export const getFrontendViewsCode = (views: any) => {
|
|
|
606
633
|
return wrapTSBlock(code);
|
|
607
634
|
};
|
|
608
635
|
|
|
609
|
-
export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: string, experimental?: boolean) {
|
|
636
|
+
export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: string, experimental?: boolean, typeMap?: any) {
|
|
610
637
|
let code = '';
|
|
611
638
|
let view: View;
|
|
612
639
|
if (currentNode?.concept === 'View') {
|
|
@@ -631,14 +658,16 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
|
|
|
631
658
|
createCompilerState('', {
|
|
632
659
|
focusedNodePath,
|
|
633
660
|
needNamespace: true,
|
|
661
|
+
typeMap,
|
|
634
662
|
}),
|
|
635
663
|
function (state) {
|
|
636
664
|
let code = '';
|
|
637
665
|
code += `\n${indent(state.tabSize)}`;
|
|
638
|
-
|
|
666
|
+
|
|
639
667
|
if (experimental) {
|
|
640
668
|
code += this.elements[0].toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1 }));
|
|
641
669
|
} else {
|
|
670
|
+
code += `${indent(state.tabSize + 1)}`;
|
|
642
671
|
code += `const $refs = {\n`;
|
|
643
672
|
// 生成所有的name和类型定义
|
|
644
673
|
this.elements.forEach((element) => {
|
|
@@ -653,17 +682,36 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
|
|
|
653
682
|
// 逻辑
|
|
654
683
|
if (currentNode?.concept === 'Logic') {
|
|
655
684
|
code += '\n';
|
|
685
|
+
this.bindEvents.forEach((bindEvent) => {
|
|
686
|
+
bindEvent.logics.forEach((logic) => {
|
|
687
|
+
if (logic === currentNode) return;
|
|
688
|
+
const logicCode = logic.toNaturalTS(
|
|
689
|
+
shiftState(state, code, {
|
|
690
|
+
tabSize: state.tabSize + 1,
|
|
691
|
+
// declaration: true,
|
|
692
|
+
autoPrefixName: true,
|
|
693
|
+
})
|
|
694
|
+
);
|
|
695
|
+
code += logicCode.replace('function ', 'private function ');
|
|
696
|
+
code += '\n';
|
|
697
|
+
});
|
|
698
|
+
if (bindEvent.logics.length) code += '\n';
|
|
699
|
+
});
|
|
700
|
+
|
|
656
701
|
this.logics.forEach((logic) => {
|
|
657
702
|
if (logic === currentNode) return;
|
|
658
|
-
|
|
703
|
+
const logicCode = logic.toNaturalTS(
|
|
659
704
|
shiftState(state, code, {
|
|
660
705
|
tabSize: state.tabSize + 1,
|
|
661
706
|
declaration: true,
|
|
662
707
|
autoPrefixName: true,
|
|
663
708
|
})
|
|
664
709
|
);
|
|
710
|
+
code += logicCode.replace('declare function', 'function');
|
|
665
711
|
code += '\n';
|
|
666
712
|
});
|
|
713
|
+
if (this.logics.length) code += '\n';
|
|
714
|
+
|
|
667
715
|
// 包含了事件逻辑的处理
|
|
668
716
|
code += `${indent(state.tabSize + 1)}/* 当前逻辑 */\n`;
|
|
669
717
|
code += (currentNode as Logic).toNaturalTS(
|
|
@@ -700,13 +748,14 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
|
|
|
700
748
|
needNamespace: true,
|
|
701
749
|
declaration: logic !== currentNode,
|
|
702
750
|
autoPrefixName: true,
|
|
751
|
+
typeMap
|
|
703
752
|
})
|
|
704
753
|
);
|
|
705
754
|
}
|
|
706
755
|
return { code: wrapTSBlock(code), currentLogic: code };
|
|
707
756
|
}
|
|
708
757
|
|
|
709
|
-
export function getCurrentNodeContextForUI(currentNode: BaseNode) {
|
|
758
|
+
export function getCurrentNodeContextForUI(currentNode: BaseNode, typeMap?: any) {
|
|
710
759
|
let code = '';
|
|
711
760
|
let view: View;
|
|
712
761
|
if (currentNode?.concept === 'View') {
|
|
@@ -725,9 +774,62 @@ export function getCurrentNodeContextForUI(currentNode: BaseNode) {
|
|
|
725
774
|
code += view?.toNaturalTS(
|
|
726
775
|
createCompilerState('', {
|
|
727
776
|
needNamespace: true,
|
|
777
|
+
typeMap,
|
|
728
778
|
})
|
|
729
779
|
);
|
|
730
780
|
}
|
|
731
781
|
|
|
732
782
|
return { code: wrapTSBlock(code), currentLogic: code };
|
|
733
783
|
}
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
const calcComponent = (activeDesignerNode: any) => {
|
|
787
|
+
const view = activeDesignerNode?.concept === 'View' ? activeDesignerNode?.elements?.[0] : (activeDesignerNode.getAncestor('View') as any)?.elements?.[0];
|
|
788
|
+
const componentSet = new Set();
|
|
789
|
+
if (view) {
|
|
790
|
+
utils.traverse(({ node }: { node: any; }) => {
|
|
791
|
+
if (node.concept === 'ViewElement') {
|
|
792
|
+
const name = utils.kebab2Camel(node.tag);
|
|
793
|
+
componentSet.add(name);
|
|
794
|
+
}
|
|
795
|
+
}, { node: view });
|
|
796
|
+
}
|
|
797
|
+
return componentSet;
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
const extractUFormClass = (tsDeclaration: string) => {
|
|
802
|
+
const regex = /class\s+(\w+)(?:<[^>]+>)?\s+extends\s+(\w+)\s*\{(.*?)\}/s;
|
|
803
|
+
const match = tsDeclaration.match(regex);
|
|
804
|
+
let code = '';
|
|
805
|
+
if (match) {
|
|
806
|
+
const [, className, baseClassName, classBody] = match;
|
|
807
|
+
const methodRegex = /\s*(\w+)\(([^)]*)\):\s*(\w+)/g;
|
|
808
|
+
code = `export class ${className} extends ${baseClassName} {`;
|
|
809
|
+
const newClassBody = classBody.replace(/nasl\.core\./g, "")
|
|
810
|
+
.replace(/Integer/g, "Long");
|
|
811
|
+
const body = newClassBody.replace(methodRegex, (method) => {
|
|
812
|
+
code += `${method};`;
|
|
813
|
+
return '';
|
|
814
|
+
});
|
|
815
|
+
code += `\n}\n`;
|
|
816
|
+
if (body === classBody) {
|
|
817
|
+
return '';
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
return code;
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
export function getCurrentComponentDeclaration(activeDesignerNode: any, components: any) {
|
|
824
|
+
let code = '';
|
|
825
|
+
const componentSet = calcComponent(activeDesignerNode);
|
|
826
|
+
if (!componentSet.size) return { componentDeclaration: '' };
|
|
827
|
+
// 遍历map,找到对应的组件
|
|
828
|
+
const result = components.filter((component: any) => componentSet.has(component.name));
|
|
829
|
+
result.forEach((component: any) => {
|
|
830
|
+
const newTsDeclaration = component.tsDeclaration;
|
|
831
|
+
const uFormClass = extractUFormClass(newTsDeclaration);
|
|
832
|
+
code += uFormClass;
|
|
833
|
+
});
|
|
834
|
+
return { componentDeclaration: code };
|
|
835
|
+
}
|