@typed/fx 1.3.0 → 1.4.1

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.
Files changed (72) hide show
  1. package/dist/Subject/RefSubject.js +2 -2
  2. package/dist/Subject/RefSubject.js.map +1 -1
  3. package/dist/cjs/Subject/RefSubject.js +2 -2
  4. package/dist/cjs/Subject/RefSubject.js.map +1 -1
  5. package/dist/cjs/constructor/index.d.ts +0 -1
  6. package/dist/cjs/constructor/index.d.ts.map +1 -1
  7. package/dist/cjs/constructor/index.js +0 -1
  8. package/dist/cjs/constructor/index.js.map +1 -1
  9. package/dist/cjs/constructor/serviceWith.d.ts +1 -1
  10. package/dist/cjs/constructor/serviceWith.d.ts.map +1 -1
  11. package/dist/cjs/constructor/serviceWith.js +1 -1
  12. package/dist/cjs/constructor/serviceWith.js.map +1 -1
  13. package/dist/cjs/constructor/serviceWithEffect.d.ts +1 -1
  14. package/dist/cjs/constructor/serviceWithEffect.d.ts.map +1 -1
  15. package/dist/cjs/constructor/serviceWithEffect.js +1 -1
  16. package/dist/cjs/constructor/serviceWithEffect.js.map +1 -1
  17. package/dist/cjs/constructor/serviceWithFx.d.ts +1 -1
  18. package/dist/cjs/constructor/serviceWithFx.d.ts.map +1 -1
  19. package/dist/cjs/constructor/serviceWithFx.js +1 -1
  20. package/dist/cjs/constructor/serviceWithFx.js.map +1 -1
  21. package/dist/cjs/operator/provideService.d.ts +1 -1
  22. package/dist/cjs/operator/provideService.d.ts.map +1 -1
  23. package/dist/cjs/operator/provideService.js.map +1 -1
  24. package/dist/cjs/operator/provideServiceEffect.d.ts +1 -1
  25. package/dist/cjs/operator/provideServiceEffect.d.ts.map +1 -1
  26. package/dist/cjs/operator/provideServiceEffect.js.map +1 -1
  27. package/dist/cjs/operator/provideSomeLayer.js +1 -1
  28. package/dist/cjs/operator/provideSomeLayer.js.map +1 -1
  29. package/dist/cjs/operator/race.js +1 -1
  30. package/dist/cjs/operator/race.js.map +1 -1
  31. package/dist/constructor/index.d.ts +0 -1
  32. package/dist/constructor/index.d.ts.map +1 -1
  33. package/dist/constructor/index.js +0 -1
  34. package/dist/constructor/index.js.map +1 -1
  35. package/dist/constructor/service.d.ts +1 -1
  36. package/dist/constructor/service.d.ts.map +1 -1
  37. package/dist/constructor/service.js.map +1 -1
  38. package/dist/constructor/serviceWith.d.ts +1 -1
  39. package/dist/constructor/serviceWith.d.ts.map +1 -1
  40. package/dist/constructor/serviceWith.js +1 -1
  41. package/dist/constructor/serviceWith.js.map +1 -1
  42. package/dist/constructor/serviceWithEffect.d.ts +1 -1
  43. package/dist/constructor/serviceWithEffect.d.ts.map +1 -1
  44. package/dist/constructor/serviceWithEffect.js +1 -1
  45. package/dist/constructor/serviceWithEffect.js.map +1 -1
  46. package/dist/constructor/serviceWithFx.d.ts +1 -1
  47. package/dist/constructor/serviceWithFx.d.ts.map +1 -1
  48. package/dist/constructor/serviceWithFx.js +1 -1
  49. package/dist/constructor/serviceWithFx.js.map +1 -1
  50. package/dist/operator/provideService.d.ts +1 -1
  51. package/dist/operator/provideService.d.ts.map +1 -1
  52. package/dist/operator/provideService.js.map +1 -1
  53. package/dist/operator/provideServiceEffect.d.ts +1 -1
  54. package/dist/operator/provideServiceEffect.d.ts.map +1 -1
  55. package/dist/operator/provideServiceEffect.js.map +1 -1
  56. package/dist/operator/provideSomeLayer.js +1 -1
  57. package/dist/operator/provideSomeLayer.js.map +1 -1
  58. package/dist/operator/race.js +1 -1
  59. package/dist/operator/race.js.map +1 -1
  60. package/dist/tsconfig.cjs.build.tsbuildinfo +1 -1
  61. package/package.json +4 -4
  62. package/src/Subject/RefSubject.ts +2 -2
  63. package/src/constructor/index.ts +0 -1
  64. package/src/constructor/serviceWith.ts +2 -2
  65. package/src/constructor/serviceWithEffect.ts +4 -4
  66. package/src/constructor/serviceWithFx.ts +5 -5
  67. package/src/operator/provideService.ts +10 -6
  68. package/src/operator/provideServiceEffect.ts +9 -9
  69. package/src/operator/provideSomeLayer.ts +1 -1
  70. package/src/operator/race.ts +1 -1
  71. package/tsconfig.build.tsbuildinfo +1 -1
  72. package/src/constructor/service.ts +0 -9
@@ -55,7 +55,7 @@ export namespace RefSubject {
55
55
  const currentValue = getValue()
56
56
  const [b, a] = f(currentValue)
57
57
 
58
- MutableRef.set(current, (Option.some(a)))
58
+ MutableRef.set(current, Option.some(a))
59
59
 
60
60
  if (eq(currentValue, a)) {
61
61
  return Effect.succeed(b)
@@ -82,7 +82,7 @@ export namespace RefSubject {
82
82
  delete: Effect.sync(() => {
83
83
  const option = MutableRef.get(current)
84
84
  const reset = initial()
85
- MutableRef.set(current, (Option.some(reset)))
85
+ MutableRef.set(current, Option.some(reset))
86
86
 
87
87
  return Option.getOrElse(option, () => reset)
88
88
  }),
@@ -31,7 +31,6 @@ export * from './promiseAbort.js'
31
31
  export * from './promiseFx.js'
32
32
  export * from './random.js'
33
33
  export * from './scheduled.js'
34
- export * from './service.js'
35
34
  export * from './serviceWith.js'
36
35
  export * from './serviceWithEffect.js'
37
36
  export * from './serviceWithFx.js'
@@ -5,6 +5,6 @@ import type { Fx } from '../Fx.js'
5
5
 
6
6
  import { fromEffect } from './fromEffect.js'
7
7
 
8
- export const serviceWith: <T>(tag: Tag<T>) => <A>(f: (a: T) => A) => Fx<T, never, A> =
8
+ export const serviceWith: <I, T>(tag: Tag<I, T>) => <A>(f: (a: T) => A) => Fx<I, never, A> =
9
9
  (tag) => (f) =>
10
- fromEffect(Effect.serviceWith(tag, f))
10
+ fromEffect(Effect.map(tag, f))
@@ -5,7 +5,7 @@ import type { Fx } from '../Fx.js'
5
5
 
6
6
  import { fromEffect } from './fromEffect.js'
7
7
 
8
- export const serviceWithEffect: <T>(
9
- tag: Tag<T>,
10
- ) => <R, E, A>(f: (a: T) => Effect.Effect<R, E, A>) => Fx<T | R, E, A> = (tag) => (f) =>
11
- fromEffect(Effect.serviceWithEffect(tag, f))
8
+ export const serviceWithEffect: <I, T>(
9
+ tag: Tag<I, T>,
10
+ ) => <R, E, A>(f: (a: T) => Effect.Effect<R, E, A>) => Fx<I | R, E, A> = (tag) => (f) =>
11
+ fromEffect(Effect.flatMap(tag, f))
@@ -4,16 +4,16 @@ import * as Effect from '@effect/io/Effect'
4
4
  import { Fx } from '../Fx.js'
5
5
 
6
6
  export const serviceWithFx =
7
- <T>(tag: Tag<T>) =>
8
- <R, E, A>(f: (t: T) => Fx<R, E, A>): Fx<T | R, E, A> =>
7
+ <I, S>(tag: Tag<I, S>) =>
8
+ <R, E, A>(f: (s: S) => Fx<R, E, A>): Fx<I | R, E, A> =>
9
9
  new ServiceWithFx(tag, f)
10
10
 
11
- class ServiceWithFx<T, R, E, A> extends Fx.Variance<T | R, E, A> implements Fx<T | R, E, A> {
12
- constructor(readonly tag: Tag<T>, readonly f: (a: T) => Fx<R, E, A>) {
11
+ class ServiceWithFx<I, S, R, E, A> extends Fx.Variance<I | R, E, A> implements Fx<I | R, E, A> {
12
+ constructor(readonly tag: Tag<I, S>, readonly f: (a: S) => Fx<R, E, A>) {
13
13
  super()
14
14
  }
15
15
 
16
16
  run<R2>(sink: Fx.Sink<R2, E, A>) {
17
- return Effect.serviceWithEffect(this.tag, (a) => this.f(a).run(sink))
17
+ return Effect.flatMap(this.tag, (a) => this.f(a).run(sink))
18
18
  }
19
19
  }
@@ -4,18 +4,22 @@ import * as Effect from '@effect/io/Effect'
4
4
 
5
5
  import { Fx } from '../Fx.js'
6
6
 
7
- export function provideService<S>(tag: Context.Tag<S>) {
7
+ export function provideService<I, S>(tag: Context.Tag<I, S>) {
8
8
  return (service: S) => {
9
- return <R, E, A>(self: Fx<R | S, E, A>): Fx<Exclude<R, S>, E, A> =>
9
+ return <R, E, A>(self: Fx<R | I, E, A>): Fx<Exclude<R, I>, E, A> =>
10
10
  new ProvideServiceFx(self, tag, service)
11
11
  }
12
12
  }
13
13
 
14
- class ProvideServiceFx<R, E, A, S>
15
- extends Fx.Variance<Exclude<R, S>, E, A>
16
- implements Fx<Exclude<R, S>, E, A>
14
+ class ProvideServiceFx<R, E, A, I, S>
15
+ extends Fx.Variance<Exclude<R, I>, E, A>
16
+ implements Fx<Exclude<R, I>, E, A>
17
17
  {
18
- constructor(readonly self: Fx<R | S, E, A>, readonly tag: Context.Tag<S>, readonly service: S) {
18
+ constructor(
19
+ readonly self: Fx<R | I, E, A>,
20
+ readonly tag: Context.Tag<I, S>,
21
+ readonly service: S,
22
+ ) {
19
23
  super()
20
24
  }
21
25
 
@@ -5,21 +5,21 @@ import type { Scope } from '@effect/io/Scope'
5
5
 
6
6
  import { Fx } from '../Fx.js'
7
7
 
8
- export function provideServiceEffect<S, R2, E2>(
9
- tag: Context.Tag<S>,
8
+ export function provideServiceEffect<I, S, R2, E2>(
9
+ tag: Context.Tag<I, S>,
10
10
  service: Effect.Effect<R2, E2, S>,
11
11
  ) {
12
- return <R, E, A>(self: Fx<R | S, E, A>): Fx<Exclude<R | R2, S>, E | E2, A> =>
12
+ return <R, E, A>(self: Fx<R | I, E, A>): Fx<Exclude<R | R2, I>, E | E2, A> =>
13
13
  new ProvideServiceEffectFx(self, tag, service)
14
14
  }
15
15
 
16
- class ProvideServiceEffectFx<R, E, A, R2, E2, S>
17
- extends Fx.Variance<Exclude<R | R2, S>, E | E2, A>
18
- implements Fx<Exclude<R | R2, S>, E | E2, A>
16
+ class ProvideServiceEffectFx<R, E, A, R2, E2, I, S>
17
+ extends Fx.Variance<Exclude<R | R2, I>, E | E2, A>
18
+ implements Fx<Exclude<R | R2, I>, E | E2, A>
19
19
  {
20
20
  constructor(
21
- readonly self: Fx<R | S, E, A>,
22
- readonly tag: Context.Tag<S>,
21
+ readonly self: Fx<R | I, E, A>,
22
+ readonly tag: Context.Tag<I, S>,
23
23
  readonly service: Effect.Effect<R2, E2, S>,
24
24
  ) {
25
25
  super()
@@ -30,6 +30,6 @@ class ProvideServiceEffectFx<R, E, A, R2, E2, S>
30
30
  this.self.run(sink),
31
31
  Effect.provideServiceEffect(this.tag, this.service),
32
32
  Effect.matchCauseEffect(sink.error, Effect.succeed),
33
- ) as Effect.Effect<Exclude<R | R2 | R3 | Scope, S>, never, unknown>
33
+ ) as Effect.Effect<Exclude<R | R2 | R3 | Scope, I>, never, unknown>
34
34
  }
35
35
  }
@@ -20,7 +20,7 @@ class ProvideSomeLayerFx<R, E, A, R2, E2, S>
20
20
  run<R3>(sink: Fx.Sink<R3, E | E2, A>) {
21
21
  return pipe(
22
22
  Effect.provideSomeLayer(this.layer)(this.self.run(sink)),
23
- Effect.matchCauseEffect(sink.error, Effect.succeed),
23
+ Effect.catchAllCause(sink.error),
24
24
  )
25
25
  }
26
26
  }
@@ -57,7 +57,7 @@ class RaceAllFx<Streams extends readonly Fx<any, any, any>[]>
57
57
  run(sink.event, sink.error, sink.end),
58
58
  Effect.scheduleForked(asap), // Schedule starts so that all Scopes can be returned *before* attempting to cleanup
59
59
  Effect.as(scope),
60
- Effect.provideService(Scope.Tag, scope),
60
+ Effect.provideService(Scope.Scope, scope),
61
61
  ),
62
62
  ),
63
63
  ),