@primate/core 0.9.1 → 0.9.3
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/lib/private/request/route.js +2 -2
- package/lib/private/response/binary.d.ts +2 -2
- package/lib/private/response/binary.js +1 -1
- package/lib/private/response/error.d.ts +1 -1
- package/lib/private/response/json.d.ts +1 -1
- package/lib/private/response/null.d.ts +2 -1
- package/lib/private/response/redirect.d.ts +1 -1
- package/lib/private/response/sse.d.ts +1 -1
- package/lib/private/response/text.d.ts +1 -1
- package/lib/private/response/ws.d.ts +1 -1
- package/lib/private/response.d.ts +2 -3
- package/lib/private/route.client.d.ts +1 -1
- package/lib/private/route.d.ts +7 -8
- package/lib/public/response.d.ts +5 -5
- package/package.json +1 -1
|
@@ -65,10 +65,10 @@ export default async function (app, partial_request) {
|
|
|
65
65
|
catch (error) {
|
|
66
66
|
const request = partial_request;
|
|
67
67
|
if (ParseError.is(error)) {
|
|
68
|
-
return response_json(error.toJSON(), { status: http.Status.BAD_REQUEST })(app);
|
|
68
|
+
return response_json(error.toJSON(), { status: http.Status.BAD_REQUEST })(app, {}, request);
|
|
69
69
|
}
|
|
70
70
|
if (CodeError.matches(error, Code.request_content_type_mismatch)) {
|
|
71
|
-
return response_json({ error: error.message }, { status: http.Status.UNSUPPORTED_MEDIA_TYPE })(app);
|
|
71
|
+
return response_json({ error: error.message }, { status: http.Status.UNSUPPORTED_MEDIA_TYPE })(app, {}, request);
|
|
72
72
|
}
|
|
73
73
|
app.log.error(error);
|
|
74
74
|
// the +error.js page itself could fail
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type ResponseFunction from "#response/ResponseFunction";
|
|
2
2
|
import type { Streamable } from "@rcompat/fs";
|
|
3
3
|
/**
|
|
4
4
|
* Stream a binary response.
|
|
@@ -6,5 +6,5 @@ import type { Streamable } from "@rcompat/fs";
|
|
|
6
6
|
* @param options response options
|
|
7
7
|
* @return Response rendering function
|
|
8
8
|
*/
|
|
9
|
-
export default function binary(source: Streamable, init?: ResponseInit):
|
|
9
|
+
export default function binary(source: Streamable, init?: ResponseInit): ResponseFunction<never>;
|
|
10
10
|
//# sourceMappingURL=binary.d.ts.map
|
|
@@ -30,7 +30,7 @@ function toContentDisposition(filename) {
|
|
|
30
30
|
* @return Response rendering function
|
|
31
31
|
*/
|
|
32
32
|
export default function binary(source, init) {
|
|
33
|
-
return
|
|
33
|
+
return app => {
|
|
34
34
|
const { headers, ...rest } = app.media(http.MIME.APPLICATION_OCTET_STREAM, init);
|
|
35
35
|
const name = fs.isNamedStream(source) ? source.name : "default.bin";
|
|
36
36
|
const out = new Headers(headers);
|
|
@@ -13,6 +13,6 @@ type Options = {
|
|
|
13
13
|
* @param options.template HTML template to use (default: `error.html`).
|
|
14
14
|
* @return Response function.
|
|
15
15
|
*/
|
|
16
|
-
export default function error(options?: Options): ResponseFunction
|
|
16
|
+
export default function error(options?: Options): ResponseFunction<never>;
|
|
17
17
|
export {};
|
|
18
18
|
//# sourceMappingURL=error.d.ts.map
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* @param options response options
|
|
5
5
|
* @return Response rendering function
|
|
6
6
|
*/
|
|
7
|
-
declare const _default: (body: unknown, init?: ResponseInit) =>
|
|
7
|
+
declare const _default: (body: unknown, init?: ResponseInit) => import("./ResponseFunction.js").default<never>;
|
|
8
8
|
export default _default;
|
|
9
9
|
//# sourceMappingURL=json.d.ts.map
|
|
@@ -7,5 +7,5 @@ export default _default;
|
|
|
7
7
|
* @param status redirection 3xx code
|
|
8
8
|
* @return Response rendering function
|
|
9
9
|
*/
|
|
10
|
-
declare function _default(location: string, status?: Redirection): ResponseFunction
|
|
10
|
+
declare function _default(location: string, status?: Redirection): ResponseFunction<never>;
|
|
11
11
|
//# sourceMappingURL=redirect.d.ts.map
|
|
@@ -9,6 +9,6 @@ type Body = (source: Source) => Cleanup;
|
|
|
9
9
|
* @param options response options
|
|
10
10
|
* @return Response rendering function
|
|
11
11
|
*/
|
|
12
|
-
declare const _default: (body: Body, init?: ResponseInit) =>
|
|
12
|
+
declare const _default: (body: Body, init?: ResponseInit) => import("./ResponseFunction.js").default<never>;
|
|
13
13
|
export default _default;
|
|
14
14
|
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* @param options response options
|
|
5
5
|
* @return Response rendering function
|
|
6
6
|
*/
|
|
7
|
-
declare const _default: (body: string, init?: ResponseInit) =>
|
|
7
|
+
declare const _default: (body: string, init?: ResponseInit) => import("./ResponseFunction.js").default<never>;
|
|
8
8
|
export default _default;
|
|
9
9
|
//# sourceMappingURL=text.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type ResponseFunction from "#response/ResponseFunction";
|
|
2
2
|
import type { Actions } from "@rcompat/http";
|
|
3
3
|
export default _default;
|
|
4
|
-
declare function _default(actions: Actions): ResponseFunction
|
|
4
|
+
declare function _default(actions: Actions): ResponseFunction<never>;
|
|
5
5
|
//# sourceMappingURL=ws.d.ts.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { MaybePromise } from "@rcompat/type";
|
|
1
|
+
import type ResponseFunction from "#response/ResponseFunction";
|
|
3
2
|
export default _default;
|
|
4
|
-
declare function _default<T>(mime: string, mapper: (input: T) => BodyInit): (body: T, init?: ResponseInit) =>
|
|
3
|
+
declare function _default<T>(mime: string, mapper: (input: T) => BodyInit): (body: T, init?: ResponseInit) => ResponseFunction<never>;
|
|
5
4
|
//# sourceMappingURL=response.d.ts.map
|
|
@@ -23,7 +23,7 @@ type MethodMeta = {
|
|
|
23
23
|
type RequestMeta = {
|
|
24
24
|
headers?: HeadersInit;
|
|
25
25
|
};
|
|
26
|
-
type Page<R> = Awaited<R> extends ResponseFunction<infer Props> ? Props : never;
|
|
26
|
+
type Page<R> = Awaited<R> extends infer Result ? Result extends ResponseFunction<infer Props> ? Props : never : never;
|
|
27
27
|
type ClientMethod<O extends RouteOptions, R = unknown> = MethodMeta & {
|
|
28
28
|
_result?: R;
|
|
29
29
|
Page: Page<R>;
|
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
|
-
type Page<R> = Awaited<R> extends ResponseFunction<infer Props> ? Props : never;
|
|
14
|
-
type AnyHandler = RouteHandler | WithResult<RouteOptions>;
|
|
14
|
+
type Page<R> = Awaited<R> extends infer Result ? Result extends ResponseFunction<infer Props> ? Props : never : never;
|
|
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/lib/public/response.d.ts
CHANGED
|
@@ -6,15 +6,15 @@ import $null from "#response/null";
|
|
|
6
6
|
declare const response: {
|
|
7
7
|
binary: typeof binary;
|
|
8
8
|
error: typeof error;
|
|
9
|
-
json: (body: unknown, init?: ResponseInit) =>
|
|
9
|
+
json: (body: unknown, init?: ResponseInit) => import("./index.js").ResponseFunction<never>;
|
|
10
10
|
page: typeof page;
|
|
11
|
-
redirect: (location: string, status?: 300 | 301 | 302 | 303 | 304 | 307 | 308) => import("./index.js").ResponseFunction
|
|
11
|
+
redirect: (location: string, status?: 300 | 301 | 302 | 303 | 304 | 307 | 308) => import("./index.js").ResponseFunction<never>;
|
|
12
12
|
sse: (body: (source: {
|
|
13
13
|
send(name: string, data: unknown): void;
|
|
14
|
-
}) => void | (() => void), init?: ResponseInit) =>
|
|
15
|
-
text: (body: string, init?: ResponseInit) =>
|
|
14
|
+
}) => void | (() => void), init?: ResponseInit) => import("./index.js").ResponseFunction<never>;
|
|
15
|
+
text: (body: string, init?: ResponseInit) => import("./index.js").ResponseFunction<never>;
|
|
16
16
|
view: typeof view;
|
|
17
|
-
ws: (actions: import("@rcompat/http").Actions) => import("./index.js").ResponseFunction
|
|
17
|
+
ws: (actions: import("@rcompat/http").Actions) => import("./index.js").ResponseFunction<never>;
|
|
18
18
|
null: typeof $null;
|
|
19
19
|
};
|
|
20
20
|
export default response;
|