@lcap/nasl 3.8.2-alpha.1 → 3.8.2-alpha.3
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/common/ComponentAPI.d.ts +9 -0
- package/out/concepts/AuthLogicForCallInterface__.js +21 -6
- package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
- package/out/concepts/BindAttribute__.js +11 -3
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BusinessComponent__.js +24 -8
- package/out/concepts/BusinessComponent__.js.map +1 -1
- package/out/concepts/BusinessLogic__.js +21 -6
- package/out/concepts/BusinessLogic__.js.map +1 -1
- package/out/concepts/CallInterface__.js +2 -1
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.js +1 -1
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/Logic__.js +43 -16
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MemberExpression__.js +19 -13
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/OverriddenLogic__.js +21 -6
- package/out/concepts/OverriddenLogic__.js.map +1 -1
- package/out/concepts/Param__.js +5 -4
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/Structure__.js +4 -4
- package/out/concepts/Structure__.js.map +1 -1
- package/out/concepts/ViewElement__.js +0 -5
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.js +50 -19
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.processV2.js +78 -0
- package/out/concepts/basics/stdlib/nasl.processV2.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 +14 -9
- package/out/natural/genNaturalTS.js +34 -25
- package/out/natural/genNaturalTS.js.map +1 -1
- package/out/natural/getContext/getUILib.js +2 -2
- package/out/natural/getContext/getUILib.js.map +1 -1
- package/out/natural/getContext/index.d.ts +6 -3
- package/out/natural/getContext/index.js +106 -12
- package/out/natural/getContext/index.js.map +1 -1
- package/out/natural/getContext/naslStdlibMap.js +8 -8
- package/out/natural/getContext/naslStdlibMap.js.map +1 -1
- package/out/natural/tools.d.ts +8 -0
- package/out/natural/tools.js +52 -1
- package/out/natural/tools.js.map +1 -1
- package/out/server/getMemberIdentifier.js +11 -17
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/naslServer.js +1 -1
- package/out/server/naslServer.js.map +1 -1
- package/out/translator/types.d.ts +2 -0
- package/package.json +1 -1
- package/sandbox/stdlib/nasl.processV2.ts +19 -0
- package/sandbox-natural/stdlib/nasl.core.d.ts +54 -0
- package/sandbox-natural/stdlib/nasl.oql.d.ts +22 -0
- package/sandbox-natural/stdlib/{nasl.ui.pre.d.ts → nasl.ui.d.ts} +20 -44
- package/sandbox-natural/stdlib/nasl.ui.h5.d.ts +1684 -1643
- package/sandbox-natural/stdlib/nasl.ui.h5.json +15746 -15045
- package/sandbox-natural/stdlib/nasl.ui.pc.d.ts +5341 -5154
- package/sandbox-natural/stdlib/nasl.ui.pc.json +31176 -30681
- package/sandbox-natural/stdlib/{nasl.util.ts → nasl.util.d.ts} +43 -37
- package/src/common/ComponentAPI.ts +7 -0
- package/src/concepts/AuthLogicForCallInterface__.ts +23 -6
- package/src/concepts/BindAttribute__.ts +17 -12
- package/src/concepts/BusinessComponent__.ts +26 -8
- package/src/concepts/BusinessLogic__.ts +23 -6
- package/src/concepts/CallInterface__.ts +2 -2
- package/src/concepts/CallLogic__.ts +1 -1
- package/src/concepts/Logic__.ts +58 -32
- package/src/concepts/MemberExpression__.ts +20 -13
- package/src/concepts/OverriddenLogic__.ts +23 -6
- package/src/concepts/Param__.ts +5 -4
- package/src/concepts/Structure__.ts +4 -4
- package/src/concepts/ViewElement__.ts +1 -7
- package/src/concepts/View__.ts +55 -21
- package/src/concepts/basics/stdlib/nasl.processV2.ts +79 -0
- package/src/generator/genBundleFiles.ts +1 -1
- package/src/natural/genNaturalTS.ts +47 -31
- package/src/natural/getContext/getUILib.ts +2 -2
- package/src/natural/getContext/index.ts +87 -11
- package/src/natural/getContext/naslStdlibMap.ts +8 -8
- package/src/natural/tools.ts +50 -1
- package/src/server/getMemberIdentifier.ts +14 -14
- package/src/server/naslServer.ts +1 -1
- package/src/translator/types.ts +2 -0
- package/test/concepts/member-expression/__snapshots__/toJS.spec.ts.snap +1 -1
- package/test/concepts/member-expression/__snapshots__/toVue.spec.ts.snap +1 -1
- package/sandbox-natural/stdlib/nasl.core.ts +0 -47
- package/sandbox-natural/stdlib/nasl.oql.ts +0 -14
- package/sandbox-natural/stdlib/nasl.ui.ts +0 -63
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as utils from '../../utils';
|
|
1
2
|
import { App, View, Logic, BaseNode, Frontend, Namespace, Module, TypeAnnotation, Structure, Connection, Connector } from '../../concepts';
|
|
2
3
|
import { shiftState, createCompilerState, TranslatorState, indent } from '../../translator';
|
|
3
4
|
import { getPreDeclaration, getUILib, handleMaterial, getExtensionsMaterial } from './getUILib';
|
|
@@ -86,7 +87,7 @@ export function getLogicWithStructuresCode(logic: Logic, type: string, desc: { d
|
|
|
86
87
|
|
|
87
88
|
newRelationStructures?.forEach((reference: { typeNamespace: string; typeName: string; }) => {
|
|
88
89
|
const { typeName } = reference || {};
|
|
89
|
-
const state = createCompilerState();
|
|
90
|
+
const state = createCompilerState('', { descriptionComment: true });
|
|
90
91
|
const tabSize = namespace ? shiftState(state, code, { tabSize: 1 }) : undefined;
|
|
91
92
|
structures?.filter((structure: any) => structure?.name === typeName)
|
|
92
93
|
?.forEach((structure: any) => {
|
|
@@ -96,15 +97,15 @@ export function getLogicWithStructuresCode(logic: Logic, type: string, desc: { d
|
|
|
96
97
|
if (namespace && newRelationStructures?.length) {
|
|
97
98
|
code += `}\n`;
|
|
98
99
|
}
|
|
99
|
-
const {
|
|
100
|
-
if (description) code += `// ${description}\n`;
|
|
100
|
+
const { codeStr } = desc || {};
|
|
101
|
+
// if (description) code += `// ${description}\n`;
|
|
101
102
|
if (codeStr) code += `${codeStr}\n`;
|
|
102
103
|
code = wrapTSBlock(code);
|
|
103
104
|
return code;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
export function getNaslCore(logicType: string) {
|
|
107
|
-
let naslCore = `${getNASLStdlibMap('nasl.core.ts')}\n`;
|
|
108
|
+
let naslCore = `${getNASLStdlibMap('nasl.core.d.ts')}\n`;
|
|
108
109
|
if (logicType === 'global_logic')
|
|
109
110
|
naslCore += `// 分页组件函数,用于分页
|
|
110
111
|
declare function PAGINATE<T>(list: List<T>, page: Integer, size: Integer): { list: List<T>, total: Integer; };
|
|
@@ -114,7 +115,7 @@ declare function PAGINATE<T>(list: List<T>, page: Integer, size: Integer): { lis
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
export function getNaslUtil() {
|
|
117
|
-
const naslUtil = `${getNASLStdlibMap('nasl.util.ts')}\n`;
|
|
118
|
+
const naslUtil = `${getNASLStdlibMap('nasl.util.d.ts')}\n`;
|
|
118
119
|
const code = wrapTSBlock(naslUtil);
|
|
119
120
|
return { code, naslUtil };
|
|
120
121
|
}
|
|
@@ -125,7 +126,7 @@ export const getNaslUI = (
|
|
|
125
126
|
material:
|
|
126
127
|
{
|
|
127
128
|
basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
|
|
128
|
-
extensionMaterials: {
|
|
129
|
+
extensionMaterials: 'pc' | 'h5' | {
|
|
129
130
|
name: string;
|
|
130
131
|
title: string;
|
|
131
132
|
description: string;
|
|
@@ -176,13 +177,13 @@ ${item.tsDeclaration}`).join('\n')}`);
|
|
|
176
177
|
};
|
|
177
178
|
|
|
178
179
|
export const getNaslUIOld = () => {
|
|
179
|
-
const naslUI = `${getNASLStdlibMap('nasl.ui.ts')}\n`;
|
|
180
|
+
const naslUI = `${getNASLStdlibMap('nasl.ui.d.ts')}\n`;
|
|
180
181
|
const code = wrapTSBlock(naslUI);
|
|
181
182
|
return { code, naslUI };
|
|
182
183
|
};
|
|
183
184
|
|
|
184
185
|
export function getNaslOQL() {
|
|
185
|
-
const naslOql = `${getNASLStdlibMap('nasl.oql.ts')}\n`;
|
|
186
|
+
const naslOql = `${getNASLStdlibMap('nasl.oql.d.ts')}\n`;
|
|
186
187
|
const code = wrapTSBlock(naslOql);
|
|
187
188
|
return { code, naslOql };
|
|
188
189
|
}
|
|
@@ -616,7 +617,7 @@ export const getFrontendViewsCode = (views: any) => {
|
|
|
616
617
|
return wrapTSBlock(code);
|
|
617
618
|
};
|
|
618
619
|
|
|
619
|
-
export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: string, experimental?: boolean) {
|
|
620
|
+
export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: string, experimental?: boolean, typeMap?: any) {
|
|
620
621
|
let code = '';
|
|
621
622
|
let view: View;
|
|
622
623
|
if (currentNode?.concept === 'View') {
|
|
@@ -641,6 +642,7 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
|
|
|
641
642
|
createCompilerState('', {
|
|
642
643
|
focusedNodePath,
|
|
643
644
|
needNamespace: true,
|
|
645
|
+
typeMap,
|
|
644
646
|
}),
|
|
645
647
|
function (state) {
|
|
646
648
|
let code = '';
|
|
@@ -649,6 +651,7 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
|
|
|
649
651
|
if (experimental) {
|
|
650
652
|
code += this.elements[0].toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1 }));
|
|
651
653
|
} else {
|
|
654
|
+
code += `${indent(state.tabSize + 1)}`;
|
|
652
655
|
code += `const $refs = {\n`;
|
|
653
656
|
// 生成所有的name和类型定义
|
|
654
657
|
this.elements.forEach((element) => {
|
|
@@ -663,17 +666,36 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
|
|
|
663
666
|
// 逻辑
|
|
664
667
|
if (currentNode?.concept === 'Logic') {
|
|
665
668
|
code += '\n';
|
|
669
|
+
this.bindEvents.forEach((bindEvent) => {
|
|
670
|
+
bindEvent.logics.forEach((logic) => {
|
|
671
|
+
if (logic === currentNode) return;
|
|
672
|
+
const logicCode = logic.toNaturalTS(
|
|
673
|
+
shiftState(state, code, {
|
|
674
|
+
tabSize: state.tabSize + 1,
|
|
675
|
+
// declaration: true,
|
|
676
|
+
autoPrefixName: true,
|
|
677
|
+
})
|
|
678
|
+
);
|
|
679
|
+
code += logicCode.replace('function ', 'private function ');
|
|
680
|
+
code += '\n';
|
|
681
|
+
});
|
|
682
|
+
if (bindEvent.logics.length) code += '\n';
|
|
683
|
+
});
|
|
684
|
+
|
|
666
685
|
this.logics.forEach((logic) => {
|
|
667
686
|
if (logic === currentNode) return;
|
|
668
|
-
|
|
687
|
+
const logicCode = logic.toNaturalTS(
|
|
669
688
|
shiftState(state, code, {
|
|
670
689
|
tabSize: state.tabSize + 1,
|
|
671
690
|
declaration: true,
|
|
672
691
|
autoPrefixName: true,
|
|
673
692
|
})
|
|
674
693
|
);
|
|
694
|
+
code += logicCode.replace('declare function', 'function');
|
|
675
695
|
code += '\n';
|
|
676
696
|
});
|
|
697
|
+
if (this.logics.length) code += '\n';
|
|
698
|
+
|
|
677
699
|
// 包含了事件逻辑的处理
|
|
678
700
|
code += `${indent(state.tabSize + 1)}/* 当前逻辑 */\n`;
|
|
679
701
|
code += (currentNode as Logic).toNaturalTS(
|
|
@@ -710,13 +732,14 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
|
|
|
710
732
|
needNamespace: true,
|
|
711
733
|
declaration: logic !== currentNode,
|
|
712
734
|
autoPrefixName: true,
|
|
735
|
+
typeMap
|
|
713
736
|
})
|
|
714
737
|
);
|
|
715
738
|
}
|
|
716
739
|
return { code: wrapTSBlock(code), currentLogic: code };
|
|
717
740
|
}
|
|
718
741
|
|
|
719
|
-
export function getCurrentNodeContextForUI(currentNode: BaseNode) {
|
|
742
|
+
export function getCurrentNodeContextForUI(currentNode: BaseNode, typeMap?: any) {
|
|
720
743
|
let code = '';
|
|
721
744
|
let view: View;
|
|
722
745
|
if (currentNode?.concept === 'View') {
|
|
@@ -735,9 +758,62 @@ export function getCurrentNodeContextForUI(currentNode: BaseNode) {
|
|
|
735
758
|
code += view?.toNaturalTS(
|
|
736
759
|
createCompilerState('', {
|
|
737
760
|
needNamespace: true,
|
|
761
|
+
typeMap,
|
|
738
762
|
})
|
|
739
763
|
);
|
|
740
764
|
}
|
|
741
765
|
|
|
742
766
|
return { code: wrapTSBlock(code), currentLogic: code };
|
|
743
767
|
}
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
const calcComponent = (activeDesignerNode: any) => {
|
|
771
|
+
const view = activeDesignerNode?.concept === 'View' ? activeDesignerNode?.elements?.[0] : (activeDesignerNode.getAncestor('View') as any)?.elements?.[0];
|
|
772
|
+
const componentSet = new Set();
|
|
773
|
+
if (view) {
|
|
774
|
+
utils.traverse(({ node }: { node: any; }) => {
|
|
775
|
+
if (node.concept === 'ViewElement') {
|
|
776
|
+
const name = utils.kebab2Camel(node.tag);
|
|
777
|
+
componentSet.add(name);
|
|
778
|
+
}
|
|
779
|
+
}, { node: view });
|
|
780
|
+
}
|
|
781
|
+
return componentSet;
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
const extractUFormClass = (tsDeclaration: string) => {
|
|
786
|
+
const regex = /class\s+(\w+)(?:<[^>]+>)?\s+extends\s+(\w+)\s*\{(.*?)\}/s;
|
|
787
|
+
const match = tsDeclaration.match(regex);
|
|
788
|
+
let code = '';
|
|
789
|
+
if (match) {
|
|
790
|
+
const [, className, baseClassName, classBody] = match;
|
|
791
|
+
const methodRegex = /\s*(\w+)\(([^)]*)\):\s*(\w+)/g;
|
|
792
|
+
code = `export class ${className} extends ${baseClassName} {`;
|
|
793
|
+
const newClassBody = classBody.replace(/nasl\.core\./g, "")
|
|
794
|
+
.replace(/Integer/g, "Long");
|
|
795
|
+
const body = newClassBody.replace(methodRegex, (method) => {
|
|
796
|
+
code += `${method};`;
|
|
797
|
+
return '';
|
|
798
|
+
});
|
|
799
|
+
code += `\n}\n`;
|
|
800
|
+
if (body === classBody) {
|
|
801
|
+
return '';
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
return code;
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
export function getCurrentComponentDeclaration(activeDesignerNode: any, components: any) {
|
|
808
|
+
let code = '';
|
|
809
|
+
const componentSet = calcComponent(activeDesignerNode);
|
|
810
|
+
if (!componentSet.size) return { componentDeclaration: '' };
|
|
811
|
+
// 遍历map,找到对应的组件
|
|
812
|
+
const result = components.filter((component: any) => componentSet.has(component.name));
|
|
813
|
+
result.forEach((component: any) => {
|
|
814
|
+
const newTsDeclaration = component.tsDeclaration;
|
|
815
|
+
const uFormClass = extractUFormClass(newTsDeclaration);
|
|
816
|
+
code += uFormClass;
|
|
817
|
+
});
|
|
818
|
+
return { componentDeclaration: code };
|
|
819
|
+
}
|
|
@@ -4,20 +4,20 @@ export const getNASLStdlibMap = (key?: string) => {
|
|
|
4
4
|
if (globalThis.process) { // For TS build
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
naslStdlibMap = {
|
|
7
|
-
'nasl.core.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.core.ts'), 'utf8'),
|
|
8
|
-
'nasl.util.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.util.ts'), 'utf8'),
|
|
9
|
-
'nasl.ui.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.ui.ts'), 'utf8'),
|
|
10
|
-
'nasl.oql.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.oql.ts'), 'utf8'),
|
|
7
|
+
'nasl.core.d.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.core.d.ts'), 'utf8'),
|
|
8
|
+
'nasl.util.d.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.util.d.ts'), 'utf8'),
|
|
9
|
+
'nasl.ui.d.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.ui.d.ts'), 'utf8'),
|
|
10
|
+
'nasl.oql.d.ts': fs.readFileSync(require.resolve('../../../sandbox-natural/stdlib/nasl.oql.d.ts'), 'utf8'),
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
/// #endif
|
|
14
14
|
/// #if process.env.BUILD_TARGET !== 'node'
|
|
15
15
|
if (globalThis.window) { // For TS build
|
|
16
16
|
naslStdlibMap = {
|
|
17
|
-
'nasl.core.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.core.ts').default,
|
|
18
|
-
'nasl.util.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.util.ts').default,
|
|
19
|
-
'nasl.ui.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.ui.ts').default,
|
|
20
|
-
'nasl.oql.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.oql.ts').default
|
|
17
|
+
'nasl.core.d.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.core.d.ts').default,
|
|
18
|
+
'nasl.util.d.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.util.d.ts').default,
|
|
19
|
+
'nasl.ui.d.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.ui.d.ts').default,
|
|
20
|
+
'nasl.oql.d.ts': require('!!raw-loader!../../../sandbox-natural/stdlib/nasl.oql.d.ts').default
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
/// #endif
|
package/src/natural/tools.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { App, BaseNode } from "src/concepts";
|
|
2
2
|
import * as utils from '../utils';
|
|
3
|
+
import { createCompilerState } from '../translator';
|
|
3
4
|
|
|
4
5
|
// 获取当前逻辑的类型
|
|
5
6
|
export const getLogicType = (activeLogic: any) => {
|
|
@@ -80,7 +81,7 @@ export const getUnImportedModulesForLogic = (json: BaseNode, app: App, material:
|
|
|
80
81
|
// 如果 连接器 不存在,则需要导入并初始化连接
|
|
81
82
|
if (!connectorNode) {
|
|
82
83
|
item.operator = 'importAndInit';
|
|
83
|
-
const curDep = material?.connectors?.find((node: any) => node.name === item.symbol)
|
|
84
|
+
const curDep = material?.connectors?.find((node: any) => node.name === item.symbol);
|
|
84
85
|
item.version = curDep?.version;
|
|
85
86
|
item.provider = curDep?.provider || '资产中心';
|
|
86
87
|
needImportModule.needImportConnector = true;
|
|
@@ -136,3 +137,51 @@ export const getUnImportedModulesForLogic = (json: BaseNode, app: App, material:
|
|
|
136
137
|
return needImportModule;
|
|
137
138
|
};
|
|
138
139
|
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 找到当前节点所使用的当前逻辑、服务端逻辑、组件相关的推导类型
|
|
144
|
+
* @param app: 当前应用
|
|
145
|
+
* @returns 推导类型集合
|
|
146
|
+
*/
|
|
147
|
+
export const deduceType = async (app: App, activeDesignerNode: any) => {
|
|
148
|
+
const typeMap = {} as any;
|
|
149
|
+
const { logics } = app;
|
|
150
|
+
const state = createCompilerState('', { descriptionComment: true, needNamespace: true });
|
|
151
|
+
|
|
152
|
+
logics.forEach((logic: any) => {
|
|
153
|
+
if (logic?.returns?.length && !logic.name.startsWith('LCAP')) {
|
|
154
|
+
const ret = logic.returns[0];
|
|
155
|
+
const typeAnnotation = ret?.typeAnnotation || ret?.__TypeAnnotation;
|
|
156
|
+
typeMap[ret.nodePath] = typeAnnotation.toNaturalTS(state);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
const params = activeDesignerNode?.params.concat(activeDesignerNode?.virtualParams || []);
|
|
160
|
+
if (params?.length) {
|
|
161
|
+
let code = '';
|
|
162
|
+
params?.forEach((param: any, index: number) => {
|
|
163
|
+
if (param.name === 'event') code += 'event';
|
|
164
|
+
else code += param.toNaturalTS(state);
|
|
165
|
+
if (index !== params.length - 1) code += ', ';
|
|
166
|
+
});
|
|
167
|
+
typeMap[activeDesignerNode.nodePath] = code;
|
|
168
|
+
}
|
|
169
|
+
const view = activeDesignerNode?.concept === 'View' ? activeDesignerNode?.elements?.[0] : (activeDesignerNode.getAncestor('View') as any)?.elements?.[0];
|
|
170
|
+
if (view) {
|
|
171
|
+
const dataSchemaMap = {} as any;
|
|
172
|
+
utils.traverse(({ node }: { node: any; }) => {
|
|
173
|
+
if (node.concept === 'ViewElement') {
|
|
174
|
+
const dataSchema = node.bindAttrs.find((_: any) => _.name === 'dataSchema');
|
|
175
|
+
if (dataSchema) dataSchemaMap[dataSchema.nodePath] = node;
|
|
176
|
+
}
|
|
177
|
+
}, { node: view });
|
|
178
|
+
await Promise.all(Object.entries(dataSchemaMap).map(async ([nodePath, node]) => {
|
|
179
|
+
const res = await app.naslServer.getDataSchemaStructureOrTypeAnnotation(node as any);
|
|
180
|
+
if (res) {
|
|
181
|
+
const dataSchemaTs = res.toNaturalTS(state);
|
|
182
|
+
typeMap[nodePath] = dataSchemaTs;
|
|
183
|
+
}
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
return { typeMap };
|
|
187
|
+
};
|
|
@@ -15,9 +15,9 @@ import {
|
|
|
15
15
|
types,
|
|
16
16
|
ViewElement,
|
|
17
17
|
PAGE_COMPONENT_INCLUDE_TAG_MAP,
|
|
18
|
-
ComponentCompletionPropertyMap,
|
|
19
18
|
configurationEnums,
|
|
20
19
|
processV2Enums,
|
|
20
|
+
config,
|
|
21
21
|
} from '..';
|
|
22
22
|
import { formatVariableData, formatFrontEndVariables, formatConfigProperties, formatBackendVariables } from './formatTsUtils';
|
|
23
23
|
|
|
@@ -422,8 +422,8 @@ export function getConfigsIdentifier(node: BaseNode): CompletionProperty[] {
|
|
|
422
422
|
}
|
|
423
423
|
function flatElements(elements: ViewElement[], componentList: CompletionProperty[], nodeParentElement: string, currentAttriBute: string, parentNodeNames: string[]) {
|
|
424
424
|
elements?.forEach((item) => {
|
|
425
|
-
// 根据
|
|
426
|
-
if (
|
|
425
|
+
// 根据readablePropsMap添加
|
|
426
|
+
if (config?.allNodesAPI[item.tag] && config?.allNodesAPI[item.tag].readablePropsMap) {
|
|
427
427
|
// 是否当前组件
|
|
428
428
|
const isCurrent = item.name === nodeParentElement;
|
|
429
429
|
const stashItem: any = {
|
|
@@ -436,9 +436,9 @@ function flatElements(elements: ViewElement[], componentList: CompletionProperty
|
|
|
436
436
|
children: [],
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
-
for (const key in
|
|
440
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
441
|
-
const property =
|
|
439
|
+
for (const key in config?.allNodesAPI[item.tag].readablePropsMap) {
|
|
440
|
+
if (Object.prototype.hasOwnProperty.call(config?.allNodesAPI[item.tag].readablePropsMap, key)) {
|
|
441
|
+
const property = config?.allNodesAPI[item.tag].readablePropsMap[key];
|
|
442
442
|
|
|
443
443
|
// 如果是当前组件,过滤掉当前属性
|
|
444
444
|
if (!isCurrent || currentAttriBute !== property.prop) {
|
|
@@ -454,7 +454,7 @@ function flatElements(elements: ViewElement[], componentList: CompletionProperty
|
|
|
454
454
|
})
|
|
455
455
|
})
|
|
456
456
|
|
|
457
|
-
completionProperty.name = `${key}(${property.
|
|
457
|
+
completionProperty.name = `${key}(${property.title})`;
|
|
458
458
|
completionProperty.icon = property.icon || 'attr'
|
|
459
459
|
stashItem.children.push(completionProperty)
|
|
460
460
|
}
|
|
@@ -511,21 +511,21 @@ function getCurrentElement(item: any): ViewElement | undefined {
|
|
|
511
511
|
if (!item?.parentNode) return undefined
|
|
512
512
|
if (item.parentNode?.concept === 'ViewElement') {
|
|
513
513
|
return item.parentNode
|
|
514
|
-
}
|
|
514
|
+
} if (item.parentNode?.concept === 'View') {
|
|
515
515
|
return undefined
|
|
516
|
-
} else {
|
|
517
|
-
return getCurrentElement(item.parentNode)
|
|
518
516
|
}
|
|
517
|
+
return getCurrentElement(item.parentNode)
|
|
518
|
+
|
|
519
519
|
}
|
|
520
520
|
|
|
521
521
|
function getCurrentAttriBute(item: any): BindAttribute | undefined {
|
|
522
522
|
if (item.concept === 'BindAttribute') {
|
|
523
523
|
return item
|
|
524
|
-
}
|
|
524
|
+
}
|
|
525
525
|
if (item?.parentNode && item.parentNode?.concept !== 'View') {
|
|
526
526
|
return getCurrentAttriBute(item.parentNode)
|
|
527
|
-
} else {
|
|
528
|
-
return undefined
|
|
529
527
|
}
|
|
530
|
-
|
|
528
|
+
return undefined
|
|
529
|
+
|
|
530
|
+
|
|
531
531
|
}
|
package/src/server/naslServer.ts
CHANGED
|
@@ -653,7 +653,7 @@ class NaslServer {
|
|
|
653
653
|
app.naslServer = this;
|
|
654
654
|
const self = this;
|
|
655
655
|
this.performance = performance;
|
|
656
|
-
const results = await utils.
|
|
656
|
+
const results = await utils.runGeneratorAsync(getAllTsFiles());
|
|
657
657
|
const files = results.map((result) => ({
|
|
658
658
|
file: result.filePath,
|
|
659
659
|
fileContent: result.code,
|
package/src/translator/types.ts
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
type Any = any;
|
|
2
|
-
type Long = number;
|
|
3
|
-
type Integer = number;
|
|
4
|
-
type Decimal = number;
|
|
5
|
-
// type Boolean = boolean;
|
|
6
|
-
// type String = string;
|
|
7
|
-
// type Date = globalThis.Date;
|
|
8
|
-
|
|
9
|
-
class Time {
|
|
10
|
-
accept: 'Time';
|
|
11
|
-
}
|
|
12
|
-
class DateTime {
|
|
13
|
-
accept: 'DateTime';
|
|
14
|
-
}
|
|
15
|
-
type List<T> = Array<T>;
|
|
16
|
-
|
|
17
|
-
interface Entity<T> {
|
|
18
|
-
get(id: Integer): T; // 只能获取一条 Entity 数据,返回一个 Entity 对象
|
|
19
|
-
create(entity: T): T;
|
|
20
|
-
update(entity: T): T;
|
|
21
|
-
delete(id: Integer): void;
|
|
22
|
-
createOrUpdate(body: T): T;
|
|
23
|
-
batchCreate(list: List<T>): List<T>;
|
|
24
|
-
batchUpdate(list: List<T>): List<T>;
|
|
25
|
-
batchDelete(list: List<Integer>): void;
|
|
26
|
-
}
|
|
27
|
-
declare function EntityRelation(property: any): any;
|
|
28
|
-
declare const createEntity: <T>() => Entity<T>;
|
|
29
|
-
|
|
30
|
-
declare function ForEach<T>(list: List<T>, start: Integer, end: Integer, fn: (item: T, index: Integer) => void): void;
|
|
31
|
-
|
|
32
|
-
declare function plus(left: Decimal, right: Decimal): Decimal;
|
|
33
|
-
declare function minus(left: Decimal, right: Decimal): Decimal;
|
|
34
|
-
declare function multiply(left: Decimal, right: Decimal): Decimal;
|
|
35
|
-
declare function divide(left: Decimal, right: Decimal): Decimal;
|
|
36
|
-
declare function remainder(left: Decimal, right: Decimal): Decimal;
|
|
37
|
-
|
|
38
|
-
declare namespace nasl.auth {
|
|
39
|
-
/* 检查当前用户是否有当前资源的权限 */
|
|
40
|
-
export function hasAuth(authPath: String): Boolean;
|
|
41
|
-
/* 退出当前登录状态 */
|
|
42
|
-
export function logout(): Promise<void>;
|
|
43
|
-
/* 对字符串 实现aes解密,返回解密后的字符串 */
|
|
44
|
-
export function encryptByAES(authPath: String): String;
|
|
45
|
-
/* 对字符串 实现aes加密,返回加密后的字符串 */
|
|
46
|
-
export function decryptByAES(authPath: String): String;
|
|
47
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
declare namespace nasl.oql {
|
|
2
|
-
/**
|
|
3
|
-
* 数据查询:当前为服务端逻辑时可使用此方法
|
|
4
|
-
* @param sql 数据查询需要的 SQL
|
|
5
|
-
* @returns 返回类型中的 T 为 sql 根据 SQL 中 select 的字段推导
|
|
6
|
-
*
|
|
7
|
-
* 所有变量格式为:${variable},不能用''包裹,不能用函数处理。
|
|
8
|
-
* 优先使用数据库的查询和数据操纵能力,例如 JOIN、SUM、GROUP_BY 等
|
|
9
|
-
* @example `SELECT * FROM Student WHERE id = ${id}`
|
|
10
|
-
* @example `SELECT OrderProduct.*, Product.price as price FROM OrderProduct JOIN Product WHERE orderId = ${id}`
|
|
11
|
-
* @example `SELECT SUM(OrderProduct.amount * Product.price) as total FROM OrderProduct JOIN Product WHERE orderId = ${orderId}`
|
|
12
|
-
*/
|
|
13
|
-
export function query<T>(sql: string): List<T>;
|
|
14
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
declare namespace nasl.ui {
|
|
2
|
-
export interface MouseEvent { }
|
|
3
|
-
|
|
4
|
-
export interface ValidateResult { valid: Boolean; }
|
|
5
|
-
|
|
6
|
-
export class Button {
|
|
7
|
-
constructor(options?: {
|
|
8
|
-
color?: 'default' | 'primary',
|
|
9
|
-
text?: String,
|
|
10
|
-
onClick?: () => any,
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class Form {
|
|
15
|
-
constructor(options?: {});
|
|
16
|
-
|
|
17
|
-
validate(): ValidateResult;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class Modal {
|
|
21
|
-
constructor(options?: {});
|
|
22
|
-
|
|
23
|
-
open(): void;
|
|
24
|
-
close(): void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class TableView {
|
|
28
|
-
constructor(options?: {});
|
|
29
|
-
|
|
30
|
-
reload(): void;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export class Select {
|
|
34
|
-
constructor(options?: {});
|
|
35
|
-
|
|
36
|
-
reload(): void;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class InfoList {
|
|
40
|
-
constructor(options?: {});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export class Collapse {
|
|
44
|
-
constructor(options?: {});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export class Input {
|
|
48
|
-
constructor(options?: {});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export class NumberInput {
|
|
52
|
-
constructor(options?: {});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function showMessage(text: Any): void;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 跳转到指定页面
|
|
59
|
-
* @example nasl.ui.destination('pageType.some_view.sub1_view', param1, param2);
|
|
60
|
-
* pageType 为 namespace,如 pc 或者 m,必填
|
|
61
|
-
*/
|
|
62
|
-
export function destination(path: String, ...args: Any[]): void;
|
|
63
|
-
}
|