@lcap/nasl 2.18.0 → 2.20.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/automate/engine/index.js +3 -3
- package/out/automate/engine/index.js.map +1 -1
- package/out/bak/translator.js +85 -37
- package/out/bak/translator.js.map +1 -1
- package/out/common/BaseNode.d.ts +6 -10
- package/out/common/BaseNode.js +7 -52
- package/out/common/BaseNode.js.map +1 -1
- package/out/concepts/AnonymousFunction__.js.map +1 -1
- package/out/concepts/App__.d.ts +0 -10
- package/out/concepts/App__.js +0 -74
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/Assignee__.js.map +1 -1
- package/out/concepts/AssignmentLine__.d.ts +5 -5
- package/out/concepts/AssignmentLine__.js +6 -6
- package/out/concepts/AssignmentLine__.js.map +1 -1
- package/out/concepts/Assignment__.js +2 -1
- package/out/concepts/Assignment__.js.map +1 -1
- package/out/concepts/BatchAssignment__.d.ts +60 -60
- package/out/concepts/BatchAssignment__.js +11 -21
- package/out/concepts/BatchAssignment__.js.map +1 -1
- package/out/concepts/BindAttribute__.d.ts +0 -19
- package/out/concepts/BindAttribute__.js +2 -39
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindEvent__.js.map +1 -1
- package/out/concepts/BindStyle__.d.ts +2 -2
- package/out/concepts/BindStyle__.js +3 -3
- package/out/concepts/BindStyle__.js.map +1 -1
- package/out/concepts/BooleanLiteral__.js +8 -0
- package/out/concepts/BooleanLiteral__.js.map +1 -1
- package/out/concepts/CallFunction__.js +25 -58
- package/out/concepts/CallFunction__.js.map +1 -1
- package/out/concepts/CallInterface__.d.ts +0 -7
- package/out/concepts/CallInterface__.js +7 -53
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.js +14 -63
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.js +1 -13
- package/out/concepts/CallQueryComponent__.js.map +1 -1
- package/out/concepts/CompletionProperty__.js +0 -3
- package/out/concepts/CompletionProperty__.js.map +1 -1
- package/out/concepts/ConfigGroup__.js.map +1 -1
- package/out/concepts/ConfigProperty__.js.map +1 -1
- package/out/concepts/Configuration__.js.map +1 -1
- package/out/concepts/DataSource__.d.ts +0 -6
- package/out/concepts/DataSource__.js +0 -41
- package/out/concepts/DataSource__.js.map +1 -1
- package/out/concepts/Destination__.d.ts +1 -9
- package/out/concepts/Destination__.js +29 -61
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/EntityProperty__.d.ts +8 -21
- package/out/concepts/EntityProperty__.js +23 -109
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/Entity__.d.ts +0 -32
- package/out/concepts/Entity__.js +2 -117
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/Enum__.js +4 -0
- package/out/concepts/Enum__.js.map +1 -1
- package/out/concepts/Event__.js.map +1 -1
- package/out/concepts/ForEachStatement__.d.ts +4 -0
- package/out/concepts/ForEachStatement__.js +8 -4
- package/out/concepts/ForEachStatement__.js.map +1 -1
- package/out/concepts/Function__.js.map +1 -1
- package/out/concepts/Identifier__.js +4 -16
- package/out/concepts/Identifier__.js.map +1 -1
- package/out/concepts/IfStatement__.d.ts +0 -8
- package/out/concepts/IfStatement__.js +0 -22
- package/out/concepts/IfStatement__.js.map +1 -1
- package/out/concepts/InterfaceParam__.js.map +1 -1
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/LogicItem__.d.ts +1 -1
- package/out/concepts/LogicItem__.js.map +1 -1
- package/out/concepts/Logic__.d.ts +1 -6
- package/out/concepts/Logic__.js +43 -144
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MatchCase__.d.ts +1 -1
- package/out/concepts/MatchCase__.js +8 -15
- package/out/concepts/MatchCase__.js.map +1 -1
- package/out/concepts/Match__.d.ts +19 -21
- package/out/concepts/Match__.js +25 -112
- package/out/concepts/Match__.js.map +1 -1
- package/out/concepts/MemberExpression__.d.ts +1 -4
- package/out/concepts/MemberExpression__.js +15 -30
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/Module__.js.map +1 -1
- package/out/concepts/Namespace__.js.map +1 -1
- package/out/concepts/NumericLiteral__.js +1 -1
- package/out/concepts/NumericLiteral__.js.map +1 -1
- package/out/concepts/OqlQueryComponent__.d.ts +3 -7
- package/out/concepts/OqlQueryComponent__.js +95 -56
- package/out/concepts/OqlQueryComponent__.js.map +1 -1
- package/out/concepts/Param__.d.ts +1 -1
- package/out/concepts/Param__.js +4 -40
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/ProcessComponent__.js.map +1 -1
- package/out/concepts/ProcessElement__.js.map +1 -1
- package/out/concepts/Process__.js.map +1 -1
- package/out/concepts/QueryJoinExpression__.js.map +1 -1
- package/out/concepts/QueryOrderByExpression__.d.ts +3 -3
- package/out/concepts/QueryOrderByExpression__.js +3 -3
- package/out/concepts/QueryOrderByExpression__.js.map +1 -1
- package/out/concepts/QuerySelectExpression__.js.map +1 -1
- package/out/concepts/Return__.js +2 -38
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/SelectMembers__.d.ts +1 -1
- package/out/concepts/SelectMembers__.js +2 -2
- package/out/concepts/SelectMembers__.js.map +1 -1
- package/out/concepts/SqlQueryComponent__.d.ts +4 -2
- package/out/concepts/SqlQueryComponent__.js +88 -9
- package/out/concepts/SqlQueryComponent__.js.map +1 -1
- package/out/concepts/StringLiteral__.js +7 -0
- package/out/concepts/StringLiteral__.js.map +1 -1
- package/out/concepts/StructureProperty__.js.map +1 -1
- package/out/concepts/Structure__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.d.ts +0 -1
- package/out/concepts/TypeAnnotation__.js +12 -25
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/TypeParam__.d.ts +0 -1
- package/out/concepts/TypeParam__.js +0 -2
- package/out/concepts/TypeParam__.js.map +1 -1
- package/out/concepts/UnaryExpression__.js +9 -6
- package/out/concepts/UnaryExpression__.js.map +1 -1
- package/out/concepts/ValidationRule__.js +23 -88
- package/out/concepts/ValidationRule__.js.map +1 -1
- package/out/concepts/Variable__.js +2 -38
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewComponent__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +29 -30
- package/out/concepts/ViewElement__.js +51 -117
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.d.ts +3 -4
- package/out/concepts/View__.js +83 -93
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/WhileStatement__.js +1 -1
- package/out/concepts/WhileStatement__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.browser.js +0 -50
- package/out/concepts/basics/stdlib/nasl.browser.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.ui.js +4 -36
- package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.util.js +43 -63
- package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
- package/out/concepts/index__.d.ts +0 -2
- package/out/concepts/index__.js +0 -2
- package/out/concepts/index__.js.map +1 -1
- package/out/generator/genBundleFiles.d.ts +2 -5
- package/out/generator/genBundleFiles.js +45 -148
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/index.d.ts +0 -1
- package/out/generator/index.js +0 -1
- package/out/generator/index.js.map +1 -1
- package/out/index.d.ts +2 -3
- package/out/index.js +1 -5
- package/out/index.js.map +1 -1
- package/out/server/entity2LogicNamespace.js +11 -11
- package/out/server/entity2LogicNamespace.js.map +1 -1
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/formatTsUtils.js +17 -10
- package/out/server/formatTsUtils.js.map +1 -1
- package/out/server/getLogics.js +6 -13
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.js +7 -7
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/getProcesses.d.ts +1 -1
- package/out/server/index.d.ts +1 -0
- package/out/server/index.js +27 -2
- package/out/server/index.js.map +1 -1
- package/out/server/naslServer.d.ts +7 -47
- package/out/server/naslServer.js +393 -591
- package/out/server/naslServer.js.map +1 -1
- package/out/server/naslStdlibMap.js +28 -30
- package/out/server/naslStdlibMap.js.map +1 -1
- package/out/server/translator.js +7 -40
- package/out/server/translator.js.map +1 -1
- package/out/service/storage/init.js +3 -33
- package/out/service/storage/init.js.map +1 -1
- package/out/templator/genCreateBlock.js +4 -6
- package/out/templator/genCreateBlock.js.map +1 -1
- package/out/templator/genCurdEditMultipleKeyBlock.js +4 -7
- package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
- package/out/templator/genCurdMultipleKeyBlock.js +5 -7
- package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
- package/out/templator/genEnumSelectBlock.js +2 -5
- package/out/templator/genEnumSelectBlock.js.map +1 -1
- package/out/templator/genGridViewBlock.js +2 -2
- package/out/templator/genGridViewBlock.js.map +1 -1
- package/out/templator/genListViewBlock.js +2 -2
- package/out/templator/genListViewBlock.js.map +1 -1
- package/out/templator/genQueryComponent.d.ts +2 -2
- package/out/templator/genQueryComponent.js +1 -4
- package/out/templator/genQueryComponent.js.map +1 -1
- package/out/templator/genTableBlock.js +2 -2
- package/out/templator/genTableBlock.js.map +1 -1
- package/out/templator/genUpdateBlock.js +3 -4
- package/out/templator/genUpdateBlock.js.map +1 -1
- package/out/templator/utils.js +1 -1
- package/out/templator/utils.js.map +1 -1
- package/out/test/integration/node-nasl-server.js +38 -10
- package/out/test/integration/node-nasl-server.js.map +1 -1
- package/out/translator/index.d.ts +0 -1
- package/out/translator/index.js +1 -1
- package/out/translator/index.js.map +1 -1
- package/out/utils/index.d.ts +0 -1
- package/out/utils/index.js +1 -38
- package/out/utils/index.js.map +1 -1
- package/out/utils/string.d.ts +2 -15
- package/out/utils/string.js +3 -18
- package/out/utils/string.js.map +1 -1
- package/package.json +2 -2
- package/sandbox/stdlib/nasl.auth.ts +1 -1
- package/sandbox/stdlib/nasl.core.ts +1 -0
- package/sandbox/stdlib/nasl.logging.ts +4 -4
- package/sandbox/stdlib/nasl.util.ts +9 -5
- package/src/automate/engine/index.js +4 -4
- package/src/automate/engine/uniqueName.js +3 -3
- package/src/automate/template/myProcess.js +1 -1
- package/src/automate/upgrader/2.20.js +41 -0
- package/src/bak/translator.js +4 -1
- package/src/common/BaseNode.ts +1 -0
- package/src/concepts/AnonymousFunction__.ts +48 -2
- package/src/concepts/App__.ts +288 -615
- package/src/concepts/BatchAssignment__.ts +111 -51
- package/src/concepts/BindAttribute__.ts +18 -25
- package/src/concepts/BindDirective__.ts +7 -0
- package/src/concepts/BindEvent__.ts +7 -0
- package/src/concepts/BindStyle__.ts +7 -0
- package/src/concepts/CallFunction__.ts +34 -45
- package/src/concepts/CallInterface__.ts +2 -1
- package/src/concepts/CallLogic__.ts +87 -55
- package/src/concepts/CallQueryComponent__.ts +4 -1
- package/src/concepts/Constant__.ts +7 -0
- package/src/concepts/DataSource__.ts +57 -5
- package/src/concepts/Destination__.ts +100 -43
- package/src/concepts/Frontend__.ts +937 -0
- package/src/concepts/Identifier__.ts +18 -16
- package/src/concepts/LogicItem__.ts +8 -1
- package/src/concepts/Logic__.ts +134 -149
- package/src/concepts/Match__.ts +13 -29
- package/src/concepts/NewComposite__.ts +1357 -0
- package/src/concepts/NewList__.ts +440 -0
- package/src/concepts/NewMap__.ts +666 -0
- package/src/concepts/New__.ts +73 -0
- package/src/concepts/Param__.ts +245 -199
- package/src/concepts/ProcessElement__.ts +43 -36
- package/src/concepts/ProcessOutcomes__.ts +90 -0
- package/src/concepts/Process__.ts +1 -23
- package/src/concepts/Return__.ts +11 -1
- package/src/concepts/SelectMembers__.ts +3 -3
- package/src/concepts/Transactional__.ts +7 -0
- package/src/concepts/TypeAnnotation__.ts +54 -49
- package/src/concepts/ValidationRule__.ts +19 -1
- package/src/concepts/Variable__.ts +12 -6
- package/src/concepts/ViewElement__.ts +26 -3
- package/src/concepts/View__.ts +25 -25
- package/src/concepts/basics/stdlib/nasl.auth.ts +1 -1
- package/src/concepts/basics/stdlib/nasl.logging.ts +5 -0
- package/src/concepts/basics/stdlib/nasl.ui.ts +2 -0
- package/src/concepts/basics/stdlib/nasl.util.ts +153 -19
- package/src/concepts/index__.ts +7 -0
- package/src/enums/KEYWORDS.ts +9 -0
- package/src/generator/genBundleFiles.ts +74 -245
- package/src/generator/genMetaData.ts +178 -78
- package/src/generator/genReleaseBody.ts +87 -44
- package/src/generator/index.ts +1 -0
- package/src/generator/permission.ts +261 -0
- package/src/index.ts +1 -1
- package/src/server/entity2LogicNamespace.ts +90 -10
- package/src/server/extendBaseNode.ts +33 -22
- package/src/server/formatTsUtils.ts +36 -46
- package/src/server/getLogics.ts +13 -1
- package/src/server/getMemberIdentifier.ts +5 -5
- package/src/server/getProcesses.ts +1 -1
- package/src/server/naslServer.ts +254 -71
- package/src/server/process2LogicNamespace.ts +8 -0
- package/src/server/translator.ts +51 -5
- package/src/service/creator/add.configs.js +4 -0
- package/src/service/datasource/api.js +11 -0
- package/src/service/datasource/index.js +6 -0
- package/src/service/storage/init.ts +12 -0
- package/src/service/video/VideoTranscribe.js +1 -0
- package/src/templator/genEditTableBlock.ts +8 -16
- package/src/templator/genGetBlock.ts +18 -19
- package/src/templator/genGridViewBlock.ts +18 -18
- package/src/templator/genListViewBlock.ts +8 -11
- package/src/templator/genTableBlock.ts +6 -10
- package/ts-worker/lib/tsserver.js +8 -1
- package/out/automate/engine/2.14-components.d.ts +0 -1115
- package/out/automate/engine/2.14-components.js +0 -1087
- package/out/automate/engine/2.14-components.js.map +0 -1
- package/out/concepts/ExternalDestination__.d.ts +0 -73
- package/out/concepts/ExternalDestination__.js +0 -264
- package/out/concepts/ExternalDestination__.js.map +0 -1
- package/out/concepts/MatchExpression__.d.ts +0 -97
- package/out/concepts/MatchExpression__.js +0 -281
- package/out/concepts/MatchExpression__.js.map +0 -1
- package/out/concepts/StringInterpolation__.d.ts +0 -113
- package/out/concepts/StringInterpolation__.js +0 -227
- package/out/concepts/StringInterpolation__.js.map +0 -1
- package/out/generator/genReleaseBody.d.ts +0 -41
- package/out/generator/genReleaseBody.js +0 -340
- package/out/generator/genReleaseBody.js.map +0 -1
- package/out/service/defaultErrorMessage.json +0 -97
- package/out/service/logic/api.d.ts +0 -9
- package/out/service/logic/api.js +0 -11
- package/out/service/logic/api.js.map +0 -1
- package/out/service/logic/index.d.ts +0 -2
- package/out/service/logic/index.js +0 -10
- package/out/service/logic/index.js.map +0 -1
- package/src/automate/engine/dist/index.dev.js +0 -517
- package/src/common/dist/BaseNode.js +0 -1101
- package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +0 -24
- package/src/concepts/dist/Anchor__.js +0 -179
- package/src/concepts/dist/Assignment__.js +0 -301
- package/src/concepts/dist/CallFunction__.js +0 -473
- package/src/concepts/dist/CallInterface__.js +0 -533
- package/src/concepts/dist/CallLogic__.js +0 -864
- package/src/concepts/dist/ForEachStatement__.js +0 -426
- package/src/concepts/dist/MatchCase__.js +0 -587
- package/src/concepts/dist/MemberExpression__.js +0 -348
- package/src/concepts/dist/Param__.js +0 -537
- package/src/concepts/dist/Return__.js +0 -493
- package/src/generator/dist/genBundleFiles.js +0 -414
- package/src/server/dist/formatTsUtils.js +0 -683
- package/src/server/dist/naslServer.js +0 -3396
- package/src/service/storage/dist/init.js +0 -541
- package/ts-worker/dist/webpack.config.dev.js +0 -104
- package/ts-worker/lib/dist/tsserver.dev.js +0 -22953
- package/ts-worker/sources/lib/dist/tsserver.dev.js +0 -22912
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { Logic, View, BaseNode, CallLogic, ViewElement, BindEvent, BindAttribute, App, Entity, Module, Frontend } from '../concepts';
|
|
2
|
+
import { processToTreeFragment } from '@nasl/server/process2LogicNamespace';
|
|
3
|
+
|
|
4
|
+
type Usage = {
|
|
5
|
+
node: BaseNode,
|
|
6
|
+
children?: Usage[],
|
|
7
|
+
}
|
|
8
|
+
type ResourceNode = {
|
|
9
|
+
path: string,
|
|
10
|
+
type: 'component' | 'page',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function isReadOnly(logic: Logic) {
|
|
14
|
+
return !!logic.module
|
|
15
|
+
|| logic.parentNode?.concept === 'Namespace'
|
|
16
|
+
|| logic.parentKey === 'readonly'; // process logic
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const cache = new Map();
|
|
20
|
+
let useCache = false;
|
|
21
|
+
async function findUsage(logic: Logic) {
|
|
22
|
+
if (useCache && cache.has(logic))
|
|
23
|
+
return cache.get(logic);
|
|
24
|
+
|
|
25
|
+
const res = isReadOnly(logic) ? await logic.findReadOnlyLogicUsage() : await logic.findUsage();
|
|
26
|
+
if (useCache)
|
|
27
|
+
cache.set(logic, res);
|
|
28
|
+
return res;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function openCache() {
|
|
32
|
+
useCache = true;
|
|
33
|
+
cache.clear();
|
|
34
|
+
}
|
|
35
|
+
function closeCache() {
|
|
36
|
+
useCache = false;
|
|
37
|
+
cache.clear();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function findViewLogicReferences(logic: Logic, vis: Set<Logic> = new Set()) {
|
|
41
|
+
const usageMap: Map<BaseNode, Usage> = await findUsage(logic);
|
|
42
|
+
const usages: Usage[] = [];
|
|
43
|
+
usageMap.forEach((usage: Usage, node: BaseNode) => {
|
|
44
|
+
if (node instanceof Frontend)
|
|
45
|
+
usages.push(usage);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
async function dfs(usage: Usage) {
|
|
49
|
+
if (usage.node instanceof CallLogic) {
|
|
50
|
+
const logic = usage.node.logic;
|
|
51
|
+
if (!vis.has(logic)) {
|
|
52
|
+
vis.add(logic);
|
|
53
|
+
await findViewLogicReferences(logic, vis);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (usage.children) {
|
|
58
|
+
for (const child of usage.children) {
|
|
59
|
+
await dfs(child);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for (const usage of usages) {
|
|
65
|
+
await dfs(usage);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return Array.from(vis);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function findUIReferences(logic: Logic) {
|
|
72
|
+
const usageMap: Map<BaseNode, Usage> = await findUsage(logic);
|
|
73
|
+
const usages: Usage[] = [];
|
|
74
|
+
usageMap.forEach((usage: Usage, node: BaseNode) => {
|
|
75
|
+
if (node instanceof Frontend)
|
|
76
|
+
usages.push(usage);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const res: Array<View | ViewElement> = [];
|
|
80
|
+
function dfs(usage: Usage, parent: Usage = null) {
|
|
81
|
+
if ((usage.node instanceof BindEvent || usage.node instanceof BindAttribute)
|
|
82
|
+
&& (parent.node instanceof View || parent.node instanceof ViewElement))
|
|
83
|
+
res.push(parent.node);
|
|
84
|
+
|
|
85
|
+
usage.children?.forEach((child) => {
|
|
86
|
+
dfs(child, usage);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
usages.forEach((usage) => {
|
|
91
|
+
dfs(usage);
|
|
92
|
+
});
|
|
93
|
+
return res;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function findResourcesOfUI(view: View | ViewElement) {
|
|
97
|
+
const res: ResourceNode[] = [];
|
|
98
|
+
let node: BaseNode = view;
|
|
99
|
+
while (node) {
|
|
100
|
+
if (node instanceof View && node.auth)
|
|
101
|
+
res.push({
|
|
102
|
+
path: node.authPath,
|
|
103
|
+
type: 'page',
|
|
104
|
+
});
|
|
105
|
+
else if (node instanceof ViewElement) {
|
|
106
|
+
const hasAuth = node.bindDirectives.find((directive) => directive.name === 'auth');
|
|
107
|
+
if (hasAuth)
|
|
108
|
+
res.push({
|
|
109
|
+
path: node.authPath,
|
|
110
|
+
type: 'component',
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
node = node.parentNode;
|
|
114
|
+
}
|
|
115
|
+
return res;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function optimizeResourceData(resources: ResourceNode[][]) {
|
|
119
|
+
let res = removeRedundantResourceData(resources);
|
|
120
|
+
res = removeRedundantResourceData2(res);
|
|
121
|
+
return res;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// [['b'], ['a' ,'b']] 只需要保留 [['b']]
|
|
125
|
+
function removeRedundantResourceData(resources: ResourceNode[][]) {
|
|
126
|
+
const wm: WeakMap<ResourceNode[], string> = new WeakMap();
|
|
127
|
+
for (const resource of resources) {
|
|
128
|
+
const hash = resource.map(({ path, type }) => `${path}_${type}`)
|
|
129
|
+
.join();
|
|
130
|
+
wm.set(resource, hash);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
resources.sort((a, b) => wm.get(a).length - wm.get(b).length);
|
|
134
|
+
|
|
135
|
+
const res: ResourceNode[][] = [];
|
|
136
|
+
const hashs: string[] = [];
|
|
137
|
+
|
|
138
|
+
for (const resource of resources) {
|
|
139
|
+
const hash = wm.get(resource);
|
|
140
|
+
if (hashs.some((h) => hash.endsWith(h)))
|
|
141
|
+
continue;
|
|
142
|
+
|
|
143
|
+
res.push(resource);
|
|
144
|
+
hashs.push(hash);
|
|
145
|
+
}
|
|
146
|
+
return res;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 子页面有权限,父页面默认也有权限,所以不需要记录父页面权限;
|
|
150
|
+
// 组件有权限,组件所在的页面默认也有权限,所以不需要记录页面权限
|
|
151
|
+
function removeRedundantResourceData2(resources: ResourceNode[][]) {
|
|
152
|
+
return resources.map((resource) => {
|
|
153
|
+
if (resource.length <= 1)
|
|
154
|
+
return resource;
|
|
155
|
+
|
|
156
|
+
if (resource[0].type === 'page')
|
|
157
|
+
return resource.slice(0, 1);
|
|
158
|
+
else if (resource[0].type === 'component')
|
|
159
|
+
return resource.filter((item) => item.type === 'component');
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function findResourcesOfLogic(logic: Logic) {
|
|
164
|
+
const logics = await findViewLogicReferences(logic);
|
|
165
|
+
logics.push(logic);
|
|
166
|
+
|
|
167
|
+
let UIs: Array<View | ViewElement> = [];
|
|
168
|
+
for (const logic of logics) {
|
|
169
|
+
UIs = UIs.concat(await findUIReferences(logic));
|
|
170
|
+
}
|
|
171
|
+
UIs = Array.from(new Set(UIs));
|
|
172
|
+
|
|
173
|
+
const res = UIs.map((ui) => findResourcesOfUI(ui));
|
|
174
|
+
|
|
175
|
+
return optimizeResourceData(res);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function getAllLogics(app: App) {
|
|
179
|
+
const modules: Module[] = [];
|
|
180
|
+
const entities: Entity[] = [];
|
|
181
|
+
const logics: Logic[] = [];
|
|
182
|
+
|
|
183
|
+
if (Array.isArray(app.dataSources)) {
|
|
184
|
+
app.dataSources.forEach((dataSource) => {
|
|
185
|
+
if (Array.isArray(dataSource.entities)) {
|
|
186
|
+
entities.push(...dataSource.entities);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
app.logics && logics.push(...app.logics);
|
|
191
|
+
|
|
192
|
+
app.dependencies && modules.push(...app.dependencies);
|
|
193
|
+
app.interfaceDependencies && modules.push(...app.interfaceDependencies);
|
|
194
|
+
|
|
195
|
+
modules.forEach((module: Module) => {
|
|
196
|
+
module.logics && logics.push(...module.logics);
|
|
197
|
+
if (Array.isArray(module.dataSources)) {
|
|
198
|
+
module.dataSources.forEach((dataSource) => {
|
|
199
|
+
if (Array.isArray(dataSource.entities)) {
|
|
200
|
+
entities.push(...dataSource.entities);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const allLogics: Logic[] = [];
|
|
207
|
+
|
|
208
|
+
if (Array.isArray(entities)) {
|
|
209
|
+
entities.forEach((entity) => {
|
|
210
|
+
const ns = entity.ns;
|
|
211
|
+
if (Array.isArray(ns?.logics)) {
|
|
212
|
+
allLogics.push(...ns.logics);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
if (Array.isArray(logics)) {
|
|
217
|
+
allLogics.push(...logics);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const processLogics: Logic[] = [];
|
|
221
|
+
const processTreeFragments = (app.processes || [])
|
|
222
|
+
.map(processToTreeFragment);
|
|
223
|
+
processTreeFragments.forEach((tree) => {
|
|
224
|
+
processLogics.push(...tree.logics);
|
|
225
|
+
tree.elements.forEach((element) => {
|
|
226
|
+
processLogics.push(...element.logics);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
logics: allLogics,
|
|
232
|
+
processLogics,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export async function genPermissionData(app: App) {
|
|
237
|
+
// console.time('xxx');
|
|
238
|
+
openCache();
|
|
239
|
+
const logicPageResourceDtoList: { [key: string]: ResourceNode[][] } = {};
|
|
240
|
+
const resourceList: string[] = [];
|
|
241
|
+
const resourceDataList: { value: string, type: 'logic', description: string }[] = [];
|
|
242
|
+
const { logics, processLogics } = getAllLogics(app);
|
|
243
|
+
for (const logic of [...logics, ...processLogics]) {
|
|
244
|
+
const resources = await findResourcesOfLogic(logic);
|
|
245
|
+
if (resources.length === 0)
|
|
246
|
+
continue;
|
|
247
|
+
|
|
248
|
+
const service = logics.includes(logic) ? logic.toService() : logic.toProcessService() as { url: { method: string, path: string } };
|
|
249
|
+
const key = `${service.url.path}:${service.url.method}`;
|
|
250
|
+
logicPageResourceDtoList[key] = resources;
|
|
251
|
+
resourceList.push(key);
|
|
252
|
+
resourceDataList.push({
|
|
253
|
+
value: key,
|
|
254
|
+
type: 'logic',
|
|
255
|
+
description: logic.description,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
closeCache();
|
|
259
|
+
// console.timeEnd('xxx');
|
|
260
|
+
return { logicPageResourceDtoList, resourceList, resourceDataList };
|
|
261
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { EventEmitter, EventPayload, BaseNode } from './common';
|
|
2
2
|
export * from './concepts';
|
|
3
|
-
export { genBundleFiles, genMetaData, genReleaseBody } from './generator';
|
|
3
|
+
export { genBundleFiles, genFrontendBundleFiles, genMetaData, genReleaseBody, genPermissionData } from './generator';
|
|
4
4
|
export * from './translator';
|
|
5
5
|
// export { default as diagnosticManager } from './manager/diagnostic';
|
|
6
6
|
export { default as server, NaslServer } from './server';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CallLogic, EntityProperty, BindEvent, App, Namespace, Entity, BaseNode, Logic, Param, TypeAnnotation, Function, Return } from '..';
|
|
1
|
+
import { CallLogic, EntityProperty, BindEvent, App, Namespace, Entity, BaseNode, Logic, Param, TypeAnnotation, Function, Return, AnonymousFunction, NewList } from '..';
|
|
2
2
|
|
|
3
3
|
export function entity2LogicNamespace(entity: Entity) {
|
|
4
4
|
const properties = entity.properties;
|
|
@@ -86,6 +86,26 @@ export function entity2LogicNamespace(entity: Entity) {
|
|
|
86
86
|
}),
|
|
87
87
|
required: true,
|
|
88
88
|
}),
|
|
89
|
+
new Param({
|
|
90
|
+
name: 'properties',
|
|
91
|
+
defaultExpression: new AnonymousFunction({
|
|
92
|
+
description: '',
|
|
93
|
+
params: [
|
|
94
|
+
new Param({
|
|
95
|
+
name: 'item',
|
|
96
|
+
typeAnnotation: new TypeAnnotation({
|
|
97
|
+
typeKind: 'reference',
|
|
98
|
+
typeNamespace: entity.getNamespace(),
|
|
99
|
+
typeName: entity.name,
|
|
100
|
+
}),
|
|
101
|
+
}),
|
|
102
|
+
],
|
|
103
|
+
body: new NewList({
|
|
104
|
+
concept: 'NewList',
|
|
105
|
+
}),
|
|
106
|
+
}),
|
|
107
|
+
required: false,
|
|
108
|
+
}),
|
|
89
109
|
],
|
|
90
110
|
returns: [
|
|
91
111
|
new Return({
|
|
@@ -118,6 +138,26 @@ export function entity2LogicNamespace(entity: Entity) {
|
|
|
118
138
|
}),
|
|
119
139
|
required: true,
|
|
120
140
|
}),
|
|
141
|
+
new Param({
|
|
142
|
+
name: 'properties',
|
|
143
|
+
defaultExpression: new AnonymousFunction({
|
|
144
|
+
description: '',
|
|
145
|
+
params: [
|
|
146
|
+
new Param({
|
|
147
|
+
name: 'item',
|
|
148
|
+
typeAnnotation: new TypeAnnotation({
|
|
149
|
+
typeKind: 'reference',
|
|
150
|
+
typeNamespace: entity.getNamespace(),
|
|
151
|
+
typeName: entity.name,
|
|
152
|
+
}),
|
|
153
|
+
}),
|
|
154
|
+
],
|
|
155
|
+
body: new NewList({
|
|
156
|
+
concept: 'NewList',
|
|
157
|
+
}),
|
|
158
|
+
}),
|
|
159
|
+
required: false,
|
|
160
|
+
}),
|
|
121
161
|
],
|
|
122
162
|
body: [],
|
|
123
163
|
returns: [
|
|
@@ -135,15 +175,6 @@ export function entity2LogicNamespace(entity: Entity) {
|
|
|
135
175
|
name: 'updateBy',
|
|
136
176
|
description: '根据条件,将body除id外所有属性更新到数据记录',
|
|
137
177
|
params: [
|
|
138
|
-
new Param({
|
|
139
|
-
name: 'body',
|
|
140
|
-
typeAnnotation: new TypeAnnotation({
|
|
141
|
-
typeKind: 'reference',
|
|
142
|
-
typeNamespace: entity.getNamespace(),
|
|
143
|
-
typeName: entity.name,
|
|
144
|
-
}),
|
|
145
|
-
required: true,
|
|
146
|
-
}),
|
|
147
178
|
new Param({
|
|
148
179
|
name: 'filter',
|
|
149
180
|
defaultExpression: new Function({
|
|
@@ -167,6 +198,35 @@ export function entity2LogicNamespace(entity: Entity) {
|
|
|
167
198
|
}),
|
|
168
199
|
required: true,
|
|
169
200
|
}),
|
|
201
|
+
new Param({
|
|
202
|
+
name: 'body',
|
|
203
|
+
typeAnnotation: new TypeAnnotation({
|
|
204
|
+
typeKind: 'reference',
|
|
205
|
+
typeNamespace: entity.getNamespace(),
|
|
206
|
+
typeName: entity.name,
|
|
207
|
+
}),
|
|
208
|
+
required: true,
|
|
209
|
+
}),
|
|
210
|
+
new Param({
|
|
211
|
+
name: 'properties',
|
|
212
|
+
defaultExpression: new AnonymousFunction({
|
|
213
|
+
description: '',
|
|
214
|
+
params: [
|
|
215
|
+
new Param({
|
|
216
|
+
name: 'item',
|
|
217
|
+
typeAnnotation: new TypeAnnotation({
|
|
218
|
+
typeKind: 'reference',
|
|
219
|
+
typeNamespace: entity.getNamespace(),
|
|
220
|
+
typeName: entity.name,
|
|
221
|
+
}),
|
|
222
|
+
}),
|
|
223
|
+
],
|
|
224
|
+
body: new NewList({
|
|
225
|
+
concept: 'NewList',
|
|
226
|
+
}),
|
|
227
|
+
}),
|
|
228
|
+
required: false,
|
|
229
|
+
}),
|
|
170
230
|
],
|
|
171
231
|
returns: [
|
|
172
232
|
new Return({
|
|
@@ -257,6 +317,26 @@ export function entity2LogicNamespace(entity: Entity) {
|
|
|
257
317
|
}),
|
|
258
318
|
required: true,
|
|
259
319
|
}),
|
|
320
|
+
new Param({
|
|
321
|
+
name: 'properties',
|
|
322
|
+
defaultExpression: new AnonymousFunction({
|
|
323
|
+
description: '',
|
|
324
|
+
params: [
|
|
325
|
+
new Param({
|
|
326
|
+
name: 'item',
|
|
327
|
+
typeAnnotation: new TypeAnnotation({
|
|
328
|
+
typeKind: 'reference',
|
|
329
|
+
typeNamespace: entity.getNamespace(),
|
|
330
|
+
typeName: entity.name,
|
|
331
|
+
}),
|
|
332
|
+
}),
|
|
333
|
+
],
|
|
334
|
+
body: new NewList({
|
|
335
|
+
concept: 'NewList',
|
|
336
|
+
}),
|
|
337
|
+
}),
|
|
338
|
+
required: false,
|
|
339
|
+
}),
|
|
260
340
|
],
|
|
261
341
|
returns: [
|
|
262
342
|
new Return({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FileNode, NaslServer } from './naslServer';
|
|
2
2
|
import * as tsProtocol from 'typescript/lib/protocol';
|
|
3
3
|
import { MinRange } from './translator';
|
|
4
|
-
import { BaseNode, CallLogic, Destination, EnumItem, Interface, Logic, Param, Process, Role, Structure, View, ViewElement } from '../concepts';
|
|
4
|
+
import { BaseNode, CallLogic, Destination, EnumItem, Interface, Logic, Param, Process, Role, Structure, View, ViewElement, Frontend } from '../concepts';
|
|
5
5
|
import { EventPayload, invokeCommand, registerCommand } from '../common';
|
|
6
6
|
|
|
7
7
|
interface SetNameNode extends BaseNode {
|
|
@@ -161,19 +161,6 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
|
|
|
161
161
|
refsList = refsList.filter((item) =>
|
|
162
162
|
// 因为ui组件本身会多渲染一次,就先过滤一个
|
|
163
163
|
!(item.lineText.includes(': nasl.ui.')));
|
|
164
|
-
// 删除参数单独处理
|
|
165
|
-
if (node instanceof Param) {
|
|
166
|
-
const methodRefs: tsProtocol.ReferencesResponseItem[] = [];
|
|
167
|
-
refsList.forEach((item) => {
|
|
168
|
-
// 入参查找引用,查到logic 和自己,内容完全一样,就保留一个
|
|
169
|
-
const find = methodRefs.find((findItem) => item.lineText === findItem.lineText);
|
|
170
|
-
if (!find) {
|
|
171
|
-
methodRefs.push(item);
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
refsList = methodRefs;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
164
|
// delete的弹框展示
|
|
178
165
|
const confirmParms = {
|
|
179
166
|
actionType: 'delete',
|
|
@@ -182,7 +169,7 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
|
|
|
182
169
|
icon: 'warning',
|
|
183
170
|
};
|
|
184
171
|
let callback = null;
|
|
185
|
-
if (refsList.length <= 1) {
|
|
172
|
+
if (refsList.length <= 1 || (node instanceof Param && node.parentNode instanceof Logic && refsList.length <= 2)) {
|
|
186
173
|
// 页面组件直接删除然后return
|
|
187
174
|
if (node instanceof ViewElement) {
|
|
188
175
|
this.delete();
|
|
@@ -202,7 +189,7 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
|
|
|
202
189
|
const node = this;
|
|
203
190
|
|
|
204
191
|
// 删除页面或者流程
|
|
205
|
-
if (node instanceof View || node instanceof Process) {
|
|
192
|
+
if (node instanceof View || node instanceof Process || node instanceof Frontend) {
|
|
206
193
|
/**
|
|
207
194
|
* 查找这个页面是不是有依赖
|
|
208
195
|
*/
|
|
@@ -222,7 +209,33 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
|
|
|
222
209
|
} else {
|
|
223
210
|
this.delete();
|
|
224
211
|
}
|
|
225
|
-
|
|
212
|
+
} else {
|
|
213
|
+
if (node instanceof Frontend) {
|
|
214
|
+
let viewPath = (this as FileNode).getEmbeddedFilePath();
|
|
215
|
+
viewPath = viewPath.slice(0, viewPath.length - 3);
|
|
216
|
+
const refsTempList = refsList.filter((record) => !record.file.includes(viewPath));
|
|
217
|
+
// 删除流程节点绑定的该端的页面跳转
|
|
218
|
+
const result = refsTempList
|
|
219
|
+
.map((record) => {
|
|
220
|
+
const fileNode = naslServer.file2NodeMap.get(record.file);
|
|
221
|
+
if (fileNode) {
|
|
222
|
+
const minRange = naslServer._findMinRange(record, fileNode as FileNode);
|
|
223
|
+
if (minRange?.node?.parentNode?.parentNode?.concept === 'ProcessElement') {
|
|
224
|
+
return minRange.node.parentNode;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}).filter((record) => !!record);
|
|
229
|
+
console.log(result);
|
|
230
|
+
const App = this.rootNode;
|
|
231
|
+
App.emit('collect:start', {
|
|
232
|
+
actionMsg: `删除端${node.name}`,
|
|
233
|
+
});
|
|
234
|
+
await Promise.all(result.map((ele) => ele.delete()));
|
|
235
|
+
this.delete();
|
|
236
|
+
App.emit('collect:end');
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
226
239
|
}
|
|
227
240
|
}
|
|
228
241
|
callback = async () => {
|
|
@@ -235,6 +248,7 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
|
|
|
235
248
|
App.emit('collect:start', {
|
|
236
249
|
actionMsg: '删除参数',
|
|
237
250
|
});
|
|
251
|
+
const Index = node.getIndexOfParent();
|
|
238
252
|
this.delete();
|
|
239
253
|
refsList.forEach((record) => {
|
|
240
254
|
const fileNode = naslServer.file2NodeMap.get(record.file);
|
|
@@ -242,11 +256,8 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
|
|
|
242
256
|
return null;
|
|
243
257
|
const minRange: MinRange = naslServer._findMinRange(record, fileNode as FileNode);
|
|
244
258
|
if (minRange) {
|
|
245
|
-
if (minRange.node instanceof CallLogic) {
|
|
246
|
-
minRange.node.
|
|
247
|
-
}
|
|
248
|
-
if (minRange.node instanceof Destination) {
|
|
249
|
-
minRange.node.setViewArgument(parentNode as View);
|
|
259
|
+
if (minRange.node instanceof CallLogic || minRange.node instanceof Destination) {
|
|
260
|
+
minRange.node.deleteCalleeArg(Index);
|
|
250
261
|
}
|
|
251
262
|
}
|
|
252
263
|
});
|
|
@@ -247,13 +247,9 @@ function findNode(typeKey: string, node: BaseNode) {
|
|
|
247
247
|
* 获取下一级的节点进行递归
|
|
248
248
|
* @param typeKey 当前节点的类型,主要为了取出内部的 T中的实际类型
|
|
249
249
|
* @param item 当前节点的内容
|
|
250
|
-
* @param parent 父级节点的内容
|
|
251
250
|
* @param node 获取变量框的位置
|
|
252
251
|
*/
|
|
253
|
-
export function nextFindTypeChild(typeKey: string, item: any,
|
|
254
|
-
// 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
|
|
255
|
-
const nodeMap = parent ? parent.nodeMap : new Map();
|
|
256
|
-
item.nodeMap = nodeMap;
|
|
252
|
+
export function nextFindTypeChild(typeKey: string, item: any, node: BaseNode) {
|
|
257
253
|
const newType = findNode(typeKey, node);
|
|
258
254
|
if ((newType as Structure)?.properties && (newType as Structure).properties.length) {
|
|
259
255
|
// 处理泛型的内容要取到值
|
|
@@ -274,16 +270,7 @@ export function nextFindTypeChild(typeKey: string, item: any, parent: any, node:
|
|
|
274
270
|
});
|
|
275
271
|
}
|
|
276
272
|
});
|
|
277
|
-
|
|
278
|
-
if (index) {
|
|
279
|
-
nodeMap.set(newType, index + 1);
|
|
280
|
-
} else {
|
|
281
|
-
nodeMap.set(newType, 1);
|
|
282
|
-
}
|
|
283
|
-
// 最多保留3层
|
|
284
|
-
if (index < 3) {
|
|
285
|
-
item.children = formatVariableData(newStructure.properties, node, item);
|
|
286
|
-
}
|
|
273
|
+
item.children = formatVariableData(newStructure.properties, node, item);
|
|
287
274
|
}
|
|
288
275
|
}
|
|
289
276
|
|
|
@@ -359,7 +346,7 @@ function getAStructureScopeType(type: string, parent: any, node: BaseNode) {
|
|
|
359
346
|
newItem.concept = 'CompletionProperty';
|
|
360
347
|
// 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
|
|
361
348
|
if (item.typeKey && !isNoChildType(item.typeKey)) {
|
|
362
|
-
newItem.children = nextObjectTypeChild(item.typeKey, newItem,
|
|
349
|
+
newItem.children = nextObjectTypeChild(item.typeKey, newItem, node);
|
|
363
350
|
}
|
|
364
351
|
const completionProperty = new CompletionProperty(newItem);
|
|
365
352
|
completionProperty.icon = 'refProperty';
|
|
@@ -395,9 +382,6 @@ function getAStructureScopeType(type: string, parent: any, node: BaseNode) {
|
|
|
395
382
|
function getAStructureObjectStringType(type: string, parent: any, node: BaseNode) {
|
|
396
383
|
let newType = type.replaceAll(' ', '').replaceAll('\n', '').replace(/__name:"AStructure_\w{8}";/g, '');
|
|
397
384
|
newType = newType.substring(1, newType.length - 1);
|
|
398
|
-
if (!parent.keyMap) {
|
|
399
|
-
parent.keyMap = new Map();
|
|
400
|
-
}
|
|
401
385
|
if (/\{([^()]+)\}/.exec(newType)) {
|
|
402
386
|
newType = newType.replace(/\{([^()]+)\}/, '');
|
|
403
387
|
}
|
|
@@ -437,7 +421,7 @@ function getAStructureObjectStringType(type: string, parent: any, node: BaseNode
|
|
|
437
421
|
newItem.concept = 'CompletionProperty';
|
|
438
422
|
// 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
|
|
439
423
|
if (item.typeKey && !isNoChildType(item.typeKey)) {
|
|
440
|
-
newItem.children = nextObjectTypeChild(getPlatformType(item.typeKey), newItem,
|
|
424
|
+
newItem.children = nextObjectTypeChild(getPlatformType(item.typeKey), newItem, node);
|
|
441
425
|
}
|
|
442
426
|
const completionProperty = new CompletionProperty(newItem);
|
|
443
427
|
|
|
@@ -451,13 +435,7 @@ function getAStructureObjectStringType(type: string, parent: any, node: BaseNode
|
|
|
451
435
|
completionProperty.icon = getNodeiconFromLogic(completionProperty, node);
|
|
452
436
|
return completionProperty;
|
|
453
437
|
}
|
|
454
|
-
function nextObjectTypeChild(typeKey: string, item: any,
|
|
455
|
-
// 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
|
|
456
|
-
const nodeMap = parent.nodeMap || new Map();
|
|
457
|
-
item.nodeMap = nodeMap; // 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
|
|
458
|
-
|
|
459
|
-
const keyMap = parent.keyMap;
|
|
460
|
-
item.keyMap = keyMap;
|
|
438
|
+
function nextObjectTypeChild(typeKey: string, item: any, node: BaseNode) {
|
|
461
439
|
const newType = findNode(typeKey, node);
|
|
462
440
|
if ((newType as Structure)?.properties && (newType as Structure).properties.length) {
|
|
463
441
|
// 处理泛型的内容要取到值
|
|
@@ -478,16 +456,7 @@ function nextObjectTypeChild(typeKey: string, item: any, parent: any, node: Base
|
|
|
478
456
|
});
|
|
479
457
|
}
|
|
480
458
|
});
|
|
481
|
-
|
|
482
|
-
if (index) {
|
|
483
|
-
nodeMap.set(newType, index + 1);
|
|
484
|
-
} else {
|
|
485
|
-
nodeMap.set(newType, 1);
|
|
486
|
-
}
|
|
487
|
-
// 最多保留3层
|
|
488
|
-
if (index < 3) {
|
|
489
|
-
return formatVariableData(newStructure.properties, node, item);
|
|
490
|
-
}
|
|
459
|
+
return formatVariableData(newStructure.properties, node, item);
|
|
491
460
|
}
|
|
492
461
|
}
|
|
493
462
|
|
|
@@ -533,21 +502,42 @@ export function formatVariableData(data: unknown | variableItem[], node: BaseNod
|
|
|
533
502
|
item.name = item.text;
|
|
534
503
|
const identifier = new Identifier({ name: item.name });
|
|
535
504
|
item.expression = identifier;
|
|
505
|
+
item.typeKey = typeKey;
|
|
536
506
|
} else {
|
|
537
507
|
item.value = `${parent.value}.${item.name}`;
|
|
508
|
+
const object: any = BaseNode.from(parent.expression.toJSON());
|
|
538
509
|
const memberExpression = new MemberExpression({
|
|
539
|
-
object
|
|
510
|
+
object,
|
|
540
511
|
property: new Identifier({ name: item.name }),
|
|
541
512
|
});
|
|
542
513
|
item.expression = memberExpression;
|
|
514
|
+
item.variableParent = parent;
|
|
515
|
+
item.typeKey = typeKey;
|
|
516
|
+
// 标记实体属性是否是符合类型
|
|
517
|
+
item.isComplexType = item.typeAnnotation?.isComplexType();
|
|
543
518
|
}
|
|
544
519
|
// 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
|
|
545
520
|
if (typeKey && !isNoChildType(typeKey)) {
|
|
546
|
-
|
|
521
|
+
let currentParent = item;
|
|
522
|
+
let typeKeyIndex = 0;
|
|
523
|
+
while (currentParent.variableParent) {
|
|
524
|
+
currentParent = currentParent.variableParent;
|
|
525
|
+
if (currentParent.typeKey === typeKey) {
|
|
526
|
+
typeKeyIndex++;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
// 向上找到3次一样的就结束
|
|
530
|
+
if (typeKeyIndex < 3) {
|
|
531
|
+
nextFindTypeChild(typeKey, item, node);
|
|
532
|
+
}
|
|
547
533
|
}
|
|
548
534
|
// 如果是从实体或者数据结构取的属性,就需要重置一下类型
|
|
549
535
|
item.concept = 'CompletionProperty';
|
|
550
536
|
const completionProperty = new CompletionProperty(item);
|
|
537
|
+
// 标记实体属性是否是符合类型
|
|
538
|
+
if (typeof item.isComplexType === 'boolean') {
|
|
539
|
+
Object.assign(completionProperty, { isComplexType: item.isComplexType });
|
|
540
|
+
}
|
|
551
541
|
if (!parent) {
|
|
552
542
|
// 变量 param return 在这里添加图标
|
|
553
543
|
completionProperty.icon = getNodeiconFromLogic(completionProperty, node);
|
|
@@ -633,20 +623,20 @@ function sortFirstVariableData(result: CompletionProperty[], node: BaseNode) {
|
|
|
633
623
|
}
|
|
634
624
|
|
|
635
625
|
export function formatFrontEndVariables(frontEndVariables: Array<Variable>) {
|
|
636
|
-
const result = frontEndVariables.map((
|
|
637
|
-
const namespace =
|
|
626
|
+
const result = frontEndVariables.map((itemNode) => {
|
|
627
|
+
const namespace = itemNode.getNamespace();
|
|
638
628
|
const newItem: any = {
|
|
639
|
-
name:
|
|
640
|
-
value:
|
|
629
|
+
name: itemNode.name,
|
|
630
|
+
value: itemNode.name,
|
|
641
631
|
expression: new Identifier({
|
|
642
|
-
name:
|
|
632
|
+
name: itemNode.name,
|
|
643
633
|
namespace,
|
|
644
634
|
}),
|
|
645
635
|
};
|
|
646
|
-
const noChildType = isNoChildType(
|
|
636
|
+
const noChildType = isNoChildType(itemNode.typeAnnotation.typeKey);
|
|
647
637
|
|
|
648
638
|
if (!noChildType) {
|
|
649
|
-
nextFindTypeChild(
|
|
639
|
+
nextFindTypeChild(itemNode.typeAnnotation.typeKey, newItem, itemNode);
|
|
650
640
|
}
|
|
651
641
|
const completionProperty = new CompletionProperty(newItem);
|
|
652
642
|
completionProperty.icon = 'frontendVariable';
|