chyz 2.0.1-rc.36 → 2.0.1-rc.37

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 (231) hide show
  1. package/dist/BaseChyz.d.ts +74 -0
  2. package/dist/BaseChyz.d.ts.map +1 -0
  3. package/dist/BaseChyz.js +586 -0
  4. package/dist/base/ActionFilter.d.ts +32 -0
  5. package/dist/base/ActionFilter.d.ts.map +1 -0
  6. package/dist/base/ActionFilter.js +90 -0
  7. package/dist/base/BadRequestHttpException.d.ts +6 -0
  8. package/dist/base/BadRequestHttpException.d.ts.map +1 -0
  9. package/dist/base/BadRequestHttpException.js +17 -0
  10. package/dist/base/BaseError.d.ts +44 -0
  11. package/dist/base/BaseError.d.ts.map +1 -0
  12. package/{base/BaseError.ts → dist/base/BaseError.js} +18 -26
  13. package/dist/base/Behavior.d.ts +4 -0
  14. package/dist/base/Behavior.d.ts.map +1 -0
  15. package/dist/base/Behavior.js +7 -0
  16. package/dist/base/CBaseObject.d.ts +5 -0
  17. package/dist/base/CBaseObject.d.ts.map +1 -0
  18. package/dist/base/CBaseObject.js +16 -0
  19. package/dist/base/CEvents.d.ts +13 -0
  20. package/dist/base/CEvents.d.ts.map +1 -0
  21. package/dist/base/CEvents.js +24 -0
  22. package/dist/base/CRequest.d.ts +2 -0
  23. package/dist/base/CRequest.d.ts.map +1 -0
  24. package/{base/CRequest.ts → dist/base/CRequest.js} +2 -6
  25. package/dist/base/CWebController.d.ts +44 -0
  26. package/dist/base/CWebController.d.ts.map +1 -0
  27. package/dist/base/CWebController.js +81 -0
  28. package/dist/base/Component.d.ts +21 -0
  29. package/dist/base/Component.d.ts.map +1 -0
  30. package/dist/base/Component.js +57 -0
  31. package/dist/base/Configurable.d.ts +3 -0
  32. package/dist/base/Configurable.d.ts.map +1 -0
  33. package/{requiments/Glob.ts → dist/base/Configurable.js} +2 -3
  34. package/dist/base/DataErrorDbException.d.ts +6 -0
  35. package/dist/base/DataErrorDbException.d.ts.map +1 -0
  36. package/dist/base/DataErrorDbException.js +17 -0
  37. package/dist/base/DbConnection.d.ts +13 -0
  38. package/dist/base/DbConnection.d.ts.map +1 -0
  39. package/dist/base/DbConnection.js +53 -0
  40. package/dist/base/ForbiddenHttpException.d.ts +5 -0
  41. package/dist/base/ForbiddenHttpException.d.ts.map +1 -0
  42. package/dist/base/ForbiddenHttpException.js +16 -0
  43. package/dist/base/InvalidArgumentException.d.ts +6 -0
  44. package/dist/base/InvalidArgumentException.d.ts.map +1 -0
  45. package/dist/base/InvalidArgumentException.js +17 -0
  46. package/dist/base/InvalidConfigException.d.ts +6 -0
  47. package/dist/base/InvalidConfigException.d.ts.map +1 -0
  48. package/dist/base/InvalidConfigException.js +17 -0
  49. package/dist/base/Logs.d.ts +22 -0
  50. package/dist/base/Logs.d.ts.map +1 -0
  51. package/{base/Logs.ts → dist/base/Logs.js} +24 -41
  52. package/dist/base/Model.d.ts +302 -0
  53. package/dist/base/Model.d.ts.map +1 -0
  54. package/{base/Model.ts → dist/base/Model.js} +158 -225
  55. package/dist/base/ModelManager.d.ts +2 -0
  56. package/dist/base/ModelManager.d.ts.map +1 -0
  57. package/{base/ModelManager.ts → dist/base/ModelManager.js} +7 -7
  58. package/dist/base/NotFoundHttpException.d.ts +6 -0
  59. package/dist/base/NotFoundHttpException.d.ts.map +1 -0
  60. package/dist/base/NotFoundHttpException.js +17 -0
  61. package/dist/base/RestClient.d.ts +7 -0
  62. package/dist/base/RestClient.d.ts.map +1 -0
  63. package/dist/base/RestClient.js +25 -0
  64. package/dist/base/UnauthorizedHttpException.d.ts +6 -0
  65. package/dist/base/UnauthorizedHttpException.d.ts.map +1 -0
  66. package/dist/base/UnauthorizedHttpException.js +17 -0
  67. package/dist/base/ValidationHttpException.d.ts +6 -0
  68. package/dist/base/ValidationHttpException.d.ts.map +1 -0
  69. package/dist/base/ValidationHttpException.js +17 -0
  70. package/dist/base/db/Exception.d.ts +7 -0
  71. package/dist/base/db/Exception.d.ts.map +1 -0
  72. package/dist/base/db/Exception.js +15 -0
  73. package/dist/base/index.d.ts +20 -0
  74. package/dist/base/index.d.ts.map +1 -0
  75. package/dist/base/index.js +41 -0
  76. package/dist/decorator/Middleware.d.ts +4 -0
  77. package/dist/decorator/Middleware.d.ts.map +1 -0
  78. package/dist/decorator/Middleware.js +10 -0
  79. package/dist/decorator/controller.d.ts +3 -0
  80. package/dist/decorator/controller.d.ts.map +1 -0
  81. package/{decorator/controller.ts → dist/decorator/controller.js} +9 -7
  82. package/dist/decorator/delete.d.ts +3 -0
  83. package/dist/decorator/delete.d.ts.map +1 -0
  84. package/{decorator/delete.ts → dist/decorator/delete.js} +9 -9
  85. package/dist/decorator/enums/ControllerDecoratorParams.d.ts +6 -0
  86. package/dist/decorator/enums/ControllerDecoratorParams.d.ts.map +1 -0
  87. package/dist/decorator/enums/ControllerDecoratorParams.js +9 -0
  88. package/dist/decorator/get.d.ts +3 -0
  89. package/dist/decorator/get.d.ts.map +1 -0
  90. package/{decorator/get.ts → dist/decorator/get.js} +10 -11
  91. package/dist/decorator/index.d.ts +6 -0
  92. package/dist/decorator/index.d.ts.map +1 -0
  93. package/dist/decorator/index.js +13 -0
  94. package/dist/decorator/post.d.ts +3 -0
  95. package/dist/decorator/post.d.ts.map +1 -0
  96. package/{decorator/post.ts → dist/decorator/post.js} +10 -10
  97. package/dist/decorator/put.d.ts +3 -0
  98. package/dist/decorator/put.d.ts.map +1 -0
  99. package/{decorator/put.ts → dist/decorator/put.js} +9 -9
  100. package/dist/filters/AccessControl.d.ts +12 -0
  101. package/dist/filters/AccessControl.d.ts.map +1 -0
  102. package/dist/filters/AccessControl.js +83 -0
  103. package/dist/filters/AccessRule.d.ts +83 -0
  104. package/dist/filters/AccessRule.d.ts.map +1 -0
  105. package/dist/filters/AccessRule.js +136 -0
  106. package/{filters/auth/AuthInterface.ts → dist/filters/auth/AuthInterface.d.ts} +7 -15
  107. package/dist/filters/auth/AuthInterface.d.ts.map +1 -0
  108. package/dist/filters/auth/AuthInterface.js +2 -0
  109. package/dist/filters/auth/AuthMethod.d.ts +38 -0
  110. package/dist/filters/auth/AuthMethod.d.ts.map +1 -0
  111. package/dist/filters/auth/AuthMethod.js +82 -0
  112. package/dist/filters/auth/HttpBasicAuth.d.ts +24 -0
  113. package/dist/filters/auth/HttpBasicAuth.d.ts.map +1 -0
  114. package/dist/filters/auth/HttpBasicAuth.js +79 -0
  115. package/dist/filters/auth/HttpBearerAuth.d.ts +18 -0
  116. package/dist/filters/auth/HttpBearerAuth.d.ts.map +1 -0
  117. package/dist/filters/auth/HttpBearerAuth.js +33 -0
  118. package/dist/filters/auth/HttpHeaderAuth.d.ts +19 -0
  119. package/dist/filters/auth/HttpHeaderAuth.d.ts.map +1 -0
  120. package/dist/filters/auth/HttpHeaderAuth.js +64 -0
  121. package/dist/filters/auth/JwtHttpBearerAuth.d.ts +21 -0
  122. package/dist/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -0
  123. package/dist/filters/auth/JwtHttpBearerAuth.js +88 -0
  124. package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts +23 -0
  125. package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts.map +1 -0
  126. package/dist/filters/auth/KeyCloakHttpBearerAuth.js +116 -0
  127. package/dist/filters/auth/index.d.ts +5 -0
  128. package/dist/filters/auth/index.d.ts.map +1 -0
  129. package/dist/filters/auth/index.js +11 -0
  130. package/dist/filters/index.d.ts +3 -0
  131. package/dist/filters/index.d.ts.map +1 -0
  132. package/dist/filters/index.js +7 -0
  133. package/dist/index.d.ts +26 -0
  134. package/dist/index.d.ts.map +1 -0
  135. package/dist/index.js +73 -0
  136. package/dist/log/log/config/log4js.json +55 -0
  137. package/dist/model/RouteDefinition.d.ts +7 -0
  138. package/dist/model/RouteDefinition.d.ts.map +1 -0
  139. package/{base/Configurable.ts → dist/model/RouteDefinition.js} +2 -4
  140. package/dist/package.json +63 -0
  141. package/dist/rbac/AuthAssignment.d.ts +19 -0
  142. package/dist/rbac/AuthAssignment.d.ts.map +1 -0
  143. package/dist/rbac/AuthAssignment.js +44 -0
  144. package/dist/rbac/AuthItem.d.ts +27 -0
  145. package/dist/rbac/AuthItem.d.ts.map +1 -0
  146. package/{rbac/AuthItem.ts → dist/rbac/AuthItem.js} +16 -22
  147. package/dist/rbac/AuthItemChild.d.ts +19 -0
  148. package/dist/rbac/AuthItemChild.d.ts.map +1 -0
  149. package/{rbac/AuthItemChild.ts → dist/rbac/AuthItemChild.js} +14 -21
  150. package/dist/rbac/AuthManager.d.ts +112 -0
  151. package/dist/rbac/AuthManager.d.ts.map +1 -0
  152. package/dist/rbac/AuthManager.js +356 -0
  153. package/dist/rbac/index.d.ts +5 -0
  154. package/dist/rbac/index.d.ts.map +1 -0
  155. package/dist/rbac/index.js +28 -0
  156. package/dist/requiments/Glob.d.ts +3 -0
  157. package/dist/requiments/Glob.d.ts.map +1 -0
  158. package/dist/requiments/Glob.js +10 -0
  159. package/dist/requiments/ReflectUtil.d.ts +1 -0
  160. package/dist/requiments/ReflectUtil.d.ts.map +1 -0
  161. package/{requiments/ReflectUtil.ts → dist/requiments/ReflectUtil.js} +4 -6
  162. package/dist/requiments/Utils.d.ts +2 -0
  163. package/dist/requiments/Utils.d.ts.map +1 -0
  164. package/{requiments/Utils.ts → dist/requiments/Utils.js} +34 -40
  165. package/dist/validators/BooleanValidator.d.ts +1 -0
  166. package/dist/validators/BooleanValidator.d.ts.map +1 -0
  167. package/dist/validators/BooleanValidator.js +1 -0
  168. package/dist/validators/CompareValidator.d.ts +1 -0
  169. package/dist/validators/CompareValidator.d.ts.map +1 -0
  170. package/dist/validators/CompareValidator.js +1 -0
  171. package/dist/validators/DateValidator.d.ts +1 -0
  172. package/dist/validators/DateValidator.d.ts.map +1 -0
  173. package/dist/validators/DateValidator.js +1 -0
  174. package/dist/validators/EmailValidator.d.ts +1 -0
  175. package/dist/validators/EmailValidator.d.ts.map +1 -0
  176. package/dist/validators/EmailValidator.js +1 -0
  177. package/dist/validators/Validator.d.ts +18 -0
  178. package/dist/validators/Validator.d.ts.map +1 -0
  179. package/dist/validators/Validator.js +27 -0
  180. package/{web/IdentityInterface.ts → dist/web/IdentityInterface.d.ts} +2 -15
  181. package/dist/web/IdentityInterface.d.ts.map +1 -0
  182. package/dist/web/IdentityInterface.js +8 -0
  183. package/dist/web/WebUser.d.ts +72 -0
  184. package/dist/web/WebUser.d.ts.map +1 -0
  185. package/dist/web/WebUser.js +165 -0
  186. package/package.json +16 -56
  187. package/BaseChyz.ts +0 -623
  188. package/base/ActionFilter.ts +0 -88
  189. package/base/BadRequestHttpException.ts +0 -14
  190. package/base/Behavior.ts +0 -6
  191. package/base/CBaseObject.ts +0 -17
  192. package/base/CEvents.ts +0 -24
  193. package/base/CWebController.ts +0 -90
  194. package/base/Component.ts +0 -66
  195. package/base/DataErrorDbException.ts +0 -16
  196. package/base/DbConnection.ts +0 -55
  197. package/base/ForbiddenHttpException.ts +0 -15
  198. package/base/InvalidArgumentException.ts +0 -16
  199. package/base/InvalidConfigException.ts +0 -16
  200. package/base/NotFoundHttpException.ts +0 -14
  201. package/base/RestClient.ts +0 -26
  202. package/base/UnauthorizedHttpException.ts +0 -17
  203. package/base/ValidationHttpException.ts +0 -14
  204. package/base/db/Exception.ts +0 -14
  205. package/base/index.ts +0 -19
  206. package/decorator/Middleware.ts +0 -9
  207. package/decorator/enums/ControllerDecoratorParams.ts +0 -5
  208. package/decorator/index.ts +0 -5
  209. package/filters/AccessControl.ts +0 -74
  210. package/filters/AccessRule.ts +0 -182
  211. package/filters/auth/AuthMethod.ts +0 -100
  212. package/filters/auth/HttpBasicAuth.ts +0 -79
  213. package/filters/auth/HttpBearerAuth.ts +0 -34
  214. package/filters/auth/HttpHeaderAuth.ts +0 -61
  215. package/filters/auth/JwtHttpBearerAuth.ts +0 -83
  216. package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -114
  217. package/filters/auth/index.ts +0 -4
  218. package/filters/index.ts +0 -2
  219. package/index.ts +0 -80
  220. package/model/RouteDefinition.ts +0 -18
  221. package/rbac/AuthAssignment.ts +0 -50
  222. package/rbac/AuthManager.ts +0 -399
  223. package/rbac/index.ts +0 -12
  224. package/validators/BooleanValidator.ts +0 -0
  225. package/validators/CompareValidator.ts +0 -0
  226. package/validators/DateValidator.ts +0 -0
  227. package/validators/EmailValidator.ts +0 -0
  228. package/validators/Validator.ts +0 -27
  229. package/web/WebUser.ts +0 -187
  230. /package/{README.md → dist/README.md} +0 -0
  231. /package/{log → dist/log}/config/log4js.json +0 -0
@@ -1,88 +0,0 @@
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
- }
@@ -1,14 +0,0 @@
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
- }
package/base/Behavior.ts DELETED
@@ -1,6 +0,0 @@
1
- import {CBaseObject} from "./CBaseObject";
2
-
3
- export class Behavior extends CBaseObject
4
- {
5
-
6
- }
@@ -1,17 +0,0 @@
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
- }
package/base/CEvents.ts DELETED
@@ -1,24 +0,0 @@
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,90 +0,0 @@
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
- }
package/base/Component.ts DELETED
@@ -1,66 +0,0 @@
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,16 +0,0 @@
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
- }
@@ -1,55 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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
-
@@ -1,16 +0,0 @@
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
- }
@@ -1,16 +0,0 @@
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,14 +0,0 @@
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 NotFoundHttpException extends BaseError {
11
- constructor ( public message: any) {
12
- super(message,404);
13
- }
14
- }
@@ -1,26 +0,0 @@
1
- /*
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
- */
9
-
10
- import {Component} from "./Component";
11
-
12
- const axios = require('axios')
13
-
14
- export class RestClient extends Component {
15
- public post(url: string, args?: any,headers?:any) {
16
- return axios.post(url, {...args,headers:headers})
17
- }
18
-
19
- public get(url: string, args?: any,headers?:any) {
20
- return axios.get(url, {...args,headers:headers} )
21
- }
22
-
23
- public Rest(params: any) {
24
- return axios(params)
25
- }
26
- }
@@ -1,17 +0,0 @@
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 UnauthorizedHttpException extends BaseError {
11
- constructor ( public message: any) {
12
- super(message,401);
13
- }
14
-
15
- }
16
-
17
-
@@ -1,14 +0,0 @@
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 ValidationHttpException extends BaseError {
11
- constructor ( public message: any) {
12
- super(message,400);
13
- }
14
- }
@@ -1,14 +0,0 @@
1
- import {BaseError} from "../BaseError";
2
-
3
- export class Exception extends BaseError {
4
- public errorInfo = [];
5
- protected code: string;
6
-
7
- constructor(message: string, errorInfo:any = [], code = '', previous = null) {
8
- super(message);
9
- this.errorInfo = errorInfo;
10
- this.name = 'Database Exception' // good practice
11
- this.code = code // error code for responding to client
12
- Error.captureStackTrace(this)
13
- }
14
- }
package/base/index.ts DELETED
@@ -1,19 +0,0 @@
1
- export {Logs} from "./Logs"
2
- export {BaseError} from "./BaseError"
3
- export {ActionFilter} from "./ActionFilter"
4
- export {Behavior} from "./Behavior"
5
- export {Component} from "./Component"
6
- export {Configurable} from "./Configurable"
7
- export {CWebController} from "./CWebController"
8
- export {DbConnection} from "./DbConnection"
9
- export {ForbiddenHttpException} from "./ForbiddenHttpException"
10
- export {InvalidConfigException} from "./InvalidConfigException"
11
- export {InvalidArgumentException} from "./InvalidArgumentException"
12
- export {NotFoundHttpException} from "./NotFoundHttpException"
13
- export {UnauthorizedHttpException} from "./UnauthorizedHttpException"
14
- export {DataErrorDbException} from "./DataErrorDbException"
15
- export {ValidationHttpException} from "./ValidationHttpException"
16
- export {Model, Relation, DataTypes, NOW} from "./Model"
17
- export {RestClient} from "./RestClient"
18
- export {ModelManager} from "./ModelManager"
19
- export {CEvents} from "./CEvents"
@@ -1,9 +0,0 @@
1
- import "reflect-metadata";
2
- import { ControllerDecoratorParams } from "./enums/ControllerDecoratorParams";
3
- import { RequestHandler } from "express";
4
-
5
- export function Middleware(middlewares: RequestHandler[]): Function {
6
- return function(target: any, propertyKey: string): void {
7
- Reflect.defineMetadata(ControllerDecoratorParams.Middleware, middlewares, target, propertyKey);
8
- }
9
- }
@@ -1,5 +0,0 @@
1
- export enum ControllerDecoratorParams {
2
- Path = 'path',
3
- Method = 'method',
4
- Middleware = 'middleware'
5
- }
@@ -1,5 +0,0 @@
1
- export {controller} from "./controller"
2
- export {get} from "./get"
3
- export {post} from "./post"
4
- export {put} from "./put"
5
- export {del} from "./delete"
@@ -1,74 +0,0 @@
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,BaseChyz} from "../index";
8
- import {ForbiddenHttpException} from "../base";
9
- import {ActionFilter} from "../base";
10
- import {AccessRule} from "./AccessRule";
11
- import {WebUser} from "../web/WebUser";
12
- import {Utils} from "../requiments/Utils";
13
-
14
-
15
- export class AccessControl extends ActionFilter {
16
-
17
- public user: any = null;
18
- public rules: any;
19
- public denyCallback: any = null;
20
-
21
- public init() {
22
- super.init()
23
-
24
- if (this.user == undefined) {
25
- this.user = Utils.cloneDeep(BaseChyz.getComponent("user")) ?? new WebUser();
26
- }
27
-
28
-
29
- this.rules.forEach((rule: any, index: number) => {
30
- if (rule === Object(rule)) {
31
- this.rules[index] = Utils.createObject(new AccessRule(), rule);
32
- }
33
- })
34
- }
35
-
36
-
37
- public async beforeAction(action: any, request: Request,res:Response) {
38
- let allow;
39
- // @ts-ignore
40
- let user = request.user ?? this.user;
41
- // @ts-ignore
42
- user.identity = request.identity ?? null;
43
-
44
- for (const rulesKey in this.rules) {
45
- let rule = this.rules[rulesKey];
46
- if ((allow = await rule.allows(action, user, request))) {
47
- return true;
48
- } else if (allow === false) {
49
- if (this.denyCallback != null) {
50
- rule.denyCallback.apply(rule, action);
51
- } else {
52
- this.denyAccess(user);
53
- }
54
- return false;
55
- }
56
- }
57
-
58
-
59
- if (this.denyCallback != null) {
60
- this.denyCallback.apply(null, action);
61
- } else {
62
- this.denyAccess(user);
63
- }
64
-
65
- return false;
66
- }
67
-
68
- public denyAccess(user: WebUser) {
69
- if (user != undefined && user.getIsGuest()) {
70
- user.loginRequired();
71
- } else throw new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'));
72
- }
73
-
74
- }