@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,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.getServerVariables = 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,115 @@ 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
|
-
.filter((entity) => !entity.name.startsWith('LCAP') || entity.name === 'LCAPUser')
|
|
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
|
-
.filter((entity) => !entity.name.startsWith('LCAP'))
|
|
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, state) {
|
|
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({ ...state, 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}] \`${tempCode}\`\n`;
|
|
259
|
+
// code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
260
|
+
});
|
|
261
|
+
return code;
|
|
262
|
+
};
|
|
263
|
+
exports.getLogicsCode = getLogicsCode;
|
|
264
|
+
function getModuleInterfaces(modules, state) {
|
|
265
|
+
const interfaceDependencies = [];
|
|
266
|
+
modules?.forEach((interfaceDependency) => {
|
|
267
|
+
interfaceDependency = new concepts_1.Module(interfaceDependency);
|
|
268
|
+
interfaceDependency.parentKey = 'interfaceDependencies';
|
|
204
269
|
const name = interfaceDependency?.name;
|
|
205
270
|
let structures = {};
|
|
206
271
|
let logics = {};
|
|
@@ -214,33 +279,43 @@ function getModuleInterfaces(app, state, requiredIndexes) {
|
|
|
214
279
|
structures = { namespace: structureNamespace, data: structureData };
|
|
215
280
|
const logicNamespace = `${namespace}.interfaces`;
|
|
216
281
|
const logicData = [];
|
|
217
|
-
interfaceDependency?.interfaces?.forEach((interface_
|
|
218
|
-
const interfaceIndex = `7-${moduleIndex}-${index}`;
|
|
219
|
-
if (hasModuleIndexList && !requiredIndexes?.includes(interfaceIndex))
|
|
220
|
-
return;
|
|
282
|
+
interfaceDependency?.interfaces?.forEach((interface_) => {
|
|
221
283
|
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
|
-
}
|
|
284
|
+
const interfaceName = interface_?.calleewholeKey;
|
|
285
|
+
const tempCode = `${interface_?.toNaturalTS((0, translator_1.shiftState)(state, '', { needNamespace: true, rename: interfaceName, declaration: true }))}`;
|
|
286
|
+
const codeWithDetail = getLogicWithStructuresCode(interface_, 'interface', { description, codeStr: tempCode }, structureNamespace);
|
|
287
|
+
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
232
288
|
});
|
|
233
289
|
logics = { namespace: logicNamespace, data: logicData };
|
|
234
290
|
interfaceDependencies.push({ name, structures, logics });
|
|
235
291
|
});
|
|
236
|
-
return {
|
|
292
|
+
return { interfaceDependencies };
|
|
237
293
|
}
|
|
238
294
|
exports.getModuleInterfaces = getModuleInterfaces;
|
|
239
|
-
|
|
240
|
-
const hasModuleIndexList = requiredIndexes?.length > 0;
|
|
241
|
-
const connections = [];
|
|
295
|
+
const getModuleInterfacesCode = (interfaceDependencies, codeType, requiredIndexes) => {
|
|
242
296
|
let code = '';
|
|
243
|
-
|
|
297
|
+
interfaceDependencies.forEach((interfaceDependency, index) => {
|
|
298
|
+
interfaceDependency?.logics?.data?.forEach((item, idx) => {
|
|
299
|
+
const interfaceIndex = `7-${index}-${idx}`;
|
|
300
|
+
if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex))
|
|
301
|
+
return;
|
|
302
|
+
if (codeType === 'short') {
|
|
303
|
+
const tempCode = item.code.replace(`${interfaceDependency?.logics.namespace}.`, '');
|
|
304
|
+
code += `[${interfaceIndex}] \`${tempCode}\`\n`;
|
|
305
|
+
// code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
code += item.codeWithDetail;
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
return code;
|
|
313
|
+
};
|
|
314
|
+
exports.getModuleInterfacesCode = getModuleInterfacesCode;
|
|
315
|
+
// 连接
|
|
316
|
+
function getConnections(modules, state) {
|
|
317
|
+
const connections = [];
|
|
318
|
+
modules?.forEach((connection) => {
|
|
244
319
|
const name = connection?.name;
|
|
245
320
|
let structures = {};
|
|
246
321
|
let logics = {};
|
|
@@ -252,59 +327,111 @@ function getConnectors(app, state, requiredIndexes) {
|
|
|
252
327
|
structureData.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
253
328
|
});
|
|
254
329
|
structures = { namespace: structureNamespace, data: structureData };
|
|
255
|
-
code += `[8-${connectionIndex}] ${connection?.connector?.title}\n`;
|
|
256
330
|
const logicData = [];
|
|
257
|
-
connection?.connector?.namespaces?.forEach((namespace
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex))
|
|
261
|
-
return;
|
|
331
|
+
connection?.connector?.namespaces?.forEach((namespace) => {
|
|
332
|
+
const curNameSpace = `${connectionNamespace}.${namespace?.name}`;
|
|
333
|
+
namespace?.logics?.forEach((logic) => {
|
|
262
334
|
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
|
-
}
|
|
335
|
+
const rename = `${connection?.name}.${logic?.calleewholeKey}`;
|
|
336
|
+
const tempCode = `${logic?.toNaturalTS((0, translator_1.shiftState)(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
337
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
338
|
+
logicData.push({ description, code: tempCode, codeWithDetail, namespace: curNameSpace });
|
|
273
339
|
});
|
|
274
340
|
});
|
|
275
341
|
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;
|
|
342
|
+
connection?.connector?.logics.forEach((logic) => {
|
|
280
343
|
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
|
-
}
|
|
344
|
+
const rename = `${connection?.name}.${logic?.calleewholeKey}`;
|
|
345
|
+
const tempCode = `${logic?.toNaturalTS((0, translator_1.shiftState)(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
346
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
347
|
+
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
291
348
|
});
|
|
292
349
|
}
|
|
293
350
|
logics = { namespace: connectionNamespace, data: logicData };
|
|
294
351
|
connections.push({ name, structures, logics });
|
|
295
352
|
});
|
|
296
|
-
return {
|
|
353
|
+
return { connections };
|
|
354
|
+
}
|
|
355
|
+
exports.getConnections = getConnections;
|
|
356
|
+
// 连接器
|
|
357
|
+
function getConnectors(modules, state) {
|
|
358
|
+
const connectors = [];
|
|
359
|
+
modules?.forEach((connector) => {
|
|
360
|
+
connector = new concepts_1.Connector(connector);
|
|
361
|
+
connector.parentKey = 'connectorDependencies';
|
|
362
|
+
const { name } = connector;
|
|
363
|
+
let structures = {};
|
|
364
|
+
let logics = {};
|
|
365
|
+
const connectorNamespace = `${name}.connector.${name}`;
|
|
366
|
+
const structureNamespace = `connector.${name}.structures`;
|
|
367
|
+
const structureData = [];
|
|
368
|
+
connector?.structures?.forEach((structure) => {
|
|
369
|
+
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}`;
|
|
370
|
+
structureData.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
371
|
+
});
|
|
372
|
+
structures = { namespace: structureNamespace, data: structureData };
|
|
373
|
+
const logicData = [];
|
|
374
|
+
connector?.namespaces?.forEach((namespace) => {
|
|
375
|
+
const curNameSpace = `${connectorNamespace}.${namespace?.name}`;
|
|
376
|
+
namespace?.logics?.forEach((logic) => {
|
|
377
|
+
const description = `${logic?.description || logic?.title || ''}`;
|
|
378
|
+
const rename = `${name}.${logic?.calleewholeKey}`;
|
|
379
|
+
const tempCode = `${logic?.toNaturalTS((0, translator_1.shiftState)(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
380
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
381
|
+
logicData.push({ description, code: tempCode, codeWithDetail, namespace: curNameSpace });
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
if (!connector?.namespaces?.length && connector?.logics?.length) {
|
|
385
|
+
connector?.logics.forEach((logic) => {
|
|
386
|
+
const description = logic?.description || '';
|
|
387
|
+
const rename = `${name}.${logic?.calleewholeKey}`;
|
|
388
|
+
const tempCode = `${logic?.toNaturalTS((0, translator_1.shiftState)(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
389
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
390
|
+
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
logics = { namespace: connectorNamespace, data: logicData };
|
|
394
|
+
connectors.push({ name, structures, logics });
|
|
395
|
+
});
|
|
396
|
+
return { connectors };
|
|
297
397
|
}
|
|
298
398
|
exports.getConnectors = getConnectors;
|
|
299
|
-
|
|
300
|
-
const hasModuleIndexList = requiredIndexes?.length > 0;
|
|
301
|
-
const dependencies = [];
|
|
399
|
+
const getConnectorsCode = (connections, codeType, requiredIndexes) => {
|
|
302
400
|
let code = '';
|
|
303
|
-
|
|
304
|
-
?.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
401
|
+
connections.forEach((connection, index) => {
|
|
402
|
+
connection?.logics?.data?.forEach((item, idx) => {
|
|
403
|
+
const interfaceIndex = `8-${index}-${idx}`;
|
|
404
|
+
if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex))
|
|
405
|
+
return;
|
|
406
|
+
if (codeType === 'short') {
|
|
407
|
+
const namespace = item?.namespace || connection?.logics.namespace;
|
|
408
|
+
const tempCode = item.code.replace(`${namespace}.`, '');
|
|
409
|
+
code += `[${interfaceIndex}] \`${tempCode}\`\n`;
|
|
410
|
+
// code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
code += item.codeWithDetail;
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
return code;
|
|
418
|
+
};
|
|
419
|
+
exports.getConnectorsCode = getConnectorsCode;
|
|
420
|
+
function getDependencies(modules, state, logicType, frontendType) {
|
|
421
|
+
const dependencies = [];
|
|
422
|
+
modules?.forEach((module) => {
|
|
423
|
+
module = new concepts_1.Module(module);
|
|
424
|
+
module.parentKey = 'dependencies';
|
|
425
|
+
// 根据类型获取对应的逻辑
|
|
426
|
+
let curLogics = module?.logics;
|
|
427
|
+
if (logicType !== 'global_logic' && frontendType) {
|
|
428
|
+
module?.frontends?.forEach((frontend) => {
|
|
429
|
+
if (frontend.type === frontendType) {
|
|
430
|
+
curLogics = curLogics.concat([...frontend?.logics]);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
if (curLogics?.length) {
|
|
308
435
|
const name = module?.name;
|
|
309
436
|
let structures = {};
|
|
310
437
|
let logics = {};
|
|
@@ -312,44 +439,65 @@ function getDependencies(app, state, requiredIndexes) {
|
|
|
312
439
|
const structureNamespace = `${namespace}.structures`;
|
|
313
440
|
const structureData = [];
|
|
314
441
|
module?.structures?.forEach((structure) => {
|
|
315
|
-
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}
|
|
442
|
+
const tempCode = structure?.toNaturalTS ? `${structure?.toNaturalTS({ ...state, needNamespace: true })}` : '';
|
|
316
443
|
structureData.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
317
444
|
});
|
|
318
445
|
structures = { namespace: structureNamespace, data: structureData };
|
|
319
|
-
|
|
446
|
+
let logicsNamespace = '';
|
|
320
447
|
const logicData = [];
|
|
321
|
-
|
|
322
|
-
const logicIndex = `9-${moduleIndex}-${index}`;
|
|
323
|
-
if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex))
|
|
324
|
-
return;
|
|
448
|
+
curLogics?.forEach((logic) => {
|
|
325
449
|
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
|
-
}
|
|
450
|
+
const rename = logic?.calleewholeKey;
|
|
451
|
+
logicsNamespace = logic?.calleewholeKey.replace(`.${logic.name}`, '');
|
|
452
|
+
const tempCode = `${logic?.toNaturalTS((0, translator_1.shiftState)(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
453
|
+
const codeWithDetail = getLogicWithStructuresCode(logic, 'extension', { description, codeStr: tempCode }, structureNamespace);
|
|
454
|
+
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
336
455
|
});
|
|
337
456
|
logics = { namespace: logicsNamespace, data: logicData };
|
|
338
457
|
dependencies.push({ name, structures, logics });
|
|
339
458
|
}
|
|
340
459
|
});
|
|
341
|
-
return {
|
|
460
|
+
return { dependencies };
|
|
342
461
|
}
|
|
343
462
|
exports.getDependencies = getDependencies;
|
|
463
|
+
const getDependenciesCode = (dependencies, codeType, requiredIndexes) => {
|
|
464
|
+
let code = '';
|
|
465
|
+
dependencies.forEach((dependency, index) => {
|
|
466
|
+
dependency?.logics?.data?.forEach((item, idx) => {
|
|
467
|
+
const logicIndex = `9-${index}-${idx}`;
|
|
468
|
+
if (requiredIndexes?.length && !requiredIndexes?.includes(logicIndex))
|
|
469
|
+
return;
|
|
470
|
+
if (codeType === 'short') {
|
|
471
|
+
const tempCode = item.code.replace(`${dependency?.logics.namespace}.`, '');
|
|
472
|
+
code += `[${logicIndex}] \`${tempCode}\`\n`;
|
|
473
|
+
// code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
code += item.codeWithDetail;
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
return code;
|
|
481
|
+
};
|
|
482
|
+
exports.getDependenciesCode = getDependenciesCode;
|
|
344
483
|
function getFrontendVariables(frontend, state) {
|
|
345
484
|
let code = '';
|
|
346
485
|
frontend?.variables?.forEach((variable) => {
|
|
347
486
|
const tempCode = `let ${variable?.toNaturalTS((0, translator_1.shiftState)(state, code, { inline: true }))};\n`;
|
|
348
487
|
code += tempCode;
|
|
349
488
|
});
|
|
350
|
-
return { code: (0, exports.wrapTSBlock)(code),
|
|
489
|
+
return { code: (0, exports.wrapTSBlock)(code), frontendVariables: code };
|
|
351
490
|
}
|
|
352
491
|
exports.getFrontendVariables = getFrontendVariables;
|
|
492
|
+
function getServerVariables(app, state) {
|
|
493
|
+
let code = '';
|
|
494
|
+
app.backend?.variables?.forEach((variable) => {
|
|
495
|
+
const tempCode = `let ${variable?.toNaturalTS((0, translator_1.shiftState)(state, code, { inline: true }))};\n`;
|
|
496
|
+
code += tempCode;
|
|
497
|
+
});
|
|
498
|
+
return { code: (0, exports.wrapTSBlock)(code), backendVariables: code };
|
|
499
|
+
}
|
|
500
|
+
exports.getServerVariables = getServerVariables;
|
|
353
501
|
function getChildrenViews(view, currentNode, convertChildren, prefix) {
|
|
354
502
|
const data = [];
|
|
355
503
|
if (view?.children?.length > 0) {
|
|
@@ -396,6 +544,16 @@ function getFrontendViews(frontend, state, currentNode, convertChildren) {
|
|
|
396
544
|
return { code: (0, exports.wrapTSBlock)(code), views: { namespace, data } };
|
|
397
545
|
}
|
|
398
546
|
exports.getFrontendViews = getFrontendViews;
|
|
547
|
+
const getFrontendViewsCode = (views) => {
|
|
548
|
+
let code = '';
|
|
549
|
+
views?.data?.forEach((item) => {
|
|
550
|
+
code += `/* ${item.description} */ \n`;
|
|
551
|
+
code += item.code;
|
|
552
|
+
code += `\n`;
|
|
553
|
+
});
|
|
554
|
+
return (0, exports.wrapTSBlock)(code);
|
|
555
|
+
};
|
|
556
|
+
exports.getFrontendViewsCode = getFrontendViewsCode;
|
|
399
557
|
function getCurrentNodeContext(currentNode, focusedNodePath, experimental) {
|
|
400
558
|
let code = '';
|
|
401
559
|
let view;
|