There are a few ways user code can interact with our system.
- There's a global
Convexobject that's created very early ininitialization::setup_contextand populated soon after when executingsetup.js. We pass this global object as the first argument to all UDFs. - The
Convex.syscallmethod, installed ininitialization::setup_contextand implemented withinsyscalls.rsprovides the API for the user to interact with the database. - Helpers within
setup.jsprovide bindings, likeConvex.getfor interacting with the database without having to useConvex.syscalldirectly. - The user can also import system modules under
convex:/systemthat will eventually include code derived from our npm package. For example, we'll eventually have a customInt64object that will be available for the user to create themselves within UDF execution.
Arguments Return value
┌───────────────────┐ ┌───────────────────┐
│ Convex Value (JS) │ │ Convex Value (JS) │
└───────────────────┘ └───────────────────┘
│ ▲
convexReplacer │
│ convexReviver
Browser ▼ │
┌──────────────────────────┐ ┌──────────────────────────┐
│ JSON-serializable object │ │ JSON-serializable object │
└──────────────────────────┘ └──────────────────────────┘
│ ▲
JSON.serialize │
│ JSON.parse
▼ │
┌─────────────┐ ┌─────────────┐
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┤ String ├ ─ ─ ─ ─ ─ ─ ─ ─ ┤ String ├ ─ ─ ─ ─ ─ ─ ─ ─ ─
└─────────────┘ └─────────────┘
│ ▲
serde::Deserialize │
│ serde::Serialize
▼ │
┌──────────────────────┐ ┌──────────────────────┐
Rust │ Convex Value (Rust) │ │ Convex Value (Rust) │
└──────────────────────┘ └──────────────────────┘
│ ▲
serde::Serialize │
│ serde::Deserialize
▼ │
┌────────────────┐ ┌────────────────┐
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┤ String │─ ─ ─ ─ ─ ─ ─ ┤ String │─ ─ ─ ─ ─ ─ ─ ─ ─
└────────────────┘ └────────────────┘
│ ▲
JSON.parse │
│ JSON.serialize
▼ │
┌──────────────────────────┐ ┌──────────────────────────┐
│ JSON-serializable object │ │ JSON-serializable object │
└──────────────────────────┘ └──────────────────────────┘
│ ▲
convexReviver │
V8 │ convexReplacer
▼ │
┌───────────────────┐ ┌───────────────────┐
│ Convex Value (JS) │ │ Convex Value (JS) │
└───────────────────┘ └───────────────────┘
│ ▲
│ │
│ ┌─────────────────────┐ │
│ │ │ │
└───▶│ User UDF code │────┘
│ │
└─────────────────────┘