effect 3.0.7 → 3.1.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 (96) hide show
  1. package/dist/cjs/Channel.js.map +1 -1
  2. package/dist/cjs/Data.js +15 -1
  3. package/dist/cjs/Data.js.map +1 -1
  4. package/dist/cjs/Effect.js +44 -7
  5. package/dist/cjs/Effect.js.map +1 -1
  6. package/dist/cjs/Layer.js.map +1 -1
  7. package/dist/cjs/SortedMap.js +24 -1
  8. package/dist/cjs/SortedMap.js.map +1 -1
  9. package/dist/cjs/Stream.js +8 -3
  10. package/dist/cjs/Stream.js.map +1 -1
  11. package/dist/cjs/Tracer.js.map +1 -1
  12. package/dist/cjs/internal/cause.js +3 -3
  13. package/dist/cjs/internal/cause.js.map +1 -1
  14. package/dist/cjs/internal/channel.js.map +1 -1
  15. package/dist/cjs/internal/core-effect.js +1 -1
  16. package/dist/cjs/internal/core-effect.js.map +1 -1
  17. package/dist/cjs/internal/core.js +1 -0
  18. package/dist/cjs/internal/core.js.map +1 -1
  19. package/dist/cjs/internal/effect/circular.js +7 -1
  20. package/dist/cjs/internal/effect/circular.js.map +1 -1
  21. package/dist/cjs/internal/fiberRuntime.js +15 -1
  22. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  23. package/dist/cjs/internal/layer/circular.js.map +1 -1
  24. package/dist/cjs/internal/layer.js.map +1 -1
  25. package/dist/cjs/internal/stream.js +23 -3
  26. package/dist/cjs/internal/stream.js.map +1 -1
  27. package/dist/cjs/internal/tracer.js +4 -2
  28. package/dist/cjs/internal/tracer.js.map +1 -1
  29. package/dist/cjs/internal/version.js +1 -1
  30. package/dist/dts/Channel.d.ts +2 -14
  31. package/dist/dts/Channel.d.ts.map +1 -1
  32. package/dist/dts/Data.d.ts +20 -5
  33. package/dist/dts/Data.d.ts.map +1 -1
  34. package/dist/dts/Effect.d.ts +56 -60
  35. package/dist/dts/Effect.d.ts.map +1 -1
  36. package/dist/dts/Layer.d.ts +3 -18
  37. package/dist/dts/Layer.d.ts.map +1 -1
  38. package/dist/dts/SortedMap.d.ts +13 -0
  39. package/dist/dts/SortedMap.d.ts.map +1 -1
  40. package/dist/dts/Stream.d.ts +7 -14
  41. package/dist/dts/Stream.d.ts.map +1 -1
  42. package/dist/dts/Tracer.d.ts +19 -1
  43. package/dist/dts/Tracer.d.ts.map +1 -1
  44. package/dist/dts/Types.d.ts +18 -0
  45. package/dist/dts/Types.d.ts.map +1 -1
  46. package/dist/dts/internal/fiberRuntime.d.ts +6 -1
  47. package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
  48. package/dist/esm/Channel.js.map +1 -1
  49. package/dist/esm/Data.js +14 -0
  50. package/dist/esm/Data.js.map +1 -1
  51. package/dist/esm/Effect.js +40 -3
  52. package/dist/esm/Effect.js.map +1 -1
  53. package/dist/esm/Layer.js.map +1 -1
  54. package/dist/esm/SortedMap.js +22 -0
  55. package/dist/esm/SortedMap.js.map +1 -1
  56. package/dist/esm/Stream.js +5 -0
  57. package/dist/esm/Stream.js.map +1 -1
  58. package/dist/esm/Tracer.js.map +1 -1
  59. package/dist/esm/internal/cause.js +3 -3
  60. package/dist/esm/internal/cause.js.map +1 -1
  61. package/dist/esm/internal/channel.js.map +1 -1
  62. package/dist/esm/internal/core-effect.js +1 -1
  63. package/dist/esm/internal/core-effect.js.map +1 -1
  64. package/dist/esm/internal/core.js +1 -0
  65. package/dist/esm/internal/core.js.map +1 -1
  66. package/dist/esm/internal/effect/circular.js +6 -0
  67. package/dist/esm/internal/effect/circular.js.map +1 -1
  68. package/dist/esm/internal/fiberRuntime.js +13 -0
  69. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  70. package/dist/esm/internal/layer/circular.js.map +1 -1
  71. package/dist/esm/internal/layer.js.map +1 -1
  72. package/dist/esm/internal/stream.js +19 -0
  73. package/dist/esm/internal/stream.js.map +1 -1
  74. package/dist/esm/internal/tracer.js +4 -2
  75. package/dist/esm/internal/tracer.js.map +1 -1
  76. package/dist/esm/internal/version.js +1 -1
  77. package/package.json +1 -1
  78. package/src/Channel.ts +2 -14
  79. package/src/Data.ts +39 -3
  80. package/src/Effect.ts +60 -66
  81. package/src/Layer.ts +3 -18
  82. package/src/SortedMap.ts +35 -0
  83. package/src/Stream.ts +12 -14
  84. package/src/Tracer.ts +22 -1
  85. package/src/Types.ts +21 -0
  86. package/src/internal/cause.ts +3 -3
  87. package/src/internal/channel.ts +2 -14
  88. package/src/internal/core-effect.ts +19 -43
  89. package/src/internal/core.ts +1 -0
  90. package/src/internal/effect/circular.ts +16 -0
  91. package/src/internal/fiberRuntime.ts +33 -21
  92. package/src/internal/layer/circular.ts +1 -6
  93. package/src/internal/layer.ts +17 -20
  94. package/src/internal/stream.ts +27 -14
  95. package/src/internal/tracer.ts +5 -3
  96. package/src/internal/version.ts +1 -1
@@ -527,16 +527,11 @@ export declare const forEach: {
527
527
  readonly batching?: boolean | "inherit" | undefined;
528
528
  readonly discard: true;
529
529
  }): (self: Iterable<A>) => Effect<void, E, R>;
530
- <A, B, E, R>(self: RA.NonEmptyReadonlyArray<A>, f: (a: A, i: number) => Effect<B, E, R>, options?: {
530
+ <B, E, R, S extends Iterable<any>>(self: S, f: (a: RA.ReadonlyArray.Infer<S>, i: number) => Effect<B, E, R>, options?: {
531
531
  readonly concurrency?: Concurrency | undefined;
532
532
  readonly batching?: boolean | "inherit" | undefined;
533
533
  readonly discard?: false | undefined;
534
- } | undefined): Effect<RA.NonEmptyArray<B>, E, R>;
535
- <A, B, E, R>(self: Iterable<A>, f: (a: A, i: number) => Effect<B, E, R>, options?: {
536
- readonly concurrency?: Concurrency | undefined;
537
- readonly batching?: boolean | "inherit" | undefined;
538
- readonly discard?: false | undefined;
539
- } | undefined): Effect<Array<B>, E, R>;
534
+ } | undefined): Effect<RA.ReadonlyArray.With<S, B>, E, R>;
540
535
  <A, B, E, R>(self: Iterable<A>, f: (a: A, i: number) => Effect<B, E, R>, options: {
541
536
  readonly concurrency?: Concurrency | undefined;
542
537
  readonly batching?: boolean | "inherit" | undefined;
@@ -909,7 +904,7 @@ export interface Adapter {
909
904
  <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, _A, _E, _R>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S, st: (s: S) => T, tu: (s: T) => Effect<_A, _E, _R>): Effect<_A, _E, _R>;
910
905
  }
911
906
  /**
912
- * Returns a effect that will never produce anything. The moral equivalent of
907
+ * Returns an effect that will never produce anything. The moral equivalent of
913
908
  * `while(true) {}`, only without the wasted CPU cycles.
914
909
  *
915
910
  * @since 2.0.0
@@ -2128,9 +2123,8 @@ export declare const timedWith: {
2128
2123
  <A, E, R, E1, R1>(self: Effect<A, E, R>, nanoseconds: Effect<bigint, E1, R1>): Effect<[Duration.Duration, A], E | E1, R | R1>;
2129
2124
  };
2130
2125
  /**
2131
- * Returns an effect that will timeout this effect, returning `None` if the
2132
- * timeout elapses before the effect has produced a value; and returning
2133
- * `Some` of the produced value otherwise.
2126
+ * Returns an effect that will timeout this effect, failing with a `Cause.TimeoutException`
2127
+ * if the timeout elapses before the effect has produced a value.
2134
2128
  *
2135
2129
  * If the timeout elapses without producing a value, the running effect will
2136
2130
  * be safely interrupted.
@@ -2150,6 +2144,29 @@ export declare const timeout: {
2150
2144
  (duration: Duration.DurationInput): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E | Cause.TimeoutException, R>;
2151
2145
  <A, E, R>(self: Effect<A, E, R>, duration: Duration.DurationInput): Effect<A, Cause.TimeoutException | E, R>;
2152
2146
  };
2147
+ /**
2148
+ * Returns an effect that will timeout this effect, returning `None` if the
2149
+ * timeout elapses before the effect has produced a value; and returning
2150
+ * `Some` of the produced value otherwise.
2151
+ *
2152
+ * If the timeout elapses without producing a value, the running effect will
2153
+ * be safely interrupted.
2154
+ *
2155
+ * WARNING: The effect returned by this method will not itself return until
2156
+ * the underlying effect is actually interrupted. This leads to more
2157
+ * predictable resource utilization. If early return is desired, then instead
2158
+ * of using `effect.timeout(d)`, use `effect.disconnect.timeout(d)`, which
2159
+ * first disconnects the effect's interruption signal before performing the
2160
+ * timeout, resulting in earliest possible return, before an underlying effect
2161
+ * has been successfully interrupted.
2162
+ *
2163
+ * @since 3.1.0
2164
+ * @category delays & timeouts
2165
+ */
2166
+ export declare const timeoutOption: {
2167
+ (duration: Duration.DurationInput): <A, E, R>(self: Effect<A, E, R>) => Effect<Option.Option<A>, E, R>;
2168
+ <A, E, R>(self: Effect<A, E, R>, duration: Duration.DurationInput): Effect<Option.Option<A>, E, R>;
2169
+ };
2153
2170
  /**
2154
2171
  * The same as `timeout`, but instead of producing a `None` in the event of
2155
2172
  * timeout, it will produce the specified error.
@@ -3245,6 +3262,27 @@ export declare const annotateLogs: {
3245
3262
  <A, E, R>(effect: Effect<A, E, R>, key: string, value: unknown): Effect<A, E, R>;
3246
3263
  <A, E, R>(effect: Effect<A, E, R>, values: Record<string, unknown>): Effect<A, E, R>;
3247
3264
  };
3265
+ /**
3266
+ * Annotates each log with the specified log annotation(s), until the Scope is closed.
3267
+ *
3268
+ * @since 3.1.0
3269
+ * @category logging
3270
+ * @example
3271
+ * import { Effect } from "effect"
3272
+ *
3273
+ * Effect.gen(function*() {
3274
+ * yield* Effect.log("no annotations")
3275
+ * yield* Effect.annotateLogsScoped({ foo: "bar" })
3276
+ * yield* Effect.log("annotated with foo=bar")
3277
+ * }).pipe(
3278
+ * Effect.scoped,
3279
+ * Effect.andThen(Effect.log("no annotations again"))
3280
+ * )
3281
+ */
3282
+ export declare const annotateLogsScoped: {
3283
+ (key: string, value: unknown): Effect<void, never, Scope.Scope>;
3284
+ (values: Record<string, unknown>): Effect<void, never, Scope.Scope>;
3285
+ };
3248
3286
  /**
3249
3287
  * Retrieves the log annotations associated with the current scope.
3250
3288
  *
@@ -3806,13 +3844,7 @@ export declare const linkSpans: {
3806
3844
  * @since 2.0.0
3807
3845
  * @category tracing
3808
3846
  */
3809
- export declare const makeSpan: (name: string, options?: {
3810
- readonly attributes?: Record<string, unknown> | undefined;
3811
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined;
3812
- readonly parent?: Tracer.AnySpan | undefined;
3813
- readonly root?: boolean | undefined;
3814
- readonly context?: Context.Context<never> | undefined;
3815
- }) => Effect<Tracer.Span>;
3847
+ export declare const makeSpan: (name: string, options?: Tracer.SpanOptions) => Effect<Tracer.Span>;
3816
3848
  /**
3817
3849
  * Create a new span for tracing, and automatically close it when the Scope
3818
3850
  * finalizes.
@@ -3823,13 +3855,7 @@ export declare const makeSpan: (name: string, options?: {
3823
3855
  * @since 2.0.0
3824
3856
  * @category tracing
3825
3857
  */
3826
- export declare const makeSpanScoped: (name: string, options?: {
3827
- readonly attributes?: Record<string, unknown> | undefined;
3828
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined;
3829
- readonly parent?: Tracer.AnySpan | undefined;
3830
- readonly root?: boolean | undefined;
3831
- readonly context?: Context.Context<never> | undefined;
3832
- } | undefined) => Effect<Tracer.Span, never, Scope.Scope>;
3858
+ export declare const makeSpanScoped: (name: string, options?: Tracer.SpanOptions | undefined) => Effect<Tracer.Span, never, Scope.Scope>;
3833
3859
  /**
3834
3860
  * Create a new span for tracing, and automatically close it when the effect
3835
3861
  * completes.
@@ -3842,13 +3868,7 @@ export declare const makeSpanScoped: (name: string, options?: {
3842
3868
  */
3843
3869
  export declare const useSpan: {
3844
3870
  <A, E, R>(name: string, evaluate: (span: Tracer.Span) => Effect<A, E, R>): Effect<A, E, R>;
3845
- <A, E, R>(name: string, options: {
3846
- readonly attributes?: Record<string, unknown> | undefined;
3847
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined;
3848
- readonly parent?: Tracer.AnySpan | undefined;
3849
- readonly root?: boolean | undefined;
3850
- readonly context?: Context.Context<never> | undefined;
3851
- }, evaluate: (span: Tracer.Span) => Effect<A, E, R>): Effect<A, E, R>;
3871
+ <A, E, R>(name: string, options: Tracer.SpanOptions, evaluate: (span: Tracer.Span) => Effect<A, E, R>): Effect<A, E, R>;
3852
3872
  };
3853
3873
  /**
3854
3874
  * Wraps the effect with a new span for tracing.
@@ -3857,20 +3877,8 @@ export declare const useSpan: {
3857
3877
  * @category tracing
3858
3878
  */
3859
3879
  export declare const withSpan: {
3860
- (name: string, options?: {
3861
- readonly attributes?: Record<string, unknown> | undefined;
3862
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined;
3863
- readonly parent?: Tracer.AnySpan | undefined;
3864
- readonly root?: boolean | undefined;
3865
- readonly context?: Context.Context<never> | undefined;
3866
- } | undefined): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, Tracer.ParentSpan>>;
3867
- <A, E, R>(self: Effect<A, E, R>, name: string, options?: {
3868
- readonly attributes?: Record<string, unknown> | undefined;
3869
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined;
3870
- readonly parent?: Tracer.AnySpan | undefined;
3871
- readonly root?: boolean | undefined;
3872
- readonly context?: Context.Context<never> | undefined;
3873
- } | undefined): Effect<A, E, Exclude<R, Tracer.ParentSpan>>;
3880
+ (name: string, options?: Tracer.SpanOptions | undefined): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, Tracer.ParentSpan>>;
3881
+ <A, E, R>(self: Effect<A, E, R>, name: string, options?: Tracer.SpanOptions | undefined): Effect<A, E, Exclude<R, Tracer.ParentSpan>>;
3874
3882
  };
3875
3883
  /**
3876
3884
  * Wraps the effect with a new span for tracing.
@@ -3881,20 +3889,8 @@ export declare const withSpan: {
3881
3889
  * @category tracing
3882
3890
  */
3883
3891
  export declare const withSpanScoped: {
3884
- (name: string, options?: {
3885
- readonly attributes?: Record<string, unknown> | undefined;
3886
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined;
3887
- readonly parent?: Tracer.AnySpan | undefined;
3888
- readonly root?: boolean | undefined;
3889
- readonly context?: Context.Context<never> | undefined;
3890
- }): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, Tracer.ParentSpan> | Scope.Scope>;
3891
- <A, E, R>(self: Effect<A, E, R>, name: string, options?: {
3892
- readonly attributes?: Record<string, unknown> | undefined;
3893
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined;
3894
- readonly parent?: Tracer.AnySpan | undefined;
3895
- readonly root?: boolean | undefined;
3896
- readonly context?: Context.Context<never> | undefined;
3897
- }): Effect<A, E, Exclude<R, Tracer.ParentSpan> | Scope.Scope>;
3892
+ (name: string, options?: Tracer.SpanOptions): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, Tracer.ParentSpan> | Scope.Scope>;
3893
+ <A, E, R>(self: Effect<A, E, R>, name: string, options?: Tracer.SpanOptions): Effect<A, E, Exclude<R, Tracer.ParentSpan> | Scope.Scope>;
3898
3894
  };
3899
3895
  /**
3900
3896
  * Adds the provided span to the current span stack.