chyz 2.0.1-rc.3 → 2.0.1-rc.36

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 (229) hide show
  1. package/BaseChyz.ts +623 -0
  2. package/README.md +518 -518
  3. package/base/ActionFilter.ts +88 -0
  4. package/base/BadRequestHttpException.ts +14 -0
  5. package/base/{BaseError.js → BaseError.ts} +26 -18
  6. package/base/Behavior.ts +6 -0
  7. package/base/CBaseObject.ts +17 -0
  8. package/base/CEvents.ts +24 -0
  9. package/base/{CRequest.js → CRequest.ts} +6 -2
  10. package/base/CWebController.ts +90 -0
  11. package/base/Component.ts +66 -0
  12. package/{model/RouteDefinition.js → base/Configurable.ts} +4 -2
  13. package/base/DataErrorDbException.ts +16 -0
  14. package/base/DbConnection.ts +55 -0
  15. package/base/ForbiddenHttpException.ts +15 -0
  16. package/base/InvalidArgumentException.ts +16 -0
  17. package/base/InvalidConfigException.ts +16 -0
  18. package/base/{Logs.js → Logs.ts} +41 -24
  19. package/base/{Model.js → Model.ts} +225 -158
  20. package/base/{ModelManager.js → ModelManager.ts} +7 -7
  21. package/base/NotFoundHttpException.ts +14 -0
  22. package/base/RestClient.ts +26 -0
  23. package/base/UnauthorizedHttpException.ts +17 -0
  24. package/base/ValidationHttpException.ts +14 -0
  25. package/base/db/Exception.ts +14 -0
  26. package/base/index.ts +19 -0
  27. package/decorator/Middleware.ts +9 -0
  28. package/decorator/{controller.js → controller.ts} +7 -9
  29. package/decorator/{delete.js → delete.ts} +9 -9
  30. package/decorator/enums/ControllerDecoratorParams.ts +5 -0
  31. package/decorator/{get.js → get.ts} +11 -10
  32. package/decorator/index.ts +5 -0
  33. package/decorator/{post.js → post.ts} +10 -10
  34. package/decorator/{put.js → put.ts} +9 -9
  35. package/filters/AccessControl.ts +74 -0
  36. package/filters/AccessRule.ts +182 -0
  37. package/filters/auth/{AuthInterface.d.ts → AuthInterface.ts} +15 -7
  38. package/filters/auth/AuthMethod.ts +100 -0
  39. package/filters/auth/HttpBasicAuth.ts +79 -0
  40. package/filters/auth/HttpBearerAuth.ts +34 -0
  41. package/filters/auth/HttpHeaderAuth.ts +61 -0
  42. package/filters/auth/JwtHttpBearerAuth.ts +83 -0
  43. package/filters/auth/KeyCloakHttpBearerAuth.ts +114 -0
  44. package/filters/auth/index.ts +4 -0
  45. package/filters/index.ts +2 -0
  46. package/index.ts +80 -0
  47. package/log/config/log4js.json +55 -55
  48. package/model/RouteDefinition.ts +18 -0
  49. package/package.json +63 -61
  50. package/rbac/AuthAssignment.ts +50 -0
  51. package/rbac/{AuthItem.js → AuthItem.ts} +22 -16
  52. package/rbac/{AuthItemChild.js → AuthItemChild.ts} +21 -14
  53. package/rbac/AuthManager.ts +399 -0
  54. package/rbac/index.ts +12 -0
  55. package/{web/IdentityInterface.js → requiments/Glob.ts} +3 -2
  56. package/requiments/{ReflectUtil.js → ReflectUtil.ts} +6 -4
  57. package/requiments/{Utils.js → Utils.ts} +40 -34
  58. package/validators/BooleanValidator.ts +0 -0
  59. package/validators/CompareValidator.ts +0 -0
  60. package/validators/DateValidator.ts +0 -0
  61. package/validators/EmailValidator.ts +0 -0
  62. package/validators/Validator.ts +27 -0
  63. package/web/{IdentityInterface.d.ts → IdentityInterface.ts} +15 -2
  64. package/web/WebUser.ts +187 -0
  65. package/BaseChyz.d.ts +0 -74
  66. package/BaseChyz.d.ts.map +0 -1
  67. package/BaseChyz.js +0 -569
  68. package/base/ActionFilter.d.ts +0 -33
  69. package/base/ActionFilter.d.ts.map +0 -1
  70. package/base/ActionFilter.js +0 -90
  71. package/base/BadRequestHttpException.d.ts +0 -6
  72. package/base/BadRequestHttpException.d.ts.map +0 -1
  73. package/base/BadRequestHttpException.js +0 -17
  74. package/base/BaseError.d.ts +0 -44
  75. package/base/BaseError.d.ts.map +0 -1
  76. package/base/Behavior.d.ts +0 -4
  77. package/base/Behavior.d.ts.map +0 -1
  78. package/base/Behavior.js +0 -7
  79. package/base/CBaseObject.d.ts +0 -5
  80. package/base/CBaseObject.d.ts.map +0 -1
  81. package/base/CBaseObject.js +0 -16
  82. package/base/CEvents.d.ts +0 -13
  83. package/base/CEvents.d.ts.map +0 -1
  84. package/base/CEvents.js +0 -24
  85. package/base/CRequest.d.ts +0 -2
  86. package/base/CRequest.d.ts.map +0 -1
  87. package/base/CWebController.d.ts +0 -44
  88. package/base/CWebController.d.ts.map +0 -1
  89. package/base/CWebController.js +0 -81
  90. package/base/Component.d.ts +0 -21
  91. package/base/Component.d.ts.map +0 -1
  92. package/base/Component.js +0 -57
  93. package/base/Configurable.d.ts +0 -3
  94. package/base/Configurable.d.ts.map +0 -1
  95. package/base/Configurable.js +0 -8
  96. package/base/DataErrorDbException.d.ts +0 -6
  97. package/base/DataErrorDbException.d.ts.map +0 -1
  98. package/base/DataErrorDbException.js +0 -17
  99. package/base/DbConnection.d.ts +0 -13
  100. package/base/DbConnection.d.ts.map +0 -1
  101. package/base/DbConnection.js +0 -53
  102. package/base/ForbiddenHttpException.d.ts +0 -5
  103. package/base/ForbiddenHttpException.d.ts.map +0 -1
  104. package/base/ForbiddenHttpException.js +0 -16
  105. package/base/InvalidArgumentException.d.ts +0 -6
  106. package/base/InvalidArgumentException.d.ts.map +0 -1
  107. package/base/InvalidArgumentException.js +0 -17
  108. package/base/InvalidConfigException.d.ts +0 -6
  109. package/base/InvalidConfigException.d.ts.map +0 -1
  110. package/base/InvalidConfigException.js +0 -17
  111. package/base/Logs.d.ts +0 -22
  112. package/base/Logs.d.ts.map +0 -1
  113. package/base/Model.d.ts +0 -302
  114. package/base/Model.d.ts.map +0 -1
  115. package/base/ModelManager.d.ts +0 -2
  116. package/base/ModelManager.d.ts.map +0 -1
  117. package/base/NotFoundHttpException.d.ts +0 -6
  118. package/base/NotFoundHttpException.d.ts.map +0 -1
  119. package/base/NotFoundHttpException.js +0 -17
  120. package/base/RestClient.d.ts +0 -7
  121. package/base/RestClient.d.ts.map +0 -1
  122. package/base/RestClient.js +0 -25
  123. package/base/UnauthorizedHttpException.d.ts +0 -6
  124. package/base/UnauthorizedHttpException.d.ts.map +0 -1
  125. package/base/UnauthorizedHttpException.js +0 -17
  126. package/base/ValidationHttpException.d.ts +0 -6
  127. package/base/ValidationHttpException.d.ts.map +0 -1
  128. package/base/ValidationHttpException.js +0 -17
  129. package/base/db/Exception.d.ts +0 -7
  130. package/base/db/Exception.d.ts.map +0 -1
  131. package/base/db/Exception.js +0 -15
  132. package/base/index.d.ts +0 -20
  133. package/base/index.d.ts.map +0 -1
  134. package/base/index.js +0 -41
  135. package/decorator/Middleware.d.ts +0 -4
  136. package/decorator/Middleware.d.ts.map +0 -1
  137. package/decorator/Middleware.js +0 -11
  138. package/decorator/controller.d.ts +0 -3
  139. package/decorator/controller.d.ts.map +0 -1
  140. package/decorator/delete.d.ts +0 -3
  141. package/decorator/delete.d.ts.map +0 -1
  142. package/decorator/enums/ControllerDecoratorParams.d.ts +0 -6
  143. package/decorator/enums/ControllerDecoratorParams.d.ts.map +0 -1
  144. package/decorator/enums/ControllerDecoratorParams.js +0 -9
  145. package/decorator/get.d.ts +0 -3
  146. package/decorator/get.d.ts.map +0 -1
  147. package/decorator/index.d.ts +0 -6
  148. package/decorator/index.d.ts.map +0 -1
  149. package/decorator/index.js +0 -13
  150. package/decorator/post.d.ts +0 -3
  151. package/decorator/post.d.ts.map +0 -1
  152. package/decorator/put.d.ts +0 -3
  153. package/decorator/put.d.ts.map +0 -1
  154. package/filters/AccessControl.d.ts +0 -13
  155. package/filters/AccessControl.d.ts.map +0 -1
  156. package/filters/AccessControl.js +0 -83
  157. package/filters/AccessRule.d.ts +0 -83
  158. package/filters/AccessRule.d.ts.map +0 -1
  159. package/filters/AccessRule.js +0 -136
  160. package/filters/auth/AuthInterface.d.ts.map +0 -1
  161. package/filters/auth/AuthInterface.js +0 -2
  162. package/filters/auth/AuthMethod.d.ts +0 -38
  163. package/filters/auth/AuthMethod.d.ts.map +0 -1
  164. package/filters/auth/AuthMethod.js +0 -82
  165. package/filters/auth/HttpBasicAuth.d.ts +0 -24
  166. package/filters/auth/HttpBasicAuth.d.ts.map +0 -1
  167. package/filters/auth/HttpBasicAuth.js +0 -78
  168. package/filters/auth/HttpBearerAuth.d.ts +0 -18
  169. package/filters/auth/HttpBearerAuth.d.ts.map +0 -1
  170. package/filters/auth/HttpBearerAuth.js +0 -33
  171. package/filters/auth/HttpHeaderAuth.d.ts +0 -19
  172. package/filters/auth/HttpHeaderAuth.d.ts.map +0 -1
  173. package/filters/auth/HttpHeaderAuth.js +0 -64
  174. package/filters/auth/JwtHttpBearerAuth.d.ts +0 -21
  175. package/filters/auth/JwtHttpBearerAuth.d.ts.map +0 -1
  176. package/filters/auth/JwtHttpBearerAuth.js +0 -87
  177. package/filters/auth/KeyCloakHttpBearerAuth.d.ts +0 -23
  178. package/filters/auth/KeyCloakHttpBearerAuth.d.ts.map +0 -1
  179. package/filters/auth/KeyCloakHttpBearerAuth.js +0 -116
  180. package/filters/auth/index.d.ts +0 -5
  181. package/filters/auth/index.d.ts.map +0 -1
  182. package/filters/auth/index.js +0 -11
  183. package/filters/index.d.ts +0 -3
  184. package/filters/index.d.ts.map +0 -1
  185. package/filters/index.js +0 -7
  186. package/index.d.ts +0 -26
  187. package/index.d.ts.map +0 -1
  188. package/index.js +0 -72
  189. package/model/RouteDefinition.d.ts +0 -7
  190. package/model/RouteDefinition.d.ts.map +0 -1
  191. package/rbac/AuthAssignment.d.ts +0 -19
  192. package/rbac/AuthAssignment.d.ts.map +0 -1
  193. package/rbac/AuthAssignment.js +0 -44
  194. package/rbac/AuthItem.d.ts +0 -27
  195. package/rbac/AuthItem.d.ts.map +0 -1
  196. package/rbac/AuthItemChild.d.ts +0 -19
  197. package/rbac/AuthItemChild.d.ts.map +0 -1
  198. package/rbac/AuthManager.d.ts +0 -112
  199. package/rbac/AuthManager.d.ts.map +0 -1
  200. package/rbac/AuthManager.js +0 -356
  201. package/rbac/index.d.ts +0 -5
  202. package/rbac/index.d.ts.map +0 -1
  203. package/rbac/index.js +0 -28
  204. package/requiments/Glob.d.ts +0 -3
  205. package/requiments/Glob.d.ts.map +0 -1
  206. package/requiments/Glob.js +0 -10
  207. package/requiments/ReflectUtil.d.ts +0 -1
  208. package/requiments/ReflectUtil.d.ts.map +0 -1
  209. package/requiments/Utils.d.ts +0 -2
  210. package/requiments/Utils.d.ts.map +0 -1
  211. package/validators/BooleanValidator.d.ts +0 -1
  212. package/validators/BooleanValidator.d.ts.map +0 -1
  213. package/validators/BooleanValidator.js +0 -1
  214. package/validators/CompareValidator.d.ts +0 -1
  215. package/validators/CompareValidator.d.ts.map +0 -1
  216. package/validators/CompareValidator.js +0 -1
  217. package/validators/DateValidator.d.ts +0 -1
  218. package/validators/DateValidator.d.ts.map +0 -1
  219. package/validators/DateValidator.js +0 -1
  220. package/validators/EmailValidator.d.ts +0 -1
  221. package/validators/EmailValidator.d.ts.map +0 -1
  222. package/validators/EmailValidator.js +0 -1
  223. package/validators/Validator.d.ts +0 -18
  224. package/validators/Validator.d.ts.map +0 -1
  225. package/validators/Validator.js +0 -27
  226. package/web/IdentityInterface.d.ts.map +0 -1
  227. package/web/WebUser.d.ts +0 -72
  228. package/web/WebUser.d.ts.map +0 -1
  229. package/web/WebUser.js +0 -165
@@ -0,0 +1,88 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+ import {Request, Response} from "../index";
8
+ import {Utils} from "../requiments/Utils";
9
+ import {CBaseObject} from "./CBaseObject"
10
+ import BaseChyz from "../BaseChyz";
11
+
12
+ export class ActionFilter extends CBaseObject {
13
+
14
+ public only: any;
15
+
16
+ /**
17
+ * @var array list of action IDs that this filter should not apply to.
18
+ * @see only
19
+ */
20
+ public except = [];
21
+
22
+
23
+ public init() {
24
+
25
+ }
26
+
27
+ /**
28
+ *
29
+ * @param route
30
+ * @param req
31
+ * @param res
32
+ */
33
+ public async beforeFilter(route: any, req: Request, res: Response) {
34
+ BaseChyz.debug("Controller->ActionFilter->beforeFilter ", JSON.stringify(route))
35
+
36
+ if (!this.isActive(route)) {
37
+ return;
38
+ }
39
+
40
+ await this.beforeAction(route, req, res)
41
+ }
42
+
43
+ /**
44
+ * This method is invoked right before an action is to be executed (after all possible filters.)
45
+ * You may override this method to do last-minute preparation for the action.
46
+ * @param Action $action the action to be executed.
47
+ * @return bool whether the action should continue to be executed.
48
+ */
49
+ public async beforeAction(route: any, req: Request, res: Response) {
50
+ return true;
51
+ }
52
+
53
+ /**
54
+ *
55
+ * @param action
56
+ * @protected
57
+ */
58
+ protected isActive(action: any) {
59
+ let id = action.id;
60
+ let onlyMatch: boolean = false;
61
+ let exceptMatch: boolean = false;
62
+
63
+ if (Utils.isEmpty(this.only)) {
64
+ onlyMatch = true;
65
+ } else {
66
+ onlyMatch = false;
67
+ for (const onlyKey of this.only) {
68
+ if (Utils.matchWildcard(action.id, onlyKey)) {
69
+ onlyMatch = true;
70
+ break;
71
+ }
72
+ }
73
+ }
74
+
75
+ for (const exceptKey in this.except) {
76
+ let pattern: string = this.except[exceptKey];
77
+ let reg = new RegExp(`${pattern}$`, "g");
78
+ let match = id.match(reg)
79
+ // let match = id.startsWith(pattern);
80
+ BaseChyz.debug("Controller->ActionFilter->isActive ", "id:",id, "patern:",pattern,"match:" ,match, JSON.stringify(this.except))
81
+ if (match && match.length > 0) {
82
+ exceptMatch = true;
83
+ }
84
+ }
85
+
86
+ return !exceptMatch && onlyMatch;
87
+ }
88
+ }
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import {BaseError} from "./BaseError";
9
+
10
+ export class BadRequestHttpException extends BaseError {
11
+ constructor ( public message: string) {
12
+ super(message,400);
13
+ }
14
+ }
@@ -1,13 +1,12 @@
1
- "use strict";
2
1
  /*
3
2
  * Copyright (c) 2021. Chy Bilgisayar Bilisim
4
3
  * Author: Cihan Ozturk
5
4
  * E-mail: cihan@chy.com.tr
6
5
  * Github:https://github.com/cihan53/
7
6
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.BaseError = void 0;
10
- const Utils_1 = require("../requiments/Utils");
7
+
8
+ import {Utils} from "../requiments/Utils";
9
+
11
10
  /**
12
11
  * 10.4 Client Error 4xx ............................................65
13
12
  * 10.4.1 400 Bad Request .........................................65
@@ -29,30 +28,39 @@ const Utils_1 = require("../requiments/Utils");
29
28
  * 10.4.17 416 Requested Range Not Satisfiable .....................69
30
29
  * 10.4.18 417 Expectation Failed ..................................70
31
30
  */
32
- class BaseError extends Error {
33
- constructor(message, statusCode = 500) {
31
+ export class BaseError extends Error {
32
+ statusCode: number;
33
+ orginal: any;
34
+ private readonly success: boolean;
35
+
36
+ constructor(message: any, statusCode = 500) {
34
37
  super(message);
38
+
35
39
  this.success = false;
36
- this.message = Utils_1.Utils.isString(message) ? message : JSON.stringify(message);
37
- this.name = this.constructor.name; // good practice
38
- this.statusCode = statusCode; // error code for responding to client
40
+ this.message = Utils.isString(message) ? message : JSON.stringify(message);
41
+ this.name = this.constructor.name // good practice
42
+ this.statusCode = statusCode // error code for responding to client
39
43
  //Error.captureStackTrace(this)
40
- this.orginal = Utils_1.Utils.isString(message) ? message : message;
44
+ this.orginal = Utils.isString(message) ? message : message
41
45
  }
46
+
42
47
  toString() {
43
- return `${this.name}[${this.statusCode}] ${this.message}`;
48
+ return `${this.name}[${this.statusCode}] ${this.message}`
44
49
  }
50
+
45
51
  toJSON() {
46
52
  if (process.env.NODE_ENV == "development" || process.env.NODE_ENV == "dev") {
47
- return { success: this.success, code: this === null || this === void 0 ? void 0 : this.statusCode, name: this.name.toString(),
53
+ return {success: this.success, code: this?.statusCode, name: this.name.toString(),
48
54
  message: this.message.toString(),
49
55
  stack: this.stack,
50
- orginal: this.orginal };
51
- }
52
- else {
53
- return { success: this.success, code: this === null || this === void 0 ? void 0 : this.statusCode, name: this.name.toString(),
54
- message: this.message.toString() };
56
+ orginal: this.orginal
57
+ }
58
+ } else {
59
+ return {success: this.success, code: this?.statusCode, name: this.name.toString(),
60
+ message: this.message.toString()
61
+ }
55
62
  }
63
+
56
64
  }
57
65
  }
58
- exports.BaseError = BaseError;
66
+
@@ -0,0 +1,6 @@
1
+ import {CBaseObject} from "./CBaseObject";
2
+
3
+ export class Behavior extends CBaseObject
4
+ {
5
+
6
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import {BaseChyz} from "../index";
9
+ import {Configurable} from "./Configurable";
10
+
11
+
12
+ export class CBaseObject implements Configurable {
13
+
14
+ public init() {
15
+ BaseChyz.debug("BaseObject init.....")
16
+ }
17
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2023.. Chy Bilgisayar Bilisim
4
+ * Author: Cihan Ozturk
5
+ * E-mail: cihan@chy.com.tr
6
+ * Github:https://github.com/cihan53/
7
+ *
8
+ */
9
+ export enum CEvents {
10
+ ON_INIT_BEFORE='oninitbefore',
11
+ ON_INIT_AFTER='oninitafter',
12
+ ON_MIDDLEWARE='onmiddleware',
13
+ ON_BEFORE_START = 'onbeforestart',
14
+ ON_AFTER_START = 'onafterestart',
15
+ ON_START = 'onstart',
16
+
17
+ ON_BEFORE_ACTION = 'onbeferoaction',
18
+ ON_AFTER_ACTION = 'onafteraction',
19
+
20
+ ON_DB_CONNECTION='ondbconnection',
21
+ ON_DB_DISCONNECT='ondbdisconnect'
22
+
23
+
24
+ }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /*
3
2
  *
4
3
  * Copyright (c) 2022.. Chy Bilgisayar Bilisim
@@ -7,4 +6,9 @@
7
6
  * Github:https://github.com/cihan53/
8
7
  *
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
9
+
10
+ export {Request ,Response, NextFunction} from "express";
11
+
12
+
13
+
14
+
@@ -0,0 +1,90 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import {Component} from "./Component";
9
+ import {RouteDefinition} from "../model/RouteDefinition";
10
+ import {Request, Response} from "express";
11
+ import BaseChyz from "../BaseChyz";
12
+ import {CEvents} from "./CEvents";
13
+
14
+ export class CWebController extends Component {
15
+
16
+
17
+ /**
18
+ * @var string the ID of this controller.
19
+ */
20
+ public id: string;
21
+ public defaultAction = 'index';
22
+
23
+ constructor(config: any) {
24
+ super();
25
+ this.id = this.constructor.name.replace("Controller", "").toLowerCase();
26
+ }
27
+
28
+ public init() {
29
+ super.init();
30
+ }
31
+
32
+
33
+ /**
34
+ * This method is invoked right before an action is executed.
35
+ * @param $action
36
+ */
37
+ public async beforeAction(route: RouteDefinition, req: Request, res: Response) {
38
+
39
+ if (route.id == "" || route.id == "/")
40
+ this.id = this.defaultAction
41
+
42
+ this.ensureBehaviors()
43
+ for (const name of Object.keys(this.getBehaviors)) {
44
+ await this.getBehaviors[name].beforeFilter(route, req, res);
45
+ }
46
+
47
+
48
+ BaseChyz.EventEmitter.emit(CEvents.ON_BEFORE_ACTION, this, req, res)
49
+ }
50
+
51
+ /**
52
+ * This method is invoked right after an action is executed.
53
+ * @param action
54
+ */
55
+ public afterAction(action: any, req: Request, res: Response) {
56
+
57
+ BaseChyz.EventEmitter.emit(CEvents.ON_AFTER_ACTION, this, req, res)
58
+ }
59
+
60
+ /**
61
+ *
62
+
63
+ Checks the privilege of the current user.
64
+
65
+ 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.
66
+
67
+ */
68
+ public checkAccess(action: any, model = null, params: any = []) {
69
+
70
+ }
71
+
72
+ /**
73
+ * Send data formatted as JSON.
74
+
75
+ 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
76
+ */
77
+ asJson(data: any) {
78
+
79
+ }
80
+
81
+ /**
82
+ * Send data formatted as XML.
83
+
84
+ 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:
85
+ */
86
+ asXml(data: any) {
87
+
88
+ }
89
+
90
+ }
@@ -0,0 +1,66 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import {CBaseObject} from "./CBaseObject"
9
+ import {ActionFilter} from "./ActionFilter";
10
+ import {Utils} from "../requiments/Utils";
11
+
12
+ export class Component extends CBaseObject {
13
+
14
+ /**
15
+ * @var array the attached event handlers (event name => handlers)
16
+ */
17
+ // private _events = [];
18
+
19
+
20
+ /**
21
+ * @var Behavior[]|null the attached behaviors (behavior name => behavior). This is `null` when not initialized.
22
+ */
23
+
24
+ private _behaviors: Array<ActionFilter> = [];
25
+
26
+
27
+ /**
28
+ * Returns a list of behaviors that this component should behave as.
29
+ */
30
+ public behaviors(): any {
31
+ return [];
32
+ }
33
+
34
+
35
+ get getBehaviors(): any {
36
+ return this._behaviors;
37
+ }
38
+
39
+ /**
40
+ * Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.
41
+ */
42
+ public ensureBehaviors() {
43
+ if (this._behaviors.length == 0) {
44
+ this._behaviors = [];
45
+ if (this.behaviors().length > 0) {
46
+ this.behaviors().forEach((behavior: any) => {
47
+ Object.keys(behavior).forEach((name: string) => {
48
+ this.attachBehaviorInternal(name, behavior)
49
+ });
50
+ })
51
+ }
52
+
53
+ }
54
+ }
55
+
56
+
57
+ private attachBehaviorInternal(name: any, behavior: any) {
58
+ if (!this._behaviors.hasOwnProperty(name)) {
59
+ let beh = Utils.createObject(new behavior[name].class, behavior[name])
60
+ beh.init()
61
+ this._behaviors[name] = beh;
62
+ }
63
+ return behavior;
64
+ }
65
+
66
+ }
@@ -1,8 +1,10 @@
1
- "use strict";
2
1
  /*
3
2
  * Copyright (c) 2021. Chy Bilgisayar Bilisim
4
3
  * Author: Cihan Ozturk
5
4
  * E-mail: cihan@chy.com.tr
6
5
  * Github:https://github.com/cihan53/
7
6
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
7
+
8
+ export interface Configurable{
9
+
10
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+
9
+
10
+ import {BaseError} from "./BaseError";
11
+
12
+ export class DataErrorDbException extends BaseError {
13
+ constructor ( public message: any) {
14
+ super(message,502);
15
+ }
16
+ }
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+ // @ts-ignore
8
+ const {Sequelize} = require("sequelize");
9
+ import {Component} from "./Component";
10
+ import BaseChyz from "../BaseChyz";
11
+
12
+ // const sequelizeCache = require('sequelize-transparent-cache')
13
+
14
+ export class DbConnection extends Component {
15
+
16
+ public database!: string;
17
+ public username!: string;
18
+ public password!: string;
19
+ public options?: object;
20
+
21
+
22
+ private _db: any
23
+
24
+ async init() {
25
+ const sequelize = new Sequelize(this.database, this.username, this.password, this.options);
26
+ this._db = sequelize;
27
+ sequelize
28
+ .authenticate()
29
+ .then(() => {
30
+ BaseChyz.info('Connection has been established successfully.');
31
+ })
32
+ .catch((err: any) => {
33
+ BaseChyz.error('Unable to connect to the database:', err);
34
+
35
+ });
36
+
37
+
38
+ // await this.connect();
39
+ }
40
+
41
+
42
+
43
+ get db(): any {
44
+ return this._db;
45
+ }
46
+
47
+ set db(value: any) {
48
+ this._db = value;
49
+ }
50
+
51
+ public transaction() {
52
+ return this.db.transaction();
53
+ }
54
+
55
+ }
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import {BaseError} from "./BaseError";
9
+ export class ForbiddenHttpException extends BaseError {
10
+ constructor ( message: any) {
11
+ super(message,403);
12
+ }
13
+ }
14
+
15
+
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+
9
+
10
+ import {BaseError} from "./BaseError";
11
+
12
+ export class InvalidArgumentException extends BaseError {
13
+ constructor ( public message: any) {
14
+ super(message,500);
15
+ }
16
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+
9
+
10
+ import {BaseError} from "./BaseError";
11
+
12
+ export class InvalidConfigException extends BaseError {
13
+ constructor ( public message: any) {
14
+ super(message,500);
15
+ }
16
+ }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /*
3
2
  *
4
3
  * Copyright (c) 2022.. Chy Bilgisayar Bilisim
@@ -7,19 +6,26 @@
7
6
  * Github:https://github.com/cihan53/
8
7
  *
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Logs = void 0;
9
+
10
+ import {Configurable} from "./Configurable";
11
+ import {Utils} from "../requiments/Utils";
12
+
12
13
  const log4js = require("log4js");
13
- class Logs {
14
- constructor(name, configs) {
15
- var _a;
16
- this.name = this.constructor.name;
17
- this.configs = (_a = require('../log/config/log4js.json')) !== null && _a !== void 0 ? _a : {};
14
+
15
+ export class Logs implements Configurable {
16
+
17
+ public name = this.constructor.name;
18
+ public configs: any = require('../log/config/log4js.json') ?? {}
19
+
20
+
21
+ constructor(name?: string, configs?: any) {
18
22
  if (name)
19
23
  this.name = name;
24
+
20
25
  if (configs) {
21
26
  this.configs = configs;
22
27
  }
28
+
23
29
  // let _conf = Utils.clone(this.configs);
24
30
  // Object.keys(_conf.appenders).forEach(function (appender: string) {
25
31
  // let _base;
@@ -40,37 +46,48 @@ class Logs {
40
46
  // });
41
47
  this.Provider().configure(this.configs);
42
48
  }
49
+
43
50
  init() {
44
51
  this.Provider().configure(this.configs);
45
52
  }
53
+
46
54
  /**
47
55
  *
48
56
  * @constructor
49
57
  */
50
- Provider() {
58
+ public Provider() {
51
59
  return log4js;
52
60
  }
53
- logs(...args) {
61
+
62
+ public logs(...args: any[]) {
54
63
  return log4js.getLogger(this.name);
55
64
  }
56
- debug(...args) {
57
- this.logs().debug(...args);
65
+
66
+ public debug(...args: any[]) {
67
+ this.logs().debug(...args)
58
68
  }
59
- info(...args) {
60
- this.logs().info(...args);
69
+
70
+ public info(...args: any[]) {
71
+ this.logs().info(...args)
61
72
  }
62
- warn(...args) {
63
- this.logs().warn(...arguments);
73
+
74
+ public warn(...args: any[]) {
75
+ this.logs().warn(...arguments)
64
76
  }
65
- error(...args) {
66
- this.logs().error(...args);
77
+
78
+ public error(...args: any[]) {
79
+ this.logs().error(...args)
67
80
  }
68
- fatal(...args) {
69
- this.logs().fatal(...args);
81
+
82
+ public fatal(...args: any[]) {
83
+ this.logs().fatal(...args)
70
84
  }
71
- warning(...args) {
72
- this.logs().warn(...args);
85
+
86
+
87
+ public warning(...args: any[]) {
88
+ this.logs().warn(...args)
73
89
  }
90
+
74
91
  }
75
- exports.Logs = Logs;
76
- exports.default = new Logs();
92
+
93
+ export default new Logs();