Skip to content

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 ​

FileContents
api.tsTyped references to public functions, plus devApi for development-only functions.
dataModel.tsTable documents, IDs, custom objects, and shared argument/result types.
index.tsRe-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.

RustJSONTypeScript
booltrueboolean
i8…i64, u8…u64, f32, f6442, 1.5number
String, &str, char"text"string
Option<T>the value or nullT | null
Option<T> as a function parametermay be left outfield?: T | null
Option<T> with #[serde(skip_serializing_if = "Option::is_none")]left out when Nonefield?: T | null
Vec<T>, HashSet<T>, BTreeSet<T>arrayArray<T>
HashMap<String, T>, BTreeMap<String, T>object{ [key in string]: T }
Id<T>"26 characters"Id<"table">
Doc<T>the fields plus _id, _creationTimeDoc<"table">
Bytes{ "$bytes": "base64" }{ $bytes: string } (Binary data)
serde_json::ValueanyJsonValue
a struct with #[object]object, camelCase keysa 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 larger i64 or u64 (a snowflake id, an external API's id, nanoseconds) arrives rounded, and nothing warns. Send such values as String.
  • Field names are camelCase in #[table] and #[object] types and in function arguments (created_at is createdAt), also when you write them by hand, as in ctx.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-written Serialize, Deserialize and ts_rs::TS derives) 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:

rust
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]:

rust
#[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.