Skip to main content

vercel_rpc_cli/
lib.rs

1//! CLI tool for the [vercel-rpc](https://github.com/misha-mad/vercel-rpc) project.
2//!
3//! Scans Rust lambda source files for `#[rpc_query]` / `#[rpc_mutation]`
4//! functions and `#[derive(Serialize)]` types, then generates TypeScript type
5//! definitions and a fully typed RPC client.
6//!
7//! # Binary
8//!
9//! The installed binary is called `rpc` and provides three subcommands:
10//!
11//! - **`rpc scan`** — parse a directory and print discovered procedures as
12//!   human-readable text plus a JSON manifest.
13//! - **`rpc generate`** — produce `rpc-types.ts` (interfaces + `Procedures`
14//!   type) and `rpc-client.ts` (typed `RpcClient` + `createRpcClient` factory).
15//! - **`rpc watch`** — same as `generate`, but re-runs automatically whenever
16//!   a `.rs` file changes (configurable debounce).
17//!
18//! # Architecture
19//!
20//! ```text
21//! ┌─────────────┐  scan   ┌──────────┐  codegen  ┌────────────────┐
22//! │  api/*.rs   │ ──────► │ Manifest │ ────────► │ rpc-types.ts   │
23//! │  attributes │  (syn)  │          │ (fmt)     │ rpc-client.ts  │
24//! └─────────────┘         └──────────┘           └────────────────┘
25//! ```
26//!
27//! - [`parser`] — walks the source directory, parses each `.rs` file with
28//!   `syn`, and builds a [`model::Manifest`].
29//! - [`codegen::typescript`] — converts the manifest into a `rpc-types.ts`
30//!   file with TypeScript interfaces, enum types, and a `Procedures` map.
31//! - [`codegen::client`] — converts the manifest into a `rpc-client.ts` file
32//!   with a typed `RpcClient` interface and `createRpcClient` factory.
33//! - [`watch`] — wraps `generate` in a file-watcher loop with debouncing.
34
35pub mod codegen;
36pub mod commands;
37pub mod config;
38pub mod model;
39pub mod parser;
40pub mod watch;