chyz 2.0.0-rc.8 → 2.0.1-rc.1

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.
Files changed (153) hide show
  1. package/BaseChyz.d.ts +73 -56
  2. package/BaseChyz.d.ts.map +1 -1
  3. package/BaseChyz.js +569 -404
  4. package/README.md +1 -1
  5. package/base/ActionFilter.d.ts +32 -32
  6. package/base/ActionFilter.d.ts.map +1 -1
  7. package/base/ActionFilter.js +82 -82
  8. package/base/BadRequestHttpException.d.ts +6 -0
  9. package/base/BadRequestHttpException.d.ts.map +1 -0
  10. package/base/BadRequestHttpException.js +17 -0
  11. package/base/BaseError.d.ts +43 -10
  12. package/base/BaseError.d.ts.map +1 -1
  13. package/base/BaseError.js +58 -26
  14. package/base/Behavior.d.ts +3 -3
  15. package/base/Behavior.js +7 -7
  16. package/base/CBaseObject.d.ts +4 -4
  17. package/base/CBaseObject.d.ts.map +1 -1
  18. package/base/CBaseObject.js +16 -16
  19. package/base/CEvents.d.ts +13 -0
  20. package/base/CEvents.d.ts.map +1 -0
  21. package/base/CEvents.js +24 -0
  22. package/base/CRequest.d.ts +1 -1
  23. package/base/CRequest.js +10 -10
  24. package/base/CWebController.d.ts +43 -43
  25. package/base/CWebController.d.ts.map +1 -1
  26. package/base/CWebController.js +81 -74
  27. package/base/Component.d.ts +20 -20
  28. package/base/Component.d.ts.map +1 -1
  29. package/base/Component.js +57 -57
  30. package/base/Configurable.d.ts +2 -2
  31. package/base/Configurable.js +8 -8
  32. package/base/DataErrorDbException.d.ts +5 -5
  33. package/base/DataErrorDbException.d.ts.map +1 -1
  34. package/base/DataErrorDbException.js +17 -17
  35. package/base/DbConnection.d.ts +12 -12
  36. package/base/DbConnection.js +53 -53
  37. package/base/ForbiddenHttpException.d.ts +4 -4
  38. package/base/ForbiddenHttpException.d.ts.map +1 -1
  39. package/base/ForbiddenHttpException.js +16 -16
  40. package/base/InvalidArgumentException.d.ts +5 -5
  41. package/base/InvalidArgumentException.d.ts.map +1 -1
  42. package/base/InvalidArgumentException.js +17 -17
  43. package/base/InvalidConfigException.d.ts +5 -5
  44. package/base/InvalidConfigException.d.ts.map +1 -1
  45. package/base/InvalidConfigException.js +17 -17
  46. package/base/Logs.d.ts +21 -21
  47. package/base/Logs.d.ts.map +1 -1
  48. package/base/Logs.js +57 -57
  49. package/base/Model.d.ts +301 -298
  50. package/base/Model.d.ts.map +1 -1
  51. package/base/Model.js +545 -507
  52. package/base/ModelManager.d.ts +1 -1
  53. package/base/ModelManager.js +19 -19
  54. package/base/NotFoundHttpException.d.ts +5 -5
  55. package/base/NotFoundHttpException.d.ts.map +1 -1
  56. package/base/NotFoundHttpException.js +17 -17
  57. package/base/RestClient.d.ts +6 -6
  58. package/base/RestClient.d.ts.map +1 -1
  59. package/base/RestClient.js +25 -25
  60. package/base/UnauthorizedHttpException.d.ts +5 -5
  61. package/base/UnauthorizedHttpException.d.ts.map +1 -1
  62. package/base/UnauthorizedHttpException.js +17 -17
  63. package/base/ValidationHttpException.d.ts +5 -5
  64. package/base/ValidationHttpException.d.ts.map +1 -1
  65. package/base/ValidationHttpException.js +17 -17
  66. package/base/db/Exception.d.ts +6 -6
  67. package/base/db/Exception.js +15 -15
  68. package/base/index.d.ts +19 -18
  69. package/base/index.d.ts.map +1 -1
  70. package/base/index.js +41 -39
  71. package/decorator/Middleware.d.ts +3 -3
  72. package/decorator/Middleware.js +11 -11
  73. package/decorator/controller.d.ts +2 -2
  74. package/decorator/controller.js +24 -24
  75. package/decorator/delete.d.ts +3 -0
  76. package/decorator/delete.d.ts.map +1 -0
  77. package/decorator/delete.js +36 -0
  78. package/decorator/enums/ControllerDecoratorParams.d.ts +5 -5
  79. package/decorator/enums/ControllerDecoratorParams.js +9 -9
  80. package/decorator/get.d.ts +2 -2
  81. package/decorator/get.js +36 -36
  82. package/decorator/index.d.ts +5 -3
  83. package/decorator/index.d.ts.map +1 -1
  84. package/decorator/index.js +13 -9
  85. package/decorator/post.d.ts +2 -2
  86. package/decorator/post.js +36 -36
  87. package/decorator/put.d.ts +3 -0
  88. package/decorator/put.d.ts.map +1 -0
  89. package/decorator/put.js +36 -0
  90. package/filters/AccessControl.d.ts +12 -12
  91. package/filters/AccessControl.d.ts.map +1 -1
  92. package/filters/AccessControl.js +83 -83
  93. package/filters/AccessRule.d.ts +82 -82
  94. package/filters/AccessRule.d.ts.map +1 -1
  95. package/filters/AccessRule.js +136 -137
  96. package/filters/auth/AuthInterface.d.ts +25 -25
  97. package/filters/auth/AuthInterface.js +2 -2
  98. package/filters/auth/AuthMethod.d.ts +37 -37
  99. package/filters/auth/AuthMethod.d.ts.map +1 -1
  100. package/filters/auth/AuthMethod.js +82 -82
  101. package/filters/auth/HttpBasicAuth.d.ts +23 -22
  102. package/filters/auth/HttpBasicAuth.d.ts.map +1 -1
  103. package/filters/auth/HttpBasicAuth.js +78 -72
  104. package/filters/auth/HttpBearerAuth.d.ts +17 -17
  105. package/filters/auth/HttpBearerAuth.d.ts.map +1 -1
  106. package/filters/auth/HttpBearerAuth.js +33 -32
  107. package/filters/auth/HttpHeaderAuth.d.ts +18 -14
  108. package/filters/auth/HttpHeaderAuth.d.ts.map +1 -1
  109. package/filters/auth/HttpHeaderAuth.js +64 -57
  110. package/filters/auth/JwtHttpBearerAuth.d.ts +20 -20
  111. package/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -1
  112. package/filters/auth/JwtHttpBearerAuth.js +87 -81
  113. package/filters/auth/KeyCloakHttpBearerAuth.d.ts +22 -22
  114. package/filters/auth/KeyCloakHttpBearerAuth.js +116 -116
  115. package/filters/auth/index.d.ts +4 -4
  116. package/filters/auth/index.js +11 -11
  117. package/filters/index.d.ts +2 -2
  118. package/filters/index.js +7 -7
  119. package/index.d.ts +28 -21
  120. package/index.d.ts.map +1 -1
  121. package/index.js +71 -60
  122. package/model/RouteDefinition.d.ts +6 -6
  123. package/model/RouteDefinition.js +8 -8
  124. package/package.json +22 -24
  125. package/rbac/AuthAssignment.d.ts +18 -18
  126. package/rbac/AuthAssignment.js +44 -44
  127. package/rbac/AuthItem.d.ts +26 -26
  128. package/rbac/AuthItem.js +51 -51
  129. package/rbac/AuthItemChild.d.ts +18 -18
  130. package/rbac/AuthItemChild.js +43 -43
  131. package/rbac/AuthManager.d.ts +111 -111
  132. package/rbac/AuthManager.d.ts.map +1 -1
  133. package/rbac/AuthManager.js +356 -355
  134. package/rbac/index.d.ts +5 -0
  135. package/rbac/index.d.ts.map +1 -0
  136. package/rbac/index.js +28 -0
  137. package/requiments/Glob.d.ts +2 -2
  138. package/requiments/Glob.js +10 -10
  139. package/requiments/ReflectUtil.js +24 -24
  140. package/requiments/Utils.d.ts +1 -8
  141. package/requiments/Utils.d.ts.map +1 -1
  142. package/requiments/Utils.js +115 -112
  143. package/validators/BooleanValidator.js +1 -1
  144. package/validators/CompareValidator.js +1 -1
  145. package/validators/DateValidator.js +1 -1
  146. package/validators/EmailValidator.js +1 -1
  147. package/validators/Validator.d.ts +17 -17
  148. package/validators/Validator.js +27 -27
  149. package/web/IdentityInterface.d.ts +55 -54
  150. package/web/IdentityInterface.d.ts.map +1 -1
  151. package/web/IdentityInterface.js +8 -8
  152. package/web/WebUser.d.ts +71 -71
  153. package/web/WebUser.js +165 -165
package/base/Model.js CHANGED
@@ -1,507 +1,545 @@
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
- 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
- var sequelize_2 = require("sequelize");
29
- Object.defineProperty(exports, "DataTypes", { enumerable: true, get: function () { return sequelize_2.DataTypes; } });
30
- Object.defineProperty(exports, "NOW", { enumerable: true, get: function () { return sequelize_2.NOW; } });
31
- /**
32
- * ValidateMe.init({
33
- bar: {
34
- type: Sequelize.STRING,
35
- validate: {
36
- is: ["^[a-z]+$",'i'], // will only allow letters
37
- is: /^[a-z]+$/i, // same as the previous example using real RegExp
38
- not: ["[a-z]",'i'], // will not allow letters
39
- isEmail: true, // checks for email format (foo@bar.com)
40
- isUrl: true, // checks for url format (http://foo.com)
41
- isIP: true, // checks for IPv4 (129.89.23.1) or IPv6 format
42
- isIPv4: true, // checks for IPv4 (129.89.23.1)
43
- isIPv6: true, // checks for IPv6 format
44
- isAlpha: true, // will only allow letters
45
- isAlphanumeric: true, // will only allow alphanumeric characters, so "_abc" will fail
46
- isNumeric: true, // will only allow numbers
47
- isInt: true, // checks for valid integers
48
- isFloat: true, // checks for valid floating point numbers
49
- isDecimal: true, // checks for any numbers
50
- isLowercase: true, // checks for lowercase
51
- isUppercase: true, // checks for uppercase
52
- notNull: true, // won't allow null
53
- isNull: true, // only allows null
54
- notEmpty: true, // don't allow empty strings
55
- equals: 'specific value', // only allow a specific value
56
- contains: 'foo', // force specific substrings
57
- notIn: [['foo', 'bar']], // check the value is not one of these
58
- isIn: [['foo', 'bar']], // check the value is one of these
59
- notContains: 'bar', // don't allow specific substrings
60
- len: [2,10], // only allow values with length between 2 and 10
61
- isUUID: 4, // only allow uuids
62
- isDate: true, // only allow date strings
63
- isAfter: "2011-11-05", // only allow date strings after a specific date
64
- isBefore: "2011-11-05", // only allow date strings before a specific date
65
- max: 23, // only allow values <= 23
66
- min: 23, // only allow values >= 23
67
- isCreditCard: true, // check for valid credit card numbers
68
-
69
- // Examples of custom validators:
70
- isEven(value) {
71
- if (parseInt(value) % 2 !== 0) {
72
- throw new Error('Only even values are allowed!');
73
- }
74
- }
75
- isGreaterThanOtherField(value) {
76
- if (parseInt(value) <= parseInt(this.otherField)) {
77
- throw new Error('Bar must be greater than otherField.');
78
- }
79
- }
80
- }
81
- }
82
- }, { sequelize });
83
- */
84
- class Model extends Component_1.Component {
85
- constructor(sequelize) {
86
- super();
87
- this._attributes = {};
88
- this._errors = {};
89
- this._tableName = this.alias();
90
- BaseChyz_1.default.debug("Model constructor", this._tableName);
91
- // this._sequelize = BaseChyz.getComponent("db").db;
92
- if (sequelize != null)
93
- this._sequelize = sequelize;
94
- else
95
- this._sequelize = this.getDb();
96
- if (!Utils_1.Utils.isEmpty(this.attributes())) {
97
- this._model = this._sequelize.define(this._tableName, this.attributes(), {
98
- tableName: this.tableName(),
99
- timestamps: false,
100
- createdAt: false,
101
- updateAt: false
102
- });
103
- }
104
- else {
105
- throw new InvalidConfigException_1.InvalidConfigException(BaseChyz_1.default.t("Invalid model configuration, is not emty attributes"));
106
- }
107
- // this.init();
108
- }
109
- /**
110
- * Returns the database connection used by this AR class.
111
- * By default, the "db" application component is used as the database connection.
112
- * You may override this method if you want to use a different database connection.
113
- * @return Connection the database connection used by this AR class.
114
- */
115
- getDb() {
116
- return BaseChyz_1.default.getComponent("db").db;
117
- }
118
- getDbConnection() {
119
- return BaseChyz_1.default.getComponent("db");
120
- }
121
- get sequelize() {
122
- return this._sequelize;
123
- }
124
- set sequelize(value) {
125
- this._sequelize = value;
126
- }
127
- provider() {
128
- return this._sequelize;
129
- }
130
- /**
131
- *
132
- */
133
- get errors() {
134
- return this._errors;
135
- }
136
- set errors(value) {
137
- this._errors = value;
138
- }
139
- init() {
140
- BaseChyz_1.default.debug("Model init....", this.constructor.name);
141
- /**
142
- * init buraya
143
- */
144
- BaseChyz_1.default.debug("Relation init....", this.constructor.name);
145
- for (const relation of this.relations()) {
146
- let m = relation.model;
147
- if (relation.type == "hasOne") {
148
- // @ts-ignore
149
- delete relation.model;
150
- this.model().hasOne(m, relation);
151
- }
152
- //
153
- if (relation.type == "hasMany") {
154
- // @ts-ignore
155
- delete relation.model;
156
- this.model().hasMany(m, relation);
157
- }
158
- if (relation.type == "belongsTo") {
159
- // @ts-ignore
160
- delete relation.model;
161
- this.model().belongsTo(m, relation);
162
- }
163
- if (relation.type == "belongsToMany") {
164
- // @ts-ignore
165
- delete relation.model;
166
- this.model().belongsToMany(m, relation);
167
- }
168
- }
169
- }
170
- alias() {
171
- return this.constructor.name;
172
- }
173
- tableName() {
174
- return this._tableName;
175
- }
176
- formName() {
177
- return this.constructor.name;
178
- }
179
- rules() {
180
- return [];
181
- }
182
- setModel(value) {
183
- this._model = value;
184
- }
185
- model() {
186
- return this._model;
187
- }
188
- save(params = {}, options = {}) {
189
- return __awaiter(this, void 0, void 0, function* () {
190
- // now instantiate an object
191
- let p = Object.assign(params, this._attributes);
192
- let result;
193
- try {
194
- result = yield this.model().create(p, options);
195
- }
196
- catch (e) {
197
- BaseChyz_1.default.debug(`Model[${this.constructor.name}].create`, e);
198
- if (e instanceof sequelize_1.ValidationError) {
199
- let validationErrorItems = e.errors;
200
- validationErrorItems.forEach(({ message, path }) => {
201
- // @ts-ignore
202
- this._errors[path] = message;
203
- });
204
- return false;
205
- }
206
- else if (e instanceof sequelize_1.DatabaseError) {
207
- }
208
- else if (e instanceof sequelize_1.TimeoutError) {
209
- }
210
- else if (e instanceof sequelize_1.UniqueConstraintError) {
211
- }
212
- else if (e instanceof sequelize_1.ForeignKeyConstraintError) {
213
- }
214
- else if (e instanceof sequelize_1.ExclusionConstraintError) {
215
- }
216
- throw new Exception_1.Exception(e.message, this.errors, e.code);
217
- }
218
- return result;
219
- });
220
- }
221
- bulkCreate(params = {}, options = {}) {
222
- return __awaiter(this, void 0, void 0, function* () {
223
- // now instantiate an object
224
- let p = Object.assign(params, this._attributes);
225
- let result;
226
- try {
227
- result = yield this.model().bulkCreate(p, options);
228
- }
229
- catch (e) {
230
- BaseChyz_1.default.debug(`Model[${this.constructor.name}].bulkCreate`, 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
- });
253
- }
254
- update(params = {}, options = {}) {
255
- let p = Object.assign(params, this._attributes);
256
- return this.model().update(p, options);
257
- }
258
- delete(params = {}, options = {}) {
259
- let p = Object.assign(params, this._attributes);
260
- return this.model().delete(p, options);
261
- }
262
- /**
263
- * 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.
264
- *
265
- * By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc). Note that since this is a raw query, the metadata are dialect specific. Some dialects return the metadata "within" the results object (as properties on an array). However, two arguments will always be returned, but for MSSQL and MySQL it will be two references to the same object.
266
- *
267
- * const [results, metadata] = await sequelize.query("UPDATE users SET y = 42 WHERE x = 12");
268
- * // Results will be an empty array and metadata will contain the number of affected rows.
269
- *
270
- * In cases where you don't need to access the metadata you can pass in a query type to tell sequelize how to format the results. For example, for a simple select query you could do:
271
- *
272
- * const { QueryTypes } = require('@sequelize/core');
273
- * const users = await sequelize.query("SELECT * FROM `users`", { type: QueryTypes.SELECT });
274
- * // We didn't need to destructure the result here - the results were returned directly
275
- *
276
- * Several other query types are available. Peek into the source for details.
277
- *
278
- * A second option is the model. If you pass a model the returned data will be instances of that model.
279
- *
280
- * // Callee is the model definition. This allows you to easily map a query to a predefined model
281
- * const projects = await sequelize.query('SELECT * FROM projects', {
282
- * model: Projects,
283
- * mapToModel: true // pass true here if you have any mapped fields
284
- * });
285
- * // Each element of `projects` is now an instance of Project
286
- *
287
- * See more options in the query API reference. Some examples:
288
- * ``
289
- * const { QueryTypes } = require('@sequelize/core');
290
- * await sequelize.query('SELECT 1', {
291
- * // A function (or false) for logging your queries
292
- * // Will get called for every SQL query that gets sent
293
- * // to the server.
294
- * logging: console.log,
295
- *
296
- * // If plain is true, then sequelize will only return the first
297
- * // record of the result set. In case of false it will return all records.
298
- * plain: false,
299
- *
300
- * // Set this to true if you don't have a model definition for your query.
301
- * raw: false,
302
- *
303
- * // The type of query you are executing. The query type affects how results are formatted before they are passed back.
304
- * type: QueryTypes.SELECT
305
- * });
306
- *``
307
- * // Note the second argument being null!
308
- * // Even if we declared a callee here, the raw: true would
309
- * // supersede and return a raw object.
310
- * console.log(await sequelize.query('SELECT * FROM projects', { raw: true }));
311
- *
312
- * ##"Dotted" attributes and the nest option
313
- *
314
- * If an attribute name of the table contains dots, the resulting objects can become nested objects by setting the nest: true option. This is achieved with dottie.js under the hood. See below:
315
- *
316
- * Without nest: true:
317
- * ``
318
- * const { QueryTypes } = require('@sequelize/core');
319
- * const records = await sequelize.query('select 1 as `foo.bar.baz`', {
320
- * type: QueryTypes.SELECT
321
- * });
322
- * console.log(JSON.stringify(records[0], null, 2));
323
- *
324
- * {
325
- * "foo.bar.baz": 1
326
- * }
327
- *
328
- * With nest: true:
329
- *
330
- * const { QueryTypes } = require('@sequelize/core');
331
- * const records = await sequelize.query('select 1 as `foo.bar.baz`', {
332
- * nest: true,
333
- * type: QueryTypes.SELECT
334
- * });
335
- * console.log(JSON.stringify(records[0], null, 2));
336
- *
337
- * {
338
- * "foo": {
339
- * "bar": {
340
- * "baz": 1
341
- * }
342
- * }
343
- * }
344
- * ``
345
- * ##Replacements
346
- *
347
- * Replacements in a query can be done in two different ways, either using named parameters (starting with :), or unnamed, represented by a ?. Replacements are passed in the options object.
348
- *
349
- * If an array is passed, ? will be replaced in the order that they appear in the array
350
- * If an object is passed, :key will be replaced with the keys from that object. If the object contains keys not found in the query or vice versa, an exception will be thrown.
351
- * ``
352
- * const { QueryTypes } = require('@sequelize/core');
353
- *
354
- * await sequelize.query(
355
- * 'SELECT * FROM projects WHERE status = ?',
356
- * {
357
- * replacements: ['active'],
358
- * type: QueryTypes.SELECT
359
- * }
360
- * );
361
- *
362
- * await sequelize.query(
363
- * 'SELECT * FROM projects WHERE status = :status',
364
- * {
365
- * replacements: { status: 'active' },
366
- * type: QueryTypes.SELECT
367
- * }
368
- * );
369
- * ``
370
- * Array replacements will automatically be handled, the following query searches for projects where the status matches an array of values.
371
- * ``
372
- * const { QueryTypes } = require('@sequelize/core');
373
- *
374
- * await sequelize.query(
375
- * 'SELECT * FROM projects WHERE status IN(:status)',
376
- * {
377
- * replacements: { status: ['active', 'inactive'] },
378
- * type: QueryTypes.SELECT
379
- * }
380
- * );
381
- * ``
382
- * To use the wildcard operator %, append it to your replacement. The following query matches users with names that start with 'ben'.
383
- * ``
384
- * const { QueryTypes } = require('@sequelize/core');
385
- *
386
- * await sequelize.query(
387
- * 'SELECT * FROM users WHERE name LIKE :search_name',
388
- * {
389
- * replacements: { search_name: 'ben%' },
390
- * type: QueryTypes.SELECT
391
- * }
392
- * ); ``
393
- *
394
- * ##Bind Parameter
395
- *
396
- * Bind parameters are like replacements. Except replacements are escaped and inserted into the query by sequelize before the query is sent to the database, while bind parameters are sent to the database outside the SQL query text. A query can have either bind parameters or replacements. Bind parameters are referred to by either $1, $2, ... (numeric) or $key (alpha-numeric). This is independent of the dialect.
397
- *
398
- * If an array is passed, $1 is bound to the 1st element in the array (bind[0])
399
- * If an object is passed, $key is bound to object['key']. Each key must begin with a non-numeric char. $1 is not a valid key, even if object['1'] exists.
400
- * In either case $$ can be used to escape a literal $ sign.
401
- *
402
- * The array or object must contain all bound values or Sequelize will throw an exception. This applies even to cases in which the database may ignore the bound parameter.
403
- *
404
- * The database may add further restrictions to this. Bind parameters cannot be SQL keywords, nor table or column names. They are also ignored in quoted text or data. In PostgreSQL it may also be needed to typecast them, if the type cannot be inferred from the context $1::varchar.
405
- *``
406
- * const { QueryTypes } = require('@sequelize/core');
407
- *
408
- * await sequelize.query(
409
- * 'SELECT *, "text with literal $$1 and literal $$status" as t FROM projects WHERE status = $1',
410
- * {
411
- * bind: ['active'],
412
- * type: QueryTypes.SELECT
413
- * }
414
- * ); ``
415
- *
416
- * `` await sequelize.query(
417
- * 'SELECT *, "text with literal $$1 and literal $$status" as t FROM projects WHERE status = $status',
418
- * {
419
- * bind: { status: 'active' },
420
- * type: QueryTypes.SELECT
421
- * }
422
- * );``
423
- * @param query
424
- */
425
- rawQuery(query, options = { type: sequelize_1.QueryTypes.SELECT, nest: true }) {
426
- return __awaiter(this, void 0, void 0, function* () {
427
- return yield this.model().query(query, options);
428
- });
429
- }
430
- /**
431
- *
432
- * @param args
433
- */
434
- findOne(...args) {
435
- return this._model.findOne(...arguments);
436
- }
437
- /**
438
- *
439
- * @param args
440
- */
441
- findAll(...args) {
442
- return this._model.findAll(...arguments);
443
- }
444
- /**
445
- * return {count : number , rows: any}
446
- * @param args
447
- */
448
- findAndCountAll(...args) {
449
- return this._model.findAndCountAll(...arguments);
450
- }
451
- validate() {
452
- }
453
- /**
454
- *
455
- * @param data
456
- * @param formName
457
- */
458
- load(data, formName = null) {
459
- let scope = formName === null ? this.formName() : formName;
460
- if (scope === '' && !Utils_1.Utils.isEmpty(data)) {
461
- this.setAttribute(data);
462
- return true;
463
- }
464
- else if (data[scope]) {
465
- this.setAttribute(data[scope]);
466
- return true;
467
- }
468
- return false;
469
- }
470
- bulkLoad(data, formName = null) {
471
- let scope = formName === null ? this.formName() : formName;
472
- if (scope === '' && !Utils_1.Utils.isEmpty(data)) {
473
- this.setAttribute(data);
474
- return true;
475
- }
476
- else if (data[scope]) {
477
- this.setAttribute(data[scope]);
478
- return true;
479
- }
480
- return false;
481
- }
482
- setAttribute(values, safeOnly = true) {
483
- if (values instanceof Object) {
484
- let attributes = this.attributes();
485
- for (const valueKey in values) {
486
- if (Object.keys(attributes).indexOf(valueKey) != -1) {
487
- // @ts-ignore
488
- BaseChyz_1.default.debug("Model[" + this.formName() + "] attributes value set ", valueKey, values[valueKey]);
489
- this._attributes[valueKey] = values[valueKey];
490
- }
491
- }
492
- }
493
- }
494
- attributes() {
495
- return {};
496
- }
497
- /**
498
- * relation return array
499
- * [
500
- *
501
- * ]
502
- */
503
- relations() {
504
- return [];
505
- }
506
- }
507
- exports.Model = Model;
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
+ 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; } });
32
+ /**
33
+ * ValidateMe.init({
34
+ bar: {
35
+ type: Sequelize.STRING,
36
+ validate: {
37
+ is: ["^[a-z]+$",'i'], // will only allow letters
38
+ is: /^[a-z]+$/i, // same as the previous example using real RegExp
39
+ not: ["[a-z]",'i'], // will not allow letters
40
+ isEmail: true, // checks for email format (foo@bar.com)
41
+ isUrl: true, // checks for url format (http://foo.com)
42
+ isIP: true, // checks for IPv4 (129.89.23.1) or IPv6 format
43
+ isIPv4: true, // checks for IPv4 (129.89.23.1)
44
+ isIPv6: true, // checks for IPv6 format
45
+ isAlpha: true, // will only allow letters
46
+ isAlphanumeric: true, // will only allow alphanumeric characters, so "_abc" will fail
47
+ isNumeric: true, // will only allow numbers
48
+ isInt: true, // checks for valid integers
49
+ isFloat: true, // checks for valid floating point numbers
50
+ isDecimal: true, // checks for any numbers
51
+ isLowercase: true, // checks for lowercase
52
+ isUppercase: true, // checks for uppercase
53
+ notNull: true, // won't allow null
54
+ isNull: true, // only allows null
55
+ notEmpty: true, // don't allow empty strings
56
+ equals: 'specific value', // only allow a specific value
57
+ contains: 'foo', // force specific substrings
58
+ notIn: [['foo', 'bar']], // check the value is not one of these
59
+ isIn: [['foo', 'bar']], // check the value is one of these
60
+ notContains: 'bar', // don't allow specific substrings
61
+ len: [2,10], // only allow values with length between 2 and 10
62
+ isUUID: 4, // only allow uuids
63
+ isDate: true, // only allow date strings
64
+ isAfter: "2011-11-05", // only allow date strings after a specific date
65
+ isBefore: "2011-11-05", // only allow date strings before a specific date
66
+ max: 23, // only allow values <= 23
67
+ min: 23, // only allow values >= 23
68
+ isCreditCard: true, // check for valid credit card numbers
69
+
70
+ // Examples of custom validators:
71
+ isEven(value) {
72
+ if (parseInt(value) % 2 !== 0) {
73
+ throw new Error('Only even values are allowed!');
74
+ }
75
+ }
76
+ isGreaterThanOtherField(value) {
77
+ if (parseInt(value) <= parseInt(this.otherField)) {
78
+ throw new Error('Bar must be greater than otherField.');
79
+ }
80
+ }
81
+ }
82
+ }
83
+ }, { sequelize });
84
+ */
85
+ class Model extends Component_1.Component {
86
+ constructor(sequelize) {
87
+ super();
88
+ this._attributes = {};
89
+ this._errors = {};
90
+ this._tableName = this.alias();
91
+ BaseChyz_1.default.debug("Model constructor", this._tableName);
92
+ // this._sequelize = BaseChyz.getComponent("db").db;
93
+ if (sequelize != null) {
94
+ this._provider = sequelize;
95
+ }
96
+ else
97
+ this._provider = this.getDb();
98
+ /**
99
+ * override query
100
+ */
101
+ // this._provider.query = async (sql: string | { query: string; values: unknown[] },options?: QueryOptions | QueryOptionsWithType<QueryTypes.RAW> | undefined,) => {
102
+ // try {
103
+ // console.log(this,Sequelize.prototype.query.apply(this, [sql, options]))
104
+ // return Sequelize.prototype.query.apply(this, [sql, options]);
105
+ // } catch (err: any) {
106
+ // console.log(err)
107
+ // throw new DatabaseError(err);
108
+ // }
109
+ // };
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") {
113
+ // e.stack = e.original;
114
+ if (err instanceof sequelize_1.DatabaseError) {
115
+ // @ts-ignore
116
+ delete err.parent;
117
+ // @ts-ignore
118
+ delete err.original;
119
+ }
120
+ }
121
+ throw new DataErrorDbException_1.DataErrorDbException(err);
122
+ });
123
+ // try {
124
+ // let r =
125
+ // console.log(r)
126
+ // } catch (err: any) {
127
+ // console.log(err)
128
+ // throw new DatabaseError(err);
129
+ // }
130
+ };
131
+ if (!Utils_1.Utils.isEmpty(this.attributes())) {
132
+ this._model = this._provider.define(this._tableName, this.attributes(), {
133
+ tableName: this.tableName(),
134
+ timestamps: false,
135
+ createdAt: false,
136
+ updateAt: false
137
+ });
138
+ }
139
+ else {
140
+ throw new InvalidConfigException_1.InvalidConfigException(BaseChyz_1.default.t("Invalid model configuration, is not emty attributes"));
141
+ }
142
+ // this.init();
143
+ }
144
+ /**
145
+ * Returns the database connection used by this AR class.
146
+ * By default, the "db" application component is used as the database connection.
147
+ * You may override this method if you want to use a different database connection.
148
+ * @return Connection the database connection used by this AR class.
149
+ */
150
+ getDb() {
151
+ return BaseChyz_1.default.getComponent("db") ? BaseChyz_1.default.getComponent("db").db : null;
152
+ }
153
+ getDbConnection() {
154
+ return BaseChyz_1.default.getComponent("db");
155
+ }
156
+ get provider() {
157
+ return this._provider;
158
+ }
159
+ set provider(value) {
160
+ this._provider = value;
161
+ }
162
+ /**
163
+ *
164
+ */
165
+ get errors() {
166
+ return this._errors;
167
+ }
168
+ set errors(value) {
169
+ this._errors = value;
170
+ }
171
+ init() {
172
+ BaseChyz_1.default.debug("Model init....", this.constructor.name);
173
+ /**
174
+ * init buraya
175
+ */
176
+ BaseChyz_1.default.debug("Relation init....", this.constructor.name);
177
+ for (const relation of this.relations()) {
178
+ let m = relation.model;
179
+ if (relation.type == "hasOne") {
180
+ // @ts-ignore
181
+ delete relation.model;
182
+ this.model().hasOne(m, relation);
183
+ }
184
+ //
185
+ if (relation.type == "hasMany") {
186
+ // @ts-ignore
187
+ delete relation.model;
188
+ this.model().hasMany(m, relation);
189
+ }
190
+ if (relation.type == "belongsTo") {
191
+ // @ts-ignore
192
+ delete relation.model;
193
+ this.model().belongsTo(m, relation);
194
+ }
195
+ if (relation.type == "belongsToMany") {
196
+ // @ts-ignore
197
+ delete relation.model;
198
+ this.model().belongsToMany(m, relation);
199
+ }
200
+ }
201
+ }
202
+ alias() {
203
+ return this.constructor.name;
204
+ }
205
+ tableName() {
206
+ return this._tableName;
207
+ }
208
+ formName() {
209
+ return this.constructor.name;
210
+ }
211
+ rules() {
212
+ return [];
213
+ }
214
+ setModel(value) {
215
+ this._model = value;
216
+ }
217
+ model() {
218
+ return this._model;
219
+ }
220
+ save(params = {}, options = {}) {
221
+ return __awaiter(this, void 0, void 0, function* () {
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);
228
+ }
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
+ });
253
+ }
254
+ bulkCreate(params = {}, options = {}) {
255
+ return __awaiter(this, void 0, void 0, function* () {
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);
262
+ }
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
+ });
287
+ }
288
+ update(params = {}, options = {}) {
289
+ this.errors = {};
290
+ let p = Object.assign(params, this._attributes);
291
+ return this.model().update(p, options);
292
+ }
293
+ delete(params = {}, options = {}) {
294
+ this.errors = {};
295
+ let p = Object.assign(params, this._attributes);
296
+ return this.model().destroy(p, options);
297
+ }
298
+ /**
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.
300
+ *
301
+ * By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc). Note that since this is a raw query, the metadata are dialect specific. Some dialects return the metadata "within" the results object (as properties on an array). However, two arguments will always be returned, but for MSSQL and MySQL it will be two references to the same object.
302
+ *
303
+ * const [results, metadata] = await sequelize.query("UPDATE users SET y = 42 WHERE x = 12");
304
+ * // Results will be an empty array and metadata will contain the number of affected rows.
305
+ *
306
+ * In cases where you don't need to access the metadata you can pass in a query type to tell sequelize how to format the results. For example, for a simple select query you could do:
307
+ *
308
+ * const { QueryTypes } = require('@sequelize/core');
309
+ * const users = await sequelize.query("SELECT * FROM `users`", { type: QueryTypes.SELECT });
310
+ * // We didn't need to destructure the result here - the results were returned directly
311
+ *
312
+ * Several other query types are available. Peek into the source for details.
313
+ *
314
+ * A second option is the model. If you pass a model the returned data will be instances of that model.
315
+ *
316
+ * // Callee is the model definition. This allows you to easily map a query to a predefined model
317
+ * const projects = await sequelize.query('SELECT * FROM projects', {
318
+ * model: Projects,
319
+ * mapToModel: true // pass true here if you have any mapped fields
320
+ * });
321
+ * // Each element of `projects` is now an instance of Project
322
+ *
323
+ * See more options in the query API reference. Some examples:
324
+ * ``
325
+ * const { QueryTypes } = require('@sequelize/core');
326
+ * await sequelize.query('SELECT 1', {
327
+ * // A function (or false) for logging your queries
328
+ * // Will get called for every SQL query that gets sent
329
+ * // to the server.
330
+ * logging: console.log,
331
+ *
332
+ * // If plain is true, then sequelize will only return the first
333
+ * // record of the result set. In case of false it will return all records.
334
+ * plain: false,
335
+ *
336
+ * // Set this to true if you don't have a model definition for your query.
337
+ * raw: false,
338
+ *
339
+ * // The type of query you are executing. The query type affects how results are formatted before they are passed back.
340
+ * type: QueryTypes.SELECT
341
+ * });
342
+ *``
343
+ * // Note the second argument being null!
344
+ * // Even if we declared a callee here, the raw: true would
345
+ * // supersede and return a raw object.
346
+ * console.log(await sequelize.query('SELECT * FROM projects', { raw: true }));
347
+ *
348
+ * ##"Dotted" attributes and the nest option
349
+ *
350
+ * If an attribute name of the table contains dots, the resulting objects can become nested objects by setting the nest: true option. This is achieved with dottie.js under the hood. See below:
351
+ *
352
+ * Without nest: true:
353
+ * ``
354
+ * const { QueryTypes } = require('@sequelize/core');
355
+ * const records = await sequelize.query('select 1 as `foo.bar.baz`', {
356
+ * type: QueryTypes.SELECT
357
+ * });
358
+ * console.log(JSON.stringify(records[0], null, 2));
359
+ *
360
+ * {
361
+ * "foo.bar.baz": 1
362
+ * }
363
+ *
364
+ * With nest: true:
365
+ *
366
+ * const { QueryTypes } = require('@sequelize/core');
367
+ * const records = await sequelize.query('select 1 as `foo.bar.baz`', {
368
+ * nest: true,
369
+ * type: QueryTypes.SELECT
370
+ * });
371
+ * console.log(JSON.stringify(records[0], null, 2));
372
+ *
373
+ * {
374
+ * "foo": {
375
+ * "bar": {
376
+ * "baz": 1
377
+ * }
378
+ * }
379
+ * }
380
+ * ``
381
+ * ##Replacements
382
+ *
383
+ * Replacements in a query can be done in two different ways, either using named parameters (starting with :), or unnamed, represented by a ?. Replacements are passed in the options object.
384
+ *
385
+ * If an array is passed, ? will be replaced in the order that they appear in the array
386
+ * If an object is passed, :key will be replaced with the keys from that object. If the object contains keys not found in the query or vice versa, an exception will be thrown.
387
+ * ``
388
+ * const { QueryTypes } = require('@sequelize/core');
389
+ *
390
+ * await sequelize.query(
391
+ * 'SELECT * FROM projects WHERE status = ?',
392
+ * {
393
+ * replacements: ['active'],
394
+ * type: QueryTypes.SELECT
395
+ * }
396
+ * );
397
+ *
398
+ * await sequelize.query(
399
+ * 'SELECT * FROM projects WHERE status = :status',
400
+ * {
401
+ * replacements: { status: 'active' },
402
+ * type: QueryTypes.SELECT
403
+ * }
404
+ * );
405
+ * ``
406
+ * Array replacements will automatically be handled, the following query searches for projects where the status matches an array of values.
407
+ * ``
408
+ * const { QueryTypes } = require('@sequelize/core');
409
+ *
410
+ * await sequelize.query(
411
+ * 'SELECT * FROM projects WHERE status IN(:status)',
412
+ * {
413
+ * replacements: { status: ['active', 'inactive'] },
414
+ * type: QueryTypes.SELECT
415
+ * }
416
+ * );
417
+ * ``
418
+ * To use the wildcard operator %, append it to your replacement. The following query matches users with names that start with 'ben'.
419
+ * ``
420
+ * const { QueryTypes } = require('@sequelize/core');
421
+ *
422
+ * await sequelize.query(
423
+ * 'SELECT * FROM users WHERE name LIKE :search_name',
424
+ * {
425
+ * replacements: { search_name: 'ben%' },
426
+ * type: QueryTypes.SELECT
427
+ * }
428
+ * ); ``
429
+ *
430
+ * ##Bind Parameter
431
+ *
432
+ * Bind parameters are like replacements. Except replacements are escaped and inserted into the query by sequelize before the query is sent to the database, while bind parameters are sent to the database outside the SQL query text. A query can have either bind parameters or replacements. Bind parameters are referred to by either $1, $2, ... (numeric) or $key (alpha-numeric). This is independent of the dialect.
433
+ *
434
+ * If an array is passed, $1 is bound to the 1st element in the array (bind[0])
435
+ * If an object is passed, $key is bound to object['key']. Each key must begin with a non-numeric char. $1 is not a valid key, even if object['1'] exists.
436
+ * In either case $$ can be used to escape a literal $ sign.
437
+ *
438
+ * The array or object must contain all bound values or Sequelize will throw an exception. This applies even to cases in which the database may ignore the bound parameter.
439
+ *
440
+ * The database may add further restrictions to this. Bind parameters cannot be SQL keywords, nor table or column names. They are also ignored in quoted text or data. In PostgreSQL it may also be needed to typecast them, if the type cannot be inferred from the context $1::varchar.
441
+ *``
442
+ * const { QueryTypes } = require('@sequelize/core');
443
+ *
444
+ * await sequelize.query(
445
+ * 'SELECT *, "text with literal $$1 and literal $$status" as t FROM projects WHERE status = $1',
446
+ * {
447
+ * bind: ['active'],
448
+ * type: QueryTypes.SELECT
449
+ * }
450
+ * ); ``
451
+ *
452
+ * `` await sequelize.query(
453
+ * 'SELECT *, "text with literal $$1 and literal $$status" as t FROM projects WHERE status = $status',
454
+ * {
455
+ * bind: { status: 'active' },
456
+ * type: QueryTypes.SELECT
457
+ * }
458
+ * );``
459
+ * @param query
460
+ * @param options
461
+ */
462
+ rawQuery(query, options = { type: sequelize_1.QueryTypes.SELECT, nest: true }) {
463
+ return __awaiter(this, void 0, void 0, function* () {
464
+ this.errors = {};
465
+ return yield this.model().query(query, options);
466
+ });
467
+ }
468
+ /**
469
+ *
470
+ * @param args
471
+ */
472
+ findOne(...args) {
473
+ return this._model.findOne(...arguments);
474
+ }
475
+ /**
476
+ *
477
+ * @param args
478
+ */
479
+ findAll(...args) {
480
+ return this._model.findAll(...arguments);
481
+ }
482
+ /**
483
+ * return {count : number , rows: any}
484
+ * @param args
485
+ */
486
+ findAndCountAll(...args) {
487
+ return this._model.findAndCountAll(...arguments);
488
+ }
489
+ validate() {
490
+ }
491
+ /**
492
+ *
493
+ * @param data
494
+ * @param formName
495
+ */
496
+ load(data, formName = null) {
497
+ let scope = formName === null ? this.formName() : formName;
498
+ if (scope === '' && !Utils_1.Utils.isEmpty(data)) {
499
+ this.setAttribute(data);
500
+ return true;
501
+ }
502
+ else if (data[scope]) {
503
+ this.setAttribute(data[scope]);
504
+ return true;
505
+ }
506
+ return false;
507
+ }
508
+ bulkLoad(data, formName = null) {
509
+ let scope = formName === null ? this.formName() : formName;
510
+ if (scope === '' && !Utils_1.Utils.isEmpty(data)) {
511
+ this.setAttribute(data);
512
+ return true;
513
+ }
514
+ else if (data[scope]) {
515
+ this.setAttribute(data[scope]);
516
+ return true;
517
+ }
518
+ return false;
519
+ }
520
+ setAttribute(values, safeOnly = true) {
521
+ if (values instanceof Object) {
522
+ let attributes = this.attributes();
523
+ for (const valueKey in values) {
524
+ if (Object.keys(attributes).indexOf(valueKey) != -1) {
525
+ // @ts-ignore
526
+ BaseChyz_1.default.debug("Model[" + this.formName() + "] attributes value set ", valueKey, values[valueKey]);
527
+ this._attributes[valueKey] = values[valueKey];
528
+ }
529
+ }
530
+ }
531
+ }
532
+ attributes() {
533
+ return {};
534
+ }
535
+ /**
536
+ * relation return array
537
+ * [
538
+ *
539
+ * ]
540
+ */
541
+ relations() {
542
+ return [];
543
+ }
544
+ }
545
+ exports.Model = Model;