import type { AnyElysia, RouteSchema } from 'elysia'; import { EdenClient } from './client'; import type { TypeError } from './errors'; import { type HttpMutationMethod, type HttpQueryMethod, type HttpSubscriptionMethod } from './http'; import type { InferRouteBody, InferRouteOptions, InferRouteResponse } from './infer'; import { type HTTPLinkOptions } from './links'; import { type ExtractEdenTreatyRouteParams, type ExtractEdenTreatyRouteParamsInput } from './path-params'; import type { EdenRequestOptions } from './request'; import type { EmptyToVoid } from './utils/empty-to-void'; import type { Optional } from './utils/optional'; import type { EdenWS } from './ws'; /** * RPC proxy derived from {@link AnyElysia._routes} for accessing an Elysia.js API. */ export 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. */ export 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. */ export type EdenTreatyQueryRouteLeaf = TMethod extends HttpQueryMethod ? EdenTreatyQueryLeaf : TMethod extends HttpMutationMethod ? EdenTreatyMutationLeaf : TMethod extends HttpSubscriptionMethod ? EdenTreatySubscriptionLeaf : EdenTreatyUnknownLeaf; /** * Strongly-typed function for queries (i.e. "GET" requests). */ export type EdenTreatyQueryLeaf = (options: EmptyToVoid, 'params'>>) => Promise>; /** * Strongly-typed function for mutations (i.e. "POST", "PATCH", etc. requests). */ export 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`. */ export type EdenTreatySubscriptionLeaf = (options: EmptyToVoid, 'params'>>) => EdenWS; /** * Strongly-typed function for unknown request. * * @todo What should it actually be... */ export 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' } ] */ export 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. */ export declare function createEdenTreaty(clientOrHttpLinkOptions?: EdenClient | HTTPLinkOptions, options?: EdenRequestOptions): EdenTreatyClient; export {}; //# sourceMappingURL=treaty.d.ts.map