kitcn 0.0.1 → 0.12.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/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 +13255 -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 -35
- 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 +759 -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,194 @@
|
|
|
1
|
+
//#region src/crpc/transformer.ts
|
|
2
|
+
const isPlainObject = (value) => {
|
|
3
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
4
|
+
const prototype = Object.getPrototypeOf(value);
|
|
5
|
+
return prototype === Object.prototype || prototype === null;
|
|
6
|
+
};
|
|
7
|
+
const CODEC_MARKER_KEY = "__crpc";
|
|
8
|
+
const CODEC_MARKER_VALUE = 1;
|
|
9
|
+
const CODEC_TAG_KEY = "t";
|
|
10
|
+
const CODEC_VALUE_KEY = "v";
|
|
11
|
+
const hasOnlyCodecPayloadKeys = (value) => {
|
|
12
|
+
let keyCount = 0;
|
|
13
|
+
for (const key in value) {
|
|
14
|
+
if (!Object.hasOwn(value, key)) continue;
|
|
15
|
+
keyCount += 1;
|
|
16
|
+
if (key !== CODEC_MARKER_KEY && key !== CODEC_TAG_KEY && key !== CODEC_VALUE_KEY) return false;
|
|
17
|
+
if (keyCount > 3) return false;
|
|
18
|
+
}
|
|
19
|
+
return keyCount === 3;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Date wire tag (Convex-style reserved key).
|
|
23
|
+
*/
|
|
24
|
+
const DATE_CODEC_TAG = "$date";
|
|
25
|
+
/**
|
|
26
|
+
* Built-in Date codec.
|
|
27
|
+
*/
|
|
28
|
+
const dateWireCodec = {
|
|
29
|
+
tag: DATE_CODEC_TAG,
|
|
30
|
+
isType: (value) => value instanceof Date,
|
|
31
|
+
encode: (value) => value.getTime(),
|
|
32
|
+
decode: (value) => {
|
|
33
|
+
if (typeof value !== "number") return value;
|
|
34
|
+
return new Date(value);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Build a recursive tagged transformer from codecs.
|
|
39
|
+
*/
|
|
40
|
+
const createTaggedTransformer = (codecs) => {
|
|
41
|
+
const codecByTag = /* @__PURE__ */ new Map();
|
|
42
|
+
for (const codec of codecs) {
|
|
43
|
+
if (!codec.tag.startsWith("$")) throw new Error(`Invalid wire codec tag '${codec.tag}'. Tags must start with '$'.`);
|
|
44
|
+
if (codecByTag.has(codec.tag)) throw new Error(`Duplicate wire codec tag '${codec.tag}'.`);
|
|
45
|
+
codecByTag.set(codec.tag, codec);
|
|
46
|
+
}
|
|
47
|
+
const serialize = (value) => {
|
|
48
|
+
for (const codec of codecs) if (codec.isType(value)) return {
|
|
49
|
+
[CODEC_MARKER_KEY]: CODEC_MARKER_VALUE,
|
|
50
|
+
[CODEC_TAG_KEY]: codec.tag,
|
|
51
|
+
[CODEC_VALUE_KEY]: serialize(codec.encode(value))
|
|
52
|
+
};
|
|
53
|
+
if (Array.isArray(value)) {
|
|
54
|
+
let result;
|
|
55
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
56
|
+
const item = value[index];
|
|
57
|
+
const serialized = serialize(item);
|
|
58
|
+
if (serialized !== item) {
|
|
59
|
+
if (!result) result = value.slice();
|
|
60
|
+
result[index] = serialized;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result ?? value;
|
|
64
|
+
}
|
|
65
|
+
if (isPlainObject(value)) {
|
|
66
|
+
let result;
|
|
67
|
+
for (const key in value) {
|
|
68
|
+
if (!Object.hasOwn(value, key)) continue;
|
|
69
|
+
const nested = value[key];
|
|
70
|
+
const serialized = serialize(nested);
|
|
71
|
+
if (serialized !== nested) {
|
|
72
|
+
if (!result) result = { ...value };
|
|
73
|
+
result[key] = serialized;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result ?? value;
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
};
|
|
80
|
+
const deserialize = (value) => {
|
|
81
|
+
if (Array.isArray(value)) {
|
|
82
|
+
let result;
|
|
83
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
84
|
+
const item = value[index];
|
|
85
|
+
const deserialized = deserialize(item);
|
|
86
|
+
if (deserialized !== item) {
|
|
87
|
+
if (!result) result = value.slice();
|
|
88
|
+
result[index] = deserialized;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return result ?? value;
|
|
92
|
+
}
|
|
93
|
+
if (isPlainObject(value)) {
|
|
94
|
+
const marker = value[CODEC_MARKER_KEY];
|
|
95
|
+
const tag = value[CODEC_TAG_KEY];
|
|
96
|
+
if (marker === CODEC_MARKER_VALUE && typeof tag === "string" && CODEC_VALUE_KEY in value && hasOnlyCodecPayloadKeys(value)) {
|
|
97
|
+
const codec = codecByTag.get(tag);
|
|
98
|
+
if (codec) return codec.decode(deserialize(value[CODEC_VALUE_KEY]));
|
|
99
|
+
}
|
|
100
|
+
let result;
|
|
101
|
+
for (const key in value) {
|
|
102
|
+
if (!Object.hasOwn(value, key)) continue;
|
|
103
|
+
const nested = value[key];
|
|
104
|
+
const deserialized = deserialize(nested);
|
|
105
|
+
if (deserialized !== nested) {
|
|
106
|
+
if (!result) result = { ...value };
|
|
107
|
+
result[key] = deserialized;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return result ?? value;
|
|
111
|
+
}
|
|
112
|
+
return value;
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
serialize,
|
|
116
|
+
deserialize
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Default cRPC transformer (Date-enabled).
|
|
121
|
+
*/
|
|
122
|
+
const defaultCRPCTransformer = createTaggedTransformer([dateWireCodec]);
|
|
123
|
+
const DEFAULT_COMBINED_TRANSFORMER = {
|
|
124
|
+
input: defaultCRPCTransformer,
|
|
125
|
+
output: defaultCRPCTransformer
|
|
126
|
+
};
|
|
127
|
+
const IDENTITY_TRANSFORMER = {
|
|
128
|
+
input: {
|
|
129
|
+
serialize: (value) => value,
|
|
130
|
+
deserialize: (value) => value
|
|
131
|
+
},
|
|
132
|
+
output: {
|
|
133
|
+
serialize: (value) => value,
|
|
134
|
+
deserialize: (value) => value
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Normalize transformer config to split input/output shape.
|
|
139
|
+
*/
|
|
140
|
+
const normalizeCustomTransformer = (transformer) => {
|
|
141
|
+
if (!transformer) return;
|
|
142
|
+
if ("input" in transformer && "output" in transformer) return transformer;
|
|
143
|
+
return {
|
|
144
|
+
input: transformer,
|
|
145
|
+
output: transformer
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Compose user transformer with default Date transformer.
|
|
150
|
+
*
|
|
151
|
+
* Date transformer is always active:
|
|
152
|
+
* - serialize: user -> default(Date)
|
|
153
|
+
* - deserialize: default(Date) -> user
|
|
154
|
+
*/
|
|
155
|
+
const composeWithDefault = (transformer) => {
|
|
156
|
+
if (!transformer) return defaultCRPCTransformer;
|
|
157
|
+
return {
|
|
158
|
+
serialize: (value) => defaultCRPCTransformer.serialize(transformer.serialize(value)),
|
|
159
|
+
deserialize: (value) => transformer.deserialize(defaultCRPCTransformer.deserialize(value))
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
const transformerCache = /* @__PURE__ */ new WeakMap();
|
|
163
|
+
/**
|
|
164
|
+
* Normalize transformer config to split input/output shape.
|
|
165
|
+
* User transformers are additive and always composed with default Date handling.
|
|
166
|
+
*/
|
|
167
|
+
const getTransformer = (transformer) => {
|
|
168
|
+
if (!transformer) return DEFAULT_COMBINED_TRANSFORMER;
|
|
169
|
+
const cacheKey = transformer;
|
|
170
|
+
const cached = transformerCache.get(cacheKey);
|
|
171
|
+
if (cached) return cached;
|
|
172
|
+
const custom = normalizeCustomTransformer(transformer);
|
|
173
|
+
const resolved = {
|
|
174
|
+
input: composeWithDefault(custom?.input),
|
|
175
|
+
output: composeWithDefault(custom?.output)
|
|
176
|
+
};
|
|
177
|
+
transformerCache.set(cacheKey, resolved);
|
|
178
|
+
return resolved;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Encode request payloads (input direction).
|
|
182
|
+
*/
|
|
183
|
+
const encodeWire = (value, transformer) => getTransformer(transformer).input.serialize(value);
|
|
184
|
+
/**
|
|
185
|
+
* Decode response payloads (output direction).
|
|
186
|
+
*/
|
|
187
|
+
const decodeWire = (value, transformer) => getTransformer(transformer).output.deserialize(value);
|
|
188
|
+
/**
|
|
189
|
+
* Exposed identity transformer for advanced composition.
|
|
190
|
+
*/
|
|
191
|
+
const identityTransformer = IDENTITY_TRANSFORMER;
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
export { defaultCRPCTransformer as a, identityTransformer as c, decodeWire as i, createTaggedTransformer as n, encodeWire as o, dateWireCodec as r, getTransformer as s, DATE_CODEC_TAG as t };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/internal/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Filter object type to only known keys from reference type.
|
|
4
|
+
* Pattern from Drizzle ORM: drizzle-orm/src/utils.ts:151-156
|
|
5
|
+
*
|
|
6
|
+
* Prevents extra properties from widening inferred types.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* type Config = { name: string; age: number };
|
|
10
|
+
* type Input = { name: string; age: number; extra: boolean };
|
|
11
|
+
* type Filtered = KnownKeysOnly<Input, Config>; // { name: string; age: number }
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
type KnownKeysOnly<T, K> = { [P in keyof T]: P extends keyof K ? T[P] : never };
|
|
15
|
+
/**
|
|
16
|
+
* Narrow a type to an expected shape without losing inference.
|
|
17
|
+
* Pattern from Drizzle ORM: drizzle-orm/src/utils.ts
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
type Assume<T, U> = T extends U ? T : U;
|
|
21
|
+
/**
|
|
22
|
+
* Extract return type if function, otherwise use the value type.
|
|
23
|
+
* Pattern from Drizzle ORM: drizzle-orm/src/relations.ts
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
type ReturnTypeOrValue<T> = T extends ((...args: any[]) => infer R) ? R : T;
|
|
27
|
+
/**
|
|
28
|
+
* Simplify complex type intersections for better IDE display.
|
|
29
|
+
* Pattern from Drizzle ORM: The & {} intersection "seals" the type to prevent
|
|
30
|
+
* distributive conditional behavior that can cause union widening.
|
|
31
|
+
* @see https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/utils.ts#L144-L149
|
|
32
|
+
*/
|
|
33
|
+
type Simplify<TType> = TType extends any[] | Date ? TType : { [K in keyof TType]: TType[K] } & {};
|
|
34
|
+
/**
|
|
35
|
+
* Omit keys without removing a potential union.
|
|
36
|
+
* Unlike standard Omit, this preserves union types.
|
|
37
|
+
*/
|
|
38
|
+
type DistributiveOmit<TObj, TKey extends keyof any> = TObj extends any ? Omit<TObj, TKey> : never;
|
|
39
|
+
/** Makes the object recursively optional */
|
|
40
|
+
type DeepPartial<TObject> = TObject extends object ? { [P in keyof TObject]?: DeepPartial<TObject[P]> } : TObject;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { ReturnTypeOrValue as a, KnownKeysOnly as i, DeepPartial as n, Simplify as o, DistributiveOmit as r, Assume as t };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/server/types.d.ts
|
|
4
|
+
/** Marker for unset values - branded type to distinguish "not set" from actual types */
|
|
5
|
+
type UnsetMarker = {
|
|
6
|
+
readonly __brand: 'UnsetMarker';
|
|
7
|
+
};
|
|
8
|
+
/** Marker to enforce middleware returns next() result */
|
|
9
|
+
type MiddlewareMarker = {
|
|
10
|
+
readonly __brand: 'MiddlewareMarker';
|
|
11
|
+
};
|
|
12
|
+
/** Flatten intersection types for better IDE display */
|
|
13
|
+
type Simplify<T> = { [K in keyof T]: T[K] } & {};
|
|
14
|
+
/**
|
|
15
|
+
* Merge context types - preserves existing properties while adding new ones
|
|
16
|
+
* - If TWith is UnsetMarker, returns TType unchanged
|
|
17
|
+
* - If TType is UnsetMarker, returns TWith (no __brand leakage)
|
|
18
|
+
* - Otherwise, merges with TWith properties taking precedence
|
|
19
|
+
*/
|
|
20
|
+
type Overwrite<TType, TWith> = TWith extends UnsetMarker ? TType : TType extends UnsetMarker ? TWith : TWith extends object ? Simplify<Omit<TType, keyof TWith> & TWith> : TType;
|
|
21
|
+
/** Resolve type only if it's not UnsetMarker */
|
|
22
|
+
type ResolveIfSet<T, TFallback> = T extends UnsetMarker ? TFallback : T;
|
|
23
|
+
/**
|
|
24
|
+
* Merge two ZodObject types into a single ZodObject with combined shape
|
|
25
|
+
* Used for chained .input() calls
|
|
26
|
+
*/
|
|
27
|
+
type MergeZodObjects<T, U> = T extends z.ZodObject<infer A> ? U extends z.ZodObject<infer B> ? z.ZodObject<Simplify<A & B>> : T : T;
|
|
28
|
+
/**
|
|
29
|
+
* Intersect two types, handling UnsetMarker and ZodObject merging
|
|
30
|
+
* - If TType is UnsetMarker, returns TWith
|
|
31
|
+
* - If TWith is UnsetMarker, returns TType
|
|
32
|
+
* - If both are ZodObjects, merges their shapes into a new ZodObject
|
|
33
|
+
* - Otherwise, returns the intersection simplified
|
|
34
|
+
*/
|
|
35
|
+
type IntersectIfDefined<TType, TWith> = TType extends UnsetMarker ? TWith : TWith extends UnsetMarker ? TType : MergeZodObjects<TType, TWith>;
|
|
36
|
+
/** Result wrapper that enforces middleware returns next() */
|
|
37
|
+
type MiddlewareResult<TContext> = {
|
|
38
|
+
readonly marker: MiddlewareMarker;
|
|
39
|
+
ctx: TContext;
|
|
40
|
+
};
|
|
41
|
+
/** Function to get raw input before validation */
|
|
42
|
+
type GetRawInputFn = () => Promise<unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Next function overloads - key to automatic context and input inference
|
|
45
|
+
* Matches tRPC's pattern: can modify context, input, or both
|
|
46
|
+
*/
|
|
47
|
+
type MiddlewareNext<TContextOverridesIn> = {
|
|
48
|
+
/** Continue without modification - passes through existing overrides */(): Promise<MiddlewareResult<TContextOverridesIn>>; /** Continue with modified context and/or input */
|
|
49
|
+
<$ContextOverride>(opts: {
|
|
50
|
+
ctx?: $ContextOverride;
|
|
51
|
+
input?: unknown;
|
|
52
|
+
}): Promise<MiddlewareResult<$ContextOverride>>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Middleware function signature with input access (tRPC-compatible)
|
|
56
|
+
*
|
|
57
|
+
* @typeParam TContext - Base context type
|
|
58
|
+
* @typeParam TMeta - Procedure metadata type
|
|
59
|
+
* @typeParam TContextOverridesIn - Context overrides from previous middleware
|
|
60
|
+
* @typeParam $ContextOverridesOut - Context overrides this middleware adds (inferred from next())
|
|
61
|
+
* @typeParam TInputOut - Parsed input type (unknown if before .input(), typed if after)
|
|
62
|
+
*/
|
|
63
|
+
type MiddlewareFunction<TContext, TMeta, TContextOverridesIn, $ContextOverridesOut, TInputOut = unknown> = (opts: {
|
|
64
|
+
ctx: Simplify<Overwrite<TContext, TContextOverridesIn>>;
|
|
65
|
+
meta: TMeta;
|
|
66
|
+
input: TInputOut;
|
|
67
|
+
getRawInput: GetRawInputFn;
|
|
68
|
+
next: MiddlewareNext<TContextOverridesIn>;
|
|
69
|
+
}) => Promise<MiddlewareResult<$ContextOverridesOut>>;
|
|
70
|
+
/** Stored middleware with type info erased for runtime */
|
|
71
|
+
type AnyMiddleware = MiddlewareFunction<any, any, any, any, any>;
|
|
72
|
+
/**
|
|
73
|
+
* Middleware builder for creating reusable, composable middleware chains
|
|
74
|
+
* Similar to tRPC's MiddlewareBuilder
|
|
75
|
+
*
|
|
76
|
+
* @typeParam TContext - Base context type
|
|
77
|
+
* @typeParam TMeta - Procedure metadata type
|
|
78
|
+
* @typeParam $ContextOverridesOut - Accumulated context overrides
|
|
79
|
+
* @typeParam TInputOut - Input type this middleware chain expects
|
|
80
|
+
*/
|
|
81
|
+
type MiddlewareBuilder<TContext, TMeta, $ContextOverridesOut, TInputOut = unknown> = {
|
|
82
|
+
/** Internal array of middleware functions */_middlewares: AnyMiddleware[]; /** Chain another middleware to this builder */
|
|
83
|
+
pipe<$NewContextOverrides>(fn: MiddlewareFunction<TContext, TMeta, $ContextOverridesOut, $NewContextOverrides, TInputOut>): MiddlewareBuilder<TContext, TMeta, Overwrite<$ContextOverridesOut, $NewContextOverrides>, TInputOut>;
|
|
84
|
+
};
|
|
85
|
+
/** Type-erased middleware builder for runtime */
|
|
86
|
+
type AnyMiddlewareBuilder = MiddlewareBuilder<any, any, any, any>;
|
|
87
|
+
//#endregion
|
|
88
|
+
export { MergeZodObjects as a, MiddlewareMarker as c, Overwrite as d, ResolveIfSet as f, IntersectIfDefined as i, MiddlewareNext as l, UnsetMarker as m, AnyMiddlewareBuilder as n, MiddlewareBuilder as o, Simplify as p, GetRawInputFn as r, MiddlewareFunction as s, AnyMiddleware as t, MiddlewareResult as u };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { O as CombinedDataTransformer, n as HttpClientError } from "./http-types-DqJubRPJ.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 };
|