rpc4next 0.3.7 → 0.3.8
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/rpc/client/index.d.ts +2 -1
- package/dist/rpc/client/index.js +1 -1
- package/dist/rpc/client/rpc-client.d.ts +32 -0
- package/dist/rpc/client/rpc-client.js +1 -0
- package/dist/rpc/client/rpc-helper.d.ts +23 -0
- package/dist/rpc/client/rpc-helper.js +1 -0
- package/dist/rpc/client/rpc.d.ts +2 -55
- package/dist/rpc/client/rpc.js +1 -1
- package/dist/rpc/client/types.d.ts +6 -0
- package/package.json +8 -8
- package/dist/rpc/client/types.js +0 -0
- package/dist/rpc/lib/content-type-types.js +0 -0
- package/dist/rpc/lib/http-request-headers-types.js +0 -0
- package/dist/rpc/lib/http-response-headers-types.js +0 -0
- package/dist/rpc/lib/http-status-code-types.js +0 -0
- package/dist/rpc/lib/types.js +0 -0
- package/dist/rpc/server/route-types.js +0 -8
- package/dist/rpc/server/types.js +0 -0
package/dist/rpc/client/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRpcClient as p
|
|
1
|
+
import{createRpcClient as p}from"./rpc-client";import{createRpcHelper as o}from"./rpc-helper";export{p as createRpcClient,o as createRpcHelper};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ClientOptions, DynamicPathProxyAsFunction } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates an RPC client proxy for making HTTP requests with a strongly typed API.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type defining the RPC endpoint structure.
|
|
6
|
+
* @param baseUrl - The base URL for the RPC client. This URL will be used as the root for all generated endpoint URLs.
|
|
7
|
+
* @param options - (Optional) Client options to customize the behavior of the RPC client. These options may include a custom fetch function and default request initialization options.
|
|
8
|
+
* @returns An object that enables you to dynamically build endpoint URLs and execute HTTP requests (such as GET, POST, DELETE, etc.) with full type support.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { createRpcClient } from "./rpc";
|
|
13
|
+
* import type { PathStructure } from "./types";
|
|
14
|
+
*
|
|
15
|
+
* // Create an RPC client with a base URL
|
|
16
|
+
* const client = createRpcClient<PathStructure>("http://localhost:3000");
|
|
17
|
+
*
|
|
18
|
+
* // Generate a URL for a dynamic endpoint
|
|
19
|
+
* const urlResult = client.fuga._foo("test").$url();
|
|
20
|
+
* console.log(urlResult.path); // "http://localhost:3000/fuga/test"
|
|
21
|
+
* console.log(urlResult.relativePath); // "/fuga/test"
|
|
22
|
+
* console.log(urlResult.pathname); // "/fuga/[foo]"
|
|
23
|
+
* console.log(urlResult.params); // { foo: "test" }
|
|
24
|
+
*
|
|
25
|
+
* // Execute a GET request on an endpoint
|
|
26
|
+
* const response = await client.api.hoge._foo("test").$get();
|
|
27
|
+
* console.log(await response.json()); // Expected response: { method: "get" }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* The above example demonstrates how to generate URLs with dynamic segments and how to execute HTTP requests.
|
|
31
|
+
*/
|
|
32
|
+
export declare const createRpcClient: <T extends object>(baseUrl: string, options?: ClientOptions) => DynamicPathProxyAsFunction<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{httpMethod as n}from"./http-method";import{makeCreateRpc as p}from"./rpc";import{createUrl as m}from"./url";import{isHttpMethod as c}from"./utils";const l=p((t,{paths:r,params:o,dynamicKeys:e,options:i})=>{if(t==="$url")return m([...r],o,e);if(c(t))return n(t,[...r],o,e,i)});export{l as createRpcClient};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DynamicPathProxyAsProperty } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates an RPC helper proxy for dynamic path matching based on a given endpoint structure.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type defining the RPC endpoint structure.
|
|
6
|
+
*
|
|
7
|
+
* @returns An object that provides dynamic RPC helper methods for the defined endpoints.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Create the RPC helper
|
|
12
|
+
* const rpcHelper = createRpcHelper<PathStructure>();
|
|
13
|
+
*
|
|
14
|
+
* // Use the $match method to extract dynamic parameters from a URL path
|
|
15
|
+
* const match = rpcHelper.fuga._foo.$match("/fuga/test");
|
|
16
|
+
* // Expected output: { foo: "test" }
|
|
17
|
+
*
|
|
18
|
+
* // If the path does not match, it returns null
|
|
19
|
+
* const noMatch = rpcHelper.fuga._foo.$match("/hoge/test");
|
|
20
|
+
* // Expected output: null
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const createRpcHelper: <T extends object>() => DynamicPathProxyAsProperty<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{matchPath as o}from"./match";import{makeCreateRpc as a}from"./rpc";const c=a((r,{paths:t,dynamicKeys:e})=>{if(r==="$match")return o([...t],e)});export{c as createRpcHelper};
|
package/dist/rpc/client/rpc.d.ts
CHANGED
|
@@ -3,58 +3,5 @@
|
|
|
3
3
|
* and pathpida (https://github.com/aspida/pathpida)
|
|
4
4
|
* particularly their routing structures and developer experience.
|
|
5
5
|
*/
|
|
6
|
-
import type {
|
|
7
|
-
export declare const
|
|
8
|
-
/**
|
|
9
|
-
* Creates an RPC client proxy for making HTTP requests with a strongly typed API.
|
|
10
|
-
*
|
|
11
|
-
* @template T - The type defining the RPC endpoint structure.
|
|
12
|
-
* @param baseUrl - The base URL for the RPC client. This URL will be used as the root for all generated endpoint URLs.
|
|
13
|
-
* @param options - (Optional) Client options to customize the behavior of the RPC client. These options may include a custom fetch function and default request initialization options.
|
|
14
|
-
* @returns An object that enables you to dynamically build endpoint URLs and execute HTTP requests (such as GET, POST, DELETE, etc.) with full type support.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* import { createRpcClient } from "./rpc";
|
|
19
|
-
* import type { PathStructure } from "./types";
|
|
20
|
-
*
|
|
21
|
-
* // Create an RPC client with a base URL
|
|
22
|
-
* const client = createRpcClient<PathStructure>("http://localhost:3000");
|
|
23
|
-
*
|
|
24
|
-
* // Generate a URL for a dynamic endpoint
|
|
25
|
-
* const urlResult = client.fuga._foo("test").$url();
|
|
26
|
-
* console.log(urlResult.path); // "http://localhost:3000/fuga/test"
|
|
27
|
-
* console.log(urlResult.relativePath); // "/fuga/test"
|
|
28
|
-
* console.log(urlResult.pathname); // "/fuga/[foo]"
|
|
29
|
-
* console.log(urlResult.params); // { foo: "test" }
|
|
30
|
-
*
|
|
31
|
-
* // Execute a GET request on an endpoint
|
|
32
|
-
* const response = await client.api.hoge._foo("test").$get();
|
|
33
|
-
* console.log(await response.json()); // Expected response: { method: "get" }
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* The above example demonstrates how to generate URLs with dynamic segments and how to execute HTTP requests.
|
|
37
|
-
*/
|
|
38
|
-
export declare const createRpcClient: <T extends object>(baseUrl: string, options?: ClientOptions) => DynamicPathProxyAsFunction<T>;
|
|
39
|
-
/**
|
|
40
|
-
* Creates an RPC helper proxy for dynamic path matching based on a given endpoint structure.
|
|
41
|
-
*
|
|
42
|
-
* @template T - The type defining the RPC endpoint structure.
|
|
43
|
-
*
|
|
44
|
-
* @returns An object that provides dynamic RPC helper methods for the defined endpoints.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* // Create the RPC helper
|
|
49
|
-
* const rpcHelper = createRpcHelper<PathStructure>();
|
|
50
|
-
*
|
|
51
|
-
* // Use the $match method to extract dynamic parameters from a URL path
|
|
52
|
-
* const match = rpcHelper.fuga._foo.$match("/fuga/test");
|
|
53
|
-
* // Expected output: { foo: "test" }
|
|
54
|
-
*
|
|
55
|
-
* // If the path does not match, it returns null
|
|
56
|
-
* const noMatch = rpcHelper.fuga._foo.$match("/hoge/test");
|
|
57
|
-
* // Expected output: null
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export declare const createRpcHelper: <T extends object>() => DynamicPathProxyAsProperty<T>;
|
|
6
|
+
import type { ClientOptions, RpcHandler } from "./types";
|
|
7
|
+
export declare const makeCreateRpc: (handler: RpcHandler) => <T extends object>(base?: string, options?: ClientOptions) => T;
|
package/dist/rpc/client/rpc.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Inspired by the design of Hono (https://github.com/honojs/hono)
|
|
3
3
|
* and pathpida (https://github.com/aspida/pathpida)
|
|
4
4
|
* particularly their routing structures and developer experience.
|
|
5
|
-
*/import{
|
|
5
|
+
*/import{isDynamic as f}from"./utils";const s=(n,e,t,c,o)=>new Proxy(u=>{const r=t.at(-1),i=o.at(-1);if(u===void 0)throw new Error(`Missing value for dynamic parameter: ${i}`);if(r&&i&&f(r))return s(n,e,[...t],{...c,[i]:u},o);throw new Error(`${r} is not dynamic`)},{get(u,r){const i=n(r,{paths:t,params:c,dynamicKeys:o,options:e});return i!==void 0?i:f(r)?s(n,e,[...t,r],c,[...o,r]):s(n,e,[...t,r],c,o)}}),l=n=>(e="/",t={})=>s(n,t,[e],{},[]);export{l as makeCreateRpc};
|
|
@@ -100,4 +100,10 @@ export type DynamicPathProxyAsFunction<T> = Omit<(T extends Endpoint ? PathProxy
|
|
|
100
100
|
export type DynamicPathProxyAsProperty<T> = Omit<(T extends Endpoint ? PathProxyAsProperty<T> : unknown) & {
|
|
101
101
|
[K in keyof T]: K extends unknown ? DynamicPathProxyAsProperty<T[K]> : DynamicPathProxyAsProperty<T[K]>;
|
|
102
102
|
}, QueryKey | OptionalQueryKey | ParamsKey>;
|
|
103
|
+
export type RpcHandler = (key: string, context: {
|
|
104
|
+
paths: string[];
|
|
105
|
+
params: FuncParams;
|
|
106
|
+
dynamicKeys: string[];
|
|
107
|
+
options: ClientOptions;
|
|
108
|
+
}) => unknown | undefined;
|
|
103
109
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rpc4next",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
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",
|
|
@@ -77,22 +77,22 @@
|
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@types/node": "^22.14.1",
|
|
80
|
-
"@vitest/coverage-v8": "^3.1.
|
|
80
|
+
"@vitest/coverage-v8": "^3.1.2",
|
|
81
81
|
"@vitest/eslint-plugin": "^1.1.43",
|
|
82
|
-
"@vitest/ui": "^3.1.
|
|
83
|
-
"esbuild": "^0.25.
|
|
84
|
-
"eslint": "^9.
|
|
82
|
+
"@vitest/ui": "^3.1.2",
|
|
83
|
+
"esbuild": "^0.25.3",
|
|
84
|
+
"eslint": "^9.25.1",
|
|
85
85
|
"eslint-config-prettier": "^10.1.2",
|
|
86
86
|
"eslint-plugin-import": "^2.31.0",
|
|
87
87
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
88
88
|
"mock-fs": "^5.5.0",
|
|
89
|
-
"msw": "^2.7.
|
|
89
|
+
"msw": "^2.7.5",
|
|
90
90
|
"next": "15.3.1",
|
|
91
91
|
"prettier": "^3.5.3",
|
|
92
92
|
"ts-node": "^10.9.2",
|
|
93
93
|
"typescript": "^5.8.3",
|
|
94
|
-
"typescript-eslint": "^8.
|
|
95
|
-
"vitest": "^3.1.
|
|
94
|
+
"typescript-eslint": "^8.31.0",
|
|
95
|
+
"vitest": "^3.1.2",
|
|
96
96
|
"zod": "^3.24.3"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
package/dist/rpc/client/types.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/rpc/lib/types.js
DELETED
|
File without changes
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Portions of this code are based on the Hono project (https://github.com/honojs/hono),
|
|
3
|
-
* originally created by Yusuke Wada (https://github.com/yusukebe) and developed with
|
|
4
|
-
* contributions from the Hono community.
|
|
5
|
-
* This code has been adapted and modified for this project.
|
|
6
|
-
* Original copyright belongs to Yusuke Wada and the Hono project contributors.
|
|
7
|
-
* Hono is licensed under the MIT License.
|
|
8
|
-
*/
|
package/dist/rpc/server/types.js
DELETED
|
File without changes
|