@lcap/nasl 3.8.2-beta.8 → 3.8.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai-engineer.config.js +617 -0
- package/out/common/BaseNode.js +5 -3
- package/out/common/BaseNode.js.map +1 -1
- package/out/common/ComponentAPI.d.ts +9 -0
- package/out/concepts/AuthLogicForCallInterface__.js +21 -6
- package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
- package/out/concepts/BackendVariable__.js +16 -1
- package/out/concepts/BackendVariable__.js.map +1 -1
- package/out/concepts/BindAttribute__.js +12 -4
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindDirective__.js +1 -1
- package/out/concepts/BindDirective__.js.map +1 -1
- package/out/concepts/BindStyle__.js +1 -1
- package/out/concepts/BindStyle__.js.map +1 -1
- package/out/concepts/BusinessComponent__.js +24 -8
- package/out/concepts/BusinessComponent__.js.map +1 -1
- package/out/concepts/BusinessLogic__.js +21 -6
- package/out/concepts/BusinessLogic__.js.map +1 -1
- package/out/concepts/CallInterface__.js +2 -1
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.d.ts +1 -0
- package/out/concepts/CallLogic__.js +32 -11
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.d.ts +1 -0
- package/out/concepts/CallQueryComponent__.js +23 -12
- package/out/concepts/CallQueryComponent__.js.map +1 -1
- package/out/concepts/Destination__.js +11 -8
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/EntityProperty__.js +3 -2
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/Entity__.js +1 -1
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/Interface__.js +1 -1
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/Logic__.js +49 -17
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MemberExpression__.js +19 -13
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/OqlQueryComponent__.js +37 -12
- package/out/concepts/OqlQueryComponent__.js.map +1 -1
- package/out/concepts/OverriddenLogic__.js +21 -6
- package/out/concepts/OverriddenLogic__.js.map +1 -1
- package/out/concepts/Param__.js +5 -4
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/QueryOrderByExpression__.d.ts +0 -1
- package/out/concepts/QueryOrderByExpression__.js +0 -1
- package/out/concepts/QueryOrderByExpression__.js.map +1 -1
- package/out/concepts/Structure__.js +5 -7
- package/out/concepts/Structure__.js.map +1 -1
- package/out/concepts/Variable__.js +5 -0
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +1 -0
- package/out/concepts/ViewElement__.js +17 -7
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.js +70 -14
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.processV2.js +78 -0
- package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.ui.js +40 -40
- package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
- package/out/generator/genBundleFiles.js +1 -1
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/release-body/utils.js +1 -1
- package/out/natural/genNaturalTS.d.ts +45 -10
- package/out/natural/genNaturalTS.js +57 -33
- package/out/natural/genNaturalTS.js.map +1 -1
- package/out/natural/getContext/getUILib.js +6 -3
- package/out/natural/getContext/getUILib.js.map +1 -1
- package/out/natural/getContext/index.d.ts +20 -7
- package/out/natural/getContext/index.js +143 -23
- package/out/natural/getContext/index.js.map +1 -1
- package/out/natural/getContext/naslStdlibMap.js +8 -8
- package/out/natural/getContext/naslStdlibMap.js.map +1 -1
- package/out/natural/tools.d.ts +16 -0
- package/out/natural/tools.js +110 -2
- package/out/natural/tools.js.map +1 -1
- package/out/natural/transformTS2UI.js +361 -304
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.d.ts +3 -5
- package/out/natural/transformTSCode.js +30 -1089
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/natural/transforms/registerTransform.d.ts +7 -0
- package/out/natural/transforms/registerTransform.js +24 -0
- package/out/natural/transforms/registerTransform.js.map +1 -0
- package/out/natural/transforms/transform2LogicItem.d.ts +24 -0
- package/out/natural/transforms/transform2LogicItem.js +1240 -0
- package/out/natural/transforms/transform2LogicItem.js.map +1 -0
- package/out/natural/transforms/transform2TypeAnnotation.d.ts +2 -0
- package/out/natural/transforms/transform2TypeAnnotation.js +86 -0
- package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -0
- package/out/natural/transforms/utils.d.ts +8 -0
- package/out/natural/transforms/utils.js +59 -0
- package/out/natural/transforms/utils.js.map +1 -0
- package/out/server/getLogics.js +12 -12
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.js +11 -17
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/naslServer.d.ts +2 -2
- package/out/server/naslServer.js +38 -18
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.js +5 -0
- package/out/server/translator.js.map +1 -1
- package/out/templator/block2nasl/jsx2nasl/index.d.ts +5 -0
- package/out/templator/block2nasl/jsx2nasl/index.js +15 -0
- package/out/templator/block2nasl/jsx2nasl/index.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.d.ts +3 -0
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js +213 -0
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.d.ts +14 -0
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js +201 -0
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.d.ts +4 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js +186 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.d.ts +28 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js +336 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/utils.d.ts +2 -0
- package/out/templator/block2nasl/jsx2nasl/utils.js +26 -0
- package/out/templator/block2nasl/jsx2nasl/utils.js.map +1 -0
- package/out/templator/block2nasl/transformBlock2Nasl.d.ts +10 -0
- package/out/templator/block2nasl/transformBlock2Nasl.js +122 -0
- package/out/templator/block2nasl/transformBlock2Nasl.js.map +1 -0
- package/out/templator/block2nasl/viewMergeBlock.d.ts +9 -0
- package/out/templator/block2nasl/viewMergeBlock.js +110 -0
- package/out/templator/block2nasl/viewMergeBlock.js.map +1 -0
- package/out/translator/types.d.ts +2 -0
- package/out/translator/utils.js +1 -1
- package/out/translator/utils.js.map +1 -1
- package/out/utils/index.js +0 -4
- package/out/utils/index.js.map +1 -1
- package/out/utils/language-cache/constant.d.ts +2 -1
- package/out/utils/language-cache/constant.js +1 -0
- package/out/utils/language-cache/constant.js.map +1 -1
- package/out/utils/language-cache/nasl.d.ts +1 -0
- package/out/utils/language-cache/nasl.js +9 -1
- package/out/utils/language-cache/nasl.js.map +1 -1
- package/package.json +6 -2
- package/sandbox/stdlib/nasl.processV2.ts +19 -0
- package/sandbox/stdlib/nasl.ui.ts +8 -8
- package/sandbox-natural/stdlib/nasl.core.d.ts +54 -0
- package/sandbox-natural/stdlib/nasl.oql.d.ts +22 -0
- package/sandbox-natural/stdlib/nasl.ui.d.ts +78 -0
- package/sandbox-natural/stdlib/nasl.ui.h5.d.ts +1684 -1643
- package/sandbox-natural/stdlib/nasl.ui.h5.json +15746 -15045
- package/sandbox-natural/stdlib/nasl.ui.pc.d.ts +5341 -5154
- package/sandbox-natural/stdlib/nasl.ui.pc.json +31176 -30681
- package/sandbox-natural/stdlib/{nasl.util.ts → nasl.util.d.ts} +49 -43
- package/src/common/BaseNode.ts +5 -3
- package/src/common/ComponentAPI.ts +7 -0
- package/src/concepts/AuthLogicForCallInterface__.ts +23 -6
- package/src/concepts/BackendVariable__.ts +16 -1
- package/src/concepts/BindAttribute__.ts +18 -13
- package/src/concepts/BindDirective__.ts +1 -1
- package/src/concepts/BindStyle__.ts +1 -1
- package/src/concepts/BusinessComponent__.ts +26 -8
- package/src/concepts/BusinessLogic__.ts +23 -6
- package/src/concepts/CallInterface__.ts +2 -2
- package/src/concepts/CallLogic__.ts +50 -24
- package/src/concepts/CallQueryComponent__.ts +26 -12
- package/src/concepts/Destination__.ts +14 -12
- package/src/concepts/EntityProperty__.ts +5 -5
- package/src/concepts/Entity__.ts +1 -1
- package/src/concepts/Interface__.ts +1 -1
- package/src/concepts/Logic__.ts +62 -33
- package/src/concepts/MemberExpression__.ts +20 -13
- package/src/concepts/OqlQueryComponent__.ts +29 -5
- package/src/concepts/OverriddenLogic__.ts +23 -6
- package/src/concepts/Param__.ts +5 -4
- package/src/concepts/QueryOrderByExpression__.ts +0 -1
- package/src/concepts/Structure__.ts +5 -7
- package/src/concepts/Variable__.ts +9 -5
- package/src/concepts/ViewElement__.ts +25 -9
- package/src/concepts/View__.ts +97 -37
- package/src/concepts/basics/stdlib/nasl.processV2.ts +79 -0
- package/src/concepts/basics/stdlib/nasl.ui.ts +40 -40
- package/src/generator/genBundleFiles.ts +1 -1
- package/src/generator/release-body/utils.ts +1 -1
- package/src/natural/genNaturalTS.ts +88 -39
- package/src/natural/getContext/getUILib.ts +6 -3
- package/src/natural/getContext/index.ts +125 -23
- package/src/natural/getContext/naslStdlibMap.ts +8 -8
- package/src/natural/tools.ts +107 -2
- package/src/natural/transformTS2UI.ts +205 -147
- package/src/natural/transformTSCode.ts +29 -1055
- package/src/natural/transforms/registerTransform.ts +34 -0
- package/src/natural/transforms/transform2LogicItem.ts +1335 -0
- package/src/natural/transforms/transform2TypeAnnotation.ts +77 -0
- package/src/natural/transforms/utils.ts +25 -0
- package/src/server/getLogics.ts +12 -12
- package/src/server/getMemberIdentifier.ts +14 -14
- package/src/server/naslServer.ts +39 -19
- package/src/server/translator.ts +5 -0
- package/src/templator/block2nasl/jsx2nasl/index.ts +11 -0
- package/src/templator/block2nasl/jsx2nasl/transform-expression2nasl.ts +238 -0
- package/src/templator/block2nasl/jsx2nasl/transform-func2nasl.ts +241 -0
- package/src/templator/block2nasl/jsx2nasl/transform-tstype2nasl.ts +213 -0
- package/src/templator/block2nasl/jsx2nasl/transform-tsx2nasl.ts +422 -0
- package/src/templator/block2nasl/jsx2nasl/utils.ts +19 -0
- package/src/templator/block2nasl/transformBlock2Nasl.ts +99 -0
- package/src/templator/block2nasl/viewMergeBlock.ts +149 -0
- package/src/translator/types.ts +2 -0
- package/src/translator/utils.ts +1 -1
- package/src/utils/index.ts +0 -4
- package/src/utils/language-cache/constant.ts +1 -0
- package/src/utils/language-cache/nasl.ts +6 -0
- package/test/concepts/member-expression/__snapshots__/toJS.spec.ts.snap +1 -1
- package/test/concepts/member-expression/__snapshots__/toVue.spec.ts.snap +1 -1
- package/test/tdd/dataQuery/QueryFieldExpression/case1/ast.json +7 -0
- package/test/tdd/dataQuery/QueryFieldExpression/case1/natural.ts.txt +1 -0
- package/test/tdd/dataQuery/QueryFieldExpression/case2/ast.json +7 -0
- package/test/tdd/dataQuery/QueryFieldExpression/case2/natural.ts.txt +1 -0
- package/test/tdd/transform/case1/ast.json +243 -0
- package/test/tdd/transform/case1/natural.ts.md +20 -0
- package/test/tdd/transform/case2/ast.json +207 -0
- package/test/tdd/transform/case2/natural.ts.md +12 -0
- package/test/tdd.test.js +10 -0
- package/test/tdd.transform.test.js +38 -0
- package/test/utils.js +40 -0
- package/sandbox-natural/stdlib/nasl.core.ts +0 -36
- package/sandbox-natural/stdlib/nasl.oql.ts +0 -14
- package/sandbox-natural/stdlib/nasl.ui.pre.d.ts +0 -90
- package/sandbox-natural/stdlib/nasl.ui.ts +0 -63
|
@@ -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
|
+
}
|
|
@@ -4,20 +4,20 @@ export const getNASLStdlibMap = (key?: string) => {
|
|
|
4
4
|
if (globalThis.process) { // For TS build
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
naslStdlibMap = {
|
|
7
|
-
'nasl.core.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.core.ts'), 'utf8'),
|
|
8
|
-
'nasl.util.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.util.ts'), 'utf8'),
|
|
9
|
-
'nasl.ui.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.ui.ts'), 'utf8'),
|
|
10
|
-
'nasl.oql.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.oql.ts'), 'utf8'),
|
|
7
|
+
'nasl.core.d.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.core.d.ts'), 'utf8'),
|
|
8
|
+
'nasl.util.d.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.util.d.ts'), 'utf8'),
|
|
9
|
+
'nasl.ui.d.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.ui.d.ts'), 'utf8'),
|
|
10
|
+
'nasl.oql.d.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.oql.d.ts'), 'utf8'),
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
/// #endif
|
|
14
14
|
/// #if process.env.BUILD_TARGET !== 'node'
|
|
15
15
|
if (globalThis.window) { // For TS build
|
|
16
16
|
naslStdlibMap = {
|
|
17
|
-
'nasl.core.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.core.ts').default,
|
|
18
|
-
'nasl.util.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.util.ts').default,
|
|
19
|
-
'nasl.ui.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.ui.ts').default,
|
|
20
|
-
'nasl.oql.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.oql.ts').default
|
|
17
|
+
'nasl.core.d.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.core.d.ts').default,
|
|
18
|
+
'nasl.util.d.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.util.d.ts').default,
|
|
19
|
+
'nasl.ui.d.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.ui.d.ts').default,
|
|
20
|
+
'nasl.oql.d.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.oql.d.ts').default
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
/// #endif
|
package/src/natural/tools.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { App, BaseNode } from "src/concepts";
|
|
2
2
|
import * as utils from '../utils';
|
|
3
|
+
import { createCompilerState } from '../translator';
|
|
3
4
|
|
|
4
5
|
// 获取当前逻辑的类型
|
|
5
6
|
export const getLogicType = (activeLogic: any) => {
|
|
@@ -32,7 +33,7 @@ export const getUsedModule = (json: BaseNode) => {
|
|
|
32
33
|
useModule.push(item);
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
if (node.concept === 'ViewElement') {
|
|
36
|
+
if (node.concept === 'ViewElement' && node?.tag) {
|
|
36
37
|
const symbol = utils.kebab2Camel(node.tag);
|
|
37
38
|
const item = {
|
|
38
39
|
symbol,
|
|
@@ -80,7 +81,7 @@ export const getUnImportedModulesForLogic = (json: BaseNode, app: App, material:
|
|
|
80
81
|
// 如果 连接器 不存在,则需要导入并初始化连接
|
|
81
82
|
if (!connectorNode) {
|
|
82
83
|
item.operator = 'importAndInit';
|
|
83
|
-
const curDep = material?.connectors?.find((node: any) => node.name === item.symbol)
|
|
84
|
+
const curDep = material?.connectors?.find((node: any) => node.name === item.symbol);
|
|
84
85
|
item.version = curDep?.version;
|
|
85
86
|
item.provider = curDep?.provider || '资产中心';
|
|
86
87
|
needImportModule.needImportConnector = true;
|
|
@@ -136,3 +137,107 @@ export const getUnImportedModulesForLogic = (json: BaseNode, app: App, material:
|
|
|
136
137
|
return needImportModule;
|
|
137
138
|
};
|
|
138
139
|
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 找到当前节点所使用的当前逻辑、服务端逻辑、组件相关的推导类型
|
|
144
|
+
* @param app: 当前应用
|
|
145
|
+
* @returns 推导类型集合
|
|
146
|
+
*/
|
|
147
|
+
export const deduceType = async (app: App, activeDesignerNode: any) => {
|
|
148
|
+
const typeMap = {} as any;
|
|
149
|
+
const { logics } = app;
|
|
150
|
+
const state = createCompilerState('', { descriptionComment: true, needNamespace: true });
|
|
151
|
+
|
|
152
|
+
logics.forEach((logic: any) => {
|
|
153
|
+
if (logic?.returns?.length && !logic.name.startsWith('LCAP')) {
|
|
154
|
+
const ret = logic.returns[0];
|
|
155
|
+
const typeAnnotation = ret?.typeAnnotation || ret?.__TypeAnnotation;
|
|
156
|
+
if (typeAnnotation)
|
|
157
|
+
typeMap[ret.nodePath] = typeAnnotation.toNaturalTS(state);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const params = activeDesignerNode?.params.concat(activeDesignerNode?.virtualParams || []);
|
|
162
|
+
if (params?.length) {
|
|
163
|
+
let code = '';
|
|
164
|
+
params?.forEach((param: any, index: number) => {
|
|
165
|
+
let curCode = '';
|
|
166
|
+
if (param.name === 'event') curCode += '';
|
|
167
|
+
else curCode += param.toNaturalTS(state);
|
|
168
|
+
if (curCode && index !== params.length - 1) curCode += ', ';
|
|
169
|
+
code += curCode;
|
|
170
|
+
});
|
|
171
|
+
if (code)
|
|
172
|
+
typeMap[activeDesignerNode.nodePath] = code;
|
|
173
|
+
}
|
|
174
|
+
const view = activeDesignerNode?.concept === 'View' ? activeDesignerNode?.elements?.[0] : (activeDesignerNode.getAncestor('View') as any)?.elements?.[0];
|
|
175
|
+
if (view) {
|
|
176
|
+
const dataSchemaMap = {} as any;
|
|
177
|
+
utils.traverse(({ node }: { node: any; }) => {
|
|
178
|
+
if (node.concept === 'ViewElement') {
|
|
179
|
+
const dataSchema = node.bindAttrs.find((_: any) => _.name === 'dataSchema');
|
|
180
|
+
if (dataSchema) dataSchemaMap[dataSchema.nodePath] = node;
|
|
181
|
+
}
|
|
182
|
+
}, { node: view });
|
|
183
|
+
await Promise.all(Object.entries(dataSchemaMap).map(async ([nodePath, node]) => {
|
|
184
|
+
const res = await app.naslServer.getDataSchemaStructureOrTypeAnnotation(node as any);
|
|
185
|
+
if (res) {
|
|
186
|
+
const dataSchemaTs = res.toNaturalTS(state);
|
|
187
|
+
typeMap[nodePath] = dataSchemaTs;
|
|
188
|
+
}
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
return { typeMap };
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 组合所有的可推导类型
|
|
196
|
+
* @param app: 当前应用
|
|
197
|
+
* @returns 推导类型集合
|
|
198
|
+
*/
|
|
199
|
+
export const deduceTypeAll = async (app: App) => {
|
|
200
|
+
const typeMap = {} as any;
|
|
201
|
+
const { logics } = app;
|
|
202
|
+
const state = createCompilerState('', { descriptionComment: true, needNamespace: true });
|
|
203
|
+
|
|
204
|
+
logics.forEach((logic: any) => {
|
|
205
|
+
if (logic?.returns?.length && !logic.name.startsWith('LCAP')) {
|
|
206
|
+
const ret = logic.returns[0];
|
|
207
|
+
const typeAnnotation = ret?.typeAnnotation || ret?.__TypeAnnotation;
|
|
208
|
+
if (typeAnnotation)
|
|
209
|
+
typeMap[ret.nodePath] = typeAnnotation.toNaturalTS(state);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
const dataSchemaMap = {} as any;
|
|
213
|
+
utils.traverse(({ node }: { node: any; }) => {
|
|
214
|
+
if (node?.concept === 'ViewElement') {
|
|
215
|
+
const dataSchema = node.bindAttrs.find((_: any) => _.name === 'dataSchema');
|
|
216
|
+
if (dataSchema) dataSchemaMap[dataSchema.nodePath] = node;
|
|
217
|
+
}
|
|
218
|
+
if (node?.concept === 'Logic' && node?.parentNode?.concept === 'BindEvent') {
|
|
219
|
+
const params = node?.params.concat(node?.virtualParams || []);
|
|
220
|
+
if (params?.length) {
|
|
221
|
+
let code = '';
|
|
222
|
+
params?.forEach((param: any, index: number) => {
|
|
223
|
+
let curCode = '';
|
|
224
|
+
if (param.name === 'event') curCode += '';
|
|
225
|
+
else curCode += param.toNaturalTS(state);
|
|
226
|
+
if (curCode && index !== params.length - 1) curCode += ', ';
|
|
227
|
+
code += curCode;
|
|
228
|
+
});
|
|
229
|
+
if (code)
|
|
230
|
+
typeMap[node.nodePath] = code;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}, { node: app }, { mode: 'onlyArray' });
|
|
234
|
+
await Promise.all(Object.entries(dataSchemaMap).map(async ([nodePath, node]) => {
|
|
235
|
+
const res = await app.naslServer.getDataSchemaStructureOrTypeAnnotation(node as any);
|
|
236
|
+
if (res) {
|
|
237
|
+
const dataSchemaTs = res.toNaturalTS(state);
|
|
238
|
+
typeMap[nodePath] = dataSchemaTs;
|
|
239
|
+
}
|
|
240
|
+
}));
|
|
241
|
+
|
|
242
|
+
return { typeMapAll: typeMap };
|
|
243
|
+
};
|