forked from loopbackio/loopback-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repository): add interface for hasManyThrough repository
The hasManyThrough repository interface defines the actions that can be performed on a many-to-many model relation. This PR is a continuation of loopbackio#2359 and implements a step from loopbackio#2359 (comment).
- Loading branch information
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
packages/repository/src/relations/has-many/has-many-through.repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright IBM Corp. 2020. All Rights Reserved. | ||
// Node module: @loopback/repository | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {Count, DataObject, Entity, Filter, Options, Where} from '../..'; | ||
|
||
/** | ||
* CRUD operations for a target repository of a HasManyThrough relation | ||
*/ | ||
export interface HasManyThroughRepository< | ||
Target extends Entity, | ||
TargetID, | ||
Through extends Entity | ||
> { | ||
/** | ||
* Create a target model instance | ||
* @param targetModelData - The target model data | ||
* @param options - Options for the operation | ||
* @returns A promise which resolves to the newly created target model instance | ||
*/ | ||
create( | ||
targetModelData: DataObject<Target>, | ||
options: Options & { | ||
throughData?: DataObject<Through>; | ||
throughOptions?: Options; | ||
}, | ||
): Promise<Target>; | ||
/** | ||
* Find target model instance(s) | ||
* @param filter - A filter object for where, order, limit, etc. | ||
* @param options - Options for the operation | ||
* @returns A promise which resolves with the found target instance(s) | ||
*/ | ||
find( | ||
filter?: Filter<Target>, | ||
options?: Options & { | ||
throughOptions?: Options; | ||
}, | ||
): Promise<Target[]>; | ||
/** | ||
* Delete multiple target model instances | ||
* @param where - Instances within the where scope are deleted | ||
* @param options | ||
* @returns A promise which resolves the deleted target model instances | ||
*/ | ||
delete( | ||
where?: Where<Target>, | ||
options?: Options & { | ||
throughOptions?: Options; | ||
}, | ||
): Promise<Count>; | ||
/** | ||
* Patch multiple target model instances | ||
* @param dataObject - The fields and their new values to patch | ||
* @param where - Instances within the where scope are patched | ||
* @param options | ||
* @returns A promise which resolves the patched target model instances | ||
*/ | ||
patch( | ||
dataObject: DataObject<Target>, | ||
where?: Where<Target>, | ||
options?: Options & { | ||
throughOptions?: Options; | ||
}, | ||
): Promise<Count>; | ||
|
||
/** | ||
* Creates a new many-to-many association to an existing target model instance | ||
* @param targetModelId - The target model ID to link | ||
* @param options | ||
* @returns A promise which resolves to the linked target model instance | ||
*/ | ||
link( | ||
targetModelId: TargetID, | ||
options?: Options & { | ||
throughData?: DataObject<Through>; | ||
throughOptions?: Options; | ||
}, | ||
): Promise<Target>; | ||
|
||
/** | ||
* Removes an association to an existing target model instance | ||
* @param targetModelId - The target model to unlink | ||
* @param options | ||
* @returns A promise which resolves to null | ||
*/ | ||
unlink( | ||
targetModelId: TargetID, | ||
options?: Options & { | ||
throughOptions?: Options; | ||
}, | ||
): Promise<void>; | ||
|
||
/** | ||
* Checks if the given target model instance is associated with the source model. | ||
* @param targetModelId - The target model ID to check | ||
* @param options | ||
* @returns A promise which resolves to true when the association exists | ||
* and false otherwise. | ||
*/ | ||
exists( | ||
targetModelId: TargetID, | ||
options?: Options & { | ||
throughOptions?: Options; | ||
}, | ||
): Promise<boolean>; | ||
} |