UNPKG

2.63 kBTypeScriptView Raw
1import { Getter } from '@loopback/core';
2import { TypeResolver } from '../../';
3import { DataObject, Options } from '../../common-types';
4import { Entity } from '../../model';
5import { EntityCrudRepository } from '../../repositories';
6/**
7 * CRUD operations for a target repository of a BelongsTo relation
8 */
9export interface BelongsToRepository<Target extends Entity> {
10 /**
11 * Gets the target model instance
12 * @param options
13 * options.polymorphicType - a string or a string array of polymorphic type names
14 * to specify which repositories should are expected to be searched
15 * It is highly recommended to contain this param especially for
16 * datasources using deplicated ids across tables
17 * @returns A promise resolved with the target object or rejected
18 * with an EntityNotFoundError when target model instance was not found.
19 */
20 get(options?: Options & {
21 polymorphicType?: string | string[];
22 }): Promise<Target>;
23}
24export declare class DefaultBelongsToRepository<TargetEntity extends Entity, TargetId, TargetRepository extends EntityCrudRepository<TargetEntity, TargetId>> implements BelongsToRepository<TargetEntity> {
25 getTargetRepository: Getter<TargetRepository> | {
26 [repoType: string]: Getter<TargetRepository>;
27 };
28 constraint: DataObject<TargetEntity>;
29 targetResolver: TypeResolver<Entity, typeof Entity>;
30 /**
31 * Constructor of DefaultBelongsToEntityCrudRepository
32 * @param getTargetRepository - either a dictionary of target model type - target repository instance
33 * or a single target repository instance
34 * e.g. if the target is of a non-polymorphic type "Student", put the studentRepositoryGetterInstance
35 * if the target is of a polymorphic type "Person" which can be either a "Student" or a "Teacher"
36 * then put "{Student: studentRepositoryGetterInstance, Teacher: teacherRepositoryGetterInstance}"
37 * @param constraint - the key value pair representing foreign key name to constrain
38 * the target repository instance
39 * @param targetResolver - () => Target to resolve the target class
40 * e.g. if the target is of type "Student", then put "() => Student"
41 */
42 constructor(getTargetRepository: Getter<TargetRepository> | {
43 [repoType: string]: Getter<TargetRepository>;
44 }, constraint: DataObject<TargetEntity>, targetResolver: TypeResolver<Entity, typeof Entity>);
45 getTargetRepositoryDict: {
46 [repoType: string]: Getter<TargetRepository>;
47 };
48 get(options?: Options & {
49 polymorphicType?: string | string[];
50 }): Promise<TargetEntity>;
51}