import type { FunctionReference as ConvexFunctionReference, FunctionVisibility } from "convex/server"; import type { Value } from "convex/values"; import { ConvexError } from "convex/values"; import type { ParseResult } from "effect"; import * as Effect from "effect/Effect"; import * as Option from "effect/Option"; import type * as FunctionSpec from "./FunctionSpec"; import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType"; export interface Ref<_RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType, _FunctionVisibility extends FunctionVisibility, _Args, _Returns, _Error = never> { readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType; readonly _FunctionVisibility?: _FunctionVisibility; readonly _Args?: _Args; readonly _Returns?: _Returns; readonly _Error?: _Error; } export interface Any extends Ref { } export interface AnyInternal extends Ref { } export interface AnyPublic extends Ref { } export interface AnyQuery extends Ref { } export interface AnyMutation extends Ref { } export interface AnyAction extends Ref { } export interface AnyPublicQuery extends Ref { } export interface AnyPublicMutation extends Ref { } export interface AnyPublicAction extends Ref { } export type GetRuntimeAndFunctionType = Ref_ extends Ref ? RuntimeAndFunctionType_ : never; export type GetRuntime = Ref_ extends Ref ? RuntimeAndFunctionType.GetRuntime : never; export type GetFunctionType = Ref_ extends Ref ? RuntimeAndFunctionType.GetFunctionType : never; export type GetFunctionVisibility = Ref_ extends Ref ? FunctionVisibility_ : never; export type Args = Ref_ extends Ref ? Args_ : never; export type OptionalArgs = keyof Args extends never ? [args?: Args] : [args: Args]; export type Returns = Ref_ extends Ref ? Returns_ : never; export type Error = Ref_ extends Ref ? Error_ : never; export type FunctionReference = ConvexFunctionReference, GetFunctionVisibility>; export type FromFunctionSpec = Ref, FunctionSpec.GetFunctionVisibility, FunctionSpec.Args, FunctionSpec.Returns, FunctionSpec.Error>; export declare const make: ( /** * The namespace portion of a Convex function name, i.e. the part before the * colon. For example, for `myGroupDir/myGroupMod:myFunc` this would be * `myGroupDir/myGroupMod`. */ functionNamespace: string, functionSpec: FunctionSpec_) => FromFunctionSpec; export declare const getConvexFunctionName: (ref: Any) => string; export declare const getFunctionReference: (ref: Ref_) => FunctionReference; export declare const hasErrorSchema: (ref: Any) => boolean; export declare const encodeArgs: (ref: Ref_, args: Args) => Effect.Effect; export declare const decodeReturns: (ref: Ref_, returns: unknown) => Effect.Effect, ParseResult.ParseError>; export declare const encodeArgsSync: (ref: Ref_, args: Args) => unknown; export declare const decodeArgsSync: (ref: Ref_, encodedArgs: unknown) => Args; export declare const encodeReturnsSync: (ref: Ref_, returns: Returns) => unknown; export declare const decodeReturnsSync: (ref: Ref_, encodedReturns: unknown) => Returns; export declare const isConvexError: (error: unknown) => error is ConvexError; /** * Build a callback-style handler that decodes the ref's typed error from a * caught `ConvexError`, or else forwards the value to `mapUnknownError`. The * fallback is also invoked when the input *is* a `ConvexError` but the ref * doesn't declare a typed-error schema—by definition such a value falls * outside the ref's error contract. Useful when adapting non-Effect APIs (e.g. * emitter callbacks for streamed subscriptions) to the same error semantics * that `runWithCodec` provides. */ export declare const decodeErrorOrElse: (ref: Ref_, mapUnknownError: (error: unknown) => E) => (error: unknown) => Error | E; /** * Decode `encodedError` against the ref's error schema. Returns `None` if the * ref doesn't declare a typed error (Confect ref without an `error` schema, or * a Convex-provenance ref)—by definition there's nothing to decode the value * into, and the caller is responsible for deciding what to do (typically: * surface the original value as a defect). */ export declare const decodeError: (ref: Ref_, encodedError: unknown) => Effect.Effect>, ParseResult.ParseError>; /** * Synchronous counterpart to `decodeError`. Throws on schema decode failure; * returns `None` when the ref doesn't declare a typed error. */ export declare const decodeErrorSync: (ref: Ref_, encodedError: unknown) => Option.Option>; export declare const maybeDecodeErrorSync: (ref: Ref_, error: unknown) => unknown; /** * Encode args via the ref's args schema, invoke `call`, decode returns via the * ref's returns schema, and translate any thrown `ConvexError` into the ref's * typed error. Anything else the Promise rejects with—network failures, * server-side runtime errors, validation failures, etc.—is passed to * `mapUnknownError` to be turned into a typed `E`, or surfaced as a defect when * no handler is provided. */ export declare const runWithCodec: (ref: Ref_, args: Args, call: (functionReference: FunctionReference, encodedArgs: unknown) => PromiseLike, mapUnknownError?: (error: unknown) => E) => Effect.Effect, E | Error | ParseResult.ParseError>; //# sourceMappingURL=Ref.d.ts.map