import { n as DeepPartial, o as Simplify, r as DistributiveOmit } from "../types-BTb_4BaU.js"; import { C as HttpProcedure, G as DataTransformerOptions, V as UnsetMarker, d as CRPCHttpRouter, p as HttpRouterRecord } from "../http-types-BK7FuIcR.js"; import { A as HttpInputArgs, C as ReservedMutationOptions$1, S as ReservedInfiniteQueryOptions, T as StaticQueryOptsParam, _ as IsPaginated, b as PaginatedFnMeta, c as ConvexMutationKey, d as ConvexQueryMeta, f as EmptyObject, g as InfiniteQueryInput, l as ConvexQueryHookOptions, m as FUNC_REF_SYMBOL, o as ConvexActionKey, p as ExtractPaginatedItem, s as ConvexInfiniteQueryMeta, u as ConvexQueryKey, w as ReservedQueryOptions$1, y as MutationVariables } from "../types-7bF_8IjP.js"; import { FunctionArgs, FunctionReference, FunctionReturnType } from "convex/server"; import { z } from "zod"; import { DefaultError, QueryFilters, SkipToken, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query"; //#region src/react/crpc-types.d.ts /** Options returned by `convexQuery` factory */ type ConvexQueryOptions> = Pick, Error, FunctionReturnType, ConvexQueryKey>, 'queryKey' | 'staleTime' | 'enabled'>; /** Options returned by `convexAction` factory */ type ConvexActionOptions> = Pick, Error, FunctionReturnType, ConvexActionKey>, 'queryKey' | 'staleTime' | 'enabled'>; /** Query options parameter type */ type QueryOptsParam> = Simplify, DefaultError>, ReservedQueryOptions$1>>; /** Query options return type */ type QueryOptsReturn> = ConvexQueryOptions & { meta: ConvexQueryMeta; }; /** Action query options parameter type (actions don't support subscriptions) */ type ActionQueryOptsParam> = DistributiveOmit, DefaultError>, ReservedQueryOptions$1>; /** Action query options return type */ type ActionQueryOptsReturn> = ConvexActionOptions; /** * Decorated query procedure with queryOptions, queryKey, and queryFilter methods. * Args are optional when the function has no required parameters. * Supports skipToken for type-safe conditional queries. */ type DecorateQuery> = { queryOptions: keyof FunctionArgs extends never ? (args?: EmptyObject | SkipToken, opts?: QueryOptsParam) => QueryOptsReturn : EmptyObject extends FunctionArgs ? (args?: FunctionArgs | SkipToken, opts?: QueryOptsParam) => QueryOptsReturn : (args: FunctionArgs | SkipToken, opts?: QueryOptsParam) => QueryOptsReturn; /** Static (non-hook) query options for event handlers and prefetching */ staticQueryOptions: keyof FunctionArgs extends never ? (args?: EmptyObject | SkipToken, opts?: StaticQueryOptsParam) => ConvexQueryOptions & { meta: ConvexQueryMeta; } : EmptyObject extends FunctionArgs ? (args?: FunctionArgs | SkipToken, opts?: StaticQueryOptsParam) => ConvexQueryOptions & { meta: ConvexQueryMeta; } : (args: FunctionArgs | SkipToken, opts?: StaticQueryOptsParam) => ConvexQueryOptions & { meta: ConvexQueryMeta; }; /** Get query key for QueryClient methods (setQueryData, getQueryData, etc.) */ queryKey: (args?: DeepPartial>) => ConvexQueryKey; /** Get query filter for QueryClient methods (invalidateQueries, removeQueries, etc.) */ queryFilter: (args?: DeepPartial>, filters?: DistributiveOmit) => QueryFilters; }; /** Options for infinite query - extends TanStack Query options */ type InfiniteQueryOptsParam = FunctionReference<'query'>> = { /** Items per page. Optional - server uses .paginated() default if not provided. */limit?: number; /** Skip query silently when unauthenticated */ skipUnauth?: boolean; /** Placeholder data shown while loading (item array, not pagination result) */ placeholderData?: ExtractPaginatedItem>[]; } & DistributiveOmit, DefaultError>, ReservedInfiniteQueryOptions>; /** Return type of infiniteQueryOptions - compatible with TanStack prefetch */ type ConvexInfiniteQueryOptions> = Pick, Error, FunctionReturnType, ConvexQueryKey>, 'queryKey' | 'staleTime' | 'enabled'> & { meta: ConvexInfiniteQueryMeta; refetchInterval: false; refetchOnMount: false; refetchOnReconnect: false; refetchOnWindowFocus: false; /** Placeholder data shown while loading (item array, not pagination result) */ placeholderData?: ExtractPaginatedItem>[]; } & DistributiveOmit, DefaultError>, ReservedInfiniteQueryOptions>; /** Infinite query options with attached function reference (client-only) */ type ConvexInfiniteQueryOptionsWithRef> = ConvexInfiniteQueryOptions & { [FUNC_REF_SYMBOL]: T; }; /** Infinite query options return type */ type InfiniteQueryOptsReturn> = ConvexInfiniteQueryOptionsWithRef; /** * Decorated infinite query procedure. * Only available on queries that have cursor/limit in their input (paginated). * Supports skipToken for conditional queries. * Args are optional when the function has no required parameters (besides cursor/limit). */ type DecorateInfiniteQuery> = { /** Create infinite query options for useInfiniteQuery and prefetch */infiniteQueryOptions: keyof InfiniteQueryInput> extends never ? (args?: EmptyObject | SkipToken, opts?: InfiniteQueryOptsParam) => InfiniteQueryOptsReturn : EmptyObject extends InfiniteQueryInput> ? (args?: InfiniteQueryInput> | SkipToken, opts?: InfiniteQueryOptsParam) => InfiniteQueryOptsReturn : (args: InfiniteQueryInput> | SkipToken, opts?: InfiniteQueryOptsParam) => InfiniteQueryOptsReturn; /** Get query key for infinite query (QueryClient methods like setQueryData, getQueryData) */ infiniteQueryKey: (args?: DeepPartial>>) => ConvexQueryKey; /** Function metadata from server (auth, limit, rateLimit, role, type) */ meta: PaginatedFnMeta; }; /** * Decorated mutation procedure with mutationOptions and mutationKey methods. */ type DecorateMutation> = { mutationOptions: (opts?: DistributiveOmit, DefaultError, MutationVariables>, ReservedMutationOptions$1>) => UseMutationOptions, DefaultError, MutationVariables>; /** Get mutation key for QueryClient methods */ mutationKey: () => ConvexMutationKey; }; /** * Decorated action procedure with queryOptions, mutationOptions, and key methods. * Actions can be used as one-shot queries (no subscription) or as mutations. * Supports skipToken for conditional queries. */ type DecorateAction> = { /** Use action as a one-shot query (no WebSocket subscription) */queryOptions: keyof FunctionArgs extends never ? (args?: EmptyObject | SkipToken, opts?: ActionQueryOptsParam) => ActionQueryOptsReturn : EmptyObject extends FunctionArgs ? (args?: FunctionArgs | SkipToken, opts?: ActionQueryOptsParam) => ActionQueryOptsReturn : (args: FunctionArgs | SkipToken, opts?: ActionQueryOptsParam) => ActionQueryOptsReturn; /** Static (non-hook) action query options for event handlers and prefetching */ staticQueryOptions: keyof FunctionArgs extends never ? (args?: EmptyObject | SkipToken, opts?: StaticQueryOptsParam) => ConvexActionOptions & { meta: ConvexQueryMeta; } : EmptyObject extends FunctionArgs ? (args?: FunctionArgs | SkipToken, opts?: StaticQueryOptsParam) => ConvexActionOptions & { meta: ConvexQueryMeta; } : (args: FunctionArgs | SkipToken, opts?: StaticQueryOptsParam) => ConvexActionOptions & { meta: ConvexQueryMeta; }; /** Use action as a mutation */ mutationOptions: (opts?: DistributiveOmit, DefaultError, MutationVariables>, ReservedMutationOptions$1>) => UseMutationOptions, DefaultError, MutationVariables>; /** Get mutation key for QueryClient methods */ mutationKey: () => ConvexMutationKey; /** Get query key for QueryClient methods */ queryKey: (args?: DeepPartial>) => ConvexActionKey; /** Get query filter for QueryClient methods */ queryFilter: (args?: DeepPartial>, filters?: DistributiveOmit) => QueryFilters; }; /** * Recursively decorates all procedures in a Convex API object. */ type CRPCClient = { [K in keyof TApi as K extends string ? K extends `_${string}` ? never : K : K]: TApi[K] extends FunctionReference<'query'> ? IsPaginated> extends true ? DecorateQuery & DecorateInfiniteQuery : DecorateQuery : TApi[K] extends FunctionReference<'mutation'> ? DecorateMutation : TApi[K] extends FunctionReference<'action'> ? DecorateAction : TApi[K] extends Record ? CRPCClient : never }; //#endregion //#region src/react/http-proxy.d.ts /** Infer schema type or return empty object if UnsetMarker */ type InferSchemaOrEmpty = T extends UnsetMarker ? object : T extends z.ZodTypeAny ? z.infer : object; /** Infer merged input from HttpProcedure (flat - used internally) */ type InferHttpInput = T extends HttpProcedure ? Simplify & InferSchemaOrEmpty & InferSchemaOrEmpty> : object; /** * Extract string keys from a Zod object schema. * Used for param/query which are always strings in URLs. */ type ZodObjectKeys = T extends z.ZodObject ? { [K in keyof Shape]: string } : Record; /** * Extract string or string[] keys from a Zod object schema. * Query params can have array values. */ type ZodQueryKeys = T extends z.ZodObject ? { [K in keyof Shape]?: string | string[] } : Record; /** * Infer client-side args from HttpProcedure with proper nesting. * - params: only present if TParams is defined, always strings (URL path params) * - searchParams: only present if TQuery is defined, always strings (URL query params) * - form: only present if TForm is defined, typed from schema * - JSON body fields spread at root level (typed from schema) * - Client options (fetch, init, headers) always optional for per-call overrides */ type InferHttpClientArgs = T extends HttpProcedure ? Simplify<(TParams extends UnsetMarker ? object : { params: ZodObjectKeys; }) & (TQuery extends UnsetMarker ? object : { searchParams: ZodQueryKeys; }) & (TForm extends UnsetMarker ? object : TForm extends z.ZodTypeAny ? { form: z.infer; } : object) & (TInput extends UnsetMarker ? object : TInput extends z.ZodTypeAny ? z.infer : object) & { fetch?: typeof fetch; init?: RequestInit; headers?: Record | (() => Record | Promise>); }> : HttpInputArgs; /** Infer output type from HttpProcedure */ type InferHttpOutput = T extends HttpProcedure ? TOutput extends UnsetMarker ? unknown : TOutput extends z.ZodTypeAny ? z.infer : unknown : unknown; /** Query key with args (3-element) or prefix key without args (2-element) for invalidation */ type HttpQueryKey = readonly ['httpQuery', string, unknown] | readonly ['httpQuery', string]; type HttpMutationKey = readonly ['httpMutation', string]; type ReservedQueryOptions = 'queryKey' | 'queryFn'; type ReservedMutationOptions = 'mutationFn'; /** Query options for GET HTTP endpoints - compatible with both useQuery and useSuspenseQuery */ type HttpQueryOptsReturn = Omit, Error, InferHttpOutput, HttpQueryKey>, 'queryFn'> & { queryFn: () => Promise>; }; /** Mutation options for POST/PUT/PATCH/DELETE HTTP endpoints - typed variables */ type HttpMutationOptsReturn = UseMutationOptions, DefaultError, InferHttpClientArgs>; /** Query options (TanStack Query only - client opts go in args) */ type HttpQueryOptions = DistributiveOmit, ReservedQueryOptions>; /** Mutation options (TanStack Query only - client opts go in mutate args) */ type HttpMutationOptions = DistributiveOmit, ReservedMutationOptions>; /** * Decorated GET procedure with queryOptions and mutationOptions. * - queryOptions: For cached data fetching (useQuery/useSuspenseQuery) * - mutationOptions: For one-time actions like exports (useMutation) */ type DecorateHttpQuery = { queryOptions: keyof InferHttpInput extends never ? (args?: InferHttpClientArgs, opts?: HttpQueryOptions) => HttpQueryOptsReturn : object extends InferHttpInput ? (args?: InferHttpClientArgs, opts?: HttpQueryOptions) => HttpQueryOptsReturn : (args: InferHttpClientArgs, opts?: HttpQueryOptions) => HttpQueryOptsReturn; /** Get query key for QueryClient methods (with args = exact match, without = prefix) */ queryKey: (args?: InferHttpClientArgs) => HttpQueryKey; /** Get query filter for QueryClient methods (e.g., invalidateQueries) */ queryFilter: (args?: InferHttpClientArgs, filters?: DistributiveOmit) => QueryFilters; /** Mutation options for GET endpoints (exports, downloads - no caching) */ mutationOptions: (opts?: HttpMutationOptions) => HttpMutationOptsReturn; /** Get mutation key for QueryClient methods */ mutationKey: () => HttpMutationKey; }; /** * Decorated POST/PUT/PATCH/DELETE procedure with mutationOptions. * The mutationFn receives typed args inferred from server schemas. */ type DecorateHttpMutation = { mutationOptions: (opts?: HttpMutationOptions) => HttpMutationOptsReturn; /** Get mutation key for QueryClient methods */ mutationKey: () => HttpMutationKey; }; /** Vanilla HTTP query - only direct call, no React Query */ /** * HTTP Client type from router record. * Maps each procedure to queryOptions (GET) or mutationOptions (POST/etc). * Uses infer to extract the method type literal for proper GET/non-GET distinction. */ type HttpCRPCClient = { [K in keyof T]: T[K] extends HttpProcedure ? TMethod extends 'GET' ? DecorateHttpQuery : DecorateHttpMutation : T[K] extends CRPCHttpRouter ? HttpCRPCClient : T[K] extends HttpRouterRecord ? HttpCRPCClient : never }; /** * HTTP Client type from a CRPCHttpRouter. * Use this when your type is the router object (with _def). */ type HttpCRPCClientFromRouter> = HttpCRPCClient; //#endregion //#region src/rsc/proxy-server.d.ts type CreateServerCRPCProxyOptions = { api: TApi; }; /** * Extract HTTP router from TApi['http'] if present (optional). * Uses NonNullable to handle optional http property. */ type ExtractHttpRouter = TApi extends { http?: infer R; } ? NonNullable extends CRPCHttpRouter ? NonNullable : undefined : undefined; /** * Combined CRPC client type with optional HTTP router. * HTTP router is extracted from TApi['http'] if present. * Uses Omit to prevent type conflicts between CRPCClient and HttpCRPCClient. */ type ServerCRPCClient> = ExtractHttpRouter extends CRPCHttpRouter ? CRPCClient> & { http: HttpCRPCClientFromRouter>; } : CRPCClient; /** * Create a server-compatible CRPC proxy for RSC. * Only supports queryOptions (no mutations in RSC). * * Query execution (including auth) is handled by getServerQueryClientOptions. * * @example * ```tsx * // src/lib/convex/rsc.tsx * import { api } from '@convex/api'; * * // Proxy just builds query options - no auth config here * export const crpc = createServerCRPCProxy({ api }); * * // Auth + execution config in QueryClient * const queryClient = new QueryClient({ * defaultOptions: getServerQueryClientOptions({ * getToken: caller.getToken, * convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL, * }), * }); * * // app/page.tsx (RSC) * prefetch(crpc.posts.list.queryOptions()); * prefetch(crpc.http.health.queryOptions({})); * ``` */ declare function createServerCRPCProxy>(options: CreateServerCRPCProxyOptions): ServerCRPCClient; //#endregion //#region src/rsc/server-query-client.d.ts type GetServerQueryClientOptionsParams = { /** Function to get auth token for authenticated queries. Use `caller.getToken` from your RSC setup. */getToken?: () => Promise; /** Base URL for HTTP routes (e.g., NEXT_PUBLIC_CONVEX_SITE_URL). Required for crpc.http.* queries. */ convexSiteUrl?: string; /** Optional payload transformer (always composed with built-in Date support). */ transformer?: DataTransformerOptions; }; /** * Get server QueryClient options for RSC prefetching. * Handles both WebSocket queries (convexQuery/convexAction) and HTTP routes (httpQuery). * * @example * ```ts * const queryClient = new QueryClient({ * defaultOptions: { * ...getServerQueryClientOptions({ * getToken: caller.getToken, * convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL, * }), * }, * }); * ``` */ declare function getServerQueryClientOptions({ getToken, convexSiteUrl, transformer: transformerOptions }?: GetServerQueryClientOptionsParams): { queries: { staleTime: number; queryFn: ({ queryKey, meta }: { queryKey: readonly unknown[]; meta?: Record; }) => Promise; queryKeyHashFn: (queryKey: readonly unknown[]) => string; }; }; //#endregion export { CreateServerCRPCProxyOptions, GetServerQueryClientOptionsParams, type ServerCRPCClient, createServerCRPCProxy, getServerQueryClientOptions };