TagClass<Self, Id, I, E, R, LE, Deps>Service class shape produced by LayerRef.Service.
When to use
Use as the public type for classes returned by LayerRef.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 LayerRef with default layers and
helper accessors for retrieving, using, and invalidating the cached resource.
export interface interface TagClass<in out Self, in out Id extends string, 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 LayerRef.Service.
When to use
Use as the public type for classes returned by LayerRef.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 LayerRef with default layers and
helper accessors for retrieving, using, and invalidating the cached resource.
TagClass<
in out function (type parameter) Self in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Self,
in out function (type parameter) Id in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Id extends string,
in out function (type parameter) I in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>I,
in out function (type parameter) E in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>E,
in out function (type parameter) R in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>R,
in out function (type parameter) LE in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>LE,
in out function (type parameter) Deps in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Deps 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<any, any, any>
> extends import ContextContext.interface ServiceClass<in out Self, in out Identifier extends string, in out Shape>Class-style service key produced by Context.Service<Self, Shape>()("Id").
When to use
Use when declaring a service as a class so the class value can serve as the
Context key.
Details
The class itself is the Context key, and its string key identifies the
service at runtime.
Namespace containing helper types for class-style Context.Service
declarations.
ServiceClass<function (type parameter) Self in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Self, function (type parameter) Id in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Id, interface LayerRef<in out I, in out E = never>A refreshable reference to a single layer-built service context.
When to use
Use when you want to share one scoped layer resource across many users while
retaining the ability to invalidate it and rebuild it later.
Details
A LayerRef is the unkeyed counterpart to a layer cache: it lazily builds the
layer on first use, reuses the resulting context while it is borrowed or kept
idle, and can invalidate the cached context so the next use rebuilds it.
LayerRef<function (type parameter) I in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>I, function (type parameter) E in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>E>> {
/**
* Default layer for the `LayerRef` service, with dependencies applied.
*/
readonly TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>.layer: Layer.Layer<Self, (Deps extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never) | LE, 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)>(property) TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>.layer: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<Self>, LE | (Deps extends Layer<infer _A, infer _E, infer _R> ? _E : never), Exclude<R, Deps extends Layer<infer _A, infer _E, infer _R> ? _A : never> | (Deps extends Layer<i…;
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; <…;
}
Default layer for the LayerRef service, with dependencies applied.
layer: 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<
function (type parameter) Self in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Self,
(function (type parameter) Deps in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Deps 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) | function (type parameter) LE in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>LE,
| type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) R in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>R, (function (type parameter) Deps in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Deps 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)>
| (function (type parameter) Deps in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Deps 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)
>
/**
* Default layer for the `LayerRef` service without provided dependencies.
*/
readonly TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>.layerNoDeps: Layer.Layer<Self, LE, R>(property) TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>.layerNoDeps: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<Self>, LE, R>;
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; <…;
}
Default layer for the LayerRef service without provided dependencies.
layerNoDeps: 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<function (type parameter) Self in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Self, function (type parameter) LE in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>LE, function (type parameter) R in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>R>
/**
* Layer that provides the currently cached context, requiring this service.
*/
readonly TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>.get: Layer.Layer<I, E, Self>(property) TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>.get: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<I>, E, Self>;
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; <…;
}
Layer that provides the currently cached context, requiring this service.
get: 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<function (type parameter) I in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>I, function (type parameter) E in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>E, function (type parameter) Self in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Self>
/**
* Scoped effect that retrieves the currently cached context through this service.
*/
readonly TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>.contextEffect: Effect.Effect<Context.Context<I>, E, Scope.Scope | Self>(property) TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>.contextEffect: {
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;
}
Scoped effect that retrieves the currently cached context through this service.
contextEffect: import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<import ContextContext.interface Context<in Services>Immutable collection of service implementations used for dependency
injection in Effect programs.
Details
The type parameter tracks the service identifiers available in the context.
At runtime, services are stored by each key's string key.
Example (Creating a context with multiple services)
import { Context } from "effect"
// Create a context with multiple services
const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
const context = Context.make(Logger, {
log: (msg: string) => console.log(msg)
})
.pipe(Context.add(Database, { query: (sql) => `Result: ${sql}` }))
Context<function (type parameter) I in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>I>, function (type parameter) E in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>E, import ScopeScope.Scope | function (type parameter) Self in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Self>
/**
* Invalidates the cached context through this service.
*/
readonly TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>.invalidate: Effect.Effect<void, never, Self>(property) TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>.invalidate: {
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;
}
Invalidates the cached context through this service.
invalidate: import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<void, never, function (type parameter) Self in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Self>
/**
* Invalidates the cached context through this service, and reacquires it.
*/
readonly TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>.refresh: Effect.Effect<void, E, Self>(property) TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>.refresh: {
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;
}
Invalidates the cached context through this service, and reacquires it.
refresh: import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<void, function (type parameter) E in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>E, function (type parameter) Self in TagClass<in out Self, in out Id extends string, in out I, in out E, in out R, in out LE, in out Deps extends Layer.Layer<any, any, any>>Self>
}