@lcap/nasl 2.13.0-beta.2 → 2.13.1-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/concepts/BindAttribute__.js +7 -4
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/CompletionProperty__.d.ts +0 -1
- package/out/concepts/CompletionProperty__.js +0 -1
- package/out/concepts/CompletionProperty__.js.map +1 -1
- package/out/concepts/DataSource__.js +1 -0
- package/out/concepts/DataSource__.js.map +1 -1
- package/out/concepts/Destination__.js +6 -1
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/Entity__.js +1 -0
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/Enum__.js +1 -0
- package/out/concepts/Enum__.js.map +1 -1
- package/out/concepts/Function__.d.ts +2 -1
- package/out/concepts/Function__.js +0 -28
- package/out/concepts/Function__.js.map +1 -1
- package/out/concepts/InterfaceParam__.js +6 -3
- package/out/concepts/InterfaceParam__.js.map +1 -1
- package/out/concepts/Interface__.js +1 -0
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/Logic__.js +1 -0
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/Param__.js +6 -3
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/ProcessElement__.d.ts +4 -0
- package/out/concepts/ProcessElement__.js +31 -0
- package/out/concepts/ProcessElement__.js.map +1 -1
- package/out/concepts/Process__.js +1 -0
- package/out/concepts/Process__.js.map +1 -1
- package/out/concepts/Return__.js +6 -3
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/Role__.js +1 -0
- package/out/concepts/Role__.js.map +1 -1
- package/out/concepts/Structure__.js +1 -0
- package/out/concepts/Structure__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.js +3 -14
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/Unparsed__.js +3 -3
- package/out/concepts/Unparsed__.js.map +1 -1
- package/out/concepts/Variable__.js +6 -3
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.js +1 -0
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.collection.js +12 -0
- package/out/concepts/basics/stdlib/nasl.collection.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.util.js +187 -5
- 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/enums/KEYWORDS.d.ts +1 -0
- package/out/enums/KEYWORDS.js +16 -1
- package/out/enums/KEYWORDS.js.map +1 -1
- package/out/generator/genBundleFiles.js +25 -1
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/server/createUiTs.js +12 -12
- package/out/server/createUiTs.js.map +1 -1
- package/out/server/formatTsUtils.d.ts +21 -0
- package/out/server/formatTsUtils.js +323 -0
- package/out/server/formatTsUtils.js.map +1 -0
- package/out/server/getLogics.js +18 -17
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.d.ts +1 -12
- package/out/server/getMemberIdentifier.js +11 -264
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/getProcesses.js +9 -18
- package/out/server/getProcesses.js.map +1 -1
- package/out/server/naslServer.d.ts +48 -0
- package/out/server/naslServer.js +58 -13
- package/out/server/naslServer.js.map +1 -1
- package/out/server/stdlib/nasl.annotation.d.ts +4 -0
- package/out/server/stdlib/nasl.annotation.js +1 -0
- package/out/server/stdlib/nasl.annotation.js.map +1 -0
- package/out/server/stdlib/nasl.auth.d.ts +30 -0
- package/out/server/stdlib/nasl.auth.js +1 -0
- package/out/server/stdlib/nasl.auth.js.map +1 -0
- package/out/server/stdlib/nasl.browser.d.ts +5 -0
- package/out/server/stdlib/nasl.browser.js +1 -0
- package/out/server/stdlib/nasl.browser.js.map +1 -0
- package/out/server/stdlib/nasl.collection.d.ts +22 -0
- package/out/server/stdlib/nasl.collection.js +1 -0
- package/out/server/stdlib/nasl.collection.js.map +1 -0
- package/out/server/stdlib/nasl.configuration.d.ts +3 -0
- package/out/server/stdlib/nasl.configuration.js +1 -0
- package/out/server/stdlib/nasl.configuration.js.map +1 -0
- package/out/server/stdlib/nasl.core.d.ts +104 -0
- package/out/server/stdlib/nasl.core.js +1 -0
- package/out/server/stdlib/nasl.core.js.map +1 -0
- package/out/server/stdlib/nasl.interface.d.ts +7 -0
- package/out/server/stdlib/nasl.interface.js +1 -0
- package/out/server/stdlib/nasl.interface.js.map +1 -0
- package/out/server/stdlib/nasl.langUtil.d.ts +28 -0
- package/out/server/stdlib/nasl.langUtil.js +1 -0
- package/out/server/stdlib/nasl.langUtil.js.map +1 -0
- package/out/server/stdlib/nasl.process.d.ts +50 -0
- package/out/server/stdlib/nasl.process.js +1 -0
- package/out/server/stdlib/nasl.process.js.map +1 -0
- package/out/server/stdlib/nasl.ui.d.ts +186 -0
- package/out/server/stdlib/nasl.ui.definition.d.ts +1072 -0
- package/out/server/stdlib/nasl.ui.definition.js +632 -0
- package/out/server/stdlib/nasl.ui.definition.js.map +1 -0
- package/out/server/stdlib/nasl.ui.js +1 -0
- package/out/server/stdlib/nasl.ui.js.map +1 -0
- package/out/server/stdlib/nasl.util.d.ts +74 -0
- package/out/server/stdlib/nasl.util.js +4 -0
- package/out/server/stdlib/nasl.util.js.map +1 -0
- package/out/server/stdlib/nasl.validation.d.ts +32 -0
- package/out/server/stdlib/nasl.validation.js +1 -0
- package/out/server/stdlib/nasl.validation.js.map +1 -0
- package/out/templator/genQueryComponent.js +8 -8
- package/out/templator/genQueryComponent.js.map +1 -1
- package/package.json +1 -1
- package/src/concepts/BindAttribute__.ts +7 -24
- package/src/concepts/CompletionProperty__.ts +0 -1
- package/src/concepts/DataSource__.ts +1 -0
- package/src/concepts/Destination__.ts +6 -1
- package/src/concepts/Entity__.ts +1 -0
- package/src/concepts/Enum__.ts +1 -0
- package/src/concepts/InterfaceParam__.ts +6 -3
- package/src/concepts/Interface__.ts +1 -0
- package/src/concepts/Logic__.ts +1 -0
- package/src/concepts/Param__.ts +5 -3
- package/src/concepts/ProcessElement__.ts +35 -1
- package/src/concepts/Process__.ts +1 -0
- package/src/concepts/Return__.ts +5 -3
- package/src/concepts/Role__.ts +1 -0
- package/src/concepts/Structure__.ts +1 -0
- package/src/concepts/TypeAnnotation__.ts +3 -30
- package/src/concepts/Unparsed__.ts +3 -10
- package/src/concepts/Variable__.ts +5 -3
- package/src/concepts/ViewElement__.ts +1 -19
- package/src/concepts/View__.ts +1 -0
- package/src/concepts/basics/stdlib/nasl.collection.ts +12 -0
- package/src/concepts/basics/stdlib/nasl.util.ts +187 -5
- package/src/concepts/basics/stdlib/reference2TypeAnnotationList.ts +1 -1
- package/src/enums/KEYWORDS.ts +16 -0
- package/src/generator/genBundleFiles.ts +24 -1
- package/src/server/createUiTs.ts +12 -12
- package/src/server/formatTsUtils.ts +319 -0
- package/src/server/getLogics.ts +18 -17
- package/src/server/getMemberIdentifier.ts +10 -264
- package/src/server/getProcesses.ts +10 -19
- package/src/server/naslServer.ts +58 -12
- package/src/server/stdlib/nasl.annotation.ts +4 -0
- package/src/server/stdlib/nasl.auth.ts +31 -0
- package/src/server/stdlib/nasl.browser.ts +5 -0
- package/src/server/stdlib/nasl.collection.ts +22 -0
- package/src/server/stdlib/nasl.configuration.ts +3 -0
- package/src/server/stdlib/nasl.core.ts +128 -0
- package/src/server/stdlib/nasl.interface.ts +7 -0
- package/src/server/stdlib/nasl.langUtil.ts +31 -0
- package/src/server/stdlib/nasl.process.ts +87 -0
- package/src/server/stdlib/nasl.ui.definition.ts +1760 -0
- package/src/server/stdlib/nasl.ui.ts +189 -0
- package/src/server/stdlib/nasl.util.ts +84 -0
- package/src/server/stdlib/nasl.validation.ts +33 -0
- package/src/templator/genQueryComponent.ts +8 -8
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { BaseNode, Identifier, TypeAnnotation, StructureProperty, Entity, Structure, EntityProperty, Param, MemberExpression, CompletionProperty } from '..';
|
|
2
|
+
import { getNaslNodeByNodeCallee } from '../automate/engine/utils';
|
|
3
|
+
|
|
4
|
+
interface variableItem {
|
|
5
|
+
text: string;
|
|
6
|
+
completionDetail: any;
|
|
7
|
+
children?: variableItem[] | any;
|
|
8
|
+
name?: string;
|
|
9
|
+
value?: string;
|
|
10
|
+
expression: MemberExpression | Identifier;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 把ts返回的详细信息截取成一个类型字符串
|
|
14
|
+
* @param displayParts ts返回的key value
|
|
15
|
+
* // 0: {text: 'let', kind: 'keyword'}
|
|
16
|
+
// 1: {text: ' ', kind: 'space'}
|
|
17
|
+
// 2: {text: 'bindRoles', kind: 'text'}
|
|
18
|
+
// 3: {text: ':', kind: 'punctuation'}
|
|
19
|
+
// 4: {text: ' ', kind: 'space'}
|
|
20
|
+
// 5: {text: 'roles', kind: 'moduleName'}
|
|
21
|
+
// 6: {text: '.', kind: 'punctuation'}
|
|
22
|
+
// 7: {text: 'DEV_AdminRole', kind: 'enumName'}
|
|
23
|
+
* @returns type roles.DEV_AdminRole
|
|
24
|
+
*/
|
|
25
|
+
function formatTs2TypeString(displayParts: Array<{ text: string; kind: string }>) {
|
|
26
|
+
let str = '';
|
|
27
|
+
displayParts.forEach((item) => {
|
|
28
|
+
str += item.text;
|
|
29
|
+
});
|
|
30
|
+
const strTypes = str.split(': ');
|
|
31
|
+
const type = strTypes[1];
|
|
32
|
+
return type;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 把当前类型转成typeAnnotation
|
|
36
|
+
* @param type app
|
|
37
|
+
* @returns typeAnnotation
|
|
38
|
+
*/
|
|
39
|
+
function getCompletionDetailType(type: string): TypeAnnotation {
|
|
40
|
+
let typeAnnotation;
|
|
41
|
+
try {
|
|
42
|
+
if (type.includes('<') && type.includes('>')) {
|
|
43
|
+
// 泛型的处理
|
|
44
|
+
typeAnnotation = createGenericTypeAnnotation(type);
|
|
45
|
+
} else {
|
|
46
|
+
typeAnnotation = createType2Annotation(type);
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.log(err);
|
|
50
|
+
}
|
|
51
|
+
return typeAnnotation;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function createGenericTypeAnnotation(type: string) {
|
|
55
|
+
// 取出匹配的内容
|
|
56
|
+
|
|
57
|
+
const childType = type.substring(0, type.indexOf('<'));
|
|
58
|
+
const typeAnnotation = createType2Annotation(childType);
|
|
59
|
+
// 如果还有匹配到的多层泛型;
|
|
60
|
+
// 取出匹配到的内容
|
|
61
|
+
const types = /\<([^()]+)\>/g.exec(type);
|
|
62
|
+
const newtext = types[1];
|
|
63
|
+
// 把匹配的值,的内容在,检索一遍,看是不是泛型套泛型
|
|
64
|
+
const newTypes = /\<([^()]+)\>/g.exec(newtext);
|
|
65
|
+
// 如果是的话就去递归
|
|
66
|
+
if (newTypes) {
|
|
67
|
+
const argTypeAnnotation = createGenericTypeAnnotation(newtext);
|
|
68
|
+
typeAnnotation.typeArguments = [argTypeAnnotation];
|
|
69
|
+
} else {
|
|
70
|
+
// 如果不是就创造内部的真正类型
|
|
71
|
+
const argTypeAnnotation = createType2Annotation(newtext);
|
|
72
|
+
typeAnnotation.typeArguments = [argTypeAnnotation];
|
|
73
|
+
}
|
|
74
|
+
return typeAnnotation;
|
|
75
|
+
}
|
|
76
|
+
function createType2Annotation(type: string): TypeAnnotation {
|
|
77
|
+
let typeAnnotation;
|
|
78
|
+
// 没有泛型类型的
|
|
79
|
+
const types = type.split('.');
|
|
80
|
+
if (types.length === 1) {
|
|
81
|
+
typeAnnotation = TypeAnnotation.createPrimitive(types[0]);
|
|
82
|
+
} else {
|
|
83
|
+
if (type.startsWith('nasl.core')) {
|
|
84
|
+
typeAnnotation = TypeAnnotation.createPrimitive(types[types.length - 1]);
|
|
85
|
+
} else if (type.startsWith('nasl.ui')) {
|
|
86
|
+
typeAnnotation = TypeAnnotation.createReference(types[types.length - 1], {
|
|
87
|
+
typeNamespace: 'nasl.ui',
|
|
88
|
+
});
|
|
89
|
+
} else if (type.startsWith('nasl.process')) {
|
|
90
|
+
typeAnnotation = TypeAnnotation.createReference(types[types.length - 1], {
|
|
91
|
+
typeNamespace: 'nasl.process',
|
|
92
|
+
});
|
|
93
|
+
} else if (type.startsWith('nasl.collection')) {
|
|
94
|
+
typeAnnotation = TypeAnnotation.createGeneric(types[types.length - 1], {
|
|
95
|
+
typeNamespace: 'nasl.collection',
|
|
96
|
+
});
|
|
97
|
+
} else if (type.startsWith('entities.')) {
|
|
98
|
+
typeAnnotation = TypeAnnotation.createReference(types[types.length - 1], {
|
|
99
|
+
typeNamespace: 'app.entities',
|
|
100
|
+
});
|
|
101
|
+
} else if (type.startsWith('structures.')) {
|
|
102
|
+
typeAnnotation = TypeAnnotation.createReference(types[types.length - 1], {
|
|
103
|
+
typeNamespace: 'app.structures',
|
|
104
|
+
});
|
|
105
|
+
} else if (type.startsWith('enums.')) {
|
|
106
|
+
typeAnnotation = TypeAnnotation.createReference(types[types.length - 1], {
|
|
107
|
+
typeNamespace: 'app.enums',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return typeAnnotation;
|
|
112
|
+
}
|
|
113
|
+
export function getPlatformType(tsType: string): string {
|
|
114
|
+
const namespacePrefix = ['app', 'extensions', 'apis', 'components', 'nasl'];
|
|
115
|
+
if (tsType === 'String') {
|
|
116
|
+
return 'nasl.core.String';
|
|
117
|
+
} else if (tsType === 'Boolean') {
|
|
118
|
+
return 'nasl.core.Boolean';
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const strTypes = tsType.split('.');
|
|
122
|
+
if (strTypes.length) {
|
|
123
|
+
const first = strTypes[0];
|
|
124
|
+
// 如果不是这几个前缀就加一个namespace
|
|
125
|
+
if (!namespacePrefix.includes(first)) {
|
|
126
|
+
return 'app.' + tsType;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return tsType;
|
|
130
|
+
}
|
|
131
|
+
export function isNoChildType(type: String) {
|
|
132
|
+
return type?.startsWith('nasl.core') || type?.startsWith('app.enums');
|
|
133
|
+
}
|
|
134
|
+
function findNode(typeKey: string, node: BaseNode) {
|
|
135
|
+
let newType: Structure | Entity;
|
|
136
|
+
if (typeKey.startsWith('nasl.') && typeKey.includes('<')) {
|
|
137
|
+
const findGenericsIndex = typeKey.indexOf('<');
|
|
138
|
+
typeKey = typeKey.substring(0, findGenericsIndex);
|
|
139
|
+
const typeIndex = typeKey.lastIndexOf('.');
|
|
140
|
+
newType = getNaslNodeByNodeCallee(typeKey.substring(0, typeIndex), typeKey.substring(typeIndex + 1, typeKey.length));
|
|
141
|
+
} else if (typeKey.startsWith('nasl.')) {
|
|
142
|
+
const typeIndex = typeKey.lastIndexOf('.');
|
|
143
|
+
newType = getNaslNodeByNodeCallee(typeKey.substring(0, typeIndex), typeKey.substring(typeIndex + 1, typeKey.length));
|
|
144
|
+
} else {
|
|
145
|
+
newType = (node as Identifier)?.app?.findNodeByCompleteName(typeKey);
|
|
146
|
+
}
|
|
147
|
+
return newType;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 获取下一级的节点进行递归
|
|
152
|
+
* @param typeKey 当前节点的类型,主要为了取出内部的 T中的实际类型
|
|
153
|
+
* @param item 当前节点的内容
|
|
154
|
+
* @param parent 父级节点的内容
|
|
155
|
+
* @param node 获取变量框的位置
|
|
156
|
+
*/
|
|
157
|
+
export function nextFindTypeChild(typeKey: string, item: any, parent: any, node: BaseNode) {
|
|
158
|
+
// 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
|
|
159
|
+
const nodeMap = parent ? parent.nodeMap : new Map();
|
|
160
|
+
item.nodeMap = nodeMap;
|
|
161
|
+
const newType = findNode(typeKey, node);
|
|
162
|
+
if (newType?.properties && newType.properties.length) {
|
|
163
|
+
// 处理泛型的内容要取到值
|
|
164
|
+
const StructureJson = newType.toJSON();
|
|
165
|
+
const newStructure = new Structure(StructureJson);
|
|
166
|
+
newStructure.properties.forEach((item: StructureProperty | EntityProperty) => {
|
|
167
|
+
const itemType = item?.typeAnnotation?.typeKey;
|
|
168
|
+
if (itemType === 'T' && /\<([^()]+)\>/g.exec(typeKey)) {
|
|
169
|
+
const newTypes = /\<([^()]+)\>/g.exec(typeKey);
|
|
170
|
+
// 找到当前原来的类型
|
|
171
|
+
const contentType = getPlatformType(newTypes[1]);
|
|
172
|
+
const typeNamespace = contentType.substring(0, contentType.lastIndexOf('.'));
|
|
173
|
+
const typeName = contentType.substring(contentType.lastIndexOf('.') + 1, contentType.length);
|
|
174
|
+
item.typeAnnotation = new TypeAnnotation({
|
|
175
|
+
typeKind: 'reference',
|
|
176
|
+
typeNamespace,
|
|
177
|
+
typeName,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
const index = nodeMap.get(newType) || 0;
|
|
182
|
+
if (index) {
|
|
183
|
+
nodeMap.set(newType, index + 1);
|
|
184
|
+
} else {
|
|
185
|
+
nodeMap.set(newType, 1);
|
|
186
|
+
}
|
|
187
|
+
// 最多保留3层
|
|
188
|
+
if (index < 3) {
|
|
189
|
+
item.children = formatVariableData(newStructure.properties, node, item);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// 格式化变量数据
|
|
195
|
+
export function formatVariableData(data: unknown | variableItem[], node: BaseNode, parent?: any) {
|
|
196
|
+
if (Array.isArray(data)) {
|
|
197
|
+
let result = data.map((item) => {
|
|
198
|
+
item.children = [];
|
|
199
|
+
// 当前结构的typeAnnotation
|
|
200
|
+
let typeAnnotation;
|
|
201
|
+
// 当前的类型如 app.entitys.entity1 nasl.core.String
|
|
202
|
+
let typeKey: string;
|
|
203
|
+
|
|
204
|
+
if (item.completionDetail) {
|
|
205
|
+
// 当前节点的完整类型,主要是在有T的内容使用 nasl.list<Enum1> 内部匹配内容给里面子集的T赋值类型
|
|
206
|
+
const currentType: string = formatTs2TypeString(item.completionDetail.displayParts as Array<{ text: string; kind: string }>);
|
|
207
|
+
typeAnnotation = getCompletionDetailType(currentType);
|
|
208
|
+
typeKey = getPlatformType(currentType);
|
|
209
|
+
} else if (item instanceof StructureProperty) {
|
|
210
|
+
typeKey = item?.typeAnnotation?.typeKey;
|
|
211
|
+
}
|
|
212
|
+
// 如果没有父节点就是Identifier
|
|
213
|
+
if (!parent) {
|
|
214
|
+
// value需要拼接生成
|
|
215
|
+
item.value = parent ? `${parent.value}.${item.text}` : item.text;
|
|
216
|
+
item.name = item.text;
|
|
217
|
+
const identifier = new Identifier({ name: item.name });
|
|
218
|
+
// 携带上当前的类型
|
|
219
|
+
identifier.typeAnnotation = typeAnnotation;
|
|
220
|
+
item.expression = identifier;
|
|
221
|
+
} else {
|
|
222
|
+
item.value = `${parent.value}.${item.name}`;
|
|
223
|
+
const memberExpression = new MemberExpression({
|
|
224
|
+
object: parent.expression,
|
|
225
|
+
property: new Identifier({ name: item.name }),
|
|
226
|
+
});
|
|
227
|
+
// 携带上当前的类型
|
|
228
|
+
memberExpression.typeAnnotation = typeAnnotation;
|
|
229
|
+
item.expression = memberExpression;
|
|
230
|
+
}
|
|
231
|
+
// 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
|
|
232
|
+
if (typeKey && !isNoChildType(typeKey)) {
|
|
233
|
+
nextFindTypeChild(typeKey, item, parent, node);
|
|
234
|
+
}
|
|
235
|
+
const completionProperty = new CompletionProperty(item);
|
|
236
|
+
if (!parent) {
|
|
237
|
+
// 变量 param return 在这里添加图标
|
|
238
|
+
completionProperty.icon = getNodeiconFromLogic(completionProperty, node);
|
|
239
|
+
} else {
|
|
240
|
+
completionProperty.icon = 'refProperty';
|
|
241
|
+
}
|
|
242
|
+
return completionProperty;
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* 排序result
|
|
247
|
+
* 如果没有父级就是第一集就排序一下当前result,用户体验优化
|
|
248
|
+
*/
|
|
249
|
+
if (!parent) {
|
|
250
|
+
result = sortFirstVariableData(result, node);
|
|
251
|
+
}
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// 从logic获取节点的icon
|
|
257
|
+
function getNodeiconFromLogic(completionProperty: CompletionProperty, node: BaseNode): string {
|
|
258
|
+
const logic = (node as Param).logic;
|
|
259
|
+
const view = (node as Param).view;
|
|
260
|
+
if (view) {
|
|
261
|
+
const { params } = view;
|
|
262
|
+
if (params.find((item) => item.name === completionProperty.name))
|
|
263
|
+
return 'param';
|
|
264
|
+
}
|
|
265
|
+
if (logic) {
|
|
266
|
+
const { params, returns } = logic;
|
|
267
|
+
if (params.find((item) => item.name === completionProperty.name))
|
|
268
|
+
return 'param';
|
|
269
|
+
|
|
270
|
+
if (returns.find((item) => item.name === completionProperty.name))
|
|
271
|
+
return 'return';
|
|
272
|
+
// if (variables.find((item) => item.name === completionProperty.name))
|
|
273
|
+
// return 'variable';
|
|
274
|
+
|
|
275
|
+
// 其余的全部按variable展示
|
|
276
|
+
return 'variable';
|
|
277
|
+
}
|
|
278
|
+
return 'variable';
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* 把要返回去的数据做一下排序
|
|
284
|
+
* @param result 要返回数据
|
|
285
|
+
* @param node 当前内容的上下级
|
|
286
|
+
* @returns 返回排序后的数组
|
|
287
|
+
* 因为ts会按照 a-z的顺序进行排序
|
|
288
|
+
* 但是影响用户体验,需要先按照页面排序,其次按照logic进行排序
|
|
289
|
+
* 流程的韬哥自己解决了,所以先解决这两部分
|
|
290
|
+
*/
|
|
291
|
+
function sortFirstVariableData(result: CompletionProperty[], node: BaseNode) {
|
|
292
|
+
const newResult: CompletionProperty[] = [];
|
|
293
|
+
const logic = (node as Param).logic;
|
|
294
|
+
const view = (node as Param).view;
|
|
295
|
+
if (view) {
|
|
296
|
+
const { params, variables } = view;
|
|
297
|
+
const list = [...params, ...variables];
|
|
298
|
+
list.forEach((item) => {
|
|
299
|
+
const findIndex = result.findIndex((findItem) => findItem.name === item.name);
|
|
300
|
+
if (findIndex === 0 || findIndex) {
|
|
301
|
+
newResult.push(result[findIndex]);
|
|
302
|
+
result.splice(findIndex, 1);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
if (logic) {
|
|
307
|
+
const { params, returns, variables } = logic;
|
|
308
|
+
const list = [...params, ...returns, ...variables];
|
|
309
|
+
list.forEach((item) => {
|
|
310
|
+
const findIndex = result.findIndex((findItem) => findItem.name === item.name);
|
|
311
|
+
if (findIndex === 0 || findIndex) {
|
|
312
|
+
newResult.push(result[findIndex]);
|
|
313
|
+
result.splice(findIndex, 1);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
newResult.push(...result);
|
|
318
|
+
return newResult;
|
|
319
|
+
}
|
package/src/server/getLogics.ts
CHANGED
|
@@ -74,13 +74,13 @@ export async function getLogics(node: CallLogic | BindEvent, needAllLogic: boole
|
|
|
74
74
|
}
|
|
75
75
|
nc.map((item) => {
|
|
76
76
|
item.logics = item.logics.filter((logic) => !logic.name.startsWith('import'));
|
|
77
|
-
item.expanded =
|
|
77
|
+
item.expanded = false;
|
|
78
78
|
item.originConcept = 'Entity';
|
|
79
79
|
return item;
|
|
80
80
|
});
|
|
81
81
|
const ps = app.processes.map((p) => {
|
|
82
82
|
const pItem = process2LogicNamespace(p);
|
|
83
|
-
pItem.expanded =
|
|
83
|
+
pItem.expanded = false;
|
|
84
84
|
pItem.originConcept = 'Process';
|
|
85
85
|
return pItem;
|
|
86
86
|
});
|
|
@@ -92,7 +92,7 @@ export async function getLogics(node: CallLogic | BindEvent, needAllLogic: boole
|
|
|
92
92
|
logics: app.logics,
|
|
93
93
|
children: [...nc, ...extensions, ...ps],
|
|
94
94
|
});
|
|
95
|
-
tree.expanded =
|
|
95
|
+
tree.expanded = false;
|
|
96
96
|
result.push(tree);
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -114,7 +114,7 @@ export async function getLogics(node: CallLogic | BindEvent, needAllLogic: boole
|
|
|
114
114
|
path: `elements.${toHump(item.name)}.logics`,
|
|
115
115
|
originConcept: 'ViewElement',
|
|
116
116
|
});
|
|
117
|
-
viewElement.expanded =
|
|
117
|
+
viewElement.expanded = false;
|
|
118
118
|
viewElements.push(viewElement);
|
|
119
119
|
}
|
|
120
120
|
});
|
|
@@ -126,7 +126,7 @@ export async function getLogics(node: CallLogic | BindEvent, needAllLogic: boole
|
|
|
126
126
|
logics: node.view.logics,
|
|
127
127
|
children: viewElements,
|
|
128
128
|
});
|
|
129
|
-
tree.expanded =
|
|
129
|
+
tree.expanded = false;
|
|
130
130
|
result.push(tree);
|
|
131
131
|
const systemTree = new Namespace({
|
|
132
132
|
name: 'category',
|
|
@@ -138,37 +138,37 @@ export async function getLogics(node: CallLogic | BindEvent, needAllLogic: boole
|
|
|
138
138
|
path: `process`,
|
|
139
139
|
title: '流程逻辑',
|
|
140
140
|
logics: stdlibNamespace.findChild('process').logics,
|
|
141
|
-
expanded:
|
|
141
|
+
expanded: false,
|
|
142
142
|
}),
|
|
143
143
|
new Namespace({
|
|
144
144
|
name: 'category',
|
|
145
145
|
path: `browser`,
|
|
146
146
|
title: '浏览器',
|
|
147
147
|
logics: stdlibNamespace.findChild('browser').logics,
|
|
148
|
-
expanded:
|
|
148
|
+
expanded: false,
|
|
149
149
|
}),
|
|
150
150
|
new Namespace({
|
|
151
151
|
name: 'category',
|
|
152
152
|
path: `auth`,
|
|
153
153
|
title: '认证与权限',
|
|
154
154
|
logics: stdlibNamespace.findChild('auth').logics,
|
|
155
|
-
expanded:
|
|
155
|
+
expanded: false,
|
|
156
156
|
}),
|
|
157
157
|
new Namespace({
|
|
158
158
|
name: 'category',
|
|
159
159
|
path: `configuration`,
|
|
160
160
|
title: '配置',
|
|
161
161
|
logics: stdlibNamespace.findChild('configuration').logics,
|
|
162
|
-
expanded:
|
|
162
|
+
expanded: false,
|
|
163
163
|
}),
|
|
164
164
|
],
|
|
165
|
-
expanded:
|
|
165
|
+
expanded: false,
|
|
166
166
|
});
|
|
167
167
|
if (!app.processes.length)
|
|
168
168
|
systemTree.children.shift();
|
|
169
169
|
|
|
170
|
-
systemTree.expanded =
|
|
171
|
-
systemTree.children.forEach((child) => (child.expanded =
|
|
170
|
+
systemTree.expanded = false;
|
|
171
|
+
systemTree.children.forEach((child) => (child.expanded = false));
|
|
172
172
|
result.push(systemTree);
|
|
173
173
|
} else {
|
|
174
174
|
// 增加全局逻辑中的系统逻辑
|
|
@@ -182,25 +182,26 @@ export async function getLogics(node: CallLogic | BindEvent, needAllLogic: boole
|
|
|
182
182
|
path: `process`,
|
|
183
183
|
title: '流程逻辑',
|
|
184
184
|
logics: stdlibNamespace.findChild('process').logics,
|
|
185
|
-
expanded:
|
|
185
|
+
expanded: false,
|
|
186
186
|
}),
|
|
187
187
|
new Namespace({
|
|
188
188
|
name: 'category',
|
|
189
189
|
path: `configuration`,
|
|
190
190
|
title: '配置',
|
|
191
191
|
logics: stdlibNamespace.findChild('configuration').logics,
|
|
192
|
-
expanded:
|
|
192
|
+
expanded: false,
|
|
193
193
|
})
|
|
194
194
|
],
|
|
195
|
-
expanded:
|
|
195
|
+
expanded: false,
|
|
196
196
|
});
|
|
197
197
|
if (!app.processes.length)
|
|
198
198
|
systemTree.children.shift();
|
|
199
199
|
|
|
200
|
-
systemTree.expanded =
|
|
201
|
-
systemTree.children.forEach((child) => (child.expanded =
|
|
200
|
+
systemTree.expanded = false;
|
|
201
|
+
systemTree.children.forEach((child) => (child.expanded = false));
|
|
202
202
|
result.push(systemTree);
|
|
203
203
|
}
|
|
204
|
+
console.log(result)
|
|
204
205
|
return result;
|
|
205
206
|
}
|
|
206
207
|
}
|