@lcap/nasl 3.8.0-beta.8 → 3.8.2-alpha.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/.nyc_output/fe4ca6db-1eb6-4898-8aa5-ba8f8d4128f2.json +1 -0
- package/.nyc_output/processinfo/fe4ca6db-1eb6-4898-8aa5-ba8f8d4128f2.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/coverage/cobertura-coverage.xml +9325 -77393
- package/out/concepts/AuthLogicForCallInterface__.js +13 -2
- package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
- package/out/concepts/BackendVariable__.js +11 -1
- package/out/concepts/BackendVariable__.js.map +1 -1
- package/out/concepts/BindDirective__.js +1 -1
- package/out/concepts/BindDirective__.js.map +1 -1
- package/out/concepts/BindStyle__.js +1 -1
- package/out/concepts/BindStyle__.js.map +1 -1
- package/out/concepts/BusinessComponent__.js +14 -3
- package/out/concepts/BusinessComponent__.js.map +1 -1
- package/out/concepts/BusinessLogic__.js +13 -2
- package/out/concepts/BusinessLogic__.js.map +1 -1
- package/out/concepts/CallConnector__.js +2 -1
- package/out/concepts/CallConnector__.js.map +1 -1
- package/out/concepts/CallInterface__.js +12 -3
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.js +24 -1
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/EntityProperty__.js +3 -2
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/Entity__.js +1 -1
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/EnumItem__.js +2 -2
- package/out/concepts/EnumItem__.js.map +1 -1
- package/out/concepts/Interface__.js +1 -1
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/Logic__.js +13 -2
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/NewComposite__.d.ts +1 -0
- package/out/concepts/NewComposite__.js +23 -0
- package/out/concepts/NewComposite__.js.map +1 -1
- package/out/concepts/OverriddenLogic__.js +13 -2
- package/out/concepts/OverriddenLogic__.js.map +1 -1
- package/out/concepts/Param__.js +1 -1
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/Structure__.js +1 -3
- package/out/concepts/Structure__.js.map +1 -1
- package/out/concepts/SubLogic__.js +13 -2
- package/out/concepts/SubLogic__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.js +6 -3
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/ViewComponentDeclaration__.js +3 -3
- package/out/concepts/ViewComponentDeclaration__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +2 -0
- package/out/concepts/ViewElement__.js +60 -19
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.js +24 -2
- package/out/concepts/View__.js.map +1 -1
- package/out/generator/genBundleFiles.js +1 -1
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/natural/genNaturalTS.d.ts +69 -16
- package/out/natural/genNaturalTS.js +198 -117
- package/out/natural/genNaturalTS.js.map +1 -1
- package/out/natural/getContext/index.d.ts +38 -26
- package/out/natural/getContext/index.js +318 -160
- package/out/natural/getContext/index.js.map +1 -1
- package/out/natural/index.d.ts +1 -0
- package/out/natural/index.js +1 -0
- package/out/natural/index.js.map +1 -1
- package/out/natural/tools.d.ts +11 -0
- package/out/natural/tools.js +162 -0
- package/out/natural/tools.js.map +1 -0
- package/out/natural/transformTS2UI.js +63 -26
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.js +26 -15
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/server/naslServer.js +1 -0
- package/out/server/naslServer.js.map +1 -1
- package/out/translator/utils.js +1 -1
- package/out/translator/utils.js.map +1 -1
- package/package.json +1 -1
- package/sandbox/stdlib/nasl.util.ts +2 -2
- package/sandbox-natural/stdlib/nasl.core.ts +11 -0
- package/sandbox-natural/stdlib/nasl.ui.pre.d.ts +37 -37
- package/sandbox-natural/stdlib/nasl.util.ts +6 -6
- package/src/concepts/AuthLogicForCallInterface__.ts +13 -1
- package/src/concepts/BackendVariable__.ts +11 -1
- package/src/concepts/BindDirective__.ts +1 -1
- package/src/concepts/BindStyle__.ts +1 -1
- package/src/concepts/BusinessComponent__.ts +14 -2
- package/src/concepts/BusinessLogic__.ts +13 -1
- package/src/concepts/CallConnector__.ts +2 -1
- package/src/concepts/CallInterface__.ts +10 -3
- package/src/concepts/CallLogic__.ts +34 -14
- package/src/concepts/EntityProperty__.ts +5 -5
- package/src/concepts/Entity__.ts +1 -1
- package/src/concepts/EnumItem__.ts +2 -2
- package/src/concepts/Interface__.ts +1 -1
- package/src/concepts/Logic__.ts +13 -1
- package/src/concepts/NewComposite__.ts +24 -0
- package/src/concepts/OverriddenLogic__.ts +13 -1
- package/src/concepts/Param__.ts +1 -1
- package/src/concepts/Structure__.ts +1 -3
- package/src/concepts/SubLogic__.ts +13 -1
- package/src/concepts/TypeAnnotation__.ts +5 -3
- package/src/concepts/ViewComponentDeclaration__.ts +3 -3
- package/src/concepts/ViewElement__.ts +78 -19
- package/src/concepts/View__.ts +48 -24
- package/src/generator/genBundleFiles.ts +1 -1
- package/src/natural/genNaturalTS.ts +363 -147
- package/src/natural/getContext/index.ts +363 -175
- package/src/natural/index.ts +1 -0
- package/src/natural/tools.ts +138 -0
- package/src/natural/transformTS2UI.ts +60 -25
- package/src/natural/transformTSCode.ts +26 -16
- package/src/server/naslServer.ts +1 -0
- package/src/translator/utils.ts +1 -1
- package/.nyc_output/047fb941-6e69-4829-8b3c-14d37e06c63b.json +0 -1
- package/.nyc_output/processinfo/047fb941-6e69-4829-8b3c-14d37e06c63b.json +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { App, View, Logic, BaseNode, Frontend, Namespace, Module, TypeAnnotation, Structure } from '../../concepts';
|
|
1
|
+
import { App, View, Logic, BaseNode, Frontend, Namespace, Module, TypeAnnotation, Structure, Connection, Connector } from '../../concepts';
|
|
2
2
|
import { shiftState, createCompilerState, TranslatorState, indent } from '../../translator';
|
|
3
3
|
import { getPreDeclaration, getUILib, handleMaterial, getExtensionsMaterial } from './getUILib';
|
|
4
4
|
import { getNASLStdlibMap } from './naslStdlibMap';
|
|
@@ -6,6 +6,8 @@ import { getNASLStdlibMap } from './naslStdlibMap';
|
|
|
6
6
|
export interface Snippet {
|
|
7
7
|
description: string;
|
|
8
8
|
code: string;
|
|
9
|
+
codeWithDetail?: string;
|
|
10
|
+
namespace?: string;
|
|
9
11
|
}
|
|
10
12
|
export interface SnippetBlock {
|
|
11
13
|
namespace: string;
|
|
@@ -16,8 +18,34 @@ export const wrapTSBlock = (code: string) => {
|
|
|
16
18
|
return `\`\`\`ts\n${code.trimEnd()}\n\`\`\`\n`;
|
|
17
19
|
};
|
|
18
20
|
|
|
21
|
+
// 获取有引用的 structures
|
|
22
|
+
export function getReferenceStructures(referenceStructures: { typeNamespace: string; typeName: string; }[], structures: Structure[]): any {
|
|
23
|
+
const relationStructures = [] as any;
|
|
24
|
+
referenceStructures?.forEach((reference: { typeNamespace: string; typeName: string; }) => {
|
|
25
|
+
structures?.filter((structure: any) => structure?.name === reference?.typeName)
|
|
26
|
+
?.forEach((structure: any) => {
|
|
27
|
+
structure.properties?.forEach((property: any) => {
|
|
28
|
+
if (property?.typeAnnotation?.typeKind === 'reference' && referenceStructures.findIndex((item: any) => item.typeName === property?.typeAnnotation?.typeName) === -1) {
|
|
29
|
+
const { typeNamespace, typeName } = property?.typeAnnotation || {};
|
|
30
|
+
relationStructures.push({ typeNamespace, typeName });
|
|
31
|
+
}
|
|
32
|
+
if (property?.typeAnnotation?.typeArguments?.length) {
|
|
33
|
+
property?.typeAnnotation?.typeArguments?.forEach((typeArg: TypeAnnotation) => {
|
|
34
|
+
if (typeArg.typeKind === 'reference' && referenceStructures.findIndex((item: any) => item.typeName === typeArg.typeName) === -1) {
|
|
35
|
+
const { typeNamespace, typeName } = typeArg || {};
|
|
36
|
+
relationStructures.push({ typeNamespace, typeName });
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
if (!relationStructures.length) return relationStructures;
|
|
44
|
+
return [...relationStructures, ...getReferenceStructures(relationStructures, structures)];
|
|
45
|
+
}
|
|
46
|
+
|
|
19
47
|
// 获取logic用到的数据结构(带属性版)
|
|
20
|
-
export function
|
|
48
|
+
export function getLogicWithStructuresCode(logic: Logic, type: string, desc: { description: string; codeStr: string; }, namespace: string) {
|
|
21
49
|
const { params, returns } = logic || {};
|
|
22
50
|
if (!params?.length && !returns?.length) return '';
|
|
23
51
|
let code = '';
|
|
@@ -40,30 +68,32 @@ export function getLogicStructures(logic: Logic, type: string, desc: { descripti
|
|
|
40
68
|
});
|
|
41
69
|
}
|
|
42
70
|
});
|
|
43
|
-
|
|
71
|
+
|
|
72
|
+
let structures = [] as any;
|
|
73
|
+
if (type === 'connector') {
|
|
74
|
+
structures = logic?.connector?.structures;
|
|
75
|
+
} else if (type === 'extension' || type === 'interface') {
|
|
76
|
+
structures = (logic?.parentNode as Module)?.structures;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const relationStructures = getReferenceStructures(referenceStructures, structures);
|
|
80
|
+
|
|
81
|
+
const newRelationStructures = [...relationStructures, ...referenceStructures];
|
|
82
|
+
|
|
83
|
+
if (namespace && newRelationStructures?.length) {
|
|
44
84
|
code += `declare namespace ${namespace} {\n`;
|
|
45
85
|
}
|
|
46
86
|
|
|
47
|
-
|
|
48
|
-
const {
|
|
87
|
+
newRelationStructures?.forEach((reference: { typeNamespace: string; typeName: string; }) => {
|
|
88
|
+
const { typeName } = reference || {};
|
|
49
89
|
const state = createCompilerState();
|
|
50
90
|
const tabSize = namespace ? shiftState(state, code, { tabSize: 1 }) : undefined;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
code += `${structure?.toNaturalTS(tabSize)}\n`;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
if ((typeNamespace?.includes('extensions.') && type === 'extension') || (typeNamespace?.includes('apis.') && type === 'interface')) {
|
|
59
|
-
(logic?.parentNode as Module)?.structures
|
|
60
|
-
?.filter((structure) => structure?.name === typeName)
|
|
61
|
-
?.forEach((structure) => {
|
|
62
|
-
code += `${structure?.toNaturalTS(tabSize)}\n`;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
91
|
+
structures?.filter((structure: any) => structure?.name === typeName)
|
|
92
|
+
?.forEach((structure: any) => {
|
|
93
|
+
code += `${structure?.toNaturalTS(tabSize)}\n`;
|
|
94
|
+
});
|
|
65
95
|
});
|
|
66
|
-
if (namespace &&
|
|
96
|
+
if (namespace && newRelationStructures?.length) {
|
|
67
97
|
code += `}\n`;
|
|
68
98
|
}
|
|
69
99
|
const { description, codeStr } = desc || {};
|
|
@@ -89,37 +119,60 @@ export function getNaslUtil() {
|
|
|
89
119
|
return { code, naslUtil };
|
|
90
120
|
}
|
|
91
121
|
|
|
92
|
-
export const getNaslUI = (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
122
|
+
export const getNaslUI = (
|
|
123
|
+
app: App,
|
|
124
|
+
frontendType: 'pc' | 'h5',
|
|
125
|
+
material:
|
|
126
|
+
{
|
|
127
|
+
basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
|
|
128
|
+
extensionMaterials: {
|
|
129
|
+
name: string;
|
|
130
|
+
title: string;
|
|
131
|
+
description: string;
|
|
132
|
+
tsDescription: string;
|
|
133
|
+
}[];
|
|
134
|
+
},
|
|
135
|
+
) => {
|
|
136
|
+
let naslUI = [] as any;
|
|
137
|
+
if (material.basicMaterials) {
|
|
138
|
+
naslUI = typeof material.basicMaterials === 'string' ? getUILib(material.basicMaterials as 'pc' | 'h5') : handleMaterial(material.basicMaterials);
|
|
102
139
|
}
|
|
103
140
|
|
|
141
|
+
const extensionMaterials = typeof material.extensionMaterials === 'string' ? getExtensionsMaterial(app, frontendType) : material.extensionMaterials || [];
|
|
142
|
+
naslUI.push(...extensionMaterials);
|
|
143
|
+
|
|
144
|
+
return { naslUI };
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export const getNaslUICode = (naslUI: any, codeType: 'detail' | 'short', requiredIndexes?: string[]) => {
|
|
148
|
+
let code = '';
|
|
104
149
|
const preDeclaration = getPreDeclaration();
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
item
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
150
|
+
let uiLib = naslUI;
|
|
151
|
+
if (requiredIndexes?.length) {
|
|
152
|
+
// 过滤出需要的组件
|
|
153
|
+
uiLib = naslUI.filter(
|
|
154
|
+
(item: any, index: number) =>
|
|
155
|
+
requiredIndexes.includes(`3-${index}`) ||
|
|
156
|
+
item.name.endsWith('LinearLayout') ||
|
|
157
|
+
item.name.endsWith('Text') ||
|
|
158
|
+
item.name.endsWith('Link') ||
|
|
159
|
+
item.name.endsWith('Button')
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
if (codeType === 'detail') {
|
|
163
|
+
code = wrapTSBlock(
|
|
164
|
+
`${preDeclaration}\n${uiLib
|
|
165
|
+
.map(
|
|
166
|
+
(item: any) => `/**
|
|
117
167
|
* ${item.name}
|
|
118
168
|
* ${item.title}
|
|
119
169
|
* ${item.description}
|
|
120
170
|
*/
|
|
121
171
|
${item.tsDeclaration}`).join('\n')}`);
|
|
122
|
-
|
|
172
|
+
} else {
|
|
173
|
+
code += uiLib.map((item: any, index: number) => `[3-${index}] ${item.name} | ${item.title} | ${item.description}`).join('\n');
|
|
174
|
+
}
|
|
175
|
+
return code;
|
|
123
176
|
};
|
|
124
177
|
|
|
125
178
|
export const getNaslUIOld = () => {
|
|
@@ -134,92 +187,122 @@ export function getNaslOQL() {
|
|
|
134
187
|
return { code, naslOql };
|
|
135
188
|
}
|
|
136
189
|
|
|
137
|
-
export function getEnums(app: App, state: TranslatorState
|
|
138
|
-
const needNamespace = requiredIndexes?.length >= 0;
|
|
190
|
+
export function getEnums(app: App, state: TranslatorState) {
|
|
139
191
|
const namespace = 'app.enums';
|
|
140
192
|
const data = [] as Snippet[];
|
|
141
|
-
let code = '';
|
|
142
|
-
code += `declare namespace ${namespace} {\n`;
|
|
143
193
|
app.enums.forEach((enumeration) => {
|
|
144
|
-
const temp = `${enumeration?.toNaturalTS({ ...state, needNamespace })}`;
|
|
145
|
-
code += temp;
|
|
194
|
+
const temp = `${enumeration?.toNaturalTS({ ...state, needNamespace: true, })}`;
|
|
146
195
|
data.push({ description: enumeration?.description || enumeration?.name, code: temp });
|
|
147
196
|
});
|
|
197
|
+
return { namespace, enums: { namespace, data } };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export const getEnumsCode = (enums: any) => {
|
|
201
|
+
let code = '';
|
|
202
|
+
code += `declare namespace ${enums?.namespace} {\n`;
|
|
203
|
+
enums?.data?.forEach((item: any) => {
|
|
204
|
+
// code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
205
|
+
code += `${item.code}\n`;
|
|
206
|
+
});
|
|
148
207
|
code += `}\n`;
|
|
149
208
|
code = wrapTSBlock(code);
|
|
150
|
-
return
|
|
151
|
-
}
|
|
209
|
+
return code;
|
|
210
|
+
};
|
|
152
211
|
|
|
153
|
-
export function getEntities(app: App, state: TranslatorState
|
|
154
|
-
const needNamespace = requiredIndexes?.length >= 0;
|
|
212
|
+
export function getEntities(app: App, state: TranslatorState) {
|
|
155
213
|
const entities = [] as SnippetBlock[];
|
|
156
|
-
let code = '';
|
|
157
214
|
app.dataSources.forEach((dataSource) => {
|
|
158
215
|
const data = [] as Snippet[];
|
|
159
216
|
const namespace = `app.dataSources.${dataSource?.name}.entities`;
|
|
160
|
-
code += `declare namespace ${namespace} {\n`;
|
|
161
217
|
dataSource.entities
|
|
162
|
-
.filter((entity) => !entity.name.startsWith('LCAP') || entity.name === 'LCAPUser')
|
|
218
|
+
// .filter((entity) => !entity.name.startsWith('LCAP') || entity.name === 'LCAPUser')
|
|
163
219
|
.forEach((entity) => {
|
|
164
|
-
const entityName =
|
|
165
|
-
const tempCode = `${entity?.toNaturalTS({ ...state, needNamespace }, entityName)}`;
|
|
166
|
-
code += tempCode;
|
|
220
|
+
const entityName = `app.dataSources.${dataSource?.name}.entities.${entity?.name}`;
|
|
221
|
+
const tempCode = `${entity?.toNaturalTS({ ...state, needNamespace: true }, entityName)}`;
|
|
167
222
|
data.push({ description: entity?.description || entity?.name, code: tempCode });
|
|
168
223
|
});
|
|
169
224
|
entities.push({ namespace, data });
|
|
225
|
+
});
|
|
226
|
+
return { entities };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export const getEntitiesCode = (entities: any) => {
|
|
230
|
+
let code = '';
|
|
231
|
+
entities?.forEach((entity: any) => {
|
|
232
|
+
code += `declare namespace ${entity?.namespace} {\n`;
|
|
233
|
+
entity?.data?.forEach((item: any) => {
|
|
234
|
+
// code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
235
|
+
code += `${item.code}\n`;
|
|
236
|
+
});
|
|
170
237
|
code += `}\n`;
|
|
171
238
|
});
|
|
172
239
|
code = wrapTSBlock(code);
|
|
173
|
-
return
|
|
174
|
-
}
|
|
240
|
+
return code;
|
|
241
|
+
};
|
|
175
242
|
|
|
176
|
-
export function getStructures(app: App, state: TranslatorState
|
|
177
|
-
const needNamespace = requiredIndexes?.length >= 0;
|
|
243
|
+
export function getStructures(app: App, state: TranslatorState) {
|
|
178
244
|
const data = [] as Snippet[];
|
|
179
245
|
const namespace = `app.structures`;
|
|
180
|
-
let code = '';
|
|
181
|
-
code += `declare namespace ${namespace} {\n`;
|
|
182
246
|
app.structures
|
|
183
|
-
.filter((entity) => !entity.name.startsWith('LCAP'))
|
|
247
|
+
// .filter((entity) => !entity.name.startsWith('LCAP'))
|
|
184
248
|
.forEach((structure) => {
|
|
185
|
-
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace })}`;
|
|
186
|
-
code += tempCode;
|
|
249
|
+
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}`;
|
|
187
250
|
data.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
188
251
|
});
|
|
252
|
+
return { structures: { namespace, data } };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export const getStructuresCode = (structures: any) => {
|
|
256
|
+
let code = '';
|
|
257
|
+
code += `declare namespace ${structures?.namespace} {\n`;
|
|
258
|
+
structures?.data?.forEach((item: any) => {
|
|
259
|
+
// code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
260
|
+
code += `${item.code}\n`;
|
|
261
|
+
});
|
|
189
262
|
code += `}\n`;
|
|
190
263
|
code = wrapTSBlock(code);
|
|
191
|
-
return
|
|
192
|
-
}
|
|
264
|
+
return code;
|
|
265
|
+
};
|
|
266
|
+
|
|
193
267
|
|
|
194
|
-
export function getLogics(app: App, currentNode: BaseNode,
|
|
195
|
-
const hasModuleIndexList = requiredIndexes?.length > 0;
|
|
268
|
+
export function getLogics(app: App, currentNode: BaseNode, state: TranslatorState) {
|
|
196
269
|
const data = [] as Snippet[];
|
|
197
270
|
const namespace = `app.logics`;
|
|
198
|
-
let code = '';
|
|
199
271
|
app?.logics
|
|
200
272
|
?.filter((logic) => logic !== currentNode && !logic.name.startsWith('LCAP'))
|
|
201
|
-
?.forEach((logic
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
const rename = requiredIndexes?.length >= 0 ? logic?.calleewholeKey : undefined;
|
|
205
|
-
const needNamespace = requiredIndexes?.length >= 0;
|
|
206
|
-
const tempCode = `${logic?.toNaturalTS({ needNamespace, rename, declaration: true })}`;
|
|
273
|
+
?.forEach((logic) => {
|
|
274
|
+
const rename = logic?.calleewholeKey;
|
|
275
|
+
const tempCode = `${logic?.toNaturalTS({ ...state, needNamespace: true, rename, declaration: true })}`;
|
|
207
276
|
const description = logic?.description || '';
|
|
208
|
-
|
|
277
|
+
|
|
209
278
|
data.push({ description, code: tempCode });
|
|
210
279
|
});
|
|
211
|
-
return {
|
|
280
|
+
return { appLogics: { namespace, data } };
|
|
212
281
|
}
|
|
213
282
|
|
|
214
|
-
|
|
215
|
-
|
|
283
|
+
|
|
284
|
+
export const getLogicsCode = (appLogics: any, codeType: 'detail' | 'short', requiredIndexes?: string[]) => {
|
|
285
|
+
let code = '';
|
|
286
|
+
appLogics?.data?.forEach((item: any, index: number) => {
|
|
287
|
+
const logicIndex = `6-${index}`;
|
|
288
|
+
if (requiredIndexes?.length && !requiredIndexes?.includes(logicIndex)) return;
|
|
289
|
+
const tempCode = codeType === 'short' ? item.code.replace(`${appLogics.namespace}.`, '') : item.code;
|
|
290
|
+
code += `[${logicIndex}] \`${tempCode}\`\n`;
|
|
291
|
+
// code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
292
|
+
});
|
|
293
|
+
return code;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
export function getModuleInterfaces(modules: Module[], state: TranslatorState) {
|
|
216
298
|
const interfaceDependencies = [] as {
|
|
217
299
|
name: string;
|
|
218
300
|
structures: SnippetBlock;
|
|
219
301
|
logics: SnippetBlock;
|
|
220
302
|
}[];
|
|
221
|
-
|
|
222
|
-
|
|
303
|
+
modules?.forEach((interfaceDependency) => {
|
|
304
|
+
interfaceDependency = new Module(interfaceDependency);
|
|
305
|
+
interfaceDependency.parentKey = 'interfaceDependencies';
|
|
223
306
|
const name = interfaceDependency?.name;
|
|
224
307
|
let structures = {} as SnippetBlock;
|
|
225
308
|
let logics = {} as SnippetBlock;
|
|
@@ -234,37 +317,47 @@ export function getModuleInterfaces(app: App, state: TranslatorState, requiredIn
|
|
|
234
317
|
|
|
235
318
|
const logicNamespace = `${namespace}.interfaces`;
|
|
236
319
|
const logicData = [] as Snippet[];
|
|
237
|
-
interfaceDependency?.interfaces?.forEach((interface_: any
|
|
238
|
-
const interfaceIndex = `7-${moduleIndex}-${index}`;
|
|
239
|
-
if (hasModuleIndexList && !requiredIndexes?.includes(interfaceIndex)) return;
|
|
320
|
+
interfaceDependency?.interfaces?.forEach((interface_: any) => {
|
|
240
321
|
const description = interface_?.description || '';
|
|
241
|
-
const interfaceName =
|
|
242
|
-
const
|
|
243
|
-
const
|
|
244
|
-
logicData.push({ description, code: tempCode });
|
|
245
|
-
|
|
246
|
-
if (requiredIndexes?.includes(interfaceIndex)) {
|
|
247
|
-
code += getLogicStructures(interface_, 'interface', { description, codeStr: tempCode }, structureNamespace);
|
|
248
|
-
} else {
|
|
249
|
-
code += `[${interfaceIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
250
|
-
}
|
|
322
|
+
const interfaceName = interface_?.calleewholeKey;
|
|
323
|
+
const tempCode = `${interface_?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename: interfaceName, declaration: true }))}`;
|
|
324
|
+
const codeWithDetail = getLogicWithStructuresCode(interface_, 'interface', { description, codeStr: tempCode }, structureNamespace);
|
|
325
|
+
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
251
326
|
});
|
|
252
327
|
logics = { namespace: logicNamespace, data: logicData };
|
|
253
328
|
|
|
254
329
|
interfaceDependencies.push({ name, structures, logics });
|
|
255
330
|
});
|
|
256
|
-
return {
|
|
331
|
+
return { interfaceDependencies };
|
|
257
332
|
}
|
|
258
333
|
|
|
259
|
-
export
|
|
260
|
-
|
|
334
|
+
export const getModuleInterfacesCode = (interfaceDependencies: any, codeType: 'detail' | 'short', requiredIndexes?: string[]) => {
|
|
335
|
+
let code = '';
|
|
336
|
+
interfaceDependencies.forEach((interfaceDependency: any, index: number) => {
|
|
337
|
+
interfaceDependency?.logics?.data?.forEach((item: any, idx: number) => {
|
|
338
|
+
const interfaceIndex = `7-${index}-${idx}`;
|
|
339
|
+
if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex)) return;
|
|
340
|
+
if (codeType === 'short') {
|
|
341
|
+
const tempCode = item.code.replace(`${interfaceDependency?.logics.namespace}.`, '');
|
|
342
|
+
code += `[${interfaceIndex}] \`${tempCode}\`\n`;
|
|
343
|
+
// code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
344
|
+
} else {
|
|
345
|
+
code += item.codeWithDetail;
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
return code;
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
// 连接
|
|
354
|
+
export function getConnections(modules: Connection[], state: TranslatorState) {
|
|
261
355
|
const connections = [] as {
|
|
262
356
|
name: string;
|
|
263
357
|
structures: SnippetBlock;
|
|
264
358
|
logics: SnippetBlock;
|
|
265
359
|
}[];
|
|
266
|
-
|
|
267
|
-
app?.connections?.forEach((connection, connectionIndex) => {
|
|
360
|
+
modules?.forEach((connection) => {
|
|
268
361
|
const name = connection?.name;
|
|
269
362
|
|
|
270
363
|
let structures = {} as SnippetBlock;
|
|
@@ -279,106 +372,191 @@ export function getConnectors(app: App, state: TranslatorState, requiredIndexes?
|
|
|
279
372
|
});
|
|
280
373
|
structures = { namespace: structureNamespace, data: structureData };
|
|
281
374
|
|
|
282
|
-
code += `[8-${connectionIndex}] ${connection?.connector?.title}\n`;
|
|
283
375
|
const logicData = [] as Snippet[];
|
|
284
|
-
connection?.connector?.namespaces?.forEach((namespace: Namespace
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex)) return;
|
|
376
|
+
connection?.connector?.namespaces?.forEach((namespace: Namespace) => {
|
|
377
|
+
const curNameSpace = `${connectionNamespace}.${namespace?.name}`;
|
|
378
|
+
namespace?.logics?.forEach((logic: Logic) => {
|
|
288
379
|
const description = `${logic?.description || logic?.title || ''}`;
|
|
289
|
-
const rename =
|
|
290
|
-
const
|
|
291
|
-
const
|
|
292
|
-
logicData.push({ description, code: tempCode });
|
|
293
|
-
|
|
294
|
-
if (requiredIndexes?.includes(logicIndex)) {
|
|
295
|
-
code += getLogicStructures(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
296
|
-
} else {
|
|
297
|
-
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
298
|
-
}
|
|
380
|
+
const rename = `${connection?.name}.${logic?.calleewholeKey}`;
|
|
381
|
+
const tempCode = `${logic?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
382
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
383
|
+
logicData.push({ description, code: tempCode, codeWithDetail, namespace: curNameSpace });
|
|
299
384
|
});
|
|
300
385
|
});
|
|
301
386
|
|
|
302
387
|
if (!connection?.connector?.namespaces?.length && connection?.connector?.logics?.length) {
|
|
303
|
-
connection?.connector?.logics.forEach((logic: Logic
|
|
304
|
-
const logicIndex = `8-${connectionIndex}-${index}`;
|
|
305
|
-
if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex)) return;
|
|
388
|
+
connection?.connector?.logics.forEach((logic: Logic) => {
|
|
306
389
|
const description = logic?.description || '';
|
|
307
|
-
const rename =
|
|
308
|
-
const
|
|
309
|
-
const
|
|
310
|
-
logicData.push({ description, code: tempCode });
|
|
311
|
-
|
|
312
|
-
if (requiredIndexes?.includes(logicIndex)) {
|
|
313
|
-
code += getLogicStructures(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
314
|
-
} else {
|
|
315
|
-
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
316
|
-
}
|
|
390
|
+
const rename = `${connection?.name}.${logic?.calleewholeKey}`;
|
|
391
|
+
const tempCode = `${logic?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
392
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
393
|
+
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
317
394
|
});
|
|
318
395
|
}
|
|
319
396
|
logics = { namespace: connectionNamespace, data: logicData };
|
|
320
397
|
connections.push({ name, structures, logics });
|
|
321
398
|
});
|
|
322
|
-
return {
|
|
399
|
+
return { connections };
|
|
323
400
|
}
|
|
324
401
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const
|
|
402
|
+
// 连接器
|
|
403
|
+
export function getConnectors(modules: Connector[], state: TranslatorState) {
|
|
404
|
+
const connectors = [] as {
|
|
328
405
|
name: string;
|
|
329
406
|
structures: SnippetBlock;
|
|
330
407
|
logics: SnippetBlock;
|
|
331
408
|
}[];
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
});
|
|
348
|
-
structures = { namespace: structureNamespace, data: structureData };
|
|
349
|
-
|
|
350
|
-
const logicsNamespace = `${namespace}.logics`;
|
|
351
|
-
const logicData = [] as Snippet[];
|
|
352
|
-
module?.logics?.forEach((logic, index) => {
|
|
353
|
-
const logicIndex = `9-${moduleIndex}-${index}`;
|
|
354
|
-
if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex)) return;
|
|
355
|
-
const description = logic?.description || '';
|
|
356
|
-
const rename = requiredIndexes?.length >= 0 ? logic?.calleewholeKey : undefined;
|
|
357
|
-
const needNamespace = requiredIndexes?.length >= 0;
|
|
358
|
-
const tempCode = `${logic?.toNaturalTS(shiftState(state, code, { needNamespace, rename, declaration: true }))}`;
|
|
359
|
-
logicData.push({ description, code: tempCode });
|
|
360
|
-
|
|
361
|
-
if (requiredIndexes?.includes(logicIndex)) {
|
|
362
|
-
code += getLogicStructures(logic, 'extension', { description, codeStr: tempCode }, structureNamespace);
|
|
363
|
-
} else {
|
|
364
|
-
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
logics = { namespace: logicsNamespace, data: logicData };
|
|
409
|
+
modules?.forEach((connector) => {
|
|
410
|
+
connector = new Connector(connector);
|
|
411
|
+
connector.parentKey = 'connectorDependencies';
|
|
412
|
+
const { name } = connector;
|
|
413
|
+
let structures = {} as SnippetBlock;
|
|
414
|
+
let logics = {} as SnippetBlock;
|
|
415
|
+
|
|
416
|
+
const connectorNamespace = `${name}.connector.${name}`;
|
|
417
|
+
const structureNamespace = `connector.${name}.structures`;
|
|
418
|
+
const structureData = [] as Snippet[];
|
|
419
|
+
connector?.structures?.forEach((structure: Structure) => {
|
|
420
|
+
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}`;
|
|
421
|
+
structureData.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
422
|
+
});
|
|
423
|
+
structures = { namespace: structureNamespace, data: structureData };
|
|
368
424
|
|
|
369
|
-
|
|
425
|
+
const logicData = [] as Snippet[];
|
|
426
|
+
connector?.namespaces?.forEach((namespace: Namespace) => {
|
|
427
|
+
const curNameSpace = `${connectorNamespace}.${namespace?.name}`;
|
|
428
|
+
namespace?.logics?.forEach((logic: Logic) => {
|
|
429
|
+
const description = `${logic?.description || logic?.title || ''}`;
|
|
430
|
+
const rename = `${name}.${logic?.calleewholeKey}`;
|
|
431
|
+
const tempCode = `${logic?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
432
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
433
|
+
logicData.push({ description, code: tempCode, codeWithDetail, namespace: curNameSpace });
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
if (!connector?.namespaces?.length && connector?.logics?.length) {
|
|
438
|
+
connector?.logics.forEach((logic: Logic) => {
|
|
439
|
+
const description = logic?.description || '';
|
|
440
|
+
const rename = `${name}.${logic?.calleewholeKey}`;
|
|
441
|
+
const tempCode = `${logic?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
442
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
443
|
+
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
logics = { namespace: connectorNamespace, data: logicData };
|
|
447
|
+
connectors.push({ name, structures, logics });
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
return { connectors };
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export const getConnectorsCode = (connections: any, codeType: 'detail' | 'short', requiredIndexes?: string[]) => {
|
|
454
|
+
let code = '';
|
|
455
|
+
connections.forEach((connection: any, index: number) => {
|
|
456
|
+
connection?.logics?.data?.forEach((item: any, idx: number) => {
|
|
457
|
+
const interfaceIndex = `8-${index}-${idx}`;
|
|
458
|
+
if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex)) return;
|
|
459
|
+
if (codeType === 'short') {
|
|
460
|
+
const namespace = item?.namespace || connection?.logics.namespace;
|
|
461
|
+
const tempCode = item.code.replace(`${namespace}.`, '');
|
|
462
|
+
code += `[${interfaceIndex}] \`${tempCode}\`\n`;
|
|
463
|
+
// code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
464
|
+
} else {
|
|
465
|
+
code += item.codeWithDetail;
|
|
370
466
|
}
|
|
371
467
|
});
|
|
372
|
-
|
|
468
|
+
});
|
|
469
|
+
return code;
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
export function getDependencies(modules: Module[], state: TranslatorState, logicType: any, frontendType: 'pc' | 'h5') {
|
|
474
|
+
const dependencies = [] as {
|
|
475
|
+
name: string;
|
|
476
|
+
structures: SnippetBlock;
|
|
477
|
+
logics: SnippetBlock;
|
|
478
|
+
}[];
|
|
479
|
+
modules?.forEach((module) => {
|
|
480
|
+
module = new Module(module);
|
|
481
|
+
module.parentKey = 'dependencies';
|
|
482
|
+
// 根据类型获取对应的逻辑
|
|
483
|
+
let curLogics = module?.logics;
|
|
484
|
+
if (logicType !== 'global_logic' && frontendType) {
|
|
485
|
+
module?.frontends?.forEach((frontend: any) => {
|
|
486
|
+
if (frontend.type === frontendType) {
|
|
487
|
+
curLogics = curLogics.concat([...frontend?.logics]);
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (curLogics?.length) {
|
|
493
|
+
const name = module?.name;
|
|
494
|
+
let structures = {} as SnippetBlock;
|
|
495
|
+
let logics = {} as SnippetBlock;
|
|
496
|
+
const namespace = `extensions.${name}`;
|
|
497
|
+
const structureNamespace = `${namespace}.structures`;
|
|
498
|
+
const structureData = [] as Snippet[];
|
|
499
|
+
module?.structures?.forEach((structure) => {
|
|
500
|
+
const tempCode = structure?.toNaturalTS ? `${structure?.toNaturalTS({ ...state, needNamespace: true })}` : '';
|
|
501
|
+
structureData.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
502
|
+
});
|
|
503
|
+
structures = { namespace: structureNamespace, data: structureData };
|
|
504
|
+
|
|
505
|
+
let logicsNamespace = '';
|
|
506
|
+
const logicData = [] as Snippet[];
|
|
507
|
+
curLogics?.forEach((logic) => {
|
|
508
|
+
const description = logic?.description || '';
|
|
509
|
+
const rename = logic?.calleewholeKey;
|
|
510
|
+
logicsNamespace = logic?.calleewholeKey.replace(`.${logic.name}`, '');
|
|
511
|
+
const tempCode = `${logic?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
512
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'extension', { description, codeStr: tempCode }, structureNamespace);
|
|
513
|
+
|
|
514
|
+
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
515
|
+
});
|
|
516
|
+
logics = { namespace: logicsNamespace, data: logicData };
|
|
517
|
+
|
|
518
|
+
dependencies.push({ name, structures, logics });
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
return { dependencies };
|
|
373
522
|
}
|
|
374
523
|
|
|
524
|
+
|
|
525
|
+
export const getDependenciesCode = (dependencies: any, codeType: 'detail' | 'short', requiredIndexes?: string[]) => {
|
|
526
|
+
let code = '';
|
|
527
|
+
dependencies.forEach((dependency: any, index: number) => {
|
|
528
|
+
dependency?.logics?.data?.forEach((item: any, idx: number) => {
|
|
529
|
+
const logicIndex = `9-${index}-${idx}`;
|
|
530
|
+
if (requiredIndexes?.length && !requiredIndexes?.includes(logicIndex)) return;
|
|
531
|
+
if (codeType === 'short') {
|
|
532
|
+
const tempCode = item.code.replace(`${dependency?.logics.namespace}.`, '');
|
|
533
|
+
code += `[${logicIndex}] \`${tempCode}\`\n`;
|
|
534
|
+
// code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
535
|
+
} else {
|
|
536
|
+
code += item.codeWithDetail;
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
return code;
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
|
|
375
544
|
export function getFrontendVariables(frontend: Frontend, state: TranslatorState) {
|
|
376
545
|
let code = '';
|
|
377
546
|
frontend?.variables?.forEach((variable) => {
|
|
378
547
|
const tempCode = `let ${variable?.toNaturalTS(shiftState(state, code, { inline: true }))};\n`;
|
|
379
548
|
code += tempCode;
|
|
380
549
|
});
|
|
381
|
-
return { code: wrapTSBlock(code),
|
|
550
|
+
return { code: wrapTSBlock(code), frontendVariables: code };
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
export function getServerVariables(app: App, state: TranslatorState) {
|
|
554
|
+
let code = '';
|
|
555
|
+
app.backend?.variables?.forEach((variable) => {
|
|
556
|
+
const tempCode = `let ${variable?.toNaturalTS(shiftState(state, code, { inline: true }))};\n`;
|
|
557
|
+
code += tempCode;
|
|
558
|
+
});
|
|
559
|
+
return { code: wrapTSBlock(code), backendVariables: code };
|
|
382
560
|
}
|
|
383
561
|
|
|
384
562
|
export function getChildrenViews(view: View, currentNode: BaseNode, convertChildren: boolean, prefix: string) {
|
|
@@ -428,6 +606,16 @@ export function getFrontendViews(frontend: Frontend, state: TranslatorState, cur
|
|
|
428
606
|
return { code: wrapTSBlock(code), views: { namespace, data } };
|
|
429
607
|
}
|
|
430
608
|
|
|
609
|
+
export const getFrontendViewsCode = (views: any) => {
|
|
610
|
+
let code = '';
|
|
611
|
+
views?.data?.forEach((item: any) => {
|
|
612
|
+
code += `/* ${item.description} */ \n`;
|
|
613
|
+
code += item.code;
|
|
614
|
+
code += `\n`;
|
|
615
|
+
});
|
|
616
|
+
return wrapTSBlock(code);
|
|
617
|
+
};
|
|
618
|
+
|
|
431
619
|
export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: string, experimental?: boolean) {
|
|
432
620
|
let code = '';
|
|
433
621
|
let view: View;
|
|
@@ -457,7 +645,7 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
|
|
|
457
645
|
function (state) {
|
|
458
646
|
let code = '';
|
|
459
647
|
code += `\n${indent(state.tabSize)}`;
|
|
460
|
-
|
|
648
|
+
|
|
461
649
|
if (experimental) {
|
|
462
650
|
code += this.elements[0].toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1 }));
|
|
463
651
|
} else {
|