import { Effect } from "effect/Effect"; import { DefaultError, MutationOptions, QueryKey, QueryObserverOptions } from "@tanstack/query-core"; import { Input } from "effect/Duration"; import { Schema } from "effect/Schema"; import { Client } from "effect/unstable/httpapi/HttpApiClient"; import { HttpApiEndpoint } from "effect/unstable/httpapi/HttpApiEndpoint"; import { SseEventFromData, StreamSse } from "effect/unstable/httpapi/HttpApiSchema"; //#region src/types.d.ts type TanstackQueryOptionsProxy = T extends Client.Method, infer _Error, infer _Requires> ? { query: Method extends 'GET' ? (input: MakeInput) => UnwrapCodec | Promise> : never; queryEffect: Method extends 'GET' ? (input: MakeInput) => Effect, UnwrapCodec> : never; queryOptions: Method extends 'GET' ? , UnwrapCodec>>(input: MakeInput, options?: Omit) => TQuery : never; subscriptionOptions: Success extends StreamSse, infer StreamError, infer _StreamValue> ? (input: MakeInput, options?: Omit, UnwrapCodec>, 'subcriptionKey' | 'subscriptionFn'>) => SubscriptionOptions, UnwrapCodec> : never; mutate: Method extends 'GET' ? never : (input: MakeInput) => UnwrapCodec | Promise>; mutateEffect: Method extends 'GET' ? never : (input: MakeInput) => Effect, UnwrapCodec>; mutationOptions: Method extends 'GET' ? never : , UnwrapCodec, UnwrapCodec>>(input: MakeInput, options?: Omit) => TMutation; getQueryKey: Method extends 'GET' ? (input?: Partial>) => QueryKey : never; } : T extends object ? { readonly [K in keyof T as K extends symbol ? never : K]: TanstackQueryOptionsProxy; } : T; interface SubscriptionOptions { /** * Determines whether the subscription is active. If set to `false`, the subscription will not be initiated. * Default is `true`. */ enabled?: boolean; /** * Configuration for the heartbeat keep-alive mechanism to prevent connection timeouts. * * @property{string} message The string payload sent by the server to maintain the connection. Default is `":keep-alive"`. * @property{Input} timeout The maximum duration to wait for a heartbeat or data payload before timing out and reconnecting. Default is `10 seconds`. */ keepAlive?: { message?: string; timeout?: Input; }; /** * Defines the retry schedule or delay duration before attempting to reconnect when the stream disconnects or fails. * Accepts an `Effect.Duration.Input` (e.g., `"3 seconds"`, `3000`, or `Duration.seconds(3)`). */ autoReconnect?: Input; /** * A unique key that identifies the subscription. This key is used for caching and managing the subscription state. */ subcriptionKey: readonly unknown[]; /** * Initiates the subscription. * * @param options.signal An `AbortSignal` used to cancel the active subscription. * @param options.keepAliveTimeout Maximum duration to wait for data or server `:keep-alive` events before timing out. Default is 10 seconds. */ subscriptionFn: (options: Omit, 'enabled' | 'subcriptionKey' | 'subscriptionFn'>) => () => void; /** * Callback invoked when the subscription is started. */ onStarted?: () => void; /** * Callback invoked when new data is received from the subscription. */ onData?: (data: TData) => void; /** * Callback invoked when an error occurs during the subscription. */ onError?: (error: TError) => void; /** * Callback invoked when the connection's status changes */ onConnectionChange?: (result: Partial>) => void; } type QueryOptions = QueryObserverOptions & { subscribed?: boolean; }; type UseSubscriptionReturns = { reset: () => void; } & ({ status: 'idle'; data: null; error: null; } | { status: 'connecting'; data: TData | null; error: TError | null; } | { status: 'pending'; data: TData | null; error: null; } | { status: 'error'; data: TData | null; error: TError; }); type UnwrapCodec = T extends Schema ? Schema.Type : T extends object ? { [K in keyof T]: UnwrapCodec; } : T; type MakeOptionalInput = keyof T extends never ? void | undefined : T; type MakeInput = MakeOptionalInput<([Headers] extends [never] ? unknown : { headers: UnwrapCodec; }) & ([Params] extends [never] ? unknown : { params: UnwrapCodec; }) & ([Query] extends [never] ? unknown : { query: UnwrapCodec; }) & ([Payload] extends [never] ? unknown : { payload: UnwrapCodec; })>; //#endregion export { TanstackQueryOptionsProxy as n, UseSubscriptionReturns as r, SubscriptionOptions as t };