(options: Config.Wrap<IoRedis.RedisOptions>): Layer.Layer<
Redis.Redis | NodeRedis,
Config.ConfigError
>Provides Redis and NodeRedis services from Config-backed ioredis
options, closing the client when the layer scope ends.
export const const layerConfig: (
options: Config.Wrap<IoRedis.RedisOptions>
) => Layer.Layer<
Redis.Redis | NodeRedis,
Config.ConfigError
>
Provides Redis and NodeRedis services from Config-backed ioredis
options, closing the client when the layer scope ends.
layerConfig: (
options: Config.Wrap<IoRedis.RedisOptions>(parameter) options: {
parse: (provider: ConfigProvider.ConfigProvider, pathPrefix?: Path) => Effect.Effect<T, ConfigError>;
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;
}
options: import ConfigConfig.type Wrap<A> = [NonNullable<A>] extends [
infer T
]
? [IsPlainObject<T>] extends [true]
?
| Config.Config<A>
| {
readonly [K in keyof A]: Config.Wrap<
A[K]
>
}
: Config.Config<A>
: Config.Config<A>
Utility type that recursively replaces primitives with Config in a nested
structure.
When to use
Use when typing the input of
unwrap
so callers can pass either a Config
or a record of Configs.
Details
Config.Wrap<{ key: string }> becomes { key: Config<string> } | Config<{ key: string }>
Wrap<import IoRedisIoRedis.type IoRedis.RedisOptions = /*unresolved*/ anyRedisOptions>
) => import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<import RedisRedis.class Redisclass Redis {
key: Identifier;
Service: {
send: <A = unknown>(command: string, ...args: ReadonlyArray<string>) => Effect.Effect<A, RedisError>;
eval: <Config extends { readonly params: ReadonlyArray<unknown>; readonly result: unknown }>(script: Script<Config>) => (...params: Config["params"]) => Effect.Effect<Config["result"], RedisError>;
};
}
Service for sending Redis commands and evaluating cached Lua scripts.
Redis | class NodeRedisclass NodeRedis {
key: Identifier;
Service: {
client: IoRedis.Redis;
use: <A>(f: (client: IoRedis.Redis) => Promise<A>) => Effect.Effect<A, Redis.RedisError>;
};
}
Service tag for the Node Redis integration, exposing the underlying
ioredis client and a use helper that maps client failures to
RedisError.
NodeRedis, import ConfigConfig.class ConfigErrorclass ConfigError {
_tag: 'ConfigError';
name: string;
cause: SourceError | Schema.SchemaError;
message: string;
toString: () => string;
}
Represents the error type produced when config loading or validation fails.
When to use
Use when you need to inspect config loading or validation failures.
Details
Wraps either:
- A
SourceError — the provider could not read data (I/O failure).
- A
SchemaError — the data was found but did not match the schema
(wrong type, out of range, missing key, etc.).
ConfigError> = (
options: Config.Wrap<IoRedis.RedisOptions>(parameter) options: {
parse: (provider: ConfigProvider.ConfigProvider, pathPrefix?: Path) => Effect.Effect<T, ConfigError>;
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;
}
options: import ConfigConfig.type Wrap<A> = [NonNullable<A>] extends [
infer T
]
? [IsPlainObject<T>] extends [true]
?
| Config.Config<A>
| {
readonly [K in keyof A]: Config.Wrap<
A[K]
>
}
: Config.Config<A>
: Config.Config<A>
Utility type that recursively replaces primitives with Config in a nested
structure.
When to use
Use when typing the input of
unwrap
so callers can pass either a Config
or a record of Configs.
Details
Config.Wrap<{ key: string }> becomes { key: Config<string> } | Config<{ key: string }>
Wrap<import IoRedisIoRedis.type IoRedis.RedisOptions = /*unresolved*/ anyRedisOptions>
): import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<import RedisRedis.class Redisclass Redis {
key: Identifier;
Service: {
send: <A = unknown>(command: string, ...args: ReadonlyArray<string>) => Effect.Effect<A, RedisError>;
eval: <Config extends { readonly params: ReadonlyArray<unknown>; readonly result: unknown }>(script: Script<Config>) => (...params: Config["params"]) => Effect.Effect<Config["result"], RedisError>;
};
}
Service for sending Redis commands and evaluating cached Lua scripts.
Redis | class NodeRedisclass NodeRedis {
key: Identifier;
Service: {
client: IoRedis.Redis;
use: <A>(f: (client: IoRedis.Redis) => Promise<A>) => Effect.Effect<A, Redis.RedisError>;
};
}
Service tag for the Node Redis integration, exposing the underlying
ioredis client and a use helper that maps client failures to
RedisError.
NodeRedis, import ConfigConfig.class ConfigErrorclass ConfigError {
_tag: 'ConfigError';
name: string;
cause: SourceError | Schema.SchemaError;
message: string;
toString: () => string;
}
Represents the error type produced when config loading or validation fails.
When to use
Use when you need to inspect config loading or validation failures.
Details
Wraps either:
- A
SourceError — the provider could not read data (I/O failure).
- A
SchemaError — the data was found but did not match the schema
(wrong type, out of range, missing key, etc.).
ConfigError> =>
import LayerLayer.const effectContext: <A, E, R>(
effect: Effect<Context.Context<A>, E, R>
) => Layer<A, E, Exclude<R, Scope.Scope>>
Constructs a layer from an effect that produces all services in a Context.
When to use
Use when you need a Layer that effectfully constructs a Context with
multiple services.
Details
This allows you to create a Layer from an effectful computation that
returns multiple services. The Effect is executed in the scope of the
layer.
Example (Creating a layer from an effectful context)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<
Database,
{ readonly query: (sql: string) => Effect.Effect<string> }
>()("Database") {}
const layer = Layer.effectContext(
Effect.succeed(Context.make(Database, {
query: (sql: string) => Effect.succeed(`Query: ${sql}`)
}))
)
effectContext(
import ConfigConfig.const unwrap: <T>(
wrapped: Wrap<T>
) => Config<T>
Constructs a Config<T> from a value matching Wrap<T>.
When to use
Use when accepting config from callers who may pass either a single Config or a
record of individual Configs.
Details
If the input is already a Config, it is returned as-is. Otherwise, each
key is recursively unwrapped and combined.
Example (Unwrapping a record of configs)
import { Config } from "effect"
interface Options {
key: string
}
const makeConfig = (config: Config.Wrap<Options>): Config.Config<Options> =>
Config.unwrap(config)
unwrap(options: Config.Wrap<IoRedis.RedisOptions>(parameter) options: {
parse: (provider: ConfigProvider.ConfigProvider, pathPrefix?: Path) => Effect.Effect<T, ConfigError>;
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;
}
options).Pipeable.pipe<Config.Config<IoRedis.RedisOptions>, Effect.Effect<Context.Context<NodeRedis | Redis.Redis>, Config.ConfigError, Scope.Scope>>(this: Config.Config<IoRedis.RedisOptions>, ab: (_: Config.Config<IoRedis.RedisOptions>) => Effect.Effect<Context.Context<NodeRedis | Redis.Redis>, Config.ConfigError, Scope.Scope>): Effect.Effect<Context.Context<NodeRedis | Redis.Redis>, Config.ConfigError, Scope.Scope> (+21 overloads)pipe(
import EffectEffect.const flatMap: {
<A, B, E1, R1>(
f: (a: A) => Effect<B, E1, R1>
): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E1 | E, R1 | R>
<A, E, R, B, E1, R1>(
self: Effect<A, E, R>,
f: (a: A) => Effect<B, E1, R1>
): Effect<B, E | E1, R | R1>
}
Chains effects to produce new Effect instances, useful for combining
operations that depend on previous results.
When to use
Use when you need to chain multiple effects, ensuring that each
step produces a new Effect while flattening any nested effects that may
occur.
Details
flatMap lets you sequence effects so that the result of one effect can be
used in the next step. It is similar to flatMap used with arrays but works
specifically with Effect instances, allowing you to avoid deeply nested
effect structures.
Since effects are immutable, flatMap always returns a new effect instead of
changing the original one.
Example (Choosing flatMap syntax variants)
import { Effect, pipe } from "effect"
const myEffect = Effect.succeed(1)
const transformation = (n: number) => Effect.succeed(n + 1)
const flatMappedWithPipe = pipe(myEffect, Effect.flatMap(transformation))
const flatMappedWithDataFirst = Effect.flatMap(myEffect, transformation)
const flatMappedWithMethod = myEffect.pipe(Effect.flatMap(transformation))
Example (Sequencing dependent effects)
import { Data, Effect, pipe } from "effect"
class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
// Function to apply a discount safely to a transaction amount
const applyDiscount = (
total: number,
discountRate: number
): Effect.Effect<number, DiscountRateError> =>
discountRate === 0
? Effect.fail(new DiscountRateError())
: Effect.succeed(total - (total * discountRate) / 100)
// Simulated asynchronous task to fetch a transaction amount from database
const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
// Chaining the fetch and discount application using `flatMap`
const finalAmount = pipe(
fetchTransactionAmount,
Effect.flatMap((amount) => applyDiscount(amount, 5))
)
Effect.runPromise(finalAmount).then(console.log)
// Output: 95
flatMap(const make: (
options?: any
) => Effect.Effect<
Context.Context<NodeRedis | Redis.Redis>,
never,
Scope.Scope
>
make)
)
)