chyz 2.0.0-rc.39 → 2.0.0-rc.40

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.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"BaseChyz.d.ts","sourceRoot":"","sources":["../src/BaseChyz.ts"],"names":[],"mappings":"AAcA,OAAO,EAAC,IAAI,EAAC,MAAM,aAAa,CAAC;AAkHjC,MAAM,CAAC,OAAO,OAAO,QAAQ;IACzB,OAAO,CAAC,MAAM,CAAuB;IACrC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC;IACvB,MAAM,CAAC,SAAS,EAAE,GAAG,CAAS;IAC9B,OAAO,CAAC,KAAK,CAAgB;IAC7B,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC;IACf,MAAM,CAAC,IAAI,EAAE,GAAG,CAAS;IACzB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACnB,MAAM,CAAC,IAAI,EAAE,IAAI,CAAE;IACnB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAiB;IACzC,OAAO,CAAC,eAAe,CAAwB;IAC/C,OAAO,CAAC,MAAM,CAAC,WAAW,CAA4B;IACtD,OAAc,UAAU,EAAE,GAAG,CAAK;IAClC,OAAc,WAAW,EAAE,GAAG,CAAK;IACnC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAU;IAGtC,MAAM,KAAK,YAAY,IAAI,GAAG,CAE7B;IAED,MAAM,KAAK,YAAY,CAAC,KAAK,EAAE,GAAG,EAEjC;IAED,IAAI,cAAc,IAAI,MAAM,CAE3B;IAED,IAAI,cAAc,CAAC,KAAK,EAAE,MAAM,EAE/B;IAED;;OAEG;IACH,IAAI;IAmCJ;;;OAGG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;OAIG;IACH,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAErB;IAGD,MAAM,KAAK,QAAQ,IAAI,GAAG,CAEz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IAAI,EAAE,GAAG,EAAE;WAKpB,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;WAItB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG;IAanC,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG;IAKrD,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG;IAUxD,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG;WAQ7C,YAAY,CAAC,GAAG,EAAE,GAAG;WAKrB,cAAc,CAAC,GAAG,EAAE,GAAG;IAIrC;;OAEG;IACG,UAAU;IAyBhB;;OAEG;IACG,cAAc;IA6Eb,UAAU;IAwDV,KAAK;CA2Bf"}
package/BaseChyz.js CHANGED
@@ -218,6 +218,9 @@ class BaseChyz {
218
218
  if (this.config.logs instanceof Logs_1.Logs) {
219
219
  BaseChyz.logs = this.config.logs;
220
220
  }
221
+ else if (!this.config.hasOwnProperty('logs')) {
222
+ BaseChyz.logs = new Logs_1.Logs();
223
+ }
221
224
  let components = Utils_1.Utils.findKeyValue(config, "components");
222
225
  if (components) {
223
226
  /**
@@ -385,13 +388,12 @@ class BaseChyz {
385
388
  }
386
389
  catch (e) {
387
390
  BaseChyz.error(e);
388
- res.status(e.statusCode || 500);
389
- // res.json({error: {code: e.statusCode || 500, name: e.name, message: e.message}})
390
- if (e.hasOwnProperty('toJSON')) {
391
+ if (e instanceof base_1.BaseError) {
392
+ res.status((e === null || e === void 0 ? void 0 : e.statusCode) || 500);
391
393
  res.json(e.toJSON());
392
394
  }
393
395
  else {
394
- res.json({ error: { code: e.statusCode || 500, name: e.name, message: e.message } });
396
+ res.json(e);
395
397
  }
396
398
  // next(e)
397
399
  }
@@ -404,11 +406,9 @@ class BaseChyz {
404
406
  instance.afterAction(route, req, res);
405
407
  }
406
408
  catch (e) {
409
+ BaseChyz.error(e);
407
410
  if (e instanceof base_1.BaseError) {
408
- BaseChyz.error(e);
409
- // @ts-ignore
410
411
  res.status(e.statusCode || 500);
411
- // @ts-ignore
412
412
  res.json(e.toJSON());
413
413
  }
414
414
  else {
@@ -20,7 +20,7 @@
20
20
  * 10.4.18 417 Expectation Failed ..................................70
21
21
  */
22
22
  export declare class BaseError extends Error {
23
- private statusCode;
23
+ statusCode: number;
24
24
  private success;
25
25
  constructor(message: any, statusCode?: number);
26
26
  toString(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"BaseError.d.ts","sourceRoot":"","sources":["../../src/base/BaseError.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAChC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,OAAO,CAAU;gBAEb,OAAO,EAAE,GAAG,EAAE,UAAU,SAAM;IAS1C,QAAQ;IAIR,MAAM;;;;;;CAGT"}
1
+ {"version":3,"file":"BaseError.d.ts","sourceRoot":"","sources":["../../src/base/BaseError.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,OAAO,CAAU;gBAEb,OAAO,EAAE,GAAG,EAAE,UAAU,SAAM;IAS1C,QAAQ;IAIR,MAAM;;;;;;CAGT"}
package/base/BaseError.js CHANGED
@@ -42,7 +42,7 @@ class BaseError extends Error {
42
42
  return `${this.name}[${this.statusCode}] ${this.message}`;
43
43
  }
44
44
  toJSON() {
45
- return { success: this.success, code: this === null || this === void 0 ? void 0 : this.statusCode, name: this.name, message: this.message };
45
+ return { success: this.success, code: this === null || this === void 0 ? void 0 : this.statusCode, name: this.name.toString(), message: this.message.toString() };
46
46
  }
47
47
  }
48
48
  exports.BaseError = BaseError;
package/base/Model.d.ts CHANGED
@@ -16,56 +16,56 @@ export interface Relation {
16
16
  }
17
17
  /**
18
18
  * ValidateMe.init({
19
- bar: {
20
- type: Sequelize.STRING,
21
- validate: {
22
- is: ["^[a-z]+$",'i'], // will only allow letters
23
- is: /^[a-z]+$/i, // same as the previous example using real RegExp
24
- not: ["[a-z]",'i'], // will not allow letters
25
- isEmail: true, // checks for email format (foo@bar.com)
26
- isUrl: true, // checks for url format (http://foo.com)
27
- isIP: true, // checks for IPv4 (129.89.23.1) or IPv6 format
28
- isIPv4: true, // checks for IPv4 (129.89.23.1)
29
- isIPv6: true, // checks for IPv6 format
30
- isAlpha: true, // will only allow letters
31
- isAlphanumeric: true, // will only allow alphanumeric characters, so "_abc" will fail
32
- isNumeric: true, // will only allow numbers
33
- isInt: true, // checks for valid integers
34
- isFloat: true, // checks for valid floating point numbers
35
- isDecimal: true, // checks for any numbers
36
- isLowercase: true, // checks for lowercase
37
- isUppercase: true, // checks for uppercase
38
- notNull: true, // won't allow null
39
- isNull: true, // only allows null
40
- notEmpty: true, // don't allow empty strings
41
- equals: 'specific value', // only allow a specific value
42
- contains: 'foo', // force specific substrings
43
- notIn: [['foo', 'bar']], // check the value is not one of these
44
- isIn: [['foo', 'bar']], // check the value is one of these
45
- notContains: 'bar', // don't allow specific substrings
46
- len: [2,10], // only allow values with length between 2 and 10
47
- isUUID: 4, // only allow uuids
48
- isDate: true, // only allow date strings
49
- isAfter: "2011-11-05", // only allow date strings after a specific date
50
- isBefore: "2011-11-05", // only allow date strings before a specific date
51
- max: 23, // only allow values <= 23
52
- min: 23, // only allow values >= 23
53
- isCreditCard: true, // check for valid credit card numbers
19
+ bar: {
20
+ type: Sequelize.STRING,
21
+ validate: {
22
+ is: ["^[a-z]+$",'i'], // will only allow letters
23
+ is: /^[a-z]+$/i, // same as the previous example using real RegExp
24
+ not: ["[a-z]",'i'], // will not allow letters
25
+ isEmail: true, // checks for email format (foo@bar.com)
26
+ isUrl: true, // checks for url format (http://foo.com)
27
+ isIP: true, // checks for IPv4 (129.89.23.1) or IPv6 format
28
+ isIPv4: true, // checks for IPv4 (129.89.23.1)
29
+ isIPv6: true, // checks for IPv6 format
30
+ isAlpha: true, // will only allow letters
31
+ isAlphanumeric: true, // will only allow alphanumeric characters, so "_abc" will fail
32
+ isNumeric: true, // will only allow numbers
33
+ isInt: true, // checks for valid integers
34
+ isFloat: true, // checks for valid floating point numbers
35
+ isDecimal: true, // checks for any numbers
36
+ isLowercase: true, // checks for lowercase
37
+ isUppercase: true, // checks for uppercase
38
+ notNull: true, // won't allow null
39
+ isNull: true, // only allows null
40
+ notEmpty: true, // don't allow empty strings
41
+ equals: 'specific value', // only allow a specific value
42
+ contains: 'foo', // force specific substrings
43
+ notIn: [['foo', 'bar']], // check the value is not one of these
44
+ isIn: [['foo', 'bar']], // check the value is one of these
45
+ notContains: 'bar', // don't allow specific substrings
46
+ len: [2,10], // only allow values with length between 2 and 10
47
+ isUUID: 4, // only allow uuids
48
+ isDate: true, // only allow date strings
49
+ isAfter: "2011-11-05", // only allow date strings after a specific date
50
+ isBefore: "2011-11-05", // only allow date strings before a specific date
51
+ max: 23, // only allow values <= 23
52
+ min: 23, // only allow values >= 23
53
+ isCreditCard: true, // check for valid credit card numbers
54
54
 
55
- // Examples of custom validators:
56
- isEven(value) {
57
- if (parseInt(value) % 2 !== 0) {
58
- throw new Error('Only even values are allowed!');
59
- }
60
- }
61
- isGreaterThanOtherField(value) {
62
- if (parseInt(value) <= parseInt(this.otherField)) {
63
- throw new Error('Bar must be greater than otherField.');
64
- }
65
- }
66
- }
67
- }
68
- }, { sequelize });
55
+ // Examples of custom validators:
56
+ isEven(value) {
57
+ if (parseInt(value) % 2 !== 0) {
58
+ throw new Error('Only even values are allowed!');
59
+ }
60
+ }
61
+ isGreaterThanOtherField(value) {
62
+ if (parseInt(value) <= parseInt(this.otherField)) {
63
+ throw new Error('Bar must be greater than otherField.');
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }, { sequelize });
69
69
  */
70
70
  export declare class Model extends Component {
71
71
  _provider: any;
@@ -1 +1 @@
1
- {"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../src/base/Model.ts"],"names":[],"mappings":"AASA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAqE,KAAK,IAAI,MAAM,EAAoE,MAAM,WAAW,CAAC;AAGjL,OAAO,EAAC,SAAS,EAAE,GAAG,EAAC,MAAM,WAAW,CAAC;AAGzC,MAAM,WAAW,QAAQ;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,eAAe,GAAG,WAAW,CAAC;IAC3D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,GAAG,CAAC;IACT,KAAK,CAAC,EAAE,GAAG,CAAA;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAEH,qBAAa,KAAM,SAAQ,SAAS;IAChC,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,GAAG,CAAC;IACf,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,WAAW,CAAW;IAC9B,OAAO,CAAC,OAAO,CAAU;gBAGb,SAAS,CAAC,EAAE,WAAW;IA6BnC;;;;;OAKG;IACI,KAAK;IAIL,eAAe;IAItB,IAAI,QAAQ,IAAI,GAAG,CAElB;IAED,IAAI,QAAQ,CAAC,KA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IAIR,KAAK;IAKL,QAAQ,CAAC,KAAK,EAAE,GAAG;IAInB,KAAK;IAKC,IAAI,CAAC,MAAM,KAAK,EAAE,OAAO,KAAK;IAoC9B,UAAU,CAAC,MAAM,KAAK,EAAE,OAAO,KAAK;IAmC1C,MAAM,CAAC,MAAM,KAAK,EAAE,OAAO,KAAK;IAMhC,MAAM,CAAC,MAAM,KAAK,EAAE,OAAO,KAAK;IAMvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmKG;IACU,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,GAA2C;IAMzF;;;OAGG;IACI,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAI7B;;;OAGG;IACI,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAI7B;;;OAGG;IACI,eAAe,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAK9B,QAAQ;IAIf;;;;OAIG;IACI,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,GAAE,GAAU;IAYpC,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,GAAE,GAAU;IAYxC,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,UAAO;IAazC,UAAU;IAIjB;;;;;OAKG;IACI,SAAS,IAAI,QAAQ,EAAE;CAKjC"}
package/base/Model.js CHANGED
@@ -25,61 +25,62 @@ const Component_1 = require("./Component");
25
25
  const InvalidConfigException_1 = require("./InvalidConfigException");
26
26
  const sequelize_1 = require("sequelize");
27
27
  const Exception_1 = require("./db/Exception");
28
+ const DataErrorDbException_1 = require("./DataErrorDbException");
28
29
  var sequelize_2 = require("sequelize");
29
30
  Object.defineProperty(exports, "DataTypes", { enumerable: true, get: function () { return sequelize_2.DataTypes; } });
30
31
  Object.defineProperty(exports, "NOW", { enumerable: true, get: function () { return sequelize_2.NOW; } });
31
32
  /**
32
33
  * ValidateMe.init({
33
- bar: {
34
- type: Sequelize.STRING,
35
- validate: {
36
- is: ["^[a-z]+$",'i'], // will only allow letters
37
- is: /^[a-z]+$/i, // same as the previous example using real RegExp
38
- not: ["[a-z]",'i'], // will not allow letters
39
- isEmail: true, // checks for email format (foo@bar.com)
40
- isUrl: true, // checks for url format (http://foo.com)
41
- isIP: true, // checks for IPv4 (129.89.23.1) or IPv6 format
42
- isIPv4: true, // checks for IPv4 (129.89.23.1)
43
- isIPv6: true, // checks for IPv6 format
44
- isAlpha: true, // will only allow letters
45
- isAlphanumeric: true, // will only allow alphanumeric characters, so "_abc" will fail
46
- isNumeric: true, // will only allow numbers
47
- isInt: true, // checks for valid integers
48
- isFloat: true, // checks for valid floating point numbers
49
- isDecimal: true, // checks for any numbers
50
- isLowercase: true, // checks for lowercase
51
- isUppercase: true, // checks for uppercase
52
- notNull: true, // won't allow null
53
- isNull: true, // only allows null
54
- notEmpty: true, // don't allow empty strings
55
- equals: 'specific value', // only allow a specific value
56
- contains: 'foo', // force specific substrings
57
- notIn: [['foo', 'bar']], // check the value is not one of these
58
- isIn: [['foo', 'bar']], // check the value is one of these
59
- notContains: 'bar', // don't allow specific substrings
60
- len: [2,10], // only allow values with length between 2 and 10
61
- isUUID: 4, // only allow uuids
62
- isDate: true, // only allow date strings
63
- isAfter: "2011-11-05", // only allow date strings after a specific date
64
- isBefore: "2011-11-05", // only allow date strings before a specific date
65
- max: 23, // only allow values <= 23
66
- min: 23, // only allow values >= 23
67
- isCreditCard: true, // check for valid credit card numbers
34
+ bar: {
35
+ type: Sequelize.STRING,
36
+ validate: {
37
+ is: ["^[a-z]+$",'i'], // will only allow letters
38
+ is: /^[a-z]+$/i, // same as the previous example using real RegExp
39
+ not: ["[a-z]",'i'], // will not allow letters
40
+ isEmail: true, // checks for email format (foo@bar.com)
41
+ isUrl: true, // checks for url format (http://foo.com)
42
+ isIP: true, // checks for IPv4 (129.89.23.1) or IPv6 format
43
+ isIPv4: true, // checks for IPv4 (129.89.23.1)
44
+ isIPv6: true, // checks for IPv6 format
45
+ isAlpha: true, // will only allow letters
46
+ isAlphanumeric: true, // will only allow alphanumeric characters, so "_abc" will fail
47
+ isNumeric: true, // will only allow numbers
48
+ isInt: true, // checks for valid integers
49
+ isFloat: true, // checks for valid floating point numbers
50
+ isDecimal: true, // checks for any numbers
51
+ isLowercase: true, // checks for lowercase
52
+ isUppercase: true, // checks for uppercase
53
+ notNull: true, // won't allow null
54
+ isNull: true, // only allows null
55
+ notEmpty: true, // don't allow empty strings
56
+ equals: 'specific value', // only allow a specific value
57
+ contains: 'foo', // force specific substrings
58
+ notIn: [['foo', 'bar']], // check the value is not one of these
59
+ isIn: [['foo', 'bar']], // check the value is one of these
60
+ notContains: 'bar', // don't allow specific substrings
61
+ len: [2,10], // only allow values with length between 2 and 10
62
+ isUUID: 4, // only allow uuids
63
+ isDate: true, // only allow date strings
64
+ isAfter: "2011-11-05", // only allow date strings after a specific date
65
+ isBefore: "2011-11-05", // only allow date strings before a specific date
66
+ max: 23, // only allow values <= 23
67
+ min: 23, // only allow values >= 23
68
+ isCreditCard: true, // check for valid credit card numbers
68
69
 
69
- // Examples of custom validators:
70
- isEven(value) {
71
- if (parseInt(value) % 2 !== 0) {
72
- throw new Error('Only even values are allowed!');
73
- }
74
- }
75
- isGreaterThanOtherField(value) {
76
- if (parseInt(value) <= parseInt(this.otherField)) {
77
- throw new Error('Bar must be greater than otherField.');
78
- }
79
- }
80
- }
81
- }
82
- }, { sequelize });
70
+ // Examples of custom validators:
71
+ isEven(value) {
72
+ if (parseInt(value) % 2 !== 0) {
73
+ throw new Error('Only even values are allowed!');
74
+ }
75
+ }
76
+ isGreaterThanOtherField(value) {
77
+ if (parseInt(value) <= parseInt(this.otherField)) {
78
+ throw new Error('Bar must be greater than otherField.');
79
+ }
80
+ }
81
+ }
82
+ }
83
+ }, { sequelize });
83
84
  */
84
85
  class Model extends Component_1.Component {
85
86
  constructor(sequelize) {
@@ -89,10 +90,37 @@ class Model extends Component_1.Component {
89
90
  this._tableName = this.alias();
90
91
  BaseChyz_1.default.debug("Model constructor", this._tableName);
91
92
  // this._sequelize = BaseChyz.getComponent("db").db;
92
- if (sequelize != null)
93
+ if (sequelize != null) {
93
94
  this._provider = sequelize;
95
+ }
94
96
  else
95
97
  this._provider = this.getDb();
98
+ /**
99
+ * override query
100
+ */
101
+ // this._provider.query = async (sql: string | { query: string; values: unknown[] },options?: QueryOptions | QueryOptionsWithType<QueryTypes.RAW> | undefined,) => {
102
+ // try {
103
+ // console.log(this,Sequelize.prototype.query.apply(this, [sql, options]))
104
+ // return Sequelize.prototype.query.apply(this, [sql, options]);
105
+ // } catch (err: any) {
106
+ // console.log(err)
107
+ // throw new DatabaseError(err);
108
+ // }
109
+ // };
110
+ this._provider.query = function (sql, options) {
111
+ return sequelize_1.Sequelize.prototype.query.apply(this, [sql, options]).catch((err) => {
112
+ let e = new Error(err.message);
113
+ e.message = err.message;
114
+ throw new DataErrorDbException_1.DataErrorDbException(e);
115
+ });
116
+ // try {
117
+ // let r =
118
+ // console.log(r)
119
+ // } catch (err: any) {
120
+ // console.log(err)
121
+ // throw new DatabaseError(err);
122
+ // }
123
+ };
96
124
  if (!Utils_1.Utils.isEmpty(this.attributes())) {
97
125
  this._model = this._provider.define(this._tableName, this.attributes(), {
98
126
  tableName: this.tableName(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chyz",
3
- "version": "2.0.0-rc.39",
3
+ "version": "2.0.0-rc.40",
4
4
  "description": "Nodejs Micro service Framework",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",