import * as _aydee_app_eden from '@aydee-app/eden'; import { EdenRequestOptions, InferRouteOptions, EdenClient, EdenClientError, InferRouteOutput, InferRouteError, EmptyToVoid, InferRouteBody, ExtractEdenTreatyRouteParams, HttpQueryMethod, HttpMutationMethod, HttpSubscriptionMethod, ExtractEdenTreatyRouteParamsInput, TypeError, EdenTreatyClient, EdenCreateClient, HTTPLinkOptions, HttpBatchLinkOptions } from '@aydee-app/eden'; export * from '@aydee-app/eden'; import { StoreOrVal, QueryClient, DehydratedState, FetchInfiniteQueryOptions, FetchQueryOptions, InfiniteData, InvalidateQueryFilters, InvalidateOptions, QueryFilters, ResetOptions, RefetchQueryFilters, RefetchOptions, CancelOptions, Updater, SetDataOptions, QueryKey, MutationOptions, CreateInfiniteQueryOptions, CreateInfiniteQueryResult, SkipToken, CreateMutationOptions, CreateBaseMutationResult, MutateOptions, CreateBaseQueryOptions, CreateQueryResult, InitialDataFunction, DefinedCreateQueryResult, CreateQueryOptions, QueriesResults, QueriesOptions, Query } from '@tanstack/svelte-query'; import { AnyElysia, MaybePromise, RouteSchema } from 'elysia'; import { Prettify } from 'elysia/types'; import { Readable } from 'svelte/store'; /** * Options to customize the behavior of the query or fetch. */ type EdenQueryRequestOptions = /** * Use svelte-query's internal AbortSignals instead of allowing user provided signals. */ Omit, 'signal'> & { /** * Opt out or into aborting request on unmount */ abortOnUnmount?: boolean; /** * Overrides for svelte-query hooks. */ overrides?: EdenQueryOverrides; /** * SSR option... */ dehydrated?: boolean | DehydratedState; }; type EdenQueryOverrides = { createMutation?: Partial; }; type CreateMutationOverride = { onSuccess: (options: CreateMutationOverrideOnSuccessOptions) => MaybePromise; }; type CreateMutationOverrideOnSuccessOptions = { originalFn: () => StoreOrVal; queryClient: QueryClient; meta: Record; }; type EdenQueryConfig = EdenQueryRequestOptions & { /** * Override the default context provider * @default undefined */ context?: any; }; /** * Makes the object recursively optional * @internal */ type DeepPartial = TObject extends object ? { [P in keyof TObject]?: DeepPartial; } : TObject; /** * Omits the key without removing a potential union * @internal */ type DistributiveOmit = TObj extends any ? Omit : never; /** * @internal */ type IntersectionError = `The property '${TKey}' in your router collides with a built-in method, rename this router or procedure on your backend.`; /** * @internal */ type ProtectedIntersection = keyof TType & keyof TWith extends never ? TType & TWith : IntersectionError; /** * Simple utility that overrides top level properties from `T` with the matching properties from `U`. */ type Override = Omit & U; /** * Key in params or query that indicates GET routes that are eligible for infinite queries. */ type InfiniteCursorKey = 'cursor'; /** * When providing request input to infinite queries, omit the "cursor" and "direction" properties * since these will be set by the integration. */ type ReservedInfiniteQueryKeys = InfiniteCursorKey | 'direction'; /** * Given T, which is presumably a {@link RouteSchema}, merge the "params" and "query" types, * then extract the "cursor". */ type ExtractCursorType = T extends Record ? (T['params'] & T['query'])['cursor'] : unknown; type ExtractQueryCursor = T extends Record ? T['cursor'] : unknown; /** * Additional options for queries. */ type EdenQueryBaseOptions = { /** * eden-related options */ eden?: EdenQueryRequestOptions; }; /** * A well-defined query type used when creating query keys for a specific type of operation. */ type EdenKnownQueryType = 'query' | 'infinite'; /** * Valid query types for creating query keys. */ type EdenQueryType = EdenKnownQueryType | 'any'; /** * QueryKey used internally. Consists of a tuple with an array key and metadata. */ type EdenQueryKey = [key: TKey, metadata?: { input?: TInput; type?: TType; }]; type EdenQueryKeyOptions = InferRouteOptions & { body?: any; }; type EdenMutationKey = [readonly string[]]; type EdenFetchInfiniteQueryOptions = DistributiveOmit>, 'queryKey' | 'initialPageParam'> & EdenQueryBaseOptions & { initialCursor?: ExtractCursorType; }; type EdenFetchQueryOptions = DistributiveOmit, 'queryKey'> & EdenQueryBaseOptions; type EdenContextPropsBase = { /** * Untyped client for making requests. */ client: EdenClient; /** * Whether to forward the `signal` from svelte-query to fetch call. * * @default false * * @deprecated pass abortOnUnmount to `createTRPCReact` instead */ abortOnUnmount?: boolean; }; type EdenContextProps = EdenContextPropsBase & { /** * The svelte-query `QueryClient` */ queryClient: QueryClient; }; type EdenContextState = Required> & EdenQueryUtils; type EdenQueryUtils = { /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery */ fetchQuery: (queryKey: EdenQueryKey, opts?: EdenFetchQueryOptions>) => Promise; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery */ fetchInfiniteQuery: (queryKey: EdenQueryKey, opts?: EdenFetchInfiniteQueryOptions>) => Promise>; /** * @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching */ prefetchQuery: (queryKey: EdenQueryKey, opts?: EdenFetchQueryOptions>) => Promise; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery */ prefetchInfiniteQuery: (queryKey: EdenQueryKey, opts?: EdenFetchInfiniteQueryOptions>) => Promise; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata */ ensureQueryData: (queryKey: EdenQueryKey, opts?: EdenFetchQueryOptions>) => Promise; /** * @link https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation */ invalidateQueries: (queryKey: EdenQueryKey, filters?: InvalidateQueryFilters, options?: InvalidateOptions) => Promise; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries */ resetQueries: (queryKey: EdenQueryKey, filters?: QueryFilters, options?: ResetOptions) => Promise; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries */ refetchQueries: (queryKey: EdenQueryKey, filters?: RefetchQueryFilters, options?: RefetchOptions) => Promise; /** * @link https://tanstack.com/query/v5/docs/framework/react/guides/query-cancellation */ cancelQuery: (queryKey: EdenQueryKey, options?: CancelOptions) => Promise; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata */ setQueryData: (queryKey: EdenQueryKey, updater: Updater, options?: SetDataOptions) => void; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetqueriesdata */ setQueriesData: (queryKey: EdenQueryKey, filters: QueryFilters, updater: Updater, options?: SetDataOptions) => [QueryKey, unknown][]; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata */ getQueryData: (queryKey: EdenQueryKey) => unknown; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata */ setInfiniteQueryData: (queryKey: EdenQueryKey, updater: Updater | undefined, InfiniteData | undefined>, options?: SetDataOptions) => void; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata */ getInfiniteQueryData: (queryKey: EdenQueryKey) => InfiniteData | undefined; /** * @link https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientsetmutationdefaults */ setMutationDefaults: (mutationKey: EdenMutationKey, options: MutationOptions | ((args: { canonicalMutationFn: (input: unknown) => Promise; }) => MutationOptions)) => void; /** * @link https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientgetmutationdefaults */ getMutationDefaults: (mutationKey: EdenMutationKey) => MutationOptions | undefined; /** * @link https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientismutating */ isMutating: (filters: { mutationKey: EdenMutationKey; }) => number; }; /** * Additional properties appended to react-query hooks by the library. * * The hooks are scoped to an `eden` property on the hook. * * @example * * const hello = eden.hello.useQuery() * * const edenPath = hello.eden.path */ type WithEdenQueryExtension = T & { /** * Additional object appended by eden-query. */ eden: EdenExtendedQueryHooks; }; /** * Additional hooks added to the original react-query hook result. */ type EdenExtendedQueryHooks = { /** * The path used to make the request. * * @example * * '/api/a/index' */ path: string; }; interface EdenCreateInfiniteQueryOptions extends DistributiveOmit>, 'queryKey' | 'initialPageParam'>, EdenQueryBaseOptions { initialCursor?: ExtractQueryCursor; } type EdenCreateInfiniteQueryResult = WithEdenQueryExtension> | null>, TError>>; type EdenCreateInfiniteQuery['query'], TOutput = InferRouteOutput, TError = InferRouteError, TInfiniteInput = InferRouteOptions['query']> = (input: StoreOrVal | SkipToken>, options: EdenCreateInfiniteQueryOptions) => EdenCreateInfiniteQueryResult; type EdenCreateMutationOptions = CreateMutationOptions & EdenQueryBaseOptions; type EdenCreateMutationResult = WithEdenQueryExtension, { mutateAsync: EdenAsyncMutationFunction; mutate: EdenMutationFunction; }>>>; type EdenCreateMutation, TInput = Partial, 'params'>> & Omit, 'params'>, TData = InferRouteOutput, TError = InferRouteError> = (options?: EdenCreateMutationOptions) => EdenCreateMutationResult; type EdenAsyncMutationFunction = (variables: TVariables, options: {} extends TInput ? void | (TData & MutateOptions, TContext>) : TData & MutateOptions, TContext>) => Promise; type EdenMutationFunction = (variables: TContext, options: {} extends TInput ? void | (TData & MutateOptions, TContext>) : TData & MutateOptions, TContext>) => void; /** * @internal * * Need to be able to provide multiple arguments to `useMutation`, since * Eden's mutations accept a body as the first argument, and additional options * as the second argument -- which are sometimes required. * * To accomplish this, eden-query intercepts the hook call to grab the args as a single object, * then destructures it in custom `mutate` and `asyncMutate` implementations. * * This "hack" is needed since the vanilla `useMutation` hook doesn't allow multiple args :( */ type EdenCreateMutationVariables = { /** * The first argument provided to the `useMutation` hook, i.e. the request body. */ body: TBody; } & ({} extends TOptions ? { /** * The second argument provided to the `useMutation` hook, i.e. request options. */ options?: TOptions; } : { /** * The second argument provided to the `useMutation` hook, i.e. request options. */ options: TOptions; }); type EdenCreateQueryOptions = DistributiveOmit, 'queryKey'> & EdenQueryBaseOptions; type EdenDefinedCreateQueryOptions = DistributiveOmit, 'queryKey'> & EdenQueryBaseOptions & { initialData: InitialDataFunction | TQueryOptsData; }; type EdenCreateQueryResult = WithEdenQueryExtension>; type EdenDefinedCreateQueryResult = WithEdenQueryExtension>; interface EdenCreateQuery['query'], TOutput = InferRouteOutput, TError = InferRouteError> { (input: StoreOrVal>, options: EdenDefinedCreateQueryOptions): EdenDefinedCreateQueryResult; (input: StoreOrVal | SkipToken>, options?: EdenCreateQueryOptions): EdenCreateQueryResult; } type CreateQueryOptionsForCreateQueries = DistributiveOmit, 'queryKey'>; /** * A function that accepts a callback that's called with a proxy object. * Invoking the proxy object returns strongly typed query options. */ type EdenTreatySvelteQueryCreateQueries = >(callback: (t: EdenTreatySvelteQueryCreateQueriesProxy) => readonly [...QueriesOptions]) => Readable; /** * RPC proxy derived from {@link AnyElysia._routes} that generates query options for `createQueries`. * This proxy is passed to the callback provided to the eden-treaty-svelte-query `createQueries` helper. */ type EdenTreatySvelteQueryCreateQueriesProxy = T extends { _routes: infer TSchema extends Record; } ? EdenTreatySvelteQueryCreateQueriesProxyMapping : 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). */ type EdenTreatySvelteQueryCreateQueriesProxyMapping, TPath extends any[] = [], TRouteParams = ExtractEdenTreatyRouteParams> = EdenTreatySvelteQueryCreateQueriesPathHooks & EdenTreatySvelteQueryCreateQueriesPathParameterHook; /** * This intersects the object created by {@link EdenTreatySvelteQueryCreateQueriesPathHooks} * (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. */ type EdenTreatySvelteQueryCreateQueriesPathParameterHook, TPath extends any[] = [], TRouteParams = {}> = {} extends TRouteParams ? {} : (params: ExtractEdenTreatyRouteParamsInput) => EdenTreatySvelteQueryCreateQueriesProxyMapping], TPath>; /** * 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. */ type EdenTreatySvelteQueryCreateQueriesPathHooks, TPath extends any[] = [], TRouteParams = ExtractEdenTreatyRouteParams> = { [K in Exclude]: TSchema[K] extends RouteSchema ? EdenTreatySvelteQueryCreateQueriesLeaf : EdenTreatySvelteQueryCreateQueriesProxyMapping; }; /** * When a {@link RouteSchema} is found, map it to leaves and stop recursive processing. * Based on the HTTP method, leaves may be functions that return {@link CreateQueryOptions}. * * @template TRoute The {@link RouteSchema} that was found. * @template TPath The current path segments up to this point (excluding dynamic path parameters). */ type EdenTreatySvelteQueryCreateQueriesLeaf = TMethod extends HttpQueryMethod ? EdenTreatySvelteQueryCreateQueriesQueryLeaf : TMethod extends HttpMutationMethod ? EdenTreatySvelteQueryCreateQueriesMutationLeaf : TMethod extends HttpSubscriptionMethod ? EdenTreatySvelteQueryCreateQueriesSubscriptionLeaf : EdenTreatySvelteQueryCreateQueriesUnknownLeaf; /** * Routes that support queries, e.g. "GET" requests, will be mapped to a function that returns {@link CreateQueryOptions}. */ type EdenTreatySvelteQueryCreateQueriesQueryLeaf['query'], TOutput = InferRouteOutput, TError = InferRouteError, TKey extends QueryKey = EdenQueryKey> = (input: EmptyToVoid, opts?: CreateQueryOptionsForCreateQueries) => CreateQueryOptions; /** * Routes that support mutations, e.g. anything besides "GET" requests, will be mapped to something unknown for now... * * @todo Decide what mutations should be mapped to... */ type EdenTreatySvelteQueryCreateQueriesMutationLeaf<_TRoute extends RouteSchema, _TPath extends any[] = []> = {}; /** * Routes that support queries, e.g. anything besides "GET" requests, will be mapped to something unknown for now... * * @todo Decide what subscriptions should be mapped to... */ type EdenTreatySvelteQueryCreateQueriesSubscriptionLeaf<_TRoute extends RouteSchema, _TPath extends any[] = []> = {}; /** * Routes that support unknown HTTP methods will be mapped to something unknown for now... * * @todo Decide what unknown methods should be mapped to... */ type EdenTreatySvelteQueryCreateQueriesUnknownLeaf<_TRoute extends RouteSchema, _TPath extends any[] = []> = {}; declare function createTreatySvelteQueryCreateQueriesProxy(client: EdenClient, paths?: string[], config?: EdenQueryConfig): EdenTreatySvelteQueryCreateQueriesProxy; type EdenTreatySvelteQueryUtils = ProtectedIntersection, EdenTreatySvelteQueryUtilsProxy>; type DecoratedEdenTreatySvelteQueryContextProps = Omit, 'client'> & { client: EdenTreatyClient; }; type EdenTreatySvelteQueryContextProps = EdenContextPropsBase & { client: EdenClient; }; type EdenTreatySvelteQueryUtilsProxy, TPath extends any[] = [], TRouteParams = ExtractEdenTreatyRouteParams> = EdenTreatyQueryUtilsUniversalUtils & { [K in keyof TSchema]: TSchema[K] extends RouteSchema ? EdenTreatyQueryUtilsMapping : EdenTreatySvelteQueryUtilsProxy; } & ({} extends TRouteParams ? {} : (params: ExtractEdenTreatyRouteParamsInput) => EdenTreatySvelteQueryUtilsProxy], TPath>); type EdenTreatyQueryUtilsMapping['query']> = TMethod extends HttpQueryMethod ? EdenTreatyQueryUtilsQueryUtils & (InfiniteCursorKey extends keyof TInput ? EdenTreatyQueryUtilsInfiniteUtils : {}) : TMethod extends HttpMutationMethod ? EdenQueryUtilsMutationUtils : never; type EdenTreatyQueryUtilsQueryUtils['query'], TOutput = InferRouteOutput, TError = InferRouteError, TKey extends QueryKey = EdenQueryKey> = { fetch: (input: EmptyToVoid, options?: EdenFetchQueryOptions) => Promise; prefetch: (input: EmptyToVoid, options?: EdenFetchQueryOptions) => Promise; ensureData: (input: EmptyToVoid, options?: EdenFetchQueryOptions) => Promise; invalidate: (input?: DeepPartial, filters?: Override) => boolean; }>, options?: InvalidateOptions) => Promise; refetch: (input?: TInput, filters?: RefetchQueryFilters, options?: RefetchOptions) => Promise; cancel: (input?: TInput, filters?: QueryFilters, options?: CancelOptions) => Promise; reset: (input?: TInput, options?: ResetOptions) => Promise; setData: (input: TInput, updater: Updater, options?: SetDataOptions) => void; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata */ setQueriesData(input: TInput, filters: QueryFilters, updater: Updater, options?: SetDataOptions): [QueryKey, TOutput]; getData: (input: EmptyToVoid) => TOutput | undefined; options: (input: EmptyToVoid, options?: CreateQueryOptions) => CreateQueryOptions; }; type EdenTreatyQueryUtilsInfiniteUtils['query'], TOutput = InferRouteOutput, TError = InferRouteError, TKey extends QueryKey = EdenQueryKey> = { fetchInfinite: (input: EmptyToVoid, options?: EdenFetchInfiniteQueryOptions) => Promise>>>; prefetchInfinite: (input: EmptyToVoid, options?: EdenFetchQueryOptions) => Promise; getInfiniteData: (input: EmptyToVoid) => InfiniteData>> | undefined; setInfiniteData: (input: TInput, updater: Updater>> | undefined, InfiniteData>> | undefined>, options?: SetDataOptions) => void; infiniteOptions: (input: EmptyToVoid, options?: EdenCreateInfiniteQueryOptions) => CreateInfiniteQueryOptions; }; type EdenQueryUtilsMutationUtils, TOutput = InferRouteOutput, TError = InferRouteError, _TKey extends QueryKey = EdenQueryKey> = { setMutationDefaults(options: EdenCreateMutationOptions | ((args: { canonicalMutationFn: NonNullable['mutationFn']>; }) => EdenCreateMutationOptions)): void; getMutationDefaults(): EdenCreateMutationOptions | undefined; isMutating(): number; }; /** * Utility hooks available at all levels of the utilities proxy. */ type EdenTreatyQueryUtilsUniversalUtils = { /** * Invalidate the full router * @link https://trpc.io/docs/v10/useContext#query-invalidation * @link https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation */ invalidate(input?: undefined, filters?: InvalidateQueryFilters, options?: InvalidateOptions): Promise; }; declare function createEdenTreatyQueryUtils(context: EdenContextState, config?: EdenQueryConfig): EdenTreatySvelteQueryUtils; declare function mergeDehydrated(source: DehydratedState | QueryClient, destination: DehydratedState): DehydratedState; declare function createEdenTreatyQueryUtilsProxy(context: EdenContextState, config?: EdenQueryConfig, originalPaths?: string[], pathParams?: Record[]): EdenTreatySvelteQueryUtils; declare function createEdenTreatyQueryRootHooks>(config?: EdenQueryConfig): { createClient: EdenCreateClient; createHttpClient: (options?: HTTPLinkOptions) => EdenClient; createHttpBatchClient: (options?: HttpBatchLinkOptions) => EdenClient; createContext: (props: EdenContextProps, configOverride?: EdenQueryConfig | undefined) => EdenContextState; createUtils: (props: EdenContextProps, configOverride?: EdenQueryConfig | undefined) => EdenTreatySvelteQueryUtils; setContext: (props: EdenContextProps, configOverride?: EdenQueryConfig | undefined) => EdenContextState; getContext: (context?: EdenContextState, configOverride?: EdenQueryConfig | undefined) => ProtectedIntersection, EdenTreatySvelteQueryUtilsProxy>>; getUtils: (context?: EdenContextState, configOverride?: EdenQueryConfig | undefined) => ProtectedIntersection, EdenTreatySvelteQueryUtilsProxy>>; createQuery: (originalPaths: readonly string[], input?: StoreOrVal, options?: StoreOrVal>) => EdenCreateQueryResult; createQueries: EdenTreatySvelteQueryCreateQueries; createMutation: (originalPaths: readonly string[], options?: StoreOrVal>) => EdenCreateMutationResult; createInfiniteQuery: (originalPaths: readonly string[], input?: StoreOrVal, options?: StoreOrVal>) => EdenCreateInfiniteQueryResult; }; type EdenTreatyQueryRootHooks = ReturnType>; type InferTreatyQueryIO = T extends { _routes: infer TSchema extends Record; } ? InferTreatyQueryIOMapping : 'Please install Elysia before using Eden'; type InferTreatyQueryIOMapping, TPath extends any[] = []> = { [K in keyof TSchema]: TSchema[K] extends RouteSchema ? { input: K extends HttpQueryMethod ? InferRouteOptions> : [ InferRouteBody>, InferRouteOptions> ]; output: InferRouteOutput; } : InferTreatyQueryIOMapping; }; type InferTreatyQueryInput = T extends { _routes: infer TSchema extends Record; } ? InferTreatyQueryInputMapping : 'Please install Elysia before using Eden'; type InferTreatyQueryInputMapping, TPath extends any[] = []> = { [K in keyof TSchema]: TSchema[K] extends RouteSchema ? K extends HttpQueryMethod ? InferRouteOptions> : [ InferRouteBody>, InferRouteOptions> ] : InferTreatyQueryInputMapping; }; type InferTreatyQueryOutput = T extends { _routes: infer TSchema extends Record; } ? InferTreatyQueryOutputMapping : 'Please install Elysia before using Eden'; type InferTreatyQueryOutputMapping, TPath extends any[] = []> = { [K in keyof TSchema]: TSchema[K] extends RouteSchema ? InferRouteOutput : InferTreatyQueryOutputMapping; }; /** * 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. */ type EdenTreatySvelteQuery = EdenTreatySvelteQueryBase & EdenTreatySvelteQueryHooks; /** * Utilities available at the eden-treaty + svelte-query root. */ 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. */ 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. */ 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. */ 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. */ 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). */ 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. */ 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. */ type EdenTreatySvelteQueryInfiniteQueryLeaf = { createInfiniteQuery: EdenCreateInfiniteQuery; }; /** * svelte-query hooks for "mutations". e.g. Basically routes with any HTTP methods other than "GET." */ 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 */ 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... */ type EdenTreatySvelteQueryUnknownLeaf = EdenTreatySvelteQueryLeaf & EdenTreatySvelteQueryInfiniteQueryLeaf & EdenTreatySvelteQueryMutationLeaf & EdenTreatySvelteQuerySubscriptionLeaf; /** * Main entrypoint for this library. * * @param config Default configuration for the root hooks. */ 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' }) ] */ declare function createEdenTreatySvelteQueryProxy(rootHooks: EdenTreatyQueryRootHooks, config?: EdenQueryConfig, paths?: (string | symbol)[], pathParams?: StoreOrVal>[]): () => void; declare const routeDefinitionSymbol: unique symbol; /** * Get a query key by providing the proxy at any level. */ 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. */ declare function getMutationKey(route: EdenTreatySvelteQueryHooksProxy, options?: EdenQueryKeyOptions): EdenMutationKey; export { type DecoratedEdenTreatySvelteQueryContextProps, type EdenQueryUtilsMutationUtils, type EdenTreatyQueryRootHooks, type EdenTreatyQueryUtilsInfiniteUtils, type EdenTreatyQueryUtilsQueryUtils, type EdenTreatyQueryUtilsUniversalUtils, type EdenTreatySvelteQuery, type EdenTreatySvelteQueryBase, type EdenTreatySvelteQueryContextProps, type EdenTreatySvelteQueryCreateQueries, type EdenTreatySvelteQueryCreateQueriesLeaf, type EdenTreatySvelteQueryCreateQueriesMutationLeaf, type EdenTreatySvelteQueryCreateQueriesPathHooks, type EdenTreatySvelteQueryCreateQueriesProxy, type EdenTreatySvelteQueryCreateQueriesProxyMapping, type EdenTreatySvelteQueryCreateQueriesQueryLeaf, type EdenTreatySvelteQueryCreateQueriesSubscriptionLeaf, type EdenTreatySvelteQueryCreateQueriesUnknownLeaf, type EdenTreatySvelteQueryHooks, type EdenTreatySvelteQueryHooksPathParameterHook, type EdenTreatySvelteQueryHooksProxy, type EdenTreatySvelteQueryInfiniteQueryLeaf, type EdenTreatySvelteQueryLeaf, type EdenTreatySvelteQueryMutationLeaf, type EdenTreatySvelteQueryPathHooks, type EdenTreatySvelteQueryRouteLeaf, type EdenTreatySvelteQuerySubscriptionLeaf, type EdenTreatySvelteQueryUnknownLeaf, type EdenTreatySvelteQueryUtils, type EdenTreatySvelteQueryUtilsProxy, type InferTreatyQueryIO, type InferTreatyQueryIOMapping, type InferTreatyQueryInput, type InferTreatyQueryInputMapping, type InferTreatyQueryOutput, type InferTreatyQueryOutputMapping, createEdenTreatyQueryRootHooks, createEdenTreatyQueryUtils, createEdenTreatyQueryUtilsProxy, createEdenTreatySvelteQuery, createEdenTreatySvelteQueryProxy, createTreatySvelteQueryCreateQueriesProxy, getMutationKey, getQueryKey, mergeDehydrated, routeDefinitionSymbol };