<Self, S extends Spec, A = void, E = never, R = never>(
tag: HyperlinkTag<Self, S>,
config: ProcessLayerConfig<A, E, R>
): Layer.Layer<
Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage,
never,
R
>Serve a process and grant its local instance from one materialization.
Soft-defaults Store.Storage. Override with Layer.provide / provideMerge(AppStore).
export function function serve<
Self,
S extends Spec,
A = void,
E = never,
R = never
>(
tag: HyperlinkTag<Self, S>,
config: ProcessLayerConfig<A, E, R>
): Layer.Layer<
| Self
| Local<Self>
| HandlerContextOf<ProcessSpec>
| Store.Storage,
never,
R
>
Serve a process and grant its local instance from one materialization.
Soft-defaults
Store.Storage
. Override with Layer.provide / provideMerge(AppStore).
serve<function (type parameter) Self in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>Self, function (type parameter) S in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>S extends import SpecSpec, function (type parameter) A in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>A = void, function (type parameter) E in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>E = never, function (type parameter) R in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>R = never>(
tag: HyperlinkTag<Self, S>tag: import HyperlinkTagHyperlinkTag<function (type parameter) Self in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>Self, function (type parameter) S in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>S>,
config: ProcessLayerConfig<A, E, R>(parameter) config: {
effect: Effect.Effect<A, E, R>;
polling: Layer.Layer<PollingTag, never, never>;
}
config: interface ProcessLayerConfig<A, E, R>Config for
layer
/
serve
/
serveRemote
. The effect is the work each run
performs; its success is captured into result when the tag is value-returning. Scheduling comes
from the tag now (Process.schedule(...)), not the config.
ProcessLayerConfig<function (type parameter) A in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>A, function (type parameter) E in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>E, function (type parameter) R in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>R>,
): import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<
function (type parameter) Self in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>Self | import LocalLocal<function (type parameter) Self in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>Self> | import HandlerContextOfHandlerContextOf<type ProcessSpec = {
events: any
run: any
status: any
start: any
stop: any
wake: any
resetCadence: any
}
The base (schedule-less, result-less) process spec.
ProcessSpec> | import StoreStore.type Store.Storage = /*unresolved*/ anyStorage,
never,
function (type parameter) R in serve<Self, S extends Spec, A = void, E = never, R = never>(tag: HyperlinkTag<Self, S>, config: ProcessLayerConfig<A, E, R>): Layer.Layer<Self | Local<Self> | HandlerContextOf<ProcessSpec> | Store.Storage, never, R>R
>;
export function function serve<
Self,
S extends Spec,
A = void,
E = never,
R = never
>(
tag: HyperlinkTag<Self, S>,
config: ProcessLayerConfig<A, E, R>
): Layer.Layer<
| Self
| Local<Self>
| HandlerContextOf<ProcessSpec>
| Store.Storage,
never,
R
>
Serve a process and grant its local instance from one materialization.
Soft-defaults
Store.Storage
. Override with Layer.provide / provideMerge(AppStore).
serve(
tag: HyperlinkTag<any, any, any>tag: import HyperlinkTagHyperlinkTag<any, any, any>,
config: ProcessLayerConfig<any, any, any>(parameter) config: {
effect: Effect.Effect<A, E, R>;
polling: Layer.Layer<PollingTag, never, never>;
}
config: interface ProcessLayerConfig<A, E, R>Config for
layer
/
serve
/
serveRemote
. The effect is the work each run
performs; its success is captured into result when the tag is value-returning. Scheduling comes
from the tag now (Process.schedule(...)), not the config.
ProcessLayerConfig<any, any, any>,
): import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<any, any, any> {
const const baseTag: HyperlinkTag<
any,
ProcessSpec
>
baseTag: import HyperlinkTagHyperlinkTag<any, type ProcessSpec = {
events: any
run: any
status: any
start: any
stop: any
wake: any
resetCadence: any
}
The base (schedule-less, result-less) process spec.
ProcessSpec> = tag: HyperlinkTag<any, any, any>tag;
return const withDefaultMemory: <
unknown,
unknown,
unknown
>(
layer: Layer.Layer<unknown, unknown, any>
) => Layer.Layer<any, unknown, unknown>
Soft-default
Store.Storage
(
Store.withDefaultStorage
) — R fulfilled; override by
providing an app store into this layer.
withDefaultMemory(
import LayerLayer.const unwrap: <
unknown,
unknown,
unknown,
never,
any
>(
self: Effect.Effect<
Layer.Layer<unknown, unknown, unknown>,
never,
any
>
) => Layer.Layer<unknown, unknown, any>
Unwraps a Layer from an Effect, flattening the nested structure.
When to use
Use when you have an Effect that produces a Layer and you want to
use that layer directly.
Details
The resulting Layer will have the combined error and dependency types from
both the outer Effect and the inner Layer.
Example (Unwrapping an effectful layer)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
const layerEffect = Effect.succeed(
Layer.succeed(Database, { query: Effect.fn("Database.query")((sql: string) => Effect.succeed("result")) })
)
const unwrappedLayer = Layer.unwrap(layerEffect)
unwrap(
import EffectEffect.const map: <Hyperlink.BuiltHyperlink<{
events: any;
run: any;
status: any;
start: any;
stop: any;
wake: any;
resetCadence: any;
}, R>, never, any, any>(self: Effect.Effect<Hyperlink.BuiltHyperlink<{
events: any;
run: any;
status: any;
start: any;
stop: any;
wake: any;
resetCadence: any;
}, R>, never, any>, f: (a: Hyperlink.BuiltHyperlink<{
events: any;
run: any;
status: any;
start: any;
stop: any;
wake: any;
resetCadence: any;
}, R>) => any) => Effect.Effect<any, never, any> (+1 overload)
Transforms the value inside an effect by applying a function to it.
When to use
Use to transform an effect's success value with a function that returns a
plain value, producing a new effect without changing the original effect's
typed error or context requirements.
Details
map takes a function and applies it to the value contained within an
effect, creating a new effect with the transformed value.
It's important to note that effects are immutable, meaning that the original
effect is not modified. Instead, a new effect is returned with the updated
value.
Example (Choosing map syntax variants)
import { Effect, pipe } from "effect"
const myEffect = Effect.succeed(1)
const transformation = (n: number) => n + 1
const mappedWithPipe = pipe(myEffect, Effect.map(transformation))
const mappedWithDataFirst = Effect.map(myEffect, transformation)
const mappedWithMethod = myEffect.pipe(Effect.map(transformation))
Example (Adding a service charge)
import { Effect, pipe } from "effect"
const addServiceCharge = (amount: number) => amount + 1
const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
const finalAmount = pipe(
fetchTransactionAmount,
Effect.map(addServiceCharge)
)
Effect.runPromise(finalAmount).then(console.log)
// Output: 101
map(
const buildProcessImpl: <A, E, R>(
tag: HyperlinkTag<any, any, any>,
baseConfig: ProcessLayerConfig<A, E, R>
) => Effect.Effect<
Hyperlink.BuiltHyperlink<ProcessSpec, R>,
never,
R | Scope.Scope | Store.Storage
>
Build the live process driver behind tag and map it onto the toolkit service impl — the adapter
shared by
layer
/
serve
/
serveRemote
. The returned record is shaped to the
tag's composed spec (base, + schedule, + result); Hyperlink.layer flattens it against the
tag's flat spec, so extra members are simply present when the spec declares them.
buildProcessImpl(tag: HyperlinkTag<any, any, any>tag, config: ProcessLayerConfig<any, any, any>(parameter) config: {
effect: Effect.Effect<A, E, R>;
polling: Layer.Layer<PollingTag, never, never>;
}
config),
(built: Hyperlink.BuiltHyperlink<
{
events: any
run: any
status: any
start: any
stop: any
wake: any
resetCadence: any
},
R
>
built) => import HyperlinkHyperlink.serve(const baseTag: HyperlinkTag<
any,
ProcessSpec
>
baseTag, built: Hyperlink.BuiltHyperlink<
{
events: any
run: any
status: any
start: any
stop: any
wake: any
resetCadence: any
},
R
>
built) as any,
),
) as any,
) as any;
}