import type { EdenClient, EdenCreateClient, EdenRequestOptions, ExtractEdenTreatyRouteParams, ExtractEdenTreatyRouteParamsInput, HttpBatchLinkOptions, HTTPLinkOptions, HttpMutationMethod, HttpQueryMethod, HttpSubscriptionMethod, InferRouteOptions, TypeError } from '@aydee-app/eden'; import type { StoreOrVal } from '@tanstack/svelte-query'; import type { AnyElysia, RouteSchema } from 'elysia'; import type { Prettify } from 'elysia/types'; import type { EdenQueryConfig } from '../../config'; import type { EdenContextProps, EdenContextState } from '../../context'; import type { EdenCreateInfiniteQuery } from '../../integration/hooks/create-infinite-query'; import type { EdenCreateMutation } from '../../integration/hooks/create-mutation'; import type { EdenCreateQuery } from '../../integration/hooks/create-query'; import type { InfiniteCursorKey } from '../../integration/internal/infinite-query'; import type { EdenMutationKey, EdenQueryKey, EdenQueryKeyOptions, EdenQueryType } from '../../integration/internal/query-key'; import type { EdenTreatySvelteQueryCreateQueries } from './create-queries'; import type { EdenTreatySvelteQueryUtils } from './query-utils'; import { type EdenTreatyQueryRootHooks } from './root-hooks'; /** * The treaty-query API provides utility methods that are available at the root, as well as * a strongly-typed proxy representing the {@link AnyElysia} API. */ export type EdenTreatySvelteQuery = EdenTreatySvelteQueryBase & EdenTreatySvelteQueryHooks; /** * Utilities available at the eden-treaty + svelte-query root. */ export interface EdenTreatySvelteQueryBase { /** * Get utilities provided via the context API. * * @see https://trpc.io/docs/v11/client/react/useUtils */ getUtils(): EdenTreatySvelteQueryUtils; /** * Get utilities provided via the context API. * * @deprecated renamed to {@link getUtils} and will be removed in a future tRPC version * * @see https://trpc.io/docs/v11/client/react/useUtils */ getContext(): EdenTreatySvelteQueryUtils; /** * Returns everything that will be provided from context. * * e.g. the root utility functions, and root configuration settings. */ createContext(props: EdenContextProps, config?: EdenQueryConfig): EdenContextState; /** * Creates a proxy that can invoke tanstack-query helper functions. */ createUtils(props: EdenContextProps, config?: EdenQueryConfig): EdenTreatySvelteQueryUtils; /** * Create utilities and provide them via context. */ setContext(props: EdenContextProps, config?: EdenQueryConfig): EdenContextState; /** * Wraps the `create-queries` svelte-query hook in a type-safe proxy. */ createQueries: EdenTreatySvelteQueryCreateQueries; /** * Create a raw, untyped-client. */ createClient: EdenCreateClient; /** * Convenience method for creating and configuring a client with a single HTTPLink. */ createHttpClient: (options?: HTTPLinkOptions) => EdenClient; /** * Convenience method for creating and configuring a client with a single HttpBatchLink. */ createHttpBatchClient: (options?: HttpBatchLinkOptions) => EdenClient; } /** * RPC proxy derived from {@link AnyElysia._routes} that connects svelte-query with an Elysia.js API. */ export type EdenTreatySvelteQueryHooks = T extends { _routes: infer TSchema extends Record; } ? EdenTreatySvelteQueryHooksProxy : 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 EdenTreatySvelteQueryHooksProxy, TPath extends any[] = [], TRouteParams = ExtractEdenTreatyRouteParams> = EdenTreatySvelteQueryPathHooks & EdenTreatySvelteQueryHooksPathParameterHook; /** * 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 svelte-query hooks. * * @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 EdenTreatySvelteQueryPathHooks, TPath extends any[] = [], TRouteParams = ExtractEdenTreatyRouteParams> = { [K in Exclude]: TSchema[K] extends RouteSchema ? EdenTreatySvelteQueryRouteLeaf : EdenTreatySvelteQueryHooksProxy; }; /** * This intersects the object created by {@link EdenTreatyPathHooks} * (for regular path parameters) to handle 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. */ export type EdenTreatySvelteQueryHooksPathParameterHook, TPath extends any[] = [], TRouteParams = {}> = {} extends TRouteParams ? {} : (params: StoreOrVal>) => EdenTreatySvelteQueryHooksProxy], TPath>; /** * When a {@link RouteSchema} is found, map it to leaves and stop recursive processing. * Leaves are objects with svelte-query hooks related to the HTTP method. * * For example, the object would contain hooks for queries if {@link TMethod} was "get". * * @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. * @template TPath The current path segments up to this point (excluding dynamic path parameters). */ export type EdenTreatySvelteQueryRouteLeaf = TMethod extends HttpQueryMethod ? EdenTreatySvelteQueryLeaf : TMethod extends HttpMutationMethod ? EdenTreatySvelteQueryMutationLeaf : TMethod extends HttpSubscriptionMethod ? EdenTreatySvelteQuerySubscriptionLeaf : EdenTreatySvelteQueryUnknownLeaf; /** * svelte-query hooks for "queries". e.g. routes with a "GET" endpoint. */ export type EdenTreatySvelteQueryLeaf = InferRouteOptions> = { createQuery: EdenCreateQuery; } & (InfiniteCursorKey extends keyof (TInput['params'] & TInput['query']) ? EdenTreatySvelteQueryInfiniteQueryLeaf : {}); /** * svelte-query hooks for "infinite-queries". * e.g. routes with a "GET" endpoint that also expects "cursor" as a query parameter. */ export type EdenTreatySvelteQueryInfiniteQueryLeaf = { createInfiniteQuery: EdenCreateInfiniteQuery; }; /** * svelte-query hooks for "mutations". e.g. Basically routes with any HTTP methods other than "GET." */ export type EdenTreatySvelteQueryMutationLeaf = { createMutation: EdenCreateMutation; }; /** * @todo: svelte-query hooks for "subscriptions". e.g. Basically routes that support "CONNECT" or "SUBSCRIBE" requests. * * @see https://github.com/trpc/trpc/blob/52a57eaa9c12394778abf5f0e6b52ec6f46288ed/packages/react-query/src/shared/hooks/createHooksInternal.tsx#L347 * @see https://tkdodo.eu/blog/using-web-sockets-with-react-query */ export type EdenTreatySvelteQuerySubscriptionLeaf> = { options: Prettify; queryKey: EdenQueryKey; }; /** * svelte-query hooks for any unknown HTTP methods will just expose all known hooks for now. * * @todo Decide what hooks to expose... */ export type EdenTreatySvelteQueryUnknownLeaf = EdenTreatySvelteQueryLeaf & EdenTreatySvelteQueryInfiniteQueryLeaf & EdenTreatySvelteQueryMutationLeaf & EdenTreatySvelteQuerySubscriptionLeaf; /** * Main entrypoint for this library. * * @param config Default configuration for the root hooks. */ export declare function createEdenTreatySvelteQuery(config?: EdenQueryConfig): EdenTreatySvelteQuery; /** * Creates the recursive proxy. * * @param config Root hooks that were created. * * @param rootHooks The original configuration for eden-treaty. * * @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 }, writable({ cursor: '456' }) ] */ export declare function createEdenTreatySvelteQueryProxy(rootHooks: EdenTreatyQueryRootHooks, config?: EdenQueryConfig, paths?: (string | symbol)[], pathParams?: StoreOrVal>[]): () => void; export declare const routeDefinitionSymbol: unique symbol; /** * Get a query key by providing the proxy at any level. */ export declare function getQueryKey>(route: EdenTreatySvelteQueryHooksProxy, input?: TSchema extends RouteSchema ? InferRouteOptions : any, type?: EdenQueryType): EdenQueryKey; /** * Get a mutation key by providing the proxy at any level. */ export declare function getMutationKey(route: EdenTreatySvelteQueryHooksProxy, options?: EdenQueryKeyOptions): EdenMutationKey; export * from './create-queries'; export * from './infer'; export * from './query-utils'; export * from './root-hooks'; //# sourceMappingURL=index.d.ts.map