effect 4.0.0-beta.10 → 4.0.0-beta.12

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 (189) hide show
  1. package/dist/Channel.d.ts +7 -7
  2. package/dist/Config.d.ts +157 -0
  3. package/dist/Config.d.ts.map +1 -1
  4. package/dist/Config.js +56 -1
  5. package/dist/Config.js.map +1 -1
  6. package/dist/Effect.d.ts +296 -8
  7. package/dist/Effect.d.ts.map +1 -1
  8. package/dist/Effect.js +72 -0
  9. package/dist/Effect.js.map +1 -1
  10. package/dist/ErrorReporter.d.ts +376 -0
  11. package/dist/ErrorReporter.d.ts.map +1 -0
  12. package/dist/ErrorReporter.js +246 -0
  13. package/dist/ErrorReporter.js.map +1 -0
  14. package/dist/Fiber.d.ts +2 -2
  15. package/dist/Fiber.d.ts.map +1 -1
  16. package/dist/Fiber.js.map +1 -1
  17. package/dist/Graph.d.ts.map +1 -1
  18. package/dist/Graph.js +3 -6
  19. package/dist/Graph.js.map +1 -1
  20. package/dist/LogLevel.d.ts +5 -0
  21. package/dist/LogLevel.d.ts.map +1 -1
  22. package/dist/LogLevel.js.map +1 -1
  23. package/dist/Logger.d.ts +25 -91
  24. package/dist/Logger.d.ts.map +1 -1
  25. package/dist/Logger.js +2 -3
  26. package/dist/Logger.js.map +1 -1
  27. package/dist/Queue.d.ts.map +1 -1
  28. package/dist/Queue.js +0 -1
  29. package/dist/Queue.js.map +1 -1
  30. package/dist/Random.d.ts +17 -0
  31. package/dist/Random.d.ts.map +1 -1
  32. package/dist/Random.js +17 -0
  33. package/dist/Random.js.map +1 -1
  34. package/dist/References.d.ts +3 -3
  35. package/dist/References.d.ts.map +1 -1
  36. package/dist/Schema.d.ts +3 -1
  37. package/dist/Schema.d.ts.map +1 -1
  38. package/dist/SchemaAST.d.ts.map +1 -1
  39. package/dist/SchemaAST.js +2 -1
  40. package/dist/SchemaAST.js.map +1 -1
  41. package/dist/Stream.d.ts +5 -5
  42. package/dist/index.d.ts +4 -0
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +4 -0
  45. package/dist/index.js.map +1 -1
  46. package/dist/internal/effect.js +98 -33
  47. package/dist/internal/effect.js.map +1 -1
  48. package/dist/internal/hashMap.js +2 -2
  49. package/dist/internal/hashMap.js.map +1 -1
  50. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  51. package/dist/unstable/ai/LanguageModel.js +86 -14
  52. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  53. package/dist/unstable/ai/McpSchema.d.ts +112 -36
  54. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  55. package/dist/unstable/ai/McpSchema.js +47 -10
  56. package/dist/unstable/ai/McpSchema.js.map +1 -1
  57. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  58. package/dist/unstable/ai/McpServer.js +33 -6
  59. package/dist/unstable/ai/McpServer.js.map +1 -1
  60. package/dist/unstable/ai/Tool.d.ts +16 -0
  61. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  62. package/dist/unstable/ai/Tool.js +14 -0
  63. package/dist/unstable/ai/Tool.js.map +1 -1
  64. package/dist/unstable/cli/CliOutput.js +37 -6
  65. package/dist/unstable/cli/CliOutput.js.map +1 -1
  66. package/dist/unstable/cli/Command.d.ts +199 -7
  67. package/dist/unstable/cli/Command.d.ts.map +1 -1
  68. package/dist/unstable/cli/Command.js +116 -6
  69. package/dist/unstable/cli/Command.js.map +1 -1
  70. package/dist/unstable/cli/HelpDoc.d.ts +60 -2
  71. package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
  72. package/dist/unstable/cli/internal/command.d.ts +11 -1
  73. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  74. package/dist/unstable/cli/internal/command.js +33 -8
  75. package/dist/unstable/cli/internal/command.js.map +1 -1
  76. package/dist/unstable/cli/internal/completions/CommandDescriptor.js +7 -2
  77. package/dist/unstable/cli/internal/completions/CommandDescriptor.js.map +1 -1
  78. package/dist/unstable/cli/internal/parser.js +10 -2
  79. package/dist/unstable/cli/internal/parser.js.map +1 -1
  80. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  81. package/dist/unstable/cluster/ClusterWorkflowEngine.js +2 -2
  82. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  83. package/dist/unstable/http/Headers.d.ts.map +1 -1
  84. package/dist/unstable/http/Headers.js +27 -10
  85. package/dist/unstable/http/Headers.js.map +1 -1
  86. package/dist/unstable/http/HttpClient.d.ts +28 -4
  87. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  88. package/dist/unstable/http/HttpClient.js.map +1 -1
  89. package/dist/unstable/http/HttpEffect.d.ts +3 -8
  90. package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
  91. package/dist/unstable/http/HttpEffect.js +25 -31
  92. package/dist/unstable/http/HttpEffect.js.map +1 -1
  93. package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
  94. package/dist/unstable/http/HttpMiddleware.js +4 -8
  95. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  96. package/dist/unstable/http/HttpServerError.d.ts +14 -27
  97. package/dist/unstable/http/HttpServerError.d.ts.map +1 -1
  98. package/dist/unstable/http/HttpServerError.js +37 -44
  99. package/dist/unstable/http/HttpServerError.js.map +1 -1
  100. package/dist/unstable/http/HttpServerRespondable.d.ts +2 -2
  101. package/dist/unstable/http/HttpServerRespondable.d.ts.map +1 -1
  102. package/dist/unstable/http/HttpServerRespondable.js +5 -5
  103. package/dist/unstable/http/HttpServerRespondable.js.map +1 -1
  104. package/dist/unstable/http/HttpServerResponse.d.ts +2 -1
  105. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  106. package/dist/unstable/http/HttpServerResponse.js +2 -0
  107. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  108. package/dist/unstable/http/internal/preResponseHandler.d.ts +2 -0
  109. package/dist/unstable/http/internal/preResponseHandler.d.ts.map +1 -0
  110. package/dist/unstable/http/internal/preResponseHandler.js +10 -0
  111. package/dist/unstable/http/internal/preResponseHandler.js.map +1 -0
  112. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +1 -1
  113. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  114. package/dist/unstable/httpapi/HttpApiBuilder.js +1 -1
  115. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  116. package/dist/unstable/httpapi/HttpApiError.d.ts +11 -0
  117. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  118. package/dist/unstable/httpapi/HttpApiError.js +29 -9
  119. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  120. package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
  121. package/dist/unstable/observability/OtlpLogger.js +7 -4
  122. package/dist/unstable/observability/OtlpLogger.js.map +1 -1
  123. package/dist/unstable/reactivity/Atom.js +1 -1
  124. package/dist/unstable/reactivity/Atom.js.map +1 -1
  125. package/dist/unstable/reactivity/AtomRegistry.d.ts +6 -0
  126. package/dist/unstable/reactivity/AtomRegistry.d.ts.map +1 -1
  127. package/dist/unstable/reactivity/AtomRegistry.js +22 -1
  128. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  129. package/dist/unstable/rpc/RpcSchema.d.ts +13 -0
  130. package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
  131. package/dist/unstable/rpc/RpcSchema.js +14 -0
  132. package/dist/unstable/rpc/RpcSchema.js.map +1 -1
  133. package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
  134. package/dist/unstable/rpc/RpcSerialization.js +34 -9
  135. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  136. package/dist/unstable/rpc/RpcServer.d.ts +0 -7
  137. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  138. package/dist/unstable/rpc/RpcServer.js +9 -10
  139. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  140. package/dist/unstable/workflow/WorkflowEngine.d.ts +6 -0
  141. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  142. package/dist/unstable/workflow/WorkflowEngine.js +131 -0
  143. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  144. package/package.json +1 -1
  145. package/src/Channel.ts +9 -9
  146. package/src/Config.ts +171 -9
  147. package/src/Effect.ts +315 -8
  148. package/src/ErrorReporter.ts +459 -0
  149. package/src/Fiber.ts +9 -2
  150. package/src/Graph.ts +16 -6
  151. package/src/LogLevel.ts +6 -0
  152. package/src/Logger.ts +28 -95
  153. package/src/Queue.ts +0 -1
  154. package/src/Random.ts +18 -0
  155. package/src/References.ts +4 -4
  156. package/src/Schema.ts +1 -1
  157. package/src/SchemaAST.ts +2 -1
  158. package/src/Stream.ts +7 -7
  159. package/src/index.ts +5 -0
  160. package/src/internal/effect.ts +205 -49
  161. package/src/internal/hashMap.ts +2 -2
  162. package/src/unstable/ai/LanguageModel.ts +117 -16
  163. package/src/unstable/ai/McpSchema.ts +57 -11
  164. package/src/unstable/ai/McpServer.ts +44 -6
  165. package/src/unstable/ai/Tool.ts +15 -0
  166. package/src/unstable/cli/CliOutput.ts +45 -6
  167. package/src/unstable/cli/Command.ts +298 -11
  168. package/src/unstable/cli/HelpDoc.ts +68 -2
  169. package/src/unstable/cli/internal/command.ts +47 -11
  170. package/src/unstable/cli/internal/completions/CommandDescriptor.ts +7 -2
  171. package/src/unstable/cli/internal/parser.ts +11 -3
  172. package/src/unstable/cluster/ClusterWorkflowEngine.ts +2 -2
  173. package/src/unstable/http/Headers.ts +28 -13
  174. package/src/unstable/http/HttpClient.ts +45 -10
  175. package/src/unstable/http/HttpEffect.ts +30 -44
  176. package/src/unstable/http/HttpMiddleware.ts +4 -14
  177. package/src/unstable/http/HttpServerError.ts +42 -45
  178. package/src/unstable/http/HttpServerRespondable.ts +6 -6
  179. package/src/unstable/http/HttpServerResponse.ts +3 -1
  180. package/src/unstable/http/internal/preResponseHandler.ts +15 -0
  181. package/src/unstable/httpapi/HttpApiBuilder.ts +2 -1
  182. package/src/unstable/httpapi/HttpApiError.ts +30 -9
  183. package/src/unstable/observability/OtlpLogger.ts +9 -5
  184. package/src/unstable/reactivity/Atom.ts +1 -1
  185. package/src/unstable/reactivity/AtomRegistry.ts +29 -1
  186. package/src/unstable/rpc/RpcSchema.ts +17 -0
  187. package/src/unstable/rpc/RpcSerialization.ts +44 -9
  188. package/src/unstable/rpc/RpcServer.ts +14 -19
  189. package/src/unstable/workflow/WorkflowEngine.ts +178 -0
package/src/Config.ts CHANGED
@@ -886,18 +886,19 @@ export function schema<T, E>(codec: Schema.Codec<T, E>, path?: string | ConfigPr
886
886
  const decodeUnknownEffect = Parser.decodeUnknownEffect(toCodecStringTree)
887
887
  const toCodecStringTreeEncoded = AST.toEncoded(toCodecStringTree.ast)
888
888
  const defaultPath = typeof path === "string" ? [path] : path ?? []
889
- return make((provider) =>
890
- recur(toCodecStringTreeEncoded, provider, defaultPath).pipe(
889
+ return make((provider) => {
890
+ const path = provider.prefix ? [...provider.prefix, ...defaultPath] : defaultPath
891
+ return recur(toCodecStringTreeEncoded, provider, defaultPath).pipe(
891
892
  Effect.flatMapEager((tree) =>
892
- decodeUnknownEffect(tree).pipe(Effect.mapErrorEager((issue) =>
893
- new Schema.SchemaError(defaultPath.length > 0 ? new Issue.Pointer(defaultPath, issue) : issue)
894
- ))
893
+ decodeUnknownEffect(tree).pipe(
894
+ Effect.mapErrorEager((issue) =>
895
+ new Schema.SchemaError(path.length > 0 ? new Issue.Pointer(path, issue) : issue)
896
+ )
897
+ )
895
898
  ),
896
- Effect.mapErrorEager((cause) =>
897
- new ConfigError(cause)
898
- )
899
+ Effect.mapErrorEager((cause) => new ConfigError(cause))
899
900
  )
900
- )
901
+ })
901
902
  }
902
903
 
903
904
  /** @internal */
@@ -1446,3 +1447,164 @@ export function url(name?: string) {
1446
1447
  export function date(name?: string) {
1447
1448
  return schema(Schema.DateValid, name)
1448
1449
  }
1450
+
1451
+ /**
1452
+ * Scopes a config under a named prefix.
1453
+ *
1454
+ * When to use:
1455
+ * - Grouping related config keys under a common namespace (e.g.
1456
+ * `"database"`, `"redis"`).
1457
+ * - Building reusable config fragments that callers nest at different paths.
1458
+ *
1459
+ * The prefix is prepended to every key the inner config reads. With
1460
+ * `fromUnknown` this means an extra object level; with `fromEnv` it means
1461
+ * a `_`-separated prefix on env var names.
1462
+ *
1463
+ * Multiple `nested` calls compose: the outermost name becomes the
1464
+ * outermost path segment.
1465
+ *
1466
+ * **Example** (Nesting a struct config under `"database"`)
1467
+ *
1468
+ * ```ts
1469
+ * import { Config, ConfigProvider, Effect } from "effect"
1470
+ *
1471
+ * const dbConfig = Config.all({
1472
+ * host: Config.string("host"),
1473
+ * port: Config.number("port")
1474
+ * }).pipe(Config.nested("database"))
1475
+ *
1476
+ * const provider = ConfigProvider.fromUnknown({
1477
+ * database: { host: "localhost", port: "5432" }
1478
+ * })
1479
+ * // Effect.runSync(dbConfig.parse(provider))
1480
+ * // { host: "localhost", port: 5432 }
1481
+ * ```
1482
+ *
1483
+ * **Example** (Env vars with nested prefix)
1484
+ *
1485
+ * ```ts
1486
+ * import { Config, ConfigProvider, Effect } from "effect"
1487
+ *
1488
+ * const host = Config.string("host").pipe(Config.nested("database"))
1489
+ *
1490
+ * const provider = ConfigProvider.fromEnv({
1491
+ * env: { database_host: "localhost" }
1492
+ * })
1493
+ * // Effect.runSync(host.parse(provider)) // "localhost"
1494
+ * ```
1495
+ *
1496
+ * @see {@link all} – combine multiple configs into a struct
1497
+ * @see {@link schema} – read structured config from a schema
1498
+ *
1499
+ * @category Combinators
1500
+ * @since 4.0.0
1501
+ */
1502
+ export const nested: {
1503
+ /**
1504
+ * Scopes a config under a named prefix.
1505
+ *
1506
+ * When to use:
1507
+ * - Grouping related config keys under a common namespace (e.g.
1508
+ * `"database"`, `"redis"`).
1509
+ * - Building reusable config fragments that callers nest at different paths.
1510
+ *
1511
+ * The prefix is prepended to every key the inner config reads. With
1512
+ * `fromUnknown` this means an extra object level; with `fromEnv` it means
1513
+ * a `_`-separated prefix on env var names.
1514
+ *
1515
+ * Multiple `nested` calls compose: the outermost name becomes the
1516
+ * outermost path segment.
1517
+ *
1518
+ * **Example** (Nesting a struct config under `"database"`)
1519
+ *
1520
+ * ```ts
1521
+ * import { Config, ConfigProvider, Effect } from "effect"
1522
+ *
1523
+ * const dbConfig = Config.all({
1524
+ * host: Config.string("host"),
1525
+ * port: Config.number("port")
1526
+ * }).pipe(Config.nested("database"))
1527
+ *
1528
+ * const provider = ConfigProvider.fromUnknown({
1529
+ * database: { host: "localhost", port: "5432" }
1530
+ * })
1531
+ * // Effect.runSync(dbConfig.parse(provider))
1532
+ * // { host: "localhost", port: 5432 }
1533
+ * ```
1534
+ *
1535
+ * **Example** (Env vars with nested prefix)
1536
+ *
1537
+ * ```ts
1538
+ * import { Config, ConfigProvider, Effect } from "effect"
1539
+ *
1540
+ * const host = Config.string("host").pipe(Config.nested("database"))
1541
+ *
1542
+ * const provider = ConfigProvider.fromEnv({
1543
+ * env: { database_host: "localhost" }
1544
+ * })
1545
+ * // Effect.runSync(host.parse(provider)) // "localhost"
1546
+ * ```
1547
+ *
1548
+ * @see {@link all} – combine multiple configs into a struct
1549
+ * @see {@link schema} – read structured config from a schema
1550
+ *
1551
+ * @category Combinators
1552
+ * @since 4.0.0
1553
+ */
1554
+ (name: string): <A>(self: Config<A>) => Config<A>
1555
+ /**
1556
+ * Scopes a config under a named prefix.
1557
+ *
1558
+ * When to use:
1559
+ * - Grouping related config keys under a common namespace (e.g.
1560
+ * `"database"`, `"redis"`).
1561
+ * - Building reusable config fragments that callers nest at different paths.
1562
+ *
1563
+ * The prefix is prepended to every key the inner config reads. With
1564
+ * `fromUnknown` this means an extra object level; with `fromEnv` it means
1565
+ * a `_`-separated prefix on env var names.
1566
+ *
1567
+ * Multiple `nested` calls compose: the outermost name becomes the
1568
+ * outermost path segment.
1569
+ *
1570
+ * **Example** (Nesting a struct config under `"database"`)
1571
+ *
1572
+ * ```ts
1573
+ * import { Config, ConfigProvider, Effect } from "effect"
1574
+ *
1575
+ * const dbConfig = Config.all({
1576
+ * host: Config.string("host"),
1577
+ * port: Config.number("port")
1578
+ * }).pipe(Config.nested("database"))
1579
+ *
1580
+ * const provider = ConfigProvider.fromUnknown({
1581
+ * database: { host: "localhost", port: "5432" }
1582
+ * })
1583
+ * // Effect.runSync(dbConfig.parse(provider))
1584
+ * // { host: "localhost", port: 5432 }
1585
+ * ```
1586
+ *
1587
+ * **Example** (Env vars with nested prefix)
1588
+ *
1589
+ * ```ts
1590
+ * import { Config, ConfigProvider, Effect } from "effect"
1591
+ *
1592
+ * const host = Config.string("host").pipe(Config.nested("database"))
1593
+ *
1594
+ * const provider = ConfigProvider.fromEnv({
1595
+ * env: { database_host: "localhost" }
1596
+ * })
1597
+ * // Effect.runSync(host.parse(provider)) // "localhost"
1598
+ * ```
1599
+ *
1600
+ * @see {@link all} – combine multiple configs into a struct
1601
+ * @see {@link schema} – read structured config from a schema
1602
+ *
1603
+ * @category Combinators
1604
+ * @since 4.0.0
1605
+ */
1606
+ <A>(self: Config<A>, name: string): Config<A>
1607
+ } = dual(
1608
+ 2,
1609
+ <A>(self: Config<A>, name: string): Config<A> => make((provider) => self.parse(ConfigProvider.nested(provider, name)))
1610
+ )
package/src/Effect.ts CHANGED
@@ -84,7 +84,7 @@ import * as internalRequest from "./internal/request.ts"
84
84
  import * as internalSchedule from "./internal/schedule.ts"
85
85
  import type * as Layer from "./Layer.ts"
86
86
  import type { Logger } from "./Logger.ts"
87
- import type { LogLevel } from "./LogLevel.ts"
87
+ import type { Severity } from "./LogLevel.ts"
88
88
  import * as Metric from "./Metric.ts"
89
89
  import type { Option } from "./Option.ts"
90
90
  import type { Pipeable } from "./Pipeable.ts"
@@ -853,6 +853,214 @@ export const partition: {
853
853
  ): Effect<[excluded: Array<E>, satisfying: Array<B>], never, R>
854
854
  } = internal.partition
855
855
 
856
+ /**
857
+ * Applies an effectful function to each element and accumulates all failures.
858
+ *
859
+ * This function always evaluates every element. If at least one effect fails,
860
+ * all failures are returned as a non-empty array and successes are discarded.
861
+ * If all effects succeed, it returns all collected successes.
862
+ *
863
+ * Use `discard: true` to ignore successful values while still validating all
864
+ * elements.
865
+ *
866
+ * @example
867
+ * ```ts
868
+ * import { Effect } from "effect"
869
+ *
870
+ * const program = Effect.validate([0, 1, 2, 3], (n) =>
871
+ * n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
872
+ * )
873
+ *
874
+ * Effect.runPromiseExit(program).then(console.log)
875
+ * // {
876
+ * // _id: 'Exit',
877
+ * // _tag: 'Failure',
878
+ * // cause: {
879
+ * // _id: 'Cause',
880
+ * // reasons: [
881
+ * // { _id: 'Reason', _tag: 'Fail', error: '0 is even' },
882
+ * // { _id: 'Reason', _tag: 'Fail', error: '2 is even' }
883
+ * // ]
884
+ * // }
885
+ * // }
886
+ * ```
887
+ *
888
+ * @since 4.0.0
889
+ * @category Error Accumulation
890
+ */
891
+ export const validate: {
892
+ /**
893
+ * Applies an effectful function to each element and accumulates all failures.
894
+ *
895
+ * This function always evaluates every element. If at least one effect fails,
896
+ * all failures are returned as a non-empty array and successes are discarded.
897
+ * If all effects succeed, it returns all collected successes.
898
+ *
899
+ * Use `discard: true` to ignore successful values while still validating all
900
+ * elements.
901
+ *
902
+ * @example
903
+ * ```ts
904
+ * import { Effect } from "effect"
905
+ *
906
+ * const program = Effect.validate([0, 1, 2, 3], (n) =>
907
+ * n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
908
+ * )
909
+ *
910
+ * Effect.runPromiseExit(program).then(console.log)
911
+ * // {
912
+ * // _id: 'Exit',
913
+ * // _tag: 'Failure',
914
+ * // cause: {
915
+ * // _id: 'Cause',
916
+ * // reasons: [
917
+ * // { _id: 'Reason', _tag: 'Fail', error: '0 is even' },
918
+ * // { _id: 'Reason', _tag: 'Fail', error: '2 is even' }
919
+ * // ]
920
+ * // }
921
+ * // }
922
+ * ```
923
+ *
924
+ * @since 4.0.0
925
+ * @category Error Accumulation
926
+ */
927
+ <A, B, E, R>(
928
+ f: (a: A, i: number) => Effect<B, E, R>,
929
+ options?: {
930
+ readonly concurrency?: Concurrency | undefined
931
+ readonly discard?: false | undefined
932
+ } | undefined
933
+ ): (elements: Iterable<A>) => Effect<Array<B>, Arr.NonEmptyArray<E>, R>
934
+ /**
935
+ * Applies an effectful function to each element and accumulates all failures.
936
+ *
937
+ * This function always evaluates every element. If at least one effect fails,
938
+ * all failures are returned as a non-empty array and successes are discarded.
939
+ * If all effects succeed, it returns all collected successes.
940
+ *
941
+ * Use `discard: true` to ignore successful values while still validating all
942
+ * elements.
943
+ *
944
+ * @example
945
+ * ```ts
946
+ * import { Effect } from "effect"
947
+ *
948
+ * const program = Effect.validate([0, 1, 2, 3], (n) =>
949
+ * n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
950
+ * )
951
+ *
952
+ * Effect.runPromiseExit(program).then(console.log)
953
+ * // {
954
+ * // _id: 'Exit',
955
+ * // _tag: 'Failure',
956
+ * // cause: {
957
+ * // _id: 'Cause',
958
+ * // reasons: [
959
+ * // { _id: 'Reason', _tag: 'Fail', error: '0 is even' },
960
+ * // { _id: 'Reason', _tag: 'Fail', error: '2 is even' }
961
+ * // ]
962
+ * // }
963
+ * // }
964
+ * ```
965
+ *
966
+ * @since 4.0.0
967
+ * @category Error Accumulation
968
+ */
969
+ <A, B, E, R>(
970
+ f: (a: A, i: number) => Effect<B, E, R>,
971
+ options: {
972
+ readonly concurrency?: Concurrency | undefined
973
+ readonly discard: true
974
+ }
975
+ ): (elements: Iterable<A>) => Effect<void, Arr.NonEmptyArray<E>, R>
976
+ /**
977
+ * Applies an effectful function to each element and accumulates all failures.
978
+ *
979
+ * This function always evaluates every element. If at least one effect fails,
980
+ * all failures are returned as a non-empty array and successes are discarded.
981
+ * If all effects succeed, it returns all collected successes.
982
+ *
983
+ * Use `discard: true` to ignore successful values while still validating all
984
+ * elements.
985
+ *
986
+ * @example
987
+ * ```ts
988
+ * import { Effect } from "effect"
989
+ *
990
+ * const program = Effect.validate([0, 1, 2, 3], (n) =>
991
+ * n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
992
+ * )
993
+ *
994
+ * Effect.runPromiseExit(program).then(console.log)
995
+ * // {
996
+ * // _id: 'Exit',
997
+ * // _tag: 'Failure',
998
+ * // cause: {
999
+ * // _id: 'Cause',
1000
+ * // reasons: [
1001
+ * // { _id: 'Reason', _tag: 'Fail', error: '0 is even' },
1002
+ * // { _id: 'Reason', _tag: 'Fail', error: '2 is even' }
1003
+ * // ]
1004
+ * // }
1005
+ * // }
1006
+ * ```
1007
+ *
1008
+ * @since 4.0.0
1009
+ * @category Error Accumulation
1010
+ */
1011
+ <A, B, E, R>(
1012
+ elements: Iterable<A>,
1013
+ f: (a: A, i: number) => Effect<B, E, R>,
1014
+ options?: {
1015
+ readonly concurrency?: Concurrency | undefined
1016
+ readonly discard?: false | undefined
1017
+ } | undefined
1018
+ ): Effect<Array<B>, Arr.NonEmptyArray<E>, R>
1019
+ /**
1020
+ * Applies an effectful function to each element and accumulates all failures.
1021
+ *
1022
+ * This function always evaluates every element. If at least one effect fails,
1023
+ * all failures are returned as a non-empty array and successes are discarded.
1024
+ * If all effects succeed, it returns all collected successes.
1025
+ *
1026
+ * Use `discard: true` to ignore successful values while still validating all
1027
+ * elements.
1028
+ *
1029
+ * @example
1030
+ * ```ts
1031
+ * import { Effect } from "effect"
1032
+ *
1033
+ * const program = Effect.validate([0, 1, 2, 3], (n) =>
1034
+ * n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
1035
+ * )
1036
+ *
1037
+ * Effect.runPromiseExit(program).then(console.log)
1038
+ * // {
1039
+ * // _id: 'Exit',
1040
+ * // _tag: 'Failure',
1041
+ * // cause: {
1042
+ * // _id: 'Cause',
1043
+ * // reasons: [
1044
+ * // { _id: 'Reason', _tag: 'Fail', error: '0 is even' },
1045
+ * // { _id: 'Reason', _tag: 'Fail', error: '2 is even' }
1046
+ * // ]
1047
+ * // }
1048
+ * // }
1049
+ * ```
1050
+ *
1051
+ * @since 4.0.0
1052
+ * @category Error Accumulation
1053
+ */
1054
+ <A, B, E, R>(
1055
+ elements: Iterable<A>,
1056
+ f: (a: A, i: number) => Effect<B, E, R>,
1057
+ options: {
1058
+ readonly concurrency?: Concurrency | undefined
1059
+ readonly discard: true
1060
+ }
1061
+ ): Effect<void, Arr.NonEmptyArray<E>, R>
1062
+ } = internal.validate
1063
+
856
1064
  /**
857
1065
  * Executes an effectful operation for each element in an `Iterable`.
858
1066
  *
@@ -6935,14 +7143,14 @@ export const sandbox: <A, E, R>(
6935
7143
  */
6936
7144
  export const ignore: <
6937
7145
  Arg extends Effect<any, any, any> | {
6938
- readonly log?: boolean | LogLevel | undefined
7146
+ readonly log?: boolean | Severity | undefined
6939
7147
  } | undefined = {
6940
- readonly log?: boolean | LogLevel | undefined
7148
+ readonly log?: boolean | Severity | undefined
6941
7149
  }
6942
7150
  >(
6943
7151
  effectOrOptions?: Arg,
6944
7152
  options?: {
6945
- readonly log?: boolean | LogLevel | undefined
7153
+ readonly log?: boolean | Severity | undefined
6946
7154
  } | undefined
6947
7155
  ) => [Arg] extends [Effect<infer _A, infer _E, infer _R>] ? Effect<void, never, _R>
6948
7156
  : <A, E, R>(self: Effect<A, E, R>) => Effect<void, never, R> = internal.ignore
@@ -6967,14 +7175,14 @@ export const ignore: <
6967
7175
  */
6968
7176
  export const ignoreCause: <
6969
7177
  Arg extends Effect<any, any, any> | {
6970
- readonly log?: boolean | LogLevel | undefined
7178
+ readonly log?: boolean | Severity | undefined
6971
7179
  } | undefined = {
6972
- readonly log?: boolean | LogLevel | undefined
7180
+ readonly log?: boolean | Severity | undefined
6973
7181
  }
6974
7182
  >(
6975
7183
  effectOrOptions?: Arg,
6976
7184
  options?: {
6977
- readonly log?: boolean | LogLevel | undefined
7185
+ readonly log?: boolean | Severity | undefined
6978
7186
  } | undefined
6979
7187
  ) => [Arg] extends [Effect<infer _A, infer _E, infer _R>] ? Effect<void, never, _R>
6980
7188
  : <A, E, R>(self: Effect<A, E, R>) => Effect<void, never, R> = internal.ignoreCause
@@ -7081,6 +7289,25 @@ export const withExecutionPlan: {
7081
7289
  ): Effect<A, E | PlanE, Exclude<R, Provides> | PlanR>
7082
7290
  } = internalExecutionPlan.withExecutionPlan
7083
7291
 
7292
+ /**
7293
+ * Runs an effect and reports any errors to the configured `ErrorReporter`s.
7294
+ *
7295
+ * If the `defectsOnly` option is set to `true`, only defects (unrecoverable
7296
+ * errors) will be reported, while regular failures will be ignored.
7297
+ *
7298
+ * @since 4.0.0
7299
+ * @category Error Handling
7300
+ */
7301
+ export const withErrorReporting: <
7302
+ Arg extends Effect<any, any, any> | { readonly defectsOnly?: boolean | undefined } | undefined = {
7303
+ readonly defectsOnly?: boolean | undefined
7304
+ }
7305
+ >(
7306
+ effectOrOptions: Arg,
7307
+ options?: { readonly defectsOnly?: boolean | undefined } | undefined
7308
+ ) => [Arg] extends [Effect<infer _A, infer _E, infer _R>] ? Arg : <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R> =
7309
+ internal.withErrorReporting
7310
+
7084
7311
  // -----------------------------------------------------------------------------
7085
7312
  // Fallback
7086
7313
  // -----------------------------------------------------------------------------
@@ -20191,7 +20418,7 @@ export const clockWith: <A, E, R>(
20191
20418
  * @since 2.0.0
20192
20419
  * @category Logging
20193
20420
  */
20194
- export const logWithLevel: (level?: LogLevel) => (...message: ReadonlyArray<any>) => Effect<void> =
20421
+ export const logWithLevel: (level?: Severity) => (...message: ReadonlyArray<any>) => Effect<void> =
20195
20422
  internal.logWithLevel
20196
20423
 
20197
20424
  /**
@@ -20619,6 +20846,86 @@ export const annotateLogs = dual<
20619
20846
  })
20620
20847
  )
20621
20848
 
20849
+ /**
20850
+ * Adds log annotations to the current scope.
20851
+ *
20852
+ * This differs from `annotateLogs`, which only annotates a specific effect.
20853
+ * `annotateLogsScoped` updates annotations for the entire current `Scope` and
20854
+ * restores the previous annotations when the scope closes.
20855
+ *
20856
+ * @example
20857
+ * ```ts
20858
+ * import { Effect } from "effect"
20859
+ *
20860
+ * const program = Effect.scoped(
20861
+ * Effect.gen(function*() {
20862
+ * yield* Effect.log("before")
20863
+ * yield* Effect.annotateLogsScoped({ requestId: "req-123" })
20864
+ * yield* Effect.log("inside scope")
20865
+ * })
20866
+ * )
20867
+ *
20868
+ * Effect.runPromise(program)
20869
+ * ```
20870
+ *
20871
+ * @since 4.0.0
20872
+ * @category Logging
20873
+ */
20874
+ export const annotateLogsScoped: {
20875
+ /**
20876
+ * Adds log annotations to the current scope.
20877
+ *
20878
+ * This differs from `annotateLogs`, which only annotates a specific effect.
20879
+ * `annotateLogsScoped` updates annotations for the entire current `Scope` and
20880
+ * restores the previous annotations when the scope closes.
20881
+ *
20882
+ * @example
20883
+ * ```ts
20884
+ * import { Effect } from "effect"
20885
+ *
20886
+ * const program = Effect.scoped(
20887
+ * Effect.gen(function*() {
20888
+ * yield* Effect.log("before")
20889
+ * yield* Effect.annotateLogsScoped({ requestId: "req-123" })
20890
+ * yield* Effect.log("inside scope")
20891
+ * })
20892
+ * )
20893
+ *
20894
+ * Effect.runPromise(program)
20895
+ * ```
20896
+ *
20897
+ * @since 4.0.0
20898
+ * @category Logging
20899
+ */
20900
+ (key: string, value: unknown): Effect<void, never, Scope>
20901
+ /**
20902
+ * Adds log annotations to the current scope.
20903
+ *
20904
+ * This differs from `annotateLogs`, which only annotates a specific effect.
20905
+ * `annotateLogsScoped` updates annotations for the entire current `Scope` and
20906
+ * restores the previous annotations when the scope closes.
20907
+ *
20908
+ * @example
20909
+ * ```ts
20910
+ * import { Effect } from "effect"
20911
+ *
20912
+ * const program = Effect.scoped(
20913
+ * Effect.gen(function*() {
20914
+ * yield* Effect.log("before")
20915
+ * yield* Effect.annotateLogsScoped({ requestId: "req-123" })
20916
+ * yield* Effect.log("inside scope")
20917
+ * })
20918
+ * )
20919
+ *
20920
+ * Effect.runPromise(program)
20921
+ * ```
20922
+ *
20923
+ * @since 4.0.0
20924
+ * @category Logging
20925
+ */
20926
+ (values: Record<string, unknown>): Effect<void, never, Scope>
20927
+ } = internal.annotateLogsScoped
20928
+
20622
20929
  /**
20623
20930
  * Adds a span to each log line in this effect.
20624
20931
  *