chyz 1.2.5-rc.0 → 2.0.0-rc.11

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 +60 -0
  2. package/BaseChyz.d.ts.map +1 -0
  3. package/BaseChyz.js +121 -82
  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 +7 -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 +26 -32
  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,60 @@
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
+ get controllerpath(): string;
17
+ set controllerpath(value: string);
18
+ /**
19
+ *
20
+ */
21
+ init(): void;
22
+ /**
23
+ * Listen port number
24
+ * Server port number get
25
+ */
26
+ get port(): number;
27
+ /**
28
+ * Listen port number
29
+ * Server port number setting
30
+ * @param value
31
+ */
32
+ set port(value: number);
33
+ static get validate(): any;
34
+ static set validate(value: any);
35
+ app(config?: any): BaseChyz;
36
+ static trace(...args: any[]): void;
37
+ static debug(...args: any[]): void;
38
+ static info(...args: any[]): void;
39
+ static warn(...args: any[]): void;
40
+ static error(...args: any[]): void;
41
+ static fatal(...args: any[]): void;
42
+ static warning(...args: any[]): void;
43
+ static t(text: string): string;
44
+ errorLogger(error: any, req: any, res: any, next: any): void;
45
+ errorResponder(error: any, req: any, res: any, next: any): void;
46
+ errorHandler(err: any, req: any, res: any, next: any): any;
47
+ static getComponent(key: any): any;
48
+ static getMiddlewares(key: any): any;
49
+ /**
50
+ * load model
51
+ */
52
+ loadModels(): Promise<void>;
53
+ /**
54
+ * load contoller
55
+ */
56
+ loadController(): Promise<void>;
57
+ middleware(): void;
58
+ Start(): this;
59
+ }
60
+ //# 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;AA8EjC,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;IAGnC,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;IAwDV,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,49 +72,46 @@ 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
+ /**
83
+ * set request id
84
+ */
85
+ Object.defineProperty(Server.request, 'reqId', {
86
+ configurable: true,
87
+ enumerable: true,
88
+ writable: true
89
+ });
90
+ Object.defineProperty(Server.request, 'user', {
91
+ configurable: true,
92
+ enumerable: true,
93
+ writable: true
94
+ });
95
+ Object.defineProperty(Server.request, 'identity', {
96
+ configurable: true,
97
+ enumerable: true,
98
+ writable: true
99
+ });
61
100
  class BaseChyz {
62
101
  constructor() {
63
- var _a;
64
102
  this._port = 3001;
65
- this._logConfig = (_a = require('./log/config/log4js.json')) !== null && _a !== void 0 ? _a : {};
66
103
  this._controllerpath = "Controllers";
67
104
  }
68
- get logConfig() {
69
- return this._logConfig;
70
- }
71
- set logConfig(value) {
72
- this._logConfig = value;
73
- }
74
105
  get controllerpath() {
75
106
  return this._controllerpath;
76
107
  }
77
108
  set controllerpath(value) {
78
109
  this._controllerpath = value;
79
110
  }
111
+ /**
112
+ *
113
+ */
80
114
  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
115
  /**
100
116
  * server port setting
101
117
  */
@@ -147,16 +163,19 @@ class BaseChyz {
147
163
  * Config set
148
164
  */
149
165
  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");
166
+ /**
167
+ * log setting
168
+ */
169
+ if (this.config.logs instanceof Logs_1.Logs) {
170
+ BaseChyz.logs = this.config.logs;
171
+ }
172
+ let components = Utils_1.Utils.findKeyValue(config, "components");
154
173
  if (components) {
155
174
  for (const componentsKey in components) {
156
175
  let comp = components[componentsKey];
157
176
  BaseChyz.debug("Create Component ", componentsKey);
158
177
  try {
159
- BaseChyz.components[componentsKey] = Utils_1.default.createObject(new comp.class, comp);
178
+ BaseChyz.components[componentsKey] = Utils_1.Utils.createObject(new comp.class, comp);
160
179
  (_a = BaseChyz.components[componentsKey]) === null || _a === void 0 ? void 0 : _a.init();
161
180
  }
162
181
  catch (e) {
@@ -164,11 +183,11 @@ class BaseChyz {
164
183
  }
165
184
  }
166
185
  }
167
- let middlewares = Utils_1.default.findKeyValue(config, "middlewares");
186
+ let middlewares = Utils_1.Utils.findKeyValue(config, "middlewares");
168
187
  if (middlewares) {
169
188
  for (const middlewareKey in middlewares) {
170
189
  let middleware1 = middlewares[middlewareKey];
171
- BaseChyz.logs().debug("Create middlewares ", middlewareKey);
190
+ BaseChyz.debug("Create middlewares ", middlewareKey);
172
191
  BaseChyz.middlewares[middlewareKey] = middleware1;
173
192
  // BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
174
193
  }
@@ -176,35 +195,26 @@ class BaseChyz {
176
195
  this.init();
177
196
  return this;
178
197
  }
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
198
  static trace(...args) {
189
- BaseChyz.logs().fatal(...arguments);
199
+ BaseChyz.logs.fatal(...arguments);
190
200
  }
191
201
  static debug(...args) {
192
- BaseChyz.logs().debug(...arguments);
202
+ BaseChyz.logs.debug(...arguments);
193
203
  }
194
204
  static info(...args) {
195
- BaseChyz.logs().info(...arguments);
205
+ BaseChyz.logs.info(...arguments);
196
206
  }
197
207
  static warn(...args) {
198
- BaseChyz.logs().warn(...arguments);
208
+ BaseChyz.logs.warn(...arguments);
199
209
  }
200
210
  static error(...args) {
201
- BaseChyz.logs().error(...arguments);
211
+ BaseChyz.logs.error(...arguments);
202
212
  }
203
213
  static fatal(...args) {
204
- BaseChyz.logs().fatal(...arguments);
214
+ BaseChyz.logs.fatal(...arguments);
205
215
  }
206
216
  static warning(...args) {
207
- BaseChyz.logs().warn(...arguments);
217
+ BaseChyz.logs.warn(...arguments);
208
218
  }
209
219
  static t(text) {
210
220
  return text;
@@ -251,6 +261,9 @@ class BaseChyz {
251
261
  models[className.replace("Class", "")] = new model[className];
252
262
  }
253
263
  });
264
+ /**
265
+ *
266
+ */
254
267
  base_1.ModelManager._register(models);
255
268
  for (const key of Object.keys(base_1.ModelManager)) {
256
269
  if (key != "_register") {
@@ -264,9 +277,19 @@ class BaseChyz {
264
277
  */
265
278
  loadController() {
266
279
  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}`);
280
+ // let articlesEndpoints: string[] = [];
281
+ for (const file of fs.readdirSync(`${this._controllerpath}/`)) {
282
+ // let controller = require(`${this._controllerpath}/${file}`);
283
+ let controller = (yield Promise.resolve().then(() => __importStar(require(`${this._controllerpath}/${file}`))));
284
+ if (controller[file.replace(".ts", "")]) {
285
+ controller = controller[file.replace(".ts", "")];
286
+ }
287
+ else if (controller.default) {
288
+ controller = controller.default;
289
+ }
290
+ else {
291
+ throw new base_1.InvalidConfigException((0, Utils_1.default)("Invalid Controller"));
292
+ }
270
293
  // This is our instantiated class
271
294
  const instance = new controller();
272
295
  BaseChyz.controllers.push(instance);
@@ -276,12 +299,12 @@ class BaseChyz {
276
299
  // Our `routes` array containing all our routes for this controller
277
300
  // @ts-ignore
278
301
  const routes = Reflect.getMetadata('routes', controller);
279
- BaseChyz.logs().debug("Controller load ", controller.name, `(${prefix})`);
302
+ BaseChyz.debug("Controller load ", controller.name, `(${prefix})`);
280
303
  if (routes) {
281
304
  routes.forEach(route => {
282
305
  let actionId = route.path == "/" || route.path == "" ? instance.defaultAction : route.path;
283
306
  route.id = actionId;
284
- BaseChyz.logs().debug("Controller route Path", prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`));
307
+ BaseChyz.debug("Controller route Path", prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`));
285
308
  BaseChyz.express[route.requestMethod](prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`), (req, res, next) => __awaiter(this, void 0, void 0, function* () {
286
309
  try {
287
310
  BaseChyz.debug(`Call Request id ${instance.id}`);
@@ -317,30 +340,46 @@ class BaseChyz {
317
340
  }));
318
341
  });
319
342
  }
320
- });
343
+ }
321
344
  });
322
345
  }
323
346
  middleware() {
324
347
  BaseChyz.express.use(bodyParser.json({ limit: '1mb' }));
325
348
  BaseChyz.express.use(bodyParser.urlencoded({ limit: '1mb', extended: true })); // support encoded bodies
326
349
  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
- });
350
+ BaseChyz.express.use(cors());
351
+ //
352
+ // // CORS
353
+ // BaseChyz.express.use(function (req: any, res: Response, next: any) {
354
+ // // @ts-ignore
355
+ // req.reqId = Utils.uniqueId("chyzzzz_")
356
+ // res.setHeader('Content-Type', 'application/json');
357
+ // res.setHeader("Access-Control-Allow-Origin", "*");
358
+ // res.setHeader("Access-Control-Allow-Credentials", "true");
359
+ // res.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
360
+ // 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");
361
+ // next();
362
+ // });
363
+ //
339
364
  // compress all responses
340
- BaseChyz.express.use(compression());
365
+ const shouldCompress = (req, res) => {
366
+ // don't compress responses explicitly asking not
367
+ if (req.headers["x-no-compression"] || res.getHeader('Content-Type') === 'text/event-stream') {
368
+ return false;
369
+ }
370
+ // use compression filter function
371
+ return compression.filter(req, res);
372
+ };
373
+ BaseChyz.express.use(compression({ filter: shouldCompress }));
374
+ //
375
+ // //static file path
376
+ if (this.config.staticFilePath) {
377
+ BaseChyz.info('Static file path', this.config.staticFilePath);
378
+ BaseChyz.express.use(express.static(this.config.staticFilePath));
379
+ }
341
380
  //Middlewares
342
381
  for (const middleware1 of Object.keys(BaseChyz.middlewares)) {
343
- if (!Utils_1.default.isFunction(middleware1)) {
382
+ if (!Utils_1.Utils.isFunction(middleware1)) {
344
383
  let keycloak = BaseChyz.middlewares[middleware1].keycloak;
345
384
  BaseChyz.express.use(keycloak.middleware(BaseChyz.middlewares[middleware1].config));
346
385
  }
@@ -375,9 +414,9 @@ class BaseChyz {
375
414
  }
376
415
  }
377
416
  exports.default = BaseChyz;
378
- BaseChyz.express = express();
417
+ BaseChyz.express = Server;
418
+ BaseChyz.logs = new Logs_1.Logs();
379
419
  BaseChyz._validate = validate;
380
420
  BaseChyz.controllers = [];
381
421
  BaseChyz.components = {};
382
422
  BaseChyz.middlewares = {};
383
- //# sourceMappingURL=BaseChyz.js.map
@@ -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 });
@@ -0,0 +1,44 @@
1
+ import { Component } from "./Component";
2
+ import { RouteDefinition } from "../model/RouteDefinition";
3
+ import { Request, Response } from "express";
4
+ export declare class CWebController extends Component {
5
+ /**
6
+ * @var string the ID of this controller.
7
+ */
8
+ id: string;
9
+ defaultAction: string;
10
+ constructor(config: any);
11
+ init(): void;
12
+ /**
13
+ * This method is invoked right before an action is executed.
14
+ * @param $action
15
+ */
16
+ beforeAction(route: RouteDefinition, req: Request, res: Response): Promise<void>;
17
+ /**
18
+ * This method is invoked right after an action is executed.
19
+ * @param action
20
+ */
21
+ afterAction(action: any, req: Request, res: Response): void;
22
+ /**
23
+ *
24
+
25
+ Checks the privilege of the current user.
26
+
27
+ This method should be overridden to check whether the current user has the privilege to run the specified action against the specified data model. If the user does not have access, a yii\web\ForbiddenHttpException should be thrown.
28
+
29
+ */
30
+ checkAccess(action: any, model?: null, params?: any): void;
31
+ /**
32
+ * Send data formatted as JSON.
33
+
34
+ This method is a shortcut for sending data formatted as JSON. It will return the response application component after configuring the format and setting the data that should be formatted. A common usage will b
35
+ */
36
+ asJson(data: any): void;
37
+ /**
38
+ * Send data formatted as XML.
39
+
40
+ This method is a shortcut for sending data formatted as XML. It will return the response application component after configuring the format and setting the data that should be formatted. A common usage will be:
41
+ */
42
+ asXml(data: any): void;
43
+ }
44
+ //# sourceMappingURL=CWebController.d.ts.map