import { AnyElysia, RouteSchema } from 'elysia'; import { EdenClient } from './client.cjs'; import { N as NonEmptyArray, T as TypeError } from './errors-DQ0_HKez.cjs'; import { c as HTTPLinkBaseOptions, H as HTTPHeaders, i as HttpQueryMethod, j as HttpMutationMethod, k as HttpSubscriptionMethod } from './http-BobyyETH.cjs'; import { InferRouteOptions, InferRouteResponse, InferRouteBody } from './infer.cjs'; import { O as Operation, N as Noop, z as EdenResponse, E as EdenRequestOptions, a as EdenLink } from './operation-JC_TyDnC.cjs'; import { EdenWS } from './ws.cjs'; import { E as EdenQueryStoreKey } from './constraints-iwkJs7sG.cjs'; import { D as DataTransformerOptions } from './transformer-BrEsAU6i.cjs'; import { EdenConfig } from './config.cjs'; type Requester = (options: RequesterOptions) => PromiseAndCancel; type RequesterOptions = Operation & HTTPLinkBaseOptions & EdenConfig; type PromiseAndCancel = { promise: Promise; cancel: Noop; }; type HTTPLinkFactoryOptions = { requester: Requester; }; type HTTPLinkOptions = HTTPLinkBaseOptions & Omit, 'headers' | 'transformer'> & { /** * @todo: Merge this headers type into {@link EdenRequestOptions} */ headers?: HTTPHeaders | ((operations: NonEmptyArray) => HTTPHeaders | Promise); } & (TTransformer extends DataTransformerOptions ? { transformer: TTransformer; } : { transformer?: DataTransformerOptions; }); type HTTPLinkFactory = (options?: HTTPLinkOptions) => EdenLink; declare function httpLinkFactory(factoryOptions: HTTPLinkFactoryOptions): HTTPLinkFactory; /** * @see https://trpc.io/docs/v11/client/links/httpLink */ declare const safeHttpLink: HTTPLinkFactory; /** * @see https://trpc.io/docs/v11/client/links/httpLink */ declare function httpLink(options?: HTTPLinkOptions): EdenLink; /** * * An eden-treaty proxy may look like these examples: * * eden.api.products.get({ limit: 5 }) * eden.api.product({ id: 'product-id' }).details.get({ limit: 5 }) * * In the first example, the proxy is called like a function at the very end, so it is trivial * to infer that the arguments are the query parameters for fetch request. * * In the second example, there are two function calls, and we need to heuristically determine whether * it is a function call to insert a path parameter, or the actual end. * * Heuristic: A path parameter function call needs exactly one object with exactly one key passed as an argument. */ declare function getPathParam(args: unknown[]): { param: any; key: string | undefined; } | undefined; /** * Only maps over keys that represents valid route params. i.e. path segments that begin with colon. */ type ExtractEdenTreatyRouteParams = { [K in keyof T as K extends `:${string}` ? K : never]: T[K]; }; /** * Create an object that maps the name of the route param to possible values (string or number). * * @example * * '/products/:id' * * :id is a path parameter, and this would return { id: string | number } * * Eden will recognize this object as a path parameter. * * @see https://elysiajs.com/eden/treaty/overview.html#dynamic-path */ type ExtractEdenTreatyRouteParamsInput = { [K in keyof T as K extends `:${infer TParam}` ? TParam : never]: string | number; }; /** * Converts an empty object to void. * * Useful for marking arguments to functions as optional. * * @see [Playground Link](https://www.typescriptlang.org/play/?ssl=5&ssc=14&pln=1&pc=1#code/GYVwdgxgLglg9mABAWwJ4DFzXmAFANwEMAbEAUwC5F84YATRAH0TBGQCMyAnASkQG8AUIkRcyUEFyRFSZQQF9BaTJFgJcPJRixq8ARh5A) * * @example * ```ts * // value is marked as required, but "void" makes it optional. * function myFunction(value: void | number) { * return value * } * * // Both are valid calls. * * myFunction() * myFunction(1) * ``` * */ type EmptyToVoid = {} extends T ? void | T : T; /** * Convert some properties from a target object to optional. */ type Optional = Omit & Partial>; /** * RPC proxy derived from {@link AnyElysia._routes} for accessing an Elysia.js API. */ type EdenTreatyClient = T extends { _routes: infer TSchema extends Record; } ? EdenTreatyHooksProxy : TypeError<'Please install Elysia before using Eden'>; /** * Recursively iterate over all keys in {@link AnyElyisa._routes}, processing path parameters * and regular path segments separately. * * Regular path parameters will be mapped to a nested object, and then intersected * with anything generated by dynamic path parameters. * * @template TSchema The current level of {@link AnyElysia._routes} being processed. * @template TPath The current path segments up to this point (excluding dynamic path parameters). * @template TRouteParams Keys that are considered path parameters instead of regular path segments. */ type EdenTreatyHooksProxy, TPath extends any[] = [], TRouteParams = ExtractEdenTreatyRouteParams> = EdenTreatyPathHooks & EdenTreatyHooksPathParameterHook; /** * Recursively handle regular path segments (i.e. NOT path parameters). * * If the value is a {@link RouteSchema}, then it's a "leaf" that does not need to be * recursively processed. The result should be the key, an HTTP method, mapped to a * strongly-typed function. * * @template TSchema The current level of {@link AnyElysia._routes} being processed. * @template TPath The current path segments up to this point (excluding dynamic path parameters). * @template TRouteParams Keys that are considered path parameters instead of regular path segments. */ type EdenTreatyPathHooks, TPath extends any[] = [], TRouteParams = ExtractEdenTreatyRouteParams> = { [K in Exclude]: TSchema[K] extends RouteSchema ? EdenTreatyQueryRouteLeaf : EdenTreatyHooksProxy; }; /** * {@link EdenTreatyHooksProxy} intersects the object created by {@link EdenTreatyPathHooks} * for regular path parameters with anything created by this type for dynamic path parameters. * * If there are no dynamic path parameters, then return an empty object. * Intersecting with empty object does nothing. * * Otherwise, return a function that returns the next level of the proxy, omitting * the current dynamic path parameter. * * @template TSchema The current level of {@link AnyElysia._routes} being processed. * @template TPath The current path segments up to this point (excluding dynamic path parameters). * @template TRouteParams Keys that are considered path parameters instead of regular path segments. */ type EdenTreatyHooksPathParameterHook, TPath extends any[] = [], TRouteParams = {}> = {} extends TRouteParams ? {} : (params: ExtractEdenTreatyRouteParamsInput) => EdenTreatyHooksProxy], TPath>; /** * When a {@link RouteSchema} is found, map it to leaves and stop recursive processing. * Leaves are function calls that abstract the native {@link fetch} API. * * Based on the HTTP request "category", e.g. "query", "mutation", "subscription", or "unknown", * return the corresponding leaf. * * @template TRoute The {@link RouteSchema} that was found. * @template TMethod The most recent key that was mapped to the {@link TRoute}. e.g. "get", "post", etc. */ type EdenTreatyQueryRouteLeaf = TMethod extends HttpQueryMethod ? EdenTreatyQueryLeaf : TMethod extends HttpMutationMethod ? EdenTreatyMutationLeaf : TMethod extends HttpSubscriptionMethod ? EdenTreatySubscriptionLeaf : EdenTreatyUnknownLeaf; /** * Strongly-typed function for queries (i.e. "GET" requests). */ type EdenTreatyQueryLeaf = (options: EmptyToVoid, 'params'>>) => Promise>; /** * Strongly-typed function for mutations (i.e. "POST", "PATCH", etc. requests). */ type EdenTreatyMutationLeaf = (body: EmptyToVoid>, options: EmptyToVoid>) => Promise>; /** * Strongly-typed function for subscriptions (i.e. "CONNECT", "SUBSCRIBE", etc. requests). * * @TODO: Available hooks assuming that the route supports `createSubscription`. */ type EdenTreatySubscriptionLeaf = (options: EmptyToVoid, 'params'>>) => EdenWS; /** * Strongly-typed function for unknown request. * * @todo What should it actually be... */ type EdenTreatyUnknownLeaf = EdenTreatyQueryLeaf & EdenTreatyQueryLeaf & EdenTreatyMutationLeaf & EdenTreatySubscriptionLeaf; /** * @param client * * @param config * * @param [paths=[]] Path parameter strings including the current path parameter as a placeholder. * @example [ 'products', ':id', ':cursor' ] * * @param [pathParams=[]] An array of objects representing path parameter replacements. * @example [ { id: 123 }, { cursor: '456' } ] */ declare function createEdenTreatyProxy(client: EdenClient, config?: EdenRequestOptions, paths?: string[], pathParams?: Record[]): () => void; /** * @param clientOrHttpLinkOptions Either an untyped {@link EdenClient} or options for an httpLink to initialize a default client. * @param options Request options. */ declare function createEdenTreaty(clientOrHttpLinkOptions?: EdenClient | HTTPLinkOptions, options?: EdenRequestOptions): EdenTreatyClient; export { type ExtractEdenTreatyRouteParams as E, type HTTPLinkFactoryOptions as H, type HTTPLinkOptions as a, type HTTPLinkFactory as b, httpLink as c, type ExtractEdenTreatyRouteParamsInput as d, type EdenTreatyClient as e, type EdenTreatyHooksProxy as f, getPathParam as g, httpLinkFactory as h, type EdenTreatyQueryRouteLeaf as i, type EdenTreatyQueryLeaf as j, type EdenTreatyMutationLeaf as k, type EdenTreatySubscriptionLeaf as l, type EdenTreatyUnknownLeaf as m, createEdenTreatyProxy as n, createEdenTreaty as o, type EmptyToVoid as p, safeHttpLink as s };