chyz 1.0.12-rc.9 → 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} +45 -8
- package/BaseChyz.js.map +1 -0
- package/{dist/Chyz.js → Chyz.js} +0 -0
- package/{dist/Chyz.js.map → Chyz.js.map} +0 -0
- package/README.md +80 -28
- package/{dist/base → base}/ActionFilter.js +2 -2
- package/base/ActionFilter.js.map +1 -0
- package/{dist/base → base}/BaseError.js +2 -2
- package/base/BaseError.js.map +1 -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 +1 -1
- package/{dist/base → base}/DataErrorDbException.js.map +1 -1
- package/{dist/base → base}/DbConnection.js +0 -0
- package/{dist/base → base}/DbConnection.js.map +0 -0
- package/{dist/base → base}/ForbiddenHttpException.js +1 -1
- package/{dist/base → base}/ForbiddenHttpException.js.map +1 -1
- package/{dist/base → base}/InvalidConfigException.js +1 -1
- package/{dist/base → base}/InvalidConfigException.js.map +1 -1
- package/{dist/base → base}/Model.js +121 -3
- package/base/Model.js.map +1 -0
- package/{dist/base → base}/NotFoundHttpException.js +1 -1
- package/{dist/base → base}/NotFoundHttpException.js.map +1 -1
- package/base/RestClient.js +27 -0
- package/base/RestClient.js.map +1 -0
- package/{dist/base → base}/UnauthorizedHttpException.js +1 -1
- package/{dist/base → base}/UnauthorizedHttpException.js.map +1 -1
- package/{dist/base → base}/ValidationHttpException.js +1 -1
- package/{dist/base → base}/ValidationHttpException.js.map +1 -1
- 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 +2 -0
- package/{dist/base → base}/index.js.map +1 -1
- 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 +2 -2
- package/filters/AccessControl.js.map +1 -0
- package/{dist/filters → filters}/AccessRule.js +0 -0
- package/{dist/filters → filters}/AccessRule.js.map +1 -1
- 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 +2 -2
- package/filters/auth/AuthMethod.js.map +1 -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 +1 -1
- package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js +1 -0
- package/filters/auth/JwtHttpBearerAuth.js.map +1 -0
- package/filters/auth/KeyCloakHttpBearerAuth.js +117 -0
- package/filters/auth/KeyCloakHttpBearerAuth.js.map +1 -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/index.js +28 -0
- package/index.js.map +1 -0
- package/log/config/log4js.json +55 -0
- package/{dist/model → model}/RouteDefinition.js +0 -0
- package/{dist/model → model}/RouteDefinition.js.map +0 -0
- package/package.json +56 -52
- 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/User.js → web/WebUser.js} +12 -7
- package/web/WebUser.js.map +1 -0
- package/BaseChyz.ts +0 -313
- package/Chyz.ts +0 -11
- package/Examples/Controllers/ApiController.ts +0 -121
- package/Examples/Controllers/PublicController.ts +0 -44
- package/Examples/Controllers/SiteController.ts +0 -127
- package/Examples/Models/Customer.ts +0 -113
- package/Examples/Models/Order.ts +0 -48
- package/Examples/Models/OrderItem.ts +0 -26
- package/Examples/Models/User.ts +0 -80
- package/Examples/index.ts +0 -38
- package/Examples/package.json +0 -45
- package/Examples/tsconfig.json +0 -20
- package/Examples/yarn.lock +0 -2202
- 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 -209
- package/base/NotFoundHttpException.ts +0 -14
- package/base/UnauthorizedHttpException.ts +0 -16
- package/base/ValidationHttpException.ts +0 -14
- package/base/db/Exception.ts +0 -14
- package/base/index.ts +0 -14
- 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/BaseChyz.js.map +0 -1
- package/dist/base/ActionFilter.js.map +0 -1
- package/dist/base/BaseError.js.map +0 -1
- package/dist/base/Model.js.map +0 -1
- package/dist/filters/AccessControl.js.map +0 -1
- package/dist/filters/auth/AuthMethod.js.map +0 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js.map +0 -1
- package/dist/web/User.js.map +0 -1
- 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 -81
- package/filters/auth/index.ts +0 -3
- package/filters/index.ts +0 -2
- package/model/RouteDefinition.ts +0 -18
- 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/User.ts +0 -96
package/base/ActionFilter.ts
DELETED
|
@@ -1,71 +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 {NextFunction, Request, Response} from "express";
|
|
9
|
-
import Utils from "../requiments/Utils";
|
|
10
|
-
import {Behavior} from "./Behavior";
|
|
11
|
-
|
|
12
|
-
export class ActionFilter extends Behavior {
|
|
13
|
-
|
|
14
|
-
public only: any;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @var array list of action IDs that this filter should not apply to.
|
|
18
|
-
* @see only
|
|
19
|
-
*/
|
|
20
|
-
public except = [];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
public init() {
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public async beforeFilter(route: any, req: Request, res: Response) {
|
|
28
|
-
if (!this.isActive(route.id)) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
await this.beforeAction(route, req, res)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
protected isActive(action: any) {
|
|
36
|
-
let id = action.id;
|
|
37
|
-
let onlyMatch: boolean = false;
|
|
38
|
-
let exceptMatch: boolean = false;
|
|
39
|
-
if (Utils.isEmpty(this.only)) {
|
|
40
|
-
onlyMatch = true;
|
|
41
|
-
} else {
|
|
42
|
-
onlyMatch = false;
|
|
43
|
-
for (const onlyKey of this.only) {
|
|
44
|
-
if (Utils.matchWildcard(action, onlyKey)) {
|
|
45
|
-
onlyMatch = true;
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
for (const exceptKey in this.except) {
|
|
52
|
-
let pattern = this.except[exceptKey];
|
|
53
|
-
let match = id.match(pattern)
|
|
54
|
-
if (match.length > 0) {
|
|
55
|
-
exceptMatch = true;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return !exceptMatch && onlyMatch;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* This method is invoked right before an action is to be executed (after all possible filters.)
|
|
64
|
-
* You may override this method to do last-minute preparation for the action.
|
|
65
|
-
* @param Action $action the action to be executed.
|
|
66
|
-
* @return bool whether the action should continue to be executed.
|
|
67
|
-
*/
|
|
68
|
-
public async beforeAction(route: any, req: Request, res: Response) {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
}
|
package/base/BaseError.ts
DELETED
|
@@ -1,26 +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
|
-
export class BaseError extends Error {
|
|
9
|
-
private statusCode: number;
|
|
10
|
-
|
|
11
|
-
constructor(message: string) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.message=message;
|
|
14
|
-
this.name = this.constructor.name // good practice
|
|
15
|
-
this.statusCode = 500 // error code for responding to client
|
|
16
|
-
Error.captureStackTrace(this)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
toString(){
|
|
20
|
-
return `${this.name}[${this.statusCode}] ${this.message}`
|
|
21
|
-
}
|
|
22
|
-
toJSON(){
|
|
23
|
-
return {code: this?.statusCode, name: this.name, message: this.message}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
package/base/BaseObject.ts
DELETED
|
@@ -1,19 +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 {Configurable} from "./Configurable";
|
|
9
|
-
import BaseChyz from "../BaseChyz";
|
|
10
|
-
|
|
11
|
-
export class BaseObject implements Configurable {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
public init() {
|
|
15
|
-
|
|
16
|
-
BaseChyz.debug("BaseObject init.....",)
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
}
|
package/base/Behavior.ts
DELETED
package/base/Component.ts
DELETED
|
@@ -1,66 +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 {BaseObject} from "./BaseObject";
|
|
9
|
-
import {ActionFilter} from "./ActionFilter";
|
|
10
|
-
import Utils from "../requiments/Utils";
|
|
11
|
-
|
|
12
|
-
export class Component extends BaseObject {
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @var array the attached event handlers (event name => handlers)
|
|
16
|
-
*/
|
|
17
|
-
private _events = [];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @var Behavior[]|null the attached behaviors (behavior name => behavior). This is `null` when not initialized.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
private _behaviors: Array<ActionFilter> = [];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Returns a list of behaviors that this component should behave as.
|
|
29
|
-
*/
|
|
30
|
-
public behaviors() {
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
get getBehaviors(): any {
|
|
36
|
-
return this._behaviors;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.
|
|
41
|
-
*/
|
|
42
|
-
public ensureBehaviors() {
|
|
43
|
-
if (this._behaviors.length == 0) {
|
|
44
|
-
this._behaviors = [];
|
|
45
|
-
if (this.behaviors().length > 0) {
|
|
46
|
-
this.behaviors().forEach(behavior => {
|
|
47
|
-
Object.keys(behavior).forEach((name: string) => {
|
|
48
|
-
this.attachBehaviorInternal(name, behavior)
|
|
49
|
-
});
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
private attachBehaviorInternal(name: any, behavior: any) {
|
|
58
|
-
if (!this._behaviors.hasOwnProperty(name)) {
|
|
59
|
-
let beh = Utils.createObject(new behavior[name].class, behavior[name])
|
|
60
|
-
beh.init()
|
|
61
|
-
this._behaviors[name] = beh;
|
|
62
|
-
}
|
|
63
|
-
return behavior;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}
|
package/base/Configurable.ts
DELETED
package/base/Controller.ts
DELETED
|
@@ -1,84 +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 {Component} from "./Component";
|
|
9
|
-
import {RouteDefinition} from "../model/RouteDefinition";
|
|
10
|
-
import {Request, Response} from "express";
|
|
11
|
-
|
|
12
|
-
export class Controller extends Component {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @var string the ID of this controller.
|
|
17
|
-
*/
|
|
18
|
-
public id: string;
|
|
19
|
-
public defaultAction = 'index';
|
|
20
|
-
|
|
21
|
-
constructor(config: any) {
|
|
22
|
-
super();
|
|
23
|
-
this.id = this.constructor.name.replace("Controller", "").toLowerCase();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public init() {
|
|
27
|
-
super.init();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* This method is invoked right before an action is executed.
|
|
33
|
-
* @param $action
|
|
34
|
-
*/
|
|
35
|
-
public async beforeAction(route: RouteDefinition, req: Request, res: Response) {
|
|
36
|
-
if (route.id == "" || route.id == "/")
|
|
37
|
-
this.id = this.defaultAction
|
|
38
|
-
|
|
39
|
-
this.ensureBehaviors()
|
|
40
|
-
for (const name of Object.keys(this.getBehaviors)) {
|
|
41
|
-
await this.getBehaviors[name].beforeFilter(route, req, res);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* This method is invoked right after an action is executed.
|
|
48
|
-
* @param action
|
|
49
|
-
*/
|
|
50
|
-
public afterAction(action: any, req: Request, res: Response) {
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
|
|
57
|
-
Checks the privilege of the current user.
|
|
58
|
-
|
|
59
|
-
This method should be overridden to check whether the current user has the privilege to run the specified action against the specified data model. If the user does not have access, a yii\web\ForbiddenHttpException should be thrown.
|
|
60
|
-
|
|
61
|
-
*/
|
|
62
|
-
public checkAccess(action: any, model = null, params: any = []) {
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Send data formatted as JSON.
|
|
68
|
-
|
|
69
|
-
This method is a shortcut for sending data formatted as JSON. It will return the response application component after configuring the format and setting the data that should be formatted. A common usage will b
|
|
70
|
-
*/
|
|
71
|
-
asJson(data: any) {
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Send data formatted as XML.
|
|
77
|
-
|
|
78
|
-
This method is a shortcut for sending data formatted as XML. It will return the response application component after configuring the format and setting the data that should be formatted. A common usage will be:
|
|
79
|
-
*/
|
|
80
|
-
asXml(data: any) {
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}
|
|
@@ -1,16 +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
|
-
|
|
9
|
-
|
|
10
|
-
import {BaseError} from "./BaseError";
|
|
11
|
-
|
|
12
|
-
export class DataErrorDbException extends BaseError {
|
|
13
|
-
constructor ( public message: string) {
|
|
14
|
-
super(message);
|
|
15
|
-
}
|
|
16
|
-
}
|
package/base/DbConnection.ts
DELETED
|
@@ -1,51 +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
|
-
const {Sequelize} = require("sequelize");
|
|
9
|
-
import {Component} from "./Component";
|
|
10
|
-
import BaseChyz from "../BaseChyz";
|
|
11
|
-
|
|
12
|
-
export class DbConnection extends Component {
|
|
13
|
-
|
|
14
|
-
public database!: string;
|
|
15
|
-
public username!: string
|
|
16
|
-
public password!: string
|
|
17
|
-
public options?: object
|
|
18
|
-
public _transaction:any;
|
|
19
|
-
|
|
20
|
-
private _db: any
|
|
21
|
-
|
|
22
|
-
async init() {
|
|
23
|
-
const sequelize = new Sequelize(this.database, this.username, this.password, this.options);
|
|
24
|
-
this._db = sequelize;
|
|
25
|
-
sequelize
|
|
26
|
-
.authenticate()
|
|
27
|
-
.then(() => {
|
|
28
|
-
BaseChyz.info('Connection has been established successfully.');
|
|
29
|
-
})
|
|
30
|
-
.catch((err: any) => {
|
|
31
|
-
BaseChyz.error('Unable to connect to the database:', err);
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// await this.connect();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
get db(): any {
|
|
40
|
-
return this._db;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
set db(value: any) {
|
|
44
|
-
this._db = value;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public transaction(){
|
|
48
|
-
return this.db.transaction();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
}
|
|
@@ -1,15 +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
|
-
export class ForbiddenHttpException extends BaseError {
|
|
10
|
-
constructor ( message: string) {
|
|
11
|
-
super(message);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
@@ -1,16 +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
|
-
|
|
9
|
-
|
|
10
|
-
import {BaseError} from "./BaseError";
|
|
11
|
-
|
|
12
|
-
export class InvalidConfigException extends BaseError {
|
|
13
|
-
constructor ( public message: string) {
|
|
14
|
-
super(message);
|
|
15
|
-
}
|
|
16
|
-
}
|
package/base/Model.ts
DELETED
|
@@ -1,209 +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 Sequelize, {DatabaseError, DataTypes, ExclusionConstraintError, ForeignKeyConstraintError, TimeoutError, UniqueConstraintError, ValidationError,} from "sequelize";
|
|
13
|
-
import {Exception} from "./db/Exception";
|
|
14
|
-
|
|
15
|
-
export {DataTypes,NOW} from "sequelize";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* ValidateMe.init({
|
|
19
|
-
bar: {
|
|
20
|
-
type: Sequelize.STRING,
|
|
21
|
-
validate: {
|
|
22
|
-
is: ["^[a-z]+$",'i'], // will only allow letters
|
|
23
|
-
is: /^[a-z]+$/i, // same as the previous example using real RegExp
|
|
24
|
-
not: ["[a-z]",'i'], // will not allow letters
|
|
25
|
-
isEmail: true, // checks for email format (foo@bar.com)
|
|
26
|
-
isUrl: true, // checks for url format (http://foo.com)
|
|
27
|
-
isIP: true, // checks for IPv4 (129.89.23.1) or IPv6 format
|
|
28
|
-
isIPv4: true, // checks for IPv4 (129.89.23.1)
|
|
29
|
-
isIPv6: true, // checks for IPv6 format
|
|
30
|
-
isAlpha: true, // will only allow letters
|
|
31
|
-
isAlphanumeric: true, // will only allow alphanumeric characters, so "_abc" will fail
|
|
32
|
-
isNumeric: true, // will only allow numbers
|
|
33
|
-
isInt: true, // checks for valid integers
|
|
34
|
-
isFloat: true, // checks for valid floating point numbers
|
|
35
|
-
isDecimal: true, // checks for any numbers
|
|
36
|
-
isLowercase: true, // checks for lowercase
|
|
37
|
-
isUppercase: true, // checks for uppercase
|
|
38
|
-
notNull: true, // won't allow null
|
|
39
|
-
isNull: true, // only allows null
|
|
40
|
-
notEmpty: true, // don't allow empty strings
|
|
41
|
-
equals: 'specific value', // only allow a specific value
|
|
42
|
-
contains: 'foo', // force specific substrings
|
|
43
|
-
notIn: [['foo', 'bar']], // check the value is not one of these
|
|
44
|
-
isIn: [['foo', 'bar']], // check the value is one of these
|
|
45
|
-
notContains: 'bar', // don't allow specific substrings
|
|
46
|
-
len: [2,10], // only allow values with length between 2 and 10
|
|
47
|
-
isUUID: 4, // only allow uuids
|
|
48
|
-
isDate: true, // only allow date strings
|
|
49
|
-
isAfter: "2011-11-05", // only allow date strings after a specific date
|
|
50
|
-
isBefore: "2011-11-05", // only allow date strings before a specific date
|
|
51
|
-
max: 23, // only allow values <= 23
|
|
52
|
-
min: 23, // only allow values >= 23
|
|
53
|
-
isCreditCard: true, // check for valid credit card numbers
|
|
54
|
-
|
|
55
|
-
// Examples of custom validators:
|
|
56
|
-
isEven(value) {
|
|
57
|
-
if (parseInt(value) % 2 !== 0) {
|
|
58
|
-
throw new Error('Only even values are allowed!');
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
isGreaterThanOtherField(value) {
|
|
62
|
-
if (parseInt(value) <= parseInt(this.otherField)) {
|
|
63
|
-
throw new Error('Bar must be greater than otherField.');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}, { sequelize });
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
export class Model extends Component {
|
|
72
|
-
private sequelize: any
|
|
73
|
-
private _tableName: string;
|
|
74
|
-
private _model: any;
|
|
75
|
-
private _attributes: any = {};
|
|
76
|
-
private _errors: any = {}
|
|
77
|
-
|
|
78
|
-
constructor() {
|
|
79
|
-
super();
|
|
80
|
-
this._tableName = this.constructor.name;
|
|
81
|
-
this.sequelize = BaseChyz.getComponent("db").db;
|
|
82
|
-
|
|
83
|
-
if (!Utils.isEmpty(this.attributes())) {
|
|
84
|
-
|
|
85
|
-
this._model = this.sequelize.define(this.constructor.name, this.attributes(), {
|
|
86
|
-
tableName: this.tableName(),
|
|
87
|
-
timestamps: false
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
} else {
|
|
91
|
-
throw new InvalidConfigException(BaseChyz.t("Invalid model configuration, is not emty attributes"))
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
this.init();
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
get errors(): any {
|
|
100
|
-
return this._errors;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
set errors(value: any) {
|
|
104
|
-
this._errors = value;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public init() {
|
|
108
|
-
BaseChyz.debug("Model init....", this.constructor.name)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public tableName() {
|
|
112
|
-
return this._tableName;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
public formName() {
|
|
116
|
-
return this.constructor.name;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public rules() {
|
|
120
|
-
return []
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
public model() {
|
|
124
|
-
return this._model;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
public async save(params = {}, options = {}) {
|
|
128
|
-
// now instantiate an object
|
|
129
|
-
let p = Object.assign(params, this._attributes)
|
|
130
|
-
let result: any;
|
|
131
|
-
try {
|
|
132
|
-
result = await this.model().create(p, options)
|
|
133
|
-
} catch (e) {
|
|
134
|
-
BaseChyz.debug(`Model[${this.constructor.name}].create`,e)
|
|
135
|
-
if (e instanceof ValidationError) {
|
|
136
|
-
let validationErrorItems = e.errors;
|
|
137
|
-
validationErrorItems.forEach(({message, path}) => {
|
|
138
|
-
// @ts-ignore
|
|
139
|
-
this._errors[path] = message
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
return false;
|
|
143
|
-
} else if (e instanceof DatabaseError) {
|
|
144
|
-
|
|
145
|
-
} else if (e instanceof TimeoutError) {
|
|
146
|
-
|
|
147
|
-
} else if (e instanceof UniqueConstraintError) {
|
|
148
|
-
|
|
149
|
-
} else if (e instanceof ForeignKeyConstraintError) {
|
|
150
|
-
|
|
151
|
-
} else if (e instanceof ExclusionConstraintError) {
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
throw new Exception(e.message,this.errors,e.code);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return result;
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
public update(params = {}, options = {}) {
|
|
162
|
-
let p = Object.assign(params, this._attributes)
|
|
163
|
-
return this.model().update(p, options)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
public delete(params = {}, options = {}) {
|
|
167
|
-
let p = Object.assign(params, this._attributes)
|
|
168
|
-
return this.model().delete(p, options)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
public findOne(...args: any[]) {
|
|
173
|
-
return this._model.findOne(...arguments)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
public validate() {
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
public load(data: any, formName: any = null) {
|
|
182
|
-
let scope = formName === null ? this.formName() : formName;
|
|
183
|
-
if (scope === '' && !Utils.isEmpty(data)) {
|
|
184
|
-
this.setAttribute(data);
|
|
185
|
-
return true;
|
|
186
|
-
} else if (data[scope]) {
|
|
187
|
-
this.setAttribute(data[scope]);
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
public setAttribute(values: any, safeOnly = true) {
|
|
194
|
-
if (values instanceof Object) {
|
|
195
|
-
let attributes = this.attributes();
|
|
196
|
-
for (const valueKey in values) {
|
|
197
|
-
if (Object.keys(attributes).indexOf(valueKey) != -1) {
|
|
198
|
-
// @ts-ignore
|
|
199
|
-
BaseChyz.debug("Model[" + this.formName() + "] attributes value set ", valueKey, values[valueKey])
|
|
200
|
-
this._attributes[valueKey] = values[valueKey];
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
public attributes() {
|
|
207
|
-
return {}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
@@ -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);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,16 +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);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
@@ -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);
|
|
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,14 +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 "./Model"
|
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
|
-
}
|