/** * A `Layer` describes how to build one or more services in your * application. Services can be injected into effects via * `Effect.provideService`. Effects can require services via `Effect.service`. * * Layer can be thought of as recipes for producing bundles of services, given * their dependencies (other services). * * Construction of services can be effectful and utilize resources that must be * acquired and safely released when the services are done being utilized. * * By default layers are shared, meaning that if the same layer is used twice * the layer will only be allocated a single time. * * Because of their excellent composition properties, layers are the idiomatic * way in Effect-TS to create services that depend on other services. * * @since 1.0.0 */ import * as Context from "@effect/data/Context"; import type { LazyArg } from "@effect/data/Function"; import type { Pipeable } from "@effect/data/Pipeable"; import type * as Cause from "@effect/io/Cause"; import type * as Effect from "@effect/io/Effect"; import type { FiberRef } from "@effect/io/FiberRef"; import type * as Runtime from "@effect/io/Runtime"; import type * as Schedule from "@effect/io/Schedule"; import type * as Scope from "@effect/io/Scope"; /** * @since 1.0.0 * @category symbols */ export declare const LayerTypeId: unique symbol; /** * @since 1.0.0 * @category symbols */ export type LayerTypeId = typeof LayerTypeId; /** * @since 1.0.0 * @category models */ export interface Layer extends Layer.Variance, Pipeable { } /** * @since 1.0.0 */ export declare namespace Layer { /** * @since 1.0.0 * @category models */ interface Variance { readonly [LayerTypeId]: { readonly _RIn: (_: never) => RIn; readonly _E: (_: never) => E; readonly _ROut: (_: ROut) => void; }; } /** * @since 1.0.0 * @category type-level */ type Context> = [T] extends [Layer] ? _R : never; /** * @since 1.0.0 * @category type-level */ type Error> = [T] extends [Layer] ? _E : never; /** * @since 1.0.0 * @category type-level */ type Success> = [T] extends [Layer] ? _A : never; } /** * Returns `true` if the specified value is a `Layer`, `false` otherwise. * * @since 1.0.0 * @category getters */ export declare const isLayer: (u: unknown) => u is Layer; /** * Returns `true` if the specified `Layer` is a fresh version that will not be * shared, `false` otherwise. * * @since 1.0.0 * @category getters */ export declare const isFresh: (self: Layer) => boolean; /** * Builds a layer into a scoped value. * * @since 1.0.0 * @category destructors */ export declare const build: (self: Layer) => Effect.Effect>; /** * Builds a layer into an `Effect` value. Any resources associated with this * layer will be released when the specified scope is closed unless their scope * has been extended. This allows building layers where the lifetime of some of * the services output by the layer exceed the lifetime of the effect the * layer is provided to. * * @since 1.0.0 * @category destructors */ export declare const buildWithScope: { (scope: Scope.Scope): (self: Layer) => Effect.Effect>; (self: Layer, scope: Scope.Scope): Effect.Effect>; }; /** * Recovers from all errors. * * @since 1.0.0 * @category error handling */ export declare const catchAll: { (onError: (error: E) => Layer): (self: Layer) => Layer; (self: Layer, onError: (error: E) => Layer): Layer; }; /** * Recovers from all errors. * * @since 1.0.0 * @category error handling */ export declare const catchAllCause: { (onError: (cause: Cause.Cause) => Layer): (self: Layer) => Layer; (self: Layer, onError: (cause: Cause.Cause) => Layer): Layer; }; /** * Constructs a `Layer` that passes along the specified context as an * output. * * @since 1.0.0 * @category constructors */ export declare const context: () => Layer; /** * Constructs a layer that dies with the specified defect. * * @since 1.0.0 * @category constructors */ export declare const die: (defect: unknown) => Layer; /** * Constructs a layer that dies with the specified defect. * * @since 1.0.0 * @category constructors */ export declare const dieSync: (evaluate: LazyArg) => Layer; /** * Replaces the layer's output with `void` and includes the layer only for its * side-effects. * * @since 1.0.0 * @category mapping */ export declare const discard: (self: Layer) => Layer; /** * Constructs a layer from the specified effect. * * @since 1.0.0 * @category constructors */ export declare const effect: { >(tag: T): (effect: Effect.Effect>) => Layer>; , R, E>(tag: T, effect: Effect.Effect>): Layer>; }; /** * Constructs a layer from the specified effect discarding it's output. * * @since 1.0.0 * @category constructors */ export declare const effectDiscard: (effect: Effect.Effect) => Layer; /** * Constructs a layer from the specified effect, which must return one or more * services. * * @since 1.0.0 * @category constructors */ export declare const effectContext: (effect: Effect.Effect>) => Layer; /** * Extends the scope of this layer, returning a new layer that when provided * to an effect will not immediately release its associated resources when * that effect completes execution but instead when the scope the resulting * effect depends on is closed. * * @since 1.0.0 * @category utils */ export declare const extendScope: (self: Layer) => Layer; /** * Constructs a layer that fails with the specified error. * * @since 1.0.0 * @category constructors */ export declare const fail: (error: E) => Layer; /** * Constructs a layer that fails with the specified error. * * @since 1.0.0 * @category constructors */ export declare const failSync: (evaluate: LazyArg) => Layer; /** * Constructs a layer that fails with the specified cause. * * @since 1.0.0 * @category constructors */ export declare const failCause: (cause: Cause.Cause) => Layer; /** * Constructs a layer that fails with the specified cause. * * @since 1.0.0 * @category constructors */ export declare const failCauseSync: (evaluate: LazyArg>) => Layer; /** * Constructs a layer dynamically based on the output of this layer. * * @since 1.0.0 * @category sequencing */ export declare const flatMap: { (f: (context: Context.Context) => Layer): (self: Layer) => Layer; (self: Layer, f: (context: Context.Context) => Layer): Layer; }; /** * Flattens layers nested in the context of an effect. * * @since 1.0.0 * @category sequencing */ export declare const flatten: { (tag: Context.Tag>): (self: Layer) => Layer; (self: Layer, tag: Context.Tag>): Layer; }; /** * Creates a fresh version of this layer that will not be shared. * * @since 1.0.0 * @category utils */ export declare const fresh: (self: Layer) => Layer; declare const fromFunction: , B extends Context.Tag>(tagA: A, tagB: B, f: (a: Context.Tag.Service) => Context.Tag.Service) => Layer, never, Context.Tag.Identifier>; export { /** * Constructs a layer from the context using the specified function. * * @since 1.0.0 * @category constructors */ fromFunction as function }; /** * Builds this layer and uses it until it is interrupted. This is useful when * your entire application is a layer, such as an HTTP server. * * @since 1.0.0 * @category conversions */ export declare const launch: (self: Layer) => Effect.Effect; /** * Returns a new layer whose output is mapped by the specified function. * * @since 1.0.0 * @category mapping */ export declare const map: { (f: (context: Context.Context) => Context.Context): (self: Layer) => Layer; (self: Layer, f: (context: Context.Context) => Context.Context): Layer; }; /** * Returns a layer with its error channel mapped using the specified function. * * @since 1.0.0 * @category mapping */ export declare const mapError: { (f: (error: E) => E2): (self: Layer) => Layer; (self: Layer, f: (error: E) => E2): Layer; }; /** * Feeds the error or output services of this layer into the input of either * the specified `failure` or `success` layers, resulting in a new layer with * the inputs of this layer, and the error or outputs of the specified layer. * * @since 1.0.0 * @category folding */ export declare const match: { (options: { readonly onFailure: (error: E) => Layer; readonly onSuccess: (context: Context.Context) => Layer; }): (self: Layer) => Layer; (self: Layer, options: { readonly onFailure: (error: E) => Layer; readonly onSuccess: (context: Context.Context) => Layer; }): Layer; }; /** * Feeds the error or output services of this layer into the input of either * the specified `failure` or `success` layers, resulting in a new layer with * the inputs of this layer, and the error or outputs of the specified layer. * * @since 1.0.0 * @category folding */ export declare const matchCause: { (options: { readonly onFailure: (cause: Cause.Cause) => Layer; readonly onSuccess: (context: Context.Context) => Layer; }): (self: Layer) => Layer; (self: Layer, options: { readonly onFailure: (cause: Cause.Cause) => Layer; readonly onSuccess: (context: Context.Context) => Layer; }): Layer; }; /** * Returns a scoped effect that, if evaluated, will return the lazily computed * result of this layer. * * @since 1.0.0 * @category utils */ export declare const memoize: (self: Layer) => Effect.Effect>; /** * Combines this layer with the specified layer, producing a new layer that * has the inputs and outputs of both. * * @since 1.0.0 * @category utils */ export declare const merge: { (that: Layer): (self: Layer) => Layer; (self: Layer, that: Layer): Layer; }; /** * Merges all the layers together in parallel. * * @since 1.0.0 * @category zipping */ export declare const mergeAll: , ...Array>]>(...layers: Layers) => Layer<{ [k in keyof Layers]: Layer.Context; }[number], { [k in keyof Layers]: Layer.Error; }[number], { [k in keyof Layers]: Layer.Success; }[number]>; /** * Translates effect failure into death of the fiber, making all failures * unchecked and not a part of the type of the layer. * * @since 1.0.0 * @category error handling */ export declare const orDie: (self: Layer) => Layer; /** * Executes this layer and returns its output, if it succeeds, but otherwise * executes the specified layer. * * @since 1.0.0 * @category error handling */ export declare const orElse: { (that: LazyArg>): (self: Layer) => Layer; (self: Layer, that: LazyArg>): Layer; }; /** * Returns a new layer that produces the outputs of this layer but also * passes through the inputs. * * @since 1.0.0 * @category utils */ export declare const passthrough: (self: Layer) => Layer; /** * Projects out part of one of the services output by this layer using the * specified function. * * @since 1.0.0 * @category utils */ export declare const project: { , B extends Context.Tag>(tagA: A, tagB: B, f: (a: Context.Tag.Service) => Context.Tag.Service): (self: Layer>) => Layer>; , B extends Context.Tag>(self: Layer>, tagA: A, tagB: B, f: (a: Context.Tag.Service) => Context.Tag.Service): Layer>; }; /** * Feeds the output services of this builder into the input of the specified * builder, resulting in a new builder with the inputs of this builder as * well as any leftover inputs, and the outputs of the specified builder. * * @since 1.0.0 * @category utils */ export declare const provide: { (that: Layer): (self: Layer) => Layer, E2 | E, ROut2>; (self: Layer, that: Layer): Layer, E | E2, ROut2>; }; /** * @since 1.0.0 * @category utils */ export declare const locallyEffect: { (f: (_: Effect.Effect>) => Effect.Effect>): (self: Layer) => Layer; (self: Layer, f: (_: Effect.Effect>) => Effect.Effect>): Layer; }; /** * @since 1.0.0 * @category utils */ export declare const locally: { (ref: FiberRef, value: X): (self: Layer) => Layer; (self: Layer, ref: FiberRef, value: X): Layer; }; /** * @since 1.0.0 * @category utils */ export declare const locallyWith: { (ref: FiberRef, value: (_: X) => X): (self: Layer) => Layer; (self: Layer, ref: FiberRef, value: (_: X) => X): Layer; }; /** * @since 1.0.0 * @category utils */ export declare const locallyScoped: (self: FiberRef, value: A) => Layer; /** * @since 1.0.0 * @category utils */ export declare const fiberRefLocallyScopedWith: (self: FiberRef, value: (_: A) => A) => Layer; /** * Feeds the output services of this layer into the input of the specified * layer, resulting in a new layer with the inputs of this layer, and the * outputs of both layers. * * @since 1.0.0 * @category utils */ export declare const provideMerge: { (that: Layer): (self: Layer) => Layer, E2 | E, ROut2 | ROut>; (self: Layer, that: Layer): Layer, E | E2, ROut | ROut2>; }; /** * Retries constructing this layer according to the specified schedule. * * @since 1.0.0 * @category retrying */ export declare const retry: { (schedule: Schedule.Schedule): (self: Layer) => Layer; (self: Layer, schedule: Schedule.Schedule): Layer; }; /** * A layer that constructs a scope and closes it when the workflow the layer * is provided to completes execution, whether by success, failure, or * interruption. This can be used to close a scope when providing a layer to a * workflow. * * @since 1.0.0 * @category constructors */ export declare const scope: Layer; /** * Constructs a layer from the specified scoped effect. * * @since 1.0.0 * @category constructors */ export declare const scoped: { >(tag: T): (effect: Effect.Effect>) => Layer, E, Context.Tag.Identifier>; , R, E>(tag: T, effect: Effect.Effect>): Layer, E, Context.Tag.Identifier>; }; /** * Constructs a layer from the specified scoped effect. * * @since 1.0.0 * @category constructors */ export declare const scopedDiscard: (effect: Effect.Effect) => Layer, E, never>; /** * Constructs a layer from the specified scoped effect, which must return one * or more services. * * @since 1.0.0 * @category constructors */ export declare const scopedContext: (effect: Effect.Effect>) => Layer, E, A>; /** * Constructs a layer that accesses and returns the specified service from the * context. * * @since 1.0.0 * @category constructors */ export declare const service: >(tag: T) => Layer, never, Context.Tag.Identifier>; /** * Constructs a layer from the specified value. * * @since 1.0.0 * @category constructors */ export declare const succeed: { >(tag: T): (resource: Context.Tag.Service) => Layer>; >(tag: T, resource: Context.Tag.Service): Layer>; }; /** * Constructs a layer from the specified value, which must return one or more * services. * * @since 1.0.0 * @category constructors */ export declare const succeedContext: (context: Context.Context) => Layer; /** * Lazily constructs a layer. This is useful to avoid infinite recursion when * creating layers that refer to themselves. * * @since 1.0.0 * @category constructors */ export declare const suspend: (evaluate: LazyArg>) => Layer; /** * Lazily constructs a layer from the specified value. * * @since 1.0.0 * @category constructors */ export declare const sync: { >(tag: T): (evaluate: LazyArg>) => Layer>; >(tag: T, evaluate: LazyArg>): Layer>; }; /** * Lazily constructs a layer from the specified value, which must return one or more * services. * * @since 1.0.0 * @category constructors */ export declare const syncContext: (evaluate: LazyArg>) => Layer; /** * Performs the specified effect if this layer succeeds. * * @since 1.0.0 * @category sequencing */ export declare const tap: { (f: (context: Context.Context) => Effect.Effect): (self: Layer) => Layer; (self: Layer, f: (context: Context.Context) => Effect.Effect): Layer; }; /** * Performs the specified effect if this layer fails. * * @since 1.0.0 * @category sequencing */ export declare const tapError: { (f: (e: XE) => Effect.Effect): (self: Layer) => Layer; (self: Layer, f: (e: XE) => Effect.Effect): Layer; }; /** * Performs the specified effect if this layer fails. * * @since 1.0.0 * @category sequencing */ export declare const tapErrorCause: { (f: (cause: Cause.Cause) => Effect.Effect): (self: Layer) => Layer; (self: Layer, f: (cause: Cause.Cause) => Effect.Effect): Layer; }; /** * Converts a layer that requires no services into a scoped runtime, which can * be used to execute effects. * * @since 1.0.0 * @category conversions */ export declare const toRuntime: (self: Layer) => Effect.Effect>; /** * Feeds the output services of this builder into the input of the specified * builder, resulting in a new builder with the inputs of this builder as * well as any leftover inputs, and the outputs of the specified builder. * * @since 1.0.0 * @category utils */ export declare const use: { (self: Layer): (that: Layer) => Layer, E | E2, ROut2>; (that: Layer, self: Layer): Layer, E2 | E, ROut2>; }; /** * Feeds the output services of this layer into the input of the specified * layer, resulting in a new layer with the inputs of this layer, and the * outputs of both layers. * * @since 1.0.0 * @category utils */ export declare const useMerge: { (self: Layer): (that: Layer) => Layer, E | E2, ROut | ROut2>; (that: Layer, self: Layer): Layer, E2 | E, ROut2 | ROut>; }; /** * Combines this layer the specified layer, producing a new layer that has the * inputs of both, and the outputs of both combined using the specified * function. * * @since 1.0.0 * @category zipping */ export declare const zipWithPar: { (that: Layer, f: (a: Context.Context, b: Context.Context) => Context.Context): (self: Layer) => Layer; (self: Layer, that: Layer, f: (a: Context.Context, b: Context.Context) => Context.Context): Layer; }; /** * @since 1.0.0 * @category utils */ export declare const unwrapEffect: (self: Effect.Effect>) => Layer; /** * @since 1.0.0 * @category utils */ export declare const unwrapScoped: (self: Effect.Effect>) => Layer, E | E1, A>; //# sourceMappingURL=Layer.d.ts.map