rouzer 1.0.0-beta.17 → 1.0.0-beta.19
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 +7 -3
- package/dist/route.d.ts +2 -2
- 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]:
|
|
27
|
+
}): { [K in keyof TRoutes]: TRoutes[K]["methods"] extends infer TMethods ? { [M in keyof TMethods]: RouteFunction<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,11 @@ 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
|
-
|
|
57
|
+
/**
|
|
58
|
+
* This function sends a request to a route of the same name. Such a function is
|
|
59
|
+
* accessible by setting the `routes` option when creating a Rouzer client,
|
|
60
|
+
* where it will exist as a method on the client.
|
|
61
|
+
*/
|
|
62
|
+
export type RouteFunction<T extends RouteSchema, P extends string> = (...p: RouteArgs<T, P> extends infer TArgs ? {} extends TArgs ? [args?: TArgs] : [args: TArgs] : never) => Promise<T extends {
|
|
58
63
|
response: any;
|
|
59
64
|
} ? InferRouteResponse<T> : Response>;
|
|
60
|
-
export {};
|
package/dist/route.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RoutePattern } from '@remix-run/route-pattern';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RouteRequestFactory, RouteSchema, RouteSchemaMap, Unchecked } from './types.js';
|
|
3
3
|
export declare function $type<T>(): Unchecked<T>;
|
|
4
4
|
export type Route<P extends string = string, T extends RouteSchemaMap = RouteSchemaMap> = {
|
|
5
5
|
path: RoutePattern<P>;
|
|
6
6
|
methods: T;
|
|
7
7
|
} & {
|
|
8
|
-
[K in keyof T]:
|
|
8
|
+
[K in keyof T]: RouteRequestFactory<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
|
|
83
|
-
(
|
|
84
|
-
$args: RouteArgs<T>;
|
|
86
|
+
export type RouteRequestFactory<T extends RouteSchema, P extends string> = {
|
|
87
|
+
(...p: RouteArgs<T, P> extends infer TArgs ? {} extends TArgs ? [args?: TArgs] : [args: TArgs] : never): RouteRequest<InferRouteResponse<T>>;
|
|
88
|
+
$args: RouteArgs<T, P>;
|
|
85
89
|
$response: InferRouteResponse<T>;
|
|
86
90
|
};
|
|
87
91
|
export {};
|