chyz 1.2.5-rc.2 → 2.0.0-rc.12

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 (226) hide show
  1. package/BaseChyz.d.ts +63 -0
  2. package/BaseChyz.d.ts.map +1 -0
  3. package/BaseChyz.js +128 -80
  4. package/base/ActionFilter.d.ts +33 -0
  5. package/base/ActionFilter.d.ts.map +1 -0
  6. package/base/ActionFilter.js +21 -20
  7. package/base/BaseError.d.ts +11 -0
  8. package/base/BaseError.d.ts.map +1 -0
  9. package/base/BaseError.js +2 -6
  10. package/base/Behavior.d.ts +4 -0
  11. package/base/Behavior.d.ts.map +1 -0
  12. package/base/Behavior.js +2 -3
  13. package/base/CBaseObject.d.ts +5 -0
  14. package/base/CBaseObject.d.ts.map +1 -0
  15. package/base/CBaseObject.js +16 -0
  16. package/base/CRequest.d.ts +2 -0
  17. package/base/CRequest.d.ts.map +1 -0
  18. package/base/CRequest.js +10 -0
  19. package/base/CWebController.d.ts +44 -0
  20. package/base/CWebController.d.ts.map +1 -0
  21. package/base/CWebController.js +0 -1
  22. package/base/Component.d.ts +21 -0
  23. package/base/Component.d.ts.map +1 -0
  24. package/base/Component.js +7 -11
  25. package/base/Configurable.d.ts +3 -0
  26. package/base/Configurable.d.ts.map +1 -0
  27. package/base/Configurable.js +0 -1
  28. package/base/DataErrorDbException.d.ts +6 -0
  29. package/base/DataErrorDbException.d.ts.map +1 -0
  30. package/base/DataErrorDbException.js +0 -1
  31. package/base/DbConnection.d.ts +13 -0
  32. package/base/DbConnection.d.ts.map +1 -0
  33. package/base/DbConnection.js +1 -2
  34. package/base/ForbiddenHttpException.d.ts +5 -0
  35. package/base/ForbiddenHttpException.d.ts.map +1 -0
  36. package/base/ForbiddenHttpException.js +0 -1
  37. package/base/InvalidArgumentException.d.ts +6 -0
  38. package/base/InvalidArgumentException.d.ts.map +1 -0
  39. package/base/InvalidArgumentException.js +0 -1
  40. package/base/InvalidConfigException.d.ts +6 -0
  41. package/base/InvalidConfigException.d.ts.map +1 -0
  42. package/base/InvalidConfigException.js +0 -1
  43. package/base/Logs.d.ts +22 -0
  44. package/base/Logs.d.ts.map +1 -0
  45. package/base/Logs.js +57 -0
  46. package/base/Model.d.ts +299 -0
  47. package/base/Model.d.ts.map +1 -0
  48. package/base/Model.js +4 -5
  49. package/base/ModelManager.d.ts +2 -0
  50. package/base/ModelManager.d.ts.map +1 -0
  51. package/base/ModelManager.js +11 -1
  52. package/base/NotFoundHttpException.d.ts +6 -0
  53. package/base/NotFoundHttpException.d.ts.map +1 -0
  54. package/base/NotFoundHttpException.js +0 -1
  55. package/base/RestClient.d.ts +7 -0
  56. package/base/RestClient.d.ts.map +1 -0
  57. package/base/RestClient.js +0 -2
  58. package/base/UnauthorizedHttpException.d.ts +6 -0
  59. package/base/UnauthorizedHttpException.d.ts.map +1 -0
  60. package/base/UnauthorizedHttpException.js +0 -1
  61. package/base/ValidationHttpException.d.ts +6 -0
  62. package/base/ValidationHttpException.d.ts.map +1 -0
  63. package/base/ValidationHttpException.js +0 -1
  64. package/base/db/Exception.d.ts +7 -0
  65. package/base/db/Exception.d.ts.map +1 -0
  66. package/base/db/Exception.js +0 -1
  67. package/base/index.d.ts +19 -0
  68. package/base/index.d.ts.map +1 -0
  69. package/base/index.js +5 -6
  70. package/decorator/Middleware.d.ts +4 -0
  71. package/decorator/Middleware.d.ts.map +1 -0
  72. package/decorator/Middleware.js +0 -1
  73. package/decorator/controller.d.ts +3 -0
  74. package/decorator/controller.d.ts.map +1 -0
  75. package/decorator/controller.js +0 -1
  76. package/decorator/enums/ControllerDecoratorParams.d.ts +6 -0
  77. package/decorator/enums/ControllerDecoratorParams.d.ts.map +1 -0
  78. package/decorator/enums/ControllerDecoratorParams.js +0 -1
  79. package/decorator/get.d.ts +3 -0
  80. package/decorator/get.d.ts.map +1 -0
  81. package/decorator/get.js +0 -1
  82. package/decorator/index.d.ts +4 -0
  83. package/decorator/index.d.ts.map +1 -0
  84. package/decorator/index.js +0 -1
  85. package/decorator/post.d.ts +3 -0
  86. package/decorator/post.d.ts.map +1 -0
  87. package/decorator/post.js +0 -1
  88. package/filters/AccessControl.d.ts +13 -0
  89. package/filters/AccessControl.d.ts.map +1 -0
  90. package/filters/AccessControl.js +6 -10
  91. package/filters/AccessRule.d.ts +83 -0
  92. package/filters/AccessRule.d.ts.map +1 -0
  93. package/filters/AccessRule.js +9 -12
  94. package/filters/auth/AuthInterface.d.ts +26 -0
  95. package/filters/auth/AuthInterface.d.ts.map +1 -0
  96. package/filters/auth/AuthInterface.js +0 -1
  97. package/filters/auth/AuthMethod.d.ts +38 -0
  98. package/filters/auth/AuthMethod.d.ts.map +1 -0
  99. package/filters/auth/AuthMethod.js +12 -1
  100. package/filters/auth/HttpBasicAuth.d.ts +23 -0
  101. package/filters/auth/HttpBasicAuth.d.ts.map +1 -0
  102. package/filters/auth/HttpBasicAuth.js +0 -1
  103. package/filters/auth/HttpBearerAuth.d.ts +18 -0
  104. package/filters/auth/HttpBearerAuth.d.ts.map +1 -0
  105. package/filters/auth/HttpBearerAuth.js +0 -1
  106. package/filters/auth/HttpHeaderAuth.d.ts +15 -0
  107. package/filters/auth/HttpHeaderAuth.d.ts.map +1 -0
  108. package/filters/auth/HttpHeaderAuth.js +2 -6
  109. package/filters/auth/JwtHttpBearerAuth.d.ts +21 -0
  110. package/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -0
  111. package/filters/auth/JwtHttpBearerAuth.js +0 -1
  112. package/filters/auth/KeyCloakHttpBearerAuth.d.ts +23 -0
  113. package/filters/auth/KeyCloakHttpBearerAuth.d.ts.map +1 -0
  114. package/filters/auth/KeyCloakHttpBearerAuth.js +0 -1
  115. package/filters/auth/index.d.ts +5 -0
  116. package/filters/auth/index.d.ts.map +1 -0
  117. package/filters/auth/index.js +0 -1
  118. package/filters/index.d.ts +3 -0
  119. package/filters/index.d.ts.map +1 -0
  120. package/filters/index.js +0 -1
  121. package/index.d.ts +22 -0
  122. package/index.d.ts.map +1 -0
  123. package/index.js +24 -31
  124. package/model/RouteDefinition.d.ts +7 -0
  125. package/model/RouteDefinition.d.ts.map +1 -0
  126. package/model/RouteDefinition.js +0 -1
  127. package/package.json +10 -10
  128. package/rbac/AuthAssignment.d.ts +19 -0
  129. package/rbac/AuthAssignment.d.ts.map +1 -0
  130. package/rbac/AuthAssignment.js +0 -1
  131. package/rbac/AuthItem.d.ts +27 -0
  132. package/rbac/AuthItem.d.ts.map +1 -0
  133. package/rbac/AuthItem.js +0 -1
  134. package/rbac/AuthItemChild.d.ts +19 -0
  135. package/rbac/AuthItemChild.d.ts.map +1 -0
  136. package/rbac/AuthItemChild.js +0 -1
  137. package/rbac/AuthManager.d.ts +112 -0
  138. package/rbac/AuthManager.d.ts.map +1 -0
  139. package/rbac/AuthManager.js +9 -13
  140. package/requiments/Glob.d.ts +3 -0
  141. package/requiments/Glob.d.ts.map +1 -0
  142. package/requiments/Glob.js +0 -1
  143. package/requiments/ReflectUtil.d.ts +1 -0
  144. package/requiments/ReflectUtil.d.ts.map +1 -0
  145. package/requiments/ReflectUtil.js +0 -1
  146. package/requiments/Utils.d.ts +9 -0
  147. package/requiments/Utils.d.ts.map +1 -0
  148. package/requiments/Utils.js +11 -3
  149. package/validators/BooleanValidator.d.ts +1 -0
  150. package/validators/BooleanValidator.d.ts.map +1 -0
  151. package/validators/BooleanValidator.js +0 -1
  152. package/validators/CompareValidator.d.ts +1 -0
  153. package/validators/CompareValidator.d.ts.map +1 -0
  154. package/validators/CompareValidator.js +0 -1
  155. package/validators/DateValidator.d.ts +1 -0
  156. package/validators/DateValidator.d.ts.map +1 -0
  157. package/validators/DateValidator.js +0 -1
  158. package/validators/EmailValidator.d.ts +1 -0
  159. package/validators/EmailValidator.d.ts.map +1 -0
  160. package/validators/EmailValidator.js +0 -1
  161. package/validators/Validator.d.ts +18 -0
  162. package/validators/Validator.d.ts.map +1 -0
  163. package/validators/Validator.js +0 -1
  164. package/web/IdentityInterface.d.ts +55 -0
  165. package/web/IdentityInterface.d.ts.map +1 -0
  166. package/web/IdentityInterface.js +0 -1
  167. package/web/WebUser.d.ts +72 -0
  168. package/web/WebUser.d.ts.map +1 -0
  169. package/web/WebUser.js +2 -3
  170. package/BaseChyz.js.map +0 -1
  171. package/Chyz.js +0 -15
  172. package/Chyz.js.map +0 -1
  173. package/base/ActionFilter.js.map +0 -1
  174. package/base/BaseError.js.map +0 -1
  175. package/base/BaseObject.js +0 -20
  176. package/base/BaseObject.js.map +0 -1
  177. package/base/Behavior.js.map +0 -1
  178. package/base/CWebController.js.map +0 -1
  179. package/base/Component.js.map +0 -1
  180. package/base/Configurable.js.map +0 -1
  181. package/base/DataErrorDbException.js.map +0 -1
  182. package/base/DbConnection.js.map +0 -1
  183. package/base/ForbiddenHttpException.js.map +0 -1
  184. package/base/InvalidArgumentException.js.map +0 -1
  185. package/base/InvalidConfigException.js.map +0 -1
  186. package/base/Model.js.map +0 -1
  187. package/base/ModelManager.js.map +0 -1
  188. package/base/NotFoundHttpException.js.map +0 -1
  189. package/base/RestClient.js.map +0 -1
  190. package/base/UnauthorizedHttpException.js.map +0 -1
  191. package/base/ValidationHttpException.js.map +0 -1
  192. package/base/db/Exception.js.map +0 -1
  193. package/base/index.js.map +0 -1
  194. package/decorator/Middleware.js.map +0 -1
  195. package/decorator/controller.js.map +0 -1
  196. package/decorator/enums/ControllerDecoratorParams.js.map +0 -1
  197. package/decorator/get.js.map +0 -1
  198. package/decorator/index.js.map +0 -1
  199. package/decorator/post.js.map +0 -1
  200. package/filters/AccessControl.js.map +0 -1
  201. package/filters/AccessRule.js.map +0 -1
  202. package/filters/auth/AuthInterface.js.map +0 -1
  203. package/filters/auth/AuthMethod.js.map +0 -1
  204. package/filters/auth/HttpBasicAuth.js.map +0 -1
  205. package/filters/auth/HttpBearerAuth.js.map +0 -1
  206. package/filters/auth/HttpHeaderAuth.js.map +0 -1
  207. package/filters/auth/JwtHttpBearerAuth.js.map +0 -1
  208. package/filters/auth/KeyCloakHttpBearerAuth.js.map +0 -1
  209. package/filters/auth/index.js.map +0 -1
  210. package/filters/index.js.map +0 -1
  211. package/index.js.map +0 -1
  212. package/model/RouteDefinition.js.map +0 -1
  213. package/rbac/AuthAssignment.js.map +0 -1
  214. package/rbac/AuthItem.js.map +0 -1
  215. package/rbac/AuthItemChild.js.map +0 -1
  216. package/rbac/AuthManager.js.map +0 -1
  217. package/requiments/Glob.js.map +0 -1
  218. package/requiments/ReflectUtil.js.map +0 -1
  219. package/requiments/Utils.js.map +0 -1
  220. package/validators/BooleanValidator.js.map +0 -1
  221. package/validators/CompareValidator.js.map +0 -1
  222. package/validators/DateValidator.js.map +0 -1
  223. package/validators/EmailValidator.js.map +0 -1
  224. package/validators/Validator.js.map +0 -1
  225. package/web/IdentityInterface.js.map +0 -1
  226. package/web/WebUser.js.map +0 -1
package/BaseChyz.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ import { Logs } from "./base/Logs";
2
+ export default class BaseChyz {
3
+ private config;
4
+ static app: string;
5
+ static httpServer: any;
6
+ static express: any;
7
+ private _port;
8
+ static db: any;
9
+ static routes: any;
10
+ static logs: Logs;
11
+ private static _validate;
12
+ private _controllerpath;
13
+ private static controllers;
14
+ static components: any;
15
+ static middlewares: any;
16
+ private static _EventEmitter;
17
+ static get EventEmitter(): any;
18
+ static set EventEmitter(value: any);
19
+ get controllerpath(): string;
20
+ set controllerpath(value: string);
21
+ /**
22
+ *
23
+ */
24
+ init(): void;
25
+ /**
26
+ * Listen port number
27
+ * Server port number get
28
+ */
29
+ get port(): number;
30
+ /**
31
+ * Listen port number
32
+ * Server port number setting
33
+ * @param value
34
+ */
35
+ set port(value: number);
36
+ static get validate(): any;
37
+ static set validate(value: any);
38
+ app(config?: any): BaseChyz;
39
+ static trace(...args: any[]): void;
40
+ static debug(...args: any[]): void;
41
+ static info(...args: any[]): void;
42
+ static warn(...args: any[]): void;
43
+ static error(...args: any[]): void;
44
+ static fatal(...args: any[]): void;
45
+ static warning(...args: any[]): void;
46
+ static t(text: string): string;
47
+ errorLogger(error: any, req: any, res: any, next: any): void;
48
+ errorResponder(error: any, req: any, res: any, next: any): void;
49
+ errorHandler(err: any, req: any, res: any, next: any): any;
50
+ static getComponent(key: any): any;
51
+ static getMiddlewares(key: any): any;
52
+ /**
53
+ * load model
54
+ */
55
+ loadModels(): Promise<void>;
56
+ /**
57
+ * load contoller
58
+ */
59
+ loadController(): Promise<void>;
60
+ middleware(): void;
61
+ Start(): this;
62
+ }
63
+ //# sourceMappingURL=BaseChyz.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseChyz.d.ts","sourceRoot":"","sources":["../src/BaseChyz.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,IAAI,EAAC,MAAM,aAAa,CAAC;AAgFjC,MAAM,CAAC,OAAO,OAAO,QAAQ;IACzB,OAAO,CAAC,MAAM,CAAuB;IACrC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC;IACvB,MAAM,CAAC,OAAO,MAAS;IACvB,OAAO,CAAC,KAAK,CAAgB;IAC7B,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC;IACf,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACnB,MAAM,CAAC,IAAI,EAAE,IAAI,CAAc;IAC/B,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,CAEzB;IAED,MAAM,KAAK,QAAQ,CAAC,KAAK,EAAE,GAAG,EAE7B;IAED,GAAG,CAAC,MAAM,GAAE,GAAQ,GAAG,QAAQ;WAiDjB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;WAIpB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;WAIpB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;WAInB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;WAInB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;WAIpB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;WAKpB,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;WAItB,CAAC,CAAC,IAAI,EAAE,MAAM;IAKrB,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;IA4Eb,UAAU;IAsDV,KAAK;CAwBf"}
package/BaseChyz.js CHANGED
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,17 +31,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
32
  });
10
33
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
34
  Object.defineProperty(exports, "__esModule", { value: true });
15
- require("reflect-metadata");
16
- const Utils_1 = __importDefault(require("./requiments/Utils"));
17
35
  const base_1 = require("./base");
36
+ const Utils_1 = __importStar(require("./requiments/Utils"));
37
+ const Logs_1 = require("./base/Logs");
18
38
  const https = require('https');
19
39
  const express = require("express");
20
40
  const compression = require('compression');
21
- const log4js = require("log4js");
22
41
  const fs = require('fs');
23
42
  const validate = require('validate.js');
24
43
  /**
@@ -43,7 +62,7 @@ validate.validators.array = (arrayItems, itemConstraints) => {
43
62
  errors[index] = { error: error };
44
63
  return errors;
45
64
  }, {});
46
- return Utils_1.default.isEmpty(arrayItemErrors) ? null : { errors: arrayItemErrors };
65
+ return Utils_1.Utils.isEmpty(arrayItemErrors) ? null : { errors: arrayItemErrors };
47
66
  };
48
67
  validate.validators.tokenString = (items, itemConstraints) => {
49
68
  let arrayItems = items.split(",");
@@ -53,23 +72,43 @@ validate.validators.tokenString = (items, itemConstraints) => {
53
72
  errors[index] = { error: error };
54
73
  return errors;
55
74
  }, {});
56
- return Utils_1.default.isEmpty(arrayItemErrors) ? null : { errors: arrayItemErrors };
75
+ return Utils_1.Utils.isEmpty(arrayItemErrors) ? null : { errors: arrayItemErrors };
57
76
  };
58
- var ip = require('ip');
59
- var bodyParser = require('body-parser');
60
- var methodOverride = require('method-override');
77
+ const ip = require('ip');
78
+ const bodyParser = require('body-parser');
79
+ const methodOverride = require('method-override');
80
+ const Server = express();
81
+ const cors = require('cors');
82
+ const emitter = require('events').EventEmitter;
83
+ const em = new emitter();
84
+ /**
85
+ * set request id
86
+ */
87
+ Object.defineProperty(Server.request, 'reqId', {
88
+ configurable: true,
89
+ enumerable: true,
90
+ writable: true
91
+ });
92
+ Object.defineProperty(Server.request, 'user', {
93
+ configurable: true,
94
+ enumerable: true,
95
+ writable: true
96
+ });
97
+ Object.defineProperty(Server.request, 'identity', {
98
+ configurable: true,
99
+ enumerable: true,
100
+ writable: true
101
+ });
61
102
  class BaseChyz {
62
103
  constructor() {
63
- var _a;
64
104
  this._port = 3001;
65
- this._logConfig = (_a = require('./log/config/log4js.json')) !== null && _a !== void 0 ? _a : {};
66
105
  this._controllerpath = "Controllers";
67
106
  }
68
- get logConfig() {
69
- return this._logConfig;
107
+ static get EventEmitter() {
108
+ return this._EventEmitter;
70
109
  }
71
- set logConfig(value) {
72
- this._logConfig = value;
110
+ static set EventEmitter(value) {
111
+ this._EventEmitter = value;
73
112
  }
74
113
  get controllerpath() {
75
114
  return this._controllerpath;
@@ -77,25 +116,10 @@ class BaseChyz {
77
116
  set controllerpath(value) {
78
117
  this._controllerpath = value;
79
118
  }
119
+ /**
120
+ *
121
+ */
80
122
  init() {
81
- /**
82
- * set request id
83
- */
84
- Object.defineProperty(BaseChyz.express.request, 'reqId', {
85
- configurable: true,
86
- enumerable: true,
87
- writable: true
88
- });
89
- Object.defineProperty(BaseChyz.express.request, 'user', {
90
- configurable: true,
91
- enumerable: true,
92
- writable: true
93
- });
94
- Object.defineProperty(BaseChyz.express.request, 'identity', {
95
- configurable: true,
96
- enumerable: true,
97
- writable: true
98
- });
99
123
  /**
100
124
  * server port setting
101
125
  */
@@ -147,16 +171,19 @@ class BaseChyz {
147
171
  * Config set
148
172
  */
149
173
  this.config = config;
150
- // logger setting
151
- this.logProvider().level = log4js.levels.ALL;
152
- this.logProvider().configure(this._logConfig);
153
- let components = Utils_1.default.findKeyValue(config, "components");
174
+ /**
175
+ * log setting
176
+ */
177
+ if (this.config.logs instanceof Logs_1.Logs) {
178
+ BaseChyz.logs = this.config.logs;
179
+ }
180
+ let components = Utils_1.Utils.findKeyValue(config, "components");
154
181
  if (components) {
155
182
  for (const componentsKey in components) {
156
183
  let comp = components[componentsKey];
157
184
  BaseChyz.debug("Create Component ", componentsKey);
158
185
  try {
159
- BaseChyz.components[componentsKey] = Utils_1.default.createObject(new comp.class, comp);
186
+ BaseChyz.components[componentsKey] = Utils_1.Utils.createObject(new comp.class, comp);
160
187
  (_a = BaseChyz.components[componentsKey]) === null || _a === void 0 ? void 0 : _a.init();
161
188
  }
162
189
  catch (e) {
@@ -164,11 +191,11 @@ class BaseChyz {
164
191
  }
165
192
  }
166
193
  }
167
- let middlewares = Utils_1.default.findKeyValue(config, "middlewares");
194
+ let middlewares = Utils_1.Utils.findKeyValue(config, "middlewares");
168
195
  if (middlewares) {
169
196
  for (const middlewareKey in middlewares) {
170
197
  let middleware1 = middlewares[middlewareKey];
171
- BaseChyz.logs().debug("Create middlewares ", middlewareKey);
198
+ BaseChyz.debug("Create middlewares ", middlewareKey);
172
199
  BaseChyz.middlewares[middlewareKey] = middleware1;
173
200
  // BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
174
201
  }
@@ -176,35 +203,26 @@ class BaseChyz {
176
203
  this.init();
177
204
  return this;
178
205
  }
179
- logProvider() {
180
- return log4js;
181
- }
182
- getLogger() {
183
- return this.logProvider().getLogger(this.constructor.name);
184
- }
185
- static logs(...args) {
186
- return log4js.getLogger(this.name);
187
- }
188
206
  static trace(...args) {
189
- BaseChyz.logs().fatal(...arguments);
207
+ BaseChyz.logs.fatal(...arguments);
190
208
  }
191
209
  static debug(...args) {
192
- BaseChyz.logs().debug(...arguments);
210
+ BaseChyz.logs.debug(...arguments);
193
211
  }
194
212
  static info(...args) {
195
- BaseChyz.logs().info(...arguments);
213
+ BaseChyz.logs.info(...arguments);
196
214
  }
197
215
  static warn(...args) {
198
- BaseChyz.logs().warn(...arguments);
216
+ BaseChyz.logs.warn(...arguments);
199
217
  }
200
218
  static error(...args) {
201
- BaseChyz.logs().error(...arguments);
219
+ BaseChyz.logs.error(...arguments);
202
220
  }
203
221
  static fatal(...args) {
204
- BaseChyz.logs().fatal(...arguments);
222
+ BaseChyz.logs.fatal(...arguments);
205
223
  }
206
224
  static warning(...args) {
207
- BaseChyz.logs().warn(...arguments);
225
+ BaseChyz.logs.warn(...arguments);
208
226
  }
209
227
  static t(text) {
210
228
  return text;
@@ -251,6 +269,9 @@ class BaseChyz {
251
269
  models[className.replace("Class", "")] = new model[className];
252
270
  }
253
271
  });
272
+ /**
273
+ *
274
+ */
254
275
  base_1.ModelManager._register(models);
255
276
  for (const key of Object.keys(base_1.ModelManager)) {
256
277
  if (key != "_register") {
@@ -264,9 +285,19 @@ class BaseChyz {
264
285
  */
265
286
  loadController() {
266
287
  return __awaiter(this, void 0, void 0, function* () {
267
- let articlesEndpoints = [];
268
- fs.readdirSync(`${this._controllerpath}/`).forEach((file) => {
269
- let controller = require(`${this._controllerpath}/${file}`);
288
+ // let articlesEndpoints: string[] = [];
289
+ for (const file of fs.readdirSync(`${this._controllerpath}/`)) {
290
+ // let controller = require(`${this._controllerpath}/${file}`);
291
+ let controller = (yield Promise.resolve().then(() => __importStar(require(`${this._controllerpath}/${file}`))));
292
+ if (controller[file.replace(".ts", "")]) {
293
+ controller = controller[file.replace(".ts", "")];
294
+ }
295
+ else if (controller.default) {
296
+ controller = controller.default;
297
+ }
298
+ else {
299
+ throw new base_1.InvalidConfigException((0, Utils_1.default)("Invalid Controller"));
300
+ }
270
301
  // This is our instantiated class
271
302
  const instance = new controller();
272
303
  BaseChyz.controllers.push(instance);
@@ -276,12 +307,12 @@ class BaseChyz {
276
307
  // Our `routes` array containing all our routes for this controller
277
308
  // @ts-ignore
278
309
  const routes = Reflect.getMetadata('routes', controller);
279
- BaseChyz.logs().debug("Controller load ", controller.name, `(${prefix})`);
310
+ BaseChyz.debug("Controller load ", controller.name, `(${prefix})`);
280
311
  if (routes) {
281
312
  routes.forEach(route => {
282
313
  let actionId = route.path == "/" || route.path == "" ? instance.defaultAction : route.path;
283
314
  route.id = actionId;
284
- BaseChyz.logs().debug("Controller route Path", prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`));
315
+ BaseChyz.debug("Controller route Path", prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`));
285
316
  BaseChyz.express[route.requestMethod](prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`), (req, res, next) => __awaiter(this, void 0, void 0, function* () {
286
317
  try {
287
318
  BaseChyz.debug(`Call Request id ${instance.id}`);
@@ -317,30 +348,46 @@ class BaseChyz {
317
348
  }));
318
349
  });
319
350
  }
320
- });
351
+ }
321
352
  });
322
353
  }
323
354
  middleware() {
324
355
  BaseChyz.express.use(bodyParser.json({ limit: '1mb' }));
325
356
  BaseChyz.express.use(bodyParser.urlencoded({ limit: '1mb', extended: true })); // support encoded bodies
326
357
  BaseChyz.express.use(methodOverride());
327
- BaseChyz.express.use(methodOverride());
328
- // CORS
329
- BaseChyz.express.use(function (req, res, next) {
330
- // @ts-ignore
331
- req.reqId = Utils_1.default.uniqueId("chyzzzz_");
332
- res.setHeader('Content-Type', 'application/json');
333
- res.setHeader("Access-Control-Allow-Origin", "*");
334
- res.setHeader("Access-Control-Allow-Credentials", "true");
335
- res.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
336
- res.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Origin,Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers,Authorization");
337
- next();
338
- });
358
+ BaseChyz.express.use(cors());
359
+ //
360
+ // // CORS
361
+ // BaseChyz.express.use(function (req: any, res: Response, next: any) {
362
+ // // @ts-ignore
363
+ // req.reqId = Utils.uniqueId("chyzzzz_")
364
+ // res.setHeader('Content-Type', 'application/json');
365
+ // res.setHeader("Access-Control-Allow-Origin", "*");
366
+ // res.setHeader("Access-Control-Allow-Credentials", "true");
367
+ // res.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
368
+ // res.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Origin,Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers,Authorization");
369
+ // next();
370
+ // });
371
+ //
339
372
  // compress all responses
340
- BaseChyz.express.use(compression());
373
+ const shouldCompress = (req, res) => {
374
+ // don't compress responses explicitly asking not
375
+ if (req.headers["x-no-compression"] || res.getHeader('Content-Type') === 'text/event-stream') {
376
+ return false;
377
+ }
378
+ // use compression filter function
379
+ return compression.filter(req, res);
380
+ };
381
+ BaseChyz.express.use(compression({ filter: shouldCompress }));
382
+ //
383
+ // //static file path
384
+ if (this.config.staticFilePath) {
385
+ BaseChyz.info('Static file path', this.config.staticFilePath);
386
+ BaseChyz.express.use(express.static(this.config.staticFilePath));
387
+ }
341
388
  //Middlewares
342
389
  for (const middleware1 of Object.keys(BaseChyz.middlewares)) {
343
- if (!Utils_1.default.isFunction(middleware1)) {
390
+ if (!Utils_1.Utils.isFunction(middleware1)) {
344
391
  let keycloak = BaseChyz.middlewares[middleware1].keycloak;
345
392
  BaseChyz.express.use(keycloak.middleware(BaseChyz.middlewares[middleware1].config));
346
393
  }
@@ -375,9 +422,10 @@ class BaseChyz {
375
422
  }
376
423
  }
377
424
  exports.default = BaseChyz;
378
- BaseChyz.express = express();
425
+ BaseChyz.express = Server;
426
+ BaseChyz.logs = new Logs_1.Logs();
379
427
  BaseChyz._validate = validate;
380
428
  BaseChyz.controllers = [];
381
429
  BaseChyz.components = {};
382
430
  BaseChyz.middlewares = {};
383
- //# sourceMappingURL=BaseChyz.js.map
431
+ BaseChyz._EventEmitter = em;
@@ -0,0 +1,33 @@
1
+ /// <reference types="express" />
2
+ import { Request, Response } from "../index";
3
+ import { CBaseObject } from "./CBaseObject";
4
+ export declare class ActionFilter extends CBaseObject {
5
+ only: any;
6
+ /**
7
+ * @var array list of action IDs that this filter should not apply to.
8
+ * @see only
9
+ */
10
+ except: never[];
11
+ init(): void;
12
+ /**
13
+ *
14
+ * @param route
15
+ * @param req
16
+ * @param res
17
+ */
18
+ beforeFilter(route: any, req: Request, res: Response): Promise<void>;
19
+ /**
20
+ * This method is invoked right before an action is to be executed (after all possible filters.)
21
+ * You may override this method to do last-minute preparation for the action.
22
+ * @param Action $action the action to be executed.
23
+ * @return bool whether the action should continue to be executed.
24
+ */
25
+ beforeAction(route: any, req: Request, res: Response): Promise<boolean>;
26
+ /**
27
+ *
28
+ * @param action
29
+ * @protected
30
+ */
31
+ protected isActive(action: any): boolean;
32
+ }
33
+ //# sourceMappingURL=ActionFilter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActionFilter.d.ts","sourceRoot":"","sources":["../../src/base/ActionFilter.ts"],"names":[],"mappings":";AAMA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,UAAU,CAAC;AAE3C,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AAEzC,qBAAa,YAAa,SAAQ,WAAW;IAElC,IAAI,EAAE,GAAG,CAAC;IAEjB;;;OAGG;IACI,MAAM,UAAM;IAGZ,IAAI;IAIX;;;;;OAKG;IACU,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ;IAQjE;;;;;OAKG;IACU,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ;IAIjE;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG;CA0BjC"}
@@ -8,14 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.ActionFilter = void 0;
16
- const Utils_1 = __importDefault(require("../requiments/Utils"));
17
- const Behavior_1 = require("./Behavior");
18
- class ActionFilter extends Behavior_1.Behavior {
13
+ const Utils_1 = require("../requiments/Utils");
14
+ const CBaseObject_1 = require("./CBaseObject");
15
+ class ActionFilter extends CBaseObject_1.CBaseObject {
19
16
  constructor() {
20
17
  super(...arguments);
21
18
  /**
@@ -40,17 +37,33 @@ class ActionFilter extends Behavior_1.Behavior {
40
37
  yield this.beforeAction(route, req, res);
41
38
  });
42
39
  }
40
+ /**
41
+ * This method is invoked right before an action is to be executed (after all possible filters.)
42
+ * You may override this method to do last-minute preparation for the action.
43
+ * @param Action $action the action to be executed.
44
+ * @return bool whether the action should continue to be executed.
45
+ */
46
+ beforeAction(route, req, res) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return true;
49
+ });
50
+ }
51
+ /**
52
+ *
53
+ * @param action
54
+ * @protected
55
+ */
43
56
  isActive(action) {
44
57
  let id = action.id;
45
58
  let onlyMatch = false;
46
59
  let exceptMatch = false;
47
- if (Utils_1.default.isEmpty(this.only)) {
60
+ if (Utils_1.Utils.isEmpty(this.only)) {
48
61
  onlyMatch = true;
49
62
  }
50
63
  else {
51
64
  onlyMatch = false;
52
65
  for (const onlyKey of this.only) {
53
- if (Utils_1.default.matchWildcard(action.id, onlyKey)) {
66
+ if (Utils_1.Utils.matchWildcard(action.id, onlyKey)) {
54
67
  onlyMatch = true;
55
68
  break;
56
69
  }
@@ -65,17 +78,5 @@ class ActionFilter extends Behavior_1.Behavior {
65
78
  }
66
79
  return !exceptMatch && onlyMatch;
67
80
  }
68
- /**
69
- * This method is invoked right before an action is to be executed (after all possible filters.)
70
- * You may override this method to do last-minute preparation for the action.
71
- * @param Action $action the action to be executed.
72
- * @return bool whether the action should continue to be executed.
73
- */
74
- beforeAction(route, req, res) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- return true;
77
- });
78
- }
79
81
  }
80
82
  exports.ActionFilter = ActionFilter;
81
- //# sourceMappingURL=ActionFilter.js.map
@@ -0,0 +1,11 @@
1
+ export declare class BaseError extends Error {
2
+ private statusCode;
3
+ constructor(message: string, statusCode?: number);
4
+ toString(): string;
5
+ toJSON(): {
6
+ code: number | undefined;
7
+ name: string;
8
+ message: string;
9
+ };
10
+ }
11
+ //# sourceMappingURL=BaseError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseError.d.ts","sourceRoot":"","sources":["../../src/base/BaseError.ts"],"names":[],"mappings":"AASA,qBAAa,SAAU,SAAQ,KAAK;IAChC,OAAO,CAAC,UAAU,CAAS;gBAEf,OAAO,EAAE,MAAM,EAAC,UAAU,SAAI;IAQ1C,QAAQ;IAGR,MAAM;;;;;CAGT"}
package/base/BaseError.js CHANGED
@@ -5,16 +5,13 @@
5
5
  * E-mail: cihan@chy.com.tr
6
6
  * Github:https://github.com/cihan53/
7
7
  */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.BaseError = void 0;
13
- const Utils_1 = __importDefault(require("../requiments/Utils"));
10
+ const Utils_1 = require("../requiments/Utils");
14
11
  class BaseError extends Error {
15
12
  constructor(message, statusCode = 500) {
16
13
  super(message);
17
- this.message = Utils_1.default.isString(message) ? message : JSON.stringify(message);
14
+ this.message = Utils_1.Utils.isString(message) ? message : JSON.stringify(message);
18
15
  this.name = this.constructor.name; // good practice
19
16
  this.statusCode = statusCode; // error code for responding to client
20
17
  //Error.captureStackTrace(this)
@@ -27,4 +24,3 @@ class BaseError extends Error {
27
24
  }
28
25
  }
29
26
  exports.BaseError = BaseError;
30
- //# sourceMappingURL=BaseError.js.map
@@ -0,0 +1,4 @@
1
+ import { CBaseObject } from "./CBaseObject";
2
+ export declare class Behavior extends CBaseObject {
3
+ }
4
+ //# sourceMappingURL=Behavior.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Behavior.d.ts","sourceRoot":"","sources":["../../src/base/Behavior.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1C,qBAAa,QAAS,SAAQ,WAAW;CAGxC"}
package/base/Behavior.js CHANGED
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Behavior = void 0;
4
- const BaseObject_1 = require("./BaseObject");
5
- class Behavior extends BaseObject_1.BaseObject {
4
+ const CBaseObject_1 = require("./CBaseObject");
5
+ class Behavior extends CBaseObject_1.CBaseObject {
6
6
  }
7
7
  exports.Behavior = Behavior;
8
- //# sourceMappingURL=Behavior.js.map
@@ -0,0 +1,5 @@
1
+ import { Configurable } from "./Configurable";
2
+ export declare class CBaseObject implements Configurable {
3
+ init(): void;
4
+ }
5
+ //# sourceMappingURL=CBaseObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CBaseObject.d.ts","sourceRoot":"","sources":["../../src/base/CBaseObject.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAG5C,qBAAa,WAAY,YAAW,YAAY;IAErC,IAAI;CAGd"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
4
+ * Author: Cihan Ozturk
5
+ * E-mail: cihan@chy.com.tr
6
+ * Github:https://github.com/cihan53/
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.CBaseObject = void 0;
10
+ const index_1 = require("../index");
11
+ class CBaseObject {
12
+ init() {
13
+ index_1.BaseChyz.debug("BaseObject init.....");
14
+ }
15
+ }
16
+ exports.CBaseObject = CBaseObject;
@@ -0,0 +1,2 @@
1
+ export { Request, Response, NextFunction } from "express";
2
+ //# sourceMappingURL=CRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CRequest.d.ts","sourceRoot":"","sources":["../../src/base/CRequest.ts"],"names":[],"mappings":"AASA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /*
3
+ *
4
+ * Copyright (c) 2022.. Chy Bilgisayar Bilisim
5
+ * Author: Cihan Ozturk
6
+ * E-mail: cihan@chy.com.tr
7
+ * Github:https://github.com/cihan53/
8
+ *
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });