chyz 1.0.13-rc.20 → 1.0.13-rc.21

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/BaseChyz.ts CHANGED
@@ -3,7 +3,8 @@ import {RouteDefinition} from "./model/RouteDefinition";
3
3
  import {NextFunction, Request, Response} from "express";
4
4
  import {Controller} from "./base/Controller";
5
5
  import Utils from "./requiments/Utils";
6
- import {ModelManager} from "./base";
6
+ import {BaseError, ModelManager} from "./base";
7
+ import {Exception} from "./base/db/Exception";
7
8
 
8
9
 
9
10
  const express = require("express");
@@ -23,7 +24,7 @@ export default class BaseChyz {
23
24
  private _port: number = 3001;
24
25
  static db: any;
25
26
  static routes: any;
26
- private static _validate:any=validate;
27
+ private static _validate: any = validate;
27
28
  private _logConfig: any = require('./log/config/log4js.json') ?? {}
28
29
  private _controllerpath: string = "Controllers"
29
30
  private static controllers: Array<Controller> = []
@@ -48,8 +49,7 @@ export default class BaseChyz {
48
49
  }
49
50
 
50
51
  init() {
51
- this.logProvider().level = log4js.levels.ALL;
52
- this.logProvider().configure(this._logConfig);
52
+
53
53
 
54
54
  /**
55
55
  * set request id
@@ -140,16 +140,21 @@ export default class BaseChyz {
140
140
  this.config = config;
141
141
 
142
142
 
143
+ // logger settin
144
+ this.logProvider().level = log4js.levels.ALL;
145
+ this.logProvider().configure(this._logConfig);
146
+
143
147
  let components = Utils.findKeyValue(config, "components")
144
148
  if (components) {
145
149
  for (const componentsKey in components) {
150
+
146
151
  let comp = components[componentsKey];
147
- BaseChyz.logs().info("Create Component ", componentsKey)
152
+ BaseChyz.debug("Create Component ", componentsKey)
148
153
  try {
149
154
  BaseChyz.components[componentsKey] = Utils.createObject(new comp.class, comp);
150
155
  BaseChyz.components[componentsKey]?.init();
151
- }catch (e) {
152
- console.error(e)
156
+ } catch (e) {
157
+ BaseChyz.error("Create Component ", e)
153
158
  }
154
159
 
155
160
  }
@@ -166,7 +171,6 @@ export default class BaseChyz {
166
171
  }
167
172
  }
168
173
 
169
-
170
174
  this.init();
171
175
 
172
176
  return this;
@@ -263,14 +267,14 @@ export default class BaseChyz {
263
267
  // @ts-ignore
264
268
  let className = file.split(".")[0] + "Class";
265
269
  if (model[className])
266
- models[className.replace("Class","")] = new model[className];
270
+ models[className.replace("Class", "")] = new model[className];
267
271
  }
268
272
  })
269
273
 
270
274
  ModelManager._register(models);
271
275
 
272
276
  for (const key of Object.keys(ModelManager)) {
273
- if(key!="_register"){
277
+ if (key != "_register") {
274
278
  ModelManager[key].init();
275
279
  }
276
280
  }
@@ -310,7 +314,7 @@ export default class BaseChyz {
310
314
  BaseChyz.debug(`Call Request id ${instance.id}`)
311
315
  await instance.beforeAction(route, req, res)
312
316
  next()
313
- } catch (e) {
317
+ } catch (e: any) {
314
318
  BaseChyz.error(e);
315
319
 
316
320
  res.status(e.statusCode || 500)
package/Examples/index.ts CHANGED
@@ -18,11 +18,9 @@ import {AuthManager} from "../rbac/AuthManager";
18
18
 
19
19
  let config = {
20
20
  port: process.env.PORT,
21
- controllerpath: "C:\\PROJELER\\github\\Chy-Nodejs-Framework\\Examples\\Controllers",
21
+ controllerpath:process.env.CONTROLLER_PATH,
22
22
  components: {
23
- authManager: {
24
- class: AuthManager,
25
- },
23
+
26
24
  db: {
27
25
  class: DbConnection,
28
26
  database: process.env.DBDATABASE,
@@ -35,6 +33,21 @@ let config = {
35
33
  logging: (msg: any) => BaseChyz.debug(msg)
36
34
  }
37
35
  },
36
+ db2: {
37
+ class: DbConnection,
38
+ database: process.env.DBDATABASE,
39
+ username: process.env.DBUSER,
40
+ password: process.env.DBPASS,
41
+ options: {
42
+ host: process.env.DBHOST,
43
+ dialect: 'postgres', /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
44
+ // disable logging; default: console.log
45
+ logging: (msg:any) => BaseChyz.debug('DB2',msg)
46
+ }
47
+ },
48
+ authManager: {
49
+ class: AuthManager,
50
+ },
38
51
  user: {
39
52
  'class': WebUser,
40
53
  'identityClass': User
package/base/BaseError.ts CHANGED
@@ -15,7 +15,7 @@ export class BaseError extends Error {
15
15
  this.message= Utils.isString(message)?message: JSON.stringify(message);
16
16
  this.name = this.constructor.name // good practice
17
17
  this.statusCode = statusCode // error code for responding to client
18
- Error.captureStackTrace(this)
18
+ //Error.captureStackTrace(this)
19
19
  }
20
20
 
21
21
  toString(){
package/base/Model.ts CHANGED
@@ -9,7 +9,16 @@ import BaseChyz from "../BaseChyz";
9
9
  import Utils from "../requiments/Utils";
10
10
  import {Component} from "./Component";
11
11
  import {InvalidConfigException} from "./InvalidConfigException";
12
- import {DatabaseError, DataTypes, ExclusionConstraintError, ForeignKeyConstraintError, Model as SModel, TimeoutError, UniqueConstraintError, ValidationError,} from "sequelize";
12
+ import {
13
+ DatabaseError,
14
+ DataTypes,
15
+ ExclusionConstraintError,
16
+ ForeignKeyConstraintError,
17
+ Model as SModel,
18
+ TimeoutError,
19
+ UniqueConstraintError,
20
+ ValidationError,
21
+ } from "sequelize";
13
22
  import {Exception} from "./db/Exception";
14
23
 
15
24
  export {DataTypes, NOW} from "sequelize";
@@ -91,11 +100,13 @@ export class Model extends Component {
91
100
  constructor(sequelize?: IDBDatabase) {
92
101
  super();
93
102
  this._tableName = this.alias();
103
+
104
+ BaseChyz.debug("Model constructor", this._tableName)
94
105
  // this._sequelize = BaseChyz.getComponent("db").db;
95
106
  if (sequelize != null)
96
107
  this._sequelize = sequelize;
97
108
  else
98
- this._sequelize = BaseChyz.getComponent("db").db;
109
+ this._sequelize = Model.getDb();
99
110
 
100
111
  if (!Utils.isEmpty(this.attributes())) {
101
112
 
@@ -208,7 +219,7 @@ export class Model extends Component {
208
219
  let result: any;
209
220
  try {
210
221
  result = await this.model().create(p, options)
211
- } catch (e) {
222
+ } catch (e: any) {
212
223
  BaseChyz.debug(`Model[${this.constructor.name}].create`, e)
213
224
  if (e instanceof ValidationError) {
214
225
  let validationErrorItems = e.errors;
@@ -242,7 +253,7 @@ export class Model extends Component {
242
253
  let result: any;
243
254
  try {
244
255
  result = await this.model().bulkCreate(p, options)
245
- } catch (e) {
256
+ } catch (e: any) {
246
257
  BaseChyz.debug(`Model[${this.constructor.name}].bulkCreate`, e)
247
258
  if (e instanceof ValidationError) {
248
259
  let validationErrorItems = e.errors;
@@ -305,7 +316,6 @@ export class Model extends Component {
305
316
  }
306
317
 
307
318
 
308
-
309
319
  public validate() {
310
320
 
311
321
  }
@@ -367,6 +377,4 @@ export class Model extends Component {
367
377
  }
368
378
 
369
379
 
370
-
371
-
372
380
  }
@@ -18,7 +18,7 @@ export class RestClient extends Component {
18
18
  }
19
19
 
20
20
  public get(url: string, args: any[],headers:any={}) {
21
- return axios.post(url, args ,headers )
21
+ return axios.get(url, args ,headers )
22
22
  }
23
23
 
24
24
  public Rest(params: any) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chyz",
3
- "version": " 1.0.13-rc.20",
3
+ "version": " 1.0.13-rc.21",
4
4
  "description": "Nodejs Micro service Framework",
5
5
  "scripts": {
6
6
  "dev": "nodemon -t --trace-warnings index.ts",