feathers-utils 5.0.0 → 5.0.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/dist/index.cjs CHANGED
@@ -696,7 +696,7 @@ const forEach = (actionPerItem, options) => {
696
696
  const promise = actionPerItem(item, {
697
697
  context,
698
698
  i,
699
- fromAll: forAll
699
+ ...forAll ? { fromAll: forAll } : {}
700
700
  });
701
701
  if (wait === "sequential") {
702
702
  await promise;
package/dist/index.d.cts CHANGED
@@ -36,7 +36,7 @@ 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 = never> = {
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>;
@@ -44,9 +44,10 @@ type HookForEachOptions<T = any, H = HookContext, R = never> = {
44
44
  type ActionPerItem<T, H, R> = (item: T, options: {
45
45
  context: H;
46
46
  i: number;
47
+ } & (undefined extends R ? {} : {
47
48
  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 = never>(actionPerItem: ActionPerItem<T, H, R>, options?: HookForEachOptions<T, H, R>) => ReturnAsyncHook<H>;
49
+ })) => Promisable<any>;
50
+ 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
51
 
51
52
  type OnDeleteAction = "cascade" | "set null";
52
53
  interface OnDeleteOptions {
package/dist/index.d.mts CHANGED
@@ -36,7 +36,7 @@ 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 = never> = {
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>;
@@ -44,9 +44,10 @@ type HookForEachOptions<T = any, H = HookContext, R = never> = {
44
44
  type ActionPerItem<T, H, R> = (item: T, options: {
45
45
  context: H;
46
46
  i: number;
47
+ } & (undefined extends R ? {} : {
47
48
  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 = never>(actionPerItem: ActionPerItem<T, H, R>, options?: HookForEachOptions<T, H, R>) => ReturnAsyncHook<H>;
49
+ })) => Promisable<any>;
50
+ 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
51
 
51
52
  type OnDeleteAction = "cascade" | "set null";
52
53
  interface OnDeleteOptions {
package/dist/index.d.ts CHANGED
@@ -36,7 +36,7 @@ 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 = never> = {
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>;
@@ -44,9 +44,10 @@ type HookForEachOptions<T = any, H = HookContext, R = never> = {
44
44
  type ActionPerItem<T, H, R> = (item: T, options: {
45
45
  context: H;
46
46
  i: number;
47
+ } & (undefined extends R ? {} : {
47
48
  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 = never>(actionPerItem: ActionPerItem<T, H, R>, options?: HookForEachOptions<T, H, R>) => ReturnAsyncHook<H>;
49
+ })) => Promisable<any>;
50
+ 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
51
 
51
52
  type OnDeleteAction = "cascade" | "set null";
52
53
  interface OnDeleteOptions {
package/dist/index.mjs CHANGED
@@ -682,7 +682,7 @@ const forEach = (actionPerItem, options) => {
682
682
  const promise = actionPerItem(item, {
683
683
  context,
684
684
  i,
685
- fromAll: forAll
685
+ ...forAll ? { fromAll: forAll } : {}
686
686
  });
687
687
  if (wait === "sequential") {
688
688
  await promise;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feathers-utils",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "Some utils for projects using '@feathersjs/feathers'",
5
5
  "author": "fratzinger",
6
6
  "repository": {
@@ -5,7 +5,7 @@ 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 = never> = {
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>;
@@ -16,15 +16,11 @@ type ActionPerItem<T, H, R> = (
16
16
  options: {
17
17
  context: H;
18
18
  i: number;
19
- fromAll: R;
20
- },
19
+ // eslint-disable-next-line @typescript-eslint/ban-types
20
+ } & (undefined extends R ? {} : { fromAll: R }),
21
21
  ) => Promisable<any>;
22
22
 
23
- export const forEach = <
24
- H extends HookContext = HookContext,
25
- T = any,
26
- R = never,
27
- >(
23
+ export const forEach = <H extends HookContext = HookContext, T = any, R = any>(
28
24
  actionPerItem: ActionPerItem<T, H, R>,
29
25
  options?: HookForEachOptions<T, H, R>,
30
26
  ): ReturnAsyncHook<H> => {
@@ -49,8 +45,8 @@ export const forEach = <
49
45
  const promise = actionPerItem(item, {
50
46
  context,
51
47
  i,
52
- fromAll: forAll,
53
- });
48
+ ...(forAll ? { fromAll: forAll } : {}),
49
+ } as any);
54
50
 
55
51
  if (wait === "sequential") {
56
52
  await promise;