@simitgroup/simpleapp-generator 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simitgroup/simpleapp-generator",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "frontend nuxtjs and backend nests code generator using jsonschema",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -12,7 +12,7 @@
12
12
  <script setup lang="ts">
13
13
  /**
14
14
  * This file was automatically generated by simpleapp everytime regenerate code.
15
- * delete file "delete-me-for-avoid-override" if you want to modify this file and
15
+ * delete file "delete-me.txt" if you want to modify this file and
16
16
  * prevent regenerate code override it.
17
17
  * last change 2023-09-09
18
18
  * author: Ks Tan
@@ -17,7 +17,7 @@ import { catchError, tap } from 'rxjs/operators';
17
17
  import { Model, Connection, ClientSession } from 'mongoose';
18
18
  import { InjectConnection, InjectModel } from '@nestjs/mongoose';
19
19
  import { UserContext } from '../user.context';
20
- import { ApiEvent } from '../../types/apievent.type';
20
+ import { ApiEvent } from '../../types';
21
21
  @Injectable()
22
22
  export class ResponseInterceptor implements NestInterceptor {
23
23
  constructor(
@@ -7,7 +7,8 @@
7
7
  import { Injectable, Logger, Inject } from '@nestjs/common';
8
8
  import { InjectModel } from '@nestjs/mongoose';
9
9
  import jsonpath from 'jsonpath';
10
- import { uniq } from 'lodash';
10
+ import _ from 'lodash';
11
+
11
12
  import { AuditTrail } from '../commons/audittrail.service';
12
13
  import { foreignkeys } from '../commons/dicts/foreignkeys';
13
14
  import { EventEmitter2 } from '@nestjs/event-emitter';
@@ -77,7 +78,7 @@ export class SimpleAppService<T extends { _id?: string }> {
77
78
  // this.tenantdoc = tenantdoc
78
79
  }
79
80
  getDocumentType = () => this.documentType;
80
- getDocumentName = () => this.documentName;
81
+ getDocumentName = (capFirst:boolean=false) => capFirst ? _.upperFirst(this.documentName) :this.documentName;
81
82
  getRecordId = (): string => this.data._id;
82
83
  setSchema = (newschema) => (this.jsonschema = newschema);
83
84
  getSchema = () => this.doc.schema.obj;
@@ -297,7 +298,7 @@ export class SimpleAppService<T extends { _id?: string }> {
297
298
  this.logger.debug(data, 'SimpleAppService');
298
299
  Object.assign(data, isolationFilter);
299
300
  this.reCalculateValue(data);
300
- await this.validateData(appuser, data);
301
+ await this.validateData(appuser, data);
301
302
  this.logger.debug(data, `after create validation`);
302
303
  this.applyNestedDateTime(appuser, data, 'create');
303
304
  this.logger.debug(data, `Create Record ${this.documentName}`);
@@ -378,7 +379,7 @@ export class SimpleAppService<T extends { _id?: string }> {
378
379
  for (let i = 0; i < this.errorlist.length; i++) {
379
380
  errormsg.push(this.errorlist[i].message);
380
381
  }
381
-
382
+
382
383
  throw new BadRequestException(
383
384
  'Before validation hook failed',
384
385
  errormsg as HttpExceptionOptions,
@@ -678,7 +679,7 @@ export class SimpleAppService<T extends { _id?: string }> {
678
679
 
679
680
  if (results.length > 0) {
680
681
  if (results.length > 1) {
681
- results = uniq<string>(results);
682
+ results = _.uniq<string>(results);
682
683
  }
683
684
 
684
685
  keystore[collectionname] = results;
@@ -21,16 +21,15 @@
21
21
  <div v-else class="p-3 border rounded-lg border-gray-300 dark:border-blue-900/40 ">
22
22
  <span :readonly="readonly" class="cursor-pointer text-primary-600 dark:text-primary-400 "
23
23
  tabindex="0" @click="openViewer(true)">{{ modelValue && modelValue.label ? modelValue.label:'-' }}</span>
24
- </div>
24
+ </div>
25
25
  </template>
26
26
  <script setup lang="ts">
27
27
  import { isNull } from 'lodash';
28
+ import * as jsonpath from 'jsonpath';
28
29
  import {autocompletetype,SchemaConfig,SchemaType} from '~/types'
29
30
  const autocompleteinput = ref()
30
31
  const {$event} = useNuxtApp()
31
32
  const list = ref<any[]>([])
32
- const emptyautocomplete =():autocompletetype=> ({_id:'',code:'',label:''})
33
-
34
33
  const props = withDefaults(defineProps<{
35
34
  setting:any
36
35
  allowAddNew?:boolean
@@ -41,15 +40,22 @@ const props = withDefaults(defineProps<{
41
40
  }>(),{
42
41
  allowAddNew:true,showNull:true
43
42
  })
44
- const autocompleteitem = ref<autocompletetype>(emptyautocomplete())
43
+
44
+ const path = '$'+props.setting.instancepath
45
+ const modifiedpath = path.replaceAll('/','.')
46
+ const queryresult = jsonpath.query(props.setting.defaultValue,modifiedpath)[0]
47
+
48
+ const emptyautocomplete = computed(():autocompletetype=> queryresult)
49
+
50
+ const autocompleteitem = ref<autocompletetype>(emptyautocomplete.value)
45
51
  const modelValue = defineModel<autocompletetype>()
46
52
  if(modelValue.value && modelValue.value._id){
47
53
  autocompleteitem.value={...modelValue.value}
48
54
  }
49
55
  //clear auto complete auto set value = empty
50
56
  const clear = ()=>{
51
- autocompleteitem.value = emptyautocomplete()
52
- modelValue.value = emptyautocomplete()
57
+ autocompleteitem.value = emptyautocomplete.value
58
+ modelValue.value = emptyautocomplete.value
53
59
  }
54
60
  const buttonClass=computed(()=>modelValue.value?._id ? 'pi pi-link' : 'pi pi-angle-down')
55
61
 
@@ -63,7 +69,7 @@ const beforeShow = ()=>{
63
69
  //recorrect data if lose focus
64
70
  const onBlurAutocomplete = ()=>{
65
71
  if( autocompleteitem.value === null){
66
- autocompleteitem.value = emptyautocomplete()
72
+ autocompleteitem.value = emptyautocomplete.value
67
73
  }
68
74
  if(isNull(modelValue.value )){
69
75
  modelValue.value = autocompleteitem.value
@@ -94,13 +100,13 @@ const pickAutoComplete = (event:any)=>{
94
100
  console.log("event",event,'event.value._id',"'"+event.value._id+"'")
95
101
  if(event.value._id===''){
96
102
 
97
- modelValue.value = emptyautocomplete()
98
- autocompleteitem.value = emptyautocomplete()
103
+ modelValue.value = emptyautocomplete.value
104
+ autocompleteitem.value = emptyautocomplete.value
99
105
  console.log(modelValue.value )
100
106
  } else if(event.value._id==='new'){
101
107
 
102
- modelValue.value = emptyautocomplete()
103
- autocompleteitem.value = emptyautocomplete()
108
+ modelValue.value = emptyautocomplete.value
109
+ autocompleteitem.value = emptyautocomplete.value
104
110
  openViewer(false)
105
111
  }
106
112
  else if(typeof event.value.query == 'undefined'){
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <form class="simpleapp-form" @submit.prevent="true">
2
+ <form class="simpleapp-form" @submit.prevent="true">
3
3
  <slot name="header"><h3 class="flex flex-col">{{ title }}</h3></slot>
4
4
  <slot name="default" :data="document.getData()" :getField="getField"></slot>
5
5
  </form>
@@ -9,7 +9,8 @@
9
9
  import * as jsonpath from 'jsonpath';
10
10
  import { SimpleAppClient } from '~/simpleapp/generate/clients/SimpleAppClient'
11
11
  import type { JSONSchema7,JSONSchema7Definition } from 'json-schema';
12
- import _ from 'lodash'
12
+ import * as alldefaults from '~/simpleapp/generate/defaults'
13
+ import _, { upperFirst } from 'lodash'
13
14
  const props = defineProps<{
14
15
  title?:string,
15
16
  document: SimpleAppClient<any,any>
@@ -29,7 +30,11 @@ import _ from 'lodash'
29
30
  const fieldsetting = getPathObject(schema,path)
30
31
  // console.log("setting",fieldsetting)
31
32
 
33
+ type defaulttype = typeof alldefaults
34
+ type keytype = keyof defaulttype
32
35
 
36
+ const x : keytype = 'Default'+ props.document.getDocName(true) as keytype
37
+ const defaultvalue = alldefaults[x](crypto.randomUUID())
33
38
  return {
34
39
  path: path,
35
40
  key: _.last(path.split('/')),
@@ -41,15 +46,13 @@ import _ from 'lodash'
41
46
  modelField: 'email',
42
47
  isrequired: getIsRequired(schema,path),
43
48
  errors: props.document.getErrors(),
44
- readonly: isreadonly.value
49
+ readonly: isreadonly.value,
50
+ defaultValue: defaultvalue
45
51
  } //as SimpleAppFieldSetting
46
52
  }
47
53
 
48
54
  // "schemaPath": "#/properties/email/format",
49
55
 
50
- const getModelValue=(data:any,path:string)=>{
51
-
52
- }
53
56
  const getIsRequired=(schema:any,path:string)=>{
54
57
  if(!path){
55
58
  console.error('unknown path')
@@ -1,4 +1,6 @@
1
1
  import plugin from 'primevue/config';
2
+ import _ from 'lodash'
3
+
2
4
  import {Md5} from 'ts-md5'
3
5
  import moment from "moment";
4
6
  export const camelCaseToWords = (s: string) =>{
@@ -19,4 +21,5 @@ export const t = (txt:string,options?:any):string => useNuxtApp().$i18n.t(txt,op
19
21
  export const today = () => moment().format('YYYY-MM-DD')
20
22
  export const dateToString = (date:Date) => moment(date).format('YYYY-MM-DD')
21
23
  export const getMoment = (startTime:string)=> moment(startTime)
22
- export const lastDateOfMonth = (datestr:string) => moment(datestr).endOf('month').format('YYYY-MM-DD');
24
+ export const lastDateOfMonth = (datestr:string) => moment(datestr).endOf('month').format('YYYY-MM-DD');
25
+ export const upperFirst = (str:string) => _.upperFirst(str)
@@ -45,7 +45,7 @@ export class SimpleAppClient<
45
45
  }
46
46
 
47
47
  getDocType = () => this.doctype;
48
- getDocName = () => this.docname;
48
+ getDocName = (capFirst:boolean=false) => capFirst ? upperFirst(this.docname) :this.docname;
49
49
  setNew = ()=>{}
50
50
  isNew = () => this.data.value?.created==''
51
51
  setSchema = (schema: SchemaType) => (this.schema = schema);
@@ -0,0 +1,4 @@
1
+ <%for(let i=0; i<it.modules.length;i++){ %>
2
+ <% const d = it.modules[i] %>
3
+ export {Default<%= d['docname']%>} from './<%= d['docname']%>.default'
4
+ <%}%>