<Self>(): <
const Id extends string,
const Options extends
| NoExcessProperties<
{
readonly lookup: (key: any) => Layer.Layer<any, any, any>
readonly dependencies?:
| ReadonlyArray<Layer.Layer<any, any, any>>
| undefined
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined
readonly preloadKeys?:
| Iterable<
Options extends { readonly lookup: (key: infer K) => any }
? K
: never
>
| undefined
},
Options
>
| NoExcessProperties<
{
readonly layers: Record<string, Layer.Layer<any, any, any>>
readonly dependencies?:
| ReadonlyArray<Layer.Layer<any, any, any>>
| undefined
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined
readonly preload?: boolean | undefined
},
Options
>
>(
id: Id,
options: Options
) => TagClass<
Self,
Id,
Options extends { readonly lookup: (key: infer K) => any }
? K
: Options extends { readonly layers: infer Layers }
? keyof Layers
: never,
Service.Success<Options>,
Options extends { readonly preload: true }
? never
: Service.Error<Options>,
Service.Services<Options>,
Options extends { readonly preload: true }
? Service.Error<Options>
: Options extends { readonly preloadKeys: Iterable<any> }
? Service.Error<Options>
: never,
Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>
}
? Options["dependencies"][number]
: never
>Create a LayerMap service that provides a dynamic set of resources based on
a key.
Example (Defining a layer map service)
import { Console, Context, Effect, Layer, LayerMap } from "effect"
// Define a service key
const Greeter = Context.Service<{
readonly greet: Effect.Effect<string>
}>("Greeter")
// Create a service that wraps a LayerMap
class GreeterMap extends LayerMap.Service<GreeterMap>()("GreeterMap", {
// Define the lookup function for the layer map
lookup: (name: string) =>
Layer.succeed(Greeter)({
greet: Effect.succeed(`Hello, ${name}!`)
}),
// If a layer is not used for a certain amount of time, it can be removed
idleTimeToLive: "5 seconds"
}) {}
// Usage
const program = Effect.gen(function*() {
// Access and use the Greeter service
const greeter = yield* Greeter
yield* Console.log(yield* greeter.greet)
}).pipe(
// Use the GreeterMap service to provide a variant of the Greeter service
Effect.provide(GreeterMap.get("John"))
).pipe(
// Provide the GreeterMap layer
Effect.provide(GreeterMap.layer)
)export const const Service: <Self>() => <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options) => TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Create a LayerMap service that provides a dynamic set of resources based on
a key.
Example (Defining a layer map service)
import { Console, Context, Effect, Layer, LayerMap } from "effect"
// Define a service key
const Greeter = Context.Service<{
readonly greet: Effect.Effect<string>
}>("Greeter")
// Create a service that wraps a LayerMap
class GreeterMap extends LayerMap.Service<GreeterMap>()("GreeterMap", {
// Define the lookup function for the layer map
lookup: (name: string) =>
Layer.succeed(Greeter)({
greet: Effect.succeed(`Hello, ${name}!`)
}),
// If a layer is not used for a certain amount of time, it can be removed
idleTimeToLive: "5 seconds"
}) {}
// Usage
const program = Effect.gen(function*() {
// Access and use the Greeter service
const greeter = yield* Greeter
yield* Console.log(yield* greeter.greet)
}).pipe(
// Use the GreeterMap service to provide a variant of the Greeter service
Effect.provide(GreeterMap.get("John"))
).pipe(
// Provide the GreeterMap layer
Effect.provide(GreeterMap.layer)
)
Type helpers for values created with LayerMap.Service.
Service = <function (type parameter) Self in <Self>(): <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options) => TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Self>() =>
<
const function (type parameter) Id in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Id extends string,
const function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options extends
| type NoExcessProperties<T, U> = T & Readonly<Record<Exclude<keyof U, keyof T>, never>>Constrains a type to prevent excess properties not present in T.
When to use
Use to catch accidental extra properties in generic functions at compile time.
Details
Extra keys from U that are not in T are mapped to never.
Example (Preventing extra properties)
import type { Types } from "effect"
type Expected = { a: number; b: string }
type Input = { a: number; b: string; c: boolean }
type Result = Types.NoExcessProperties<Expected, Input>
// { a: number; b: string; readonly c: never }
NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>lookup: (key: anykey: any) => import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<any, any, any>
readonly dependencies?: | ReadonlyArray<Layer.Layer<any, any, any>>
| undefined
dependencies?: interface ReadonlyArray<T>ReadonlyArray<import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<any, any, any>> | undefined
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefinedidleTimeToLive?: type IdleTimeToLiveInput<K> =
| Duration.Input
| ((key: K) => Duration.Input)
IdleTimeToLiveInput<any> | undefined
readonly preloadKeys?: | Iterable<
Options extends {
readonly lookup: (key: infer K) => any
}
? K
: never
>
| undefined
preloadKeys?:
| interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options extends { readonly lookup: (key: infer K) => anylookup: (key: Kkey: infer function (type parameter) KK) => any } ? function (type parameter) KK : never>
| undefined
}, function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options>
| type NoExcessProperties<T, U> = T & Readonly<Record<Exclude<keyof U, keyof T>, never>>Constrains a type to prevent excess properties not present in T.
When to use
Use to catch accidental extra properties in generic functions at compile time.
Details
Extra keys from U that are not in T are mapped to never.
Example (Preventing extra properties)
import type { Types } from "effect"
type Expected = { a: number; b: string }
type Input = { a: number; b: string; c: boolean }
type Result = Types.NoExcessProperties<Expected, Input>
// { a: number; b: string; readonly c: never }
NoExcessProperties<{
readonly layers: Record<
string,
Layer.Layer<any, any, any>
>
layers: type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<any, any, any>>
readonly dependencies?: | ReadonlyArray<Layer.Layer<any, any, any>>
| undefined
dependencies?: interface ReadonlyArray<T>ReadonlyArray<import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<any, any, any>> | undefined
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefinedidleTimeToLive?: type IdleTimeToLiveInput<K> =
| Duration.Input
| ((key: K) => Duration.Input)
IdleTimeToLiveInput<any> | undefined
readonly preload?: boolean | undefinedpreload?: boolean | undefined
}, function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options>
>(
id: const Id extends stringid: function (type parameter) Id in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Id,
options: const Options extends NoExcessProperties<{ readonly lookup: (key: any) => Layer.Layer<any, any, any>; readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined; readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined; readonly preloadKeys?: Iterable<Options extends { readonly lookup: (key: infer K) => any; } ? K : never> | undefined; }, Options> | NoExcessProperties<{ readonly layers: Record<string, Layer.Layer<any, any, any>>; readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined; readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined; readonly preload?: boolean | undefined; }, Options>options: function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options
): interface TagClass<in out Self, in out Id extends string, in out K, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Service class shape produced by LayerMap.Service.
When to use
Use as the public type for classes returned by LayerMap.Service when an API
needs to accept, return, or alias the generated service class and its static
helpers.
Details
It combines a Context.Service tag for the LayerMap with default layers
and helper accessors for retrieving, using, and invalidating keyed resources.
TagClass<
function (type parameter) Self in <Self>(): <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options) => TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Self,
function (type parameter) Id in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Id,
function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options extends { readonly lookup: (key: infer K) => anylookup: (key: Kkey: infer function (type parameter) KK) => any } ? function (type parameter) KK
: function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options extends { readonly layers: Layerslayers: infer function (type parameter) LayersLayers } ? keyof function (type parameter) LayersLayers
: never,
Service.type Service.Success<Options> = Service.Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : neverExtracts the services provided by the layers in a LayerMap.Service
definition.
Success<function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options>,
function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options extends { readonly preload: truepreload: true } ? never : Service.type Service.Error<Options> = Service.Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : neverExtracts the error type of the layers in a LayerMap.Service definition.
Error<function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options>,
Service.type Service.Services<Options> = Service.Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : neverExtracts the service requirements of the layers in a LayerMap.Service
definition.
Services<function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options>,
function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options extends { readonly preload: truepreload: true } ? Service.type Service.Error<Options> = Service.Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : neverExtracts the error type of the layers in a LayerMap.Service definition.
Error<function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options>
: function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options extends { readonly preloadKeys: Iterable<any>preloadKeys: interface Iterable<T, TReturn = any, TNext = any>Iterable<any> } ? Service.type Service.Error<Options> = Service.Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : neverExtracts the error type of the layers in a LayerMap.Service definition.
Error<function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options>
: never,
function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options extends { readonly dependencies: ReadonlyArray<
Layer.Layer<any, any, any>
>
dependencies: interface ReadonlyArray<T>ReadonlyArray<import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<any, any, any>> } ? function (type parameter) Options in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Options["dependencies"][number]
: never
> => {
const const Err: anyErr = module globalThisglobalThis.var Error: ErrorConstructorError as any
const const limit: number | undefinedlimit = function getStackTraceLimit(): number | undefinedGet the current Error.stackTraceLimit value.
Returns undefined if the property doesn't exist.
getStackTraceLimit()
function setStackTraceLimit(value: number | undefined): voidSafely set Error.stackTraceLimit if possible, otherwise no-op.
Accepts undefined so a value read via
getStackTraceLimit
can be
restored faithfully.
setStackTraceLimit(2)
const const creationError: anycreationError = new const Err: anyErr()
function setStackTraceLimit(value: number | undefined): voidSafely set Error.stackTraceLimit if possible, otherwise no-op.
Accepts undefined so a value read via
getStackTraceLimit
can be
restored faithfully.
setStackTraceLimit(const limit: number | undefinedlimit)
function function (local function) TagClass(): voidTagClass() {}
const const TagClass_: Mutable<
TagClass<
Self,
Id,
string,
any,
any,
any,
any,
any
>
>
const TagClass_: {
key: Id;
Service: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
};
layer: Layer.Layer<Self, any, unknown>;
layerNoDeps: Layer.Layer<Self, any, any>;
get: (key: string) => Layer.Layer<any, any, Self>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope | Self>;
invalidate: (key: string) => Effect.Effect<void, never, Self>;
of: (this: void, self: LayerMap<string, any, any>) => LayerMap<string, any, any>;
context: (self: LayerMap<string, any, any>) => Context.Context<Self>;
use: (f: (service: LayerMap<string, any, any>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Self | R>;
useSync: (f: (service: LayerMap<string, any, any>) => A) => Effect.Effect<A, never, Self>;
Identifier: Self;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
TagClass_ = function (local function) TagClass(): voidTagClass as any as type Mutable<T> = { -readonly [P in keyof T]: T[P]; }Removes readonly from all properties of T. Supports arrays, tuples,
and records.
When to use
Use when you need a mutable version of a readonly type.
Details
Only affects the top level; nested properties remain readonly.
Example (Converting shallowly to mutable types)
import type { Types } from "effect"
type Obj = Types.Mutable<{
readonly a: string
readonly b: ReadonlyArray<number>
}>
// { a: string; b: ReadonlyArray<number> }
// ^ mutable ^ still readonly inside
type Arr = Types.Mutable<ReadonlyArray<string>>
// string[]
type Tup = Types.Mutable<readonly [string, number]>
// [string, number]
Mutable<interface TagClass<in out Self, in out Id extends string, in out K, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Service class shape produced by LayerMap.Service.
When to use
Use as the public type for classes returned by LayerMap.Service when an API
needs to accept, return, or alias the generated service class and its static
helpers.
Details
It combines a Context.Service tag for the LayerMap with default layers
and helper accessors for retrieving, using, and invalidating keyed resources.
TagClass<function (type parameter) Self in <Self>(): <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options) => TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Self, function (type parameter) Id in <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options): TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Id, string, any, any, any, any, any>>
var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.setPrototypeOf(o: any, proto: object | null): anySets the prototype of a specified object o to object proto or null. Returns the object o.
setPrototypeOf(function (local function) TagClass(): voidTagClass, var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.getPrototypeOf(o: any): anyReturns the prototype of an object.
getPrototypeOf(import ContextContext.const Service: {
<Identifier, Shape = Identifier>(
key: string
): Service<Identifier, Shape>
<Self, Shape>(): <
Identifier extends string,
E,
R = Types.unassigned,
Args extends ReadonlyArray<any> = never
>(
id: Identifier,
options?:
| {
readonly make:
| ((
...args: Args
) => Effect<Shape, E, R>)
| Effect<Shape, E, R>
| undefined
}
| undefined
) => ServiceClass<Self, Identifier, Shape> &
([Types.unassigned] extends [R]
? unknown
: {
readonly make: [Args] extends [never]
? Effect<Shape, E, R>
: (
...args: Args
) => Effect<Shape, E, R>
})
<Self>(): <
Identifier extends string,
Make extends
| Effect<any, any, any>
| ((...args: any) => Effect<any, any, any>)
>(
id: Identifier,
options: { readonly make: Make }
) => ServiceClass<
Self,
Identifier,
Make extends
| Effect<infer _A, infer _E, infer _R>
| ((
...args: infer _Args
) => Effect<infer _A, infer _E, infer _R>)
? _A
: never
> & { readonly make: Make }
}
Service<function (type parameter) Self in <Self>(): <const Id extends string, const Options extends NoExcessProperties<{
readonly lookup: (key: any) => Layer.Layer<any, any, any>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preloadKeys?: Iterable<Options extends {
readonly lookup: (key: infer K) => any;
} ? K : never> | undefined;
}, Options> | NoExcessProperties<{
readonly layers: Record<string, Layer.Layer<any, any, any>>;
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined;
readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined;
readonly preload?: boolean | undefined;
}, Options>>(id: Id, options: Options) => TagClass<Self, Id, Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never, Service.Success<Options>, Options extends {
readonly preload: true;
} ? never : Service.Error<Options>, Service.Services<Options>, Options extends {
readonly preload: true;
} ? Service.Error<Options> : Options extends {
readonly preloadKeys: Iterable<any>;
} ? Service.Error<Options> : never, Options extends {
readonly dependencies: ReadonlyArray<Layer.Layer<any, any, any>>;
} ? Options["dependencies"][number] : never>
Self, any>(id: const Id extends stringid)))
function (local function) TagClass(): voidTagClass.TagClass.key: const Id extends stringkey = id: const Id extends stringid
var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.defineProperty<{
(): void;
key: Id;
}>(o: {
(): void;
key: Id;
}, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>): {
(): void;
key: Id;
}
Adds a property to an object, or modifies attributes of an existing property.
defineProperty(function (local function) TagClass(): voidTagClass, "stack", {
PropertyDescriptor.get?(): anyget() {
return const creationError: anycreationError.stack
}
})
const TagClass_: Mutable<
TagClass<
Self,
Id,
string,
any,
any,
any,
any,
any
>
>
const TagClass_: {
key: Id;
Service: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
};
layer: Layer.Layer<Self, any, unknown>;
layerNoDeps: Layer.Layer<Self, any, any>;
get: (key: string) => Layer.Layer<any, any, Self>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope | Self>;
invalidate: (key: string) => Effect.Effect<void, never, Self>;
of: (this: void, self: LayerMap<string, any, any>) => LayerMap<string, any, any>;
context: (self: LayerMap<string, any, any>) => Context.Context<Self>;
use: (f: (service: LayerMap<string, any, any>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Self | R>;
useSync: (f: (service: LayerMap<string, any, any>) => A) => Effect.Effect<A, never, Self>;
Identifier: Self;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
TagClass_.layerNoDeps: Layer.Layer<Self, any, any>(property) layerNoDeps: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<Self>, any, any>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
A default layer for the LayerMap service without the dependencies provided.
layerNoDeps = import LayerLayer.const effect: {
<I, S>(service: Context.Key<I, S>): <E, R>(
effect: Effect<S, E, R>
) => Layer<I, E, Exclude<R, Scope.Scope>>
<I, S, E, R>(
service: Context.Key<I, S>,
effect: Effect<Types.NoInfer<S>, E, R>
): Layer<I, E, Exclude<R, Scope.Scope>>
}
effect(const TagClass_: Mutable<
TagClass<
Self,
Id,
string,
any,
any,
any,
any,
any
>
>
const TagClass_: {
key: Id;
Service: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
};
layer: Layer.Layer<Self, any, unknown>;
layerNoDeps: Layer.Layer<Self, any, any>;
get: (key: string) => Layer.Layer<any, any, Self>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope | Self>;
invalidate: (key: string) => Effect.Effect<void, never, Self>;
of: (this: void, self: LayerMap<string, any, any>) => LayerMap<string, any, any>;
context: (self: LayerMap<string, any, any>) => Context.Context<Self>;
use: (f: (service: LayerMap<string, any, any>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Self | R>;
useSync: (f: (service: LayerMap<string, any, any>) => A) => Effect.Effect<A, never, Self>;
Identifier: Self;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
TagClass_)(
"lookup" in options: const Options extends NoExcessProperties<{ readonly lookup: (key: any) => Layer.Layer<any, any, any>; readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined; readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined; readonly preloadKeys?: Iterable<Options extends { readonly lookup: (key: infer K) => any; } ? K : never> | undefined; }, Options> | NoExcessProperties<{ readonly layers: Record<string, Layer.Layer<any, any, any>>; readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>> | undefined; readonly idleTimeToLive?: IdleTimeToLiveInput<any> | undefined; readonly preload?: boolean | undefined; }, Options>options
? const make: <
K,
L extends Layer.Layer<any, any, any>,
PreloadKeys extends
| Iterable<K>
| undefined = undefined
>(
lookup: (key: K) => L,
options?:
| {
readonly idleTimeToLive?:
| IdleTimeToLiveInput<K>
| undefined
readonly preloadKeys?: PreloadKeys
}
| undefined
) => Effect.Effect<
LayerMap<K, Layer.Success<L>, Layer.Error<L>>,
PreloadKeys extends undefined
? never
: Layer.Error<L>,
Scope.Scope | Layer.Services<L>
>
Creates a LayerMap that dynamically provides resources based on a key.
Example (Creating a layer map)
import { Context, Effect, Layer, LayerMap } from "effect"
// Define a service key
const DatabaseService = Context.Service<{
readonly query: (sql: string) => Effect.Effect<string>
}>("Database")
// Create a LayerMap that provides different database configurations
const program = Effect.gen(function*() {
const layerMap = yield* LayerMap.make(
(env: string) =>
Layer.succeed(DatabaseService)({
query: Effect.fn("DatabaseService.query")((sql) => Effect.succeed(`${env}: ${sql}`))
}),
{ idleTimeToLive: "5 seconds" }
)
// Get a layer for a specific environment
const devLayer = layerMap.get("development")
// Use the layer to provide the service
const result = yield* Effect.provide(
Effect.gen(function*() {
const db = yield* DatabaseService
return yield* db.query("SELECT * FROM users")
}),
devLayer
)
console.log(result) // "development: SELECT * FROM users"
})
make(options: NoExcessProperties<
{
readonly lookup: (
key: any
) => Layer.Layer<any, any, any>
readonly dependencies?:
| ReadonlyArray<Layer.Layer<any, any, any>>
| undefined
readonly idleTimeToLive?:
| IdleTimeToLiveInput<any>
| undefined
readonly preloadKeys?:
| Iterable<
Options extends {
readonly lookup: (key: infer K) => any
}
? K
: never
>
| undefined
},
Options
>
options.lookup: (key: any) => Layer.Layer<any, any, any>lookup, options: NoExcessProperties<
{
readonly lookup: (
key: any
) => Layer.Layer<any, any, any>
readonly dependencies?:
| ReadonlyArray<Layer.Layer<any, any, any>>
| undefined
readonly idleTimeToLive?:
| IdleTimeToLiveInput<any>
| undefined
readonly preloadKeys?:
| Iterable<
Options extends {
readonly lookup: (key: infer K) => any
}
? K
: never
>
| undefined
},
Options
>
options)
: const fromRecord: <
Layers extends Record<
string,
Layer.Layer<any, any, any>
>,
Preload extends boolean = false
>(
layers: Layers,
options?:
| {
readonly idleTimeToLive?:
| IdleTimeToLiveInput<keyof Layers>
| undefined
readonly preload?: Preload | undefined
}
| undefined
) => Effect.Effect<
LayerMap<
keyof Layers,
Layer.Success<Layers[keyof Layers]>,
Layer.Error<Layers[keyof Layers]>
>,
Preload extends true
? Layer.Error<Layers[keyof Layers]>
: never,
| Scope.Scope
| (Layers[keyof Layers] extends Layer.Layer<
infer _A,
infer _E,
infer _R
>
? _R
: never)
>
Creates a LayerMap from a record of predefined layers.
Details
The record keys become the keys accepted by the returned LayerMap, and the
record values are the layers built for those keys.
Example (Creating a layer map from a record)
import { Context, Effect, Layer, LayerMap } from "effect"
// Define service keys
const DevDatabase = Context.Service<{
readonly query: (sql: string) => Effect.Effect<string>
}>("DevDatabase")
const ProdDatabase = Context.Service<{
readonly query: (sql: string) => Effect.Effect<string>
}>("ProdDatabase")
// Create predefined layers
const layers = {
development: Layer.succeed(DevDatabase)({
query: Effect.fn("DevDatabase.query")((sql) => Effect.succeed(`DEV: ${sql}`))
}),
production: Layer.succeed(ProdDatabase)({
query: Effect.fn("ProdDatabase.query")((sql) => Effect.succeed(`PROD: ${sql}`))
})
} as const
// Create a LayerMap from the record
const program = Effect.gen(function*() {
const layerMap = yield* LayerMap.fromRecord(layers, {
idleTimeToLive: "10 seconds"
})
// Get layers by key
const devLayer = layerMap.get("development")
const prodLayer = layerMap.get("production")
console.log("LayerMap created from record")
})
fromRecord(options: NoExcessProperties<
{
readonly layers: Record<
string,
Layer.Layer<any, any, any>
>
readonly dependencies?:
| ReadonlyArray<Layer.Layer<any, any, any>>
| undefined
readonly idleTimeToLive?:
| IdleTimeToLiveInput<any>
| undefined
readonly preload?: boolean | undefined
},
Options
>
options.layers: Record<
string,
Layer.Layer<any, any, any>
>
layers as any, options: NoExcessProperties<
{
readonly layers: Record<
string,
Layer.Layer<any, any, any>
>
readonly dependencies?:
| ReadonlyArray<Layer.Layer<any, any, any>>
| undefined
readonly idleTimeToLive?:
| IdleTimeToLiveInput<any>
| undefined
readonly preload?: boolean | undefined
},
Options
>
options) as any
)
const TagClass_: Mutable<
TagClass<
Self,
Id,
string,
any,
any,
any,
any,
any
>
>
const TagClass_: {
key: Id;
Service: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
};
layer: Layer.Layer<Self, any, unknown>;
layerNoDeps: Layer.Layer<Self, any, any>;
get: (key: string) => Layer.Layer<any, any, Self>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope | Self>;
invalidate: (key: string) => Effect.Effect<void, never, Self>;
of: (this: void, self: LayerMap<string, any, any>) => LayerMap<string, any, any>;
context: (self: LayerMap<string, any, any>) => Context.Context<Self>;
use: (f: (service: LayerMap<string, any, any>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Self | R>;
useSync: (f: (service: LayerMap<string, any, any>) => A) => Effect.Effect<A, never, Self>;
Identifier: Self;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
TagClass_.layer: Layer.Layer<Self, any, unknown>(property) layer: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<Self>, any, unknown>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
A default layer for the LayerMap service.
layer = options: | NoExcessProperties<
{
readonly lookup: (
key: any
) => Layer.Layer<any, any, any>
readonly dependencies?:
| ReadonlyArray<
Layer.Layer<any, any, any>
>
| undefined
readonly idleTimeToLive?:
| IdleTimeToLiveInput<any>
| undefined
readonly preloadKeys?:
| Iterable<
Options extends {
readonly lookup: (
key: infer K
) => any
}
? K
: never
>
| undefined
},
Options
>
| NoExcessProperties<
{
readonly layers: Record<
string,
Layer.Layer<any, any, any>
>
readonly dependencies?:
| ReadonlyArray<
Layer.Layer<any, any, any>
>
| undefined
readonly idleTimeToLive?:
| IdleTimeToLiveInput<any>
| undefined
readonly preload?: boolean | undefined
},
Options
>
options.dependencies?: | readonly Layer.Layer<any, any, any>[]
| undefined
dependencies && options: | NoExcessProperties<
{
readonly lookup: (
key: any
) => Layer.Layer<any, any, any>
readonly dependencies?:
| ReadonlyArray<
Layer.Layer<any, any, any>
>
| undefined
readonly idleTimeToLive?:
| IdleTimeToLiveInput<any>
| undefined
readonly preloadKeys?:
| Iterable<
Options extends {
readonly lookup: (
key: infer K
) => any
}
? K
: never
>
| undefined
},
Options
>
| NoExcessProperties<
{
readonly layers: Record<
string,
Layer.Layer<any, any, any>
>
readonly dependencies?:
| ReadonlyArray<
Layer.Layer<any, any, any>
>
| undefined
readonly idleTimeToLive?:
| IdleTimeToLiveInput<any>
| undefined
readonly preload?: boolean | undefined
},
Options
>
options.dependencies?: ReadonlyArray<
Layer.Layer<any, any, any>
>
dependencies.ReadonlyArray<Layer<any, any, any>>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length > 0 ?
import LayerLayer.const provide: {
<RIn, E, ROut>(that: Layer<ROut, E, RIn>): <
RIn2,
E2,
ROut2
>(
self: Layer<ROut2, E2, RIn2>
) => Layer<
ROut2,
E | E2,
RIn | Exclude<RIn2, ROut>
>
<Layers extends [Any, ...Array<Any>]>(
that: Layers
): <A, E, R>(
self: Layer<A, E, R>
) => Layer<
A,
E | Error<Layers[number]>,
| Services<Layers[number]>
| Exclude<R, Success<Layers[number]>>
>
<RIn2, E2, ROut2, RIn, E, ROut>(
self: Layer<ROut2, E2, RIn2>,
that: Layer<ROut, E, RIn>
): Layer<
ROut2,
E | E2,
RIn | Exclude<RIn2, ROut>
>
<A, E, R, Layers extends [Any, ...Array<Any>]>(
self: Layer<A, E, R>,
that: Layers
): Layer<
A,
E | Error<Layers[number]>,
| Services<Layers[number]>
| Exclude<R, Success<Layers[number]>>
>
}
provide(const TagClass_: Mutable<
TagClass<
Self,
Id,
string,
any,
any,
any,
any,
any
>
>
const TagClass_: {
key: Id;
Service: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
};
layer: Layer.Layer<Self, any, unknown>;
layerNoDeps: Layer.Layer<Self, any, any>;
get: (key: string) => Layer.Layer<any, any, Self>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope | Self>;
invalidate: (key: string) => Effect.Effect<void, never, Self>;
of: (this: void, self: LayerMap<string, any, any>) => LayerMap<string, any, any>;
context: (self: LayerMap<string, any, any>) => Context.Context<Self>;
use: (f: (service: LayerMap<string, any, any>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Self | R>;
useSync: (f: (service: LayerMap<string, any, any>) => A) => Effect.Effect<A, never, Self>;
Identifier: Self;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
TagClass_.layerNoDeps: Layer.Layer<Self, any, any>(property) layerNoDeps: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<Self>, any, any>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
A default layer for the LayerMap service without the dependencies provided.
layerNoDeps, options: | NoExcessProperties<
{
readonly lookup: (
key: any
) => Layer.Layer<any, any, any>
readonly dependencies?:
| ReadonlyArray<
Layer.Layer<any, any, any>
>
| undefined
readonly idleTimeToLive?:
| IdleTimeToLiveInput<any>
| undefined
readonly preloadKeys?:
| Iterable<
Options extends {
readonly lookup: (
key: infer K
) => any
}
? K
: never
>
| undefined
},
Options
>
| NoExcessProperties<
{
readonly layers: Record<
string,
Layer.Layer<any, any, any>
>
readonly dependencies?:
| ReadonlyArray<
Layer.Layer<any, any, any>
>
| undefined
readonly idleTimeToLive?:
| IdleTimeToLiveInput<any>
| undefined
readonly preload?: boolean | undefined
},
Options
>
options.dependencies?: ReadonlyArray<
Layer.Layer<any, any, any>
>
dependencies as any) :
const TagClass_: Mutable<
TagClass<
Self,
Id,
string,
any,
any,
any,
any,
any
>
>
const TagClass_: {
key: Id;
Service: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
};
layer: Layer.Layer<Self, any, unknown>;
layerNoDeps: Layer.Layer<Self, any, any>;
get: (key: string) => Layer.Layer<any, any, Self>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope | Self>;
invalidate: (key: string) => Effect.Effect<void, never, Self>;
of: (this: void, self: LayerMap<string, any, any>) => LayerMap<string, any, any>;
context: (self: LayerMap<string, any, any>) => Context.Context<Self>;
use: (f: (service: LayerMap<string, any, any>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Self | R>;
useSync: (f: (service: LayerMap<string, any, any>) => A) => Effect.Effect<A, never, Self>;
Identifier: Self;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
TagClass_.layerNoDeps: Layer.Layer<Self, any, any>(property) layerNoDeps: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<Self>, any, any>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
A default layer for the LayerMap service without the dependencies provided.
layerNoDeps
const TagClass_: Mutable<
TagClass<
Self,
Id,
string,
any,
any,
any,
any,
any
>
>
const TagClass_: {
key: Id;
Service: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
};
layer: Layer.Layer<Self, any, unknown>;
layerNoDeps: Layer.Layer<Self, any, any>;
get: (key: string) => Layer.Layer<any, any, Self>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope | Self>;
invalidate: (key: string) => Effect.Effect<void, never, Self>;
of: (this: void, self: LayerMap<string, any, any>) => LayerMap<string, any, any>;
context: (self: LayerMap<string, any, any>) => Context.Context<Self>;
use: (f: (service: LayerMap<string, any, any>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Self | R>;
useSync: (f: (service: LayerMap<string, any, any>) => A) => Effect.Effect<A, never, Self>;
Identifier: Self;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
TagClass_.get: (
key: string
) => Layer.Layer<any, any, Self>
Retrieves a Layer for the resources associated with the key.
get = (key: stringkey: string) => import LayerLayer.const unwrap: <A, E1, R1, E, R>(
self: Effect<Layer<A, E1, R1>, E, R>
) => Layer<
A,
E | E1,
R1 | Exclude<R, Scope.Scope>
>
Unwraps a Layer from an Effect, flattening the nested structure.
When to use
Use when you have an Effect that produces a Layer and you want to
use that layer directly.
Details
The resulting Layer will have the combined error and dependency types from
both the outer Effect and the inner Layer.
Example (Unwrapping an effectful layer)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
const layerEffect = Effect.succeed(
Layer.succeed(Database, { query: Effect.fn("Database.query")((sql: string) => Effect.succeed("result")) })
)
const unwrappedLayer = Layer.unwrap(layerEffect)
unwrap(import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
map(const TagClass_: Mutable<
TagClass<
Self,
Id,
string,
any,
any,
any,
any,
any
>
>
const TagClass_: {
key: Id;
Service: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
};
layer: Layer.Layer<Self, any, unknown>;
layerNoDeps: Layer.Layer<Self, any, any>;
get: (key: string) => Layer.Layer<any, any, Self>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope | Self>;
invalidate: (key: string) => Effect.Effect<void, never, Self>;
of: (this: void, self: LayerMap<string, any, any>) => LayerMap<string, any, any>;
context: (self: LayerMap<string, any, any>) => Context.Context<Self>;
use: (f: (service: LayerMap<string, any, any>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Self | R>;
useSync: (f: (service: LayerMap<string, any, any>) => A) => Effect.Effect<A, never, Self>;
Identifier: Self;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
TagClass_, (layerMap: LayerMap<string, any, any>(parameter) layerMap: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
}
layerMap) => layerMap: LayerMap<string, any, any>(parameter) layerMap: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
}
layerMap.LayerMap<string, any, any>.get(key: string): Layer.Layer<any, any, never>Retrieves a Layer for the resources associated with the key.
get(key: stringkey)))
const TagClass_: Mutable<
TagClass<
Self,
Id,
string,
any,
any,
any,
any,
any
>
>
const TagClass_: {
key: Id;
Service: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
};
layer: Layer.Layer<Self, any, unknown>;
layerNoDeps: Layer.Layer<Self, any, any>;
get: (key: string) => Layer.Layer<any, any, Self>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope | Self>;
invalidate: (key: string) => Effect.Effect<void, never, Self>;
of: (this: void, self: LayerMap<string, any, any>) => LayerMap<string, any, any>;
context: (self: LayerMap<string, any, any>) => Context.Context<Self>;
use: (f: (service: LayerMap<string, any, any>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Self | R>;
useSync: (f: (service: LayerMap<string, any, any>) => A) => Effect.Effect<A, never, Self>;
Identifier: Self;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
TagClass_.contextEffect: (
key: string
) => Effect.Effect<
Context.Context<any>,
any,
Scope.Scope | Self
>
Retrieves the context associated with the key.
contextEffect = (key: stringkey: string) => import EffectEffect.const flatMap: {
<A, B, E1, R1>(
f: (a: A) => Effect<B, E1, R1>
): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E1 | E, R1 | R>
<A, E, R, B, E1, R1>(
self: Effect<A, E, R>,
f: (a: A) => Effect<B, E1, R1>
): Effect<B, E | E1, R | R1>
}
flatMap(const TagClass_: Mutable<
TagClass<
Self,
Id,
string,
any,
any,
any,
any,
any
>
>
const TagClass_: {
key: Id;
Service: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
};
layer: Layer.Layer<Self, any, unknown>;
layerNoDeps: Layer.Layer<Self, any, any>;
get: (key: string) => Layer.Layer<any, any, Self>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope | Self>;
invalidate: (key: string) => Effect.Effect<void, never, Self>;
of: (this: void, self: LayerMap<string, any, any>) => LayerMap<string, any, any>;
context: (self: LayerMap<string, any, any>) => Context.Context<Self>;
use: (f: (service: LayerMap<string, any, any>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Self | R>;
useSync: (f: (service: LayerMap<string, any, any>) => A) => Effect.Effect<A, never, Self>;
Identifier: Self;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
TagClass_, (layerMap: LayerMap<string, any, any>(parameter) layerMap: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
}
layerMap) => layerMap: LayerMap<string, any, any>(parameter) layerMap: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
}
layerMap.LayerMap<string, any, any>.contextEffect(key: string): Effect.Effect<Context.Context<any>, any, Scope.Scope>Retrieves the context associated with the key.
contextEffect(key: stringkey))
const TagClass_: Mutable<
TagClass<
Self,
Id,
string,
any,
any,
any,
any,
any
>
>
const TagClass_: {
key: Id;
Service: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
};
layer: Layer.Layer<Self, any, unknown>;
layerNoDeps: Layer.Layer<Self, any, any>;
get: (key: string) => Layer.Layer<any, any, Self>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope | Self>;
invalidate: (key: string) => Effect.Effect<void, never, Self>;
of: (this: void, self: LayerMap<string, any, any>) => LayerMap<string, any, any>;
context: (self: LayerMap<string, any, any>) => Context.Context<Self>;
use: (f: (service: LayerMap<string, any, any>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Self | R>;
useSync: (f: (service: LayerMap<string, any, any>) => A) => Effect.Effect<A, never, Self>;
Identifier: Self;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
TagClass_.invalidate: (
key: string
) => Effect.Effect<void, never, Self>
Invalidates the resource associated with the key.
invalidate = (key: stringkey: string) => import EffectEffect.const flatMap: {
<A, B, E1, R1>(
f: (a: A) => Effect<B, E1, R1>
): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E1 | E, R1 | R>
<A, E, R, B, E1, R1>(
self: Effect<A, E, R>,
f: (a: A) => Effect<B, E1, R1>
): Effect<B, E | E1, R | R1>
}
flatMap(const TagClass_: Mutable<
TagClass<
Self,
Id,
string,
any,
any,
any,
any,
any
>
>
const TagClass_: {
key: Id;
Service: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
};
layer: Layer.Layer<Self, any, unknown>;
layerNoDeps: Layer.Layer<Self, any, any>;
get: (key: string) => Layer.Layer<any, any, Self>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope | Self>;
invalidate: (key: string) => Effect.Effect<void, never, Self>;
of: (this: void, self: LayerMap<string, any, any>) => LayerMap<string, any, any>;
context: (self: LayerMap<string, any, any>) => Context.Context<Self>;
use: (f: (service: LayerMap<string, any, any>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Self | R>;
useSync: (f: (service: LayerMap<string, any, any>) => A) => Effect.Effect<A, never, Self>;
Identifier: Self;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
TagClass_, (layerMap: LayerMap<string, any, any>(parameter) layerMap: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
}
layerMap) => layerMap: LayerMap<string, any, any>(parameter) layerMap: {
rcMap: RcMap.RcMap<K, Context.Context<I>, E>;
get: (key: string) => Layer.Layer<any, any, never>;
contextEffect: (key: string) => Effect.Effect<Context.Context<any>, any, Scope.Scope>;
invalidate: (key: string) => Effect.Effect<void>;
}
layerMap.function LayerMap(key: string): Effect.Effect<void>Invalidates the resource associated with the key.
invalidate(key: stringkey))
return function (local function) TagClass(): voidTagClass as any
}
/**
* Type helpers for values created with `LayerMap.Service`.
*
* @since 3.14.0
*/
export declare namespace Service {
/**
* Extracts the key type accepted by a `LayerMap.Service` definition.
*
* @category services
* @since 3.14.0
*/
export type type Service.Key<Options> = Options extends {
readonly lookup: (key: infer K) => any;
} ? K : Options extends {
readonly layers: infer Layers;
} ? keyof Layers : never
Extracts the key type accepted by a LayerMap.Service definition.
Key<function (type parameter) Options in type Service.Key<Options>Options> = function (type parameter) Options in type Service.Key<Options>Options extends { readonly lookup: (key: infer K) => anylookup: (key: Kkey: infer function (type parameter) KK) => any } ? function (type parameter) KK
: function (type parameter) Options in type Service.Key<Options>Options extends { readonly layers: Layerslayers: infer function (type parameter) LayersLayers } ? keyof function (type parameter) LayersLayers
: never
/**
* Extracts the layer type produced by a `LayerMap.Service` definition.
*
* @category services
* @since 3.14.0
*/
export type type Service.Layers<Options> = Options extends {
readonly lookup: (key: infer _K) => infer Layers;
} ? Layers : Options extends {
readonly layers: infer Layers;
} ? Layers[keyof Layers] : never
Extracts the layer type produced by a LayerMap.Service definition.
Layers<function (type parameter) Options in type Service.Layers<Options>Options> = function (type parameter) Options in type Service.Layers<Options>Options extends { readonly lookup: (key: infer _K) => infer Layerslookup: (key: _Kkey: infer function (type parameter) _K_K) => infer function (type parameter) LayersLayers } ? function (type parameter) LayersLayers
: function (type parameter) Options in type Service.Layers<Options>Options extends { readonly layers: Layerslayers: infer function (type parameter) LayersLayers } ? function (type parameter) LayersLayers[keyof function (type parameter) LayersLayers]
: never
/**
* Extracts the services provided by the layers in a `LayerMap.Service`
* definition.
*
* @category services
* @since 3.14.0
*/
export type type Service.Success<Options> = Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : neverExtracts the services provided by the layers in a LayerMap.Service
definition.
Success<function (type parameter) Options in type Service.Success<Options>Options> = type Service.Layers<Options> = Options extends {
readonly lookup: (key: infer _K) => infer Layers;
} ? Layers : Options extends {
readonly layers: infer Layers;
} ? Layers[keyof Layers] : never
Extracts the layer type produced by a LayerMap.Service definition.
Layers<function (type parameter) Options in type Service.Success<Options>Options> extends import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<infer function (type parameter) _A_A, infer function (type parameter) _E_E, infer function (type parameter) _R_R> ? function (type parameter) _A_A : never
/**
* Extracts the error type of the layers in a `LayerMap.Service` definition.
*
* @category services
* @since 3.14.0
*/
export type type Service.Error<Options> = Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : neverExtracts the error type of the layers in a LayerMap.Service definition.
Error<function (type parameter) Options in type Service.Error<Options>Options> = type Service.Layers<Options> = Options extends {
readonly lookup: (key: infer _K) => infer Layers;
} ? Layers : Options extends {
readonly layers: infer Layers;
} ? Layers[keyof Layers] : never
Extracts the layer type produced by a LayerMap.Service definition.
Layers<function (type parameter) Options in type Service.Error<Options>Options> extends import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<infer function (type parameter) _A_A, infer function (type parameter) _E_E, infer function (type parameter) _R_R> ? function (type parameter) _E_E : never
/**
* Extracts the service requirements of the layers in a `LayerMap.Service`
* definition.
*
* @category services
* @since 4.0.0
*/
export type type Service.Services<Options> = Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : neverExtracts the service requirements of the layers in a LayerMap.Service
definition.
Services<function (type parameter) Options in type Service.Services<Options>Options> = type Service.Layers<Options> = Options extends {
readonly lookup: (key: infer _K) => infer Layers;
} ? Layers : Options extends {
readonly layers: infer Layers;
} ? Layers[keyof Layers] : never
Extracts the layer type produced by a LayerMap.Service definition.
Layers<function (type parameter) Options in type Service.Services<Options>Options> extends import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<infer function (type parameter) _A_A, infer function (type parameter) _E_E, infer function (type parameter) _R_R> ? function (type parameter) _R_R : never
}