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.
- package/dist/Channel.d.ts +7 -7
- package/dist/Config.d.ts +157 -0
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +56 -1
- package/dist/Config.js.map +1 -1
- package/dist/Effect.d.ts +296 -8
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +72 -0
- package/dist/Effect.js.map +1 -1
- package/dist/ErrorReporter.d.ts +376 -0
- package/dist/ErrorReporter.d.ts.map +1 -0
- package/dist/ErrorReporter.js +246 -0
- package/dist/ErrorReporter.js.map +1 -0
- package/dist/Fiber.d.ts +2 -2
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Fiber.js.map +1 -1
- package/dist/Graph.d.ts.map +1 -1
- package/dist/Graph.js +3 -6
- package/dist/Graph.js.map +1 -1
- package/dist/LogLevel.d.ts +5 -0
- package/dist/LogLevel.d.ts.map +1 -1
- package/dist/LogLevel.js.map +1 -1
- package/dist/Logger.d.ts +25 -91
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +2 -3
- package/dist/Logger.js.map +1 -1
- package/dist/Queue.d.ts.map +1 -1
- package/dist/Queue.js +0 -1
- package/dist/Queue.js.map +1 -1
- package/dist/Random.d.ts +17 -0
- package/dist/Random.d.ts.map +1 -1
- package/dist/Random.js +17 -0
- package/dist/Random.js.map +1 -1
- package/dist/References.d.ts +3 -3
- package/dist/References.d.ts.map +1 -1
- package/dist/Schema.d.ts +3 -1
- package/dist/Schema.d.ts.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +2 -1
- package/dist/SchemaAST.js.map +1 -1
- package/dist/Stream.d.ts +5 -5
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +98 -33
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/hashMap.js +2 -2
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +86 -14
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +112 -36
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +47 -10
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +33 -6
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +16 -0
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +14 -0
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/CliOutput.js +37 -6
- package/dist/unstable/cli/CliOutput.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +199 -7
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +116 -6
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/HelpDoc.d.ts +60 -2
- package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts +11 -1
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +33 -8
- package/dist/unstable/cli/internal/command.js.map +1 -1
- package/dist/unstable/cli/internal/completions/CommandDescriptor.js +7 -2
- package/dist/unstable/cli/internal/completions/CommandDescriptor.js.map +1 -1
- package/dist/unstable/cli/internal/parser.js +10 -2
- package/dist/unstable/cli/internal/parser.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +2 -2
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/http/Headers.d.ts.map +1 -1
- package/dist/unstable/http/Headers.js +27 -10
- package/dist/unstable/http/Headers.js.map +1 -1
- package/dist/unstable/http/HttpClient.d.ts +28 -4
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpEffect.d.ts +3 -8
- package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
- package/dist/unstable/http/HttpEffect.js +25 -31
- package/dist/unstable/http/HttpEffect.js.map +1 -1
- package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/unstable/http/HttpMiddleware.js +4 -8
- package/dist/unstable/http/HttpMiddleware.js.map +1 -1
- package/dist/unstable/http/HttpServerError.d.ts +14 -27
- package/dist/unstable/http/HttpServerError.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerError.js +37 -44
- package/dist/unstable/http/HttpServerError.js.map +1 -1
- package/dist/unstable/http/HttpServerRespondable.d.ts +2 -2
- package/dist/unstable/http/HttpServerRespondable.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRespondable.js +5 -5
- package/dist/unstable/http/HttpServerRespondable.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts +2 -1
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +2 -0
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/internal/preResponseHandler.d.ts +2 -0
- package/dist/unstable/http/internal/preResponseHandler.d.ts.map +1 -0
- package/dist/unstable/http/internal/preResponseHandler.js +10 -0
- package/dist/unstable/http/internal/preResponseHandler.js.map +1 -0
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +11 -0
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +29 -9
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpLogger.js +7 -4
- package/dist/unstable/observability/OtlpLogger.js.map +1 -1
- package/dist/unstable/reactivity/Atom.js +1 -1
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.d.ts +6 -0
- package/dist/unstable/reactivity/AtomRegistry.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js +22 -1
- package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
- package/dist/unstable/rpc/RpcSchema.d.ts +13 -0
- package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSchema.js +14 -0
- package/dist/unstable/rpc/RpcSchema.js.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.js +34 -9
- package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts +0 -7
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +9 -10
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +6 -0
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +131 -0
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +1 -1
- package/src/Channel.ts +9 -9
- package/src/Config.ts +171 -9
- package/src/Effect.ts +315 -8
- package/src/ErrorReporter.ts +459 -0
- package/src/Fiber.ts +9 -2
- package/src/Graph.ts +16 -6
- package/src/LogLevel.ts +6 -0
- package/src/Logger.ts +28 -95
- package/src/Queue.ts +0 -1
- package/src/Random.ts +18 -0
- package/src/References.ts +4 -4
- package/src/Schema.ts +1 -1
- package/src/SchemaAST.ts +2 -1
- package/src/Stream.ts +7 -7
- package/src/index.ts +5 -0
- package/src/internal/effect.ts +205 -49
- package/src/internal/hashMap.ts +2 -2
- package/src/unstable/ai/LanguageModel.ts +117 -16
- package/src/unstable/ai/McpSchema.ts +57 -11
- package/src/unstable/ai/McpServer.ts +44 -6
- package/src/unstable/ai/Tool.ts +15 -0
- package/src/unstable/cli/CliOutput.ts +45 -6
- package/src/unstable/cli/Command.ts +298 -11
- package/src/unstable/cli/HelpDoc.ts +68 -2
- package/src/unstable/cli/internal/command.ts +47 -11
- package/src/unstable/cli/internal/completions/CommandDescriptor.ts +7 -2
- package/src/unstable/cli/internal/parser.ts +11 -3
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +2 -2
- package/src/unstable/http/Headers.ts +28 -13
- package/src/unstable/http/HttpClient.ts +45 -10
- package/src/unstable/http/HttpEffect.ts +30 -44
- package/src/unstable/http/HttpMiddleware.ts +4 -14
- package/src/unstable/http/HttpServerError.ts +42 -45
- package/src/unstable/http/HttpServerRespondable.ts +6 -6
- package/src/unstable/http/HttpServerResponse.ts +3 -1
- package/src/unstable/http/internal/preResponseHandler.ts +15 -0
- package/src/unstable/httpapi/HttpApiBuilder.ts +2 -1
- package/src/unstable/httpapi/HttpApiError.ts +30 -9
- package/src/unstable/observability/OtlpLogger.ts +9 -5
- package/src/unstable/reactivity/Atom.ts +1 -1
- package/src/unstable/reactivity/AtomRegistry.ts +29 -1
- package/src/unstable/rpc/RpcSchema.ts +17 -0
- package/src/unstable/rpc/RpcSerialization.ts +44 -9
- package/src/unstable/rpc/RpcServer.ts +14 -19
- 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
|
-
|
|
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(
|
|
893
|
-
|
|
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 {
|
|
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 |
|
|
7146
|
+
readonly log?: boolean | Severity | undefined
|
|
6939
7147
|
} | undefined = {
|
|
6940
|
-
readonly log?: boolean |
|
|
7148
|
+
readonly log?: boolean | Severity | undefined
|
|
6941
7149
|
}
|
|
6942
7150
|
>(
|
|
6943
7151
|
effectOrOptions?: Arg,
|
|
6944
7152
|
options?: {
|
|
6945
|
-
readonly log?: boolean |
|
|
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 |
|
|
7178
|
+
readonly log?: boolean | Severity | undefined
|
|
6971
7179
|
} | undefined = {
|
|
6972
|
-
readonly log?: boolean |
|
|
7180
|
+
readonly log?: boolean | Severity | undefined
|
|
6973
7181
|
}
|
|
6974
7182
|
>(
|
|
6975
7183
|
effectOrOptions?: Arg,
|
|
6976
7184
|
options?: {
|
|
6977
|
-
readonly log?: boolean |
|
|
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?:
|
|
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
|
*
|