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: <const Layers extends Record<string, Layer.Layer<any, any, any>>>(
  layers: Layers,
  options?: { readonly idleTimeToLive?: Duration.DurationInput | undefined } | undefined
) => Effect.Effect<
  LayerMap<
    keyof Layers,
    Layers[keyof Layers] extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : never,
    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: <K, L extends Layer.Layer<any, any, any>>(
  lookup: (key: K) => L,
  options?: { readonly idleTimeToLive?: Duration.DurationInput | undefined } | undefined
) => Effect.Effect<
  LayerMap<
    K,
    L extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : never,
    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 E = never> {
  readonly [TypeId]: TypeId

  /**
   * The internal RcMap that stores the resources.
   */
  readonly rcMap: RcMap.RcMap<
    K,
    {
      readonly layer: Layer.Layer<I, E>
      readonly runtimeEffect: Effect.Effect<Runtime.Runtime<I>, E, Scope.Scope>
    },
    E
  >

  /**
   * Retrieves a Layer for the resources associated with the key.
   */
  get(key: K): Layer.Layer<I, E>

  /**
   * Retrieves a Runtime for the resources associated with the key.
   */
  runtime(key: K): Effect.Effect<Runtime.Runtime<I>, E, Scope.Scope>

  /**
   * 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,
  Lookup extends
    | { readonly lookup: (key: any) => Layer.Layer<any, any, any> }
    | { readonly layers: Record<string, Layer.Layer<any, any, any>> },
  const Deps extends ReadonlyArray<Layer.Layer<any, any, any>> = []
>(
  id: Id,
  options: Lookup & {
    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,
  Service.Success<Lookup>,
  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

Success (type alias)

Signature

type Success<Options> = Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : 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 E,
  in out R,
  in out Deps extends Layer.Layer<any, any, any>
> extends Context.TagClass<Self, Id, LayerMap<K, I, 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 a Layer for the resources associated with the key.
   */
  readonly get: (key: K) => Layer.Layer<I, E, Self>

  /**
   * Retrieves a Runtime for the resources associated with the key.
   */
  readonly runtime: (key: K) => Effect.Effect<Runtime.Runtime<I>, E, Scope.Scope | 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