@lcap/nasl 3.7.2-beta.4 → 3.7.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/out/common/BaseNode.js +1 -1
- package/out/concepts/App__.js +3 -0
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/BinaryExpression__.js +49 -2
- package/out/concepts/BinaryExpression__.js.map +1 -1
- package/out/concepts/BindAttribute__.js +7 -1
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BusinessComponent__.d.ts +1 -0
- package/out/concepts/BusinessComponent__.js +9 -0
- package/out/concepts/BusinessComponent__.js.map +1 -1
- package/out/concepts/CallConnector__.js +1 -1
- package/out/concepts/CallConnector__.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/Entity__.d.ts +1 -0
- package/out/concepts/Entity__.js +20 -0
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/EventDeclaration__.d.ts +1 -0
- package/out/concepts/EventDeclaration__.js +38 -0
- package/out/concepts/EventDeclaration__.js.map +1 -1
- package/out/concepts/LogicDeclaration__.d.ts +1 -0
- package/out/concepts/LogicDeclaration__.js +26 -0
- package/out/concepts/LogicDeclaration__.js.map +1 -1
- package/out/concepts/Logic__.js +2 -2
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/PropDeclaration__.d.ts +1 -0
- package/out/concepts/PropDeclaration__.js +14 -0
- package/out/concepts/PropDeclaration__.js.map +1 -1
- package/out/concepts/SlotDeclaration__.d.ts +1 -0
- package/out/concepts/SlotDeclaration__.js +14 -0
- package/out/concepts/SlotDeclaration__.js.map +1 -1
- package/out/concepts/Variable__.js +5 -1
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewComponentDeclaration__.d.ts +1 -0
- package/out/concepts/ViewComponentDeclaration__.js +42 -0
- package/out/concepts/ViewComponentDeclaration__.js.map +1 -1
- package/out/concepts/ViewElement__.js +2 -2
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/generator/genBundleFiles.js +3 -2
- 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 +4 -3
- package/out/generator/release-body/body.js.map +1 -1
- package/out/natural/genNaturalTS.d.ts +20 -4
- package/out/natural/genNaturalTS.js +2 -2
- package/out/natural/genNaturalTS.js.map +1 -1
- package/out/natural/getContext/getUILib.d.ts +3 -0
- package/out/natural/getContext/getUILib.js +90 -2
- package/out/natural/getContext/getUILib.js.map +1 -1
- package/out/natural/getContext/index.d.ts +11 -3
- package/out/natural/getContext/index.js +21 -27
- 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/transformTS2UI.d.ts +1 -1
- package/out/natural/transformTS2UI.js +148 -28
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.js +95 -22
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/server/getLogics.js +3 -6
- package/out/server/getLogics.js.map +1 -1
- package/out/server/naslServer.js +44 -0
- package/out/server/naslServer.js.map +1 -1
- package/out/templator/genSelectBlock.js +82 -59
- package/out/templator/genSelectBlock.js.map +1 -1
- package/out/utils/index.d.ts +17 -0
- package/out/utils/index.js +36 -1
- package/out/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/common/BaseNode.ts +1 -1
- package/src/concepts/App__.ts +3 -0
- package/src/concepts/BinaryExpression__.ts +46 -2
- package/src/concepts/BindAttribute__.ts +8 -3
- package/src/concepts/BusinessComponent__.ts +10 -0
- package/src/concepts/CallConnector__.ts +1 -1
- package/src/concepts/Connection__.ts +16 -0
- package/src/concepts/Entity__.ts +23 -0
- package/src/concepts/EventDeclaration__.ts +9 -1
- package/src/concepts/LogicDeclaration__.ts +23 -1
- package/src/concepts/Logic__.ts +2 -2
- package/src/concepts/PropDeclaration__.ts +14 -0
- package/src/concepts/SlotDeclaration__.ts +9 -1
- package/src/concepts/Variable__.ts +5 -1
- package/src/concepts/ViewComponentDeclaration__.ts +40 -1
- package/src/concepts/ViewElement__.ts +2 -2
- package/src/generator/genBundleFiles.ts +3 -2
- package/src/generator/genMetaData.ts +21 -26
- package/src/generator/release-body/body.ts +5 -3
- package/src/natural/genNaturalTS.ts +4 -4
- package/src/natural/getContext/getUILib.ts +139 -71
- package/src/natural/getContext/index.ts +29 -35
- package/src/natural/index.ts +1 -0
- package/src/natural/transformTS2UI.ts +151 -31
- package/src/natural/transformTSCode.ts +99 -25
- package/src/server/getLogics.ts +3 -6
- package/src/server/naslServer.ts +42 -0
- package/src/templator/genSelectBlock.ts +88 -61
- package/src/utils/index.ts +37 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { App, View, Logic, BaseNode, Frontend, Namespace, Module, TypeAnnotation, Structure } from '../../concepts';
|
|
2
2
|
import { shiftState, createCompilerState, TranslatorState, indent } from '../../translator';
|
|
3
|
-
import { getPreDeclaration, getUILib, handleMaterial } from './getUILib';
|
|
3
|
+
import { getPreDeclaration, getUILib, handleMaterial, getExtensionsMaterial } from './getUILib';
|
|
4
4
|
import { getNASLStdlibMap } from './naslStdlibMap';
|
|
5
5
|
|
|
6
6
|
export interface Snippet {
|
|
@@ -89,43 +89,37 @@ export function getNaslUtil() {
|
|
|
89
89
|
return { code, naslUtil };
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
export const getNaslUI = (material: { json: any
|
|
92
|
+
export const getNaslUI = (app: App, frontendType: 'pc' | 'h5', material: { basicMaterials: { json: any; tsDeclaration: string; }, extensionMaterials: { name: string; title: string; description: string; tsDescription: string; }[]; } | string, requiredIndexes?: string[]) => {
|
|
93
93
|
const hasModuleIndexList = requiredIndexes?.length > 0;
|
|
94
|
-
|
|
95
|
-
const
|
|
94
|
+
const uiLib = typeof material === 'string' ? getUILib(material as 'pc' | 'h5') : handleMaterial(material.basicMaterials);
|
|
95
|
+
const extensionMaterials = typeof material === 'string' ? getExtensionsMaterial(app, frontendType) : material.extensionMaterials || [];
|
|
96
|
+
uiLib.push(...extensionMaterials);
|
|
96
97
|
|
|
97
98
|
if (!hasModuleIndexList) {
|
|
98
99
|
const naslUI = uiLib;
|
|
99
100
|
const code = naslUI.map((item, index) => `[3-${index}] ${item.name} | ${item.title} | ${item.description}`).join('\n');
|
|
100
101
|
return { code, naslUI };
|
|
101
|
-
} else {
|
|
102
|
-
const preDeclaration = getPreDeclaration();
|
|
103
|
-
const naslUI = uiLib.filter(
|
|
104
|
-
(item, index) =>
|
|
105
|
-
requiredIndexes.includes(`3-${index}`) ||
|
|
106
|
-
requiredIndexes.includes(item.name) ||
|
|
107
|
-
item.name.endsWith('LinearLayout') ||
|
|
108
|
-
item.name.endsWith('Text') ||
|
|
109
|
-
item.name.endsWith('Link') ||
|
|
110
|
-
item.name.endsWith('Button')
|
|
111
|
-
);
|
|
112
|
-
const code = wrapTSBlock(
|
|
113
|
-
preDeclaration +
|
|
114
|
-
'\n' +
|
|
115
|
-
naslUI
|
|
116
|
-
.map(
|
|
117
|
-
(item) =>
|
|
118
|
-
`/**
|
|
119
|
-
* ${item.name}
|
|
120
|
-
* ${item.title}
|
|
121
|
-
* ${item.description}
|
|
122
|
-
*/
|
|
123
|
-
` + item.tsDeclaration
|
|
124
|
-
)
|
|
125
|
-
.join('\n')
|
|
126
|
-
);
|
|
127
|
-
return { code, naslUI };
|
|
128
102
|
}
|
|
103
|
+
|
|
104
|
+
const preDeclaration = getPreDeclaration();
|
|
105
|
+
const naslUI = uiLib.filter(
|
|
106
|
+
(item, index) =>
|
|
107
|
+
requiredIndexes.includes(`3-${index}`) ||
|
|
108
|
+
item.name.endsWith('LinearLayout') ||
|
|
109
|
+
item.name.endsWith('Text') ||
|
|
110
|
+
item.name.endsWith('Link') ||
|
|
111
|
+
item.name.endsWith('Button')
|
|
112
|
+
);
|
|
113
|
+
const code = wrapTSBlock(
|
|
114
|
+
`${preDeclaration}\n${naslUI.map(
|
|
115
|
+
(item) =>
|
|
116
|
+
`/**
|
|
117
|
+
* ${item.name}
|
|
118
|
+
* ${item.title}
|
|
119
|
+
* ${item.description}
|
|
120
|
+
*/
|
|
121
|
+
${item.tsDeclaration}`).join('\n')}`);
|
|
122
|
+
return { code, naslUI };
|
|
129
123
|
};
|
|
130
124
|
|
|
131
125
|
export const getNaslUIOld = () => {
|
|
@@ -211,7 +205,7 @@ export function getLogics(app: App, currentNode: BaseNode, requiredIndexes?: str
|
|
|
211
205
|
const needNamespace = requiredIndexes?.length >= 0;
|
|
212
206
|
const tempCode = `${logic?.toNaturalTS({ needNamespace, rename, declaration: true })}`;
|
|
213
207
|
const description = logic?.description || '';
|
|
214
|
-
code += `[${logicIndex}] ${description ? description
|
|
208
|
+
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
215
209
|
data.push({ description, code: tempCode });
|
|
216
210
|
});
|
|
217
211
|
return { code, appLogics: { namespace, data } };
|
|
@@ -252,7 +246,7 @@ export function getModuleInterfaces(app: App, state: TranslatorState, requiredIn
|
|
|
252
246
|
if (requiredIndexes?.includes(interfaceIndex)) {
|
|
253
247
|
code += getLogicStructures(interface_, 'interface', { description, codeStr: tempCode }, structureNamespace);
|
|
254
248
|
} else {
|
|
255
|
-
code += `[${interfaceIndex}] ${description ? description
|
|
249
|
+
code += `[${interfaceIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
256
250
|
}
|
|
257
251
|
});
|
|
258
252
|
logics = { namespace: logicNamespace, data: logicData };
|
|
@@ -300,7 +294,7 @@ export function getConnectors(app: App, state: TranslatorState, requiredIndexes?
|
|
|
300
294
|
if (requiredIndexes?.includes(logicIndex)) {
|
|
301
295
|
code += getLogicStructures(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
302
296
|
} else {
|
|
303
|
-
code += `[${logicIndex}] ${description ? description
|
|
297
|
+
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
304
298
|
}
|
|
305
299
|
});
|
|
306
300
|
});
|
|
@@ -318,7 +312,7 @@ export function getConnectors(app: App, state: TranslatorState, requiredIndexes?
|
|
|
318
312
|
if (requiredIndexes?.includes(logicIndex)) {
|
|
319
313
|
code += getLogicStructures(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
320
314
|
} else {
|
|
321
|
-
code += `[${logicIndex}] ${description ? description
|
|
315
|
+
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
322
316
|
}
|
|
323
317
|
});
|
|
324
318
|
}
|
package/src/natural/index.ts
CHANGED
|
@@ -18,6 +18,13 @@ function flatMemberExpression(node: babelTypes.Node): Array<babelTypes.Node> {
|
|
|
18
18
|
return [...flatMemberExpression(node.object), node.property];
|
|
19
19
|
return [node];
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
function flatMembers(node: naslTypes.MemberExpression): Array<naslTypes.MemberExpression> {
|
|
23
|
+
if (node.concept === 'MemberExpression')
|
|
24
|
+
return [...flatMembers(((node as any)?.object)), node];
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
function flatMatchPatternsExpression(node: any): Array<babelTypes.Node> {
|
|
22
29
|
if (node.concept === 'BinaryExpression') {
|
|
23
30
|
if (node.operator === '||') {
|
|
@@ -64,6 +71,13 @@ function transformTypeAnnotation(node: babelTypes.TSType): naslTypes.TypeAnnotat
|
|
|
64
71
|
typeNamespace: (node as any).typeNamespace,
|
|
65
72
|
});
|
|
66
73
|
}
|
|
74
|
+
|
|
75
|
+
if (['ValidateResult', 'ValidateEvent'].includes(typeName)) {
|
|
76
|
+
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
77
|
+
typeNamespace: 'nasl.ui'
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
67
81
|
if (typeName === 'Any' || typeName === 'any') {
|
|
68
82
|
return undefined;
|
|
69
83
|
}
|
|
@@ -218,17 +232,47 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
|
|
|
218
232
|
const assignmentLines: any = [];
|
|
219
233
|
node?.arguments?.[0]?.properties.forEach((arg: any, index: number) => {
|
|
220
234
|
properties.push(transformNode2Expression(arg.key));
|
|
221
|
-
|
|
222
|
-
expression
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
235
|
+
if (arg.value.type === 'MemberExpression') {
|
|
236
|
+
const expression = flatMemberExpression(arg.value);
|
|
237
|
+
const members = flatMembers(transformNode2Expression(arg.value) as any);
|
|
238
|
+
rights.push(new naslTypes.SelectMembers({
|
|
239
|
+
expression: transformNode2Expression(expression[0]),
|
|
240
|
+
members,
|
|
241
|
+
}));
|
|
242
|
+
if (arg?.value) {
|
|
243
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
244
|
+
leftIndex: [0, index],
|
|
245
|
+
rightIndex: [index, index],
|
|
246
|
+
}));
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
rights.push(new naslTypes.SelectMembers({
|
|
250
|
+
expression: transformNode2Expression(arg.value)
|
|
228
251
|
}));
|
|
252
|
+
if (arg?.value) {
|
|
253
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
254
|
+
leftIndex: [0, index],
|
|
255
|
+
rightIndex: [index],
|
|
256
|
+
}));
|
|
257
|
+
}
|
|
229
258
|
}
|
|
230
259
|
});
|
|
231
|
-
const
|
|
260
|
+
const parameters = node?.typeParameters?.params?.[0] || {};
|
|
261
|
+
if (parameters && parameters?.type === 'TSTypeReference' && parameters?.typeName?.type === 'TSQualifiedName') {
|
|
262
|
+
const { left, right } = parameters?.typeName || {};
|
|
263
|
+
const typeNamespace = generate(left as any)?.code;
|
|
264
|
+
const typeName = right?.name;
|
|
265
|
+
return new naslTypes.NewComposite({
|
|
266
|
+
typeAnnotation: naslTypes.TypeAnnotation.createReference(typeName, {
|
|
267
|
+
typeNamespace,
|
|
268
|
+
typeName
|
|
269
|
+
}),
|
|
270
|
+
properties,
|
|
271
|
+
rights,
|
|
272
|
+
assignmentLines
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
const typeName = parameters?.typeName?.name;
|
|
232
276
|
return new naslTypes.NewComposite({
|
|
233
277
|
typeAnnotation: naslTypes.TypeAnnotation.createReference(typeName, {
|
|
234
278
|
typeNamespace: 'app.dataSources.defaultDS.entities',
|
|
@@ -245,14 +289,29 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
|
|
|
245
289
|
const assignmentLines: any = [];
|
|
246
290
|
node?.arguments?.[0]?.properties.forEach((arg: any, index: number) => {
|
|
247
291
|
properties.push(transformNode2Expression(arg.key));
|
|
248
|
-
|
|
249
|
-
expression
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
292
|
+
if (arg.value.type === 'MemberExpression') {
|
|
293
|
+
const expression = flatMemberExpression(arg.value);
|
|
294
|
+
const members = flatMembers(transformNode2Expression(arg.value) as any);
|
|
295
|
+
rights.push(new naslTypes.SelectMembers({
|
|
296
|
+
expression: transformNode2Expression(expression[0]),
|
|
297
|
+
members,
|
|
298
|
+
}));
|
|
299
|
+
if (arg?.value) {
|
|
300
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
301
|
+
leftIndex: [0, index],
|
|
302
|
+
rightIndex: [index, index],
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
} else {
|
|
306
|
+
rights.push(new naslTypes.SelectMembers({
|
|
307
|
+
expression: transformNode2Expression(arg.value)
|
|
255
308
|
}));
|
|
309
|
+
if (arg?.value) {
|
|
310
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
311
|
+
leftIndex: [0, index],
|
|
312
|
+
rightIndex: [index],
|
|
313
|
+
}));
|
|
314
|
+
}
|
|
256
315
|
}
|
|
257
316
|
});
|
|
258
317
|
const parameters = node?.typeParameters?.params?.[0] || {};
|
|
@@ -288,14 +347,29 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
|
|
|
288
347
|
const assignmentLines: any = [];
|
|
289
348
|
node?.arguments?.[0]?.properties?.forEach((arg: any, index: number) => {
|
|
290
349
|
properties.push(transformNode2Expression(arg.key));
|
|
291
|
-
|
|
292
|
-
expression
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
350
|
+
if (arg.value.type === 'MemberExpression') {
|
|
351
|
+
const expression = flatMemberExpression(arg.value);
|
|
352
|
+
const members = flatMembers(transformNode2Expression(arg.value) as any);
|
|
353
|
+
rights.push(new naslTypes.SelectMembers({
|
|
354
|
+
expression: transformNode2Expression(expression[0]),
|
|
355
|
+
members,
|
|
356
|
+
}));
|
|
357
|
+
if (arg?.value) {
|
|
358
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
359
|
+
leftIndex: [0, index],
|
|
360
|
+
rightIndex: [index, index],
|
|
361
|
+
}));
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
rights.push(new naslTypes.SelectMembers({
|
|
365
|
+
expression: transformNode2Expression(arg.value)
|
|
298
366
|
}));
|
|
367
|
+
if (arg?.value) {
|
|
368
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
369
|
+
leftIndex: [0, index],
|
|
370
|
+
rightIndex: [index],
|
|
371
|
+
}));
|
|
372
|
+
}
|
|
299
373
|
}
|
|
300
374
|
structureProperties.push(new naslTypes.StructureProperty({
|
|
301
375
|
name: arg?.key?.name,
|
|
@@ -695,7 +769,7 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
695
769
|
const callee = flatMemberExpression(node);
|
|
696
770
|
const calleeName = generate(node)?.code;
|
|
697
771
|
if (calleeName?.includes('app.enums')) {
|
|
698
|
-
const name = (callee?.[3] as babelTypes.StringLiteral)?.value || (callee?.[3] as babelTypes.Identifier)?.name || (callee?.[3] as babelTypes.NumericLiteral)?.value
|
|
772
|
+
const name = (callee?.[3] as babelTypes.StringLiteral)?.value || (callee?.[3] as babelTypes.Identifier)?.name || (callee?.[3] as babelTypes.NumericLiteral)?.value;
|
|
699
773
|
return new naslTypes.MemberExpression({
|
|
700
774
|
object: new naslTypes.Identifier({
|
|
701
775
|
namespace: 'app.enums',
|
|
@@ -888,7 +962,7 @@ function transformNode2Logic(node: babelTypes.FunctionDeclaration, name?: string
|
|
|
888
962
|
const param = transformParam(item);
|
|
889
963
|
if (param && param.name !== 'event' && !curLogic.params.find((_: any) => _.name === param.name)) curLogic.addParam(param);
|
|
890
964
|
});
|
|
891
|
-
statements.forEach((item
|
|
965
|
+
statements.forEach((item) => {
|
|
892
966
|
if (item.type === 'ReturnStatement' && item?.argument) {
|
|
893
967
|
if (!curLogic.returns.length) {
|
|
894
968
|
curLogic.returns.push(new naslTypes.Return({
|
|
@@ -901,7 +975,7 @@ function transformNode2Logic(node: babelTypes.FunctionDeclaration, name?: string
|
|
|
901
975
|
}),
|
|
902
976
|
right: transformNode2Expression(item.argument, 'logic')
|
|
903
977
|
});
|
|
904
|
-
curLogic.insertItemInBodyAt(logicItem,
|
|
978
|
+
curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
|
|
905
979
|
} else {
|
|
906
980
|
let logicItem = transformNode2Expression(item, 'logic');
|
|
907
981
|
if (logicItem) {
|
|
@@ -911,8 +985,10 @@ function transformNode2Logic(node: babelTypes.FunctionDeclaration, name?: string
|
|
|
911
985
|
left: new naslTypes.Identifier({ name: logicItem?.name }),
|
|
912
986
|
right: (logicItem as any).defaultValue?.expression || '',
|
|
913
987
|
});
|
|
988
|
+
if (logicItem.right) curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
|
|
989
|
+
} else {
|
|
990
|
+
curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
|
|
914
991
|
}
|
|
915
|
-
curLogic.insertItemInBodyAt(logicItem, index + 1);
|
|
916
992
|
}
|
|
917
993
|
}
|
|
918
994
|
});
|
|
@@ -934,9 +1010,17 @@ function transformNode2Attribute(node: any): any {
|
|
|
934
1010
|
item = {
|
|
935
1011
|
name: node.key.name,
|
|
936
1012
|
type: 'string',
|
|
937
|
-
value: generate(node.value.body
|
|
1013
|
+
value: generate(node.value.body).code,
|
|
938
1014
|
};
|
|
939
|
-
} else {
|
|
1015
|
+
} else if (['CallExpression'].includes(node.value.type) && node.value?.callee?.name === 'sync') {
|
|
1016
|
+
item = {
|
|
1017
|
+
name: node.key.name,
|
|
1018
|
+
type: 'dynamic',
|
|
1019
|
+
sync: true,
|
|
1020
|
+
expression: transformNode2Expression(node.value.arguments[0]),
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
else {
|
|
940
1024
|
// ['TemplateLiteral', 'BooleanLiteral', 'NullLiteral', 'CallExpression']
|
|
941
1025
|
item = {
|
|
942
1026
|
name: node.key.name,
|
|
@@ -1154,7 +1238,7 @@ function transformNode2View(node: babelTypes.FunctionDeclaration, root?: babelTy
|
|
|
1154
1238
|
const action = (item.argument as any)?.callee?.name;
|
|
1155
1239
|
const selectedNodeName = (item.argument as any).arguments?.[0]?.property?.name;
|
|
1156
1240
|
const newNodeBackup = cloneDeep(viewItem);
|
|
1157
|
-
(viewItem as any).aiParams = { selectedNodeName, action, concept: 'ViewElement', object: newNodeBackup};
|
|
1241
|
+
(viewItem as any).aiParams = { selectedNodeName, action, concept: 'ViewElement', object: newNodeBackup };
|
|
1158
1242
|
}
|
|
1159
1243
|
if (item.type === 'ReturnStatement' && item?.argument?.type === 'ArrayExpression') {
|
|
1160
1244
|
viewItem?.forEach((element: any) => {
|
|
@@ -1173,7 +1257,7 @@ function transformNode2View(node: babelTypes.FunctionDeclaration, root?: babelTy
|
|
|
1173
1257
|
}
|
|
1174
1258
|
});
|
|
1175
1259
|
// console.log("lemon ~ 转换出的 view:", view);
|
|
1176
|
-
return { view, json };
|
|
1260
|
+
return { view: view.toJSON(), json };
|
|
1177
1261
|
}
|
|
1178
1262
|
|
|
1179
1263
|
/**
|
|
@@ -1197,12 +1281,48 @@ const transformTS2View = (tsCode: string): any => {
|
|
|
1197
1281
|
return transformNode2View(func, root);
|
|
1198
1282
|
};
|
|
1199
1283
|
|
|
1200
|
-
|
|
1284
|
+
const handleNodeName = (curView: any, object: any) => {
|
|
1285
|
+
const list = [];
|
|
1286
|
+
if (object.concept === 'ViewElement') {
|
|
1287
|
+
const oldName = object.name;
|
|
1288
|
+
const newName = curView?.getViewElementUniqueNameOld(oldName);
|
|
1289
|
+
if (oldName !== newName) {
|
|
1290
|
+
object.name = `${newName}_${genHash(new Date().getTime() + newName)}`;
|
|
1291
|
+
list.push({ oldName, newName: object.name });
|
|
1292
|
+
}
|
|
1293
|
+
if (object?.children?.length) {
|
|
1294
|
+
object.children.forEach((child: any) => {
|
|
1295
|
+
handleNodeName(curView, child);
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
return { object, list };
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1302
|
+
export function tryTransformTS2UI(tsCode: string, curView?: any): any {
|
|
1201
1303
|
if (tsCode.includes('```')) {
|
|
1202
1304
|
const cap = tsCode.match(/```.*\n([\s\S]+?)```/);
|
|
1203
1305
|
if (cap)
|
|
1204
1306
|
tsCode = cap[1].trim();
|
|
1205
1307
|
}
|
|
1308
|
+
|
|
1309
|
+
if (!curView) return transformTS2View(tsCode);
|
|
1310
|
+
const newView = new naslTypes.View(curView);
|
|
1311
|
+
const { json } = transformTS2View(tsCode);
|
|
1312
|
+
const replaceNameList = [] as any;
|
|
1313
|
+
const selectedNodeNames = [] as any;
|
|
1314
|
+
json.forEach((item: any) => {
|
|
1315
|
+
if (item.concept === 'ViewElement' && item.action !== 'remove') {
|
|
1316
|
+
selectedNodeNames.push(item.selectedNodeName.replace('$refs.', ''));
|
|
1317
|
+
const { list } = handleNodeName(newView, item.object.toJSON());
|
|
1318
|
+
replaceNameList.push(...list);
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
replaceNameList.forEach((item: any) => {
|
|
1322
|
+
if (!selectedNodeNames.includes(item.oldName)) {
|
|
1323
|
+
tsCode = tsCode.replace(new RegExp(item.oldName, 'g'), item.newName);
|
|
1324
|
+
}
|
|
1325
|
+
});
|
|
1206
1326
|
return transformTS2View(tsCode);
|
|
1207
1327
|
}
|
|
1208
1328
|
|
|
@@ -29,6 +29,13 @@ function flatMemberExpression(node: babelTypes.Node): Array<babelTypes.Node> {
|
|
|
29
29
|
return [...flatMemberExpression(node.object), node.property];
|
|
30
30
|
return [node];
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
function flatMembers(node: naslTypes.MemberExpression): Array<naslTypes.MemberExpression> {
|
|
34
|
+
if (node.concept === 'MemberExpression')
|
|
35
|
+
return [...flatMembers(((node as any)?.object)), node];
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
function flatMatchPatternsExpression(node: any): Array<babelTypes.Node> {
|
|
33
40
|
if (node.concept === 'BinaryExpression') {
|
|
34
41
|
if (node.operator === '||') {
|
|
@@ -79,6 +86,13 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
79
86
|
typeNamespace: (node as any).typeNamespace,
|
|
80
87
|
});
|
|
81
88
|
}
|
|
89
|
+
|
|
90
|
+
if (['ValidateResult', 'ValidateEvent'].includes(typeName)) {
|
|
91
|
+
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
92
|
+
typeNamespace: 'nasl.ui'
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
82
96
|
if (typeName === 'Any' || typeName === 'any') {
|
|
83
97
|
return undefined;
|
|
84
98
|
}
|
|
@@ -204,17 +218,47 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
204
218
|
const assignmentLines: any = [];
|
|
205
219
|
node?.arguments?.[0]?.properties.forEach((arg: any, index: number) => {
|
|
206
220
|
properties.push(transformLogicNode(arg.key));
|
|
207
|
-
|
|
208
|
-
expression
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
rightIndex: [index],
|
|
221
|
+
if (arg.value.type === 'MemberExpression') {
|
|
222
|
+
const expression = flatMemberExpression(arg.value);
|
|
223
|
+
const members = flatMembers(transformLogicNode(arg.value) as any);
|
|
224
|
+
rights.push(new naslTypes.SelectMembers({
|
|
225
|
+
expression: transformLogicNode(expression[0]),
|
|
226
|
+
members,
|
|
214
227
|
}));
|
|
228
|
+
if (arg?.value) {
|
|
229
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
230
|
+
leftIndex: [0, index],
|
|
231
|
+
rightIndex: [index, index],
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
rights.push(new naslTypes.SelectMembers({
|
|
236
|
+
expression: transformLogicNode(arg.value)
|
|
237
|
+
}));
|
|
238
|
+
if (arg?.value) {
|
|
239
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
240
|
+
leftIndex: [0, index],
|
|
241
|
+
rightIndex: [index],
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
215
244
|
}
|
|
216
245
|
});
|
|
217
|
-
const
|
|
246
|
+
const parameters = node?.typeParameters?.params?.[0] || {};
|
|
247
|
+
if (parameters && parameters?.type === 'TSTypeReference' && parameters?.typeName?.type === 'TSQualifiedName') {
|
|
248
|
+
const { left, right } = parameters?.typeName || {};
|
|
249
|
+
const typeNamespace = generate(left as any)?.code;
|
|
250
|
+
const typeName = right?.name;
|
|
251
|
+
return new naslTypes.NewComposite({
|
|
252
|
+
typeAnnotation: naslTypes.TypeAnnotation.createReference(typeName, {
|
|
253
|
+
typeNamespace,
|
|
254
|
+
typeName
|
|
255
|
+
}),
|
|
256
|
+
properties,
|
|
257
|
+
rights,
|
|
258
|
+
assignmentLines
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
const typeName = parameters?.typeName?.name;
|
|
218
262
|
return new naslTypes.NewComposite({
|
|
219
263
|
typeAnnotation: naslTypes.TypeAnnotation.createReference(typeName, {
|
|
220
264
|
typeNamespace: 'app.dataSources.defaultDS.entities',
|
|
@@ -231,14 +275,29 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
231
275
|
const assignmentLines: any = [];
|
|
232
276
|
node?.arguments?.[0]?.properties.forEach((arg: any, index: number) => {
|
|
233
277
|
properties.push(transformLogicNode(arg.key));
|
|
234
|
-
|
|
235
|
-
expression
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
278
|
+
if (arg.value.type === 'MemberExpression') {
|
|
279
|
+
const expression = flatMemberExpression(arg.value);
|
|
280
|
+
const members = flatMembers(transformLogicNode(arg.value) as any);
|
|
281
|
+
rights.push(new naslTypes.SelectMembers({
|
|
282
|
+
expression: transformLogicNode(expression[0]),
|
|
283
|
+
members,
|
|
284
|
+
}));
|
|
285
|
+
if (arg?.value) {
|
|
286
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
287
|
+
leftIndex: [0, index],
|
|
288
|
+
rightIndex: [index, index],
|
|
289
|
+
}));
|
|
290
|
+
}
|
|
291
|
+
} else {
|
|
292
|
+
rights.push(new naslTypes.SelectMembers({
|
|
293
|
+
expression: transformLogicNode(arg.value)
|
|
241
294
|
}));
|
|
295
|
+
if (arg?.value) {
|
|
296
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
297
|
+
leftIndex: [0, index],
|
|
298
|
+
rightIndex: [index],
|
|
299
|
+
}));
|
|
300
|
+
}
|
|
242
301
|
}
|
|
243
302
|
});
|
|
244
303
|
const parameters = node?.typeParameters?.params?.[0] || {};
|
|
@@ -274,14 +333,29 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
274
333
|
const assignmentLines: any = [];
|
|
275
334
|
node?.arguments?.[0]?.properties?.forEach((arg: any, index: number) => {
|
|
276
335
|
properties.push(transformLogicNode(arg.key));
|
|
277
|
-
|
|
278
|
-
expression
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
rightIndex: [index],
|
|
336
|
+
if (arg.value.type === 'MemberExpression') {
|
|
337
|
+
const expression = flatMemberExpression(arg.value);
|
|
338
|
+
const members = flatMembers(transformLogicNode(arg.value) as any);
|
|
339
|
+
rights.push(new naslTypes.SelectMembers({
|
|
340
|
+
expression: transformLogicNode(expression[0]),
|
|
341
|
+
members,
|
|
284
342
|
}));
|
|
343
|
+
if (arg?.value) {
|
|
344
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
345
|
+
leftIndex: [0, index],
|
|
346
|
+
rightIndex: [index, index],
|
|
347
|
+
}));
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
rights.push(new naslTypes.SelectMembers({
|
|
351
|
+
expression: transformLogicNode(arg.value)
|
|
352
|
+
}));
|
|
353
|
+
if (arg?.value) {
|
|
354
|
+
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
355
|
+
leftIndex: [0, index],
|
|
356
|
+
rightIndex: [index],
|
|
357
|
+
}));
|
|
358
|
+
}
|
|
285
359
|
}
|
|
286
360
|
structureProperties.push(new naslTypes.StructureProperty({
|
|
287
361
|
name: arg?.key?.name,
|
|
@@ -367,7 +441,7 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
367
441
|
// const _typeAnnotation = node?.typeParameters?.params?.length > 0 ? naslTypes.TypeAnnotation.createGeneric('List', {
|
|
368
442
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transformTypeAnnotation({ ...curType })),
|
|
369
443
|
// }) : null;
|
|
370
|
-
let code = generate(node.arguments[0] as any).code.trim().slice(1, -1)
|
|
444
|
+
let code = generate(node.arguments[0] as any).code.trim().slice(1, -1);
|
|
371
445
|
code = code?.replace(/app\.enums\.(\w+)\[(\d+)\]/g, "app.enums.$1.$2").replace(/app\.enums\.(\w+)\['(\w+)'\]/g, "app.enums.$1.$2");
|
|
372
446
|
return new naslTypes.OqlQueryComponent({
|
|
373
447
|
dataSource: 'app.dataSources.defaultDS',
|
|
@@ -426,7 +500,7 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
426
500
|
let _callee = (callee[0] as any).callee;
|
|
427
501
|
while (_callee.type === 'CallExpression')
|
|
428
502
|
_callee = _callee.callee;
|
|
429
|
-
curCalleeName = _callee.property.name
|
|
503
|
+
curCalleeName = _callee.property.name;
|
|
430
504
|
}
|
|
431
505
|
const argument = callee.length === 3 ? node.arguments : (callee[0] as any).arguments as any;
|
|
432
506
|
|
|
@@ -753,7 +827,7 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
753
827
|
const callee = flatMemberExpression(node);
|
|
754
828
|
const calleeName = generate(node)?.code;
|
|
755
829
|
if (calleeName?.includes('app.enums')) {
|
|
756
|
-
const name = (callee?.[3] as babelTypes.StringLiteral)?.value || (callee?.[3] as babelTypes.Identifier)?.name || (callee?.[3] as babelTypes.NumericLiteral)?.value
|
|
830
|
+
const name = (callee?.[3] as babelTypes.StringLiteral)?.value || (callee?.[3] as babelTypes.Identifier)?.name || (callee?.[3] as babelTypes.NumericLiteral)?.value;
|
|
757
831
|
return new naslTypes.MemberExpression({
|
|
758
832
|
object: new naslTypes.Identifier({
|
|
759
833
|
namespace: 'app.enums',
|
package/src/server/getLogics.ts
CHANGED
|
@@ -188,9 +188,9 @@ export function getLogicsSync(node: CallLogic | BindEvent | Identifier | Logic,
|
|
|
188
188
|
// 连接器 相关迁移到了 conenctorDependencies 下,因此这边需要扩展
|
|
189
189
|
const dependencies = [
|
|
190
190
|
...app.dependencies,
|
|
191
|
-
...(app.connectorDependencies || [])
|
|
191
|
+
// ...(app.connectorDependencies || [])
|
|
192
192
|
]; //.filter((d) => d.enable);
|
|
193
|
-
const extensions = [...app.dependencies
|
|
193
|
+
const extensions = [...app.dependencies]
|
|
194
194
|
.map((dep) => moduleToLogicNamesapce(dep, app.overriddenLogics))
|
|
195
195
|
.filter((item) => item.logics && item.logics.length);
|
|
196
196
|
const dependEntityNs: Namespace[] = [];
|
|
@@ -509,12 +509,9 @@ export function getLogicsSync(node: CallLogic | BindEvent | Identifier | Logic,
|
|
|
509
509
|
return result;
|
|
510
510
|
}
|
|
511
511
|
if (node?.concept === 'Identifier') {
|
|
512
|
-
// 之前 连接器 Connector 相关也存在与 app.dependencies 下,
|
|
513
|
-
// 现在迁移到 app.connectorDependencies 下,
|
|
514
|
-
// 为保证上下游逻辑与之前保持一致,这边做相应的扩展
|
|
515
512
|
const extensions = [
|
|
516
513
|
...app.dependencies,
|
|
517
|
-
...(app.connectorDependencies || [])
|
|
514
|
+
// ...(app.connectorDependencies || [])
|
|
518
515
|
]
|
|
519
516
|
.map((dep) => moduleToLogicNamesapce(dep, app.overriddenLogics))
|
|
520
517
|
.filter((item) => item.logics && item.logics.length);
|
package/src/server/naslServer.ts
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
EnumItem,
|
|
37
37
|
Param,
|
|
38
38
|
Process,
|
|
39
|
+
ProcessV2,
|
|
39
40
|
Interface,
|
|
40
41
|
Argument,
|
|
41
42
|
ViewElement,
|
|
@@ -2407,6 +2408,47 @@ class NaslServer {
|
|
|
2407
2408
|
yield* utils.wrapIteratorToGenerator(fileNode.sourceMap.entries(), ([node, value]) => {
|
|
2408
2409
|
this.checkNodeError(node, diagnostics);
|
|
2409
2410
|
});
|
|
2411
|
+
} else if (fileNode instanceof ProcessV2) {
|
|
2412
|
+
yield* utils.wrapIteratorToGenerator(fileNode.sourceMap.entries(), function* wrapIterator([node, value]) {
|
|
2413
|
+
if (node instanceof Return || node instanceof Variable) {
|
|
2414
|
+
const nodeTypeName = node.concept === 'Return' ? '输出参数' : '局部变量';
|
|
2415
|
+
if (!node.typeAnnotation && !node.__TypeAnnotation) {
|
|
2416
|
+
let used = false;
|
|
2417
|
+
fileNode?.sourceMap.forEach((valueIn, nodeIn) => {
|
|
2418
|
+
if (!used && nodeIn && (nodeIn instanceof BatchAssignment || (nodeIn instanceof Assignment && nodeIn.left?.name))) {
|
|
2419
|
+
let jsCode = '';
|
|
2420
|
+
try {
|
|
2421
|
+
jsCode = nodeIn.toJS();
|
|
2422
|
+
} catch (err) {
|
|
2423
|
+
self.logger.error(err);
|
|
2424
|
+
}
|
|
2425
|
+
if (jsCode.startsWith(`${node.name} = `)) {
|
|
2426
|
+
used = true;
|
|
2427
|
+
if (!nodeIn.tsErrorDetail) {
|
|
2428
|
+
const diagnostic = {
|
|
2429
|
+
node: nodeIn,
|
|
2430
|
+
severity: 'error',
|
|
2431
|
+
message: `${nodeIn.label || ''}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
|
|
2432
|
+
};
|
|
2433
|
+
nodeIn.tsErrorDetail = diagnostic;
|
|
2434
|
+
diagnostics.push(diagnostic);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
});
|
|
2439
|
+
const msg = used ? '必须赋值有返回值的内容。' : '未设置类型或未赋值。直接赋值系统可以自动推断类型。';
|
|
2440
|
+
const diagnostic = {
|
|
2441
|
+
node,
|
|
2442
|
+
severity: 'error',
|
|
2443
|
+
message: `${nodeTypeName} ${node.name} ${msg}`,
|
|
2444
|
+
};
|
|
2445
|
+
node.__aStructureError = diagnostic;
|
|
2446
|
+
diagnostics.push(diagnostic);
|
|
2447
|
+
} else {
|
|
2448
|
+
node.__aStructureError = null;
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
});
|
|
2410
2452
|
} else if (fileNode instanceof Connection) {
|
|
2411
2453
|
const connectorPropertyNames = NaslServer.getPropertyNames(fileNode);
|
|
2412
2454
|
const connectionPropertyNames = NaslServer.getPropertyNames(fileNode?.connector);
|