@lcap/nasl 3.3.0-alpha.3 → 3.4.0-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.
@@ -1,81 +1,90 @@
1
- import {
2
- App, Module, View, Entity, Structure, Enum,
3
- uiStructures, collectionStructures, interfaceStructures, processStructures,
4
- Logic, Interface, Process, BaseNode,
5
- } from '../concepts';
1
+ import { App, View, Logic, BaseNode, Frontend } from '../concepts';
6
2
  import { shiftState, createCompilerState } from '../translator';
7
3
 
8
4
  import naslStdlibMap from './naslStdlibMap';
9
5
 
10
6
  export function genNaturalTS(app: App, currentNode?: BaseNode) {
11
- const logic = currentNode as Logic;
12
- const code = logic.toNaturalTS(undefined);
13
- return code;
7
+ const logic = currentNode as Logic;
8
+ const code = logic.toNaturalTS(undefined);
9
+ return code;
14
10
  }
15
11
 
16
12
  export function genNaturalTSContext(app: App, currentNode?: BaseNode) {
13
+ let code = `### 低代码应用的 ts 上下文定义如下:\n`;
14
+ /* 标准库 */
15
+ code += `\`\`\`ts\n`;
16
+ code += '// 标准库\n';
17
+ code += `${Object.values(naslStdlibMap).join('\n')}\n`;
18
+ /* 全局上下文 */
19
+ code += '\n// 全局上下文\n';
20
+ app.enums.forEach((enumeration) => code += `${enumeration.toNaturalTS()}\n`);
21
+ app.dataSources.forEach((dataSource) => dataSource.entities
22
+ .filter((entity) => !entity.name.startsWith('LCAP') || entity.name === 'LCAPUser')
23
+ .forEach((entity) => code += `${entity.toNaturalTS()}\n`));
24
+ app.structures
25
+ .filter((entity) => !entity.name.startsWith('LCAP'))
26
+ .forEach((structure) => code += `${structure.toNaturalTS()}\n`);
27
+
28
+ code += '\n// 服务端逻辑\n';
29
+ app.logics
30
+ .filter((logic) => logic !== currentNode && !logic.name.startsWith('LCAP'))
31
+ .forEach((logic) => code += `${logic.toNaturalTS(undefined, undefined, undefined, currentNode)}`);
17
32
 
18
- let code = `### 低代码平台的 ts 定义如下:\n`;
19
- /* 标准库 */
20
- code += `\`\`\`ts\n`;
21
- code += '// 标准库\n';
22
- code += Object.values(naslStdlibMap).join('\n') + '\n';
23
- /* 全局上下文 */
24
- code += '// 全局上下文\n';
25
- app.enums.forEach((enumeration) => code += enumeration.toNaturalTS() + '\n');
26
- app.dataSources.forEach((dataSource) => dataSource.entities
27
- .filter((entity) => !entity.name.startsWith('LCAP') || entity.name === 'LCAPUser')
28
- .forEach((entity) => code += entity.toNaturalTS() + '\n'));
29
- app.structures
30
- .filter((entity) => !entity.name.startsWith('LCAP'))
31
- .forEach((structure) => code += structure.toNaturalTS() + '\n');
32
- code += '// 全局变量\n';
33
- const variables = app.frontends.flatMap((item) => item.variables).filter((item) => !!item);
34
- variables.forEach((variable) => {
35
- const state = createCompilerState();
36
- code += 'let ';
37
- code += variable.toNaturalTS(shiftState(state, code, { inline: true }));
38
- code += ';\n';
33
+
34
+ const frontend = currentNode?.getAncestor('Frontend') as Frontend;
35
+ if (frontend) {
36
+ code += '\n// 前端全局变量\n';
37
+ frontend.variables.forEach((variable) => {
38
+ const state = createCompilerState();
39
+ code += 'let ';
40
+ code += variable.toNaturalTS(shiftState(state, code, { inline: true }));
41
+ code += ';\n';
42
+ });
43
+
44
+ code += '\n// 前端页面\n';
45
+ frontend.views.forEach((view) => {
46
+ code += view.toNaturalTS(undefined, currentNode, true);
39
47
  });
48
+ }
40
49
 
41
- /* 页面上下文 */
42
- let view: View;
43
- if (currentNode?.concept === 'View')
44
- view = currentNode as View;
45
- else if (currentNode) {
46
- if (!currentNode.getAncestor)
47
- console.log(currentNode.concept, currentNode.parentNode?.concept);
48
- view = currentNode.getAncestor('View') as View;
50
+ /* 页面上下文 */
51
+ let view: View;
52
+ if (currentNode?.concept === 'View') {
53
+ view = currentNode as View;
54
+ } else if (currentNode) {
55
+ if (!currentNode.getAncestor) {
56
+ console.log(currentNode.concept, currentNode.parentNode?.concept);
49
57
  }
58
+ view = currentNode.getAncestor('View') as View;
59
+ }
50
60
 
51
- if (currentNode?.concept === 'ViewElement') {
52
- code += '// 页面变量\n';
53
- view.variables.forEach((variable) => {
54
- const state = createCompilerState();
55
- code += 'let ';
56
- code += variable.toNaturalTS(shiftState(state, code, { inline: true }));
57
- code += ';\n';
58
- });
59
- code += 'let current.item.supplier: Supplier; \n';
60
- code += '\n';
61
- return code;
62
- }
63
- /* 逻辑上下文 */
64
- let logic: Logic;
65
- if (currentNode?.concept === 'Logic')
66
- logic = currentNode as Logic;
67
- else if (currentNode) {
68
- logic = currentNode.getAncestor('Logic') as Logic;
69
- }
70
- // code += '// 页面上下文\n';
71
- code += `\`\`\`\n`;
72
- code += '### 当前逻辑的 ts 定义\n';
73
- code += `\`\`\`ts\n`;
74
- if (view) { // 为页面中的逻辑
75
- code += view.toNaturalTS(undefined, currentNode);
76
- } else if (logic) { // 为全局逻辑
77
- code += logic.toNaturalTS(undefined);
78
- }
79
- code += `\`\`\`\n`;
61
+ if (currentNode?.concept === 'ViewElement') {
62
+ code += '\n// 页面变量\n';
63
+ view.variables.forEach((variable) => {
64
+ const state = createCompilerState();
65
+ code += 'let ';
66
+ code += variable.toNaturalTS(shiftState(state, code, { inline: true }));
67
+ code += ';\n';
68
+ });
69
+ code += 'let current.item.supplier: Supplier; \n';
70
+ code += '\n';
80
71
  return code;
72
+ }
73
+
74
+ /* 逻辑上下文 */
75
+ let logic: Logic;
76
+ if (currentNode?.concept === 'Logic')
77
+ logic = currentNode as Logic;
78
+ else if (currentNode) {
79
+ logic = currentNode.getAncestor('Logic') as Logic;
80
+ }
81
+ // code += '// 页面上下文\n';
82
+ code += ``;
83
+ if (view) { // 为页面中的逻辑
84
+ code += view.toNaturalTS(undefined, currentNode);
85
+ } else if (logic) { // 为全局逻辑
86
+ code += logic.toNaturalTS(undefined);
87
+ }
88
+ code += `\n\`\`\`\n`;
89
+ return code;
81
90
  }