rouzer 1.0.0-beta.17 → 1.0.0-beta.18
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/client/index.d.ts +2 -2
- package/dist/route.d.ts +1 -1
- package/dist/types.d.ts +13 -9
- package/package.json +1 -1
package/dist/client/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare function createClient<TRoutes extends Record<string, Route> = Rec
|
|
|
24
24
|
* response is always parsed as JSON, regardless of the HTTP status code.
|
|
25
25
|
*/
|
|
26
26
|
onJsonError?: (response: Response) => Promisable<Response>;
|
|
27
|
-
}): { [K in keyof TRoutes]: TRoutes[K]["methods"] extends infer TMethods ? { [M in keyof TMethods]: RouteRequestFunction<Extract<TMethods[M], RouteSchema
|
|
27
|
+
}): { [K in keyof TRoutes]: TRoutes[K]["methods"] extends infer TMethods ? { [M in keyof TMethods]: RouteRequestFunction<Extract<TMethods[M], RouteSchema>, TRoutes[K]["path"]["source"]>; } : never; } & {
|
|
28
28
|
config: {
|
|
29
29
|
/**
|
|
30
30
|
* Base URL to use for all requests.
|
|
@@ -54,7 +54,7 @@ export declare function createClient<TRoutes extends Record<string, Route> = Rec
|
|
|
54
54
|
}>;
|
|
55
55
|
json: <T extends RouteRequest>(props: T) => Promise<T["$result"]>;
|
|
56
56
|
};
|
|
57
|
-
type RouteRequestFunction<T extends RouteSchema> = (args: RouteArgs<T>) => Promise<T extends {
|
|
57
|
+
type RouteRequestFunction<T extends RouteSchema, P extends string> = (args: RouteArgs<T, P>) => Promise<T extends {
|
|
58
58
|
response: any;
|
|
59
59
|
} ? InferRouteResponse<T> : Response>;
|
|
60
60
|
export {};
|
package/dist/route.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export type Route<P extends string = string, T extends RouteSchemaMap = RouteSch
|
|
|
5
5
|
path: RoutePattern<P>;
|
|
6
6
|
methods: T;
|
|
7
7
|
} & {
|
|
8
|
-
[K in keyof T]: RouteFunction<Extract<T[K], RouteSchema
|
|
8
|
+
[K in keyof T]: RouteFunction<Extract<T[K], RouteSchema>, P>;
|
|
9
9
|
};
|
|
10
10
|
export declare function route<P extends string, T extends RouteSchemaMap>(pattern: P, methods: T): Route<P, T>;
|
package/dist/types.d.ts
CHANGED
|
@@ -36,13 +36,17 @@ export type Routes = {
|
|
|
36
36
|
declare class Any {
|
|
37
37
|
private isAny;
|
|
38
38
|
}
|
|
39
|
-
type PathArgs<T> = T extends {
|
|
40
|
-
path: infer TPath
|
|
41
|
-
} ?
|
|
39
|
+
type PathArgs<T, P extends string> = T extends {
|
|
40
|
+
path: infer TPath;
|
|
41
|
+
} ? {} extends z.infer<TPath> ? {
|
|
42
|
+
path?: z.infer<TPath>;
|
|
43
|
+
} : {
|
|
44
|
+
path: z.infer<TPath>;
|
|
45
|
+
} : Params<P> extends infer TParams ? {} extends TParams ? {
|
|
42
46
|
path?: TParams;
|
|
43
47
|
} : {
|
|
44
48
|
path: TParams;
|
|
45
|
-
} : unknown
|
|
49
|
+
} : unknown;
|
|
46
50
|
type QueryArgs<T> = T extends QueryRouteSchema & {
|
|
47
51
|
query: infer TQuery;
|
|
48
52
|
} ? {} extends z.infer<TQuery> ? {
|
|
@@ -59,11 +63,11 @@ type MutationArgs<T> = T extends MutationRouteSchema ? T extends {
|
|
|
59
63
|
} : {
|
|
60
64
|
body?: unknown;
|
|
61
65
|
} : unknown;
|
|
62
|
-
export type RouteArgs<T extends RouteSchema = any> = ([T] extends [Any] ? {
|
|
66
|
+
export type RouteArgs<T extends RouteSchema = any, P extends string = string> = ([T] extends [Any] ? {
|
|
63
67
|
query?: any;
|
|
64
68
|
body?: any;
|
|
65
69
|
path?: any;
|
|
66
|
-
} : QueryArgs<T> & MutationArgs<T> & PathArgs<T>) & Omit<RequestInit, 'method' | 'body' | 'headers'> & {
|
|
70
|
+
} : QueryArgs<T> & MutationArgs<T> & PathArgs<T, P>) & Omit<RequestInit, 'method' | 'body' | 'headers'> & {
|
|
67
71
|
headers?: Record<string, string | undefined>;
|
|
68
72
|
};
|
|
69
73
|
export type RouteRequest<TResult = any> = {
|
|
@@ -79,9 +83,9 @@ export type RouteResponse<TResult = any> = Response & {
|
|
|
79
83
|
export type InferRouteResponse<T extends RouteSchema> = T extends {
|
|
80
84
|
response: Unchecked<infer TResponse>;
|
|
81
85
|
} ? TResponse : void;
|
|
82
|
-
export type RouteFunction<T extends RouteSchema> = {
|
|
83
|
-
(args: RouteArgs<T>): RouteRequest<InferRouteResponse<T>>;
|
|
84
|
-
$args: RouteArgs<T>;
|
|
86
|
+
export type RouteFunction<T extends RouteSchema, P extends string> = {
|
|
87
|
+
(args: RouteArgs<T, P>): RouteRequest<InferRouteResponse<T>>;
|
|
88
|
+
$args: RouteArgs<T, P>;
|
|
85
89
|
$response: InferRouteResponse<T>;
|
|
86
90
|
};
|
|
87
91
|
export {};
|