1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.createHasManyThroughRepositoryFactory = void 0;
|
8 | const has_many_through_helpers_1 = require("./has-many-through.helpers");
|
9 | const has_many_through_inclusion_resolver_1 = require("./has-many-through.inclusion-resolver");
|
10 | const has_many_through_repository_1 = require("./has-many-through.repository");
|
11 | function createHasManyThroughRepositoryFactory(relationMetadata, targetRepositoryGetter, throughRepositoryGetter) {
|
12 | const meta = (0, has_many_through_helpers_1.resolveHasManyThroughMetadata)(relationMetadata);
|
13 |
|
14 | if (typeof targetRepositoryGetter === 'function') {
|
15 | targetRepositoryGetter = {
|
16 | [meta.target().name]: targetRepositoryGetter,
|
17 | };
|
18 | }
|
19 | const result = function (fkValue) {
|
20 | function getTargetConstraintFromThroughModels(throughInstances) {
|
21 | return (0, has_many_through_helpers_1.createTargetConstraintFromThrough)(meta, throughInstances);
|
22 | }
|
23 | function getTargetKeys(throughInstances) {
|
24 | return (0, has_many_through_helpers_1.getTargetKeysFromThroughModels)(meta, throughInstances);
|
25 | }
|
26 | function getThroughConstraintFromSource() {
|
27 | const constraint = (0, has_many_through_helpers_1.createThroughConstraintFromSource)(meta, fkValue);
|
28 | return constraint;
|
29 | }
|
30 | function getTargetIds(targetInstances) {
|
31 | return (0, has_many_through_helpers_1.getTargetIdsFromTargetModels)(meta, targetInstances);
|
32 | }
|
33 | function getThroughConstraintFromTarget(fkValues) {
|
34 | const constraint = (0, has_many_through_helpers_1.createThroughConstraintFromTarget)(meta, fkValues);
|
35 | return constraint;
|
36 | }
|
37 | return new has_many_through_repository_1.DefaultHasManyThroughRepository(targetRepositoryGetter, throughRepositoryGetter, getTargetConstraintFromThroughModels, getTargetKeys, getThroughConstraintFromSource, getTargetIds, getThroughConstraintFromTarget, relationMetadata.target, relationMetadata.through.model);
|
38 | };
|
39 | result.inclusionResolver = (0, has_many_through_inclusion_resolver_1.createHasManyThroughInclusionResolver)(meta, throughRepositoryGetter, targetRepositoryGetter);
|
40 | return result;
|
41 | }
|
42 | exports.createHasManyThroughRepositoryFactory = createHasManyThroughRepositoryFactory;
|
43 |
|
\ | No newline at end of file |