UNPKG

7.87 kBTypeScriptView Raw
1import { Count, DataObject, Entity, EntityCrudRepository, Filter, Getter, Options, TypeResolver, Where } from '../..';
2/**
3 * CRUD operations for a target repository of a HasManyThrough relation
4 *
5 * EXPERIMENTAL: This interface is not stable and may change in the near future.
6 * Backwards-incompatible changes may be introduced in semver-minor versions.
7 */
8export interface HasManyThroughRepository<Target extends Entity, TargetID, Through extends Entity> {
9 /**
10 * Create a target model instance
11 * @param targetModelData - The target model data
12 * @param options - Options for the operation
13 * options.polymorphicType a string or a string array of polymorphic type names
14 * specify of which concrete model the created instance should be
15 * @returns A promise which resolves to the newly created target model instance
16 */
17 create(targetModelData: DataObject<Target>, options?: Options & {
18 throughData?: DataObject<Through>;
19 throughOptions?: Options;
20 } & {
21 polymorphicType?: string;
22 }): Promise<Target>;
23 /**
24 * Find target model instance(s)
25 * @param filter - A filter object for where, order, limit, etc.
26 * @param options - Options for the operation
27 * options.throughOptions.discriminator - target discriminator field on through
28 * options.polymorphicType a string or a string array of polymorphic type names
29 * to specify which repositories should are expected to be searched
30 * It is highly recommended to contain this param especially for
31 * datasources using deplicated ids across tables
32 * @returns A promise which resolves with the found target instance(s)
33 */
34 find(filter?: Filter<Target>, options?: Options & {
35 throughOptions?: Options & {
36 discriminator?: string;
37 };
38 } & {
39 polymorphicType?: string | string[];
40 }): Promise<Target[]>;
41 /**
42 * Delete multiple target model instances
43 * @param where - Instances within the where scope are deleted
44 * @param options
45 * options.throughOptions.discriminator - target discriminator field on through
46 * options.polymorphicType a string or a string array of polymorphic type names
47 * to specify which repositories should are expected to be searched
48 * It is highly recommended to contain this param especially for
49 * datasources using deplicated ids across tables
50 * @returns A promise which resolves the deleted target model instances
51 */
52 delete(where?: Where<Target>, options?: Options & {
53 throughOptions?: Options & {
54 discriminator?: string;
55 };
56 } & {
57 polymorphicType?: string | string[];
58 }): Promise<Count>;
59 /**
60 * Patch multiple target model instances
61 * @param dataObject - The fields and their new values to patch
62 * @param where - Instances within the where scope are patched
63 * @param options
64 * options.throughOptions.discriminator - target discriminator field on through
65 * options.isPolymorphic - whether dataObject is a dictionary
66 * @returns A promise which resolves the patched target model instances
67 */
68 patch(dataObject: DataObject<Target> | {
69 [polymorphicType: string]: DataObject<Target>;
70 }, where?: Where<Target>, options?: Options & {
71 throughOptions?: Options & {
72 discriminator?: string;
73 };
74 } & {
75 isPolymorphic?: boolean;
76 }): Promise<Count>;
77 /**
78 * Creates a new many-to-many association to an existing target model instance
79 * @param targetModelId - The target model ID to link
80 * @param options
81 * @returns A promise which resolves to the linked target model instance
82 */
83 link(targetModelId: TargetID, options?: Options & {
84 throughData?: DataObject<Through>;
85 throughOptions?: Options;
86 }): Promise<void>;
87 /**
88 * Removes an association to an existing target model instance
89 * @param targetModelId - The target model to unlink
90 * @param options
91 * @returns A promise which resolves to null
92 */
93 unlink(targetModelId: TargetID, options?: Options & {
94 throughOptions?: Options;
95 }): Promise<void>;
96 /**
97 * Remove all association to an existing target model instance
98 * @param options
99 * @return A promise which resolves to void
100 */
101 unlinkAll(options?: Options & {
102 throughOptions?: Options;
103 }): Promise<void>;
104}
105/**
106 * a class for CRUD operations for hasManyThrough relation.
107 *
108 * Warning: The hasManyThrough interface is experimental and is subject to change.
109 * If backwards-incompatible changes are made, a new major version may not be
110 * released.
111 */
112export declare class DefaultHasManyThroughRepository<TargetEntity extends Entity, TargetID, TargetRepository extends EntityCrudRepository<TargetEntity, TargetID>, ThroughEntity extends Entity, ThroughID, ThroughRepository extends EntityCrudRepository<ThroughEntity, ThroughID>> implements HasManyThroughRepository<TargetEntity, TargetID, ThroughEntity> {
113 getTargetRepository: Getter<TargetRepository> | {
114 [repoType: string]: Getter<TargetRepository>;
115 };
116 getThroughRepository: Getter<ThroughRepository>;
117 getTargetConstraintFromThroughModels: (throughInstances: ThroughEntity[]) => DataObject<TargetEntity>;
118 getTargetKeys: (throughInstances: ThroughEntity[]) => TargetID[];
119 getThroughConstraintFromSource: () => DataObject<ThroughEntity>;
120 getTargetIds: (targetInstances: TargetEntity[]) => TargetID[];
121 getThroughConstraintFromTarget: (targetID: TargetID[]) => DataObject<ThroughEntity>;
122 targetResolver: TypeResolver<Entity, typeof Entity>;
123 throughResolver: TypeResolver<Entity, typeof Entity>;
124 constructor(getTargetRepository: Getter<TargetRepository> | {
125 [repoType: string]: Getter<TargetRepository>;
126 }, getThroughRepository: Getter<ThroughRepository>, getTargetConstraintFromThroughModels: (throughInstances: ThroughEntity[]) => DataObject<TargetEntity>, getTargetKeys: (throughInstances: ThroughEntity[]) => TargetID[], getThroughConstraintFromSource: () => DataObject<ThroughEntity>, getTargetIds: (targetInstances: TargetEntity[]) => TargetID[], getThroughConstraintFromTarget: (targetID: TargetID[]) => DataObject<ThroughEntity>, targetResolver: TypeResolver<Entity, typeof Entity>, throughResolver: TypeResolver<Entity, typeof Entity>);
127 getTargetRepositoryDict: {
128 [repoType: string]: Getter<TargetRepository>;
129 };
130 create(targetModelData: DataObject<TargetEntity>, options?: Options & {
131 throughData?: DataObject<ThroughEntity>;
132 throughOptions?: Options;
133 } & {
134 polymorphicType?: string;
135 }): Promise<TargetEntity>;
136 find(filter?: Filter<TargetEntity>, options?: Options & {
137 throughOptions?: Options & {
138 discriminator?: string;
139 };
140 } & {
141 polymorphicType?: string | string[];
142 }): Promise<TargetEntity[]>;
143 delete(where?: Where<TargetEntity>, options?: Options & {
144 throughOptions?: Options & {
145 discriminator?: string;
146 };
147 } & {
148 polymorphicType?: string | string[];
149 }): Promise<Count>;
150 patch(dataObject: DataObject<TargetEntity> | {
151 [polymorphicType: string]: DataObject<TargetEntity>;
152 }, where?: Where<TargetEntity>, options?: Options & {
153 throughOptions?: Options & {
154 discriminator?: string;
155 };
156 } & {
157 isPolymorphic?: boolean;
158 }): Promise<Count>;
159 link(targetId: TargetID, options?: Options & {
160 throughData?: DataObject<ThroughEntity>;
161 throughOptions?: Options;
162 }): Promise<void>;
163 unlink(targetId: TargetID, options?: Options & {
164 throughOptions?: Options;
165 }): Promise<void>;
166 unlinkAll(options?: Options & {
167 throughOptions?: Options;
168 }): Promise<void>;
169}