Skip to main content

metaxy_cli/
lib.rs

1//! CLI tool for the [metaxy](https://github.com/misha-mad/metaxy) 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 `metaxy` and provides three subcommands:
10//!
11//! - **`metaxy scan`** — parse a directory and print discovered procedures as
12//!   human-readable text plus a JSON manifest.
13//! - **`metaxy generate`** — produce `rpc-types.ts` (interfaces + `Procedures`
14//!   type) and `rpc-client.ts` (typed `RpcClient` + `createRpcClient` factory).
15//! - **`metaxy 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//! └─────────────┘         └──────────┘           │ rpc.svelte.ts (opt)│
25//!                                                └────────────────────┘
26//! ```
27//!
28//! - [`parser`] — walks the source directory, parses each `.rs` file with
29//!   `syn`, and builds a [`model::Manifest`].
30//! - [`codegen::typescript`] — converts the manifest into a `rpc-types.ts`
31//!   file with TypeScript interfaces, enum types, and a `Procedures` map.
32//! - [`codegen::client`] — converts the manifest into a `rpc-client.ts` file
33//!   with a typed `RpcClient` interface and `createRpcClient` factory.
34//! - [`codegen::svelte`] — optionally converts the manifest into a
35//!   `rpc.svelte.ts` file with Svelte 5 reactive wrappers (`createQuery`,
36//!   `createMutation`).
37//! - [`watch`] — wraps `generate` in a file-watcher loop with debouncing.
38
39pub mod codegen;
40pub mod commands;
41pub mod config;
42pub mod model;
43pub mod parser;
44pub mod watch;