@simitgroup/simpleapp-generator 1.6.7-e-alpha → 1.6.7-g-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 +8 -0
- package/dist/buildinschemas/message.d.ts +3 -0
- package/dist/buildinschemas/message.d.ts.map +1 -0
- package/dist/buildinschemas/message.js +34 -0
- package/dist/buildinschemas/message.js.map +1 -0
- package/dist/buildinschemas/webhookhistory.d.ts +3 -0
- package/dist/buildinschemas/webhookhistory.d.ts.map +1 -0
- package/dist/buildinschemas/webhookhistory.js +44 -0
- package/dist/buildinschemas/webhookhistory.js.map +1 -0
- package/dist/createproject.js +138 -0
- package/dist/createproject.js.map +1 -0
- package/dist/framework.d.ts +1 -0
- package/dist/framework.d.ts.map +1 -1
- package/dist/framework.js +7 -1
- package/dist/framework.js.map +1 -1
- package/dist/generate-allow-changebackend.js +305 -0
- package/dist/generate-allow-changebackend.js.map +1 -0
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +85 -9
- package/dist/generate.js.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/index2.js +118 -0
- package/dist/index2.js.map +1 -0
- package/dist/installdependency.js +20 -0
- package/dist/installdependency.js.map +1 -0
- package/dist/installnest.js +2 -0
- package/dist/installnest.js.map +1 -0
- package/dist/installnuxt.js +2 -0
- package/dist/installnuxt.js.map +1 -0
- package/dist/processors/groupsbuilder.js +2 -0
- package/dist/processors/groupsbuilder.js.map +1 -0
- package/dist/schematype/baseschema.js +25 -0
- package/dist/schematype/baseschema.js.map +1 -0
- package/dist/schematype/default.js +2 -0
- package/dist/schematype/default.js.map +1 -0
- package/dist/schematype/index.js +12 -0
- package/dist/schematype/index.js.map +1 -0
- package/dist/schematype/primarymasterdata.js +38 -0
- package/dist/schematype/primarymasterdata.js.map +1 -0
- package/dist/schematype/simple.js +24 -0
- package/dist/schematype/simple.js.map +1 -0
- package/dist/schematype/simplemasterdata.js +31 -0
- package/dist/schematype/simplemasterdata.js.map +1 -0
- package/dist/schematype/transaction.js +74 -0
- package/dist/schematype/transaction.js.map +1 -0
- package/dist/type.d.ts +6 -0
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js.map +1 -1
- package/package.json +1 -1
- package/reset-install.sh +2 -2
- package/src/framework.ts +7 -0
- package/src/generate.ts +118 -2
- package/src/index.ts +10 -0
- package/src/type.ts +6 -0
- package/templates/basic/miniApi/resource.controller.ts.eta +139 -0
- package/templates/basic/miniApi/resource.module.ts.eta +16 -0
- package/templates/basic/miniApi/resource.service.ts.eta +109 -0
- package/templates/basic/miniAppJsSdk/resource-bridge.service.ts.eta +3 -6
- package/templates/basic/miniAppStreamlitSdk/resource-bridge.service.ts.eta +0 -4
- package/templates/basic/nest/type.ts.eta +2 -2
- package/templates/basic/nuxt/resource-bridge.editable.service.ts.eta +0 -8
- package/templates/basic/nuxt/resource-bridge.service.ts.eta +5 -5
- package/templates/miniApi/src/constants/api-scopes.ts.eta +76 -0
- package/templates/miniApi/src/modules/resource/resource.module.ts.eta +46 -0
- package/templates/miniAppJsSdk/src/services/bridge-resource-accessor.service.ts.eta +1 -9
- package/templates/miniAppStreamlitSdk/simtrain_eco_mini_app_streamlit_sdk/sdk.py.eta +0 -8
- package/templates/nest/src/app.module.ts._eta +2 -1
- package/templates/nest/src/simpleapp/generate/commons/runwebhook.service.ts.eta +1 -0
- package/templates/nest/src/simpleapp/generate/commons/user.context.ts.eta +1 -1
- package/templates/nest/src/simpleapp/generate/workflow/workflow.apischema.ts.eta +2 -2
- package/templates/nest/src/simpleapp/profile/{profile.apischema.ts.eta → profile.apischema.ts._eta} +7 -7
- package/templates/nuxt/simpleapp/generate/features/miniApp/bridge/constants/resource.constant.ts.eta +0 -8
- package/templates/nuxt/simpleapp/generate/features/miniApp/bridge/services/bridge-resource-accessor.service.ts.eta +0 -8
- package/templates/nuxt/simpleapp/generate/features/miniApp/bridge/types/bridge.type.ts.eta +20 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/bridge/types/resource-mapper.type.ts.eta +0 -8
package/src/generate.ts
CHANGED
|
@@ -45,6 +45,7 @@ const docs = [];
|
|
|
45
45
|
let frontendFolder = '';
|
|
46
46
|
let backendFolder = '';
|
|
47
47
|
let miniAppSdkFolder = {};
|
|
48
|
+
let miniApiFolder = '';
|
|
48
49
|
let frontendpagefolder = '';
|
|
49
50
|
const allroles: any = {};
|
|
50
51
|
let langdata: any = {};
|
|
@@ -61,6 +62,7 @@ export const run = async (
|
|
|
61
62
|
frontendFolder = configs.frontendFolder;
|
|
62
63
|
backendFolder = configs.backendFolder;
|
|
63
64
|
miniAppSdkFolder = configs.miniAppSdkFolder;
|
|
65
|
+
miniApiFolder = configs.miniApiFolder;
|
|
64
66
|
|
|
65
67
|
const printformats: SchemaPrintFormat[] = [];
|
|
66
68
|
const groupFolder = configs.groupFolder;
|
|
@@ -78,6 +80,9 @@ export const run = async (
|
|
|
78
80
|
if (genFor.includes('miniAppStreamlitSdk')) {
|
|
79
81
|
generateTypes['miniAppStreamlitSdk'] = miniAppSdkFolder['streamlit'];
|
|
80
82
|
}
|
|
83
|
+
if (genFor.includes('miniApi')) {
|
|
84
|
+
generateTypes['miniApi'] = miniApiFolder;
|
|
85
|
+
}
|
|
81
86
|
// console.log("genForgenForgenForgenFor",genFor,generateTypes)
|
|
82
87
|
//
|
|
83
88
|
frontendpagefolder = `${frontendFolder}/pages/[xorg]`;
|
|
@@ -207,6 +212,9 @@ const generateSchema = (
|
|
|
207
212
|
jsonschemas[docname]?.['x-simpleapp-config']?.resourceName ?? docname;
|
|
208
213
|
|
|
209
214
|
//console.log("---^^^^^------",modelname,docname, doctype, rendertype,currentmodel,allmodels)
|
|
215
|
+
|
|
216
|
+
const miniAppWhitelistApis =
|
|
217
|
+
jsonschemas[docname][X_SIMPLEAPP_CONFIG]?.miniApp?.whitelist || {};
|
|
210
218
|
const variables: TypeGenerateDocumentVariable = {
|
|
211
219
|
resourceName: resourceName,
|
|
212
220
|
name: docname,
|
|
@@ -234,6 +242,10 @@ const generateSchema = (
|
|
|
234
242
|
customField: {
|
|
235
243
|
isEnable:
|
|
236
244
|
jsonschemas[docname][X_SIMPLEAPP_CONFIG]?.customField?.isEnable ?? false
|
|
245
|
+
},
|
|
246
|
+
miniApp: {
|
|
247
|
+
whitelistApis: miniAppWhitelistApis,
|
|
248
|
+
hasMiniAppWhitelistedApi: Object.keys(miniAppWhitelistApis).length > 0
|
|
237
249
|
}
|
|
238
250
|
};
|
|
239
251
|
|
|
@@ -251,7 +263,6 @@ const generateSchema = (
|
|
|
251
263
|
const backendTargetFolder = `${backendFolder}/src/simpleapp/generate`;
|
|
252
264
|
const simpleappTargetFolder = `${backendFolder}/src/simpleapp`;
|
|
253
265
|
const backendServiceFolder = `${backendFolder}/src/simpleapp/services`;
|
|
254
|
-
|
|
255
266
|
Object.keys(generateTypes).forEach((foldertype) => {
|
|
256
267
|
//generate code for every schema
|
|
257
268
|
const generateTemplatefolder = `${constants.templatedir}/basic/${foldertype}`;
|
|
@@ -590,9 +601,111 @@ const generateSchema = (
|
|
|
590
601
|
mkdirSync(path.dirname(targetfile), { recursive: true });
|
|
591
602
|
writeFileSync(targetfile, filecontent);
|
|
592
603
|
}
|
|
604
|
+
} else if (foldertype === 'miniApi') {
|
|
605
|
+
processPlatformFileMiniApi(
|
|
606
|
+
resourceName,
|
|
607
|
+
docname,
|
|
608
|
+
{
|
|
609
|
+
name: filename,
|
|
610
|
+
platform: foldertype,
|
|
611
|
+
templatePath: templatepath
|
|
612
|
+
},
|
|
613
|
+
variables
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
type FileInfo = {
|
|
621
|
+
name: string;
|
|
622
|
+
platform: string;
|
|
623
|
+
templatePath: string;
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
const processPlatformFileMiniApi = (
|
|
627
|
+
resourceName: string,
|
|
628
|
+
docname: string,
|
|
629
|
+
file: FileInfo,
|
|
630
|
+
variables: any
|
|
631
|
+
) => {
|
|
632
|
+
const mapfiles = {
|
|
633
|
+
'resource.service.ts.eta': {
|
|
634
|
+
to: `src/modules/resource/resources/${_.kebabCase(resourceName)}`,
|
|
635
|
+
as: `${_.kebabCase(resourceName)}.service.ts`,
|
|
636
|
+
validate: (targetfile: string, isexists: boolean) => {
|
|
637
|
+
const {
|
|
638
|
+
miniApp: { hasMiniAppWhitelistedApi }
|
|
639
|
+
} = variables;
|
|
640
|
+
|
|
641
|
+
if (!hasMiniAppWhitelistedApi) {
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
},
|
|
648
|
+
'resource.controller.ts.eta': {
|
|
649
|
+
to: `src/modules/resource/resources/${_.kebabCase(resourceName)}`,
|
|
650
|
+
as: `${_.kebabCase(resourceName)}.controller.ts`,
|
|
651
|
+
validate: (targetfile: string, isexists: boolean) => {
|
|
652
|
+
const {
|
|
653
|
+
miniApp: { hasMiniAppWhitelistedApi }
|
|
654
|
+
} = variables;
|
|
655
|
+
|
|
656
|
+
if (!hasMiniAppWhitelistedApi) {
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
'resource.module.ts.eta': {
|
|
664
|
+
to: `src/modules/resource/resources/${_.kebabCase(resourceName)}`,
|
|
665
|
+
as: `${_.kebabCase(resourceName)}.module.ts`,
|
|
666
|
+
validate: (targetfile: string, isexists: boolean) => {
|
|
667
|
+
const {
|
|
668
|
+
miniApp: { hasMiniAppWhitelistedApi }
|
|
669
|
+
} = variables;
|
|
670
|
+
|
|
671
|
+
if (!hasMiniAppWhitelistedApi) {
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
return true;
|
|
593
676
|
}
|
|
594
677
|
}
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
processPlatformFile(docname, mapfiles, file, variables);
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
const processPlatformFile = (
|
|
684
|
+
docname: string,
|
|
685
|
+
mapfiles: any,
|
|
686
|
+
file: FileInfo,
|
|
687
|
+
variables: any
|
|
688
|
+
) => {
|
|
689
|
+
const eta = new Eta({
|
|
690
|
+
views: '/',
|
|
691
|
+
functionHeader: getCodeGenHelper()
|
|
595
692
|
});
|
|
693
|
+
|
|
694
|
+
const target = mapfiles[file.name];
|
|
695
|
+
const targetfolder = `${generateTypes[file.platform]}/${target.to}`;
|
|
696
|
+
const targetfile = `${targetfolder}/${target.as}`;
|
|
697
|
+
|
|
698
|
+
const isexists = existsSync(targetfile);
|
|
699
|
+
const iswrite: boolean = target.validate(targetfile, isexists);
|
|
700
|
+
|
|
701
|
+
if (iswrite) {
|
|
702
|
+
if (!existsSync(targetfolder)) {
|
|
703
|
+
mkdirSync(targetfolder, { recursive: true });
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
const filecontent = eta.render(file.templatePath, variables);
|
|
707
|
+
writeFileSync(targetfile, filecontent);
|
|
708
|
+
}
|
|
596
709
|
};
|
|
597
710
|
|
|
598
711
|
const generateSystemFiles = (modules: ModuleObject[], allbpmn) => {
|
|
@@ -682,4 +795,7 @@ const prepareRoles = (groupsettings) => {
|
|
|
682
795
|
const getCodeGenHelper = () =>
|
|
683
796
|
'const capitalizeFirstLetter = (str) => !str ? `Object` : str.slice(0, 1).toUpperCase() + str.slice(1);' +
|
|
684
797
|
'const initType=(str)=>{return ["string","number","boolean","array","object"].includes(str) ? capitalizeFirstLetter(str) : str;};' +
|
|
685
|
-
"const camelCaseToWords = (s) => {const result = s.replace(/([A-Z])/g, ' $1');return result.charAt(0).toUpperCase() + result.slice(1);}"
|
|
798
|
+
"const camelCaseToWords = (s) => {const result = s.replace(/([A-Z])/g, ' $1');return result.charAt(0).toUpperCase() + result.slice(1);};" +
|
|
799
|
+
'const upperFirstCase = (value) => { return value.charAt(0).toUpperCase() + value.slice(1); };' +
|
|
800
|
+
'const camelToKebab = (value) => { return value.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); };' +
|
|
801
|
+
'const titleCase = (value) => { return value.replace(/([a-z])([A-Z])/g, "$1 $2"); }; ';
|
package/src/index.ts
CHANGED
|
@@ -100,6 +100,13 @@ if (continueexecute) {
|
|
|
100
100
|
});
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
+
const runUpdateMiniApi = async () => {
|
|
104
|
+
fw.setConfiguration(configs);
|
|
105
|
+
generate.run(configs, ['miniApi'], () => {
|
|
106
|
+
fw.prettyMiniApi();
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
103
110
|
const reGenFrontend = async () => {
|
|
104
111
|
fw.setConfiguration(configs);
|
|
105
112
|
generate.run(configs, ['nuxt'], () => {
|
|
@@ -157,6 +164,9 @@ if (continueexecute) {
|
|
|
157
164
|
case 'updateMiniAppStreamlitSdk':
|
|
158
165
|
runUpdateMiniAppStreamlitSdk();
|
|
159
166
|
break;
|
|
167
|
+
case 'updateMiniApi':
|
|
168
|
+
runUpdateMiniApi();
|
|
169
|
+
break;
|
|
160
170
|
case 'all':
|
|
161
171
|
run();
|
|
162
172
|
break;
|
package/src/type.ts
CHANGED
|
@@ -104,6 +104,12 @@ export type TypeGenerateDocumentVariable = {
|
|
|
104
104
|
customField: {
|
|
105
105
|
isEnable: boolean;
|
|
106
106
|
};
|
|
107
|
+
miniApp: {
|
|
108
|
+
whitelistApis: {
|
|
109
|
+
[key: string]: any;
|
|
110
|
+
};
|
|
111
|
+
hasMiniAppWhitelistedApi: boolean;
|
|
112
|
+
};
|
|
107
113
|
};
|
|
108
114
|
|
|
109
115
|
// export type DocSetting = {
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const pascalName = upperFirstCase(it.resourceName);
|
|
3
|
+
const kebabName = camelToKebab(it.resourceName);
|
|
4
|
+
const apiName = it.typename.toUpperCase() + 'Api';
|
|
5
|
+
const titleName = titleCase(pascalName);
|
|
6
|
+
|
|
7
|
+
const serviceVariable = it.resourceName + 'Service';
|
|
8
|
+
%>
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
Controller,
|
|
12
|
+
Get,
|
|
13
|
+
Post,
|
|
14
|
+
Body,
|
|
15
|
+
Put,
|
|
16
|
+
Patch,
|
|
17
|
+
Param,
|
|
18
|
+
Delete,
|
|
19
|
+
Headers,
|
|
20
|
+
Query,
|
|
21
|
+
} from '@nestjs/common';
|
|
22
|
+
import { ApiTags, ApiBody, ApiResponse, ApiOperation, ApiQuery } from '@nestjs/swagger';
|
|
23
|
+
import { ApiHeader } from 'src/types/api';
|
|
24
|
+
import { <%= pascalName %>Service } from './<%= kebabName %>.service';
|
|
25
|
+
|
|
26
|
+
@ApiTags('<%= titleName %>')
|
|
27
|
+
@Controller('resources/<%= kebabName %>')
|
|
28
|
+
export class <%= pascalName %>Controller {
|
|
29
|
+
constructor(private readonly <%= serviceVariable %>: <%= pascalName %>Service) {}
|
|
30
|
+
|
|
31
|
+
<% Object.entries(it.miniApp.whitelistApis).forEach(([action, value]) => { %>
|
|
32
|
+
<% if (value !== true && typeof value !== 'object') { return; } %>
|
|
33
|
+
|
|
34
|
+
<% if(action === 'list') { %>
|
|
35
|
+
@Get()
|
|
36
|
+
findAll(@Headers() headers:ApiHeader) {
|
|
37
|
+
return this.<%= serviceVariable %>.findAll(headers);
|
|
38
|
+
}
|
|
39
|
+
<% } else if(action === 'detail') { %>
|
|
40
|
+
@Get(':id')
|
|
41
|
+
findOne(@Headers() headers: ApiHeader, @Param('id') id: string) {
|
|
42
|
+
return this.<%= serviceVariable %>.findOne(headers, id);
|
|
43
|
+
}
|
|
44
|
+
<% } else if(action === 'create') { %>
|
|
45
|
+
@Post()
|
|
46
|
+
@ApiBody({})
|
|
47
|
+
create(
|
|
48
|
+
@Headers() headers: ApiHeader,
|
|
49
|
+
@Body() resourceDto: any,
|
|
50
|
+
) {
|
|
51
|
+
return this.<%= serviceVariable %>.create(headers, resourceDto);
|
|
52
|
+
}
|
|
53
|
+
<% } else if(action === 'update') { %>
|
|
54
|
+
@Put(':id')
|
|
55
|
+
@ApiBody({})
|
|
56
|
+
update(
|
|
57
|
+
@Headers() headers: ApiHeader,
|
|
58
|
+
@Param('id') id: string,
|
|
59
|
+
@Body() resourceDto: any,
|
|
60
|
+
) {
|
|
61
|
+
return this.<%= serviceVariable %>.update(headers, id, resourceDto);
|
|
62
|
+
}
|
|
63
|
+
<% } else if(action === 'patch') { %>
|
|
64
|
+
@Patch(':id')
|
|
65
|
+
@ApiBody({})
|
|
66
|
+
patch(
|
|
67
|
+
@Headers() headers: ApiHeader,
|
|
68
|
+
@Param('id') id: string,
|
|
69
|
+
@Body() resourceDto: any,
|
|
70
|
+
) {
|
|
71
|
+
return this.<%= serviceVariable %>.patch(headers, id, resourceDto);
|
|
72
|
+
}
|
|
73
|
+
<% } else if(action === 'delete') { %>
|
|
74
|
+
@Delete(':id')
|
|
75
|
+
delete(
|
|
76
|
+
@Headers() headers: ApiHeader,
|
|
77
|
+
@Param('id') id: string,
|
|
78
|
+
) {
|
|
79
|
+
return this.<%= serviceVariable %>.delete(headers, id);
|
|
80
|
+
}
|
|
81
|
+
<% } else if(action === 'autoComplete') { %>
|
|
82
|
+
@Post('autocomplete')
|
|
83
|
+
@ApiQuery({ name: 'query', type: String })
|
|
84
|
+
@ApiBody({ description: 'Mongo DB Filter', type: () => Object })
|
|
85
|
+
findAutocomplete(
|
|
86
|
+
@Headers() headers: ApiHeader,
|
|
87
|
+
@Query('query') query: string,
|
|
88
|
+
@Body() filter: any,
|
|
89
|
+
) {
|
|
90
|
+
return this.<%= serviceVariable %>.autocomplete(headers, query, filter);
|
|
91
|
+
}
|
|
92
|
+
<% } else if(action === 'current') { %>
|
|
93
|
+
<% } else { %>
|
|
94
|
+
<% const apiSetting = it.apiSettings.find(item => item.action === action); %>
|
|
95
|
+
<% if (apiSetting) { %>
|
|
96
|
+
<% const hasBody = ['post', 'put', 'patch'].includes(apiSetting.method); %>
|
|
97
|
+
|
|
98
|
+
<%
|
|
99
|
+
const paramMatches = apiSetting.entryPoint.match(/:([\w]+)/g) || [];
|
|
100
|
+
const paramNames = paramMatches.map(p => p.replace(':', ''));
|
|
101
|
+
|
|
102
|
+
const args = [];
|
|
103
|
+
const output = [];
|
|
104
|
+
const queryParams = [];
|
|
105
|
+
|
|
106
|
+
for (let i = 0; i < paramNames.length; i++) {
|
|
107
|
+
const name = paramNames[i];
|
|
108
|
+
args.push(name);
|
|
109
|
+
output.push(name);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (hasBody) {
|
|
113
|
+
output.push('data');
|
|
114
|
+
}
|
|
115
|
+
%>
|
|
116
|
+
|
|
117
|
+
@<%= upperFirstCase(apiSetting.method) %>('<%= apiSetting.entryPoint %>')
|
|
118
|
+
<% if (hasBody) { %>
|
|
119
|
+
@ApiBody({
|
|
120
|
+
description: 'Request Body',
|
|
121
|
+
})
|
|
122
|
+
<% } %>
|
|
123
|
+
|
|
124
|
+
<%= action %>(
|
|
125
|
+
@Headers() headers: ApiHeader,
|
|
126
|
+
<% args.forEach(arg => { %>
|
|
127
|
+
@Param('<%= arg %>') <%= arg %>: string,
|
|
128
|
+
<% }) %>
|
|
129
|
+
<% if (hasBody) { %>
|
|
130
|
+
@Body() data: any,
|
|
131
|
+
<% } %>
|
|
132
|
+
) {
|
|
133
|
+
return this.<%= serviceVariable %>.<%= action %>(headers, <%= output.join(', ') %>);
|
|
134
|
+
}
|
|
135
|
+
<% } %>
|
|
136
|
+
<% } %>
|
|
137
|
+
|
|
138
|
+
<% }); %>
|
|
139
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const pascalName = upperFirstCase(it.resourceName);
|
|
3
|
+
const kebabName = camelToKebab(it.resourceName);
|
|
4
|
+
%>
|
|
5
|
+
|
|
6
|
+
import { Module } from '@nestjs/common';
|
|
7
|
+
import { <%= pascalName %>Controller } from './<%= kebabName %>.controller';
|
|
8
|
+
import { <%= pascalName %>Service } from './<%= kebabName %>.service';
|
|
9
|
+
|
|
10
|
+
@Module({
|
|
11
|
+
imports: [],
|
|
12
|
+
controllers: [<%= pascalName %>Controller],
|
|
13
|
+
providers: [<%= pascalName %>Service],
|
|
14
|
+
exports: [<%= pascalName %>Service],
|
|
15
|
+
})
|
|
16
|
+
export class <%= pascalName %>Module {}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const pascalName = upperFirstCase(it.resourceName);
|
|
3
|
+
const apiName = it.typename.toUpperCase() + 'Api';
|
|
4
|
+
%>
|
|
5
|
+
|
|
6
|
+
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
7
|
+
import _ from 'lodash';
|
|
8
|
+
import { <%= apiName %> } from 'src/openapi/backend-api';
|
|
9
|
+
import { ApiHeader } from 'src/types/api';
|
|
10
|
+
import { getOpenApiConfig } from 'src/utils/api';
|
|
11
|
+
|
|
12
|
+
@Injectable()
|
|
13
|
+
export class <%= pascalName %>Service {
|
|
14
|
+
protected guards = {
|
|
15
|
+
read: [],
|
|
16
|
+
create: [],
|
|
17
|
+
update: [],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
constructor() {}
|
|
21
|
+
|
|
22
|
+
private getApi(headers: Record<string, string>) {
|
|
23
|
+
return new <%= apiName %>(getOpenApiConfig(headers));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
<% Object.entries(it.miniApp.whitelistApis).forEach(([action, value]) => { %>
|
|
27
|
+
<% if (value !== true && typeof value !== 'object') { return; } %>
|
|
28
|
+
|
|
29
|
+
<% if(action === 'list') { %>
|
|
30
|
+
async findAll(headers: ApiHeader) {
|
|
31
|
+
const api = this.getApi(headers);
|
|
32
|
+
const resp = await api.runSearch({});
|
|
33
|
+
return resp.data;
|
|
34
|
+
}
|
|
35
|
+
<% } else if(action === 'detail') { %>
|
|
36
|
+
async findOne(headers: ApiHeader, id: string) {
|
|
37
|
+
const api = this.getApi(headers);
|
|
38
|
+
const resp = await api.runFindOne(id);
|
|
39
|
+
return resp.data;
|
|
40
|
+
}
|
|
41
|
+
<% } else if(action === 'create') { %>
|
|
42
|
+
async create(headers: ApiHeader, resourceDto: any) {
|
|
43
|
+
const api = this.getApi(headers);
|
|
44
|
+
const resp = await api.runCreate(resourceDto);
|
|
45
|
+
return resp.data;
|
|
46
|
+
}
|
|
47
|
+
<% } else if(action === 'update') { %>
|
|
48
|
+
async update(headers: ApiHeader, id: string, resourceDto: any) {
|
|
49
|
+
const api = this.getApi(headers);
|
|
50
|
+
const resp = await api.runUpdate(id, resourceDto);
|
|
51
|
+
return resp.data;
|
|
52
|
+
}
|
|
53
|
+
<% } else if(action === 'patch') { %>
|
|
54
|
+
async patch(headers: ApiHeader, id: string, resourceDto: any) {
|
|
55
|
+
const api = this.getApi(headers);
|
|
56
|
+
const resp = await api.runPatch(id, resourceDto);
|
|
57
|
+
return resp.data;
|
|
58
|
+
}
|
|
59
|
+
<% } else if(action === 'delete') { %>
|
|
60
|
+
async delete(headers: ApiHeader, id: string) {
|
|
61
|
+
const api = this.getApi(headers);
|
|
62
|
+
const resp = await api.runDelete(id);
|
|
63
|
+
return resp.data;
|
|
64
|
+
}
|
|
65
|
+
<% } else if(action === 'autoComplete') { %>
|
|
66
|
+
async autocomplete(headers: ApiHeader, query: string, filter: any) {
|
|
67
|
+
const api = this.getApi(headers);
|
|
68
|
+
const resp = await api.autoComplete(query, filter);
|
|
69
|
+
return resp.data;
|
|
70
|
+
}
|
|
71
|
+
<% } else if(action === 'current') { %>
|
|
72
|
+
<% } else { %>
|
|
73
|
+
<% const apiSetting = it.apiSettings.find(item => item.action === action); %>
|
|
74
|
+
<% if (apiSetting) { %>
|
|
75
|
+
<% const hasBody = ['post', 'put', 'patch'].includes(apiSetting.method); %>
|
|
76
|
+
|
|
77
|
+
<%
|
|
78
|
+
const paramMatches = apiSetting.entryPoint.match(/:([\w]+)/g) || [];
|
|
79
|
+
const paramNames = paramMatches.map(p => p.replace(':', ''));
|
|
80
|
+
|
|
81
|
+
const args = paramNames.map(name => {
|
|
82
|
+
return `${name}: string`;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const output = [];
|
|
86
|
+
const queryParams = [];
|
|
87
|
+
|
|
88
|
+
for (let i = 0; i < paramNames.length; i++) {
|
|
89
|
+
const name = paramNames[i];
|
|
90
|
+
|
|
91
|
+
output.push(name);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (hasBody) {
|
|
95
|
+
args.push('data: any');
|
|
96
|
+
output.push('data');
|
|
97
|
+
}
|
|
98
|
+
%>
|
|
99
|
+
|
|
100
|
+
async <%= action %>(headers: ApiHeader, <%= args.join(', ') %>) {
|
|
101
|
+
const api = this.getApi(headers);
|
|
102
|
+
const resp = await api.run<%= upperFirstCase(action) %>(<%= output.join(', ') %>);
|
|
103
|
+
return resp.data;
|
|
104
|
+
}
|
|
105
|
+
<% } %>
|
|
106
|
+
<% } %>
|
|
107
|
+
<% }) %>
|
|
108
|
+
|
|
109
|
+
}
|
|
@@ -6,10 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
<%
|
|
9
|
-
const upperFirstCase = (value) => {
|
|
10
|
-
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
9
|
const pascalName = upperFirstCase(it.resourceName);
|
|
14
10
|
const apiName = it.typename.toUpperCase() + 'Api';
|
|
15
11
|
const typeActionName = pascalName + 'Actions';
|
|
@@ -18,6 +14,7 @@
|
|
|
18
14
|
const hasMiniAppWhitelistedApi = Object.keys(miniAppWhitelistApis).length > 0;
|
|
19
15
|
%>
|
|
20
16
|
|
|
17
|
+
import { MiniAppApiListParam } from "../../types/bridge.type";
|
|
21
18
|
import { MiniAppBridgeService } from "../bridge.service";
|
|
22
19
|
|
|
23
20
|
export class MiniApp<%= pascalName %>BridgeService {
|
|
@@ -33,8 +30,8 @@ export class MiniApp<%= pascalName %>BridgeService {
|
|
|
33
30
|
<% if (value !== true && typeof value !== 'object') { return; } %>
|
|
34
31
|
|
|
35
32
|
<% if(action === 'list') { %>
|
|
36
|
-
async list() {
|
|
37
|
-
return this.bridge.callApi(this.resourceName, "list");
|
|
33
|
+
async list(params?: MiniAppApiListParam | undefined) {
|
|
34
|
+
return this.bridge.callApi(this.resourceName, "list", { body: params });
|
|
38
35
|
}
|
|
39
36
|
<% } else if(action === 'detail') { %>
|
|
40
37
|
async detail(id: string) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file was automatically generated by simpleapp generator. Every
|
|
3
3
|
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
-
* last change
|
|
4
|
+
* last change 2025-07-16
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
|
-
import {DefaultHooks} from "
|
|
7
|
+
import {DefaultHooks} from "./simpleapp.type"
|
|
8
8
|
|
|
9
9
|
<% const draw = (it, obj, key, schema) => { %>
|
|
10
10
|
<% if(typeof obj == 'string') {%>
|
|
@@ -6,14 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
<%
|
|
9
|
-
const upperFirstCase = (value) => {
|
|
10
|
-
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const camelToKebab = (value) => {
|
|
14
|
-
return value.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
9
|
const pascalName = upperFirstCase(it.resourceName);
|
|
18
10
|
const kebabName = camelToKebab(it.resourceName);
|
|
19
11
|
const apiName = it.typename.toUpperCase() + 'Api';
|
|
@@ -6,10 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
<%
|
|
9
|
-
const upperFirstCase = (value) => {
|
|
10
|
-
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
9
|
const pascalName = upperFirstCase(it.resourceName);
|
|
14
10
|
const apiName = it.typename.toUpperCase() + 'Api';
|
|
15
11
|
const typeActionName = 'MiniApp' + pascalName + 'Actions';
|
|
@@ -83,7 +79,11 @@ export class MiniApp<%= pascalName %>BridgeService {
|
|
|
83
79
|
|
|
84
80
|
<% if(action === 'list') { %>
|
|
85
81
|
protected async handleList(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) {
|
|
86
|
-
return (await this.api!.runSearch({
|
|
82
|
+
return (await this.api!.runSearch({
|
|
83
|
+
fields: message.params.body?.fields,
|
|
84
|
+
sorts: message.params.body?.sorts,
|
|
85
|
+
filter: message.params.body?.filters,
|
|
86
|
+
})).data;
|
|
87
87
|
}
|
|
88
88
|
<% } else if(action === 'detail') { %>
|
|
89
89
|
protected async handleDetail(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const getMiniAppInfo = (module) => {
|
|
3
|
+
const schema = module.schema;
|
|
4
|
+
const simpleAppConfig = schema['x-simpleapp-config'];
|
|
5
|
+
const miniAppWhitelistApis = simpleAppConfig?.miniApp?.whitelist || {};
|
|
6
|
+
const hasMiniAppWhitelistedApi = Object.keys(miniAppWhitelistApis).length > 0;
|
|
7
|
+
const resourcePascalName = upperFirstCase(simpleAppConfig.resourceName);
|
|
8
|
+
const resourceKebabName = camelToKebab(simpleAppConfig.resourceName);
|
|
9
|
+
const additionalApis = simpleAppConfig?.additionalApis || [];
|
|
10
|
+
let availableApis = {};
|
|
11
|
+
|
|
12
|
+
Object.entries(miniAppWhitelistApis).forEach(([action, value]) => {
|
|
13
|
+
if (value !== true && typeof value !== 'object') { return; }
|
|
14
|
+
let method = '';
|
|
15
|
+
switch(action) {
|
|
16
|
+
case 'list':
|
|
17
|
+
case 'detail':
|
|
18
|
+
method = 'get';
|
|
19
|
+
break;
|
|
20
|
+
|
|
21
|
+
case 'create':
|
|
22
|
+
case 'autoComplete':
|
|
23
|
+
method = 'post';
|
|
24
|
+
break;
|
|
25
|
+
|
|
26
|
+
case 'update':
|
|
27
|
+
method = 'put';
|
|
28
|
+
break;
|
|
29
|
+
|
|
30
|
+
case 'patch':
|
|
31
|
+
method = 'patch';
|
|
32
|
+
break;
|
|
33
|
+
|
|
34
|
+
case 'delete':
|
|
35
|
+
method = 'delete';
|
|
36
|
+
break;
|
|
37
|
+
|
|
38
|
+
case 'current':
|
|
39
|
+
return;
|
|
40
|
+
break;
|
|
41
|
+
|
|
42
|
+
default:
|
|
43
|
+
method = (additionalApis ?? []).find(item => item.action === action)?.method ?? '';
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
availableApis[action] = {
|
|
48
|
+
method: method
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
miniAppWhitelistApis,
|
|
54
|
+
hasMiniAppWhitelistedApi,
|
|
55
|
+
resourceName: simpleAppConfig.resourceName,
|
|
56
|
+
resourcePascalName,
|
|
57
|
+
resourceKebabName,
|
|
58
|
+
availableApis
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const modules = it.modules.sort((a, b) => a.docname.localeCompare(b.docname, undefined, { sensitivity: 'base' }));
|
|
63
|
+
%>
|
|
64
|
+
|
|
65
|
+
const scopes = {
|
|
66
|
+
<% modules.forEach(module => { %>
|
|
67
|
+
<%
|
|
68
|
+
const { hasMiniAppWhitelistedApi, resourceName, miniAppWhitelistApis, availableApis } = getMiniAppInfo(module);
|
|
69
|
+
%>
|
|
70
|
+
<% if(hasMiniAppWhitelistedApi) { %>
|
|
71
|
+
<%= resourceName %>: <%~ JSON.stringify(availableApis) %>,
|
|
72
|
+
<% } %>
|
|
73
|
+
<% }); %>
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default scopes;
|