Skip to main content Link Search Menu Expand Document (external link)

LayerMap.ts overview

Since v3.14.0


Exports Grouped by Category


Constructors

fromRecord

Signature

declare const fromRecord: <
  Accessor extends Context.Tag<any, any> | Effect.Effect<any, any, any>,
  const Layers extends Record<string, Layer.Layer<Exclude<Effect.Effect.Context<Accessor>, Scope.Scope>, any, any>>
>(
  tagOrAccessor: Accessor,
  layers: Layers,
  options?: { readonly idleTimeToLive?: Duration.DurationInput | undefined } | undefined
) => Effect.Effect<
  LayerMap<
    keyof Layers,
    Exclude<Effect.Effect.Context<Accessor>, Scope.Scope>,
    Effect.Effect.Success<Accessor>,
    | Effect.Effect.Error<Accessor>
    | (Layers[keyof Layers] extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never)
  >,
  never,
  Scope.Scope | (Layers[keyof Layers] extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : never)
>

Source

Since v3.14.0

make

Signature

declare const make: <
  Accessor extends Context.Tag<any, any> | Effect.Effect<any, any, any>,
  K,
  L extends Layer.Layer<Exclude<Effect.Effect.Context<Accessor>, Scope.Scope>, any, any>
>(
  tagOrAccessor: Accessor,
  lookup: (key: K) => L,
  options?: { readonly idleTimeToLive?: Duration.DurationInput | undefined } | undefined
) => Effect.Effect<
  LayerMap<
    K,
    Exclude<Effect.Effect.Context<Accessor>, Scope.Scope>,
    Effect.Effect.Success<Accessor>,
    Effect.Effect.Error<Accessor> | (L extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never)
  >,
  never,
  Scope.Scope | (L extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : never)
>

Source

Since v3.14.0

Models

LayerMap (interface)

Signature

export interface LayerMap<in K, in out I, out S, out E = never> {
  readonly [TypeId]: TypeId

  /**
   * The internal RcMap that stores the resources.
   */
  readonly rcMap: RcMap.RcMap<K, readonly [Context.Context<I>, S], E>

  /**
   * Retrieves an instance of the resource associated with the key.
   */
  get(key: K): Effect.Effect<S, E, Scope.Scope>

  /**
   * Provides an instance of the resource associated with the key
   * to the given effect.
   */
  provide(key: K): <A, EX, R>(effect: Effect.Effect<A, EX, R>) => Effect.Effect<A, EX | E, Exclude<R, I>>

  /**
   * Invalidates the resource associated with the key.
   */
  invalidate(key: K): Effect.Effect<void>
}

Source

Since v3.14.0

Service

Service

Signature

declare const Service: <Self>() => <
  const Id extends string,
  Accessor extends Context.Tag<any, any> | Effect.Effect<any, any, any>,
  Lookup extends
    | { readonly lookup: (key: any) => Layer.Layer<Exclude<Effect.Effect.Context<Accessor>, Scope.Scope>, any, any> }
    | { readonly layers: Record<string, Layer.Layer<Exclude<Effect.Effect.Context<Accessor>, Scope.Scope>, any, any>> },
  const Deps extends ReadonlyArray<Layer.Layer<any, any, any>> = []
>(
  id: Id,
  options: Lookup & {
    readonly provides: Accessor
    readonly dependencies?: Deps | undefined
    readonly idleTimeToLive?: Duration.DurationInput | undefined
  }
) => TagClass<
  Self,
  Id,
  Lookup extends { readonly lookup: (key: infer K) => any }
    ? K
    : Lookup extends { readonly layers: infer Layers }
      ? keyof Layers
      : never,
  Exclude<Effect.Effect.Context<Accessor>, Scope.Scope>,
  Effect.Effect.Success<Accessor>,
  Effect.Effect.Error<Accessor> | Service.Error<Lookup>,
  Service.Context<Lookup>,
  Deps[number]
>

Source

Since v3.14.0

Service (namespace)

Source

Since v3.14.0

Key (type alias)

Signature

type Key<Options> = Options extends { readonly lookup: (key: infer K) => any }
  ? K
  : Options extends { readonly layers: infer Layers }
    ? keyof Layers
    : never

Source

Since v3.14.0

Layers (type alias)

Signature

type Layers<Options> = Options extends { readonly lookup: (key: infer _K) => infer Layers }
  ? Layers
  : Options extends { readonly layers: infer Layers }
    ? Layers[keyof Layers]
    : never

Source

Since v3.14.0

Error (type alias)

Signature

type Error<Options> = Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never

Source

Since v3.14.0

Context (type alias)

Signature

type Context<Options> = Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : never

Source

Since v3.14.0

TagClass (interface)

Signature

export interface TagClass<
  in out Self,
  in out Id extends string,
  in out K,
  in out I,
  in out S,
  in out E,
  in out R,
  in out Deps extends Layer.Layer<any, any, any>
> extends Context.TagClass<Self, Id, LayerMap<K, I, S, E>> {
  /**
   * A default layer for the `LayerMap` service.
   */
  readonly Default: Layer.Layer<
    Self,
    Deps extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never,
    | Exclude<R, Deps extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : never>
    | (Deps extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : never)
  >

  /**
   * A default layer for the `LayerMap` service without the dependencies provided.
   */
  readonly DefaultWithoutDependencies: Layer.Layer<Self, never, R>

  /**
   * Retrieves an instance of the resource associated with the key.
   */
  readonly get: (key: K) => Effect.Effect<S, E, Scope.Scope | Self>

  /**
   * Provides an instance of the resource associated with the key to the given
   * effect.
   */
  readonly provide: (
    key: K
  ) => <A, EX, R>(effect: Effect.Effect<A, EX, R>) => Effect.Effect<A, EX | E, Exclude<R, I> | Self>

  /**
   * Invalidates the resource associated with the key.
   */
  readonly invalidate: (key: K) => Effect.Effect<void, never, Self>
}

Source

Since v3.14.0

Symbols

TypeId

Signature

declare const TypeId: unique symbol

Source

Since v3.14.0

TypeId (type alias)

Signature

type TypeId = typeof TypeId

Source

Since v3.14.0