@typed/fx 2.0.0-beta.3 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Fx/Fx.d.ts +2 -2
- package/dist/Fx/Fx.d.ts.map +1 -1
- package/dist/Fx/Fx.js +5 -5
- package/dist/Fx/combinators/keyed.js +4 -4
- package/dist/Fx/combinators/provide.d.ts +9 -9
- package/dist/Fx/combinators/provide.d.ts.map +1 -1
- package/dist/Fx/combinators/provide.js +5 -5
- package/dist/Fx/combinators/scan.js +2 -2
- package/dist/Fx/combinators/switchMap.js +4 -4
- package/dist/Fx/constructors/make.js +2 -2
- package/dist/Fx/run/observe.js +2 -2
- package/dist/Push/Push.d.ts +6 -6
- package/dist/Push/Push.d.ts.map +1 -1
- package/dist/Push/Push.js +3 -3
- package/dist/RefSubject/RefSubject.d.ts +3 -3
- package/dist/RefSubject/RefSubject.d.ts.map +1 -1
- package/dist/RefSubject/RefSubject.js +8 -8
- package/dist/Sink/Sink.d.ts +4 -4
- package/dist/Sink/Sink.d.ts.map +1 -1
- package/dist/Sink/Sink.js +4 -4
- package/dist/Sink/combinators.js +1 -1
- package/dist/Subject/Subject.d.ts +3 -3
- package/dist/Subject/Subject.d.ts.map +1 -1
- package/dist/Subject/Subject.js +3 -3
- package/dist/Versioned/Versioned.d.ts +2 -2
- package/dist/Versioned/Versioned.d.ts.map +1 -1
- package/dist/Versioned/Versioned.js +4 -4
- package/package.json +9 -9
- package/src/Fx/Fx.ts +6 -6
- package/src/Fx/combinators/catch.ts +2 -2
- package/src/Fx/combinators/keyed.ts +4 -4
- package/src/Fx/combinators/provide.ts +15 -15
- package/src/Fx/combinators/scan.ts +2 -2
- package/src/Fx/combinators/switchMap.ts +4 -4
- package/src/Fx/constructors/make.ts +2 -2
- package/src/Fx/run/observe.ts +2 -2
- package/src/Fx.provide-combinators.test.ts +2 -2
- package/src/Push/Push.ts +34 -13
- package/src/RefSubject/RefSubject.ts +12 -14
- package/src/Sink/Sink.ts +7 -7
- package/src/Sink/combinators.ts +1 -1
- package/src/Subject/Subject.ts +8 -9
- package/src/Versioned/Versioned.ts +6 -8
|
@@ -75,7 +75,7 @@ export const callback = <A, E = never, R = never>(
|
|
|
75
75
|
withEarlyExit(
|
|
76
76
|
sink,
|
|
77
77
|
Effect.fn(function* <RSink = never>(sink: Sink.WithEarlyExit<A, E, RSink>) {
|
|
78
|
-
const services = yield* Effect.
|
|
78
|
+
const services = yield* Effect.context<R | RSink>();
|
|
79
79
|
const runFork = Effect.runForkWith(services);
|
|
80
80
|
const controller = new AbortController();
|
|
81
81
|
yield* Scope.addFinalizer(
|
|
@@ -94,7 +94,7 @@ export const callback = <A, E = never, R = never>(
|
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
const effect = run(emit);
|
|
97
|
-
if (effect) yield* Scope.addFinalizer(scope, Effect.
|
|
97
|
+
if (effect) yield* Scope.addFinalizer(scope, Effect.provideContext(effect, services));
|
|
98
98
|
return yield* Effect.never;
|
|
99
99
|
}),
|
|
100
100
|
),
|
package/src/Fx/run/observe.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
isEffect,
|
|
9
9
|
matchCauseEffect,
|
|
10
10
|
runForkWith,
|
|
11
|
-
|
|
11
|
+
contextWith,
|
|
12
12
|
sync,
|
|
13
13
|
void as void_,
|
|
14
14
|
} from "effect/Effect";
|
|
@@ -45,7 +45,7 @@ export const observe: {
|
|
|
45
45
|
fx: Fx<A, E, R>,
|
|
46
46
|
f: (value: A) => void | Effect<unknown, E2, R2>,
|
|
47
47
|
): Effect<unknown, E | E2, R | R2> =>
|
|
48
|
-
|
|
48
|
+
contextWith((services) =>
|
|
49
49
|
callback<void, E | E2, R | R2>((resume) => {
|
|
50
50
|
const onFailure = (cause: Cause<E | E2>) => sync(() => resume(failCause(cause)));
|
|
51
51
|
const onSuccess = (value: A) => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { assert, describe, it } from "vitest";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import { Fx } from "./index.js";
|
|
4
|
-
import * as
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
5
|
|
|
6
|
-
const Foo =
|
|
6
|
+
const Foo = Context.Service<{ readonly n: number }>("Test/Foo");
|
|
7
7
|
|
|
8
8
|
describe("Fx provideService", () => {
|
|
9
9
|
it("provides a single service and Fx can use it", () =>
|
package/src/Push/Push.ts
CHANGED
|
@@ -11,7 +11,7 @@ import * as Layer from "effect/Layer";
|
|
|
11
11
|
import * as Option from "effect/Option";
|
|
12
12
|
import { pipeArguments } from "effect/Pipeable";
|
|
13
13
|
import type * as Scope from "effect/Scope";
|
|
14
|
-
import * as
|
|
14
|
+
import * as Context from "effect/Context";
|
|
15
15
|
import * as Fx from "../Fx/index.js";
|
|
16
16
|
import { FxTypeId } from "../Fx/TypeId.js";
|
|
17
17
|
import * as Sink from "../Sink.js";
|
|
@@ -68,7 +68,7 @@ export namespace Push {
|
|
|
68
68
|
Self
|
|
69
69
|
> {
|
|
70
70
|
readonly id: Id;
|
|
71
|
-
readonly service:
|
|
71
|
+
readonly service: Context.Service<Self, Push<A, E, never, B, E2, never>>;
|
|
72
72
|
readonly make: <R = never, R2 = never>(
|
|
73
73
|
sink: Sink.Sink<A, E, R>,
|
|
74
74
|
fx: Fx.Fx<B, E2, R2>,
|
|
@@ -201,13 +201,20 @@ export const mapInput: {
|
|
|
201
201
|
f: (c: C) => Sink.Success<P>,
|
|
202
202
|
): (
|
|
203
203
|
push: P,
|
|
204
|
-
) => Push<
|
|
204
|
+
) => Push<
|
|
205
|
+
Sink.Services<P>,
|
|
206
|
+
Sink.Error<P>,
|
|
207
|
+
C,
|
|
208
|
+
Fx.Fx.Services<P>,
|
|
209
|
+
Fx.Fx.Error<P>,
|
|
210
|
+
Fx.Fx.Success<P>
|
|
211
|
+
>;
|
|
205
212
|
|
|
206
213
|
<P extends Push.Any, C>(
|
|
207
214
|
push: P,
|
|
208
215
|
f: (c: C) => Sink.Sink.Success<P>,
|
|
209
216
|
): Push<
|
|
210
|
-
Sink.Sink.
|
|
217
|
+
Sink.Sink.Services<P>,
|
|
211
218
|
Sink.Sink.Error<P>,
|
|
212
219
|
C,
|
|
213
220
|
Fx.Fx.Services<P>,
|
|
@@ -215,7 +222,7 @@ export const mapInput: {
|
|
|
215
222
|
Fx.Fx.Success<P>
|
|
216
223
|
>;
|
|
217
224
|
} = dual(2, function mapInput<P extends Push.Any, C>(push: P, f: (c: C) => Sink.Success<P>): Push<
|
|
218
|
-
Sink.
|
|
225
|
+
Sink.Services<P>,
|
|
219
226
|
Sink.Error<P>,
|
|
220
227
|
C,
|
|
221
228
|
Fx.Fx.Services<P>,
|
|
@@ -259,7 +266,14 @@ export const filterInput: {
|
|
|
259
266
|
f: (a: A) => boolean,
|
|
260
267
|
): <P extends Push.Any>(
|
|
261
268
|
push: P,
|
|
262
|
-
) => Push<
|
|
269
|
+
) => Push<
|
|
270
|
+
Sink.Services<P>,
|
|
271
|
+
Sink.Error<P>,
|
|
272
|
+
A,
|
|
273
|
+
Fx.Fx.Services<P>,
|
|
274
|
+
Fx.Fx.Error<P>,
|
|
275
|
+
Fx.Fx.Success<P>
|
|
276
|
+
>;
|
|
263
277
|
<A, E, R, B, E2, R2>(
|
|
264
278
|
push: Push<A, E, R, B, E2, R2>,
|
|
265
279
|
f: (a: A) => boolean,
|
|
@@ -308,7 +322,14 @@ export const filterMapInput: {
|
|
|
308
322
|
f: (c: C) => Option.Option<A>,
|
|
309
323
|
): <P extends Push.Any>(
|
|
310
324
|
push: P,
|
|
311
|
-
) => Push<
|
|
325
|
+
) => Push<
|
|
326
|
+
C,
|
|
327
|
+
Sink.Error<P>,
|
|
328
|
+
Sink.Services<P>,
|
|
329
|
+
Fx.Fx.Success<P>,
|
|
330
|
+
Fx.Fx.Error<P>,
|
|
331
|
+
Fx.Fx.Services<P>
|
|
332
|
+
>;
|
|
312
333
|
<A, E, R, B, E2, R2, C>(
|
|
313
334
|
push: Push<A, E, R, B, E2, R2>,
|
|
314
335
|
f: (c: C) => Option.Option<A>,
|
|
@@ -1015,7 +1036,7 @@ export const mapAccumEffect: {
|
|
|
1015
1036
|
|
|
1016
1037
|
export function Service<Self, A, E = never, B = never, E2 = never>() {
|
|
1017
1038
|
return <const Id extends string>(id: Id): Push.Class<Self, Id, A, E, B, E2> => {
|
|
1018
|
-
const service =
|
|
1039
|
+
const service = Context.Service<Self, Push<A, E, never, B, E2, never>>(id);
|
|
1019
1040
|
|
|
1020
1041
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
1021
1042
|
return class PushService {
|
|
@@ -1028,17 +1049,17 @@ export function Service<Self, A, E = never, B = never, E2 = never>() {
|
|
|
1028
1049
|
): Layer.Layer<Self, never, Exclude<R | R2, Scope.Scope>> =>
|
|
1029
1050
|
Layer.effect(
|
|
1030
1051
|
service,
|
|
1031
|
-
Effect.
|
|
1052
|
+
Effect.context<R | R2>().pipe(
|
|
1032
1053
|
Effect.map((services) =>
|
|
1033
1054
|
make(
|
|
1034
1055
|
Sink.make(
|
|
1035
|
-
(cause) => Effect.
|
|
1036
|
-
(value) => Effect.
|
|
1056
|
+
(cause) => Effect.provideContext(sink.onFailure(cause), services),
|
|
1057
|
+
(value) => Effect.provideContext(sink.onSuccess(value), services),
|
|
1037
1058
|
),
|
|
1038
1059
|
Fx.make(<RSink>(sink: Sink.Sink<B, E2, RSink>) =>
|
|
1039
|
-
Effect.
|
|
1060
|
+
Effect.context<RSink>().pipe(
|
|
1040
1061
|
Effect.flatMap((services2) =>
|
|
1041
|
-
Effect.
|
|
1062
|
+
Effect.provideContext(fx.run(sink), Context.merge(services, services2)),
|
|
1042
1063
|
),
|
|
1043
1064
|
),
|
|
1044
1065
|
),
|
|
@@ -16,7 +16,7 @@ import { sum } from "effect/Number";
|
|
|
16
16
|
import * as Option from "effect/Option";
|
|
17
17
|
import { pipeArguments } from "effect/Pipeable";
|
|
18
18
|
import * as Scope from "effect/Scope";
|
|
19
|
-
import * as
|
|
19
|
+
import * as Context from "effect/Context";
|
|
20
20
|
import * as Stream from "effect/Stream";
|
|
21
21
|
import { compact as fxCompact } from "../Fx/combinators/compact.js";
|
|
22
22
|
import { continueWith } from "../Fx/combinators/continueWith.js";
|
|
@@ -291,7 +291,7 @@ export declare namespace RefSubject {
|
|
|
291
291
|
export interface Service<Self, Id extends string, A, E> extends RefSubject<A, E, Self> {
|
|
292
292
|
readonly id: Id;
|
|
293
293
|
|
|
294
|
-
readonly service:
|
|
294
|
+
readonly service: Context.Service<Self, RefSubject<A, E>>;
|
|
295
295
|
|
|
296
296
|
readonly make: <R = never>(
|
|
297
297
|
value: A | Effect.Effect<A, E, R> | Fx<A, E, R>,
|
|
@@ -307,14 +307,12 @@ export declare namespace RefSubject {
|
|
|
307
307
|
new (): RefSubject.Service<Self, Id, A, E>;
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
|
-
export const CurrentComputedBehavior =
|
|
310
|
+
export const CurrentComputedBehavior = Context.Reference("@typed/fx/CurrentComputedBehavior", {
|
|
311
311
|
defaultValue: (): "one" | "multiple" => "multiple",
|
|
312
312
|
});
|
|
313
313
|
|
|
314
|
-
const checkIsMultiple = (
|
|
315
|
-
ctx
|
|
316
|
-
): ctx is ServiceMap.ServiceMap<"multiple"> =>
|
|
317
|
-
ServiceMap.getReferenceUnsafe(ctx, CurrentComputedBehavior) === "multiple";
|
|
314
|
+
const checkIsMultiple = (ctx: Context.Context<any>): ctx is Context.Context<"multiple"> =>
|
|
315
|
+
Context.getReferenceUnsafe(ctx, CurrentComputedBehavior) === "multiple";
|
|
318
316
|
|
|
319
317
|
class ComputedImpl<R0, E0, A, E, R, E2, R2, C, E3, R3>
|
|
320
318
|
extends Versioned.VersionedTransform<
|
|
@@ -352,7 +350,7 @@ class ComputedImpl<R0, E0, A, E, R, E2, R2, C, E3, R3>
|
|
|
352
350
|
|
|
353
351
|
this._computed = Subject.hold(
|
|
354
352
|
unwrap(
|
|
355
|
-
Effect.map(Effect.
|
|
353
|
+
Effect.map(Effect.context(), (ctx) => {
|
|
356
354
|
if (checkIsMultiple(ctx)) {
|
|
357
355
|
return fromYieldable(input).pipe(
|
|
358
356
|
continueWith(() => input),
|
|
@@ -426,7 +424,7 @@ class FilteredImpl<R0, E0, A, E, R, E2, R2, C, E3, R3>
|
|
|
426
424
|
|
|
427
425
|
this._computed = Subject.hold(
|
|
428
426
|
unwrap(
|
|
429
|
-
Effect.map(Effect.
|
|
427
|
+
Effect.map(Effect.context(), (ctx) => {
|
|
430
428
|
if (checkIsMultiple(ctx)) {
|
|
431
429
|
return fromYieldable(input).pipe(
|
|
432
430
|
continueWith(() => input),
|
|
@@ -457,14 +455,14 @@ class FilteredImpl<R0, E0, A, E, R, E2, R2, C, E3, R3>
|
|
|
457
455
|
class RefSubjectCore<A, E, R, R2> {
|
|
458
456
|
readonly initial: Effect.Effect<A, E, R>;
|
|
459
457
|
readonly subject: Subject.HoldSubjectImpl<A, E>;
|
|
460
|
-
readonly services:
|
|
458
|
+
readonly services: Context.Context<R2>;
|
|
461
459
|
readonly scope: Scope.Closeable;
|
|
462
460
|
readonly deferredRef: DeferredRef.DeferredRef<E, A>;
|
|
463
461
|
readonly semaphore: Semaphore.Semaphore;
|
|
464
462
|
constructor(
|
|
465
463
|
initial: Effect.Effect<A, E, R>,
|
|
466
464
|
subject: Subject.HoldSubjectImpl<A, E>,
|
|
467
|
-
services:
|
|
465
|
+
services: Context.Context<R2>,
|
|
468
466
|
scope: Scope.Closeable,
|
|
469
467
|
deferredRef: DeferredRef.DeferredRef<E, A>,
|
|
470
468
|
semaphore: Semaphore.Semaphore,
|
|
@@ -766,8 +764,8 @@ function makeCore<A, E, R>(
|
|
|
766
764
|
deferredRef?: DeferredRef.DeferredRef<E, A>,
|
|
767
765
|
) {
|
|
768
766
|
return Effect.gen(function* () {
|
|
769
|
-
const services = yield* Effect.
|
|
770
|
-
const scope = yield* Scope.fork(
|
|
767
|
+
const services = yield* Effect.context<R | Scope.Scope>();
|
|
768
|
+
const scope = yield* Scope.fork(Context.get(services, Scope.Scope));
|
|
771
769
|
const id = yield* Effect.withFiber((fiber) => Effect.succeed(fiber.id));
|
|
772
770
|
const subject = new Subject.HoldSubjectImpl<A, E>();
|
|
773
771
|
const core = new RefSubjectCore(
|
|
@@ -1335,7 +1333,7 @@ const Variance: Fx.Variance<any, any, any> = {
|
|
|
1335
1333
|
|
|
1336
1334
|
export function Service<Self, A, E = never>() {
|
|
1337
1335
|
return <const Id extends string>(id: Id): RefSubject.Class<Self, Id, A, E> => {
|
|
1338
|
-
const service =
|
|
1336
|
+
const service = Context.Service<Self, RefSubject<A, E>>(id);
|
|
1339
1337
|
|
|
1340
1338
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
1341
1339
|
return class RefSubjectService {
|
package/src/Sink/Sink.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type * as Cause from "effect/Cause";
|
|
2
2
|
import type { Effect } from "effect/Effect";
|
|
3
|
-
import { flatMap, map, provide,
|
|
3
|
+
import { flatMap, map, provide, context } from "effect/Effect";
|
|
4
4
|
import type { Layer } from "effect/Layer";
|
|
5
5
|
import { effect } from "effect/Layer";
|
|
6
6
|
import type { Ref } from "effect/Ref";
|
|
7
7
|
import type { Scope } from "effect/Scope";
|
|
8
|
-
import * as
|
|
8
|
+
import * as Context from "effect/Context";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* A Sink is a consumer of values. It consists of two effectful callbacks:
|
|
@@ -46,11 +46,11 @@ export declare namespace Sink {
|
|
|
46
46
|
* @since 1.0.0
|
|
47
47
|
* @category type-level
|
|
48
48
|
*/
|
|
49
|
-
export type
|
|
49
|
+
export type Services<T> = T extends Sink<infer _A, infer _E, infer _R> ? _R : never;
|
|
50
50
|
|
|
51
51
|
export interface Service<Self, Id extends string, A, E> extends Sink<A, E, Self> {
|
|
52
52
|
readonly id: Id;
|
|
53
|
-
readonly service:
|
|
53
|
+
readonly service: Context.Service<Self, Sink<A, E>>;
|
|
54
54
|
readonly make: <R = never>(
|
|
55
55
|
onFailure: (cause: Cause.Cause<E>) => Effect<unknown, never, R>,
|
|
56
56
|
onSuccess: (value: A) => Effect<unknown, never, R>,
|
|
@@ -64,7 +64,7 @@ export declare namespace Sink {
|
|
|
64
64
|
|
|
65
65
|
export type Success<T> = Sink.Success<T>;
|
|
66
66
|
export type Error<T> = Sink.Error<T>;
|
|
67
|
-
export type
|
|
67
|
+
export type Services<T> = Sink.Services<T>;
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* Creates a Sink from success and failure callbacks.
|
|
@@ -124,7 +124,7 @@ export declare namespace Sink {
|
|
|
124
124
|
|
|
125
125
|
export function Service<Self, A, E = never>() {
|
|
126
126
|
return <const Id extends string>(id: Id): Sink.Class<Self, Id, A, E> => {
|
|
127
|
-
const service =
|
|
127
|
+
const service = Context.Service<Self, Sink<A, E>>(id);
|
|
128
128
|
|
|
129
129
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
130
130
|
return class SinkService {
|
|
@@ -137,7 +137,7 @@ export function Service<Self, A, E = never>() {
|
|
|
137
137
|
): Layer<Self, never, Exclude<R | R2, Scope>> =>
|
|
138
138
|
effect(
|
|
139
139
|
service,
|
|
140
|
-
map(
|
|
140
|
+
map(context<R | R2>(), (context) =>
|
|
141
141
|
make(
|
|
142
142
|
(cause) => provide(onFailure(cause), context),
|
|
143
143
|
(value) => provide(onSuccess(value), context),
|
package/src/Sink/combinators.ts
CHANGED
|
@@ -219,7 +219,7 @@ export function withEarlyExit<A, E, R, R2>(
|
|
|
219
219
|
params: { signal: AbortSignal; scheduler: Scheduler },
|
|
220
220
|
) => Effect.Effect<unknown, never, R2>,
|
|
221
221
|
): Effect.Effect<void, never, R | R2> {
|
|
222
|
-
return Effect.
|
|
222
|
+
return Effect.contextWith((services) =>
|
|
223
223
|
Effect.callback<unknown, never, R2>(function (this: Scheduler, resume, signal) {
|
|
224
224
|
let exited = false;
|
|
225
225
|
const earlyExit = Effect.sync<void>(() => {
|
package/src/Subject/Subject.ts
CHANGED
|
@@ -8,7 +8,7 @@ import * as MutableRef from "effect/MutableRef";
|
|
|
8
8
|
import * as Option from "effect/Option";
|
|
9
9
|
import { pipeArguments } from "effect/Pipeable";
|
|
10
10
|
import * as Scope from "effect/Scope";
|
|
11
|
-
import * as
|
|
11
|
+
import * as Context from "effect/Context";
|
|
12
12
|
import type * as Fx from "../Fx/index.js";
|
|
13
13
|
import { RingBuffer } from "../Fx/internal/ring-buffer.js";
|
|
14
14
|
import { awaitScopeClose, withExtendedScope } from "../Fx/internal/scope.js";
|
|
@@ -37,7 +37,7 @@ export interface Subject<A, E = never, R = never>
|
|
|
37
37
|
export declare namespace Subject {
|
|
38
38
|
export interface Service<Self, Id extends string, A, E> extends Subject<A, E, Self> {
|
|
39
39
|
readonly id: Id;
|
|
40
|
-
readonly service:
|
|
40
|
+
readonly service: Context.Service<Self, Subject<A, E>>;
|
|
41
41
|
readonly make: (replay?: number) => Layer.Layer<Self, never, Scope.Scope>;
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -191,9 +191,8 @@ const DISCARD = { discard: true } as const;
|
|
|
191
191
|
*/
|
|
192
192
|
export class SubjectImpl<A, E> implements Subject<A, E> {
|
|
193
193
|
readonly [FxTypeId]: Fx.Fx.Variance<A, E, Scope.Scope> = VARIANCE;
|
|
194
|
-
protected sinks: Set<
|
|
195
|
-
|
|
196
|
-
> = new Set();
|
|
194
|
+
protected sinks: Set<readonly [Sink.Sink<A, E, any>, Context.Context<any>, Scope.Closeable]> =
|
|
195
|
+
new Set();
|
|
197
196
|
|
|
198
197
|
constructor() {
|
|
199
198
|
this.onFailure = this.onFailure.bind(this);
|
|
@@ -232,7 +231,7 @@ export class SubjectImpl<A, E> implements Subject<A, E> {
|
|
|
232
231
|
): Effect.Effect<B, never, R2 | Scope.Scope> {
|
|
233
232
|
return withExtendedScope(
|
|
234
233
|
(innerScope) =>
|
|
235
|
-
Effect.
|
|
234
|
+
Effect.contextWith((ctx) => {
|
|
236
235
|
const entry = [sink, ctx, innerScope] as const;
|
|
237
236
|
this.sinks.add(entry);
|
|
238
237
|
const remove = Effect.sync(() => this.sinks.delete(entry));
|
|
@@ -272,7 +271,7 @@ export class SubjectImpl<A, E> implements Subject<A, E> {
|
|
|
272
271
|
|
|
273
272
|
function runSinkEvent<A, E>(
|
|
274
273
|
sink: Sink.Sink<A, E, any>,
|
|
275
|
-
ctx:
|
|
274
|
+
ctx: Context.Context<any>,
|
|
276
275
|
a: A,
|
|
277
276
|
): Effect.Effect<void, never, never> {
|
|
278
277
|
return Effect.provide(Effect.catchCause(sink.onSuccess(a), sink.onFailure), ctx);
|
|
@@ -280,7 +279,7 @@ function runSinkEvent<A, E>(
|
|
|
280
279
|
|
|
281
280
|
function runSinkCause<A, E>(
|
|
282
281
|
sink: Sink.Sink<A, E, any>,
|
|
283
|
-
ctx:
|
|
282
|
+
ctx: Context.Context<any>,
|
|
284
283
|
scope: Scope.Closeable,
|
|
285
284
|
cause: Cause.Cause<E>,
|
|
286
285
|
): Effect.Effect<void, never, never> {
|
|
@@ -398,7 +397,7 @@ export function make<A, E = never>(
|
|
|
398
397
|
|
|
399
398
|
export function Service<Self, A, E = never>() {
|
|
400
399
|
return <const Id extends string>(id: Id): Subject.Class<Self, Id, A, E> => {
|
|
401
|
-
const service =
|
|
400
|
+
const service = Context.Service<Self, Subject<A, E>>(id);
|
|
402
401
|
|
|
403
402
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
404
403
|
return class SubjectService {
|
|
@@ -16,14 +16,14 @@ import { sum } from "effect/Number";
|
|
|
16
16
|
import * as Option from "effect/Option";
|
|
17
17
|
import { pipeArguments } from "effect/Pipeable";
|
|
18
18
|
import type * as Scope from "effect/Scope";
|
|
19
|
-
import * as
|
|
19
|
+
import * as Context from "effect/Context";
|
|
20
20
|
import { filterMap as fxFilterMap } from "../Fx/combinators/filterMap.js";
|
|
21
21
|
import { filterMapEffect as fxFilterMapEffect } from "../Fx/combinators/filterMapEffect.js";
|
|
22
22
|
import { map as fxMap } from "../Fx/combinators/map.js";
|
|
23
23
|
import { mapEffect as fxMapEffect } from "../Fx/combinators/mapEffect.js";
|
|
24
24
|
import {
|
|
25
25
|
provide as fxProvide,
|
|
26
|
-
|
|
26
|
+
provideContext as fxprovideContext,
|
|
27
27
|
} from "../Fx/combinators/provide.js";
|
|
28
28
|
import { struct as fxStruct, tuple as fxTuple } from "../Fx/combinators/tuple.js";
|
|
29
29
|
import { succeed as fxSucceed } from "../Fx/constructors/succeed.js";
|
|
@@ -92,7 +92,7 @@ export namespace Versioned {
|
|
|
92
92
|
Self
|
|
93
93
|
> {
|
|
94
94
|
readonly id: Id;
|
|
95
|
-
readonly service:
|
|
95
|
+
readonly service: Context.Service<Self, Versioned<never, E1, A2, E2, never, A3, E3, never>>;
|
|
96
96
|
readonly make: <R1 = never, R2 = never, R3 = never>(
|
|
97
97
|
version: Effect.Effect<number, E1, R1>,
|
|
98
98
|
fx: Fx.Fx<A2, E2, R2>,
|
|
@@ -545,9 +545,7 @@ const VARIANCE = {
|
|
|
545
545
|
|
|
546
546
|
export function Service<Self, E1 = never, A2 = never, E2 = never, A3 = never, E3 = never>() {
|
|
547
547
|
return <const Id extends string>(id: Id): Versioned.Class<Self, Id, E1, A2, E2, A3, E3> => {
|
|
548
|
-
const service =
|
|
549
|
-
id,
|
|
550
|
-
);
|
|
548
|
+
const service = Context.Service<Self, Versioned<never, E1, A2, E2, never, A3, E3, never>>(id);
|
|
551
549
|
|
|
552
550
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
553
551
|
return class VersionedService {
|
|
@@ -561,11 +559,11 @@ export function Service<Self, E1 = never, A2 = never, E2 = never, A3 = never, E3
|
|
|
561
559
|
): Layer.Layer<Self, never, Exclude<R1 | R2 | R3, Scope.Scope>> =>
|
|
562
560
|
Layer.effect(
|
|
563
561
|
service,
|
|
564
|
-
Effect.
|
|
562
|
+
Effect.context<R1 | R2 | R3>().pipe(
|
|
565
563
|
Effect.map((context) =>
|
|
566
564
|
make(
|
|
567
565
|
Effect.provide(version, context),
|
|
568
|
-
|
|
566
|
+
fxprovideContext(fx, context),
|
|
569
567
|
Effect.provide(effect.asEffect(), context),
|
|
570
568
|
),
|
|
571
569
|
),
|