better-convex 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -197,8 +197,8 @@ declare const adapterArgsValidator: convex_values0.VObject<{
197
197
  select?: string[] | undefined;
198
198
  offset?: number | undefined;
199
199
  sortBy?: {
200
- direction: "asc" | "desc";
201
200
  field: string;
201
+ direction: "asc" | "desc";
202
202
  } | undefined;
203
203
  where?: {
204
204
  connector?: "AND" | "OR" | undefined;
@@ -213,12 +213,12 @@ declare const adapterArgsValidator: convex_values0.VObject<{
213
213
  offset: convex_values0.VFloat64<number | undefined, "optional">;
214
214
  select: convex_values0.VArray<string[] | undefined, convex_values0.VString<string, "required">, "optional">;
215
215
  sortBy: convex_values0.VObject<{
216
- direction: "asc" | "desc";
217
216
  field: string;
217
+ direction: "asc" | "desc";
218
218
  } | undefined, {
219
219
  direction: convex_values0.VUnion<"asc" | "desc", [convex_values0.VLiteral<"asc", "required">, convex_values0.VLiteral<"desc", "required">], "required", never>;
220
220
  field: convex_values0.VString<string, "required">;
221
- }, "optional", "direction" | "field">;
221
+ }, "optional", "field" | "direction">;
222
222
  where: convex_values0.VArray<{
223
223
  connector?: "AND" | "OR" | undefined;
224
224
  operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
@@ -235,7 +235,7 @@ declare const adapterArgsValidator: convex_values0.VObject<{
235
235
  operator: convex_values0.VUnion<"in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
236
236
  value: convex_values0.VUnion<string | number | boolean | string[] | number[] | null, [convex_values0.VString<string, "required">, convex_values0.VFloat64<number, "required">, convex_values0.VBoolean<boolean, "required">, convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">, convex_values0.VArray<number[], convex_values0.VFloat64<number, "required">, "required">, convex_values0.VNull<null, "required">], "required", never>;
237
237
  }, "required", "value" | "connector" | "field" | "operator">, "optional">;
238
- }, "required", "limit" | "model" | "select" | "offset" | "sortBy" | "where" | "sortBy.direction" | "sortBy.field">;
238
+ }, "required", "limit" | "model" | "select" | "offset" | "sortBy" | "where" | "sortBy.field" | "sortBy.direction">;
239
239
  declare const hasUniqueFields: (betterAuthSchema: BetterAuthDBSchema, model: string, input: Record<string, any>) => boolean;
240
240
  declare const checkUniqueFields: <Schema extends SchemaDefinition<any, any>>(ctx: GenericQueryCtx<GenericDataModel>, schema: Schema, betterAuthSchema: BetterAuthDBSchema, table: string, input: Record<string, any>, doc?: Record<string, any>) => Promise<void>;
241
241
  declare const selectFields: <T extends TableNamesInDataModel<GenericDataModel>, D extends DocumentByName<GenericDataModel, T>>(doc: D | null, select?: string[]) => Promise<D | null>;
@@ -407,8 +407,8 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
407
407
  join?: any;
408
408
  offset?: number | undefined;
409
409
  sortBy?: {
410
- direction: "asc" | "desc";
411
410
  field: string;
411
+ direction: "asc" | "desc";
412
412
  } | undefined;
413
413
  where?: {
414
414
  connector?: "AND" | "OR" | undefined;
@@ -19203,8 +19203,8 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
19203
19203
  join?: any;
19204
19204
  offset?: number | undefined;
19205
19205
  sortBy?: {
19206
- direction: "asc" | "desc";
19207
19206
  field: string;
19207
+ direction: "asc" | "desc";
19208
19208
  } | undefined;
19209
19209
  where?: {
19210
19210
  connector?: "AND" | "OR" | undefined;
@@ -1,7 +1,36 @@
1
1
  import { $ as identityTransformer, G as DataTransformerOptions, H as CombinedDataTransformer, J as dateWireCodec, K as WireCodec, Q as getTransformer, U as DATE_CODEC_TAG, W as DataTransformer, X as defaultCRPCTransformer, Y as decodeWire, Z as encodeWire, a as HttpProcedureCall, c as InferHttpInput, i as HttpErrorCode, l as InferHttpOutput, n as HttpClientError, o as HttpRouteInfo, q as createTaggedTransformer, r as HttpClientFromRouter, s as HttpRouteMap, t as HttpClient, u as isHttpClientError } from "../http-types-BK7FuIcR.js";
2
- import { C as PaginatedFnMeta, D as VanillaMutation, E as VanillaCRPCClient, O as VanillaQuery, S as Meta, T as VanillaAction, _ as ExtractPaginatedItem, a as ConvexInfiniteQueryMeta, b as InfiniteQueryInput, c as ConvexMutationKey, d as ConvexQueryMeta, f as ConvexQueryOptions, g as DecorateQuery, h as DecorateMutation, i as ConvexActionOptions, l as ConvexQueryHookOptions, m as DecorateInfiniteQuery, n as CRPCClient, o as ConvexInfiniteQueryOptions, p as DecorateAction, r as ConvexActionKey, s as ConvexInfiniteQueryOptionsWithRef, t as AuthType, u as ConvexQueryKey, v as FUNC_REF_SYMBOL, w as PaginationOpts, x as InfiniteQueryOptsParam, y as FnMeta } from "../types-f53SgpBL.js";
2
+ import { A as HttpInputArgs, C as ReservedMutationOptions, D as VanillaMutation, E as VanillaAction, F as replaceUrlParam, M as RESERVED_KEYS, N as buildSearchParams, O as HttpClientOptions, P as executeHttpRequest, S as ReservedInfiniteQueryOptions, T as StaticQueryOptsParam, _ as IsPaginated, a as BaseInfiniteQueryOptsParam, b as PaginatedFnMeta, c as ConvexMutationKey, d as ConvexQueryMeta, f as EmptyObject, g as InfiniteQueryInput, h as FnMeta, i as BaseConvexQueryOptions, j as HttpProxyBaseOptions, k as HttpFormValue, l as ConvexQueryHookOptions, m as FUNC_REF_SYMBOL, n as BaseConvexActionOptions, o as ConvexActionKey, p as ExtractPaginatedItem, r as BaseConvexInfiniteQueryOptions, s as ConvexInfiniteQueryMeta, t as AuthType, u as ConvexQueryKey, v as Meta, w as ReservedQueryOptions, x as PaginationOpts, y as MutationVariables } from "../types-7bF_8IjP.js";
3
3
  import { FunctionArgs, FunctionReference } from "convex/server";
4
4
 
5
+ //#region src/crpc/auth-error.d.ts
6
+ /**
7
+ * Auth Mutation Error
8
+ *
9
+ * Framework-agnostic error class for Better Auth mutations.
10
+ */
11
+ /**
12
+ * Error thrown when a Better Auth mutation fails.
13
+ * Contains the original error details from Better Auth.
14
+ */
15
+ declare class AuthMutationError extends Error {
16
+ /** Error code from Better Auth (e.g., 'INVALID_PASSWORD', 'EMAIL_ALREADY_REGISTERED') */
17
+ code?: string;
18
+ /** HTTP status code */
19
+ status: number;
20
+ /** HTTP status text */
21
+ statusText: string;
22
+ constructor(authError: {
23
+ message?: string;
24
+ status: number;
25
+ statusText: string;
26
+ code?: string;
27
+ });
28
+ }
29
+ /**
30
+ * Type guard to check if an error is an AuthMutationError.
31
+ */
32
+ declare function isAuthMutationError(error: unknown): error is AuthMutationError;
33
+ //#endregion
5
34
  //#region src/crpc/error.d.ts
6
35
  /**
7
36
  * Client error codes (subset of CRPC codes for client-side use)
@@ -40,7 +69,7 @@ declare const defaultIsUnauthorized: (error: unknown) => boolean;
40
69
  */
41
70
  declare function convexQuery<T extends FunctionReference<'query'>>(funcRef: T, args?: FunctionArgs<T> | 'skip', meta?: Meta, opts?: {
42
71
  skipUnauth?: boolean;
43
- }): ConvexQueryOptions<T> & {
72
+ }): BaseConvexQueryOptions<T> & {
44
73
  meta: ConvexQueryMeta;
45
74
  };
46
75
  /**
@@ -62,7 +91,7 @@ declare function convexQuery<T extends FunctionReference<'query'>>(funcRef: T, a
62
91
  */
63
92
  declare function convexAction<T extends FunctionReference<'action'>>(funcRef: T, args?: FunctionArgs<T> | 'skip', meta?: Meta, opts?: {
64
93
  skipUnauth?: boolean;
65
- }): ConvexActionOptions<T> & {
94
+ }): BaseConvexActionOptions<T> & {
66
95
  meta: ConvexQueryMeta;
67
96
  };
68
97
  /**
@@ -71,6 +100,6 @@ declare function convexAction<T extends FunctionReference<'action'>>(funcRef: T,
71
100
  *
72
101
  * Uses flat { cursor, limit } input like tRPC.
73
102
  */
74
- declare function convexInfiniteQueryOptions<T extends FunctionReference<'query'>>(funcRef: T, args: Record<string, unknown> | 'skip', opts?: InfiniteQueryOptsParam<T>, meta?: Meta): ConvexInfiniteQueryOptions<T>;
103
+ declare function convexInfiniteQueryOptions<T extends FunctionReference<'query'>>(funcRef: T, args: Record<string, unknown> | 'skip', opts?: BaseInfiniteQueryOptsParam<T> & Record<string, unknown>, meta?: Meta): BaseConvexInfiniteQueryOptions<T> & Record<string, unknown>;
75
104
  //#endregion
76
- export { AuthType, CRPCClient, CRPCClientError, CombinedDataTransformer, ConvexActionKey, ConvexActionOptions, ConvexInfiniteQueryMeta, ConvexInfiniteQueryOptions, ConvexInfiniteQueryOptionsWithRef, ConvexMutationKey, ConvexQueryHookOptions, ConvexQueryKey, ConvexQueryMeta, ConvexQueryOptions, DATE_CODEC_TAG, DataTransformer, DataTransformerOptions, DecorateAction, DecorateInfiniteQuery, DecorateMutation, DecorateQuery, ExtractPaginatedItem, FUNC_REF_SYMBOL, FnMeta, HttpClient, HttpClientError, HttpClientFromRouter, HttpErrorCode, HttpProcedureCall, HttpRouteInfo, HttpRouteMap, InferHttpInput, InferHttpOutput, InfiniteQueryInput, InfiniteQueryOptsParam, Meta, PaginatedFnMeta, PaginationOpts, VanillaAction, VanillaCRPCClient, VanillaMutation, VanillaQuery, WireCodec, convexAction, convexInfiniteQueryOptions, convexQuery, createTaggedTransformer, dateWireCodec, decodeWire, defaultCRPCTransformer, defaultIsUnauthorized, encodeWire, getTransformer, identityTransformer, isCRPCClientError, isCRPCError, isCRPCErrorCode, isHttpClientError };
105
+ export { AuthMutationError, AuthType, BaseConvexActionOptions, BaseConvexInfiniteQueryOptions, BaseConvexQueryOptions, BaseInfiniteQueryOptsParam, CRPCClientError, CombinedDataTransformer, ConvexActionKey, ConvexInfiniteQueryMeta, ConvexMutationKey, ConvexQueryHookOptions, ConvexQueryKey, ConvexQueryMeta, DATE_CODEC_TAG, DataTransformer, DataTransformerOptions, EmptyObject, ExtractPaginatedItem, FUNC_REF_SYMBOL, FnMeta, HttpClient, HttpClientError, HttpClientFromRouter, HttpClientOptions, HttpErrorCode, HttpFormValue, HttpInputArgs, HttpProcedureCall, HttpProxyBaseOptions, HttpRouteInfo, HttpRouteMap, InferHttpInput, InferHttpOutput, InfiniteQueryInput, IsPaginated, Meta, MutationVariables, PaginatedFnMeta, PaginationOpts, RESERVED_KEYS, ReservedInfiniteQueryOptions, ReservedMutationOptions, ReservedQueryOptions, StaticQueryOptsParam, VanillaAction, VanillaMutation, WireCodec, buildSearchParams, convexAction, convexInfiniteQueryOptions, convexQuery, createTaggedTransformer, dateWireCodec, decodeWire, defaultCRPCTransformer, defaultIsUnauthorized, encodeWire, executeHttpRequest, getTransformer, identityTransformer, isAuthMutationError, isCRPCClientError, isCRPCError, isCRPCErrorCode, isHttpClientError, replaceUrlParam };
@@ -2,6 +2,39 @@ import { a as isCRPCErrorCode, i as isCRPCError, n as defaultIsUnauthorized, r a
2
2
  import { a as defaultCRPCTransformer, c as identityTransformer, i as decodeWire, n as createTaggedTransformer, o as encodeWire, r as dateWireCodec, s as getTransformer, t as DATE_CODEC_TAG } from "../transformer-ogg-4d78.js";
3
3
  import { n as convexInfiniteQueryOptions, r as convexQuery, t as convexAction } from "../query-options-CSCmKYdJ.js";
4
4
 
5
+ //#region src/crpc/auth-error.ts
6
+ /**
7
+ * Auth Mutation Error
8
+ *
9
+ * Framework-agnostic error class for Better Auth mutations.
10
+ */
11
+ /**
12
+ * Error thrown when a Better Auth mutation fails.
13
+ * Contains the original error details from Better Auth.
14
+ */
15
+ var AuthMutationError = class extends Error {
16
+ /** Error code from Better Auth (e.g., 'INVALID_PASSWORD', 'EMAIL_ALREADY_REGISTERED') */
17
+ code;
18
+ /** HTTP status code */
19
+ status;
20
+ /** HTTP status text */
21
+ statusText;
22
+ constructor(authError) {
23
+ super(authError.message || authError.statusText);
24
+ this.name = "AuthMutationError";
25
+ this.code = authError.code;
26
+ this.status = authError.status;
27
+ this.statusText = authError.statusText;
28
+ }
29
+ };
30
+ /**
31
+ * Type guard to check if an error is an AuthMutationError.
32
+ */
33
+ function isAuthMutationError(error) {
34
+ return error instanceof AuthMutationError;
35
+ }
36
+
37
+ //#endregion
5
38
  //#region src/crpc/http-types.ts
6
39
  /** HTTP client error */
7
40
  var HttpClientError = class extends Error {
@@ -19,10 +52,118 @@ var HttpClientError = class extends Error {
19
52
  /** Type guard for HttpClientError */
20
53
  const isHttpClientError = (error) => error instanceof HttpClientError;
21
54
 
55
+ //#endregion
56
+ //#region src/crpc/http-client.ts
57
+ /**
58
+ * HTTP Client Helpers
59
+ *
60
+ * Framework-agnostic utilities for executing HTTP requests
61
+ * against Convex HTTP endpoints.
62
+ */
63
+ /** Reserved keys that are not part of JSON body */
64
+ const RESERVED_KEYS = new Set([
65
+ "params",
66
+ "searchParams",
67
+ "form",
68
+ "fetch",
69
+ "init",
70
+ "headers"
71
+ ]);
72
+ /**
73
+ * Replace URL path parameters with actual values.
74
+ * e.g., '/users/:id' with { id: '123' } -> '/users/123'
75
+ */
76
+ function replaceUrlParam(url, params) {
77
+ return url.replace(/:(\w+)/g, (_, key) => {
78
+ const value = params[key];
79
+ return value !== void 0 ? encodeURIComponent(value) : `:${key}`;
80
+ });
81
+ }
82
+ /**
83
+ * Build URLSearchParams from query object.
84
+ * Handles array values as multiple params with same key (like Hono).
85
+ */
86
+ function buildSearchParams(query) {
87
+ const params = new URLSearchParams();
88
+ for (const [key, value] of Object.entries(query)) if (Array.isArray(value)) for (const v of value) params.append(key, v);
89
+ else if (value !== void 0 && value !== null) params.append(key, value);
90
+ return params;
91
+ }
92
+ /**
93
+ * Hono-style HTTP request executor.
94
+ * Processes args in the same way as Hono's ClientRequestImpl.fetch().
95
+ */
96
+ async function executeHttpRequest(opts) {
97
+ const { method, path } = opts.route;
98
+ const args = opts.args ?? {};
99
+ let rBody;
100
+ let cType;
101
+ if (args.form) {
102
+ const form = new FormData();
103
+ for (const [k, v] of Object.entries(args.form)) if (Array.isArray(v)) for (const v2 of v) form.append(k, v2);
104
+ else form.append(k, v);
105
+ rBody = form;
106
+ } else {
107
+ const jsonBody = {};
108
+ for (const [key, value] of Object.entries(args)) if (!RESERVED_KEYS.has(key) && value !== void 0) jsonBody[key] = value;
109
+ if (Object.keys(jsonBody).length > 0) {
110
+ rBody = JSON.stringify(opts.transformer.input.serialize(jsonBody));
111
+ cType = "application/json";
112
+ }
113
+ }
114
+ const argsClientOpts = {};
115
+ if (args.fetch) argsClientOpts.fetch = args.fetch;
116
+ if (args.init) argsClientOpts.init = args.init;
117
+ if (args.headers) argsClientOpts.headers = args.headers;
118
+ const mergedClientOpts = {
119
+ ...opts.clientOpts,
120
+ ...argsClientOpts
121
+ };
122
+ const resolvedBaseHeaders = typeof opts.baseHeaders === "function" ? await opts.baseHeaders() : opts.baseHeaders;
123
+ const headerValues = { ...typeof mergedClientOpts.headers === "function" ? await mergedClientOpts.headers() : mergedClientOpts.headers };
124
+ if (cType) headerValues["Content-Type"] = cType;
125
+ const finalHeaders = {};
126
+ if (resolvedBaseHeaders) {
127
+ for (const [key, value] of Object.entries(resolvedBaseHeaders)) if (value !== void 0) finalHeaders[key] = value;
128
+ }
129
+ Object.assign(finalHeaders, headerValues);
130
+ let url = opts.convexSiteUrl + path;
131
+ if (args.params) url = opts.convexSiteUrl + replaceUrlParam(path, args.params);
132
+ if (args.searchParams) {
133
+ const queryString = buildSearchParams(args.searchParams).toString();
134
+ if (queryString) url = `${url}?${queryString}`;
135
+ }
136
+ const methodUpperCase = method.toUpperCase();
137
+ const setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
138
+ const response = await (mergedClientOpts.fetch ?? opts.baseFetch ?? globalThis.fetch)(url, {
139
+ body: setBody ? rBody : void 0,
140
+ method: methodUpperCase,
141
+ headers: finalHeaders,
142
+ ...mergedClientOpts.init
143
+ });
144
+ if (!response.ok) {
145
+ const errorData = await response.json().catch(() => ({ error: {
146
+ code: "UNKNOWN",
147
+ message: response.statusText
148
+ } }));
149
+ const errorCode = errorData?.error?.code || "UNKNOWN";
150
+ const errorMessage = errorData?.error?.message || response.statusText;
151
+ throw new HttpClientError({
152
+ code: errorCode,
153
+ status: response.status,
154
+ procedureName: opts.procedureName,
155
+ message: errorMessage
156
+ });
157
+ }
158
+ if (response.headers.get("content-length") === "0" || response.status === 204) return;
159
+ if ((response.headers.get("content-type") || "").includes("application/json")) return opts.transformer.output.deserialize(await response.json());
160
+ return response.text();
161
+ }
162
+
22
163
  //#endregion
23
164
  //#region src/crpc/types.ts
24
165
  /** Symbol key for attaching FunctionReference to options (non-serializable) */
25
166
  const FUNC_REF_SYMBOL = Symbol.for("convex.funcRef");
26
167
 
27
168
  //#endregion
28
- export { CRPCClientError, DATE_CODEC_TAG, FUNC_REF_SYMBOL, HttpClientError, convexAction, convexInfiniteQueryOptions, convexQuery, createTaggedTransformer, dateWireCodec, decodeWire, defaultCRPCTransformer, defaultIsUnauthorized, encodeWire, getTransformer, identityTransformer, isCRPCClientError, isCRPCError, isCRPCErrorCode, isHttpClientError };
169
+ export { AuthMutationError, CRPCClientError, DATE_CODEC_TAG, FUNC_REF_SYMBOL, HttpClientError, RESERVED_KEYS, buildSearchParams, convexAction, convexInfiniteQueryOptions, convexQuery, createTaggedTransformer, dateWireCodec, decodeWire, defaultCRPCTransformer, defaultIsUnauthorized, encodeWire, executeHttpRequest, getTransformer, identityTransformer, isAuthMutationError, isCRPCClientError, isCRPCError, isCRPCErrorCode, isHttpClientError, replaceUrlParam };
package/dist/orm/index.js CHANGED
@@ -2075,6 +2075,12 @@ function findRelationIndex(table, columns, relationName, targetTableName, strict
2075
2075
  const PUBLIC_CREATED_AT_FIELD = "createdAt";
2076
2076
  const INTERNAL_CREATION_TIME_FIELD = "_creationTime";
2077
2077
  const CREATED_AT_MIGRATION_MESSAGE = "`_creationTime` is no longer public. Use `createdAt` instead.";
2078
+ const hasUserCreatedAtColumn = (table) => {
2079
+ if (!table || typeof table !== "object") return false;
2080
+ const columns = table[Columns];
2081
+ if (!columns || typeof columns !== "object") return false;
2082
+ return Object.hasOwn(columns, PUBLIC_CREATED_AT_FIELD);
2083
+ };
2078
2084
  const usesSystemCreatedAtAlias = (_table) => true;
2079
2085
 
2080
2086
  //#endregion
@@ -2176,10 +2182,11 @@ const normalizePublicSystemFields = (value, options) => {
2176
2182
  };
2177
2183
  const normalizeDateFieldsForWrite = (table, value) => {
2178
2184
  const useSystemCreatedAt = usesSystemCreatedAtAlias(table);
2185
+ const hasUserCreatedAt = hasUserCreatedAtColumn(table);
2179
2186
  const temporalColumns = getTemporalColumnDescriptors(table);
2180
2187
  const result = { ...value };
2181
2188
  if (Object.hasOwn(result, INTERNAL_CREATION_TIME_FIELD)) throw new Error(CREATED_AT_MIGRATION_MESSAGE);
2182
- if (useSystemCreatedAt && Object.hasOwn(result, PUBLIC_CREATED_AT_FIELD)) delete result[PUBLIC_CREATED_AT_FIELD];
2189
+ if (useSystemCreatedAt && !hasUserCreatedAt && Object.hasOwn(result, PUBLIC_CREATED_AT_FIELD)) delete result[PUBLIC_CREATED_AT_FIELD];
2183
2190
  for (const [name, descriptor] of temporalColumns.entries()) {
2184
2191
  if (!Object.hasOwn(result, name)) continue;
2185
2192
  result[name] = normalizeTemporalWriteValue(descriptor, result[name]);
@@ -10,7 +10,12 @@ import { ConvexHttpClient } from "convex/browser";
10
10
  import * as jotai_vanilla0 from "jotai/vanilla";
11
11
  import { z } from "zod";
12
12
 
13
- //#region src/react/auth-mutations.d.ts
13
+ //#region src/crpc/auth-error.d.ts
14
+ /**
15
+ * Auth Mutation Error
16
+ *
17
+ * Framework-agnostic error class for Better Auth mutations.
18
+ */
14
19
  /**
15
20
  * Error thrown when a Better Auth mutation fails.
16
21
  * Contains the original error details from Better Auth.
@@ -33,6 +38,8 @@ declare class AuthMutationError extends Error {
33
38
  * Type guard to check if an error is an AuthMutationError.
34
39
  */
35
40
  declare function isAuthMutationError(error: unknown): error is AuthMutationError;
41
+ //#endregion
42
+ //#region src/react/auth-mutations.d.ts
36
43
  type MutationOptionsHook<TData, TVariables = void> = (options?: Omit<UseMutationOptions<TData, DefaultError, TVariables>, 'mutationFn'>) => UseMutationOptions<TData, DefaultError, TVariables>;
37
44
  type AnyFn = (...args: any[]) => Promise<any>;
38
45
  type AuthClient = {
@@ -534,6 +541,8 @@ declare const FUNC_REF_SYMBOL: unique symbol;
534
541
  type ReservedQueryOptions$2 = 'queryKey' | 'queryFn' | 'staleTime';
535
542
  /** Options controlled by mutation factories */
536
543
  type ReservedMutationOptions$2 = 'mutationFn';
544
+ /** Reserved options controlled by infinite query factories */
545
+ type ReservedInfiniteQueryOptions = 'queryKey' | 'queryFn' | 'staleTime' | 'refetchInterval' | 'refetchOnMount' | 'refetchOnReconnect' | 'refetchOnWindowFocus' | 'persister' | 'placeholderData';
537
546
  /** Metadata for a single Convex function */
538
547
  type FnMeta$1 = {
539
548
  auth?: 'required' | 'optional';
@@ -569,10 +578,6 @@ type ConvexQueryMeta = {
569
578
  skipUnauth?: boolean; /** Whether to create WebSocket subscription (default: true) */
570
579
  subscribe?: boolean;
571
580
  };
572
- /** Options returned by `convexQuery` factory */
573
- type ConvexQueryOptions<T extends FunctionReference<'query'>> = Pick<UseQueryOptions<FunctionReturnType<T>, Error, FunctionReturnType<T>, ConvexQueryKey<T>>, 'queryKey' | 'staleTime' | 'enabled'>;
574
- /** Options returned by `convexAction` factory */
575
- type ConvexActionOptions<T extends FunctionReference<'action'>> = Pick<UseQueryOptions<FunctionReturnType<T>, Error, FunctionReturnType<T>, ConvexActionKey<T>>, 'queryKey' | 'staleTime' | 'enabled'>;
576
581
  /** Hook options for Convex queries */
577
582
  type ConvexQueryHookOptions = {
578
583
  /** Skip query silently when unauthenticated (default: false, calls onQueryUnauthorized) */skipUnauth?: boolean; /** Set to false to fetch once without subscribing (default: true) */
@@ -584,7 +589,36 @@ type InfiniteQueryInput<TInput> = Omit<TInput, 'cursor' | 'limit'>;
584
589
  type ExtractPaginatedItem<TOutput> = TOutput extends {
585
590
  page: (infer T)[];
586
591
  } ? T : never;
592
+ /** Metadata for infinite query (extends ConvexQueryMeta) */
593
+ type ConvexInfiniteQueryMeta = ConvexQueryMeta & {
594
+ /** The query function name (serializable for RSC) */queryName: string; /** Query args without cursor/limit (user's filter args only) */
595
+ args: Record<string, unknown>; /** Items per page (optional - server uses .paginated() default) */
596
+ limit?: number;
597
+ };
587
598
  type EmptyObject = Record<string, never>;
599
+ /** Static query options parameter type (non-hook, for event handlers) */
600
+ type StaticQueryOptsParam = {
601
+ skipUnauth?: boolean;
602
+ };
603
+ /** Check if a type has cursor key (pagination detection) */
604
+ type IsPaginated<T> = 'cursor' extends keyof T ? true : false;
605
+ /** Mutation variables type - undefined when no args required (allows mutateAsync() without args) */
606
+ type MutationVariables<T extends FunctionReference<'mutation' | 'action'>> = keyof FunctionArgs<T> extends never ? void : EmptyObject extends FunctionArgs<T> ? FunctionArgs<T> | undefined : FunctionArgs<T>;
607
+ /** Vanilla mutation - direct .mutate() call without TanStack Query */
608
+ type VanillaMutation<T extends FunctionReference<'mutation'>> = {
609
+ mutate: keyof FunctionArgs<T> extends never ? (args?: EmptyObject) => Promise<FunctionReturnType<T>> : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T>) => Promise<FunctionReturnType<T>> : (args: FunctionArgs<T>) => Promise<FunctionReturnType<T>>;
610
+ };
611
+ /** Vanilla action - both .query() and .mutate() for direct calls */
612
+ type VanillaAction<T extends FunctionReference<'action'>> = {
613
+ query: keyof FunctionArgs<T> extends never ? (args?: EmptyObject) => Promise<FunctionReturnType<T>> : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T>) => Promise<FunctionReturnType<T>> : (args: FunctionArgs<T>) => Promise<FunctionReturnType<T>>;
614
+ mutate: keyof FunctionArgs<T> extends never ? (args?: EmptyObject) => Promise<FunctionReturnType<T>> : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T>) => Promise<FunctionReturnType<T>> : (args: FunctionArgs<T>) => Promise<FunctionReturnType<T>>;
615
+ };
616
+ //#endregion
617
+ //#region src/react/crpc-types.d.ts
618
+ /** Options returned by `convexQuery` factory */
619
+ type ConvexQueryOptions<T extends FunctionReference<'query'>> = Pick<UseQueryOptions<FunctionReturnType<T>, Error, FunctionReturnType<T>, ConvexQueryKey<T>>, 'queryKey' | 'staleTime' | 'enabled'>;
620
+ /** Options returned by `convexAction` factory */
621
+ type ConvexActionOptions<T extends FunctionReference<'action'>> = Pick<UseQueryOptions<FunctionReturnType<T>, Error, FunctionReturnType<T>, ConvexActionKey<T>>, 'queryKey' | 'staleTime' | 'enabled'>;
588
622
  /** Query options parameter type */
589
623
  type QueryOptsParam<T extends FunctionReference<'query'>> = Simplify<ConvexQueryHookOptions & DistributiveOmit<UseQueryOptions<FunctionReturnType<T>, DefaultError>, ReservedQueryOptions$2>>;
590
624
  /** Query options return type */
@@ -600,10 +634,6 @@ type ActionQueryOptsReturn<T extends FunctionReference<'action'>> = ConvexAction
600
634
  * Args are optional when the function has no required parameters.
601
635
  * Supports skipToken for type-safe conditional queries.
602
636
  */
603
- /** Static query options parameter type (non-hook, for event handlers) */
604
- type StaticQueryOptsParam = {
605
- skipUnauth?: boolean;
606
- };
607
637
  type DecorateQuery<T extends FunctionReference<'query'>> = {
608
638
  queryOptions: keyof FunctionArgs<T> extends never ? (args?: EmptyObject | SkipToken, opts?: QueryOptsParam<T>) => QueryOptsReturn<T> : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T> | SkipToken, opts?: QueryOptsParam<T>) => QueryOptsReturn<T> : (args: FunctionArgs<T> | SkipToken, opts?: QueryOptsParam<T>) => QueryOptsReturn<T>; /** Static (non-hook) query options for event handlers and prefetching */
609
639
  staticQueryOptions: keyof FunctionArgs<T> extends never ? (args?: EmptyObject | SkipToken, opts?: StaticQueryOptsParam) => ConvexQueryOptions<T> & {
@@ -616,20 +646,12 @@ type DecorateQuery<T extends FunctionReference<'query'>> = {
616
646
  queryKey: (args?: DeepPartial<FunctionArgs<T>>) => ConvexQueryKey<T>; /** Get query filter for QueryClient methods (invalidateQueries, removeQueries, etc.) */
617
647
  queryFilter: (args?: DeepPartial<FunctionArgs<T>>, filters?: DistributiveOmit<QueryFilters, 'queryKey'>) => QueryFilters;
618
648
  };
619
- /** Reserved options controlled by infinite query factories */
620
- type ReservedInfiniteQueryOptions = 'queryKey' | 'queryFn' | 'staleTime' | 'refetchInterval' | 'refetchOnMount' | 'refetchOnReconnect' | 'refetchOnWindowFocus' | 'persister' | 'placeholderData';
621
649
  /** Options for infinite query - extends TanStack Query options */
622
650
  type InfiniteQueryOptsParam<T extends FunctionReference<'query'> = FunctionReference<'query'>> = {
623
651
  /** Items per page. Optional - server uses .paginated() default if not provided. */limit?: number; /** Skip query silently when unauthenticated */
624
652
  skipUnauth?: boolean; /** Placeholder data shown while loading (item array, not pagination result) */
625
653
  placeholderData?: ExtractPaginatedItem<FunctionReturnType<T>>[];
626
654
  } & DistributiveOmit<UseQueryOptions<FunctionReturnType<T>, DefaultError>, ReservedInfiniteQueryOptions>;
627
- /** Metadata for infinite query (extends ConvexQueryMeta) */
628
- type ConvexInfiniteQueryMeta = ConvexQueryMeta & {
629
- /** The query function name (serializable for RSC) */queryName: string; /** Query args without cursor/limit (user's filter args only) */
630
- args: Record<string, unknown>; /** Items per page (optional - server uses .paginated() default) */
631
- limit?: number;
632
- };
633
655
  /** Return type of infiniteQueryOptions - compatible with TanStack prefetch */
634
656
  type ConvexInfiniteQueryOptions<T extends FunctionReference<'query'>> = Pick<UseQueryOptions<FunctionReturnType<T>, Error, FunctionReturnType<T>, ConvexQueryKey<T>>, 'queryKey' | 'staleTime' | 'enabled'> & {
635
657
  meta: ConvexInfiniteQueryMeta;
@@ -656,8 +678,6 @@ type DecorateInfiniteQuery<T extends FunctionReference<'query'>> = {
656
678
  infiniteQueryKey: (args?: DeepPartial<InfiniteQueryInput<FunctionArgs<T>>>) => ConvexQueryKey<T>; /** Function metadata from server (auth, limit, rateLimit, role, type) */
657
679
  meta: PaginatedFnMeta;
658
680
  };
659
- /** Mutation variables type - undefined when no args required (allows mutateAsync() without args) */
660
- type MutationVariables<T extends FunctionReference<'mutation' | 'action'>> = keyof FunctionArgs<T> extends never ? void : EmptyObject extends FunctionArgs<T> ? FunctionArgs<T> | undefined : FunctionArgs<T>;
661
681
  /**
662
682
  * Decorated mutation procedure with mutationOptions and mutationKey methods.
663
683
  */
@@ -689,54 +709,16 @@ type VanillaQuery<T extends FunctionReference<'query'>> = {
689
709
  query: keyof FunctionArgs<T> extends never ? (args?: EmptyObject) => Promise<FunctionReturnType<T>> : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T>) => Promise<FunctionReturnType<T>> : (args: FunctionArgs<T>) => Promise<FunctionReturnType<T>>;
690
710
  watchQuery: keyof FunctionArgs<T> extends never ? (args?: EmptyObject, opts?: WatchQueryOptions) => Watch<FunctionReturnType<T>> : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T>, opts?: WatchQueryOptions) => Watch<FunctionReturnType<T>> : (args: FunctionArgs<T>, opts?: WatchQueryOptions) => Watch<FunctionReturnType<T>>;
691
711
  };
692
- /** Vanilla mutation - direct .mutate() call without React Query */
693
- type VanillaMutation<T extends FunctionReference<'mutation'>> = {
694
- mutate: keyof FunctionArgs<T> extends never ? (args?: EmptyObject) => Promise<FunctionReturnType<T>> : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T>) => Promise<FunctionReturnType<T>> : (args: FunctionArgs<T>) => Promise<FunctionReturnType<T>>;
695
- };
696
- /** Vanilla action - both .query() and .mutate() for direct calls */
697
- type VanillaAction<T extends FunctionReference<'action'>> = {
698
- query: keyof FunctionArgs<T> extends never ? (args?: EmptyObject) => Promise<FunctionReturnType<T>> : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T>) => Promise<FunctionReturnType<T>> : (args: FunctionArgs<T>) => Promise<FunctionReturnType<T>>;
699
- mutate: keyof FunctionArgs<T> extends never ? (args?: EmptyObject) => Promise<FunctionReturnType<T>> : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T>) => Promise<FunctionReturnType<T>> : (args: FunctionArgs<T>) => Promise<FunctionReturnType<T>>;
700
- };
701
712
  /**
702
713
  * Recursively creates vanilla client type for direct procedural calls.
703
- * Similar to CRPCClient but for imperative usage outside React Query.
704
- *
705
- * @example
706
- * ```ts
707
- * const client = useCRPCClient();
708
- * await client.user.get.query({ id });
709
- * await client.user.update.mutate({ id, name: 'test' });
710
- * ```
711
714
  */
712
715
  type VanillaCRPCClient<TApi> = { [K in keyof TApi as K extends string ? K extends `_${string}` ? never : K : K]: TApi[K] extends FunctionReference<'query'> ? VanillaQuery<TApi[K]> : TApi[K] extends FunctionReference<'mutation'> ? VanillaMutation<TApi[K]> : TApi[K] extends FunctionReference<'action'> ? VanillaAction<TApi[K]> : TApi[K] extends Record<string, unknown> ? VanillaCRPCClient<TApi[K]> : never };
713
716
  /**
714
717
  * Recursively decorates all procedures in a Convex API object.
715
- *
716
- * - Queries get `queryOptions(args, opts?)`
717
- * - Paginated queries also get `infiniteQueryOptions(args, opts)`
718
- * - Mutations get `mutationOptions(opts?)`
719
- * - Actions get `mutationOptions(opts?)`
720
- * - Nested objects are recursively decorated
721
- *
722
- * @example
723
- * ```ts
724
- * type Client = CRPCClient<typeof api>;
725
- * // Client.user.get.queryOptions({ id }) -> QueryOptions
726
- * // Client.posts.list.infiniteQueryOptions({ userId }, { initialNumItems: 20 }) -> InfiniteQueryOptions
727
- * // Client.user.update.mutationOptions() -> MutationOptions
728
- * ```
729
718
  */
730
- /** Check if a type has cursor key (pagination detection) */
731
- type IsPaginated<T> = 'cursor' extends keyof T ? true : false;
732
719
  type CRPCClient<TApi> = { [K in keyof TApi as K extends string ? K extends `_${string}` ? never : K : K]: TApi[K] extends FunctionReference<'query'> ? IsPaginated<FunctionArgs<TApi[K]>> extends true ? DecorateQuery<TApi[K]> & DecorateInfiniteQuery<TApi[K]> : DecorateQuery<TApi[K]> : TApi[K] extends FunctionReference<'mutation'> ? DecorateMutation<TApi[K]> : TApi[K] extends FunctionReference<'action'> ? DecorateAction<TApi[K]> : TApi[K] extends Record<string, unknown> ? CRPCClient<TApi[K]> : never };
733
720
  //#endregion
734
- //#region src/react/http-proxy.d.ts
735
- type HttpRouteInfo = {
736
- path: string;
737
- method: string;
738
- };
739
- type HttpRouteMap = Record<string, HttpRouteInfo>;
721
+ //#region src/crpc/http-client.d.ts
740
722
  /** Form value types (matches Hono's FormValue) */
741
723
  type HttpFormValue = string | Blob;
742
724
  /**
@@ -770,6 +752,13 @@ type HttpClientOptions = {
770
752
  init?: RequestInit; /** Additional headers (or async function returning headers) */
771
753
  headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
772
754
  };
755
+ //#endregion
756
+ //#region src/react/http-proxy.d.ts
757
+ type HttpRouteInfo = {
758
+ path: string;
759
+ method: string;
760
+ };
761
+ type HttpRouteMap = Record<string, HttpRouteInfo>;
773
762
  /** Infer schema type or return empty object if UnsetMarker */
774
763
  type InferSchemaOrEmpty<T> = T extends UnsetMarker ? object : T extends z.ZodTypeAny ? z.infer<T> : object;
775
764
  /** Infer merged input from HttpProcedure (flat - used internally) */
@@ -1260,4 +1249,4 @@ declare function useUploadMutationOptions<TGenerateUrlMutation extends FunctionR
1260
1249
  */
1261
1250
  declare function createVanillaCRPCProxy<TApi extends Record<string, unknown>>(api: TApi, meta: CallerMeta, convexClient: ConvexReactClient$1, transformer?: DataTransformerOptions): VanillaCRPCClient<TApi>;
1262
1251
  //#endregion
1263
- export { AuthMutationError, AuthProvider, AuthStore, AuthStoreState, Authenticated, CRPCHttpOptions, ConvexAuthBridge, ConvexProvider, ConvexProviderWithAuth, ConvexQueryClient, ConvexQueryClientOptions, ConvexQueryClientSingletonOptions, ConvexReactClient, CreateCRPCContextOptions, FetchAccessTokenContext, FetchAccessTokenFn, HttpCRPCClient, HttpCRPCClientFromRouter, HttpClientOptions, HttpFormValue, HttpInputArgs, HttpMutationKey, HttpProxyOptions, HttpQueryKey, HttpRouteInfo, HttpRouteMap, MaybeAuthenticated, MaybeUnauthenticated, PaginationState, PaginationStatus, Unauthenticated, UseInfiniteQueryResult, VanillaHttpCRPCClient, VanillaHttpCRPCClientFromRouter, createAuthMutations, createCRPCContext, createCRPCOptionsProxy, createHttpProxy, createVanillaCRPCProxy, decodeJwtExp, getConvexQueryClientSingleton, getQueryClientSingleton, isAuthMutationError, useAuth, useAuthGuard, useAuthState, useAuthStore, useAuthValue, useConvex, useConvexActionOptions, useConvexActionQueryOptions, useSafeConvexAuth as useConvexAuth, useSafeConvexAuth, useConvexAuthBridge, useConvexInfiniteQueryOptions, useConvexMutationOptions, useConvexQueryClient, useConvexQueryOptions, useFetchAccessToken, useFnMeta, useInfiniteQuery, useIsAuth, useMaybeAuth, useMeta, useUploadMutationOptions };
1252
+ export { AuthMutationError, AuthProvider, AuthStore, AuthStoreState, Authenticated, CRPCHttpOptions, ConvexAuthBridge, ConvexProvider, ConvexProviderWithAuth, ConvexQueryClient, ConvexQueryClientOptions, ConvexQueryClientSingletonOptions, ConvexReactClient, CreateCRPCContextOptions, FetchAccessTokenContext, FetchAccessTokenFn, HttpCRPCClient, HttpCRPCClientFromRouter, type HttpClientOptions, type HttpFormValue, type HttpInputArgs, HttpMutationKey, HttpProxyOptions, HttpQueryKey, HttpRouteInfo, HttpRouteMap, MaybeAuthenticated, MaybeUnauthenticated, PaginationState, PaginationStatus, Unauthenticated, UseInfiniteQueryResult, VanillaHttpCRPCClient, VanillaHttpCRPCClientFromRouter, createAuthMutations, createCRPCContext, createCRPCOptionsProxy, createHttpProxy, createVanillaCRPCProxy, decodeJwtExp, getConvexQueryClientSingleton, getQueryClientSingleton, isAuthMutationError, useAuth, useAuthGuard, useAuthState, useAuthStore, useAuthValue, useConvex, useConvexActionOptions, useConvexActionQueryOptions, useSafeConvexAuth as useConvexAuth, useSafeConvexAuth, useConvexAuthBridge, useConvexInfiniteQueryOptions, useConvexMutationOptions, useConvexQueryClient, useConvexQueryOptions, useFetchAccessToken, useFnMeta, useInfiniteQuery, useIsAuth, useMaybeAuth, useMeta, useUploadMutationOptions };