@rws-framework/db 2.1.11 → 2.2.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/dist/decorators/InverseRelation.d.ts +0 -0
- package/dist/decorators/InverseRelation.js +0 -0
- package/dist/decorators/InverseTimeSeries.d.ts +0 -0
- package/dist/decorators/InverseTimeSeries.js +0 -0
- package/dist/decorators/RWSCollection.d.ts +0 -0
- package/dist/decorators/RWSCollection.js +0 -0
- package/dist/decorators/Relation.d.ts +0 -0
- package/dist/decorators/Relation.js +0 -0
- package/dist/decorators/TrackType.d.ts +1 -1
- package/dist/decorators/TrackType.js +0 -0
- package/dist/decorators/index.d.ts +0 -0
- package/dist/decorators/index.js +0 -0
- package/dist/helper/DbHelper.d.ts +0 -0
- package/dist/helper/DbHelper.js +0 -0
- package/dist/helper/FieldsHelper.d.ts +0 -0
- package/dist/helper/FieldsHelper.js +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/models/TimeSeriesModel.d.ts +0 -0
- package/dist/models/TimeSeriesModel.js +0 -0
- package/dist/models/_model.d.ts +5 -116
- package/dist/models/_model.js +10 -42
- package/dist/models/core/RWSModel.d.ts +65 -0
- package/dist/models/core/RWSModel.js +375 -0
- package/dist/models/core/TimeSeriesModel.d.ts +7 -0
- package/dist/models/core/TimeSeriesModel.js +34 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.js +12 -0
- package/dist/models/interfaces/IModel.d.ts +10 -0
- package/dist/models/interfaces/IModel.js +2 -0
- package/dist/models/interfaces/IRWSModelServices.d.ts +6 -0
- package/dist/models/interfaces/IRWSModelServices.js +2 -0
- package/dist/models/interfaces/OpModelType.d.ts +32 -0
- package/dist/models/interfaces/OpModelType.js +2 -0
- package/dist/models/types/RelationTypes.d.ts +24 -0
- package/dist/models/types/RelationTypes.js +2 -0
- package/dist/models/utils/ModelUtils.d.ts +10 -0
- package/dist/models/utils/ModelUtils.js +56 -0
- package/dist/models/utils/PaginationUtils.d.ts +5 -0
- package/dist/models/utils/PaginationUtils.js +32 -0
- package/dist/models/utils/RelationUtils.d.ts +14 -0
- package/dist/models/utils/RelationUtils.js +65 -0
- package/dist/models/utils/TimeSeriesUtils.d.ts +11 -0
- package/dist/models/utils/TimeSeriesUtils.js +35 -0
- package/dist/services/DBService.d.ts +3 -2
- package/dist/services/DBService.js +5 -1
- package/dist/types/DbConfigHandler.d.ts +1 -1
- package/dist/types/DbConfigHandler.js +0 -0
- package/dist/types/FindParams.d.ts +5 -0
- package/dist/types/FindParams.js +0 -0
- package/dist/types/IRWSModel.d.ts +0 -0
- package/dist/types/IRWSModel.js +0 -0
- package/dist/types/ITimeSeries.d.ts +0 -0
- package/dist/types/ITimeSeries.js +0 -0
- package/package.json +1 -1
- package/src/decorators/TrackType.ts +2 -2
- package/src/models/_model.ts +29 -24
- package/src/models/core/RWSModel.ts +482 -0
- package/src/models/core/TimeSeriesModel.ts +19 -0
- package/src/models/index.ts +20 -0
- package/src/models/interfaces/IModel.ts +11 -0
- package/src/models/interfaces/IRWSModelServices.ts +7 -0
- package/src/models/interfaces/OpModelType.ts +49 -0
- package/src/models/types/RelationTypes.ts +25 -0
- package/src/models/utils/ModelUtils.ts +65 -0
- package/src/models/utils/PaginationUtils.ts +42 -0
- package/src/models/utils/RelationUtils.ts +76 -0
- package/src/models/utils/TimeSeriesUtils.ts +38 -0
- package/src/services/DBService.ts +14 -3
- package/src/types/DbConfigHandler.ts +2 -2
- package/src/types/FindParams.ts +10 -4
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelationUtils = void 0;
|
|
4
|
+
class RelationUtils {
|
|
5
|
+
static async getRelationOneMeta(model, classFields) {
|
|
6
|
+
const relIds = {};
|
|
7
|
+
const relationFields = classFields
|
|
8
|
+
.filter((item) => item.indexOf('Relation') === 0 && !item.includes('Inverse'))
|
|
9
|
+
.map((item) => item.split(':').at(-1));
|
|
10
|
+
for (const key of relationFields) {
|
|
11
|
+
const metadataKey = `Relation:${key}`;
|
|
12
|
+
const metadata = Reflect.getMetadata(metadataKey, model);
|
|
13
|
+
if (metadata && metadata.promise) {
|
|
14
|
+
const resolvedMetadata = await metadata.promise;
|
|
15
|
+
if (!relIds[key]) {
|
|
16
|
+
relIds[key] = {
|
|
17
|
+
key: resolvedMetadata.key,
|
|
18
|
+
required: resolvedMetadata.required,
|
|
19
|
+
model: resolvedMetadata.relatedTo,
|
|
20
|
+
hydrationField: resolvedMetadata.relationField,
|
|
21
|
+
foreignKey: resolvedMetadata.relatedToField
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return relIds;
|
|
27
|
+
}
|
|
28
|
+
static async getRelationManyMeta(model, classFields) {
|
|
29
|
+
const relIds = {};
|
|
30
|
+
const inverseFields = classFields
|
|
31
|
+
.filter((item) => item.indexOf('InverseRelation') === 0)
|
|
32
|
+
.map((item) => item.split(':').at(-1));
|
|
33
|
+
for (const key of inverseFields) {
|
|
34
|
+
const metadataKey = `InverseRelation:${key}`;
|
|
35
|
+
const metadata = Reflect.getMetadata(metadataKey, model);
|
|
36
|
+
if (metadata && metadata.promise) {
|
|
37
|
+
const resolvedMetadata = await metadata.promise;
|
|
38
|
+
if (!relIds[key]) {
|
|
39
|
+
relIds[key] = {
|
|
40
|
+
key: resolvedMetadata.key,
|
|
41
|
+
inversionModel: resolvedMetadata.inversionModel,
|
|
42
|
+
foreignKey: resolvedMetadata.foreignKey
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return relIds;
|
|
48
|
+
}
|
|
49
|
+
static bindRelation(relatedModel) {
|
|
50
|
+
return {
|
|
51
|
+
connect: {
|
|
52
|
+
id: relatedModel.id
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
static hasRelation(model, key) {
|
|
57
|
+
// Check if the property exists and is an object with an id property
|
|
58
|
+
return !!model[key] && typeof model[key] === 'object' && model[key] !== null && 'id' in model[key];
|
|
59
|
+
}
|
|
60
|
+
static checkRelEnabled(model, key) {
|
|
61
|
+
return Object.keys(model.constructor._RELATIONS).includes(key) &&
|
|
62
|
+
model.constructor._RELATIONS[key] === true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.RelationUtils = RelationUtils;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RWSModel } from "../_model";
|
|
2
|
+
export declare class TimeSeriesUtils {
|
|
3
|
+
static getTimeSeriesModelFields(model: RWSModel<any>): {
|
|
4
|
+
[key: string]: {
|
|
5
|
+
collection: string;
|
|
6
|
+
hydrationField: string;
|
|
7
|
+
ids: string[];
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
static checkTimeSeries(constructor: any): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimeSeriesUtils = void 0;
|
|
4
|
+
class TimeSeriesUtils {
|
|
5
|
+
static getTimeSeriesModelFields(model) {
|
|
6
|
+
const timeSeriesIds = {};
|
|
7
|
+
for (const key in model) {
|
|
8
|
+
if (model.hasOwnProperty(key)) {
|
|
9
|
+
const meta = Reflect.getMetadata(`InverseTimeSeries:${key}`, model);
|
|
10
|
+
if (meta) {
|
|
11
|
+
if (!timeSeriesIds[key]) {
|
|
12
|
+
timeSeriesIds[key] = {
|
|
13
|
+
collection: meta.timeSeriesModel,
|
|
14
|
+
hydrationField: meta.hydrationField,
|
|
15
|
+
ids: model[key]
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return timeSeriesIds;
|
|
22
|
+
}
|
|
23
|
+
static checkTimeSeries(constructor) {
|
|
24
|
+
const data = constructor.prototype;
|
|
25
|
+
for (const key in data) {
|
|
26
|
+
if (data.hasOwnProperty(key)) {
|
|
27
|
+
if (Reflect.getMetadata(`InverseTimeSeries:${key}`, constructor.prototype)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.TimeSeriesUtils = TimeSeriesUtils;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Collection } from 'mongodb';
|
|
2
2
|
import { ITimeSeries } from '../types/ITimeSeries';
|
|
3
|
-
import { IModel } from '../models/
|
|
3
|
+
import { IModel } from '../models/interfaces/IModel';
|
|
4
4
|
import { IDbConfigHandler } from '../types/DbConfigHandler';
|
|
5
|
+
import { IPaginationParams } from 'src/types/FindParams';
|
|
5
6
|
interface IDBClientCreate {
|
|
6
7
|
dbUrl?: string;
|
|
7
8
|
dbName?: string;
|
|
@@ -26,7 +27,7 @@ declare class DBService {
|
|
|
26
27
|
delete(collection: string, conditions: any): Promise<void>;
|
|
27
28
|
findBy(collection: string, conditions: any, fields?: string[] | null, ordering?: {
|
|
28
29
|
[fieldName: string]: string;
|
|
29
|
-
},
|
|
30
|
+
}, pagination?: IPaginationParams): Promise<IModel[]>;
|
|
30
31
|
collectionExists(collection_name: string): Promise<boolean>;
|
|
31
32
|
createTimeSeriesCollection(collection_name: string): Promise<Collection<ITimeSeries>>;
|
|
32
33
|
private getCollectionHandler;
|
|
@@ -127,7 +127,7 @@ class DBService {
|
|
|
127
127
|
await this.getCollectionHandler(collection).deleteMany({ where: conditions });
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
|
-
async findBy(collection, conditions, fields = null, ordering = null,
|
|
130
|
+
async findBy(collection, conditions, fields = null, ordering = null, pagination = null) {
|
|
131
131
|
const params = { where: conditions };
|
|
132
132
|
if (fields) {
|
|
133
133
|
params.select = {};
|
|
@@ -138,6 +138,10 @@ class DBService {
|
|
|
138
138
|
if (ordering) {
|
|
139
139
|
params.orderBy = ordering;
|
|
140
140
|
}
|
|
141
|
+
if (pagination) {
|
|
142
|
+
params.skip = pagination.page * pagination.per_page;
|
|
143
|
+
params.take = pagination.per_page;
|
|
144
|
+
}
|
|
141
145
|
const retData = await this.getCollectionHandler(collection).findMany(params);
|
|
142
146
|
return retData;
|
|
143
147
|
}
|
|
File without changes
|
package/dist/types/FindParams.js
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/types/IRWSModel.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { OpModelType } from '../models/
|
|
2
|
+
import { OpModelType } from '../models/interfaces/OpModelType';
|
|
3
3
|
|
|
4
4
|
interface ITrackerOpts{
|
|
5
5
|
required?: boolean,
|
|
@@ -53,4 +53,4 @@ function TrackType(type: any, opts: ITrackerOpts | null = null, tags: string[] =
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export default TrackType;
|
|
56
|
-
export {IMetaOpts, ITrackerOpts};
|
|
56
|
+
export {IMetaOpts, ITrackerOpts};
|
package/src/models/_model.ts
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated This file is deprecated. Import from 'models' directory instead.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
IModel,
|
|
7
|
+
IRWSModelServices,
|
|
8
|
+
OpModelType,
|
|
9
|
+
RelationBindType,
|
|
10
|
+
RelOneMetaType,
|
|
11
|
+
RelManyMetaType,
|
|
12
|
+
RWSModel,
|
|
13
|
+
TrackType,
|
|
14
|
+
IMetaOpts
|
|
15
|
+
} from './index';
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
IModel,
|
|
19
|
+
IRWSModelServices,
|
|
20
|
+
OpModelType,
|
|
21
|
+
RelationBindType,
|
|
22
|
+
RelOneMetaType,
|
|
23
|
+
RelManyMetaType,
|
|
24
|
+
RWSModel,
|
|
25
|
+
TrackType,
|
|
26
|
+
IMetaOpts
|
|
25
27
|
};
|
|
28
|
+
<<<<<<< HEAD
|
|
26
29
|
|
|
27
30
|
type RelOneMetaType<T extends IRWSModel> = {[key: string]: {required: boolean, key?: string, model: OpModelType<T>, hydrationField: string, foreignKey: string}};
|
|
28
31
|
type RelManyMetaType<T extends IRWSModel> = {[key: string]: {key: string, inversionModel: OpModelType<T>, foreignKey: string}};
|
|
@@ -674,3 +677,5 @@ class RWSModel<ChildClass> implements IModel{
|
|
|
674
677
|
export { IModel, TrackType, IMetaOpts, RWSModel };
|
|
675
678
|
|
|
676
679
|
|
|
680
|
+
=======
|
|
681
|
+
>>>>>>> 7c50786 (v2.2.0)
|