@goatlab/fluent 0.6.22 → 0.6.30
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 +49 -82
- package/dist/BaseConnector.js +219 -319
- package/dist/Fluent.d.ts +2 -21
- package/dist/Fluent.js +0 -33
- package/dist/FluentEntity.d.ts +7 -0
- package/dist/FluentEntity.js +28 -0
- package/dist/TypeOrmConnector/TypeOrmConnector.d.ts +34 -27
- package/dist/TypeOrmConnector/TypeOrmConnector.js +599 -343
- package/dist/TypeOrmConnector/test/advanced/advancedTestSuite.d.ts +0 -0
- package/dist/TypeOrmConnector/test/advanced/advancedTestSuite.js +182 -48
- package/dist/TypeOrmConnector/test/advanced/typeOrm.entity.d.ts +103 -3
- package/dist/TypeOrmConnector/test/advanced/typeOrm.entity.js +30 -13
- package/dist/TypeOrmConnector/test/advanced/typeOrm.mongo.repository.d.ts +5 -0
- package/dist/TypeOrmConnector/test/advanced/typeOrm.mongo.repository.js +17 -0
- package/dist/TypeOrmConnector/test/advanced/typeOrm.mysql.repository.d.ts +5 -0
- package/dist/TypeOrmConnector/test/advanced/typeOrm.mysql.repository.js +17 -0
- package/dist/TypeOrmConnector/test/advanced/typeOrm.repository.d.ts +3 -3
- package/dist/TypeOrmConnector/test/advanced/typeOrm.repository.js +8 -3
- package/dist/TypeOrmConnector/test/basic/basicTestSuite.d.ts +1 -1
- package/dist/TypeOrmConnector/test/basic/basicTestSuite.js +42 -16
- package/dist/TypeOrmConnector/test/basic/goat.entity.d.ts +43 -0
- package/dist/TypeOrmConnector/test/basic/goat.entity.js +19 -8
- package/dist/TypeOrmConnector/test/basic/goat.mongo.repository.d.ts +5 -0
- package/dist/TypeOrmConnector/test/basic/goat.mongo.repository.js +16 -0
- package/dist/TypeOrmConnector/test/basic/goat.mysql.repository.d.ts +5 -0
- package/dist/TypeOrmConnector/test/basic/goat.mysql.repository.js +16 -0
- package/dist/TypeOrmConnector/test/basic/goat.repository.d.ts +3 -4
- package/dist/TypeOrmConnector/test/basic/goat.repository.js +7 -3
- package/dist/TypeOrmConnector/test/dbEntities.d.ts +6 -6
- package/dist/TypeOrmConnector/test/dbEntities.js +0 -0
- package/dist/TypeOrmConnector/test/docker/docker.d.ts +35 -0
- package/dist/TypeOrmConnector/test/docker/docker.js +149 -0
- package/dist/TypeOrmConnector/test/docker/mysql.d.ts +17 -0
- package/dist/TypeOrmConnector/test/docker/mysql.js +132 -0
- package/dist/TypeOrmConnector/test/flock.d.ts +0 -0
- package/dist/TypeOrmConnector/test/flock.js +0 -0
- package/dist/TypeOrmConnector/test/mongo/car.mongo.repository.d.ts +8 -0
- package/dist/TypeOrmConnector/test/mongo/car.mongo.repository.js +23 -0
- package/dist/TypeOrmConnector/test/mongo/mongo.memory.d.ts +4 -0
- package/dist/TypeOrmConnector/test/mongo/mongo.memory.js +43 -0
- package/dist/TypeOrmConnector/test/mongo/mongoDatasource.d.ts +2 -0
- package/dist/TypeOrmConnector/test/mongo/mongoDatasource.js +12 -0
- package/dist/TypeOrmConnector/test/mongo/roles.mongo.repository.d.ts +8 -0
- package/dist/TypeOrmConnector/test/mongo/roles.mongo.repository.js +23 -0
- package/dist/TypeOrmConnector/test/mongo/roles_user.mongo.repository.d.ts +6 -0
- package/dist/TypeOrmConnector/test/mongo/roles_user.mongo.repository.js +17 -0
- package/dist/TypeOrmConnector/test/mongo/user.mongo.repository.d.ts +10 -0
- package/dist/TypeOrmConnector/test/mongo/user.mongo.repository.js +31 -0
- package/dist/TypeOrmConnector/test/mysql/car.mysql.repository.d.ts +6 -0
- package/dist/TypeOrmConnector/test/mysql/car.mysql.repository.js +17 -0
- package/dist/TypeOrmConnector/test/mysql/mysqlDataSource.d.ts +2 -0
- package/dist/TypeOrmConnector/test/mysql/mysqlDataSource.js +16 -0
- package/dist/TypeOrmConnector/test/mysql/roles.mysql.repository.d.ts +8 -0
- package/dist/TypeOrmConnector/test/mysql/roles.mysql.repository.js +23 -0
- package/dist/TypeOrmConnector/test/mysql/roles_user.mysql.repository.d.ts +6 -0
- package/dist/TypeOrmConnector/test/mysql/roles_user.mysql.repository.js +17 -0
- package/dist/TypeOrmConnector/test/mysql/user.mysql.repository.d.ts +10 -0
- package/dist/TypeOrmConnector/test/mysql/user.mysql.repository.js +32 -0
- package/dist/TypeOrmConnector/test/relations/car/car.entity.d.ts +1 -0
- package/dist/TypeOrmConnector/test/relations/car/car.entity.js +13 -5
- package/dist/TypeOrmConnector/test/relations/car/car.repositoryTypeOrm.d.ts +3 -3
- package/dist/TypeOrmConnector/test/relations/car/car.repositoryTypeOrm.js +11 -4
- package/dist/TypeOrmConnector/test/relations/car/car.schema.d.ts +38 -0
- package/dist/TypeOrmConnector/test/relations/car/car.schema.js +14 -0
- package/dist/TypeOrmConnector/test/relations/relationsTestsSuite.d.ts +0 -0
- package/dist/TypeOrmConnector/test/relations/relationsTestsSuite.js +85 -32
- package/dist/TypeOrmConnector/test/relations/roles/role.schema.d.ts +35 -0
- package/dist/TypeOrmConnector/test/relations/roles/role.schema.js +16 -0
- package/dist/TypeOrmConnector/test/relations/roles/roles.entity.d.ts +0 -0
- package/dist/TypeOrmConnector/test/relations/roles/roles.entity.js +4 -4
- package/dist/TypeOrmConnector/test/relations/roles/roles.repositoryTypeOrm.d.ts +3 -3
- package/dist/TypeOrmConnector/test/relations/roles/roles.repositoryTypeOrm.js +12 -4
- package/dist/TypeOrmConnector/test/relations/roles/roles_user.entity.d.ts +2 -2
- package/dist/TypeOrmConnector/test/relations/roles/roles_user.entity.js +4 -4
- package/dist/TypeOrmConnector/test/relations/roles/roles_user.schema.d.ts +15 -0
- package/dist/TypeOrmConnector/test/relations/roles/roles_user.schema.js +9 -0
- package/dist/TypeOrmConnector/test/relations/roles/roles_users.repositoryTypeOrm.d.ts +3 -3
- package/dist/TypeOrmConnector/test/relations/roles/roles_users.repositoryTypeOrm.js +8 -3
- package/dist/TypeOrmConnector/test/relations/user/user.entity.d.ts +0 -0
- package/dist/TypeOrmConnector/test/relations/user/user.entity.js +10 -10
- package/dist/TypeOrmConnector/test/relations/user/user.repositoryTypeOrm.d.ts +3 -3
- package/dist/TypeOrmConnector/test/relations/user/user.repositoryTypeOrm.js +17 -5
- package/dist/TypeOrmConnector/test/relations/user/user.schema.d.ts +150 -0
- package/dist/TypeOrmConnector/test/relations/user/user.schema.js +18 -0
- package/dist/TypeOrmConnector/test/{memoryDataSource.d.ts → sqlite/memoryDataSource.d.ts} +0 -0
- package/dist/TypeOrmConnector/test/{memoryDataSource.js → sqlite/memoryDataSource.js} +1 -1
- package/dist/cache.d.ts +0 -0
- package/dist/cache.js +0 -0
- package/dist/core/Loopback/build-schema.d.ts +0 -0
- package/dist/core/Loopback/build-schema.js +1 -3
- package/dist/core/Loopback/common-types.d.ts +0 -0
- package/dist/core/Loopback/common-types.js +0 -0
- package/dist/core/Loopback/json-to-schema.d.ts +0 -0
- package/dist/core/Loopback/json-to-schema.js +6 -6
- package/dist/core/Loopback/mapValues.d.ts +2 -0
- package/dist/core/Loopback/mapValues.js +835 -0
- package/dist/core/Loopback/metadata.d.ts +0 -0
- package/dist/core/Loopback/metadata.js +0 -0
- package/dist/core/Loopback/model.d.ts +0 -0
- package/dist/core/Loopback/model.js +0 -0
- package/dist/core/Loopback/query.d.ts +0 -0
- package/dist/core/Loopback/query.js +6 -4
- package/dist/core/Loopback/relation.types.d.ts +0 -0
- package/dist/core/Loopback/relation.types.js +0 -0
- package/dist/core/Loopback/type-resolver.d.ts +1 -1
- package/dist/core/Loopback/type-resolver.js +0 -0
- package/dist/core/Loopback/type.d.ts +0 -0
- package/dist/core/Loopback/type.js +0 -0
- package/dist/core/Nestjs/applyDecorators.d.ts +1 -1
- package/dist/core/Nestjs/applyDecorators.js +0 -0
- package/dist/core/Nestjs/types/common.d.ts +0 -0
- package/dist/core/Nestjs/types/common.js +3 -1
- package/dist/core/Nestjs/types/decorators/api-hide-property.decorator.d.ts +0 -0
- package/dist/core/Nestjs/types/decorators/api-hide-property.decorator.js +0 -0
- package/dist/core/Nestjs/types/decorators/api-property.decorator.d.ts +0 -0
- package/dist/core/Nestjs/types/decorators/api-property.decorator.js +0 -0
- package/dist/core/Nestjs/types/decorators/apply-is-optional.decorator.d.ts +1 -1
- package/dist/core/Nestjs/types/decorators/apply-is-optional.decorator.js +0 -0
- package/dist/core/Nestjs/types/decorators/args-type.decorator.d.ts +0 -0
- package/dist/core/Nestjs/types/decorators/args-type.decorator.js +0 -0
- package/dist/core/Nestjs/types/decorators/create-property.decorator.d.ts +0 -0
- package/dist/core/Nestjs/types/decorators/create-property.decorator.js +9 -4
- package/dist/core/Nestjs/types/decorators/directive.decorator.d.ts +0 -0
- package/dist/core/Nestjs/types/decorators/directive.decorator.js +0 -0
- package/dist/core/Nestjs/types/decorators/extensions.decorator.d.ts +0 -0
- package/dist/core/Nestjs/types/decorators/extensions.decorator.js +0 -0
- package/dist/core/Nestjs/types/decorators/field.decorator.d.ts +1 -1
- package/dist/core/Nestjs/types/decorators/field.decorator.js +6 -6
- package/dist/core/Nestjs/types/decorators/input-type.decorator.d.ts +0 -0
- package/dist/core/Nestjs/types/decorators/input-type.decorator.js +0 -0
- package/dist/core/Nestjs/types/decorators/interface-type.decorator.d.ts +0 -0
- package/dist/core/Nestjs/types/decorators/interface-type.decorator.js +0 -0
- package/dist/core/Nestjs/types/decorators/partial-type.helper.d.ts +0 -0
- package/dist/core/Nestjs/types/decorators/partial-type.helper.js +0 -0
- package/dist/core/Nestjs/types/errors/cannot-determine-host-type.error.d.ts +0 -0
- package/dist/core/Nestjs/types/errors/cannot-determine-host-type.error.js +0 -0
- package/dist/core/Nestjs/types/errors/directive-parsing.error.d.ts +0 -0
- package/dist/core/Nestjs/types/errors/directive-parsing.error.js +0 -0
- package/dist/core/Nestjs/types/errors/unable-to-find-fields.error.d.ts +0 -0
- package/dist/core/Nestjs/types/errors/unable-to-find-fields.error.js +0 -0
- package/dist/core/Nestjs/types/errors/undefined-type.error.d.ts +0 -0
- package/dist/core/Nestjs/types/errors/undefined-type.error.js +0 -0
- package/dist/core/Nestjs/types/interfaces/add-class-type-metadata.util.d.ts +0 -0
- package/dist/core/Nestjs/types/interfaces/add-class-type-metadata.util.js +0 -0
- package/dist/core/Nestjs/types/interfaces/base-type-options.interface.d.ts +0 -0
- package/dist/core/Nestjs/types/interfaces/base-type-options.interface.js +0 -0
- package/dist/core/Nestjs/types/interfaces/class-decorator-factory.interface.d.ts +0 -0
- package/dist/core/Nestjs/types/interfaces/class-decorator-factory.interface.js +0 -0
- package/dist/core/Nestjs/types/interfaces/complexity.interface.d.ts +0 -0
- package/dist/core/Nestjs/types/interfaces/complexity.interface.js +0 -0
- package/dist/core/Nestjs/types/interfaces/field-middleware.interface.d.ts +0 -0
- package/dist/core/Nestjs/types/interfaces/field-middleware.interface.js +0 -0
- package/dist/core/Nestjs/types/interfaces/open-api-spec.interface.d.ts +0 -0
- package/dist/core/Nestjs/types/interfaces/open-api-spec.interface.js +0 -0
- package/dist/core/Nestjs/types/interfaces/resolve-type-fn.interface.d.ts +0 -0
- package/dist/core/Nestjs/types/interfaces/resolve-type-fn.interface.js +0 -0
- package/dist/core/Nestjs/types/interfaces/return-type-func.interface.d.ts +0 -0
- package/dist/core/Nestjs/types/interfaces/return-type-func.interface.js +0 -0
- package/dist/core/Nestjs/types/interfaces/schema-object-metadata.interface.d.ts +0 -0
- package/dist/core/Nestjs/types/interfaces/schema-object-metadata.interface.js +0 -0
- package/dist/core/Nestjs/types/interfaces/type-options.interface.d.ts +0 -0
- package/dist/core/Nestjs/types/interfaces/type-options.interface.js +0 -0
- package/dist/core/Nestjs/types/lazy-metadata.storage.d.ts +0 -0
- package/dist/core/Nestjs/types/lazy-metadata.storage.js +3 -3
- package/dist/core/Nestjs/types/metadata/class.metadata.d.ts +0 -0
- package/dist/core/Nestjs/types/metadata/class.metadata.js +0 -0
- package/dist/core/Nestjs/types/metadata/directive.metadata.d.ts +0 -0
- package/dist/core/Nestjs/types/metadata/directive.metadata.js +0 -0
- package/dist/core/Nestjs/types/metadata/enum.metadata.d.ts +0 -0
- package/dist/core/Nestjs/types/metadata/enum.metadata.js +0 -0
- package/dist/core/Nestjs/types/metadata/extensions.metadata.d.ts +0 -0
- package/dist/core/Nestjs/types/metadata/extensions.metadata.js +0 -0
- package/dist/core/Nestjs/types/metadata/index.d.ts +0 -0
- package/dist/core/Nestjs/types/metadata/index.js +0 -0
- package/dist/core/Nestjs/types/metadata/interface.metadata.d.ts +0 -0
- package/dist/core/Nestjs/types/metadata/interface.metadata.js +0 -0
- package/dist/core/Nestjs/types/metadata/object-type.metadata.d.ts +0 -0
- package/dist/core/Nestjs/types/metadata/object-type.metadata.js +0 -0
- package/dist/core/Nestjs/types/metadata/param.metadata.d.ts +0 -0
- package/dist/core/Nestjs/types/metadata/param.metadata.js +0 -0
- package/dist/core/Nestjs/types/metadata/property.metadata.d.ts +0 -0
- package/dist/core/Nestjs/types/metadata/property.metadata.js +0 -0
- package/dist/core/Nestjs/types/metadata/resolver.metadata.d.ts +0 -0
- package/dist/core/Nestjs/types/metadata/resolver.metadata.js +0 -0
- package/dist/core/Nestjs/types/metadata/union.metadata.d.ts +0 -0
- package/dist/core/Nestjs/types/metadata/union.metadata.js +0 -0
- package/dist/core/Nestjs/types/object-type.decorator.d.ts +0 -0
- package/dist/core/Nestjs/types/object-type.decorator.js +0 -0
- package/dist/core/Nestjs/types/omit-type.d.ts +0 -0
- package/dist/core/Nestjs/types/omit-type.js +6 -2
- package/dist/core/Nestjs/types/reflection.utils.d.ts +1 -1
- package/dist/core/Nestjs/types/reflection.utils.js +9 -2
- package/dist/core/Nestjs/types/set-metadata.decorator.d.ts +0 -0
- package/dist/core/Nestjs/types/set-metadata.decorator.js +0 -0
- package/dist/core/Nestjs/types/type-metadata.storage.d.ts +0 -0
- package/dist/core/Nestjs/types/type-metadata.storage.js +4 -4
- package/dist/core/Nestjs/types/utils/enum.utils.d.ts +0 -0
- package/dist/core/Nestjs/types/utils/enum.utils.js +0 -0
- package/dist/core/Nestjs/types/utils/get-fields-and-decorator.util.d.ts +1 -11
- package/dist/core/Nestjs/types/utils/get-fields-and-decorator.util.js +0 -0
- package/dist/core/Nestjs/types/utils/mapped-types.utils.d.ts +0 -0
- package/dist/core/Nestjs/types/utils/mapped-types.utils.js +2 -2
- package/dist/core/Nestjs/types/utils/model-properties-accessor.d.ts +0 -0
- package/dist/core/Nestjs/types/utils/model-properties-accessor.js +0 -0
- package/dist/core/Nestjs/types/utils/type-helpers.utils.d.ts +0 -0
- package/dist/core/Nestjs/types/utils/type-helpers.utils.js +0 -0
- package/dist/core/types.d.ts +0 -0
- package/dist/core/types.js +0 -0
- package/dist/decorators.d.ts +25 -21
- package/dist/decorators.js +76 -70
- package/dist/generatorDatasource.d.ts +0 -0
- package/dist/generatorDatasource.js +0 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.js +5 -7
- package/dist/loadRelations.d.ts +0 -0
- package/dist/loadRelations.js +108 -68
- package/dist/outputKeys.d.ts +0 -0
- package/dist/outputKeys.js +0 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +104 -60
- package/dist/types.js +20 -0
- package/package.json +12 -101
- package/dist/TypeOrmConnector/TypeOrmMongoConnector._bypass.d.ts +0 -1
- package/dist/TypeOrmConnector/TypeOrmMongoConnector._bypass.js +0 -52
- package/dist/TypeOrmConnector/TypeOrmMysqlConnector._bypass.d.ts +0 -1
- package/dist/TypeOrmConnector/TypeOrmMysqlConnector._bypass.js +0 -55
- package/dist/TypeOrmConnector/test/basic/goat.dto.d.ts +0 -8
- package/dist/TypeOrmConnector/test/basic/goat.dto.js +0 -18
- package/dist/TypeOrmConnector/test/relations/car/car.dto.d.ts +0 -5
- package/dist/TypeOrmConnector/test/relations/car/car.dto.js +0 -12
- package/dist/TypeOrmConnector/test/relations/roles/role.dto.d.ts +0 -5
- package/dist/TypeOrmConnector/test/relations/roles/role.dto.js +0 -12
- package/dist/TypeOrmConnector/test/relations/roles/roles_user.dto.d.ts +0 -5
- package/dist/TypeOrmConnector/test/relations/roles/roles_user.dto.js +0 -12
- package/dist/TypeOrmConnector/test/relations/user/user.dto.d.ts +0 -5
- package/dist/TypeOrmConnector/test/relations/user/user.dto.js +0 -12
- package/dist/core/dtos/access.dto.d.ts +0 -4
- package/dist/core/dtos/access.dto.js +0 -21
- package/dist/core/dtos/pagination.dto.d.ts +0 -13
- package/dist/core/dtos/pagination.dto.js +0 -62
package/dist/BaseConnector.js
CHANGED
|
@@ -1,306 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseConnector = void 0;
|
|
4
|
-
const typed_path_1 = require("typed-path");
|
|
5
4
|
const js_utils_1 = require("@goatlab/js-utils");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const bson_1 = require("bson");
|
|
8
7
|
class BaseConnector {
|
|
9
8
|
constructor() {
|
|
10
|
-
this.generatedKeyPath = (0, typed_path_1.typedPath)();
|
|
11
|
-
this.chainReference = [];
|
|
12
|
-
this.whereArray = [];
|
|
13
|
-
this.orWhereArray = [];
|
|
14
|
-
this.selectArray = [];
|
|
15
|
-
this.forceSelectArray = [];
|
|
16
|
-
this.orderByArray = [];
|
|
17
|
-
this.limitNumber = 0;
|
|
18
|
-
this.offsetNumber = 0;
|
|
19
|
-
this.populateArray = [];
|
|
20
9
|
this.chunk = null;
|
|
21
10
|
this.pullSize = null;
|
|
22
|
-
this.ownerId = undefined;
|
|
23
11
|
this.paginator = undefined;
|
|
24
12
|
this.rawQuery = undefined;
|
|
25
|
-
this.getFirst = false;
|
|
26
|
-
this.relations = undefined;
|
|
27
|
-
this.loadModels = false;
|
|
28
|
-
this.chainReference = [];
|
|
29
|
-
this.whereArray = [];
|
|
30
|
-
this.orWhereArray = [];
|
|
31
|
-
this.selectArray = [];
|
|
32
|
-
this.forceSelectArray = [];
|
|
33
|
-
this.orderByArray = [];
|
|
34
|
-
this.limitNumber = undefined;
|
|
35
|
-
this.offsetNumber = undefined;
|
|
36
|
-
this.populateArray = [];
|
|
37
13
|
this.chunk = null;
|
|
38
14
|
this.pullSize = null;
|
|
39
|
-
this.ownerId = undefined;
|
|
40
15
|
this.paginator = undefined;
|
|
41
16
|
this.rawQuery = undefined;
|
|
42
17
|
this.outputKeys = [];
|
|
43
|
-
this.getFirst = false;
|
|
44
18
|
}
|
|
45
|
-
async findByIds(ids) {
|
|
19
|
+
async findByIds(ids, q) {
|
|
46
20
|
throw new Error('findByIds() method not implemented');
|
|
47
21
|
}
|
|
48
|
-
async get() {
|
|
49
|
-
throw new Error('get() method not implemented');
|
|
50
|
-
}
|
|
51
22
|
async insertMany(data) {
|
|
52
23
|
throw new Error('get() method not implemented');
|
|
53
24
|
}
|
|
54
25
|
async updateById(id, data) {
|
|
55
26
|
throw new Error('get() method not implemented');
|
|
56
27
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.ownerId = user;
|
|
60
|
-
return this;
|
|
28
|
+
async findMany(query) {
|
|
29
|
+
throw new Error('findMany() method not implemented');
|
|
61
30
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
async first() {
|
|
66
|
-
this.limit(1);
|
|
67
|
-
const data = await this.get();
|
|
31
|
+
async findFirst(query) {
|
|
32
|
+
const data = await this.findMany({ ...query, limit: 1 });
|
|
68
33
|
if (!data[0]) {
|
|
69
34
|
return null;
|
|
70
35
|
}
|
|
71
36
|
return data[0];
|
|
72
37
|
}
|
|
73
|
-
async collect() {
|
|
74
|
-
const data = await this.
|
|
38
|
+
async collect(query) {
|
|
39
|
+
const data = await this.findMany(query);
|
|
75
40
|
if (!Array.isArray(data)) {
|
|
76
|
-
|
|
41
|
+
return new js_utils_1.Collection([data]);
|
|
77
42
|
}
|
|
78
43
|
return new js_utils_1.Collection(data);
|
|
79
44
|
}
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
const columns = this.prepareInput(cols);
|
|
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(paths) {
|
|
91
|
-
if (typeof module === 'undefined' || !module.exports) {
|
|
92
|
-
throw new Error('forceSelect cant be used in frontend');
|
|
93
|
-
}
|
|
94
|
-
const arrCols = paths(this.generatedKeyPath);
|
|
95
|
-
const cols = arrCols.map(c => c.toString());
|
|
96
|
-
const columns = this.prepareInput(cols);
|
|
97
|
-
this.chainReference.push({ method: 'forceSelect', args: columns });
|
|
98
|
-
this.forceSelectArray = this.forceSelectArray
|
|
99
|
-
.concat(columns)
|
|
100
|
-
.filter((elem, pos, arr) => arr.indexOf(elem) === pos);
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
offset(offset) {
|
|
104
|
-
this.chainReference.push({ method: 'offset', args: offset });
|
|
105
|
-
this.offsetNumber = offset;
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
populate(...relations) {
|
|
109
|
-
this.chainReference.push({ method: 'relations', args: relations });
|
|
110
|
-
this.populateArray = relations;
|
|
111
|
-
return this;
|
|
112
|
-
}
|
|
113
|
-
skip(offset) {
|
|
114
|
-
return this.offset(offset);
|
|
115
|
-
}
|
|
116
|
-
where(path, operator, value) {
|
|
117
|
-
const stringP = path(this.generatedKeyPath);
|
|
118
|
-
const stringPath = stringP.toString();
|
|
119
|
-
const chainedWhere = [stringPath, operator, value];
|
|
120
|
-
this.chainReference.push({ method: 'where', chainedWhere });
|
|
121
|
-
this.whereArray = [];
|
|
122
|
-
this.whereArray.push(chainedWhere);
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
andWhere(path, operator, value) {
|
|
126
|
-
const stringP = path(this.generatedKeyPath);
|
|
127
|
-
const stringPath = stringP.toString();
|
|
128
|
-
const chainedWhere = [stringPath, operator, value];
|
|
129
|
-
this.chainReference.push({ method: 'andWhere', chainedWhere });
|
|
130
|
-
this.whereArray.push(chainedWhere);
|
|
131
|
-
return this;
|
|
132
|
-
}
|
|
133
|
-
orWhere(path, operator, value) {
|
|
134
|
-
const stringP = path(this.generatedKeyPath);
|
|
135
|
-
const stringPath = stringP.toString();
|
|
136
|
-
const chainedWhere = [stringPath, operator, value];
|
|
137
|
-
this.chainReference.push({ method: 'orWhere', chainedWhere });
|
|
138
|
-
this.orWhereArray.push(chainedWhere);
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
limit(limit) {
|
|
142
|
-
this.chainReference.push({ method: 'limit', args: limit });
|
|
143
|
-
this.limitNumber = limit;
|
|
144
|
-
return this;
|
|
145
|
-
}
|
|
146
|
-
take(limit) {
|
|
147
|
-
return this.limit(limit);
|
|
148
|
-
}
|
|
149
|
-
async pluck(path) {
|
|
150
|
-
const stringP = path(this.generatedKeyPath);
|
|
151
|
-
const stringPath = stringP.toString();
|
|
152
|
-
this.chainReference.push({ method: 'pluck', args: stringPath });
|
|
153
|
-
const data = await this.get();
|
|
45
|
+
async pluck(path, query) {
|
|
46
|
+
const data = await this.findMany(query);
|
|
47
|
+
const paths = Object.keys(js_utils_1.Objects.flatten(path));
|
|
154
48
|
const result = data.map(e => {
|
|
155
|
-
const extracted = js_utils_1.Objects.getFromPath(e, String(
|
|
49
|
+
const extracted = js_utils_1.Objects.getFromPath(e, String(paths[0]), undefined);
|
|
156
50
|
if (typeof extracted.value !== 'undefined') {
|
|
157
51
|
return extracted.value;
|
|
158
52
|
}
|
|
159
53
|
});
|
|
160
54
|
return result;
|
|
161
55
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const stringPath = stringP.toString();
|
|
165
|
-
const orderB = [stringPath, order, orderType];
|
|
166
|
-
this.chainReference.push({ method: 'orderBy', orderB });
|
|
167
|
-
this.orderByArray = orderB;
|
|
168
|
-
return this;
|
|
169
|
-
}
|
|
170
|
-
jsApplySelect(data) {
|
|
171
|
-
const _data = Array.isArray(data) ? [...data] : [data];
|
|
172
|
-
if (this.selectArray.length <= 0 && this.outputKeys.length <= 0) {
|
|
173
|
-
return _data;
|
|
174
|
-
}
|
|
175
|
-
const iterationArray = this.outputKeys.length === 0 && this.selectArray.length > 0
|
|
176
|
-
? this.selectArray
|
|
177
|
-
: [...this.outputKeys, ...this.forceSelectArray];
|
|
178
|
-
const compareArray = this.outputKeys.length === 0 && this.selectArray.length > 0
|
|
179
|
-
? [...this.outputKeys, ...this.forceSelectArray]
|
|
180
|
-
: this.selectArray;
|
|
181
|
-
return _data.map(element => {
|
|
182
|
-
const newElement = {};
|
|
183
|
-
iterationArray.forEach(attribute => {
|
|
184
|
-
if (compareArray.length > 0 && !compareArray.includes(attribute)) {
|
|
185
|
-
return undefined;
|
|
186
|
-
}
|
|
187
|
-
const extract = js_utils_1.Objects.getFromPath(element, attribute, undefined);
|
|
188
|
-
let value = js_utils_1.Objects.get(() => extract.value, undefined);
|
|
189
|
-
if (typeof value !== 'undefined' && value !== null) {
|
|
190
|
-
if (typeof value === 'object' &&
|
|
191
|
-
value.hasOwnProperty('data') &&
|
|
192
|
-
value.data.hasOwnProperty('name')) {
|
|
193
|
-
newElement[extract.label] = value.data.name;
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
if (typeof value === 'object' && js_utils_1.Ids.isValidObjectID(value)) {
|
|
197
|
-
value = js_utils_1.Ids.objectIdString(value);
|
|
198
|
-
}
|
|
199
|
-
newElement[extract.label] = value;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
return js_utils_1.Objects.nest(newElement);
|
|
204
|
-
});
|
|
56
|
+
setRelatedQuery(r) {
|
|
57
|
+
this.relatedQuery = r;
|
|
205
58
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return _data;
|
|
210
|
-
}
|
|
211
|
-
const field = this.orderByArray[0];
|
|
212
|
-
if (this.selectArray.length > 0 &&
|
|
213
|
-
(field.includes('.') || field.includes('['))) {
|
|
214
|
-
throw new Error(`Cannot orderBy nested attribute "${field}" when using Select. You must rename the attribute`);
|
|
215
|
-
}
|
|
216
|
-
const order = this.orderByArray[1];
|
|
217
|
-
let type = this.orderByArray[2];
|
|
218
|
-
if (!type) {
|
|
219
|
-
type = 'string';
|
|
59
|
+
async associate(data) {
|
|
60
|
+
if (!this.relatedQuery?.entity || !this.relatedQuery.key) {
|
|
61
|
+
throw new Error('Associate can only be called as a related model');
|
|
220
62
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (typeof A === 'undefined' || typeof B === 'undefined') {
|
|
225
|
-
throw new Error(`Cannot order by property "${field}" not all values have this property`);
|
|
226
|
-
}
|
|
227
|
-
if (type.includes('string') || type.includes('number')) {
|
|
228
|
-
if (order === 'asc') {
|
|
229
|
-
return A > B ? 1 : A < B ? -1 : 0;
|
|
230
|
-
}
|
|
231
|
-
return A > B ? -1 : A < B ? 1 : 0;
|
|
232
|
-
}
|
|
233
|
-
if (type.includes('date')) {
|
|
234
|
-
if (order === 'asc') {
|
|
235
|
-
return new Date(A).getTime() - new Date(B).getTime();
|
|
236
|
-
}
|
|
237
|
-
return new Date(B).getTime() - new Date(A).getTime();
|
|
238
|
-
}
|
|
63
|
+
const parentData = await this.relatedQuery.repository.findMany({
|
|
64
|
+
...this.relatedQuery.query,
|
|
65
|
+
select: { id: true }
|
|
239
66
|
});
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this.whereArray = [];
|
|
245
|
-
this.orWhereArray = [];
|
|
246
|
-
this.selectArray = [];
|
|
247
|
-
this.forceSelectArray = [];
|
|
248
|
-
this.orderByArray = [];
|
|
249
|
-
this.limitNumber = undefined;
|
|
250
|
-
this.offsetNumber = undefined;
|
|
251
|
-
this.populateArray = [];
|
|
252
|
-
this.chunk = null;
|
|
253
|
-
this.pullSize = null;
|
|
254
|
-
this.ownerId = undefined;
|
|
255
|
-
this.paginator = undefined;
|
|
256
|
-
this.rawQuery = undefined;
|
|
257
|
-
this.getFirst = false;
|
|
258
|
-
this.relations = undefined;
|
|
259
|
-
this.loadModels = false;
|
|
260
|
-
this.relationQuery = undefined;
|
|
261
|
-
}
|
|
262
|
-
async load() {
|
|
263
|
-
const result = await this.get();
|
|
264
|
-
this.relationQuery = {
|
|
265
|
-
data: result,
|
|
266
|
-
relations: this.modelRelations
|
|
267
|
-
};
|
|
268
|
-
return this;
|
|
269
|
-
}
|
|
270
|
-
async loadFirst() {
|
|
271
|
-
const result = await this.first();
|
|
272
|
-
this.relationQuery = {
|
|
273
|
-
data: result,
|
|
274
|
-
relations: this.modelRelations
|
|
275
|
-
};
|
|
276
|
-
return this;
|
|
277
|
-
}
|
|
278
|
-
getLoadedData() {
|
|
279
|
-
return this.relationQuery.data;
|
|
280
|
-
}
|
|
281
|
-
with(entities) {
|
|
282
|
-
this.relations = entities;
|
|
283
|
-
return this;
|
|
284
|
-
}
|
|
285
|
-
async attach(data) {
|
|
286
|
-
if (!this.relationQuery.relation || !this.relationQuery.data) {
|
|
287
|
-
throw new Error('Attached can only be called as a related model');
|
|
67
|
+
const foreignKeyName = this.relatedQuery['repository']['modelRelations'][this.relatedQuery.key]
|
|
68
|
+
.inverseSidePropertyPath;
|
|
69
|
+
if (!foreignKeyName) {
|
|
70
|
+
throw new Error('The relationship was not properly defined. Please check that your Repository and Model relations have the same keys');
|
|
288
71
|
}
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
? this.relationQuery.data
|
|
292
|
-
: [this.relationQuery.data];
|
|
293
|
-
const relatedData = D.map(d => ({
|
|
294
|
-
[foreignKeyName]: this.isMongoDB
|
|
295
|
-
? js_utils_1.Ids.objectID(d.id)
|
|
296
|
-
: d.id,
|
|
72
|
+
const relatedData = parentData.map(r => ({
|
|
73
|
+
[foreignKeyName]: r.id,
|
|
297
74
|
...data
|
|
298
75
|
}));
|
|
299
|
-
const
|
|
76
|
+
const existingIds = this.clearEmpties(relatedData.map(r => r.id));
|
|
77
|
+
const existingData = existingIds.length
|
|
78
|
+
? await this.findByIds(relatedData.map(r => r.id))
|
|
79
|
+
: [];
|
|
300
80
|
const updateQueries = [];
|
|
301
81
|
const insertQueries = [];
|
|
302
82
|
for (const related of relatedData) {
|
|
303
|
-
const exists = existingData.find(d => d.id === related.id);
|
|
83
|
+
const exists = existingData.find((d) => d.id === related.id);
|
|
304
84
|
if (exists) {
|
|
305
85
|
updateQueries.push(this.updateById(exists.id, {
|
|
306
86
|
...exists,
|
|
@@ -315,88 +95,208 @@ class BaseConnector {
|
|
|
315
95
|
const insertedResult = await this.insertMany(insertQueries);
|
|
316
96
|
return [...updateResult, ...insertedResult];
|
|
317
97
|
}
|
|
318
|
-
|
|
319
|
-
if (!this.
|
|
98
|
+
async attach(id) {
|
|
99
|
+
if (!this.relatedQuery?.entity || !this.relatedQuery.key) {
|
|
320
100
|
throw new Error('Associate can only be called as a related model');
|
|
321
101
|
}
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
:
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
102
|
+
const parentData = await this.relatedQuery.repository.findMany({
|
|
103
|
+
...this.relatedQuery.query,
|
|
104
|
+
select: { id: true }
|
|
105
|
+
});
|
|
106
|
+
const foreignKeyName = this.relatedQuery['repository']['modelRelations'][this.relatedQuery.key]
|
|
107
|
+
.joinColumns[0].propertyPath;
|
|
108
|
+
const inverseKeyName = this.relatedQuery['repository']['modelRelations'][this.relatedQuery.key]
|
|
109
|
+
.inverseJoinColumns[0].propertyPath;
|
|
110
|
+
if (!foreignKeyName || !inverseKeyName) {
|
|
111
|
+
throw new Error(`The relationship was not properly defined. Please check that your Repository and Model relations have the same keys: Searching for: ${this.relatedQuery.key}`);
|
|
112
|
+
}
|
|
113
|
+
const relatedData = parentData.map(d => ({
|
|
114
|
+
[foreignKeyName]: d.id,
|
|
115
|
+
[inverseKeyName]: id
|
|
334
116
|
}));
|
|
335
|
-
return this.
|
|
336
|
-
}
|
|
337
|
-
hasMany(
|
|
338
|
-
|
|
339
|
-
|
|
117
|
+
return this.relatedQuery.pivot.insertMany(relatedData);
|
|
118
|
+
}
|
|
119
|
+
hasMany(r) {
|
|
120
|
+
const newRepo = new r.repository();
|
|
121
|
+
const calleeName = new Error('dummy')
|
|
122
|
+
.stack.split('\n')[2]
|
|
123
|
+
.replace(/^\s+at\s+(.+?)\s.+/g, '$1')
|
|
124
|
+
.split('.')[1];
|
|
125
|
+
if (this.relatedQuery) {
|
|
126
|
+
newRepo.setRelatedQuery({
|
|
127
|
+
...this.relatedQuery,
|
|
128
|
+
key: calleeName
|
|
129
|
+
});
|
|
340
130
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
131
|
+
return newRepo;
|
|
132
|
+
}
|
|
133
|
+
belongsTo(r) {
|
|
134
|
+
return this.hasMany(r);
|
|
344
135
|
}
|
|
345
136
|
hasOne() {
|
|
346
137
|
throw new Error('Method not implemented');
|
|
347
138
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
139
|
+
belongsToMany(r) {
|
|
140
|
+
const newRepo = new r.repository();
|
|
141
|
+
const relationName = new Error('dummy')
|
|
142
|
+
.stack.split('\n')[2]
|
|
143
|
+
.replace(/^\s+at\s+(.+?)\s.+/g, '$1')
|
|
144
|
+
.split('.')[1];
|
|
145
|
+
const pivot = new r.pivot();
|
|
146
|
+
pivot.setRelatedQuery({
|
|
147
|
+
...this.relatedQuery,
|
|
148
|
+
key: relationName
|
|
149
|
+
});
|
|
150
|
+
if (this.relatedQuery) {
|
|
151
|
+
newRepo.setRelatedQuery({
|
|
152
|
+
...this.relatedQuery,
|
|
153
|
+
key: relationName,
|
|
154
|
+
pivot
|
|
155
|
+
});
|
|
351
156
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
this.relationQuery = !this.relationQuery
|
|
358
|
-
? { pivot: new Pivot(this.relationQuery) }
|
|
359
|
-
: {
|
|
360
|
-
...this.relationQuery,
|
|
361
|
-
...{
|
|
362
|
-
pivot: new Pivot(this.relationQuery),
|
|
363
|
-
relation: this.relationQuery.relations[relationName]
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
const newClass = new Repository(this.relationQuery);
|
|
367
|
-
this.reset();
|
|
368
|
-
return newClass;
|
|
369
|
-
}
|
|
370
|
-
withPivot() {
|
|
371
|
-
if (this.relationQuery?.pivot) {
|
|
372
|
-
this.relationQuery.returnPivot = true;
|
|
157
|
+
else {
|
|
158
|
+
newRepo.setRelatedQuery({
|
|
159
|
+
key: relationName,
|
|
160
|
+
pivot
|
|
161
|
+
});
|
|
373
162
|
}
|
|
374
|
-
return
|
|
163
|
+
return newRepo;
|
|
375
164
|
}
|
|
376
165
|
hasManyThrough() {
|
|
377
166
|
throw new Error('Method not implemented');
|
|
378
167
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
168
|
+
clearEmpties(object) {
|
|
169
|
+
Object.entries(object).forEach(([k, v]) => {
|
|
170
|
+
if (v && typeof v === 'object')
|
|
171
|
+
this.clearEmpties(v);
|
|
172
|
+
if ((v && typeof v === 'object' && !Object.keys(v).length) ||
|
|
173
|
+
v === null ||
|
|
174
|
+
v === undefined ||
|
|
175
|
+
v.length === 0) {
|
|
176
|
+
if (Array.isArray(object)) {
|
|
177
|
+
if (!(object[k] instanceof bson_1.ObjectId)) {
|
|
178
|
+
object.splice(k, 1);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else if (!(v instanceof Date) && !(v instanceof bson_1.ObjectId)) {
|
|
182
|
+
delete object[k];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
383
185
|
});
|
|
384
|
-
|
|
385
|
-
|
|
186
|
+
return object;
|
|
187
|
+
}
|
|
188
|
+
isAnyObject(val) {
|
|
189
|
+
return typeof val === 'object' && !Array.isArray(val) && val !== null;
|
|
190
|
+
}
|
|
191
|
+
extractConditions(conditions) {
|
|
192
|
+
const accumulatedClauses = [];
|
|
193
|
+
if (!conditions) {
|
|
194
|
+
return accumulatedClauses;
|
|
195
|
+
}
|
|
196
|
+
for (const clause of conditions) {
|
|
197
|
+
if (!clause) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
for (const el of Object.keys(clause)) {
|
|
201
|
+
const value = clause[el];
|
|
202
|
+
if (this.isAnyObject(value)) {
|
|
203
|
+
const initialKey = el;
|
|
204
|
+
const flatten = js_utils_1.Objects.flatten(value);
|
|
205
|
+
for (const key of Object.keys(flatten)) {
|
|
206
|
+
const transformedKey = key.replace(new RegExp('.[0-9]', 'g'), '');
|
|
207
|
+
if (types_1.LogicOperator[transformedKey]) {
|
|
208
|
+
if (types_1.LogicOperator[transformedKey] === types_1.LogicOperator.in ||
|
|
209
|
+
types_1.LogicOperator[transformedKey] === types_1.LogicOperator.notIn) {
|
|
210
|
+
accumulatedClauses.push({
|
|
211
|
+
operator: types_1.LogicOperator[transformedKey],
|
|
212
|
+
element: `${initialKey}`,
|
|
213
|
+
value: value[transformedKey]
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
accumulatedClauses.push({
|
|
218
|
+
operator: types_1.LogicOperator[transformedKey],
|
|
219
|
+
element: `${initialKey}`,
|
|
220
|
+
value: flatten[key]
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else if (transformedKey.includes('.')) {
|
|
225
|
+
const op = key.split('.').slice(-1).pop();
|
|
226
|
+
if (!op) {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (types_1.LogicOperator[op]) {
|
|
230
|
+
accumulatedClauses.push({
|
|
231
|
+
operator: types_1.LogicOperator[op],
|
|
232
|
+
element: `${initialKey}.${key.replace(`.${op}`, '')}`,
|
|
233
|
+
value: flatten[key]
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
accumulatedClauses.push({
|
|
238
|
+
operator: types_1.LogicOperator.equals,
|
|
239
|
+
element: `${initialKey}.${key}`,
|
|
240
|
+
value: flatten[key]
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
accumulatedClauses.push({
|
|
246
|
+
operator: types_1.LogicOperator.equals,
|
|
247
|
+
element: `${initialKey}.${transformedKey}`,
|
|
248
|
+
value: flatten[key]
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
accumulatedClauses.push({
|
|
255
|
+
operator: types_1.LogicOperator.equals,
|
|
256
|
+
element: el,
|
|
257
|
+
value
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return accumulatedClauses;
|
|
386
263
|
}
|
|
387
|
-
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
264
|
+
jsApplySelect(select, data) {
|
|
265
|
+
const _data = Array.isArray(data) ? [...data] : [data];
|
|
266
|
+
if (!select) {
|
|
267
|
+
return data;
|
|
268
|
+
}
|
|
269
|
+
const selectedAttributes = Object.keys(js_utils_1.Objects.flatten(select));
|
|
270
|
+
const iterationArray = this.outputKeys.length === 0 && selectedAttributes.length > 0
|
|
271
|
+
? selectedAttributes
|
|
272
|
+
: [...this.outputKeys];
|
|
273
|
+
const compareArray = this.outputKeys.length === 0 && selectedAttributes.length > 0
|
|
274
|
+
? [...this.outputKeys]
|
|
275
|
+
: selectedAttributes;
|
|
276
|
+
return _data.map(element => {
|
|
277
|
+
const newElement = {};
|
|
278
|
+
iterationArray.forEach(attribute => {
|
|
279
|
+
if (compareArray.length > 0 && !compareArray.includes(attribute)) {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
const extract = js_utils_1.Objects.getFromPath(element, attribute, undefined);
|
|
283
|
+
let value = js_utils_1.Objects.get(() => extract.value, undefined);
|
|
284
|
+
if (typeof value !== 'undefined' && value !== null) {
|
|
285
|
+
if (typeof value === 'object' &&
|
|
286
|
+
value.hasOwnProperty('data') &&
|
|
287
|
+
value.data.hasOwnProperty('name')) {
|
|
288
|
+
newElement[extract.label] = value.data.name;
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
if (typeof value === 'object' && js_utils_1.Ids.isValidObjectID(value)) {
|
|
292
|
+
value = js_utils_1.Ids.objectIdString(value);
|
|
293
|
+
}
|
|
294
|
+
newElement[extract.label] = value;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
return js_utils_1.Objects.nest(newElement);
|
|
299
|
+
});
|
|
400
300
|
}
|
|
401
301
|
}
|
|
402
302
|
exports.BaseConnector = BaseConnector;
|
package/dist/Fluent.d.ts
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
import { DataSource } from 'typeorm';
|
|
2
|
-
import {
|
|
2
|
+
import { AnyObject, Primitives } from './types';
|
|
3
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
4
|
export declare class Fluent {
|
|
20
|
-
|
|
21
|
-
static model<T = BaseDataElement>(name: string): any;
|
|
22
|
-
static collect<T = BaseDataElement | Primitives>(data: T[]): Collection<T>;
|
|
23
|
-
static getConfig(): _FLUENT_;
|
|
5
|
+
static collect<T = AnyObject | Primitives>(data: T[]): Collection<T>;
|
|
24
6
|
static initialize(dataSources: DataSource[], Entities: any[]): Promise<void>;
|
|
25
7
|
}
|
|
26
|
-
export {};
|