rpc4next 0.1.6 → 0.1.7
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 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,15 +8,12 @@ Inspired by Hono RPC and Pathpida, **rpc4next** automatically generates a type-s
|
|
|
8
8
|
|
|
9
9
|
## ✨ Features
|
|
10
10
|
|
|
11
|
-
- ✅ 既存の `app/**/route.ts` および `app/**/page.tsx` を活用するため、新たなハンドラファイルの作成は不要
|
|
12
11
|
- ✅ ルート、パラメータ、クエリパラメータ、 リクエストボディ、レスポンスの型安全なクライアント生成
|
|
12
|
+
- ✅ 既存の `app/**/route.ts` および `app/**/page.tsx` を活用するため、新たなハンドラファイルの作成は不要
|
|
13
13
|
- ✅ 最小限のセットアップで、カスタムサーバー不要
|
|
14
14
|
- ✅ 動的ルート(`[id]`、`[...slug]` など)に対応
|
|
15
15
|
- ✅ CLI による自動クライアント用型定義生成
|
|
16
16
|
|
|
17
|
-
> **注意**
|
|
18
|
-
> RPCとしてresponseの戻り値の推論が機能するのは、対象となる `route.ts` の HTTPメソッドハンドラ内で`NextResponse.json()` をしている物のみになります。
|
|
19
|
-
|
|
20
17
|
---
|
|
21
18
|
|
|
22
19
|
## 🚀 Getting Started
|
|
@@ -54,7 +51,7 @@ export async function GET(
|
|
|
54
51
|
|
|
55
52
|
🚩 Query or OptionalQuery 型を export することで、searchParams の型も自動的にクライアントに反映されます。
|
|
56
53
|
|
|
57
|
-
- **RPCとしてresponseの戻り値の推論が機能するのは、対象となる `route.ts` の HTTPメソッドハンドラ内で`NextResponse.json()`
|
|
54
|
+
- **RPCとしてresponseの戻り値の推論が機能するのは、対象となる `route.ts` の HTTPメソッドハンドラ内で`NextResponse.json()` をしている関数のみになります**
|
|
58
55
|
|
|
59
56
|
---
|
|
60
57
|
|
|
@@ -85,8 +82,6 @@ npx rpc4next <baseDir> <outputPath>
|
|
|
85
82
|
npx rpc4next <baseDir> <outputPath> --generate-params-types <paramsFileName>
|
|
86
83
|
```
|
|
87
84
|
|
|
88
|
-
※ このオプションを指定する際は、必ずファイル名をセットしてください。ファイル名が指定されない場合、エラーが発生します。
|
|
89
|
-
|
|
90
85
|
---
|
|
91
86
|
|
|
92
87
|
### 4. Create Your RPC Client
|
|
@@ -152,10 +147,7 @@ const createRouteHandler = routeHandlerFactory((err, rc) =>
|
|
|
152
147
|
rc.text("error", { status: 400 })
|
|
153
148
|
);
|
|
154
149
|
|
|
155
|
-
const { POST } = createRouteHandler().post(
|
|
156
|
-
async (rc) => rc.json("json response"),
|
|
157
|
-
async (rc) => rc.text("plain text")
|
|
158
|
-
);
|
|
150
|
+
const { POST } = createRouteHandler().post(async (rc) => rc.text("plain text"));
|
|
159
151
|
```
|
|
160
152
|
|
|
161
153
|
これだけで、POST リクエストの返り値が、responseの内容(json,textなど)、status,contenttypeが型付けされるようになります。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rpc4next",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Inspired by Hono RPC and Pathpida, rpc4next brings a lightweight and intuitive RPC solution to Next.js, making server-client communication seamless",
|
|
5
5
|
"author": "watanabe-1",
|
|
6
6
|
"license": "MIT",
|