@rest-rpc/next 0.1.0-beta.1 → 0.1.0-beta.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/README.md CHANGED
@@ -26,7 +26,7 @@ GET /todos/todo_1
26
26
  - `@rest-rpc/hono`: Hono server adapter.
27
27
  - `@rest-rpc/fastify`: Fastify server adapter.
28
28
  - `@rest-rpc/web`: Web `Request`/`Response` HTTP handler adapter.
29
- - `@rest-rpc/next`: Next.js server/client adapter.
29
+ - `@rest-rpc/next`: Next.js server adapter.
30
30
  - `@rest-rpc/tanstack-query`: TanStack Query options and key helpers.
31
31
 
32
32
  `@rest-rpc/server` contains shared adapter infrastructure and is mainly useful
@@ -42,4 +42,4 @@ for adapter authors.
42
42
 
43
43
  ## Documentation
44
44
 
45
- Full documentation will live at [rest-rpc.dev](https://rest-rpc.dev).
45
+ [rest-rpc.dev](https://rest-rpc.dev)
package/dist/index.d.ts CHANGED
@@ -1,4 +1,2 @@
1
1
  export { ContractResponseError } from "@rest-rpc/web";
2
- export type { NextClientOptions } from "./client.ts";
3
- export { getGeneratedTagsForRoute, initNextClient, } from "./client.ts";
4
2
  export { type CreateRouteHandlerOptions, createRouteHandler, createRouterHandler, type NextRouteHandlerContext, type NextRouteParseBody, type NextRouteParseBodyInput, type RouteHandler, type RouteRequest, type RouteResponse, } from "./server.ts";
package/dist/index.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export { ContractResponseError } from "@rest-rpc/web";
2
- export { getGeneratedTagsForRoute, initNextClient, } from "./client.js";
3
2
  export { createRouteHandler, createRouterHandler, } from "./server.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rest-rpc/next",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -19,8 +19,8 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@rest-rpc/core": "^0.1.0-beta.1",
23
- "@rest-rpc/web": "^0.1.0-beta.1"
22
+ "@rest-rpc/core": "^0.1.0-beta.3",
23
+ "@rest-rpc/web": "^0.1.0-beta.3"
24
24
  },
25
25
  "scripts": {
26
26
  "build": "tsc -p tsconfig.build.json",
package/dist/client.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import type { ApiClientFor, ApiClientOptions, Contract } from "@rest-rpc/core";
2
- import type { HttpRouteDeclaration } from "@rest-rpc/core/contract";
3
- type NextFetchOptions = RequestInit & {
4
- next?: {
5
- tags?: string[];
6
- [key: string]: unknown;
7
- };
8
- };
9
- export type NextClientFetchOptions = Omit<NextFetchOptions, "method" | "body" | "headers" | "signal">;
10
- export type NextClientOptions = Omit<ApiClientOptions, "fetchOptions"> & {
11
- automaticFetchTags?: {
12
- enabled: boolean;
13
- tagPrefix?: string;
14
- };
15
- fetchOptions?: NextClientFetchOptions;
16
- };
17
- export declare const initNextClient: <TContract extends Contract>(contract: TContract, options: NextClientOptions) => ApiClientFor<TContract>;
18
- export declare const getGeneratedTagsForRoute: (route: HttpRouteDeclaration, options?: {
19
- request?: Record<string, unknown>;
20
- tagPrefix?: string;
21
- }) => string[];
22
- export {};
package/dist/client.js DELETED
@@ -1,41 +0,0 @@
1
- import { getRouteCacheTags, initClient } from "@rest-rpc/core";
2
- const createRouteCacheTagsForUrl = (url, prefix) => {
3
- const parsed = new URL(url instanceof Request ? url.url : String(url));
4
- return Array.from(new Set([
5
- `${prefix ?? "rest-rpc"}:${parsed.pathname}${parsed.search}`,
6
- `${prefix ?? "rest-rpc"}:${parsed.pathname}`,
7
- ]));
8
- };
9
- const fetchWithTags = (fetchImpl, tagPrefix) => {
10
- return (url, init) => {
11
- if (init?.method !== "GET")
12
- return fetchImpl(url, init);
13
- const nextInit = init;
14
- const taggedInit = {
15
- ...nextInit,
16
- next: {
17
- ...nextInit.next,
18
- tags: [
19
- ...(nextInit.next?.tags ?? []),
20
- ...createRouteCacheTagsForUrl(url, tagPrefix),
21
- ],
22
- },
23
- };
24
- return fetchImpl(url, taggedInit);
25
- };
26
- };
27
- export const initNextClient = (contract, options) => {
28
- const { automaticFetchTags, fetch, ...clientOptions } = options;
29
- if (!automaticFetchTags?.enabled) {
30
- return initClient(contract, options);
31
- }
32
- const fetchImpl = fetch ?? ((url, init) => globalThis.fetch(url, init));
33
- return initClient(contract, {
34
- ...clientOptions,
35
- fetch: fetchWithTags(fetchImpl, automaticFetchTags.tagPrefix),
36
- });
37
- };
38
- export const getGeneratedTagsForRoute = (route, options) => getRouteCacheTags(route, {
39
- request: options?.request,
40
- prefix: options?.tagPrefix,
41
- });