Skip to content

Template.ts

Builds HTTP response text from template literals.

Template interpolations can be plain values, optional values, effects, or streams. The resulting effect or stream keeps the errors and service requirements from any effectful interpolations, which lets response helpers assemble dynamic text without losing type information.

Since v4.0.0



Creates an effectful string from a template literal.

Details

Primitive and Option interpolations are rendered immediately. Effect interpolations are evaluated and rendered before the final string is produced.

Signature

declare const make: <A extends ReadonlyArray<Interpolated>>(
strings: TemplateStringsArray,
...args: A
) => Effect.Effect<string, Interpolated.Error<A[number]>, Interpolated.Context<A[number]>>

Source

Since v4.0.0

Creates a stream of strings from a template literal.

Details

Static text is emitted with interpolated values. Effect interpolations are evaluated as stream chunks, and stream interpolations are flattened into the output.

Signature

declare const stream: <A extends ReadonlyArray<InterpolatedWithStream>>(
strings: TemplateStringsArray,
...args: A
) => Stream.Stream<string, Interpolated.Error<A[number]>, Interpolated.Context<A[number]>>

Source

Since v4.0.0

Value accepted by the string template constructor.

Details

Interpolations can be primitive values, optional primitive values, or effects that produce primitive values.

Signature

type Interpolated = Primitive | Option.Option<Primitive> | Effect.Effect<Primitive, any, any>

Source

Since v4.0.0

Value accepted by the streaming template constructor.

Details

In addition to normal interpolations, stream interpolations can emit primitive values over time.

Signature

type InterpolatedWithStream = Interpolated | Stream.Stream<Primitive, any, any>

Source

Since v4.0.0

Primitive template interpolation value.

Details

Arrays are rendered by converting each element to a string and concatenating the results.

Signature

type Primitive = PrimitiveValue | ReadonlyArray<PrimitiveValue>

Source

Since v4.0.0

Primitive value that can be interpolated into an HTTP template.

Signature

type PrimitiveValue = string | number | bigint | boolean | null | undefined

Source

Since v4.0.0

Namespace containing type-level helpers for template interpolations.

Source

Since v4.0.0

Extracts the required context from an effect or stream interpolation.

Details

Plain values and Option interpolations contribute no context.

Signature

type Context<A> = A extends infer T
? T extends Option.Option<infer _>
? never
: T extends Effect.Effect<infer _A, infer _E, infer R>
? R
: T extends Stream.Stream<infer _A, infer _E, infer R>
? R
: never
: never

Source

Since v4.0.0

Extracts the error type from an effect or stream interpolation.

Details

Plain values and Option interpolations contribute no error type.

Signature

type Error<A> = A extends infer T
? T extends Option.Option<infer _>
? never
: T extends Stream.Stream<infer _A, infer E, infer _R>
? E
: T extends Effect.Effect<infer _A, infer E, infer _R>
? E
: never
: never

Source

Since v4.0.0