<Self>(
tag: ApiMetricsTag<Self>,
options?: ApiMetricsTagOptions
): Layer.Layer<Handler<"metrics"> | Handler<"usage">, never, never>Serve this metrics resource remotely (served-only) — the counterpart to Hyperlink.serveRemote. Mounts the metrics RPC handlers and registers into Hyperlink.servedHyperlinksLayer without granting the local instance. For a pure gateway/edge; use serve when the serving node also reads the metrics in-process.
export const const serveRemote: <Self>(
tag: ApiMetricsTag<Self>,
options?: ApiMetricsTagOptions
) => Layer.Layer<unknown, unknown, unknown>
Serve this metrics resource remotely (served-only) — the counterpart to
Hyperlink.serveRemote
. Mounts the metrics RPC handlers and registers into
Hyperlink.servedHyperlinksLayer
without granting the local instance. For a pure
gateway/edge; use
serve
when the serving node also reads the metrics in-process.
serveRemote = <function (type parameter) Self in <Self>(tag: ApiMetricsTag<Self>, options?: ApiMetricsTagOptions): Layer.Layer<unknown, unknown, unknown>Self>(
tag: ApiMetricsTag<Self>tag: type ApiMetricsTag<Self> = anyAn
ApiMetrics
instance tag — a
HyperlinkTag
plus the linked client id.
ApiMetricsTag<function (type parameter) Self in <Self>(tag: ApiMetricsTag<Self>, options?: ApiMetricsTagOptions): Layer.Layer<unknown, unknown, unknown>Self>,
options: ApiMetricsTagOptionsoptions?: ApiMetricsTagOptions,
) =>
import LayerLayer.const unwrap: <unknown, unknown, unknown, never, Scope.Scope>(self: Effect.Effect<Layer.Layer<unknown, unknown, unknown>, never, Scope.Scope>) => Layer.Layer<unknown, unknown, unknown>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: <{
readonly metrics: import("effect").Stream.Stream<ApiUsageMetrics>;
readonly usage: Subscribable<ApiUsageSnapshot>;
}, never, Scope.Scope, any>(self: Effect.Effect<{
readonly metrics: import("effect").Stream.Stream<ApiUsageMetrics>;
readonly usage: Subscribable<ApiUsageSnapshot>;
}, never, Scope.Scope>, f: (a: {
readonly metrics: import("effect").Stream.Stream<ApiUsageMetrics>;
readonly usage: Subscribable<ApiUsageSnapshot>;
}) => any) => Effect.Effect<any, never, Scope.Scope> (+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 buildImpl: (
clientId: string,
options?: ApiMetricsTagOptions
) => Effect.Effect<
{
readonly metrics: Stream.Stream<ApiUsageMetrics>
readonly usage: Subscribable<ApiUsageSnapshot>
},
never,
Scope.Scope
>
buildImpl(tag: ApiMetricsTag<Self>tag[const clientIdSym: typeof clientIdSymWhere the linked outbound client id is stored on an
ApiMetrics
tag.
clientIdSym], options: ApiMetricsTagOptionsoptions), (impl: {
readonly metrics: import("effect").Stream.Stream<ApiUsageMetrics>
readonly usage: Subscribable<ApiUsageSnapshot>
}
impl) =>
import resourceServeRemoteresourceServeRemote(tag: ApiMetricsTag<Self>tag, impl: {
readonly metrics: import("effect").Stream.Stream<ApiUsageMetrics>
readonly usage: Subscribable<ApiUsageSnapshot>
}
impl),
),
);