effect 4.0.0-beta.30 → 4.0.0-beta.32
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/Array.d.ts +87 -86
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +47 -40
- package/dist/Array.js.map +1 -1
- package/dist/BigDecimal.d.ts +46 -45
- package/dist/BigDecimal.d.ts.map +1 -1
- package/dist/BigDecimal.js +35 -38
- package/dist/BigDecimal.js.map +1 -1
- package/dist/BigInt.d.ts +39 -32
- package/dist/BigInt.d.ts.map +1 -1
- package/dist/BigInt.js +32 -29
- package/dist/BigInt.js.map +1 -1
- package/dist/Channel.d.ts +2 -2
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js.map +1 -1
- package/dist/Chunk.d.ts +58 -57
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js +20 -21
- package/dist/Chunk.js.map +1 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +4 -1
- package/dist/Config.js.map +1 -1
- package/dist/Cron.d.ts +3 -6
- package/dist/Cron.d.ts.map +1 -1
- package/dist/Cron.js +11 -18
- package/dist/Cron.js.map +1 -1
- package/dist/DateTime.d.ts +49 -92
- package/dist/DateTime.d.ts.map +1 -1
- package/dist/DateTime.js +9 -9
- package/dist/DateTime.js.map +1 -1
- package/dist/Deferred.d.ts +7 -5
- package/dist/Deferred.d.ts.map +1 -1
- package/dist/Deferred.js +7 -5
- package/dist/Deferred.js.map +1 -1
- package/dist/Duration.d.ts +55 -25
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +100 -70
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +3 -4
- package/dist/Effect.js.map +1 -1
- package/dist/Fiber.d.ts +2 -1
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Fiber.js.map +1 -1
- package/dist/FiberHandle.d.ts +9 -8
- package/dist/FiberHandle.d.ts.map +1 -1
- package/dist/FiberHandle.js +8 -7
- package/dist/FiberHandle.js.map +1 -1
- package/dist/FiberMap.d.ts +20 -19
- package/dist/FiberMap.d.ts.map +1 -1
- package/dist/FiberMap.js +6 -6
- package/dist/FiberMap.js.map +1 -1
- package/dist/FileSystem.d.ts +17 -16
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js +10 -7
- package/dist/FileSystem.js.map +1 -1
- package/dist/Graph.d.ts +64 -64
- package/dist/Graph.d.ts.map +1 -1
- package/dist/Graph.js +53 -53
- package/dist/Graph.js.map +1 -1
- package/dist/HashMap.d.ts +11 -5
- package/dist/HashMap.d.ts.map +1 -1
- package/dist/HashMap.js +3 -1
- package/dist/HashMap.js.map +1 -1
- package/dist/Iterable.d.ts +11 -11
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +12 -12
- package/dist/Iterable.js.map +1 -1
- package/dist/Latch.d.ts +69 -3
- package/dist/Latch.d.ts.map +1 -1
- package/dist/Latch.js +58 -0
- package/dist/Latch.js.map +1 -1
- package/dist/Layer.d.ts +181 -2
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +35 -2
- package/dist/Layer.js.map +1 -1
- package/dist/Number.d.ts +74 -18
- package/dist/Number.d.ts.map +1 -1
- package/dist/Number.js +34 -15
- package/dist/Number.js.map +1 -1
- package/dist/Option.d.ts +2 -0
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js.map +1 -1
- package/dist/PartitionedSemaphore.d.ts +183 -0
- package/dist/PartitionedSemaphore.d.ts.map +1 -0
- package/dist/PartitionedSemaphore.js +231 -0
- package/dist/PartitionedSemaphore.js.map +1 -0
- package/dist/PubSub.d.ts +5 -4
- package/dist/PubSub.d.ts.map +1 -1
- package/dist/PubSub.js +6 -5
- package/dist/PubSub.js.map +1 -1
- package/dist/Queue.d.ts +3 -3
- package/dist/Queue.d.ts.map +1 -1
- package/dist/Queue.js +2 -2
- package/dist/Queue.js.map +1 -1
- package/dist/Record.d.ts +40 -40
- package/dist/Record.d.ts.map +1 -1
- package/dist/Record.js +16 -15
- package/dist/Record.js.map +1 -1
- package/dist/Scheduler.d.ts +25 -123
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +20 -123
- package/dist/Scheduler.js.map +1 -1
- package/dist/Schema.d.ts +2346 -114
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +1359 -68
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +2 -2
- package/dist/SchemaAST.js +2 -2
- package/dist/SchemaGetter.js +6 -4
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +2 -2
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +32 -27
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/Semaphore.d.ts +149 -53
- package/dist/Semaphore.d.ts.map +1 -1
- package/dist/Semaphore.js +137 -117
- package/dist/Semaphore.js.map +1 -1
- package/dist/ServiceMap.d.ts +26 -0
- package/dist/ServiceMap.d.ts.map +1 -1
- package/dist/ServiceMap.js +36 -21
- package/dist/ServiceMap.js.map +1 -1
- package/dist/Stream.js +1 -1
- package/dist/Stream.js.map +1 -1
- package/dist/String.d.ts +114 -47
- package/dist/String.d.ts.map +1 -1
- package/dist/String.js +29 -47
- package/dist/String.js.map +1 -1
- package/dist/SubscriptionRef.d.ts +1 -2
- package/dist/SubscriptionRef.d.ts.map +1 -1
- package/dist/SubscriptionRef.js +81 -115
- package/dist/SubscriptionRef.js.map +1 -1
- package/dist/Terminal.d.ts +2 -1
- package/dist/Terminal.d.ts.map +1 -1
- package/dist/Terminal.js.map +1 -1
- package/dist/Tracer.d.ts +5 -4
- package/dist/Tracer.d.ts.map +1 -1
- package/dist/Tracer.js +2 -1
- package/dist/Tracer.js.map +1 -1
- package/dist/Trie.d.ts +26 -14
- package/dist/Trie.d.ts.map +1 -1
- package/dist/Trie.js +8 -4
- package/dist/Trie.js.map +1 -1
- package/dist/TxHashMap.d.ts +77 -59
- package/dist/TxHashMap.d.ts.map +1 -1
- package/dist/TxHashMap.js +25 -19
- package/dist/TxHashMap.js.map +1 -1
- package/dist/TxSemaphore.d.ts +162 -2
- package/dist/TxSemaphore.d.ts.map +1 -1
- package/dist/TxSemaphore.js +16 -2
- package/dist/TxSemaphore.js.map +1 -1
- package/dist/index.d.ts +88 -32
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +88 -32
- package/dist/index.js.map +1 -1
- package/dist/internal/dateTime.js +66 -59
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +21 -90
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/hashMap.js +2 -1
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/option.js +6 -0
- package/dist/internal/option.js.map +1 -1
- package/dist/internal/trie.js +3 -3
- package/dist/internal/trie.js.map +1 -1
- package/dist/unstable/ai/AiError.js +1 -1
- package/dist/unstable/ai/AiError.js.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.js +4 -0
- package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +3 -4
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js +2 -2
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +30 -16
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +10 -87
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.js +4 -0
- package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +14 -0
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +13 -0
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/Argument.d.ts +2 -4
- package/dist/unstable/cli/Argument.d.ts.map +1 -1
- package/dist/unstable/cli/Argument.js +1 -3
- package/dist/unstable/cli/Argument.js.map +1 -1
- package/dist/unstable/cli/CliOutput.d.ts +3 -2
- package/dist/unstable/cli/CliOutput.d.ts.map +1 -1
- package/dist/unstable/cli/CliOutput.js +4 -3
- package/dist/unstable/cli/CliOutput.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +3 -2
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +3 -3
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/Completions.d.ts +16 -0
- package/dist/unstable/cli/Completions.d.ts.map +1 -0
- package/dist/unstable/cli/Completions.js +23 -0
- package/dist/unstable/cli/Completions.js.map +1 -0
- package/dist/unstable/cli/Flag.d.ts +2 -2
- package/dist/unstable/cli/Flag.d.ts.map +1 -1
- package/dist/unstable/cli/Flag.js +1 -1
- package/dist/unstable/cli/Flag.js.map +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
- package/dist/unstable/cli/GlobalFlag.js +4 -4
- package/dist/unstable/cli/GlobalFlag.js.map +1 -1
- package/dist/unstable/cli/HelpDoc.d.ts +14 -12
- package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
- package/dist/unstable/cli/Param.d.ts +4 -4
- package/dist/unstable/cli/Param.d.ts.map +1 -1
- package/dist/unstable/cli/Param.js +7 -7
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/Primitive.d.ts +1 -1
- package/dist/unstable/cli/Primitive.d.ts.map +1 -1
- package/dist/unstable/cli/Primitive.js.map +1 -1
- package/dist/unstable/cli/Prompt.js +71 -67
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +4 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +4 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cli/internal/completions/CommandDescriptor.js +9 -2
- package/dist/unstable/cli/internal/completions/CommandDescriptor.js.map +1 -1
- package/dist/unstable/cli/internal/parser.js +8 -3
- package/dist/unstable/cli/internal/parser.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +3 -2
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +25 -23
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/DeliverAt.js +1 -1
- package/dist/unstable/cluster/DeliverAt.js.map +1 -1
- package/dist/unstable/cluster/Entity.d.ts +3 -2
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/Entity.js +7 -7
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/Message.d.ts +4 -3
- package/dist/unstable/cluster/Message.d.ts.map +1 -1
- package/dist/unstable/cluster/Message.js +3 -2
- package/dist/unstable/cluster/Message.js.map +1 -1
- package/dist/unstable/cluster/MessageStorage.d.ts +10 -10
- package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/MessageStorage.js +12 -12
- package/dist/unstable/cluster/MessageStorage.js.map +1 -1
- package/dist/unstable/cluster/Reply.d.ts +2 -1
- package/dist/unstable/cluster/Reply.d.ts.map +1 -1
- package/dist/unstable/cluster/Reply.js +4 -3
- 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 +9 -8
- package/dist/unstable/cluster/RunnerServer.js.map +1 -1
- package/dist/unstable/cluster/Runners.d.ts +2 -1
- package/dist/unstable/cluster/Runners.d.ts.map +1 -1
- package/dist/unstable/cluster/Runners.js +7 -6
- package/dist/unstable/cluster/Runners.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +19 -13
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.d.ts +5 -4
- package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.js +4 -4
- package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.js +19 -18
- package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +9 -10
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/devtools/DevToolsSchema.d.ts +2 -1
- package/dist/unstable/devtools/DevToolsSchema.d.ts.map +1 -1
- package/dist/unstable/devtools/DevToolsSchema.js +1 -4
- package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +8 -8
- package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
- package/dist/unstable/encoding/Ndjson.js.map +1 -1
- package/dist/unstable/http/Cookies.d.ts +5 -4
- package/dist/unstable/http/Cookies.d.ts.map +1 -1
- package/dist/unstable/http/Cookies.js +3 -4
- package/dist/unstable/http/Cookies.js.map +1 -1
- package/dist/unstable/http/Etag.d.ts.map +1 -1
- package/dist/unstable/http/Etag.js +5 -1
- package/dist/unstable/http/Etag.js.map +1 -1
- package/dist/unstable/http/Headers.d.ts +3 -2
- package/dist/unstable/http/Headers.d.ts.map +1 -1
- package/dist/unstable/http/Headers.js +2 -1
- package/dist/unstable/http/Headers.js.map +1 -1
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +2 -1
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts +4 -3
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +8 -6
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpClientResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientResponse.js +2 -1
- package/dist/unstable/http/HttpClientResponse.js.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts +3 -2
- package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
- package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/unstable/http/HttpMiddleware.js +16 -15
- package/dist/unstable/http/HttpMiddleware.js.map +1 -1
- package/dist/unstable/http/HttpPlatform.d.ts.map +1 -1
- package/dist/unstable/http/HttpPlatform.js +3 -2
- package/dist/unstable/http/HttpPlatform.js.map +1 -1
- package/dist/unstable/http/HttpRouter.d.ts +2 -1
- package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
- package/dist/unstable/http/HttpRouter.js +7 -7
- package/dist/unstable/http/HttpRouter.js.map +1 -1
- package/dist/unstable/http/HttpServer.d.ts.map +1 -1
- package/dist/unstable/http/HttpServer.js +2 -2
- package/dist/unstable/http/HttpServer.js.map +1 -1
- package/dist/unstable/http/HttpServerError.d.ts +2 -1
- package/dist/unstable/http/HttpServerError.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerError.js +2 -1
- package/dist/unstable/http/HttpServerError.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts +3 -2
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +14 -10
- 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 +4 -3
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/HttpTraceContext.d.ts +3 -2
- package/dist/unstable/http/HttpTraceContext.d.ts.map +1 -1
- package/dist/unstable/http/HttpTraceContext.js +27 -15
- package/dist/unstable/http/HttpTraceContext.js.map +1 -1
- package/dist/unstable/http/UrlParams.d.ts +5 -4
- package/dist/unstable/http/UrlParams.d.ts.map +1 -1
- package/dist/unstable/http/UrlParams.js +5 -6
- package/dist/unstable/http/UrlParams.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +4 -2
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +15 -0
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +81 -3
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.js +2 -2
- package/dist/unstable/observability/OtlpExporter.js.map +1 -1
- package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpTracer.js +7 -3
- package/dist/unstable/observability/OtlpTracer.js.map +1 -1
- package/dist/unstable/persistence/Persistable.js +1 -1
- package/dist/unstable/persistence/Persistable.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +1 -5
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js +4 -2
- package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js +4 -3
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +4 -4
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcGroup.d.ts +1 -3
- package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSchema.js +3 -2
- package/dist/unstable/rpc/RpcSchema.js.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.js +4 -1
- package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +3 -2
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +2 -1
- 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 +1 -1
- package/dist/unstable/sql/SqlClient.js.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.js +6 -6
- package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +2 -1
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +5 -4
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +19 -14
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +112 -105
- package/src/BigDecimal.ts +63 -66
- package/src/BigInt.ts +49 -41
- package/src/Channel.ts +3 -3
- package/src/Chunk.ts +68 -63
- package/src/Config.ts +4 -1
- package/src/Cron.ts +13 -18
- package/src/DateTime.ts +51 -92
- package/src/Deferred.ts +8 -6
- package/src/Duration.ts +112 -56
- package/src/Effect.ts +3 -4
- package/src/Fiber.ts +2 -1
- package/src/FiberHandle.ts +10 -9
- package/src/FiberMap.ts +22 -22
- package/src/FileSystem.ts +25 -22
- package/src/Graph.ts +105 -105
- package/src/HashMap.ts +11 -5
- package/src/Iterable.ts +13 -13
- package/src/Latch.ts +85 -3
- package/src/Layer.ts +244 -19
- package/src/Number.ts +85 -26
- package/src/Option.ts +2 -0
- package/src/PartitionedSemaphore.ts +414 -0
- package/src/PubSub.ts +7 -6
- package/src/Queue.ts +5 -5
- package/src/Record.ts +52 -47
- package/src/Scheduler.ts +37 -126
- package/src/Schema.ts +2366 -116
- package/src/SchemaAST.ts +2 -2
- package/src/SchemaGetter.ts +4 -4
- package/src/SchemaRepresentation.ts +2 -2
- package/src/SchemaTransformation.ts +27 -27
- package/src/Semaphore.ts +271 -183
- package/src/ServiceMap.ts +83 -31
- package/src/Stream.ts +1 -1
- package/src/String.ts +122 -69
- package/src/SubscriptionRef.ts +96 -117
- package/src/Terminal.ts +2 -1
- package/src/Tracer.ts +6 -5
- package/src/Trie.ts +26 -14
- package/src/TxHashMap.ts +78 -60
- package/src/TxSemaphore.ts +186 -11
- package/src/index.ts +89 -33
- package/src/internal/dateTime.ts +74 -65
- package/src/internal/effect.ts +30 -122
- package/src/internal/hashMap.ts +4 -3
- package/src/internal/option.ts +7 -0
- package/src/internal/trie.ts +6 -6
- package/src/unstable/ai/AiError.ts +1 -1
- package/src/unstable/ai/AnthropicStructuredOutput.ts +4 -0
- package/src/unstable/ai/Chat.ts +17 -15
- package/src/unstable/ai/LanguageModel.ts +148 -97
- package/src/unstable/ai/OpenAiStructuredOutput.ts +4 -0
- package/src/unstable/ai/Tool.ts +20 -0
- package/src/unstable/cli/Argument.ts +2 -4
- package/src/unstable/cli/CliOutput.ts +7 -5
- package/src/unstable/cli/Command.ts +5 -5
- package/src/unstable/cli/Completions.ts +36 -0
- package/src/unstable/cli/Flag.ts +2 -2
- package/src/unstable/cli/GlobalFlag.ts +4 -5
- package/src/unstable/cli/HelpDoc.ts +14 -12
- package/src/unstable/cli/Param.ts +15 -11
- package/src/unstable/cli/Primitive.ts +1 -1
- package/src/unstable/cli/Prompt.ts +81 -83
- package/src/unstable/cli/index.ts +5 -0
- package/src/unstable/cli/internal/completions/CommandDescriptor.ts +3 -2
- package/src/unstable/cli/internal/parser.ts +7 -4
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +35 -30
- package/src/unstable/cluster/DeliverAt.ts +1 -1
- package/src/unstable/cluster/Entity.ts +13 -12
- package/src/unstable/cluster/Message.ts +6 -5
- package/src/unstable/cluster/MessageStorage.ts +26 -25
- package/src/unstable/cluster/Reply.ts +7 -4
- package/src/unstable/cluster/RunnerServer.ts +10 -13
- package/src/unstable/cluster/Runners.ts +8 -7
- package/src/unstable/cluster/Sharding.ts +24 -17
- package/src/unstable/cluster/ShardingConfig.ts +6 -6
- package/src/unstable/cluster/SqlMessageStorage.ts +21 -18
- package/src/unstable/cluster/internal/entityManager.ts +27 -21
- package/src/unstable/devtools/DevToolsSchema.ts +3 -2
- package/src/unstable/encoding/Ndjson.ts +17 -17
- package/src/unstable/http/Cookies.ts +7 -8
- package/src/unstable/http/Etag.ts +5 -3
- package/src/unstable/http/Headers.ts +6 -5
- package/src/unstable/http/HttpClient.ts +2 -1
- package/src/unstable/http/HttpClientRequest.ts +11 -9
- package/src/unstable/http/HttpClientResponse.ts +5 -4
- package/src/unstable/http/HttpIncomingMessage.ts +3 -2
- package/src/unstable/http/HttpMiddleware.ts +16 -15
- package/src/unstable/http/HttpPlatform.ts +3 -2
- package/src/unstable/http/HttpRouter.ts +9 -9
- package/src/unstable/http/HttpServer.ts +3 -9
- package/src/unstable/http/HttpServerError.ts +3 -2
- package/src/unstable/http/HttpServerRequest.ts +29 -25
- package/src/unstable/http/HttpServerResponse.ts +7 -6
- package/src/unstable/http/HttpTraceContext.ts +31 -17
- package/src/unstable/http/UrlParams.ts +11 -14
- package/src/unstable/httpapi/HttpApiBuilder.ts +13 -7
- package/src/unstable/httpapi/HttpApiError.ts +67 -12
- package/src/unstable/observability/OtlpExporter.ts +5 -2
- package/src/unstable/observability/OtlpTracer.ts +8 -4
- package/src/unstable/persistence/Persistable.ts +1 -1
- package/src/unstable/reactivity/Atom.ts +1 -4
- package/src/unstable/reactivity/AtomRegistry.ts +5 -3
- package/src/unstable/rpc/Rpc.ts +4 -3
- package/src/unstable/rpc/RpcClient.ts +10 -9
- package/src/unstable/rpc/RpcGroup.ts +3 -3
- package/src/unstable/rpc/RpcSchema.ts +6 -5
- package/src/unstable/rpc/RpcSerialization.ts +4 -1
- package/src/unstable/rpc/RpcServer.ts +3 -3
- package/src/unstable/socket/Socket.ts +2 -1
- package/src/unstable/sql/SqlClient.ts +5 -3
- package/src/unstable/workflow/DurableDeferred.ts +6 -6
- package/src/unstable/workflow/Workflow.ts +1 -1
- package/src/unstable/workflow/WorkflowEngine.ts +29 -20
- package/dist/NullOr.d.ts +0 -149
- package/dist/NullOr.d.ts.map +0 -1
- package/dist/NullOr.js +0 -152
- package/dist/NullOr.js.map +0 -1
- package/dist/unstable/cli/internal/completions/Completions.d.ts +0 -2
- package/dist/unstable/cli/internal/completions/Completions.d.ts.map +0 -1
- package/dist/unstable/cli/internal/completions/Completions.js +0 -23
- package/dist/unstable/cli/internal/completions/Completions.js.map +0 -1
- package/src/NullOr.ts +0 -204
- package/src/unstable/cli/internal/completions/Completions.ts +0 -31
package/dist/Schema.d.ts
CHANGED
|
@@ -1,4 +1,86 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Define data shapes, validate unknown input, and transform values between formats.
|
|
3
|
+
*
|
|
4
|
+
* ## Mental model
|
|
5
|
+
*
|
|
6
|
+
* - **Schema** — a description of a data shape. Every schema carries a decoded
|
|
7
|
+
* *Type* (the value you work with) and an *Encoded* representation (the
|
|
8
|
+
* serialized form, e.g. JSON).
|
|
9
|
+
* - **Decoding** — turning unknown external data (API responses, form
|
|
10
|
+
* submissions, config files) into typed, validated values.
|
|
11
|
+
* - **Encoding** — turning typed values back into a serializable format.
|
|
12
|
+
* - **Codec** — a schema that tracks both Type and Encoded, so it can decode
|
|
13
|
+
* *and* encode. Most concrete schemas are Codecs.
|
|
14
|
+
* - **Check / Filter** — a constraint attached to a schema (e.g. `isMinLength`,
|
|
15
|
+
* `isGreaterThan`). Attach them with `.check(...)`.
|
|
16
|
+
* - **Transformation** — a pair of functions (decode + encode) that convert
|
|
17
|
+
* values between two schemas. Created with {@link decodeTo} / {@link encodeTo}.
|
|
18
|
+
* - **Annotation** — metadata attached to a schema (title, description, custom
|
|
19
|
+
* keys). Attach with `.annotate(...)`.
|
|
20
|
+
*
|
|
21
|
+
* ## Common tasks
|
|
22
|
+
*
|
|
23
|
+
* - Define a struct: {@link Struct}
|
|
24
|
+
* - Define a union: {@link Union}, {@link TaggedUnion}, {@link Literals}
|
|
25
|
+
* - Define an array: {@link Array}, {@link NonEmptyArray}
|
|
26
|
+
* - Define a record: {@link Record}
|
|
27
|
+
* - Define a tuple: {@link Tuple}, {@link TupleWithRest}
|
|
28
|
+
* - Validate unknown data synchronously: {@link decodeUnknownSync}
|
|
29
|
+
* - Validate unknown data (Effect): {@link decodeUnknownEffect}
|
|
30
|
+
* - Encode a value: {@link encodeUnknownSync}, {@link encodeUnknownEffect}
|
|
31
|
+
* - Type guard: {@link is}
|
|
32
|
+
* - Assertion: {@link asserts}
|
|
33
|
+
* - Add constraints: `.check(...)` with filters like {@link isMinLength},
|
|
34
|
+
* {@link isGreaterThan}, {@link isPattern}, {@link isUUID}
|
|
35
|
+
* - Transform between schemas: {@link decodeTo}, {@link encodeTo}
|
|
36
|
+
* - Add a default for missing keys: {@link withDecodingDefault}, {@link withDecodingDefaultKey}
|
|
37
|
+
* - Create branded types: {@link brand}
|
|
38
|
+
* - Define classes with validation: {@link Class}, {@link TaggedClass}
|
|
39
|
+
* - Define error classes: {@link ErrorClass}, {@link TaggedErrorClass}
|
|
40
|
+
* - Generate JSON Schema: {@link toJsonSchemaDocument}
|
|
41
|
+
* - Generate test data: {@link toArbitrary}
|
|
42
|
+
* - Derive equivalence: {@link toEquivalence}
|
|
43
|
+
*
|
|
44
|
+
* ## Gotchas
|
|
45
|
+
*
|
|
46
|
+
* - `Schema.optional` creates `T | undefined` (key can be missing *or*
|
|
47
|
+
* `undefined`). Use `Schema.optionalKey` for exact optional properties.
|
|
48
|
+
* - `decodeTo` is curried: use `from.pipe(Schema.decodeTo(to, ...))`.
|
|
49
|
+
* - `decodeUnknownSync` throws on failure. Use `decodeUnknownExit` or
|
|
50
|
+
* `decodeUnknownOption` for non-throwing alternatives.
|
|
51
|
+
* - Filters do not change the TypeScript type. Use {@link refine} or
|
|
52
|
+
* {@link brand} to narrow the type.
|
|
53
|
+
* - Recursive schemas require {@link suspend} to avoid infinite loops.
|
|
54
|
+
*
|
|
55
|
+
* ## Quickstart
|
|
56
|
+
*
|
|
57
|
+
* **Example** (Validate a user object)
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { Schema } from "effect"
|
|
61
|
+
*
|
|
62
|
+
* const User = Schema.Struct({
|
|
63
|
+
* name: Schema.String.check(Schema.isMinLength(1)),
|
|
64
|
+
* age: Schema.Number.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
65
|
+
* email: Schema.optionalKey(Schema.String)
|
|
66
|
+
* })
|
|
67
|
+
*
|
|
68
|
+
* // Decode unknown input — throws on failure
|
|
69
|
+
* const user = Schema.decodeUnknownSync(User)({
|
|
70
|
+
* name: "Alice",
|
|
71
|
+
* age: 30
|
|
72
|
+
* })
|
|
73
|
+
*
|
|
74
|
+
* console.log(user)
|
|
75
|
+
* // { name: "Alice", age: 30 }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @see {@link Schema} — type-level view tracking only the decoded Type
|
|
79
|
+
* @see {@link Codec} — type-level view tracking both Type and Encoded
|
|
80
|
+
* @see {@link Struct} — define object shapes
|
|
81
|
+
* @see {@link decodeUnknownSync} — synchronous validation
|
|
82
|
+
* @see {@link decodeTo} — schema transformations
|
|
83
|
+
*
|
|
2
84
|
* @since 4.0.0
|
|
3
85
|
*/
|
|
4
86
|
/** @effect-diagnostics schemaStructWithTag:skip-file */
|
|
@@ -37,26 +119,39 @@ import type { UnionToIntersection } from "./Types.ts";
|
|
|
37
119
|
import type { Unify } from "./Unify.ts";
|
|
38
120
|
declare const TypeId = "~effect/Schema/Schema";
|
|
39
121
|
/**
|
|
40
|
-
*
|
|
122
|
+
* Whether a schema field is required or optional within a struct.
|
|
123
|
+
*
|
|
124
|
+
* @see {@link optionalKey} — mark a struct field as optional
|
|
125
|
+
* @see {@link optional} — mark a struct field as optional with `| undefined`
|
|
41
126
|
*
|
|
42
127
|
* @since 4.0.0
|
|
43
128
|
*/
|
|
44
129
|
export type Optionality = "required" | "optional";
|
|
45
130
|
/**
|
|
46
|
-
*
|
|
131
|
+
* Whether a schema field is readonly or mutable within a struct.
|
|
132
|
+
*
|
|
133
|
+
* @see {@link mutableKey} — mark a struct field as mutable
|
|
47
134
|
*
|
|
48
135
|
* @since 4.0.0
|
|
49
136
|
*/
|
|
50
137
|
export type Mutability = "readonly" | "mutable";
|
|
51
138
|
/**
|
|
52
|
-
*
|
|
139
|
+
* Whether a schema field has a constructor default value.
|
|
140
|
+
*
|
|
141
|
+
* @see {@link withConstructorDefault} — add a default to a schema field
|
|
142
|
+
* @see {@link tag} — creates a literal field with a constructor default
|
|
53
143
|
*
|
|
54
144
|
* @since 4.0.0
|
|
55
145
|
*/
|
|
56
146
|
export type ConstructorDefault = "no-default" | "with-default";
|
|
57
147
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
148
|
+
* Options for `makeUnsafe` and Class constructors.
|
|
149
|
+
*
|
|
150
|
+
* When to use:
|
|
151
|
+
* - Pass `disableValidation: true` to skip validation when you trust the data.
|
|
152
|
+
* - Pass `parseOptions` to control error reporting behavior.
|
|
153
|
+
*
|
|
154
|
+
* @see {@link Bottom.makeUnsafe}
|
|
60
155
|
*
|
|
61
156
|
* @since 4.0.0
|
|
62
157
|
*/
|
|
@@ -71,15 +166,19 @@ export interface MakeOptions {
|
|
|
71
166
|
readonly disableValidation?: boolean | undefined;
|
|
72
167
|
}
|
|
73
168
|
/**
|
|
74
|
-
* The base interface for all schemas
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* complete internal type information of schemas.
|
|
169
|
+
* The fully-parameterized base interface for all schemas. Exposes all 14 type
|
|
170
|
+
* parameters controlling type inference, mutability, optionality, services,
|
|
171
|
+
* and transformation behavior.
|
|
78
172
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
173
|
+
* When to use:
|
|
174
|
+
* - You are writing advanced generic schema utilities or performing schema
|
|
175
|
+
* introspection.
|
|
176
|
+
* - In user code, prefer {@link Schema}, {@link Codec}, {@link Decoder}, or
|
|
177
|
+
* {@link Encoder} instead.
|
|
178
|
+
*
|
|
179
|
+
* @see {@link Top} — the existential "any schema" type (erased type params)
|
|
180
|
+
* @see {@link Schema} — tracks only the decoded Type
|
|
181
|
+
* @see {@link Codec} — tracks Type + Encoded
|
|
83
182
|
*
|
|
84
183
|
* @since 4.0.0
|
|
85
184
|
*/
|
|
@@ -112,69 +211,199 @@ export interface Bottom<out T, out E, out RD, out RE, out Ast extends AST.AST, o
|
|
|
112
211
|
makeOption(input: this["~type.make.in"], options?: MakeOptions): Option_.Option<this["Type"]>;
|
|
113
212
|
}
|
|
114
213
|
/**
|
|
214
|
+
* The schema type returned by {@link declareConstructor}, tracking the decoded
|
|
215
|
+
* type `T`, the encoded type `E`, and the list of type-parameter schemas
|
|
216
|
+
* `TypeParameters`.
|
|
217
|
+
*
|
|
218
|
+
* @category Constructors
|
|
115
219
|
* @since 4.0.0
|
|
116
220
|
*/
|
|
117
221
|
export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<Top>, Iso = T> extends Bottom<T, E, TypeParameters[number]["DecodingServices"], TypeParameters[number]["EncodingServices"], AST.Declaration, declareConstructor<T, E, TypeParameters, Iso>, T, Iso, TypeParameters> {
|
|
118
222
|
readonly "~rebuild.out": this;
|
|
119
223
|
}
|
|
120
224
|
/**
|
|
121
|
-
*
|
|
225
|
+
* Creates a schema for a **parametric** type (a generic container such as
|
|
226
|
+
* `Array<A>`, `Option<A>`, etc.) by accepting a list of type-parameter schemas
|
|
227
|
+
* and a decoder factory.
|
|
228
|
+
*
|
|
229
|
+
* The outer call `declareConstructor<T, E, Iso>()` fixes the decoded type `T`,
|
|
230
|
+
* the encoded type `E`, and the optional iso type. The inner call receives:
|
|
231
|
+
* - `typeParameters` — the concrete schemas for each type variable
|
|
232
|
+
* - `run` — a factory that, given resolved codecs for each type parameter,
|
|
233
|
+
* returns a parsing function `(u, ast, options) => Effect<T, Issue>`
|
|
234
|
+
* - `annotations` — optional metadata
|
|
235
|
+
*
|
|
236
|
+
* @see {@link declare} for creating schemas for non-parametric types.
|
|
237
|
+
*
|
|
238
|
+
* **Example** (Schema for a parametric `Box<A>` type)
|
|
239
|
+
*
|
|
240
|
+
* ```ts
|
|
241
|
+
* import { Effect, Schema } from "effect"
|
|
242
|
+
* import * as SchemaParser from "effect/SchemaParser"
|
|
243
|
+
* import * as Issue from "effect/SchemaIssue"
|
|
244
|
+
* import * as Option from "effect/Option"
|
|
245
|
+
*
|
|
246
|
+
* interface Box<A> {
|
|
247
|
+
* readonly value: A
|
|
248
|
+
* }
|
|
249
|
+
*
|
|
250
|
+
* const isBox = (u: unknown): u is Box<unknown> =>
|
|
251
|
+
* typeof u === "object" && u !== null && "value" in u
|
|
252
|
+
*
|
|
253
|
+
* const Box = <A extends Schema.Top>(item: A) =>
|
|
254
|
+
* Schema.declareConstructor<Box<A["Type"]>, Box<A["Encoded"]>>()(
|
|
255
|
+
* [item],
|
|
256
|
+
* ([itemCodec]) =>
|
|
257
|
+
* (u, ast, options) => {
|
|
258
|
+
* if (!isBox(u)) {
|
|
259
|
+
* return Effect.fail(new Issue.InvalidType(ast, Option.some(u)))
|
|
260
|
+
* }
|
|
261
|
+
* return Effect.map(
|
|
262
|
+
* SchemaParser.decodeUnknownEffect(itemCodec)(u.value, options),
|
|
263
|
+
* (value) => ({ value })
|
|
264
|
+
* )
|
|
265
|
+
* }
|
|
266
|
+
* )
|
|
122
267
|
*
|
|
123
|
-
*
|
|
268
|
+
* const schema = Box(Schema.Number)
|
|
269
|
+
* ```
|
|
124
270
|
*
|
|
125
271
|
* @category Constructors
|
|
126
272
|
* @since 4.0.0
|
|
127
273
|
*/
|
|
128
274
|
export declare function declareConstructor<T, E = T, Iso = T>(): <const TypeParameters extends ReadonlyArray<Top>>(typeParameters: TypeParameters, run: (typeParameters: { readonly [K in keyof TypeParameters]: Codec<TypeParameters[K]["Type"], TypeParameters[K]["Encoded"]>; }) => (u: unknown, self: AST.Declaration, options: AST.ParseOptions) => Effect.Effect<T, Issue.Issue>, annotations?: Annotations.Declaration<T, TypeParameters>) => declareConstructor<T, E, TypeParameters, Iso>;
|
|
129
275
|
/**
|
|
276
|
+
* The schema type returned by {@link declare}, representing a non-parametric
|
|
277
|
+
* opaque type `T` with no type parameters.
|
|
278
|
+
*
|
|
130
279
|
* @category Constructors
|
|
131
280
|
* @since 4.0.0
|
|
132
281
|
*/
|
|
133
282
|
export interface declare<T, Iso = T> extends declareConstructor<T, T, readonly [], Iso> {
|
|
134
283
|
}
|
|
135
284
|
/**
|
|
136
|
-
*
|
|
285
|
+
* Creates a schema for a **non-parametric** opaque type using a type-guard
|
|
286
|
+
* function. The schema accepts any unknown value and succeeds when `is` returns
|
|
287
|
+
* `true`, failing with an `InvalidType` issue otherwise.
|
|
288
|
+
*
|
|
289
|
+
* Use this when the type has no type parameters. For parametric types such as
|
|
290
|
+
* `Option<A>` or `Array<A>`, use {@link declareConstructor} instead.
|
|
291
|
+
*
|
|
292
|
+
* **Example** (Schema for a custom `UserId` branded type)
|
|
293
|
+
*
|
|
294
|
+
* ```ts
|
|
295
|
+
* import { Schema } from "effect"
|
|
296
|
+
*
|
|
297
|
+
* type UserId = string & { readonly _tag: "UserId" }
|
|
298
|
+
*
|
|
299
|
+
* const isUserId = (u: unknown): u is UserId =>
|
|
300
|
+
* typeof u === "string" && u.startsWith("user_")
|
|
301
|
+
*
|
|
302
|
+
* const UserId = Schema.declare<UserId>(isUserId, {
|
|
303
|
+
* title: "UserId",
|
|
304
|
+
* description: "A user identifier starting with 'user_'"
|
|
305
|
+
* })
|
|
306
|
+
* ```
|
|
137
307
|
*
|
|
138
308
|
* @see {@link declareConstructor} for creating schemas for parametric types.
|
|
139
309
|
*
|
|
310
|
+
* @category Constructors
|
|
140
311
|
* @since 4.0.0
|
|
141
312
|
*/
|
|
142
313
|
export declare function declare<T, Iso = T>(is: (u: unknown) => u is T, annotations?: Annotations.Declaration<T> | undefined): declare<T, Iso>;
|
|
143
314
|
/**
|
|
144
|
-
*
|
|
145
|
-
* parameters.
|
|
315
|
+
* Widens a schema's type to the fully-parameterized {@link Bottom} interface,
|
|
316
|
+
* making all 14 type parameters visible to TypeScript.
|
|
317
|
+
*
|
|
318
|
+
* Normally, concrete schema interfaces (e.g. `Schema<string>`) hide most type
|
|
319
|
+
* parameters. `revealBottom` is useful when writing generic utilities that need
|
|
320
|
+
* to inspect or propagate the complete set of type parameters.
|
|
321
|
+
*
|
|
322
|
+
* **Example** (Inspecting all type parameters of a schema)
|
|
323
|
+
*
|
|
324
|
+
* ```ts
|
|
325
|
+
* import { Schema } from "effect"
|
|
326
|
+
*
|
|
327
|
+
* const schema = Schema.String
|
|
328
|
+
*
|
|
329
|
+
* // Widen to Bottom to access all 14 type parameters
|
|
330
|
+
* const bottom = Schema.revealBottom(schema)
|
|
331
|
+
*
|
|
332
|
+
* // `bottom` now exposes Type, Encoded, DecodingServices, EncodingServices,
|
|
333
|
+
* // ast, ~rebuild.out, ~type.make.in, Iso, ~type.parameters, etc.
|
|
334
|
+
* type T = typeof bottom["Type"] // string
|
|
335
|
+
* type E = typeof bottom["Encoded"] // string
|
|
336
|
+
* ```
|
|
146
337
|
*
|
|
147
338
|
* @since 4.0.0
|
|
148
339
|
*/
|
|
149
340
|
export declare function revealBottom<S extends Top>(bottom: S): Bottom<S["Type"], S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], S["~rebuild.out"], S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]>;
|
|
150
341
|
/**
|
|
151
342
|
* Adds metadata annotations to a schema without changing its runtime behavior.
|
|
152
|
-
*
|
|
153
|
-
*
|
|
343
|
+
* This is the pipeable (curried) counterpart of the `.annotate` method.
|
|
344
|
+
*
|
|
345
|
+
* Annotations provide extra context used by documentation generators, JSON
|
|
346
|
+
* Schema converters, error formatters, and other tooling. Common keys include
|
|
347
|
+
* `title`, `description`, `examples`, `message`, and `identifier`.
|
|
348
|
+
*
|
|
349
|
+
* **Example** (Adding a title and description)
|
|
350
|
+
*
|
|
351
|
+
* ```ts
|
|
352
|
+
* import { Schema } from "effect"
|
|
353
|
+
*
|
|
354
|
+
* const Age = Schema.Number.pipe(
|
|
355
|
+
* Schema.annotate({
|
|
356
|
+
* title: "Age",
|
|
357
|
+
* description: "A non-negative integer representing age in years"
|
|
358
|
+
* })
|
|
359
|
+
* )
|
|
360
|
+
* ```
|
|
154
361
|
*
|
|
155
362
|
* @category Annotations
|
|
156
363
|
* @since 4.0.0
|
|
157
364
|
*/
|
|
158
365
|
export declare function annotate<S extends Top>(annotations: S["~annotate.in"]): (self: S) => S["~rebuild.out"];
|
|
159
366
|
/**
|
|
160
|
-
* Adds key-
|
|
161
|
-
*
|
|
162
|
-
*
|
|
367
|
+
* Adds key-level annotations to a schema field. This is the pipeable
|
|
368
|
+
* (curried) counterpart of the `.annotateKey` method.
|
|
369
|
+
*
|
|
370
|
+
* Key annotations apply to a field's position inside a `Struct` or `Tuple`
|
|
371
|
+
* rather than to the field's value type. They can carry a
|
|
372
|
+
* `messageMissingKey` to customise the error shown when the field is absent,
|
|
373
|
+
* as well as standard documentation fields such as `title`, `description`,
|
|
374
|
+
* and `examples`.
|
|
375
|
+
*
|
|
376
|
+
* **Example** (Custom missing-key message for a required field)
|
|
377
|
+
*
|
|
378
|
+
* ```ts
|
|
379
|
+
* import { Schema } from "effect"
|
|
380
|
+
*
|
|
381
|
+
* const schema = Schema.Struct({
|
|
382
|
+
* username: Schema.String.pipe(
|
|
383
|
+
* Schema.annotateKey({
|
|
384
|
+
* description: "The username used to log in",
|
|
385
|
+
* messageMissingKey: "Username is required"
|
|
386
|
+
* })
|
|
387
|
+
* )
|
|
388
|
+
* })
|
|
389
|
+
* ```
|
|
163
390
|
*
|
|
164
391
|
* @category Annotations
|
|
165
392
|
* @since 4.0.0
|
|
166
393
|
*/
|
|
167
394
|
export declare function annotateKey<S extends Top>(annotations: Annotations.Key<S["Type"]>): (self: S) => S["~rebuild.out"];
|
|
168
395
|
/**
|
|
169
|
-
* The
|
|
396
|
+
* The existential "any schema" type — all type parameters are erased to `unknown`.
|
|
170
397
|
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
398
|
+
* Use `Top` as a constraint when writing generic utilities that must accept *any*
|
|
399
|
+
* schema regardless of its `Type`, `Encoded`, or service requirements. It is the
|
|
400
|
+
* widest possible schema type and therefore gives you the least static information.
|
|
174
401
|
*
|
|
175
|
-
*
|
|
176
|
-
* -
|
|
177
|
-
* -
|
|
402
|
+
* In user code prefer the narrower interfaces:
|
|
403
|
+
* - {@link Schema}`<T>` — when you only care about the decoded type
|
|
404
|
+
* - {@link Codec}`<T, E, RD, RE>` — when you need the encoded type and service requirements
|
|
405
|
+
* - {@link Decoder}`<T, RD>` — for decode-only APIs
|
|
406
|
+
* - {@link Encoder}`<E, RE>` — for encode-only APIs
|
|
178
407
|
*
|
|
179
408
|
* @since 4.0.0
|
|
180
409
|
*/
|
|
@@ -182,24 +411,52 @@ export interface Top extends Bottom<unknown, unknown, unknown, unknown, AST.AST,
|
|
|
182
411
|
unknown, Mutability, Optionality, ConstructorDefault, Mutability, Optionality> {
|
|
183
412
|
}
|
|
184
413
|
/**
|
|
414
|
+
* Namespace of type-level helpers for {@link Schema}.
|
|
415
|
+
*
|
|
185
416
|
* @since 4.0.0
|
|
186
417
|
*/
|
|
187
418
|
export declare namespace Schema {
|
|
188
419
|
/**
|
|
420
|
+
* Extracts the decoded `Type` from a schema.
|
|
421
|
+
*
|
|
422
|
+
* **Example** (Extracting the decoded type)
|
|
423
|
+
*
|
|
424
|
+
* ```ts
|
|
425
|
+
* import { Schema } from "effect"
|
|
426
|
+
*
|
|
427
|
+
* const Person = Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
428
|
+
* type Person = Schema.Schema.Type<typeof Person>
|
|
429
|
+
* // { readonly name: string; readonly age: number }
|
|
430
|
+
* ```
|
|
431
|
+
*
|
|
189
432
|
* @since 4.0.0
|
|
190
433
|
*/
|
|
191
434
|
type Type<S> = S extends Top ? S["Type"] : never;
|
|
192
435
|
}
|
|
193
436
|
/**
|
|
194
|
-
* A typed view of a schema that tracks the decoded (output) type `T`.
|
|
437
|
+
* A typed view of a schema that tracks only the decoded (output) type `T`.
|
|
195
438
|
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
439
|
+
* Use `Schema<T>` as a constraint when you want to accept "any schema that
|
|
440
|
+
* decodes to `T`" and do not need to know or constrain the encoded
|
|
441
|
+
* representation, required services, or any other type parameters.
|
|
442
|
+
*
|
|
443
|
+
* This is a structural interface — concrete schema values are produced by the
|
|
444
|
+
* constructors in this module (e.g. {@link Struct}, {@link String}, {@link Number}).
|
|
445
|
+
* When you also need the encoded type or service requirements, use {@link Codec}.
|
|
446
|
+
*
|
|
447
|
+
* **Example** (Function that accepts any schema decoding to `string`)
|
|
448
|
+
*
|
|
449
|
+
* ```ts
|
|
450
|
+
* import { Schema } from "effect"
|
|
451
|
+
*
|
|
452
|
+
* declare function print(schema: Schema.Schema<string>): void
|
|
453
|
+
*
|
|
454
|
+
* print(Schema.String) // ok
|
|
455
|
+
* print(Schema.NonEmptyString) // ok
|
|
456
|
+
* ```
|
|
199
457
|
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* - If you also need the encoded type (or decoding/encoding services), use {@link Codec}.
|
|
458
|
+
* @see {@link Codec} — also tracks Encoded, DecodingServices, EncodingServices
|
|
459
|
+
* @see {@link Schema.Type} — extract the decoded type at the type level
|
|
203
460
|
*
|
|
204
461
|
* @since 4.0.0
|
|
205
462
|
*/
|
|
@@ -208,22 +465,66 @@ export interface Schema<out T> extends Top {
|
|
|
208
465
|
readonly "~rebuild.out": Schema<T>;
|
|
209
466
|
}
|
|
210
467
|
/**
|
|
468
|
+
* Namespace of type-level helpers for {@link Codec}.
|
|
469
|
+
*
|
|
211
470
|
* @since 4.0.0
|
|
212
471
|
*/
|
|
213
472
|
export declare namespace Codec {
|
|
214
473
|
/**
|
|
474
|
+
* Extracts the encoded (`Encoded`) type from a schema.
|
|
475
|
+
*
|
|
476
|
+
* **Example** (Extracting the encoded type)
|
|
477
|
+
*
|
|
478
|
+
* ```ts
|
|
479
|
+
* import { Schema } from "effect"
|
|
480
|
+
*
|
|
481
|
+
* const schema = Schema.NumberFromString
|
|
482
|
+
* type Enc = Schema.Codec.Encoded<typeof schema>
|
|
483
|
+
* // string
|
|
484
|
+
* ```
|
|
485
|
+
*
|
|
215
486
|
* @since 4.0.0
|
|
216
487
|
*/
|
|
217
488
|
type Encoded<S> = S extends Top ? S["Encoded"] : never;
|
|
218
489
|
/**
|
|
490
|
+
* Extracts the Effect services required during *decoding* from a schema.
|
|
491
|
+
*
|
|
492
|
+
* **Example** (Checking decoding service requirements)
|
|
493
|
+
*
|
|
494
|
+
* ```ts
|
|
495
|
+
* import { Schema } from "effect"
|
|
496
|
+
*
|
|
497
|
+
* const schema = Schema.String
|
|
498
|
+
* type RD = Schema.Codec.DecodingServices<typeof schema>
|
|
499
|
+
* // never
|
|
500
|
+
* ```
|
|
501
|
+
*
|
|
219
502
|
* @since 4.0.0
|
|
220
503
|
*/
|
|
221
504
|
type DecodingServices<S> = S extends Top ? S["DecodingServices"] : never;
|
|
222
505
|
/**
|
|
506
|
+
* Extracts the Effect services required during *encoding* from a schema.
|
|
507
|
+
*
|
|
508
|
+
* **Example** (Checking encoding service requirements)
|
|
509
|
+
*
|
|
510
|
+
* ```ts
|
|
511
|
+
* import { Schema } from "effect"
|
|
512
|
+
*
|
|
513
|
+
* const schema = Schema.String
|
|
514
|
+
* type RE = Schema.Codec.EncodingServices<typeof schema>
|
|
515
|
+
* // never
|
|
516
|
+
* ```
|
|
517
|
+
*
|
|
223
518
|
* @since 4.0.0
|
|
224
519
|
*/
|
|
225
520
|
type EncodingServices<S> = S extends Top ? S["EncodingServices"] : never;
|
|
226
521
|
/**
|
|
522
|
+
* Converts a schema type into an assertion function signature. The resulting
|
|
523
|
+
* function narrows its argument to `I & S["Type"]`. Only schemas with
|
|
524
|
+
* `DecodingServices: never` (i.e. no required services) can be used here.
|
|
525
|
+
*
|
|
526
|
+
* Produced by {@link asserts}.
|
|
527
|
+
*
|
|
227
528
|
* @since 4.0.0
|
|
228
529
|
*/
|
|
229
530
|
type ToAsserts<S extends Top & {
|
|
@@ -231,6 +532,18 @@ export declare namespace Codec {
|
|
|
231
532
|
}> = <I>(input: I) => asserts input is I & S["Type"];
|
|
232
533
|
}
|
|
233
534
|
/**
|
|
535
|
+
* A schema that additionally supports optic (lens/prism) operations.
|
|
536
|
+
*
|
|
537
|
+
* `Optic<T, Iso>` extends {@link Schema}`<T>` with an `Iso` type that
|
|
538
|
+
* describes the isomorphic counterpart used by the optic layer. Crucially,
|
|
539
|
+
* decoding and encoding require *no* Effect services (`DecodingServices` and
|
|
540
|
+
* `EncodingServices` are both `never`), which means the optic can operate
|
|
541
|
+
* purely without an Effect runtime.
|
|
542
|
+
*
|
|
543
|
+
* Most primitive schemas (e.g. `Schema.String`, `Schema.Number`) implement
|
|
544
|
+
* `Optic` automatically. You normally interact with this interface through
|
|
545
|
+
* {@link Optic_} utilities rather than constructing it directly.
|
|
546
|
+
*
|
|
234
547
|
* @since 4.0.0
|
|
235
548
|
*/
|
|
236
549
|
export interface Optic<out T, out Iso> extends Schema<T> {
|
|
@@ -240,16 +553,32 @@ export interface Optic<out T, out Iso> extends Schema<T> {
|
|
|
240
553
|
readonly "~rebuild.out": Optic<T, Iso>;
|
|
241
554
|
}
|
|
242
555
|
/**
|
|
243
|
-
* A schema that tracks
|
|
556
|
+
* A schema that tracks the decoded type `T`, the encoded type `E`, and the
|
|
557
|
+
* Effect services required during decoding (`RD`) and encoding (`RE`).
|
|
244
558
|
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* - You need to model required services for decoding (`RD`) and encoding (`RE`).
|
|
559
|
+
* Use `Codec<T, E, RD, RE>` when you need to preserve full type information
|
|
560
|
+
* about a schema — both what it decodes to and what it serializes from/to.
|
|
561
|
+
* Most concrete schemas produced by this module implement `Codec`.
|
|
249
562
|
*
|
|
250
|
-
*
|
|
251
|
-
* -
|
|
252
|
-
* -
|
|
563
|
+
* For APIs that only need one direction, prefer the narrower views:
|
|
564
|
+
* - {@link Decoder}`<T, RD>` — decode-only
|
|
565
|
+
* - {@link Encoder}`<E, RE>` — encode-only
|
|
566
|
+
* - {@link Schema}`<T>` — type-only (no encoded representation)
|
|
567
|
+
*
|
|
568
|
+
* **Example** (Accepting a codec that decodes to `number` from `string`)
|
|
569
|
+
*
|
|
570
|
+
* ```ts
|
|
571
|
+
* import { Schema } from "effect"
|
|
572
|
+
*
|
|
573
|
+
* declare function serialize<T>(codec: Schema.Codec<T, string>): string
|
|
574
|
+
*
|
|
575
|
+
* serialize(Schema.NumberFromString) // ok — decodes number, encoded as string
|
|
576
|
+
* ```
|
|
577
|
+
*
|
|
578
|
+
* @see {@link Codec.Encoded} — extract the encoded type
|
|
579
|
+
* @see {@link Codec.DecodingServices} — extract required decoding services
|
|
580
|
+
* @see {@link Codec.EncodingServices} — extract required encoding services
|
|
581
|
+
* @see {@link revealCodec} — helper to make TypeScript infer the full Codec type
|
|
253
582
|
*
|
|
254
583
|
* @since 4.0.0
|
|
255
584
|
*/
|
|
@@ -260,11 +589,22 @@ export interface Codec<out T, out E = T, out RD = never, out RE = never> extends
|
|
|
260
589
|
readonly "~rebuild.out": Codec<T, E, RD, RE>;
|
|
261
590
|
}
|
|
262
591
|
/**
|
|
263
|
-
* A
|
|
592
|
+
* A {@link Codec} view for APIs that only *decode* (parse/validate) values.
|
|
264
593
|
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
594
|
+
* Use `Decoder<T, RD>` to accept "any schema that can decode to `T`" without
|
|
595
|
+
* constraining or depending on the encoded representation (`Encoded` is
|
|
596
|
+
* `unknown`) or encoding services.
|
|
597
|
+
*
|
|
598
|
+
* **Example** (Function that only needs to decode)
|
|
599
|
+
*
|
|
600
|
+
* ```ts
|
|
601
|
+
* import { Schema } from "effect"
|
|
602
|
+
*
|
|
603
|
+
* declare function validate<T>(decoder: Schema.Decoder<T>): (input: unknown) => T
|
|
604
|
+
*
|
|
605
|
+
* validate(Schema.String) // ok
|
|
606
|
+
* validate(Schema.NumberFromString) // ok
|
|
607
|
+
* ```
|
|
268
608
|
*
|
|
269
609
|
* @since 4.0.0
|
|
270
610
|
*/
|
|
@@ -272,11 +612,22 @@ export interface Decoder<out T, out RD = never> extends Codec<T, unknown, RD, un
|
|
|
272
612
|
readonly "~rebuild.out": Decoder<T, RD>;
|
|
273
613
|
}
|
|
274
614
|
/**
|
|
275
|
-
* A
|
|
615
|
+
* A {@link Codec} view for APIs that only *encode* values.
|
|
276
616
|
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
617
|
+
* Use `Encoder<E, RE>` to accept "any schema that can encode to `E`" without
|
|
618
|
+
* constraining or depending on the decoded `Type` (`Type` is `unknown`) or
|
|
619
|
+
* decoding services.
|
|
620
|
+
*
|
|
621
|
+
* **Example** (Function that only needs to encode)
|
|
622
|
+
*
|
|
623
|
+
* ```ts
|
|
624
|
+
* import { Schema } from "effect"
|
|
625
|
+
*
|
|
626
|
+
* declare function serialize<E>(encoder: Schema.Encoder<E>): (value: unknown) => E
|
|
627
|
+
*
|
|
628
|
+
* serialize(Schema.String) // ok — encodes to string
|
|
629
|
+
* serialize(Schema.NumberFromString) // ok — encodes number to string
|
|
630
|
+
* ```
|
|
280
631
|
*
|
|
281
632
|
* @since 4.0.0
|
|
282
633
|
*/
|
|
@@ -284,17 +635,54 @@ export interface Encoder<out E, out RE = never> extends Codec<unknown, E, unknow
|
|
|
284
635
|
readonly "~rebuild.out": Encoder<E, RE>;
|
|
285
636
|
}
|
|
286
637
|
/**
|
|
638
|
+
* Identity function that widens a value to the full {@link Codec} interface,
|
|
639
|
+
* prompting TypeScript to infer all four type parameters (`T`, `E`, `RD`, `RE`).
|
|
640
|
+
*
|
|
641
|
+
* When a schema is stored in a variable typed as `Schema<T>` or `Top`, the
|
|
642
|
+
* encoded type and service requirements are erased. Passing the value through
|
|
643
|
+
* `revealCodec` recovers those parameters without any runtime cost.
|
|
644
|
+
*
|
|
645
|
+
* **Example** (Recovering encoded type from a schema variable)
|
|
646
|
+
*
|
|
647
|
+
* ```ts
|
|
648
|
+
* import { Schema } from "effect"
|
|
649
|
+
*
|
|
650
|
+
* const schema: Schema.Schema<number> = Schema.NumberFromString
|
|
651
|
+
*
|
|
652
|
+
* // Without revealCodec, Encoded is unknown
|
|
653
|
+
* const codec = Schema.revealCodec(schema)
|
|
654
|
+
* type Enc = typeof codec["Encoded"] // string
|
|
655
|
+
* ```
|
|
656
|
+
*
|
|
287
657
|
* @since 4.0.0
|
|
288
658
|
*/
|
|
289
659
|
export declare function revealCodec<T, E, RD, RE>(codec: Codec<T, E, RD, RE>): Codec<T, E, RD, RE>;
|
|
290
660
|
declare const SchemaErrorTypeId = "~effect/Schema/SchemaError";
|
|
291
661
|
/**
|
|
292
|
-
*
|
|
662
|
+
* Error thrown (or returned as the error channel value) when schema decoding
|
|
663
|
+
* or encoding fails.
|
|
293
664
|
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
665
|
+
* The `issue` field contains a structured {@link Issue.Issue} tree describing
|
|
666
|
+
* every validation failure, including the path to the problematic value,
|
|
667
|
+
* expected types, and actual values received. `message` renders the issue tree
|
|
668
|
+
* as a human-readable string.
|
|
669
|
+
*
|
|
670
|
+
* Use {@link isSchemaError} to narrow an unknown value to `SchemaError`.
|
|
671
|
+
*
|
|
672
|
+
* **Example** (Catching a SchemaError)
|
|
673
|
+
*
|
|
674
|
+
* ```ts
|
|
675
|
+
* import { Schema } from "effect"
|
|
676
|
+
*
|
|
677
|
+
* try {
|
|
678
|
+
* Schema.decodeUnknownSync(Schema.Number)("not a number")
|
|
679
|
+
* } catch (err) {
|
|
680
|
+
* if (Schema.isSchemaError(err)) {
|
|
681
|
+
* console.log(err.message)
|
|
682
|
+
* // Expected number, actual "not a number"
|
|
683
|
+
* }
|
|
684
|
+
* }
|
|
685
|
+
* ```
|
|
298
686
|
*
|
|
299
687
|
* @since 4.0.0
|
|
300
688
|
*/
|
|
@@ -308,6 +696,22 @@ export declare class SchemaError {
|
|
|
308
696
|
toString(): string;
|
|
309
697
|
}
|
|
310
698
|
/**
|
|
699
|
+
* Returns `true` if `u` is a {@link SchemaError}.
|
|
700
|
+
*
|
|
701
|
+
* **Example** (Type guard in a catch block)
|
|
702
|
+
*
|
|
703
|
+
* ```ts
|
|
704
|
+
* import { Schema } from "effect"
|
|
705
|
+
*
|
|
706
|
+
* try {
|
|
707
|
+
* Schema.decodeUnknownSync(Schema.Number)("oops")
|
|
708
|
+
* } catch (err) {
|
|
709
|
+
* if (Schema.isSchemaError(err)) {
|
|
710
|
+
* console.log(err._tag) // "SchemaError"
|
|
711
|
+
* }
|
|
712
|
+
* }
|
|
713
|
+
* ```
|
|
714
|
+
*
|
|
311
715
|
* @since 4.0.0
|
|
312
716
|
*/
|
|
313
717
|
export declare function isSchemaError(u: unknown): u is SchemaError;
|
|
@@ -457,16 +861,32 @@ export declare const is: typeof Parser.is;
|
|
|
457
861
|
*/
|
|
458
862
|
export declare const asserts: typeof Parser.asserts;
|
|
459
863
|
/**
|
|
864
|
+
* Decodes an `unknown` input against a schema, returning an `Effect` that
|
|
865
|
+
* succeeds with the decoded value or fails with a {@link SchemaError}. Use this
|
|
866
|
+
* when the input type is not statically known. Prefer {@link decodeEffect} when
|
|
867
|
+
* the input is already typed as the schema's `Encoded` type.
|
|
868
|
+
*
|
|
460
869
|
* @category Decoding
|
|
461
870
|
* @since 4.0.0
|
|
462
871
|
*/
|
|
463
872
|
export declare function decodeUnknownEffect<S extends Top>(schema: S): (input: unknown, options?: AST.ParseOptions) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]>;
|
|
464
873
|
/**
|
|
874
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
875
|
+
* returning an `Effect` that succeeds with the decoded value or fails with a
|
|
876
|
+
* {@link SchemaError}. Use this when the input is already typed; for `unknown`
|
|
877
|
+
* input use {@link decodeUnknownEffect}.
|
|
878
|
+
*
|
|
465
879
|
* @category Decoding
|
|
466
880
|
* @since 4.0.0
|
|
467
881
|
*/
|
|
468
882
|
export declare const decodeEffect: <S extends Top>(schema: S) => (input: S["Encoded"], options?: AST.ParseOptions) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]>;
|
|
469
883
|
/**
|
|
884
|
+
* Decodes an `unknown` input against a schema synchronously, returning an
|
|
885
|
+
* `Exit` that is either a `Success` with the decoded value or a `Failure` with
|
|
886
|
+
* a {@link SchemaError}. Only usable with schemas that have no
|
|
887
|
+
* `DecodingServices` requirement. Prefer {@link decodeExit} when the input is
|
|
888
|
+
* already typed as the schema's `Encoded` type.
|
|
889
|
+
*
|
|
470
890
|
* @category Decoding
|
|
471
891
|
* @since 4.0.0
|
|
472
892
|
*/
|
|
@@ -474,6 +894,12 @@ export declare function decodeUnknownExit<S extends Top & {
|
|
|
474
894
|
readonly DecodingServices: never;
|
|
475
895
|
}>(schema: S): (input: unknown, options?: AST.ParseOptions) => Exit_.Exit<S["Type"], SchemaError>;
|
|
476
896
|
/**
|
|
897
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
898
|
+
* synchronously, returning an `Exit` that is either a `Success` with the
|
|
899
|
+
* decoded value or a `Failure` with a {@link SchemaError}. Only usable with
|
|
900
|
+
* schemas that have no `DecodingServices` requirement. For `unknown` input use
|
|
901
|
+
* {@link decodeUnknownExit}.
|
|
902
|
+
*
|
|
477
903
|
* @category Decoding
|
|
478
904
|
* @since 4.0.0
|
|
479
905
|
*/
|
|
@@ -481,11 +907,21 @@ export declare const decodeExit: <S extends Top & {
|
|
|
481
907
|
readonly DecodingServices: never;
|
|
482
908
|
}>(schema: S) => (input: S["Encoded"], options?: AST.ParseOptions) => Exit_.Exit<S["Type"], SchemaError>;
|
|
483
909
|
/**
|
|
910
|
+
* Decodes an `unknown` input against a schema, returning an `Option` that is
|
|
911
|
+
* `Some` with the decoded value on success or `None` on failure. Prefer this
|
|
912
|
+
* over {@link decodeUnknownExit} or {@link decodeUnknownEffect} when you only
|
|
913
|
+
* need to know whether decoding succeeded and don't need error details. For
|
|
914
|
+
* typed input use {@link decodeOption}.
|
|
915
|
+
*
|
|
484
916
|
* @category Decoding
|
|
485
917
|
* @since 4.0.0
|
|
486
918
|
*/
|
|
487
919
|
export declare const decodeUnknownOption: typeof Parser.decodeUnknownOption;
|
|
488
920
|
/**
|
|
921
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
922
|
+
* returning an `Option` that is `Some` with the decoded value on success or
|
|
923
|
+
* `None` on failure. For `unknown` input use {@link decodeUnknownOption}.
|
|
924
|
+
*
|
|
489
925
|
* @category Decoding
|
|
490
926
|
* @since 4.0.0
|
|
491
927
|
*/
|
|
@@ -493,21 +929,58 @@ export declare const decodeOption: <S extends Top & {
|
|
|
493
929
|
readonly DecodingServices: never;
|
|
494
930
|
}>(schema: S) => (input: S["Encoded"], options?: AST.ParseOptions) => Option_.Option<S["Type"]>;
|
|
495
931
|
/**
|
|
932
|
+
* Decodes an `unknown` input against a schema, returning a `Promise` that
|
|
933
|
+
* resolves with the decoded value or rejects with a {@link SchemaError}. Useful
|
|
934
|
+
* for integrating with Promise-based APIs. For typed input use
|
|
935
|
+
* {@link decodePromise}.
|
|
936
|
+
*
|
|
496
937
|
* @category Decoding
|
|
497
938
|
* @since 4.0.0
|
|
498
939
|
*/
|
|
499
940
|
export declare const decodeUnknownPromise: typeof Parser.decodeUnknownPromise;
|
|
500
941
|
/**
|
|
942
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
943
|
+
* returning a `Promise` that resolves with the decoded value or rejects with a
|
|
944
|
+
* {@link SchemaError}. For `unknown` input use {@link decodeUnknownPromise}.
|
|
945
|
+
*
|
|
501
946
|
* @category Decoding
|
|
502
947
|
* @since 4.0.0
|
|
503
948
|
*/
|
|
504
949
|
export declare const decodePromise: typeof Parser.decodePromise;
|
|
505
950
|
/**
|
|
951
|
+
* Decodes an `unknown` input against a schema synchronously, throwing a
|
|
952
|
+
* {@link SchemaError} on failure. Use this when you want to validate data at a
|
|
953
|
+
* boundary and treat a schema mismatch as an unrecoverable error. For
|
|
954
|
+
* non-throwing alternatives see {@link decodeUnknownOption},
|
|
955
|
+
* {@link decodeUnknownExit}, or {@link decodeUnknownEffect}. For typed input
|
|
956
|
+
* use {@link decodeSync}.
|
|
957
|
+
*
|
|
958
|
+
* **Example** (Decoding with a transformation schema)
|
|
959
|
+
*
|
|
960
|
+
* ```ts
|
|
961
|
+
* import { Schema } from "effect"
|
|
962
|
+
*
|
|
963
|
+
* const NumberFromString = Schema.NumberFromString
|
|
964
|
+
*
|
|
965
|
+
* console.log(Schema.decodeUnknownSync(NumberFromString)("42"))
|
|
966
|
+
* // Output: 42
|
|
967
|
+
*
|
|
968
|
+
* Schema.decodeUnknownSync(NumberFromString)("not a number")
|
|
969
|
+
* // throws SchemaError: NumberFromString
|
|
970
|
+
* // └─ Encoded side transformation failure
|
|
971
|
+
* // └─ NumberFromString
|
|
972
|
+
* // └─ Expected a numeric string, actual "not a number"
|
|
973
|
+
* ```
|
|
974
|
+
*
|
|
506
975
|
* @category Decoding
|
|
507
976
|
* @since 4.0.0
|
|
508
977
|
*/
|
|
509
978
|
export declare const decodeUnknownSync: typeof Parser.decodeUnknownSync;
|
|
510
979
|
/**
|
|
980
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
981
|
+
* synchronously, throwing a {@link SchemaError} on failure. For `unknown` input
|
|
982
|
+
* use {@link decodeUnknownSync}.
|
|
983
|
+
*
|
|
511
984
|
* @category Decoding
|
|
512
985
|
* @since 4.0.0
|
|
513
986
|
*/
|
|
@@ -515,16 +988,43 @@ export declare const decodeSync: <S extends Top & {
|
|
|
515
988
|
readonly DecodingServices: never;
|
|
516
989
|
}>(schema: S) => (input: S["Encoded"], options?: AST.ParseOptions) => S["Type"];
|
|
517
990
|
/**
|
|
991
|
+
* Encodes an `unknown` input against a schema, returning an `Effect` that
|
|
992
|
+
* succeeds with the encoded value or fails with a {@link SchemaError}. Use this
|
|
993
|
+
* when the input type is not statically known. Prefer {@link encodeEffect} when
|
|
994
|
+
* the input is already typed as the schema's `Type`.
|
|
995
|
+
*
|
|
996
|
+
* **Example** (Encoding a value to a string)
|
|
997
|
+
*
|
|
998
|
+
* ```ts
|
|
999
|
+
* import { Effect, Schema } from "effect"
|
|
1000
|
+
*
|
|
1001
|
+
* const NumberFromString = Schema.NumberFromString
|
|
1002
|
+
*
|
|
1003
|
+
* Effect.runPromise(Schema.encodeUnknownEffect(NumberFromString)(42)).then(console.log)
|
|
1004
|
+
* // Output: "42"
|
|
1005
|
+
* ```
|
|
1006
|
+
*
|
|
518
1007
|
* @category Encoding
|
|
519
1008
|
* @since 4.0.0
|
|
520
1009
|
*/
|
|
521
1010
|
export declare function encodeUnknownEffect<S extends Top>(schema: S): (input: unknown, options?: AST.ParseOptions) => Effect.Effect<S["Encoded"], SchemaError, S["EncodingServices"]>;
|
|
522
1011
|
/**
|
|
1012
|
+
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
1013
|
+
* `Effect` that succeeds with the encoded value or fails with a
|
|
1014
|
+
* {@link SchemaError}. Use this when the input is already typed; for `unknown`
|
|
1015
|
+
* input use {@link encodeUnknownEffect}.
|
|
1016
|
+
*
|
|
523
1017
|
* @category Encoding
|
|
524
1018
|
* @since 4.0.0
|
|
525
1019
|
*/
|
|
526
1020
|
export declare const encodeEffect: <S extends Top>(schema: S) => (input: S["Type"], options?: AST.ParseOptions) => Effect.Effect<S["Encoded"], SchemaError, S["EncodingServices"]>;
|
|
527
1021
|
/**
|
|
1022
|
+
* Encodes an `unknown` input against a schema synchronously, returning an
|
|
1023
|
+
* `Exit` that is either a `Success` with the encoded value or a `Failure` with
|
|
1024
|
+
* a {@link SchemaError}. Only usable with schemas that have no
|
|
1025
|
+
* `EncodingServices` requirement. Prefer {@link encodeExit} when the input is
|
|
1026
|
+
* already typed as the schema's `Type`.
|
|
1027
|
+
*
|
|
528
1028
|
* @category Encoding
|
|
529
1029
|
* @since 4.0.0
|
|
530
1030
|
*/
|
|
@@ -532,6 +1032,12 @@ export declare function encodeUnknownExit<S extends Top & {
|
|
|
532
1032
|
readonly EncodingServices: never;
|
|
533
1033
|
}>(schema: S): (input: unknown, options?: AST.ParseOptions) => Exit_.Exit<S["Encoded"], SchemaError>;
|
|
534
1034
|
/**
|
|
1035
|
+
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
1036
|
+
* returning an `Exit` that is either a `Success` with the encoded value or a
|
|
1037
|
+
* `Failure` with a {@link SchemaError}. Only usable with schemas that have no
|
|
1038
|
+
* `EncodingServices` requirement. For `unknown` input use
|
|
1039
|
+
* {@link encodeUnknownExit}.
|
|
1040
|
+
*
|
|
535
1041
|
* @category Encoding
|
|
536
1042
|
* @since 4.0.0
|
|
537
1043
|
*/
|
|
@@ -539,11 +1045,21 @@ export declare const encodeExit: <S extends Top & {
|
|
|
539
1045
|
readonly EncodingServices: never;
|
|
540
1046
|
}>(schema: S) => (input: S["Type"], options?: AST.ParseOptions) => Exit_.Exit<S["Encoded"], SchemaError>;
|
|
541
1047
|
/**
|
|
1048
|
+
* Encodes an `unknown` input against a schema, returning an `Option` that is
|
|
1049
|
+
* `Some` with the encoded value on success or `None` on failure. Prefer this
|
|
1050
|
+
* over {@link encodeUnknownExit} or {@link encodeUnknownEffect} when you only
|
|
1051
|
+
* need to know whether encoding succeeded and don't need error details. For
|
|
1052
|
+
* typed input use {@link encodeOption}.
|
|
1053
|
+
*
|
|
542
1054
|
* @category Encoding
|
|
543
1055
|
* @since 4.0.0
|
|
544
1056
|
*/
|
|
545
1057
|
export declare const encodeUnknownOption: typeof Parser.encodeUnknownOption;
|
|
546
1058
|
/**
|
|
1059
|
+
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
1060
|
+
* `Option` that is `Some` with the encoded value on success or `None` on
|
|
1061
|
+
* failure. For `unknown` input use {@link encodeUnknownOption}.
|
|
1062
|
+
*
|
|
547
1063
|
* @category Encoding
|
|
548
1064
|
* @since 4.0.0
|
|
549
1065
|
*/
|
|
@@ -551,6 +1067,11 @@ export declare const encodeOption: <S extends Top & {
|
|
|
551
1067
|
readonly EncodingServices: never;
|
|
552
1068
|
}>(schema: S) => (input: S["Type"], options?: AST.ParseOptions) => Option_.Option<S["Encoded"]>;
|
|
553
1069
|
/**
|
|
1070
|
+
* Encodes an `unknown` input against a schema, returning a `Promise` that
|
|
1071
|
+
* resolves with the encoded value or rejects with a {@link SchemaError}. Useful
|
|
1072
|
+
* for integrating with Promise-based APIs. For typed input use
|
|
1073
|
+
* {@link encodePromise}.
|
|
1074
|
+
*
|
|
554
1075
|
* @category Encoding
|
|
555
1076
|
* @since 4.0.0
|
|
556
1077
|
*/
|
|
@@ -558,6 +1079,10 @@ export declare const encodeUnknownPromise: <S extends Top & {
|
|
|
558
1079
|
readonly EncodingServices: never;
|
|
559
1080
|
}>(schema: S) => (input: unknown, options?: AST.ParseOptions) => Promise<S["Encoded"]>;
|
|
560
1081
|
/**
|
|
1082
|
+
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
1083
|
+
* `Promise` that resolves with the encoded value or rejects with a
|
|
1084
|
+
* {@link SchemaError}. For `unknown` input use {@link encodeUnknownPromise}.
|
|
1085
|
+
*
|
|
561
1086
|
* @category Encoding
|
|
562
1087
|
* @since 4.0.0
|
|
563
1088
|
*/
|
|
@@ -565,11 +1090,22 @@ export declare const encodePromise: <S extends Top & {
|
|
|
565
1090
|
readonly EncodingServices: never;
|
|
566
1091
|
}>(schema: S) => (input: S["Type"], options?: AST.ParseOptions) => Promise<S["Encoded"]>;
|
|
567
1092
|
/**
|
|
1093
|
+
* Encodes an `unknown` input against a schema synchronously, throwing a
|
|
1094
|
+
* {@link SchemaError} on failure. Use this when you want to serialize data at a
|
|
1095
|
+
* boundary and treat a schema mismatch as an unrecoverable error. For
|
|
1096
|
+
* non-throwing alternatives see {@link encodeUnknownOption},
|
|
1097
|
+
* {@link encodeUnknownExit}, or {@link encodeUnknownEffect}. For typed input
|
|
1098
|
+
* use {@link encodeSync}.
|
|
1099
|
+
*
|
|
568
1100
|
* @category Encoding
|
|
569
1101
|
* @since 4.0.0
|
|
570
1102
|
*/
|
|
571
1103
|
export declare const encodeUnknownSync: typeof Parser.encodeUnknownSync;
|
|
572
1104
|
/**
|
|
1105
|
+
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
1106
|
+
* throwing a {@link SchemaError} on failure. For `unknown` input use
|
|
1107
|
+
* {@link encodeUnknownSync}.
|
|
1108
|
+
*
|
|
573
1109
|
* @category Encoding
|
|
574
1110
|
* @since 4.0.0
|
|
575
1111
|
*/
|
|
@@ -600,6 +1136,10 @@ export declare const make: <S extends Top>(ast: S["ast"], options?: object) => S
|
|
|
600
1136
|
*/
|
|
601
1137
|
export declare function isSchema(u: unknown): u is Top;
|
|
602
1138
|
/**
|
|
1139
|
+
* Schema type for an exact optional struct key. The key may be absent, but
|
|
1140
|
+
* when present must match the wrapped schema (no implicit `undefined`).
|
|
1141
|
+
* Produced by {@link optionalKey}.
|
|
1142
|
+
*
|
|
603
1143
|
* @since 4.0.0
|
|
604
1144
|
*/
|
|
605
1145
|
export interface optionalKey<S extends Top> extends Bottom<S["Type"], S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], optionalKey<S>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], "optional", S["~type.constructor.default"], S["~encoded.mutability"], "optional"> {
|
|
@@ -637,10 +1177,16 @@ interface requiredKeyLambda extends Lambda {
|
|
|
637
1177
|
readonly "~lambda.out": this["~lambda.in"] extends optionalKey<Top> ? this["~lambda.in"]["schema"] : "Error: schema not eligible for requiredKey";
|
|
638
1178
|
}
|
|
639
1179
|
/**
|
|
1180
|
+
* Reverses {@link optionalKey}, returning the inner required schema. Only
|
|
1181
|
+
* applicable to schemas already wrapped with `optionalKey`.
|
|
1182
|
+
*
|
|
640
1183
|
* @since 4.0.0
|
|
641
1184
|
*/
|
|
642
1185
|
export declare const requiredKey: requiredKeyLambda;
|
|
643
1186
|
/**
|
|
1187
|
+
* Schema type for an optional struct key that also accepts `undefined`.
|
|
1188
|
+
* Equivalent to `optionalKey<UndefinedOr<S>>`. Produced by {@link optional}.
|
|
1189
|
+
*
|
|
644
1190
|
* @since 4.0.0
|
|
645
1191
|
*/
|
|
646
1192
|
export interface optional<S extends Top> extends optionalKey<UndefinedOr<S>> {
|
|
@@ -650,27 +1196,26 @@ interface optionalLambda extends Lambda {
|
|
|
650
1196
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? optional<this["~lambda.in"]> : never;
|
|
651
1197
|
}
|
|
652
1198
|
/**
|
|
653
|
-
*
|
|
1199
|
+
* Marks a struct field as optional, allowing the key to be absent or
|
|
654
1200
|
* `undefined`.
|
|
655
1201
|
*
|
|
656
|
-
*
|
|
657
|
-
* that:
|
|
658
|
-
* - Can be omitted from the object entirely
|
|
659
|
-
* - Can be explicitly set to `undefined`
|
|
660
|
-
* - Can contain the specified schema type
|
|
1202
|
+
* explicitly set to `undefined`. Equivalent to `optionalKey(UndefinedOr(S))`.
|
|
661
1203
|
*
|
|
662
|
-
*
|
|
1204
|
+
* Use {@link optionalKey} instead if you want exact optional semantics (absent
|
|
1205
|
+
* only, not `undefined`).
|
|
1206
|
+
*
|
|
1207
|
+
* **Example** (Optional field accepting undefined)
|
|
663
1208
|
*
|
|
664
1209
|
* ```ts
|
|
665
1210
|
* import { Schema } from "effect"
|
|
666
1211
|
*
|
|
667
1212
|
* const schema = Schema.Struct({
|
|
668
1213
|
* name: Schema.String,
|
|
669
|
-
* age: Schema.
|
|
1214
|
+
* age: Schema.optional(Schema.Number)
|
|
670
1215
|
* })
|
|
671
1216
|
*
|
|
672
|
-
* //
|
|
673
|
-
* type Person = typeof schema
|
|
1217
|
+
* // { readonly name: string; readonly age?: number | undefined }
|
|
1218
|
+
* type Person = typeof schema.Type
|
|
674
1219
|
* ```
|
|
675
1220
|
*
|
|
676
1221
|
* @since 4.0.0
|
|
@@ -681,10 +1226,16 @@ interface requiredLambda extends Lambda {
|
|
|
681
1226
|
readonly "~lambda.out": this["~lambda.in"] extends optional<Top> ? this["~lambda.in"]["schema"]["members"][0] : "Error: schema not eligible for required";
|
|
682
1227
|
}
|
|
683
1228
|
/**
|
|
1229
|
+
* Reverses {@link optional}, returning the inner schema (unwrapping `UndefinedOr`).
|
|
1230
|
+
* Only applicable to schemas already wrapped with `optional`.
|
|
1231
|
+
*
|
|
684
1232
|
* @since 4.0.0
|
|
685
1233
|
*/
|
|
686
1234
|
export declare const required: requiredLambda;
|
|
687
1235
|
/**
|
|
1236
|
+
* Schema type for a mutable struct key. The key's property is writable.
|
|
1237
|
+
* Produced by {@link mutableKey}.
|
|
1238
|
+
*
|
|
688
1239
|
* @since 4.0.0
|
|
689
1240
|
*/
|
|
690
1241
|
export interface mutableKey<S extends Top> extends Bottom<S["Type"], S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], mutableKey<S>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], "mutable", S["~type.optionality"], S["~type.constructor.default"], "mutable", S["~encoded.optionality"]> {
|
|
@@ -696,6 +1247,9 @@ interface mutableKeyLambda extends Lambda {
|
|
|
696
1247
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? mutableKey<this["~lambda.in"]> : never;
|
|
697
1248
|
}
|
|
698
1249
|
/**
|
|
1250
|
+
* Makes a struct field mutable (removes the `readonly` modifier on the property).
|
|
1251
|
+
* Use {@link readonlyKey} to reverse.
|
|
1252
|
+
*
|
|
699
1253
|
* @since 4.0.0
|
|
700
1254
|
*/
|
|
701
1255
|
export declare const mutableKey: mutableKeyLambda;
|
|
@@ -704,10 +1258,16 @@ interface readonlyKeyLambda extends Lambda {
|
|
|
704
1258
|
readonly "~lambda.out": this["~lambda.in"] extends mutableKey<Top> ? this["~lambda.in"]["schema"] : "Error: schema not eligible for readonlyKey";
|
|
705
1259
|
}
|
|
706
1260
|
/**
|
|
1261
|
+
* Reverses {@link mutableKey}, returning the inner schema as readonly again.
|
|
1262
|
+
* Only applicable to schemas already wrapped with `mutableKey`.
|
|
1263
|
+
*
|
|
707
1264
|
* @since 4.0.0
|
|
708
1265
|
*/
|
|
709
1266
|
export declare const readonlyKey: readonlyKeyLambda;
|
|
710
1267
|
/**
|
|
1268
|
+
* Schema type that collapses a transformation schema to its decoded `Type` on
|
|
1269
|
+
* both sides (Type = Encoded = S["Type"]). Produced by {@link toType}.
|
|
1270
|
+
*
|
|
711
1271
|
* @since 4.0.0
|
|
712
1272
|
*/
|
|
713
1273
|
export interface toType<S extends Top> extends Bottom<S["Type"], S["Type"], never, never, S["ast"], toType<S>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -718,10 +1278,16 @@ interface toTypeLambda extends Lambda {
|
|
|
718
1278
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? toType<this["~lambda.in"]> : never;
|
|
719
1279
|
}
|
|
720
1280
|
/**
|
|
1281
|
+
* Extracts the type-side schema: sets `Encoded` to equal the decoded `Type`,
|
|
1282
|
+
* discarding the encoding transformation path.
|
|
1283
|
+
*
|
|
721
1284
|
* @since 4.0.0
|
|
722
1285
|
*/
|
|
723
1286
|
export declare const toType: toTypeLambda;
|
|
724
1287
|
/**
|
|
1288
|
+
* Schema type that collapses a transformation schema to its `Encoded` side on
|
|
1289
|
+
* both sides (Type = Encoded = S["Encoded"]). Produced by {@link toEncoded}.
|
|
1290
|
+
*
|
|
725
1291
|
* @since 4.0.0
|
|
726
1292
|
*/
|
|
727
1293
|
export interface toEncoded<S extends Top> extends Bottom<S["Encoded"], S["Encoded"], never, never, AST.AST, toEncoded<S>, S["Encoded"], S["Encoded"], ReadonlyArray<Top>, S["Encoded"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -732,11 +1298,17 @@ interface toEncodedLambda extends Lambda {
|
|
|
732
1298
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? toEncoded<this["~lambda.in"]> : never;
|
|
733
1299
|
}
|
|
734
1300
|
/**
|
|
1301
|
+
* Extracts the encoded-side schema: sets `Type` to equal the `Encoded`,
|
|
1302
|
+
* discarding the decoding transformation path.
|
|
1303
|
+
*
|
|
735
1304
|
* @since 4.0.0
|
|
736
1305
|
*/
|
|
737
1306
|
export declare const toEncoded: toEncodedLambda;
|
|
738
1307
|
declare const FlipTypeId = "~effect/Schema/flip";
|
|
739
1308
|
/**
|
|
1309
|
+
* Schema type representing a flipped schema where `Type` and `Encoded` are
|
|
1310
|
+
* swapped. Produced by {@link flip}.
|
|
1311
|
+
*
|
|
740
1312
|
* @since 4.0.0
|
|
741
1313
|
*/
|
|
742
1314
|
export interface flip<S extends Top> extends Bottom<S["Encoded"], S["Type"], S["EncodingServices"], S["DecodingServices"], AST.AST, flip<S>, S["Encoded"], S["Encoded"], ReadonlyArray<Top>, S["Encoded"], S["~encoded.mutability"], S["~encoded.optionality"], ConstructorDefault, S["~type.mutability"], S["~type.optionality"]> {
|
|
@@ -745,10 +1317,26 @@ export interface flip<S extends Top> extends Bottom<S["Encoded"], S["Type"], S["
|
|
|
745
1317
|
readonly schema: S;
|
|
746
1318
|
}
|
|
747
1319
|
/**
|
|
1320
|
+
* Swaps the `Type` and `Encoded` of a schema, inverting the transformation
|
|
1321
|
+
* direction. Calling `flip` twice returns the original schema.
|
|
1322
|
+
*
|
|
1323
|
+
* **Example** (Flip a number-from-string schema)
|
|
1324
|
+
*
|
|
1325
|
+
* ```ts
|
|
1326
|
+
* import { Schema } from "effect"
|
|
1327
|
+
*
|
|
1328
|
+
* // NumberFromString: decodes string → number
|
|
1329
|
+
* const flipped = Schema.flip(Schema.NumberFromString)
|
|
1330
|
+
* // flipped: decodes number → string
|
|
1331
|
+
* ```
|
|
1332
|
+
*
|
|
748
1333
|
* @since 4.0.0
|
|
749
1334
|
*/
|
|
750
1335
|
export declare function flip<S extends Top>(schema: S): S extends flip<infer F> ? F["~rebuild.out"] : flip<S>;
|
|
751
1336
|
/**
|
|
1337
|
+
* Represents a schema for a single literal value.
|
|
1338
|
+
*
|
|
1339
|
+
* @see {@link Literal} for the constructor function.
|
|
752
1340
|
* @since 4.0.0
|
|
753
1341
|
*/
|
|
754
1342
|
export interface Literal<L extends AST.LiteralValue> extends Bottom<L, L, never, never, AST.Literal, Literal<L>> {
|
|
@@ -757,6 +1345,16 @@ export interface Literal<L extends AST.LiteralValue> extends Bottom<L, L, never,
|
|
|
757
1345
|
transform<L2 extends AST.LiteralValue>(to: L2): decodeTo<Literal<L2>, Literal<L>>;
|
|
758
1346
|
}
|
|
759
1347
|
/**
|
|
1348
|
+
* Creates a schema for a single literal value (string, number, bigint, boolean, or null).
|
|
1349
|
+
*
|
|
1350
|
+
* **Example** (String literal)
|
|
1351
|
+
* ```ts
|
|
1352
|
+
* import { Schema } from "effect"
|
|
1353
|
+
*
|
|
1354
|
+
* const schema = Schema.Literal("hello")
|
|
1355
|
+
* // Type: Schema.Literal<"hello">
|
|
1356
|
+
* ```
|
|
1357
|
+
*
|
|
760
1358
|
* @see {@link Literals} for a schema that represents a union of literals.
|
|
761
1359
|
* @see {@link tag} for a schema that represents a literal value that can be
|
|
762
1360
|
* used as a discriminator field in tagged unions and has a constructor default.
|
|
@@ -764,6 +1362,8 @@ export interface Literal<L extends AST.LiteralValue> extends Bottom<L, L, never,
|
|
|
764
1362
|
*/
|
|
765
1363
|
export declare function Literal<L extends AST.LiteralValue>(literal: L): Literal<L>;
|
|
766
1364
|
/**
|
|
1365
|
+
* Namespace for {@link TemplateLiteral} helper types.
|
|
1366
|
+
*
|
|
767
1367
|
* @since 4.0.0
|
|
768
1368
|
*/
|
|
769
1369
|
export declare namespace TemplateLiteral {
|
|
@@ -792,6 +1392,10 @@ export declare namespace TemplateLiteral {
|
|
|
792
1392
|
type Encoded<Parts> = Parts extends readonly [...infer Init, infer Last] ? AppendType<Encoded<Init>, Last> : ``;
|
|
793
1393
|
}
|
|
794
1394
|
/**
|
|
1395
|
+
* Represents a schema that validates strings matching a template literal pattern.
|
|
1396
|
+
* The encoded type is a string formed by concatenating the parts.
|
|
1397
|
+
*
|
|
1398
|
+
* @see {@link TemplateLiteral} for the constructor function.
|
|
795
1399
|
* @since 4.0.0
|
|
796
1400
|
*/
|
|
797
1401
|
export interface TemplateLiteral<Parts extends TemplateLiteral.Parts> extends Bottom<TemplateLiteral.Encoded<Parts>, TemplateLiteral.Encoded<Parts>, never, never, AST.TemplateLiteral, TemplateLiteral<Parts>> {
|
|
@@ -799,10 +1403,24 @@ export interface TemplateLiteral<Parts extends TemplateLiteral.Parts> extends Bo
|
|
|
799
1403
|
readonly parts: Parts;
|
|
800
1404
|
}
|
|
801
1405
|
/**
|
|
1406
|
+
* Creates a schema that validates strings matching a template literal pattern. Each part can be
|
|
1407
|
+
* a literal string/number/bigint or a schema whose encoded type is a string, number, or bigint.
|
|
1408
|
+
*
|
|
1409
|
+
* **Example** (URL path pattern)
|
|
1410
|
+
* ```ts
|
|
1411
|
+
* import { Schema } from "effect"
|
|
1412
|
+
*
|
|
1413
|
+
* const schema = Schema.TemplateLiteral(["/user/", Schema.Number])
|
|
1414
|
+
* // matches strings like "/user/123", "/user/42", etc.
|
|
1415
|
+
* ```
|
|
1416
|
+
*
|
|
1417
|
+
* @see {@link TemplateLiteralParser} for a schema that also parses matched parts into a tuple.
|
|
802
1418
|
* @since 4.0.0
|
|
803
1419
|
*/
|
|
804
1420
|
export declare function TemplateLiteral<const Parts extends TemplateLiteral.Parts>(parts: Parts): TemplateLiteral<Parts>;
|
|
805
1421
|
/**
|
|
1422
|
+
* Namespace for {@link TemplateLiteralParser} helper types.
|
|
1423
|
+
*
|
|
806
1424
|
* @since 4.0.0
|
|
807
1425
|
*/
|
|
808
1426
|
export declare namespace TemplateLiteralParser {
|
|
@@ -815,6 +1433,10 @@ export declare namespace TemplateLiteralParser {
|
|
|
815
1433
|
] : [];
|
|
816
1434
|
}
|
|
817
1435
|
/**
|
|
1436
|
+
* Represents a schema that validates strings matching a template literal pattern and decodes
|
|
1437
|
+
* them into a tuple of typed values, one per schema part.
|
|
1438
|
+
*
|
|
1439
|
+
* @see {@link TemplateLiteralParser} for the constructor function.
|
|
818
1440
|
* @since 4.0.0
|
|
819
1441
|
*/
|
|
820
1442
|
export interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts> extends Bottom<TemplateLiteralParser.Type<Parts>, TemplateLiteral.Encoded<Parts>, never, never, AST.Arrays, TemplateLiteralParser<Parts>> {
|
|
@@ -822,10 +1444,26 @@ export interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts> exte
|
|
|
822
1444
|
readonly parts: Parts;
|
|
823
1445
|
}
|
|
824
1446
|
/**
|
|
1447
|
+
* Like {@link TemplateLiteral} but decodes the matched string into a readonly tuple of typed values,
|
|
1448
|
+
* one element per schema part.
|
|
1449
|
+
*
|
|
1450
|
+
* **Example** (Parse path parameters)
|
|
1451
|
+
* ```ts
|
|
1452
|
+
* import { Schema } from "effect"
|
|
1453
|
+
*
|
|
1454
|
+
* const schema = Schema.TemplateLiteralParser(["/user/", Schema.NumberFromString])
|
|
1455
|
+
* // decodes "/user/42" => readonly ["/user/", 42]
|
|
1456
|
+
* ```
|
|
1457
|
+
*
|
|
1458
|
+
* @see {@link TemplateLiteral} for a validation-only version that keeps the string encoded.
|
|
825
1459
|
* @since 4.0.0
|
|
826
1460
|
*/
|
|
827
1461
|
export declare function TemplateLiteralParser<const Parts extends TemplateLiteral.Parts>(parts: Parts): TemplateLiteralParser<Parts>;
|
|
828
1462
|
/**
|
|
1463
|
+
* Represents a schema derived from a TypeScript `const enum` or a plain enum object,
|
|
1464
|
+
* accepting any of its values.
|
|
1465
|
+
*
|
|
1466
|
+
* @see {@link Enum} for the constructor function.
|
|
829
1467
|
* @since 4.0.0
|
|
830
1468
|
*/
|
|
831
1469
|
export interface Enum<A extends {
|
|
@@ -835,176 +1473,262 @@ export interface Enum<A extends {
|
|
|
835
1473
|
readonly enums: A;
|
|
836
1474
|
}
|
|
837
1475
|
/**
|
|
1476
|
+
* Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
|
|
1477
|
+
*
|
|
1478
|
+
* **Example** (Direction enum)
|
|
1479
|
+
* ```ts
|
|
1480
|
+
* import { Schema } from "effect"
|
|
1481
|
+
*
|
|
1482
|
+
* enum Direction {
|
|
1483
|
+
* Up = "Up",
|
|
1484
|
+
* Down = "Down"
|
|
1485
|
+
* }
|
|
1486
|
+
*
|
|
1487
|
+
* const schema = Schema.Enum(Direction)
|
|
1488
|
+
* // accepts "Up" or "Down"
|
|
1489
|
+
* ```
|
|
1490
|
+
*
|
|
838
1491
|
* @since 4.0.0
|
|
839
1492
|
*/
|
|
840
1493
|
export declare function Enum<A extends {
|
|
841
1494
|
[x: string]: string | number;
|
|
842
1495
|
}>(enums: A): Enum<A>;
|
|
843
1496
|
/**
|
|
1497
|
+
* Schema for the `never` type. Always fails validation.
|
|
1498
|
+
*
|
|
1499
|
+
* @see {@link Never} for the schema value.
|
|
844
1500
|
* @since 4.0.0
|
|
845
1501
|
*/
|
|
846
1502
|
export interface Never extends Bottom<never, never, never, never, AST.Never, Never> {
|
|
847
1503
|
readonly "~rebuild.out": this;
|
|
848
1504
|
}
|
|
849
1505
|
/**
|
|
1506
|
+
* Schema for the `never` type. Always fails validation — no value satisfies it.
|
|
1507
|
+
*
|
|
850
1508
|
* @since 4.0.0
|
|
851
1509
|
*/
|
|
852
1510
|
export declare const Never: Never;
|
|
853
1511
|
/**
|
|
1512
|
+
* Schema for the `any` type. Accepts any value without validation.
|
|
1513
|
+
*
|
|
1514
|
+
* @see {@link Any} for the schema value.
|
|
854
1515
|
* @since 4.0.0
|
|
855
1516
|
*/
|
|
856
1517
|
export interface Any extends Bottom<any, any, never, never, AST.Any, Any> {
|
|
857
1518
|
readonly "~rebuild.out": this;
|
|
858
1519
|
}
|
|
859
1520
|
/**
|
|
1521
|
+
* Schema for the `any` type. Accepts any value without validation.
|
|
1522
|
+
*
|
|
1523
|
+
* @see {@link Unknown} for a safer alternative that uses `unknown`.
|
|
860
1524
|
* @since 4.0.0
|
|
861
1525
|
*/
|
|
862
1526
|
export declare const Any: Any;
|
|
863
1527
|
/**
|
|
1528
|
+
* Schema for the `unknown` type. Accepts any value without validation.
|
|
1529
|
+
*
|
|
1530
|
+
* @see {@link Unknown} for the schema value.
|
|
864
1531
|
* @since 4.0.0
|
|
865
1532
|
*/
|
|
866
1533
|
export interface Unknown extends Bottom<unknown, unknown, never, never, AST.Unknown, Unknown> {
|
|
867
1534
|
readonly "~rebuild.out": this;
|
|
868
1535
|
}
|
|
869
1536
|
/**
|
|
1537
|
+
* Schema for the `unknown` type. Accepts any value without validation.
|
|
1538
|
+
*
|
|
1539
|
+
* @see {@link Any} for the `any` variant.
|
|
870
1540
|
* @since 4.0.0
|
|
871
1541
|
*/
|
|
872
1542
|
export declare const Unknown: Unknown;
|
|
873
1543
|
/**
|
|
1544
|
+
* Schema for the `null` literal. Validates that the input is strictly `null`.
|
|
1545
|
+
*
|
|
1546
|
+
* @see {@link Null} for the schema value.
|
|
874
1547
|
* @since 4.0.0
|
|
875
1548
|
*/
|
|
876
1549
|
export interface Null extends Bottom<null, null, never, never, AST.Null, Null> {
|
|
877
1550
|
readonly "~rebuild.out": this;
|
|
878
1551
|
}
|
|
879
1552
|
/**
|
|
1553
|
+
* Schema for the `null` literal. Validates that the input is strictly `null`.
|
|
1554
|
+
*
|
|
1555
|
+
* @see {@link NullOr} for a union with another schema.
|
|
880
1556
|
* @since 4.0.0
|
|
881
1557
|
*/
|
|
882
1558
|
export declare const Null: Null;
|
|
883
1559
|
/**
|
|
1560
|
+
* Schema for the `undefined` literal. Validates that the input is strictly `undefined`.
|
|
1561
|
+
*
|
|
1562
|
+
* @see {@link Undefined} for the schema value.
|
|
884
1563
|
* @since 4.0.0
|
|
885
1564
|
*/
|
|
886
1565
|
export interface Undefined extends Bottom<undefined, undefined, never, never, AST.Undefined, Undefined> {
|
|
887
1566
|
readonly "~rebuild.out": this;
|
|
888
1567
|
}
|
|
889
1568
|
/**
|
|
1569
|
+
* Schema for the `undefined` literal. Validates that the input is strictly `undefined`.
|
|
1570
|
+
*
|
|
1571
|
+
* @see {@link UndefinedOr} for a union with another schema.
|
|
890
1572
|
* @since 4.0.0
|
|
891
1573
|
*/
|
|
892
1574
|
export declare const Undefined: Undefined;
|
|
893
1575
|
/**
|
|
1576
|
+
* Schema for `string` values.
|
|
1577
|
+
*
|
|
1578
|
+
* @see {@link String} for the schema value.
|
|
894
1579
|
* @since 4.0.0
|
|
895
1580
|
*/
|
|
896
1581
|
export interface String extends Bottom<string, string, never, never, AST.String, String> {
|
|
897
1582
|
readonly "~rebuild.out": this;
|
|
898
1583
|
}
|
|
899
1584
|
/**
|
|
900
|
-
*
|
|
1585
|
+
* Schema for `string` values. Validates that the input is `typeof` `"string"`.
|
|
901
1586
|
*
|
|
902
1587
|
* @since 4.0.0
|
|
903
1588
|
*/
|
|
904
1589
|
export declare const String: String;
|
|
905
1590
|
/**
|
|
1591
|
+
* Schema for `number` values, including `NaN`, `Infinity`, and `-Infinity`.
|
|
1592
|
+
*
|
|
1593
|
+
* @see {@link Number} for the schema value.
|
|
906
1594
|
* @since 4.0.0
|
|
907
1595
|
*/
|
|
908
1596
|
export interface Number extends Bottom<number, number, never, never, AST.Number, Number> {
|
|
909
1597
|
readonly "~rebuild.out": this;
|
|
910
1598
|
}
|
|
911
1599
|
/**
|
|
912
|
-
*
|
|
1600
|
+
* Schema for `number` values, including `NaN`, `Infinity`, and `-Infinity`.
|
|
913
1601
|
*
|
|
914
1602
|
* **Default Json Serializer**
|
|
915
1603
|
*
|
|
916
|
-
* -
|
|
917
|
-
* -
|
|
1604
|
+
* - Finite numbers are serialized as numbers.
|
|
1605
|
+
* - Non-finite values are serialized as strings (`"NaN"`, `"Infinity"`, `"-Infinity"`).
|
|
918
1606
|
*
|
|
1607
|
+
* @see {@link Finite} for a schema that excludes non-finite values.
|
|
919
1608
|
* @since 4.0.0
|
|
920
1609
|
*/
|
|
921
1610
|
export declare const Number: Number;
|
|
922
1611
|
/**
|
|
1612
|
+
* Schema for `boolean` values.
|
|
1613
|
+
*
|
|
1614
|
+
* @see {@link Boolean} for the schema value.
|
|
923
1615
|
* @since 4.0.0
|
|
924
1616
|
*/
|
|
925
1617
|
export interface Boolean extends Bottom<boolean, boolean, never, never, AST.Boolean, Boolean> {
|
|
926
1618
|
readonly "~rebuild.out": this;
|
|
927
1619
|
}
|
|
928
1620
|
/**
|
|
929
|
-
*
|
|
1621
|
+
* Schema for `boolean` values. Validates that the input is `typeof` `"boolean"`.
|
|
930
1622
|
*
|
|
931
1623
|
* @category Boolean
|
|
932
1624
|
* @since 4.0.0
|
|
933
1625
|
*/
|
|
934
1626
|
export declare const Boolean: Boolean;
|
|
935
1627
|
/**
|
|
1628
|
+
* Schema for `symbol` values.
|
|
1629
|
+
*
|
|
1630
|
+
* @see {@link Symbol} for the schema value.
|
|
936
1631
|
* @since 4.0.0
|
|
937
1632
|
*/
|
|
938
1633
|
export interface Symbol extends Bottom<symbol, symbol, never, never, AST.Symbol, Symbol> {
|
|
939
1634
|
readonly "~rebuild.out": this;
|
|
940
1635
|
}
|
|
941
1636
|
/**
|
|
942
|
-
*
|
|
1637
|
+
* Schema for `symbol` values. Validates that the input is `typeof` `"symbol"`.
|
|
943
1638
|
*
|
|
1639
|
+
* @see {@link UniqueSymbol} for a schema that matches a specific symbol.
|
|
944
1640
|
* @since 4.0.0
|
|
945
1641
|
*/
|
|
946
1642
|
export declare const Symbol: Symbol;
|
|
947
1643
|
/**
|
|
1644
|
+
* Schema for `bigint` values.
|
|
1645
|
+
*
|
|
1646
|
+
* @see {@link BigInt} for the schema value.
|
|
948
1647
|
* @since 4.0.0
|
|
949
1648
|
*/
|
|
950
1649
|
export interface BigInt extends Bottom<bigint, bigint, never, never, AST.BigInt, BigInt> {
|
|
951
1650
|
readonly "~rebuild.out": this;
|
|
952
1651
|
}
|
|
953
1652
|
/**
|
|
954
|
-
*
|
|
1653
|
+
* Schema for `bigint` values. Validates that the input is `typeof` `"bigint"`.
|
|
955
1654
|
*
|
|
956
1655
|
* @since 4.0.0
|
|
957
1656
|
*/
|
|
958
1657
|
export declare const BigInt: BigInt;
|
|
959
1658
|
/**
|
|
1659
|
+
* Schema for the `void` type.
|
|
1660
|
+
*
|
|
1661
|
+
* @see {@link Void} for the schema value.
|
|
960
1662
|
* @since 4.0.0
|
|
961
1663
|
*/
|
|
962
1664
|
export interface Void extends Bottom<void, void, never, never, AST.Void, Void> {
|
|
963
1665
|
readonly "~rebuild.out": this;
|
|
964
1666
|
}
|
|
965
1667
|
/**
|
|
966
|
-
*
|
|
1668
|
+
* Schema for the `void` type. Accepts `undefined` as the encoded value.
|
|
967
1669
|
*
|
|
968
1670
|
* @since 4.0.0
|
|
969
1671
|
*/
|
|
970
1672
|
export declare const Void: Void;
|
|
971
1673
|
/**
|
|
1674
|
+
* Schema for the `object` type keyword.
|
|
1675
|
+
*
|
|
1676
|
+
* @see {@link ObjectKeyword} for the schema value.
|
|
972
1677
|
* @since 4.0.0
|
|
973
1678
|
*/
|
|
974
1679
|
export interface ObjectKeyword extends Bottom<object, object, never, never, AST.ObjectKeyword, ObjectKeyword> {
|
|
975
1680
|
readonly "~rebuild.out": this;
|
|
976
1681
|
}
|
|
977
1682
|
/**
|
|
978
|
-
*
|
|
1683
|
+
* Schema for the `object` type. Validates that the input is a non-null object or function
|
|
1684
|
+
* (i.e. `typeof value === "object" && value !== null || typeof value === "function"`).
|
|
979
1685
|
*
|
|
980
1686
|
* @since 4.0.0
|
|
981
1687
|
*/
|
|
982
1688
|
export declare const ObjectKeyword: ObjectKeyword;
|
|
983
1689
|
/**
|
|
1690
|
+
* Represents a schema for a specific unique symbol.
|
|
1691
|
+
*
|
|
1692
|
+
* @see {@link UniqueSymbol} for the constructor function.
|
|
984
1693
|
* @since 4.0.0
|
|
985
1694
|
*/
|
|
986
1695
|
export interface UniqueSymbol<sym extends symbol> extends Bottom<sym, sym, never, never, AST.UniqueSymbol, UniqueSymbol<sym>> {
|
|
987
1696
|
readonly "~rebuild.out": this;
|
|
988
1697
|
}
|
|
989
1698
|
/**
|
|
990
|
-
*
|
|
991
|
-
*
|
|
992
|
-
* **Example**
|
|
1699
|
+
* Creates a schema for a specific symbol. Only that exact symbol satisfies the schema.
|
|
993
1700
|
*
|
|
1701
|
+
* **Example** (Specific symbol)
|
|
994
1702
|
* ```ts
|
|
995
1703
|
* import { Schema } from "effect"
|
|
996
1704
|
*
|
|
997
|
-
* const
|
|
998
|
-
* const schema = Schema.UniqueSymbol(
|
|
1705
|
+
* const mySymbol = Symbol.for("mySymbol")
|
|
1706
|
+
* const schema = Schema.UniqueSymbol(mySymbol)
|
|
999
1707
|
* ```
|
|
1708
|
+
*
|
|
1709
|
+
* @see {@link Symbol} for a schema that accepts any symbol.
|
|
1000
1710
|
* @since 4.0.0
|
|
1001
1711
|
*/
|
|
1002
1712
|
export declare function UniqueSymbol<const sym extends symbol>(symbol: sym): UniqueSymbol<sym>;
|
|
1003
1713
|
/**
|
|
1714
|
+
* Namespace for struct field type utilities.
|
|
1715
|
+
*
|
|
1716
|
+
* These types compute the decoded `Type`, encoded `Encoded`, and constructor
|
|
1717
|
+
* input `MakeIn` of a {@link Struct} from its field map, handling optional,
|
|
1718
|
+
* mutable, and other field modifiers automatically.
|
|
1719
|
+
*
|
|
1720
|
+
* - `Struct.Fields` — constraint for the field map object
|
|
1721
|
+
* - `Struct.Type<F>` — decoded type of the struct
|
|
1722
|
+
* - `Struct.Encoded<F>` — encoded type of the struct
|
|
1723
|
+
* - `Struct.MakeIn<F>` — constructor input (optional/defaulted fields may be omitted)
|
|
1724
|
+
* - `Struct.DecodingServices<F>` / `Struct.EncodingServices<F>` — required services
|
|
1725
|
+
*
|
|
1004
1726
|
* @since 4.0.0
|
|
1005
1727
|
*/
|
|
1006
1728
|
export declare namespace Struct {
|
|
1007
1729
|
/**
|
|
1730
|
+
* Constraint for a struct field map: an object whose values are schemas.
|
|
1731
|
+
*
|
|
1008
1732
|
* @since 4.0.0
|
|
1009
1733
|
*/
|
|
1010
1734
|
type Fields = {
|
|
@@ -1142,6 +1866,34 @@ export interface Struct<Fields extends Struct.Fields> extends Bottom<Simplify<St
|
|
|
1142
1866
|
} | undefined): Struct<Simplify<Readonly<To>>>;
|
|
1143
1867
|
}
|
|
1144
1868
|
/**
|
|
1869
|
+
* Defines a struct schema from a map of field schemas.
|
|
1870
|
+
*
|
|
1871
|
+
* Each field value is a schema. Use {@link optionalKey} or {@link optional} to
|
|
1872
|
+
* mark fields as optional, and {@link mutableKey} to mark them as mutable.
|
|
1873
|
+
*
|
|
1874
|
+
* The resulting schema's `Type` is a readonly object type with the fields'
|
|
1875
|
+
* decoded types. The `Encoded` form mirrors the field schemas' encoded types.
|
|
1876
|
+
*
|
|
1877
|
+
* **Example** (Basic struct)
|
|
1878
|
+
*
|
|
1879
|
+
* ```ts
|
|
1880
|
+
* import { Schema } from "effect"
|
|
1881
|
+
*
|
|
1882
|
+
* const Person = Schema.Struct({
|
|
1883
|
+
* name: Schema.String,
|
|
1884
|
+
* age: Schema.Number,
|
|
1885
|
+
* email: Schema.optionalKey(Schema.String)
|
|
1886
|
+
* })
|
|
1887
|
+
*
|
|
1888
|
+
* // { readonly name: string; readonly age: number; readonly email?: string }
|
|
1889
|
+
* type Person = typeof Person.Type
|
|
1890
|
+
*
|
|
1891
|
+
* const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
|
|
1892
|
+
* console.log(alice)
|
|
1893
|
+
* // { name: 'Alice', age: 30 }
|
|
1894
|
+
* ```
|
|
1895
|
+
*
|
|
1896
|
+
* @category Constructors
|
|
1145
1897
|
* @since 4.0.0
|
|
1146
1898
|
*/
|
|
1147
1899
|
export declare function Struct<const Fields extends Struct.Fields>(fields: Fields): Struct<Fields>;
|
|
@@ -1169,6 +1921,26 @@ interface fieldsAssign<NewFields extends Struct.Fields> extends Lambda {
|
|
|
1169
1921
|
*/
|
|
1170
1922
|
export declare function fieldsAssign<const NewFields extends Struct.Fields>(fields: NewFields): fieldsAssign<NewFields>;
|
|
1171
1923
|
/**
|
|
1924
|
+
* Renames struct keys in the encoded form without changing the decoded type.
|
|
1925
|
+
*
|
|
1926
|
+
* Takes a partial mapping `{ decodedKey: encodedKey }` and produces a
|
|
1927
|
+
* transformation schema that decodes from the renamed keys and encodes back to
|
|
1928
|
+
* the renamed keys. Keys not present in the mapping are left unchanged.
|
|
1929
|
+
*
|
|
1930
|
+
* **Example** (Rename `name` to `full_name` in the encoded form)
|
|
1931
|
+
*
|
|
1932
|
+
* ```ts
|
|
1933
|
+
* import { Schema } from "effect"
|
|
1934
|
+
*
|
|
1935
|
+
* const Person = Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
1936
|
+
* const Encoded = Person.pipe(Schema.encodeKeys({ name: "full_name" }))
|
|
1937
|
+
*
|
|
1938
|
+
* // Decodes { full_name: "Alice", age: 30 } → { name: "Alice", age: 30 }
|
|
1939
|
+
* const alice = Schema.decodeUnknownSync(Encoded)({ full_name: "Alice", age: 30 })
|
|
1940
|
+
* console.log(alice)
|
|
1941
|
+
* // { name: 'Alice', age: 30 }
|
|
1942
|
+
* ```
|
|
1943
|
+
*
|
|
1172
1944
|
* @category Struct transformations
|
|
1173
1945
|
* @since 4.0.0
|
|
1174
1946
|
*/
|
|
@@ -1178,6 +1950,31 @@ export declare function encodeKeys<S extends Top & {
|
|
|
1178
1950
|
readonly [K in keyof S["fields"]]?: PropertyKey;
|
|
1179
1951
|
}>(mapping: M): (self: S) => decodeTo<S, Struct<{ [K in keyof S["fields"] as K extends keyof M ? M[K] extends PropertyKey ? M[K] : K : K]: toEncoded<S["fields"][K]>; }>>;
|
|
1180
1952
|
/**
|
|
1953
|
+
* Adds derived fields to a struct schema during decoding.
|
|
1954
|
+
*
|
|
1955
|
+
* Each new field is derived from the decoded struct value via a function that
|
|
1956
|
+
* returns `Option`. On encoding the derived fields are stripped. This allows
|
|
1957
|
+
* computed or enriched fields to live in the decoded type without appearing in
|
|
1958
|
+
* the encoded form.
|
|
1959
|
+
*
|
|
1960
|
+
* **Example** (Add a computed `fullName` field)
|
|
1961
|
+
*
|
|
1962
|
+
* ```ts
|
|
1963
|
+
* import { Option, Schema } from "effect"
|
|
1964
|
+
*
|
|
1965
|
+
* const Person = Schema.Struct({ first: Schema.String, last: Schema.String })
|
|
1966
|
+
* const Extended = Person.pipe(
|
|
1967
|
+
* Schema.extendTo(
|
|
1968
|
+
* { fullName: Schema.String },
|
|
1969
|
+
* { fullName: (p) => Option.some(`${p.first} ${p.last}`) }
|
|
1970
|
+
* )
|
|
1971
|
+
* )
|
|
1972
|
+
*
|
|
1973
|
+
* const alice = Schema.decodeUnknownSync(Extended)({ first: "Alice", last: "Smith" })
|
|
1974
|
+
* console.log(alice.fullName)
|
|
1975
|
+
* // Alice Smith
|
|
1976
|
+
* ```
|
|
1977
|
+
*
|
|
1181
1978
|
* @since 4.0.0
|
|
1182
1979
|
* @experimental
|
|
1183
1980
|
*/
|
|
@@ -1189,6 +1986,12 @@ derive: {
|
|
|
1189
1986
|
readonly [K in keyof Fields]: (s: S["Type"]) => Option_.Option<Fields[K]["Type"]>;
|
|
1190
1987
|
}): (self: S) => decodeTo<Struct<Simplify<{ [K in keyof S["fields"]]: toType<S["fields"][K]>; } & Fields>>, S>;
|
|
1191
1988
|
/**
|
|
1989
|
+
* Namespace for `Record` type utilities.
|
|
1990
|
+
*
|
|
1991
|
+
* - `Record.Key` — constraint for the key schema (must encode to `PropertyKey`)
|
|
1992
|
+
* - `Record.Type<K, V>` — decoded type of the record
|
|
1993
|
+
* - `Record.Encoded<K, V>` — encoded type of the record
|
|
1994
|
+
*
|
|
1192
1995
|
* @since 4.0.0
|
|
1193
1996
|
*/
|
|
1194
1997
|
export declare namespace Record {
|
|
@@ -1281,6 +2084,9 @@ export declare namespace Record {
|
|
|
1281
2084
|
};
|
|
1282
2085
|
}
|
|
1283
2086
|
/**
|
|
2087
|
+
* Schema type for a key-value record (map) with a typed key and value schema.
|
|
2088
|
+
* Produced by {@link Record}.
|
|
2089
|
+
*
|
|
1284
2090
|
* @since 4.0.0
|
|
1285
2091
|
*/
|
|
1286
2092
|
export interface $Record<Key extends Record.Key, Value extends Top> extends Bottom<Record.Type<Key, Value>, Record.Encoded<Key, Value>, Record.DecodingServices<Key, Value>, Record.EncodingServices<Key, Value>, AST.Objects, $Record<Key, Value>, Simplify<Record.MakeIn<Key, Value>>, Record.Iso<Key, Value>> {
|
|
@@ -1289,6 +2095,24 @@ export interface $Record<Key extends Record.Key, Value extends Top> extends Bott
|
|
|
1289
2095
|
readonly value: Value;
|
|
1290
2096
|
}
|
|
1291
2097
|
/**
|
|
2098
|
+
* Defines a record (dictionary) schema with typed keys and values.
|
|
2099
|
+
*
|
|
2100
|
+
* **Example** (String-keyed record of numbers)
|
|
2101
|
+
*
|
|
2102
|
+
* ```ts
|
|
2103
|
+
* import { Schema } from "effect"
|
|
2104
|
+
*
|
|
2105
|
+
* const schema = Schema.Record(Schema.String, Schema.Number)
|
|
2106
|
+
*
|
|
2107
|
+
* // { readonly [x: string]: number }
|
|
2108
|
+
* type R = typeof schema.Type
|
|
2109
|
+
*
|
|
2110
|
+
* const result = Schema.decodeUnknownSync(schema)({ a: 1, b: 2 })
|
|
2111
|
+
* console.log(result)
|
|
2112
|
+
* // { a: 1, b: 2 }
|
|
2113
|
+
* ```
|
|
2114
|
+
*
|
|
2115
|
+
* @category Constructors
|
|
1292
2116
|
* @since 4.0.0
|
|
1293
2117
|
*/
|
|
1294
2118
|
export declare function Record<Key extends Record.Key, Value extends Top>(key: Key, value: Value, options?: {
|
|
@@ -1298,6 +2122,11 @@ export declare function Record<Key extends Record.Key, Value extends Top>(key: K
|
|
|
1298
2122
|
};
|
|
1299
2123
|
}): $Record<Key, Value>;
|
|
1300
2124
|
/**
|
|
2125
|
+
* Namespace for `StructWithRest` type utilities.
|
|
2126
|
+
*
|
|
2127
|
+
* - `StructWithRest.Type<S, R>` — decoded type (struct type intersected with record types)
|
|
2128
|
+
* - `StructWithRest.Encoded<S, R>` — encoded type
|
|
2129
|
+
*
|
|
1301
2130
|
* @since 4.0.0
|
|
1302
2131
|
*/
|
|
1303
2132
|
export declare namespace StructWithRest {
|
|
@@ -1350,6 +2179,9 @@ export declare namespace StructWithRest {
|
|
|
1350
2179
|
}>;
|
|
1351
2180
|
}
|
|
1352
2181
|
/**
|
|
2182
|
+
* Schema type for a struct combined with one or more record schemas. Produced
|
|
2183
|
+
* by {@link StructWithRest}.
|
|
2184
|
+
*
|
|
1353
2185
|
* @since 4.0.0
|
|
1354
2186
|
*/
|
|
1355
2187
|
export interface StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records> extends Bottom<Simplify<StructWithRest.Type<S, Records>>, Simplify<StructWithRest.Encoded<S, Records>>, StructWithRest.DecodingServices<S, Records>, StructWithRest.EncodingServices<S, Records>, AST.Objects, StructWithRest<S, Records>, Simplify<StructWithRest.MakeIn<S, Records>>, Simplify<StructWithRest.Iso<S, Records>>> {
|
|
@@ -1358,10 +2190,35 @@ export interface StructWithRest<S extends StructWithRest.Objects, Records extend
|
|
|
1358
2190
|
readonly records: Records;
|
|
1359
2191
|
}
|
|
1360
2192
|
/**
|
|
2193
|
+
* Extends a struct schema with one or more record (index-signature) schemas,
|
|
2194
|
+
* producing a schema whose decoded type intersects the struct and all records.
|
|
2195
|
+
*
|
|
2196
|
+
* **Example** (Struct with string-indexed extra keys)
|
|
2197
|
+
*
|
|
2198
|
+
* ```ts
|
|
2199
|
+
* import { Schema } from "effect"
|
|
2200
|
+
*
|
|
2201
|
+
* const schema = Schema.StructWithRest(
|
|
2202
|
+
* Schema.Struct({ id: Schema.Number }),
|
|
2203
|
+
* [Schema.Record(Schema.String, Schema.String)]
|
|
2204
|
+
* )
|
|
2205
|
+
*
|
|
2206
|
+
* // { readonly id: number } & { readonly [x: string]: string }
|
|
2207
|
+
* type T = typeof schema.Type
|
|
2208
|
+
* ```
|
|
2209
|
+
*
|
|
2210
|
+
* @category Constructors
|
|
1361
2211
|
* @since 4.0.0
|
|
1362
2212
|
*/
|
|
1363
2213
|
export declare function StructWithRest<const S extends StructWithRest.Objects, const Records extends StructWithRest.Records>(schema: S, records: Records): StructWithRest<S, Records>;
|
|
1364
2214
|
/**
|
|
2215
|
+
* Namespace for `Tuple` type utilities.
|
|
2216
|
+
*
|
|
2217
|
+
* - `Tuple.Elements` — constraint for the element schema array
|
|
2218
|
+
* - `Tuple.Type<E>` — decoded tuple type
|
|
2219
|
+
* - `Tuple.Encoded<E>` — encoded tuple type
|
|
2220
|
+
* - `Tuple.MakeIn<E>` — constructor input tuple
|
|
2221
|
+
*
|
|
1365
2222
|
* @since 4.0.0
|
|
1366
2223
|
*/
|
|
1367
2224
|
export declare namespace Tuple {
|
|
@@ -1417,6 +2274,8 @@ export declare namespace Tuple {
|
|
|
1417
2274
|
type MakeIn<E extends Elements> = MakeIn_<E>;
|
|
1418
2275
|
}
|
|
1419
2276
|
/**
|
|
2277
|
+
* Schema type for a fixed-length tuple. Produced by {@link Tuple}.
|
|
2278
|
+
*
|
|
1420
2279
|
* @since 4.0.0
|
|
1421
2280
|
*/
|
|
1422
2281
|
export interface Tuple<Elements extends Tuple.Elements> extends Bottom<Tuple.Type<Elements>, Tuple.Encoded<Elements>, Tuple.DecodingServices<Elements>, Tuple.EncodingServices<Elements>, AST.Arrays, Tuple<Elements>, Tuple.MakeIn<Elements>, Tuple.Iso<Elements>> {
|
|
@@ -1441,11 +2300,32 @@ export interface Tuple<Elements extends Tuple.Elements> extends Bottom<Tuple.Typ
|
|
|
1441
2300
|
} | undefined): Tuple<Simplify<Readonly<To>>>;
|
|
1442
2301
|
}
|
|
1443
2302
|
/**
|
|
2303
|
+
* Defines a fixed-length tuple schema from an array of element schemas.
|
|
2304
|
+
*
|
|
2305
|
+
* **Example** (Pair of string and number)
|
|
2306
|
+
*
|
|
2307
|
+
* ```ts
|
|
2308
|
+
* import { Schema } from "effect"
|
|
2309
|
+
*
|
|
2310
|
+
* const schema = Schema.Tuple([Schema.String, Schema.Number])
|
|
2311
|
+
*
|
|
2312
|
+
* const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
|
|
2313
|
+
* console.log(pair)
|
|
2314
|
+
* // [ 'hello', 42 ]
|
|
2315
|
+
* ```
|
|
2316
|
+
*
|
|
1444
2317
|
* @category Constructors
|
|
1445
2318
|
* @since 4.0.0
|
|
1446
2319
|
*/
|
|
1447
2320
|
export declare function Tuple<const Elements extends ReadonlyArray<Top>>(elements: Elements): Tuple<Elements>;
|
|
1448
2321
|
/**
|
|
2322
|
+
* Namespace for `TupleWithRest` type utilities.
|
|
2323
|
+
*
|
|
2324
|
+
* - `TupleWithRest.TupleType` — constraint for the leading tuple schema
|
|
2325
|
+
* - `TupleWithRest.Rest` — the rest element schema(s)
|
|
2326
|
+
* - `TupleWithRest.Type<T, R>` — decoded type (fixed elements + rest)
|
|
2327
|
+
* - `TupleWithRest.Encoded<T, R>` — encoded type
|
|
2328
|
+
*
|
|
1449
2329
|
* @since 4.0.0
|
|
1450
2330
|
*/
|
|
1451
2331
|
export declare namespace TupleWithRest {
|
|
@@ -1505,6 +2385,9 @@ export declare namespace TupleWithRest {
|
|
|
1505
2385
|
] : M;
|
|
1506
2386
|
}
|
|
1507
2387
|
/**
|
|
2388
|
+
* Schema type for a tuple with additional rest elements. Produced by
|
|
2389
|
+
* {@link TupleWithRest}.
|
|
2390
|
+
*
|
|
1508
2391
|
* @since 4.0.0
|
|
1509
2392
|
*/
|
|
1510
2393
|
export interface TupleWithRest<S extends TupleWithRest.TupleType, Rest extends TupleWithRest.Rest> extends Bottom<TupleWithRest.Type<S["Type"], Rest>, TupleWithRest.Encoded<S["Encoded"], Rest>, S["DecodingServices"] | Rest[number]["DecodingServices"], S["EncodingServices"] | Rest[number]["EncodingServices"], AST.Arrays, TupleWithRest<S, Rest>, TupleWithRest.MakeIn<S["~type.make"], Rest>, TupleWithRest.Iso<S["Iso"], Rest>> {
|
|
@@ -1513,11 +2396,33 @@ export interface TupleWithRest<S extends TupleWithRest.TupleType, Rest extends T
|
|
|
1513
2396
|
readonly rest: Rest;
|
|
1514
2397
|
}
|
|
1515
2398
|
/**
|
|
2399
|
+
* Extends a fixed-length tuple schema with rest elements, creating a variadic
|
|
2400
|
+
* tuple that starts with the fixed elements and ends with zero or more rest
|
|
2401
|
+
* elements.
|
|
2402
|
+
*
|
|
2403
|
+
* **Example** (Tuple with rest)
|
|
2404
|
+
*
|
|
2405
|
+
* ```ts
|
|
2406
|
+
* import { Schema } from "effect"
|
|
2407
|
+
*
|
|
2408
|
+
* // [string, number, ...boolean[]]
|
|
2409
|
+
* const schema = Schema.TupleWithRest(
|
|
2410
|
+
* Schema.Tuple([Schema.String, Schema.Number]),
|
|
2411
|
+
* [Schema.Boolean]
|
|
2412
|
+
* )
|
|
2413
|
+
*
|
|
2414
|
+
* const result = Schema.decodeUnknownSync(schema)(["hello", 1, true, false])
|
|
2415
|
+
* console.log(result)
|
|
2416
|
+
* // [ 'hello', 1, true, false ]
|
|
2417
|
+
* ```
|
|
2418
|
+
*
|
|
1516
2419
|
* @category Constructors
|
|
1517
2420
|
* @since 4.0.0
|
|
1518
2421
|
*/
|
|
1519
2422
|
export declare function TupleWithRest<S extends Tuple<Tuple.Elements>, const Rest extends TupleWithRest.Rest>(schema: S, rest: Rest): TupleWithRest<S, Rest>;
|
|
1520
2423
|
/**
|
|
2424
|
+
* Schema type for a `ReadonlyArray`. Produced by {@link Array}.
|
|
2425
|
+
*
|
|
1521
2426
|
* @since 4.0.0
|
|
1522
2427
|
*/
|
|
1523
2428
|
export interface $Array<S extends Top> extends Bottom<ReadonlyArray<S["Type"]>, ReadonlyArray<S["Encoded"]>, S["DecodingServices"], S["EncodingServices"], AST.Arrays, $Array<S>, ReadonlyArray<S["~type.make"]>, ReadonlyArray<S["Iso"]>> {
|
|
@@ -1529,11 +2434,27 @@ interface ArrayLambda extends Lambda {
|
|
|
1529
2434
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? $Array<this["~lambda.in"]> : never;
|
|
1530
2435
|
}
|
|
1531
2436
|
/**
|
|
2437
|
+
* Defines a `ReadonlyArray` schema for a given element schema.
|
|
2438
|
+
*
|
|
2439
|
+
* **Example** (Array of strings)
|
|
2440
|
+
*
|
|
2441
|
+
* ```ts
|
|
2442
|
+
* import { Schema } from "effect"
|
|
2443
|
+
*
|
|
2444
|
+
* const schema = Schema.Array(Schema.String)
|
|
2445
|
+
*
|
|
2446
|
+
* const result = Schema.decodeUnknownSync(schema)(["a", "b", "c"])
|
|
2447
|
+
* console.log(result)
|
|
2448
|
+
* // [ 'a', 'b', 'c' ]
|
|
2449
|
+
* ```
|
|
2450
|
+
*
|
|
1532
2451
|
* @category Constructors
|
|
1533
2452
|
* @since 4.0.0
|
|
1534
2453
|
*/
|
|
1535
2454
|
export declare const Array: ArrayLambda;
|
|
1536
2455
|
/**
|
|
2456
|
+
* Schema type for a non-empty `ReadonlyArray`. Produced by {@link NonEmptyArray}.
|
|
2457
|
+
*
|
|
1537
2458
|
* @since 4.0.0
|
|
1538
2459
|
*/
|
|
1539
2460
|
export interface NonEmptyArray<S extends Top> extends Bottom<readonly [S["Type"], ...Array<S["Type"]>], readonly [S["Encoded"], ...Array<S["Encoded"]>], S["DecodingServices"], S["EncodingServices"], AST.Arrays, NonEmptyArray<S>, readonly [S["~type.make"], ...Array<S["~type.make"]>], readonly [S["Iso"], ...Array<S["Iso"]>]> {
|
|
@@ -1545,11 +2466,27 @@ interface NonEmptyArrayLambda extends Lambda {
|
|
|
1545
2466
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? NonEmptyArray<this["~lambda.in"]> : never;
|
|
1546
2467
|
}
|
|
1547
2468
|
/**
|
|
2469
|
+
* Defines a non-empty `ReadonlyArray` schema — at least one element required.
|
|
2470
|
+
* Type is `readonly [T, ...T[]]`.
|
|
2471
|
+
*
|
|
2472
|
+
* **Example** (Non-empty array of numbers)
|
|
2473
|
+
*
|
|
2474
|
+
* ```ts
|
|
2475
|
+
* import { Schema } from "effect"
|
|
2476
|
+
*
|
|
2477
|
+
* const schema = Schema.NonEmptyArray(Schema.Number)
|
|
2478
|
+
*
|
|
2479
|
+
* Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
|
|
2480
|
+
* Schema.decodeUnknownSync(schema)([]) // throws
|
|
2481
|
+
* ```
|
|
2482
|
+
*
|
|
1548
2483
|
* @category Constructors
|
|
1549
2484
|
* @since 4.0.0
|
|
1550
2485
|
*/
|
|
1551
2486
|
export declare const NonEmptyArray: NonEmptyArrayLambda;
|
|
1552
2487
|
/**
|
|
2488
|
+
* Schema type for an array with unique elements. Produced by {@link UniqueArray}.
|
|
2489
|
+
*
|
|
1553
2490
|
* @since 4.0.0
|
|
1554
2491
|
*/
|
|
1555
2492
|
export interface UniqueArray<S extends Top> extends $Array<S> {
|
|
@@ -1565,6 +2502,9 @@ export interface UniqueArray<S extends Top> extends $Array<S> {
|
|
|
1565
2502
|
*/
|
|
1566
2503
|
export declare function UniqueArray<S extends Top>(item: S): UniqueArray<S>;
|
|
1567
2504
|
/**
|
|
2505
|
+
* Schema type that makes array or tuple elements mutable (removes `readonly`).
|
|
2506
|
+
* Produced by {@link mutable}.
|
|
2507
|
+
*
|
|
1568
2508
|
* @since 4.0.0
|
|
1569
2509
|
*/
|
|
1570
2510
|
export interface mutable<S extends Top & {
|
|
@@ -1582,12 +2522,25 @@ interface mutableLambda extends Lambda {
|
|
|
1582
2522
|
} ? mutable<this["~lambda.in"]> : "Error: schema not eligible for mutable";
|
|
1583
2523
|
}
|
|
1584
2524
|
/**
|
|
1585
|
-
* Makes
|
|
2525
|
+
* Makes an array or tuple schema mutable, removing the `readonly` modifier.
|
|
2526
|
+
*
|
|
2527
|
+
* **Example** (Mutable array)
|
|
2528
|
+
*
|
|
2529
|
+
* ```ts
|
|
2530
|
+
* import { Schema } from "effect"
|
|
2531
|
+
*
|
|
2532
|
+
* const schema = Schema.mutable(Schema.Array(Schema.Number))
|
|
2533
|
+
*
|
|
2534
|
+
* // number[] (mutable)
|
|
2535
|
+
* type T = typeof schema.Type
|
|
2536
|
+
* ```
|
|
1586
2537
|
*
|
|
1587
2538
|
* @since 4.0.0
|
|
1588
2539
|
*/
|
|
1589
2540
|
export declare const mutable: mutableLambda;
|
|
1590
2541
|
/**
|
|
2542
|
+
* Schema type for a union of multiple schemas. Produced by {@link Union}.
|
|
2543
|
+
*
|
|
1591
2544
|
* @since 4.0.0
|
|
1592
2545
|
*/
|
|
1593
2546
|
export interface Union<Members extends ReadonlyArray<Top>> extends Bottom<{
|
|
@@ -1626,12 +2579,23 @@ export interface Union<Members extends ReadonlyArray<Top>> extends Bottom<{
|
|
|
1626
2579
|
} | undefined): Union<Simplify<Readonly<To>>>;
|
|
1627
2580
|
}
|
|
1628
2581
|
/**
|
|
1629
|
-
* Creates a schema
|
|
2582
|
+
* Creates a union schema from an array of member schemas. Members are tested in
|
|
2583
|
+
* order; the first match is returned.
|
|
2584
|
+
*
|
|
2585
|
+
* Optionally, specify `mode`:
|
|
2586
|
+
* - `"anyOf"` (default) — matches if any member matches.
|
|
2587
|
+
* - `"oneOf"` — matches if exactly one member matches.
|
|
1630
2588
|
*
|
|
1631
|
-
*
|
|
2589
|
+
* **Example** (String or number union)
|
|
1632
2590
|
*
|
|
1633
|
-
*
|
|
1634
|
-
*
|
|
2591
|
+
* ```ts
|
|
2592
|
+
* import { Schema } from "effect"
|
|
2593
|
+
*
|
|
2594
|
+
* const schema = Schema.Union([Schema.String, Schema.Number])
|
|
2595
|
+
*
|
|
2596
|
+
* Schema.decodeUnknownSync(schema)("hello") // "hello"
|
|
2597
|
+
* Schema.decodeUnknownSync(schema)(42) // 42
|
|
2598
|
+
* ```
|
|
1635
2599
|
*
|
|
1636
2600
|
* @category Constructors
|
|
1637
2601
|
* @since 4.0.0
|
|
@@ -1640,6 +2604,9 @@ export declare function Union<const Members extends ReadonlyArray<Top>>(members:
|
|
|
1640
2604
|
mode?: "anyOf" | "oneOf";
|
|
1641
2605
|
}): Union<Members>;
|
|
1642
2606
|
/**
|
|
2607
|
+
* Represents a union schema of multiple literal values.
|
|
2608
|
+
*
|
|
2609
|
+
* @see {@link Literals} for the constructor function.
|
|
1643
2610
|
* @since 4.0.0
|
|
1644
2611
|
*/
|
|
1645
2612
|
export interface Literals<L extends ReadonlyArray<AST.LiteralValue>> extends Bottom<L[number], L[number], never, never, AST.Union<AST.Literal>, Literals<L>> {
|
|
@@ -1660,12 +2627,24 @@ export interface Literals<L extends ReadonlyArray<AST.LiteralValue>> extends Bot
|
|
|
1660
2627
|
}>;
|
|
1661
2628
|
}
|
|
1662
2629
|
/**
|
|
2630
|
+
* Creates a union schema from an array of literal values.
|
|
2631
|
+
*
|
|
2632
|
+
* **Example** (Status codes)
|
|
2633
|
+
* ```ts
|
|
2634
|
+
* import { Schema } from "effect"
|
|
2635
|
+
*
|
|
2636
|
+
* const schema = Schema.Literals(["active", "inactive", "pending"])
|
|
2637
|
+
* // accepts "active", "inactive", or "pending"
|
|
2638
|
+
* ```
|
|
2639
|
+
*
|
|
1663
2640
|
* @see {@link Literal} for a schema that represents a single literal.
|
|
1664
2641
|
* @category Constructors
|
|
1665
2642
|
* @since 4.0.0
|
|
1666
2643
|
*/
|
|
1667
2644
|
export declare function Literals<const L extends ReadonlyArray<AST.LiteralValue>>(literals: L): Literals<L>;
|
|
1668
2645
|
/**
|
|
2646
|
+
* Schema type for `S | null`. Produced by {@link NullOr}.
|
|
2647
|
+
*
|
|
1669
2648
|
* @since 4.0.0
|
|
1670
2649
|
*/
|
|
1671
2650
|
export interface NullOr<S extends Top> extends Union<readonly [S, Null]> {
|
|
@@ -1675,11 +2654,15 @@ interface NullOrLambda extends Lambda {
|
|
|
1675
2654
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? NullOr<this["~lambda.in"]> : never;
|
|
1676
2655
|
}
|
|
1677
2656
|
/**
|
|
2657
|
+
* Creates a union schema of `S | null`.
|
|
2658
|
+
*
|
|
1678
2659
|
* @category Constructors
|
|
1679
2660
|
* @since 4.0.0
|
|
1680
2661
|
*/
|
|
1681
2662
|
export declare const NullOr: NullOrLambda;
|
|
1682
2663
|
/**
|
|
2664
|
+
* Schema type for `S | undefined`. Produced by {@link UndefinedOr}.
|
|
2665
|
+
*
|
|
1683
2666
|
* @since 4.0.0
|
|
1684
2667
|
*/
|
|
1685
2668
|
export interface UndefinedOr<S extends Top> extends Union<readonly [S, Undefined]> {
|
|
@@ -1689,11 +2672,14 @@ interface UndefinedOrLambda extends Lambda {
|
|
|
1689
2672
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? UndefinedOr<this["~lambda.in"]> : never;
|
|
1690
2673
|
}
|
|
1691
2674
|
/**
|
|
2675
|
+
* Creates a union schema of `S | undefined`.
|
|
2676
|
+
*
|
|
1692
2677
|
* @category Constructors
|
|
1693
2678
|
* @since 4.0.0
|
|
1694
2679
|
*/
|
|
1695
2680
|
export declare const UndefinedOr: UndefinedOrLambda;
|
|
1696
2681
|
/**
|
|
2682
|
+
* Schema type for `S | null | undefined`. Produced by {@link NullishOr}.
|
|
1697
2683
|
* @since 4.0.0
|
|
1698
2684
|
*/
|
|
1699
2685
|
export interface NullishOr<S extends Top> extends Union<readonly [S, Null, Undefined]> {
|
|
@@ -1703,11 +2689,13 @@ interface NullishOrLambda extends Lambda {
|
|
|
1703
2689
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? NullishOr<this["~lambda.in"]> : never;
|
|
1704
2690
|
}
|
|
1705
2691
|
/**
|
|
2692
|
+
* Creates a union schema of `S | null | undefined`.
|
|
1706
2693
|
* @category Constructors
|
|
1707
2694
|
* @since 4.0.0
|
|
1708
2695
|
*/
|
|
1709
2696
|
export declare const NullishOr: NullishOrLambda;
|
|
1710
2697
|
/**
|
|
2698
|
+
* Schema type wrapping a lazily-evaluated schema. Produced by {@link suspend}.
|
|
1711
2699
|
* @since 4.0.0
|
|
1712
2700
|
*/
|
|
1713
2701
|
export interface suspend<S extends Top> extends Bottom<S["Type"], S["Encoded"], S["DecodingServices"], S["EncodingServices"], AST.Suspend, suspend<S>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -1718,16 +2706,46 @@ export interface suspend<S extends Top> extends Bottom<S["Type"], S["Encoded"],
|
|
|
1718
2706
|
* essential for creating recursive schemas where a schema references itself,
|
|
1719
2707
|
* preventing infinite recursion during schema definition.
|
|
1720
2708
|
*
|
|
2709
|
+
* **Example** (Recursive tree schema)
|
|
2710
|
+
* ```ts
|
|
2711
|
+
* import { Schema } from "effect"
|
|
2712
|
+
*
|
|
2713
|
+
* interface Tree {
|
|
2714
|
+
* readonly value: number
|
|
2715
|
+
* readonly children: ReadonlyArray<Tree>
|
|
2716
|
+
* }
|
|
2717
|
+
*
|
|
2718
|
+
* const Tree = Schema.Struct({
|
|
2719
|
+
* value: Schema.Number,
|
|
2720
|
+
* children: Schema.Array(Schema.suspend((): Schema.Codec<Tree> => Tree))
|
|
2721
|
+
* })
|
|
2722
|
+
* ```
|
|
2723
|
+
*
|
|
1721
2724
|
* @category Constructors
|
|
1722
2725
|
* @since 4.0.0
|
|
1723
2726
|
*/
|
|
1724
2727
|
export declare function suspend<S extends Top>(f: () => S): suspend<S>;
|
|
1725
2728
|
/**
|
|
2729
|
+
* Pipeable function that attaches one or more filter checks to a schema without
|
|
2730
|
+
* changing the TypeScript type.
|
|
2731
|
+
*
|
|
2732
|
+
* **Example** (Adding checks to a schema)
|
|
2733
|
+
* ```ts
|
|
2734
|
+
* import { Schema } from "effect"
|
|
2735
|
+
*
|
|
2736
|
+
* const AgeSchema = Schema.Number.pipe(
|
|
2737
|
+
* Schema.check(Schema.isGreaterThanOrEqualTo(0), Schema.isLessThanOrEqualTo(120))
|
|
2738
|
+
* )
|
|
2739
|
+
* ```
|
|
2740
|
+
*
|
|
1726
2741
|
* @category Filtering
|
|
1727
2742
|
* @since 4.0.0
|
|
1728
2743
|
*/
|
|
1729
2744
|
export declare function check<S extends Top>(...checks: readonly [AST.Check<S["Type"]>, ...Array<AST.Check<S["Type"]>>]): (self: S) => S["~rebuild.out"];
|
|
1730
2745
|
/**
|
|
2746
|
+
* The output type of {@link refine}, narrowing the schema's `Type` to `T` via a
|
|
2747
|
+
* type guard.
|
|
2748
|
+
*
|
|
1731
2749
|
* @since 4.0.0
|
|
1732
2750
|
*/
|
|
1733
2751
|
export interface refine<T extends S["Type"], S extends Top> extends Bottom<T, S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], refine<T, S>, S["~type.make.in"], T, S["~type.parameters"], T, S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -1735,12 +2753,18 @@ export interface refine<T extends S["Type"], S extends Top> extends Bottom<T, S[
|
|
|
1735
2753
|
readonly schema: S;
|
|
1736
2754
|
}
|
|
1737
2755
|
/**
|
|
2756
|
+
* Narrows the TypeScript type of a schema's output via a type guard predicate,
|
|
2757
|
+
* attaching the guard as a runtime filter check.
|
|
2758
|
+
*
|
|
1738
2759
|
* @category Filtering
|
|
1739
2760
|
* @since 4.0.0
|
|
1740
2761
|
*/
|
|
1741
2762
|
export declare function refine<S extends Top, T extends S["Type"]>(refinement: (value: S["Type"]) => value is T, annotations?: Annotations.Filter): (schema: S) => refine<T, S>;
|
|
1742
2763
|
type DistributeBrands<B> = UnionToIntersection<B extends infer U extends string ? Brand.Brand<U> : never>;
|
|
1743
2764
|
/**
|
|
2765
|
+
* The output type of {@link brand}, intersecting the schema's `Type` with one or
|
|
2766
|
+
* more {@link Brand.Brand} tags.
|
|
2767
|
+
*
|
|
1744
2768
|
* @since 4.0.0
|
|
1745
2769
|
*/
|
|
1746
2770
|
export interface brand<S extends Top, B> extends Bottom<S["Type"] & DistributeBrands<B>, S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], brand<S, B>, S["~type.make.in"], S["Type"] & DistributeBrands<B>, S["~type.parameters"], S["Type"] & DistributeBrands<B>, S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -1749,20 +2773,30 @@ export interface brand<S extends Top, B> extends Bottom<S["Type"] & DistributeBr
|
|
|
1749
2773
|
readonly identifier: string;
|
|
1750
2774
|
}
|
|
1751
2775
|
/**
|
|
1752
|
-
* Adds a brand to a schema
|
|
2776
|
+
* Adds a nominal brand to a schema, intersecting the output type with
|
|
2777
|
+
* `Brand.Brand<B>` to prevent accidental mixing of structurally identical types.
|
|
1753
2778
|
*
|
|
1754
2779
|
* @category Branding
|
|
1755
2780
|
* @since 4.0.0
|
|
1756
2781
|
*/
|
|
1757
2782
|
export declare function brand<B extends string>(identifier: B): <S extends Top>(schema: S) => brand<S["~rebuild.out"], B>;
|
|
1758
2783
|
/**
|
|
1759
|
-
* @
|
|
2784
|
+
* Creates a branded schema from a {@link Brand.Constructor}, applying the
|
|
2785
|
+
* constructor's checks and brand tag to the underlying schema.
|
|
2786
|
+
*
|
|
2787
|
+
* @category Branding
|
|
1760
2788
|
* @since 4.0.0
|
|
1761
2789
|
*/
|
|
1762
2790
|
export declare function fromBrand<A extends Brand.Brand<any>>(identifier: string, ctor: Brand.Constructor<A>): <S extends Top & {
|
|
1763
2791
|
readonly "Type": Brand.Brand.Unbranded<A>;
|
|
1764
2792
|
}>(self: S) => brand<S["~rebuild.out"], Brand.Brand.Keys<A>>;
|
|
1765
2793
|
/**
|
|
2794
|
+
* A schema that wraps another schema and intercepts its decoding pipeline.
|
|
2795
|
+
*
|
|
2796
|
+
* The interceptor receives the full decoding `Effect` and may replace, modify,
|
|
2797
|
+
* or augment it — including adding service requirements via `RD`.
|
|
2798
|
+
*
|
|
2799
|
+
* @see {@link middlewareDecoding} for the constructor
|
|
1766
2800
|
* @since 4.0.0
|
|
1767
2801
|
*/
|
|
1768
2802
|
export interface middlewareDecoding<S extends Top, RD> extends Bottom<S["Type"], S["Encoded"], RD, S["EncodingServices"], S["ast"], middlewareDecoding<S, RD>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -1770,10 +2804,35 @@ export interface middlewareDecoding<S extends Top, RD> extends Bottom<S["Type"],
|
|
|
1770
2804
|
readonly schema: S;
|
|
1771
2805
|
}
|
|
1772
2806
|
/**
|
|
2807
|
+
* Intercepts the decoding pipeline of a schema.
|
|
2808
|
+
*
|
|
2809
|
+
* The provided function receives the current decoding `Effect` and `ParseOptions`,
|
|
2810
|
+
* and returns a new `Effect` — potentially adding service requirements (`RD`),
|
|
2811
|
+
* recovering from errors, or augmenting the result.
|
|
2812
|
+
*
|
|
2813
|
+
* **Example** (Logging decode failures)
|
|
2814
|
+
*
|
|
2815
|
+
* ```ts
|
|
2816
|
+
* import { Effect, Schema } from "effect"
|
|
2817
|
+
*
|
|
2818
|
+
* const Logged = Schema.String.pipe(
|
|
2819
|
+
* Schema.middlewareDecoding((effect) =>
|
|
2820
|
+
* Effect.tapError(effect, (issue) => Effect.log("decode failed", issue))
|
|
2821
|
+
* )
|
|
2822
|
+
* )
|
|
2823
|
+
* ```
|
|
2824
|
+
*
|
|
2825
|
+
* @see {@link catchDecoding} for a simpler error-recovery variant
|
|
1773
2826
|
* @since 4.0.0
|
|
1774
2827
|
*/
|
|
1775
2828
|
export declare function middlewareDecoding<S extends Top, RD>(decode: (effect: Effect.Effect<Option_.Option<S["Type"]>, Issue.Issue, S["DecodingServices"]>, options: AST.ParseOptions) => Effect.Effect<Option_.Option<S["Type"]>, Issue.Issue, RD>): (schema: S) => middlewareDecoding<S, RD>;
|
|
1776
2829
|
/**
|
|
2830
|
+
* A schema that wraps another schema and intercepts its encoding pipeline.
|
|
2831
|
+
*
|
|
2832
|
+
* The interceptor receives the full encoding `Effect` and may replace, modify,
|
|
2833
|
+
* or augment it — including adding service requirements via `RE`.
|
|
2834
|
+
*
|
|
2835
|
+
* @see {@link middlewareEncoding} for the constructor
|
|
1777
2836
|
* @since 4.0.0
|
|
1778
2837
|
*/
|
|
1779
2838
|
export interface middlewareEncoding<S extends Top, RE> extends Bottom<S["Type"], S["Encoded"], S["DecodingServices"], RE, S["ast"], middlewareEncoding<S, RE>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -1781,26 +2840,77 @@ export interface middlewareEncoding<S extends Top, RE> extends Bottom<S["Type"],
|
|
|
1781
2840
|
readonly schema: S;
|
|
1782
2841
|
}
|
|
1783
2842
|
/**
|
|
2843
|
+
* Intercepts the encoding pipeline of a schema.
|
|
2844
|
+
*
|
|
2845
|
+
* The provided function receives the current encoding `Effect` and `ParseOptions`,
|
|
2846
|
+
* and returns a new `Effect` — potentially adding service requirements (`RE`),
|
|
2847
|
+
* recovering from errors, or augmenting the result.
|
|
2848
|
+
*
|
|
2849
|
+
* **Example** (Logging encode failures)
|
|
2850
|
+
*
|
|
2851
|
+
* ```ts
|
|
2852
|
+
* import { Effect, Schema } from "effect"
|
|
2853
|
+
*
|
|
2854
|
+
* const Logged = Schema.String.pipe(
|
|
2855
|
+
* Schema.middlewareEncoding((effect) =>
|
|
2856
|
+
* Effect.tapError(effect, (issue) => Effect.log("encode failed", issue))
|
|
2857
|
+
* )
|
|
2858
|
+
* )
|
|
2859
|
+
* ```
|
|
2860
|
+
*
|
|
2861
|
+
* @see {@link catchEncoding} for a simpler error-recovery variant
|
|
1784
2862
|
* @since 4.0.0
|
|
1785
2863
|
*/
|
|
1786
2864
|
export declare function middlewareEncoding<S extends Top, RE>(encode: (effect: Effect.Effect<Option_.Option<S["Encoded"]>, Issue.Issue, S["EncodingServices"]>, options: AST.ParseOptions) => Effect.Effect<Option_.Option<S["Encoded"]>, Issue.Issue, RE>): (schema: S) => middlewareEncoding<S, RE>;
|
|
1787
2865
|
/**
|
|
2866
|
+
* Recovers from a decoding error by providing a fallback value.
|
|
2867
|
+
*
|
|
2868
|
+
* The handler receives the `Issue` and returns an `Effect` that either
|
|
2869
|
+
* succeeds with a fallback value or re-fails with a (possibly different) issue.
|
|
2870
|
+
*
|
|
2871
|
+
* **Example** (Returning a default on decode failure)
|
|
2872
|
+
*
|
|
2873
|
+
* ```ts
|
|
2874
|
+
* import { Effect, Option, Schema } from "effect"
|
|
2875
|
+
*
|
|
2876
|
+
* const schema = Schema.Number.pipe(
|
|
2877
|
+
* Schema.catchDecoding((_issue) => Effect.succeed(Option.some(0)))
|
|
2878
|
+
* )
|
|
2879
|
+
* ```
|
|
2880
|
+
*
|
|
2881
|
+
* @see {@link catchDecodingWithContext} to add service requirements to the handler
|
|
1788
2882
|
* @since 4.0.0
|
|
1789
2883
|
*/
|
|
1790
2884
|
export declare function catchDecoding<S extends Top>(f: (issue: Issue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, Issue.Issue>): (self: S) => S["~rebuild.out"];
|
|
1791
2885
|
/**
|
|
2886
|
+
* Like {@link catchDecoding}, but the handler may require Effect services (`R`).
|
|
2887
|
+
*
|
|
1792
2888
|
* @since 4.0.0
|
|
1793
2889
|
*/
|
|
1794
2890
|
export declare function catchDecodingWithContext<S extends Top, R = never>(f: (issue: Issue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, Issue.Issue, R>): (self: S) => middlewareDecoding<S, S["DecodingServices"] | R>;
|
|
1795
2891
|
/**
|
|
2892
|
+
* Recovers from an encoding error by providing a fallback value.
|
|
2893
|
+
*
|
|
2894
|
+
* The handler receives the `Issue` and returns an `Effect` that either
|
|
2895
|
+
* succeeds with a fallback value or re-fails with a (possibly different) issue.
|
|
2896
|
+
*
|
|
2897
|
+
* @see {@link catchEncodingWithContext} to add service requirements to the handler
|
|
1796
2898
|
* @since 4.0.0
|
|
1797
2899
|
*/
|
|
1798
2900
|
export declare function catchEncoding<S extends Top>(f: (issue: Issue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, Issue.Issue>): (self: S) => S["~rebuild.out"];
|
|
1799
2901
|
/**
|
|
2902
|
+
* Like {@link catchEncoding}, but the handler may require Effect services (`R`).
|
|
2903
|
+
*
|
|
1800
2904
|
* @since 4.0.0
|
|
1801
2905
|
*/
|
|
1802
2906
|
export declare function catchEncodingWithContext<S extends Top, R = never>(f: (issue: Issue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, Issue.Issue, R>): (self: S) => middlewareEncoding<S, S["EncodingServices"] | R>;
|
|
1803
2907
|
/**
|
|
2908
|
+
* The type produced by {@link decodeTo} when a custom transformation is provided.
|
|
2909
|
+
*
|
|
2910
|
+
* - `Type` is `To["Type"]`, `Encoded` is `From["Encoded"]`
|
|
2911
|
+
* - Decoding services from both `from` and `to` are combined
|
|
2912
|
+
*
|
|
2913
|
+
* @see {@link compose} for the passthrough (no transformation) variant
|
|
1804
2914
|
* @since 4.0.0
|
|
1805
2915
|
*/
|
|
1806
2916
|
export interface decodeTo<To extends Top, From extends Top, RD = never, RE = never> extends Bottom<To["Type"], From["Encoded"], To["DecodingServices"] | From["DecodingServices"] | RD, To["EncodingServices"] | From["EncodingServices"] | RE, To["ast"], decodeTo<To, From, RD, RE>, To["~type.make.in"], To["Iso"], To["~type.parameters"], To["~type.make"], To["~type.mutability"], To["~type.optionality"], To["~type.constructor.default"], From["~encoded.mutability"], From["~encoded.optionality"]> {
|
|
@@ -1809,6 +2919,12 @@ export interface decodeTo<To extends Top, From extends Top, RD = never, RE = nev
|
|
|
1809
2919
|
readonly to: To;
|
|
1810
2920
|
}
|
|
1811
2921
|
/**
|
|
2922
|
+
* The type produced by {@link decodeTo} when called without a custom transformation (passthrough composition).
|
|
2923
|
+
*
|
|
2924
|
+
* Equivalent to {@link decodeTo} with `RD = never` and `RE = never`, meaning the schemas
|
|
2925
|
+
* are composed using their natural encoding/decoding chain.
|
|
2926
|
+
*
|
|
2927
|
+
* @see {@link decodeTo} for the transformation variant
|
|
1812
2928
|
* @since 4.0.0
|
|
1813
2929
|
*/
|
|
1814
2930
|
export interface compose<To extends Top, From extends Top> extends decodeTo<To, From> {
|
|
@@ -1902,6 +3018,25 @@ export declare function decode<S extends Top, RD = never, RE = never>(transforma
|
|
|
1902
3018
|
readonly encode: Getter.Getter<S["Type"], S["Type"], RE>;
|
|
1903
3019
|
}): (self: S) => decodeTo<toType<S>, S, RD, RE>;
|
|
1904
3020
|
/**
|
|
3021
|
+
* Like {@link decodeTo} but reverses the direction: the `from` schema acts as the target (decoded type)
|
|
3022
|
+
* and `to` acts as the encoded source.
|
|
3023
|
+
*
|
|
3024
|
+
* `encodeTo(to)(from)` is equivalent to `to.pipe(decodeTo(from))` — useful when it reads more
|
|
3025
|
+
* naturally to specify the encoded schema first.
|
|
3026
|
+
*
|
|
3027
|
+
* **Example** (Encode a number back to string)
|
|
3028
|
+
*
|
|
3029
|
+
* ```ts
|
|
3030
|
+
* import { Schema, SchemaGetter } from "effect"
|
|
3031
|
+
*
|
|
3032
|
+
* const NumberFromString = Schema.Number.pipe(
|
|
3033
|
+
* Schema.encodeTo(Schema.String, {
|
|
3034
|
+
* decode: SchemaGetter.transform((s: string) => Number(s)),
|
|
3035
|
+
* encode: SchemaGetter.transform((n: number) => String(n))
|
|
3036
|
+
* })
|
|
3037
|
+
* )
|
|
3038
|
+
* ```
|
|
3039
|
+
*
|
|
1905
3040
|
* @since 4.0.0
|
|
1906
3041
|
*/
|
|
1907
3042
|
export declare function encodeTo<To extends Top>(to: To): <From extends Top>(from: From) => decodeTo<From, To>;
|
|
@@ -1910,6 +3045,25 @@ export declare function encodeTo<To extends Top, From extends Top, RD = never, R
|
|
|
1910
3045
|
readonly encode: Getter.Getter<NoInfer<To["Type"]>, NoInfer<From["Encoded"]>, RE>;
|
|
1911
3046
|
}): (from: From) => decodeTo<From, To, RD, RE>;
|
|
1912
3047
|
/**
|
|
3048
|
+
* Applies a transformation to a schema's encoded type, creating a new schema where encoding/decoding
|
|
3049
|
+
* operate on `S["Encoded"]` rather than `S["Type"]`.
|
|
3050
|
+
*
|
|
3051
|
+
* The `decode` getter maps `S["Encoded"]` → `S["Encoded"]` (applied during decoding),
|
|
3052
|
+
* and the `encode` getter maps `S["Encoded"]` → `S["Encoded"]` (applied during encoding).
|
|
3053
|
+
*
|
|
3054
|
+
* **Example** (Upper-casing encoded strings)
|
|
3055
|
+
*
|
|
3056
|
+
* ```ts
|
|
3057
|
+
* import { Schema, SchemaGetter } from "effect"
|
|
3058
|
+
*
|
|
3059
|
+
* const UpperFromLower = Schema.String.pipe(
|
|
3060
|
+
* Schema.encode({
|
|
3061
|
+
* decode: SchemaGetter.transform((s: string) => s.toLowerCase()),
|
|
3062
|
+
* encode: SchemaGetter.transform((s: string) => s.toUpperCase())
|
|
3063
|
+
* })
|
|
3064
|
+
* )
|
|
3065
|
+
* ```
|
|
3066
|
+
*
|
|
1913
3067
|
* @since 4.0.0
|
|
1914
3068
|
*/
|
|
1915
3069
|
export declare function encode<S extends Top, RD = never, RE = never>(transformation: {
|
|
@@ -1917,12 +3071,19 @@ export declare function encode<S extends Top, RD = never, RE = never>(transforma
|
|
|
1917
3071
|
readonly encode: Getter.Getter<S["Encoded"], S["Encoded"], RE>;
|
|
1918
3072
|
}): (self: S) => decodeTo<S, toEncoded<S>, RD, RE>;
|
|
1919
3073
|
/**
|
|
3074
|
+
* Constraint used to ensure a schema field does not already have a constructor default.
|
|
3075
|
+
*
|
|
3076
|
+
* Only schemas that satisfy this constraint can be passed to {@link withConstructorDefault}.
|
|
3077
|
+
*
|
|
1920
3078
|
* @since 4.0.0
|
|
1921
3079
|
*/
|
|
1922
3080
|
export interface WithoutConstructorDefault {
|
|
1923
3081
|
readonly "~type.constructor.default": "no-default";
|
|
1924
3082
|
}
|
|
1925
3083
|
/**
|
|
3084
|
+
* The type produced by {@link withConstructorDefault} — a schema with `"~type.constructor.default": "with-default"`.
|
|
3085
|
+
*
|
|
3086
|
+
* @see {@link withConstructorDefault} for the constructor
|
|
1926
3087
|
* @since 4.0.0
|
|
1927
3088
|
*/
|
|
1928
3089
|
export interface withConstructorDefault<S extends Top & WithoutConstructorDefault> extends Bottom<S["Type"], S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], withConstructorDefault<S>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], "with-default", S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -1930,15 +3091,50 @@ export interface withConstructorDefault<S extends Top & WithoutConstructorDefaul
|
|
|
1930
3091
|
readonly schema: S;
|
|
1931
3092
|
}
|
|
1932
3093
|
/**
|
|
3094
|
+
* Attaches a constructor default value to a schema field.
|
|
3095
|
+
*
|
|
3096
|
+
* The `defaultValue` function receives `Option.some(undefined)` when the field is
|
|
3097
|
+
* explicitly set to `undefined`, or `Option.none()` when the field is absent.
|
|
3098
|
+
* Return `Option.some(value)` to supply a default, or `Option.none()` to leave the
|
|
3099
|
+
* field required. An `Effect` may be returned for async or service-dependent defaults.
|
|
3100
|
+
*
|
|
3101
|
+
* Constructor defaults are applied only during `makeUnsafe` / `make`, not during
|
|
3102
|
+
* decoding or encoding.
|
|
3103
|
+
*
|
|
3104
|
+
* **Example** (Optional field with a static default)
|
|
3105
|
+
*
|
|
3106
|
+
* ```ts
|
|
3107
|
+
* import { Option, Schema } from "effect"
|
|
3108
|
+
*
|
|
3109
|
+
* const MySchema = Schema.Struct({
|
|
3110
|
+
* name: Schema.String.pipe(
|
|
3111
|
+
* Schema.optionalKey,
|
|
3112
|
+
* Schema.withConstructorDefault(() => Option.some("anonymous"))
|
|
3113
|
+
* )
|
|
3114
|
+
* })
|
|
3115
|
+
*
|
|
3116
|
+
* const value = MySchema.makeUnsafe({})
|
|
3117
|
+
* // value: { name: "anonymous" }
|
|
3118
|
+
* ```
|
|
3119
|
+
*
|
|
1933
3120
|
* @since 4.0.0
|
|
1934
3121
|
*/
|
|
1935
3122
|
export declare function withConstructorDefault<S extends Top & WithoutConstructorDefault>(defaultValue: (input: Option_.Option<undefined>) => Option_.Option<S["~type.make.in"]> | Effect.Effect<Option_.Option<S["~type.make.in"]>>): (schema: S) => withConstructorDefault<S>;
|
|
1936
3123
|
/**
|
|
3124
|
+
* The type produced by {@link withDecodingDefaultKey} — a schema that decodes from an `optionalKey` encoded source.
|
|
3125
|
+
*
|
|
3126
|
+
* @see {@link withDecodingDefaultKey} for the constructor
|
|
1937
3127
|
* @since 4.0.0
|
|
1938
3128
|
*/
|
|
1939
3129
|
export interface withDecodingDefaultKey<S extends Top> extends decodeTo<S, optionalKey<toEncoded<S>>> {
|
|
1940
3130
|
}
|
|
1941
3131
|
/**
|
|
3132
|
+
* Options for {@link withDecodingDefaultKey} and {@link withDecodingDefault}.
|
|
3133
|
+
*
|
|
3134
|
+
* - `encodingStrategy`:
|
|
3135
|
+
* - `"passthrough"` (default): pass the value through during encoding
|
|
3136
|
+
* - `"omit"`: omit the key from the encoded output
|
|
3137
|
+
*
|
|
1942
3138
|
* @since 4.0.0
|
|
1943
3139
|
*/
|
|
1944
3140
|
export type DecodingDefaultOptions = {
|
|
@@ -1951,10 +3147,34 @@ export type DecodingDefaultOptions = {
|
|
|
1951
3147
|
* - `passthrough`: (default) Pass the default value through to the output.
|
|
1952
3148
|
* - `omit`: Omit the value from the output.
|
|
1953
3149
|
*
|
|
3150
|
+
* Provides a default value for a missing key during decoding.
|
|
3151
|
+
*
|
|
3152
|
+
* When the key is absent from the input, `defaultValue()` is called to supply a value.
|
|
3153
|
+
* During encoding, the behavior is controlled by `options.encodingStrategy`:
|
|
3154
|
+
* - `"passthrough"` (default): include the value in the output
|
|
3155
|
+
* - `"omit"`: omit the key from the output
|
|
3156
|
+
*
|
|
3157
|
+
* **Example** (Default for a missing struct key)
|
|
3158
|
+
*
|
|
3159
|
+
* ```ts
|
|
3160
|
+
* import { Schema } from "effect"
|
|
3161
|
+
*
|
|
3162
|
+
* const MySchema = Schema.Struct({
|
|
3163
|
+
* name: Schema.String.pipe(Schema.withDecodingDefaultKey(() => "anonymous"))
|
|
3164
|
+
* })
|
|
3165
|
+
*
|
|
3166
|
+
* const result = Schema.decodeUnknownSync(MySchema)({})
|
|
3167
|
+
* // result: { name: "anonymous" }
|
|
3168
|
+
* ```
|
|
3169
|
+
*
|
|
3170
|
+
* @see {@link withDecodingDefault} for the `optional` (value-level) variant
|
|
1954
3171
|
* @since 4.0.0
|
|
1955
3172
|
*/
|
|
1956
3173
|
export declare function withDecodingDefaultKey<S extends Top>(defaultValue: () => S["Encoded"], options?: DecodingDefaultOptions): (self: S) => withDecodingDefaultKey<S>;
|
|
1957
3174
|
/**
|
|
3175
|
+
* The type produced by {@link withDecodingDefault} — a schema that decodes from an `optional` encoded source.
|
|
3176
|
+
*
|
|
3177
|
+
* @see {@link withDecodingDefault} for the constructor
|
|
1958
3178
|
* @since 4.0.0
|
|
1959
3179
|
*/
|
|
1960
3180
|
export interface withDecodingDefault<S extends Top> extends decodeTo<S, optional<toEncoded<S>>> {
|
|
@@ -1966,34 +3186,93 @@ export interface withDecodingDefault<S extends Top> extends decodeTo<S, optional
|
|
|
1966
3186
|
* - `passthrough`: (default) Pass the default value through to the output.
|
|
1967
3187
|
* - `omit`: Omit the value from the output.
|
|
1968
3188
|
*
|
|
3189
|
+
* Provides a default value for an `optional` field during decoding.
|
|
3190
|
+
*
|
|
3191
|
+
* Similar to {@link withDecodingDefaultKey} but works on `optional` (value-level optional)
|
|
3192
|
+
* rather than `optionalKey` (key-level optional).
|
|
3193
|
+
*
|
|
3194
|
+
* When the value is `undefined` or absent, `defaultValue()` is called to supply a value.
|
|
3195
|
+
* During encoding, the behavior is controlled by `options.encodingStrategy`:
|
|
3196
|
+
* - `"passthrough"` (default): include the value in the output
|
|
3197
|
+
* - `"omit"`: omit the value from the output
|
|
3198
|
+
*
|
|
3199
|
+
* **Example** (Default for an optional field value)
|
|
3200
|
+
*
|
|
3201
|
+
* ```ts
|
|
3202
|
+
* import { Schema } from "effect"
|
|
3203
|
+
*
|
|
3204
|
+
* const MySchema = Schema.Struct({
|
|
3205
|
+
* name: Schema.String.pipe(Schema.optional, Schema.withDecodingDefault(() => "anonymous"))
|
|
3206
|
+
* })
|
|
3207
|
+
*
|
|
3208
|
+
* const result = Schema.decodeUnknownSync(MySchema)({ name: undefined })
|
|
3209
|
+
* // result: { name: "anonymous" }
|
|
3210
|
+
* ```
|
|
3211
|
+
*
|
|
3212
|
+
* @see {@link withDecodingDefaultKey} for the key-level variant
|
|
1969
3213
|
* @since 4.0.0
|
|
1970
3214
|
*/
|
|
1971
3215
|
export declare function withDecodingDefault<S extends Top>(defaultValue: () => S["Encoded"], options?: DecodingDefaultOptions): (self: S) => withDecodingDefault<S>;
|
|
1972
3216
|
/**
|
|
3217
|
+
* The type produced by {@link tag} — a literal schema with a constructor default.
|
|
3218
|
+
*
|
|
3219
|
+
* Used as the type of the `_tag` field in {@link TaggedStruct} and related helpers.
|
|
3220
|
+
*
|
|
3221
|
+
* @see {@link tag} for the constructor
|
|
1973
3222
|
* @since 4.0.0
|
|
1974
3223
|
*/
|
|
1975
3224
|
export interface tag<Tag extends AST.LiteralValue> extends withConstructorDefault<Literal<Tag>> {
|
|
1976
3225
|
}
|
|
1977
3226
|
/**
|
|
1978
|
-
*
|
|
1979
|
-
*
|
|
3227
|
+
* Combines a {@link Literal} schema with {@link withConstructorDefault}, making it ideal
|
|
3228
|
+
* for discriminator fields in tagged unions. When constructing via `makeUnsafe`, the
|
|
3229
|
+
* `_tag` field can be omitted and will be filled automatically.
|
|
1980
3230
|
*
|
|
1981
|
-
*
|
|
1982
|
-
* making it perfect for discriminated unions and tagged data structures. The
|
|
1983
|
-
* tag value is automatically provided when the field is missing during
|
|
1984
|
-
* construction.
|
|
3231
|
+
* **Example** (Discriminated union tag)
|
|
1985
3232
|
*
|
|
3233
|
+
* ```ts
|
|
3234
|
+
* import { Schema } from "effect"
|
|
3235
|
+
*
|
|
3236
|
+
* const A = Schema.Struct({ _tag: Schema.tag("A"), value: Schema.Number })
|
|
3237
|
+
*
|
|
3238
|
+
* // _tag is optional in makeUnsafe, auto-filled to "A"
|
|
3239
|
+
* const a = A.makeUnsafe({ value: 42 })
|
|
3240
|
+
* // a: { _tag: "A", value: 42 }
|
|
3241
|
+
* ```
|
|
3242
|
+
*
|
|
3243
|
+
* @see {@link tagDefaultOmit} to also omit the tag during encoding
|
|
3244
|
+
* @see {@link TaggedStruct} for a shorthand that adds `_tag` automatically
|
|
1986
3245
|
* @since 4.0.0
|
|
1987
3246
|
*/
|
|
1988
3247
|
export declare function tag<Tag extends AST.LiteralValue>(literal: Tag): tag<Tag>;
|
|
1989
3248
|
/**
|
|
1990
|
-
*
|
|
1991
|
-
* the
|
|
3249
|
+
* Like {@link tag}, but additionally omits the tag field from the encoded output.
|
|
3250
|
+
* Useful when the encoded form (e.g. JSON) does not include the discriminator key,
|
|
3251
|
+
* but the decoded type and constructor still need it.
|
|
3252
|
+
*
|
|
3253
|
+
* **Example** (Tag omitted during encoding)
|
|
3254
|
+
*
|
|
3255
|
+
* ```ts
|
|
3256
|
+
* import { Schema } from "effect"
|
|
3257
|
+
*
|
|
3258
|
+
* const A = Schema.Struct({
|
|
3259
|
+
* _tag: Schema.tagDefaultOmit("A"),
|
|
3260
|
+
* value: Schema.Number
|
|
3261
|
+
* })
|
|
1992
3262
|
*
|
|
3263
|
+
* // Encode strips the _tag field
|
|
3264
|
+
* const encoded = Schema.encodeUnknownSync(A)({ _tag: "A", value: 1 })
|
|
3265
|
+
* // encoded: { value: 1 }
|
|
3266
|
+
* ```
|
|
3267
|
+
*
|
|
3268
|
+
* @see {@link tag} for the variant that keeps the tag during encoding
|
|
1993
3269
|
* @since 4.0.0
|
|
1994
3270
|
*/
|
|
1995
3271
|
export declare function tagDefaultOmit<Tag extends AST.LiteralValue>(literal: Tag): withDecodingDefaultKey<tag<Tag>>;
|
|
1996
3272
|
/**
|
|
3273
|
+
* The type produced by {@link TaggedStruct} — a {@link Struct} with an extra `_tag` field of type {@link tag}.
|
|
3274
|
+
*
|
|
3275
|
+
* @see {@link TaggedStruct} for the constructor
|
|
1997
3276
|
* @since 4.0.0
|
|
1998
3277
|
*/
|
|
1999
3278
|
export type TaggedStruct<Tag extends AST.LiteralValue, Fields extends Struct.Fields> = Struct<Simplify<{
|
|
@@ -2074,6 +3353,9 @@ type TaggedUnionUtils<Tag extends PropertyKey, Members extends ReadonlyArray<Top
|
|
|
2074
3353
|
};
|
|
2075
3354
|
};
|
|
2076
3355
|
/**
|
|
3356
|
+
* The type produced by {@link toTaggedUnion} — a {@link Union} augmented with `cases`, `guards`, `isAnyOf`, and `match` utilities.
|
|
3357
|
+
*
|
|
3358
|
+
* @see {@link toTaggedUnion} for the constructor
|
|
2077
3359
|
* @since 4.0.0
|
|
2078
3360
|
* @experimental
|
|
2079
3361
|
*/
|
|
@@ -2083,6 +3365,26 @@ export type toTaggedUnion<Tag extends PropertyKey, Members extends ReadonlyArray
|
|
|
2083
3365
|
};
|
|
2084
3366
|
}>> = Union<Members> & TaggedUnionUtils<Tag, Members>;
|
|
2085
3367
|
/**
|
|
3368
|
+
* Augments an existing {@link Union} of tagged structs with utility methods keyed by the discriminant field.
|
|
3369
|
+
*
|
|
3370
|
+
* **Example** (Adding tagged-union utilities to an existing union)
|
|
3371
|
+
*
|
|
3372
|
+
* ```ts
|
|
3373
|
+
* import { Schema } from "effect"
|
|
3374
|
+
*
|
|
3375
|
+
* const A = Schema.TaggedStruct("A", { value: Schema.Number })
|
|
3376
|
+
* const B = Schema.TaggedStruct("B", { name: Schema.String })
|
|
3377
|
+
*
|
|
3378
|
+
* const MyUnion = Schema.Union([A, B]).pipe(Schema.toTaggedUnion("_tag"))
|
|
3379
|
+
*
|
|
3380
|
+
* // Pattern-match on the union
|
|
3381
|
+
* const result = MyUnion.match({ _tag: "A", value: 1 }, {
|
|
3382
|
+
* A: (a) => `number: ${a.value}`,
|
|
3383
|
+
* B: (b) => `name: ${b.name}`
|
|
3384
|
+
* })
|
|
3385
|
+
* ```
|
|
3386
|
+
*
|
|
3387
|
+
* @see {@link TaggedUnion} for a shorthand that builds the union from scratch
|
|
2086
3388
|
* @since 4.0.0
|
|
2087
3389
|
* @experimental
|
|
2088
3390
|
*/
|
|
@@ -2090,6 +3392,10 @@ export declare function toTaggedUnion<const Tag extends PropertyKey>(tag: Tag):
|
|
|
2090
3392
|
readonly Type: { readonly [K in Tag]: PropertyKey; };
|
|
2091
3393
|
}>>(self: Union<Members>) => toTaggedUnion<Tag, Members>;
|
|
2092
3394
|
/**
|
|
3395
|
+
* A union schema that exposes `cases`, `guards`, `isAnyOf`, and `match` utilities keyed by the `_tag` discriminant.
|
|
3396
|
+
* Produced by {@link TaggedUnion}.
|
|
3397
|
+
*
|
|
3398
|
+
* @see {@link TaggedUnion} for the constructor
|
|
2093
3399
|
* @since 4.0.0
|
|
2094
3400
|
* @experimental
|
|
2095
3401
|
*/
|
|
@@ -2122,6 +3428,28 @@ export interface TaggedUnion<Cases extends Record<string, Top>> extends Bottom<{
|
|
|
2122
3428
|
};
|
|
2123
3429
|
}
|
|
2124
3430
|
/**
|
|
3431
|
+
* Builds a discriminated union from a record of field sets, one per variant.
|
|
3432
|
+
* Each key becomes the `_tag` literal and the value is passed to {@link TaggedStruct}.
|
|
3433
|
+
* The result includes `cases`, `guards`, `isAnyOf`, and `match` utilities.
|
|
3434
|
+
*
|
|
3435
|
+
* **Example** (Discriminated union with pattern matching)
|
|
3436
|
+
*
|
|
3437
|
+
* ```ts
|
|
3438
|
+
* import { Schema } from "effect"
|
|
3439
|
+
*
|
|
3440
|
+
* const Shape = Schema.TaggedUnion({
|
|
3441
|
+
* Circle: { radius: Schema.Number },
|
|
3442
|
+
* Rectangle: { width: Schema.Number, height: Schema.Number }
|
|
3443
|
+
* })
|
|
3444
|
+
*
|
|
3445
|
+
* // Pattern-match on a decoded value
|
|
3446
|
+
* const area = Shape.match({ _tag: "Circle", radius: 5 }, {
|
|
3447
|
+
* Circle: (c) => Math.PI * c.radius ** 2,
|
|
3448
|
+
* Rectangle: (r) => r.width * r.height
|
|
3449
|
+
* })
|
|
3450
|
+
* ```
|
|
3451
|
+
*
|
|
3452
|
+
* @see {@link toTaggedUnion} to augment an existing union instead
|
|
2125
3453
|
* @category Constructors
|
|
2126
3454
|
* @since 4.0.0
|
|
2127
3455
|
*/
|
|
@@ -2129,29 +3457,69 @@ export declare function TaggedUnion<const CasesByTag extends Record<string, Stru
|
|
|
2129
3457
|
readonly [K in keyof CasesByTag & string]: TaggedStruct<K, CasesByTag[K]>;
|
|
2130
3458
|
}>;
|
|
2131
3459
|
/**
|
|
3460
|
+
* The interface type for schemas created by {@link Opaque}.
|
|
3461
|
+
* Carries the same encoded/decoded shape as `S` but replaces `Type` with `Self & Brand`,
|
|
3462
|
+
* making the decoded value nominally distinct.
|
|
3463
|
+
*
|
|
3464
|
+
* @see {@link Opaque} for the constructor
|
|
2132
3465
|
* @since 4.0.0
|
|
2133
3466
|
*/
|
|
2134
3467
|
export interface Opaque<Self, S extends Top, Brand> extends Bottom<Self, S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], S["~rebuild.out"], S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
2135
3468
|
new (_: never): S["Type"] & Brand;
|
|
2136
3469
|
}
|
|
2137
3470
|
/**
|
|
3471
|
+
* Wraps a schema so that its decoded `Type` becomes a nominally distinct type `Self`.
|
|
3472
|
+
* Useful for creating opaque types that are structurally identical to a base schema
|
|
3473
|
+
* but type-incompatible with it.
|
|
3474
|
+
*
|
|
3475
|
+
* **Example** (Opaque user ID)
|
|
3476
|
+
*
|
|
3477
|
+
* ```ts
|
|
3478
|
+
* import { Schema } from "effect"
|
|
3479
|
+
*
|
|
3480
|
+
* type UserId = string & { readonly _tag: "UserId" }
|
|
3481
|
+
* const UserId = Schema.Opaque<UserId>()(Schema.String)
|
|
3482
|
+
*
|
|
3483
|
+
* // Decoded value is UserId, not plain string
|
|
3484
|
+
* const id = Schema.decodeUnknownSync(UserId)("abc")
|
|
3485
|
+
* // id: UserId
|
|
3486
|
+
* ```
|
|
3487
|
+
*
|
|
2138
3488
|
* @since 4.0.0
|
|
2139
3489
|
*/
|
|
2140
3490
|
export declare function Opaque<Self, Brand = {}>(): <S extends Top>(schema: S) => Opaque<Self, S, Brand> & Omit<S, "Type">;
|
|
2141
3491
|
/**
|
|
3492
|
+
* The type produced by {@link instanceOf} — a declaration schema that validates class instances.
|
|
3493
|
+
*
|
|
3494
|
+
* @see {@link instanceOf} for the constructor
|
|
2142
3495
|
* @since 4.0.0
|
|
2143
3496
|
*/
|
|
2144
3497
|
export interface instanceOf<T, Iso = T> extends declare<T, Iso> {
|
|
2145
3498
|
readonly "~rebuild.out": this;
|
|
2146
3499
|
}
|
|
2147
3500
|
/**
|
|
2148
|
-
* Creates a schema that validates
|
|
3501
|
+
* Creates a schema that validates values using `instanceof`.
|
|
3502
|
+
* Decoding and encoding pass the value through unchanged.
|
|
3503
|
+
*
|
|
3504
|
+
* **Example** (Schema for a built-in class)
|
|
3505
|
+
*
|
|
3506
|
+
* ```ts
|
|
3507
|
+
* import { Schema } from "effect"
|
|
3508
|
+
*
|
|
3509
|
+
* const DateSchema = Schema.instanceOf(Date)
|
|
3510
|
+
*
|
|
3511
|
+
* const decoded = Schema.decodeUnknownSync(DateSchema)(new Date("2024-01-01"))
|
|
3512
|
+
* // decoded: Date
|
|
3513
|
+
* ```
|
|
2149
3514
|
*
|
|
2150
3515
|
* @category Constructors
|
|
2151
3516
|
* @since 4.0.0
|
|
2152
3517
|
*/
|
|
2153
3518
|
export declare function instanceOf<C extends abstract new (...args: any) => any, Iso = InstanceType<C>>(constructor: C, annotations?: Annotations.Declaration<InstanceType<C>> | undefined): instanceOf<InstanceType<C>, Iso>;
|
|
2154
3519
|
/**
|
|
3520
|
+
* Constructs an `AST.Link` that describes how a value of type `T` encodes to and decodes from a `To` schema.
|
|
3521
|
+
* Used when building low-level AST transformations that bridge two schema types.
|
|
3522
|
+
*
|
|
2155
3523
|
* @since 4.0.0
|
|
2156
3524
|
* @experimental
|
|
2157
3525
|
*/
|
|
@@ -2160,6 +3528,22 @@ export declare function link<T>(): <To extends Top>(encodeTo: To, transformation
|
|
|
2160
3528
|
readonly encode: Getter.Getter<NoInfer<To["Type"]>, T>;
|
|
2161
3529
|
}) => AST.Link;
|
|
2162
3530
|
/**
|
|
3531
|
+
* Creates a custom filter check from a predicate function. The predicate
|
|
3532
|
+
* receives the input value, the schema's AST, and parse options, and returns
|
|
3533
|
+
* `true`/`undefined` on success or a failure description on error.
|
|
3534
|
+
*
|
|
3535
|
+
* **Example** (Custom filter check)
|
|
3536
|
+
* ```ts
|
|
3537
|
+
* import { Schema } from "effect"
|
|
3538
|
+
*
|
|
3539
|
+
* // Check that a number is even
|
|
3540
|
+
* const isEven = Schema.makeFilter(
|
|
3541
|
+
* (n: number) => n % 2 === 0 || "expected an even number"
|
|
3542
|
+
* )
|
|
3543
|
+
*
|
|
3544
|
+
* const EvenNumber = Schema.Number.check(isEven)
|
|
3545
|
+
* ```
|
|
3546
|
+
*
|
|
2163
3547
|
* @category Checks Constructors
|
|
2164
3548
|
* @since 4.0.0
|
|
2165
3549
|
*/
|
|
@@ -2168,6 +3552,9 @@ export declare const makeFilter: <T>(filter: (input: T, ast: AST.AST, options: A
|
|
|
2168
3552
|
readonly message: string;
|
|
2169
3553
|
}, annotations?: Annotations.Filter | undefined, abort?: boolean) => AST.Filter<T>;
|
|
2170
3554
|
/**
|
|
3555
|
+
* Groups multiple checks into a single {@link AST.FilterGroup}, applying
|
|
3556
|
+
* optional shared annotations to the group as a whole.
|
|
3557
|
+
*
|
|
2171
3558
|
* @category Checks Constructors
|
|
2172
3559
|
* @since 4.0.0
|
|
2173
3560
|
*/
|
|
@@ -2465,6 +3852,9 @@ export declare function isUncapitalized(annotations?: Annotations.Filter): AST.F
|
|
|
2465
3852
|
*/
|
|
2466
3853
|
export declare function isFinite(annotations?: Annotations.Filter): AST.Filter<number>;
|
|
2467
3854
|
/**
|
|
3855
|
+
* Generic factory for creating a "greater than" (`>`) check for any ordered
|
|
3856
|
+
* type by supplying an {@link Order.Order} instance.
|
|
3857
|
+
*
|
|
2468
3858
|
* @category Order checks
|
|
2469
3859
|
* @since 4.0.0
|
|
2470
3860
|
*/
|
|
@@ -2474,6 +3864,9 @@ export declare function makeIsGreaterThan<T>(options: {
|
|
|
2474
3864
|
readonly formatter?: Formatter<T> | undefined;
|
|
2475
3865
|
}): (exclusiveMinimum: T, annotations?: Annotations.Filter) => AST.Filter<T>;
|
|
2476
3866
|
/**
|
|
3867
|
+
* Generic factory for creating a ">=" check for any ordered type by supplying
|
|
3868
|
+
* an {@link Order.Order} instance.
|
|
3869
|
+
*
|
|
2477
3870
|
* @category Order checks
|
|
2478
3871
|
* @since 4.0.0
|
|
2479
3872
|
*/
|
|
@@ -2483,6 +3876,9 @@ export declare function makeIsGreaterThanOrEqualTo<T>(options: {
|
|
|
2483
3876
|
readonly formatter?: Formatter<T> | undefined;
|
|
2484
3877
|
}): (minimum: T, annotations?: Annotations.Filter) => AST.Filter<T>;
|
|
2485
3878
|
/**
|
|
3879
|
+
* Generic factory for creating a "<" check for any ordered type by supplying
|
|
3880
|
+
* an {@link Order.Order} instance.
|
|
3881
|
+
*
|
|
2486
3882
|
* @category Order checks
|
|
2487
3883
|
* @since 4.0.0
|
|
2488
3884
|
*/
|
|
@@ -2492,6 +3888,9 @@ export declare function makeIsLessThan<T>(options: {
|
|
|
2492
3888
|
readonly formatter?: Formatter<T> | undefined;
|
|
2493
3889
|
}): (exclusiveMaximum: T, annotations?: Annotations.Filter) => AST.Filter<T>;
|
|
2494
3890
|
/**
|
|
3891
|
+
* Generic factory for creating a "<=" check for any ordered type by supplying
|
|
3892
|
+
* an {@link Order.Order} instance.
|
|
3893
|
+
*
|
|
2495
3894
|
* @category Order checks
|
|
2496
3895
|
* @since 4.0.0
|
|
2497
3896
|
*/
|
|
@@ -2501,6 +3900,9 @@ export declare function makeIsLessThanOrEqualTo<T>(options: {
|
|
|
2501
3900
|
readonly formatter?: Formatter<T> | undefined;
|
|
2502
3901
|
}): (maximum: T, annotations?: Annotations.Filter) => AST.Filter<T>;
|
|
2503
3902
|
/**
|
|
3903
|
+
* Generic factory for creating an inclusive/exclusive range check for any
|
|
3904
|
+
* ordered type by supplying an {@link Order.Order} instance.
|
|
3905
|
+
*
|
|
2504
3906
|
* @category Order checks
|
|
2505
3907
|
* @since 4.0.0
|
|
2506
3908
|
*/
|
|
@@ -2520,6 +3922,9 @@ export declare function makeIsBetween<T>(deriveOptions: {
|
|
|
2520
3922
|
readonly exclusiveMaximum?: boolean | undefined;
|
|
2521
3923
|
}, annotations?: Annotations.Filter) => AST.Filter<T>;
|
|
2522
3924
|
/**
|
|
3925
|
+
* Generic factory for creating a divisibility check for any numeric type by
|
|
3926
|
+
* supplying a remainder function and a zero value.
|
|
3927
|
+
*
|
|
2523
3928
|
* @category Numeric checks
|
|
2524
3929
|
* @since 4.0.0
|
|
2525
3930
|
*/
|
|
@@ -2925,6 +4330,14 @@ export declare const isBetweenBigDecimal: (options: {
|
|
|
2925
4330
|
* constraint to ensure generated strings or arrays have at least the required
|
|
2926
4331
|
* length.
|
|
2927
4332
|
*
|
|
4333
|
+
* **Example** (Minimum length check)
|
|
4334
|
+
* ```ts
|
|
4335
|
+
* import { Schema } from "effect"
|
|
4336
|
+
*
|
|
4337
|
+
* const NonEmptyStringSchema = Schema.String.check(Schema.isMinLength(1))
|
|
4338
|
+
* const NonEmptyArraySchema = Schema.Array(Schema.Number).check(Schema.isMinLength(1))
|
|
4339
|
+
* ```
|
|
4340
|
+
*
|
|
2928
4341
|
* @category Length checks
|
|
2929
4342
|
* @since 4.0.0
|
|
2930
4343
|
*/
|
|
@@ -3140,6 +4553,7 @@ export declare function isPropertyNames(keySchema: Top, annotations?: Annotation
|
|
|
3140
4553
|
* constraint using the provided equivalence function to ensure generated arrays
|
|
3141
4554
|
* contain only unique items.
|
|
3142
4555
|
*
|
|
4556
|
+
* @category Array checks
|
|
3143
4557
|
* @since 4.0.0
|
|
3144
4558
|
*/
|
|
3145
4559
|
export declare function isUnique<T>(annotations?: Annotations.Filter): AST.Filter<readonly T[]>;
|
|
@@ -3157,6 +4571,23 @@ export declare const NonEmptyString: String;
|
|
|
3157
4571
|
*/
|
|
3158
4572
|
export declare const Char: String;
|
|
3159
4573
|
/**
|
|
4574
|
+
* Schema for the `Option<A>` type, representing an optional value that is
|
|
4575
|
+
* either `None` or `Some<A>`.
|
|
4576
|
+
*
|
|
4577
|
+
* **Example** (Option schema)
|
|
4578
|
+
*
|
|
4579
|
+
* ```ts
|
|
4580
|
+
* import { Schema } from "effect"
|
|
4581
|
+
* import { Option } from "effect"
|
|
4582
|
+
*
|
|
4583
|
+
* const schema = Schema.Option(Schema.Number)
|
|
4584
|
+
*
|
|
4585
|
+
* Schema.decodeUnknownSync(schema)(Option.some(1))
|
|
4586
|
+
* // => Some(1)
|
|
4587
|
+
* Schema.decodeUnknownSync(schema)(Option.none())
|
|
4588
|
+
* // => None
|
|
4589
|
+
* ```
|
|
4590
|
+
*
|
|
3160
4591
|
* @category Option
|
|
3161
4592
|
* @since 4.0.0
|
|
3162
4593
|
*/
|
|
@@ -3174,11 +4605,16 @@ export type OptionIso<A extends Top> = {
|
|
|
3174
4605
|
readonly value: A["Iso"];
|
|
3175
4606
|
};
|
|
3176
4607
|
/**
|
|
4608
|
+
* Creates a schema for `Option<A>`. See {@link Option} for details.
|
|
4609
|
+
*
|
|
3177
4610
|
* @category Option
|
|
3178
4611
|
* @since 4.0.0
|
|
3179
4612
|
*/
|
|
3180
4613
|
export declare function Option<A extends Top>(value: A): Option<A>;
|
|
3181
4614
|
/**
|
|
4615
|
+
* Schema type for {@link OptionFromNullOr}.
|
|
4616
|
+
*
|
|
4617
|
+
* @category Option
|
|
3182
4618
|
* @since 4.0.0
|
|
3183
4619
|
*/
|
|
3184
4620
|
export interface OptionFromNullOr<S extends Top> extends decodeTo<Option<toType<S>>, NullOr<S>> {
|
|
@@ -3199,6 +4635,9 @@ export interface OptionFromNullOr<S extends Top> extends decodeTo<Option<toType<
|
|
|
3199
4635
|
*/
|
|
3200
4636
|
export declare function OptionFromNullOr<S extends Top>(schema: S): OptionFromNullOr<S>;
|
|
3201
4637
|
/**
|
|
4638
|
+
* Schema type for {@link OptionFromUndefinedOr}.
|
|
4639
|
+
*
|
|
4640
|
+
* @category Option
|
|
3202
4641
|
* @since 4.0.0
|
|
3203
4642
|
*/
|
|
3204
4643
|
export interface OptionFromUndefinedOr<S extends Top> extends decodeTo<Option<toType<S>>, UndefinedOr<S>> {
|
|
@@ -3219,6 +4658,9 @@ export interface OptionFromUndefinedOr<S extends Top> extends decodeTo<Option<to
|
|
|
3219
4658
|
*/
|
|
3220
4659
|
export declare function OptionFromUndefinedOr<S extends Top>(schema: S): OptionFromUndefinedOr<S>;
|
|
3221
4660
|
/**
|
|
4661
|
+
* Schema type for {@link OptionFromNullishOr}.
|
|
4662
|
+
*
|
|
4663
|
+
* @category Option
|
|
3222
4664
|
* @since 4.0.0
|
|
3223
4665
|
*/
|
|
3224
4666
|
export interface OptionFromNullishOr<S extends Top> extends decodeTo<Option<toType<S>>, NullishOr<S>> {
|
|
@@ -3241,6 +4683,9 @@ export declare function OptionFromNullishOr<S extends Top>(schema: S, options?:
|
|
|
3241
4683
|
onNoneEncoding: null | undefined;
|
|
3242
4684
|
}): OptionFromNullishOr<S>;
|
|
3243
4685
|
/**
|
|
4686
|
+
* Schema type for {@link OptionFromOptionalKey}.
|
|
4687
|
+
*
|
|
4688
|
+
* @category Option
|
|
3244
4689
|
* @since 4.0.0
|
|
3245
4690
|
*/
|
|
3246
4691
|
export interface OptionFromOptionalKey<S extends Top> extends decodeTo<Option<toType<S>>, optionalKey<S>> {
|
|
@@ -3261,6 +4706,9 @@ export interface OptionFromOptionalKey<S extends Top> extends decodeTo<Option<to
|
|
|
3261
4706
|
*/
|
|
3262
4707
|
export declare function OptionFromOptionalKey<S extends Top>(schema: S): OptionFromOptionalKey<S>;
|
|
3263
4708
|
/**
|
|
4709
|
+
* Schema type for {@link OptionFromOptional}.
|
|
4710
|
+
*
|
|
4711
|
+
* @category Option
|
|
3264
4712
|
* @since 4.0.0
|
|
3265
4713
|
*/
|
|
3266
4714
|
export interface OptionFromOptional<S extends Top> extends decodeTo<Option<toType<S>>, optional<S>> {
|
|
@@ -3283,6 +4731,39 @@ export interface OptionFromOptional<S extends Top> extends decodeTo<Option<toTyp
|
|
|
3283
4731
|
*/
|
|
3284
4732
|
export declare function OptionFromOptional<S extends Top>(schema: S): OptionFromOptional<S>;
|
|
3285
4733
|
/**
|
|
4734
|
+
* Schema type for {@link OptionFromOptionalNullOr}.
|
|
4735
|
+
*
|
|
4736
|
+
* @category Option
|
|
4737
|
+
* @since 4.0.0
|
|
4738
|
+
*/
|
|
4739
|
+
export interface OptionFromOptionalNullOr<S extends Top> extends decodeTo<Option<toType<S>>, optional<NullOr<S>>> {
|
|
4740
|
+
}
|
|
4741
|
+
/**
|
|
4742
|
+
* Decodes an optional or `null` or `undefined` value `A` to a required `Option<A>`
|
|
4743
|
+
* value.
|
|
4744
|
+
*
|
|
4745
|
+
* Decoding:
|
|
4746
|
+
* - a missing key is decoded as `None`
|
|
4747
|
+
* - a present key with an `undefined` value is decoded as `None`
|
|
4748
|
+
* - a present key with a `null` value is decoded as `None`
|
|
4749
|
+
* - all other values are decoded as `Some`
|
|
4750
|
+
*
|
|
4751
|
+
* Encoding (controlled by `options.onNoneEncoding`):
|
|
4752
|
+
* - `"omit"` (default): `None` is encoded as a missing key
|
|
4753
|
+
* - `null`: `None` is encoded as `null`
|
|
4754
|
+
* - `undefined`: `None` is encoded as `undefined`
|
|
4755
|
+
* - `Some` is always encoded as the value
|
|
4756
|
+
*
|
|
4757
|
+
* @category Option
|
|
4758
|
+
* @since 4.0.0
|
|
4759
|
+
*/
|
|
4760
|
+
export declare function OptionFromOptionalNullOr<S extends Top>(schema: S, options?: {
|
|
4761
|
+
readonly onNoneEncoding: "omit" | null | undefined;
|
|
4762
|
+
}): OptionFromOptionalNullOr<S>;
|
|
4763
|
+
/**
|
|
4764
|
+
* Schema for the `Result<A, E>` type, representing a computation that either
|
|
4765
|
+
* succeeds with `A` or fails with `E`.
|
|
4766
|
+
*
|
|
3286
4767
|
* @category Result
|
|
3287
4768
|
* @since 4.0.0
|
|
3288
4769
|
*/
|
|
@@ -3302,11 +4783,16 @@ export type ResultIso<A extends Top, E extends Top> = {
|
|
|
3302
4783
|
readonly failure: E["Iso"];
|
|
3303
4784
|
};
|
|
3304
4785
|
/**
|
|
4786
|
+
* Creates a schema for `Result<A, E>`. See {@link Result} for details.
|
|
4787
|
+
*
|
|
3305
4788
|
* @category Result
|
|
3306
4789
|
* @since 4.0.0
|
|
3307
4790
|
*/
|
|
3308
4791
|
export declare function Result<A extends Top, E extends Top>(success: A, failure: E): Result<A, E>;
|
|
3309
4792
|
/**
|
|
4793
|
+
* Schema for the `Redacted<A>` type, providing secure handling of sensitive
|
|
4794
|
+
* values. The inner value is hidden from error messages.
|
|
4795
|
+
*
|
|
3310
4796
|
* @category Redacted
|
|
3311
4797
|
* @since 4.0.0
|
|
3312
4798
|
*/
|
|
@@ -3340,17 +4826,26 @@ export declare function Redacted<S extends Top>(value: S, options?: {
|
|
|
3340
4826
|
readonly label?: string | undefined;
|
|
3341
4827
|
}): Redacted<S>;
|
|
3342
4828
|
/**
|
|
4829
|
+
* Schema type for {@link RedactedFromValue}.
|
|
4830
|
+
*
|
|
3343
4831
|
* @category Redacted
|
|
3344
4832
|
* @since 4.0.0
|
|
3345
4833
|
*/
|
|
3346
4834
|
export interface RedactedFromValue<S extends Top> extends decodeTo<Redacted<toType<S>>, middlewareDecoding<S, S["DecodingServices"]>> {
|
|
3347
4835
|
}
|
|
3348
4836
|
/**
|
|
4837
|
+
* Middleware that wraps decoded errors in `Redacted`, preventing sensitive
|
|
4838
|
+
* schema details from leaking in error messages.
|
|
4839
|
+
*
|
|
3349
4840
|
* @category Redacted
|
|
3350
4841
|
* @since 4.0.0
|
|
3351
4842
|
*/
|
|
3352
4843
|
export declare function redact<S extends Top>(schema: S): middlewareDecoding<S, S["DecodingServices"]>;
|
|
3353
4844
|
/**
|
|
4845
|
+
* Decodes a value and wraps it in `Redacted<A>`. Unlike {@link Redacted} which
|
|
4846
|
+
* expects the input to already be a `Redacted` instance, this schema decodes
|
|
4847
|
+
* the raw value and wraps it.
|
|
4848
|
+
*
|
|
3354
4849
|
* @category Redacted
|
|
3355
4850
|
* @since 4.0.0
|
|
3356
4851
|
*/
|
|
@@ -3358,6 +4853,10 @@ export declare function RedactedFromValue<S extends Top>(value: S, options?: {
|
|
|
3358
4853
|
readonly label?: string | undefined;
|
|
3359
4854
|
}): RedactedFromValue<S>;
|
|
3360
4855
|
/**
|
|
4856
|
+
* Schema for a single `Cause.Reason<E>`, representing one reason a fiber may
|
|
4857
|
+
* fail: a typed error (`Fail`), an unexpected defect (`Die`), or an interrupt
|
|
4858
|
+
* (`Interrupt`).
|
|
4859
|
+
*
|
|
3361
4860
|
* @category CauseReason
|
|
3362
4861
|
* @since 4.0.0
|
|
3363
4862
|
*/
|
|
@@ -3380,11 +4879,16 @@ export type CauseReasonIso<E extends Top, D extends Top> = {
|
|
|
3380
4879
|
readonly fiberId: number | undefined;
|
|
3381
4880
|
};
|
|
3382
4881
|
/**
|
|
4882
|
+
* Creates a schema for `Cause.Reason<E>`. See {@link CauseReason} for details.
|
|
4883
|
+
*
|
|
3383
4884
|
* @category CauseReason
|
|
3384
4885
|
* @since 4.0.0
|
|
3385
4886
|
*/
|
|
3386
4887
|
export declare function CauseReason<E extends Top, D extends Top>(error: E, defect: D): CauseReason<E, D>;
|
|
3387
4888
|
/**
|
|
4889
|
+
* Schema for `Cause<E>`, an ordered collection of reasons a fiber failed,
|
|
4890
|
+
* combining typed errors, defects, and interrupts.
|
|
4891
|
+
*
|
|
3388
4892
|
* @category Cause
|
|
3389
4893
|
* @since 4.0.0
|
|
3390
4894
|
*/
|
|
@@ -3398,11 +4902,16 @@ export interface Cause<E extends Top, D extends Top> extends declareConstructor<
|
|
|
3398
4902
|
*/
|
|
3399
4903
|
export type CauseIso<E extends Top, D extends Top> = ReadonlyArray<CauseReasonIso<E, D>>;
|
|
3400
4904
|
/**
|
|
4905
|
+
* Creates a schema for `Cause<E>`. See {@link Cause} for details.
|
|
4906
|
+
*
|
|
3401
4907
|
* @category Cause
|
|
3402
4908
|
* @since 4.0.0
|
|
3403
4909
|
*/
|
|
3404
4910
|
export declare function Cause<E extends Top, D extends Top>(error: E, defect: D): Cause<E, D>;
|
|
3405
4911
|
/**
|
|
4912
|
+
* Schema type for {@link Error}.
|
|
4913
|
+
*
|
|
4914
|
+
* @category Schemas
|
|
3406
4915
|
* @since 4.0.0
|
|
3407
4916
|
*/
|
|
3408
4917
|
export interface Error extends instanceOf<globalThis.Error> {
|
|
@@ -3428,6 +4937,9 @@ export declare const Error: Error;
|
|
|
3428
4937
|
*/
|
|
3429
4938
|
export declare const ErrorWithStack: Error;
|
|
3430
4939
|
/**
|
|
4940
|
+
* Schema type for {@link Defect}.
|
|
4941
|
+
*
|
|
4942
|
+
* @category Schemas
|
|
3431
4943
|
* @since 4.0.0
|
|
3432
4944
|
*/
|
|
3433
4945
|
export interface Defect extends Union<readonly [
|
|
@@ -3455,6 +4967,9 @@ export declare const Defect: Defect;
|
|
|
3455
4967
|
*/
|
|
3456
4968
|
export declare const DefectWithStack: Defect;
|
|
3457
4969
|
/**
|
|
4970
|
+
* Schema for `Exit<A, E>`, representing the result of a fiber execution —
|
|
4971
|
+
* either a success with value `A` or a failure with `Cause<E>`.
|
|
4972
|
+
*
|
|
3458
4973
|
* @category Exit
|
|
3459
4974
|
* @since 4.0.0
|
|
3460
4975
|
*/
|
|
@@ -3475,11 +4990,15 @@ export type ExitIso<A extends Top, E extends Top, D extends Top> = {
|
|
|
3475
4990
|
readonly cause: CauseIso<E, D>;
|
|
3476
4991
|
};
|
|
3477
4992
|
/**
|
|
4993
|
+
* Creates a schema for `Exit<A, E>`. See {@link Exit} for details.
|
|
4994
|
+
*
|
|
3478
4995
|
* @category Exit
|
|
3479
4996
|
* @since 4.0.0
|
|
3480
4997
|
*/
|
|
3481
4998
|
export declare function Exit<A extends Top, E extends Top, D extends Top>(value: A, error: E, defect: D): Exit<A, E, D>;
|
|
3482
4999
|
/**
|
|
5000
|
+
* Schema type for {@link ReadonlyMap}.
|
|
5001
|
+
*
|
|
3483
5002
|
* @category ReadonlyMap
|
|
3484
5003
|
* @since 4.0.0
|
|
3485
5004
|
*/
|
|
@@ -3501,6 +5020,9 @@ export type ReadonlyMapIso<Key extends Top, Value extends Top> = ReadonlyArray<r
|
|
|
3501
5020
|
*/
|
|
3502
5021
|
export declare function ReadonlyMap<Key extends Top, Value extends Top>(key: Key, value: Value): $ReadonlyMap<Key, Value>;
|
|
3503
5022
|
/**
|
|
5023
|
+
* Schema for an Effect `HashMap` where keys and values must conform to the
|
|
5024
|
+
* provided schemas.
|
|
5025
|
+
*
|
|
3504
5026
|
* @category HashMap
|
|
3505
5027
|
* @since 4.0.0
|
|
3506
5028
|
*/
|
|
@@ -3522,6 +5044,8 @@ export type HashMapIso<Key extends Top, Value extends Top> = ReadonlyArray<reado
|
|
|
3522
5044
|
*/
|
|
3523
5045
|
export declare function HashMap<Key extends Top, Value extends Top>(key: Key, value: Value): HashMap<Key, Value>;
|
|
3524
5046
|
/**
|
|
5047
|
+
* Schema type for {@link ReadonlySet}.
|
|
5048
|
+
*
|
|
3525
5049
|
* @category ReadonlySet
|
|
3526
5050
|
* @since 4.0.0
|
|
3527
5051
|
*/
|
|
@@ -3539,6 +5063,9 @@ export type ReadonlySetIso<Value extends Top> = ReadonlyArray<Value["Iso"]>;
|
|
|
3539
5063
|
*/
|
|
3540
5064
|
export declare function ReadonlySet<Value extends Top>(value: Value): $ReadonlySet<Value>;
|
|
3541
5065
|
/**
|
|
5066
|
+
* Schema for an Effect `HashSet` where values must conform to the provided
|
|
5067
|
+
* schema.
|
|
5068
|
+
*
|
|
3542
5069
|
* @category HashSet
|
|
3543
5070
|
* @since 4.0.0
|
|
3544
5071
|
*/
|
|
@@ -3559,6 +5086,9 @@ export type HashSetIso<Value extends Top> = ReadonlyArray<Value["Iso"]>;
|
|
|
3559
5086
|
*/
|
|
3560
5087
|
export declare function HashSet<Value extends Top>(value: Value): HashSet<Value>;
|
|
3561
5088
|
/**
|
|
5089
|
+
* Schema for an Effect `Chunk` (immutable array-like collection) where values
|
|
5090
|
+
* must conform to the provided schema.
|
|
5091
|
+
*
|
|
3562
5092
|
* @category Chunk
|
|
3563
5093
|
* @since 4.0.0
|
|
3564
5094
|
*/
|
|
@@ -3579,15 +5109,26 @@ export type ChunkIso<Value extends Top> = ReadonlyArray<Value["Iso"]>;
|
|
|
3579
5109
|
*/
|
|
3580
5110
|
export declare function Chunk<Value extends Top>(value: Value): Chunk<Value>;
|
|
3581
5111
|
/**
|
|
5112
|
+
* Schema type for {@link RegExp}.
|
|
5113
|
+
*
|
|
5114
|
+
* @category Schemas
|
|
3582
5115
|
* @since 4.0.0
|
|
3583
5116
|
*/
|
|
3584
5117
|
export interface RegExp extends instanceOf<globalThis.RegExp> {
|
|
3585
5118
|
}
|
|
3586
5119
|
/**
|
|
5120
|
+
* Schema for JavaScript `RegExp` objects.
|
|
5121
|
+
*
|
|
5122
|
+
* The default JSON serializer encodes a `RegExp` as `{ source, flags }`.
|
|
5123
|
+
*
|
|
5124
|
+
* @category Schemas
|
|
3587
5125
|
* @since 4.0.0
|
|
3588
5126
|
*/
|
|
3589
5127
|
export declare const RegExp: RegExp;
|
|
3590
5128
|
/**
|
|
5129
|
+
* Schema type for {@link URL}.
|
|
5130
|
+
*
|
|
5131
|
+
* @category URL
|
|
3591
5132
|
* @since 4.0.0
|
|
3592
5133
|
*/
|
|
3593
5134
|
export interface URL extends instanceOf<globalThis.URL> {
|
|
@@ -3604,6 +5145,9 @@ export interface URL extends instanceOf<globalThis.URL> {
|
|
|
3604
5145
|
*/
|
|
3605
5146
|
export declare const URL: URL;
|
|
3606
5147
|
/**
|
|
5148
|
+
* Schema type for {@link URLFromString}.
|
|
5149
|
+
*
|
|
5150
|
+
* @category URL
|
|
3607
5151
|
* @since 4.0.0
|
|
3608
5152
|
*/
|
|
3609
5153
|
export interface URLFromString extends decodeTo<URL, String> {
|
|
@@ -3622,6 +5166,9 @@ export interface URLFromString extends decodeTo<URL, String> {
|
|
|
3622
5166
|
*/
|
|
3623
5167
|
export declare const URLFromString: URLFromString;
|
|
3624
5168
|
/**
|
|
5169
|
+
* Schema type for {@link Date}.
|
|
5170
|
+
*
|
|
5171
|
+
* @category Schemas
|
|
3625
5172
|
* @since 4.0.0
|
|
3626
5173
|
*/
|
|
3627
5174
|
export interface Date extends instanceOf<globalThis.Date> {
|
|
@@ -3630,12 +5177,26 @@ export interface Date extends instanceOf<globalThis.Date> {
|
|
|
3630
5177
|
* A schema for JavaScript `Date` objects.
|
|
3631
5178
|
*
|
|
3632
5179
|
* This schema accepts any `Date` instance, including invalid dates (e.g., `new
|
|
3633
|
-
* Date("invalid")`). For validating only valid dates, use
|
|
5180
|
+
* Date("invalid")`). For validating only valid dates, use {@link DateValid}
|
|
5181
|
+
* instead. The default JSON serializer encodes `Date` as an ISO 8601 string.
|
|
5182
|
+
*
|
|
5183
|
+
* **Example** (Date schema)
|
|
5184
|
+
*
|
|
5185
|
+
* ```ts
|
|
5186
|
+
* import { Schema } from "effect"
|
|
5187
|
+
*
|
|
5188
|
+
* Schema.decodeUnknownSync(Schema.Date)(new Date("2024-01-01"))
|
|
5189
|
+
* // => Date { 2024-01-01T00:00:00.000Z }
|
|
5190
|
+
* ```
|
|
3634
5191
|
*
|
|
5192
|
+
* @category Schemas
|
|
3635
5193
|
* @since 4.0.0
|
|
3636
5194
|
*/
|
|
3637
5195
|
export declare const Date: Date;
|
|
3638
5196
|
/**
|
|
5197
|
+
* Schema type for {@link DateValid}.
|
|
5198
|
+
*
|
|
5199
|
+
* @category Schemas
|
|
3639
5200
|
* @since 4.0.0
|
|
3640
5201
|
*/
|
|
3641
5202
|
export interface DateValid extends Date {
|
|
@@ -3650,6 +5211,9 @@ export interface DateValid extends Date {
|
|
|
3650
5211
|
*/
|
|
3651
5212
|
export declare const DateValid: Date;
|
|
3652
5213
|
/**
|
|
5214
|
+
* Schema type for {@link Duration}.
|
|
5215
|
+
*
|
|
5216
|
+
* @category Duration
|
|
3653
5217
|
* @since 4.0.0
|
|
3654
5218
|
*/
|
|
3655
5219
|
export interface Duration extends declare<Duration_.Duration> {
|
|
@@ -3657,14 +5221,28 @@ export interface Duration extends declare<Duration_.Duration> {
|
|
|
3657
5221
|
/**
|
|
3658
5222
|
* A schema for `Duration` values.
|
|
3659
5223
|
*
|
|
3660
|
-
*
|
|
5224
|
+
* The default JSON serializer encodes `Duration` as a tagged object with the
|
|
5225
|
+
* duration type and value.
|
|
5226
|
+
*
|
|
5227
|
+
* **Example** (Duration schema)
|
|
5228
|
+
*
|
|
5229
|
+
* ```ts
|
|
5230
|
+
* import { Schema } from "effect"
|
|
5231
|
+
* import { Duration } from "effect"
|
|
5232
|
+
*
|
|
5233
|
+
* Schema.decodeUnknownSync(Schema.Duration)(Duration.seconds(5))
|
|
5234
|
+
* // => Duration(5s)
|
|
5235
|
+
* ```
|
|
3661
5236
|
*
|
|
3662
|
-
*
|
|
5237
|
+
* @category Duration
|
|
3663
5238
|
*
|
|
3664
5239
|
* @since 4.0.0
|
|
3665
5240
|
*/
|
|
3666
5241
|
export declare const Duration: Duration;
|
|
3667
5242
|
/**
|
|
5243
|
+
* Schema type for {@link DurationFromNanos}.
|
|
5244
|
+
*
|
|
5245
|
+
* @category Duration
|
|
3668
5246
|
* @since 4.0.0
|
|
3669
5247
|
*/
|
|
3670
5248
|
export interface DurationFromNanos extends decodeTo<Duration, BigInt> {
|
|
@@ -3684,6 +5262,9 @@ export interface DurationFromNanos extends decodeTo<Duration, BigInt> {
|
|
|
3684
5262
|
*/
|
|
3685
5263
|
export declare const DurationFromNanos: DurationFromNanos;
|
|
3686
5264
|
/**
|
|
5265
|
+
* Schema type for {@link DurationFromMillis}.
|
|
5266
|
+
*
|
|
5267
|
+
* @category Duration
|
|
3687
5268
|
* @since 4.0.0
|
|
3688
5269
|
*/
|
|
3689
5270
|
export interface DurationFromMillis extends decodeTo<Duration, Number> {
|
|
@@ -3706,6 +5287,9 @@ export interface DurationFromMillis extends decodeTo<Duration, Number> {
|
|
|
3706
5287
|
*/
|
|
3707
5288
|
export declare const DurationFromMillis: DurationFromMillis;
|
|
3708
5289
|
/**
|
|
5290
|
+
* Schema type for {@link BigDecimal}.
|
|
5291
|
+
*
|
|
5292
|
+
* @category Schemas
|
|
3709
5293
|
* @since 4.0.0
|
|
3710
5294
|
*/
|
|
3711
5295
|
export interface BigDecimal extends declare<BigDecimal_.BigDecimal> {
|
|
@@ -3721,6 +5305,9 @@ export interface BigDecimal extends declare<BigDecimal_.BigDecimal> {
|
|
|
3721
5305
|
*/
|
|
3722
5306
|
export declare const BigDecimal: BigDecimal;
|
|
3723
5307
|
/**
|
|
5308
|
+
* Schema type for {@link UnknownFromJsonString}.
|
|
5309
|
+
*
|
|
5310
|
+
* @category JSON
|
|
3724
5311
|
* @since 4.0.0
|
|
3725
5312
|
*/
|
|
3726
5313
|
export interface UnknownFromJsonString extends fromJsonString<Unknown> {
|
|
@@ -3749,6 +5336,9 @@ export interface UnknownFromJsonString extends fromJsonString<Unknown> {
|
|
|
3749
5336
|
*/
|
|
3750
5337
|
export declare const UnknownFromJsonString: fromJsonString<Unknown>;
|
|
3751
5338
|
/**
|
|
5339
|
+
* Schema type for {@link fromJsonString}.
|
|
5340
|
+
*
|
|
5341
|
+
* @category JSON
|
|
3752
5342
|
* @since 4.0.0
|
|
3753
5343
|
*/
|
|
3754
5344
|
export interface fromJsonString<S extends Top> extends decodeTo<S, String> {
|
|
@@ -3818,24 +5408,45 @@ export interface fromJsonString<S extends Top> extends decodeTo<S, String> {
|
|
|
3818
5408
|
*/
|
|
3819
5409
|
export declare function fromJsonString<S extends Top>(schema: S): fromJsonString<S>;
|
|
3820
5410
|
/**
|
|
5411
|
+
* Schema type for {@link File}.
|
|
5412
|
+
*
|
|
5413
|
+
* @category Schemas
|
|
3821
5414
|
* @since 4.0.0
|
|
3822
5415
|
*/
|
|
3823
5416
|
export interface File extends instanceOf<globalThis.File> {
|
|
3824
5417
|
}
|
|
3825
5418
|
/**
|
|
5419
|
+
* Schema for JavaScript `File` objects.
|
|
5420
|
+
*
|
|
5421
|
+
* The default JSON serializer encodes a `File` as `{ data, type, name, lastModified }`
|
|
5422
|
+
* where `data` is base64-encoded.
|
|
5423
|
+
*
|
|
5424
|
+
* @category Schemas
|
|
3826
5425
|
* @since 4.0.0
|
|
3827
5426
|
*/
|
|
3828
5427
|
export declare const File: File;
|
|
3829
5428
|
/**
|
|
5429
|
+
* Schema type for {@link FormData}.
|
|
5430
|
+
*
|
|
5431
|
+
* @category Schemas
|
|
3830
5432
|
* @since 4.0.0
|
|
3831
5433
|
*/
|
|
3832
5434
|
export interface FormData extends instanceOf<globalThis.FormData> {
|
|
3833
5435
|
}
|
|
3834
5436
|
/**
|
|
5437
|
+
* Schema for JavaScript `FormData` objects.
|
|
5438
|
+
*
|
|
5439
|
+
* The default JSON serializer encodes a `FormData` as an array of `[key, entry]`
|
|
5440
|
+
* pairs where each entry is tagged as `"String"` or `"File"`.
|
|
5441
|
+
*
|
|
5442
|
+
* @category Schemas
|
|
3835
5443
|
* @since 4.0.0
|
|
3836
5444
|
*/
|
|
3837
5445
|
export declare const FormData: FormData;
|
|
3838
5446
|
/**
|
|
5447
|
+
* Schema type for {@link fromFormData}.
|
|
5448
|
+
*
|
|
5449
|
+
* @category Schemas
|
|
3839
5450
|
* @since 4.0.0
|
|
3840
5451
|
*/
|
|
3841
5452
|
export interface fromFormData<S extends Top> extends decodeTo<S, FormData> {
|
|
@@ -3925,15 +5536,26 @@ export interface fromFormData<S extends Top> extends decodeTo<S, FormData> {
|
|
|
3925
5536
|
*/
|
|
3926
5537
|
export declare function fromFormData<S extends Top>(schema: S): fromFormData<S>;
|
|
3927
5538
|
/**
|
|
5539
|
+
* Schema type for {@link URLSearchParams}.
|
|
5540
|
+
*
|
|
5541
|
+
* @category Schemas
|
|
3928
5542
|
* @since 4.0.0
|
|
3929
5543
|
*/
|
|
3930
5544
|
export interface URLSearchParams extends instanceOf<globalThis.URLSearchParams> {
|
|
3931
5545
|
}
|
|
3932
5546
|
/**
|
|
5547
|
+
* Schema for JavaScript `URLSearchParams` objects.
|
|
5548
|
+
*
|
|
5549
|
+
* The default JSON serializer encodes a `URLSearchParams` as a query string.
|
|
5550
|
+
*
|
|
5551
|
+
* @category Schemas
|
|
3933
5552
|
* @since 4.0.0
|
|
3934
5553
|
*/
|
|
3935
5554
|
export declare const URLSearchParams: URLSearchParams;
|
|
3936
5555
|
/**
|
|
5556
|
+
* Schema type for {@link fromURLSearchParams}.
|
|
5557
|
+
*
|
|
5558
|
+
* @category Schemas
|
|
3937
5559
|
* @since 4.0.0
|
|
3938
5560
|
*/
|
|
3939
5561
|
export interface fromURLSearchParams<S extends Top> extends decodeTo<S, URLSearchParams> {
|
|
@@ -4014,6 +5636,9 @@ export interface fromURLSearchParams<S extends Top> extends decodeTo<S, URLSearc
|
|
|
4014
5636
|
*/
|
|
4015
5637
|
export declare function fromURLSearchParams<S extends Top>(schema: S): fromURLSearchParams<S>;
|
|
4016
5638
|
/**
|
|
5639
|
+
* Schema type for {@link Finite}.
|
|
5640
|
+
*
|
|
5641
|
+
* @category Schemas
|
|
4017
5642
|
* @since 4.0.0
|
|
4018
5643
|
*/
|
|
4019
5644
|
export interface Finite extends Number {
|
|
@@ -4025,6 +5650,9 @@ export interface Finite extends Number {
|
|
|
4025
5650
|
*/
|
|
4026
5651
|
export declare const Finite: Finite;
|
|
4027
5652
|
/**
|
|
5653
|
+
* Schema type for {@link Int}.
|
|
5654
|
+
*
|
|
5655
|
+
* @category Schemas
|
|
4028
5656
|
* @since 4.0.0
|
|
4029
5657
|
*/
|
|
4030
5658
|
export interface Int extends Number {
|
|
@@ -4036,6 +5664,9 @@ export interface Int extends Number {
|
|
|
4036
5664
|
*/
|
|
4037
5665
|
export declare const Int: Int;
|
|
4038
5666
|
/**
|
|
5667
|
+
* Schema type for {@link NumberFromString}.
|
|
5668
|
+
*
|
|
5669
|
+
* @category Schemas
|
|
4039
5670
|
* @since 4.0.0
|
|
4040
5671
|
*/
|
|
4041
5672
|
export interface NumberFromString extends decodeTo<Finite, String> {
|
|
@@ -4053,6 +5684,9 @@ export interface NumberFromString extends decodeTo<Finite, String> {
|
|
|
4053
5684
|
*/
|
|
4054
5685
|
export declare const NumberFromString: NumberFromString;
|
|
4055
5686
|
/**
|
|
5687
|
+
* Schema type for {@link FiniteFromString}.
|
|
5688
|
+
*
|
|
5689
|
+
* @category Schemas
|
|
4056
5690
|
* @since 4.0.0
|
|
4057
5691
|
*/
|
|
4058
5692
|
export interface FiniteFromString extends decodeTo<Finite, String> {
|
|
@@ -4071,6 +5705,9 @@ export interface FiniteFromString extends decodeTo<Finite, String> {
|
|
|
4071
5705
|
*/
|
|
4072
5706
|
export declare const FiniteFromString: FiniteFromString;
|
|
4073
5707
|
/**
|
|
5708
|
+
* Schema type for {@link Trimmed}.
|
|
5709
|
+
*
|
|
5710
|
+
* @category Schemas
|
|
4074
5711
|
* @since 4.0.0
|
|
4075
5712
|
*/
|
|
4076
5713
|
export interface Trimmed extends String {
|
|
@@ -4082,6 +5719,9 @@ export interface Trimmed extends String {
|
|
|
4082
5719
|
*/
|
|
4083
5720
|
export declare const Trimmed: Trimmed;
|
|
4084
5721
|
/**
|
|
5722
|
+
* Schema type for {@link Trim}.
|
|
5723
|
+
*
|
|
5724
|
+
* @category Schemas
|
|
4085
5725
|
* @since 4.0.0
|
|
4086
5726
|
*/
|
|
4087
5727
|
export interface Trim extends decodeTo<Trimmed, String> {
|
|
@@ -4099,6 +5739,9 @@ export interface Trim extends decodeTo<Trimmed, String> {
|
|
|
4099
5739
|
*/
|
|
4100
5740
|
export declare const Trim: Trim;
|
|
4101
5741
|
/**
|
|
5742
|
+
* A union schema for JavaScript property keys: `number | symbol | string`.
|
|
5743
|
+
*
|
|
5744
|
+
* @category Schemas
|
|
4102
5745
|
* @since 4.0.0
|
|
4103
5746
|
*/
|
|
4104
5747
|
export declare const PropertyKey: Union<readonly [Finite, Symbol, String]>;
|
|
@@ -4114,6 +5757,9 @@ export declare const StandardSchemaV1FailureResult: Struct<{
|
|
|
4114
5757
|
}>>;
|
|
4115
5758
|
}>;
|
|
4116
5759
|
/**
|
|
5760
|
+
* Schema type for {@link BooleanFromBit}.
|
|
5761
|
+
*
|
|
5762
|
+
* @category Schemas
|
|
4117
5763
|
* @since 4.0.0
|
|
4118
5764
|
*/
|
|
4119
5765
|
export interface BooleanFromBit extends decodeTo<Boolean, Literals<readonly [0, 1]>> {
|
|
@@ -4126,6 +5772,9 @@ export interface BooleanFromBit extends decodeTo<Boolean, Literals<readonly [0,
|
|
|
4126
5772
|
*/
|
|
4127
5773
|
export declare const BooleanFromBit: BooleanFromBit;
|
|
4128
5774
|
/**
|
|
5775
|
+
* Schema type for {@link Uint8Array}.
|
|
5776
|
+
*
|
|
5777
|
+
* @category Schemas
|
|
4129
5778
|
* @since 4.0.0
|
|
4130
5779
|
*/
|
|
4131
5780
|
export interface Uint8Array extends instanceOf<globalThis.Uint8Array<ArrayBufferLike>> {
|
|
@@ -4142,6 +5791,9 @@ export interface Uint8Array extends instanceOf<globalThis.Uint8Array<ArrayBuffer
|
|
|
4142
5791
|
*/
|
|
4143
5792
|
export declare const Uint8Array: Uint8Array;
|
|
4144
5793
|
/**
|
|
5794
|
+
* Schema type for {@link Uint8ArrayFromBase64}.
|
|
5795
|
+
*
|
|
5796
|
+
* @category Schemas
|
|
4145
5797
|
* @since 4.0.0
|
|
4146
5798
|
*/
|
|
4147
5799
|
export interface Uint8ArrayFromBase64 extends decodeTo<Uint8Array, String> {
|
|
@@ -4161,6 +5813,9 @@ export interface Uint8ArrayFromBase64 extends decodeTo<Uint8Array, String> {
|
|
|
4161
5813
|
*/
|
|
4162
5814
|
export declare const Uint8ArrayFromBase64: Uint8ArrayFromBase64;
|
|
4163
5815
|
/**
|
|
5816
|
+
* Schema type for {@link Uint8ArrayFromBase64Url}.
|
|
5817
|
+
*
|
|
5818
|
+
* @category Schemas
|
|
4164
5819
|
* @since 4.0.0
|
|
4165
5820
|
*/
|
|
4166
5821
|
export interface Uint8ArrayFromBase64Url extends decodeTo<Uint8Array, String> {
|
|
@@ -4180,6 +5835,9 @@ export interface Uint8ArrayFromBase64Url extends decodeTo<Uint8Array, String> {
|
|
|
4180
5835
|
*/
|
|
4181
5836
|
export declare const Uint8ArrayFromBase64Url: Uint8ArrayFromBase64Url;
|
|
4182
5837
|
/**
|
|
5838
|
+
* Schema type for {@link Uint8ArrayFromHex}.
|
|
5839
|
+
*
|
|
5840
|
+
* @category Schemas
|
|
4183
5841
|
* @since 4.0.0
|
|
4184
5842
|
*/
|
|
4185
5843
|
export interface Uint8ArrayFromHex extends decodeTo<Uint8Array, String> {
|
|
@@ -4199,6 +5857,9 @@ export interface Uint8ArrayFromHex extends decodeTo<Uint8Array, String> {
|
|
|
4199
5857
|
*/
|
|
4200
5858
|
export declare const Uint8ArrayFromHex: Uint8ArrayFromHex;
|
|
4201
5859
|
/**
|
|
5860
|
+
* Schema type for {@link DateTimeUtc}.
|
|
5861
|
+
*
|
|
5862
|
+
* @category DateTime
|
|
4202
5863
|
* @since 4.0.0
|
|
4203
5864
|
*/
|
|
4204
5865
|
export interface DateTimeUtc extends declare<DateTime.Utc> {
|
|
@@ -4215,6 +5876,9 @@ export interface DateTimeUtc extends declare<DateTime.Utc> {
|
|
|
4215
5876
|
*/
|
|
4216
5877
|
export declare const DateTimeUtc: DateTimeUtc;
|
|
4217
5878
|
/**
|
|
5879
|
+
* Schema type for {@link DateTimeUtcFromDate}.
|
|
5880
|
+
*
|
|
5881
|
+
* @category DateTime
|
|
4218
5882
|
* @since 4.0.0
|
|
4219
5883
|
*/
|
|
4220
5884
|
export interface DateTimeUtcFromDate extends decodeTo<DateTimeUtc, Date> {
|
|
@@ -4233,6 +5897,9 @@ export interface DateTimeUtcFromDate extends decodeTo<DateTimeUtc, Date> {
|
|
|
4233
5897
|
*/
|
|
4234
5898
|
export declare const DateTimeUtcFromDate: DateTimeUtcFromDate;
|
|
4235
5899
|
/**
|
|
5900
|
+
* Schema type for {@link DateTimeUtcFromString}.
|
|
5901
|
+
*
|
|
5902
|
+
* @category DateTime
|
|
4236
5903
|
* @since 4.0.0
|
|
4237
5904
|
*/
|
|
4238
5905
|
export interface DateTimeUtcFromString extends decodeTo<DateTimeUtc, String> {
|
|
@@ -4253,6 +5920,9 @@ export interface DateTimeUtcFromString extends decodeTo<DateTimeUtc, String> {
|
|
|
4253
5920
|
*/
|
|
4254
5921
|
export declare const DateTimeUtcFromString: DateTimeUtcFromString;
|
|
4255
5922
|
/**
|
|
5923
|
+
* Schema type for {@link DateTimeUtcFromMillis}.
|
|
5924
|
+
*
|
|
5925
|
+
* @category DateTime
|
|
4256
5926
|
* @since 4.0.0
|
|
4257
5927
|
*/
|
|
4258
5928
|
export interface DateTimeUtcFromMillis extends decodeTo<instanceOf<DateTime.Utc>, Number> {
|
|
@@ -4271,6 +5941,9 @@ export interface DateTimeUtcFromMillis extends decodeTo<instanceOf<DateTime.Utc>
|
|
|
4271
5941
|
*/
|
|
4272
5942
|
export declare const DateTimeUtcFromMillis: DateTimeUtcFromMillis;
|
|
4273
5943
|
/**
|
|
5944
|
+
* Schema type for {@link TimeZoneOffset}.
|
|
5945
|
+
*
|
|
5946
|
+
* @category DateTime
|
|
4274
5947
|
* @since 4.0.0
|
|
4275
5948
|
*/
|
|
4276
5949
|
export interface TimeZoneOffset extends declare<DateTime.TimeZone.Offset> {
|
|
@@ -4287,6 +5960,9 @@ export interface TimeZoneOffset extends declare<DateTime.TimeZone.Offset> {
|
|
|
4287
5960
|
*/
|
|
4288
5961
|
export declare const TimeZoneOffset: TimeZoneOffset;
|
|
4289
5962
|
/**
|
|
5963
|
+
* Schema type for {@link TimeZoneNamed}.
|
|
5964
|
+
*
|
|
5965
|
+
* @category DateTime
|
|
4290
5966
|
* @since 4.0.0
|
|
4291
5967
|
*/
|
|
4292
5968
|
export interface TimeZoneNamed extends declare<DateTime.TimeZone.Named> {
|
|
@@ -4303,6 +5979,9 @@ export interface TimeZoneNamed extends declare<DateTime.TimeZone.Named> {
|
|
|
4303
5979
|
*/
|
|
4304
5980
|
export declare const TimeZoneNamed: TimeZoneNamed;
|
|
4305
5981
|
/**
|
|
5982
|
+
* Schema type for {@link TimeZone}.
|
|
5983
|
+
*
|
|
5984
|
+
* @category DateTime
|
|
4306
5985
|
* @since 4.0.0
|
|
4307
5986
|
*/
|
|
4308
5987
|
export interface TimeZone extends declare<DateTime.TimeZone> {
|
|
@@ -4320,6 +5999,9 @@ export interface TimeZone extends declare<DateTime.TimeZone> {
|
|
|
4320
5999
|
*/
|
|
4321
6000
|
export declare const TimeZone: TimeZone;
|
|
4322
6001
|
/**
|
|
6002
|
+
* Schema type for {@link DateTimeZoned}.
|
|
6003
|
+
*
|
|
6004
|
+
* @category DateTime
|
|
4323
6005
|
* @since 4.0.0
|
|
4324
6006
|
*/
|
|
4325
6007
|
export interface DateTimeZoned extends declare<DateTime.Zoned> {
|
|
@@ -4337,6 +6019,14 @@ export interface DateTimeZoned extends declare<DateTime.Zoned> {
|
|
|
4337
6019
|
*/
|
|
4338
6020
|
export declare const DateTimeZoned: DateTimeZoned;
|
|
4339
6021
|
/**
|
|
6022
|
+
* Interface for schema-backed classes created with {@link Class}.
|
|
6023
|
+
*
|
|
6024
|
+
* A `Class` is a TypeScript class whose constructor validates its input
|
|
6025
|
+
* against a {@link Struct} schema. Instances are always structurally valid.
|
|
6026
|
+
*
|
|
6027
|
+
* The interface exposes the schema's `fields`, an `identifier` string, and
|
|
6028
|
+
* helpers such as `mapFields`, `annotate`, `check`, and `extend`.
|
|
6029
|
+
*
|
|
4340
6030
|
* @since 4.0.0
|
|
4341
6031
|
*/
|
|
4342
6032
|
export interface Class<Self, S extends Top & {
|
|
@@ -4365,6 +6055,10 @@ export interface Class<Self, S extends Top & {
|
|
|
4365
6055
|
}
|
|
4366
6056
|
type AddStaticMembers<C, Static> = C & Pick<Static, Exclude<keyof Static, keyof C>>;
|
|
4367
6057
|
/**
|
|
6058
|
+
* A {@link Class} that additionally exposes an `extend` method, allowing
|
|
6059
|
+
* subclasses to be derived with extra fields while inheriting all parent
|
|
6060
|
+
* fields and validation.
|
|
6061
|
+
*
|
|
4368
6062
|
* @since 4.0.0
|
|
4369
6063
|
*/
|
|
4370
6064
|
export interface ExtendableClass<Self, S extends Top & {
|
|
@@ -4373,21 +6067,181 @@ export interface ExtendableClass<Self, S extends Top & {
|
|
|
4373
6067
|
extend<Extended, Static = {}, Brand = {}>(identifier: string): <NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>) => AddStaticMembers<ExtendableClass<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
|
|
4374
6068
|
}
|
|
4375
6069
|
/**
|
|
6070
|
+
* Creates a schema-backed class whose constructor validates input against a
|
|
6071
|
+
* {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
|
|
6072
|
+
* input (unless `disableValidation` is set in the options).
|
|
6073
|
+
*
|
|
6074
|
+
* Pass the desired class type as the first type parameter. The second optional
|
|
6075
|
+
* type parameter can be used to add nominal brands.
|
|
6076
|
+
*
|
|
6077
|
+
* **Example** (Basic class)
|
|
6078
|
+
*
|
|
6079
|
+
* ```ts
|
|
6080
|
+
* import { Schema } from "effect"
|
|
6081
|
+
*
|
|
6082
|
+
* class Person extends Schema.Class<Person>("Person")({
|
|
6083
|
+
* name: Schema.String,
|
|
6084
|
+
* age: Schema.Number
|
|
6085
|
+
* }) {}
|
|
6086
|
+
*
|
|
6087
|
+
* const alice = new Person({ name: "Alice", age: 30 })
|
|
6088
|
+
* console.log(alice.name) // "Alice"
|
|
6089
|
+
* console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
|
|
6090
|
+
* ```
|
|
6091
|
+
*
|
|
6092
|
+
* **Example** (Extending a class)
|
|
6093
|
+
*
|
|
6094
|
+
* ```ts
|
|
6095
|
+
* import { Schema } from "effect"
|
|
6096
|
+
*
|
|
6097
|
+
* class Animal extends Schema.Class<Animal>("Animal")({
|
|
6098
|
+
* name: Schema.String
|
|
6099
|
+
* }) {}
|
|
6100
|
+
*
|
|
6101
|
+
* class Dog extends Animal.extend<Dog>("Dog")({
|
|
6102
|
+
* breed: Schema.String
|
|
6103
|
+
* }) {}
|
|
6104
|
+
*
|
|
6105
|
+
* const dog = new Dog({ name: "Rex", breed: "Labrador" })
|
|
6106
|
+
* console.log(dog.name) // "Rex"
|
|
6107
|
+
* console.log(dog.breed) // "Labrador"
|
|
6108
|
+
* ```
|
|
6109
|
+
*
|
|
4376
6110
|
* @category Constructors
|
|
4377
6111
|
* @since 4.0.0
|
|
4378
6112
|
*/
|
|
4379
6113
|
export declare const Class: {
|
|
4380
6114
|
/**
|
|
6115
|
+
* Creates a schema-backed class whose constructor validates input against a
|
|
6116
|
+
* {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
|
|
6117
|
+
* input (unless `disableValidation` is set in the options).
|
|
6118
|
+
*
|
|
6119
|
+
* Pass the desired class type as the first type parameter. The second optional
|
|
6120
|
+
* type parameter can be used to add nominal brands.
|
|
6121
|
+
*
|
|
6122
|
+
* **Example** (Basic class)
|
|
6123
|
+
*
|
|
6124
|
+
* ```ts
|
|
6125
|
+
* import { Schema } from "effect"
|
|
6126
|
+
*
|
|
6127
|
+
* class Person extends Schema.Class<Person>("Person")({
|
|
6128
|
+
* name: Schema.String,
|
|
6129
|
+
* age: Schema.Number
|
|
6130
|
+
* }) {}
|
|
6131
|
+
*
|
|
6132
|
+
* const alice = new Person({ name: "Alice", age: 30 })
|
|
6133
|
+
* console.log(alice.name) // "Alice"
|
|
6134
|
+
* console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
|
|
6135
|
+
* ```
|
|
6136
|
+
*
|
|
6137
|
+
* **Example** (Extending a class)
|
|
6138
|
+
*
|
|
6139
|
+
* ```ts
|
|
6140
|
+
* import { Schema } from "effect"
|
|
6141
|
+
*
|
|
6142
|
+
* class Animal extends Schema.Class<Animal>("Animal")({
|
|
6143
|
+
* name: Schema.String
|
|
6144
|
+
* }) {}
|
|
6145
|
+
*
|
|
6146
|
+
* class Dog extends Animal.extend<Dog>("Dog")({
|
|
6147
|
+
* breed: Schema.String
|
|
6148
|
+
* }) {}
|
|
6149
|
+
*
|
|
6150
|
+
* const dog = new Dog({ name: "Rex", breed: "Labrador" })
|
|
6151
|
+
* console.log(dog.name) // "Rex"
|
|
6152
|
+
* console.log(dog.breed) // "Labrador"
|
|
6153
|
+
* ```
|
|
6154
|
+
*
|
|
4381
6155
|
* @category Constructors
|
|
4382
6156
|
* @since 4.0.0
|
|
4383
6157
|
*/
|
|
4384
6158
|
<Self, Brand = {}>(identifier: string): {
|
|
4385
6159
|
/**
|
|
6160
|
+
* Creates a schema-backed class whose constructor validates input against a
|
|
6161
|
+
* {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
|
|
6162
|
+
* input (unless `disableValidation` is set in the options).
|
|
6163
|
+
*
|
|
6164
|
+
* Pass the desired class type as the first type parameter. The second optional
|
|
6165
|
+
* type parameter can be used to add nominal brands.
|
|
6166
|
+
*
|
|
6167
|
+
* **Example** (Basic class)
|
|
6168
|
+
*
|
|
6169
|
+
* ```ts
|
|
6170
|
+
* import { Schema } from "effect"
|
|
6171
|
+
*
|
|
6172
|
+
* class Person extends Schema.Class<Person>("Person")({
|
|
6173
|
+
* name: Schema.String,
|
|
6174
|
+
* age: Schema.Number
|
|
6175
|
+
* }) {}
|
|
6176
|
+
*
|
|
6177
|
+
* const alice = new Person({ name: "Alice", age: 30 })
|
|
6178
|
+
* console.log(alice.name) // "Alice"
|
|
6179
|
+
* console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
|
|
6180
|
+
* ```
|
|
6181
|
+
*
|
|
6182
|
+
* **Example** (Extending a class)
|
|
6183
|
+
*
|
|
6184
|
+
* ```ts
|
|
6185
|
+
* import { Schema } from "effect"
|
|
6186
|
+
*
|
|
6187
|
+
* class Animal extends Schema.Class<Animal>("Animal")({
|
|
6188
|
+
* name: Schema.String
|
|
6189
|
+
* }) {}
|
|
6190
|
+
*
|
|
6191
|
+
* class Dog extends Animal.extend<Dog>("Dog")({
|
|
6192
|
+
* breed: Schema.String
|
|
6193
|
+
* }) {}
|
|
6194
|
+
*
|
|
6195
|
+
* const dog = new Dog({ name: "Rex", breed: "Labrador" })
|
|
6196
|
+
* console.log(dog.name) // "Rex"
|
|
6197
|
+
* console.log(dog.breed) // "Labrador"
|
|
6198
|
+
* ```
|
|
6199
|
+
*
|
|
4386
6200
|
* @category Constructors
|
|
4387
6201
|
* @since 4.0.0
|
|
4388
6202
|
*/
|
|
4389
6203
|
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): ExtendableClass<Self, Struct<Fields>, Brand>;
|
|
4390
6204
|
/**
|
|
6205
|
+
* Creates a schema-backed class whose constructor validates input against a
|
|
6206
|
+
* {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
|
|
6207
|
+
* input (unless `disableValidation` is set in the options).
|
|
6208
|
+
*
|
|
6209
|
+
* Pass the desired class type as the first type parameter. The second optional
|
|
6210
|
+
* type parameter can be used to add nominal brands.
|
|
6211
|
+
*
|
|
6212
|
+
* **Example** (Basic class)
|
|
6213
|
+
*
|
|
6214
|
+
* ```ts
|
|
6215
|
+
* import { Schema } from "effect"
|
|
6216
|
+
*
|
|
6217
|
+
* class Person extends Schema.Class<Person>("Person")({
|
|
6218
|
+
* name: Schema.String,
|
|
6219
|
+
* age: Schema.Number
|
|
6220
|
+
* }) {}
|
|
6221
|
+
*
|
|
6222
|
+
* const alice = new Person({ name: "Alice", age: 30 })
|
|
6223
|
+
* console.log(alice.name) // "Alice"
|
|
6224
|
+
* console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
|
|
6225
|
+
* ```
|
|
6226
|
+
*
|
|
6227
|
+
* **Example** (Extending a class)
|
|
6228
|
+
*
|
|
6229
|
+
* ```ts
|
|
6230
|
+
* import { Schema } from "effect"
|
|
6231
|
+
*
|
|
6232
|
+
* class Animal extends Schema.Class<Animal>("Animal")({
|
|
6233
|
+
* name: Schema.String
|
|
6234
|
+
* }) {}
|
|
6235
|
+
*
|
|
6236
|
+
* class Dog extends Animal.extend<Dog>("Dog")({
|
|
6237
|
+
* breed: Schema.String
|
|
6238
|
+
* }) {}
|
|
6239
|
+
*
|
|
6240
|
+
* const dog = new Dog({ name: "Rex", breed: "Labrador" })
|
|
6241
|
+
* console.log(dog.name) // "Rex"
|
|
6242
|
+
* console.log(dog.breed) // "Labrador"
|
|
6243
|
+
* ```
|
|
6244
|
+
*
|
|
4391
6245
|
* @category Constructors
|
|
4392
6246
|
* @since 4.0.0
|
|
4393
6247
|
*/
|
|
@@ -4395,21 +6249,105 @@ export declare const Class: {
|
|
|
4395
6249
|
};
|
|
4396
6250
|
};
|
|
4397
6251
|
/**
|
|
6252
|
+
* Like {@link Class} but automatically adds a `_tag` literal field set to the
|
|
6253
|
+
* given `tag` value. This makes instances compatible with tagged union
|
|
6254
|
+
* discrimination patterns.
|
|
6255
|
+
*
|
|
6256
|
+
* The optional `identifier` parameter overrides the schema identifier;
|
|
6257
|
+
* it defaults to the `tag` value.
|
|
6258
|
+
*
|
|
6259
|
+
* **Example** (Tagged class)
|
|
6260
|
+
*
|
|
6261
|
+
* ```ts
|
|
6262
|
+
* import { Schema } from "effect"
|
|
6263
|
+
*
|
|
6264
|
+
* class Circle extends Schema.TaggedClass<Circle>()("Circle", {
|
|
6265
|
+
* radius: Schema.Number
|
|
6266
|
+
* }) {}
|
|
6267
|
+
*
|
|
6268
|
+
* const c = new Circle({ radius: 5 })
|
|
6269
|
+
* console.log(c._tag) // "Circle"
|
|
6270
|
+
* console.log(c.radius) // 5
|
|
6271
|
+
* ```
|
|
6272
|
+
*
|
|
4398
6273
|
* @category Constructors
|
|
4399
6274
|
* @since 4.0.0
|
|
4400
6275
|
*/
|
|
4401
6276
|
export declare const TaggedClass: {
|
|
4402
6277
|
/**
|
|
6278
|
+
* Like {@link Class} but automatically adds a `_tag` literal field set to the
|
|
6279
|
+
* given `tag` value. This makes instances compatible with tagged union
|
|
6280
|
+
* discrimination patterns.
|
|
6281
|
+
*
|
|
6282
|
+
* The optional `identifier` parameter overrides the schema identifier;
|
|
6283
|
+
* it defaults to the `tag` value.
|
|
6284
|
+
*
|
|
6285
|
+
* **Example** (Tagged class)
|
|
6286
|
+
*
|
|
6287
|
+
* ```ts
|
|
6288
|
+
* import { Schema } from "effect"
|
|
6289
|
+
*
|
|
6290
|
+
* class Circle extends Schema.TaggedClass<Circle>()("Circle", {
|
|
6291
|
+
* radius: Schema.Number
|
|
6292
|
+
* }) {}
|
|
6293
|
+
*
|
|
6294
|
+
* const c = new Circle({ radius: 5 })
|
|
6295
|
+
* console.log(c._tag) // "Circle"
|
|
6296
|
+
* console.log(c.radius) // 5
|
|
6297
|
+
* ```
|
|
6298
|
+
*
|
|
4403
6299
|
* @category Constructors
|
|
4404
6300
|
* @since 4.0.0
|
|
4405
6301
|
*/
|
|
4406
6302
|
<Self, Brand = {}>(identifier?: string): {
|
|
4407
6303
|
/**
|
|
6304
|
+
* Like {@link Class} but automatically adds a `_tag` literal field set to the
|
|
6305
|
+
* given `tag` value. This makes instances compatible with tagged union
|
|
6306
|
+
* discrimination patterns.
|
|
6307
|
+
*
|
|
6308
|
+
* The optional `identifier` parameter overrides the schema identifier;
|
|
6309
|
+
* it defaults to the `tag` value.
|
|
6310
|
+
*
|
|
6311
|
+
* **Example** (Tagged class)
|
|
6312
|
+
*
|
|
6313
|
+
* ```ts
|
|
6314
|
+
* import { Schema } from "effect"
|
|
6315
|
+
*
|
|
6316
|
+
* class Circle extends Schema.TaggedClass<Circle>()("Circle", {
|
|
6317
|
+
* radius: Schema.Number
|
|
6318
|
+
* }) {}
|
|
6319
|
+
*
|
|
6320
|
+
* const c = new Circle({ radius: 5 })
|
|
6321
|
+
* console.log(c._tag) // "Circle"
|
|
6322
|
+
* console.log(c.radius) // 5
|
|
6323
|
+
* ```
|
|
6324
|
+
*
|
|
4408
6325
|
* @category Constructors
|
|
4409
6326
|
* @since 4.0.0
|
|
4410
6327
|
*/
|
|
4411
6328
|
<Tag extends string, const Fields extends Struct.Fields>(tag: Tag, fields: Fields, annotations?: Annotations.Declaration<Self, readonly [TaggedStruct<Tag, Fields>]>): ExtendableClass<Self, TaggedStruct<Tag, Fields>, Brand>;
|
|
4412
6329
|
/**
|
|
6330
|
+
* Like {@link Class} but automatically adds a `_tag` literal field set to the
|
|
6331
|
+
* given `tag` value. This makes instances compatible with tagged union
|
|
6332
|
+
* discrimination patterns.
|
|
6333
|
+
*
|
|
6334
|
+
* The optional `identifier` parameter overrides the schema identifier;
|
|
6335
|
+
* it defaults to the `tag` value.
|
|
6336
|
+
*
|
|
6337
|
+
* **Example** (Tagged class)
|
|
6338
|
+
*
|
|
6339
|
+
* ```ts
|
|
6340
|
+
* import { Schema } from "effect"
|
|
6341
|
+
*
|
|
6342
|
+
* class Circle extends Schema.TaggedClass<Circle>()("Circle", {
|
|
6343
|
+
* radius: Schema.Number
|
|
6344
|
+
* }) {}
|
|
6345
|
+
*
|
|
6346
|
+
* const c = new Circle({ radius: 5 })
|
|
6347
|
+
* console.log(c._tag) // "Circle"
|
|
6348
|
+
* console.log(c.radius) // 5
|
|
6349
|
+
* ```
|
|
6350
|
+
*
|
|
4413
6351
|
* @category Constructors
|
|
4414
6352
|
* @since 4.0.0
|
|
4415
6353
|
*/
|
|
@@ -4421,6 +6359,10 @@ export declare const TaggedClass: {
|
|
|
4421
6359
|
};
|
|
4422
6360
|
};
|
|
4423
6361
|
/**
|
|
6362
|
+
* Interface for schema-backed error classes created with {@link ErrorClass}.
|
|
6363
|
+
* Extends {@link ExtendableClass} and is also a `YieldableError`, so instances
|
|
6364
|
+
* can be yielded inside `Effect.gen` as failures.
|
|
6365
|
+
*
|
|
4424
6366
|
* @since 4.0.0
|
|
4425
6367
|
*/
|
|
4426
6368
|
export interface ErrorClass<Self, S extends Top & {
|
|
@@ -4428,21 +6370,97 @@ export interface ErrorClass<Self, S extends Top & {
|
|
|
4428
6370
|
}, Inherited> extends ExtendableClass<Self, S, Inherited> {
|
|
4429
6371
|
}
|
|
4430
6372
|
/**
|
|
6373
|
+
* Creates a schema-backed error class that can be used as a typed,
|
|
6374
|
+
* yieldable error in Effect programs. Combines {@link Class} validation with
|
|
6375
|
+
* the `YieldableError` interface so instances can be yielded directly inside
|
|
6376
|
+
* `Effect.gen`.
|
|
6377
|
+
*
|
|
6378
|
+
* **Example** (Schema-backed error)
|
|
6379
|
+
*
|
|
6380
|
+
* ```ts
|
|
6381
|
+
* import { Effect, Schema } from "effect"
|
|
6382
|
+
*
|
|
6383
|
+
* class NotFound extends Schema.ErrorClass<NotFound>("NotFound")({
|
|
6384
|
+
* id: Schema.Number
|
|
6385
|
+
* }) {}
|
|
6386
|
+
*
|
|
6387
|
+
* const program = Effect.gen(function*() {
|
|
6388
|
+
* yield* new NotFound({ id: 1 })
|
|
6389
|
+
* })
|
|
6390
|
+
* ```
|
|
6391
|
+
*
|
|
4431
6392
|
* @category Constructors
|
|
4432
6393
|
* @since 4.0.0
|
|
4433
6394
|
*/
|
|
4434
6395
|
export declare const ErrorClass: {
|
|
4435
6396
|
/**
|
|
6397
|
+
* Creates a schema-backed error class that can be used as a typed,
|
|
6398
|
+
* yieldable error in Effect programs. Combines {@link Class} validation with
|
|
6399
|
+
* the `YieldableError` interface so instances can be yielded directly inside
|
|
6400
|
+
* `Effect.gen`.
|
|
6401
|
+
*
|
|
6402
|
+
* **Example** (Schema-backed error)
|
|
6403
|
+
*
|
|
6404
|
+
* ```ts
|
|
6405
|
+
* import { Effect, Schema } from "effect"
|
|
6406
|
+
*
|
|
6407
|
+
* class NotFound extends Schema.ErrorClass<NotFound>("NotFound")({
|
|
6408
|
+
* id: Schema.Number
|
|
6409
|
+
* }) {}
|
|
6410
|
+
*
|
|
6411
|
+
* const program = Effect.gen(function*() {
|
|
6412
|
+
* yield* new NotFound({ id: 1 })
|
|
6413
|
+
* })
|
|
6414
|
+
* ```
|
|
6415
|
+
*
|
|
4436
6416
|
* @category Constructors
|
|
4437
6417
|
* @since 4.0.0
|
|
4438
6418
|
*/
|
|
4439
6419
|
<Self, Brand = {}>(identifier: string): {
|
|
4440
6420
|
/**
|
|
6421
|
+
* Creates a schema-backed error class that can be used as a typed,
|
|
6422
|
+
* yieldable error in Effect programs. Combines {@link Class} validation with
|
|
6423
|
+
* the `YieldableError` interface so instances can be yielded directly inside
|
|
6424
|
+
* `Effect.gen`.
|
|
6425
|
+
*
|
|
6426
|
+
* **Example** (Schema-backed error)
|
|
6427
|
+
*
|
|
6428
|
+
* ```ts
|
|
6429
|
+
* import { Effect, Schema } from "effect"
|
|
6430
|
+
*
|
|
6431
|
+
* class NotFound extends Schema.ErrorClass<NotFound>("NotFound")({
|
|
6432
|
+
* id: Schema.Number
|
|
6433
|
+
* }) {}
|
|
6434
|
+
*
|
|
6435
|
+
* const program = Effect.gen(function*() {
|
|
6436
|
+
* yield* new NotFound({ id: 1 })
|
|
6437
|
+
* })
|
|
6438
|
+
* ```
|
|
6439
|
+
*
|
|
4441
6440
|
* @category Constructors
|
|
4442
6441
|
* @since 4.0.0
|
|
4443
6442
|
*/
|
|
4444
6443
|
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): ErrorClass<Self, Struct<Fields>, Cause_.YieldableError & Brand>;
|
|
4445
6444
|
/**
|
|
6445
|
+
* Creates a schema-backed error class that can be used as a typed,
|
|
6446
|
+
* yieldable error in Effect programs. Combines {@link Class} validation with
|
|
6447
|
+
* the `YieldableError` interface so instances can be yielded directly inside
|
|
6448
|
+
* `Effect.gen`.
|
|
6449
|
+
*
|
|
6450
|
+
* **Example** (Schema-backed error)
|
|
6451
|
+
*
|
|
6452
|
+
* ```ts
|
|
6453
|
+
* import { Effect, Schema } from "effect"
|
|
6454
|
+
*
|
|
6455
|
+
* class NotFound extends Schema.ErrorClass<NotFound>("NotFound")({
|
|
6456
|
+
* id: Schema.Number
|
|
6457
|
+
* }) {}
|
|
6458
|
+
*
|
|
6459
|
+
* const program = Effect.gen(function*() {
|
|
6460
|
+
* yield* new NotFound({ id: 1 })
|
|
6461
|
+
* })
|
|
6462
|
+
* ```
|
|
6463
|
+
*
|
|
4446
6464
|
* @category Constructors
|
|
4447
6465
|
* @since 4.0.0
|
|
4448
6466
|
*/
|
|
@@ -4450,21 +6468,93 @@ export declare const ErrorClass: {
|
|
|
4450
6468
|
};
|
|
4451
6469
|
};
|
|
4452
6470
|
/**
|
|
6471
|
+
* Like {@link ErrorClass} but automatically adds a `_tag` literal field. The
|
|
6472
|
+
* resulting class is both a schema-validated, yieldable error and a tagged
|
|
6473
|
+
* union member.
|
|
6474
|
+
*
|
|
6475
|
+
* **Example** (Tagged error class)
|
|
6476
|
+
*
|
|
6477
|
+
* ```ts
|
|
6478
|
+
* import { Effect, Schema } from "effect"
|
|
6479
|
+
*
|
|
6480
|
+
* class NotFound extends Schema.TaggedErrorClass<NotFound>()("NotFound", {
|
|
6481
|
+
* id: Schema.Number
|
|
6482
|
+
* }) {}
|
|
6483
|
+
*
|
|
6484
|
+
* const program = Effect.gen(function*() {
|
|
6485
|
+
* yield* new NotFound({ id: 42 })
|
|
6486
|
+
* })
|
|
6487
|
+
* ```
|
|
6488
|
+
*
|
|
4453
6489
|
* @category Constructors
|
|
4454
6490
|
* @since 4.0.0
|
|
4455
6491
|
*/
|
|
4456
6492
|
export declare const TaggedErrorClass: {
|
|
4457
6493
|
/**
|
|
6494
|
+
* Like {@link ErrorClass} but automatically adds a `_tag` literal field. The
|
|
6495
|
+
* resulting class is both a schema-validated, yieldable error and a tagged
|
|
6496
|
+
* union member.
|
|
6497
|
+
*
|
|
6498
|
+
* **Example** (Tagged error class)
|
|
6499
|
+
*
|
|
6500
|
+
* ```ts
|
|
6501
|
+
* import { Effect, Schema } from "effect"
|
|
6502
|
+
*
|
|
6503
|
+
* class NotFound extends Schema.TaggedErrorClass<NotFound>()("NotFound", {
|
|
6504
|
+
* id: Schema.Number
|
|
6505
|
+
* }) {}
|
|
6506
|
+
*
|
|
6507
|
+
* const program = Effect.gen(function*() {
|
|
6508
|
+
* yield* new NotFound({ id: 42 })
|
|
6509
|
+
* })
|
|
6510
|
+
* ```
|
|
6511
|
+
*
|
|
4458
6512
|
* @category Constructors
|
|
4459
6513
|
* @since 4.0.0
|
|
4460
6514
|
*/
|
|
4461
6515
|
<Self, Brand = {}>(identifier?: string): {
|
|
4462
6516
|
/**
|
|
6517
|
+
* Like {@link ErrorClass} but automatically adds a `_tag` literal field. The
|
|
6518
|
+
* resulting class is both a schema-validated, yieldable error and a tagged
|
|
6519
|
+
* union member.
|
|
6520
|
+
*
|
|
6521
|
+
* **Example** (Tagged error class)
|
|
6522
|
+
*
|
|
6523
|
+
* ```ts
|
|
6524
|
+
* import { Effect, Schema } from "effect"
|
|
6525
|
+
*
|
|
6526
|
+
* class NotFound extends Schema.TaggedErrorClass<NotFound>()("NotFound", {
|
|
6527
|
+
* id: Schema.Number
|
|
6528
|
+
* }) {}
|
|
6529
|
+
*
|
|
6530
|
+
* const program = Effect.gen(function*() {
|
|
6531
|
+
* yield* new NotFound({ id: 42 })
|
|
6532
|
+
* })
|
|
6533
|
+
* ```
|
|
6534
|
+
*
|
|
4463
6535
|
* @category Constructors
|
|
4464
6536
|
* @since 4.0.0
|
|
4465
6537
|
*/
|
|
4466
6538
|
<Tag extends string, const Fields extends Struct.Fields>(tag: Tag, fields: Fields, annotations?: Annotations.Declaration<Self, readonly [TaggedStruct<Tag, Fields>]>): ErrorClass<Self, TaggedStruct<Tag, Fields>, Cause_.YieldableError & Brand>;
|
|
4467
6539
|
/**
|
|
6540
|
+
* Like {@link ErrorClass} but automatically adds a `_tag` literal field. The
|
|
6541
|
+
* resulting class is both a schema-validated, yieldable error and a tagged
|
|
6542
|
+
* union member.
|
|
6543
|
+
*
|
|
6544
|
+
* **Example** (Tagged error class)
|
|
6545
|
+
*
|
|
6546
|
+
* ```ts
|
|
6547
|
+
* import { Effect, Schema } from "effect"
|
|
6548
|
+
*
|
|
6549
|
+
* class NotFound extends Schema.TaggedErrorClass<NotFound>()("NotFound", {
|
|
6550
|
+
* id: Schema.Number
|
|
6551
|
+
* }) {}
|
|
6552
|
+
*
|
|
6553
|
+
* const program = Effect.gen(function*() {
|
|
6554
|
+
* yield* new NotFound({ id: 42 })
|
|
6555
|
+
* })
|
|
6556
|
+
* ```
|
|
6557
|
+
*
|
|
4468
6558
|
* @category Constructors
|
|
4469
6559
|
* @since 4.0.0
|
|
4470
6560
|
*/
|
|
@@ -4476,16 +6566,43 @@ export declare const TaggedErrorClass: {
|
|
|
4476
6566
|
};
|
|
4477
6567
|
};
|
|
4478
6568
|
/**
|
|
6569
|
+
* A thunk that, given the `fast-check` module, returns an `Arbitrary<T>`.
|
|
6570
|
+
* Use this type when you need to defer instantiation of the arbitrary, for
|
|
6571
|
+
* example to support recursive schemas.
|
|
6572
|
+
*
|
|
4479
6573
|
* @category Arbitrary
|
|
4480
6574
|
* @since 4.0.0
|
|
4481
6575
|
*/
|
|
4482
6576
|
export type LazyArbitrary<T> = (fc: typeof FastCheck) => FastCheck.Arbitrary<T>;
|
|
4483
6577
|
/**
|
|
6578
|
+
* Derives a {@link LazyArbitrary} from a schema. The result is memoized so
|
|
6579
|
+
* repeated calls with the same schema are cheap.
|
|
6580
|
+
*
|
|
6581
|
+
* Prefer {@link toArbitrary} when you just need the arbitrary directly.
|
|
6582
|
+
*
|
|
4484
6583
|
* @category Arbitrary
|
|
4485
6584
|
* @since 4.0.0
|
|
4486
6585
|
*/
|
|
4487
6586
|
export declare function toArbitraryLazy<S extends Top>(schema: S): LazyArbitrary<S["Type"]>;
|
|
4488
6587
|
/**
|
|
6588
|
+
* Derives a `fast-check` `Arbitrary` from a schema for property-based
|
|
6589
|
+
* testing. The derived arbitrary generates values that satisfy the schema.
|
|
6590
|
+
*
|
|
6591
|
+
* **Example** (Generating arbitrary values)
|
|
6592
|
+
*
|
|
6593
|
+
* ```ts
|
|
6594
|
+
* import { Schema } from "effect"
|
|
6595
|
+
* import * as FastCheck from "fast-check"
|
|
6596
|
+
*
|
|
6597
|
+
* const PersonArb = Schema.toArbitrary(
|
|
6598
|
+
* Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
6599
|
+
* )
|
|
6600
|
+
*
|
|
6601
|
+
* // Sample a random value
|
|
6602
|
+
* const sample = FastCheck.sample(PersonArb, 1)[0]
|
|
6603
|
+
* console.log(typeof sample.name) // "string"
|
|
6604
|
+
* ```
|
|
6605
|
+
*
|
|
4489
6606
|
* @category Arbitrary
|
|
4490
6607
|
* @since 4.0.0
|
|
4491
6608
|
*/
|
|
@@ -4501,6 +6618,13 @@ export declare function toArbitrary<S extends Top>(schema: S): FastCheck.Arbitra
|
|
|
4501
6618
|
*/
|
|
4502
6619
|
export declare function overrideToFormatter<S extends Top>(toFormatter: () => Formatter<S["Type"]>): (self: S) => S["~rebuild.out"];
|
|
4503
6620
|
/**
|
|
6621
|
+
* Derives a string formatter function from a schema. The formatter converts
|
|
6622
|
+
* a value to its human-readable string representation, recursing into structs,
|
|
6623
|
+
* arrays, and unions.
|
|
6624
|
+
*
|
|
6625
|
+
* The optional `onBefore` hook lets you intercept specific AST nodes before
|
|
6626
|
+
* the default formatting logic runs.
|
|
6627
|
+
*
|
|
4504
6628
|
* @category Formatter
|
|
4505
6629
|
* @since 4.0.0
|
|
4506
6630
|
*/
|
|
@@ -4508,26 +6632,46 @@ export declare function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
4508
6632
|
readonly onBefore?: ((ast: AST.AST, recur: (ast: AST.AST) => Formatter<any>) => Formatter<any> | undefined) | undefined;
|
|
4509
6633
|
}): Formatter<T>;
|
|
4510
6634
|
/**
|
|
4511
|
-
*
|
|
4512
|
-
*
|
|
4513
|
-
*
|
|
4514
|
-
* the schema invariant.
|
|
6635
|
+
* Overrides the equivalence derivation for a schema by supplying a custom
|
|
6636
|
+
* `Equivalence`. Use this when the default structural equivalence derived by
|
|
6637
|
+
* {@link toEquivalence} is not appropriate for a type.
|
|
4515
6638
|
*
|
|
4516
6639
|
* @category Equivalence
|
|
4517
6640
|
* @since 4.0.0
|
|
4518
6641
|
*/
|
|
4519
6642
|
export declare function overrideToEquivalence<S extends Top>(toEquivalence: () => Equivalence.Equivalence<S["Type"]>): (self: S) => S["~rebuild.out"];
|
|
4520
6643
|
/**
|
|
6644
|
+
* Derives an `Equivalence` from a schema. Two values are considered equal when
|
|
6645
|
+
* every field (and nested field) compares equal according to the schema
|
|
6646
|
+
* structure.
|
|
6647
|
+
*
|
|
6648
|
+
* **Example** (Struct equivalence)
|
|
6649
|
+
*
|
|
6650
|
+
* ```ts
|
|
6651
|
+
* import { Schema } from "effect"
|
|
6652
|
+
*
|
|
6653
|
+
* const eq = Schema.toEquivalence(Schema.Struct({ id: Schema.Number, name: Schema.String }))
|
|
6654
|
+
*
|
|
6655
|
+
* console.log(eq({ id: 1, name: "Alice" }, { id: 1, name: "Alice" })) // true
|
|
6656
|
+
* console.log(eq({ id: 1, name: "Alice" }, { id: 2, name: "Alice" })) // false
|
|
6657
|
+
* ```
|
|
6658
|
+
*
|
|
4521
6659
|
* @category Equivalence
|
|
4522
6660
|
* @since 4.0.0
|
|
4523
6661
|
*/
|
|
4524
6662
|
export declare function toEquivalence<T>(schema: Schema<T>): Equivalence.Equivalence<T>;
|
|
4525
6663
|
/**
|
|
6664
|
+
* Derives an intermediate `SchemaRepresentation.Document` from a schema. This
|
|
6665
|
+
* document is used internally by {@link toJsonSchemaDocument} and related
|
|
6666
|
+
* functions to produce JSON Schema output.
|
|
6667
|
+
*
|
|
4526
6668
|
* @category Representation
|
|
4527
6669
|
* @since 4.0.0
|
|
4528
6670
|
*/
|
|
4529
6671
|
export declare function toRepresentation(schema: Top): SchemaRepresentation.Document;
|
|
4530
6672
|
/**
|
|
6673
|
+
* Options for {@link toJsonSchemaDocument}.
|
|
6674
|
+
*
|
|
4531
6675
|
* @since 4.0.0
|
|
4532
6676
|
*/
|
|
4533
6677
|
export interface ToJsonSchemaOptions {
|
|
@@ -4557,16 +6701,25 @@ export interface ToJsonSchemaOptions {
|
|
|
4557
6701
|
*/
|
|
4558
6702
|
export declare function toJsonSchemaDocument(schema: Top, options?: ToJsonSchemaOptions): JsonSchema.Document<"draft-2020-12">;
|
|
4559
6703
|
/**
|
|
6704
|
+
* Derives a canonical JSON codec from a schema. The encoded form is `unknown`
|
|
6705
|
+
* (any JSON-compatible value), decoded to the schema's `Type`.
|
|
6706
|
+
*
|
|
4560
6707
|
* @category Canonical Codecs
|
|
4561
6708
|
* @since 4.0.0
|
|
4562
6709
|
*/
|
|
4563
|
-
export declare function toCodecJson<T, E, RD, RE>(schema: Codec<T, E, RD, RE>): Codec<T,
|
|
6710
|
+
export declare function toCodecJson<T, E, RD, RE>(schema: Codec<T, E, RD, RE>): Codec<T, Json, RD, RE>;
|
|
4564
6711
|
/**
|
|
6712
|
+
* Derives an isomorphism codec from a schema. The encoded form is the
|
|
6713
|
+
* schema's `Iso` type — the intermediate representation used for round-tripping.
|
|
6714
|
+
*
|
|
4565
6715
|
* @category Canonical Codecs
|
|
4566
6716
|
* @since 4.0.0
|
|
4567
6717
|
*/
|
|
4568
6718
|
export declare function toCodecIso<S extends Top>(schema: S): Codec<S["Type"], S["Iso"]>;
|
|
4569
6719
|
/**
|
|
6720
|
+
* A {@link Tree} of `string | undefined` nodes. Leaf values are either a
|
|
6721
|
+
* string representation or `undefined` for opaque/declaration types.
|
|
6722
|
+
*
|
|
4570
6723
|
* @category Canonical Codecs
|
|
4571
6724
|
* @since 4.0.0
|
|
4572
6725
|
*/
|
|
@@ -4606,26 +6759,40 @@ type XmlEncoderOptions = {
|
|
|
4606
6759
|
readonly sortKeys?: boolean | undefined;
|
|
4607
6760
|
};
|
|
4608
6761
|
/**
|
|
6762
|
+
* Derives an XML encoder from a codec. Encodes a value to an XML string by
|
|
6763
|
+
* first converting it through {@link toCodecStringTree}, then serializing the
|
|
6764
|
+
* resulting tree to XML.
|
|
6765
|
+
*
|
|
4609
6766
|
* @category Canonical Codecs
|
|
4610
6767
|
* @since 4.0.0
|
|
4611
6768
|
*/
|
|
4612
6769
|
export declare function toEncoderXml<T, E, RD, RE>(codec: Codec<T, E, RD, RE>, options?: XmlEncoderOptions): (t: T) => Effect.Effect<string, SchemaError, RE>;
|
|
4613
6770
|
/**
|
|
6771
|
+
* Derives an `Iso` optic from a schema that isomorphically converts between
|
|
6772
|
+
* the schema's `Type` and its `Iso` (intermediate / serialized form).
|
|
6773
|
+
*
|
|
4614
6774
|
* @category Optic
|
|
4615
6775
|
* @since 4.0.0
|
|
4616
6776
|
*/
|
|
4617
6777
|
export declare function toIso<S extends Top>(schema: S): Optic_.Iso<S["Type"], S["Iso"]>;
|
|
4618
6778
|
/**
|
|
6779
|
+
* Returns an identity `Iso` over the schema's source (`Type`) side.
|
|
6780
|
+
*
|
|
4619
6781
|
* @category Optic
|
|
4620
6782
|
* @since 4.0.0
|
|
4621
6783
|
*/
|
|
4622
6784
|
export declare function toIsoSource<S extends Top>(_: S): Optic_.Iso<S["Type"], S["Type"]>;
|
|
4623
6785
|
/**
|
|
6786
|
+
* Returns an identity `Iso` over the schema's focus (`Iso`) side.
|
|
6787
|
+
*
|
|
4624
6788
|
* @category Optic
|
|
4625
6789
|
* @since 4.0.0
|
|
4626
6790
|
*/
|
|
4627
6791
|
export declare function toIsoFocus<S extends Top>(_: S): Optic_.Iso<S["Iso"], S["Iso"]>;
|
|
4628
6792
|
/**
|
|
6793
|
+
* The schema type returned by {@link overrideToCodecIso}. Carries a custom
|
|
6794
|
+
* `Iso` type parameter and exposes the original `schema`.
|
|
6795
|
+
*
|
|
4629
6796
|
* @category Optic
|
|
4630
6797
|
* @since 4.0.0
|
|
4631
6798
|
*/
|
|
@@ -4634,10 +6801,11 @@ export interface overrideToCodecIso<S extends Top, Iso> extends Bottom<S["Type"]
|
|
|
4634
6801
|
readonly schema: S;
|
|
4635
6802
|
}
|
|
4636
6803
|
/**
|
|
4637
|
-
*
|
|
4638
|
-
*
|
|
4639
|
-
*
|
|
4640
|
-
* the
|
|
6804
|
+
* Overrides the ISO codec derivation for a schema by providing a target codec
|
|
6805
|
+
* and explicit `decode`/`encode` getters. The resulting schema carries a
|
|
6806
|
+
* custom `Iso` type, which changes the schema's type parameter — use
|
|
6807
|
+
* {@link overrideToCodecIso} when the default ISO transformation is not
|
|
6808
|
+
* appropriate.
|
|
4641
6809
|
*
|
|
4642
6810
|
* @category Optic
|
|
4643
6811
|
* @since 4.0.0
|
|
@@ -4647,6 +6815,10 @@ export declare function overrideToCodecIso<S extends Top, Iso>(to: Codec<Iso>, t
|
|
|
4647
6815
|
readonly encode: Getter.Getter<Iso, S["Type"]>;
|
|
4648
6816
|
}): (schema: S) => overrideToCodecIso<S, Iso>;
|
|
4649
6817
|
/**
|
|
6818
|
+
* Derives a JSON Patch differ from a codec. Serializes values to JSON (via
|
|
6819
|
+
* {@link toCodecJson}), computes RFC 6902 JSON Patch operations between old
|
|
6820
|
+
* and new values, and can apply patches back to the typed value.
|
|
6821
|
+
*
|
|
4650
6822
|
* @category JsonPatch
|
|
4651
6823
|
* @since 4.0.0
|
|
4652
6824
|
*/
|
|
@@ -4657,6 +6829,9 @@ export declare function toDifferJsonPatch<T, E>(schema: Codec<T, E>): Differ<T,
|
|
|
4657
6829
|
*/
|
|
4658
6830
|
export type Tree<Node> = Node | TreeRecord<Node> | ReadonlyArray<Tree<Node>>;
|
|
4659
6831
|
/**
|
|
6832
|
+
* A record node in a {@link Tree}: an object mapping string keys to child
|
|
6833
|
+
* `Tree` nodes.
|
|
6834
|
+
*
|
|
4660
6835
|
* @category Tree
|
|
4661
6836
|
* @since 4.0.0
|
|
4662
6837
|
*/
|
|
@@ -4664,22 +6839,35 @@ export interface TreeRecord<A> {
|
|
|
4664
6839
|
readonly [x: string]: Tree<A>;
|
|
4665
6840
|
}
|
|
4666
6841
|
/**
|
|
6842
|
+
* Creates a recursive schema for a {@link Tree} of values described by `node`.
|
|
6843
|
+
* The resulting schema accepts a single node value, an array of trees, or an
|
|
6844
|
+
* object whose values are trees.
|
|
6845
|
+
*
|
|
4667
6846
|
* @category Tree
|
|
4668
6847
|
* @since 4.0.0
|
|
4669
6848
|
*/
|
|
4670
6849
|
export declare function Tree<S extends Top>(node: S): Union<readonly [S, $Array<suspend<Codec<Tree<S["Type"]>, Tree<S["Encoded"]>, S["DecodingServices"], S["EncodingServices"]>>>, $Record<String, suspend<Codec<Tree<S["Type"]>, Tree<S["Encoded"]>, S["DecodingServices"], S["EncodingServices"]>>>]>;
|
|
4671
6850
|
/**
|
|
6851
|
+
* Recursive TypeScript type for any valid immutable JSON value: `null`,
|
|
6852
|
+
* `number`, `boolean`, `string`, a readonly array of `Json` values, or a
|
|
6853
|
+
* readonly record of `string → Json`. For the corresponding schema, see the
|
|
6854
|
+
* {@link Json} const.
|
|
6855
|
+
*
|
|
4672
6856
|
* @category JSON
|
|
4673
6857
|
* @since 4.0.0
|
|
4674
6858
|
*/
|
|
4675
6859
|
export type Json = null | number | boolean | string | JsonArray | JsonObject;
|
|
4676
6860
|
/**
|
|
6861
|
+
* A readonly array of {@link Json} values.
|
|
6862
|
+
*
|
|
4677
6863
|
* @category JSON
|
|
4678
6864
|
* @since 4.0.0
|
|
4679
6865
|
*/
|
|
4680
6866
|
export interface JsonArray extends ReadonlyArray<Json> {
|
|
4681
6867
|
}
|
|
4682
6868
|
/**
|
|
6869
|
+
* A readonly record whose values are {@link Json} values.
|
|
6870
|
+
*
|
|
4683
6871
|
* @category JSON
|
|
4684
6872
|
* @since 4.0.0
|
|
4685
6873
|
*/
|
|
@@ -4687,6 +6875,17 @@ export interface JsonObject {
|
|
|
4687
6875
|
readonly [x: string]: Json;
|
|
4688
6876
|
}
|
|
4689
6877
|
/**
|
|
6878
|
+
* Schema that accepts and validates any immutable JSON-compatible value.
|
|
6879
|
+
*
|
|
6880
|
+
* **Example** (Validating a JSON value)
|
|
6881
|
+
*
|
|
6882
|
+
* ```ts
|
|
6883
|
+
* import { Schema } from "effect"
|
|
6884
|
+
*
|
|
6885
|
+
* const result = Schema.decodeUnknownOption(Schema.Json)({ key: [1, true, null] })
|
|
6886
|
+
* console.log(result._tag) // "Some"
|
|
6887
|
+
* ```
|
|
6888
|
+
*
|
|
4690
6889
|
* @category JSON
|
|
4691
6890
|
* @since 4.0.0
|
|
4692
6891
|
*/
|
|
@@ -4697,12 +6896,16 @@ export declare const Json: Codec<Json>;
|
|
|
4697
6896
|
*/
|
|
4698
6897
|
export type MutableJson = null | number | boolean | string | MutableJsonArray | MutableJsonObject;
|
|
4699
6898
|
/**
|
|
6899
|
+
* A mutable array of {@link MutableJson} values.
|
|
6900
|
+
*
|
|
4700
6901
|
* @category JSON
|
|
4701
6902
|
* @since 4.0.0
|
|
4702
6903
|
*/
|
|
4703
6904
|
export interface MutableJsonArray extends Array<MutableJson> {
|
|
4704
6905
|
}
|
|
4705
6906
|
/**
|
|
6907
|
+
* A mutable record whose values are {@link MutableJson} values.
|
|
6908
|
+
*
|
|
4706
6909
|
* @category JSON
|
|
4707
6910
|
* @since 4.0.0
|
|
4708
6911
|
*/
|
|
@@ -4710,6 +6913,9 @@ export interface MutableJsonObject {
|
|
|
4710
6913
|
[x: string]: MutableJson;
|
|
4711
6914
|
}
|
|
4712
6915
|
/**
|
|
6916
|
+
* Schema that accepts any mutable JSON-compatible value. See {@link Json} for
|
|
6917
|
+
* the immutable variant.
|
|
6918
|
+
*
|
|
4713
6919
|
* @category JSON
|
|
4714
6920
|
* @since 4.0.0
|
|
4715
6921
|
*/
|
|
@@ -4722,6 +6928,13 @@ export declare const MutableJson: Codec<MutableJson>;
|
|
|
4722
6928
|
*/
|
|
4723
6929
|
export declare function resolveInto<S extends Top>(schema: S): S["~annotate.in"] | undefined;
|
|
4724
6930
|
/**
|
|
6931
|
+
* The `Annotations` namespace groups all annotation interfaces used to attach
|
|
6932
|
+
* metadata to schemas. Annotations control documentation, validation messages,
|
|
6933
|
+
* JSON Schema generation, equivalence, arbitrary generation, and more.
|
|
6934
|
+
*
|
|
6935
|
+
* Use {@link resolveInto} to read the annotations attached to a schema at
|
|
6936
|
+
* runtime.
|
|
6937
|
+
*
|
|
4725
6938
|
* @since 4.0.0
|
|
4726
6939
|
*/
|
|
4727
6940
|
export declare namespace Annotations {
|
|
@@ -4770,6 +6983,9 @@ export declare namespace Annotations {
|
|
|
4770
6983
|
readonly [x: string]: unknown;
|
|
4771
6984
|
}
|
|
4772
6985
|
/**
|
|
6986
|
+
* Annotations shared by all schema nodes. These map to common JSON Schema /
|
|
6987
|
+
* OpenAPI fields: `title`, `description`, `format`, etc.
|
|
6988
|
+
*
|
|
4773
6989
|
* @since 4.0.0
|
|
4774
6990
|
*/
|
|
4775
6991
|
interface Augment extends Annotations {
|
|
@@ -4784,6 +7000,8 @@ export declare namespace Annotations {
|
|
|
4784
7000
|
readonly contentMediaType?: string | undefined;
|
|
4785
7001
|
}
|
|
4786
7002
|
/**
|
|
7003
|
+
* Extends {@link Augment} with type-parametric `default` and `examples` fields.
|
|
7004
|
+
*
|
|
4787
7005
|
* @since 4.0.0
|
|
4788
7006
|
*/
|
|
4789
7007
|
interface Documentation<T> extends Augment {
|
|
@@ -4791,6 +7009,10 @@ export declare namespace Annotations {
|
|
|
4791
7009
|
readonly examples?: ReadonlyArray<T> | undefined;
|
|
4792
7010
|
}
|
|
4793
7011
|
/**
|
|
7012
|
+
* Annotations for struct property schemas. Extends {@link Documentation}
|
|
7013
|
+
* with an optional `messageMissingKey` to override the error message when
|
|
7014
|
+
* the property key is absent during decoding.
|
|
7015
|
+
*
|
|
4794
7016
|
* @category Model
|
|
4795
7017
|
* @since 4.0.0
|
|
4796
7018
|
*/
|
|
@@ -4801,6 +7023,11 @@ export declare namespace Annotations {
|
|
|
4801
7023
|
readonly messageMissingKey?: string | undefined;
|
|
4802
7024
|
}
|
|
4803
7025
|
/**
|
|
7026
|
+
* Base annotations shared by all composite schema nodes. Extends
|
|
7027
|
+
* {@link Documentation} with error messages, branding, parse options, and
|
|
7028
|
+
* arbitrary generation hooks. {@link Declaration} and other annotation
|
|
7029
|
+
* interfaces build on top of this.
|
|
7030
|
+
*
|
|
4804
7031
|
* @category Model
|
|
4805
7032
|
* @since 4.0.0
|
|
4806
7033
|
*/
|
|
@@ -4843,6 +7070,12 @@ export declare namespace Annotations {
|
|
|
4843
7070
|
};
|
|
4844
7071
|
}
|
|
4845
7072
|
/**
|
|
7073
|
+
* Full annotation set for `Declaration` schema nodes — used when defining
|
|
7074
|
+
* custom, opaque schema types via `Schema.declare`. Extends {@link Bottom}
|
|
7075
|
+
* with optional codec, arbitrary, equivalence, and formatter hooks so that
|
|
7076
|
+
* derived capabilities (JSON encoding, property testing, etc.) can be
|
|
7077
|
+
* provided for the custom type.
|
|
7078
|
+
*
|
|
4846
7079
|
* @category Model
|
|
4847
7080
|
* @since 4.0.0
|
|
4848
7081
|
*/
|
|
@@ -4864,10 +7097,9 @@ export declare namespace Annotations {
|
|
|
4864
7097
|
} | undefined;
|
|
4865
7098
|
}
|
|
4866
7099
|
/**
|
|
4867
|
-
*
|
|
4868
|
-
*
|
|
4869
|
-
*
|
|
4870
|
-
* invariant
|
|
7100
|
+
* Annotations for filter schema nodes (created via `Schema.filter`). Extends
|
|
7101
|
+
* {@link Augment} with an optional error message, identifier, and metadata.
|
|
7102
|
+
* Filters are intentionally non-parametric to keep them covariant.
|
|
4871
7103
|
*
|
|
4872
7104
|
* @category Model
|
|
4873
7105
|
* @since 4.0.0
|