chyz 1.0.12-rc.14

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 (163) hide show
  1. package/BaseChyz.ts +316 -0
  2. package/Chyz.ts +11 -0
  3. package/Examples/Controllers/ApiController.ts +121 -0
  4. package/Examples/Controllers/PublicController.ts +44 -0
  5. package/Examples/Controllers/SiteController.ts +127 -0
  6. package/Examples/Models/Customer.ts +113 -0
  7. package/Examples/Models/Order.ts +48 -0
  8. package/Examples/Models/OrderItem.ts +26 -0
  9. package/Examples/Models/User.ts +80 -0
  10. package/Examples/index.ts +38 -0
  11. package/Examples/log/access.log +0 -0
  12. package/Examples/log/app.log +3264 -0
  13. package/Examples/log/errors.log +534 -0
  14. package/Examples/package.json +45 -0
  15. package/Examples/tsconfig.json +20 -0
  16. package/Examples/yarn.lock +2202 -0
  17. package/README.md +218 -0
  18. package/base/ActionFilter.ts +71 -0
  19. package/base/BaseError.ts +26 -0
  20. package/base/BaseObject.ts +19 -0
  21. package/base/Behavior.ts +6 -0
  22. package/base/Component.ts +66 -0
  23. package/base/Configurable.ts +10 -0
  24. package/base/Controller.ts +84 -0
  25. package/base/DataErrorDbException.ts +16 -0
  26. package/base/DbConnection.ts +51 -0
  27. package/base/ForbiddenHttpException.ts +15 -0
  28. package/base/InvalidConfigException.ts +16 -0
  29. package/base/Model.ts +254 -0
  30. package/base/NotFoundHttpException.ts +14 -0
  31. package/base/RestClient.ts +27 -0
  32. package/base/UnauthorizedHttpException.ts +16 -0
  33. package/base/ValidationHttpException.ts +14 -0
  34. package/base/db/Exception.ts +14 -0
  35. package/base/index.ts +16 -0
  36. package/decorator/Middleware.ts +9 -0
  37. package/decorator/controller.ts +22 -0
  38. package/decorator/enums/ControllerDecoratorParams.ts +5 -0
  39. package/decorator/get.ts +37 -0
  40. package/decorator/index.ts +3 -0
  41. package/decorator/post.ts +36 -0
  42. package/dist/BaseChyz.js +257 -0
  43. package/dist/BaseChyz.js.map +1 -0
  44. package/dist/Chyz.js +15 -0
  45. package/dist/Chyz.js.map +1 -0
  46. package/dist/base/ActionFilter.js +75 -0
  47. package/dist/base/ActionFilter.js.map +1 -0
  48. package/dist/base/BaseError.js +26 -0
  49. package/dist/base/BaseError.js.map +1 -0
  50. package/dist/base/BaseObject.js +20 -0
  51. package/dist/base/BaseObject.js.map +1 -0
  52. package/dist/base/Behavior.js +8 -0
  53. package/dist/base/Behavior.js.map +1 -0
  54. package/dist/base/Component.js +61 -0
  55. package/dist/base/Component.js.map +1 -0
  56. package/dist/base/Configurable.js +9 -0
  57. package/dist/base/Configurable.js.map +1 -0
  58. package/dist/base/Controller.js +75 -0
  59. package/dist/base/Controller.js.map +1 -0
  60. package/dist/base/DataErrorDbException.js +18 -0
  61. package/dist/base/DataErrorDbException.js.map +1 -0
  62. package/dist/base/DbConnection.js +53 -0
  63. package/dist/base/DbConnection.js.map +1 -0
  64. package/dist/base/ForbiddenHttpException.js +17 -0
  65. package/dist/base/ForbiddenHttpException.js.map +1 -0
  66. package/dist/base/InvalidConfigException.js +18 -0
  67. package/dist/base/InvalidConfigException.js.map +1 -0
  68. package/dist/base/Model.js +243 -0
  69. package/dist/base/Model.js.map +1 -0
  70. package/dist/base/NotFoundHttpException.js +18 -0
  71. package/dist/base/NotFoundHttpException.js.map +1 -0
  72. package/dist/base/RestClient.js +26 -0
  73. package/dist/base/RestClient.js.map +1 -0
  74. package/dist/base/UnauthorizedHttpException.js +18 -0
  75. package/dist/base/UnauthorizedHttpException.js.map +1 -0
  76. package/dist/base/ValidationHttpException.js +18 -0
  77. package/dist/base/ValidationHttpException.js.map +1 -0
  78. package/dist/base/db/Exception.js +16 -0
  79. package/dist/base/db/Exception.js.map +1 -0
  80. package/dist/base/index.js +29 -0
  81. package/dist/base/index.js.map +1 -0
  82. package/dist/decorator/Middleware.js +12 -0
  83. package/dist/decorator/Middleware.js.map +1 -0
  84. package/dist/decorator/controller.js +25 -0
  85. package/dist/decorator/controller.js.map +1 -0
  86. package/dist/decorator/enums/ControllerDecoratorParams.js +10 -0
  87. package/dist/decorator/enums/ControllerDecoratorParams.js.map +1 -0
  88. package/dist/decorator/get.js +37 -0
  89. package/dist/decorator/get.js.map +1 -0
  90. package/dist/decorator/index.js +16 -0
  91. package/dist/decorator/index.js.map +1 -0
  92. package/dist/decorator/post.js +37 -0
  93. package/dist/decorator/post.js.map +1 -0
  94. package/dist/filters/AccessControl.js +76 -0
  95. package/dist/filters/AccessControl.js.map +1 -0
  96. package/dist/filters/AccessRule.js +79 -0
  97. package/dist/filters/AccessRule.js.map +1 -0
  98. package/dist/filters/auth/AuthInterface.js +3 -0
  99. package/dist/filters/auth/AuthInterface.js.map +1 -0
  100. package/dist/filters/auth/AuthMethod.js +71 -0
  101. package/dist/filters/auth/AuthMethod.js.map +1 -0
  102. package/dist/filters/auth/HttpBasicAuth.js +8 -0
  103. package/dist/filters/auth/HttpBasicAuth.js.map +1 -0
  104. package/dist/filters/auth/HttpBearerAuth.js +33 -0
  105. package/dist/filters/auth/HttpBearerAuth.js.map +1 -0
  106. package/dist/filters/auth/HttpHeaderAuth.js +61 -0
  107. package/dist/filters/auth/HttpHeaderAuth.js.map +1 -0
  108. package/dist/filters/auth/JwtHttpBearerAuth.js +82 -0
  109. package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -0
  110. package/dist/filters/auth/index.js +16 -0
  111. package/dist/filters/auth/index.js.map +1 -0
  112. package/dist/filters/index.js +15 -0
  113. package/dist/filters/index.js.map +1 -0
  114. package/dist/index.js +28 -0
  115. package/dist/index.js.map +1 -0
  116. package/dist/log/config/log4js.json +55 -0
  117. package/dist/model/RouteDefinition.js +9 -0
  118. package/dist/model/RouteDefinition.js.map +1 -0
  119. package/dist/requiments/Glob.js +11 -0
  120. package/dist/requiments/Glob.js.map +1 -0
  121. package/dist/requiments/ReflectUtil.js +25 -0
  122. package/dist/requiments/ReflectUtil.js.map +1 -0
  123. package/dist/requiments/Utils.js +40 -0
  124. package/dist/requiments/Utils.js.map +1 -0
  125. package/dist/validators/BooleanValidator.js +2 -0
  126. package/dist/validators/BooleanValidator.js.map +1 -0
  127. package/dist/validators/CompareValidator.js +2 -0
  128. package/dist/validators/CompareValidator.js.map +1 -0
  129. package/dist/validators/DateValidator.js +2 -0
  130. package/dist/validators/DateValidator.js.map +1 -0
  131. package/dist/validators/EmailValidator.js +2 -0
  132. package/dist/validators/EmailValidator.js.map +1 -0
  133. package/dist/validators/Validator.js +28 -0
  134. package/dist/validators/Validator.js.map +1 -0
  135. package/dist/web/IdentityInterface.js +9 -0
  136. package/dist/web/IdentityInterface.js.map +1 -0
  137. package/dist/web/User.js +83 -0
  138. package/dist/web/User.js.map +1 -0
  139. package/filters/AccessControl.ts +64 -0
  140. package/filters/AccessRule.ts +137 -0
  141. package/filters/auth/AuthInterface.ts +34 -0
  142. package/filters/auth/AuthMethod.ts +88 -0
  143. package/filters/auth/HttpBasicAuth.ts +7 -0
  144. package/filters/auth/HttpBearerAuth.ts +31 -0
  145. package/filters/auth/HttpHeaderAuth.ts +53 -0
  146. package/filters/auth/JwtHttpBearerAuth.ts +81 -0
  147. package/filters/auth/index.ts +3 -0
  148. package/filters/index.ts +2 -0
  149. package/index.ts +14 -0
  150. package/log/config/log4js.json +55 -0
  151. package/model/RouteDefinition.ts +18 -0
  152. package/package.json +52 -0
  153. package/requiments/Glob.ts +9 -0
  154. package/requiments/ReflectUtil.ts +26 -0
  155. package/requiments/Utils.ts +57 -0
  156. package/tsconfig.json +18 -0
  157. package/validators/BooleanValidator.ts +0 -0
  158. package/validators/CompareValidator.ts +0 -0
  159. package/validators/DateValidator.ts +0 -0
  160. package/validators/EmailValidator.ts +0 -0
  161. package/validators/Validator.ts +27 -0
  162. package/web/IdentityInterface.ts +62 -0
  163. package/web/User.ts +96 -0
package/README.md ADDED
@@ -0,0 +1,218 @@
1
+ Hızlı şekilde microservis hazırlama için geliştirmeye başladım<br>
2
+
3
+ Temel olarak yii2 php framework'ten örnekler alındı<br>
4
+
5
+ Temel olarak basit bir Controller geliştirildi, ayrıca authentication geliştirildi.<br>
6
+
7
+ Klasör Yapısı<br>
8
+ *---Controllers <br>
9
+ *---Models<br>
10
+ *---Log<br>
11
+ *---Framework<br>
12
+ index.ts<br>
13
+
14
+ `##Başlangıç<br>
15
+ yarn start
16
+
17
+ ## index.ts alanlar düzenlenmeli.
18
+
19
+ ```js
20
+ let config = {
21
+ components: {
22
+ db: {
23
+ class: DbConnection,
24
+ database: process.env.DBDATABASE,
25
+ username: process.env.DBUSER,
26
+ password: process.env.DBPASS,
27
+ options: {
28
+ host: process.env.DBHOST,
29
+ dialect: 'postgres', /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
30
+ // disable logging; default: console.log
31
+ logging: false
32
+ }
33
+ },
34
+ user: {
35
+ 'class': User,
36
+ 'identityClass': Identity
37
+ }
38
+ }
39
+ }
40
+ Chyz.app(config).Start();
41
+ ```
42
+
43
+ ## Create Model
44
+
45
+ Veritabanı işlemleri için model oluşturma, sequelize desteklidir.
46
+
47
+ ```js
48
+ import {Model, DataTypes} from "chyz/base/Model";
49
+
50
+ export class Customer extends Model {
51
+ public tableName() {
52
+ return 'customer';
53
+ }
54
+
55
+ public attributes() {
56
+ return {
57
+ username: {
58
+ type: DataTypes.STRING,
59
+ allowNull: false,
60
+ validate: {
61
+ notEmpty: true,
62
+ len: [4, 255],
63
+ }
64
+ },
65
+ email: {
66
+ type: DataTypes.STRING,
67
+ validate: {
68
+ isEmail: true
69
+ }
70
+ },
71
+ firstname: {
72
+ type: DataTypes.STRING,
73
+ allowNull: false
74
+ },
75
+ lastname: {
76
+ type: DataTypes.STRING,
77
+ },
78
+ }
79
+ }
80
+
81
+ }
82
+ ```
83
+ ## Http POST ve GET verilerini model'e yükleme
84
+ ````js
85
+
86
+ /**
87
+ * post data
88
+ * {
89
+ * "Customer":{
90
+ * "firstname":"cihan",
91
+ * "lastname":"ozturk"
92
+ * ....
93
+ * }
94
+ * }
95
+ * @type {Customer}
96
+ */
97
+
98
+ //Customer Model Create
99
+ let customer: Customer = new Customer();
100
+ customer.load(req.body, "Customer");//load customer data
101
+ let cus: any = await customer.save();
102
+
103
+
104
+
105
+
106
+ ````
107
+ ## Transaction
108
+ Transaction oluşturma
109
+
110
+
111
+ ```js
112
+ let transaction
113
+ try {
114
+ // get transaction
115
+ transaction = await BaseChyz.getComponent("db").transaction();
116
+ //Customer Model Create
117
+ let customer: Customer = new Customer();
118
+ customer.load(data, "Customer");//load customer data
119
+ let cus: any = await customer.save({}, {transaction});
120
+ if (!cus) {
121
+ throw new ValidationHttpException(customer.errors);
122
+ }
123
+ } catch (e) {
124
+ if (transaction) {
125
+ await transaction.rollback();
126
+ BaseChyz.warn("Rollback transaction")
127
+ }
128
+ ...
129
+ }
130
+ ```
131
+
132
+ ## Yetkilendirme için kullanıcı modeli
133
+
134
+ ```js
135
+ /*
136
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
137
+ * Author: Cihan Ozturk
138
+ * E-mail: cihan@chy.com.tr
139
+ * Github:https://github.com/cihan53/
140
+ */
141
+ import {IdentityInterface} from "chyz/web/IdentityInterface";
142
+ // @ts-ignore
143
+ import {DataTypes} from "chyz/base";
144
+ import {Model} from "chyz/base";
145
+ import BaseChyz from "chyz/BaseChyz";
146
+
147
+ const bcrypt = require('bcrypt');
148
+ const JsonWebToken = require("jsonwebtoken");
149
+
150
+ export class User extends Model implements IdentityInterface {
151
+ public tableName() {
152
+ return 'users';
153
+ }
154
+ findIdentity(id: number) {
155
+ throw new Error("Method not implemented.");
156
+ }
157
+
158
+ getId(): number {
159
+ throw new Error("Method not implemented.");
160
+ }
161
+
162
+ getAuthKey(): string {
163
+ throw new Error("Method not implemented.");
164
+ }
165
+
166
+ validateAuthKey(authKey: string): boolean {
167
+ throw new Error("Method not implemented.");
168
+ }
169
+
170
+ public attributes() {
171
+ return {
172
+ // Model attributes are defined here
173
+ username: {
174
+ type: DataTypes.STRING,
175
+ allowNull: false
176
+ },
177
+ password: {
178
+ type: DataTypes.STRING,
179
+ allowNull: false
180
+ },
181
+ user_role: {
182
+ type: DataTypes.STRING,
183
+ allowNull: false
184
+ },
185
+ salt_text: {
186
+ type: DataTypes.STRING
187
+ // allowNull defaults to true
188
+ }
189
+ }
190
+ }
191
+
192
+ async findIdentityByAccessToken(token, type) {
193
+ let decoded = JsonWebToken.decode(token, {complete: true})
194
+ let identity = await this.findOne({where: {id: parseInt(decoded.payload.user)}});
195
+ if(identity){
196
+ BaseChyz.debug("Find Identity By AccessToken: User Found", decoded.payload)
197
+ try {
198
+ JsonWebToken.verify(token, identity.salt_text);
199
+ BaseChyz.debug("Find Identity By AccessToken: User Verify Success")
200
+ return identity;
201
+ } catch(err) {
202
+ BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
203
+ return null;
204
+ }
205
+ }
206
+ BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
207
+ return null;
208
+ }
209
+
210
+
211
+ }
212
+
213
+
214
+
215
+
216
+
217
+
218
+ ```
@@ -0,0 +1,71 @@
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
+ import {NextFunction, Request, Response} from "express";
9
+ import Utils from "../requiments/Utils";
10
+ import {Behavior} from "./Behavior";
11
+
12
+ export class ActionFilter extends Behavior {
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
+ public async beforeFilter(route: any, req: Request, res: Response) {
28
+ if (!this.isActive(route.id)) {
29
+ return;
30
+ }
31
+
32
+ await this.beforeAction(route, req, res)
33
+ }
34
+
35
+ protected isActive(action: any) {
36
+ let id = action.id;
37
+ let onlyMatch: boolean = false;
38
+ let exceptMatch: boolean = false;
39
+ if (Utils.isEmpty(this.only)) {
40
+ onlyMatch = true;
41
+ } else {
42
+ onlyMatch = false;
43
+ for (const onlyKey of this.only) {
44
+ if (Utils.matchWildcard(action, onlyKey)) {
45
+ onlyMatch = true;
46
+ break;
47
+ }
48
+ }
49
+ }
50
+
51
+ for (const exceptKey in this.except) {
52
+ let pattern = this.except[exceptKey];
53
+ let match = id.match(pattern)
54
+ if (match.length > 0) {
55
+ exceptMatch = true;
56
+ }
57
+ }
58
+
59
+ return !exceptMatch && onlyMatch;
60
+ }
61
+
62
+ /**
63
+ * This method is invoked right before an action is to be executed (after all possible filters.)
64
+ * You may override this method to do last-minute preparation for the action.
65
+ * @param Action $action the action to be executed.
66
+ * @return bool whether the action should continue to be executed.
67
+ */
68
+ public async beforeAction(route: any, req: Request, res: Response) {
69
+ return true;
70
+ }
71
+ }
@@ -0,0 +1,26 @@
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
+ export class BaseError extends Error {
9
+ private statusCode: number;
10
+
11
+ constructor(message: string) {
12
+ super(message);
13
+ this.message=message;
14
+ this.name = this.constructor.name // good practice
15
+ this.statusCode = 500 // error code for responding to client
16
+ Error.captureStackTrace(this)
17
+ }
18
+
19
+ toString(){
20
+ return `${this.name}[${this.statusCode}] ${this.message}`
21
+ }
22
+ toJSON(){
23
+ return {code: this?.statusCode, name: this.name, message: this.message}
24
+ }
25
+ }
26
+
@@ -0,0 +1,19 @@
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 {Configurable} from "./Configurable";
9
+ import BaseChyz from "../BaseChyz";
10
+
11
+ export class BaseObject implements Configurable {
12
+
13
+
14
+ public init() {
15
+
16
+ BaseChyz.debug("BaseObject init.....",)
17
+
18
+ }
19
+ }
@@ -0,0 +1,6 @@
1
+ import {BaseObject} from "./BaseObject";
2
+
3
+ export class Behavior extends BaseObject
4
+ {
5
+
6
+ }
@@ -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 {BaseObject} from "./BaseObject";
9
+ import {ActionFilter} from "./ActionFilter";
10
+ import Utils from "../requiments/Utils";
11
+
12
+ export class Component extends BaseObject {
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() {
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 => {
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
+ }
@@ -0,0 +1,10 @@
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
+ export interface Configurable{
9
+
10
+ }
@@ -0,0 +1,84 @@
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
+
12
+ export class Controller extends Component {
13
+
14
+
15
+ /**
16
+ * @var string the ID of this controller.
17
+ */
18
+ public id: string;
19
+ public defaultAction = 'index';
20
+
21
+ constructor(config: any) {
22
+ super();
23
+ this.id = this.constructor.name.replace("Controller", "").toLowerCase();
24
+ }
25
+
26
+ public init() {
27
+ super.init();
28
+ }
29
+
30
+
31
+ /**
32
+ * This method is invoked right before an action is executed.
33
+ * @param $action
34
+ */
35
+ public async beforeAction(route: RouteDefinition, req: Request, res: Response) {
36
+ if (route.id == "" || route.id == "/")
37
+ this.id = this.defaultAction
38
+
39
+ this.ensureBehaviors()
40
+ for (const name of Object.keys(this.getBehaviors)) {
41
+ await this.getBehaviors[name].beforeFilter(route, req, res);
42
+ }
43
+
44
+ }
45
+
46
+ /**
47
+ * This method is invoked right after an action is executed.
48
+ * @param action
49
+ */
50
+ public afterAction(action: any, req: Request, res: Response) {
51
+
52
+ }
53
+
54
+ /**
55
+ *
56
+
57
+ Checks the privilege of the current user.
58
+
59
+ 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.
60
+
61
+ */
62
+ public checkAccess(action: any, model = null, params: any = []) {
63
+
64
+ }
65
+
66
+ /**
67
+ * Send data formatted as JSON.
68
+
69
+ 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
70
+ */
71
+ asJson(data: any) {
72
+
73
+ }
74
+
75
+ /**
76
+ * Send data formatted as XML.
77
+
78
+ 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:
79
+ */
80
+ asXml(data: any) {
81
+
82
+ }
83
+
84
+ }
@@ -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: string) {
14
+ super(message);
15
+ }
16
+ }
@@ -0,0 +1,51 @@
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
+ export class DbConnection extends Component {
13
+
14
+ public database!: string;
15
+ public username!: string
16
+ public password!: string
17
+ public options?: object
18
+ public _transaction:any;
19
+
20
+ private _db: any
21
+
22
+ async init() {
23
+ const sequelize = new Sequelize(this.database, this.username, this.password, this.options);
24
+ this._db = sequelize;
25
+ sequelize
26
+ .authenticate()
27
+ .then(() => {
28
+ BaseChyz.info('Connection has been established successfully.');
29
+ })
30
+ .catch((err: any) => {
31
+ BaseChyz.error('Unable to connect to the database:', err);
32
+
33
+ });
34
+
35
+ // await this.connect();
36
+ }
37
+
38
+
39
+ get db(): any {
40
+ return this._db;
41
+ }
42
+
43
+ set db(value: any) {
44
+ this._db = value;
45
+ }
46
+
47
+ public transaction(){
48
+ return this.db.transaction();
49
+ }
50
+
51
+ }
@@ -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: string) {
11
+ super(message);
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 InvalidConfigException extends BaseError {
13
+ constructor ( public message: string) {
14
+ super(message);
15
+ }
16
+ }