Rust and TypeScript types
Rust is the source of truth for both stored data and function signatures. Regenerate the client API after changing either. In a generated web project, restart cargo run -- serve --dev; otherwise run your app’s codegen --out DIR command.
Generated files
| File | Contents |
|---|---|
api.ts | Typed references to public functions, plus devApi for development-only functions. |
dataModel.ts | Table documents, IDs, custom objects, and shared argument/result types. |
index.ts | Re-exports for importing from the generated directory. |
Do not edit these files manually. Function references carry argument and output types; they are used by all client bindings.
Value mapping
The generated api.ts and dataModel.ts give every function's arguments and result a TypeScript type. Values travel as JSON; this is how each Rust type looks on the client.
| Rust | JSON | TypeScript |
|---|---|---|
bool | true | boolean |
i8…i64, u8…u64, f32, f64 | 42, 1.5 | number |
String, &str, char | "text" | string |
Option<T> | the value or null | T | null |
Option<T> as a function parameter | may be left out | field?: T | null |
Option<T> with #[serde(skip_serializing_if = "Option::is_none")] | left out when None | field?: T | null |
Vec<T>, HashSet<T>, BTreeSet<T> | array | Array<T> |
HashMap<String, T>, BTreeMap<String, T> | object | { [key in string]: T } |
Id<T> | "26 characters" | Id<"table"> |
Doc<T> | the fields plus _id, _creationTime | Doc<"table"> |
Bytes | { "$bytes": "base64" } | { $bytes: string } (Binary data) |
serde_json::Value | any | JsonValue |
a struct with #[object] | object, camelCase keys | a named type |
an enum with #[object], unit variants | "inProgress" | "inProgress" | ... |
an enum with #[object], data variants | { "variant": ... } | a union |
chrono::DateTime<Utc>, NaiveDate, ... (feature chrono) | "2026-10-29T12:30:00Z" | string |
uuid::Uuid (feature uuid) | "…-…" | string |
Naming and precision
- 64-bit integers are
number. JavaScript numbers are exact only up to 2^53 (9 007 199 254 740 991): a largeri64oru64(a snowflake id, an external API's id, nanoseconds) arrives rounded, and nothing warns. Send such values asString. - Field names are camelCase in
#[table]and#[object]types and in function arguments (created_atiscreatedAt), also when you write them by hand, as inctx.db.patch(id, json!({ "createdAt": now }))(patch!(Note { created_at: now })names them as in Rust). The fields of an enum's struct variants keep their Rust names unless the enum sets#[serde(rename_all_fields = "camelCase")]. - Function names stay as written (
api.todos.set_done). - Your own types need
#[object](or hand-writtenSerialize,Deserializeandts_rs::TSderives) to appear in a function signature; the compiler says so when one is missing.
Define custom objects
Use #[object] on structs and enums appearing in function arguments or results when they are not tables:
use rxferrix::prelude::*;
#[object]
pub struct TaskSummary {
pub open_count: u32,
pub latest_text: Option<String>,
}The client gets a named TaskSummary type with openCount and latestText. The macro provides serde and TypeScript derives through framework re-exports. Field doc comments become generated JSDoc.
#[object] adds only Serialize, Deserialize, and TS. #[table] also derives Clone and Debug, so a type used as a table field needs those too. Derive them after #[object]:
#[object]
#[derive(Clone, Debug)]
pub struct Address {
pub street: String,
pub city: String,
}
#[table(name = "customers")]
pub struct Customer {
pub name: String,
pub address: Address,
}A field declared f32 or f64 stores a float. A whole number written into it as a JSON integer, such as ctx.db.patch(id, json!({ "score": 5 })) or a document saved in the dashboard, is stored as 5.0, so indexes, aggregates, and search filters on the field see one kind of number. This covers the fields whose shape the table knows: f32 and f64, Option and Vec of them, and the float fields of nested #[object] types. It does not reach inside types the table only knows as JSON, such as a newtype around f64 that is not an #[object], a map, or a field with #[serde(with = ...)].
Documents are not rewritten when this rule starts to apply to them. A document written by 0.12.0 or earlier, or one that held an integer while the field was declared as an integer type (i64 changed to f64 without a migration), keeps its integer until it is written again. Until then, eq and range queries on the field do not find it, and neither does a dashboard filter. Rewrite such documents with a migration that patches the field.
For dates and UUIDs, enable the chrono or uuid feature on rxferrix and add the corresponding crate to your app to name its types. Use serde support as needed. Dates serialize as strings according to the type's serde format; DateTime<Utc> uses RFC 3339. ctx.now() remains f64 epoch milliseconds.
When hand-writing patches, use serialized field names. When calling functions, keep their Rust names: set_done is api.tasks.set_done, while a completed_at argument becomes completedAt.