chyz 1.0.13-rc.20 → 1.0.13-rc.6
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 +4 -19
- package/Examples/Controllers/ApiController.ts +22 -22
- package/Examples/Controllers/SiteController.ts +8 -18
- package/Examples/Models/Categories.ts +2 -1
- package/Examples/Models/KeycloakUser.ts +0 -4
- package/Examples/Models/User.ts +1 -8
- package/Examples/index.ts +0 -5
- package/Examples/log/app.log +0 -4322
- package/Examples/log/errors.log +0 -458
- package/README.md +12 -265
- package/base/ActionFilter.ts +1 -1
- package/base/BaseError.ts +1 -3
- package/base/Model.ts +29 -43
- package/base/ModelManager.ts +1 -6
- package/base/RestClient.ts +4 -4
- package/base/ValidationHttpException.ts +1 -1
- package/base/index.ts +0 -1
- package/dist/BaseChyz.js +4 -17
- package/dist/BaseChyz.js.map +1 -1
- package/dist/base/ActionFilter.js +1 -1
- package/dist/base/ActionFilter.js.map +1 -1
- package/dist/base/BaseError.js +1 -5
- package/dist/base/BaseError.js.map +1 -1
- package/dist/base/Model.js +2 -12
- package/dist/base/Model.js.map +1 -1
- package/dist/base/ModelManager.js +8 -0
- package/dist/base/ModelManager.js.map +1 -1
- package/dist/base/RestClient.js +4 -4
- package/dist/base/RestClient.js.map +1 -1
- package/dist/base/ValidationHttpException.js +1 -1
- package/dist/base/index.js +0 -1
- package/dist/base/index.js.map +1 -1
- package/dist/filters/AccessControl.js +3 -15
- package/dist/filters/AccessControl.js.map +1 -1
- package/dist/filters/AccessRule.js +38 -99
- package/dist/filters/AccessRule.js.map +1 -1
- package/dist/filters/auth/HttpBasicAuth.js +0 -65
- package/dist/filters/auth/HttpBasicAuth.js.map +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -1
- package/dist/filters/auth/index.js +0 -1
- package/dist/filters/auth/index.js.map +1 -1
- package/dist/package.json +5 -4
- package/dist/web/WebUser.js +0 -78
- package/dist/web/WebUser.js.map +1 -1
- package/filters/AccessControl.ts +6 -19
- package/filters/AccessRule.ts +16 -61
- package/filters/auth/HttpBasicAuth.ts +0 -68
- package/filters/auth/JwtHttpBearerAuth.ts +1 -1
- package/filters/auth/index.ts +0 -1
- package/package.json +5 -4
- package/web/IdentityInterface.ts +0 -6
- package/web/WebUser.ts +1 -88
- package/Doc/Moel kullanma.md +0 -13
- package/Examples/Controllers/BasicApiController.ts +0 -121
- package/Examples/Models/AuthAssignment.ts +0 -50
- package/Examples/Models/AuthItem.ts +0 -59
- package/Examples/Models/AuthItemChild.ts +0 -49
- package/base/InvalidArgumentException.ts +0 -16
- package/dist/base/InvalidArgumentException.js +0 -18
- package/dist/base/InvalidArgumentException.js.map +0 -1
- package/dist/rbac/AuthAssignment.js +0 -45
- package/dist/rbac/AuthAssignment.js.map +0 -1
- package/dist/rbac/AuthItem.js +0 -52
- package/dist/rbac/AuthItem.js.map +0 -1
- package/dist/rbac/AuthItemChild.js +0 -44
- package/dist/rbac/AuthItemChild.js.map +0 -1
- package/dist/rbac/AuthManager.js +0 -359
- package/dist/rbac/AuthManager.js.map +0 -1
- package/rbac/AuthAssignment.ts +0 -50
- package/rbac/AuthItem.ts +0 -57
- package/rbac/AuthItemChild.ts +0 -50
- package/rbac/AuthManager.ts +0 -398
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ Klasör Yapısı<br>
|
|
|
8
8
|
*---Controllers <br>
|
|
9
9
|
*---Models<br>
|
|
10
10
|
*---Log<br>
|
|
11
|
+
*---Framework<br>
|
|
11
12
|
index.ts<br>
|
|
12
13
|
|
|
13
14
|
`##Başlangıç<br>
|
|
@@ -16,23 +17,15 @@ yarn start
|
|
|
16
17
|
## index.ts alanlar düzenlenmeli.
|
|
17
18
|
|
|
18
19
|
```typescript
|
|
19
|
-
|
|
20
|
-
import {BaseChyz} from "../index";
|
|
21
|
-
|
|
22
20
|
require('dotenv-flow').config();
|
|
23
|
-
import Chyz ,{ DbConnection, BaseChyz} from "chyz/dist/";
|
|
24
|
-
import {AuthManager} from "chyz/dist/rbac/AuthManager"
|
|
25
|
-
import {WebUser} from "chyz/dist/web/WebUser";
|
|
26
|
-
import {User as Identity} from "./Models/User";
|
|
27
21
|
|
|
22
|
+
import BaseChyz from "chyz/dist/BaseChyz";
|
|
23
|
+
import Chyz, {DbConnection} from "chyz/dist";
|
|
24
|
+
import {WebUser} from "../web/WebUser";
|
|
25
|
+
import {User} from "./Models/User";
|
|
28
26
|
|
|
29
27
|
let config = {
|
|
30
|
-
port: process.env.PORT || 8870,
|
|
31
|
-
controllerpath: "Examples\\Controllers",
|
|
32
28
|
components: {
|
|
33
|
-
authManager: {
|
|
34
|
-
class: AuthManager,
|
|
35
|
-
},
|
|
36
29
|
db: {
|
|
37
30
|
class: DbConnection,
|
|
38
31
|
database: process.env.DBDATABASE,
|
|
@@ -42,7 +35,7 @@ let config = {
|
|
|
42
35
|
host: process.env.DBHOST,
|
|
43
36
|
dialect: 'postgres', /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
|
|
44
37
|
// disable logging; default: console.log
|
|
45
|
-
logging:
|
|
38
|
+
logging: false
|
|
46
39
|
}
|
|
47
40
|
},
|
|
48
41
|
user: {
|
|
@@ -50,168 +43,14 @@ let config = {
|
|
|
50
43
|
'identityClass': User
|
|
51
44
|
}
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
}
|
|
55
47
|
Chyz.app(config).Start();
|
|
56
48
|
```
|
|
57
49
|
|
|
58
|
-
##Controller
|
|
59
|
-
Basit şekilde kontroller oluşturulabilir.
|
|
60
|
-
```typescript
|
|
61
|
-
/*
|
|
62
|
-
*
|
|
63
|
-
* Copyright (c) 2021-2021.. Chy Bilgisayar Bilisim
|
|
64
|
-
* Author: Cihan Ozturk
|
|
65
|
-
* E-mail: cihan@chy.com.tr
|
|
66
|
-
* Github:https://github.com/cihan53/
|
|
67
|
-
*
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
import {AccessControl, BaseChyz, JwtHttpBearerAuth, ModelManager, Request, Response,} from "chyz/dist";
|
|
71
|
-
import {ForbiddenHttpException, Model, NotFoundHttpException, ValidationHttpException} from "chyz/dist/base";
|
|
72
|
-
|
|
73
|
-
import Utils from 'chyz/dist/requiments/Utils';
|
|
74
|
-
import {controller, get, post} from "chyz/dist/decorator";
|
|
75
|
-
import {Controller} from "chyz/dist/base/Controller";
|
|
76
|
-
import * as Util from "util";
|
|
77
|
-
import {uid} from "uid";
|
|
78
|
-
|
|
79
|
-
import {User} from "../Models/User";
|
|
80
|
-
import {AuthManager} from "../Lib/AuthManager";
|
|
81
|
-
import {CategoriesClass} from "../Models/Categories";
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const keygen = require('ssh-keygen');
|
|
85
|
-
const os = require('os');
|
|
86
|
-
const bcrypt = require('bcrypt');
|
|
87
|
-
const JsonWebToken = require("jsonwebtoken");
|
|
88
|
-
const {Op} = require("sequelize");
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
@controller("/api")
|
|
92
|
-
class ApiController extends Controller {
|
|
93
|
-
|
|
94
|
-
public myCheck(token) {
|
|
95
|
-
console.log("myyyyyyyyyyyyyyyyyyyyy")
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public behaviors(): any[] {
|
|
99
|
-
|
|
100
|
-
return [{
|
|
101
|
-
'authenticator': {
|
|
102
|
-
"class": JwtHttpBearerAuth,
|
|
103
|
-
// "auth": this.myCheck
|
|
104
|
-
},
|
|
105
|
-
'access': {
|
|
106
|
-
'class': AccessControl,
|
|
107
|
-
'only': ['order/list' ],
|
|
108
|
-
'rules': [
|
|
109
|
-
|
|
110
|
-
{
|
|
111
|
-
'allow': true,
|
|
112
|
-
'actions': ['order/list' ],
|
|
113
|
-
'roles': ['editor'],
|
|
114
|
-
}
|
|
115
|
-
]
|
|
116
|
-
}
|
|
117
|
-
}]
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@get("/")
|
|
121
|
-
Index(req: Request, res: Response) {
|
|
122
|
-
|
|
123
|
-
BaseChyz.logs().info("Site Controller Burası", this.id)
|
|
124
|
-
return res.json({message: "index sayfası"})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
@post("orderCreate")
|
|
128
|
-
async Login(req: Request, res: Response) {
|
|
129
|
-
let data = req.body;
|
|
130
|
-
data.Customer.status = "true";
|
|
131
|
-
|
|
132
|
-
//Customer Model Create
|
|
133
|
-
let customer = ModelManager.Customer.save();
|
|
134
|
-
//Order Model Create
|
|
135
|
-
let order = ModelManager.Order;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
let transaction
|
|
139
|
-
try {
|
|
140
|
-
// get transaction
|
|
141
|
-
transaction = await BaseChyz.getComponent("db").transaction();
|
|
142
|
-
customer.load(data, "Customer");//load customer data
|
|
143
|
-
let cus: any = await customer.save({}, {transaction});
|
|
144
|
-
|
|
145
|
-
if (!cus) {
|
|
146
|
-
throw new ValidationHttpException(customer.errors);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
data.Order.customer_id = cus.id;
|
|
150
|
-
|
|
151
|
-
order.load(data, "Order");
|
|
152
|
-
let res1 = await order.save({}, {transaction});
|
|
153
|
-
if (!res1) {
|
|
154
|
-
throw new ValidationHttpException(order.errors);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// commit
|
|
158
|
-
await transaction.commit();
|
|
159
|
-
|
|
160
|
-
} catch (e) {
|
|
161
|
-
if (transaction) {
|
|
162
|
-
await transaction.rollback();
|
|
163
|
-
BaseChyz.warn("Rollback transaction")
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (e instanceof ValidationHttpException)
|
|
167
|
-
throw new ValidationHttpException(e.message)
|
|
168
|
-
else
|
|
169
|
-
throw new ForbiddenHttpException(e.message)
|
|
170
|
-
}
|
|
171
|
-
return res.send("Post Controller")
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
@get("order/list")
|
|
176
|
-
async listOrder(req: Request, res: Response) {
|
|
177
|
-
const {Products}: { Products: ProductsClass } = ModelManager;
|
|
178
|
-
let product = await Products.findAll( );
|
|
179
|
-
return res.json(product)
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
@get("categories")
|
|
184
|
-
async Categories(req: Request, res: Response) {
|
|
185
|
-
let product = await ModelManager.Categories.findAll({
|
|
186
|
-
include: [
|
|
187
|
-
{
|
|
188
|
-
model: ModelManager.Products.model(),
|
|
189
|
-
}
|
|
190
|
-
]
|
|
191
|
-
});
|
|
192
|
-
return res.json(product)
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
error(req: Request, res: Response) {
|
|
197
|
-
BaseChyz.logs().info("Error Sayfası")
|
|
198
|
-
return res.send("Post Controller")
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
module.exports = ApiController
|
|
203
|
-
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
|
|
207
50
|
## Create Model
|
|
208
51
|
|
|
209
52
|
Veritabanı işlemleri için model oluşturma, sequelize desteklidir.
|
|
210
53
|
|
|
211
|
-
Model adı "**Class**" şeklinde bitmeli.
|
|
212
|
-
|
|
213
|
-
Örnek = "ModelName**Class**"
|
|
214
|
-
|
|
215
54
|
```typescript
|
|
216
55
|
import {Model, DataTypes} from "chyz/base/Model";
|
|
217
56
|
|
|
@@ -251,7 +90,6 @@ export class CustomerCLass extends Model {
|
|
|
251
90
|
|
|
252
91
|
```
|
|
253
92
|
````typescript
|
|
254
|
-
|
|
255
93
|
export class ProductsClass extends Model {
|
|
256
94
|
[x: string]: any;
|
|
257
95
|
|
|
@@ -290,48 +128,6 @@ export class ProductsClass extends Model {
|
|
|
290
128
|
}
|
|
291
129
|
}
|
|
292
130
|
|
|
293
|
-
/**
|
|
294
|
-
*
|
|
295
|
-
*/
|
|
296
|
-
export class CategoriesClass extends Model {
|
|
297
|
-
[x: string]: any;
|
|
298
|
-
|
|
299
|
-
alias() {
|
|
300
|
-
return "c"
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
tableName() {
|
|
304
|
-
return 'categories';
|
|
305
|
-
}
|
|
306
|
-
attributes() {
|
|
307
|
-
return {
|
|
308
|
-
// Model attributes are defined here
|
|
309
|
-
title: {
|
|
310
|
-
type: DataTypes.STRING,
|
|
311
|
-
allowNull: false
|
|
312
|
-
},
|
|
313
|
-
properties: {
|
|
314
|
-
type: DataTypes.STRING,
|
|
315
|
-
allowNull: false
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
relations(): Relation[] {
|
|
321
|
-
return [
|
|
322
|
-
{
|
|
323
|
-
type: "belongsToMany",
|
|
324
|
-
foreignKey: "category_id",
|
|
325
|
-
sourceKey: "id",
|
|
326
|
-
as: 'product',
|
|
327
|
-
model: ModelManager.Products.model(),
|
|
328
|
-
through: ModelManager.ProductToCategories.model()
|
|
329
|
-
}
|
|
330
|
-
]
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
|
|
335
131
|
|
|
336
132
|
````
|
|
337
133
|
|
|
@@ -350,11 +146,9 @@ export class CategoriesClass extends Model {
|
|
|
350
146
|
* }
|
|
351
147
|
* @type {Customer}
|
|
352
148
|
*/
|
|
353
|
-
import { ModelManager} from "chyz/dist";
|
|
354
149
|
import {Customer} from "./Customer";
|
|
355
|
-
|
|
356
150
|
//Customer Model Create
|
|
357
|
-
let customer: Customer =
|
|
151
|
+
let customer: Customer = Customer;
|
|
358
152
|
customer.load(req.body, "Customer");//load customer data
|
|
359
153
|
let cus: any = await customer.save();
|
|
360
154
|
|
|
@@ -370,7 +164,7 @@ Transaction oluşturma
|
|
|
370
164
|
// get transaction
|
|
371
165
|
transaction = await BaseChyz.getComponent("db").transaction();
|
|
372
166
|
//Customer Model Create
|
|
373
|
-
let customer: Customer =
|
|
167
|
+
let customer: Customer = new Customer();
|
|
374
168
|
customer.load(data, "Customer");//load customer data
|
|
375
169
|
let cus: any = await customer.save({}, {transaction});
|
|
376
170
|
if (!cus) {
|
|
@@ -379,9 +173,9 @@ Transaction oluşturma
|
|
|
379
173
|
} catch (e) {
|
|
380
174
|
if (transaction) {
|
|
381
175
|
await transaction.rollback();
|
|
382
|
-
BaseChyz.warn("Rollback transaction")
|
|
176
|
+
BaseChyz.warn("Rollback transaction")
|
|
383
177
|
}
|
|
384
|
-
|
|
178
|
+
...
|
|
385
179
|
}
|
|
386
180
|
```
|
|
387
181
|
|
|
@@ -423,44 +217,6 @@ export class User extends Model implements IdentityInterface {
|
|
|
423
217
|
throw new Error("Method not implemented.");
|
|
424
218
|
}
|
|
425
219
|
|
|
426
|
-
/**
|
|
427
|
-
* Returns auth manager associated with the user component.
|
|
428
|
-
*
|
|
429
|
-
* By default this is the `authManager` application component.
|
|
430
|
-
* You may override this method to return a different auth manager instance if needed.
|
|
431
|
-
*/
|
|
432
|
-
protected getAuthManager() {
|
|
433
|
-
return BaseChyz.getComponent("authManager");
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Returns the access checker used for checking access.
|
|
438
|
-
* @return CheckAccessInterface
|
|
439
|
-
*/
|
|
440
|
-
protected getAccessChecker() {
|
|
441
|
-
return this.accessChecker !== null ? this.accessChecker : this.getAuthManager();
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
*
|
|
446
|
-
* @param permissionName
|
|
447
|
-
* @param params
|
|
448
|
-
* @param allowCaching
|
|
449
|
-
*/
|
|
450
|
-
public async can(permissionName, params: any[] = [], allowCaching: boolean = true) {
|
|
451
|
-
let accessChecker;
|
|
452
|
-
if ((accessChecker = this.getAccessChecker()) === null) {
|
|
453
|
-
return false;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
let access = await accessChecker.checkAccess(this.getId(), permissionName, params);
|
|
457
|
-
this._access[permissionName] = access;
|
|
458
|
-
if (allowCaching && Utils.isEmpty(params)) {
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
return access;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
220
|
public attributes() {
|
|
465
221
|
return {
|
|
466
222
|
// Model attributes are defined here
|
|
@@ -484,25 +240,16 @@ export class User extends Model implements IdentityInterface {
|
|
|
484
240
|
}
|
|
485
241
|
|
|
486
242
|
async findIdentityByAccessToken(token, type) {
|
|
487
|
-
|
|
488
|
-
|
|
489
243
|
let decoded = JsonWebToken.decode(token, {complete: true})
|
|
490
|
-
if (!decoded.payload.user) {
|
|
491
|
-
return null;
|
|
492
|
-
}
|
|
493
244
|
let identity = await this.findOne({where: {id: parseInt(decoded.payload.user)}});
|
|
494
245
|
if(identity){
|
|
495
246
|
BaseChyz.debug("Find Identity By AccessToken: User Found", decoded.payload)
|
|
496
247
|
try {
|
|
497
248
|
JsonWebToken.verify(token, identity.salt_text);
|
|
498
|
-
this.setIdentity(identity);
|
|
499
249
|
BaseChyz.debug("Find Identity By AccessToken: User Verify Success")
|
|
500
|
-
return
|
|
250
|
+
return identity;
|
|
501
251
|
} catch(err) {
|
|
502
|
-
|
|
503
|
-
BaseChyz.debug("Find Identity By AccessToken: Token Expired")
|
|
504
|
-
else
|
|
505
|
-
BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
|
|
252
|
+
BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
|
|
506
253
|
return null;
|
|
507
254
|
}
|
|
508
255
|
}
|
package/base/ActionFilter.ts
CHANGED
package/base/BaseError.ts
CHANGED
|
@@ -5,14 +5,12 @@
|
|
|
5
5
|
* Github:https://github.com/cihan53/
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import Utils from "../requiments/Utils";
|
|
9
|
-
|
|
10
8
|
export class BaseError extends Error {
|
|
11
9
|
private statusCode: number;
|
|
12
10
|
|
|
13
11
|
constructor(message: string,statusCode=500) {
|
|
14
12
|
super(message);
|
|
15
|
-
this.message=
|
|
13
|
+
this.message=message;
|
|
16
14
|
this.name = this.constructor.name // good practice
|
|
17
15
|
this.statusCode = statusCode // error code for responding to client
|
|
18
16
|
Error.captureStackTrace(this)
|
package/base/Model.ts
CHANGED
|
@@ -14,15 +14,15 @@ import {Exception} from "./db/Exception";
|
|
|
14
14
|
|
|
15
15
|
export {DataTypes, NOW} from "sequelize";
|
|
16
16
|
|
|
17
|
-
export interface Relation
|
|
18
|
-
type:
|
|
19
|
-
allowNull?:
|
|
20
|
-
sourceKey
|
|
21
|
-
model:
|
|
22
|
-
foreignKey:
|
|
23
|
-
name?:
|
|
24
|
-
through?:
|
|
25
|
-
as?:
|
|
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?:any,
|
|
25
|
+
as?:string
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -80,8 +80,7 @@ export interface Relation {
|
|
|
80
80
|
*/
|
|
81
81
|
|
|
82
82
|
export class Model extends Component {
|
|
83
|
-
_sequelize: any;
|
|
84
|
-
_register: any;
|
|
83
|
+
_sequelize: any ;
|
|
85
84
|
private _tableName: string;
|
|
86
85
|
private _model: any;
|
|
87
86
|
private _attributes: any = {};
|
|
@@ -90,7 +89,7 @@ export class Model extends Component {
|
|
|
90
89
|
|
|
91
90
|
constructor(sequelize?: IDBDatabase) {
|
|
92
91
|
super();
|
|
93
|
-
this._tableName = this.
|
|
92
|
+
this._tableName = this.constructor.name;
|
|
94
93
|
// this._sequelize = BaseChyz.getComponent("db").db;
|
|
95
94
|
if (sequelize != null)
|
|
96
95
|
this._sequelize = sequelize;
|
|
@@ -98,14 +97,17 @@ export class Model extends Component {
|
|
|
98
97
|
this._sequelize = BaseChyz.getComponent("db").db;
|
|
99
98
|
|
|
100
99
|
if (!Utils.isEmpty(this.attributes())) {
|
|
101
|
-
|
|
102
|
-
this._model = this._sequelize.define(this._tableName, this.attributes(), {
|
|
100
|
+
this._model = this._sequelize.define(this.constructor.name, this.attributes(), {
|
|
103
101
|
tableName: this.tableName(),
|
|
104
102
|
timestamps: false,
|
|
105
103
|
createdAt: false,
|
|
106
|
-
updateAt:
|
|
104
|
+
updateAt:false
|
|
107
105
|
});
|
|
108
106
|
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
109
111
|
} else {
|
|
110
112
|
throw new InvalidConfigException(BaseChyz.t("Invalid model configuration, is not emty attributes"))
|
|
111
113
|
}
|
|
@@ -121,7 +123,8 @@ export class Model extends Component {
|
|
|
121
123
|
* You may override this method if you want to use a different database connection.
|
|
122
124
|
* @return Connection the database connection used by this AR class.
|
|
123
125
|
*/
|
|
124
|
-
public static getDb()
|
|
126
|
+
public static getDb()
|
|
127
|
+
{
|
|
125
128
|
return BaseChyz.getComponent("db").db
|
|
126
129
|
}
|
|
127
130
|
|
|
@@ -154,38 +157,34 @@ export class Model extends Component {
|
|
|
154
157
|
for (const relation of this.relations()) {
|
|
155
158
|
let m = relation.model;
|
|
156
159
|
|
|
157
|
-
if
|
|
160
|
+
if(relation.type=="hasOne" ){
|
|
158
161
|
// @ts-ignore
|
|
159
162
|
delete relation.model
|
|
160
|
-
this.model().hasOne(m, relation);
|
|
163
|
+
this.model().hasOne(m, relation );
|
|
161
164
|
}
|
|
162
|
-
|
|
163
|
-
if
|
|
165
|
+
//
|
|
166
|
+
if(relation.type=="hasMany" ){
|
|
164
167
|
// @ts-ignore
|
|
165
168
|
delete relation.model;
|
|
166
|
-
this.model().hasMany(m, relation);
|
|
169
|
+
this.model().hasMany(m, relation );
|
|
167
170
|
}
|
|
168
171
|
|
|
169
|
-
if
|
|
172
|
+
if(relation.type=="belongsTo" ){
|
|
170
173
|
// @ts-ignore
|
|
171
174
|
delete relation.model;
|
|
172
|
-
this.model().belongsTo(m, relation);
|
|
175
|
+
this.model().belongsTo(m, relation );
|
|
173
176
|
}
|
|
174
177
|
|
|
175
|
-
if
|
|
178
|
+
if(relation.type=="belongsToMany" ){
|
|
176
179
|
// @ts-ignore
|
|
177
180
|
delete relation.model;
|
|
178
|
-
this.model().belongsToMany(m, relation);
|
|
181
|
+
this.model().belongsToMany(m, relation );
|
|
179
182
|
}
|
|
180
183
|
}
|
|
181
184
|
|
|
182
185
|
}
|
|
183
186
|
|
|
184
187
|
|
|
185
|
-
public alias() {
|
|
186
|
-
return this.constructor.name;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
188
|
public tableName() {
|
|
190
189
|
return this._tableName;
|
|
191
190
|
}
|
|
@@ -296,15 +295,6 @@ export class Model extends Component {
|
|
|
296
295
|
return this._model.findAll(...arguments)
|
|
297
296
|
}
|
|
298
297
|
|
|
299
|
-
/**
|
|
300
|
-
* return {count : number , rows: any}
|
|
301
|
-
* @param args
|
|
302
|
-
*/
|
|
303
|
-
public findAndCountAll(...args: any[]) {
|
|
304
|
-
return this._model.findAndCountAll(...arguments)
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
298
|
|
|
309
299
|
public validate() {
|
|
310
300
|
|
|
@@ -362,11 +352,7 @@ export class Model extends Component {
|
|
|
362
352
|
*
|
|
363
353
|
* ]
|
|
364
354
|
*/
|
|
365
|
-
public relations():
|
|
355
|
+
public relations():Relation[]{
|
|
366
356
|
return []
|
|
367
357
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
358
|
}
|
package/base/ModelManager.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {Model} from "./Model"
|
|
2
|
-
|
|
3
1
|
/*
|
|
4
2
|
*
|
|
5
3
|
* Copyright (c) 2021.. Chy Bilgisayar Bilisim
|
|
@@ -8,12 +6,9 @@ import {Model} from "./Model"
|
|
|
8
6
|
* Github:https://github.com/cihan53/
|
|
9
7
|
*
|
|
10
8
|
*/
|
|
11
|
-
interface ObjectConstructor {
|
|
12
|
-
_register(o: Model): void;
|
|
13
|
-
}
|
|
14
9
|
|
|
15
10
|
export const ModelManager: any = {
|
|
16
|
-
_register(map:
|
|
11
|
+
_register(map: any) {
|
|
17
12
|
Object.assign(this, map)
|
|
18
13
|
}
|
|
19
14
|
}
|
package/base/RestClient.ts
CHANGED
|
@@ -13,12 +13,12 @@ import {Component} from "./Component";
|
|
|
13
13
|
const axios = require('axios')
|
|
14
14
|
|
|
15
15
|
export class RestClient extends Component {
|
|
16
|
-
public post(url: string, args: any[]
|
|
17
|
-
return axios.post(url, args
|
|
16
|
+
public post(url: string, args: any[]) {
|
|
17
|
+
return axios.post(url, args)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
public get(url: string, args: any[]
|
|
21
|
-
return axios.post(url, args
|
|
20
|
+
public get(url: string, args: any[]) {
|
|
21
|
+
return axios.post(url, args)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
public Rest(params: any) {
|
package/base/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ export * from "./Controller"
|
|
|
8
8
|
export * from "./DbConnection"
|
|
9
9
|
export * from "./ForbiddenHttpException"
|
|
10
10
|
export * from "./InvalidConfigException"
|
|
11
|
-
export * from "./InvalidArgumentException"
|
|
12
11
|
export * from "./NotFoundHttpException"
|
|
13
12
|
export * from "./UnauthorizedHttpException"
|
|
14
13
|
export * from "./DataErrorDbException"
|
package/dist/BaseChyz.js
CHANGED
|
@@ -18,7 +18,6 @@ const base_1 = require("./base");
|
|
|
18
18
|
const express = require("express");
|
|
19
19
|
const log4js = require("log4js");
|
|
20
20
|
const fs = require('fs');
|
|
21
|
-
const validate = require('validate.js');
|
|
22
21
|
var ip = require('ip');
|
|
23
22
|
var bodyParser = require('body-parser');
|
|
24
23
|
var methodOverride = require('method-override');
|
|
@@ -101,12 +100,6 @@ class BaseChyz {
|
|
|
101
100
|
set port(value) {
|
|
102
101
|
this._port = value;
|
|
103
102
|
}
|
|
104
|
-
static get validate() {
|
|
105
|
-
return this._validate;
|
|
106
|
-
}
|
|
107
|
-
static set validate(value) {
|
|
108
|
-
this._validate = value;
|
|
109
|
-
}
|
|
110
103
|
app(config = {}) {
|
|
111
104
|
var _a;
|
|
112
105
|
/**
|
|
@@ -117,21 +110,16 @@ class BaseChyz {
|
|
|
117
110
|
if (components) {
|
|
118
111
|
for (const componentsKey in components) {
|
|
119
112
|
let comp = components[componentsKey];
|
|
120
|
-
BaseChyz.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
(_a = BaseChyz.components[componentsKey]) === null || _a === void 0 ? void 0 : _a.init();
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
console.error(e);
|
|
127
|
-
}
|
|
113
|
+
BaseChyz.debug("Create Component ", componentsKey);
|
|
114
|
+
BaseChyz.components[componentsKey] = Utils_1.default.createObject(new comp.class, comp);
|
|
115
|
+
(_a = BaseChyz.components[componentsKey]) === null || _a === void 0 ? void 0 : _a.init();
|
|
128
116
|
}
|
|
129
117
|
}
|
|
130
118
|
let middlewares = Utils_1.default.findKeyValue(config, "middlewares");
|
|
131
119
|
if (middlewares) {
|
|
132
120
|
for (const middlewareKey in middlewares) {
|
|
133
121
|
let middleware1 = middlewares[middlewareKey];
|
|
134
|
-
BaseChyz.
|
|
122
|
+
BaseChyz.debug("Create middlewares ", middlewareKey);
|
|
135
123
|
BaseChyz.middlewares[middlewareKey] = middleware1;
|
|
136
124
|
// BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
|
|
137
125
|
}
|
|
@@ -326,7 +314,6 @@ class BaseChyz {
|
|
|
326
314
|
}
|
|
327
315
|
exports.default = BaseChyz;
|
|
328
316
|
BaseChyz.express = express();
|
|
329
|
-
BaseChyz._validate = validate;
|
|
330
317
|
BaseChyz.controllers = [];
|
|
331
318
|
BaseChyz.components = {};
|
|
332
319
|
BaseChyz.middlewares = {};
|