@lcap/nasl 1.0.1 → 1.0.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/automate/engine/utils.js +16 -0
- package/out/automate/engine/utils.js.map +1 -1
- package/out/common/BaseNode.d.ts +1 -1
- package/out/common/BaseNode.js +13 -3
- package/out/common/BaseNode.js.map +1 -1
- package/out/concepts/App__.d.ts +1 -0
- package/out/concepts/App__.js +4 -1
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/Assignee__.d.ts +11 -0
- package/out/concepts/Assignee__.js +34 -0
- package/out/concepts/Assignee__.js.map +1 -1
- package/out/concepts/CallFunction__.js +1 -2
- package/out/concepts/CallFunction__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.d.ts +31 -2
- package/out/concepts/CallQueryComponent__.js +286 -51
- package/out/concepts/CallQueryComponent__.js.map +1 -1
- package/out/concepts/Constant__.js +6 -6
- package/out/concepts/Constant__.js.map +1 -1
- package/out/concepts/Destination__.js +18 -4
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/EntityIndex__.js +4 -2
- package/out/concepts/EntityIndex__.js.map +1 -1
- package/out/concepts/EntityProperty__.js +3 -5
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/Entity__.d.ts +1 -0
- package/out/concepts/Entity__.js +7 -1
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/Enum__.d.ts +1 -0
- package/out/concepts/Enum__.js +6 -2
- package/out/concepts/Enum__.js.map +1 -1
- package/out/concepts/Identifier__.js +1 -1
- package/out/concepts/Identifier__.js.map +1 -1
- package/out/concepts/InterfaceParam__.js +9 -4
- package/out/concepts/InterfaceParam__.js.map +1 -1
- package/out/concepts/Param__.d.ts +1 -1
- package/out/concepts/Param__.js +14 -7
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/ProcessElement__.js +8 -2
- package/out/concepts/ProcessElement__.js.map +1 -1
- package/out/concepts/QueryAggregateExpression__.js +1 -1
- package/out/concepts/QueryAggregateExpression__.js.map +1 -1
- package/out/concepts/QueryFieldExpression__.d.ts +1 -0
- package/out/concepts/QueryFieldExpression__.js +3 -0
- package/out/concepts/QueryFieldExpression__.js.map +1 -1
- package/out/concepts/QueryGroupByExpression__.d.ts +3 -0
- package/out/concepts/QueryGroupByExpression__.js +20 -0
- package/out/concepts/QueryGroupByExpression__.js.map +1 -1
- package/out/concepts/Return__.d.ts +1 -1
- package/out/concepts/Return__.js +15 -10
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/StringLiteral__.js +1 -8
- package/out/concepts/StringLiteral__.js.map +1 -1
- package/out/concepts/StructureProperty__.js +5 -5
- package/out/concepts/StructureProperty__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.js +12 -4
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/Variable__.d.ts +1 -1
- package/out/concepts/Variable__.js +15 -10
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewElement__.js +1 -1
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.d.ts +1 -1
- package/out/concepts/View__.js +15 -4
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.configuration.js +1 -1
- package/out/concepts/basics/stdlib/nasl.configuration.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.interface.d.ts +2 -0
- package/out/concepts/basics/stdlib/nasl.interface.js +4 -4
- package/out/concepts/basics/stdlib/nasl.interface.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.util.js +21 -37
- package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
- package/out/concepts/basics/stdlib/reference2TypeAnnotationList.js +1 -1
- package/out/concepts/basics/stdlib/reference2TypeAnnotationList.js.map +1 -1
- package/out/concepts/basics/types/index.d.ts +1 -0
- package/out/concepts/basics/types/index.js +3 -1
- package/out/concepts/basics/types/index.js.map +1 -1
- package/out/enums/KEYWORDS.js +0 -7
- package/out/enums/KEYWORDS.js.map +1 -1
- package/out/manager/diagnostic.d.ts +1 -1
- package/out/{test/integration/connect-file copy.d.ts → server/extendBaseNode.d.ts} +0 -0
- package/out/server/extendBaseNode.js +323 -0
- package/out/server/extendBaseNode.js.map +1 -0
- package/out/server/getLogics.js +22 -1
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.js +47 -2
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/getProcesses.d.ts +4 -2
- package/out/server/getProcesses.js +160 -20
- package/out/server/getProcesses.js.map +1 -1
- package/out/server/getScope.d.ts +1 -0
- package/out/server/getScope.js +4 -0
- package/out/server/getScope.js.map +1 -1
- package/out/server/index.d.ts +1 -0
- package/out/server/index.js +1 -0
- package/out/server/index.js.map +1 -1
- package/out/server/naslServer.d.ts +7 -5
- package/out/server/naslServer.js +96 -362
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.d.ts +1 -1
- package/out/server/translator.js +3 -1
- package/out/server/translator.js.map +1 -1
- package/out/service/storage/init.js +18 -10
- package/out/service/storage/init.js.map +1 -1
- package/out/templator/genGetBlock.js +1 -1
- package/out/templator/genGetBlock.js.map +1 -1
- package/out/templator/genQueryComponent.js +7 -4
- package/out/templator/genQueryComponent.js.map +1 -1
- package/out/templator/genSelectBlock.js +5 -15
- package/out/templator/genSelectBlock.js.map +1 -1
- package/out/templator/genUpdateBlock.js +1 -1
- package/out/templator/genUpdateBlock.js.map +1 -1
- package/out/templator/utils.d.ts +3 -1
- package/out/templator/utils.js +2 -1
- package/out/templator/utils.js.map +1 -1
- package/package.json +1 -2
- package/src/automate/engine/utils.js +16 -2
- package/src/common/BaseNode.ts +14 -3
- package/src/concepts/App__.ts +6 -39
- package/src/concepts/Assignee__.ts +30 -0
- package/src/concepts/CallFunction__.ts +1 -2
- package/src/concepts/CallQueryComponent__.ts +294 -54
- package/src/concepts/Constant__.ts +6 -6
- package/src/concepts/Destination__.ts +18 -20
- package/src/concepts/EntityIndex__.ts +4 -2
- package/src/concepts/EntityProperty__.ts +3 -5
- package/src/concepts/Entity__.ts +15 -3
- package/src/concepts/Enum__.ts +7 -15
- package/src/concepts/Identifier__.ts +1 -10
- package/src/concepts/InterfaceParam__.ts +9 -4
- package/src/concepts/Param__.ts +14 -7
- package/src/concepts/ProcessElement__.ts +9 -3
- package/src/concepts/QueryAggregateExpression__.ts +1 -1
- package/src/concepts/QueryFieldExpression__.ts +4 -0
- package/src/concepts/QueryGroupByExpression__.ts +23 -0
- package/src/concepts/Return__.ts +15 -10
- package/src/concepts/StringLiteral__.ts +1 -8
- package/src/concepts/StructureProperty__.ts +5 -5
- package/src/concepts/TypeAnnotation__.ts +12 -4
- package/src/concepts/Variable__.ts +15 -10
- package/src/concepts/ViewElement__.ts +2 -2
- package/src/concepts/View__.ts +16 -4
- package/src/concepts/basics/stdlib/nasl.configuration.ts +1 -1
- package/src/concepts/basics/stdlib/nasl.interface.ts +1 -1
- package/src/concepts/basics/stdlib/nasl.util.ts +21 -37
- package/src/concepts/basics/stdlib/reference2TypeAnnotationList.ts +1 -1
- package/src/concepts/basics/types/index.ts +1 -0
- package/src/enums/KEYWORDS.ts +0 -7
- package/src/manager/diagnostic.ts +1 -1
- package/src/server/extendBaseNode.ts +318 -0
- package/src/server/getLogics.ts +22 -1
- package/src/server/getMemberIdentifier.ts +49 -2
- package/src/server/getProcesses.ts +170 -21
- package/src/server/getScope.ts +5 -0
- package/src/server/index.ts +1 -0
- package/src/server/naslServer.ts +100 -355
- package/src/server/translator.ts +3 -1
- package/src/service/storage/init.ts +18 -11
- package/src/templator/genGetBlock.ts +1 -1
- package/src/templator/genQueryComponent.ts +7 -4
- package/src/templator/genSelectBlock.ts +5 -15
- package/src/templator/genUpdateBlock.ts +1 -1
- package/src/templator/utils.ts +3 -0
- package/out/concepts/basics/stdlib/nasl.browser copy.d.ts +0 -3
- package/out/concepts/basics/stdlib/nasl.browser copy.js +0 -70
- package/out/concepts/basics/stdlib/nasl.browser copy.js.map +0 -1
- package/out/terms/LEVEL_NAME_MAP.d.ts +0 -26
- package/out/terms/LEVEL_NAME_MAP.js +0 -30
- package/out/terms/LEVEL_NAME_MAP.js.map +0 -1
- package/out/test/integration/connect-file copy.js +0 -50
- package/out/test/integration/connect-file copy.js.map +0 -1
- package/out/test/integration/node-nasl-server.d.ts +0 -1
- package/out/test/integration/node-nasl-server.js +0 -41
- package/out/test/integration/node-nasl-server.js.map +0 -1
|
@@ -4,6 +4,7 @@ import Entity from './Entity__';
|
|
|
4
4
|
import Structure from './Structure__';
|
|
5
5
|
import StructureProperty from './StructureProperty__';
|
|
6
6
|
import CompletionProperty from './CompletionProperty__';
|
|
7
|
+
import QueryFieldExpression from './QueryFieldExpression__';
|
|
7
8
|
//================================================================================
|
|
8
9
|
// 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
|
|
9
10
|
// ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
|
|
@@ -781,10 +782,41 @@ export class CallQueryComponent extends LogicItem {
|
|
|
781
782
|
// })`;
|
|
782
783
|
}
|
|
783
784
|
|
|
785
|
+
isAutoInfer() {
|
|
786
|
+
return this.ideVersion === '2.11';
|
|
787
|
+
}
|
|
788
|
+
|
|
784
789
|
@withSourceMap()
|
|
785
790
|
toEmbeddedTS(state?: TranslatorState): string {
|
|
786
|
-
|
|
787
|
-
|
|
791
|
+
if (!this.typeAnnotation)
|
|
792
|
+
return `(function () {
|
|
793
|
+
return;
|
|
794
|
+
})()`;
|
|
795
|
+
let code = `(function(): `;
|
|
796
|
+
if (this.isAutoInfer()) {
|
|
797
|
+
code += `${this.typeAnnotation.toEmbeddedTS(shiftState(state, code))} {\n`;
|
|
798
|
+
} else {
|
|
799
|
+
code += `nasl.collection.PageOf<`;
|
|
800
|
+
code += `${this.typeAnnotation.toEmbeddedTS(shiftState(state, code))}> {\n`;
|
|
801
|
+
}
|
|
802
|
+
// 2.11版本后 分组使用别名
|
|
803
|
+
if (this.isAutoInfer()) {
|
|
804
|
+
// 分组别名(列别名)
|
|
805
|
+
this.groupBy.forEach((item, index, array) => {
|
|
806
|
+
code += indent(state.tabSize + 1);
|
|
807
|
+
const groupElement = item.groupElement as QueryFieldExpression;
|
|
808
|
+
if (groupElement.asName)
|
|
809
|
+
code += `const __${groupElement.asName} = `;
|
|
810
|
+
if (groupElement.propertyName) {
|
|
811
|
+
code += groupElement.toEmbeddedTS(shiftState(state, code, { tabSize: 0 }));
|
|
812
|
+
code += ';\n';
|
|
813
|
+
} else
|
|
814
|
+
code += `__EMPTY_GROUP_BY_NAME__;\n`;
|
|
815
|
+
|
|
816
|
+
if (index === array.length - 1)
|
|
817
|
+
code += '\n';
|
|
818
|
+
});
|
|
819
|
+
}
|
|
788
820
|
// 聚合属性别名
|
|
789
821
|
this.select.selectElements.forEach((item, index, array) => {
|
|
790
822
|
code += indent(state.tabSize + 1);
|
|
@@ -821,7 +853,7 @@ export class CallQueryComponent extends LogicItem {
|
|
|
821
853
|
});
|
|
822
854
|
|
|
823
855
|
// 分组属性(Group by)
|
|
824
|
-
code = this.toEmbeddedTSOfSubPart('GROUP_BY', this.groupBy
|
|
856
|
+
code = this.toEmbeddedTSOfSubPart('GROUP_BY', this.groupBy, {
|
|
825
857
|
code,
|
|
826
858
|
state,
|
|
827
859
|
});
|
|
@@ -851,70 +883,242 @@ export class CallQueryComponent extends LogicItem {
|
|
|
851
883
|
return code;
|
|
852
884
|
}
|
|
853
885
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
886
|
+
genPropertyListOfFrom(node: QueryFromExpression | QueryJoinExpression, entities: any[] = []) {
|
|
887
|
+
if (!node)
|
|
888
|
+
return [];
|
|
889
|
+
|
|
890
|
+
const entityName = node.entityName;
|
|
891
|
+
entities.push({
|
|
892
|
+
concept: 'StructureProperty',
|
|
893
|
+
name: utils.firstLowerCase(entityName),
|
|
894
|
+
typeAnnotation: {
|
|
895
|
+
concept: 'TypeAnnotation',
|
|
896
|
+
typeKind: 'reference',
|
|
897
|
+
typeName: entityName,
|
|
898
|
+
typeNamespace: `${this.app.getNamespace()}.entities`,
|
|
899
|
+
},
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
for (const sub of node.joinParts) {
|
|
903
|
+
this.genPropertyListOfFrom(sub, entities);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
return entities;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
genPropertyListOfAggregate(node: CallQueryComponent) {
|
|
910
|
+
return node.select.selectElements
|
|
911
|
+
.filter((item) => item.aggregateName && item.asName)
|
|
912
|
+
.map((item) => {
|
|
913
|
+
let typeName;
|
|
914
|
+
if (['COUNT', 'COUNTD'].includes(item.aggregateName)) {
|
|
915
|
+
typeName = 'Integer';
|
|
916
|
+
} else if (['AVG'].includes(item.aggregateName)) {
|
|
917
|
+
typeName = 'Double';
|
|
918
|
+
} else {
|
|
919
|
+
const { entityAsName, propertyName } = item.aggregateParam;
|
|
920
|
+
const entity = this.app.entities.find((item: Entity) => item.name === entityAsName);
|
|
921
|
+
const property = entity?.properties.find((item) => item.name === propertyName);
|
|
922
|
+
typeName = property?.typeAnnotation.typeName;
|
|
923
|
+
}
|
|
924
|
+
return {
|
|
925
|
+
concept: 'StructureProperty',
|
|
926
|
+
name: item.asName,
|
|
927
|
+
typeAnnotation: {
|
|
928
|
+
concept: 'TypeAnnotation',
|
|
929
|
+
typeKind: 'primitive',
|
|
930
|
+
typeNamespace: 'nasl.core',
|
|
931
|
+
typeName,
|
|
932
|
+
},
|
|
933
|
+
};
|
|
870
934
|
});
|
|
935
|
+
}
|
|
871
936
|
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
937
|
+
genPropertyListOfGroupBy(node: CallQueryComponent) {
|
|
938
|
+
return node.groupBy
|
|
939
|
+
.filter((item) => item.groupElement && (item.groupElement as QueryFieldExpression).propertyName && (item.groupElement as QueryFieldExpression).asName)
|
|
940
|
+
.map((item) => {
|
|
941
|
+
const { entityAsName, propertyName, asName } = item.groupElement as QueryFieldExpression;
|
|
942
|
+
const entity = this.app.entities.find((item: Entity) => item.name === entityAsName);
|
|
943
|
+
const property = entity?.properties.find((item) => item.name === propertyName);
|
|
944
|
+
const typeName = property?.typeAnnotation.typeName;
|
|
945
|
+
return {
|
|
946
|
+
concept: 'StructureProperty',
|
|
947
|
+
name: asName,
|
|
948
|
+
typeAnnotation: {
|
|
949
|
+
concept: 'TypeAnnotation',
|
|
950
|
+
typeKind: 'primitive',
|
|
951
|
+
typeName,
|
|
952
|
+
typeNamespace: 'nasl.core',
|
|
953
|
+
},
|
|
954
|
+
};
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
genStructure(structureName?: string, properties: any[] = []) {
|
|
959
|
+
return Structure.from({
|
|
960
|
+
concept: 'Structure',
|
|
961
|
+
name: structureName || this.typeAnnotation?.typeName || `${utils.firstUpperCase(this.logic.name)}Structure`,
|
|
962
|
+
origin: 'CallQueryComponent',
|
|
963
|
+
properties,
|
|
964
|
+
});
|
|
965
|
+
}
|
|
875
966
|
|
|
876
|
-
|
|
967
|
+
saveStructure() {
|
|
968
|
+
// 没有数据源时不初始化数据结构
|
|
969
|
+
if (!this.entityNames.length) {
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
if (!this.isAutoInfer()) {
|
|
974
|
+
// 存量应用走之前的逻辑
|
|
975
|
+
return this.saveStructureNoInfer();
|
|
877
976
|
}
|
|
878
977
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
978
|
+
const groupBy = this.groupBy;
|
|
979
|
+
const selectElements = this.select.selectElements;
|
|
980
|
+
let structureName;
|
|
981
|
+
let typeAnnotation;
|
|
982
|
+
|
|
983
|
+
// Structures
|
|
984
|
+
if (this.typeAnnotation) {
|
|
985
|
+
const { typeNamespace, typeName, typeArguments } = this.typeAnnotation;
|
|
986
|
+
if (typeNamespace === 'app.structures') {
|
|
987
|
+
structureName = typeName;
|
|
988
|
+
this.removeStructure(structureName);
|
|
989
|
+
} else if (typeNamespace === 'nasl.collection' && typeName === 'PageOf') {
|
|
990
|
+
// PageOf<Structures>
|
|
991
|
+
if (typeArguments[0].typeNamespace === 'app.structures') {
|
|
992
|
+
structureName = typeArguments[0].typeName;
|
|
993
|
+
this.removeStructure(structureName);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
structureName = structureName || utils.unique(`${utils.firstUpperCase(this.logic.name)}Structure`, this.app.getStructureExistingNames());
|
|
999
|
+
const groupByLength = groupBy.filter((item) => (item.groupElement as QueryFieldExpression)?.propertyName && (item.groupElement as QueryFieldExpression).asName).length;
|
|
1000
|
+
const aggregateLength = selectElements.filter((item) => item.aggregateName && item.asName).length;
|
|
1001
|
+
|
|
1002
|
+
// 1. 有分组
|
|
1003
|
+
if (groupByLength) {
|
|
1004
|
+
if (!aggregateLength && groupByLength === 1) {
|
|
1005
|
+
// 1.1 单分组无聚合:`PageOf<列的类型>`
|
|
1006
|
+
const { entityAsName, propertyName } = groupBy[0].groupElement as any;
|
|
1007
|
+
const entity = this.app.entities.find((item: Entity) => item.name === entityAsName);
|
|
1008
|
+
const property = entity?.properties.find((item) => item.name === propertyName);
|
|
1009
|
+
const typeName = property?.typeAnnotation.typeName;
|
|
1010
|
+
|
|
1011
|
+
typeAnnotation = TypeAnnotation.from({
|
|
1012
|
+
text: `PageOf<${typeName}>`,
|
|
1013
|
+
concept: 'TypeAnnotation',
|
|
1014
|
+
typeKind: 'generic',
|
|
1015
|
+
typeName: 'PageOf',
|
|
1016
|
+
typeNamespace: `nasl.collection`,
|
|
1017
|
+
typeArguments: [
|
|
1018
|
+
TypeAnnotation.from({
|
|
1019
|
+
concept: 'TypeAnnotation',
|
|
1020
|
+
typeKind: 'primitive',
|
|
1021
|
+
typeName,
|
|
1022
|
+
typeNamespace: 'nasl.core',
|
|
1023
|
+
}, this.typeAnnotation, 'typeAnnotation'),
|
|
1024
|
+
],
|
|
1025
|
+
}, this, 'typeAnnotation');
|
|
1026
|
+
} else {
|
|
1027
|
+
// 1.2 多分组:`PageOf<Structure>`
|
|
1028
|
+
const structure = this.genStructure(structureName, [
|
|
1029
|
+
...this.genPropertyListOfGroupBy(this),
|
|
1030
|
+
...this.genPropertyListOfAggregate(this),
|
|
1031
|
+
]);
|
|
1032
|
+
this.app.addStructure(structure);
|
|
1033
|
+
|
|
1034
|
+
typeAnnotation = TypeAnnotation.from({
|
|
1035
|
+
text: `PageOf<${structureName}>`,
|
|
1036
|
+
concept: 'TypeAnnotation',
|
|
1037
|
+
typeKind: 'generic',
|
|
1038
|
+
typeName: 'PageOf',
|
|
1039
|
+
typeNamespace: `nasl.collection`,
|
|
1040
|
+
typeArguments: [
|
|
1041
|
+
TypeAnnotation.from({
|
|
1042
|
+
concept: 'TypeAnnotation',
|
|
1043
|
+
typeKind: 'reference',
|
|
1044
|
+
typeName: structureName,
|
|
1045
|
+
typeNamespace: 'app.structures',
|
|
1046
|
+
}, this.typeAnnotation, 'typeAnnotation'),
|
|
1047
|
+
],
|
|
1048
|
+
}, this, 'typeAnnotation');
|
|
1049
|
+
}
|
|
1050
|
+
} else { // 2. 无分组
|
|
1051
|
+
if (aggregateLength) {
|
|
1052
|
+
if (aggregateLength === 1) {
|
|
1053
|
+
// 2.1 单聚合:`基本类型`
|
|
883
1054
|
let typeName;
|
|
884
|
-
if (['COUNT', 'COUNTD'].includes(
|
|
1055
|
+
if (['COUNT', 'COUNTD'].includes(selectElements[0].aggregateName)) {
|
|
1056
|
+
// 2.1.1. `COUNT`、`COUNTD` 返回 `Integer`
|
|
885
1057
|
typeName = 'Integer';
|
|
886
|
-
else {
|
|
887
|
-
|
|
888
|
-
|
|
1058
|
+
} else if (['AVG'].includes(selectElements[0].aggregateName)) {
|
|
1059
|
+
// 2.1.2. `AVG` 返回 `Double`
|
|
1060
|
+
typeName = 'Double';
|
|
1061
|
+
} else {
|
|
1062
|
+
// 2.1.3. 其他返回列类型,包含:`Integer`、`Long`、`Double`
|
|
1063
|
+
const { entityAsName, propertyName } = selectElements[0].aggregateParam;
|
|
1064
|
+
const entity = this.app.entities.find((item: Entity) => item.name === entityAsName);
|
|
889
1065
|
const property = entity?.properties.find((item) => item.name === propertyName);
|
|
890
1066
|
typeName = property?.typeAnnotation.typeName;
|
|
891
1067
|
}
|
|
892
|
-
|
|
893
|
-
concept: '
|
|
894
|
-
|
|
895
|
-
|
|
1068
|
+
typeAnnotation = TypeAnnotation.from({
|
|
1069
|
+
concept: 'TypeAnnotation',
|
|
1070
|
+
typeKind: 'primitive',
|
|
1071
|
+
typeName,
|
|
1072
|
+
typeNamespace: 'nasl.core',
|
|
1073
|
+
}, this, 'typeAnnotation');
|
|
1074
|
+
} else {
|
|
1075
|
+
// 2.2. 多聚合:`Structure`(自动创建 `Structure`)
|
|
1076
|
+
const structure = this.genStructure(structureName, [
|
|
1077
|
+
...this.genPropertyListOfAggregate(this),
|
|
1078
|
+
]);
|
|
1079
|
+
this.app.addStructure(structure);
|
|
1080
|
+
|
|
1081
|
+
typeAnnotation = TypeAnnotation.from({
|
|
1082
|
+
concept: 'TypeAnnotation',
|
|
1083
|
+
typeKind: 'reference',
|
|
1084
|
+
typeName: structureName,
|
|
1085
|
+
typeNamespace: `app.structures`,
|
|
1086
|
+
}, this, 'typeAnnotation');
|
|
1087
|
+
}
|
|
1088
|
+
} else {
|
|
1089
|
+
// 2.3. 无聚合(默认情况):`PageOf<Structure>`(自动创建 `Structure`)
|
|
1090
|
+
const structure = this.genStructure(structureName, [
|
|
1091
|
+
...this.genPropertyListOfFrom(this.from),
|
|
1092
|
+
...this.genPropertyListOfAggregate(this),
|
|
1093
|
+
]);
|
|
1094
|
+
this.app.addStructure(structure);
|
|
1095
|
+
|
|
1096
|
+
typeAnnotation = TypeAnnotation.from({
|
|
1097
|
+
text: structureName,
|
|
1098
|
+
concept: 'TypeAnnotation',
|
|
1099
|
+
typeKind: 'generic',
|
|
1100
|
+
typeName: 'PageOf',
|
|
1101
|
+
typeNamespace: `nasl.collection`,
|
|
1102
|
+
typeArguments: [
|
|
1103
|
+
TypeAnnotation.from({
|
|
896
1104
|
concept: 'TypeAnnotation',
|
|
897
|
-
typeKind: '
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
},
|
|
901
|
-
|
|
902
|
-
});
|
|
1105
|
+
typeKind: 'reference',
|
|
1106
|
+
typeName: structureName,
|
|
1107
|
+
typeNamespace: 'app.structures',
|
|
1108
|
+
}, this.typeAnnotation, 'typeAnnotation'),
|
|
1109
|
+
],
|
|
1110
|
+
}, this, 'typeAnnotation');
|
|
1111
|
+
}
|
|
903
1112
|
}
|
|
904
1113
|
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
return Structure.from({
|
|
908
|
-
concept: 'Structure',
|
|
909
|
-
name: structureName,
|
|
910
|
-
origin: 'CallQueryComponent',
|
|
911
|
-
properties: [...genPropertyListOfFrom(this.from), ...genPropertyListOfAggregate(this)],
|
|
912
|
-
});
|
|
1114
|
+
this.update({ typeAnnotation });
|
|
913
1115
|
}
|
|
914
1116
|
|
|
915
|
-
|
|
916
|
-
const source = this.genStructure(
|
|
917
|
-
|
|
1117
|
+
saveStructureNoInfer() {
|
|
1118
|
+
const source = this.genStructure(null, [
|
|
1119
|
+
...this.genPropertyListOfFrom(this.from),
|
|
1120
|
+
...this.genPropertyListOfAggregate(this),
|
|
1121
|
+
]);
|
|
918
1122
|
if (this.typeAnnotation) {
|
|
919
1123
|
const structure = this.app.structures.find((item) => item.name === this.typeAnnotation.typeName);
|
|
920
1124
|
if (structure) {
|
|
@@ -939,9 +1143,22 @@ export class CallQueryComponent extends LogicItem {
|
|
|
939
1143
|
}
|
|
940
1144
|
}
|
|
941
1145
|
|
|
942
|
-
removeStructure() {
|
|
1146
|
+
removeStructure(structureName?: string) {
|
|
943
1147
|
try {
|
|
944
|
-
|
|
1148
|
+
if (this.typeAnnotation) {
|
|
1149
|
+
const { typeNamespace, typeName, typeArguments } = this.typeAnnotation;
|
|
1150
|
+
if (typeNamespace === 'app.structures') {
|
|
1151
|
+
// Structures
|
|
1152
|
+
structureName = typeName;
|
|
1153
|
+
this.app.removeStructure(structureName);
|
|
1154
|
+
} else if (typeNamespace === 'nasl.collection' && typeName === 'PageOf') {
|
|
1155
|
+
// PageOf<Structures>
|
|
1156
|
+
if (typeArguments[0].typeNamespace === 'app.structures') {
|
|
1157
|
+
structureName = typeArguments[0].typeName;
|
|
1158
|
+
this.app.removeStructure(structureName);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
945
1162
|
} catch {}
|
|
946
1163
|
}
|
|
947
1164
|
|
|
@@ -1017,6 +1234,29 @@ export class CallQueryComponent extends LogicItem {
|
|
|
1017
1234
|
return { name: '聚合属性别名', icon: 'category', children, expanded: true };
|
|
1018
1235
|
}
|
|
1019
1236
|
|
|
1237
|
+
getCompletionPropertyOfGroupByAsNames() {
|
|
1238
|
+
const children = this.groupBy
|
|
1239
|
+
?.filter((item) => item.concept === 'QueryGroupByExpression' && (item.groupElement as QueryFieldExpression)?.asName)
|
|
1240
|
+
.map((item) =>
|
|
1241
|
+
new CompletionProperty({
|
|
1242
|
+
concept: 'CompletionProperty',
|
|
1243
|
+
name: (item.groupElement as QueryFieldExpression).asName,
|
|
1244
|
+
value: `inner.${(item.groupElement as QueryFieldExpression).asName}`,
|
|
1245
|
+
expression: LogicItem.from({
|
|
1246
|
+
concept: 'Identifier',
|
|
1247
|
+
name: (item.groupElement as QueryFieldExpression).asName,
|
|
1248
|
+
namespace: 'inner',
|
|
1249
|
+
}),
|
|
1250
|
+
}));
|
|
1251
|
+
if (!children || children.length === 0)
|
|
1252
|
+
return;
|
|
1253
|
+
|
|
1254
|
+
children.forEach((item) => {
|
|
1255
|
+
item.icon = 'variable';
|
|
1256
|
+
});
|
|
1257
|
+
return { name: '分组属性别名', icon: 'category', children, expanded: true };
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1020
1260
|
//================================================================================
|
|
1021
1261
|
// 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
|
|
1022
1262
|
// ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
|
|
@@ -230,9 +230,9 @@ export class Constant extends BaseNode {
|
|
|
230
230
|
code += ': ';
|
|
231
231
|
code += this.typeAnnotation.toEmbeddedTS(shiftState(state, code));
|
|
232
232
|
}
|
|
233
|
-
if (this.defaultValue) {
|
|
234
|
-
|
|
235
|
-
}
|
|
233
|
+
// if (this.defaultValue) {
|
|
234
|
+
// code += ` = ${this.defaultValue}`;
|
|
235
|
+
// }
|
|
236
236
|
return code;
|
|
237
237
|
}
|
|
238
238
|
@withSourceMap()
|
|
@@ -242,9 +242,9 @@ export class Constant extends BaseNode {
|
|
|
242
242
|
code += ': undefined as ';
|
|
243
243
|
code += this.typeAnnotation.toEmbeddedTS(shiftState(state, code));
|
|
244
244
|
}
|
|
245
|
-
if (this.defaultValue) {
|
|
246
|
-
|
|
247
|
-
}
|
|
245
|
+
// if (this.defaultValue) {
|
|
246
|
+
// code += ` : ${this.defaultValue}`;
|
|
247
|
+
// }
|
|
248
248
|
return code;
|
|
249
249
|
}
|
|
250
250
|
//================================================================================
|
|
@@ -52,8 +52,6 @@ export class Destination extends LogicItem {
|
|
|
52
52
|
@property('Argument')
|
|
53
53
|
arguments: Array<Argument> = [];
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
55
|
/**
|
|
58
56
|
* @param source 需要合并的部分参数
|
|
59
57
|
*/
|
|
@@ -67,7 +65,6 @@ export class Destination extends LogicItem {
|
|
|
67
65
|
return super.from(source, parentNode, parentKey) as Destination;
|
|
68
66
|
}
|
|
69
67
|
|
|
70
|
-
|
|
71
68
|
/**
|
|
72
69
|
* 设置viewNamespace
|
|
73
70
|
*/
|
|
@@ -92,10 +89,6 @@ export class Destination extends LogicItem {
|
|
|
92
89
|
});
|
|
93
90
|
}
|
|
94
91
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
92
|
/**
|
|
100
93
|
* 插入实际参数
|
|
101
94
|
* @internal
|
|
@@ -128,8 +121,6 @@ export class Destination extends LogicItem {
|
|
|
128
121
|
return argument;
|
|
129
122
|
}
|
|
130
123
|
|
|
131
|
-
|
|
132
|
-
|
|
133
124
|
/**
|
|
134
125
|
* 插入实际参数
|
|
135
126
|
* @param argumentOptions 实际参数参数
|
|
@@ -152,8 +143,6 @@ export class Destination extends LogicItem {
|
|
|
152
143
|
return node;
|
|
153
144
|
}
|
|
154
145
|
|
|
155
|
-
|
|
156
|
-
|
|
157
146
|
/**
|
|
158
147
|
* 添加实际参数
|
|
159
148
|
* @internal
|
|
@@ -173,8 +162,6 @@ export class Destination extends LogicItem {
|
|
|
173
162
|
return this._insertArgumentAt(options as any, index);
|
|
174
163
|
}
|
|
175
164
|
|
|
176
|
-
|
|
177
|
-
|
|
178
165
|
/**
|
|
179
166
|
* 添加实际参数
|
|
180
167
|
* @param argumentOptions 实际参数参数
|
|
@@ -198,9 +185,6 @@ export class Destination extends LogicItem {
|
|
|
198
185
|
return node;
|
|
199
186
|
}
|
|
200
187
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
188
|
/**
|
|
205
189
|
* 删除实际参数
|
|
206
190
|
* @param argument 已有的实际参数实例
|
|
@@ -208,7 +192,7 @@ export class Destination extends LogicItem {
|
|
|
208
192
|
removeArgument(argument: Argument): void;
|
|
209
193
|
|
|
210
194
|
removeArgument(options: Argument) {
|
|
211
|
-
|
|
195
|
+
const argument: Argument = options;
|
|
212
196
|
return argument.delete();
|
|
213
197
|
}
|
|
214
198
|
|
|
@@ -281,7 +265,14 @@ export class Destination extends LogicItem {
|
|
|
281
265
|
url += ':destination="`';
|
|
282
266
|
url += `/${viewArr.join('/')}`;
|
|
283
267
|
if (Array.isArray(this.arguments) && this.arguments.length) {
|
|
284
|
-
const args = this.arguments
|
|
268
|
+
const args = this.arguments.map((arg) => {
|
|
269
|
+
const value = arg?.toVue();
|
|
270
|
+
let argStr = '';
|
|
271
|
+
if (value) {
|
|
272
|
+
argStr += `${arg.keyword}=` + '${' + `${value}` + '}';
|
|
273
|
+
}
|
|
274
|
+
return argStr;
|
|
275
|
+
}).filter((arg) => !!arg);
|
|
285
276
|
url += `?${args.join('&')}`;
|
|
286
277
|
}
|
|
287
278
|
url += '`"';
|
|
@@ -311,7 +302,14 @@ export class Destination extends LogicItem {
|
|
|
311
302
|
url += 'this.$destination(`';
|
|
312
303
|
url += `/${viewArr.join('/')}`;
|
|
313
304
|
if (Array.isArray(this.arguments) && this.arguments.length) {
|
|
314
|
-
const args = this.arguments.map((arg) =>
|
|
305
|
+
const args = this.arguments.map((arg) => {
|
|
306
|
+
const value = arg?.toJS();
|
|
307
|
+
let argStr = '';
|
|
308
|
+
if (value) {
|
|
309
|
+
argStr += `${arg.keyword}=` + '${' + `${value}` + '}';
|
|
310
|
+
}
|
|
311
|
+
return argStr;
|
|
312
|
+
}).filter((arg) => !!arg);
|
|
315
313
|
url += `?${args.join('&')}`;
|
|
316
314
|
}
|
|
317
315
|
url += '`)';
|
|
@@ -466,7 +464,7 @@ export class Destination extends LogicItem {
|
|
|
466
464
|
//================================================================================
|
|
467
465
|
}
|
|
468
466
|
|
|
469
|
-
classMap
|
|
467
|
+
classMap.Destination = Destination;
|
|
470
468
|
export default Destination;
|
|
471
469
|
//================================================================================
|
|
472
470
|
// ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
|
|
@@ -177,7 +177,8 @@ export class EntityIndex extends BaseNode {
|
|
|
177
177
|
*/
|
|
178
178
|
moveUp() {
|
|
179
179
|
const indexes = [...(this.parentNode as Entity).indexes];
|
|
180
|
-
const
|
|
180
|
+
const indexesNameList = indexes.map((item) => item.name);
|
|
181
|
+
const oldIndex = indexesNameList.indexOf(this.name);
|
|
181
182
|
this.changeSort(indexes, oldIndex, 'up');
|
|
182
183
|
this.parentNode.update({
|
|
183
184
|
indexes,
|
|
@@ -188,7 +189,8 @@ export class EntityIndex extends BaseNode {
|
|
|
188
189
|
*/
|
|
189
190
|
moveDown() {
|
|
190
191
|
const indexes = [...(this.parentNode as Entity).indexes];
|
|
191
|
-
const
|
|
192
|
+
const indexesNameList = indexes.map((item) => item.name);
|
|
193
|
+
const oldIndex = indexesNameList.indexOf(this.name);
|
|
192
194
|
this.changeSort(indexes, oldIndex, 'down');
|
|
193
195
|
this.parentNode.update({
|
|
194
196
|
indexes,
|
|
@@ -369,11 +369,9 @@ export class EntityProperty extends BaseNode {
|
|
|
369
369
|
completionChildren = properties;
|
|
370
370
|
}
|
|
371
371
|
} else if (typeKind === 'generic') {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
completionChildren = properties;
|
|
376
|
-
}
|
|
372
|
+
const node = getNaslNodeByNodeCallee(typeNamespace, typeName);
|
|
373
|
+
const properties = node.properties || [];
|
|
374
|
+
completionChildren = properties;
|
|
377
375
|
} else {
|
|
378
376
|
completionChildren = undefined;
|
|
379
377
|
}
|
package/src/concepts/Entity__.ts
CHANGED
|
@@ -107,7 +107,6 @@ export class Entity extends BaseNode {
|
|
|
107
107
|
}
|
|
108
108
|
return params;
|
|
109
109
|
}
|
|
110
|
-
|
|
111
110
|
/**
|
|
112
111
|
* 设置实体描述
|
|
113
112
|
*/
|
|
@@ -120,7 +119,7 @@ export class Entity extends BaseNode {
|
|
|
120
119
|
});
|
|
121
120
|
}
|
|
122
121
|
|
|
123
|
-
|
|
122
|
+
getPropertyExistingNames(excludedList: Array<EntityProperty> = []) {
|
|
124
123
|
const excludedSet = new Set(excludedList);
|
|
125
124
|
return (this.properties || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
|
|
126
125
|
}
|
|
@@ -261,6 +260,7 @@ export class Entity extends BaseNode {
|
|
|
261
260
|
return node;
|
|
262
261
|
}
|
|
263
262
|
|
|
263
|
+
|
|
264
264
|
getEntityIndexExistingNames(excludedList: Array<EntityIndex> = []) {
|
|
265
265
|
const excludedSet = new Set(excludedList);
|
|
266
266
|
return (this.indexes || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
|
|
@@ -402,6 +402,9 @@ export class Entity extends BaseNode {
|
|
|
402
402
|
return node;
|
|
403
403
|
}
|
|
404
404
|
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
405
408
|
/**
|
|
406
409
|
* 删除实体字段
|
|
407
410
|
* @param name 实体字段名称
|
|
@@ -450,6 +453,8 @@ export class Entity extends BaseNode {
|
|
|
450
453
|
return params;
|
|
451
454
|
}
|
|
452
455
|
|
|
456
|
+
|
|
457
|
+
|
|
453
458
|
/**
|
|
454
459
|
* 删除实体索引
|
|
455
460
|
* @param name 实体索引名称
|
|
@@ -503,6 +508,13 @@ export class Entity extends BaseNode {
|
|
|
503
508
|
// 自动生成的代码已结束。下面可以手动编写。
|
|
504
509
|
//================================================================================
|
|
505
510
|
|
|
511
|
+
getPropertyExistingNameList(excludedList: Array<EntityProperty> = []) {
|
|
512
|
+
const excludedSet = Array.from(new Set(excludedList));
|
|
513
|
+
const namelist = excludedSet.map((item) => item.name);
|
|
514
|
+
console.log(namelist);
|
|
515
|
+
|
|
516
|
+
return (this.properties || []).filter((item) => !namelist.includes(item.name)).map((item) => item.name);
|
|
517
|
+
}
|
|
506
518
|
/**
|
|
507
519
|
* 设置实体表名并修改表名
|
|
508
520
|
*/
|
|
@@ -716,7 +728,7 @@ export class Entity extends BaseNode {
|
|
|
716
728
|
//================================================================================
|
|
717
729
|
}
|
|
718
730
|
|
|
719
|
-
classMap
|
|
731
|
+
classMap['Entity'] = Entity;
|
|
720
732
|
export default Entity;
|
|
721
733
|
//================================================================================
|
|
722
734
|
// ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
|