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.
- package/BaseChyz.ts +623 -0
- package/README.md +518 -518
- package/base/ActionFilter.ts +88 -0
- package/base/BadRequestHttpException.ts +14 -0
- package/base/{BaseError.js → BaseError.ts} +26 -18
- package/base/Behavior.ts +6 -0
- package/base/CBaseObject.ts +17 -0
- package/base/CEvents.ts +24 -0
- package/base/{CRequest.js → CRequest.ts} +6 -2
- package/base/CWebController.ts +90 -0
- package/base/Component.ts +66 -0
- package/{model/RouteDefinition.js → base/Configurable.ts} +4 -2
- package/base/DataErrorDbException.ts +16 -0
- package/base/DbConnection.ts +55 -0
- package/base/ForbiddenHttpException.ts +15 -0
- package/base/InvalidArgumentException.ts +16 -0
- package/base/InvalidConfigException.ts +16 -0
- package/base/{Logs.js → Logs.ts} +41 -24
- package/base/{Model.js → Model.ts} +225 -158
- package/base/{ModelManager.js → ModelManager.ts} +7 -7
- package/base/NotFoundHttpException.ts +14 -0
- package/base/RestClient.ts +26 -0
- package/base/UnauthorizedHttpException.ts +17 -0
- package/base/ValidationHttpException.ts +14 -0
- package/base/db/Exception.ts +14 -0
- package/base/index.ts +19 -0
- package/decorator/Middleware.ts +9 -0
- package/decorator/{controller.js → controller.ts} +7 -9
- package/decorator/{delete.js → delete.ts} +9 -9
- package/decorator/enums/ControllerDecoratorParams.ts +5 -0
- package/decorator/{get.js → get.ts} +11 -10
- package/decorator/index.ts +5 -0
- package/decorator/{post.js → post.ts} +10 -10
- package/decorator/{put.js → put.ts} +9 -9
- package/filters/AccessControl.ts +74 -0
- package/filters/AccessRule.ts +182 -0
- package/filters/auth/{AuthInterface.d.ts → AuthInterface.ts} +15 -7
- package/filters/auth/AuthMethod.ts +100 -0
- package/filters/auth/HttpBasicAuth.ts +79 -0
- package/filters/auth/HttpBearerAuth.ts +34 -0
- package/filters/auth/HttpHeaderAuth.ts +61 -0
- package/filters/auth/JwtHttpBearerAuth.ts +83 -0
- package/filters/auth/KeyCloakHttpBearerAuth.ts +114 -0
- package/filters/auth/index.ts +4 -0
- package/filters/index.ts +2 -0
- package/index.ts +80 -0
- package/log/config/log4js.json +55 -55
- package/model/RouteDefinition.ts +18 -0
- package/package.json +63 -61
- package/rbac/AuthAssignment.ts +50 -0
- package/rbac/{AuthItem.js → AuthItem.ts} +22 -16
- package/rbac/{AuthItemChild.js → AuthItemChild.ts} +21 -14
- package/rbac/AuthManager.ts +399 -0
- package/rbac/index.ts +12 -0
- package/{web/IdentityInterface.js → requiments/Glob.ts} +3 -2
- package/requiments/{ReflectUtil.js → ReflectUtil.ts} +6 -4
- package/requiments/{Utils.js → Utils.ts} +40 -34
- package/validators/BooleanValidator.ts +0 -0
- package/validators/CompareValidator.ts +0 -0
- package/validators/DateValidator.ts +0 -0
- package/validators/EmailValidator.ts +0 -0
- package/validators/Validator.ts +27 -0
- package/web/{IdentityInterface.d.ts → IdentityInterface.ts} +15 -2
- package/web/WebUser.ts +187 -0
- package/BaseChyz.d.ts +0 -74
- package/BaseChyz.d.ts.map +0 -1
- package/BaseChyz.js +0 -569
- package/base/ActionFilter.d.ts +0 -33
- package/base/ActionFilter.d.ts.map +0 -1
- package/base/ActionFilter.js +0 -90
- package/base/BadRequestHttpException.d.ts +0 -6
- package/base/BadRequestHttpException.d.ts.map +0 -1
- package/base/BadRequestHttpException.js +0 -17
- package/base/BaseError.d.ts +0 -44
- package/base/BaseError.d.ts.map +0 -1
- package/base/Behavior.d.ts +0 -4
- package/base/Behavior.d.ts.map +0 -1
- package/base/Behavior.js +0 -7
- package/base/CBaseObject.d.ts +0 -5
- package/base/CBaseObject.d.ts.map +0 -1
- package/base/CBaseObject.js +0 -16
- package/base/CEvents.d.ts +0 -13
- package/base/CEvents.d.ts.map +0 -1
- package/base/CEvents.js +0 -24
- package/base/CRequest.d.ts +0 -2
- package/base/CRequest.d.ts.map +0 -1
- package/base/CWebController.d.ts +0 -44
- package/base/CWebController.d.ts.map +0 -1
- package/base/CWebController.js +0 -81
- package/base/Component.d.ts +0 -21
- package/base/Component.d.ts.map +0 -1
- package/base/Component.js +0 -57
- package/base/Configurable.d.ts +0 -3
- package/base/Configurable.d.ts.map +0 -1
- package/base/Configurable.js +0 -8
- package/base/DataErrorDbException.d.ts +0 -6
- package/base/DataErrorDbException.d.ts.map +0 -1
- package/base/DataErrorDbException.js +0 -17
- package/base/DbConnection.d.ts +0 -13
- package/base/DbConnection.d.ts.map +0 -1
- package/base/DbConnection.js +0 -53
- package/base/ForbiddenHttpException.d.ts +0 -5
- package/base/ForbiddenHttpException.d.ts.map +0 -1
- package/base/ForbiddenHttpException.js +0 -16
- package/base/InvalidArgumentException.d.ts +0 -6
- package/base/InvalidArgumentException.d.ts.map +0 -1
- package/base/InvalidArgumentException.js +0 -17
- package/base/InvalidConfigException.d.ts +0 -6
- package/base/InvalidConfigException.d.ts.map +0 -1
- package/base/InvalidConfigException.js +0 -17
- package/base/Logs.d.ts +0 -22
- package/base/Logs.d.ts.map +0 -1
- package/base/Model.d.ts +0 -302
- package/base/Model.d.ts.map +0 -1
- package/base/ModelManager.d.ts +0 -2
- package/base/ModelManager.d.ts.map +0 -1
- package/base/NotFoundHttpException.d.ts +0 -6
- package/base/NotFoundHttpException.d.ts.map +0 -1
- package/base/NotFoundHttpException.js +0 -17
- package/base/RestClient.d.ts +0 -7
- package/base/RestClient.d.ts.map +0 -1
- package/base/RestClient.js +0 -25
- package/base/UnauthorizedHttpException.d.ts +0 -6
- package/base/UnauthorizedHttpException.d.ts.map +0 -1
- package/base/UnauthorizedHttpException.js +0 -17
- package/base/ValidationHttpException.d.ts +0 -6
- package/base/ValidationHttpException.d.ts.map +0 -1
- package/base/ValidationHttpException.js +0 -17
- package/base/db/Exception.d.ts +0 -7
- package/base/db/Exception.d.ts.map +0 -1
- package/base/db/Exception.js +0 -15
- package/base/index.d.ts +0 -20
- package/base/index.d.ts.map +0 -1
- package/base/index.js +0 -41
- package/decorator/Middleware.d.ts +0 -4
- package/decorator/Middleware.d.ts.map +0 -1
- package/decorator/Middleware.js +0 -11
- package/decorator/controller.d.ts +0 -3
- package/decorator/controller.d.ts.map +0 -1
- package/decorator/delete.d.ts +0 -3
- package/decorator/delete.d.ts.map +0 -1
- package/decorator/enums/ControllerDecoratorParams.d.ts +0 -6
- package/decorator/enums/ControllerDecoratorParams.d.ts.map +0 -1
- package/decorator/enums/ControllerDecoratorParams.js +0 -9
- package/decorator/get.d.ts +0 -3
- package/decorator/get.d.ts.map +0 -1
- package/decorator/index.d.ts +0 -6
- package/decorator/index.d.ts.map +0 -1
- package/decorator/index.js +0 -13
- package/decorator/post.d.ts +0 -3
- package/decorator/post.d.ts.map +0 -1
- package/decorator/put.d.ts +0 -3
- package/decorator/put.d.ts.map +0 -1
- package/filters/AccessControl.d.ts +0 -13
- package/filters/AccessControl.d.ts.map +0 -1
- package/filters/AccessControl.js +0 -83
- package/filters/AccessRule.d.ts +0 -83
- package/filters/AccessRule.d.ts.map +0 -1
- package/filters/AccessRule.js +0 -136
- package/filters/auth/AuthInterface.d.ts.map +0 -1
- package/filters/auth/AuthInterface.js +0 -2
- package/filters/auth/AuthMethod.d.ts +0 -38
- package/filters/auth/AuthMethod.d.ts.map +0 -1
- package/filters/auth/AuthMethod.js +0 -82
- package/filters/auth/HttpBasicAuth.d.ts +0 -24
- package/filters/auth/HttpBasicAuth.d.ts.map +0 -1
- package/filters/auth/HttpBasicAuth.js +0 -78
- package/filters/auth/HttpBearerAuth.d.ts +0 -18
- package/filters/auth/HttpBearerAuth.d.ts.map +0 -1
- package/filters/auth/HttpBearerAuth.js +0 -33
- package/filters/auth/HttpHeaderAuth.d.ts +0 -19
- package/filters/auth/HttpHeaderAuth.d.ts.map +0 -1
- package/filters/auth/HttpHeaderAuth.js +0 -64
- package/filters/auth/JwtHttpBearerAuth.d.ts +0 -21
- package/filters/auth/JwtHttpBearerAuth.d.ts.map +0 -1
- package/filters/auth/JwtHttpBearerAuth.js +0 -87
- package/filters/auth/KeyCloakHttpBearerAuth.d.ts +0 -23
- package/filters/auth/KeyCloakHttpBearerAuth.d.ts.map +0 -1
- package/filters/auth/KeyCloakHttpBearerAuth.js +0 -116
- package/filters/auth/index.d.ts +0 -5
- package/filters/auth/index.d.ts.map +0 -1
- package/filters/auth/index.js +0 -11
- package/filters/index.d.ts +0 -3
- package/filters/index.d.ts.map +0 -1
- package/filters/index.js +0 -7
- package/index.d.ts +0 -26
- package/index.d.ts.map +0 -1
- package/index.js +0 -72
- package/model/RouteDefinition.d.ts +0 -7
- package/model/RouteDefinition.d.ts.map +0 -1
- package/rbac/AuthAssignment.d.ts +0 -19
- package/rbac/AuthAssignment.d.ts.map +0 -1
- package/rbac/AuthAssignment.js +0 -44
- package/rbac/AuthItem.d.ts +0 -27
- package/rbac/AuthItem.d.ts.map +0 -1
- package/rbac/AuthItemChild.d.ts +0 -19
- package/rbac/AuthItemChild.d.ts.map +0 -1
- package/rbac/AuthManager.d.ts +0 -112
- package/rbac/AuthManager.d.ts.map +0 -1
- package/rbac/AuthManager.js +0 -356
- package/rbac/index.d.ts +0 -5
- package/rbac/index.d.ts.map +0 -1
- package/rbac/index.js +0 -28
- package/requiments/Glob.d.ts +0 -3
- package/requiments/Glob.d.ts.map +0 -1
- package/requiments/Glob.js +0 -10
- package/requiments/ReflectUtil.d.ts +0 -1
- package/requiments/ReflectUtil.d.ts.map +0 -1
- package/requiments/Utils.d.ts +0 -2
- package/requiments/Utils.d.ts.map +0 -1
- package/validators/BooleanValidator.d.ts +0 -1
- package/validators/BooleanValidator.d.ts.map +0 -1
- package/validators/BooleanValidator.js +0 -1
- package/validators/CompareValidator.d.ts +0 -1
- package/validators/CompareValidator.d.ts.map +0 -1
- package/validators/CompareValidator.js +0 -1
- package/validators/DateValidator.d.ts +0 -1
- package/validators/DateValidator.d.ts.map +0 -1
- package/validators/DateValidator.js +0 -1
- package/validators/EmailValidator.d.ts +0 -1
- package/validators/EmailValidator.d.ts.map +0 -1
- package/validators/EmailValidator.js +0 -1
- package/validators/Validator.d.ts +0 -18
- package/validators/Validator.d.ts.map +0 -1
- package/validators/Validator.js +0 -27
- package/web/IdentityInterface.d.ts.map +0 -1
- package/web/WebUser.d.ts +0 -72
- package/web/WebUser.d.ts.map +0 -1
- 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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
86
|
-
|
|
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
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
182
|
+
public getDb() {
|
|
183
|
+
return BaseChyz.getComponent("db") ? BaseChyz.getComponent("db").db : null
|
|
152
184
|
}
|
|
153
|
-
|
|
154
|
-
|
|
185
|
+
|
|
186
|
+
public getDbConnection() {
|
|
187
|
+
return BaseChyz.getComponent("db");
|
|
155
188
|
}
|
|
156
|
-
|
|
189
|
+
|
|
190
|
+
get provider(): any {
|
|
157
191
|
return this._provider;
|
|
158
192
|
}
|
|
159
|
-
|
|
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
|
-
|
|
205
|
+
|
|
206
|
+
set errors(value: any) {
|
|
169
207
|
this._errors = value;
|
|
170
208
|
}
|
|
171
|
-
|
|
172
|
-
|
|
209
|
+
|
|
210
|
+
public init() {
|
|
211
|
+
BaseChyz.debug("Model init....", this.constructor.name)
|
|
173
212
|
/**
|
|
174
213
|
* init buraya
|
|
175
214
|
*/
|
|
176
|
-
|
|
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
|
-
|
|
246
|
+
|
|
247
|
+
public alias() {
|
|
203
248
|
return this.constructor.name;
|
|
204
249
|
}
|
|
205
|
-
|
|
250
|
+
|
|
251
|
+
public tableName() {
|
|
206
252
|
return this._tableName;
|
|
207
253
|
}
|
|
208
|
-
|
|
254
|
+
|
|
255
|
+
public formName() {
|
|
209
256
|
return this.constructor.name;
|
|
210
257
|
}
|
|
211
|
-
|
|
212
|
-
|
|
258
|
+
|
|
259
|
+
public rules() {
|
|
260
|
+
return []
|
|
213
261
|
}
|
|
214
|
-
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
public setModel(value: any) {
|
|
215
265
|
this._model = value;
|
|
216
266
|
}
|
|
217
|
-
|
|
267
|
+
|
|
268
|
+
public model() {
|
|
218
269
|
return this._model;
|
|
219
270
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
252
|
-
}
|
|
302
|
+
throw new Exception(e.message, this.errors, e.code);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return result;
|
|
306
|
+
|
|
253
307
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
286
|
-
}
|
|
337
|
+
throw new Exception(e.message, this.errors, e.code);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return result;
|
|
341
|
+
|
|
287
342
|
}
|
|
288
|
-
|
|
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
|
-
|
|
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 = {
|
|
463
|
-
|
|
464
|
-
|
|
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
|
-
|
|
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 === '' && !
|
|
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
|
-
|
|
571
|
+
|
|
572
|
+
public bulkLoad(data: any, formName: any = null) {
|
|
509
573
|
let scope = formName === null ? this.formName() : formName;
|
|
510
|
-
if (scope === '' && !
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
533
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
}
|