<Status extends Schema.Top, Change extends Schema.Top>(
options: MonitoredDependencyOptions<Status, Change>
): MonitoredDependency<Status, Change>Build the common monitored dependency contract: status (one-shot read),
changes (live snapshot stream), and readiness derived from status. Still a
plain Hyperlink.Tag shape — not a new resource kind.
Compose behaviour the usual way: tag + withReadiness (see Resources → behaviour via piped combinators).
export const const monitoredDependency: <
Status extends Schema.Top,
Change extends Schema.Top
>(
options: MonitoredDependencyOptions<
Status,
Change
>
) => MonitoredDependency<Status, Change>
Build the common monitored dependency contract: status (one-shot read),
changes (live snapshot stream), and readiness derived from status. Still a
plain
Hyperlink.Tag
shape — not a new resource kind.
Compose behaviour the usual way: tag +
withReadiness
(see
Resources → behaviour via piped combinators).
monitoredDependency = <
function (type parameter) Status in <Status extends Schema.Top, Change extends Schema.Top>(options: MonitoredDependencyOptions<Status, Change>): MonitoredDependency<Status, Change>Status extends import SchemaSchema.Top,
function (type parameter) Change in <Status extends Schema.Top, Change extends Schema.Top>(options: MonitoredDependencyOptions<Status, Change>): MonitoredDependency<Status, Change>Change extends import SchemaSchema.Top,
>(
options: MonitoredDependencyOptions<
Status,
Change
>
(parameter) options: {
status: Status;
changes: Change;
readyWhen: (status: Schema.Schema.Type<Status>) => boolean;
detail: (status: Schema.Schema.Type<Status>) => string | undefined;
}
options: interface MonitoredDependencyOptions<Status extends Schema.Top, Change extends Schema.Top>Authoring options for
monitoredDependency
. Field names match the
produced
MonitoredDependencySpec
(status / changes); changes is the
element schema of the live stream.
MonitoredDependencyOptions<function (type parameter) Status in <Status extends Schema.Top, Change extends Schema.Top>(options: MonitoredDependencyOptions<Status, Change>): MonitoredDependency<Status, Change>Status, function (type parameter) Change in <Status extends Schema.Top, Change extends Schema.Top>(options: MonitoredDependencyOptions<Status, Change>): MonitoredDependency<Status, Change>Change>,
): interface MonitoredDependency<Status extends Schema.Top, Change extends Schema.Top>Spec + readiness from
monitoredDependency
. Pass spec to
Hyperlink.Tag
; attach readiness with
withReadiness
.
MonitoredDependency<function (type parameter) Status in <Status extends Schema.Top, Change extends Schema.Top>(options: MonitoredDependencyOptions<Status, Change>): MonitoredDependency<Status, Change>Status, function (type parameter) Change in <Status extends Schema.Top, Change extends Schema.Top>(options: MonitoredDependencyOptions<Status, Change>): MonitoredDependency<Status, Change>Change> => ({
MonitoredDependency<Status, Change>.spec: MonitoredDependencySpec<Status, Change>(property) MonitoredDependency<Status, Change>.spec: {
status: Method<undefined, Status, Schema.Never, false, MethodAnnotations, Derive>;
changes: Method<undefined, Change, Schema.Never, true, MethodAnnotations, Derive>;
}
spec: const contract: <S extends Spec>(
spec: S
) => S
Narrow a resource contract object through the builder (prefer over as const satisfies).
contract({
status: Method<
undefined,
Status,
Schema.Never,
false,
MethodAnnotations,
Derive
>
(property) status: {
kind: MethodKind;
payload: P;
success: Su;
error: E;
stream: Str;
annotations: Ann;
annotate: <A extends MethodAnnotations>(annotations: A) => Method<P, Su, E, Str, Ann & A, Client>;
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; <…;
}
status: function effect<Status>(success: Status): Method<undefined, Status, Schema.Never, false, MethodAnnotations, Derive> (+3 overloads)Two-stage
effect
— override the client-facing type with a Client (an Effect type;
a read surfaces as Effect<Success>) that must narrow the schema-derived shape:
effect<Client>()(success). Widening the success fails to compile. For a free override, see
unsafeEffect
.
effect(options: MonitoredDependencyOptions<
Status,
Change
>
(parameter) options: {
status: Status;
changes: Change;
readyWhen: (status: Schema.Schema.Type<Status>) => boolean;
detail: (status: Schema.Schema.Type<Status>) => string | undefined;
}
options.MonitoredDependencyOptions<Status, Change>.status: Status extends Schema.Topstatus),
changes: Method<
undefined,
Change,
Schema.Never,
true,
MethodAnnotations,
Derive
>
(property) changes: {
kind: MethodKind;
payload: P;
success: Su;
error: E;
stream: Str;
annotations: Ann;
annotate: <A extends MethodAnnotations>(annotations: A) => Method<P, Su, E, Str, Ann & A, Client>;
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; <…;
}
changes: function stream<Change>(success: Change): Method<undefined, Change, Schema.Never, true, MethodAnnotations, Derive> (+5 overloads)Define a stream (a live, idempotent push source) whose elements are success. The
service member surfaces as a Stream<Success, Error> (a property, or (payload) => Stream
when a payload is declared) rather than an Effect — drive dashboard atoms, a CLI
--watch, or a TUI from it. Conventionally named changes when it carries a resource's
whole observable state (a snapshot stream); back it with a SubscriptionRef's .changes.
Counts as a query for tools (an idempotent read). success is the element schema and
error (if any) is the stream error schema; both must be encodable (they cross RPC).
payload is a single schema or struct fields — same as Effect's Rpc.make.
changes: Hyperlink.stream(QueueSnapshot).annotate({ description: "Live queue state." }),
tail: Hyperlink.stream(LogLine, { payload: Schema.Struct({ since: Schema.Number }) }),
stream(options: MonitoredDependencyOptions<
Status,
Change
>
(parameter) options: {
status: Status;
changes: Change;
readyWhen: (status: Schema.Schema.Type<Status>) => boolean;
detail: (status: Schema.Schema.Type<Status>) => string | undefined;
}
options.MonitoredDependencyOptions<Status, Change>.changes: Change extends Schema.Topchanges),
}),
MonitoredDependency<Status, Change>.readiness: ReadinessOf<MonitoredDependencyService<Status>>readiness: ((svc: MonitoredDependencyService<Status>(parameter) svc: {
status: Effect.Effect<Schema.Schema.Type<Status>>;
}
svc, _base: any_base: any) =>
(import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<B, E, R>
<A, E, R, B>(
self: Effect.Effect<A, E, R>,
f: (a: A) => B
): Effect.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 as any)(
(svc: MonitoredDependencyService<Status>(parameter) svc: {
status: Effect.Effect<Schema.Schema.Type<Status>>;
}
svc as interface MonitoredDependencyService<Status extends Schema.Top>The service slice
monitoredDependency
readiness reads — status only.
Assignable into
withReadiness
for a full
MonitoredDependencySpec
tag (extra changes is ignored).
MonitoredDependencyService<function (type parameter) Status in <Status extends Schema.Top, Change extends Schema.Top>(options: MonitoredDependencyOptions<Status, Change>): MonitoredDependency<Status, Change>Status>).MonitoredDependencyService<Status>.status: Effect.Effect<Schema.Schema.Type<Status>, never, never>(property) MonitoredDependencyService<Status>.status: {
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;
}
status,
(s: Schema.Schema.Type<Status>s: import SchemaSchema.Schema.type Schema<out T>.Type<S> = S extends {
readonly Type: infer T;
} ? T : never
Extracts the decoded Type from a schema.
Example (Extracting the decoded type)
import { Schema } from "effect"
const Person = Schema.Struct({ name: Schema.String, age: Schema.Number })
type Person = Schema.Schema.Type<typeof Person>
// { readonly name: string; readonly age: number }
Type<function (type parameter) Status in <Status extends Schema.Top, Change extends Schema.Top>(options: MonitoredDependencyOptions<Status, Change>): MonitoredDependency<Status, Change>Status>): Readiness => {
const const ready: booleanready = options: MonitoredDependencyOptions<
Status,
Change
>
(parameter) options: {
status: Status;
changes: Change;
readyWhen: (status: Schema.Schema.Type<Status>) => boolean;
detail: (status: Schema.Schema.Type<Status>) => string | undefined;
}
options.MonitoredDependencyOptions<Status, Change>.readyWhen: (status: Schema.Schema<out T>.Type<Status>) => booleanreadyWhen(s: Schema.Schema.Type<Status>s);
const const detail: string | undefineddetail = options: MonitoredDependencyOptions<
Status,
Change
>
(parameter) options: {
status: Status;
changes: Change;
readyWhen: (status: Schema.Schema.Type<Status>) => boolean;
detail: (status: Schema.Schema.Type<Status>) => string | undefined;
}
options.MonitoredDependencyOptions<Status, Change>.detail?: ((status: Schema.Schema.Type<Status>) => string | undefined) | undefineddetail?.(s: Schema.Schema.Type<Status>s);
return const detail: string | undefineddetail === var undefinedundefined ? { Readiness.ready: booleanready } : { Readiness.ready: booleanready, Readiness.detail?: string | undefineddetail };
},
)) as type ReadinessOf<Service> = (
service: Service,
base: Effect.Effect<Readiness, never, any>
) => Effect.Effect<Readiness, never, any>
Derive
Readiness
from a resource's materialized service — read its status, don't store new
state. The second argument, base, is the readiness already on the tag (e.g. a contract
factory's own check) — yield* base to extend it (a queue's phase === "running" and your
dependency checks), or ignore it to replace it. Stacks: each
withReadiness
wraps the prior.
Attach one with
withReadiness
; read the result with
readinessCheck
.
ReadinessOf<interface MonitoredDependencyService<Status extends Schema.Top>The service slice
monitoredDependency
readiness reads — status only.
Assignable into
withReadiness
for a full
MonitoredDependencySpec
tag (extra changes is ignored).
MonitoredDependencyService<function (type parameter) Status in <Status extends Schema.Top, Change extends Schema.Top>(options: MonitoredDependencyOptions<Status, Change>): MonitoredDependency<Status, Change>Status>>,
});