@simitgroup/simpleapp-generator 1.6.6-n-alpha → 1.6.6-p-alpha
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/ReleaseNote.md +3 -0
- package/dist/buildinschemas/customfield.d.ts.map +1 -1
- package/dist/buildinschemas/customfield.js +13 -2
- package/dist/buildinschemas/customfield.js.map +1 -1
- package/dist/framework.d.ts +2 -0
- package/dist/framework.d.ts.map +1 -1
- package/dist/framework.js +94 -57
- package/dist/framework.js.map +1 -1
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +160 -34
- package/dist/generate.js.map +1 -1
- package/dist/index.js +30 -12
- package/dist/index.js.map +1 -1
- package/dist/type.d.ts +5 -0
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js.map +1 -1
- package/package.json +1 -1
- package/src/buildinschemas/customfield.ts +14 -3
- package/src/framework.ts +309 -251
- package/src/generate.ts +592 -434
- package/src/index.ts +136 -118
- package/src/type.ts +5 -0
- package/templates/basic/miniAppJsSdk/resource-bridge.service.ts.eta +117 -0
- package/templates/basic/miniAppStreamlitSdk/resource-bridge.service.ts.eta +213 -0
- package/templates/basic/nest/apischema.ts.eta +56 -27
- package/templates/basic/nest/controller.ts.eta +2 -1
- package/templates/basic/nest/type.ts.eta +28 -10
- package/templates/basic/nuxt/resource-bridge.service.ts.eta +162 -0
- package/templates/miniAppJsSdk/src/index.ts.eta +28 -0
- package/templates/miniAppJsSdk/src/services/bridge-resource-accessor.service.ts.eta +70 -0
- package/templates/miniAppJsSdk/src/services/bridge.service.ts.eta +91 -0
- package/templates/miniAppJsSdk/src/types/service.type.ts.eta +22 -0
- package/templates/miniAppStreamlitSdk/simtrain_eco_mini_app_streamlit_sdk/sdk.py.eta +73 -0
- package/templates/nest/src/simpleapp/apischemas/customfield.ts.eta +21 -0
- package/templates/nest/src/simpleapp/generate/jsonschemas/index.ts.eta +11 -0
- package/templates/nest/src/simpleapp/types/customfield.ts.eta +14 -0
- package/templates/nuxt/components/simpleApp/SimpleAppForm.vue.eta +2 -3
- package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +13 -12
- package/templates/nuxt/simpleapp/generate/clients/SimpleAppCustomFieldClient.ts.eta +122 -125
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/constants/common.constant.ts.eta +15 -0
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/constants/resource.constant.ts.eta +46 -0
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/services/bridge-resource-accessor.service.ts.eta +63 -0
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/services/bridge.service.ts.eta +110 -0
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/types/bridge.type.ts.eta +72 -0
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/types/resource-mapper.type.ts.eta +55 -0
- package/templates/nuxt/types/others.ts.eta +74 -65
- package/templates/nuxt/types/schema.ts.eta +225 -188
- package/templates/project/build.sh.eta +9 -0
package/src/index.ts
CHANGED
|
@@ -1,149 +1,167 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import { error } from
|
|
3
|
-
import * as fw from
|
|
4
|
-
import * as generate from './generate'
|
|
5
|
-
import { chmod } from
|
|
6
|
-
const program =
|
|
7
|
-
const Fieldtypes= require(
|
|
2
|
+
import { error } from 'console';
|
|
3
|
+
import * as fw from './framework';
|
|
4
|
+
import * as generate from './generate';
|
|
5
|
+
import { chmod } from 'fs';
|
|
6
|
+
const program = require('commander'); // add this line
|
|
7
|
+
const Fieldtypes = require('./type');
|
|
8
8
|
// const generate= require( './generate')
|
|
9
9
|
|
|
10
|
-
const fs = require(
|
|
10
|
+
const fs = require('fs');
|
|
11
11
|
// const createproject =require( './createproject')
|
|
12
|
-
const ps =
|
|
13
|
-
const capitalizeFirstLetter= require(
|
|
14
|
-
const {Logger, ILogObj} = require(
|
|
12
|
+
const ps = require('child_process');
|
|
13
|
+
const capitalizeFirstLetter = require('./libs');
|
|
14
|
+
const { Logger, ILogObj } = require('tslog');
|
|
15
15
|
|
|
16
|
-
const log
|
|
16
|
+
const log: typeof Logger = new Logger();
|
|
17
17
|
|
|
18
|
-
const figlet = require(
|
|
18
|
+
const figlet = require('figlet');
|
|
19
19
|
// const program = new Command();
|
|
20
|
-
const pj = require('../package.json')
|
|
20
|
+
const pj = require('../package.json');
|
|
21
21
|
|
|
22
|
-
let version=pj.version
|
|
22
|
+
let version = pj.version;
|
|
23
23
|
program
|
|
24
24
|
.version(version)
|
|
25
|
-
.description(
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
.description(
|
|
26
|
+
'An simpleapp CLI tool for generate frontend (vuejs) and backend(nestjs) codes'
|
|
27
|
+
)
|
|
28
|
+
.option('-c, --config-file <value>', 'configuration file')
|
|
29
|
+
.option(
|
|
30
|
+
'-g, --generate-type <value>',
|
|
31
|
+
'generate type init, backend, frontend'
|
|
32
|
+
)
|
|
28
33
|
.parse(process.argv);
|
|
29
34
|
|
|
30
|
-
let path=''
|
|
35
|
+
let path = '';
|
|
31
36
|
const options = program.opts();
|
|
32
37
|
console.log(figlet.textSync(`SimpleApp Generator`));
|
|
33
38
|
console.log(figlet.textSync(`${version}`));
|
|
34
|
-
let continueexecute = true
|
|
35
|
-
if(options.generateType && options.generateType=='init'){
|
|
36
|
-
continueexecute=false
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
let continueexecute = true;
|
|
40
|
+
if (options.generateType && options.generateType == 'init') {
|
|
41
|
+
continueexecute = false;
|
|
42
|
+
|
|
43
|
+
fw.prepareProject(() => {
|
|
44
|
+
chmod(process.cwd() + '/build.sh', 0o755, () => {
|
|
45
|
+
process.exit(1);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
} else if (!options.configFile) {
|
|
49
|
+
log.error(
|
|
50
|
+
'Config file parameter is required. Example: simpleapp-generator -c ./config.json'
|
|
51
|
+
);
|
|
52
|
+
throw 'Undefine configuration file';
|
|
53
|
+
} else if (options.configFile && options.configFile[0] == '/') {
|
|
54
|
+
path = options.configFile;
|
|
55
|
+
} else if (options.configFile) {
|
|
56
|
+
path = process.cwd() + '/' + options.configFile;
|
|
57
|
+
} else {
|
|
58
|
+
log.error(
|
|
59
|
+
'undefine configuration file, use command simpleapp-generator -c <configfilename.json>'
|
|
60
|
+
);
|
|
61
|
+
throw error;
|
|
45
62
|
}
|
|
46
|
-
else if(!options.configFile){
|
|
47
|
-
log.error("Config file parameter is required. Example: simpleapp-generator -c ./config.json")
|
|
48
|
-
throw "Undefine configuration file"
|
|
49
|
-
}
|
|
50
|
-
else if(options.configFile && options.configFile[0]=='/'){
|
|
51
|
-
path=options.configFile
|
|
52
|
-
}
|
|
53
|
-
else if(options.configFile){
|
|
54
|
-
path=process.cwd()+'/'+options.configFile
|
|
55
|
-
}else{
|
|
56
|
-
log.error("undefine configuration file, use command simpleapp-generator -c <configfilename.json>")
|
|
57
|
-
throw error
|
|
58
|
-
}
|
|
59
63
|
|
|
60
|
-
if(continueexecute){
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const frontendFolder = configs.frontendFolder
|
|
64
|
+
if (continueexecute) {
|
|
65
|
+
const configs = require(path);
|
|
66
|
+
// console.log("configurations: ",configs)
|
|
67
|
+
const jsonschemaFolder = configs.jsonschemaFolder;
|
|
68
|
+
const bpmnFolder = configs.bpmnFolder;
|
|
69
|
+
const backendFolder = configs.backendFolder;
|
|
70
|
+
const frontendFolder = configs.frontendFolder;
|
|
68
71
|
|
|
72
|
+
const run = async () => {
|
|
73
|
+
fw.setConfiguration(configs);
|
|
74
|
+
fw.runCreateNuxt(() => {
|
|
75
|
+
fw.runCreateNest(() => {
|
|
76
|
+
fw.prepareNest(() => {
|
|
77
|
+
fw.prepareNuxt(() => {
|
|
78
|
+
// generate.initialize(jsonschemaFolder,configs.groupFolder,bpmnFolder,backendFolder,frontendFolder,()=>{
|
|
79
|
+
generate.run(configs, ['nest', 'nuxt'], () => {
|
|
80
|
+
fw.prettyNuxt();
|
|
81
|
+
fw.prettyNest();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
69
88
|
|
|
89
|
+
const runUpdateMiniAppJsSdk = async () => {
|
|
90
|
+
fw.setConfiguration(configs);
|
|
91
|
+
generate.run(configs, ['miniAppJsSdk'], () => {
|
|
92
|
+
fw.prettyMiniAppJsSdk();
|
|
93
|
+
});
|
|
94
|
+
};
|
|
70
95
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// generate.initialize(jsonschemaFolder,configs.groupFolder,bpmnFolder,backendFolder,frontendFolder,()=>{
|
|
78
|
-
generate.run(configs,['nest','nuxt'],()=>{
|
|
79
|
-
fw.prettyNuxt()
|
|
80
|
-
fw.prettyNest()
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
const reGenFrontend = async()=>{
|
|
88
|
-
fw.setConfiguration(configs)
|
|
89
|
-
generate.run(configs,['nuxt'],()=>{
|
|
90
|
-
fw.prettyNuxt()
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
const reGenBackend = async()=>{
|
|
94
|
-
fw.setConfiguration(configs)
|
|
95
|
-
generate.run(configs,['nest'],()=>{
|
|
96
|
-
fw.prettyNest()
|
|
97
|
-
})
|
|
98
|
-
}
|
|
96
|
+
const runUpdateMiniAppStreamlitSdk = async () => {
|
|
97
|
+
fw.setConfiguration(configs);
|
|
98
|
+
generate.run(configs, ['miniAppStreamlitSdk'], () => {
|
|
99
|
+
fw.prettyMiniAppStreamlitSdk();
|
|
100
|
+
});
|
|
101
|
+
};
|
|
99
102
|
|
|
100
|
-
const
|
|
101
|
-
fw.setConfiguration(configs)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
103
|
+
const reGenFrontend = async () => {
|
|
104
|
+
fw.setConfiguration(configs);
|
|
105
|
+
generate.run(configs, ['nuxt'], () => {
|
|
106
|
+
fw.prettyNuxt();
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
const reGenBackend = async () => {
|
|
110
|
+
fw.setConfiguration(configs);
|
|
111
|
+
generate.run(configs, ['nest'], () => {
|
|
112
|
+
fw.prettyNest();
|
|
113
|
+
});
|
|
114
|
+
};
|
|
113
115
|
|
|
114
|
-
const
|
|
115
|
-
fw.setConfiguration(configs)
|
|
116
|
-
fw.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
|
|
116
|
+
const runbackend = async () => {
|
|
117
|
+
fw.setConfiguration(configs);
|
|
118
|
+
fw.setConfiguration(configs);
|
|
119
|
+
fw.runCreateNest(() => {
|
|
120
|
+
fw.prepareNest(() => {
|
|
121
|
+
// generate.run(jsonschemaFolder,configs.groupFolder,bpmnFolder,backendFolder,frontendFolder,()=>{
|
|
122
|
+
generate.run(configs, ['nest'], () => {
|
|
123
|
+
fw.prettyNest();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
};
|
|
125
128
|
|
|
129
|
+
const runfrontend = async () => {
|
|
130
|
+
fw.setConfiguration(configs);
|
|
131
|
+
fw.runCreateNuxt(() => {
|
|
132
|
+
fw.prepareNuxt(() => {
|
|
133
|
+
// generate.initialize(jsonschemaFolder,configs.groupFolder,bpmnFolder,backendFolder,frontendFolder,()=>{
|
|
134
|
+
generate.run(configs, ['nuxt'], () => {
|
|
135
|
+
fw.prettyNuxt();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
};
|
|
126
140
|
|
|
127
|
-
switch(options.generateType){
|
|
141
|
+
switch (options.generateType) {
|
|
128
142
|
case 'updatefrontend':
|
|
129
|
-
reGenFrontend()
|
|
130
|
-
|
|
143
|
+
reGenFrontend();
|
|
144
|
+
break;
|
|
131
145
|
case 'updatebackend':
|
|
132
|
-
reGenBackend()
|
|
133
|
-
|
|
146
|
+
reGenBackend();
|
|
147
|
+
break;
|
|
134
148
|
case 'frontend':
|
|
135
|
-
runfrontend()
|
|
136
|
-
|
|
149
|
+
runfrontend();
|
|
150
|
+
break;
|
|
137
151
|
case 'backend':
|
|
138
|
-
runbackend()
|
|
139
|
-
|
|
152
|
+
runbackend();
|
|
153
|
+
break;
|
|
154
|
+
case 'updateMiniAppJsSdk':
|
|
155
|
+
runUpdateMiniAppJsSdk();
|
|
156
|
+
break;
|
|
157
|
+
case 'updateMiniAppStreamlitSdk':
|
|
158
|
+
runUpdateMiniAppStreamlitSdk();
|
|
159
|
+
break;
|
|
140
160
|
case 'all':
|
|
141
|
-
run()
|
|
142
|
-
|
|
161
|
+
run();
|
|
162
|
+
break;
|
|
143
163
|
default:
|
|
144
|
-
log.error(
|
|
145
|
-
|
|
146
|
-
|
|
164
|
+
log.error('unknown generate type');
|
|
165
|
+
break;
|
|
147
166
|
}
|
|
148
|
-
|
|
149
|
-
}
|
|
167
|
+
}
|
package/src/type.ts
CHANGED
|
@@ -69,6 +69,11 @@ export type ModuleObject = {
|
|
|
69
69
|
schema:SimpleAppJSONSchema7
|
|
70
70
|
}
|
|
71
71
|
export type TypeGenerateDocumentVariable ={
|
|
72
|
+
/**
|
|
73
|
+
* Resource Name should be a readable name with camelCase.
|
|
74
|
+
* Ex: studentSummary
|
|
75
|
+
*/
|
|
76
|
+
resourceName: string;
|
|
72
77
|
name: string
|
|
73
78
|
doctype: string
|
|
74
79
|
models: ChildModels
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2025-06-18
|
|
5
|
+
* Author: --
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
<%
|
|
9
|
+
const upperFirstCase = (value) => {
|
|
10
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const pascalName = upperFirstCase(it.resourceName);
|
|
14
|
+
const apiName = it.typename.toUpperCase() + 'Api';
|
|
15
|
+
const typeActionName = pascalName + 'Actions';
|
|
16
|
+
|
|
17
|
+
const miniAppWhitelistApis = it.jsonschema['x-simpleapp-config']?.miniApp?.whitelist || [];
|
|
18
|
+
const hasMiniAppWhitelistedApi = miniAppWhitelistApis.length > 0;
|
|
19
|
+
%>
|
|
20
|
+
|
|
21
|
+
import { MiniAppBridgeService } from "../bridge.service";
|
|
22
|
+
|
|
23
|
+
export class MiniApp<%= pascalName %>BridgeService {
|
|
24
|
+
private bridge: MiniAppBridgeService;
|
|
25
|
+
|
|
26
|
+
private resourceName = "<%= it.resourceName %>";
|
|
27
|
+
|
|
28
|
+
constructor(bridge: MiniAppBridgeService) {
|
|
29
|
+
this.bridge = bridge;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
<% for (let i = 0; i < miniAppWhitelistApis.length; i++) { %>
|
|
33
|
+
<%
|
|
34
|
+
const action = miniAppWhitelistApis[i];
|
|
35
|
+
%>
|
|
36
|
+
|
|
37
|
+
<% if(action === 'list') { %>
|
|
38
|
+
async list() {
|
|
39
|
+
return this.bridge.callApi(this.resourceName, "list");
|
|
40
|
+
}
|
|
41
|
+
<% } else if(action === 'detail') { %>
|
|
42
|
+
async detail(id: string) {
|
|
43
|
+
return this.bridge.callApi(this.resourceName, "detail", { id });
|
|
44
|
+
}
|
|
45
|
+
<% } else if(action === 'create') { %>
|
|
46
|
+
async create(data: any) {
|
|
47
|
+
return this.bridge.callApi(this.resourceName, "create", { body: data });
|
|
48
|
+
}
|
|
49
|
+
<% } else if(action === 'update') { %>
|
|
50
|
+
async update(id: string, data: any) {
|
|
51
|
+
return this.bridge.callApi(this.resourceName, "update", { id, body: data });
|
|
52
|
+
}
|
|
53
|
+
<% } else if(action === 'patch') { %>
|
|
54
|
+
async patch(id: string, data: any) {
|
|
55
|
+
return this.bridge.callApi(this.resourceName, "patch", { id, body: data });
|
|
56
|
+
}
|
|
57
|
+
<% } else if(action === 'delete') { %>
|
|
58
|
+
async delete(id: string) {
|
|
59
|
+
return this.bridge.callApi(this.resourceName, "delete", { id });
|
|
60
|
+
}
|
|
61
|
+
<% } else if(action === 'autoComplete') { %>
|
|
62
|
+
async autoComplete(query: string, data: any) {
|
|
63
|
+
return this.bridge.callApi(this.resourceName, "autoComplete", {
|
|
64
|
+
query,
|
|
65
|
+
body: data,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
<% } else { %>
|
|
69
|
+
<% const apiSetting = it.apiSettings.find(item => item.action === action); %>
|
|
70
|
+
<% if (apiSetting) { %>
|
|
71
|
+
<% const hasBody = ['post', 'put', 'patch'].includes(apiSetting.method); %>
|
|
72
|
+
|
|
73
|
+
<%
|
|
74
|
+
const paramMatches = apiSetting.entryPoint.match(/:([\w]+)/g) || [];
|
|
75
|
+
const paramNames = paramMatches.map(p => p.replace(':', ''));
|
|
76
|
+
|
|
77
|
+
const args = paramNames.map(name => {
|
|
78
|
+
return `${name}: string`;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const output = [];
|
|
82
|
+
const queryParams = [];
|
|
83
|
+
|
|
84
|
+
for (let i = 0; i < paramNames.length; i++) {
|
|
85
|
+
const name = paramNames[i];
|
|
86
|
+
if (name === 'id') {
|
|
87
|
+
output.push(`id: ${name}`);
|
|
88
|
+
} else {
|
|
89
|
+
queryParams.push(`${name}: ${name}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (queryParams.length > 0) {
|
|
94
|
+
output.push(`queryParams: {\n ${queryParams.join(',\n ')}\n}`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (hasBody) {
|
|
98
|
+
args.push('data: any');
|
|
99
|
+
output.push('body: data');
|
|
100
|
+
}
|
|
101
|
+
%>
|
|
102
|
+
|
|
103
|
+
async <%= action %>(<%= args.join(', ') %>) {
|
|
104
|
+
return this.bridge.callApi(this.resourceName, "<%= action %>", {
|
|
105
|
+
<%= output.join(',\n ') %>
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
<% } %>
|
|
109
|
+
<% } %>
|
|
110
|
+
<% } %>
|
|
111
|
+
|
|
112
|
+
openOnScreenForm(id?: string) {
|
|
113
|
+
this.bridge.openOnScreenResourceForm(this.resourceName, {
|
|
114
|
+
id,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const upperFirstCase = (value) => {
|
|
3
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const pascalName = upperFirstCase(it.resourceName);
|
|
7
|
+
const apiName = it.typename.toUpperCase() + 'Api';
|
|
8
|
+
const typeActionName = pascalName + 'Actions';
|
|
9
|
+
|
|
10
|
+
const miniAppWhitelistApis = it.jsonschema['x-simpleapp-config']?.miniApp?.whitelist || [];
|
|
11
|
+
const hasMiniAppWhitelistedApi = miniAppWhitelistApis.length > 0;
|
|
12
|
+
%>
|
|
13
|
+
|
|
14
|
+
from streamlit_javascript import st_javascript
|
|
15
|
+
from ..helper import Helper
|
|
16
|
+
from typing import Optional
|
|
17
|
+
from ..api_option import ApiOption
|
|
18
|
+
from streamlit.components.v1 import html
|
|
19
|
+
import json
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class <%= pascalName %>:
|
|
23
|
+
_resource_name = "<%= it.resourceName %>"
|
|
24
|
+
|
|
25
|
+
<% for (let i = 0; i < miniAppWhitelistApis.length; i++) { %>
|
|
26
|
+
<%
|
|
27
|
+
const action = miniAppWhitelistApis[i];
|
|
28
|
+
%>
|
|
29
|
+
|
|
30
|
+
<% if(action === 'list') { %>
|
|
31
|
+
|
|
32
|
+
def <%= action %>(self, options: Optional[ApiOption] = {}):
|
|
33
|
+
action = "<%= action %>"
|
|
34
|
+
request_key = Helper.get_api_key(
|
|
35
|
+
"request", resource=self._resource_name, action=action, options=options
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
st_javascript(
|
|
39
|
+
f"window.parent.callApi('{self._resource_name}', '{action}')",
|
|
40
|
+
key=request_key,
|
|
41
|
+
on_change=lambda: Helper.set_api_response(
|
|
42
|
+
resource=self._resource_name, action=action, options=options
|
|
43
|
+
),
|
|
44
|
+
)
|
|
45
|
+
<% } else if(action === 'detail') { %>
|
|
46
|
+
|
|
47
|
+
def <%= action %>(self, id: str, options: Optional[ApiOption] = {}):
|
|
48
|
+
action = "<%= action %>"
|
|
49
|
+
request_key = Helper.get_api_key(
|
|
50
|
+
"request", resource=self._resource_name, action=action, options=options
|
|
51
|
+
)
|
|
52
|
+
payload = json.dumps({"id": id})
|
|
53
|
+
|
|
54
|
+
st_javascript(
|
|
55
|
+
f"window.parent.callApi('{self._resource_name}', '{action}', {payload})",
|
|
56
|
+
key=request_key,
|
|
57
|
+
on_change=lambda: Helper.set_api_response(
|
|
58
|
+
resource=self._resource_name, action=action, options=options
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
<% } else if(action === 'create') { %>
|
|
62
|
+
|
|
63
|
+
def <%= action %>(self, data = {}, options: Optional[ApiOption] = {}):
|
|
64
|
+
action = "<%= action %>"
|
|
65
|
+
request_key = Helper.get_api_key(
|
|
66
|
+
"request", resource=self._resource_name, action=action, options=options
|
|
67
|
+
)
|
|
68
|
+
payload = json.dumps({"body": data})
|
|
69
|
+
|
|
70
|
+
st_javascript(
|
|
71
|
+
f"window.parent.callApi('{self._resource_name}', '{action}', {payload})",
|
|
72
|
+
key=request_key,
|
|
73
|
+
on_change=lambda: Helper.set_api_response(
|
|
74
|
+
resource=self._resource_name, action=action, options=options
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
<% } else if(action === 'update') { %>
|
|
78
|
+
|
|
79
|
+
def <%= action %>(self, id: str, data = {}, options: Optional[ApiOption] = {}):
|
|
80
|
+
action = "<%= action %>"
|
|
81
|
+
request_key = Helper.get_api_key(
|
|
82
|
+
"request", resource=self._resource_name, action=action, options=options
|
|
83
|
+
)
|
|
84
|
+
payload = json.dumps({"id": id, "body": data})
|
|
85
|
+
|
|
86
|
+
st_javascript(
|
|
87
|
+
f"window.parent.callApi('{self._resource_name}', '{action}', {payload})",
|
|
88
|
+
key=request_key,
|
|
89
|
+
on_change=lambda: Helper.set_api_response(
|
|
90
|
+
resource=self._resource_name, action=action, options=options
|
|
91
|
+
),
|
|
92
|
+
)
|
|
93
|
+
<% } else if(action === 'patch') { %>
|
|
94
|
+
|
|
95
|
+
def <%= action %>(self, id: str, data = {}, options: Optional[ApiOption] = {}):
|
|
96
|
+
action = "<%= action %>"
|
|
97
|
+
request_key = Helper.get_api_key(
|
|
98
|
+
"request", resource=self._resource_name, action=action, options=options
|
|
99
|
+
)
|
|
100
|
+
payload = json.dumps({"id": id, "body": data})
|
|
101
|
+
|
|
102
|
+
st_javascript(
|
|
103
|
+
f"window.parent.callApi('{self._resource_name}', '{action}', {payload})",
|
|
104
|
+
key=request_key,
|
|
105
|
+
on_change=lambda: Helper.set_api_response(
|
|
106
|
+
resource=self._resource_name, action=action, options=options
|
|
107
|
+
),
|
|
108
|
+
)
|
|
109
|
+
<% } else if(action === 'delete') { %>
|
|
110
|
+
|
|
111
|
+
def <%= action %>(self, id: str, options: Optional[ApiOption] = {}):
|
|
112
|
+
action = "<%= action %>"
|
|
113
|
+
request_key = Helper.get_api_key(
|
|
114
|
+
"request", resource=self._resource_name, action=action, options=options
|
|
115
|
+
)
|
|
116
|
+
payload = json.dumps({"id": id})
|
|
117
|
+
st_javascript(
|
|
118
|
+
f"window.parent.callApi('{self._resource_name}', '{action}', {payload})",
|
|
119
|
+
key=request_key,
|
|
120
|
+
on_change=lambda: Helper.set_api_response(
|
|
121
|
+
resource=self._resource_name, action=action, options=options
|
|
122
|
+
),
|
|
123
|
+
)
|
|
124
|
+
<% } else if(action === 'autoComplete') { %>
|
|
125
|
+
|
|
126
|
+
def <%= action %>(self, query: str, data = {}, options: Optional[ApiOption] = {}):
|
|
127
|
+
action = "<%= action %>"
|
|
128
|
+
request_key = Helper.get_api_key(
|
|
129
|
+
"request", resource=self._resource_name, action=action, options=options
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
payload = json.dumps({"query": query, "body": data})
|
|
133
|
+
st_javascript(
|
|
134
|
+
f"window.parent.callApi('{self._resource_name}', '{action}', {payload})",
|
|
135
|
+
key=request_key,
|
|
136
|
+
on_change=lambda: Helper.set_api_response(
|
|
137
|
+
resource=self._resource_name, action=action, options=options
|
|
138
|
+
),
|
|
139
|
+
)
|
|
140
|
+
<% } else { %>
|
|
141
|
+
<% const apiSetting = it.apiSettings.find(item => item.action === action); %>
|
|
142
|
+
<% if (apiSetting) { %>
|
|
143
|
+
<% const hasBody = ['post', 'put', 'patch'].includes(apiSetting.method); %>
|
|
144
|
+
|
|
145
|
+
<%
|
|
146
|
+
const paramMatches = apiSetting.entryPoint.match(/:([\w]+)/g) || [];
|
|
147
|
+
const paramNames = paramMatches.map(p => p.replace(':', ''));
|
|
148
|
+
|
|
149
|
+
const args = paramNames.map(name => {
|
|
150
|
+
return `${name}: str`;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
const output = [];
|
|
155
|
+
const queryParams = [];
|
|
156
|
+
|
|
157
|
+
for (let i = 0; i < paramNames.length; i++) {
|
|
158
|
+
const name = paramNames[i];
|
|
159
|
+
if (name === 'id') {
|
|
160
|
+
output.push(`'id': ${name}`)
|
|
161
|
+
} else {
|
|
162
|
+
queryParams.push(`'${name}': ${name}`)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (queryParams.length > 0) {
|
|
167
|
+
output.push(`'queryParams': { ${queryParams.join(', ')} }`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (hasBody) {
|
|
171
|
+
args.push('data = {}');
|
|
172
|
+
output.push("'body': data");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
args.push('options: Optional[ApiOption] = {}')
|
|
176
|
+
%>
|
|
177
|
+
|
|
178
|
+
def <%= action %>(self, <%= args.join(', ') %>):
|
|
179
|
+
action = "<%= action %>"
|
|
180
|
+
request_key = Helper.get_api_key(
|
|
181
|
+
"request", resource=self._resource_name, action=action, options=options
|
|
182
|
+
)
|
|
183
|
+
payload = json.dumps({ <%~ output.join(', ') %> })
|
|
184
|
+
|
|
185
|
+
st_javascript(
|
|
186
|
+
f"window.parent.callApi('{self._resource_name}', '{action}', {payload})",
|
|
187
|
+
key=request_key,
|
|
188
|
+
on_change=lambda: Helper.set_api_response(
|
|
189
|
+
resource=self._resource_name, action=action, options=options
|
|
190
|
+
),
|
|
191
|
+
)
|
|
192
|
+
<% } %>
|
|
193
|
+
<% } %>
|
|
194
|
+
<% } %>
|
|
195
|
+
|
|
196
|
+
def response(self, action: str, options: Optional[ApiOption] = {}):
|
|
197
|
+
return Helper.get_api_response(
|
|
198
|
+
resource=self._resource_name, action=action, options=options
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
def openOnScreenForm(self, id: Optional[str] = None):
|
|
202
|
+
id_js = f"'{id}'" if id else "undefined"
|
|
203
|
+
|
|
204
|
+
html(
|
|
205
|
+
f"""
|
|
206
|
+
<script>
|
|
207
|
+
window.parent.openOnScreenResourceForm('{self._resource_name}', {{
|
|
208
|
+
id: {id_js}
|
|
209
|
+
}});
|
|
210
|
+
</script>
|
|
211
|
+
""",
|
|
212
|
+
height=0,
|
|
213
|
+
)
|