<Effects extends StoreEffectsVariance<StoreContractValue>, Out = Effects>(
effects: Effects,
transform: (
effect: Effect.Effect<unknown, never, never>
) => Effect.Effect<unknown, never, never>
): OutThe generic transform primitive: walk every method on a effects object (nested shape
leaves + custom methods) and pass each method's returned Effect through transform, then
re-nest and re-stamp the TypeId brand. Composes with pipe.
transform is applied uniformly; whether it changes types is expressed through the result:
- Type-preserving transforms (
withSpan/retry/timed, whose signature isEffect<A, E, R> → Effect<A, E, R>) leave the type unchanged —Outdefaults toEffects. - Type-changing transforms (narrowing
E, like catchWriteErrors) supply an explicitOutcomputed per method by a mapped type (e.g. CatchWriteError), so the change flows through each method precisely.
export const const mapEffects: <
Effects extends StoreEffectsVariance<StoreContractValue>,
Out = Effects
>(
effects: Effects,
transform: (
effect: Effect.Effect<unknown, never, never>
) => Effect.Effect<unknown, never, never>
) => Out
The generic transform primitive: walk every method on a
effects
object (nested shape
leaves + custom methods) and pass each method's returned
Effect
through transform, then
re-nest and re-stamp the
TypeId
brand. Composes with pipe.
transform is applied uniformly; whether it changes types is expressed through the result:
- Type-preserving transforms (
withSpan / retry / timed, whose signature is
Effect<A, E, R> → Effect<A, E, R>) leave the type unchanged — Out defaults to Effects.
- Type-changing transforms (narrowing
E, like
catchWriteErrors
) supply an explicit
Out computed per method by a mapped type (e.g.
CatchWriteError
), so the change flows
through each method precisely.
mapEffects = <
function (type parameter) Effects in <Effects extends StoreEffectsVariance<StoreContractValue>, Out = Effects>(effects: Effects, transform: (effect: Effect.Effect<unknown, never, never>) => Effect.Effect<unknown, never, never>): OutEffects extends interface StoreEffectsVariance<out C extends StoreContractValue>Variance carrier for the
effects
brand — mirrors Effect's Stream.Variance. C is
covariant (Effect's (_: never) => C encoding), so a specific contract's effects satisfy the wide
StoreEffectsVariance<StoreContractValue> constraint that
mapEffects
/
catchWriteErrors
take.
StoreEffectsVariance<import StoreContractValueStoreContractValue>,
function (type parameter) Out in <Effects extends StoreEffectsVariance<StoreContractValue>, Out = Effects>(effects: Effects, transform: (effect: Effect.Effect<unknown, never, never>) => Effect.Effect<unknown, never, never>): OutOut = function (type parameter) Effects in <Effects extends StoreEffectsVariance<StoreContractValue>, Out = Effects>(effects: Effects, transform: (effect: Effect.Effect<unknown, never, never>) => Effect.Effect<unknown, never, never>): OutEffects,
>(
effects: Effects extends StoreEffectsVariance<StoreContractValue>effects: function (type parameter) Effects in <Effects extends StoreEffectsVariance<StoreContractValue>, Out = Effects>(effects: Effects, transform: (effect: Effect.Effect<unknown, never, never>) => Effect.Effect<unknown, never, never>): OutEffects,
transform: (
effect: Effect.Effect<unknown, never, never>
) => Effect.Effect<unknown, never, never>
transform: (
effect: Effect.Effect<unknown, never, never>(parameter) effect: {
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;
}
effect: import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<unknown, never, never>,
) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<unknown, never, never>,
): function (type parameter) Out in <Effects extends StoreEffectsVariance<StoreContractValue>, Out = Effects>(effects: Effects, transform: (effect: Effect.Effect<unknown, never, never>) => Effect.Effect<unknown, never, never>): OutOut => {
const const flat: Record<string, unknown>flat: type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, unknown> = {};
const flattenEffects: (
node: unknown,
prefix: string,
out: Record<string, unknown>
) => void
Flatten an effects object to a dotted-key map of its method leaves (functions).
flattenEffects(effects: Effects extends StoreEffectsVariance<StoreContractValue>effects, "", const flat: Record<string, unknown>flat);
const const mapped: Record<string, unknown>mapped: type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, unknown> = {};
for (const [const path: stringpath, const method: unknownmethod] of var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.entries<unknown>(o: {
[s: string]: unknown;
} | ArrayLike<unknown>): [string, unknown][] (+1 overload)
Returns an array of key/values of the enumerable own properties of an object
entries(const flat: Record<string, unknown>flat)) {
const mapped: Record<string, unknown>mapped[const path: stringpath] = const mapMethod: (
method: unknown,
transform: (
effect: Effect.Effect<unknown, never, never>
) => Effect.Effect<unknown, never, never>
) => (
...args: ReadonlyArray<unknown>
) => Effect.Effect<unknown, never, never>
Wrap a type-erased method leaf so its returned
Effect
is passed through transform. Dies if
the leaf is somehow not callable (a structural invariant the
flattenEffects
walk guarantees).
mapMethod(const method: unknownmethod, transform: (
effect: Effect.Effect<unknown, never, never>
) => Effect.Effect<unknown, never, never>
transform);
}
const const built: anybuilt = import nestHandlenestHandle(const mapped: Record<string, unknown>mapped);
const stampEffectsBrand: (
target: object
) => void
Stamp the honest (present-at-runtime)
TypeId
brand so
isStoreEffects
and the
mapEffects
/
catchWriteErrors
constraint are backed by a real property, not a phantom.
Non-enumerable so it stays invisible to method access / destructuring / the
flattenEffects
walk.
stampEffectsBrand(const built: anybuilt);
// Same structural-rebuild idiom as `effects`: the mapped object is reassembled by dynamic assignment,
// so its type is asserted once here (as `Out` — the caller-supplied per-method result, or `Effects`).
return const built: anybuilt as function (type parameter) Out in <Effects extends StoreEffectsVariance<StoreContractValue>, Out = Effects>(effects: Effects, transform: (effect: Effect.Effect<unknown, never, never>) => Effect.Effect<unknown, never, never>): OutOut;
};