kitcn 0.0.1 → 0.12.1

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.
Files changed (93) hide show
  1. package/bin/intent.js +3 -0
  2. package/dist/aggregate/index.d.ts +388 -0
  3. package/dist/aggregate/index.js +37 -0
  4. package/dist/api-entry-BckXqaLb.js +66 -0
  5. package/dist/auth/client/index.d.ts +37 -0
  6. package/dist/auth/client/index.js +217 -0
  7. package/dist/auth/config/index.d.ts +45 -0
  8. package/dist/auth/config/index.js +24 -0
  9. package/dist/auth/generated/index.d.ts +2 -0
  10. package/dist/auth/generated/index.js +3 -0
  11. package/dist/auth/http/index.d.ts +64 -0
  12. package/dist/auth/http/index.js +461 -0
  13. package/dist/auth/index.d.ts +221 -0
  14. package/dist/auth/index.js +1398 -0
  15. package/dist/auth/nextjs/index.d.ts +50 -0
  16. package/dist/auth/nextjs/index.js +81 -0
  17. package/dist/auth-store-Cljlmdmi.js +197 -0
  18. package/dist/builder-CBdG5W6A.js +1974 -0
  19. package/dist/caller-factory-cTXNvYdz.js +216 -0
  20. package/dist/cli.mjs +13264 -0
  21. package/dist/codegen-lF80HSWu.mjs +3416 -0
  22. package/dist/context-utils-HPC5nXzx.d.ts +17 -0
  23. package/dist/create-schema-odyF4kCy.js +156 -0
  24. package/dist/create-schema-orm-DOyiNDCx.js +246 -0
  25. package/dist/crpc/index.d.ts +105 -0
  26. package/dist/crpc/index.js +169 -0
  27. package/dist/customFunctions-C0voKmtx.js +144 -0
  28. package/dist/error-BZEnI7Sq.js +41 -0
  29. package/dist/generated-contract-disabled-Cih4eITO.js +50 -0
  30. package/dist/generated-contract-disabled-D-sOFy92.d.ts +354 -0
  31. package/dist/http-types-DqJubRPJ.d.ts +292 -0
  32. package/dist/meta-utils-0Pu0Nrap.js +117 -0
  33. package/dist/middleware-BUybuv9n.d.ts +34 -0
  34. package/dist/middleware-C2qTZ3V7.js +84 -0
  35. package/dist/orm/index.d.ts +17 -0
  36. package/dist/orm/index.js +10713 -0
  37. package/dist/plugins/index.d.ts +2 -0
  38. package/dist/plugins/index.js +3 -0
  39. package/dist/procedure-caller-DtxLmGwA.d.ts +1467 -0
  40. package/dist/procedure-caller-MWcxhQDv.js +349 -0
  41. package/dist/query-context-B8o6-8kC.js +1518 -0
  42. package/dist/query-context-CFZqIvD7.d.ts +42 -0
  43. package/dist/query-options-Dw7cOyXl.js +121 -0
  44. package/dist/ratelimit/index.d.ts +269 -0
  45. package/dist/ratelimit/index.js +856 -0
  46. package/dist/ratelimit/react/index.d.ts +76 -0
  47. package/dist/ratelimit/react/index.js +183 -0
  48. package/dist/react/index.d.ts +1284 -0
  49. package/dist/react/index.js +2526 -0
  50. package/dist/rsc/index.d.ts +276 -0
  51. package/dist/rsc/index.js +233 -0
  52. package/dist/runtime-CtvJPkur.js +2453 -0
  53. package/dist/server/index.d.ts +5 -0
  54. package/dist/server/index.js +6 -0
  55. package/dist/solid/index.d.ts +1221 -0
  56. package/dist/solid/index.js +2940 -0
  57. package/dist/transformer-DtDhR3Lc.js +194 -0
  58. package/dist/types-BTb_4BaU.d.ts +42 -0
  59. package/dist/types-BiJE7qxR.d.ts +4 -0
  60. package/dist/types-DEJpkIhw.d.ts +88 -0
  61. package/dist/types-HhO_R6pd.d.ts +213 -0
  62. package/dist/validators-B7oIJCAp.js +279 -0
  63. package/dist/validators-vzRKjBJC.d.ts +88 -0
  64. package/dist/watcher.mjs +96 -0
  65. package/dist/where-clause-compiler-DdjN63Io.d.ts +4756 -0
  66. package/package.json +107 -34
  67. package/skills/convex/SKILL.md +486 -0
  68. package/skills/convex/references/features/aggregates.md +353 -0
  69. package/skills/convex/references/features/auth-admin.md +446 -0
  70. package/skills/convex/references/features/auth-organizations.md +1141 -0
  71. package/skills/convex/references/features/auth-polar.md +579 -0
  72. package/skills/convex/references/features/auth.md +470 -0
  73. package/skills/convex/references/features/create-plugins.md +153 -0
  74. package/skills/convex/references/features/http.md +676 -0
  75. package/skills/convex/references/features/migrations.md +162 -0
  76. package/skills/convex/references/features/orm.md +1166 -0
  77. package/skills/convex/references/features/react.md +657 -0
  78. package/skills/convex/references/features/scheduling.md +267 -0
  79. package/skills/convex/references/features/testing.md +209 -0
  80. package/skills/convex/references/setup/auth.md +501 -0
  81. package/skills/convex/references/setup/biome.md +190 -0
  82. package/skills/convex/references/setup/doc-guidelines.md +145 -0
  83. package/skills/convex/references/setup/index.md +761 -0
  84. package/skills/convex/references/setup/next.md +116 -0
  85. package/skills/convex/references/setup/react.md +175 -0
  86. package/skills/convex/references/setup/server.md +473 -0
  87. package/skills/convex/references/setup/start.md +67 -0
  88. package/LICENSE +0 -21
  89. package/README.md +0 -0
  90. package/dist/index.d.mts +0 -5
  91. package/dist/index.d.mts.map +0 -1
  92. package/dist/index.mjs +0 -6
  93. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,276 @@
1
+ import { n as DeepPartial, o as Simplify, r as DistributiveOmit } from "../types-BTb_4BaU.js";
2
+ import { C as HttpProcedure, d as CRPCHttpRouter, j as DataTransformerOptions, p as HttpRouterRecord } from "../http-types-DqJubRPJ.js";
3
+ import { m as UnsetMarker } from "../types-DEJpkIhw.js";
4
+ 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-HhO_R6pd.js";
5
+ import { FunctionArgs, FunctionReference, FunctionReturnType } from "convex/server";
6
+ import { z } from "zod";
7
+ import { DefaultError, QueryFilters, SkipToken, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
8
+
9
+ //#region src/react/crpc-types.d.ts
10
+ /** Options returned by `convexQuery` factory */
11
+ type ConvexQueryOptions<T extends FunctionReference<'query'>> = Pick<UseQueryOptions<FunctionReturnType<T>, Error, FunctionReturnType<T>, ConvexQueryKey<T>>, 'queryKey' | 'staleTime' | 'enabled'>;
12
+ /** Options returned by `convexAction` factory */
13
+ type ConvexActionOptions<T extends FunctionReference<'action'>> = Pick<UseQueryOptions<FunctionReturnType<T>, Error, FunctionReturnType<T>, ConvexActionKey<T>>, 'queryKey' | 'staleTime' | 'enabled'>;
14
+ /** Query options parameter type */
15
+ type QueryOptsParam<T extends FunctionReference<'query'>> = Simplify<ConvexQueryHookOptions & DistributiveOmit<UseQueryOptions<FunctionReturnType<T>, DefaultError>, ReservedQueryOptions$1>>;
16
+ /** Query options return type */
17
+ type QueryOptsReturn<T extends FunctionReference<'query'>> = ConvexQueryOptions<T> & {
18
+ meta: ConvexQueryMeta;
19
+ };
20
+ /** Action query options parameter type (actions don't support subscriptions) */
21
+ type ActionQueryOptsParam<T extends FunctionReference<'action'>> = DistributiveOmit<UseQueryOptions<FunctionReturnType<T>, DefaultError>, ReservedQueryOptions$1>;
22
+ /** Action query options return type */
23
+ type ActionQueryOptsReturn<T extends FunctionReference<'action'>> = ConvexActionOptions<T>;
24
+ /**
25
+ * Decorated query procedure with queryOptions, queryKey, and queryFilter methods.
26
+ * Args are optional when the function has no required parameters.
27
+ * Supports skipToken for type-safe conditional queries.
28
+ */
29
+ type DecorateQuery<T extends FunctionReference<'query'>> = {
30
+ 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 */
31
+ staticQueryOptions: keyof FunctionArgs<T> extends never ? (args?: EmptyObject | SkipToken, opts?: StaticQueryOptsParam) => ConvexQueryOptions<T> & {
32
+ meta: ConvexQueryMeta;
33
+ } : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T> | SkipToken, opts?: StaticQueryOptsParam) => ConvexQueryOptions<T> & {
34
+ meta: ConvexQueryMeta;
35
+ } : (args: FunctionArgs<T> | SkipToken, opts?: StaticQueryOptsParam) => ConvexQueryOptions<T> & {
36
+ meta: ConvexQueryMeta;
37
+ }; /** Get query key for QueryClient methods (setQueryData, getQueryData, etc.) */
38
+ queryKey: (args?: DeepPartial<FunctionArgs<T>>) => ConvexQueryKey<T>; /** Get query filter for QueryClient methods (invalidateQueries, removeQueries, etc.) */
39
+ queryFilter: (args?: DeepPartial<FunctionArgs<T>>, filters?: DistributiveOmit<QueryFilters, 'queryKey'>) => QueryFilters;
40
+ };
41
+ /** Options for infinite query - extends TanStack Query options */
42
+ type InfiniteQueryOptsParam<T extends FunctionReference<'query'> = FunctionReference<'query'>> = {
43
+ /** Items per page. Optional - server uses .paginated() default if not provided. */limit?: number; /** Skip query silently when unauthenticated */
44
+ skipUnauth?: boolean; /** Placeholder data shown while loading (item array, not pagination result) */
45
+ placeholderData?: ExtractPaginatedItem<FunctionReturnType<T>>[];
46
+ } & DistributiveOmit<UseQueryOptions<FunctionReturnType<T>, DefaultError>, ReservedInfiniteQueryOptions>;
47
+ /** Return type of infiniteQueryOptions - compatible with TanStack prefetch */
48
+ type ConvexInfiniteQueryOptions<T extends FunctionReference<'query'>> = Pick<UseQueryOptions<FunctionReturnType<T>, Error, FunctionReturnType<T>, ConvexQueryKey<T>>, 'queryKey' | 'staleTime' | 'enabled'> & {
49
+ meta: ConvexInfiniteQueryMeta;
50
+ refetchInterval: false;
51
+ refetchOnMount: false;
52
+ refetchOnReconnect: false;
53
+ refetchOnWindowFocus: false; /** Placeholder data shown while loading (item array, not pagination result) */
54
+ placeholderData?: ExtractPaginatedItem<FunctionReturnType<T>>[];
55
+ } & DistributiveOmit<UseQueryOptions<FunctionReturnType<T>, DefaultError>, ReservedInfiniteQueryOptions>;
56
+ /** Infinite query options with attached function reference (client-only) */
57
+ type ConvexInfiniteQueryOptionsWithRef<T extends FunctionReference<'query'>> = ConvexInfiniteQueryOptions<T> & {
58
+ [FUNC_REF_SYMBOL]: T;
59
+ };
60
+ /** Infinite query options return type */
61
+ type InfiniteQueryOptsReturn<T extends FunctionReference<'query'>> = ConvexInfiniteQueryOptionsWithRef<T>;
62
+ /**
63
+ * Decorated infinite query procedure.
64
+ * Only available on queries that have cursor/limit in their input (paginated).
65
+ * Supports skipToken for conditional queries.
66
+ * Args are optional when the function has no required parameters (besides cursor/limit).
67
+ */
68
+ type DecorateInfiniteQuery<T extends FunctionReference<'query'>> = {
69
+ /** 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) */
70
+ infiniteQueryKey: (args?: DeepPartial<InfiniteQueryInput<FunctionArgs<T>>>) => ConvexQueryKey<T>; /** Function metadata from server (auth, limit, rateLimit, role, type) */
71
+ meta: PaginatedFnMeta;
72
+ };
73
+ /**
74
+ * Decorated mutation procedure with mutationOptions and mutationKey methods.
75
+ */
76
+ type DecorateMutation<T extends FunctionReference<'mutation'>> = {
77
+ mutationOptions: (opts?: DistributiveOmit<UseMutationOptions<FunctionReturnType<T>, DefaultError, MutationVariables<T>>, ReservedMutationOptions$1>) => UseMutationOptions<FunctionReturnType<T>, DefaultError, MutationVariables<T>>; /** Get mutation key for QueryClient methods */
78
+ mutationKey: () => ConvexMutationKey;
79
+ };
80
+ /**
81
+ * Decorated action procedure with queryOptions, mutationOptions, and key methods.
82
+ * Actions can be used as one-shot queries (no subscription) or as mutations.
83
+ * Supports skipToken for conditional queries.
84
+ */
85
+ type DecorateAction<T extends FunctionReference<'action'>> = {
86
+ /** 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 */
87
+ staticQueryOptions: keyof FunctionArgs<T> extends never ? (args?: EmptyObject | SkipToken, opts?: StaticQueryOptsParam) => ConvexActionOptions<T> & {
88
+ meta: ConvexQueryMeta;
89
+ } : EmptyObject extends FunctionArgs<T> ? (args?: FunctionArgs<T> | SkipToken, opts?: StaticQueryOptsParam) => ConvexActionOptions<T> & {
90
+ meta: ConvexQueryMeta;
91
+ } : (args: FunctionArgs<T> | SkipToken, opts?: StaticQueryOptsParam) => ConvexActionOptions<T> & {
92
+ meta: ConvexQueryMeta;
93
+ }; /** Use action as a mutation */
94
+ mutationOptions: (opts?: DistributiveOmit<UseMutationOptions<FunctionReturnType<T>, DefaultError, MutationVariables<T>>, ReservedMutationOptions$1>) => UseMutationOptions<FunctionReturnType<T>, DefaultError, MutationVariables<T>>; /** Get mutation key for QueryClient methods */
95
+ mutationKey: () => ConvexMutationKey; /** Get query key for QueryClient methods */
96
+ queryKey: (args?: DeepPartial<FunctionArgs<T>>) => ConvexActionKey<T>; /** Get query filter for QueryClient methods */
97
+ queryFilter: (args?: DeepPartial<FunctionArgs<T>>, filters?: DistributiveOmit<QueryFilters, 'queryKey'>) => QueryFilters;
98
+ };
99
+ /**
100
+ * Recursively decorates all procedures in a Convex API object.
101
+ */
102
+ 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 };
103
+ //#endregion
104
+ //#region src/react/http-proxy.d.ts
105
+ /** Infer schema type or return empty object if UnsetMarker */
106
+ type InferSchemaOrEmpty<T> = T extends UnsetMarker ? object : T extends z.ZodTypeAny ? z.infer<T> : object;
107
+ /** Infer merged input from HttpProcedure (flat - used internally) */
108
+ type InferHttpInput<T> = T extends HttpProcedure<infer TInput, infer _TOutput, infer TParams, infer TQuery> ? Simplify<InferSchemaOrEmpty<TParams> & InferSchemaOrEmpty<TQuery> & InferSchemaOrEmpty<TInput>> : object;
109
+ /**
110
+ * Extract string keys from a Zod object schema.
111
+ * Used for param/query which are always strings in URLs.
112
+ */
113
+ type ZodObjectKeys<T> = T extends z.ZodObject<infer Shape> ? { [K in keyof Shape]: string } : Record<string, string>;
114
+ /**
115
+ * Extract string or string[] keys from a Zod object schema.
116
+ * Query params can have array values.
117
+ */
118
+ type ZodQueryKeys<T> = T extends z.ZodObject<infer Shape> ? { [K in keyof Shape]?: string | string[] } : Record<string, string | string[]>;
119
+ /**
120
+ * Infer client-side args from HttpProcedure with proper nesting.
121
+ * - params: only present if TParams is defined, always strings (URL path params)
122
+ * - searchParams: only present if TQuery is defined, always strings (URL query params)
123
+ * - form: only present if TForm is defined, typed from schema
124
+ * - JSON body fields spread at root level (typed from schema)
125
+ * - Client options (fetch, init, headers) always optional for per-call overrides
126
+ */
127
+ type InferHttpClientArgs<T> = T extends HttpProcedure<infer TInput, infer _TOutput, infer TParams, infer TQuery, infer _TMethod, infer TForm> ? Simplify<(TParams extends UnsetMarker ? object : {
128
+ params: ZodObjectKeys<TParams>;
129
+ }) & (TQuery extends UnsetMarker ? object : {
130
+ searchParams: ZodQueryKeys<TQuery>;
131
+ }) & (TForm extends UnsetMarker ? object : TForm extends z.ZodTypeAny ? {
132
+ form: z.infer<TForm>;
133
+ } : object) & (TInput extends UnsetMarker ? object : TInput extends z.ZodTypeAny ? z.infer<TInput> : object) & {
134
+ fetch?: typeof fetch;
135
+ init?: RequestInit;
136
+ headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
137
+ }> : HttpInputArgs;
138
+ /** Infer output type from HttpProcedure */
139
+ type InferHttpOutput<T> = T extends HttpProcedure<infer _TInput, infer TOutput, infer _TParams, infer _TQuery> ? TOutput extends UnsetMarker ? unknown : TOutput extends z.ZodTypeAny ? z.infer<TOutput> : unknown : unknown;
140
+ /** Query key with args (3-element) or prefix key without args (2-element) for invalidation */
141
+ type HttpQueryKey = readonly ['httpQuery', string, unknown] | readonly ['httpQuery', string];
142
+ type HttpMutationKey = readonly ['httpMutation', string];
143
+ type ReservedQueryOptions = 'queryKey' | 'queryFn';
144
+ type ReservedMutationOptions = 'mutationFn';
145
+ /** Query options for GET HTTP endpoints - compatible with both useQuery and useSuspenseQuery */
146
+ type HttpQueryOptsReturn<T extends HttpProcedure> = Omit<UseQueryOptions<InferHttpOutput<T>, Error, InferHttpOutput<T>, HttpQueryKey>, 'queryFn'> & {
147
+ queryFn: () => Promise<InferHttpOutput<T>>;
148
+ };
149
+ /** Mutation options for POST/PUT/PATCH/DELETE HTTP endpoints - typed variables */
150
+ type HttpMutationOptsReturn<T extends HttpProcedure> = UseMutationOptions<InferHttpOutput<T>, DefaultError, InferHttpClientArgs<T>>;
151
+ /** Query options (TanStack Query only - client opts go in args) */
152
+ type HttpQueryOptions<T extends HttpProcedure> = DistributiveOmit<HttpQueryOptsReturn<T>, ReservedQueryOptions>;
153
+ /** Mutation options (TanStack Query only - client opts go in mutate args) */
154
+ type HttpMutationOptions<T extends HttpProcedure> = DistributiveOmit<HttpMutationOptsReturn<T>, ReservedMutationOptions>;
155
+ /**
156
+ * Decorated GET procedure with queryOptions and mutationOptions.
157
+ * - queryOptions: For cached data fetching (useQuery/useSuspenseQuery)
158
+ * - mutationOptions: For one-time actions like exports (useMutation)
159
+ */
160
+ type DecorateHttpQuery<T extends HttpProcedure> = {
161
+ queryOptions: keyof InferHttpInput<T> extends never ? (args?: InferHttpClientArgs<T>, opts?: HttpQueryOptions<T>) => HttpQueryOptsReturn<T> : object extends InferHttpInput<T> ? (args?: InferHttpClientArgs<T>, opts?: HttpQueryOptions<T>) => HttpQueryOptsReturn<T> : (args: InferHttpClientArgs<T>, opts?: HttpQueryOptions<T>) => HttpQueryOptsReturn<T>; /** Get query key for QueryClient methods (with args = exact match, without = prefix) */
162
+ queryKey: (args?: InferHttpClientArgs<T>) => HttpQueryKey; /** Get query filter for QueryClient methods (e.g., invalidateQueries) */
163
+ queryFilter: (args?: InferHttpClientArgs<T>, filters?: DistributiveOmit<QueryFilters, 'queryKey'>) => QueryFilters; /** Mutation options for GET endpoints (exports, downloads - no caching) */
164
+ mutationOptions: (opts?: HttpMutationOptions<T>) => HttpMutationOptsReturn<T>; /** Get mutation key for QueryClient methods */
165
+ mutationKey: () => HttpMutationKey;
166
+ };
167
+ /**
168
+ * Decorated POST/PUT/PATCH/DELETE procedure with mutationOptions.
169
+ * The mutationFn receives typed args inferred from server schemas.
170
+ */
171
+ type DecorateHttpMutation<T extends HttpProcedure> = {
172
+ mutationOptions: (opts?: HttpMutationOptions<T>) => HttpMutationOptsReturn<T>; /** Get mutation key for QueryClient methods */
173
+ mutationKey: () => HttpMutationKey;
174
+ };
175
+ /** Vanilla HTTP query - only direct call, no React Query */
176
+ /**
177
+ * HTTP Client type from router record.
178
+ * Maps each procedure to queryOptions (GET) or mutationOptions (POST/etc).
179
+ * Uses infer to extract the method type literal for proper GET/non-GET distinction.
180
+ */
181
+ type HttpCRPCClient<T extends HttpRouterRecord> = { [K in keyof T]: T[K] extends HttpProcedure<infer _TInput, infer _TOutput, infer _TParams, infer _TQuery, infer TMethod, infer _TForm> ? TMethod extends 'GET' ? DecorateHttpQuery<T[K]> : DecorateHttpMutation<T[K]> : T[K] extends CRPCHttpRouter<infer R> ? HttpCRPCClient<R> : T[K] extends HttpRouterRecord ? HttpCRPCClient<T[K]> : never };
182
+ /**
183
+ * HTTP Client type from a CRPCHttpRouter.
184
+ * Use this when your type is the router object (with _def).
185
+ */
186
+ type HttpCRPCClientFromRouter<TRouter extends CRPCHttpRouter<any>> = HttpCRPCClient<TRouter['_def']['record']>;
187
+ //#endregion
188
+ //#region src/rsc/proxy-server.d.ts
189
+ type CreateServerCRPCProxyOptions<TApi> = {
190
+ api: TApi;
191
+ };
192
+ /**
193
+ * Extract HTTP router from TApi['http'] if present (optional).
194
+ * Uses NonNullable to handle optional http property.
195
+ */
196
+ type ExtractHttpRouter<TApi> = TApi extends {
197
+ http?: infer R;
198
+ } ? NonNullable<R> extends CRPCHttpRouter<HttpRouterRecord> ? NonNullable<R> : undefined : undefined;
199
+ /**
200
+ * Combined CRPC client type with optional HTTP router.
201
+ * HTTP router is extracted from TApi['http'] if present.
202
+ * Uses Omit to prevent type conflicts between CRPCClient and HttpCRPCClient.
203
+ */
204
+ type ServerCRPCClient<TApi extends Record<string, unknown>> = ExtractHttpRouter<TApi> extends CRPCHttpRouter<HttpRouterRecord> ? CRPCClient<Omit<TApi, 'http'>> & {
205
+ http: HttpCRPCClientFromRouter<ExtractHttpRouter<TApi>>;
206
+ } : CRPCClient<TApi>;
207
+ /**
208
+ * Create a server-compatible CRPC proxy for RSC.
209
+ * Only supports queryOptions (no mutations in RSC).
210
+ *
211
+ * Query execution (including auth) is handled by getServerQueryClientOptions.
212
+ *
213
+ * @example
214
+ * ```tsx
215
+ * // src/lib/convex/rsc.tsx
216
+ * import { api } from '@convex/api';
217
+ *
218
+ * // Proxy just builds query options - no auth config here
219
+ * export const crpc = createServerCRPCProxy({ api });
220
+ *
221
+ * // Auth + execution config in QueryClient
222
+ * const queryClient = new QueryClient({
223
+ * defaultOptions: getServerQueryClientOptions({
224
+ * getToken: caller.getToken,
225
+ * convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
226
+ * }),
227
+ * });
228
+ *
229
+ * // app/page.tsx (RSC)
230
+ * prefetch(crpc.posts.list.queryOptions());
231
+ * prefetch(crpc.http.health.queryOptions({}));
232
+ * ```
233
+ */
234
+ declare function createServerCRPCProxy<TApi extends Record<string, unknown>>(options: CreateServerCRPCProxyOptions<TApi>): ServerCRPCClient<TApi>;
235
+ //#endregion
236
+ //#region src/rsc/server-query-client.d.ts
237
+ type GetServerQueryClientOptionsParams = {
238
+ /** Function to get auth token for authenticated queries. Use `caller.getToken` from your RSC setup. */getToken?: () => Promise<string | undefined>; /** Base URL for HTTP routes (e.g., NEXT_PUBLIC_CONVEX_SITE_URL). Required for crpc.http.* queries. */
239
+ convexSiteUrl?: string; /** Optional payload transformer (always composed with built-in Date support). */
240
+ transformer?: DataTransformerOptions;
241
+ };
242
+ /**
243
+ * Get server QueryClient options for RSC prefetching.
244
+ * Handles both WebSocket queries (convexQuery/convexAction) and HTTP routes (httpQuery).
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * const queryClient = new QueryClient({
249
+ * defaultOptions: {
250
+ * ...getServerQueryClientOptions({
251
+ * getToken: caller.getToken,
252
+ * convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
253
+ * }),
254
+ * },
255
+ * });
256
+ * ```
257
+ */
258
+ declare function getServerQueryClientOptions({
259
+ getToken,
260
+ convexSiteUrl,
261
+ transformer: transformerOptions
262
+ }?: GetServerQueryClientOptionsParams): {
263
+ queries: {
264
+ staleTime: number;
265
+ queryFn: ({
266
+ queryKey,
267
+ meta
268
+ }: {
269
+ queryKey: readonly unknown[];
270
+ meta?: Record<string, unknown>;
271
+ }) => Promise<any>;
272
+ queryKeyHashFn: (queryKey: readonly unknown[]) => string;
273
+ };
274
+ };
275
+ //#endregion
276
+ export { CreateServerCRPCProxyOptions, GetServerQueryClientOptionsParams, type ServerCRPCClient, createServerCRPCProxy, getServerQueryClientOptions };
@@ -0,0 +1,233 @@
1
+ import { n as defaultIsUnauthorized } from "../error-BZEnI7Sq.js";
2
+ import { n as getFuncRef, r as getFunctionMeta, t as buildMetaIndex } from "../meta-utils-0Pu0Nrap.js";
3
+ import { i as decodeWire, s as getTransformer } from "../transformer-DtDhR3Lc.js";
4
+ import { n as convexInfiniteQueryOptions, r as convexQuery } from "../query-options-Dw7cOyXl.js";
5
+ import { convexToJson } from "convex/values";
6
+ import { getFunctionName } from "convex/server";
7
+ import { fetchAction, fetchQuery } from "convex/nextjs";
8
+ import { hashKey } from "@tanstack/query-core";
9
+
10
+ //#region src/rsc/http-server.ts
11
+ /**
12
+ * Build query options for an HTTP route (server-side).
13
+ * Does NOT include queryFn - execution handled by getServerQueryClientOptions.
14
+ */
15
+ function buildHttpQueryOptions(route, routeKey, args) {
16
+ return {
17
+ queryKey: [
18
+ "httpQuery",
19
+ routeKey,
20
+ args
21
+ ],
22
+ meta: {
23
+ path: route.path,
24
+ method: route.method
25
+ }
26
+ };
27
+ }
28
+ /**
29
+ * Execute an HTTP route fetch.
30
+ * Called by getServerQueryClientOptions queryFn.
31
+ */
32
+ async function fetchHttpRoute(convexSiteUrl, routeMeta, args, token, transformer) {
33
+ const url = buildUrl(convexSiteUrl, routeMeta.path, args);
34
+ const response = await fetch(url, {
35
+ method: routeMeta.method,
36
+ headers: {
37
+ "Content-Type": "application/json",
38
+ ...token ? { Authorization: `Bearer ${token}` } : {}
39
+ }
40
+ });
41
+ if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
42
+ if (response.headers.get("content-length") === "0" || response.status === 204) return null;
43
+ return decodeWire(await response.json(), transformer);
44
+ }
45
+ /**
46
+ * Build URL with path params and query params.
47
+ */
48
+ function buildUrl(convexSiteUrl, pathTemplate, args) {
49
+ const remaining = { ...args };
50
+ const path = pathTemplate.replace(/:(\w+)/g, (_, key) => {
51
+ const value = remaining[key];
52
+ delete remaining[key];
53
+ return value !== null && value !== void 0 ? encodeURIComponent(String(value)) : "";
54
+ });
55
+ const queryEntries = Object.entries(remaining).filter(([_, v]) => v !== void 0 && v !== null);
56
+ if (queryEntries.length > 0) {
57
+ const params = new URLSearchParams();
58
+ for (const [key, value] of queryEntries) params.set(key, String(value));
59
+ return `${convexSiteUrl}${path}?${params.toString()}`;
60
+ }
61
+ return convexSiteUrl + path;
62
+ }
63
+
64
+ //#endregion
65
+ //#region src/rsc/proxy-server.ts
66
+ /**
67
+ * Server-compatible CRPC Proxy for RSC
68
+ *
69
+ * Provides a proxy that works in React Server Components.
70
+ * Query execution is delegated to getServerQueryClientOptions.
71
+ */
72
+ function createRecursiveProxy(api, path, meta) {
73
+ return new Proxy(() => {}, { get(_target, prop) {
74
+ if (typeof prop === "symbol") return;
75
+ if (prop === "then") return;
76
+ if (path[0] === "http" && prop === "queryOptions") {
77
+ const routeKey = path.slice(1).join(".");
78
+ const route = meta._http?.[routeKey];
79
+ if (!route) throw new Error(`HTTP route not found: ${routeKey}`);
80
+ return (args = {}) => buildHttpQueryOptions(route, routeKey, args);
81
+ }
82
+ if (prop === "queryOptions") return (args = {}, opts) => {
83
+ return convexQuery(getFuncRef(api, path), args, meta, opts);
84
+ };
85
+ if (prop === "infiniteQueryOptions") return (args = {}, opts = {}) => {
86
+ return convexInfiniteQueryOptions(getFuncRef(api, path), args, opts, meta);
87
+ };
88
+ if (prop === "infiniteQueryKey") return (args) => {
89
+ return [
90
+ "convexQuery",
91
+ getFunctionName(getFuncRef(api, path)),
92
+ args ?? {}
93
+ ];
94
+ };
95
+ if (prop === "meta" && path.length >= 2) return getFunctionMeta(path, meta);
96
+ return createRecursiveProxy(api, [...path, prop], meta);
97
+ } });
98
+ }
99
+ /**
100
+ * Create a server-compatible CRPC proxy for RSC.
101
+ * Only supports queryOptions (no mutations in RSC).
102
+ *
103
+ * Query execution (including auth) is handled by getServerQueryClientOptions.
104
+ *
105
+ * @example
106
+ * ```tsx
107
+ * // src/lib/convex/rsc.tsx
108
+ * import { api } from '@convex/api';
109
+ *
110
+ * // Proxy just builds query options - no auth config here
111
+ * export const crpc = createServerCRPCProxy({ api });
112
+ *
113
+ * // Auth + execution config in QueryClient
114
+ * const queryClient = new QueryClient({
115
+ * defaultOptions: getServerQueryClientOptions({
116
+ * getToken: caller.getToken,
117
+ * convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
118
+ * }),
119
+ * });
120
+ *
121
+ * // app/page.tsx (RSC)
122
+ * prefetch(crpc.posts.list.queryOptions());
123
+ * prefetch(crpc.http.health.queryOptions({}));
124
+ * ```
125
+ */
126
+ function createServerCRPCProxy(options) {
127
+ const { api } = options;
128
+ return createRecursiveProxy(api, [], buildMetaIndex(api));
129
+ }
130
+
131
+ //#endregion
132
+ //#region src/internal/query-key.ts
133
+ /**
134
+ * Shared query key utilities for Convex + TanStack Query.
135
+ * This file has NO React dependencies so it can be imported in both
136
+ * server (RSC) and client contexts.
137
+ */
138
+ /**
139
+ * Check if query key is for a Convex query function.
140
+ * Format: ['convexQuery', 'namespace:functionName', { args }]
141
+ */
142
+ function isConvexQuery(queryKey) {
143
+ return queryKey.length >= 2 && queryKey[0] === "convexQuery";
144
+ }
145
+ /**
146
+ * Check if query key is for a Convex action function.
147
+ * Format: ['convexAction', 'namespace:functionName', { args }]
148
+ */
149
+ function isConvexAction(queryKey) {
150
+ return queryKey.length >= 2 && queryKey[0] === "convexAction";
151
+ }
152
+ /**
153
+ * Create stable hash for Convex query keys.
154
+ * Uses Convex's JSON serialization for consistent argument hashing.
155
+ */
156
+ function hashConvexQuery(queryKey) {
157
+ const [, funcName, args] = queryKey;
158
+ return `convexQuery|${funcName}|${JSON.stringify(convexToJson(args))}`;
159
+ }
160
+ /**
161
+ * Create stable hash for Convex action keys.
162
+ * Uses Convex's JSON serialization for consistent argument hashing.
163
+ */
164
+ function hashConvexAction(queryKey) {
165
+ const [, funcName, args] = queryKey;
166
+ return `convexAction|${funcName}|${JSON.stringify(convexToJson(args))}`;
167
+ }
168
+
169
+ //#endregion
170
+ //#region src/internal/hash.ts
171
+ /**
172
+ * Create a hash function for TanStack Query that handles Convex keys.
173
+ */
174
+ function createHashFn(fallback = hashKey) {
175
+ return (queryKey) => {
176
+ if (isConvexQuery(queryKey)) return hashConvexQuery(queryKey);
177
+ if (isConvexAction(queryKey)) return hashConvexAction(queryKey);
178
+ return fallback(queryKey);
179
+ };
180
+ }
181
+
182
+ //#endregion
183
+ //#region src/rsc/server-query-client.ts
184
+ /**
185
+ * Get server QueryClient options for RSC prefetching.
186
+ * Handles both WebSocket queries (convexQuery/convexAction) and HTTP routes (httpQuery).
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * const queryClient = new QueryClient({
191
+ * defaultOptions: {
192
+ * ...getServerQueryClientOptions({
193
+ * getToken: caller.getToken,
194
+ * convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
195
+ * }),
196
+ * },
197
+ * });
198
+ * ```
199
+ */
200
+ function getServerQueryClientOptions({ getToken, convexSiteUrl, transformer: transformerOptions } = {}) {
201
+ const transformer = getTransformer(transformerOptions);
202
+ return { queries: {
203
+ staleTime: 3e4,
204
+ queryFn: async ({ queryKey, meta }) => {
205
+ const [type, ...rest] = queryKey;
206
+ const token = await getToken?.();
207
+ if (type === "httpQuery") {
208
+ const [routeKey, args] = rest;
209
+ const routeMeta = meta;
210
+ if (!convexSiteUrl) throw new Error("convexSiteUrl required for HTTP queries. Pass it to getServerQueryClientOptions().");
211
+ if (!routeMeta?.path) throw new Error(`HTTP route metadata missing for: ${routeKey}`);
212
+ return await fetchHttpRoute(convexSiteUrl, routeMeta, args, token, transformer);
213
+ }
214
+ const [funcRef, args] = rest;
215
+ const wireArgs = transformer.input.serialize(args);
216
+ const queryMeta = meta;
217
+ const skipUnauth = queryMeta?.skipUnauth;
218
+ const authRequired = queryMeta?.authType === "required";
219
+ if (!token && (skipUnauth || authRequired)) return null;
220
+ const opts = token ? { token } : void 0;
221
+ try {
222
+ return transformer.output.deserialize(type === "convexQuery" ? await fetchQuery(funcRef, wireArgs, opts) : await fetchAction(funcRef, wireArgs, opts));
223
+ } catch (error) {
224
+ if ((skipUnauth || authRequired) && defaultIsUnauthorized(error)) return null;
225
+ throw error;
226
+ }
227
+ },
228
+ queryKeyHashFn: createHashFn()
229
+ } };
230
+ }
231
+
232
+ //#endregion
233
+ export { createServerCRPCProxy, getServerQueryClientOptions };