import type * as Either from "@effect/data/Either" import * as Option from "@effect/data/Option" import * as Effect from "@effect/io/Effect" import * as Ref from "@effect/io/Ref" import type * as DataSource from "@effect/query/DataSource" import * as queryFailure from "@effect/query/internal_effect_untraced/queryFailure" import type * as Query from "@effect/query/Query" import type * as Request from "@effect/query/Request" /** @internal */ export const ContinueTypeId: unique symbol = Symbol.for("@effect/query/Continue") /** @internal */ export type ContinueTypeId = typeof ContinueTypeId /** * A `Continue` models a continuation of a blocked request that * requires an environment `R` and may either fail with an `E` or succeed with * an `A`. A continuation may either be a `Get` that merely gets the result of a * blocked request (potentially transforming it with pure functions) or an * `Effect` that may perform arbitrary effects. This is used by the library * internally to determine whether it is safe to pipeline two requests that must * be executed sequentially. * * @internal */ export type Continue = Get | Eff /** @internal */ export interface Get { readonly _tag: "Get" readonly effect: Effect.Effect } /** @internal */ export interface Eff { readonly _tag: "Eff" readonly query: Query.Query } /** * Constructs a continuation that may perform arbitrary effects. * * @internal */ export const eff = (query: Query.Query): Continue => ({ _tag: "Eff", query }) /** * Constructs a continuation that merely gets the result of a blocked request * (potentially transforming it with pure functions). * * @internal */ export const get = (effect: Effect.Effect): Continue => ({ _tag: "Get", effect }) /** * Constructs a continuation from a request, a data source, and a `Ref` that * will contain the result of the request when it is executed. * * @internal */ export const make = , R>( request: A, dataSource: DataSource.DataSource, ref: Ref.Ref, Request.Request.Success>>> ): Continue, Request.Request.Success> => get(Effect.flatMap( Ref.get(ref), Option.match( () => Effect.die(queryFailure.make(dataSource, request)), Effect.fromEither ) ))