Service<Identifier, Shape>Context key with helper methods for working with a service.
Details
context creates a one-service Context, use and useSync retrieve the
service from the current Effect context before applying a function, and of
is a type-level helper for service values.
Example (Defining a service key)
import { Context } from "effect"
// Define an identifier for a database service
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// The key can be used to store and retrieve services
const context = Context.make(Database, { query: (sql) => `Result: ${sql}` })export interface interface Service<in out Identifier, in out Shape>Context key with helper methods for working with a service.
Details
context creates a one-service Context, use and useSync retrieve the
service from the current Effect context before applying a function, and of
is a type-level helper for service values.
Example (Defining a service key)
import { Context } from "effect"
// Define an identifier for a database service
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// The key can be used to store and retrieve services
const context = Context.make(Database, { query: (sql) => `Result: ${sql}` })
Creates a Context service key.
When to use
Use when you need to define a context service key for a dependency that must
be provided by the surrounding context.
Details
Call Context.Service("Key") for a function-style key, or use the two-stage
form Context.Service<Self, Shape>()("Key") for class-style service
declarations. The returned key can be yielded as an Effect and passed to
Context.make, Context.add, and the Context getter functions.
Gotchas
The string key is the runtime identity of the service. Reusing the same key
string for unrelated services makes them occupy the same slot in a
Context.
Example (Creating service keys)
import { Context } from "effect"
// Create a simple service
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Create a service class
class Config extends Context.Service<Config, {
port: number
}>()("Config") {}
// Use the services to create contexts
const db = Context.make(Database, {
query: (sql) => `Result: ${sql}`
})
const config = Context.make(Config, { port: 8080 })
Namespace containing utility types for Context service keys.
Example (Extracting service types)
import { Context } from "effect"
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Extract service type from a key
type DatabaseService = Context.Service.Shape<typeof Database>
// Extract identifier type from a key
type DatabaseId = Context.Service.Identifier<typeof Database>
Service<in out function (type parameter) Identifier in Service<in out Identifier, in out Shape>Identifier, in out function (type parameter) Shape in Service<in out Identifier, in out Shape>Shape> extends interface Key<out Identifier, out Shape>Typed identifier for a service stored in a Context.
When to use
Use as the typed handle for storing, retrieving, and requiring a specific
service in a Context.
Details
Identifier tracks the requirement in Effect types, while Shape is the
service implementation retrieved by the key. A key is also an Effect value,
so yielding it inside Effect.gen retrieves the service from the current
fiber context.
Key<function (type parameter) Identifier in Service<in out Identifier, in out Shape>Identifier, function (type parameter) Shape in Service<in out Identifier, in out Shape>Shape> {
Service<in out Identifier, in out Shape>.of(this: void, self: Shape): Shapeof(this: voidthis: void, self: in out Shapeself: function (type parameter) Shape in Service<in out Identifier, in out Shape>Shape): function (type parameter) Shape in Service<in out Identifier, in out Shape>Shape
function Service(self: Shape): Context<Identifier>context(self: in out Shapeself: function (type parameter) Shape in Service<in out Identifier, in out Shape>Shape): 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) Identifier in Service<in out Identifier, in out Shape>Identifier>
Service<A, E, R>(f: (service: Shape) => Effect<A, E, R>): Effect<A, E, R | Identifier>use<function (type parameter) A in Service<in out Identifier, in out Shape>.use<A, E, R>(f: (service: Shape) => Effect<A, E, R>): Effect<A, E, R | Identifier>A, function (type parameter) E in Service<in out Identifier, in out Shape>.use<A, E, R>(f: (service: Shape) => Effect<A, E, R>): Effect<A, E, R | Identifier>E, function (type parameter) R in Service<in out Identifier, in out Shape>.use<A, E, R>(f: (service: Shape) => Effect<A, E, R>): Effect<A, E, R | Identifier>R>(f: (service: Shape) => Effect<A, E, R>f: (service: in out Shapeservice: function (type parameter) Shape in Service<in out Identifier, in out Shape>Shape) => 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<function (type parameter) A in Service<in out Identifier, in out Shape>.use<A, E, R>(f: (service: Shape) => Effect<A, E, R>): Effect<A, E, R | Identifier>A, function (type parameter) E in Service<in out Identifier, in out Shape>.use<A, E, R>(f: (service: Shape) => Effect<A, E, R>): Effect<A, E, R | Identifier>E, function (type parameter) R in Service<in out Identifier, in out Shape>.use<A, E, R>(f: (service: Shape) => Effect<A, E, R>): Effect<A, E, R | Identifier>R>): 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<function (type parameter) A in Service<in out Identifier, in out Shape>.use<A, E, R>(f: (service: Shape) => Effect<A, E, R>): Effect<A, E, R | Identifier>A, function (type parameter) E in Service<in out Identifier, in out Shape>.use<A, E, R>(f: (service: Shape) => Effect<A, E, R>): Effect<A, E, R | Identifier>E, function (type parameter) R in Service<in out Identifier, in out Shape>.use<A, E, R>(f: (service: Shape) => Effect<A, E, R>): Effect<A, E, R | Identifier>R | function (type parameter) Identifier in Service<in out Identifier, in out Shape>Identifier>
Service<A>(f: (service: Shape) => A): Effect<A, never, Identifier>useSync<function (type parameter) A in Service<in out Identifier, in out Shape>.useSync<A>(f: (service: Shape) => A): Effect<A, never, Identifier>A>(f: (service: Shape) => Af: (service: in out Shapeservice: function (type parameter) Shape in Service<in out Identifier, in out Shape>Shape) => function (type parameter) A in Service<in out Identifier, in out Shape>.useSync<A>(f: (service: Shape) => A): Effect<A, never, Identifier>A): 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<function (type parameter) A in Service<in out Identifier, in out Shape>.useSync<A>(f: (service: Shape) => A): Effect<A, never, Identifier>A, never, function (type parameter) Identifier in Service<in out Identifier, in out Shape>Identifier>
}
/**
* 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.
*
* @see {@link Service} for creating function-style keys or class-style service keys
*
* @category models
* @since 4.0.0
*/
export interface 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<in out function (type parameter) Self in ServiceClass<in out Self, in out Identifier extends string, in out Shape>Self, in out function (type parameter) Identifier in ServiceClass<in out Self, in out Identifier extends string, in out Shape>Identifier extends string, in out function (type parameter) Shape in ServiceClass<in out Self, in out Identifier extends string, in out Shape>Shape>
extends interface Service<in out Identifier, in out Shape>Context key with helper methods for working with a service.
Details
context creates a one-service Context, use and useSync retrieve the
service from the current Effect context before applying a function, and of
is a type-level helper for service values.
Example (Defining a service key)
import { Context } from "effect"
// Define an identifier for a database service
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// The key can be used to store and retrieve services
const context = Context.make(Database, { query: (sql) => `Result: ${sql}` })
Creates a Context service key.
When to use
Use when you need to define a context service key for a dependency that must
be provided by the surrounding context.
Details
Call Context.Service("Key") for a function-style key, or use the two-stage
form Context.Service<Self, Shape>()("Key") for class-style service
declarations. The returned key can be yielded as an Effect and passed to
Context.make, Context.add, and the Context getter functions.
Gotchas
The string key is the runtime identity of the service. Reusing the same key
string for unrelated services makes them occupy the same slot in a
Context.
Example (Creating service keys)
import { Context } from "effect"
// Create a simple service
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Create a service class
class Config extends Context.Service<Config, {
port: number
}>()("Config") {}
// Use the services to create contexts
const db = Context.make(Database, {
query: (sql) => `Result: ${sql}`
})
const config = Context.make(Config, { port: 8080 })
Namespace containing utility types for Context service keys.
Example (Extracting service types)
import { Context } from "effect"
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Extract service type from a key
type DatabaseService = Context.Service.Shape<typeof Database>
// Extract identifier type from a key
type DatabaseId = Context.Service.Identifier<typeof Database>
Service<function (type parameter) Self in ServiceClass<in out Self, in out Identifier extends string, in out Shape>Self, function (type parameter) Shape in ServiceClass<in out Self, in out Identifier extends string, in out Shape>Shape>
{
new(_: never_: never): ServiceClass.interface ServiceClass<in out Self, in out Identifier extends string, in out Shape>.Shape<Identifier extends string, Service>Runtime and type-level metadata carried by a class-style service key,
including its service type identifier, string key, and service shape.
Shape<function (type parameter) Identifier in ServiceClass<in out Self, in out Identifier extends string, in out Shape>Identifier, function (type parameter) Shape in ServiceClass<in out Self, in out Identifier extends string, in out Shape>Shape>
readonly ServiceClass<in out Self, in out Identifier extends string, in out Shape>.key: in out Identifier extends stringkey: function (type parameter) Identifier in ServiceClass<in out Self, in out Identifier extends string, in out Shape>Identifier
}
/**
* Namespace containing helper types for class-style `Context.Service`
* declarations.
*
* @since 4.0.0
*/
export declare namespace ServiceClass {
/**
* Runtime and type-level metadata carried by a class-style service key,
* including its service type identifier, string key, and service shape.
*
* @category models
* @since 4.0.0
*/
export interface interface ServiceClass<in out Self, in out Identifier extends string, in out Shape>.Shape<Identifier extends string, Service>Runtime and type-level metadata carried by a class-style service key,
including its service type identifier, string key, and service shape.
Shape<function (type parameter) Identifier in Shape<Identifier extends string, Service>Identifier extends string, function (type parameter) Service in Shape<Identifier extends string, Service>Service> {
readonly [const ServiceTypeId: ServiceTypeIdString literal type used as the runtime type identifier for Context
service keys.
Runtime type identifier attached to Context service keys and used by
isKey to recognize them.
ServiceTypeId]: typeof const ServiceTypeId: ServiceTypeIdString literal type used as the runtime type identifier for Context
service keys.
Runtime type identifier attached to Context service keys and used by
isKey to recognize them.
ServiceTypeId
readonly ServiceClass<in out Self, in out Identifier extends string, in out Shape>.Shape<Identifier extends string, Service>.key: Identifier extends stringkey: function (type parameter) Identifier in Shape<Identifier extends string, Service>Identifier
readonly type Service: ServiceService: function (type parameter) Service in Shape<Identifier extends string, Service>Service
}
}
/**
* Creates a `Context` service key.
*
* **When to use**
*
* Use when you need to define a context service key for a dependency that must
* be provided by the surrounding context.
*
* **Details**
*
* Call `Context.Service("Key")` for a function-style key, or use the two-stage
* form `Context.Service<Self, Shape>()("Key")` for class-style service
* declarations. The returned key can be yielded as an Effect and passed to
* `Context.make`, `Context.add`, and the Context getter functions.
*
* **Gotchas**
*
* The string key is the runtime identity of the service. Reusing the same key
* string for unrelated services makes them occupy the same slot in a
* `Context`.
*
* **Example** (Creating service keys)
*
* ```ts
* import { Context } from "effect"
*
* // Create a simple service
* const Database = Context.Service<{
* query: (sql: string) => string
* }>("Database")
*
* // Create a service class
* class Config extends Context.Service<Config, {
* port: number
* }>()("Config") {}
*
* // Use the services to create contexts
* const db = Context.make(Database, {
* query: (sql) => `Result: ${sql}`
* })
* const config = Context.make(Config, { port: 8080 })
* ```
*
* @see {@link Reference} for service keys with default values
*
* @category constructors
* @since 4.0.0
*/
export const const Service: {
<Identifier, Shape = Identifier>(key: string): Service<Identifier, Shape>;
<Self, Shape>(): <const 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>(): <const 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;
};
}
Context key with helper methods for working with a service.
Details
context creates a one-service Context, use and useSync retrieve the
service from the current Effect context before applying a function, and of
is a type-level helper for service values.
Example (Defining a service key)
import { Context } from "effect"
// Define an identifier for a database service
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// The key can be used to store and retrieve services
const context = Context.make(Database, { query: (sql) => `Result: ${sql}` })
Creates a Context service key.
When to use
Use when you need to define a context service key for a dependency that must
be provided by the surrounding context.
Details
Call Context.Service("Key") for a function-style key, or use the two-stage
form Context.Service<Self, Shape>()("Key") for class-style service
declarations. The returned key can be yielded as an Effect and passed to
Context.make, Context.add, and the Context getter functions.
Gotchas
The string key is the runtime identity of the service. Reusing the same key
string for unrelated services makes them occupy the same slot in a
Context.
Example (Creating service keys)
import { Context } from "effect"
// Create a simple service
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Create a service class
class Config extends Context.Service<Config, {
port: number
}>()("Config") {}
// Use the services to create contexts
const db = Context.make(Database, {
query: (sql) => `Result: ${sql}`
})
const config = Context.make(Config, { port: 8080 })
Namespace containing utility types for Context service keys.
Example (Extracting service types)
import { Context } from "effect"
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Extract service type from a key
type DatabaseService = Context.Service.Shape<typeof Database>
// Extract identifier type from a key
type DatabaseId = Context.Service.Identifier<typeof Database>
Service: {
<function (type parameter) Identifier in <Identifier, Shape = Identifier>(key: string): Service<Identifier, Shape>Identifier, function (type parameter) Shape in <Identifier, Shape = Identifier>(key: string): Service<Identifier, Shape>Shape = function (type parameter) Identifier in <Identifier, Shape = Identifier>(key: string): Service<Identifier, Shape>Identifier>(key: stringkey: string): interface Service<in out Identifier, in out Shape>Context key with helper methods for working with a service.
Details
context creates a one-service Context, use and useSync retrieve the
service from the current Effect context before applying a function, and of
is a type-level helper for service values.
Example (Defining a service key)
import { Context } from "effect"
// Define an identifier for a database service
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// The key can be used to store and retrieve services
const context = Context.make(Database, { query: (sql) => `Result: ${sql}` })
Creates a Context service key.
When to use
Use when you need to define a context service key for a dependency that must
be provided by the surrounding context.
Details
Call Context.Service("Key") for a function-style key, or use the two-stage
form Context.Service<Self, Shape>()("Key") for class-style service
declarations. The returned key can be yielded as an Effect and passed to
Context.make, Context.add, and the Context getter functions.
Gotchas
The string key is the runtime identity of the service. Reusing the same key
string for unrelated services makes them occupy the same slot in a
Context.
Example (Creating service keys)
import { Context } from "effect"
// Create a simple service
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Create a service class
class Config extends Context.Service<Config, {
port: number
}>()("Config") {}
// Use the services to create contexts
const db = Context.make(Database, {
query: (sql) => `Result: ${sql}`
})
const config = Context.make(Config, { port: 8080 })
Namespace containing utility types for Context service keys.
Example (Extracting service types)
import { Context } from "effect"
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Extract service type from a key
type DatabaseService = Context.Service.Shape<typeof Database>
// Extract identifier type from a key
type DatabaseId = Context.Service.Identifier<typeof Database>
Service<function (type parameter) Identifier in <Identifier, Shape = Identifier>(key: string): Service<Identifier, Shape>Identifier, function (type parameter) Shape in <Identifier, Shape = Identifier>(key: string): Service<Identifier, Shape>Shape>
<function (type parameter) Self in <Self, Shape>(): <const 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, function (type parameter) Shape in <Self, Shape>(): <const 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>;
})
Shape>(): <
const function (type parameter) Identifier in <const 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>;
})
Identifier extends string,
function (type parameter) E in <const 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>;
})
E,
function (type parameter) R in <const 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>;
})
R = import TypesTypes.unassigned,
function (type parameter) Args in <const 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>;
})
Args extends interface ReadonlyArray<T>ReadonlyArray<any> = never
>(
id: const Identifier extends stringid: function (type parameter) Identifier in <const 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>;
})
Identifier,
options: | {
readonly make:
| ((...args: Args) => Effect<Shape, E, R>)
| Effect<Shape, E, R>
| undefined
}
| undefined
options?: {
readonly make: | ((...args: Args) => Effect<Shape, E, R>)
| Effect<Shape, E, R>
| undefined
make: ((...args: Args extends ReadonlyArray<any> = neverargs: function (type parameter) Args in <const 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>;
})
Args) => 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<function (type parameter) Shape in <Self, Shape>(): <const 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>;
})
Shape, function (type parameter) E in <const 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>;
})
E, function (type parameter) R in <const 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>;
})
R>) | 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<function (type parameter) Shape in <Self, Shape>(): <const 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>;
})
Shape, function (type parameter) E in <const 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>;
})
E, function (type parameter) R in <const 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>;
})
R> | undefined
} | undefined
) =>
& 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 <Self, Shape>(): <const 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, function (type parameter) Identifier in <const 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>;
})
Identifier, function (type parameter) Shape in <Self, Shape>(): <const 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>;
})
Shape>
& ([import TypesTypes.unassigned] extends [function (type parameter) R in <const 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>;
})
R] ? unknown
: { readonly make: [Args] extends [never]
? Effect<Shape, E, R>
: (...args: Args) => Effect<Shape, E, R>
make: [function (type parameter) Args in <const 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>;
})
Args] extends [never] ? 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<function (type parameter) Shape in <Self, Shape>(): <const 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>;
})
Shape, function (type parameter) E in <const 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>;
})
E, function (type parameter) R in <const 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>;
})
R> : (...args: Args extends ReadonlyArray<any> = neverargs: function (type parameter) Args in <const 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>;
})
Args) => 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<function (type parameter) Shape in <Self, Shape>(): <const 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>;
})
Shape, function (type parameter) E in <const 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>;
})
E, function (type parameter) R in <const 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>;
})
R> })
<function (type parameter) Self in <Self>(): <const 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;
}
Self>(): <
const function (type parameter) Identifier in <const 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;
}
Identifier extends string,
function (type parameter) Make in <const 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;
}
Make extends 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<any, any, any> | ((...args: anyargs: any) => 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<any, any, any>)
>(
id: const Identifier extends stringid: function (type parameter) Identifier in <const 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;
}
Identifier,
options: {
readonly make: Make
}
options: {
readonly make: Make extends Effect<any, any, any> | ((...args: any) => Effect<any, any, any>)make: function (type parameter) Make in <const 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;
}
Make
}
) =>
& 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 <Self>(): <const 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;
}
Self,
function (type parameter) Identifier in <const 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;
}
Identifier,
function (type parameter) Make in <const 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;
}
Make extends
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<infer function (type parameter) _A_A, infer function (type parameter) _E_E, infer function (type parameter) _R_R> | ((...args: _Args extends unknown[]args: infer function (type parameter) _Args_Args) => 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<infer function (type parameter) _A_A, infer function (type parameter) _E_E, infer function (type parameter) _R_R>) ? function (type parameter) _A_A
: never
>
& { readonly make: Make extends Effect<any, any, any> | ((...args: any) => Effect<any, any, any>)make: function (type parameter) Make in <const 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;
}
Make }
} = function() {
const const prevLimit: number | undefinedprevLimit = 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 err: Errorconst err: {
name: string;
message: string;
stack: string;
cause: unknown;
}
err = new var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error()
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 prevLimit: number | undefinedprevLimit)
function function (local function) KeyClass(): voidKeyClass() {}
const const self: Types.Mutable<Reference<any>>const self: {
defaultValue: () => any;
of: (this: void, self: any) => any;
context: (self: any) => Context<never>;
use: (f: (service: any) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: any) => A) => Effect<A, never, never>;
Identifier: never;
Service: any;
key: string;
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;
}
self = function (local function) KeyClass(): voidKeyClass as any as import TypesTypes.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 Reference<in out Shape>Service key with a lazily computed default value.
Details
When a Reference is requested from a Context that does not contain an
override, Context getters that resolve references return the cached default
value instead of failing.
Example (Defining a reference with a default value)
import { Context } from "effect"
// Define a reference with a default value
const LoggerRef: Context.Reference<{ log: (msg: string) => void }> =
Context.Reference("Logger", {
defaultValue: () => ({ log: (msg: string) => console.log(msg) })
})
// The reference can be used without explicit provision
const context = Context.empty()
const logger = Context.get(context, LoggerRef) // Uses default value
Creates a context key with a default value.
When to use
Use when you need to define a context key with a lazily computed default
value.
Details
Context.Reference allows you to create a key that can hold a value. You
can provide a default value for the service, which will automatically be used
when the context is accessed, or override it with a custom implementation
when needed. The default value is computed lazily and cached on the
reference.
Example (Creating references with default values)
import { Context } from "effect"
// Create a reference with a default value
const LoggerRef = Context.Reference("Logger", {
defaultValue: () => ({ log: (msg: string) => console.log(msg) })
})
// The reference provides the default value when accessed from an empty context
const context = Context.empty()
const logger = Context.get(context, LoggerRef)
// You can also override the default value
const customContext = Context.make(LoggerRef, {
log: (msg: string) => `Custom: ${msg}`
})
const customLogger = Context.get(customContext, LoggerRef)
Reference<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(const self: Types.Mutable<Reference<any>>const self: {
defaultValue: () => any;
of: (this: void, self: any) => any;
context: (self: any) => Context<never>;
use: (f: (service: any) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: any) => A) => Effect<A, never, never>;
Identifier: never;
Service: any;
key: string;
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;
}
self, const ServiceProto: anyServiceProto)
// @effect-diagnostics-next-line floatingEffect:off
var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.defineProperty<Types.Mutable<Reference<any>>>(o: Types.Mutable<Reference<any>>, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>): Types.Mutable<Reference<any>>Adds a property to an object, or modifies attributes of an existing property.
defineProperty(const self: Types.Mutable<Reference<any>>const self: {
defaultValue: () => any;
of: (this: void, self: any) => any;
context: (self: any) => Context<never>;
use: (f: (service: any) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: any) => A) => Effect<A, never, never>;
Identifier: never;
Service: any;
key: string;
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;
}
self, "stack", {
PropertyDescriptor.get?(): anyget() {
return const err: Errorconst err: {
name: string;
message: string;
stack: string;
cause: unknown;
}
err.Error.stack?: string | undefinedstack
}
})
if (function (local var) arguments: IArgumentsarguments.IArguments.length: numberlength > 0) {
const self: Types.Mutable<Reference<any>>const self: {
defaultValue: () => any;
of: (this: void, self: any) => any;
context: (self: any) => Context<never>;
use: (f: (service: any) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: any) => A) => Effect<A, never, never>;
Identifier: never;
Service: any;
key: string;
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;
}
self.key: stringkey = function (local var) arguments: IArgumentsarguments[0]
if (function (local var) arguments: IArgumentsarguments[1]?.defaultValue) {
const self: Types.Mutable<Reference<any>>const self: {
defaultValue: () => any;
of: (this: void, self: any) => any;
context: (self: any) => Context<never>;
use: (f: (service: any) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: any) => A) => Effect<A, never, never>;
Identifier: never;
Service: any;
key: string;
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;
}
self[const ReferenceTypeId: "~effect/Context/Reference"ReferenceTypeId] = const ReferenceTypeId: "~effect/Context/Reference"ReferenceTypeId
const self: Types.Mutable<Reference<any>>const self: {
defaultValue: () => any;
of: (this: void, self: any) => any;
context: (self: any) => Context<never>;
use: (f: (service: any) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: any) => A) => Effect<A, never, never>;
Identifier: never;
Service: any;
key: string;
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;
}
self.defaultValue: () => anydefaultValue = function (local var) arguments: IArgumentsarguments[1].defaultValue
}
return const self: Types.Mutable<Reference<any>>const self: {
defaultValue: () => any;
of: (this: void, self: any) => any;
context: (self: any) => Context<never>;
use: (f: (service: any) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: any) => A) => Effect<A, never, never>;
Identifier: never;
Service: any;
key: string;
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;
}
self
}
return function(key: stringkey: string, options: | {
readonly make?: any
}
| undefined
options?: {
readonly make?: anymake?: any
}) {
const self: Types.Mutable<Reference<any>>const self: {
defaultValue: () => any;
of: (this: void, self: any) => any;
context: (self: any) => Context<never>;
use: (f: (service: any) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: any) => A) => Effect<A, never, never>;
Identifier: never;
Service: any;
key: string;
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;
}
self.key: stringkey = key: stringkey
if (options: | {
readonly make?: any
}
| undefined
options?.make?: anymake) {
;(const self: Types.Mutable<Reference<any>>const self: {
defaultValue: () => any;
of: (this: void, self: any) => any;
context: (self: any) => Context<never>;
use: (f: (service: any) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: any) => A) => Effect<A, never, never>;
Identifier: never;
Service: any;
key: string;
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;
}
self as any).make = options: {
readonly make?: any
}
options.make?: anymake
}
return const self: Types.Mutable<Reference<any>>const self: {
defaultValue: () => any;
of: (this: void, self: any) => any;
context: (self: any) => Context<never>;
use: (f: (service: any) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: any) => A) => Effect<A, never, never>;
Identifier: never;
Service: any;
key: string;
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;
}
self
}
} as any
const const ServiceProto: anyServiceProto: any = {
[const ServiceTypeId: ServiceTypeIdString literal type used as the runtime type identifier for Context
service keys.
Runtime type identifier attached to Context service keys and used by
isKey to recognize them.
ServiceTypeId]: const ServiceTypeId: ServiceTypeIdString literal type used as the runtime type identifier for Context
service keys.
Runtime type identifier attached to Context service keys and used by
isKey to recognize them.
ServiceTypeId,
...import EffectableEffectable.const Prototype: <
A extends Effect.Effect<any, any, any>
>(options: {
readonly label: string
readonly evaluate: (
this: A,
fiber: Fiber.Fiber<any, any>
) => Effect.Effect<
Effect.Success<A>,
Effect.Error<A>,
Effect.Services<A>
>
}) => Effect.Effect<
Effect.Success<A>,
Effect.Error<A>,
Effect.Services<A>
>
Create a low-level Effect prototype.
When to use
Use when you need to create a custom Effect-like value without extending a
class, by providing a label and an evaluate function that receives the
current fiber.
Details
When the effect is evaluated, it calls evaluate with the current fiber.
Prototype<interface Service<in out Identifier, in out Shape>Context key with helper methods for working with a service.
Details
context creates a one-service Context, use and useSync retrieve the
service from the current Effect context before applying a function, and of
is a type-level helper for service values.
Example (Defining a service key)
import { Context } from "effect"
// Define an identifier for a database service
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// The key can be used to store and retrieve services
const context = Context.make(Database, { query: (sql) => `Result: ${sql}` })
Creates a Context service key.
When to use
Use when you need to define a context service key for a dependency that must
be provided by the surrounding context.
Details
Call Context.Service("Key") for a function-style key, or use the two-stage
form Context.Service<Self, Shape>()("Key") for class-style service
declarations. The returned key can be yielded as an Effect and passed to
Context.make, Context.add, and the Context getter functions.
Gotchas
The string key is the runtime identity of the service. Reusing the same key
string for unrelated services makes them occupy the same slot in a
Context.
Example (Creating service keys)
import { Context } from "effect"
// Create a simple service
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Create a service class
class Config extends Context.Service<Config, {
port: number
}>()("Config") {}
// Use the services to create contexts
const db = Context.make(Database, {
query: (sql) => `Result: ${sql}`
})
const config = Context.make(Config, { port: 8080 })
Namespace containing utility types for Context service keys.
Example (Extracting service types)
import { Context } from "effect"
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Extract service type from a key
type DatabaseService = Context.Service.Shape<typeof Database>
// Extract identifier type from a key
type DatabaseId = Context.Service.Identifier<typeof Database>
Service<never, any>>({
label: stringlabel: "Service",
evaluate: (
this: Service<never, any>,
fiber: Fiber<any, any>
) => Effect<any, never, never>
evaluate(fiber: Fiber<any, any>(parameter) fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | 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; <…;
}
fiber) {
return exitSucceed<A>(a: A): Exit.Exit<A>exitSucceed(const get: {
<Services, I extends Services, S>(
service: Key<I, S>
): (self: Context<Services>) => S
<Services, I extends Services, S>(
self: Context<Services>,
service: Key<I, S>
): S
}
get(fiber: Fiber<any, any>(parameter) fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | 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; <…;
}
fiber.Fiber<out A, out E = never>.context: Context.Context<never>(property) Fiber<out A, out E = never>.context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
context, this))
}
}),
toJSON<I, A>(this: Service<I, A>): { _id: string; key: string; stack: string | undefined }toJSON<function (type parameter) I in toJSON<I, A>(this: Service<I, A>): {
_id: string;
key: string;
stack: string | undefined;
}
I, function (type parameter) A in toJSON<I, A>(this: Service<I, A>): {
_id: string;
key: string;
stack: string | undefined;
}
A>(this: Service<I, A>(parameter) this: {
of: (this: void, self: A) => A;
context: (self: A) => Context<I>;
use: (f: (service: A) => Effect<A, E, R>) => Effect<A, E, I | R>;
useSync: (f: (service: A) => A) => Effect<A, never, I>;
Identifier: Identifier;
Service: Shape;
key: string;
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;
}
this: interface Service<in out Identifier, in out Shape>Context key with helper methods for working with a service.
Details
context creates a one-service Context, use and useSync retrieve the
service from the current Effect context before applying a function, and of
is a type-level helper for service values.
Example (Defining a service key)
import { Context } from "effect"
// Define an identifier for a database service
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// The key can be used to store and retrieve services
const context = Context.make(Database, { query: (sql) => `Result: ${sql}` })
Creates a Context service key.
When to use
Use when you need to define a context service key for a dependency that must
be provided by the surrounding context.
Details
Call Context.Service("Key") for a function-style key, or use the two-stage
form Context.Service<Self, Shape>()("Key") for class-style service
declarations. The returned key can be yielded as an Effect and passed to
Context.make, Context.add, and the Context getter functions.
Gotchas
The string key is the runtime identity of the service. Reusing the same key
string for unrelated services makes them occupy the same slot in a
Context.
Example (Creating service keys)
import { Context } from "effect"
// Create a simple service
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Create a service class
class Config extends Context.Service<Config, {
port: number
}>()("Config") {}
// Use the services to create contexts
const db = Context.make(Database, {
query: (sql) => `Result: ${sql}`
})
const config = Context.make(Config, { port: 8080 })
Namespace containing utility types for Context service keys.
Example (Extracting service types)
import { Context } from "effect"
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Extract service type from a key
type DatabaseService = Context.Service.Shape<typeof Database>
// Extract identifier type from a key
type DatabaseId = Context.Service.Identifier<typeof Database>
Service<function (type parameter) I in toJSON<I, A>(this: Service<I, A>): {
_id: string;
key: string;
stack: string | undefined;
}
I, function (type parameter) A in toJSON<I, A>(this: Service<I, A>): {
_id: string;
key: string;
stack: string | undefined;
}
A>) {
return {
_id: string_id: "Service",
key: stringkey: this.Key<out Identifier, out Shape>.key: stringkey,
stack: string | undefinedstack: this.Key<out Identifier, out Shape>.stack?: string | undefinedstack
}
},
of<Service>(this: void, self: Service): Serviceof<function (type parameter) Service in of<Service>(this: void, self: Service): ServiceService>(this: voidthis: void, self: Serviceself: function (type parameter) Service in of<Service>(this: void, self: Service): ServiceService): function (type parameter) Service in of<Service>(this: void, self: Service): ServiceService {
return self: Serviceself
},
context<Identifier, Shape>(this: Service<Identifier, Shape>, self: Shape): Context<Identifier>context<function (type parameter) Identifier in context<Identifier, Shape>(this: Service<Identifier, Shape>, self: Shape): Context<Identifier>Identifier, function (type parameter) Shape in context<Identifier, Shape>(this: Service<Identifier, Shape>, self: Shape): Context<Identifier>Shape>(
this: Service<Identifier, Shape>(parameter) this: {
of: (this: void, self: Shape) => Shape;
context: (self: Shape) => Context<Identifier>;
use: (f: (service: Shape) => Effect<A, E, R>) => Effect<A, E, Identifier | R>;
useSync: (f: (service: Shape) => A) => Effect<A, never, Identifier>;
Identifier: Identifier;
Service: Shape;
key: string;
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;
}
this: interface Service<in out Identifier, in out Shape>Context key with helper methods for working with a service.
Details
context creates a one-service Context, use and useSync retrieve the
service from the current Effect context before applying a function, and of
is a type-level helper for service values.
Example (Defining a service key)
import { Context } from "effect"
// Define an identifier for a database service
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// The key can be used to store and retrieve services
const context = Context.make(Database, { query: (sql) => `Result: ${sql}` })
Creates a Context service key.
When to use
Use when you need to define a context service key for a dependency that must
be provided by the surrounding context.
Details
Call Context.Service("Key") for a function-style key, or use the two-stage
form Context.Service<Self, Shape>()("Key") for class-style service
declarations. The returned key can be yielded as an Effect and passed to
Context.make, Context.add, and the Context getter functions.
Gotchas
The string key is the runtime identity of the service. Reusing the same key
string for unrelated services makes them occupy the same slot in a
Context.
Example (Creating service keys)
import { Context } from "effect"
// Create a simple service
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Create a service class
class Config extends Context.Service<Config, {
port: number
}>()("Config") {}
// Use the services to create contexts
const db = Context.make(Database, {
query: (sql) => `Result: ${sql}`
})
const config = Context.make(Config, { port: 8080 })
Namespace containing utility types for Context service keys.
Example (Extracting service types)
import { Context } from "effect"
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Extract service type from a key
type DatabaseService = Context.Service.Shape<typeof Database>
// Extract identifier type from a key
type DatabaseId = Context.Service.Identifier<typeof Database>
Service<function (type parameter) Identifier in context<Identifier, Shape>(this: Service<Identifier, Shape>, self: Shape): Context<Identifier>Identifier, function (type parameter) Shape in context<Identifier, Shape>(this: Service<Identifier, Shape>, self: Shape): Context<Identifier>Shape>,
self: Shapeself: function (type parameter) Shape in context<Identifier, Shape>(this: Service<Identifier, Shape>, self: Shape): Context<Identifier>Shape
): 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) Identifier in context<Identifier, Shape>(this: Service<Identifier, Shape>, self: Shape): Context<Identifier>Identifier> {
return const make: <I, S>(
key: Key<I, S>,
service: Types.NoInfer<S>
) => Context<I>
Creates a new Context with a single service associated to the key.
Example (Creating a context with one service)
import { Context } from "effect"
import * as assert from "node:assert"
const Port = Context.Service<{ PORT: number }>("Port")
const context = Context.make(Port, { PORT: 8080 })
assert.deepStrictEqual(Context.get(context, Port), { PORT: 8080 })
make(this, self: Shapeself)
},
use<A, E, R>(this: Service<never, any>, f: (service: any) => Effect<A, E, R>): Effect<A, E, R>use<function (type parameter) A in use<A, E, R>(this: Service<never, any>, f: (service: any) => Effect<A, E, R>): Effect<A, E, R>A, function (type parameter) E in use<A, E, R>(this: Service<never, any>, f: (service: any) => Effect<A, E, R>): Effect<A, E, R>E, function (type parameter) R in use<A, E, R>(this: Service<never, any>, f: (service: any) => Effect<A, E, R>): Effect<A, E, R>R>(this: Service<never, any>(parameter) this: {
of: (this: void, self: any) => any;
context: (self: any) => Context<never>;
use: (f: (service: any) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: any) => A) => Effect<A, never, never>;
Identifier: Identifier;
Service: Shape;
key: string;
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;
}
this: interface Service<in out Identifier, in out Shape>Context key with helper methods for working with a service.
Details
context creates a one-service Context, use and useSync retrieve the
service from the current Effect context before applying a function, and of
is a type-level helper for service values.
Example (Defining a service key)
import { Context } from "effect"
// Define an identifier for a database service
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// The key can be used to store and retrieve services
const context = Context.make(Database, { query: (sql) => `Result: ${sql}` })
Creates a Context service key.
When to use
Use when you need to define a context service key for a dependency that must
be provided by the surrounding context.
Details
Call Context.Service("Key") for a function-style key, or use the two-stage
form Context.Service<Self, Shape>()("Key") for class-style service
declarations. The returned key can be yielded as an Effect and passed to
Context.make, Context.add, and the Context getter functions.
Gotchas
The string key is the runtime identity of the service. Reusing the same key
string for unrelated services makes them occupy the same slot in a
Context.
Example (Creating service keys)
import { Context } from "effect"
// Create a simple service
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Create a service class
class Config extends Context.Service<Config, {
port: number
}>()("Config") {}
// Use the services to create contexts
const db = Context.make(Database, {
query: (sql) => `Result: ${sql}`
})
const config = Context.make(Config, { port: 8080 })
Namespace containing utility types for Context service keys.
Example (Extracting service types)
import { Context } from "effect"
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Extract service type from a key
type DatabaseService = Context.Service.Shape<typeof Database>
// Extract identifier type from a key
type DatabaseId = Context.Service.Identifier<typeof Database>
Service<never, any>, f: (service: any) => Effect<A, E, R>f: (service: anyservice: any) => 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<function (type parameter) A in use<A, E, R>(this: Service<never, any>, f: (service: any) => Effect<A, E, R>): Effect<A, E, R>A, function (type parameter) E in use<A, E, R>(this: Service<never, any>, f: (service: any) => Effect<A, E, R>): Effect<A, E, R>E, function (type parameter) R in use<A, E, R>(this: Service<never, any>, f: (service: any) => Effect<A, E, R>): Effect<A, E, R>R>): 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<function (type parameter) A in use<A, E, R>(this: Service<never, any>, f: (service: any) => Effect<A, E, R>): Effect<A, E, R>A, function (type parameter) E in use<A, E, R>(this: Service<never, any>, f: (service: any) => Effect<A, E, R>): Effect<A, E, R>E, function (type parameter) R in use<A, E, R>(this: Service<never, any>, f: (service: any) => Effect<A, E, R>): Effect<A, E, R>R> {
return withFiber<A, E = never, R = never>(evaluate: (fiber: FiberImpl<unknown, unknown>) => Effect.Effect<A, E, R>): Effect.Effect<A, E, R>withFiber((fiber: FiberImpl<unknown, unknown>(parameter) fiber: {
id: number;
interruptible: boolean;
currentOpCount: number;
currentLoopCount: number;
_stack: Array<Primitive>;
_observers: Array<(exit: Exit.Exit<A, E>) => void>;
_exit: Exit.Exit<A, E> | undefined;
_currentExit: Exit.Exit<A, E> | undefined;
_children: Set<FiberImpl<any, any>> | undefined;
_interruptedCause: Cause.Cause<never> | undefined;
_yielded: Exit.Exit<any, any> | (() => void) | undefined;
context: Context.Context<never>;
currentScheduler: Scheduler.Scheduler;
currentTracerContext: Tracer.Tracer["context"];
currentSpan: Tracer.AnySpan | undefined;
currentLogLevel: LogLevel.LogLevel;
minimumLogLevel: LogLevel.LogLevel;
currentStackFrame: StackFrame | undefined;
runtimeMetrics: Metric.FiberRuntimeMetricsService | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
_dispatcher: Scheduler.SchedulerDispatcher | undefined;
currentDispatcher: SchedulerDispatcher;
getRef: <X>(ref: Context.Reference<X>) => X;
addObserver: (cb: (exit: Exit<unknown, unknown>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<unknown, unknown> | undefined;
evaluate: (effect: Primitive) => void;
runLoop: (effect: Primitive) => Exit<unknown, unknown> | typeof Yield;
getCont: <S extends contA | contE>(symbol: S) => (Primitive & Record<S, (value: any, fiber: FiberImpl) => Primitive>) | undefined;
yieldWith: (value: Exit.Exit<any, any> | (() => void)) => Yield;
children: () => Set<Fiber.Fiber<any, any>>;
pipe: () => unknown;
setContext: (context: Context.Context<never>) => void;
currentSpanLocal: Span | undefined;
}
fiber) => f: (service: any) => Effect<A, E, R>f(const get: {
<Services, I extends Services, S>(
service: Key<I, S>
): (self: Context<Services>) => S
<Services, I extends Services, S>(
self: Context<Services>,
service: Key<I, S>
): S
}
get(fiber: FiberImpl<unknown, unknown>(parameter) fiber: {
id: number;
interruptible: boolean;
currentOpCount: number;
currentLoopCount: number;
_stack: Array<Primitive>;
_observers: Array<(exit: Exit.Exit<A, E>) => void>;
_exit: Exit.Exit<A, E> | undefined;
_currentExit: Exit.Exit<A, E> | undefined;
_children: Set<FiberImpl<any, any>> | undefined;
_interruptedCause: Cause.Cause<never> | undefined;
_yielded: Exit.Exit<any, any> | (() => void) | undefined;
context: Context.Context<never>;
currentScheduler: Scheduler.Scheduler;
currentTracerContext: Tracer.Tracer["context"];
currentSpan: Tracer.AnySpan | undefined;
currentLogLevel: LogLevel.LogLevel;
minimumLogLevel: LogLevel.LogLevel;
currentStackFrame: StackFrame | undefined;
runtimeMetrics: Metric.FiberRuntimeMetricsService | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
_dispatcher: Scheduler.SchedulerDispatcher | undefined;
currentDispatcher: SchedulerDispatcher;
getRef: <X>(ref: Context.Reference<X>) => X;
addObserver: (cb: (exit: Exit<unknown, unknown>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<unknown, unknown> | undefined;
evaluate: (effect: Primitive) => void;
runLoop: (effect: Primitive) => Exit<unknown, unknown> | typeof Yield;
getCont: <S extends contA | contE>(symbol: S) => (Primitive & Record<S, (value: any, fiber: FiberImpl) => Primitive>) | undefined;
yieldWith: (value: Exit.Exit<any, any> | (() => void)) => Yield;
children: () => Set<Fiber.Fiber<any, any>>;
pipe: () => unknown;
setContext: (context: Context.Context<never>) => void;
currentSpanLocal: Span | undefined;
}
fiber.FiberImpl<unknown, unknown>.context: Context.Context<never>(property) FiberImpl<unknown, unknown>.context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
context, this)))
},
useSync<A>(this: Service<never, any>, f: (service: any) => A): Effect<A, never, never>useSync<function (type parameter) A in useSync<A>(this: Service<never, any>, f: (service: any) => A): Effect<A, never, never>A>(this: Service<never, any>(parameter) this: {
of: (this: void, self: any) => any;
context: (self: any) => Context<never>;
use: (f: (service: any) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: any) => A) => Effect<A, never, never>;
Identifier: Identifier;
Service: Shape;
key: string;
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;
}
this: interface Service<in out Identifier, in out Shape>Context key with helper methods for working with a service.
Details
context creates a one-service Context, use and useSync retrieve the
service from the current Effect context before applying a function, and of
is a type-level helper for service values.
Example (Defining a service key)
import { Context } from "effect"
// Define an identifier for a database service
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// The key can be used to store and retrieve services
const context = Context.make(Database, { query: (sql) => `Result: ${sql}` })
Creates a Context service key.
When to use
Use when you need to define a context service key for a dependency that must
be provided by the surrounding context.
Details
Call Context.Service("Key") for a function-style key, or use the two-stage
form Context.Service<Self, Shape>()("Key") for class-style service
declarations. The returned key can be yielded as an Effect and passed to
Context.make, Context.add, and the Context getter functions.
Gotchas
The string key is the runtime identity of the service. Reusing the same key
string for unrelated services makes them occupy the same slot in a
Context.
Example (Creating service keys)
import { Context } from "effect"
// Create a simple service
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Create a service class
class Config extends Context.Service<Config, {
port: number
}>()("Config") {}
// Use the services to create contexts
const db = Context.make(Database, {
query: (sql) => `Result: ${sql}`
})
const config = Context.make(Config, { port: 8080 })
Namespace containing utility types for Context service keys.
Example (Extracting service types)
import { Context } from "effect"
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Extract service type from a key
type DatabaseService = Context.Service.Shape<typeof Database>
// Extract identifier type from a key
type DatabaseId = Context.Service.Identifier<typeof Database>
Service<never, any>, f: (service: any) => Af: (service: anyservice: any) => function (type parameter) A in useSync<A>(this: Service<never, any>, f: (service: any) => A): Effect<A, never, never>A): 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<function (type parameter) A in useSync<A>(this: Service<never, any>, f: (service: any) => A): Effect<A, never, never>A, never, never> {
return withFiber<A, E = never, R = never>(evaluate: (fiber: FiberImpl<unknown, unknown>) => Effect.Effect<A, E, R>): Effect.Effect<A, E, R>withFiber((fiber: FiberImpl<unknown, unknown>(parameter) fiber: {
id: number;
interruptible: boolean;
currentOpCount: number;
currentLoopCount: number;
_stack: Array<Primitive>;
_observers: Array<(exit: Exit.Exit<A, E>) => void>;
_exit: Exit.Exit<A, E> | undefined;
_currentExit: Exit.Exit<A, E> | undefined;
_children: Set<FiberImpl<any, any>> | undefined;
_interruptedCause: Cause.Cause<never> | undefined;
_yielded: Exit.Exit<any, any> | (() => void) | undefined;
context: Context.Context<never>;
currentScheduler: Scheduler.Scheduler;
currentTracerContext: Tracer.Tracer["context"];
currentSpan: Tracer.AnySpan | undefined;
currentLogLevel: LogLevel.LogLevel;
minimumLogLevel: LogLevel.LogLevel;
currentStackFrame: StackFrame | undefined;
runtimeMetrics: Metric.FiberRuntimeMetricsService | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
_dispatcher: Scheduler.SchedulerDispatcher | undefined;
currentDispatcher: SchedulerDispatcher;
getRef: <X>(ref: Context.Reference<X>) => X;
addObserver: (cb: (exit: Exit<unknown, unknown>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<unknown, unknown> | undefined;
evaluate: (effect: Primitive) => void;
runLoop: (effect: Primitive) => Exit<unknown, unknown> | typeof Yield;
getCont: <S extends contA | contE>(symbol: S) => (Primitive & Record<S, (value: any, fiber: FiberImpl) => Primitive>) | undefined;
yieldWith: (value: Exit.Exit<any, any> | (() => void)) => Yield;
children: () => Set<Fiber.Fiber<any, any>>;
pipe: () => unknown;
setContext: (context: Context.Context<never>) => void;
currentSpanLocal: Span | undefined;
}
fiber) => exitSucceed<A>(a: A): Exit.Exit<A>exitSucceed(f: (service: any) => Af(const get: {
<Services, I extends Services, S>(
service: Key<I, S>
): (self: Context<Services>) => S
<Services, I extends Services, S>(
self: Context<Services>,
service: Key<I, S>
): S
}
get(fiber: FiberImpl<unknown, unknown>(parameter) fiber: {
id: number;
interruptible: boolean;
currentOpCount: number;
currentLoopCount: number;
_stack: Array<Primitive>;
_observers: Array<(exit: Exit.Exit<A, E>) => void>;
_exit: Exit.Exit<A, E> | undefined;
_currentExit: Exit.Exit<A, E> | undefined;
_children: Set<FiberImpl<any, any>> | undefined;
_interruptedCause: Cause.Cause<never> | undefined;
_yielded: Exit.Exit<any, any> | (() => void) | undefined;
context: Context.Context<never>;
currentScheduler: Scheduler.Scheduler;
currentTracerContext: Tracer.Tracer["context"];
currentSpan: Tracer.AnySpan | undefined;
currentLogLevel: LogLevel.LogLevel;
minimumLogLevel: LogLevel.LogLevel;
currentStackFrame: StackFrame | undefined;
runtimeMetrics: Metric.FiberRuntimeMetricsService | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
_dispatcher: Scheduler.SchedulerDispatcher | undefined;
currentDispatcher: SchedulerDispatcher;
getRef: <X>(ref: Context.Reference<X>) => X;
addObserver: (cb: (exit: Exit<unknown, unknown>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<unknown, unknown> | undefined;
evaluate: (effect: Primitive) => void;
runLoop: (effect: Primitive) => Exit<unknown, unknown> | typeof Yield;
getCont: <S extends contA | contE>(symbol: S) => (Primitive & Record<S, (value: any, fiber: FiberImpl) => Primitive>) | undefined;
yieldWith: (value: Exit.Exit<any, any> | (() => void)) => Yield;
children: () => Set<Fiber.Fiber<any, any>>;
pipe: () => unknown;
setContext: (context: Context.Context<never>) => void;
currentSpanLocal: Span | undefined;
}
fiber.FiberImpl<unknown, unknown>.context: Context.Context<never>(property) FiberImpl<unknown, unknown>.context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
context, this))))
}
}
const const ReferenceTypeId: "~effect/Context/Reference"ReferenceTypeId = "~effect/Context/Reference" as type const = "~effect/Context/Reference"const
/**
* Service key with a lazily computed default value.
*
* **Details**
*
* When a `Reference` is requested from a `Context` that does not contain an
* override, Context getters that resolve references return the cached default
* value instead of failing.
*
* **Example** (Defining a reference with a default value)
*
* ```ts
* import { Context } from "effect"
*
* // Define a reference with a default value
* const LoggerRef: Context.Reference<{ log: (msg: string) => void }> =
* Context.Reference("Logger", {
* defaultValue: () => ({ log: (msg: string) => console.log(msg) })
* })
*
* // The reference can be used without explicit provision
* const context = Context.empty()
* const logger = Context.get(context, LoggerRef) // Uses default value
* ```
*
* @category models
* @since 3.11.0
*/
export interface interface Reference<in out Shape>Service key with a lazily computed default value.
Details
When a Reference is requested from a Context that does not contain an
override, Context getters that resolve references return the cached default
value instead of failing.
Example (Defining a reference with a default value)
import { Context } from "effect"
// Define a reference with a default value
const LoggerRef: Context.Reference<{ log: (msg: string) => void }> =
Context.Reference("Logger", {
defaultValue: () => ({ log: (msg: string) => console.log(msg) })
})
// The reference can be used without explicit provision
const context = Context.empty()
const logger = Context.get(context, LoggerRef) // Uses default value
Creates a context key with a default value.
When to use
Use when you need to define a context key with a lazily computed default
value.
Details
Context.Reference allows you to create a key that can hold a value. You
can provide a default value for the service, which will automatically be used
when the context is accessed, or override it with a custom implementation
when needed. The default value is computed lazily and cached on the
reference.
Example (Creating references with default values)
import { Context } from "effect"
// Create a reference with a default value
const LoggerRef = Context.Reference("Logger", {
defaultValue: () => ({ log: (msg: string) => console.log(msg) })
})
// The reference provides the default value when accessed from an empty context
const context = Context.empty()
const logger = Context.get(context, LoggerRef)
// You can also override the default value
const customContext = Context.make(LoggerRef, {
log: (msg: string) => `Custom: ${msg}`
})
const customLogger = Context.get(customContext, LoggerRef)
Reference<in out function (type parameter) Shape in Reference<in out Shape>Shape> extends interface Service<in out Identifier, in out Shape>Context key with helper methods for working with a service.
Details
context creates a one-service Context, use and useSync retrieve the
service from the current Effect context before applying a function, and of
is a type-level helper for service values.
Example (Defining a service key)
import { Context } from "effect"
// Define an identifier for a database service
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// The key can be used to store and retrieve services
const context = Context.make(Database, { query: (sql) => `Result: ${sql}` })
Creates a Context service key.
When to use
Use when you need to define a context service key for a dependency that must
be provided by the surrounding context.
Details
Call Context.Service("Key") for a function-style key, or use the two-stage
form Context.Service<Self, Shape>()("Key") for class-style service
declarations. The returned key can be yielded as an Effect and passed to
Context.make, Context.add, and the Context getter functions.
Gotchas
The string key is the runtime identity of the service. Reusing the same key
string for unrelated services makes them occupy the same slot in a
Context.
Example (Creating service keys)
import { Context } from "effect"
// Create a simple service
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Create a service class
class Config extends Context.Service<Config, {
port: number
}>()("Config") {}
// Use the services to create contexts
const db = Context.make(Database, {
query: (sql) => `Result: ${sql}`
})
const config = Context.make(Config, { port: 8080 })
Namespace containing utility types for Context service keys.
Example (Extracting service types)
import { Context } from "effect"
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
// Extract service type from a key
type DatabaseService = Context.Service.Shape<typeof Database>
// Extract identifier type from a key
type DatabaseId = Context.Service.Identifier<typeof Database>
Service<never, function (type parameter) Shape in Reference<in out Shape>Shape> {
readonly [const ReferenceTypeId: "~effect/Context/Reference"ReferenceTypeId]: typeof const ReferenceTypeId: "~effect/Context/Reference"ReferenceTypeId
readonly Reference<in out Shape>.defaultValue: () => ShapedefaultValue: () => function (type parameter) Shape in Reference<in out Shape>Shape
[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator](): interface EffectIterator<T extends Effect<any, any, any>>Iterator interface for Effect generators, enabling Effect values to work with generator functions.
When to use
Use when defining or typing [Symbol.iterator]() for values typed as
Effects so yield* can pass their success type back into Effect.gen.
EffectIterator<interface Reference<in out Shape>Service key with a lazily computed default value.
Details
When a Reference is requested from a Context that does not contain an
override, Context getters that resolve references return the cached default
value instead of failing.
Example (Defining a reference with a default value)
import { Context } from "effect"
// Define a reference with a default value
const LoggerRef: Context.Reference<{ log: (msg: string) => void }> =
Context.Reference("Logger", {
defaultValue: () => ({ log: (msg: string) => console.log(msg) })
})
// The reference can be used without explicit provision
const context = Context.empty()
const logger = Context.get(context, LoggerRef) // Uses default value
Creates a context key with a default value.
When to use
Use when you need to define a context key with a lazily computed default
value.
Details
Context.Reference allows you to create a key that can hold a value. You
can provide a default value for the service, which will automatically be used
when the context is accessed, or override it with a custom implementation
when needed. The default value is computed lazily and cached on the
reference.
Example (Creating references with default values)
import { Context } from "effect"
// Create a reference with a default value
const LoggerRef = Context.Reference("Logger", {
defaultValue: () => ({ log: (msg: string) => console.log(msg) })
})
// The reference provides the default value when accessed from an empty context
const context = Context.empty()
const logger = Context.get(context, LoggerRef)
// You can also override the default value
const customContext = Context.make(LoggerRef, {
log: (msg: string) => `Custom: ${msg}`
})
const customLogger = Context.get(customContext, LoggerRef)
Reference<function (type parameter) Shape in Reference<in out Shape>Shape>>
new(_: never_: never): {}
}
/**
* Namespace containing utility types for `Context` service keys.
*
* **Example** (Extracting service types)
*
* ```ts
* import { Context } from "effect"
*
* const Database = Context.Service<{
* query: (sql: string) => string
* }>("Database")
*
* // Extract service type from a key
* type DatabaseService = Context.Service.Shape<typeof Database>
*
* // Extract identifier type from a key
* type DatabaseId = Context.Service.Identifier<typeof Database>
* ```
*
* @since 2.0.0
*/
export declare namespace Service {
/**
* Type that matches any `Context` service key regardless of its identifier or
* service shape.
*
* **Example** (Typing any service key)
*
* ```ts
* import { Context } from "effect"
*
* // Any represents any possible service type
* const services: Array<Context.Service.Any> = [
* Context.Service<{ log: (msg: string) => void }>("Logger"),
* Context.Service<{ query: (sql: string) => string }>("Database")
* ]
* ```
*
* @category models
* @since 4.0.0
*/
export type type Service<in out Identifier, in out Shape>.Any = Key<never, any> | Key<any, any>Type that matches any Context service key regardless of its identifier or
service shape.
Example (Typing any service key)
import { Context } from "effect"
// Any represents any possible service type
const services: Array<Context.Service.Any> = [
Context.Service<{ log: (msg: string) => void }>("Logger"),
Context.Service<{ query: (sql: string) => string }>("Database")
]
Any = interface Key<out Identifier, out Shape>Typed identifier for a service stored in a Context.
When to use
Use as the typed handle for storing, retrieving, and requiring a specific
service in a Context.
Details
Identifier tracks the requirement in Effect types, while Shape is the
service implementation retrieved by the key. A key is also an Effect value,
so yielding it inside Effect.gen retrieves the service from the current
fiber context.
Key<never, any> | interface Key<out Identifier, out Shape>Typed identifier for a service stored in a Context.
When to use
Use as the typed handle for storing, retrieving, and requiring a specific
service in a Context.
Details
Identifier tracks the requirement in Effect types, while Shape is the
service implementation retrieved by the key. A key is also an Effect value,
so yielding it inside Effect.gen retrieves the service from the current
fiber context.
Key<any, any>
/**
* Extracts the service implementation type stored behind a `Context` service
* key.
*
* **Example** (Extracting a service shape)
*
* ```ts
* import { Context } from "effect"
*
* const Database = Context.Service<{ query: (sql: string) => string }>(
* "Database"
* )
*
* // Extract the service shape from the service
* type DatabaseService = Context.Service.Shape<typeof Database>
* // DatabaseService is { query: (sql: string) => string }
* ```
*
* @category models
* @since 4.0.0
*/
export type type Service<in out Identifier, in out Shape>.Shape<T> = T extends Key<infer _I, infer S> ? S : neverExtracts the service implementation type stored behind a Context service
key.
Example (Extracting a service shape)
import { Context } from "effect"
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// Extract the service shape from the service
type DatabaseService = Context.Service.Shape<typeof Database>
// DatabaseService is { query: (sql: string) => string }
Shape<function (type parameter) T in type Service<in out Identifier, in out Shape>.Shape<T>T> = function (type parameter) T in type Service<in out Identifier, in out Shape>.Shape<T>T extends interface Key<out Identifier, out Shape>Typed identifier for a service stored in a Context.
When to use
Use as the typed handle for storing, retrieving, and requiring a specific
service in a Context.
Details
Identifier tracks the requirement in Effect types, while Shape is the
service implementation retrieved by the key. A key is also an Effect value,
so yielding it inside Effect.gen retrieves the service from the current
fiber context.
Key<infer function (type parameter) _I_I, infer function (type parameter) SS> ? function (type parameter) SS : never
/**
* Extracts the identifier, or requirement type, associated with a `Context`
* service key.
*
* **Example** (Extracting a service identifier)
*
* ```ts
* import { Context } from "effect"
*
* const Database = Context.Service<{ query: (sql: string) => string }>(
* "Database"
* )
*
* // Extract the identifier type from a key
* type DatabaseId = Context.Service.Identifier<typeof Database>
* // DatabaseId is the identifier type
* ```
*
* @category models
* @since 2.0.0
*/
export type type Service<in out Identifier, in out Shape>.Identifier<T> = T extends Key<infer I, infer _S> ? I : neverExtracts the identifier, or requirement type, associated with a Context
service key.
Example (Extracting a service identifier)
import { Context } from "effect"
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
// Extract the identifier type from a key
type DatabaseId = Context.Service.Identifier<typeof Database>
// DatabaseId is the identifier type
Identifier<function (type parameter) T in type Service<in out Identifier, in out Shape>.Identifier<T>T> = function (type parameter) T in type Service<in out Identifier, in out Shape>.Identifier<T>T extends interface Key<out Identifier, out Shape>Typed identifier for a service stored in a Context.
When to use
Use as the typed handle for storing, retrieving, and requiring a specific
service in a Context.
Details
Identifier tracks the requirement in Effect types, while Shape is the
service implementation retrieved by the key. A key is also an Effect value,
so yielding it inside Effect.gen retrieves the service from the current
fiber context.
Key<infer function (type parameter) II, infer function (type parameter) _S_S> ? function (type parameter) II : never
}