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.
- package/bin/intent.js +3 -0
- package/dist/aggregate/index.d.ts +388 -0
- package/dist/aggregate/index.js +37 -0
- package/dist/api-entry-BckXqaLb.js +66 -0
- package/dist/auth/client/index.d.ts +37 -0
- package/dist/auth/client/index.js +217 -0
- package/dist/auth/config/index.d.ts +45 -0
- package/dist/auth/config/index.js +24 -0
- package/dist/auth/generated/index.d.ts +2 -0
- package/dist/auth/generated/index.js +3 -0
- package/dist/auth/http/index.d.ts +64 -0
- package/dist/auth/http/index.js +461 -0
- package/dist/auth/index.d.ts +221 -0
- package/dist/auth/index.js +1398 -0
- package/dist/auth/nextjs/index.d.ts +50 -0
- package/dist/auth/nextjs/index.js +81 -0
- package/dist/auth-store-Cljlmdmi.js +197 -0
- package/dist/builder-CBdG5W6A.js +1974 -0
- package/dist/caller-factory-cTXNvYdz.js +216 -0
- package/dist/cli.mjs +13264 -0
- package/dist/codegen-lF80HSWu.mjs +3416 -0
- package/dist/context-utils-HPC5nXzx.d.ts +17 -0
- package/dist/create-schema-odyF4kCy.js +156 -0
- package/dist/create-schema-orm-DOyiNDCx.js +246 -0
- package/dist/crpc/index.d.ts +105 -0
- package/dist/crpc/index.js +169 -0
- package/dist/customFunctions-C0voKmtx.js +144 -0
- package/dist/error-BZEnI7Sq.js +41 -0
- package/dist/generated-contract-disabled-Cih4eITO.js +50 -0
- package/dist/generated-contract-disabled-D-sOFy92.d.ts +354 -0
- package/dist/http-types-DqJubRPJ.d.ts +292 -0
- package/dist/meta-utils-0Pu0Nrap.js +117 -0
- package/dist/middleware-BUybuv9n.d.ts +34 -0
- package/dist/middleware-C2qTZ3V7.js +84 -0
- package/dist/orm/index.d.ts +17 -0
- package/dist/orm/index.js +10713 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +3 -0
- package/dist/procedure-caller-DtxLmGwA.d.ts +1467 -0
- package/dist/procedure-caller-MWcxhQDv.js +349 -0
- package/dist/query-context-B8o6-8kC.js +1518 -0
- package/dist/query-context-CFZqIvD7.d.ts +42 -0
- package/dist/query-options-Dw7cOyXl.js +121 -0
- package/dist/ratelimit/index.d.ts +269 -0
- package/dist/ratelimit/index.js +856 -0
- package/dist/ratelimit/react/index.d.ts +76 -0
- package/dist/ratelimit/react/index.js +183 -0
- package/dist/react/index.d.ts +1284 -0
- package/dist/react/index.js +2526 -0
- package/dist/rsc/index.d.ts +276 -0
- package/dist/rsc/index.js +233 -0
- package/dist/runtime-CtvJPkur.js +2453 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +6 -0
- package/dist/solid/index.d.ts +1221 -0
- package/dist/solid/index.js +2940 -0
- package/dist/transformer-DtDhR3Lc.js +194 -0
- package/dist/types-BTb_4BaU.d.ts +42 -0
- package/dist/types-BiJE7qxR.d.ts +4 -0
- package/dist/types-DEJpkIhw.d.ts +88 -0
- package/dist/types-HhO_R6pd.d.ts +213 -0
- package/dist/validators-B7oIJCAp.js +279 -0
- package/dist/validators-vzRKjBJC.d.ts +88 -0
- package/dist/watcher.mjs +96 -0
- package/dist/where-clause-compiler-DdjN63Io.d.ts +4756 -0
- package/package.json +107 -34
- package/skills/convex/SKILL.md +486 -0
- package/skills/convex/references/features/aggregates.md +353 -0
- package/skills/convex/references/features/auth-admin.md +446 -0
- package/skills/convex/references/features/auth-organizations.md +1141 -0
- package/skills/convex/references/features/auth-polar.md +579 -0
- package/skills/convex/references/features/auth.md +470 -0
- package/skills/convex/references/features/create-plugins.md +153 -0
- package/skills/convex/references/features/http.md +676 -0
- package/skills/convex/references/features/migrations.md +162 -0
- package/skills/convex/references/features/orm.md +1166 -0
- package/skills/convex/references/features/react.md +657 -0
- package/skills/convex/references/features/scheduling.md +267 -0
- package/skills/convex/references/features/testing.md +209 -0
- package/skills/convex/references/setup/auth.md +501 -0
- package/skills/convex/references/setup/biome.md +190 -0
- package/skills/convex/references/setup/doc-guidelines.md +145 -0
- package/skills/convex/references/setup/index.md +761 -0
- package/skills/convex/references/setup/next.md +116 -0
- package/skills/convex/references/setup/react.md +175 -0
- package/skills/convex/references/setup/server.md +473 -0
- package/skills/convex/references/setup/start.md +67 -0
- package/LICENSE +0 -21
- package/README.md +0 -0
- package/dist/index.d.mts +0 -5
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -6
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { i as getFunctionType, n as getFuncRef, t as buildMetaIndex } from "./meta-utils-0Pu0Nrap.js";
|
|
2
|
+
import { s as getTransformer } from "./transformer-DtDhR3Lc.js";
|
|
3
|
+
import { fetchAction, fetchMutation, fetchQuery } from "convex/nextjs";
|
|
4
|
+
|
|
5
|
+
//#region src/server/caller.ts
|
|
6
|
+
function createRecursiveProxy(api, path, createOpts) {
|
|
7
|
+
return new Proxy(() => {}, {
|
|
8
|
+
get(_target, prop) {
|
|
9
|
+
if (typeof prop === "symbol") return;
|
|
10
|
+
if (prop === "then") return;
|
|
11
|
+
return createRecursiveProxy(api, [...path, prop], createOpts);
|
|
12
|
+
},
|
|
13
|
+
apply(_target, _thisArg, argsList) {
|
|
14
|
+
const funcRef = getFuncRef(api, path);
|
|
15
|
+
const args = createOpts.transformer.input.serialize(argsList[0] ?? {});
|
|
16
|
+
const callerOpts = argsList[1];
|
|
17
|
+
const fnType = getFunctionType(path, createOpts.meta);
|
|
18
|
+
if (fnType === "query") return createOpts.fetchQuery(funcRef, args, callerOpts).then((result) => createOpts.transformer.output.deserialize(result));
|
|
19
|
+
if (fnType === "mutation") return createOpts.fetchMutation(funcRef, args, callerOpts).then((result) => createOpts.transformer.output.deserialize(result));
|
|
20
|
+
return createOpts.fetchAction(funcRef, args, callerOpts).then((result) => createOpts.transformer.output.deserialize(result));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a server caller for direct data fetching without React Query.
|
|
26
|
+
*
|
|
27
|
+
* This is detached from React Query cache - data is NOT available in client components.
|
|
28
|
+
* Use for server-only data that doesn't need to be shared with the client.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* // src/lib/convex/rsc.tsx
|
|
33
|
+
* export const caller = createServerCaller(api, {
|
|
34
|
+
* fetchQuery: fetchAuthQuery,
|
|
35
|
+
* fetchMutation: fetchAuthMutation,
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // app/page.tsx (RSC)
|
|
39
|
+
* const posts = await caller.posts.list();
|
|
40
|
+
* return <div>{posts?.length} posts</div>;
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
function createServerCaller(api, opts) {
|
|
44
|
+
return createRecursiveProxy(api, [], {
|
|
45
|
+
...opts,
|
|
46
|
+
transformer: getTransformer(opts.transformer)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/server/lazy-caller.ts
|
|
52
|
+
/**
|
|
53
|
+
* Lazy caller that creates context on each procedure invocation.
|
|
54
|
+
* Matches tRPC's appRouter.createCaller(createTRPCContext) pattern.
|
|
55
|
+
*/
|
|
56
|
+
function traverseCaller(caller, path) {
|
|
57
|
+
let target = caller;
|
|
58
|
+
for (const key of path) target = target[key];
|
|
59
|
+
return target;
|
|
60
|
+
}
|
|
61
|
+
function createRecursiveProxyWithLazyContext(api, path, createContext) {
|
|
62
|
+
return new Proxy(() => {}, {
|
|
63
|
+
get(_target, prop) {
|
|
64
|
+
if (typeof prop === "symbol") return;
|
|
65
|
+
if (prop === "then") return;
|
|
66
|
+
if (path.length === 0 && prop === "isAuth") return async () => {
|
|
67
|
+
return (await createContext()).isAuthenticated;
|
|
68
|
+
};
|
|
69
|
+
if (path.length === 0 && prop === "isUnauth") return async () => {
|
|
70
|
+
return !(await createContext()).isAuthenticated;
|
|
71
|
+
};
|
|
72
|
+
if (path.length === 0 && prop === "getToken") return async () => {
|
|
73
|
+
return (await createContext()).token;
|
|
74
|
+
};
|
|
75
|
+
return createRecursiveProxyWithLazyContext(api, [...path, prop], createContext);
|
|
76
|
+
},
|
|
77
|
+
async apply(_target, _thisArg, argsList) {
|
|
78
|
+
try {
|
|
79
|
+
getFuncRef(api, path);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
const displayPath = path.length > 0 ? path.join(".") : "<root>";
|
|
82
|
+
throw new Error(`Invalid caller path: ${displayPath}`, { cause: error });
|
|
83
|
+
}
|
|
84
|
+
return traverseCaller((await createContext()).caller, path)(argsList[0] ?? {}, argsList[1]);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create a lazy caller that creates context on each procedure invocation.
|
|
90
|
+
* Matches tRPC's `appRouter.createCaller(createTRPCContext)` pattern.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* // server.ts
|
|
95
|
+
* const { createContext, createCaller } = createCallerFactory({...});
|
|
96
|
+
*
|
|
97
|
+
* // rsc.tsx
|
|
98
|
+
* const createRSCContext = cache(async () => {
|
|
99
|
+
* const heads = await headers();
|
|
100
|
+
* return createContext({ headers: heads });
|
|
101
|
+
* });
|
|
102
|
+
* export const caller = createCaller(createRSCContext);
|
|
103
|
+
*
|
|
104
|
+
* // app/page.tsx - single call! Context created lazily
|
|
105
|
+
* const posts = await caller.posts.list();
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
function createLazyCaller(api, createContext) {
|
|
109
|
+
return createRecursiveProxyWithLazyContext(api, [], createContext);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/server/caller-factory.ts
|
|
114
|
+
/** biome-ignore-all lint/suspicious/noExplicitAny: lib */
|
|
115
|
+
/**
|
|
116
|
+
* Framework-agnostic caller factory.
|
|
117
|
+
* getToken is passed as a parameter - decoupled from @convex-dev/better-auth.
|
|
118
|
+
*/
|
|
119
|
+
const CONVEX_SITE_URL_RE = /\.convex\.site(?=\/|$)/;
|
|
120
|
+
const getArgsAndOptions = (args, token, url) => [args[0], {
|
|
121
|
+
token,
|
|
122
|
+
url
|
|
123
|
+
}];
|
|
124
|
+
const parseConvexSiteUrl = (url) => {
|
|
125
|
+
if (!url) throw new Error("CONVEX_SITE_URL is not set. This must be set in the environment.");
|
|
126
|
+
if (url.endsWith(".convex.cloud")) throw new Error(`CONVEX_SITE_URL should end in .convex.site, not .convex.cloud. Currently set to ${url}.`);
|
|
127
|
+
return url;
|
|
128
|
+
};
|
|
129
|
+
const getConvexUrl = (siteUrl, convexUrl) => {
|
|
130
|
+
if (convexUrl) return convexUrl;
|
|
131
|
+
return siteUrl.replace(CONVEX_SITE_URL_RE, ".convex.cloud");
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Framework-agnostic caller factory.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const { createContext, createCaller } = createCallerFactory({
|
|
139
|
+
* api,
|
|
140
|
+
* convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
|
|
141
|
+
* auth: { getToken },
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
const noAuthGetToken = () => Promise.resolve({ token: void 0 });
|
|
146
|
+
function createCallerFactory(opts) {
|
|
147
|
+
const siteUrl = parseConvexSiteUrl(opts.convexSiteUrl);
|
|
148
|
+
const convexUrl = getConvexUrl(siteUrl, opts.convexUrl);
|
|
149
|
+
const getToken = opts.auth?.getToken ?? noAuthGetToken;
|
|
150
|
+
const isUnauthorized = opts.auth?.isUnauthorized;
|
|
151
|
+
const crpcMeta = buildMetaIndex(opts.api);
|
|
152
|
+
const callWithTokenAndRetry = async (fn, tokenResult, headers) => {
|
|
153
|
+
const shouldRetryWithFreshToken = !!opts.auth && !tokenResult.isFresh;
|
|
154
|
+
try {
|
|
155
|
+
return await fn(tokenResult.token);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
if (!shouldRetryWithFreshToken) {
|
|
158
|
+
if (isUnauthorized?.(error)) return null;
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
const newToken = await getToken(siteUrl, headers, {
|
|
162
|
+
...opts,
|
|
163
|
+
forceRefresh: true
|
|
164
|
+
});
|
|
165
|
+
try {
|
|
166
|
+
return await fn(newToken.token);
|
|
167
|
+
} catch (retryError) {
|
|
168
|
+
if (isUnauthorized?.(retryError)) return null;
|
|
169
|
+
throw retryError;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const createContext = async (reqOpts) => {
|
|
174
|
+
const tokenResult = await getToken(siteUrl, reqOpts.headers, opts);
|
|
175
|
+
const fetchAuthQuery = async (query, args, callerOpts) => {
|
|
176
|
+
if (callerOpts?.skipUnauth && !tokenResult.token) return null;
|
|
177
|
+
return callWithTokenAndRetry((token) => {
|
|
178
|
+
const argsAndOptions = getArgsAndOptions([args], token, convexUrl);
|
|
179
|
+
return fetchQuery(query, argsAndOptions[0], argsAndOptions[1]);
|
|
180
|
+
}, tokenResult, reqOpts.headers);
|
|
181
|
+
};
|
|
182
|
+
const fetchAuthMutation = async (mutation, args, callerOpts) => {
|
|
183
|
+
if (callerOpts?.skipUnauth && !tokenResult.token) return null;
|
|
184
|
+
return callWithTokenAndRetry((token) => {
|
|
185
|
+
const argsAndOptions = getArgsAndOptions([args], token, convexUrl);
|
|
186
|
+
return fetchMutation(mutation, argsAndOptions[0], argsAndOptions[1]);
|
|
187
|
+
}, tokenResult, reqOpts.headers);
|
|
188
|
+
};
|
|
189
|
+
const fetchAuthAction = async (action, args, callerOpts) => {
|
|
190
|
+
if (callerOpts?.skipUnauth && !tokenResult.token) return null;
|
|
191
|
+
return callWithTokenAndRetry((token) => {
|
|
192
|
+
const argsAndOptions = getArgsAndOptions([args], token, convexUrl);
|
|
193
|
+
return fetchAction(action, argsAndOptions[0], argsAndOptions[1]);
|
|
194
|
+
}, tokenResult, reqOpts.headers);
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
caller: createServerCaller(opts.api, {
|
|
198
|
+
fetchAction: fetchAuthAction,
|
|
199
|
+
fetchMutation: fetchAuthMutation,
|
|
200
|
+
fetchQuery: fetchAuthQuery,
|
|
201
|
+
meta: crpcMeta,
|
|
202
|
+
transformer: opts.transformer
|
|
203
|
+
}),
|
|
204
|
+
isAuthenticated: !!tokenResult.token,
|
|
205
|
+
token: tokenResult.token
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
const createCaller = (ctxFn) => createLazyCaller(opts.api, ctxFn);
|
|
209
|
+
return {
|
|
210
|
+
createCaller,
|
|
211
|
+
createContext
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
//#endregion
|
|
216
|
+
export { createLazyCaller as n, createServerCaller as r, createCallerFactory as t };
|