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.
- package/dist/auth/index.d.ts +6 -6
- package/dist/crpc/index.d.ts +34 -5
- package/dist/crpc/index.js +142 -1
- package/dist/orm/index.js +8 -1
- package/dist/react/index.d.ts +48 -59
- package/dist/react/index.js +119 -101
- package/dist/rsc/index.d.ts +99 -22
- package/dist/rsc/index.js +1 -1
- package/dist/solid/index.d.ts +1221 -0
- package/dist/solid/index.js +2930 -0
- package/dist/types-7bF_8IjP.d.ts +213 -0
- package/package.json +15 -1
- package/dist/types-f53SgpBL.d.ts +0 -221
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { H as CombinedDataTransformer, n as HttpClientError } from "./http-types-BK7FuIcR.js";
|
|
2
|
+
import { FunctionArgs, FunctionReference, FunctionReturnType } from "convex/server";
|
|
3
|
+
|
|
4
|
+
//#region src/crpc/http-client.d.ts
|
|
5
|
+
/** Form value types (matches Hono's FormValue) */
|
|
6
|
+
type HttpFormValue = string | Blob;
|
|
7
|
+
/**
|
|
8
|
+
* Hybrid input args: JSON body fields at root, explicit params/searchParams/form.
|
|
9
|
+
* - JSON body: spread at root level (tRPC-style)
|
|
10
|
+
* - Path params: { params: { id: '123' } }
|
|
11
|
+
* - Query params: { searchParams: { limit: '10' } }
|
|
12
|
+
* - Form data: { form: { file: blob } } - typed via .form() builder
|
|
13
|
+
* - Client options: { headers, fetch, init } - for per-call customization
|
|
14
|
+
*/
|
|
15
|
+
type HttpInputArgs = {
|
|
16
|
+
/** Path parameters (e.g., :id in /users/:id) */params?: Record<string, string>; /** Query string parameters */
|
|
17
|
+
searchParams?: Record<string, string | string[]>; /** Form data body (Content-Type: multipart/form-data) - typed via .form() builder */
|
|
18
|
+
form?: Record<string, HttpFormValue | HttpFormValue[]>; /** Custom fetch function (per-call override) */
|
|
19
|
+
fetch?: typeof fetch; /** Standard RequestInit (per-call override) */
|
|
20
|
+
init?: RequestInit; /** Additional headers (per-call override) */
|
|
21
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>); /** Any other properties are JSON body fields */
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Client request options (matches Hono's ClientRequestOptions).
|
|
26
|
+
* Standard RequestInit in `init` takes highest priority and can override
|
|
27
|
+
* things that are set automatically like body, method, headers.
|
|
28
|
+
*/
|
|
29
|
+
type HttpClientOptions = {
|
|
30
|
+
/** Custom fetch function */fetch?: typeof fetch;
|
|
31
|
+
/**
|
|
32
|
+
* Standard RequestInit - takes highest priority.
|
|
33
|
+
* Can override body, method, headers if needed.
|
|
34
|
+
*/
|
|
35
|
+
init?: RequestInit; /** Additional headers (or async function returning headers) */
|
|
36
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
37
|
+
};
|
|
38
|
+
/** HTTP proxy options (framework-agnostic parts) */
|
|
39
|
+
interface HttpProxyBaseOptions {
|
|
40
|
+
/** Base URL for the Convex HTTP API (e.g., https://your-site.convex.site) */
|
|
41
|
+
convexSiteUrl: string;
|
|
42
|
+
/** Custom fetch function (defaults to global fetch) */
|
|
43
|
+
fetch?: typeof fetch;
|
|
44
|
+
/** Default headers or async function returning headers (for auth tokens) */
|
|
45
|
+
headers?: {
|
|
46
|
+
[key: string]: string | undefined;
|
|
47
|
+
} | (() => {
|
|
48
|
+
[key: string]: string | undefined;
|
|
49
|
+
} | Promise<{
|
|
50
|
+
[key: string]: string | undefined;
|
|
51
|
+
}>);
|
|
52
|
+
/** Error handler called on HTTP errors */
|
|
53
|
+
onError?: (error: HttpClientError) => void;
|
|
54
|
+
}
|
|
55
|
+
/** Reserved keys that are not part of JSON body */
|
|
56
|
+
declare const RESERVED_KEYS: Set<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Replace URL path parameters with actual values.
|
|
59
|
+
* e.g., '/users/:id' with { id: '123' } -> '/users/123'
|
|
60
|
+
*/
|
|
61
|
+
declare function replaceUrlParam(url: string, params: Record<string, string>): string;
|
|
62
|
+
/**
|
|
63
|
+
* Build URLSearchParams from query object.
|
|
64
|
+
* Handles array values as multiple params with same key (like Hono).
|
|
65
|
+
*/
|
|
66
|
+
declare function buildSearchParams(query: Record<string, string | string[]>): URLSearchParams;
|
|
67
|
+
/**
|
|
68
|
+
* Hono-style HTTP request executor.
|
|
69
|
+
* Processes args in the same way as Hono's ClientRequestImpl.fetch().
|
|
70
|
+
*/
|
|
71
|
+
declare function executeHttpRequest(opts: {
|
|
72
|
+
convexSiteUrl: string;
|
|
73
|
+
route: {
|
|
74
|
+
path: string;
|
|
75
|
+
method: string;
|
|
76
|
+
};
|
|
77
|
+
procedureName: string; /** Hono-style input args */
|
|
78
|
+
args?: HttpInputArgs; /** Per-request client options */
|
|
79
|
+
clientOpts?: HttpClientOptions; /** Base headers from proxy config */
|
|
80
|
+
baseHeaders?: {
|
|
81
|
+
[key: string]: string | undefined;
|
|
82
|
+
} | (() => {
|
|
83
|
+
[key: string]: string | undefined;
|
|
84
|
+
} | Promise<{
|
|
85
|
+
[key: string]: string | undefined;
|
|
86
|
+
}>); /** Base fetch from proxy config */
|
|
87
|
+
baseFetch?: typeof fetch; /** Wire transformer for payload serialization. */
|
|
88
|
+
transformer: CombinedDataTransformer;
|
|
89
|
+
}): Promise<unknown>;
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/crpc/types.d.ts
|
|
92
|
+
/** Symbol key for attaching FunctionReference to options (non-serializable) */
|
|
93
|
+
declare const FUNC_REF_SYMBOL: unique symbol;
|
|
94
|
+
/** Options controlled by convexQuery/convexAction factories */
|
|
95
|
+
type ReservedQueryOptions = 'queryKey' | 'queryFn' | 'staleTime';
|
|
96
|
+
/** Options controlled by mutation factories */
|
|
97
|
+
type ReservedMutationOptions = 'mutationFn';
|
|
98
|
+
/** Reserved options controlled by infinite query factories */
|
|
99
|
+
type ReservedInfiniteQueryOptions = 'queryKey' | 'queryFn' | 'staleTime' | 'refetchInterval' | 'refetchOnMount' | 'refetchOnReconnect' | 'refetchOnWindowFocus' | 'persister' | 'placeholderData';
|
|
100
|
+
/** Metadata for a single Convex function */
|
|
101
|
+
type FnMeta = {
|
|
102
|
+
auth?: 'required' | 'optional';
|
|
103
|
+
role?: string;
|
|
104
|
+
rateLimit?: string;
|
|
105
|
+
type?: 'query' | 'mutation' | 'action';
|
|
106
|
+
limit?: number;
|
|
107
|
+
[key: string]: unknown;
|
|
108
|
+
};
|
|
109
|
+
/** Metadata for paginated functions (limit is required) */
|
|
110
|
+
type PaginatedFnMeta = Omit<FnMeta, 'limit'> & {
|
|
111
|
+
limit: number;
|
|
112
|
+
};
|
|
113
|
+
/** Metadata for all Convex functions by namespace.fnName, with _http for HTTP routes */
|
|
114
|
+
type Meta = Record<string, Record<string, FnMeta>> & {
|
|
115
|
+
_http?: Record<string, {
|
|
116
|
+
path: string;
|
|
117
|
+
method: string;
|
|
118
|
+
}>;
|
|
119
|
+
};
|
|
120
|
+
/** Authentication requirement for a Convex function */
|
|
121
|
+
type AuthType = 'required' | 'optional' | undefined;
|
|
122
|
+
/** Query key structure for Convex queries */
|
|
123
|
+
type ConvexQueryKey<T extends FunctionReference<'query'>> = readonly ['convexQuery', string, FunctionArgs<T>];
|
|
124
|
+
/** Query key structure for Convex actions */
|
|
125
|
+
type ConvexActionKey<T extends FunctionReference<'action'>> = readonly ['convexAction', string, FunctionArgs<T>];
|
|
126
|
+
/** Mutation key structure for Convex mutations/actions */
|
|
127
|
+
type ConvexMutationKey = ['convexMutation', string];
|
|
128
|
+
/**
|
|
129
|
+
* Meta passed to TanStack Query for auth and subscription control.
|
|
130
|
+
* Set by convexQuery, read by ConvexQueryClient.queryFn() and subscribeInner().
|
|
131
|
+
*/
|
|
132
|
+
type ConvexQueryMeta = {
|
|
133
|
+
/** Auth type from generated Convex metadata via getMeta() */authType?: 'required' | 'optional'; /** Skip query silently when unauthenticated (returns null) */
|
|
134
|
+
skipUnauth?: boolean; /** Whether to create WebSocket subscription (default: true) */
|
|
135
|
+
subscribe?: boolean;
|
|
136
|
+
};
|
|
137
|
+
/** Hook options for Convex queries */
|
|
138
|
+
type ConvexQueryHookOptions = {
|
|
139
|
+
/** Skip query silently when unauthenticated (default: false, calls onQueryUnauthorized) */skipUnauth?: boolean; /** Set to false to fetch once without subscribing (default: true) */
|
|
140
|
+
subscribe?: boolean;
|
|
141
|
+
};
|
|
142
|
+
/** Internal Convex pagination options (used by .paginate()) */
|
|
143
|
+
type PaginationOpts = {
|
|
144
|
+
cursor: string | null;
|
|
145
|
+
numItems: number;
|
|
146
|
+
endCursor?: string | null;
|
|
147
|
+
id?: number;
|
|
148
|
+
maximumRowsRead?: number;
|
|
149
|
+
maximumBytesRead?: number;
|
|
150
|
+
};
|
|
151
|
+
/** Extract input args without cursor/limit (user's filter args only) */
|
|
152
|
+
type InfiniteQueryInput<TInput> = Omit<TInput, 'cursor' | 'limit'>;
|
|
153
|
+
/** Extract item type from PaginationResult<T> */
|
|
154
|
+
type ExtractPaginatedItem<TOutput> = TOutput extends {
|
|
155
|
+
page: (infer T)[];
|
|
156
|
+
} ? T : never;
|
|
157
|
+
/** Metadata for infinite query (extends ConvexQueryMeta) */
|
|
158
|
+
type ConvexInfiniteQueryMeta = ConvexQueryMeta & {
|
|
159
|
+
/** The query function name (serializable for RSC) */queryName: string; /** Query args without cursor/limit (user's filter args only) */
|
|
160
|
+
args: Record<string, unknown>; /** Items per page (optional - server uses .paginated() default) */
|
|
161
|
+
limit?: number;
|
|
162
|
+
};
|
|
163
|
+
type EmptyObject = Record<string, never>;
|
|
164
|
+
/** Static query options parameter type (non-hook, for event handlers) */
|
|
165
|
+
type StaticQueryOptsParam = {
|
|
166
|
+
skipUnauth?: boolean;
|
|
167
|
+
};
|
|
168
|
+
/** Check if a type has cursor key (pagination detection) */
|
|
169
|
+
type IsPaginated<T> = 'cursor' extends keyof T ? true : false;
|
|
170
|
+
/** Mutation variables type - undefined when no args required (allows mutateAsync() without args) */
|
|
171
|
+
type MutationVariables<T extends FunctionReference<'mutation' | 'action'>> = keyof FunctionArgs<T> extends never ? void : EmptyObject extends FunctionArgs<T> ? FunctionArgs<T> | undefined : FunctionArgs<T>;
|
|
172
|
+
/** Base query options shape returned by convexQuery factory */
|
|
173
|
+
type BaseConvexQueryOptions<T extends FunctionReference<'query'>> = {
|
|
174
|
+
queryKey: ConvexQueryKey<T>;
|
|
175
|
+
staleTime?: number;
|
|
176
|
+
enabled?: unknown;
|
|
177
|
+
};
|
|
178
|
+
/** Base action options shape returned by convexAction factory */
|
|
179
|
+
type BaseConvexActionOptions<T extends FunctionReference<'action'>> = {
|
|
180
|
+
queryKey: ConvexActionKey<T>;
|
|
181
|
+
staleTime?: number;
|
|
182
|
+
enabled?: unknown;
|
|
183
|
+
};
|
|
184
|
+
/** Base infinite query options parameter */
|
|
185
|
+
type BaseInfiniteQueryOptsParam<T extends FunctionReference<'query'> = FunctionReference<'query'>> = {
|
|
186
|
+
/** Items per page. Optional - server uses .paginated() default if not provided. */limit?: number; /** Skip query silently when unauthenticated */
|
|
187
|
+
skipUnauth?: boolean; /** Placeholder data shown while loading (item array, not pagination result) */
|
|
188
|
+
placeholderData?: ExtractPaginatedItem<FunctionReturnType<T>>[]; /** Whether the query is enabled */
|
|
189
|
+
enabled?: unknown;
|
|
190
|
+
};
|
|
191
|
+
/** Base infinite query options shape */
|
|
192
|
+
type BaseConvexInfiniteQueryOptions<T extends FunctionReference<'query'>> = {
|
|
193
|
+
queryKey: ConvexQueryKey<T>;
|
|
194
|
+
staleTime?: number;
|
|
195
|
+
enabled?: unknown;
|
|
196
|
+
meta: ConvexInfiniteQueryMeta;
|
|
197
|
+
refetchInterval: false;
|
|
198
|
+
refetchOnMount: false;
|
|
199
|
+
refetchOnReconnect: false;
|
|
200
|
+
refetchOnWindowFocus: false; /** Placeholder data shown while loading (item array, not pagination result) */
|
|
201
|
+
placeholderData?: ExtractPaginatedItem<FunctionReturnType<T>>[];
|
|
202
|
+
};
|
|
203
|
+
/** Vanilla mutation - direct .mutate() call without TanStack Query */
|
|
204
|
+
type VanillaMutation<T extends FunctionReference<'mutation'>> = {
|
|
205
|
+
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>>;
|
|
206
|
+
};
|
|
207
|
+
/** Vanilla action - both .query() and .mutate() for direct calls */
|
|
208
|
+
type VanillaAction<T extends FunctionReference<'action'>> = {
|
|
209
|
+
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>>;
|
|
210
|
+
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>>;
|
|
211
|
+
};
|
|
212
|
+
//#endregion
|
|
213
|
+
export { HttpInputArgs as A, ReservedMutationOptions as C, VanillaMutation as D, VanillaAction as E, replaceUrlParam as F, RESERVED_KEYS as M, buildSearchParams as N, HttpClientOptions as O, executeHttpRequest as P, ReservedInfiniteQueryOptions as S, StaticQueryOptsParam as T, IsPaginated as _, BaseInfiniteQueryOptsParam as a, PaginatedFnMeta as b, ConvexMutationKey as c, ConvexQueryMeta as d, EmptyObject as f, InfiniteQueryInput as g, FnMeta as h, BaseConvexQueryOptions as i, HttpProxyBaseOptions as j, HttpFormValue as k, ConvexQueryHookOptions as l, FUNC_REF_SYMBOL as m, BaseConvexActionOptions as n, ConvexActionKey as o, ExtractPaginatedItem as p, BaseConvexInfiniteQueryOptions as r, ConvexInfiniteQueryMeta as s, AuthType as t, ConvexQueryKey as u, Meta as v, ReservedQueryOptions as w, PaginationOpts as x, MutationVariables as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-convex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Better Convex - React Query integration and CLI tools for Convex",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"convex",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"./react": "./dist/react/index.js",
|
|
27
27
|
"./rsc": "./dist/rsc/index.js",
|
|
28
28
|
"./server": "./dist/server/index.js",
|
|
29
|
+
"./solid": "./dist/solid/index.js",
|
|
29
30
|
"./package.json": "./package.json"
|
|
30
31
|
},
|
|
31
32
|
"bin": {
|
|
@@ -59,18 +60,28 @@
|
|
|
59
60
|
"devDependencies": {
|
|
60
61
|
"@rollup/plugin-babel": "^6.1.0",
|
|
61
62
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
63
|
+
"rolldown-plugin-solid": "^0.2.1",
|
|
62
64
|
"tsdown": "^0.20.3"
|
|
63
65
|
},
|
|
64
66
|
"peerDependencies": {
|
|
67
|
+
"@tanstack/query-core": ">=5",
|
|
65
68
|
"@tanstack/react-query": ">=5",
|
|
69
|
+
"@tanstack/solid-query": ">=5",
|
|
66
70
|
"better-auth": ">=1.4.9",
|
|
67
71
|
"convex": ">=1.32",
|
|
68
72
|
"hono": ">=4",
|
|
69
73
|
"next": ">=14",
|
|
70
74
|
"react": ">=18",
|
|
75
|
+
"solid-js": ">=1.8",
|
|
71
76
|
"zod": ">=4"
|
|
72
77
|
},
|
|
73
78
|
"peerDependenciesMeta": {
|
|
79
|
+
"@tanstack/react-query": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"@tanstack/solid-query": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
74
85
|
"better-auth": {
|
|
75
86
|
"optional": true
|
|
76
87
|
},
|
|
@@ -82,6 +93,9 @@
|
|
|
82
93
|
},
|
|
83
94
|
"react": {
|
|
84
95
|
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"solid-js": {
|
|
98
|
+
"optional": true
|
|
85
99
|
}
|
|
86
100
|
},
|
|
87
101
|
"publishConfig": {
|
package/dist/types-f53SgpBL.d.ts
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { n as DeepPartial, o as Simplify, r as DistributiveOmit } from "./types-BTb_4BaU.js";
|
|
2
|
-
import { FunctionArgs, FunctionReference, FunctionReturnType } from "convex/server";
|
|
3
|
-
import { DefaultError, QueryFilters, SkipToken, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
4
|
-
import { Watch, WatchQueryOptions } from "convex/react";
|
|
5
|
-
|
|
6
|
-
//#region src/crpc/types.d.ts
|
|
7
|
-
/** Symbol key for attaching FunctionReference to options (non-serializable) */
|
|
8
|
-
declare const FUNC_REF_SYMBOL: unique symbol;
|
|
9
|
-
/** Options controlled by convexQuery/convexAction factories */
|
|
10
|
-
type ReservedQueryOptions = 'queryKey' | 'queryFn' | 'staleTime';
|
|
11
|
-
/** Options controlled by mutation factories */
|
|
12
|
-
type ReservedMutationOptions = 'mutationFn';
|
|
13
|
-
/** Metadata for a single Convex function */
|
|
14
|
-
type FnMeta = {
|
|
15
|
-
auth?: 'required' | 'optional';
|
|
16
|
-
role?: string;
|
|
17
|
-
rateLimit?: string;
|
|
18
|
-
type?: 'query' | 'mutation' | 'action';
|
|
19
|
-
limit?: number;
|
|
20
|
-
[key: string]: unknown;
|
|
21
|
-
};
|
|
22
|
-
/** Metadata for paginated functions (limit is required) */
|
|
23
|
-
type PaginatedFnMeta = Omit<FnMeta, 'limit'> & {
|
|
24
|
-
limit: number;
|
|
25
|
-
};
|
|
26
|
-
/** Metadata for all Convex functions by namespace.fnName, with _http for HTTP routes */
|
|
27
|
-
type Meta = Record<string, Record<string, FnMeta>> & {
|
|
28
|
-
_http?: Record<string, {
|
|
29
|
-
path: string;
|
|
30
|
-
method: string;
|
|
31
|
-
}>;
|
|
32
|
-
};
|
|
33
|
-
/** Authentication requirement for a Convex function */
|
|
34
|
-
type AuthType = 'required' | 'optional' | undefined;
|
|
35
|
-
/** Query key structure for Convex queries */
|
|
36
|
-
type ConvexQueryKey<T extends FunctionReference<'query'>> = readonly ['convexQuery', string, FunctionArgs<T>];
|
|
37
|
-
/** Query key structure for Convex actions */
|
|
38
|
-
type ConvexActionKey<T extends FunctionReference<'action'>> = readonly ['convexAction', string, FunctionArgs<T>];
|
|
39
|
-
/** Mutation key structure for Convex mutations/actions */
|
|
40
|
-
type ConvexMutationKey = ['convexMutation', string];
|
|
41
|
-
/**
|
|
42
|
-
* Meta passed to TanStack Query for auth and subscription control.
|
|
43
|
-
* Set by convexQuery, read by ConvexQueryClient.queryFn() and subscribeInner().
|
|
44
|
-
*/
|
|
45
|
-
type ConvexQueryMeta = {
|
|
46
|
-
/** Auth type from generated Convex metadata via getMeta() */authType?: 'required' | 'optional'; /** Skip query silently when unauthenticated (returns null) */
|
|
47
|
-
skipUnauth?: boolean; /** Whether to create WebSocket subscription (default: true) */
|
|
48
|
-
subscribe?: boolean;
|
|
49
|
-
};
|
|
50
|
-
/** Options returned by `convexQuery` factory */
|
|
51
|
-
type ConvexQueryOptions<T extends FunctionReference<'query'>> = Pick<UseQueryOptions<FunctionReturnType<T>, Error, FunctionReturnType<T>, ConvexQueryKey<T>>, 'queryKey' | 'staleTime' | 'enabled'>;
|
|
52
|
-
/** Options returned by `convexAction` factory */
|
|
53
|
-
type ConvexActionOptions<T extends FunctionReference<'action'>> = Pick<UseQueryOptions<FunctionReturnType<T>, Error, FunctionReturnType<T>, ConvexActionKey<T>>, 'queryKey' | 'staleTime' | 'enabled'>;
|
|
54
|
-
/** Hook options for Convex queries */
|
|
55
|
-
type ConvexQueryHookOptions = {
|
|
56
|
-
/** Skip query silently when unauthenticated (default: false, calls onQueryUnauthorized) */skipUnauth?: boolean; /** Set to false to fetch once without subscribing (default: true) */
|
|
57
|
-
subscribe?: boolean;
|
|
58
|
-
};
|
|
59
|
-
/** Internal Convex pagination options (used by .paginate()) */
|
|
60
|
-
type PaginationOpts = {
|
|
61
|
-
cursor: string | null;
|
|
62
|
-
numItems: number;
|
|
63
|
-
endCursor?: string | null;
|
|
64
|
-
id?: number;
|
|
65
|
-
maximumRowsRead?: number;
|
|
66
|
-
maximumBytesRead?: number;
|
|
67
|
-
};
|
|
68
|
-
/** Extract input args without cursor/limit (user's filter args only) */
|
|
69
|
-
type InfiniteQueryInput<TInput> = Omit<TInput, 'cursor' | 'limit'>;
|
|
70
|
-
/** Extract item type from PaginationResult<T> */
|
|
71
|
-
type ExtractPaginatedItem<TOutput> = TOutput extends {
|
|
72
|
-
page: (infer T)[];
|
|
73
|
-
} ? T : never;
|
|
74
|
-
type EmptyObject = Record<string, never>;
|
|
75
|
-
/** Query options parameter type */
|
|
76
|
-
type QueryOptsParam<T extends FunctionReference<'query'>> = Simplify<ConvexQueryHookOptions & DistributiveOmit<UseQueryOptions<FunctionReturnType<T>, DefaultError>, ReservedQueryOptions>>;
|
|
77
|
-
/** Query options return type */
|
|
78
|
-
type QueryOptsReturn<T extends FunctionReference<'query'>> = ConvexQueryOptions<T> & {
|
|
79
|
-
meta: ConvexQueryMeta;
|
|
80
|
-
};
|
|
81
|
-
/** Action query options parameter type (actions don't support subscriptions) */
|
|
82
|
-
type ActionQueryOptsParam<T extends FunctionReference<'action'>> = DistributiveOmit<UseQueryOptions<FunctionReturnType<T>, DefaultError>, ReservedQueryOptions>;
|
|
83
|
-
/** Action query options return type */
|
|
84
|
-
type ActionQueryOptsReturn<T extends FunctionReference<'action'>> = ConvexActionOptions<T>;
|
|
85
|
-
/**
|
|
86
|
-
* Decorated query procedure with queryOptions, queryKey, and queryFilter methods.
|
|
87
|
-
* Args are optional when the function has no required parameters.
|
|
88
|
-
* Supports skipToken for type-safe conditional queries.
|
|
89
|
-
*/
|
|
90
|
-
/** Static query options parameter type (non-hook, for event handlers) */
|
|
91
|
-
type StaticQueryOptsParam = {
|
|
92
|
-
skipUnauth?: boolean;
|
|
93
|
-
};
|
|
94
|
-
type DecorateQuery<T extends FunctionReference<'query'>> = {
|
|
95
|
-
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 */
|
|
96
|
-
staticQueryOptions: keyof FunctionArgs<T> extends never ? (args?: EmptyObject | SkipToken, opts?: StaticQueryOptsParam) => ConvexQueryOptions<T> & {
|
|
97
|
-
meta: ConvexQueryMeta;
|
|
98
|
-
} : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T> | SkipToken, opts?: StaticQueryOptsParam) => ConvexQueryOptions<T> & {
|
|
99
|
-
meta: ConvexQueryMeta;
|
|
100
|
-
} : (args: FunctionArgs<T> | SkipToken, opts?: StaticQueryOptsParam) => ConvexQueryOptions<T> & {
|
|
101
|
-
meta: ConvexQueryMeta;
|
|
102
|
-
}; /** Get query key for QueryClient methods (setQueryData, getQueryData, etc.) */
|
|
103
|
-
queryKey: (args?: DeepPartial<FunctionArgs<T>>) => ConvexQueryKey<T>; /** Get query filter for QueryClient methods (invalidateQueries, removeQueries, etc.) */
|
|
104
|
-
queryFilter: (args?: DeepPartial<FunctionArgs<T>>, filters?: DistributiveOmit<QueryFilters, 'queryKey'>) => QueryFilters;
|
|
105
|
-
};
|
|
106
|
-
/** Reserved options controlled by infinite query factories */
|
|
107
|
-
type ReservedInfiniteQueryOptions = 'queryKey' | 'queryFn' | 'staleTime' | 'refetchInterval' | 'refetchOnMount' | 'refetchOnReconnect' | 'refetchOnWindowFocus' | 'persister' | 'placeholderData';
|
|
108
|
-
/** Options for infinite query - extends TanStack Query options */
|
|
109
|
-
type InfiniteQueryOptsParam<T extends FunctionReference<'query'> = FunctionReference<'query'>> = {
|
|
110
|
-
/** Items per page. Optional - server uses .paginated() default if not provided. */limit?: number; /** Skip query silently when unauthenticated */
|
|
111
|
-
skipUnauth?: boolean; /** Placeholder data shown while loading (item array, not pagination result) */
|
|
112
|
-
placeholderData?: ExtractPaginatedItem<FunctionReturnType<T>>[];
|
|
113
|
-
} & DistributiveOmit<UseQueryOptions<FunctionReturnType<T>, DefaultError>, ReservedInfiniteQueryOptions>;
|
|
114
|
-
/** Metadata for infinite query (extends ConvexQueryMeta) */
|
|
115
|
-
type ConvexInfiniteQueryMeta = ConvexQueryMeta & {
|
|
116
|
-
/** The query function name (serializable for RSC) */queryName: string; /** Query args without cursor/limit (user's filter args only) */
|
|
117
|
-
args: Record<string, unknown>; /** Items per page (optional - server uses .paginated() default) */
|
|
118
|
-
limit?: number;
|
|
119
|
-
};
|
|
120
|
-
/** Return type of infiniteQueryOptions - compatible with TanStack prefetch */
|
|
121
|
-
type ConvexInfiniteQueryOptions<T extends FunctionReference<'query'>> = Pick<UseQueryOptions<FunctionReturnType<T>, Error, FunctionReturnType<T>, ConvexQueryKey<T>>, 'queryKey' | 'staleTime' | 'enabled'> & {
|
|
122
|
-
meta: ConvexInfiniteQueryMeta;
|
|
123
|
-
refetchInterval: false;
|
|
124
|
-
refetchOnMount: false;
|
|
125
|
-
refetchOnReconnect: false;
|
|
126
|
-
refetchOnWindowFocus: false; /** Placeholder data shown while loading (item array, not pagination result) */
|
|
127
|
-
placeholderData?: ExtractPaginatedItem<FunctionReturnType<T>>[];
|
|
128
|
-
} & DistributiveOmit<UseQueryOptions<FunctionReturnType<T>, DefaultError>, ReservedInfiniteQueryOptions>;
|
|
129
|
-
/** Infinite query options with attached function reference (client-only) */
|
|
130
|
-
type ConvexInfiniteQueryOptionsWithRef<T extends FunctionReference<'query'>> = ConvexInfiniteQueryOptions<T> & {
|
|
131
|
-
[FUNC_REF_SYMBOL]: T;
|
|
132
|
-
};
|
|
133
|
-
/** Infinite query options return type */
|
|
134
|
-
type InfiniteQueryOptsReturn<T extends FunctionReference<'query'>> = ConvexInfiniteQueryOptionsWithRef<T>;
|
|
135
|
-
/**
|
|
136
|
-
* Decorated infinite query procedure.
|
|
137
|
-
* Only available on queries that have cursor/limit in their input (paginated).
|
|
138
|
-
* Supports skipToken for conditional queries.
|
|
139
|
-
* Args are optional when the function has no required parameters (besides cursor/limit).
|
|
140
|
-
*/
|
|
141
|
-
type DecorateInfiniteQuery<T extends FunctionReference<'query'>> = {
|
|
142
|
-
/** Create infinite query options for useInfiniteQuery and prefetch */infiniteQueryOptions: keyof InfiniteQueryInput<FunctionArgs<T>> extends never ? (args?: EmptyObject | SkipToken, opts?: InfiniteQueryOptsParam<T>) => InfiniteQueryOptsReturn<T> : EmptyObject extends InfiniteQueryInput<FunctionArgs<T>> ? (args?: InfiniteQueryInput<FunctionArgs<T>> | SkipToken, opts?: InfiniteQueryOptsParam<T>) => InfiniteQueryOptsReturn<T> : (args: InfiniteQueryInput<FunctionArgs<T>> | SkipToken, opts?: InfiniteQueryOptsParam<T>) => InfiniteQueryOptsReturn<T>; /** Get query key for infinite query (QueryClient methods like setQueryData, getQueryData) */
|
|
143
|
-
infiniteQueryKey: (args?: DeepPartial<InfiniteQueryInput<FunctionArgs<T>>>) => ConvexQueryKey<T>; /** Function metadata from server (auth, limit, rateLimit, role, type) */
|
|
144
|
-
meta: PaginatedFnMeta;
|
|
145
|
-
};
|
|
146
|
-
/** Mutation variables type - undefined when no args required (allows mutateAsync() without args) */
|
|
147
|
-
type MutationVariables<T extends FunctionReference<'mutation' | 'action'>> = keyof FunctionArgs<T> extends never ? void : EmptyObject extends FunctionArgs<T> ? FunctionArgs<T> | undefined : FunctionArgs<T>;
|
|
148
|
-
/**
|
|
149
|
-
* Decorated mutation procedure with mutationOptions and mutationKey methods.
|
|
150
|
-
*/
|
|
151
|
-
type DecorateMutation<T extends FunctionReference<'mutation'>> = {
|
|
152
|
-
mutationOptions: (opts?: DistributiveOmit<UseMutationOptions<FunctionReturnType<T>, DefaultError, MutationVariables<T>>, ReservedMutationOptions>) => UseMutationOptions<FunctionReturnType<T>, DefaultError, MutationVariables<T>>; /** Get mutation key for QueryClient methods */
|
|
153
|
-
mutationKey: () => ConvexMutationKey;
|
|
154
|
-
};
|
|
155
|
-
/**
|
|
156
|
-
* Decorated action procedure with queryOptions, mutationOptions, and key methods.
|
|
157
|
-
* Actions can be used as one-shot queries (no subscription) or as mutations.
|
|
158
|
-
* Supports skipToken for conditional queries.
|
|
159
|
-
*/
|
|
160
|
-
type DecorateAction<T extends FunctionReference<'action'>> = {
|
|
161
|
-
/** Use action as a one-shot query (no WebSocket subscription) */queryOptions: keyof FunctionArgs<T> extends never ? (args?: EmptyObject | SkipToken, opts?: ActionQueryOptsParam<T>) => ActionQueryOptsReturn<T> : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T> | SkipToken, opts?: ActionQueryOptsParam<T>) => ActionQueryOptsReturn<T> : (args: FunctionArgs<T> | SkipToken, opts?: ActionQueryOptsParam<T>) => ActionQueryOptsReturn<T>; /** Static (non-hook) action query options for event handlers and prefetching */
|
|
162
|
-
staticQueryOptions: keyof FunctionArgs<T> extends never ? (args?: EmptyObject | SkipToken, opts?: StaticQueryOptsParam) => ConvexActionOptions<T> & {
|
|
163
|
-
meta: ConvexQueryMeta;
|
|
164
|
-
} : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T> | SkipToken, opts?: StaticQueryOptsParam) => ConvexActionOptions<T> & {
|
|
165
|
-
meta: ConvexQueryMeta;
|
|
166
|
-
} : (args: FunctionArgs<T> | SkipToken, opts?: StaticQueryOptsParam) => ConvexActionOptions<T> & {
|
|
167
|
-
meta: ConvexQueryMeta;
|
|
168
|
-
}; /** Use action as a mutation */
|
|
169
|
-
mutationOptions: (opts?: DistributiveOmit<UseMutationOptions<FunctionReturnType<T>, DefaultError, MutationVariables<T>>, ReservedMutationOptions>) => UseMutationOptions<FunctionReturnType<T>, DefaultError, MutationVariables<T>>; /** Get mutation key for QueryClient methods */
|
|
170
|
-
mutationKey: () => ConvexMutationKey; /** Get query key for QueryClient methods */
|
|
171
|
-
queryKey: (args?: DeepPartial<FunctionArgs<T>>) => ConvexActionKey<T>; /** Get query filter for QueryClient methods */
|
|
172
|
-
queryFilter: (args?: DeepPartial<FunctionArgs<T>>, filters?: DistributiveOmit<QueryFilters, 'queryKey'>) => QueryFilters;
|
|
173
|
-
};
|
|
174
|
-
/** Vanilla query - direct .query() and .watchQuery() calls without React Query */
|
|
175
|
-
type VanillaQuery<T extends FunctionReference<'query'>> = {
|
|
176
|
-
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>>;
|
|
177
|
-
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>>;
|
|
178
|
-
};
|
|
179
|
-
/** Vanilla mutation - direct .mutate() call without React Query */
|
|
180
|
-
type VanillaMutation<T extends FunctionReference<'mutation'>> = {
|
|
181
|
-
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>>;
|
|
182
|
-
};
|
|
183
|
-
/** Vanilla action - both .query() and .mutate() for direct calls */
|
|
184
|
-
type VanillaAction<T extends FunctionReference<'action'>> = {
|
|
185
|
-
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>>;
|
|
186
|
-
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>>;
|
|
187
|
-
};
|
|
188
|
-
/**
|
|
189
|
-
* Recursively creates vanilla client type for direct procedural calls.
|
|
190
|
-
* Similar to CRPCClient but for imperative usage outside React Query.
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* ```ts
|
|
194
|
-
* const client = useCRPCClient();
|
|
195
|
-
* await client.user.get.query({ id });
|
|
196
|
-
* await client.user.update.mutate({ id, name: 'test' });
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
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 };
|
|
200
|
-
/**
|
|
201
|
-
* Recursively decorates all procedures in a Convex API object.
|
|
202
|
-
*
|
|
203
|
-
* - Queries get `queryOptions(args, opts?)`
|
|
204
|
-
* - Paginated queries also get `infiniteQueryOptions(args, opts)`
|
|
205
|
-
* - Mutations get `mutationOptions(opts?)`
|
|
206
|
-
* - Actions get `mutationOptions(opts?)`
|
|
207
|
-
* - Nested objects are recursively decorated
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* ```ts
|
|
211
|
-
* type Client = CRPCClient<typeof api>;
|
|
212
|
-
* // Client.user.get.queryOptions({ id }) -> QueryOptions
|
|
213
|
-
* // Client.posts.list.infiniteQueryOptions({ userId }, { initialNumItems: 20 }) -> InfiniteQueryOptions
|
|
214
|
-
* // Client.user.update.mutationOptions() -> MutationOptions
|
|
215
|
-
* ```
|
|
216
|
-
*/
|
|
217
|
-
/** Check if a type has cursor key (pagination detection) */
|
|
218
|
-
type IsPaginated<T> = 'cursor' extends keyof T ? true : false;
|
|
219
|
-
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 };
|
|
220
|
-
//#endregion
|
|
221
|
-
export { PaginatedFnMeta as C, VanillaMutation as D, VanillaCRPCClient as E, VanillaQuery as O, Meta as S, VanillaAction as T, ExtractPaginatedItem as _, ConvexInfiniteQueryMeta as a, InfiniteQueryInput as b, ConvexMutationKey as c, ConvexQueryMeta as d, ConvexQueryOptions as f, DecorateQuery as g, DecorateMutation as h, ConvexActionOptions as i, ConvexQueryHookOptions as l, DecorateInfiniteQuery as m, CRPCClient as n, ConvexInfiniteQueryOptions as o, DecorateAction as p, ConvexActionKey as r, ConvexInfiniteQueryOptionsWithRef as s, AuthType as t, ConvexQueryKey as u, FUNC_REF_SYMBOL as v, PaginationOpts as w, InfiniteQueryOptsParam as x, FnMeta as y };
|