effect 4.1.5 → 4.1.7
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/Config.d.ts +1 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +5 -3
- package/dist/Config.js.map +1 -1
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +79 -31
- package/dist/Context.js.map +1 -1
- package/dist/Cron.d.ts.map +1 -1
- package/dist/Cron.js +10 -9
- package/dist/Cron.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 -66
- package/dist/Equal.js.map +1 -1
- package/dist/Formatter.js +4 -4
- package/dist/Formatter.js.map +1 -1
- package/dist/Hash.d.ts.map +1 -1
- package/dist/Hash.js +34 -41
- 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/Metric.d.ts.map +1 -1
- package/dist/Metric.js +3 -4
- package/dist/Metric.js.map +1 -1
- package/dist/Order.js +1 -1
- package/dist/Order.js.map +1 -1
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +49 -21
- package/dist/Pool.js.map +1 -1
- package/dist/Predicate.d.ts.map +1 -1
- package/dist/Predicate.js +2 -1
- package/dist/Predicate.js.map +1 -1
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +15 -9
- package/dist/Scheduler.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 +2 -2
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +199 -98
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +29 -50
- package/dist/SchemaParser.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 +3 -4
- package/dist/Tracer.js.map +1 -1
- package/dist/ai/McpClient.d.ts +68 -4
- package/dist/ai/McpClient.d.ts.map +1 -1
- package/dist/ai/McpClient.js +100 -17
- package/dist/ai/McpClient.js.map +1 -1
- package/dist/ai/McpClientError.d.ts +46 -4
- package/dist/ai/McpClientError.d.ts.map +1 -1
- package/dist/ai/McpClientError.js +38 -3
- package/dist/ai/McpClientError.js.map +1 -1
- package/dist/ai/McpServer.d.ts +158 -7
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +103 -49
- 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/ai/internal/mcpProtocol/v2024_11_05.js +9 -7
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js +12 -11
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js +18 -17
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js +19 -18
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2026_07_28.js +1 -1
- package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
- package/dist/ai/internal/mcpProtocol.js +11 -0
- package/dist/ai/internal/mcpProtocol.js.map +1 -1
- package/dist/ai/internal/mcpRuntime.js +29 -17
- package/dist/ai/internal/mcpRuntime.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2024_11_05.js +2 -1
- package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2025_03_26.js +1 -8
- package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2025_06_18.js +5 -9
- package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2025_11_25.js +1 -8
- package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2026_07_28.js +4 -3
- package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
- package/dist/cluster/ClusterCron.d.ts +5 -20
- package/dist/cluster/ClusterCron.d.ts.map +1 -1
- package/dist/cluster/ClusterCron.js +16 -4
- package/dist/cluster/ClusterCron.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 +48 -23
- 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/Hex.js +7 -5
- package/dist/encoding/Hex.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/HttpEffect.d.ts.map +1 -1
- package/dist/http/HttpEffect.js +31 -2
- package/dist/http/HttpEffect.js.map +1 -1
- package/dist/http/HttpMiddleware.js +1 -1
- package/dist/http/HttpMiddleware.js.map +1 -1
- package/dist/http/HttpServerError.d.ts +1 -1
- package/dist/http/HttpServerError.js +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/core.js +60 -43
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/dateTime.js +35 -17
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +60 -52
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/equal.js +44 -13
- package/dist/internal/equal.js.map +1 -1
- package/dist/internal/fiberCachedKeys.d.ts +2 -0
- package/dist/internal/fiberCachedKeys.d.ts.map +1 -0
- package/dist/internal/fiberCachedKeys.js +48 -0
- package/dist/internal/fiberCachedKeys.js.map +1 -0
- package/dist/internal/hashMap.js +1 -1
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/matcher.js +17 -17
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/predicate.d.ts +2 -0
- package/dist/internal/predicate.d.ts.map +1 -0
- package/dist/internal/predicate.js +10 -0
- package/dist/internal/predicate.js.map +1 -0
- package/dist/internal/references.js +8 -11
- package/dist/internal/references.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/sql/Statement.d.ts +23 -0
- package/dist/sql/Statement.d.ts.map +1 -1
- package/dist/sql/Statement.js +30 -5
- package/dist/sql/Statement.js.map +1 -1
- package/dist/workers/Worker.d.ts +21 -0
- package/dist/workers/Worker.d.ts.map +1 -1
- package/dist/workers/Worker.js +23 -0
- package/dist/workers/Worker.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/Config.ts +6 -3
- package/src/Context.ts +108 -50
- package/src/Cron.ts +11 -10
- package/src/Effect.ts +224 -48
- package/src/Equal.ts +93 -80
- package/src/Formatter.ts +4 -4
- package/src/Hash.ts +49 -48
- package/src/LayerRef.ts +6 -4
- package/src/Logger.ts +68 -25
- package/src/Match.ts +78 -50
- package/src/Metric.ts +4 -4
- package/src/Order.ts +1 -1
- package/src/Pool.ts +62 -33
- package/src/Predicate.ts +2 -5
- package/src/Scheduler.ts +27 -10
- package/src/Schema.ts +79 -296
- package/src/SchemaAST.ts +231 -157
- package/src/SchemaParser.ts +40 -57
- package/src/ScopedCache.ts +6 -4
- package/src/Stream.ts +167 -33
- package/src/String.ts +1 -1
- package/src/Tracer.ts +11 -2
- package/src/ai/McpClient.ts +157 -15
- package/src/ai/McpClientError.ts +55 -4
- package/src/ai/McpServer.ts +318 -91
- package/src/ai/Prompt.ts +20 -3
- package/src/ai/Skill.ts +236 -0
- package/src/ai/index.ts +6 -0
- package/src/ai/internal/mcpProtocol/v2024_11_05.ts +8 -13
- package/src/ai/internal/mcpProtocol/v2025_03_26.ts +13 -15
- package/src/ai/internal/mcpProtocol/v2025_06_18.ts +21 -23
- package/src/ai/internal/mcpProtocol/v2025_11_25.ts +22 -24
- package/src/ai/internal/mcpProtocol/v2026_07_28.ts +1 -1
- package/src/ai/internal/mcpProtocol.ts +15 -0
- package/src/ai/internal/mcpRuntime.ts +36 -13
- package/src/ai/internal/mcpSchema/v2024_11_05.ts +2 -1
- package/src/ai/internal/mcpSchema/v2025_03_26.ts +1 -9
- package/src/ai/internal/mcpSchema/v2025_06_18.ts +3 -10
- package/src/ai/internal/mcpSchema/v2025_11_25.ts +1 -9
- package/src/ai/internal/mcpSchema/v2026_07_28.ts +6 -8
- package/src/cluster/ClusterCron.ts +31 -20
- package/src/cluster/ClusterWorkflowEngine.ts +172 -96
- package/src/cluster/MessageStorage.ts +51 -2
- package/src/cluster/SqlMessageStorage.ts +88 -36
- 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/Hex.ts +5 -5
- 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/HttpEffect.ts +23 -3
- package/src/http/HttpMiddleware.ts +1 -1
- package/src/http/HttpServerError.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/core.ts +80 -44
- package/src/internal/dateTime.ts +43 -24
- package/src/internal/effect.ts +115 -157
- package/src/internal/equal.ts +73 -17
- package/src/internal/fiberCachedKeys.ts +81 -0
- package/src/internal/hashMap.ts +1 -1
- package/src/internal/matcher.ts +34 -113
- package/src/internal/predicate.ts +10 -0
- package/src/internal/references.ts +21 -14
- 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/sql/Statement.ts +48 -12
- package/src/workers/Worker.ts +25 -0
- 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/dist/internal/hash.d.ts +0 -2
- package/dist/internal/hash.d.ts.map +0 -1
- package/dist/internal/hash.js +0 -11
- package/dist/internal/hash.js.map +0 -1
- package/dist/internal/metric.d.ts +0 -2
- package/dist/internal/metric.d.ts.map +0 -1
- package/dist/internal/metric.js +0 -3
- package/dist/internal/metric.js.map +0 -1
- package/src/internal/hash.ts +0 -11
- package/src/internal/metric.ts +0 -2
package/src/reactivity/Atom.ts
CHANGED
|
@@ -20,7 +20,7 @@ import * as Effect from "../Effect.ts"
|
|
|
20
20
|
import * as Exit from "../Exit.ts"
|
|
21
21
|
import * as Fiber from "../Fiber.ts"
|
|
22
22
|
import type { LazyArg } from "../Function.ts"
|
|
23
|
-
import { constant, constTrue, constVoid, dual
|
|
23
|
+
import { constant, constTrue, constVoid, dual } from "../Function.ts"
|
|
24
24
|
import type * as Inspectable from "../Inspectable.ts"
|
|
25
25
|
import { PipeInspectableProto } from "../internal/core.ts"
|
|
26
26
|
import { getStackTraceLimit } from "../internal/stackTraceLimit.ts"
|
|
@@ -1016,12 +1016,14 @@ function makeStream<A, E>(
|
|
|
1016
1016
|
}
|
|
1017
1017
|
services = Context.add(services, AtomRegistry, ctx.registry)
|
|
1018
1018
|
|
|
1019
|
+
let emitted = false
|
|
1019
1020
|
const run = Effect.scopedWith((scope) =>
|
|
1020
1021
|
Effect.flatMap(Channel.toPullScoped(stream.channel, scope), (pull) =>
|
|
1021
1022
|
Effect.whileLoop({
|
|
1022
1023
|
while: constTrue,
|
|
1023
1024
|
body: () => pull,
|
|
1024
1025
|
step(arr) {
|
|
1026
|
+
emitted = true
|
|
1025
1027
|
ctx.setSelf(AsyncResult.success(Arr.lastNonEmpty(arr), {
|
|
1026
1028
|
waiting: true
|
|
1027
1029
|
}))
|
|
@@ -1029,24 +1031,16 @@ function makeStream<A, E>(
|
|
|
1029
1031
|
}))
|
|
1030
1032
|
).pipe(
|
|
1031
1033
|
Effect.catchCause((cause) => {
|
|
1034
|
+
const current = ctx.self<AsyncResult.AsyncResult<A, E | Cause.NoSuchElementError>>()
|
|
1032
1035
|
if (Pull.isDoneCause(cause)) {
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
Option.
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
ctx.setSelf(
|
|
1039
|
-
AsyncResult.failWithPrevious(new Cause.NoSuchElementError(), {
|
|
1040
|
-
previous: ctx.self<AsyncResult.AsyncResult<A, E | Cause.NoSuchElementError>>()
|
|
1041
|
-
})
|
|
1042
|
-
),
|
|
1043
|
-
onSome: (a) => ctx.setSelf(AsyncResult.success(a))
|
|
1044
|
-
})
|
|
1036
|
+
const value = emitted ? Option.flatMap(current, AsyncResult.value) : Option.none()
|
|
1037
|
+
ctx.setSelf(
|
|
1038
|
+
Option.isSome(value)
|
|
1039
|
+
? AsyncResult.success(value.value)
|
|
1040
|
+
: AsyncResult.failWithPrevious(new Cause.NoSuchElementError(), { previous: current })
|
|
1045
1041
|
)
|
|
1046
1042
|
} else {
|
|
1047
|
-
ctx.setSelf(AsyncResult.failureWithPrevious(cause as Cause.Cause<E>, {
|
|
1048
|
-
previous: ctx.self<AsyncResult.AsyncResult<A, E | Cause.NoSuchElementError>>()
|
|
1049
|
-
}))
|
|
1043
|
+
ctx.setSelf(AsyncResult.failureWithPrevious(cause as Cause.Cause<E>, { previous: current }))
|
|
1050
1044
|
}
|
|
1051
1045
|
return Effect.void
|
|
1052
1046
|
})
|
|
@@ -1168,9 +1162,9 @@ const makeSubRef = (
|
|
|
1168
1162
|
function write(ctx: WriteContext<SubscriptionRef.SubscriptionRef<any>>, value: any) {
|
|
1169
1163
|
const ref = ctx.get(refAtom)
|
|
1170
1164
|
if (SubscriptionRef.isSubscriptionRef(ref)) {
|
|
1171
|
-
Effect.
|
|
1165
|
+
Effect.runFork(SubscriptionRef.set(ref, value))
|
|
1172
1166
|
} else if (AsyncResult.isSuccess(ref)) {
|
|
1173
|
-
Effect.
|
|
1167
|
+
Effect.runFork(SubscriptionRef.set(ref.value, value))
|
|
1174
1168
|
}
|
|
1175
1169
|
}
|
|
1176
1170
|
return writable((get) => {
|
package/src/rpc/RpcClient.ts
CHANGED
|
@@ -1010,6 +1010,31 @@ const makeProtocolHttpUnbatched = (client: HttpClient.HttpClient) =>
|
|
|
1010
1010
|
}
|
|
1011
1011
|
}))
|
|
1012
1012
|
|
|
1013
|
+
const withBatchSpan = <A, E, R>(effect: Effect.Effect<A, E, R>, requests: ReadonlyArray<RequestEncoded>) => {
|
|
1014
|
+
const links: Array<Tracer.SpanLink> = []
|
|
1015
|
+
const seen = new Set<string>()
|
|
1016
|
+
let sampled = false
|
|
1017
|
+
for (const request of requests) {
|
|
1018
|
+
if (request.traceId === undefined || request.spanId === undefined || seen.has(request.spanId)) continue
|
|
1019
|
+
seen.add(request.spanId)
|
|
1020
|
+
const span = Tracer.externalSpan({ traceId: request.traceId, spanId: request.spanId, sampled: request.sampled })
|
|
1021
|
+
sampled ||= span.sampled
|
|
1022
|
+
links.push({ span, attributes: {} })
|
|
1023
|
+
}
|
|
1024
|
+
if (links.length === 0) return effect
|
|
1025
|
+
return Effect.withSpan(effect, "RpcClient.batch", {
|
|
1026
|
+
root: true,
|
|
1027
|
+
sampled,
|
|
1028
|
+
links,
|
|
1029
|
+
attributes: { batchSize: requests.length },
|
|
1030
|
+
captureStackTrace: false
|
|
1031
|
+
}).pipe(
|
|
1032
|
+
// Do not let the opener's tracing settings suppress tracing for other callers.
|
|
1033
|
+
Effect.provideService(Tracer.DisablePropagation, false),
|
|
1034
|
+
Effect.withTracerEnabled(true)
|
|
1035
|
+
)
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1013
1038
|
const makeProtocolHttpBatched = Effect.fnUntraced(function*(client: HttpClient.HttpClient, options: {
|
|
1014
1039
|
readonly window: Duration.Input
|
|
1015
1040
|
readonly maxSize?: number | undefined
|
|
@@ -1047,7 +1072,7 @@ const makeProtocolHttpBatched = Effect.fnUntraced(function*(client: HttpClient.H
|
|
|
1047
1072
|
Effect.raceFirst(Effect.sleep(window), batch.full.await).pipe(
|
|
1048
1073
|
Effect.andThen(Effect.suspend(() => {
|
|
1049
1074
|
closeBatch(clientId, batch)
|
|
1050
|
-
return exchange.send(clientId, batch.requests)
|
|
1075
|
+
return withBatchSpan(exchange.send(clientId, batch.requests), batch.requests)
|
|
1051
1076
|
})),
|
|
1052
1077
|
Effect.onExit((exit) => {
|
|
1053
1078
|
closeBatch(clientId, batch)
|
package/src/rpc/RpcGroup.ts
CHANGED
|
@@ -15,7 +15,7 @@ import * as Effect from "../Effect.ts"
|
|
|
15
15
|
import { identity } from "../Function.ts"
|
|
16
16
|
import type { Headers } from "../http/Headers.ts"
|
|
17
17
|
import * as Layer from "../Layer.ts"
|
|
18
|
-
import type
|
|
18
|
+
import { type Pipeable, pipeArguments } from "../Pipeable.ts"
|
|
19
19
|
import type * as Queue from "../Queue.ts"
|
|
20
20
|
import type * as Record from "../Record.ts"
|
|
21
21
|
import type { Scope } from "../Scope.ts"
|
|
@@ -394,6 +394,9 @@ const RpcGroupProto = {
|
|
|
394
394
|
requests,
|
|
395
395
|
annotations: this.annotations
|
|
396
396
|
})
|
|
397
|
+
},
|
|
398
|
+
pipe() {
|
|
399
|
+
return pipeArguments(this, arguments)
|
|
397
400
|
}
|
|
398
401
|
}
|
|
399
402
|
|
package/src/sql/Migrator.ts
CHANGED
|
@@ -271,16 +271,7 @@ ORDER BY migration_id`,
|
|
|
271
271
|
orElse: () => Effect.void
|
|
272
272
|
})
|
|
273
273
|
|
|
274
|
-
const [
|
|
275
|
-
Effect.map(
|
|
276
|
-
latestMigration,
|
|
277
|
-
Option.match({
|
|
278
|
-
onNone: () => 0,
|
|
279
|
-
onSome: (_) => _.id
|
|
280
|
-
})
|
|
281
|
-
),
|
|
282
|
-
loader
|
|
283
|
-
])
|
|
274
|
+
const [latest, current] = yield* Effect.all([latestMigration, loader])
|
|
284
275
|
|
|
285
276
|
if (new Set(current.map(([id]) => id)).size !== current.length) {
|
|
286
277
|
return yield* new MigrationError({
|
|
@@ -293,7 +284,7 @@ ORDER BY migration_id`,
|
|
|
293
284
|
|
|
294
285
|
for (const resolved of current) {
|
|
295
286
|
const [currentId, currentName] = resolved
|
|
296
|
-
if (currentId <=
|
|
287
|
+
if (Option.isSome(latest) && currentId <= latest.value.id) {
|
|
297
288
|
continue
|
|
298
289
|
}
|
|
299
290
|
|
package/src/sql/SqlClient.ts
CHANGED
|
@@ -746,16 +746,22 @@ export const makeWithTransaction = <I, S>(options: {
|
|
|
746
746
|
Effect.flatMap(() => {
|
|
747
747
|
const level = [conn, id] as const
|
|
748
748
|
afterCommitBuffers.set(level, buffer)
|
|
749
|
+
const transactionContext = services.pipe(
|
|
750
|
+
Context.add(options.transactionService, level),
|
|
751
|
+
Context.add(CurrentTransactionService, options.transactionService),
|
|
752
|
+
reactivity ? Context.add(Reactivity, deferInvalidations(reactivity)) : identity,
|
|
753
|
+
Context.add(transactionSemaphore, Semaphore.makeUnsafe(1)),
|
|
754
|
+
Context.add(Tracer.ParentSpan, span)
|
|
755
|
+
)
|
|
749
756
|
return Effect.onExitPrimitive(
|
|
750
|
-
Effect.
|
|
757
|
+
Effect.updateContext(
|
|
751
758
|
restore(effect),
|
|
752
|
-
services
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
)
|
|
759
|
+
// `transactionContext` already extends `services`, so merging it
|
|
760
|
+
// into an unchanged fiber context would only copy every service.
|
|
761
|
+
(current: Context.Context<R>) =>
|
|
762
|
+
(current === services
|
|
763
|
+
? transactionContext
|
|
764
|
+
: Context.merge(current, transactionContext)) as Context.Context<R>
|
|
759
765
|
),
|
|
760
766
|
(exit) => {
|
|
761
767
|
buffer.open = false
|
package/src/sql/Statement.ts
CHANGED
|
@@ -168,6 +168,34 @@ export const SpanPropagationEnabled = Context.Reference<boolean>("effect/sql/Spa
|
|
|
168
168
|
defaultValue: () => false
|
|
169
169
|
})
|
|
170
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Context reference for generating the span name used for SQL statement spans.
|
|
173
|
+
*
|
|
174
|
+
* **Details**
|
|
175
|
+
*
|
|
176
|
+
* Defaults to {@link spanName}. Resolved when each statement runs, leaving
|
|
177
|
+
* span attributes such as `db.namespace` and `server.address` unchanged.
|
|
178
|
+
*
|
|
179
|
+
* **Example** (Using a stable statement span name)
|
|
180
|
+
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* import { Effect } from "effect"
|
|
183
|
+
* import { Statement } from "effect/sql"
|
|
184
|
+
*
|
|
185
|
+
* const withStableSpanName = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
|
186
|
+
* Effect.provideService(effect, Statement.SpanNameGenerator, () => "sql.execute")
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @stability unstable
|
|
190
|
+
* @category services
|
|
191
|
+
* @since 4.1.7
|
|
192
|
+
*/
|
|
193
|
+
export const SpanNameGenerator = Context.Reference<
|
|
194
|
+
(spanAttributes: ReadonlyArray<readonly [string, unknown]>) => string
|
|
195
|
+
>("effect/sql/Statement/SpanNameGenerator", {
|
|
196
|
+
defaultValue: () => spanName
|
|
197
|
+
})
|
|
198
|
+
|
|
171
199
|
/**
|
|
172
200
|
* Returns `true` when a value is a SQL `Fragment`.
|
|
173
201
|
*
|
|
@@ -1481,16 +1509,18 @@ const StatementProto: Omit<
|
|
|
1481
1509
|
) => Effect.Effect<XA, E>,
|
|
1482
1510
|
withoutTransform = false
|
|
1483
1511
|
): Effect.Effect<XA, E | SqlError> {
|
|
1484
|
-
return Effect.
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1512
|
+
return Effect.withFiber((fiber) =>
|
|
1513
|
+
Effect.useSpan(
|
|
1514
|
+
fiber.getRef(SpanNameGenerator)(this.spanAttributes),
|
|
1515
|
+
{ kind: "client" },
|
|
1516
|
+
(span) =>
|
|
1517
|
+
this.withConnectionSpan(
|
|
1518
|
+
operation,
|
|
1519
|
+
f,
|
|
1520
|
+
withoutTransform,
|
|
1521
|
+
span
|
|
1522
|
+
)
|
|
1523
|
+
)
|
|
1494
1524
|
)
|
|
1495
1525
|
},
|
|
1496
1526
|
withConnectionSpan<XA, E>(
|
|
@@ -1548,7 +1578,9 @@ const StatementProto: Omit<
|
|
|
1548
1578
|
get stream(): Stream.Stream<any, SqlError> {
|
|
1549
1579
|
const self = this as StatementImpl<any>
|
|
1550
1580
|
return Stream.unwrap(Effect.flatMap(
|
|
1551
|
-
Effect.
|
|
1581
|
+
Effect.withFiber((fiber) =>
|
|
1582
|
+
Effect.makeSpanScoped(fiber.getRef(SpanNameGenerator)(self.spanAttributes), { kind: "client" })
|
|
1583
|
+
),
|
|
1552
1584
|
(span) =>
|
|
1553
1585
|
withStatement(self, span, (statement, fiber) => {
|
|
1554
1586
|
const [sql, params] = statement.compile()
|
|
@@ -1598,7 +1630,11 @@ const StatementProto: Omit<
|
|
|
1598
1630
|
...Effectable.Prototype<StatementImpl<any>>({
|
|
1599
1631
|
label: "Statement",
|
|
1600
1632
|
evaluate(fiber) {
|
|
1601
|
-
const span = internalEffect.makeSpanUnsafe(
|
|
1633
|
+
const span = internalEffect.makeSpanUnsafe(
|
|
1634
|
+
fiber,
|
|
1635
|
+
fiber.getRef(SpanNameGenerator)(this.spanAttributes),
|
|
1636
|
+
{ kind: "client" }
|
|
1637
|
+
)
|
|
1602
1638
|
const clock = fiber.getRef(Clock)
|
|
1603
1639
|
const timingEnabled = fiber.getRef(TracerTimingEnabled)
|
|
1604
1640
|
return Effect.onExit(
|
package/src/workers/Worker.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import * as Context from "../Context.ts"
|
|
15
15
|
import type * as Deferred from "../Deferred.ts"
|
|
16
|
+
import * as Duration from "../Duration.ts"
|
|
16
17
|
import * as Effect from "../Effect.ts"
|
|
17
18
|
import * as FiberSet from "../FiberSet.ts"
|
|
18
19
|
import * as Latch from "../Latch.ts"
|
|
@@ -143,6 +144,30 @@ export const layerSpawner: <W = unknown>(
|
|
|
143
144
|
spawner: SpawnerFn<W>
|
|
144
145
|
) => Layer.Layer<Spawner> = Layer.succeed(Spawner)
|
|
145
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Context reference for how long a closing worker may take to exit before its
|
|
149
|
+
* platform terminates it.
|
|
150
|
+
*
|
|
151
|
+
* **When to use**
|
|
152
|
+
*
|
|
153
|
+
* Use to shorten or lengthen graceful worker shutdown, for example to stop
|
|
154
|
+
* workers well within a process shutdown deadline.
|
|
155
|
+
*
|
|
156
|
+
* **Details**
|
|
157
|
+
*
|
|
158
|
+
* Defaults to 5 seconds. Node and Bun read it when a worker starts running, so
|
|
159
|
+
* provide it where the worker is run or where a worker pool is built. Browser
|
|
160
|
+
* workers are not terminated when closed.
|
|
161
|
+
*
|
|
162
|
+
* @stability unstable
|
|
163
|
+
* @category references
|
|
164
|
+
* @since 4.1.7
|
|
165
|
+
*/
|
|
166
|
+
export const CloseTimeout = Context.Reference<Duration.Duration>(
|
|
167
|
+
"effect/workers/Worker/CloseTimeout",
|
|
168
|
+
{ defaultValue: () => Duration.seconds(5) }
|
|
169
|
+
)
|
|
170
|
+
|
|
146
171
|
/**
|
|
147
172
|
* Creates a `WorkerPlatform` from platform-specific setup and listen hooks,
|
|
148
173
|
* buffering sent messages until the worker is ready and scoping port cleanup to
|
package/src/workflow/Activity.ts
CHANGED
|
@@ -21,6 +21,7 @@ import type { Scope } from "../Scope.ts"
|
|
|
21
21
|
import type * as Types from "../Types.ts"
|
|
22
22
|
import * as DurableDeferred from "./DurableDeferred.ts"
|
|
23
23
|
import { makeHashDigest } from "./internal/crypto.ts"
|
|
24
|
+
import { RetryingExecution } from "./internal/retry.ts"
|
|
24
25
|
import * as Workflow from "./Workflow.ts"
|
|
25
26
|
import type { WorkflowEngine, WorkflowInstance } from "./WorkflowEngine.ts"
|
|
26
27
|
|
|
@@ -220,6 +221,12 @@ const retryOnInterrupt = (
|
|
|
220
221
|
* Retries an effect with `Effect.retry` while updating `CurrentAttempt` for
|
|
221
222
|
* each attempt.
|
|
222
223
|
*
|
|
224
|
+
* **Details**
|
|
225
|
+
*
|
|
226
|
+
* Under `Workflow.SuspendOnFailure`, failed attempts reach the retry policy
|
|
227
|
+
* instead of suspending immediately. If the policy is exhausted and the error
|
|
228
|
+
* escapes, the workflow suspends and `resume` replays the stored failures.
|
|
229
|
+
*
|
|
223
230
|
* @stability unstable
|
|
224
231
|
* @category error handling
|
|
225
232
|
* @since 4.0.0
|
|
@@ -229,6 +236,12 @@ export const retry: {
|
|
|
229
236
|
* Retries an effect with `Effect.retry` while updating `CurrentAttempt` for
|
|
230
237
|
* each attempt.
|
|
231
238
|
*
|
|
239
|
+
* **Details**
|
|
240
|
+
*
|
|
241
|
+
* Under `Workflow.SuspendOnFailure`, failed attempts reach the retry policy
|
|
242
|
+
* instead of suspending immediately. If the policy is exhausted and the error
|
|
243
|
+
* escapes, the workflow suspends and `resume` replays the stored failures.
|
|
244
|
+
*
|
|
232
245
|
* @stability unstable
|
|
233
246
|
* @category error handling
|
|
234
247
|
* @since 4.0.0
|
|
@@ -238,6 +251,12 @@ export const retry: {
|
|
|
238
251
|
* Retries an effect with `Effect.retry` while updating `CurrentAttempt` for
|
|
239
252
|
* each attempt.
|
|
240
253
|
*
|
|
254
|
+
* **Details**
|
|
255
|
+
*
|
|
256
|
+
* Under `Workflow.SuspendOnFailure`, failed attempts reach the retry policy
|
|
257
|
+
* instead of suspending immediately. If the policy is exhausted and the error
|
|
258
|
+
* escapes, the workflow suspends and `resume` replays the stored failures.
|
|
259
|
+
*
|
|
241
260
|
* @stability unstable
|
|
242
261
|
* @category error handling
|
|
243
262
|
* @since 4.0.0
|
|
@@ -246,9 +265,12 @@ export const retry: {
|
|
|
246
265
|
} = dual(
|
|
247
266
|
2,
|
|
248
267
|
(effect: Effect.Effect<any, any, any>, options: {}) =>
|
|
249
|
-
Effect.
|
|
268
|
+
Effect.contextWith((context: Context.Context<never>) => {
|
|
250
269
|
let attempt = 1
|
|
251
|
-
return Effect.suspend(() => Effect.provideService(effect, CurrentAttempt, attempt++)).pipe(
|
|
270
|
+
return Effect.suspend(() => Effect.provideService(effect, CurrentAttempt, attempt++)).pipe(
|
|
271
|
+
Effect.provideService(RetryingExecution, Context.getOrUndefined(context, InstanceTag)?.executionId),
|
|
272
|
+
Effect.retry(options)
|
|
273
|
+
)
|
|
252
274
|
})
|
|
253
275
|
)
|
|
254
276
|
|
|
@@ -343,11 +365,13 @@ const makeExecute = Effect.fnUntraced(function*<
|
|
|
343
365
|
const attempt = yield* CurrentAttempt
|
|
344
366
|
yield* Effect.annotateCurrentSpan({ executionId: instance.executionId })
|
|
345
367
|
const result = yield* Workflow.wrapActivityResult(
|
|
346
|
-
engine.activityExecute(activity, attempt),
|
|
368
|
+
Effect.map(engine.activityExecute(activity, attempt), (result) => {
|
|
369
|
+
if (result._tag === "Suspended" && result.failed) instance.failed = true
|
|
370
|
+
return result
|
|
371
|
+
}),
|
|
347
372
|
(_) => _._tag === "Suspended"
|
|
348
373
|
)
|
|
349
374
|
if (result._tag === "Suspended") {
|
|
350
|
-
if (result.failed) instance.failed = true
|
|
351
375
|
return yield* Workflow.suspend(instance)
|
|
352
376
|
}
|
|
353
377
|
return yield* result.exit
|
package/src/workflow/Workflow.ts
CHANGED
|
@@ -31,6 +31,8 @@ import * as SchemaParser from "../SchemaParser.ts"
|
|
|
31
31
|
import * as Tranformation from "../SchemaTransformation.ts"
|
|
32
32
|
import * as Scope from "../Scope.ts"
|
|
33
33
|
import { makeHashDigest } from "./internal/crypto.ts"
|
|
34
|
+
import { RetryingExecution } from "./internal/retry.ts"
|
|
35
|
+
import { isScopeAbandoned, markScopeAbandoned } from "./internal/scope.ts"
|
|
34
36
|
import type { WorkflowEngine, WorkflowInstance } from "./WorkflowEngine.ts"
|
|
35
37
|
|
|
36
38
|
const TypeId = "~effect/workflow/Workflow"
|
|
@@ -84,18 +86,14 @@ export interface Workflow<
|
|
|
84
86
|
* `discard: true` returns the execution ID without waiting for the result.
|
|
85
87
|
* The child remains linked to its parent for completion wakes and interruption.
|
|
86
88
|
*
|
|
87
|
-
* With `discard: true, detached: true`,
|
|
88
|
-
*
|
|
89
|
-
*
|
|
89
|
+
* With `discard: true, detached: true`, that call does not register the caller
|
|
90
|
+
* for completion wakes or interruption linkage. A later non-detached call for
|
|
91
|
+
* the same execution still registers its caller for a completion wake. The
|
|
92
|
+
* cluster engine retains the parent for observability.
|
|
90
93
|
*
|
|
91
94
|
* Inside a workflow, an awaited child that is interrupted fails the parent
|
|
92
95
|
* with a defect rather than an interrupt, so the parent can recover with
|
|
93
96
|
* `Effect.catchDefect` or `Effect.exit`.
|
|
94
|
-
*
|
|
95
|
-
* **Gotchas**
|
|
96
|
-
*
|
|
97
|
-
* Do not await a detached execution later. Executing the same payload joins
|
|
98
|
-
* it, but its completion will not wake the awaiting workflow.
|
|
99
97
|
*/
|
|
100
98
|
readonly execute: <const Discard extends boolean = false>(
|
|
101
99
|
payload: Payload["~type.make.in"],
|
|
@@ -375,7 +373,9 @@ const Proto = {
|
|
|
375
373
|
) {
|
|
376
374
|
return Effect.suspend(() => {
|
|
377
375
|
const payload = this.payloadSchema.make(fields)
|
|
378
|
-
|
|
376
|
+
// Register with the parent before the execution id is computed, so a
|
|
377
|
+
// sibling that suspends first waits for this child to be dispatched.
|
|
378
|
+
return withPendingActivity(Effect.flatMap(
|
|
379
379
|
EngineTag,
|
|
380
380
|
(engine) =>
|
|
381
381
|
Effect.flatMap(makeExecutionIdFromPayload(this, payload), (executionId) =>
|
|
@@ -389,10 +389,7 @@ const Proto = {
|
|
|
389
389
|
suspendedRetrySchedule: this.suspendedRetrySchedule
|
|
390
390
|
})
|
|
391
391
|
))
|
|
392
|
-
)
|
|
393
|
-
// Register with the parent before the execution id is computed, so a
|
|
394
|
-
// sibling that suspends first waits for this child to be dispatched.
|
|
395
|
-
return opts?.discard ? run : withPendingActivity(run)
|
|
392
|
+
))
|
|
396
393
|
}).pipe(
|
|
397
394
|
Effect.withSpan(
|
|
398
395
|
`${this._tag}.execute`,
|
|
@@ -715,7 +712,9 @@ export const intoResult = <A, E, R>(
|
|
|
715
712
|
Effect.contextWith((context: Context.Context<WorkflowInstance>) => {
|
|
716
713
|
const instance = Context.get(context, InstanceTag)
|
|
717
714
|
const captureDefects = Context.get(instance.workflow.annotations, CaptureDefects)
|
|
718
|
-
|
|
715
|
+
// Inside `Activity.retry` a failure goes to the retry policy instead.
|
|
716
|
+
const suspendOnFailure = Context.get(instance.workflow.annotations, SuspendOnFailure) &&
|
|
717
|
+
Context.get(context, RetryingExecution) !== instance.executionId
|
|
719
718
|
return effect.pipe(
|
|
720
719
|
Effect.forkChild({ startImmediately: true }),
|
|
721
720
|
// The outer uninterruptible region protects the fork and cancellation hook.
|
|
@@ -749,6 +748,11 @@ export const intoResult = <A, E, R>(
|
|
|
749
748
|
const filtered = reasons.length === 0 ? cause : Cause.fromReasons(reasons)
|
|
750
749
|
const abandoned = instance.abandoned && !instance.interrupted && hasInterruptsOnly
|
|
751
750
|
instance.abandoned = abandoned
|
|
751
|
+
if (abandoned) {
|
|
752
|
+
// Superseded instances can share this scope, which closes before
|
|
753
|
+
// the engine marks its parent.
|
|
754
|
+
markScopeAbandoned(instance.scope)
|
|
755
|
+
}
|
|
752
756
|
if (instance.suspended && hasInterruptsOnly && !abandoned) {
|
|
753
757
|
return Effect.succeed(
|
|
754
758
|
new Suspended(instance.failed ? { cause: instance.cause, failed: true } : { cause: instance.cause })
|
|
@@ -767,14 +771,27 @@ export const intoResult = <A, E, R>(
|
|
|
767
771
|
}
|
|
768
772
|
}),
|
|
769
773
|
(eff) =>
|
|
770
|
-
Effect.onExitPrimitive(
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
774
|
+
Effect.onExitPrimitive(
|
|
775
|
+
eff,
|
|
776
|
+
(exit) => Exit.isFailure(exit) ? Scope.close(instance.scope, exit) : undefined,
|
|
777
|
+
true
|
|
778
|
+
),
|
|
779
|
+
Effect.flatMap((result): Effect.Effect<Result<A, E>> => {
|
|
780
|
+
if (result._tag !== "Complete") {
|
|
781
|
+
return Effect.succeed(result)
|
|
782
|
+
}
|
|
783
|
+
const close = Effect.as(Scope.close(instance.scope, result.exit), result)
|
|
784
|
+
return captureDefects
|
|
785
|
+
? Effect.catchCauseIf(close, Cause.hasDies, (closeCause) =>
|
|
786
|
+
Effect.succeed(
|
|
787
|
+
new Complete({
|
|
788
|
+
exit: Exit.failCause(
|
|
789
|
+
Exit.isFailure(result.exit) ? Cause.combine(result.exit.cause, closeCause) : closeCause
|
|
790
|
+
)
|
|
791
|
+
})
|
|
792
|
+
))
|
|
793
|
+
: close
|
|
794
|
+
}),
|
|
778
795
|
Effect.uninterruptible
|
|
779
796
|
)
|
|
780
797
|
})
|
|
@@ -796,23 +813,22 @@ export const wrapActivityResult = <A, E, R>(
|
|
|
796
813
|
return Effect.acquireUseRelease(
|
|
797
814
|
Effect.sync(() => adoptActivityUnsafe(context, instance) ?? registerActivityUnsafe(instance)),
|
|
798
815
|
() => effect,
|
|
799
|
-
(registration, exit) =>
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
+
(registration, exit) =>
|
|
817
|
+
Effect.sync(() => {
|
|
818
|
+
releaseActivityUnsafe(registration)
|
|
819
|
+
if (
|
|
820
|
+
Exit.isSuccess(exit) &&
|
|
821
|
+
isResult(exit.value) &&
|
|
822
|
+
exit.value._tag === "Suspended" &&
|
|
823
|
+
exit.value.cause
|
|
824
|
+
) {
|
|
825
|
+
instance.cause = instance.cause
|
|
826
|
+
? Cause.combine(instance.cause, exit.value.cause)
|
|
827
|
+
: exit.value.cause
|
|
828
|
+
}
|
|
829
|
+
})
|
|
830
|
+
).pipe(
|
|
831
|
+
Effect.tap((value) => isSuspend(value) ? waitForZero(instance) : Effect.void)
|
|
816
832
|
)
|
|
817
833
|
})
|
|
818
834
|
|
|
@@ -856,9 +872,9 @@ const releaseActivityUnsafe = (registration: ActivityRegistration) => {
|
|
|
856
872
|
}
|
|
857
873
|
|
|
858
874
|
/**
|
|
859
|
-
* Registers a pending child workflow
|
|
860
|
-
*
|
|
861
|
-
*
|
|
875
|
+
* Registers a pending child workflow with the current instance before async
|
|
876
|
+
* work runs. Awaited starts are adopted by `wrapActivityResult`; discarded
|
|
877
|
+
* starts release when dispatch returns.
|
|
862
878
|
*/
|
|
863
879
|
const withPendingActivity = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
|
|
864
880
|
Effect.contextWith((context: Context.Context<never>) => {
|
|
@@ -941,7 +957,10 @@ export const addFinalizer: <R>(
|
|
|
941
957
|
const services = yield* Effect.context<R>()
|
|
942
958
|
yield* Scope.addFinalizerExit(
|
|
943
959
|
instance.scope,
|
|
944
|
-
(exit) =>
|
|
960
|
+
(exit) =>
|
|
961
|
+
instance.abandoned || isScopeAbandoned(instance.scope)
|
|
962
|
+
? Effect.void
|
|
963
|
+
: Effect.provideContext(f(exit), services)
|
|
945
964
|
)
|
|
946
965
|
})
|
|
947
966
|
|
|
@@ -1064,7 +1083,12 @@ export const CaptureDefects = Context.Reference<boolean>(
|
|
|
1064
1083
|
*
|
|
1065
1084
|
* **Details**
|
|
1066
1085
|
*
|
|
1067
|
-
* The suspended execution can later be resumed with the workflow's `resume`
|
|
1086
|
+
* The suspended execution can later be resumed with the workflow's `resume`
|
|
1087
|
+
* method, for example `MyWorkflow.resume(executionId)`.
|
|
1088
|
+
*
|
|
1089
|
+
* Inside `Activity.retry`, failed attempts reach the retry policy instead of
|
|
1090
|
+
* suspending immediately; if the policy is exhausted and the error escapes,
|
|
1091
|
+
* the workflow suspends and `resume` replays the stored failures.
|
|
1068
1092
|
*
|
|
1069
1093
|
* @stability unstable
|
|
1070
1094
|
* @category services
|