@goatlab/fluent 0.6.7 → 0.6.10

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 (179) hide show
  1. package/dist/BaseConnector.d.ts +79 -0
  2. package/dist/BaseConnector.js +361 -0
  3. package/dist/Fluent.d.ts +26 -0
  4. package/dist/Fluent.js +52 -0
  5. package/dist/TypeOrmConnector/TypeOrmMongoConnector._bypass.js +52 -0
  6. package/dist/TypeOrmConnector/TypeOrmMysqlConnector._bypass.js +55 -0
  7. package/dist/TypeOrmConnector/test/advanced/advancedTestSuite.d.ts +1 -0
  8. package/dist/TypeOrmConnector/test/advanced/advancedTestSuite.js +114 -0
  9. package/dist/TypeOrmConnector/test/advanced/typeOrm.entity.d.ts +16 -0
  10. package/dist/TypeOrmConnector/test/advanced/typeOrm.entity.js +57 -0
  11. package/dist/TypeOrmConnector/test/advanced/typeOrm.repository.js +11 -0
  12. package/dist/TypeOrmConnector/test/basic/basicTestSuite.d.ts +1 -0
  13. package/dist/TypeOrmConnector/test/basic/basicTestSuite.js +45 -0
  14. package/dist/TypeOrmConnector/test/basic/goat.dto.d.ts +8 -0
  15. package/dist/TypeOrmConnector/test/basic/goat.dto.js +18 -0
  16. package/dist/TypeOrmConnector/test/basic/goat.entity.d.ts +10 -0
  17. package/dist/TypeOrmConnector/test/basic/goat.entity.js +42 -0
  18. package/dist/TypeOrmConnector/test/basic/goat.repository.js +11 -0
  19. package/dist/TypeOrmConnector/test/flock.d.ts +4 -0
  20. package/dist/TypeOrmConnector/test/flock.js +25 -0
  21. package/dist/TypeOrmConnector/test/relations/car/car.dto.d.ts +5 -0
  22. package/dist/TypeOrmConnector/test/relations/car/car.dto.js +12 -0
  23. package/dist/TypeOrmConnector/test/relations/car/car.entity.d.ts +7 -0
  24. package/dist/TypeOrmConnector/test/relations/car/car.entity.js +32 -0
  25. package/dist/TypeOrmConnector/test/relations/car/car.repositoryTypeOrm.js +13 -0
  26. package/dist/TypeOrmConnector/test/relations/relationsTestsSuite.d.ts +1 -0
  27. package/dist/TypeOrmConnector/test/relations/relationsTestsSuite.js +93 -0
  28. package/dist/TypeOrmConnector/test/relations/roles/role.dto.d.ts +5 -0
  29. package/dist/TypeOrmConnector/test/relations/roles/role.dto.js +12 -0
  30. package/dist/TypeOrmConnector/test/relations/roles/roles.entity.d.ts +6 -0
  31. package/dist/TypeOrmConnector/test/relations/roles/roles.entity.js +29 -0
  32. package/dist/TypeOrmConnector/test/relations/roles/roles.repositoryTypeOrm.js +14 -0
  33. package/dist/TypeOrmConnector/test/relations/roles/roles_user.dto.d.ts +5 -0
  34. package/dist/TypeOrmConnector/test/relations/roles/roles_user.dto.js +12 -0
  35. package/dist/TypeOrmConnector/test/relations/roles/roles_user.entity.d.ts +5 -0
  36. package/dist/TypeOrmConnector/test/relations/roles/roles_user.entity.js +23 -0
  37. package/dist/TypeOrmConnector/test/relations/roles/roles_users.repositoryTypeOrm.js +11 -0
  38. package/dist/TypeOrmConnector/test/relations/user/user.dto.d.ts +5 -0
  39. package/dist/TypeOrmConnector/test/relations/user/user.dto.js +12 -0
  40. package/dist/TypeOrmConnector/test/relations/user/user.entity.d.ts +14 -0
  41. package/dist/TypeOrmConnector/test/relations/user/user.entity.js +56 -0
  42. package/dist/TypeOrmConnector/test/relations/user/user.repositoryTypeOrm.js +16 -0
  43. package/dist/core/Loopback/build-schema.d.ts +31 -0
  44. package/dist/core/Loopback/build-schema.js +335 -0
  45. package/dist/core/Loopback/common-types.d.ts +36 -0
  46. package/dist/core/Loopback/common-types.js +13 -0
  47. package/dist/core/Loopback/json-to-schema.d.ts +6 -0
  48. package/dist/core/Loopback/json-to-schema.js +96 -0
  49. package/dist/core/Loopback/metadata.d.ts +9 -0
  50. package/dist/core/Loopback/metadata.js +28 -0
  51. package/dist/core/Loopback/model.d.ts +87 -0
  52. package/dist/core/Loopback/model.js +244 -0
  53. package/dist/core/Loopback/query.d.ts +97 -0
  54. package/dist/core/Loopback/query.js +290 -0
  55. package/dist/core/Loopback/relation.types.d.ts +45 -0
  56. package/dist/core/Loopback/relation.types.js +13 -0
  57. package/dist/core/Loopback/type-resolver.d.ts +7 -0
  58. package/dist/core/Loopback/type-resolver.js +34 -0
  59. package/dist/core/Loopback/type.d.ts +9 -0
  60. package/dist/core/Loopback/type.js +2 -0
  61. package/dist/core/Nestjs/applyDecorators.d.ts +1 -0
  62. package/dist/core/Nestjs/applyDecorators.js +17 -0
  63. package/dist/core/Nestjs/types/common.d.ts +16 -0
  64. package/dist/core/Nestjs/types/common.js +35 -0
  65. package/dist/core/Nestjs/types/decorators/api-hide-property.decorator.d.ts +1 -0
  66. package/dist/core/Nestjs/types/decorators/api-hide-property.decorator.js +7 -0
  67. package/dist/core/Nestjs/types/decorators/api-property.decorator.d.ts +27 -0
  68. package/dist/core/Nestjs/types/decorators/api-property.decorator.js +65 -0
  69. package/dist/core/Nestjs/types/decorators/apply-is-optional.decorator.d.ts +5 -0
  70. package/dist/core/Nestjs/types/decorators/apply-is-optional.decorator.js +131 -0
  71. package/dist/core/Nestjs/types/decorators/args-type.decorator.d.ts +1 -0
  72. package/dist/core/Nestjs/types/decorators/args-type.decorator.js +19 -0
  73. package/dist/core/Nestjs/types/decorators/create-property.decorator.d.ts +2 -0
  74. package/dist/core/Nestjs/types/decorators/create-property.decorator.js +50 -0
  75. package/dist/core/Nestjs/types/decorators/directive.decorator.d.ts +1 -0
  76. package/dist/core/Nestjs/types/decorators/directive.decorator.js +36 -0
  77. package/dist/core/Nestjs/types/decorators/extensions.decorator.d.ts +1 -0
  78. package/dist/core/Nestjs/types/decorators/extensions.decorator.js +25 -0
  79. package/dist/core/Nestjs/types/decorators/field.decorator.d.ts +15 -0
  80. package/dist/core/Nestjs/types/decorators/field.decorator.js +56 -0
  81. package/dist/core/Nestjs/types/decorators/input-type.decorator.d.ts +7 -0
  82. package/dist/core/Nestjs/types/decorators/input-type.decorator.js +23 -0
  83. package/dist/core/Nestjs/types/decorators/interface-type.decorator.d.ts +9 -0
  84. package/dist/core/Nestjs/types/decorators/interface-type.decorator.js +27 -0
  85. package/dist/core/Nestjs/types/decorators/partial-type.helper.d.ts +3 -0
  86. package/dist/core/Nestjs/types/decorators/partial-type.helper.js +42 -0
  87. package/dist/core/Nestjs/types/errors/cannot-determine-host-type.error.d.ts +3 -0
  88. package/dist/core/Nestjs/types/errors/cannot-determine-host-type.error.js +9 -0
  89. package/dist/core/Nestjs/types/errors/directive-parsing.error.d.ts +3 -0
  90. package/dist/core/Nestjs/types/errors/directive-parsing.error.js +9 -0
  91. package/dist/core/Nestjs/types/errors/unable-to-find-fields.error.d.ts +3 -0
  92. package/dist/core/Nestjs/types/errors/unable-to-find-fields.error.js +9 -0
  93. package/dist/core/Nestjs/types/errors/undefined-type.error.d.ts +3 -0
  94. package/dist/core/Nestjs/types/errors/undefined-type.error.js +10 -0
  95. package/dist/core/Nestjs/types/interfaces/add-class-type-metadata.util.d.ts +3 -0
  96. package/dist/core/Nestjs/types/interfaces/add-class-type-metadata.util.js +10 -0
  97. package/dist/core/Nestjs/types/interfaces/base-type-options.interface.d.ts +5 -0
  98. package/dist/core/Nestjs/types/interfaces/base-type-options.interface.js +2 -0
  99. package/dist/core/Nestjs/types/interfaces/class-decorator-factory.interface.d.ts +5 -0
  100. package/dist/core/Nestjs/types/interfaces/class-decorator-factory.interface.js +2 -0
  101. package/dist/core/Nestjs/types/interfaces/complexity.interface.d.ts +11 -0
  102. package/dist/core/Nestjs/types/interfaces/complexity.interface.js +2 -0
  103. package/dist/core/Nestjs/types/interfaces/field-middleware.interface.d.ts +15 -0
  104. package/dist/core/Nestjs/types/interfaces/field-middleware.interface.js +2 -0
  105. package/dist/core/Nestjs/types/interfaces/open-api-spec.interface.d.ts +235 -0
  106. package/dist/core/Nestjs/types/interfaces/open-api-spec.interface.js +2 -0
  107. package/dist/core/Nestjs/types/interfaces/resolve-type-fn.interface.d.ts +2 -0
  108. package/dist/core/Nestjs/types/interfaces/resolve-type-fn.interface.js +2 -0
  109. package/dist/core/Nestjs/types/interfaces/return-type-func.interface.d.ts +5 -0
  110. package/dist/core/Nestjs/types/interfaces/return-type-func.interface.js +2 -0
  111. package/dist/core/Nestjs/types/interfaces/schema-object-metadata.interface.d.ts +9 -0
  112. package/dist/core/Nestjs/types/interfaces/schema-object-metadata.interface.js +2 -0
  113. package/dist/core/Nestjs/types/interfaces/type-options.interface.d.ts +5 -0
  114. package/dist/core/Nestjs/types/interfaces/type-options.interface.js +2 -0
  115. package/dist/core/Nestjs/types/lazy-metadata.storage.d.ts +15 -0
  116. package/dist/core/Nestjs/types/lazy-metadata.storage.js +67 -0
  117. package/dist/core/Nestjs/types/metadata/class.metadata.d.ts +11 -0
  118. package/dist/core/Nestjs/types/metadata/class.metadata.js +2 -0
  119. package/dist/core/Nestjs/types/metadata/directive.metadata.d.ts +8 -0
  120. package/dist/core/Nestjs/types/metadata/directive.metadata.js +2 -0
  121. package/dist/core/Nestjs/types/metadata/enum.metadata.d.ts +11 -0
  122. package/dist/core/Nestjs/types/metadata/enum.metadata.js +2 -0
  123. package/dist/core/Nestjs/types/metadata/extensions.metadata.d.ts +8 -0
  124. package/dist/core/Nestjs/types/metadata/extensions.metadata.js +2 -0
  125. package/dist/core/Nestjs/types/metadata/index.d.ts +8 -0
  126. package/dist/core/Nestjs/types/metadata/index.js +11 -0
  127. package/dist/core/Nestjs/types/metadata/interface.metadata.d.ts +6 -0
  128. package/dist/core/Nestjs/types/metadata/interface.metadata.js +2 -0
  129. package/dist/core/Nestjs/types/metadata/object-type.metadata.d.ts +4 -0
  130. package/dist/core/Nestjs/types/metadata/object-type.metadata.js +2 -0
  131. package/dist/core/Nestjs/types/metadata/param.metadata.d.ts +18 -0
  132. package/dist/core/Nestjs/types/metadata/param.metadata.js +2 -0
  133. package/dist/core/Nestjs/types/metadata/property.metadata.d.ts +20 -0
  134. package/dist/core/Nestjs/types/metadata/property.metadata.js +2 -0
  135. package/dist/core/Nestjs/types/metadata/resolver.metadata.d.ts +34 -0
  136. package/dist/core/Nestjs/types/metadata/resolver.metadata.js +2 -0
  137. package/dist/core/Nestjs/types/metadata/union.metadata.d.ts +9 -0
  138. package/dist/core/Nestjs/types/metadata/union.metadata.js +2 -0
  139. package/dist/core/Nestjs/types/object-type.decorator.d.ts +8 -0
  140. package/dist/core/Nestjs/types/object-type.decorator.js +25 -0
  141. package/dist/core/Nestjs/types/omit-type.d.ts +2 -0
  142. package/dist/core/Nestjs/types/omit-type.js +30 -0
  143. package/dist/core/Nestjs/types/reflection.utils.d.ts +15 -0
  144. package/dist/core/Nestjs/types/reflection.utils.js +58 -0
  145. package/dist/core/Nestjs/types/set-metadata.decorator.d.ts +4 -0
  146. package/dist/core/Nestjs/types/set-metadata.decorator.js +16 -0
  147. package/dist/core/Nestjs/types/type-metadata.storage.d.ts +69 -0
  148. package/dist/core/Nestjs/types/type-metadata.storage.js +342 -0
  149. package/dist/core/Nestjs/types/utils/enum.utils.d.ts +3 -0
  150. package/dist/core/Nestjs/types/utils/enum.utils.js +29 -0
  151. package/dist/core/Nestjs/types/utils/get-fields-and-decorator.util.d.ts +13 -0
  152. package/dist/core/Nestjs/types/utils/get-fields-and-decorator.util.js +72 -0
  153. package/dist/core/Nestjs/types/utils/mapped-types.utils.d.ts +2 -0
  154. package/dist/core/Nestjs/types/utils/mapped-types.utils.js +38 -0
  155. package/dist/core/Nestjs/types/utils/model-properties-accessor.d.ts +6 -0
  156. package/dist/core/Nestjs/types/utils/model-properties-accessor.js +36 -0
  157. package/dist/core/Nestjs/types/utils/type-helpers.utils.d.ts +2 -0
  158. package/dist/core/Nestjs/types/utils/type-helpers.utils.js +16 -0
  159. package/dist/core/database/createConnection.d.ts +30 -0
  160. package/dist/core/database/createConnection.js +43 -0
  161. package/dist/core/database/decorators.d.ts +43 -0
  162. package/dist/core/database/decorators.js +98 -0
  163. package/dist/core/dtos/access.dto.d.ts +4 -0
  164. package/dist/core/dtos/access.dto.js +21 -0
  165. package/dist/core/dtos/pagination.dto.d.ts +13 -0
  166. package/dist/core/dtos/pagination.dto.js +62 -0
  167. package/dist/core/types.d.ts +23 -0
  168. package/dist/core/types.js +29 -0
  169. package/dist/generatorDatasource.d.ts +2 -0
  170. package/dist/generatorDatasource.js +12 -0
  171. package/dist/index.d.ts +10 -9
  172. package/dist/index.js +36 -0
  173. package/dist/loadRelations.js +92 -0
  174. package/dist/outputKeys.d.ts +2 -0
  175. package/dist/outputKeys.js +17 -0
  176. package/dist/tsconfig.tsbuildinfo +1 -0
  177. package/dist/types.d.ts +85 -0
  178. package/dist/types.js +2 -0
  179. package/package.json +1 -1
@@ -0,0 +1,79 @@
1
+ import { TypedPathWrapper } from 'typed-path';
2
+ import { Filter, DaoOutput, BaseDaoExtendedAttributes, LogicOperator, Primitives, PrimitivesArray } from './types';
3
+ import { Collection } from '@goatlab/js-utils';
4
+ export interface FluentConnectorInterface<InputDTO, OutputDTO> {
5
+ get(): Promise<DaoOutput<InputDTO, OutputDTO>[]>;
6
+ all(filter: Filter): Promise<DaoOutput<InputDTO, OutputDTO>[]>;
7
+ findById(id: string): Promise<DaoOutput<InputDTO, OutputDTO>>;
8
+ find(filter: Filter): Promise<DaoOutput<InputDTO, OutputDTO>[]>;
9
+ deleteById(id: string): Promise<string>;
10
+ updateById(id: string, data: InputDTO): Promise<DaoOutput<InputDTO, OutputDTO>>;
11
+ insert(data: InputDTO): Promise<DaoOutput<InputDTO, OutputDTO>>;
12
+ insertMany(data: InputDTO[]): Promise<DaoOutput<InputDTO, OutputDTO>[]>;
13
+ }
14
+ export declare abstract class BaseConnector<ModelDTO, InputDTO, OutputDTO> {
15
+ _keys: TypedPathWrapper<ModelDTO & InputDTO & OutputDTO, Record<never, never> & {
16
+ $path: (path: import("typed-path").TypedPathKey[]) => string;
17
+ $raw: (path: import("typed-path").TypedPathKey[]) => string[];
18
+ $rawPath: (path: import("typed-path").TypedPathKey[]) => import("typed-path").TypedPathKey[];
19
+ toString: (path: import("typed-path").TypedPathKey[]) => () => string;
20
+ valueOf: (path: import("typed-path").TypedPathKey[]) => () => string;
21
+ [Symbol.toStringTag]: (path: import("typed-path").TypedPathKey[]) => string;
22
+ }>;
23
+ protected outputKeys: string[];
24
+ protected chainReference: any[];
25
+ protected whereArray: any[];
26
+ protected orWhereArray: any[];
27
+ protected selectArray: any[];
28
+ protected forceSelectArray: any[];
29
+ protected orderByArray: any[];
30
+ protected limitNumber: number;
31
+ protected offsetNumber: number;
32
+ protected populateArray: any[];
33
+ protected chunk: any;
34
+ protected pullSize: any;
35
+ protected ownerId: any;
36
+ protected paginator: any;
37
+ protected rawQuery: any;
38
+ protected getFirst: boolean;
39
+ protected relations: any;
40
+ protected loadModels: boolean;
41
+ protected relationQuery: any;
42
+ protected modelRelations: any;
43
+ isMongoDB: boolean;
44
+ protected getExtendedCreateAttributes: () => BaseDaoExtendedAttributes;
45
+ constructor();
46
+ get(): Promise<DaoOutput<InputDTO, OutputDTO>[]>;
47
+ insertMany(data: InputDTO[]): Promise<DaoOutput<InputDTO, OutputDTO>[]>;
48
+ owner(user: string): this;
49
+ own(user: string): this;
50
+ first(): Promise<DaoOutput<InputDTO, OutputDTO> | null>;
51
+ collect(): Promise<Collection<DaoOutput<InputDTO, OutputDTO>>>;
52
+ select(...columns: TypedPathWrapper<Primitives, Primitives>[]): this;
53
+ forceSelect(...columns: TypedPathWrapper<Primitives, Primitives>[]): this;
54
+ offset(offset: number): this;
55
+ populate(...relations: any[]): this;
56
+ skip(offset: number): this;
57
+ where(path: TypedPathWrapper<Primitives, Primitives>, operator: LogicOperator, value: Primitives | PrimitivesArray): this;
58
+ andWhere(path: TypedPathWrapper<Primitives, Primitives>, operator: LogicOperator, value: Primitives | Primitives[]): this;
59
+ orWhere(path: TypedPathWrapper<Primitives, Primitives>, operator: LogicOperator, value: Primitives): this;
60
+ limit(limit: number): this;
61
+ take(limit: number): this;
62
+ pluck(path: TypedPathWrapper<Primitives, Primitives>): Promise<string[]>;
63
+ orderBy(path: TypedPathWrapper<Primitives, Primitives>, order?: 'asc' | 'desc', orderType?: 'string' | 'number' | 'date'): this;
64
+ protected jsApplySelect(data: any): any[];
65
+ protected jsApplyOrderBy(data: any): any[];
66
+ protected reset(): void;
67
+ load(): Promise<this>;
68
+ loadFirst(): Promise<this>;
69
+ getLoadedData(): DaoOutput<InputDTO, OutputDTO>[] | DaoOutput<InputDTO, OutputDTO>;
70
+ with(entities: any): this;
71
+ attach(data: InputDTO): Promise<DaoOutput<InputDTO, OutputDTO>[]>;
72
+ associate(id: string): any;
73
+ protected hasMany<T>(Repository: any, relationName: string): T;
74
+ protected hasOne(): void;
75
+ protected belongsTo<T>(Repository: any, relationName: string): T;
76
+ protected belongsToMany<T, R>(Repository: any, Pivot: any, relationName: string): T;
77
+ protected hasManyThrough(): void;
78
+ private prepareInput;
79
+ }
@@ -0,0 +1,361 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseConnector = void 0;
4
+ const typed_path_1 = require("typed-path");
5
+ const dates_1 = require("@goatlab/dates");
6
+ const js_utils_1 = require("@goatlab/js-utils");
7
+ class BaseConnector {
8
+ constructor() {
9
+ this._keys = (0, typed_path_1.typedPath)();
10
+ this.chainReference = [];
11
+ this.whereArray = [];
12
+ this.orWhereArray = [];
13
+ this.selectArray = [];
14
+ this.forceSelectArray = [];
15
+ this.orderByArray = [];
16
+ this.limitNumber = 0;
17
+ this.offsetNumber = 0;
18
+ this.populateArray = [];
19
+ this.chunk = null;
20
+ this.pullSize = null;
21
+ this.ownerId = undefined;
22
+ this.paginator = undefined;
23
+ this.rawQuery = undefined;
24
+ this.getFirst = false;
25
+ this.relations = undefined;
26
+ this.loadModels = false;
27
+ this.getExtendedCreateAttributes = () => {
28
+ const date = dates_1.Dates.currentIsoString();
29
+ return {
30
+ id: `${js_utils_1.Ids.objectIdString()}_local`,
31
+ updated: date,
32
+ created: date,
33
+ roles: []
34
+ };
35
+ };
36
+ this.chainReference = [];
37
+ this.whereArray = [];
38
+ this.orWhereArray = [];
39
+ this.selectArray = [];
40
+ this.forceSelectArray = [];
41
+ this.orderByArray = [];
42
+ this.limitNumber = undefined;
43
+ this.offsetNumber = undefined;
44
+ this.populateArray = [];
45
+ this.chunk = null;
46
+ this.pullSize = null;
47
+ this.ownerId = undefined;
48
+ this.paginator = undefined;
49
+ this.rawQuery = undefined;
50
+ this.outputKeys = [];
51
+ this.getFirst = false;
52
+ }
53
+ async get() {
54
+ throw new Error('get() method not implemented');
55
+ }
56
+ async insertMany(data) {
57
+ throw new Error('get() method not implemented');
58
+ }
59
+ owner(user) {
60
+ this.chainReference.push({ method: 'owner', args: user });
61
+ this.ownerId = user;
62
+ return this;
63
+ }
64
+ own(user) {
65
+ return this.owner(user);
66
+ }
67
+ async first() {
68
+ this.limit(1);
69
+ const data = await this.get();
70
+ if (!data[0]) {
71
+ return null;
72
+ }
73
+ return data[0];
74
+ }
75
+ async collect() {
76
+ const data = await this.get();
77
+ if (!Array.isArray(data)) {
78
+ throw new Error('Collect method only accepts arrays of data');
79
+ }
80
+ return new js_utils_1.Collection(data);
81
+ }
82
+ select(...columns) {
83
+ columns = this.prepareInput(columns);
84
+ this.chainReference.push({ method: 'select', args: columns });
85
+ this.selectArray = this.selectArray
86
+ .concat(columns)
87
+ .filter((elem, pos, arr) => arr.indexOf(elem) === pos);
88
+ return this;
89
+ }
90
+ forceSelect(...columns) {
91
+ if (typeof module === 'undefined' || !module.exports) {
92
+ throw new Error('forceSelect cant be used in frontend');
93
+ }
94
+ columns = this.prepareInput(columns);
95
+ this.chainReference.push({ method: 'forceSelect', args: columns });
96
+ this.forceSelectArray = this.forceSelectArray
97
+ .concat(columns)
98
+ .filter((elem, pos, arr) => arr.indexOf(elem) === pos);
99
+ return this;
100
+ }
101
+ offset(offset) {
102
+ this.chainReference.push({ method: 'offset', args: offset });
103
+ this.offsetNumber = offset;
104
+ return this;
105
+ }
106
+ populate(...relations) {
107
+ this.chainReference.push({ method: 'relations', args: relations });
108
+ this.populateArray = relations;
109
+ return this;
110
+ }
111
+ skip(offset) {
112
+ return this.offset(offset);
113
+ }
114
+ where(path, operator, value) {
115
+ const stringPath = path.toString();
116
+ const chainedWhere = [stringPath, operator, value];
117
+ this.chainReference.push({ method: 'where', chainedWhere });
118
+ this.whereArray = [];
119
+ this.whereArray.push(chainedWhere);
120
+ return this;
121
+ }
122
+ andWhere(path, operator, value) {
123
+ const stringPath = path.toString();
124
+ const chainedWhere = [stringPath, operator, value];
125
+ this.chainReference.push({ method: 'andWhere', chainedWhere });
126
+ this.whereArray.push(chainedWhere);
127
+ return this;
128
+ }
129
+ orWhere(path, operator, value) {
130
+ const stringPath = path.toString();
131
+ const chainedWhere = [stringPath, operator, value];
132
+ this.chainReference.push({ method: 'orWhere', chainedWhere });
133
+ this.orWhereArray.push(chainedWhere);
134
+ return this;
135
+ }
136
+ limit(limit) {
137
+ this.chainReference.push({ method: 'limit', args: limit });
138
+ this.limitNumber = limit;
139
+ return this;
140
+ }
141
+ take(limit) {
142
+ return this.limit(limit);
143
+ }
144
+ async pluck(path) {
145
+ const stringPath = path.toString();
146
+ this.chainReference.push({ method: 'pluck', args: stringPath });
147
+ const data = await this.get();
148
+ const result = data.map(e => {
149
+ const extracted = js_utils_1.Objects.getFromPath(e, String(stringPath), undefined);
150
+ if (typeof extracted.value !== 'undefined') {
151
+ return extracted.value;
152
+ }
153
+ });
154
+ return result;
155
+ }
156
+ orderBy(path, order = 'desc', orderType = 'string') {
157
+ const stringPath = path.toString();
158
+ const orderB = [stringPath, order, orderType];
159
+ this.chainReference.push({ method: 'orderBy', orderB });
160
+ this.orderByArray = orderB;
161
+ return this;
162
+ }
163
+ jsApplySelect(data) {
164
+ const _data = Array.isArray(data) ? [...data] : [data];
165
+ if (this.selectArray.length <= 0 && this.outputKeys.length <= 0) {
166
+ return _data;
167
+ }
168
+ const iterationArray = this.outputKeys.length === 0 && this.selectArray.length > 0
169
+ ? this.selectArray
170
+ : [...this.outputKeys, ...this.forceSelectArray];
171
+ const compareArray = this.outputKeys.length === 0 && this.selectArray.length > 0
172
+ ? [...this.outputKeys, ...this.forceSelectArray]
173
+ : this.selectArray;
174
+ return _data.map(element => {
175
+ const newElement = {};
176
+ iterationArray.forEach(attribute => {
177
+ if (compareArray.length > 0 && !compareArray.includes(attribute)) {
178
+ return undefined;
179
+ }
180
+ const extract = js_utils_1.Objects.getFromPath(element, attribute, undefined);
181
+ let value = js_utils_1.Objects.get(() => extract.value, undefined);
182
+ if (typeof value !== 'undefined' && value !== null) {
183
+ if (typeof value === 'object' &&
184
+ value.hasOwnProperty('data') &&
185
+ value.data.hasOwnProperty('name')) {
186
+ newElement[extract.label] = value.data.name;
187
+ }
188
+ else {
189
+ if (typeof value === 'object' && js_utils_1.Ids.isValidObjectID(value)) {
190
+ value = js_utils_1.Ids.objectIdString(value);
191
+ }
192
+ newElement[extract.label] = value;
193
+ }
194
+ }
195
+ });
196
+ return js_utils_1.Objects.nest(newElement);
197
+ });
198
+ }
199
+ jsApplyOrderBy(data) {
200
+ let _data = [...data];
201
+ if (this.orderByArray.length === 0) {
202
+ return _data;
203
+ }
204
+ const field = this.orderByArray[0];
205
+ if (this.selectArray.length > 0 &&
206
+ (field.includes('.') || field.includes('['))) {
207
+ throw new Error(`Cannot orderBy nested attribute "${field}" when using Select. You must rename the attribute`);
208
+ }
209
+ const order = this.orderByArray[1];
210
+ let type = this.orderByArray[2];
211
+ if (!type) {
212
+ type = 'string';
213
+ }
214
+ _data = _data.sort((a, b) => {
215
+ const A = js_utils_1.Objects.getFromPath(a, field, undefined).value;
216
+ const B = js_utils_1.Objects.getFromPath(b, field, undefined).value;
217
+ if (typeof A === 'undefined' || typeof B === 'undefined') {
218
+ throw new Error(`Cannot order by property "${field}" not all values have this property`);
219
+ }
220
+ if (type.includes('string') || type.includes('number')) {
221
+ if (order === 'asc') {
222
+ return A > B ? 1 : A < B ? -1 : 0;
223
+ }
224
+ return A > B ? -1 : A < B ? 1 : 0;
225
+ }
226
+ if (type.includes('date')) {
227
+ if (order === 'asc') {
228
+ return new Date(A).getTime() - new Date(B).getTime();
229
+ }
230
+ return new Date(B).getTime() - new Date(A).getTime();
231
+ }
232
+ });
233
+ return _data;
234
+ }
235
+ reset() {
236
+ this.chainReference = [];
237
+ this.whereArray = [];
238
+ this.orWhereArray = [];
239
+ this.selectArray = [];
240
+ this.forceSelectArray = [];
241
+ this.orderByArray = [];
242
+ this.limitNumber = undefined;
243
+ this.offsetNumber = undefined;
244
+ this.populateArray = [];
245
+ this.chunk = null;
246
+ this.pullSize = null;
247
+ this.ownerId = undefined;
248
+ this.paginator = undefined;
249
+ this.rawQuery = undefined;
250
+ this.getFirst = false;
251
+ this.relations = undefined;
252
+ this.loadModels = false;
253
+ this.relationQuery = undefined;
254
+ }
255
+ async load() {
256
+ const result = await this.get();
257
+ this.relationQuery = {
258
+ data: result,
259
+ relations: this.modelRelations
260
+ };
261
+ return this;
262
+ }
263
+ async loadFirst() {
264
+ const result = await this.first();
265
+ this.relationQuery = {
266
+ data: result,
267
+ relations: this.modelRelations
268
+ };
269
+ return this;
270
+ }
271
+ getLoadedData() {
272
+ return this.relationQuery.data;
273
+ }
274
+ with(entities) {
275
+ this.relations = entities;
276
+ return this;
277
+ }
278
+ async attach(data) {
279
+ if (!this.relationQuery.relation || !this.relationQuery.data) {
280
+ throw new Error('Attached can only be called as a related model');
281
+ }
282
+ if (this.relationQuery && this.relationQuery.data) {
283
+ const D = Array.isArray(this.relationQuery.data)
284
+ ? this.relationQuery.data
285
+ : [this.relationQuery.data];
286
+ const relatedData = D.map(d => ({
287
+ [this.relationQuery.relation.inverseSidePropertyPath]: this.isMongoDB
288
+ ? js_utils_1.Ids.objectID(d.id)
289
+ : d.id,
290
+ ...data
291
+ }));
292
+ return this.insertMany(relatedData);
293
+ }
294
+ }
295
+ associate(id) {
296
+ if (!this.relationQuery.relation || !this.relationQuery.data) {
297
+ throw new Error('Attached can only be called as a related model');
298
+ }
299
+ if (this.relationQuery && this.relationQuery.data) {
300
+ const D = Array.isArray(this.relationQuery.data)
301
+ ? this.relationQuery.data
302
+ : [this.relationQuery.data];
303
+ const relatedData = D.map(d => ({
304
+ [this.relationQuery.relation.joinColumns[0].propertyName]: this
305
+ .isMongoDB
306
+ ? js_utils_1.Ids.objectID(d.id)
307
+ : d.id,
308
+ [this.relationQuery.relation.inverseJoinColumns[0].propertyName]: this
309
+ .isMongoDB
310
+ ? js_utils_1.Ids.objectID(id)
311
+ : id
312
+ }));
313
+ return this.relationQuery.pivot.insertMany(relatedData);
314
+ }
315
+ }
316
+ hasMany(Repository, relationName) {
317
+ if (this.relationQuery) {
318
+ this.relationQuery.relation = this.relationQuery.relations[relationName];
319
+ }
320
+ const newClass = new Repository(this.relationQuery);
321
+ this.reset();
322
+ return newClass;
323
+ }
324
+ hasOne() {
325
+ throw new Error('Method not implemented');
326
+ }
327
+ belongsTo(Repository, relationName) {
328
+ if (this.relationQuery) {
329
+ this.relationQuery.relation = this.relationQuery.relations[relationName];
330
+ }
331
+ const newClass = new Repository(this.relationQuery);
332
+ this.reset();
333
+ return newClass;
334
+ }
335
+ belongsToMany(Repository, Pivot, relationName) {
336
+ this.relationQuery = !this.relationQuery
337
+ ? { pivot: new Pivot(this.relationQuery) }
338
+ : {
339
+ ...this.relationQuery,
340
+ ...{
341
+ pivot: new Pivot(this.relationQuery),
342
+ relation: this.relationQuery.relations[relationName]
343
+ }
344
+ };
345
+ const newClass = new Repository(this.relationQuery);
346
+ this.reset();
347
+ return newClass;
348
+ }
349
+ hasManyThrough() {
350
+ throw new Error('Method not implemented');
351
+ }
352
+ prepareInput(columns) {
353
+ let cols = [];
354
+ columns.forEach(col => {
355
+ cols = cols.concat(col.toString().trim());
356
+ });
357
+ cols.filter((elem, pos, arr) => arr.indexOf(elem) === pos);
358
+ return cols;
359
+ }
360
+ }
361
+ exports.BaseConnector = BaseConnector;
@@ -0,0 +1,26 @@
1
+ import { DataSource } from 'typeorm';
2
+ import { BaseDataElement, Primitives } from './types';
3
+ import { Collection } from '@goatlab/js-utils';
4
+ interface _FLUENT_ {
5
+ models?: {
6
+ [key: string]: boolean;
7
+ };
8
+ }
9
+ declare global {
10
+ interface Window {
11
+ _FLUENT_: _FLUENT_;
12
+ }
13
+ namespace NodeJS {
14
+ interface Global {
15
+ _FLUENT_: _FLUENT_;
16
+ }
17
+ }
18
+ }
19
+ export declare class Fluent {
20
+ private static registerModel;
21
+ static model<T = BaseDataElement>(name: string): any;
22
+ static collect<T = BaseDataElement | Primitives>(data: T[]): Collection<T>;
23
+ static getConfig(): _FLUENT_;
24
+ static models(Entities: any[]): Promise<DataSource>;
25
+ }
26
+ export {};
package/dist/Fluent.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Fluent = void 0;
4
+ const typed_path_1 = require("typed-path");
5
+ const js_utils_1 = require("@goatlab/js-utils");
6
+ const generatorDatasource_1 = require("./generatorDatasource");
7
+ if (typeof window !== 'undefined' && window && !window._FLUENT_) {
8
+ window._FLUENT_ = {
9
+ models: {}
10
+ };
11
+ }
12
+ if (global && !global._FLUENT_) {
13
+ global._FLUENT_ = {
14
+ models: {}
15
+ };
16
+ }
17
+ class Fluent {
18
+ static registerModel(name) {
19
+ if (!name || name === 'baseModel') {
20
+ return;
21
+ }
22
+ if (typeof window !== 'undefined') {
23
+ window._FLUENT_.models[name] = true;
24
+ return;
25
+ }
26
+ global._FLUENT_.models[name] = true;
27
+ }
28
+ static model(name) {
29
+ this.registerModel(name);
30
+ return (0, typed_path_1.typedPath)();
31
+ }
32
+ static collect(data) {
33
+ return new js_utils_1.Collection(data);
34
+ }
35
+ static getConfig() {
36
+ if (typeof window !== 'undefined' && window) {
37
+ return window._FLUENT_;
38
+ }
39
+ if (typeof global !== 'undefined' && global) {
40
+ return global._FLUENT_;
41
+ }
42
+ }
43
+ static async models(Entities) {
44
+ generatorDatasource_1.modelGeneratorDataSource.setOptions({ entities: Entities });
45
+ if (generatorDatasource_1.modelGeneratorDataSource.isInitialized) {
46
+ return generatorDatasource_1.modelGeneratorDataSource;
47
+ }
48
+ await generatorDatasource_1.modelGeneratorDataSource.initialize();
49
+ return generatorDatasource_1.modelGeneratorDataSource;
50
+ }
51
+ }
52
+ exports.Fluent = Fluent;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const typeorm_1 = require("typeorm");
4
+ const car_entity_1 = require("./test/relations/car/car.entity");
5
+ const car_repositoryTypeOrm_1 = require("./test/relations/car/car.repositoryTypeOrm");
6
+ const goat_entity_1 = require("./test/basic/goat.entity");
7
+ const goat_repository_1 = require("./test/basic/goat.repository");
8
+ const roles_entity_1 = require("./test/relations/roles/roles.entity");
9
+ const roles_repositoryTypeOrm_1 = require("./test/relations/roles/roles.repositoryTypeOrm");
10
+ const roles_user_entity_1 = require("./test/relations/roles/roles_user.entity");
11
+ const typeOrm_entity_1 = require("./test/advanced/typeOrm.entity");
12
+ const typeOrm_repository_1 = require("./test/advanced/typeOrm.repository");
13
+ const user_repositoryTypeOrm_1 = require("./test/relations/user/user.repositoryTypeOrm");
14
+ const user_entity_1 = require("./test/relations/user/user.entity");
15
+ const advancedTestSuite_1 = require("./test/advanced/advancedTestSuite");
16
+ const basicTestSuite_1 = require("./test/basic/basicTestSuite");
17
+ const relationsTestsSuite_1 = require("./test/relations/relationsTestsSuite");
18
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;
19
+ let mongoConnection;
20
+ beforeAll(async (done) => {
21
+ mongoConnection = '';
22
+ await (0, typeorm_1.createConnection)({
23
+ type: 'mongodb',
24
+ name: 'runningTest',
25
+ url: mongoConnection.url,
26
+ useNewUrlParser: true,
27
+ useUnifiedTopology: true,
28
+ entities: [
29
+ goat_entity_1.GoatEntity,
30
+ typeOrm_entity_1.TypeORMDataModel,
31
+ car_entity_1.CarsEntity,
32
+ user_entity_1.UsersEntity,
33
+ roles_entity_1.RoleEntity,
34
+ roles_user_entity_1.RolesUser
35
+ ],
36
+ synchronize: false,
37
+ logging: false
38
+ });
39
+ done();
40
+ });
41
+ afterAll(async () => {
42
+ await mongoConnection.instance.stop();
43
+ });
44
+ describe('Execute all basic test Suite', () => {
45
+ (0, basicTestSuite_1.basicTestSuite)(goat_repository_1.GoatRepository);
46
+ });
47
+ describe('Execute all advanced test Suite', () => {
48
+ (0, advancedTestSuite_1.advancedTestSuite)(typeOrm_repository_1.TypeOrmRepository);
49
+ });
50
+ describe('Execute all relations test suite', () => {
51
+ (0, relationsTestsSuite_1.relationsTestSuite)(user_repositoryTypeOrm_1.UserRepository, car_repositoryTypeOrm_1.CarsRepository, roles_repositoryTypeOrm_1.RoleRepository);
52
+ });
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const typeorm_1 = require("typeorm");
4
+ const car_entity_1 = require("./test/relations/car/car.entity");
5
+ const car_repositoryTypeOrm_1 = require("./test/relations/car/car.repositoryTypeOrm");
6
+ const goat_entity_1 = require("./test/basic/goat.entity");
7
+ const goat_repository_1 = require("./test/basic/goat.repository");
8
+ const roles_entity_1 = require("./test/relations/roles/roles.entity");
9
+ const roles_repositoryTypeOrm_1 = require("./test/relations/roles/roles.repositoryTypeOrm");
10
+ const roles_user_entity_1 = require("./test/relations/roles/roles_user.entity");
11
+ const typeOrm_entity_1 = require("./test/advanced/typeOrm.entity");
12
+ const typeOrm_repository_1 = require("./test/advanced/typeOrm.repository");
13
+ const user_repositoryTypeOrm_1 = require("./test/relations/user/user.repositoryTypeOrm");
14
+ const user_entity_1 = require("./test/relations/user/user.entity");
15
+ const advancedTestSuite_1 = require("./test/advanced/advancedTestSuite");
16
+ const basicTestSuite_1 = require("./test/basic/basicTestSuite");
17
+ const relationsTestsSuite_1 = require("./test/relations/relationsTestsSuite");
18
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;
19
+ let tearDown;
20
+ beforeAll(async (done) => {
21
+ const { databaseURL, kill } = { databaseURL: '', kill: () => { } };
22
+ tearDown = kill;
23
+ const conn = new typeorm_1.DataSource({
24
+ type: 'mysql',
25
+ name: 'runningTest',
26
+ database: 'test-db',
27
+ username: 'test-user',
28
+ password: 'password',
29
+ port: 3306,
30
+ entities: [
31
+ goat_entity_1.GoatEntity,
32
+ typeOrm_entity_1.TypeORMDataModel,
33
+ car_entity_1.CarsEntity,
34
+ user_entity_1.UsersEntity,
35
+ roles_entity_1.RoleEntity,
36
+ roles_user_entity_1.RolesUser
37
+ ],
38
+ synchronize: true,
39
+ logging: false
40
+ });
41
+ await conn.initialize();
42
+ done();
43
+ });
44
+ afterAll(() => {
45
+ return tearDown();
46
+ });
47
+ describe('Execute all basic test Suite', () => {
48
+ (0, basicTestSuite_1.basicTestSuite)(goat_repository_1.GoatRepository);
49
+ });
50
+ describe('Execute all advanced test Suite', () => {
51
+ (0, advancedTestSuite_1.advancedTestSuite)(typeOrm_repository_1.TypeOrmRepository);
52
+ });
53
+ describe('Execute all relations test suite', () => {
54
+ (0, relationsTestsSuite_1.relationsTestSuite)(user_repositoryTypeOrm_1.UserRepository, car_repositoryTypeOrm_1.CarsRepository, roles_repositoryTypeOrm_1.RoleRepository);
55
+ });
@@ -0,0 +1 @@
1
+ export declare const advancedTestSuite: (Model: any) => void;