@rws-framework/db 2.2.0 → 2.2.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/README.md +17 -26
- 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 +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 +0 -0
- package/dist/models/_model.js +0 -0
- package/dist/services/DBService.d.ts +0 -0
- package/dist/services/DBService.js +0 -0
- package/dist/types/DbConfigHandler.d.ts +0 -0
- 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/package.json +1 -1
- package/dist/models/utils/RelationUtils copy.d.ts +0 -13
- package/dist/models/utils/RelationUtils copy.js +0 -65
package/README.md
CHANGED
|
@@ -10,34 +10,38 @@ import User from "./User";
|
|
|
10
10
|
|
|
11
11
|
export const models = [ User, ApiKey];
|
|
12
12
|
```
|
|
13
|
-
|
|
14
|
-
|
|
15
13
|
## Example user model
|
|
16
14
|
|
|
17
15
|
```typescript
|
|
18
|
-
import {
|
|
16
|
+
import { TrackType, InverseRelation, RWSCollection, RWSModel } from '@rws-framework/db';
|
|
19
17
|
|
|
20
|
-
import IUser from './interfaces/IUser';
|
|
21
|
-
import 'reflect-metadata';
|
|
18
|
+
import IUser from './interfaces/IUser';
|
|
19
|
+
import 'reflect-metadata';
|
|
22
20
|
|
|
23
|
-
import ApiKey from './ApiKey';
|
|
24
|
-
import IApiKey from './interfaces/IApiKey';
|
|
25
|
-
const { RWSTrackType, InverseRelation } = RWSannotations.modelAnnotations;
|
|
21
|
+
import ApiKey from './ApiKey';
|
|
22
|
+
import IApiKey from './interfaces/IApiKey';
|
|
26
23
|
|
|
24
|
+
@RWSCollection('users', {
|
|
25
|
+
relations: {
|
|
26
|
+
transcriptions: true,
|
|
27
|
+
apiKeys: true
|
|
28
|
+
},
|
|
29
|
+
ignored_keys: ['passwd']
|
|
30
|
+
})
|
|
27
31
|
class User extends RWSModel<User> implements IUser {
|
|
28
|
-
@
|
|
32
|
+
@TrackType(String)
|
|
29
33
|
username: string;
|
|
30
34
|
|
|
31
|
-
@
|
|
35
|
+
@TrackType(String) // Can also handle Object and Number
|
|
32
36
|
passwd: string;
|
|
33
37
|
|
|
34
|
-
@
|
|
38
|
+
@TrackType(Boolean)
|
|
35
39
|
active: boolean;
|
|
36
40
|
|
|
37
|
-
@
|
|
41
|
+
@TrackType(Date, { required: true })
|
|
38
42
|
created_at: Date;
|
|
39
43
|
|
|
40
|
-
@
|
|
44
|
+
@TrackType(Date)
|
|
41
45
|
updated_at: Date;
|
|
42
46
|
|
|
43
47
|
/**
|
|
@@ -47,25 +51,12 @@ class User extends RWSModel<User> implements IUser {
|
|
|
47
51
|
@InverseRelation(() => ApiKey, () => User)
|
|
48
52
|
apiKeys: IApiKey[];
|
|
49
53
|
|
|
50
|
-
static _collection = 'user';
|
|
51
|
-
|
|
52
|
-
static _RELATIONS = {
|
|
53
|
-
transcriptions: true,
|
|
54
|
-
apiKeys: true
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
static _CUT_KEYS = ['passwd'];
|
|
58
|
-
|
|
59
54
|
constructor(data?: IUser) {
|
|
60
55
|
super(data);
|
|
61
56
|
|
|
62
57
|
if(!this.created_at){
|
|
63
58
|
this.created_at = new Date();
|
|
64
59
|
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
addMessage(message: string){
|
|
68
|
-
this.messages.push(message);
|
|
69
60
|
}
|
|
70
61
|
}
|
|
71
62
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/decorators/index.js
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/helper/DbHelper.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
File without changes
|
package/dist/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/models/_model.d.ts
CHANGED
|
File without changes
|
package/dist/models/_model.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
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,13 +0,0 @@
|
|
|
1
|
-
import { RelOneMetaType, RelManyMetaType } from '../types/RelationTypes';
|
|
2
|
-
import { IRWSModel } from '../../types/IRWSModel';
|
|
3
|
-
export declare class RelationUtils {
|
|
4
|
-
static getRelationOneMeta(model: any, classFields: string[]): Promise<RelOneMetaType<IRWSModel>>;
|
|
5
|
-
static getRelationManyMeta(model: any, classFields: string[]): Promise<RelManyMetaType<IRWSModel>>;
|
|
6
|
-
static bindRelation(relatedModel: any): {
|
|
7
|
-
connect: {
|
|
8
|
-
id: string;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
static hasRelation(model: any, key: string): boolean;
|
|
12
|
-
static checkRelEnabled(model: any, key: string): boolean;
|
|
13
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
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;
|