Normally when using the Effect schema library, it's recommended to set exactOptionalPropertyTypes in your tsconfig.json to true. However, this configuration is not supported by convex-js at the moment, so to use Confect, you must set it to false instead.
To understand the implications of this, see in the Effect docs.
Usage
1. Define your database schema
Not every Effect Schema is valid for use in Confect. See Schema restrictions for more information about what's permitted and what's not.
2. Generate your Convex function constructors and types.
3. Write some Convex functions!
Example project
The above files are pulled from a real example project. Check it out .
import {
ConfectActionCtx as ConfectActionCtxService,
type ConfectActionCtx as ConfectActionCtxType,
type ConfectDataModelFromConfectSchemaDefinition,
type ConfectDoc as ConfectDocType,
ConfectMutationCtx as ConfectMutationCtxService,
type ConfectMutationCtx as ConfectMutationCtxType,
ConfectQueryCtx as ConfectQueryCtxService,
type ConfectQueryCtx as ConfectQueryCtxType,
type TableNamesInConfectDataModel,
makeFunctions,
} from "@rjdellecese/confect/server";
import { confectSchema } from "./schema";
export const {
action,
internalAction,
internalMutation,
internalQuery,
mutation,
query,
} = makeFunctions(confectSchema);
type ConfectSchema = typeof confectSchema;
type ConfectDataModel =
ConfectDataModelFromConfectSchemaDefinition<ConfectSchema>;
export type ConfectDoc<
TableName extends TableNamesInConfectDataModel<ConfectDataModel>,
> = ConfectDocType<ConfectDataModel, TableName>;
export const ConfectQueryCtx = ConfectQueryCtxService<ConfectDataModel>();
export type ConfectQueryCtx = ConfectQueryCtxType<ConfectDataModel>;
export const ConfectMutationCtx = ConfectMutationCtxService<ConfectDataModel>();
export type ConfectMutationCtx = ConfectMutationCtxType<ConfectDataModel>;
export const ConfectActionCtx = ConfectActionCtxService<ConfectDataModel>();
export type ConfectActionCtx = ConfectActionCtxType<ConfectDataModel>;