@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
|
@@ -7,6 +7,35 @@
|
|
|
7
7
|
import { ApiProperty } from '@nestjs/swagger';
|
|
8
8
|
import { Field, ObjectType,ID } from '@nestjs/graphql';
|
|
9
9
|
import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json';
|
|
10
|
+
|
|
11
|
+
<% const draw = (it, obj, key) => { %>
|
|
12
|
+
<% if(typeof obj == 'string') {%>
|
|
13
|
+
<% // This Is Dynamic Object %>
|
|
14
|
+
<% if(it.models?.[obj] && it.models[obj]?.model && Object.keys(it.models[obj]?.model).length === 0) { %>
|
|
15
|
+
@Field(()=>GraphQLJSON)
|
|
16
|
+
@ApiProperty({ type:()=>Object,required: false, default: {} })
|
|
17
|
+
<%= key %>: Object;
|
|
18
|
+
<% } else { %>
|
|
19
|
+
@Field()
|
|
20
|
+
@ApiProperty({type: ()=><%=obj%>})
|
|
21
|
+
<%= key %>: <%= obj %>;
|
|
22
|
+
<% } %>
|
|
23
|
+
<%} else if(typeof obj.default !='undefined' && JSON.stringify(obj.default)=='{}'){%>
|
|
24
|
+
@Field(()=>GraphQLJSON)
|
|
25
|
+
@ApiProperty({ type:()=>Object,required: false, default: {} })
|
|
26
|
+
<%= key %>: Object;
|
|
27
|
+
<% } else if( Array.isArray( obj)){%>
|
|
28
|
+
@Field(type=>[<%=initType(obj[0]) %>])
|
|
29
|
+
@ApiProperty({type: ()=>[<%=initType(obj[0]) %>] })
|
|
30
|
+
<%= key %>: <%= obj[0] %>[];
|
|
31
|
+
|
|
32
|
+
<% }else{%>
|
|
33
|
+
@Field()
|
|
34
|
+
@ApiProperty(<%~ JSON.stringify(obj)%> )
|
|
35
|
+
<%= key %>: <%= obj.type %>;
|
|
36
|
+
<% } %>
|
|
37
|
+
<% } %>
|
|
38
|
+
|
|
10
39
|
<%Object.keys(it.models).forEach(function(name) { %>
|
|
11
40
|
<% let schema = it.models[name].model %>
|
|
12
41
|
|
|
@@ -18,35 +47,35 @@ import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json';
|
|
|
18
47
|
|
|
19
48
|
<% Object.keys(schema).forEach(function(key) { %>
|
|
20
49
|
<% let obj = schema[key] %>
|
|
21
|
-
<%
|
|
22
|
-
<% // This Is Dynamic Object %>
|
|
23
|
-
<% if(it.models?.[obj] && it.models[obj]?.model && Object.keys(it.models[obj]?.model).length === 0) { %>
|
|
24
|
-
@Field(()=>GraphQLJSON)
|
|
25
|
-
@ApiProperty({ type:()=>Object,required: false, default: {} })
|
|
26
|
-
<%= key %>: Object;
|
|
27
|
-
<% } else { %>
|
|
28
|
-
@Field()
|
|
29
|
-
@ApiProperty({type: ()=><%=obj%>})
|
|
30
|
-
<%= key %>: <%= obj %>;
|
|
31
|
-
<% } %>
|
|
32
|
-
<%} else if(typeof obj.default !='undefined' && JSON.stringify(obj.default)=='{}'){%>
|
|
33
|
-
@Field(()=>GraphQLJSON)
|
|
34
|
-
@ApiProperty({ type:()=>Object,required: false, default: {} })
|
|
35
|
-
<%= key %>: Object;
|
|
36
|
-
<% } else if( Array.isArray( obj)){%>
|
|
37
|
-
@Field(type=>[<%=initType(obj[0]) %>])
|
|
38
|
-
@ApiProperty({type: ()=>[<%=initType(obj[0]) %>] })
|
|
39
|
-
<%= key %>: <%= obj[0] %>[];
|
|
40
|
-
|
|
41
|
-
<% }else{%>
|
|
42
|
-
@Field()
|
|
43
|
-
@ApiProperty(<%~ JSON.stringify(obj)%> )
|
|
44
|
-
<%= key %>: <%= obj.type %>;
|
|
45
|
-
<% } %>
|
|
50
|
+
<% draw(it, obj, key) %>
|
|
46
51
|
<% }) %>
|
|
47
52
|
}
|
|
48
53
|
<%}) %>
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
/***************************************** Start Auto Complete *****************************************/
|
|
56
|
+
@ObjectType()
|
|
57
|
+
export class <%= it.apiSchemaName %>AutoComplete {
|
|
58
|
+
@Field()
|
|
59
|
+
@ApiProperty({ type: 'string', required: true, default: '' })
|
|
60
|
+
_id: string;
|
|
61
|
+
|
|
62
|
+
@Field()
|
|
63
|
+
@ApiProperty({ type: 'string', required: true, default: '' })
|
|
64
|
+
code: string;
|
|
65
|
+
|
|
66
|
+
@Field()
|
|
67
|
+
@ApiProperty({ type: 'string', required: true, default: '' })
|
|
68
|
+
label: string;
|
|
69
|
+
|
|
70
|
+
<% if(it.moreAutoComplete && Array.isArray(it.moreAutoComplete)) { %>
|
|
71
|
+
<% it.moreAutoComplete.forEach(function(field){ %>
|
|
72
|
+
<% draw(it, it.models[it.apiSchemaName].model[field], field) %>
|
|
73
|
+
|
|
74
|
+
<% }) %>
|
|
75
|
+
<% } %>
|
|
76
|
+
}
|
|
77
|
+
/****************************************** End Auto Complete ******************************************/
|
|
78
|
+
|
|
79
|
+
/************************************** Customized Code Begin Here *************************************/
|
|
80
|
+
<%~ it.apiSchemaCode %>
|
|
52
81
|
|
|
@@ -96,7 +96,8 @@ export class <%= it.typename %>Controller extends SimpleAppAbstractController<
|
|
|
96
96
|
@ApiResponse({
|
|
97
97
|
status: 200,
|
|
98
98
|
description: 'Found',
|
|
99
|
-
type:
|
|
99
|
+
type: schemas.<%= it.typename %>AutoComplete,
|
|
100
|
+
isArray: true,
|
|
100
101
|
})
|
|
101
102
|
@ApiResponse({ status: 500, description: 'Internal error' })
|
|
102
103
|
@ApiQuery({ name: 'keyword', type:String})
|
|
@@ -6,15 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import {DefaultHooks} from "../types"
|
|
8
8
|
|
|
9
|
-
<%
|
|
10
|
-
<% let schema = it.models[prop] %>
|
|
11
|
-
export type <%= prop %> = {
|
|
12
|
-
<% // Dynamic Object %>
|
|
13
|
-
<% if(it.models[prop].type === 'object' && it.models[prop]?.model && Object.keys(it.models[prop].model).length === 0 ) { %>
|
|
14
|
-
[key: string]: any;
|
|
15
|
-
<% } else { %>
|
|
16
|
-
<%Object.keys(schema.model).forEach(function(key){ %>
|
|
17
|
-
<% const obj = schema.model[key] %>
|
|
9
|
+
<% const draw = (it, obj, key, schema) => { %>
|
|
18
10
|
<% if(typeof obj == 'string') {%>
|
|
19
11
|
<%= key %> <%if(!schema.required.includes(key)){%>?<%}%>: <%= obj %>; //child object
|
|
20
12
|
<% }else if( Array.isArray( obj)){%>
|
|
@@ -24,6 +16,18 @@ import {DefaultHooks} from "../types"
|
|
|
24
16
|
<% }else{%>
|
|
25
17
|
<%= key %> <% if(!obj.required || obj.required==false){%>?<%}%>: <%= obj.type %>; // <%~ JSON.stringify(obj) %>
|
|
26
18
|
<% } %>
|
|
19
|
+
<% } %>
|
|
20
|
+
|
|
21
|
+
<%Object.keys(it.models).forEach(function(prop){ %>
|
|
22
|
+
<% let schema = it.models[prop] %>
|
|
23
|
+
export type <%= prop %> = {
|
|
24
|
+
<% // Dynamic Object %>
|
|
25
|
+
<% if(it.models[prop].type === 'object' && it.models[prop]?.model && Object.keys(it.models[prop].model).length === 0 ) { %>
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
<% } else { %>
|
|
28
|
+
<%Object.keys(schema.model).forEach(function(key){ %>
|
|
29
|
+
<% const obj = schema.model[key] %>
|
|
30
|
+
<% draw(it, obj, key, schema) %>
|
|
27
31
|
<%})%>
|
|
28
32
|
|
|
29
33
|
<% } %>
|
|
@@ -35,4 +39,18 @@ import {DefaultHooks} from "../types"
|
|
|
35
39
|
export type <%=it.typename%>Hooks = DefaultHooks<<%=it.typename%>> & {
|
|
36
40
|
|
|
37
41
|
|
|
38
|
-
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/***************************************** Start Auto Complete *****************************************/
|
|
45
|
+
export type <%= it.apiSchemaName %>AutoComplete = {
|
|
46
|
+
_id: string;
|
|
47
|
+
code: string;
|
|
48
|
+
label: string;
|
|
49
|
+
<% if(it.moreAutoComplete && Array.isArray(it.moreAutoComplete)) { %>
|
|
50
|
+
<% it.moreAutoComplete.forEach(function(field){ %>
|
|
51
|
+
<% draw(it, it.models[it.apiSchemaName].model[field], field, it.models[it.apiSchemaName]) %>
|
|
52
|
+
<% }) %>
|
|
53
|
+
|
|
54
|
+
<% } %>
|
|
55
|
+
}
|
|
56
|
+
/****************************************** End Auto Complete ******************************************/
|
|
@@ -0,0 +1,162 @@
|
|
|
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 { <%= apiName %> } from "~/simpleapp/generate/openapi";
|
|
22
|
+
import { MiniAppBridgeMessageApi } from "../../types/bridge.type";
|
|
23
|
+
|
|
24
|
+
const actions = <%~ JSON.stringify(miniAppWhitelistApis, null, 2) %> as const;
|
|
25
|
+
|
|
26
|
+
type <%= typeActionName %> = (typeof actions)[number];
|
|
27
|
+
|
|
28
|
+
export class MiniApp<%= pascalName %>BridgeService {
|
|
29
|
+
protected api!: <%= apiName %>;
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
this.api = new <%= apiName %>(getAxiosConfig());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async handleApi(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) {
|
|
36
|
+
<% if(hasMiniAppWhitelistedApi) { %>
|
|
37
|
+
const handlers = this.getHandlers();
|
|
38
|
+
|
|
39
|
+
const handler = handlers[message.params.action];
|
|
40
|
+
if (!handler) {
|
|
41
|
+
throw new Error(`ERR_UNKNOWN_ACTION: ${message.params.action}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return await handler(message);
|
|
45
|
+
<% } else { %>
|
|
46
|
+
throw new Error(`ERR_NOT_SUPPORTED`);
|
|
47
|
+
<% } %>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private getHandlers(): Record<
|
|
51
|
+
<%= typeActionName %>,
|
|
52
|
+
(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) => Promise<any>
|
|
53
|
+
> {
|
|
54
|
+
<% if(hasMiniAppWhitelistedApi) { %>
|
|
55
|
+
return {
|
|
56
|
+
<% for (let i = 0; i < miniAppWhitelistApis.length; i++) { %>
|
|
57
|
+
<%
|
|
58
|
+
const action = miniAppWhitelistApis[i];
|
|
59
|
+
const handlerName = "handle" + upperFirstCase(action);
|
|
60
|
+
%>
|
|
61
|
+
<%= action %>: this.<%= handlerName %>.bind(this),
|
|
62
|
+
<% } %>
|
|
63
|
+
};
|
|
64
|
+
<% } else { %>
|
|
65
|
+
throw new Error(`ERR_NOT_SUPPORTED`);
|
|
66
|
+
<% } %>
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/****************************************** API Action *****************************************/
|
|
70
|
+
|
|
71
|
+
<% for (let i = 0; i < miniAppWhitelistApis.length; i++) { %>
|
|
72
|
+
<%
|
|
73
|
+
const action = miniAppWhitelistApis[i];
|
|
74
|
+
%>
|
|
75
|
+
|
|
76
|
+
<% if(action === 'list') { %>
|
|
77
|
+
private async handleList(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) {
|
|
78
|
+
return (await this.api!.runSearch({})).data;
|
|
79
|
+
}
|
|
80
|
+
<% } else if(action === 'detail') { %>
|
|
81
|
+
private async handleDetail(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) {
|
|
82
|
+
if (!message.params.resource.id) throw new Error("ERR_MISSING_ID");
|
|
83
|
+
return (await this.api!.runFindOne(message.params.resource.id)).data;
|
|
84
|
+
}
|
|
85
|
+
<% } else if(action === 'create') { %>
|
|
86
|
+
private async handleCreate(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) {
|
|
87
|
+
if (!message.params.body) throw new Error("ERR_MISSING_BODY");
|
|
88
|
+
return (await this.api!.runCreate(message.params.body as any)).data;
|
|
89
|
+
}
|
|
90
|
+
<% } else if(action === 'update') { %>
|
|
91
|
+
private async handleUpdate(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) {
|
|
92
|
+
if (!message.params.resource.id) throw new Error("ERR_MISSING_ID");
|
|
93
|
+
if (!message.params.body) throw new Error("ERR_MISSING_BODY");
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
await this.api!.runUpdate(
|
|
97
|
+
message.params.resource.id,
|
|
98
|
+
// TODO: Type
|
|
99
|
+
message.params.body as any,
|
|
100
|
+
)
|
|
101
|
+
).data;
|
|
102
|
+
}
|
|
103
|
+
<% } else if(action === 'patch') { %>
|
|
104
|
+
private async handlePatch(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) {
|
|
105
|
+
if (!message.params.resource.id) throw new Error("ERR_MISSING_ID");
|
|
106
|
+
if (!message.params.body) throw new Error("ERR_MISSING_BODY");
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
await this.api!.runPatch(
|
|
110
|
+
message.params.resource.id,
|
|
111
|
+
// TODO: Type
|
|
112
|
+
message.params.body as any,
|
|
113
|
+
)
|
|
114
|
+
).data;
|
|
115
|
+
}
|
|
116
|
+
<% } else if(action === 'delete') { %>
|
|
117
|
+
private async handleDelete(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) {
|
|
118
|
+
if (!message.params.resource.id) throw new Error("ERR_MISSING_ID");
|
|
119
|
+
|
|
120
|
+
return (await this.api!.runDelete(message.params.resource.id)).data;
|
|
121
|
+
}
|
|
122
|
+
<% } else if(action === 'autoComplete') { %>
|
|
123
|
+
private async handleAutoComplete(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) {
|
|
124
|
+
return (await this.api!.autoComplete(message.params.query ?? "", {})).data;
|
|
125
|
+
}
|
|
126
|
+
<% } else { %>
|
|
127
|
+
private async handle<%= upperFirstCase(action) %>(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) {
|
|
128
|
+
<% const apiSetting = it.apiSettings.find(item => item.action === action); %>
|
|
129
|
+
<% if (apiSetting) { %>
|
|
130
|
+
const queryParams = message.params?.queryParams;
|
|
131
|
+
|
|
132
|
+
<% const hasBody = ['post', 'put', 'patch'].includes(apiSetting.method); %>
|
|
133
|
+
<% if (hasBody) { %>
|
|
134
|
+
if (!message.params.body) throw new Error("ERR_MISSING_BODY");
|
|
135
|
+
<% } %>
|
|
136
|
+
<%
|
|
137
|
+
const paramMatches = apiSetting.entryPoint.match(/:([\w]+)/g) || [];
|
|
138
|
+
const paramNames = paramMatches.map(p => p.replace(':', ''));
|
|
139
|
+
paramNames.forEach(name => {
|
|
140
|
+
if (name === 'id') {
|
|
141
|
+
%>
|
|
142
|
+
if (!message.params.resource.id) throw new Error("ERR_MISSING_ID");
|
|
143
|
+
<% } else { %>
|
|
144
|
+
if (!queryParams?.<%= name %>) throw new Error("ERR_MISSING_QUERY_PARAM: <%= name %>");
|
|
145
|
+
<% }
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// prepare args for the function call
|
|
149
|
+
const args = paramNames.map(name => (
|
|
150
|
+
name === 'id'
|
|
151
|
+
? 'message.params.resource.id'
|
|
152
|
+
: `queryParams?.${name}`
|
|
153
|
+
));
|
|
154
|
+
if (hasBody) args.push('message.params.body');
|
|
155
|
+
%>
|
|
156
|
+
|
|
157
|
+
return (await this.api!.run<%= upperFirstCase(action) %>(<%= args.join(', ') %>)).data;
|
|
158
|
+
<% } %>
|
|
159
|
+
}
|
|
160
|
+
<% } %>
|
|
161
|
+
<% } %>
|
|
162
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
import { MINI_APP_BRIDGE_MESSAGES } from './constants/common.constant';
|
|
9
|
+
import { MiniAppBridgeResourceAccessor } from './services/bridge-resource-accessor.service';
|
|
10
|
+
import { MiniAppBridgeMessageNavigate } from './types/bridge.type';
|
|
11
|
+
|
|
12
|
+
export class SimtrainEcoMiniAppJsSdk extends MiniAppBridgeResourceAccessor {
|
|
13
|
+
public ui = {
|
|
14
|
+
navigateTo: (target: string, id?: string, query?: string) => {
|
|
15
|
+
const message: MiniAppBridgeMessageNavigate = {
|
|
16
|
+
type: MINI_APP_BRIDGE_MESSAGES.NAVIGATE,
|
|
17
|
+
params: { target, id, query }
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
window.parent.postMessage(message, '*');
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
console.log('Hello from SimtrainEcoMiniAppJsSdk !!!');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 camelToKebab = (value) => {
|
|
14
|
+
return value.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const getMiniAppInfo = (module) => {
|
|
18
|
+
const config = module.schema['x-simpleapp-config'];
|
|
19
|
+
const resourceName = config?.resourceName ?? config.documentName;
|
|
20
|
+
|
|
21
|
+
const pascalName = upperFirstCase(resourceName);
|
|
22
|
+
const kebabName = camelToKebab(resourceName);
|
|
23
|
+
|
|
24
|
+
const miniAppWhitelistApis = config?.miniApp?.whitelist || [];
|
|
25
|
+
const hasMiniAppWhitelistedApi = miniAppWhitelistApis.length > 0;
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
resourceName,
|
|
29
|
+
pascalName,
|
|
30
|
+
kebabName,
|
|
31
|
+
hasMiniAppWhitelistedApi,
|
|
32
|
+
miniAppWhitelistApis,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
%>
|
|
36
|
+
|
|
37
|
+
import { MiniAppResourceMap } from "../types/resource-mapper.type";
|
|
38
|
+
import { MiniAppBridgeService } from "./bridge.service";
|
|
39
|
+
|
|
40
|
+
<% for (let i = 0; i < it.modules.length; i++) { %>
|
|
41
|
+
<%
|
|
42
|
+
const { pascalName, kebabName, hasMiniAppWhitelistedApi } = getMiniAppInfo(it.modules[i]);
|
|
43
|
+
%>
|
|
44
|
+
<% if(hasMiniAppWhitelistedApi) { %>
|
|
45
|
+
import { MiniApp<%= pascalName %>BridgeService } from "../services/resources/<%= kebabName %>-bridge.service";
|
|
46
|
+
<% } %>
|
|
47
|
+
<% } %>
|
|
48
|
+
|
|
49
|
+
export class MiniAppBridgeResourceAccessor {
|
|
50
|
+
protected bridge: MiniAppBridgeService;
|
|
51
|
+
protected instances: Partial<MiniAppResourceMap> = {};
|
|
52
|
+
|
|
53
|
+
constructor() {
|
|
54
|
+
this.bridge = new MiniAppBridgeService();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
<% for (let i = 0; i < it.modules.length; i++) { %>
|
|
58
|
+
<%
|
|
59
|
+
const { resourceName, pascalName, kebabName, hasMiniAppWhitelistedApi } = getMiniAppInfo(it.modules[i]);
|
|
60
|
+
%>
|
|
61
|
+
<% if(hasMiniAppWhitelistedApi) { %>
|
|
62
|
+
get <%= resourceName %>() {
|
|
63
|
+
if (!this.instances.<%= resourceName %>) {
|
|
64
|
+
this.instances.<%= resourceName %> = new MiniApp<%= pascalName %>BridgeService(this.bridge);
|
|
65
|
+
}
|
|
66
|
+
return this.instances.<%= resourceName %>;
|
|
67
|
+
}
|
|
68
|
+
<% } %>
|
|
69
|
+
<% } %>
|
|
70
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
import { MINI_APP_BRIDGE_MESSAGES } from '../constants/common.constant';
|
|
9
|
+
import {
|
|
10
|
+
MiniAppBridgeMessageApi,
|
|
11
|
+
MiniAppBridgeMessageApiResponse,
|
|
12
|
+
MiniAppBridgeMessageOpenOnScreenResourceForm
|
|
13
|
+
} from '../types/bridge.type';
|
|
14
|
+
import {
|
|
15
|
+
MiniAppResourceServiceApiParam,
|
|
16
|
+
MiniAppResourceServiceOpenOnScreenResourceFormParam
|
|
17
|
+
} from '../types/service.type';
|
|
18
|
+
|
|
19
|
+
export class MiniAppBridgeService {
|
|
20
|
+
private pendingRequests: Record<
|
|
21
|
+
string,
|
|
22
|
+
{ resolve: (data: any) => void; reject: (err: any) => void }
|
|
23
|
+
> = {};
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
if (typeof window !== 'undefined') {
|
|
27
|
+
window.addEventListener('message', (event) => {
|
|
28
|
+
const message: MiniAppBridgeMessageApiResponse<any> = event.data;
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
message.type === MINI_APP_BRIDGE_MESSAGES.API_RESPONSE &&
|
|
32
|
+
message.requestId
|
|
33
|
+
) {
|
|
34
|
+
const handler = this.pendingRequests[message.requestId];
|
|
35
|
+
if (!handler) return;
|
|
36
|
+
|
|
37
|
+
if (message.success) {
|
|
38
|
+
handler.resolve(message.data);
|
|
39
|
+
} else {
|
|
40
|
+
handler.reject(message.error);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
delete this.pendingRequests[message.requestId];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async callApi(
|
|
50
|
+
resource: string,
|
|
51
|
+
action: string,
|
|
52
|
+
params: MiniAppResourceServiceApiParam = {}
|
|
53
|
+
) {
|
|
54
|
+
const requestId = crypto.randomUUID();
|
|
55
|
+
|
|
56
|
+
// TODO: Type
|
|
57
|
+
const requestMessage: MiniAppBridgeMessageApi<any> = {
|
|
58
|
+
type: MINI_APP_BRIDGE_MESSAGES.API,
|
|
59
|
+
requestId,
|
|
60
|
+
params: {
|
|
61
|
+
resource: { name: resource, id: params.id },
|
|
62
|
+
action,
|
|
63
|
+
query: params.query,
|
|
64
|
+
body: params.body,
|
|
65
|
+
queryParams: params.queryParams,
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const promise = new Promise<any>((resolve, reject) => {
|
|
70
|
+
this.pendingRequests[requestId] = { resolve, reject };
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
window.parent.postMessage(requestMessage, '*');
|
|
74
|
+
return promise;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
openOnScreenResourceForm(
|
|
78
|
+
resource: string,
|
|
79
|
+
params: MiniAppResourceServiceOpenOnScreenResourceFormParam = {}
|
|
80
|
+
) {
|
|
81
|
+
const message: MiniAppBridgeMessageOpenOnScreenResourceForm = {
|
|
82
|
+
type: MINI_APP_BRIDGE_MESSAGES.OPEN_ON_SCREEN_RESOURCE_FORM,
|
|
83
|
+
params: {
|
|
84
|
+
resource: { name: resource, id: params.id },
|
|
85
|
+
data: params.data
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
window.parent.postMessage(message, '*');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
export type MiniAppResourceServiceApiParam = {
|
|
9
|
+
id?: string;
|
|
10
|
+
queryParams?: {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
};
|
|
13
|
+
query?: string;
|
|
14
|
+
// TODO: Type
|
|
15
|
+
body?: any;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type MiniAppResourceServiceOpenOnScreenResourceFormParam = {
|
|
19
|
+
id?: string;
|
|
20
|
+
// TODO: Type
|
|
21
|
+
data?: any;
|
|
22
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const upperFirstCase = (value) => {
|
|
3
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const camelToKebab = (value) => {
|
|
7
|
+
return value.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const camelToSnake = (value) => {
|
|
11
|
+
return value.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const getMiniAppInfo = (module) => {
|
|
15
|
+
const config = module.schema['x-simpleapp-config'];
|
|
16
|
+
const resourceName = config?.resourceName ?? config.documentName;
|
|
17
|
+
|
|
18
|
+
const pascalName = upperFirstCase(resourceName);
|
|
19
|
+
const kebabName = camelToKebab(resourceName);
|
|
20
|
+
const snakeName = camelToSnake(resourceName);
|
|
21
|
+
|
|
22
|
+
const miniAppWhitelistApis = config?.miniApp?.whitelist || [];
|
|
23
|
+
const hasMiniAppWhitelistedApi = miniAppWhitelistApis.length > 0;
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
resourceName,
|
|
27
|
+
pascalName,
|
|
28
|
+
kebabName,
|
|
29
|
+
snakeName,
|
|
30
|
+
hasMiniAppWhitelistedApi,
|
|
31
|
+
miniAppWhitelistApis,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
%>
|
|
35
|
+
|
|
36
|
+
from .services.ui import UI
|
|
37
|
+
from .services.resources.student import Student
|
|
38
|
+
from .services.init_message_bridge import InitMessageBridge
|
|
39
|
+
from .services.helper import Helper as SimtrainSdkHelper
|
|
40
|
+
|
|
41
|
+
# ========================== Import Resource ==========================
|
|
42
|
+
|
|
43
|
+
<% for (let i = 0; i < it.modules.length; i++) { %>
|
|
44
|
+
<%
|
|
45
|
+
const { resourceName, pascalName, kebabName, snakeName, hasMiniAppWhitelistedApi } = getMiniAppInfo(it.modules[i]);
|
|
46
|
+
%>
|
|
47
|
+
<% if(hasMiniAppWhitelistedApi) { %>
|
|
48
|
+
|
|
49
|
+
from .services.resources.<%= snakeName %> import <%= pascalName %>
|
|
50
|
+
|
|
51
|
+
<% } %>
|
|
52
|
+
<% } %>
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class SimtrainEcoMiniAppStreamlitSdk:
|
|
56
|
+
def __init__(self):
|
|
57
|
+
InitMessageBridge()
|
|
58
|
+
|
|
59
|
+
self.ui = UI()
|
|
60
|
+
|
|
61
|
+
self.helper = SimtrainSdkHelper
|
|
62
|
+
|
|
63
|
+
# ========================== Import Resource ==========================
|
|
64
|
+
|
|
65
|
+
<% for (let i = 0; i < it.modules.length; i++) { %>
|
|
66
|
+
<%
|
|
67
|
+
const { resourceName, pascalName, kebabName, hasMiniAppWhitelistedApi } = getMiniAppInfo(it.modules[i]);
|
|
68
|
+
%>
|
|
69
|
+
<% if(hasMiniAppWhitelistedApi) { %>
|
|
70
|
+
|
|
71
|
+
self.<%= resourceName %> = <%= pascalName %>()
|
|
72
|
+
<% } %>
|
|
73
|
+
<% } %>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2024-02-23
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Field, ObjectType } from '@nestjs/graphql';
|
|
9
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
10
|
+
import { Customfield } from '../generate/apischemas';
|
|
11
|
+
|
|
12
|
+
@ObjectType()
|
|
13
|
+
export class CompleteCustomFieldResource {
|
|
14
|
+
@Field()
|
|
15
|
+
@ApiProperty({ type: 'string', required: true })
|
|
16
|
+
resourceName: string;
|
|
17
|
+
|
|
18
|
+
@Field(() => Customfield)
|
|
19
|
+
@ApiProperty({ type: () => Customfield, required: false })
|
|
20
|
+
data: Customfield;
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2024-02-23
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
<%for(let i=0; i<it.modules.length;i++){ %>
|
|
9
|
+
<% const d = it.modules[i] %>
|
|
10
|
+
export * from './<%= d['doctype']%>.jsonschema'
|
|
11
|
+
<%}%>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2024-02-23
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Customfield } from '../generate/types';
|
|
9
|
+
|
|
10
|
+
export type CompleteCustomFieldResource = {
|
|
11
|
+
resourceName: string;
|
|
12
|
+
|
|
13
|
+
data?: Customfield;
|
|
14
|
+
};
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
<slot name="default" :data="document.getData()" :getField="getField"></slot>
|
|
4
4
|
<slot name="customField">
|
|
5
5
|
<!-- TODO: TS Error -->
|
|
6
|
-
<SimpleAppCustomFieldFormSection
|
|
6
|
+
<!-- <SimpleAppCustomFieldFormSection
|
|
7
7
|
:customFieldJsonSchema="document.schema.properties.more"
|
|
8
8
|
:data="document.getData().more"
|
|
9
9
|
:handleGetField="getField"
|
|
10
|
-
/>
|
|
10
|
+
/> -->
|
|
11
11
|
</slot>
|
|
12
12
|
</form>
|
|
13
13
|
</template>
|
|
@@ -24,7 +24,6 @@ import type { JSONSchema7, JSONSchema7Definition } from "json-schema";
|
|
|
24
24
|
import * as alldefaults from "~/simpleapp/generate/defaults";
|
|
25
25
|
import _, { upperFirst } from "lodash";
|
|
26
26
|
const props = defineProps<{
|
|
27
|
-
|
|
28
27
|
document: SimpleAppClient<any, any>;
|
|
29
28
|
readonly?: boolean;
|
|
30
29
|
}>();
|