chyz 1.0.13-rc.3 → 1.0.13-rc.4
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/{dist/BaseChyz.js → BaseChyz.js} +0 -0
- package/{dist/BaseChyz.js.map → BaseChyz.js.map} +0 -0
- package/{dist/Chyz.js → Chyz.js} +0 -0
- package/{dist/Chyz.js.map → Chyz.js.map} +0 -0
- package/{dist/base → base}/ActionFilter.js +0 -0
- package/{dist/base → base}/ActionFilter.js.map +0 -0
- package/{dist/base → base}/BaseError.js +0 -0
- package/{dist/base → base}/BaseError.js.map +0 -0
- package/{dist/base → base}/BaseObject.js +0 -0
- package/{dist/base → base}/BaseObject.js.map +0 -0
- package/{dist/base → base}/Behavior.js +0 -0
- package/{dist/base → base}/Behavior.js.map +0 -0
- package/{dist/base → base}/Component.js +0 -0
- package/{dist/base → base}/Component.js.map +0 -0
- package/{dist/base → base}/Configurable.js +0 -0
- package/{dist/base → base}/Configurable.js.map +0 -0
- package/{dist/base → base}/Controller.js +0 -0
- package/{dist/base → base}/Controller.js.map +0 -0
- package/{dist/base → base}/DataErrorDbException.js +0 -0
- package/{dist/base → base}/DataErrorDbException.js.map +0 -0
- package/{dist/base → base}/DbConnection.js +0 -0
- package/{dist/base → base}/DbConnection.js.map +0 -0
- package/{dist/base → base}/ForbiddenHttpException.js +0 -0
- package/{dist/base → base}/ForbiddenHttpException.js.map +0 -0
- package/{dist/base → base}/InvalidConfigException.js +0 -0
- package/{dist/base → base}/InvalidConfigException.js.map +0 -0
- package/{dist/base → base}/Model.js +0 -0
- package/{dist/base → base}/Model.js.map +0 -0
- package/{dist/base → base}/NotFoundHttpException.js +0 -0
- package/{dist/base → base}/NotFoundHttpException.js.map +0 -0
- package/{dist/base → base}/RestClient.js +0 -0
- package/{dist/base → base}/RestClient.js.map +0 -0
- package/{dist/base → base}/UnauthorizedHttpException.js +0 -0
- package/{dist/base → base}/UnauthorizedHttpException.js.map +0 -0
- package/{dist/base → base}/ValidationHttpException.js +0 -0
- package/{dist/base → base}/ValidationHttpException.js.map +0 -0
- package/{dist/base → base}/db/Exception.js +0 -0
- package/{dist/base → base}/db/Exception.js.map +0 -0
- package/{dist/base → base}/index.js +0 -0
- package/{dist/base → base}/index.js.map +0 -0
- package/{dist/decorator → decorator}/Middleware.js +0 -0
- package/{dist/decorator → decorator}/Middleware.js.map +0 -0
- package/{dist/decorator → decorator}/controller.js +0 -0
- package/{dist/decorator → decorator}/controller.js.map +0 -0
- package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js +0 -0
- package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js.map +0 -0
- package/{dist/decorator → decorator}/get.js +0 -0
- package/{dist/decorator → decorator}/get.js.map +0 -0
- package/{dist/decorator → decorator}/index.js +0 -0
- package/{dist/decorator → decorator}/index.js.map +0 -0
- package/{dist/decorator → decorator}/post.js +0 -0
- package/{dist/decorator → decorator}/post.js.map +0 -0
- package/{dist/filters → filters}/AccessControl.js +0 -0
- package/{dist/filters → filters}/AccessControl.js.map +0 -0
- package/{dist/filters → filters}/AccessRule.js +0 -0
- package/{dist/filters → filters}/AccessRule.js.map +0 -0
- package/{dist/filters → filters}/auth/AuthInterface.js +0 -0
- package/{dist/filters → filters}/auth/AuthInterface.js.map +0 -0
- package/{dist/filters → filters}/auth/AuthMethod.js +0 -0
- package/{dist/filters → filters}/auth/AuthMethod.js.map +0 -0
- package/{dist/filters → filters}/auth/HttpBasicAuth.js +0 -0
- package/{dist/filters → filters}/auth/HttpBasicAuth.js.map +0 -0
- package/{dist/filters → filters}/auth/HttpBearerAuth.js +0 -0
- package/{dist/filters → filters}/auth/HttpBearerAuth.js.map +0 -0
- package/{dist/filters → filters}/auth/HttpHeaderAuth.js +0 -0
- package/{dist/filters → filters}/auth/HttpHeaderAuth.js.map +0 -0
- package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js +0 -0
- package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js.map +0 -0
- package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js +0 -0
- package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js.map +0 -0
- package/{dist/filters → filters}/auth/index.js +0 -0
- package/{dist/filters → filters}/auth/index.js.map +0 -0
- package/{dist/filters → filters}/index.js +0 -0
- package/{dist/filters → filters}/index.js.map +0 -0
- package/{dist/index.js → index.js} +0 -0
- package/{dist/index.js.map → index.js.map} +0 -0
- package/{dist/model → model}/RouteDefinition.js +0 -0
- package/{dist/model → model}/RouteDefinition.js.map +0 -0
- package/package.json +1 -1
- package/{dist/requiments → requiments}/Glob.js +0 -0
- package/{dist/requiments → requiments}/Glob.js.map +0 -0
- package/{dist/requiments → requiments}/ReflectUtil.js +0 -0
- package/{dist/requiments → requiments}/ReflectUtil.js.map +0 -0
- package/{dist/requiments → requiments}/Utils.js +0 -0
- package/{dist/requiments → requiments}/Utils.js.map +0 -0
- package/{dist/validators → validators}/BooleanValidator.js +0 -0
- package/{dist/validators → validators}/BooleanValidator.js.map +0 -0
- package/{dist/validators → validators}/CompareValidator.js +0 -0
- package/{dist/validators → validators}/CompareValidator.js.map +0 -0
- package/{dist/validators → validators}/DateValidator.js +0 -0
- package/{dist/validators → validators}/DateValidator.js.map +0 -0
- package/{dist/validators → validators}/EmailValidator.js +0 -0
- package/{dist/validators → validators}/EmailValidator.js.map +0 -0
- package/{dist/validators → validators}/Validator.js +0 -0
- package/{dist/validators → validators}/Validator.js.map +0 -0
- package/{dist/web → web}/IdentityInterface.js +0 -0
- package/{dist/web → web}/IdentityInterface.js.map +0 -0
- package/{dist/web → web}/WebUser.js +0 -0
- package/{dist/web → web}/WebUser.js.map +0 -0
- package/BaseChyz.ts +0 -361
- package/Chyz.ts +0 -11
- package/Examples/Controllers/ApiController.ts +0 -131
- package/Examples/Controllers/KeyCloakController.ts +0 -100
- package/Examples/Controllers/PublicController.ts +0 -42
- package/Examples/Controllers/SiteController.ts +0 -139
- package/Examples/Models/Categories.ts +0 -36
- package/Examples/Models/Customer.ts +0 -115
- package/Examples/Models/KeycloakUser.ts +0 -66
- package/Examples/Models/Order.ts +0 -64
- package/Examples/Models/OrderItem.ts +0 -27
- package/Examples/Models/ProductModels.ts +0 -50
- package/Examples/Models/ProductToCategories.ts +0 -35
- package/Examples/Models/Products.ts +0 -49
- package/Examples/Models/Stocks.ts +0 -60
- package/Examples/Models/User.ts +0 -100
- package/Examples/Models/UserPermission.ts +0 -37
- package/Examples/index-keycloack.ts +0 -78
- package/Examples/index.ts +0 -39
- package/Examples/keycloak.json +0 -7
- package/Examples/log/access.log +0 -0
- package/Examples/log/app.log +0 -923
- package/Examples/log/errors.log +0 -80
- package/Examples/package.json +0 -46
- package/Examples/tsconfig.json +0 -20
- package/base/ActionFilter.ts +0 -71
- package/base/BaseError.ts +0 -26
- package/base/BaseObject.ts +0 -19
- package/base/Behavior.ts +0 -6
- package/base/Component.ts +0 -66
- package/base/Configurable.ts +0 -10
- package/base/Controller.ts +0 -84
- package/base/DataErrorDbException.ts +0 -16
- package/base/DbConnection.ts +0 -51
- package/base/ForbiddenHttpException.ts +0 -15
- package/base/InvalidConfigException.ts +0 -16
- package/base/Model.ts +0 -354
- package/base/NotFoundHttpException.ts +0 -14
- package/base/RestClient.ts +0 -28
- package/base/UnauthorizedHttpException.ts +0 -17
- package/base/ValidationHttpException.ts +0 -14
- package/base/db/Exception.ts +0 -14
- package/base/index.ts +0 -16
- package/decorator/Middleware.ts +0 -9
- package/decorator/controller.ts +0 -22
- package/decorator/enums/ControllerDecoratorParams.ts +0 -5
- package/decorator/get.ts +0 -37
- package/decorator/index.ts +0 -3
- package/decorator/post.ts +0 -36
- package/dist/README.md +0 -270
- package/dist/log/config/log4js.json +0 -55
- package/dist/package.json +0 -55
- package/filters/AccessControl.ts +0 -64
- package/filters/AccessRule.ts +0 -137
- package/filters/auth/AuthInterface.ts +0 -34
- package/filters/auth/AuthMethod.ts +0 -88
- package/filters/auth/HttpBasicAuth.ts +0 -7
- package/filters/auth/HttpBearerAuth.ts +0 -31
- package/filters/auth/HttpHeaderAuth.ts +0 -53
- package/filters/auth/JwtHttpBearerAuth.ts +0 -80
- package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -115
- package/filters/auth/index.ts +0 -3
- package/filters/index.ts +0 -2
- package/index.ts +0 -14
- package/model/RouteDefinition.ts +0 -18
- package/package-lock.json +0 -5259
- package/requiments/Glob.ts +0 -9
- package/requiments/ReflectUtil.ts +0 -26
- package/requiments/Utils.ts +0 -57
- package/tsconfig.json +0 -18
- 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 +0 -27
- package/web/IdentityInterface.ts +0 -62
- package/web/WebUser.ts +0 -100
package/base/Model.ts
DELETED
|
@@ -1,354 +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 "../BaseChyz";
|
|
9
|
-
import Utils from "../requiments/Utils";
|
|
10
|
-
import {Component} from "./Component";
|
|
11
|
-
import {InvalidConfigException} from "./InvalidConfigException";
|
|
12
|
-
import {DatabaseError, DataTypes, ExclusionConstraintError, ForeignKeyConstraintError, Model as SModel, TimeoutError, UniqueConstraintError, ValidationError,} from "sequelize";
|
|
13
|
-
import {Exception} from "./db/Exception";
|
|
14
|
-
|
|
15
|
-
export {DataTypes, NOW} from "sequelize";
|
|
16
|
-
|
|
17
|
-
export interface Relation{
|
|
18
|
-
type: "hasOne" | "hasMany" | "belongsToMany" | "belongsTo",
|
|
19
|
-
allowNull?:boolean,
|
|
20
|
-
sourceKey:string,
|
|
21
|
-
model:SModel,
|
|
22
|
-
foreignKey:string,
|
|
23
|
-
name?:string,
|
|
24
|
-
through?:string,
|
|
25
|
-
as?:string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* ValidateMe.init({
|
|
30
|
-
bar: {
|
|
31
|
-
type: Sequelize.STRING,
|
|
32
|
-
validate: {
|
|
33
|
-
is: ["^[a-z]+$",'i'], // will only allow letters
|
|
34
|
-
is: /^[a-z]+$/i, // same as the previous example using real RegExp
|
|
35
|
-
not: ["[a-z]",'i'], // will not allow letters
|
|
36
|
-
isEmail: true, // checks for email format (foo@bar.com)
|
|
37
|
-
isUrl: true, // checks for url format (http://foo.com)
|
|
38
|
-
isIP: true, // checks for IPv4 (129.89.23.1) or IPv6 format
|
|
39
|
-
isIPv4: true, // checks for IPv4 (129.89.23.1)
|
|
40
|
-
isIPv6: true, // checks for IPv6 format
|
|
41
|
-
isAlpha: true, // will only allow letters
|
|
42
|
-
isAlphanumeric: true, // will only allow alphanumeric characters, so "_abc" will fail
|
|
43
|
-
isNumeric: true, // will only allow numbers
|
|
44
|
-
isInt: true, // checks for valid integers
|
|
45
|
-
isFloat: true, // checks for valid floating point numbers
|
|
46
|
-
isDecimal: true, // checks for any numbers
|
|
47
|
-
isLowercase: true, // checks for lowercase
|
|
48
|
-
isUppercase: true, // checks for uppercase
|
|
49
|
-
notNull: true, // won't allow null
|
|
50
|
-
isNull: true, // only allows null
|
|
51
|
-
notEmpty: true, // don't allow empty strings
|
|
52
|
-
equals: 'specific value', // only allow a specific value
|
|
53
|
-
contains: 'foo', // force specific substrings
|
|
54
|
-
notIn: [['foo', 'bar']], // check the value is not one of these
|
|
55
|
-
isIn: [['foo', 'bar']], // check the value is one of these
|
|
56
|
-
notContains: 'bar', // don't allow specific substrings
|
|
57
|
-
len: [2,10], // only allow values with length between 2 and 10
|
|
58
|
-
isUUID: 4, // only allow uuids
|
|
59
|
-
isDate: true, // only allow date strings
|
|
60
|
-
isAfter: "2011-11-05", // only allow date strings after a specific date
|
|
61
|
-
isBefore: "2011-11-05", // only allow date strings before a specific date
|
|
62
|
-
max: 23, // only allow values <= 23
|
|
63
|
-
min: 23, // only allow values >= 23
|
|
64
|
-
isCreditCard: true, // check for valid credit card numbers
|
|
65
|
-
|
|
66
|
-
// Examples of custom validators:
|
|
67
|
-
isEven(value) {
|
|
68
|
-
if (parseInt(value) % 2 !== 0) {
|
|
69
|
-
throw new Error('Only even values are allowed!');
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
isGreaterThanOtherField(value) {
|
|
73
|
-
if (parseInt(value) <= parseInt(this.otherField)) {
|
|
74
|
-
throw new Error('Bar must be greater than otherField.');
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}, { sequelize });
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
export class Model extends Component {
|
|
83
|
-
_sequelize: any ;
|
|
84
|
-
private _tableName: string;
|
|
85
|
-
private _model: any;
|
|
86
|
-
private _attributes: any = {};
|
|
87
|
-
private _errors: any = {}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
constructor(sequelize?: IDBDatabase) {
|
|
91
|
-
super();
|
|
92
|
-
this._tableName = this.constructor.name;
|
|
93
|
-
// this._sequelize = BaseChyz.getComponent("db").db;
|
|
94
|
-
if (sequelize != null)
|
|
95
|
-
this._sequelize = sequelize;
|
|
96
|
-
else
|
|
97
|
-
this._sequelize = BaseChyz.getComponent("db").db;
|
|
98
|
-
|
|
99
|
-
if (!Utils.isEmpty(this.attributes())) {
|
|
100
|
-
this._model = this._sequelize.define(this.constructor.name, this.attributes(), {
|
|
101
|
-
tableName: this.tableName(),
|
|
102
|
-
timestamps: false
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* init buraya
|
|
109
|
-
*/
|
|
110
|
-
|
|
111
|
-
for (const relation of this.relations()) {
|
|
112
|
-
let m = relation.model;
|
|
113
|
-
|
|
114
|
-
if(relation.type=="hasOne" ){
|
|
115
|
-
// @ts-ignore
|
|
116
|
-
delete relation.model
|
|
117
|
-
this.model().hasOne(m, relation );
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if(relation.type=="hasMany" ){
|
|
121
|
-
// @ts-ignore
|
|
122
|
-
delete relation.model;
|
|
123
|
-
this.model().hasMany(m, relation );
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if(relation.type=="belongsTo" ){
|
|
127
|
-
// @ts-ignore
|
|
128
|
-
delete relation.model;
|
|
129
|
-
this.model().belongsTo(m, relation );
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if(relation.type=="belongsToMany" ){
|
|
133
|
-
// @ts-ignore
|
|
134
|
-
delete relation.model;
|
|
135
|
-
this.model().belongsToMany(m, relation );
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
} else {
|
|
140
|
-
throw new InvalidConfigException(BaseChyz.t("Invalid model configuration, is not emty attributes"))
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
this.init();
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Returns the database connection used by this AR class.
|
|
150
|
-
* By default, the "db" application component is used as the database connection.
|
|
151
|
-
* You may override this method if you want to use a different database connection.
|
|
152
|
-
* @return Connection the database connection used by this AR class.
|
|
153
|
-
*/
|
|
154
|
-
public static getDb()
|
|
155
|
-
{
|
|
156
|
-
return BaseChyz.getComponent("db").db
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
get sequelize(): any {
|
|
160
|
-
return this._sequelize;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
set sequelize(value: any) {
|
|
164
|
-
this._sequelize = value;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
*
|
|
170
|
-
*/
|
|
171
|
-
get errors(): any {
|
|
172
|
-
return this._errors;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
set errors(value: any) {
|
|
176
|
-
this._errors = value;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
public init() {
|
|
180
|
-
BaseChyz.debug("Model init....", this.constructor.name)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
public tableName() {
|
|
185
|
-
return this._tableName;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
public formName() {
|
|
189
|
-
return this.constructor.name;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
public rules() {
|
|
193
|
-
return []
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
public model() {
|
|
197
|
-
return this._model;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
public async save(params = {}, options = {}) {
|
|
201
|
-
// now instantiate an object
|
|
202
|
-
let p = Object.assign(params, this._attributes)
|
|
203
|
-
let result: any;
|
|
204
|
-
try {
|
|
205
|
-
result = await this.model().create(p, options)
|
|
206
|
-
} catch (e) {
|
|
207
|
-
BaseChyz.debug(`Model[${this.constructor.name}].create`, e)
|
|
208
|
-
if (e instanceof ValidationError) {
|
|
209
|
-
let validationErrorItems = e.errors;
|
|
210
|
-
validationErrorItems.forEach(({message, path}) => {
|
|
211
|
-
// @ts-ignore
|
|
212
|
-
this._errors[path] = message
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
return false;
|
|
216
|
-
} else if (e instanceof DatabaseError) {
|
|
217
|
-
|
|
218
|
-
} else if (e instanceof TimeoutError) {
|
|
219
|
-
|
|
220
|
-
} else if (e instanceof UniqueConstraintError) {
|
|
221
|
-
|
|
222
|
-
} else if (e instanceof ForeignKeyConstraintError) {
|
|
223
|
-
|
|
224
|
-
} else if (e instanceof ExclusionConstraintError) {
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
throw new Exception(e.message, this.errors, e.code);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return result;
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
public async bulkCreate(params = {}, options = {}) {
|
|
235
|
-
// now instantiate an object
|
|
236
|
-
let p = Object.assign(params, this._attributes)
|
|
237
|
-
let result: any;
|
|
238
|
-
try {
|
|
239
|
-
result = await this.model().bulkCreate(p, options)
|
|
240
|
-
} catch (e) {
|
|
241
|
-
BaseChyz.debug(`Model[${this.constructor.name}].bulkCreate`, e)
|
|
242
|
-
if (e instanceof ValidationError) {
|
|
243
|
-
let validationErrorItems = e.errors;
|
|
244
|
-
validationErrorItems.forEach(({message, path}) => {
|
|
245
|
-
// @ts-ignore
|
|
246
|
-
this._errors[path] = message
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
return false;
|
|
250
|
-
} else if (e instanceof DatabaseError) {
|
|
251
|
-
|
|
252
|
-
} else if (e instanceof TimeoutError) {
|
|
253
|
-
|
|
254
|
-
} else if (e instanceof UniqueConstraintError) {
|
|
255
|
-
|
|
256
|
-
} else if (e instanceof ForeignKeyConstraintError) {
|
|
257
|
-
|
|
258
|
-
} else if (e instanceof ExclusionConstraintError) {
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
throw new Exception(e.message, this.errors, e.code);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return result;
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
public update(params = {}, options = {}) {
|
|
269
|
-
let p = Object.assign(params, this._attributes)
|
|
270
|
-
return this.model().update(p, options)
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
public delete(params = {}, options = {}) {
|
|
274
|
-
let p = Object.assign(params, this._attributes)
|
|
275
|
-
return this.model().delete(p, options)
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
*
|
|
280
|
-
* @param args
|
|
281
|
-
*/
|
|
282
|
-
public findOne(...args: any[]) {
|
|
283
|
-
return this._model.findOne(...arguments)
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
*
|
|
288
|
-
* @param args
|
|
289
|
-
*/
|
|
290
|
-
public findAll(...args: any[]) {
|
|
291
|
-
return this._model.findAll(...arguments)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
public validate() {
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
*
|
|
301
|
-
* @param data
|
|
302
|
-
* @param formName
|
|
303
|
-
*/
|
|
304
|
-
public load(data: any, formName: any = null) {
|
|
305
|
-
let scope = formName === null ? this.formName() : formName;
|
|
306
|
-
if (scope === '' && !Utils.isEmpty(data)) {
|
|
307
|
-
this.setAttribute(data);
|
|
308
|
-
return true;
|
|
309
|
-
} else if (data[scope]) {
|
|
310
|
-
this.setAttribute(data[scope]);
|
|
311
|
-
return true;
|
|
312
|
-
}
|
|
313
|
-
return false;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
public bulkLoad(data: any, formName: any = null) {
|
|
317
|
-
let scope = formName === null ? this.formName() : formName;
|
|
318
|
-
if (scope === '' && !Utils.isEmpty(data)) {
|
|
319
|
-
this.setAttribute(data);
|
|
320
|
-
return true;
|
|
321
|
-
} else if (data[scope]) {
|
|
322
|
-
this.setAttribute(data[scope]);
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
public setAttribute(values: any, safeOnly = true) {
|
|
329
|
-
if (values instanceof Object) {
|
|
330
|
-
let attributes = this.attributes();
|
|
331
|
-
for (const valueKey in values) {
|
|
332
|
-
if (Object.keys(attributes).indexOf(valueKey) != -1) {
|
|
333
|
-
// @ts-ignore
|
|
334
|
-
BaseChyz.debug("Model[" + this.formName() + "] attributes value set ", valueKey, values[valueKey])
|
|
335
|
-
this._attributes[valueKey] = values[valueKey];
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
public attributes() {
|
|
342
|
-
return {}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* relation return array
|
|
347
|
-
* [
|
|
348
|
-
*
|
|
349
|
-
* ]
|
|
350
|
-
*/
|
|
351
|
-
public relations():Relation[]{
|
|
352
|
-
return []
|
|
353
|
-
}
|
|
354
|
-
}
|
|
@@ -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: string) {
|
|
12
|
-
super(message,404);
|
|
13
|
-
}
|
|
14
|
-
}
|
package/base/RestClient.ts
DELETED
|
@@ -1,28 +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
|
-
|
|
11
|
-
import {Component} from "./Component";
|
|
12
|
-
|
|
13
|
-
const axios = require('axios')
|
|
14
|
-
|
|
15
|
-
export class RestClient extends Component {
|
|
16
|
-
public post(url: string, args: any[]) {
|
|
17
|
-
return axios.post(url, args)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public get(url: string, args: any[]) {
|
|
21
|
-
return axios.post(url, args)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public Rest(params: any) {
|
|
25
|
-
return axios(params)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export default new RestClient();
|
|
@@ -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: string) {
|
|
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: string) {
|
|
12
|
-
super(message,401);
|
|
13
|
-
}
|
|
14
|
-
}
|
package/base/db/Exception.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {BaseError} from "../BaseError";
|
|
2
|
-
|
|
3
|
-
export class Exception extends BaseError {
|
|
4
|
-
public errorInfo = [];
|
|
5
|
-
private 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,16 +0,0 @@
|
|
|
1
|
-
export * from "./ActionFilter"
|
|
2
|
-
export * from "./BaseObject"
|
|
3
|
-
export * from "./BaseError"
|
|
4
|
-
export * from "./Behavior"
|
|
5
|
-
export * from "./Component"
|
|
6
|
-
export * from "./Configurable"
|
|
7
|
-
export * from "./Controller"
|
|
8
|
-
export * from "./DbConnection"
|
|
9
|
-
export * from "./ForbiddenHttpException"
|
|
10
|
-
export * from "./InvalidConfigException"
|
|
11
|
-
export * from "./NotFoundHttpException"
|
|
12
|
-
export * from "./UnauthorizedHttpException"
|
|
13
|
-
export * from "./DataErrorDbException"
|
|
14
|
-
export * from "./ValidationHttpException"
|
|
15
|
-
export * from "./Model"
|
|
16
|
-
export * from "./RestClient"
|
package/decorator/Middleware.ts
DELETED
|
@@ -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
|
-
}
|
package/decorator/controller.ts
DELETED
|
@@ -1,22 +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
|
-
// @ts-ignore
|
|
9
|
-
import "reflect-metadata";
|
|
10
|
-
export const controller = (prefix: string = ''): ClassDecorator => {
|
|
11
|
-
return (target: any) => {
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
Reflect.defineMetadata('prefix', prefix, target);
|
|
14
|
-
|
|
15
|
-
// Since routes are set by our methods this should almost never be true (except the controller has no methods)
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
if (! Reflect.hasMetadata('routes', target)) {
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
Reflect.defineMetadata('routes', [], target);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
};
|
package/decorator/get.ts
DELETED
|
@@ -1,37 +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
|
-
import "reflect-metadata";
|
|
9
|
-
import {RouteDefinition} from '../model/RouteDefinition';
|
|
10
|
-
|
|
11
|
-
export const get = (path: string): MethodDecorator => {
|
|
12
|
-
// `target` equals our class, `propertyKey` equals our decorated method name
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
return (target, propertyKey: string): void => {
|
|
15
|
-
// In case this is the first route to be registered the `routes` metadata is likely to be undefined at this point.
|
|
16
|
-
// To prevent any further validation simply set it to an empty array here.
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
if (!Reflect.hasMetadata('routes', target.constructor)) {
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
Reflect.defineMetadata('routes', [], target.constructor);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Get the routes stored so far, extend it by the new route and re-set the metadata.
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
const routes = Reflect.getMetadata('routes', target.constructor) as Array<RouteDefinition>;
|
|
26
|
-
|
|
27
|
-
routes.push({
|
|
28
|
-
id:"",
|
|
29
|
-
requestMethod: 'get',
|
|
30
|
-
path,
|
|
31
|
-
methodName: propertyKey
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
Reflect.defineMetadata('routes', routes, target.constructor);
|
|
36
|
-
};
|
|
37
|
-
};
|
package/decorator/index.ts
DELETED
package/decorator/post.ts
DELETED
|
@@ -1,36 +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
|
-
import "reflect-metadata";
|
|
9
|
-
import {RouteDefinition} from '../model/RouteDefinition';
|
|
10
|
-
|
|
11
|
-
export const post = (path: string): MethodDecorator => {
|
|
12
|
-
// `target` equals our class, `propertyKey` equals our decorated method name
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
return (target, propertyKey: string): void => {
|
|
15
|
-
// In case this is the first route to be registered the `routes` metadata is likely to be undefined at this point.
|
|
16
|
-
// To prevent any further validation simply set it to an empty array here.
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
if (!Reflect.hasMetadata('routes', target.constructor)) {
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
Reflect.defineMetadata('routes', [], target.constructor);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Get the routes stored so far, extend it by the new route and re-set the metadata.
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
const routes = Reflect.getMetadata('routes', target.constructor) as Array<RouteDefinition>;
|
|
26
|
-
|
|
27
|
-
routes.push({
|
|
28
|
-
id:"",
|
|
29
|
-
requestMethod: 'post',
|
|
30
|
-
path,
|
|
31
|
-
methodName: propertyKey
|
|
32
|
-
});
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
Reflect.defineMetadata('routes', routes, target.constructor);
|
|
35
|
-
};
|
|
36
|
-
};
|