Skip to main content

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 DatabaseReader 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 DatabaseWriter interface.

import { mutation } from "./_generated/server";

export default mutation(async ({ db }, { arg1, arg2 }) => {
// Your mutation code here!
});

Classes

Interfaces

Type Aliases

CronJobsForAPI

Ƭ CronJobsForAPI<API>: () => Crons<API>

Type parameters

NameType
APIextends GenericAPI

Type declaration

▸ (): Crons<API>

Returns

Crons<API>

Defined in

server/cron.ts:203


GenericDocument

Ƭ GenericDocument: Record<string, Value>

A document stored in Convex.

Defined in

server/data_model.ts:9


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

server/data_model.ts:18


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

server/data_model.ts:29


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

server/data_model.ts:37


GenericSearchIndexConfig

Ƭ GenericSearchIndexConfig: Object

A type describing the configuration of a search index.

Type declaration

NameType
searchFieldstring
filterFieldsstring

Defined in

server/data_model.ts:43


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

server/data_model.ts:54


FieldTypeFromFieldPath

Ƭ FieldTypeFromFieldPath<Document, FieldPath>: FieldPath extends `${infer First}.${infer Second}` ? First extends keyof Document ? Document[First] extends GenericDocument ? FieldTypeFromFieldPath<Document[First], Second> : undefined : undefined : FieldPath extends keyof Document ? 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

NameType
Documentextends GenericDocument
FieldPathextends string

Defined in

server/data_model.ts:69


GenericTableInfo

Ƭ GenericTableInfo: Object

A type describing the document type and indexes in a table.

Type declaration

NameType
documentGenericDocument
fieldPathsGenericFieldPaths
indexesGenericTableIndexes
searchIndexesGenericTableSearchIndexes

Defined in

server/data_model.ts:90


DocumentByInfo

Ƭ DocumentByInfo<TableInfo>: TableInfo["document"]

The type of a document in a table for a given GenericTableInfo.

Type parameters

NameType
TableInfoextends GenericTableInfo

Defined in

server/data_model.ts:101


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

NameType
TableInfoextends GenericTableInfo

Defined in

server/data_model.ts:111


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

NameType
TableInfoextends GenericTableInfo

Defined in

server/data_model.ts:120


IndexNames

Ƭ IndexNames<TableInfo>: keyof Indexes<TableInfo>

The names of indexes in a table for a given GenericTableInfo.

Type parameters

NameType
TableInfoextends GenericTableInfo

Defined in

server/data_model.ts:126


NamedIndex

Ƭ NamedIndex<TableInfo, IndexName>: Indexes<TableInfo>[IndexName]

Extract the fields of an index from a GenericTableInfo by name.

Type parameters

NameType
TableInfoextends GenericTableInfo
IndexNameextends IndexNames<TableInfo>

Defined in

server/data_model.ts:133


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

NameType
TableInfoextends GenericTableInfo

Defined in

server/data_model.ts:144


SearchIndexNames

Ƭ SearchIndexNames<TableInfo>: keyof SearchIndexes<TableInfo>

The names of search indexes in a table for a given GenericTableInfo.

Type parameters

NameType
TableInfoextends GenericTableInfo

Defined in

server/data_model.ts:151


NamedSearchIndex

Ƭ NamedSearchIndex<TableInfo, IndexName>: SearchIndexes<TableInfo>[IndexName]

Extract the fields of an index from a GenericTableInfo by name.

Type parameters

NameType
TableInfoextends GenericTableInfo
IndexNameextends SearchIndexNames<TableInfo>

Defined in

server/data_model.ts:158


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

server/data_model.ts:171


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

Defined in

server/data_model.ts:180


TableNamesInDataModel

Ƭ TableNamesInDataModel<DataModel>: keyof DataModel & string

A type of all of the table names defined in a GenericDataModel.

Type parameters

NameType
DataModelextends GenericDataModel

Defined in

server/data_model.ts:195


NamedTableInfo

Ƭ NamedTableInfo<DataModel, TableName>: DataModel[TableName]

Extract the TableInfo for a table in a GenericDataModel by table name.

Type parameters

NameType
DataModelextends GenericDataModel
TableNameextends keyof DataModel

Defined in

server/data_model.ts:204


DocumentByName

Ƭ DocumentByName<DataModel, TableName>: DataModel[TableName]["document"]

The type of a document in a GenericDataModel by table name.

Type parameters

NameType
DataModelextends GenericDataModel
TableNameextends TableNamesInDataModel<DataModel>

Defined in

server/data_model.ts:213


ExpressionOrValue

Ƭ ExpressionOrValue<T>: Expression<T> | T

An Expression or a constant Value

Type parameters

NameType
Textends Value | undefined

Defined in

server/filter_builder.ts:38


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

server/pagination.ts:19


FunctionArgs

Ƭ FunctionArgs: Record<string, unknown>

The arguments to a Convex query, mutation, or action function.

Convex functions always take an arguments object that maps the argument names to their values.

Defined in

server/registration.ts:158


ArgsArray

Ƭ ArgsArray: OneArgArray | NoArgsArray

An array of arguments to a Convex function.

Convex functions can take either a single FunctionArgs object or no args at all.

Defined in

server/registration.ts:180


RegisteredMutation

Ƭ RegisteredMutation<Visibility, Args, Output>: (ctx: MutationCtx<any, 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

NameType
Visibilityextends FunctionVisibility
Argsextends ArgsArray
OutputOutput

Defined in

server/registration.ts:208


RegisteredQuery

Ƭ RegisteredQuery<Visibility, Args, Output>: (ctx: QueryCtx<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

NameType
Visibilityextends FunctionVisibility
Argsextends ArgsArray
OutputOutput

Defined in

server/registration.ts:236


RegisteredAction

Ƭ RegisteredAction<Visibility, Args, Output>: (ctx: ActionCtx<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

NameType
Visibilityextends FunctionVisibility
Argsextends ArgsArray
OutputOutput

Defined in

server/registration.ts:264


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
NameType
ctxActionCtx<any>
requestRequest
Returns

Response

Type declaration

NameType
isHttptrue
isRegistered?true

Defined in

server/registration.ts:292


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

NameType
CtxCtx
Argsextends ArgsArray
OutputOutput

Defined in

server/registration.ts:327


MutationBuilder

Ƭ MutationBuilder<DataModel, API, Visibility>: <Output, ArgsValidator>(func: ValidatedFunction<MutationCtx<DataModel, API>, ArgsValidator, Output>) => RegisteredMutation<Visibility, [Expand<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>], Output><Output, Args>(func: UnvalidatedFunction<MutationCtx<DataModel, API>, Args, Output>) => RegisteredMutation<Visibility, Args, Output>

Type parameters

NameType
DataModelextends GenericDataModel
APIextends GenericAPI
Visibilityextends FunctionVisibility

Type declaration

▸ <Output, ArgsValidator>(func): RegisteredMutation<Visibility, [Expand<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>], Output>

Internal type helper used by Convex code generation.

Used to give mutationGeneric a type specific to your data model.

Type parameters
NameType
OutputOutput
ArgsValidatorextends PropertyValidators
Parameters
NameType
funcValidatedFunction<MutationCtx<DataModel, API>, ArgsValidator, Output>
Returns

RegisteredMutation<Visibility, [Expand<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>], Output>

▸ <Output, Args>(func): RegisteredMutation<Visibility, Args, Output>

Internal type helper used by Convex code generation.

Used to give mutationGeneric a type specific to your data model.

Type parameters
NameType
OutputOutput
Argsextends ArgsArray = OneArgArray
Parameters
NameType
funcUnvalidatedFunction<MutationCtx<DataModel, API>, Args, Output>
Returns

RegisteredMutation<Visibility, Args, Output>

Defined in

server/registration.ts:403


QueryBuilder

Ƭ QueryBuilder<DataModel, Visibility>: <Output, ArgsValidator>(func: ValidatedFunction<QueryCtx<DataModel>, ArgsValidator, Output>) => RegisteredQuery<Visibility, [Expand<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>], Output><Output, Args>(func: UnvalidatedFunction<QueryCtx<DataModel>, Args, Output>) => RegisteredQuery<Visibility, Args, Output>

Type parameters

NameType
DataModelextends GenericDataModel
Visibilityextends FunctionVisibility

Type declaration

▸ <Output, ArgsValidator>(func): RegisteredQuery<Visibility, [Expand<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>], Output>

Internal type helper used by Convex code generation.

Used to give queryGeneric a type specific to your data model.

Type parameters
NameType
OutputOutput
ArgsValidatorextends PropertyValidators
Parameters
NameType
funcValidatedFunction<QueryCtx<DataModel>, ArgsValidator, Output>
Returns

RegisteredQuery<Visibility, [Expand<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>], Output>

▸ <Output, Args>(func): RegisteredQuery<Visibility, Args, Output>

Internal type helper used by Convex code generation.

Used to give queryGeneric a type specific to your data model.

Type parameters
NameType
OutputOutput
Argsextends ArgsArray = OneArgArray
Parameters
NameType
funcUnvalidatedFunction<QueryCtx<DataModel>, Args, Output>
Returns

RegisteredQuery<Visibility, Args, Output>

Defined in

server/registration.ts:423


ActionBuilder

Ƭ ActionBuilder<API, Visibility>: <Output, ArgsValidator>(func: ValidatedFunction<ActionCtx<API>, ArgsValidator, Output>) => RegisteredAction<Visibility, [Expand<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>], Output><Output, Args>(func: UnvalidatedFunction<ActionCtx<API>, Args, Output>) => RegisteredAction<Visibility, Args, Output>

Type parameters

NameType
APIextends GenericAPI
Visibilityextends FunctionVisibility

Type declaration

▸ <Output, ArgsValidator>(func): RegisteredAction<Visibility, [Expand<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>], Output>

Internal type helper used by Convex code generation.

Used to give actionGeneric a type specific to your data model.

Type parameters
NameType
OutputOutput
ArgsValidatorextends PropertyValidators
Parameters
NameType
funcValidatedFunction<ActionCtx<API>, ArgsValidator, Output>
Returns

RegisteredAction<Visibility, [Expand<{ [Property in string | number | symbol]?: ArgsValidator[Property]["type"] } & { [Property in string | number | symbol]: ArgsValidator[Property]["type"] }>], Output>

▸ <Output, Args>(func): RegisteredAction<Visibility, Args, Output>

Internal type helper used by Convex code generation.

Used to give actionGeneric a type specific to your data model.

Type parameters
NameType
OutputOutput
Argsextends ArgsArray = OneArgArray
Parameters
NameType
funcUnvalidatedFunction<ActionCtx<API>, Args, Output>
Returns

RegisteredAction<Visibility, Args, Output>

Defined in

server/registration.ts:442


HttpActionBuilderForAPI

Ƭ HttpActionBuilderForAPI<API>: (func: (ctx: ActionCtx<API>, request: Request) => Promise<Response>) => PublicHttpAction

Type parameters

NameType
APIextends GenericAPI

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
NameType
func(ctx: ActionCtx<API>, request: Request) => Promise<Response>
Returns

PublicHttpAction

Defined in

server/registration.ts:462


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

server/router.ts:31


SchedulableFunctionNames

Ƭ SchedulableFunctionNames<API>: ActionNames<API> | MutationNames<API>

The names of all of the schedulable in a Convex API.

These are all of the mutations and actions.

Type parameters

NameType
APIextends GenericAPI

Defined in

server/scheduler.ts:17


NamedSchedulableFunction

Ƭ NamedSchedulableFunction<API, Name>: Name extends ActionNames<API> ? NamedAction<API, Name> : NamedMutation<API, Name>

The type of a schedulable function in a Convex API.

Type parameters

NameType
APIextends GenericAPI
Nameextends SchedulableFunctionNames<API>

Defined in

server/scheduler.ts:26


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

server/storage.ts:9


FileMetadata

Ƭ FileMetadata: Object

Metadata for a single file as returned by storage.getMetadata.

Type declaration

NameTypeDescription
storageIdStorageIdID for referencing the file (eg. via storage.getUrl)
sha256stringHex encoded sha256 checksum of file contents
sizenumberSize of the file in bytes
contentTypestring | nullContentType of the file if it was provided on upload

Defined in

server/storage.ts:16


WithoutSystemFields

Ƭ WithoutSystemFields<Document>: Expand<BetterOmit<Document, keyof SystemFields | "_id">>

A Convex document with the system fields like _id and _creationTime omitted.

Type parameters

NameType
Documentextends GenericDocument

Defined in

server/system_fields.ts:28

Variables

paginationOptsValidator

Const paginationOptsValidator: ObjectValidator<{ numItems: Validator<number, false, never> ; cursor: Validator<null | string, false, never> ; id: Validator<undefined | number, true, never> }>

A Validator for PaginationOptions.

This includes the standard numItems and cursor properties along with an optional cache-busting id property used by usePaginatedQueryGeneric.

Defined in

server/pagination.ts:109


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

server/router.ts:14

Functions

cronJobsGeneric

cronJobsGeneric<API>(): Crons<API>

Internal type helper used by Convex code generation.

If you're using code generation, use the cronJobs function in convex/_generated/server.js which is typed for your API.

// convex/crons.js
import { cronJobs } from 'convex/server';

const crons = cronJobs();
crons.weekly(
"weekly re-engagement email",
{
hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)
minuteUTC: 30,
},
"sendEmails"
)
export default crons;

Type parameters

NameType
APIextends GenericAPI

Returns

Crons<API>

Defined in

server/cron.ts:191


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

NameType
OutputOutput
ArgsValidatorextends PropertyValidators

Parameters

NameTypeDescription
funcValidatedFunction<MutationCtx<any, 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

server/registration.ts:408

mutationGeneric<Output, Args>(func): RegisteredMutation<"public", 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

NameType
OutputOutput
Argsextends ArgsArray = OneArgArray

Parameters

NameTypeDescription
funcUnvalidatedFunction<MutationCtx<any, any>, Args, Output>The mutation function. It receives a MutationCtx as its first argument.

Returns

RegisteredMutation<"public", Args, Output>

The wrapped mutation. Include this as an export to name it and make it accessible.

Defined in

server/registration.ts:412


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

NameType
OutputOutput
ArgsValidatorextends PropertyValidators

Parameters

NameTypeDescription
funcValidatedFunction<MutationCtx<any, 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

server/registration.ts:408

internalMutationGeneric<Output, Args>(func): RegisteredMutation<"internal", 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

NameType
OutputOutput
Argsextends ArgsArray = OneArgArray

Parameters

NameTypeDescription
funcUnvalidatedFunction<MutationCtx<any, any>, Args, Output>The mutation function. It receives a MutationCtx as its first argument.

Returns

RegisteredMutation<"internal", Args, Output>

The wrapped mutation. Include this as an export to name it and make it accessible.

Defined in

server/registration.ts:412


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

NameType
OutputOutput
ArgsValidatorextends PropertyValidators

Parameters

NameTypeDescription
funcValidatedFunction<QueryCtx<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

server/registration.ts:427

queryGeneric<Output, Args>(func): RegisteredQuery<"public", 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

NameType
OutputOutput
Argsextends ArgsArray = OneArgArray

Parameters

NameTypeDescription
funcUnvalidatedFunction<QueryCtx<any>, Args, Output>The query function. It receives a QueryCtx as its first argument.

Returns

RegisteredQuery<"public", Args, Output>

The wrapped query. Include this as an export to name it and make it accessible.

Defined in

server/registration.ts:431


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

NameType
OutputOutput
ArgsValidatorextends PropertyValidators

Parameters

NameTypeDescription
funcValidatedFunction<QueryCtx<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

server/registration.ts:427

internalQueryGeneric<Output, Args>(func): RegisteredQuery<"internal", 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

NameType
OutputOutput
Argsextends ArgsArray = OneArgArray

Parameters

NameTypeDescription
funcUnvalidatedFunction<QueryCtx<any>, Args, Output>The query function. It receives a QueryCtx as its first argument.

Returns

RegisteredQuery<"internal", Args, Output>

The wrapped query. Include this as an export to name it and make it accessible.

Defined in

server/registration.ts:431


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

NameType
OutputOutput
ArgsValidatorextends PropertyValidators

Parameters

NameTypeDescription
funcValidatedFunction<ActionCtx<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

server/registration.ts:446

actionGeneric<Output, Args>(func): RegisteredAction<"public", 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

NameType
OutputOutput
Argsextends ArgsArray = OneArgArray

Parameters

NameTypeDescription
funcUnvalidatedFunction<ActionCtx<any>, Args, Output>The function. It receives a ActionCtx as its first argument.

Returns

RegisteredAction<"public", Args, Output>

The wrapped function. Include this as an export to name it and make it accessible.

Defined in

server/registration.ts:450


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

NameType
OutputOutput
ArgsValidatorextends PropertyValidators

Parameters

NameTypeDescription
funcValidatedFunction<ActionCtx<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

server/registration.ts:446

internalActionGeneric<Output, Args>(func): RegisteredAction<"internal", 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

NameType
OutputOutput
Argsextends ArgsArray = OneArgArray

Parameters

NameTypeDescription
funcUnvalidatedFunction<ActionCtx<any>, Args, Output>The function. It receives a ActionCtx as its first argument.

Returns

RegisteredAction<"internal", Args, Output>

The wrapped function. Include this as an export to name it and make it accessible.

Defined in

server/registration.ts:450


httpActionGeneric

httpActionGeneric<API>(func): PublicHttpAction

Define a Convex HTTP action.

Type parameters

NameType
APIextends GenericAPI

Parameters

NameTypeDescription
func(ctx: ActionCtx<API>, request: Request) => Promise<Response>The function. It receives an ActionCtx as its first argument, and a Request object as its second.

Returns

PublicHttpAction

The wrapped function. Route a URL path to this function in convex/http.js.

Defined in

server/impl/registration_impl.ts:345


httpRouter

httpRouter(): HttpRouter

Return a new HttpRouter object.

Returns

HttpRouter

Defined in

server/router.ts:47