effect 3.9.2 → 3.10.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 (202) hide show
  1. package/Arbitrary/package.json +6 -0
  2. package/FastCheck/package.json +6 -0
  3. package/JSONSchema/package.json +6 -0
  4. package/ParseResult/package.json +6 -0
  5. package/Pretty/package.json +6 -0
  6. package/Schema/package.json +6 -0
  7. package/SchemaAST/package.json +6 -0
  8. package/TSubscriptionRef/package.json +6 -0
  9. package/dist/cjs/Arbitrary.js +490 -0
  10. package/dist/cjs/Arbitrary.js.map +1 -0
  11. package/dist/cjs/Effect.js +247 -16
  12. package/dist/cjs/Effect.js.map +1 -1
  13. package/dist/cjs/FastCheck.js +17 -0
  14. package/dist/cjs/FastCheck.js.map +1 -0
  15. package/dist/cjs/Inspectable.js +43 -3
  16. package/dist/cjs/Inspectable.js.map +1 -1
  17. package/dist/cjs/JSONSchema.js +418 -0
  18. package/dist/cjs/JSONSchema.js.map +1 -0
  19. package/dist/cjs/ParseResult.js +1539 -0
  20. package/dist/cjs/ParseResult.js.map +1 -0
  21. package/dist/cjs/Predicate.js +3 -1
  22. package/dist/cjs/Predicate.js.map +1 -1
  23. package/dist/cjs/Pretty.js +183 -0
  24. package/dist/cjs/Pretty.js.map +1 -0
  25. package/dist/cjs/Schema.js +5529 -0
  26. package/dist/cjs/Schema.js.map +1 -0
  27. package/dist/cjs/SchemaAST.js +2365 -0
  28. package/dist/cjs/SchemaAST.js.map +1 -0
  29. package/dist/cjs/Stream.js +17 -3
  30. package/dist/cjs/Stream.js.map +1 -1
  31. package/dist/cjs/TPubSub.js +9 -1
  32. package/dist/cjs/TPubSub.js.map +1 -1
  33. package/dist/cjs/TQueue.js.map +1 -1
  34. package/dist/cjs/TRef.js.map +1 -1
  35. package/dist/cjs/TSubscriptionRef.js +96 -0
  36. package/dist/cjs/TSubscriptionRef.js.map +1 -0
  37. package/dist/cjs/index.js +18 -2
  38. package/dist/cjs/index.js.map +1 -1
  39. package/dist/cjs/internal/cause.js +2 -2
  40. package/dist/cjs/internal/cause.js.map +1 -1
  41. package/dist/cjs/internal/core.js +4 -4
  42. package/dist/cjs/internal/core.js.map +1 -1
  43. package/dist/cjs/internal/fiberRuntime.js +14 -12
  44. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  45. package/dist/cjs/internal/logger.js +7 -6
  46. package/dist/cjs/internal/logger.js.map +1 -1
  47. package/dist/cjs/internal/redacted.js +4 -0
  48. package/dist/cjs/internal/redacted.js.map +1 -1
  49. package/dist/cjs/internal/schema/errors.js +116 -0
  50. package/dist/cjs/internal/schema/errors.js.map +1 -0
  51. package/dist/cjs/internal/schema/filters.js +41 -0
  52. package/dist/cjs/internal/schema/filters.js.map +1 -0
  53. package/dist/cjs/internal/schema/util.js +96 -0
  54. package/dist/cjs/internal/schema/util.js.map +1 -0
  55. package/dist/cjs/internal/stm/core.js +2 -3
  56. package/dist/cjs/internal/stm/core.js.map +1 -1
  57. package/dist/cjs/internal/stm/tPubSub.js.map +1 -1
  58. package/dist/cjs/internal/stm/tQueue.js +1 -2
  59. package/dist/cjs/internal/stm/tQueue.js.map +1 -1
  60. package/dist/cjs/internal/stm/tRef.js +6 -2
  61. package/dist/cjs/internal/stm/tRef.js.map +1 -1
  62. package/dist/cjs/internal/stm/tSubscriptionRef.js +178 -0
  63. package/dist/cjs/internal/stm/tSubscriptionRef.js.map +1 -0
  64. package/dist/cjs/internal/stream.js +36 -16
  65. package/dist/cjs/internal/stream.js.map +1 -1
  66. package/dist/cjs/internal/version.js +1 -1
  67. package/dist/cjs/internal/version.js.map +1 -1
  68. package/dist/dts/Arbitrary.d.ts +45 -0
  69. package/dist/dts/Arbitrary.d.ts.map +1 -0
  70. package/dist/dts/Effect.d.ts +298 -30
  71. package/dist/dts/Effect.d.ts.map +1 -1
  72. package/dist/dts/FastCheck.d.ts +9 -0
  73. package/dist/dts/FastCheck.d.ts.map +1 -0
  74. package/dist/dts/Inspectable.d.ts +28 -0
  75. package/dist/dts/Inspectable.d.ts.map +1 -1
  76. package/dist/dts/JSONSchema.d.ts +181 -0
  77. package/dist/dts/JSONSchema.d.ts.map +1 -0
  78. package/dist/dts/ParseResult.d.ts +551 -0
  79. package/dist/dts/ParseResult.d.ts.map +1 -0
  80. package/dist/dts/Predicate.d.ts.map +1 -1
  81. package/dist/dts/Pretty.d.ts +26 -0
  82. package/dist/dts/Pretty.d.ts.map +1 -0
  83. package/dist/dts/Schema.d.ts +4562 -0
  84. package/dist/dts/Schema.d.ts.map +1 -0
  85. package/dist/dts/SchemaAST.d.ts +1321 -0
  86. package/dist/dts/SchemaAST.d.ts.map +1 -0
  87. package/dist/dts/Stream.d.ts +67 -2
  88. package/dist/dts/Stream.d.ts.map +1 -1
  89. package/dist/dts/TPubSub.d.ts +8 -0
  90. package/dist/dts/TPubSub.d.ts.map +1 -1
  91. package/dist/dts/TQueue.d.ts +7 -7
  92. package/dist/dts/TQueue.d.ts.map +1 -1
  93. package/dist/dts/TRef.d.ts +2 -1
  94. package/dist/dts/TRef.d.ts.map +1 -1
  95. package/dist/dts/TSubscriptionRef.d.ts +251 -0
  96. package/dist/dts/TSubscriptionRef.d.ts.map +1 -0
  97. package/dist/dts/index.d.ts +32 -0
  98. package/dist/dts/index.d.ts.map +1 -1
  99. package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
  100. package/dist/dts/internal/schema/errors.d.ts +2 -0
  101. package/dist/dts/internal/schema/errors.d.ts.map +1 -0
  102. package/dist/dts/internal/schema/filters.d.ts +2 -0
  103. package/dist/dts/internal/schema/filters.d.ts.map +1 -0
  104. package/dist/dts/internal/schema/util.d.ts +2 -0
  105. package/dist/dts/internal/schema/util.d.ts.map +1 -0
  106. package/dist/dts/internal/stm/tRef.d.ts +3 -1
  107. package/dist/dts/internal/stm/tRef.d.ts.map +1 -1
  108. package/dist/dts/internal/stm/tSubscriptionRef.d.ts +2 -0
  109. package/dist/dts/internal/stm/tSubscriptionRef.d.ts.map +1 -0
  110. package/dist/dts/internal/stream.d.ts.map +1 -1
  111. package/dist/esm/Arbitrary.js +472 -0
  112. package/dist/esm/Arbitrary.js.map +1 -0
  113. package/dist/esm/Effect.js +256 -18
  114. package/dist/esm/Effect.js.map +1 -1
  115. package/dist/esm/FastCheck.js +9 -0
  116. package/dist/esm/FastCheck.js.map +1 -0
  117. package/dist/esm/Inspectable.js +39 -2
  118. package/dist/esm/Inspectable.js.map +1 -1
  119. package/dist/esm/JSONSchema.js +408 -0
  120. package/dist/esm/JSONSchema.js.map +1 -0
  121. package/dist/esm/ParseResult.js +1503 -0
  122. package/dist/esm/ParseResult.js.map +1 -0
  123. package/dist/esm/Predicate.js +2 -1
  124. package/dist/esm/Predicate.js.map +1 -1
  125. package/dist/esm/Pretty.js +173 -0
  126. package/dist/esm/Pretty.js.map +1 -0
  127. package/dist/esm/Schema.js +5328 -0
  128. package/dist/esm/Schema.js.map +1 -0
  129. package/dist/esm/SchemaAST.js +2300 -0
  130. package/dist/esm/SchemaAST.js.map +1 -0
  131. package/dist/esm/Stream.js +14 -0
  132. package/dist/esm/Stream.js.map +1 -1
  133. package/dist/esm/TPubSub.js +8 -0
  134. package/dist/esm/TPubSub.js.map +1 -1
  135. package/dist/esm/TQueue.js.map +1 -1
  136. package/dist/esm/TRef.js.map +1 -1
  137. package/dist/esm/TSubscriptionRef.js +87 -0
  138. package/dist/esm/TSubscriptionRef.js.map +1 -0
  139. package/dist/esm/index.js +32 -0
  140. package/dist/esm/index.js.map +1 -1
  141. package/dist/esm/internal/cause.js +3 -3
  142. package/dist/esm/internal/cause.js.map +1 -1
  143. package/dist/esm/internal/core.js +4 -4
  144. package/dist/esm/internal/core.js.map +1 -1
  145. package/dist/esm/internal/fiberRuntime.js +14 -12
  146. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  147. package/dist/esm/internal/logger.js +7 -6
  148. package/dist/esm/internal/logger.js.map +1 -1
  149. package/dist/esm/internal/redacted.js +4 -0
  150. package/dist/esm/internal/redacted.js.map +1 -1
  151. package/dist/esm/internal/schema/errors.js +87 -0
  152. package/dist/esm/internal/schema/errors.js.map +1 -0
  153. package/dist/esm/internal/schema/filters.js +35 -0
  154. package/dist/esm/internal/schema/filters.js.map +1 -0
  155. package/dist/esm/internal/schema/util.js +78 -0
  156. package/dist/esm/internal/schema/util.js.map +1 -0
  157. package/dist/esm/internal/stm/core.js +1 -2
  158. package/dist/esm/internal/stm/core.js.map +1 -1
  159. package/dist/esm/internal/stm/tPubSub.js.map +1 -1
  160. package/dist/esm/internal/stm/tQueue.js +1 -2
  161. package/dist/esm/internal/stm/tQueue.js.map +1 -1
  162. package/dist/esm/internal/stm/tRef.js +5 -1
  163. package/dist/esm/internal/stm/tRef.js.map +1 -1
  164. package/dist/esm/internal/stm/tSubscriptionRef.js +166 -0
  165. package/dist/esm/internal/stm/tSubscriptionRef.js.map +1 -0
  166. package/dist/esm/internal/stream.js +33 -15
  167. package/dist/esm/internal/stream.js.map +1 -1
  168. package/dist/esm/internal/version.js +1 -1
  169. package/dist/esm/internal/version.js.map +1 -1
  170. package/package.json +68 -1
  171. package/src/Arbitrary.ts +563 -0
  172. package/src/Effect.ts +302 -31
  173. package/src/FastCheck.ts +9 -0
  174. package/src/Inspectable.ts +56 -2
  175. package/src/JSONSchema.ts +601 -0
  176. package/src/ParseResult.ts +2027 -0
  177. package/src/Predicate.ts +3 -1
  178. package/src/Pretty.ts +204 -0
  179. package/src/Schema.ts +10388 -0
  180. package/src/SchemaAST.ts +2827 -0
  181. package/src/Stream.ts +77 -9
  182. package/src/TPubSub.ts +9 -0
  183. package/src/TQueue.ts +7 -7
  184. package/src/TRef.ts +2 -1
  185. package/src/TSubscriptionRef.ts +284 -0
  186. package/src/index.ts +40 -0
  187. package/src/internal/cause.ts +3 -3
  188. package/src/internal/core-effect.ts +2 -2
  189. package/src/internal/core.ts +4 -4
  190. package/src/internal/fiberRuntime.ts +14 -12
  191. package/src/internal/logger.ts +7 -6
  192. package/src/internal/redacted.ts +4 -0
  193. package/src/internal/schema/errors.ts +189 -0
  194. package/src/internal/schema/filters.ts +86 -0
  195. package/src/internal/schema/util.ts +113 -0
  196. package/src/internal/stm/core.ts +1 -2
  197. package/src/internal/stm/tPubSub.ts +1 -0
  198. package/src/internal/stm/tQueue.ts +2 -2
  199. package/src/internal/stm/tRef.ts +7 -2
  200. package/src/internal/stm/tSubscriptionRef.ts +286 -0
  201. package/src/internal/stream.ts +97 -20
  202. package/src/internal/version.ts +1 -1
package/src/Effect.ts CHANGED
@@ -1669,26 +1669,46 @@ export const validateFirst: {
1669
1669
  // -------------------------------------------------------------------------------------
1670
1670
 
1671
1671
  /**
1672
- * Imports an asynchronous side-effect into a pure `Effect` value. The callback
1673
- * function `Effect<A, E, R> => void` **MUST** be called at most once.
1672
+ * Creates an `Effect` from a callback-based asynchronous API.
1674
1673
  *
1675
- * The registration function can optionally return an Effect, which will be
1676
- * executed if the `Fiber` executing this Effect is interrupted.
1674
+ * Useful for integrating Node.js-style callback functions into the Effect system.
1677
1675
  *
1678
- * The registration function can also receive an `AbortSignal` if required for
1676
+ * The `resume` function **MUST** be called at most once.
1677
+ *
1678
+ * The `resume` function can optionally return an `Effect`, which will be
1679
+ * executed if the `Fiber` executing this `Effect` is interrupted.
1680
+ *
1681
+ * The `resume` function can also receive an `AbortSignal` if required for
1679
1682
  * interruption.
1680
1683
  *
1681
1684
  * The `FiberId` of the fiber that may complete the async callback may also be
1682
1685
  * specified. This is called the "blocking fiber" because it suspends the fiber
1683
- * executing the `async` Effect (i.e. semantically blocks the fiber from making
1686
+ * executing the `async` effect (i.e. semantically blocks the fiber from making
1684
1687
  * progress). Specifying this fiber id in cases where it is known will improve
1685
1688
  * diagnostics, but not affect the behavior of the returned effect.
1686
1689
  *
1690
+ * @example
1691
+ * import { Effect } from "effect"
1692
+ * import * as fs from "fs"
1693
+ *
1694
+ * // Wrapping a callback-based API using Effect.async
1695
+ * const readFile = (filename: string) => Effect.async<Buffer, Error>((resume) => {
1696
+ * fs.readFile(filename, (error, data) => {
1697
+ * if (error) {
1698
+ * resume(Effect.fail(error))
1699
+ * } else {
1700
+ * resume(Effect.succeed(data))
1701
+ * }
1702
+ * });
1703
+ * });
1704
+ *
1705
+ * const program = readFile("todos.txt")
1706
+ *
1687
1707
  * @since 2.0.0
1688
1708
  * @category constructors
1689
1709
  */
1690
1710
  export const async: <A, E = never, R = never>(
1691
- register: (callback: (_: Effect<A, E, R>) => void, signal: AbortSignal) => void | Effect<void, never, R>,
1711
+ resume: (callback: (_: Effect<A, E, R>) => void, signal: AbortSignal) => void | Effect<void, never, R>,
1692
1712
  blockingOn?: FiberId.FiberId
1693
1713
  ) => Effect<A, E, R> = core.async
1694
1714
 
@@ -1796,6 +1816,29 @@ export const withFiberRuntime: <A, E = never, R = never>(
1796
1816
  ) => Effect<A, E, R> = core.withFiberRuntime
1797
1817
 
1798
1818
  /**
1819
+ * Creates an `Effect` that represents a recoverable error.
1820
+ *
1821
+ * This `Effect` does not succeed but instead fails with the provided error. The
1822
+ * failure can be of any type, and will propagate through the effect pipeline
1823
+ * unless handled.
1824
+ *
1825
+ * Use this function when you want to explicitly signal an error in an `Effect`
1826
+ * computation. The failed effect can later be handled with functions like
1827
+ * {@link catchAll} or {@link catchTag}.
1828
+ *
1829
+ * @example
1830
+ * import { Effect } from "effect"
1831
+ *
1832
+ * // Example of creating a failed effect
1833
+ * const failedEffect = Effect.fail("Something went wrong")
1834
+ *
1835
+ * // Handle the failure
1836
+ * failedEffect.pipe(
1837
+ * Effect.catchAll((error) => Effect.succeed(`Recovered from: ${error}`)),
1838
+ * Effect.runPromise
1839
+ * ).then(console.log)
1840
+ * // Output: "Recovered from: Something went wrong"
1841
+ *
1799
1842
  * @since 2.0.0
1800
1843
  * @category constructors
1801
1844
  */
@@ -2155,10 +2198,23 @@ export const none: <A, E, R>(
2155
2198
  ) => Effect<void, E | Cause.NoSuchElementException, R> = effect.none
2156
2199
 
2157
2200
  /**
2158
- * Like `tryPromise` but produces a defect in case of errors.
2201
+ * Creates an `Effect` that represents an asynchronous computation guaranteed to succeed.
2202
+ *
2203
+ * The provided function (`thunk`) returns a `Promise` that should never reject.
2204
+ * If the `Promise` does reject, the rejection is treated as a defect.
2159
2205
  *
2160
2206
  * An optional `AbortSignal` can be provided to allow for interruption of the
2161
- * wrapped Promise api.
2207
+ * wrapped `Promise` API.
2208
+ *
2209
+ * @example
2210
+ * import { Effect } from "effect"
2211
+ *
2212
+ * // Creating an effect that resolves after a delay
2213
+ * const delay = (message: string) => Effect.promise(() => new Promise((resolve) => {
2214
+ * setTimeout(() => resolve(message), 2000)
2215
+ * }))
2216
+ *
2217
+ * const program = delay("Async operation completed successfully!")
2162
2218
  *
2163
2219
  * @since 2.0.0
2164
2220
  * @category constructors
@@ -2168,6 +2224,17 @@ export const promise: <A>(
2168
2224
  ) => Effect<A> = effect.promise
2169
2225
 
2170
2226
  /**
2227
+ * Creates an `Effect` that succeeds with the provided value.
2228
+ *
2229
+ * Use this function to represent a successful computation that yields a value of type `A`.
2230
+ * The effect does not fail and does not require any environmental context.
2231
+ *
2232
+ * @example
2233
+ * import { Effect } from "effect"
2234
+ *
2235
+ * // Creating an effect that succeeds with the number 42
2236
+ * const success = Effect.succeed(42)
2237
+ *
2171
2238
  * @since 2.0.0
2172
2239
  * @category constructors
2173
2240
  */
@@ -2190,16 +2257,50 @@ export const succeedNone: Effect<Option.Option<never>> = effect.succeedNone
2190
2257
  export const succeedSome: <A>(value: A) => Effect<Option.Option<A>> = effect.succeedSome
2191
2258
 
2192
2259
  /**
2260
+ * Creates an `Effect` that defers the creation of another effect until it is needed.
2261
+ *
2262
+ * Useful for lazy evaluation, handling circular dependencies, or avoiding eager execution in recursive functions.
2263
+ *
2264
+ * @example
2265
+ * import { Effect } from "effect"
2266
+ *
2267
+ * // Handling recursion without stack overflow
2268
+ * const fibonacci = (n: number): Effect.Effect<number> =>
2269
+ * n < 2
2270
+ * ? Effect.succeed(1)
2271
+ * : Effect.zipWith(
2272
+ * Effect.suspend(() => fibonacci(n - 1)),
2273
+ * Effect.suspend(() => fibonacci(n - 2)),
2274
+ * (a, b) => a + b
2275
+ * )
2276
+ *
2277
+ * console.log(Effect.runSync(fibonacci(10))) // Output: 89
2278
+ *
2193
2279
  * @since 2.0.0
2194
2280
  * @category constructors
2195
2281
  */
2196
2282
  export const suspend: <A, E, R>(effect: LazyArg<Effect<A, E, R>>) => Effect<A, E, R> = core.suspend
2197
2283
 
2198
2284
  /**
2285
+ * Creates an `Effect` that represents a synchronous side-effectful computation.
2286
+ *
2287
+ * The provided function (`thunk`) should not throw errors; if it does, the error is treated as a defect.
2288
+ * Use `Effect.sync` when you are certain the operation will not fail.
2289
+ *
2290
+ * @example
2291
+ * import { Effect } from "effect"
2292
+ *
2293
+ * // Creating an effect that logs a message
2294
+ * const log = (message: string) => Effect.sync(() => {
2295
+ * console.log(message) // side effect
2296
+ * })
2297
+ *
2298
+ * const program = log("Hello, World!")
2299
+ *
2199
2300
  * @since 2.0.0
2200
2301
  * @category constructors
2201
2302
  */
2202
- export const sync: <A>(evaluate: LazyArg<A>) => Effect<A> = core.sync
2303
+ export const sync: <A>(thunk: LazyArg<A>) => Effect<A> = core.sync
2203
2304
 
2204
2305
  const _void: Effect<void> = core.void
2205
2306
  export {
@@ -2765,13 +2866,20 @@ export const retryOrElse: {
2765
2866
 
2766
2867
  const try_: {
2767
2868
  <A, E>(options: { readonly try: LazyArg<A>; readonly catch: (error: unknown) => E }): Effect<A, E>
2768
- <A>(evaluate: LazyArg<A>): Effect<A, Cause.UnknownException>
2869
+ <A>(thunk: LazyArg<A>): Effect<A, Cause.UnknownException>
2769
2870
  } = effect.try_
2770
2871
 
2771
2872
  export {
2772
2873
  /**
2773
- * Imports a synchronous side-effect into a pure `Effect` value, translating any
2774
- * thrown exceptions into typed failed effects creating with `Effect.fail`.
2874
+ * Creates an `Effect` that represents a synchronous computation that might fail.
2875
+ *
2876
+ * If the function (`thunk`) throws an error, it is caught and the effect fails with an `UnknownException`.
2877
+ *
2878
+ * **Overload with custom error handling:**
2879
+ *
2880
+ * Creates an `Effect` that represents a synchronous computation that might fail, with custom error mapping.
2881
+ *
2882
+ * If the `try` function throws an error, the `catch` function maps it to an error of type `E`.
2775
2883
  *
2776
2884
  * @since 2.0.0
2777
2885
  * @category error handling
@@ -2822,7 +2930,7 @@ export const tryMap: {
2822
2930
  * via the `catch` function.
2823
2931
  *
2824
2932
  * An optional `AbortSignal` can be provided to allow for interruption of the
2825
- * wrapped Promise api.
2933
+ * wrapped `Promise` API.
2826
2934
  *
2827
2935
  * @since 2.0.0
2828
2936
  * @category error handling
@@ -2834,7 +2942,7 @@ export const tryMapPromise: {
2834
2942
  * via the `catch` function.
2835
2943
  *
2836
2944
  * An optional `AbortSignal` can be provided to allow for interruption of the
2837
- * wrapped Promise api.
2945
+ * wrapped `Promise` API.
2838
2946
  *
2839
2947
  * @since 2.0.0
2840
2948
  * @category error handling
@@ -2848,7 +2956,7 @@ export const tryMapPromise: {
2848
2956
  * via the `catch` function.
2849
2957
  *
2850
2958
  * An optional `AbortSignal` can be provided to allow for interruption of the
2851
- * wrapped Promise api.
2959
+ * wrapped `Promise` API.
2852
2960
  *
2853
2961
  * @since 2.0.0
2854
2962
  * @category error handling
@@ -2860,40 +2968,88 @@ export const tryMapPromise: {
2860
2968
  } = effect.tryMapPromise
2861
2969
 
2862
2970
  /**
2863
- * Create an `Effect` that when executed will construct `promise` and wait for
2864
- * its result, errors will produce failure as `unknown`.
2971
+ * Creates an `Effect` that represents an asynchronous computation that might fail.
2972
+ *
2973
+ * If the `Promise` returned by `evaluate` rejects, the error is caught and the effect fails with an `UnknownException`.
2865
2974
  *
2866
2975
  * An optional `AbortSignal` can be provided to allow for interruption of the
2867
- * wrapped Promise api.
2976
+ * wrapped `Promise` API.
2977
+ *
2978
+ * **Overload with custom error handling:**
2979
+ *
2980
+ * Creates an `Effect` that represents an asynchronous computation that might fail, with custom error mapping.
2981
+ *
2982
+ * If the `Promise` rejects, the `catch` function maps the error to an error of type `E`.
2983
+ *
2984
+ * @example
2985
+ * import { Effect } from "effect"
2986
+ *
2987
+ * // Fetching data from an API that may fail
2988
+ * const getTodo = (id: number) => Effect.tryPromise(() =>
2989
+ * fetch(`https://jsonplaceholder.typicode.com/todos/${id}`)
2990
+ * )
2868
2991
  *
2869
2992
  * @since 2.0.0
2870
2993
  * @category error handling
2871
2994
  */
2872
2995
  export const tryPromise: {
2873
2996
  /**
2874
- * Create an `Effect` that when executed will construct `promise` and wait for
2875
- * its result, errors will produce failure as `unknown`.
2997
+ * Creates an `Effect` that represents an asynchronous computation that might fail.
2998
+ *
2999
+ * If the `Promise` returned by `evaluate` rejects, the error is caught and the effect fails with an `UnknownException`.
2876
3000
  *
2877
3001
  * An optional `AbortSignal` can be provided to allow for interruption of the
2878
- * wrapped Promise api.
3002
+ * wrapped `Promise` API.
3003
+ *
3004
+ * **Overload with custom error handling:**
3005
+ *
3006
+ * Creates an `Effect` that represents an asynchronous computation that might fail, with custom error mapping.
3007
+ *
3008
+ * If the `Promise` rejects, the `catch` function maps the error to an error of type `E`.
3009
+ *
3010
+ * @example
3011
+ * import { Effect } from "effect"
3012
+ *
3013
+ * // Fetching data from an API that may fail
3014
+ * const getTodo = (id: number) => Effect.tryPromise(() =>
3015
+ * fetch(`https://jsonplaceholder.typicode.com/todos/${id}`)
3016
+ * )
2879
3017
  *
2880
3018
  * @since 2.0.0
2881
3019
  * @category error handling
2882
3020
  */
2883
3021
  <A, E>(
2884
- options: { readonly try: (signal: AbortSignal) => PromiseLike<A>; readonly catch: (error: unknown) => E }
3022
+ options: {
3023
+ readonly try: (signal: AbortSignal) => PromiseLike<A>
3024
+ readonly catch: (error: unknown) => E
3025
+ }
2885
3026
  ): Effect<A, E>
2886
3027
  /**
2887
- * Create an `Effect` that when executed will construct `promise` and wait for
2888
- * its result, errors will produce failure as `unknown`.
3028
+ * Creates an `Effect` that represents an asynchronous computation that might fail.
3029
+ *
3030
+ * If the `Promise` returned by `evaluate` rejects, the error is caught and the effect fails with an `UnknownException`.
2889
3031
  *
2890
3032
  * An optional `AbortSignal` can be provided to allow for interruption of the
2891
- * wrapped Promise api.
3033
+ * wrapped `Promise` API.
3034
+ *
3035
+ * **Overload with custom error handling:**
3036
+ *
3037
+ * Creates an `Effect` that represents an asynchronous computation that might fail, with custom error mapping.
3038
+ *
3039
+ * If the `Promise` rejects, the `catch` function maps the error to an error of type `E`.
3040
+ *
3041
+ * @example
3042
+ * import { Effect } from "effect"
3043
+ *
3044
+ * // Fetching data from an API that may fail
3045
+ * const getTodo = (id: number) => Effect.tryPromise(() =>
3046
+ * fetch(`https://jsonplaceholder.typicode.com/todos/${id}`)
3047
+ * )
2892
3048
  *
2893
3049
  * @since 2.0.0
2894
3050
  * @category error handling
2895
3051
  */
2896
- <A>(try_: (signal: AbortSignal) => PromiseLike<A>): Effect<A, Cause.UnknownException>
3052
+ <A>(evaluate: (signal: AbortSignal) => PromiseLike<A>): Effect<A, Cause.UnknownException>
2897
3053
  } = effect.tryPromise
2898
3054
 
2899
3055
  /**
@@ -9222,6 +9378,28 @@ export const makeLatch: (open?: boolean | undefined) => Effect<Latch, never, nev
9222
9378
  // -------------------------------------------------------------------------------------
9223
9379
 
9224
9380
  /**
9381
+ * Executes an effect and returns a `RuntimeFiber` that represents the running computation.
9382
+ *
9383
+ * Use `runFork` when you want to start an effect without blocking the current execution flow.
9384
+ * It returns a fiber that you can observe, interrupt, or join as needed.
9385
+ *
9386
+ * @example
9387
+ * import { Effect, Console, Schedule, Fiber } from "effect"
9388
+ *
9389
+ * // Define an effect that repeats a message every 200 milliseconds
9390
+ * const program = Effect.repeat(
9391
+ * Console.log("running..."),
9392
+ * Schedule.spaced("200 millis")
9393
+ * )
9394
+ *
9395
+ * // Start the effect without blocking
9396
+ * const fiber = Effect.runFork(program)
9397
+ *
9398
+ * // Interrupt the fiber after 500 milliseconds
9399
+ * setTimeout(() => {
9400
+ * Effect.runFork(Fiber.interrupt(fiber))
9401
+ * }, 500)
9402
+ *
9225
9403
  * @since 2.0.0
9226
9404
  * @category execution
9227
9405
  */
@@ -9240,8 +9418,21 @@ export const runCallback: <A, E>(
9240
9418
  ) => Runtime.Cancel<A, E> = _runtime.unsafeRunEffect
9241
9419
 
9242
9420
  /**
9243
- * Runs an `Effect` workflow, returning a `Promise` which resolves with the
9244
- * result of the workflow or rejects with an error.
9421
+ * Executes an effect and returns a `Promise` that resolves with the result.
9422
+ *
9423
+ * Use `runPromise` when working with asynchronous effects and you need to integrate with code that uses Promises.
9424
+ * If the effect fails, the returned Promise will be rejected with the error.
9425
+ *
9426
+ * @example
9427
+ * import { Effect } from "effect"
9428
+ *
9429
+ * // Execute an effect and handle the result with a Promise
9430
+ * Effect.runPromise(Effect.succeed(1)).then(console.log) // Output: 1
9431
+ *
9432
+ * // Execute a failing effect and handle the rejection
9433
+ * Effect.runPromise(Effect.fail("my error")).catch((error) => {
9434
+ * console.error("Effect failed with error:", error)
9435
+ * })
9245
9436
  *
9246
9437
  * @since 2.0.0
9247
9438
  * @category execution
@@ -9252,8 +9443,35 @@ export const runPromise: <A, E>(
9252
9443
  ) => Promise<A> = _runtime.unsafeRunPromiseEffect
9253
9444
 
9254
9445
  /**
9255
- * Runs an `Effect` workflow, returning a `Promise` which resolves with the
9256
- * `Exit` value of the workflow.
9446
+ * Executes an effect and returns a `Promise` that resolves with an `Exit` describing the result.
9447
+ *
9448
+ * Use `runPromiseExit` when you need detailed information about the outcome of the effect, including success or failure,
9449
+ * and you want to work with Promises.
9450
+ *
9451
+ * @example
9452
+ * import { Effect } from "effect"
9453
+ *
9454
+ * // Execute a successful effect and get the Exit result as a Promise
9455
+ * Effect.runPromiseExit(Effect.succeed(1)).then(console.log)
9456
+ * // Output:
9457
+ * // {
9458
+ * // _id: "Exit",
9459
+ * // _tag: "Success",
9460
+ * // value: 1
9461
+ * // }
9462
+ *
9463
+ * // Execute a failing effect and get the Exit result as a Promise
9464
+ * Effect.runPromiseExit(Effect.fail("my error")).then(console.log)
9465
+ * // Output:
9466
+ * // {
9467
+ * // _id: "Exit",
9468
+ * // _tag: "Failure",
9469
+ * // cause: {
9470
+ * // _id: "Cause",
9471
+ * // _tag: "Fail",
9472
+ * // failure: "my error"
9473
+ * // }
9474
+ * // }
9257
9475
  *
9258
9476
  * @since 2.0.0
9259
9477
  * @category execution
@@ -9264,12 +9482,65 @@ export const runPromiseExit: <A, E>(
9264
9482
  ) => Promise<Exit.Exit<A, E>> = _runtime.unsafeRunPromiseExitEffect
9265
9483
 
9266
9484
  /**
9485
+ * Executes an effect synchronously and returns its result.
9486
+ *
9487
+ * Use `runSync` when you are certain that the effect is purely synchronous and will not perform any asynchronous operations.
9488
+ * If the effect fails or contains asynchronous tasks, it will throw an error.
9489
+ *
9490
+ * @example
9491
+ * import { Effect } from "effect"
9492
+ *
9493
+ * // Define a synchronous effect
9494
+ * const program = Effect.sync(() => {
9495
+ * console.log("Hello, World!")
9496
+ * return 1
9497
+ * })
9498
+ *
9499
+ * // Execute the effect synchronously
9500
+ * const result = Effect.runSync(program)
9501
+ * // Output: Hello, World!
9502
+ *
9503
+ * console.log(result)
9504
+ * // Output: 1
9505
+ *
9267
9506
  * @since 2.0.0
9268
9507
  * @category execution
9269
9508
  */
9270
9509
  export const runSync: <A, E>(effect: Effect<A, E>) => A = _runtime.unsafeRunSyncEffect
9271
9510
 
9272
9511
  /**
9512
+ * Executes an effect synchronously and returns an `Exit` describing the result.
9513
+ *
9514
+ * Use `runSyncExit` when you need detailed information about the outcome of the effect,
9515
+ * including whether it succeeded or failed, without throwing exceptions.
9516
+ *
9517
+ * @example
9518
+ * import { Effect } from "effect"
9519
+ *
9520
+ * // Execute a successful effect and get the Exit result
9521
+ * const result1 = Effect.runSyncExit(Effect.succeed(1))
9522
+ * console.log(result1)
9523
+ * // Output:
9524
+ * // {
9525
+ * // _id: "Exit",
9526
+ * // _tag: "Success",
9527
+ * // value: 1
9528
+ * // }
9529
+ *
9530
+ * // Execute a failing effect and get the Exit result
9531
+ * const result2 = Effect.runSyncExit(Effect.fail("my error"))
9532
+ * console.log(result2)
9533
+ * // Output:
9534
+ * // {
9535
+ * // _id: "Exit",
9536
+ * // _tag: "Failure",
9537
+ * // cause: {
9538
+ * // _id: "Cause",
9539
+ * // _tag: "Fail",
9540
+ * // failure: "my error"
9541
+ * // }
9542
+ * // }
9543
+ *
9273
9544
  * @since 2.0.0
9274
9545
  * @category execution
9275
9546
  */
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @since 3.10.0
3
+ */
4
+
5
+ /**
6
+ * @category re-exports
7
+ * @since 3.10.0
8
+ */
9
+ export * from "fast-check"
@@ -2,6 +2,8 @@
2
2
  * @since 2.0.0
3
3
  */
4
4
 
5
+ import type * as FiberRefs from "./FiberRefs.js"
6
+ import { globalValue } from "./GlobalValue.js"
5
7
  import { hasProperty, isFunction } from "./Predicate.js"
6
8
 
7
9
  /**
@@ -38,7 +40,7 @@ export const toJSON = (x: unknown): unknown => {
38
40
  } else if (Array.isArray(x)) {
39
41
  return x.map(toJSON)
40
42
  }
41
- return x
43
+ return redact(x)
42
44
  }
43
45
 
44
46
  /**
@@ -108,10 +110,62 @@ export const stringifyCircular = (obj: unknown, whitespace?: number | string | u
108
110
  typeof value === "object" && value !== null
109
111
  ? cache.includes(value)
110
112
  ? undefined // circular reference
111
- : cache.push(value) && value
113
+ : cache.push(value) && (redactableState.fiberRefs !== undefined && isRedactable(value)
114
+ ? value[symbolRedactable](redactableState.fiberRefs)
115
+ : value)
112
116
  : value,
113
117
  whitespace
114
118
  )
115
119
  ;(cache as any) = undefined
116
120
  return retVal
117
121
  }
122
+
123
+ /**
124
+ * @since 3.10.0
125
+ * @category redactable
126
+ */
127
+ export interface Redactable {
128
+ readonly [symbolRedactable]: (fiberRefs: FiberRefs.FiberRefs) => unknown
129
+ }
130
+
131
+ /**
132
+ * @since 3.10.0
133
+ * @category redactable
134
+ */
135
+ export const symbolRedactable: unique symbol = Symbol.for("effect/Inspectable/Redactable")
136
+
137
+ /**
138
+ * @since 3.10.0
139
+ * @category redactable
140
+ */
141
+ export const isRedactable = (u: unknown): u is Redactable =>
142
+ typeof u === "object" && u !== null && symbolRedactable in u
143
+
144
+ const redactableState = globalValue("effect/Inspectable/redactableState", () => ({
145
+ fiberRefs: undefined as FiberRefs.FiberRefs | undefined
146
+ }))
147
+
148
+ /**
149
+ * @since 3.10.0
150
+ * @category redactable
151
+ */
152
+ export const withRedactableContext = <A>(context: FiberRefs.FiberRefs, f: () => A): A => {
153
+ const prev = redactableState.fiberRefs
154
+ redactableState.fiberRefs = context
155
+ try {
156
+ return f()
157
+ } finally {
158
+ redactableState.fiberRefs = prev
159
+ }
160
+ }
161
+
162
+ /**
163
+ * @since 3.10.0
164
+ * @category redactable
165
+ */
166
+ export const redact = (u: unknown): unknown => {
167
+ if (isRedactable(u) && redactableState.fiberRefs !== undefined) {
168
+ return u[symbolRedactable](redactableState.fiberRefs)
169
+ }
170
+ return u
171
+ }