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,116 @@
|
|
|
1
|
+
## 8. Framework-Specific Setup
|
|
2
|
+
|
|
3
|
+
## 8.A Next.js App Router
|
|
4
|
+
|
|
5
|
+
### 8.A.1 Server caller + auth utilities
|
|
6
|
+
|
|
7
|
+
**Create:** `src/lib/convex/server.ts`
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { api } from "@convex/api";
|
|
11
|
+
import { convexBetterAuth } from "kitcn/auth/nextjs";
|
|
12
|
+
|
|
13
|
+
export const { createContext, createCaller, handler } = convexBetterAuth({
|
|
14
|
+
api,
|
|
15
|
+
convexSiteUrl: process.env.NEXT_PUBLIC_CONVEX_SITE_URL!,
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 8.A.2 Auth API route
|
|
20
|
+
|
|
21
|
+
**Create:** `src/app/api/auth/[...all]/route.ts`
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { handler } from "@/lib/convex/server";
|
|
25
|
+
|
|
26
|
+
export const { GET, POST } = handler;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 8.A.3 RSC helpers
|
|
30
|
+
|
|
31
|
+
**Create:** `src/lib/convex/rsc.tsx`
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import "server-only";
|
|
35
|
+
|
|
36
|
+
import { api } from "@convex/api";
|
|
37
|
+
import type { FetchQueryOptions } from "@tanstack/react-query";
|
|
38
|
+
import {
|
|
39
|
+
dehydrate,
|
|
40
|
+
HydrationBoundary,
|
|
41
|
+
QueryClient,
|
|
42
|
+
} from "@tanstack/react-query";
|
|
43
|
+
import {
|
|
44
|
+
createServerCRPCProxy,
|
|
45
|
+
getServerQueryClientOptions,
|
|
46
|
+
} from "kitcn/rsc";
|
|
47
|
+
import { headers } from "next/headers";
|
|
48
|
+
import { cache } from "react";
|
|
49
|
+
|
|
50
|
+
import { hydrationConfig } from "./query-client";
|
|
51
|
+
import { createCaller, createContext } from "./server";
|
|
52
|
+
|
|
53
|
+
const createRSCContext = cache(async () =>
|
|
54
|
+
createContext({ headers: await headers() })
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export const caller = createCaller(createRSCContext);
|
|
58
|
+
export const crpc = createServerCRPCProxy({ api });
|
|
59
|
+
|
|
60
|
+
function createServerQueryClient() {
|
|
61
|
+
return new QueryClient({
|
|
62
|
+
defaultOptions: {
|
|
63
|
+
...hydrationConfig,
|
|
64
|
+
...getServerQueryClientOptions({
|
|
65
|
+
getToken: caller.getToken,
|
|
66
|
+
convexSiteUrl: process.env.NEXT_PUBLIC_CONVEX_SITE_URL!,
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const getQueryClient = cache(createServerQueryClient);
|
|
73
|
+
|
|
74
|
+
export function prefetch<T extends { queryKey: readonly unknown[] }>(
|
|
75
|
+
queryOptions: T
|
|
76
|
+
): void {
|
|
77
|
+
void getQueryClient().prefetchQuery(queryOptions);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function preloadQuery<
|
|
81
|
+
TQueryFnData = unknown,
|
|
82
|
+
TError = Error,
|
|
83
|
+
TData = TQueryFnData,
|
|
84
|
+
TQueryKey extends readonly unknown[] = readonly unknown[],
|
|
85
|
+
>(
|
|
86
|
+
options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>
|
|
87
|
+
): Promise<TData> {
|
|
88
|
+
return getQueryClient().fetchQuery(options);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function HydrateClient({ children }: { children: React.ReactNode }) {
|
|
92
|
+
const queryClient = getQueryClient();
|
|
93
|
+
const dehydratedState = dehydrate(queryClient);
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<HydrationBoundary state={dehydratedState}>{children}</HydrationBoundary>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 8.A.4 Pass server token to provider
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
// app/(app)/layout.tsx
|
|
105
|
+
import { AppConvexProvider } from "@/lib/convex/convex-provider";
|
|
106
|
+
import { caller } from "@/lib/convex/rsc";
|
|
107
|
+
|
|
108
|
+
export default async function AppLayout({
|
|
109
|
+
children,
|
|
110
|
+
}: {
|
|
111
|
+
children: React.ReactNode;
|
|
112
|
+
}) {
|
|
113
|
+
const token = await caller.getToken();
|
|
114
|
+
return <AppConvexProvider token={token}>{children}</AppConvexProvider>;
|
|
115
|
+
}
|
|
116
|
+
```
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
## 7. Client Core (after auth gate)
|
|
2
|
+
|
|
3
|
+
### 7.1 Auth client setup
|
|
4
|
+
|
|
5
|
+
Prerequisite:
|
|
6
|
+
|
|
7
|
+
1. Section 6.10 / Section 11.3 auth sign-in gate is green.
|
|
8
|
+
|
|
9
|
+
**Create:** `src/lib/convex/auth-client.ts`
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import type { Auth } from "@convex/auth-shared";
|
|
13
|
+
import { adminClient, inferAdditionalFields } from "better-auth/client/plugins";
|
|
14
|
+
import { createAuthClient } from "better-auth/react";
|
|
15
|
+
import { convexClient } from "kitcn/auth/client";
|
|
16
|
+
import { createAuthMutations } from "kitcn/react";
|
|
17
|
+
|
|
18
|
+
export const authClient = createAuthClient({
|
|
19
|
+
baseURL: process.env.NEXT_PUBLIC_SITE_URL!,
|
|
20
|
+
sessionOptions: {
|
|
21
|
+
// Disable session polling on tab focus (saves ~500ms HTTP call per focus)
|
|
22
|
+
refetchOnWindowFocus: false,
|
|
23
|
+
},
|
|
24
|
+
plugins: [inferAdditionalFields<Auth>(), adminClient(), convexClient()],
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const { useActiveOrganization, useListOrganizations } = authClient;
|
|
28
|
+
|
|
29
|
+
export const {
|
|
30
|
+
useSignOutMutationOptions,
|
|
31
|
+
useSignInSocialMutationOptions,
|
|
32
|
+
useSignInMutationOptions,
|
|
33
|
+
useSignUpMutationOptions,
|
|
34
|
+
} = createAuthMutations(authClient);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 7.2 QueryClient setup
|
|
38
|
+
|
|
39
|
+
**Create:** `src/lib/convex/query-client.ts`
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import {
|
|
43
|
+
type DefaultOptions,
|
|
44
|
+
defaultShouldDehydrateQuery,
|
|
45
|
+
QueryCache,
|
|
46
|
+
QueryClient,
|
|
47
|
+
} from "@tanstack/react-query";
|
|
48
|
+
import { isCRPCClientError, isCRPCError } from "kitcn/crpc";
|
|
49
|
+
import SuperJSON from "superjson";
|
|
50
|
+
|
|
51
|
+
export const hydrationConfig: Pick<DefaultOptions, "dehydrate" | "hydrate"> = {
|
|
52
|
+
dehydrate: {
|
|
53
|
+
serializeData: SuperJSON.serialize,
|
|
54
|
+
shouldDehydrateQuery: (query) =>
|
|
55
|
+
defaultShouldDehydrateQuery(query) || query.state.status === "pending",
|
|
56
|
+
shouldRedactErrors: () => false,
|
|
57
|
+
},
|
|
58
|
+
hydrate: {
|
|
59
|
+
deserializeData: SuperJSON.deserialize,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export function createQueryClient() {
|
|
64
|
+
return new QueryClient({
|
|
65
|
+
queryCache: new QueryCache({
|
|
66
|
+
onError: (error) => {
|
|
67
|
+
if (isCRPCClientError(error)) {
|
|
68
|
+
console.warn(`[CRPC] ${error.code}:`, error.functionName);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
defaultOptions: {
|
|
73
|
+
...hydrationConfig,
|
|
74
|
+
queries: {
|
|
75
|
+
retry: (failureCount, error) => {
|
|
76
|
+
if (isCRPCError(error)) return false;
|
|
77
|
+
return failureCount < 3;
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 7.3 cRPC React context
|
|
86
|
+
|
|
87
|
+
**Create:** `src/lib/convex/crpc.tsx`
|
|
88
|
+
|
|
89
|
+
Preconditions:
|
|
90
|
+
|
|
91
|
+
1. Complete Section 5.5 first so `@convex/api` exists.
|
|
92
|
+
2. Complete Section 7.4 so `CRPCProvider` is mounted before any `useCRPC()` call.
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
import { api } from "@convex/api";
|
|
96
|
+
import { createCRPCContext } from "kitcn/react";
|
|
97
|
+
|
|
98
|
+
export const { CRPCProvider, useCRPC, useCRPCClient } = createCRPCContext({
|
|
99
|
+
api,
|
|
100
|
+
convexSiteUrl: process.env.NEXT_PUBLIC_CONVEX_SITE_URL!,
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 7.4 Provider composition
|
|
105
|
+
|
|
106
|
+
**Create:** `src/lib/convex/convex-provider.tsx`
|
|
107
|
+
|
|
108
|
+
Hard rule:
|
|
109
|
+
|
|
110
|
+
1. Any component using `useCRPC`, `useCRPCClient`, or cRPC hooks must render under `CRPCProvider`.
|
|
111
|
+
2. If not, runtime will crash with `useCRPC must be used within CRPCProvider`.
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
"use client";
|
|
115
|
+
|
|
116
|
+
import { QueryClientProvider as TanstackQueryClientProvider } from "@tanstack/react-query";
|
|
117
|
+
import { ConvexAuthProvider } from "kitcn/auth/client";
|
|
118
|
+
import {
|
|
119
|
+
ConvexReactClient,
|
|
120
|
+
getConvexQueryClientSingleton,
|
|
121
|
+
getQueryClientSingleton,
|
|
122
|
+
useAuthStore,
|
|
123
|
+
} from "kitcn/react";
|
|
124
|
+
import type { ReactNode } from "react";
|
|
125
|
+
|
|
126
|
+
import { authClient } from "./auth-client";
|
|
127
|
+
import { CRPCProvider } from "./crpc";
|
|
128
|
+
import { createQueryClient } from "./query-client";
|
|
129
|
+
|
|
130
|
+
const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL!);
|
|
131
|
+
|
|
132
|
+
export function AppConvexProvider({
|
|
133
|
+
children,
|
|
134
|
+
token,
|
|
135
|
+
}: {
|
|
136
|
+
children: ReactNode;
|
|
137
|
+
token?: string;
|
|
138
|
+
}) {
|
|
139
|
+
return (
|
|
140
|
+
<ConvexAuthProvider
|
|
141
|
+
authClient={authClient}
|
|
142
|
+
client={convex}
|
|
143
|
+
initialToken={token}
|
|
144
|
+
>
|
|
145
|
+
<QueryProvider>{children}</QueryProvider>
|
|
146
|
+
</ConvexAuthProvider>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function QueryProvider({ children }: { children: ReactNode }) {
|
|
151
|
+
const authStore = useAuthStore();
|
|
152
|
+
|
|
153
|
+
const queryClient = getQueryClientSingleton(createQueryClient);
|
|
154
|
+
const convexQueryClient = getConvexQueryClientSingleton({
|
|
155
|
+
authStore,
|
|
156
|
+
convex,
|
|
157
|
+
queryClient,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<TanstackQueryClientProvider client={queryClient}>
|
|
162
|
+
<CRPCProvider convexClient={convex} convexQueryClient={convexQueryClient}>
|
|
163
|
+
{children}
|
|
164
|
+
</CRPCProvider>
|
|
165
|
+
</TanstackQueryClientProvider>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Provider mount checklist:
|
|
171
|
+
|
|
172
|
+
1. `AppConvexProvider` wraps app routes before client feature components render.
|
|
173
|
+
2. `CRPCProvider` is nested inside TanStack Query provider (`QueryClientProvider`).
|
|
174
|
+
3. Next.js apps pass token where required (Section 8.A.4) or intentionally run without token for public-only paths.
|
|
175
|
+
|