effect 4.1.5 → 4.1.6
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/ai-docs/package.json +2 -2
- package/dist/Channel.d.ts +104 -7
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +73 -4
- package/dist/Channel.js.map +1 -1
- package/dist/Codegen.d.ts +7 -2
- package/dist/Codegen.d.ts.map +1 -1
- package/dist/Codegen.js +7 -2
- package/dist/Codegen.js.map +1 -1
- package/dist/Effect.d.ts +139 -18
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +10 -2
- package/dist/Effect.js.map +1 -1
- package/dist/Equal.d.ts +4 -4
- package/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +78 -65
- package/dist/Equal.js.map +1 -1
- package/dist/Hash.d.ts.map +1 -1
- package/dist/Hash.js +24 -17
- package/dist/Hash.js.map +1 -1
- package/dist/LayerRef.d.ts +1 -1
- package/dist/LayerRef.d.ts.map +1 -1
- package/dist/LayerRef.js +3 -3
- package/dist/LayerRef.js.map +1 -1
- package/dist/Logger.d.ts +37 -13
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +39 -10
- package/dist/Logger.js.map +1 -1
- package/dist/Match.d.ts +23 -23
- package/dist/Match.d.ts.map +1 -1
- package/dist/Match.js.map +1 -1
- package/dist/Order.js +1 -1
- package/dist/Order.js.map +1 -1
- package/dist/Schema.d.ts +41 -0
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +51 -390
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +0 -3
- package/dist/SchemaAST.js.map +1 -1
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +6 -4
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Stream.d.ts +128 -5
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +124 -29
- package/dist/Stream.js.map +1 -1
- package/dist/String.js +1 -1
- package/dist/String.js.map +1 -1
- package/dist/Tracer.d.ts +10 -0
- package/dist/Tracer.d.ts.map +1 -1
- package/dist/Tracer.js +2 -0
- package/dist/Tracer.js.map +1 -1
- package/dist/ai/McpSchema.d.ts +88 -88
- package/dist/ai/McpSchema.d.ts.map +1 -1
- package/dist/ai/McpServer.d.ts +152 -2
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +8 -2
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/Prompt.d.ts +3 -1
- package/dist/ai/Prompt.d.ts.map +1 -1
- package/dist/ai/Prompt.js +17 -3
- package/dist/ai/Prompt.js.map +1 -1
- package/dist/ai/Skill.d.ts +172 -0
- package/dist/ai/Skill.d.ts.map +1 -0
- package/dist/ai/Skill.js +209 -0
- package/dist/ai/Skill.js.map +1 -0
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.js +155 -83
- package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/cluster/MessageStorage.d.ts +56 -0
- package/dist/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/cluster/MessageStorage.js +18 -2
- package/dist/cluster/MessageStorage.js.map +1 -1
- package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/cluster/SqlMessageStorage.js +45 -22
- package/dist/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/cluster/internal/entityActivation.js +2 -0
- package/dist/cluster/internal/entityActivation.js.map +1 -1
- package/dist/cluster/internal/entityManager.js +8 -5
- package/dist/cluster/internal/entityManager.js.map +1 -1
- package/dist/encoding/Base64.js +5 -1
- package/dist/encoding/Base64.js.map +1 -1
- package/dist/encoding/Base64Url.d.ts.map +1 -1
- package/dist/encoding/Base64Url.js +6 -1
- package/dist/encoding/Base64Url.js.map +1 -1
- package/dist/encoding/Xml.d.ts +38 -9
- package/dist/encoding/Xml.d.ts.map +1 -1
- package/dist/encoding/Xml.js +63 -31
- package/dist/encoding/Xml.js.map +1 -1
- package/dist/http/FetchHttpClient.d.ts +2 -1
- package/dist/http/FetchHttpClient.d.ts.map +1 -1
- package/dist/http/FetchHttpClient.js +14 -10
- package/dist/http/FetchHttpClient.js.map +1 -1
- package/dist/http/Headers.d.ts +201 -3
- package/dist/http/Headers.d.ts.map +1 -1
- package/dist/http/Headers.js +205 -3
- package/dist/http/Headers.js.map +1 -1
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpClient.js +11 -7
- package/dist/http/HttpClient.js.map +1 -1
- package/dist/http/HttpClientError.d.ts +1 -0
- package/dist/http/HttpClientError.d.ts.map +1 -1
- package/dist/http/HttpClientError.js +32 -9
- package/dist/http/HttpClientError.js.map +1 -1
- package/dist/http/HttpClientRequest.d.ts +46 -0
- package/dist/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/http/HttpClientRequest.js +15 -0
- package/dist/http/HttpClientRequest.js.map +1 -1
- package/dist/http/HttpClientResponse.d.ts +132 -0
- package/dist/http/HttpClientResponse.d.ts.map +1 -1
- package/dist/http/HttpClientResponse.js +83 -0
- package/dist/http/HttpClientResponse.js.map +1 -1
- package/dist/http/HttpMiddleware.js +1 -1
- package/dist/http/HttpMiddleware.js.map +1 -1
- package/dist/http/HttpServerResponse.d.ts +118 -0
- package/dist/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/http/HttpServerResponse.js +43 -0
- package/dist/http/HttpServerResponse.js.map +1 -1
- package/dist/http/Multipart.d.ts.map +1 -1
- package/dist/http/Multipart.js +0 -5
- package/dist/http/Multipart.js.map +1 -1
- package/dist/http/MultipartParser/internal/contentType.d.ts +6 -0
- package/dist/http/MultipartParser/internal/contentType.d.ts.map +1 -1
- package/dist/http/MultipartParser/internal/contentType.js +1 -1
- package/dist/http/MultipartParser/internal/contentType.js.map +1 -1
- package/dist/http/internal/clientPath.d.ts +2 -0
- package/dist/http/internal/clientPath.d.ts.map +1 -0
- package/dist/http/internal/clientPath.js +24 -0
- package/dist/http/internal/clientPath.js.map +1 -0
- package/dist/http/internal/redactedPath.js +2 -0
- package/dist/http/internal/redactedPath.js.map +1 -1
- package/dist/http/internal/tracing.js +5 -3
- package/dist/http/internal/tracing.js.map +1 -1
- package/dist/http-api/HttpApi.d.ts +2 -2
- package/dist/http-api/HttpApi.d.ts.map +1 -1
- package/dist/http-api/HttpApi.js +30 -7
- package/dist/http-api/HttpApi.js.map +1 -1
- package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
- package/dist/http-api/HttpApiBuilder.js +5 -2
- package/dist/http-api/HttpApiBuilder.js.map +1 -1
- package/dist/http-api/HttpApiClient.d.ts.map +1 -1
- package/dist/http-api/HttpApiClient.js +23 -6
- package/dist/http-api/HttpApiClient.js.map +1 -1
- package/dist/http-api/internal/redactedKeys.d.ts +2 -0
- package/dist/http-api/internal/redactedKeys.d.ts.map +1 -0
- package/dist/http-api/internal/redactedKeys.js +37 -0
- package/dist/http-api/internal/redactedKeys.js.map +1 -0
- package/dist/internal/base64.js +34 -2
- package/dist/internal/base64.js.map +1 -1
- package/dist/internal/dateTime.js +35 -17
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +9 -1
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/equal.js +14 -13
- package/dist/internal/equal.js.map +1 -1
- package/dist/internal/hash.js +4 -1
- package/dist/internal/hash.js.map +1 -1
- package/dist/internal/matcher.js +17 -17
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/schema/schemaCodegen.js +3 -2
- package/dist/internal/schema/schemaCodegen.js.map +1 -1
- package/dist/internal/schema/schemaCodegenBuiltIns.d.ts +2 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.d.ts.map +1 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.js +425 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.js.map +1 -0
- package/dist/internal/schema/toEquivalence.js +3 -4
- package/dist/internal/schema/toEquivalence.js.map +1 -1
- package/dist/internal/version.js +1 -1
- package/dist/jose/JoseError.d.ts +51 -1
- package/dist/jose/JoseError.d.ts.map +1 -1
- package/dist/jose/JoseError.js +25 -18
- package/dist/jose/JoseError.js.map +1 -1
- package/dist/jose/internal/compact.js +10 -5
- package/dist/jose/internal/compact.js.map +1 -1
- package/dist/observability/Otlp.d.ts +19 -0
- package/dist/observability/Otlp.d.ts.map +1 -1
- package/dist/observability/Otlp.js +10 -0
- package/dist/observability/Otlp.js.map +1 -1
- package/dist/observability/OtlpExporter.d.ts +49 -13
- package/dist/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/observability/OtlpExporter.js +135 -54
- package/dist/observability/OtlpExporter.js.map +1 -1
- package/dist/observability/OtlpLogger.d.ts +14 -0
- package/dist/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/observability/OtlpLogger.js +10 -2
- package/dist/observability/OtlpLogger.js.map +1 -1
- package/dist/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/observability/OtlpMetrics.js +2 -0
- package/dist/observability/OtlpMetrics.js.map +1 -1
- package/dist/observability/OtlpTracer.d.ts +14 -0
- package/dist/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/observability/OtlpTracer.js +10 -2
- package/dist/observability/OtlpTracer.js.map +1 -1
- package/dist/persistence/KeyValueStore.d.ts.map +1 -1
- package/dist/persistence/KeyValueStore.js +6 -4
- package/dist/persistence/KeyValueStore.js.map +1 -1
- package/dist/reactivity/Atom.d.ts.map +1 -1
- package/dist/reactivity/Atom.js +10 -9
- package/dist/reactivity/Atom.js.map +1 -1
- package/dist/rpc/RpcClient.d.ts.map +1 -1
- package/dist/rpc/RpcClient.js +32 -1
- package/dist/rpc/RpcClient.js.map +1 -1
- package/dist/rpc/RpcGroup.d.ts +1 -1
- package/dist/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/rpc/RpcGroup.js +4 -0
- package/dist/rpc/RpcGroup.js.map +1 -1
- package/dist/sql/Migrator.d.ts.map +1 -1
- package/dist/sql/Migrator.js +2 -5
- package/dist/sql/Migrator.js.map +1 -1
- package/dist/sql/SqlClient.d.ts.map +1 -1
- package/dist/sql/SqlClient.js +5 -1
- package/dist/sql/SqlClient.js.map +1 -1
- package/dist/workflow/Activity.d.ts +18 -0
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow/Activity.js +13 -4
- package/dist/workflow/Activity.js.map +1 -1
- package/dist/workflow/Workflow.d.ts +10 -9
- package/dist/workflow/Workflow.d.ts.map +1 -1
- package/dist/workflow/Workflow.js +33 -22
- package/dist/workflow/Workflow.js.map +1 -1
- package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/workflow/WorkflowEngine.js +26 -12
- package/dist/workflow/WorkflowEngine.js.map +1 -1
- package/dist/workflow/internal/retry.d.ts +2 -0
- package/dist/workflow/internal/retry.d.ts.map +1 -0
- package/dist/workflow/internal/retry.js +11 -0
- package/dist/workflow/internal/retry.js.map +1 -0
- package/dist/workflow/internal/scope.d.ts +2 -0
- package/dist/workflow/internal/scope.d.ts.map +1 -0
- package/dist/workflow/internal/scope.js +26 -0
- package/dist/workflow/internal/scope.js.map +1 -0
- package/package.json +3 -3
- package/src/Channel.ts +105 -8
- package/src/Codegen.ts +7 -2
- package/src/Effect.ts +224 -48
- package/src/Equal.ts +85 -79
- package/src/Hash.ts +30 -22
- package/src/LayerRef.ts +6 -4
- package/src/Logger.ts +68 -25
- package/src/Match.ts +78 -50
- package/src/Order.ts +1 -1
- package/src/Schema.ts +79 -296
- package/src/SchemaAST.ts +0 -1
- package/src/ScopedCache.ts +6 -4
- package/src/Stream.ts +167 -33
- package/src/String.ts +1 -1
- package/src/Tracer.ts +10 -0
- package/src/ai/McpServer.ts +161 -4
- package/src/ai/Prompt.ts +20 -3
- package/src/ai/Skill.ts +236 -0
- package/src/ai/index.ts +6 -0
- package/src/cluster/ClusterWorkflowEngine.ts +172 -96
- package/src/cluster/MessageStorage.ts +51 -2
- package/src/cluster/SqlMessageStorage.ts +81 -34
- package/src/cluster/internal/entityActivation.ts +6 -0
- package/src/cluster/internal/entityManager.ts +8 -4
- package/src/encoding/Base64.ts +5 -1
- package/src/encoding/Base64Url.ts +6 -1
- package/src/encoding/Xml.ts +96 -26
- package/src/http/FetchHttpClient.ts +8 -5
- package/src/http/Headers.ts +309 -3
- package/src/http/HttpClient.ts +19 -7
- package/src/http/HttpClientError.ts +42 -9
- package/src/http/HttpClientRequest.ts +51 -0
- package/src/http/HttpClientResponse.ts +156 -0
- package/src/http/HttpMiddleware.ts +1 -1
- package/src/http/HttpServerResponse.ts +126 -0
- package/src/http/Multipart.ts +0 -5
- package/src/http/MultipartParser/internal/contentType.ts +1 -1
- package/src/http/internal/clientPath.ts +39 -0
- package/src/http/internal/redactedPath.ts +4 -0
- package/src/http/internal/tracing.ts +6 -3
- package/src/http-api/HttpApi.ts +29 -8
- package/src/http-api/HttpApiBuilder.ts +7 -2
- package/src/http-api/HttpApiClient.ts +30 -7
- package/src/http-api/internal/redactedKeys.ts +40 -0
- package/src/internal/base64.ts +57 -2
- package/src/internal/dateTime.ts +43 -24
- package/src/internal/effect.ts +31 -102
- package/src/internal/equal.ts +37 -17
- package/src/internal/hash.ts +5 -1
- package/src/internal/matcher.ts +34 -113
- package/src/internal/schema/schemaCodegen.ts +5 -4
- package/src/internal/schema/schemaCodegenBuiltIns.ts +343 -0
- package/src/internal/schema/toEquivalence.ts +3 -5
- package/src/internal/version.ts +1 -1
- package/src/jose/JoseError.ts +34 -0
- package/src/jose/internal/compact.ts +14 -5
- package/src/observability/Otlp.ts +29 -0
- package/src/observability/OtlpExporter.ts +206 -75
- package/src/observability/OtlpLogger.ts +24 -2
- package/src/observability/OtlpMetrics.ts +2 -0
- package/src/observability/OtlpTracer.ts +24 -3
- package/src/persistence/KeyValueStore.ts +17 -14
- package/src/reactivity/Atom.ts +12 -18
- package/src/rpc/RpcClient.ts +26 -1
- package/src/rpc/RpcGroup.ts +4 -1
- package/src/sql/Migrator.ts +2 -11
- package/src/sql/SqlClient.ts +14 -8
- package/src/workflow/Activity.ts +28 -4
- package/src/workflow/Workflow.ts +68 -44
- package/src/workflow/WorkflowEngine.ts +38 -15
- package/src/workflow/internal/retry.ts +12 -0
- package/src/workflow/internal/scope.ts +36 -0
package/src/Channel.ts
CHANGED
|
@@ -7,6 +7,23 @@
|
|
|
7
7
|
* higher-level modules instead. This module is useful when implementing stream
|
|
8
8
|
* operators or specialized streaming workflows.
|
|
9
9
|
*
|
|
10
|
+
* Every channel runs in a scope supplied by its consumer, called the channel
|
|
11
|
+
* scope. The run functions create that scope and close it before they return,
|
|
12
|
+
* however the channel ends: completion, failure, defect, an early stop by a
|
|
13
|
+
* downstream operator, or interruption. `toPull` and `toPullScoped` use the
|
|
14
|
+
* scope they are given and leave closing it to its owner. Operators that run
|
|
15
|
+
* inner channels, such as `flatMap` and `concat`, may give each inner channel
|
|
16
|
+
* a child scope that closes sooner.
|
|
17
|
+
*
|
|
18
|
+
* `acquireUseRelease`, `ensuring`, `onExit`, and `scoped` finalize when their
|
|
19
|
+
* channel ends on its own (completion, failure, or defect), before downstream
|
|
20
|
+
* observes that end. `callback`, `callbackArray`, `unwrap`, and
|
|
21
|
+
* `acquireRelease` register finalizers in the channel scope, so they run when
|
|
22
|
+
* that scope closes. A channel that is abandoned because a downstream operator
|
|
23
|
+
* stopped pulling from it is finalized no later than when its channel scope
|
|
24
|
+
* closes. Under `toPull`, that can be after the pull has returned its final
|
|
25
|
+
* result, so close the scope to release what the channel still holds.
|
|
26
|
+
*
|
|
10
27
|
* @stability stable
|
|
11
28
|
* @since 2.0.0
|
|
12
29
|
*/
|
|
@@ -496,6 +513,12 @@ const asyncQueue = <A, E = never, R = never>(
|
|
|
496
513
|
/**
|
|
497
514
|
* Creates a `Channel` that interacts with a callback function using a queue.
|
|
498
515
|
*
|
|
516
|
+
* **Details**
|
|
517
|
+
*
|
|
518
|
+
* The callback effect runs in the channel scope. Finalizers it registers, for
|
|
519
|
+
* example with `Effect.acquireRelease`, run when that scope closes, not when
|
|
520
|
+
* the queue ends.
|
|
521
|
+
*
|
|
499
522
|
* **Example** (Creating channels from callbacks)
|
|
500
523
|
*
|
|
501
524
|
* ```ts import.meta.vitest
|
|
@@ -528,6 +551,12 @@ export const callback = <A, E = never, R = never>(
|
|
|
528
551
|
/**
|
|
529
552
|
* Creates a `Channel` that interacts with a callback function using a queue, emitting arrays.
|
|
530
553
|
*
|
|
554
|
+
* **Details**
|
|
555
|
+
*
|
|
556
|
+
* The callback effect runs in the channel scope. Finalizers it registers, for
|
|
557
|
+
* example with `Effect.acquireRelease`, run when that scope closes, not when
|
|
558
|
+
* the queue ends.
|
|
559
|
+
*
|
|
531
560
|
* **Example** (Creating array channels from callbacks)
|
|
532
561
|
*
|
|
533
562
|
* ```ts import.meta.vitest
|
|
@@ -585,6 +614,10 @@ export const suspend = <OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>(
|
|
|
585
614
|
* Acquisition is uninterruptible. If acquisition fails, `use` is not run and
|
|
586
615
|
* `release` is not registered.
|
|
587
616
|
*
|
|
617
|
+
* The finalizer runs when the channel ends on its own (completion, failure, or
|
|
618
|
+
* defect), before downstream observes that end. If a downstream operator stops
|
|
619
|
+
* pulling first, it runs no later than when the channel scope closes.
|
|
620
|
+
*
|
|
588
621
|
* **Example** (Managing resources with acquire-use-release)
|
|
589
622
|
*
|
|
590
623
|
* ```ts import.meta.vitest
|
|
@@ -630,8 +663,9 @@ export const acquireUseRelease = <A, E, R, OutElem, OutErr, OutDone, InElem, InE
|
|
|
630
663
|
* **Details**
|
|
631
664
|
*
|
|
632
665
|
* The release action runs when the channel scope closes and receives the scope
|
|
633
|
-
* exit.
|
|
634
|
-
*
|
|
666
|
+
* exit. The channel scope is the scope supplied by whatever consumes this
|
|
667
|
+
* channel: a run function, `toPull`, or an enclosing operator. If acquisition
|
|
668
|
+
* fails, no element is emitted and `release` is not registered.
|
|
635
669
|
*
|
|
636
670
|
* **Example** (Managing resources with acquire-release)
|
|
637
671
|
*
|
|
@@ -646,6 +680,8 @@ export const acquireUseRelease = <A, E, R, OutElem, OutErr, OutDone, InElem, InE
|
|
|
646
680
|
* const observed = [await Effect.runPromise(Channel.runCollect(channel)), released] // => [["resource"], ["resource"]]
|
|
647
681
|
* ```
|
|
648
682
|
*
|
|
683
|
+
* @see {@link acquireUseRelease} for releasing when the channel itself ends
|
|
684
|
+
*
|
|
649
685
|
* @stability stable
|
|
650
686
|
* @category constructors
|
|
651
687
|
* @since 4.0.0
|
|
@@ -658,8 +694,9 @@ export const acquireRelease: {
|
|
|
658
694
|
* **Details**
|
|
659
695
|
*
|
|
660
696
|
* The release action runs when the channel scope closes and receives the scope
|
|
661
|
-
* exit.
|
|
662
|
-
*
|
|
697
|
+
* exit. The channel scope is the scope supplied by whatever consumes this
|
|
698
|
+
* channel: a run function, `toPull`, or an enclosing operator. If acquisition
|
|
699
|
+
* fails, no element is emitted and `release` is not registered.
|
|
663
700
|
*
|
|
664
701
|
* **Example** (Managing resources with acquire-release)
|
|
665
702
|
*
|
|
@@ -674,6 +711,8 @@ export const acquireRelease: {
|
|
|
674
711
|
* const observed = [await Effect.runPromise(Channel.runCollect(channel)), released] // => [["resource"], ["resource"]]
|
|
675
712
|
* ```
|
|
676
713
|
*
|
|
714
|
+
* @see {@link acquireUseRelease} for releasing when the channel itself ends
|
|
715
|
+
*
|
|
677
716
|
* @stability stable
|
|
678
717
|
* @category constructors
|
|
679
718
|
* @since 4.0.0
|
|
@@ -686,8 +725,9 @@ export const acquireRelease: {
|
|
|
686
725
|
* **Details**
|
|
687
726
|
*
|
|
688
727
|
* The release action runs when the channel scope closes and receives the scope
|
|
689
|
-
* exit.
|
|
690
|
-
*
|
|
728
|
+
* exit. The channel scope is the scope supplied by whatever consumes this
|
|
729
|
+
* channel: a run function, `toPull`, or an enclosing operator. If acquisition
|
|
730
|
+
* fails, no element is emitted and `release` is not registered.
|
|
691
731
|
*
|
|
692
732
|
* **Example** (Managing resources with acquire-release)
|
|
693
733
|
*
|
|
@@ -702,6 +742,8 @@ export const acquireRelease: {
|
|
|
702
742
|
* const observed = [await Effect.runPromise(Channel.runCollect(channel)), released] // => [["resource"], ["resource"]]
|
|
703
743
|
* ```
|
|
704
744
|
*
|
|
745
|
+
* @see {@link acquireUseRelease} for releasing when the channel itself ends
|
|
746
|
+
*
|
|
705
747
|
* @stability stable
|
|
706
748
|
* @category constructors
|
|
707
749
|
* @since 4.0.0
|
|
@@ -8992,7 +9034,7 @@ export const merge: {
|
|
|
8992
9034
|
})
|
|
8993
9035
|
)
|
|
8994
9036
|
),
|
|
8995
|
-
Effect.forkIn(forkedScope)
|
|
9037
|
+
Effect.forkIn(forkedScope, { startImmediately: true })
|
|
8996
9038
|
)
|
|
8997
9039
|
yield* runSide("left", left, Scope.forkUnsafe(forkedScope))
|
|
8998
9040
|
yield* runSide("right", right, Scope.forkUnsafe(forkedScope))
|
|
@@ -9523,6 +9565,11 @@ export const restoreUpstreamFailure = <A, E, R>(
|
|
|
9523
9565
|
* Constructs a `Channel` from a scoped effect that will result in a
|
|
9524
9566
|
* `Channel` if successful.
|
|
9525
9567
|
*
|
|
9568
|
+
* **Details**
|
|
9569
|
+
*
|
|
9570
|
+
* The effect runs in the channel scope, so finalizers it registers run when
|
|
9571
|
+
* that scope closes.
|
|
9572
|
+
*
|
|
9526
9573
|
* **Example** (Unwrapping channel effects)
|
|
9527
9574
|
*
|
|
9528
9575
|
* ```ts import.meta.vitest
|
|
@@ -9566,6 +9613,14 @@ export const unwrap = <OutElem, OutErr, OutDone, InElem, InErr, InDone, R2, E, R
|
|
|
9566
9613
|
* Runs a channel with a scope provided for the duration of the channel
|
|
9567
9614
|
* execution, removing the channel's `Scope` requirement.
|
|
9568
9615
|
*
|
|
9616
|
+
* **Details**
|
|
9617
|
+
*
|
|
9618
|
+
* The provided scope closes when the channel ends on its own (completion,
|
|
9619
|
+
* failure, or defect), before downstream observes that end. If a downstream
|
|
9620
|
+
* operator stops pulling first, it closes no later than when the channel scope
|
|
9621
|
+
* closes. It satisfies the `Scope` service requirement only; constructors that
|
|
9622
|
+
* register finalizers in the channel scope, such as `callback`, keep using it.
|
|
9623
|
+
*
|
|
9569
9624
|
* @stability stable
|
|
9570
9625
|
* @category resource management
|
|
9571
9626
|
* @since 2.0.0
|
|
@@ -10145,6 +10200,12 @@ export const onError: {
|
|
|
10145
10200
|
* Returns a channel with an exit-aware finalizer that is guaranteed to run once
|
|
10146
10201
|
* the channel begins execution, whether it succeeds or fails.
|
|
10147
10202
|
*
|
|
10203
|
+
* **Details**
|
|
10204
|
+
*
|
|
10205
|
+
* The finalizer runs when the channel ends on its own (completion, failure, or
|
|
10206
|
+
* defect), before downstream observes that end. If a downstream operator stops
|
|
10207
|
+
* pulling first, it runs no later than when the channel scope closes.
|
|
10208
|
+
*
|
|
10148
10209
|
* **Example** (Running exit finalizers)
|
|
10149
10210
|
*
|
|
10150
10211
|
* ```ts import.meta.vitest
|
|
@@ -10175,6 +10236,12 @@ export const onExit: {
|
|
|
10175
10236
|
* Returns a channel with an exit-aware finalizer that is guaranteed to run once
|
|
10176
10237
|
* the channel begins execution, whether it succeeds or fails.
|
|
10177
10238
|
*
|
|
10239
|
+
* **Details**
|
|
10240
|
+
*
|
|
10241
|
+
* The finalizer runs when the channel ends on its own (completion, failure, or
|
|
10242
|
+
* defect), before downstream observes that end. If a downstream operator stops
|
|
10243
|
+
* pulling first, it runs no later than when the channel scope closes.
|
|
10244
|
+
*
|
|
10178
10245
|
* **Example** (Running exit finalizers)
|
|
10179
10246
|
*
|
|
10180
10247
|
* ```ts import.meta.vitest
|
|
@@ -10209,6 +10276,12 @@ export const onExit: {
|
|
|
10209
10276
|
* Returns a channel with an exit-aware finalizer that is guaranteed to run once
|
|
10210
10277
|
* the channel begins execution, whether it succeeds or fails.
|
|
10211
10278
|
*
|
|
10279
|
+
* **Details**
|
|
10280
|
+
*
|
|
10281
|
+
* The finalizer runs when the channel ends on its own (completion, failure, or
|
|
10282
|
+
* defect), before downstream observes that end. If a downstream operator stops
|
|
10283
|
+
* pulling first, it runs no later than when the channel scope closes.
|
|
10284
|
+
*
|
|
10212
10285
|
* **Example** (Running exit finalizers)
|
|
10213
10286
|
*
|
|
10214
10287
|
* ```ts import.meta.vitest
|
|
@@ -10434,6 +10507,12 @@ export const onEnd: {
|
|
|
10434
10507
|
* Returns a channel with a finalizer effect that is guaranteed to run once the
|
|
10435
10508
|
* channel begins execution, whether it succeeds or fails.
|
|
10436
10509
|
*
|
|
10510
|
+
* **Details**
|
|
10511
|
+
*
|
|
10512
|
+
* The finalizer runs when the channel ends on its own (completion, failure, or
|
|
10513
|
+
* defect), before downstream observes that end. If a downstream operator stops
|
|
10514
|
+
* pulling first, it runs no later than when the channel scope closes.
|
|
10515
|
+
*
|
|
10437
10516
|
* **Example** (Ensuring cleanup runs)
|
|
10438
10517
|
*
|
|
10439
10518
|
* ```ts import.meta.vitest
|
|
@@ -10464,6 +10543,12 @@ export const ensuring: {
|
|
|
10464
10543
|
* Returns a channel with a finalizer effect that is guaranteed to run once the
|
|
10465
10544
|
* channel begins execution, whether it succeeds or fails.
|
|
10466
10545
|
*
|
|
10546
|
+
* **Details**
|
|
10547
|
+
*
|
|
10548
|
+
* The finalizer runs when the channel ends on its own (completion, failure, or
|
|
10549
|
+
* defect), before downstream observes that end. If a downstream operator stops
|
|
10550
|
+
* pulling first, it runs no later than when the channel scope closes.
|
|
10551
|
+
*
|
|
10467
10552
|
* **Example** (Ensuring cleanup runs)
|
|
10468
10553
|
*
|
|
10469
10554
|
* ```ts import.meta.vitest
|
|
@@ -10496,6 +10581,12 @@ export const ensuring: {
|
|
|
10496
10581
|
* Returns a channel with a finalizer effect that is guaranteed to run once the
|
|
10497
10582
|
* channel begins execution, whether it succeeds or fails.
|
|
10498
10583
|
*
|
|
10584
|
+
* **Details**
|
|
10585
|
+
*
|
|
10586
|
+
* The finalizer runs when the channel ends on its own (completion, failure, or
|
|
10587
|
+
* defect), before downstream observes that end. If a downstream operator stops
|
|
10588
|
+
* pulling first, it runs no later than when the channel scope closes.
|
|
10589
|
+
*
|
|
10499
10590
|
* **Example** (Ensuring cleanup runs)
|
|
10500
10591
|
*
|
|
10501
10592
|
* ```ts import.meta.vitest
|
|
@@ -11852,7 +11943,8 @@ export const runFoldEffect: {
|
|
|
11852
11943
|
*
|
|
11853
11944
|
* **Details**
|
|
11854
11945
|
*
|
|
11855
|
-
* The
|
|
11946
|
+
* The channel runs in the provided `Scope`, which the pull leaves open; close
|
|
11947
|
+
* it to release any resources the channel still holds. Consume the pull only
|
|
11856
11948
|
* while that scope remains open. Pulls are serialized so only one pull is
|
|
11857
11949
|
* evaluated at a time.
|
|
11858
11950
|
*
|
|
@@ -11905,6 +11997,11 @@ export const toPull: <OutElem, OutErr, OutDone, Env>(
|
|
|
11905
11997
|
/**
|
|
11906
11998
|
* Converts a channel to a Pull within an existing scope.
|
|
11907
11999
|
*
|
|
12000
|
+
* **Details**
|
|
12001
|
+
*
|
|
12002
|
+
* The channel runs in the provided scope, which the pull leaves open; close it
|
|
12003
|
+
* to release any resources the channel still holds.
|
|
12004
|
+
*
|
|
11908
12005
|
* **Example** (Converting channels to scoped pulls)
|
|
11909
12006
|
*
|
|
11910
12007
|
* ```ts import.meta.vitest
|
package/src/Codegen.ts
CHANGED
|
@@ -509,11 +509,16 @@ export class Module {
|
|
|
509
509
|
* Returned keys preserve the requested names even when declaration names must change to avoid collisions.
|
|
510
510
|
* A root that references a definition of the same name reuses that definition's binding.
|
|
511
511
|
* The module remains open for further declarations; imports and initialization order are resolved when printing.
|
|
512
|
+
* Built-in declarations and filters use their recorded representation ID and payload, including after a JSON
|
|
513
|
+
* round trip. A custom `toCode` annotation takes precedence. Replacing a built-in ID with a custom ID requires
|
|
514
|
+
* supplying a callback for that ID.
|
|
512
515
|
*
|
|
513
516
|
* **Gotchas**
|
|
514
517
|
*
|
|
515
|
-
* Recursive representations must contain explicit suspensions. Custom declarations and
|
|
516
|
-
* `toCode` callbacks. Each callback is called once and its exceptions pass through unchanged.
|
|
518
|
+
* Recursive representations must contain explicit suspensions. Custom declarations and individual filters require
|
|
519
|
+
* supported `toCode` callbacks. Each callback is called once and its exceptions pass through unchanged.
|
|
520
|
+
* An explicit `toCode: undefined` disables built-in lookup on a live declaration or filter.
|
|
521
|
+
* Mutable arguments such as date bounds are printed from the values recorded at schema creation.
|
|
517
522
|
* Callback output supports imports, qualified names, generic and structural types, API calls,
|
|
518
523
|
* literal/object/array arguments, and zero-argument arrows. Unsupported syntax throws with its document path.
|
|
519
524
|
* When another declaration eagerly uses a returned binding, include it in that declaration's dependencies.
|
package/src/Effect.ts
CHANGED
|
@@ -84,6 +84,7 @@ import type {
|
|
|
84
84
|
ExcludeTag,
|
|
85
85
|
ExtractReason,
|
|
86
86
|
ExtractTag,
|
|
87
|
+
IsUnion,
|
|
87
88
|
NarrowReason,
|
|
88
89
|
NoInfer,
|
|
89
90
|
OmitReason,
|
|
@@ -4905,12 +4906,13 @@ export const catchTag: {
|
|
|
4905
4906
|
*/
|
|
4906
4907
|
<
|
|
4907
4908
|
A,
|
|
4908
|
-
E
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4909
|
+
// Default `E` to `any` so `K` is not rejected while TS defers an inline `self` (e.g. `Effect.map(...)`)
|
|
4910
|
+
E = any,
|
|
4911
|
+
R = unknown,
|
|
4912
|
+
const K extends Tags<E> | Arr.NonEmptyReadonlyArray<Tags<E>> = never,
|
|
4913
|
+
R1 = unknown,
|
|
4914
|
+
E1 = unknown,
|
|
4915
|
+
A1 = unknown,
|
|
4914
4916
|
A2 = unassigned,
|
|
4915
4917
|
E2 = never,
|
|
4916
4918
|
R2 = never
|
|
@@ -5382,6 +5384,22 @@ export const catchReason: {
|
|
|
5382
5384
|
>
|
|
5383
5385
|
} = internal.catchReason
|
|
5384
5386
|
|
|
5387
|
+
type RequiredCaseKeys<Cases> = {
|
|
5388
|
+
[RK in keyof Cases & string]: {} extends Record<RK, 1> ? never
|
|
5389
|
+
: [Cases] extends [Record<RK, (...args: Array<any>) => any>] ? RK
|
|
5390
|
+
: never
|
|
5391
|
+
}[keyof Cases & string]
|
|
5392
|
+
|
|
5393
|
+
type CaseReturn<Cases> = Cases extends unknown ? ReturnType<Extract<Cases[keyof Cases], (...args: Array<any>) => any>>
|
|
5394
|
+
: never
|
|
5395
|
+
|
|
5396
|
+
type UnhandledParent<E, K extends string, Handled extends string> = {} extends Record<K, 1> ? ExtractTag<E, K>
|
|
5397
|
+
: IsUnion<K> extends true ? ExtractTag<E, K>
|
|
5398
|
+
: ExtractTag<E, K> extends infer P
|
|
5399
|
+
? P extends { readonly reason: { readonly _tag: string } } ? [ExcludeReason<P, Handled>] extends [never] ? never : P
|
|
5400
|
+
: P
|
|
5401
|
+
: never
|
|
5402
|
+
|
|
5385
5403
|
/**
|
|
5386
5404
|
* Catches multiple reasons within a tagged error using an object of handlers.
|
|
5387
5405
|
*
|
|
@@ -5391,6 +5409,8 @@ export const catchReason: {
|
|
|
5391
5409
|
* is converted to a defect, preserving reason order and interrupts. An
|
|
5392
5410
|
* interruption alongside a typed error does not prevent recovery.
|
|
5393
5411
|
*
|
|
5412
|
+
* Only own enumerable properties of `cases` are matched; inherited properties are ignored.
|
|
5413
|
+
*
|
|
5394
5414
|
* **Example** (Handling multiple error reasons)
|
|
5395
5415
|
*
|
|
5396
5416
|
* ```ts import.meta.vitest
|
|
@@ -5438,6 +5458,8 @@ export const catchReasons: {
|
|
|
5438
5458
|
* is converted to a defect, preserving reason order and interrupts. An
|
|
5439
5459
|
* interruption alongside a typed error does not prevent recovery.
|
|
5440
5460
|
*
|
|
5461
|
+
* Only own enumerable properties of `cases` are matched; inherited properties are ignored.
|
|
5462
|
+
*
|
|
5441
5463
|
* **Example** (Handling multiple error reasons)
|
|
5442
5464
|
*
|
|
5443
5465
|
* ```ts import.meta.vitest
|
|
@@ -5484,37 +5506,105 @@ export const catchReasons: {
|
|
|
5484
5506
|
error: NarrowReason<ExtractTag<NoInfer<E>, K>, RK>
|
|
5485
5507
|
) => Effect<any, any, any>
|
|
5486
5508
|
},
|
|
5487
|
-
A2
|
|
5509
|
+
// `A2`, `E2` and `R2` are only for calls that pass explicit type arguments.
|
|
5510
|
+
A2 = never,
|
|
5488
5511
|
E2 = never,
|
|
5489
|
-
R2 = never
|
|
5512
|
+
R2 = never,
|
|
5513
|
+
Ret extends Effect<any, any, any> = Effect<A2, E2, R2>
|
|
5514
|
+
>(
|
|
5515
|
+
errorTag: K,
|
|
5516
|
+
cases: Cases,
|
|
5517
|
+
orElse: (
|
|
5518
|
+
reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>,
|
|
5519
|
+
error: OmitReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>
|
|
5520
|
+
) => Ret
|
|
5521
|
+
): <A, R>(
|
|
5522
|
+
self: Effect<A, E, R>
|
|
5523
|
+
) => Effect<
|
|
5524
|
+
A | Success<Ret | CaseReturn<Cases>>,
|
|
5525
|
+
| ExcludeTag<E, K>
|
|
5526
|
+
| UnhandledParent<E, K, string>
|
|
5527
|
+
| Error<Ret | CaseReturn<Cases>>,
|
|
5528
|
+
R | Services<Ret | CaseReturn<Cases>>
|
|
5529
|
+
>
|
|
5530
|
+
/**
|
|
5531
|
+
* Catches multiple reasons within a tagged error using an object of handlers.
|
|
5532
|
+
*
|
|
5533
|
+
* **Gotchas**
|
|
5534
|
+
*
|
|
5535
|
+
* If the cause contains a defect, the handler is skipped and every typed error
|
|
5536
|
+
* is converted to a defect, preserving reason order and interrupts. An
|
|
5537
|
+
* interruption alongside a typed error does not prevent recovery.
|
|
5538
|
+
*
|
|
5539
|
+
* Only own enumerable properties of `cases` are matched; inherited properties are ignored.
|
|
5540
|
+
*
|
|
5541
|
+
* **Example** (Handling multiple error reasons)
|
|
5542
|
+
*
|
|
5543
|
+
* ```ts import.meta.vitest
|
|
5544
|
+
* import { Data, Effect } from "effect"
|
|
5545
|
+
*
|
|
5546
|
+
* class RateLimitError extends Data.TaggedError("RateLimitError")<{
|
|
5547
|
+
* retryAfter: number
|
|
5548
|
+
* }> {}
|
|
5549
|
+
*
|
|
5550
|
+
* class QuotaExceededError extends Data.TaggedError("QuotaExceededError")<{
|
|
5551
|
+
* limit: number
|
|
5552
|
+
* }> {}
|
|
5553
|
+
*
|
|
5554
|
+
* class AiError extends Data.TaggedError("AiError")<{
|
|
5555
|
+
* reason: RateLimitError | QuotaExceededError
|
|
5556
|
+
* }> {}
|
|
5557
|
+
*
|
|
5558
|
+
* const program: Effect.Effect<string, AiError> = Effect.fail(
|
|
5559
|
+
* new AiError({ reason: new QuotaExceededError({ limit: 100 }) })
|
|
5560
|
+
* )
|
|
5561
|
+
*
|
|
5562
|
+
* const handled = program.pipe(
|
|
5563
|
+
* Effect.catchReasons("AiError", {
|
|
5564
|
+
* RateLimitError: (reason) =>
|
|
5565
|
+
* Effect.succeed(`Retry after ${reason.retryAfter}s`),
|
|
5566
|
+
* QuotaExceededError: (reason) =>
|
|
5567
|
+
* Effect.succeed(`Quota exceeded: ${reason.limit}`)
|
|
5568
|
+
* })
|
|
5569
|
+
* )
|
|
5570
|
+
*
|
|
5571
|
+
* Effect.runSync(handled) // => "Quota exceeded: 100"
|
|
5572
|
+
* ```
|
|
5573
|
+
*
|
|
5574
|
+
* @stability stable
|
|
5575
|
+
* @category error handling
|
|
5576
|
+
* @since 4.0.0
|
|
5577
|
+
*/
|
|
5578
|
+
<
|
|
5579
|
+
K extends Tags<E>,
|
|
5580
|
+
E,
|
|
5581
|
+
Cases extends {
|
|
5582
|
+
[RK in ReasonTags<ExtractTag<NoInfer<E>, K>>]+?: (
|
|
5583
|
+
reason: ExtractReason<ExtractTag<NoInfer<E>, K>, RK>,
|
|
5584
|
+
error: NarrowReason<ExtractTag<NoInfer<E>, K>, RK>
|
|
5585
|
+
) => Effect<any, any, any>
|
|
5586
|
+
},
|
|
5587
|
+
A2 = never,
|
|
5588
|
+
E2 = never,
|
|
5589
|
+
R2 = never,
|
|
5590
|
+
Ret extends Effect<any, any, any> = Effect<A2, E2, R2>
|
|
5490
5591
|
>(
|
|
5491
5592
|
errorTag: K,
|
|
5492
5593
|
cases: Cases,
|
|
5493
5594
|
orElse?:
|
|
5494
5595
|
| ((
|
|
5495
|
-
reason: ExcludeReason<ExtractTag<NoInfer<E>, K>,
|
|
5496
|
-
error: OmitReason<ExtractTag<NoInfer<E>, K>,
|
|
5497
|
-
) =>
|
|
5596
|
+
reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>,
|
|
5597
|
+
error: OmitReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>
|
|
5598
|
+
) => Ret)
|
|
5498
5599
|
| undefined
|
|
5499
5600
|
): <A, R>(
|
|
5500
5601
|
self: Effect<A, E, R>
|
|
5501
5602
|
) => Effect<
|
|
5502
|
-
|
|
|
5503
|
-
| Exclude<A2, unassigned>
|
|
5504
|
-
| {
|
|
5505
|
-
[RK in keyof Cases]: Cases[RK] extends (...args: Array<any>) => Effect<infer A, any, any> ? A : never
|
|
5506
|
-
}[keyof Cases],
|
|
5603
|
+
A | Success<Ret | CaseReturn<Cases>>,
|
|
5507
5604
|
| ExcludeTag<E, K>
|
|
5508
|
-
|
|
|
5509
|
-
|
|
|
5510
|
-
|
|
|
5511
|
-
[RK in keyof Cases]: Cases[RK] extends (...args: Array<any>) => Effect<any, infer E, any> ? E : never
|
|
5512
|
-
}[keyof Cases],
|
|
5513
|
-
| R
|
|
5514
|
-
| R2
|
|
5515
|
-
| {
|
|
5516
|
-
[RK in keyof Cases]: Cases[RK] extends (...args: Array<any>) => Effect<any, any, infer R> ? R : never
|
|
5517
|
-
}[keyof Cases]
|
|
5605
|
+
| UnhandledParent<E, K, RequiredCaseKeys<Cases>>
|
|
5606
|
+
| Error<Ret | CaseReturn<Cases>>,
|
|
5607
|
+
R | Services<Ret | CaseReturn<Cases>>
|
|
5518
5608
|
>
|
|
5519
5609
|
/**
|
|
5520
5610
|
* Catches multiple reasons within a tagged error using an object of handlers.
|
|
@@ -5525,6 +5615,8 @@ export const catchReasons: {
|
|
|
5525
5615
|
* is converted to a defect, preserving reason order and interrupts. An
|
|
5526
5616
|
* interruption alongside a typed error does not prevent recovery.
|
|
5527
5617
|
*
|
|
5618
|
+
* Only own enumerable properties of `cases` are matched; inherited properties are ignored.
|
|
5619
|
+
*
|
|
5528
5620
|
* **Example** (Handling multiple error reasons)
|
|
5529
5621
|
*
|
|
5530
5622
|
* ```ts import.meta.vitest
|
|
@@ -5573,36 +5665,104 @@ export const catchReasons: {
|
|
|
5573
5665
|
error: NarrowReason<ExtractTag<E, K>, RK>
|
|
5574
5666
|
) => Effect<any, any, any>
|
|
5575
5667
|
},
|
|
5576
|
-
A2 =
|
|
5668
|
+
A2 = never,
|
|
5577
5669
|
E2 = never,
|
|
5578
|
-
R2 = never
|
|
5670
|
+
R2 = never,
|
|
5671
|
+
Ret extends Effect<any, any, any> = Effect<A2, E2, R2>
|
|
5672
|
+
>(
|
|
5673
|
+
self: Effect<A, E, R>,
|
|
5674
|
+
errorTag: K,
|
|
5675
|
+
cases: Cases,
|
|
5676
|
+
orElse: (
|
|
5677
|
+
reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>,
|
|
5678
|
+
error: OmitReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>
|
|
5679
|
+
) => Ret
|
|
5680
|
+
): Effect<
|
|
5681
|
+
A | Success<Ret | CaseReturn<Cases>>,
|
|
5682
|
+
| ExcludeTag<E, K>
|
|
5683
|
+
| UnhandledParent<E, K, string>
|
|
5684
|
+
| Error<Ret | CaseReturn<Cases>>,
|
|
5685
|
+
R | Services<Ret | CaseReturn<Cases>>
|
|
5686
|
+
>
|
|
5687
|
+
/**
|
|
5688
|
+
* Catches multiple reasons within a tagged error using an object of handlers.
|
|
5689
|
+
*
|
|
5690
|
+
* **Gotchas**
|
|
5691
|
+
*
|
|
5692
|
+
* If the cause contains a defect, the handler is skipped and every typed error
|
|
5693
|
+
* is converted to a defect, preserving reason order and interrupts. An
|
|
5694
|
+
* interruption alongside a typed error does not prevent recovery.
|
|
5695
|
+
*
|
|
5696
|
+
* Only own enumerable properties of `cases` are matched; inherited properties are ignored.
|
|
5697
|
+
*
|
|
5698
|
+
* **Example** (Handling multiple error reasons)
|
|
5699
|
+
*
|
|
5700
|
+
* ```ts import.meta.vitest
|
|
5701
|
+
* import { Data, Effect } from "effect"
|
|
5702
|
+
*
|
|
5703
|
+
* class RateLimitError extends Data.TaggedError("RateLimitError")<{
|
|
5704
|
+
* retryAfter: number
|
|
5705
|
+
* }> {}
|
|
5706
|
+
*
|
|
5707
|
+
* class QuotaExceededError extends Data.TaggedError("QuotaExceededError")<{
|
|
5708
|
+
* limit: number
|
|
5709
|
+
* }> {}
|
|
5710
|
+
*
|
|
5711
|
+
* class AiError extends Data.TaggedError("AiError")<{
|
|
5712
|
+
* reason: RateLimitError | QuotaExceededError
|
|
5713
|
+
* }> {}
|
|
5714
|
+
*
|
|
5715
|
+
* const program: Effect.Effect<string, AiError> = Effect.fail(
|
|
5716
|
+
* new AiError({ reason: new QuotaExceededError({ limit: 100 }) })
|
|
5717
|
+
* )
|
|
5718
|
+
*
|
|
5719
|
+
* const handled = program.pipe(
|
|
5720
|
+
* Effect.catchReasons("AiError", {
|
|
5721
|
+
* RateLimitError: (reason) =>
|
|
5722
|
+
* Effect.succeed(`Retry after ${reason.retryAfter}s`),
|
|
5723
|
+
* QuotaExceededError: (reason) =>
|
|
5724
|
+
* Effect.succeed(`Quota exceeded: ${reason.limit}`)
|
|
5725
|
+
* })
|
|
5726
|
+
* )
|
|
5727
|
+
*
|
|
5728
|
+
* Effect.runSync(handled) // => "Quota exceeded: 100"
|
|
5729
|
+
* ```
|
|
5730
|
+
*
|
|
5731
|
+
* @stability stable
|
|
5732
|
+
* @category error handling
|
|
5733
|
+
* @since 4.0.0
|
|
5734
|
+
*/
|
|
5735
|
+
<
|
|
5736
|
+
A,
|
|
5737
|
+
E,
|
|
5738
|
+
R,
|
|
5739
|
+
K extends Tags<E>,
|
|
5740
|
+
Cases extends {
|
|
5741
|
+
[RK in ReasonTags<ExtractTag<E, K>>]+?: (
|
|
5742
|
+
reason: ExtractReason<ExtractTag<E, K>, RK>,
|
|
5743
|
+
error: NarrowReason<ExtractTag<E, K>, RK>
|
|
5744
|
+
) => Effect<any, any, any>
|
|
5745
|
+
},
|
|
5746
|
+
A2 = never,
|
|
5747
|
+
E2 = never,
|
|
5748
|
+
R2 = never,
|
|
5749
|
+
Ret extends Effect<any, any, any> = Effect<A2, E2, R2>
|
|
5579
5750
|
>(
|
|
5580
5751
|
self: Effect<A, E, R>,
|
|
5581
5752
|
errorTag: K,
|
|
5582
5753
|
cases: Cases,
|
|
5583
5754
|
orElse?:
|
|
5584
5755
|
| ((
|
|
5585
|
-
reason: ExcludeReason<ExtractTag<NoInfer<E>, K>,
|
|
5586
|
-
error: OmitReason<ExtractTag<NoInfer<E>, K>,
|
|
5587
|
-
) =>
|
|
5756
|
+
reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>,
|
|
5757
|
+
error: OmitReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>
|
|
5758
|
+
) => Ret)
|
|
5588
5759
|
| undefined
|
|
5589
5760
|
): Effect<
|
|
5590
|
-
|
|
|
5591
|
-
| Exclude<A2, unassigned>
|
|
5592
|
-
| {
|
|
5593
|
-
[RK in keyof Cases]: Cases[RK] extends (...args: Array<any>) => Effect<infer A, any, any> ? A : never
|
|
5594
|
-
}[keyof Cases],
|
|
5761
|
+
A | Success<Ret | CaseReturn<Cases>>,
|
|
5595
5762
|
| ExcludeTag<E, K>
|
|
5596
|
-
|
|
|
5597
|
-
|
|
|
5598
|
-
|
|
|
5599
|
-
[RK in keyof Cases]: Cases[RK] extends (...args: Array<any>) => Effect<any, infer E, any> ? E : never
|
|
5600
|
-
}[keyof Cases],
|
|
5601
|
-
| R
|
|
5602
|
-
| R2
|
|
5603
|
-
| {
|
|
5604
|
-
[RK in keyof Cases]: Cases[RK] extends (...args: Array<any>) => Effect<any, any, infer R> ? R : never
|
|
5605
|
-
}[keyof Cases]
|
|
5763
|
+
| UnhandledParent<E, K, RequiredCaseKeys<Cases>>
|
|
5764
|
+
| Error<Ret | CaseReturn<Cases>>,
|
|
5765
|
+
R | Services<Ret | CaseReturn<Cases>>
|
|
5606
5766
|
>
|
|
5607
5767
|
} = internal.catchReasons
|
|
5608
5768
|
|
|
@@ -17916,6 +18076,11 @@ export const annotateSpans: {
|
|
|
17916
18076
|
/**
|
|
17917
18077
|
* Adds an annotation to the current span if available.
|
|
17918
18078
|
*
|
|
18079
|
+
* **Details**
|
|
18080
|
+
*
|
|
18081
|
+
* Does nothing when there is no current span or when the nearest parent span is
|
|
18082
|
+
* an `ExternalSpan`.
|
|
18083
|
+
*
|
|
17919
18084
|
* **Example** (Annotating the current span)
|
|
17920
18085
|
*
|
|
17921
18086
|
* ```ts import.meta.vitest
|
|
@@ -17941,6 +18106,11 @@ export const annotateCurrentSpan: {
|
|
|
17941
18106
|
/**
|
|
17942
18107
|
* Adds an annotation to the current span if available.
|
|
17943
18108
|
*
|
|
18109
|
+
* **Details**
|
|
18110
|
+
*
|
|
18111
|
+
* Does nothing when there is no current span or when the nearest parent span is
|
|
18112
|
+
* an `ExternalSpan`.
|
|
18113
|
+
*
|
|
17944
18114
|
* **Example** (Annotating the current span)
|
|
17945
18115
|
*
|
|
17946
18116
|
* ```ts import.meta.vitest
|
|
@@ -17966,6 +18136,11 @@ export const annotateCurrentSpan: {
|
|
|
17966
18136
|
/**
|
|
17967
18137
|
* Adds an annotation to the current span if available.
|
|
17968
18138
|
*
|
|
18139
|
+
* **Details**
|
|
18140
|
+
*
|
|
18141
|
+
* Does nothing when there is no current span or when the nearest parent span is
|
|
18142
|
+
* an `ExternalSpan`.
|
|
18143
|
+
*
|
|
17969
18144
|
* **Example** (Annotating the current span)
|
|
17970
18145
|
*
|
|
17971
18146
|
* ```ts import.meta.vitest
|
|
@@ -17995,8 +18170,9 @@ export const annotateCurrentSpan: {
|
|
|
17995
18170
|
*
|
|
17996
18171
|
* **Details**
|
|
17997
18172
|
*
|
|
17998
|
-
* The effect fails with `NoSuchElementError` when there is no
|
|
17999
|
-
* `
|
|
18173
|
+
* The effect fails with `NoSuchElementError` when there is no parent span or
|
|
18174
|
+
* when the nearest parent span is an `ExternalSpan`. Use `currentParentSpan` to
|
|
18175
|
+
* read either kind.
|
|
18000
18176
|
*
|
|
18001
18177
|
* **Example** (Reading the current span)
|
|
18002
18178
|
*
|