|
|
|
@@ -1,4 +1,4 @@
|
|
|
|
|
import { Array, Chunk, type Context, Effect, Function, identity, Option, Pipeable, Predicate, Readable, Stream, type SubscriptionRef, type SynchronizedRef } from "effect"
|
|
|
|
|
import { Array, Chunk, Effect, Function, identity, type Layer, Option, Pipeable, Predicate, Readable, Stream, type Context, type SubscriptionRef, type SynchronizedRef } from "effect"
|
|
|
|
|
import type { NoSuchElementException } from "effect/Cause"
|
|
|
|
|
import * as Subscribable from "./Subscribable.js"
|
|
|
|
|
|
|
|
|
@@ -273,6 +273,58 @@ export const mapStream: {
|
|
|
|
|
* Provides a single service to a `Lens`, removing it from both the read and write environments.
|
|
|
|
|
*/
|
|
|
|
|
export const provide: {
|
|
|
|
|
<const Layers extends readonly [Layer.Layer.Any, ...Array<Layer.Layer.Any>]>(
|
|
|
|
|
layers: Layers,
|
|
|
|
|
): <A, ER, EW, RR, RW>(self: Lens<A, ER, EW, RR, RW>) => Lens<
|
|
|
|
|
A,
|
|
|
|
|
ER | { [k in keyof Layers]: Layer.Layer.Error<Layers[k]> }[number],
|
|
|
|
|
EW | { [k in keyof Layers]: Layer.Layer.Error<Layers[k]> }[number],
|
|
|
|
|
{ [k in keyof Layers]: Layer.Layer.Context<Layers[k]> }[number] | Exclude<RR, { [k in keyof Layers]: Layer.Layer.Success<Layers[k]> }[number]>,
|
|
|
|
|
{ [k in keyof Layers]: Layer.Layer.Context<Layers[k]> }[number] | Exclude<RW, { [k in keyof Layers]: Layer.Layer.Success<Layers[k]> }[number]>
|
|
|
|
|
>
|
|
|
|
|
<ROut, E2, RIn>(
|
|
|
|
|
layer: Layer.Layer<ROut, E2, RIn>,
|
|
|
|
|
): <A, ER, EW, RR, RW>(self: Lens<A, ER, EW, RR, RW>) => Lens<A, ER | E2, EW | E2, RIn | Exclude<RR, ROut>, RIn | Exclude<RW, ROut>>
|
|
|
|
|
<R2>(
|
|
|
|
|
context: Context.Context<R2>,
|
|
|
|
|
): <A, ER, EW, RR, RW>(self: Lens<A, ER, EW, RR, RW>) => Lens<A, ER, EW, Exclude<RR, R2>, Exclude<RW, R2>>
|
|
|
|
|
<A, ER, EW, RR, RW, const Layers extends readonly [Layer.Layer.Any, ...Array<Layer.Layer.Any>]>(
|
|
|
|
|
self: Lens<A, ER, EW, RR, RW>,
|
|
|
|
|
layers: Layers,
|
|
|
|
|
): Lens<
|
|
|
|
|
A,
|
|
|
|
|
ER | { [k in keyof Layers]: Layer.Layer.Error<Layers[k]> }[number],
|
|
|
|
|
EW | { [k in keyof Layers]: Layer.Layer.Error<Layers[k]> }[number],
|
|
|
|
|
{ [k in keyof Layers]: Layer.Layer.Context<Layers[k]> }[number] | Exclude<RR, { [k in keyof Layers]: Layer.Layer.Success<Layers[k]> }[number]>,
|
|
|
|
|
{ [k in keyof Layers]: Layer.Layer.Context<Layers[k]> }[number] | Exclude<RW, { [k in keyof Layers]: Layer.Layer.Success<Layers[k]> }[number]>
|
|
|
|
|
>
|
|
|
|
|
<A, ER, EW, RR, RW, ROut, E2, RIn>(
|
|
|
|
|
self: Lens<A, ER, EW, RR, RW>,
|
|
|
|
|
layer: Layer.Layer<ROut, E2, RIn>,
|
|
|
|
|
): Lens<A, ER | E2, EW | E2, RIn | Exclude<RR, ROut>, RIn | Exclude<RW, ROut>>
|
|
|
|
|
<A, ER, EW, RR, RW, R2>(
|
|
|
|
|
self: Lens<A, ER, EW, RR, RW>,
|
|
|
|
|
context: Context.Context<R2>,
|
|
|
|
|
): Lens<A, ER, EW, Exclude<RR, R2>, Exclude<RW, R2>>
|
|
|
|
|
} = Function.dual(2, <A, ER, EW, RR, RW>(
|
|
|
|
|
self: Lens<A, ER, EW, RR, RW>,
|
|
|
|
|
provider: unknown,
|
|
|
|
|
): Lens<A, any, any, any, any> => make({
|
|
|
|
|
get get() { return Effect.provide(self.get, provider as any) },
|
|
|
|
|
get changes() {
|
|
|
|
|
return Stream.unwrapScoped(
|
|
|
|
|
Effect.map(
|
|
|
|
|
Effect.provide(Effect.context<RR>(), provider as any),
|
|
|
|
|
(context) => Stream.provideContext(self.changes as Stream.Stream<A, ER, RR>, context),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
modify: <B, E1 = never, R1 = never>(
|
|
|
|
|
f: (a: A) => Effect.Effect<readonly [B, A], E1, R1>
|
|
|
|
|
) => Effect.provide(self.modify(f), provider as any),
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
export const provideService: {
|
|
|
|
|
<A, ER, EW, RR, RW, I, S>(
|
|
|
|
|
self: Lens<A, ER, EW, RR, RW>,
|
|
|
|
|
tag: Context.Tag<I, S>,
|
|
|
|
|