Module: values
Utilities for working with values stored in Convex.
You can see the full set of supported types at Types.
Namespaces
Classes
Type Aliases
PropertyValidators
Ƭ PropertyValidators: Record
<string
, Validator
<any
, any
, any
>>
Validators for each property of an object.
This is represented as an object mapping the property name to its Validator.
Defined in
ObjectType
Ƭ ObjectType<Validators
>: Expand
<{ [Property in OptionalKeys<Validators>]?: Validators[Property]["type"] } & { [Property in RequiredKeys<Validators>]: Validators[Property]["type"] }>
Compute the type of an object from PropertyValidators.
Type parameters
Name | Type |
---|---|
Validators | extends PropertyValidators |
Defined in
Infer
Ƭ Infer<V
>: V
["type"
]
Extract a TypeScript type from a validator.
Example usage:
const objectSchema = v.object({
property: v.string(),
});
type MyObject = Infer<typeof objectSchema>; // { property: string }
Type parameters
Name | Type | Description |
---|---|---|
V | extends Validator <any , any , any > | The type of a Validator constructed with v. |
Defined in
JSONValue
Ƭ JSONValue: null
| boolean
| number
| string
| JSONValue
[] | { [key: string]
: JSONValue
; }
The type of JavaScript values serializable to JSON.
Defined in
GenericId
Ƭ GenericId<TableName
>: string
& { __tableName
: TableName
}
An identifier for a document in Convex.
Convex documents are uniquely identified by their Id
, which is accessible
on the _id
field. To learn more, see Document IDs.
Documents can be loaded using db.get(id)
in query and mutation functions.
IDs are base 32 encoded strings which are URL safe.
IDs are just strings at runtime, but this type can be used to distinguish them from other strings at compile time.
If you're using code generation, use the Id
type generated for your data model in
convex/_generated/dataModel.d.ts
.
Type parameters
Name | Type | Description |
---|---|---|
TableName | extends string | A string literal type of the table name (like "users"). |
Defined in
Value
Ƭ Value: null
| bigint
| number
| boolean
| string
| ArrayBuffer
| Value
[] | { [key: string]
: undefined
| Value
; }
A value supported by Convex.
Values can be:
- stored inside of documents.
- used as arguments and return types to queries and mutation functions.
You can see the full set of supported types at Types.
Defined in
NumericValue
Ƭ NumericValue: bigint
| number
The types of Value that can be used to represent numbers.
Defined in
Variables
v
• Const
v: Object
The validator builder.
This builder allows you to build validators for Convex values.
Validators can be used in schema definitions and as input validators for Convex functions.
Type declaration
Name | Type |
---|---|
id | <TableName>(tableName : TableName ) => Validator <GenericId <TableName >, false , never > |
null | () => Validator <null , false , never > |
number | () => Validator <number , false , never > |
float64 | () => Validator <number , false , never > |
bigint | () => Validator <bigint , false , never > |
int64 | () => Validator <bigint , false , never > |
boolean | () => Validator <boolean , false , never > |
string | () => Validator <string , false , never > |
bytes | () => Validator <ArrayBuffer , false , never > |
literal | <T>(literal : T ) => Validator <T , false , never > |
array | <T>(values : Validator <T , false , any >) => Validator <T [], false , never > |
object | <T>(schema : T ) => ObjectValidator <T > |
union | <T>(...schemaTypes : T ) => Validator <T [number ]["type" ], false , T [number ]["fieldPaths" ]> |
any | () => Validator <any , false , string > |
optional | <T>(inner : T ) => Validator <undefined | T ["type" ], true , T ["fieldPaths" ]> |
Defined in
Functions
jsonToConvex
▸ jsonToConvex(value
): Value
Parse a Convex value from its JSON representation.
This function will deserialize serialized Int64s to BigInt
s, Bytes to ArrayBuffer
s etc.
To learn more about Convex values, see Types.
Parameters
Name | Type | Description |
---|---|---|
value | JSONValue | The JSON representation of a Convex value previously created with convexToJson. |
Returns
The JavaScript representation of the Convex value.
Defined in
convexToJson
▸ convexToJson(value
): JSONValue
Convert a Convex value to its JSON representation.
Use jsonToConvex to recreate the original value.
To learn more about Convex values, see Types.
Parameters
Name | Type | Description |
---|---|---|
value | Value | A Convex value to convert into JSON. |
Returns
The JSON representation of value
.