@lcap/nasl 3.8.0-beta.6 → 3.8.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/concepts/CallLogic__.js +2 -2
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/Logic__.js +2 -11
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/NullLiteral__.js +0 -6
- package/out/concepts/NullLiteral__.js.map +1 -1
- package/out/concepts/ViewComponentDeclaration__.js +3 -3
- package/out/concepts/ViewComponentDeclaration__.js.map +1 -1
- package/out/generator/release-body/body.d.ts +0 -4
- package/out/generator/release-body/body.js +2 -2
- package/out/generator/release-body/body.js.map +1 -1
- package/out/generator/release-body/index.d.ts +0 -1
- package/out/generator/release-body/index.js +0 -1
- package/out/generator/release-body/index.js.map +1 -1
- package/out/natural/genNaturalTS.d.ts +56 -24
- package/out/natural/genNaturalTS.js +182 -114
- package/out/natural/genNaturalTS.js.map +1 -1
- package/out/natural/getContext/getUILib.js +9 -5
- package/out/natural/getContext/getUILib.js.map +1 -1
- package/out/natural/getContext/index.d.ts +34 -25
- package/out/natural/getContext/index.js +302 -157
- 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 +156 -0
- package/out/natural/tools.js.map +1 -0
- package/out/natural/transformTS2UI.js +5 -1
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.js +4 -1
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/server/naslServer.js +3 -3
- package/out/server/naslServer.js.map +1 -1
- package/package.json +2 -2
- package/src/concepts/CallLogic__.ts +2 -2
- package/src/concepts/Logic__.ts +2 -11
- package/src/concepts/NullLiteral__.ts +0 -7
- package/src/concepts/ViewComponentDeclaration__.ts +3 -3
- package/src/generator/release-body/body.ts +7 -7
- package/src/generator/release-body/index.ts +0 -1
- package/src/natural/genNaturalTS.ts +328 -144
- package/src/natural/getContext/getUILib.ts +9 -5
- package/src/natural/getContext/index.ts +346 -171
- package/src/natural/index.ts +1 -0
- package/src/natural/tools.ts +132 -0
- package/src/natural/transformTS2UI.ts +4 -1
- package/src/natural/transformTSCode.ts +3 -1
- package/src/server/naslServer.ts +3 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCurrentNodeContextForUI = exports.getCurrentNodeContext = exports.getFrontendViews = exports.getChildrenViews = exports.getFrontendVariables = exports.getDependencies = exports.getConnectors = exports.getModuleInterfaces = exports.getLogics = exports.getStructures = exports.getEntities = exports.getEnums = exports.getNaslOQL = exports.getNaslUIOld = exports.getNaslUI = exports.getNaslUtil = exports.getNaslCore = exports.
|
|
3
|
+
exports.getCurrentNodeContextForUI = exports.getCurrentNodeContext = exports.getFrontendViewsCode = exports.getFrontendViews = exports.getChildrenViews = exports.getFrontendVariables = exports.getDependenciesCode = exports.getDependencies = exports.getConnectorsCode = exports.getConnectors = exports.getConnections = exports.getModuleInterfacesCode = exports.getModuleInterfaces = exports.getLogicsCode = exports.getLogics = exports.getStructuresCode = exports.getStructures = exports.getEntitiesCode = exports.getEntities = exports.getEnumsCode = exports.getEnums = exports.getNaslOQL = exports.getNaslUIOld = exports.getNaslUICode = exports.getNaslUI = exports.getNaslUtil = exports.getNaslCore = exports.getLogicWithStructuresCode = exports.getReferenceStructures = exports.wrapTSBlock = void 0;
|
|
4
|
+
const concepts_1 = require("../../concepts");
|
|
4
5
|
const translator_1 = require("../../translator");
|
|
5
6
|
const getUILib_1 = require("./getUILib");
|
|
6
7
|
const naslStdlibMap_1 = require("./naslStdlibMap");
|
|
@@ -8,8 +9,35 @@ const wrapTSBlock = (code) => {
|
|
|
8
9
|
return `\`\`\`ts\n${code.trimEnd()}\n\`\`\`\n`;
|
|
9
10
|
};
|
|
10
11
|
exports.wrapTSBlock = wrapTSBlock;
|
|
12
|
+
// 获取有引用的 structures
|
|
13
|
+
function getReferenceStructures(referenceStructures, structures) {
|
|
14
|
+
const relationStructures = [];
|
|
15
|
+
referenceStructures?.forEach((reference) => {
|
|
16
|
+
structures?.filter((structure) => structure?.name === reference?.typeName)
|
|
17
|
+
?.forEach((structure) => {
|
|
18
|
+
structure.properties?.forEach((property) => {
|
|
19
|
+
if (property?.typeAnnotation?.typeKind === 'reference' && referenceStructures.findIndex((item) => item.typeName === property?.typeAnnotation?.typeName) === -1) {
|
|
20
|
+
const { typeNamespace, typeName } = property?.typeAnnotation || {};
|
|
21
|
+
relationStructures.push({ typeNamespace, typeName });
|
|
22
|
+
}
|
|
23
|
+
if (property?.typeAnnotation?.typeArguments?.length) {
|
|
24
|
+
property?.typeAnnotation?.typeArguments?.forEach((typeArg) => {
|
|
25
|
+
if (typeArg.typeKind === 'reference' && referenceStructures.findIndex((item) => item.typeName === typeArg.typeName) === -1) {
|
|
26
|
+
const { typeNamespace, typeName } = typeArg || {};
|
|
27
|
+
relationStructures.push({ typeNamespace, typeName });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
if (!relationStructures.length)
|
|
35
|
+
return relationStructures;
|
|
36
|
+
return [...relationStructures, ...getReferenceStructures(relationStructures, structures)];
|
|
37
|
+
}
|
|
38
|
+
exports.getReferenceStructures = getReferenceStructures;
|
|
11
39
|
// 获取logic用到的数据结构(带属性版)
|
|
12
|
-
function
|
|
40
|
+
function getLogicWithStructuresCode(logic, type, desc, namespace) {
|
|
13
41
|
const { params, returns } = logic || {};
|
|
14
42
|
if (!params?.length && !returns?.length)
|
|
15
43
|
return '';
|
|
@@ -31,29 +59,28 @@ function getLogicStructures(logic, type, desc, namespace) {
|
|
|
31
59
|
});
|
|
32
60
|
}
|
|
33
61
|
});
|
|
34
|
-
|
|
62
|
+
let structures = [];
|
|
63
|
+
if (type === 'connector') {
|
|
64
|
+
structures = logic?.connector?.structures;
|
|
65
|
+
}
|
|
66
|
+
else if (type === 'extension' || type === 'interface') {
|
|
67
|
+
structures = logic?.parentNode?.structures;
|
|
68
|
+
}
|
|
69
|
+
const relationStructures = getReferenceStructures(referenceStructures, structures);
|
|
70
|
+
const newRelationStructures = [...relationStructures, ...referenceStructures];
|
|
71
|
+
if (namespace && newRelationStructures?.length) {
|
|
35
72
|
code += `declare namespace ${namespace} {\n`;
|
|
36
73
|
}
|
|
37
|
-
|
|
38
|
-
const {
|
|
74
|
+
newRelationStructures?.forEach((reference) => {
|
|
75
|
+
const { typeName } = reference || {};
|
|
39
76
|
const state = (0, translator_1.createCompilerState)();
|
|
40
77
|
const tabSize = namespace ? (0, translator_1.shiftState)(state, code, { tabSize: 1 }) : undefined;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
code += `${structure?.toNaturalTS(tabSize)}\n`;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
if ((typeNamespace?.includes('extensions.') && type === 'extension') || (typeNamespace?.includes('apis.') && type === 'interface')) {
|
|
49
|
-
logic?.parentNode?.structures
|
|
50
|
-
?.filter((structure) => structure?.name === typeName)
|
|
51
|
-
?.forEach((structure) => {
|
|
52
|
-
code += `${structure?.toNaturalTS(tabSize)}\n`;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
78
|
+
structures?.filter((structure) => structure?.name === typeName)
|
|
79
|
+
?.forEach((structure) => {
|
|
80
|
+
code += `${structure?.toNaturalTS(tabSize)}\n`;
|
|
81
|
+
});
|
|
55
82
|
});
|
|
56
|
-
if (namespace &&
|
|
83
|
+
if (namespace && newRelationStructures?.length) {
|
|
57
84
|
code += `}\n`;
|
|
58
85
|
}
|
|
59
86
|
const { description, codeStr } = desc || {};
|
|
@@ -64,7 +91,7 @@ function getLogicStructures(logic, type, desc, namespace) {
|
|
|
64
91
|
code = (0, exports.wrapTSBlock)(code);
|
|
65
92
|
return code;
|
|
66
93
|
}
|
|
67
|
-
exports.
|
|
94
|
+
exports.getLogicWithStructuresCode = getLogicWithStructuresCode;
|
|
68
95
|
function getNaslCore(logicType) {
|
|
69
96
|
let naslCore = `${(0, naslStdlibMap_1.getNASLStdlibMap)('nasl.core.ts')}\n`;
|
|
70
97
|
if (logicType === 'global_logic')
|
|
@@ -81,31 +108,43 @@ function getNaslUtil() {
|
|
|
81
108
|
return { code, naslUtil };
|
|
82
109
|
}
|
|
83
110
|
exports.getNaslUtil = getNaslUtil;
|
|
84
|
-
const getNaslUI = (app, frontendType, material
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
uiLib.push(...extensionMaterials);
|
|
89
|
-
if (!hasModuleIndexList) {
|
|
90
|
-
const naslUI = uiLib;
|
|
91
|
-
const code = naslUI.map((item, index) => `[3-${index}] ${item.name} | ${item.title} | ${item.description}`).join('\n');
|
|
92
|
-
return { code, naslUI };
|
|
111
|
+
const getNaslUI = (app, frontendType, material) => {
|
|
112
|
+
let naslUI = [];
|
|
113
|
+
if (material.basicMaterials) {
|
|
114
|
+
naslUI = typeof material.basicMaterials === 'string' ? (0, getUILib_1.getUILib)(material.basicMaterials) : (0, getUILib_1.handleMaterial)(material.basicMaterials);
|
|
93
115
|
}
|
|
116
|
+
const extensionMaterials = typeof material.extensionMaterials === 'string' ? (0, getUILib_1.getExtensionsMaterial)(app, frontendType) : material.extensionMaterials || [];
|
|
117
|
+
naslUI.push(...extensionMaterials);
|
|
118
|
+
return { naslUI };
|
|
119
|
+
};
|
|
120
|
+
exports.getNaslUI = getNaslUI;
|
|
121
|
+
const getNaslUICode = (naslUI, codeType, requiredIndexes) => {
|
|
122
|
+
let code = '';
|
|
94
123
|
const preDeclaration = (0, getUILib_1.getPreDeclaration)();
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
item.
|
|
99
|
-
|
|
100
|
-
|
|
124
|
+
let uiLib = naslUI;
|
|
125
|
+
if (requiredIndexes?.length) {
|
|
126
|
+
// 过滤出需要的组件
|
|
127
|
+
uiLib = naslUI.filter((item, index) => requiredIndexes.includes(`3-${index}`) ||
|
|
128
|
+
item.name.endsWith('LinearLayout') ||
|
|
129
|
+
item.name.endsWith('Text') ||
|
|
130
|
+
item.name.endsWith('Link') ||
|
|
131
|
+
item.name.endsWith('Button'));
|
|
132
|
+
}
|
|
133
|
+
if (codeType === 'detail') {
|
|
134
|
+
code = (0, exports.wrapTSBlock)(`${preDeclaration}\n${uiLib
|
|
135
|
+
.map((item) => `/**
|
|
101
136
|
* ${item.name}
|
|
102
137
|
* ${item.title}
|
|
103
138
|
* ${item.description}
|
|
104
139
|
*/
|
|
105
140
|
${item.tsDeclaration}`).join('\n')}`);
|
|
106
|
-
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
code += uiLib.map((item, index) => `[3-${index}] ${item.name} | ${item.title} | ${item.description}`).join('\n');
|
|
144
|
+
}
|
|
145
|
+
return code;
|
|
107
146
|
};
|
|
108
|
-
exports.
|
|
147
|
+
exports.getNaslUICode = getNaslUICode;
|
|
109
148
|
const getNaslUIOld = () => {
|
|
110
149
|
const naslUI = `${(0, naslStdlibMap_1.getNASLStdlibMap)('nasl.ui.ts')}\n`;
|
|
111
150
|
const code = (0, exports.wrapTSBlock)(naslUI);
|
|
@@ -118,89 +157,114 @@ function getNaslOQL() {
|
|
|
118
157
|
return { code, naslOql };
|
|
119
158
|
}
|
|
120
159
|
exports.getNaslOQL = getNaslOQL;
|
|
121
|
-
function getEnums(app, state
|
|
122
|
-
const needNamespace = requiredIndexes?.length >= 0;
|
|
160
|
+
function getEnums(app, state) {
|
|
123
161
|
const namespace = 'app.enums';
|
|
124
162
|
const data = [];
|
|
125
|
-
let code = '';
|
|
126
|
-
code += `declare namespace ${namespace} {\n`;
|
|
127
163
|
app.enums.forEach((enumeration) => {
|
|
128
|
-
const temp = `${enumeration?.toNaturalTS({ ...state, needNamespace })}`;
|
|
129
|
-
code += temp;
|
|
164
|
+
const temp = `${enumeration?.toNaturalTS({ ...state, needNamespace: true })}`;
|
|
130
165
|
data.push({ description: enumeration?.description || enumeration?.name, code: temp });
|
|
131
166
|
});
|
|
132
|
-
|
|
133
|
-
code = (0, exports.wrapTSBlock)(code);
|
|
134
|
-
return { code, namespace, enums: { namespace, data } };
|
|
167
|
+
return { namespace, enums: { namespace, data } };
|
|
135
168
|
}
|
|
136
169
|
exports.getEnums = getEnums;
|
|
137
|
-
|
|
138
|
-
const needNamespace = requiredIndexes?.length >= 0;
|
|
139
|
-
const entities = [];
|
|
170
|
+
const getEnumsCode = (enums) => {
|
|
140
171
|
let code = '';
|
|
172
|
+
code += `declare namespace ${enums?.namespace} {\n`;
|
|
173
|
+
enums?.data?.forEach((item) => {
|
|
174
|
+
code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
175
|
+
code += `${item.code}\n`;
|
|
176
|
+
});
|
|
177
|
+
code += `}\n`;
|
|
178
|
+
code = (0, exports.wrapTSBlock)(code);
|
|
179
|
+
return code;
|
|
180
|
+
};
|
|
181
|
+
exports.getEnumsCode = getEnumsCode;
|
|
182
|
+
function getEntities(app, state) {
|
|
183
|
+
const entities = [];
|
|
141
184
|
app.dataSources.forEach((dataSource) => {
|
|
142
185
|
const data = [];
|
|
143
186
|
const namespace = `app.dataSources.${dataSource?.name}.entities`;
|
|
144
|
-
code += `declare namespace ${namespace} {\n`;
|
|
145
187
|
dataSource.entities
|
|
146
188
|
.filter((entity) => !entity.name.startsWith('LCAP') || entity.name === 'LCAPUser')
|
|
147
189
|
.forEach((entity) => {
|
|
148
|
-
const entityName =
|
|
149
|
-
const tempCode = `${entity?.toNaturalTS({ ...state, needNamespace }, entityName)}`;
|
|
150
|
-
code += tempCode;
|
|
190
|
+
const entityName = `app.dataSources.${dataSource?.name}.entities.${entity?.name}`;
|
|
191
|
+
const tempCode = `${entity?.toNaturalTS({ ...state, needNamespace: true }, entityName)}`;
|
|
151
192
|
data.push({ description: entity?.description || entity?.name, code: tempCode });
|
|
152
193
|
});
|
|
153
194
|
entities.push({ namespace, data });
|
|
154
|
-
code += `}\n`;
|
|
155
195
|
});
|
|
156
|
-
|
|
157
|
-
return { code, entities };
|
|
196
|
+
return { entities };
|
|
158
197
|
}
|
|
159
198
|
exports.getEntities = getEntities;
|
|
160
|
-
|
|
161
|
-
|
|
199
|
+
const getEntitiesCode = (entities) => {
|
|
200
|
+
let code = '';
|
|
201
|
+
entities?.forEach((entity) => {
|
|
202
|
+
code += `declare namespace ${entity?.namespace} {\n`;
|
|
203
|
+
entity?.data?.forEach((item) => {
|
|
204
|
+
code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
205
|
+
code += `${item.code}\n`;
|
|
206
|
+
});
|
|
207
|
+
code += `}\n`;
|
|
208
|
+
});
|
|
209
|
+
code = (0, exports.wrapTSBlock)(code);
|
|
210
|
+
return code;
|
|
211
|
+
};
|
|
212
|
+
exports.getEntitiesCode = getEntitiesCode;
|
|
213
|
+
function getStructures(app, state) {
|
|
162
214
|
const data = [];
|
|
163
215
|
const namespace = `app.structures`;
|
|
164
|
-
let code = '';
|
|
165
|
-
code += `declare namespace ${namespace} {\n`;
|
|
166
216
|
app.structures
|
|
167
217
|
.filter((entity) => !entity.name.startsWith('LCAP'))
|
|
168
218
|
.forEach((structure) => {
|
|
169
|
-
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace })}`;
|
|
170
|
-
code += tempCode;
|
|
219
|
+
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}`;
|
|
171
220
|
data.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
172
221
|
});
|
|
173
|
-
|
|
174
|
-
code = (0, exports.wrapTSBlock)(code);
|
|
175
|
-
return { code, structures: { namespace, data } };
|
|
222
|
+
return { structures: { namespace, data } };
|
|
176
223
|
}
|
|
177
224
|
exports.getStructures = getStructures;
|
|
178
|
-
|
|
179
|
-
|
|
225
|
+
const getStructuresCode = (structures) => {
|
|
226
|
+
let code = '';
|
|
227
|
+
code += `declare namespace ${structures?.namespace} {\n`;
|
|
228
|
+
structures?.data?.forEach((item) => {
|
|
229
|
+
code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
230
|
+
code += `${item.code}\n`;
|
|
231
|
+
});
|
|
232
|
+
code += `}\n`;
|
|
233
|
+
code = (0, exports.wrapTSBlock)(code);
|
|
234
|
+
return code;
|
|
235
|
+
};
|
|
236
|
+
exports.getStructuresCode = getStructuresCode;
|
|
237
|
+
function getLogics(app, currentNode) {
|
|
180
238
|
const data = [];
|
|
181
239
|
const namespace = `app.logics`;
|
|
182
|
-
let code = '';
|
|
183
240
|
app?.logics
|
|
184
241
|
?.filter((logic) => logic !== currentNode && !logic.name.startsWith('LCAP'))
|
|
185
|
-
?.forEach((logic
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
return;
|
|
189
|
-
const rename = requiredIndexes?.length >= 0 ? logic?.calleewholeKey : undefined;
|
|
190
|
-
const needNamespace = requiredIndexes?.length >= 0;
|
|
191
|
-
const tempCode = `${logic?.toNaturalTS({ needNamespace, rename, declaration: true })}`;
|
|
242
|
+
?.forEach((logic) => {
|
|
243
|
+
const rename = logic?.calleewholeKey;
|
|
244
|
+
const tempCode = `${logic?.toNaturalTS({ needNamespace: true, rename, declaration: true })}`;
|
|
192
245
|
const description = logic?.description || '';
|
|
193
|
-
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
194
246
|
data.push({ description, code: tempCode });
|
|
195
247
|
});
|
|
196
|
-
return {
|
|
248
|
+
return { appLogics: { namespace, data } };
|
|
197
249
|
}
|
|
198
250
|
exports.getLogics = getLogics;
|
|
199
|
-
|
|
200
|
-
const hasModuleIndexList = requiredIndexes?.length > 0;
|
|
201
|
-
const interfaceDependencies = [];
|
|
251
|
+
const getLogicsCode = (appLogics, codeType, requiredIndexes) => {
|
|
202
252
|
let code = '';
|
|
203
|
-
|
|
253
|
+
appLogics?.data?.forEach((item, index) => {
|
|
254
|
+
const logicIndex = `6-${index}`;
|
|
255
|
+
if (requiredIndexes?.length && !requiredIndexes?.includes(logicIndex))
|
|
256
|
+
return;
|
|
257
|
+
const tempCode = codeType === 'short' ? item.code.replace(`${appLogics.namespace}.`, '') : item.code;
|
|
258
|
+
code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
259
|
+
});
|
|
260
|
+
return code;
|
|
261
|
+
};
|
|
262
|
+
exports.getLogicsCode = getLogicsCode;
|
|
263
|
+
function getModuleInterfaces(modules, state) {
|
|
264
|
+
const interfaceDependencies = [];
|
|
265
|
+
modules?.forEach((interfaceDependency) => {
|
|
266
|
+
interfaceDependency = new concepts_1.Module(interfaceDependency);
|
|
267
|
+
interfaceDependency.parentKey = 'interfaceDependencies';
|
|
204
268
|
const name = interfaceDependency?.name;
|
|
205
269
|
let structures = {};
|
|
206
270
|
let logics = {};
|
|
@@ -214,33 +278,42 @@ function getModuleInterfaces(app, state, requiredIndexes) {
|
|
|
214
278
|
structures = { namespace: structureNamespace, data: structureData };
|
|
215
279
|
const logicNamespace = `${namespace}.interfaces`;
|
|
216
280
|
const logicData = [];
|
|
217
|
-
interfaceDependency?.interfaces?.forEach((interface_
|
|
218
|
-
const interfaceIndex = `7-${moduleIndex}-${index}`;
|
|
219
|
-
if (hasModuleIndexList && !requiredIndexes?.includes(interfaceIndex))
|
|
220
|
-
return;
|
|
281
|
+
interfaceDependency?.interfaces?.forEach((interface_) => {
|
|
221
282
|
const description = interface_?.description || '';
|
|
222
|
-
const interfaceName =
|
|
223
|
-
const
|
|
224
|
-
const
|
|
225
|
-
logicData.push({ description, code: tempCode });
|
|
226
|
-
if (requiredIndexes?.includes(interfaceIndex)) {
|
|
227
|
-
code += getLogicStructures(interface_, 'interface', { description, codeStr: tempCode }, structureNamespace);
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
code += `[${interfaceIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
231
|
-
}
|
|
283
|
+
const interfaceName = interface_?.calleewholeKey;
|
|
284
|
+
const tempCode = interface_?.toNaturalTS((0, translator_1.createCompilerState)('', { needNamespace: true }), interfaceName);
|
|
285
|
+
const codeWithDetail = getLogicWithStructuresCode(interface_, 'interface', { description, codeStr: tempCode }, structureNamespace);
|
|
286
|
+
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
232
287
|
});
|
|
233
288
|
logics = { namespace: logicNamespace, data: logicData };
|
|
234
289
|
interfaceDependencies.push({ name, structures, logics });
|
|
235
290
|
});
|
|
236
|
-
return {
|
|
291
|
+
return { interfaceDependencies };
|
|
237
292
|
}
|
|
238
293
|
exports.getModuleInterfaces = getModuleInterfaces;
|
|
239
|
-
|
|
240
|
-
const hasModuleIndexList = requiredIndexes?.length > 0;
|
|
241
|
-
const connections = [];
|
|
294
|
+
const getModuleInterfacesCode = (interfaceDependencies, codeType, requiredIndexes) => {
|
|
242
295
|
let code = '';
|
|
243
|
-
|
|
296
|
+
interfaceDependencies.forEach((interfaceDependency, index) => {
|
|
297
|
+
interfaceDependency?.logics?.data?.forEach((item, idx) => {
|
|
298
|
+
const interfaceIndex = `7-${index}-${idx}`;
|
|
299
|
+
if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex))
|
|
300
|
+
return;
|
|
301
|
+
if (codeType === 'short') {
|
|
302
|
+
const tempCode = item.code.replace(`${interfaceDependency?.logics.namespace}.`, '');
|
|
303
|
+
code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
code += item.codeWithDetail;
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
return code;
|
|
311
|
+
};
|
|
312
|
+
exports.getModuleInterfacesCode = getModuleInterfacesCode;
|
|
313
|
+
// 连接
|
|
314
|
+
function getConnections(modules, state) {
|
|
315
|
+
const connections = [];
|
|
316
|
+
modules?.forEach((connection) => {
|
|
244
317
|
const name = connection?.name;
|
|
245
318
|
let structures = {};
|
|
246
319
|
let logics = {};
|
|
@@ -252,59 +325,110 @@ function getConnectors(app, state, requiredIndexes) {
|
|
|
252
325
|
structureData.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
253
326
|
});
|
|
254
327
|
structures = { namespace: structureNamespace, data: structureData };
|
|
255
|
-
code += `[8-${connectionIndex}] ${connection?.connector?.title}\n`;
|
|
256
328
|
const logicData = [];
|
|
257
|
-
connection?.connector?.namespaces?.forEach((namespace
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex))
|
|
261
|
-
return;
|
|
329
|
+
connection?.connector?.namespaces?.forEach((namespace) => {
|
|
330
|
+
const curNameSpace = `${connectionNamespace}.${namespace?.name}`;
|
|
331
|
+
namespace?.logics?.forEach((logic) => {
|
|
262
332
|
const description = `${logic?.description || logic?.title || ''}`;
|
|
263
|
-
const rename =
|
|
264
|
-
const
|
|
265
|
-
const
|
|
266
|
-
logicData.push({ description, code: tempCode });
|
|
267
|
-
if (requiredIndexes?.includes(logicIndex)) {
|
|
268
|
-
code += getLogicStructures(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
272
|
-
}
|
|
333
|
+
const rename = `${connection?.name}.${logic?.calleewholeKey}`;
|
|
334
|
+
const tempCode = `${logic?.toNaturalTS((0, translator_1.shiftState)(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
335
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
336
|
+
logicData.push({ description, code: tempCode, codeWithDetail, namespace: curNameSpace });
|
|
273
337
|
});
|
|
274
338
|
});
|
|
275
339
|
if (!connection?.connector?.namespaces?.length && connection?.connector?.logics?.length) {
|
|
276
|
-
connection?.connector?.logics.forEach((logic
|
|
277
|
-
const logicIndex = `8-${connectionIndex}-${index}`;
|
|
278
|
-
if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex))
|
|
279
|
-
return;
|
|
340
|
+
connection?.connector?.logics.forEach((logic) => {
|
|
280
341
|
const description = logic?.description || '';
|
|
281
|
-
const rename =
|
|
282
|
-
const
|
|
283
|
-
const
|
|
284
|
-
logicData.push({ description, code: tempCode });
|
|
285
|
-
if (requiredIndexes?.includes(logicIndex)) {
|
|
286
|
-
code += getLogicStructures(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
290
|
-
}
|
|
342
|
+
const rename = `${connection?.name}.${logic?.calleewholeKey}`;
|
|
343
|
+
const tempCode = `${logic?.toNaturalTS((0, translator_1.shiftState)(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
344
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
345
|
+
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
291
346
|
});
|
|
292
347
|
}
|
|
293
348
|
logics = { namespace: connectionNamespace, data: logicData };
|
|
294
349
|
connections.push({ name, structures, logics });
|
|
295
350
|
});
|
|
296
|
-
return {
|
|
351
|
+
return { connections };
|
|
352
|
+
}
|
|
353
|
+
exports.getConnections = getConnections;
|
|
354
|
+
// 连接器
|
|
355
|
+
function getConnectors(modules, state) {
|
|
356
|
+
const connectors = [];
|
|
357
|
+
modules?.forEach((connector) => {
|
|
358
|
+
connector = new concepts_1.Connector(connector);
|
|
359
|
+
connector.parentKey = 'connectorDependencies';
|
|
360
|
+
const { name } = connector;
|
|
361
|
+
let structures = {};
|
|
362
|
+
let logics = {};
|
|
363
|
+
const connectorNamespace = `${name}.connector.${name}`;
|
|
364
|
+
const structureNamespace = `connector.${name}.structures`;
|
|
365
|
+
const structureData = [];
|
|
366
|
+
connector?.structures?.forEach((structure) => {
|
|
367
|
+
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}`;
|
|
368
|
+
structureData.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
369
|
+
});
|
|
370
|
+
structures = { namespace: structureNamespace, data: structureData };
|
|
371
|
+
const logicData = [];
|
|
372
|
+
connector?.namespaces?.forEach((namespace) => {
|
|
373
|
+
const curNameSpace = `${connectorNamespace}.${namespace?.name}`;
|
|
374
|
+
namespace?.logics?.forEach((logic) => {
|
|
375
|
+
const description = `${logic?.description || logic?.title || ''}`;
|
|
376
|
+
const rename = `${name}.${logic?.calleewholeKey}`;
|
|
377
|
+
const tempCode = `${logic?.toNaturalTS((0, translator_1.shiftState)(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
378
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
379
|
+
logicData.push({ description, code: tempCode, codeWithDetail, namespace: curNameSpace });
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
if (!connector?.namespaces?.length && connector?.logics?.length) {
|
|
383
|
+
connector?.logics.forEach((logic) => {
|
|
384
|
+
const description = logic?.description || '';
|
|
385
|
+
const rename = `${name}.${logic?.calleewholeKey}`;
|
|
386
|
+
const tempCode = `${logic?.toNaturalTS((0, translator_1.shiftState)(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
387
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
388
|
+
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
logics = { namespace: connectorNamespace, data: logicData };
|
|
392
|
+
connectors.push({ name, structures, logics });
|
|
393
|
+
});
|
|
394
|
+
return { connectors };
|
|
297
395
|
}
|
|
298
396
|
exports.getConnectors = getConnectors;
|
|
299
|
-
|
|
300
|
-
const hasModuleIndexList = requiredIndexes?.length > 0;
|
|
301
|
-
const dependencies = [];
|
|
397
|
+
const getConnectorsCode = (connections, codeType, requiredIndexes) => {
|
|
302
398
|
let code = '';
|
|
303
|
-
|
|
304
|
-
?.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
399
|
+
connections.forEach((connection, index) => {
|
|
400
|
+
connection?.logics?.data?.forEach((item, idx) => {
|
|
401
|
+
const interfaceIndex = `8-${index}-${idx}`;
|
|
402
|
+
if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex))
|
|
403
|
+
return;
|
|
404
|
+
if (codeType === 'short') {
|
|
405
|
+
const namespace = item?.namespace || connection?.logics.namespace;
|
|
406
|
+
const tempCode = item.code.replace(`${namespace}.`, '');
|
|
407
|
+
code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
code += item.codeWithDetail;
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
return code;
|
|
415
|
+
};
|
|
416
|
+
exports.getConnectorsCode = getConnectorsCode;
|
|
417
|
+
function getDependencies(modules, state, logicType, frontendType) {
|
|
418
|
+
const dependencies = [];
|
|
419
|
+
modules?.forEach((module) => {
|
|
420
|
+
module = new concepts_1.Module(module);
|
|
421
|
+
module.parentKey = 'dependencies';
|
|
422
|
+
// 根据类型获取对应的逻辑
|
|
423
|
+
let curLogics = module?.logics;
|
|
424
|
+
if (logicType !== 'global_logic' && frontendType) {
|
|
425
|
+
module?.frontends?.forEach((frontend) => {
|
|
426
|
+
if (frontend.type === frontendType) {
|
|
427
|
+
curLogics = curLogics.concat([...frontend?.logics]);
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
if (curLogics?.length) {
|
|
308
432
|
const name = module?.name;
|
|
309
433
|
let structures = {};
|
|
310
434
|
let logics = {};
|
|
@@ -312,35 +436,46 @@ function getDependencies(app, state, requiredIndexes) {
|
|
|
312
436
|
const structureNamespace = `${namespace}.structures`;
|
|
313
437
|
const structureData = [];
|
|
314
438
|
module?.structures?.forEach((structure) => {
|
|
315
|
-
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}
|
|
439
|
+
const tempCode = structure?.toNaturalTS ? `${structure?.toNaturalTS({ ...state, needNamespace: true })}` : '';
|
|
316
440
|
structureData.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
317
441
|
});
|
|
318
442
|
structures = { namespace: structureNamespace, data: structureData };
|
|
319
|
-
|
|
443
|
+
let logicsNamespace = '';
|
|
320
444
|
const logicData = [];
|
|
321
|
-
|
|
322
|
-
const logicIndex = `9-${moduleIndex}-${index}`;
|
|
323
|
-
if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex))
|
|
324
|
-
return;
|
|
445
|
+
curLogics?.forEach((logic) => {
|
|
325
446
|
const description = logic?.description || '';
|
|
326
|
-
const rename =
|
|
327
|
-
|
|
328
|
-
const tempCode = `${logic?.toNaturalTS((0, translator_1.shiftState)(state,
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
code += getLogicStructures(logic, 'extension', { description, codeStr: tempCode }, structureNamespace);
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
335
|
-
}
|
|
447
|
+
const rename = logic?.calleewholeKey;
|
|
448
|
+
logicsNamespace = logic?.calleewholeKey.replace(`.${logic.name}`, '');
|
|
449
|
+
const tempCode = `${logic?.toNaturalTS((0, translator_1.shiftState)(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
450
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'extension', { description, codeStr: tempCode }, structureNamespace);
|
|
451
|
+
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
336
452
|
});
|
|
337
453
|
logics = { namespace: logicsNamespace, data: logicData };
|
|
338
454
|
dependencies.push({ name, structures, logics });
|
|
339
455
|
}
|
|
340
456
|
});
|
|
341
|
-
return {
|
|
457
|
+
return { dependencies };
|
|
342
458
|
}
|
|
343
459
|
exports.getDependencies = getDependencies;
|
|
460
|
+
const getDependenciesCode = (dependencies, codeType, requiredIndexes) => {
|
|
461
|
+
let code = '';
|
|
462
|
+
dependencies.forEach((dependency, index) => {
|
|
463
|
+
dependency?.logics?.data?.forEach((item, idx) => {
|
|
464
|
+
const logicIndex = `9-${index}-${idx}`;
|
|
465
|
+
if (requiredIndexes?.length && !requiredIndexes?.includes(logicIndex))
|
|
466
|
+
return;
|
|
467
|
+
if (codeType === 'short') {
|
|
468
|
+
const tempCode = item.code.replace(`${dependency?.logics.namespace}.`, '');
|
|
469
|
+
code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
code += item.codeWithDetail;
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
return code;
|
|
477
|
+
};
|
|
478
|
+
exports.getDependenciesCode = getDependenciesCode;
|
|
344
479
|
function getFrontendVariables(frontend, state) {
|
|
345
480
|
let code = '';
|
|
346
481
|
frontend?.variables?.forEach((variable) => {
|
|
@@ -396,6 +531,16 @@ function getFrontendViews(frontend, state, currentNode, convertChildren) {
|
|
|
396
531
|
return { code: (0, exports.wrapTSBlock)(code), views: { namespace, data } };
|
|
397
532
|
}
|
|
398
533
|
exports.getFrontendViews = getFrontendViews;
|
|
534
|
+
const getFrontendViewsCode = (views) => {
|
|
535
|
+
let code = '';
|
|
536
|
+
views?.data?.forEach((item) => {
|
|
537
|
+
code += `/* ${item.description} */ \n`;
|
|
538
|
+
code += item.code;
|
|
539
|
+
code += `\n`;
|
|
540
|
+
});
|
|
541
|
+
return (0, exports.wrapTSBlock)(code);
|
|
542
|
+
};
|
|
543
|
+
exports.getFrontendViewsCode = getFrontendViewsCode;
|
|
399
544
|
function getCurrentNodeContext(currentNode, focusedNodePath) {
|
|
400
545
|
let code = '';
|
|
401
546
|
let view;
|