@simitgroup/simpleapp-generator 1.6.6-m-alpha → 1.6.6-n-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.
Files changed (49) hide show
  1. package/ReleaseNote.md +4 -0
  2. package/dist/buildinschemas/customfield.js +1 -1
  3. package/dist/buildinschemas/customfield.js.map +1 -1
  4. package/dist/buildinschemas/index.d.ts +1 -0
  5. package/dist/buildinschemas/index.d.ts.map +1 -1
  6. package/dist/buildinschemas/index.js +3 -2
  7. package/dist/buildinschemas/index.js.map +1 -1
  8. package/dist/framework.d.ts.map +1 -1
  9. package/dist/framework.js +2 -1
  10. package/dist/framework.js.map +1 -1
  11. package/dist/generate.d.ts.map +1 -1
  12. package/dist/generate.js +0 -5
  13. package/dist/generate.js.map +1 -1
  14. package/dist/processors/jsonschemabuilder.d.ts.map +1 -1
  15. package/dist/processors/jsonschemabuilder.js +75 -35
  16. package/dist/processors/jsonschemabuilder.js.map +1 -1
  17. package/dist/type.d.ts +1 -0
  18. package/dist/type.d.ts.map +1 -1
  19. package/dist/type.js.map +1 -1
  20. package/package.json +1 -1
  21. package/reset-install.sh +2 -1
  22. package/src/buildinschemas/customfield.ts +47 -0
  23. package/src/buildinschemas/index.ts +11 -11
  24. package/src/framework.ts +2 -0
  25. package/src/processors/jsonschemabuilder.ts +268 -192
  26. package/src/type.ts +3 -2
  27. package/templates/basic/nest/apischema.ts.eta +33 -22
  28. package/templates/basic/nest/default.ts.eta +6 -1
  29. package/templates/basic/nest/type.ts.eta +9 -5
  30. package/templates/basic/nuxt/default.ts.eta +7 -1
  31. package/templates/basic/nuxt/pages.form.vue.eta +5 -3
  32. package/templates/basic/nuxt/simpleapp.generate.client.ts.eta +70 -32
  33. package/templates/nest/src/enums/enums.generate.ts.eta +23 -0
  34. package/templates/nest/src/simpleapp/generate/apischemas/simpleapp.apischema.ts.eta +7 -1
  35. package/templates/nest/src/simpleapp/generate/types/simpleapp.type.ts.eta +7 -1
  36. package/templates/nuxt/components/simpleApp/SimpleAppForm.vue.eta +8 -0
  37. package/templates/nuxt/components/simpleApp/SimpleAppInput.vue.eta +15 -2
  38. package/templates/nuxt/components/simpleApp/SimpleAppInputTable.vue.eta +6 -1
  39. package/templates/nuxt/composables/getUserStore.generate.ts.eta +4 -0
  40. package/templates/nuxt/enums/enums.generate.ts.eta +23 -0
  41. package/templates/nuxt/i18n/lang/cn.ts._eta +15 -0
  42. package/templates/nuxt/i18n/lang/en.ts.eta +19 -0
  43. package/templates/nuxt/lang/en.ts.eta +1 -1
  44. package/templates/nuxt/plugins/18.simpleapp-custom-field-store.ts.eta +38 -0
  45. package/templates/nuxt/plugins/19.app-plugins.ts.eta +422 -0
  46. package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +8 -1
  47. package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +249 -213
  48. package/templates/nuxt/simpleapp/generate/clients/SimpleAppCustomFieldClient.ts.eta +191 -0
  49. package/templates/nuxt/types/schema.ts.eta +19 -2
@@ -0,0 +1,47 @@
1
+ import { IsolationType, SchemaType } from '../type';
2
+
3
+ export const customfield: SchemaType = {
4
+ type: 'object',
5
+ 'x-simpleapp-config': {
6
+ documentType: 'customfield',
7
+ documentName: 'customfield',
8
+ isolationType: IsolationType.tenant,
9
+ uniqueKey: 'collectionName',
10
+ documentTitle: 'collectionName'
11
+ },
12
+ properties: {
13
+ _id: { type: 'string' },
14
+ created: { type: 'string' },
15
+ updated: { type: 'string' },
16
+ createdBy: { type: 'string' },
17
+ updatedBy: { type: 'string' },
18
+ tenantId: { type: 'integer', default: 1 },
19
+ orgId: { type: 'integer', default: 1 },
20
+ branchId: { type: 'integer', default: 1 },
21
+ collectionName: {
22
+ type: 'string',
23
+ minLength: 2
24
+ },
25
+ form: {
26
+ type: 'object',
27
+ properties: {
28
+ schema: {
29
+ type: 'object',
30
+ properties: {},
31
+ examples: [
32
+ {
33
+ type: 'object',
34
+ required: ['hello'],
35
+ properties: {
36
+ hello: {
37
+ type: 'string',
38
+ minLength: 2,
39
+ }
40
+ }
41
+ }
42
+ ]
43
+ }
44
+ }
45
+ }
46
+ }
47
+ };
@@ -1,11 +1,11 @@
1
- export {tenant} from './tenant'
2
- export {organization} from './organization'
3
- export {branch} from './branch'
4
- export {permission} from './permission'
5
- // export {user} from './user'
6
- export {autoincreament} from './autoincreament'
7
- export {docnoformat} from './docnoformat'
8
- export {systemmessage} from './systemmessage'
9
- export {keyvaluepair} from './keyvaluepair'
10
- export {webhook} from './webhook'
11
- export {documentevent} from './documentevent'
1
+ export { tenant } from './tenant';
2
+ export { organization } from './organization';
3
+ export { branch } from './branch';
4
+ export { permission } from './permission';
5
+ export { autoincreament } from './autoincreament';
6
+ export { docnoformat } from './docnoformat';
7
+ export { systemmessage } from './systemmessage';
8
+ export { keyvaluepair } from './keyvaluepair';
9
+ export { webhook } from './webhook';
10
+ export { documentevent } from './documentevent';
11
+ export { customfield } from './customfield';
package/src/framework.ts CHANGED
@@ -257,6 +257,8 @@ export const prettyNuxt = ()=>{
257
257
  console.log("Formatting Nuxt...");
258
258
  prepareOpenApiClient()
259
259
  exec(`cd ${config.frontendFolder};npx prettier --write "./pages/**/*.vue" "./components/**/*.vue" "./generate/*/*.ts" `)
260
+ exec(`npx prettier --write ${config.frontendFolder}/simpleapp/generate/clients/*.ts`)
261
+
260
262
 
261
263
  }
262
264
  export const prettyNest = ()=>{
@@ -1,13 +1,19 @@
1
1
  // import { ExceptionsHandler } from '@nestjs/core/exceptions/exceptions-handler';
2
- import { JSONSchema7, JSONSchema7Definition,JSONSchema7Array,JSONSchema7TypeName, JSONSchema7Object } from 'json-schema';
2
+ import {
3
+ JSONSchema7,
4
+ JSONSchema7Definition,
5
+ JSONSchema7Array,
6
+ JSONSchema7TypeName,
7
+ JSONSchema7Object
8
+ } from 'json-schema';
3
9
  import * as js7 from 'json-schema';
4
- import _ from 'lodash'
10
+ import _ from 'lodash';
5
11
  import { capitalizeFirstLetter } from '../libs';
6
- import {SchemaType,SchemaConfig,JsonSchemaProperties} from "../type"
12
+ import { SchemaType, SchemaConfig, JsonSchemaProperties } from '../type';
7
13
  // import * as schematemplates from '../schematype'
8
- import { Logger, ILogObj } from "tslog";
9
- import $RefParser from "@apidevtools/json-schema-ref-parser";
10
- import {allforeignkeys,allfields} from '../storage'
14
+ import { Logger, ILogObj } from 'tslog';
15
+ import $RefParser from '@apidevtools/json-schema-ref-parser';
16
+ import { allforeignkeys, allfields } from '../storage';
11
17
  // import { ConflictException } from '@nestjs/common';
12
18
  import {
13
19
  FieldModel,
@@ -15,96 +21,119 @@ import {
15
21
  ChildModels,
16
22
  SchemaModel,
17
23
  TypeForeignKey,
18
- TypeForeignKeyCatalogue,
24
+ TypeForeignKeyCatalogue
19
25
  } from '../type';
20
26
  const log: Logger<ILogObj> = new Logger();
21
- const configname = "x-simpleapp-config"
22
- const FOREIGNKEY_PROPERTY = 'x-foreignkey'
23
- export const readJsonSchemaBuilder = async (docname: string,orijsondata:JSONSchema7,
27
+ const configname = 'x-simpleapp-config';
28
+ const FOREIGNKEY_PROPERTY = 'x-foreignkey';
29
+ export const readJsonSchemaBuilder = async (
30
+ docname: string,
31
+ orijsondata: JSONSchema7
24
32
  ) => {
25
33
  // log.info(`----------------------------------------------------`)
26
34
  // log.error(`Processing schema ${docname}`)
27
35
  //validation
28
- if(!orijsondata[configname]) throw new Error(`Undefine ${configname}`)
29
- if(!orijsondata[configname]) throw new Error(`Undefine ${configname}`)
36
+ if (!orijsondata[configname]) throw new Error(`Undefine ${configname}`);
37
+ if (!orijsondata[configname]) throw new Error(`Undefine ${configname}`);
30
38
  // // Object.assign(targettemplate,schematemplates[currentschematype])
31
39
  // console.log("just want process schemaprops ********>>",targettemplate)
32
-
33
- let schemaconfigs:SchemaConfig = orijsondata[configname]
34
- const doctype=schemaconfigs.documentType
35
40
 
36
- if(!schemaconfigs.collectionName){
37
- schemaconfigs.documentName
41
+ let schemaconfigs: SchemaConfig = orijsondata[configname];
42
+ const doctype = schemaconfigs.documentType;
43
+
44
+ if (!schemaconfigs.collectionName) {
45
+ schemaconfigs.documentName;
38
46
  }
39
47
 
40
- if(!schemaconfigs.foreignKeys){
41
- schemaconfigs.foreignKeys={}
48
+ if (!schemaconfigs.foreignKeys) {
49
+ schemaconfigs.foreignKeys = {};
42
50
  }
43
51
 
44
- if(schemaconfigs.generateDocumentNumber){
45
- if(!schemaconfigs.docNoPattern){
46
- log.error(docname+" generateDocumentNumber=true but undefine docNoPattern")
47
- throw new Error(docname+" generateDocumentNumber=true but undefine docNoPattern")
52
+ if (schemaconfigs.generateDocumentNumber) {
53
+ if (!schemaconfigs.docNoPattern) {
54
+ log.error(
55
+ docname + ' generateDocumentNumber=true but undefine docNoPattern'
56
+ );
57
+ throw new Error(
58
+ docname + ' generateDocumentNumber=true but undefine docNoPattern'
59
+ );
48
60
  }
49
61
  const tmp = {
50
- type: "object",
51
- "x-foreignkey":"docnoformat",
52
- properties: {_id: {type: "string"},label: {type: "string"}}
53
- }
54
- orijsondata.properties["docNoFormat"] = tmp as JSONSchema7Definition
62
+ type: 'object',
63
+ 'x-foreignkey': 'docnoformat',
64
+ properties: { _id: { type: 'string' }, label: { type: 'string' } }
65
+ };
66
+ orijsondata.properties['docNoFormat'] = tmp as JSONSchema7Definition;
55
67
  }
56
68
 
57
- if(schemaconfigs.allStatus && schemaconfigs.allStatus.length>0){
58
- orijsondata.properties["documentStatus"] = {type:'string', default:'draft'}
69
+ if (schemaconfigs.allStatus && schemaconfigs.allStatus.length > 0) {
70
+ orijsondata.properties['documentStatus'] = {
71
+ type: 'string',
72
+ default: 'draft'
73
+ };
59
74
  }
60
75
 
61
- if(schemaconfigs.additionalApis && schemaconfigs.additionalApis.length>0){
62
- const apis = schemaconfigs.additionalApis
63
- for(let i =0 ; i< apis.length; i++ ){
64
- if(!apis[i].responseType){
65
- log.error(docname +" undefine responseType in api "+ apis[i].action)
66
- throw new Error(docname+ " undefine responseType in api "+ apis[i].action)
76
+ if (schemaconfigs.additionalApis && schemaconfigs.additionalApis.length > 0) {
77
+ const apis = schemaconfigs.additionalApis;
78
+ for (let i = 0; i < apis.length; i++) {
79
+ if (!apis[i].responseType) {
80
+ log.error(docname + ' undefine responseType in api ' + apis[i].action);
81
+ throw new Error(
82
+ docname + ' undefine responseType in api ' + apis[i].action
83
+ );
67
84
  }
68
- if(!Array.isArray(apis[i].requiredRole) || apis[i].requiredRole.length==0 ){
69
- log.error(docname+ " undefine requiredRole in api "+ apis[i].action)
70
- throw new Error(docname +" undefine requiredRole in api "+ apis[i].action)
85
+ if (
86
+ !Array.isArray(apis[i].requiredRole) ||
87
+ apis[i].requiredRole.length == 0
88
+ ) {
89
+ log.error(docname + ' undefine requiredRole in api ' + apis[i].action);
90
+ throw new Error(
91
+ docname + ' undefine requiredRole in api ' + apis[i].action
92
+ );
71
93
  }
72
94
  }
73
95
  }
74
-
96
+
75
97
  //ensure all important field exists
76
- const compulsoryfields = ['_id','tenantId','orgId','branchId','created','createdBy','updated','updatedBy']
77
- for(let cf=0 ; cf< compulsoryfields.length;cf++){
78
- if(!orijsondata.properties[compulsoryfields[cf]]){
79
- log.error("Undefine "+ compulsoryfields[cf])
80
- throw new Error("Undefine "+ compulsoryfields[cf])
98
+ const compulsoryfields = [
99
+ '_id',
100
+ 'tenantId',
101
+ 'orgId',
102
+ 'branchId',
103
+ 'created',
104
+ 'createdBy',
105
+ 'updated',
106
+ 'updatedBy'
107
+ ];
108
+ for (let cf = 0; cf < compulsoryfields.length; cf++) {
109
+ if (!orijsondata.properties[compulsoryfields[cf]]) {
110
+ log.error('Undefine ' + compulsoryfields[cf]);
111
+ throw new Error('Undefine ' + compulsoryfields[cf]);
81
112
  }
82
113
  }
83
114
 
84
115
  //enforce format uuid for _id
85
- orijsondata.properties['_id']['format']='uuid'
86
-
87
-
116
+ orijsondata.properties['_id']['format'] = 'uuid';
88
117
 
89
118
  // let newschema:JSONSchema7 & SchemaType = {
90
119
  // type: 'object',
91
120
  // "x-simpleapp-config":schemaconfigs,
92
121
  // properties:schemaprops,
93
122
  // definitions:schemadefinitions
94
-
123
+
95
124
  // }
96
125
  // log.warn("------------------")
97
126
  // log.warn(newschema)
98
127
  // dereference in case implement remote schema
99
128
  // console.log("before dereference jsondata.properties =======---",newschema)
100
- const tmpjsondata = await $RefParser.dereference(orijsondata).then((tmp)=>{
101
- return tmp
102
- })
129
+ const tmpjsondata = await $RefParser.dereference(orijsondata).then((tmp) => {
130
+ return tmp;
131
+ });
103
132
  // console.log("First level jsondata.properties =======++",tmpjsondata)
104
133
  // log.info(tmpjsondata,`==========================${schemaconfigs.documentType}==========================`)
105
- const jsondata:JSONSchema7 = {...tmpjsondata} as JSONSchema7
134
+ const jsondata: JSONSchema7 = { ...tmpjsondata } as JSONSchema7;
106
135
  let allmodels: ChildModels = {};
107
-
136
+
108
137
  await genSchema(
109
138
  schemaconfigs.documentName,
110
139
  'object',
@@ -113,178 +142,225 @@ export const readJsonSchemaBuilder = async (docname: string,orijsondata:JSONSche
113
142
  '$',
114
143
  schemaconfigs,
115
144
  allmodels,
116
- ""
145
+ '',
146
+ {}
117
147
  );
118
- return allmodels
148
+ return allmodels;
119
149
  };
120
150
 
121
-
122
151
  /**
123
152
  * process recursively every property in schema
124
- * @param SchemaConfig
125
- * @param parentName
126
- * @param schematype
127
- * @param jsondata
128
- * @param requiredlist
129
- * @param parentpath
153
+ * @param SchemaConfig
154
+ * @param parentName
155
+ * @param schematype
156
+ * @param jsondata
157
+ * @param requiredlist
158
+ * @param parentpath
130
159
  * @param schemaconfigs
131
- * @returns
160
+ * @returns
132
161
  */
133
162
  const genSchema = async (
134
- docname: string,
135
- schematype: string,
136
- jsondata: JsonSchemaProperties,
137
- requiredlist: string[] | undefined,parentpath:string,
138
- schemaconfigs:SchemaConfig,
139
- allmodels: ChildModels,
140
- parentFlatStr: string, // ex: docnoformat.branch
141
- ): Promise<SchemaModel> => {
142
- if(!allfields.includes(docname)){
143
- allfields.push(docname)
163
+ docname: string,
164
+ schematype: string,
165
+ jsondata: JsonSchemaProperties,
166
+ requiredlist: string[] | undefined,
167
+ parentpath: string,
168
+ schemaconfigs: SchemaConfig,
169
+ allmodels: ChildModels,
170
+ parentFlatStr: string, // ex: docnoformat.branch
171
+ parentObj: JSONSchema7
172
+ ): Promise<SchemaModel> => {
173
+ if (!allfields.includes(docname)) {
174
+ allfields.push(docname);
175
+ }
176
+ const newmodel: SchemaModel = {};
177
+
178
+ if (schematype === 'object' && !_.isEmpty(jsondata) && _.isEmpty(parentObj)) {
179
+ if (!parentObj[FOREIGNKEY_PROPERTY]) {
180
+ jsondata['more'] = {
181
+ type: 'object',
182
+ properties: {}
183
+ };
144
184
  }
145
- const newmodel: SchemaModel = {};
185
+ }
146
186
 
147
- Object.keys(jsondata).forEach(async (key) => {
148
- if(!allfields.includes(key)){
149
- allfields.push(key)
150
- }
151
-
152
- //below is Object.assign use for force datatype compatibility
153
- const obj:JSONSchema7={}
154
- Object.assign(obj,jsondata[key]);
155
- const objectitem:JSONSchema7= {} as JSONSchema7
156
- Object.assign(objectitem,obj.items);
187
+ Object.keys(jsondata).forEach(async (key) => {
188
+ if (!allfields.includes(key)) {
189
+ allfields.push(key);
190
+ }
157
191
 
158
- let isrequired = false
159
- if(requiredlist && requiredlist.includes(key)){
160
- isrequired=true
161
- }
162
- const newName: string = _.upperFirst(docname) + _.upperFirst(key);
163
- // const flatHierarchyStr: string = docname + '.' + key;
164
- let flatHierarchyStr = parentFlatStr + "." + key;
165
- if(parentFlatStr == ''){
166
- flatHierarchyStr = docname+ '.' + key;
167
- }
192
+ //below is Object.assign use for force datatype compatibility
193
+ const obj: JSONSchema7 = {};
194
+ Object.assign(obj, jsondata[key]);
195
+ const objectitem: JSONSchema7 = {} as JSONSchema7;
196
+ Object.assign(objectitem, obj.items);
197
+
198
+ let isrequired = false;
199
+ if (requiredlist && requiredlist.includes(key)) {
200
+ isrequired = true;
201
+ }
202
+ const newName: string = _.upperFirst(docname) + _.upperFirst(key);
203
+ // const flatHierarchyStr: string = docname + '.' + key;
204
+ let flatHierarchyStr = parentFlatStr + '.' + key;
205
+ if (parentFlatStr == '') {
206
+ flatHierarchyStr = docname + '.' + key;
207
+ }
168
208
 
169
209
  // if(obj[X_AUTOCOMPLETE_FIELD]){
170
210
  // docSetting.autocompleteFields.push(key)
171
211
  // }
172
-
173
212
 
174
213
  // if(obj.format && obj.format==FORMAT_TEL){
175
214
  // obj.pattern=obj.pattern ?? '/^\d{7,15}$/gm'
176
215
  // }
177
216
  // if (obj.type == 'object' && obj.items ){
178
217
  // console.log("Refer to another object",docname,': ',key,obj,obj.items)
179
-
180
- // obj,obj.items
181
- //foreignkeys
182
- //FOREIGNKEY_PROPERTY
183
- // newmodel[key] = 'Object';
184
- // }
185
- // else
186
218
 
187
-
188
- if(obj[FOREIGNKEY_PROPERTY]){
189
-
190
- const masterdatacollection = obj[FOREIGNKEY_PROPERTY]
191
- // const clientdatacollection = docname.toLowerCase()
192
- const clientdatacollection = parentFlatStr.split(".")[0] || docname.toLowerCase();
193
- const foreignkeyidentity= (obj.type=='object')? `${key}._id` : key
194
- const foreignkeypath = (obj.type=='object') ? `${parentpath}.${key}._id` : (obj.type =='array') ? `${parentpath}.${key}[*]._id` : `${parentpath}.${key}`
219
+ // obj,obj.items
220
+ //foreignkeys
221
+ //FOREIGNKEY_PROPERTY
222
+ // newmodel[key] = 'Object';
223
+ // }
224
+ // else
195
225
 
196
- const foreignkeyidentityNew = foreignkeypath.replace("$.", "").replace("[*]", "")
197
-
198
- //current document foreignkeys
199
- if(schemaconfigs.foreignKeys[masterdatacollection]){
200
- schemaconfigs.foreignKeys[masterdatacollection].push(foreignkeypath)
201
- }else{
202
- schemaconfigs.foreignKeys[masterdatacollection]=[foreignkeypath]
203
- }
226
+ if (obj[FOREIGNKEY_PROPERTY]) {
227
+ const masterdatacollection = obj[FOREIGNKEY_PROPERTY];
228
+ // const clientdatacollection = docname.toLowerCase()
229
+ const clientdatacollection =
230
+ parentFlatStr.split('.')[0] || docname.toLowerCase();
231
+ const foreignkeyidentity = obj.type == 'object' ? `${key}._id` : key;
232
+ const foreignkeypath =
233
+ obj.type == 'object'
234
+ ? `${parentpath}.${key}._id`
235
+ : obj.type == 'array'
236
+ ? `${parentpath}.${key}[*]._id`
237
+ : `${parentpath}.${key}`;
204
238
 
205
- //centralize foreignkeys catalogue
206
- if(!allforeignkeys[masterdatacollection]){
207
- let tmp:TypeForeignKey = {} as TypeForeignKey
208
- tmp[clientdatacollection]=[foreignkeyidentityNew]
209
- allforeignkeys[masterdatacollection] = tmp
210
- }
211
- else if(!allforeignkeys[masterdatacollection][clientdatacollection]){
239
+ const foreignkeyidentityNew = foreignkeypath
240
+ .replace('$.', '')
241
+ .replace('[*]', '');
212
242
 
213
- allforeignkeys[masterdatacollection][clientdatacollection]=[foreignkeyidentityNew]
214
- }else{
215
- // console.log(masterdatacollection, 3);
216
- allforeignkeys[masterdatacollection][clientdatacollection].push(foreignkeyidentityNew)
217
- }
243
+ //current document foreignkeys
244
+ if (schemaconfigs.foreignKeys[masterdatacollection]) {
245
+ schemaconfigs.foreignKeys[masterdatacollection].push(foreignkeypath);
246
+ } else {
247
+ schemaconfigs.foreignKeys[masterdatacollection] = [foreignkeypath];
218
248
  }
219
249
 
220
- if (obj.type == 'object') {
221
- // console.log("line 175",key,obj.type,obj.properties)
222
- await genSchema(newName, obj.type, obj.properties, obj.required,`${parentpath}.${key}`,schemaconfigs,allmodels, flatHierarchyStr);
223
- newmodel[key] = newName;
224
- } else if (obj.type == 'array' && obj.items && objectitem?.type == 'object') {
225
- const childprops = objectitem?.properties
226
- if(!childprops['created']){
227
- childprops['created']={type:'string',description:'iso8601 dataempty mean new record'}
228
- }
229
- if(!childprops['updated']){
230
- childprops['updated']={type:'string',description:'iso8601 or empty'}
231
- }
232
- if(!childprops['createdBy']){
233
- childprops['createdBy']={type:'string'}
234
- }
235
- if(!childprops['updatedBy']){
236
- childprops['updatedBy']={type:'string'}
237
- }
238
- if(!childprops['_id']){
239
- childprops['_id']={type:'string'}
240
- }
241
- // console.log("line 195")
242
- await genSchema(newName, obj.type, objectitem?.properties, obj.items['required'],`${parentpath}.${key}[*]`,schemaconfigs,allmodels, flatHierarchyStr);
243
- newmodel[key] = [newName];
244
- } else if (obj.type == 'array' && objectitem?.type != 'object') {
245
- //array need submodel
246
- // genSchema(newName, obj.type, obj.items.properties);
247
- const objecttype:string = objectitem.type?.toString() ?? 'string'
248
- newmodel[key] = [objecttype];
250
+ //centralize foreignkeys catalogue
251
+ if (!allforeignkeys[masterdatacollection]) {
252
+ let tmp: TypeForeignKey = {} as TypeForeignKey;
253
+ tmp[clientdatacollection] = [foreignkeyidentityNew];
254
+ allforeignkeys[masterdatacollection] = tmp;
255
+ } else if (!allforeignkeys[masterdatacollection][clientdatacollection]) {
256
+ allforeignkeys[masterdatacollection][clientdatacollection] = [
257
+ foreignkeyidentityNew
258
+ ];
249
259
  } else {
250
- newmodel[key] = getField(key, obj, isrequired);
251
- // console.log(key,'--------newmodel',obj, newmodel[key]);
260
+ // console.log(masterdatacollection, 3);
261
+ allforeignkeys[masterdatacollection][clientdatacollection].push(
262
+ foreignkeyidentityNew
263
+ );
252
264
  }
253
- })
254
- // log.warn(newmodel,docname)
255
-
256
- const modelname= _.upperFirst(docname)
257
- // log.warn("$$$$$$$$$$>>>",modelname,)
258
- // log.warn(newmodel,modelname)
259
- allmodels[modelname] = {
260
- type: schematype,
261
- model: newmodel,
262
- codeField: schemaconfigs.uniqueKey??'' ,
263
- nameField: schemaconfigs.documentTitle ?? '',
264
- moreAutoComplete:schemaconfigs.additionalAutoCompleteFields ?? [],
265
- docStatusSettings:schemaconfigs.allStatus ?? [],
266
- apiSettings:schemaconfigs.additionalApis ?? [],
267
- // requireautocomplete:docSetting.requireautocomplete,
268
- isolationtype:schemaconfigs.isolationType ,
269
- hasdocformat:schemaconfigs.generateDocumentNumber ?? false,
270
- foreignkeys: schemaconfigs.foreignKeys ?? {}
271
- };
272
- // console.warn("-------------apiSettings-----",docname,"::::",docSetting.apiSettings)
273
- return newmodel;
274
- };
275
-
265
+ }
276
266
 
267
+ if (obj.type == 'object') {
268
+ // console.log("line 175",key,obj.type,obj.properties)
269
+ await genSchema(
270
+ newName,
271
+ obj.type,
272
+ obj.properties,
273
+ obj.required,
274
+ `${parentpath}.${key}`,
275
+ schemaconfigs,
276
+ allmodels,
277
+ flatHierarchyStr,
278
+ obj
279
+ );
280
+ newmodel[key] = newName;
281
+ } else if (
282
+ obj.type == 'array' &&
283
+ obj.items &&
284
+ objectitem?.type == 'object'
285
+ ) {
286
+ const childprops = objectitem?.properties;
287
+ if (!childprops['created']) {
288
+ childprops['created'] = {
289
+ type: 'string',
290
+ description: 'iso8601 dataempty mean new record'
291
+ };
292
+ }
293
+ if (!childprops['updated']) {
294
+ childprops['updated'] = {
295
+ type: 'string',
296
+ description: 'iso8601 or empty'
297
+ };
298
+ }
299
+ if (!childprops['createdBy']) {
300
+ childprops['createdBy'] = { type: 'string' };
301
+ }
302
+ if (!childprops['updatedBy']) {
303
+ childprops['updatedBy'] = { type: 'string' };
304
+ }
305
+ if (!childprops['_id']) {
306
+ childprops['_id'] = { type: 'string' };
307
+ }
308
+ // console.log("line 195")
309
+ await genSchema(
310
+ newName,
311
+ obj.type,
312
+ objectitem?.properties,
313
+ obj.items['required'],
314
+ `${parentpath}.${key}[*]`,
315
+ schemaconfigs,
316
+ allmodels,
317
+ flatHierarchyStr,
318
+ obj
319
+ );
320
+ newmodel[key] = [newName];
321
+ } else if (obj.type == 'array' && objectitem?.type != 'object') {
322
+ //array need submodel
323
+ // genSchema(newName, obj.type, obj.items.properties);
324
+ const objecttype: string = objectitem.type?.toString() ?? 'string';
325
+ newmodel[key] = [objecttype];
326
+ } else {
327
+ newmodel[key] = getField(key, obj, isrequired);
328
+ // console.log(key,'--------newmodel',obj, newmodel[key]);
329
+ }
330
+ });
331
+ // log.warn(newmodel,docname)
332
+ // console.log(docname, requiredlist);
333
+ const modelname = _.upperFirst(docname);
334
+ // log.warn("$$$$$$$$$$>>>",modelname,)
335
+ // log.warn(newmodel,modelname)
336
+ allmodels[modelname] = {
337
+ type: schematype,
338
+ model: newmodel,
339
+ codeField: schemaconfigs.uniqueKey ?? '',
340
+ nameField: schemaconfigs.documentTitle ?? '',
341
+ moreAutoComplete: schemaconfigs.additionalAutoCompleteFields ?? [],
342
+ docStatusSettings: schemaconfigs.allStatus ?? [],
343
+ apiSettings: schemaconfigs.additionalApis ?? [],
344
+ // requireautocomplete:docSetting.requireautocomplete,
345
+ isolationtype: schemaconfigs.isolationType,
346
+ hasdocformat: schemaconfigs.generateDocumentNumber ?? false,
347
+ foreignkeys: schemaconfigs.foreignKeys ?? {},
348
+ required: requiredlist ?? []
349
+ };
350
+ // console.warn("-------------apiSettings-----",docname,"::::",docSetting.apiSettings)
351
+ return newmodel;
352
+ };
277
353
 
278
354
  const getField = (
279
355
  fieldname: string,
280
356
  obj: JSONSchema7,
281
- isrequired: boolean | undefined,
357
+ isrequired: boolean | undefined
282
358
  ): FieldModel => {
283
- if(!allfields.includes(fieldname)){
284
- allfields.push(fieldname)
359
+ if (!allfields.includes(fieldname)) {
360
+ allfields.push(fieldname);
285
361
  }
286
-
287
- let datatype: Fieldtypes = obj.type as Fieldtypes
362
+
363
+ let datatype: Fieldtypes = obj.type as Fieldtypes;
288
364
  // console.log(datatype)
289
365
  //Fieldtypes.string;
290
366
  let format = obj.format;
@@ -296,10 +372,10 @@ const getField = (
296
372
  const f: FieldModel = {
297
373
  type: datatype,
298
374
  // oritype: obj.type,
299
- required: isrequired,
375
+ required: isrequired
300
376
  };
301
377
 
302
- // if (obj.title)
378
+ // if (obj.title)
303
379
  f.title = obj.title;
304
380
  if (obj.description) f.description = obj.description;
305
381
  if (obj.format) f.format = obj.format;
package/src/type.ts CHANGED
@@ -9,9 +9,10 @@ export type ChildModels = {
9
9
  docStatusSettings?:DocumentStatus[],
10
10
  apiSettings?:DocumentApi[],
11
11
  // requireautocomplete: boolean
12
- isolationtype:string
12
+ isolationtype:string,
13
13
  hasdocformat:boolean,
14
- foreignkeys:MyForeignKey
14
+ foreignkeys:MyForeignKey,
15
+ required: string[]
15
16
  };
16
17
  };
17
18
  export enum Fieldtypes {