@rest-rpc/next 0.1.0-beta.13 → 0.1.0-beta.15
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/README.md +3 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/server.d.ts +30 -12
- package/dist/server.js +7 -7
- package/package.json +22 -22
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ server handlers, fetch clients, openAPI documents, and more from it.
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
10
|
- Shared TypeScript contracts for HTTP APIs.
|
|
11
|
-
- Typed server handlers for Express, Hono, Fastify, Next.js, and Fetch runtimes.
|
|
11
|
+
- Typed server handlers for Express, Hono, Fastify, NestJS, Next.js, and Fetch runtimes.
|
|
12
12
|
- Typed fetch client.
|
|
13
13
|
- Typed TanStack Query helpers.
|
|
14
14
|
- Typed WebSockets, streaming, non-JSON requests/responses.
|
|
@@ -76,6 +76,7 @@ Full documentation is available at [rest-rpc.dev](https://rest-rpc.dev)
|
|
|
76
76
|
- [`@rest-rpc/express`](https://npmx.dev/package/@rest-rpc/express): Express server adapter.
|
|
77
77
|
- [`@rest-rpc/fastify`](https://npmx.dev/package/@rest-rpc/fastify): Fastify server adapter.
|
|
78
78
|
- [`@rest-rpc/hono`](https://npmx.dev/package/@rest-rpc/hono): Hono server adapter.
|
|
79
|
+
- [`@rest-rpc/nest`](https://npmx.dev/package/@rest-rpc/nest): NestJS server adapter.
|
|
79
80
|
- [`@rest-rpc/next`](https://npmx.dev/package/@rest-rpc/next): Next.js adapter.
|
|
80
|
-
- [`@rest-rpc/
|
|
81
|
+
- [`@rest-rpc/fetch`](https://npmx.dev/package/@rest-rpc/fetch): Fetch runtime adapter
|
|
81
82
|
- [`@rest-rpc/tanstack-query`](https://npmx.dev/package/@rest-rpc/tanstack-query): TanStack Query adapter.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { type ClearCookieOptions, clearCookie, type RouteErrors, type RouteRequestData, RouteResponseError, type RouteResponseShorthand, type SetCookieOptions, setCookie, } from "@rest-rpc/
|
|
2
|
-
export { type CreateRouteHandlerOptions, createRouteHandler, type NextRouteMiddleware, type RouteRequest, type RouteResponse, route, router, } from "./server.ts";
|
|
1
|
+
export { type ClearCookieOptions, clearCookie, type RouteErrors, type RouteRequestData, RouteResponseError, type RouteResponseShorthand, type SetCookieOptions, setCookie, type SseEvent, sseEvent, } from "@rest-rpc/fetch";
|
|
2
|
+
export { type CreateRouteHandlerOptions, createRouteHandler, type NextRouteMiddleware, type RouteHandlers, type RouteRequest, type RouteResponse, route, router, } from "./server.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { clearCookie, RouteResponseError, setCookie, } from "@rest-rpc/
|
|
1
|
+
export { clearCookie, RouteResponseError, setCookie, sseEvent, } from "@rest-rpc/fetch";
|
|
2
2
|
export { createRouteHandler, route, router, } from "./server.js";
|
package/dist/server.d.ts
CHANGED
|
@@ -1,52 +1,70 @@
|
|
|
1
1
|
import type { HttpRouteDeclaration } from "@rest-rpc/core/contract";
|
|
2
|
-
import { type
|
|
2
|
+
import { type CreateFetchHandlerOptions, type FetchContract, type FetchImplementationTree, type FetchRouteBuilder, type RouteHandlers as FetchRouteHandlers, type FetchRouteMiddleware, type FetchRouteParseBodyInput, type RouteRequest as FetchRouteRequest, type RouteResponse as FetchRouteResponse, type FetchRouterBuilder } from "@rest-rpc/fetch";
|
|
3
3
|
import type { NextRequest } from "next/server.js";
|
|
4
4
|
/**
|
|
5
5
|
* Middleware function shape for Next.js route handlers.
|
|
6
6
|
*
|
|
7
7
|
* @see {@link https://rest-rpc.dev/docs/server/next.js#framework-context}
|
|
8
8
|
*/
|
|
9
|
-
export type NextRouteMiddleware<TContext extends Record<string, unknown>> =
|
|
9
|
+
export type NextRouteMiddleware<TContext extends Record<string, unknown>> = FetchRouteMiddleware<Record<never, never>, TContext, NextRequest>;
|
|
10
10
|
/**
|
|
11
11
|
* Infers the Next.js route handler request type for a route declaration.
|
|
12
12
|
*
|
|
13
13
|
* @see {@link https://rest-rpc.dev/docs/type-helpers#server}
|
|
14
14
|
*/
|
|
15
|
-
export type RouteRequest<E extends HttpRouteDeclaration, TContext extends Record<string, unknown> = Record<string, unknown>> =
|
|
15
|
+
export type RouteRequest<E extends HttpRouteDeclaration, TContext extends Record<string, unknown> = Record<string, unknown>> = FetchRouteRequest<E, TContext, NextRequest>;
|
|
16
16
|
/**
|
|
17
17
|
* Infers the explicit response union for a Next.js HTTP route.
|
|
18
18
|
*
|
|
19
19
|
* @see {@link https://rest-rpc.dev/docs/type-helpers#server}
|
|
20
20
|
*/
|
|
21
|
-
export type RouteResponse<E extends HttpRouteDeclaration> =
|
|
21
|
+
export type RouteResponse<E extends HttpRouteDeclaration> = FetchRouteResponse<E>;
|
|
22
|
+
/**
|
|
23
|
+
* Handler tree accepted by `router().handlers()` when building a Next.js implementation tree.
|
|
24
|
+
*
|
|
25
|
+
* @remarks Use this type with `implements` to check class-based route handler
|
|
26
|
+
* services against a contract tree.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* class TodoHandlers implements RouteHandlers<typeof api.todos> {
|
|
31
|
+
* get(request: RouteRequest<typeof api.todos.get>) {
|
|
32
|
+
* return { id: request.id };
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://rest-rpc.dev/docs/recipes/organizing-route-handlers#service-classes-as-handlers}
|
|
38
|
+
*/
|
|
39
|
+
export type RouteHandlers<TContract extends FetchContract, TContext extends Record<string, unknown> = Record<string, unknown>> = FetchRouteHandlers<TContract, TContext, NextRequest>;
|
|
22
40
|
/**
|
|
23
41
|
* Options for creating Next.js route handler exports.
|
|
24
42
|
*
|
|
25
43
|
* @see {@link https://rest-rpc.dev/docs/server/next.js#options}
|
|
26
44
|
*/
|
|
27
45
|
export type CreateRouteHandlerOptions = {
|
|
28
|
-
errorHandlers?:
|
|
29
|
-
parseBody?: (input:
|
|
46
|
+
errorHandlers?: CreateFetchHandlerOptions["errorHandlers"];
|
|
47
|
+
parseBody?: (input: FetchRouteParseBodyInput) => unknown | Promise<unknown>;
|
|
30
48
|
};
|
|
31
49
|
/**
|
|
32
|
-
* Creates a
|
|
50
|
+
* Creates a Next.js route implementation builder for a single HTTP route.
|
|
33
51
|
*
|
|
34
52
|
* @see {@link https://rest-rpc.dev/docs/server/next.js#single-route-handler}
|
|
35
53
|
*/
|
|
36
|
-
export declare function route<const TRoute extends HttpRouteDeclaration>(contract: TRoute):
|
|
54
|
+
export declare function route<const TRoute extends HttpRouteDeclaration>(contract: TRoute): FetchRouteBuilder<TRoute, Record<never, never>, NextRequest>;
|
|
37
55
|
/**
|
|
38
|
-
* Creates a
|
|
56
|
+
* Creates a Next.js router implementation builder for a contract tree.
|
|
39
57
|
*
|
|
40
58
|
* @see {@link https://rest-rpc.dev/docs/server/next.js#catch-all-route-handler}
|
|
41
59
|
*/
|
|
42
|
-
export declare function router<const TContract extends
|
|
60
|
+
export declare function router<const TContract extends FetchContract>(contract: TContract): FetchRouterBuilder<TContract, Record<never, never>, NextRequest>;
|
|
43
61
|
/**
|
|
44
62
|
* Creates Next.js route handler exports from route implementations.
|
|
45
63
|
*
|
|
46
|
-
* @remarks This wrapper passes only the `NextRequest`; use `@rest-rpc/
|
|
64
|
+
* @remarks This wrapper passes only the `NextRequest`; use `@rest-rpc/fetch` directly for custom runtime context.
|
|
47
65
|
* @see {@link https://rest-rpc.dev/docs/server/next.js#custom-runtime-context}
|
|
48
66
|
*/
|
|
49
|
-
export declare function createRouteHandler(implementations:
|
|
67
|
+
export declare function createRouteHandler(implementations: FetchImplementationTree, options?: CreateRouteHandlerOptions): {
|
|
50
68
|
DELETE: (request: Request) => Promise<Response>;
|
|
51
69
|
GET: (request: Request) => Promise<Response>;
|
|
52
70
|
PATCH: (request: Request) => Promise<Response>;
|
package/dist/server.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { createRouteHandler as
|
|
1
|
+
import { createRouteHandler as createFetchRouteHandler, route as fetchRoute, router as fetchRouter, } from "@rest-rpc/fetch";
|
|
2
2
|
/**
|
|
3
|
-
* Creates a
|
|
3
|
+
* Creates a Next.js route implementation builder for a single HTTP route.
|
|
4
4
|
*
|
|
5
5
|
* @see {@link https://rest-rpc.dev/docs/server/next.js#single-route-handler}
|
|
6
6
|
*/
|
|
7
7
|
export function route(contract) {
|
|
8
|
-
return
|
|
8
|
+
return fetchRoute(contract);
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Creates a
|
|
11
|
+
* Creates a Next.js router implementation builder for a contract tree.
|
|
12
12
|
*
|
|
13
13
|
* @see {@link https://rest-rpc.dev/docs/server/next.js#catch-all-route-handler}
|
|
14
14
|
*/
|
|
15
15
|
export function router(contract) {
|
|
16
|
-
return
|
|
16
|
+
return fetchRouter(contract);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Creates Next.js route handler exports from route implementations.
|
|
20
20
|
*
|
|
21
|
-
* @remarks This wrapper passes only the `NextRequest`; use `@rest-rpc/
|
|
21
|
+
* @remarks This wrapper passes only the `NextRequest`; use `@rest-rpc/fetch` directly for custom runtime context.
|
|
22
22
|
* @see {@link https://rest-rpc.dev/docs/server/next.js#custom-runtime-context}
|
|
23
23
|
*/
|
|
24
24
|
export function createRouteHandler(implementations, options) {
|
|
25
|
-
const handle =
|
|
25
|
+
const handle = createFetchRouteHandler(implementations, {
|
|
26
26
|
errorHandlers: options?.errorHandlers,
|
|
27
27
|
parseBody: options?.parseBody,
|
|
28
28
|
});
|
package/package.json
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rest-rpc/next",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"license": "MIT",
|
|
3
|
+
"version": "0.1.0-beta.15",
|
|
6
4
|
"description": "Next.js adapter for serving and consuming rest-rpc contracts in App Router projects.",
|
|
7
5
|
"keywords": [
|
|
8
|
-
"rest-rpc",
|
|
9
|
-
"typescript",
|
|
10
|
-
"rpc",
|
|
11
|
-
"rest",
|
|
12
6
|
"api-contract",
|
|
7
|
+
"app-router",
|
|
13
8
|
"contract-first",
|
|
14
|
-
"
|
|
9
|
+
"fetch",
|
|
15
10
|
"next",
|
|
16
11
|
"nextjs",
|
|
17
|
-
"app-router",
|
|
18
|
-
"route-handler",
|
|
19
|
-
"fetch",
|
|
20
12
|
"react",
|
|
21
|
-
"
|
|
13
|
+
"rest",
|
|
14
|
+
"rest-rpc",
|
|
15
|
+
"route-handler",
|
|
16
|
+
"rpc",
|
|
17
|
+
"server-components",
|
|
18
|
+
"type-safe-api",
|
|
19
|
+
"typescript"
|
|
22
20
|
],
|
|
21
|
+
"license": "MIT",
|
|
23
22
|
"repository": {
|
|
24
23
|
"type": "git",
|
|
25
24
|
"url": "git+https://github.com/rest-rpc/rest-rpc.git",
|
|
26
25
|
"directory": "packages/next"
|
|
27
26
|
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
28
31
|
"main": "./dist/index.js",
|
|
29
32
|
"types": "./dist/index.d.ts",
|
|
30
33
|
"exports": {
|
|
@@ -33,21 +36,18 @@
|
|
|
33
36
|
"import": "./dist/index.js"
|
|
34
37
|
}
|
|
35
38
|
},
|
|
36
|
-
"files": [
|
|
37
|
-
"dist"
|
|
38
|
-
],
|
|
39
|
-
"tsd": {
|
|
40
|
-
"directory": "test-d"
|
|
41
|
-
},
|
|
42
39
|
"dependencies": {
|
|
43
|
-
"@rest-rpc/
|
|
44
|
-
"@rest-rpc/
|
|
40
|
+
"@rest-rpc/fetch": "0.1.0-beta.15",
|
|
41
|
+
"@rest-rpc/core": "0.1.0-beta.15"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"next": "16.3.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"next": ">=15"
|
|
48
48
|
},
|
|
49
|
-
"
|
|
50
|
-
"
|
|
49
|
+
"tsd": {
|
|
50
|
+
"directory": "test-d"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "tsc -p tsconfig.build.json",
|