Baseflare uses plain UUIDv7 strings as document IDs. UUIDv7 is a time-sortable UUID format — the most significant 48 bits encode a Unix millisecond timestamp, which means ordering documents byDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nickruigrok/baseflare/llms.txt
Use this file to discover all available pages before exploring further.
_id is equivalent to ordering them by creation time. Because the timestamp is encoded directly in the ID, Baseflare derives the _createdAt field on every document from the ID at read time; no separate timestamp column is stored in the database. All ID utilities are exported from baseflare/values and can be used in both server-side handlers and client-side code.
Import
generateId()
Generates a new UUIDv7 string using the current system time as the timestamp component. Each call produces a unique, time-ordered ID suitable for use as a document _id.
Signature:
You rarely need to call
generateId() directly in application code — Baseflare automatically assigns a UUIDv7 _id when you insert a document via ctx.db.insert(). Use generateId() when you need to know the ID before performing the insert, for example to create cross-references between two documents in a single mutation.getCreatedAtFromId(id)
Extracts the creation timestamp encoded in a UUIDv7 string and returns it as a JavaScript Date object. The timestamp has millisecond precision.
Signature:
A valid UUIDv7 string. Throws an
Error if the string is not a valid UUIDv7.Date representing the millisecond the ID was created.
getCreatedMsFromId(id)
Extracts the creation timestamp encoded in a UUIDv7 string and returns it as milliseconds since the Unix epoch. Use this when you need a numeric timestamp rather than a Date object.
Signature:
A valid UUIDv7 string. Throws an
Error if the string is not a valid UUIDv7.number).
isUuidV7(value)
Tests whether a string is a well-formed UUIDv7. The check is purely structural (regex pattern match) — it does not validate that the timestamp is sensible or that the ID was generated by Baseflare.
Signature:
The string to test.
true if value matches the UUIDv7 pattern, false otherwise.
minIdForMs(ms) and maxIdForMs(ms)
These two utilities produce the lexicographic minimum and maximum UUIDv7 strings for a given millisecond timestamp. They are primarily used internally to construct efficient time-range queries against _id — since IDs are time-ordered, a range query _id >= minIdForMs(start) AND _id <= maxIdForMs(end) scans only documents created in that time window.
Signatures:
A Unix timestamp in milliseconds. Must be a safe integer between
0 and 281474976710655 (0xFFFFFFFFFFFF). Throws a ValidationError if out of range.Id<TableName> Type
Id<TableName> is a branded string type that carries the table name as a compile-time phantom type parameter. At runtime it is just a plain string, but TypeScript will refuse to accept an Id<'users'> where an Id<'todos'> is expected.
Using
v.id('tableName') in a validator both validates the UUIDv7 format at runtime and provides the branded Id<'tableName'> TypeScript type for the field. You get full safety at both the runtime and type-system layers with a single declaration.