Module: server
Utilities for implementing server-side Convex query and mutation functions.
Usage
Code Generation
This module is typically used alongside generated server code.
To generate the server code, run npx convex dev
in your Convex project.
This will create a convex/_generated/server.js
file with the following
functions, typed for your schema:
If you aren't using TypeScript and code generation, you can use these untyped functions instead:
Example
Convex functions are defined by using either the query
or
mutation
wrappers.
Queries receive a db
that implements the GenericDatabaseReader interface.
import { query } from "./_generated/server";
export default query(async ({ db }, { arg1, arg2 }) => {
// Your (read-only) code here!
});
If your function needs to write to the database, such as inserting, updating,
or deleting documents, use mutation
instead which provides a db
that
implements the GenericDatabaseWriter interface.
import { mutation } from "./_generated/server";
export default mutation(async ({ db }, { arg1, arg2 }) => {
// Your mutation code here!
});
Classes
- Crons
- Expression
- IndexRange
- HttpRouter
- TableDefinition
- SchemaDefinition
- SearchFilter
- FilterExpression
Interfaces
- UserIdentity
- Auth
- CronJob
- DatabaseReader
- GenericDatabaseReader
- DatabaseWriter
- GenericDatabaseWriter
- FilterBuilder
- IndexRangeBuilder
- PaginationResult
- PaginationOptions
- QueryInitializer
- Query
- OrderedQuery
- GenericMutationCtx
- MutationCtx
- GenericQueryCtx
- QueryCtx
- GenericActionCtx
- ActionCtx
- ValidatedFunction
- Scheduler
- SearchIndexConfig
- DefineSchemaOptions
- SystemDataModel
- SearchFilterBuilder
- SearchFilterFinalizer
- StorageReader
- StorageWriter
- StorageActionWriter
- VectorSearchQuery
- VectorFilterBuilder
Type Aliases
FunctionType
Ƭ FunctionType: "query"
| "mutation"
| "action"
The type of a Convex function.
Defined in
FunctionReference
Ƭ FunctionReference<Type
, Visibility
, Args
, ReturnType
>: Object
A reference to a registered Convex function.
You can create a FunctionReference using the generated api
utility:
import { api } from "../convex/_generated/api";
const reference = api.myModule.myFunction;
If you aren't using code generation, you can create references using anyApi:
import { anyApi } from "convex/server";
const reference = anyApi.myModule.myFunction;
Function references can be used to invoke functions from the client. For example, in React you can pass references to the useQuery hook:
const result = useQuery(api.myModule.myFunction);
Type parameters
Name | Type | Description |
---|---|---|
Type | extends FunctionType | The type of the function ("query", "mutation", or "action"). |
Visibility | extends FunctionVisibility = "public" | The visibility of the function ("public" or "internal"). |
Args | extends DefaultFunctionArgs = any | The arguments to this function. This is an object mapping argument names to their types. |
ReturnType | any | The return type of this function. |
Type declaration
Name | Type |
---|---|
_type | Type |
_visibility | Visibility |
_args | Args |
_returnType | ReturnType |
Defined in
ApiFromModules
Ƭ ApiFromModules<AllModules
>: FilterApi
<ApiFromModulesAllowEmptyNodes
<AllModules
>, FunctionReference
<any
, any
, any
, any
>>
Given the types of all modules in the convex/
directory, construct the type
of api
.
api
is a utility for constructing FunctionReferences.
Type parameters
Name | Type | Description |
---|---|---|
AllModules | extends Record <string , object > | A type mapping module paths (like "dir/myModule" ) to the types of the modules. |
Defined in
FilterApi
Ƭ FilterApi<API
, Predicate
>: Expand
<{ [mod in keyof API as API[mod] extends Predicate ? mod : API[mod] extends FunctionReference<any, any, any, any> ? never : FilterApi<API[mod], Predicate> extends Record<string, never> ? never : mod]: API[mod] extends Predicate ? API[mod] : FilterApi<API[mod], Predicate> }>
Filter a Convex deployment api object for functions which meet criteria, for example all public queries.
Type parameters
Name |
---|
API |
Predicate |
Defined in
AnyApi
Ƭ AnyApi: Record
<string
, Record
<string
, AnyModuleDirOrFunc
>>
The type that Convex api objects extend. If you were writing an api from scratch it should extend this type.
Defined in
PartialApi
Ƭ PartialApi<API
>: { [mod in keyof API]?: API[mod] extends FunctionReference<any, any, any, any> ? API[mod] : PartialApi<API[mod]> }
Recursive partial API, useful for defining a subset of an API when mocking or building custom api objects.
Type parameters
Name |
---|
API |
Defined in
FunctionArgs
Ƭ FunctionArgs<FuncRef
>: FuncRef
["_args"
]
Given a FunctionReference, get the return type of the function.
This is represented as an object mapping argument names to values.
Type parameters
Name | Type |
---|---|
FuncRef | extends AnyFunctionReference |
Defined in
OptionalRestArgs
Ƭ OptionalRestArgs<FuncRef
>: FuncRef
["_args"
] extends EmptyObject
? [args?: EmptyObject] : [args: FuncRef["_args"]]
A tuple type of the (maybe optional) arguments to FuncRef
.
This type is used to make methods involving arguments type safe while allowing skipping the arguments for functions that don't require arguments.
Type parameters
Name | Type |
---|---|
FuncRef | extends AnyFunctionReference |
Defined in
ArgsAndOptions
Ƭ ArgsAndOptions<FuncRef
, Options
>: FuncRef
["_args"
] extends EmptyObject
? [args?: EmptyObject, options?: Options] : [args: FuncRef["_args"], options?: Options]
A tuple type of the (maybe optional) arguments to FuncRef
, followed by an options
object of type Options
.
This type is used to make methods like useQuery
type-safe while allowing
- Skipping arguments for functions that don't require arguments.
- Skipping the options object.
Type parameters
Name | Type |
---|---|
FuncRef | extends AnyFunctionReference |
Options | Options |
Defined in
FunctionReturnType
Ƭ FunctionReturnType<FuncRef
>: FuncRef
["_returnType"
]
Given a FunctionReference, get the return type of the function.
Type parameters
Name | Type |
---|---|
FuncRef | extends AnyFunctionReference |
Defined in
GenericDocument
Ƭ GenericDocument: Record
<string
, Value
>
A document stored in Convex.
Defined in
GenericFieldPaths
Ƭ GenericFieldPaths: string
A type describing all of the document fields in a table.
These can either be field names (like "name") or references to fields on nested objects (like "properties.name").
Defined in
GenericIndexFields
Ƭ GenericIndexFields: string
[]
A type describing the ordered fields in an index.
These can either be field names (like "name") or references to fields on nested objects (like "properties.name").
Defined in
GenericTableIndexes
Ƭ GenericTableIndexes: Record
<string
, GenericIndexFields
>
A type describing the indexes in a table.
It's an object mapping each index name to the fields in the index.
Defined in
GenericSearchIndexConfig
Ƭ GenericSearchIndexConfig: Object
A type describing the configuration of a search index.
Type declaration
Name | Type |
---|---|
searchField | string |
filterFields | string |
Defined in
GenericTableSearchIndexes
Ƭ GenericTableSearchIndexes: Record
<string
, GenericSearchIndexConfig
>
A type describing all of the search indexes in a table.
This is an object mapping each index name to the config for the index.
Defined in
GenericVectorIndexConfig
Ƭ GenericVectorIndexConfig: Object
A type describing the configuration of a vector index.
Type declaration
Name | Type |
---|---|
vectorField | string |
dimensions | number |
filterFields | string |
Defined in
GenericTableVectorIndexes
Ƭ GenericTableVectorIndexes: Record
<string
, GenericVectorIndexConfig
>
A type describing all of the vector indexes in a table.
This is an object mapping each index name to the config for the index.
Defined in
FieldTypeFromFieldPath
Ƭ FieldTypeFromFieldPath<Document
, FieldPath
>: FieldPath
extends `${infer First}.${infer Second}` ? ValueFromUnion
<Document
, First
, Record
<never
, never
>> extends GenericDocument
? FieldTypeFromFieldPath
<ValueFromUnion
<Document
, First
, Record
<never
, never
>>, Second
> : undefined
: ValueFromUnion
<Document
, FieldPath
, undefined
>
The type of a field in a document.
Note that this supports both simple fields like "name" and nested fields like "properties.name".
If the field is not present in the document it is considered to be undefined
.
Type parameters
Name | Type |
---|---|
Document | extends GenericDocument |
FieldPath | extends string |
Defined in
GenericTableInfo
Ƭ GenericTableInfo: Object
A type describing the document type and indexes in a table.
Type declaration
Name | Type |
---|---|
document | GenericDocument |
fieldPaths | GenericFieldPaths |
indexes | GenericTableIndexes |
searchIndexes | GenericTableSearchIndexes |
vectorIndexes | GenericTableVectorIndexes |
Defined in
DocumentByInfo
Ƭ DocumentByInfo<TableInfo
>: TableInfo
["document"
]
The type of a document in a table for a given GenericTableInfo.
Type parameters
Name | Type |
---|---|
TableInfo | extends GenericTableInfo |
Defined in
FieldPaths
Ƭ FieldPaths<TableInfo
>: TableInfo
["fieldPaths"
]
The field paths in a table for a given GenericTableInfo.
These can either be field names (like "name") or references to fields on nested objects (like "properties.name").
Type parameters
Name | Type |
---|---|
TableInfo | extends GenericTableInfo |
Defined in
Indexes
Ƭ Indexes<TableInfo
>: TableInfo
["indexes"
]
The database indexes in a table for a given GenericTableInfo.
This will be an object mapping index names to the fields in the index.
Type parameters
Name | Type |
---|---|
TableInfo | extends GenericTableInfo |
Defined in
IndexNames
Ƭ IndexNames<TableInfo
>: keyof Indexes
<TableInfo
>
The names of indexes in a table for a given GenericTableInfo.
Type parameters
Name | Type |
---|---|
TableInfo | extends GenericTableInfo |
Defined in
NamedIndex
Ƭ NamedIndex<TableInfo
, IndexName
>: Indexes
<TableInfo
>[IndexName
]
Extract the fields of an index from a GenericTableInfo by name.
Type parameters
Name | Type |
---|---|
TableInfo | extends GenericTableInfo |
IndexName | extends IndexNames <TableInfo > |
Defined in
SearchIndexes
Ƭ SearchIndexes<TableInfo
>: TableInfo
["searchIndexes"
]
The search indexes in a table for a given GenericTableInfo.
This will be an object mapping index names to the search index config.
Type parameters
Name | Type |
---|---|
TableInfo | extends GenericTableInfo |
Defined in
SearchIndexNames
Ƭ SearchIndexNames<TableInfo
>: keyof SearchIndexes
<TableInfo
>
The names of search indexes in a table for a given GenericTableInfo.
Type parameters
Name | Type |
---|---|
TableInfo | extends GenericTableInfo |
Defined in
NamedSearchIndex
Ƭ NamedSearchIndex<TableInfo
, IndexName
>: SearchIndexes
<TableInfo
>[IndexName
]
Extract the config of a search index from a GenericTableInfo by name.
Type parameters
Name | Type |
---|---|
TableInfo | extends GenericTableInfo |
IndexName | extends SearchIndexNames <TableInfo > |
Defined in
VectorIndexes
Ƭ VectorIndexes<TableInfo
>: TableInfo
["vectorIndexes"
]
The vector indexes in a table for a given GenericTableInfo.
This will be an object mapping index names to the vector index config.
Type parameters
Name | Type |
---|---|
TableInfo | extends GenericTableInfo |
Defined in
VectorIndexNames
Ƭ VectorIndexNames<TableInfo
>: keyof VectorIndexes
<TableInfo
>
The names of vector indexes in a table for a given GenericTableInfo.
Type parameters
Name | Type |
---|---|
TableInfo | extends GenericTableInfo |
Defined in
NamedVectorIndex
Ƭ NamedVectorIndex<TableInfo
, IndexName
>: VectorIndexes
<TableInfo
>[IndexName
]
Extract the config of a vector index from a GenericTableInfo by name.
Type parameters
Name | Type |
---|---|
TableInfo | extends GenericTableInfo |
IndexName | extends VectorIndexNames <TableInfo > |
Defined in
GenericDataModel
Ƭ GenericDataModel: Record
<string
, GenericTableInfo
>
A type describing the tables in a Convex project.
This is designed to be code generated with npx convex dev
.
Defined in
AnyDataModel
Ƭ AnyDataModel: Object
A GenericDataModel that considers documents to be any
and does not
support indexes.
This is the default before a schema is defined.
Index signature
▪ [tableName: string
]: { document
: any
; fieldPaths
: GenericFieldPaths
; indexes
: ; searchIndexes
: ; vectorIndexes
: }
Defined in
TableNamesInDataModel
Ƭ TableNamesInDataModel<DataModel
>: keyof DataModel
& string
A type of all of the table names defined in a GenericDataModel.
Type parameters
Name | Type |
---|---|
DataModel | extends GenericDataModel |
Defined in
NamedTableInfo
Ƭ NamedTableInfo<DataModel
, TableName
>: DataModel
[TableName
]
Extract the TableInfo
for a table in a GenericDataModel by table
name.
Type parameters
Name | Type |
---|---|
DataModel | extends GenericDataModel |
TableName | extends keyof DataModel |
Defined in
DocumentByName
Ƭ DocumentByName<DataModel
, TableName
>: DataModel
[TableName
]["document"
]
The type of a document in a GenericDataModel by table name.
Type parameters
Name | Type |
---|---|
DataModel | extends GenericDataModel |
TableName | extends TableNamesInDataModel <DataModel > |
Defined in
ExpressionOrValue
Ƭ ExpressionOrValue<T
>: Expression
<T
> | T
An Expression or a constant Value
Type parameters
Name | Type |
---|---|
T | extends Value | undefined |
Defined in
Cursor
Ƭ Cursor: string
An opaque identifier used for paginating a database query.
Cursors are returned from paginate and represent the point of the query where the page of results ended.
To continue paginating, pass the cursor back into paginate in the PaginationOptions object to fetch another page of results.
Note: Cursors can only be passed to exactly the same database query that they were generated from. You may not reuse a cursor between different database queries.
Defined in
DefaultFunctionArgs
Ƭ DefaultFunctionArgs: Record
<string
, unknown
>
The default arguments type for a Convex query, mutation, or action function.
Convex functions always take an arguments object that maps the argument names to their values.
Defined in
ArgsArray
Ƭ ArgsArray: OneArgArray
| NoArgsArray
An array of arguments to a Convex function.
Convex functions can take either a single DefaultFunctionArgs object or no args at all.
Defined in
FunctionVisibility
Ƭ FunctionVisibility: "public"
| "internal"
A type representing the visibility of a Convex function.
Defined in
RegisteredMutation
Ƭ RegisteredMutation<Visibility
, Args
, Output
>: (ctx
: GenericMutationCtx
<any
>, args
: Args
) => Output
& VisibilityProperties
<Visibility
>
A mutation function that is part of this app.
You can create a mutation by wrapping your function in mutationGeneric or internalMutationGeneric and exporting it.
Type parameters
Name | Type |
---|---|
Visibility | extends FunctionVisibility |
Args | extends DefaultFunctionArgs |
Output | Output |
Defined in
RegisteredQuery
Ƭ RegisteredQuery<Visibility
, Args
, Output
>: (ctx
: GenericQueryCtx
<any
>, args
: Args
) => Output
& VisibilityProperties
<Visibility
>
A query function that is part of this app.
You can create a query by wrapping your function in queryGeneric or internalQueryGeneric and exporting it.
Type parameters
Name | Type |
---|---|
Visibility | extends FunctionVisibility |
Args | extends DefaultFunctionArgs |
Output | Output |
Defined in
RegisteredAction
Ƭ RegisteredAction<Visibility
, Args
, Output
>: (ctx
: GenericActionCtx
<any
>, args
: Args
) => Output
& VisibilityProperties
<Visibility
>
An action that is part of this app.
You can create an action by wrapping your function in actionGeneric or internalActionGeneric and exporting it.
Type parameters
Name | Type |
---|---|
Visibility | extends FunctionVisibility |
Args | extends DefaultFunctionArgs |
Output | Output |
Defined in
PublicHttpAction
Ƭ PublicHttpAction: Object
Call signature
▸ (ctx
, request
): Response
An HTTP action that is part of this app's public API.
You can create public HTTP actions by wrapping your function in httpActionGeneric and exporting it.
Parameters
Name | Type |
---|---|
ctx | GenericActionCtx <any > |
request | Request |
Returns
Response
Type declaration
Name | Type |
---|---|
isHttp | true |
isRegistered? | true |
Defined in
UnvalidatedFunction
Ƭ UnvalidatedFunction<Ctx
, Args
, Output
>: (ctx
: Ctx
, ...args
: Args
) => Output
| { handler
: (ctx
: Ctx
, ...args
: Args
) => Output
}
The definition of a Convex query, mutation, or action function without argument validation.
Convex functions always take a context object as their first argument and an (optional) args object as their second argument.
This can be written as a function like:
import { query } from "./_generated/server";
export const func = query(({ db }, { arg }) => {...});
or as an object like:
import { query } from "./_generated/server";
export const func = query({
handler: ({ db }, { arg }) => {...},
});
See ValidatedFunction to add argument validation.
Type parameters
Name | Type |
---|---|
Ctx | Ctx |
Args | extends ArgsArray |
Output | Output |
Defined in
MutationBuilder
Ƭ MutationBuilder<DataModel
, Visibility
>: <Output, ArgsValidator>(func
: ValidatedFunction
<GenericMutationCtx
<DataModel
>, ArgsValidator
, Output
>) => RegisteredMutation
<Visibility
, ObjectType
<ArgsValidator
>, Output
><Output, Args>(func
: UnvalidatedFunction
<GenericMutationCtx
<DataModel
>, Args
, Output
>) => RegisteredMutation
<Visibility
, ArgsArrayToObject
<Args
>, Output
>
Type parameters
Name | Type |
---|---|
DataModel | extends GenericDataModel |
Visibility | extends FunctionVisibility |
Type declaration
▸ <Output
, ArgsValidator
>(func
): RegisteredMutation
<Visibility
, ObjectType
<ArgsValidator
>, Output
>
Internal type helper used by Convex code generation.
Used to give mutationGeneric a type specific to your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
ArgsValidator | extends PropertyValidators |
Parameters
Name | Type |
---|---|
func | ValidatedFunction <GenericMutationCtx <DataModel >, ArgsValidator , Output > |
Returns
RegisteredMutation
<Visibility
, ObjectType
<ArgsValidator
>, Output
>
▸ <Output
, Args
>(func
): RegisteredMutation
<Visibility
, ArgsArrayToObject
<Args
>, Output
>
Internal type helper used by Convex code generation.
Used to give mutationGeneric a type specific to your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
Args | extends ArgsArray = OneArgArray <DefaultFunctionArgs > |
Parameters
Name | Type |
---|---|
func | UnvalidatedFunction <GenericMutationCtx <DataModel >, Args , Output > |
Returns
RegisteredMutation
<Visibility
, ArgsArrayToObject
<Args
>, Output
>
Defined in
QueryBuilder
Ƭ QueryBuilder<DataModel
, Visibility
>: <Output, ArgsValidator>(func
: ValidatedFunction
<GenericQueryCtx
<DataModel
>, ArgsValidator
, Output
>) => RegisteredQuery
<Visibility
, ObjectType
<ArgsValidator
>, Output
><Output, Args>(func
: UnvalidatedFunction
<GenericQueryCtx
<DataModel
>, Args
, Output
>) => RegisteredQuery
<Visibility
, ArgsArrayToObject
<Args
>, Output
>
Type parameters
Name | Type |
---|---|
DataModel | extends GenericDataModel |
Visibility | extends FunctionVisibility |
Type declaration
▸ <Output
, ArgsValidator
>(func
): RegisteredQuery
<Visibility
, ObjectType
<ArgsValidator
>, Output
>
Internal type helper used by Convex code generation.
Used to give queryGeneric a type specific to your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
ArgsValidator | extends PropertyValidators |
Parameters
Name | Type |
---|---|
func | ValidatedFunction <GenericQueryCtx <DataModel >, ArgsValidator , Output > |
Returns
RegisteredQuery
<Visibility
, ObjectType
<ArgsValidator
>, Output
>
▸ <Output
, Args
>(func
): RegisteredQuery
<Visibility
, ArgsArrayToObject
<Args
>, Output
>
Internal type helper used by Convex code generation.
Used to give queryGeneric a type specific to your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
Args | extends ArgsArray = OneArgArray <DefaultFunctionArgs > |
Parameters
Name | Type |
---|---|
func | UnvalidatedFunction <GenericQueryCtx <DataModel >, Args , Output > |
Returns
RegisteredQuery
<Visibility
, ArgsArrayToObject
<Args
>, Output
>
Defined in
ActionBuilder
Ƭ ActionBuilder<DataModel
, Visibility
>: <Output, ArgsValidator>(func
: ValidatedFunction
<GenericActionCtx
<DataModel
>, ArgsValidator
, Output
>) => RegisteredAction
<Visibility
, ObjectType
<ArgsValidator
>, Output
><Output, Args>(func
: UnvalidatedFunction
<GenericActionCtx
<DataModel
>, Args
, Output
>) => RegisteredAction
<Visibility
, ArgsArrayToObject
<Args
>, Output
>
Type parameters
Name | Type |
---|---|
DataModel | extends GenericDataModel |
Visibility | extends FunctionVisibility |
Type declaration
▸ <Output
, ArgsValidator
>(func
): RegisteredAction
<Visibility
, ObjectType
<ArgsValidator
>, Output
>
Internal type helper used by Convex code generation.
Used to give actionGeneric a type specific to your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
ArgsValidator | extends PropertyValidators |
Parameters
Name | Type |
---|---|
func | ValidatedFunction <GenericActionCtx <DataModel >, ArgsValidator , Output > |
Returns
RegisteredAction
<Visibility
, ObjectType
<ArgsValidator
>, Output
>
▸ <Output
, Args
>(func
): RegisteredAction
<Visibility
, ArgsArrayToObject
<Args
>, Output
>
Internal type helper used by Convex code generation.
Used to give actionGeneric a type specific to your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
Args | extends ArgsArray = OneArgArray <DefaultFunctionArgs > |
Parameters
Name | Type |
---|---|
func | UnvalidatedFunction <GenericActionCtx <DataModel >, Args , Output > |
Returns
RegisteredAction
<Visibility
, ArgsArrayToObject
<Args
>, Output
>
Defined in
HttpActionBuilder
Ƭ HttpActionBuilder: (func
: (ctx
: GenericActionCtx
<any
>, request
: Request
) => Promise
<Response
>) => PublicHttpAction
Type declaration
▸ (func
): PublicHttpAction
Internal type helper used by Convex code generation.
Used to give httpActionGeneric a type specific to your data model and functions.
Parameters
Name | Type |
---|---|
func | (ctx : GenericActionCtx <any >, request : Request ) => Promise <Response > |
Returns
Defined in
RoutableMethod
Ƭ RoutableMethod: typeof ROUTABLE_HTTP_METHODS
[number
]
A type representing the methods supported by Convex HTTP actions.
HEAD is handled by Convex by running GET and stripping the body. CONNECT is not supported and will not be supported. TRACE is not supported and will not be supported.
Defined in
SchedulableFunctionReference
Ƭ SchedulableFunctionReference: FunctionReference
<"mutation"
| "action"
, "public"
| "internal"
>
A FunctionReference that can be scheduled to run in the future.
Schedulable functions are mutations and actions that are public or internal.
Defined in
GenericSchema
Ƭ GenericSchema: Record
<string
, TableDefinition
>
A type describing the schema of a Convex project.
This should be constructed using defineSchema, defineTable, and v.
Defined in
DataModelFromSchemaDefinition
Ƭ DataModelFromSchemaDefinition<SchemaDef
>: MaybeMakeLooseDataModel
<{ [TableName in keyof SchemaDef["tables"] & string]: SchemaDef["tables"][TableName] extends TableDefinition<infer Document, infer FieldPaths, infer Indexes, infer SearchIndexes, infer VectorIndexes> ? Object : never }, SchemaDef
["strictTableNameTypes"
]>
Internal type used in Convex code generation!
Convert a SchemaDefinition into a GenericDataModel.
Type parameters
Name | Type |
---|---|
SchemaDef | extends SchemaDefinition <any , boolean > |
Defined in
SystemTableNames
Ƭ SystemTableNames: TableNamesInDataModel
<SystemDataModel
>
Defined in
StorageId
Ƭ StorageId: string
A reference to a file in storage.
This is used in the StorageReader and StorageWriter which are accessible in Convex queries and mutations via QueryCtx and MutationCtx respectively.
Defined in
FileStorageId
Ƭ FileStorageId: GenericId
<"_storage"
> | StorageId
Defined in
FileMetadata
Ƭ FileMetadata: Object
Metadata for a single file as returned by storage.getMetadata.
Type declaration
Name | Type | Description |
---|---|---|
storageId | StorageId | ID for referencing the file (eg. via storage.getUrl) |
sha256 | string | Hex encoded sha256 checksum of file contents |
size | number | Size of the file in bytes |
contentType | string | null | ContentType of the file if it was provided on upload |
Defined in
WithoutSystemFields
Ƭ WithoutSystemFields<Document
>: Expand
<BetterOmit
<Document
, keyof SystemFields
| "_id"
>>
A Convex document with the system fields like _id
and _creationTime
omitted.
Type parameters
Name | Type |
---|---|
Document | extends GenericDocument |
Defined in
WithOptionalSystemFields
Ƭ WithOptionalSystemFields<Document
>: Expand
<WithoutSystemFields
<Document
> & Partial
<Pick
<Document
, keyof SystemFields
| "_id"
>>>
A Convex document with the system fields like _id
and _creationTime
optional.
Type parameters
Name | Type |
---|---|
Document | extends GenericDocument |
Defined in
VectorSearch
Ƭ VectorSearch<DataModel
, TableName
, IndexName
>: (tableName
: TableName
, indexName
: IndexName
, query
: VectorSearchQuery
<NamedTableInfo
<DataModel
, TableName
>, IndexName
>) => Promise
<{ _id
: GenericId
<TableName
> ; _score
: number
}[]>
Type parameters
Name | Type |
---|---|
DataModel | extends GenericDataModel |
TableName | extends TableNamesInDataModel <DataModel > |
IndexName | extends VectorIndexNames <NamedTableInfo <DataModel , TableName >> |
Type declaration
▸ (tableName
, indexName
, query
): Promise
<{ _id
: GenericId
<TableName
> ; _score
: number
}[]>
Parameters
Name | Type |
---|---|
tableName | TableName |
indexName | IndexName |
query | VectorSearchQuery <NamedTableInfo <DataModel , TableName >, IndexName > |
Returns
Promise
<{ _id
: GenericId
<TableName
> ; _score
: number
}[]>
Defined in
Variables
anyApi
• Const
anyApi: AnyApi
A utility for constructing FunctionReferences in projects that are not using code generation.
You can create a reference to a function like:
const reference = anyApi.myModule.myFunction;
This supports accessing any path regardless of what directories and modules are in your project. All function references are typed as AnyFunctionReference.
If you're using code generation, use api
from convex/_generated/api
instead. It will be more type-safe and produce better auto-complete
in your editor.
Defined in
paginationOptsValidator
• Const
paginationOptsValidator: ObjectValidator
<{ numItems
: Validator
<number
, false
, never
> ; cursor
: Validator
<null
| string
, false
, never
> ; endCursor
: Validator
<undefined
| null
| string
, true
, never
> ; id
: Validator
<undefined
| number
, true
, never
> ; maximumRowsRead
: Validator
<undefined
| number
, true
, never
> ; maximumBytesRead
: Validator
<undefined
| number
, true
, never
> }>
A Validator for PaginationOptions.
This includes the standard PaginationOptions properties along with
an optional cache-busting id
property used by usePaginatedQuery.
Defined in
ROUTABLE_HTTP_METHODS
• Const
ROUTABLE_HTTP_METHODS: readonly ["GET"
, "POST"
, "PUT"
, "DELETE"
, "OPTIONS"
, "PATCH"
]
A list of the methods supported by Convex HTTP actions.
HEAD is handled by Convex by running GET and stripping the body. CONNECT is not supported and will not be supported. TRACE is not supported and will not be supported.
Defined in
Functions
getFunctionName
▸ getFunctionName(functionReference
): string
Get the name of a function from a FunctionReference.
The name is a string like "myDir/myModule:myFunction". If the exported name
of the function is "default"
, the function name is omitted
(e.g. "myDir/myModule").
Parameters
Name | Type | Description |
---|---|---|
functionReference | AnyFunctionReference | A FunctionReference to get the name of. |
Returns
string
A string of the function's name.
Defined in
makeFunctionReference
▸ makeFunctionReference<type
, args
, ret
>(name
): FunctionReference
<type
, "public"
, args
, ret
>
FunctionReferences generally come from generated code, but in custom clients it may be useful to be able to build one manually.
Real function references are empty objects at runtime, but the same interface can be implemented with an object for tests and clients which don't use code generation.
Type parameters
Name | Type |
---|---|
type | extends FunctionType |
args | extends DefaultFunctionArgs = any |
ret | any |
Parameters
Name | Type | Description |
---|---|---|
name | string | The identifier of the function. E.g. path/to/file:functionName |
Returns
FunctionReference
<type
, "public"
, args
, ret
>
Defined in
filterApi
▸ filterApi<API
, Predicate
>(api
): FilterApi
<API
, Predicate
>
Given an api of type API and a FunctionReference subtype, return an api object containing only the function references that match.
const q = filterApi<typeof api, FunctionReference<"query">>(api)
Type parameters
Name |
---|
API |
Predicate |
Parameters
Name | Type |
---|---|
api | API |
Returns
FilterApi
<API
, Predicate
>
Defined in
cronJobs
▸ cronJobs(): Crons
Create a CronJobs object to schedule recurring tasks.
// convex/crons.js
import { cronJobs } from 'convex/server';
import { api } from "./_generated/api";
const crons = cronJobs();
crons.weekly(
"weekly re-engagement email",
{
hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)
minuteUTC: 30,
},
api.emails.send
)
export default crons;
Returns
Defined in
mutationGeneric
▸ mutationGeneric<Output
, ArgsValidator
>(func
): RegisteredMutation
<"public"
, Expand
<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>, Output
>
Define a mutation in this Convex app's public API.
This function will be allowed to modify your Convex database and will be accessible from the client.
If you're using code generation, use the mutation
function in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
ArgsValidator | extends PropertyValidators |
Parameters
Name | Type | Description |
---|---|---|
func | ValidatedFunction <GenericMutationCtx <any >, ArgsValidator , Output > | The mutation function. It receives a MutationCtx as its first argument. |
Returns
RegisteredMutation
<"public"
, Expand
<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>, Output
>
The wrapped mutation. Include this as an export
to name it and make it accessible.
Defined in
▸ mutationGeneric<Output
, Args
>(func
): RegisteredMutation
<"public"
, ArgsArrayToObject
<Args
>, Output
>
Define a mutation in this Convex app's public API.
This function will be allowed to modify your Convex database and will be accessible from the client.
If you're using code generation, use the mutation
function in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
Args | extends ArgsArray = OneArgArray <DefaultFunctionArgs > |
Parameters
Name | Type | Description |
---|---|---|
func | UnvalidatedFunction <GenericMutationCtx <any >, Args , Output > | The mutation function. It receives a MutationCtx as its first argument. |
Returns
RegisteredMutation
<"public"
, ArgsArrayToObject
<Args
>, Output
>
The wrapped mutation. Include this as an export
to name it and make it accessible.
Defined in
internalMutationGeneric
▸ internalMutationGeneric<Output
, ArgsValidator
>(func
): RegisteredMutation
<"internal"
, Expand
<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>, Output
>
Define a mutation that is only accessible from other Convex functions (but not from the client).
This function will be allowed to modify your Convex database. It will not be accessible from the client.
If you're using code generation, use the internalMutation
function in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
ArgsValidator | extends PropertyValidators |
Parameters
Name | Type | Description |
---|---|---|
func | ValidatedFunction <GenericMutationCtx <any >, ArgsValidator , Output > | The mutation function. It receives a MutationCtx as its first argument. |
Returns
RegisteredMutation
<"internal"
, Expand
<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>, Output
>
The wrapped mutation. Include this as an export
to name it and make it accessible.
Defined in
▸ internalMutationGeneric<Output
, Args
>(func
): RegisteredMutation
<"internal"
, ArgsArrayToObject
<Args
>, Output
>
Define a mutation that is only accessible from other Convex functions (but not from the client).
This function will be allowed to modify your Convex database. It will not be accessible from the client.
If you're using code generation, use the internalMutation
function in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
Args | extends ArgsArray = OneArgArray <DefaultFunctionArgs > |
Parameters
Name | Type | Description |
---|---|---|
func | UnvalidatedFunction <GenericMutationCtx <any >, Args , Output > | The mutation function. It receives a MutationCtx as its first argument. |
Returns
RegisteredMutation
<"internal"
, ArgsArrayToObject
<Args
>, Output
>
The wrapped mutation. Include this as an export
to name it and make it accessible.
Defined in
queryGeneric
▸ queryGeneric<Output
, ArgsValidator
>(func
): RegisteredQuery
<"public"
, Expand
<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>, Output
>
Define a query in this Convex app's public API.
This function will be allowed to read your Convex database and will be accessible from the client.
If you're using code generation, use the query
function in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
ArgsValidator | extends PropertyValidators |
Parameters
Name | Type | Description |
---|---|---|
func | ValidatedFunction <GenericQueryCtx <any >, ArgsValidator , Output > | The query function. It receives a QueryCtx as its first argument. |
Returns
RegisteredQuery
<"public"
, Expand
<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>, Output
>
The wrapped query. Include this as an export
to name it and make it accessible.
Defined in
▸ queryGeneric<Output
, Args
>(func
): RegisteredQuery
<"public"
, ArgsArrayToObject
<Args
>, Output
>
Define a query in this Convex app's public API.
This function will be allowed to read your Convex database and will be accessible from the client.
If you're using code generation, use the query
function in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
Args | extends ArgsArray = OneArgArray <DefaultFunctionArgs > |
Parameters
Name | Type | Description |
---|---|---|
func | UnvalidatedFunction <GenericQueryCtx <any >, Args , Output > | The query function. It receives a QueryCtx as its first argument. |
Returns
RegisteredQuery
<"public"
, ArgsArrayToObject
<Args
>, Output
>
The wrapped query. Include this as an export
to name it and make it accessible.
Defined in
internalQueryGeneric
▸ internalQueryGeneric<Output
, ArgsValidator
>(func
): RegisteredQuery
<"internal"
, Expand
<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>, Output
>
Define a query that is only accessible from other Convex functions (but not from the client).
This function will be allowed to read from your Convex database. It will not be accessible from the client.
If you're using code generation, use the internalQuery
function in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
ArgsValidator | extends PropertyValidators |
Parameters
Name | Type | Description |
---|---|---|
func | ValidatedFunction <GenericQueryCtx <any >, ArgsValidator , Output > | The query function. It receives a QueryCtx as its first argument. |
Returns
RegisteredQuery
<"internal"
, Expand
<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>, Output
>
The wrapped query. Include this as an export
to name it and make it accessible.
Defined in
▸ internalQueryGeneric<Output
, Args
>(func
): RegisteredQuery
<"internal"
, ArgsArrayToObject
<Args
>, Output
>
Define a query that is only accessible from other Convex functions (but not from the client).
This function will be allowed to read from your Convex database. It will not be accessible from the client.
If you're using code generation, use the internalQuery
function in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
Args | extends ArgsArray = OneArgArray <DefaultFunctionArgs > |
Parameters
Name | Type | Description |
---|---|---|
func | UnvalidatedFunction <GenericQueryCtx <any >, Args , Output > | The query function. It receives a QueryCtx as its first argument. |
Returns
RegisteredQuery
<"internal"
, ArgsArrayToObject
<Args
>, Output
>
The wrapped query. Include this as an export
to name it and make it accessible.
Defined in
actionGeneric
▸ actionGeneric<Output
, ArgsValidator
>(func
): RegisteredAction
<"public"
, Expand
<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>, Output
>
Define an action in this Convex app's public API.
If you're using code generation, use the action
function in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
ArgsValidator | extends PropertyValidators |
Parameters
Name | Type | Description |
---|---|---|
func | ValidatedFunction <GenericActionCtx <any >, ArgsValidator , Output > | The function. It receives a ActionCtx as its first argument. |
Returns
RegisteredAction
<"public"
, Expand
<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>, Output
>
The wrapped function. Include this as an export
to name it and make it accessible.
Defined in
▸ actionGeneric<Output
, Args
>(func
): RegisteredAction
<"public"
, ArgsArrayToObject
<Args
>, Output
>
Define an action in this Convex app's public API.
If you're using code generation, use the action
function in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
Args | extends ArgsArray = OneArgArray <DefaultFunctionArgs > |
Parameters
Name | Type | Description |
---|---|---|
func | UnvalidatedFunction <GenericActionCtx <any >, Args , Output > | The function. It receives a ActionCtx as its first argument. |
Returns
RegisteredAction
<"public"
, ArgsArrayToObject
<Args
>, Output
>
The wrapped function. Include this as an export
to name it and make it accessible.
Defined in
internalActionGeneric
▸ internalActionGeneric<Output
, ArgsValidator
>(func
): RegisteredAction
<"internal"
, Expand
<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>, Output
>
Define an action that is only accessible from other Convex functions (but not from the client).
If you're using code generation, use the internalAction
function in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
ArgsValidator | extends PropertyValidators |
Parameters
Name | Type | Description |
---|---|---|
func | ValidatedFunction <GenericActionCtx <any >, ArgsValidator , Output > | The function. It receives a ActionCtx as its first argument. |
Returns
RegisteredAction
<"internal"
, Expand
<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>, Output
>
The wrapped function. Include this as an export
to name it and make it accessible.
Defined in
▸ internalActionGeneric<Output
, Args
>(func
): RegisteredAction
<"internal"
, ArgsArrayToObject
<Args
>, Output
>
Define an action that is only accessible from other Convex functions (but not from the client).
If you're using code generation, use the internalAction
function in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
Output | Output |
Args | extends ArgsArray = OneArgArray <DefaultFunctionArgs > |
Parameters
Name | Type | Description |
---|---|---|
func | UnvalidatedFunction <GenericActionCtx <any >, Args , Output > | The function. It receives a ActionCtx as its first argument. |
Returns
RegisteredAction
<"internal"
, ArgsArrayToObject
<Args
>, Output
>
The wrapped function. Include this as an export
to name it and make it accessible.
Defined in
httpActionGeneric
▸ httpActionGeneric(func
): PublicHttpAction
Define a Convex HTTP action.
Parameters
Name | Type | Description |
---|---|---|
func | (ctx : ActionCtx <GenericDataModel >, request : Request ) => Promise <Response > | The function. It receives an ActionCtx as its first argument, and a Request object as its second. |
Returns
The wrapped function. Route a URL path to this function in convex/http.js
.
Defined in
server/impl/registration_impl.ts:409
httpRouter
▸ httpRouter(): HttpRouter
Return a new HttpRouter object.
Returns
Defined in
defineTable
▸ defineTable<DocumentSchema
>(documentSchema
): TableDefinition
<ExtractDocument
<DocumentSchema
>, ExtractFieldPaths
<DocumentSchema
>>
Define a table in a schema.
You can either specify the schema of your documents as an object like
defineTable({
field: v.string()
});
or as a schema type like
defineTable(
v.union(
v.object({...}),
v.object({...})
)
);
Type parameters
Name | Type |
---|---|
DocumentSchema | extends Validator <Record <string , any >, false , any , DocumentSchema > |
Parameters
Name | Type | Description |
---|---|---|
documentSchema | DocumentSchema | The type of documents stored in this table. |
Returns
TableDefinition
<ExtractDocument
<DocumentSchema
>, ExtractFieldPaths
<DocumentSchema
>>
A TableDefinition for the table.
Defined in
▸ defineTable<DocumentSchema
>(documentSchema
): TableDefinition
<ExtractDocument
<ObjectValidator
<DocumentSchema
>>, ExtractFieldPaths
<ObjectValidator
<DocumentSchema
>>>
Define a table in a schema.
You can either specify the schema of your documents as an object like
defineTable({
field: v.string()
});
or as a schema type like
defineTable(
v.union(
v.object({...}),
v.object({...})
)
);
Type parameters
Name | Type |
---|---|
DocumentSchema | extends Record <string , Validator <any , any , any >> |
Parameters
Name | Type | Description |
---|---|---|
documentSchema | DocumentSchema | The type of documents stored in this table. |
Returns
TableDefinition
<ExtractDocument
<ObjectValidator
<DocumentSchema
>>, ExtractFieldPaths
<ObjectValidator
<DocumentSchema
>>>
A TableDefinition for the table.
Defined in
defineSchema
▸ defineSchema<Schema
, StrictTableNameTypes
>(schema
, options?
): SchemaDefinition
<Schema
, StrictTableNameTypes
>
Define the schema of this Convex project.
This should be exported from a schema.ts
file in your convex/
directory
like:
export default defineSchema({
...
});
Type parameters
Name | Type |
---|---|
Schema | extends GenericSchema |
StrictTableNameTypes | extends boolean = true |
Parameters
Name | Type | Description |
---|---|---|
schema | Schema | A map from table name to TableDefinition for all of the tables in this project. |
options? | DefineSchemaOptions <StrictTableNameTypes > | Optional configuration. See DefineSchemaOptions for a full description. |
Returns
SchemaDefinition
<Schema
, StrictTableNameTypes
>
The schema.