@rest-rpc/next 0.1.0-beta.12 → 0.1.0-beta.14

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/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { type ClearCookieOptions, clearCookie, type RouteErrors, type RouteRequestData, RouteResponseError, type RouteResponseShorthand, type SetCookieOptions, setCookie, } from "@rest-rpc/web";
2
- export { type CreateRouteHandlerOptions, createRouteHandler, type NextRouteMiddleware, type RouteRequest, type RouteResponse, route, router, } from "./server.ts";
2
+ export { type CreateRouteHandlerOptions, createRouteHandler, type NextRouteMiddleware, type RouteHandlers, type RouteRequest, type RouteResponse, route, router, } from "./server.ts";
package/dist/server.d.ts CHANGED
@@ -1,16 +1,70 @@
1
1
  import type { HttpRouteDeclaration } from "@rest-rpc/core/contract";
2
- import { type CreateWebHandlerOptions, type WebContract, type WebImplementationTree, type WebRouteBuilder, type WebRouteMiddleware, type WebRouteParseBodyInput, type RouteRequest as WebRouteRequest, type RouteResponse as WebRouteResponse, type WebRouterBuilder } from "@rest-rpc/web";
2
+ import { type CreateWebHandlerOptions, type WebContract, type WebImplementationTree, type WebRouteBuilder, type RouteHandlers as WebRouteHandlers, type WebRouteMiddleware, type WebRouteParseBodyInput, type RouteRequest as WebRouteRequest, type RouteResponse as WebRouteResponse, type WebRouterBuilder } from "@rest-rpc/web";
3
3
  import type { NextRequest } from "next/server.js";
4
+ /**
5
+ * Middleware function shape for Next.js route handlers.
6
+ *
7
+ * @see {@link https://rest-rpc.dev/docs/server/next.js#framework-context}
8
+ */
4
9
  export type NextRouteMiddleware<TContext extends Record<string, unknown>> = WebRouteMiddleware<Record<never, never>, TContext, NextRequest>;
10
+ /**
11
+ * Infers the Next.js route handler request type for a route declaration.
12
+ *
13
+ * @see {@link https://rest-rpc.dev/docs/type-helpers#server}
14
+ */
5
15
  export type RouteRequest<E extends HttpRouteDeclaration, TContext extends Record<string, unknown> = Record<string, unknown>> = WebRouteRequest<E, TContext, NextRequest>;
16
+ /**
17
+ * Infers the explicit response union for a Next.js HTTP route.
18
+ *
19
+ * @see {@link https://rest-rpc.dev/docs/type-helpers#server}
20
+ */
6
21
  export type RouteResponse<E extends HttpRouteDeclaration> = WebRouteResponse<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/class-handlers}
38
+ */
39
+ export type RouteHandlers<TContract extends WebContract, TContext extends Record<string, unknown> = Record<string, unknown>> = WebRouteHandlers<TContract, TContext, NextRequest>;
40
+ /**
41
+ * Options for creating Next.js route handler exports.
42
+ *
43
+ * @see {@link https://rest-rpc.dev/docs/server/next.js#options}
44
+ */
7
45
  export type CreateRouteHandlerOptions = {
8
46
  errorHandlers?: CreateWebHandlerOptions["errorHandlers"];
9
47
  parseBody?: (input: WebRouteParseBodyInput) => unknown | Promise<unknown>;
10
48
  };
11
- export declare const route: <const TRoute extends HttpRouteDeclaration>(contract: TRoute) => WebRouteBuilder<TRoute, Record<never, never>, NextRequest>;
12
- export declare const router: <const TContract extends WebContract>(contract: TContract) => WebRouterBuilder<TContract, Record<never, never>, NextRequest>;
13
- export declare const createRouteHandler: (implementations: WebImplementationTree, options?: CreateRouteHandlerOptions) => {
49
+ /**
50
+ * Creates a Next.js route implementation builder for a single HTTP route.
51
+ *
52
+ * @see {@link https://rest-rpc.dev/docs/server/next.js#single-route-handler}
53
+ */
54
+ export declare function route<const TRoute extends HttpRouteDeclaration>(contract: TRoute): WebRouteBuilder<TRoute, Record<never, never>, NextRequest>;
55
+ /**
56
+ * Creates a Next.js router implementation builder for a contract tree.
57
+ *
58
+ * @see {@link https://rest-rpc.dev/docs/server/next.js#catch-all-route-handler}
59
+ */
60
+ export declare function router<const TContract extends WebContract>(contract: TContract): WebRouterBuilder<TContract, Record<never, never>, NextRequest>;
61
+ /**
62
+ * Creates Next.js route handler exports from route implementations.
63
+ *
64
+ * @remarks This wrapper passes only the `NextRequest`; use `@rest-rpc/web` directly for custom runtime context.
65
+ * @see {@link https://rest-rpc.dev/docs/server/next.js#custom-runtime-context}
66
+ */
67
+ export declare function createRouteHandler(implementations: WebImplementationTree, options?: CreateRouteHandlerOptions): {
14
68
  DELETE: (request: Request) => Promise<Response>;
15
69
  GET: (request: Request) => Promise<Response>;
16
70
  PATCH: (request: Request) => Promise<Response>;
package/dist/server.js CHANGED
@@ -1,7 +1,27 @@
1
1
  import { createRouteHandler as createWebRouteHandler, route as webRoute, router as webRouter, } from "@rest-rpc/web";
2
- export const route = (contract) => webRoute(contract);
3
- export const router = (contract) => webRouter(contract);
4
- export const createRouteHandler = (implementations, options) => {
2
+ /**
3
+ * Creates a Next.js route implementation builder for a single HTTP route.
4
+ *
5
+ * @see {@link https://rest-rpc.dev/docs/server/next.js#single-route-handler}
6
+ */
7
+ export function route(contract) {
8
+ return webRoute(contract);
9
+ }
10
+ /**
11
+ * Creates a Next.js router implementation builder for a contract tree.
12
+ *
13
+ * @see {@link https://rest-rpc.dev/docs/server/next.js#catch-all-route-handler}
14
+ */
15
+ export function router(contract) {
16
+ return webRouter(contract);
17
+ }
18
+ /**
19
+ * Creates Next.js route handler exports from route implementations.
20
+ *
21
+ * @remarks This wrapper passes only the `NextRequest`; use `@rest-rpc/web` directly for custom runtime context.
22
+ * @see {@link https://rest-rpc.dev/docs/server/next.js#custom-runtime-context}
23
+ */
24
+ export function createRouteHandler(implementations, options) {
5
25
  const handle = createWebRouteHandler(implementations, {
6
26
  errorHandlers: options?.errorHandlers,
7
27
  parseBody: options?.parseBody,
@@ -14,4 +34,4 @@ export const createRouteHandler = (implementations, options) => {
14
34
  POST: nextHandler,
15
35
  PUT: nextHandler,
16
36
  };
17
- };
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rest-rpc/next",
3
- "version": "0.1.0-beta.12",
3
+ "version": "0.1.0-beta.14",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Next.js adapter for serving and consuming rest-rpc contracts in App Router projects.",
@@ -40,8 +40,8 @@
40
40
  "directory": "test-d"
41
41
  },
42
42
  "dependencies": {
43
- "@rest-rpc/core": "0.1.0-beta.12",
44
- "@rest-rpc/web": "0.1.0-beta.12"
43
+ "@rest-rpc/web": "0.1.0-beta.14",
44
+ "@rest-rpc/core": "0.1.0-beta.14"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "next": ">=15"