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,169 @@
1
+ import { a as isCRPCErrorCode, i as isCRPCError, n as defaultIsUnauthorized, r as isCRPCClientError, t as CRPCClientError } from "../error-BZEnI7Sq.js";
2
+ import { a as defaultCRPCTransformer, c as identityTransformer, i as decodeWire, n as createTaggedTransformer, o as encodeWire, r as dateWireCodec, s as getTransformer, t as DATE_CODEC_TAG } from "../transformer-DtDhR3Lc.js";
3
+ import { n as convexInfiniteQueryOptions, r as convexQuery, t as convexAction } from "../query-options-Dw7cOyXl.js";
4
+
5
+ //#region src/crpc/auth-error.ts
6
+ /**
7
+ * Auth Mutation Error
8
+ *
9
+ * Framework-agnostic error class for Better Auth mutations.
10
+ */
11
+ /**
12
+ * Error thrown when a Better Auth mutation fails.
13
+ * Contains the original error details from Better Auth.
14
+ */
15
+ var AuthMutationError = class extends Error {
16
+ /** Error code from Better Auth (e.g., 'INVALID_PASSWORD', 'EMAIL_ALREADY_REGISTERED') */
17
+ code;
18
+ /** HTTP status code */
19
+ status;
20
+ /** HTTP status text */
21
+ statusText;
22
+ constructor(authError) {
23
+ super(authError.message || authError.statusText);
24
+ this.name = "AuthMutationError";
25
+ this.code = authError.code;
26
+ this.status = authError.status;
27
+ this.statusText = authError.statusText;
28
+ }
29
+ };
30
+ /**
31
+ * Type guard to check if an error is an AuthMutationError.
32
+ */
33
+ function isAuthMutationError(error) {
34
+ return error instanceof AuthMutationError;
35
+ }
36
+
37
+ //#endregion
38
+ //#region src/crpc/http-types.ts
39
+ /** HTTP client error */
40
+ var HttpClientError = class extends Error {
41
+ name = "HttpClientError";
42
+ code;
43
+ status;
44
+ procedureName;
45
+ constructor(opts) {
46
+ super(opts.message ?? `${opts.code}: ${opts.procedureName}`);
47
+ this.code = opts.code;
48
+ this.status = opts.status;
49
+ this.procedureName = opts.procedureName;
50
+ }
51
+ };
52
+ /** Type guard for HttpClientError */
53
+ const isHttpClientError = (error) => error instanceof HttpClientError;
54
+
55
+ //#endregion
56
+ //#region src/crpc/http-client.ts
57
+ /**
58
+ * HTTP Client Helpers
59
+ *
60
+ * Framework-agnostic utilities for executing HTTP requests
61
+ * against Convex HTTP endpoints.
62
+ */
63
+ /** Reserved keys that are not part of JSON body */
64
+ const RESERVED_KEYS = new Set([
65
+ "params",
66
+ "searchParams",
67
+ "form",
68
+ "fetch",
69
+ "init",
70
+ "headers"
71
+ ]);
72
+ /**
73
+ * Replace URL path parameters with actual values.
74
+ * e.g., '/users/:id' with { id: '123' } -> '/users/123'
75
+ */
76
+ function replaceUrlParam(url, params) {
77
+ return url.replace(/:(\w+)/g, (_, key) => {
78
+ const value = params[key];
79
+ return value !== void 0 ? encodeURIComponent(value) : `:${key}`;
80
+ });
81
+ }
82
+ /**
83
+ * Build URLSearchParams from query object.
84
+ * Handles array values as multiple params with same key (like Hono).
85
+ */
86
+ function buildSearchParams(query) {
87
+ const params = new URLSearchParams();
88
+ for (const [key, value] of Object.entries(query)) if (Array.isArray(value)) for (const v of value) params.append(key, v);
89
+ else if (value !== void 0 && value !== null) params.append(key, value);
90
+ return params;
91
+ }
92
+ /**
93
+ * Hono-style HTTP request executor.
94
+ * Processes args in the same way as Hono's ClientRequestImpl.fetch().
95
+ */
96
+ async function executeHttpRequest(opts) {
97
+ const { method, path } = opts.route;
98
+ const args = opts.args ?? {};
99
+ let rBody;
100
+ let cType;
101
+ if (args.form) {
102
+ const form = new FormData();
103
+ for (const [k, v] of Object.entries(args.form)) if (Array.isArray(v)) for (const v2 of v) form.append(k, v2);
104
+ else form.append(k, v);
105
+ rBody = form;
106
+ } else {
107
+ const jsonBody = {};
108
+ for (const [key, value] of Object.entries(args)) if (!RESERVED_KEYS.has(key) && value !== void 0) jsonBody[key] = value;
109
+ if (Object.keys(jsonBody).length > 0) {
110
+ rBody = JSON.stringify(opts.transformer.input.serialize(jsonBody));
111
+ cType = "application/json";
112
+ }
113
+ }
114
+ const argsClientOpts = {};
115
+ if (args.fetch) argsClientOpts.fetch = args.fetch;
116
+ if (args.init) argsClientOpts.init = args.init;
117
+ if (args.headers) argsClientOpts.headers = args.headers;
118
+ const mergedClientOpts = {
119
+ ...opts.clientOpts,
120
+ ...argsClientOpts
121
+ };
122
+ const resolvedBaseHeaders = typeof opts.baseHeaders === "function" ? await opts.baseHeaders() : opts.baseHeaders;
123
+ const headerValues = { ...typeof mergedClientOpts.headers === "function" ? await mergedClientOpts.headers() : mergedClientOpts.headers };
124
+ if (cType) headerValues["Content-Type"] = cType;
125
+ const finalHeaders = {};
126
+ if (resolvedBaseHeaders) {
127
+ for (const [key, value] of Object.entries(resolvedBaseHeaders)) if (value !== void 0) finalHeaders[key] = value;
128
+ }
129
+ Object.assign(finalHeaders, headerValues);
130
+ let url = opts.convexSiteUrl + path;
131
+ if (args.params) url = opts.convexSiteUrl + replaceUrlParam(path, args.params);
132
+ if (args.searchParams) {
133
+ const queryString = buildSearchParams(args.searchParams).toString();
134
+ if (queryString) url = `${url}?${queryString}`;
135
+ }
136
+ const methodUpperCase = method.toUpperCase();
137
+ const setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
138
+ const response = await (mergedClientOpts.fetch ?? opts.baseFetch ?? globalThis.fetch)(url, {
139
+ body: setBody ? rBody : void 0,
140
+ method: methodUpperCase,
141
+ headers: finalHeaders,
142
+ ...mergedClientOpts.init
143
+ });
144
+ if (!response.ok) {
145
+ const errorData = await response.json().catch(() => ({ error: {
146
+ code: "UNKNOWN",
147
+ message: response.statusText
148
+ } }));
149
+ const errorCode = errorData?.error?.code || "UNKNOWN";
150
+ const errorMessage = errorData?.error?.message || response.statusText;
151
+ throw new HttpClientError({
152
+ code: errorCode,
153
+ status: response.status,
154
+ procedureName: opts.procedureName,
155
+ message: errorMessage
156
+ });
157
+ }
158
+ if (response.headers.get("content-length") === "0" || response.status === 204) return;
159
+ if ((response.headers.get("content-type") || "").includes("application/json")) return opts.transformer.output.deserialize(await response.json());
160
+ return response.text();
161
+ }
162
+
163
+ //#endregion
164
+ //#region src/crpc/types.ts
165
+ /** Symbol key for attaching FunctionReference to options (non-serializable) */
166
+ const FUNC_REF_SYMBOL = Symbol.for("convex.funcRef");
167
+
168
+ //#endregion
169
+ export { AuthMutationError, CRPCClientError, DATE_CODEC_TAG, FUNC_REF_SYMBOL, HttpClientError, RESERVED_KEYS, buildSearchParams, convexAction, convexInfiniteQueryOptions, convexQuery, createTaggedTransformer, dateWireCodec, decodeWire, defaultCRPCTransformer, defaultIsUnauthorized, encodeWire, executeHttpRequest, getTransformer, identityTransformer, isAuthMutationError, isCRPCClientError, isCRPCError, isCRPCErrorCode, isHttpClientError, replaceUrlParam };
@@ -0,0 +1,144 @@
1
+ import { c as omit, l as pick, t as addFieldsToValidator } from "./validators-B7oIJCAp.js";
2
+
3
+ //#region src/internal/upstream/server/customFunctions.ts
4
+ /**
5
+ * A helper for defining a Customization when your mod doesn't need to add or remove
6
+ * anything from args.
7
+ * @param modifyCtx A function that defines how to modify the ctx.
8
+ * @returns A ctx delta to be applied to the original ctx.
9
+ */
10
+ function customCtx(modifyCtx) {
11
+ return {
12
+ args: {},
13
+ input: async (ctx, _, extra) => ({
14
+ ctx: await modifyCtx(ctx, extra),
15
+ args: {}
16
+ })
17
+ };
18
+ }
19
+ /**
20
+ * A Customization that doesn't add or remove any context or args.
21
+ */
22
+ const NoOp = {
23
+ args: {},
24
+ input() {
25
+ return {
26
+ args: {},
27
+ ctx: {}
28
+ };
29
+ }
30
+ };
31
+ /**
32
+ * customMutation helps define custom behavior on top of `mutation`
33
+ * or `internalMutation` by passing a function that modifies the ctx and args.
34
+ *
35
+ * Example usage:
36
+ * ```js
37
+ * const myMutationBuilder = customMutation(mutation, {
38
+ * args: { sessionId: v.id("sessions") },
39
+ * input: async (ctx, args) => {
40
+ * const user = await getUserOrNull(ctx);
41
+ * const session = await db.get(sessionId);
42
+ * const db = wrapDatabaseReader({ user }, ctx.db, rlsRules);
43
+ * return {
44
+ * ctx: { db, user, session },
45
+ * args: {},
46
+ * onSuccess: ({ result }) => {
47
+ * // Optional callback that runs after the function executes
48
+ * // Has access to resources created during input processing
49
+ * console.log(`User ${user.name} returned:`, result);
50
+ * }
51
+ * };
52
+ * },
53
+ * });
54
+ *
55
+ * // Using the custom builder
56
+ * export const setSomeData = myMutationBuilder({
57
+ * args: { someArg: v.string() },
58
+ * handler: async (ctx, args) => {
59
+ * const { db, user, session, scheduler } = ctx;
60
+ * const { someArg } = args;
61
+ * // ...
62
+ * }
63
+ * });
64
+ * ```
65
+ *
66
+ * Simple usage only modifying ctx:
67
+ * ```js
68
+ * const myUserMutation = customMutation(
69
+ * mutation,
70
+ * customCtx(async (ctx) => {
71
+ * return {
72
+ * // Throws an exception if the user isn't logged in
73
+ * user: await getUserByTokenIdentifier(ctx),
74
+ * };
75
+ * })
76
+ * );
77
+ *
78
+ * // Using it
79
+ * export const setMyName = myUserMutation({
80
+ * args: { name: v.string() },
81
+ * handler: async (ctx, args) => {
82
+ * await ctx.db.patch(ctx.user._id, { name: args.name });
83
+ * },
84
+ * });
85
+ *
86
+ * @param mutation The mutation to be modified. Usually `mutation` or `internalMutation`
87
+ * from `_generated/server`.
88
+ * @param customization The modifier to be applied to the mutation, changing ctx and args.
89
+ * @returns A new mutation builder to define queries with modified ctx and args.
90
+ */
91
+ function customMutation(mutation, customization) {
92
+ return customFnBuilder(mutation, customization);
93
+ }
94
+ function customFnBuilder(builder, customization) {
95
+ const customInput = customization.input ?? NoOp.input;
96
+ const inputArgs = customization.args ?? NoOp.args;
97
+ return function customBuilder(fn) {
98
+ const { args, handler = fn, returns, ...extra } = fn;
99
+ if (args) return builder({
100
+ args: addFieldsToValidator(args, inputArgs),
101
+ returns,
102
+ handler: async (ctx, allArgs) => {
103
+ const added = await customInput(ctx, pick(allArgs, Object.keys(inputArgs)), extra);
104
+ const args = omit(allArgs, Object.keys(inputArgs));
105
+ const result = await handler({
106
+ ...ctx,
107
+ ...added.ctx
108
+ }, {
109
+ ...args,
110
+ ...added.args
111
+ });
112
+ if (added.onSuccess) await added.onSuccess({
113
+ ctx,
114
+ args,
115
+ result
116
+ });
117
+ return result;
118
+ }
119
+ });
120
+ if (Object.keys(inputArgs).length > 0) throw new Error("If you're using a custom function with arguments for the input customization, you must declare the arguments for the function too.");
121
+ return builder({
122
+ returns: fn.returns,
123
+ handler: async (ctx, args) => {
124
+ const added = await customInput(ctx, args, extra);
125
+ const result = await handler({
126
+ ...ctx,
127
+ ...added.ctx
128
+ }, {
129
+ ...args,
130
+ ...added.args
131
+ });
132
+ if (added.onSuccess) await added.onSuccess({
133
+ ctx,
134
+ args,
135
+ result
136
+ });
137
+ return result;
138
+ }
139
+ });
140
+ };
141
+ }
142
+
143
+ //#endregion
144
+ export { customCtx as n, customMutation as r, NoOp as t };
@@ -0,0 +1,41 @@
1
+ //#region src/crpc/error.ts
2
+ /**
3
+ * Client-side CRPC error.
4
+ * Mirrors backend CRPCError pattern with typed error codes.
5
+ */
6
+ var CRPCClientError = class extends Error {
7
+ name = "CRPCClientError";
8
+ code;
9
+ functionName;
10
+ constructor(opts) {
11
+ super(opts.message ?? `${opts.code}: ${opts.functionName}`);
12
+ this.code = opts.code;
13
+ this.functionName = opts.functionName;
14
+ }
15
+ };
16
+ /** Type guard for CRPCClientError */
17
+ const isCRPCClientError = (error) => error instanceof CRPCClientError;
18
+ /**
19
+ * Unified check for any deterministic CRPC error (Convex or HTTP).
20
+ * Use in retry logic to skip retrying client errors (4xx).
21
+ */
22
+ const isCRPCError = (error) => {
23
+ if (error instanceof CRPCClientError) return true;
24
+ if (error instanceof Error && error.name === "HttpClientError" && "status" in error && typeof error.status === "number") return error.status < 500;
25
+ return false;
26
+ };
27
+ /** Type guard for specific error code */
28
+ const isCRPCErrorCode = (error, code) => isCRPCClientError(error) && error.code === code;
29
+ /** Default unauthorized detection - checks UNAUTHORIZED code */
30
+ const defaultIsUnauthorized = (error) => {
31
+ if (!error || typeof error !== "object") return false;
32
+ if ("data" in error) {
33
+ const data = error.data;
34
+ if (data && typeof data === "object" && "code" in data) return data.code === "UNAUTHORIZED";
35
+ }
36
+ if ("code" in error) return error.code === "UNAUTHORIZED";
37
+ return false;
38
+ };
39
+
40
+ //#endregion
41
+ export { isCRPCErrorCode as a, isCRPCError as i, defaultIsUnauthorized as n, isCRPCClientError as r, CRPCClientError as t };
@@ -0,0 +1,50 @@
1
+ //#region src/auth/define-auth.ts
2
+ const defineAuth = (definition) => definition;
3
+
4
+ //#endregion
5
+ //#region src/auth/generated-contract-disabled.ts
6
+ const DEFAULT_AUTH_DEFINITION_PATH = "convex/auth.ts";
7
+ const resolveAuthDefinitionPath = (authDefinitionPath) => {
8
+ const normalized = authDefinitionPath?.trim();
9
+ return normalized && normalized.length > 0 ? normalized : DEFAULT_AUTH_DEFINITION_PATH;
10
+ };
11
+ const getGeneratedAuthDisabledReason = (kind, authDefinitionPath) => {
12
+ const resolvedAuthDefinitionPath = resolveAuthDefinitionPath(authDefinitionPath);
13
+ switch (kind) {
14
+ case "default_export_unavailable": return `Auth runtime is disabled. ${resolvedAuthDefinitionPath} default export is unavailable. Export \`default defineAuth((ctx) => ({ ...options, triggers }))\` and run \`kitcn codegen\`.`;
15
+ case "missing_auth_file": return `Auth runtime is disabled. Create ${resolvedAuthDefinitionPath} with \`export default defineAuth(...)\` and run \`kitcn codegen\`.`;
16
+ case "missing_default_export": return `Auth runtime is disabled. ${resolvedAuthDefinitionPath} exists but does not export a default auth definition. Export \`default defineAuth((ctx) => ({ ...options, triggers }))\` and run \`kitcn codegen\`.`;
17
+ }
18
+ };
19
+ const DEFAULT_DISABLED_AUTH_MESSAGE = getGeneratedAuthDisabledReason("missing_auth_file");
20
+ const createDisabledError = (message, exportName) => () => {
21
+ throw new Error(`${message} (${exportName})`);
22
+ };
23
+ const createDisabledRuntimeExport = (message, exportName) => createDisabledError(message, exportName);
24
+ const createDisabledAuthRuntime = (config) => {
25
+ const message = config?.reason ?? DEFAULT_DISABLED_AUTH_MESSAGE;
26
+ return {
27
+ authEnabled: false,
28
+ authClient: {
29
+ authFunctions: {},
30
+ triggers: void 0,
31
+ adapter: createDisabledError(message, "authClient.adapter")
32
+ },
33
+ auth: new Proxy({}, { get() {
34
+ throw new Error(`${message} (auth)`);
35
+ } }),
36
+ getAuth: createDisabledError(message, "getAuth"),
37
+ create: createDisabledRuntimeExport(message, "create"),
38
+ deleteMany: createDisabledRuntimeExport(message, "deleteMany"),
39
+ deleteOne: createDisabledRuntimeExport(message, "deleteOne"),
40
+ findMany: createDisabledRuntimeExport(message, "findMany"),
41
+ findOne: createDisabledRuntimeExport(message, "findOne"),
42
+ updateMany: createDisabledRuntimeExport(message, "updateMany"),
43
+ updateOne: createDisabledRuntimeExport(message, "updateOne"),
44
+ getLatestJwks: createDisabledRuntimeExport(message, "getLatestJwks"),
45
+ rotateKeys: createDisabledRuntimeExport(message, "rotateKeys")
46
+ };
47
+ };
48
+
49
+ //#endregion
50
+ export { defineAuth as i, createDisabledAuthRuntime as n, getGeneratedAuthDisabledReason as r, DEFAULT_AUTH_DEFINITION_PATH as t };