@loopback/repository 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/relations/has-many/has-many-through-repository.factory.d.ts +2 -2
- package/dist/relations/has-many/has-many-through-repository.factory.js +12 -13
- package/dist/relations/has-many/has-many-through-repository.factory.js.map +1 -1
- package/dist/relations/has-many/has-many-through.helpers.d.ts +58 -17
- package/dist/relations/has-many/has-many-through.helpers.js +77 -32
- package/dist/relations/has-many/has-many-through.helpers.js.map +1 -1
- package/dist/relations/has-many/has-many-through.repository.d.ts +9 -8
- package/dist/relations/has-many/has-many-through.repository.js +32 -26
- package/dist/relations/has-many/has-many-through.repository.js.map +1 -1
- package/dist/repositories/legacy-juggler-bridge.d.ts +32 -1
- package/dist/repositories/legacy-juggler-bridge.js +34 -0
- package/dist/repositories/legacy-juggler-bridge.js.map +1 -1
- package/package.json +7 -7
- package/src/relations/has-many/has-many-through-repository.factory.ts +33 -26
- package/src/relations/has-many/has-many-through.helpers.ts +99 -36
- package/src/relations/has-many/has-many-through.repository.ts +50 -36
- package/src/repositories/legacy-juggler-bridge.ts +58 -0
|
@@ -29,9 +29,11 @@ import {
|
|
|
29
29
|
BelongsToDefinition,
|
|
30
30
|
createBelongsToAccessor,
|
|
31
31
|
createHasManyRepositoryFactory,
|
|
32
|
+
createHasManyThroughRepositoryFactory,
|
|
32
33
|
createHasOneRepositoryFactory,
|
|
33
34
|
HasManyDefinition,
|
|
34
35
|
HasManyRepositoryFactory,
|
|
36
|
+
HasManyThroughRepositoryFactory,
|
|
35
37
|
HasOneDefinition,
|
|
36
38
|
HasOneRepositoryFactory,
|
|
37
39
|
includeRelatedModels,
|
|
@@ -283,6 +285,62 @@ export class DefaultCrudRepository<
|
|
|
283
285
|
);
|
|
284
286
|
}
|
|
285
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Function to create a constrained hasManyThrough relation repository factory
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* class CustomerRepository extends DefaultCrudRepository<
|
|
294
|
+
* Customer,
|
|
295
|
+
* typeof Customer.prototype.id,
|
|
296
|
+
* CustomerRelations
|
|
297
|
+
* > {
|
|
298
|
+
* public readonly cartItems: HasManyRepositoryFactory<CartItem, typeof Customer.prototype.id>;
|
|
299
|
+
*
|
|
300
|
+
* constructor(
|
|
301
|
+
* protected db: juggler.DataSource,
|
|
302
|
+
* cartItemRepository: EntityCrudRepository<CartItem, typeof, CartItem.prototype.id>,
|
|
303
|
+
* throughRepository: EntityCrudRepository<Through, typeof Through.prototype.id>,
|
|
304
|
+
* ) {
|
|
305
|
+
* super(Customer, db);
|
|
306
|
+
* this.cartItems = this.createHasManyThroughRepositoryFactoryFor(
|
|
307
|
+
* 'cartItems',
|
|
308
|
+
* cartItemRepository,
|
|
309
|
+
* );
|
|
310
|
+
* }
|
|
311
|
+
* }
|
|
312
|
+
* ```
|
|
313
|
+
*
|
|
314
|
+
* @param relationName - Name of the relation defined on the source model
|
|
315
|
+
* @param targetRepo - Target repository instance
|
|
316
|
+
* @param throughRepo - Through repository instance
|
|
317
|
+
*/
|
|
318
|
+
protected createHasManyThroughRepositoryFactoryFor<
|
|
319
|
+
Target extends Entity,
|
|
320
|
+
TargetID,
|
|
321
|
+
Through extends Entity,
|
|
322
|
+
ThroughID,
|
|
323
|
+
ForeignKeyType
|
|
324
|
+
>(
|
|
325
|
+
relationName: string,
|
|
326
|
+
targetRepoGetter: Getter<EntityCrudRepository<Target, TargetID>>,
|
|
327
|
+
throughRepoGetter: Getter<EntityCrudRepository<Through, ThroughID>>,
|
|
328
|
+
): HasManyThroughRepositoryFactory<
|
|
329
|
+
Target,
|
|
330
|
+
TargetID,
|
|
331
|
+
Through,
|
|
332
|
+
ForeignKeyType
|
|
333
|
+
> {
|
|
334
|
+
const meta = this.entityClass.definition.relations[relationName];
|
|
335
|
+
return createHasManyThroughRepositoryFactory<
|
|
336
|
+
Target,
|
|
337
|
+
TargetID,
|
|
338
|
+
Through,
|
|
339
|
+
ThroughID,
|
|
340
|
+
ForeignKeyType
|
|
341
|
+
>(meta as HasManyDefinition, targetRepoGetter, throughRepoGetter);
|
|
342
|
+
}
|
|
343
|
+
|
|
286
344
|
/**
|
|
287
345
|
* @deprecated
|
|
288
346
|
* Function to create a belongs to accessor
|