Skip to content

Commit c249043

Browse files
author
KoLiBer
committed
Merge branch 'release/1.1.0'
2 parents 689b4a5 + 9ee15fb commit c249043

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v1.1.0
4+
5+
- **Feat**: add `context` to options and pass into `InvocationContext`
6+
37
## v1.0.0
48

59
- **Fix**: remove sources folder from ci file

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "loopback-component-filter",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Loopback component models filter",
55
"keywords": [
66
"loopback-extension",

src/repositories/filter.repository.ts

+25-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MixinTarget } from "@loopback/core";
1+
import { MixinTarget, Context } from "@loopback/core";
22
import { InvocationContext } from "@loopback/context";
33
import {
44
DefaultCrudRepository,
@@ -12,6 +12,10 @@ import {
1212
EntityNotFoundError,
1313
} from "@loopback/repository";
1414

15+
export interface FilterOptions extends Options {
16+
context: Context;
17+
}
18+
1519
/**
1620
* This interface contains additional types added to FilterRepositoryMixin type
1721
*/
@@ -90,10 +94,10 @@ export function FilterRepositoryMixin<
9094
*/
9195
createAll = async (
9296
entities: DataObject<T>[],
93-
options?: Options
97+
options?: FilterOptions
9498
) => {
9599
const filterContext = new InvocationContext(
96-
undefined as any,
100+
options?.context as Context,
97101
this,
98102
"create",
99103
Array.from(arguments)
@@ -108,7 +112,7 @@ export function FilterRepositoryMixin<
108112
/**
109113
* Filter create() using createAll()
110114
*/
111-
create = async (entity: DataObject<T>, options?: Options) => {
115+
create = async (entity: DataObject<T>, options?: FilterOptions) => {
112116
const result = await this.createAll([entity], options);
113117

114118
return result[0];
@@ -117,9 +121,9 @@ export function FilterRepositoryMixin<
117121
/**
118122
* Filter where and find all entities
119123
*/
120-
find = async (filter?: Filter<T>, options?: Options) => {
124+
find = async (filter?: Filter<T>, options?: FilterOptions) => {
121125
const filterContext = new InvocationContext(
122-
undefined as any,
126+
options?.context as Context,
123127
this,
124128
"read",
125129
Array.from(arguments)
@@ -144,9 +148,9 @@ export function FilterRepositoryMixin<
144148
/**
145149
* Filter where and find one entity
146150
*/
147-
findOne = async (filter?: Filter<T>, options?: Options) => {
151+
findOne = async (filter?: Filter<T>, options?: FilterOptions) => {
148152
const filterContext = new InvocationContext(
149-
undefined as any,
153+
options?.context as Context,
150154
this,
151155
"read",
152156
Array.from(arguments)
@@ -174,7 +178,7 @@ export function FilterRepositoryMixin<
174178
findById = async (
175179
id: ID,
176180
filter?: FilterExcludingWhere<T>,
177-
options?: Options
181+
options?: FilterOptions
178182
) => {
179183
const result = await this.findOne(
180184
{
@@ -194,9 +198,9 @@ export function FilterRepositoryMixin<
194198
/**
195199
* Filter where and count all entities
196200
*/
197-
count = async (where?: Where<T>, options?: Options) => {
201+
count = async (where?: Where<T>, options?: FilterOptions) => {
198202
const filterContext = new InvocationContext(
199-
undefined as any,
203+
options?.context as Context,
200204
this,
201205
"read",
202206
Array.from(arguments)
@@ -211,7 +215,7 @@ export function FilterRepositoryMixin<
211215
/**
212216
* Filter exists() using count()
213217
*/
214-
exists = async (id: ID, options?: Options) => {
218+
exists = async (id: ID, options?: FilterOptions) => {
215219
const result = await this.count(
216220
this.entityClass.buildWhereForId(id),
217221
options
@@ -226,10 +230,10 @@ export function FilterRepositoryMixin<
226230
updateAll = async (
227231
data: DataObject<T>,
228232
where?: Where<T>,
229-
options?: Options
233+
options?: FilterOptions
230234
) => {
231235
const filterContext = new InvocationContext(
232-
undefined as any,
236+
options?.context as Context,
233237
this,
234238
"update",
235239
Array.from(arguments)
@@ -257,7 +261,7 @@ export function FilterRepositoryMixin<
257261
updateById = async (
258262
id: ID,
259263
data: DataObject<T>,
260-
options?: Options
264+
options?: FilterOptions
261265
) => {
262266
await this.updateAll(
263267
data,
@@ -269,7 +273,7 @@ export function FilterRepositoryMixin<
269273
/**
270274
* Filter update() using updateAll()
271275
*/
272-
update = async (entity: T, options?: Options) => {
276+
update = async (entity: T, options?: FilterOptions) => {
273277
await this.updateAll(
274278
entity,
275279
this.entityClass.buildWhereForId(
@@ -285,7 +289,7 @@ export function FilterRepositoryMixin<
285289
replaceById = async (
286290
id: ID,
287291
data: DataObject<T>,
288-
options?: Options
292+
options?: FilterOptions
289293
) => {
290294
await this.updateAll(
291295
{
@@ -304,9 +308,9 @@ export function FilterRepositoryMixin<
304308
/**
305309
* Filter where and delete all entities
306310
*/
307-
deleteAll = async (where?: Where<T>, options?: Options) => {
311+
deleteAll = async (where?: Where<T>, options?: FilterOptions) => {
308312
const filterContext = new InvocationContext(
309-
undefined as any,
313+
options?.context as Context,
310314
this,
311315
"delete",
312316
Array.from(arguments)
@@ -321,7 +325,7 @@ export function FilterRepositoryMixin<
321325
/**
322326
* Filter delete() using deleteAll()
323327
*/
324-
delete = async (entity: T, options?: Options) => {
328+
delete = async (entity: T, options?: FilterOptions) => {
325329
await this.deleteAll(
326330
this.entityClass.buildWhereForId(
327331
this.entityClass.getIdOf(entity)
@@ -333,7 +337,7 @@ export function FilterRepositoryMixin<
333337
/**
334338
* Filter deleteById() using deleteAll()
335339
*/
336-
deleteById = async (id: ID, options?: Options) => {
340+
deleteById = async (id: ID, options?: FilterOptions) => {
337341
await this.deleteAll(
338342
this.entityClass.buildWhereForId(id),
339343
options

0 commit comments

Comments
 (0)