@lcap/nasl 4.3.0-creator.4 → 4.3.0-creator.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/generator/genSimpleBundleFile.js +1 -1
- package/out/generator/genSimpleBundleFile.js.map +1 -1
- package/out/natural/parseNaturalTS.d.ts +7 -0
- package/out/natural/parseNaturalTS.d.ts.map +1 -1
- package/out/natural/parseNaturalTS.js +92 -98
- package/out/natural/parseNaturalTS.js.map +1 -1
- package/out/natural/parseNaturalTSXView.d.ts +6 -19
- package/out/natural/parseNaturalTSXView.d.ts.map +1 -1
- package/out/natural/parseNaturalTSXView.js +128 -59
- package/out/natural/parseNaturalTSXView.js.map +1 -1
- package/out/natural/transformTS2UI.d.ts.map +1 -1
- package/out/natural/transformTS2UI.js +4 -4
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.d.ts.map +1 -1
- package/out/natural/transformTSCode.js +8 -1
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/natural/transforms/transform2Entity.d.ts +2 -4
- package/out/natural/transforms/transform2Entity.d.ts.map +1 -1
- package/out/natural/transforms/transform2Entity.js +5 -5
- package/out/natural/transforms/transform2Entity.js.map +1 -1
- package/out/natural/transforms/transform2Enum.d.ts +2 -4
- package/out/natural/transforms/transform2Enum.d.ts.map +1 -1
- package/out/natural/transforms/transform2Enum.js +5 -5
- package/out/natural/transforms/transform2Enum.js.map +1 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts +2 -4
- package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts.map +1 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.js +4 -4
- package/out/natural/transforms/transform2GlobalLogicDeclaration.js.map +1 -1
- package/out/natural/transforms/transform2Logic.d.ts +4 -13
- package/out/natural/transforms/transform2Logic.d.ts.map +1 -1
- package/out/natural/transforms/transform2Logic.js +3 -2
- package/out/natural/transforms/transform2Logic.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.d.ts +3 -3
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +187 -114
- package/out/natural/transforms/transform2LogicItem.js.map +1 -1
- package/out/natural/transforms/transform2MetadataType.d.ts +2 -4
- package/out/natural/transforms/transform2MetadataType.d.ts.map +1 -1
- package/out/natural/transforms/transform2MetadataType.js +3 -3
- package/out/natural/transforms/transform2MetadataType.js.map +1 -1
- package/out/natural/transforms/transform2Structure.d.ts +2 -4
- package/out/natural/transforms/transform2Structure.d.ts.map +1 -1
- package/out/natural/transforms/transform2Structure.js +5 -5
- package/out/natural/transforms/transform2Structure.js.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.d.ts +2 -4
- package/out/natural/transforms/transform2TypeAnnotation.d.ts.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.js +10 -10
- package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -1
- package/out/natural/transforms/transform2ValidationRule.d.ts +2 -4
- package/out/natural/transforms/transform2ValidationRule.d.ts.map +1 -1
- package/out/natural/transforms/transform2ValidationRule.js +3 -3
- package/out/natural/transforms/transform2ValidationRule.js.map +1 -1
- package/out/natural/transforms/transform2Variable.d.ts +3 -7
- package/out/natural/transforms/transform2Variable.d.ts.map +1 -1
- package/out/natural/transforms/transform2Variable.js +10 -10
- package/out/natural/transforms/transform2Variable.js.map +1 -1
- package/out/natural/transforms/transformThemeAndStyle.d.ts +3 -7
- package/out/natural/transforms/transformThemeAndStyle.d.ts.map +1 -1
- package/out/natural/transforms/transformThemeAndStyle.js +7 -7
- package/out/natural/transforms/transformThemeAndStyle.js.map +1 -1
- package/out/natural/transforms/utils.d.ts +99 -7
- package/out/natural/transforms/utils.d.ts.map +1 -1
- package/out/natural/transforms/utils.js +336 -14
- package/out/natural/transforms/utils.js.map +1 -1
- package/out/server/naslServer.d.ts +0 -1
- package/out/server/naslServer.d.ts.map +1 -1
- package/out/server/naslServer.js +19 -8
- package/out/server/naslServer.js.map +1 -1
- package/out/service/initial/form-designer.d.ts +1 -1
- package/out/service/initial/form-designer.d.ts.map +1 -1
- package/out/service/initial/form-designer.js +2 -2
- package/out/service/initial/form-designer.js.map +1 -1
- package/out/service/initial/processV2.d.ts +1 -1
- package/out/service/initial/processV2.d.ts.map +1 -1
- package/out/service/initial/processV2.js +2 -2
- package/out/service/initial/processV2.js.map +1 -1
- package/out/service/initial/types.d.ts +1 -1
- package/out/service/initial/types.d.ts.map +1 -1
- package/package.json +11 -11
|
@@ -24,7 +24,7 @@ class TransformManager {
|
|
|
24
24
|
apply(node, options) {
|
|
25
25
|
if (node.type === 'CallExpression') {
|
|
26
26
|
if (node.callee.type === 'CallExpression')
|
|
27
|
-
return (0, utils_1.throwError)(options
|
|
27
|
+
return (0, utils_1.throwError)(options, '不支持连续调用!', node.callee);
|
|
28
28
|
const callee = flatMemberExpression(node.callee);
|
|
29
29
|
if (callee[0]
|
|
30
30
|
&& callee[0].type === 'CallExpression'
|
|
@@ -37,7 +37,7 @@ class TransformManager {
|
|
|
37
37
|
else {
|
|
38
38
|
for (const calleeItem of callee) {
|
|
39
39
|
if (calleeItem.type !== 'Identifier' && !(calleeItem.type === 'FunctionExpression' && calleeItem.id?.name === 'match')) {
|
|
40
|
-
return (0, utils_1.throwError)(options
|
|
40
|
+
return (0, utils_1.throwError)(options, '不支持连续调用!', node.callee);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -47,7 +47,7 @@ class TransformManager {
|
|
|
47
47
|
return transform(node, calleeName, callee, options);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
return (0, utils_1.throwError)(options
|
|
50
|
+
return (0, utils_1.throwError)(options, `不支持的节点类型 ${callee.map((item) => item.name).join('.')}`, node.type, node);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
53
|
for (const [type, transform] of this.transforms) {
|
|
@@ -55,7 +55,7 @@ class TransformManager {
|
|
|
55
55
|
return transform(node, options);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
return (0, utils_1.throwError)(options
|
|
58
|
+
return (0, utils_1.throwError)(options, '不支持的节点类型', node.type, node);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -126,7 +126,7 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
126
126
|
}
|
|
127
127
|
function assertAssignmentRightIsNotAnonymousFunction(expression, options) {
|
|
128
128
|
if (expression?.concept === 'AnonymousFunction')
|
|
129
|
-
return (0, utils_1.throwError)(options
|
|
129
|
+
return (0, utils_1.throwError)(options, 'Anonymous function is not allowed in assignment');
|
|
130
130
|
return expression;
|
|
131
131
|
}
|
|
132
132
|
function fixExpression(arg, options, supportSubLogic = false) {
|
|
@@ -284,7 +284,7 @@ function transform2Param(node, options) {
|
|
|
284
284
|
name,
|
|
285
285
|
typeAnnotation,
|
|
286
286
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
287
|
-
expression: transform2LogicItem(defaultValueExpression, {
|
|
287
|
+
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
288
288
|
}),
|
|
289
289
|
});
|
|
290
290
|
}
|
|
@@ -298,7 +298,7 @@ function transform2Param(node, options) {
|
|
|
298
298
|
name,
|
|
299
299
|
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
300
300
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
301
|
-
expression: transform2LogicItem(defaultValueExpression, {
|
|
301
|
+
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
302
302
|
}),
|
|
303
303
|
});
|
|
304
304
|
}
|
|
@@ -313,7 +313,7 @@ function transform2Param(node, options) {
|
|
|
313
313
|
required: !node.optional,
|
|
314
314
|
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
315
315
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
316
|
-
expression: transform2LogicItem(defaultValueExpression, {
|
|
316
|
+
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
317
317
|
}),
|
|
318
318
|
});
|
|
319
319
|
}
|
|
@@ -336,12 +336,12 @@ function transform2Param(node, options) {
|
|
|
336
336
|
name,
|
|
337
337
|
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
338
338
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
339
|
-
expression: transform2LogicItem(defaultValueExpression, {
|
|
339
|
+
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
340
340
|
}),
|
|
341
341
|
});
|
|
342
342
|
}
|
|
343
343
|
else {
|
|
344
|
-
return (0, utils_1.throwError)(options
|
|
344
|
+
return (0, utils_1.throwError)(options, '在输入参数中不支持节点类型', node);
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
exports.transform2Param = transform2Param;
|
|
@@ -362,7 +362,7 @@ function transformCallExpressionToBinaryExpression(node, calleeName, callee, opt
|
|
|
362
362
|
};
|
|
363
363
|
const limitMap = ['STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN', 'IS_NULL'];
|
|
364
364
|
if (limitMap.includes(calleeName) && options.transformType === 'logic' && !options.inCallQueryComponentField) {
|
|
365
|
-
return (0, utils_1.throwError)(options
|
|
365
|
+
return (0, utils_1.throwError)(options, `${calleeName} 仅支持在数据查询中使用`, node);
|
|
366
366
|
}
|
|
367
367
|
if (calleeName === 'IS_NULL') {
|
|
368
368
|
return new utils_1.naslTypes.UnaryExpression({
|
|
@@ -449,7 +449,7 @@ function transform2BinaryExpression(node, options) {
|
|
|
449
449
|
right: transformNodeFunction(node.right, options),
|
|
450
450
|
});
|
|
451
451
|
}
|
|
452
|
-
return (0, utils_1.throwError)(options
|
|
452
|
+
return (0, utils_1.throwError)(options, '在二元表达式中不支持节点类型', node.type, node);
|
|
453
453
|
}
|
|
454
454
|
exports.transform2BinaryExpression = transform2BinaryExpression;
|
|
455
455
|
function transformDefaultExpression(node, options) {
|
|
@@ -462,7 +462,7 @@ function transformConditionalExpression(node, options) {
|
|
|
462
462
|
const expr = (0, utils_1.generate)(node.test)?.code;
|
|
463
463
|
const then_expr = (0, utils_1.generate)(node.consequent)?.code;
|
|
464
464
|
const else_expr = (0, utils_1.generate)(node.alternate)?.code;
|
|
465
|
-
return (0, utils_1.throwError)(options
|
|
465
|
+
return (0, utils_1.throwError)(options, `数据查询中不支持条件表达式!${(0, utils_1.generate)(node)?.code}, 请使用 SQL函数 IF(${expr} == null, ${then_expr}, ${else_expr})`);
|
|
466
466
|
}
|
|
467
467
|
const test = transformNodeFunction(node.test, options);
|
|
468
468
|
const consequent = transformNodeFunction(node.consequent, options);
|
|
@@ -515,7 +515,7 @@ function transform2NewAnonymousStructure(node, options) {
|
|
|
515
515
|
item.naslType = currentType.typeAnnotation;
|
|
516
516
|
}
|
|
517
517
|
else {
|
|
518
|
-
return (0, utils_1.throwError)(options
|
|
518
|
+
return (0, utils_1.throwError)(options, '匿名数据结构的属性中, 不允许出现没有类型的 null 值,请使用 as 关键字来指定类型,如 { price: null as Decimal }', node);
|
|
519
519
|
}
|
|
520
520
|
}
|
|
521
521
|
else if (itemValue.type === 'TSAsExpression') {
|
|
@@ -556,7 +556,7 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
556
556
|
});
|
|
557
557
|
}
|
|
558
558
|
if (node?.arguments && node?.arguments?.[0]?.type !== 'ArrayExpression') {
|
|
559
|
-
return (0, utils_1.throwError)(options
|
|
559
|
+
return (0, utils_1.throwError)(options, 'NewList 中不允许出现非数组表达式', node);
|
|
560
560
|
}
|
|
561
561
|
return new utils_1.naslTypes.NewList({
|
|
562
562
|
typeAnnotation: node?.typeParameters ? typeAnnotation : undefined,
|
|
@@ -589,13 +589,13 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
589
589
|
const typeParam = node.typeParameters?.params[0];
|
|
590
590
|
const typeNamespaceAndName = typeParam ? (0, utils_1.generate)(typeParam).code : '';
|
|
591
591
|
if (!typeNamespaceAndName)
|
|
592
|
-
return (0, utils_1.throwError)(options
|
|
592
|
+
return (0, utils_1.throwError)(options, 'NewEntity 中必须指定类型', node);
|
|
593
593
|
return transform2NewStructure(typeNamespaceAndName, node.arguments[0], options);
|
|
594
594
|
}
|
|
595
595
|
if (calleeName === 'NewAnonymousStructure') {
|
|
596
596
|
return transform2NewAnonymousStructure(node.arguments[0], options);
|
|
597
597
|
}
|
|
598
|
-
return (0, utils_1.throwError)(options
|
|
598
|
+
return (0, utils_1.throwError)(options, '在新建表达式中不支持节点类型', node.type, node);
|
|
599
599
|
}
|
|
600
600
|
function pushElseIf(ifNode, switchStatement, options) {
|
|
601
601
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
@@ -622,7 +622,7 @@ function transformBlockBody(body, options) {
|
|
|
622
622
|
return body.flatMap((item) => {
|
|
623
623
|
const logicItem = transformNodeFunction(item, options);
|
|
624
624
|
if (!logicItem) {
|
|
625
|
-
console.log('item in block:', item);
|
|
625
|
+
console.log('item in block:', (0, utils_1.generate)(item).code);
|
|
626
626
|
return [];
|
|
627
627
|
}
|
|
628
628
|
return item?.type === 'ReturnStatement' && item?.argument && logicItem.concept !== 'End' ? [logicItem, new utils_1.naslTypes.End()] : [logicItem];
|
|
@@ -825,7 +825,7 @@ function transformIdentifier(node, options) {
|
|
|
825
825
|
propertyName: '',
|
|
826
826
|
});
|
|
827
827
|
}
|
|
828
|
-
const placeholderMap = ['__IDENTIFIER__', '__LEFT__', '__RIGHT__', '__RIGHT', '__LEFT', '__IDENTIFIER'
|
|
828
|
+
const placeholderMap = ['__IDENTIFIER__', '__LEFT__', '__RIGHT__', '__RIGHT', '__LEFT', '__IDENTIFIER'];
|
|
829
829
|
if (placeholderMap.includes(node.name)) {
|
|
830
830
|
return new utils_1.naslTypes.Identifier({});
|
|
831
831
|
}
|
|
@@ -839,6 +839,9 @@ function transformIdentifier(node, options) {
|
|
|
839
839
|
}),
|
|
840
840
|
});
|
|
841
841
|
}
|
|
842
|
+
else if (node.name === 'undefined') {
|
|
843
|
+
return new utils_1.naslTypes.NullLiteral();
|
|
844
|
+
}
|
|
842
845
|
return new utils_1.naslTypes.Identifier({
|
|
843
846
|
name: node.name,
|
|
844
847
|
});
|
|
@@ -850,7 +853,7 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
850
853
|
if (expression.type === 'Identifier') {
|
|
851
854
|
const isSameName = (0, utils_2.firstUpperCase)(asNameNode.name) === expression.name;
|
|
852
855
|
if (!isSameName) {
|
|
853
|
-
return (0, utils_1.throwError)(options
|
|
856
|
+
return (0, utils_1.throwError)(options, `字段名需为 ${(0, utils_2.firstLowerCase)(expression.name)}, 目前为: ${asNameNode.name}, 相关代码如下`, node);
|
|
854
857
|
}
|
|
855
858
|
return new utils_1.naslTypes.QueryFieldExpression({
|
|
856
859
|
isDotStar: true,
|
|
@@ -871,7 +874,7 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
871
874
|
// @TODO
|
|
872
875
|
}
|
|
873
876
|
else {
|
|
874
|
-
return (0, utils_1.throwError)(options
|
|
877
|
+
return (0, utils_1.throwError)(options, '在 QueryFieldExpression 不支持表达式类型', expression.type, expression);
|
|
875
878
|
}
|
|
876
879
|
}
|
|
877
880
|
function transform2QueryAggregateExpression(node, options) {
|
|
@@ -880,10 +883,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
880
883
|
const arg = callExpression.arguments[0];
|
|
881
884
|
if (arg.type !== 'MemberExpression') {
|
|
882
885
|
const code = (0, utils_1.generate)(arg).code;
|
|
883
|
-
return (0, utils_1.throwError)(options
|
|
886
|
+
return (0, utils_1.throwError)(options, `聚合函数的输入只能是表字段(实体.属性),但${callExpression.callee.name}(${code})中的${code}不是表字段`, node);
|
|
884
887
|
}
|
|
885
888
|
if (callExpression.arguments?.length > 1) {
|
|
886
|
-
return (0, utils_1.throwError)(options
|
|
889
|
+
return (0, utils_1.throwError)(options, `聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
887
890
|
}
|
|
888
891
|
return new utils_1.naslTypes.QueryAggregateExpression({
|
|
889
892
|
asName: asNameNode.name,
|
|
@@ -893,7 +896,7 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
893
896
|
}
|
|
894
897
|
function transform2AnonymousFunction(node, options) {
|
|
895
898
|
if (node.body.type === 'BlockStatement')
|
|
896
|
-
return (0, utils_1.throwError)(options
|
|
899
|
+
return (0, utils_1.throwError)(options, 'Anonymous function with block statement is not supported', node);
|
|
897
900
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
898
901
|
return new utils_1.naslTypes.AnonymousFunction({
|
|
899
902
|
params: node.params.map((param) => transform2Param(param, options)).filter(Boolean),
|
|
@@ -1178,7 +1181,7 @@ function transformNewExpression(node, options) {
|
|
|
1178
1181
|
else if (calleeName.includes('.entities.') || calleeName.includes('.structures.')) {
|
|
1179
1182
|
return transform2NewStructure(calleeName, node.arguments[0], options);
|
|
1180
1183
|
}
|
|
1181
|
-
return (0, utils_1.throwError)(options
|
|
1184
|
+
return (0, utils_1.throwError)(options, '在新建表达式中不支持节点类型', node.type, node);
|
|
1182
1185
|
}
|
|
1183
1186
|
exports.transformNewExpression = transformNewExpression;
|
|
1184
1187
|
function transformMemberExpression(node, options) {
|
|
@@ -1308,38 +1311,80 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1308
1311
|
const arg = node.arguments[0];
|
|
1309
1312
|
const ifStatement = node.callee.body.body[0];
|
|
1310
1313
|
if (ifStatement.type !== 'IfStatement') {
|
|
1311
|
-
return (0, utils_1.throwError)(options
|
|
1314
|
+
return (0, utils_1.throwError)(options, 'Match 函数体内必须是一个 if 语句', ifStatement);
|
|
1312
1315
|
}
|
|
1313
1316
|
const flatedIfStatements = flatIfStatementForMatch(ifStatement);
|
|
1317
|
+
let isExpression = options.transformType !== 'logic';
|
|
1314
1318
|
const match = new utils_1.naslTypes.Match({
|
|
1315
1319
|
expression: transformNodeFunction(arg, options),
|
|
1316
|
-
isExpression
|
|
1317
|
-
cases: flatedIfStatements.map((_case) => {
|
|
1320
|
+
isExpression,
|
|
1321
|
+
cases: flatedIfStatements.map((_case, index) => {
|
|
1318
1322
|
let argument;
|
|
1319
1323
|
if (_case.consequent.type === 'BlockStatement') {
|
|
1320
1324
|
if (_case.consequent.body.length === 1 && _case.consequent.body[0].type === 'ReturnStatement') {
|
|
1321
1325
|
argument = _case.consequent.body[0].argument;
|
|
1326
|
+
// 有一个 Return, match 就按 expression 处理
|
|
1327
|
+
isExpression = true;
|
|
1322
1328
|
}
|
|
1323
1329
|
else {
|
|
1324
|
-
|
|
1330
|
+
const isLastCase = index === flatedIfStatements.length - 1;
|
|
1331
|
+
let allowEmptyBody = false;
|
|
1332
|
+
if (isExpression) {
|
|
1333
|
+
if (isLastCase) {
|
|
1334
|
+
// 检查前面所有case的test属性,对布尔或者枚举类型特殊处理
|
|
1335
|
+
allowEmptyBody = flatedIfStatements
|
|
1336
|
+
.slice(0, index)
|
|
1337
|
+
.every((prevCase) => {
|
|
1338
|
+
if (!prevCase.test || prevCase.test.type !== 'BinaryExpression')
|
|
1339
|
+
return false;
|
|
1340
|
+
const testNode = prevCase.test;
|
|
1341
|
+
const right = testNode.right;
|
|
1342
|
+
// 检查right是否为BooleanLiteral
|
|
1343
|
+
if (right?.type === 'BooleanLiteral')
|
|
1344
|
+
return true;
|
|
1345
|
+
// 检查right是否为MemberExpression且包含app.enums
|
|
1346
|
+
if (right?.type === 'MemberExpression') {
|
|
1347
|
+
const rightCode = (0, utils_1.generate)(right).code;
|
|
1348
|
+
return rightCode.includes('app.enums');
|
|
1349
|
+
}
|
|
1350
|
+
return false;
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
if (!allowEmptyBody) {
|
|
1354
|
+
return (0, utils_1.throwError)(options, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
else {
|
|
1358
|
+
allowEmptyBody = true;
|
|
1359
|
+
}
|
|
1325
1360
|
}
|
|
1326
1361
|
}
|
|
1327
1362
|
else {
|
|
1328
1363
|
if (_case.consequent.type === 'ReturnStatement') {
|
|
1329
1364
|
argument = _case.consequent.argument;
|
|
1365
|
+
isExpression = true;
|
|
1330
1366
|
}
|
|
1331
1367
|
else {
|
|
1332
|
-
return (0, utils_1.throwError)(options
|
|
1368
|
+
return (0, utils_1.throwError)(options, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1333
1369
|
}
|
|
1334
1370
|
}
|
|
1335
|
-
|
|
1371
|
+
let bodyNode = transformNodeFunction(argument, options);
|
|
1372
|
+
let body = [];
|
|
1373
|
+
if (bodyNode) {
|
|
1374
|
+
body = [bodyNode];
|
|
1375
|
+
}
|
|
1376
|
+
if (!isExpression && _case.consequent.type === 'BlockStatement') {
|
|
1377
|
+
body = transformBlockBody(_case.consequent.body.filter((item) => item.type !== 'BreakStatement'), options);
|
|
1378
|
+
}
|
|
1336
1379
|
return new utils_1.naslTypes.MatchCase({
|
|
1337
1380
|
isMatchedTypeEnumable: false,
|
|
1338
1381
|
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1339
|
-
body
|
|
1382
|
+
body,
|
|
1340
1383
|
});
|
|
1341
1384
|
}).filter(Boolean),
|
|
1342
1385
|
});
|
|
1386
|
+
// 根据 toNaturalTS,有Return语句的默认为 expression
|
|
1387
|
+
match.isExpression = isExpression;
|
|
1343
1388
|
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1344
1389
|
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
1345
1390
|
isMatchedTypeEnumable: false,
|
|
@@ -1349,7 +1394,7 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1349
1394
|
}
|
|
1350
1395
|
match.cases.forEach((case_) => {
|
|
1351
1396
|
if (case_.patterns.length) {
|
|
1352
|
-
if (case_.patterns[0].concept === 'BooleanLiteral'
|
|
1397
|
+
if (case_.patterns[0].concept === 'BooleanLiteral') {
|
|
1353
1398
|
case_.isMatchedTypeEnumable = true;
|
|
1354
1399
|
}
|
|
1355
1400
|
if (case_.patterns[0].concept === 'MemberExpression') {
|
|
@@ -1357,13 +1402,13 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1357
1402
|
case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
|
|
1358
1403
|
object: {
|
|
1359
1404
|
concept: 'Identifier',
|
|
1360
|
-
name: case_.patterns[0].object.
|
|
1405
|
+
name: case_.patterns[0].object.name,
|
|
1361
1406
|
folded: false,
|
|
1362
1407
|
namespace: 'app.enums'
|
|
1363
1408
|
},
|
|
1364
1409
|
property: {
|
|
1365
1410
|
concept: 'Identifier',
|
|
1366
|
-
name: case_.patterns[0].property.
|
|
1411
|
+
name: case_.patterns[0].property.name,
|
|
1367
1412
|
folded: false,
|
|
1368
1413
|
},
|
|
1369
1414
|
});
|
|
@@ -1375,7 +1420,7 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1375
1420
|
exports.transformCallFunctionExpression2Match = transformCallFunctionExpression2Match;
|
|
1376
1421
|
function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
1377
1422
|
if (options?.isRestricted)
|
|
1378
|
-
return (0, utils_1.throwError)(options
|
|
1423
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1379
1424
|
if (calleeName?.includes('getPropValue') || calleeName?.includes('setPropValue')) {
|
|
1380
1425
|
const componentName = callee?.[1]?.name;
|
|
1381
1426
|
const propertyName = node?.arguments?.[0]?.value;
|
|
@@ -1411,7 +1456,7 @@ function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
|
1411
1456
|
exports.transformCall2CallViewElementLogic = transformCall2CallViewElementLogic;
|
|
1412
1457
|
function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
1413
1458
|
if (options?.isRestricted)
|
|
1414
|
-
return (0, utils_1.throwError)(options
|
|
1459
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1415
1460
|
const entityName = callee[0].name.replace(/Entity$/, '');
|
|
1416
1461
|
// console.log('callee', callee);
|
|
1417
1462
|
return new utils_1.naslTypes.CallLogic({
|
|
@@ -1425,7 +1470,7 @@ function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
|
1425
1470
|
exports.transformCall2CallEntityLogic = transformCall2CallEntityLogic;
|
|
1426
1471
|
function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
1427
1472
|
if (options?.isRestricted)
|
|
1428
|
-
return (0, utils_1.throwError)(options
|
|
1473
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1429
1474
|
if (calleeName?.includes('.entities.')) {
|
|
1430
1475
|
const calleeNamespace = (0, utils_1.generate)(node?.callee?.object?.object)?.code;
|
|
1431
1476
|
const entityName = node?.callee?.object?.property?.name?.replace(/Entity$/, '');
|
|
@@ -1485,9 +1530,9 @@ function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
|
1485
1530
|
exports.transformCall2CallDataSourceLogic = transformCall2CallDataSourceLogic;
|
|
1486
1531
|
function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
1487
1532
|
if (options?.isInFrontend)
|
|
1488
|
-
return (0, utils_1.throwError)(options
|
|
1533
|
+
return (0, utils_1.throwError)(options, 'OQL组件不支持在前端使用', node);
|
|
1489
1534
|
if (options?.isRestricted)
|
|
1490
|
-
return (0, utils_1.throwError)(options
|
|
1535
|
+
return (0, utils_1.throwError)(options, 'OQL组件不支持在组件或默认值表达式中使用', node);
|
|
1491
1536
|
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1492
1537
|
// const _typeAnnotation = node?.typeParameters?.params?.length > 0 ? naslTypes.TypeAnnotation.createGeneric('List', {
|
|
1493
1538
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType })),
|
|
@@ -1503,7 +1548,7 @@ function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
|
1503
1548
|
}
|
|
1504
1549
|
function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
1505
1550
|
if (options?.isRestricted)
|
|
1506
|
-
return (0, utils_1.throwError)(options
|
|
1551
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1507
1552
|
return new utils_1.naslTypes.CallLogic({
|
|
1508
1553
|
calleeNamespace: 'nasl.logging',
|
|
1509
1554
|
calleeName: 'INFO',
|
|
@@ -1516,7 +1561,7 @@ function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
|
1516
1561
|
exports.transformCall2ConsoleLog = transformCall2ConsoleLog;
|
|
1517
1562
|
function transformCall2Logging(node, calleeName, callee, options) {
|
|
1518
1563
|
if (options?.isRestricted)
|
|
1519
|
-
return (0, utils_1.throwError)(options
|
|
1564
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1520
1565
|
const newArguments = node.arguments.map((arg) => new utils_1.naslTypes.Argument({
|
|
1521
1566
|
expression: arg?.name === "undefined" ?
|
|
1522
1567
|
new utils_1.naslTypes.StringLiteral()
|
|
@@ -1642,7 +1687,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1642
1687
|
const content = np?.toNaturalTS();
|
|
1643
1688
|
const noContent = np?.toNaturalTS()?.includes('__IDENTIFIER__');
|
|
1644
1689
|
if (!np && !p?.defaultExpression) {
|
|
1645
|
-
return (0, utils_1.throwError)(options
|
|
1690
|
+
return (0, utils_1.throwError)(options, `函数${calleeName}生成不符合标准的函数调用`, content);
|
|
1646
1691
|
}
|
|
1647
1692
|
if (np && calleeName === 'ListDistinctBy') {
|
|
1648
1693
|
if (idx === 1) {
|
|
@@ -1675,7 +1720,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1675
1720
|
});
|
|
1676
1721
|
}
|
|
1677
1722
|
else {
|
|
1678
|
-
return (0, utils_1.throwError)(options
|
|
1723
|
+
return (0, utils_1.throwError)(options, `函数${calleeName}不存在`, node.callee, node);
|
|
1679
1724
|
}
|
|
1680
1725
|
if (!func.params?.length) {
|
|
1681
1726
|
const needDefaultParam = ['CurrDate', 'CurrTime', 'CurrDateTime'];
|
|
@@ -1697,7 +1742,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1697
1742
|
// 这两个参数比较特殊,可以无限加参数,不再判断参数数量
|
|
1698
1743
|
const excludes = ['HasValue', 'ListSort'];
|
|
1699
1744
|
if (func.params?.length !== newArguments?.length && !excludes.includes(calleeName)) {
|
|
1700
|
-
return (0, utils_1.throwError)(options
|
|
1745
|
+
return (0, utils_1.throwError)(options, `函数${calleeName}生成不符合标准的函数调用,参数数量不匹配`, node.callee, node);
|
|
1701
1746
|
}
|
|
1702
1747
|
else {
|
|
1703
1748
|
newArguments?.forEach((arg, idx) => {
|
|
@@ -1715,17 +1760,20 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1715
1760
|
});
|
|
1716
1761
|
if (calleeName === 'ListSort') {
|
|
1717
1762
|
const handledNode = (0, utils_1.handleListSort)(nodeElement?.toJSON(), options);
|
|
1763
|
+
if (handledNode === null) {
|
|
1764
|
+
return (0, utils_1.throwError)(options, 'ListSort 函数使用错误,ListSort 定义如下:export function ListSort<T>(list: List<T>, ...fns: ((item: T) => { asc: Boolean, by: Boolean | Long | Decimal | String | Date | Time | DateTime; })[]): List<T>;', node);
|
|
1765
|
+
}
|
|
1718
1766
|
return handledNode && new utils_1.naslTypes.CallFunction(handledNode);
|
|
1719
1767
|
}
|
|
1720
1768
|
if (options.transformType === 'logic' && options?.inCallQueryComponentField) {
|
|
1721
|
-
return (0, utils_1.throwError)(options
|
|
1769
|
+
return (0, utils_1.throwError)(options, '数据查询中不支持使用内置函数', nodeElement.calleeName, node);
|
|
1722
1770
|
}
|
|
1723
1771
|
return nodeElement;
|
|
1724
1772
|
}
|
|
1725
1773
|
exports.transform2CallFunction = transform2CallFunction;
|
|
1726
1774
|
function transform2SqlFunction(node, calleeName, argument, options) {
|
|
1727
1775
|
if (options.inCallQueryComponentField && !['WHERE', 'HAVING', 'ORDER_BY'].includes(options.inCallQueryComponentField)) {
|
|
1728
|
-
return (0, utils_1.throwError)(options
|
|
1776
|
+
return (0, utils_1.throwError)(options, `数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}`, node.callee, node);
|
|
1729
1777
|
}
|
|
1730
1778
|
const specFunList = ['COUNT', 'COUNTD', 'SUM', 'AVG', 'MAX', 'MIN'];
|
|
1731
1779
|
// TODO: 先写死了 mysql,后续需要传入: 参考 requestSqlFunctions
|
|
@@ -1826,10 +1874,10 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1826
1874
|
});
|
|
1827
1875
|
}
|
|
1828
1876
|
if (options?.isRestricted)
|
|
1829
|
-
return (0, utils_1.throwError)(options
|
|
1830
|
-
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1831
|
-
|
|
1832
|
-
}
|
|
1877
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1878
|
+
// if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1879
|
+
// return transformCall2ConsoleLog(node, calleeName, callee, options);
|
|
1880
|
+
// }
|
|
1833
1881
|
return new utils_1.naslTypes.CallLogic({
|
|
1834
1882
|
calleeNamespace: 'nasl.ui',
|
|
1835
1883
|
calleeName: callee[2].name,
|
|
@@ -1950,7 +1998,7 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1950
1998
|
exports.transformForEach2ForEachStatement = transformForEach2ForEachStatement;
|
|
1951
1999
|
function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
1952
2000
|
if (options?.isRestricted)
|
|
1953
|
-
return (0, utils_1.throwError)(options
|
|
2001
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1954
2002
|
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1955
2003
|
return transformCall2ConsoleLog(node, calleeName, callee, options);
|
|
1956
2004
|
}
|
|
@@ -1966,7 +2014,7 @@ function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
|
1966
2014
|
exports.transformAlert2ShowMessage = transformAlert2ShowMessage;
|
|
1967
2015
|
function transformCall2Interface(node, calleeName, callee, options) {
|
|
1968
2016
|
if (options?.isRestricted)
|
|
1969
|
-
return (0, utils_1.throwError)(options
|
|
2017
|
+
return (0, utils_1.throwError)(options, '调用接口不支持在组件或默认值表达式中使用', node);
|
|
1970
2018
|
return new utils_1.naslTypes.CallInterface({
|
|
1971
2019
|
calleeNamespace: (0, utils_1.generate)(node.callee.object).code,
|
|
1972
2020
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -1979,14 +2027,14 @@ function transformCall2Interface(node, calleeName, callee, options) {
|
|
|
1979
2027
|
exports.transformCall2Interface = transformCall2Interface;
|
|
1980
2028
|
function transformCall2Connector(node, calleeName, callee, options) {
|
|
1981
2029
|
if (options?.isRestricted)
|
|
1982
|
-
return (0, utils_1.throwError)(options
|
|
2030
|
+
return (0, utils_1.throwError)(options, '调用连接器不支持在组件或默认值表达式中使用', node);
|
|
1983
2031
|
let calleeConnectionName = undefined;
|
|
1984
2032
|
let calleeNamespace = undefined;
|
|
1985
2033
|
let calleeNamespacePrefix = `connector.${callee[1].name}`;
|
|
1986
2034
|
if (callee.length === 5) {
|
|
1987
2035
|
const connectArg = callee[2].arguments[0];
|
|
1988
2036
|
if (!connectArg || connectArg.type !== 'StringLiteral') {
|
|
1989
|
-
return (0, utils_1.throwError)(options
|
|
2037
|
+
return (0, utils_1.throwError)(options, '调用 connector 的 connect 参数不正确,只允许使用字符串字面量', node);
|
|
1990
2038
|
}
|
|
1991
2039
|
calleeConnectionName = connectArg.value;
|
|
1992
2040
|
const noNamespace = callee[3].name === 'logics';
|
|
@@ -2001,7 +2049,7 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
2001
2049
|
calleeNamespace = calleeNamespacePrefix;
|
|
2002
2050
|
}
|
|
2003
2051
|
else {
|
|
2004
|
-
return (0, utils_1.throwError)(options
|
|
2052
|
+
return (0, utils_1.throwError)(options, `调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}`, node);
|
|
2005
2053
|
}
|
|
2006
2054
|
return new utils_1.naslTypes.CallConnector({
|
|
2007
2055
|
calleeConnectionName,
|
|
@@ -2015,7 +2063,7 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
2015
2063
|
exports.transformCall2Connector = transformCall2Connector;
|
|
2016
2064
|
function transformCall2Extension(node, calleeName, callee, options) {
|
|
2017
2065
|
if (options?.isRestricted)
|
|
2018
|
-
return (0, utils_1.throwError)(options
|
|
2066
|
+
return (0, utils_1.throwError)(options, '调用扩展逻辑不支持在组件或默认值表达式中使用', node);
|
|
2019
2067
|
return new utils_1.naslTypes.CallLogic({
|
|
2020
2068
|
calleeNamespace: (0, utils_1.generate)(node?.callee?.object)?.code,
|
|
2021
2069
|
calleeName: callee?.[callee?.length - 1]?.name,
|
|
@@ -2032,19 +2080,19 @@ function transformTSAsExpression(node, options) {
|
|
|
2032
2080
|
else if (node.expression.type === 'ArrayExpression') {
|
|
2033
2081
|
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined;
|
|
2034
2082
|
if (typeAnnotation.typeName !== 'List' && typeAnnotation.typeNamespace !== 'nasl.collection')
|
|
2035
|
-
return (0, utils_1.throwError)(options
|
|
2083
|
+
return (0, utils_1.throwError)(options, `列表 as 必须为 List 类型`, node);
|
|
2036
2084
|
return transformArrayExpression(node.expression, { ...options, typeAnnotation });
|
|
2037
2085
|
}
|
|
2038
2086
|
else if (node.expression.type === 'NullLiteral') {
|
|
2039
2087
|
return transform2NullLiteral(node.expression, options);
|
|
2040
2088
|
}
|
|
2041
2089
|
else {
|
|
2042
|
-
return (0, utils_1.throwError)(options
|
|
2090
|
+
return (0, utils_1.throwError)(options, '表达式不支持使用 as 关键字', node.expression.type, node.expression);
|
|
2043
2091
|
}
|
|
2044
2092
|
}
|
|
2045
2093
|
function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
2046
2094
|
if (options?.isRestricted)
|
|
2047
|
-
return (0, utils_1.throwError)(options
|
|
2095
|
+
return (0, utils_1.throwError)(options, '调用页面逻辑不支持在组件或默认值表达式中使用', node);
|
|
2048
2096
|
return new utils_1.naslTypes.CallLogic({
|
|
2049
2097
|
calleeNamespace: '',
|
|
2050
2098
|
calleeName: calleeName.slice('viewLogic_'.length),
|
|
@@ -2056,7 +2104,7 @@ function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
|
2056
2104
|
exports.transformCall2CallViewLogic = transformCall2CallViewLogic;
|
|
2057
2105
|
function transformCall2Logic(node, calleeName, callee, options) {
|
|
2058
2106
|
if (options?.isRestricted)
|
|
2059
|
-
return (0, utils_1.throwError)(options
|
|
2107
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
2060
2108
|
if (utils_1.callFunctionMap.includes(calleeName)) {
|
|
2061
2109
|
// 未带前缀,补一下
|
|
2062
2110
|
return transform2CallFunction(node, calleeName, node?.arguments || [], options);
|
|
@@ -2082,7 +2130,7 @@ function transformCall2Logic(node, calleeName, callee, options) {
|
|
|
2082
2130
|
exports.transformCall2Logic = transformCall2Logic;
|
|
2083
2131
|
function transformCall2LogicWithAuth(node, calleeName, callee, options) {
|
|
2084
2132
|
if (options?.isRestricted)
|
|
2085
|
-
return (0, utils_1.throwError)(options
|
|
2133
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
2086
2134
|
return new utils_1.naslTypes.CallLogic({
|
|
2087
2135
|
calleeNamespace: `nasl.auth`,
|
|
2088
2136
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -2107,10 +2155,10 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
2107
2155
|
const calleeName = node.callee.name;
|
|
2108
2156
|
if (['FROM', 'INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(calleeName)) {
|
|
2109
2157
|
if (node.arguments[1].type !== 'ArrowFunctionExpression')
|
|
2110
|
-
return (0, utils_1.throwError)(options
|
|
2158
|
+
return (0, utils_1.throwError)(options, 'FROM should have a ArrowFunctionExpression as the second argument', node.arguments[1], node);
|
|
2111
2159
|
const arrowFunctionExpression = node.arguments[1];
|
|
2112
2160
|
if (arrowFunctionExpression.body.type !== 'CallExpression')
|
|
2113
|
-
return (0, utils_1.throwError)(options
|
|
2161
|
+
return (0, utils_1.throwError)(options, 'FROM should have a CallExpression as the body of ArrowFunctionExpression', arrowFunctionExpression.body, node);
|
|
2114
2162
|
const body = arrowFunctionExpression.body;
|
|
2115
2163
|
const callExpressions = flatChainCallExpression(body);
|
|
2116
2164
|
const joinNode = callExpressions?.filter((item) => item?.callee?.name.includes('_JOIN'));
|
|
@@ -2120,13 +2168,13 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
2120
2168
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id)).SELECT(...)); // 错误用法, ${name}的回调函数必须是完整的QueryChain
|
|
2121
2169
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); // 正确用法, 后续查询都在${name}的回调函数中进行
|
|
2122
2170
|
`;
|
|
2123
|
-
return (0, utils_1.throwError)(options
|
|
2171
|
+
return (0, utils_1.throwError)(options, error, node);
|
|
2124
2172
|
}
|
|
2125
2173
|
const joinCode = (0, utils_1.generate)(joinNode[0])?.code || '';
|
|
2126
2174
|
const count = joinCode.match(/_JOIN/g)?.length || 0;
|
|
2127
2175
|
const errorOrder = count >= 1 && !callExpressions?.[callExpressions?.length - 1]?.callee?.name?.includes('_JOIN');
|
|
2128
2176
|
if (errorOrder) {
|
|
2129
|
-
return (0, utils_1.throwError)(options
|
|
2177
|
+
return (0, utils_1.throwError)(options, '调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。', node);
|
|
2130
2178
|
}
|
|
2131
2179
|
const result = [{
|
|
2132
2180
|
calleeName: calleeName,
|
|
@@ -2176,26 +2224,26 @@ function transformMemberExpression2Entity(node, node2, options) {
|
|
|
2176
2224
|
const entityNamespace = entityPath.slice(0, -1).map(n => n.name).join('.');
|
|
2177
2225
|
const entityName = entityPath[entityPath.length - 1].name.replace(/Entity$/, '');
|
|
2178
2226
|
if (!entityNamespace?.includes('.entities')) {
|
|
2179
|
-
return (0, utils_1.throwError)(options
|
|
2227
|
+
return (0, utils_1.throwError)(options, `${entityNamespace}.${entityName} 不是一个数据库表,无法使用数据查询`, node);
|
|
2180
2228
|
}
|
|
2181
2229
|
const asName = node2.name === entityName ? undefined : node2.name;
|
|
2182
2230
|
if (asName) {
|
|
2183
|
-
return (0, utils_1.throwError)(options
|
|
2231
|
+
return (0, utils_1.throwError)(options, `FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
2184
2232
|
}
|
|
2185
2233
|
return { entityNamespace, entityName, asName };
|
|
2186
2234
|
}
|
|
2187
2235
|
function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
2188
2236
|
if (options?.isInFrontend)
|
|
2189
|
-
return (0, utils_1.throwError)(options
|
|
2237
|
+
return (0, utils_1.throwError)(options, '数据查询组件不支持在前端使用', node);
|
|
2190
2238
|
if (options?.isRestricted)
|
|
2191
|
-
return (0, utils_1.throwError)(options
|
|
2239
|
+
return (0, utils_1.throwError)(options, '数据查询组件不支持在组件或默认值表达式中使用', node);
|
|
2192
2240
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
2193
2241
|
const code = (0, utils_1.generate)(node)?.code || '';
|
|
2194
2242
|
if (code?.includes('nasl.util')) {
|
|
2195
|
-
return (0, utils_1.throwError)(options
|
|
2243
|
+
return (0, utils_1.throwError)(options, '数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理', code);
|
|
2196
2244
|
}
|
|
2197
2245
|
if (!code?.includes('.SELECT(') && !code?.includes('.AGGR_SELECT(')) {
|
|
2198
|
-
return (0, utils_1.throwError)(options
|
|
2246
|
+
return (0, utils_1.throwError)(options, '缺少 SELECT 或 AGGR_SELECT 语句', code);
|
|
2199
2247
|
}
|
|
2200
2248
|
const flatted = flatCallQueryComponentChainNode(node, options);
|
|
2201
2249
|
if (!flatted)
|
|
@@ -2203,7 +2251,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2203
2251
|
const calleeNames = flatted && flatted.map((item) => item?.calleeName).filter((name) => name !== '$');
|
|
2204
2252
|
const isOrderCorrect = (0, utils_1.checkOQLCalleeNameOrder)(calleeNames);
|
|
2205
2253
|
if (!isOrderCorrect) {
|
|
2206
|
-
return (0, utils_1.throwError)(options
|
|
2254
|
+
return (0, utils_1.throwError)(options, '调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。', node);
|
|
2207
2255
|
}
|
|
2208
2256
|
let from;
|
|
2209
2257
|
let where;
|
|
@@ -2242,7 +2290,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2242
2290
|
const joinType = rawJoinType === 'OUTER' ? 'FULL' : rawJoinType;
|
|
2243
2291
|
const onExpressions = flatOnExpressions(item.arguments[2]);
|
|
2244
2292
|
if (!from)
|
|
2245
|
-
return; // throwError(options
|
|
2293
|
+
return; // throwError(options, 'FROM 不存在或异常,无法添加 JOIN 子句', node);
|
|
2246
2294
|
from.addJoinPart(new utils_1.naslTypes.QueryJoinExpression({
|
|
2247
2295
|
...entity,
|
|
2248
2296
|
joinType,
|
|
@@ -2258,8 +2306,8 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2258
2306
|
}));
|
|
2259
2307
|
break;
|
|
2260
2308
|
case 'AGGR_SELECT':
|
|
2261
|
-
if (groupBy
|
|
2262
|
-
return (0, utils_1.throwError)(options
|
|
2309
|
+
if (groupBy.length) {
|
|
2310
|
+
return (0, utils_1.throwError)(options, '存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT', node);
|
|
2263
2311
|
}
|
|
2264
2312
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
2265
2313
|
distinct: false,
|
|
@@ -2280,7 +2328,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2280
2328
|
}
|
|
2281
2329
|
}
|
|
2282
2330
|
else {
|
|
2283
|
-
return (0, utils_1.throwError)(options
|
|
2331
|
+
return (0, utils_1.throwError)(options, `Unsupported expression type for QueryAggregateExpression`, arg?.value.type, arg?.value);
|
|
2284
2332
|
}
|
|
2285
2333
|
});
|
|
2286
2334
|
}
|
|
@@ -2301,37 +2349,41 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2301
2349
|
}
|
|
2302
2350
|
}
|
|
2303
2351
|
else {
|
|
2304
|
-
return (0, utils_1.throwError)(options
|
|
2352
|
+
return (0, utils_1.throwError)(options, 'Unsupported expression type for QueryAggregateExpression', item.arguments[0].type, item.arguments[0]);
|
|
2305
2353
|
}
|
|
2306
2354
|
break;
|
|
2307
2355
|
case 'SELECT':
|
|
2308
2356
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
2309
2357
|
distinct: false,
|
|
2310
2358
|
star: true,
|
|
2311
|
-
selectElements: groupBy
|
|
2359
|
+
selectElements: groupBy.length ? [new utils_1.naslTypes.QueryFieldExpression({
|
|
2312
2360
|
isDotStar: true,
|
|
2313
2361
|
entityAsName: from?.entityName,
|
|
2314
2362
|
propertyName: '',
|
|
2315
2363
|
})] : [],
|
|
2316
2364
|
});
|
|
2365
|
+
if (item.arguments[0].type !== 'ObjectExpression') {
|
|
2366
|
+
select = undefined;
|
|
2367
|
+
return (0, utils_1.throwError)(options, 'SELECT 参数应为 ObjectExpression,标准示例:.SELECT({ ... })', node);
|
|
2368
|
+
}
|
|
2317
2369
|
item.arguments[0].properties?.forEach((arg) => {
|
|
2318
2370
|
let selectElements = [];
|
|
2319
2371
|
if (arg.value.type === 'CallExpression') {
|
|
2320
2372
|
selectElements = [transform2QueryAggregateExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName })];
|
|
2321
2373
|
}
|
|
2322
2374
|
else if (arg.value.type === 'ObjectExpression') {
|
|
2323
|
-
if (groupBy
|
|
2324
|
-
return (0, utils_1.throwError)(options
|
|
2375
|
+
if (groupBy.length) {
|
|
2376
|
+
return (0, utils_1.throwError)(options, '存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列', node);
|
|
2325
2377
|
}
|
|
2326
2378
|
const originName = arg.key?.name || '';
|
|
2327
2379
|
if (originName && originName.charAt(0) === originName.charAt(0).toUpperCase()) {
|
|
2328
2380
|
const needName = (0, utils_2.firstLowerCase)(originName);
|
|
2329
|
-
return (0, utils_1.throwError)(options
|
|
2381
|
+
return (0, utils_1.throwError)(options, `SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}`, node);
|
|
2330
2382
|
}
|
|
2331
2383
|
const entityName = (0, utils_2.firstUpperCase)(originName);
|
|
2332
2384
|
const needNameList = entityAsNames.map(item => (0, utils_2.firstLowerCase)(item))?.join('或');
|
|
2333
2385
|
if (!entityAsNames.includes(entityName)) {
|
|
2334
|
-
return (0, utils_1.throwError)(options
|
|
2386
|
+
return (0, utils_1.throwError)(options, `SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}`, node);
|
|
2335
2387
|
}
|
|
2336
2388
|
selectElements = arg.value.properties?.map((property) => {
|
|
2337
2389
|
const columnAsName = property.key?.name;
|
|
@@ -2339,7 +2391,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2339
2391
|
const selectElement = transform2SelectQueryFieldExpression(property, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2340
2392
|
if (columnAsName !== columnPropertyName) {
|
|
2341
2393
|
// eg: comment: Topic_Comment.comment_stu
|
|
2342
|
-
return (0, utils_1.throwError)(options
|
|
2394
|
+
return (0, utils_1.throwError)(options, `SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}`, node);
|
|
2343
2395
|
}
|
|
2344
2396
|
selectElement.isDotStar = false;
|
|
2345
2397
|
return selectElement;
|
|
@@ -2350,7 +2402,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2350
2402
|
hasErrorTSScopeColumn = true;
|
|
2351
2403
|
}
|
|
2352
2404
|
if (arg.type === 'ObjectProperty' && select?.selectElements?.find(item => item?.concept === 'QueryFieldExpression' && item.entityAsName === arg.value?.name)) {
|
|
2353
|
-
return (0, utils_1.throwError)(options
|
|
2405
|
+
return (0, utils_1.throwError)(options, `SELECT 禁止在一次查询中对同一实体设置多个别名,请修改`, node);
|
|
2354
2406
|
}
|
|
2355
2407
|
selectElements = [transform2SelectQueryFieldExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName })];
|
|
2356
2408
|
}
|
|
@@ -2377,35 +2429,43 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2377
2429
|
}
|
|
2378
2430
|
}
|
|
2379
2431
|
else {
|
|
2380
|
-
return (0, utils_1.throwError)(options
|
|
2432
|
+
return (0, utils_1.throwError)(options, 'HAVING 不符合规范,请使用箭头函数', havingNode, node);
|
|
2381
2433
|
}
|
|
2382
2434
|
having = transformNodeFunction(havingNode, { ...options, ...restParams });
|
|
2383
2435
|
break;
|
|
2384
2436
|
case 'ORDER_BY':
|
|
2437
|
+
const ORDER_BY_ERROR_MESSAGE = `ORDER_BY 不符合规范,请使用箭头函数,并返回 Array<[字段值, "ASC" | "DESC"]> 的形式,示例:
|
|
2438
|
+
- .ORDER_BY((resultItem) => [[resultItem[sort], order]])
|
|
2439
|
+
- .ORDER_BY((resultItem) => [[Student.age, 'ASC'], [Student.name, 'DESC']])`;
|
|
2385
2440
|
let orderNode = item.arguments;
|
|
2386
2441
|
let restOptionParams = { entityAsNames };
|
|
2387
|
-
if (orderNode
|
|
2388
|
-
const params = orderNode
|
|
2389
|
-
if (orderNode
|
|
2390
|
-
return (0, utils_1.throwError)(options
|
|
2442
|
+
if (orderNode.length === 1 && orderNode[0].type === 'ArrowFunctionExpression') {
|
|
2443
|
+
const params = orderNode[0].params;
|
|
2444
|
+
if (orderNode[0].body.type !== 'ArrayExpression') {
|
|
2445
|
+
return (0, utils_1.throwError)(options, ORDER_BY_ERROR_MESSAGE, orderNode, node);
|
|
2391
2446
|
}
|
|
2392
|
-
orderNode = orderNode
|
|
2393
|
-
if (params
|
|
2394
|
-
restOptionParams = { inOqlIdentifierNamespace: params
|
|
2447
|
+
orderNode = orderNode[0].body.elements;
|
|
2448
|
+
if (params.length && params[0].name) {
|
|
2449
|
+
restOptionParams = { inOqlIdentifierNamespace: params[0].name, entityAsNames };
|
|
2395
2450
|
}
|
|
2396
2451
|
}
|
|
2397
2452
|
else {
|
|
2398
|
-
return (0, utils_1.throwError)(options
|
|
2453
|
+
return (0, utils_1.throwError)(options, ORDER_BY_ERROR_MESSAGE, orderNode, node);
|
|
2399
2454
|
}
|
|
2400
2455
|
orderBy = orderNode.map((arg) => {
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2456
|
+
if (arg.type === 'ArrayExpression') {
|
|
2457
|
+
let orderElementCode = (0, utils_1.generate)(arg)?.code || '';
|
|
2458
|
+
if (!useResultItem) {
|
|
2459
|
+
useResultItem = orderElementCode.includes('resultItem.');
|
|
2460
|
+
}
|
|
2461
|
+
return new utils_1.naslTypes.QueryOrderByExpression({
|
|
2462
|
+
orderElement: transformNodeFunction(arg.elements[0], { ...options, ...restOptionParams, inCallQueryComponentField: item.calleeName }),
|
|
2463
|
+
order: transformNodeFunction(arg.elements[1], { ...options, ...restOptionParams, inCallQueryComponentField: item.calleeName })
|
|
2464
|
+
});
|
|
2465
|
+
}
|
|
2466
|
+
else {
|
|
2467
|
+
(0, utils_1.throwError)(options, ORDER_BY_ERROR_MESSAGE, arg, node);
|
|
2404
2468
|
}
|
|
2405
|
-
return new utils_1.naslTypes.QueryOrderByExpression({
|
|
2406
|
-
orderElement: transformNodeFunction(arg.elements[0], { ...options, ...restOptionParams, inCallQueryComponentField: item.calleeName }),
|
|
2407
|
-
order: transformNodeFunction(arg.elements[1], { ...options, ...restOptionParams, inCallQueryComponentField: item.calleeName })
|
|
2408
|
-
});
|
|
2409
2469
|
});
|
|
2410
2470
|
break;
|
|
2411
2471
|
}
|
|
@@ -2420,27 +2480,30 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2420
2480
|
orderBy,
|
|
2421
2481
|
ideVersion: '2.22',
|
|
2422
2482
|
});
|
|
2423
|
-
if (
|
|
2424
|
-
return (0, utils_1.throwError)(options
|
|
2483
|
+
if (!select) {
|
|
2484
|
+
return (0, utils_1.throwError)(options, 'SELECT 不符合规范', node);
|
|
2485
|
+
}
|
|
2486
|
+
if (hasErrorTSScopeColumn && !groupBy.length && !having) {
|
|
2487
|
+
return (0, utils_1.throwError)(options, 'SELECT 局部列不符合规范,需要按两层对象返回', node);
|
|
2425
2488
|
}
|
|
2426
|
-
const hasScopeColumn = select
|
|
2427
|
-
if (hasScopeColumn && (groupBy
|
|
2428
|
-
return (0, utils_1.throwError)(options
|
|
2489
|
+
const hasScopeColumn = select.selectElements.find((selectElement) => selectElement.concept === 'QueryFieldExpression' && !selectElement.isDotStar);
|
|
2490
|
+
if (hasScopeColumn && (groupBy.length || having)) {
|
|
2491
|
+
return (0, utils_1.throwError)(options, '分组聚合与表字段局部列不允许同时出现', node);
|
|
2429
2492
|
}
|
|
2430
2493
|
if (hasScopeColumn && useResultItem) {
|
|
2431
|
-
return (0, utils_1.throwError)(options
|
|
2494
|
+
return (0, utils_1.throwError)(options, "对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])", node);
|
|
2432
2495
|
}
|
|
2433
|
-
const
|
|
2496
|
+
const onlyAggr = select.selectElements.length && select.selectElements.every((selectElement) => selectElement.concept === 'QueryAggregateExpression');
|
|
2434
2497
|
// 如果 select 中只有聚合属性时,并且没有用 AGGR_SELECT 来指定列
|
|
2435
|
-
if (
|
|
2436
|
-
return (0, utils_1.throwError)(options
|
|
2498
|
+
if (onlyAggr && !calleeNames.includes('AGGR_SELECT')) {
|
|
2499
|
+
return (0, utils_1.throwError)(options, 'SELECT 不符合规范,请使用 AGGR_SELECT', node);
|
|
2437
2500
|
}
|
|
2438
2501
|
// callQueryComponent.typeAnnotation = callQueryComponent.computeStructure();
|
|
2439
2502
|
return callQueryComponent;
|
|
2440
2503
|
}
|
|
2441
2504
|
function transformCall2LaunchProcess(node, calleeName, callee, options) {
|
|
2442
2505
|
if (options?.isRestricted)
|
|
2443
|
-
return (0, utils_1.throwError)(options
|
|
2506
|
+
return (0, utils_1.throwError)(options, '调用流程逻辑不支持在组件或默认值表达式中使用', node);
|
|
2444
2507
|
const args = node.arguments;
|
|
2445
2508
|
const dataArg = args?.[0];
|
|
2446
2509
|
const procDefKeyArg = args?.[1];
|
|
@@ -2556,9 +2619,19 @@ function transform2LogicItem(node, options) {
|
|
|
2556
2619
|
transformManager.registerCallExpression('PAGINATE', transformCall2Paginate);
|
|
2557
2620
|
transformManager.registerCallExpression('FROM', transformCall2DataQuery);
|
|
2558
2621
|
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && !['ArrowFunctionExpression', 'FunctionExpression'].includes(callee[0].type), transformCall2Logic);
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2622
|
+
try {
|
|
2623
|
+
let result = transformManager.apply(node, options);
|
|
2624
|
+
return result || undefined;
|
|
2625
|
+
}
|
|
2626
|
+
catch (err) {
|
|
2627
|
+
if (err.name === 'ParseNaturalTSError')
|
|
2628
|
+
throw err;
|
|
2629
|
+
(0, utils_1.throwError)(options, `解析逻辑发生异常:${err?.message}\n相关代码如下`, node);
|
|
2630
|
+
return undefined;
|
|
2631
|
+
}
|
|
2632
|
+
finally {
|
|
2633
|
+
delete options.typeAnnotation;
|
|
2634
|
+
}
|
|
2562
2635
|
}
|
|
2563
2636
|
exports.transform2LogicItem = transform2LogicItem;
|
|
2564
2637
|
//# sourceMappingURL=transform2LogicItem.js.map
|