feathers-utils 5.0.0 → 5.0.2
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/dist/index.cjs +4 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +4 -1
- package/package.json +1 -1
- package/src/hooks/forEach.ts +11 -10
package/dist/index.cjs
CHANGED
|
@@ -688,6 +688,9 @@ const forEach = (actionPerItem, options) => {
|
|
|
688
688
|
if (shouldSkip("forEach", context)) {
|
|
689
689
|
return context;
|
|
690
690
|
}
|
|
691
|
+
if (options?.skip && await options.skip(context)) {
|
|
692
|
+
return context;
|
|
693
|
+
}
|
|
691
694
|
const { items } = getItemsIsArray(context, { from });
|
|
692
695
|
const forAll = options?.forAll ? await options.forAll(items, context) : {};
|
|
693
696
|
const promises = [];
|
|
@@ -696,7 +699,7 @@ const forEach = (actionPerItem, options) => {
|
|
|
696
699
|
const promise = actionPerItem(item, {
|
|
697
700
|
context,
|
|
698
701
|
i,
|
|
699
|
-
fromAll: forAll
|
|
702
|
+
...forAll ? { fromAll: forAll } : {}
|
|
700
703
|
});
|
|
701
704
|
if (wait === "sequential") {
|
|
702
705
|
await promise;
|
package/dist/index.d.cts
CHANGED
|
@@ -36,17 +36,19 @@ interface GetItemsIsArrayResult<T = any> {
|
|
|
36
36
|
}
|
|
37
37
|
declare const getItemsIsArray: <T = any, H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>>(context: H, options?: GetItemsIsArrayOptions) => GetItemsIsArrayResult<T>;
|
|
38
38
|
|
|
39
|
-
type HookForEachOptions<T = any, H = HookContext, R =
|
|
39
|
+
type HookForEachOptions<T = any, H = HookContext, R = any> = {
|
|
40
40
|
wait?: "sequential" | "parallel" | false;
|
|
41
41
|
items?: GetItemsIsArrayOptions["from"];
|
|
42
42
|
forAll?: (items: T[], context: H) => Promisable<R>;
|
|
43
|
+
skip?: (context: H) => Promisable<boolean>;
|
|
43
44
|
};
|
|
44
45
|
type ActionPerItem<T, H, R> = (item: T, options: {
|
|
45
46
|
context: H;
|
|
46
47
|
i: number;
|
|
48
|
+
} & (undefined extends R ? {} : {
|
|
47
49
|
fromAll: R;
|
|
48
|
-
}) => Promisable<any>;
|
|
49
|
-
declare const forEach: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any, R =
|
|
50
|
+
})) => Promisable<any>;
|
|
51
|
+
declare const forEach: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any, R = any>(actionPerItem: ActionPerItem<T, H, R>, options?: HookForEachOptions<T, H, R>) => ReturnAsyncHook<H>;
|
|
50
52
|
|
|
51
53
|
type OnDeleteAction = "cascade" | "set null";
|
|
52
54
|
interface OnDeleteOptions {
|
package/dist/index.d.mts
CHANGED
|
@@ -36,17 +36,19 @@ interface GetItemsIsArrayResult<T = any> {
|
|
|
36
36
|
}
|
|
37
37
|
declare const getItemsIsArray: <T = any, H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>>(context: H, options?: GetItemsIsArrayOptions) => GetItemsIsArrayResult<T>;
|
|
38
38
|
|
|
39
|
-
type HookForEachOptions<T = any, H = HookContext, R =
|
|
39
|
+
type HookForEachOptions<T = any, H = HookContext, R = any> = {
|
|
40
40
|
wait?: "sequential" | "parallel" | false;
|
|
41
41
|
items?: GetItemsIsArrayOptions["from"];
|
|
42
42
|
forAll?: (items: T[], context: H) => Promisable<R>;
|
|
43
|
+
skip?: (context: H) => Promisable<boolean>;
|
|
43
44
|
};
|
|
44
45
|
type ActionPerItem<T, H, R> = (item: T, options: {
|
|
45
46
|
context: H;
|
|
46
47
|
i: number;
|
|
48
|
+
} & (undefined extends R ? {} : {
|
|
47
49
|
fromAll: R;
|
|
48
|
-
}) => Promisable<any>;
|
|
49
|
-
declare const forEach: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any, R =
|
|
50
|
+
})) => Promisable<any>;
|
|
51
|
+
declare const forEach: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any, R = any>(actionPerItem: ActionPerItem<T, H, R>, options?: HookForEachOptions<T, H, R>) => ReturnAsyncHook<H>;
|
|
50
52
|
|
|
51
53
|
type OnDeleteAction = "cascade" | "set null";
|
|
52
54
|
interface OnDeleteOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -36,17 +36,19 @@ interface GetItemsIsArrayResult<T = any> {
|
|
|
36
36
|
}
|
|
37
37
|
declare const getItemsIsArray: <T = any, H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>>(context: H, options?: GetItemsIsArrayOptions) => GetItemsIsArrayResult<T>;
|
|
38
38
|
|
|
39
|
-
type HookForEachOptions<T = any, H = HookContext, R =
|
|
39
|
+
type HookForEachOptions<T = any, H = HookContext, R = any> = {
|
|
40
40
|
wait?: "sequential" | "parallel" | false;
|
|
41
41
|
items?: GetItemsIsArrayOptions["from"];
|
|
42
42
|
forAll?: (items: T[], context: H) => Promisable<R>;
|
|
43
|
+
skip?: (context: H) => Promisable<boolean>;
|
|
43
44
|
};
|
|
44
45
|
type ActionPerItem<T, H, R> = (item: T, options: {
|
|
45
46
|
context: H;
|
|
46
47
|
i: number;
|
|
48
|
+
} & (undefined extends R ? {} : {
|
|
47
49
|
fromAll: R;
|
|
48
|
-
}) => Promisable<any>;
|
|
49
|
-
declare const forEach: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any, R =
|
|
50
|
+
})) => Promisable<any>;
|
|
51
|
+
declare const forEach: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any, R = any>(actionPerItem: ActionPerItem<T, H, R>, options?: HookForEachOptions<T, H, R>) => ReturnAsyncHook<H>;
|
|
50
52
|
|
|
51
53
|
type OnDeleteAction = "cascade" | "set null";
|
|
52
54
|
interface OnDeleteOptions {
|
package/dist/index.mjs
CHANGED
|
@@ -674,6 +674,9 @@ const forEach = (actionPerItem, options) => {
|
|
|
674
674
|
if (shouldSkip("forEach", context)) {
|
|
675
675
|
return context;
|
|
676
676
|
}
|
|
677
|
+
if (options?.skip && await options.skip(context)) {
|
|
678
|
+
return context;
|
|
679
|
+
}
|
|
677
680
|
const { items } = getItemsIsArray(context, { from });
|
|
678
681
|
const forAll = options?.forAll ? await options.forAll(items, context) : {};
|
|
679
682
|
const promises = [];
|
|
@@ -682,7 +685,7 @@ const forEach = (actionPerItem, options) => {
|
|
|
682
685
|
const promise = actionPerItem(item, {
|
|
683
686
|
context,
|
|
684
687
|
i,
|
|
685
|
-
fromAll: forAll
|
|
688
|
+
...forAll ? { fromAll: forAll } : {}
|
|
686
689
|
});
|
|
687
690
|
if (wait === "sequential") {
|
|
688
691
|
await promise;
|
package/package.json
CHANGED
package/src/hooks/forEach.ts
CHANGED
|
@@ -5,10 +5,11 @@ import type { HookContext } from "@feathersjs/feathers";
|
|
|
5
5
|
import type { GetItemsIsArrayOptions } from "../utils/getItemsIsArray";
|
|
6
6
|
import { getItemsIsArray } from "../utils/getItemsIsArray";
|
|
7
7
|
|
|
8
|
-
export type HookForEachOptions<T = any, H = HookContext, R =
|
|
8
|
+
export type HookForEachOptions<T = any, H = HookContext, R = any> = {
|
|
9
9
|
wait?: "sequential" | "parallel" | false;
|
|
10
10
|
items?: GetItemsIsArrayOptions["from"];
|
|
11
11
|
forAll?: (items: T[], context: H) => Promisable<R>;
|
|
12
|
+
skip?: (context: H) => Promisable<boolean>;
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
type ActionPerItem<T, H, R> = (
|
|
@@ -16,15 +17,11 @@ type ActionPerItem<T, H, R> = (
|
|
|
16
17
|
options: {
|
|
17
18
|
context: H;
|
|
18
19
|
i: number;
|
|
19
|
-
|
|
20
|
-
},
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
21
|
+
} & (undefined extends R ? {} : { fromAll: R }),
|
|
21
22
|
) => Promisable<any>;
|
|
22
23
|
|
|
23
|
-
export const forEach = <
|
|
24
|
-
H extends HookContext = HookContext,
|
|
25
|
-
T = any,
|
|
26
|
-
R = never,
|
|
27
|
-
>(
|
|
24
|
+
export const forEach = <H extends HookContext = HookContext, T = any, R = any>(
|
|
28
25
|
actionPerItem: ActionPerItem<T, H, R>,
|
|
29
26
|
options?: HookForEachOptions<T, H, R>,
|
|
30
27
|
): ReturnAsyncHook<H> => {
|
|
@@ -35,6 +32,10 @@ export const forEach = <
|
|
|
35
32
|
return context;
|
|
36
33
|
}
|
|
37
34
|
|
|
35
|
+
if (options?.skip && (await options.skip(context))) {
|
|
36
|
+
return context;
|
|
37
|
+
}
|
|
38
|
+
|
|
38
39
|
const { items } = getItemsIsArray(context, { from });
|
|
39
40
|
|
|
40
41
|
const forAll = options?.forAll
|
|
@@ -49,8 +50,8 @@ export const forEach = <
|
|
|
49
50
|
const promise = actionPerItem(item, {
|
|
50
51
|
context,
|
|
51
52
|
i,
|
|
52
|
-
fromAll: forAll,
|
|
53
|
-
});
|
|
53
|
+
...(forAll ? { fromAll: forAll } : {}),
|
|
54
|
+
} as any);
|
|
54
55
|
|
|
55
56
|
if (wait === "sequential") {
|
|
56
57
|
await promise;
|