1 | import { Entity } from '../../model';
|
2 | import { EntityCrudRepository } from '../../repositories';
|
3 | import { Getter, HasOneDefinition, InclusionResolver } from '../relation.types';
|
4 | import { HasOneRepository } from './has-one.repository';
|
5 | export interface HasOneRepositoryFactory<Target extends Entity, ForeignKeyType> {
|
6 | /**
|
7 | * Invoke the function to obtain HasOneRepository.
|
8 | */
|
9 | (fkValue: ForeignKeyType): HasOneRepository<Target>;
|
10 | /**
|
11 | * Use `resolver` property to obtain an InclusionResolver for this relation.
|
12 | */
|
13 | inclusionResolver: InclusionResolver<Entity, Target>;
|
14 | }
|
15 | /**
|
16 | * Enforces a constraint on a repository based on a relationship contract
|
17 | * between models. For example, if a Customer model is related to an Address model
|
18 | * via a HasOne relation, then, the relational repository returned by the
|
19 | * factory function would be constrained by a Customer model instance's id(s).
|
20 | *
|
21 | * If the target model is polymorphic, i.e. stored within different repositories,
|
22 | * supply the targetRepositoryGetter with a dictionary in the form of {[typeName: string]: repositoryGetter}
|
23 | *
|
24 | * @param relationMetadata - The relation metadata used to describe the
|
25 | * relationship and determine how to apply the constraint.
|
26 | * @param targetRepositoryGetter - The repository or a dictionary of classname - repository,
|
27 | * which represents the target model of a relation attached to a datasource.
|
28 | * For the dictionary, the key is the class name of the concrete class the the polymorphic model.
|
29 | * @returns The factory function which accepts a foreign key value to constrain
|
30 | * the given target repository
|
31 | */
|
32 | export declare function createHasOneRepositoryFactory<Target extends Entity, TargetID, ForeignKeyType>(relationMetadata: HasOneDefinition, targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>> | {
|
33 | [repoType: string]: Getter<EntityCrudRepository<Target, TargetID>>;
|
34 | }): HasOneRepositoryFactory<Target, ForeignKeyType>;
|