<Self>(
tag: HyperlinkTag<Self, ScheduleHyperlinkSpec>,
options?: { readonly initial?: ReadonlyArray<ScheduleWindow> }
): Layer.Layer<Self | Local<Self>>The local layer for a standalone Schedule resource — an in-memory window manager
(optionally seeded with initial windows) that any number of daemons can be gated by.
export const const scheduleLayer: <Self>(
tag: HyperlinkTag<Self, ScheduleHyperlinkSpec>,
options?: {
readonly initial?: ReadonlyArray<ScheduleWindow>
}
) => Layer.Layer<Self | Local<Self>>
The local layer for a standalone
Schedule
resource — an in-memory window manager
(optionally seeded with initial windows) that any number of daemons can be gated by.
scheduleLayer = <function (type parameter) Self in <Self>(tag: HyperlinkTag<Self, ScheduleHyperlinkSpec>, options?: {
readonly initial?: ReadonlyArray<ScheduleWindow>;
}): Layer.Layer<Self | Local<Self>>
Self>(
tag: HyperlinkTag<
Self,
ScheduleHyperlinkSpec
>
(parameter) tag: {
key: Identifier;
Service: {
entries: Hyperlink.Subscribable<ReadonlyArray<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>>;
get: (payload: { id: string }) => Effect.Effect<Option.Option<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>, never, never>;
has: (payload: { id: string }) => Effect.Effect<boolean, never, never>;
set: (payload: ReadonlyArray<{ startAt: DateTime.Utc; id?: string | undefined; stopAt?: DateTime.Utc | undefined }>) => Effect.Effect<void, never, never>;
add: (payload: { startAt: DateTime.Utc; id?: string | undefined; stopAt?: DateTime.Utc | undefined }) => Effect.Effect<void, never, never>;
upsert: (payload: { startAt: DateTime.Utc; id?: string | undefined; stopAt?: DateTime.Utc | undefined }) => Effect.Effect<void, never, never>;
remove: (payload: { id: string }) => Effect.Effect<boolean, never, never>;
removeMany: (payload: ReadonlyArray<string>) => Effect.Effect<number, never, never>;
clear: Effect.Effect<void, never, never>;
};
description: string | undefined;
of: (this: void, self: { readonly entries: Hyperlink.Subscribable<ReadonlyArray<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>>; readonly get: (payload: { id: string }) => Effe…;
context: (self: { readonly entries: Hyperlink.Subscribable<ReadonlyArray<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>>; readonly get: (payload: { id: string }) => Effect.Effect<Op…;
use: (f: (service: { readonly entries: Hyperlink.Subscribable<ReadonlyArray<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>>; readonly get: (payload: { id: string }) => Effect.Ef…;
useSync: (f: (service: { readonly entries: Hyperlink.Subscribable<ReadonlyArray<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>>; readonly get: (payload: { id: string }) => Effect.Ef…;
Identifier: Identifier;
stack: string | undefined;
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;
}
tag: interface HyperlinkTag<Self, S extends Spec, Svc = Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<...> : S[K] extends DefaultMethod<...> ? F : S[K] extends { ...; } ? SuccessOf<...> : S[K] extends { ...; } ? Subscribable<...> : S[K] extends { ...; } ? ClientMethod<...> : S[K] extends Spec ? Simplify<...> : never; }>>The type of a HyperService tag carrying spec S — what
Hyperlink.Tag
produces
(and what you extend). Lets a consumer write
<S extends Spec>(tag: HyperlinkTag<Self, S>) and read the spec through named types
(
specOf
/
groupOf
) instead of a Parameters<typeof specOf> workaround.
HyperlinkTag<function (type parameter) Self in <Self>(tag: HyperlinkTag<Self, ScheduleHyperlinkSpec>, options?: {
readonly initial?: ReadonlyArray<ScheduleWindow>;
}): Layer.Layer<Self | Local<Self>>
Self, type ScheduleHyperlinkSpec = {
entries: Hyperlink.Marked<Hyperlink.Method<undefined, Schema.$Array<Schema.Struct<{
readonly id: Schema.optionalKey<Schema.String>;
readonly startAt: Schema.DateTimeUtc;
readonly stopAt: Schema.optionalKey<Schema.DateTimeUtc>;
}>>, Schema.Never, true, Hyperlink.MethodAnnotations & {
description: string;
}, Hyperlink.Derive>, {
readonly _tag: "ref";
}>;
get: Hyperlink.Method<{
readonly id: Schema.String;
}, Schema.Option<...>, Schema.Never, false, Hyperlink.MethodAnnotations & {
...;
}, Hyperlink.Derive>;
... 6 more ...;
clear: Hyperlink.Method<...>;
}
The standalone
Schedule
HyperService's spec.
ScheduleHyperlinkSpec>,
options: {
readonly initial?: ReadonlyArray<ScheduleWindow>
}
options?: { readonly initial?: ReadonlyArray<ScheduleWindow>initial?: interface ReadonlyArray<T>ReadonlyArray<ScheduleWindow> },
): 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>(tag: HyperlinkTag<Self, ScheduleHyperlinkSpec>, options?: {
readonly initial?: ReadonlyArray<ScheduleWindow>;
}): Layer.Layer<Self | Local<Self>>
Self | interface Local<in out Self>Granted only by a HyperService's local layer (
Hyperlink.layer
/
serve
) — never by
Hyperlink.client
. Local to this runtime's materialized impl for the tag (not a remote
client, not a peer). A
LocalMethod
carries it in its requirement channel, so calling a
non-serializable method against a client is a compile error (unsatisfied requirement); the
same call resolves when the local layer is provided. Branded by Self so one HyperService's local
layer can't unlock another's.
Local<function (type parameter) Self in <Self>(tag: HyperlinkTag<Self, ScheduleHyperlinkSpec>, options?: {
readonly initial?: ReadonlyArray<ScheduleWindow>;
}): Layer.Layer<Self | Local<Self>>
Self>> =>
import LayerLayer.const unwrap: <A, E1, R1, E, R>(
self: Effect<Layer<A, E1, R1>, E, R>
) => Layer<
A,
E | E1,
R1 | Exclude<R, Scope.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(
import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
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 buildScheduleImpl: (options?: {
readonly initial?: ReadonlyArray<ScheduleWindow>
}) => Effect.Effect<
ImplOf<ScheduleHyperlinkSpec>,
never,
Scope.Scope
>
buildScheduleImpl(options: {
readonly initial?: ReadonlyArray<ScheduleWindow>
}
options), (impl: Hyperlink.ImplOf<{
entries: Hyperlink.Marked<Hyperlink.Method<undefined, Schema.$Array<Schema.Struct<{
readonly id: Schema.optionalKey<Schema.String>;
readonly startAt: Schema.DateTimeUtc;
readonly stopAt: Schema.optionalKey<Schema.DateTimeUtc>;
}>>, Schema.Never, true, Hyperlink.MethodAnnotations & {
description: string;
}, Hyperlink.Derive>, {
readonly _tag: "ref";
}>;
get: Hyperlink.Method<{
readonly id: Schema.String;
}, Schema.Option<...>, Schema.Never, false, Hyperlink.MethodAnnotations & {
...;
}, Hyperlink.Derive>;
... 6 more ...;
clear: Hyperlink.Method<...>;
}>
(parameter) impl: {
entries: Hyperlink.Subscribable<ReadonlyArray<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>>;
get: (payload: { id: string }) => Effect.Effect<Option.Option<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>, never, never>;
has: (payload: { id: string }) => Effect.Effect<boolean, never, never>;
set: (payload: ReadonlyArray<{ startAt: DateTime.Utc; id?: string | undefined; stopAt?: DateTime.Utc | undefined }>) => Effect.Effect<void, never, never>;
add: (payload: { startAt: DateTime.Utc; id?: string | undefined; stopAt?: DateTime.Utc | undefined }) => Effect.Effect<void, never, never>;
upsert: (payload: { startAt: DateTime.Utc; id?: string | undefined; stopAt?: DateTime.Utc | undefined }) => Effect.Effect<void, never, never>;
remove: (payload: { id: string }) => Effect.Effect<boolean, never, never>;
removeMany: (payload: ReadonlyArray<string>) => Effect.Effect<number, never, never>;
clear: Effect.Effect<void, never, never>;
}
impl) => import HyperlinkHyperlink.layer<Self, {
entries: Hyperlink.Marked<Hyperlink.Method<undefined, Schema.$Array<Schema.Struct<{
readonly id: Schema.optionalKey<Schema.String>;
readonly startAt: Schema.DateTimeUtc;
readonly stopAt: Schema.optionalKey<Schema.DateTimeUtc>;
}>>, Schema.Never, true, Hyperlink.MethodAnnotations & {
description: string;
}, Hyperlink.Derive>, {
readonly _tag: "ref";
}>;
get: Hyperlink.Method<{
readonly id: Schema.String;
}, Schema.Option<Schema.Struct<...>>, Schema.Never, false, Hyperlink.MethodAnnotations & {
...;
}, Hyperlink.Derive>;
... 6 more ...;
clear: Hyperlink.Method<...>;
}>(tag: Hyperlink.HyperlinkTag<...>, impl: Hyperlink.ImplWithDefaultOverrides<...>): Layer.Layer<...> (+3 overloads)
export layer
layer(tag: HyperlinkTag<
Self,
ScheduleHyperlinkSpec
>
(parameter) tag: {
key: Identifier;
Service: {
entries: Hyperlink.Subscribable<ReadonlyArray<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>>;
get: (payload: { id: string }) => Effect.Effect<Option.Option<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>, never, never>;
has: (payload: { id: string }) => Effect.Effect<boolean, never, never>;
set: (payload: ReadonlyArray<{ startAt: DateTime.Utc; id?: string | undefined; stopAt?: DateTime.Utc | undefined }>) => Effect.Effect<void, never, never>;
add: (payload: { startAt: DateTime.Utc; id?: string | undefined; stopAt?: DateTime.Utc | undefined }) => Effect.Effect<void, never, never>;
upsert: (payload: { startAt: DateTime.Utc; id?: string | undefined; stopAt?: DateTime.Utc | undefined }) => Effect.Effect<void, never, never>;
remove: (payload: { id: string }) => Effect.Effect<boolean, never, never>;
removeMany: (payload: ReadonlyArray<string>) => Effect.Effect<number, never, never>;
clear: Effect.Effect<void, never, never>;
};
description: string | undefined;
of: (this: void, self: { readonly entries: Hyperlink.Subscribable<ReadonlyArray<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>>; readonly get: (payload: { id: string }) => Effe…;
context: (self: { readonly entries: Hyperlink.Subscribable<ReadonlyArray<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>>; readonly get: (payload: { id: string }) => Effect.Effect<Op…;
use: (f: (service: { readonly entries: Hyperlink.Subscribable<ReadonlyArray<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>>; readonly get: (payload: { id: string }) => Effect.Ef…;
useSync: (f: (service: { readonly entries: Hyperlink.Subscribable<ReadonlyArray<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>>; readonly get: (payload: { id: string }) => Effect.Ef…;
Identifier: Identifier;
stack: string | undefined;
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;
}
tag, impl: Hyperlink.ImplOf<{
entries: Hyperlink.Marked<Hyperlink.Method<undefined, Schema.$Array<Schema.Struct<{
readonly id: Schema.optionalKey<Schema.String>;
readonly startAt: Schema.DateTimeUtc;
readonly stopAt: Schema.optionalKey<Schema.DateTimeUtc>;
}>>, Schema.Never, true, Hyperlink.MethodAnnotations & {
description: string;
}, Hyperlink.Derive>, {
readonly _tag: "ref";
}>;
get: Hyperlink.Method<{
readonly id: Schema.String;
}, Schema.Option<...>, Schema.Never, false, Hyperlink.MethodAnnotations & {
...;
}, Hyperlink.Derive>;
... 6 more ...;
clear: Hyperlink.Method<...>;
}>
(parameter) impl: {
entries: Hyperlink.Subscribable<ReadonlyArray<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>>;
get: (payload: { id: string }) => Effect.Effect<Option.Option<{ readonly startAt: DateTime.Utc; readonly id?: string | undefined; readonly stopAt?: DateTime.Utc | undefined }>, never, never>;
has: (payload: { id: string }) => Effect.Effect<boolean, never, never>;
set: (payload: ReadonlyArray<{ startAt: DateTime.Utc; id?: string | undefined; stopAt?: DateTime.Utc | undefined }>) => Effect.Effect<void, never, never>;
add: (payload: { startAt: DateTime.Utc; id?: string | undefined; stopAt?: DateTime.Utc | undefined }) => Effect.Effect<void, never, never>;
upsert: (payload: { startAt: DateTime.Utc; id?: string | undefined; stopAt?: DateTime.Utc | undefined }) => Effect.Effect<void, never, never>;
remove: (payload: { id: string }) => Effect.Effect<boolean, never, never>;
removeMany: (payload: ReadonlyArray<string>) => Effect.Effect<number, never, never>;
clear: Effect.Effect<void, never, never>;
}
impl)),
);