@rws-framework/db 2.4.0 → 2.4.2
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 +12 -12
- package/dist/decorators/InverseRelation.js +24 -24
- package/dist/decorators/InverseTimeSeries.d.ts +8 -8
- package/dist/decorators/InverseTimeSeries.js +13 -13
- package/dist/decorators/RWSCollection.d.ts +12 -12
- package/dist/decorators/RWSCollection.js +16 -16
- package/dist/decorators/Relation.d.ts +19 -19
- package/dist/decorators/Relation.js +26 -26
- package/dist/decorators/TrackType.d.ts +20 -20
- package/dist/decorators/TrackType.js +41 -41
- package/dist/decorators/index.d.ts +5 -5
- package/dist/decorators/index.js +14 -14
- package/dist/helper/DbHelper.d.ts +12 -8
- package/dist/helper/DbHelper.js +185 -137
- package/dist/helper/FieldsHelper.d.ts +4 -4
- package/dist/helper/FieldsHelper.js +35 -35
- package/dist/index.d.ts +12 -12
- package/dist/index.js +19 -19
- package/dist/models/_model.d.ts +6 -6
- package/dist/models/_model.js +9 -9
- package/dist/models/core/RWSModel.d.ts +66 -66
- package/dist/models/core/RWSModel.js +400 -400
- package/dist/models/core/TimeSeriesModel.d.ts +1 -1
- package/dist/models/core/TimeSeriesModel.js +14 -14
- package/dist/models/index.d.ts +7 -7
- package/dist/models/index.js +8 -8
- package/dist/models/interfaces/IModel.d.ts +11 -11
- package/dist/models/interfaces/IModel.js +2 -2
- package/dist/models/interfaces/IRWSModelServices.d.ts +6 -6
- package/dist/models/interfaces/IRWSModelServices.js +2 -2
- package/dist/models/interfaces/OpModelType.d.ts +31 -31
- package/dist/models/interfaces/OpModelType.js +2 -2
- package/dist/models/types/RelationTypes.d.ts +24 -24
- package/dist/models/types/RelationTypes.js +2 -2
- package/dist/models/utils/ModelUtils.d.ts +10 -10
- package/dist/models/utils/ModelUtils.js +56 -56
- package/dist/models/utils/PaginationUtils.d.ts +5 -5
- package/dist/models/utils/PaginationUtils.js +32 -32
- package/dist/models/utils/RelationUtils.d.ts +14 -14
- package/dist/models/utils/RelationUtils.js +65 -65
- package/dist/models/utils/TimeSeriesUtils.d.ts +11 -11
- package/dist/models/utils/TimeSeriesUtils.js +35 -35
- package/dist/services/DBService.d.ts +37 -37
- package/dist/services/DBService.js +198 -198
- package/dist/types/DbConfigHandler.d.ts +14 -9
- package/dist/types/DbConfigHandler.js +2 -2
- package/dist/types/FindParams.d.ts +14 -14
- package/dist/types/FindParams.js +2 -2
- package/dist/types/IRWSModel.d.ts +3 -3
- package/dist/types/IRWSModel.js +2 -2
- package/dist/types/ITimeSeries.d.ts +6 -6
- package/dist/types/ITimeSeries.js +2 -2
- package/exec/src/cli.ts +1 -0
- package/package.json +1 -1
- package/src/helper/DbHelper.ts +77 -12
- package/src/index.ts +2 -1
- package/src/models/core/RWSModel.ts +3 -3
- package/src/models/interfaces/IModel.ts +1 -1
- package/src/models/utils/RelationUtils.ts +1 -1
- package/src/types/DbConfigHandler.ts +6 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// export default class TimeSeriesModel<T> extends RWSModel<T> {
|
|
4
|
-
// @TrackType(Number) value: number;
|
|
5
|
-
// @TrackType(Date) timestamp: Date;
|
|
6
|
-
// @TrackType(Object)
|
|
7
|
-
// params: any;
|
|
8
|
-
// constructor(data?: any) {
|
|
9
|
-
// super(data);
|
|
10
|
-
// if(!this.timestamp) {
|
|
11
|
-
// this.timestamp = new Date();
|
|
12
|
-
// }
|
|
13
|
-
// }
|
|
14
|
-
// }
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// export default class TimeSeriesModel<T> extends RWSModel<T> {
|
|
4
|
+
// @TrackType(Number) value: number;
|
|
5
|
+
// @TrackType(Date) timestamp: Date;
|
|
6
|
+
// @TrackType(Object)
|
|
7
|
+
// params: any;
|
|
8
|
+
// constructor(data?: any) {
|
|
9
|
+
// super(data);
|
|
10
|
+
// if(!this.timestamp) {
|
|
11
|
+
// this.timestamp = new Date();
|
|
12
|
+
// }
|
|
13
|
+
// }
|
|
14
|
+
// }
|
package/dist/models/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IModel } from './interfaces/IModel';
|
|
2
|
-
import { IRWSModelServices } from './interfaces/IRWSModelServices';
|
|
3
|
-
import { OpModelType } from './interfaces/OpModelType';
|
|
4
|
-
import { RelationBindType, RelOneMetaType, RelManyMetaType } from './types/RelationTypes';
|
|
5
|
-
import { RWSModel } from './core/RWSModel';
|
|
6
|
-
import { TrackType, IMetaOpts } from '../decorators';
|
|
7
|
-
export { IModel, IRWSModelServices, OpModelType, RelationBindType, RelOneMetaType, RelManyMetaType, RWSModel, TrackType, IMetaOpts };
|
|
1
|
+
import { IModel } from './interfaces/IModel';
|
|
2
|
+
import { IRWSModelServices } from './interfaces/IRWSModelServices';
|
|
3
|
+
import { OpModelType } from './interfaces/OpModelType';
|
|
4
|
+
import { RelationBindType, RelOneMetaType, RelManyMetaType } from './types/RelationTypes';
|
|
5
|
+
import { RWSModel } from './core/RWSModel';
|
|
6
|
+
import { TrackType, IMetaOpts } from '../decorators';
|
|
7
|
+
export { IModel, IRWSModelServices, OpModelType, RelationBindType, RelOneMetaType, RelManyMetaType, RWSModel, TrackType, IMetaOpts };
|
package/dist/models/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TrackType = exports.RWSModel = void 0;
|
|
4
|
-
const RWSModel_1 = require("./core/RWSModel");
|
|
5
|
-
Object.defineProperty(exports, "RWSModel", { enumerable: true, get: function () { return RWSModel_1.RWSModel; } });
|
|
6
|
-
// import TimeSeriesModel from './core/TimeSeriesModel';
|
|
7
|
-
const decorators_1 = require("../decorators");
|
|
8
|
-
Object.defineProperty(exports, "TrackType", { enumerable: true, get: function () { return decorators_1.TrackType; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrackType = exports.RWSModel = void 0;
|
|
4
|
+
const RWSModel_1 = require("./core/RWSModel");
|
|
5
|
+
Object.defineProperty(exports, "RWSModel", { enumerable: true, get: function () { return RWSModel_1.RWSModel; } });
|
|
6
|
+
// import TimeSeriesModel from './core/TimeSeriesModel';
|
|
7
|
+
const decorators_1 = require("../decorators");
|
|
8
|
+
Object.defineProperty(exports, "TrackType", { enumerable: true, get: function () { return decorators_1.TrackType; } });
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { IDbConfigHandler } from '../../types/DbConfigHandler';
|
|
2
|
-
import { DBService } from '../../services/DBService';
|
|
3
|
-
export interface IModel {
|
|
4
|
-
[key: string]: any;
|
|
5
|
-
id: string | null;
|
|
6
|
-
save: () => void;
|
|
7
|
-
getDb: () => DBService;
|
|
8
|
-
getCollection: () => string | null;
|
|
9
|
-
configService?: IDbConfigHandler;
|
|
10
|
-
dbService?: DBService;
|
|
11
|
-
}
|
|
1
|
+
import { IDbConfigHandler } from '../../types/DbConfigHandler';
|
|
2
|
+
import { DBService } from '../../services/DBService';
|
|
3
|
+
export interface IModel {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
id: string | number | null;
|
|
6
|
+
save: () => void;
|
|
7
|
+
getDb: () => DBService;
|
|
8
|
+
getCollection: () => string | null;
|
|
9
|
+
configService?: IDbConfigHandler;
|
|
10
|
+
dbService?: DBService;
|
|
11
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IDbConfigHandler } from '../../types/DbConfigHandler';
|
|
2
|
-
import { DBService } from '../../services/DBService';
|
|
3
|
-
export interface IRWSModelServices {
|
|
4
|
-
configService?: IDbConfigHandler;
|
|
5
|
-
dbService?: DBService;
|
|
6
|
-
}
|
|
1
|
+
import { IDbConfigHandler } from '../../types/DbConfigHandler';
|
|
2
|
+
import { DBService } from '../../services/DBService';
|
|
3
|
+
export interface IRWSModelServices {
|
|
4
|
+
configService?: IDbConfigHandler;
|
|
5
|
+
dbService?: DBService;
|
|
6
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { IRWSModel } from '../../types/IRWSModel';
|
|
2
|
-
import { FindByType, IPaginationParams } from '../../types/FindParams';
|
|
3
|
-
import { IRWSModelServices } from './IRWSModelServices';
|
|
4
|
-
import { RelOneMetaType, RelManyMetaType } from '../types/RelationTypes';
|
|
5
|
-
import { DBService } from '../../services/DBService';
|
|
6
|
-
import type { RWSModel } from '../core/RWSModel';
|
|
7
|
-
export interface OpModelType<T> {
|
|
8
|
-
new (data?: any | null): T;
|
|
9
|
-
services: IRWSModelServices;
|
|
10
|
-
name: string;
|
|
11
|
-
_collection: string;
|
|
12
|
-
_RELATIONS: {
|
|
13
|
-
[key: string]: boolean;
|
|
14
|
-
};
|
|
15
|
-
_CUT_KEYS: string[];
|
|
16
|
-
allModels: OpModelType<any>[];
|
|
17
|
-
loadModels: () => OpModelType<any>[];
|
|
18
|
-
checkForInclusionWithThrow: (className: string) => void;
|
|
19
|
-
checkForInclusion: (className: string) => boolean;
|
|
20
|
-
findOneBy<T extends RWSModel<T>>(this: OpModelType<T>, findParams?: FindByType): Promise<T | null>;
|
|
21
|
-
find<T extends RWSModel<T>>(this: OpModelType<T>, id: string, findParams?: Omit<FindByType, 'conditions'>): Promise<T | null>;
|
|
22
|
-
findBy<T extends RWSModel<T>>(this: OpModelType<T>, findParams?: FindByType): Promise<T[]>;
|
|
23
|
-
paginate<T extends RWSModel<T>>(this: OpModelType<T>, paginateParams?: IPaginationParams, findParams?: FindByType): Promise<T[]>;
|
|
24
|
-
delete<T extends RWSModel<T>>(this: OpModelType<T>, conditions: any): Promise<void>;
|
|
25
|
-
create<T extends RWSModel<T>>(this: new () => T, data: any): Promise<T>;
|
|
26
|
-
getRelationOneMeta(model: any, classFields: string[]): Promise<RelOneMetaType<IRWSModel>>;
|
|
27
|
-
getRelationManyMeta(model: any, classFields: string[]): Promise<RelManyMetaType<IRWSModel>>;
|
|
28
|
-
getCollection(): string;
|
|
29
|
-
getDb(): DBService;
|
|
30
|
-
setServices(services: IRWSModelServices): void;
|
|
31
|
-
}
|
|
1
|
+
import { IRWSModel } from '../../types/IRWSModel';
|
|
2
|
+
import { FindByType, IPaginationParams } from '../../types/FindParams';
|
|
3
|
+
import { IRWSModelServices } from './IRWSModelServices';
|
|
4
|
+
import { RelOneMetaType, RelManyMetaType } from '../types/RelationTypes';
|
|
5
|
+
import { DBService } from '../../services/DBService';
|
|
6
|
+
import type { RWSModel } from '../core/RWSModel';
|
|
7
|
+
export interface OpModelType<T> {
|
|
8
|
+
new (data?: any | null): T;
|
|
9
|
+
services: IRWSModelServices;
|
|
10
|
+
name: string;
|
|
11
|
+
_collection: string;
|
|
12
|
+
_RELATIONS: {
|
|
13
|
+
[key: string]: boolean;
|
|
14
|
+
};
|
|
15
|
+
_CUT_KEYS: string[];
|
|
16
|
+
allModels: OpModelType<any>[];
|
|
17
|
+
loadModels: () => OpModelType<any>[];
|
|
18
|
+
checkForInclusionWithThrow: (className: string) => void;
|
|
19
|
+
checkForInclusion: (className: string) => boolean;
|
|
20
|
+
findOneBy<T extends RWSModel<T>>(this: OpModelType<T>, findParams?: FindByType): Promise<T | null>;
|
|
21
|
+
find<T extends RWSModel<T>>(this: OpModelType<T>, id: string, findParams?: Omit<FindByType, 'conditions'>): Promise<T | null>;
|
|
22
|
+
findBy<T extends RWSModel<T>>(this: OpModelType<T>, findParams?: FindByType): Promise<T[]>;
|
|
23
|
+
paginate<T extends RWSModel<T>>(this: OpModelType<T>, paginateParams?: IPaginationParams, findParams?: FindByType): Promise<T[]>;
|
|
24
|
+
delete<T extends RWSModel<T>>(this: OpModelType<T>, conditions: any): Promise<void>;
|
|
25
|
+
create<T extends RWSModel<T>>(this: new () => T, data: any): Promise<T>;
|
|
26
|
+
getRelationOneMeta(model: any, classFields: string[]): Promise<RelOneMetaType<IRWSModel>>;
|
|
27
|
+
getRelationManyMeta(model: any, classFields: string[]): Promise<RelManyMetaType<IRWSModel>>;
|
|
28
|
+
getCollection(): string;
|
|
29
|
+
getDb(): DBService;
|
|
30
|
+
setServices(services: IRWSModelServices): void;
|
|
31
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { IRWSModel } from '../../types/IRWSModel';
|
|
2
|
-
type OpModelType<T> = any;
|
|
3
|
-
export type RelationBindType = {
|
|
4
|
-
connect: {
|
|
5
|
-
id: string;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
export type RelOneMetaType<T extends IRWSModel> = {
|
|
9
|
-
[key: string]: {
|
|
10
|
-
required: boolean;
|
|
11
|
-
key?: string;
|
|
12
|
-
model: OpModelType<T>;
|
|
13
|
-
hydrationField: string;
|
|
14
|
-
foreignKey: string;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export type RelManyMetaType<T extends IRWSModel> = {
|
|
18
|
-
[key: string]: {
|
|
19
|
-
key: string;
|
|
20
|
-
inversionModel: OpModelType<T>;
|
|
21
|
-
foreignKey: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export {};
|
|
1
|
+
import { IRWSModel } from '../../types/IRWSModel';
|
|
2
|
+
type OpModelType<T> = any;
|
|
3
|
+
export type RelationBindType = {
|
|
4
|
+
connect: {
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export type RelOneMetaType<T extends IRWSModel> = {
|
|
9
|
+
[key: string]: {
|
|
10
|
+
required: boolean;
|
|
11
|
+
key?: string;
|
|
12
|
+
model: OpModelType<T>;
|
|
13
|
+
hydrationField: string;
|
|
14
|
+
foreignKey: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type RelManyMetaType<T extends IRWSModel> = {
|
|
18
|
+
[key: string]: {
|
|
19
|
+
key: string;
|
|
20
|
+
inversionModel: OpModelType<T>;
|
|
21
|
+
foreignKey: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { RWSModel } from "../core/RWSModel";
|
|
2
|
-
export declare class ModelUtils {
|
|
3
|
-
static getModelAnnotations<T extends unknown>(constructor: new () => T): Promise<Record<string, {
|
|
4
|
-
annotationType: string;
|
|
5
|
-
metadata: any;
|
|
6
|
-
}>>;
|
|
7
|
-
static checkDbVariable(constructor: any, variable: string): Promise<boolean>;
|
|
8
|
-
static isSubclass<T, C extends new () => T>(constructor: C, baseClass: new () => T): boolean;
|
|
9
|
-
static getModelScalarFields(model: RWSModel<any>): string[];
|
|
10
|
-
}
|
|
1
|
+
import { RWSModel } from "../core/RWSModel";
|
|
2
|
+
export declare class ModelUtils {
|
|
3
|
+
static getModelAnnotations<T extends unknown>(constructor: new () => T): Promise<Record<string, {
|
|
4
|
+
annotationType: string;
|
|
5
|
+
metadata: any;
|
|
6
|
+
}>>;
|
|
7
|
+
static checkDbVariable(constructor: any, variable: string): Promise<boolean>;
|
|
8
|
+
static isSubclass<T, C extends new () => T>(constructor: C, baseClass: new () => T): boolean;
|
|
9
|
+
static getModelScalarFields(model: RWSModel<any>): string[];
|
|
10
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelUtils = void 0;
|
|
4
|
-
const FieldsHelper_1 = require("../../helper/FieldsHelper");
|
|
5
|
-
class ModelUtils {
|
|
6
|
-
static async getModelAnnotations(constructor) {
|
|
7
|
-
const annotationsData = {};
|
|
8
|
-
const metadataKeys = Reflect.getMetadataKeys(constructor.prototype);
|
|
9
|
-
// Process all metadata keys and collect promises
|
|
10
|
-
const metadataPromises = metadataKeys.map(async (fullKey) => {
|
|
11
|
-
const [annotationType, propertyKey] = fullKey.split(':');
|
|
12
|
-
const metadata = Reflect.getMetadata(fullKey, constructor.prototype);
|
|
13
|
-
if (metadata) {
|
|
14
|
-
// If this is a relation metadata with a promise
|
|
15
|
-
if (metadata.promise && (annotationType === 'Relation' || annotationType === 'InverseRelation')) {
|
|
16
|
-
const resolvedMetadata = await metadata.promise;
|
|
17
|
-
annotationsData[propertyKey] = {
|
|
18
|
-
annotationType,
|
|
19
|
-
metadata: resolvedMetadata
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
// Handle non-relation metadata as before
|
|
24
|
-
const key = metadata.key || propertyKey;
|
|
25
|
-
annotationsData[key] = {
|
|
26
|
-
annotationType,
|
|
27
|
-
metadata
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
// Wait for all metadata to be processed
|
|
33
|
-
await Promise.all(metadataPromises);
|
|
34
|
-
return annotationsData;
|
|
35
|
-
}
|
|
36
|
-
static async checkDbVariable(constructor, variable) {
|
|
37
|
-
if (variable === 'id') {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
const dbAnnotations = await ModelUtils.getModelAnnotations(constructor);
|
|
41
|
-
const dbProperties = Object.keys(dbAnnotations)
|
|
42
|
-
.map((key) => { return { ...dbAnnotations[key], key }; })
|
|
43
|
-
.filter((element) => element.annotationType === 'TrackType')
|
|
44
|
-
.map((element) => element.key);
|
|
45
|
-
return dbProperties.includes(variable);
|
|
46
|
-
}
|
|
47
|
-
static isSubclass(constructor, baseClass) {
|
|
48
|
-
return baseClass.prototype.isPrototypeOf(constructor.prototype);
|
|
49
|
-
}
|
|
50
|
-
static getModelScalarFields(model) {
|
|
51
|
-
return FieldsHelper_1.FieldsHelper.getAllClassFields(model)
|
|
52
|
-
.filter((item) => item.indexOf('TrackType') === 0)
|
|
53
|
-
.map((item) => item.split(':').at(-1));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.ModelUtils = ModelUtils;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelUtils = void 0;
|
|
4
|
+
const FieldsHelper_1 = require("../../helper/FieldsHelper");
|
|
5
|
+
class ModelUtils {
|
|
6
|
+
static async getModelAnnotations(constructor) {
|
|
7
|
+
const annotationsData = {};
|
|
8
|
+
const metadataKeys = Reflect.getMetadataKeys(constructor.prototype);
|
|
9
|
+
// Process all metadata keys and collect promises
|
|
10
|
+
const metadataPromises = metadataKeys.map(async (fullKey) => {
|
|
11
|
+
const [annotationType, propertyKey] = fullKey.split(':');
|
|
12
|
+
const metadata = Reflect.getMetadata(fullKey, constructor.prototype);
|
|
13
|
+
if (metadata) {
|
|
14
|
+
// If this is a relation metadata with a promise
|
|
15
|
+
if (metadata.promise && (annotationType === 'Relation' || annotationType === 'InverseRelation')) {
|
|
16
|
+
const resolvedMetadata = await metadata.promise;
|
|
17
|
+
annotationsData[propertyKey] = {
|
|
18
|
+
annotationType,
|
|
19
|
+
metadata: resolvedMetadata
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// Handle non-relation metadata as before
|
|
24
|
+
const key = metadata.key || propertyKey;
|
|
25
|
+
annotationsData[key] = {
|
|
26
|
+
annotationType,
|
|
27
|
+
metadata
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
// Wait for all metadata to be processed
|
|
33
|
+
await Promise.all(metadataPromises);
|
|
34
|
+
return annotationsData;
|
|
35
|
+
}
|
|
36
|
+
static async checkDbVariable(constructor, variable) {
|
|
37
|
+
if (variable === 'id') {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
const dbAnnotations = await ModelUtils.getModelAnnotations(constructor);
|
|
41
|
+
const dbProperties = Object.keys(dbAnnotations)
|
|
42
|
+
.map((key) => { return { ...dbAnnotations[key], key }; })
|
|
43
|
+
.filter((element) => element.annotationType === 'TrackType')
|
|
44
|
+
.map((element) => element.key);
|
|
45
|
+
return dbProperties.includes(variable);
|
|
46
|
+
}
|
|
47
|
+
static isSubclass(constructor, baseClass) {
|
|
48
|
+
return baseClass.prototype.isPrototypeOf(constructor.prototype);
|
|
49
|
+
}
|
|
50
|
+
static getModelScalarFields(model) {
|
|
51
|
+
return FieldsHelper_1.FieldsHelper.getAllClassFields(model)
|
|
52
|
+
.filter((item) => item.indexOf('TrackType') === 0)
|
|
53
|
+
.map((item) => item.split(':').at(-1));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.ModelUtils = ModelUtils;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OpModelType, RWSModel } from '../_model';
|
|
2
|
-
import { FindByType, IPaginationParams } from '../../types/FindParams';
|
|
3
|
-
export declare class PaginationUtils {
|
|
4
|
-
static paginate<T extends RWSModel<T>>(this: OpModelType<T>, paginationParams?: IPaginationParams, findParams?: FindByType): Promise<T[]>;
|
|
5
|
-
}
|
|
1
|
+
import { OpModelType, RWSModel } from '../_model';
|
|
2
|
+
import { FindByType, IPaginationParams } from '../../types/FindParams';
|
|
3
|
+
export declare class PaginationUtils {
|
|
4
|
+
static paginate<T extends RWSModel<T>>(this: OpModelType<T>, paginationParams?: IPaginationParams, findParams?: FindByType): Promise<T[]>;
|
|
5
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PaginationUtils = void 0;
|
|
4
|
-
class PaginationUtils {
|
|
5
|
-
static async paginate(paginationParams = { page: 0, per_page: 50 }, findParams = {}) {
|
|
6
|
-
var _a, _b, _c, _d, _e;
|
|
7
|
-
const conditions = (_a = findParams === null || findParams === void 0 ? void 0 : findParams.conditions) !== null && _a !== void 0 ? _a : {};
|
|
8
|
-
const ordering = (_b = findParams === null || findParams === void 0 ? void 0 : findParams.ordering) !== null && _b !== void 0 ? _b : null;
|
|
9
|
-
const fields = (_c = findParams === null || findParams === void 0 ? void 0 : findParams.fields) !== null && _c !== void 0 ? _c : null;
|
|
10
|
-
const allowRelations = (_d = findParams === null || findParams === void 0 ? void 0 : findParams.allowRelations) !== null && _d !== void 0 ? _d : true;
|
|
11
|
-
const fullData = (_e = findParams === null || findParams === void 0 ? void 0 : findParams.fullData) !== null && _e !== void 0 ? _e : false;
|
|
12
|
-
const collection = Reflect.get(this, '_collection');
|
|
13
|
-
this.checkForInclusionWithThrow(this.name);
|
|
14
|
-
try {
|
|
15
|
-
const dbData = await this.services.dbService.findBy(collection, conditions, fields, ordering, paginationParams);
|
|
16
|
-
if (dbData.length) {
|
|
17
|
-
const instanced = [];
|
|
18
|
-
for (const data of dbData) {
|
|
19
|
-
const inst = new this();
|
|
20
|
-
instanced.push((await inst._asyncFill(data, fullData, allowRelations)));
|
|
21
|
-
}
|
|
22
|
-
return instanced;
|
|
23
|
-
}
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
|
-
catch (rwsError) {
|
|
27
|
-
console.error(rwsError);
|
|
28
|
-
throw rwsError;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.PaginationUtils = PaginationUtils;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaginationUtils = void 0;
|
|
4
|
+
class PaginationUtils {
|
|
5
|
+
static async paginate(paginationParams = { page: 0, per_page: 50 }, findParams = {}) {
|
|
6
|
+
var _a, _b, _c, _d, _e;
|
|
7
|
+
const conditions = (_a = findParams === null || findParams === void 0 ? void 0 : findParams.conditions) !== null && _a !== void 0 ? _a : {};
|
|
8
|
+
const ordering = (_b = findParams === null || findParams === void 0 ? void 0 : findParams.ordering) !== null && _b !== void 0 ? _b : null;
|
|
9
|
+
const fields = (_c = findParams === null || findParams === void 0 ? void 0 : findParams.fields) !== null && _c !== void 0 ? _c : null;
|
|
10
|
+
const allowRelations = (_d = findParams === null || findParams === void 0 ? void 0 : findParams.allowRelations) !== null && _d !== void 0 ? _d : true;
|
|
11
|
+
const fullData = (_e = findParams === null || findParams === void 0 ? void 0 : findParams.fullData) !== null && _e !== void 0 ? _e : false;
|
|
12
|
+
const collection = Reflect.get(this, '_collection');
|
|
13
|
+
this.checkForInclusionWithThrow(this.name);
|
|
14
|
+
try {
|
|
15
|
+
const dbData = await this.services.dbService.findBy(collection, conditions, fields, ordering, paginationParams);
|
|
16
|
+
if (dbData.length) {
|
|
17
|
+
const instanced = [];
|
|
18
|
+
for (const data of dbData) {
|
|
19
|
+
const inst = new this();
|
|
20
|
+
instanced.push((await inst._asyncFill(data, fullData, allowRelations)));
|
|
21
|
+
}
|
|
22
|
+
return instanced;
|
|
23
|
+
}
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
catch (rwsError) {
|
|
27
|
+
console.error(rwsError);
|
|
28
|
+
throw rwsError;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.PaginationUtils = PaginationUtils;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { RelOneMetaType, RelManyMetaType } from '../types/RelationTypes';
|
|
2
|
-
import { IRWSModel } from '../../types/IRWSModel';
|
|
3
|
-
import { RWSModel } from '../_model';
|
|
4
|
-
export declare class RelationUtils {
|
|
5
|
-
static getRelationOneMeta(model: RWSModel<any>, classFields: string[]): Promise<RelOneMetaType<IRWSModel>>;
|
|
6
|
-
static getRelationManyMeta(model: RWSModel<any>, classFields: string[]): Promise<RelManyMetaType<IRWSModel>>;
|
|
7
|
-
static bindRelation(relatedModel: RWSModel<any>): {
|
|
8
|
-
connect: {
|
|
9
|
-
id: string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
static hasRelation(model: RWSModel<any>, key: string): boolean;
|
|
13
|
-
static checkRelEnabled(model: RWSModel<any>, key: string): boolean;
|
|
14
|
-
}
|
|
1
|
+
import { RelOneMetaType, RelManyMetaType } from '../types/RelationTypes';
|
|
2
|
+
import { IRWSModel } from '../../types/IRWSModel';
|
|
3
|
+
import { RWSModel } from '../_model';
|
|
4
|
+
export declare class RelationUtils {
|
|
5
|
+
static getRelationOneMeta(model: RWSModel<any>, classFields: string[]): Promise<RelOneMetaType<IRWSModel>>;
|
|
6
|
+
static getRelationManyMeta(model: RWSModel<any>, classFields: string[]): Promise<RelManyMetaType<IRWSModel>>;
|
|
7
|
+
static bindRelation(relatedModel: RWSModel<any>): {
|
|
8
|
+
connect: {
|
|
9
|
+
id: string | number;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
static hasRelation(model: RWSModel<any>, key: string): boolean;
|
|
13
|
+
static checkRelEnabled(model: RWSModel<any>, key: string): boolean;
|
|
14
|
+
}
|
|
@@ -1,65 +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;
|
|
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;
|