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.
- package/BaseChyz.d.ts +73 -56
- package/BaseChyz.d.ts.map +1 -1
- package/BaseChyz.js +569 -404
- package/README.md +1 -1
- package/base/ActionFilter.d.ts +32 -32
- package/base/ActionFilter.d.ts.map +1 -1
- package/base/ActionFilter.js +82 -82
- package/base/BadRequestHttpException.d.ts +6 -0
- package/base/BadRequestHttpException.d.ts.map +1 -0
- package/base/BadRequestHttpException.js +17 -0
- package/base/BaseError.d.ts +43 -10
- package/base/BaseError.d.ts.map +1 -1
- package/base/BaseError.js +58 -26
- package/base/Behavior.d.ts +3 -3
- package/base/Behavior.js +7 -7
- package/base/CBaseObject.d.ts +4 -4
- package/base/CBaseObject.d.ts.map +1 -1
- package/base/CBaseObject.js +16 -16
- package/base/CEvents.d.ts +13 -0
- package/base/CEvents.d.ts.map +1 -0
- package/base/CEvents.js +24 -0
- package/base/CRequest.d.ts +1 -1
- package/base/CRequest.js +10 -10
- package/base/CWebController.d.ts +43 -43
- package/base/CWebController.d.ts.map +1 -1
- package/base/CWebController.js +81 -74
- package/base/Component.d.ts +20 -20
- package/base/Component.d.ts.map +1 -1
- package/base/Component.js +57 -57
- package/base/Configurable.d.ts +2 -2
- package/base/Configurable.js +8 -8
- package/base/DataErrorDbException.d.ts +5 -5
- package/base/DataErrorDbException.d.ts.map +1 -1
- package/base/DataErrorDbException.js +17 -17
- package/base/DbConnection.d.ts +12 -12
- package/base/DbConnection.js +53 -53
- package/base/ForbiddenHttpException.d.ts +4 -4
- package/base/ForbiddenHttpException.d.ts.map +1 -1
- package/base/ForbiddenHttpException.js +16 -16
- package/base/InvalidArgumentException.d.ts +5 -5
- package/base/InvalidArgumentException.d.ts.map +1 -1
- package/base/InvalidArgumentException.js +17 -17
- package/base/InvalidConfigException.d.ts +5 -5
- package/base/InvalidConfigException.d.ts.map +1 -1
- package/base/InvalidConfigException.js +17 -17
- package/base/Logs.d.ts +21 -21
- package/base/Logs.d.ts.map +1 -1
- package/base/Logs.js +57 -57
- package/base/Model.d.ts +301 -298
- package/base/Model.d.ts.map +1 -1
- package/base/Model.js +545 -507
- package/base/ModelManager.d.ts +1 -1
- package/base/ModelManager.js +19 -19
- package/base/NotFoundHttpException.d.ts +5 -5
- package/base/NotFoundHttpException.d.ts.map +1 -1
- package/base/NotFoundHttpException.js +17 -17
- package/base/RestClient.d.ts +6 -6
- package/base/RestClient.d.ts.map +1 -1
- package/base/RestClient.js +25 -25
- package/base/UnauthorizedHttpException.d.ts +5 -5
- package/base/UnauthorizedHttpException.d.ts.map +1 -1
- package/base/UnauthorizedHttpException.js +17 -17
- package/base/ValidationHttpException.d.ts +5 -5
- package/base/ValidationHttpException.d.ts.map +1 -1
- package/base/ValidationHttpException.js +17 -17
- package/base/db/Exception.d.ts +6 -6
- package/base/db/Exception.js +15 -15
- package/base/index.d.ts +19 -18
- package/base/index.d.ts.map +1 -1
- package/base/index.js +41 -39
- package/decorator/Middleware.d.ts +3 -3
- package/decorator/Middleware.js +11 -11
- package/decorator/controller.d.ts +2 -2
- package/decorator/controller.js +24 -24
- package/decorator/delete.d.ts +3 -0
- package/decorator/delete.d.ts.map +1 -0
- package/decorator/delete.js +36 -0
- package/decorator/enums/ControllerDecoratorParams.d.ts +5 -5
- package/decorator/enums/ControllerDecoratorParams.js +9 -9
- package/decorator/get.d.ts +2 -2
- package/decorator/get.js +36 -36
- package/decorator/index.d.ts +5 -3
- package/decorator/index.d.ts.map +1 -1
- package/decorator/index.js +13 -9
- package/decorator/post.d.ts +2 -2
- package/decorator/post.js +36 -36
- package/decorator/put.d.ts +3 -0
- package/decorator/put.d.ts.map +1 -0
- package/decorator/put.js +36 -0
- package/filters/AccessControl.d.ts +12 -12
- package/filters/AccessControl.d.ts.map +1 -1
- package/filters/AccessControl.js +83 -83
- package/filters/AccessRule.d.ts +82 -82
- package/filters/AccessRule.d.ts.map +1 -1
- package/filters/AccessRule.js +136 -137
- package/filters/auth/AuthInterface.d.ts +25 -25
- package/filters/auth/AuthInterface.js +2 -2
- package/filters/auth/AuthMethod.d.ts +37 -37
- package/filters/auth/AuthMethod.d.ts.map +1 -1
- package/filters/auth/AuthMethod.js +82 -82
- package/filters/auth/HttpBasicAuth.d.ts +23 -22
- package/filters/auth/HttpBasicAuth.d.ts.map +1 -1
- package/filters/auth/HttpBasicAuth.js +78 -72
- package/filters/auth/HttpBearerAuth.d.ts +17 -17
- package/filters/auth/HttpBearerAuth.d.ts.map +1 -1
- package/filters/auth/HttpBearerAuth.js +33 -32
- package/filters/auth/HttpHeaderAuth.d.ts +18 -14
- package/filters/auth/HttpHeaderAuth.d.ts.map +1 -1
- package/filters/auth/HttpHeaderAuth.js +64 -57
- package/filters/auth/JwtHttpBearerAuth.d.ts +20 -20
- package/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -1
- package/filters/auth/JwtHttpBearerAuth.js +87 -81
- package/filters/auth/KeyCloakHttpBearerAuth.d.ts +22 -22
- package/filters/auth/KeyCloakHttpBearerAuth.js +116 -116
- package/filters/auth/index.d.ts +4 -4
- package/filters/auth/index.js +11 -11
- package/filters/index.d.ts +2 -2
- package/filters/index.js +7 -7
- package/index.d.ts +28 -21
- package/index.d.ts.map +1 -1
- package/index.js +71 -60
- package/model/RouteDefinition.d.ts +6 -6
- package/model/RouteDefinition.js +8 -8
- package/package.json +22 -24
- package/rbac/AuthAssignment.d.ts +18 -18
- package/rbac/AuthAssignment.js +44 -44
- package/rbac/AuthItem.d.ts +26 -26
- package/rbac/AuthItem.js +51 -51
- package/rbac/AuthItemChild.d.ts +18 -18
- package/rbac/AuthItemChild.js +43 -43
- package/rbac/AuthManager.d.ts +111 -111
- package/rbac/AuthManager.d.ts.map +1 -1
- package/rbac/AuthManager.js +356 -355
- package/rbac/index.d.ts +5 -0
- package/rbac/index.d.ts.map +1 -0
- package/rbac/index.js +28 -0
- package/requiments/Glob.d.ts +2 -2
- package/requiments/Glob.js +10 -10
- package/requiments/ReflectUtil.js +24 -24
- package/requiments/Utils.d.ts +1 -8
- package/requiments/Utils.d.ts.map +1 -1
- package/requiments/Utils.js +115 -112
- package/validators/BooleanValidator.js +1 -1
- package/validators/CompareValidator.js +1 -1
- package/validators/DateValidator.js +1 -1
- package/validators/EmailValidator.js +1 -1
- package/validators/Validator.d.ts +17 -17
- package/validators/Validator.js +27 -27
- package/web/IdentityInterface.d.ts +55 -54
- package/web/IdentityInterface.d.ts.map +1 -1
- package/web/IdentityInterface.js +8 -8
- package/web/WebUser.d.ts +71 -71
- 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
|
-
|
|
29
|
-
|
|
30
|
-
Object.defineProperty(exports, "
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
// now instantiate an object
|
|
224
|
-
let p = Object.assign(params, this._attributes);
|
|
225
|
-
let result;
|
|
226
|
-
try {
|
|
227
|
-
result = yield this.model().
|
|
228
|
-
}
|
|
229
|
-
catch (e) {
|
|
230
|
-
BaseChyz_1.default.debug(`Model[${this.constructor.name}].
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
this.
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
return
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
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;
|