chyz 2.0.1-rc.36 → 2.0.1-rc.37
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.d.ts +74 -0
- package/dist/BaseChyz.d.ts.map +1 -0
- package/dist/BaseChyz.js +586 -0
- package/dist/base/ActionFilter.d.ts +32 -0
- package/dist/base/ActionFilter.d.ts.map +1 -0
- package/dist/base/ActionFilter.js +90 -0
- package/dist/base/BadRequestHttpException.d.ts +6 -0
- package/dist/base/BadRequestHttpException.d.ts.map +1 -0
- package/dist/base/BadRequestHttpException.js +17 -0
- package/dist/base/BaseError.d.ts +44 -0
- package/dist/base/BaseError.d.ts.map +1 -0
- package/{base/BaseError.ts → dist/base/BaseError.js} +18 -26
- package/dist/base/Behavior.d.ts +4 -0
- package/dist/base/Behavior.d.ts.map +1 -0
- package/dist/base/Behavior.js +7 -0
- package/dist/base/CBaseObject.d.ts +5 -0
- package/dist/base/CBaseObject.d.ts.map +1 -0
- package/dist/base/CBaseObject.js +16 -0
- package/dist/base/CEvents.d.ts +13 -0
- package/dist/base/CEvents.d.ts.map +1 -0
- package/dist/base/CEvents.js +24 -0
- package/dist/base/CRequest.d.ts +2 -0
- package/dist/base/CRequest.d.ts.map +1 -0
- package/{base/CRequest.ts → dist/base/CRequest.js} +2 -6
- package/dist/base/CWebController.d.ts +44 -0
- package/dist/base/CWebController.d.ts.map +1 -0
- package/dist/base/CWebController.js +81 -0
- package/dist/base/Component.d.ts +21 -0
- package/dist/base/Component.d.ts.map +1 -0
- package/dist/base/Component.js +57 -0
- package/dist/base/Configurable.d.ts +3 -0
- package/dist/base/Configurable.d.ts.map +1 -0
- package/{requiments/Glob.ts → dist/base/Configurable.js} +2 -3
- package/dist/base/DataErrorDbException.d.ts +6 -0
- package/dist/base/DataErrorDbException.d.ts.map +1 -0
- package/dist/base/DataErrorDbException.js +17 -0
- package/dist/base/DbConnection.d.ts +13 -0
- package/dist/base/DbConnection.d.ts.map +1 -0
- package/dist/base/DbConnection.js +53 -0
- package/dist/base/ForbiddenHttpException.d.ts +5 -0
- package/dist/base/ForbiddenHttpException.d.ts.map +1 -0
- package/dist/base/ForbiddenHttpException.js +16 -0
- package/dist/base/InvalidArgumentException.d.ts +6 -0
- package/dist/base/InvalidArgumentException.d.ts.map +1 -0
- package/dist/base/InvalidArgumentException.js +17 -0
- package/dist/base/InvalidConfigException.d.ts +6 -0
- package/dist/base/InvalidConfigException.d.ts.map +1 -0
- package/dist/base/InvalidConfigException.js +17 -0
- package/dist/base/Logs.d.ts +22 -0
- package/dist/base/Logs.d.ts.map +1 -0
- package/{base/Logs.ts → dist/base/Logs.js} +24 -41
- package/dist/base/Model.d.ts +302 -0
- package/dist/base/Model.d.ts.map +1 -0
- package/{base/Model.ts → dist/base/Model.js} +158 -225
- package/dist/base/ModelManager.d.ts +2 -0
- package/dist/base/ModelManager.d.ts.map +1 -0
- package/{base/ModelManager.ts → dist/base/ModelManager.js} +7 -7
- package/dist/base/NotFoundHttpException.d.ts +6 -0
- package/dist/base/NotFoundHttpException.d.ts.map +1 -0
- package/dist/base/NotFoundHttpException.js +17 -0
- package/dist/base/RestClient.d.ts +7 -0
- package/dist/base/RestClient.d.ts.map +1 -0
- package/dist/base/RestClient.js +25 -0
- package/dist/base/UnauthorizedHttpException.d.ts +6 -0
- package/dist/base/UnauthorizedHttpException.d.ts.map +1 -0
- package/dist/base/UnauthorizedHttpException.js +17 -0
- package/dist/base/ValidationHttpException.d.ts +6 -0
- package/dist/base/ValidationHttpException.d.ts.map +1 -0
- package/dist/base/ValidationHttpException.js +17 -0
- package/dist/base/db/Exception.d.ts +7 -0
- package/dist/base/db/Exception.d.ts.map +1 -0
- package/dist/base/db/Exception.js +15 -0
- package/dist/base/index.d.ts +20 -0
- package/dist/base/index.d.ts.map +1 -0
- package/dist/base/index.js +41 -0
- package/dist/decorator/Middleware.d.ts +4 -0
- package/dist/decorator/Middleware.d.ts.map +1 -0
- package/dist/decorator/Middleware.js +10 -0
- package/dist/decorator/controller.d.ts +3 -0
- package/dist/decorator/controller.d.ts.map +1 -0
- package/{decorator/controller.ts → dist/decorator/controller.js} +9 -7
- package/dist/decorator/delete.d.ts +3 -0
- package/dist/decorator/delete.d.ts.map +1 -0
- package/{decorator/delete.ts → dist/decorator/delete.js} +9 -9
- package/dist/decorator/enums/ControllerDecoratorParams.d.ts +6 -0
- package/dist/decorator/enums/ControllerDecoratorParams.d.ts.map +1 -0
- package/dist/decorator/enums/ControllerDecoratorParams.js +9 -0
- package/dist/decorator/get.d.ts +3 -0
- package/dist/decorator/get.d.ts.map +1 -0
- package/{decorator/get.ts → dist/decorator/get.js} +10 -11
- package/dist/decorator/index.d.ts +6 -0
- package/dist/decorator/index.d.ts.map +1 -0
- package/dist/decorator/index.js +13 -0
- package/dist/decorator/post.d.ts +3 -0
- package/dist/decorator/post.d.ts.map +1 -0
- package/{decorator/post.ts → dist/decorator/post.js} +10 -10
- package/dist/decorator/put.d.ts +3 -0
- package/dist/decorator/put.d.ts.map +1 -0
- package/{decorator/put.ts → dist/decorator/put.js} +9 -9
- package/dist/filters/AccessControl.d.ts +12 -0
- package/dist/filters/AccessControl.d.ts.map +1 -0
- package/dist/filters/AccessControl.js +83 -0
- package/dist/filters/AccessRule.d.ts +83 -0
- package/dist/filters/AccessRule.d.ts.map +1 -0
- package/dist/filters/AccessRule.js +136 -0
- package/{filters/auth/AuthInterface.ts → dist/filters/auth/AuthInterface.d.ts} +7 -15
- package/dist/filters/auth/AuthInterface.d.ts.map +1 -0
- package/dist/filters/auth/AuthInterface.js +2 -0
- package/dist/filters/auth/AuthMethod.d.ts +38 -0
- package/dist/filters/auth/AuthMethod.d.ts.map +1 -0
- package/dist/filters/auth/AuthMethod.js +82 -0
- package/dist/filters/auth/HttpBasicAuth.d.ts +24 -0
- package/dist/filters/auth/HttpBasicAuth.d.ts.map +1 -0
- package/dist/filters/auth/HttpBasicAuth.js +79 -0
- package/dist/filters/auth/HttpBearerAuth.d.ts +18 -0
- package/dist/filters/auth/HttpBearerAuth.d.ts.map +1 -0
- package/dist/filters/auth/HttpBearerAuth.js +33 -0
- package/dist/filters/auth/HttpHeaderAuth.d.ts +19 -0
- package/dist/filters/auth/HttpHeaderAuth.d.ts.map +1 -0
- package/dist/filters/auth/HttpHeaderAuth.js +64 -0
- package/dist/filters/auth/JwtHttpBearerAuth.d.ts +21 -0
- package/dist/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -0
- package/dist/filters/auth/JwtHttpBearerAuth.js +88 -0
- package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts +23 -0
- package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts.map +1 -0
- package/dist/filters/auth/KeyCloakHttpBearerAuth.js +116 -0
- package/dist/filters/auth/index.d.ts +5 -0
- package/dist/filters/auth/index.d.ts.map +1 -0
- package/dist/filters/auth/index.js +11 -0
- package/dist/filters/index.d.ts +3 -0
- package/dist/filters/index.d.ts.map +1 -0
- package/dist/filters/index.js +7 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/log/log/config/log4js.json +55 -0
- package/dist/model/RouteDefinition.d.ts +7 -0
- package/dist/model/RouteDefinition.d.ts.map +1 -0
- package/{base/Configurable.ts → dist/model/RouteDefinition.js} +2 -4
- package/dist/package.json +63 -0
- package/dist/rbac/AuthAssignment.d.ts +19 -0
- package/dist/rbac/AuthAssignment.d.ts.map +1 -0
- package/dist/rbac/AuthAssignment.js +44 -0
- package/dist/rbac/AuthItem.d.ts +27 -0
- package/dist/rbac/AuthItem.d.ts.map +1 -0
- package/{rbac/AuthItem.ts → dist/rbac/AuthItem.js} +16 -22
- package/dist/rbac/AuthItemChild.d.ts +19 -0
- package/dist/rbac/AuthItemChild.d.ts.map +1 -0
- package/{rbac/AuthItemChild.ts → dist/rbac/AuthItemChild.js} +14 -21
- package/dist/rbac/AuthManager.d.ts +112 -0
- package/dist/rbac/AuthManager.d.ts.map +1 -0
- package/dist/rbac/AuthManager.js +356 -0
- package/dist/rbac/index.d.ts +5 -0
- package/dist/rbac/index.d.ts.map +1 -0
- package/dist/rbac/index.js +28 -0
- package/dist/requiments/Glob.d.ts +3 -0
- package/dist/requiments/Glob.d.ts.map +1 -0
- package/dist/requiments/Glob.js +10 -0
- package/dist/requiments/ReflectUtil.d.ts +1 -0
- package/dist/requiments/ReflectUtil.d.ts.map +1 -0
- package/{requiments/ReflectUtil.ts → dist/requiments/ReflectUtil.js} +4 -6
- package/dist/requiments/Utils.d.ts +2 -0
- package/dist/requiments/Utils.d.ts.map +1 -0
- package/{requiments/Utils.ts → dist/requiments/Utils.js} +34 -40
- package/dist/validators/BooleanValidator.d.ts +1 -0
- package/dist/validators/BooleanValidator.d.ts.map +1 -0
- package/dist/validators/BooleanValidator.js +1 -0
- package/dist/validators/CompareValidator.d.ts +1 -0
- package/dist/validators/CompareValidator.d.ts.map +1 -0
- package/dist/validators/CompareValidator.js +1 -0
- package/dist/validators/DateValidator.d.ts +1 -0
- package/dist/validators/DateValidator.d.ts.map +1 -0
- package/dist/validators/DateValidator.js +1 -0
- package/dist/validators/EmailValidator.d.ts +1 -0
- package/dist/validators/EmailValidator.d.ts.map +1 -0
- package/dist/validators/EmailValidator.js +1 -0
- package/dist/validators/Validator.d.ts +18 -0
- package/dist/validators/Validator.d.ts.map +1 -0
- package/dist/validators/Validator.js +27 -0
- package/{web/IdentityInterface.ts → dist/web/IdentityInterface.d.ts} +2 -15
- package/dist/web/IdentityInterface.d.ts.map +1 -0
- package/dist/web/IdentityInterface.js +8 -0
- package/dist/web/WebUser.d.ts +72 -0
- package/dist/web/WebUser.d.ts.map +1 -0
- package/dist/web/WebUser.js +165 -0
- package/package.json +16 -56
- package/BaseChyz.ts +0 -623
- package/base/ActionFilter.ts +0 -88
- package/base/BadRequestHttpException.ts +0 -14
- package/base/Behavior.ts +0 -6
- package/base/CBaseObject.ts +0 -17
- package/base/CEvents.ts +0 -24
- package/base/CWebController.ts +0 -90
- package/base/Component.ts +0 -66
- package/base/DataErrorDbException.ts +0 -16
- package/base/DbConnection.ts +0 -55
- package/base/ForbiddenHttpException.ts +0 -15
- package/base/InvalidArgumentException.ts +0 -16
- package/base/InvalidConfigException.ts +0 -16
- package/base/NotFoundHttpException.ts +0 -14
- package/base/RestClient.ts +0 -26
- package/base/UnauthorizedHttpException.ts +0 -17
- package/base/ValidationHttpException.ts +0 -14
- package/base/db/Exception.ts +0 -14
- package/base/index.ts +0 -19
- package/decorator/Middleware.ts +0 -9
- package/decorator/enums/ControllerDecoratorParams.ts +0 -5
- package/decorator/index.ts +0 -5
- package/filters/AccessControl.ts +0 -74
- package/filters/AccessRule.ts +0 -182
- package/filters/auth/AuthMethod.ts +0 -100
- package/filters/auth/HttpBasicAuth.ts +0 -79
- package/filters/auth/HttpBearerAuth.ts +0 -34
- package/filters/auth/HttpHeaderAuth.ts +0 -61
- package/filters/auth/JwtHttpBearerAuth.ts +0 -83
- package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -114
- package/filters/auth/index.ts +0 -4
- package/filters/index.ts +0 -2
- package/index.ts +0 -80
- package/model/RouteDefinition.ts +0 -18
- package/rbac/AuthAssignment.ts +0 -50
- package/rbac/AuthManager.ts +0 -399
- package/rbac/index.ts +0 -12
- 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/WebUser.ts +0 -187
- /package/{README.md → dist/README.md} +0 -0
- /package/{log → dist/log}/config/log4js.json +0 -0
|
@@ -1,48 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*
|
|
2
3
|
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
3
4
|
* Author: Cihan Ozturk
|
|
4
5
|
* E-mail: cihan@chy.com.tr
|
|
5
6
|
* Github:https://github.com/cihan53/
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.Model = exports.NOW = exports.DataTypes = void 0;
|
|
22
|
+
const BaseChyz_1 = __importDefault(require("../BaseChyz"));
|
|
23
|
+
const Utils_1 = require("../requiments/Utils");
|
|
24
|
+
const Component_1 = require("./Component");
|
|
25
|
+
const InvalidConfigException_1 = require("./InvalidConfigException");
|
|
26
|
+
const sequelize_1 = require("sequelize");
|
|
27
|
+
const Exception_1 = require("./db/Exception");
|
|
28
|
+
const DataErrorDbException_1 = require("./DataErrorDbException");
|
|
29
|
+
var sequelize_2 = require("sequelize");
|
|
30
|
+
Object.defineProperty(exports, "DataTypes", { enumerable: true, get: function () { return sequelize_2.DataTypes; } });
|
|
31
|
+
Object.defineProperty(exports, "NOW", { enumerable: true, get: function () { return sequelize_2.NOW; } });
|
|
46
32
|
/**
|
|
47
33
|
* ValidateMe.init({
|
|
48
34
|
bar: {
|
|
@@ -96,29 +82,19 @@ export interface Relation {
|
|
|
96
82
|
}
|
|
97
83
|
}, { sequelize });
|
|
98
84
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
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) {
|
|
85
|
+
class Model extends Component_1.Component {
|
|
86
|
+
constructor(sequelize) {
|
|
110
87
|
super();
|
|
88
|
+
this._attributes = {};
|
|
89
|
+
this._errors = {};
|
|
111
90
|
this._tableName = this.alias();
|
|
112
|
-
|
|
113
|
-
BaseChyz.debug("Model constructor", this._tableName)
|
|
91
|
+
BaseChyz_1.default.debug("Model constructor", this._tableName);
|
|
114
92
|
// this._sequelize = BaseChyz.getComponent("db").db;
|
|
115
|
-
|
|
116
93
|
if (sequelize != null) {
|
|
117
94
|
this._provider = sequelize;
|
|
118
|
-
}
|
|
95
|
+
}
|
|
96
|
+
else
|
|
119
97
|
this._provider = this.getDb();
|
|
120
|
-
|
|
121
|
-
|
|
122
98
|
/**
|
|
123
99
|
* override query
|
|
124
100
|
*/
|
|
@@ -131,22 +107,19 @@ export class Model extends Component {
|
|
|
131
107
|
// throw new DatabaseError(err);
|
|
132
108
|
// }
|
|
133
109
|
// };
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if( process.env.NODE_ENV=="development" || process.env.NODE_ENV=="dev"){
|
|
110
|
+
this._provider.query = function (sql, options) {
|
|
111
|
+
return sequelize_1.Sequelize.prototype.query.apply(this, [sql, options]).catch((err) => {
|
|
112
|
+
if (process.env.NODE_ENV == "development" || process.env.NODE_ENV == "dev") {
|
|
140
113
|
// e.stack = e.original;
|
|
141
|
-
if(
|
|
114
|
+
if (err instanceof sequelize_1.DatabaseError) {
|
|
142
115
|
// @ts-ignore
|
|
143
116
|
delete err.parent;
|
|
144
117
|
// @ts-ignore
|
|
145
118
|
delete err.original;
|
|
146
119
|
}
|
|
147
120
|
}
|
|
148
|
-
throw new DataErrorDbException(err);
|
|
149
|
-
})
|
|
121
|
+
throw new DataErrorDbException_1.DataErrorDbException(err);
|
|
122
|
+
});
|
|
150
123
|
// try {
|
|
151
124
|
// let r =
|
|
152
125
|
// console.log(r)
|
|
@@ -154,68 +127,55 @@ export class Model extends Component {
|
|
|
154
127
|
// console.log(err)
|
|
155
128
|
// throw new DatabaseError(err);
|
|
156
129
|
// }
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (!Utils.isEmpty(this.attributes())) {
|
|
130
|
+
};
|
|
131
|
+
if (!Utils_1.Utils.isEmpty(this.attributes())) {
|
|
160
132
|
this._model = this._provider.define(this._tableName, this.attributes(), {
|
|
161
133
|
tableName: this.tableName(),
|
|
162
134
|
timestamps: false,
|
|
163
135
|
createdAt: false,
|
|
164
136
|
updateAt: false
|
|
165
137
|
});
|
|
166
|
-
|
|
167
|
-
} else {
|
|
168
|
-
throw new InvalidConfigException(BaseChyz.t("Invalid model configuration, is not emty attributes"))
|
|
169
138
|
}
|
|
170
|
-
|
|
139
|
+
else {
|
|
140
|
+
throw new InvalidConfigException_1.InvalidConfigException(BaseChyz_1.default.t("Invalid model configuration, is not emty attributes"));
|
|
141
|
+
}
|
|
171
142
|
// this.init();
|
|
172
|
-
|
|
173
143
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
144
|
/**
|
|
177
145
|
* Returns the database connection used by this AR class.
|
|
178
146
|
* By default, the "db" application component is used as the database connection.
|
|
179
147
|
* You may override this method if you want to use a different database connection.
|
|
180
148
|
* @return Connection the database connection used by this AR class.
|
|
181
149
|
*/
|
|
182
|
-
|
|
183
|
-
return
|
|
150
|
+
getDb() {
|
|
151
|
+
return BaseChyz_1.default.getComponent("db") ? BaseChyz_1.default.getComponent("db").db : null;
|
|
184
152
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return BaseChyz.getComponent("db");
|
|
153
|
+
getDbConnection() {
|
|
154
|
+
return BaseChyz_1.default.getComponent("db");
|
|
188
155
|
}
|
|
189
|
-
|
|
190
|
-
get provider(): any {
|
|
156
|
+
get provider() {
|
|
191
157
|
return this._provider;
|
|
192
158
|
}
|
|
193
|
-
|
|
194
|
-
set provider(value: any) {
|
|
159
|
+
set provider(value) {
|
|
195
160
|
this._provider = value;
|
|
196
161
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
162
|
/**
|
|
200
163
|
*
|
|
201
164
|
*/
|
|
202
|
-
get errors()
|
|
165
|
+
get errors() {
|
|
203
166
|
return this._errors;
|
|
204
167
|
}
|
|
205
|
-
|
|
206
|
-
set errors(value: any) {
|
|
168
|
+
set errors(value) {
|
|
207
169
|
this._errors = value;
|
|
208
170
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
BaseChyz.debug("Model init....", this.constructor.name)
|
|
171
|
+
init() {
|
|
172
|
+
BaseChyz_1.default.debug("Model init....", this.constructor.name);
|
|
212
173
|
/**
|
|
213
174
|
* init buraya
|
|
214
175
|
*/
|
|
215
|
-
|
|
176
|
+
BaseChyz_1.default.debug("Relation init....", this.constructor.name);
|
|
216
177
|
for (const relation of this.relations()) {
|
|
217
178
|
let m = relation.model;
|
|
218
|
-
|
|
219
179
|
if (relation.type == "hasOne") {
|
|
220
180
|
// @ts-ignore
|
|
221
181
|
delete relation.model;
|
|
@@ -227,132 +187,114 @@ export class Model extends Component {
|
|
|
227
187
|
delete relation.model;
|
|
228
188
|
this.model().hasMany(m, relation);
|
|
229
189
|
}
|
|
230
|
-
|
|
231
190
|
if (relation.type == "belongsTo") {
|
|
232
191
|
// @ts-ignore
|
|
233
192
|
delete relation.model;
|
|
234
193
|
this.model().belongsTo(m, relation);
|
|
235
194
|
}
|
|
236
|
-
|
|
237
195
|
if (relation.type == "belongsToMany") {
|
|
238
196
|
// @ts-ignore
|
|
239
197
|
delete relation.model;
|
|
240
198
|
this.model().belongsToMany(m, relation);
|
|
241
199
|
}
|
|
242
200
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
201
|
}
|
|
246
|
-
|
|
247
|
-
public alias() {
|
|
202
|
+
alias() {
|
|
248
203
|
return this.constructor.name;
|
|
249
204
|
}
|
|
250
|
-
|
|
251
|
-
public tableName() {
|
|
205
|
+
tableName() {
|
|
252
206
|
return this._tableName;
|
|
253
207
|
}
|
|
254
|
-
|
|
255
|
-
public formName() {
|
|
208
|
+
formName() {
|
|
256
209
|
return this.constructor.name;
|
|
257
210
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return []
|
|
211
|
+
rules() {
|
|
212
|
+
return [];
|
|
261
213
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
public setModel(value: any) {
|
|
214
|
+
setModel(value) {
|
|
265
215
|
this._model = value;
|
|
266
216
|
}
|
|
267
|
-
|
|
268
|
-
public model() {
|
|
217
|
+
model() {
|
|
269
218
|
return this._model;
|
|
270
219
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
-
|
|
220
|
+
save() {
|
|
221
|
+
return __awaiter(this, arguments, void 0, function* (params = {}, options = {}) {
|
|
222
|
+
this.errors = {};
|
|
223
|
+
// now instantiate an object
|
|
224
|
+
let p = Object.assign(params, this._attributes);
|
|
225
|
+
let result;
|
|
226
|
+
try {
|
|
227
|
+
result = yield this.model().create(p, options);
|
|
301
228
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
229
|
+
catch (e) {
|
|
230
|
+
BaseChyz_1.default.debug(`Model[${this.constructor.name}].create`, e);
|
|
231
|
+
if (e instanceof sequelize_1.ValidationError) {
|
|
232
|
+
let validationErrorItems = e.errors;
|
|
233
|
+
validationErrorItems.forEach(({ message, path }) => {
|
|
234
|
+
// @ts-ignore
|
|
235
|
+
this._errors[path] = message;
|
|
236
|
+
});
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
else if (e instanceof sequelize_1.DatabaseError) {
|
|
240
|
+
}
|
|
241
|
+
else if (e instanceof sequelize_1.TimeoutError) {
|
|
242
|
+
}
|
|
243
|
+
else if (e instanceof sequelize_1.UniqueConstraintError) {
|
|
244
|
+
}
|
|
245
|
+
else if (e instanceof sequelize_1.ForeignKeyConstraintError) {
|
|
246
|
+
}
|
|
247
|
+
else if (e instanceof sequelize_1.ExclusionConstraintError) {
|
|
248
|
+
}
|
|
249
|
+
throw new Exception_1.Exception(e.message, this.errors, e.code);
|
|
250
|
+
}
|
|
251
|
+
return result;
|
|
252
|
+
});
|
|
307
253
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
-
|
|
254
|
+
bulkCreate() {
|
|
255
|
+
return __awaiter(this, arguments, void 0, function* (params = {}, options = {}) {
|
|
256
|
+
this.errors = {};
|
|
257
|
+
// now instantiate an object
|
|
258
|
+
let p = Object.assign(params, this._attributes);
|
|
259
|
+
let result;
|
|
260
|
+
try {
|
|
261
|
+
result = yield this.model().bulkCreate(p, options);
|
|
336
262
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
263
|
+
catch (e) {
|
|
264
|
+
BaseChyz_1.default.debug(`Model[${this.constructor.name}].bulkCreate`, e);
|
|
265
|
+
if (e instanceof sequelize_1.ValidationError) {
|
|
266
|
+
let validationErrorItems = e.errors;
|
|
267
|
+
validationErrorItems.forEach(({ message, path }) => {
|
|
268
|
+
// @ts-ignore
|
|
269
|
+
this._errors[path] = message;
|
|
270
|
+
});
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
else if (e instanceof sequelize_1.DatabaseError) {
|
|
274
|
+
}
|
|
275
|
+
else if (e instanceof sequelize_1.TimeoutError) {
|
|
276
|
+
}
|
|
277
|
+
else if (e instanceof sequelize_1.UniqueConstraintError) {
|
|
278
|
+
}
|
|
279
|
+
else if (e instanceof sequelize_1.ForeignKeyConstraintError) {
|
|
280
|
+
}
|
|
281
|
+
else if (e instanceof sequelize_1.ExclusionConstraintError) {
|
|
282
|
+
}
|
|
283
|
+
throw new Exception_1.Exception(e.message, this.errors, e.code);
|
|
284
|
+
}
|
|
285
|
+
return result;
|
|
286
|
+
});
|
|
342
287
|
}
|
|
343
|
-
|
|
344
|
-
public update(params = {}, options = {}) {
|
|
288
|
+
update(params = {}, options = {}) {
|
|
345
289
|
this.errors = {};
|
|
346
|
-
let p = Object.assign(params, this._attributes)
|
|
347
|
-
return this.model().update(p, options)
|
|
290
|
+
let p = Object.assign(params, this._attributes);
|
|
291
|
+
return this.model().update(p, options);
|
|
348
292
|
}
|
|
349
|
-
|
|
350
|
-
public delete(params = {}, options = {}) {
|
|
293
|
+
delete(params = {}, options = {}) {
|
|
351
294
|
this.errors = {};
|
|
352
|
-
let p = Object.assign(params, this._attributes)
|
|
353
|
-
return this.model().destroy(p, options)
|
|
295
|
+
let p = Object.assign(params, this._attributes);
|
|
296
|
+
return this.model().destroy(p, options);
|
|
354
297
|
}
|
|
355
|
-
|
|
356
298
|
/**
|
|
357
299
|
* 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.
|
|
358
300
|
*
|
|
@@ -517,96 +459,87 @@ export class Model extends Component {
|
|
|
517
459
|
* @param query
|
|
518
460
|
* @param options
|
|
519
461
|
*/
|
|
520
|
-
|
|
521
|
-
this
|
|
522
|
-
|
|
462
|
+
rawQuery(query_1) {
|
|
463
|
+
return __awaiter(this, arguments, void 0, function* (query, options = { type: sequelize_1.QueryTypes.SELECT, nest: true }) {
|
|
464
|
+
this.errors = {};
|
|
465
|
+
return yield this.model().query(query, options);
|
|
466
|
+
});
|
|
523
467
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
468
|
/**
|
|
527
469
|
*
|
|
528
470
|
* @param args
|
|
529
471
|
*/
|
|
530
|
-
|
|
531
|
-
return this._model.findOne(...arguments)
|
|
472
|
+
findOne(...args) {
|
|
473
|
+
return this._model.findOne(...arguments);
|
|
532
474
|
}
|
|
533
|
-
|
|
534
475
|
/**
|
|
535
476
|
*
|
|
536
477
|
* @param args
|
|
537
478
|
*/
|
|
538
|
-
|
|
539
|
-
return this._model.findAll(...arguments)
|
|
479
|
+
findAll(...args) {
|
|
480
|
+
return this._model.findAll(...arguments);
|
|
540
481
|
}
|
|
541
|
-
|
|
542
482
|
/**
|
|
543
483
|
* return {count : number , rows: any}
|
|
544
484
|
* @param args
|
|
545
485
|
*/
|
|
546
|
-
|
|
547
|
-
return this._model.findAndCountAll(...arguments)
|
|
486
|
+
findAndCountAll(...args) {
|
|
487
|
+
return this._model.findAndCountAll(...arguments);
|
|
548
488
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
public validate() {
|
|
552
|
-
|
|
489
|
+
validate() {
|
|
553
490
|
}
|
|
554
|
-
|
|
555
491
|
/**
|
|
556
492
|
*
|
|
557
493
|
* @param data
|
|
558
494
|
* @param formName
|
|
559
495
|
*/
|
|
560
|
-
|
|
496
|
+
load(data, formName = null) {
|
|
561
497
|
let scope = formName === null ? this.formName() : formName;
|
|
562
|
-
if (scope === '' && !Utils.isEmpty(data)) {
|
|
498
|
+
if (scope === '' && !Utils_1.Utils.isEmpty(data)) {
|
|
563
499
|
this.setAttribute(data);
|
|
564
500
|
return true;
|
|
565
|
-
}
|
|
501
|
+
}
|
|
502
|
+
else if (data[scope]) {
|
|
566
503
|
this.setAttribute(data[scope]);
|
|
567
504
|
return true;
|
|
568
505
|
}
|
|
569
506
|
return false;
|
|
570
507
|
}
|
|
571
|
-
|
|
572
|
-
public bulkLoad(data: any, formName: any = null) {
|
|
508
|
+
bulkLoad(data, formName = null) {
|
|
573
509
|
let scope = formName === null ? this.formName() : formName;
|
|
574
|
-
if (scope === '' && !Utils.isEmpty(data)) {
|
|
510
|
+
if (scope === '' && !Utils_1.Utils.isEmpty(data)) {
|
|
575
511
|
this.setAttribute(data);
|
|
576
512
|
return true;
|
|
577
|
-
}
|
|
513
|
+
}
|
|
514
|
+
else if (data[scope]) {
|
|
578
515
|
this.setAttribute(data[scope]);
|
|
579
516
|
return true;
|
|
580
517
|
}
|
|
581
518
|
return false;
|
|
582
519
|
}
|
|
583
|
-
|
|
584
|
-
public setAttribute(values: any, safeOnly = true) {
|
|
520
|
+
setAttribute(values, safeOnly = true) {
|
|
585
521
|
if (values instanceof Object) {
|
|
586
522
|
let attributes = this.attributes();
|
|
587
523
|
for (const valueKey in values) {
|
|
588
524
|
if (Object.keys(attributes).indexOf(valueKey) != -1) {
|
|
589
525
|
// @ts-ignore
|
|
590
|
-
|
|
526
|
+
BaseChyz_1.default.debug("Model[" + this.formName() + "] attributes value set ", valueKey, values[valueKey]);
|
|
591
527
|
this._attributes[valueKey] = values[valueKey];
|
|
592
528
|
}
|
|
593
529
|
}
|
|
594
530
|
}
|
|
595
531
|
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
return {}
|
|
532
|
+
attributes() {
|
|
533
|
+
return {};
|
|
599
534
|
}
|
|
600
|
-
|
|
601
535
|
/**
|
|
602
536
|
* relation return array
|
|
603
537
|
* [
|
|
604
538
|
*
|
|
605
539
|
* ]
|
|
606
540
|
*/
|
|
607
|
-
|
|
608
|
-
return []
|
|
541
|
+
relations() {
|
|
542
|
+
return [];
|
|
609
543
|
}
|
|
610
|
-
|
|
611
|
-
|
|
612
544
|
}
|
|
545
|
+
exports.Model = Model;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelManager.d.ts","sourceRoot":"","sources":["../../src/base/ModelManager.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,YAAY,EAAE,GAI1B,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelManager = void 0;
|
|
3
4
|
/*
|
|
4
5
|
*
|
|
5
6
|
* Copyright (c) 2021.. Chy Bilgisayar Bilisim
|
|
@@ -11,9 +12,8 @@ import {Model} from "./Model"
|
|
|
11
12
|
// interface ObjectConstructor {
|
|
12
13
|
// _register(o: Model): void;
|
|
13
14
|
// }
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Object.assign(this, map)
|
|
15
|
+
exports.ModelManager = {
|
|
16
|
+
_register(map) {
|
|
17
|
+
Object.assign(this, map);
|
|
18
18
|
}
|
|
19
|
-
}
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotFoundHttpException.d.ts","sourceRoot":"","sources":["../../src/base/NotFoundHttpException.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC,qBAAa,qBAAsB,SAAQ,SAAS;IAC3B,OAAO,EAAE,GAAG;gBAAZ,OAAO,EAAE,GAAG;CAGpC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.NotFoundHttpException = void 0;
|
|
10
|
+
const BaseError_1 = require("./BaseError");
|
|
11
|
+
class NotFoundHttpException extends BaseError_1.BaseError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message, 404);
|
|
14
|
+
this.message = message;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.NotFoundHttpException = NotFoundHttpException;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Component } from "./Component";
|
|
2
|
+
export declare class RestClient extends Component {
|
|
3
|
+
post(url: string, args?: any, headers?: any): any;
|
|
4
|
+
get(url: string, args?: any, headers?: any): any;
|
|
5
|
+
Rest(params: any): any;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=RestClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RestClient.d.ts","sourceRoot":"","sources":["../../src/base/RestClient.ts"],"names":[],"mappings":"AASA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAItC,qBAAa,UAAW,SAAQ,SAAS;IAC9B,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAC,OAAO,CAAC,EAAC,GAAG;IAIzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAC,OAAO,CAAC,EAAC,GAAG;IAIxC,IAAI,CAAC,MAAM,EAAE,GAAG;CAG1B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2021.. Chy Bilgisayar Bilisim
|
|
5
|
+
* Author: Cihan Ozturk
|
|
6
|
+
* E-mail: cihan@chy.com.tr
|
|
7
|
+
* Github:https://github.com/cihan53/
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.RestClient = void 0;
|
|
12
|
+
const Component_1 = require("./Component");
|
|
13
|
+
const axios = require('axios');
|
|
14
|
+
class RestClient extends Component_1.Component {
|
|
15
|
+
post(url, args, headers) {
|
|
16
|
+
return axios.post(url, Object.assign(Object.assign({}, args), { headers: headers }));
|
|
17
|
+
}
|
|
18
|
+
get(url, args, headers) {
|
|
19
|
+
return axios.get(url, Object.assign(Object.assign({}, args), { headers: headers }));
|
|
20
|
+
}
|
|
21
|
+
Rest(params) {
|
|
22
|
+
return axios(params);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.RestClient = RestClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnauthorizedHttpException.d.ts","sourceRoot":"","sources":["../../src/base/UnauthorizedHttpException.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC,qBAAa,yBAA0B,SAAQ,SAAS;IAC/B,OAAO,EAAE,GAAG;gBAAZ,OAAO,EAAE,GAAG;CAIpC"}
|