/** * @since 1.0.0 */ import type * as Chunk from "@effect/data/Chunk"; import type * as Context from "@effect/data/Context"; import type * as Either from "@effect/data/Either"; import type * as Equal from "@effect/data/Equal"; import type * as Option from "@effect/data/Option"; import type * as Effect from "@effect/io/Effect"; import type * as CompletedRequestMap from "@effect/query/CompletedRequestMap"; import type * as Described from "@effect/query/Described"; import type * as Request from "@effect/query/Request"; /** * @since 1.0.0 * @category symbols */ export declare const DataSourceTypeId: unique symbol; /** * @since 1.0.0 * @category symbols */ export type DataSourceTypeId = typeof DataSourceTypeId; /** * A `DataSource` requires an environment `R` and is capable of executing * requests of type `A`. * * Data sources must implement the method `runAll` which takes a collection of * requests and returns an effect with a `CompletedRequestMap` containing a * mapping from requests to results. The type of the collection of requests is * a `Chunk>`. The outer `Chunk` represents batches of requests that * must be performed sequentially. The inner `Chunk` represents a batch of * requests that can be performed in parallel. This allows data sources to * introspect on all the requests being executed and optimize the query. * * Data sources will typically be parameterized on a subtype of `Request`, * though that is not strictly necessarily as long as the data source can map * the request type to a `Request`. Data sources can then pattern match on * the collection of requests to determine the information requested, execute * the query, and place the results into the `CompletedRequestMap` using * `CompletedRequestMap.empty` and `CompletedRequestMap.insert`. Data * sources must provide results for all requests received. Failure to do so * will cause a query to die with a `QueryFailure` when run. * * @since 1.0.0 * @category models */ export interface DataSource extends Equal.Equal { /** * The data source's identifier. */ readonly identifier: string; /** * Execute a collection of requests. The outer `Chunk` represents batches * of requests that must be performed sequentially. The inner `Chunk` * represents a batch of requests that can be performed in parallel. */ runAll(requests: Chunk.Chunk>): Effect.Effect; } /** * @since 1.0.0 */ export declare namespace DataSource { /** * @since 1.0.0 * @category models */ interface Variance { readonly [DataSourceTypeId]: { readonly _R: (_: never) => R; readonly _A: (_: never) => A; }; } } /** * Returns `true` if the specified value is a `DataSource`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isDataSource: (u: unknown) => u is DataSource; /** * Constructs a data source with the specified identifier and method to run * requests. * * @since 1.0.0 * @category constructors */ export declare const make: (identifier: string, runAll: (requests: Chunk.Chunk>) => Effect.Effect) => DataSource, A>; /** * Constructs a data source from a function taking a collection of requests * and returning a `CompletedRequestMap`. * * @since 1.0.0 * @category constructors */ export declare const makeBatched: >(identifier: string, run: (requests: Chunk.Chunk) => Effect.Effect) => DataSource, A>; /** * A data source aspect that executes requests between two effects, `before` * and `after`, where the result of `before` can be used by `after`. * * @since 1.0.0 * @category combinators */ export declare const around: { (before: Described.Described>, after: Described.Described<(a: A2) => Effect.Effect>): (self: DataSource) => DataSource; (self: DataSource, before: Described.Described>, after: Described.Described<(a: A2) => Effect.Effect>): DataSource; }; /** * Returns a data source that executes at most `n` requests in parallel. * * @since 1.0.0 * @category combinators */ export declare const batchN: { (n: number): (self: DataSource) => DataSource; (self: DataSource, n: number): DataSource; }; /** * Returns a new data source that executes requests of type `B` using the * specified function to transform `B` requests into requests that this data * source can execute. * * @since 1.0.0 * @category combinators */ export declare const contramap: { , B extends Request.Request>(f: Described.Described<(_: B) => A>): (self: DataSource) => DataSource; , B extends Request.Request>(self: DataSource, f: Described.Described<(_: B) => A>): DataSource; }; /** * Provides this data source with part of its required context. * * @since 1.0.0 * @category context */ export declare const contramapContext: { (f: Described.Described<(context: Context.Context) => Context.Context>): >(self: DataSource) => DataSource; , R0>(self: DataSource, f: Described.Described<(context: Context.Context) => Context.Context>): DataSource; }; /** * Returns a new data source that executes requests of type `B` using the * specified effectual function to transform `B` requests into requests that * this data source can execute. * * @since 1.0.0 * @category combinators */ export declare const contramapEffect: { , R2, B extends Request.Request>(f: Described.Described<(_: B) => Effect.Effect>): (self: DataSource) => DataSource; , R2, B extends Request.Request>(self: DataSource, f: Described.Described<(_: B) => Effect.Effect>): DataSource; }; /** * 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 1.0.0 * @category combinators */ export declare const eitherWith: { , R2, B extends Request.Request, C extends Request.Request>(that: DataSource, f: Described.Described<(_: C) => Either.Either>): (self: DataSource) => DataSource; , R2, B extends Request.Request, C extends Request.Request>(self: DataSource, that: DataSource, f: Described.Described<(_: C) => Either.Either>): DataSource; }; /** * Constructs a data source from a pure function. * * @since 1.0.0 * @category constructors */ export declare const fromFunction: >(name: string, f: (request: A) => Request.Request.Success) => DataSource; /** * 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 1.0.0 * @category constructors */ export declare const fromFunctionBatched: >(name: string, f: (chunk: Chunk.Chunk) => Chunk.Chunk>) => DataSource; /** * Constructs a data source from an effectual 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 1.0.0 * @category constructors */ export declare const fromFunctionBatchedEffect: >(name: string, f: (chunk: Chunk.Chunk) => Effect.Effect, Chunk.Chunk>>) => DataSource; /** * Constructs a data source from a pure function that takes a list of requests * and returns a list of optional 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 1.0.0 * @category constructors */ export declare const fromFunctionBatchedOption: >(name: string, f: (chunk: Chunk.Chunk) => Chunk.Chunk>>) => DataSource; /** * Constructs a data source from an effectual function that takes a list of * requests and returns a list of optional 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 1.0.0 * @category constructors */ export declare const fromFunctionBatchedOptionEffect: >(name: string, f: (chunk: Chunk.Chunk) => Effect.Effect, Chunk.Chunk>>>) => DataSource; /** * Constructs a data source from a function that takes a list of requests and * returns a list of results of the same size. Uses the specified function to * associate each result with the corresponding effect, allowing the function * to return the list of results in a different order than the list of * requests. * * @since 1.0.0 * @category constructors */ export declare const fromFunctionBatchedWith: >(name: string, f: (chunk: Chunk.Chunk) => Chunk.Chunk>, g: (value: Request.Request.Success) => Request.Request>) => DataSource; /** * Constructs a data source from an effectual function that takes a list of * requests and returns a list of results of the same size. Uses the specified * function to associate each result with the corresponding effect, allowing * the function to return the list of results in a different order than the * list of requests. * * @since 1.0.0 * @category constructors */ export declare const fromFunctionBatchedWithEffect: >(name: string, f: (chunk: Chunk.Chunk) => Effect.Effect, Chunk.Chunk>>, g: (b: Request.Request.Success) => Request.Request, Request.Request.Success>) => DataSource; /** * Constructs a data source from an effectual function. * * @since 1.0.0 * @category constructors */ export declare const fromFunctionEffect: >(name: string, f: (a: A) => Effect.Effect, Request.Request.Success>) => DataSource; /** * Constructs a data source from a pure function that may not provide results * for all requests received. * * @since 1.0.0 * @category constructors */ export declare const fromFunctionOption: >(name: string, f: (a: A) => Option.Option>) => DataSource; /** * Constructs a data source from an effectual function that may not provide * results for all requests received. * * @since 1.0.0 * @category constructors */ export declare const fromFunctionOptionEffect: >(name: string, f: (a: A) => Effect.Effect, Option.Option>>) => DataSource; /** * A data source that never executes requests. * * @since 1.0.0 * @category constructors */ export declare const never: (_: void) => DataSource; /** * Provides this data source with its required context. * * @since 1.0.0 * @category context */ export declare const provideContext: { (context: Described.Described>): >(self: DataSource) => DataSource; >(self: DataSource, context: Described.Described>): DataSource; }; /** * 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 1.0.0 * @category combinators */ export declare const race: { >(that: DataSource): >(self: DataSource) => DataSource; , R2, A2 extends Request.Request>(self: DataSource, that: DataSource): DataSource; }; //# sourceMappingURL=DataSource.d.ts.map