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
@@ -1,34 +1,48 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.Model = exports.NOW = exports.DataTypes = void 0;
22
- const BaseChyz_1 = __importDefault(require("../BaseChyz"));
23
- const Utils_1 = require("../requiments/Utils");
24
- const Component_1 = require("./Component");
25
- const InvalidConfigException_1 = require("./InvalidConfigException");
26
- const sequelize_1 = require("sequelize");
27
- const Exception_1 = require("./db/Exception");
28
- const DataErrorDbException_1 = require("./DataErrorDbException");
29
- var sequelize_2 = require("sequelize");
30
- Object.defineProperty(exports, "DataTypes", { enumerable: true, get: function () { return sequelize_2.DataTypes; } });
31
- Object.defineProperty(exports, "NOW", { enumerable: true, get: function () { return sequelize_2.NOW; } });
7
+
8
+ import BaseChyz from "../BaseChyz";
9
+ import {Utils} from "../requiments/Utils";
10
+ import {Component} from "./Component";
11
+ import {InvalidConfigException} from "./InvalidConfigException";
12
+ import {
13
+ DatabaseError,
14
+ ExclusionConstraintError,
15
+ ForeignKeyConstraintError,
16
+ Model as SModel,
17
+ QueryOptions,
18
+ QueryOptionsWithType,
19
+ QueryTypes,
20
+ Sequelize,
21
+ TimeoutError,
22
+ UniqueConstraintError,
23
+ ValidationError,
24
+ } from "sequelize";
25
+ import {Exception} from "./db/Exception";
26
+ import {DataErrorDbException} from "./DataErrorDbException";
27
+
28
+ export {DataTypes, NOW} from "sequelize";
29
+
30
+
31
+ export interface Relation {
32
+ [key: string]: any;
33
+
34
+ type: "hasOne" | "hasMany" | "belongsToMany" | "belongsTo",
35
+ allowNull?: boolean,
36
+ sourceKey?: string,
37
+ model: SModel,
38
+ foreignKey: string,
39
+ name?: string,
40
+ through?: any,
41
+ as?: string,
42
+ on?: any,
43
+ scope?: any
44
+ }
45
+
32
46
  /**
33
47
  * ValidateMe.init({
34
48
  bar: {
@@ -82,19 +96,29 @@ Object.defineProperty(exports, "NOW", { enumerable: true, get: function () { ret
82
96
  }
83
97
  }, { sequelize });
84
98
  */
85
- class Model extends Component_1.Component {
86
- constructor(sequelize) {
99
+
100
+ export class Model extends Component {
101
+ _provider: any;
102
+ _register: any;
103
+ private readonly _tableName: string;
104
+ private _model: any;
105
+ private _attributes: any = {};
106
+ private _errors: any = {}
107
+
108
+
109
+ constructor(sequelize?: IDBDatabase) {
87
110
  super();
88
- this._attributes = {};
89
- this._errors = {};
90
111
  this._tableName = this.alias();
91
- BaseChyz_1.default.debug("Model constructor", this._tableName);
112
+
113
+ BaseChyz.debug("Model constructor", this._tableName)
92
114
  // this._sequelize = BaseChyz.getComponent("db").db;
115
+
93
116
  if (sequelize != null) {
94
117
  this._provider = sequelize;
95
- }
96
- else
118
+ } else
97
119
  this._provider = this.getDb();
120
+
121
+
98
122
  /**
99
123
  * override query
100
124
  */
@@ -107,19 +131,22 @@ class Model extends Component_1.Component {
107
131
  // throw new DatabaseError(err);
108
132
  // }
109
133
  // };
110
- this._provider.query = function (sql, options) {
111
- return sequelize_1.Sequelize.prototype.query.apply(this, [sql, options]).catch((err) => {
112
- if (process.env.NODE_ENV == "development" || process.env.NODE_ENV == "dev") {
134
+
135
+ this._provider.query = function (sql: string | { query: string; values: unknown[] }, options?: QueryOptions | QueryOptionsWithType<QueryTypes.RAW> | undefined,) {
136
+ return Sequelize.prototype.query.apply(this, [sql, options]).catch((err ) => {
137
+
138
+
139
+ if( process.env.NODE_ENV=="development" || process.env.NODE_ENV=="dev"){
113
140
  // e.stack = e.original;
114
- if (err instanceof sequelize_1.DatabaseError) {
141
+ if( err instanceof DatabaseError){
115
142
  // @ts-ignore
116
143
  delete err.parent;
117
144
  // @ts-ignore
118
145
  delete err.original;
119
146
  }
120
147
  }
121
- throw new DataErrorDbException_1.DataErrorDbException(err);
122
- });
148
+ throw new DataErrorDbException(err);
149
+ })
123
150
  // try {
124
151
  // let r =
125
152
  // console.log(r)
@@ -127,55 +154,68 @@ class Model extends Component_1.Component {
127
154
  // console.log(err)
128
155
  // throw new DatabaseError(err);
129
156
  // }
130
- };
131
- if (!Utils_1.Utils.isEmpty(this.attributes())) {
157
+ }
158
+
159
+ if (!Utils.isEmpty(this.attributes())) {
132
160
  this._model = this._provider.define(this._tableName, this.attributes(), {
133
161
  tableName: this.tableName(),
134
162
  timestamps: false,
135
163
  createdAt: false,
136
164
  updateAt: false
137
165
  });
166
+
167
+ } else {
168
+ throw new InvalidConfigException(BaseChyz.t("Invalid model configuration, is not emty attributes"))
138
169
  }
139
- else {
140
- throw new InvalidConfigException_1.InvalidConfigException(BaseChyz_1.default.t("Invalid model configuration, is not emty attributes"));
141
- }
170
+
142
171
  // this.init();
172
+
143
173
  }
174
+
175
+
144
176
  /**
145
177
  * Returns the database connection used by this AR class.
146
178
  * By default, the "db" application component is used as the database connection.
147
179
  * You may override this method if you want to use a different database connection.
148
180
  * @return Connection the database connection used by this AR class.
149
181
  */
150
- getDb() {
151
- return BaseChyz_1.default.getComponent("db") ? BaseChyz_1.default.getComponent("db").db : null;
182
+ public getDb() {
183
+ return BaseChyz.getComponent("db") ? BaseChyz.getComponent("db").db : null
152
184
  }
153
- getDbConnection() {
154
- return BaseChyz_1.default.getComponent("db");
185
+
186
+ public getDbConnection() {
187
+ return BaseChyz.getComponent("db");
155
188
  }
156
- get provider() {
189
+
190
+ get provider(): any {
157
191
  return this._provider;
158
192
  }
159
- set provider(value) {
193
+
194
+ set provider(value: any) {
160
195
  this._provider = value;
161
196
  }
197
+
198
+
162
199
  /**
163
200
  *
164
201
  */
165
- get errors() {
202
+ get errors(): any {
166
203
  return this._errors;
167
204
  }
168
- set errors(value) {
205
+
206
+ set errors(value: any) {
169
207
  this._errors = value;
170
208
  }
171
- init() {
172
- BaseChyz_1.default.debug("Model init....", this.constructor.name);
209
+
210
+ public init() {
211
+ BaseChyz.debug("Model init....", this.constructor.name)
173
212
  /**
174
213
  * init buraya
175
214
  */
176
- BaseChyz_1.default.debug("Relation init....", this.constructor.name);
215
+ BaseChyz.debug("Relation init....", this.constructor.name)
177
216
  for (const relation of this.relations()) {
178
217
  let m = relation.model;
218
+
179
219
  if (relation.type == "hasOne") {
180
220
  // @ts-ignore
181
221
  delete relation.model;
@@ -187,114 +227,132 @@ class Model extends Component_1.Component {
187
227
  delete relation.model;
188
228
  this.model().hasMany(m, relation);
189
229
  }
230
+
190
231
  if (relation.type == "belongsTo") {
191
232
  // @ts-ignore
192
233
  delete relation.model;
193
234
  this.model().belongsTo(m, relation);
194
235
  }
236
+
195
237
  if (relation.type == "belongsToMany") {
196
238
  // @ts-ignore
197
239
  delete relation.model;
198
240
  this.model().belongsToMany(m, relation);
199
241
  }
200
242
  }
243
+
244
+
201
245
  }
202
- alias() {
246
+
247
+ public alias() {
203
248
  return this.constructor.name;
204
249
  }
205
- tableName() {
250
+
251
+ public tableName() {
206
252
  return this._tableName;
207
253
  }
208
- formName() {
254
+
255
+ public formName() {
209
256
  return this.constructor.name;
210
257
  }
211
- rules() {
212
- return [];
258
+
259
+ public rules() {
260
+ return []
213
261
  }
214
- setModel(value) {
262
+
263
+
264
+ public setModel(value: any) {
215
265
  this._model = value;
216
266
  }
217
- model() {
267
+
268
+ public model() {
218
269
  return this._model;
219
270
  }
220
- save(params = {}, options = {}) {
221
- return __awaiter(this, void 0, void 0, function* () {
222
- this.errors = {};
223
- // now instantiate an object
224
- let p = Object.assign(params, this._attributes);
225
- let result;
226
- try {
227
- result = yield this.model().create(p, options);
228
- }
229
- catch (e) {
230
- BaseChyz_1.default.debug(`Model[${this.constructor.name}].create`, e);
231
- if (e instanceof sequelize_1.ValidationError) {
232
- let validationErrorItems = e.errors;
233
- validationErrorItems.forEach(({ message, path }) => {
234
- // @ts-ignore
235
- this._errors[path] = message;
236
- });
237
- return false;
238
- }
239
- else if (e instanceof sequelize_1.DatabaseError) {
240
- }
241
- else if (e instanceof sequelize_1.TimeoutError) {
242
- }
243
- else if (e instanceof sequelize_1.UniqueConstraintError) {
244
- }
245
- else if (e instanceof sequelize_1.ForeignKeyConstraintError) {
246
- }
247
- else if (e instanceof sequelize_1.ExclusionConstraintError) {
248
- }
249
- throw new Exception_1.Exception(e.message, this.errors, e.code);
271
+
272
+
273
+ public async save(params = {}, options = {}) {
274
+
275
+ this.errors = {};
276
+ // now instantiate an object
277
+ let p = Object.assign(params, this._attributes)
278
+ let result: any;
279
+ try {
280
+ result = await this.model().create(p, options)
281
+ } catch (e: any) {
282
+ BaseChyz.debug(`Model[${this.constructor.name}].create`, e)
283
+ if (e instanceof ValidationError) {
284
+ let validationErrorItems = e.errors;
285
+ validationErrorItems.forEach(({message, path}) => {
286
+ // @ts-ignore
287
+ this._errors[path] = message
288
+ })
289
+
290
+ return false;
291
+ } else if (e instanceof DatabaseError) {
292
+
293
+ } else if (e instanceof TimeoutError) {
294
+
295
+ } else if (e instanceof UniqueConstraintError) {
296
+
297
+ } else if (e instanceof ForeignKeyConstraintError) {
298
+
299
+ } else if (e instanceof ExclusionConstraintError) {
300
+
250
301
  }
251
- return result;
252
- });
302
+ throw new Exception(e.message, this.errors, e.code);
303
+ }
304
+
305
+ return result;
306
+
253
307
  }
254
- bulkCreate(params = {}, options = {}) {
255
- return __awaiter(this, void 0, void 0, function* () {
256
- this.errors = {};
257
- // now instantiate an object
258
- let p = Object.assign(params, this._attributes);
259
- let result;
260
- try {
261
- result = yield this.model().bulkCreate(p, options);
262
- }
263
- catch (e) {
264
- BaseChyz_1.default.debug(`Model[${this.constructor.name}].bulkCreate`, e);
265
- if (e instanceof sequelize_1.ValidationError) {
266
- let validationErrorItems = e.errors;
267
- validationErrorItems.forEach(({ message, path }) => {
268
- // @ts-ignore
269
- this._errors[path] = message;
270
- });
271
- return false;
272
- }
273
- else if (e instanceof sequelize_1.DatabaseError) {
274
- }
275
- else if (e instanceof sequelize_1.TimeoutError) {
276
- }
277
- else if (e instanceof sequelize_1.UniqueConstraintError) {
278
- }
279
- else if (e instanceof sequelize_1.ForeignKeyConstraintError) {
280
- }
281
- else if (e instanceof sequelize_1.ExclusionConstraintError) {
282
- }
283
- throw new Exception_1.Exception(e.message, this.errors, e.code);
308
+
309
+ public async bulkCreate(params = {}, options = {}) {
310
+ this.errors = {};
311
+ // now instantiate an object
312
+ let p = Object.assign(params, this._attributes)
313
+ let result: any;
314
+ try {
315
+ result = await this.model().bulkCreate(p, options)
316
+ } catch (e: any) {
317
+ BaseChyz.debug(`Model[${this.constructor.name}].bulkCreate`, e)
318
+ if (e instanceof ValidationError) {
319
+ let validationErrorItems = e.errors;
320
+ validationErrorItems.forEach(({message, path}) => {
321
+ // @ts-ignore
322
+ this._errors[path] = message
323
+ })
324
+
325
+ return false;
326
+ } else if (e instanceof DatabaseError) {
327
+
328
+ } else if (e instanceof TimeoutError) {
329
+
330
+ } else if (e instanceof UniqueConstraintError) {
331
+
332
+ } else if (e instanceof ForeignKeyConstraintError) {
333
+
334
+ } else if (e instanceof ExclusionConstraintError) {
335
+
284
336
  }
285
- return result;
286
- });
337
+ throw new Exception(e.message, this.errors, e.code);
338
+ }
339
+
340
+ return result;
341
+
287
342
  }
288
- update(params = {}, options = {}) {
343
+
344
+ public update(params = {}, options = {}) {
289
345
  this.errors = {};
290
- let p = Object.assign(params, this._attributes);
291
- return this.model().update(p, options);
346
+ let p = Object.assign(params, this._attributes)
347
+ return this.model().update(p, options)
292
348
  }
293
- delete(params = {}, options = {}) {
349
+
350
+ public delete(params = {}, options = {}) {
294
351
  this.errors = {};
295
- let p = Object.assign(params, this._attributes);
296
- return this.model().destroy(p, options);
352
+ let p = Object.assign(params, this._attributes)
353
+ return this.model().destroy(p, options)
297
354
  }
355
+
298
356
  /**
299
357
  * As there are often use cases in which it is just easier to execute raw / already prepared SQL queries, you can use the sequelize.query method.
300
358
  *
@@ -459,87 +517,96 @@ class Model extends Component_1.Component {
459
517
  * @param query
460
518
  * @param options
461
519
  */
462
- rawQuery(query, options = { type: sequelize_1.QueryTypes.SELECT, nest: true }) {
463
- return __awaiter(this, void 0, void 0, function* () {
464
- this.errors = {};
465
- return yield this.model().query(query, options);
466
- });
520
+ public async rawQuery(query: string, options: any = {type: QueryTypes.SELECT, nest: true}) {
521
+ this.errors = {};
522
+ return await this.model().query(query, options);
467
523
  }
524
+
525
+
468
526
  /**
469
527
  *
470
528
  * @param args
471
529
  */
472
- findOne(...args) {
473
- return this._model.findOne(...arguments);
530
+ public findOne(...args: any[]) {
531
+ return this._model.findOne(...arguments)
474
532
  }
533
+
475
534
  /**
476
535
  *
477
536
  * @param args
478
537
  */
479
- findAll(...args) {
480
- return this._model.findAll(...arguments);
538
+ public findAll(...args: any[]) {
539
+ return this._model.findAll(...arguments)
481
540
  }
541
+
482
542
  /**
483
543
  * return {count : number , rows: any}
484
544
  * @param args
485
545
  */
486
- findAndCountAll(...args) {
487
- return this._model.findAndCountAll(...arguments);
546
+ public findAndCountAll(...args: any[]) {
547
+ return this._model.findAndCountAll(...arguments)
488
548
  }
489
- validate() {
549
+
550
+
551
+ public validate() {
552
+
490
553
  }
554
+
491
555
  /**
492
556
  *
493
557
  * @param data
494
558
  * @param formName
495
559
  */
496
- load(data, formName = null) {
560
+ public load(data: any, formName: any = null) {
497
561
  let scope = formName === null ? this.formName() : formName;
498
- if (scope === '' && !Utils_1.Utils.isEmpty(data)) {
562
+ if (scope === '' && !Utils.isEmpty(data)) {
499
563
  this.setAttribute(data);
500
564
  return true;
501
- }
502
- else if (data[scope]) {
565
+ } else if (data[scope]) {
503
566
  this.setAttribute(data[scope]);
504
567
  return true;
505
568
  }
506
569
  return false;
507
570
  }
508
- bulkLoad(data, formName = null) {
571
+
572
+ public bulkLoad(data: any, formName: any = null) {
509
573
  let scope = formName === null ? this.formName() : formName;
510
- if (scope === '' && !Utils_1.Utils.isEmpty(data)) {
574
+ if (scope === '' && !Utils.isEmpty(data)) {
511
575
  this.setAttribute(data);
512
576
  return true;
513
- }
514
- else if (data[scope]) {
577
+ } else if (data[scope]) {
515
578
  this.setAttribute(data[scope]);
516
579
  return true;
517
580
  }
518
581
  return false;
519
582
  }
520
- setAttribute(values, safeOnly = true) {
583
+
584
+ public setAttribute(values: any, safeOnly = true) {
521
585
  if (values instanceof Object) {
522
586
  let attributes = this.attributes();
523
587
  for (const valueKey in values) {
524
588
  if (Object.keys(attributes).indexOf(valueKey) != -1) {
525
589
  // @ts-ignore
526
- BaseChyz_1.default.debug("Model[" + this.formName() + "] attributes value set ", valueKey, values[valueKey]);
590
+ BaseChyz.debug("Model[" + this.formName() + "] attributes value set ", valueKey, values[valueKey])
527
591
  this._attributes[valueKey] = values[valueKey];
528
592
  }
529
593
  }
530
594
  }
531
595
  }
532
- attributes() {
533
- return {};
596
+
597
+ public attributes() {
598
+ return {}
534
599
  }
600
+
535
601
  /**
536
602
  * relation return array
537
603
  * [
538
604
  *
539
605
  * ]
540
606
  */
541
- relations() {
542
- return [];
607
+ public relations(): Relation[] {
608
+ return []
543
609
  }
610
+
611
+
544
612
  }
545
- exports.Model = Model;
@@ -1,6 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModelManager = void 0;
1
+ import {Model} from "./Model"
2
+
4
3
  /*
5
4
  *
6
5
  * Copyright (c) 2021.. Chy Bilgisayar Bilisim
@@ -12,8 +11,9 @@ exports.ModelManager = void 0;
12
11
  // interface ObjectConstructor {
13
12
  // _register(o: Model): void;
14
13
  // }
15
- exports.ModelManager = {
16
- _register(map) {
17
- Object.assign(this, map);
14
+
15
+ export const ModelManager: any = {
16
+ _register(map: Model) {
17
+ Object.assign(this, map)
18
18
  }
19
- };
19
+ }
@@ -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 NotFoundHttpException extends BaseError {
11
+ constructor ( public message: any) {
12
+ super(message,404);
13
+ }
14
+ }
@@ -0,0 +1,26 @@
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
+ }
@@ -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 {BaseError} from "./BaseError";
9
+
10
+ export class UnauthorizedHttpException extends BaseError {
11
+ constructor ( public message: any) {
12
+ super(message,401);
13
+ }
14
+
15
+ }
16
+
17
+
@@ -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 ValidationHttpException extends BaseError {
11
+ constructor ( public message: any) {
12
+ super(message,400);
13
+ }
14
+ }
@@ -0,0 +1,14 @@
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
+ }