@rws-framework/db 3.9.0 → 3.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/models/core/RWSModel.d.ts +1 -1
- package/dist/models/core/RWSModel.js +33 -29
- package/dist/models/interfaces/IModel.d.ts +1 -1
- package/dist/models/utils/FindUtils.js +70 -131
- package/package.json +1 -1
- package/src/models/core/RWSModel.ts +13 -15
- package/src/models/interfaces/IModel.ts +1 -1
- package/src/models/utils/FindUtils.ts +84 -150
- package/LOADING_CONTEXT_FIX.md +0 -139
- package/LOADING_CONTEXT_IMPLEMENTATION.md +0 -122
- package/dist/models/utils/LoadingContext.d.ts +0 -56
- package/dist/models/utils/LoadingContext.js +0 -119
- package/dist/models/utils/LoadingContext.test.d.ts +0 -5
- package/dist/models/utils/LoadingContext.test.js +0 -51
- package/dist/models/utils/index.d.ts +0 -7
- package/dist/models/utils/index.js +0 -17
- package/src/models/utils/LoadingContext.ts +0 -140
- package/src/models/utils/index.ts +0 -7
|
@@ -12,7 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.RWSModel = void 0;
|
|
13
13
|
const decorators_1 = require("../../decorators");
|
|
14
14
|
const FieldsHelper_1 = require("../../helper/FieldsHelper");
|
|
15
|
-
const
|
|
15
|
+
const RelationUtils_1 = require("../utils/RelationUtils");
|
|
16
|
+
const TimeSeriesUtils_1 = require("../utils/TimeSeriesUtils");
|
|
17
|
+
const ModelUtils_1 = require("../utils/ModelUtils");
|
|
18
|
+
const HydrateUtils_1 = require("../utils/HydrateUtils");
|
|
19
|
+
const FindUtils_1 = require("../utils/FindUtils");
|
|
16
20
|
class RWSModel {
|
|
17
21
|
static services = {};
|
|
18
22
|
id;
|
|
@@ -83,13 +87,13 @@ class RWSModel {
|
|
|
83
87
|
return this;
|
|
84
88
|
}
|
|
85
89
|
async hasRelation(key) {
|
|
86
|
-
return
|
|
90
|
+
return RelationUtils_1.RelationUtils.hasRelation(this.constructor, key);
|
|
87
91
|
}
|
|
88
92
|
async getRelationKey(key) {
|
|
89
|
-
return
|
|
93
|
+
return RelationUtils_1.RelationUtils.getRelationKey(this.constructor, key);
|
|
90
94
|
}
|
|
91
95
|
bindRelation(key, relatedModel) {
|
|
92
|
-
return
|
|
96
|
+
return RelationUtils_1.RelationUtils.bindRelation(relatedModel);
|
|
93
97
|
}
|
|
94
98
|
async _asyncFill(data, fullDataMode = false, allowRelations = true, postLoadExecute = true) {
|
|
95
99
|
const collections_to_models = {};
|
|
@@ -104,36 +108,37 @@ class RWSModel {
|
|
|
104
108
|
});
|
|
105
109
|
const seriesHydrationfields = [];
|
|
106
110
|
if (allowRelations) {
|
|
107
|
-
await
|
|
111
|
+
await HydrateUtils_1.HydrateUtils.hydrateRelations(this, relManyData, relOneData, seriesHydrationfields, fullDataMode, data);
|
|
108
112
|
}
|
|
109
113
|
// Process regular fields and time series
|
|
110
|
-
await
|
|
114
|
+
await HydrateUtils_1.HydrateUtils.hydrateDataFields(this, collections_to_models, relOneData, seriesHydrationfields, fullDataMode, data);
|
|
111
115
|
if (!this.isPostLoadExecuted() && postLoadExecute) {
|
|
112
116
|
await this.postLoad();
|
|
117
|
+
this.setPostLoadExecuted();
|
|
113
118
|
}
|
|
114
119
|
return this;
|
|
115
120
|
}
|
|
116
121
|
getModelScalarFields(model) {
|
|
117
|
-
return
|
|
122
|
+
return ModelUtils_1.ModelUtils.getModelScalarFields(model);
|
|
118
123
|
}
|
|
119
124
|
async getRelationOneMeta(classFields) {
|
|
120
|
-
return
|
|
125
|
+
return RelationUtils_1.RelationUtils.getRelationOneMeta(this, classFields);
|
|
121
126
|
}
|
|
122
127
|
static async getRelationOneMeta(model, classFields) {
|
|
123
|
-
return
|
|
128
|
+
return RelationUtils_1.RelationUtils.getRelationOneMeta(model, classFields);
|
|
124
129
|
}
|
|
125
130
|
async getRelationManyMeta(classFields) {
|
|
126
|
-
return
|
|
131
|
+
return RelationUtils_1.RelationUtils.getRelationManyMeta(this, classFields);
|
|
127
132
|
}
|
|
128
133
|
static async getRelationManyMeta(model, classFields) {
|
|
129
|
-
return
|
|
134
|
+
return RelationUtils_1.RelationUtils.getRelationManyMeta(model, classFields);
|
|
130
135
|
}
|
|
131
136
|
static async paginate(paginateParams, findParams) {
|
|
132
|
-
return await
|
|
137
|
+
return await FindUtils_1.FindUtils.paginate(this, paginateParams, findParams);
|
|
133
138
|
}
|
|
134
139
|
async toMongo() {
|
|
135
140
|
const data = {};
|
|
136
|
-
const timeSeriesIds =
|
|
141
|
+
const timeSeriesIds = TimeSeriesUtils_1.TimeSeriesUtils.getTimeSeriesModelFields(this);
|
|
137
142
|
const timeSeriesHydrationFields = [];
|
|
138
143
|
for (const key in this) {
|
|
139
144
|
if (await this.hasRelation(key)) {
|
|
@@ -175,10 +180,10 @@ class RWSModel {
|
|
|
175
180
|
async save() {
|
|
176
181
|
const data = await this.toMongo();
|
|
177
182
|
let updatedModelData = data;
|
|
178
|
-
const entryExists = await
|
|
183
|
+
const entryExists = await ModelUtils_1.ModelUtils.entryExists(this);
|
|
179
184
|
if (entryExists) {
|
|
180
185
|
await this.preUpdate();
|
|
181
|
-
const pk =
|
|
186
|
+
const pk = ModelUtils_1.ModelUtils.findPrimaryKeyFields(this.constructor);
|
|
182
187
|
updatedModelData = await this.dbService.update(data, this.getCollection(), pk);
|
|
183
188
|
await this._asyncFill(updatedModelData);
|
|
184
189
|
await this.postUpdate();
|
|
@@ -193,13 +198,12 @@ class RWSModel {
|
|
|
193
198
|
return this;
|
|
194
199
|
}
|
|
195
200
|
static async getModelAnnotations(constructor) {
|
|
196
|
-
return
|
|
201
|
+
return ModelUtils_1.ModelUtils.getModelAnnotations(constructor);
|
|
197
202
|
}
|
|
198
203
|
async preUpdate() {
|
|
199
204
|
return;
|
|
200
205
|
}
|
|
201
206
|
async postLoad() {
|
|
202
|
-
this.setPostLoadExecuted();
|
|
203
207
|
return;
|
|
204
208
|
}
|
|
205
209
|
async postUpdate() {
|
|
@@ -212,19 +216,19 @@ class RWSModel {
|
|
|
212
216
|
return;
|
|
213
217
|
}
|
|
214
218
|
static isSubclass(constructor, baseClass) {
|
|
215
|
-
return
|
|
219
|
+
return ModelUtils_1.ModelUtils.isSubclass(constructor, baseClass);
|
|
216
220
|
}
|
|
217
221
|
hasTimeSeries() {
|
|
218
|
-
return
|
|
222
|
+
return TimeSeriesUtils_1.TimeSeriesUtils.checkTimeSeries(this.constructor);
|
|
219
223
|
}
|
|
220
224
|
static checkTimeSeries(constructor) {
|
|
221
|
-
return
|
|
225
|
+
return TimeSeriesUtils_1.TimeSeriesUtils.checkTimeSeries(constructor);
|
|
222
226
|
}
|
|
223
227
|
async isDbVariable(variable) {
|
|
224
|
-
return
|
|
228
|
+
return ModelUtils_1.ModelUtils.checkDbVariable(this.constructor, variable);
|
|
225
229
|
}
|
|
226
230
|
static async checkDbVariable(constructor, variable) {
|
|
227
|
-
return
|
|
231
|
+
return ModelUtils_1.ModelUtils.checkDbVariable(constructor, variable);
|
|
228
232
|
}
|
|
229
233
|
sanitizeDBData(data) {
|
|
230
234
|
const dataKeys = Object.keys(data);
|
|
@@ -242,13 +246,13 @@ class RWSModel {
|
|
|
242
246
|
return await this.services.dbService.watchCollection(collection, preRun);
|
|
243
247
|
}
|
|
244
248
|
static async findOneBy(findParams) {
|
|
245
|
-
return await
|
|
249
|
+
return await FindUtils_1.FindUtils.findOneBy(this, findParams);
|
|
246
250
|
}
|
|
247
251
|
static async find(id, findParams = null) {
|
|
248
|
-
return await
|
|
252
|
+
return await FindUtils_1.FindUtils.find(this, id, findParams);
|
|
249
253
|
}
|
|
250
254
|
static async findBy(findParams) {
|
|
251
|
-
return await
|
|
255
|
+
return await FindUtils_1.FindUtils.findBy(this, findParams);
|
|
252
256
|
}
|
|
253
257
|
static async delete(conditions) {
|
|
254
258
|
const collection = Reflect.get(this, '_collection');
|
|
@@ -275,7 +279,7 @@ class RWSModel {
|
|
|
275
279
|
return RWSModel.loadModels();
|
|
276
280
|
}
|
|
277
281
|
checkRelDisabled(key) {
|
|
278
|
-
return
|
|
282
|
+
return RelationUtils_1.RelationUtils.checkRelDisabled(this, key);
|
|
279
283
|
}
|
|
280
284
|
static setServices(services) {
|
|
281
285
|
this.allModels = services.configService.get('db_models');
|
|
@@ -290,8 +294,8 @@ class RWSModel {
|
|
|
290
294
|
static getDb() {
|
|
291
295
|
return this.services.dbService;
|
|
292
296
|
}
|
|
293
|
-
async reload(
|
|
294
|
-
const pk =
|
|
297
|
+
async reload() {
|
|
298
|
+
const pk = ModelUtils_1.ModelUtils.findPrimaryKeyFields(this.constructor);
|
|
295
299
|
const where = {};
|
|
296
300
|
if (Array.isArray(pk)) {
|
|
297
301
|
for (const pkElem of pk) {
|
|
@@ -301,7 +305,7 @@ class RWSModel {
|
|
|
301
305
|
else {
|
|
302
306
|
where[pk] = this[pk];
|
|
303
307
|
}
|
|
304
|
-
return await
|
|
308
|
+
return await FindUtils_1.FindUtils.findOneBy(this.constructor, { conditions: where });
|
|
305
309
|
}
|
|
306
310
|
}
|
|
307
311
|
exports.RWSModel = RWSModel;
|
|
@@ -9,7 +9,7 @@ export interface IModel {
|
|
|
9
9
|
save: () => Promise<this>;
|
|
10
10
|
getDb: () => DBService;
|
|
11
11
|
getCollection: () => string | null;
|
|
12
|
-
reload: (
|
|
12
|
+
reload: () => Promise<RWSModel<any>>;
|
|
13
13
|
delete: () => Promise<void>;
|
|
14
14
|
hasTimeSeries: () => boolean;
|
|
15
15
|
_asyncFill: (data: any, fullDataMode?: boolean, allowRelations?: boolean) => Promise<any>;
|
|
@@ -1,149 +1,88 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.FindUtils = void 0;
|
|
7
|
-
const LoadingContext_1 = require("./LoadingContext");
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
function circularReferenceWarning(modelType, id) {
|
|
10
|
-
console.warn(chalk_1.default.yellow(`Circular reference detected: ${modelType}:${id} is already being loaded. Breaking cycle.`));
|
|
11
|
-
}
|
|
12
4
|
class FindUtils {
|
|
13
5
|
static async findOneBy(opModel, findParams) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (LoadingContext_1.LoadingContext.isLoading(modelType, id)) {
|
|
29
|
-
circularReferenceWarning(modelType, id);
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
return await LoadingContext_1.LoadingContext.withLoadingContext(modelType, id, async () => {
|
|
33
|
-
const inst = new opModel();
|
|
34
|
-
const loaded = await inst._asyncFill(dbData, fullData, allowRelations, findParams?.cancelPostLoad ? false : true);
|
|
35
|
-
return loaded;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return null;
|
|
39
|
-
});
|
|
6
|
+
const conditions = findParams?.conditions ?? {};
|
|
7
|
+
const ordering = findParams?.ordering ?? null;
|
|
8
|
+
const fields = findParams?.fields ?? null;
|
|
9
|
+
const allowRelations = findParams?.allowRelations ?? true;
|
|
10
|
+
const fullData = findParams?.fullData ?? false;
|
|
11
|
+
opModel.checkForInclusionWithThrow('');
|
|
12
|
+
const collection = Reflect.get(opModel, '_collection');
|
|
13
|
+
const dbData = await opModel.services.dbService.findOneBy(collection, conditions, fields, ordering);
|
|
14
|
+
if (dbData) {
|
|
15
|
+
const inst = new opModel();
|
|
16
|
+
const loaded = await inst._asyncFill(dbData, fullData, allowRelations, findParams?.cancelPostLoad ? false : true);
|
|
17
|
+
return loaded;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
40
20
|
}
|
|
41
21
|
static async find(opModel, id, findParams = null) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
circularReferenceWarning(modelType, id);
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
return await LoadingContext_1.LoadingContext.withLoadingContext(modelType, id, async () => {
|
|
59
|
-
const inst = new opModel();
|
|
60
|
-
const loaded = await inst._asyncFill(dbData, fullData, allowRelations, findParams?.cancelPostLoad ? false : true);
|
|
61
|
-
return loaded;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
});
|
|
22
|
+
const ordering = findParams?.ordering ?? null;
|
|
23
|
+
const fields = findParams?.fields ?? null;
|
|
24
|
+
const allowRelations = findParams?.allowRelations ?? true;
|
|
25
|
+
const fullData = findParams?.fullData ?? false;
|
|
26
|
+
const collection = Reflect.get(opModel, '_collection');
|
|
27
|
+
opModel.checkForInclusionWithThrow(opModel.name);
|
|
28
|
+
const dbData = await opModel.services.dbService.findOneBy(collection, { id }, fields, ordering);
|
|
29
|
+
if (dbData) {
|
|
30
|
+
const inst = new opModel();
|
|
31
|
+
const loaded = await inst._asyncFill(dbData, fullData, allowRelations, findParams?.cancelPostLoad ? false : true);
|
|
32
|
+
return loaded;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
66
35
|
}
|
|
67
36
|
static async findBy(opModel, findParams) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
const modelType = opModel.name;
|
|
84
|
-
const id = data.id;
|
|
85
|
-
// Check if this model is already being loaded to prevent circular references
|
|
86
|
-
if (LoadingContext_1.LoadingContext.isLoading(modelType, id)) {
|
|
87
|
-
circularReferenceWarning(modelType, id);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
const loaded = await LoadingContext_1.LoadingContext.withLoadingContext(modelType, id, async () => {
|
|
91
|
-
const inst = new opModel();
|
|
92
|
-
return await inst._asyncFill(data, fullData, allowRelations, findParams?.cancelPostLoad ? false : true);
|
|
93
|
-
});
|
|
94
|
-
if (loaded) {
|
|
95
|
-
instanced.push(loaded);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return instanced;
|
|
37
|
+
const conditions = findParams?.conditions ?? {};
|
|
38
|
+
const ordering = findParams?.ordering ?? null;
|
|
39
|
+
const fields = findParams?.fields ?? null;
|
|
40
|
+
const allowRelations = findParams?.allowRelations ?? true;
|
|
41
|
+
const fullData = findParams?.fullData ?? false;
|
|
42
|
+
const collection = Reflect.get(opModel, '_collection');
|
|
43
|
+
opModel.checkForInclusionWithThrow(opModel.name);
|
|
44
|
+
try {
|
|
45
|
+
const paginateParams = findParams?.pagination ? findParams?.pagination : undefined;
|
|
46
|
+
const dbData = await opModel.services.dbService.findBy(collection, conditions, fields, ordering, paginateParams);
|
|
47
|
+
if (dbData.length) {
|
|
48
|
+
const instanced = [];
|
|
49
|
+
for (const data of dbData) {
|
|
50
|
+
const inst = new opModel();
|
|
51
|
+
instanced.push((await inst._asyncFill(data, fullData, allowRelations, findParams?.cancelPostLoad ? false : true)));
|
|
99
52
|
}
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
catch (rwsError) {
|
|
103
|
-
console.error(rwsError);
|
|
104
|
-
throw rwsError;
|
|
53
|
+
return instanced;
|
|
105
54
|
}
|
|
106
|
-
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
catch (rwsError) {
|
|
58
|
+
console.error(rwsError);
|
|
59
|
+
throw rwsError;
|
|
60
|
+
}
|
|
107
61
|
}
|
|
108
62
|
static async paginate(opModel, paginateParams, findParams) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
opModel.
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
const modelType = opModel.name;
|
|
124
|
-
const id = data.id;
|
|
125
|
-
// Check if this model is already being loaded to prevent circular references
|
|
126
|
-
if (LoadingContext_1.LoadingContext.isLoading(modelType, id)) {
|
|
127
|
-
circularReferenceWarning(modelType, id);
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
const loaded = await LoadingContext_1.LoadingContext.withLoadingContext(modelType, id, async () => {
|
|
131
|
-
const inst = new opModel();
|
|
132
|
-
return await inst._asyncFill(data, fullData, allowRelations, findParams?.cancelPostLoad ? false : true);
|
|
133
|
-
});
|
|
134
|
-
if (loaded) {
|
|
135
|
-
instanced.push(loaded);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return instanced;
|
|
63
|
+
const conditions = findParams?.conditions ?? {};
|
|
64
|
+
const ordering = findParams?.ordering ?? null;
|
|
65
|
+
const fields = findParams?.fields ?? null;
|
|
66
|
+
const allowRelations = findParams?.allowRelations ?? true;
|
|
67
|
+
const fullData = findParams?.fullData ?? false;
|
|
68
|
+
const collection = Reflect.get(opModel, '_collection');
|
|
69
|
+
opModel.checkForInclusionWithThrow(opModel.name);
|
|
70
|
+
try {
|
|
71
|
+
const dbData = await opModel.services.dbService.findBy(collection, conditions, fields, ordering, paginateParams);
|
|
72
|
+
if (dbData.length) {
|
|
73
|
+
const instanced = [];
|
|
74
|
+
for (const data of dbData) {
|
|
75
|
+
const inst = new opModel();
|
|
76
|
+
instanced.push((await inst._asyncFill(data, fullData, allowRelations, findParams?.cancelPostLoad ? false : true)));
|
|
139
77
|
}
|
|
140
|
-
return
|
|
141
|
-
}
|
|
142
|
-
catch (rwsError) {
|
|
143
|
-
console.error(rwsError);
|
|
144
|
-
throw rwsError;
|
|
78
|
+
return instanced;
|
|
145
79
|
}
|
|
146
|
-
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
catch (rwsError) {
|
|
83
|
+
console.error(rwsError);
|
|
84
|
+
throw rwsError;
|
|
85
|
+
}
|
|
147
86
|
}
|
|
148
87
|
}
|
|
149
88
|
exports.FindUtils = FindUtils;
|
package/package.json
CHANGED
|
@@ -4,16 +4,15 @@ import { OpModelType } from '../interfaces/OpModelType';
|
|
|
4
4
|
import { TrackType } from '../../decorators';
|
|
5
5
|
import { FieldsHelper } from '../../helper/FieldsHelper';
|
|
6
6
|
import { FindByType, IPaginationParams } from '../../types/FindParams';
|
|
7
|
+
import { RelationUtils } from '../utils/RelationUtils';
|
|
8
|
+
|
|
9
|
+
import { TimeSeriesUtils } from '../utils/TimeSeriesUtils';
|
|
10
|
+
import { ModelUtils } from '../utils/ModelUtils';
|
|
11
|
+
// import timeSeriesModel from './TimeSeriesModel';
|
|
7
12
|
import { DBService } from '../../services/DBService';
|
|
8
13
|
import { ISuperTagData } from '../../decorators/RWSCollection';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
TimeSeriesUtils,
|
|
12
|
-
ModelUtils,
|
|
13
|
-
HydrateUtils,
|
|
14
|
-
FindUtils,
|
|
15
|
-
LoadingContext
|
|
16
|
-
} from '../utils';
|
|
14
|
+
import { HydrateUtils } from '../utils/HydrateUtils';
|
|
15
|
+
import { FindUtils } from '../utils/FindUtils';
|
|
17
16
|
|
|
18
17
|
class RWSModel<T> implements IModel {
|
|
19
18
|
static services: IRWSModelServices = {};
|
|
@@ -138,9 +137,9 @@ class RWSModel<T> implements IModel {
|
|
|
138
137
|
// Process regular fields and time series
|
|
139
138
|
await HydrateUtils.hydrateDataFields(this, collections_to_models, relOneData, seriesHydrationfields, fullDataMode, data);
|
|
140
139
|
|
|
141
|
-
if(!this.isPostLoadExecuted() && postLoadExecute){
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
if(!this.isPostLoadExecuted() && postLoadExecute){
|
|
141
|
+
await this.postLoad();
|
|
142
|
+
this.setPostLoadExecuted();
|
|
144
143
|
}
|
|
145
144
|
|
|
146
145
|
return this as any as T;
|
|
@@ -267,8 +266,7 @@ class RWSModel<T> implements IModel {
|
|
|
267
266
|
return;
|
|
268
267
|
}
|
|
269
268
|
|
|
270
|
-
public async postLoad(): Promise<void> {
|
|
271
|
-
this.setPostLoadExecuted();
|
|
269
|
+
public async postLoad(): Promise<void> {
|
|
272
270
|
return;
|
|
273
271
|
}
|
|
274
272
|
|
|
@@ -406,7 +404,7 @@ class RWSModel<T> implements IModel {
|
|
|
406
404
|
return this.services.dbService;
|
|
407
405
|
}
|
|
408
406
|
|
|
409
|
-
public async reload(
|
|
407
|
+
public async reload(): Promise<RWSModel<T> | null>
|
|
410
408
|
{
|
|
411
409
|
const pk = ModelUtils.findPrimaryKeyFields(this.constructor as OpModelType<T>);
|
|
412
410
|
const where: any = {};
|
|
@@ -419,7 +417,7 @@ class RWSModel<T> implements IModel {
|
|
|
419
417
|
where[pk as string] = this[pk as string]
|
|
420
418
|
}
|
|
421
419
|
|
|
422
|
-
return await FindUtils.findOneBy(this.constructor as OpModelType<any>, { conditions: where
|
|
420
|
+
return await FindUtils.findOneBy(this.constructor as OpModelType<any>, { conditions: where });
|
|
423
421
|
}
|
|
424
422
|
}
|
|
425
423
|
|
|
@@ -11,7 +11,7 @@ export interface IModel {
|
|
|
11
11
|
save: () => Promise<this>;
|
|
12
12
|
getDb: () => DBService;
|
|
13
13
|
getCollection: () => string | null;
|
|
14
|
-
reload: (
|
|
14
|
+
reload: () => Promise<RWSModel<any>>;
|
|
15
15
|
delete: () => Promise<void>;
|
|
16
16
|
hasTimeSeries: () => boolean;
|
|
17
17
|
|