@ueberbrot/effect-api-query
Version:
Type-safe TanStack Query utilities derived from Effect RPC and HTTP API contracts.
859 lines • 74.8 kB
text/typescript
import { DataTag, DefaultError, DehydratedState, InfiniteData, InfiniteQueryObserverOptions, InitialDataFunction, MutationFunctionContext, MutationObserverOptions, NonUndefinedGuard, QueryClient, QueryExecuteOptions, QueryFilters, QueryFunction, QueryFunctionContext, QueryKey, QueryObserverOptions, SkipToken, SkipToken as SkipToken$1, dataTagErrorSymbol, dataTagSymbol, skipToken } from "@tanstack/query-core";
import { Brand, Cause, Context, Duration, Effect, Exit, Option, Redacted, Schema, SchemaAST, Stream } from "effect";
import { Rpc, RpcClient, RpcGroup, RpcSchema } from "effect/rpc";
import { HttpApi, HttpApiClient, HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "effect/http-api";
import { Headers as Headers$1 } from "effect/http";
import { Sse } from "effect/encoding";
//#region src/core/inference.d.ts
type QueryView = "query" | "infinite" | "metadata" | "live" | "streamed";
type SupportedQueryView<Leaf> = { [View in QueryView]: [Leaf] extends [Record<`${View}Key`, (...args: never[]) => unknown>] ? [Leaf] extends [Record<`${View}Options`, (...args: never[]) => unknown>] ? View : never : never; }[QueryView];
type QueryViewKey<Leaf, View extends QueryView> = Leaf extends Record<`${View}Key`, (...args: never[]) => infer Key> ? Key : never;
type QueryPageData<Data, View extends QueryView> = View extends "infinite" ? Data extends InfiniteData<infer Page> ? Page : never : Data;
type QueryPageParam<Data, View extends QueryView> = View extends "infinite" ? Data extends InfiniteData<unknown, infer PageParam> ? PageParam : never : never;
interface MutationLeaf$1 {
readonly mutationOptions: (...args: never[]) => unknown;
}
type MutationResult<Leaf> = Leaf extends {
readonly mutationOptions: (...args: never[]) => infer Options;
} ? Options : never;
type OptionsInput<Leaf> = Leaf extends {
readonly streamedOptions: (...args: infer Args) => unknown;
} ? NonNullable<Args[0]> extends {
readonly input: infer Input;
} ? Exclude<Input, SkipToken$1 | PreparedInput<unknown>> : void : Leaf extends {
readonly queryKey: (...args: infer Args) => unknown;
} ? Args extends [] ? void : Exclude<Args[0], PreparedInput<unknown>> : never;
/** The RPC payload constructor input or decoded HTTP request accepted by a leaf. */
type InferInput<Leaf> = [MutationResult<Leaf>] extends [never] ? OptionsInput<Leaf> : MutationResult<Leaf> extends {
readonly mutationFn: (input: infer Input) => unknown;
} ? Input : never;
/** The cached data for a supported view, before an observer's select projection. */
type InferQueryData<Leaf, View extends SupportedQueryView<Leaf> = Extract<"query", SupportedQueryView<Leaf>>> = [QueryViewKey<Leaf, View>] extends [never] ? never : QueryViewKey<Leaf, View> extends {
readonly [dataTagSymbol]: infer Data;
} ? Data : never;
/** The execution and package errors carried by a supported view's concrete key. */
type InferQueryError<Leaf, View extends SupportedQueryView<Leaf> = Extract<"query", SupportedQueryView<Leaf>>> = [QueryViewKey<Leaf, View>] extends [never] ? never : QueryViewKey<Leaf, View> extends {
readonly [dataTagErrorSymbol]: infer Error;
} ? Error : never;
/** The unmodified successful value returned by a buffered mutation. */
type InferMutationData<Leaf> = [MutationResult<Leaf>] extends [never] ? never : MutationResult<Leaf> extends {
readonly mutationFn: (...args: never[]) => Promise<infer Data>;
} ? Data : never;
/** The execution error exposed by a buffered mutation. */
type InferMutationError<Leaf> = [MutationResult<Leaf>] extends [never] ? never : MutationResult<Leaf> extends {
readonly retry?: boolean | number | ((count: number, error: infer Error) => boolean);
} ? Error : never;
//#endregion
//#region src/core/prepared-input.d.ts
/** Opaque, owner-bound preparation. Retained execution input must remain unchanged. */
interface PreparedInput<Input> {
readonly "~effect-api-query/PreparedInput": {
readonly input?: Input;
};
}
/** Constructs and encodes once for repeated keys/options on this utility leaf. */
export declare const prepareInput: <Leaf extends {
readonly key: () => QueryKey;
}>(leaf: Leaf & ([SupportedQueryView<Leaf>] extends [never] ? never : unknown), input: InferInput<NoInfer<Leaf>>) => PreparedInput<InferInput<Leaf>>;
//#endregion
//#region src/core/types.d.ts
type JsonPrimitive = boolean | null | number | string;
/** An immutable JSON value accepted in cache keys. */
type JsonValue = JsonPrimitive | {
readonly [key: string]: JsonValue;
} | readonly JsonValue[];
type QueryData<A> = undefined extends A ? Exclude<A, undefined | void> | null : A;
/** Runs an Effect and returns its Exit, optionally forwarding an abort signal. */
type RunPromiseExit<R = never> = <A, E>(effect: Effect.Effect<A, E, R>, options?: {
readonly signal?: AbortSignal;
}) => Promise<Exit.Exit<A, E>>;
/** Requires encoders only when eligible requests need an override. */
type KeyEncoderRequirement<Eligible, Required, Encoders> = [Eligible] extends [never] ? {
readonly keyEncoders?: never;
} : [Required] extends [never] ? {
/** Overrides synchronous semantic encoding for selected requests. */
readonly keyEncoders?: Encoders;
} : {
/** Supplies safe synchronous cache identity for requests requiring an encoder. */
readonly keyEncoders: Encoders;
};
/** Requires a custom runner when client-side Schema services remain. */
type RunnerRequirement<Services> = [Services] extends [never] ? {
/** Overrides service-free execution; defaults to `Effect.runPromiseExit`. */
readonly runPromiseExit?: RunPromiseExit;
} : {
/** Runs Effects that retain client-side Schema services. */
readonly runPromiseExit: RunPromiseExit<Services>;
};
/** Uses the adapter's inputless proof to determine key-builder arguments. */
type KeyBuilder<Input, Key, Inputless extends boolean> = [Inputless] extends [true] ? () => Key : (input: Input | PreparedInput<Input>) => Key;
type OwnedQueryOption = "queryFn" | "queryKey" | "queryKeyHashFn" | "queryHash";
type OwnedMutationOption = "mutationFn" | "mutationKey";
type StreamRefetchMode = "append" | "replace" | "reset";
type StreamedPolicyOptions = {
/** Controls whether a refetch clears, appends to, or replaces accumulated data. */
readonly refetchMode?: StreamRefetchMode | undefined;
/** Keeps the newest elements, or retains the complete history when explicitly unbounded. */
readonly maxChunks: number | "unbounded";
/** Publishes the first element immediately, then ordered batches; defaults to one. */
readonly publicationBatchSize?: number | undefined;
/** Flushes a partial batch after this many milliseconds; omitted means count-only. */
readonly publicationMaxWaitMs?: number | undefined;
};
type WithDefinedInitialData<Options, Data> = Omit<Options, "initialData"> & {
readonly initialData: NonUndefinedGuard<Data> | (() => NonUndefinedGuard<Data>);
};
type WithUndefinedInitialData<Options, Data> = Omit<Options, "initialData"> & {
readonly initialData?: undefined | InitialDataFunction<NonUndefinedGuard<Data>> | NonUndefinedGuard<Data>;
};
type QueryInput<Data, Error, Selected, Key extends QueryKey, AdapterOptions = unknown> = Omit<QueryObserverOptions<Data, Error, Selected, Data, Key>, OwnedQueryOption> & AdapterOptions;
type GeneratedQueryFunction<Data, Key extends QueryKey> = QueryFunction<Data> & QueryFunction<Data, Key>;
type QueryOptions<Data, Error, Selected, Key extends QueryKey, Fn = GeneratedQueryFunction<Data, Key>> = QueryInput<Data, Error, Selected, Key> & {
readonly queryFn: Fn;
readonly queryKey: Key;
};
type ConditionalQueryOptions<Data, Error, Selected, Key extends QueryKey> = QueryOptions<Data, Error, Selected, Key, GeneratedQueryFunction<Data, Key> | SkipToken$1>;
type InputQueryOptions<Input, Data, Error, Selected, Key extends QueryKey, SkippedKey extends QueryKey> = unknown extends Input ? ConditionalQueryOptions<Data, Error, Selected, Key | SkippedKey> : [Input] extends [SkipToken$1] ? QueryOptions<Data, Error, Selected, SkippedKey, SkipToken$1> : SkipToken$1 extends Input ? ConditionalQueryOptions<Data, Error, Selected, Key | SkippedKey> : QueryOptions<Data, Error, Selected, Key>;
type KeysOfUnion<Value> = Value extends unknown ? keyof Value : never;
type UnionProperty<Value, Key extends PropertyKey> = Value extends unknown ? Key extends keyof Value ? Value[Key] : never : never;
type ExactBuilderOptions<Expected, Supplied> = Expected & Supplied & { readonly [Key in Exclude<KeysOfUnion<Supplied>, keyof Expected | typeof uninferredBuilderOptions>]: string extends Key ? UnionProperty<Supplied, Key> : number extends Key ? UnionProperty<Supplied, Key> : never; };
type SuppliedInitialData<Supplied> = "initialData" extends keyof Supplied ? undefined extends Supplied["initialData"] ? Omit<Supplied, "initialData"> & {
readonly initialData?: Exclude<Supplied["initialData"], undefined>;
} : Supplied : Supplied;
declare const uninferredBuilderOptions: unique symbol;
interface UninferredBuilderOptions {
readonly [uninferredBuilderOptions]?: never;
}
type RetainedQueryOptions<Options> = Pick<Options, Extract<keyof Options, "queryFn" | "queryKey" | "select" | "retry" | "retryDelay" | "throwOnError" | "initialPageParam" | "getNextPageParam">>;
type SuppliedQueryOptions<Options, Supplied, AdapterOptions> = typeof uninferredBuilderOptions extends keyof Supplied ? Options : RetainedQueryOptions<Options> & Omit<SuppliedInitialData<Supplied>, "input" | keyof AdapterOptions>;
interface InputQueryBuilder<Input, Data, Error, Key extends QueryKey, SkippedKey extends QueryKey, AdapterOptions> {
<Selected = Data, ActualInput extends Input = Input, Supplied extends object = UninferredBuilderOptions>(options: ExactBuilderOptions<WithDefinedInitialData<QueryInput<Data, Error, Selected, InputQueryOptions<ActualInput, Data, Error, Selected, Key, SkippedKey>["queryKey"], AdapterOptions>, Data> & {
readonly input: ActualInput;
}, Supplied>): WithDefinedInitialData<SuppliedQueryOptions<InputQueryOptions<ActualInput, Data, Error, Selected, Key, SkippedKey>, Supplied, AdapterOptions>, Data>;
<Selected = Data, ActualInput extends Input = Input, Supplied extends object = UninferredBuilderOptions>(options: ExactBuilderOptions<WithUndefinedInitialData<QueryInput<Data, Error, Selected, InputQueryOptions<ActualInput, Data, Error, Selected, Key, SkippedKey>["queryKey"], AdapterOptions>, Data> & {
readonly input: ActualInput;
}, Supplied>): SuppliedQueryOptions<InputQueryOptions<ActualInput, Data, Error, Selected, Key, SkippedKey>, Supplied, AdapterOptions>;
}
declare const unaryQueryBuilderTypes: unique symbol;
type UnaryQueryBuilderDescriptor<Builder> = typeof unaryQueryBuilderTypes extends keyof Builder ? NonNullable<Builder[typeof unaryQueryBuilderTypes]> : never;
type RequiredAdapterKeys<Options> = { [Key in keyof Options]-?: Options extends Readonly<Record<Key, Options[Key]>> ? Key : never; }[keyof Options];
type BuilderArguments<Options, AdapterOptions> = [RequiredAdapterKeys<AdapterOptions>] extends [never] ? [options?: Options] : [options: Options];
type UnaryQueryBuilder<Input, Data, Error, Key extends QueryKey, SkippedKey extends QueryKey, AdapterOptions = unknown, Inputless extends boolean = void extends Input ? true : false> = UnaryQueryBuilderImpl<Input | PreparedInput<Input>, Data, Error, Key, SkippedKey, AdapterOptions, Inputless> & {
readonly [unaryQueryBuilderTypes]?: {
readonly input: Input;
readonly data: Data;
readonly error: Error;
readonly key: Key;
readonly skippedKey: SkippedKey;
readonly adapterOptions: (options: AdapterOptions) => void;
readonly inputless: Inputless;
};
};
type UnaryQueryBuilderImpl<Input, Data, Error, Key extends QueryKey, SkippedKey extends QueryKey, AdapterOptions = unknown, Inputless extends boolean = void extends Input ? true : false> = Inputless extends true ? {
<Selected = Data>(...args: [RequiredAdapterKeys<AdapterOptions>] extends [never] ? [options?: undefined] : [options: never]): RetainedQueryOptions<QueryOptions<Data, Error, Selected, Key>>;
<Selected = Data, Supplied extends object = UninferredBuilderOptions>(options: ExactBuilderOptions<WithDefinedInitialData<QueryInput<Data, Error, Selected, Key, AdapterOptions>, Data>, Supplied>): WithDefinedInitialData<SuppliedQueryOptions<QueryOptions<Data, Error, Selected, Key>, Supplied, AdapterOptions>, Data>;
<Selected = Data, Supplied extends object = UninferredBuilderOptions>(...args: BuilderArguments<ExactBuilderOptions<WithUndefinedInitialData<QueryInput<Data, Error, Selected, Key, AdapterOptions>, Data>, Supplied>, AdapterOptions>): SuppliedQueryOptions<QueryOptions<Data, Error, Selected, Key>, Supplied, AdapterOptions>;
} : InputQueryBuilder<SkipToken$1, Data, Error, Key, SkippedKey, AdapterOptions> & InputQueryBuilder<Input, Data, Error, Key, SkippedKey, AdapterOptions> & {
<Selected = Data, Supplied extends object = UninferredBuilderOptions>(options: ExactBuilderOptions<WithDefinedInitialData<Omit<ConditionalQueryOptions<Data, Error, Selected, Key | SkippedKey>, OwnedQueryOption>, Data> & AdapterOptions & {
readonly input: Input | SkipToken$1;
}, Supplied>): WithDefinedInitialData<SuppliedQueryOptions<ConditionalQueryOptions<Data, Error, Selected, Key | SkippedKey>, Supplied, AdapterOptions>, Data>;
<Selected = Data, Supplied extends object = UninferredBuilderOptions>(options: ExactBuilderOptions<WithUndefinedInitialData<Omit<ConditionalQueryOptions<Data, Error, Selected, Key | SkippedKey>, OwnedQueryOption>, Data> & AdapterOptions & {
readonly input: Input | SkipToken$1;
}, Supplied>): SuppliedQueryOptions<ConditionalQueryOptions<Data, Error, Selected, Key | SkippedKey>, Supplied, AdapterOptions>;
};
type InfiniteInput<Data, Error, Selected, Key extends QueryKey, PageParam, AdapterOptions = unknown> = Omit<InfiniteQueryObserverOptions<Data, Error, Selected, Key, PageParam>, OwnedQueryOption> & AdapterOptions;
type InfiniteOptions<Data, Error, Selected, Key extends QueryKey, PageParam, Fn = QueryFunction<Data, QueryKey, PageParam>> = InfiniteInput<Data, Error, Selected, Key, PageParam> & {
readonly queryFn: Fn;
readonly queryKey: Key;
};
type InfiniteQueryKey<Input, Data, Error, OperationKey extends readonly JsonValue[], PageParam = unknown, Inputless extends boolean = void extends Input ? true : false> = DataTag<Inputless extends true ? OperationKey : readonly [...OperationKey, unknown], InfiniteData<Data, PageParam>, Error>;
type MappedInfiniteInput<Input, Data, Error, OperationKey extends readonly JsonValue[], Selected, PageParam, AdapterOptions, Inputless extends boolean> = InfiniteInput<Data, Error, Selected, InfiniteQueryKey<Input, Data, Error, OperationKey, PageParam, Inputless>, PageParam, AdapterOptions> & (Inputless extends true ? unknown : {
readonly input: (pageParam: PageParam) => Input;
});
type ConditionalInfiniteOptions<Data, Error, Selected, Key extends QueryKey, PageParam> = InfiniteOptions<Data, Error, Selected, Key, PageParam, QueryFunction<Data, QueryKey, PageParam> | SkipToken$1>;
type InfiniteQueryBuilder<Input, Data, Error, OperationKey extends readonly JsonValue[], AdapterOptions = unknown, Inputless extends boolean = void extends Input ? true : false> = {
<PageParam, Selected = InfiniteData<Data, PageParam>, Supplied extends object = UninferredBuilderOptions>(options: ExactBuilderOptions<WithDefinedInitialData<MappedInfiniteInput<Input, Data, Error, OperationKey, Selected, PageParam, AdapterOptions, Inputless>, InfiniteData<Data, PageParam>>, Supplied>): WithDefinedInitialData<SuppliedQueryOptions<InfiniteOptions<Data, Error, Selected, InfiniteQueryKey<Input, Data, Error, OperationKey, PageParam, Inputless>, PageParam>, Supplied, AdapterOptions>, InfiniteData<Data, PageParam>>;
<PageParam, Selected = InfiniteData<Data, PageParam>, Supplied extends object = UninferredBuilderOptions>(options: ExactBuilderOptions<WithUndefinedInitialData<MappedInfiniteInput<Input, Data, Error, OperationKey, Selected, PageParam, AdapterOptions, Inputless>, InfiniteData<Data, PageParam>>, Supplied>): SuppliedQueryOptions<InfiniteOptions<Data, Error, Selected, InfiniteQueryKey<Input, Data, Error, OperationKey, PageParam, Inputless>, PageParam>, Supplied, AdapterOptions>;
} & (Inputless extends true ? unknown : {
<PageParam, Selected = InfiniteData<Data, PageParam>, Supplied extends object = UninferredBuilderOptions>(options: ExactBuilderOptions<WithDefinedInitialData<InfiniteInput<Data, Error, Selected, OperationKey, PageParam, AdapterOptions>, InfiniteData<Data, PageParam>> & {
readonly input: SkipToken$1;
}, Supplied>): WithDefinedInitialData<SuppliedQueryOptions<InfiniteOptions<Data, Error, Selected, OperationKey, PageParam, SkipToken$1>, Supplied, AdapterOptions>, InfiniteData<Data, PageParam>>;
<PageParam, Selected = InfiniteData<Data, PageParam>, Supplied extends object = UninferredBuilderOptions>(options: ExactBuilderOptions<WithUndefinedInitialData<InfiniteInput<Data, Error, Selected, OperationKey, PageParam, AdapterOptions>, InfiniteData<Data, PageParam>> & {
readonly input: SkipToken$1;
}, Supplied>): SuppliedQueryOptions<InfiniteOptions<Data, Error, Selected, OperationKey, PageParam, SkipToken$1>, Supplied, AdapterOptions>;
<PageParam, Selected = InfiniteData<Data, PageParam>, Supplied extends object = UninferredBuilderOptions>(options: ExactBuilderOptions<WithDefinedInitialData<InfiniteInput<Data, Error, Selected, InfiniteQueryKey<Input, Data, Error, OperationKey, PageParam, Inputless> | OperationKey, PageParam, AdapterOptions>, InfiniteData<Data, PageParam>> & {
readonly input: ((pageParam: PageParam) => Input) | SkipToken$1;
}, Supplied>): WithDefinedInitialData<SuppliedQueryOptions<ConditionalInfiniteOptions<Data, Error, Selected, InfiniteQueryKey<Input, Data, Error, OperationKey, PageParam, Inputless> | OperationKey, PageParam>, Supplied, AdapterOptions>, InfiniteData<Data, PageParam>>;
<PageParam, Selected = InfiniteData<Data, PageParam>, Supplied extends object = UninferredBuilderOptions>(options: ExactBuilderOptions<WithUndefinedInitialData<InfiniteInput<Data, Error, Selected, InfiniteQueryKey<Input, Data, Error, OperationKey, PageParam, Inputless> | OperationKey, PageParam, AdapterOptions>, InfiniteData<Data, PageParam>> & {
readonly input: ((pageParam: PageParam) => Input) | SkipToken$1;
}, Supplied>): SuppliedQueryOptions<ConditionalInfiniteOptions<Data, Error, Selected, InfiniteQueryKey<Input, Data, Error, OperationKey, PageParam, Inputless> | OperationKey, PageParam>, Supplied, AdapterOptions>;
});
type MutationOptions<Data, Error, Input, Key extends QueryKey, OnMutateResult> = Omit<MutationObserverOptions<Data, Error, Input, OnMutateResult>, OwnedMutationOption> & {
readonly mutationFn: (variables: Input) => Promise<Data>;
readonly mutationKey: Key;
};
type MutationBuilder<Data, Error, Input, Key extends QueryKey, AdapterOptions = unknown> = <OnMutateResult = unknown>(options?: Omit<MutationObserverOptions<Data, Error, Input, OnMutateResult>, OwnedMutationOption> & { readonly [Key in OwnedMutationOption]?: never; } & AdapterOptions) => MutationOptions<Data, Error, Input, Key, OnMutateResult>;
type HasSeenType<A, Seen> = Seen extends unknown ? (<T>() => T extends A ? 1 : 2) extends (<T>() => (T extends Seen ? 1 : 2)) ? true : false : never;
type ContainsRedacted<A, Seen = never> = A extends Redacted.Redacted<unknown> ? true : true extends HasSeenType<A, Seen> ? false : A extends readonly (infer Value)[] ? ContainsRedacted<Value, Seen | A> : A extends object ? true extends { readonly [Key in keyof A]: ContainsRedacted<A[Key], Seen | A>; }[keyof A] ? true : false : false;
//#endregion
//#region src/rpc/errors.d.ts
/** Stable codes for invalid RPC utility configuration. */
type EffectRpcQueryConfigErrorCode = "InvalidMaxChunks" | "InvalidRefetchMode" | "InvalidKeyPrefix" | "InvalidRpcPath" | "RpcPathCollision" | "MissingKeyEncoder" | "UnknownKeyEncoder" | "UnsupportedQueryHash";
/** Stable codes for synchronous query-key preparation failures. */
type EffectRpcQueryKeyErrorCode = "PayloadConstructionFailed" | "PayloadEncodingFailed" | "KeyEncoderFailed" | "InvalidKeyValue";
/** The TanStack operation that executed an RPC. */
type RpcOperation = "infinite" | "live" | "mutation" | "query" | "streamed";
/** Identifies the failed configuration entry and retains any underlying failure. */
interface EffectRpcQueryConfigErrorOptions {
/** The underlying failure, when one exists. */
readonly cause?: unknown;
/** The existing projected path associated with a collision. */
readonly path?: string;
/** The RPC or encoder tag associated with the invalid configuration. */
readonly rpcTag?: string;
}
/**
* Wraps a failed RPC Exit for TanStack while preserving its complete Effect Cause.
*
* Runner rejections pass through unchanged; this class wraps failed Exits.
*/
export declare class EffectRpcQueryError<E> extends Error {
/** Identifies this error without relying on `instanceof`. */
readonly _tag = "EffectRpcQueryError";
/** The literal tag of the RPC that failed. */
readonly rpcTag: string;
/** The operation that ran the RPC. */
readonly operation: RpcOperation;
/** The original Cause returned by the Effect runner. */
readonly cause: Cause.Cause<E>;
constructor(rpcTag: string, operation: RpcOperation, cause: Cause.Cause<E>);
}
/** Reports a live RPC stream that completed before emitting its first value. */
export declare class EffectRpcQueryEmptyStreamError extends Error {
/** Identifies this error without relying on `instanceof`. */
readonly _tag = "EffectRpcQueryEmptyStreamError";
/** The streaming RPC that completed empty. */
readonly rpcTag: string;
constructor(rpcTag: string);
}
/** Reports invalid factory, builder, or stream cache configuration. */
export declare class EffectRpcQueryConfigError extends Error {
/** Identifies this error without relying on `instanceof`. */
readonly _tag = "EffectRpcQueryConfigError";
/** A stable, machine-readable description of the failure. */
readonly code: EffectRpcQueryConfigErrorCode;
/** The underlying failure, when one exists. */
readonly cause?: unknown;
/** The existing projected path associated with a collision. */
readonly path: string | undefined;
/** The RPC or encoder tag associated with the invalid configuration. */
readonly rpcTag: string | undefined;
constructor(code: EffectRpcQueryConfigErrorCode, message: string, options?: EffectRpcQueryConfigErrorOptions);
}
/** Reports synchronous payload construction, encoding, or canonicalization failures. */
export declare class EffectRpcQueryKeyError extends Error {
/** Identifies this error without relying on `instanceof`. */
readonly _tag = "EffectRpcQueryKeyError";
/** A stable, machine-readable description of the failure. */
readonly code: EffectRpcQueryKeyErrorCode;
/** The RPC whose query key could not be prepared. */
readonly rpcTag: string;
/** The underlying failure, when one exists. */
readonly cause?: unknown;
constructor(code: EffectRpcQueryKeyErrorCode, rpcTag: string, message: string, cause?: unknown);
}
/** Returns whether a value is an RPC execution error from this JavaScript realm. */
export declare const isEffectRpcQueryError: (value: unknown) => value is EffectRpcQueryError<unknown>;
//#endregion
//#region src/rpc/types.d.ts
/** Request-local options for unary queries, infinite queries, and mutations. */
interface UnaryRpcOptions {
readonly headers?: Headers$1.Input | undefined;
readonly context?: Context.Context<never> | undefined;
/** The generated query or mutation requires the RPC result. */
readonly discard?: never;
/** Stream adaptation belongs to the package. */
readonly asQueue?: never;
readonly streamBufferSize?: never;
}
/** Request-local options for accumulated-stream and live queries. */
interface StreamingRpcOptions extends Omit<UnaryRpcOptions, "streamBufferSize"> {
readonly streamBufferSize?: number | undefined;
}
interface RpcOptionsInput<Options = UnaryRpcOptions> {
readonly rpcOptions?: Options;
}
/** Converts a normalized RPC payload into a synchronous, JSON-safe key value. */
type KeyEncoder<R extends Rpc.Any> = (payload: Rpc.Payload<R>) => JsonValue;
type RpcsOf<Group extends RpcGroup.Any> = RpcGroup.Rpcs<Group>;
type PayloadSchema<R extends Rpc.Any> = R extends Rpc.Rpc<infer _Tag, infer Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? Payload : never;
type PayloadlessRpc<R extends Rpc.Any> = [PayloadSchema<R>["ast"]] extends [SchemaAST.Void] ? true : false;
type StreamingRpc<R extends Rpc.Any> = Rpc.SuccessSchema<R> extends RpcSchema.Stream<Schema.Top, Schema.Top> ? R : never;
type PayloadBearingRpcs<Group extends RpcGroup.Any> = RpcsOf<Group> extends (infer R) ? R extends Rpc.Any ? PayloadlessRpc<R> extends true ? never : R : never : never;
type ClientMiddlewareError<R extends Rpc.Any> = R extends Rpc.Rpc<string, Schema.Top, Schema.Top, Schema.Top, infer Middleware, unknown> ? Middleware["~ClientError"] : never;
type RpcFailure<R extends Rpc.Any, ClientError> = Rpc.Error<R> | ClientMiddlewareError<R> | ClientError;
type RpcStreamFailure<R extends Rpc.Any, ClientError> = Rpc.ErrorExit<R> | ClientMiddlewareError<R> | ClientError;
type RpcStreamQueryError<R extends Rpc.Any, ClientError> = EffectRpcQueryConfigError | EffectRpcQueryError<RpcStreamFailure<R, ClientError>>;
type RpcLiveError<R extends Rpc.Any, ClientError> = EffectRpcQueryEmptyStreamError | RpcStreamQueryError<R, ClientError>;
type Segments<Tag extends string> = Tag extends `${infer Head}.${infer Tail}` ? readonly [Head, ...Segments<Tail>] : readonly [Tag];
type RpcKey<Prefix extends readonly JsonValue[], R extends Rpc.Any> = readonly [...Prefix, "rpc", ...Segments<R["_tag"]>];
type QueryOperationKey<Prefix extends readonly JsonValue[], R extends Rpc.Any> = readonly [...RpcKey<Prefix, R>, "query"];
type InfiniteOperationKey<Prefix extends readonly JsonValue[], R extends Rpc.Any> = readonly [...RpcKey<Prefix, R>, "infinite"];
type StreamedOperationKey<Prefix extends readonly JsonValue[], R extends Rpc.Any> = readonly [...RpcKey<Prefix, R>, "streamed"];
type LiveOperationKey<Prefix extends readonly JsonValue[], R extends Rpc.Any> = readonly [...RpcKey<Prefix, R>, "live"];
type ConcreteQueryKey<Prefix extends readonly JsonValue[], R extends Rpc.Any, ClientError> = DataTag<PayloadlessRpc<R> extends true ? QueryOperationKey<Prefix, R> : readonly [...QueryOperationKey<Prefix, R>, unknown], QueryData<Rpc.Success<R>>, EffectRpcQueryError<RpcFailure<R, ClientError>>>;
type MutationKey<Prefix extends readonly JsonValue[], R extends Rpc.Any> = readonly [...RpcKey<Prefix, R>, "mutation"];
type QueryOptionsBuilder<R extends Rpc.Any, Prefix extends readonly JsonValue[], ClientError> = UnaryQueryBuilder<Rpc.PayloadConstructor<R>, QueryData<Rpc.Success<R>>, EffectRpcQueryError<RpcFailure<R, ClientError>>, ConcreteQueryKey<Prefix, R, ClientError>, QueryOperationKey<Prefix, R>, RpcOptionsInput, PayloadlessRpc<R>>;
type QueryKeyBuilder<R extends Rpc.Any, Prefix extends readonly JsonValue[], ClientError> = KeyBuilder<Rpc.PayloadConstructor<R>, ConcreteQueryKey<Prefix, R, ClientError>, PayloadlessRpc<R>>;
type ConcreteInfiniteKey$1<Prefix extends readonly JsonValue[], R extends Rpc.Any, ClientError, PageParam = unknown> = InfiniteQueryKey<Rpc.PayloadConstructor<R>, QueryData<Rpc.Success<R>>, EffectRpcQueryError<RpcFailure<R, ClientError>>, InfiniteOperationKey<Prefix, R>, PageParam, PayloadlessRpc<R>>;
type InfiniteOptionsBuilder<R extends Rpc.Any, Prefix extends readonly JsonValue[], ClientError> = InfiniteQueryBuilder<Rpc.PayloadConstructor<R>, QueryData<Rpc.Success<R>>, EffectRpcQueryError<RpcFailure<R, ClientError>>, InfiniteOperationKey<Prefix, R>, RpcOptionsInput, PayloadlessRpc<R>>;
type InfiniteKeyBuilder<R extends Rpc.Any, Prefix extends readonly JsonValue[], ClientError> = KeyBuilder<Rpc.PayloadConstructor<R>, ConcreteInfiniteKey$1<Prefix, R, ClientError>, PayloadlessRpc<R>>;
type StreamedData<R extends Rpc.Any> = readonly Rpc.SuccessChunk<R>[];
type ConcreteStreamedKey<Prefix extends readonly JsonValue[], R extends Rpc.Any, ClientError> = DataTag<PayloadlessRpc<R> extends true ? readonly [...StreamedOperationKey<Prefix, R>, unknown] : readonly [...StreamedOperationKey<Prefix, R>, unknown, unknown], StreamedData<R>, RpcStreamQueryError<R, ClientError>>;
type ConcreteLiveKey<Prefix extends readonly JsonValue[], R extends Rpc.Any, ClientError> = DataTag<PayloadlessRpc<R> extends true ? LiveOperationKey<Prefix, R> : readonly [...LiveOperationKey<Prefix, R>, unknown], QueryData<Rpc.SuccessChunk<R>>, RpcLiveError<R, ClientError>>;
type StreamingQueryBuilder<Input, Data, Error, Key extends QueryKey, SkippedKey extends QueryKey, Policy = unknown, Inputless extends boolean = void extends Input ? true : false> = UnaryQueryBuilder<Input, Data, Error, Key, SkippedKey, Policy & RpcOptionsInput<StreamingRpcOptions>, Inputless>;
type StreamedOptionsBuilder<R extends Rpc.Any, Prefix extends readonly JsonValue[], ClientError> = StreamingQueryBuilder<Rpc.PayloadConstructor<R>, StreamedData<R>, RpcStreamQueryError<R, ClientError>, ConcreteStreamedKey<Prefix, R, ClientError>, StreamedOperationKey<Prefix, R>, StreamedPolicyOptions, PayloadlessRpc<R>>;
type LiveOptionsBuilder<R extends Rpc.Any, Prefix extends readonly JsonValue[], ClientError> = StreamingQueryBuilder<Rpc.PayloadConstructor<R>, QueryData<Rpc.SuccessChunk<R>>, RpcLiveError<R, ClientError>, ConcreteLiveKey<Prefix, R, ClientError>, LiveOperationKey<Prefix, R>, unknown, PayloadlessRpc<R>>;
type StreamKeyBuilder<R extends Rpc.Any, Key> = KeyBuilder<Rpc.PayloadConstructor<R>, Key, PayloadlessRpc<R>>;
type StreamedKeyBuilder<R extends Rpc.Any, Key> = PayloadlessRpc<R> extends true ? (policy: StreamedPolicyOptions) => Key : (input: Rpc.PayloadConstructor<R> | PreparedInput<Rpc.PayloadConstructor<R>>, policy: StreamedPolicyOptions) => Key;
/** The key and option builders exposed at one streaming RPC path. */
interface RpcStreamLeaf<R extends Rpc.Any, Prefix extends readonly JsonValue[], ClientError> {
/** Returns the immutable key prefix for this streaming RPC. */
readonly key: () => RpcKey<Prefix, R>;
/** Builds a semantic key for the latest-value view of the stream. */
readonly liveKey: StreamKeyBuilder<R, ConcreteLiveKey<Prefix, R, ClientError>>;
readonly liveOptions: LiveOptionsBuilder<R, Prefix, ClientError>;
/** Builds a semantic key for the accumulated view of the stream. */
readonly streamedKey: StreamedKeyBuilder<R, ConcreteStreamedKey<Prefix, R, ClientError>>;
/** Builds accumulated streamed-query options with Query Core refetch semantics. */
readonly streamedOptions: StreamedOptionsBuilder<R, Prefix, ClientError>;
}
/** The key and option builders exposed at one unary RPC path. */
interface RpcQueryLeaf<R extends Rpc.Any, Prefix extends readonly JsonValue[], ClientError> {
/** Builds a semantic, data-tagged infinite-query key from constructor input. */
readonly infiniteKey: InfiniteKeyBuilder<R, Prefix, ClientError>;
/** Builds fresh Query Core infinite-query options from a page-input mapper or `skipToken`. */
readonly infiniteOptions: InfiniteOptionsBuilder<R, Prefix, ClientError>;
/** Returns the immutable key prefix for this RPC. */
readonly key: () => RpcKey<Prefix, R>;
/** Returns the immutable key shared by every mutation of this RPC. */
readonly mutationKey: () => MutationKey<Prefix, R>;
/** Builds fresh Query Core mutation options without binding variables. */
readonly mutationOptions: MutationBuilder<Rpc.Success<R>, EffectRpcQueryError<RpcFailure<R, ClientError>>, Rpc.PayloadConstructor<R>, MutationKey<Prefix, R>, RpcOptionsInput>;
/** Builds a semantic, data-tagged query key from constructor input. */
readonly queryKey: QueryKeyBuilder<R, Prefix, ClientError>;
/** Builds fresh Query Core query options from constructor input or `skipToken`. */
readonly queryOptions: QueryOptionsBuilder<R, Prefix, ClientError>;
}
type RpcTagEntry<R extends Rpc.Any, Tag extends string> = Tag extends string ? {
readonly path: Tag;
readonly rpc: R & {
readonly _tag: Tag;
};
} : never;
type RpcPathEntry<R extends Rpc.Any> = R extends Rpc.Any ? RpcTagEntry<R, R["_tag"]> : never;
type PathHead<Path extends string> = Path extends `${infer Head}.${string}` ? Head : Path;
type PathDescendants<Entry, Head extends string> = Entry extends {
readonly path: `${Head}.${infer Tail}`;
readonly rpc: infer R extends Rpc.Any;
} ? {
readonly path: Tail;
readonly rpc: R;
} : never;
type PathTree<Entry extends {
readonly path: string;
readonly rpc: Rpc.Any;
}, Prefix extends readonly JsonValue[], ClientError, Path extends readonly string[] = readonly []> = { readonly [Head in PathHead<Entry["path"]>]: [PathDescendants<Entry, Head>] extends [never] ? Extract<Entry, {
readonly path: Head;
}>["rpc"] extends (infer R extends Rpc.Any) ? StreamingRpc<R> extends never ? RpcQueryLeaf<R, Prefix, ClientError> : RpcStreamLeaf<R, Prefix, ClientError> : never : {
readonly key: () => readonly [...Prefix, "rpc", ...Path, Head];
} & PathTree<PathDescendants<Entry, Head>, Prefix, ClientError, readonly [...Path, Head]>; };
declare const rpcQueryClientError: unique symbol;
/** An eager utility tree projected from the group's dotted RPC tags. */
type RpcQueryUtils<Group extends RpcGroup.Any, Prefix extends readonly [JsonValue, ...JsonValue[]], ClientError = never> = {
readonly [rpcQueryClientError]?: ClientError;
/** Returns the immutable root key, including the RPC discriminator. */
readonly key: () => readonly [...Prefix, "rpc"];
} & PathTree<RpcPathEntry<RpcsOf<Group>>, Prefix, ClientError>;
type NeedsKeyEncoder<R extends Rpc.Any> = [PayloadSchema<R>["EncodingServices"]] extends [never] ? PayloadSchema<R>["ast"] extends SchemaAST.Any | SchemaAST.Unknown ? false : true extends ContainsRedacted<Rpc.Payload<R>> ? true : false : true;
type RequiredEncoderRpcs<Group extends RpcGroup.Any> = PayloadBearingRpcs<Group> extends (infer R) ? R extends Rpc.Any ? NeedsKeyEncoder<R> extends true ? R : never : never : never;
type KeyEncoders<Group extends RpcGroup.Any> = { readonly [R in RequiredEncoderRpcs<Group> as R["_tag"]]: KeyEncoder<R>; } & Partial<{ readonly [R in Exclude<PayloadBearingRpcs<Group>, RequiredEncoderRpcs<Group>> as R["_tag"]]: KeyEncoder<R>; }>;
/** Makes the encoder map optional only when no RPC requires an override. */
type KeyEncoderOption<Group extends RpcGroup.Any> = KeyEncoderRequirement<PayloadBearingRpcs<Group>, RequiredEncoderRpcs<Group>, KeyEncoders<Group>>;
/** Requires a custom runner when client-side Schema services remain. */
type RunnerOption$1<Group extends RpcGroup.Any> = RunnerRequirement<Rpc.ServicesClient<RpcsOf<Group>>>;
/** Configuration for deriving a utility tree from an Effect RPC group. */
type CreateRpcQueryUtilsOptions<Group extends RpcGroup.Any, Prefix extends readonly [JsonValue, ...JsonValue[]], ClientError = never> = {
/** A ready, flat RPC client whose Scope remains owned by the caller. */
readonly client: RpcClient.RpcClient.Flat<RpcsOf<Group>, ClientError>;
/** A non-empty JSON-safe tuple that namespaces every generated key. */
readonly keyPrefix: Prefix;
} & KeyEncoderOption<Group> & RunnerOption$1<Group>;
//#endregion
//#region src/rpc/create-utils.d.ts
/**
* Derives an eager, frozen TanStack Query utility tree from an Effect RPC group.
*
* Dotted RPC tags become nested properties with unary or streaming utility leaves.
* The caller retains ownership of the ready client's Scope and lifecycle.
*
* @throws {@link EffectRpcQueryConfigError} if the prefix, paths, or encoders are invalid.
*/
export declare const createRpcQueryUtils: <const Group extends RpcGroup.Any, const Prefix extends readonly [JsonValue, ...JsonValue[]], ClientError = never>(group: Group, options: CreateRpcQueryUtilsOptions<Group, Prefix, ClientError>) => RpcQueryUtils<Group, Prefix, ClientError>;
//#endregion
//#region src/http/errors.d.ts
/** Safe identity shared by HTTP execution and key errors. */
interface HttpApiEndpointIdentity {
readonly apiId: string;
readonly groupId: string;
readonly endpoint: string;
readonly method: string;
}
type HttpApiOperation = "query" | "infinite" | "mutation" | "metadata" | "streamed" | "live";
/** Stable codes for invalid HTTP utility configuration. */
type EffectHttpApiQueryConfigErrorCode = "InvalidKeyPrefix" | "InvalidEndpointPath" | "EndpointPathCollision" | "MissingKeyEncoder" | "UnknownKeyEncoder" | "UnsupportedEndpointMetadata" | "UnsupportedQueryHash" | "InvalidMaxChunks" | "InvalidRefetchMode" | "InvalidMaxEventSize" | "InvalidSseOptions";
/** Stable codes for synchronous HTTP key failures. */
type EffectHttpApiQueryKeyErrorCode = "RequestEncodingFailed" | "KeyEncoderFailed" | "InvalidKeyValue";
/** Preserves the complete failed Exit Cause with declaration-only metadata. */
export declare class EffectHttpApiQueryError<E> extends Error implements HttpApiEndpointIdentity {
readonly _tag = "EffectHttpApiQueryError";
readonly apiId: string;
readonly groupId: string;
readonly endpoint: string;
readonly method: string;
readonly operation: HttpApiOperation;
readonly cause: Cause.Cause<E>;
constructor(identity: HttpApiEndpointIdentity, operation: HttpApiOperation, cause: Cause.Cause<E>);
}
export declare class EffectHttpApiQueryEmptyStreamError extends Error implements HttpApiEndpointIdentity {
readonly _tag = "EffectHttpApiQueryEmptyStreamError";
readonly apiId: string;
readonly groupId: string;
readonly endpoint: string;
readonly method: string;
readonly operation = "live";
constructor(identity: HttpApiEndpointIdentity);
}
/** Reports invalid factory, builder, or stream cache configuration. */
export declare class EffectHttpApiQueryConfigError extends Error {
readonly _tag = "EffectHttpApiQueryConfigError";
readonly code: EffectHttpApiQueryConfigErrorCode;
readonly apiId: string;
readonly groupId: string | undefined;
readonly endpoint: string | undefined;
readonly method: string | undefined;
readonly path: readonly string[] | undefined;
readonly cause?: unknown;
constructor(code: EffectHttpApiQueryConfigErrorCode, message: string, options: {
readonly apiId: string;
readonly groupId?: string;
readonly endpoint?: string;
readonly method?: string;
readonly path?: readonly string[];
readonly cause?: unknown;
});
}
/** Reports synchronous request encoding and key canonicalization failures. */
export declare class EffectHttpApiQueryKeyError extends Error implements HttpApiEndpointIdentity {
readonly _tag = "EffectHttpApiQueryKeyError";
readonly code: EffectHttpApiQueryKeyErrorCode;
readonly apiId: string;
readonly groupId: string;
readonly endpoint: string;
readonly method: string;
readonly cause?: unknown;
constructor(code: EffectHttpApiQueryKeyErrorCode, identity: HttpApiEndpointIdentity, message: string, cause?: unknown);
}
/** Recognizes HTTP execution errors from this JavaScript realm. */
export declare const isEffectHttpApiQueryError: (value: unknown) => value is EffectHttpApiQueryError<unknown>;
//#endregion
//#region src/http/types.d.ts
type Groups<Api extends HttpApi.Constraint> = Api extends HttpApi.HttpApi<infer _Id, infer Group> ? Group : never;
type ApiIdentifier<Api extends HttpApi.Constraint> = Api extends HttpApi.HttpApi<infer Id, infer _Group> ? Id : never;
type Endpoints<Group> = Extract<HttpApiGroup.Endpoints<Group>, HttpApiEndpoint.ConstraintRequest>;
type SuccessSchema<Endpoint extends HttpApiEndpoint.ConstraintRequest> = [Endpoint["~Success"]] extends [never] ? typeof HttpApiSchema.NoContent : Endpoint["~Success"];
type ResponseBody<S> = S extends HttpApiSchema.WithHeaders<infer Body, Schema.Top> ? Body : S;
type MultipartPayload = Brand.Brand<HttpApiSchema.MultipartTypeId> | Brand.Brand<HttpApiSchema.MultipartStreamTypeId>;
type SseEndpoint<Endpoint> = Endpoint extends HttpApiEndpoint.ConstraintRequest ? [ResponseBody<SuccessSchema<Endpoint>>] extends [{
readonly _tag: "StreamSse";
}] ? Endpoint : never : never;
type Supported<Endpoint> = Endpoint extends HttpApiEndpoint.ConstraintRequest ? [Extract<Endpoint["~Payload"]["Type"], Brand.Brand<HttpApiSchema.MultipartStreamTypeId>>] extends [never] ? [Extract<ResponseBody<SuccessSchema<Endpoint>>, HttpApiSchema.StreamSchema>] extends [never] ? Endpoint : [SseEndpoint<Endpoint>] extends [never] ? never : [Extract<Endpoint["~Payload"]["Type"], MultipartPayload>] extends [never] ? Endpoint : never : never : never;
type Queryable<Endpoint> = Endpoint extends HttpApiEndpoint.ConstraintRequest ? [Extract<Endpoint["~Payload"]["Type"], MultipartPayload>] extends [never] ? Endpoint : never : never;
type SupportedGroups<Api extends HttpApi.Constraint> = Groups<Api> extends (infer Group) ? Group extends HttpApiGroup.Constraint ? [Supported<Endpoints<Group>>] extends [never] ? never : Group : never : never;
type RequestFields<Endpoint extends HttpApiEndpoint.ConstraintRequest> = Omit<Exclude<HttpApiEndpoint.ClientRequest<Endpoint["~Params"], Endpoint["~Query"], Endpoint["~Payload"], Endpoint["~Headers"], "decoded-only">, void>, "responseMode" | "sseOptions">;
type Request<Endpoint extends HttpApiEndpoint.ConstraintRequest> = keyof RequestFields<Endpoint> extends never ? void : RequestFields<Endpoint> & {
readonly responseMode?: never;
readonly sseOptions?: never;
};
type Success<Endpoint extends HttpApiEndpoint.ConstraintRequest> = SuccessSchema<Endpoint>["Type"];
type Failure<ClientError> = EffectHttpApiQueryError<ClientError>;
type Member<Value, Key extends PropertyKey> = Key extends keyof Value ? Value[Key] : never;
type ClientGroup<Group, Client> = Group extends {
readonly topLevel: true;
} ? Client : Group extends HttpApiGroup.Constraint ? Member<Client, Group["identifier"]> : never;
type SeenMethod<Method, Seen extends readonly unknown[]> = Seen extends readonly [infer First, ...infer Rest] ? (<Value>() => Value extends Method ? 1 : 2) extends (<Value>() => (Value extends First ? 1 : 2)) ? true : SeenMethod<Method, Rest> : false;
type MethodSignatures<Method, Partial = unknown, Seen extends readonly unknown[] = []> = Method extends ((...args: infer Args) => infer Result) ? SeenMethod<(...args: Args) => Result, Seen> extends true ? never : ((...args: Args) => Result) | MethodSignatures<((...args: Args) => Result) & Partial & Method, Partial & ((...args: Args) => Result), [...Seen, (...args: Args) => Result]> : never;
type DecodedEffect<Method, Endpoint extends HttpApiEndpoint.ConstraintRequest, Mode extends "decoded-only" | "decoded-and-response" = "decoded-only"> = Method extends ((request: RequestFields<Endpoint> & {
readonly responseMode: Mode;
}) => infer Result) ? Result : never;
type ClientEffect<Group, Endpoint extends HttpApiEndpoint.ConstraintRequest, Client, Mode extends "decoded-only" | "decoded-and-response" = "decoded-only"> = DecodedEffect<MethodSignatures<Member<ClientGroup<Group, Client>, Endpoint["identifier"]>>, Endpoint, Mode>;
type ExposedEffects<Api extends HttpApi.Constraint, Client> = SupportedGroups<Api> extends (infer Group) ? Group extends HttpApiGroup.Constraint ? Supported<Endpoints<Group>> extends (infer Endpoint) ? Endpoint extends HttpApiEndpoint.ConstraintRequest ? ClientEffect<Group, Endpoint, Client> | ([Queryable<Endpoint>] extends [never] ? never : [SseEndpoint<Endpoint>] extends [never] ? ClientEffect<Group, Endpoint, Client, "decoded-and-response"> : never) : never : never : never : never;
type Root<Api extends HttpApi.Constraint, Prefix extends readonly JsonValue[]> = readonly [...Prefix, "http", ApiIdentifier<Api>];
type EndpointKey<Api extends HttpApi.Constraint, Prefix extends readonly JsonValue[], Group extends HttpApiGroup.Constraint, Endpoint extends HttpApiEndpoint.ConstraintRequest> = Group extends {
readonly topLevel: true;
} ? readonly [...Root<Api, Prefix>, Endpoint["identifier"]] : readonly [...Root<Api, Prefix>, Group["identifier"], Endpoint["identifier"]];
type ConcreteKey<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError> = DataTag<void extends Request<Endpoint> ? readonly [...Key, "query"] : readonly [...Key, "query", unknown], QueryData<Success<Endpoint>>, Failure<ClientError>>;
type QueryBuilder<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError> = UnaryQueryBuilder<Request<Endpoint>, QueryData<Success<Endpoint>>, Failure<ClientError>, ConcreteKey<Endpoint, Key, ClientError>, readonly [...Key, "query"]>;
type MetadataData<Endpoint extends HttpApiEndpoint.ConstraintRequest> = {
readonly data: QueryData<Success<Endpoint>>;
readonly status: number;
readonly headers: Readonly<Record<string, string>>;
};
type ConcreteMetadataKey<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError> = DataTag<void extends Request<Endpoint> ? readonly [...Key, "metadata"] : readonly [...Key, "metadata", unknown], MetadataData<Endpoint>, Failure<ClientError>>;
type MetadataBuilder<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError> = UnaryQueryBuilder<Request<Endpoint>, MetadataData<Endpoint>, Failure<ClientError>, ConcreteMetadataKey<Endpoint, Key, ClientError>, readonly [...Key, "metadata"]>;
type ConcreteInfiniteKey<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError, PageParam = unknown> = InfiniteQueryKey<Request<Endpoint>, QueryData<Success<Endpoint>>, Failure<ClientError>, readonly [...Key, "infinite"], PageParam>;
type InfiniteBuilder<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError> = InfiniteQueryBuilder<Request<Endpoint>, QueryData<Success<Endpoint>>, Failure<ClientError>, readonly [...Key, "infinite"]>;
type MutationLeaf<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError> = {
readonly key: () => Key;
readonly mutationKey: () => readonly [...Key, "mutation"];
readonly mutationOptions: MutationBuilder<Success<Endpoint>, Failure<ClientError>, Request<Endpoint>, readonly [...Key, "mutation"]>;
};
type BufferedLeaf<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError, MetadataClientError = ClientError> = MutationLeaf<Endpoint, Key, ClientError> & ([Queryable<Endpoint>] extends [never] ? unknown : {
readonly queryKey: KeyBuilder<Request<Endpoint>, ConcreteKey<Endpoint, Key, ClientError>, void extends Request<Endpoint> ? true : false>;
readonly queryOptions: QueryBuilder<Endpoint, Key, ClientError>;
readonly metadataKey: KeyBuilder<Request<Endpoint>, ConcreteMetadataKey<Endpoint, Key, MetadataClientError>, void extends Request<Endpoint> ? true : false>;
readonly metadataOptions: MetadataBuilder<Endpoint, Key, MetadataClientError>;
readonly infiniteKey: KeyBuilder<Request<Endpoint>, ConcreteInfiniteKey<Endpoint, Key, ClientError>, void extends Request<Endpoint> ? true : false>;
readonly infiniteOptions: InfiniteBuilder<Endpoint, Key, ClientError>;
});
type StreamChunk<Value> = Value extends HttpApiSchema.withHeaders<infer Body, infer Headers> ? Body extends Stream.Stream<infer Chunk, infer _Error, infer _Services> ? HttpApiSchema.withHeaders<Chunk, Headers> : never : Value extends Stream.Stream<infer Chunk, infer _Error, infer _Services> ? Chunk : never;
type StreamFailure<Value> = Value extends HttpApiSchema.withHeaders<infer Body, infer _Headers> ? StreamFailure<Body> : Value extends Stream.Stream<infer _Chunk, infer Error, infer _Services> ? Error : never;
type HttpStreamPolicy = StreamedPolicyOptions & {
readonly sseOptions?: Sse.DecodeOptions | undefined;
};
type HttpStreamQueryError<Endpoint extends HttpApiEndpoint.ConstraintRequest, ClientError> = EffectHttpApiQueryConfigError | Failure<ClientError | StreamFailure<Success<Endpoint>>>;
type StreamedKey<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError> = DataTag<void extends Request<Endpoint> ? readonly [...Key, "streamed", unknown] : readonly [...Key, "streamed", unknown, unknown], readonly StreamChunk<Success<Endpoint>>[], HttpStreamQueryError<Endpoint, ClientError>>;
type StreamedLeaf<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError> = {
readonly key: () => Key;
readonly streamedKey: void extends Request<Endpoint> ? (policy: HttpStreamPolicy) => StreamedKey<Endpoint, Key, ClientError> : (input: Request<Endpoint> | PreparedInput<Request<Endpoint>>, policy: HttpStreamPolicy) => StreamedKey<Endpoint, Key, ClientError>;
readonly streamedOptions: UnaryQueryBuilder<Request<Endpoint>, readonly StreamChunk<Success<Endpoint>>[], HttpStreamQueryError<Endpoint, ClientError>, StreamedKey<Endpoint, Key, ClientError>, readonly [...Key, "streamed"], HttpStreamPolicy>;
};
interface HttpLivePolicy {
readonly sseOptions?: Sse.DecodeOptions | undefined;
}
type LiveFailure<Endpoint extends HttpApiEndpoint.ConstraintRequest, ClientError> = HttpStreamQueryError<Endpoint, ClientError> | EffectHttpApiQueryEmptyStreamError;
type LiveKey<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError> = DataTag<void extends Request<Endpoint> ? readonly [...Key, "live", unknown] : readonly [...Key, "live", unknown, unknown], QueryData<StreamChunk<Success<Endpoint>>>, LiveFailure<Endpoint, ClientError>>;
type LiveLeaf<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError> = {
readonly liveKey: void extends Request<Endpoint> ? (policy?: HttpLivePolicy) => LiveKey<Endpoint, Key, ClientError> : (input: Request<Endpoint> | PreparedInput<Request<Endpoint>>, policy?: HttpLivePolicy) => LiveKey<Endpoint, Key, ClientError>;
readonly liveOptions: UnaryQueryBuilder<Request<Endpoint>, QueryData<StreamChunk<Success<Endpoint>>>, LiveFailure<Endpoint, ClientError>, LiveKey<Endpoint, Key, ClientError>, readonly [...Key, "live"], HttpLivePolicy>;
};
type Leaf<Endpoint extends HttpApiEndpoint.ConstraintRequest, Key extends readonly JsonValue[], ClientError, MetadataClientError = ClientError> = [SseEndpoint<Endpoint>] extends [never] ? BufferedLeaf<Endpoint, Key, ClientError, MetadataClientError> : StreamedLeaf<Endpoint, Key, ClientError> & LiveLeaf<Endpoint, Key, ClientError>;
declare const httpQueryClient: unique symbol;
/** An eager utility tree mirroring the ready HTTP client's literal properties. */
type HttpApiQueryUtils<Api extends HttpApi.Constraint, Prefix extends readonly [JsonValue, ...JsonValue[]], Client = HttpApiClient.ForApi<Api>> = {
readonly [httpQueryClient]?: Client;
readonly key: () => Root<Api, Prefix>;
} & { readonly [Group in Extract<SupportedGroups<Api>, {
readonly topLevel: false;
}> as Group["identifier"]]: {
readonly key: () => readonly [...Root<Api, Prefix>, Group["identifier"]];
} & { readonly [Endpoint in Supported<Endpoints<Group>> as Endpoint["identifier"]]: Leaf<Endpoint, EndpointKey<Api, Prefix, Group, Endpoint>, Effect.Error<ClientEffect<Group, Endpoint, Client>> | StreamFailure<Effect.Success<ClientEffect<Group, Endpoint, Client>>>, Effect.Error<ClientEffect<Group, Endpoint, Client, "decoded-and-response">>>; }; } & { readonly [Endpoint in Supported<Endpoints<Extract<SupportedGroups<Api>, {
readonly topLevel: true;
}>>> as Endpoint["identifier"]]: Leaf<Endpoint, readonly [...Root<Api, Prefix>, Endpoint["identifier"]], Effect.Error<ClientEffect<{
readonly topLevel: true;
}, Endpoint, Client>> | StreamFailure<Effect.Success<ClientEffect<{
readonly topLevel: true;
}, Endpoint, Client>>>, Effect.Error<ClientEffect<{
readonly topLevel: true;
}, Endpoint, Client, "decoded-and-response">>>; };
/** Projects a complete decoded HTTP request into safe, synchronous cache identity. */
type HttpApiKeyEncoder<Endpoint extends HttpApiEndpoint.ConstraintRequest> = (input: Request<Endpoint>) => JsonValue;
type InputEndpoints<Group> = Queryable<Supported<Endpoints<Group>>> extends (infer Endpoint) ? Endpoint extends HttpApiEndpoint.ConstraintRequest ? void extends Request<Endpoint> ? never : Endpoint : never : never;
type EncodingServices<Endpoint extends HttpApiEndpoint.ConstraintRequest> = Endpoint["~Params"]["EncodingServices"] | Endpoint["~Query"]["EncodingServices"] | Endpoint["~Payload"]["EncodingServices"] | Endpoint["~Headers"]["EncodingServices"];
type IsUnion<Value, Whole = Value> = Value extends Whole ? [Whole] extends [Value] ? false : true : never;
type PayloadSchemas<S> = S extends {
readonly schema: infer Inner extends Schema.Constraint;
} ? Inner : S;
type RequiredEncoders<Group> = InputEndpoints<Group> extends (infer Endpoint) ? Endpoint extends HttpApiEndpoint.ConstraintRequest ? [EncodingServices<Endpoint>] extends [never] ? true extends ContainsRedacted<Request<Endpoint>> | IsUnion<PayloadSchemas<Endpoint["~Payload"]>> ? Endpoint : never : Endpoint : never : never;
type GroupEncoders<Group> = { readonly [Endpoint in RequiredEncoders<Group> as Endpoint["identifier"]]: HttpApiKeyEncoder<Endpoint>; } & { readonly [Endpoint in Exclude<InputEndpoints<Group>, RequiredEncoders<Group>> as Endpoint["identifier"]]?: HttpApiKeyEncoder<Endpoint>; };
type EncoderGroups<Api extends HttpApi.Constraint> = SupportedGroups<Api> extends (infer Group) ? Group extends HttpApiGroup.Constraint ? [InputEndpoints<Group>] extends [never] ? never : Group : never : never;
type RequiredEncoderGroups<Api extends HttpApi.Constraint> = EncoderGroups<Api> extends (infer Group) ? Group extends HttpApiGroup.Constraint ? [RequiredEncoders<Group>] extends [never] ? never : Group : never : never;
type Encoders<Api extends HttpApi.Constraint> = { readonly [Group in RequiredEncoderGroups<Api> as Group["identifier"]]: GroupEncoders<Group>; } & { readonly [Group in Exclude<EncoderGroups<Api>, RequiredEncoderGroups<Api>> as Group["identifier"]]?: GroupEncoders<Group>; };
type EncoderOption<Api extends HttpApi.Constraint> = KeyEncoderRequirement<EncoderGroups<Api>, RequiredEncoderGroups<Api>, Encoders<Api>>;
type StreamServices<Value> = Value extends HttpApiSchema.withHeaders<infer Body, infer _Headers> ? StreamServices<Body> : Value extends Stream.Stream<infer _Chunk, infer _Error, infer Services> ? Services : never;
type ClientServices<Api extends HttpApi.Constraint, Client> = HttpApiEndpoint.ClientServices<Supported<Endpoints<Groups<Api>>>> | HttpApiEndpoint.ErrorServicesDecode<Supported<Endpoints<Groups<Api>>>> | Effect.Services<ExposedEffects<Api, Client>> | StreamServices<Effect.Success<ExposedEffects<Api, Client>>>;
type RunnerOption<Api extends HttpApi.Constraint, Client> = RunnerRequirement<ClientServices<Api, Client>>;
/** Derives HTTP utilities while the caller retains client and runtime ownership. */
type CreateHttpApiQueryUtilsOptions<Api extends HttpApi.Constraint, Prefix extends readonly [JsonValue, ...JsonValue[]], Client = HttpApiClient.ForApi<Api>> = {
readonly client: Client & HttpApiClient.ForApi<Api, unknown, unknown>;
readonly keyPrefix: Prefix;
} & EncoderOption<Api> & RunnerOption<Api, NoInfer<Client>>;
//#endregion
//#region src/http/create-utils.d.ts
export declare const createHttpApiQueryUtils: <const Api extends HttpApi.Constraint, const Prefix extends readonly [JsonValue, ...JsonValue[]], Client extends HttpApiClient.ForApi<Api, unknown, unknown>>(api: Api, options: CreateHttpApiQueryUtilsOptions<Api, Prefix, Client>) => HttpApiQueryUtils<Api, Prefix, Client>;
//#endregion
//#region src/core/stream-snapshot.d.ts
interface StreamSnapshotOptions {
readonly mode?: "fresh" | "cached";
readonly signal?: AbortSignal;
readonly timeoutMs?: number;
}
export declare const fetchStreamSnapshot: <TQueryFnData, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(queryClient: QueryClient, options: QueryExecuteOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> & {
readonly queryFn: QueryFunction<TQueryFnData, TQueryKey>;
readonly queryHash?: never;
readonly queryKeyHashFn?: never;
}, { mode, signal, timeoutMs }?: StreamSnapshotOptions) => Promise<TData>;
//#endregion
//#region src/core/view-prefix.d.ts
/** Selects every input and stream policy for one leaf's query view. */
export declare const viewPrefix: <const Key extends QueryKey, Leaf extends {
readonly key: () => Key;
}, View extends SupportedQueryView<Leaf>>(leaf: Leaf & {
readonly key: () => Key;
}, view: View) => readonly [...Key, View];
//#endregion
//#region src/core/query-filter.d.ts
/** Native query filters with identity supplied by the generated leaf and view. */
type QueryFilterOptions = Omit<QueryFilters, "queryKey"> & {
readonly queryKey?: never;
};
/** A typed application projection into a partial canonical key payload. */
type QueryFilterEncoder<Input> = (input: Input) => JsonValue;
/** Builds native filters for every input of one supported query view. */
export declare function createQueryFilter<Leaf extends {
readonly key: () => QueryKey;
}>(leaf: Leaf, view: SupportedQueryView<NoInfer<Leaf>>): (options?: QueryFilterOptions) => QueryFilters & {
readonly queryKey: QueryKey;
};
/** Builds partial-input filters without running full payload constructors or defaults. */
export declare function createQueryFilter<Leaf extends {
readonly key: () => QueryKey;
}, Input = InferInput<Leaf>>(leaf: Leaf, view: SupportedQueryView<NoInfer<Leaf>>, encode: QueryFilterEncoder<Input>): (input: Input, options?: QueryFilterOptions) => QueryFilters & {
readonly queryKey: QueryKey;
};
//#endregion
//#region src/core/policy.d.ts
type LocalQueryOption = OwnedQueryOption | "select" | "initialData" | "initialDataUpdatedAt" | "placeholderData" | "initialPageParam" | "getNextPageParam" | "getPreviousPageParam" | "maxPages";
type NativeQueryPolicy<Leaf, View extends SupportedQueryView<Leaf>> = QueryObserverOptions<QueryPageData<InferQueryData<Leaf, View>, View>, InferQueryError<Leaf, View>, InferQueryData<Leaf, View>, InferQueryData<Leaf, View>, Extract<QueryViewKey<Leaf, View>, QueryKey>, QueryPageParam<InferQueryData<Leaf, View>, View>>;
/** Reusable cache and observer policies; inputs, projections and identity remain local. */
type QueryPolicy<Leaf, View extends SupportedQueryView<Leaf> = Extract<"query", SupportedQueryView<Leaf>>> = Omit<NativeQueryPolicy<Leaf, View>, LocalQueryOption>;
/** Reusable mutation callbacks receive typed data and variables and an unknown local context. */
type MutationPolicy<Leaf> = Omit<MutationObserverOptions<InferMutationData<Leaf>, InferMutationError<Leaf>, InferInput<Leaf>>, OwnedMutationOption | "onMutate">;
interface MutationPolicyOptions {
/** Compose shared callbacks before local callbacks instead of replacing them. */
readonly callbacks?: "replace" | "compose";
}
//#endregion
//#region src/core/interceptor.d.ts
/** Wraps one native query-function attempt, including each retry. */
type QueryInterceptor<Leaf, View extends SupportedQueryView<Leaf>> = (execution: {
readonly context: QueryFunctionContext<Extract<QueryViewKey<Leaf, View>, QueryKey>, QueryPageParam<InferQueryData<Leaf, View>, View>>;
readonly next: () => Promise<QueryPageData<InferQueryData<Leaf, View>, View>>;
}) => Promise<QueryPageData<InferQueryData<Leaf, View>, View>>;
/** Wraps a native mutation-function attempt without replacing observer callbacks. */
type MutationInterceptor<Leaf> = (execution: {
readonly input: InferInput<Leaf>;
readonly context: MutationFunctionContext | undefined;
readonly next: () => Promise<InferMutationData<Leaf>>;
}) => Promise<InferMutationData<Leaf>>;
//#endregion
//#region src/core/hydration.d.ts
/** One generated leaf/view's cache-data codec, before observer selection. */
interface HydrationCodec<Data, Encoded, DecodingServices = never, EncodingServices = never> {
readonly prefix: QueryKey;
readonly schema: Schema.Codec<Data, Encoded, DecodingServices, EncodingServices>;
readonly matches: (key: QueryKey) => boolean;
}
/** Registers a codec whose decoded type matches the generated cached representation. */
export declare const queryViewCodec: <L extends {
readonly key: () => QueryKey;
}, V extends Exclude<SupportedQueryView<L>, "infinite">, S extends Schema.Codec<unknown, unknown, unknown, unknown>>(leaf: L, view: V, schema: S & ([S["Type"]] extends [InferQueryData<NoInfer<L>, NoInfer<V>>] ? [InferQueryData<NoInfer<L>, NoInfer<V>>] extends [S["Type"]] ? unknown : never : never)) => HydrationCodec<S["Type"], S["Encoded"], S["DecodingServices"], S["EncodingServices"]>;
/** Infinite data needs an explicit page-parameter codec in addition to its page codec. */
export declare const infiniteQueryCodec: <L extends {
readonly key: () => QueryKey;
}, Page extends Schema.Codec<unknown, unknown, unknown, unknown>, PageParam extends Schema.Codec<unknown, unknown, unknown, unknown>>(leaf: L & ("infinite" extends SupportedQueryView<L> ? unknown : never), codecs: {
readonly page: Page & ([Page["Type"]] extends [InferQueryData<NoInfer<L>, Extract<"query", SupportedQueryView<L>>>] ? [InferQueryData<NoInfer<L>, Extract<"query", SupportedQueryView<L>>>] extends [Page["Type"]] ? unknown : never : never);
readonly pageParam: PageParam;
}) => Readonly<{
prefix: readonly unknown[];
schema: Schema.Struct<{
readonly pages: Schema.$Array<Page & ([Page["Type"]] extends [InferQueryData<NoInfer<L>, Extract<"query", SupportedQueryView<L>>>] ? [InferQueryData<NoInfer<L>, Extract<"query", SupportedQueryView<L>>>] extends [Page["Type"]] ? unknown : never : never)>;
readonly pageParams: Schema.$Array<PageParam>;
}>;
matches: (key: QueryKey) => boolean;
}>;
/** Native synchronous callbacks for a single service-free leaf/view snapshot. */
export declare const hydrationCallbacks: <Data, Encoded>(codec: HydrationCodec<Data, Encoded>) => {
serializeData: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => Encoded;
deserializeData: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => Data;
};
export declare class HydrationCodecError extends Error {
readonly _tag = "HydrationCodecError";
readonly code: "DuplicateCodec" | "UnknownQuery" | "UnsettledQuery";
constructor(code: HydrationCodecError["code"]);
}
/** Prepares all query data before the application calls native hydrate or serializes a snapshot. */
interface HydrationRegistry<DecodingServices = never, EncodingServices = never> {
readonly matches: (key: QueryKey) => boolean;
readonly encodeQueries: (queries: DehydratedState["queries"]) => Effect.Effect<DehydratedState["queries"], Schema.SchemaError | HydrationCodecError, EncodingServices>;
readonly decodeQueries: (queries: DehydratedState["queries"]) => Effect.Effect<DehydratedState["queries"], Schema.SchemaError | HydrationCodecError, DecodingServices>;
}
/** Indexes explicit leaf/view codecs without owning a QueryClient, runner, or serialization. */
export declare const createHydrationRegistry: <const Entries extends readonly HydrationCodec<unknown, unknown, unknown, unknown>[]>(entries: Entries) => HydrationRegistry<Entries[number]["schema"]["DecodingServices"], Entries[number]["schema"]["EncodingServices"]>;
//#endregion
//#region src/core/stream-recovery.d.ts
/** Local delivery state; it does not acknowledge server-side persistence or cleanup. */
type StreamConnectionState<E> = {
readonly status: "connecting" | "connected";
readonly cursor: number;
readonly attempt: number;
} | {
readonly status: "backing-off";
readonly cursor: number;
readonly attempt: number;
readonly delay: Duration.Duration;
readonly cause: Cause.Cause<E>;
} | {
readonly status: "refreshing";
readonly cursor: number;
readonly attempt: number;
readonly cause: Cause.Cause<E>;
} | {
readonly status: "completed" | "stopped";
readonly cursor: number;
} | {
readonly status: "failed";
readonly cursor: number;
readonly cause: Cause.Cause<E>;
};
interface RecoverStreamOptions<A, E, R = never> {
/** Acquires an application-owned native stream using the last accepted cursor. */
readonly connect: (cursor: number) => Stream.Stream<A, E, R>;
/** One nonnegative safe-integer sequence per owner; older cursors are discarded. */
readonly cursor: (value: A) => number;
readonly initialCursor?: number | undefined;
/** One-based retry count across this consumption. Undefined stops with the original Cause. */
readonly retryDelay: (cause: Cause.Cause<E>, attempt: number) => Duration.Input | undefined;
readonly isReplayExpired?: ((cause: Cause.Cause<E>) => boolean) | undefined;
/** Refreshes authoritative reads and returns their replay cursor before reconnecting. */
readonly onReplayExpired?: ((cause: Cause.Cause<E>) => Effect.Effect<number, E, R>) | undefined;
/** Runs before accepting a gap; applications can refresh affected reads here. */
readonly onGap?: ((previous: number, next: number) => Effect.Effect<void, E, R>) | undefined;
readonly onState?: ((state: StreamConnectionState<E>) => Effect.Effect<void, never, R>) | undefined;
}
/** Restarts a decoded stream without putting attempt-specific resume state in a query key. */
export declare const recoverStream: <A, E, R = never>(options: RecoverStreamOptions<A, E, R>) => Stream.Stream<A, E, R>;
//#endregion
//#region src/core/configure-utils.d.ts
interface UtilityNode {
readonly key: () => QueryKey;
}
interface QueryConfiguration<Leaf, View extends SupportedQueryView<Leaf>> {
readonly policy?: QueryPolicy<Leaf, View> & (View extends "streamed" ? Partial<StreamedPolicyOptions> : unknown);
readonly interceptors?: readonly QueryInterceptor<Leaf, View>[];
}
type MutationConfiguration<Leaf> = MutationPolicyOptions & {
readonly policy?: MutationPolicy<Leaf>;
readonly interceptors?: readonly MutationInterceptor<Leaf>[];
};
type SharedQueryInterceptor<View extends QueryView> = <Data>(execution: {
readonly context: QueryFunctionContext<QueryKey, View extends "infinite" ? unknown : never>;
readonly next: () => Promise<Data>;
}) => Promise<Data>;
type SharedMutationInterceptor = <Data>(execution: {
readonly input: unknown;
readonly context: MutationFunctionContext | undefined;
readonly next: () => Promise<Data>;
}) => Promise<Data>;
interface SharedQueryConfiguration<View extends QueryView> {
readonly policy?: Omit<QueryObserverOptions<unknown, unknown>, LocalQueryOption> & (View extends "streamed" ? Partial<StreamedPolicyOptions> : unknown);
readonly interceptors?: readonly SharedQueryInterceptor<View>[];
}
type SharedMutationConfiguration = MutationPolicyOptions & {
readonly policy?: Omit<MutationObserverOptions<unknown, unknown, unknown>, OwnedMutationOption | "onMutate">;
readonly interceptors?: readonly SharedMutationInterceptor[];
};
type InheritedMethods = { readonly [Key in "toString" | "toLocaleString" | "valueOf" | "hasOwnProperty" | "isPrototypeOf" | "propertyIsEnumerable"]: (...args: never[]) => unknown; };
type ChildNames<Node> = Exclude<Extract<keyof Node, string>, "key">;
type Children<Node> = [ChildNames<Node>] extends [never] ? never : { readonly [Key in ChildNames<Node>]?: UtilsConfiguration<Node[Key]> | (Key extends keyof InheritedMethods ? InheritedMethods[Key] : never); };
type LeafMembers<Node> = Node extends MutationLeaf$1 ? Node : [SupportedQueryView<Node>] extends [never] ? never : Node;
/** Typed defaults and ordered interceptors for a generated tree, branch, or leaf. */
type UtilsConfiguration<Node> = [LeafMembers<Node>] extends [never] ? { readonly [View in QueryView]?: SharedQueryConfiguration<View>; } & {
readonly mutation?: SharedMutationConfiguration;
readonly scoped?: Children<Node>;
} : { readonly [View in QueryView]?: View extends SupportedQueryView<Node> ? QueryConfiguration<Node, Extract<View, SupportedQueryView<Node>>> : never; } & {
readonly mutation?: [Node] extends [MutationLeaf$1] ? MutationConfiguration<Node> : never;
readonly scoped?: never;
};
type ExtraProperties<Expected, Actual> = { readonly [Key in Exclude<KeysOfUnion<Actual>, keyof Expected>]: never; };
type Property<Value, Key extends PropertyKey> = Value extends unknown ? Key extends keyof Value ? Value[Key] : never : never;
type ExactView<Expected, Actual> = ExtraProperties<Expected, Actual> & ("policy" extends KeysOfUnion<Actual> ? {
readonly policy?: ExtraProperties<NonNullable<Property<Expected, "policy">>, NonNullable<Property<Actual, "policy">>>;
} : unknown);
type ExactChildConfiguration<Node, Key, Actual> = Key extends keyof InheritedMethods ? [Exclude<Actual, InheritedMethods[Key]>] extends [never] ? never : ExactConfiguration<Node, Exclude<Actual, InheritedMethods[Key]>> | Extract<Actual, InheritedMethods[Key]> : ExactConfiguration<Node, Actual>;
type ExactConfiguration<Node, Actual> = [Actual] extends [UtilsConfiguration<Node>] ? ExtraProperties<UtilsConfiguration<Node>, Actual> & { readonly [Key in KeysOfUnion<Actual> & keyof UtilsConfiguration<Node>]?: Key extends "scoped" ? NonNullable<Property<Actual, Key>> extends object ? ExtraProperties<Children<Node>, NonNullable<Property<Actual, Key>>> & { readonly [Child in KeysOfUnion<NonNullable<Property<Actual, Key>>> & keyof Node]?: ExactChildConfiguration<Node[Child], Child, NonNullable<Property<NonNullable<Property<Actual, Key>>, Child>>>; } : unknown : ExactView<NonNullable<UtilsConfiguration<Node>[Key]>, NonNullable<Property<Actual, Key>>>; } : never;
type StreamPolicy<Configuration> = Configuration extends {
readonly streamed: {
readonly policy: infer Policy;
};
} ? Policy : unknown;
type ScopedConfiguration<Configuration, Key extends PropertyKey> = Configuration extends {
readonly scoped: infer Scoped;
} ? Key extends keyof Scoped ? Scoped[Key] : unknown : unknown;
type RetentionDefault<Configuration, Inherited> = StreamPolicy<Configuration> extends {
readonly maxChunks: infer MaxChunks;
} ? {
readonly maxChunks: MaxChunks;
} : Inherited;
type WithDefaultRetention<Builder> = UnaryQueryBuilderDescriptor<Builder> extends (infer Descriptor) ? Descriptor extends {
readonly input: infer Input;
readonly data: infer Data;
readonly error: infer Error;
readonly key: infer Key extends QueryKey;
readonly skippedKey: infer SkippedKey extends QueryKey;
readonly adapterOptions: (options: infer AdapterOptions) => void;
readonly inputless: infer Inputless extends boolean;
} ? UnaryQueryBuilder<Input, Data, Error, Key, SkippedKey, Omit<AdapterOptions, "maxChunks"> & {
readonly maxChunks?: StreamedPolicyOptions["maxChunks"];
}, Inputless> : Builder : Builder;
type WithDefaultKeyRetention<KeyBuilder> = KeyBuilder extends ((...args: infer Args) => infer Key) ? Args extends readonly [infer Input, infer Policy] ? (input: Input, policy?: Partial<Policy>) => Key : Args extends readonly [infer Policy] ? (policy?: Partial<Policy>) => Key : KeyBuilder : KeyBuilder;
/** Preserves leaf builders and makes configured stream retention optional at call sites. */
type ConfiguredUtils<Node, Configuration, Inherited = unknown> = { readonly [Key in keyof Node]: Node[Key] extends UtilityNode ? Key extends string ? ConfiguredUtils<Node[Key], ScopedConfiguration<Configuration, Key>, RetentionDefault<Configuration, Inherited>> : Node[Key] : RetentionDefault<Configuration, Inherited> extends {
readonly maxChunks: StreamedPolicyOptions["maxChunks"];
} ? Key extends "streamedOptions" ? WithDefaultRetention<Node[Key]> : Key extends "streamedKey" ? WithDefaultKeyRetention<Node[Key]> : Node[Key] : Node[Key]; };
/** Applies root, branch, and leaf configuration while preserving generated cache identity. */
export declare const configureUtils: <Node extends UtilityNode, const Configuration extends object>(tree: Node, configuration: Configuration & NoInfer<UtilsConfiguration<Node>> & NoInfer<ExactConfiguration<Node, Configuration>>) => ConfiguredUtils<Node, Configuration>;
//#endregion
//#region src/core/branch-filter.d.ts
/** Selects one view across a generated root, branch or leaf without changing cache keys. */
export declare const createBranchQueryFilter: (branch: {
readonly key: () => QueryKey;
}, view: QueryView) => ((options?: QueryFilterOptions) => QueryFilters & {
readonly queryKey: QueryKey;
});
//#endregion
//#region src/core/declared-error.d.ts
type FailureOf<Error> = Error extends {
readonly cause: Cause.Cause<infer Failure>;
} ? Failure : never;
type TaggedFailure<Error> = Extract<FailureOf<Error>, {
readonly _tag: string;
}>;
/** Matches one typed failure only; defects, interruptions and composite Causes never match. */
export declare const findDeclaredError: <Error, Tag extends TaggedFailure<Error>["_tag"]>(error: Error, tag: Tag) => Option.Option<Extract<TaggedFailure<Error>, {
readonly _tag: Tag;
}>>;
//#endregion
//#region src/core/consume-events.d.ts
interface ConsumeEventsOptions<A, E, R, HandlerError = never, HandlerServices = never> {
readonly onEvent: (event: A) => Effect.Effect<void, HandlerError, HandlerServices>;
/** Runs before consuming; this is not a transport connection acknowledgement. */
readonly onStart?: Effect.Effect<void, HandlerError, HandlerServices>;
/** Runs after stream cleanup, including failure or interruption. */
readonly onExit?: (exit: Exit.Exit<void, E | HandlerError>) => Effect.Effect<void, never, R | HandlerServices>;
}
/** Consumes events sequentially without retaining history or owning a runtime or cache. */
export declare const consumeEvents: <A, E, R, HandlerError = never, HandlerServices = never>(source: Stream.Stream<A, E, R>, options: ConsumeEventsOptions<A, E, R, HandlerError, HandlerServices>) => Effect.Effect<void, E | HandlerError, R | HandlerServices>;
//#endregion
export { type ConfiguredUtils, type ConsumeEventsOptions, type CreateHttpApiQueryUtilsOptions, type CreateRpcQueryUtilsOptions, type EffectHttpApiQueryConfigErrorCode, type EffectHttpApiQueryKeyErrorCode, type EffectRpcQueryConfigErrorCode, type EffectRpcQueryKeyErrorCode, type HttpApiKeyEncoder, type HttpApiQueryUtils, type HydrationCodec, type HydrationRegistry, type InferInput, type InferMutationData, type InferMutationError, type InferQueryData, type InferQueryError, type JsonValue, type KeyEncoder, type MutationInterceptor, type MutationPolicy, type MutationPolicyOptions, type PreparedInput, type QueryData, type QueryFilterEncoder, type QueryFilterOptions, type QueryInterceptor, type QueryPolicy, type RecoverStreamOptions, type RpcQueryUtils, type RunPromiseExit, type SkipToken, type StreamConnectionState, type StreamSnapshotOptions, type StreamingRpcOptions, type UnaryRpcOptions, type UtilsConfiguration, skipToken };
//# sourceMappingURL=index.d.mts.map