@loopback/repository 3.6.0 → 3.7.3
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/README.md +3 -3
- package/dist/connectors/index.js +3 -3
- package/dist/connectors/index.js.map +1 -1
- package/dist/decorators/index.js +3 -3
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/metadata.js +1 -1
- package/dist/decorators/repository.decorator.js +4 -4
- package/dist/decorators/repository.decorator.js.map +1 -1
- package/dist/define-model-class.js +2 -2
- package/dist/define-model-class.js.map +1 -1
- package/dist/define-repository-class.js +1 -1
- package/dist/define-repository-class.js.map +1 -1
- package/dist/errors/index.js +2 -2
- package/dist/errors/index.js.map +1 -1
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/dist/mixins/index.js +1 -1
- package/dist/mixins/index.js.map +1 -1
- package/dist/mixins/repository.mixin.d.ts +3 -4
- package/dist/mixins/repository.mixin.js +10 -7
- package/dist/mixins/repository.mixin.js.map +1 -1
- package/dist/model.d.ts +1 -1
- package/dist/relations/belongs-to/belongs-to.accessor.js +5 -5
- package/dist/relations/belongs-to/belongs-to.accessor.js.map +1 -1
- package/dist/relations/belongs-to/belongs-to.decorator.js +2 -2
- package/dist/relations/belongs-to/belongs-to.decorator.js.map +1 -1
- package/dist/relations/belongs-to/belongs-to.helpers.js +4 -4
- package/dist/relations/belongs-to/belongs-to.helpers.js.map +1 -1
- package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js +4 -4
- package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js.map +1 -1
- package/dist/relations/belongs-to/belongs-to.repository.js +1 -1
- package/dist/relations/belongs-to/belongs-to.repository.js.map +1 -1
- package/dist/relations/belongs-to/index.js +4 -4
- package/dist/relations/belongs-to/index.js.map +1 -1
- package/dist/relations/has-many/has-many-through.helpers.js +8 -8
- package/dist/relations/has-many/has-many-through.helpers.js.map +1 -1
- package/dist/relations/has-many/has-many-through.inclusion-resolver.js +9 -6
- package/dist/relations/has-many/has-many-through.inclusion-resolver.js.map +1 -1
- package/dist/relations/has-many/has-many-through.repository-factory.js +7 -7
- package/dist/relations/has-many/has-many-through.repository-factory.js.map +1 -1
- package/dist/relations/has-many/has-many-through.repository.d.ts +11 -0
- package/dist/relations/has-many/has-many-through.repository.js +19 -10
- package/dist/relations/has-many/has-many-through.repository.js.map +1 -1
- package/dist/relations/has-many/has-many.decorator.js +1 -1
- package/dist/relations/has-many/has-many.decorator.js.map +1 -1
- package/dist/relations/has-many/has-many.helpers.js +4 -4
- package/dist/relations/has-many/has-many.helpers.js.map +1 -1
- package/dist/relations/has-many/has-many.inclusion-resolver.js +5 -5
- package/dist/relations/has-many/has-many.inclusion-resolver.js.map +1 -1
- package/dist/relations/has-many/has-many.repository-factory.js +4 -4
- package/dist/relations/has-many/has-many.repository-factory.js.map +1 -1
- package/dist/relations/has-many/has-many.repository.js +4 -4
- package/dist/relations/has-many/has-many.repository.js.map +1 -1
- package/dist/relations/has-many/index.js +6 -6
- package/dist/relations/has-many/index.js.map +1 -1
- package/dist/relations/has-one/has-one.decorator.js +1 -1
- package/dist/relations/has-one/has-one.decorator.js.map +1 -1
- package/dist/relations/has-one/has-one.helpers.js +4 -4
- package/dist/relations/has-one/has-one.helpers.js.map +1 -1
- package/dist/relations/has-one/has-one.inclusion-resolver.js +3 -3
- package/dist/relations/has-one/has-one.inclusion-resolver.js.map +1 -1
- package/dist/relations/has-one/has-one.repository-factory.js +4 -4
- package/dist/relations/has-one/has-one.repository-factory.js.map +1 -1
- package/dist/relations/has-one/has-one.repository.js +4 -4
- package/dist/relations/has-one/has-one.repository.js.map +1 -1
- package/dist/relations/has-one/index.js +3 -3
- package/dist/relations/has-one/index.js.map +1 -1
- package/dist/relations/index.js +6 -6
- package/dist/relations/index.js.map +1 -1
- package/dist/relations/relation.decorator.js +1 -1
- package/dist/relations/relation.decorator.js.map +1 -1
- package/dist/relations/relation.helpers.d.ts +3 -1
- package/dist/relations/relation.helpers.js +47 -14
- package/dist/relations/relation.helpers.js.map +1 -1
- package/dist/repositories/constraint-utils.js +4 -4
- package/dist/repositories/constraint-utils.js.map +1 -1
- package/dist/repositories/index.js +5 -5
- package/dist/repositories/index.js.map +1 -1
- package/dist/repositories/kv.repository.bridge.js +9 -8
- package/dist/repositories/kv.repository.bridge.js.map +1 -1
- package/dist/repositories/legacy-juggler-bridge.js +13 -13
- package/dist/repositories/legacy-juggler-bridge.js.map +1 -1
- package/dist/repositories/repository.js.map +1 -1
- package/dist/types/array.js +1 -1
- package/dist/types/array.js.map +1 -1
- package/dist/types/buffer.js +1 -1
- package/dist/types/buffer.js.map +1 -1
- package/dist/types/date.js +1 -1
- package/dist/types/date.js.map +1 -1
- package/dist/types/number.js +1 -1
- package/dist/types/number.js.map +1 -1
- package/dist/types/object.js +1 -1
- package/dist/types/object.js.map +1 -1
- package/dist/types/union.js +1 -1
- package/dist/types/union.js.map +1 -1
- package/package.json +17 -17
- package/src/decorators/metadata.ts +1 -1
- package/src/define-model-class.ts +2 -2
- package/src/define-repository-class.ts +4 -4
- package/src/mixins/repository.mixin.ts +11 -8
- package/src/model.ts +1 -1
- package/src/relations/belongs-to/belongs-to.accessor.ts +21 -23
- package/src/relations/belongs-to/belongs-to.inclusion-resolver.ts +1 -1
- package/src/relations/belongs-to/belongs-to.repository.ts +3 -2
- package/src/relations/has-many/has-many-through.helpers.ts +4 -4
- package/src/relations/has-many/has-many-through.inclusion-resolver.ts +5 -2
- package/src/relations/has-many/has-many-through.repository-factory.ts +2 -2
- package/src/relations/has-many/has-many-through.repository.ts +44 -15
- package/src/relations/has-many/has-many.inclusion-resolver.ts +1 -1
- package/src/relations/has-many/has-many.repository-factory.ts +2 -2
- package/src/relations/has-many/has-many.repository.ts +3 -2
- package/src/relations/has-one/has-one.inclusion-resolver.ts +1 -1
- package/src/relations/has-one/has-one.repository-factory.ts +2 -2
- package/src/relations/has-one/has-one.repository.ts +3 -2
- package/src/relations/relation.helpers.ts +43 -12
- package/src/repositories/kv.repository.bridge.ts +4 -4
- package/src/repositories/legacy-juggler-bridge.ts +11 -9
- package/src/repositories/repository.ts +5 -4
- package/src/type-resolver.ts +1 -1
- package/CHANGELOG.md +0 -1925
|
@@ -59,8 +59,9 @@ export interface HasManyRepository<Target extends Entity> {
|
|
|
59
59
|
export class DefaultHasManyRepository<
|
|
60
60
|
TargetEntity extends Entity,
|
|
61
61
|
TargetID,
|
|
62
|
-
TargetRepository extends EntityCrudRepository<TargetEntity, TargetID
|
|
63
|
-
> implements HasManyRepository<TargetEntity>
|
|
62
|
+
TargetRepository extends EntityCrudRepository<TargetEntity, TargetID>,
|
|
63
|
+
> implements HasManyRepository<TargetEntity>
|
|
64
|
+
{
|
|
64
65
|
/**
|
|
65
66
|
* Constructor of DefaultHasManyEntityCrudRepository
|
|
66
67
|
* @param getTargetRepository - the getter of the related target model repository instance
|
|
@@ -28,7 +28,7 @@ import {resolveHasOneMetadata} from './has-one.helpers';
|
|
|
28
28
|
export function createHasOneInclusionResolver<
|
|
29
29
|
Target extends Entity,
|
|
30
30
|
TargetID,
|
|
31
|
-
TargetRelations extends object
|
|
31
|
+
TargetRelations extends object,
|
|
32
32
|
>(
|
|
33
33
|
meta: HasOneDefinition,
|
|
34
34
|
getTargetRepo: Getter<
|
|
@@ -18,7 +18,7 @@ const debug = debugFactory(
|
|
|
18
18
|
|
|
19
19
|
export interface HasOneRepositoryFactory<
|
|
20
20
|
Target extends Entity,
|
|
21
|
-
ForeignKeyType
|
|
21
|
+
ForeignKeyType,
|
|
22
22
|
> {
|
|
23
23
|
/**
|
|
24
24
|
* Invoke the function to obtain HasOneRepository.
|
|
@@ -46,7 +46,7 @@ export interface HasOneRepositoryFactory<
|
|
|
46
46
|
export function createHasOneRepositoryFactory<
|
|
47
47
|
Target extends Entity,
|
|
48
48
|
TargetID,
|
|
49
|
-
ForeignKeyType
|
|
49
|
+
ForeignKeyType,
|
|
50
50
|
>(
|
|
51
51
|
relationMetadata: HasOneDefinition,
|
|
52
52
|
targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>>,
|
|
@@ -61,8 +61,9 @@ export interface HasOneRepository<Target extends Entity> {
|
|
|
61
61
|
export class DefaultHasOneRepository<
|
|
62
62
|
TargetEntity extends Entity,
|
|
63
63
|
TargetID,
|
|
64
|
-
TargetRepository extends EntityCrudRepository<TargetEntity, TargetID
|
|
65
|
-
> implements HasOneRepository<TargetEntity>
|
|
64
|
+
TargetRepository extends EntityCrudRepository<TargetEntity, TargetID>,
|
|
65
|
+
> implements HasOneRepository<TargetEntity>
|
|
66
|
+
{
|
|
66
67
|
/**
|
|
67
68
|
* Constructor of DefaultHasOneEntityCrudRepository
|
|
68
69
|
* @param getTargetRepository - the getter of the related target model repository instance
|
|
@@ -30,34 +30,65 @@ const debug = debugFactory('loopback:repository:relation-helpers');
|
|
|
30
30
|
export async function findByForeignKeys<
|
|
31
31
|
Target extends Entity,
|
|
32
32
|
TargetRelations extends object,
|
|
33
|
-
ForeignKey extends StringKeyOf<Target
|
|
33
|
+
ForeignKey extends StringKeyOf<Target>,
|
|
34
34
|
>(
|
|
35
35
|
targetRepository: EntityCrudRepository<Target, unknown, TargetRelations>,
|
|
36
36
|
fkName: ForeignKey,
|
|
37
37
|
fkValues: Target[ForeignKey][] | Target[ForeignKey],
|
|
38
|
-
scope?: Filter<Target
|
|
38
|
+
scope?: Filter<Target> & {totalLimit?: number},
|
|
39
39
|
options?: Options,
|
|
40
40
|
): Promise<(Target & TargetRelations)[]> {
|
|
41
41
|
let value;
|
|
42
42
|
scope = cloneDeep(scope);
|
|
43
|
-
|
|
44
43
|
if (Array.isArray(fkValues)) {
|
|
45
44
|
if (fkValues.length === 0) return [];
|
|
46
45
|
value = fkValues.length === 1 ? fkValues[0] : {inq: fkValues};
|
|
47
46
|
} else {
|
|
48
47
|
value = fkValues;
|
|
49
48
|
}
|
|
49
|
+
let useScopeFilterGlobally = false;
|
|
50
|
+
if (options) {
|
|
51
|
+
useScopeFilterGlobally = options.isThroughModelInclude;
|
|
52
|
+
//if its an include from a through model, fkValues will be an array
|
|
53
|
+
//however, in this case we DO want to use the scope in the entire query
|
|
54
|
+
//no in a per fk basis
|
|
55
|
+
}
|
|
56
|
+
//This code is to keep backward compatability. See https://github.com/loopbackio/loopback-next/issues/6832
|
|
57
|
+
//for more info
|
|
58
|
+
if (scope?.totalLimit) {
|
|
59
|
+
scope.limit = scope.totalLimit;
|
|
60
|
+
useScopeFilterGlobally = true;
|
|
61
|
+
delete scope.totalLimit;
|
|
62
|
+
}
|
|
50
63
|
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
scope
|
|
64
|
+
const isScopeSet = scope && !_.isEmpty(scope);
|
|
65
|
+
if (isScopeSet && Array.isArray(fkValues) && !useScopeFilterGlobally) {
|
|
66
|
+
// since there is a scope, there could be a where filter, a limit, an order
|
|
67
|
+
// and we should run the scope in multiple queries so we can respect the
|
|
68
|
+
// scope filter params
|
|
69
|
+
const findPromises = fkValues.map(fk => {
|
|
70
|
+
const where = {[fkName]: fk} as unknown as Where<Target>;
|
|
71
|
+
let localScope = cloneDeep(scope);
|
|
72
|
+
// combine where clause to scope filter
|
|
73
|
+
localScope = new FilterBuilder(localScope).impose({where}).filter;
|
|
74
|
+
return targetRepository.find(localScope, options);
|
|
75
|
+
});
|
|
76
|
+
return Promise.all(findPromises).then(findResults => {
|
|
77
|
+
//findResults is an array of arrays for each scope result, so we need to flatten it before returning it
|
|
78
|
+
return _.flatten(findResults);
|
|
79
|
+
});
|
|
56
80
|
} else {
|
|
57
|
-
|
|
58
|
-
}
|
|
81
|
+
const where = {[fkName]: value} as unknown as Where<Target>;
|
|
59
82
|
|
|
60
|
-
|
|
83
|
+
if (isScopeSet) {
|
|
84
|
+
// combine where clause to scope filter
|
|
85
|
+
scope = new FilterBuilder(scope).impose({where}).filter;
|
|
86
|
+
} else {
|
|
87
|
+
scope = {where} as Filter<Target>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return targetRepository.find(scope, options);
|
|
91
|
+
}
|
|
61
92
|
}
|
|
62
93
|
|
|
63
94
|
export type StringKeyOf<T> = Extract<keyof T, string>;
|
|
@@ -74,7 +105,7 @@ export type StringKeyOf<T> = Extract<keyof T, string>;
|
|
|
74
105
|
|
|
75
106
|
export async function includeRelatedModels<
|
|
76
107
|
T extends Entity,
|
|
77
|
-
Relations extends object = {}
|
|
108
|
+
Relations extends object = {},
|
|
78
109
|
>(
|
|
79
110
|
targetRepository: EntityCrudRepository<T, unknown, Relations>,
|
|
80
111
|
entities: T[],
|
|
@@ -13,7 +13,8 @@ import {ensurePromise, juggler} from './legacy-juggler-bridge';
|
|
|
13
13
|
* An implementation of KeyValueRepository based on loopback-datasource-juggler
|
|
14
14
|
*/
|
|
15
15
|
export class DefaultKeyValueRepository<T extends Model>
|
|
16
|
-
implements KeyValueRepository<T>
|
|
16
|
+
implements KeyValueRepository<T>
|
|
17
|
+
{
|
|
17
18
|
/**
|
|
18
19
|
* A legacy KeyValueModel class
|
|
19
20
|
*/
|
|
@@ -29,9 +30,8 @@ export class DefaultKeyValueRepository<T extends Model>
|
|
|
29
30
|
) {
|
|
30
31
|
// KVModel class is placeholder to receive methods from KeyValueAccessObject
|
|
31
32
|
// through mixin
|
|
32
|
-
this.kvModelClass =
|
|
33
|
-
'_kvModel'
|
|
34
|
-
);
|
|
33
|
+
this.kvModelClass =
|
|
34
|
+
ds.createModel<typeof juggler.KeyValueModel>('_kvModel');
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
delete(key: string, options?: Options): Promise<void> {
|
|
@@ -111,8 +111,9 @@ export function ensurePromise<T>(p: legacy.PromiseOrVoid<T>): Promise<T> {
|
|
|
111
111
|
export class DefaultCrudRepository<
|
|
112
112
|
T extends Entity,
|
|
113
113
|
ID,
|
|
114
|
-
Relations extends object = {}
|
|
115
|
-
> implements EntityCrudRepository<T, ID, Relations>
|
|
114
|
+
Relations extends object = {},
|
|
115
|
+
> implements EntityCrudRepository<T, ID, Relations>
|
|
116
|
+
{
|
|
116
117
|
modelClass: juggler.PersistedModelClass;
|
|
117
118
|
|
|
118
119
|
public readonly inclusionResolvers: Map<
|
|
@@ -236,7 +237,7 @@ export class DefaultCrudRepository<
|
|
|
236
237
|
protected _createHasManyRepositoryFactoryFor<
|
|
237
238
|
Target extends Entity,
|
|
238
239
|
TargetID,
|
|
239
|
-
ForeignKeyType
|
|
240
|
+
ForeignKeyType,
|
|
240
241
|
>(
|
|
241
242
|
relationName: string,
|
|
242
243
|
targetRepoGetter: Getter<EntityCrudRepository<Target, TargetID>>,
|
|
@@ -278,7 +279,7 @@ export class DefaultCrudRepository<
|
|
|
278
279
|
protected createHasManyRepositoryFactoryFor<
|
|
279
280
|
Target extends Entity,
|
|
280
281
|
TargetID,
|
|
281
|
-
ForeignKeyType
|
|
282
|
+
ForeignKeyType,
|
|
282
283
|
>(
|
|
283
284
|
relationName: string,
|
|
284
285
|
targetRepoGetter: Getter<EntityCrudRepository<Target, TargetID>>,
|
|
@@ -325,7 +326,7 @@ export class DefaultCrudRepository<
|
|
|
325
326
|
TargetID,
|
|
326
327
|
Through extends Entity,
|
|
327
328
|
ThroughID,
|
|
328
|
-
ForeignKeyType
|
|
329
|
+
ForeignKeyType,
|
|
329
330
|
>(
|
|
330
331
|
relationName: string,
|
|
331
332
|
targetRepoGetter: Getter<EntityCrudRepository<Target, TargetID>>,
|
|
@@ -390,7 +391,7 @@ export class DefaultCrudRepository<
|
|
|
390
391
|
protected _createHasOneRepositoryFactoryFor<
|
|
391
392
|
Target extends Entity,
|
|
392
393
|
TargetID,
|
|
393
|
-
ForeignKeyType
|
|
394
|
+
ForeignKeyType,
|
|
394
395
|
>(
|
|
395
396
|
relationName: string,
|
|
396
397
|
targetRepoGetter: Getter<EntityCrudRepository<Target, TargetID>>,
|
|
@@ -410,7 +411,7 @@ export class DefaultCrudRepository<
|
|
|
410
411
|
protected createHasOneRepositoryFactoryFor<
|
|
411
412
|
Target extends Entity,
|
|
412
413
|
TargetID,
|
|
413
|
-
ForeignKeyType
|
|
414
|
+
ForeignKeyType,
|
|
414
415
|
>(
|
|
415
416
|
relationName: string,
|
|
416
417
|
targetRepoGetter: Getter<EntityCrudRepository<Target, TargetID>>,
|
|
@@ -770,10 +771,11 @@ export class DefaultCrudRepository<
|
|
|
770
771
|
export class DefaultTransactionalRepository<
|
|
771
772
|
T extends Entity,
|
|
772
773
|
ID,
|
|
773
|
-
Relations extends object = {}
|
|
774
|
+
Relations extends object = {},
|
|
774
775
|
>
|
|
775
776
|
extends DefaultCrudRepository<T, ID, Relations>
|
|
776
|
-
implements TransactionalEntityRepository<T, ID, Relations>
|
|
777
|
+
implements TransactionalEntityRepository<T, ID, Relations>
|
|
778
|
+
{
|
|
777
779
|
async beginTransaction(
|
|
778
780
|
options?: IsolationLevel | Options,
|
|
779
781
|
): Promise<Transaction> {
|
|
@@ -46,7 +46,7 @@ export interface ExecutableRepository<T extends Model> extends Repository<T> {
|
|
|
46
46
|
export type TransactionalEntityRepository<
|
|
47
47
|
T extends Entity,
|
|
48
48
|
ID,
|
|
49
|
-
Relations extends object = {}
|
|
49
|
+
Relations extends object = {},
|
|
50
50
|
> = TransactionalRepository<T> & EntityCrudRepository<T, ID>;
|
|
51
51
|
/**
|
|
52
52
|
* Repository Interface for Repositories that support Transactions
|
|
@@ -69,7 +69,7 @@ export interface TransactionalRepository<T extends Entity>
|
|
|
69
69
|
*/
|
|
70
70
|
export interface CrudRepository<
|
|
71
71
|
T extends ValueObject | Entity,
|
|
72
|
-
Relations extends object = {}
|
|
72
|
+
Relations extends object = {},
|
|
73
73
|
> extends Repository<T> {
|
|
74
74
|
/**
|
|
75
75
|
* Create a new record
|
|
@@ -137,7 +137,7 @@ export interface EntityRepository<T extends Entity, ID>
|
|
|
137
137
|
export interface EntityCrudRepository<
|
|
138
138
|
T extends Entity,
|
|
139
139
|
ID,
|
|
140
|
-
Relations extends object = {}
|
|
140
|
+
Relations extends object = {},
|
|
141
141
|
> extends EntityRepository<T, ID>,
|
|
142
142
|
CrudRepository<T, Relations> {
|
|
143
143
|
// entityClass should have type "typeof T", but that's not supported by TSC
|
|
@@ -254,7 +254,8 @@ export interface EntityCrudRepository<
|
|
|
254
254
|
* ```
|
|
255
255
|
*/
|
|
256
256
|
export class CrudRepositoryImpl<T extends Entity, ID>
|
|
257
|
-
implements EntityCrudRepository<T, ID>
|
|
257
|
+
implements EntityCrudRepository<T, ID>
|
|
258
|
+
{
|
|
258
259
|
private connector: CrudConnector;
|
|
259
260
|
public readonly inclusionResolvers: Map<
|
|
260
261
|
string,
|