@rws-framework/db 2.4.5 → 3.0.0

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.
Files changed (123) hide show
  1. package/.bin/add-v.sh +9 -9
  2. package/.bin/emerge.sh +10 -10
  3. package/.eslintrc.json +53 -53
  4. package/README.md +404 -404
  5. package/dist/decorators/IdType.d.ts +8 -0
  6. package/dist/decorators/IdType.js +10 -0
  7. package/dist/decorators/InverseRelation.d.ts +2 -2
  8. package/dist/decorators/InverseRelation.js +5 -1
  9. package/dist/decorators/InverseTimeSeries.d.ts +0 -0
  10. package/dist/decorators/InverseTimeSeries.js +0 -0
  11. package/dist/decorators/RWSCollection.d.ts +7 -0
  12. package/dist/decorators/RWSCollection.js +6 -0
  13. package/dist/decorators/Relation.d.ts +8 -6
  14. package/dist/decorators/Relation.js +8 -1
  15. package/dist/decorators/TrackType.d.ts +2 -14
  16. package/dist/decorators/TrackType.js +7 -0
  17. package/dist/decorators/TypeFunctions.d.ts +44 -0
  18. package/dist/decorators/TypeFunctions.js +174 -0
  19. package/dist/decorators/index.d.ts +4 -2
  20. package/dist/decorators/index.js +3 -1
  21. package/dist/helper/DbHelper.d.ts +76 -5
  22. package/dist/helper/DbHelper.js +93 -154
  23. package/dist/helper/FieldsHelper.d.ts +0 -0
  24. package/dist/helper/FieldsHelper.js +0 -0
  25. package/dist/helper/db/index.d.ts +9 -0
  26. package/dist/helper/db/index.js +18 -0
  27. package/dist/helper/db/relation-manager.d.ts +45 -0
  28. package/dist/helper/db/relation-manager.js +105 -0
  29. package/dist/helper/db/schema-generator.d.ts +37 -0
  30. package/dist/helper/db/schema-generator.js +243 -0
  31. package/dist/helper/db/type-converter.d.ts +22 -0
  32. package/dist/helper/db/type-converter.js +106 -0
  33. package/dist/helper/db/utils.d.ts +24 -0
  34. package/dist/helper/db/utils.js +99 -0
  35. package/dist/index.d.ts +3 -3
  36. package/dist/index.js +2 -1
  37. package/dist/models/TimeSeriesModel.d.ts +7 -7
  38. package/dist/models/TimeSeriesModel.js +33 -33
  39. package/dist/models/_model.d.ts +2 -2
  40. package/dist/models/_model.js +0 -0
  41. package/dist/models/core/RWSModel.d.ts +4 -1
  42. package/dist/models/core/RWSModel.js +6 -4
  43. package/dist/models/core/TimeSeriesModel.d.ts +0 -0
  44. package/dist/models/core/TimeSeriesModel.js +0 -0
  45. package/dist/models/index.d.ts +2 -2
  46. package/dist/models/index.js +0 -0
  47. package/dist/models/interfaces/IDbOpts.d.ts +17 -0
  48. package/dist/models/interfaces/IDbOpts.js +2 -0
  49. package/dist/models/interfaces/IIdOpts.d.ts +0 -0
  50. package/dist/models/interfaces/IIdOpts.js +1 -0
  51. package/dist/models/interfaces/IIdTypeOpts.d.ts +3 -0
  52. package/dist/models/interfaces/IIdTypeOpts.js +2 -0
  53. package/dist/models/interfaces/IModel.d.ts +0 -0
  54. package/dist/models/interfaces/IModel.js +0 -0
  55. package/dist/models/interfaces/IRWSModelServices.d.ts +0 -0
  56. package/dist/models/interfaces/IRWSModelServices.js +0 -0
  57. package/dist/models/interfaces/ITrackerOpts.d.ts +12 -0
  58. package/dist/models/interfaces/ITrackerOpts.js +2 -0
  59. package/dist/models/interfaces/OpModelType.d.ts +3 -0
  60. package/dist/models/interfaces/OpModelType.js +0 -0
  61. package/dist/models/types/RelationTypes.d.ts +0 -0
  62. package/dist/models/types/RelationTypes.js +0 -0
  63. package/dist/models/utils/ModelUtils.d.ts +0 -0
  64. package/dist/models/utils/ModelUtils.js +0 -0
  65. package/dist/models/utils/PaginationUtils.d.ts +0 -0
  66. package/dist/models/utils/PaginationUtils.js +0 -0
  67. package/dist/models/utils/RelationUtils.d.ts +1 -1
  68. package/dist/models/utils/RelationUtils.js +2 -2
  69. package/dist/models/utils/TimeSeriesUtils.d.ts +0 -0
  70. package/dist/models/utils/TimeSeriesUtils.js +0 -0
  71. package/dist/services/DBService.d.ts +0 -0
  72. package/dist/services/DBService.js +0 -0
  73. package/dist/types/DbConfigHandler.d.ts +1 -1
  74. package/dist/types/DbConfigHandler.js +0 -0
  75. package/dist/types/FindParams.d.ts +0 -0
  76. package/dist/types/FindParams.js +0 -0
  77. package/dist/types/IRWSModel.d.ts +1 -1
  78. package/dist/types/IRWSModel.js +0 -0
  79. package/dist/types/ITimeSeries.d.ts +0 -0
  80. package/dist/types/ITimeSeries.js +0 -0
  81. package/exec/console.js +110 -110
  82. package/exec/db.rws.webpack.config.js +168 -168
  83. package/exec/src/cli.ts +73 -75
  84. package/exec/tsconfig.json +32 -32
  85. package/exec/webpackFilters.js +17 -17
  86. package/package.json +36 -36
  87. package/src/decorators/IdType.ts +17 -0
  88. package/src/decorators/InverseRelation.ts +41 -37
  89. package/src/decorators/InverseTimeSeries.ts +21 -21
  90. package/src/decorators/RWSCollection.ts +45 -27
  91. package/src/decorators/Relation.ts +61 -48
  92. package/src/decorators/TrackType.ts +65 -69
  93. package/src/decorators/index.ts +16 -8
  94. package/src/empty.js +0 -0
  95. package/src/helper/DbHelper.ts +133 -223
  96. package/src/helper/FieldsHelper.ts +34 -34
  97. package/src/helper/db/index.ts +10 -0
  98. package/src/helper/db/relation-manager.ts +119 -0
  99. package/src/helper/db/schema-generator.ts +302 -0
  100. package/src/helper/db/type-converter.ts +119 -0
  101. package/src/helper/db/utils.ts +120 -0
  102. package/src/index.ts +47 -38
  103. package/src/models/_model.ts +29 -29
  104. package/src/models/core/RWSModel.ts +523 -520
  105. package/src/models/core/TimeSeriesModel.ts +19 -19
  106. package/src/models/index.ts +20 -20
  107. package/src/models/interfaces/IDbOpts.ts +17 -0
  108. package/src/models/interfaces/IIdTypeOpts.ts +4 -0
  109. package/src/models/interfaces/IModel.ts +12 -12
  110. package/src/models/interfaces/IRWSModelServices.ts +7 -7
  111. package/src/models/interfaces/ITrackerOpts.ts +13 -0
  112. package/src/models/interfaces/OpModelType.ts +52 -49
  113. package/src/models/types/RelationTypes.ts +25 -25
  114. package/src/models/utils/ModelUtils.ts +65 -65
  115. package/src/models/utils/PaginationUtils.ts +42 -42
  116. package/src/models/utils/RelationUtils.ts +76 -76
  117. package/src/models/utils/TimeSeriesUtils.ts +38 -38
  118. package/src/services/DBService.ts +277 -277
  119. package/src/types/DbConfigHandler.ts +17 -17
  120. package/src/types/FindParams.ts +13 -13
  121. package/src/types/IRWSModel.ts +2 -2
  122. package/src/types/ITimeSeries.ts +5 -5
  123. 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
+ // }
@@ -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, ITrackerMetaOpts } from '../decorators';
8
+
9
+ export {
10
+ IModel,
11
+ IRWSModelServices,
12
+ OpModelType,
13
+ RelationBindType,
14
+ RelOneMetaType,
15
+ RelManyMetaType,
16
+ RWSModel,
17
+ // TimeSeriesModel,
18
+ TrackType,
19
+ ITrackerMetaOpts
20
+ };
@@ -0,0 +1,17 @@
1
+ export interface IDbOpts {
2
+ dbOptions?: {
3
+ mysql?: {
4
+ useType?: string;
5
+ useText?: boolean;
6
+ maxLength?: number;
7
+ useUuid?: boolean;
8
+ };
9
+ postgres?: {
10
+ useText?: boolean;
11
+ useUuid?: boolean;
12
+ };
13
+ mongodb?: {
14
+ customType?: string;
15
+ };
16
+ }
17
+ }
@@ -0,0 +1,4 @@
1
+ import { IDbOpts } from "./IDbOpts";
2
+
3
+ export interface IIdTypeOpts extends IDbOpts {
4
+ }
@@ -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
+ }
@@ -0,0 +1,13 @@
1
+ import { IDbOpts } from "./IDbOpts";
2
+ import { OpModelType } from "./OpModelType";
3
+
4
+ export interface ITrackerOpts extends IDbOpts {
5
+ required?: boolean,
6
+ unique?: boolean | string,
7
+ isArray?: boolean,
8
+ relationField?: string,
9
+ relatedToField?: string,
10
+ relatedTo?: OpModelType<any>,
11
+ inversionModel?: OpModelType<any>,
12
+ relationName?: string
13
+ }
@@ -1,49 +1,52 @@
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
+ import { ISuperTagData } from '../../decorators/RWSCollection';
10
+
11
+ export interface OpModelType<T> {
12
+ new(data?: any | null): T;
13
+ services: IRWSModelServices;
14
+ name: string;
15
+ _collection: string;
16
+ _NO_ID: boolean;
17
+ _SUPER_TAGS: ISuperTagData[];
18
+ _RELATIONS: {[key: string]: boolean};
19
+ _CUT_KEYS: string[];
20
+ allModels: OpModelType<any>[];
21
+ loadModels: () => OpModelType<any>[];
22
+ checkForInclusionWithThrow: (className: string) => void;
23
+ checkForInclusion: (className: string) => boolean;
24
+ findOneBy<T extends RWSModel<T>>(
25
+ this: OpModelType<T>,
26
+ findParams?: FindByType
27
+ ): Promise<T | null>;
28
+ find<T extends RWSModel<T>>(
29
+ this: OpModelType<T>,
30
+ id: string,
31
+ findParams?: Omit<FindByType, 'conditions'>
32
+ ): Promise<T | null>;
33
+ findBy<T extends RWSModel<T>>(
34
+ this: OpModelType<T>,
35
+ findParams?: FindByType
36
+ ): Promise<T[]>;
37
+ paginate<T extends RWSModel<T>>(
38
+ this: OpModelType<T>,
39
+ paginateParams?: IPaginationParams,
40
+ findParams?: FindByType
41
+ ): Promise<T[]>;
42
+ delete<T extends RWSModel<T>>(
43
+ this: OpModelType<T>,
44
+ conditions: any
45
+ ): Promise<void>;
46
+ create<T extends RWSModel<T>>(this: new () => T, data: any): Promise<T>;
47
+ getRelationOneMeta(model: any, classFields: string[]): Promise<RelOneMetaType<IRWSModel>>;
48
+ getRelationManyMeta(model: any, classFields: string[]): Promise<RelManyMetaType<IRWSModel>>;
49
+ getCollection(): string;
50
+ getDb(): DBService;
51
+ setServices(services: IRWSModelServices): void;
52
+ }
@@ -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
+ }