@simitgroup/simpleapp-generator 1.0.8 → 1.0.14

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.
Files changed (43) hide show
  1. package/README.md +128 -1
  2. package/dist/createproject.js +39 -18
  3. package/dist/createproject.js.map +1 -1
  4. package/dist/generate.js +49 -20
  5. package/dist/generate.js.map +1 -1
  6. package/dist/index.js +36 -25
  7. package/dist/index.js.map +1 -1
  8. package/dist/processors/jsonschemabuilder.js +60 -9
  9. package/dist/processors/jsonschemabuilder.js.map +1 -1
  10. package/dist/storage.js +5 -0
  11. package/dist/storage.js.map +1 -0
  12. package/package.json +10 -5
  13. package/src/createproject.ts +40 -14
  14. package/src/generate.ts +62 -28
  15. package/src/index.ts +31 -20
  16. package/src/processors/jsonschemabuilder.ts +70 -15
  17. package/src/storage.ts +3 -0
  18. package/src/type.ts +24 -2
  19. package/templates/SimpleAppClient.eta +10 -5
  20. package/templates/SimpleAppController.eta +4 -1
  21. package/templates/SimpleAppService.eta +87 -11
  22. package/templates/basic/controller.eta +17 -1
  23. package/templates/basic/model.eta +1 -1
  24. package/templates/basic/pageindex.vue.eta +50 -0
  25. package/templates/basic/pageindexwithid.vue.eta +1 -0
  26. package/templates/basic/service.eta +2 -0
  27. package/templates/basic/{apiclient.eta → simpleappclient.eta} +15 -7
  28. package/templates/nuxt/app.vue.eta +8 -0
  29. package/templates/nuxt/components.crudsimple.vue.eta +95 -0
  30. package/templates/nuxt/components.debugdocdata.vue.eta +20 -0
  31. package/templates/nuxt/components.eventmonitor.vue.eta +79 -0
  32. package/templates/nuxt/components.menus.vue.eta +8 -0
  33. package/templates/nuxt/composables.getautocomplete.ts.eta +24 -0
  34. package/templates/nuxt/composables.getmenus.ts.eta +8 -0
  35. package/templates/nuxt/env.eta +3 -0
  36. package/templates/nuxt/layouts.default.vue.eta +10 -0
  37. package/templates/{nuxt.config.eta → nuxt/nuxt.config.ts.eta} +6 -3
  38. package/templates/nuxt/pages.index.vue.eta +3 -0
  39. package/templates/{nuxt.plugins.eta → nuxt/plugins.simpleapp.ts.eta} +12 -2
  40. package/templates/nuxt/server.api.ts.eta +131 -0
  41. package/templates/nuxt/tailwind.config.ts.eta +9 -0
  42. package/templates/nuxt/tailwind.css.eta +28 -0
  43. package/templates/nuxt.env.eta +0 -2
@@ -0,0 +1,95 @@
1
+ <template>
2
+ <div class="simpleapp-crudsimple">
3
+ <button class="bg-primary" type="reset" @click="newData">New</button>
4
+
5
+
6
+ <SimpleAppDatatable
7
+ @row-dblclick="editRecord"
8
+ v-model="recordlist"
9
+ :setting="{}"
10
+ :columns="listColumns"
11
+ ></SimpleAppDatatable>
12
+
13
+ <DebugDocumentData v-model="data"/>
14
+ </div>
15
+
16
+ <Dialog v-model:visible="visible" modal header="Header" class="crudsimple-dialog" :autoZIndex="false" :style="{zIndex:100, width: '80vw' }">
17
+ <SimpleAppForm :document="obj" :title="title" #default="o">
18
+ <div class="simpleapp-tool-bar" >
19
+ <button class="bg-default" @click="newData" type="reset">New</button>
20
+ <button class="bg-primary" @click="saveData" type="submit">Save</button>
21
+ <button class="bg-danger" @click="deleteData($event)">Delete</button>
22
+ <ConfirmPopup></ConfirmPopup>
23
+ </div>
24
+ <slot :data="o.data" :getField="o.getField" name="default"></slot>
25
+ </SimpleAppForm>
26
+ </Dialog>
27
+ </template>
28
+ <script setup lang="ts">
29
+
30
+ import { SimpleAppClient } from '@simitgroup//simpleapp-vue-component/src/SimpleAppClient';
31
+ import SimpleAppForm from '@simitgroup/simpleapp-vue-component/src/components/SimpleAppForm.vue';
32
+ import SimpleAppDatatable from '@simitgroup/simpleapp-vue-component/src/components/SimpleAppDatatable.vue';
33
+ import Dialog from 'primevue/dialog';
34
+ import ConfirmPopup from 'primevue/confirmpopup';
35
+ import { useConfirm } from "primevue/useconfirm";
36
+
37
+ const confirm = useConfirm();
38
+ const props = defineProps<{
39
+ document:SimpleAppClient<any,any>
40
+ listColumns:string[]
41
+ title:string
42
+ }>()
43
+ const visible = ref(false)
44
+ const obj = props.document
45
+ const data = obj.getReactiveData()
46
+ const recordlist = ref();
47
+
48
+
49
+ const refresh = () => {
50
+ obj.list().then((res:any) => {
51
+ recordlist.value = res;
52
+ });
53
+ };
54
+ const newData = () => {
55
+ obj.setNew()
56
+ visible.value=true;
57
+ };
58
+
59
+ const editRecord = (event: any) => {
60
+ obj.getById(event.data._id);
61
+ visible.value=true
62
+ };
63
+
64
+ const saveData = () => {
65
+ if (data.value._id == "") {
66
+ obj.create().then(()=>visible.value=false).finally(() => refresh());
67
+ } else {
68
+ obj.update().then(()=>visible.value=false).finally(() => refresh());
69
+ }
70
+ };
71
+ const deleteData = (event:Event) => {
72
+ console.log("deleteData")
73
+ confirm.require({
74
+ target: event.currentTarget as HTMLElement,
75
+ message:'Delete?',
76
+ icon: 'pi pi-exclamation-triangle',
77
+ acceptClass: 'p-button-danger',
78
+ accept: ()=>{
79
+ obj.delete(data.value._id ?? "").then(()=>visible.value=false).finally(() => {
80
+ refresh();
81
+ });
82
+ },
83
+ reject: () => {
84
+ console.log("Cancel delete")
85
+ }
86
+ })
87
+
88
+ };
89
+ refresh();
90
+ </script>
91
+ <style scoped>
92
+ .crudsimple-dialog{
93
+ z-index: 100;
94
+ }
95
+ </style>
@@ -0,0 +1,20 @@
1
+ <template>
2
+ <div class="floatright">
3
+ <h3>data in json</h3>
4
+ <pre>
5
+ {{ modelValue }}
6
+ </pre>
7
+ </div>
8
+ </template>
9
+ <script setup lang="ts">
10
+ const modelValue = defineModel()
11
+ </script>
12
+ <style scoped>
13
+ .floatright{
14
+ position: fixed;
15
+ right: 0;
16
+ background-color: antiquewhite;
17
+ font-size: large;
18
+ top: 0;
19
+ }
20
+ </style>
@@ -0,0 +1,79 @@
1
+ <template>
2
+ <Toast group="default"/>
3
+ <Toast group="list">
4
+ <template #message="p">
5
+ <ol>
6
+ <li v-for="(item,index) in p.message.detail" :key="index">{{item.instancePath}} {{ item.message }}</li>
7
+ </ol>
8
+ </template>
9
+ </Toast>
10
+ </template>
11
+ <script setup lang="ts">
12
+
13
+ import { useToast, } from 'primevue/usetoast';
14
+ import type { ToastMessageOptions } from 'primevue/toast';
15
+ import Toast from 'primevue/toast';
16
+ import { stringify } from 'ajv';
17
+ const toast = useToast();
18
+ const { $event,$listen } = useNuxtApp()
19
+ let resmsg:ToastMessageOptions = {} as ToastMessageOptions
20
+
21
+ $listen('*',(type:string,data:any)=>{
22
+
23
+
24
+ let duration = 3000
25
+ let severity:typeof resmsg['severity']
26
+ let isshow=true
27
+ let toastgroup='default'
28
+ if(type.indexOf('error')>=0){
29
+ duration = 0
30
+ severity='error'
31
+
32
+ }
33
+ else if(type.indexOf('warn')>=0){
34
+ duration = 10000
35
+ severity='warn'
36
+ }
37
+ else if(type.indexOf('info')>=0){
38
+ duration = 3000
39
+ severity='info'
40
+ isshow=false
41
+ }
42
+ else if(type.indexOf('success')>=0){
43
+ duration = 3000
44
+ severity='success'
45
+ }
46
+ if(Array.isArray(data)){
47
+ toastgroup='list'
48
+ }
49
+ // let msg:string=prepareMsg(data,severity?.toString()??'')
50
+
51
+ if(isshow){
52
+ toast.removeAllGroups()
53
+ resmsg = { severity: severity, summary: type, detail :data, life: duration, group:toastgroup}
54
+ toast.add(resmsg)
55
+ }
56
+
57
+
58
+ })
59
+ const prepareMsg=(data:any,msgtype:string):string=>{
60
+ let res : string =''
61
+
62
+ if(typeof data == 'string'){
63
+ res = data
64
+ }else if(Array.isArray(data)){
65
+ res+='<ul>'
66
+ for(let i=0;i<data.length;i++){
67
+ const d=data[i]
68
+ res+= '<li>'+d['instancePath']+':'+(d['message']?? JSON.stringify(d))+'</li>'
69
+ }
70
+ res+='</ul>'
71
+ }else if(typeof data =='object'){
72
+ res=JSON.stringify(data)
73
+ }
74
+ return res
75
+
76
+
77
+ }
78
+
79
+ </script>
@@ -0,0 +1,8 @@
1
+ <template>
2
+ <header>
3
+ <MegaMenu :model="getMenus()" orientation="horizontal" />
4
+ </header>
5
+ </template>
6
+ <script setup lang="ts">
7
+ import MegaMenu from 'primevue/megamenu';
8
+ </script>
@@ -0,0 +1,24 @@
1
+
2
+ import * as o from "../simpleapp/openapi";
3
+
4
+ const getAutoComplete = (apiname: string): any => {
5
+ const config: o.Configuration = {
6
+ basePath: useRuntimeConfig().public.APP_URL + "/api",
7
+ isJsonMime: () => true,
8
+ };
9
+ const docsOpenapi: any = {
10
+ <% for(let i=0;i<it.length; i++){ %>
11
+ <% let obj = it[i]%>
12
+ '<%=obj.docname.toLowerCase()%>' : new o.<%=obj.doctype.toUpperCase()%>Api(config),
13
+ <%}%>
14
+ };
15
+ if (!docsOpenapi[apiname]) {
16
+ console.error(
17
+ `api for '${apiname}' does not exists, most probably define wrong x-foreignkey`,
18
+ );
19
+ return undefined;
20
+ } else {
21
+ return docsOpenapi[apiname];
22
+ }
23
+ };
24
+ export default getAutoComplete;
@@ -0,0 +1,8 @@
1
+ export const getMenus =()=>
2
+ [
3
+ {label: 'Home',icon: 'pi pi-fw pi-home',to: '/'},
4
+ <% for(let i=0;i<it.length; i++){ %>
5
+ <% let obj = it[i]%>
6
+ {label: '<%=obj.docname.toLowerCase()%>', to:'/<%=obj.docname.toLowerCase()%>'},
7
+ <%}%>
8
+ ]
@@ -0,0 +1,3 @@
1
+ PORT=8800
2
+ SIMPLEAPP_BACKEND_URL=http://localhost:8000
3
+ APP_URL=http://localhost:8800
@@ -0,0 +1,10 @@
1
+
2
+ <template>
3
+ <div>
4
+ <Menus />
5
+ <slot></slot>
6
+ </div>
7
+ </template>
8
+ <script lang="ts" setup>
9
+ import Menus from '~/components/Menus.vue'
10
+ </script>
@@ -3,6 +3,7 @@ export default defineNuxtConfig({
3
3
  runtimeConfig:{
4
4
  public:{
5
5
  SIMPLEAPP_BACKEND_URL: process.env.SIMPLEAPP_BACKEND_URL,
6
+ APP_URL: process.env.APP_URL,
6
7
  }
7
8
  },
8
9
  vite: {
@@ -13,14 +14,16 @@ export default defineNuxtConfig({
13
14
  }
14
15
  }
15
16
  },
17
+ tailwindcss: {
18
+ // Options
19
+ },
16
20
  modules: [
17
- // '@nuxtjs/tailwindcss',
21
+ '@nuxtjs/tailwindcss',
18
22
  // '@nuxtjs/color-mode'
19
23
 
20
24
  ],
21
- ssr: false,
25
+ ssr: true,
22
26
  css: [
23
- // "assets/css/index.css",
24
27
  "primevue/resources/themes/lara-light-blue/theme.css",
25
28
  'primeicons/primeicons.css'
26
29
  ],
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <div>index page</div>
3
+ </template>
@@ -1,4 +1,3 @@
1
-
2
1
  import { defineNuxtPlugin } from "#app";
3
2
  import PrimeVue from "primevue/config";
4
3
  import SimpleAppAutocomplete from '@simitgroup/simpleapp-vue-component/src/components/SimpleAppAutocomplete.vue'
@@ -23,8 +22,12 @@ import SimpleAppText from '@simitgroup/simpleapp-vue-component/src/components/Si
23
22
  import SimpleAppTextarea from '@simitgroup/simpleapp-vue-component/src/components/SimpleAppTextarea.vue'
24
23
  import SimpleAppValue from '@simitgroup/simpleapp-vue-component/src/components/SimpleAppValue.vue'
25
24
  import SimpleFieldContainer from '@simitgroup/simpleapp-vue-component/src/components/SimpleFieldContainer.vue'
25
+ import SimpleAppDatatable from '@simitgroup/simpleapp-vue-component/src/components/SimpleAppDatatable.vue'
26
+ import mitt from 'mitt'
27
+ import ToastService from 'primevue/toastservice';
28
+ import ConfirmationService from 'primevue/confirmationservice';
26
29
 
27
-
30
+ const emitter = mitt()
28
31
 
29
32
 
30
33
 
@@ -53,6 +56,13 @@ export default defineNuxtPlugin((nuxtApp) => {
53
56
  .component("SimpleAppTextarea",SimpleAppTextarea)
54
57
  .component("SimpleAppValue",SimpleAppValue)
55
58
  .component("SimpleFieldContainer",SimpleFieldContainer)
59
+ .use(ToastService).use(ConfirmationService)
56
60
  ;
61
+ return {
62
+ provide: {
63
+ event: emitter.emit, // Will emit an event
64
+ listen: emitter.on // Will register a listener for an event
65
+ }
66
+ }
57
67
  //other components that you need
58
68
  });
@@ -0,0 +1,131 @@
1
+ import axios from 'axios';
2
+ // import { getServerSession } from '#auth'
3
+ // import type { Session } from 'next-auth';
4
+
5
+ export default defineEventHandler(async (event) => {
6
+ // let session: Session | null = null
7
+ // try {
8
+ // session = await getServerSession(event)
9
+ // } catch (error) {
10
+ // return sendRedirect(event, '/login', 401)
11
+ // }
12
+
13
+ return new Promise<any>(async (resolve, reject) => {
14
+ // if(!session || !session.accessToken) {
15
+ // reject({ statusMessage: 'Unauthorized', statusCode: 401 });
16
+ // throw createError({ statusMessage: 'Unauthorized', statusCode: 401 })
17
+ // }
18
+ // console.log("------hihi------")
19
+ const seperateSymbol = '.';
20
+ // const seperateSymbol = '&';
21
+ const key = event.context.params?.key ?? ''
22
+ const platform = event.context.params?.platform ?? ''
23
+ const otherLink = event.context.params?._ ?? ''
24
+
25
+ // console.error("event.context???",event.context)
26
+ // const accessToken = session?.accessToken;
27
+
28
+ // const allowPlatform = ['report-api', 'cloudapi'];
29
+ // if(!key || !platform || !allowPlatform.includes(platform) || !accessToken) {
30
+ // reject({ statusMessage: 'Unauthorized', statusCode: 401 });
31
+ // // throw createError({ statusMessage: 'Unauthorized', statusCode: 401 })
32
+ // }
33
+
34
+ // let tenantKey = '', organizationKey = '';
35
+ // let xOrg = '';
36
+
37
+ // if(key !== 'system') {
38
+ // [tenantKey, organizationKey] = key.split(seperateSymbol);
39
+ // xOrg = `${tenantKey}/${organizationKey}/`;
40
+ // }
41
+
42
+ // if(key === 'system' && platform == 'cloudapi') {
43
+ // // xOrg = 'MC0wLTA'
44
+ // }
45
+
46
+ let forwardData: any = {};
47
+
48
+ const req = event.node.req;
49
+
50
+ if(req.method == 'POST' || req.method == 'PUT') {
51
+
52
+ forwardData = await readBody(event);
53
+ } else {
54
+ forwardData = getQuery(event);
55
+ }
56
+
57
+ // if(typeof forwardData === "object" && "_branch" in forwardData) {
58
+ // xOrg = xOrg + forwardData._branch;
59
+ // delete forwardData._branch;
60
+ // }
61
+
62
+ const frontEndRes = event.node.res;
63
+ const url = process.env.SIMPLEAPP_BACKEND_URL +platform + '/' + otherLink;
64
+ // console.warn('backend server-----',req.method,url,forwardData)
65
+ const axiosConfig: any = {
66
+ method: req.method,
67
+ url: url,
68
+ headers: {
69
+ // Authorization: `Bearer ${accessToken}`,
70
+ // 'X-Org': `${xOrg}`,
71
+ },
72
+ data: forwardData,
73
+ params: forwardData,
74
+ }
75
+
76
+ // if(key === 'system') {
77
+ // axiosConfig.headers["X-Global"] = true;
78
+ // delete axiosConfig.headers["X-Org"];
79
+ // }
80
+
81
+ // if(otherLink.includes('avatar')) {
82
+ // axiosConfig.responseType = 'arraybuffer';
83
+ // // axiosConfig.headers['Acceptable'] = 'text/html,image/avif,image/webp,image/apng';
84
+ // }
85
+
86
+ axios(axiosConfig).then((res) => {
87
+ if (res.headers['content-type'] === 'image/png') {
88
+ // Set the response headers for the image
89
+ frontEndRes.setHeader('Content-Type', 'image/png');
90
+ frontEndRes.setHeader('Content-Disposition', 'inline');
91
+
92
+ // Send the image data as the response body
93
+ frontEndRes.end(Buffer.from(res.data, 'binary'));
94
+ } else {
95
+ // For non-image responses, set the Content-Type header and send the response body
96
+ // setHeader(event, 'Content-type', <string>res.headers['Content-Type']);
97
+
98
+ frontEndRes.statusCode = res.status;
99
+ if(res.statusText) {
100
+ frontEndRes.statusMessage = res.statusText;
101
+ }
102
+
103
+ resolve(res.data);
104
+ }
105
+
106
+ }).catch((error) => {
107
+ // console.log("==============================================================")
108
+ // console.log('@@@@@@@@@@@@@ API error', error)
109
+ // console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
110
+ // console.log('######### response', error.response)
111
+ // console.log('#####################################')
112
+ // console.log(axiosConfig);
113
+ // console.log('#####################################')
114
+
115
+ if (error.response?.status && error.response.status == '401') {
116
+ return reject({ statusMessage: 'Unauthorized', statusCode: 401 });
117
+ // throw createError({ statusMessage: 'Unauthorized', statusCode: 401 })
118
+ }
119
+
120
+ // reject(error.data)
121
+ reject({ statusMessage: error.response.statusText, statusCode: error.response.status });
122
+ // resolve({ status: 'ok' })
123
+ // throw createError({ statusMessage: 'Bad Requests', statusCode: 404 })
124
+ })
125
+
126
+ // resolve({
127
+ // status: 'ok'
128
+ // })
129
+ })
130
+
131
+ })
@@ -0,0 +1,9 @@
1
+ import type { Config } from 'tailwindcss'
2
+
3
+ // Default are on https://tailwindcss.nuxtjs.org/tailwind/config#default-configuration
4
+ export default <Partial<Config>>{
5
+ theme: {},
6
+ plugins: [],
7
+ content: [],
8
+ darkMode: 'class',
9
+ }
@@ -0,0 +1,28 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+ button {
6
+ @apply p-2 border-2
7
+ }
8
+
9
+ .input-error{
10
+ @apply text-red-500
11
+ }
12
+ .simpleapp-tool-bar button{
13
+ margin-right: 1rem;
14
+ }
15
+
16
+ .bg-primary{
17
+ @apply bg-green-600 text-white
18
+
19
+ }
20
+ .bg-default{
21
+ @apply bg-white
22
+ }
23
+ .bg-danger{
24
+ @apply bg-red-500 text-white
25
+ }
26
+ .bg-warning{
27
+ @apply bg-orange-600 text-white
28
+ }
@@ -1,2 +0,0 @@
1
- PORT=8800
2
- SIMPLEAPP_BACKEND_URL=http://localhost:8000