feathers-utils 3.1.1 → 3.1.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.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/package.json +14 -14
- package/src/hooks/forEach.ts +4 -4
- package/src/hooks/runPerItem.ts +3 -3
- package/src/typesInternal.ts +7 -2
- package/src/utility-types/index.ts +20 -20
package/dist/index.d.cts
CHANGED
|
@@ -13,7 +13,7 @@ declare function checkMulti<H extends HookContext = HookContext>(): (context: H)
|
|
|
13
13
|
type MaybeArray<T> = T | T[];
|
|
14
14
|
type Promisable<T> = T | Promise<T>;
|
|
15
15
|
type Path = Array<string | number>;
|
|
16
|
-
type ReturnAsyncHook = (context:
|
|
16
|
+
type ReturnAsyncHook<H extends HookContext$1 = HookContext$1> = (context: H) => Promise<H>;
|
|
17
17
|
|
|
18
18
|
interface CreateRelatedOptions<S = Record<string, any>> {
|
|
19
19
|
service: keyof S;
|
|
@@ -39,7 +39,7 @@ interface HookForEachOptions {
|
|
|
39
39
|
wait?: "sequential" | "parallel" | false;
|
|
40
40
|
items?: GetItemsIsArrayOptions["from"];
|
|
41
41
|
}
|
|
42
|
-
declare const forEach: (actionPerItem: (item:
|
|
42
|
+
declare const forEach: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any>(actionPerItem: (item: T, context: H) => Promisable<any>, _options?: HookForEachOptions) => ReturnAsyncHook<H>;
|
|
43
43
|
|
|
44
44
|
type OnDeleteAction = "cascade" | "set null";
|
|
45
45
|
interface OnDeleteOptions {
|
|
@@ -79,7 +79,7 @@ interface HookRunPerItemOptions {
|
|
|
79
79
|
* hook to run a hook for each item in the context
|
|
80
80
|
* uses `context.result` if it is existent. otherwise uses context.data
|
|
81
81
|
*/
|
|
82
|
-
declare const runPerItem: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any
|
|
82
|
+
declare const runPerItem: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any>(actionPerItem: (item: T, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
|
|
83
83
|
|
|
84
84
|
type Predicate<T = any> = (item: T) => boolean;
|
|
85
85
|
type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
|
package/dist/index.d.mts
CHANGED
|
@@ -13,7 +13,7 @@ declare function checkMulti<H extends HookContext = HookContext>(): (context: H)
|
|
|
13
13
|
type MaybeArray<T> = T | T[];
|
|
14
14
|
type Promisable<T> = T | Promise<T>;
|
|
15
15
|
type Path = Array<string | number>;
|
|
16
|
-
type ReturnAsyncHook = (context:
|
|
16
|
+
type ReturnAsyncHook<H extends HookContext$1 = HookContext$1> = (context: H) => Promise<H>;
|
|
17
17
|
|
|
18
18
|
interface CreateRelatedOptions<S = Record<string, any>> {
|
|
19
19
|
service: keyof S;
|
|
@@ -39,7 +39,7 @@ interface HookForEachOptions {
|
|
|
39
39
|
wait?: "sequential" | "parallel" | false;
|
|
40
40
|
items?: GetItemsIsArrayOptions["from"];
|
|
41
41
|
}
|
|
42
|
-
declare const forEach: (actionPerItem: (item:
|
|
42
|
+
declare const forEach: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any>(actionPerItem: (item: T, context: H) => Promisable<any>, _options?: HookForEachOptions) => ReturnAsyncHook<H>;
|
|
43
43
|
|
|
44
44
|
type OnDeleteAction = "cascade" | "set null";
|
|
45
45
|
interface OnDeleteOptions {
|
|
@@ -79,7 +79,7 @@ interface HookRunPerItemOptions {
|
|
|
79
79
|
* hook to run a hook for each item in the context
|
|
80
80
|
* uses `context.result` if it is existent. otherwise uses context.data
|
|
81
81
|
*/
|
|
82
|
-
declare const runPerItem: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any
|
|
82
|
+
declare const runPerItem: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any>(actionPerItem: (item: T, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
|
|
83
83
|
|
|
84
84
|
type Predicate<T = any> = (item: T) => boolean;
|
|
85
85
|
type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare function checkMulti<H extends HookContext = HookContext>(): (context: H)
|
|
|
13
13
|
type MaybeArray<T> = T | T[];
|
|
14
14
|
type Promisable<T> = T | Promise<T>;
|
|
15
15
|
type Path = Array<string | number>;
|
|
16
|
-
type ReturnAsyncHook = (context:
|
|
16
|
+
type ReturnAsyncHook<H extends HookContext$1 = HookContext$1> = (context: H) => Promise<H>;
|
|
17
17
|
|
|
18
18
|
interface CreateRelatedOptions<S = Record<string, any>> {
|
|
19
19
|
service: keyof S;
|
|
@@ -39,7 +39,7 @@ interface HookForEachOptions {
|
|
|
39
39
|
wait?: "sequential" | "parallel" | false;
|
|
40
40
|
items?: GetItemsIsArrayOptions["from"];
|
|
41
41
|
}
|
|
42
|
-
declare const forEach: (actionPerItem: (item:
|
|
42
|
+
declare const forEach: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any>(actionPerItem: (item: T, context: H) => Promisable<any>, _options?: HookForEachOptions) => ReturnAsyncHook<H>;
|
|
43
43
|
|
|
44
44
|
type OnDeleteAction = "cascade" | "set null";
|
|
45
45
|
interface OnDeleteOptions {
|
|
@@ -79,7 +79,7 @@ interface HookRunPerItemOptions {
|
|
|
79
79
|
* hook to run a hook for each item in the context
|
|
80
80
|
* uses `context.result` if it is existent. otherwise uses context.data
|
|
81
81
|
*/
|
|
82
|
-
declare const runPerItem: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any
|
|
82
|
+
declare const runPerItem: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any>(actionPerItem: (item: T, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
|
|
83
83
|
|
|
84
84
|
type Predicate<T = any> = (item: T) => boolean;
|
|
85
85
|
type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feathers-utils",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Some utils for projects using '@feathersjs/feathers'",
|
|
5
5
|
"author": "fratzinger",
|
|
6
6
|
"repository": {
|
|
@@ -40,29 +40,29 @@
|
|
|
40
40
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@feathersjs/adapter-commons": "^5.0.
|
|
44
|
-
"@feathersjs/commons": "^5.0.
|
|
45
|
-
"@feathersjs/errors": "^5.0.
|
|
43
|
+
"@feathersjs/adapter-commons": "^5.0.11",
|
|
44
|
+
"@feathersjs/commons": "^5.0.11",
|
|
45
|
+
"@feathersjs/errors": "^5.0.11",
|
|
46
46
|
"fast-equals": "^5.0.1",
|
|
47
47
|
"feathers-hooks-common": "^8.1.1",
|
|
48
48
|
"lodash": "^4.17.21"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@feathersjs/feathers": "^5.0.
|
|
52
|
-
"@feathersjs/memory": "^5.0.
|
|
53
|
-
"@types/lodash": "^4.14.
|
|
54
|
-
"@types/node": "^20.
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
56
|
-
"@typescript-eslint/parser": "^6.
|
|
51
|
+
"@feathersjs/feathers": "^5.0.11",
|
|
52
|
+
"@feathersjs/memory": "^5.0.11",
|
|
53
|
+
"@types/lodash": "^4.14.201",
|
|
54
|
+
"@types/node": "^20.9.0",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
56
|
+
"@typescript-eslint/parser": "^6.10.0",
|
|
57
57
|
"@vitest/coverage-v8": "^0.34.6",
|
|
58
|
-
"eslint": "^8.
|
|
58
|
+
"eslint": "^8.53.0",
|
|
59
59
|
"eslint-config-prettier": "^9.0.0",
|
|
60
60
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
61
|
-
"eslint-plugin-import": "^2.
|
|
62
|
-
"eslint-plugin-prettier": "^5.0.
|
|
61
|
+
"eslint-plugin-import": "^2.29.0",
|
|
62
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
63
63
|
"eslint-plugin-security": "^1.7.1",
|
|
64
64
|
"np": "^8.0.4",
|
|
65
|
-
"prettier": "^3.0
|
|
65
|
+
"prettier": "^3.1.0",
|
|
66
66
|
"shx": "^0.3.4",
|
|
67
67
|
"typescript": "^5.2.2",
|
|
68
68
|
"unbuild": "^2.0.0",
|
package/src/hooks/forEach.ts
CHANGED
|
@@ -10,18 +10,18 @@ export interface HookForEachOptions {
|
|
|
10
10
|
items?: GetItemsIsArrayOptions["from"];
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const forEach = (
|
|
13
|
+
export const forEach = <H extends HookContext = HookContext, T = any>(
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
actionPerItem: (item:
|
|
15
|
+
actionPerItem: (item: T, context: H) => Promisable<any>,
|
|
16
16
|
_options?: HookForEachOptions,
|
|
17
|
-
): ReturnAsyncHook => {
|
|
17
|
+
): ReturnAsyncHook<H> => {
|
|
18
18
|
const options: Required<HookForEachOptions> = {
|
|
19
19
|
wait: "parallel",
|
|
20
20
|
items: "automatic",
|
|
21
21
|
..._options,
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
return async (context:
|
|
24
|
+
return async (context: H): Promise<H> => {
|
|
25
25
|
if (shouldSkip("runForItems", context)) {
|
|
26
26
|
return context;
|
|
27
27
|
}
|
package/src/hooks/runPerItem.ts
CHANGED
|
@@ -21,9 +21,9 @@ const makeOptions = (
|
|
|
21
21
|
* hook to run a hook for each item in the context
|
|
22
22
|
* uses `context.result` if it is existent. otherwise uses context.data
|
|
23
23
|
*/
|
|
24
|
-
export const runPerItem = <H extends HookContext = HookContext>(
|
|
24
|
+
export const runPerItem = <H extends HookContext = HookContext, T = any>(
|
|
25
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
actionPerItem: (item:
|
|
26
|
+
actionPerItem: (item: T, context: H) => Promisable<any>,
|
|
27
27
|
_options?: HookRunPerItemOptions,
|
|
28
28
|
) => {
|
|
29
29
|
const options = makeOptions(_options);
|
|
@@ -34,7 +34,7 @@ export const runPerItem = <H extends HookContext = HookContext>(
|
|
|
34
34
|
|
|
35
35
|
const { items } = getItemsIsArray(context);
|
|
36
36
|
|
|
37
|
-
const promises = items.map(async (item:
|
|
37
|
+
const promises = items.map(async (item: T) => {
|
|
38
38
|
await actionPerItem(item, context);
|
|
39
39
|
});
|
|
40
40
|
|
package/src/typesInternal.ts
CHANGED
|
@@ -15,5 +15,10 @@ export type ServiceMethodName =
|
|
|
15
15
|
| "update"
|
|
16
16
|
| "patch"
|
|
17
17
|
| "remove";
|
|
18
|
-
|
|
19
|
-
export type
|
|
18
|
+
|
|
19
|
+
export type ReturnSyncHook<H extends HookContext = HookContext> = (
|
|
20
|
+
context: H,
|
|
21
|
+
) => H;
|
|
22
|
+
export type ReturnAsyncHook<H extends HookContext = HookContext> = (
|
|
23
|
+
context: H,
|
|
24
|
+
) => Promise<H>;
|
|
@@ -41,8 +41,8 @@ export type InferCreateResult<S, D = unknown> = S extends {
|
|
|
41
41
|
? D extends any[]
|
|
42
42
|
? AsArray<Awaited<R>>
|
|
43
43
|
: D extends InferCreateDataSingle<S>
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
? Single<Awaited<R>>
|
|
45
|
+
: Awaited<R>
|
|
46
46
|
: never;
|
|
47
47
|
|
|
48
48
|
export type InferCreateResultSingle<S> = Single<InferCreateResult<S>>;
|
|
@@ -59,8 +59,8 @@ export type InferPatchResult<S, IdOrNullable = any> = S extends {
|
|
|
59
59
|
? IdOrNullable extends Id
|
|
60
60
|
? Single<Awaited<R>>
|
|
61
61
|
: IdOrNullable extends null
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
? AsArray<Awaited<R>>
|
|
63
|
+
: Awaited<R>
|
|
64
64
|
: never;
|
|
65
65
|
|
|
66
66
|
export type InferRemoveResult<S, IdOrNullable = any> = S extends {
|
|
@@ -69,8 +69,8 @@ export type InferRemoveResult<S, IdOrNullable = any> = S extends {
|
|
|
69
69
|
? IdOrNullable extends Id
|
|
70
70
|
? Single<Awaited<R>>
|
|
71
71
|
: IdOrNullable extends null
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
? AsArray<Awaited<R>>
|
|
73
|
+
: Awaited<R>
|
|
74
74
|
: never;
|
|
75
75
|
|
|
76
76
|
export type GetService<
|
|
@@ -138,10 +138,10 @@ export type InferDataFromPath<
|
|
|
138
138
|
> = Method extends "create"
|
|
139
139
|
? InferCreateDataFromPath<App, Path>
|
|
140
140
|
: Method extends "update"
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
? InferUpdateDataFromPath<App, Path>
|
|
142
|
+
: Method extends "patch"
|
|
143
|
+
? InferPatchDataFromPath<App, Path>
|
|
144
|
+
: never;
|
|
145
145
|
|
|
146
146
|
export type InferResultFromPath<
|
|
147
147
|
App extends Application,
|
|
@@ -150,13 +150,13 @@ export type InferResultFromPath<
|
|
|
150
150
|
> = Method extends "get"
|
|
151
151
|
? InferGetResultFromPath<App, Path>
|
|
152
152
|
: Method extends "find"
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
153
|
+
? InferFindResultFromPath<App, Path>
|
|
154
|
+
: Method extends "create"
|
|
155
|
+
? InferCreateResultFromPath<App, Path>
|
|
156
|
+
: Method extends "update"
|
|
157
|
+
? InferUpdateResultFromPath<App, Path>
|
|
158
|
+
: Method extends "patch"
|
|
159
|
+
? InferPatchResultFromPath<App, Path>
|
|
160
|
+
: Method extends "remove"
|
|
161
|
+
? InferRemoveResultFromPath<App, Path>
|
|
162
|
+
: never;
|