@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.
Files changed (49) hide show
  1. package/out/concepts/CallLogic__.js +2 -2
  2. package/out/concepts/CallLogic__.js.map +1 -1
  3. package/out/concepts/Logic__.js +2 -11
  4. package/out/concepts/Logic__.js.map +1 -1
  5. package/out/concepts/NullLiteral__.js +0 -6
  6. package/out/concepts/NullLiteral__.js.map +1 -1
  7. package/out/concepts/ViewComponentDeclaration__.js +3 -3
  8. package/out/concepts/ViewComponentDeclaration__.js.map +1 -1
  9. package/out/generator/release-body/body.d.ts +0 -4
  10. package/out/generator/release-body/body.js +2 -2
  11. package/out/generator/release-body/body.js.map +1 -1
  12. package/out/generator/release-body/index.d.ts +0 -1
  13. package/out/generator/release-body/index.js +0 -1
  14. package/out/generator/release-body/index.js.map +1 -1
  15. package/out/natural/genNaturalTS.d.ts +56 -24
  16. package/out/natural/genNaturalTS.js +182 -114
  17. package/out/natural/genNaturalTS.js.map +1 -1
  18. package/out/natural/getContext/getUILib.js +9 -5
  19. package/out/natural/getContext/getUILib.js.map +1 -1
  20. package/out/natural/getContext/index.d.ts +34 -25
  21. package/out/natural/getContext/index.js +302 -157
  22. package/out/natural/getContext/index.js.map +1 -1
  23. package/out/natural/index.d.ts +1 -0
  24. package/out/natural/index.js +1 -0
  25. package/out/natural/index.js.map +1 -1
  26. package/out/natural/tools.d.ts +11 -0
  27. package/out/natural/tools.js +156 -0
  28. package/out/natural/tools.js.map +1 -0
  29. package/out/natural/transformTS2UI.js +5 -1
  30. package/out/natural/transformTS2UI.js.map +1 -1
  31. package/out/natural/transformTSCode.js +4 -1
  32. package/out/natural/transformTSCode.js.map +1 -1
  33. package/out/server/naslServer.js +3 -3
  34. package/out/server/naslServer.js.map +1 -1
  35. package/package.json +2 -2
  36. package/src/concepts/CallLogic__.ts +2 -2
  37. package/src/concepts/Logic__.ts +2 -11
  38. package/src/concepts/NullLiteral__.ts +0 -7
  39. package/src/concepts/ViewComponentDeclaration__.ts +3 -3
  40. package/src/generator/release-body/body.ts +7 -7
  41. package/src/generator/release-body/index.ts +0 -1
  42. package/src/natural/genNaturalTS.ts +328 -144
  43. package/src/natural/getContext/getUILib.ts +9 -5
  44. package/src/natural/getContext/index.ts +346 -171
  45. package/src/natural/index.ts +1 -0
  46. package/src/natural/tools.ts +132 -0
  47. package/src/natural/transformTS2UI.ts +4 -1
  48. package/src/natural/transformTSCode.ts +3 -1
  49. package/src/server/naslServer.ts +3 -3
@@ -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 getLogicStructures(logic: Logic, type: string, desc: { description: string; codeStr: string; }, namespace: string) {
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
- if (namespace && referenceStructures?.length) {
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
- referenceStructures?.forEach((reference: { typeNamespace: string; typeName: string; }) => {
48
- const { typeNamespace, typeName } = reference || {};
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
- if (typeNamespace?.includes('extensions.') && type === 'connector') {
52
- logic?.connector?.structures
53
- ?.filter((structure) => structure?.name === typeName)
54
- ?.forEach((structure) => {
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 && referenceStructures?.length) {
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 = (app: App, frontendType: 'pc' | 'h5', material: { basicMaterials: { json: any; tsDeclaration: string; }, extensionMaterials: { name: string; title: string; description: string; tsDescription: string; }[]; } | string, requiredIndexes?: string[]) => {
93
- const hasModuleIndexList = requiredIndexes?.length > 0;
94
- const uiLib = typeof material === 'string' ? getUILib(material as 'pc' | 'h5') : handleMaterial(material.basicMaterials);
95
- const extensionMaterials = typeof material === 'string' ? getExtensionsMaterial(app, frontendType) : material.extensionMaterials || [];
96
- uiLib.push(...extensionMaterials);
97
-
98
- if (!hasModuleIndexList) {
99
- const naslUI = uiLib;
100
- const code = naslUI.map((item, index) => `[3-${index}] ${item.name} | ${item.title} | ${item.description}`).join('\n');
101
- return { code, naslUI };
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
- const naslUI = uiLib.filter(
106
- (item, index) =>
107
- requiredIndexes.includes(`3-${index}`) ||
108
- item.name.endsWith('LinearLayout') ||
109
- item.name.endsWith('Text') ||
110
- item.name.endsWith('Link') ||
111
- item.name.endsWith('Button')
112
- );
113
- const code = wrapTSBlock(
114
- `${preDeclaration}\n${naslUI.map(
115
- (item) =>
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
- return { code, naslUI };
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,121 @@ export function getNaslOQL() {
134
187
  return { code, naslOql };
135
188
  }
136
189
 
137
- export function getEnums(app: App, state: TranslatorState, requiredIndexes?: string[]) {
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 { code, namespace, enums: { namespace, data } };
151
- }
209
+ return code;
210
+ };
152
211
 
153
- export function getEntities(app: App, state: TranslatorState, requiredIndexes?: string[]) {
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
218
  .filter((entity) => !entity.name.startsWith('LCAP') || entity.name === 'LCAPUser')
163
219
  .forEach((entity) => {
164
- const entityName = needNamespace ? `app.dataSources.${dataSource?.name}.entities.${entity?.name}` : undefined;
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 { code, entities };
174
- }
240
+ return code;
241
+ };
175
242
 
176
- export function getStructures(app: App, state: TranslatorState, requiredIndexes?: string[]) {
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
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 { code, structures: { namespace, data } };
192
- }
264
+ return code;
265
+ };
266
+
193
267
 
194
- export function getLogics(app: App, currentNode: BaseNode, requiredIndexes?: string[]) {
195
- const hasModuleIndexList = requiredIndexes?.length > 0;
268
+ export function getLogics(app: App, currentNode: BaseNode) {
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, index) => {
202
- const logicIndex = `6-${index}`;
203
- if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex)) return;
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({ needNamespace: true, rename, declaration: true })}`;
207
276
  const description = logic?.description || '';
208
- code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
277
+
209
278
  data.push({ description, code: tempCode });
210
279
  });
211
- return { code, appLogics: { namespace, data } };
280
+ return { appLogics: { namespace, data } };
212
281
  }
213
282
 
214
- export function getModuleInterfaces(app: App, state: TranslatorState, requiredIndexes?: string[]) {
215
- const hasModuleIndexList = requiredIndexes?.length > 0;
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}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
291
+ });
292
+ return code;
293
+ };
294
+
295
+
296
+ export function getModuleInterfaces(modules: Module[], state: TranslatorState) {
216
297
  const interfaceDependencies = [] as {
217
298
  name: string;
218
299
  structures: SnippetBlock;
219
300
  logics: SnippetBlock;
220
301
  }[];
221
- let code = '';
222
- app?.interfaceDependencies?.forEach((interfaceDependency, moduleIndex) => {
302
+ modules?.forEach((interfaceDependency) => {
303
+ interfaceDependency = new Module(interfaceDependency);
304
+ interfaceDependency.parentKey = 'interfaceDependencies';
223
305
  const name = interfaceDependency?.name;
224
306
  let structures = {} as SnippetBlock;
225
307
  let logics = {} as SnippetBlock;
@@ -234,37 +316,46 @@ export function getModuleInterfaces(app: App, state: TranslatorState, requiredIn
234
316
 
235
317
  const logicNamespace = `${namespace}.interfaces`;
236
318
  const logicData = [] as Snippet[];
237
- interfaceDependency?.interfaces?.forEach((interface_: any, index) => {
238
- const interfaceIndex = `7-${moduleIndex}-${index}`;
239
- if (hasModuleIndexList && !requiredIndexes?.includes(interfaceIndex)) return;
319
+ interfaceDependency?.interfaces?.forEach((interface_: any) => {
240
320
  const description = interface_?.description || '';
241
- const interfaceName = requiredIndexes?.length >= 0 ? interface_?.calleewholeKey : undefined;
242
- const needNamespace = requiredIndexes?.length >= 0;
243
- const tempCode = interface_?.toNaturalTS(createCompilerState('', { needNamespace }), interfaceName);
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
- }
321
+ const interfaceName = interface_?.calleewholeKey;
322
+ const tempCode = interface_?.toNaturalTS(createCompilerState('', { needNamespace: true }), interfaceName);
323
+ const codeWithDetail = getLogicWithStructuresCode(interface_, 'interface', { description, codeStr: tempCode }, structureNamespace);
324
+ logicData.push({ description, code: tempCode, codeWithDetail });
251
325
  });
252
326
  logics = { namespace: logicNamespace, data: logicData };
253
327
 
254
328
  interfaceDependencies.push({ name, structures, logics });
255
329
  });
256
- return { code, interfaceDependencies };
330
+ return { interfaceDependencies };
257
331
  }
258
332
 
259
- export function getConnectors(app: App, state: TranslatorState, requiredIndexes?: string[]) {
260
- const hasModuleIndexList = requiredIndexes?.length > 0;
333
+ export const getModuleInterfacesCode = (interfaceDependencies: any, codeType: 'detail' | 'short', requiredIndexes?: string[]) => {
334
+ let code = '';
335
+ interfaceDependencies.forEach((interfaceDependency: any, index: number) => {
336
+ interfaceDependency?.logics?.data?.forEach((item: any, idx: number) => {
337
+ const interfaceIndex = `7-${index}-${idx}`;
338
+ if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex)) return;
339
+ if (codeType === 'short') {
340
+ const tempCode = item.code.replace(`${interfaceDependency?.logics.namespace}.`, '');
341
+ code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
342
+ } else {
343
+ code += item.codeWithDetail;
344
+ }
345
+ });
346
+ });
347
+ return code;
348
+ };
349
+
350
+
351
+ // 连接
352
+ export function getConnections(modules: Connection[], state: TranslatorState) {
261
353
  const connections = [] as {
262
354
  name: string;
263
355
  structures: SnippetBlock;
264
356
  logics: SnippetBlock;
265
357
  }[];
266
- let code = '';
267
- app?.connections?.forEach((connection, connectionIndex) => {
358
+ modules?.forEach((connection) => {
268
359
  const name = connection?.name;
269
360
 
270
361
  let structures = {} as SnippetBlock;
@@ -279,99 +370,173 @@ export function getConnectors(app: App, state: TranslatorState, requiredIndexes?
279
370
  });
280
371
  structures = { namespace: structureNamespace, data: structureData };
281
372
 
282
- code += `[8-${connectionIndex}] ${connection?.connector?.title}\n`;
283
373
  const logicData = [] as Snippet[];
284
- connection?.connector?.namespaces?.forEach((namespace: Namespace, namespaceIndex: number) => {
285
- namespace?.logics?.forEach((logic: Logic, index) => {
286
- const logicIndex = `8-${connectionIndex}-${namespaceIndex}-${index}`;
287
- if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex)) return;
374
+ connection?.connector?.namespaces?.forEach((namespace: Namespace) => {
375
+ const curNameSpace = `${connectionNamespace}.${namespace?.name}`;
376
+ namespace?.logics?.forEach((logic: Logic) => {
288
377
  const description = `${logic?.description || logic?.title || ''}`;
289
- const rename = requiredIndexes?.length >= 0 ? `${connection?.name}.${logic?.calleewholeKey}` : undefined;
290
- const needNamespace = requiredIndexes?.length >= 0;
291
- const tempCode = `${logic?.toNaturalTS(shiftState(state, code, { needNamespace, rename, declaration: true }))}`;
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
- }
378
+ const rename = `${connection?.name}.${logic?.calleewholeKey}`;
379
+ const tempCode = `${logic?.toNaturalTS(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 });
299
382
  });
300
383
  });
301
384
 
302
385
  if (!connection?.connector?.namespaces?.length && connection?.connector?.logics?.length) {
303
- connection?.connector?.logics.forEach((logic: Logic, index: number) => {
304
- const logicIndex = `8-${connectionIndex}-${index}`;
305
- if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex)) return;
386
+ connection?.connector?.logics.forEach((logic: Logic) => {
306
387
  const description = logic?.description || '';
307
- const rename = requiredIndexes?.length >= 0 ? `${connection?.name}.${logic?.calleewholeKey}` : undefined;
308
- const needNamespace = requiredIndexes?.length >= 0;
309
- const tempCode = `${logic?.toNaturalTS(shiftState(state, code, { needNamespace, rename, declaration: true }))}`;
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
- }
388
+ const rename = `${connection?.name}.${logic?.calleewholeKey}`;
389
+ const tempCode = `${logic?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename, declaration: true }))}`;
390
+ const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
391
+ logicData.push({ description, code: tempCode, codeWithDetail });
317
392
  });
318
393
  }
319
394
  logics = { namespace: connectionNamespace, data: logicData };
320
395
  connections.push({ name, structures, logics });
321
396
  });
322
- return { code, connections };
397
+ return { connections };
323
398
  }
324
399
 
325
- export function getDependencies(app: App, state: TranslatorState, requiredIndexes?: string[]) {
326
- const hasModuleIndexList = requiredIndexes?.length > 0;
327
- const dependencies = [] as {
400
+ // 连接器
401
+ export function getConnectors(modules: Connector[], state: TranslatorState) {
402
+ const connectors = [] as {
328
403
  name: string;
329
404
  structures: SnippetBlock;
330
405
  logics: SnippetBlock;
331
406
  }[];
332
- let code = '';
333
- app?.dependencies
334
- ?.filter((dependency) => dependency.concept === 'Module')
335
- ?.forEach((module, moduleIndex) => {
336
- // 区分一下扩展组件和依赖库
337
- if (module?.logics?.length) {
338
- const name = module?.name;
339
- let structures = {} as SnippetBlock;
340
- let logics = {} as SnippetBlock;
341
- const namespace = `extensions.${name}`;
342
- const structureNamespace = `${namespace}.structures`;
343
- const structureData = [] as Snippet[];
344
- module?.structures?.forEach((structure) => {
345
- const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}`;
346
- structureData.push({ description: structure?.description || structure?.name, code: tempCode });
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 };
407
+ modules?.forEach((connector) => {
408
+ connector = new Connector(connector);
409
+ connector.parentKey = 'connectorDependencies';
410
+ const { name } = connector;
411
+ let structures = {} as SnippetBlock;
412
+ let logics = {} as SnippetBlock;
368
413
 
369
- dependencies.push({ name, structures, logics });
414
+ const connectorNamespace = `${name}.connector.${name}`;
415
+ const structureNamespace = `connector.${name}.structures`;
416
+ const structureData = [] as Snippet[];
417
+ connector?.structures?.forEach((structure: Structure) => {
418
+ const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}`;
419
+ structureData.push({ description: structure?.description || structure?.name, code: tempCode });
420
+ });
421
+ structures = { namespace: structureNamespace, data: structureData };
422
+
423
+ const logicData = [] as Snippet[];
424
+ connector?.namespaces?.forEach((namespace: Namespace) => {
425
+ const curNameSpace = `${connectorNamespace}.${namespace?.name}`;
426
+ namespace?.logics?.forEach((logic: Logic) => {
427
+ const description = `${logic?.description || logic?.title || ''}`;
428
+ const rename = `${name}.${logic?.calleewholeKey}`;
429
+ const tempCode = `${logic?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename, declaration: true }))}`;
430
+ const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
431
+ logicData.push({ description, code: tempCode, codeWithDetail, namespace: curNameSpace });
432
+ });
433
+ });
434
+
435
+ if (!connector?.namespaces?.length && connector?.logics?.length) {
436
+ connector?.logics.forEach((logic: Logic) => {
437
+ const description = logic?.description || '';
438
+ const rename = `${name}.${logic?.calleewholeKey}`;
439
+ const tempCode = `${logic?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename, declaration: true }))}`;
440
+ const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
441
+ logicData.push({ description, code: tempCode, codeWithDetail });
442
+ });
443
+ }
444
+ logics = { namespace: connectorNamespace, data: logicData };
445
+ connectors.push({ name, structures, logics });
446
+ });
447
+
448
+ return { connectors };
449
+ }
450
+
451
+ export const getConnectorsCode = (connections: any, codeType: 'detail' | 'short', requiredIndexes?: string[]) => {
452
+ let code = '';
453
+ connections.forEach((connection: any, index: number) => {
454
+ connection?.logics?.data?.forEach((item: any, idx: number) => {
455
+ const interfaceIndex = `8-${index}-${idx}`;
456
+ if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex)) return;
457
+ if (codeType === 'short') {
458
+ const namespace = item?.namespace || connection?.logics.namespace;
459
+ const tempCode = item.code.replace(`${namespace}.`, '');
460
+ code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
461
+ } else {
462
+ code += item.codeWithDetail;
370
463
  }
371
464
  });
372
- return { code, dependencies };
465
+ });
466
+ return code;
467
+ };
468
+
469
+
470
+ export function getDependencies(modules: Module[], state: TranslatorState, logicType: any, frontendType: 'pc' | 'h5') {
471
+ const dependencies = [] as {
472
+ name: string;
473
+ structures: SnippetBlock;
474
+ logics: SnippetBlock;
475
+ }[];
476
+ modules?.forEach((module) => {
477
+ module = new Module(module);
478
+ module.parentKey = 'dependencies';
479
+ // 根据类型获取对应的逻辑
480
+ let curLogics = module?.logics;
481
+ if (logicType !== 'global_logic' && frontendType) {
482
+ module?.frontends?.forEach((frontend: any) => {
483
+ if (frontend.type === frontendType) {
484
+ curLogics = curLogics.concat([...frontend?.logics]);
485
+ }
486
+ });
487
+ }
488
+
489
+ if (curLogics?.length) {
490
+ const name = module?.name;
491
+ let structures = {} as SnippetBlock;
492
+ let logics = {} as SnippetBlock;
493
+ const namespace = `extensions.${name}`;
494
+ const structureNamespace = `${namespace}.structures`;
495
+ const structureData = [] as Snippet[];
496
+ module?.structures?.forEach((structure) => {
497
+ const tempCode = structure?.toNaturalTS ? `${structure?.toNaturalTS({ ...state, needNamespace: true })}` : '';
498
+ structureData.push({ description: structure?.description || structure?.name, code: tempCode });
499
+ });
500
+ structures = { namespace: structureNamespace, data: structureData };
501
+
502
+ let logicsNamespace = '';
503
+ const logicData = [] as Snippet[];
504
+ curLogics?.forEach((logic) => {
505
+ const description = logic?.description || '';
506
+ const rename = logic?.calleewholeKey;
507
+ logicsNamespace = logic?.calleewholeKey.replace(`.${logic.name}`, '');
508
+ const tempCode = `${logic?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename, declaration: true }))}`;
509
+ const codeWithDetail = getLogicWithStructuresCode(logic, 'extension', { description, codeStr: tempCode }, structureNamespace);
510
+
511
+ logicData.push({ description, code: tempCode, codeWithDetail });
512
+ });
513
+ logics = { namespace: logicsNamespace, data: logicData };
514
+
515
+ dependencies.push({ name, structures, logics });
516
+ }
517
+ });
518
+ return { dependencies };
373
519
  }
374
520
 
521
+
522
+ export const getDependenciesCode = (dependencies: any, codeType: 'detail' | 'short', requiredIndexes?: string[]) => {
523
+ let code = '';
524
+ dependencies.forEach((dependency: any, index: number) => {
525
+ dependency?.logics?.data?.forEach((item: any, idx: number) => {
526
+ const logicIndex = `9-${index}-${idx}`;
527
+ if (requiredIndexes?.length && !requiredIndexes?.includes(logicIndex)) return;
528
+ if (codeType === 'short') {
529
+ const tempCode = item.code.replace(`${dependency?.logics.namespace}.`, '');
530
+ code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
531
+ } else {
532
+ code += item.codeWithDetail;
533
+ }
534
+ });
535
+ });
536
+ return code;
537
+ };
538
+
539
+
375
540
  export function getFrontendVariables(frontend: Frontend, state: TranslatorState) {
376
541
  let code = '';
377
542
  frontend?.variables?.forEach((variable) => {
@@ -428,6 +593,16 @@ export function getFrontendViews(frontend: Frontend, state: TranslatorState, cur
428
593
  return { code: wrapTSBlock(code), views: { namespace, data } };
429
594
  }
430
595
 
596
+ export const getFrontendViewsCode = (views: any) => {
597
+ let code = '';
598
+ views?.data?.forEach((item: any) => {
599
+ code += `/* ${item.description} */ \n`;
600
+ code += item.code;
601
+ code += `\n`;
602
+ });
603
+ return wrapTSBlock(code);
604
+ };
605
+
431
606
  export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: string) {
432
607
  let code = '';
433
608
  let view: View;