@rws-framework/db 2.3.2 → 2.4.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/.bin/add-v.sh +9 -9
- package/.bin/emerge.sh +10 -10
- package/.eslintrc.json +53 -53
- package/README.md +404 -367
- 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 +0 -0
- 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 +7 -7
- 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 +7 -7
- package/dist/models/TimeSeriesModel.js +33 -33
- package/dist/models/_model.d.ts +0 -0
- package/dist/models/_model.js +0 -0
- package/dist/models/core/RWSModel.d.ts +0 -0
- package/dist/models/core/RWSModel.js +0 -0
- package/dist/models/core/TimeSeriesModel.d.ts +0 -0
- package/dist/models/core/TimeSeriesModel.js +0 -0
- package/dist/models/index.d.ts +0 -0
- package/dist/models/index.js +0 -0
- package/dist/models/interfaces/IModel.d.ts +0 -0
- package/dist/models/interfaces/IModel.js +0 -0
- package/dist/models/interfaces/IRWSModelServices.d.ts +0 -0
- package/dist/models/interfaces/IRWSModelServices.js +0 -0
- package/dist/models/interfaces/OpModelType.d.ts +0 -0
- package/dist/models/interfaces/OpModelType.js +0 -0
- package/dist/models/types/RelationTypes.d.ts +0 -0
- package/dist/models/types/RelationTypes.js +0 -0
- package/dist/models/utils/ModelUtils.d.ts +0 -0
- package/dist/models/utils/ModelUtils.js +0 -0
- package/dist/models/utils/PaginationUtils.d.ts +0 -0
- package/dist/models/utils/PaginationUtils.js +0 -0
- package/dist/models/utils/RelationUtils.d.ts +0 -0
- package/dist/models/utils/RelationUtils.js +0 -0
- package/dist/models/utils/TimeSeriesUtils.d.ts +0 -0
- package/dist/models/utils/TimeSeriesUtils.js +0 -0
- package/dist/services/DBService.d.ts +1 -1
- package/dist/services/DBService.js +6 -6
- package/dist/types/DbConfigHandler.d.ts +3 -2
- package/dist/types/DbConfigHandler.js +0 -0
- package/dist/types/FindParams.d.ts +0 -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/exec/console.js +110 -110
- package/exec/db.rws.webpack.config.js +168 -168
- package/exec/src/cli.ts +75 -73
- package/exec/tsconfig.json +32 -32
- package/exec/webpackFilters.js +17 -17
- package/package.json +36 -36
- package/src/decorators/InverseRelation.ts +36 -36
- package/src/decorators/InverseTimeSeries.ts +21 -21
- package/src/decorators/RWSCollection.ts +27 -27
- package/src/decorators/Relation.ts +47 -47
- package/src/decorators/TrackType.ts +69 -69
- package/src/decorators/index.ts +7 -7
- package/src/empty.js +0 -0
- package/src/helper/DbHelper.ts +177 -177
- package/src/helper/FieldsHelper.ts +34 -34
- package/src/index.ts +36 -36
- package/src/models/_model.ts +29 -29
- package/src/models/core/RWSModel.ts +520 -520
- package/src/models/core/TimeSeriesModel.ts +19 -19
- package/src/models/index.ts +20 -20
- package/src/models/interfaces/IModel.ts +12 -12
- package/src/models/interfaces/IRWSModelServices.ts +7 -7
- package/src/models/interfaces/OpModelType.ts +49 -49
- package/src/models/types/RelationTypes.ts +25 -25
- package/src/models/utils/ModelUtils.ts +65 -65
- package/src/models/utils/PaginationUtils.ts +42 -42
- package/src/models/utils/RelationUtils.ts +76 -76
- package/src/models/utils/TimeSeriesUtils.ts +38 -38
- package/src/services/DBService.ts +277 -277
- package/src/types/DbConfigHandler.ts +12 -11
- package/src/types/FindParams.ts +13 -13
- package/src/types/IRWSModel.ts +2 -2
- package/src/types/ITimeSeries.ts +5 -5
- package/tsconfig.json +22 -22
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { RWSModel } from './RWSModel';
|
|
2
|
-
import { TrackType } from '../../decorators';
|
|
3
|
-
|
|
4
|
-
// export default class TimeSeriesModel<T> extends RWSModel<T> {
|
|
5
|
-
// @TrackType(Number) value: number;
|
|
6
|
-
|
|
7
|
-
// @TrackType(Date) timestamp: Date;
|
|
8
|
-
|
|
9
|
-
// @TrackType(Object)
|
|
10
|
-
// params: any;
|
|
11
|
-
|
|
12
|
-
// constructor(data?: any) {
|
|
13
|
-
// super(data);
|
|
14
|
-
|
|
15
|
-
// if(!this.timestamp) {
|
|
16
|
-
// this.timestamp = new Date();
|
|
17
|
-
// }
|
|
18
|
-
// }
|
|
19
|
-
// }
|
|
1
|
+
import { RWSModel } from './RWSModel';
|
|
2
|
+
import { TrackType } from '../../decorators';
|
|
3
|
+
|
|
4
|
+
// export default class TimeSeriesModel<T> extends RWSModel<T> {
|
|
5
|
+
// @TrackType(Number) value: number;
|
|
6
|
+
|
|
7
|
+
// @TrackType(Date) timestamp: Date;
|
|
8
|
+
|
|
9
|
+
// @TrackType(Object)
|
|
10
|
+
// params: any;
|
|
11
|
+
|
|
12
|
+
// constructor(data?: any) {
|
|
13
|
+
// super(data);
|
|
14
|
+
|
|
15
|
+
// if(!this.timestamp) {
|
|
16
|
+
// this.timestamp = new Date();
|
|
17
|
+
// }
|
|
18
|
+
// }
|
|
19
|
+
// }
|
package/src/models/index.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
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 TimeSeriesModel from './core/TimeSeriesModel';
|
|
7
|
-
import { TrackType, IMetaOpts } from '../decorators';
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
IModel,
|
|
11
|
-
IRWSModelServices,
|
|
12
|
-
OpModelType,
|
|
13
|
-
RelationBindType,
|
|
14
|
-
RelOneMetaType,
|
|
15
|
-
RelManyMetaType,
|
|
16
|
-
RWSModel,
|
|
17
|
-
// TimeSeriesModel,
|
|
18
|
-
TrackType,
|
|
19
|
-
IMetaOpts
|
|
20
|
-
};
|
|
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 TimeSeriesModel from './core/TimeSeriesModel';
|
|
7
|
+
import { TrackType, IMetaOpts } from '../decorators';
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
IModel,
|
|
11
|
+
IRWSModelServices,
|
|
12
|
+
OpModelType,
|
|
13
|
+
RelationBindType,
|
|
14
|
+
RelOneMetaType,
|
|
15
|
+
RelManyMetaType,
|
|
16
|
+
RWSModel,
|
|
17
|
+
// TimeSeriesModel,
|
|
18
|
+
TrackType,
|
|
19
|
+
IMetaOpts
|
|
20
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { IDbConfigHandler } from '../../types/DbConfigHandler';
|
|
2
|
-
import { DBService } from '../../services/DBService';
|
|
3
|
-
|
|
4
|
-
export interface IModel {
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
id: string | null;
|
|
7
|
-
save: () => void;
|
|
8
|
-
getDb: () => DBService;
|
|
9
|
-
getCollection: () => string | null;
|
|
10
|
-
configService?: IDbConfigHandler;
|
|
11
|
-
dbService?: DBService;
|
|
12
|
-
}
|
|
1
|
+
import { IDbConfigHandler } from '../../types/DbConfigHandler';
|
|
2
|
+
import { DBService } from '../../services/DBService';
|
|
3
|
+
|
|
4
|
+
export interface IModel {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
id: string | null;
|
|
7
|
+
save: () => void;
|
|
8
|
+
getDb: () => DBService;
|
|
9
|
+
getCollection: () => string | null;
|
|
10
|
+
configService?: IDbConfigHandler;
|
|
11
|
+
dbService?: DBService;
|
|
12
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IDbConfigHandler } from '../../types/DbConfigHandler';
|
|
2
|
-
import { DBService } from '../../services/DBService';
|
|
3
|
-
|
|
4
|
-
export interface IRWSModelServices {
|
|
5
|
-
configService?: IDbConfigHandler;
|
|
6
|
-
dbService?: DBService;
|
|
7
|
-
}
|
|
1
|
+
import { IDbConfigHandler } from '../../types/DbConfigHandler';
|
|
2
|
+
import { DBService } from '../../services/DBService';
|
|
3
|
+
|
|
4
|
+
export interface IRWSModelServices {
|
|
5
|
+
configService?: IDbConfigHandler;
|
|
6
|
+
dbService?: DBService;
|
|
7
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
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
|
-
|
|
7
|
-
// Reference to the RWSModel class to avoid circular dependency
|
|
8
|
-
import type { RWSModel } from '../core/RWSModel';
|
|
9
|
-
|
|
10
|
-
export interface OpModelType<T> {
|
|
11
|
-
new(data?: any | null): T;
|
|
12
|
-
services: IRWSModelServices;
|
|
13
|
-
name: string;
|
|
14
|
-
_collection: string;
|
|
15
|
-
_RELATIONS: {[key: string]: boolean};
|
|
16
|
-
_CUT_KEYS: string[];
|
|
17
|
-
allModels: OpModelType<any>[];
|
|
18
|
-
loadModels: () => OpModelType<any>[];
|
|
19
|
-
checkForInclusionWithThrow: (className: string) => void;
|
|
20
|
-
checkForInclusion: (className: string) => boolean;
|
|
21
|
-
findOneBy<T extends RWSModel<T>>(
|
|
22
|
-
this: OpModelType<T>,
|
|
23
|
-
findParams?: FindByType
|
|
24
|
-
): Promise<T | null>;
|
|
25
|
-
find<T extends RWSModel<T>>(
|
|
26
|
-
this: OpModelType<T>,
|
|
27
|
-
id: string,
|
|
28
|
-
findParams?: Omit<FindByType, 'conditions'>
|
|
29
|
-
): Promise<T | null>;
|
|
30
|
-
findBy<T extends RWSModel<T>>(
|
|
31
|
-
this: OpModelType<T>,
|
|
32
|
-
findParams?: FindByType
|
|
33
|
-
): Promise<T[]>;
|
|
34
|
-
paginate<T extends RWSModel<T>>(
|
|
35
|
-
this: OpModelType<T>,
|
|
36
|
-
paginateParams?: IPaginationParams,
|
|
37
|
-
findParams?: FindByType
|
|
38
|
-
): Promise<T[]>;
|
|
39
|
-
delete<T extends RWSModel<T>>(
|
|
40
|
-
this: OpModelType<T>,
|
|
41
|
-
conditions: any
|
|
42
|
-
): Promise<void>;
|
|
43
|
-
create<T extends RWSModel<T>>(this: new () => T, data: any): Promise<T>;
|
|
44
|
-
getRelationOneMeta(model: any, classFields: string[]): Promise<RelOneMetaType<IRWSModel>>;
|
|
45
|
-
getRelationManyMeta(model: any, classFields: string[]): Promise<RelManyMetaType<IRWSModel>>;
|
|
46
|
-
getCollection(): string;
|
|
47
|
-
getDb(): DBService;
|
|
48
|
-
setServices(services: IRWSModelServices): void;
|
|
49
|
-
}
|
|
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
|
+
|
|
7
|
+
// Reference to the RWSModel class to avoid circular dependency
|
|
8
|
+
import type { RWSModel } from '../core/RWSModel';
|
|
9
|
+
|
|
10
|
+
export interface OpModelType<T> {
|
|
11
|
+
new(data?: any | null): T;
|
|
12
|
+
services: IRWSModelServices;
|
|
13
|
+
name: string;
|
|
14
|
+
_collection: string;
|
|
15
|
+
_RELATIONS: {[key: string]: boolean};
|
|
16
|
+
_CUT_KEYS: string[];
|
|
17
|
+
allModels: OpModelType<any>[];
|
|
18
|
+
loadModels: () => OpModelType<any>[];
|
|
19
|
+
checkForInclusionWithThrow: (className: string) => void;
|
|
20
|
+
checkForInclusion: (className: string) => boolean;
|
|
21
|
+
findOneBy<T extends RWSModel<T>>(
|
|
22
|
+
this: OpModelType<T>,
|
|
23
|
+
findParams?: FindByType
|
|
24
|
+
): Promise<T | null>;
|
|
25
|
+
find<T extends RWSModel<T>>(
|
|
26
|
+
this: OpModelType<T>,
|
|
27
|
+
id: string,
|
|
28
|
+
findParams?: Omit<FindByType, 'conditions'>
|
|
29
|
+
): Promise<T | null>;
|
|
30
|
+
findBy<T extends RWSModel<T>>(
|
|
31
|
+
this: OpModelType<T>,
|
|
32
|
+
findParams?: FindByType
|
|
33
|
+
): Promise<T[]>;
|
|
34
|
+
paginate<T extends RWSModel<T>>(
|
|
35
|
+
this: OpModelType<T>,
|
|
36
|
+
paginateParams?: IPaginationParams,
|
|
37
|
+
findParams?: FindByType
|
|
38
|
+
): Promise<T[]>;
|
|
39
|
+
delete<T extends RWSModel<T>>(
|
|
40
|
+
this: OpModelType<T>,
|
|
41
|
+
conditions: any
|
|
42
|
+
): Promise<void>;
|
|
43
|
+
create<T extends RWSModel<T>>(this: new () => T, data: any): Promise<T>;
|
|
44
|
+
getRelationOneMeta(model: any, classFields: string[]): Promise<RelOneMetaType<IRWSModel>>;
|
|
45
|
+
getRelationManyMeta(model: any, classFields: string[]): Promise<RelManyMetaType<IRWSModel>>;
|
|
46
|
+
getCollection(): string;
|
|
47
|
+
getDb(): DBService;
|
|
48
|
+
setServices(services: IRWSModelServices): void;
|
|
49
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { IRWSModel } from '../../types/IRWSModel';
|
|
2
|
-
// Using a type reference to avoid circular dependency
|
|
3
|
-
type OpModelType<T> = any;
|
|
4
|
-
|
|
5
|
-
export type RelationBindType = {
|
|
6
|
-
connect: { id: string }
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export type RelOneMetaType<T extends IRWSModel> = {
|
|
10
|
-
[key: string]: {
|
|
11
|
-
required: boolean,
|
|
12
|
-
key?: string,
|
|
13
|
-
model: OpModelType<T>,
|
|
14
|
-
hydrationField: string,
|
|
15
|
-
foreignKey: string
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type RelManyMetaType<T extends IRWSModel> = {
|
|
20
|
-
[key: string]: {
|
|
21
|
-
key: string,
|
|
22
|
-
inversionModel: OpModelType<T>,
|
|
23
|
-
foreignKey: string
|
|
24
|
-
}
|
|
25
|
-
};
|
|
1
|
+
import { IRWSModel } from '../../types/IRWSModel';
|
|
2
|
+
// Using a type reference to avoid circular dependency
|
|
3
|
+
type OpModelType<T> = any;
|
|
4
|
+
|
|
5
|
+
export type RelationBindType = {
|
|
6
|
+
connect: { id: string }
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type RelOneMetaType<T extends IRWSModel> = {
|
|
10
|
+
[key: string]: {
|
|
11
|
+
required: boolean,
|
|
12
|
+
key?: string,
|
|
13
|
+
model: OpModelType<T>,
|
|
14
|
+
hydrationField: string,
|
|
15
|
+
foreignKey: string
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type RelManyMetaType<T extends IRWSModel> = {
|
|
20
|
+
[key: string]: {
|
|
21
|
+
key: string,
|
|
22
|
+
inversionModel: OpModelType<T>,
|
|
23
|
+
foreignKey: string
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { RWSModel } from "../core/RWSModel";
|
|
2
|
-
import { FieldsHelper } from '../../helper/FieldsHelper';
|
|
3
|
-
|
|
4
|
-
export class ModelUtils {
|
|
5
|
-
static async getModelAnnotations<T extends unknown>(constructor: new () => T): Promise<Record<string, {annotationType: string, metadata: any}>> {
|
|
6
|
-
const annotationsData: Record<string, {annotationType: string, metadata: any}> = {};
|
|
7
|
-
|
|
8
|
-
const metadataKeys = Reflect.getMetadataKeys(constructor.prototype);
|
|
9
|
-
|
|
10
|
-
// Process all metadata keys and collect promises
|
|
11
|
-
const metadataPromises = metadataKeys.map(async (fullKey: string) => {
|
|
12
|
-
const [annotationType, propertyKey] = fullKey.split(':');
|
|
13
|
-
const metadata = Reflect.getMetadata(fullKey, constructor.prototype);
|
|
14
|
-
|
|
15
|
-
if (metadata) {
|
|
16
|
-
// If this is a relation metadata with a promise
|
|
17
|
-
if (metadata.promise && (annotationType === 'Relation' || annotationType === 'InverseRelation')) {
|
|
18
|
-
const resolvedMetadata = await metadata.promise;
|
|
19
|
-
annotationsData[propertyKey] = {
|
|
20
|
-
annotationType,
|
|
21
|
-
metadata: resolvedMetadata
|
|
22
|
-
};
|
|
23
|
-
} else {
|
|
24
|
-
// Handle non-relation metadata as before
|
|
25
|
-
const key = metadata.key || propertyKey;
|
|
26
|
-
annotationsData[key] = {
|
|
27
|
-
annotationType,
|
|
28
|
-
metadata
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Wait for all metadata to be processed
|
|
35
|
-
await Promise.all(metadataPromises);
|
|
36
|
-
|
|
37
|
-
return annotationsData;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static async checkDbVariable(constructor: any, variable: string): Promise<boolean> {
|
|
41
|
-
if(variable === 'id'){
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const dbAnnotations = await ModelUtils.getModelAnnotations(constructor);
|
|
46
|
-
type AnnotationType = { annotationType: string, key: string };
|
|
47
|
-
|
|
48
|
-
const dbProperties: string[] = Object.keys(dbAnnotations)
|
|
49
|
-
.map((key: string): AnnotationType => {return {...dbAnnotations[key], key};})
|
|
50
|
-
.filter((element: AnnotationType) => element.annotationType === 'TrackType' )
|
|
51
|
-
.map((element: AnnotationType) => element.key);
|
|
52
|
-
|
|
53
|
-
return dbProperties.includes(variable);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
static isSubclass<T, C extends new () => T>(constructor: C, baseClass: new () => T): boolean {
|
|
57
|
-
return baseClass.prototype.isPrototypeOf(constructor.prototype);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static getModelScalarFields(model: RWSModel<any>): string[] {
|
|
61
|
-
return FieldsHelper.getAllClassFields(model)
|
|
62
|
-
.filter((item: string) => item.indexOf('TrackType') === 0)
|
|
63
|
-
.map((item: string) => item.split(':').at(-1));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
1
|
+
import { RWSModel } from "../core/RWSModel";
|
|
2
|
+
import { FieldsHelper } from '../../helper/FieldsHelper';
|
|
3
|
+
|
|
4
|
+
export class ModelUtils {
|
|
5
|
+
static async getModelAnnotations<T extends unknown>(constructor: new () => T): Promise<Record<string, {annotationType: string, metadata: any}>> {
|
|
6
|
+
const annotationsData: Record<string, {annotationType: string, metadata: any}> = {};
|
|
7
|
+
|
|
8
|
+
const metadataKeys = Reflect.getMetadataKeys(constructor.prototype);
|
|
9
|
+
|
|
10
|
+
// Process all metadata keys and collect promises
|
|
11
|
+
const metadataPromises = metadataKeys.map(async (fullKey: string) => {
|
|
12
|
+
const [annotationType, propertyKey] = fullKey.split(':');
|
|
13
|
+
const metadata = Reflect.getMetadata(fullKey, constructor.prototype);
|
|
14
|
+
|
|
15
|
+
if (metadata) {
|
|
16
|
+
// If this is a relation metadata with a promise
|
|
17
|
+
if (metadata.promise && (annotationType === 'Relation' || annotationType === 'InverseRelation')) {
|
|
18
|
+
const resolvedMetadata = await metadata.promise;
|
|
19
|
+
annotationsData[propertyKey] = {
|
|
20
|
+
annotationType,
|
|
21
|
+
metadata: resolvedMetadata
|
|
22
|
+
};
|
|
23
|
+
} else {
|
|
24
|
+
// Handle non-relation metadata as before
|
|
25
|
+
const key = metadata.key || propertyKey;
|
|
26
|
+
annotationsData[key] = {
|
|
27
|
+
annotationType,
|
|
28
|
+
metadata
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Wait for all metadata to be processed
|
|
35
|
+
await Promise.all(metadataPromises);
|
|
36
|
+
|
|
37
|
+
return annotationsData;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static async checkDbVariable(constructor: any, variable: string): Promise<boolean> {
|
|
41
|
+
if(variable === 'id'){
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const dbAnnotations = await ModelUtils.getModelAnnotations(constructor);
|
|
46
|
+
type AnnotationType = { annotationType: string, key: string };
|
|
47
|
+
|
|
48
|
+
const dbProperties: string[] = Object.keys(dbAnnotations)
|
|
49
|
+
.map((key: string): AnnotationType => {return {...dbAnnotations[key], key};})
|
|
50
|
+
.filter((element: AnnotationType) => element.annotationType === 'TrackType' )
|
|
51
|
+
.map((element: AnnotationType) => element.key);
|
|
52
|
+
|
|
53
|
+
return dbProperties.includes(variable);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static isSubclass<T, C extends new () => T>(constructor: C, baseClass: new () => T): boolean {
|
|
57
|
+
return baseClass.prototype.isPrototypeOf(constructor.prototype);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static getModelScalarFields(model: RWSModel<any>): string[] {
|
|
61
|
+
return FieldsHelper.getAllClassFields(model)
|
|
62
|
+
.filter((item: string) => item.indexOf('TrackType') === 0)
|
|
63
|
+
.map((item: string) => item.split(':').at(-1));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { RelOneMetaType, RelManyMetaType } from '../types/RelationTypes';
|
|
2
|
-
import { IRWSModel } from '../../types/IRWSModel';
|
|
3
|
-
import { OpModelType, RWSModel } from '../_model';
|
|
4
|
-
import { FindByType, IPaginationParams } from '../../types/FindParams';
|
|
5
|
-
|
|
6
|
-
export class PaginationUtils {
|
|
7
|
-
|
|
8
|
-
public static async paginate<T extends RWSModel<T>>(
|
|
9
|
-
this: OpModelType<T>,
|
|
10
|
-
paginationParams: IPaginationParams = { page: 0, per_page: 50 },
|
|
11
|
-
findParams: FindByType = {},
|
|
12
|
-
): Promise<T[]> {
|
|
13
|
-
const conditions = findParams?.conditions ?? {};
|
|
14
|
-
const ordering = findParams?.ordering ?? null;
|
|
15
|
-
const fields = findParams?.fields ?? null;
|
|
16
|
-
const allowRelations = findParams?.allowRelations ?? true;
|
|
17
|
-
const fullData = findParams?.fullData ?? false;
|
|
18
|
-
|
|
19
|
-
const collection = Reflect.get(this, '_collection');
|
|
20
|
-
this.checkForInclusionWithThrow(this.name);
|
|
21
|
-
try {
|
|
22
|
-
const dbData = await this.services.dbService.findBy(collection, conditions, fields, ordering, paginationParams);
|
|
23
|
-
if (dbData.length) {
|
|
24
|
-
const instanced: T[] = [];
|
|
25
|
-
|
|
26
|
-
for (const data of dbData) {
|
|
27
|
-
const inst: T = new (this as { new(): T })();
|
|
28
|
-
instanced.push((await inst._asyncFill(data, fullData,allowRelations)) as T);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return instanced;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return [];
|
|
35
|
-
} catch (rwsError: Error | any) {
|
|
36
|
-
console.error(rwsError);
|
|
37
|
-
|
|
38
|
-
throw rwsError;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
}
|
|
1
|
+
import { RelOneMetaType, RelManyMetaType } from '../types/RelationTypes';
|
|
2
|
+
import { IRWSModel } from '../../types/IRWSModel';
|
|
3
|
+
import { OpModelType, RWSModel } from '../_model';
|
|
4
|
+
import { FindByType, IPaginationParams } from '../../types/FindParams';
|
|
5
|
+
|
|
6
|
+
export class PaginationUtils {
|
|
7
|
+
|
|
8
|
+
public static async paginate<T extends RWSModel<T>>(
|
|
9
|
+
this: OpModelType<T>,
|
|
10
|
+
paginationParams: IPaginationParams = { page: 0, per_page: 50 },
|
|
11
|
+
findParams: FindByType = {},
|
|
12
|
+
): Promise<T[]> {
|
|
13
|
+
const conditions = findParams?.conditions ?? {};
|
|
14
|
+
const ordering = findParams?.ordering ?? null;
|
|
15
|
+
const fields = findParams?.fields ?? null;
|
|
16
|
+
const allowRelations = findParams?.allowRelations ?? true;
|
|
17
|
+
const fullData = findParams?.fullData ?? false;
|
|
18
|
+
|
|
19
|
+
const collection = Reflect.get(this, '_collection');
|
|
20
|
+
this.checkForInclusionWithThrow(this.name);
|
|
21
|
+
try {
|
|
22
|
+
const dbData = await this.services.dbService.findBy(collection, conditions, fields, ordering, paginationParams);
|
|
23
|
+
if (dbData.length) {
|
|
24
|
+
const instanced: T[] = [];
|
|
25
|
+
|
|
26
|
+
for (const data of dbData) {
|
|
27
|
+
const inst: T = new (this as { new(): T })();
|
|
28
|
+
instanced.push((await inst._asyncFill(data, fullData,allowRelations)) as T);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return instanced;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return [];
|
|
35
|
+
} catch (rwsError: Error | any) {
|
|
36
|
+
console.error(rwsError);
|
|
37
|
+
|
|
38
|
+
throw rwsError;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import { RelOneMetaType, RelManyMetaType } from '../types/RelationTypes';
|
|
2
|
-
import { IRWSModel } from '../../types/IRWSModel';
|
|
3
|
-
import { RWSModel } from '../_model';
|
|
4
|
-
|
|
5
|
-
export class RelationUtils {
|
|
6
|
-
static async getRelationOneMeta(model: RWSModel<any>, classFields: string[]): Promise<RelOneMetaType<IRWSModel>> {
|
|
7
|
-
const relIds: RelOneMetaType<IRWSModel> = {};
|
|
8
|
-
const relationFields = classFields
|
|
9
|
-
.filter((item: string) => item.indexOf('Relation') === 0 && !item.includes('Inverse'))
|
|
10
|
-
.map((item: string) => item.split(':').at(-1));
|
|
11
|
-
|
|
12
|
-
for (const key of relationFields) {
|
|
13
|
-
const metadataKey = `Relation:${key}`;
|
|
14
|
-
const metadata = Reflect.getMetadata(metadataKey, model);
|
|
15
|
-
|
|
16
|
-
if (metadata && metadata.promise) {
|
|
17
|
-
const resolvedMetadata = await metadata.promise;
|
|
18
|
-
if (!relIds[key]) {
|
|
19
|
-
relIds[key] = {
|
|
20
|
-
key: resolvedMetadata.key,
|
|
21
|
-
required: resolvedMetadata.required,
|
|
22
|
-
model: resolvedMetadata.relatedTo,
|
|
23
|
-
hydrationField: resolvedMetadata.relationField,
|
|
24
|
-
foreignKey: resolvedMetadata.relatedToField
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return relIds;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static async getRelationManyMeta(model: RWSModel<any>, classFields: string[]): Promise<RelManyMetaType<IRWSModel>> {
|
|
34
|
-
const relIds: RelManyMetaType<IRWSModel> = {};
|
|
35
|
-
|
|
36
|
-
const inverseFields = classFields
|
|
37
|
-
.filter((item: string) => item.indexOf('InverseRelation') === 0)
|
|
38
|
-
.map((item: string) => item.split(':').at(-1));
|
|
39
|
-
|
|
40
|
-
for (const key of inverseFields) {
|
|
41
|
-
const metadataKey = `InverseRelation:${key}`;
|
|
42
|
-
const metadata = Reflect.getMetadata(metadataKey, model);
|
|
43
|
-
|
|
44
|
-
if (metadata && metadata.promise) {
|
|
45
|
-
const resolvedMetadata = await metadata.promise;
|
|
46
|
-
if (!relIds[key]) {
|
|
47
|
-
relIds[key] = {
|
|
48
|
-
key: resolvedMetadata.key,
|
|
49
|
-
inversionModel: resolvedMetadata.inversionModel,
|
|
50
|
-
foreignKey: resolvedMetadata.foreignKey
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return relIds;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
static bindRelation(relatedModel: RWSModel<any>): { connect: { id: string } } {
|
|
60
|
-
return {
|
|
61
|
-
connect: {
|
|
62
|
-
id: relatedModel.id
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static hasRelation(model: RWSModel<any>, key: string): boolean {
|
|
68
|
-
// Check if the property exists and is an object with an id property
|
|
69
|
-
return !!model[key] && typeof model[key] === 'object' && model[key] !== null && 'id' in model[key];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
static checkRelEnabled(model: RWSModel<any>, key: string): boolean {
|
|
73
|
-
return Object.keys((model.constructor as any)._RELATIONS).includes(key) &&
|
|
74
|
-
(model.constructor as any)._RELATIONS[key] === true;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
1
|
+
import { RelOneMetaType, RelManyMetaType } from '../types/RelationTypes';
|
|
2
|
+
import { IRWSModel } from '../../types/IRWSModel';
|
|
3
|
+
import { RWSModel } from '../_model';
|
|
4
|
+
|
|
5
|
+
export class RelationUtils {
|
|
6
|
+
static async getRelationOneMeta(model: RWSModel<any>, classFields: string[]): Promise<RelOneMetaType<IRWSModel>> {
|
|
7
|
+
const relIds: RelOneMetaType<IRWSModel> = {};
|
|
8
|
+
const relationFields = classFields
|
|
9
|
+
.filter((item: string) => item.indexOf('Relation') === 0 && !item.includes('Inverse'))
|
|
10
|
+
.map((item: string) => item.split(':').at(-1));
|
|
11
|
+
|
|
12
|
+
for (const key of relationFields) {
|
|
13
|
+
const metadataKey = `Relation:${key}`;
|
|
14
|
+
const metadata = Reflect.getMetadata(metadataKey, model);
|
|
15
|
+
|
|
16
|
+
if (metadata && metadata.promise) {
|
|
17
|
+
const resolvedMetadata = await metadata.promise;
|
|
18
|
+
if (!relIds[key]) {
|
|
19
|
+
relIds[key] = {
|
|
20
|
+
key: resolvedMetadata.key,
|
|
21
|
+
required: resolvedMetadata.required,
|
|
22
|
+
model: resolvedMetadata.relatedTo,
|
|
23
|
+
hydrationField: resolvedMetadata.relationField,
|
|
24
|
+
foreignKey: resolvedMetadata.relatedToField
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return relIds;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static async getRelationManyMeta(model: RWSModel<any>, classFields: string[]): Promise<RelManyMetaType<IRWSModel>> {
|
|
34
|
+
const relIds: RelManyMetaType<IRWSModel> = {};
|
|
35
|
+
|
|
36
|
+
const inverseFields = classFields
|
|
37
|
+
.filter((item: string) => item.indexOf('InverseRelation') === 0)
|
|
38
|
+
.map((item: string) => item.split(':').at(-1));
|
|
39
|
+
|
|
40
|
+
for (const key of inverseFields) {
|
|
41
|
+
const metadataKey = `InverseRelation:${key}`;
|
|
42
|
+
const metadata = Reflect.getMetadata(metadataKey, model);
|
|
43
|
+
|
|
44
|
+
if (metadata && metadata.promise) {
|
|
45
|
+
const resolvedMetadata = await metadata.promise;
|
|
46
|
+
if (!relIds[key]) {
|
|
47
|
+
relIds[key] = {
|
|
48
|
+
key: resolvedMetadata.key,
|
|
49
|
+
inversionModel: resolvedMetadata.inversionModel,
|
|
50
|
+
foreignKey: resolvedMetadata.foreignKey
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return relIds;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static bindRelation(relatedModel: RWSModel<any>): { connect: { id: string } } {
|
|
60
|
+
return {
|
|
61
|
+
connect: {
|
|
62
|
+
id: relatedModel.id
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static hasRelation(model: RWSModel<any>, key: string): boolean {
|
|
68
|
+
// Check if the property exists and is an object with an id property
|
|
69
|
+
return !!model[key] && typeof model[key] === 'object' && model[key] !== null && 'id' in model[key];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static checkRelEnabled(model: RWSModel<any>, key: string): boolean {
|
|
73
|
+
return Object.keys((model.constructor as any)._RELATIONS).includes(key) &&
|
|
74
|
+
(model.constructor as any)._RELATIONS[key] === true;
|
|
75
|
+
}
|
|
76
|
+
}
|