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:183


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:190


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:257


JSONValue

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

The type of JavaScript values serializable to JSON.

Defined in

values/value.ts:24


GenericIdConstructor

Ƭ GenericIdConstructor<TableNames>: Object

Type parameters

NameType
TableNamesextends string

Call signature

new GenericIdConstructor<TableName>(tableName, id): GenericId<TableName>

Internal type used in Convex code generation.

Type parameters
NameType
TableNameextends string
Parameters
NameType
tableNameTableName
idstring
Returns

GenericId<TableName>

Type declaration

NameType
prototypeGenericId<string>
fromJSON(obj: any) => GenericId<string>

Defined in

values/value.ts:137


Value

Ƭ Value: GenericId<string> | null | bigint | number | boolean | string | ArrayBuffer | Value[] | Set<Value> | Map<Value, 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:158


NumericValue

Ƭ NumericValue: bigint | number

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

Defined in

values/value.ts:176

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>
bigint() => 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>
set<T>(values: Validator<T, false, any>) => Validator<Set<T>, false, never>
map<K, V>(keys: Validator<K, false, any>, values: Validator<V, false, any>) => Validator<Map<K, V>, 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 revive classes like GenericId that have been serialized to JSON, parse out BigInts, and so on.

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:370


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:511