@loopback/repository 3.2.0 → 3.4.1
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 +48 -0
- package/dist/connectors/connector.d.ts +35 -1
- package/dist/relations/belongs-to/{belongs-to-accessor.d.ts → belongs-to.accessor.d.ts} +0 -0
- package/dist/relations/belongs-to/{belongs-to-accessor.js → belongs-to.accessor.js} +2 -2
- package/dist/relations/belongs-to/{belongs-to-accessor.js.map → 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 +1 -1
- package/dist/relations/belongs-to/belongs-to.helpers.js.map +1 -1
- package/dist/relations/belongs-to/belongs-to.inclusion-resolver.d.ts +1 -1
- package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js +2 -1
- package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js.map +1 -1
- package/dist/relations/belongs-to/belongs-to.repository.d.ts +1 -1
- package/dist/relations/belongs-to/belongs-to.repository.js +2 -2
- package/dist/relations/belongs-to/belongs-to.repository.js.map +1 -1
- package/dist/relations/belongs-to/index.d.ts +1 -1
- package/dist/relations/belongs-to/index.js +1 -1
- package/dist/relations/has-many/has-many-through.helpers.js +1 -1
- package/dist/relations/has-many/has-many-through.helpers.js.map +1 -1
- package/dist/relations/has-many/{has-many-through.inclusion.resolver.d.ts → has-many-through.inclusion-resolver.d.ts} +1 -1
- package/dist/relations/has-many/{has-many-through.inclusion.resolver.js → has-many-through.inclusion-resolver.js} +4 -3
- package/dist/relations/has-many/{has-many-through.inclusion.resolver.js.map → has-many-through.inclusion-resolver.js.map} +1 -1
- package/dist/relations/has-many/{has-many-through-repository.factory.d.ts → has-many-through.repository-factory.d.ts} +0 -0
- package/dist/relations/has-many/{has-many-through-repository.factory.js → has-many-through.repository-factory.js} +2 -2
- package/dist/relations/has-many/{has-many-through-repository.factory.js.map → has-many-through.repository-factory.js.map} +1 -1
- package/dist/relations/has-many/has-many.helpers.js +1 -1
- package/dist/relations/has-many/has-many.helpers.js.map +1 -1
- package/dist/relations/has-many/has-many.inclusion-resolver.d.ts +1 -1
- package/dist/relations/has-many/has-many.inclusion-resolver.js +3 -2
- package/dist/relations/has-many/has-many.inclusion-resolver.js.map +1 -1
- package/dist/relations/has-many/{has-many-repository.factory.d.ts → has-many.repository-factory.d.ts} +1 -1
- package/dist/relations/has-many/{has-many-repository.factory.js → has-many.repository-factory.js} +2 -2
- package/dist/relations/has-many/has-many.repository-factory.js.map +1 -0
- package/dist/relations/has-many/has-many.repository.d.ts +1 -1
- package/dist/relations/has-many/has-many.repository.js +5 -5
- package/dist/relations/has-many/has-many.repository.js.map +1 -1
- package/dist/relations/has-many/index.d.ts +2 -2
- package/dist/relations/has-many/index.js +2 -2
- package/dist/relations/has-one/has-one.helpers.js +1 -1
- package/dist/relations/has-one/has-one.helpers.js.map +1 -1
- package/dist/relations/has-one/has-one.inclusion-resolver.d.ts +1 -1
- package/dist/relations/has-one/has-one.inclusion-resolver.js +2 -1
- package/dist/relations/has-one/has-one.inclusion-resolver.js.map +1 -1
- package/dist/relations/has-one/{has-one-repository.factory.d.ts → has-one.repository-factory.d.ts} +1 -1
- package/dist/relations/has-one/{has-one-repository.factory.js → has-one.repository-factory.js} +2 -2
- package/dist/relations/has-one/has-one.repository-factory.js.map +1 -0
- package/dist/relations/has-one/index.d.ts +1 -1
- package/dist/relations/has-one/index.js +1 -1
- package/dist/relations/relation.helpers.d.ts +2 -2
- package/dist/relations/relation.helpers.js +10 -11
- package/dist/relations/relation.helpers.js.map +1 -1
- package/dist/relations/relation.types.d.ts +2 -2
- package/dist/repositories/kv.repository.bridge.js.map +1 -1
- package/dist/repositories/legacy-juggler-bridge.d.ts +2 -2
- package/dist/repositories/legacy-juggler-bridge.js.map +1 -1
- package/package.json +18 -18
- package/src/connectors/connector.ts +41 -1
- package/src/define-model-class.ts +3 -4
- package/src/relations/belongs-to/{belongs-to-accessor.ts → belongs-to.accessor.ts} +1 -1
- package/src/relations/belongs-to/belongs-to.decorator.ts +2 -2
- package/src/relations/belongs-to/belongs-to.helpers.ts +1 -1
- package/src/relations/belongs-to/belongs-to.inclusion-resolver.ts +7 -4
- package/src/relations/belongs-to/belongs-to.repository.ts +1 -2
- package/src/relations/belongs-to/index.ts +1 -1
- package/src/relations/has-many/has-many-through.helpers.ts +3 -1
- package/src/relations/has-many/{has-many-through.inclusion.resolver.ts → has-many-through.inclusion-resolver.ts} +8 -11
- package/src/relations/has-many/{has-many-through-repository.factory.ts → has-many-through.repository-factory.ts} +1 -1
- package/src/relations/has-many/has-many.helpers.ts +1 -1
- package/src/relations/has-many/has-many.inclusion-resolver.ts +10 -5
- package/src/relations/has-many/{has-many-repository.factory.ts → has-many.repository-factory.ts} +4 -2
- package/src/relations/has-many/has-many.repository.ts +2 -2
- package/src/relations/has-many/index.ts +2 -2
- package/src/relations/has-one/has-one.helpers.ts +1 -1
- package/src/relations/has-one/has-one.inclusion-resolver.ts +7 -4
- package/src/relations/has-one/{has-one-repository.factory.ts → has-one.repository-factory.ts} +4 -2
- package/src/relations/has-one/index.ts +1 -1
- package/src/relations/relation.helpers.ts +14 -14
- package/src/relations/relation.types.ts +2 -2
- package/src/repositories/kv.repository.bridge.ts +4 -3
- package/src/repositories/legacy-juggler-bridge.ts +7 -2
- package/dist/relations/has-many/has-many-repository.factory.js.map +0 -1
- package/dist/relations/has-one/has-one-repository.factory.js.map +0 -1
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
constrainDataObject,
|
|
12
12
|
constrainFilter,
|
|
13
13
|
constrainWhere,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
EntityCrudRepository,
|
|
15
|
+
} from '../../repositories';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* CRUD operations for a target repository of a HasMany relation
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
|
-
export * from './has-many-
|
|
7
|
-
export * from './has-many-through-
|
|
6
|
+
export * from './has-many.repository-factory';
|
|
7
|
+
export * from './has-many-through.repository-factory';
|
|
8
8
|
export * from './has-many-through.repository';
|
|
9
9
|
export * from './has-many.decorator';
|
|
10
10
|
export * from './has-many.inclusion-resolver';
|
|
@@ -9,7 +9,7 @@ import {InvalidRelationError} from '../../errors';
|
|
|
9
9
|
import {isTypeResolver} from '../../type-resolver';
|
|
10
10
|
import {HasOneDefinition, RelationType} from '../relation.types';
|
|
11
11
|
|
|
12
|
-
const debug = debugFactory('loopback:repository:has-one
|
|
12
|
+
const debug = debugFactory('loopback:repository:relations:has-one:helpers');
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Relation definition with optional metadata (e.g. `keyTo`) filled in.
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
|
-
import {Filter,
|
|
6
|
+
import {Filter, InclusionFilter} from '@loopback/filter';
|
|
7
7
|
import {AnyObject, Options} from '../../common-types';
|
|
8
8
|
import {Entity} from '../../model';
|
|
9
|
-
import {EntityCrudRepository} from '../../repositories
|
|
9
|
+
import {EntityCrudRepository} from '../../repositories';
|
|
10
10
|
import {
|
|
11
11
|
findByForeignKeys,
|
|
12
12
|
flattenTargetsOfOneToOneRelation,
|
|
@@ -39,7 +39,7 @@ export function createHasOneInclusionResolver<
|
|
|
39
39
|
|
|
40
40
|
return async function fetchHasOneModel(
|
|
41
41
|
entities: Entity[],
|
|
42
|
-
inclusion:
|
|
42
|
+
inclusion: InclusionFilter,
|
|
43
43
|
options?: Options,
|
|
44
44
|
): Promise<((Target & TargetRelations) | undefined)[]> {
|
|
45
45
|
if (!entities.length) return [];
|
|
@@ -48,12 +48,15 @@ export function createHasOneInclusionResolver<
|
|
|
48
48
|
const sourceIds = entities.map(e => (e as AnyObject)[sourceKey]);
|
|
49
49
|
const targetKey = relationMeta.keyTo as StringKeyOf<Target>;
|
|
50
50
|
|
|
51
|
+
const scope =
|
|
52
|
+
typeof inclusion === 'string' ? {} : (inclusion.scope as Filter<Target>);
|
|
53
|
+
|
|
51
54
|
const targetRepo = await getTargetRepo();
|
|
52
55
|
const targetsFound = await findByForeignKeys(
|
|
53
56
|
targetRepo,
|
|
54
57
|
targetKey,
|
|
55
58
|
sourceIds,
|
|
56
|
-
|
|
59
|
+
scope,
|
|
57
60
|
options,
|
|
58
61
|
);
|
|
59
62
|
|
package/src/relations/has-one/{has-one-repository.factory.ts → has-one.repository-factory.ts}
RENAMED
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
import debugFactory from 'debug';
|
|
7
7
|
import {DataObject} from '../../common-types';
|
|
8
8
|
import {Entity} from '../../model';
|
|
9
|
-
import {EntityCrudRepository} from '../../repositories
|
|
9
|
+
import {EntityCrudRepository} from '../../repositories';
|
|
10
10
|
import {Getter, HasOneDefinition, InclusionResolver} from '../relation.types';
|
|
11
11
|
import {resolveHasOneMetadata} from './has-one.helpers';
|
|
12
12
|
import {createHasOneInclusionResolver} from './has-one.inclusion-resolver';
|
|
13
13
|
import {DefaultHasOneRepository, HasOneRepository} from './has-one.repository';
|
|
14
14
|
|
|
15
|
-
const debug = debugFactory(
|
|
15
|
+
const debug = debugFactory(
|
|
16
|
+
'loopback:repository:relations:has-one:repository-factory',
|
|
17
|
+
);
|
|
16
18
|
|
|
17
19
|
export interface HasOneRepositoryFactory<
|
|
18
20
|
Target extends Entity,
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
import assert from 'assert';
|
|
7
7
|
import debugFactory from 'debug';
|
|
8
|
-
import _ from 'lodash';
|
|
8
|
+
import _, {cloneDeep} from 'lodash';
|
|
9
9
|
import {
|
|
10
10
|
AnyObject,
|
|
11
11
|
Entity,
|
|
12
12
|
EntityCrudRepository,
|
|
13
13
|
Filter,
|
|
14
14
|
FilterBuilder,
|
|
15
|
-
|
|
15
|
+
InclusionFilter,
|
|
16
16
|
Options,
|
|
17
17
|
Where,
|
|
18
18
|
} from '..';
|
|
@@ -39,17 +39,11 @@ export async function findByForeignKeys<
|
|
|
39
39
|
options?: Options,
|
|
40
40
|
): Promise<(Target & TargetRelations)[]> {
|
|
41
41
|
let value;
|
|
42
|
+
scope = cloneDeep(scope);
|
|
42
43
|
|
|
43
44
|
if (Array.isArray(fkValues)) {
|
|
44
45
|
if (fkValues.length === 0) return [];
|
|
45
|
-
value =
|
|
46
|
-
fkValues.length === 1
|
|
47
|
-
? fkValues[0]
|
|
48
|
-
: {
|
|
49
|
-
// Create a copy to prevent query coercion algorithm
|
|
50
|
-
// inside connectors from modifying the original values
|
|
51
|
-
inq: [...fkValues],
|
|
52
|
-
};
|
|
46
|
+
value = fkValues.length === 1 ? fkValues[0] : {inq: fkValues};
|
|
53
47
|
} else {
|
|
54
48
|
value = fkValues;
|
|
55
49
|
}
|
|
@@ -84,9 +78,11 @@ export async function includeRelatedModels<
|
|
|
84
78
|
>(
|
|
85
79
|
targetRepository: EntityCrudRepository<T, unknown, Relations>,
|
|
86
80
|
entities: T[],
|
|
87
|
-
include?:
|
|
81
|
+
include?: InclusionFilter[],
|
|
88
82
|
options?: Options,
|
|
89
83
|
): Promise<(T & Relations)[]> {
|
|
84
|
+
entities = cloneDeep(entities);
|
|
85
|
+
include = cloneDeep(include);
|
|
90
86
|
const result = entities as (T & Relations)[];
|
|
91
87
|
if (!include) return result;
|
|
92
88
|
|
|
@@ -102,12 +98,16 @@ export async function includeRelatedModels<
|
|
|
102
98
|
const err = new Error(msg);
|
|
103
99
|
Object.assign(err, {
|
|
104
100
|
code: 'INVALID_INCLUSION_FILTER',
|
|
101
|
+
statusCode: 400,
|
|
105
102
|
});
|
|
106
103
|
throw err;
|
|
107
104
|
}
|
|
108
105
|
|
|
109
106
|
const resolveTasks = include.map(async inclusionFilter => {
|
|
110
|
-
const relationName =
|
|
107
|
+
const relationName =
|
|
108
|
+
typeof inclusionFilter === 'string'
|
|
109
|
+
? inclusionFilter
|
|
110
|
+
: inclusionFilter.relation;
|
|
111
111
|
const resolver = targetRepository.inclusionResolvers.get(relationName)!;
|
|
112
112
|
const targets = await resolver(entities, inclusionFilter, options);
|
|
113
113
|
|
|
@@ -130,9 +130,9 @@ export async function includeRelatedModels<
|
|
|
130
130
|
*/
|
|
131
131
|
function isInclusionAllowed<T extends Entity, Relations extends object = {}>(
|
|
132
132
|
targetRepository: EntityCrudRepository<T, unknown, Relations>,
|
|
133
|
-
include:
|
|
133
|
+
include: InclusionFilter,
|
|
134
134
|
): boolean {
|
|
135
|
-
const relationName = include.relation;
|
|
135
|
+
const relationName = typeof include === 'string' ? include : include.relation;
|
|
136
136
|
if (!relationName) {
|
|
137
137
|
debug('isInclusionAllowed for %j? No: missing relation name', include);
|
|
138
138
|
return false;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {InclusionFilter} from '@loopback/filter';
|
|
7
7
|
import {Options} from '../common-types';
|
|
8
8
|
import {Entity} from '../model';
|
|
9
9
|
import {TypeResolver} from '../type-resolver';
|
|
@@ -172,7 +172,7 @@ export type InclusionResolver<S extends Entity, T extends Entity> = (
|
|
|
172
172
|
/**
|
|
173
173
|
* Inclusion requested by the user (e.g. scope constraints to apply).
|
|
174
174
|
*/
|
|
175
|
-
inclusion:
|
|
175
|
+
inclusion: InclusionFilter,
|
|
176
176
|
/**
|
|
177
177
|
* Generic options object, e.g. carrying the Transaction object.
|
|
178
178
|
*/
|
|
@@ -53,9 +53,10 @@ export class DefaultKeyValueRepository<T extends Model>
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
async get(key: string, options?: Options): Promise<T> {
|
|
56
|
-
const val = this.kvModelClass.get(
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
const val = this.kvModelClass.get(
|
|
57
|
+
key,
|
|
58
|
+
options,
|
|
59
|
+
) as legacy.PromiseOrVoid<legacy.ModelData>;
|
|
59
60
|
const result = await ensurePromise(val);
|
|
60
61
|
return this.toEntity(result);
|
|
61
62
|
}
|
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
6
|
import {Getter} from '@loopback/core';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
Filter,
|
|
9
|
+
FilterExcludingWhere,
|
|
10
|
+
InclusionFilter,
|
|
11
|
+
Where,
|
|
12
|
+
} from '@loopback/filter';
|
|
8
13
|
import assert from 'assert';
|
|
9
14
|
import legacy from 'loopback-datasource-juggler';
|
|
10
15
|
import {
|
|
@@ -695,7 +700,7 @@ export class DefaultCrudRepository<
|
|
|
695
700
|
*/
|
|
696
701
|
protected async includeRelatedModels(
|
|
697
702
|
entities: T[],
|
|
698
|
-
include?:
|
|
703
|
+
include?: InclusionFilter[],
|
|
699
704
|
options?: Options,
|
|
700
705
|
): Promise<(T & Relations)[]> {
|
|
701
706
|
return includeRelatedModels<T, Relations>(this, entities, include, options);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"has-many-repository.factory.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many-repository.factory.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,0DAAiC;AAKjC,yDAA0D;AAC1D,+EAA6E;AAC7E,+DAG+B;AAE/B,MAAM,KAAK,GAAG,eAAY,CAAC,iDAAiD,CAAC,CAAC;AAiB9E;;;;;;;;;;;;GAYG;AACH,SAAgB,8BAA8B,CAK5C,gBAAmC,EACnC,sBAAsE;IAEtE,MAAM,IAAI,GAAG,yCAAsB,CAAC,gBAAgB,CAAC,CAAC;IACtD,KAAK,CAAC,wCAAwC,EAAE,IAAI,CAAC,CAAC;IACtD,MAAM,MAAM,GAAqD,UAC/D,OAAuB;QAEvB,8DAA8D;QAC9D,MAAM,UAAU,GAAQ,EAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,EAAC,CAAC;QAChD,OAAO,IAAI,8CAAwB,CAIjC,sBAAsB,EAAE,UAAgC,CAAC,CAAC;IAC9D,CAAC,CAAC;IACF,MAAM,CAAC,iBAAiB,GAAG,4DAA8B,CACvD,IAAI,EACJ,sBAAsB,CACvB,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AA1BD,wEA0BC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"has-one-repository.factory.js","sourceRoot":"","sources":["../../../src/relations/has-one/has-one-repository.factory.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,0DAAiC;AAKjC,uDAAwD;AACxD,6EAA2E;AAC3E,6DAA+E;AAE/E,MAAM,KAAK,GAAG,eAAY,CAAC,gDAAgD,CAAC,CAAC;AAgB7E;;;;;;;;;;;;GAYG;AACH,SAAgB,6BAA6B,CAK3C,gBAAkC,EAClC,sBAAsE;IAEtE,MAAM,IAAI,GAAG,uCAAqB,CAAC,gBAAgB,CAAC,CAAC;IACrD,KAAK,CAAC,uCAAuC,EAAE,IAAI,CAAC,CAAC;IACrD,MAAM,MAAM,GAAoD,UAC9D,OAAuB;QAEvB,8DAA8D;QAC9D,MAAM,UAAU,GAAQ,EAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,EAAC,CAAC;QAChD,OAAO,IAAI,4CAAuB,CAIhC,sBAAsB,EAAE,UAAgC,CAAC,CAAC;IAC9D,CAAC,CAAC;IACF,MAAM,CAAC,iBAAiB,GAAG,0DAA6B,CACtD,IAAI,EACJ,sBAAsB,CACvB,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AA1BD,sEA0BC"}
|