@goatlab/fluent 0.6.6 → 0.6.9
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/dist/BaseConnector.d.ts +79 -0
- package/dist/BaseConnector.js +361 -0
- package/dist/Fluent.d.ts +26 -0
- package/dist/Fluent.js +52 -0
- package/dist/TypeOrmConnector/TypeOrmConnector.d.ts +2 -2
- package/dist/TypeOrmConnector/TypeOrmConnector.js +511 -0
- package/dist/TypeOrmConnector/TypeOrmMongoConnector._bypass.js +52 -0
- package/dist/TypeOrmConnector/TypeOrmMysqlConnector._bypass.js +55 -0
- package/dist/TypeOrmConnector/test/advanced/advancedTestSuite.d.ts +1 -0
- package/dist/TypeOrmConnector/test/advanced/advancedTestSuite.js +114 -0
- package/dist/TypeOrmConnector/test/advanced/typeOrm.entity.d.ts +16 -0
- package/dist/TypeOrmConnector/test/advanced/typeOrm.entity.js +57 -0
- package/dist/TypeOrmConnector/test/advanced/typeOrm.repository.js +11 -0
- package/dist/TypeOrmConnector/test/basic/basicTestSuite.d.ts +1 -0
- package/dist/TypeOrmConnector/test/basic/basicTestSuite.js +45 -0
- package/dist/TypeOrmConnector/test/basic/goat.dto.d.ts +8 -0
- package/dist/TypeOrmConnector/test/basic/goat.dto.js +18 -0
- package/dist/TypeOrmConnector/test/basic/goat.entity.d.ts +10 -0
- package/dist/TypeOrmConnector/test/basic/goat.entity.js +42 -0
- package/dist/TypeOrmConnector/test/basic/goat.repository.js +11 -0
- package/dist/TypeOrmConnector/test/flock.d.ts +4 -0
- package/dist/TypeOrmConnector/test/flock.js +25 -0
- package/dist/TypeOrmConnector/test/relations/car/car.dto.d.ts +5 -0
- package/dist/TypeOrmConnector/test/relations/car/car.dto.js +12 -0
- package/dist/TypeOrmConnector/test/relations/car/car.entity.d.ts +7 -0
- package/dist/TypeOrmConnector/test/relations/car/car.entity.js +32 -0
- package/dist/TypeOrmConnector/test/relations/car/car.repositoryTypeOrm.js +13 -0
- package/dist/TypeOrmConnector/test/relations/relationsTestsSuite.d.ts +1 -0
- package/dist/TypeOrmConnector/test/relations/relationsTestsSuite.js +93 -0
- package/dist/TypeOrmConnector/test/relations/roles/role.dto.d.ts +5 -0
- package/dist/TypeOrmConnector/test/relations/roles/role.dto.js +12 -0
- package/dist/TypeOrmConnector/test/relations/roles/roles.entity.d.ts +6 -0
- package/dist/TypeOrmConnector/test/relations/roles/roles.entity.js +29 -0
- package/dist/TypeOrmConnector/test/relations/roles/roles.repositoryTypeOrm.js +14 -0
- package/dist/TypeOrmConnector/test/relations/roles/roles_user.dto.d.ts +5 -0
- package/dist/TypeOrmConnector/test/relations/roles/roles_user.dto.js +12 -0
- package/dist/TypeOrmConnector/test/relations/roles/roles_user.entity.d.ts +5 -0
- package/dist/TypeOrmConnector/test/relations/roles/roles_user.entity.js +23 -0
- package/dist/TypeOrmConnector/test/relations/roles/roles_users.repositoryTypeOrm.js +11 -0
- package/dist/TypeOrmConnector/test/relations/user/user.dto.d.ts +5 -0
- package/dist/TypeOrmConnector/test/relations/user/user.dto.js +12 -0
- package/dist/TypeOrmConnector/test/relations/user/user.entity.d.ts +14 -0
- package/dist/TypeOrmConnector/test/relations/user/user.entity.js +56 -0
- package/dist/TypeOrmConnector/test/relations/user/user.repositoryTypeOrm.js +16 -0
- package/dist/core/Loopback/build-schema.d.ts +31 -0
- package/dist/core/Loopback/build-schema.js +335 -0
- package/dist/core/Loopback/common-types.d.ts +36 -0
- package/dist/core/Loopback/common-types.js +13 -0
- package/dist/core/Loopback/json-to-schema.d.ts +6 -0
- package/dist/core/Loopback/json-to-schema.js +96 -0
- package/dist/core/Loopback/metadata.d.ts +9 -0
- package/dist/core/Loopback/metadata.js +28 -0
- package/dist/core/Loopback/model.d.ts +87 -0
- package/dist/core/Loopback/model.js +244 -0
- package/dist/core/Loopback/query.d.ts +97 -0
- package/dist/core/Loopback/query.js +290 -0
- package/dist/core/Loopback/relation.types.d.ts +45 -0
- package/dist/core/Loopback/relation.types.js +13 -0
- package/dist/core/Loopback/type-resolver.d.ts +7 -0
- package/dist/core/Loopback/type-resolver.js +34 -0
- package/dist/core/Loopback/type.d.ts +9 -0
- package/dist/core/Loopback/type.js +2 -0
- package/dist/core/Nestjs/applyDecorators.d.ts +1 -0
- package/dist/core/Nestjs/applyDecorators.js +17 -0
- package/dist/core/Nestjs/types/common.d.ts +16 -0
- package/dist/core/Nestjs/types/common.js +35 -0
- package/dist/core/Nestjs/types/decorators/api-hide-property.decorator.d.ts +1 -0
- package/dist/core/Nestjs/types/decorators/api-hide-property.decorator.js +7 -0
- package/dist/core/Nestjs/types/decorators/api-property.decorator.d.ts +27 -0
- package/dist/core/Nestjs/types/decorators/api-property.decorator.js +65 -0
- package/dist/core/Nestjs/types/decorators/apply-is-optional.decorator.d.ts +5 -0
- package/dist/core/Nestjs/types/decorators/apply-is-optional.decorator.js +131 -0
- package/dist/core/Nestjs/types/decorators/args-type.decorator.d.ts +1 -0
- package/dist/core/Nestjs/types/decorators/args-type.decorator.js +19 -0
- package/dist/core/Nestjs/types/decorators/create-property.decorator.d.ts +2 -0
- package/dist/core/Nestjs/types/decorators/create-property.decorator.js +50 -0
- package/dist/core/Nestjs/types/decorators/directive.decorator.d.ts +1 -0
- package/dist/core/Nestjs/types/decorators/directive.decorator.js +36 -0
- package/dist/core/Nestjs/types/decorators/extensions.decorator.d.ts +1 -0
- package/dist/core/Nestjs/types/decorators/extensions.decorator.js +25 -0
- package/dist/core/Nestjs/types/decorators/field.decorator.d.ts +15 -0
- package/dist/core/Nestjs/types/decorators/field.decorator.js +56 -0
- package/dist/core/Nestjs/types/decorators/input-type.decorator.d.ts +7 -0
- package/dist/core/Nestjs/types/decorators/input-type.decorator.js +23 -0
- package/dist/core/Nestjs/types/decorators/interface-type.decorator.d.ts +9 -0
- package/dist/core/Nestjs/types/decorators/interface-type.decorator.js +27 -0
- package/dist/core/Nestjs/types/decorators/partial-type.helper.d.ts +3 -0
- package/dist/core/Nestjs/types/decorators/partial-type.helper.js +42 -0
- package/dist/core/Nestjs/types/errors/cannot-determine-host-type.error.d.ts +3 -0
- package/dist/core/Nestjs/types/errors/cannot-determine-host-type.error.js +9 -0
- package/dist/core/Nestjs/types/errors/directive-parsing.error.d.ts +3 -0
- package/dist/core/Nestjs/types/errors/directive-parsing.error.js +9 -0
- package/dist/core/Nestjs/types/errors/unable-to-find-fields.error.d.ts +3 -0
- package/dist/core/Nestjs/types/errors/unable-to-find-fields.error.js +9 -0
- package/dist/core/Nestjs/types/errors/undefined-type.error.d.ts +3 -0
- package/dist/core/Nestjs/types/errors/undefined-type.error.js +10 -0
- package/dist/core/Nestjs/types/interfaces/add-class-type-metadata.util.d.ts +3 -0
- package/dist/core/Nestjs/types/interfaces/add-class-type-metadata.util.js +10 -0
- package/dist/core/Nestjs/types/interfaces/base-type-options.interface.d.ts +5 -0
- package/dist/core/Nestjs/types/interfaces/base-type-options.interface.js +2 -0
- package/dist/core/Nestjs/types/interfaces/class-decorator-factory.interface.d.ts +5 -0
- package/dist/core/Nestjs/types/interfaces/class-decorator-factory.interface.js +2 -0
- package/dist/core/Nestjs/types/interfaces/complexity.interface.d.ts +11 -0
- package/dist/core/Nestjs/types/interfaces/complexity.interface.js +2 -0
- package/dist/core/Nestjs/types/interfaces/field-middleware.interface.d.ts +15 -0
- package/dist/core/Nestjs/types/interfaces/field-middleware.interface.js +2 -0
- package/dist/core/Nestjs/types/interfaces/open-api-spec.interface.d.ts +235 -0
- package/dist/core/Nestjs/types/interfaces/open-api-spec.interface.js +2 -0
- package/dist/core/Nestjs/types/interfaces/resolve-type-fn.interface.d.ts +2 -0
- package/dist/core/Nestjs/types/interfaces/resolve-type-fn.interface.js +2 -0
- package/dist/core/Nestjs/types/interfaces/return-type-func.interface.d.ts +5 -0
- package/dist/core/Nestjs/types/interfaces/return-type-func.interface.js +2 -0
- package/dist/core/Nestjs/types/interfaces/schema-object-metadata.interface.d.ts +9 -0
- package/dist/core/Nestjs/types/interfaces/schema-object-metadata.interface.js +2 -0
- package/dist/core/Nestjs/types/interfaces/type-options.interface.d.ts +5 -0
- package/dist/core/Nestjs/types/interfaces/type-options.interface.js +2 -0
- package/dist/core/Nestjs/types/lazy-metadata.storage.d.ts +15 -0
- package/dist/core/Nestjs/types/lazy-metadata.storage.js +67 -0
- package/dist/core/Nestjs/types/metadata/class.metadata.d.ts +11 -0
- package/dist/core/Nestjs/types/metadata/class.metadata.js +2 -0
- package/dist/core/Nestjs/types/metadata/directive.metadata.d.ts +8 -0
- package/dist/core/Nestjs/types/metadata/directive.metadata.js +2 -0
- package/dist/core/Nestjs/types/metadata/enum.metadata.d.ts +11 -0
- package/dist/core/Nestjs/types/metadata/enum.metadata.js +2 -0
- package/dist/core/Nestjs/types/metadata/extensions.metadata.d.ts +8 -0
- package/dist/core/Nestjs/types/metadata/extensions.metadata.js +2 -0
- package/dist/core/Nestjs/types/metadata/index.d.ts +8 -0
- package/dist/core/Nestjs/types/metadata/index.js +11 -0
- package/dist/core/Nestjs/types/metadata/interface.metadata.d.ts +6 -0
- package/dist/core/Nestjs/types/metadata/interface.metadata.js +2 -0
- package/dist/core/Nestjs/types/metadata/object-type.metadata.d.ts +4 -0
- package/dist/core/Nestjs/types/metadata/object-type.metadata.js +2 -0
- package/dist/core/Nestjs/types/metadata/param.metadata.d.ts +18 -0
- package/dist/core/Nestjs/types/metadata/param.metadata.js +2 -0
- package/dist/core/Nestjs/types/metadata/property.metadata.d.ts +20 -0
- package/dist/core/Nestjs/types/metadata/property.metadata.js +2 -0
- package/dist/core/Nestjs/types/metadata/resolver.metadata.d.ts +34 -0
- package/dist/core/Nestjs/types/metadata/resolver.metadata.js +2 -0
- package/dist/core/Nestjs/types/metadata/union.metadata.d.ts +9 -0
- package/dist/core/Nestjs/types/metadata/union.metadata.js +2 -0
- package/dist/core/Nestjs/types/object-type.decorator.d.ts +8 -0
- package/dist/core/Nestjs/types/object-type.decorator.js +25 -0
- package/dist/core/Nestjs/types/omit-type.d.ts +2 -0
- package/dist/core/Nestjs/types/omit-type.js +30 -0
- package/dist/core/Nestjs/types/reflection.utils.d.ts +15 -0
- package/dist/core/Nestjs/types/reflection.utils.js +58 -0
- package/dist/core/Nestjs/types/set-metadata.decorator.d.ts +4 -0
- package/dist/core/Nestjs/types/set-metadata.decorator.js +16 -0
- package/dist/core/Nestjs/types/type-metadata.storage.d.ts +69 -0
- package/dist/core/Nestjs/types/type-metadata.storage.js +342 -0
- package/dist/core/Nestjs/types/utils/enum.utils.d.ts +3 -0
- package/dist/core/Nestjs/types/utils/enum.utils.js +29 -0
- package/dist/core/Nestjs/types/utils/get-fields-and-decorator.util.d.ts +13 -0
- package/dist/core/Nestjs/types/utils/get-fields-and-decorator.util.js +72 -0
- package/dist/core/Nestjs/types/utils/mapped-types.utils.d.ts +2 -0
- package/dist/core/Nestjs/types/utils/mapped-types.utils.js +38 -0
- package/dist/core/Nestjs/types/utils/model-properties-accessor.d.ts +6 -0
- package/dist/core/Nestjs/types/utils/model-properties-accessor.js +36 -0
- package/dist/core/Nestjs/types/utils/type-helpers.utils.d.ts +2 -0
- package/dist/core/Nestjs/types/utils/type-helpers.utils.js +16 -0
- package/dist/core/database/createConnection.d.ts +30 -0
- package/dist/core/database/createConnection.js +43 -0
- package/dist/core/database/decorators.d.ts +43 -0
- package/dist/core/database/decorators.js +98 -0
- package/dist/core/dtos/access.dto.d.ts +4 -0
- package/dist/core/dtos/access.dto.js +21 -0
- package/dist/core/types.d.ts +23 -0
- package/dist/core/types.js +29 -0
- package/dist/generatorDatasource.d.ts +2 -0
- package/dist/generatorDatasource.js +12 -0
- package/dist/loadRelations.js +92 -0
- package/dist/outputKeys.d.ts +2 -0
- package/dist/outputKeys.js +17 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.js +2 -0
- 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;
|
package/dist/Fluent.d.ts
ADDED
|
@@ -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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Repository } from 'typeorm';
|
|
2
|
-
import {
|
|
3
|
-
import type { Filter, DaoOutput, BaseDataElement, PaginatedData, Paginator, Sure } from '../
|
|
2
|
+
import { BaseConnector, FluentConnectorInterface } from '../BaseConnector';
|
|
3
|
+
import type { Filter, DaoOutput, BaseDataElement, PaginatedData, Paginator, Sure } from '../types';
|
|
4
4
|
export declare class GoatRepository<T> extends Repository<T> {
|
|
5
5
|
}
|
|
6
6
|
export declare const getRelations: (typeOrmRepo: any) => {
|