feathers-utils 1.13.0 → 1.14.0

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.
@@ -1,9 +1,10 @@
1
+ import type { Application, Id } from "@feathersjs/feathers";
2
+ declare type Single<T> = T extends Array<infer U> ? U : T;
3
+ declare type AsArray<T> = T extends any[] ? T : [T];
1
4
  export declare type InferCreateData<S> = S extends {
2
5
  create: (data: infer D, params: any) => any;
3
6
  } ? D : never;
4
- export declare type InferCreateDataSingle<S> = S extends {
5
- create: (data: infer D, params: any) => any;
6
- } ? D extends Array<infer T> ? T : D : never;
7
+ export declare type InferCreateDataSingle<S> = Single<InferCreateData<S>>;
7
8
  export declare type InferUpdateData<S> = S extends {
8
9
  update: (id: any, data: infer D, params: any) => any;
9
10
  } ? D : never;
@@ -16,18 +17,31 @@ export declare type InferGetResult<S> = S extends {
16
17
  export declare type InferFindResult<S> = S extends {
17
18
  find: (params: any) => infer R;
18
19
  } ? Awaited<R> : never;
19
- export declare type InferCreateResult<S, D = any> = S extends {
20
- create: (data: D, params: any) => infer R;
21
- } ? Awaited<R> : never;
22
- export declare type InferCreateResultSingle<S> = S extends {
20
+ export declare type InferCreateResult<S, D = unknown> = S extends {
23
21
  create: (data: any, params: any) => infer R;
24
- } ? Awaited<R> extends Array<infer T> ? T : Awaited<R> : never;
22
+ } ? D extends unknown ? Awaited<R> : D extends any[] ? Awaited<AsArray<R>> : Awaited<Single<R>> : never;
23
+ export declare type InferCreateResultSingle<S> = Single<InferCreateResult<S>>;
25
24
  export declare type InferUpdateResult<S> = S extends {
26
25
  update: (id: any, data: any, params: any) => infer R;
27
26
  } ? Awaited<R> : never;
28
- export declare type InferPatchResult<S, Id = any> = S extends {
27
+ export declare type InferPatchResult<S, IdOrNullable = any> = S extends {
29
28
  patch: (id: Id, data: any, params: any) => infer R;
30
- } ? Awaited<R> : never;
31
- export declare type InferRemoveResult<S, Id = any> = S extends {
32
- remove: (id: Id, params: any) => infer R;
33
- } ? Awaited<R> : never;
29
+ } ? IdOrNullable extends Id ? Awaited<Single<R>> : IdOrNullable extends null ? Awaited<AsArray<R>> : Awaited<R> : never;
30
+ export declare type InferRemoveResult<S, IdOrNullable = any> = S extends {
31
+ remove: (id: IdOrNullable, params: any) => infer R;
32
+ } ? IdOrNullable extends Id ? Awaited<Single<R>> : IdOrNullable extends null ? Awaited<AsArray<R>> : Awaited<R> : never;
33
+ export declare type GetService<App extends Application, Path extends string> = App["services"][Path];
34
+ export declare type InferGetResultFromPath<App extends Application, Path extends string> = InferGetResult<GetService<App, Path>>;
35
+ export declare type InferFindResultFromPath<App extends Application, Path extends string> = InferFindResult<GetService<App, Path>>;
36
+ export declare type InferCreateDataFromPath<App extends Application, Path extends string> = InferCreateData<GetService<App, Path>>;
37
+ export declare type InferCreateDataSingleFromPath<App extends Application, Path extends string> = InferCreateDataSingle<GetService<App, Path>>;
38
+ export declare type InferCreateResultFromPath<App extends Application, Path extends string> = InferCreateResult<GetService<App, Path>>;
39
+ export declare type InferCreateResultSingleFromPath<App extends Application, Path extends string> = InferCreateResultSingle<GetService<App, Path>>;
40
+ export declare type InferUpdateDataFromPath<App extends Application, Path extends string> = InferUpdateData<GetService<App, Path>>;
41
+ export declare type InferPatchDataFromPath<App extends Application, Path extends string> = InferPatchData<GetService<App, Path>>;
42
+ export declare type InferUpdateResultFromPath<App extends Application, Path extends string> = InferUpdateResult<GetService<App, Path>>;
43
+ export declare type InferPatchResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferPatchResult<GetService<App, Path>, IdOrNullable>;
44
+ export declare type InferRemoveResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferRemoveResult<GetService<App, Path>, IdOrNullable>;
45
+ export declare type InferDataFromPath<App extends Application, Path extends string, Method extends "create" | "update" | "patch"> = Method extends "create" ? InferCreateDataFromPath<App, Path> : Method extends "update" ? InferUpdateDataFromPath<App, Path> : Method extends "patch" ? InferPatchDataFromPath<App, Path> : never;
46
+ export declare type InferResultFromPath<App extends Application, Path extends string, Method extends "get" | "find" | "create" | "update" | "patch" | "remove"> = Method extends "get" ? InferGetResultFromPath<App, Path> : Method extends "find" ? InferFindResultFromPath<App, Path> : Method extends "create" ? InferCreateResultFromPath<App, Path> : Method extends "update" ? InferUpdateResultFromPath<App, Path> : Method extends "patch" ? InferPatchResultFromPath<App, Path> : Method extends "remove" ? InferRemoveResultFromPath<App, Path> : never;
47
+ export {};
@@ -1,9 +1,10 @@
1
+ import type { Application, Id } from "@feathersjs/feathers";
2
+ declare type Single<T> = T extends Array<infer U> ? U : T;
3
+ declare type AsArray<T> = T extends any[] ? T : [T];
1
4
  export declare type InferCreateData<S> = S extends {
2
5
  create: (data: infer D, params: any) => any;
3
6
  } ? D : never;
4
- export declare type InferCreateDataSingle<S> = S extends {
5
- create: (data: infer D, params: any) => any;
6
- } ? D extends Array<infer T> ? T : D : never;
7
+ export declare type InferCreateDataSingle<S> = Single<InferCreateData<S>>;
7
8
  export declare type InferUpdateData<S> = S extends {
8
9
  update: (id: any, data: infer D, params: any) => any;
9
10
  } ? D : never;
@@ -16,18 +17,31 @@ export declare type InferGetResult<S> = S extends {
16
17
  export declare type InferFindResult<S> = S extends {
17
18
  find: (params: any) => infer R;
18
19
  } ? Awaited<R> : never;
19
- export declare type InferCreateResult<S, D = any> = S extends {
20
- create: (data: D, params: any) => infer R;
21
- } ? Awaited<R> : never;
22
- export declare type InferCreateResultSingle<S> = S extends {
20
+ export declare type InferCreateResult<S, D = unknown> = S extends {
23
21
  create: (data: any, params: any) => infer R;
24
- } ? Awaited<R> extends Array<infer T> ? T : Awaited<R> : never;
22
+ } ? D extends unknown ? Awaited<R> : D extends any[] ? Awaited<AsArray<R>> : Awaited<Single<R>> : never;
23
+ export declare type InferCreateResultSingle<S> = Single<InferCreateResult<S>>;
25
24
  export declare type InferUpdateResult<S> = S extends {
26
25
  update: (id: any, data: any, params: any) => infer R;
27
26
  } ? Awaited<R> : never;
28
- export declare type InferPatchResult<S, Id = any> = S extends {
27
+ export declare type InferPatchResult<S, IdOrNullable = any> = S extends {
29
28
  patch: (id: Id, data: any, params: any) => infer R;
30
- } ? Awaited<R> : never;
31
- export declare type InferRemoveResult<S, Id = any> = S extends {
32
- remove: (id: Id, params: any) => infer R;
33
- } ? Awaited<R> : never;
29
+ } ? IdOrNullable extends Id ? Awaited<Single<R>> : IdOrNullable extends null ? Awaited<AsArray<R>> : Awaited<R> : never;
30
+ export declare type InferRemoveResult<S, IdOrNullable = any> = S extends {
31
+ remove: (id: IdOrNullable, params: any) => infer R;
32
+ } ? IdOrNullable extends Id ? Awaited<Single<R>> : IdOrNullable extends null ? Awaited<AsArray<R>> : Awaited<R> : never;
33
+ export declare type GetService<App extends Application, Path extends string> = App["services"][Path];
34
+ export declare type InferGetResultFromPath<App extends Application, Path extends string> = InferGetResult<GetService<App, Path>>;
35
+ export declare type InferFindResultFromPath<App extends Application, Path extends string> = InferFindResult<GetService<App, Path>>;
36
+ export declare type InferCreateDataFromPath<App extends Application, Path extends string> = InferCreateData<GetService<App, Path>>;
37
+ export declare type InferCreateDataSingleFromPath<App extends Application, Path extends string> = InferCreateDataSingle<GetService<App, Path>>;
38
+ export declare type InferCreateResultFromPath<App extends Application, Path extends string> = InferCreateResult<GetService<App, Path>>;
39
+ export declare type InferCreateResultSingleFromPath<App extends Application, Path extends string> = InferCreateResultSingle<GetService<App, Path>>;
40
+ export declare type InferUpdateDataFromPath<App extends Application, Path extends string> = InferUpdateData<GetService<App, Path>>;
41
+ export declare type InferPatchDataFromPath<App extends Application, Path extends string> = InferPatchData<GetService<App, Path>>;
42
+ export declare type InferUpdateResultFromPath<App extends Application, Path extends string> = InferUpdateResult<GetService<App, Path>>;
43
+ export declare type InferPatchResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferPatchResult<GetService<App, Path>, IdOrNullable>;
44
+ export declare type InferRemoveResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferRemoveResult<GetService<App, Path>, IdOrNullable>;
45
+ export declare type InferDataFromPath<App extends Application, Path extends string, Method extends "create" | "update" | "patch"> = Method extends "create" ? InferCreateDataFromPath<App, Path> : Method extends "update" ? InferUpdateDataFromPath<App, Path> : Method extends "patch" ? InferPatchDataFromPath<App, Path> : never;
46
+ export declare type InferResultFromPath<App extends Application, Path extends string, Method extends "get" | "find" | "create" | "update" | "patch" | "remove"> = Method extends "get" ? InferGetResultFromPath<App, Path> : Method extends "find" ? InferFindResultFromPath<App, Path> : Method extends "create" ? InferCreateResultFromPath<App, Path> : Method extends "update" ? InferUpdateResultFromPath<App, Path> : Method extends "patch" ? InferPatchResultFromPath<App, Path> : Method extends "remove" ? InferRemoveResultFromPath<App, Path> : never;
47
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feathers-utils",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "Some utils for projects using '@feathersjs/feathers'",
5
5
  "author": "fratzinger",
6
6
  "repository": {
@@ -1,16 +1,15 @@
1
+ import type { Application, Id } from "@feathersjs/feathers";
2
+
3
+ type Single<T> = T extends Array<infer U> ? U : T;
4
+ type AsArray<T> = T extends any[] ? T : [T];
5
+
1
6
  export type InferCreateData<S> = S extends {
2
7
  create: (data: infer D, params: any) => any;
3
8
  }
4
9
  ? D
5
10
  : never;
6
11
 
7
- export type InferCreateDataSingle<S> = S extends {
8
- create: (data: infer D, params: any) => any;
9
- }
10
- ? D extends Array<infer T>
11
- ? T
12
- : D
13
- : never;
12
+ export type InferCreateDataSingle<S> = Single<InferCreateData<S>>;
14
13
 
15
14
  export type InferUpdateData<S> = S extends {
16
15
  update: (id: any, data: infer D, params: any) => any;
@@ -36,34 +35,81 @@ export type InferFindResult<S> = S extends {
36
35
  ? Awaited<R>
37
36
  : never;
38
37
 
39
- export type InferCreateResult<S, D = any> = S extends {
40
- create: (data: D, params: any) => infer R;
41
- }
42
- ? Awaited<R>
43
- : never;
44
-
45
- export type InferCreateResultSingle<S> = S extends {
38
+ export type InferCreateResult<S, D = unknown> = S extends {
46
39
  create: (data: any, params: any) => infer R;
47
40
  }
48
- ? Awaited<R> extends Array<infer T>
49
- ? T
50
- : Awaited<R>
41
+ ? D extends unknown
42
+ ? Awaited<R>
43
+ : D extends any[]
44
+ ? Awaited<AsArray<R>>
45
+ : Awaited<Single<R>>
51
46
  : never;
52
47
 
48
+ export type InferCreateResultSingle<S> = Single<InferCreateResult<S>>;
49
+
53
50
  export type InferUpdateResult<S> = S extends {
54
51
  update: (id: any, data: any, params: any) => infer R;
55
52
  }
56
53
  ? Awaited<R>
57
54
  : never;
58
55
 
59
- export type InferPatchResult<S, Id = any> = S extends {
56
+ export type InferPatchResult<S, IdOrNullable = any> = S extends {
60
57
  patch: (id: Id, data: any, params: any) => infer R;
61
58
  }
62
- ? Awaited<R>
59
+ ? IdOrNullable extends Id
60
+ ? Awaited<Single<R>>
61
+ : IdOrNullable extends null
62
+ ? Awaited<AsArray<R>>
63
+ : Awaited<R>
63
64
  : never;
64
65
 
65
- export type InferRemoveResult<S, Id = any> = S extends {
66
- remove: (id: Id, params: any) => infer R;
66
+ export type InferRemoveResult<S, IdOrNullable = any> = S extends {
67
+ remove: (id: IdOrNullable, params: any) => infer R;
67
68
  }
68
- ? Awaited<R>
69
+ ? IdOrNullable extends Id
70
+ ? Awaited<Single<R>>
71
+ : IdOrNullable extends null
72
+ ? Awaited<AsArray<R>>
73
+ : Awaited<R>
69
74
  : never;
75
+
76
+ export type GetService<App extends Application, Path extends string> = App["services"][Path];
77
+
78
+ export type InferGetResultFromPath<App extends Application, Path extends string> = InferGetResult<GetService<App, Path>>;
79
+ export type InferFindResultFromPath<App extends Application, Path extends string> = InferFindResult<GetService<App, Path>>;
80
+
81
+ export type InferCreateDataFromPath<App extends Application, Path extends string> = InferCreateData<GetService<App, Path>>
82
+ export type InferCreateDataSingleFromPath<App extends Application, Path extends string> = InferCreateDataSingle<GetService<App, Path>>;
83
+ export type InferCreateResultFromPath<App extends Application, Path extends string> = InferCreateResult<GetService<App, Path>>;
84
+ export type InferCreateResultSingleFromPath<App extends Application, Path extends string> = InferCreateResultSingle<GetService<App, Path>>;
85
+
86
+ export type InferUpdateDataFromPath<App extends Application, Path extends string> = InferUpdateData<GetService<App, Path>>
87
+ export type InferPatchDataFromPath<App extends Application, Path extends string> = InferPatchData<GetService<App, Path>>
88
+
89
+ export type InferUpdateResultFromPath<App extends Application, Path extends string> = InferUpdateResult<GetService<App, Path>>;
90
+ export type InferPatchResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferPatchResult<GetService<App, Path>, IdOrNullable>;
91
+
92
+ export type InferRemoveResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferRemoveResult<GetService<App, Path>, IdOrNullable>;
93
+
94
+ export type InferDataFromPath<App extends Application, Path extends string, Method extends "create" | "update" | "patch"> = Method extends "create"
95
+ ? InferCreateDataFromPath<App, Path>
96
+ : Method extends "update"
97
+ ? InferUpdateDataFromPath<App, Path>
98
+ : Method extends "patch"
99
+ ? InferPatchDataFromPath<App, Path>
100
+ : never;
101
+
102
+ export type InferResultFromPath<App extends Application, Path extends string, Method extends "get" | "find" | "create" | "update" | "patch" | "remove"> = Method extends "get"
103
+ ? InferGetResultFromPath<App, Path>
104
+ : Method extends "find"
105
+ ? InferFindResultFromPath<App, Path>
106
+ : Method extends "create"
107
+ ? InferCreateResultFromPath<App, Path>
108
+ : Method extends "update"
109
+ ? InferUpdateResultFromPath<App, Path>
110
+ : Method extends "patch"
111
+ ? InferPatchResultFromPath<App, Path>
112
+ : Method extends "remove"
113
+ ? InferRemoveResultFromPath<App, Path>
114
+ : never;
115
+