@simitgroup/simpleapp-generator 1.0.32 → 1.0.35
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/.vscode/settings.json +3 -0
- package/README.md +185 -16
- package/buildinschemas copy/autoincreament.autoinc.jsonschema.json +39 -0
- package/buildinschemas copy/branch.branch.jsonschema.json +41 -0
- package/buildinschemas copy/docnoformat.docno.jsonschema.json +41 -0
- package/buildinschemas copy/organization.org.jsonschema.json +50 -0
- package/buildinschemas copy/permission.perm.jsonschema.json +23 -0
- package/buildinschemas copy/permission.perm.jsonschema.try.json +25 -0
- package/buildinschemas copy/tenant.tenant.jsonschema.json +21 -0
- package/buildinschemas copy/tenant.tenant.jsonschema.try.json +27 -0
- package/buildinschemas copy/user.user.jsonschema.json +31 -0
- package/dist/buildinschemas/autoincreament.d.ts +3 -0
- package/dist/buildinschemas/autoincreament.d.ts.map +1 -0
- package/dist/buildinschemas/autoincreament.js +36 -0
- package/dist/buildinschemas/autoincreament.js.map +1 -0
- package/dist/buildinschemas/branch.d.ts +3 -0
- package/dist/buildinschemas/branch.d.ts.map +1 -0
- package/dist/buildinschemas/branch.js +41 -0
- package/dist/buildinschemas/branch.js.map +1 -0
- package/dist/buildinschemas/docnoformat.d.ts +3 -0
- package/dist/buildinschemas/docnoformat.d.ts.map +1 -0
- package/dist/buildinschemas/docnoformat.js +60 -0
- package/dist/buildinschemas/docnoformat.js.map +1 -0
- package/dist/buildinschemas/index.d.ts +8 -0
- package/dist/buildinschemas/index.d.ts.map +1 -0
- package/dist/buildinschemas/index.js +18 -0
- package/dist/buildinschemas/index.js.map +1 -0
- package/dist/buildinschemas/organization.d.ts +3 -0
- package/dist/buildinschemas/organization.d.ts.map +1 -0
- package/dist/buildinschemas/organization.js +34 -0
- package/dist/buildinschemas/organization.js.map +1 -0
- package/dist/buildinschemas/permission.d.ts +3 -0
- package/dist/buildinschemas/permission.d.ts.map +1 -0
- package/dist/buildinschemas/permission.js +34 -0
- package/dist/buildinschemas/permission.js.map +1 -0
- package/dist/buildinschemas/tenant.d.ts +3 -0
- package/dist/buildinschemas/tenant.d.ts.map +1 -0
- package/dist/buildinschemas/tenant.js +41 -0
- package/dist/buildinschemas/tenant.js.map +1 -0
- package/dist/buildinschemas/user.d.ts +3 -0
- package/dist/buildinschemas/user.d.ts.map +1 -0
- package/dist/buildinschemas/user.js +31 -0
- package/dist/buildinschemas/user.js.map +1 -0
- package/dist/constant.d.ts +4 -0
- package/dist/constant.d.ts.map +1 -0
- package/dist/constant.js +2 -1
- package/dist/constant.js.map +1 -1
- package/dist/framework.d.ts +10 -0
- package/dist/framework.d.ts.map +1 -0
- package/dist/framework.js +120 -68
- 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 +2 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +310 -230
- package/dist/generate.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -20
- package/dist/index.js.map +1 -1
- package/dist/libs.d.ts +2 -0
- package/dist/libs.d.ts.map +1 -0
- package/dist/processors/groupsbuilder.js +2 -0
- package/dist/processors/groupsbuilder.js.map +1 -0
- package/dist/processors/jsonschemabuilder.d.ts +4 -0
- package/dist/processors/jsonschemabuilder.d.ts.map +1 -0
- package/dist/processors/jsonschemabuilder.js +146 -172
- package/dist/processors/jsonschemabuilder.js.map +1 -1
- 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/storage.d.ts +3 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +2 -2
- package/dist/storage.js.map +1 -1
- package/dist/type.d.ts +164 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +16 -1
- package/dist/type.js.map +1 -1
- package/dist/validation.d.ts +1 -0
- package/dist/validation.d.ts.map +1 -0
- package/documentation/designconcept.bpmn +349 -0
- package/documentation/documentation.png +0 -0
- package/documentation/infra.drawio +141 -0
- package/documentation/infra.png +0 -0
- package/documentation/management.drawio +57 -0
- package/documentation/stack.drawio +106 -0
- package/package.json +3 -1
- package/src/buildinschemas/autoincreament.ts +34 -0
- package/src/buildinschemas/branch.ts +39 -0
- package/src/buildinschemas/docnoformat.ts +58 -0
- package/src/buildinschemas/index.ts +7 -0
- package/src/buildinschemas/organization.ts +31 -0
- package/src/buildinschemas/permission.ts +31 -0
- package/src/buildinschemas/tenant.ts +38 -0
- package/src/buildinschemas/user.ts +28 -0
- package/src/constant.ts +2 -1
- package/src/framework.ts +126 -67
- package/src/generate.ts +327 -266
- package/src/generate.ts.backup +339 -0
- package/src/index.ts +93 -18
- package/src/processors/jsonschemabuilder.ts +199 -226
- package/src/processors/jsonschemabuilder.ts-old +383 -0
- package/src/storage.ts +1 -1
- package/src/type.ts +94 -27
- package/templates/basic/nest/controller.ts.eta +255 -0
- package/templates/basic/nest/default.ts.eta +42 -0
- package/templates/basic/{model.eta → nest/model.ts.eta} +18 -5
- package/templates/basic/nest/processor.ts.eta +129 -0
- package/templates/basic/nest/service.ts.eta +64 -0
- package/templates/basic/{type.eta → nest/type.ts.eta} +3 -3
- package/templates/basic/nuxt/default.ts.eta +42 -0
- package/templates/basic/{pageindex.vue.eta → nuxt/pages.crud.vue.eta} +85 -22
- package/templates/basic/nuxt/simpleapp.doc.ts.eta +11 -0
- package/templates/basic/nuxt/simpleapp.generate.client.ts.eta +212 -0
- package/templates/nest/.env.eta +31 -0
- package/templates/nest/.gitignore.eta +40 -0
- package/templates/nest/src/app.controller.ts.eta +19 -0
- package/templates/nest/src/app.module.ts.eta +77 -0
- package/templates/nest/src/app.service.ts.eta +9 -0
- package/templates/nest/src/main.ts.eta +58 -0
- package/templates/nest/src/simpleapp/generate/apischemas/index.ts.eta +16 -0
- package/templates/nest/src/simpleapp/generate/commons/decorators/appuser.decorator.ts.eta +8 -0
- package/templates/nest/src/simpleapp/generate/commons/dicts/foreignkeys.ts.eta +1 -0
- package/templates/nest/src/simpleapp/generate/commons/docnogenerator.service.ts.eta +101 -0
- package/templates/nest/src/simpleapp/generate/commons/exceptions/SimpleAppExceptionFilter.ts.eta +39 -0
- package/templates/nest/src/simpleapp/generate/commons/interceptors/response.interceptor.ts.eta +38 -0
- package/templates/nest/src/simpleapp/generate/commons/middlewares/tenant.middleware.ts.eta +88 -0
- package/templates/nest/{Workflow.eta → src/simpleapp/generate/commons/providers/workflow.provider.ts.etax} +20 -14
- package/templates/nest/src/simpleapp/generate/commons/roles/roles.decorator.ts.eta +6 -0
- package/templates/nest/src/simpleapp/generate/commons/roles/roles.enum.ts.eta +28 -0
- package/templates/nest/src/simpleapp/generate/commons/roles/roles.group.ts.eta +10 -0
- package/templates/nest/src/simpleapp/generate/commons/roles/roles.guard.ts.eta +34 -0
- package/templates/nest/src/simpleapp/generate/commons/user.context.ts.eta +391 -0
- package/templates/nest/src/simpleapp/generate/controllers/simpleapp.controller.ts.eta +71 -0
- package/templates/nest/src/simpleapp/generate/models/perm.model.ts.eta +53 -0
- package/templates/nest/src/simpleapp/generate/models/tenant.model.ts.eta +45 -0
- package/templates/nest/src/simpleapp/generate/models/user.model.ts.eta +57 -0
- package/templates/nest/src/simpleapp/generate/processors/simpleapp.processor.ts.eta +624 -0
- package/templates/nest/src/simpleapp/generate/types/index.ts.eta +19 -0
- package/templates/nest/src/simpleapp/profile/profile.apischema.ts.eta +74 -0
- package/templates/nest/src/simpleapp/profile/profile.controller.ts.eta +110 -0
- package/templates/nest/src/simpleapp/profile/profile.service.ts.eta +195 -0
- package/templates/nest/src/simpleapp/profile/profile.types.ts.eta +18 -0
- package/templates/nest/src/simpleapp/services/autoinc.service.ts.eta +89 -0
- package/templates/nest/src/simpleapp/services/branch.service.ts.eta +66 -0
- package/templates/nest/src/simpleapp/services/docno.service.ts.eta +93 -0
- package/templates/nest/src/simpleapp/services/org.service.ts.eta +67 -0
- package/templates/nest/src/simpleapp/services/perm.service.ts.eta +102 -0
- package/templates/nest/src/simpleapp/services/tenant.service.ts.eta +69 -0
- package/templates/nest/src/simpleapp/services/user.service.ts.eta +66 -0
- package/templates/nest/src/simpleapp/simpleapp.module.ts.eta +43 -0
- package/templates/nuxt/.env.eta +21 -0
- package/templates/nuxt/.gitignore.eta +28 -0
- package/templates/nuxt/app.vue.eta +5 -2
- package/templates/nuxt/assets/css/tailwind.css.eta +35 -0
- package/templates/nuxt/components/CrudNestedDoc.vue.eta +164 -0
- package/templates/nuxt/components/CrudSimple.vue.eta +179 -0
- package/templates/nuxt/{components.debugdocdata.vue.eta → components/DebugDocumentData.vue.eta} +4 -1
- package/templates/nuxt/{components.eventmonitor.vue.eta → components/EventMonitor.vue.eta} +27 -27
- package/templates/nuxt/components/Invitation.vue.eta +50 -0
- package/templates/nuxt/components/Menus.vue.eta +58 -0
- package/templates/nuxt/components/PermissionInfo.vue.eta +92 -0
- package/templates/nuxt/components/SimpleAppAutocomplete.vue.eta +131 -0
- package/templates/nuxt/components/SimpleAppAutocompletemulti.vue.eta +73 -0
- package/templates/nuxt/components/SimpleAppCalendar.vue.eta +55 -0
- package/templates/nuxt/components/SimpleAppCheckbox.vue.eta +29 -0
- package/templates/nuxt/components/SimpleAppChip.vue.eta +28 -0
- package/templates/nuxt/components/SimpleAppColor.vue.eta +41 -0
- package/templates/nuxt/components/SimpleAppDatatable.vue.eta +20 -0
- package/templates/nuxt/components/SimpleAppDocumentNo.vue.eta +90 -0
- package/templates/nuxt/components/SimpleAppDynamicInput.vue.eta +29 -0
- package/templates/nuxt/components/SimpleAppEditor.vue.eta +31 -0
- package/templates/nuxt/components/SimpleAppForm.vue.eta +131 -0
- package/templates/nuxt/components/SimpleAppInputTable.vue.eta +104 -0
- package/templates/nuxt/components/SimpleAppList.vue.eta +38 -0
- package/templates/nuxt/components/SimpleAppListmulti.vue.eta +41 -0
- package/templates/nuxt/components/SimpleAppNumber.vue.eta +32 -0
- package/templates/nuxt/components/SimpleAppPassword.vue.eta +41 -0
- package/templates/nuxt/components/SimpleAppRadio.vue.eta +42 -0
- package/templates/nuxt/components/SimpleAppRating.vue.eta +41 -0
- package/templates/nuxt/components/SimpleAppSelect.vue.eta +38 -0
- package/templates/nuxt/components/SimpleAppSelectmulti.vue.eta +39 -0
- package/templates/nuxt/components/SimpleAppSlider.vue.eta +42 -0
- package/templates/nuxt/components/SimpleAppSwitch.vue.eta +30 -0
- package/templates/nuxt/components/SimpleAppText.vue.eta +50 -0
- package/templates/nuxt/components/SimpleAppTextarea.vue.eta +30 -0
- package/templates/nuxt/components/SimpleAppValue.vue.eta +86 -0
- package/templates/nuxt/components/SimpleFieldContainer.vue.eta +102 -0
- package/templates/nuxt/components/XorgPicker.vue.eta +66 -0
- package/templates/nuxt/components/helper.ts.eta +90 -0
- package/templates/nuxt/components/type.ts.eta +32 -0
- package/templates/nuxt/composables/docformat.generate.ts.eta +5 -0
- package/templates/nuxt/{composables.getautocomplete.ts.eta → composables/getAutocomplete.generate.ts.eta} +4 -5
- package/templates/nuxt/{composables.getmenus.ts.eta → composables/getMenus.generate.ts.eta} +22 -7
- package/templates/nuxt/composables/getOpenApi.generate.ts.eta +6 -0
- package/templates/nuxt/composables/getTenant.generate.ts.eta +4 -0
- package/templates/nuxt/composables/getUserStore.generate.ts.eta +22 -0
- package/templates/nuxt/composables/logout.generate.ts.eta +22 -0
- package/templates/nuxt/composables/roles.generate.ts.eta +48 -0
- package/templates/nuxt/composables/stringHelper.generate.ts.eta +5 -0
- package/templates/nuxt/{layouts.default.vue.eta → layouts/default.vue.eta} +2 -0
- package/templates/nuxt/middleware/10.acl.global.ts.eta +38 -0
- package/templates/nuxt/nuxt.config.ts.eta +12 -2
- package/templates/nuxt/pages/[xorg]/branch/index.vue.eta +102 -0
- package/templates/nuxt/pages/[xorg]/docnoformat/[id].vue.eta +17 -0
- package/templates/nuxt/pages/[xorg]/docnoformat/index.vue.eta +269 -0
- package/templates/nuxt/pages/[xorg]/index.vue.eta +36 -0
- package/templates/nuxt/pages/[xorg]/organization/index.vue.eta +148 -0
- package/templates/nuxt/pages/[xorg]/permission/index.vue.eta +280 -0
- package/templates/nuxt/pages/[xorg]/tenant/index.vue.eta +93 -0
- package/templates/nuxt/pages/[xorg]/user/index.vue.eta +468 -0
- package/templates/nuxt/pages/index.vue.eta +191 -0
- package/templates/nuxt/pages/login.vue.eta +21 -0
- package/templates/nuxt/plugins/10.simpleapp-event.ts.eta +53 -0
- package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +155 -0
- package/templates/nuxt/plugins/50.simpleapp-client.ts.eta +23 -0
- package/templates/nuxt/{server.api.ts.eta → server/api/[xorg]/[...].ts.eta} +5 -2
- package/templates/nuxt/server/api/auth/[...].ts.eta +68 -0
- package/templates/nuxt/{server.api.auth.logout.ts.eta → server/api/auth/logout.ts.eta} +1 -3
- package/templates/nuxt/server/api/profile/[...].ts.eta +150 -0
- package/templates/nuxt/server/api/profile/index.ts.eta +103 -0
- package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +187 -0
- package/templates/nuxt/simpleapp/generate/commons/documents.ts.eta +6 -0
- package/templates/nuxt/simpleapp/generate/commons/events.ts.eta +5 -0
- package/templates/nuxt/simpleapp/generate/commons/groups.ts.eta +11 -0
- package/templates/nuxt/simpleapp/generate/commons/roles.ts.eta +21 -0
- package/templates/nuxt/types/index.ts.eta +65 -0
- package/templates/project/README.md +11 -0
- package/templates/project/build.sh.eta +17 -0
- package/templates/project/config.json.eta +2 -0
- package/templates/project/generate.ts.eta +10 -0
- package/templates/project/schemas/category.ts.eta +26 -0
- package/templates/project/schemas/index.ts.eta +5 -0
- package/templates/project/schemas/product.ts.eta +59 -0
- package/templates/project/shares/hello.ts.eta +1 -0
- package/templates/project/shares/index.ts.eta +2 -0
- package/tsconfig.json +9 -2
- package/tsconfig.tsbuildinfo +1 -0
- package/definations/category.cat.jsonschema.json +0 -55
- package/definations/level.lvl.jsonschema.json +0 -48
- package/definations/product.prd.jsonschema.json +0 -46
- package/templates/basic/controller.eta +0 -152
- package/templates/basic/module.eta +0 -22
- package/templates/basic/service.eta +0 -62
- package/templates/basic/simpleappclient.eta +0 -120
- package/templates/nest/SimpleAppController.eta +0 -69
- package/templates/nest/SimpleAppService.eta +0 -366
- package/templates/nest/TenantMiddleware.eta +0 -34
- package/templates/nest/UserProvider.eta +0 -127
- package/templates/nest/app.controller.eta +0 -12
- package/templates/nest/app.module.eta +0 -64
- package/templates/nest/app.service.eta +0 -8
- package/templates/nest/inputvalidation-exception.eta +0 -6
- package/templates/nest/nest.env.eta +0 -28
- package/templates/nest/nest.main.eta +0 -31
- package/templates/nuxt/components.crudsimple.vue.eta +0 -124
- package/templates/nuxt/components.menus.vue.eta +0 -35
- package/templates/nuxt/env.eta +0 -17
- package/templates/nuxt/pages.[xorg].index.vue.eta +0 -20
- package/templates/nuxt/pages.index.vue.eta +0 -72
- package/templates/nuxt/pages.login.vue.eta +0 -20
- package/templates/nuxt/plugins.simpleapp.ts.eta +0 -88
- package/templates/nuxt/server.api.auth[...].ts.eta +0 -233
- package/templates/nuxt/tailwind.css.eta +0 -49
- /package/templates/basic/{apischema.eta → nest/apischema.ts.eta} +0 -0
- /package/templates/basic/{jsonschema.eta → nest/jsonschema.ts.eta} +0 -0
- /package/templates/basic/{pageindexwithid.vue.eta → nuxt/pages.[id].vue.eta} +0 -0
- /package/templates/nest/{oauth2-redirect.eta → public_html/oauth2-redirect.html.eta} +0 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// import { ExceptionsHandler } from '@nestjs/core/exceptions/exceptions-handler';
|
|
2
|
-
import { JSONSchema7, JSONSchema7Definition,JSONSchema7Array,JSONSchema7TypeName } from 'json-schema';
|
|
2
|
+
import { JSONSchema7, JSONSchema7Definition,JSONSchema7Array,JSONSchema7TypeName, JSONSchema7Object } from 'json-schema';
|
|
3
3
|
import * as js7 from 'json-schema';
|
|
4
|
+
import _ from 'lodash'
|
|
4
5
|
import { capitalizeFirstLetter } from '../libs';
|
|
5
|
-
import {JsonSchemaProperties} from "../type"
|
|
6
|
+
import {SchemaType,SchemaConfig,JsonSchemaProperties,MyForeignKey} from "../type"
|
|
7
|
+
// import * as schematemplates from '../schematype'
|
|
6
8
|
import { Logger, ILogObj } from "tslog";
|
|
7
9
|
import $RefParser from "@apidevtools/json-schema-ref-parser";
|
|
8
|
-
import {
|
|
10
|
+
import {allforeignkeys} from '../storage'
|
|
9
11
|
// import { ConflictException } from '@nestjs/common';
|
|
10
12
|
import {
|
|
11
13
|
FieldModel,
|
|
@@ -14,263 +16,235 @@ import {
|
|
|
14
16
|
SchemaModel,
|
|
15
17
|
TypeForeignKey,
|
|
16
18
|
TypeForeignKeyCatalogue,
|
|
17
|
-
DocSetting,
|
|
19
|
+
DocSetting,
|
|
18
20
|
|
|
19
21
|
} from '../type';
|
|
20
|
-
import { json } from 'stream/consumers';
|
|
21
22
|
const log: Logger<ILogObj> = new Logger();
|
|
23
|
+
const configname = "x-simpleapp-config"
|
|
24
|
+
const FOREIGNKEY_PROPERTY = 'x-foreignkey'
|
|
25
|
+
const COMPULSORYFIELDS={ _id:{type:'string'},
|
|
26
|
+
created:{type:'string'},
|
|
27
|
+
updated:{type:'string'},
|
|
28
|
+
createdby:{type:'string'},
|
|
29
|
+
updatedby:{type:'string'},
|
|
30
|
+
tenantId: {type:'integer',default:1,minimum:1 },
|
|
31
|
+
orgId: {type:'integer',default:1,minimum:1 },
|
|
32
|
+
branchId: {type:'integer',default:1,minimum:1 },
|
|
33
|
+
}
|
|
34
|
+
export const readJsonSchemaBuilder = async (docname: string,orijsondata:JSONSchema7,
|
|
35
|
+
) => {
|
|
36
|
+
// log.info(`----------------------------------------------------`)
|
|
37
|
+
// log.error(`Processing schema ${docname}`)
|
|
38
|
+
//validation
|
|
39
|
+
if(!orijsondata[configname]) throw new Error(`Undefine ${configname}`)
|
|
40
|
+
|
|
41
|
+
// // Object.assign(targettemplate,schematemplates[currentschematype])
|
|
42
|
+
// console.log("just want process schemaprops ********>>",targettemplate)
|
|
43
|
+
|
|
44
|
+
let schemaconfigs:SchemaConfig = orijsondata[configname]
|
|
45
|
+
const doctype=schemaconfigs.documentType
|
|
46
|
+
if(!schemaconfigs.collectionName){
|
|
47
|
+
schemaconfigs.documentName
|
|
48
|
+
}
|
|
22
49
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const X_DOCUMENT_NAME='x-document-name'
|
|
27
|
-
const X_DOCUMENT_TYPE='x-document-type'
|
|
28
|
-
const X_COLLECTION_NAME='x-document-collection'
|
|
29
|
-
const X_DOCUMENT_STATUS='x-document-status'
|
|
30
|
-
const X_DOCUMENT_API='x-document-api'
|
|
31
|
-
const X_IGNORE_AUTOCOMPLETE='x-ignore-autocomplete'
|
|
32
|
-
const FOREIGNKEY_PROPERTY='x-foreignkey'
|
|
33
|
-
const X_TEL_NO='x-tel'
|
|
34
|
-
const X_ISOLATION_TYPE='x-isolation-type'
|
|
35
|
-
|
|
36
|
-
let docSetting:DocSetting={} as DocSetting
|
|
37
|
-
|
|
50
|
+
if(!schemaconfigs.foreignKeys){
|
|
51
|
+
schemaconfigs.foreignKeys={}
|
|
52
|
+
}
|
|
38
53
|
|
|
54
|
+
// let schemaprops:any = targettemplate.properties
|
|
55
|
+
// console.log("just want process targettemplate ######>>>",orijsondata)
|
|
56
|
+
// let schemadefinitions = targettemplate.definitions
|
|
39
57
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
|
|
59
|
+
// Object.assign(schemaconfigs,orijsondata[configname])
|
|
60
|
+
// Object.assign(schemaprops,orijsondata.properties)
|
|
61
|
+
|
|
62
|
+
// if(orijsondata['definitions']){
|
|
63
|
+
// Object.assign(schemadefinitions,orijsondata['definitions'])
|
|
64
|
+
// }
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// //merge properties from template
|
|
68
|
+
// Object.keys(schemaconfigs).forEach(keyname=>{
|
|
69
|
+
// if(!schemaconfigs[keyname]){
|
|
70
|
+
// log.fatal(`Undefine ${keyname} in "${configname}"`)
|
|
71
|
+
// }
|
|
72
|
+
// })
|
|
45
73
|
|
|
74
|
+
//fill in default values
|
|
75
|
+
|
|
46
76
|
|
|
47
|
-
const newDocSetting=(doctype:string,docname:string):DocSetting=>{
|
|
48
|
-
return {
|
|
49
|
-
docName:docname, //done
|
|
50
|
-
docType:doctype, //done
|
|
51
|
-
colDocNo:'', //done
|
|
52
|
-
colDocLabel:'', //done
|
|
53
|
-
collectionName:docname, //done
|
|
54
|
-
autocompleteFields:[],
|
|
55
|
-
docStatusSettings:[],
|
|
56
|
-
apiSettings:[],
|
|
57
|
-
requireautocomplete:true,
|
|
58
|
-
isolationtype:"org"
|
|
59
77
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const validateddata: JSONSchema7 = { ...orijsondata };
|
|
75
|
-
let schema: SchemaModel | SchemaModel[];
|
|
76
|
-
const tmpjsondata = await $RefParser.dereference(orijsondata).then((schema)=>{
|
|
77
|
-
// console.log("schema",doctype, schema['properties']['category']? schema['properties']['category']:'')
|
|
78
|
-
return schema
|
|
78
|
+
// let newschema:JSONSchema7 & SchemaType = {
|
|
79
|
+
// type: 'object',
|
|
80
|
+
// "x-simpleapp-config":schemaconfigs,
|
|
81
|
+
// properties:schemaprops,
|
|
82
|
+
// definitions:schemadefinitions
|
|
83
|
+
|
|
84
|
+
// }
|
|
85
|
+
// log.warn("------------------")
|
|
86
|
+
// log.warn(newschema)
|
|
87
|
+
// dereference in case implement remote schema
|
|
88
|
+
// console.log("before dereference jsondata.properties =======---",newschema)
|
|
89
|
+
const tmpjsondata = await $RefParser.dereference(orijsondata).then((tmp)=>{
|
|
90
|
+
return tmp
|
|
79
91
|
})
|
|
92
|
+
// console.log("First level jsondata.properties =======++",tmpjsondata)
|
|
93
|
+
// log.info(tmpjsondata,`==========================${schemaconfigs.documentType}==========================`)
|
|
80
94
|
const jsondata:JSONSchema7 = {...tmpjsondata} as JSONSchema7
|
|
81
|
-
|
|
95
|
+
let allmodels: ChildModels = {};
|
|
82
96
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
throw "missing field format"
|
|
94
|
-
}
|
|
95
|
-
if(docSetting.colDocLabel=='' && docSetting.requireautocomplete) {
|
|
96
|
-
log.error(`you shall define 1 field with format: '${X_DOCUMENT_LABEL}'}`)
|
|
97
|
-
throw "missing field format"
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return Promise.resolve(allmodels);
|
|
97
|
+
await genSchema(
|
|
98
|
+
schemaconfigs.documentName,
|
|
99
|
+
'object',
|
|
100
|
+
jsondata.properties,
|
|
101
|
+
jsondata['required'] ?? [],
|
|
102
|
+
'$',
|
|
103
|
+
schemaconfigs,
|
|
104
|
+
allmodels
|
|
105
|
+
);
|
|
106
|
+
return allmodels
|
|
101
107
|
};
|
|
102
108
|
|
|
103
109
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
/**
|
|
111
|
+
* process recursively every property in schema
|
|
112
|
+
* @param SchemaConfig
|
|
113
|
+
* @param parentName
|
|
114
|
+
* @param schematype
|
|
115
|
+
* @param jsondata
|
|
116
|
+
* @param requiredlist
|
|
117
|
+
* @param parentpath
|
|
118
|
+
* @param schemaconfigs
|
|
119
|
+
* @returns
|
|
120
|
+
*/
|
|
121
|
+
const genSchema = async (
|
|
122
|
+
docname: string,
|
|
123
|
+
schematype: string,
|
|
124
|
+
jsondata: JsonSchemaProperties,
|
|
125
|
+
requiredlist: string[] | undefined,parentpath:string,
|
|
126
|
+
schemaconfigs:SchemaConfig,
|
|
127
|
+
allmodels: ChildModels
|
|
128
|
+
): Promise<SchemaModel> => {
|
|
110
129
|
|
|
111
|
-
|
|
112
|
-
jsondata
|
|
113
|
-
jsondata.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
jsondata.properties['createdby'] = {type: 'string',description: 'Control value, dont edit it',};
|
|
120
|
-
jsondata.properties['updatedby'] = {type: 'string',description: 'Control value, dont edit it',};
|
|
130
|
+
const newmodel: SchemaModel = {};
|
|
131
|
+
// console.log("jsondata--->>>>",docname,jsondata)
|
|
132
|
+
Object.keys(jsondata).forEach(async (key) => {
|
|
133
|
+
//below is Object.assign use for force datatype compatibility
|
|
134
|
+
const obj:JSONSchema7={}
|
|
135
|
+
Object.assign(obj,jsondata[key]);
|
|
136
|
+
const objectitem:JSONSchema7= {} as JSONSchema7
|
|
137
|
+
Object.assign(objectitem,obj.items);
|
|
121
138
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if(jsondata[X_IGNORE_AUTOCOMPLETE] && jsondata[X_IGNORE_AUTOCOMPLETE]==true){
|
|
126
|
-
docSetting.requireautocomplete=false
|
|
127
|
-
}
|
|
128
|
-
if(jsondata[X_DOCUMENT_API] && Array.isArray(jsondata[X_DOCUMENT_API])){
|
|
129
|
-
log.warn("x-document-api exists:")
|
|
130
|
-
log.warn(jsondata[X_DOCUMENT_API])
|
|
131
|
-
for(let i=0; i<jsondata[X_DOCUMENT_API].length;i++){
|
|
132
|
-
const tmp:ApiSetting =jsondata[X_DOCUMENT_API][i]
|
|
133
|
-
if(!tmp.action){
|
|
134
|
-
const errmsg = "x-document-api defined but undefine property 'action'"
|
|
135
|
-
log.error(errmsg)
|
|
136
|
-
|
|
137
|
-
throw errmsg
|
|
138
|
-
}
|
|
139
|
-
if(!tmp.method){
|
|
140
|
-
const errmsg = "x-document-api defined but undefine property 'method'"
|
|
141
|
-
log.error(errmsg)
|
|
142
|
-
throw errmsg
|
|
143
|
-
}
|
|
144
|
-
docSetting.apiSettings.push(tmp)
|
|
139
|
+
let isrequired = false
|
|
140
|
+
if(requiredlist && requiredlist.includes(key)){
|
|
141
|
+
isrequired=true
|
|
145
142
|
}
|
|
146
|
-
|
|
147
|
-
if(jsondata[X_DOCUMENT_STATUS] && Array.isArray(jsondata[X_DOCUMENT_STATUS])){
|
|
148
|
-
for(let i=0; i<jsondata[X_DOCUMENT_STATUS].length;i++){
|
|
149
|
-
const tmp:DocStatusSetting =jsondata[X_DOCUMENT_STATUS][i]
|
|
150
|
-
if(tmp.statusCode ===undefined){
|
|
151
|
-
const errmsg = "x-document-status defined but undefine property 'statusCode'"
|
|
152
|
-
log.error(errmsg)
|
|
153
|
-
throw errmsg
|
|
154
|
-
}
|
|
155
|
-
if(!tmp.statusName ===undefined){
|
|
156
|
-
const errmsg = "x-document-status defined but undefine property 'statusName'"
|
|
157
|
-
log.error(errmsg)
|
|
158
|
-
throw errmsg
|
|
159
|
-
}
|
|
160
|
-
docSetting.docStatusSettings.push(tmp)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
143
|
+
const newName: string = _.upperFirst(docname) + _.upperFirst(key);
|
|
163
144
|
|
|
164
145
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
jsondata.properties,
|
|
169
|
-
jsondata['required'] ? jsondata['required'] : [],
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const genSchema = (docname: string,schematype: string,jsondata: JsonSchemaProperties,
|
|
174
|
-
requiredlist: string[] | undefined): SchemaModel => {
|
|
175
|
-
const newmodel: SchemaModel = {};
|
|
176
|
-
const props = Object.getOwnPropertyNames(jsondata ??{});
|
|
177
|
-
// console.log('==== jsondata', jsondata);
|
|
178
|
-
|
|
179
|
-
for (let i = 0; i < props.length; i++) {
|
|
180
|
-
const key = props[i];
|
|
146
|
+
// if(obj[X_AUTOCOMPLETE_FIELD]){
|
|
147
|
+
// docSetting.autocompleteFields.push(key)
|
|
148
|
+
// }
|
|
181
149
|
|
|
182
|
-
//below is Object.assign use for force datatype compatibility
|
|
183
|
-
const obj:JSONSchema7={}
|
|
184
|
-
Object.assign(obj,jsondata[key]);
|
|
185
|
-
const objectitem:JSONSchema7= {} as JSONSchema7
|
|
186
|
-
Object.assign(objectitem,obj.items);
|
|
187
|
-
|
|
188
|
-
const isrequired = requiredlist && requiredlist.includes(key);
|
|
189
|
-
const newName: string = docname + capitalizeFirstLetter(key);
|
|
190
|
-
if(obj.format && obj.format==X_DOCUMENT_NO){
|
|
191
|
-
docSetting.colDocNo=key
|
|
192
|
-
obj.minLength=obj.minLength??1
|
|
193
|
-
jsondata[key]['minLength']=obj.minLength
|
|
194
|
-
}
|
|
195
|
-
if(obj.format && obj.format==X_DOCUMENT_LABEL){
|
|
196
|
-
docSetting.colDocLabel=key
|
|
197
|
-
obj.minLength=obj.minLength??1
|
|
198
|
-
jsondata[key]['minLength']=obj.minLength
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if(obj[X_COLLECTION_NAME]){
|
|
202
|
-
docSetting.collectionName=key
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if(obj[X_AUTOCOMPLETE_FIELD]){
|
|
207
|
-
docSetting.autocompleteFields.push(key)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
150
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
// obj,obj.items
|
|
218
|
-
//foreignkeys
|
|
219
|
-
//FOREIGNKEY_PROPERTY
|
|
220
|
-
// newmodel[key] = 'Object';
|
|
221
|
-
// }
|
|
222
|
-
// else
|
|
223
|
-
if (obj.type == 'object') {
|
|
151
|
+
// if(obj.format && obj.format==FORMAT_TEL){
|
|
152
|
+
// obj.pattern=obj.pattern ?? '/^\d{7,15}$/gm'
|
|
153
|
+
// }
|
|
154
|
+
// if (obj.type == 'object' && obj.items ){
|
|
155
|
+
// console.log("Refer to another object",docname,': ',key,obj,obj.items)
|
|
224
156
|
|
|
157
|
+
// obj,obj.items
|
|
158
|
+
//foreignkeys
|
|
159
|
+
//FOREIGNKEY_PROPERTY
|
|
160
|
+
// newmodel[key] = 'Object';
|
|
161
|
+
// }
|
|
162
|
+
// else
|
|
225
163
|
if(obj[FOREIGNKEY_PROPERTY]){
|
|
226
|
-
// console.warn("FOREIGNKEY_PROPERTY exists",FOREIGNKEY_PROPERTY,obj[FOREIGNKEY_PROPERTY])
|
|
227
164
|
const masterdatacollection = obj[FOREIGNKEY_PROPERTY]
|
|
228
165
|
const clientdatacollection = docname.toLowerCase()
|
|
229
|
-
const foreignkeyidentity= key
|
|
230
|
-
|
|
166
|
+
const foreignkeyidentity= (obj.type=='object')? `${key}._id` : key
|
|
167
|
+
const foreignkeypath = (obj.type=='object') ?`${parentpath}.${key}._id`:`${parentpath}.${key}`
|
|
168
|
+
|
|
169
|
+
//current document foreignkeys
|
|
170
|
+
if(schemaconfigs.foreignKeys[masterdatacollection]){
|
|
171
|
+
schemaconfigs.foreignKeys[masterdatacollection].push(foreignkeypath)
|
|
172
|
+
}else{
|
|
173
|
+
schemaconfigs.foreignKeys[masterdatacollection]=[foreignkeypath]
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
//centralize foreignkeys catalogue
|
|
177
|
+
if(!allforeignkeys[masterdatacollection]){
|
|
231
178
|
let tmp:TypeForeignKey = {} as TypeForeignKey
|
|
232
179
|
tmp[clientdatacollection]=[foreignkeyidentity]
|
|
233
|
-
|
|
180
|
+
allforeignkeys[masterdatacollection] = tmp
|
|
234
181
|
}
|
|
235
|
-
else if(!
|
|
236
|
-
|
|
182
|
+
else if(!allforeignkeys[masterdatacollection][clientdatacollection]){
|
|
183
|
+
allforeignkeys[masterdatacollection][clientdatacollection]=[foreignkeyidentity]
|
|
237
184
|
}else{
|
|
238
|
-
|
|
185
|
+
allforeignkeys[masterdatacollection][clientdatacollection].push(foreignkeyidentity)
|
|
239
186
|
}
|
|
240
187
|
|
|
241
188
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
189
|
+
|
|
190
|
+
if (obj.type == 'object') {
|
|
191
|
+
// console.log("line 175",key,obj.type,obj.properties)
|
|
192
|
+
await genSchema(newName, obj.type, obj.properties, obj.required,`${parentpath}.${key}`,schemaconfigs,allmodels);
|
|
193
|
+
newmodel[key] = newName;
|
|
194
|
+
} else if (obj.type == 'array' && obj.items && objectitem?.type == 'object') {
|
|
195
|
+
const childprops = objectitem?.properties
|
|
196
|
+
if(!childprops['created']){
|
|
197
|
+
childprops['created']={type:'string',description:'iso8601 dataempty mean new record'}
|
|
198
|
+
}
|
|
199
|
+
if(!childprops['updated']){
|
|
200
|
+
childprops['updated']={type:'string',description:'iso8601 or empty'}
|
|
201
|
+
}
|
|
202
|
+
if(!childprops['createdby']){
|
|
203
|
+
childprops['createdby']={type:'string'}
|
|
204
|
+
}
|
|
205
|
+
if(!childprops['updatedby']){
|
|
206
|
+
childprops['updatedby']={type:'string'}
|
|
207
|
+
}
|
|
208
|
+
if(!childprops['_id']){
|
|
209
|
+
childprops['_id']={type:'string'}
|
|
210
|
+
}
|
|
211
|
+
// console.log("line 195")
|
|
212
|
+
await genSchema(newName, obj.type, objectitem?.properties, obj.items['required'],`${parentpath}.${key}[*]`,schemaconfigs,allmodels);
|
|
213
|
+
newmodel[key] = [newName];
|
|
214
|
+
} else if (obj.type == 'array' && objectitem?.type != 'object') {
|
|
215
|
+
//array need submodel
|
|
216
|
+
// genSchema(newName, obj.type, obj.items.properties);
|
|
217
|
+
const objecttype:string = objectitem.type?.toString() ?? 'string'
|
|
218
|
+
newmodel[key] = [objecttype];
|
|
219
|
+
} else {
|
|
220
|
+
newmodel[key] = getField(key, obj, isrequired);
|
|
221
|
+
// console.log(key,'--------newmodel',obj, newmodel[key]);
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
log.warn(newmodel,docname)
|
|
225
|
+
|
|
226
|
+
const modelname= _.upperFirst(docname)
|
|
227
|
+
log.warn("$$$$$$$$$$>>>",modelname,)
|
|
228
|
+
log.warn(newmodel,modelname)
|
|
229
|
+
allmodels[modelname] = {
|
|
230
|
+
type: schematype,
|
|
231
|
+
model: newmodel,
|
|
232
|
+
codeField: schemaconfigs.uniqueKey??'' ,
|
|
233
|
+
nameField: schemaconfigs.documentTitle ?? '',
|
|
234
|
+
moreAutoComplete:schemaconfigs.additionalAutoCompleteFields ?? [],
|
|
235
|
+
docStatusSettings:schemaconfigs.allStatus ?? [],
|
|
236
|
+
apiSettings:schemaconfigs.additionalApis ?? [],
|
|
237
|
+
// requireautocomplete:docSetting.requireautocomplete,
|
|
238
|
+
isolationtype:schemaconfigs.isolationType ,
|
|
239
|
+
hasdocformat:schemaconfigs.generateDocumentNumber ?? false,
|
|
240
|
+
foreignkeys: schemaconfigs.foreignKeys ?? {}
|
|
241
|
+
};
|
|
242
|
+
// console.warn("-------------apiSettings-----",docname,"::::",docSetting.apiSettings)
|
|
243
|
+
return newmodel;
|
|
272
244
|
};
|
|
273
245
|
|
|
246
|
+
|
|
247
|
+
|
|
274
248
|
const getField = (
|
|
275
249
|
fieldname: string,
|
|
276
250
|
obj: JSONSchema7,
|
|
@@ -306,4 +280,3 @@ const getField = (
|
|
|
306
280
|
}
|
|
307
281
|
return f;
|
|
308
282
|
};
|
|
309
|
-
|