UNPKG

2.69 kBJavaScriptView Raw
1"use strict";
2// Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
3// Node module: @loopback/repository
4// This file is licensed under the MIT License.
5// License text available at https://opensource.org/licenses/MIT
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.createHasManyThroughRepositoryFactory = void 0;
8const has_many_through_helpers_1 = require("./has-many-through.helpers");
9const has_many_through_inclusion_resolver_1 = require("./has-many-through.inclusion-resolver");
10const has_many_through_repository_1 = require("./has-many-through.repository");
11function createHasManyThroughRepositoryFactory(relationMetadata, targetRepositoryGetter, throughRepositoryGetter) {
12 const meta = (0, has_many_through_helpers_1.resolveHasManyThroughMetadata)(relationMetadata);
13 // resolve the repositoryGetter into a dictionary
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}
42exports.createHasManyThroughRepositoryFactory = createHasManyThroughRepositoryFactory;
43//# sourceMappingURL=has-many-through.repository-factory.js.map
\No newline at end of file