effect 3.4.9 → 3.5.0

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 (159) hide show
  1. package/RcMap/package.json +6 -0
  2. package/RcRef/package.json +6 -0
  3. package/dist/cjs/Cause.js +22 -1
  4. package/dist/cjs/Cause.js.map +1 -1
  5. package/dist/cjs/Channel.js.map +1 -1
  6. package/dist/cjs/Config.js.map +1 -1
  7. package/dist/cjs/Console.js.map +1 -1
  8. package/dist/cjs/Data.js +3 -1
  9. package/dist/cjs/Data.js.map +1 -1
  10. package/dist/cjs/Duration.js +23 -2
  11. package/dist/cjs/Duration.js.map +1 -1
  12. package/dist/cjs/Logger.js +11 -1
  13. package/dist/cjs/Logger.js.map +1 -1
  14. package/dist/cjs/PubSub.js.map +1 -1
  15. package/dist/cjs/Random.js +9 -1
  16. package/dist/cjs/Random.js.map +1 -1
  17. package/dist/cjs/RcMap.js +52 -0
  18. package/dist/cjs/RcMap.js.map +1 -0
  19. package/dist/cjs/RcRef.js +51 -0
  20. package/dist/cjs/RcRef.js.map +1 -0
  21. package/dist/cjs/Stream.js +29 -2
  22. package/dist/cjs/Stream.js.map +1 -1
  23. package/dist/cjs/index.js +6 -2
  24. package/dist/cjs/index.js.map +1 -1
  25. package/dist/cjs/internal/cause.js +21 -5
  26. package/dist/cjs/internal/cause.js.map +1 -1
  27. package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
  28. package/dist/cjs/internal/channel.js.map +1 -1
  29. package/dist/cjs/internal/core-effect.js +0 -5
  30. package/dist/cjs/internal/core-effect.js.map +1 -1
  31. package/dist/cjs/internal/core.js +15 -10
  32. package/dist/cjs/internal/core.js.map +1 -1
  33. package/dist/cjs/internal/defaultServices.js +1 -1
  34. package/dist/cjs/internal/defaultServices.js.map +1 -1
  35. package/dist/cjs/internal/fiberRuntime.js +3 -1
  36. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  37. package/dist/cjs/internal/logger.js +128 -27
  38. package/dist/cjs/internal/logger.js.map +1 -1
  39. package/dist/cjs/internal/pubsub.js +216 -36
  40. package/dist/cjs/internal/pubsub.js.map +1 -1
  41. package/dist/cjs/internal/random.js +2 -1
  42. package/dist/cjs/internal/random.js.map +1 -1
  43. package/dist/cjs/internal/rcMap.js +129 -0
  44. package/dist/cjs/internal/rcMap.js.map +1 -0
  45. package/dist/cjs/internal/rcRef.js +122 -0
  46. package/dist/cjs/internal/rcRef.js.map +1 -0
  47. package/dist/cjs/internal/stream.js +57 -11
  48. package/dist/cjs/internal/stream.js.map +1 -1
  49. package/dist/cjs/internal/version.js +1 -1
  50. package/dist/dts/Cause.d.ts +40 -1
  51. package/dist/dts/Cause.d.ts.map +1 -1
  52. package/dist/dts/Channel.d.ts +3 -3
  53. package/dist/dts/Channel.d.ts.map +1 -1
  54. package/dist/dts/Config.d.ts +5 -0
  55. package/dist/dts/Config.d.ts.map +1 -1
  56. package/dist/dts/Console.d.ts +2 -4
  57. package/dist/dts/Console.d.ts.map +1 -1
  58. package/dist/dts/Duration.d.ts +5 -0
  59. package/dist/dts/Duration.d.ts.map +1 -1
  60. package/dist/dts/Logger.d.ts +15 -0
  61. package/dist/dts/Logger.d.ts.map +1 -1
  62. package/dist/dts/PubSub.d.ts +15 -4
  63. package/dist/dts/PubSub.d.ts.map +1 -1
  64. package/dist/dts/Random.d.ts +8 -0
  65. package/dist/dts/Random.d.ts.map +1 -1
  66. package/dist/dts/RcMap.d.ts +93 -0
  67. package/dist/dts/RcMap.d.ts.map +1 -0
  68. package/dist/dts/RcRef.d.ts +83 -0
  69. package/dist/dts/RcRef.d.ts.map +1 -0
  70. package/dist/dts/Stream.d.ts +64 -26
  71. package/dist/dts/Stream.d.ts.map +1 -1
  72. package/dist/dts/index.d.ts +8 -0
  73. package/dist/dts/index.d.ts.map +1 -1
  74. package/dist/dts/internal/core-effect.d.ts.map +1 -1
  75. package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
  76. package/dist/dts/internal/logger.d.ts.map +1 -1
  77. package/dist/dts/internal/random.d.ts +1 -1
  78. package/dist/dts/internal/random.d.ts.map +1 -1
  79. package/dist/dts/internal/rcMap.d.ts +2 -0
  80. package/dist/dts/internal/rcMap.d.ts.map +1 -0
  81. package/dist/dts/internal/rcRef.d.ts +2 -0
  82. package/dist/dts/internal/rcRef.d.ts.map +1 -0
  83. package/dist/dts/internal/stream.d.ts +1 -0
  84. package/dist/dts/internal/stream.d.ts.map +1 -1
  85. package/dist/esm/Cause.js +21 -0
  86. package/dist/esm/Cause.js.map +1 -1
  87. package/dist/esm/Channel.js.map +1 -1
  88. package/dist/esm/Config.js.map +1 -1
  89. package/dist/esm/Console.js.map +1 -1
  90. package/dist/esm/Data.js +3 -1
  91. package/dist/esm/Data.js.map +1 -1
  92. package/dist/esm/Duration.js +20 -0
  93. package/dist/esm/Duration.js.map +1 -1
  94. package/dist/esm/Logger.js +10 -0
  95. package/dist/esm/Logger.js.map +1 -1
  96. package/dist/esm/PubSub.js.map +1 -1
  97. package/dist/esm/Random.js +8 -0
  98. package/dist/esm/Random.js.map +1 -1
  99. package/dist/esm/RcMap.js +44 -0
  100. package/dist/esm/RcMap.js.map +1 -0
  101. package/dist/esm/RcRef.js +43 -0
  102. package/dist/esm/RcRef.js.map +1 -0
  103. package/dist/esm/Stream.js +27 -0
  104. package/dist/esm/Stream.js.map +1 -1
  105. package/dist/esm/index.js +8 -0
  106. package/dist/esm/index.js.map +1 -1
  107. package/dist/esm/internal/cause.js +21 -5
  108. package/dist/esm/internal/cause.js.map +1 -1
  109. package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
  110. package/dist/esm/internal/channel.js.map +1 -1
  111. package/dist/esm/internal/core-effect.js +0 -5
  112. package/dist/esm/internal/core-effect.js.map +1 -1
  113. package/dist/esm/internal/core.js +11 -7
  114. package/dist/esm/internal/core.js.map +1 -1
  115. package/dist/esm/internal/defaultServices.js +1 -1
  116. package/dist/esm/internal/defaultServices.js.map +1 -1
  117. package/dist/esm/internal/fiberRuntime.js +2 -0
  118. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  119. package/dist/esm/internal/logger.js +126 -26
  120. package/dist/esm/internal/logger.js.map +1 -1
  121. package/dist/esm/internal/pubsub.js +216 -36
  122. package/dist/esm/internal/pubsub.js.map +1 -1
  123. package/dist/esm/internal/random.js +2 -1
  124. package/dist/esm/internal/random.js.map +1 -1
  125. package/dist/esm/internal/rcMap.js +120 -0
  126. package/dist/esm/internal/rcMap.js.map +1 -0
  127. package/dist/esm/internal/rcRef.js +112 -0
  128. package/dist/esm/internal/rcRef.js.map +1 -0
  129. package/dist/esm/internal/stream.js +53 -8
  130. package/dist/esm/internal/stream.js.map +1 -1
  131. package/dist/esm/internal/version.js +1 -1
  132. package/package.json +17 -1
  133. package/src/Cause.ts +47 -1
  134. package/src/Channel.ts +3 -3
  135. package/src/Config.ts +6 -0
  136. package/src/Console.ts +2 -4
  137. package/src/Data.ts +1 -1
  138. package/src/Duration.ts +18 -0
  139. package/src/Logger.ts +19 -0
  140. package/src/PubSub.ts +11 -4
  141. package/src/Random.ts +9 -0
  142. package/src/RcMap.ts +103 -0
  143. package/src/RcRef.ts +91 -0
  144. package/src/Stream.ts +83 -26
  145. package/src/index.ts +10 -0
  146. package/src/internal/cause.ts +26 -5
  147. package/src/internal/channel/channelExecutor.ts +1 -1
  148. package/src/internal/channel.ts +4 -3
  149. package/src/internal/core-effect.ts +0 -5
  150. package/src/internal/core.ts +19 -9
  151. package/src/internal/defaultServices.ts +1 -1
  152. package/src/internal/fiberRuntime.ts +6 -0
  153. package/src/internal/logger.ts +133 -27
  154. package/src/internal/pubsub.ts +249 -58
  155. package/src/internal/random.ts +2 -1
  156. package/src/internal/rcMap.ts +213 -0
  157. package/src/internal/rcRef.ts +172 -0
  158. package/src/internal/stream.ts +325 -111
  159. package/src/internal/version.ts +1 -1
package/src/Stream.ts CHANGED
@@ -30,7 +30,7 @@ import type * as Emit from "./StreamEmit.js"
30
30
  import type * as HaltStrategy from "./StreamHaltStrategy.js"
31
31
  import type * as Take from "./Take.js"
32
32
  import type * as Tracer from "./Tracer.js"
33
- import type { Covariant, NoInfer } from "./Types.js"
33
+ import type { Covariant, NoInfer, TupleOf } from "./Types.js"
34
34
  import type * as Unify from "./Unify.js"
35
35
 
36
36
  /**
@@ -146,6 +146,7 @@ export declare namespace Stream {
146
146
  /**
147
147
  * @since 2.0.0
148
148
  * @category models
149
+ * @deprecated use Types.TupleOf instead
149
150
  */
150
151
  export type DynamicTuple<T, N extends number> = N extends N ? number extends N ? Array<T> : DynamicTupleOf<T, N, []>
151
152
  : never
@@ -153,6 +154,7 @@ export declare namespace Stream {
153
154
  /**
154
155
  * @since 2.0.0
155
156
  * @category models
157
+ * @deprecated use Types.TupleOf instead
156
158
  */
157
159
  export type DynamicTupleOf<T, N extends number, R extends Array<unknown>> = R["length"] extends N ? R
158
160
  : DynamicTupleOf<T, N, [T, ...R]>
@@ -310,7 +312,10 @@ export const as: {
310
312
 
311
313
  const _async: <A, E = never, R = never>(
312
314
  register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<void, never, R> | void,
313
- outputBuffer?: number
315
+ bufferSize?: number | "unbounded" | {
316
+ readonly bufferSize?: number | undefined
317
+ readonly strategy?: "dropping" | "sliding" | "suspend" | undefined
318
+ } | undefined
314
319
  ) => Stream<A, E, R> = internal._async
315
320
 
316
321
  export {
@@ -362,7 +367,10 @@ export {
362
367
  */
363
368
  export const asyncEffect: <A, E = never, R = never>(
364
369
  register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<unknown, E, R>,
365
- outputBuffer?: number
370
+ bufferSize?: number | "unbounded" | {
371
+ readonly bufferSize?: number | undefined
372
+ readonly strategy?: "dropping" | "sliding" | "suspend" | undefined
373
+ } | undefined
366
374
  ) => Stream<A, E, R> = internal.asyncEffect
367
375
 
368
376
  /**
@@ -376,7 +384,10 @@ export const asyncEffect: <A, E = never, R = never>(
376
384
  */
377
385
  export const asyncScoped: <A, E = never, R = never>(
378
386
  register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<unknown, E, R | Scope.Scope>,
379
- outputBuffer?: number
387
+ bufferSize?: number | "unbounded" | {
388
+ readonly bufferSize?: number | undefined
389
+ readonly strategy?: "dropping" | "sliding" | "suspend" | undefined
390
+ } | undefined
380
391
  ) => Stream<A, E, Exclude<R, Scope.Scope>> = internal.asyncScoped
381
392
 
382
393
  /**
@@ -484,12 +495,12 @@ export const broadcast: {
484
495
  maximumLag: number
485
496
  ): <A, E, R>(
486
497
  self: Stream<A, E, R>
487
- ) => Effect.Effect<Stream.DynamicTuple<Stream<A, E>, N>, never, Scope.Scope | R>
498
+ ) => Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
488
499
  <A, E, R, N extends number>(
489
500
  self: Stream<A, E, R>,
490
501
  n: N,
491
502
  maximumLag: number
492
- ): Effect.Effect<Stream.DynamicTuple<Stream<A, E>, N>, never, Scope.Scope | R>
503
+ ): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
493
504
  } = internal.broadcast
494
505
 
495
506
  /**
@@ -521,12 +532,12 @@ export const broadcastedQueues: {
521
532
  maximumLag: number
522
533
  ): <A, E, R>(
523
534
  self: Stream<A, E, R>
524
- ) => Effect.Effect<Stream.DynamicTuple<Queue.Dequeue<Take.Take<A, E>>, N>, never, R | Scope.Scope>
535
+ ) => Effect.Effect<TupleOf<N, Queue.Dequeue<Take.Take<A, E>>>, never, R | Scope.Scope>
525
536
  <A, E, R, N extends number>(
526
537
  self: Stream<A, E, R>,
527
538
  n: N,
528
539
  maximumLag: number
529
- ): Effect.Effect<Stream.DynamicTuple<Queue.Dequeue<Take.Take<A, E>>, N>, never, Scope.Scope | R>
540
+ ): Effect.Effect<TupleOf<N, Queue.Dequeue<Take.Take<A, E>>>, never, Scope.Scope | R>
530
541
  } = internal.broadcastedQueues
531
542
 
532
543
  /**
@@ -1139,7 +1150,7 @@ export const distributedWith: {
1139
1150
  }
1140
1151
  ): <E, R>(
1141
1152
  self: Stream<A, E, R>
1142
- ) => Effect.Effect<Stream.DynamicTuple<Queue.Dequeue<Exit.Exit<A, Option.Option<E>>>, N>, never, Scope.Scope | R>
1153
+ ) => Effect.Effect<TupleOf<N, Queue.Dequeue<Exit.Exit<A, Option.Option<E>>>>, never, Scope.Scope | R>
1143
1154
  <A, E, R, N extends number>(
1144
1155
  self: Stream<A, E, R>,
1145
1156
  options: {
@@ -1147,7 +1158,7 @@ export const distributedWith: {
1147
1158
  readonly maximumLag: number
1148
1159
  readonly decide: (a: A) => Effect.Effect<Predicate<number>>
1149
1160
  }
1150
- ): Effect.Effect<Stream.DynamicTuple<Queue.Dequeue<Exit.Exit<A, Option.Option<E>>>, N>, never, Scope.Scope | R>
1161
+ ): Effect.Effect<TupleOf<N, Queue.Dequeue<Exit.Exit<A, Option.Option<E>>>>, never, Scope.Scope | R>
1151
1162
  } = internal.distributedWith
1152
1163
 
1153
1164
  /**
@@ -2843,8 +2854,8 @@ export const mergeEither: {
2843
2854
  * @category utils
2844
2855
  */
2845
2856
  export const mergeLeft: {
2846
- <A2, E2, R2>(that: Stream<A2, E2, R2>): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E2 | E, R2 | R>
2847
- <A, E, R, A2, E2, R2>(self: Stream<A, E, R>, that: Stream<A2, E2, R2>): Stream<A, E | E2, R | R2>
2857
+ <AR, ER, RR>(right: Stream<AR, ER, RR>): <AL, EL, RL>(left: Stream<AL, EL, RL>) => Stream<AL, ER | EL, RR | RL>
2858
+ <AL, EL, RL, AR, ER, RR>(left: Stream<AL, EL, RL>, right: Stream<AR, ER, RR>): Stream<AL, EL | ER, RL | RR>
2848
2859
  } = internal.mergeLeft
2849
2860
 
2850
2861
  /**
@@ -2855,8 +2866,8 @@ export const mergeLeft: {
2855
2866
  * @category utils
2856
2867
  */
2857
2868
  export const mergeRight: {
2858
- <A2, E2, R2>(that: Stream<A2, E2, R2>): <A, E, R>(self: Stream<A, E, R>) => Stream<A2, E2 | E, R2 | R>
2859
- <A, E, R, A2, E2, R2>(self: Stream<A, E, R>, that: Stream<A2, E2, R2>): Stream<A2, E | E2, R | R2>
2869
+ <AR, ER, RR>(right: Stream<AR, ER, RR>): <AL, EL, RL>(left: Stream<AL, EL, RL>) => Stream<AR, ER | EL, RR | RL>
2870
+ <AL, EL, RL, AR, ER, RR>(left: Stream<AL, EL, RL>, right: Stream<AR, ER, RR>): Stream<AR, EL | ER, RL | RR>
2860
2871
  } = internal.mergeRight
2861
2872
 
2862
2873
  /**
@@ -3357,6 +3368,40 @@ export const provideSomeLayer: {
3357
3368
  ): Stream<A, E | E2, RIn | Exclude<R, ROut>>
3358
3369
  } = internal.provideSomeLayer
3359
3370
 
3371
+ /**
3372
+ * Returns a stream that mirrors the first upstream to emit an item.
3373
+ * As soon as one of the upstream emits a first value, all the others are interrupted.
3374
+ * The resulting stream will forward all items from the "winning" source stream.
3375
+ * Any upstream failures will cause the returned stream to fail.
3376
+ *
3377
+ * @example
3378
+ * import { Stream, Schedule, Console, Effect } from "effect"
3379
+ *
3380
+ * const stream = Stream.raceAll(
3381
+ * Stream.fromSchedule(Schedule.spaced('1 millis')),
3382
+ * Stream.fromSchedule(Schedule.spaced('2 millis')),
3383
+ * Stream.fromSchedule(Schedule.spaced('4 millis')),
3384
+ * ).pipe(Stream.take(6), Stream.tap(Console.log))
3385
+ *
3386
+ * Effect.runPromise(Stream.runDrain(stream))
3387
+ * // Output each millisecond from the first stream, the rest streams are interrupted
3388
+ * // 0
3389
+ * // 1
3390
+ * // 2
3391
+ * // 3
3392
+ * // 4
3393
+ * // 5
3394
+ * @since 3.5.0
3395
+ * @category racing
3396
+ */
3397
+ export const raceAll: <S extends ReadonlyArray<Stream<any, any, any>>>(
3398
+ ...streams: S
3399
+ ) => Stream<
3400
+ Stream.Success<S[number]>,
3401
+ Stream.Error<S[number]>,
3402
+ Stream.Context<S[number]>
3403
+ > = internal.raceAll
3404
+
3360
3405
  /**
3361
3406
  * Constructs a stream from a range of integers, including both endpoints.
3362
3407
  *
@@ -3638,7 +3683,7 @@ export const run: {
3638
3683
  <A, E, R, A2, E2, R2>(
3639
3684
  self: Stream<A, E, R>,
3640
3685
  sink: Sink.Sink<A2, A, unknown, E2, R2>
3641
- ): Effect.Effect<A2, E | E2, R | R2>
3686
+ ): Effect.Effect<A2, E | E2, Exclude<R | R2, Scope.Scope>>
3642
3687
  } = internal.run
3643
3688
 
3644
3689
  /**
@@ -3647,7 +3692,8 @@ export const run: {
3647
3692
  * @since 2.0.0
3648
3693
  * @category destructors
3649
3694
  */
3650
- export const runCollect: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Chunk.Chunk<A>, E, R> = internal.runCollect
3695
+ export const runCollect: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Chunk.Chunk<A>, E, Exclude<R, Scope.Scope>> =
3696
+ internal.runCollect
3651
3697
 
3652
3698
  /**
3653
3699
  * Runs the stream and emits the number of elements processed
@@ -3655,7 +3701,8 @@ export const runCollect: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Chunk
3655
3701
  * @since 2.0.0
3656
3702
  * @category destructors
3657
3703
  */
3658
- export const runCount: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<number, E, R> = internal.runCount
3704
+ export const runCount: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<number, E, Exclude<R, Scope.Scope>> =
3705
+ internal.runCount
3659
3706
 
3660
3707
  /**
3661
3708
  * Runs the stream only for its effects. The emitted elements are discarded.
@@ -3663,7 +3710,8 @@ export const runCount: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<number,
3663
3710
  * @since 2.0.0
3664
3711
  * @category destructors
3665
3712
  */
3666
- export const runDrain: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<void, E, R> = internal.runDrain
3713
+ export const runDrain: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>> =
3714
+ internal.runDrain
3667
3715
 
3668
3716
  /**
3669
3717
  * Executes a pure fold over the stream of values - reduces all elements in
@@ -3673,8 +3721,8 @@ export const runDrain: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<void, E
3673
3721
  * @category destructors
3674
3722
  */
3675
3723
  export const runFold: {
3676
- <S, A>(s: S, f: (s: S, a: A) => S): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E, R>
3677
- <A, E, R, S>(self: Stream<A, E, R>, s: S, f: (s: S, a: A) => S): Effect.Effect<S, E, R>
3724
+ <S, A>(s: S, f: (s: S, a: A) => S): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E, Exclude<R, Scope.Scope>>
3725
+ <A, E, R, S>(self: Stream<A, E, R>, s: S, f: (s: S, a: A) => S): Effect.Effect<S, E, Exclude<R, Scope.Scope>>
3678
3726
  } = internal.runFold
3679
3727
 
3680
3728
  /**
@@ -3687,12 +3735,12 @@ export const runFoldEffect: {
3687
3735
  <S, A, E2, R2>(
3688
3736
  s: S,
3689
3737
  f: (s: S, a: A) => Effect.Effect<S, E2, R2>
3690
- ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E2 | E, R2 | R>
3738
+ ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E2 | E, Exclude<R | R2, Scope.Scope>>
3691
3739
  <A, E, R, S, E2, R2>(
3692
3740
  self: Stream<A, E, R>,
3693
3741
  s: S,
3694
3742
  f: (s: S, a: A) => Effect.Effect<S, E2, R2>
3695
- ): Effect.Effect<S, E | E2, R | R2>
3743
+ ): Effect.Effect<S, E | E2, Exclude<R | R2, Scope.Scope>>
3696
3744
  } = internal.runFoldEffect
3697
3745
 
3698
3746
  /**
@@ -3734,8 +3782,17 @@ export const runFoldScopedEffect: {
3734
3782
  * @category destructors
3735
3783
  */
3736
3784
  export const runFoldWhile: {
3737
- <S, A>(s: S, cont: Predicate<S>, f: (s: S, a: A) => S): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E, R>
3738
- <A, E, R, S>(self: Stream<A, E, R>, s: S, cont: Predicate<S>, f: (s: S, a: A) => S): Effect.Effect<S, E, R>
3785
+ <S, A>(
3786
+ s: S,
3787
+ cont: Predicate<S>,
3788
+ f: (s: S, a: A) => S
3789
+ ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E, Exclude<R, Scope.Scope>>
3790
+ <A, E, R, S>(
3791
+ self: Stream<A, E, R>,
3792
+ s: S,
3793
+ cont: Predicate<S>,
3794
+ f: (s: S, a: A) => S
3795
+ ): Effect.Effect<S, E, Exclude<R, Scope.Scope>>
3739
3796
  } = internal.runFoldWhile
3740
3797
 
3741
3798
  /**
@@ -3750,13 +3807,13 @@ export const runFoldWhileEffect: {
3750
3807
  s: S,
3751
3808
  cont: Predicate<S>,
3752
3809
  f: (s: S, a: A) => Effect.Effect<S, E2, R2>
3753
- ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E2 | E, R2 | R>
3810
+ ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E2 | E, Exclude<R | R2, Scope.Scope>>
3754
3811
  <A, E, R, S, E2, R2>(
3755
3812
  self: Stream<A, E, R>,
3756
3813
  s: S,
3757
3814
  cont: Predicate<S>,
3758
3815
  f: (s: S, a: A) => Effect.Effect<S, E2, R2>
3759
- ): Effect.Effect<S, E | E2, R | R2>
3816
+ ): Effect.Effect<S, E | E2, Exclude<R | R2, Scope.Scope>>
3760
3817
  } = internal.runFoldWhileEffect
3761
3818
 
3762
3819
  /**
package/src/index.ts CHANGED
@@ -605,6 +605,16 @@ export * as Random from "./Random.js"
605
605
  */
606
606
  export * as RateLimiter from "./RateLimiter.js"
607
607
 
608
+ /**
609
+ * @since 3.5.0
610
+ */
611
+ export * as RcMap from "./RcMap.js"
612
+
613
+ /**
614
+ * @since 3.5.0
615
+ */
616
+ export * as RcRef from "./RcRef.js"
617
+
608
618
  /**
609
619
  * @since 2.0.0
610
620
  */
@@ -970,25 +970,46 @@ export const reduceWithContext = dual<
970
970
  // -----------------------------------------------------------------------------
971
971
 
972
972
  /** @internal */
973
- export const pretty = <E>(cause: Cause.Cause<E>): string => {
973
+ export const pretty = <E>(cause: Cause.Cause<E>, options?: {
974
+ readonly renderErrorCause?: boolean | undefined
975
+ }): string => {
974
976
  if (isInterruptedOnly(cause)) {
975
977
  return "All fibers interrupted without errors."
976
978
  }
977
- return prettyErrors<E>(cause).map((e) => e.stack).join("\n")
979
+ return prettyErrors<E>(cause).map(function(e) {
980
+ if (options?.renderErrorCause !== true || e.cause === undefined) {
981
+ return e.stack
982
+ }
983
+ return `${e.stack} {\n${renderErrorCause(e.cause as PrettyError, " ")}\n}`
984
+ }).join("\n")
985
+ }
986
+
987
+ const renderErrorCause = (cause: PrettyError, prefix: string) => {
988
+ const lines = cause.stack!.split("\n")
989
+ let stack = `${prefix}[cause]: ${lines[0]}`
990
+ for (let i = 1, len = lines.length; i < len; i++) {
991
+ stack += `\n${prefix}${lines[i]}`
992
+ }
993
+ return stack
978
994
  }
979
995
 
980
996
  class PrettyError extends globalThis.Error implements Cause.PrettyError {
981
997
  span: undefined | Span = undefined
982
998
  constructor(originalError: unknown) {
999
+ const originalErrorIsObject = typeof originalError === "object" && originalError !== null
983
1000
  const prevLimit = Error.stackTraceLimit
984
- Error.stackTraceLimit = 0
985
- super(prettyErrorMessage(originalError))
1001
+ Error.stackTraceLimit = 1
1002
+ super(prettyErrorMessage(originalError), {
1003
+ cause: originalErrorIsObject && "cause" in originalError && typeof originalError.cause !== "undefined"
1004
+ ? new PrettyError(originalError.cause)
1005
+ : undefined
1006
+ })
986
1007
  if (this.message === "") {
987
1008
  this.message = "An error has occurred"
988
1009
  }
989
1010
  Error.stackTraceLimit = prevLimit
990
1011
  this.name = originalError instanceof Error ? originalError.name : "Error"
991
- if (typeof originalError === "object" && originalError !== null) {
1012
+ if (originalErrorIsObject) {
992
1013
  if (spanSymbol in originalError) {
993
1014
  this.span = originalError[spanSymbol] as Span
994
1015
  }
@@ -1095,7 +1095,7 @@ export const readUpstream = <A, E2, R, E>(
1095
1095
  /** @internal */
1096
1096
  export const run = <Env, InErr, InDone, OutErr, OutDone>(
1097
1097
  self: Channel.Channel<never, unknown, OutErr, InErr, OutDone, InDone, Env>
1098
- ): Effect.Effect<OutDone, OutErr, Env> => pipe(runScoped(self), Effect.scoped)
1098
+ ): Effect.Effect<OutDone, OutErr, Exclude<Env, Scope.Scope>> => pipe(runScoped(self), Effect.scoped)
1099
1099
 
1100
1100
  /** @internal */
1101
1101
  export const runScoped = <Env, InErr, InDone, OutErr, OutDone>(
@@ -2052,17 +2052,18 @@ export const repeated = <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
2052
2052
  /** @internal */
2053
2053
  export const run = <OutErr, InErr, OutDone, InDone, Env>(
2054
2054
  self: Channel.Channel<never, unknown, OutErr, InErr, OutDone, InDone, Env>
2055
- ): Effect.Effect<OutDone, OutErr, Env> => Effect.scoped(executor.runScoped(self))
2055
+ ): Effect.Effect<OutDone, OutErr, Exclude<Env, Scope.Scope>> => Effect.scoped(executor.runScoped(self))
2056
2056
 
2057
2057
  /** @internal */
2058
2058
  export const runCollect = <OutElem, OutErr, InErr, OutDone, InDone, Env>(
2059
2059
  self: Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, Env>
2060
- ): Effect.Effect<[Chunk.Chunk<OutElem>, OutDone], OutErr, Env> => executor.run(core.collectElements(self))
2060
+ ): Effect.Effect<[Chunk.Chunk<OutElem>, OutDone], OutErr, Exclude<Env, Scope.Scope>> =>
2061
+ executor.run(core.collectElements(self))
2061
2062
 
2062
2063
  /** @internal */
2063
2064
  export const runDrain = <OutElem, OutErr, InErr, OutDone, InDone, Env>(
2064
2065
  self: Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, Env>
2065
- ): Effect.Effect<OutDone, OutErr, Env> => executor.run(drain(self))
2066
+ ): Effect.Effect<OutDone, OutErr, Exclude<Env, Scope.Scope>> => executor.run(drain(self))
2066
2067
 
2067
2068
  /** @internal */
2068
2069
  export const scoped = <A, E, R>(
@@ -911,11 +911,6 @@ export const logWithLevel = (level?: LogLevel.LogLevel) =>
911
911
  i--
912
912
  }
913
913
  }
914
- if (message.length === 0) {
915
- message = "" as any
916
- } else if (message.length === 1) {
917
- message = message[0]
918
- }
919
914
  if (cause === undefined) {
920
915
  cause = internalCause.empty
921
916
  }
@@ -2174,23 +2174,19 @@ export const causeSquashWith = dual<
2174
2174
  // -----------------------------------------------------------------------------
2175
2175
 
2176
2176
  /** @internal */
2177
- export const YieldableError: new(message?: string) => Cause.YieldableError = (function() {
2177
+ export const YieldableError: new(message?: string, options?: ErrorOptions) => Cause.YieldableError = (function() {
2178
2178
  class YieldableError extends globalThis.Error {
2179
2179
  commit() {
2180
2180
  return fail(this)
2181
2181
  }
2182
- toString() {
2183
- return this.message ? `${this.name}: ${this.message}` : this.name
2184
- }
2185
2182
  toJSON() {
2186
2183
  return { ...this }
2187
2184
  }
2188
- [NodeInspectSymbol](): string {
2189
- const stack = this.stack
2190
- if (stack) {
2191
- return `${this.toString()}\n${stack.split("\n").slice(1).join("\n")}`
2185
+ [NodeInspectSymbol]() {
2186
+ if (this.toString !== globalThis.Error.prototype.toString) {
2187
+ return this.stack ? `${this.toString()}\n${this.stack.split("\n").slice(1).join("\n")}` : this.toString()
2192
2188
  }
2193
- return this.toString()
2189
+ return this
2194
2190
  }
2195
2191
  }
2196
2192
  Object.assign(YieldableError.prototype, StructuralCommitPrototype)
@@ -2274,6 +2270,20 @@ export const InvalidPubSubCapacityException = makeException<Cause.InvalidPubSubC
2274
2270
  [InvalidPubSubCapacityExceptionTypeId]: InvalidPubSubCapacityExceptionTypeId
2275
2271
  }, "InvalidPubSubCapacityException")
2276
2272
 
2273
+ /** @internal */
2274
+ export const ExceededCapacityExceptionTypeId: Cause.ExceededCapacityExceptionTypeId = Symbol.for(
2275
+ "effect/Cause/errors/ExceededCapacityException"
2276
+ ) as Cause.ExceededCapacityExceptionTypeId
2277
+
2278
+ /** @internal */
2279
+ export const ExceededCapacityException = makeException<Cause.ExceededCapacityException>({
2280
+ [ExceededCapacityExceptionTypeId]: ExceededCapacityExceptionTypeId
2281
+ }, "ExceededCapacityException")
2282
+
2283
+ /** @internal */
2284
+ export const isExceededCapacityException = (u: unknown): u is Cause.ExceededCapacityException =>
2285
+ hasProperty(u, ExceededCapacityExceptionTypeId)
2286
+
2277
2287
  /** @internal */
2278
2288
  export const isInvalidCapacityError = (u: unknown): u is Cause.InvalidPubSubCapacityException =>
2279
2289
  hasProperty(u, InvalidPubSubCapacityExceptionTypeId)
@@ -22,7 +22,7 @@ export const liveServices: Context.Context<DefaultServices.DefaultServices> = pi
22
22
  Context.empty(),
23
23
  Context.add(clock.clockTag, clock.make()),
24
24
  Context.add(console_.consoleTag, console_.defaultConsole),
25
- Context.add(random.randomTag, random.make((Math.random() * 4294967296) >>> 0)),
25
+ Context.add(random.randomTag, random.make(Math.random())),
26
26
  Context.add(configProvider.configProviderTag, configProvider.fromEnv()),
27
27
  Context.add(tracer.tracerTag, tracer.nativeTracer)
28
28
  )
@@ -1421,6 +1421,12 @@ export const logFmtLogger: Logger<unknown, void> = globalValue(
1421
1421
  () => loggerWithConsoleLog(internalLogger.logfmtLogger)
1422
1422
  )
1423
1423
 
1424
+ /** @internal */
1425
+ export const prettyLogger: Logger<unknown, void> = globalValue(
1426
+ Symbol.for("effect/Logger/prettyLogger"),
1427
+ () => internalLogger.prettyLogger()
1428
+ )
1429
+
1424
1430
  /** @internal */
1425
1431
  export const structuredLogger: Logger<unknown, void> = globalValue(
1426
1432
  Symbol.for("effect/Logger/structuredLogger"),