@simitgroup/simpleapp-generator 1.4.2-alpha → 1.5.1-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 (72) hide show
  1. package/README.md +3 -1
  2. package/dist/buildinschemas/autoincreament.d.ts.map +1 -1
  3. package/dist/buildinschemas/autoincreament.js +1 -0
  4. package/dist/buildinschemas/autoincreament.js.map +1 -1
  5. package/dist/buildinschemas/docnoformat.d.ts.map +1 -1
  6. package/dist/buildinschemas/docnoformat.js +1 -0
  7. package/dist/buildinschemas/docnoformat.js.map +1 -1
  8. package/dist/buildinschemas/permission.d.ts.map +1 -1
  9. package/dist/buildinschemas/permission.js +1 -8
  10. package/dist/buildinschemas/permission.js.map +1 -1
  11. package/dist/framework.d.ts.map +1 -1
  12. package/dist/framework.js +4 -2
  13. package/dist/framework.js.map +1 -1
  14. package/dist/generate.js +6 -4
  15. package/dist/generate.js.map +1 -1
  16. package/dist/processors/bpmnbuilder.d.ts.map +1 -1
  17. package/dist/processors/bpmnbuilder.js +10 -4
  18. package/dist/processors/bpmnbuilder.js.map +1 -1
  19. package/dist/processors/jsonschemabuilder.d.ts.map +1 -1
  20. package/dist/processors/jsonschemabuilder.js +9 -0
  21. package/dist/processors/jsonschemabuilder.js.map +1 -1
  22. package/package.json +1 -1
  23. package/src/buildinschemas/autoincreament.ts +1 -0
  24. package/src/buildinschemas/docnoformat.ts +1 -0
  25. package/src/buildinschemas/permission.ts +1 -8
  26. package/src/framework.ts +5 -4
  27. package/src/generate.ts +7 -6
  28. package/src/processors/bpmnbuilder.ts +10 -5
  29. package/src/processors/jsonschemabuilder.ts +10 -0
  30. package/templates/basic/nest/apischema.ts.eta +5 -0
  31. package/templates/basic/nest/controller.ts.eta +31 -12
  32. package/templates/basic/nest/resolver.ts.eta +124 -0
  33. package/templates/basic/nest/service.ts.eta +0 -6
  34. package/templates/nest/.env._eta +7 -7
  35. package/templates/nest/src/app.module.ts.eta +24 -21
  36. package/templates/nest/src/app.resolver.ts.eta +9 -0
  37. package/templates/nest/src/cloudapi/cloudapi.module.ts._eta +15 -0
  38. package/templates/nest/src/cloudapi/cloudapi.service.ts._eta +15 -0
  39. package/templates/nest/src/simpleapp/apischemas/index.ts._eta +15 -1
  40. package/templates/nest/src/simpleapp/generate/commons/decorators/appuser.decorator.ts.eta +11 -5
  41. package/templates/nest/src/simpleapp/generate/commons/interceptors/response.interceptor.ts.eta +44 -39
  42. package/templates/nest/src/simpleapp/generate/commons/middlewares/tenant.middleware.ts.eta +16 -4
  43. package/templates/nest/src/simpleapp/generate/commons/robotuser.service.ts.eta +112 -0
  44. package/templates/nest/src/simpleapp/generate/commons/roles/roles.guard.ts.eta +24 -12
  45. package/templates/nest/src/simpleapp/generate/commons/user.context.ts.eta +4 -1
  46. package/templates/nest/src/simpleapp/generate/processors/simpleapp.processor.ts.eta +12 -5
  47. package/templates/nest/src/simpleapp/generate/types/index.ts.eta +1 -1
  48. package/templates/nest/src/simpleapp/generate/types/schema.type.ts.eta +191 -0
  49. package/templates/nest/src/simpleapp/generate/types/simpleapp.type.ts.eta +200 -5
  50. package/templates/nest/src/simpleapp/generate/types/workflow.type.ts.eta +15 -0
  51. package/templates/nest/src/simpleapp/generate/workflow/workflow.config.ts.eta +3 -3
  52. package/templates/nest/src/simpleapp/generate/workflow/workflow.controller.ts.eta +8 -6
  53. package/templates/nest/src/simpleapp/generate/workflow/workflow.service.ts.eta +60 -23
  54. package/templates/nest/src/simpleapp/resolvers/readme.md.eta +1 -0
  55. package/templates/nest/src/simpleapp/simpleapp.module.ts.eta +13 -3
  56. package/templates/nest/src/simpleapp/types/index.ts._eta +6 -0
  57. package/templates/nest/src/simpleapp/workflows/listeners/simpleapp.listener.ts.eta +31 -0
  58. package/templates/nuxt/app.vue._eta +8 -2
  59. package/templates/nuxt/assets/primevue/passthrough.ts._eta +1 -1
  60. package/templates/nuxt/components/renderer/RendererMoney.vue.eta +21 -12
  61. package/templates/nuxt/composables/graphquery.generate.ts.eta +26 -0
  62. package/templates/nuxt/composables/refreshDocumentList.generate.ts.eta +7 -6
  63. package/templates/nuxt/layouts/mobile.vue._eta +2 -2
  64. package/templates/nuxt/nuxt.config.ts._eta +8 -0
  65. package/templates/nuxt/pages/[xorg]/index.vue._eta +9 -0
  66. package/templates/nuxt/pages/[xorg]/mobile/index.vue._eta +2 -15
  67. package/templates/nuxt/pages/picktenant.vue._eta +3 -1
  68. package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +2 -0
  69. package/templates/nuxt/types/events.ts.eta +4 -3
  70. package/templates/project/workflows/bpmn/{suspendcustomer.bpmn._eta → sayhello.bpmn._eta} +6 -36
  71. package/tsconfig.tsbuildinfo +1 -1
  72. package/templates/nest/src/simpleapp/workflows/listeners/simpleapp.listener.ts._eta +0 -26
@@ -0,0 +1,112 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator.
3
+ * DONT CHANGE THIS FILE !!
4
+ * MODIFICATION OVERRIDE BY GENERATEOR
5
+ * last change 2024-03-19
6
+ * Author: Ks Tan
7
+ */
8
+ import { Injectable, Logger } from '@nestjs/common';
9
+ import { InjectModel } from '@nestjs/mongoose';
10
+ import { Model } from 'mongoose';
11
+ import { UserContext } from 'src/simpleapp/generate/commons/user.context';
12
+ import { User } from 'src/simpleapp/services/user.service';
13
+ import { Permission } from 'src/simpleapp/services/perm.service';
14
+
15
+ @Injectable()
16
+ export class SimpleAppRobotUserService {
17
+ private systemAccessToken: string;
18
+ private setToken = (token:string) => this.systemAccessToken = token
19
+ private getToken = ()=>this.systemAccessToken
20
+ private expired: string;
21
+ logger = new Logger();
22
+ @InjectModel('User') private readonly usermodel: Model<User>;
23
+ @InjectModel('Permission') private readonly permmodel: Model<Permission>;
24
+
25
+ constructor() {
26
+ this.init();
27
+ // console.log('init SimpleAppRobotUserService');
28
+ }
29
+
30
+ async init() {
31
+ await this.refreshSystemToken();
32
+ }
33
+ async refreshSystemToken() {
34
+ enum GrantType {
35
+ 'client_credentials' = 'client_credentials',
36
+ 'password' = 'password',
37
+ }
38
+
39
+ type KeycloakAuthModel = {
40
+ client_id: string;
41
+ client_secret: string;
42
+ username: string;
43
+ password: string;
44
+ grant_type: GrantType;
45
+ };
46
+
47
+ const keycloakdata: KeycloakAuthModel = {
48
+ client_id: process.env.OAUTH2_CLIENTID,
49
+ client_secret: process.env.OAUTH2_CLIENTSECRET,
50
+ username: process.env.OAUTH2_CLOUDAPI_USER,
51
+ password: process.env.OAUTH2_CLOUDAPI_PASSWORD,
52
+ grant_type: GrantType.password,
53
+ };
54
+ const body = new URLSearchParams(keycloakdata);
55
+
56
+ const mybody = new FormData();
57
+ mybody.append('grant_type', 'password');
58
+ mybody.append('client_id', process.env.OAUTH2_CLIENTID);
59
+ mybody.append('client_secret', process.env.OAUTH2_CLIENTSECRET);
60
+ mybody.append('username', process.env.OAUTH2_CLOUDAPI_USER);
61
+ mybody.append('password', process.env.OAUTH2_CLOUDAPI_PASSWORD);
62
+
63
+ const ssoendpoint = `${process.env.OAUTH2_CONFIGURL}/protocol/openid-connect/token`;
64
+
65
+ const tokens = await fetch(ssoendpoint, {
66
+ method: 'POST',
67
+ headers: {
68
+ 'Content-Type': 'application/x-www-form-urlencoded',
69
+ },
70
+ body: body.toString(),
71
+ })
72
+ .then((response) => {
73
+ return response.json();
74
+ })
75
+ .then((data) => {
76
+ return data;
77
+ });
78
+
79
+ this.setToken(tokens.access_token)
80
+ // console.log("access token ",this.getToken())
81
+ const nextrefresh = tokens.expires_in * 0.8;
82
+ const appuser = this.prepareAppUser(undefined);
83
+
84
+
85
+ setTimeout(async () => {
86
+ await this.refreshSystemToken();
87
+ }, nextrefresh * 1000);
88
+ }
89
+
90
+ prepareAppUser(data: any) {
91
+ const appuser = new UserContext(this.usermodel, this.permmodel);
92
+ appuser.setAsStaticUser(
93
+ '00000000-0000-0000-0000-000000000000',
94
+ 'robot',
95
+ 'Robot',
96
+ 'robot@a.org',
97
+ );
98
+
99
+ const tenantId = data?.tenantId ?? 0;
100
+ const orgId = data?.orgId ?? 0;
101
+ const branchId = data?.branchId ?? 0;
102
+
103
+ appuser.setXorg(appuser.generateXorg(tenantId, orgId, branchId));
104
+ appuser.setUserToken(this.getToken());
105
+ // console.log(
106
+ // 'return user ' + appuser.getUname(),
107
+ // appuser.getXorg(),
108
+ // appuser.getUserToken().length,
109
+ // );
110
+ return appuser;
111
+ }
112
+ }
@@ -1,13 +1,19 @@
1
1
  /**
2
2
  * This file was automatically generated by simpleapp generator. Every
3
3
  * MODIFICATION OVERRIDE BY GENERATEOR
4
- * last change 2023-10-28
4
+ * last change 2024-03-17
5
5
  * Author: Ks Tan
6
6
  */
7
- import { Injectable, Inject, CanActivate, ExecutionContext, Scope } from '@nestjs/common';
7
+ import {
8
+ Injectable,
9
+ Inject,
10
+ CanActivate,
11
+ ExecutionContext,
12
+ Scope,
13
+ } from '@nestjs/common';
8
14
  import { Reflector } from '@nestjs/core';
9
- import { Role } from './roles.enum'
10
- import { ROLES_KEY } from './roles.decorator'
15
+ import { Role } from './roles.enum';
16
+ import { ROLES_KEY } from './roles.decorator';
11
17
  import { UserContext } from '../user.context';
12
18
 
13
19
  @Injectable()
@@ -15,25 +21,31 @@ export class RolesGuard implements CanActivate {
15
21
  constructor(private reflector: Reflector) {}
16
22
 
17
23
  canActivate(context: ExecutionContext): boolean {
18
-
19
24
  const requiredRoles = this.reflector.getAllAndOverride<Role[]>(ROLES_KEY, [
20
25
  context.getHandler(),
21
26
  context.getClass(),
22
27
  ]);
23
28
 
24
- const sessionuser = context.switchToHttp().getRequest()['sessionuser']
29
+ let sessionuser:UserContext
30
+ if (context.getType() == 'http') {
31
+ const request = context.switchToHttp().getRequest();
32
+ sessionuser = request['sessionuser'];
33
+ } else if (context.getArgs()[2]) {
34
+ const req = context.getArgs()[2].req;
35
+ sessionuser = req['sessionuser'];
36
+ }
25
37
 
26
38
  if (!requiredRoles) {
27
39
  return true;
28
40
  }
29
-
30
- const roles = sessionuser.getRoles()
31
- if(!roles){
32
- return false
41
+
42
+ const roles = sessionuser.getRoles();
43
+ if (!roles) {
44
+ return false;
33
45
  }
34
46
  const result = requiredRoles.some((role) => roles.includes(role));
35
47
 
36
- return result
48
+ return result;
37
49
  // return true
38
50
  }
39
- }
51
+ }
@@ -44,7 +44,7 @@ export class UserContext {
44
44
  protected uname: string = '';
45
45
  protected email: string = '';
46
46
  protected fullname: string = '';
47
- protected xOrg: string = '';
47
+ protected xOrg: string = '';
48
48
  protected tenantId: number = 0;
49
49
  protected orgId: number = 0;
50
50
  protected orgRecordId: string = '';
@@ -252,6 +252,7 @@ export class UserContext {
252
252
  return undefined;
253
253
  }
254
254
  };
255
+ getUserToken = () => this.token
255
256
  setUserToken = async (tokenstr: string) => {
256
257
  //define token info
257
258
  const tokeninfo = jwt.decode(tokenstr);
@@ -363,7 +364,9 @@ export class UserContext {
363
364
  this.orgId = orgId;
364
365
  this.branchId = branchId;
365
366
  }
367
+ getXorg = () =>this.xOrg
366
368
  setXorg = (xorg) => {
369
+ this.xOrg = xorg
367
370
  try {
368
371
  const decodedText: string = Base64URL.decodeText(xorg);
369
372
  const x = decodedText.includes('/')
@@ -37,6 +37,7 @@ import {
37
37
  DefaultHooks,
38
38
  MoreProjectionType,
39
39
  DeleteResultType,
40
+ WorkflowName,
40
41
  } from '../types';
41
42
  @Injectable()
42
43
  export class SimpleAppService<T extends { _id?: string }> {
@@ -555,12 +556,13 @@ export class SimpleAppService<T extends { _id?: string }> {
555
556
  this.applyNestedDateTime(appuser, data, 'update');
556
557
  try {
557
558
  const result = await this.doc.findOneAndReplace(isolationFilter, data, {
558
- session: dbsession,new:true
559
+ session: dbsession,
560
+ new: true,
559
561
  });
560
562
  appuser.addUpdatedRecordId(this.documentName, data._id);
561
563
  if (this.hooks.afterUpdate)
562
564
  await this.hooks.afterUpdate(appuser, id, result);
563
- return await this.findById(appuser, id);
565
+ return result // await this.findById(appuser, id);
564
566
  } catch (err) {
565
567
  this.logger.error(err);
566
568
  throw new InternalServerErrorException(err.message);
@@ -605,14 +607,15 @@ export class SimpleAppService<T extends { _id?: string }> {
605
607
 
606
608
  try {
607
609
  const result = await this.doc.findOneAndUpdate(isolationFilter, data, {
608
- session: dbsession,new:true
610
+ session: dbsession,
611
+ new: true,
609
612
  });
610
613
 
611
614
  appuser.addUpdatedRecordId(this.documentName, data._id);
612
615
 
613
616
  if (this.hooks.afterUpdate)
614
617
  await this.hooks.afterUpdate(appuser, id, result);
615
- return await this.findById(appuser, id);
618
+ return result //await this.findById(appuser, id);
616
619
  } catch (err) {
617
620
  throw new InternalServerErrorException(err.message);
618
621
  }
@@ -719,7 +722,11 @@ export class SimpleAppService<T extends { _id?: string }> {
719
722
  }
720
723
  }
721
724
 
722
- startWorkflow(appuser: UserContext, processName: string, workflowData: any) {
725
+ startWorkflow(
726
+ appuser: UserContext,
727
+ processName: WorkflowName,
728
+ workflowData: any,
729
+ ) {
723
730
  return this.eventEmitter.emit(
724
731
  'workflow.start',
725
732
  appuser,
@@ -3,5 +3,5 @@
3
3
  export * from './<%= d['doctype']%>.type'
4
4
  <%}%>
5
5
  export * from './simpleapp.type'
6
-
6
+ export * from './workflow.type'
7
7
  export * from '../../types';
@@ -0,0 +1,191 @@
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
+ import { JSONSchema7,JSONSchema7Type,JSONSchema7Version, JSONSchema7TypeName,JSONSchema7Definition } from 'json-schema';
8
+ export type DocumentStatus = {
9
+ status:string //'CO', 'V', 'CL', 'D' and etc
10
+ statusName:string
11
+ readOnly:boolean
12
+ actions: string[] //api name ['confirm','revert','close','void' and etc]
13
+ }
14
+ export enum RESTMethods {'post'='post','get'='get', 'delete'='delete','put'='put', 'patch'='patch'}
15
+ export type DocumentApi = {
16
+ action:string //api action name
17
+ entryPoint:string //api entry point example:':id', ':id/confirm'
18
+ queryPara?:string[] //what query parameter wish to accept, example: ['description','date']
19
+ requiredRole?: string[] // what special user role wish to allow for this api, example: ['SuperUser']
20
+ workflowSetting?: {bpmn:string} //optional property, once define code gen connect the bpmn workflow
21
+ method:RESTMethods
22
+ schema?:string //any schema/type name in types & apischemas
23
+ responseType?:string //any schema/type name for response
24
+ description:string //description of api
25
+ }
26
+ export enum IsolationType {"none"="none" , "tenant"="tenant","org"="org", "branch"="branch"}
27
+ // export type ImportLibs = {"lib":string,"as":string}
28
+ export type Formula = {
29
+ jsonPath:string //example: "$.subtotal","$.details[*]"
30
+ formula:string //example "jslib.getDocumentSubTotal(@F{$.details})"
31
+ }
32
+ export type SchemaConfig = {
33
+ isolationType: IsolationType
34
+ requiredRoles?:string[]
35
+ pageType?: string
36
+ uniqueKey?:string
37
+ uniqueKeys?:string[][]
38
+ documentTitle?:string
39
+ generateDocumentNumber?:boolean
40
+ documentDate?:string
41
+ allStatus?:DocumentStatus[]
42
+ additionalApis?:DocumentApi[]
43
+ additionalAutoCompleteFields ?: string[]
44
+ // libs?:ImportLibs[] // both process class and frontend client class will import same lib
45
+ formulas?: Formula[]
46
+ documentType: string
47
+ documentName: string
48
+ collectionName?: string
49
+ foreignKeys?:MyForeignKey,
50
+ }
51
+ export type MyForeignKey = {
52
+ [collectionname:string]:string[]
53
+ }
54
+
55
+ export type SchemaType = {
56
+ type:string
57
+ definitions?:SimpleAppJSONSchema7
58
+ required?:string[]
59
+
60
+ "x-simpleapp-config":SchemaConfig
61
+ properties: SchemaFields
62
+ }
63
+
64
+
65
+ export type SchemaFields = {
66
+ _id: SimpleAppJSONSchema7
67
+ tenantId: SimpleAppJSONSchema7
68
+ orgId: SimpleAppJSONSchema7
69
+ branchId: SimpleAppJSONSchema7
70
+ created: SimpleAppJSONSchema7
71
+ updated: SimpleAppJSONSchema7
72
+ createdBy: SimpleAppJSONSchema7
73
+ updatedBy: SimpleAppJSONSchema7
74
+ [key:string]:SimpleAppJSONSchema7 | SimpleAppJSONSchema7[] | undefined
75
+
76
+ }
77
+
78
+
79
+
80
+ // modified from jsonschemas
81
+ export type SimpleAppJSONSchema7Definition = SimpleAppJSONSchema7 | boolean;
82
+ export interface SimpleAppJSONSchema7 {
83
+
84
+ 'x-foreignkey' ?:string
85
+ $id?: string | undefined;
86
+ $ref?: string | undefined;
87
+ $schema?: JSONSchema7Version | undefined;
88
+ $comment?: string | undefined;
89
+
90
+ /**
91
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
92
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
93
+ */
94
+ $defs?: {
95
+ [key: string]: JSONSchema7Definition;
96
+ } | undefined;
97
+
98
+ /**
99
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
100
+ */
101
+ type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
102
+ enum?: JSONSchema7Type[] | undefined;
103
+ const?: JSONSchema7Type | undefined;
104
+
105
+ /**
106
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
107
+ */
108
+ multipleOf?: number | undefined;
109
+ maximum?: number | undefined;
110
+ exclusiveMaximum?: number | undefined;
111
+ minimum?: number | undefined;
112
+ exclusiveMinimum?: number | undefined;
113
+
114
+ /**
115
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
116
+ */
117
+ maxLength?: number | undefined;
118
+ minLength?: number | undefined;
119
+ pattern?: string | undefined;
120
+
121
+ /**
122
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
123
+ */
124
+ items?: SimpleAppJSONSchema7Definition | SimpleAppJSONSchema7Definition[] | undefined;
125
+ additionalItems?: JSONSchema7Definition | undefined;
126
+ maxItems?: number | undefined;
127
+ minItems?: number | undefined;
128
+ uniqueItems?: boolean | undefined;
129
+ contains?: SimpleAppJSONSchema7Definition | undefined;
130
+
131
+ /**
132
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
133
+ */
134
+ maxProperties?: number | undefined;
135
+ minProperties?: number | undefined;
136
+ required?: string[] | undefined;
137
+ properties?: {
138
+ [key: string]: SimpleAppJSONSchema7Definition;
139
+ } | undefined;
140
+ patternProperties?: {
141
+ [key: string]: SimpleAppJSONSchema7Definition;
142
+ } | undefined;
143
+ additionalProperties?: SimpleAppJSONSchema7Definition | undefined;
144
+ dependencies?: {
145
+ [key: string]: SimpleAppJSONSchema7Definition | string[];
146
+ } | undefined;
147
+ propertyNames?: SimpleAppJSONSchema7Definition | undefined;
148
+
149
+ /**
150
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
151
+ */
152
+ if?: SimpleAppJSONSchema7Definition | undefined;
153
+ then?: SimpleAppJSONSchema7Definition | undefined;
154
+ else?: SimpleAppJSONSchema7Definition | undefined;
155
+
156
+ /**
157
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
158
+ */
159
+ allOf?: SimpleAppJSONSchema7Definition[] | undefined;
160
+ anyOf?: SimpleAppJSONSchema7Definition[] | undefined;
161
+ oneOf?: SimpleAppJSONSchema7Definition[] | undefined;
162
+ not?: SimpleAppJSONSchema7Definition | undefined;
163
+
164
+ /**
165
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
166
+ */
167
+ format?: string | undefined;
168
+
169
+ /**
170
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
171
+ */
172
+ contentMediaType?: string | undefined;
173
+ contentEncoding?: string | undefined;
174
+
175
+ /**
176
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
177
+ */
178
+ definitions?: {
179
+ [key: string]: JSONSchema7Definition;
180
+ } | undefined;
181
+
182
+ /**
183
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
184
+ */
185
+ title?: string | undefined;
186
+ description?: string | undefined;
187
+ default?: JSONSchema7Type | undefined;
188
+ readOnly?: boolean | undefined;
189
+ writeOnly?: boolean | undefined;
190
+ examples?: JSONSchema7Type | undefined;
191
+ }
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * This file was automatically generated by simpleapp generator. Every
3
3
  * MODIFICATION OVERRIDE BY GENERATEOR
4
- * last change 2024-01-25
4
+ * last change 2024-04-18
5
5
  * Author: Ks Tan
6
6
  */
7
- import { UserContext } from '../commons/user.context'
8
-
7
+ import { UserContext } from '../commons/user.context';
8
+ import { JSONSchema7,JSONSchema7Type,JSONSchema7Version, JSONSchema7TypeName,JSONSchema7Definition } from 'json-schema';
9
9
 
10
10
  export type ModifiedCollection = {
11
11
  [key: string]: string[];
@@ -43,9 +43,18 @@ export type DefaultHooks<T> = {
43
43
  afterValidation?: (appuser: UserContext, data: T) => Promise<void>;
44
44
  beforeCreate?: (appuser: UserContext, data: T) => Promise<void>;
45
45
  afterCreate?: (appuser: UserContext, data: T) => Promise<void>;
46
- beforeUpdate?: (appuser: UserContext, id: string, data: T, existingdata:T) => Promise<void>;
46
+ beforeUpdate?: (
47
+ appuser: UserContext,
48
+ id: string,
49
+ data: T,
50
+ existingdata: T,
51
+ ) => Promise<void>;
47
52
  afterUpdate?: (appuser: UserContext, id: string, data: T) => Promise<void>;
48
- beforeDelete?: (appuser: UserContext, id: string,deletedata:T) => Promise<void>;
53
+ beforeDelete?: (
54
+ appuser: UserContext,
55
+ id: string,
56
+ deletedata: T,
57
+ ) => Promise<void>;
49
58
  afterDelete?: (
50
59
  appuser: UserContext,
51
60
  result: DeleteResultType<T>,
@@ -88,3 +97,189 @@ export type DeleteResultType<T> = {
88
97
  deletedCount: number;
89
98
  };
90
99
  };
100
+
101
+
102
+ export type DocumentStatus = {
103
+ status:string //'CO', 'V', 'CL', 'D' and etc
104
+ statusName:string
105
+ readOnly:boolean
106
+ actions: string[] //api name ['confirm','revert','close','void' and etc]
107
+ }
108
+ export enum RESTMethods {'post'='post','get'='get', 'delete'='delete','put'='put', 'patch'='patch'}
109
+ export type DocumentApi = {
110
+ action:string //api action name
111
+ entryPoint:string //api entry point example:':id', ':id/confirm'
112
+ queryPara?:string[] //what query parameter wish to accept, example: ['description','date']
113
+ requiredRole?: string[] // what special user role wish to allow for this api, example: ['SuperUser']
114
+ workflowSetting?: {bpmn:string} //optional property, once define code gen connect the bpmn workflow
115
+ method:RESTMethods
116
+ schema?:string //any schema/type name in types & apischemas
117
+ responseType?:string //any schema/type name for response
118
+ description:string //description of api
119
+ }
120
+ //export enum IsolationType {"none"="none" , "tenant"="tenant","org"="org", "branch"="branch"}
121
+ // export type ImportLibs = {"lib":string,"as":string}
122
+ export type Formula = {
123
+ jsonPath:string //example: "$.subtotal","$.details[*]"
124
+ formula:string //example "jslib.getDocumentSubTotal(@F{$.details})"
125
+ }
126
+ export type SchemaConfig = {
127
+ isolationType: IsolationType
128
+ requiredRoles?:string[]
129
+ pageType?: string
130
+ uniqueKey?:string
131
+ uniqueKeys?:string[][]
132
+ documentTitle?:string
133
+ generateDocumentNumber?:boolean
134
+ documentDate?:string
135
+ allStatus?:DocumentStatus[]
136
+ additionalApis?:DocumentApi[]
137
+ additionalAutoCompleteFields ?: string[]
138
+ // libs?:ImportLibs[] // both process class and frontend client class will import same lib
139
+ formulas?: Formula[]
140
+ documentType: string
141
+ documentName: string
142
+ collectionName?: string
143
+ foreignKeys?:MyForeignKey,
144
+ }
145
+ export type MyForeignKey = {
146
+ [collectionname:string]:string[]
147
+ }
148
+
149
+ export type SchemaType = {
150
+ type:string
151
+ definitions?:SimpleAppJSONSchema7
152
+ required?:string[]
153
+
154
+ "x-simpleapp-config":SchemaConfig
155
+ properties: SchemaFields
156
+ }
157
+
158
+
159
+ export type SchemaFields = {
160
+ _id: SimpleAppJSONSchema7
161
+ tenantId: SimpleAppJSONSchema7
162
+ orgId: SimpleAppJSONSchema7
163
+ branchId: SimpleAppJSONSchema7
164
+ created: SimpleAppJSONSchema7
165
+ updated: SimpleAppJSONSchema7
166
+ createdBy: SimpleAppJSONSchema7
167
+ updatedBy: SimpleAppJSONSchema7
168
+ [key:string]:SimpleAppJSONSchema7 | SimpleAppJSONSchema7[] | undefined
169
+
170
+ }
171
+
172
+
173
+
174
+ // modified from jsonschemas
175
+ export type SimpleAppJSONSchema7Definition = SimpleAppJSONSchema7 | boolean;
176
+ export interface SimpleAppJSONSchema7 {
177
+
178
+ 'x-foreignkey' ?:string
179
+ $id?: string | undefined;
180
+ $ref?: string | undefined;
181
+ $schema?: JSONSchema7Version | undefined;
182
+ $comment?: string | undefined;
183
+
184
+ /**
185
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
186
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
187
+ */
188
+ $defs?: {
189
+ [key: string]: JSONSchema7Definition;
190
+ } | undefined;
191
+
192
+ /**
193
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
194
+ */
195
+ type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
196
+ enum?: JSONSchema7Type[] | undefined;
197
+ const?: JSONSchema7Type | undefined;
198
+
199
+ /**
200
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
201
+ */
202
+ multipleOf?: number | undefined;
203
+ maximum?: number | undefined;
204
+ exclusiveMaximum?: number | undefined;
205
+ minimum?: number | undefined;
206
+ exclusiveMinimum?: number | undefined;
207
+
208
+ /**
209
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
210
+ */
211
+ maxLength?: number | undefined;
212
+ minLength?: number | undefined;
213
+ pattern?: string | undefined;
214
+
215
+ /**
216
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
217
+ */
218
+ items?: SimpleAppJSONSchema7Definition | SimpleAppJSONSchema7Definition[] | undefined;
219
+ additionalItems?: JSONSchema7Definition | undefined;
220
+ maxItems?: number | undefined;
221
+ minItems?: number | undefined;
222
+ uniqueItems?: boolean | undefined;
223
+ contains?: SimpleAppJSONSchema7Definition | undefined;
224
+
225
+ /**
226
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
227
+ */
228
+ maxProperties?: number | undefined;
229
+ minProperties?: number | undefined;
230
+ required?: string[] | undefined;
231
+ properties?: {
232
+ [key: string]: SimpleAppJSONSchema7Definition;
233
+ } | undefined;
234
+ patternProperties?: {
235
+ [key: string]: SimpleAppJSONSchema7Definition;
236
+ } | undefined;
237
+ additionalProperties?: SimpleAppJSONSchema7Definition | undefined;
238
+ dependencies?: {
239
+ [key: string]: SimpleAppJSONSchema7Definition | string[];
240
+ } | undefined;
241
+ propertyNames?: SimpleAppJSONSchema7Definition | undefined;
242
+
243
+ /**
244
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
245
+ */
246
+ if?: SimpleAppJSONSchema7Definition | undefined;
247
+ then?: SimpleAppJSONSchema7Definition | undefined;
248
+ else?: SimpleAppJSONSchema7Definition | undefined;
249
+
250
+ /**
251
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
252
+ */
253
+ allOf?: SimpleAppJSONSchema7Definition[] | undefined;
254
+ anyOf?: SimpleAppJSONSchema7Definition[] | undefined;
255
+ oneOf?: SimpleAppJSONSchema7Definition[] | undefined;
256
+ not?: SimpleAppJSONSchema7Definition | undefined;
257
+
258
+ /**
259
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
260
+ */
261
+ format?: string | undefined;
262
+
263
+ /**
264
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
265
+ */
266
+ contentMediaType?: string | undefined;
267
+ contentEncoding?: string | undefined;
268
+
269
+ /**
270
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
271
+ */
272
+ definitions?: {
273
+ [key: string]: JSONSchema7Definition;
274
+ } | undefined;
275
+
276
+ /**
277
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
278
+ */
279
+ title?: string | undefined;
280
+ description?: string | undefined;
281
+ default?: JSONSchema7Type | undefined;
282
+ readOnly?: boolean | undefined;
283
+ writeOnly?: boolean | undefined;
284
+ examples?: JSONSchema7Type | undefined;
285
+ }