kitcn 0.33.1 → 0.33.2

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.
@@ -1,140 +0,0 @@
1
- import { i as DataTransformerOptions } from "./transformer-BEkxlnss.js";
2
- import { FunctionReference, FunctionReturnType } from "convex/server";
3
-
4
- //#region src/internal/upstream/index.d.ts
5
- type EmptyObject = Record<string, never>;
6
- /**
7
- * Hack! This type causes TypeScript to simplify how it renders object types.
8
- *
9
- * It is functionally the identity for object types, but in practice it can
10
- * simplify expressions like `A & B`.
11
- */
12
- type Expand<ObjectType extends Record<any, any>> = ObjectType extends Record<any, any> ? { [Key in keyof ObjectType]: ObjectType[Key] } : never;
13
- //#endregion
14
- //#region src/server/caller.d.ts
15
- /** Metadata for a single function */
16
- type FnMeta = {
17
- type?: 'query' | 'mutation' | 'action';
18
- [key: string]: unknown;
19
- };
20
- /** Metadata for all functions in a module */
21
- type ModuleMeta = Record<string, FnMeta>;
22
- /** Metadata for all modules - from generated `@convex/api` */
23
- type CallerMeta = Record<string, ModuleMeta>;
24
- /** Options for individual caller function calls */
25
- type CallerOpts = {
26
- /** Skip query silently when unauthenticated (returns null instead of throwing) */skipUnauth?: boolean;
27
- };
28
- type CallerReturn<T, Opts extends CallerOpts | undefined> = Opts extends {
29
- skipUnauth: true;
30
- } ? T | null : T;
31
- type FetchFn<T extends 'query' | 'mutation' | 'action'> = <Fn extends FunctionReference<T>>(fn: Fn, args: Fn['_args'], opts?: CallerOpts) => Promise<FunctionReturnType<Fn> | null>;
32
- type CreateCallerOptions = {
33
- fetchQuery: FetchFn<'query'>;
34
- fetchMutation: FetchFn<'mutation'>;
35
- fetchAction: FetchFn<'action'>;
36
- meta: CallerMeta;
37
- transformer?: DataTransformerOptions;
38
- };
39
- type ServerCallerFn<TApi, K extends keyof TApi> = TApi[K] extends FunctionReference<infer T, 'public'> ? T extends 'query' | 'mutation' | 'action' ? keyof TApi[K]['_args'] extends never ? <Opts extends CallerOpts | undefined = undefined>(args?: EmptyObject, opts?: Opts) => Promise<CallerReturn<FunctionReturnType<TApi[K]>, Opts>> : EmptyObject extends TApi[K]['_args'] ? <Opts extends CallerOpts | undefined = undefined>(args?: TApi[K]['_args'], opts?: Opts) => Promise<CallerReturn<FunctionReturnType<TApi[K]>, Opts>> : <Opts extends CallerOpts | undefined = undefined>(args: TApi[K]['_args'], opts?: Opts) => Promise<CallerReturn<FunctionReturnType<TApi[K]>, Opts>> : never : ServerCaller<TApi[K]>;
40
- type ServerCaller<TApi> = { [K in keyof TApi as K extends string ? K extends `_${string}` ? never : K extends 'http' ? never : K : K]: ServerCallerFn<TApi, K> };
41
- /**
42
- * Create a server caller for direct data fetching without React Query.
43
- *
44
- * This is detached from React Query cache - data is NOT available in client components.
45
- * Use for server-only data that doesn't need to be shared with the client.
46
- *
47
- * @example
48
- * ```tsx
49
- * // src/lib/convex/rsc.tsx
50
- * export const caller = createServerCaller(api, {
51
- * fetchQuery: fetchAuthQuery,
52
- * fetchMutation: fetchAuthMutation,
53
- * });
54
- *
55
- * // app/page.tsx (RSC)
56
- * const posts = await caller.posts.list();
57
- * return <div>{posts?.length} posts</div>;
58
- * ```
59
- */
60
- declare function createServerCaller<TApi extends Record<string, unknown>>(api: TApi, opts: CreateCallerOptions): ServerCaller<TApi>;
61
- //#endregion
62
- //#region src/server/lazy-caller.d.ts
63
- type CallerContext<TApi> = {
64
- caller: ServerCaller<TApi>;
65
- token: string | undefined;
66
- isAuthenticated: boolean;
67
- };
68
- /**
69
- * Lazy caller with auth helper methods.
70
- * Context is created on first procedure invocation, not at definition time.
71
- */
72
- type LazyCaller<TApi> = ServerCaller<TApi> & {
73
- /** Check if user is authenticated */isAuth: () => Promise<boolean>; /** Check if user is unauthenticated */
74
- isUnauth: () => Promise<boolean>; /** Get the auth token (for RSC prefetching) */
75
- getToken: () => Promise<string | undefined>;
76
- };
77
- /**
78
- * Create a lazy caller that creates context on each procedure invocation.
79
- * Matches tRPC's `appRouter.createCaller(createTRPCContext)` pattern.
80
- *
81
- * @example
82
- * ```ts
83
- * // server.ts
84
- * const { createContext, createCaller } = createCallerFactory({...});
85
- *
86
- * // rsc.tsx
87
- * const createRSCContext = cache(async () => {
88
- * const heads = await headers();
89
- * return createContext({ headers: heads });
90
- * });
91
- * export const caller = createCaller(createRSCContext);
92
- *
93
- * // app/page.tsx - single call! Context created lazily
94
- * const posts = await caller.posts.list();
95
- * ```
96
- */
97
- declare function createLazyCaller<TApi extends Record<string, unknown>>(api: TApi, createContext: () => Promise<CallerContext<TApi>>): LazyCaller<TApi>;
98
- //#endregion
99
- //#region src/server/caller-factory.d.ts
100
- type TokenResult = {
101
- token?: string;
102
- isFresh?: boolean;
103
- };
104
- type GetTokenFn = (siteUrl: string, headers: Headers, opts?: unknown) => Promise<TokenResult>;
105
- /** Auth options for server-side calls. */
106
- type AuthOptions = {
107
- /** Function to extract auth token from request headers. */getToken: GetTokenFn;
108
- /**
109
- * Custom function to detect UNAUTHORIZED errors.
110
- * Set this to resolve those errors to `null` instead of throwing.
111
- *
112
- * Refreshing an expired cached token and retrying does not require this:
113
- * that always falls back to `defaultIsUnauthorized`.
114
- */
115
- isUnauthorized?: (error: unknown) => boolean;
116
- };
117
- type CreateCallerFactoryOptions<TApi> = {
118
- /** Your Convex API object. */api: TApi; /** Convex site URL (must end in `.convex.site`). */
119
- convexSiteUrl: string;
120
- /**
121
- * Convex deployment URL (must end in `.convex.cloud`).
122
- * Defaults to `convexSiteUrl` with the domain swapped.
123
- */
124
- convexUrl?: string; /** Auth options. Pass to enable authenticated calls with JWT caching. */
125
- auth?: AuthOptions; /** Optional wire transformer for request/response payloads (always composed with Date). */
126
- transformer?: DataTransformerOptions;
127
- };
128
- type ConvexContext<TApi> = {
129
- token: string | undefined;
130
- isAuthenticated: boolean;
131
- caller: ServerCaller<TApi>;
132
- };
133
- declare function createCallerFactory<TApi extends Record<string, unknown>>(opts: CreateCallerFactoryOptions<TApi>): {
134
- createCaller: (ctxFn: () => Promise<ConvexContext<TApi>>) => LazyCaller<TApi>;
135
- createContext: (reqOpts: {
136
- headers: Headers;
137
- }) => Promise<ConvexContext<TApi>>;
138
- };
139
- //#endregion
140
- export { CallerMeta as a, createServerCaller as c, createLazyCaller as i, EmptyObject as l, createCallerFactory as n, CallerOpts as o, LazyCaller as r, ServerCaller as s, ConvexContext as t, Expand as u };
@@ -1,78 +0,0 @@
1
- //#region src/crpc/transformer.d.ts
2
- /**
3
- * Generic transformer contract (mirrors tRPC shape).
4
- */
5
- interface DataTransformer {
6
- deserialize(object: any): any;
7
- serialize(object: any): any;
8
- }
9
- /**
10
- * Separate input/output transformers.
11
- */
12
- interface CombinedDataTransformer {
13
- input: DataTransformer;
14
- output: DataTransformer;
15
- }
16
- /**
17
- * Transformer config accepted by cRPC.
18
- */
19
- type DataTransformerOptions = CombinedDataTransformer | DataTransformer;
20
- /**
21
- * Extensible tagged wire codec.
22
- */
23
- interface WireCodec {
24
- decode(value: unknown): unknown;
25
- encode(value: unknown): unknown;
26
- isType(value: unknown): boolean;
27
- /**
28
- * Declares that `isType` only ever claims a value where
29
- * `typeof value === 'object' && value !== null` - never a primitive, a
30
- * function, `null` or `undefined`.
31
- *
32
- * Lets `serialize` skip codec dispatch on primitives, which are the majority
33
- * of visited nodes. It is opt-in because an arbitrary predicate cannot be
34
- * classified by sampling values: a codec that claims, say, one specific
35
- * number would be misread as object-only and silently lose its encoding.
36
- * Codecs that leave it unset keep full dispatch.
37
- */
38
- readonly objectsOnly?: boolean;
39
- readonly tag: `$${string}`;
40
- }
41
- /**
42
- * Date wire tag (Convex-style reserved key).
43
- */
44
- declare const DATE_CODEC_TAG = "$date";
45
- /**
46
- * Built-in Date codec.
47
- */
48
- declare const dateWireCodec: WireCodec;
49
- /**
50
- * Build a recursive tagged transformer from codecs.
51
- */
52
- declare const createTaggedTransformer: (codecs: readonly WireCodec[]) => DataTransformer;
53
- /**
54
- * Default cRPC transformer (Date-enabled).
55
- */
56
- declare const defaultCRPCTransformer: DataTransformer;
57
- /**
58
- * Normalize transformer config to split input/output shape.
59
- * User transformers are additive and always composed with default Date handling.
60
- *
61
- * Idempotent: passing a transformer this function already resolved returns it
62
- * unchanged.
63
- */
64
- declare const getTransformer: (transformer?: DataTransformerOptions) => CombinedDataTransformer;
65
- /**
66
- * Encode request payloads (input direction).
67
- */
68
- declare const encodeWire: (value: unknown, transformer?: DataTransformerOptions) => unknown;
69
- /**
70
- * Decode response payloads (output direction).
71
- */
72
- declare const decodeWire: (value: unknown, transformer?: DataTransformerOptions) => unknown;
73
- /**
74
- * Exposed identity transformer for advanced composition.
75
- */
76
- declare const identityTransformer: CombinedDataTransformer;
77
- //#endregion
78
- export { WireCodec as a, decodeWire as c, getTransformer as d, identityTransformer as f, DataTransformerOptions as i, defaultCRPCTransformer as l, DATE_CODEC_TAG as n, createTaggedTransformer as o, DataTransformer as r, dateWireCodec as s, CombinedDataTransformer as t, encodeWire as u };