effect 4.0.0-beta.103 → 4.0.0-beta.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Cache.js +1 -1
- package/dist/Cache.js.map +1 -1
- package/dist/Channel.d.ts +1 -1
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js.map +1 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +28 -7
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +2 -1
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Context.d.ts +2 -2
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js.map +1 -1
- package/dist/Crypto.d.ts.map +1 -1
- package/dist/Crypto.js +13 -5
- package/dist/Crypto.js.map +1 -1
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +12 -1
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +132 -14
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +38 -0
- package/dist/Effect.js.map +1 -1
- package/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +10 -2
- package/dist/Equal.js.map +1 -1
- package/dist/ExecutionPlan.d.ts +73 -0
- package/dist/ExecutionPlan.d.ts.map +1 -1
- package/dist/ExecutionPlan.js +1 -1
- package/dist/ExecutionPlan.js.map +1 -1
- package/dist/FiberSet.js +1 -1
- package/dist/FileSystem.d.ts +2 -2
- package/dist/Function.d.ts +4 -3
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +5 -5
- package/dist/Function.js.map +1 -1
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +11 -10
- package/dist/Iterable.js.map +1 -1
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +7 -5
- package/dist/Layer.js.map +1 -1
- package/dist/Schedule.d.ts +8 -8
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +4 -4
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +32 -32
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +23 -18
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +3 -3
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +47 -31
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +35 -53
- package/dist/SchemaParser.js.map +1 -1
- package/dist/ScopedCache.js +1 -1
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Sink.d.ts +1 -1
- package/dist/Sink.d.ts.map +1 -1
- package/dist/Stream.d.ts +27 -4
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +27 -2
- package/dist/Stream.js.map +1 -1
- package/dist/SynchronizedRef.js +1 -1
- package/dist/SynchronizedRef.js.map +1 -1
- package/dist/Terminal.js +1 -1
- package/dist/Terminal.js.map +1 -1
- package/dist/Tuple.d.ts +6 -4
- package/dist/Tuple.d.ts.map +1 -1
- package/dist/Tuple.js.map +1 -1
- package/dist/TxReentrantLock.d.ts +0 -56
- package/dist/TxReentrantLock.d.ts.map +1 -1
- package/dist/TxReentrantLock.js +8 -8
- package/dist/TxReentrantLock.js.map +1 -1
- package/dist/internal/dateTime.js +1 -1
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/executionPlan.js +51 -3
- package/dist/internal/executionPlan.js.map +1 -1
- package/dist/internal/hashMap.js +12 -8
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/matcher.js +1 -1
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/schedule.js.map +1 -1
- package/dist/internal/schema/annotations.js +2 -0
- package/dist/internal/schema/annotations.js.map +1 -1
- package/dist/internal/schema/toArbitrary.js +1 -1
- package/dist/internal/schema/toArbitrary.js.map +1 -1
- package/dist/internal/trie.js +13 -3
- package/dist/internal/trie.js.map +1 -1
- package/dist/testing/TestClock.d.ts.map +1 -1
- package/dist/testing/TestClock.js +11 -1
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +1 -1
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/unstable/ai/AiError.js +19 -19
- package/dist/unstable/ai/AiError.js.map +1 -1
- package/dist/unstable/ai/Chat.js +1 -1
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +4 -2
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +132 -132
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +8 -8
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.js +1 -1
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts +15 -3
- package/dist/unstable/ai/Prompt.d.ts.map +1 -1
- package/dist/unstable/ai/Prompt.js +6 -3
- package/dist/unstable/ai/Prompt.js.map +1 -1
- package/dist/unstable/cli/CliError.d.ts +3 -3
- package/dist/unstable/cli/CliError.js +11 -11
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +9 -9
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +8 -6
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/Param.d.ts +7 -5
- package/dist/unstable/cli/Param.d.ts.map +1 -1
- package/dist/unstable/cli/Param.js +15 -11
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/Primitive.d.ts.map +1 -1
- package/dist/unstable/cli/Primitive.js +31 -24
- package/dist/unstable/cli/Primitive.js.map +1 -1
- package/dist/unstable/cli/Prompt.d.ts.map +1 -1
- package/dist/unstable/cli/Prompt.js +31 -17
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cli/internal/ansi.js +2 -2
- package/dist/unstable/cli/internal/ansi.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts +2 -2
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +10 -9
- package/dist/unstable/cli/internal/command.js.map +1 -1
- package/dist/unstable/cli/internal/completions/bash.js +69 -9
- package/dist/unstable/cli/internal/completions/bash.js.map +1 -1
- package/dist/unstable/cli/internal/completions/descriptor.js +24 -18
- package/dist/unstable/cli/internal/completions/descriptor.js.map +1 -1
- package/dist/unstable/cli/internal/completions/fish.js +5 -5
- package/dist/unstable/cli/internal/completions/fish.js.map +1 -1
- package/dist/unstable/cli/internal/help.d.ts.map +1 -1
- package/dist/unstable/cli/internal/help.js +4 -2
- package/dist/unstable/cli/internal/help.js.map +1 -1
- package/dist/unstable/cli/internal/parser.js +3 -3
- package/dist/unstable/cli/internal/parser.js.map +1 -1
- package/dist/unstable/cli/internal/wizard.js +2 -2
- package/dist/unstable/cli/internal/wizard.js.map +1 -1
- package/dist/unstable/cluster/ClusterError.js +7 -7
- package/dist/unstable/cluster/ClusterError.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/MessageStorage.js +8 -1
- package/dist/unstable/cluster/MessageStorage.js.map +1 -1
- package/dist/unstable/cluster/Reply.d.ts +8 -0
- package/dist/unstable/cluster/Reply.d.ts.map +1 -1
- package/dist/unstable/cluster/Reply.js +12 -0
- package/dist/unstable/cluster/Reply.js.map +1 -1
- package/dist/unstable/cluster/RunnerServer.d.ts.map +1 -1
- package/dist/unstable/cluster/RunnerServer.js +4 -2
- package/dist/unstable/cluster/RunnerServer.js.map +1 -1
- package/dist/unstable/cluster/RunnerStorage.d.ts +1 -2
- package/dist/unstable/cluster/RunnerStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/RunnerStorage.js +7 -6
- package/dist/unstable/cluster/RunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +22 -4
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +1 -1
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/cluster/internal/resourceMap.js +2 -2
- package/dist/unstable/cluster/internal/resourceMap.js.map +1 -1
- package/dist/unstable/cluster/internal/resourceRef.js +17 -0
- package/dist/unstable/cluster/internal/resourceRef.js.map +1 -1
- package/dist/unstable/devtools/DevToolsClient.d.ts.map +1 -1
- package/dist/unstable/devtools/DevToolsClient.js +7 -2
- package/dist/unstable/devtools/DevToolsClient.js.map +1 -1
- package/dist/unstable/encoding/Ini.d.ts +20 -0
- package/dist/unstable/encoding/Ini.d.ts.map +1 -0
- package/dist/unstable/encoding/Ini.js +153 -0
- package/dist/unstable/encoding/Ini.js.map +1 -0
- package/dist/unstable/encoding/Msgpack.d.ts +2 -1
- package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
- package/dist/unstable/encoding/Msgpack.js +21 -7
- package/dist/unstable/encoding/Msgpack.js.map +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
- package/dist/unstable/encoding/Ndjson.js +7 -1
- package/dist/unstable/encoding/Ndjson.js.map +1 -1
- package/dist/unstable/encoding/Sse.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.js +14 -23
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/encoding/Toml.d.ts +19 -0
- package/dist/unstable/encoding/Toml.d.ts.map +1 -0
- package/dist/unstable/encoding/Toml.js +434 -0
- package/dist/unstable/encoding/Toml.js.map +1 -0
- package/dist/unstable/encoding/Yaml.d.ts +19 -0
- package/dist/unstable/encoding/Yaml.d.ts.map +1 -0
- package/dist/unstable/encoding/Yaml.js +461 -0
- package/dist/unstable/encoding/Yaml.js.map +1 -0
- package/dist/unstable/encoding/index.d.ts +12 -0
- package/dist/unstable/encoding/index.d.ts.map +1 -1
- package/dist/unstable/encoding/index.js +12 -0
- package/dist/unstable/encoding/index.js.map +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventJournal.js +13 -5
- package/dist/unstable/eventlog/EventJournal.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.js +1 -1
- package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
- package/dist/unstable/eventlog/EventLogServerUnencrypted.js +1 -1
- package/dist/unstable/eventlog/EventLogServerUnencrypted.js.map +1 -1
- package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -1
- package/dist/unstable/eventlog/SqlEventJournal.js +1 -4
- package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
- package/dist/unstable/http/FindMyWay/internal/queryString.d.ts +11 -0
- package/dist/unstable/http/FindMyWay/internal/queryString.d.ts.map +1 -0
- package/dist/unstable/http/FindMyWay/internal/queryString.js +259 -0
- package/dist/unstable/http/FindMyWay/internal/queryString.js.map +1 -0
- package/dist/unstable/http/FindMyWay/internal/router.d.ts +2 -0
- package/dist/unstable/http/FindMyWay/internal/router.d.ts.map +1 -0
- package/dist/unstable/http/FindMyWay/internal/router.js +665 -0
- package/dist/unstable/http/FindMyWay/internal/router.js.map +1 -0
- package/dist/unstable/http/FindMyWay.d.ts +33 -8
- package/dist/unstable/http/FindMyWay.d.ts.map +1 -1
- package/dist/unstable/http/FindMyWay.js +4 -7
- package/dist/unstable/http/FindMyWay.js.map +1 -1
- package/dist/unstable/http/HttpClientError.js +1 -1
- package/dist/unstable/http/HttpClientError.js.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +2 -14
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpClientResponse.js +1 -16
- package/dist/unstable/http/HttpClientResponse.js.map +1 -1
- package/dist/unstable/http/HttpPlatform.d.ts.map +1 -1
- package/dist/unstable/http/HttpPlatform.js +21 -3
- package/dist/unstable/http/HttpPlatform.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +7 -6
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +8 -6
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/Multipart.d.ts +1 -1
- package/dist/unstable/http/Multipart.d.ts.map +1 -1
- package/dist/unstable/http/Multipart.js +9 -2
- package/dist/unstable/http/Multipart.js.map +1 -1
- package/dist/unstable/http/MultipartParser/HeadersParser.d.ts +53 -0
- package/dist/unstable/http/MultipartParser/HeadersParser.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser/HeadersParser.js +14 -0
- package/dist/unstable/http/MultipartParser/HeadersParser.js.map +1 -0
- package/dist/unstable/http/MultipartParser/Search.d.ts +11 -0
- package/dist/unstable/http/MultipartParser/Search.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser/Search.js +14 -0
- package/dist/unstable/http/MultipartParser/Search.js.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/contentType.d.ts +5 -0
- package/dist/unstable/http/MultipartParser/internal/contentType.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/contentType.js +82 -0
- package/dist/unstable/http/MultipartParser/internal/contentType.js.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/headers.d.ts +3 -0
- package/dist/unstable/http/MultipartParser/internal/headers.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/headers.js +194 -0
- package/dist/unstable/http/MultipartParser/internal/headers.js.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/multipart.d.ts +8 -0
- package/dist/unstable/http/MultipartParser/internal/multipart.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/multipart.js +226 -0
- package/dist/unstable/http/MultipartParser/internal/multipart.js.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/search.d.ts +5 -0
- package/dist/unstable/http/MultipartParser/internal/search.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/search.js +120 -0
- package/dist/unstable/http/MultipartParser/internal/search.js.map +1 -0
- package/dist/unstable/http/MultipartParser.d.ts +98 -0
- package/dist/unstable/http/MultipartParser.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser.js +23 -0
- package/dist/unstable/http/MultipartParser.js.map +1 -0
- package/dist/unstable/http/Template.d.ts.map +1 -1
- package/dist/unstable/http/Template.js +2 -2
- package/dist/unstable/http/Template.js.map +1 -1
- package/dist/unstable/http/index.d.ts +1 -1
- package/dist/unstable/http/index.d.ts.map +1 -1
- package/dist/unstable/http/index.js +1 -1
- package/dist/unstable/http/index.js.map +1 -1
- package/dist/unstable/http/internal/httpBody.d.ts +2 -0
- package/dist/unstable/http/internal/httpBody.d.ts.map +1 -0
- package/dist/unstable/http/internal/httpBody.js +10 -0
- package/dist/unstable/http/internal/httpBody.js.map +1 -0
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js +5 -5
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +68 -15
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +65 -25
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +6 -4
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +73 -16
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +5 -5
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +17 -17
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +219 -0
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js +170 -0
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts +8 -0
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +45 -18
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/observability/OtlpExporter.d.ts +1 -1
- package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.js +2 -1
- package/dist/unstable/observability/OtlpExporter.js.map +1 -1
- package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpLogger.js +2 -2
- package/dist/unstable/observability/OtlpLogger.js.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.d.ts +2 -2
- package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.js +28 -15
- package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
- package/dist/unstable/observability/OtlpTracer.js +1 -1
- package/dist/unstable/observability/OtlpTracer.js.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +9 -9
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistence.js +17 -7
- package/dist/unstable/persistence/Persistence.js.map +1 -1
- package/dist/unstable/persistence/RateLimiter.d.ts +22 -12
- package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
- package/dist/unstable/persistence/RateLimiter.js +15 -42
- package/dist/unstable/persistence/RateLimiter.js.map +1 -1
- package/dist/unstable/persistence/Redis.js +1 -1
- package/dist/unstable/persistence/Redis.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts +14 -0
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +18 -9
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcClientError.js +2 -2
- package/dist/unstable/rpc/RpcClientError.js.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.js +3 -1
- package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
- package/dist/unstable/schema/Model.d.ts +1 -1
- package/dist/unstable/schema/Model.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +5 -5
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js +17 -9
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +28 -12
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
- package/dist/unstable/sql/SqlClient.js +7 -3
- package/dist/unstable/sql/SqlClient.js.map +1 -1
- package/dist/unstable/sql/SqlError.js +13 -13
- package/dist/unstable/sql/SqlError.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.js +8 -6
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/sql/Statement.d.ts.map +1 -1
- package/dist/unstable/sql/Statement.js +8 -6
- package/dist/unstable/sql/Statement.js.map +1 -1
- package/dist/unstable/workers/WorkerError.js +5 -5
- package/dist/unstable/workers/WorkerError.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +3 -3
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +2 -8
- package/src/Cache.ts +1 -1
- package/src/Channel.ts +1 -1
- package/src/Config.ts +28 -7
- package/src/ConfigProvider.ts +4 -1
- package/src/Context.ts +5 -5
- package/src/Crypto.ts +17 -8
- package/src/Duration.ts +16 -2
- package/src/Effect.ts +141 -17
- package/src/Equal.ts +10 -2
- package/src/ExecutionPlan.ts +78 -1
- package/src/FiberSet.ts +1 -1
- package/src/FileSystem.ts +2 -2
- package/src/Function.ts +6 -6
- package/src/Iterable.ts +11 -10
- package/src/Layer.ts +7 -5
- package/src/Schedule.ts +13 -13
- package/src/Schema.ts +50 -41
- package/src/SchemaAST.ts +69 -37
- package/src/SchemaParser.ts +75 -69
- package/src/ScopedCache.ts +1 -1
- package/src/Sink.ts +1 -1
- package/src/Stream.ts +77 -10
- package/src/SynchronizedRef.ts +1 -1
- package/src/Terminal.ts +1 -1
- package/src/Tuple.ts +7 -4
- package/src/TxReentrantLock.ts +39 -35
- package/src/internal/dateTime.ts +1 -1
- package/src/internal/executionPlan.ts +105 -10
- package/src/internal/hashMap.ts +20 -14
- package/src/internal/matcher.ts +2 -2
- package/src/internal/schedule.ts +4 -4
- package/src/internal/schema/annotations.ts +3 -0
- package/src/internal/schema/toArbitrary.ts +3 -1
- package/src/internal/trie.ts +12 -2
- package/src/testing/TestClock.ts +13 -1
- package/src/testing/TestSchema.ts +1 -1
- package/src/unstable/ai/AiError.ts +19 -19
- package/src/unstable/ai/Chat.ts +1 -1
- package/src/unstable/ai/LanguageModel.ts +4 -2
- package/src/unstable/ai/McpSchema.ts +17 -16
- package/src/unstable/ai/McpServer.ts +1 -1
- package/src/unstable/ai/Prompt.ts +21 -6
- package/src/unstable/cli/CliError.ts +12 -12
- package/src/unstable/cli/Command.ts +12 -10
- package/src/unstable/cli/Param.ts +41 -19
- package/src/unstable/cli/Primitive.ts +11 -5
- package/src/unstable/cli/Prompt.ts +36 -20
- package/src/unstable/cli/internal/ansi.ts +2 -2
- package/src/unstable/cli/internal/command.ts +15 -10
- package/src/unstable/cli/internal/completions/bash.ts +59 -9
- package/src/unstable/cli/internal/completions/descriptor.ts +14 -20
- package/src/unstable/cli/internal/completions/fish.ts +5 -7
- package/src/unstable/cli/internal/help.ts +4 -2
- package/src/unstable/cli/internal/parser.ts +3 -3
- package/src/unstable/cli/internal/wizard.ts +2 -2
- package/src/unstable/cluster/ClusterError.ts +7 -7
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +4 -1
- package/src/unstable/cluster/MessageStorage.ts +9 -5
- package/src/unstable/cluster/Reply.ts +21 -0
- package/src/unstable/cluster/RunnerServer.ts +4 -10
- package/src/unstable/cluster/RunnerStorage.ts +9 -7
- package/src/unstable/cluster/Sharding.ts +35 -7
- package/src/unstable/cluster/internal/entityManager.ts +1 -1
- package/src/unstable/cluster/internal/resourceMap.ts +5 -2
- package/src/unstable/cluster/internal/resourceRef.ts +27 -5
- package/src/unstable/devtools/DevToolsClient.ts +3 -2
- package/src/unstable/encoding/Ini.ts +174 -0
- package/src/unstable/encoding/Msgpack.ts +47 -28
- package/src/unstable/encoding/Ndjson.ts +9 -1
- package/src/unstable/encoding/Sse.ts +11 -21
- package/src/unstable/encoding/Toml.ts +504 -0
- package/src/unstable/encoding/Yaml.ts +541 -0
- package/src/unstable/encoding/index.ts +15 -0
- package/src/unstable/eventlog/EventJournal.ts +14 -6
- package/src/unstable/eventlog/EventLogMessage.ts +1 -1
- package/src/unstable/eventlog/EventLogServerUnencrypted.ts +1 -1
- package/src/unstable/eventlog/SqlEventJournal.ts +6 -4
- package/src/unstable/http/FindMyWay/internal/queryString.ts +420 -0
- package/src/unstable/http/FindMyWay/internal/router.ts +950 -0
- package/src/unstable/http/FindMyWay.ts +65 -6
- package/src/unstable/http/HttpClientError.ts +1 -1
- package/src/unstable/http/HttpClientRequest.ts +2 -14
- package/src/unstable/http/HttpClientResponse.ts +1 -17
- package/src/unstable/http/HttpPlatform.ts +34 -6
- package/src/unstable/http/HttpServerRequest.ts +14 -6
- package/src/unstable/http/HttpServerResponse.ts +9 -7
- package/src/unstable/http/Multipart.ts +9 -2
- package/src/unstable/http/MultipartParser/HeadersParser.ts +68 -0
- package/src/unstable/http/MultipartParser/Search.ts +17 -0
- package/src/unstable/http/MultipartParser/internal/contentType.ts +103 -0
- package/src/unstable/http/MultipartParser/internal/headers.ts +615 -0
- package/src/unstable/http/MultipartParser/internal/multipart.ts +262 -0
- package/src/unstable/http/MultipartParser/internal/search.ts +167 -0
- package/src/unstable/http/MultipartParser.ts +115 -0
- package/src/unstable/http/Template.ts +6 -5
- package/src/unstable/http/index.ts +1 -1
- package/src/unstable/http/internal/httpBody.ts +15 -0
- package/src/unstable/httpapi/HttpApi.ts +6 -7
- package/src/unstable/httpapi/HttpApiBuilder.ts +119 -21
- package/src/unstable/httpapi/HttpApiClient.ts +104 -41
- package/src/unstable/httpapi/HttpApiEndpoint.ts +117 -29
- package/src/unstable/httpapi/HttpApiError.ts +33 -39
- package/src/unstable/httpapi/HttpApiMiddleware.ts +1 -1
- package/src/unstable/httpapi/HttpApiSchema.ts +353 -0
- package/src/unstable/httpapi/OpenApi.ts +70 -20
- package/src/unstable/observability/OtlpExporter.ts +4 -2
- package/src/unstable/observability/OtlpLogger.ts +3 -1
- package/src/unstable/observability/OtlpMetrics.ts +32 -18
- package/src/unstable/observability/OtlpTracer.ts +1 -1
- package/src/unstable/persistence/PersistedQueue.ts +12 -9
- package/src/unstable/persistence/Persistence.ts +27 -7
- package/src/unstable/persistence/RateLimiter.ts +54 -31
- package/src/unstable/persistence/Redis.ts +1 -1
- package/src/unstable/rpc/RpcClient.ts +38 -12
- package/src/unstable/rpc/RpcClientError.ts +2 -2
- package/src/unstable/rpc/RpcSerialization.ts +1 -1
- package/src/unstable/schema/VariantSchema.ts +36 -18
- package/src/unstable/socket/Socket.ts +24 -14
- package/src/unstable/sql/SqlClient.ts +65 -56
- package/src/unstable/sql/SqlError.ts +13 -13
- package/src/unstable/sql/SqlResolver.ts +8 -6
- package/src/unstable/sql/Statement.ts +13 -8
- package/src/unstable/workers/WorkerError.ts +5 -5
- package/src/unstable/workflow/WorkflowEngine.ts +8 -3
- package/dist/unstable/http/Multipasta/HeadersParser.d.ts +0 -14
- package/dist/unstable/http/Multipasta/HeadersParser.d.ts.map +0 -1
- package/dist/unstable/http/Multipasta/HeadersParser.js +0 -14
- package/dist/unstable/http/Multipasta/HeadersParser.js.map +0 -1
- package/dist/unstable/http/Multipasta/Node.d.ts +0 -14
- package/dist/unstable/http/Multipasta/Node.d.ts.map +0 -1
- package/dist/unstable/http/Multipasta/Node.js +0 -14
- package/dist/unstable/http/Multipasta/Node.js.map +0 -1
- package/dist/unstable/http/Multipasta/Search.d.ts +0 -14
- package/dist/unstable/http/Multipasta/Search.d.ts.map +0 -1
- package/dist/unstable/http/Multipasta/Search.js +0 -14
- package/dist/unstable/http/Multipasta/Search.js.map +0 -1
- package/dist/unstable/http/Multipasta/Web.d.ts +0 -14
- package/dist/unstable/http/Multipasta/Web.d.ts.map +0 -1
- package/dist/unstable/http/Multipasta/Web.js +0 -14
- package/dist/unstable/http/Multipasta/Web.js.map +0 -1
- package/dist/unstable/http/Multipasta.d.ts +0 -15
- package/dist/unstable/http/Multipasta.d.ts.map +0 -1
- package/dist/unstable/http/Multipasta.js +0 -15
- package/dist/unstable/http/Multipasta.js.map +0 -1
- package/src/unstable/http/Multipasta/HeadersParser.ts +0 -14
- package/src/unstable/http/Multipasta/Node.ts +0 -14
- package/src/unstable/http/Multipasta/Search.ts +0 -14
- package/src/unstable/http/Multipasta/Web.ts +0 -14
- package/src/unstable/http/Multipasta.ts +0 -15
|
@@ -760,6 +760,7 @@ function handlerToHttpEffect(
|
|
|
760
760
|
const decodeHeaders = UndefinedOr.map(endpoint.headers, Schema.decodeUnknownEffect)
|
|
761
761
|
const decodeQuery = UndefinedOr.map(endpoint.query, Schema.decodeUnknownEffect)
|
|
762
762
|
const encodeStream = makeStreamEncoder(endpoint)
|
|
763
|
+
const encodeWithHeaders = makeWithHeadersEncoder(endpoint)
|
|
763
764
|
|
|
764
765
|
const shouldParsePayload = endpoint.payload.size > 0 && !isRaw
|
|
765
766
|
const payloadBy = shouldParsePayload ? buildPayloadDecoders(endpoint.payload) : undefined
|
|
@@ -797,15 +798,26 @@ function handlerToHttpEffect(
|
|
|
797
798
|
request.payload = yield* HttpApiSchemaError.wrap("Payload", result)
|
|
798
799
|
}
|
|
799
800
|
}
|
|
800
|
-
|
|
801
|
+
let response = yield* handler(request)
|
|
801
802
|
if (Response.isHttpServerResponse(response)) {
|
|
802
803
|
return response
|
|
803
804
|
}
|
|
804
|
-
|
|
805
|
-
if (
|
|
806
|
-
|
|
805
|
+
let responseHeaders: unknown | undefined
|
|
806
|
+
if (encodeWithHeaders !== undefined && HttpApiSchema.isWithHeadersValue(response)) {
|
|
807
|
+
responseHeaders = response.headers
|
|
808
|
+
response = response.body
|
|
807
809
|
}
|
|
808
|
-
|
|
810
|
+
const encoded = yield* HttpApiSchemaError.wrap(
|
|
811
|
+
"Body",
|
|
812
|
+
encodeStream?.(response, context) ??
|
|
813
|
+
(responseHeaders !== undefined ? encodeWithHeaders!.encodeBody(response) : encodeSuccess(response))
|
|
814
|
+
)
|
|
815
|
+
if (encodeWithHeaders === undefined || responseHeaders === undefined) return encoded
|
|
816
|
+
const encodedHeaders = yield* HttpApiSchemaError.wrap(
|
|
817
|
+
"ResponseHeaders",
|
|
818
|
+
encodeWithHeaders.encodeHeaders.get(encoded.status)!(responseHeaders)
|
|
819
|
+
)
|
|
820
|
+
return Response.setHeaders(encoded, encodedHeaders as any)
|
|
809
821
|
})
|
|
810
822
|
).pipe(
|
|
811
823
|
Effect.withErrorReporting,
|
|
@@ -918,6 +930,37 @@ type StreamEncoder = (response: unknown, context: Context.Context<never>) =>
|
|
|
918
930
|
| Effect.Effect<HttpServerResponse, Schema.SchemaError, unknown>
|
|
919
931
|
| undefined
|
|
920
932
|
|
|
933
|
+
type WithHeadersEncoder = (headers: unknown) => Effect.Effect<unknown, Schema.SchemaError, unknown>
|
|
934
|
+
|
|
935
|
+
interface WithHeadersEncoders {
|
|
936
|
+
readonly encodeBody: (body: unknown) => Effect.Effect<HttpServerResponse, Schema.SchemaError, unknown>
|
|
937
|
+
readonly encodeHeaders: ReadonlyMap<number, WithHeadersEncoder>
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
function makeWithHeadersEncoder(endpoint: HttpApiEndpoint.Top): WithHeadersEncoders | undefined {
|
|
941
|
+
const encodeHeaders = new Map<number, WithHeadersEncoder>()
|
|
942
|
+
const bodySchemas: Array<Schema.ConstraintEncoder<HttpServerResponse, unknown>> = []
|
|
943
|
+
for (const schema of endpoint.success) {
|
|
944
|
+
if (!HttpApiSchema.isWithHeaders(schema)) continue
|
|
945
|
+
encodeHeaders.set(HttpApiSchema.getStatusSuccessSchema(schema), Schema.encodeUnknownEffect(schema.headers))
|
|
946
|
+
if (!HttpApiSchema.isStreamSchema(schema.schema)) {
|
|
947
|
+
bodySchemas.push(toResponseSuccessSchema(schema))
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
if (encodeHeaders.size === 0) return undefined
|
|
951
|
+
// Branded response bodies encode against the header-carrying members only, so
|
|
952
|
+
// the encoded status always has a matching header schema.
|
|
953
|
+
const bodySchema: Schema.ConstraintEncoder<HttpServerResponse, unknown> = bodySchemas.length === 0
|
|
954
|
+
? Schema.Never
|
|
955
|
+
: bodySchemas.length === 1
|
|
956
|
+
? bodySchemas[0]
|
|
957
|
+
: Schema.Union(bodySchemas)
|
|
958
|
+
return {
|
|
959
|
+
encodeBody: Schema.encodeUnknownEffect(bodySchema),
|
|
960
|
+
encodeHeaders
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
921
964
|
function makeStreamEncoder(endpoint: HttpApiEndpoint.Top): StreamEncoder | undefined {
|
|
922
965
|
const streamSchema = getStreamSuccessSchema(endpoint)
|
|
923
966
|
if (streamSchema === undefined) {
|
|
@@ -967,15 +1010,17 @@ function makeStreamEncoder(endpoint: HttpApiEndpoint.Top): StreamEncoder | undef
|
|
|
967
1010
|
|
|
968
1011
|
function getStreamSuccessSchema(endpoint: HttpApiEndpoint.Top) {
|
|
969
1012
|
for (const schema of endpoint.success) {
|
|
970
|
-
|
|
971
|
-
|
|
1013
|
+
const body = HttpApiSchema.isWithHeaders(schema) ? schema.schema : schema
|
|
1014
|
+
if (HttpApiSchema.isStreamSchema(body)) {
|
|
1015
|
+
return body
|
|
972
1016
|
}
|
|
973
1017
|
}
|
|
974
1018
|
}
|
|
975
1019
|
|
|
976
1020
|
function hasBufferedSuccess(endpoint: HttpApiEndpoint.Top): boolean {
|
|
977
1021
|
for (const schema of endpoint.success) {
|
|
978
|
-
|
|
1022
|
+
const body = HttpApiSchema.isWithHeaders(schema) ? schema.schema : schema
|
|
1023
|
+
if (Schema.isSchema(body) && !HttpApiSchema.isStreamSchema(body)) return true
|
|
979
1024
|
}
|
|
980
1025
|
return endpoint.success.size === 0
|
|
981
1026
|
}
|
|
@@ -1040,8 +1085,31 @@ function renderSseEvent(event: Sse.EventEncoded) {
|
|
|
1040
1085
|
})
|
|
1041
1086
|
}
|
|
1042
1087
|
|
|
1043
|
-
const toResponseSuccessSchema = toResponseSchema(HttpApiSchema.
|
|
1044
|
-
const
|
|
1088
|
+
const toResponseSuccessSchema = toResponseSchema(HttpApiSchema.getStatusSuccessSchema)
|
|
1089
|
+
const toResponseErrorSchemaPlain = toResponseSchema(HttpApiSchema.getStatusErrorSchema)
|
|
1090
|
+
|
|
1091
|
+
function toResponseErrorSchema(
|
|
1092
|
+
schema: Schema.Constraint
|
|
1093
|
+
): Schema.ConstraintEncoder<HttpServerResponse, unknown> {
|
|
1094
|
+
if (!HttpApiSchema.isWithHeaders(schema)) return toResponseErrorSchemaPlain(schema)
|
|
1095
|
+
|
|
1096
|
+
const encodeBody = Schema.encodeUnknownEffect(schema.schema)
|
|
1097
|
+
const encodeHeaders = Schema.encodeUnknownEffect(schema.headers)
|
|
1098
|
+
const encodeResponse = getResponseEncode(
|
|
1099
|
+
HttpApiSchema.getStatusErrorSchema(schema),
|
|
1100
|
+
HttpApiSchema.getResponseEncodingSchema(schema),
|
|
1101
|
+
HttpApiSchema.isNoContent(schema.schema.ast)
|
|
1102
|
+
)
|
|
1103
|
+
const transformation = withHeadersTransformation<HttpApiSchema.withHeaders<unknown, Schema.StringTree>>(
|
|
1104
|
+
(body) =>
|
|
1105
|
+
encodeBody(body).pipe(
|
|
1106
|
+
Effect.mapError((error) => error.issue),
|
|
1107
|
+
Effect.flatMap(encodeResponse)
|
|
1108
|
+
),
|
|
1109
|
+
encodeHeaders
|
|
1110
|
+
)
|
|
1111
|
+
return $HttpServerResponse.pipe(Schema.decodeTo(schema, transformation))
|
|
1112
|
+
}
|
|
1045
1113
|
|
|
1046
1114
|
function makeSuccessSchema(
|
|
1047
1115
|
endpoint: HttpApiEndpoint.Top
|
|
@@ -1058,31 +1126,44 @@ function makeErrorSchema(
|
|
|
1058
1126
|
return schemas.length === 1 ? schemas[0] : Schema.Union(schemas)
|
|
1059
1127
|
}
|
|
1060
1128
|
|
|
1061
|
-
function toResponseSchema(getStatus: (
|
|
1062
|
-
|
|
1129
|
+
function toResponseSchema(getStatus: (schema: Schema.Constraint) => number) {
|
|
1130
|
+
// WithHeaders wrappers share a single declaration AST, so they are cached by instance
|
|
1131
|
+
const cache = new WeakMap<object, Schema.Top>()
|
|
1063
1132
|
|
|
1064
1133
|
return (schema: Schema.Constraint): Schema.ConstraintEncoder<HttpServerResponse, unknown> => {
|
|
1065
|
-
const
|
|
1134
|
+
const key = HttpApiSchema.isWithHeaders(schema) ? schema : schema.ast
|
|
1135
|
+
const cached = cache.get(key)
|
|
1066
1136
|
if (cached !== undefined) {
|
|
1067
1137
|
return cached as any
|
|
1068
1138
|
}
|
|
1139
|
+
const bodySchema = HttpApiSchema.isWithHeaders(schema) ? schema.schema : schema
|
|
1069
1140
|
const responseSchema = $HttpServerResponse.pipe(
|
|
1070
|
-
Schema.decodeTo(
|
|
1141
|
+
Schema.decodeTo(bodySchema, getResponseTransformation(getStatus, schema))
|
|
1071
1142
|
)
|
|
1072
|
-
cache.set(
|
|
1143
|
+
cache.set(key, responseSchema)
|
|
1073
1144
|
return responseSchema
|
|
1074
1145
|
}
|
|
1075
1146
|
}
|
|
1076
1147
|
|
|
1077
1148
|
function getResponseTransformation(
|
|
1078
|
-
getStatus: (
|
|
1149
|
+
getStatus: (schema: Schema.Constraint) => number,
|
|
1079
1150
|
schema: Schema.Constraint
|
|
1080
|
-
): SchemaTransformation.Transformation<unknown, Response.HttpServerResponse> {
|
|
1081
|
-
const
|
|
1151
|
+
): SchemaTransformation.Transformation<unknown, Response.HttpServerResponse, never, unknown> {
|
|
1152
|
+
const withHeaders = HttpApiSchema.getWithHeadersAnnotation(schema.ast)
|
|
1153
|
+
if (withHeaders !== undefined) {
|
|
1154
|
+
const encodeBody = getResponseEncode(
|
|
1155
|
+
getStatus(withHeaders.body),
|
|
1156
|
+
HttpApiSchema.getResponseEncoding(withHeaders.body.ast),
|
|
1157
|
+
HttpApiSchema.isNoContent(withHeaders.body.ast)
|
|
1158
|
+
)
|
|
1159
|
+
return withHeadersTransformation(encodeBody, Schema.encodeUnknownEffect(withHeaders.headersCodec))
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
const bodySchema = HttpApiSchema.isWithHeaders(schema) ? schema.schema : schema
|
|
1082
1163
|
const encode = getResponseEncode(
|
|
1083
|
-
getStatus(
|
|
1084
|
-
HttpApiSchema.
|
|
1085
|
-
HttpApiSchema.isNoContent(ast)
|
|
1164
|
+
getStatus(schema),
|
|
1165
|
+
HttpApiSchema.getResponseEncodingSchema(schema),
|
|
1166
|
+
HttpApiSchema.isNoContent(bodySchema.ast)
|
|
1086
1167
|
)
|
|
1087
1168
|
|
|
1088
1169
|
return SchemaTransformation.transformOrFail({
|
|
@@ -1091,6 +1172,23 @@ function getResponseTransformation(
|
|
|
1091
1172
|
})
|
|
1092
1173
|
}
|
|
1093
1174
|
|
|
1175
|
+
function withHeadersTransformation<T = unknown>(
|
|
1176
|
+
encodeBody: (body: unknown) => Effect.Effect<Response.HttpServerResponse, SchemaIssue.Issue, unknown>,
|
|
1177
|
+
encodeHeaders: (headers: unknown) => Effect.Effect<unknown, Schema.SchemaError, unknown>
|
|
1178
|
+
): SchemaTransformation.Transformation<T, Response.HttpServerResponse, never, unknown> {
|
|
1179
|
+
return SchemaTransformation.transformOrFail<T, Response.HttpServerResponse, never, unknown>({
|
|
1180
|
+
decode: () => Effect.fail(new SchemaIssue.Forbidden({ message: "Encode only schema" })),
|
|
1181
|
+
encode: (value) => {
|
|
1182
|
+
const pair = value as { readonly body: unknown; readonly headers: unknown }
|
|
1183
|
+
return Effect.flatMap(encodeBody(pair.body), (response) =>
|
|
1184
|
+
Effect.map(
|
|
1185
|
+
encodeHeaders(pair.headers).pipe(Effect.mapError((error) => error.issue)),
|
|
1186
|
+
(headers) => Response.setHeaders(response, headers as any)
|
|
1187
|
+
))
|
|
1188
|
+
}
|
|
1189
|
+
})
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1094
1192
|
function getResponseEncode<E>(
|
|
1095
1193
|
status: number,
|
|
1096
1194
|
encoding: HttpApiSchema.ResponseEncoding,
|
|
@@ -68,15 +68,19 @@ export type ForApi<Api extends HttpApi.Constraint, E = never, R = never> = Api e
|
|
|
68
68
|
HttpApi.HttpApi<infer _Id, infer Groups> ? Client<Groups, E, R> :
|
|
69
69
|
never
|
|
70
70
|
|
|
71
|
-
type SuccessType<S> = S extends HttpApiSchema.
|
|
72
|
-
infer
|
|
73
|
-
infer
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
_Error
|
|
78
|
-
|
|
79
|
-
>
|
|
71
|
+
type SuccessType<S> = S extends HttpApiSchema.WithHeaders<
|
|
72
|
+
infer _Inner,
|
|
73
|
+
infer _Headers
|
|
74
|
+
> ? HttpApiSchema.withHeaders<SuccessType<_Inner>, _Headers["Type"]>
|
|
75
|
+
: S extends HttpApiSchema.StreamSse<
|
|
76
|
+
infer _Events,
|
|
77
|
+
infer _Error,
|
|
78
|
+
infer _Value
|
|
79
|
+
> ? Stream.Stream<
|
|
80
|
+
_Value,
|
|
81
|
+
_Error["Type"] | HttpClientError.HttpClientError | Schema.SchemaError | Sse.Retry | Sse.SseError,
|
|
82
|
+
never
|
|
83
|
+
>
|
|
80
84
|
: S extends HttpApiSchema.StreamUint8Array ? Stream.Stream<Uint8Array, HttpClientError.HttpClientError, never>
|
|
81
85
|
: S extends Schema.Constraint ? S["Type"]
|
|
82
86
|
: never
|
|
@@ -366,10 +370,11 @@ export const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Con
|
|
|
366
370
|
}
|
|
367
371
|
}
|
|
368
372
|
for (const streamSuccess of getStreamSuccessSchemas(endpoint)) {
|
|
373
|
+
const streamSchema = isWithHeadersStreamSuccess(streamSuccess) ? streamSuccess.schema : streamSuccess
|
|
369
374
|
addResponseAlternative(
|
|
370
375
|
successAlternatives,
|
|
371
|
-
HttpApiSchema.
|
|
372
|
-
|
|
376
|
+
HttpApiSchema.getStatusSuccessSchema(streamSuccess),
|
|
377
|
+
streamSchema.contentType,
|
|
373
378
|
streamToResponse(streamSuccess)
|
|
374
379
|
)
|
|
375
380
|
}
|
|
@@ -722,9 +727,44 @@ const compilePath = (path: string) => {
|
|
|
722
727
|
}
|
|
723
728
|
|
|
724
729
|
function schemasToResponse(schemas: readonly [Schema.Constraint, ...Array<Schema.Constraint>]) {
|
|
725
|
-
const
|
|
730
|
+
const hasWithHeaders = schemas.some((schema) =>
|
|
731
|
+
HttpApiSchema.isWithHeaders(schema) || HttpApiSchema.getWithHeadersAnnotation(schema.ast) !== undefined
|
|
732
|
+
)
|
|
733
|
+
const codec = hasWithHeaders
|
|
734
|
+
? Schema.Union(schemas.map(toCodecArrayBufferWithHeaders))
|
|
735
|
+
: toCodecArrayBuffer(schemas)
|
|
726
736
|
const decode = Schema.decodeEffect(codec)
|
|
727
|
-
return (response: HttpClientResponse.HttpClientResponse) =>
|
|
737
|
+
return (response: HttpClientResponse.HttpClientResponse) =>
|
|
738
|
+
Effect.flatMap(
|
|
739
|
+
response.arrayBuffer,
|
|
740
|
+
hasWithHeaders
|
|
741
|
+
? (body) => decode({ body, headers: response.headers })
|
|
742
|
+
: decode
|
|
743
|
+
)
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
function toCodecArrayBufferWithHeaders(schema: Schema.Constraint): Schema.Top {
|
|
747
|
+
const isWithHeaders = HttpApiSchema.isWithHeaders(schema)
|
|
748
|
+
const annotation = HttpApiSchema.getWithHeadersAnnotation(schema.ast)
|
|
749
|
+
if (annotation !== undefined) {
|
|
750
|
+
return Schema.Struct({
|
|
751
|
+
body: fromArrayBuffer(annotation.body),
|
|
752
|
+
headers: annotation.headersCodec
|
|
753
|
+
}).pipe(Schema.decodeTo(schema))
|
|
754
|
+
}
|
|
755
|
+
const body = isWithHeaders ? schema.schema : schema
|
|
756
|
+
return Schema.Struct({
|
|
757
|
+
body: fromArrayBuffer(body).pipe(Schema.decodeTo(body)),
|
|
758
|
+
headers: isWithHeaders ? schema.headers : Schema.Unknown
|
|
759
|
+
}).pipe(
|
|
760
|
+
Schema.decodeTo(
|
|
761
|
+
isWithHeaders ? schema : Schema.toType(schema),
|
|
762
|
+
SchemaTransformation.transform({
|
|
763
|
+
decode: (value) => isWithHeaders ? HttpApiSchema.withHeaders(value) : value.body,
|
|
764
|
+
encode: (value: any) => isWithHeaders ? value : { body: value, headers: undefined }
|
|
765
|
+
}) as any
|
|
766
|
+
)
|
|
767
|
+
)
|
|
728
768
|
}
|
|
729
769
|
|
|
730
770
|
type ResponseDecoder = (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<unknown, unknown, unknown>
|
|
@@ -768,9 +808,10 @@ function groupSchemasByContentType(
|
|
|
768
808
|
): Map<string, Arr.NonEmptyReadonlyArray<Schema.Top>> {
|
|
769
809
|
const grouped = new Map<string, [Schema.Top, ...Array<Schema.Top>]>()
|
|
770
810
|
for (const schema of schemas) {
|
|
771
|
-
const
|
|
811
|
+
const body = HttpApiSchema.isWithHeaders(schema) ? schema.schema : schema
|
|
812
|
+
const contentType = HttpApiSchema.isNoContent(body.ast)
|
|
772
813
|
? ""
|
|
773
|
-
: MediaType.normalize(HttpApiSchema.
|
|
814
|
+
: MediaType.normalize(HttpApiSchema.getResponseEncodingSchema(schema).contentType)
|
|
774
815
|
const existing = grouped.get(contentType)
|
|
775
816
|
if (existing === undefined) {
|
|
776
817
|
grouped.set(contentType, [schema])
|
|
@@ -802,24 +843,35 @@ function failUnsupportedContentType(
|
|
|
802
843
|
|
|
803
844
|
const reservedStreamFailureEvent = "effect/httpapi/stream/failure"
|
|
804
845
|
|
|
805
|
-
|
|
806
|
-
|
|
846
|
+
type StreamSuccessSchema =
|
|
847
|
+
| HttpApiSchema.StreamSchema
|
|
848
|
+
| HttpApiSchema.WithHeaders<HttpApiSchema.StreamSchema, Schema.Top>
|
|
849
|
+
|
|
850
|
+
const isWithHeadersStreamSuccess = (
|
|
851
|
+
schema: StreamSuccessSchema
|
|
852
|
+
): schema is HttpApiSchema.WithHeaders<HttpApiSchema.StreamSchema, Schema.Top> => HttpApiSchema.isWithHeaders(schema)
|
|
853
|
+
|
|
854
|
+
function getStreamSuccessSchemas(endpoint: HttpApiEndpoint.Top): Array<StreamSuccessSchema> {
|
|
855
|
+
const schemas: Array<StreamSuccessSchema> = []
|
|
807
856
|
for (const schema of endpoint.success) {
|
|
808
|
-
|
|
809
|
-
|
|
857
|
+
const body = HttpApiSchema.isWithHeaders(schema) ? schema.schema : schema
|
|
858
|
+
if (HttpApiSchema.isStreamSchema(body)) {
|
|
859
|
+
schemas.push(schema as StreamSuccessSchema)
|
|
810
860
|
}
|
|
811
861
|
}
|
|
812
862
|
return schemas
|
|
813
863
|
}
|
|
814
864
|
|
|
815
|
-
function streamToResponse(
|
|
865
|
+
function streamToResponse(successSchema: StreamSuccessSchema) {
|
|
866
|
+
const isWithHeaders = isWithHeadersStreamSuccess(successSchema)
|
|
867
|
+
const streamSchema = isWithHeaders ? successSchema.schema : successSchema
|
|
816
868
|
const sse = HttpApiSchema.isStreamUint8Array(streamSchema)
|
|
817
869
|
? undefined
|
|
818
870
|
: {
|
|
819
871
|
declaration: streamSchema,
|
|
820
872
|
decoder: makeSseDecoder(streamSchema)
|
|
821
873
|
}
|
|
822
|
-
|
|
874
|
+
const toStream = (response: HttpClientResponse.HttpClientResponse) =>
|
|
823
875
|
Effect.map(Effect.context<never>(), (context) =>
|
|
824
876
|
Stream.provideContext(
|
|
825
877
|
sse === undefined ?
|
|
@@ -827,6 +879,14 @@ function streamToResponse(streamSchema: HttpApiSchema.StreamSchema) {
|
|
|
827
879
|
decodeSseStream(response.stream, sse.declaration, sse.decoder),
|
|
828
880
|
context as Context.Context<unknown>
|
|
829
881
|
))
|
|
882
|
+
if (!isWithHeaders) return toStream
|
|
883
|
+
|
|
884
|
+
const decodeHeaders = Schema.decodeUnknownEffect(successSchema.headers)
|
|
885
|
+
return (response: HttpClientResponse.HttpClientResponse) =>
|
|
886
|
+
Effect.flatMap(
|
|
887
|
+
decodeHeaders(response.headers),
|
|
888
|
+
(headers) => Effect.map(toStream(response), (body) => HttpApiSchema.withHeaders({ body, headers }))
|
|
889
|
+
)
|
|
830
890
|
}
|
|
831
891
|
|
|
832
892
|
function makeSseDecoder(
|
|
@@ -940,31 +1000,34 @@ function toCodecArrayBuffer(schemas: readonly [Schema.Constraint, ...Array<Schem
|
|
|
940
1000
|
return Schema.Union(schemas.map(onSchema))
|
|
941
1001
|
|
|
942
1002
|
function onSchema(schema: Schema.Constraint) {
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
1003
|
+
return fromArrayBuffer(schema).pipe(Schema.decodeTo(schema))
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
function fromArrayBuffer(schema: Schema.Constraint): Schema.Top {
|
|
1008
|
+
const encoding = HttpApiSchema.getResponseEncoding(schema.ast)
|
|
1009
|
+
switch (encoding._tag) {
|
|
1010
|
+
case "Json": {
|
|
1011
|
+
// handle json codecs that transform void schemas to null
|
|
1012
|
+
const encodedIsNull = SchemaAST.isNull(SchemaAST.toEncoded(schema.ast))
|
|
1013
|
+
return encodedIsNull
|
|
1014
|
+
? UnknownFromArrayBuffer.pipe(
|
|
1015
|
+
Schema.decodeTo(
|
|
1016
|
+
Schema.Unknown,
|
|
951
1017
|
SchemaTransformation.transform({
|
|
952
1018
|
decode: (a) => a === undefined ? null : a,
|
|
953
1019
|
encode: (a) => a === null ? undefined : a
|
|
954
|
-
}) as any
|
|
955
|
-
|
|
956
|
-
))
|
|
957
|
-
}
|
|
958
|
-
case "FormUrlEncoded":
|
|
959
|
-
return StringFromArrayBuffer.pipe(
|
|
960
|
-
Schema.decodeTo(UrlParams.schemaRecord),
|
|
961
|
-
Schema.decodeTo(schema)
|
|
1020
|
+
}) as any
|
|
1021
|
+
)
|
|
962
1022
|
)
|
|
963
|
-
|
|
964
|
-
return Uint8ArrayFromArrayBuffer.pipe(Schema.decodeTo(schema))
|
|
965
|
-
case "Text":
|
|
966
|
-
return StringFromArrayBuffer.pipe(Schema.decodeTo(schema))
|
|
1023
|
+
: UnknownFromArrayBuffer
|
|
967
1024
|
}
|
|
1025
|
+
case "FormUrlEncoded":
|
|
1026
|
+
return StringFromArrayBuffer.pipe(Schema.decodeTo(UrlParams.schemaRecord))
|
|
1027
|
+
case "Uint8Array":
|
|
1028
|
+
return Uint8ArrayFromArrayBuffer
|
|
1029
|
+
case "Text":
|
|
1030
|
+
return StringFromArrayBuffer
|
|
968
1031
|
}
|
|
969
1032
|
}
|
|
970
1033
|
|
|
@@ -44,11 +44,15 @@ const TypeId = "~effect/httpapi/HttpApiEndpoint"
|
|
|
44
44
|
*/
|
|
45
45
|
export const isHttpApiEndpoint = (u: unknown): u is Top => Predicate.hasProperty(u, TypeId)
|
|
46
46
|
|
|
47
|
-
type SuccessType<S> = S extends HttpApiSchema.
|
|
48
|
-
infer
|
|
49
|
-
infer
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
type SuccessType<S> = S extends HttpApiSchema.WithHeaders<
|
|
48
|
+
infer _Inner,
|
|
49
|
+
infer _Headers
|
|
50
|
+
> ? HttpApiSchema.withHeaders<SuccessType<_Inner>, _Headers["Type"]>
|
|
51
|
+
: S extends HttpApiSchema.StreamSse<
|
|
52
|
+
infer _Events,
|
|
53
|
+
infer _Error,
|
|
54
|
+
infer _Value
|
|
55
|
+
> ? Stream.Stream<_Value, _Error["Type"], never>
|
|
52
56
|
: S extends HttpApiSchema.StreamUint8Array ? Stream.Stream<Uint8Array, unknown, never>
|
|
53
57
|
: S extends Schema.Constraint ? S["Type"]
|
|
54
58
|
: never
|
|
@@ -75,15 +79,24 @@ type UnwrapReadonlyArray<S> = S extends ReadonlyArray<infer A> ? A : S
|
|
|
75
79
|
|
|
76
80
|
type ExtractBufferedSuccess<S extends SuccessConstraint> = Exclude<
|
|
77
81
|
Extract<UnwrapReadonlyArray<S>, Schema.Top>,
|
|
78
|
-
HttpApiSchema.StreamSchema
|
|
82
|
+
HttpApiSchema.StreamSchema | HttpApiSchema.WithHeaders<Schema.Top, Schema.Top>
|
|
79
83
|
>
|
|
80
84
|
|
|
81
85
|
type ExtractStreamSuccess<S extends SuccessConstraint> = UnwrapReadonlyArray<S> extends infer Success ?
|
|
82
86
|
Success extends HttpApiSchema.StreamSchema ? Success : never
|
|
83
87
|
: never
|
|
84
88
|
|
|
85
|
-
type
|
|
86
|
-
|
|
89
|
+
type ExtractWithHeadersSuccess<S extends SuccessConstraint> = UnwrapReadonlyArray<S> extends infer Success ?
|
|
90
|
+
Success extends HttpApiSchema.WithHeaders<infer _Inner, infer _Headers> ? HttpApiSchema.WithHeaders<
|
|
91
|
+
_Inner extends HttpApiSchema.StreamSchema ? _Inner : Schema.toCodecJson<_Inner>,
|
|
92
|
+
Schema.toCodecStringTree<_Headers>
|
|
93
|
+
> :
|
|
94
|
+
never
|
|
95
|
+
: never
|
|
96
|
+
|
|
97
|
+
type ToSuccessCodec<S extends SuccessConstraint> = [ExtractBufferedSuccess<S>] extends [never] ?
|
|
98
|
+
ExtractStreamSuccess<S> | ExtractWithHeadersSuccess<S>
|
|
99
|
+
: Schema.toCodecJson<ExtractBufferedSuccess<S>> | ExtractStreamSuccess<S> | ExtractWithHeadersSuccess<S>
|
|
87
100
|
|
|
88
101
|
type ToJsonCodec<S> = [S] extends [never] ? never
|
|
89
102
|
: [S] extends [Schema.Constraint] ? Schema.toCodecJson<S>
|
|
@@ -945,9 +958,11 @@ export type SuccessConstraint = Schema.Top | ReadonlyArray<Schema.Top>
|
|
|
945
958
|
*/
|
|
946
959
|
export type ErrorConstraint = Schema.Top | ReadonlyArray<Schema.Top>
|
|
947
960
|
|
|
961
|
+
type ErrorSchema<S> = S extends HttpApiSchema.WithHeaders<infer Inner, Schema.Top> ? Inner : S
|
|
962
|
+
|
|
948
963
|
type ErrorNoStream<S extends ErrorConstraint> = [
|
|
949
964
|
Extract<
|
|
950
|
-
S extends ReadonlyArray<Schema.Constraint> ? S[number] : S
|
|
965
|
+
ErrorSchema<S extends ReadonlyArray<Schema.Constraint> ? S[number] : S>,
|
|
951
966
|
HttpApiSchema.StreamSchema
|
|
952
967
|
>
|
|
953
968
|
] extends [never] ? S : never
|
|
@@ -1139,11 +1154,18 @@ function getSuccessResponse(
|
|
|
1139
1154
|
if (success === undefined) return new Set()
|
|
1140
1155
|
const schemas = Arr.ensure(success)
|
|
1141
1156
|
validateSuccessResponse(schemas, method)
|
|
1142
|
-
return new Set(
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
)
|
|
1157
|
+
return new Set(disableCodecs ? schemas : schemas.map(transformResponseSchema))
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
function transformResponseSchema(schema: Schema.Top): Schema.Top {
|
|
1161
|
+
if (HttpApiSchema.isStreamSchema(schema)) return schema
|
|
1162
|
+
if (HttpApiSchema.isWithHeaders(schema)) {
|
|
1163
|
+
const inner = HttpApiSchema.isStreamSchema(schema.schema)
|
|
1164
|
+
? schema.schema
|
|
1165
|
+
: applyResponseEncoding(schema.schema, HttpApiSchema.getResponseEncodingSchema(schema))
|
|
1166
|
+
return HttpApiSchema.rebuildWithHeaders(schema, inner, Schema.toCodecStringTree(schema.headers))
|
|
1167
|
+
}
|
|
1168
|
+
return transformResponse(schema)
|
|
1147
1169
|
}
|
|
1148
1170
|
|
|
1149
1171
|
function getErrorResponse(
|
|
@@ -1153,14 +1175,17 @@ function getErrorResponse(
|
|
|
1153
1175
|
if (error === undefined) return new Set()
|
|
1154
1176
|
const schemas = Arr.ensure(error)
|
|
1155
1177
|
for (const schema of schemas) {
|
|
1156
|
-
|
|
1178
|
+
const body = HttpApiSchema.isWithHeaders(schema) ? schema.schema : schema
|
|
1179
|
+
if (HttpApiSchema.isStreamSchema(body)) {
|
|
1157
1180
|
throw new Error("Streaming schemas are not supported in error responses")
|
|
1158
1181
|
}
|
|
1159
1182
|
}
|
|
1160
|
-
|
|
1183
|
+
validateResponseExclusivity(schemas, HttpApiSchema.getStatusErrorSchema)
|
|
1184
|
+
return new Set(disableCodecs ? schemas : schemas.map(transformResponseSchema))
|
|
1161
1185
|
}
|
|
1162
1186
|
|
|
1163
1187
|
function validateSuccessResponse(schemas: ReadonlyArray<Schema.Constraint>, method: HttpMethod) {
|
|
1188
|
+
let hasStream = false
|
|
1164
1189
|
const statuses = new Map<number, {
|
|
1165
1190
|
readonly stream?: HttpApiSchema.StreamSchema | undefined
|
|
1166
1191
|
bufferedContentTypes: Set<string>
|
|
@@ -1168,31 +1193,32 @@ function validateSuccessResponse(schemas: ReadonlyArray<Schema.Constraint>, meth
|
|
|
1168
1193
|
}>()
|
|
1169
1194
|
|
|
1170
1195
|
for (const schema of schemas) {
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
if (
|
|
1176
|
-
throw new Error(
|
|
1196
|
+
const inner = HttpApiSchema.isWithHeaders(schema) ? schema.schema : schema
|
|
1197
|
+
const status = HttpApiSchema.getStatusSuccessSchema(schema)
|
|
1198
|
+
if (HttpApiSchema.isStreamSchema(inner)) {
|
|
1199
|
+
validateStreamSuccess(inner, method)
|
|
1200
|
+
if (hasStream) {
|
|
1201
|
+
throw new Error("Multiple streaming success responses are not supported")
|
|
1177
1202
|
}
|
|
1203
|
+
hasStream = true
|
|
1204
|
+
const entry = getStatusEntry(statuses, status)
|
|
1178
1205
|
if (entry.noContent) {
|
|
1179
1206
|
throw new Error(`Cannot combine no-content and streaming success responses for status: ${status}`)
|
|
1180
1207
|
}
|
|
1181
|
-
if (entry.bufferedContentTypes.has(MediaType.normalize(
|
|
1208
|
+
if (entry.bufferedContentTypes.has(MediaType.normalize(inner.contentType))) {
|
|
1182
1209
|
throw new Error(
|
|
1183
|
-
`Cannot combine buffered and streaming success responses for status ${status} and content-type: ${
|
|
1210
|
+
`Cannot combine buffered and streaming success responses for status ${status} and content-type: ${inner.contentType}`
|
|
1184
1211
|
)
|
|
1185
1212
|
}
|
|
1186
|
-
statuses.set(status, { ...entry, stream:
|
|
1213
|
+
statuses.set(status, { ...entry, stream: inner })
|
|
1187
1214
|
} else {
|
|
1188
|
-
const status = HttpApiSchema.getStatusSuccess(schema.ast)
|
|
1189
1215
|
const entry = getStatusEntry(statuses, status)
|
|
1190
|
-
const noContent = HttpApiSchema.isNoContent(
|
|
1216
|
+
const noContent = HttpApiSchema.isNoContent(inner.ast)
|
|
1191
1217
|
if (entry.stream !== undefined) {
|
|
1192
1218
|
if (noContent) {
|
|
1193
1219
|
throw new Error(`Cannot combine no-content and streaming success responses for status: ${status}`)
|
|
1194
1220
|
}
|
|
1195
|
-
const encoding = HttpApiSchema.
|
|
1221
|
+
const encoding = HttpApiSchema.getResponseEncodingSchema(schema)
|
|
1196
1222
|
if (
|
|
1197
1223
|
MediaType.normalize(encoding.contentType) === MediaType.normalize(entry.stream.contentType)
|
|
1198
1224
|
) {
|
|
@@ -1203,12 +1229,14 @@ function validateSuccessResponse(schemas: ReadonlyArray<Schema.Constraint>, meth
|
|
|
1203
1229
|
}
|
|
1204
1230
|
if (!noContent) {
|
|
1205
1231
|
entry.bufferedContentTypes.add(
|
|
1206
|
-
MediaType.normalize(HttpApiSchema.
|
|
1232
|
+
MediaType.normalize(HttpApiSchema.getResponseEncodingSchema(schema).contentType)
|
|
1207
1233
|
)
|
|
1208
1234
|
}
|
|
1209
1235
|
entry.noContent = entry.noContent || noContent
|
|
1210
1236
|
}
|
|
1211
1237
|
}
|
|
1238
|
+
|
|
1239
|
+
validateResponseExclusivity(schemas, HttpApiSchema.getStatusSuccessSchema)
|
|
1212
1240
|
}
|
|
1213
1241
|
|
|
1214
1242
|
function getStatusEntry(
|
|
@@ -1227,6 +1255,49 @@ function getStatusEntry(
|
|
|
1227
1255
|
return entry
|
|
1228
1256
|
}
|
|
1229
1257
|
|
|
1258
|
+
function validateResponseExclusivity(
|
|
1259
|
+
schemas: ReadonlyArray<Schema.Constraint>,
|
|
1260
|
+
getStatus: (schema: Schema.Constraint) => number
|
|
1261
|
+
) {
|
|
1262
|
+
const statuses = new Map<number, {
|
|
1263
|
+
headerContentType: string | undefined
|
|
1264
|
+
readonly plainContentTypes: Set<string>
|
|
1265
|
+
}>()
|
|
1266
|
+
for (const schema of schemas) {
|
|
1267
|
+
const status = getStatus(schema)
|
|
1268
|
+
const withHeadersAnnotation = HttpApiSchema.getWithHeadersAnnotation(schema.ast)
|
|
1269
|
+
const body = HttpApiSchema.isWithHeaders(schema) ? schema.schema : withHeadersAnnotation?.body ?? schema
|
|
1270
|
+
const contentType = HttpApiSchema.isNoContent(body.ast)
|
|
1271
|
+
? ""
|
|
1272
|
+
: MediaType.normalize(
|
|
1273
|
+
HttpApiSchema.isStreamSchema(body)
|
|
1274
|
+
? body.contentType
|
|
1275
|
+
: HttpApiSchema.getResponseEncodingSchema(schema).contentType
|
|
1276
|
+
)
|
|
1277
|
+
let entry = statuses.get(status)
|
|
1278
|
+
if (entry === undefined) {
|
|
1279
|
+
entry = { headerContentType: undefined, plainContentTypes: new Set() }
|
|
1280
|
+
statuses.set(status, entry)
|
|
1281
|
+
}
|
|
1282
|
+
const combineError = () =>
|
|
1283
|
+
new Error(
|
|
1284
|
+
`Cannot combine a response with headers with another response for status ${status} and content-type: ${
|
|
1285
|
+
contentType || "<no content>"
|
|
1286
|
+
}`
|
|
1287
|
+
)
|
|
1288
|
+
if (HttpApiSchema.isWithHeaders(schema) || withHeadersAnnotation !== undefined) {
|
|
1289
|
+
if (entry.headerContentType !== undefined) {
|
|
1290
|
+
throw new Error(`Cannot declare multiple responses with headers for status ${status}`)
|
|
1291
|
+
}
|
|
1292
|
+
if (entry.plainContentTypes.has(contentType)) throw combineError()
|
|
1293
|
+
entry.headerContentType = contentType
|
|
1294
|
+
} else {
|
|
1295
|
+
if (entry.headerContentType === contentType) throw combineError()
|
|
1296
|
+
entry.plainContentTypes.add(contentType)
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1230
1301
|
function validateStreamSuccess(schema: HttpApiSchema.StreamSchema, method: HttpMethod) {
|
|
1231
1302
|
if (method === "HEAD") {
|
|
1232
1303
|
throw new Error("HEAD endpoints cannot declare streaming success responses")
|
|
@@ -1275,6 +1346,23 @@ function hasReservedEventLiteral(ast: AST.AST, seen: Set<AST.AST>): boolean {
|
|
|
1275
1346
|
|
|
1276
1347
|
function transformResponse(schema: Schema.Top): Schema.Top {
|
|
1277
1348
|
const encoding = HttpApiSchema.getResponseEncoding(schema.ast)
|
|
1349
|
+
const withHeaders = HttpApiSchema.getWithHeadersAnnotation(schema.ast)
|
|
1350
|
+
if (withHeaders === undefined) {
|
|
1351
|
+
return applyResponseEncoding(schema, encoding)
|
|
1352
|
+
}
|
|
1353
|
+
const headers = Schema.toEncoded(withHeaders.headers)
|
|
1354
|
+
return Schema.Struct({
|
|
1355
|
+
body: applyResponseEncoding(Schema.toEncoded(withHeaders.body), encoding),
|
|
1356
|
+
headers
|
|
1357
|
+
}).pipe(Schema.decodeTo(schema)).annotate({
|
|
1358
|
+
"~httpApiWithHeaders": {
|
|
1359
|
+
...withHeaders,
|
|
1360
|
+
headersCodec: Schema.toCodecStringTree(headers)
|
|
1361
|
+
}
|
|
1362
|
+
})
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
function applyResponseEncoding(schema: Schema.Top, encoding: HttpApiSchema.ResponseEncoding): Schema.Top {
|
|
1278
1366
|
switch (encoding._tag) {
|
|
1279
1367
|
case "Json":
|
|
1280
1368
|
return Schema.toCodecJson(schema)
|