rouzer 3.0.1 → 3.0.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/package.json +2 -2
- package/dist/internal.d.ts +0 -17
- package/dist/internal.js +0 -1
- package/dist/server/types.d.ts +0 -42
- package/dist/server/types.js +0 -1
- package/dist/types.d.ts +0 -140
- package/dist/types.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rouzer",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"!*.tsbuildinfo"
|
|
48
48
|
],
|
|
49
49
|
"scripts": {
|
|
50
|
-
"build": "tsgo -b tsconfig.json",
|
|
50
|
+
"build": "rm -rf dist && tsgo -b tsconfig.json",
|
|
51
51
|
"test": "vitest run"
|
|
52
52
|
}
|
|
53
53
|
}
|
package/dist/internal.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { RoutePattern } from '@remix-run/route-pattern';
|
|
2
|
-
import type { RouteRequestFactory, RouteSchema } from './types.js';
|
|
3
|
-
/** @internal */
|
|
4
|
-
export type RouteSchemaMap = {
|
|
5
|
-
GET?: RouteSchema;
|
|
6
|
-
POST?: RouteSchema;
|
|
7
|
-
PUT?: RouteSchema;
|
|
8
|
-
PATCH?: RouteSchema;
|
|
9
|
-
DELETE?: RouteSchema;
|
|
10
|
-
};
|
|
11
|
-
/** @internal */
|
|
12
|
-
export type Route<P extends string = string, T extends RouteSchemaMap = RouteSchemaMap> = {
|
|
13
|
-
path: RoutePattern<P>;
|
|
14
|
-
methods: T;
|
|
15
|
-
} & {
|
|
16
|
-
[K in keyof T]: RouteRequestFactory<Extract<T[K], RouteSchema>, P>;
|
|
17
|
-
};
|
package/dist/internal.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/server/types.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { MatchParams } from '@remix-run/route-pattern/match';
|
|
2
|
-
import type { AnyMiddlewareChain, MiddlewareChain, MiddlewareContext } from 'alien-middleware';
|
|
3
|
-
import type * as z from 'zod';
|
|
4
|
-
import { Promisable } from '../common.js';
|
|
5
|
-
import type { HttpAction, HttpResource, HttpRouteTree } from '../http.js';
|
|
6
|
-
import type { InferRouteResponse, RouteSchema } from '../types.js';
|
|
7
|
-
type RequestContext<TMiddleware extends AnyMiddlewareChain> = MiddlewareContext<TMiddleware>;
|
|
8
|
-
type RouteRequestHandler<TMiddleware extends AnyMiddlewareChain, TArgs extends object, TResult> = (context: RequestContext<TMiddleware> & TArgs) => Promisable<TResult | Response>;
|
|
9
|
-
type InferActionHandler<TMiddleware extends AnyMiddlewareChain, TAction extends HttpAction, TPath extends string> = TAction['method'] extends 'GET' ? RouteRequestHandler<TMiddleware, {
|
|
10
|
-
path: TAction['schema'] extends {
|
|
11
|
-
path: any;
|
|
12
|
-
} ? z.infer<TAction['schema']['path']> : MatchParams<TPath>;
|
|
13
|
-
query: TAction['schema'] extends {
|
|
14
|
-
query: any;
|
|
15
|
-
} ? z.infer<TAction['schema']['query']> : undefined;
|
|
16
|
-
headers: TAction['schema'] extends {
|
|
17
|
-
headers: any;
|
|
18
|
-
} ? z.infer<TAction['schema']['headers']> : undefined;
|
|
19
|
-
}, InferRouteResponse<Extract<TAction['schema'], RouteSchema>>> : RouteRequestHandler<TMiddleware, {
|
|
20
|
-
path: TAction['schema'] extends {
|
|
21
|
-
path: any;
|
|
22
|
-
} ? z.infer<TAction['schema']['path']> : MatchParams<TPath>;
|
|
23
|
-
body: TAction['schema'] extends {
|
|
24
|
-
body: any;
|
|
25
|
-
} ? z.infer<TAction['schema']['body']> : undefined;
|
|
26
|
-
headers: TAction['schema'] extends {
|
|
27
|
-
headers: any;
|
|
28
|
-
} ? z.infer<TAction['schema']['headers']> : undefined;
|
|
29
|
-
}, InferRouteResponse<Extract<TAction['schema'], RouteSchema>>>;
|
|
30
|
-
type Join<A extends string, B extends string> = A extends '' ? B : B extends '' ? A : `${A}/${B}`;
|
|
31
|
-
/**
|
|
32
|
-
* Handler map shape required by `createRouter().use(routes, handlers)`.
|
|
33
|
-
*
|
|
34
|
-
* @remarks The handler object mirrors the HTTP route tree. Resource nodes become
|
|
35
|
-
* nested handler objects, while action nodes become direct handler functions.
|
|
36
|
-
* Handler context is inferred from middleware plus accumulated path params,
|
|
37
|
-
* query/body schemas, and header schemas.
|
|
38
|
-
*/
|
|
39
|
-
export type RouteRequestHandlerMap<TRoutes extends HttpRouteTree = HttpRouteTree, TMiddleware extends AnyMiddlewareChain = MiddlewareChain, TPrefix extends string = ''> = {
|
|
40
|
-
[K in keyof TRoutes]: TRoutes[K] extends HttpResource<infer P, infer C> ? RouteRequestHandlerMap<C, TMiddleware, Join<TPrefix, P>> : TRoutes[K] extends HttpAction<infer P, any, any> ? InferActionHandler<TMiddleware, TRoutes[K], Join<TPrefix, P>> : never;
|
|
41
|
-
};
|
|
42
|
-
export {};
|
package/dist/server/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types.d.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import type { MatchParams } from '@remix-run/route-pattern/match';
|
|
2
|
-
import { RoutePattern } from '@remix-run/route-pattern';
|
|
3
|
-
import * as z from 'zod';
|
|
4
|
-
import { Unchecked } from './common.js';
|
|
5
|
-
/**
|
|
6
|
-
* Compile-time-only marker used by `$type<T>()` for unchecked response types.
|
|
7
|
-
*
|
|
8
|
-
* @remarks Application code should usually call `$type<T>()` instead of naming
|
|
9
|
-
* this marker directly.
|
|
10
|
-
*/
|
|
11
|
-
export type { Unchecked };
|
|
12
|
-
/** Schema shape for `GET` route methods. */
|
|
13
|
-
export type QueryRouteSchema = {
|
|
14
|
-
/** Optional Zod object used to validate path params. */
|
|
15
|
-
path?: z.ZodObject<any>;
|
|
16
|
-
/** Optional Zod object used to validate URL query params. */
|
|
17
|
-
query?: z.ZodObject<any>;
|
|
18
|
-
/** `GET` routes do not accept request bodies. */
|
|
19
|
-
body?: never;
|
|
20
|
-
/** Optional Zod object used to validate request headers. */
|
|
21
|
-
headers?: z.ZodObject<any>;
|
|
22
|
-
/** Optional compile-time-only JSON response type marker. */
|
|
23
|
-
response?: Unchecked<any>;
|
|
24
|
-
};
|
|
25
|
-
/** Schema shape for mutation route methods. */
|
|
26
|
-
export type MutationRouteSchema = {
|
|
27
|
-
/** Optional Zod object used to validate path params. */
|
|
28
|
-
path?: z.ZodObject<any>;
|
|
29
|
-
/** Mutation routes do not accept query schemas. */
|
|
30
|
-
query?: never;
|
|
31
|
-
/** Optional Zod schema used to validate the JSON request body. */
|
|
32
|
-
body?: z.ZodType<any, any>;
|
|
33
|
-
/** Optional Zod object used to validate request headers. */
|
|
34
|
-
headers?: z.ZodObject<any>;
|
|
35
|
-
/** Optional compile-time-only JSON response type marker. */
|
|
36
|
-
response?: Unchecked<any>;
|
|
37
|
-
};
|
|
38
|
-
/** Any HTTP action schema Rouzer can execute. */
|
|
39
|
-
export type RouteSchema = QueryRouteSchema | MutationRouteSchema;
|
|
40
|
-
declare class Any {
|
|
41
|
-
private isAny;
|
|
42
|
-
}
|
|
43
|
-
type PathArgs<T, P extends string> = T extends {
|
|
44
|
-
path: infer TPath;
|
|
45
|
-
} ? {} extends z.infer<TPath> ? {
|
|
46
|
-
[K in keyof T as 'path']?: z.infer<TPath>;
|
|
47
|
-
} : {
|
|
48
|
-
[K in keyof T as 'path']: z.infer<TPath>;
|
|
49
|
-
} : MatchParams<P> extends infer TParams ? {} extends TParams ? {
|
|
50
|
-
[K in keyof T as 'path']?: TParams;
|
|
51
|
-
} : {
|
|
52
|
-
[K in keyof T as 'path']: TParams;
|
|
53
|
-
} : unknown;
|
|
54
|
-
type QueryArgs<T> = T extends QueryRouteSchema & {
|
|
55
|
-
query: infer TQuery;
|
|
56
|
-
} ? {} extends z.infer<TQuery> ? {
|
|
57
|
-
[K in keyof T as 'query']?: z.infer<TQuery>;
|
|
58
|
-
} : {
|
|
59
|
-
[K in keyof T as 'query']: z.infer<TQuery>;
|
|
60
|
-
} : unknown;
|
|
61
|
-
type MutationArgs<T> = T extends MutationRouteSchema ? T extends {
|
|
62
|
-
body: infer TBody;
|
|
63
|
-
} ? {} extends z.infer<TBody> ? {
|
|
64
|
-
[K in keyof T as 'body']?: z.infer<TBody>;
|
|
65
|
-
} : {
|
|
66
|
-
[K in keyof T as 'body']: z.infer<TBody>;
|
|
67
|
-
} : {
|
|
68
|
-
body?: unknown;
|
|
69
|
-
} : unknown;
|
|
70
|
-
/**
|
|
71
|
-
* Arguments accepted by a client action function or low-level request factory.
|
|
72
|
-
*
|
|
73
|
-
* @remarks The type is derived from an action schema and route pattern. `path`,
|
|
74
|
-
* `query`, `body`, and `headers` are validated by the client before `fetch` when
|
|
75
|
-
* a matching schema exists. Other `RequestInit` fields are forwarded to `fetch`,
|
|
76
|
-
* except `method`, `body`, and `headers`, which Rouzer derives from the action
|
|
77
|
-
* schema and call arguments.
|
|
78
|
-
*/
|
|
79
|
-
export type RouteArgs<T extends RouteSchema = any, P extends string = string> = ([T] extends [Any] ? {
|
|
80
|
-
query?: any;
|
|
81
|
-
body?: any;
|
|
82
|
-
path?: any;
|
|
83
|
-
} : QueryArgs<T> & MutationArgs<T> & PathArgs<T, P>) & Omit<RequestInit, 'method' | 'body' | 'headers'> & {
|
|
84
|
-
/** Headers for this request. Undefined values are removed before `fetch`. */
|
|
85
|
-
headers?: Record<string, string | undefined>;
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Request descriptor produced by an HTTP action request factory.
|
|
89
|
-
*
|
|
90
|
-
* @remarks Pass this object to `client.request(...)` for a raw `Response` or
|
|
91
|
-
* `client.json(...)` for parsed JSON handling.
|
|
92
|
-
*/
|
|
93
|
-
export type RouteRequest<TResult = any> = {
|
|
94
|
-
/** Method schema used for client-side validation. */
|
|
95
|
-
schema: RouteSchema;
|
|
96
|
-
/** Parsed route pattern used to generate the request URL. */
|
|
97
|
-
path: RoutePattern;
|
|
98
|
-
/** HTTP method to send. */
|
|
99
|
-
method: string;
|
|
100
|
-
/** Validated route arguments and request options. */
|
|
101
|
-
args: RouteArgs;
|
|
102
|
-
/** Phantom result type consumed by `client.json(...)`. */
|
|
103
|
-
$result: TResult;
|
|
104
|
-
};
|
|
105
|
-
/** `Response` whose `.json()` method resolves to a known payload type. */
|
|
106
|
-
export type RouteResponse<TResult = any> = Response & {
|
|
107
|
-
json(): Promise<TResult>;
|
|
108
|
-
};
|
|
109
|
-
/** Infer the JSON response payload type from an action schema. */
|
|
110
|
-
export type InferRouteResponse<T extends RouteSchema> = T extends {
|
|
111
|
-
response: Unchecked<infer TResponse>;
|
|
112
|
-
} ? TResponse : void;
|
|
113
|
-
type InferRouteSchemaBody<TSchema> = TSchema extends MutationRouteSchema ? TSchema extends {
|
|
114
|
-
body: infer TBody;
|
|
115
|
-
} ? z.infer<TBody> : unknown : never;
|
|
116
|
-
type InferRouteArgsBody<TArgs> = TArgs extends {
|
|
117
|
-
body?: infer TBody;
|
|
118
|
-
} ? TBody : never;
|
|
119
|
-
/**
|
|
120
|
-
* Infer the request body type from an action schema or request factory.
|
|
121
|
-
*
|
|
122
|
-
* @remarks HTTP action schemas can be inspected with
|
|
123
|
-
* `InferRouteBody<typeof action.schema>`. Request factories for mutation actions
|
|
124
|
-
* infer their `body` argument type. Schemas without a body schema infer
|
|
125
|
-
* `unknown`.
|
|
126
|
-
*/
|
|
127
|
-
export type InferRouteBody<T> = T extends RouteRequestFactory<any, any> ? InferRouteArgsBody<T['$args']> : T extends RouteSchema ? InferRouteSchemaBody<T> : never;
|
|
128
|
-
/**
|
|
129
|
-
* Callable factory attached to an HTTP action.
|
|
130
|
-
*
|
|
131
|
-
* @remarks Calling a factory validates no data by itself; it creates a typed
|
|
132
|
-
* `RouteRequest` descriptor for `createClient` to validate and send.
|
|
133
|
-
*/
|
|
134
|
-
export type RouteRequestFactory<T extends RouteSchema, P extends string> = {
|
|
135
|
-
(...p: RouteArgs<T, P> extends infer TArgs ? {} extends TArgs ? [args?: TArgs] : [args: TArgs] : never): RouteRequest<InferRouteResponse<T>>;
|
|
136
|
-
/** Inferred argument type for this request factory. */
|
|
137
|
-
$args: RouteArgs<T, P>;
|
|
138
|
-
/** Inferred JSON response type for this request factory. */
|
|
139
|
-
$response: InferRouteResponse<T>;
|
|
140
|
-
};
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|