@pyrpc/client 0.1.0-alpha.1 → 0.1.0-alpha.2

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.
Files changed (2) hide show
  1. package/README.md +71 -39
  2. package/package.json +4 -1
package/README.md CHANGED
@@ -1,39 +1,71 @@
1
- # @pyrpc/client
2
-
3
- The universal TypeScript client for pyRPC.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @pyrpc/client
9
- # or
10
- pnpm add @pyrpc/client
11
- # or
12
- yarn add @pyrpc/client
13
- ```
14
-
15
- ## Usage
16
-
17
- ```typescript
18
- import { createClient } from '@pyrpc/client';
19
- import type { AppRouter } from './server-types'; // Generated by pyrpc-codegen
20
-
21
- const client = createClient<AppRouter>({
22
- baseUrl: 'http://localhost:8000',
23
- });
24
-
25
- // Call remote procedures as local methods
26
- const user = await client.get_user({ id: 1 });
27
- console.log(user.name);
28
- ```
29
-
30
- ### Dynamic Headers (Auth)
31
-
32
- ```typescript
33
- const client = createClient({
34
- baseUrl: 'http://localhost:8000',
35
- headers: () => ({
36
- Authorization: `Bearer ${localStorage.getItem('token')}`,
37
- }),
38
- });
39
- ```
1
+ # @pyrpc/client
2
+
3
+ Universal TypeScript client for [pyRPC](https://pyrpc.dev). Type-safe RPC calls to your Python backend — install, import, call.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @pyrpc/client
9
+ ```
10
+
11
+ The postinstall script in `@pyrpc/types` will prompt for your server URL and generate typed contracts automatically.
12
+
13
+ For CI, set the `PYRPC_URL` environment variable:
14
+
15
+ ```bash
16
+ PYRPC_URL=https://api.example.com npm install @pyrpc/client
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```typescript
22
+ import { createClient } from "@pyrpc/client";
23
+ import type { Types } from "@pyrpc/types";
24
+
25
+ const client = createClient<Types>({
26
+ baseUrl: "https://api.example.com",
27
+ });
28
+
29
+ const user = await client.get_user(1);
30
+ console.log(user.name);
31
+ ```
32
+
33
+ The proxy-based API lets you call any remote procedure as a local method. Parameters are passed positionally or as a single object for named arguments.
34
+
35
+ ### Dynamic headers (auth)
36
+
37
+ ```typescript
38
+ const client = createClient({
39
+ baseUrl: "https://api.example.com",
40
+ headers: () => ({
41
+ Authorization: `Bearer ${localStorage.getItem("token")}`,
42
+ }),
43
+ });
44
+ ```
45
+
46
+ ### Error handling
47
+
48
+ ```typescript
49
+ import { createClient, PyRPCError } from "@pyrpc/client";
50
+
51
+ try {
52
+ await client.delete_user(1);
53
+ } catch (error) {
54
+ if (error instanceof PyRPCError) {
55
+ console.error(error.code, error.message);
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## API
61
+
62
+ ### `createClient<TTypes>(options?)`
63
+
64
+ Creates a proxy client that forwards method calls to the server.
65
+
66
+ - `baseUrl` — Server root URL (defaults to `window.location.origin` in browsers)
67
+ - `headers` — Static, dynamic, or async `HeadersInit`
68
+
69
+ ## License
70
+
71
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyrpc/client",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.2",
4
4
  "description": "Universal TypeScript client for pyRPC",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -23,6 +23,9 @@
23
23
  ],
24
24
  "author": "",
25
25
  "license": "MIT",
26
+ "dependencies": {
27
+ "@pyrpc/types": "^0.1.0-alpha.1"
28
+ },
26
29
  "devDependencies": {
27
30
  "@types/node": "^20.19.39",
28
31
  "tsup": "^8.5.1",