Skip to main content

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

values/validator.ts:195


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

NameType
Validatorsextends PropertyValidators

Defined in

values/validator.ts:202


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

NameTypeDescription
Vextends Validator<any, any, any>The type of a Validator constructed with v.

Defined in

values/validator.ts:289


JSONValue

Ƭ JSONValue: null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue; }

The type of JavaScript values serializable to JSON.

Defined in

values/value.ts:24


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

NameTypeDescription
TableNameextends stringA string literal type of the table name (like "users").

Defined in

values/value.ts:52


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

values/value.ts:66


NumericValue

Ƭ NumericValue: bigint | number

The types of Value that can be used to represent numbers.

Defined in

values/value.ts:81

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

NameType
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

values/validator.ts:81

Functions

jsonToConvex

jsonToConvex(value): Value

Parse a Convex value from its JSON representation.

This function will deserialize serialized Int64s to BigInts, Bytes to ArrayBuffers etc.

To learn more about Convex values, see Types.

Parameters

NameTypeDescription
valueJSONValueThe JSON representation of a Convex value previously created with convexToJson.

Returns

Value

The JavaScript representation of the Convex value.

Defined in

values/value.ts:190


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

NameTypeDescription
valueValueA Convex value to convert into JSON.

Returns

JSONValue

The JSON representation of value.

Defined in

values/value.ts:419