import type { FunctionSpec, RuntimeAndFunctionType } from "@confect/core"; import type * as FunctionProvenance from "@confect/core/FunctionProvenance"; import * as MiddlewareSpec from "@confect/core/MiddlewareSpec"; import { type DefaultFunctionArgs, type FunctionVisibility, type GenericActionCtx, type GenericDataModel, type RegisteredAction, type RegisteredMutation, type RegisteredQuery } from "convex/server"; import type { Value } from "convex/values"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Schema from "effect/Schema"; import type * as EffectScheduler from "effect/Scheduler"; import * as ActionCtx from "./ActionCtx"; import * as ActionRunner from "./ActionRunner"; import * as Auth from "./Auth"; import type * as DatabaseSchema from "./DatabaseSchema"; import type * as DataModel from "./DataModel"; import * as ExecutionMetadata from "./ExecutionMetadata"; import * as RequestMetadata from "./RequestMetadata"; import * as MutationRunner from "./MutationRunner"; import * as QueryRunner from "./QueryRunner"; import type * as ResolvedMiddleware from "./ResolvedMiddleware"; import * as Scheduler from "./Scheduler"; import * as Storage from "./Storage"; import * as StorageActionWriter from "./StorageActionWriter"; import type * as StorageReader from "./StorageReader"; import * as StorageWriter from "./StorageWriter"; import * as VectorSearch from "./VectorSearch"; export type Any = RegisteredQuery | RegisteredMutation | RegisteredAction; type ConfectRegisteredFunction = FunctionSpec.EncodedArgs extends infer Args_ extends DefaultFunctionArgs ? RuntimeAndFunctionType.GetFunctionType extends "query" ? RegisteredQuery, Args_, Promise>> : RuntimeAndFunctionType.GetFunctionType extends "mutation" ? RegisteredMutation, Args_, Promise>> : RuntimeAndFunctionType.GetFunctionType extends "action" ? RegisteredAction, Args_, Promise>> : never : never; export type ConvexRegisteredFunction = FunctionSpec_ extends FunctionSpec.AnyWithProps ? FunctionSpec.GetFunctionProvenance extends FunctionProvenance.Convex ? RuntimeAndFunctionType.GetFunctionType extends "query" ? RegisteredQuery, Args_, Returns_> : RuntimeAndFunctionType.GetFunctionType extends "mutation" ? RegisteredMutation, Args_, Returns_> : RuntimeAndFunctionType.GetFunctionType extends "action" ? RegisteredAction, Args_, Returns_> : never : never : never; export type RegisteredFunction = FunctionSpec_ extends FunctionSpec.WithFunctionProvenance ? ConvexRegisteredFunction : FunctionSpec_ extends FunctionSpec.WithFunctionProvenance ? ConfectRegisteredFunction : never; /** * Wrap a function's handler effect in its resolved middleware chain, per * invocation, after args decode. Iterated innermost-first so that the * first-attached (group-level, in attachment order) middleware ends up * outermost and runs first. Erased types: the public safety story lives at the * `MiddlewareSpec.MiddlewareImpl`/`MiddlewareImpl.make` signatures, and the * composed effect's error channel is re-accounted by * {@link combineErrorSchemas}. */ export declare const applyMiddleware: (effect: Effect.Effect, resolvedMiddlewares: ReadonlyArray, invocation: MiddlewareSpec.MiddlewareOptions["invocation"]) => Effect.Effect; /** * The error-schema allowlist for a function with middleware: the function's own * declared `error` schema unioned with every covering middleware's error * schema. `undefined` (⇒ every failure dies) only when neither declares * one—mirroring the ref-side union clients decode against. */ export declare const combineErrorSchemas: (error: Schema.Codec | undefined, resolvedMiddlewares: ReadonlyArray) => Schema.Codec | undefined; /** * Run the `Effect` as a `Promise`. The error schema acts as an allowlist of * failures that may be surfaced to the client as a `ConvexError`: * * - With a schema: typed errors are schema-encoded and wrapped in a * `ConvexError`, then thrown so Convex surfaces the data to the client. * `Effect.either` escapes the failure channel before `runPromise` so the * thrown `ConvexError` retains its `Symbol.for("ConvexError")` identity * instead of being wrapped in Effect's `FiberFailure`. * - Without a schema: every failure is converted to a defect via `Effect.orDie`, * so nothing—not even a `ConvexError` the handler placed in its error * channel—reaches the client as a `ConvexError`. The fiber dies and * `runPromise` rejects with a generic failure. * * Either way, a `ConvexError` _defect_—thrown imperatively rather than placed * in the error channel, e.g. the pagination protocol's `InvalidCursor` signal * from `QueryStream.paginate`—is rethrown bare so it retains its identity and * Convex serializes its `data` to the client, matching how a thrown * `ConvexError` behaves in a plain Convex handler. * * A `scheduler` in `runOptions` must be passed here as a run option rather than * provided via `Effect.provideService` inside `effect`: the run option lands in * the fiber's root context, while a service provided within `effect` pops * before the `orDie`/`catch`/`result` wrappers this function adds. The fiber's * op counter survives context pops, so a cooperative yield can fire inside * those wrappers—only a root-context scheduler covers them. */ export declare const runHandlerPromise: (errorSchema: Schema.Codec | undefined, runOptions?: { readonly scheduler?: EffectScheduler.Scheduler | undefined; }) => (effect: Effect.Effect) => Promise; export declare const actionFunctionBase: ({ name, functionVisibility, args, returns, error, handler, resolvedMiddlewares, createLayer, }: { name: string; functionVisibility: FunctionVisibility; args: Schema.Codec; returns: Schema.Codec; error: Schema.Codec | undefined; handler: (a: Args) => Effect.Effect; resolvedMiddlewares?: ReadonlyArray; createLayer: (ctx: GenericActionCtx>>) => Layer.Layer; }) => { args: import("convex/values").PropertyValidators; returns: import("convex/values").Validator; handler: (ctx: GenericActionCtx>>, actualArgs: ConvexArgs) => Promise; }; export type ActionServices = Scheduler.Scheduler | Auth.Auth | ExecutionMetadata.ExecutionMetadata | RequestMetadata.RequestMetadata | Storage.Storage | StorageReader.StorageReader | StorageWriter.StorageWriter | StorageActionWriter.StorageActionWriter | QueryRunner.QueryRunner | MutationRunner.MutationRunner | ActionRunner.ActionRunner | VectorSearch.VectorSearch> | ActionCtx.ActionCtx>>; /** * The ctx-backed action services that don't depend on a Confect database * schema. {@link actionLayer} adds the schema-typed `VectorSearch` on top; the * HTTP API handler uses this base directly. */ export declare const baseActionLayer: (ctx: GenericActionCtx) => Layer.Layer | RequestMetadata.RequestMetadata | Storage.Storage | StorageActionWriter.StorageActionWriter | StorageReader.StorageReader | StorageWriter.StorageWriter | { runAction: (action: Action, ...args: import("@confect/core/Ref").OptionalArgs) => Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError>; } | { runMutation: { (mutation: Mutation, ...args: [...import("@confect/core/Ref").OptionalArgs, options?: undefined]): Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError>; (mutation: Mutation, args: import("@confect/core/Ref").Args, options: MutationRunner.Options | undefined): Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError, import("./MutationTransactionContext").MutationTransactionContext>; }; } | { runQuery: { (query: Query, ...args: [...import("@confect/core/Ref").OptionalArgs, options?: undefined]): Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError>; (query: Query, args: import("@confect/core/Ref").Args, options: (import("./QueryTransactionContext").Options & { readonly useStaleSnapshot?: never; }) | undefined): Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError, import("./QueryTransactionContext").QueryTransactionContext>; (query: Query, args: import("@confect/core/Ref").Args, options: QueryRunner.Options & { readonly useStaleSnapshot: boolean; }): Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError, import("./MutationTransactionContext").MutationTransactionContext>; (query: Query, args: import("@confect/core/Ref").Args, options: QueryRunner.Options | undefined): Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError, import("./QueryTransactionContext").QueryTransactionContext | import("./MutationTransactionContext").MutationTransactionContext>; }; } | { cancel: (id: import("convex/values").GenericId<"_scheduled_functions">) => Effect.Effect; runAfter: (delay: import("effect/Duration").Duration, ref: Ref_, ...args: import("@confect/core/Ref").OptionalArgs) => Effect.Effect, never, never>; runAt: (dateTime: import("effect/DateTime").DateTime, ref: Ref_, ...args: import("@confect/core/Ref").OptionalArgs) => Effect.Effect, never, never>; }, never, never>; export declare const actionLayer: (databaseSchema: DatabaseSchema_, ctx: GenericActionCtx>>) => Layer.Layer>> | RequestMetadata.RequestMetadata | Storage.Storage | StorageActionWriter.StorageActionWriter | StorageReader.StorageReader | StorageWriter.StorageWriter | VectorSearch.VectorSearchService> | { runAction: (action: Action, ...args: import("@confect/core/Ref").OptionalArgs) => Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError>; } | { runMutation: { (mutation: Mutation, ...args: [...import("@confect/core/Ref").OptionalArgs, options?: undefined]): Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError>; (mutation: Mutation, args: import("@confect/core/Ref").Args, options: MutationRunner.Options | undefined): Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError, import("./MutationTransactionContext").MutationTransactionContext>; }; } | { runQuery: { (query: Query, ...args: [...import("@confect/core/Ref").OptionalArgs, options?: undefined]): Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError>; (query: Query, args: import("@confect/core/Ref").Args, options: (import("./QueryTransactionContext").Options & { readonly useStaleSnapshot?: never; }) | undefined): Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError, import("./QueryTransactionContext").QueryTransactionContext>; (query: Query, args: import("@confect/core/Ref").Args, options: QueryRunner.Options & { readonly useStaleSnapshot: boolean; }): Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError, import("./MutationTransactionContext").MutationTransactionContext>; (query: Query, args: import("@confect/core/Ref").Args, options: QueryRunner.Options | undefined): Effect.Effect, import("@confect/core/Ref").Error | Schema.SchemaError, import("./QueryTransactionContext").QueryTransactionContext | import("./MutationTransactionContext").MutationTransactionContext>; }; } | { cancel: (id: import("convex/values").GenericId<"_scheduled_functions">) => Effect.Effect; runAfter: (delay: import("effect/Duration").Duration, ref: Ref_, ...args: import("@confect/core/Ref").OptionalArgs) => Effect.Effect, never, never>; runAt: (dateTime: import("effect/DateTime").DateTime, ref: Ref_, ...args: import("@confect/core/Ref").OptionalArgs) => Effect.Effect, never, never>; }, never, never>; export {}; //# sourceMappingURL=RegisteredFunction.d.ts.map