@rws-framework/db 3.3.8 → 3.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.
@@ -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
+ // }
@@ -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 |number | 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 |number | 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,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,38 +1,38 @@
1
- import { RWSModel } from "../_model";
2
-
3
- export class TimeSeriesUtils {
4
- static getTimeSeriesModelFields(model: RWSModel<any>): {[key: string]: {collection: string, hydrationField: string, ids: string[]}} {
5
- const timeSeriesIds: {[key: string]: {collection: string, hydrationField: string, ids: string[]}} = {};
6
-
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
-
22
- return timeSeriesIds;
23
- }
24
-
25
- static checkTimeSeries(constructor: any): boolean {
26
- const data = constructor.prototype as any;
27
-
28
- for (const key in data) {
29
- if (data.hasOwnProperty(key)) {
30
- if(Reflect.getMetadata(`InverseTimeSeries:${key}`, constructor.prototype)){
31
- return true;
32
- }
33
- }
34
- }
35
-
36
- return false;
37
- }
38
- }
1
+ import { RWSModel } from "../_model";
2
+
3
+ export class TimeSeriesUtils {
4
+ static getTimeSeriesModelFields(model: RWSModel<any>): {[key: string]: {collection: string, hydrationField: string, ids: string[]}} {
5
+ const timeSeriesIds: {[key: string]: {collection: string, hydrationField: string, ids: string[]}} = {};
6
+
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
+
22
+ return timeSeriesIds;
23
+ }
24
+
25
+ static checkTimeSeries(constructor: any): boolean {
26
+ const data = constructor.prototype as any;
27
+
28
+ for (const key in data) {
29
+ if (data.hasOwnProperty(key)) {
30
+ if(Reflect.getMetadata(`InverseTimeSeries:${key}`, constructor.prototype)){
31
+ return true;
32
+ }
33
+ }
34
+ }
35
+
36
+ return false;
37
+ }
38
+ }
@@ -4,7 +4,9 @@ export interface IDbConfigParams {
4
4
  db_url?: string;
5
5
  db_name?: string;
6
6
  db_type?: 'mongodb' | 'mysql' | 'sqlite' | 'postgresql' | 'postgres';
7
- db_models?: OpModelType<any>[]
7
+ db_models?: OpModelType<any>[],
8
+ db_prisma_output?: string,
9
+ db_prisma_binary_targets?: string[]
8
10
  }
9
11
 
10
12
  export interface IdGeneratorOptions {
@@ -1,13 +1,13 @@
1
- export type FindByType = {
2
- conditions?: any
3
- ordering?: { [fieldName: string]: string }
4
- fields?: string[]
5
- allowRelations?: boolean
6
- fullData?: boolean
7
- pagination?: IPaginationParams
8
- }
9
-
10
- export interface IPaginationParams {
11
- page: number,
12
- per_page?: number
13
- }
1
+ export type FindByType = {
2
+ conditions?: any
3
+ ordering?: { [fieldName: string]: string }
4
+ fields?: string[]
5
+ allowRelations?: boolean
6
+ fullData?: boolean
7
+ pagination?: IPaginationParams
8
+ }
9
+
10
+ export interface IPaginationParams {
11
+ page: number,
12
+ per_page?: number
13
+ }
@@ -1,6 +1,6 @@
1
- export interface ITimeSeries {
2
- value: number,
3
- timestamp?: Date;
4
- params?: any;
5
- time_tracker_id?: string
1
+ export interface ITimeSeries {
2
+ value: number,
3
+ timestamp?: Date;
4
+ params?: any;
5
+ time_tracker_id?: string
6
6
  }