@primate/core 0.9.0 → 0.9.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.
|
@@ -5,18 +5,18 @@ import type RouteHandler from "#route/Handler";
|
|
|
5
5
|
import hook from "#route/hook";
|
|
6
6
|
import type RouteOptions from "#route/Options";
|
|
7
7
|
import type { Unpack } from "@rcompat/type";
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
} ?
|
|
8
|
+
type InputSchema<S> = S extends {
|
|
9
|
+
input: infer I;
|
|
10
|
+
} ? I : never;
|
|
11
11
|
type Body<O extends RouteOptions> = O extends {
|
|
12
12
|
contentType: infer _CT extends keyof ContentTypeMap;
|
|
13
13
|
body: infer S;
|
|
14
|
-
} ? Unpack<
|
|
14
|
+
} ? Unpack<InputSchema<S>> : O extends {
|
|
15
15
|
contentType: infer CT extends keyof ContentTypeMap;
|
|
16
16
|
} ? ContentTypeMap[CT] : never;
|
|
17
17
|
type Path<O extends RouteOptions> = O extends {
|
|
18
18
|
path: infer S;
|
|
19
|
-
} ? Unpack<
|
|
19
|
+
} ? Unpack<InputSchema<S>> : never;
|
|
20
20
|
type MethodMeta = {
|
|
21
21
|
contentType?: string;
|
|
22
22
|
};
|
package/lib/private/route.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import type ResponseFunction from "#response/ResponseFunction";
|
|
2
|
+
import type ResponseLike from "#response/ResponseLike";
|
|
2
3
|
import type NarrowedRequest from "#route/NarrowedRequest";
|
|
3
4
|
import type RouteHandler from "#route/Handler";
|
|
4
5
|
import hook from "#route/hook";
|
|
5
6
|
import type RouteOptions from "#route/Options";
|
|
6
7
|
import type { Method } from "@rcompat/http";
|
|
7
8
|
declare const BRAND: unique symbol;
|
|
8
|
-
type WithResult<O extends RouteOptions> = {
|
|
9
|
+
type WithResult<O extends RouteOptions, R extends ResponseLike> = {
|
|
9
10
|
[BRAND]: true;
|
|
10
|
-
handler:
|
|
11
|
+
handler: RouteHandler<O, R>;
|
|
11
12
|
options: O;
|
|
12
13
|
};
|
|
13
14
|
type Page<R> = Awaited<R> extends ResponseFunction<infer Props> ? Props : never;
|
|
14
|
-
type AnyHandler = RouteHandler | WithResult<RouteOptions>;
|
|
15
|
+
type AnyHandler = RouteHandler | WithResult<RouteOptions, ResponseLike>;
|
|
15
16
|
type RouteHandlers = {
|
|
16
17
|
[key in Method]?: AnyHandler;
|
|
17
18
|
};
|
|
@@ -24,13 +25,11 @@ type RouteMethodWithResult<O extends RouteOptions, R> = Omit<RouteMethod<O>, "Pa
|
|
|
24
25
|
Page: Page<R>;
|
|
25
26
|
};
|
|
26
27
|
type Routes<R extends RouteHandlers> = {
|
|
27
|
-
[K in keyof R]: R[K] extends WithResult<infer O extends RouteOptions> ? R[K] extends {
|
|
28
|
-
handler: (...args: any[]) => infer Result;
|
|
29
|
-
} ? RouteMethodWithResult<O, Result> : RouteMethod<O> : R[K] extends (...args: any[]) => infer Result ? RouteMethodWithResult<{}, Result> : RouteMethod<{}>;
|
|
28
|
+
[K in keyof R]: R[K] extends WithResult<infer O extends RouteOptions, infer Result> ? RouteMethodWithResult<O, Result> : R[K] extends (...args: any[]) => infer Result ? RouteMethodWithResult<{}, Result> : RouteMethod<{}>;
|
|
30
29
|
};
|
|
31
30
|
declare function route<R extends RouteHandlers>(handlers: R): Routes<R>;
|
|
32
31
|
declare namespace route {
|
|
33
|
-
var _a: <O extends RouteOptions>(options: O, handler: RouteHandler<O>) => WithResult<O>;
|
|
32
|
+
var _a: <O extends RouteOptions, R extends ResponseLike>(options: O, handler: RouteHandler<O, R>) => WithResult<O, R>;
|
|
34
33
|
export { _a as with };
|
|
35
34
|
export { hook };
|
|
36
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "The universal web framework",
|
|
5
5
|
"homepage": "https://primate.run",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@rcompat/symbol": "^0.3.0",
|
|
36
36
|
"@rcompat/type": "^0.18.0",
|
|
37
37
|
"esbuild": "^0.28.1",
|
|
38
|
-
"pema": "^0.9.
|
|
38
|
+
"pema": "^0.9.1"
|
|
39
39
|
},
|
|
40
40
|
"imports": {
|
|
41
41
|
"#i18n/config": {
|