@rws-framework/db 2.1.10 → 2.1.11

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 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 { RWSannotations, RWSModel } from '@rws-framework/server';
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
- @RWSTrackType(String)
32
+ @TrackType(String)
29
33
  username: string;
30
34
 
31
- @RWSTrackType(String) // Can also handle Object and Number
35
+ @TrackType(String) // Can also handle Object and Number
32
36
  passwd: string;
33
37
 
34
- @RWSTrackType(Boolean)
38
+ @TrackType(Boolean)
35
39
  active: boolean;
36
40
 
37
- @RWSTrackType(Date, { required: true })
41
+ @TrackType(Date, { required: true })
38
42
  created_at: Date;
39
43
 
40
- @RWSTrackType(Date)
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
 
@@ -73,7 +73,7 @@ declare class RWSModel<ChildClass> implements IModel {
73
73
  static checkForInclusionWithThrow(this: OpModelType<any>, checkModelType: string): void;
74
74
  checkForInclusion(): boolean;
75
75
  static checkForInclusion(this: OpModelType<any>, checkModelType: string): boolean;
76
- protected _fill(data: any): RWSModel<ChildClass>;
76
+ _fill(data: any): RWSModel<ChildClass>;
77
77
  protected hasRelation(key: string): boolean;
78
78
  protected bindRelation(key: string, relatedModel: RWSModel<any>): RelationBindType;
79
79
  _asyncFill(data: any, fullDataMode?: boolean, allowRelations?: boolean): Promise<ChildClass>;
@@ -119,7 +119,6 @@ class RWSModel {
119
119
  });
120
120
  const seriesHydrationfields = [];
121
121
  if (allowRelations) {
122
- // Handle many-to-many relations
123
122
  for (const key in relManyData) {
124
123
  if (!fullDataMode && this.constructor._CUT_KEYS.includes(key)) {
125
124
  continue;
@@ -135,7 +134,6 @@ class RWSModel {
135
134
  });
136
135
  }
137
136
  }
138
- // Handle one-to-one relations
139
137
  for (const key in relOneData) {
140
138
  if (!fullDataMode && this.constructor._CUT_KEYS.includes(key)) {
141
139
  continue;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/db",
3
3
  "private": false,
4
- "version": "2.1.10",
4
+ "version": "2.1.11",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -59,7 +59,7 @@ export interface OpModelType<ChildClass> {
59
59
  getRelationOneMeta(model: any, classFields: string[]): Promise<RelOneMetaType<IRWSModel>>;
60
60
  getRelationManyMeta(model: any, classFields: string[]): Promise<RelManyMetaType<IRWSModel>>;
61
61
  getCollection(): string;
62
- setServices(services: IRWSModelServices): void;
62
+ setServices(services: IRWSModelServices): void;
63
63
  }
64
64
 
65
65
  class RWSModel<ChildClass> implements IModel{
@@ -118,7 +118,7 @@ class RWSModel<ChildClass> implements IModel{
118
118
  }) !== undefined;
119
119
  }
120
120
 
121
- protected _fill(data: any): RWSModel<ChildClass>{
121
+ _fill(data: any): RWSModel<ChildClass>{
122
122
  for (const key in data) {
123
123
  if (data.hasOwnProperty(key)) {
124
124
 
@@ -170,7 +170,6 @@ class RWSModel<ChildClass> implements IModel{
170
170
  const seriesHydrationfields: string[] = [];
171
171
 
172
172
  if (allowRelations) {
173
- // Handle many-to-many relations
174
173
  for (const key in relManyData) {
175
174
  if(!fullDataMode && (this as any).constructor._CUT_KEYS.includes(key)){
176
175
  continue;
@@ -188,8 +187,7 @@ class RWSModel<ChildClass> implements IModel{
188
187
  });
189
188
  }
190
189
  }
191
-
192
- // Handle one-to-one relations
190
+
193
191
  for (const key in relOneData) {
194
192
  if(!fullDataMode && (this as any).constructor._CUT_KEYS.includes(key)){
195
193
  continue;