/** * @since 2.0.0 */ import type { NonEmptyArray } from "./Array.js"; import * as Context from "./Context.js"; import * as Effect from "./Effect.js"; import type * as Either from "./Either.js"; import type * as Equal from "./Equal.js"; import type { FiberRef } from "./FiberRef.js"; import type { Pipeable } from "./Pipeable.js"; import type * as Request from "./Request.js"; import type * as Types from "./Types.js"; /** * @since 2.0.0 * @category symbols */ export declare const RequestResolverTypeId: unique symbol; /** * @since 2.0.0 * @category symbols */ export type RequestResolverTypeId = typeof RequestResolverTypeId; /** * The `RequestResolver` interface requires an environment `R` and handles * the execution of requests of type `A`. * * Implementations must provide a `runAll` method, which processes a collection * of requests and produces an effect that fulfills these requests. Requests are * organized into a `Array>`, where the outer `Array` groups requests * into batches that are executed sequentially, and each inner `Array` contains * requests that can be executed in parallel. This structure allows * implementations to analyze all incoming requests collectively and optimize * query execution accordingly. * * Implementations are typically specialized for a subtype of `Request`. * However, they are not strictly limited to these subtypes as long as they can * map any given request type to `Request`. Implementations should inspect * the collection of requests to identify the needed information and execute the * corresponding queries. It is imperative that implementations resolve all the * requests they receive. Failing to do so will lead to a `QueryFailure` error * during query execution. * * @since 2.0.0 * @category models */ export interface RequestResolver extends RequestResolver.Variance, Equal.Equal, Pipeable { /** * Execute a collection of requests. The outer `Array` represents batches * of requests that must be performed sequentially. The inner `Array` * represents a batch of requests that can be performed in parallel. */ runAll(requests: Array>>): Effect.Effect; /** * Identify the data source using the specific identifier */ identified(...identifiers: Array): RequestResolver; } /** * @since 2.0.0 */ export declare namespace RequestResolver { /** * @since 2.0.0 * @category models */ interface Variance { readonly [RequestResolverTypeId]: { readonly _A: Types.Contravariant; readonly _R: Types.Covariant; }; } } /** * @since 2.0.0 * @category utils */ export declare const contextFromEffect: >(self: RequestResolver) => Effect.Effect, never, R>; /** * @since 2.0.0 * @category utils */ export declare const contextFromServices: >>(...services: Services) => >(self: RequestResolver) => Effect.Effect; }[number]>>, never, { [k in keyof Services]: Effect.Effect.Context; }[number]>; /** * Returns `true` if the specified value is a `RequestResolver`, `false` otherwise. * * @since 2.0.0 * @category refinements */ export declare const isRequestResolver: (u: unknown) => u is RequestResolver; /** * Constructs a data source with the specified identifier and method to run * requests. * * @since 2.0.0 * @category constructors */ export declare const make: (runAll: (requests: Array>) => Effect.Effect) => RequestResolver; /** * Constructs a data source with the specified identifier and method to run * requests. * * @since 2.0.0 * @category constructors */ export declare const makeWithEntry: (runAll: (requests: Array>>) => Effect.Effect) => RequestResolver; /** * Constructs a data source from a function taking a collection of requests. * * @since 2.0.0 * @category constructors */ export declare const makeBatched: , R>(run: (requests: NonEmptyArray) => Effect.Effect) => RequestResolver; /** * A data source aspect that executes requests between two effects, `before` * and `after`, where the result of `before` can be used by `after`. * * @since 2.0.0 * @category combinators */ export declare const around: { /** * A data source aspect that executes requests between two effects, `before` * and `after`, where the result of `before` can be used by `after`. * * @since 2.0.0 * @category combinators */ (before: Effect.Effect, after: (a: A2) => Effect.Effect): (self: RequestResolver) => RequestResolver; /** * A data source aspect that executes requests between two effects, `before` * and `after`, where the result of `before` can be used by `after`. * * @since 2.0.0 * @category combinators */ (self: RequestResolver, before: Effect.Effect, after: (a: A2) => Effect.Effect): RequestResolver; }; /** * A data source aspect that executes requests between two effects, `before` * and `after`, where the result of `before` can be used by `after`. * * The `before` and `after` effects are provided with the requests being executed. * * @since 2.0.0 * @category combinators * @example * ```ts * import { Effect, Request, RequestResolver } from "effect" * * interface GetUserById extends Request.Request { * readonly id: number * } * * const resolver = RequestResolver.fromFunction( * (request: GetUserById) => ({ id: request.id, name: "John" }) * ) * * RequestResolver.aroundRequests( * resolver, * (requests) => Effect.log(`got ${requests.length} requests`), * (requests, _) => Effect.log(`finised running ${requests.length} requests`) * ) * ``` */ export declare const aroundRequests: { /** * A data source aspect that executes requests between two effects, `before` * and `after`, where the result of `before` can be used by `after`. * * The `before` and `after` effects are provided with the requests being executed. * * @since 2.0.0 * @category combinators * @example * ```ts * import { Effect, Request, RequestResolver } from "effect" * * interface GetUserById extends Request.Request { * readonly id: number * } * * const resolver = RequestResolver.fromFunction( * (request: GetUserById) => ({ id: request.id, name: "John" }) * ) * * RequestResolver.aroundRequests( * resolver, * (requests) => Effect.log(`got ${requests.length} requests`), * (requests, _) => Effect.log(`finised running ${requests.length} requests`) * ) * ``` */ (before: (requests: ReadonlyArray>) => Effect.Effect, after: (requests: ReadonlyArray>, _: A2) => Effect.Effect): (self: RequestResolver) => RequestResolver; /** * A data source aspect that executes requests between two effects, `before` * and `after`, where the result of `before` can be used by `after`. * * The `before` and `after` effects are provided with the requests being executed. * * @since 2.0.0 * @category combinators * @example * ```ts * import { Effect, Request, RequestResolver } from "effect" * * interface GetUserById extends Request.Request { * readonly id: number * } * * const resolver = RequestResolver.fromFunction( * (request: GetUserById) => ({ id: request.id, name: "John" }) * ) * * RequestResolver.aroundRequests( * resolver, * (requests) => Effect.log(`got ${requests.length} requests`), * (requests, _) => Effect.log(`finised running ${requests.length} requests`) * ) * ``` */ (self: RequestResolver, before: (requests: ReadonlyArray>) => Effect.Effect, after: (requests: ReadonlyArray>, _: A2) => Effect.Effect): RequestResolver; }; /** * Returns a data source that executes at most `n` requests in parallel. * * @since 2.0.0 * @category combinators */ export declare const batchN: { /** * Returns a data source that executes at most `n` requests in parallel. * * @since 2.0.0 * @category combinators */ (n: number): (self: RequestResolver) => RequestResolver; /** * Returns a data source that executes at most `n` requests in parallel. * * @since 2.0.0 * @category combinators */ (self: RequestResolver, n: number): RequestResolver; }; /** * Provides this data source with part of its required context. * * @since 2.0.0 * @category context */ export declare const mapInputContext: { /** * Provides this data source with part of its required context. * * @since 2.0.0 * @category context */ (f: (context: Context.Context) => Context.Context): >(self: RequestResolver) => RequestResolver; /** * Provides this data source with part of its required context. * * @since 2.0.0 * @category context */ , R0>(self: RequestResolver, f: (context: Context.Context) => Context.Context): RequestResolver; }; /** * Returns a new data source that executes requests of type `C` using the * specified function to transform `C` requests into requests that either this * data source or that data source can execute. * * @since 2.0.0 * @category combinators */ export declare const eitherWith: { /** * Returns a new data source that executes requests of type `C` using the * specified function to transform `C` requests into requests that either this * data source or that data source can execute. * * @since 2.0.0 * @category combinators */ , R2, B extends Request.Request, C extends Request.Request>(that: RequestResolver, f: (_: Request.Entry) => Either.Either, Request.Entry>): (self: RequestResolver) => RequestResolver; /** * Returns a new data source that executes requests of type `C` using the * specified function to transform `C` requests into requests that either this * data source or that data source can execute. * * @since 2.0.0 * @category combinators */ , R2, B extends Request.Request, C extends Request.Request>(self: RequestResolver, that: RequestResolver, f: (_: Request.Entry) => Either.Either, Request.Entry>): RequestResolver; }; /** * Constructs a data source from a pure function. * * @since 2.0.0 * @category constructors */ export declare const fromFunction: >(f: (request: A) => Request.Request.Success) => RequestResolver; /** * Constructs a data source from a pure function that takes a list of requests * and returns a list of results of the same size. Each item in the result * list must correspond to the item at the same index in the request list. * * @since 2.0.0 * @category constructors */ export declare const fromFunctionBatched: >(f: (chunk: NonEmptyArray) => Iterable>) => RequestResolver; /** * Constructs a data source from an effectual function. * * @since 2.0.0 * @category constructors */ export declare const fromEffect: >(f: (a: A) => Effect.Effect, Request.Request.Error, R>) => RequestResolver; /** * Constructs a data source from a list of tags paired to functions, that takes * a list of requests and returns a list of results of the same size. Each item * in the result list must correspond to the item at the same index in the * request list. * * @since 2.0.0 * @category constructors */ export declare const fromEffectTagged: & { readonly _tag: string; }>() => ] extends [infer Req] ? Req extends Request.Request ? (requests: Array) => Effect.Effect, ReqE, any> : never : never; }>(fns: Fns) => RequestResolver extends Effect.Effect ? R : never>; /** * A data source that never executes requests. * * @since 2.0.0 * @category constructors */ export declare const never: RequestResolver; /** * Provides this data source with its required context. * * @since 2.0.0 * @category context */ export declare const provideContext: { /** * Provides this data source with its required context. * * @since 2.0.0 * @category context */ (context: Context.Context): >(self: RequestResolver) => RequestResolver; /** * Provides this data source with its required context. * * @since 2.0.0 * @category context */ >(self: RequestResolver, context: Context.Context): RequestResolver; }; /** * Returns a new data source that executes requests by sending them to this * data source and that data source, returning the results from the first data * source to complete and safely interrupting the loser. * * @since 2.0.0 * @category combinators */ export declare const race: { /** * Returns a new data source that executes requests by sending them to this * data source and that data source, returning the results from the first data * source to complete and safely interrupting the loser. * * @since 2.0.0 * @category combinators */ , R2>(that: RequestResolver): , R>(self: RequestResolver) => RequestResolver; /** * Returns a new data source that executes requests by sending them to this * data source and that data source, returning the results from the first data * source to complete and safely interrupting the loser. * * @since 2.0.0 * @category combinators */ , R, A2 extends Request.Request, R2>(self: RequestResolver, that: RequestResolver): RequestResolver; }; /** * Returns a new data source with a localized FiberRef * * @since 2.0.0 * @category combinators */ export declare const locally: { /** * Returns a new data source with a localized FiberRef * * @since 2.0.0 * @category combinators */ (self: FiberRef, value: A): >(use: RequestResolver) => RequestResolver; /** * Returns a new data source with a localized FiberRef * * @since 2.0.0 * @category combinators */ , A>(use: RequestResolver, self: FiberRef, value: A): RequestResolver; }; //# sourceMappingURL=RequestResolver.d.ts.map