import "@effect-ts/system/Operator"; import * as Chunk from "@effect-ts/core/Collections/Immutable/Chunk"; import * as Tp from "@effect-ts/core/Collections/Immutable/Tuple"; import * as T from "@effect-ts/core/Effect"; import { _A, _E, _R } from "@effect-ts/core/Effect"; import * as E from "@effect-ts/core/Either"; import type { Has, Tag } from "@effect-ts/core/Has"; import * as O from "@effect-ts/core/Option"; import type { URI } from "@effect-ts/core/Prelude"; import * as P from "@effect-ts/core/Prelude"; import * as DSL from "@effect-ts/core/Prelude/DSL"; import type { _A as _GetA, _E as _GetE } from "@effect-ts/core/Utils"; import * as C from "@effect-ts/system/Cause"; import * as CL from "@effect-ts/system/Clock"; import { NoSuchElementException } from "@effect-ts/system/GlobalExceptions"; import * as CH from "../Cache/index.js"; import type { DataSource } from "../DataSource/index.js"; import type { DataSourceAspect } from "../DataSourceAspect/index.js"; import type { QueryContext } from "../Internal/QueryContext/index.js"; import * as RES from "../Internal/Result/index.js"; import type { Request } from "../Request/index.js"; /** * A `ZQuery[R, E, A]` is a purely functional description of an effectual query * that may contain requests from one or more data sources, requires an * environment `R`, and may fail with an `E` or succeed with an `A`. * * Requests that can be performed in parallel, as expressed by `zipWithPar` and * combinators derived from it, will automatically be batched. Requests that * must be performed sequentially, as expressed by `zipWith` and combinators * derived from it, will automatically be pipelined. This allows for aggressive * data source specific optimizations. Requests can also be deduplicated and * cached. * * This allows for writing queries in a high level, compositional style, with * confidence that they will automatically be optimized. For example, consider * the following query from a user service. * * {{{ * val getAllUserIds: ZQuery[Any, Nothing, List[Int]] = ??? * def getUserNameById(id: Int): ZQuery[Any, Nothing, String] = ??? * * for { * userIds <- getAllUserIds * userNames <- ZQuery.forEachPar(userIds)(getUserNameById) * } yield userNames * }}} * * This would normally require N + 1 queries, one for `getAllUserIds` and one * for each call to `getUserNameById`. In contrast, `ZQuery` will automatically * optimize this to two queries, one for `userIds` and one for `userNames`, * assuming an implementation of the user service that supports batching. * * Based on "There is no Fork: an Abstraction for Efficient, Concurrent, and * Concise Data Access" by Simon Marlow, Louis Brandy, Jonathan Coens, and Jon * Purdy. [[http://simonmar.github.io/bib/papers/haxl-icfp14.pdf]] */ export declare class Query { readonly step: T.Effect>; readonly _tag = "Query"; readonly [_R]: (r: R) => void; readonly [_E]: () => E; readonly [_A]: () => A; constructor(step: T.Effect>); } /** * Returns a query that models execution of this query, followed by passing * its result to the specified function that returns a query. Requests * composed with `flatMap` or combinators derived from it will be executed * sequentially and will not be pipelined, though deduplication and caching of * requests may still be applied. */ export declare function chain_(self: Query, f: (a: A) => Query): Query; /** * Returns a query that models execution of this query, followed by passing * its result to the specified function that returns a query. Requests * composed with `flatMap` or combinators derived from it will be executed * sequentially and will not be pipelined, though deduplication and caching of * requests may still be applied. * @ets_data_first chain_ */ export declare function chain(f: (a: A) => Query): (self: Query) => Query; /** * Returns a query whose failure and success have been lifted into an * `Either`. The resulting query cannot fail, because the failure case has * been exposed as part of the `Either` success case. */ export declare function either(self: Query): Query>; /** * Folds over the failed or successful result of this query to yield a query * that does not fail, but succeeds with the value returned by the left or * right function passed to `fold`. */ export declare function fold_(self: Query, failure: (e: E) => B, success: (a: A) => B): Query; /** * Folds over the failed or successful result of this query to yield a query * that does not fail, but succeeds with the value returned by the left or * right function passed to `fold`. * @ets_data_first fold_ */ export declare function fold(failure: (e: E) => B, success: (a: A) => B): (self: Query) => Query; /** * A more powerful version of `foldM` that allows recovering from any type * of failure except interruptions. */ export declare function foldCauseM_(self: Query, failure: (cause: C.Cause) => Query, success: (a: A) => Query): Query; /** * A more powerful version of `foldM` that allows recovering from any type * of failure except interruptions. * @ets_data_first foldCauseM_ */ export declare function foldCauseM(failure: (cause: C.Cause) => Query, success: (a: A) => Query): (self: Query) => Query; /** * Recovers from errors by accepting one query to execute for the case of an * error, and one query to execute for the case of success. */ export declare function foldM_(self: Query, failure: (failure: E) => Query, success: (a: A) => Query): Query; /** * Recovers from errors by accepting one query to execute for the case of an * error, and one query to execute for the case of success. * @ets_data_first foldM_ */ export declare function foldM(failure: (failure: E) => Query, success: (a: A) => Query): (self: Query) => Query; /** * Maps the specified function over the successful result of this query. */ export declare function map_(self: Query, f: (a: A) => B): Query; /** * Maps the specified function over the successful result of this query. * @ets_data_first map_ */ export declare function map(f: (a: A) => B): (self: Query) => Query; /** * Transforms all data sources with the specified data source aspect. */ export declare function mapDataSources_(self: Query, f: DataSourceAspect): Query; /** * Transforms all data sources with the specified data source aspect. * @ets_data_first mapDataSources_ */ export declare function mapDataSources(f: DataSourceAspect): (self: Query) => Query; /** * Maps the specified function over the failed result of this query. */ export declare function mapError_(self: Query, f: (a: E) => E1): Query; /** * Maps the specified function over the failed result of this query. * @ets_data_first mapError_ */ export declare function mapError(f: (a: E) => E1): (self: Query) => Query; /** * Returns a query whose failure and success channels have been mapped by the * specified pair of functions, `f` and `g`. */ export declare function bimap_(self: Query, f: (e: E) => E1, g: (a: A) => B): Query; /** * Returns a query whose failure and success channels have been mapped by the * specified pair of functions, `f` and `g`. * @ets_data_first bimap_ */ export declare function bimap(f: (e: E) => E1, g: (a: A) => B): (self: Query) => Query; /** * Provides this query with part of its required environment. */ export declare function provideSome_(self: Query, description: string, f: (r: R0) => R): Query; /** * Provides this query with part of its required environment. * @ets_data_first provideSome_ */ export declare function provideSome(description: string, f: (r: R0) => R): (self: Query) => Query; /** * Returns a query that models the execution of this query and the specified * query sequentially, combining their results into a tuple. */ export declare function zip_(self: Query, that: Query): Query>; /** * Returns a query that models the execution of this query and the specified * query sequentially, combining their results into a tuple. * @ets_data_first zip_ */ export declare function zip(that: Query): (self: Query) => Query>; /** * Returns a query that models the execution of this query and the specified * query sequentially, combining their results with the specified function. * Requests composed with `zipWith` or combinators derived from it will * automatically be pipelined. */ export declare function zipWith_(self: Query, that: Query, f: (a: A, b: B) => C): Query; /** * Returns a query that models the execution of this query and the specified * query sequentially, combining their results with the specified function. * Requests composed with `zipWith` or combinators derived from it will * automatically be pipelined. * * @ets_data_first zipWith_ */ export declare function zipWith(that: Query, f: (a: A, b: B) => C): (self: Query) => Query; /** * Returns a query that models the execution of this query and the specified * query in parallel, combining their results with the specified function. * Requests composed with `zipWithPar` or combinators derived from it will * automatically be batched. */ export declare function zipWithPar_(self: Query, that: Query, f: (a: A, b: B) => C): Query; /** * Returns a query that models the execution of this query and the specified * query in parallel, combining their results with the specified function. * Requests composed with `zipWithPar` or combinators derived from it will * automatically be batched. * * @ets_data_first zipWithPar_ */ export declare function zipWithPar(that: Query, f: (a: A, b: B) => C): (self: Query) => Query; /** * Summarizes a query by computing some value before and after execution, * and then combining the values to produce a summary, together with the * result of execution. */ export declare function summarized_(self: Query, summary: T.Effect, f: (a: B, b: B) => C): Query; /** * Summarizes a query by computing some value before and after execution, * and then combining the values to produce a summary, together with the * result of execution. * * @ets_data_first summarized_ */ export declare function summarized(summary: T.Effect, f: (a: B, b: B) => B): (self: Query) => Query; /** * Returns an effect that will timeout this query, returning `None` if the * timeout elapses before the query was completed. * @dataFirst timeout_ */ export declare function timeout(duration: number): (self: Query) => Query & R, E, O.Option>; /** * Returns an effect that will timeout this query, returning `None` if the * timeout elapses before the query was completed. */ export declare function timeout_(self: Query, duration: number): Query & R, E, O.Option>; /** * The same as [[timeout]], but instead of producing a `None` in the event * of timeout, it will produce the specified error. */ export declare function timeoutFail_(self: Query, error: E1, duration: number): Query & R, E | E1, A>; /** * The same as [[timeout]], but instead of producing a `None` in the event * of timeout, it will produce the specified failure. * @dataFirst timeoutFail_ */ export declare function timeoutFail(error: E1, duration: number): (self: Query) => Query & R, E1 | E, A>; /** * The same as [[timeout]], but instead of producing a `None` in the event * of timeout, it will produce the specified failure. */ export declare function timeoutHalt_(self: Query, error: C.Cause, duration: number): Query & R, E | E1, A>; /** * The same as [[timeout]], but instead of producing a `None` in the event * of timeout, it will produce the specified error. * @dataFirst timeoutHalt_ */ export declare function timeoutHalt(error: C.Cause, duration: number): (self: Query) => Query & R, E1 | E, A>; export declare function timeoutTo_(self: Query, b: B, f: (a: A) => B, duration: number): Query & R, E, B>; /** * Constructs a query that fails with the specified cause. */ export declare function halt(cause: C.Cause): Query; /** * Constructs a query that never completes. */ export declare const never: Query; /** * Constructs a query that succeds with the empty value. */ export declare const none: Query>; /** * Constructs a query that succeeds with the specified value. */ export declare function succeed(value: A): Query; /** * Constructs a query that succeeds with the specified value. */ export declare function fail(value: E): Query; /** * Constructs a query from an effect. */ export declare function fromEffect(effect: T.Effect): Query; /** * Returns a query which submerges the error case of `Either` into the error channel of the query * * The inverse of [[ZQuery.either]] */ export declare function absolve(query: Query>): Query; /** * Performs a query for each element in a collection, collecting the results * into a query returning a collection of their results. Requests will be * executed sequentially and will be pipelined. */ export declare function forEach_(as: Iterable, f: (a: A) => Query): Query>; /** * Performs a query for each element in a collection, collecting the results * into a query returning a collection of their results. Requests will be * executed sequentially and will be pipelined. * * @ets_data_first forEach_ */ export declare function forEach(f: (a: A) => Query): (as: Iterable) => Query>; /** * Constructs a query from an either */ export declare function fromEither(either: E.Either): Query; /** * Constructs a query from an option */ export declare function fromOption(option: O.Option): Query, A>; /** * Collects a collection of queries into a query returning a collection of * their results. Requests will be executed sequentially and will be * pipelined. */ export declare function collectAll(as: Iterable>): Query>; /** * Constructs a query from a request and a data source. Queries will die with * a `QueryFailure` when run if the data source does not provide results for * all requests received. Queries must be constructed with `fromRequest` or * one of its variants for optimizations to be applied. */ export declare function fromRequest>(request: A, dataSource: DataSource): Query, _GetA>; /** * Returns an effect that models executing this query with the specified * cache. */ export declare function runCache(cache: CH.Cache): (self: Query) => T.Effect; /** * Returns an effect that models executing this query. */ export declare function run(query: Query): T.Effect; /** * Returns an effect that models executing this query, returning the query * result along with the cache. */ export declare function runLog(query: Query): T.Effect; /** * Performs a query for each element in a collection, collecting the results * into a query returning a collection of their results. Requests will be * executed parallely and will be pipelined. */ export declare function forEachPar_(as: Iterable, f: (a: A) => Query): Query>; /** * Performs a query for each element in a collection, collecting the results * into a query returning a collection of their results. Requests will be * executed parallely and will be pipelined. * * @ets_data_first forEachPar_ */ export declare function forEachPar(f: (a: A) => Query): (as: Iterable) => Query>; /** * Collects a collection of queries into a query returning a collection of * their results. Requests will be executed in parallel and will be batched. */ export declare function collectAllPar(as: Iterable>): Query>; /** * Returns a new query that executes this one and times the execution. */ export declare function timed(self: Query): Query, E, readonly [number, A]>; /** * Converts this query to one that returns `Some` if data sources return * results for all requests received and `None` otherwise. */ export declare function optional(self: Query): Query>; /** * Lifts the error channel into a `Some` value for composition with other optional queries * * @see [[ZQuery.some]] */ export declare function asSomeError(self: Query): Query, A>; /** * Recovers from all errors. */ export declare function catchAll_(self: Query, h: (e: E) => Query): Query; /** * Recovers from all errors. * @ets_data_first catchAll_ */ export declare function catchAll(h: (e: E) => Query): (self: Query) => Query; /** * Recovers from all errors with provided Cause. * * @see [[ZQuery.sandbox]] - other functions that can recover from defects */ export declare function catchAllCause_(self: Query, h: (cause: C.Cause) => Query): Query; /** * Recovers from all errors with provided Cause. * * @see [[ZQuery.sandbox]] - other functions that can recover from defects * @ets_data_first catchAllCause_ */ export declare function catchAllCause(h: (cause: C.Cause) => Query): (self: Query) => Query; /** * Returns a query that performs the outer query first, followed by the inner * query, yielding the value of the inner query. * * This method can be used to "flatten" nested queries. */ export declare function flatten(self: Query>): Query; /** * Returns a successful query if the value is `Left`, or fails with the error `None`. */ export declare function left(self: Query>): Query, B>; /** * Returns a successful query if the value is `Left`, or fails with the error e. */ export declare function leftOrFail_(self: Query>, e: E1): Query; /** * Returns a successful query if the value is `Left`, or fails with the error e. * @ets_data_first leftOrFail_ */ export declare function leftOrFail(e: E1): (self: Query>) => Query; /** * Returns a successful query if the value is `Left`, or fails with the given error function 'e'. */ export declare function leftOrFailWith_(self: Query>, e: (c: C) => E1): Query; /** * Returns a successful query if the value is `Left`, or fails with the given error function 'e'. * @ets_data_first leftOrFailWith_ */ export declare function leftOrFailWith(e: (c: C) => E1): (self: Query>) => Query; /** * Returns a query with its full cause of failure mapped using the * specified function. This can be used to transform errors while * preserving the original structure of `Cause`. * * @see [[sandbox]], [[catchAllCause]] - other functions for dealing with defects */ export declare function mapErrorCause_(self: Query, h: (cause: C.Cause) => C.Cause): Query; /** * Returns a query with its full cause of failure mapped using the * specified function. This can be used to transform errors while * preserving the original structure of `Cause`. * * @see [[sandbox]], [[catchAllCause]] - other functions for dealing with defects * @ets_data_first mapErrorCause_ */ export declare function mapErrorCause(h: (cause: C.Cause) => C.Cause): (self: Query) => Query; /** * Converts this query to one that dies if a query failure occurs. */ export declare function orDie(self: Query): Query; /** * Converts this query to one that dies if a query failure occurs, using the * specified function to map the error to a `Throwable`. */ export declare function orDieWith_(self: Query, f: (e: E) => unknown): Query; /** * Converts this query to one that dies if a query failure occurs, using the * specified function to map the error to a `Throwable`. * @ets_data_first orDieWith_ */ export declare function orDieWith(f: (e: E) => unknown): (self: Query) => Query; /** * Constructs a query that dies with the specified error. */ export declare function die(cause: unknown): Query; /** * Provides this query with its required environment. */ export declare function provide_(self: Query, description: string, env: R): Query; /** * Provides this query with its required environment. * @ets_data_first provide_ */ export declare function provide(description: string, env: R): (self: Query) => Query; /** * Effectfully accesses the environment of the query. */ export declare function access(fn: (env: R0) => A): Query; /** * Effectfully accesses the environment of the query. */ export declare function accessM(fn: (env: R0) => Query): Query; /** * Access a service with the required Service Entry */ export declare function accessService(s: Tag): (f: (a: T) => B) => Query, never, B>; /** * Access a service with the required Service Entry */ export declare function accessServiceM(s: Tag): (f: (a: T) => Query) => Query, E, B>; /** * Extracts the optional value or fails with NoSuchElementException. */ export declare function getOrFail(value: O.Option): Query; export declare const QueryURI = "@effect-ts/query/Query"; export declare type QueryURI = typeof QueryURI; declare module "@effect-ts/core/Prelude/HKT" { interface URItoKind { [QueryURI]: Query; } } export declare type V = P.V<"R", "-"> & P.V<"E", "+">; export declare const Any: P.Any<[URI<"@effect-ts/query/Query", {}>], V>; export declare const AssociativeFlatten: P.AssociativeFlatten<[URI<"@effect-ts/query/Query", {}>], V>; export declare const AssociativeBoth: P.AssociativeBoth<[URI<"@effect-ts/query/Query", {}>], V>; export declare const Covariant: P.Covariant<[URI<"@effect-ts/query/Query", {}>], V>; export declare const IdentityFlatten: P.IdentityFlatten<[URI<"@effect-ts/query/Query", {}>], V>; export declare const IdentityBoth: P.IdentityBoth<[URI<"@effect-ts/query/Query", {}>], V>; export declare const Monad: P.Monad<[URI<"@effect-ts/query/Query", {}>], V>; export declare const Applicative: P.Applicative<[URI<"@effect-ts/query/Query", {}>], V>; export declare const Fail: P.FX.Fail<[URI<"@effect-ts/query/Query", {}>], V>; export declare const Run: P.FX.Run<[URI<"@effect-ts/query/Query", {}>], V>; export declare const gen: , any>, AEff>(f: (i: { (_: O.Option, onNone: () => E): P.GenHKT, A>; (_: O.Option): P.GenHKT, A_1>; (_: Tag): P.GenHKT, never, A_2>, A_2>; (_: E.Either): P.GenHKT, A_3>; (_: T.Effect): P.GenHKT, A_4>; (_: Query): P.GenHKT, A_5>; }) => Generator) => Query], unknown, "R", Eff["effect"]>, P.Infer<[URI<"@effect-ts/query/Query", {}>], unknown, "E", Eff["effect"]>, AEff>; export declare const bind: (tag: Exclude, f: (a: BK) => Query) => (fa: Query) => Query; declare const let_: (tag: Exclude, f: (a: BK) => BA) => (fa: Query) => Query; declare const do_: Query; export { do_ as do, let_ as let }; export { branch as if, branch_ as if_ }; export declare const struct: >, K = any, Q = any, W = any, X = any, I = any, S = any, R = unknown, E = never>(r: import("@effect-ts/system/Utils").EnforceNonEmptyRecord & Record>) => Query], V, "R", NER[keyof NER]>, P.Infer<[URI<"@effect-ts/query/Query", {}>], V, "E", NER[keyof NER]>, { [K_1 in keyof NER]: P.Infer<[URI<"@effect-ts/query/Query", {}>], V, "A", NER[K_1]>; }>; /** * Matchers */ export declare const match: (tag: N) => P.MatchFn<[URI<"@effect-ts/query/Query", {}>], V, N>, matchIn: (tag: N_1) => P.MatchInFn<[URI<"@effect-ts/query/Query", {}>], V, N_1>, matchMorph: (MorphADT: { tag: N_2; _A: X; }) => P.MatchMorphFn<[URI<"@effect-ts/query/Query", {}>], V, N_2, X>, matchTag: P.MatchFn<[URI<"@effect-ts/query/Query", {}>], V, "_tag">, matchTagIn: P.MatchInFn<[URI<"@effect-ts/query/Query", {}>], V, "_tag">; /** * Conditionals */ declare const branch: , Y extends Query>(onTrue: () => X, onFalse: () => Y) => (predicate: boolean) => Query], V, "R", X | Y>, P.Infer<[URI<"@effect-ts/query/Query", {}>], V, "E", X | Y>, P.Infer<[URI<"@effect-ts/query/Query", {}>], V, "A", X | Y>>; declare const branch_: , Y extends Query>(predicate: boolean, onTrue: () => X, onFalse: () => Y) => Query], V, "R", X | Y>, P.Infer<[URI<"@effect-ts/query/Query", {}>], V, "E", X | Y>, P.Infer<[URI<"@effect-ts/query/Query", {}>], V, "A", X | Y>>; //# sourceMappingURL=index.d.ts.map