@rws-framework/db 2.1.11 → 2.2.0

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 (49) hide show
  1. package/README.md +26 -17
  2. package/dist/decorators/TrackType.d.ts +1 -1
  3. package/dist/models/_model.d.ts +5 -116
  4. package/dist/models/_model.js +7 -497
  5. package/dist/models/core/RWSModel.d.ts +65 -0
  6. package/dist/models/core/RWSModel.js +375 -0
  7. package/dist/models/core/TimeSeriesModel.d.ts +7 -0
  8. package/dist/models/core/TimeSeriesModel.js +34 -0
  9. package/dist/models/index.d.ts +8 -0
  10. package/dist/models/index.js +12 -0
  11. package/dist/models/interfaces/IModel.d.ts +10 -0
  12. package/dist/models/interfaces/IModel.js +2 -0
  13. package/dist/models/interfaces/IRWSModelServices.d.ts +6 -0
  14. package/dist/models/interfaces/IRWSModelServices.js +2 -0
  15. package/dist/models/interfaces/OpModelType.d.ts +32 -0
  16. package/dist/models/interfaces/OpModelType.js +2 -0
  17. package/dist/models/types/RelationTypes.d.ts +24 -0
  18. package/dist/models/types/RelationTypes.js +2 -0
  19. package/dist/models/utils/ModelUtils.d.ts +10 -0
  20. package/dist/models/utils/ModelUtils.js +56 -0
  21. package/dist/models/utils/PaginationUtils.d.ts +5 -0
  22. package/dist/models/utils/PaginationUtils.js +32 -0
  23. package/dist/models/utils/RelationUtils copy.d.ts +13 -0
  24. package/dist/models/utils/RelationUtils copy.js +65 -0
  25. package/dist/models/utils/RelationUtils.d.ts +14 -0
  26. package/dist/models/utils/RelationUtils.js +65 -0
  27. package/dist/models/utils/TimeSeriesUtils.d.ts +11 -0
  28. package/dist/models/utils/TimeSeriesUtils.js +35 -0
  29. package/dist/services/DBService.d.ts +3 -2
  30. package/dist/services/DBService.js +5 -1
  31. package/dist/types/DbConfigHandler.d.ts +1 -1
  32. package/dist/types/FindParams.d.ts +5 -0
  33. package/package.json +1 -1
  34. package/src/decorators/TrackType.ts +2 -2
  35. package/src/models/_model.ts +26 -675
  36. package/src/models/core/RWSModel.ts +482 -0
  37. package/src/models/core/TimeSeriesModel.ts +19 -0
  38. package/src/models/index.ts +20 -0
  39. package/src/models/interfaces/IModel.ts +11 -0
  40. package/src/models/interfaces/IRWSModelServices.ts +7 -0
  41. package/src/models/interfaces/OpModelType.ts +49 -0
  42. package/src/models/types/RelationTypes.ts +25 -0
  43. package/src/models/utils/ModelUtils.ts +65 -0
  44. package/src/models/utils/PaginationUtils.ts +42 -0
  45. package/src/models/utils/RelationUtils.ts +76 -0
  46. package/src/models/utils/TimeSeriesUtils.ts +38 -0
  47. package/src/services/DBService.ts +14 -3
  48. package/src/types/DbConfigHandler.ts +2 -2
  49. package/src/types/FindParams.ts +10 -4
@@ -1,499 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __importStar = (this && this.__importStar) || (function () {
25
- var ownKeys = function(o) {
26
- ownKeys = Object.getOwnPropertyNames || function (o) {
27
- var ar = [];
28
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
- return ar;
30
- };
31
- return ownKeys(o);
32
- };
33
- return function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- })();
41
- var __metadata = (this && this.__metadata) || function (k, v) {
42
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
- };
2
+ /**
3
+ * @deprecated This file is deprecated. Import from 'models' directory instead.
4
+ */
44
5
  Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.RWSModel = exports.TrackType = void 0;
46
- const decorators_1 = require("../decorators");
47
- Object.defineProperty(exports, "TrackType", { enumerable: true, get: function () { return decorators_1.TrackType; } });
48
- const FieldsHelper_1 = require("../helper/FieldsHelper");
49
- class RWSModel {
50
- constructor(data) {
51
- if (!this.getCollection()) {
52
- throw new Error('Model must have a collection defined');
53
- }
54
- this.dbService = RWSModel.services.dbService;
55
- this.configService = RWSModel.services.configService;
56
- if (!data) {
57
- return;
58
- }
59
- if (!this.hasTimeSeries()) {
60
- this._fill(data);
61
- }
62
- else {
63
- throw new Error('Time Series not supported in synchronous constructor. Use `await Model.create(data)` static method to instantiate this model.');
64
- }
65
- }
66
- checkForInclusionWithThrow() {
67
- this.checkForInclusionWithThrow();
68
- }
69
- static checkForInclusionWithThrow(checkModelType) {
70
- if (!this.checkForInclusion(this.name)) {
71
- throw new Error('Model undefined: ' + this.name);
72
- }
73
- }
74
- checkForInclusion() {
75
- return this.checkForInclusion();
76
- }
77
- static checkForInclusion(checkModelType) {
78
- return this.loadModels().find((definedModel) => {
79
- return definedModel.name === checkModelType;
80
- }) !== undefined;
81
- }
82
- _fill(data) {
83
- for (const key in data) {
84
- if (data.hasOwnProperty(key)) {
85
- const meta = Reflect.getMetadata(`InverseTimeSeries:${key}`, this.constructor.prototype);
86
- if (meta) {
87
- data[key] = {
88
- create: data[key]
89
- };
90
- }
91
- else {
92
- this[key] = data[key];
93
- }
94
- }
95
- }
96
- return this;
97
- }
98
- hasRelation(key) {
99
- return !!this[key] && this[key] instanceof RWSModel;
100
- }
101
- bindRelation(key, relatedModel) {
102
- return {
103
- connect: {
104
- id: relatedModel.id
105
- }
106
- };
107
- }
108
- async _asyncFill(data, fullDataMode = false, allowRelations = true) {
109
- const collections_to_models = {};
110
- const timeSeriesIds = this.getTimeSeriesModelFields();
111
- const classFields = FieldsHelper_1.FieldsHelper.getAllClassFields(this.constructor);
112
- // Get both relation metadata types asynchronously
113
- const [relOneData, relManyData] = await Promise.all([
114
- this.getRelationOneMeta(classFields),
115
- this.getRelationManyMeta(classFields)
116
- ]);
117
- this.loadModels().forEach((model) => {
118
- collections_to_models[model.getCollection()] = model;
119
- });
120
- const seriesHydrationfields = [];
121
- if (allowRelations) {
122
- for (const key in relManyData) {
123
- if (!fullDataMode && this.constructor._CUT_KEYS.includes(key)) {
124
- continue;
125
- }
126
- const relMeta = relManyData[key];
127
- const relationEnabled = this.checkRelEnabled(relMeta.key);
128
- if (relationEnabled) {
129
- this[relMeta.key] = await relMeta.inversionModel.findBy({
130
- conditions: {
131
- [relMeta.foreignKey]: data.id
132
- },
133
- allowRelations: false
134
- });
135
- }
136
- }
137
- for (const key in relOneData) {
138
- if (!fullDataMode && this.constructor._CUT_KEYS.includes(key)) {
139
- continue;
140
- }
141
- const relMeta = relOneData[key];
142
- const relationEnabled = this.checkRelEnabled(relMeta.key);
143
- if (!data[relMeta.hydrationField] && relMeta.required) {
144
- throw new Error(`Relation field "${relMeta.hydrationField}" is required in model ${this.constructor.name}.`);
145
- }
146
- if (relationEnabled && data[relMeta.hydrationField]) {
147
- this[relMeta.key] = await relMeta.model.find(data[relMeta.hydrationField], { allowRelations: false });
148
- }
149
- else if (relationEnabled && !data[relMeta.hydrationField] && data[relMeta.key]) {
150
- const newRelModel = await relMeta.model.create(data[relMeta.key]);
151
- this[relMeta.key] = await newRelModel.save();
152
- }
153
- const cutKeys = this.constructor._CUT_KEYS;
154
- if (!cutKeys.includes(relMeta.hydrationField)) {
155
- cutKeys.push(relMeta.hydrationField);
156
- }
157
- }
158
- }
159
- // Process regular fields and time series
160
- for (const key in data) {
161
- if (data.hasOwnProperty(key)) {
162
- if (!fullDataMode && this.constructor._CUT_KEYS.includes(key)) {
163
- continue;
164
- }
165
- if (Object.keys(relOneData).includes(key)) {
166
- continue;
167
- }
168
- if (seriesHydrationfields.includes(key)) {
169
- continue;
170
- }
171
- const timeSeriesMetaData = timeSeriesIds[key];
172
- if (timeSeriesMetaData) {
173
- this[key] = data[key];
174
- const seriesModel = collections_to_models[timeSeriesMetaData.collection];
175
- const dataModels = await seriesModel.findBy({
176
- id: { in: data[key] }
177
- });
178
- seriesHydrationfields.push(timeSeriesMetaData.hydrationField);
179
- this[timeSeriesMetaData.hydrationField] = dataModels;
180
- }
181
- else {
182
- this[key] = data[key];
183
- }
184
- }
185
- }
186
- return this;
187
- }
188
- getModelScalarFields(model) {
189
- return FieldsHelper_1.FieldsHelper.getAllClassFields(model)
190
- .filter(item => item.indexOf('TrackType') === 0)
191
- .map(item => item.split(':').at(-1));
192
- }
193
- getTimeSeriesModelFields() {
194
- const timeSeriesIds = {};
195
- for (const key in this) {
196
- if (this.hasOwnProperty(key)) {
197
- const meta = Reflect.getMetadata(`InverseTimeSeries:${key}`, this);
198
- if (meta) {
199
- if (!timeSeriesIds[key]) {
200
- timeSeriesIds[key] = {
201
- collection: meta.timeSeriesModel,
202
- hydrationField: meta.hydrationField,
203
- ids: this[key]
204
- };
205
- }
206
- }
207
- }
208
- }
209
- return timeSeriesIds;
210
- }
211
- async getRelationOneMeta(classFields) {
212
- return RWSModel.getRelationOneMeta(this, classFields);
213
- }
214
- static async getRelationOneMeta(model, classFields) {
215
- const relIds = {};
216
- const relationFields = classFields
217
- .filter((item) => item.indexOf('Relation') === 0 && !item.includes('Inverse'))
218
- .map((item) => item.split(':').at(-1));
219
- for (const key of relationFields) {
220
- const metadataKey = `Relation:${key}`;
221
- const metadata = Reflect.getMetadata(metadataKey, model);
222
- if (metadata && metadata.promise) {
223
- const resolvedMetadata = await metadata.promise;
224
- if (!relIds[key]) {
225
- relIds[key] = {
226
- key: resolvedMetadata.key,
227
- required: resolvedMetadata.required,
228
- model: resolvedMetadata.relatedTo,
229
- hydrationField: resolvedMetadata.relationField,
230
- foreignKey: resolvedMetadata.relatedToField
231
- };
232
- }
233
- }
234
- }
235
- return relIds;
236
- }
237
- async getRelationManyMeta(classFields) {
238
- return RWSModel.getRelationManyMeta(this, classFields);
239
- }
240
- static async getRelationManyMeta(model, classFields) {
241
- const relIds = {};
242
- const inverseFields = classFields
243
- .filter((item) => item.indexOf('InverseRelation') === 0)
244
- .map((item) => item.split(':').at(-1));
245
- for (const key of inverseFields) {
246
- const metadataKey = `InverseRelation:${key}`;
247
- const metadata = Reflect.getMetadata(metadataKey, model);
248
- if (metadata && metadata.promise) {
249
- const resolvedMetadata = await metadata.promise;
250
- if (!relIds[key]) {
251
- relIds[key] = {
252
- key: resolvedMetadata.key,
253
- inversionModel: resolvedMetadata.inversionModel,
254
- foreignKey: resolvedMetadata.foreignKey
255
- };
256
- }
257
- }
258
- }
259
- return relIds;
260
- }
261
- async toMongo() {
262
- const data = {};
263
- const timeSeriesIds = this.getTimeSeriesModelFields();
264
- const timeSeriesHydrationFields = [];
265
- for (const key in this) {
266
- if (this.hasRelation(key)) {
267
- data[key] = this.bindRelation(key, this[key]);
268
- continue;
269
- }
270
- if (!(await this.isDbVariable(key))) {
271
- continue;
272
- }
273
- const passedFieldCondition = this.hasOwnProperty(key) &&
274
- !(this.constructor._BANNED_KEYS
275
- || RWSModel._BANNED_KEYS).includes(key) &&
276
- !timeSeriesHydrationFields.includes(key);
277
- if (passedFieldCondition) {
278
- data[key] = this[key];
279
- }
280
- if (timeSeriesIds[key]) {
281
- data[key] = this[key];
282
- timeSeriesHydrationFields.push(timeSeriesIds[key].hydrationField);
283
- }
284
- }
285
- return data;
286
- }
287
- getCollection() {
288
- return this.constructor._collection || this._collection;
289
- }
290
- static getCollection() {
291
- return this.constructor._collection || this._collection;
292
- }
293
- async save() {
294
- const data = await this.toMongo();
295
- let updatedModelData = data;
296
- if (this.id) {
297
- this.preUpdate();
298
- updatedModelData = await this.dbService.update(data, this.getCollection());
299
- await this._asyncFill(updatedModelData);
300
- this.postUpdate();
301
- }
302
- else {
303
- this.preCreate();
304
- const timeSeriesModel = await Promise.resolve().then(() => __importStar(require('./TimeSeriesModel')));
305
- const isTimeSeries = this instanceof timeSeriesModel.default;
306
- updatedModelData = await this.dbService.insert(data, this.getCollection(), isTimeSeries);
307
- await this._asyncFill(updatedModelData);
308
- this.postCreate();
309
- }
310
- return this;
311
- }
312
- static async getModelAnnotations(constructor) {
313
- const annotationsData = {};
314
- const metadataKeys = Reflect.getMetadataKeys(constructor.prototype);
315
- // Process all metadata keys and collect promises
316
- const metadataPromises = metadataKeys.map(async (fullKey) => {
317
- const [annotationType, propertyKey] = fullKey.split(':');
318
- const metadata = Reflect.getMetadata(fullKey, constructor.prototype);
319
- if (metadata) {
320
- // If this is a relation metadata with a promise
321
- if (metadata.promise && (annotationType === 'Relation' || annotationType === 'InverseRelation')) {
322
- const resolvedMetadata = await metadata.promise;
323
- annotationsData[propertyKey] = {
324
- annotationType,
325
- metadata: resolvedMetadata
326
- };
327
- }
328
- else {
329
- // Handle non-relation metadata as before
330
- const key = metadata.key || propertyKey;
331
- annotationsData[key] = {
332
- annotationType,
333
- metadata
334
- };
335
- }
336
- }
337
- });
338
- // Wait for all metadata to be processed
339
- await Promise.all(metadataPromises);
340
- return annotationsData;
341
- }
342
- preUpdate() {
343
- return;
344
- }
345
- postUpdate() {
346
- return;
347
- }
348
- preCreate() {
349
- return;
350
- }
351
- postCreate() {
352
- return;
353
- }
354
- static isSubclass(constructor, baseClass) {
355
- return baseClass.prototype.isPrototypeOf(constructor.prototype);
356
- }
357
- hasTimeSeries() {
358
- return RWSModel.checkTimeSeries(this.constructor);
359
- }
360
- static checkTimeSeries(constructor) {
361
- const data = constructor.prototype;
362
- for (const key in data) {
363
- if (data.hasOwnProperty(key)) {
364
- if (Reflect.getMetadata(`InverseTimeSeries:${key}`, constructor.prototype)) {
365
- return true;
366
- }
367
- }
368
- }
369
- return false;
370
- }
371
- async isDbVariable(variable) {
372
- return RWSModel.checkDbVariable(this.constructor, variable);
373
- }
374
- static async checkDbVariable(constructor, variable) {
375
- if (variable === 'id') {
376
- return true;
377
- }
378
- const dbAnnotations = await RWSModel.getModelAnnotations(constructor);
379
- const dbProperties = Object.keys(dbAnnotations)
380
- .map((key) => { return { ...dbAnnotations[key], key }; })
381
- .filter((element) => element.annotationType === 'TrackType')
382
- .map((element) => element.key);
383
- return dbProperties.includes(variable);
384
- }
385
- sanitizeDBData(data) {
386
- const dataKeys = Object.keys(data);
387
- const sanitizedData = {};
388
- for (const key of dataKeys) {
389
- if (this.isDbVariable(key)) {
390
- sanitizedData[key] = data[key];
391
- }
392
- }
393
- return sanitizedData;
394
- }
395
- static async watchCollection(preRun) {
396
- const collection = Reflect.get(this, '_collection');
397
- this.checkForInclusionWithThrow(this.name);
398
- return await this.services.dbService.watchCollection(collection, preRun);
399
- }
400
- static async findOneBy(findParams) {
401
- var _a, _b, _c, _d, _e;
402
- const conditions = (_a = findParams === null || findParams === void 0 ? void 0 : findParams.conditions) !== null && _a !== void 0 ? _a : {};
403
- const ordering = (_b = findParams === null || findParams === void 0 ? void 0 : findParams.ordering) !== null && _b !== void 0 ? _b : null;
404
- const fields = (_c = findParams === null || findParams === void 0 ? void 0 : findParams.fields) !== null && _c !== void 0 ? _c : null;
405
- const allowRelations = (_d = findParams === null || findParams === void 0 ? void 0 : findParams.allowRelations) !== null && _d !== void 0 ? _d : true;
406
- const fullData = (_e = findParams === null || findParams === void 0 ? void 0 : findParams.fullData) !== null && _e !== void 0 ? _e : false;
407
- this.checkForInclusionWithThrow('');
408
- const collection = Reflect.get(this, '_collection');
409
- const dbData = await this.services.dbService.findOneBy(collection, conditions, fields, ordering, allowRelations);
410
- if (dbData) {
411
- const inst = new this();
412
- return await inst._asyncFill(dbData, fullData, allowRelations);
413
- }
414
- return null;
415
- }
416
- static async find(id, findParams = null) {
417
- var _a, _b, _c, _d;
418
- const ordering = (_a = findParams === null || findParams === void 0 ? void 0 : findParams.ordering) !== null && _a !== void 0 ? _a : null;
419
- const fields = (_b = findParams === null || findParams === void 0 ? void 0 : findParams.fields) !== null && _b !== void 0 ? _b : null;
420
- const allowRelations = (_c = findParams === null || findParams === void 0 ? void 0 : findParams.allowRelations) !== null && _c !== void 0 ? _c : true;
421
- const fullData = (_d = findParams === null || findParams === void 0 ? void 0 : findParams.fullData) !== null && _d !== void 0 ? _d : false;
422
- const collection = Reflect.get(this, '_collection');
423
- this.checkForInclusionWithThrow(this.name);
424
- const dbData = await this.services.dbService.findOneBy(collection, { id }, fields, ordering, allowRelations);
425
- if (dbData) {
426
- const inst = new this();
427
- return await inst._asyncFill(dbData, fullData, allowRelations);
428
- }
429
- return null;
430
- }
431
- static async findBy(findParams) {
432
- var _a, _b, _c, _d, _e;
433
- const conditions = (_a = findParams === null || findParams === void 0 ? void 0 : findParams.conditions) !== null && _a !== void 0 ? _a : {};
434
- const ordering = (_b = findParams === null || findParams === void 0 ? void 0 : findParams.ordering) !== null && _b !== void 0 ? _b : null;
435
- const fields = (_c = findParams === null || findParams === void 0 ? void 0 : findParams.fields) !== null && _c !== void 0 ? _c : null;
436
- const allowRelations = (_d = findParams === null || findParams === void 0 ? void 0 : findParams.allowRelations) !== null && _d !== void 0 ? _d : true;
437
- const fullData = (_e = findParams === null || findParams === void 0 ? void 0 : findParams.fullData) !== null && _e !== void 0 ? _e : false;
438
- const collection = Reflect.get(this, '_collection');
439
- this.checkForInclusionWithThrow(this.name);
440
- try {
441
- const dbData = await this.services.dbService.findBy(collection, conditions, fields, ordering, allowRelations);
442
- if (dbData.length) {
443
- const instanced = [];
444
- for (const data of dbData) {
445
- const inst = new this();
446
- instanced.push((await inst._asyncFill(data, fullData, allowRelations)));
447
- }
448
- return instanced;
449
- }
450
- return [];
451
- }
452
- catch (rwsError) {
453
- console.error(rwsError);
454
- throw rwsError;
455
- }
456
- }
457
- static async delete(conditions) {
458
- const collection = Reflect.get(this, '_collection');
459
- this.checkForInclusionWithThrow(this.name);
460
- return await this.services.dbService.delete(collection, conditions);
461
- }
462
- async delete() {
463
- const collection = Reflect.get(this, '_collection');
464
- this.checkForInclusionWithThrow();
465
- return await this.dbService.delete(collection, {
466
- id: this.id
467
- });
468
- }
469
- static async create(data) {
470
- const newModel = new this();
471
- const sanitizedData = newModel.sanitizeDBData(data);
472
- await newModel._asyncFill(sanitizedData);
473
- return newModel;
474
- }
475
- static loadModels() {
476
- return this.allModels || [];
477
- }
478
- loadModels() {
479
- return RWSModel.loadModels();
480
- }
481
- checkRelEnabled(key) {
482
- return Object.keys(this.constructor._RELATIONS).includes(key) && this.constructor._RELATIONS[key] === true;
483
- }
484
- static setServices(services) {
485
- this.allModels = services.configService.get('db_models');
486
- this.services = services;
487
- }
488
- }
489
- exports.RWSModel = RWSModel;
490
- RWSModel.services = {};
491
- RWSModel._collection = null;
492
- RWSModel._RELATIONS = {};
493
- RWSModel._BANNED_KEYS = ['_collection'];
494
- RWSModel.allModels = [];
495
- RWSModel._CUT_KEYS = [];
496
- __decorate([
497
- (0, decorators_1.TrackType)(String),
498
- __metadata("design:type", String)
499
- ], RWSModel.prototype, "id", void 0);
6
+ exports.TrackType = exports.RWSModel = void 0;
7
+ const index_1 = require("./index");
8
+ Object.defineProperty(exports, "RWSModel", { enumerable: true, get: function () { return index_1.RWSModel; } });
9
+ Object.defineProperty(exports, "TrackType", { enumerable: true, get: function () { return index_1.TrackType; } });
@@ -0,0 +1,65 @@
1
+ import { IModel } from '../interfaces/IModel';
2
+ import { IRWSModelServices } from '../interfaces/IRWSModelServices';
3
+ import { OpModelType } from '../interfaces/OpModelType';
4
+ import { FindByType, IPaginationParams } from '../../types/FindParams';
5
+ import { DBService } from '../../services/DBService';
6
+ declare class RWSModel<ChildClass> implements IModel {
7
+ static services: IRWSModelServices;
8
+ [key: string]: any;
9
+ id: string;
10
+ static _collection: string;
11
+ static _RELATIONS: {};
12
+ static _BANNED_KEYS: string[];
13
+ static allModels: OpModelType<any>[];
14
+ static _CUT_KEYS: string[];
15
+ constructor(data: any);
16
+ checkForInclusionWithThrow(): void;
17
+ static checkForInclusionWithThrow(this: OpModelType<any>, checkModelType: string): void;
18
+ checkForInclusion(): boolean;
19
+ static checkForInclusion(this: OpModelType<any>, checkModelType: string): boolean;
20
+ protected _fill(data: any): RWSModel<ChildClass>;
21
+ protected hasRelation(key: string): boolean;
22
+ protected bindRelation(key: string, relatedModel: RWSModel<any>): {
23
+ connect: {
24
+ id: string;
25
+ };
26
+ };
27
+ _asyncFill(data: any, fullDataMode?: boolean, allowRelations?: boolean): Promise<ChildClass>;
28
+ private getModelScalarFields;
29
+ private getRelationOneMeta;
30
+ static getRelationOneMeta(model: any, classFields: string[]): Promise<import("..").RelOneMetaType<import("../..").IRWSModel>>;
31
+ private getRelationManyMeta;
32
+ static getRelationManyMeta(model: any, classFields: string[]): Promise<import("..").RelManyMetaType<import("../..").IRWSModel>>;
33
+ static paginate<ChildClass extends RWSModel<ChildClass>>(this: OpModelType<any>, pageParams: IPaginationParams, findParams?: FindByType): Promise<RWSModel<ChildClass>[]>;
34
+ toMongo(): Promise<any>;
35
+ getCollection(): string | null;
36
+ static getCollection(): string | null;
37
+ save(): Promise<this>;
38
+ static getModelAnnotations<T extends unknown>(constructor: new () => T): Promise<Record<string, {
39
+ annotationType: string;
40
+ metadata: any;
41
+ }>>;
42
+ preUpdate(): void;
43
+ postUpdate(): void;
44
+ preCreate(): void;
45
+ postCreate(): void;
46
+ static isSubclass<T extends RWSModel<T>, C extends new () => T>(constructor: C, baseClass: new () => T): boolean;
47
+ hasTimeSeries(): boolean;
48
+ static checkTimeSeries(constructor: any): boolean;
49
+ isDbVariable(variable: string): Promise<boolean>;
50
+ static checkDbVariable(constructor: any, variable: string): Promise<boolean>;
51
+ sanitizeDBData(data: any): any;
52
+ static watchCollection<ChildClass extends RWSModel<ChildClass>>(this: OpModelType<ChildClass>, preRun: () => void): Promise<any>;
53
+ static findOneBy<ChildClass extends RWSModel<ChildClass>>(this: OpModelType<ChildClass>, findParams?: FindByType): Promise<ChildClass | null>;
54
+ static find<ChildClass extends RWSModel<ChildClass>>(this: OpModelType<ChildClass>, id: string, findParams?: Omit<FindByType, 'conditions'>): Promise<ChildClass | null>;
55
+ static findBy<ChildClass extends RWSModel<ChildClass>>(this: OpModelType<ChildClass>, findParams?: FindByType): Promise<ChildClass[]>;
56
+ static delete<ChildClass extends RWSModel<ChildClass>>(this: OpModelType<ChildClass>, conditions: any): Promise<void>;
57
+ delete<ChildClass extends RWSModel<ChildClass>>(): Promise<void>;
58
+ static create<T extends RWSModel<T>>(this: new () => T, data: any): Promise<T>;
59
+ static loadModels(): OpModelType<any>[];
60
+ loadModels(): OpModelType<any>[];
61
+ private checkRelEnabled;
62
+ static setServices(services: IRWSModelServices): void;
63
+ getDb(): DBService;
64
+ }
65
+ export { RWSModel };