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/SchemaAST.ts
CHANGED
|
@@ -717,6 +717,14 @@ abstract class ASTNodeImpl implements ASTNode {
|
|
|
717
717
|
}
|
|
718
718
|
}
|
|
719
719
|
|
|
720
|
+
function flipChecks<A extends Declaration | Arrays | Objects | Union>(ast: A): A {
|
|
721
|
+
return ast.checks === ast.encodingChecks ? ast : copy(ast, {
|
|
722
|
+
checks: ast.encodingChecks,
|
|
723
|
+
encodingChecks: ast.checks,
|
|
724
|
+
encoding: undefined
|
|
725
|
+
})
|
|
726
|
+
}
|
|
727
|
+
|
|
720
728
|
type DeclarationRun = (
|
|
721
729
|
typeParameters: ReadonlyArray<AST>
|
|
722
730
|
) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue>
|
|
@@ -823,26 +831,19 @@ export const Declaration: new(
|
|
|
823
831
|
}
|
|
824
832
|
}
|
|
825
833
|
}
|
|
826
|
-
private _rebuild(
|
|
827
|
-
recur: (ast: AST) => AST,
|
|
828
|
-
checks: Checks | undefined,
|
|
829
|
-
encodingChecks: Checks | undefined,
|
|
830
|
-
run: DeclarationRun,
|
|
831
|
-
encodingRun: DeclarationRun | undefined
|
|
832
|
-
) {
|
|
833
|
-
const tps = mapOrSame(this.typeParameters, recur)
|
|
834
|
-
return tps === this.typeParameters && checks === this.checks && encodingChecks === this.encodingChecks &&
|
|
835
|
-
run === this.run && encodingRun === this.encodingRun ?
|
|
836
|
-
this :
|
|
837
|
-
new Declaration(tps, run, this.annotations, checks, undefined, this.context, encodingChecks, encodingRun)
|
|
838
|
-
}
|
|
839
834
|
/** @internal */
|
|
840
|
-
recur(recur: (ast: AST) => AST) {
|
|
841
|
-
|
|
835
|
+
recur(recur: (ast: AST) => AST): Declaration {
|
|
836
|
+
const typeParameters = mapOrSame(this.typeParameters, recur)
|
|
837
|
+
return typeParameters === this.typeParameters ? this : copy(this, { typeParameters, encoding: undefined })
|
|
842
838
|
}
|
|
843
839
|
/** @internal */
|
|
844
|
-
flip(recur: (ast: AST) => AST) {
|
|
845
|
-
|
|
840
|
+
flip(recur: (ast: AST) => AST): Declaration {
|
|
841
|
+
const out = flipChecks(this.recur(recur))
|
|
842
|
+
return this.run === this.encodingRun ? out : copy(out, {
|
|
843
|
+
run: this.encodingRun ?? this.run,
|
|
844
|
+
encodingRun: this.run,
|
|
845
|
+
encoding: undefined
|
|
846
|
+
})
|
|
846
847
|
}
|
|
847
848
|
/** @internal */
|
|
848
849
|
getExpected(): string {
|
|
@@ -2486,30 +2487,26 @@ export const Arrays: new(
|
|
|
2486
2487
|
}
|
|
2487
2488
|
}
|
|
2488
2489
|
}
|
|
2489
|
-
|
|
2490
|
+
/** @internal */
|
|
2491
|
+
recur(recur: (ast: AST) => AST): Arrays {
|
|
2490
2492
|
const elements = mapOrSame(this.elements, recur)
|
|
2491
2493
|
const rest = mapOrSame(this.rest, recur)
|
|
2492
|
-
return elements === this.elements && rest === this.rest
|
|
2493
|
-
encodingChecks === this.encodingChecks ?
|
|
2494
|
+
return elements === this.elements && rest === this.rest ?
|
|
2494
2495
|
this :
|
|
2495
2496
|
new Arrays(
|
|
2496
2497
|
this.isMutable,
|
|
2497
2498
|
elements,
|
|
2498
2499
|
rest,
|
|
2499
2500
|
this.annotations,
|
|
2500
|
-
checks,
|
|
2501
|
+
this.checks,
|
|
2501
2502
|
undefined,
|
|
2502
2503
|
this.context,
|
|
2503
|
-
encodingChecks
|
|
2504
|
+
this.encodingChecks
|
|
2504
2505
|
)
|
|
2505
2506
|
}
|
|
2506
2507
|
/** @internal */
|
|
2507
|
-
|
|
2508
|
-
return this.
|
|
2509
|
-
}
|
|
2510
|
-
/** @internal */
|
|
2511
|
-
flip(recur: (ast: AST) => AST) {
|
|
2512
|
-
return this._rebuild(recur, this.encodingChecks, this.checks)
|
|
2508
|
+
flip(recur: (ast: AST) => AST): Arrays {
|
|
2509
|
+
return flipChecks(this.recur(recur))
|
|
2513
2510
|
}
|
|
2514
2511
|
/** @internal */
|
|
2515
2512
|
getExpected(): string {
|
|
@@ -3181,12 +3178,8 @@ export const Objects: new(
|
|
|
3181
3178
|
return InternalParser.succeed(out)
|
|
3182
3179
|
}
|
|
3183
3180
|
}
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
recurParameter: (ast: AST) => AST,
|
|
3187
|
-
checks: Checks | undefined,
|
|
3188
|
-
encodingChecks: Checks | undefined
|
|
3189
|
-
): Objects {
|
|
3181
|
+
/** @internal */
|
|
3182
|
+
recur(recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST = recur): Objects {
|
|
3190
3183
|
const props = mapOrSame(this.propertySignatures, (ps) => {
|
|
3191
3184
|
const t = recur(ps.type)
|
|
3192
3185
|
return t === ps.type ? ps : new PropertySignature(ps.name, t)
|
|
@@ -3200,26 +3193,13 @@ export const Objects: new(
|
|
|
3200
3193
|
: new IndexSignature(p, t)
|
|
3201
3194
|
})
|
|
3202
3195
|
|
|
3203
|
-
return props === this.propertySignatures && indexes === this.indexSignatures
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
: new Objects(
|
|
3207
|
-
props,
|
|
3208
|
-
indexes,
|
|
3209
|
-
this.annotations,
|
|
3210
|
-
checks,
|
|
3211
|
-
undefined,
|
|
3212
|
-
this.context,
|
|
3213
|
-
encodingChecks
|
|
3214
|
-
)
|
|
3215
|
-
}
|
|
3216
|
-
/** @internal */
|
|
3217
|
-
flip(recur: (ast: AST) => AST): AST {
|
|
3218
|
-
return this._rebuild(recur, recur, this.encodingChecks, this.checks)
|
|
3196
|
+
return props === this.propertySignatures && indexes === this.indexSignatures ?
|
|
3197
|
+
this :
|
|
3198
|
+
copy(this, { propertySignatures: props, indexSignatures: indexes, encoding: undefined })
|
|
3219
3199
|
}
|
|
3220
3200
|
/** @internal */
|
|
3221
|
-
|
|
3222
|
-
return this.
|
|
3201
|
+
flip(recur: (ast: AST) => AST): Objects {
|
|
3202
|
+
return flipChecks(this.recur(recur))
|
|
3223
3203
|
}
|
|
3224
3204
|
/** @internal */
|
|
3225
3205
|
getExpected(): string {
|
|
@@ -3814,23 +3794,14 @@ export const Union: new<A extends AST = AST>(
|
|
|
3814
3794
|
return parseUnionCandidates(ast, parser, candidates, input, options)
|
|
3815
3795
|
}
|
|
3816
3796
|
}
|
|
3817
|
-
private _rebuild(
|
|
3818
|
-
recur: (ast: AST) => AST,
|
|
3819
|
-
checks: Checks | undefined,
|
|
3820
|
-
encodingChecks: Checks | undefined
|
|
3821
|
-
): Union<AST> {
|
|
3822
|
-
const types = mapOrSame(this.types, recur)
|
|
3823
|
-
return types === this.types && checks === this.checks && encodingChecks === this.encodingChecks ?
|
|
3824
|
-
this :
|
|
3825
|
-
new Union(types, this.options, this.annotations, checks, undefined, this.context, encodingChecks)
|
|
3826
|
-
}
|
|
3827
3797
|
/** @internal */
|
|
3828
3798
|
recur(recur: (ast: AST) => AST): Union<AST> {
|
|
3829
|
-
|
|
3799
|
+
const types = mapOrSame(this.types, recur)
|
|
3800
|
+
return types === this.types ? this : copy<Union<AST>>(this, { types, encoding: undefined })
|
|
3830
3801
|
}
|
|
3831
3802
|
/** @internal */
|
|
3832
3803
|
flip(recur: (ast: AST) => AST): Union<AST> {
|
|
3833
|
-
return this.
|
|
3804
|
+
return flipChecks(this.recur(recur))
|
|
3834
3805
|
}
|
|
3835
3806
|
/** @internal */
|
|
3836
3807
|
matchPart(s: string, options: ParseOptions): LiteralValue | undefined {
|
|
@@ -4065,8 +4036,7 @@ export const Suspend: new(
|
|
|
4065
4036
|
throw new Error("Cannot add checks to Suspend")
|
|
4066
4037
|
}
|
|
4067
4038
|
super(annotations, undefined, encoding, context)
|
|
4068
|
-
|
|
4069
|
-
this.thunk = () => ast ??= thunk()
|
|
4039
|
+
this.thunk = memoizeThunk(thunk)
|
|
4070
4040
|
}
|
|
4071
4041
|
/** @internal */
|
|
4072
4042
|
getParser(compile: SchemaParser.Compiler): SchemaParser.Parser {
|
|
@@ -4089,6 +4059,11 @@ export const Suspend: new(
|
|
|
4089
4059
|
}
|
|
4090
4060
|
}
|
|
4091
4061
|
|
|
4062
|
+
function memoizeThunk(thunk: Suspend["thunk"]): Suspend["thunk"] {
|
|
4063
|
+
let ast: AST
|
|
4064
|
+
return () => ast ??= thunk()
|
|
4065
|
+
}
|
|
4066
|
+
|
|
4092
4067
|
// -----------------------------------------------------------------------------
|
|
4093
4068
|
// Checks
|
|
4094
4069
|
// -----------------------------------------------------------------------------
|
|
@@ -4288,7 +4263,6 @@ export function isFinite(annotations?: Schema.Annotations.Filter) {
|
|
|
4288
4263
|
payload: null
|
|
4289
4264
|
},
|
|
4290
4265
|
toJsonSchema: () => ({ type: "number" }),
|
|
4291
|
-
toCode: () => ({ runtime: "Schema.isFinite()" }),
|
|
4292
4266
|
arbitraryConstraint: {
|
|
4293
4267
|
number: "finite"
|
|
4294
4268
|
},
|
|
@@ -4379,11 +4353,12 @@ export function isPattern(regExp: globalThis.RegExp, annotations?: Schema.Annota
|
|
|
4379
4353
|
const bodyOwners = new WeakMap<AST, AST>()
|
|
4380
4354
|
|
|
4381
4355
|
function copy<A extends AST>(ast: A, changes: Partial<AST>): A {
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4356
|
+
return Object.assign(Object.create(Object.getPrototypeOf(ast)), ast, changes) as A
|
|
4357
|
+
}
|
|
4358
|
+
|
|
4359
|
+
function copyBody<A extends AST>(ast: A, changes: Pick<Partial<AST>, "context" | "encoding">): A {
|
|
4360
|
+
const out = copy(ast, changes)
|
|
4361
|
+
bodyOwners.set(out, getContextOwner(ast))
|
|
4387
4362
|
return out
|
|
4388
4363
|
}
|
|
4389
4364
|
|
|
@@ -4393,14 +4368,14 @@ export function getContextOwner<A extends AST>(ast: A): A {
|
|
|
4393
4368
|
if (existing !== undefined) return existing as A
|
|
4394
4369
|
if (ast.encoding === undefined) return ast
|
|
4395
4370
|
// A body representative must not expose or retain the node's own codec.
|
|
4396
|
-
const owner =
|
|
4371
|
+
const owner = copy(ast, { encoding: undefined })
|
|
4397
4372
|
bodyOwners.set(ast, owner)
|
|
4398
4373
|
return owner
|
|
4399
4374
|
}
|
|
4400
4375
|
|
|
4401
4376
|
/** @internal */
|
|
4402
4377
|
export function replaceEncoding<A extends AST>(ast: A, encoding: Encoding | undefined): A {
|
|
4403
|
-
return ast.encoding === encoding ? ast :
|
|
4378
|
+
return ast.encoding === encoding ? ast : copyBody(ast, { encoding })
|
|
4404
4379
|
}
|
|
4405
4380
|
|
|
4406
4381
|
/** @internal */
|
|
@@ -4412,7 +4387,7 @@ export function replaceContext<A extends AST>(ast: A, context: Context | undefin
|
|
|
4412
4387
|
if (owner.context === context && owner.encoding === ast.encoding) {
|
|
4413
4388
|
return owner
|
|
4414
4389
|
}
|
|
4415
|
-
return
|
|
4390
|
+
return copyBody(ast, { context })
|
|
4416
4391
|
}
|
|
4417
4392
|
|
|
4418
4393
|
/** @internal */
|
|
@@ -4423,8 +4398,7 @@ export function getLastEncoding(ast: AST): AST {
|
|
|
4423
4398
|
/** @internal */
|
|
4424
4399
|
export function annotate<A extends AST>(ast: A, annotations: Schema.Annotations.Annotations): A {
|
|
4425
4400
|
if (ast.checks) {
|
|
4426
|
-
|
|
4427
|
-
return replaceChecks(ast, Arr.append(ast.checks.slice(0, -1), last.annotate(annotations)))
|
|
4401
|
+
return replaceChecks(ast, mapLast(ast.checks, (check) => check.annotate(annotations)))
|
|
4428
4402
|
}
|
|
4429
4403
|
return copy(ast, { annotations: { ...ast.annotations, ...annotations } })
|
|
4430
4404
|
}
|
|
@@ -4451,11 +4425,17 @@ export function mapLink(link: Link, f: (ast: AST) => AST): Link {
|
|
|
4451
4425
|
return to === link.to ? link : new Link(to, link.transformation)
|
|
4452
4426
|
}
|
|
4453
4427
|
|
|
4428
|
+
function mapLast<A>(items: readonly [A, ...Array<A>], f: (item: A) => A): readonly [A, ...Array<A>] {
|
|
4429
|
+
const last = items[items.length - 1]
|
|
4430
|
+
const out = f(last)
|
|
4431
|
+
if (last === out) return items
|
|
4432
|
+
const copy: [A, ...Array<A>] = [...items]
|
|
4433
|
+
copy[copy.length - 1] = out
|
|
4434
|
+
return copy
|
|
4435
|
+
}
|
|
4436
|
+
|
|
4454
4437
|
function updateLastLink(encoding: Encoding, f: (ast: AST) => AST): Encoding {
|
|
4455
|
-
|
|
4456
|
-
const last = links[links.length - 1]
|
|
4457
|
-
const out = mapLink(last, f)
|
|
4458
|
-
return out === last ? encoding : Arr.append(encoding.slice(0, encoding.length - 1), out)
|
|
4438
|
+
return mapLast(encoding, (link) => mapLink(link, f))
|
|
4459
4439
|
}
|
|
4460
4440
|
|
|
4461
4441
|
/** @internal */
|
|
@@ -4542,30 +4522,39 @@ export function mapOrSame<A>(as: ReadonlyArray<A>, f: (a: A) => A): ReadonlyArra
|
|
|
4542
4522
|
return out ?? as
|
|
4543
4523
|
}
|
|
4544
4524
|
|
|
4525
|
+
function updateContext<A extends AST>(
|
|
4526
|
+
ast: A,
|
|
4527
|
+
optional = isOptional(ast),
|
|
4528
|
+
mutable = isMutable(ast),
|
|
4529
|
+
constructorDefault = ast.context?.constructorDefault,
|
|
4530
|
+
annotations = ast.context?.annotations
|
|
4531
|
+
): A {
|
|
4532
|
+
return replaceContext(ast, new Context(optional, mutable, constructorDefault, annotations))
|
|
4533
|
+
}
|
|
4534
|
+
|
|
4535
|
+
function setContextFlag(key: "isOptional" | "isMutable") {
|
|
4536
|
+
const optional = key === "isOptional" ? true : undefined
|
|
4537
|
+
const mutable = key === "isMutable" ? true : undefined
|
|
4538
|
+
const set: <A extends AST>(ast: A) => A = memoizeIdempotent(<A extends AST>(ast: A): A =>
|
|
4539
|
+
last(ast.context?.[key] ? ast : updateContext(ast, optional, mutable))
|
|
4540
|
+
)
|
|
4541
|
+
const last = applyToLastLink(set)
|
|
4542
|
+
return set
|
|
4543
|
+
}
|
|
4544
|
+
|
|
4545
4545
|
/** @internal */
|
|
4546
4546
|
export function annotateKey<A extends AST>(ast: A, annotations: Schema.Annotations.Key<unknown>): A {
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
new Context(false, false, undefined, annotations)
|
|
4555
|
-
return replaceContext(ast, context)
|
|
4547
|
+
return updateContext(
|
|
4548
|
+
ast,
|
|
4549
|
+
undefined,
|
|
4550
|
+
undefined,
|
|
4551
|
+
undefined,
|
|
4552
|
+
ast.context ? { ...ast.context.annotations, ...annotations } : annotations
|
|
4553
|
+
)
|
|
4556
4554
|
}
|
|
4557
4555
|
|
|
4558
4556
|
/** @internal */
|
|
4559
|
-
export const optionalKey: <A extends AST>(ast: A) => A =
|
|
4560
|
-
const context = ast.context ?
|
|
4561
|
-
ast.context.isOptional === false ?
|
|
4562
|
-
new Context(true, ast.context.isMutable, ast.context.constructorDefault, ast.context.annotations) :
|
|
4563
|
-
ast.context :
|
|
4564
|
-
new Context(true, false)
|
|
4565
|
-
return optionalKeyLastLink(replaceContext(ast, context))
|
|
4566
|
-
})
|
|
4567
|
-
|
|
4568
|
-
const optionalKeyLastLink = applyToLastLink(optionalKey)
|
|
4557
|
+
export const optionalKey: <A extends AST>(ast: A) => A = setContextFlag("isOptional")
|
|
4569
4558
|
|
|
4570
4559
|
/** @internal */
|
|
4571
4560
|
export const optional = memoize(<A extends AST>(ast: A): Union<A | Undefined> =>
|
|
@@ -4573,26 +4562,14 @@ export const optional = memoize(<A extends AST>(ast: A): Union<A | Undefined> =>
|
|
|
4573
4562
|
)
|
|
4574
4563
|
|
|
4575
4564
|
/** @internal */
|
|
4576
|
-
export const mutableKey =
|
|
4577
|
-
const context = ast.context ?
|
|
4578
|
-
ast.context.isMutable === false ?
|
|
4579
|
-
new Context(ast.context.isOptional, true, ast.context.constructorDefault, ast.context.annotations) :
|
|
4580
|
-
ast.context :
|
|
4581
|
-
new Context(false, true)
|
|
4582
|
-
return mutableKeyLastLink(replaceContext(ast, context))
|
|
4583
|
-
})
|
|
4584
|
-
|
|
4585
|
-
const mutableKeyLastLink = applyToLastLink(mutableKey)
|
|
4565
|
+
export const mutableKey = setContextFlag("isMutable")
|
|
4586
4566
|
|
|
4587
4567
|
/** @internal */
|
|
4588
4568
|
export function withConstructorDefault<A extends AST>(
|
|
4589
4569
|
ast: A,
|
|
4590
4570
|
defaultValue: Effect.Effect<unknown, SchemaIssue.Issue>
|
|
4591
4571
|
): A {
|
|
4592
|
-
|
|
4593
|
-
new Context(ast.context.isOptional, ast.context.isMutable, defaultValue, ast.context.annotations) :
|
|
4594
|
-
new Context(false, false, defaultValue)
|
|
4595
|
-
return replaceContext(ast, context)
|
|
4572
|
+
return updateContext(ast, undefined, undefined, defaultValue)
|
|
4596
4573
|
}
|
|
4597
4574
|
|
|
4598
4575
|
/**
|
|
@@ -4712,17 +4689,64 @@ function extractStructuralChecks(checks: Checks): Checks | undefined {
|
|
|
4712
4689
|
return Arr.isArrayNonEmpty(out) ? out : undefined
|
|
4713
4690
|
}
|
|
4714
4691
|
|
|
4715
|
-
|
|
4716
|
-
|
|
4692
|
+
// Suspensions are leaves in this walk. Only resolving a suspension may call its thunk.
|
|
4693
|
+
function everyNode(root: AST, predicate: (ast: AST) => boolean, proven?: WeakSet<AST>): boolean {
|
|
4694
|
+
const nodes = new Set([root])
|
|
4695
|
+
for (const ast of nodes) {
|
|
4696
|
+
if (proven?.has(ast)) continue
|
|
4697
|
+
if (!predicate(ast)) return false
|
|
4698
|
+
if (!isSuspend(ast) && "recur" in ast) ast.recur(visit)
|
|
4699
|
+
}
|
|
4700
|
+
if (proven) {
|
|
4701
|
+
for (const ast of nodes) {
|
|
4702
|
+
proven.add(ast)
|
|
4703
|
+
}
|
|
4704
|
+
}
|
|
4705
|
+
return true
|
|
4706
|
+
|
|
4717
4707
|
function visit(child: AST): AST {
|
|
4718
|
-
|
|
4719
|
-
if (preserve && "recur" in child) child.recur(visit)
|
|
4708
|
+
nodes.add(child)
|
|
4720
4709
|
return child
|
|
4721
4710
|
}
|
|
4722
|
-
if ("recur" in ast) ast.recur(visit)
|
|
4723
|
-
return preserve
|
|
4724
4711
|
}
|
|
4725
4712
|
|
|
4713
|
+
const preservesShape = new WeakSet<AST>()
|
|
4714
|
+
|
|
4715
|
+
function projectChecks(ast: AST, checks: Checks): Checks | undefined {
|
|
4716
|
+
const structural = isArrays(ast) || isObjects(ast) || isDeclaration(ast) && ast.typeParameters.length > 0
|
|
4717
|
+
if (
|
|
4718
|
+
structural && checks.every(isStructuralCheck) ||
|
|
4719
|
+
everyNode(ast, (node) => !node.encoding && !isSuspend(node), preservesShape)
|
|
4720
|
+
) {
|
|
4721
|
+
return checks
|
|
4722
|
+
}
|
|
4723
|
+
if (structural) return extractStructuralChecks(checks)
|
|
4724
|
+
}
|
|
4725
|
+
|
|
4726
|
+
function hasDirectionalParser(ast: AST): boolean {
|
|
4727
|
+
return isDeclaration(ast) && ast.encodingRun !== undefined && ast.encodingRun !== ast.run
|
|
4728
|
+
}
|
|
4729
|
+
|
|
4730
|
+
function canReuse(root: AST, edge: Suspend["thunk"]): boolean {
|
|
4731
|
+
function same(ast: AST): boolean {
|
|
4732
|
+
if (isSuspend(ast)) return ast.thunk === edge
|
|
4733
|
+
return !hasDirectionalParser(ast) &&
|
|
4734
|
+
!("encodingChecks" in ast && ast.checks && projectChecks(ast, ast.checks) !== ast.checks)
|
|
4735
|
+
}
|
|
4736
|
+
return everyNode(root, same)
|
|
4737
|
+
}
|
|
4738
|
+
|
|
4739
|
+
const types = new WeakMap<AST, AST>()
|
|
4740
|
+
const reversed = new WeakMap<AST, AST>()
|
|
4741
|
+
const encoded = new WeakSet<AST>()
|
|
4742
|
+
const reprojected = new WeakSet<AST>()
|
|
4743
|
+
const flippedFrom = new WeakMap<AST, AST>()
|
|
4744
|
+
interface FlippedSuspension {
|
|
4745
|
+
readonly source: Suspend
|
|
4746
|
+
project(ast: Suspend): Suspend
|
|
4747
|
+
}
|
|
4748
|
+
const flippedThunks = new WeakMap<Suspend["thunk"], FlippedSuspension>()
|
|
4749
|
+
|
|
4726
4750
|
/**
|
|
4727
4751
|
* Strips all encoding transformations from an AST, returning the decoded
|
|
4728
4752
|
* (type-level) representation.
|
|
@@ -4749,27 +4773,52 @@ function canPreserveEncodingChecks(ast: AST): boolean {
|
|
|
4749
4773
|
* @category transforming
|
|
4750
4774
|
* @since 4.0.0
|
|
4751
4775
|
*/
|
|
4752
|
-
export const toType =
|
|
4776
|
+
export const toType = <A extends AST>(ast: A): A => flippedFrom.has(ast) ? toFlippedType(ast) : stripEncoding(ast)
|
|
4777
|
+
|
|
4778
|
+
const toFlippedType = memoize(<A extends AST>(ast: A): A => {
|
|
4779
|
+
const source = flippedFrom.get(ast)
|
|
4780
|
+
// The public encoded projection is idempotent, including when requested as toType(flip(ast)).
|
|
4781
|
+
if (source && encoded.has(source)) return source as A
|
|
4782
|
+
const out = stripEncoding(ast)
|
|
4783
|
+
if (source) encoded.add(out)
|
|
4784
|
+
return out
|
|
4785
|
+
})
|
|
4786
|
+
|
|
4787
|
+
function stripEncoding<A extends AST>(ast: A): A {
|
|
4788
|
+
const cached = types.get(ast)
|
|
4789
|
+
if (cached) return cached as A
|
|
4790
|
+
const source = flippedFrom.get(ast)
|
|
4791
|
+
const wasProjected = source && types.get(source) === source
|
|
4792
|
+
const out = source && reversed.get(source) || projectType(ast)
|
|
4793
|
+
if (wasProjected) reversed.set(source, out)
|
|
4794
|
+
types.set(ast, out)
|
|
4795
|
+
// Projected nodes map to themselves, so the cache also identifies completed projections.
|
|
4796
|
+
if (out !== ast) types.set(out, out)
|
|
4797
|
+
return out as A
|
|
4798
|
+
}
|
|
4799
|
+
|
|
4800
|
+
function projectOwner<A extends AST>(ast: A, project: (ast: A) => AST): A | undefined {
|
|
4753
4801
|
const owner = getContextOwner(ast)
|
|
4754
4802
|
if (owner !== ast) {
|
|
4755
|
-
const
|
|
4756
|
-
return
|
|
4803
|
+
const out = project(owner)
|
|
4804
|
+
return out === owner && !ast.encoding ? ast : replaceContext(out, ast.context) as A
|
|
4757
4805
|
}
|
|
4758
|
-
|
|
4806
|
+
}
|
|
4807
|
+
|
|
4808
|
+
function projectType<A extends AST>(ast: A): A {
|
|
4809
|
+
const owned = projectOwner(ast, stripEncoding)
|
|
4810
|
+
if (owned) return owned
|
|
4811
|
+
if (isSuspend(ast)) return (flippedThunks.get(ast.thunk)?.project(ast) ?? ast.recur(stripEncoding)) as A
|
|
4812
|
+
const type = ("recur" in ast ? ast.recur(stripEncoding) : ast) as A
|
|
4759
4813
|
if ("encodingChecks" in type && type.encodingChecks) {
|
|
4760
|
-
const checks = canPreserveEncodingChecks(ast)
|
|
4761
|
-
? type.encodingChecks
|
|
4762
|
-
: isArrays(type) || isObjects(type) || isDeclaration(type) && type.typeParameters.length > 0
|
|
4763
|
-
? extractStructuralChecks(type.encodingChecks)
|
|
4764
|
-
: undefined
|
|
4765
4814
|
return copy(type, {
|
|
4766
4815
|
encodingChecks: undefined,
|
|
4767
|
-
|
|
4768
|
-
checks: combineChecks(checks, type.checks)
|
|
4816
|
+
checks: combineChecks(projectChecks(ast, type.encodingChecks), type.checks)
|
|
4769
4817
|
})
|
|
4770
4818
|
}
|
|
4771
|
-
|
|
4772
|
-
})
|
|
4819
|
+
// A flipped declaration and its encoded projection need distinct reverse parsers.
|
|
4820
|
+
return type === ast && hasDirectionalParser(type) && flippedFrom.has(ast) ? copy(type, {}) : type
|
|
4821
|
+
}
|
|
4773
4822
|
|
|
4774
4823
|
/**
|
|
4775
4824
|
* Returns the encoded (wire-format) AST by flipping and then stripping
|
|
@@ -4798,26 +4847,17 @@ export const toType = memoizeIdempotent(<A extends AST>(ast: A): A => {
|
|
|
4798
4847
|
* @category transforming
|
|
4799
4848
|
* @since 4.0.0
|
|
4800
4849
|
*/
|
|
4801
|
-
export const toEncoded =
|
|
4802
|
-
return toType(flip(ast))
|
|
4803
|
-
})
|
|
4850
|
+
export const toEncoded = (ast: AST): AST => toType(flip(ast))
|
|
4804
4851
|
|
|
4805
4852
|
function flipEncoding(ast: AST, encoding: Encoding): AST {
|
|
4806
|
-
|
|
4807
|
-
const
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
}
|
|
4815
|
-
const to = flip(last.to)
|
|
4816
|
-
if (to.encoding) {
|
|
4817
|
-
return replaceEncoding(to, [...to.encoding, ...ls])
|
|
4818
|
-
} else {
|
|
4819
|
-
return replaceEncoding(to, ls)
|
|
4820
|
-
}
|
|
4853
|
+
let from = replaceEncoding(ast, undefined)
|
|
4854
|
+
const reversed = encoding.map((link) => {
|
|
4855
|
+
const out = new Link(flip(from), link.transformation.flip())
|
|
4856
|
+
from = link.to
|
|
4857
|
+
return out
|
|
4858
|
+
}).reverse() as Arr.NonEmptyArray<Link>
|
|
4859
|
+
const to = flip(from)
|
|
4860
|
+
return replaceEncoding(to, to.encoding ? [...to.encoding, ...reversed] : reversed)
|
|
4821
4861
|
}
|
|
4822
4862
|
|
|
4823
4863
|
/**
|
|
@@ -4839,16 +4879,50 @@ function flipEncoding(ast: AST, encoding: Encoding): AST {
|
|
|
4839
4879
|
* @since 4.0.0
|
|
4840
4880
|
*/
|
|
4841
4881
|
export const flip = memoize((ast: AST): AST => {
|
|
4882
|
+
const out = flipAST(ast)
|
|
4883
|
+
if (out !== ast) flippedFrom.set(out, ast)
|
|
4884
|
+
return out
|
|
4885
|
+
})
|
|
4886
|
+
|
|
4887
|
+
function flipAST(ast: AST): AST {
|
|
4842
4888
|
if (ast.encoding) {
|
|
4843
4889
|
return flipEncoding(ast, ast.encoding)
|
|
4844
4890
|
}
|
|
4845
|
-
const
|
|
4846
|
-
if (
|
|
4847
|
-
|
|
4848
|
-
|
|
4891
|
+
const owned = projectOwner(ast, flip)
|
|
4892
|
+
if (owned) return owned
|
|
4893
|
+
if (isSuspend(ast)) {
|
|
4894
|
+
const previous = flippedThunks.get(ast.thunk)
|
|
4895
|
+
if (previous) return copy(ast, { thunk: previous.source.thunk })
|
|
4896
|
+
const flipped = ast.recur(flip)
|
|
4897
|
+
// Register the projection here so decoding alone does not pull in flip.
|
|
4898
|
+
flippedThunks.set(flipped.thunk, {
|
|
4899
|
+
source: ast,
|
|
4900
|
+
project(node) {
|
|
4901
|
+
const thunk = memoizeThunk(() => reverseBody(ast.thunk(), thunk))
|
|
4902
|
+
return copy(node, { thunk })
|
|
4903
|
+
}
|
|
4904
|
+
})
|
|
4905
|
+
return flipped
|
|
4849
4906
|
}
|
|
4850
|
-
return "flip" in ast ? ast.flip(flip) :
|
|
4851
|
-
}
|
|
4907
|
+
return "flip" in ast ? ast.flip(flip) : ast
|
|
4908
|
+
}
|
|
4909
|
+
|
|
4910
|
+
function reverseBody(body: AST, edge: Suspend["thunk"]): AST {
|
|
4911
|
+
if (types.get(body) !== body) return stripEncoding(flip(body))
|
|
4912
|
+
const existing = reversed.get(body)
|
|
4913
|
+
if (existing) return existing
|
|
4914
|
+
// A projected body can close its own cycle if all suspended edges lead back here
|
|
4915
|
+
// and reversing it preserves the checks and declaration callbacks.
|
|
4916
|
+
if (canReuse(body, edge)) {
|
|
4917
|
+
reversed.set(body, body)
|
|
4918
|
+
return body
|
|
4919
|
+
}
|
|
4920
|
+
const out = stripEncoding(flip(body))
|
|
4921
|
+
// The first reversal can discard checks. Further reversals can reuse the pair.
|
|
4922
|
+
if (reprojected.has(body) && !reversed.has(out)) reversed.set(out, body)
|
|
4923
|
+
reprojected.add(out)
|
|
4924
|
+
return out
|
|
4925
|
+
}
|
|
4852
4926
|
|
|
4853
4927
|
function fromConst<const T>(
|
|
4854
4928
|
ast: AST,
|