<
Self,
Key extends Schema.Top,
Value extends Schema.Top,
Error extends Schema.Top
>(
tag: ShardMapTag<Self, Key, Value, Error>,
options?: ShardMapOptions
): Layer.Layer<
Self | Local<Self>,
never,
PeersId<Self> | SelfNodeId<Self>
>Local layer — SQL-backed shard + routed/fleet members. Opens SQLite (:memory: by default;
override with { filename }). Requires the mesh capability
(Hyperlink.peersLayer, or Hyperlink.peersFrom + Hyperlink.selfNodeLayer).
export const const layer: <
Self,
Key extends Schema.Top,
Value extends Schema.Top,
Error extends Schema.Top
>(
tag: ShardMapTag<Self, Key, Value, Error>,
options?: ShardMapOptions
) => Layer.Layer<
Self | Local<Self>,
never,
PeersId<Self> | SelfNodeId<Self>
>
Local layer — SQL-backed shard + routed/fleet members. Opens SQLite (:memory: by default;
override with { filename }). Requires the mesh capability
(
Hyperlink.peersLayer
, or
Hyperlink.peersFrom
+
Hyperlink.selfNodeLayer
).
layer = <
function (type parameter) Self in <Self, Key extends Schema.Top, Value extends Schema.Top, Error extends Schema.Top>(tag: ShardMapTag<Self, Key, Value, Error>, options?: ShardMapOptions): Layer.Layer<Self | Local<Self>, never, PeersId<Self> | SelfNodeId<Self>>Self,
function (type parameter) Key in <Self, Key extends Schema.Top, Value extends Schema.Top, Error extends Schema.Top>(tag: ShardMapTag<Self, Key, Value, Error>, options?: ShardMapOptions): Layer.Layer<Self | Local<Self>, never, PeersId<Self> | SelfNodeId<Self>>Key extends import SchemaSchema.Top,
function (type parameter) Value in <Self, Key extends Schema.Top, Value extends Schema.Top, Error extends Schema.Top>(tag: ShardMapTag<Self, Key, Value, Error>, options?: ShardMapOptions): Layer.Layer<Self | Local<Self>, never, PeersId<Self> | SelfNodeId<Self>>Value extends import SchemaSchema.Top,
function (type parameter) Error in <Self, Key extends Schema.Top, Value extends Schema.Top, Error extends Schema.Top>(tag: ShardMapTag<Self, Key, Value, Error>, options?: ShardMapOptions): Layer.Layer<Self | Local<Self>, never, PeersId<Self> | SelfNodeId<Self>>Error extends import SchemaSchema.Top,
>(
tag: ShardMapTag<Self, Key, Value, Error>tag: type ShardMapTag<
Self,
Key extends Schema.Top,
Value extends Schema.Top,
Error extends Schema.Top = Schema.Never
> = any
A ShardMap instance tag — wire contract plus stamped key / value / keyOf carriers.
ShardMapTag<function (type parameter) Self in <Self, Key extends Schema.Top, Value extends Schema.Top, Error extends Schema.Top>(tag: ShardMapTag<Self, Key, Value, Error>, options?: ShardMapOptions): Layer.Layer<Self | Local<Self>, never, PeersId<Self> | SelfNodeId<Self>>Self, function (type parameter) Key in <Self, Key extends Schema.Top, Value extends Schema.Top, Error extends Schema.Top>(tag: ShardMapTag<Self, Key, Value, Error>, options?: ShardMapOptions): Layer.Layer<Self | Local<Self>, never, PeersId<Self> | SelfNodeId<Self>>Key, function (type parameter) Value in <Self, Key extends Schema.Top, Value extends Schema.Top, Error extends Schema.Top>(tag: ShardMapTag<Self, Key, Value, Error>, options?: ShardMapOptions): Layer.Layer<Self | Local<Self>, never, PeersId<Self> | SelfNodeId<Self>>Value, function (type parameter) Error in <Self, Key extends Schema.Top, Value extends Schema.Top, Error extends Schema.Top>(tag: ShardMapTag<Self, Key, Value, Error>, options?: ShardMapOptions): Layer.Layer<Self | Local<Self>, never, PeersId<Self> | SelfNodeId<Self>>Error>,
options: ShardMapOptionsoptions?: type ShardMapOptions =
internal.ShardMapOptions
Options for
layer
/
serve
/
serveRemote
.
ShardMapOptions,
): 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 <Self, Key extends Schema.Top, Value extends Schema.Top, Error extends Schema.Top>(tag: ShardMapTag<Self, Key, Value, Error>, options?: ShardMapOptions): Layer.Layer<Self | Local<Self>, never, PeersId<Self> | SelfNodeId<Self>>Self | import LocalLocal<function (type parameter) Self in <Self, Key extends Schema.Top, Value extends Schema.Top, Error extends Schema.Top>(tag: ShardMapTag<Self, Key, Value, Error>, options?: ShardMapOptions): Layer.Layer<Self | Local<Self>, never, PeersId<Self> | SelfNodeId<Self>>Self>, never, import PeersIdPeersId<function (type parameter) Self in <Self, Key extends Schema.Top, Value extends Schema.Top, Error extends Schema.Top>(tag: ShardMapTag<Self, Key, Value, Error>, options?: ShardMapOptions): Layer.Layer<Self | Local<Self>, never, PeersId<Self> | SelfNodeId<Self>>Self> | import SelfNodeIdSelfNodeId<function (type parameter) Self in <Self, Key extends Schema.Top, Value extends Schema.Top, Error extends Schema.Top>(tag: ShardMapTag<Self, Key, Value, Error>, options?: ShardMapOptions): Layer.Layer<Self | Local<Self>, never, PeersId<Self> | SelfNodeId<Self>>Self>> =>
const withSqlite: <A, E, R>(
options: ShardMapOptions | undefined,
layer: Layer.Layer<A, E, R | SqlClient>
) => Layer.Layer<A, E, R>
Provide
SqlClient
(default :memory:) and install the shard-map schema before the
resource layer builds.
withSqlite(
options: ShardMapOptionsoptions,
const buildImpl: <
Self,
Key extends Schema.Top,
Value extends Schema.Top,
Error extends Schema.Top
>(
tag: ShardMapTag<Self, Key, Value, Error>,
options?: ShardMapOptions
) => Effect.Effect<
ShardMapImpl<Key, Value>,
never,
PeersId<Self> | SelfNodeId<Self> | SqlClient
>
The served SQL-backed shard + routed/fleet members. Requires
Hyperlink.peers
/
Hyperlink.selfNode
and
SqlClient
(toolkit layers install schema + provide a
default :memory: client).
buildImpl(tag: ShardMapTag<Self, Key, Value, Error>tag, options: ShardMapOptionsoptions).Pipeable.pipe<Effect.Effect<ShardMapImpl<Schema.Top, Schema.Top>, never, any>, Effect.Effect<any, never, any>, Layer.Layer<unknown, unknown, any>>(this: Effect.Effect<ShardMapImpl<Schema.Top, Schema.Top>, never, any>, ab: (_: Effect.Effect<ShardMapImpl<Schema.Top, Schema.Top>, never, any>) => Effect.Effect<any, never, any>, bc: (_: Effect.Effect<any, never, any>) => Layer.Layer<unknown, unknown, any>): Layer.Layer<...> (+21 overloads)pipe(
import EffectEffect.const map: <ShardMapImpl<Schema.Top, Schema.Top>, any>(f: (a: ShardMapImpl<Schema.Top, Schema.Top>) => any) => <E, R>(self: Effect.Effect<ShardMapImpl<Schema.Top, Schema.Top>, E, R>) => Effect.Effect<any, E, R> (+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((impl: ShardMapImpl<Schema.Top, Schema.Top>(parameter) impl: {
get: (key: KeyT<Key>) => Effect.Effect<Option.Option<ValueT<Value>>>;
put: (value: ValueT<Value>) => Effect.Effect<boolean>;
delete: (key: KeyT<Key>) => Effect.Effect<boolean>;
getLocal: (key: KeyT<Key>) => Effect.Effect<Option.Option<ValueT<Value>>>;
putLocal: (value: ValueT<Value>) => Effect.Effect<void>;
deleteLocal: (key: KeyT<Key>) => Effect.Effect<boolean>;
sizeLocal: Effect.Effect<number>;
sizeByNode: Effect.Effect<Readonly<Record<string, number>>>;
size: Effect.Effect<number>;
}
impl) => import HyperlinkHyperlink.layer(tag: ShardMapTag<Self, Key, Value, Error>tag, const asImpl: <
Key extends Schema.Top,
Value extends Schema.Top,
Error extends Schema.Top
>(
impl: ShardMapImpl<Key, Value>
) => Hyperlink.ImplOf<
ShardMapSpecOf<Key, Value, Error>
>
Bridge concrete
ShardMapImpl
→
Hyperlink.ImplOf
. ImplOf stays opaque under
Schema.Top Key/Value Method params (Telemetry avoids this via a concrete Spec const).
asImpl(impl: ShardMapImpl<Schema.Top, Schema.Top>(parameter) impl: {
get: (key: KeyT<Key>) => Effect.Effect<Option.Option<ValueT<Value>>>;
put: (value: ValueT<Value>) => Effect.Effect<boolean>;
delete: (key: KeyT<Key>) => Effect.Effect<boolean>;
getLocal: (key: KeyT<Key>) => Effect.Effect<Option.Option<ValueT<Value>>>;
putLocal: (value: ValueT<Value>) => Effect.Effect<void>;
deleteLocal: (key: KeyT<Key>) => Effect.Effect<boolean>;
sizeLocal: Effect.Effect<number>;
sizeByNode: Effect.Effect<Readonly<Record<string, number>>>;
size: Effect.Effect<number>;
}
impl))),
import LayerLayer.const unwrap: <A, E1, R1, E, R>(
self: Effect.Effect<
Layer.Layer<A, E1, R1>,
E,
R
>
) => Layer.Layer<
A,
E | E1,
R1 | Exclude<R, Scope>
>
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,
),
);