@primate/core 0.9.4 → 0.9.5
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/response/ResponseFunction.d.ts +2 -1
- package/lib/private/response/ResponseLike.d.ts +2 -1
- package/lib/private/response/json.d.ts +2 -2
- package/lib/private/response/json.js +4 -1
- package/lib/private/response/respond.d.ts +2 -1
- package/lib/private/route.client.d.ts +2 -2
- package/lib/private/route.d.ts +1 -1
- package/lib/public/response.d.ts +2 -1
- package/package.json +1 -1
|
@@ -2,9 +2,10 @@ import type View from "#client/View";
|
|
|
2
2
|
import type RequestFacade from "#request/RequestFacade";
|
|
3
3
|
import type ServeApp from "#serve/App";
|
|
4
4
|
import type { Dict, MaybePromise } from "@rcompat/type";
|
|
5
|
-
type ResponseFunction<Props =
|
|
5
|
+
type ResponseFunction<Props = never, Result = never> = {
|
|
6
6
|
(app: ServeApp, transfer: Dict, request: RequestFacade): MaybePromise<View | null | Response | undefined>;
|
|
7
7
|
readonly _props?: Props;
|
|
8
|
+
readonly _result?: Result;
|
|
8
9
|
};
|
|
9
10
|
export { ResponseFunction as default };
|
|
10
11
|
//# sourceMappingURL=ResponseFunction.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type ResponseFunction from "#response/ResponseFunction";
|
|
2
2
|
import type Streamable from "@rcompat/fs/Streamable";
|
|
3
3
|
import type { Dict } from "@rcompat/type";
|
|
4
|
-
type
|
|
4
|
+
type UnknownResponseFunction = ResponseFunction<unknown, unknown>;
|
|
5
|
+
type ResponseLike = string | Dict | Dict[] | URL | Blob | ReadableStream | Streamable | Response | UnknownResponseFunction | null;
|
|
5
6
|
export { ResponseLike as default };
|
|
6
7
|
//# sourceMappingURL=ResponseLike.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type ResponseFunction from "#response/ResponseFunction";
|
|
1
2
|
/**
|
|
2
3
|
* Issue a JSON response
|
|
3
4
|
* @param body body object
|
|
4
5
|
* @param options response options
|
|
5
6
|
* @return Response rendering function
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
export default _default;
|
|
8
|
+
export default function json<const T>(body: T, init?: ResponseInit): ResponseFunction<never, T>;
|
|
9
9
|
//# sourceMappingURL=json.d.ts.map
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import response from "#response";
|
|
2
2
|
import http from "@rcompat/http";
|
|
3
|
+
const json_response = response(http.MIME.APPLICATION_JSON, JSON.stringify);
|
|
3
4
|
/**
|
|
4
5
|
* Issue a JSON response
|
|
5
6
|
* @param body body object
|
|
6
7
|
* @param options response options
|
|
7
8
|
* @return Response rendering function
|
|
8
9
|
*/
|
|
9
|
-
export default
|
|
10
|
+
export default function json(body, init) {
|
|
11
|
+
return json_response(body, init);
|
|
12
|
+
}
|
|
10
13
|
//# sourceMappingURL=json.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type ResponseFunction from "#response/ResponseFunction";
|
|
2
2
|
import type ResponseLike from "#response/ResponseLike";
|
|
3
|
+
type UnknownResponseFunction = ResponseFunction<unknown, unknown>;
|
|
3
4
|
export default _default;
|
|
4
|
-
declare function _default(result: ResponseLike):
|
|
5
|
+
declare function _default(result: ResponseLike): UnknownResponseFunction;
|
|
5
6
|
//# sourceMappingURL=respond.d.ts.map
|
|
@@ -23,8 +23,8 @@ type MethodMeta = {
|
|
|
23
23
|
type RequestMeta = {
|
|
24
24
|
headers?: HeadersInit;
|
|
25
25
|
};
|
|
26
|
-
type Page<R> = Awaited<R> extends infer Result ? Result extends ResponseFunction<infer Props> ? Props : never : never;
|
|
27
|
-
type ClientResult<R> = Awaited<R> extends infer Result ? Result extends ResponseFunction ?
|
|
26
|
+
type Page<R> = Awaited<R> extends infer Result ? Result extends ResponseFunction<infer Props, unknown> ? Props : never : never;
|
|
27
|
+
type ClientResult<R> = Awaited<R> extends infer Result ? Result extends ResponseFunction<unknown, infer Payload> ? Payload : Result : never;
|
|
28
28
|
type ClientMethod<O extends RouteOptions, R = unknown> = MethodMeta & {
|
|
29
29
|
_result?: ClientResult<R>;
|
|
30
30
|
Page: Page<R>;
|
package/lib/private/route.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ type WithResult<O extends RouteOptions, R extends ResponseLike> = {
|
|
|
11
11
|
handler: RouteHandler<O, R>;
|
|
12
12
|
options: O;
|
|
13
13
|
};
|
|
14
|
-
type Page<R> = Awaited<R> extends infer Result ? Result extends ResponseFunction<infer Props> ? Props : never : never;
|
|
14
|
+
type Page<R> = Awaited<R> extends infer Result ? Result extends ResponseFunction<infer Props, unknown> ? Props : never : never;
|
|
15
15
|
type AnyHandler = RouteHandler | WithResult<RouteOptions, ResponseLike>;
|
|
16
16
|
type RouteHandlers = {
|
|
17
17
|
[key in Method]?: AnyHandler;
|
package/lib/public/response.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import binary from "#response/binary";
|
|
2
2
|
import error from "#response/error";
|
|
3
|
+
import json from "#response/json";
|
|
3
4
|
import page from "#response/page";
|
|
4
5
|
import view from "#response/view";
|
|
5
6
|
import $null from "#response/null";
|
|
6
7
|
declare const response: {
|
|
7
8
|
binary: typeof binary;
|
|
8
9
|
error: typeof error;
|
|
9
|
-
json:
|
|
10
|
+
json: typeof json;
|
|
10
11
|
page: typeof page;
|
|
11
12
|
redirect: (location: string, status?: 300 | 301 | 302 | 303 | 304 | 307 | 308) => import("./index.js").ResponseFunction<never>;
|
|
12
13
|
sse: (body: (source: {
|