effect 4.0.0-beta.74 → 4.0.0-beta.76
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 +729 -611
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +273 -213
- package/dist/Array.js.map +1 -1
- package/dist/BigDecimal.d.ts +37 -30
- package/dist/BigDecimal.d.ts.map +1 -1
- package/dist/BigDecimal.js +19 -16
- package/dist/BigDecimal.js.map +1 -1
- package/dist/BigInt.d.ts +34 -40
- package/dist/BigInt.d.ts.map +1 -1
- package/dist/BigInt.js +16 -16
- package/dist/BigInt.js.map +1 -1
- package/dist/Boolean.d.ts +8 -8
- package/dist/Boolean.js +4 -4
- package/dist/Brand.d.ts +13 -11
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +10 -8
- package/dist/Brand.js.map +1 -1
- package/dist/Cause.d.ts +21 -23
- package/dist/Cause.d.ts.map +1 -1
- package/dist/Cause.js +21 -23
- package/dist/Cause.js.map +1 -1
- package/dist/Channel.d.ts +219 -9
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +83 -3
- package/dist/Channel.js.map +1 -1
- package/dist/ChannelSchema.d.ts +11 -11
- package/dist/ChannelSchema.js +5 -5
- package/dist/Chunk.d.ts +69 -16
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js +43 -8
- package/dist/Chunk.js.map +1 -1
- package/dist/Clock.d.ts +3 -3
- package/dist/Clock.js +3 -3
- package/dist/Combiner.d.ts +9 -13
- package/dist/Combiner.d.ts.map +1 -1
- package/dist/Combiner.js +9 -13
- package/dist/Combiner.js.map +1 -1
- package/dist/Config.d.ts +49 -56
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +40 -43
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts +34 -44
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +24 -32
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Console.d.ts +2 -2
- package/dist/Console.js +2 -2
- package/dist/Context.d.ts +60 -72
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +28 -32
- package/dist/Context.js.map +1 -1
- package/dist/Cron.d.ts +2 -2
- package/dist/Cron.js +2 -2
- package/dist/Crypto.d.ts +4 -4
- package/dist/Crypto.js +4 -4
- package/dist/Data.d.ts +21 -15
- package/dist/Data.d.ts.map +1 -1
- package/dist/Data.js +7 -7
- package/dist/Data.js.map +1 -1
- package/dist/DateTime.d.ts +35 -16
- package/dist/DateTime.d.ts.map +1 -1
- package/dist/DateTime.js +35 -8
- package/dist/DateTime.js.map +1 -1
- package/dist/Deferred.d.ts +24 -15
- package/dist/Deferred.d.ts.map +1 -1
- package/dist/Deferred.js +8 -5
- package/dist/Deferred.js.map +1 -1
- package/dist/Duration.d.ts +44 -31
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +22 -11
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +516 -416
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +234 -174
- package/dist/Effect.js.map +1 -1
- package/dist/Encoding.d.ts +5 -0
- package/dist/Encoding.d.ts.map +1 -1
- package/dist/Encoding.js +5 -0
- package/dist/Encoding.js.map +1 -1
- package/dist/Equal.d.ts +26 -39
- package/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +10 -17
- package/dist/Equal.js.map +1 -1
- package/dist/Equivalence.d.ts +71 -99
- package/dist/Equivalence.d.ts.map +1 -1
- package/dist/Equivalence.js +53 -73
- package/dist/Equivalence.js.map +1 -1
- package/dist/ErrorReporter.d.ts +1 -1
- package/dist/ErrorReporter.js +1 -1
- package/dist/Exit.d.ts +79 -96
- package/dist/Exit.d.ts.map +1 -1
- package/dist/Exit.js +57 -64
- package/dist/Exit.js.map +1 -1
- package/dist/Fiber.d.ts +8 -6
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Fiber.js +8 -6
- package/dist/Fiber.js.map +1 -1
- package/dist/FiberHandle.d.ts +25 -0
- package/dist/FiberHandle.d.ts.map +1 -1
- package/dist/FiberHandle.js +15 -0
- package/dist/FiberHandle.js.map +1 -1
- package/dist/FiberMap.d.ts +35 -0
- package/dist/FiberMap.d.ts.map +1 -1
- package/dist/FiberMap.js +15 -0
- package/dist/FiberMap.js.map +1 -1
- package/dist/FiberSet.d.ts +20 -0
- package/dist/FiberSet.d.ts.map +1 -1
- package/dist/FiberSet.js +10 -0
- package/dist/FiberSet.js.map +1 -1
- package/dist/Filter.d.ts +4 -4
- package/dist/Filter.js +4 -4
- package/dist/Formatter.d.ts +14 -19
- package/dist/Formatter.d.ts.map +1 -1
- package/dist/Formatter.js +14 -19
- package/dist/Formatter.js.map +1 -1
- package/dist/Function.d.ts +15 -16
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +9 -10
- package/dist/Function.js.map +1 -1
- package/dist/Graph.d.ts +2 -2
- package/dist/Graph.js +2 -2
- package/dist/HKT.d.ts +2 -2
- package/dist/Hash.d.ts +2 -1
- package/dist/Hash.d.ts.map +1 -1
- package/dist/Hash.js +2 -1
- package/dist/Hash.js.map +1 -1
- package/dist/HashMap.d.ts +15 -0
- package/dist/HashMap.d.ts.map +1 -1
- package/dist/HashMap.js +5 -0
- package/dist/HashMap.js.map +1 -1
- package/dist/HashRing.d.ts +9 -9
- package/dist/HashRing.js +3 -3
- package/dist/Iterable.d.ts +24 -12
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +16 -6
- package/dist/Iterable.js.map +1 -1
- package/dist/JsonPatch.d.ts +2 -3
- package/dist/JsonPatch.d.ts.map +1 -1
- package/dist/JsonPatch.js +2 -3
- package/dist/JsonPatch.js.map +1 -1
- package/dist/JsonPointer.d.ts +2 -6
- package/dist/JsonPointer.d.ts.map +1 -1
- package/dist/JsonPointer.js +2 -6
- package/dist/JsonPointer.js.map +1 -1
- package/dist/JsonSchema.d.ts +17 -13
- package/dist/JsonSchema.d.ts.map +1 -1
- package/dist/JsonSchema.js +17 -13
- package/dist/JsonSchema.js.map +1 -1
- package/dist/Latch.d.ts +4 -3
- package/dist/Latch.d.ts.map +1 -1
- package/dist/Latch.js +4 -3
- package/dist/Latch.js.map +1 -1
- package/dist/Layer.d.ts +92 -114
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +38 -46
- package/dist/Layer.js.map +1 -1
- package/dist/Logger.d.ts +11 -14
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +11 -14
- package/dist/Logger.js.map +1 -1
- package/dist/Match.d.ts +2 -2
- package/dist/Match.js +2 -2
- package/dist/Metric.d.ts +89 -109
- package/dist/Metric.d.ts.map +1 -1
- package/dist/Metric.js +51 -61
- package/dist/Metric.js.map +1 -1
- package/dist/MutableHashMap.d.ts +21 -12
- package/dist/MutableHashMap.d.ts.map +1 -1
- package/dist/MutableHashMap.js +7 -4
- package/dist/MutableHashMap.js.map +1 -1
- package/dist/MutableList.d.ts +15 -0
- package/dist/MutableList.d.ts.map +1 -1
- package/dist/MutableList.js +15 -0
- package/dist/MutableList.js.map +1 -1
- package/dist/MutableRef.d.ts +56 -42
- package/dist/MutableRef.d.ts.map +1 -1
- package/dist/MutableRef.js +28 -22
- package/dist/MutableRef.js.map +1 -1
- package/dist/Newtype.d.ts +10 -7
- package/dist/Newtype.d.ts.map +1 -1
- package/dist/Newtype.js +10 -7
- package/dist/Newtype.js.map +1 -1
- package/dist/Number.d.ts +23 -11
- package/dist/Number.d.ts.map +1 -1
- package/dist/Number.js +9 -5
- package/dist/Number.js.map +1 -1
- package/dist/Optic.d.ts +16 -16
- package/dist/Optic.d.ts.map +1 -1
- package/dist/Optic.js +10 -9
- package/dist/Optic.js.map +1 -1
- package/dist/Option.d.ts +196 -168
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +96 -79
- package/dist/Option.js.map +1 -1
- package/dist/Order.d.ts +118 -179
- package/dist/Order.d.ts.map +1 -1
- package/dist/Order.js +92 -144
- package/dist/Order.js.map +1 -1
- package/dist/PartitionedSemaphore.d.ts +14 -14
- package/dist/PartitionedSemaphore.js +6 -6
- package/dist/Path.d.ts +2 -2
- package/dist/Path.js +2 -2
- package/dist/Pipeable.d.ts +2 -2
- package/dist/Pipeable.js +2 -2
- package/dist/PlatformError.d.ts +4 -4
- package/dist/PlatformError.js +4 -4
- package/dist/Pool.d.ts +7 -11
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +3 -5
- package/dist/Pool.js.map +1 -1
- package/dist/Predicate.d.ts +274 -263
- package/dist/Predicate.d.ts.map +1 -1
- package/dist/Predicate.js +128 -123
- package/dist/Predicate.js.map +1 -1
- package/dist/PubSub.d.ts +24 -14
- package/dist/PubSub.d.ts.map +1 -1
- package/dist/PubSub.js +16 -6
- package/dist/PubSub.js.map +1 -1
- package/dist/Pull.d.ts +4 -4
- package/dist/Pull.js +4 -4
- package/dist/Queue.d.ts +46 -7
- package/dist/Queue.d.ts.map +1 -1
- package/dist/Queue.js +46 -7
- package/dist/Queue.js.map +1 -1
- package/dist/RcRef.d.ts +0 -4
- package/dist/RcRef.d.ts.map +1 -1
- package/dist/RcRef.js.map +1 -1
- package/dist/Redactable.d.ts +2 -2
- package/dist/Redactable.js +2 -2
- package/dist/Redacted.d.ts +3 -3
- package/dist/Redacted.js +3 -3
- package/dist/Reducer.d.ts +2 -3
- package/dist/Reducer.d.ts.map +1 -1
- package/dist/Reducer.js +2 -3
- package/dist/Reducer.js.map +1 -1
- package/dist/Ref.d.ts +17 -16
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +15 -14
- package/dist/Ref.js.map +1 -1
- package/dist/References.d.ts +4 -4
- package/dist/References.js +4 -4
- package/dist/Request.d.ts +18 -18
- package/dist/Request.js +6 -6
- package/dist/Resource.d.ts +2 -2
- package/dist/Resource.js +2 -2
- package/dist/Result.d.ts +77 -33
- package/dist/Result.d.ts.map +1 -1
- package/dist/Result.js +42 -19
- package/dist/Result.js.map +1 -1
- package/dist/Runtime.d.ts +11 -8
- package/dist/Runtime.d.ts.map +1 -1
- package/dist/Runtime.js +11 -8
- package/dist/Runtime.js.map +1 -1
- package/dist/Schedule.d.ts +107 -45
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +41 -29
- package/dist/Schedule.js.map +1 -1
- package/dist/Scheduler.d.ts +6 -4
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +6 -4
- package/dist/Scheduler.js.map +1 -1
- package/dist/Schema.d.ts +545 -411
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +662 -500
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +42 -21
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +81 -59
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaGetter.d.ts +126 -106
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +121 -101
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaIssue.d.ts +37 -39
- package/dist/SchemaIssue.d.ts.map +1 -1
- package/dist/SchemaIssue.js +16 -17
- package/dist/SchemaIssue.js.map +1 -1
- package/dist/SchemaParser.d.ts +72 -153
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +72 -145
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +40 -22
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +38 -27
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +169 -145
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +240 -177
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/SchemaUtils.js +2 -2
- package/dist/SchemaUtils.js.map +1 -1
- package/dist/Scope.d.ts +15 -0
- package/dist/Scope.d.ts.map +1 -1
- package/dist/Scope.js +15 -0
- package/dist/Scope.js.map +1 -1
- package/dist/ScopedCache.d.ts +1 -1
- package/dist/ScopedCache.js +1 -1
- package/dist/ScopedRef.d.ts +14 -18
- package/dist/ScopedRef.d.ts.map +1 -1
- package/dist/ScopedRef.js +6 -8
- package/dist/ScopedRef.js.map +1 -1
- package/dist/Semaphore.d.ts +9 -9
- package/dist/Semaphore.js +3 -3
- package/dist/Sink.d.ts +13 -13
- package/dist/Sink.d.ts.map +1 -1
- package/dist/Sink.js +9 -9
- package/dist/Sink.js.map +1 -1
- package/dist/Stdio.d.ts +4 -5
- package/dist/Stdio.d.ts.map +1 -1
- package/dist/Stdio.js +4 -5
- package/dist/Stdio.js.map +1 -1
- package/dist/Stream.d.ts +321 -44
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +137 -22
- package/dist/Stream.js.map +1 -1
- package/dist/String.d.ts +6 -9
- package/dist/String.d.ts.map +1 -1
- package/dist/String.js +2 -3
- package/dist/String.js.map +1 -1
- package/dist/Struct.d.ts +15 -13
- package/dist/Struct.d.ts.map +1 -1
- package/dist/Struct.js +11 -9
- package/dist/Struct.js.map +1 -1
- package/dist/SubscriptionRef.d.ts +24 -19
- package/dist/SubscriptionRef.d.ts.map +1 -1
- package/dist/SubscriptionRef.js +12 -7
- package/dist/SubscriptionRef.js.map +1 -1
- package/dist/SynchronizedRef.d.ts +88 -63
- package/dist/SynchronizedRef.d.ts.map +1 -1
- package/dist/SynchronizedRef.js +32 -23
- package/dist/SynchronizedRef.js.map +1 -1
- package/dist/Tracer.d.ts +4 -4
- package/dist/Tracer.js +4 -4
- package/dist/Trie.d.ts +15 -0
- package/dist/Trie.d.ts.map +1 -1
- package/dist/Trie.js +5 -0
- package/dist/Trie.js.map +1 -1
- package/dist/Tuple.d.ts +25 -19
- package/dist/Tuple.d.ts.map +1 -1
- package/dist/Tuple.js +17 -13
- package/dist/Tuple.js.map +1 -1
- package/dist/TxReentrantLock.d.ts +6 -3
- package/dist/TxReentrantLock.d.ts.map +1 -1
- package/dist/TxReentrantLock.js +2 -1
- package/dist/TxReentrantLock.js.map +1 -1
- package/dist/TxRef.d.ts +16 -16
- package/dist/TxRef.js +8 -8
- package/dist/TxSubscriptionRef.d.ts +43 -27
- package/dist/TxSubscriptionRef.d.ts.map +1 -1
- package/dist/TxSubscriptionRef.js +19 -13
- package/dist/TxSubscriptionRef.js.map +1 -1
- package/dist/Types.d.ts +12 -38
- package/dist/Types.d.ts.map +1 -1
- package/dist/Types.js +0 -2
- package/dist/UndefinedOr.d.ts +15 -14
- package/dist/UndefinedOr.d.ts.map +1 -1
- package/dist/UndefinedOr.js +11 -10
- package/dist/UndefinedOr.js.map +1 -1
- package/dist/Unify.d.ts +2 -2
- package/dist/internal/schema/annotations.js.map +1 -1
- package/dist/internal/schema/arbitrary.js +9 -9
- package/dist/internal/schema/arbitrary.js.map +1 -1
- package/dist/internal/schema/equivalence.js +9 -9
- package/dist/internal/schema/equivalence.js.map +1 -1
- package/dist/internal/schema/representation.js +15 -14
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.js +11 -11
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +10 -10
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js +9 -9
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/unstable/ai/AiError.d.ts +4 -2
- package/dist/unstable/ai/AiError.d.ts.map +1 -1
- package/dist/unstable/ai/AiError.js +4 -2
- package/dist/unstable/ai/AiError.js.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +17 -20
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.js +36 -39
- package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +4 -5
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js +4 -5
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/EmbeddingModel.d.ts +4 -4
- package/dist/unstable/ai/EmbeddingModel.js +4 -4
- package/dist/unstable/ai/IdGenerator.d.ts +2 -3
- package/dist/unstable/ai/IdGenerator.d.ts.map +1 -1
- package/dist/unstable/ai/IdGenerator.js +2 -3
- package/dist/unstable/ai/IdGenerator.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +3 -2
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +5 -4
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +14 -12
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +20 -18
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +11 -4
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +8 -5
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +20 -18
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.js +45 -43
- package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts +2 -2
- package/dist/unstable/ai/Prompt.js +3 -3
- package/dist/unstable/ai/Prompt.js.map +1 -1
- package/dist/unstable/ai/ResponseIdTracker.d.ts +3 -2
- package/dist/unstable/ai/ResponseIdTracker.d.ts.map +1 -1
- package/dist/unstable/ai/ResponseIdTracker.js +3 -2
- package/dist/unstable/ai/ResponseIdTracker.js.map +1 -1
- package/dist/unstable/ai/Telemetry.d.ts +21 -6
- package/dist/unstable/ai/Telemetry.d.ts.map +1 -1
- package/dist/unstable/ai/Telemetry.js +7 -2
- package/dist/unstable/ai/Telemetry.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +7 -6
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +8 -7
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/ai/Toolkit.d.ts +2 -2
- package/dist/unstable/ai/Toolkit.js +2 -2
- package/dist/unstable/cli/CliError.js +1 -1
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +37 -16
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +15 -8
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/Completions.d.ts +1 -1
- package/dist/unstable/cli/Completions.js +1 -1
- package/dist/unstable/cli/Flag.d.ts +7 -6
- package/dist/unstable/cli/Flag.d.ts.map +1 -1
- package/dist/unstable/cli/Flag.js +7 -6
- package/dist/unstable/cli/Flag.js.map +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts +6 -1
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
- package/dist/unstable/cli/GlobalFlag.js +7 -2
- package/dist/unstable/cli/GlobalFlag.js.map +1 -1
- package/dist/unstable/cli/Param.d.ts +3 -3
- package/dist/unstable/cli/Param.d.ts.map +1 -1
- package/dist/unstable/cli/Param.js +13 -10
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/Primitive.d.ts +3 -2
- package/dist/unstable/cli/Primitive.d.ts.map +1 -1
- package/dist/unstable/cli/Primitive.js +3 -2
- package/dist/unstable/cli/Primitive.js.map +1 -1
- package/dist/unstable/cluster/ClusterCron.d.ts +1 -2
- package/dist/unstable/cluster/ClusterCron.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterCron.js.map +1 -1
- package/dist/unstable/cluster/ClusterError.js +2 -2
- package/dist/unstable/cluster/ClusterError.js.map +1 -1
- package/dist/unstable/cluster/ClusterMetrics.d.ts +5 -0
- package/dist/unstable/cluster/ClusterMetrics.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMetrics.js +5 -0
- package/dist/unstable/cluster/ClusterMetrics.js.map +1 -1
- package/dist/unstable/cluster/ClusterSchema.d.ts +3 -3
- package/dist/unstable/cluster/ClusterSchema.js +3 -3
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +15 -15
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/EntityResource.d.ts +10 -0
- package/dist/unstable/cluster/EntityResource.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityResource.js +10 -0
- package/dist/unstable/cluster/EntityResource.js.map +1 -1
- package/dist/unstable/cluster/Envelope.d.ts +2 -2
- package/dist/unstable/cluster/Envelope.d.ts.map +1 -1
- package/dist/unstable/cluster/Envelope.js +2 -2
- package/dist/unstable/cluster/Envelope.js.map +1 -1
- package/dist/unstable/cluster/Reply.d.ts +2 -2
- package/dist/unstable/cluster/Reply.d.ts.map +1 -1
- package/dist/unstable/cluster/Reply.js +13 -13
- package/dist/unstable/cluster/Reply.js.map +1 -1
- package/dist/unstable/cluster/RunnerHealth.d.ts +2 -1
- package/dist/unstable/cluster/RunnerHealth.d.ts.map +1 -1
- package/dist/unstable/cluster/RunnerHealth.js +2 -1
- package/dist/unstable/cluster/RunnerHealth.js.map +1 -1
- package/dist/unstable/cluster/RunnerServer.d.ts +2 -2
- package/dist/unstable/cluster/RunnerServer.js +2 -2
- package/dist/unstable/cluster/Runners.d.ts +3 -3
- package/dist/unstable/cluster/Runners.js +3 -3
- package/dist/unstable/cluster/ShardId.js +3 -3
- package/dist/unstable/cluster/ShardId.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts +3 -3
- package/dist/unstable/cluster/Sharding.js +3 -3
- package/dist/unstable/cluster/ShardingConfig.d.ts +4 -4
- package/dist/unstable/cluster/ShardingConfig.js +4 -4
- package/dist/unstable/cluster/Snowflake.d.ts +1 -1
- package/dist/unstable/cluster/Snowflake.js +3 -3
- package/dist/unstable/cluster/Snowflake.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +2 -2
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/devtools/DevToolsSchema.js +5 -1
- package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
- package/dist/unstable/encoding/Msgpack.d.ts +2 -2
- package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
- package/dist/unstable/encoding/Msgpack.js +5 -5
- package/dist/unstable/encoding/Msgpack.js.map +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +5 -0
- package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
- package/dist/unstable/encoding/Ndjson.js +5 -0
- package/dist/unstable/encoding/Ndjson.js.map +1 -1
- package/dist/unstable/encoding/Sse.d.ts +2 -2
- package/dist/unstable/encoding/Sse.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.js +2 -2
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/eventlog/EventGroup.d.ts +2 -1
- package/dist/unstable/eventlog/EventGroup.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventGroup.js +2 -1
- package/dist/unstable/eventlog/EventGroup.js.map +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +10 -0
- package/dist/unstable/eventlog/EventJournal.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventJournal.js +10 -0
- package/dist/unstable/eventlog/EventJournal.js.map +1 -1
- package/dist/unstable/eventlog/EventLog.d.ts +3 -3
- package/dist/unstable/eventlog/EventLog.js +3 -3
- package/dist/unstable/eventlog/EventLogServerEncrypted.d.ts +2 -3
- package/dist/unstable/eventlog/EventLogServerEncrypted.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogServerEncrypted.js +2 -3
- package/dist/unstable/eventlog/EventLogServerEncrypted.js.map +1 -1
- package/dist/unstable/eventlog/EventLogServerUnencrypted.d.ts +5 -7
- package/dist/unstable/eventlog/EventLogServerUnencrypted.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogServerUnencrypted.js +5 -7
- package/dist/unstable/eventlog/EventLogServerUnencrypted.js.map +1 -1
- package/dist/unstable/eventlog/EventLogSessionAuth.d.ts +4 -4
- package/dist/unstable/eventlog/EventLogSessionAuth.js +4 -4
- package/dist/unstable/http/Cookies.js +4 -4
- package/dist/unstable/http/Cookies.js.map +1 -1
- package/dist/unstable/http/Etag.d.ts +2 -3
- package/dist/unstable/http/Etag.d.ts.map +1 -1
- package/dist/unstable/http/Etag.js +2 -3
- package/dist/unstable/http/Etag.js.map +1 -1
- package/dist/unstable/http/Headers.js +2 -2
- package/dist/unstable/http/Headers.js.map +1 -1
- package/dist/unstable/http/HttpBody.js +2 -2
- package/dist/unstable/http/HttpBody.js.map +1 -1
- package/dist/unstable/http/HttpClient.d.ts +2 -2
- package/dist/unstable/http/HttpClient.js +2 -2
- package/dist/unstable/http/HttpClientError.js +1 -1
- package/dist/unstable/http/HttpClientError.js.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts +30 -3
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +10 -1
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpRouter.d.ts +1 -1
- package/dist/unstable/http/HttpRouter.js +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts +25 -20
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +13 -8
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/Multipart.js +3 -3
- package/dist/unstable/http/Multipart.js.map +1 -1
- package/dist/unstable/http/UrlParams.d.ts +30 -0
- package/dist/unstable/http/UrlParams.d.ts.map +1 -1
- package/dist/unstable/http/UrlParams.js +16 -6
- package/dist/unstable/http/UrlParams.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts +3 -2
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js +3 -2
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +10 -8
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +15 -15
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +3 -3
- package/dist/unstable/httpapi/HttpApiMiddleware.js +3 -3
- package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -0
- package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.js +12 -6
- package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js +9 -9
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +11 -11
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/observability/OtlpResource.d.ts +5 -0
- package/dist/unstable/observability/OtlpResource.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpResource.js +5 -0
- package/dist/unstable/observability/OtlpResource.js.map +1 -1
- package/dist/unstable/observability/PrometheusMetrics.d.ts +4 -2
- package/dist/unstable/observability/PrometheusMetrics.d.ts.map +1 -1
- package/dist/unstable/observability/PrometheusMetrics.js +4 -2
- package/dist/unstable/observability/PrometheusMetrics.js.map +1 -1
- package/dist/unstable/persistence/Persistable.js +1 -1
- package/dist/unstable/persistence/Persistable.js.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +1 -1
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Persistence.js +1 -1
- package/dist/unstable/persistence/Persistence.js.map +1 -1
- package/dist/unstable/persistence/RateLimiter.js +1 -1
- package/dist/unstable/persistence/RateLimiter.js.map +1 -1
- package/dist/unstable/persistence/Redis.js +1 -1
- package/dist/unstable/persistence/Redis.js.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.js +1 -1
- package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +3 -3
- package/dist/unstable/reactivity/Atom.js +3 -3
- package/dist/unstable/rpc/Rpc.d.ts +1 -1
- package/dist/unstable/rpc/Rpc.js +2 -2
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +1 -1
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcClientError.js +1 -1
- package/dist/unstable/rpc/RpcClientError.js.map +1 -1
- package/dist/unstable/rpc/RpcMessage.d.ts +2 -2
- package/dist/unstable/rpc/RpcMessage.js +3 -3
- package/dist/unstable/rpc/RpcMessage.js.map +1 -1
- package/dist/unstable/rpc/RpcSchema.d.ts +2 -2
- package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.d.ts +2 -2
- package/dist/unstable/rpc/RpcSerialization.js +2 -2
- package/dist/unstable/schema/Model.js +5 -5
- package/dist/unstable/schema/Model.js.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +2 -2
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +3 -3
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/dist/unstable/sql/SqlError.js +1 -1
- package/dist/unstable/sql/SqlError.js.map +1 -1
- package/dist/unstable/sql/SqlSchema.d.ts +4 -4
- package/dist/unstable/sql/SqlSchema.js +4 -4
- package/dist/unstable/workers/Transferable.d.ts +2 -2
- package/dist/unstable/workers/Transferable.d.ts.map +1 -1
- package/dist/unstable/workers/Transferable.js +5 -5
- package/dist/unstable/workers/Transferable.js.map +1 -1
- package/dist/unstable/workers/WorkerError.js +4 -4
- package/dist/unstable/workers/WorkerError.js.map +1 -1
- package/dist/unstable/workflow/Activity.js +1 -1
- package/dist/unstable/workflow/Activity.js.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.js +8 -8
- package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
- package/dist/unstable/workflow/DurableQueue.d.ts +1 -2
- package/dist/unstable/workflow/DurableQueue.d.ts.map +1 -1
- package/dist/unstable/workflow/DurableQueue.js +1 -2
- package/dist/unstable/workflow/DurableQueue.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +35 -15
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.js +96 -74
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +10 -2
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +16 -8
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/dist/unstable/workflow/WorkflowProxy.d.ts +2 -4
- package/dist/unstable/workflow/WorkflowProxy.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowProxy.js +9 -11
- package/dist/unstable/workflow/WorkflowProxy.js.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.js +7 -7
- package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +729 -611
- package/src/BigDecimal.ts +37 -30
- package/src/BigInt.ts +34 -40
- package/src/Boolean.ts +8 -8
- package/src/Brand.ts +16 -14
- package/src/Cause.ts +21 -23
- package/src/Channel.ts +249 -9
- package/src/ChannelSchema.ts +11 -11
- package/src/Chunk.ts +69 -16
- package/src/Clock.ts +3 -3
- package/src/Combiner.ts +9 -13
- package/src/Config.ts +60 -67
- package/src/ConfigProvider.ts +34 -44
- package/src/Console.ts +2 -2
- package/src/Context.ts +60 -72
- package/src/Cron.ts +2 -2
- package/src/Crypto.ts +4 -4
- package/src/Data.ts +21 -15
- package/src/DateTime.ts +35 -16
- package/src/Deferred.ts +24 -15
- package/src/Duration.ts +44 -31
- package/src/Effect.ts +516 -416
- package/src/Encoding.ts +5 -0
- package/src/Equal.ts +26 -39
- package/src/Equivalence.ts +71 -99
- package/src/ErrorReporter.ts +1 -1
- package/src/Exit.ts +79 -96
- package/src/Fiber.ts +8 -6
- package/src/FiberHandle.ts +25 -0
- package/src/FiberMap.ts +35 -0
- package/src/FiberSet.ts +20 -0
- package/src/Filter.ts +4 -4
- package/src/Formatter.ts +14 -19
- package/src/Function.ts +15 -16
- package/src/Graph.ts +2 -2
- package/src/HKT.ts +2 -2
- package/src/Hash.ts +2 -1
- package/src/HashMap.ts +15 -0
- package/src/HashRing.ts +9 -9
- package/src/Iterable.ts +24 -12
- package/src/JsonPatch.ts +2 -3
- package/src/JsonPointer.ts +2 -6
- package/src/JsonSchema.ts +17 -13
- package/src/Latch.ts +4 -3
- package/src/Layer.ts +92 -114
- package/src/Logger.ts +15 -18
- package/src/Match.ts +2 -2
- package/src/Metric.ts +109 -137
- package/src/MutableHashMap.ts +35 -20
- package/src/MutableList.ts +15 -0
- package/src/MutableRef.ts +56 -42
- package/src/Newtype.ts +10 -7
- package/src/Number.ts +23 -11
- package/src/Optic.ts +25 -22
- package/src/Option.ts +196 -168
- package/src/Order.ts +118 -179
- package/src/PartitionedSemaphore.ts +14 -14
- package/src/Path.ts +2 -2
- package/src/Pipeable.ts +2 -2
- package/src/PlatformError.ts +4 -4
- package/src/Pool.ts +7 -11
- package/src/Predicate.ts +274 -263
- package/src/PubSub.ts +24 -14
- package/src/Pull.ts +4 -4
- package/src/Queue.ts +46 -7
- package/src/RcRef.ts +0 -4
- package/src/Redactable.ts +2 -2
- package/src/Redacted.ts +3 -3
- package/src/Reducer.ts +2 -3
- package/src/Ref.ts +43 -40
- package/src/References.ts +4 -4
- package/src/Request.ts +18 -18
- package/src/Resource.ts +2 -2
- package/src/Result.ts +87 -33
- package/src/Runtime.ts +11 -8
- package/src/Schedule.ts +112 -45
- package/src/Scheduler.ts +6 -4
- package/src/Schema.ts +1015 -759
- package/src/SchemaAST.ts +150 -117
- package/src/SchemaGetter.ts +142 -121
- package/src/SchemaIssue.ts +39 -41
- package/src/SchemaParser.ts +173 -229
- package/src/SchemaRepresentation.ts +50 -32
- package/src/SchemaTransformation.ts +308 -232
- package/src/SchemaUtils.ts +2 -2
- package/src/Scope.ts +15 -0
- package/src/ScopedCache.ts +1 -1
- package/src/ScopedRef.ts +14 -18
- package/src/Semaphore.ts +9 -9
- package/src/Sink.ts +13 -13
- package/src/Stdio.ts +4 -5
- package/src/Stream.ts +354 -57
- package/src/String.ts +6 -9
- package/src/Struct.ts +15 -13
- package/src/SubscriptionRef.ts +24 -19
- package/src/SynchronizedRef.ts +88 -63
- package/src/Tracer.ts +4 -4
- package/src/Trie.ts +15 -0
- package/src/Tuple.ts +25 -19
- package/src/TxReentrantLock.ts +6 -3
- package/src/TxRef.ts +16 -16
- package/src/TxSubscriptionRef.ts +43 -27
- package/src/Types.ts +12 -39
- package/src/UndefinedOr.ts +15 -14
- package/src/Unify.ts +2 -2
- package/src/internal/schema/annotations.ts +4 -4
- package/src/internal/schema/arbitrary.ts +16 -16
- package/src/internal/schema/equivalence.ts +11 -11
- package/src/internal/schema/representation.ts +24 -23
- package/src/internal/schema/schema.ts +17 -17
- package/src/testing/TestSchema.ts +20 -20
- package/src/unstable/ai/AiError.ts +4 -2
- package/src/unstable/ai/AnthropicStructuredOutput.ts +59 -56
- package/src/unstable/ai/Chat.ts +4 -5
- package/src/unstable/ai/EmbeddingModel.ts +4 -4
- package/src/unstable/ai/IdGenerator.ts +2 -3
- package/src/unstable/ai/LanguageModel.ts +5 -4
- package/src/unstable/ai/McpSchema.ts +20 -18
- package/src/unstable/ai/McpServer.ts +14 -7
- package/src/unstable/ai/OpenAiStructuredOutput.ts +72 -61
- package/src/unstable/ai/Prompt.ts +5 -5
- package/src/unstable/ai/ResponseIdTracker.ts +3 -2
- package/src/unstable/ai/Telemetry.ts +21 -6
- package/src/unstable/ai/Tool.ts +11 -10
- package/src/unstable/ai/Toolkit.ts +2 -2
- package/src/unstable/cli/CliError.ts +1 -1
- package/src/unstable/cli/Command.ts +37 -16
- package/src/unstable/cli/Completions.ts +1 -1
- package/src/unstable/cli/Flag.ts +7 -6
- package/src/unstable/cli/GlobalFlag.ts +7 -1
- package/src/unstable/cli/Param.ts +23 -18
- package/src/unstable/cli/Primitive.ts +3 -2
- package/src/unstable/cluster/ClusterCron.ts +1 -2
- package/src/unstable/cluster/ClusterError.ts +2 -2
- package/src/unstable/cluster/ClusterMetrics.ts +5 -0
- package/src/unstable/cluster/ClusterSchema.ts +3 -3
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +15 -15
- package/src/unstable/cluster/EntityResource.ts +10 -0
- package/src/unstable/cluster/Envelope.ts +3 -3
- package/src/unstable/cluster/Reply.ts +15 -13
- package/src/unstable/cluster/RunnerHealth.ts +2 -1
- package/src/unstable/cluster/RunnerServer.ts +2 -2
- package/src/unstable/cluster/Runners.ts +3 -3
- package/src/unstable/cluster/ShardId.ts +3 -3
- package/src/unstable/cluster/Sharding.ts +3 -3
- package/src/unstable/cluster/ShardingConfig.ts +4 -4
- package/src/unstable/cluster/Snowflake.ts +3 -3
- package/src/unstable/cluster/internal/entityManager.ts +2 -2
- package/src/unstable/devtools/DevToolsSchema.ts +1 -1
- package/src/unstable/encoding/Msgpack.ts +6 -6
- package/src/unstable/encoding/Ndjson.ts +5 -0
- package/src/unstable/encoding/Sse.ts +2 -2
- package/src/unstable/eventlog/EventGroup.ts +2 -1
- package/src/unstable/eventlog/EventJournal.ts +10 -0
- package/src/unstable/eventlog/EventLog.ts +3 -3
- package/src/unstable/eventlog/EventLogServerEncrypted.ts +2 -3
- package/src/unstable/eventlog/EventLogServerUnencrypted.ts +5 -7
- package/src/unstable/eventlog/EventLogSessionAuth.ts +4 -4
- package/src/unstable/http/Cookies.ts +4 -4
- package/src/unstable/http/Etag.ts +2 -3
- package/src/unstable/http/Headers.ts +2 -2
- package/src/unstable/http/HttpBody.ts +2 -2
- package/src/unstable/http/HttpClient.ts +2 -2
- package/src/unstable/http/HttpClientError.ts +1 -1
- package/src/unstable/http/HttpClientRequest.ts +30 -3
- package/src/unstable/http/HttpRouter.ts +1 -1
- package/src/unstable/http/HttpServerResponse.ts +25 -20
- package/src/unstable/http/Multipart.ts +3 -3
- package/src/unstable/http/UrlParams.ts +36 -6
- package/src/unstable/httpapi/HttpApi.ts +5 -4
- package/src/unstable/httpapi/HttpApiBuilder.ts +14 -13
- package/src/unstable/httpapi/HttpApiClient.ts +16 -16
- package/src/unstable/httpapi/HttpApiMiddleware.ts +3 -3
- package/src/unstable/httpapi/HttpApiScalar.ts +14 -7
- package/src/unstable/httpapi/HttpApiSchema.ts +15 -15
- package/src/unstable/httpapi/OpenApi.ts +18 -18
- package/src/unstable/observability/OtlpResource.ts +5 -0
- package/src/unstable/observability/PrometheusMetrics.ts +4 -2
- package/src/unstable/persistence/Persistable.ts +1 -1
- package/src/unstable/persistence/PersistedQueue.ts +1 -1
- package/src/unstable/persistence/Persistence.ts +1 -1
- package/src/unstable/persistence/RateLimiter.ts +1 -1
- package/src/unstable/persistence/Redis.ts +1 -1
- package/src/unstable/reactivity/AsyncResult.ts +1 -1
- package/src/unstable/reactivity/Atom.ts +3 -3
- package/src/unstable/rpc/Rpc.ts +3 -3
- package/src/unstable/rpc/RpcClient.ts +1 -1
- package/src/unstable/rpc/RpcClientError.ts +1 -1
- package/src/unstable/rpc/RpcMessage.ts +3 -3
- package/src/unstable/rpc/RpcSchema.ts +2 -2
- package/src/unstable/rpc/RpcSerialization.ts +2 -2
- package/src/unstable/schema/Model.ts +5 -5
- package/src/unstable/schema/VariantSchema.ts +2 -2
- package/src/unstable/socket/Socket.ts +3 -3
- package/src/unstable/sql/SqlError.ts +1 -1
- package/src/unstable/sql/SqlSchema.ts +4 -4
- package/src/unstable/workers/Transferable.ts +6 -6
- package/src/unstable/workers/WorkerError.ts +4 -4
- package/src/unstable/workflow/Activity.ts +1 -1
- package/src/unstable/workflow/DurableDeferred.ts +8 -8
- package/src/unstable/workflow/DurableQueue.ts +1 -2
- package/src/unstable/workflow/Workflow.ts +161 -116
- package/src/unstable/workflow/WorkflowEngine.ts +16 -8
- package/src/unstable/workflow/WorkflowProxy.ts +9 -11
- package/src/unstable/workflow/WorkflowProxyServer.ts +7 -7
package/src/Schema.ts
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* - Type guard: {@link is}
|
|
32
32
|
* - Assertion: {@link asserts}
|
|
33
33
|
* - Add constraints: `.check(...)` with filters like {@link isMinLength},
|
|
34
|
-
* {@link isGreaterThan}, {@link isPattern}, {@link isUUID}
|
|
34
|
+
* {@link isGreaterThan}, {@link isPattern}, {@link isUUID}, {@link isGUID}
|
|
35
35
|
* - Transform between schemas: {@link decodeTo}, {@link encodeTo}
|
|
36
36
|
* - Add a default for missing keys: {@link withDecodingDefault}, {@link withDecodingDefaultKey}
|
|
37
37
|
* - Create branded types: {@link brand}
|
|
@@ -125,12 +125,12 @@ import * as Record_ from "./Record.ts"
|
|
|
125
125
|
import * as Redacted_ from "./Redacted.ts"
|
|
126
126
|
import * as Result_ from "./Result.ts"
|
|
127
127
|
import * as Scheduler from "./Scheduler.ts"
|
|
128
|
-
import * as
|
|
129
|
-
import * as
|
|
130
|
-
import * as
|
|
131
|
-
import * as
|
|
128
|
+
import * as SchemaAST from "./SchemaAST.ts"
|
|
129
|
+
import * as SchemaGetter from "./SchemaGetter.ts"
|
|
130
|
+
import * as SchemaIssue from "./SchemaIssue.ts"
|
|
131
|
+
import * as SchemaParser from "./SchemaParser.ts"
|
|
132
132
|
import type * as SchemaRepresentation from "./SchemaRepresentation.ts"
|
|
133
|
-
import * as
|
|
133
|
+
import * as SchemaTransformation from "./SchemaTransformation.ts"
|
|
134
134
|
import type { Assign, Lambda, Mutable, Simplify } from "./Struct.ts"
|
|
135
135
|
import * as Struct_ from "./Struct.ts"
|
|
136
136
|
import * as FastCheck from "./testing/FastCheck.ts"
|
|
@@ -189,7 +189,7 @@ export interface MakeOptions {
|
|
|
189
189
|
/**
|
|
190
190
|
* The parse options to use for the schema.
|
|
191
191
|
*/
|
|
192
|
-
readonly parseOptions?:
|
|
192
|
+
readonly parseOptions?: SchemaAST.ParseOptions | undefined
|
|
193
193
|
/**
|
|
194
194
|
* Whether to disable validation for the schema.
|
|
195
195
|
*/
|
|
@@ -220,7 +220,7 @@ export interface Bottom<
|
|
|
220
220
|
out E,
|
|
221
221
|
out RD,
|
|
222
222
|
out RE,
|
|
223
|
-
out Ast extends
|
|
223
|
+
out Ast extends SchemaAST.AST,
|
|
224
224
|
out Rebuild extends Top,
|
|
225
225
|
out TypeMakeIn = T,
|
|
226
226
|
out Iso = T,
|
|
@@ -255,7 +255,7 @@ export interface Bottom<
|
|
|
255
255
|
|
|
256
256
|
annotate(annotations: Annotations.Bottom<this["Type"], this["~type.parameters"]>): this["Rebuild"]
|
|
257
257
|
annotateKey(annotations: Annotations.Key<this["Type"]>): this["Rebuild"]
|
|
258
|
-
check(...checks: readonly [
|
|
258
|
+
check(...checks: readonly [SchemaAST.Check<this["Type"]>, ...Array<SchemaAST.Check<this["Type"]>>]): this["Rebuild"]
|
|
259
259
|
rebuild(ast: this["ast"]): this["Rebuild"]
|
|
260
260
|
/**
|
|
261
261
|
* Constructs a value from the make input representation synchronously.
|
|
@@ -324,7 +324,7 @@ export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<T
|
|
|
324
324
|
E,
|
|
325
325
|
TypeParameters[number]["DecodingServices"],
|
|
326
326
|
TypeParameters[number]["EncodingServices"],
|
|
327
|
-
|
|
327
|
+
SchemaAST.Declaration,
|
|
328
328
|
declareConstructor<T, E, TypeParameters, Iso>,
|
|
329
329
|
T,
|
|
330
330
|
Iso,
|
|
@@ -337,6 +337,11 @@ export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<T
|
|
|
337
337
|
* `Array<A>`, `Option<A>`, etc.) by accepting a list of type-parameter schemas
|
|
338
338
|
* and a decoder factory.
|
|
339
339
|
*
|
|
340
|
+
* **When to use**
|
|
341
|
+
*
|
|
342
|
+
* Use when you are defining a schema for a generic container whose validation
|
|
343
|
+
* depends on one or more type-parameter schemas.
|
|
344
|
+
*
|
|
340
345
|
* **Details**
|
|
341
346
|
*
|
|
342
347
|
* The outer call `declareConstructor<T, E, Iso>()` fixes the decoded type `T`,
|
|
@@ -366,7 +371,7 @@ export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<T
|
|
|
366
371
|
* ([itemCodec]) =>
|
|
367
372
|
* (u, ast, options) => {
|
|
368
373
|
* if (!isBox(u)) {
|
|
369
|
-
* return Effect.fail(new
|
|
374
|
+
* return Effect.fail(new SchemaIssue.InvalidType(ast, Option.some(u)))
|
|
370
375
|
* }
|
|
371
376
|
* return Effect.map(
|
|
372
377
|
* SchemaParser.decodeUnknownEffect(itemCodec)(u.value, options),
|
|
@@ -388,12 +393,16 @@ export function declareConstructor<T, E = T, Iso = T>() {
|
|
|
388
393
|
typeParameters: {
|
|
389
394
|
readonly [K in keyof TypeParameters]: Codec<TypeParameters[K]["Type"], TypeParameters[K]["Encoded"]>
|
|
390
395
|
}
|
|
391
|
-
) => (
|
|
396
|
+
) => (
|
|
397
|
+
u: unknown,
|
|
398
|
+
self: SchemaAST.Declaration,
|
|
399
|
+
options: SchemaAST.ParseOptions
|
|
400
|
+
) => Effect.Effect<T, SchemaIssue.Issue>,
|
|
392
401
|
annotations?: Annotations.Declaration<T, TypeParameters>
|
|
393
402
|
): declareConstructor<T, E, TypeParameters, Iso> => {
|
|
394
403
|
return make(
|
|
395
|
-
new
|
|
396
|
-
typeParameters.map(
|
|
404
|
+
new SchemaAST.Declaration(
|
|
405
|
+
typeParameters.map(SchemaAST.getAST),
|
|
397
406
|
(typeParameters) => run(typeParameters.map((ast) => make(ast)) as any),
|
|
398
407
|
annotations
|
|
399
408
|
)
|
|
@@ -416,10 +425,10 @@ export interface declare<T, Iso = T> extends declareConstructor<T, T, readonly [
|
|
|
416
425
|
* function. The schema accepts any unknown value and succeeds when `is` returns
|
|
417
426
|
* `true`, failing with an `InvalidType` issue otherwise.
|
|
418
427
|
*
|
|
419
|
-
* **
|
|
428
|
+
* **When to use**
|
|
420
429
|
*
|
|
421
|
-
* Use
|
|
422
|
-
*
|
|
430
|
+
* Use when you are defining a schema for an opaque type with no type parameters
|
|
431
|
+
* and validation can be expressed as a type guard.
|
|
423
432
|
*
|
|
424
433
|
* **Example** (Schema for a custom `UserId` branded type)
|
|
425
434
|
*
|
|
@@ -451,7 +460,7 @@ export function declare<T, Iso = T>(
|
|
|
451
460
|
() => (input, ast) =>
|
|
452
461
|
is(input) ?
|
|
453
462
|
Effect.succeed(input) :
|
|
454
|
-
Effect.fail(new
|
|
463
|
+
Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input))),
|
|
455
464
|
annotations
|
|
456
465
|
)
|
|
457
466
|
}
|
|
@@ -605,7 +614,7 @@ export function annotateEncoded<S extends Top>(annotations: Annotations.Bottom<S
|
|
|
605
614
|
*/
|
|
606
615
|
export function annotateKey<S extends Top>(annotations: Annotations.Key<S["Type"]>) {
|
|
607
616
|
return (self: S): S["Rebuild"] => {
|
|
608
|
-
return self.rebuild(
|
|
617
|
+
return self.rebuild(SchemaAST.annotateKey(self.ast, annotations))
|
|
609
618
|
}
|
|
610
619
|
}
|
|
611
620
|
|
|
@@ -633,7 +642,7 @@ export interface Top extends
|
|
|
633
642
|
unknown,
|
|
634
643
|
unknown,
|
|
635
644
|
unknown,
|
|
636
|
-
|
|
645
|
+
SchemaAST.AST,
|
|
637
646
|
Top,
|
|
638
647
|
unknown,
|
|
639
648
|
unknown,
|
|
@@ -921,7 +930,7 @@ export {
|
|
|
921
930
|
*
|
|
922
931
|
* **Details**
|
|
923
932
|
*
|
|
924
|
-
* The `issue` field contains a structured {@link
|
|
933
|
+
* The `issue` field contains a structured {@link SchemaIssue.Issue} tree describing
|
|
925
934
|
* every validation failure, including the path to the problematic value,
|
|
926
935
|
* expected types, and actual values received. `message` renders the issue tree
|
|
927
936
|
* as a human-readable string.
|
|
@@ -1045,17 +1054,17 @@ function makeStandardResult<A>(exit: Exit_.Exit<StandardSchemaV1.Result<A>>): St
|
|
|
1045
1054
|
export function toStandardSchemaV1<S extends Decoder<unknown>>(
|
|
1046
1055
|
self: S,
|
|
1047
1056
|
options?: {
|
|
1048
|
-
readonly leafHook?:
|
|
1049
|
-
readonly checkHook?:
|
|
1050
|
-
readonly parseOptions?:
|
|
1057
|
+
readonly leafHook?: SchemaIssue.LeafHook | undefined
|
|
1058
|
+
readonly checkHook?: SchemaIssue.CheckHook | undefined
|
|
1059
|
+
readonly parseOptions?: SchemaAST.ParseOptions | undefined
|
|
1051
1060
|
}
|
|
1052
1061
|
): StandardSchemaV1<S["Encoded"], S["Type"]> & S {
|
|
1053
|
-
const decodeUnknownEffect =
|
|
1062
|
+
const decodeUnknownEffect = SchemaParser.decodeUnknownEffect(self) as (
|
|
1054
1063
|
input: unknown,
|
|
1055
|
-
options?:
|
|
1056
|
-
) => Effect.Effect<S["Type"],
|
|
1057
|
-
const parseOptions:
|
|
1058
|
-
const formatter =
|
|
1064
|
+
options?: SchemaAST.ParseOptions
|
|
1065
|
+
) => Effect.Effect<S["Type"], SchemaIssue.Issue>
|
|
1066
|
+
const parseOptions: SchemaAST.ParseOptions = { errors: "all", ...options?.parseOptions }
|
|
1067
|
+
const formatter = SchemaIssue.makeFormatterStandardSchemaV1(options)
|
|
1059
1068
|
const validate: StandardSchemaV1<S["Encoded"], S["Type"]>["~standard"]["validate"] = (value: unknown) => {
|
|
1060
1069
|
const scheduler = new Scheduler.MixedScheduler()
|
|
1061
1070
|
const fiber = Effect.runFork(
|
|
@@ -1177,7 +1186,7 @@ export function toStandardJSONSchemaV1<S extends Top>(self: S): StandardJSONSche
|
|
|
1177
1186
|
* @category guards
|
|
1178
1187
|
* @since 3.10.0
|
|
1179
1188
|
*/
|
|
1180
|
-
export const is =
|
|
1189
|
+
export const is = SchemaParser.is
|
|
1181
1190
|
|
|
1182
1191
|
/**
|
|
1183
1192
|
* Creates an assertion function that throws an error if the input doesn't match
|
|
@@ -1186,7 +1195,7 @@ export const is = Parser.is
|
|
|
1186
1195
|
* **When to use**
|
|
1187
1196
|
*
|
|
1188
1197
|
* Use to validate unknown input at runtime while narrowing the value with a
|
|
1189
|
-
* TypeScript
|
|
1198
|
+
* TypeScript assertion signature.
|
|
1190
1199
|
*
|
|
1191
1200
|
* **Details**
|
|
1192
1201
|
*
|
|
@@ -1216,7 +1225,7 @@ export const is = Parser.is
|
|
|
1216
1225
|
* @category guards
|
|
1217
1226
|
* @since 4.0.0
|
|
1218
1227
|
*/
|
|
1219
|
-
export const asserts: <S extends Top, I>(schema: S, input: I) => asserts input is I & S["Type"] =
|
|
1228
|
+
export const asserts: <S extends Top, I>(schema: S, input: I) => asserts input is I & S["Type"] = SchemaParser.asserts
|
|
1220
1229
|
|
|
1221
1230
|
/**
|
|
1222
1231
|
* Decodes an `unknown` input against a schema, returning an `Effect` that
|
|
@@ -1224,7 +1233,8 @@ export const asserts: <S extends Top, I>(schema: S, input: I) => asserts input i
|
|
|
1224
1233
|
*
|
|
1225
1234
|
* **When to use**
|
|
1226
1235
|
*
|
|
1227
|
-
* Use when
|
|
1236
|
+
* Use when you need to decode unknown input in an `Effect` whose failure
|
|
1237
|
+
* channel is `SchemaError`.
|
|
1228
1238
|
*
|
|
1229
1239
|
* **Details**
|
|
1230
1240
|
*
|
|
@@ -1233,12 +1243,17 @@ export const asserts: <S extends Top, I>(schema: S, input: I) => asserts input i
|
|
|
1233
1243
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1234
1244
|
* application options override creation options.
|
|
1235
1245
|
*
|
|
1246
|
+
* @see {@link SchemaParser.decodeUnknownEffect} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1247
|
+
*
|
|
1236
1248
|
* @category decoding
|
|
1237
1249
|
* @since 4.0.0
|
|
1238
1250
|
*/
|
|
1239
|
-
export function decodeUnknownEffect<S extends Top>(schema: S, options?:
|
|
1240
|
-
const parser =
|
|
1241
|
-
return (
|
|
1251
|
+
export function decodeUnknownEffect<S extends Top>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1252
|
+
const parser = SchemaParser.decodeUnknownEffect(schema, options)
|
|
1253
|
+
return (
|
|
1254
|
+
input: unknown,
|
|
1255
|
+
options?: SchemaAST.ParseOptions
|
|
1256
|
+
): Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]> => {
|
|
1242
1257
|
return Effect.mapErrorEager(parser(input, options), (issue) => new SchemaError(issue))
|
|
1243
1258
|
}
|
|
1244
1259
|
}
|
|
@@ -1250,7 +1265,8 @@ export function decodeUnknownEffect<S extends Top>(schema: S, options?: AST.Pars
|
|
|
1250
1265
|
*
|
|
1251
1266
|
* **When to use**
|
|
1252
1267
|
*
|
|
1253
|
-
* Use when
|
|
1268
|
+
* Use when you need to decode input already typed as the schema's `Encoded`
|
|
1269
|
+
* type in an `Effect` whose failure channel is `SchemaError`.
|
|
1254
1270
|
*
|
|
1255
1271
|
* **Details**
|
|
1256
1272
|
*
|
|
@@ -1258,14 +1274,18 @@ export function decodeUnknownEffect<S extends Top>(schema: S, options?: AST.Pars
|
|
|
1258
1274
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1259
1275
|
* application options override creation options.
|
|
1260
1276
|
*
|
|
1277
|
+
* @see {@link SchemaParser.decodeEffect} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1278
|
+
*
|
|
1261
1279
|
* @category decoding
|
|
1262
1280
|
* @since 4.0.0
|
|
1263
1281
|
*/
|
|
1264
1282
|
export const decodeEffect: <S extends Top>(
|
|
1265
1283
|
schema: S,
|
|
1266
|
-
options?:
|
|
1267
|
-
) => (
|
|
1268
|
-
|
|
1284
|
+
options?: SchemaAST.ParseOptions
|
|
1285
|
+
) => (
|
|
1286
|
+
input: S["Encoded"],
|
|
1287
|
+
options?: SchemaAST.ParseOptions
|
|
1288
|
+
) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]> = decodeUnknownEffect
|
|
1269
1289
|
|
|
1270
1290
|
/**
|
|
1271
1291
|
* Decodes an `unknown` input against a schema synchronously, returning an
|
|
@@ -1274,8 +1294,8 @@ export const decodeEffect: <S extends Top>(
|
|
|
1274
1294
|
*
|
|
1275
1295
|
* **When to use**
|
|
1276
1296
|
*
|
|
1277
|
-
* Use when
|
|
1278
|
-
* `
|
|
1297
|
+
* Use when you need to decode unknown input into an `Exit` whose failure
|
|
1298
|
+
* contains `SchemaError`.
|
|
1279
1299
|
*
|
|
1280
1300
|
* **Details**
|
|
1281
1301
|
*
|
|
@@ -1285,12 +1305,14 @@ export const decodeEffect: <S extends Top>(
|
|
|
1285
1305
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1286
1306
|
* application options override creation options.
|
|
1287
1307
|
*
|
|
1308
|
+
* @see {@link SchemaParser.decodeUnknownExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1309
|
+
*
|
|
1288
1310
|
* @category decoding
|
|
1289
1311
|
* @since 4.0.0
|
|
1290
1312
|
*/
|
|
1291
|
-
export function decodeUnknownExit<S extends Decoder<unknown>>(schema: S, options?:
|
|
1292
|
-
const parser =
|
|
1293
|
-
return (input: unknown, options?:
|
|
1313
|
+
export function decodeUnknownExit<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1314
|
+
const parser = SchemaParser.decodeUnknownExit(schema, options)
|
|
1315
|
+
return (input: unknown, options?: SchemaAST.ParseOptions): Exit_.Exit<S["Type"], SchemaError> => {
|
|
1294
1316
|
return Exit_.mapError(parser(input, options), (issue) => new SchemaError(issue))
|
|
1295
1317
|
}
|
|
1296
1318
|
}
|
|
@@ -1302,8 +1324,8 @@ export function decodeUnknownExit<S extends Decoder<unknown>>(schema: S, options
|
|
|
1302
1324
|
*
|
|
1303
1325
|
* **When to use**
|
|
1304
1326
|
*
|
|
1305
|
-
* Use when
|
|
1306
|
-
*
|
|
1327
|
+
* Use when you need to decode already typed `Encoded` input into an `Exit`
|
|
1328
|
+
* whose failure contains `SchemaError`.
|
|
1307
1329
|
*
|
|
1308
1330
|
* **Details**
|
|
1309
1331
|
*
|
|
@@ -1312,13 +1334,15 @@ export function decodeUnknownExit<S extends Decoder<unknown>>(schema: S, options
|
|
|
1312
1334
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1313
1335
|
* application options override creation options.
|
|
1314
1336
|
*
|
|
1337
|
+
* @see {@link SchemaParser.decodeExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1338
|
+
*
|
|
1315
1339
|
* @category decoding
|
|
1316
1340
|
* @since 4.0.0
|
|
1317
1341
|
*/
|
|
1318
1342
|
export const decodeExit: <S extends Decoder<unknown>>(
|
|
1319
1343
|
schema: S,
|
|
1320
|
-
options?:
|
|
1321
|
-
) => (input: S["Encoded"], options?:
|
|
1344
|
+
options?: SchemaAST.ParseOptions
|
|
1345
|
+
) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Type"], SchemaError> = decodeUnknownExit
|
|
1322
1346
|
|
|
1323
1347
|
/**
|
|
1324
1348
|
* Decodes an `unknown` input against a schema, returning an `Option` that is
|
|
@@ -1326,20 +1350,24 @@ export const decodeExit: <S extends Decoder<unknown>>(
|
|
|
1326
1350
|
*
|
|
1327
1351
|
* **When to use**
|
|
1328
1352
|
*
|
|
1329
|
-
* Use when the input type
|
|
1353
|
+
* Use when you do not know the input type statically and only need to know
|
|
1330
1354
|
* whether decoding succeeded.
|
|
1331
1355
|
*
|
|
1332
1356
|
* **Details**
|
|
1333
1357
|
*
|
|
1334
1358
|
* Prefer this over {@link decodeUnknownExit} or {@link decodeUnknownEffect}
|
|
1335
|
-
* when you don't need error details. For typed
|
|
1359
|
+
* when you don't need error details. For input already typed as the schema's
|
|
1360
|
+
* `Encoded` type use {@link decodeOption}.
|
|
1336
1361
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1337
1362
|
* application options override creation options.
|
|
1338
1363
|
*
|
|
1339
1364
|
* @category decoding
|
|
1340
1365
|
* @since 3.10.0
|
|
1341
1366
|
*/
|
|
1342
|
-
export const decodeUnknownOption
|
|
1367
|
+
export const decodeUnknownOption: <S extends Decoder<unknown>>(
|
|
1368
|
+
schema: S,
|
|
1369
|
+
options?: SchemaAST.ParseOptions
|
|
1370
|
+
) => (input: unknown, options?: SchemaAST.ParseOptions) => Option_.Option<S["Type"]> = SchemaParser.decodeUnknownOption
|
|
1343
1371
|
|
|
1344
1372
|
/**
|
|
1345
1373
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
@@ -1348,7 +1376,8 @@ export const decodeUnknownOption = Parser.decodeUnknownOption
|
|
|
1348
1376
|
*
|
|
1349
1377
|
* **When to use**
|
|
1350
1378
|
*
|
|
1351
|
-
* Use when
|
|
1379
|
+
* Use when you already have input typed as the schema's `Encoded` type and
|
|
1380
|
+
* only need to know whether decoding succeeded.
|
|
1352
1381
|
*
|
|
1353
1382
|
* **Details**
|
|
1354
1383
|
*
|
|
@@ -1359,37 +1388,48 @@ export const decodeUnknownOption = Parser.decodeUnknownOption
|
|
|
1359
1388
|
* @category decoding
|
|
1360
1389
|
* @since 3.10.0
|
|
1361
1390
|
*/
|
|
1362
|
-
export const decodeOption
|
|
1391
|
+
export const decodeOption: <S extends Decoder<unknown>>(
|
|
1392
|
+
schema: S,
|
|
1393
|
+
options?: SchemaAST.ParseOptions
|
|
1394
|
+
) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Option_.Option<S["Type"]> = decodeUnknownOption
|
|
1363
1395
|
|
|
1364
1396
|
/**
|
|
1365
1397
|
* Decodes an `unknown` input against a schema, returning a `Result` that
|
|
1366
|
-
* succeeds with the decoded value or fails with a
|
|
1398
|
+
* succeeds with the decoded value or fails with a {@link SchemaError}.
|
|
1367
1399
|
*
|
|
1368
1400
|
* **When to use**
|
|
1369
1401
|
*
|
|
1370
|
-
* Use when the input type
|
|
1371
|
-
* `Result` with
|
|
1402
|
+
* Use when you do not know the input type statically and want decoding to
|
|
1403
|
+
* return a `Result` with `SchemaError` failure data.
|
|
1372
1404
|
*
|
|
1373
1405
|
* **Details**
|
|
1374
1406
|
*
|
|
1375
|
-
* For typed
|
|
1407
|
+
* For input already typed as the schema's `Encoded` type use
|
|
1408
|
+
* {@link decodeResult}.
|
|
1376
1409
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1377
1410
|
* application options override creation options.
|
|
1378
1411
|
*
|
|
1412
|
+
* @see {@link SchemaParser.decodeUnknownResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1413
|
+
*
|
|
1379
1414
|
* @category decoding
|
|
1380
1415
|
* @since 4.0.0
|
|
1381
1416
|
*/
|
|
1382
|
-
export
|
|
1417
|
+
export function decodeUnknownResult<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1418
|
+
const parser = SchemaParser.decodeUnknownResult(schema, options)
|
|
1419
|
+
return (input: unknown, options?: SchemaAST.ParseOptions): Result_.Result<S["Type"], SchemaError> => {
|
|
1420
|
+
return Result_.mapError(parser(input, options), (issue) => new SchemaError(issue))
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1383
1423
|
|
|
1384
1424
|
/**
|
|
1385
1425
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
1386
1426
|
* returning a `Result` that succeeds with the decoded value or fails with a
|
|
1387
|
-
*
|
|
1427
|
+
* {@link SchemaError}.
|
|
1388
1428
|
*
|
|
1389
1429
|
* **When to use**
|
|
1390
1430
|
*
|
|
1391
|
-
* Use when
|
|
1392
|
-
* data.
|
|
1431
|
+
* Use when you already have input typed as the schema's `Encoded` type and
|
|
1432
|
+
* want decoding to return a `Result` with `SchemaError` failure data.
|
|
1393
1433
|
*
|
|
1394
1434
|
* **Details**
|
|
1395
1435
|
*
|
|
@@ -1397,38 +1437,55 @@ export const decodeUnknownResult = Parser.decodeUnknownResult
|
|
|
1397
1437
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1398
1438
|
* application options override creation options.
|
|
1399
1439
|
*
|
|
1440
|
+
* @see {@link SchemaParser.decodeResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1441
|
+
*
|
|
1400
1442
|
* @category decoding
|
|
1401
1443
|
* @since 4.0.0
|
|
1402
1444
|
*/
|
|
1403
|
-
export const decodeResult
|
|
1445
|
+
export const decodeResult: <S extends Decoder<unknown>>(
|
|
1446
|
+
schema: S,
|
|
1447
|
+
options?: SchemaAST.ParseOptions
|
|
1448
|
+
) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Result_.Result<S["Type"], SchemaError> =
|
|
1449
|
+
decodeUnknownResult
|
|
1404
1450
|
|
|
1405
1451
|
/**
|
|
1406
1452
|
* Decodes an `unknown` input against a schema, returning a `Promise` that
|
|
1407
|
-
* resolves with the decoded value or rejects with a
|
|
1453
|
+
* resolves with the decoded value or rejects with a {@link SchemaError}.
|
|
1408
1454
|
*
|
|
1409
1455
|
* **When to use**
|
|
1410
1456
|
*
|
|
1411
|
-
* Use when
|
|
1457
|
+
* Use when you need decoding of unknown input to return a JavaScript `Promise`
|
|
1458
|
+
* that rejects with `SchemaError`.
|
|
1412
1459
|
*
|
|
1413
1460
|
* **Details**
|
|
1414
1461
|
*
|
|
1415
|
-
* For typed
|
|
1462
|
+
* For input already typed as the schema's `Encoded` type use
|
|
1463
|
+
* {@link decodePromise}.
|
|
1416
1464
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1417
1465
|
* application options override creation options.
|
|
1418
1466
|
*
|
|
1467
|
+
* @see {@link SchemaParser.decodeUnknownPromise} for the adapter that rejects with `SchemaIssue.Issue` directly
|
|
1468
|
+
*
|
|
1419
1469
|
* @category decoding
|
|
1420
1470
|
* @since 3.10.0
|
|
1421
1471
|
*/
|
|
1422
|
-
export
|
|
1472
|
+
export function decodeUnknownPromise<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1473
|
+
const parser = decodeUnknownEffect(schema, options)
|
|
1474
|
+
return (input: unknown, options?: SchemaAST.ParseOptions): Promise<S["Type"]> => {
|
|
1475
|
+
return Effect.runPromise(parser(input, options))
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1423
1478
|
|
|
1424
1479
|
/**
|
|
1425
1480
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
1426
1481
|
* returning a `Promise` that resolves with the decoded value or rejects with a
|
|
1427
|
-
*
|
|
1482
|
+
* {@link SchemaError}.
|
|
1428
1483
|
*
|
|
1429
1484
|
* **When to use**
|
|
1430
1485
|
*
|
|
1431
|
-
* Use when
|
|
1486
|
+
* Use when you already have input typed as the schema's `Encoded` type and
|
|
1487
|
+
* need decoding to return a JavaScript `Promise` that rejects with
|
|
1488
|
+
* `SchemaError`.
|
|
1432
1489
|
*
|
|
1433
1490
|
* **Details**
|
|
1434
1491
|
*
|
|
@@ -1436,23 +1493,28 @@ export const decodeUnknownPromise = Parser.decodeUnknownPromise
|
|
|
1436
1493
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1437
1494
|
* application options override creation options.
|
|
1438
1495
|
*
|
|
1496
|
+
* @see {@link SchemaParser.decodePromise} for the adapter that rejects with `SchemaIssue.Issue` directly
|
|
1497
|
+
*
|
|
1439
1498
|
* @category decoding
|
|
1440
1499
|
* @since 3.10.0
|
|
1441
1500
|
*/
|
|
1442
|
-
export const decodePromise
|
|
1501
|
+
export const decodePromise: <S extends Decoder<unknown>>(
|
|
1502
|
+
schema: S,
|
|
1503
|
+
options?: SchemaAST.ParseOptions
|
|
1504
|
+
) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Promise<S["Type"]> = decodeUnknownPromise
|
|
1443
1505
|
|
|
1444
1506
|
/**
|
|
1445
1507
|
* Decodes an `unknown` input against a schema synchronously, returning the
|
|
1446
|
-
* decoded value or throwing
|
|
1508
|
+
* decoded value or throwing a {@link SchemaError}.
|
|
1447
1509
|
*
|
|
1448
1510
|
* **When to use**
|
|
1449
1511
|
*
|
|
1450
|
-
* Use when
|
|
1451
|
-
*
|
|
1512
|
+
* Use when you need to validate unknown data at a synchronous boundary and want
|
|
1513
|
+
* schema mismatches to throw `SchemaError`.
|
|
1452
1514
|
*
|
|
1453
1515
|
* **Details**
|
|
1454
1516
|
*
|
|
1455
|
-
* For typed
|
|
1517
|
+
* For input already typed as the schema's `Encoded` type use `decodeSync`.
|
|
1456
1518
|
* Only service-free schemas can be decoded synchronously. For non-throwing
|
|
1457
1519
|
* alternatives see `decodeUnknownOption`, `decodeUnknownExit`, or
|
|
1458
1520
|
* `decodeUnknownEffect`. Options may be provided either when creating the
|
|
@@ -1475,20 +1537,26 @@ export const decodePromise = Parser.decodePromise
|
|
|
1475
1537
|
* // └─ Expected a numeric string, actual "not a number"
|
|
1476
1538
|
* ```
|
|
1477
1539
|
*
|
|
1540
|
+
* @see {@link SchemaParser.decodeUnknownSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1541
|
+
*
|
|
1478
1542
|
* @category decoding
|
|
1479
1543
|
* @since 4.0.0
|
|
1480
1544
|
*/
|
|
1481
|
-
export
|
|
1545
|
+
export function decodeUnknownSync<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1546
|
+
const parser = decodeUnknownEffect(schema, options)
|
|
1547
|
+
return (input: unknown, options?: SchemaAST.ParseOptions): S["Type"] => {
|
|
1548
|
+
return Effect.runSync(parser(input, options) as Effect.Effect<S["Type"], SchemaError>)
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1482
1551
|
|
|
1483
1552
|
/**
|
|
1484
1553
|
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
1485
|
-
* synchronously, returning the decoded value or throwing
|
|
1486
|
-
* contains the schema issue.
|
|
1554
|
+
* synchronously, returning the decoded value or throwing a {@link SchemaError}.
|
|
1487
1555
|
*
|
|
1488
1556
|
* **When to use**
|
|
1489
1557
|
*
|
|
1490
|
-
* Use when
|
|
1491
|
-
*
|
|
1558
|
+
* Use when you already have input typed as the schema's `Encoded` type and
|
|
1559
|
+
* want schema mismatches to throw `SchemaError` synchronously.
|
|
1492
1560
|
*
|
|
1493
1561
|
* **Details**
|
|
1494
1562
|
*
|
|
@@ -1497,10 +1565,15 @@ export const decodeUnknownSync = Parser.decodeUnknownSync
|
|
|
1497
1565
|
* provided either when creating the decoder or when applying it; application
|
|
1498
1566
|
* options override creation options.
|
|
1499
1567
|
*
|
|
1568
|
+
* @see {@link SchemaParser.decodeSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1569
|
+
*
|
|
1500
1570
|
* @category decoding
|
|
1501
1571
|
* @since 4.0.0
|
|
1502
1572
|
*/
|
|
1503
|
-
export const decodeSync
|
|
1573
|
+
export const decodeSync: <S extends Decoder<unknown>>(
|
|
1574
|
+
schema: S,
|
|
1575
|
+
options?: SchemaAST.ParseOptions
|
|
1576
|
+
) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => S["Type"] = decodeUnknownSync
|
|
1504
1577
|
|
|
1505
1578
|
/**
|
|
1506
1579
|
* Encodes an `unknown` input against a schema, returning an `Effect` that
|
|
@@ -1508,11 +1581,12 @@ export const decodeSync = Parser.decodeSync
|
|
|
1508
1581
|
*
|
|
1509
1582
|
* **When to use**
|
|
1510
1583
|
*
|
|
1511
|
-
* Use when
|
|
1584
|
+
* Use when you need to encode unknown input in an `Effect` whose failure
|
|
1585
|
+
* channel is `SchemaError`.
|
|
1512
1586
|
*
|
|
1513
1587
|
* **Details**
|
|
1514
1588
|
*
|
|
1515
|
-
* Prefer {@link encodeEffect} when the
|
|
1589
|
+
* Prefer {@link encodeEffect} when the value is already typed as the schema's
|
|
1516
1590
|
* `Type`.
|
|
1517
1591
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1518
1592
|
* application options override creation options.
|
|
@@ -1528,14 +1602,16 @@ export const decodeSync = Parser.decodeSync
|
|
|
1528
1602
|
* // Output: "42"
|
|
1529
1603
|
* ```
|
|
1530
1604
|
*
|
|
1605
|
+
* @see {@link SchemaParser.encodeUnknownEffect} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1606
|
+
*
|
|
1531
1607
|
* @category encoding
|
|
1532
1608
|
* @since 4.0.0
|
|
1533
1609
|
*/
|
|
1534
|
-
export function encodeUnknownEffect<S extends Top>(schema: S, options?:
|
|
1535
|
-
const parser =
|
|
1610
|
+
export function encodeUnknownEffect<S extends Top>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1611
|
+
const parser = SchemaParser.encodeUnknownEffect(schema, options)
|
|
1536
1612
|
return (
|
|
1537
1613
|
input: unknown,
|
|
1538
|
-
options?:
|
|
1614
|
+
options?: SchemaAST.ParseOptions
|
|
1539
1615
|
): Effect.Effect<S["Encoded"], SchemaError, S["EncodingServices"]> => {
|
|
1540
1616
|
return Effect.mapErrorEager(parser(input, options), (issue) => new SchemaError(issue))
|
|
1541
1617
|
}
|
|
@@ -1548,7 +1624,8 @@ export function encodeUnknownEffect<S extends Top>(schema: S, options?: AST.Pars
|
|
|
1548
1624
|
*
|
|
1549
1625
|
* **When to use**
|
|
1550
1626
|
*
|
|
1551
|
-
* Use when
|
|
1627
|
+
* Use when you need to encode input already typed as the schema's `Type` in
|
|
1628
|
+
* an `Effect` whose failure channel is `SchemaError`.
|
|
1552
1629
|
*
|
|
1553
1630
|
* **Details**
|
|
1554
1631
|
*
|
|
@@ -1556,14 +1633,18 @@ export function encodeUnknownEffect<S extends Top>(schema: S, options?: AST.Pars
|
|
|
1556
1633
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1557
1634
|
* application options override creation options.
|
|
1558
1635
|
*
|
|
1636
|
+
* @see {@link SchemaParser.encodeEffect} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1637
|
+
*
|
|
1559
1638
|
* @category encoding
|
|
1560
1639
|
* @since 4.0.0
|
|
1561
1640
|
*/
|
|
1562
1641
|
export const encodeEffect: <S extends Top>(
|
|
1563
1642
|
schema: S,
|
|
1564
|
-
options?:
|
|
1565
|
-
) => (
|
|
1566
|
-
|
|
1643
|
+
options?: SchemaAST.ParseOptions
|
|
1644
|
+
) => (
|
|
1645
|
+
input: S["Type"],
|
|
1646
|
+
options?: SchemaAST.ParseOptions
|
|
1647
|
+
) => Effect.Effect<S["Encoded"], SchemaError, S["EncodingServices"]> = encodeUnknownEffect
|
|
1567
1648
|
|
|
1568
1649
|
/**
|
|
1569
1650
|
* Encodes an `unknown` input against a schema synchronously, returning an
|
|
@@ -1572,22 +1653,24 @@ export const encodeEffect: <S extends Top>(
|
|
|
1572
1653
|
*
|
|
1573
1654
|
* **When to use**
|
|
1574
1655
|
*
|
|
1575
|
-
* Use when
|
|
1576
|
-
* `
|
|
1656
|
+
* Use when you need to encode unknown input into an `Exit` whose failure
|
|
1657
|
+
* contains `SchemaError`.
|
|
1577
1658
|
*
|
|
1578
1659
|
* **Details**
|
|
1579
1660
|
*
|
|
1580
1661
|
* Only usable with schemas that have no `EncodingServices` requirement. Prefer
|
|
1581
|
-
* {@link encodeExit} when the
|
|
1662
|
+
* {@link encodeExit} when the value is already typed as the schema's `Type`.
|
|
1582
1663
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1583
1664
|
* application options override creation options.
|
|
1584
1665
|
*
|
|
1666
|
+
* @see {@link SchemaParser.encodeUnknownExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1667
|
+
*
|
|
1585
1668
|
* @category encoding
|
|
1586
1669
|
* @since 4.0.0
|
|
1587
1670
|
*/
|
|
1588
|
-
export function encodeUnknownExit<S extends Encoder<unknown>>(schema: S, options?:
|
|
1589
|
-
const parser =
|
|
1590
|
-
return (input: unknown, options?:
|
|
1671
|
+
export function encodeUnknownExit<S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1672
|
+
const parser = SchemaParser.encodeUnknownExit(schema, options)
|
|
1673
|
+
return (input: unknown, options?: SchemaAST.ParseOptions): Exit_.Exit<S["Encoded"], SchemaError> => {
|
|
1591
1674
|
return Exit_.mapError(parser(input, options), (issue) => new SchemaError(issue))
|
|
1592
1675
|
}
|
|
1593
1676
|
}
|
|
@@ -1599,8 +1682,8 @@ export function encodeUnknownExit<S extends Encoder<unknown>>(schema: S, options
|
|
|
1599
1682
|
*
|
|
1600
1683
|
* **When to use**
|
|
1601
1684
|
*
|
|
1602
|
-
* Use when
|
|
1603
|
-
*
|
|
1685
|
+
* Use when you need to encode already typed schema values into an `Exit` whose
|
|
1686
|
+
* failure contains `SchemaError`.
|
|
1604
1687
|
*
|
|
1605
1688
|
* **Details**
|
|
1606
1689
|
*
|
|
@@ -1609,13 +1692,15 @@ export function encodeUnknownExit<S extends Encoder<unknown>>(schema: S, options
|
|
|
1609
1692
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1610
1693
|
* application options override creation options.
|
|
1611
1694
|
*
|
|
1695
|
+
* @see {@link SchemaParser.encodeExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1696
|
+
*
|
|
1612
1697
|
* @category encoding
|
|
1613
1698
|
* @since 4.0.0
|
|
1614
1699
|
*/
|
|
1615
1700
|
export const encodeExit: <S extends Encoder<unknown>>(
|
|
1616
1701
|
schema: S,
|
|
1617
|
-
options?:
|
|
1618
|
-
) => (input: S["Type"], options?:
|
|
1702
|
+
options?: SchemaAST.ParseOptions
|
|
1703
|
+
) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Encoded"], SchemaError> = encodeUnknownExit
|
|
1619
1704
|
|
|
1620
1705
|
/**
|
|
1621
1706
|
* Encodes an `unknown` input against a schema, returning an `Option` that is
|
|
@@ -1623,20 +1708,25 @@ export const encodeExit: <S extends Encoder<unknown>>(
|
|
|
1623
1708
|
*
|
|
1624
1709
|
* **When to use**
|
|
1625
1710
|
*
|
|
1626
|
-
* Use when the input type
|
|
1711
|
+
* Use when you do not know the input type statically and only need to know
|
|
1627
1712
|
* whether encoding succeeded.
|
|
1628
1713
|
*
|
|
1629
1714
|
* **Details**
|
|
1630
1715
|
*
|
|
1631
1716
|
* Prefer this over {@link encodeUnknownExit} or {@link encodeUnknownEffect}
|
|
1632
|
-
* when you don't need error details. For typed
|
|
1717
|
+
* when you don't need error details. For values already typed as the schema's
|
|
1718
|
+
* `Type` use {@link encodeOption}.
|
|
1633
1719
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1634
1720
|
* application options override creation options.
|
|
1635
1721
|
*
|
|
1636
1722
|
* @category encoding
|
|
1637
1723
|
* @since 3.10.0
|
|
1638
1724
|
*/
|
|
1639
|
-
export const encodeUnknownOption
|
|
1725
|
+
export const encodeUnknownOption: <S extends Encoder<unknown>>(
|
|
1726
|
+
schema: S,
|
|
1727
|
+
options?: SchemaAST.ParseOptions
|
|
1728
|
+
) => (input: unknown, options?: SchemaAST.ParseOptions) => Option_.Option<S["Encoded"]> =
|
|
1729
|
+
SchemaParser.encodeUnknownOption
|
|
1640
1730
|
|
|
1641
1731
|
/**
|
|
1642
1732
|
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
@@ -1645,7 +1735,8 @@ export const encodeUnknownOption = Parser.encodeUnknownOption
|
|
|
1645
1735
|
*
|
|
1646
1736
|
* **When to use**
|
|
1647
1737
|
*
|
|
1648
|
-
* Use when typed
|
|
1738
|
+
* Use when you already have a value typed as the schema's `Type` and only need
|
|
1739
|
+
* to know whether encoding succeeded.
|
|
1649
1740
|
*
|
|
1650
1741
|
* **Details**
|
|
1651
1742
|
*
|
|
@@ -1656,36 +1747,47 @@ export const encodeUnknownOption = Parser.encodeUnknownOption
|
|
|
1656
1747
|
* @category encoding
|
|
1657
1748
|
* @since 3.10.0
|
|
1658
1749
|
*/
|
|
1659
|
-
export const encodeOption
|
|
1750
|
+
export const encodeOption: <S extends Encoder<unknown>>(
|
|
1751
|
+
schema: S,
|
|
1752
|
+
options?: SchemaAST.ParseOptions
|
|
1753
|
+
) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Option_.Option<S["Encoded"]> = encodeUnknownOption
|
|
1660
1754
|
|
|
1661
1755
|
/**
|
|
1662
1756
|
* Encodes an `unknown` input against a schema, returning a `Result` that
|
|
1663
|
-
* succeeds with the encoded value or fails with a
|
|
1757
|
+
* succeeds with the encoded value or fails with a {@link SchemaError}.
|
|
1664
1758
|
*
|
|
1665
1759
|
* **When to use**
|
|
1666
1760
|
*
|
|
1667
|
-
* Use when the input type
|
|
1668
|
-
* `Result` with
|
|
1761
|
+
* Use when you do not know the input type statically and want encoding to
|
|
1762
|
+
* return a `Result` with `SchemaError` failure data.
|
|
1669
1763
|
*
|
|
1670
1764
|
* **Details**
|
|
1671
1765
|
*
|
|
1672
|
-
* For typed
|
|
1766
|
+
* For values already typed as the schema's `Type` use {@link encodeResult}.
|
|
1673
1767
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1674
1768
|
* application options override creation options.
|
|
1675
1769
|
*
|
|
1770
|
+
* @see {@link SchemaParser.encodeUnknownResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1771
|
+
*
|
|
1676
1772
|
* @category encoding
|
|
1677
1773
|
* @since 4.0.0
|
|
1678
1774
|
*/
|
|
1679
|
-
export
|
|
1775
|
+
export function encodeUnknownResult<S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1776
|
+
const parser = SchemaParser.encodeUnknownResult(schema, options)
|
|
1777
|
+
return (input: unknown, options?: SchemaAST.ParseOptions): Result_.Result<S["Encoded"], SchemaError> => {
|
|
1778
|
+
return Result_.mapError(parser(input, options), (issue) => new SchemaError(issue))
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1680
1781
|
|
|
1681
1782
|
/**
|
|
1682
1783
|
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
1683
|
-
* `Result` that succeeds with the encoded value or fails with a
|
|
1784
|
+
* `Result` that succeeds with the encoded value or fails with a
|
|
1785
|
+
* {@link SchemaError}.
|
|
1684
1786
|
*
|
|
1685
1787
|
* **When to use**
|
|
1686
1788
|
*
|
|
1687
|
-
* Use when
|
|
1688
|
-
* data.
|
|
1789
|
+
* Use when you already have a value typed as the schema's `Type` and want
|
|
1790
|
+
* encoding to return a `Result` with `SchemaError` failure data.
|
|
1689
1791
|
*
|
|
1690
1792
|
* **Details**
|
|
1691
1793
|
*
|
|
@@ -1693,29 +1795,43 @@ export const encodeUnknownResult = Parser.encodeUnknownResult
|
|
|
1693
1795
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1694
1796
|
* application options override creation options.
|
|
1695
1797
|
*
|
|
1798
|
+
* @see {@link SchemaParser.encodeResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1799
|
+
*
|
|
1696
1800
|
* @category encoding
|
|
1697
1801
|
* @since 4.0.0
|
|
1698
1802
|
*/
|
|
1699
|
-
export const encodeResult
|
|
1803
|
+
export const encodeResult: <S extends Encoder<unknown>>(
|
|
1804
|
+
schema: S,
|
|
1805
|
+
options?: SchemaAST.ParseOptions
|
|
1806
|
+
) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Result_.Result<S["Encoded"], SchemaError> =
|
|
1807
|
+
encodeUnknownResult
|
|
1700
1808
|
|
|
1701
1809
|
/**
|
|
1702
1810
|
* Encodes an `unknown` input against a schema, returning a `Promise` that
|
|
1703
|
-
* resolves with the encoded value or rejects with a
|
|
1811
|
+
* resolves with the encoded value or rejects with a {@link SchemaError}.
|
|
1704
1812
|
*
|
|
1705
1813
|
* **When to use**
|
|
1706
1814
|
*
|
|
1707
|
-
* Use when
|
|
1815
|
+
* Use when you need encoding of unknown input to return a JavaScript `Promise`
|
|
1816
|
+
* that rejects with `SchemaError`.
|
|
1708
1817
|
*
|
|
1709
1818
|
* **Details**
|
|
1710
1819
|
*
|
|
1711
|
-
* For typed
|
|
1820
|
+
* For values already typed as the schema's `Type` use {@link encodePromise}.
|
|
1712
1821
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1713
1822
|
* application options override creation options.
|
|
1714
1823
|
*
|
|
1824
|
+
* @see {@link SchemaParser.encodeUnknownPromise} for the adapter that rejects with `SchemaIssue.Issue` directly
|
|
1825
|
+
*
|
|
1715
1826
|
* @category encoding
|
|
1716
1827
|
* @since 3.10.0
|
|
1717
1828
|
*/
|
|
1718
|
-
export
|
|
1829
|
+
export function encodeUnknownPromise<S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1830
|
+
const parser = encodeUnknownEffect(schema, options)
|
|
1831
|
+
return (input: unknown, options?: SchemaAST.ParseOptions): Promise<S["Encoded"]> => {
|
|
1832
|
+
return Effect.runPromise(parser(input, options))
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1719
1835
|
|
|
1720
1836
|
/**
|
|
1721
1837
|
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
@@ -1724,7 +1840,8 @@ export const encodeUnknownPromise = Parser.encodeUnknownPromise
|
|
|
1724
1840
|
*
|
|
1725
1841
|
* **When to use**
|
|
1726
1842
|
*
|
|
1727
|
-
* Use when
|
|
1843
|
+
* Use when you already have a value typed as the schema's `Type` and need
|
|
1844
|
+
* encoding to return a JavaScript `Promise` that rejects with `SchemaError`.
|
|
1728
1845
|
*
|
|
1729
1846
|
* **Details**
|
|
1730
1847
|
*
|
|
@@ -1732,10 +1849,15 @@ export const encodeUnknownPromise = Parser.encodeUnknownPromise
|
|
|
1732
1849
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1733
1850
|
* application options override creation options.
|
|
1734
1851
|
*
|
|
1852
|
+
* @see {@link SchemaParser.encodePromise} for the adapter that rejects with `SchemaIssue.Issue` directly
|
|
1853
|
+
*
|
|
1735
1854
|
* @category encoding
|
|
1736
1855
|
* @since 3.10.0
|
|
1737
1856
|
*/
|
|
1738
|
-
export const encodePromise
|
|
1857
|
+
export const encodePromise: <S extends Encoder<unknown>>(
|
|
1858
|
+
schema: S,
|
|
1859
|
+
options?: SchemaAST.ParseOptions
|
|
1860
|
+
) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Promise<S["Encoded"]> = encodeUnknownPromise
|
|
1739
1861
|
|
|
1740
1862
|
/**
|
|
1741
1863
|
* Encodes an `unknown` input against a schema synchronously, throwing a
|
|
@@ -1743,21 +1865,28 @@ export const encodePromise = Parser.encodePromise
|
|
|
1743
1865
|
*
|
|
1744
1866
|
* **When to use**
|
|
1745
1867
|
*
|
|
1746
|
-
* Use when
|
|
1747
|
-
* mismatches
|
|
1868
|
+
* Use when you need to serialize unknown data at a synchronous boundary and
|
|
1869
|
+
* want schema mismatches to throw `SchemaError`.
|
|
1748
1870
|
*
|
|
1749
1871
|
* **Details**
|
|
1750
1872
|
*
|
|
1751
1873
|
* For non-throwing alternatives see {@link encodeUnknownOption},
|
|
1752
|
-
* {@link encodeUnknownExit}, or {@link encodeUnknownEffect}. For
|
|
1753
|
-
* use {@link encodeSync}.
|
|
1874
|
+
* {@link encodeUnknownExit}, or {@link encodeUnknownEffect}. For values
|
|
1875
|
+
* already typed as the schema's `Type` use {@link encodeSync}.
|
|
1754
1876
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1755
1877
|
* application options override creation options.
|
|
1756
1878
|
*
|
|
1879
|
+
* @see {@link SchemaParser.encodeUnknownSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1880
|
+
*
|
|
1757
1881
|
* @category encoding
|
|
1758
1882
|
* @since 4.0.0
|
|
1759
1883
|
*/
|
|
1760
|
-
export
|
|
1884
|
+
export function encodeUnknownSync<S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1885
|
+
const parser = encodeUnknownEffect(schema, options)
|
|
1886
|
+
return (input: unknown, options?: SchemaAST.ParseOptions): S["Encoded"] => {
|
|
1887
|
+
return Effect.runSync(parser(input, options) as Effect.Effect<S["Encoded"], SchemaError>)
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1761
1890
|
|
|
1762
1891
|
/**
|
|
1763
1892
|
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
@@ -1765,8 +1894,8 @@ export const encodeUnknownSync = Parser.encodeUnknownSync
|
|
|
1765
1894
|
*
|
|
1766
1895
|
* **When to use**
|
|
1767
1896
|
*
|
|
1768
|
-
* Use when
|
|
1769
|
-
*
|
|
1897
|
+
* Use when you already have a value typed as the schema's `Type` and want
|
|
1898
|
+
* schema mismatches to throw `SchemaError` synchronously.
|
|
1770
1899
|
*
|
|
1771
1900
|
* **Details**
|
|
1772
1901
|
*
|
|
@@ -1774,10 +1903,15 @@ export const encodeUnknownSync = Parser.encodeUnknownSync
|
|
|
1774
1903
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1775
1904
|
* application options override creation options.
|
|
1776
1905
|
*
|
|
1906
|
+
* @see {@link SchemaParser.encodeSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1907
|
+
*
|
|
1777
1908
|
* @category encoding
|
|
1778
1909
|
* @since 4.0.0
|
|
1779
1910
|
*/
|
|
1780
|
-
export const encodeSync
|
|
1911
|
+
export const encodeSync: <S extends Encoder<unknown>>(
|
|
1912
|
+
schema: S,
|
|
1913
|
+
options?: SchemaAST.ParseOptions
|
|
1914
|
+
) => (input: S["Type"], options?: SchemaAST.ParseOptions) => S["Encoded"] = encodeUnknownSync
|
|
1781
1915
|
|
|
1782
1916
|
/**
|
|
1783
1917
|
* Creates a schema from an AST (Abstract Syntax Tree) node.
|
|
@@ -1890,7 +2024,9 @@ interface optionalKeyLambda extends Lambda {
|
|
|
1890
2024
|
* @category combinators
|
|
1891
2025
|
* @since 4.0.0
|
|
1892
2026
|
*/
|
|
1893
|
-
export const optionalKey = Struct_.lambda<optionalKeyLambda>((schema) =>
|
|
2027
|
+
export const optionalKey = Struct_.lambda<optionalKeyLambda>((schema) =>
|
|
2028
|
+
make(SchemaAST.optionalKey(schema.ast), { schema })
|
|
2029
|
+
)
|
|
1894
2030
|
|
|
1895
2031
|
interface requiredKeyLambda extends Lambda {
|
|
1896
2032
|
<S extends Top>(self: optionalKey<S>): S
|
|
@@ -2020,7 +2156,9 @@ interface mutableKeyLambda extends Lambda {
|
|
|
2020
2156
|
* @category combinators
|
|
2021
2157
|
* @since 4.0.0
|
|
2022
2158
|
*/
|
|
2023
|
-
export const mutableKey = Struct_.lambda<mutableKeyLambda>((schema) =>
|
|
2159
|
+
export const mutableKey = Struct_.lambda<mutableKeyLambda>((schema) =>
|
|
2160
|
+
make(SchemaAST.mutableKey(schema.ast), { schema })
|
|
2161
|
+
)
|
|
2024
2162
|
|
|
2025
2163
|
interface readonlyKeyLambda extends Lambda {
|
|
2026
2164
|
<S extends Top>(self: mutableKey<S>): S
|
|
@@ -2079,7 +2217,7 @@ interface toTypeLambda extends Lambda {
|
|
|
2079
2217
|
* @category transforming
|
|
2080
2218
|
* @since 4.0.0
|
|
2081
2219
|
*/
|
|
2082
|
-
export const toType = Struct_.lambda<toTypeLambda>((schema) => make(
|
|
2220
|
+
export const toType = Struct_.lambda<toTypeLambda>((schema) => make(SchemaAST.toType(schema.ast), { schema }))
|
|
2083
2221
|
|
|
2084
2222
|
/**
|
|
2085
2223
|
* Type-level representation returned by {@link toEncoded}.
|
|
@@ -2093,7 +2231,7 @@ export interface toEncoded<S extends Top> extends
|
|
|
2093
2231
|
S["Encoded"],
|
|
2094
2232
|
never,
|
|
2095
2233
|
never,
|
|
2096
|
-
|
|
2234
|
+
SchemaAST.AST,
|
|
2097
2235
|
toEncoded<S>,
|
|
2098
2236
|
S["Encoded"],
|
|
2099
2237
|
S["Encoded"],
|
|
@@ -2119,7 +2257,7 @@ interface toEncodedLambda extends Lambda {
|
|
|
2119
2257
|
* @category transforming
|
|
2120
2258
|
* @since 4.0.0
|
|
2121
2259
|
*/
|
|
2122
|
-
export const toEncoded = Struct_.lambda<toEncodedLambda>((schema) => make(
|
|
2260
|
+
export const toEncoded = Struct_.lambda<toEncodedLambda>((schema) => make(SchemaAST.toEncoded(schema.ast), { schema }))
|
|
2123
2261
|
|
|
2124
2262
|
const FlipTypeId = "~effect/Schema/flip"
|
|
2125
2263
|
|
|
@@ -2135,7 +2273,7 @@ export interface flip<S extends Top> extends
|
|
|
2135
2273
|
S["Type"],
|
|
2136
2274
|
S["EncodingServices"],
|
|
2137
2275
|
S["DecodingServices"],
|
|
2138
|
-
|
|
2276
|
+
SchemaAST.AST,
|
|
2139
2277
|
flip<S>,
|
|
2140
2278
|
S["Encoded"],
|
|
2141
2279
|
S["Encoded"],
|
|
@@ -2183,9 +2321,9 @@ function isFlip$(schema: Top): schema is flip<any> {
|
|
|
2183
2321
|
export function flip<S extends Top>(schema: S): S extends flip<infer F> ? F["Rebuild"] : flip<S>
|
|
2184
2322
|
export function flip<S extends Top>(schema: S): flip<S> {
|
|
2185
2323
|
if (isFlip$(schema)) {
|
|
2186
|
-
return schema.schema.rebuild(
|
|
2324
|
+
return schema.schema.rebuild(SchemaAST.flip(schema.ast))
|
|
2187
2325
|
}
|
|
2188
|
-
return make(
|
|
2326
|
+
return make(SchemaAST.flip(schema.ast), { [FlipTypeId]: FlipTypeId, schema })
|
|
2189
2327
|
}
|
|
2190
2328
|
|
|
2191
2329
|
/**
|
|
@@ -2194,9 +2332,11 @@ export function flip<S extends Top>(schema: S): flip<S> {
|
|
|
2194
2332
|
* @category models
|
|
2195
2333
|
* @since 3.10.0
|
|
2196
2334
|
*/
|
|
2197
|
-
export interface Literal<L extends
|
|
2335
|
+
export interface Literal<L extends SchemaAST.LiteralValue>
|
|
2336
|
+
extends Bottom<L, L, never, never, SchemaAST.Literal, Literal<L>>
|
|
2337
|
+
{
|
|
2198
2338
|
readonly literal: L
|
|
2199
|
-
transform<L2 extends
|
|
2339
|
+
transform<L2 extends SchemaAST.LiteralValue>(to: L2): decodeTo<Literal<L2>, Literal<L>>
|
|
2200
2340
|
}
|
|
2201
2341
|
|
|
2202
2342
|
/**
|
|
@@ -2217,13 +2357,13 @@ export interface Literal<L extends AST.LiteralValue> extends Bottom<L, L, never,
|
|
|
2217
2357
|
* @category constructors
|
|
2218
2358
|
* @since 3.10.0
|
|
2219
2359
|
*/
|
|
2220
|
-
export function Literal<L extends
|
|
2221
|
-
const out = make<Literal<L>>(new
|
|
2360
|
+
export function Literal<L extends SchemaAST.LiteralValue>(literal: L): Literal<L> {
|
|
2361
|
+
const out = make<Literal<L>>(new SchemaAST.Literal(literal), {
|
|
2222
2362
|
literal,
|
|
2223
|
-
transform<L2 extends
|
|
2363
|
+
transform<L2 extends SchemaAST.LiteralValue>(to: L2): decodeTo<Literal<L2>, Literal<L>> {
|
|
2224
2364
|
return out.pipe(decodeTo(Literal(to), {
|
|
2225
|
-
decode:
|
|
2226
|
-
encode:
|
|
2365
|
+
decode: SchemaGetter.transform(() => to),
|
|
2366
|
+
encode: SchemaGetter.transform(() => literal)
|
|
2227
2367
|
}))
|
|
2228
2368
|
}
|
|
2229
2369
|
})
|
|
@@ -2306,7 +2446,7 @@ export interface TemplateLiteral<Parts extends TemplateLiteral.Parts> extends
|
|
|
2306
2446
|
TemplateLiteral.Encoded<Parts>,
|
|
2307
2447
|
never,
|
|
2308
2448
|
never,
|
|
2309
|
-
|
|
2449
|
+
SchemaAST.TemplateLiteral,
|
|
2310
2450
|
TemplateLiteral<Parts>
|
|
2311
2451
|
>
|
|
2312
2452
|
{
|
|
@@ -2314,13 +2454,18 @@ export interface TemplateLiteral<Parts extends TemplateLiteral.Parts> extends
|
|
|
2314
2454
|
}
|
|
2315
2455
|
|
|
2316
2456
|
function templateLiteralFromParts<Parts extends TemplateLiteral.Parts>(parts: Parts) {
|
|
2317
|
-
return new
|
|
2457
|
+
return new SchemaAST.TemplateLiteral(parts.map((part) => isSchema(part) ? part.ast : new SchemaAST.Literal(part)))
|
|
2318
2458
|
}
|
|
2319
2459
|
|
|
2320
2460
|
/**
|
|
2321
2461
|
* Creates a schema that validates strings matching a template literal pattern. Each part can be
|
|
2322
2462
|
* a literal string/number/bigint or a schema whose encoded type is a string, number, or bigint.
|
|
2323
2463
|
*
|
|
2464
|
+
* **When to use**
|
|
2465
|
+
*
|
|
2466
|
+
* Use when the decoded value should remain the matched string and you do not
|
|
2467
|
+
* need the individual template parts parsed into a tuple.
|
|
2468
|
+
*
|
|
2324
2469
|
* **Example** (URL path pattern)
|
|
2325
2470
|
*
|
|
2326
2471
|
* ```ts
|
|
@@ -2376,7 +2521,7 @@ export interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts> exte
|
|
|
2376
2521
|
TemplateLiteral.Encoded<Parts>,
|
|
2377
2522
|
never,
|
|
2378
2523
|
never,
|
|
2379
|
-
|
|
2524
|
+
SchemaAST.Arrays,
|
|
2380
2525
|
TemplateLiteralParser<Parts>
|
|
2381
2526
|
>
|
|
2382
2527
|
{
|
|
@@ -2422,7 +2567,7 @@ export function TemplateLiteralParser<const Parts extends TemplateLiteral.Parts>
|
|
|
2422
2567
|
* @since 4.0.0
|
|
2423
2568
|
*/
|
|
2424
2569
|
export interface Enum<A extends { [x: string]: string | number }>
|
|
2425
|
-
extends Bottom<A[keyof A], A[keyof A], never, never,
|
|
2570
|
+
extends Bottom<A[keyof A], A[keyof A], never, never, SchemaAST.Enum, Enum<A>>
|
|
2426
2571
|
{
|
|
2427
2572
|
readonly enums: A
|
|
2428
2573
|
}
|
|
@@ -2449,7 +2594,7 @@ export interface Enum<A extends { [x: string]: string | number }>
|
|
|
2449
2594
|
*/
|
|
2450
2595
|
export function Enum<A extends { [x: string]: string | number }>(enums: A): Enum<A> {
|
|
2451
2596
|
return make(
|
|
2452
|
-
new
|
|
2597
|
+
new SchemaAST.Enum(
|
|
2453
2598
|
Object.keys(enums).filter(
|
|
2454
2599
|
(key) => typeof enums[enums[key]] !== "number"
|
|
2455
2600
|
).map((key) => [key, enums[key]])
|
|
@@ -2464,7 +2609,7 @@ export function Enum<A extends { [x: string]: string | number }>(enums: A): Enum
|
|
|
2464
2609
|
* @category models
|
|
2465
2610
|
* @since 3.10.0
|
|
2466
2611
|
*/
|
|
2467
|
-
export interface Never extends Bottom<never, never, never, never,
|
|
2612
|
+
export interface Never extends Bottom<never, never, never, never, SchemaAST.Never, Never> {}
|
|
2468
2613
|
|
|
2469
2614
|
/**
|
|
2470
2615
|
* Schema for the `never` type. Always fails validation — no value satisfies it.
|
|
@@ -2472,7 +2617,7 @@ export interface Never extends Bottom<never, never, never, never, AST.Never, Nev
|
|
|
2472
2617
|
* @category schemas
|
|
2473
2618
|
* @since 3.10.0
|
|
2474
2619
|
*/
|
|
2475
|
-
export const Never: Never = make(
|
|
2620
|
+
export const Never: Never = make(SchemaAST.never)
|
|
2476
2621
|
|
|
2477
2622
|
/**
|
|
2478
2623
|
* Type-level representation of {@link Any}.
|
|
@@ -2480,7 +2625,7 @@ export const Never: Never = make(AST.never)
|
|
|
2480
2625
|
* @category models
|
|
2481
2626
|
* @since 3.10.0
|
|
2482
2627
|
*/
|
|
2483
|
-
export interface Any extends Bottom<any, any, never, never,
|
|
2628
|
+
export interface Any extends Bottom<any, any, never, never, SchemaAST.Any, Any> {}
|
|
2484
2629
|
|
|
2485
2630
|
/**
|
|
2486
2631
|
* Schema for the `any` type. Accepts any value without validation.
|
|
@@ -2489,7 +2634,7 @@ export interface Any extends Bottom<any, any, never, never, AST.Any, Any> {}
|
|
|
2489
2634
|
* @category schemas
|
|
2490
2635
|
* @since 3.10.0
|
|
2491
2636
|
*/
|
|
2492
|
-
export const Any: Any = make(
|
|
2637
|
+
export const Any: Any = make(SchemaAST.any)
|
|
2493
2638
|
|
|
2494
2639
|
/**
|
|
2495
2640
|
* Type-level representation of {@link Unknown}.
|
|
@@ -2497,16 +2642,21 @@ export const Any: Any = make(AST.any)
|
|
|
2497
2642
|
* @category models
|
|
2498
2643
|
* @since 3.10.0
|
|
2499
2644
|
*/
|
|
2500
|
-
export interface Unknown extends Bottom<unknown, unknown, never, never,
|
|
2645
|
+
export interface Unknown extends Bottom<unknown, unknown, never, never, SchemaAST.Unknown, Unknown> {}
|
|
2501
2646
|
|
|
2502
2647
|
/**
|
|
2503
2648
|
* Schema for the `unknown` type. Accepts any value without validation.
|
|
2504
2649
|
*
|
|
2650
|
+
* **When to use**
|
|
2651
|
+
*
|
|
2652
|
+
* Use as a top schema when you need to accept any input while preserving
|
|
2653
|
+
* TypeScript's `unknown` safety at use sites.
|
|
2654
|
+
*
|
|
2505
2655
|
* @see {@link Any} for the `any` variant.
|
|
2506
2656
|
* @category schemas
|
|
2507
2657
|
* @since 3.10.0
|
|
2508
2658
|
*/
|
|
2509
|
-
export const Unknown: Unknown = make(
|
|
2659
|
+
export const Unknown: Unknown = make(SchemaAST.unknown)
|
|
2510
2660
|
|
|
2511
2661
|
/**
|
|
2512
2662
|
* Type-level representation of {@link Null}.
|
|
@@ -2514,7 +2664,7 @@ export const Unknown: Unknown = make(AST.unknown)
|
|
|
2514
2664
|
* @category models
|
|
2515
2665
|
* @since 3.10.0
|
|
2516
2666
|
*/
|
|
2517
|
-
export interface Null extends Bottom<null, null, never, never,
|
|
2667
|
+
export interface Null extends Bottom<null, null, never, never, SchemaAST.Null, Null> {}
|
|
2518
2668
|
|
|
2519
2669
|
/**
|
|
2520
2670
|
* Schema for the `null` literal. Validates that the input is strictly `null`.
|
|
@@ -2523,7 +2673,7 @@ export interface Null extends Bottom<null, null, never, never, AST.Null, Null> {
|
|
|
2523
2673
|
* @category schemas
|
|
2524
2674
|
* @since 3.10.0
|
|
2525
2675
|
*/
|
|
2526
|
-
export const Null: Null = make(
|
|
2676
|
+
export const Null: Null = make(SchemaAST.null)
|
|
2527
2677
|
|
|
2528
2678
|
/**
|
|
2529
2679
|
* Type-level representation of {@link Undefined}.
|
|
@@ -2531,7 +2681,7 @@ export const Null: Null = make(AST.null)
|
|
|
2531
2681
|
* @category models
|
|
2532
2682
|
* @since 3.10.0
|
|
2533
2683
|
*/
|
|
2534
|
-
export interface Undefined extends Bottom<undefined, undefined, never, never,
|
|
2684
|
+
export interface Undefined extends Bottom<undefined, undefined, never, never, SchemaAST.Undefined, Undefined> {}
|
|
2535
2685
|
|
|
2536
2686
|
/**
|
|
2537
2687
|
* Schema for the `undefined` literal. Validates that the input is strictly `undefined`.
|
|
@@ -2540,7 +2690,7 @@ export interface Undefined extends Bottom<undefined, undefined, never, never, AS
|
|
|
2540
2690
|
* @category schemas
|
|
2541
2691
|
* @since 3.10.0
|
|
2542
2692
|
*/
|
|
2543
|
-
export const Undefined: Undefined = make(
|
|
2693
|
+
export const Undefined: Undefined = make(SchemaAST.undefined)
|
|
2544
2694
|
|
|
2545
2695
|
/**
|
|
2546
2696
|
* Type-level representation of {@link String}.
|
|
@@ -2548,7 +2698,7 @@ export const Undefined: Undefined = make(AST.undefined)
|
|
|
2548
2698
|
* @category models
|
|
2549
2699
|
* @since 4.0.0
|
|
2550
2700
|
*/
|
|
2551
|
-
export interface String extends Bottom<string, string, never, never,
|
|
2701
|
+
export interface String extends Bottom<string, string, never, never, SchemaAST.String, String> {}
|
|
2552
2702
|
|
|
2553
2703
|
/**
|
|
2554
2704
|
* Schema for `string` values. Validates that the input is `typeof` `"string"`.
|
|
@@ -2556,7 +2706,7 @@ export interface String extends Bottom<string, string, never, never, AST.String,
|
|
|
2556
2706
|
* @category schemas
|
|
2557
2707
|
* @since 4.0.0
|
|
2558
2708
|
*/
|
|
2559
|
-
export const String: String = make(
|
|
2709
|
+
export const String: String = make(SchemaAST.string)
|
|
2560
2710
|
|
|
2561
2711
|
/**
|
|
2562
2712
|
* Type-level representation of {@link Number}.
|
|
@@ -2564,7 +2714,7 @@ export const String: String = make(AST.string)
|
|
|
2564
2714
|
* @category models
|
|
2565
2715
|
* @since 4.0.0
|
|
2566
2716
|
*/
|
|
2567
|
-
export interface Number extends Bottom<number, number, never, never,
|
|
2717
|
+
export interface Number extends Bottom<number, number, never, never, SchemaAST.Number, Number> {}
|
|
2568
2718
|
|
|
2569
2719
|
/**
|
|
2570
2720
|
* Schema for `number` values, including `NaN`, `Infinity`, and `-Infinity`.
|
|
@@ -2580,7 +2730,7 @@ export interface Number extends Bottom<number, number, never, never, AST.Number,
|
|
|
2580
2730
|
* @category schemas
|
|
2581
2731
|
* @since 4.0.0
|
|
2582
2732
|
*/
|
|
2583
|
-
export const Number: Number = make(
|
|
2733
|
+
export const Number: Number = make(SchemaAST.number)
|
|
2584
2734
|
|
|
2585
2735
|
/**
|
|
2586
2736
|
* Type-level representation of {@link Boolean}.
|
|
@@ -2588,7 +2738,7 @@ export const Number: Number = make(AST.number)
|
|
|
2588
2738
|
* @category models
|
|
2589
2739
|
* @since 4.0.0
|
|
2590
2740
|
*/
|
|
2591
|
-
export interface Boolean extends Bottom<boolean, boolean, never, never,
|
|
2741
|
+
export interface Boolean extends Bottom<boolean, boolean, never, never, SchemaAST.Boolean, Boolean> {}
|
|
2592
2742
|
|
|
2593
2743
|
/**
|
|
2594
2744
|
* Schema for `boolean` values. Validates that the input is `typeof` `"boolean"`.
|
|
@@ -2602,7 +2752,7 @@ export interface Boolean extends Bottom<boolean, boolean, never, never, AST.Bool
|
|
|
2602
2752
|
* @category boolean
|
|
2603
2753
|
* @since 4.0.0
|
|
2604
2754
|
*/
|
|
2605
|
-
export const Boolean: Boolean = make(
|
|
2755
|
+
export const Boolean: Boolean = make(SchemaAST.boolean)
|
|
2606
2756
|
|
|
2607
2757
|
/**
|
|
2608
2758
|
* Type-level representation of {@link Symbol}.
|
|
@@ -2610,7 +2760,7 @@ export const Boolean: Boolean = make(AST.boolean)
|
|
|
2610
2760
|
* @category models
|
|
2611
2761
|
* @since 4.0.0
|
|
2612
2762
|
*/
|
|
2613
|
-
export interface Symbol extends Bottom<symbol, symbol, never, never,
|
|
2763
|
+
export interface Symbol extends Bottom<symbol, symbol, never, never, SchemaAST.Symbol, Symbol> {}
|
|
2614
2764
|
|
|
2615
2765
|
/**
|
|
2616
2766
|
* Schema for `symbol` values. Validates that the input is `typeof` `"symbol"`.
|
|
@@ -2619,7 +2769,7 @@ export interface Symbol extends Bottom<symbol, symbol, never, never, AST.Symbol,
|
|
|
2619
2769
|
* @category schemas
|
|
2620
2770
|
* @since 4.0.0
|
|
2621
2771
|
*/
|
|
2622
|
-
export const Symbol: Symbol = make(
|
|
2772
|
+
export const Symbol: Symbol = make(SchemaAST.symbol)
|
|
2623
2773
|
|
|
2624
2774
|
/**
|
|
2625
2775
|
* Type-level representation of {@link BigInt}.
|
|
@@ -2627,7 +2777,7 @@ export const Symbol: Symbol = make(AST.symbol)
|
|
|
2627
2777
|
* @category models
|
|
2628
2778
|
* @since 4.0.0
|
|
2629
2779
|
*/
|
|
2630
|
-
export interface BigInt extends Bottom<bigint, bigint, never, never,
|
|
2780
|
+
export interface BigInt extends Bottom<bigint, bigint, never, never, SchemaAST.BigInt, BigInt> {}
|
|
2631
2781
|
|
|
2632
2782
|
/**
|
|
2633
2783
|
* Schema for `bigint` values. Validates that the input is `typeof` `"bigint"`.
|
|
@@ -2642,7 +2792,7 @@ export interface BigInt extends Bottom<bigint, bigint, never, never, AST.BigInt,
|
|
|
2642
2792
|
* @category schemas
|
|
2643
2793
|
* @since 4.0.0
|
|
2644
2794
|
*/
|
|
2645
|
-
export const BigInt: BigInt = make(
|
|
2795
|
+
export const BigInt: BigInt = make(SchemaAST.bigInt)
|
|
2646
2796
|
|
|
2647
2797
|
/**
|
|
2648
2798
|
* Type-level representation of {@link Void}.
|
|
@@ -2650,7 +2800,7 @@ export const BigInt: BigInt = make(AST.bigInt)
|
|
|
2650
2800
|
* @category models
|
|
2651
2801
|
* @since 3.10.0
|
|
2652
2802
|
*/
|
|
2653
|
-
export interface Void extends Bottom<void, void, never, never,
|
|
2803
|
+
export interface Void extends Bottom<void, void, never, never, SchemaAST.Void, Void> {}
|
|
2654
2804
|
|
|
2655
2805
|
/**
|
|
2656
2806
|
* Schema for the `void` type. Accepts `undefined` as the encoded value.
|
|
@@ -2658,7 +2808,7 @@ export interface Void extends Bottom<void, void, never, never, AST.Void, Void> {
|
|
|
2658
2808
|
* @category schemas
|
|
2659
2809
|
* @since 3.10.0
|
|
2660
2810
|
*/
|
|
2661
|
-
export const Void: Void = make(
|
|
2811
|
+
export const Void: Void = make(SchemaAST.void)
|
|
2662
2812
|
|
|
2663
2813
|
/**
|
|
2664
2814
|
* Type-level representation of {@link ObjectKeyword}.
|
|
@@ -2666,7 +2816,7 @@ export const Void: Void = make(AST.void)
|
|
|
2666
2816
|
* @category models
|
|
2667
2817
|
* @since 4.0.0
|
|
2668
2818
|
*/
|
|
2669
|
-
export interface ObjectKeyword extends Bottom<object, object, never, never,
|
|
2819
|
+
export interface ObjectKeyword extends Bottom<object, object, never, never, SchemaAST.ObjectKeyword, ObjectKeyword> {}
|
|
2670
2820
|
|
|
2671
2821
|
/**
|
|
2672
2822
|
* Schema for the `object` type. Validates that the input is a non-null object or function
|
|
@@ -2675,7 +2825,7 @@ export interface ObjectKeyword extends Bottom<object, object, never, never, AST.
|
|
|
2675
2825
|
* @category schemas
|
|
2676
2826
|
* @since 4.0.0
|
|
2677
2827
|
*/
|
|
2678
|
-
export const ObjectKeyword: ObjectKeyword = make(
|
|
2828
|
+
export const ObjectKeyword: ObjectKeyword = make(SchemaAST.objectKeyword)
|
|
2679
2829
|
|
|
2680
2830
|
/**
|
|
2681
2831
|
* Type-level representation returned by {@link UniqueSymbol}.
|
|
@@ -2684,7 +2834,7 @@ export const ObjectKeyword: ObjectKeyword = make(AST.objectKeyword)
|
|
|
2684
2834
|
* @since 4.0.0
|
|
2685
2835
|
*/
|
|
2686
2836
|
export interface UniqueSymbol<sym extends symbol>
|
|
2687
|
-
extends Bottom<sym, sym, never, never,
|
|
2837
|
+
extends Bottom<sym, sym, never, never, SchemaAST.UniqueSymbol, UniqueSymbol<sym>>
|
|
2688
2838
|
{}
|
|
2689
2839
|
|
|
2690
2840
|
/**
|
|
@@ -2704,7 +2854,7 @@ export interface UniqueSymbol<sym extends symbol>
|
|
|
2704
2854
|
* @since 4.0.0
|
|
2705
2855
|
*/
|
|
2706
2856
|
export function UniqueSymbol<const sym extends symbol>(symbol: sym): UniqueSymbol<sym> {
|
|
2707
|
-
return make(new
|
|
2857
|
+
return make(new SchemaAST.UniqueSymbol(symbol))
|
|
2708
2858
|
}
|
|
2709
2859
|
|
|
2710
2860
|
/**
|
|
@@ -2880,7 +3030,7 @@ export interface Struct<Fields extends Struct.Fields> extends
|
|
|
2880
3030
|
Struct.Encoded<Fields>,
|
|
2881
3031
|
Struct.DecodingServices<Fields>,
|
|
2882
3032
|
Struct.EncodingServices<Fields>,
|
|
2883
|
-
|
|
3033
|
+
SchemaAST.Objects,
|
|
2884
3034
|
Struct<Fields>,
|
|
2885
3035
|
Struct.MakeIn<Fields>,
|
|
2886
3036
|
Struct.Iso<Fields>
|
|
@@ -2932,7 +3082,7 @@ export interface Struct<Fields extends Struct.Fields> extends
|
|
|
2932
3082
|
): Struct<Simplify<Readonly<To>>>
|
|
2933
3083
|
}
|
|
2934
3084
|
|
|
2935
|
-
function makeStruct<const Fields extends Struct.Fields>(ast:
|
|
3085
|
+
function makeStruct<const Fields extends Struct.Fields>(ast: SchemaAST.Objects, fields: Fields): Struct<Fields> {
|
|
2936
3086
|
return make(ast, {
|
|
2937
3087
|
fields,
|
|
2938
3088
|
mapFields<To extends Struct.Fields>(
|
|
@@ -2943,7 +3093,7 @@ function makeStruct<const Fields extends Struct.Fields>(ast: AST.Objects, fields
|
|
|
2943
3093
|
} | undefined
|
|
2944
3094
|
): Struct<To> {
|
|
2945
3095
|
const fields = f(this.fields)
|
|
2946
|
-
return makeStruct(
|
|
3096
|
+
return makeStruct(SchemaAST.struct(fields, options?.unsafePreserveChecks ? this.ast.checks : undefined), fields)
|
|
2947
3097
|
}
|
|
2948
3098
|
})
|
|
2949
3099
|
}
|
|
@@ -2982,7 +3132,7 @@ function makeStruct<const Fields extends Struct.Fields>(ast: AST.Objects, fields
|
|
|
2982
3132
|
* @since 3.10.0
|
|
2983
3133
|
*/
|
|
2984
3134
|
export function Struct<const Fields extends Struct.Fields>(fields: Fields): Struct<Fields> {
|
|
2985
|
-
return makeStruct(
|
|
3135
|
+
return makeStruct(SchemaAST.struct(fields, undefined), fields)
|
|
2986
3136
|
}
|
|
2987
3137
|
|
|
2988
3138
|
interface fieldsAssign<NewFields extends Struct.Fields> extends Lambda {
|
|
@@ -2999,8 +3149,8 @@ interface fieldsAssign<NewFields extends Struct.Fields> extends Lambda {
|
|
|
2999
3149
|
*
|
|
3000
3150
|
* **When to use**
|
|
3001
3151
|
*
|
|
3002
|
-
* Use to add the same fields to an existing struct or
|
|
3003
|
-
*
|
|
3152
|
+
* Use to add the same fields to an existing struct or every struct member of a
|
|
3153
|
+
* union.
|
|
3004
3154
|
*
|
|
3005
3155
|
* **Details**
|
|
3006
3156
|
*
|
|
@@ -3091,7 +3241,7 @@ export function encodeKeys<
|
|
|
3091
3241
|
}
|
|
3092
3242
|
return Struct(fields).pipe(decodeTo(
|
|
3093
3243
|
self,
|
|
3094
|
-
|
|
3244
|
+
SchemaTransformation.transform<any, any>({
|
|
3095
3245
|
decode: Struct_.renameKeys(reverseMapping),
|
|
3096
3246
|
encode: Struct_.renameKeys(mapping)
|
|
3097
3247
|
})
|
|
@@ -3143,7 +3293,7 @@ export function extendTo<S extends Struct<Struct.Fields>, const Fields extends S
|
|
|
3143
3293
|
const to = Struct({ ...f, ...fields })
|
|
3144
3294
|
return self.pipe(decodeTo(
|
|
3145
3295
|
to,
|
|
3146
|
-
|
|
3296
|
+
SchemaTransformation.transform({
|
|
3147
3297
|
decode: (input) => {
|
|
3148
3298
|
const out: any = { ...input }
|
|
3149
3299
|
for (const k in fields) {
|
|
@@ -3302,7 +3452,7 @@ export interface $Record<Key extends Record.Key, Value extends Top> extends
|
|
|
3302
3452
|
Record.Encoded<Key, Value>,
|
|
3303
3453
|
Record.DecodingServices<Key, Value>,
|
|
3304
3454
|
Record.EncodingServices<Key, Value>,
|
|
3305
|
-
|
|
3455
|
+
SchemaAST.Objects,
|
|
3306
3456
|
$Record<Key, Value>,
|
|
3307
3457
|
Simplify<Record.MakeIn<Key, Value>>,
|
|
3308
3458
|
Record.Iso<Key, Value>
|
|
@@ -3344,9 +3494,9 @@ export function Record<Key extends Record.Key, Value extends Top>(
|
|
|
3344
3494
|
}
|
|
3345
3495
|
): $Record<Key, Value> {
|
|
3346
3496
|
const keyValueCombiner = options?.keyValueCombiner?.decode || options?.keyValueCombiner?.encode
|
|
3347
|
-
? new
|
|
3497
|
+
? new SchemaAST.KeyValueCombiner(options.keyValueCombiner.decode, options.keyValueCombiner.encode)
|
|
3348
3498
|
: undefined
|
|
3349
|
-
return make(
|
|
3499
|
+
return make(SchemaAST.record(key.ast, value.ast, keyValueCombiner), { key, value })
|
|
3350
3500
|
}
|
|
3351
3501
|
|
|
3352
3502
|
/**
|
|
@@ -3367,7 +3517,7 @@ export declare namespace StructWithRest {
|
|
|
3367
3517
|
* @category utility types
|
|
3368
3518
|
* @since 4.0.0
|
|
3369
3519
|
*/
|
|
3370
|
-
export type Objects = Top & { readonly ast:
|
|
3520
|
+
export type Objects = Top & { readonly ast: SchemaAST.Objects }
|
|
3371
3521
|
|
|
3372
3522
|
/**
|
|
3373
3523
|
* Readonly list of record schemas that provide the additional index signatures
|
|
@@ -3382,6 +3532,14 @@ export declare namespace StructWithRest {
|
|
|
3382
3532
|
Head & MergeTuple<Tail>
|
|
3383
3533
|
: {}
|
|
3384
3534
|
|
|
3535
|
+
type Intersect<
|
|
3536
|
+
S extends Objects,
|
|
3537
|
+
Records extends StructWithRest.Records,
|
|
3538
|
+
Side extends "Type" | "Iso" | "Encoded" | "~type.make"
|
|
3539
|
+
> =
|
|
3540
|
+
& S[Side]
|
|
3541
|
+
& MergeTuple<{ readonly [K in keyof Records]: Records[K][Side] }>
|
|
3542
|
+
|
|
3385
3543
|
/**
|
|
3386
3544
|
* Computes the decoded type for `StructWithRest` by intersecting the base object
|
|
3387
3545
|
* schema's decoded `Type` with the decoded types of all rest record schemas.
|
|
@@ -3389,9 +3547,7 @@ export declare namespace StructWithRest {
|
|
|
3389
3547
|
* @category utility types
|
|
3390
3548
|
* @since 3.10.0
|
|
3391
3549
|
*/
|
|
3392
|
-
export type Type<S extends Objects, Records extends StructWithRest.Records> =
|
|
3393
|
-
& S["Type"]
|
|
3394
|
-
& MergeTuple<{ readonly [K in keyof Records]: Records[K]["Type"] }>
|
|
3550
|
+
export type Type<S extends Objects, Records extends StructWithRest.Records> = Intersect<S, Records, "Type">
|
|
3395
3551
|
|
|
3396
3552
|
/**
|
|
3397
3553
|
* Computes the iso type for `StructWithRest` by intersecting the base object
|
|
@@ -3400,9 +3556,7 @@ export declare namespace StructWithRest {
|
|
|
3400
3556
|
* @category utility types
|
|
3401
3557
|
* @since 4.0.0
|
|
3402
3558
|
*/
|
|
3403
|
-
export type Iso<S extends Objects, Records extends StructWithRest.Records> =
|
|
3404
|
-
& S["Iso"]
|
|
3405
|
-
& MergeTuple<{ readonly [K in keyof Records]: Records[K]["Iso"] }>
|
|
3559
|
+
export type Iso<S extends Objects, Records extends StructWithRest.Records> = Intersect<S, Records, "Iso">
|
|
3406
3560
|
|
|
3407
3561
|
/**
|
|
3408
3562
|
* Computes the encoded type for `StructWithRest` by intersecting the base object
|
|
@@ -3411,9 +3565,25 @@ export declare namespace StructWithRest {
|
|
|
3411
3565
|
* @category utility types
|
|
3412
3566
|
* @since 3.10.0
|
|
3413
3567
|
*/
|
|
3414
|
-
export type Encoded<S extends Objects, Records extends StructWithRest.Records> =
|
|
3415
|
-
|
|
3416
|
-
|
|
3568
|
+
export type Encoded<S extends Objects, Records extends StructWithRest.Records> = Intersect<S, Records, "Encoded">
|
|
3569
|
+
|
|
3570
|
+
/**
|
|
3571
|
+
* Computes the input type accepted when constructing a `StructWithRest` value by
|
|
3572
|
+
* intersecting the base object's make input with the make inputs of all rest
|
|
3573
|
+
* record schemas.
|
|
3574
|
+
*
|
|
3575
|
+
* @category utility types
|
|
3576
|
+
* @since 4.0.0
|
|
3577
|
+
*/
|
|
3578
|
+
export type MakeIn<S extends Objects, Records extends StructWithRest.Records> = Intersect<S, Records, "~type.make">
|
|
3579
|
+
|
|
3580
|
+
type Services<
|
|
3581
|
+
S extends Objects,
|
|
3582
|
+
Records extends StructWithRest.Records,
|
|
3583
|
+
Side extends "DecodingServices" | "EncodingServices"
|
|
3584
|
+
> =
|
|
3585
|
+
| S[Side]
|
|
3586
|
+
| { [K in keyof Records]: Records[K][Side] }[number]
|
|
3417
3587
|
|
|
3418
3588
|
/**
|
|
3419
3589
|
* Union of the decoding service requirements of the base object schema and all
|
|
@@ -3422,9 +3592,11 @@ export declare namespace StructWithRest {
|
|
|
3422
3592
|
* @category utility types
|
|
3423
3593
|
* @since 4.0.0
|
|
3424
3594
|
*/
|
|
3425
|
-
export type DecodingServices<S extends Objects, Records extends StructWithRest.Records> =
|
|
3426
|
-
|
|
3427
|
-
|
|
3595
|
+
export type DecodingServices<S extends Objects, Records extends StructWithRest.Records> = Services<
|
|
3596
|
+
S,
|
|
3597
|
+
Records,
|
|
3598
|
+
"DecodingServices"
|
|
3599
|
+
>
|
|
3428
3600
|
|
|
3429
3601
|
/**
|
|
3430
3602
|
* Union of the encoding service requirements of the base object schema and all
|
|
@@ -3433,21 +3605,43 @@ export declare namespace StructWithRest {
|
|
|
3433
3605
|
* @category utility types
|
|
3434
3606
|
* @since 4.0.0
|
|
3435
3607
|
*/
|
|
3436
|
-
export type EncodingServices<S extends Objects, Records extends StructWithRest.Records> =
|
|
3437
|
-
|
|
3438
|
-
|
|
3608
|
+
export type EncodingServices<S extends Objects, Records extends StructWithRest.Records> = Services<
|
|
3609
|
+
S,
|
|
3610
|
+
Records,
|
|
3611
|
+
"EncodingServices"
|
|
3612
|
+
>
|
|
3613
|
+
|
|
3614
|
+
type IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>> = {
|
|
3615
|
+
[K in OK]: Required<Pick<A, K>>[K] extends B[K] ? never : K
|
|
3616
|
+
}[OK]
|
|
3617
|
+
|
|
3618
|
+
type IncompatibleSideKeys<
|
|
3619
|
+
S extends Objects,
|
|
3620
|
+
Records extends StructWithRest.Records,
|
|
3621
|
+
Side extends "Type" | "Encoded" | "Iso" | "~type.make"
|
|
3622
|
+
> = {
|
|
3623
|
+
[I in keyof Records]: Records[I][Side] extends object ? IncompatibleKeys<S[Side], Records[I][Side]> : never
|
|
3624
|
+
}[number]
|
|
3439
3625
|
|
|
3440
3626
|
/**
|
|
3441
|
-
*
|
|
3442
|
-
* intersecting the base object's make input with the make inputs of all rest
|
|
3443
|
-
* record schemas.
|
|
3627
|
+
* Validates that the records are compatible with the struct.
|
|
3444
3628
|
*
|
|
3445
3629
|
* @category utility types
|
|
3446
3630
|
* @since 4.0.0
|
|
3447
3631
|
*/
|
|
3448
|
-
export type
|
|
3449
|
-
|
|
3450
|
-
|
|
3632
|
+
export type ValidateRecords<S extends Objects, Records extends StructWithRest.Records> = [
|
|
3633
|
+
| IncompatibleSideKeys<S, Records, "Type">
|
|
3634
|
+
| IncompatibleSideKeys<S, Records, "Encoded">
|
|
3635
|
+
| IncompatibleSideKeys<S, Records, "Iso">
|
|
3636
|
+
| IncompatibleSideKeys<S, Records, "~type.make">
|
|
3637
|
+
] extends [never] ? unknown
|
|
3638
|
+
: {
|
|
3639
|
+
"incompatible index signatures":
|
|
3640
|
+
| IncompatibleSideKeys<S, Records, "Type">
|
|
3641
|
+
| IncompatibleSideKeys<S, Records, "Encoded">
|
|
3642
|
+
| IncompatibleSideKeys<S, Records, "Iso">
|
|
3643
|
+
| IncompatibleSideKeys<S, Records, "~type.make">
|
|
3644
|
+
}
|
|
3451
3645
|
}
|
|
3452
3646
|
|
|
3453
3647
|
/**
|
|
@@ -3465,7 +3659,7 @@ export interface StructWithRest<
|
|
|
3465
3659
|
Simplify<StructWithRest.Encoded<S, Records>>,
|
|
3466
3660
|
StructWithRest.DecodingServices<S, Records>,
|
|
3467
3661
|
StructWithRest.EncodingServices<S, Records>,
|
|
3468
|
-
|
|
3662
|
+
SchemaAST.Objects,
|
|
3469
3663
|
StructWithRest<S, Records>,
|
|
3470
3664
|
Simplify<StructWithRest.MakeIn<S, Records>>,
|
|
3471
3665
|
Simplify<StructWithRest.Iso<S, Records>>
|
|
@@ -3486,10 +3680,10 @@ export interface StructWithRest<
|
|
|
3486
3680
|
*
|
|
3487
3681
|
* const schema = Schema.StructWithRest(
|
|
3488
3682
|
* Schema.Struct({ id: Schema.Number }),
|
|
3489
|
-
* [Schema.Record(Schema.String, Schema.
|
|
3683
|
+
* [Schema.Record(Schema.String, Schema.Number)]
|
|
3490
3684
|
* )
|
|
3491
3685
|
*
|
|
3492
|
-
* // { readonly id: number
|
|
3686
|
+
* // { readonly id: number, readonly [x: string]: number }
|
|
3493
3687
|
* type T = typeof schema.Type
|
|
3494
3688
|
* ```
|
|
3495
3689
|
*
|
|
@@ -3501,9 +3695,9 @@ export function StructWithRest<
|
|
|
3501
3695
|
const Records extends StructWithRest.Records
|
|
3502
3696
|
>(
|
|
3503
3697
|
schema: S,
|
|
3504
|
-
records: Records
|
|
3698
|
+
records: Records & StructWithRest.ValidateRecords<S, Records>
|
|
3505
3699
|
): StructWithRest<S, Records> {
|
|
3506
|
-
return make(
|
|
3700
|
+
return make(SchemaAST.structWithRest(schema.ast, records.map(SchemaAST.getAST)), { schema, records })
|
|
3507
3701
|
}
|
|
3508
3702
|
|
|
3509
3703
|
/**
|
|
@@ -3649,7 +3843,7 @@ export interface Tuple<Elements extends Tuple.Elements> extends
|
|
|
3649
3843
|
Tuple.Encoded<Elements>,
|
|
3650
3844
|
Tuple.DecodingServices<Elements>,
|
|
3651
3845
|
Tuple.EncodingServices<Elements>,
|
|
3652
|
-
|
|
3846
|
+
SchemaAST.Arrays,
|
|
3653
3847
|
Tuple<Elements>,
|
|
3654
3848
|
Tuple.MakeIn<Elements>,
|
|
3655
3849
|
Tuple.Iso<Elements>
|
|
@@ -3680,7 +3874,7 @@ export interface Tuple<Elements extends Tuple.Elements> extends
|
|
|
3680
3874
|
): Tuple<Simplify<Readonly<To>>>
|
|
3681
3875
|
}
|
|
3682
3876
|
|
|
3683
|
-
function makeTuple<Elements extends Tuple.Elements>(ast:
|
|
3877
|
+
function makeTuple<Elements extends Tuple.Elements>(ast: SchemaAST.Arrays, elements: Elements): Tuple<Elements> {
|
|
3684
3878
|
return make(ast, {
|
|
3685
3879
|
elements,
|
|
3686
3880
|
mapElements<To extends Tuple.Elements>(
|
|
@@ -3691,7 +3885,7 @@ function makeTuple<Elements extends Tuple.Elements>(ast: AST.Arrays, elements: E
|
|
|
3691
3885
|
} | undefined
|
|
3692
3886
|
): Tuple<Simplify<Readonly<To>>> {
|
|
3693
3887
|
const elements = f(this.elements)
|
|
3694
|
-
return makeTuple(
|
|
3888
|
+
return makeTuple(SchemaAST.tuple(elements, options?.unsafePreserveChecks ? this.ast.checks : undefined), elements)
|
|
3695
3889
|
}
|
|
3696
3890
|
})
|
|
3697
3891
|
}
|
|
@@ -3715,7 +3909,7 @@ function makeTuple<Elements extends Tuple.Elements>(ast: AST.Arrays, elements: E
|
|
|
3715
3909
|
* @since 3.10.0
|
|
3716
3910
|
*/
|
|
3717
3911
|
export function Tuple<const Elements extends ReadonlyArray<Top>>(elements: Elements): Tuple<Elements> {
|
|
3718
|
-
return makeTuple(
|
|
3912
|
+
return makeTuple(SchemaAST.tuple(elements), elements)
|
|
3719
3913
|
}
|
|
3720
3914
|
|
|
3721
3915
|
/**
|
|
@@ -3741,7 +3935,7 @@ export declare namespace TupleWithRest {
|
|
|
3741
3935
|
export type TupleType = Top & {
|
|
3742
3936
|
readonly Type: ReadonlyArray<unknown>
|
|
3743
3937
|
readonly Encoded: ReadonlyArray<unknown>
|
|
3744
|
-
readonly ast:
|
|
3938
|
+
readonly ast: SchemaAST.Arrays
|
|
3745
3939
|
readonly "~type.make": ReadonlyArray<unknown>
|
|
3746
3940
|
readonly "Iso": ReadonlyArray<unknown>
|
|
3747
3941
|
}
|
|
@@ -3855,7 +4049,7 @@ export interface TupleWithRest<
|
|
|
3855
4049
|
TupleWithRest.Encoded<S["Encoded"], Rest>,
|
|
3856
4050
|
S["DecodingServices"] | Rest[number]["DecodingServices"],
|
|
3857
4051
|
S["EncodingServices"] | Rest[number]["EncodingServices"],
|
|
3858
|
-
|
|
4052
|
+
SchemaAST.Arrays,
|
|
3859
4053
|
TupleWithRest<S, Rest>,
|
|
3860
4054
|
TupleWithRest.MakeIn<S["~type.make"], Rest>,
|
|
3861
4055
|
TupleWithRest.Iso<S["Iso"], Rest>
|
|
@@ -3899,7 +4093,7 @@ export function TupleWithRest<S extends Tuple<Tuple.Elements>, const Rest extend
|
|
|
3899
4093
|
schema: S,
|
|
3900
4094
|
rest: Rest
|
|
3901
4095
|
): TupleWithRest<S, Rest> {
|
|
3902
|
-
return make(
|
|
4096
|
+
return make(SchemaAST.tupleWithRest(schema.ast, rest.map(SchemaAST.getAST)), { schema, rest })
|
|
3903
4097
|
}
|
|
3904
4098
|
|
|
3905
4099
|
/**
|
|
@@ -3914,7 +4108,7 @@ export interface $Array<S extends Top> extends
|
|
|
3914
4108
|
ReadonlyArray<S["Encoded"]>,
|
|
3915
4109
|
S["DecodingServices"],
|
|
3916
4110
|
S["EncodingServices"],
|
|
3917
|
-
|
|
4111
|
+
SchemaAST.Arrays,
|
|
3918
4112
|
$Array<S>,
|
|
3919
4113
|
ReadonlyArray<S["~type.make"]>,
|
|
3920
4114
|
ReadonlyArray<S["Iso"]>
|
|
@@ -3933,7 +4127,7 @@ interface ArrayLambda extends Lambda {
|
|
|
3933
4127
|
* @since 4.0.0
|
|
3934
4128
|
*/
|
|
3935
4129
|
const ArraySchema = Struct_.lambda<ArrayLambda>((schema) =>
|
|
3936
|
-
make(new
|
|
4130
|
+
make(new SchemaAST.Arrays(false, [], [schema.ast]), { value: schema })
|
|
3937
4131
|
)
|
|
3938
4132
|
|
|
3939
4133
|
export {
|
|
@@ -3970,7 +4164,7 @@ export interface NonEmptyArray<S extends Top> extends
|
|
|
3970
4164
|
readonly [S["Encoded"], ...Array<S["Encoded"]>],
|
|
3971
4165
|
S["DecodingServices"],
|
|
3972
4166
|
S["EncodingServices"],
|
|
3973
|
-
|
|
4167
|
+
SchemaAST.Arrays,
|
|
3974
4168
|
NonEmptyArray<S>,
|
|
3975
4169
|
readonly [S["~type.make"], ...Array<S["~type.make"]>],
|
|
3976
4170
|
readonly [S["Iso"], ...Array<S["Iso"]>]
|
|
@@ -4003,7 +4197,7 @@ interface NonEmptyArrayLambda extends Lambda {
|
|
|
4003
4197
|
* @since 3.10.0
|
|
4004
4198
|
*/
|
|
4005
4199
|
export const NonEmptyArray = Struct_.lambda<NonEmptyArrayLambda>((schema) =>
|
|
4006
|
-
make(new
|
|
4200
|
+
make(new SchemaAST.Arrays(false, [schema.ast], [schema.ast]), { value: schema })
|
|
4007
4201
|
)
|
|
4008
4202
|
|
|
4009
4203
|
/**
|
|
@@ -4045,7 +4239,7 @@ export interface ArrayEnsure<S extends Top> extends decodeTo<$Array<toType<S>>,
|
|
|
4045
4239
|
export function ArrayEnsure<S extends Top>(schema: S): ArrayEnsure<S> {
|
|
4046
4240
|
return Union([schema, ArraySchema(schema)]).pipe(decodeTo(
|
|
4047
4241
|
ArraySchema(toType(schema)),
|
|
4048
|
-
|
|
4242
|
+
SchemaTransformation.transform({
|
|
4049
4243
|
decode: Arr.ensure,
|
|
4050
4244
|
encode: (array) => array.length === 1 ? array[0] : array
|
|
4051
4245
|
})
|
|
@@ -4083,7 +4277,7 @@ export function UniqueArray<S extends Top>(item: S): UniqueArray<S> {
|
|
|
4083
4277
|
* @category transforming
|
|
4084
4278
|
* @since 3.10.0
|
|
4085
4279
|
*/
|
|
4086
|
-
export interface mutable<S extends Top & { readonly "ast":
|
|
4280
|
+
export interface mutable<S extends Top & { readonly "ast": SchemaAST.Arrays }> extends
|
|
4087
4281
|
Bottom<
|
|
4088
4282
|
Mutable<S["Type"]>,
|
|
4089
4283
|
Mutable<S["Encoded"]>,
|
|
@@ -4107,8 +4301,9 @@ export interface mutable<S extends Top & { readonly "ast": AST.Arrays }> extends
|
|
|
4107
4301
|
}
|
|
4108
4302
|
|
|
4109
4303
|
interface mutableLambda extends Lambda {
|
|
4110
|
-
<S extends Top & { readonly "ast":
|
|
4111
|
-
readonly "~lambda.out": this["~lambda.in"] extends Top & { readonly "ast":
|
|
4304
|
+
<S extends Top & { readonly "ast": SchemaAST.Arrays }>(self: S): mutable<S>
|
|
4305
|
+
readonly "~lambda.out": this["~lambda.in"] extends Top & { readonly "ast": SchemaAST.Arrays } ?
|
|
4306
|
+
mutable<this["~lambda.in"]>
|
|
4112
4307
|
: "Error: schema not eligible for mutable"
|
|
4113
4308
|
}
|
|
4114
4309
|
|
|
@@ -4130,7 +4325,7 @@ interface mutableLambda extends Lambda {
|
|
|
4130
4325
|
* @since 3.10.0
|
|
4131
4326
|
*/
|
|
4132
4327
|
export const mutable = Struct_.lambda<mutableLambda>((schema) => {
|
|
4133
|
-
return make(new
|
|
4328
|
+
return make(new SchemaAST.Arrays(true, schema.ast.elements, schema.ast.rest), { schema })
|
|
4134
4329
|
})
|
|
4135
4330
|
|
|
4136
4331
|
/**
|
|
@@ -4145,7 +4340,7 @@ export interface Union<Members extends ReadonlyArray<Top>> extends
|
|
|
4145
4340
|
{ [K in keyof Members]: Members[K]["Encoded"] }[number],
|
|
4146
4341
|
{ [K in keyof Members]: Members[K]["DecodingServices"] }[number],
|
|
4147
4342
|
{ [K in keyof Members]: Members[K]["EncodingServices"] }[number],
|
|
4148
|
-
|
|
4343
|
+
SchemaAST.Union<{ [K in keyof Members]: Members[K]["ast"] }[number]>,
|
|
4149
4344
|
Union<Members>,
|
|
4150
4345
|
{ [K in keyof Members]: Members[K]["~type.make"] }[number],
|
|
4151
4346
|
{ [K in keyof Members]: Members[K]["Iso"] }[number]
|
|
@@ -4177,7 +4372,7 @@ export interface Union<Members extends ReadonlyArray<Top>> extends
|
|
|
4177
4372
|
}
|
|
4178
4373
|
|
|
4179
4374
|
function makeUnion<Members extends ReadonlyArray<Top>>(
|
|
4180
|
-
ast:
|
|
4375
|
+
ast: SchemaAST.Union<Members[number]["ast"]>,
|
|
4181
4376
|
members: Members
|
|
4182
4377
|
): Union<Members> {
|
|
4183
4378
|
return make(ast, {
|
|
@@ -4191,7 +4386,7 @@ function makeUnion<Members extends ReadonlyArray<Top>>(
|
|
|
4191
4386
|
): Union<Simplify<Readonly<To>>> {
|
|
4192
4387
|
const members = f(this.members)
|
|
4193
4388
|
return makeUnion(
|
|
4194
|
-
|
|
4389
|
+
SchemaAST.union(members, this.ast.mode, options?.unsafePreserveChecks ? this.ast.checks : undefined),
|
|
4195
4390
|
members
|
|
4196
4391
|
)
|
|
4197
4392
|
}
|
|
@@ -4226,7 +4421,7 @@ export function Union<const Members extends ReadonlyArray<Top>>(
|
|
|
4226
4421
|
members: Members,
|
|
4227
4422
|
options?: { mode?: "anyOf" | "oneOf" }
|
|
4228
4423
|
): Union<Members> {
|
|
4229
|
-
return makeUnion(
|
|
4424
|
+
return makeUnion(SchemaAST.union(members, options?.mode ?? "anyOf", undefined), members)
|
|
4230
4425
|
}
|
|
4231
4426
|
|
|
4232
4427
|
/**
|
|
@@ -4235,8 +4430,8 @@ export function Union<const Members extends ReadonlyArray<Top>>(
|
|
|
4235
4430
|
* @category models
|
|
4236
4431
|
* @since 4.0.0
|
|
4237
4432
|
*/
|
|
4238
|
-
export interface Literals<L extends ReadonlyArray<
|
|
4239
|
-
extends Bottom<L[number], L[number], never, never,
|
|
4433
|
+
export interface Literals<L extends ReadonlyArray<SchemaAST.LiteralValue>>
|
|
4434
|
+
extends Bottom<L[number], L[number], never, never, SchemaAST.Union<SchemaAST.Literal>, Literals<L>>
|
|
4240
4435
|
{
|
|
4241
4436
|
readonly literals: L
|
|
4242
4437
|
readonly members: { readonly [K in keyof L]: Literal<L[K]> }
|
|
@@ -4247,7 +4442,7 @@ export interface Literals<L extends ReadonlyArray<AST.LiteralValue>>
|
|
|
4247
4442
|
|
|
4248
4443
|
pick<const L2 extends ReadonlyArray<L[number]>>(literals: L2): Literals<L2>
|
|
4249
4444
|
|
|
4250
|
-
transform<const L2 extends { readonly [I in keyof L]:
|
|
4445
|
+
transform<const L2 extends { readonly [I in keyof L]: SchemaAST.LiteralValue }>(
|
|
4251
4446
|
to: L2
|
|
4252
4447
|
): Union<{ [I in keyof L]: decodeTo<Literal<L2[I]>, Literal<L[I]>> }>
|
|
4253
4448
|
}
|
|
@@ -4268,9 +4463,9 @@ export interface Literals<L extends ReadonlyArray<AST.LiteralValue>>
|
|
|
4268
4463
|
* @category constructors
|
|
4269
4464
|
* @since 4.0.0
|
|
4270
4465
|
*/
|
|
4271
|
-
export function Literals<const L extends ReadonlyArray<
|
|
4466
|
+
export function Literals<const L extends ReadonlyArray<SchemaAST.LiteralValue>>(literals: L): Literals<L> {
|
|
4272
4467
|
const members = literals.map(Literal) as { readonly [K in keyof L]: Literal<L[K]> }
|
|
4273
|
-
return make(
|
|
4468
|
+
return make(SchemaAST.union(members, "anyOf", undefined), {
|
|
4274
4469
|
literals,
|
|
4275
4470
|
members,
|
|
4276
4471
|
mapMembers<To extends ReadonlyArray<Top>>(
|
|
@@ -4282,7 +4477,7 @@ export function Literals<const L extends ReadonlyArray<AST.LiteralValue>>(litera
|
|
|
4282
4477
|
pick<const L2 extends ReadonlyArray<L[number]>>(literals: L2): Literals<L2> {
|
|
4283
4478
|
return Literals(literals)
|
|
4284
4479
|
},
|
|
4285
|
-
transform<const L2 extends { readonly [I in keyof L]:
|
|
4480
|
+
transform<const L2 extends { readonly [I in keyof L]: SchemaAST.LiteralValue }>(
|
|
4286
4481
|
to: L2
|
|
4287
4482
|
): Union<{ [I in keyof L]: decodeTo<Literal<L2[I]>, Literal<L[I]>> }> {
|
|
4288
4483
|
return Union(members.map((member, index) => member.transform(to[index]))) as any
|
|
@@ -4371,7 +4566,7 @@ export interface suspend<S extends Top> extends
|
|
|
4371
4566
|
S["Encoded"],
|
|
4372
4567
|
S["DecodingServices"],
|
|
4373
4568
|
S["EncodingServices"],
|
|
4374
|
-
|
|
4569
|
+
SchemaAST.Suspend,
|
|
4375
4570
|
suspend<S>,
|
|
4376
4571
|
S["~type.make.in"],
|
|
4377
4572
|
S["Iso"],
|
|
@@ -4410,7 +4605,7 @@ export interface suspend<S extends Top> extends
|
|
|
4410
4605
|
* @since 3.10.0
|
|
4411
4606
|
*/
|
|
4412
4607
|
export function suspend<S extends Top>(f: () => S): suspend<S> {
|
|
4413
|
-
return make(new
|
|
4608
|
+
return make(new SchemaAST.Suspend(() => f().ast))
|
|
4414
4609
|
}
|
|
4415
4610
|
|
|
4416
4611
|
/**
|
|
@@ -4430,7 +4625,9 @@ export function suspend<S extends Top>(f: () => S): suspend<S> {
|
|
|
4430
4625
|
* @category filtering
|
|
4431
4626
|
* @since 4.0.0
|
|
4432
4627
|
*/
|
|
4433
|
-
export function check<S extends Top>(
|
|
4628
|
+
export function check<S extends Top>(
|
|
4629
|
+
...checks: readonly [SchemaAST.Check<S["Type"]>, ...Array<SchemaAST.Check<S["Type"]>>]
|
|
4630
|
+
) {
|
|
4434
4631
|
return (self: S): S["Rebuild"] => self.check(...checks)
|
|
4435
4632
|
}
|
|
4436
4633
|
|
|
@@ -4482,7 +4679,7 @@ export function refine<S extends Top, T extends S["Type"]>(
|
|
|
4482
4679
|
annotations?: Annotations.Filter
|
|
4483
4680
|
) {
|
|
4484
4681
|
return (schema: S): refine<T, S> =>
|
|
4485
|
-
make(
|
|
4682
|
+
make(SchemaAST.appendChecks(schema.ast, [SchemaAST.makeFilterByGuard(refinement, annotations)]), { schema })
|
|
4486
4683
|
}
|
|
4487
4684
|
|
|
4488
4685
|
type DistributeBrands<B> = UnionToIntersection<B extends infer U extends string ? Brand.Brand<U> : never>
|
|
@@ -4537,7 +4734,7 @@ export interface brand<S extends Top, B> extends
|
|
|
4537
4734
|
*/
|
|
4538
4735
|
export function brand<B extends string>(identifier: B) {
|
|
4539
4736
|
return <S extends Top>(schema: S): brand<S["Rebuild"], B> =>
|
|
4540
|
-
make(
|
|
4737
|
+
make(SchemaAST.brand(schema.ast, identifier), { schema, identifier })
|
|
4541
4738
|
}
|
|
4542
4739
|
|
|
4543
4740
|
/**
|
|
@@ -4610,13 +4807,13 @@ export interface middlewareDecoding<S extends Top, RD> extends
|
|
|
4610
4807
|
*/
|
|
4611
4808
|
export function middlewareDecoding<S extends Top, RD>(
|
|
4612
4809
|
decode: (
|
|
4613
|
-
effect: Effect.Effect<Option_.Option<S["Type"]>,
|
|
4614
|
-
options:
|
|
4615
|
-
) => Effect.Effect<Option_.Option<S["Type"]>,
|
|
4810
|
+
effect: Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, S["DecodingServices"]>,
|
|
4811
|
+
options: SchemaAST.ParseOptions
|
|
4812
|
+
) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, RD>
|
|
4616
4813
|
) {
|
|
4617
4814
|
return (schema: S): middlewareDecoding<S, RD> =>
|
|
4618
4815
|
make(
|
|
4619
|
-
|
|
4816
|
+
SchemaAST.middlewareDecoding(schema.ast, new SchemaTransformation.Middleware(decode, identity)),
|
|
4620
4817
|
{ schema }
|
|
4621
4818
|
)
|
|
4622
4819
|
}
|
|
@@ -4676,13 +4873,13 @@ export interface middlewareEncoding<S extends Top, RE> extends
|
|
|
4676
4873
|
*/
|
|
4677
4874
|
export function middlewareEncoding<S extends Top, RE>(
|
|
4678
4875
|
encode: (
|
|
4679
|
-
effect: Effect.Effect<Option_.Option<S["Encoded"]>,
|
|
4680
|
-
options:
|
|
4681
|
-
) => Effect.Effect<Option_.Option<S["Encoded"]>,
|
|
4876
|
+
effect: Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue, S["EncodingServices"]>,
|
|
4877
|
+
options: SchemaAST.ParseOptions
|
|
4878
|
+
) => Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue, RE>
|
|
4682
4879
|
) {
|
|
4683
4880
|
return (schema: S): middlewareEncoding<S, RE> =>
|
|
4684
4881
|
make(
|
|
4685
|
-
|
|
4882
|
+
SchemaAST.middlewareEncoding(schema.ast, new SchemaTransformation.Middleware(identity, encode)),
|
|
4686
4883
|
{ schema }
|
|
4687
4884
|
)
|
|
4688
4885
|
}
|
|
@@ -4710,7 +4907,7 @@ export function middlewareEncoding<S extends Top, RE>(
|
|
|
4710
4907
|
* @since 4.0.0
|
|
4711
4908
|
*/
|
|
4712
4909
|
export function catchDecoding<S extends Top>(
|
|
4713
|
-
f: (issue:
|
|
4910
|
+
f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue>
|
|
4714
4911
|
): (self: S) => S["Rebuild"] {
|
|
4715
4912
|
return catchDecodingWithContext(f)
|
|
4716
4913
|
}
|
|
@@ -4720,7 +4917,8 @@ export function catchDecoding<S extends Top>(
|
|
|
4720
4917
|
*
|
|
4721
4918
|
* **When to use**
|
|
4722
4919
|
*
|
|
4723
|
-
* Use when decoding fallback logic
|
|
4920
|
+
* Use when you need decoding fallback logic to require services from the Effect
|
|
4921
|
+
* context.
|
|
4724
4922
|
*
|
|
4725
4923
|
* **Details**
|
|
4726
4924
|
*
|
|
@@ -4735,7 +4933,7 @@ export function catchDecoding<S extends Top>(
|
|
|
4735
4933
|
* @since 4.0.0
|
|
4736
4934
|
*/
|
|
4737
4935
|
export function catchDecodingWithContext<S extends Top, R = never>(
|
|
4738
|
-
f: (issue:
|
|
4936
|
+
f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, R>
|
|
4739
4937
|
) {
|
|
4740
4938
|
return (self: S): middlewareDecoding<S, S["DecodingServices"] | R> =>
|
|
4741
4939
|
self.pipe(middlewareDecoding(Effect.catchEager(f)))
|
|
@@ -4754,7 +4952,7 @@ export function catchDecodingWithContext<S extends Top, R = never>(
|
|
|
4754
4952
|
* @since 4.0.0
|
|
4755
4953
|
*/
|
|
4756
4954
|
export function catchEncoding<S extends Top>(
|
|
4757
|
-
f: (issue:
|
|
4955
|
+
f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue>
|
|
4758
4956
|
): (self: S) => S["Rebuild"] {
|
|
4759
4957
|
return catchEncodingWithContext(f)
|
|
4760
4958
|
}
|
|
@@ -4764,7 +4962,8 @@ export function catchEncoding<S extends Top>(
|
|
|
4764
4962
|
*
|
|
4765
4963
|
* **When to use**
|
|
4766
4964
|
*
|
|
4767
|
-
* Use when encoding fallback logic
|
|
4965
|
+
* Use when you need encoding fallback logic to require services from the Effect
|
|
4966
|
+
* context.
|
|
4768
4967
|
*
|
|
4769
4968
|
* **Details**
|
|
4770
4969
|
*
|
|
@@ -4779,7 +4978,7 @@ export function catchEncoding<S extends Top>(
|
|
|
4779
4978
|
* @since 4.0.0
|
|
4780
4979
|
*/
|
|
4781
4980
|
export function catchEncodingWithContext<S extends Top, R = never>(
|
|
4782
|
-
f: (issue:
|
|
4981
|
+
f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue, R>
|
|
4783
4982
|
) {
|
|
4784
4983
|
return (self: S): middlewareEncoding<S, S["EncodingServices"] | R> =>
|
|
4785
4984
|
self.pipe(middlewareEncoding(Effect.catchEager(f)))
|
|
@@ -4825,25 +5024,28 @@ export interface compose<To extends Top, From extends Top> extends decodeTo<To,
|
|
|
4825
5024
|
/**
|
|
4826
5025
|
* Creates a schema that transforms from a source schema to a target schema.
|
|
4827
5026
|
*
|
|
5027
|
+
* **When to use**
|
|
5028
|
+
*
|
|
5029
|
+
* Use when decoding should change the schema's decoded type or encoded shape,
|
|
5030
|
+
* with an optional custom bidirectional transformation.
|
|
5031
|
+
*
|
|
4828
5032
|
* **Details**
|
|
4829
5033
|
*
|
|
4830
|
-
*
|
|
4831
|
-
*
|
|
4832
|
-
* `From["Encoded"]` to `To["Type"]` and encodes from `To["Type"]` back to
|
|
5034
|
+
* Call it with the target schema `to` and then pipe the source schema `from`
|
|
5035
|
+
* into the returned function. The resulting schema decodes from
|
|
5036
|
+
* `From["Encoded"]` to `To["Type"]` and encodes from `To["Type"]` back to
|
|
5037
|
+
* `From["Encoded"]`.
|
|
4833
5038
|
*
|
|
4834
|
-
*
|
|
4835
|
-
*
|
|
4836
|
-
*
|
|
4837
|
-
*
|
|
4838
|
-
* - Transformation `decode` maps `From["Type"]` → `To["Encoded"]` (used during encoding)
|
|
4839
|
-
* - Transformation `encode` maps `To["Encoded"]` → `From["Type"]` (used during decoding)
|
|
5039
|
+
* When no transformation is provided, `SchemaTransformation.passthrough()` is
|
|
5040
|
+
* used, so `From["Type"]` must already be compatible with `To["Encoded"]`.
|
|
5041
|
+
* The resulting schema combines decoding and encoding services from both
|
|
5042
|
+
* schemas and any custom transformation.
|
|
4840
5043
|
*
|
|
4841
|
-
*
|
|
4842
|
-
*
|
|
4843
|
-
*
|
|
4844
|
-
*
|
|
4845
|
-
*
|
|
4846
|
-
* - **Service dependencies**: Resulting schema requires services from both schemas; use `Schema.provideService` if needed
|
|
5044
|
+
* **Gotchas**
|
|
5045
|
+
*
|
|
5046
|
+
* In a custom transformation, `decode` maps `From["Type"]` to `To["Encoded"]`
|
|
5047
|
+
* and is used on the encoding path, while `encode` maps `To["Encoded"]` to
|
|
5048
|
+
* `From["Type"]` and is used on the decoding path.
|
|
4847
5049
|
*
|
|
4848
5050
|
* **Example** (String to Number with transformation)
|
|
4849
5051
|
*
|
|
@@ -4871,23 +5073,23 @@ export function decodeTo<To extends Top>(to: To): <From extends Top>(from: From)
|
|
|
4871
5073
|
export function decodeTo<To extends Top, From extends Top, RD = never, RE = never>(
|
|
4872
5074
|
to: To,
|
|
4873
5075
|
transformation: {
|
|
4874
|
-
readonly decode:
|
|
4875
|
-
readonly encode:
|
|
5076
|
+
readonly decode: SchemaGetter.Getter<NoInfer<To["Encoded"]>, NoInfer<From["Type"]>, RD>
|
|
5077
|
+
readonly encode: SchemaGetter.Getter<NoInfer<From["Type"]>, NoInfer<To["Encoded"]>, RE>
|
|
4876
5078
|
}
|
|
4877
5079
|
): (from: From) => decodeTo<To, From, RD, RE>
|
|
4878
5080
|
export function decodeTo<To extends Top, From extends Top, RD = never, RE = never>(
|
|
4879
5081
|
to: To,
|
|
4880
5082
|
transformation?: {
|
|
4881
|
-
readonly decode:
|
|
4882
|
-
readonly encode:
|
|
5083
|
+
readonly decode: SchemaGetter.Getter<To["Encoded"], From["Type"], RD>
|
|
5084
|
+
readonly encode: SchemaGetter.Getter<From["Type"], To["Encoded"], RE>
|
|
4883
5085
|
} | undefined
|
|
4884
5086
|
) {
|
|
4885
5087
|
return (from: From) => {
|
|
4886
5088
|
return make(
|
|
4887
|
-
|
|
5089
|
+
SchemaAST.decodeTo(
|
|
4888
5090
|
from.ast,
|
|
4889
5091
|
to.ast,
|
|
4890
|
-
transformation ?
|
|
5092
|
+
transformation ? SchemaTransformation.make(transformation) : SchemaTransformation.passthrough()
|
|
4891
5093
|
),
|
|
4892
5094
|
{
|
|
4893
5095
|
from,
|
|
@@ -4900,23 +5102,26 @@ export function decodeTo<To extends Top, From extends Top, RD = never, RE = neve
|
|
|
4900
5102
|
/**
|
|
4901
5103
|
* Applies a transformation to a schema, creating a new schema with the same type but transformed encoding/decoding.
|
|
4902
5104
|
*
|
|
5105
|
+
* **When to use**
|
|
5106
|
+
*
|
|
5107
|
+
* Use when the decoded type stays the same and the transformation only
|
|
5108
|
+
* normalizes values during encoding and decoding.
|
|
5109
|
+
*
|
|
4903
5110
|
* **Details**
|
|
4904
5111
|
*
|
|
4905
|
-
*
|
|
4906
|
-
* The resulting schema
|
|
4907
|
-
*
|
|
5112
|
+
* Call it with a transformation object and then pipe a schema into the returned
|
|
5113
|
+
* function. The resulting schema keeps the same `Type` and `Encoded` types as
|
|
5114
|
+
* the source schema, while applying the transformation during both decoding and
|
|
5115
|
+
* encoding.
|
|
5116
|
+
*
|
|
5117
|
+
* Internally this uses `toType(self)` as the target schema and combines service
|
|
5118
|
+
* requirements from the source schema and the transformation.
|
|
4908
5119
|
*
|
|
4909
|
-
*
|
|
4910
|
-
* - Resulting schema has `Type = S["Type"]` and `Encoded = S["Encoded"]`
|
|
4911
|
-
* - Uses `toType(self)` as the target schema internally (creates a schema where both Type and Encoded are `S["Type"]`)
|
|
4912
|
-
* - Combines decoding/encoding services from the source schema and transformation
|
|
4913
|
-
* - Transformation `decode` maps `S["Type"]` → `S["Type"]` (used during encoding)
|
|
4914
|
-
* - Transformation `encode` maps `S["Type"]` → `S["Type"]` (used during decoding)
|
|
5120
|
+
* **Gotchas**
|
|
4915
5121
|
*
|
|
4916
|
-
*
|
|
4917
|
-
*
|
|
4918
|
-
*
|
|
4919
|
-
* - **Service dependencies**: Resulting schema requires services from the source schema and transformation; use `Schema.provideService` if needed
|
|
5122
|
+
* Use {@link decodeTo} instead when the transformation should change the
|
|
5123
|
+
* decoded type. For this helper, both transformation getters operate on
|
|
5124
|
+
* `S["Type"]` values.
|
|
4920
5125
|
*
|
|
4921
5126
|
* **Example** (Trimming string values during encoding/decoding)
|
|
4922
5127
|
*
|
|
@@ -4938,8 +5143,8 @@ export function decodeTo<To extends Top, From extends Top, RD = never, RE = neve
|
|
|
4938
5143
|
* @since 3.10.0
|
|
4939
5144
|
*/
|
|
4940
5145
|
export function decode<S extends Top, RD = never, RE = never>(transformation: {
|
|
4941
|
-
readonly decode:
|
|
4942
|
-
readonly encode:
|
|
5146
|
+
readonly decode: SchemaGetter.Getter<S["Type"], S["Type"], RD>
|
|
5147
|
+
readonly encode: SchemaGetter.Getter<S["Type"], S["Type"], RE>
|
|
4943
5148
|
}) {
|
|
4944
5149
|
return (self: S): decodeTo<toType<S>, S, RD, RE> => {
|
|
4945
5150
|
return self.pipe(decodeTo(toType(self), transformation))
|
|
@@ -4981,15 +5186,15 @@ export function encodeTo<To extends Top>(
|
|
|
4981
5186
|
export function encodeTo<To extends Top, From extends Top, RD = never, RE = never>(
|
|
4982
5187
|
to: To,
|
|
4983
5188
|
transformation: {
|
|
4984
|
-
readonly decode:
|
|
4985
|
-
readonly encode:
|
|
5189
|
+
readonly decode: SchemaGetter.Getter<NoInfer<From["Encoded"]>, NoInfer<To["Type"]>, RD>
|
|
5190
|
+
readonly encode: SchemaGetter.Getter<NoInfer<To["Type"]>, NoInfer<From["Encoded"]>, RE>
|
|
4986
5191
|
}
|
|
4987
5192
|
): (from: From) => decodeTo<From, To, RD, RE>
|
|
4988
5193
|
export function encodeTo<To extends Top, From extends Top, RD = never, RE = never>(
|
|
4989
5194
|
to: To,
|
|
4990
5195
|
transformation?: {
|
|
4991
|
-
readonly decode:
|
|
4992
|
-
readonly encode:
|
|
5196
|
+
readonly decode: SchemaGetter.Getter<From["Encoded"], To["Type"], RD>
|
|
5197
|
+
readonly encode: SchemaGetter.Getter<To["Type"], From["Encoded"], RE>
|
|
4993
5198
|
}
|
|
4994
5199
|
) {
|
|
4995
5200
|
return (from: From): decodeTo<From, To, RD, RE> => {
|
|
@@ -5025,8 +5230,8 @@ export function encodeTo<To extends Top, From extends Top, RD = never, RE = neve
|
|
|
5025
5230
|
* @since 3.10.0
|
|
5026
5231
|
*/
|
|
5027
5232
|
export function encode<S extends Top, RD = never, RE = never>(transformation: {
|
|
5028
|
-
readonly decode:
|
|
5029
|
-
readonly encode:
|
|
5233
|
+
readonly decode: SchemaGetter.Getter<S["Encoded"], S["Encoded"], RD>
|
|
5234
|
+
readonly encode: SchemaGetter.Getter<S["Encoded"], S["Encoded"], RE>
|
|
5030
5235
|
}) {
|
|
5031
5236
|
return (self: S): decodeTo<S, toEncoded<S>, RD, RE> => {
|
|
5032
5237
|
return toEncoded(self).pipe(decodeTo(self, transformation))
|
|
@@ -5108,7 +5313,7 @@ export function withConstructorDefault<S extends Top & WithoutConstructorDefault
|
|
|
5108
5313
|
defaultValue: Effect.Effect<S["~type.make.in"], SchemaError>
|
|
5109
5314
|
) {
|
|
5110
5315
|
return (schema: S): withConstructorDefault<S> =>
|
|
5111
|
-
make(
|
|
5316
|
+
make(SchemaAST.withConstructorDefault(schema.ast, Effect.mapErrorEager(defaultValue, (e) => e.issue)), { schema })
|
|
5112
5317
|
}
|
|
5113
5318
|
|
|
5114
5319
|
/**
|
|
@@ -5175,10 +5380,10 @@ export function withDecodingDefaultKey<S extends Top, R = never>(
|
|
|
5175
5380
|
defaultValue: Effect.Effect<S["Encoded"], SchemaError, R>,
|
|
5176
5381
|
options?: DecodingDefaultOptions
|
|
5177
5382
|
) {
|
|
5178
|
-
const encode = options?.encodingStrategy === "omit" ?
|
|
5383
|
+
const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough()
|
|
5179
5384
|
return (self: S): withDecodingDefaultKey<S, R> => {
|
|
5180
5385
|
return optionalKey(toEncoded(self)).pipe(decodeTo(self, {
|
|
5181
|
-
decode:
|
|
5386
|
+
decode: SchemaGetter.withDefault(Effect.mapErrorEager(defaultValue, (e) => e.issue)),
|
|
5182
5387
|
encode
|
|
5183
5388
|
}))
|
|
5184
5389
|
}
|
|
@@ -5245,6 +5450,11 @@ export interface withDecodingDefault<S extends Top, R = never> extends decodeTo<
|
|
|
5245
5450
|
* and provides a default `Encoded` value when the field is missing or
|
|
5246
5451
|
* `undefined` during decoding.
|
|
5247
5452
|
*
|
|
5453
|
+
* **When to use**
|
|
5454
|
+
*
|
|
5455
|
+
* Use when the default is expressed in the encoded representation, before the
|
|
5456
|
+
* field's decoding transformation runs.
|
|
5457
|
+
*
|
|
5248
5458
|
* **Details**
|
|
5249
5459
|
*
|
|
5250
5460
|
* The default value is specified in terms of the `Encoded` type (before any
|
|
@@ -5278,10 +5488,10 @@ export function withDecodingDefault<S extends Top, R = never>(
|
|
|
5278
5488
|
defaultValue: Effect.Effect<S["Encoded"], SchemaError, R>,
|
|
5279
5489
|
options?: DecodingDefaultOptions
|
|
5280
5490
|
) {
|
|
5281
|
-
const encode = options?.encodingStrategy === "omit" ?
|
|
5491
|
+
const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough()
|
|
5282
5492
|
return (self: S): withDecodingDefault<S, R> => {
|
|
5283
5493
|
return optional(toEncoded(self)).pipe(decodeTo(self, {
|
|
5284
|
-
decode:
|
|
5494
|
+
decode: SchemaGetter.withDefault(Effect.mapErrorEager(defaultValue, (e) => e.issue)),
|
|
5285
5495
|
encode
|
|
5286
5496
|
}))
|
|
5287
5497
|
}
|
|
@@ -5304,6 +5514,11 @@ export interface withDecodingDefaultType<S extends Top, R = never>
|
|
|
5304
5514
|
* and provides a default `Type` value when the field is missing or
|
|
5305
5515
|
* `undefined` during decoding.
|
|
5306
5516
|
*
|
|
5517
|
+
* **When to use**
|
|
5518
|
+
*
|
|
5519
|
+
* Use when the default is already in the decoded representation and should not
|
|
5520
|
+
* pass through the field's decoding transformation.
|
|
5521
|
+
*
|
|
5307
5522
|
* **Details**
|
|
5308
5523
|
*
|
|
5309
5524
|
* Unlike {@link withDecodingDefault}, the default value is specified in terms
|
|
@@ -5339,7 +5554,7 @@ export function withDecodingDefaultType<S extends Top, R = never>(
|
|
|
5339
5554
|
* @category constructors
|
|
5340
5555
|
* @since 3.10.0
|
|
5341
5556
|
*/
|
|
5342
|
-
export interface tag<Tag extends
|
|
5557
|
+
export interface tag<Tag extends SchemaAST.LiteralValue> extends withConstructorDefault<Literal<Tag>> {}
|
|
5343
5558
|
|
|
5344
5559
|
/**
|
|
5345
5560
|
* Combines a {@link Literal} schema with {@link withConstructorDefault}, making it ideal
|
|
@@ -5363,7 +5578,7 @@ export interface tag<Tag extends AST.LiteralValue> extends withConstructorDefaul
|
|
|
5363
5578
|
* @category constructors
|
|
5364
5579
|
* @since 3.10.0
|
|
5365
5580
|
*/
|
|
5366
|
-
export function tag<Tag extends
|
|
5581
|
+
export function tag<Tag extends SchemaAST.LiteralValue>(literal: Tag): tag<Tag> {
|
|
5367
5582
|
return Literal(literal).pipe(withConstructorDefault(Effect.succeed(literal)))
|
|
5368
5583
|
}
|
|
5369
5584
|
|
|
@@ -5399,7 +5614,7 @@ export function tag<Tag extends AST.LiteralValue>(literal: Tag): tag<Tag> {
|
|
|
5399
5614
|
* @category constructors
|
|
5400
5615
|
* @since 4.0.0
|
|
5401
5616
|
*/
|
|
5402
|
-
export function tagDefaultOmit<Tag extends
|
|
5617
|
+
export function tagDefaultOmit<Tag extends SchemaAST.LiteralValue>(literal: Tag) {
|
|
5403
5618
|
return tag(literal).pipe(withDecodingDefaultKey(Effect.succeed(literal), { encodingStrategy: "omit" }))
|
|
5404
5619
|
}
|
|
5405
5620
|
|
|
@@ -5409,7 +5624,7 @@ export function tagDefaultOmit<Tag extends AST.LiteralValue>(literal: Tag) {
|
|
|
5409
5624
|
* @category models
|
|
5410
5625
|
* @since 3.10.0
|
|
5411
5626
|
*/
|
|
5412
|
-
export type TaggedStruct<Tag extends
|
|
5627
|
+
export type TaggedStruct<Tag extends SchemaAST.LiteralValue, Fields extends Struct.Fields> = Struct<
|
|
5413
5628
|
Simplify<{ readonly _tag: tag<Tag> } & Fields>
|
|
5414
5629
|
>
|
|
5415
5630
|
|
|
@@ -5459,7 +5674,7 @@ export type TaggedStruct<Tag extends AST.LiteralValue, Fields extends Struct.Fie
|
|
|
5459
5674
|
* @category constructors
|
|
5460
5675
|
* @since 3.10.0
|
|
5461
5676
|
*/
|
|
5462
|
-
export function TaggedStruct<const Tag extends
|
|
5677
|
+
export function TaggedStruct<const Tag extends SchemaAST.LiteralValue, const Fields extends Struct.Fields>(
|
|
5463
5678
|
value: Tag,
|
|
5464
5679
|
fields: Fields
|
|
5465
5680
|
): TaggedStruct<Tag, Fields> {
|
|
@@ -5554,13 +5769,13 @@ export function toTaggedUnion<const Tag extends PropertyKey>(tag: Tag) {
|
|
|
5554
5769
|
const ast = schema.ast
|
|
5555
5770
|
|
|
5556
5771
|
if (
|
|
5557
|
-
|
|
5772
|
+
SchemaAST.isUnion(ast) && "members" in schema && globalThis.Array.isArray(schema.members) &&
|
|
5558
5773
|
schema.members.every(isSchema)
|
|
5559
5774
|
) {
|
|
5560
5775
|
return schema.members.forEach(walk)
|
|
5561
5776
|
}
|
|
5562
5777
|
|
|
5563
|
-
const sentinels =
|
|
5778
|
+
const sentinels = SchemaAST.collectSentinels(ast)
|
|
5564
5779
|
if (sentinels.length > 0) {
|
|
5565
5780
|
const literal = sentinels.find((s) => s.key === tag)?.literal
|
|
5566
5781
|
if (Predicate.isPropertyKey(literal)) {
|
|
@@ -5599,7 +5814,7 @@ export interface TaggedUnion<Cases extends Record<string, Top>> extends
|
|
|
5599
5814
|
{ [K in keyof Cases]: Cases[K]["Encoded"] }[keyof Cases],
|
|
5600
5815
|
{ [K in keyof Cases]: Cases[K]["DecodingServices"] }[keyof Cases],
|
|
5601
5816
|
{ [K in keyof Cases]: Cases[K]["EncodingServices"] }[keyof Cases],
|
|
5602
|
-
|
|
5817
|
+
SchemaAST.Union<SchemaAST.Objects>,
|
|
5603
5818
|
TaggedUnion<Cases>,
|
|
5604
5819
|
{ [K in keyof Cases]: Cases[K]["~type.make"] }[keyof Cases]
|
|
5605
5820
|
>
|
|
@@ -5755,7 +5970,7 @@ export function instanceOf<C extends abstract new(...args: any) => any, Iso = In
|
|
|
5755
5970
|
}
|
|
5756
5971
|
|
|
5757
5972
|
/**
|
|
5758
|
-
* Constructs an `
|
|
5973
|
+
* Constructs an `SchemaAST.Link` that describes how a value of type `T` encodes to and decodes from a `To` schema.
|
|
5759
5974
|
* Used when building low-level AST transformations that bridge two schema types.
|
|
5760
5975
|
*
|
|
5761
5976
|
* @category transforming
|
|
@@ -5765,11 +5980,11 @@ export function link<T>() {
|
|
|
5765
5980
|
return <To extends Top>(
|
|
5766
5981
|
encodeTo: To,
|
|
5767
5982
|
transformation: {
|
|
5768
|
-
readonly decode:
|
|
5769
|
-
readonly encode:
|
|
5983
|
+
readonly decode: SchemaGetter.Getter<T, NoInfer<To["Type"]>>
|
|
5984
|
+
readonly encode: SchemaGetter.Getter<NoInfer<To["Type"]>, T>
|
|
5770
5985
|
}
|
|
5771
|
-
):
|
|
5772
|
-
return new
|
|
5986
|
+
): SchemaAST.Link => {
|
|
5987
|
+
return new SchemaAST.Link(encodeTo.ast, SchemaTransformation.make(transformation))
|
|
5773
5988
|
}
|
|
5774
5989
|
}
|
|
5775
5990
|
|
|
@@ -5836,10 +6051,10 @@ export function link<T>() {
|
|
|
5836
6051
|
* @since 4.0.0
|
|
5837
6052
|
*/
|
|
5838
6053
|
export const makeFilter: <T>(
|
|
5839
|
-
filter: (input: T, ast:
|
|
6054
|
+
filter: (input: T, ast: SchemaAST.AST, options: SchemaAST.ParseOptions) => FilterOutput,
|
|
5840
6055
|
annotations?: Annotations.Filter | undefined,
|
|
5841
6056
|
abort?: boolean
|
|
5842
|
-
) =>
|
|
6057
|
+
) => SchemaAST.Filter<T> = SchemaAST.makeFilter
|
|
5843
6058
|
|
|
5844
6059
|
/**
|
|
5845
6060
|
* A single failure reported by a filter predicate. Used as the element type
|
|
@@ -5848,20 +6063,20 @@ export const makeFilter: <T>(
|
|
|
5848
6063
|
* **Details**
|
|
5849
6064
|
*
|
|
5850
6065
|
* - `string`: failure with that string as the message. Produces an
|
|
5851
|
-
* {@link
|
|
6066
|
+
* {@link SchemaIssue.InvalidValue} wrapping the input, with the string used as
|
|
5852
6067
|
* the issue's `message` annotation.
|
|
5853
|
-
* - {@link
|
|
6068
|
+
* - {@link SchemaIssue.Issue}: a fully-formed issue, returned as-is.
|
|
5854
6069
|
* - `{ path, issue }`: failure attached to a nested path. `issue` is either
|
|
5855
|
-
* a `string` (wrapped in an {@link
|
|
5856
|
-
* {@link
|
|
6070
|
+
* a `string` (wrapped in an {@link SchemaIssue.InvalidValue}) or a full
|
|
6071
|
+
* {@link SchemaIssue.Issue}; the result is wrapped in an {@link SchemaIssue.Pointer}
|
|
5857
6072
|
* at the given `path`.
|
|
5858
6073
|
*
|
|
5859
6074
|
* @category models
|
|
5860
6075
|
* @since 3.10.0
|
|
5861
6076
|
*/
|
|
5862
|
-
export type FilterIssue = string |
|
|
6077
|
+
export type FilterIssue = string | SchemaIssue.Issue | {
|
|
5863
6078
|
readonly path: ReadonlyArray<PropertyKey>
|
|
5864
|
-
readonly issue: string |
|
|
6079
|
+
readonly issue: string | SchemaIssue.Issue
|
|
5865
6080
|
}
|
|
5866
6081
|
|
|
5867
6082
|
/**
|
|
@@ -5869,20 +6084,20 @@ export type FilterIssue = string | Issue.Issue | {
|
|
|
5869
6084
|
*
|
|
5870
6085
|
* **Details**
|
|
5871
6086
|
*
|
|
5872
|
-
* Each shape is normalized into an {@link
|
|
6087
|
+
* Each shape is normalized into an {@link SchemaIssue.Issue} (or `undefined` for
|
|
5873
6088
|
* success) before being attached to the parse result:
|
|
5874
6089
|
*
|
|
5875
6090
|
* - `undefined`: success. The input satisfies the filter.
|
|
5876
6091
|
* - `true`: success. Equivalent to `undefined`, useful when the predicate is
|
|
5877
6092
|
* a plain boolean expression.
|
|
5878
|
-
* - `false`: generic failure. Produces an {@link
|
|
6093
|
+
* - `false`: generic failure. Produces an {@link SchemaIssue.InvalidValue} wrapping
|
|
5879
6094
|
* the input, with no custom message.
|
|
5880
6095
|
* - {@link FilterIssue}: a single failure. See {@link FilterIssue} for the
|
|
5881
|
-
* shapes (`string`, {@link
|
|
6096
|
+
* shapes (`string`, {@link SchemaIssue.Issue}, or `{ path, issue }`).
|
|
5882
6097
|
* - `ReadonlyArray<FilterIssue>`: several failures reported together. An
|
|
5883
6098
|
* empty array is treated as success; a single-element array is equivalent
|
|
5884
6099
|
* to returning that element directly; otherwise the entries are grouped
|
|
5885
|
-
* into an {@link
|
|
6100
|
+
* into an {@link SchemaIssue.Composite}.
|
|
5886
6101
|
*
|
|
5887
6102
|
* @category models
|
|
5888
6103
|
* @since 3.10.0
|
|
@@ -5894,17 +6109,17 @@ export type FilterOutput =
|
|
|
5894
6109
|
| ReadonlyArray<FilterIssue>
|
|
5895
6110
|
|
|
5896
6111
|
/**
|
|
5897
|
-
* Groups multiple checks into a single {@link
|
|
6112
|
+
* Groups multiple checks into a single {@link SchemaAST.FilterGroup}, applying
|
|
5898
6113
|
* optional shared annotations to the group as a whole.
|
|
5899
6114
|
*
|
|
5900
6115
|
* @category constructors
|
|
5901
6116
|
* @since 4.0.0
|
|
5902
6117
|
*/
|
|
5903
6118
|
export function makeFilterGroup<T>(
|
|
5904
|
-
checks: readonly [
|
|
6119
|
+
checks: readonly [SchemaAST.Check<T>, ...Array<SchemaAST.Check<T>>],
|
|
5905
6120
|
annotations: Annotations.Filter | undefined = undefined
|
|
5906
|
-
):
|
|
5907
|
-
return new
|
|
6121
|
+
): SchemaAST.FilterGroup<T> {
|
|
6122
|
+
return new SchemaAST.FilterGroup(checks, annotations)
|
|
5908
6123
|
}
|
|
5909
6124
|
|
|
5910
6125
|
const TRIMMED_PATTERN = "^\\S[\\s\\S]*\\S$|^\\S$|^$"
|
|
@@ -5963,8 +6178,8 @@ export function isTrimmed(annotations?: Annotations.Filter) {
|
|
|
5963
6178
|
* @category String checks
|
|
5964
6179
|
* @since 4.0.0
|
|
5965
6180
|
*/
|
|
5966
|
-
export const isPattern: (regExp: globalThis.RegExp, annotations?: Annotations.Filter) =>
|
|
5967
|
-
|
|
6181
|
+
export const isPattern: (regExp: globalThis.RegExp, annotations?: Annotations.Filter) => SchemaAST.Filter<string> =
|
|
6182
|
+
SchemaAST.isPattern
|
|
5968
6183
|
|
|
5969
6184
|
/**
|
|
5970
6185
|
* Validates that a string represents a finite number.
|
|
@@ -5984,7 +6199,7 @@ export const isPattern: (regExp: globalThis.RegExp, annotations?: Annotations.Fi
|
|
|
5984
6199
|
* @category String checks
|
|
5985
6200
|
* @since 4.0.0
|
|
5986
6201
|
*/
|
|
5987
|
-
export const isStringFinite: (annotations?: Annotations.Filter) =>
|
|
6202
|
+
export const isStringFinite: (annotations?: Annotations.Filter) => SchemaAST.Filter<string> = SchemaAST.isStringFinite
|
|
5988
6203
|
|
|
5989
6204
|
/**
|
|
5990
6205
|
* Validates that a string is a signed base-10 integer literal for Effect's
|
|
@@ -6003,7 +6218,7 @@ export const isStringFinite: (annotations?: Annotations.Filter) => AST.Filter<st
|
|
|
6003
6218
|
* @category String checks
|
|
6004
6219
|
* @since 4.0.0
|
|
6005
6220
|
*/
|
|
6006
|
-
export const isStringBigInt: (annotations?: Annotations.Filter) =>
|
|
6221
|
+
export const isStringBigInt: (annotations?: Annotations.Filter) => SchemaAST.Filter<string> = SchemaAST.isStringBigInt
|
|
6007
6222
|
|
|
6008
6223
|
/**
|
|
6009
6224
|
* Validates that a string has the `Symbol(description)` format used by Effect's
|
|
@@ -6017,10 +6232,10 @@ export const isStringBigInt: (annotations?: Annotations.Filter) => AST.Filter<st
|
|
|
6017
6232
|
* @category String checks
|
|
6018
6233
|
* @since 4.0.0
|
|
6019
6234
|
*/
|
|
6020
|
-
export const isStringSymbol: (annotations?: Annotations.Filter) =>
|
|
6235
|
+
export const isStringSymbol: (annotations?: Annotations.Filter) => SchemaAST.Filter<string> = SchemaAST.isStringSymbol
|
|
6021
6236
|
|
|
6022
6237
|
/**
|
|
6023
|
-
* Returns a RegExp for validating an RFC 4122 UUID.
|
|
6238
|
+
* Returns a RegExp for validating an RFC 9562 / RFC 4122 UUID.
|
|
6024
6239
|
*
|
|
6025
6240
|
* Optionally specify a version 1-8. If no version is specified (`undefined`), all versions are supported.
|
|
6026
6241
|
*/
|
|
@@ -6030,16 +6245,25 @@ const getUUIDRegExp = (version?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8): globalThis.RegE
|
|
|
6030
6245
|
`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`
|
|
6031
6246
|
)
|
|
6032
6247
|
}
|
|
6033
|
-
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/;
|
|
6248
|
+
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|[fF]{8}-[fF]{4}-[fF]{4}-[fF]{4}-[fF]{12})$/;
|
|
6034
6249
|
}
|
|
6035
6250
|
|
|
6036
6251
|
/**
|
|
6037
|
-
* Validates that a string is a
|
|
6038
|
-
*
|
|
6039
|
-
*
|
|
6252
|
+
* Validates that a string is a strict Universally Unique Identifier (UUID).
|
|
6253
|
+
*
|
|
6254
|
+
* **When to use**
|
|
6255
|
+
*
|
|
6256
|
+
* Use when you need UUID semantics, including version and RFC variant bits,
|
|
6257
|
+
* rather than only the dashed hexadecimal shape.
|
|
6040
6258
|
*
|
|
6041
6259
|
* **Details**
|
|
6042
6260
|
*
|
|
6261
|
+
* Without a version argument, this accepts UUID versions 1 through 8, the nil
|
|
6262
|
+
* UUID (`00000000-0000-0000-0000-000000000000`), and the max UUID
|
|
6263
|
+
* (`ffffffff-ffff-ffff-ffff-ffffffffffff`). With a version argument, this
|
|
6264
|
+
* accepts only UUIDs with that version and RFC variant bits; nil and max UUIDs
|
|
6265
|
+
* are not versioned UUIDs and do not match version-specific checks.
|
|
6266
|
+
*
|
|
6043
6267
|
* JSON Schema:
|
|
6044
6268
|
*
|
|
6045
6269
|
* This check corresponds to a `pattern` constraint in JSON Schema that matches
|
|
@@ -6050,6 +6274,7 @@ const getUUIDRegExp = (version?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8): globalThis.RegE
|
|
|
6050
6274
|
* When generating test data with fast-check, this applies a `patterns`
|
|
6051
6275
|
* constraint to ensure generated strings match the UUID pattern.
|
|
6052
6276
|
*
|
|
6277
|
+
* @see {@link isGUID} for shape-only GUID validation.
|
|
6053
6278
|
* @category String checks
|
|
6054
6279
|
* @since 4.0.0
|
|
6055
6280
|
*/
|
|
@@ -6069,6 +6294,46 @@ export function isUUID(version?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8, annotations?: An
|
|
|
6069
6294
|
)
|
|
6070
6295
|
}
|
|
6071
6296
|
|
|
6297
|
+
const GUID_REGEXP = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/
|
|
6298
|
+
|
|
6299
|
+
/**
|
|
6300
|
+
* Validates that a string has the GUID / UUID textual shape.
|
|
6301
|
+
*
|
|
6302
|
+
* **When to use**
|
|
6303
|
+
*
|
|
6304
|
+
* Use when you need to accept dashed hexadecimal identifiers without enforcing
|
|
6305
|
+
* UUID version or variant bits.
|
|
6306
|
+
*
|
|
6307
|
+
* **Details**
|
|
6308
|
+
*
|
|
6309
|
+
* This check accepts strings in the `8-4-4-4-12` hexadecimal form. JSON Schema
|
|
6310
|
+
* output includes the corresponding `pattern` constraint and intentionally does
|
|
6311
|
+
* not include `format: "uuid"` because GUID validation is looser than UUID
|
|
6312
|
+
* validation.
|
|
6313
|
+
*
|
|
6314
|
+
* Arbitrary:
|
|
6315
|
+
*
|
|
6316
|
+
* When generating test data with fast-check, this applies a `patterns`
|
|
6317
|
+
* constraint to ensure generated strings match the GUID pattern.
|
|
6318
|
+
*
|
|
6319
|
+
* @see {@link isUUID} for strict UUID validation.
|
|
6320
|
+
* @category String checks
|
|
6321
|
+
* @since 4.0.0
|
|
6322
|
+
*/
|
|
6323
|
+
export function isGUID(annotations?: Annotations.Filter) {
|
|
6324
|
+
return isPattern(
|
|
6325
|
+
GUID_REGEXP,
|
|
6326
|
+
{
|
|
6327
|
+
expected: "a GUID",
|
|
6328
|
+
meta: {
|
|
6329
|
+
_tag: "isGUID",
|
|
6330
|
+
regExp: GUID_REGEXP
|
|
6331
|
+
},
|
|
6332
|
+
...annotations
|
|
6333
|
+
}
|
|
6334
|
+
)
|
|
6335
|
+
}
|
|
6336
|
+
|
|
6072
6337
|
/**
|
|
6073
6338
|
* Validates that a string is a valid ULID (Universally Unique Lexicographically
|
|
6074
6339
|
* Sortable Identifier).
|
|
@@ -6874,7 +7139,7 @@ export function isInt(annotations?: Annotations.Filter) {
|
|
|
6874
7139
|
* @since 4.0.0
|
|
6875
7140
|
*/
|
|
6876
7141
|
export function isInt32(annotations?: Annotations.Filter) {
|
|
6877
|
-
return new
|
|
7142
|
+
return new SchemaAST.FilterGroup(
|
|
6878
7143
|
[
|
|
6879
7144
|
isInt(annotations),
|
|
6880
7145
|
isBetween({ minimum: -2147483648, maximum: 2147483647 })
|
|
@@ -6906,7 +7171,7 @@ export function isInt32(annotations?: Annotations.Filter) {
|
|
|
6906
7171
|
* @since 4.0.0
|
|
6907
7172
|
*/
|
|
6908
7173
|
export function isUint32(annotations?: Annotations.Filter) {
|
|
6909
|
-
return new
|
|
7174
|
+
return new SchemaAST.FilterGroup(
|
|
6910
7175
|
[
|
|
6911
7176
|
isInt(),
|
|
6912
7177
|
isBetween({ minimum: 0, maximum: 4294967295 })
|
|
@@ -7377,7 +7642,7 @@ export function isMinLength(minLength: number, annotations?: Annotations.Filter)
|
|
|
7377
7642
|
_tag: "isMinLength",
|
|
7378
7643
|
minLength
|
|
7379
7644
|
},
|
|
7380
|
-
[
|
|
7645
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7381
7646
|
toArbitraryConstraint: {
|
|
7382
7647
|
string: {
|
|
7383
7648
|
minLength
|
|
@@ -7444,7 +7709,7 @@ export function isMaxLength(maxLength: number, annotations?: Annotations.Filter)
|
|
|
7444
7709
|
_tag: "isMaxLength",
|
|
7445
7710
|
maxLength
|
|
7446
7711
|
},
|
|
7447
|
-
[
|
|
7712
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7448
7713
|
toArbitraryConstraint: {
|
|
7449
7714
|
string: {
|
|
7450
7715
|
maxLength
|
|
@@ -7492,7 +7757,7 @@ export function isLengthBetween(minimum: number, maximum: number, annotations?:
|
|
|
7492
7757
|
minimum,
|
|
7493
7758
|
maximum
|
|
7494
7759
|
},
|
|
7495
|
-
[
|
|
7760
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7496
7761
|
toArbitraryConstraint: {
|
|
7497
7762
|
string: {
|
|
7498
7763
|
minLength: minimum,
|
|
@@ -7538,7 +7803,7 @@ export function isMinSize(minSize: number, annotations?: Annotations.Filter) {
|
|
|
7538
7803
|
_tag: "isMinSize",
|
|
7539
7804
|
minSize
|
|
7540
7805
|
},
|
|
7541
|
-
[
|
|
7806
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7542
7807
|
toArbitraryConstraint: {
|
|
7543
7808
|
array: {
|
|
7544
7809
|
minLength: minSize
|
|
@@ -7579,7 +7844,7 @@ export function isMaxSize(maxSize: number, annotations?: Annotations.Filter) {
|
|
|
7579
7844
|
_tag: "isMaxSize",
|
|
7580
7845
|
maxSize
|
|
7581
7846
|
},
|
|
7582
|
-
[
|
|
7847
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7583
7848
|
toArbitraryConstraint: {
|
|
7584
7849
|
array: {
|
|
7585
7850
|
maxLength: maxSize
|
|
@@ -7624,7 +7889,7 @@ export function isSizeBetween(minimum: number, maximum: number, annotations?: An
|
|
|
7624
7889
|
minimum,
|
|
7625
7890
|
maximum
|
|
7626
7891
|
},
|
|
7627
|
-
[
|
|
7892
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7628
7893
|
toArbitraryConstraint: {
|
|
7629
7894
|
array: {
|
|
7630
7895
|
minLength: minimum,
|
|
@@ -7667,7 +7932,7 @@ export function isMinProperties(minProperties: number, annotations?: Annotations
|
|
|
7667
7932
|
_tag: "isMinProperties",
|
|
7668
7933
|
minProperties
|
|
7669
7934
|
},
|
|
7670
|
-
[
|
|
7935
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7671
7936
|
toArbitraryConstraint: {
|
|
7672
7937
|
array: {
|
|
7673
7938
|
minLength: minProperties
|
|
@@ -7708,7 +7973,7 @@ export function isMaxProperties(maxProperties: number, annotations?: Annotations
|
|
|
7708
7973
|
_tag: "isMaxProperties",
|
|
7709
7974
|
maxProperties
|
|
7710
7975
|
},
|
|
7711
|
-
[
|
|
7976
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7712
7977
|
toArbitraryConstraint: {
|
|
7713
7978
|
array: {
|
|
7714
7979
|
maxLength: maxProperties
|
|
@@ -7753,7 +8018,7 @@ export function isPropertiesLengthBetween(minimum: number, maximum: number, anno
|
|
|
7753
8018
|
minimum,
|
|
7754
8019
|
maximum
|
|
7755
8020
|
},
|
|
7756
|
-
[
|
|
8021
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7757
8022
|
toArbitraryConstraint: {
|
|
7758
8023
|
array: {
|
|
7759
8024
|
minLength: minimum,
|
|
@@ -7783,20 +8048,20 @@ export function isPropertiesLengthBetween(minimum: number, maximum: number, anno
|
|
|
7783
8048
|
*/
|
|
7784
8049
|
export function isPropertyNames(keySchema: Top, annotations?: Annotations.Filter) {
|
|
7785
8050
|
const propertyNames = toEncoded(keySchema)
|
|
7786
|
-
const parser =
|
|
8051
|
+
const parser = SchemaParser._issue(propertyNames.ast)
|
|
7787
8052
|
return makeFilter<object>(
|
|
7788
8053
|
(input, ast, options) => {
|
|
7789
8054
|
const keys = Reflect.ownKeys(input)
|
|
7790
|
-
const issues: Array<
|
|
8055
|
+
const issues: Array<SchemaIssue.Issue> = []
|
|
7791
8056
|
for (const key of keys) {
|
|
7792
8057
|
const issue = parser(key, options)
|
|
7793
8058
|
if (issue !== undefined) {
|
|
7794
|
-
issues.push(new
|
|
8059
|
+
issues.push(new SchemaIssue.Pointer([key], issue))
|
|
7795
8060
|
if (options.errors === "first") break
|
|
7796
8061
|
}
|
|
7797
8062
|
}
|
|
7798
8063
|
if (Arr.isArrayNonEmpty(issues)) {
|
|
7799
|
-
return new
|
|
8064
|
+
return new SchemaIssue.Composite(ast, Option_.some(input), issues)
|
|
7800
8065
|
}
|
|
7801
8066
|
return true
|
|
7802
8067
|
},
|
|
@@ -7806,7 +8071,7 @@ export function isPropertyNames(keySchema: Top, annotations?: Annotations.Filter
|
|
|
7806
8071
|
_tag: "isPropertyNames",
|
|
7807
8072
|
propertyNames: propertyNames.ast
|
|
7808
8073
|
},
|
|
7809
|
-
[
|
|
8074
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7810
8075
|
...annotations
|
|
7811
8076
|
}
|
|
7812
8077
|
)
|
|
@@ -7952,14 +8217,15 @@ export function Option<A extends Top>(value: A): Option<A> {
|
|
|
7952
8217
|
return Effect.succeedNone
|
|
7953
8218
|
}
|
|
7954
8219
|
return Effect.mapBothEager(
|
|
7955
|
-
|
|
8220
|
+
SchemaParser.decodeUnknownEffect(value)(input.value, options),
|
|
7956
8221
|
{
|
|
7957
8222
|
onSuccess: Option_.some,
|
|
7958
|
-
onFailure: (issue) =>
|
|
8223
|
+
onFailure: (issue) =>
|
|
8224
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["value"], issue)])
|
|
7959
8225
|
}
|
|
7960
8226
|
)
|
|
7961
8227
|
}
|
|
7962
|
-
return Effect.fail(new
|
|
8228
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
7963
8229
|
},
|
|
7964
8230
|
{
|
|
7965
8231
|
typeConstructor: {
|
|
@@ -7977,7 +8243,7 @@ export function Option<A extends Top>(value: A): Option<A> {
|
|
|
7977
8243
|
Struct({ _tag: Literal("Some"), value }),
|
|
7978
8244
|
Struct({ _tag: Literal("None") })
|
|
7979
8245
|
]),
|
|
7980
|
-
|
|
8246
|
+
SchemaTransformation.transform({
|
|
7981
8247
|
decode: (e) => e._tag === "None" ? Option_.none() : Option_.some(e.value),
|
|
7982
8248
|
encode: (o) => (Option_.isSome(o) ? { _tag: "Some", value: o.value } as const : { _tag: "None" } as const)
|
|
7983
8249
|
})
|
|
@@ -8015,13 +8281,8 @@ export interface OptionFromNullOr<S extends Top> extends decodeTo<Option<toType<
|
|
|
8015
8281
|
*
|
|
8016
8282
|
* **Details**
|
|
8017
8283
|
*
|
|
8018
|
-
* Decoding
|
|
8019
|
-
*
|
|
8020
|
-
* - other values are decoded as `Some`
|
|
8021
|
-
*
|
|
8022
|
-
* Encoding:
|
|
8023
|
-
* - `None` is encoded as `null`
|
|
8024
|
-
* - `Some` is encoded as the value
|
|
8284
|
+
* Decoding maps `null` to `None` and all other values to `Some`. Encoding maps
|
|
8285
|
+
* `None` to `null` and maps `Some` to its value.
|
|
8025
8286
|
*
|
|
8026
8287
|
* @category Option
|
|
8027
8288
|
* @since 3.10.0
|
|
@@ -8029,7 +8290,7 @@ export interface OptionFromNullOr<S extends Top> extends decodeTo<Option<toType<
|
|
|
8029
8290
|
export function OptionFromNullOr<S extends Top>(schema: S): OptionFromNullOr<S> {
|
|
8030
8291
|
return NullOr(schema).pipe(decodeTo(
|
|
8031
8292
|
Option(toType(schema)),
|
|
8032
|
-
|
|
8293
|
+
SchemaTransformation.optionFromNullOr()
|
|
8033
8294
|
))
|
|
8034
8295
|
}
|
|
8035
8296
|
|
|
@@ -8044,17 +8305,13 @@ export interface OptionFromUndefinedOr<S extends Top> extends decodeTo<Option<to
|
|
|
8044
8305
|
}
|
|
8045
8306
|
|
|
8046
8307
|
/**
|
|
8047
|
-
* Decodes
|
|
8308
|
+
* Decodes a required value that may be `undefined` to a required `Option<T>`
|
|
8309
|
+
* value.
|
|
8048
8310
|
*
|
|
8049
8311
|
* **Details**
|
|
8050
8312
|
*
|
|
8051
|
-
* Decoding
|
|
8052
|
-
*
|
|
8053
|
-
* - other values are decoded as `Some`
|
|
8054
|
-
*
|
|
8055
|
-
* Encoding:
|
|
8056
|
-
* - `None` is encoded as `undefined`
|
|
8057
|
-
* - `Some` is encoded as the value
|
|
8313
|
+
* Decoding maps `undefined` to `None` and all other values to `Some`. Encoding
|
|
8314
|
+
* maps `None` to `undefined` and maps `Some` to its value.
|
|
8058
8315
|
*
|
|
8059
8316
|
* @category Option
|
|
8060
8317
|
* @since 3.10.0
|
|
@@ -8062,7 +8319,7 @@ export interface OptionFromUndefinedOr<S extends Top> extends decodeTo<Option<to
|
|
|
8062
8319
|
export function OptionFromUndefinedOr<S extends Top>(schema: S): OptionFromUndefinedOr<S> {
|
|
8063
8320
|
return UndefinedOr(schema).pipe(decodeTo(
|
|
8064
8321
|
Option(toType(schema)),
|
|
8065
|
-
|
|
8322
|
+
SchemaTransformation.optionFromUndefinedOr()
|
|
8066
8323
|
))
|
|
8067
8324
|
}
|
|
8068
8325
|
|
|
@@ -8081,13 +8338,10 @@ export interface OptionFromNullishOr<S extends Top> extends decodeTo<Option<toTy
|
|
|
8081
8338
|
*
|
|
8082
8339
|
* **Details**
|
|
8083
8340
|
*
|
|
8084
|
-
* Decoding
|
|
8085
|
-
*
|
|
8086
|
-
*
|
|
8087
|
-
*
|
|
8088
|
-
* Encoding:
|
|
8089
|
-
* - `None` is encoded as `null` or `undefined` depending on the provided `options.onNoneEncoding` (defaults to `undefined`)
|
|
8090
|
-
* - `Some` is encoded as the value
|
|
8341
|
+
* Decoding maps `null` and `undefined` to `None` and all other values to
|
|
8342
|
+
* `Some`. Encoding maps `None` to `null` or `undefined` depending on
|
|
8343
|
+
* `options.onNoneEncoding`, which defaults to `undefined`, and maps `Some` to
|
|
8344
|
+
* its value.
|
|
8091
8345
|
*
|
|
8092
8346
|
* @category Option
|
|
8093
8347
|
* @since 3.10.0
|
|
@@ -8100,7 +8354,7 @@ export function OptionFromNullishOr<S extends Top>(
|
|
|
8100
8354
|
): OptionFromNullishOr<S> {
|
|
8101
8355
|
return NullishOr(schema).pipe(decodeTo(
|
|
8102
8356
|
Option(toType(schema)),
|
|
8103
|
-
|
|
8357
|
+
SchemaTransformation.optionFromNullishOr(options)
|
|
8104
8358
|
))
|
|
8105
8359
|
}
|
|
8106
8360
|
|
|
@@ -8119,13 +8373,8 @@ export interface OptionFromOptionalKey<S extends Top> extends decodeTo<Option<to
|
|
|
8119
8373
|
*
|
|
8120
8374
|
* **Details**
|
|
8121
8375
|
*
|
|
8122
|
-
* Decoding
|
|
8123
|
-
*
|
|
8124
|
-
* - a present value is decoded as `Some`
|
|
8125
|
-
*
|
|
8126
|
-
* Encoding:
|
|
8127
|
-
* - `None` is encoded as missing key
|
|
8128
|
-
* - `Some` is encoded as the value
|
|
8376
|
+
* Decoding maps a missing key to `None` and a present value to `Some`.
|
|
8377
|
+
* Encoding maps `None` to a missing key and maps `Some` to its value.
|
|
8129
8378
|
*
|
|
8130
8379
|
* @category Option
|
|
8131
8380
|
* @since 4.0.0
|
|
@@ -8133,7 +8382,7 @@ export interface OptionFromOptionalKey<S extends Top> extends decodeTo<Option<to
|
|
|
8133
8382
|
export function OptionFromOptionalKey<S extends Top>(schema: S): OptionFromOptionalKey<S> {
|
|
8134
8383
|
return optionalKey(schema).pipe(decodeTo(
|
|
8135
8384
|
Option(toType(schema)),
|
|
8136
|
-
|
|
8385
|
+
SchemaTransformation.optionFromOptionalKey()
|
|
8137
8386
|
))
|
|
8138
8387
|
}
|
|
8139
8388
|
|
|
@@ -8148,19 +8397,14 @@ export interface OptionFromOptional<S extends Top> extends decodeTo<Option<toTyp
|
|
|
8148
8397
|
}
|
|
8149
8398
|
|
|
8150
8399
|
/**
|
|
8151
|
-
* Decodes an optional or `undefined` value `A` to
|
|
8400
|
+
* Decodes an optional or `undefined` value `A` to a required `Option<A>`
|
|
8152
8401
|
* value.
|
|
8153
8402
|
*
|
|
8154
8403
|
* **Details**
|
|
8155
8404
|
*
|
|
8156
|
-
* Decoding
|
|
8157
|
-
*
|
|
8158
|
-
*
|
|
8159
|
-
* - all other values are decoded as `Some`
|
|
8160
|
-
*
|
|
8161
|
-
* Encoding:
|
|
8162
|
-
* - `None` is encoded as missing key
|
|
8163
|
-
* - `Some` is encoded as the value
|
|
8405
|
+
* Decoding maps a missing key or a present `undefined` value to `None`, and
|
|
8406
|
+
* maps all other values to `Some`. Encoding maps `None` to a missing key and
|
|
8407
|
+
* maps `Some` to its value.
|
|
8164
8408
|
*
|
|
8165
8409
|
* @category Option
|
|
8166
8410
|
* @since 4.0.0
|
|
@@ -8168,7 +8412,7 @@ export interface OptionFromOptional<S extends Top> extends decodeTo<Option<toTyp
|
|
|
8168
8412
|
export function OptionFromOptional<S extends Top>(schema: S): OptionFromOptional<S> {
|
|
8169
8413
|
return optional(schema).pipe(decodeTo(
|
|
8170
8414
|
Option(toType(schema)),
|
|
8171
|
-
|
|
8415
|
+
SchemaTransformation.optionFromOptional<any>()
|
|
8172
8416
|
))
|
|
8173
8417
|
}
|
|
8174
8418
|
|
|
@@ -8188,17 +8432,10 @@ export interface OptionFromOptionalNullOr<S extends Top> extends decodeTo<Option
|
|
|
8188
8432
|
*
|
|
8189
8433
|
* **Details**
|
|
8190
8434
|
*
|
|
8191
|
-
* Decoding
|
|
8192
|
-
*
|
|
8193
|
-
*
|
|
8194
|
-
*
|
|
8195
|
-
* - all other values are decoded as `Some`
|
|
8196
|
-
*
|
|
8197
|
-
* Encoding (controlled by `options.onNoneEncoding`):
|
|
8198
|
-
* - `"omit"` (default): `None` is encoded as a missing key
|
|
8199
|
-
* - `null`: `None` is encoded as `null`
|
|
8200
|
-
* - `undefined`: `None` is encoded as `undefined`
|
|
8201
|
-
* - `Some` is always encoded as the value
|
|
8435
|
+
* Decoding maps a missing key, `undefined`, or `null` to `None`, and maps all
|
|
8436
|
+
* other values to `Some`. Encoding maps `Some` to its value. `None` is encoded
|
|
8437
|
+
* according to `options.onNoneEncoding`: `"omit"` encodes a missing key,
|
|
8438
|
+
* `null` encodes `null`, and `undefined` encodes `undefined`.
|
|
8202
8439
|
*
|
|
8203
8440
|
* @category Option
|
|
8204
8441
|
* @since 4.0.0
|
|
@@ -8215,7 +8452,7 @@ export function OptionFromOptionalNullOr<S extends Top>(
|
|
|
8215
8452
|
: undefined as S["Type"] | null | undefined
|
|
8216
8453
|
return optional(NullOr(schema)).pipe(decodeTo(
|
|
8217
8454
|
Option(toType(schema)),
|
|
8218
|
-
|
|
8455
|
+
SchemaTransformation.transformOptional<Option_.Option<S["Type"]>, S["Type"] | null | undefined>({
|
|
8219
8456
|
decode: (oe) => oe.pipe(Option_.filter(Predicate.isNotNullish), Option_.some),
|
|
8220
8457
|
encode: onNoneEncoding === "omit"
|
|
8221
8458
|
? Option_.flatten
|
|
@@ -8276,18 +8513,20 @@ export function Result<A extends Top, E extends Top>(
|
|
|
8276
8513
|
[success, failure],
|
|
8277
8514
|
([success, failure]) => (input, ast, options) => {
|
|
8278
8515
|
if (!Result_.isResult(input)) {
|
|
8279
|
-
return Effect.fail(new
|
|
8516
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
8280
8517
|
}
|
|
8281
8518
|
switch (input._tag) {
|
|
8282
8519
|
case "Success":
|
|
8283
|
-
return Effect.mapBothEager(
|
|
8520
|
+
return Effect.mapBothEager(SchemaParser.decodeEffect(success)(input.success, options), {
|
|
8284
8521
|
onSuccess: Result_.succeed,
|
|
8285
|
-
onFailure: (issue) =>
|
|
8522
|
+
onFailure: (issue) =>
|
|
8523
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["success"], issue)])
|
|
8286
8524
|
})
|
|
8287
8525
|
case "Failure":
|
|
8288
|
-
return Effect.mapBothEager(
|
|
8526
|
+
return Effect.mapBothEager(SchemaParser.decodeEffect(failure)(input.failure, options), {
|
|
8289
8527
|
onSuccess: Result_.fail,
|
|
8290
|
-
onFailure: (issue) =>
|
|
8528
|
+
onFailure: (issue) =>
|
|
8529
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["failure"], issue)])
|
|
8291
8530
|
})
|
|
8292
8531
|
}
|
|
8293
8532
|
},
|
|
@@ -8307,7 +8546,7 @@ export function Result<A extends Top, E extends Top>(
|
|
|
8307
8546
|
Struct({ _tag: Literal("Success"), success }),
|
|
8308
8547
|
Struct({ _tag: Literal("Failure"), failure })
|
|
8309
8548
|
]),
|
|
8310
|
-
|
|
8549
|
+
SchemaTransformation.transform({
|
|
8311
8550
|
decode: (e): Result_.Result<A["Encoded"], E["Encoded"]> =>
|
|
8312
8551
|
e._tag === "Success" ? Result_.succeed(e.success) : Result_.fail(e.failure),
|
|
8313
8552
|
encode: (r) =>
|
|
@@ -8379,43 +8618,44 @@ export function Redacted<S extends Top>(value: S, options?: {
|
|
|
8379
8618
|
readonly disallowJsonEncode?: boolean | undefined
|
|
8380
8619
|
}): Redacted<S> {
|
|
8381
8620
|
const decodeLabel = typeof options?.label === "string"
|
|
8382
|
-
?
|
|
8621
|
+
? SchemaParser.decodeUnknownEffect(Literal(options.label))
|
|
8383
8622
|
: undefined
|
|
8384
8623
|
const schema = declareConstructor<Redacted_.Redacted<S["Type"]>, Redacted_.Redacted<S["Encoded"]>>()(
|
|
8385
8624
|
[value],
|
|
8386
8625
|
([value]) => (input, ast, poptions) => {
|
|
8387
8626
|
if (Redacted_.isRedacted(input)) {
|
|
8388
|
-
const label: Effect.Effect<void,
|
|
8627
|
+
const label: Effect.Effect<void, SchemaIssue.Issue, never> = decodeLabel !== undefined
|
|
8389
8628
|
? Effect.mapErrorEager(
|
|
8390
8629
|
decodeLabel(input.label, poptions),
|
|
8391
|
-
(issue) => new
|
|
8630
|
+
(issue) => new SchemaIssue.Pointer(["label"], issue)
|
|
8392
8631
|
)
|
|
8393
8632
|
: Effect.void
|
|
8394
8633
|
return Effect.flatMapEager(
|
|
8395
8634
|
label,
|
|
8396
8635
|
() =>
|
|
8397
8636
|
Effect.mapBothEager(
|
|
8398
|
-
|
|
8637
|
+
SchemaParser.decodeUnknownEffect(value)(Redacted_.value(input), poptions),
|
|
8399
8638
|
{
|
|
8400
8639
|
onSuccess: () => input,
|
|
8401
8640
|
onFailure: (/** ignore the actual issue because of security reasons */) => {
|
|
8402
8641
|
const oinput = Option_.some(input)
|
|
8403
|
-
return new
|
|
8404
|
-
new
|
|
8642
|
+
return new SchemaIssue.Composite(ast, oinput, [
|
|
8643
|
+
new SchemaIssue.Pointer(["value"], new SchemaIssue.InvalidValue(oinput))
|
|
8405
8644
|
])
|
|
8406
8645
|
}
|
|
8407
8646
|
}
|
|
8408
8647
|
)
|
|
8409
8648
|
)
|
|
8410
8649
|
}
|
|
8411
|
-
return Effect.fail(new
|
|
8650
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
8412
8651
|
},
|
|
8413
8652
|
{
|
|
8414
8653
|
typeConstructor: {
|
|
8415
|
-
_tag: "effect/Redacted"
|
|
8654
|
+
_tag: "effect/Redacted",
|
|
8655
|
+
options
|
|
8416
8656
|
},
|
|
8417
8657
|
generation: {
|
|
8418
|
-
runtime: `Schema.Redacted(?)`,
|
|
8658
|
+
runtime: options !== undefined ? `Schema.Redacted(?, ${format(options)})` : `Schema.Redacted(?)`,
|
|
8419
8659
|
Type: `Redacted.Redacted<?>`,
|
|
8420
8660
|
importDeclaration: `import * as Redacted from "effect/Redacted"`
|
|
8421
8661
|
},
|
|
@@ -8424,13 +8664,13 @@ export function Redacted<S extends Top>(value: S, options?: {
|
|
|
8424
8664
|
link<Redacted_.Redacted<S["Encoded"]>>()(
|
|
8425
8665
|
redact(value),
|
|
8426
8666
|
{
|
|
8427
|
-
decode:
|
|
8667
|
+
decode: SchemaGetter.transform((e) => Redacted_.make(e, { label: options?.label })),
|
|
8428
8668
|
encode: options?.disallowJsonEncode ?
|
|
8429
|
-
|
|
8669
|
+
SchemaGetter.forbidden((oe) =>
|
|
8430
8670
|
"Cannot serialize Redacted" +
|
|
8431
8671
|
(Option_.isSome(oe) && typeof oe.value.label === "string" ? ` with label: "${oe.value.label}"` : "")
|
|
8432
8672
|
) :
|
|
8433
|
-
|
|
8673
|
+
SchemaGetter.transform(Redacted_.value)
|
|
8434
8674
|
}
|
|
8435
8675
|
),
|
|
8436
8676
|
toArbitrary: ([value]) => () => value.map((a) => Redacted_.make(a, { label: options?.label })),
|
|
@@ -8461,7 +8701,7 @@ export interface RedactedFromValue<S extends Top>
|
|
|
8461
8701
|
* @since 4.0.0
|
|
8462
8702
|
*/
|
|
8463
8703
|
export function redact<S extends Top>(schema: S): middlewareDecoding<S, S["DecodingServices"]> {
|
|
8464
|
-
return schema.pipe(middlewareDecoding(Effect.mapErrorEager(
|
|
8704
|
+
return schema.pipe(middlewareDecoding(Effect.mapErrorEager(SchemaIssue.redact)))
|
|
8465
8705
|
}
|
|
8466
8706
|
|
|
8467
8707
|
/**
|
|
@@ -8483,13 +8723,13 @@ export function RedactedFromValue<S extends Top>(value: S, options?: {
|
|
|
8483
8723
|
disallowJsonEncode: options?.disallowEncode
|
|
8484
8724
|
}),
|
|
8485
8725
|
{
|
|
8486
|
-
decode:
|
|
8726
|
+
decode: SchemaGetter.transform((t) => Redacted_.make(t, { label: options?.label })),
|
|
8487
8727
|
encode: options?.disallowEncode ?
|
|
8488
|
-
|
|
8728
|
+
SchemaGetter.forbidden((oe) =>
|
|
8489
8729
|
"Cannot encode Redacted" +
|
|
8490
8730
|
(Option_.isSome(oe) && typeof oe.value.label === "string" ? ` with label: "${oe.value.label}"` : "")
|
|
8491
8731
|
) :
|
|
8492
|
-
|
|
8732
|
+
SchemaGetter.transform(Redacted_.value)
|
|
8493
8733
|
}
|
|
8494
8734
|
)
|
|
8495
8735
|
)
|
|
@@ -8542,8 +8782,8 @@ export type CauseReasonIso<E extends Top, D extends Top> = {
|
|
|
8542
8782
|
*
|
|
8543
8783
|
* **When to use**
|
|
8544
8784
|
*
|
|
8545
|
-
* Use
|
|
8546
|
-
*
|
|
8785
|
+
* Use when serializing or decoding individual cause reasons separately from a
|
|
8786
|
+
* full failure cause, with distinct schemas for typed errors and defects.
|
|
8547
8787
|
*
|
|
8548
8788
|
* **Details**
|
|
8549
8789
|
*
|
|
@@ -8561,24 +8801,25 @@ export function CauseReason<E extends Top, D extends Top>(error: E, defect: D):
|
|
|
8561
8801
|
[error, defect],
|
|
8562
8802
|
([error, defect]) => (input, ast, options) => {
|
|
8563
8803
|
if (!Cause_.isReason(input)) {
|
|
8564
|
-
return Effect.fail(new
|
|
8804
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
8565
8805
|
}
|
|
8566
8806
|
switch (input._tag) {
|
|
8567
8807
|
case "Fail":
|
|
8568
8808
|
return Effect.mapBothEager(
|
|
8569
|
-
|
|
8809
|
+
SchemaParser.decodeUnknownEffect(error)(input.error, options),
|
|
8570
8810
|
{
|
|
8571
8811
|
onSuccess: Cause_.makeFailReason,
|
|
8572
|
-
onFailure: (issue) =>
|
|
8812
|
+
onFailure: (issue) =>
|
|
8813
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["error"], issue)])
|
|
8573
8814
|
}
|
|
8574
8815
|
)
|
|
8575
8816
|
case "Die":
|
|
8576
8817
|
return Effect.mapBothEager(
|
|
8577
|
-
|
|
8818
|
+
SchemaParser.decodeUnknownEffect(defect)(input.defect, options),
|
|
8578
8819
|
{
|
|
8579
8820
|
onSuccess: Cause_.makeDieReason,
|
|
8580
8821
|
onFailure: (issue) =>
|
|
8581
|
-
new
|
|
8822
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["defect"], issue)])
|
|
8582
8823
|
}
|
|
8583
8824
|
)
|
|
8584
8825
|
case "Interrupt":
|
|
@@ -8602,7 +8843,7 @@ export function CauseReason<E extends Top, D extends Top>(error: E, defect: D):
|
|
|
8602
8843
|
Struct({ _tag: Literal("Die"), defect }),
|
|
8603
8844
|
Struct({ _tag: Literal("Interrupt"), fiberId: UndefinedOr(Finite) })
|
|
8604
8845
|
]),
|
|
8605
|
-
|
|
8846
|
+
SchemaTransformation.transform({
|
|
8606
8847
|
decode: (e) => {
|
|
8607
8848
|
switch (e._tag) {
|
|
8608
8849
|
case "Fail":
|
|
@@ -8727,11 +8968,12 @@ export function Cause<E extends Top, D extends Top>(error: E, defect: D): Cause<
|
|
|
8727
8968
|
const failures = ArraySchema(CauseReason(error, defect))
|
|
8728
8969
|
return (input, ast, options) => {
|
|
8729
8970
|
if (!Cause_.isCause(input)) {
|
|
8730
|
-
return Effect.fail(new
|
|
8971
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
8731
8972
|
}
|
|
8732
|
-
return Effect.mapBothEager(
|
|
8973
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(failures)(input.reasons, options), {
|
|
8733
8974
|
onSuccess: Cause_.fromReasons,
|
|
8734
|
-
onFailure: (issue) =>
|
|
8975
|
+
onFailure: (issue) =>
|
|
8976
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["failures"], issue)])
|
|
8735
8977
|
})
|
|
8736
8978
|
}
|
|
8737
8979
|
},
|
|
@@ -8748,7 +8990,7 @@ export function Cause<E extends Top, D extends Top>(error: E, defect: D): Cause<
|
|
|
8748
8990
|
toCodec: ([error, defect]) =>
|
|
8749
8991
|
link<Cause_.Cause<E["Encoded"]>>()(
|
|
8750
8992
|
ArraySchema(CauseReason(error, defect)),
|
|
8751
|
-
|
|
8993
|
+
SchemaTransformation.transform({
|
|
8752
8994
|
decode: Cause_.fromReasons,
|
|
8753
8995
|
encode: ({ reasons: failures }) => failures
|
|
8754
8996
|
})
|
|
@@ -8787,69 +9029,87 @@ export interface Error extends instanceOf<globalThis.Error> {
|
|
|
8787
9029
|
readonly "Rebuild": Error
|
|
8788
9030
|
}
|
|
8789
9031
|
|
|
8790
|
-
const ErrorJsonEncoded = Struct({
|
|
8791
|
-
message: String,
|
|
8792
|
-
name: optionalKey(String),
|
|
8793
|
-
stack: optionalKey(String)
|
|
8794
|
-
})
|
|
8795
|
-
|
|
8796
9032
|
/**
|
|
8797
|
-
*
|
|
9033
|
+
* Options for {@link Error} and {@link Defect}.
|
|
8798
9034
|
*
|
|
8799
|
-
*
|
|
8800
|
-
*
|
|
8801
|
-
* Default JSON serializer:
|
|
8802
|
-
* Encodes an `Error` as an object with `message` and optional `name` properties,
|
|
8803
|
-
* and decodes that object back into an `Error`. The stack trace is omitted from
|
|
8804
|
-
* the encoded form for security.
|
|
8805
|
-
*
|
|
8806
|
-
* @category schemas
|
|
9035
|
+
* @category options
|
|
8807
9036
|
* @since 4.0.0
|
|
8808
9037
|
*/
|
|
8809
|
-
export
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
|
|
9038
|
+
export interface ErrorOptions {
|
|
9039
|
+
/**
|
|
9040
|
+
* Includes string stack traces in encoded `Error` values when set to `true`.
|
|
9041
|
+
*
|
|
9042
|
+
* @default false
|
|
9043
|
+
*/
|
|
9044
|
+
readonly includeStack?: boolean | undefined
|
|
9045
|
+
/**
|
|
9046
|
+
* Excludes `Error.cause` values from encoded `Error` values when set to
|
|
9047
|
+
* `true`.
|
|
9048
|
+
*
|
|
9049
|
+
* @default false
|
|
9050
|
+
*/
|
|
9051
|
+
readonly excludeCause?: boolean | undefined
|
|
9052
|
+
}
|
|
9053
|
+
|
|
9054
|
+
type ErrorOptionsKey = 0 | 1 | 2 | 3
|
|
9055
|
+
|
|
9056
|
+
const getErrorOptionsKey = (options?: ErrorOptions): ErrorOptionsKey =>
|
|
9057
|
+
((options?.includeStack === true ? 1 : 0) |
|
|
9058
|
+
(options?.excludeCause === true ? 2 : 0)) as ErrorOptionsKey
|
|
9059
|
+
|
|
9060
|
+
const getErrorOptions = (key: ErrorOptionsKey): ErrorOptions | undefined => {
|
|
9061
|
+
switch (key) {
|
|
9062
|
+
case 0:
|
|
9063
|
+
return undefined
|
|
9064
|
+
case 1:
|
|
9065
|
+
return { includeStack: true }
|
|
9066
|
+
case 2:
|
|
9067
|
+
return { excludeCause: true }
|
|
9068
|
+
case 3:
|
|
9069
|
+
return { includeStack: true, excludeCause: true }
|
|
9070
|
+
}
|
|
9071
|
+
}
|
|
9072
|
+
|
|
9073
|
+
const errorSchemaCache: Array<Error | undefined> = []
|
|
8821
9074
|
|
|
8822
9075
|
/**
|
|
8823
|
-
* Schema for JavaScript `Error` objects
|
|
8824
|
-
* encoded form.
|
|
9076
|
+
* Schema for JavaScript `Error` objects.
|
|
8825
9077
|
*
|
|
8826
9078
|
* **Details**
|
|
8827
9079
|
*
|
|
8828
9080
|
* Default JSON serializer:
|
|
9081
|
+
*
|
|
8829
9082
|
* Encodes an `Error` as an object with `message`, optional `name`, and optional
|
|
8830
|
-
* `
|
|
9083
|
+
* `cause` properties, and decodes that object back into an `Error`. Stack
|
|
9084
|
+
* traces are omitted by default for security. Pass `{ includeStack: true }` to
|
|
9085
|
+
* include stack traces, or `{ excludeCause: true }` to omit causes.
|
|
8831
9086
|
*
|
|
8832
|
-
* @category
|
|
9087
|
+
* @category constructors
|
|
8833
9088
|
* @since 4.0.0
|
|
8834
9089
|
*/
|
|
8835
|
-
export
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
|
|
8850
|
-
|
|
8851
|
-
|
|
8852
|
-
|
|
9090
|
+
export function Error(options?: ErrorOptions): Error {
|
|
9091
|
+
const key = getErrorOptionsKey(options)
|
|
9092
|
+
const cached = errorSchemaCache[key]
|
|
9093
|
+
if (cached !== undefined) {
|
|
9094
|
+
return cached
|
|
9095
|
+
}
|
|
9096
|
+
const normalizedOptions = getErrorOptions(key)
|
|
9097
|
+
const schema = instanceOf(globalThis.Error, {
|
|
9098
|
+
typeConstructor: {
|
|
9099
|
+
_tag: "Error",
|
|
9100
|
+
...(normalizedOptions === undefined ? {} : { options: normalizedOptions })
|
|
9101
|
+
},
|
|
9102
|
+
generation: {
|
|
9103
|
+
runtime: normalizedOptions !== undefined ? `Schema.Error(${format(normalizedOptions)})` : `Schema.Error()`,
|
|
9104
|
+
Type: `globalThis.Error`
|
|
9105
|
+
},
|
|
9106
|
+
expected: "Error",
|
|
9107
|
+
toCodecJson: () => link<globalThis.Error>()(JsonError, SchemaTransformation.errorFromJsonError(normalizedOptions)),
|
|
9108
|
+
toArbitrary: () => (fc) => fc.string().map((message) => new globalThis.Error(message))
|
|
9109
|
+
})
|
|
9110
|
+
errorSchemaCache[key] = schema
|
|
9111
|
+
return schema
|
|
9112
|
+
}
|
|
8853
9113
|
|
|
8854
9114
|
/**
|
|
8855
9115
|
* Type-level representation of {@link Defect}.
|
|
@@ -8857,80 +9117,63 @@ export const ErrorWithStack: Error = instanceOf(globalThis.Error, {
|
|
|
8857
9117
|
* @category Defect
|
|
8858
9118
|
* @since 3.10.0
|
|
8859
9119
|
*/
|
|
8860
|
-
export interface Defect extends
|
|
8861
|
-
Union<
|
|
8862
|
-
readonly [
|
|
8863
|
-
decodeTo<
|
|
8864
|
-
Error,
|
|
8865
|
-
Struct<{
|
|
8866
|
-
readonly message: String
|
|
8867
|
-
readonly name: optionalKey<String>
|
|
8868
|
-
readonly stack: optionalKey<String>
|
|
8869
|
-
}>
|
|
8870
|
-
>,
|
|
8871
|
-
decodeTo<Unknown, Any>
|
|
8872
|
-
]
|
|
8873
|
-
>
|
|
8874
|
-
{
|
|
9120
|
+
export interface Defect extends decodeTo<Unknown, typeof Json> {
|
|
8875
9121
|
readonly "Rebuild": Defect
|
|
8876
9122
|
}
|
|
8877
9123
|
|
|
8878
|
-
const
|
|
8879
|
-
Getter.passthrough(),
|
|
8880
|
-
Getter.transform((u) => {
|
|
8881
|
-
try {
|
|
8882
|
-
return JSON.parse(JSON.stringify(u))
|
|
8883
|
-
} catch {
|
|
8884
|
-
return format(u)
|
|
8885
|
-
}
|
|
8886
|
-
})
|
|
8887
|
-
)
|
|
9124
|
+
const defectSchemaCache: Array<Defect | undefined> = []
|
|
8888
9125
|
|
|
8889
9126
|
/**
|
|
8890
|
-
* Schema for defect values
|
|
8891
|
-
*
|
|
9127
|
+
* Schema for unexpected defect values represented as `unknown` with a JSON
|
|
9128
|
+
* encoded form.
|
|
9129
|
+
*
|
|
9130
|
+
* **When to use**
|
|
9131
|
+
*
|
|
9132
|
+
* Use when you need a schema for `Cause` defects or other unexpected failures
|
|
9133
|
+
* whose runtime value may be any value.
|
|
8892
9134
|
*
|
|
8893
9135
|
* **Details**
|
|
8894
9136
|
*
|
|
8895
|
-
*
|
|
8896
|
-
*
|
|
8897
|
-
*
|
|
9137
|
+
* The encoded side is {@link Json}. During decoding, JSON objects with a string
|
|
9138
|
+
* `message` property are decoded into JavaScript `Error` values, preserving a
|
|
9139
|
+
* non-default `name` and any string `stack`. Other JSON values decode
|
|
9140
|
+
* unchanged.
|
|
8898
9141
|
*
|
|
8899
|
-
*
|
|
8900
|
-
*
|
|
8901
|
-
|
|
8902
|
-
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
Unknown.annotate({
|
|
8906
|
-
toCodecJson: () => link<unknown>()(Any, defectTransformation),
|
|
8907
|
-
toArbitrary: () => (fc) => fc.json()
|
|
8908
|
-
}),
|
|
8909
|
-
defectTransformation
|
|
8910
|
-
))
|
|
8911
|
-
])
|
|
8912
|
-
|
|
8913
|
-
/**
|
|
8914
|
-
* Schema for defects that also includes stack traces in the encoded form.
|
|
9142
|
+
* During encoding, JavaScript `Error` values encode to JSON objects with
|
|
9143
|
+
* `name`, `message`, and optional `cause` properties. Pass
|
|
9144
|
+
* `{ includeStack: true }` to include string stack traces in encoded `Error`
|
|
9145
|
+
* defects, or `{ excludeCause: true }` to omit causes. Other values are
|
|
9146
|
+
* serialized through Effect's JSON formatter and then parsed back into JSON
|
|
9147
|
+
* when possible.
|
|
8915
9148
|
*
|
|
8916
|
-
*
|
|
9149
|
+
* **Gotchas**
|
|
9150
|
+
*
|
|
9151
|
+
* This schema is for carrying defects across JSON boundaries, not for
|
|
9152
|
+
* preserving every JavaScript value exactly. Some values cannot round-trip
|
|
9153
|
+
* unchanged:
|
|
9154
|
+
*
|
|
9155
|
+
* - A non-`Error` object such as `{ message: "boom" }` encodes as an
|
|
9156
|
+
* error-shaped JSON object and decodes back as an `Error`.
|
|
9157
|
+
* - JSON serialization normalizes unsupported values. For example,
|
|
9158
|
+
* `undefined` array elements encode as `null`, unsupported object properties
|
|
9159
|
+
* are omitted, and circular references are dropped.
|
|
9160
|
+
* - Values that cannot be represented as JSON fall back to Effect's formatted
|
|
9161
|
+
* string representation.
|
|
9162
|
+
*
|
|
9163
|
+
* @see {@link Error} for a schema that only accepts JavaScript `Error` values.
|
|
9164
|
+
* @category constructors
|
|
8917
9165
|
* @since 4.0.0
|
|
8918
9166
|
*/
|
|
8919
|
-
export
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
))
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8929
|
-
toArbitrary: () => (fc) => fc.json()
|
|
8930
|
-
}),
|
|
8931
|
-
defectTransformation
|
|
8932
|
-
))
|
|
8933
|
-
])
|
|
9167
|
+
export function Defect(options?: ErrorOptions): Defect {
|
|
9168
|
+
const key = getErrorOptionsKey(options)
|
|
9169
|
+
const cached = defectSchemaCache[key]
|
|
9170
|
+
if (cached !== undefined) {
|
|
9171
|
+
return cached
|
|
9172
|
+
}
|
|
9173
|
+
const schema = Json.pipe(decodeTo(Unknown, SchemaTransformation.defectFromJson(getErrorOptions(key))))
|
|
9174
|
+
defectSchemaCache[key] = schema
|
|
9175
|
+
return schema
|
|
9176
|
+
}
|
|
8934
9177
|
|
|
8935
9178
|
/**
|
|
8936
9179
|
* Type-level representation returned by {@link Exit}.
|
|
@@ -8975,6 +9218,11 @@ export type ExitIso<A extends Top, E extends Top, D extends Top> = {
|
|
|
8975
9218
|
* Creates a schema for `Exit` values using schemas for the success value, typed
|
|
8976
9219
|
* failure, and unexpected defect channels.
|
|
8977
9220
|
*
|
|
9221
|
+
* **When to use**
|
|
9222
|
+
*
|
|
9223
|
+
* Use when serializing or validating an effect outcome where success, typed
|
|
9224
|
+
* failure, and defects each need their own schema.
|
|
9225
|
+
*
|
|
8978
9226
|
* @category Exit
|
|
8979
9227
|
* @since 3.10.0
|
|
8980
9228
|
*/
|
|
@@ -8989,25 +9237,25 @@ export function Exit<A extends Top, E extends Top, D extends Top>(value: A, erro
|
|
|
8989
9237
|
const cause = Cause(error, defect)
|
|
8990
9238
|
return (input, ast, options) => {
|
|
8991
9239
|
if (!Exit_.isExit(input)) {
|
|
8992
|
-
return Effect.fail(new
|
|
9240
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
8993
9241
|
}
|
|
8994
9242
|
switch (input._tag) {
|
|
8995
9243
|
case "Success":
|
|
8996
9244
|
return Effect.mapBothEager(
|
|
8997
|
-
|
|
9245
|
+
SchemaParser.decodeUnknownEffect(value)(input.value, options),
|
|
8998
9246
|
{
|
|
8999
9247
|
onSuccess: Exit_.succeed,
|
|
9000
9248
|
onFailure: (issue) =>
|
|
9001
|
-
new
|
|
9249
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["value"], issue)])
|
|
9002
9250
|
}
|
|
9003
9251
|
)
|
|
9004
9252
|
case "Failure":
|
|
9005
9253
|
return Effect.mapBothEager(
|
|
9006
|
-
|
|
9254
|
+
SchemaParser.decodeUnknownEffect(cause)(input.cause, options),
|
|
9007
9255
|
{
|
|
9008
9256
|
onSuccess: Exit_.failCause,
|
|
9009
9257
|
onFailure: (issue) =>
|
|
9010
|
-
new
|
|
9258
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["cause"], issue)])
|
|
9011
9259
|
}
|
|
9012
9260
|
)
|
|
9013
9261
|
}
|
|
@@ -9029,7 +9277,7 @@ export function Exit<A extends Top, E extends Top, D extends Top>(value: A, erro
|
|
|
9029
9277
|
Struct({ _tag: Literal("Success"), value }),
|
|
9030
9278
|
Struct({ _tag: Literal("Failure"), cause: Cause(error, defect) })
|
|
9031
9279
|
]),
|
|
9032
|
-
|
|
9280
|
+
SchemaTransformation.transform({
|
|
9033
9281
|
decode: (e): Exit_.Exit<A["Encoded"], E["Encoded"]> =>
|
|
9034
9282
|
e._tag === "Success" ? Exit_.succeed(e.value) : Exit_.failCause(e.cause),
|
|
9035
9283
|
encode: (exit) =>
|
|
@@ -9119,15 +9367,15 @@ export function ReadonlyMap<Key extends Top, Value extends Top>(key: Key, value:
|
|
|
9119
9367
|
return (input, ast, options) => {
|
|
9120
9368
|
if (input instanceof globalThis.Map) {
|
|
9121
9369
|
return Effect.mapBothEager(
|
|
9122
|
-
|
|
9370
|
+
SchemaParser.decodeUnknownEffect(array)([...input], options),
|
|
9123
9371
|
{
|
|
9124
9372
|
onSuccess: (array: ReadonlyArray<readonly [Key["Type"], Value["Type"]]>) => new globalThis.Map(array),
|
|
9125
9373
|
onFailure: (issue) =>
|
|
9126
|
-
new
|
|
9374
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["entries"], issue)])
|
|
9127
9375
|
}
|
|
9128
9376
|
)
|
|
9129
9377
|
}
|
|
9130
|
-
return Effect.fail(new
|
|
9378
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
9131
9379
|
}
|
|
9132
9380
|
},
|
|
9133
9381
|
{
|
|
@@ -9142,7 +9390,7 @@ export function ReadonlyMap<Key extends Top, Value extends Top>(key: Key, value:
|
|
|
9142
9390
|
toCodec: ([key, value]) =>
|
|
9143
9391
|
link<globalThis.Map<Key["Encoded"], Value["Encoded"]>>()(
|
|
9144
9392
|
ArraySchema(Tuple([key, value])),
|
|
9145
|
-
|
|
9393
|
+
SchemaTransformation.transform({
|
|
9146
9394
|
decode: (e) => new globalThis.Map(e),
|
|
9147
9395
|
encode: (map) => [...map.entries()]
|
|
9148
9396
|
})
|
|
@@ -9214,15 +9462,15 @@ export function HashMap<Key extends Top, Value extends Top>(key: Key, value: Val
|
|
|
9214
9462
|
return (input, ast, options) => {
|
|
9215
9463
|
if (HashMap_.isHashMap(input)) {
|
|
9216
9464
|
return Effect.mapBothEager(
|
|
9217
|
-
|
|
9465
|
+
SchemaParser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options),
|
|
9218
9466
|
{
|
|
9219
9467
|
onSuccess: HashMap_.fromIterable,
|
|
9220
9468
|
onFailure: (issue) =>
|
|
9221
|
-
new
|
|
9469
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["entries"], issue)])
|
|
9222
9470
|
}
|
|
9223
9471
|
)
|
|
9224
9472
|
}
|
|
9225
|
-
return Effect.fail(new
|
|
9473
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
9226
9474
|
}
|
|
9227
9475
|
},
|
|
9228
9476
|
{
|
|
@@ -9238,7 +9486,7 @@ export function HashMap<Key extends Top, Value extends Top>(key: Key, value: Val
|
|
|
9238
9486
|
toCodec: ([key, value]) =>
|
|
9239
9487
|
link<HashMap_.HashMap<Key["Encoded"], Value["Encoded"]>>()(
|
|
9240
9488
|
ArraySchema(Tuple([key, value])),
|
|
9241
|
-
|
|
9489
|
+
SchemaTransformation.transform({
|
|
9242
9490
|
decode: HashMap_.fromIterable,
|
|
9243
9491
|
encode: HashMap_.toEntries
|
|
9244
9492
|
})
|
|
@@ -9309,15 +9557,15 @@ export function ReadonlySet<Value extends Top>(value: Value): $ReadonlySet<Value
|
|
|
9309
9557
|
return (input, ast, options) => {
|
|
9310
9558
|
if (input instanceof globalThis.Set) {
|
|
9311
9559
|
return Effect.mapBothEager(
|
|
9312
|
-
|
|
9560
|
+
SchemaParser.decodeUnknownEffect(array)([...input], options),
|
|
9313
9561
|
{
|
|
9314
9562
|
onSuccess: (array: ReadonlyArray<Value["Type"]>) => new globalThis.Set(array),
|
|
9315
9563
|
onFailure: (issue) =>
|
|
9316
|
-
new
|
|
9564
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["values"], issue)])
|
|
9317
9565
|
}
|
|
9318
9566
|
)
|
|
9319
9567
|
}
|
|
9320
|
-
return Effect.fail(new
|
|
9568
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
9321
9569
|
}
|
|
9322
9570
|
},
|
|
9323
9571
|
{
|
|
@@ -9332,7 +9580,7 @@ export function ReadonlySet<Value extends Top>(value: Value): $ReadonlySet<Value
|
|
|
9332
9580
|
toCodec: ([value]) =>
|
|
9333
9581
|
link<globalThis.Set<Value["Encoded"]>>()(
|
|
9334
9582
|
ArraySchema(value),
|
|
9335
|
-
|
|
9583
|
+
SchemaTransformation.transform({
|
|
9336
9584
|
decode: (e) => new globalThis.Set(e),
|
|
9337
9585
|
encode: (set) => [...set.values()]
|
|
9338
9586
|
})
|
|
@@ -9403,15 +9651,15 @@ export function HashSet<Value extends Top>(value: Value): HashSet<Value> {
|
|
|
9403
9651
|
return (input, ast, options) => {
|
|
9404
9652
|
if (HashSet_.isHashSet(input)) {
|
|
9405
9653
|
return Effect.mapBothEager(
|
|
9406
|
-
|
|
9654
|
+
SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
|
|
9407
9655
|
{
|
|
9408
9656
|
onSuccess: HashSet_.fromIterable,
|
|
9409
9657
|
onFailure: (issue) =>
|
|
9410
|
-
new
|
|
9658
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["values"], issue)])
|
|
9411
9659
|
}
|
|
9412
9660
|
)
|
|
9413
9661
|
}
|
|
9414
|
-
return Effect.fail(new
|
|
9662
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
9415
9663
|
}
|
|
9416
9664
|
},
|
|
9417
9665
|
{
|
|
@@ -9426,7 +9674,7 @@ export function HashSet<Value extends Top>(value: Value): HashSet<Value> {
|
|
|
9426
9674
|
toCodec: ([value]) =>
|
|
9427
9675
|
link<HashSet_.HashSet<Value["Encoded"]>>()(
|
|
9428
9676
|
ArraySchema(value),
|
|
9429
|
-
|
|
9677
|
+
SchemaTransformation.transform({
|
|
9430
9678
|
decode: HashSet_.fromIterable,
|
|
9431
9679
|
encode: Arr.fromIterable
|
|
9432
9680
|
})
|
|
@@ -9504,15 +9752,15 @@ export function Chunk<Value extends Top>(value: Value): Chunk<Value> {
|
|
|
9504
9752
|
return (input, ast, options) => {
|
|
9505
9753
|
if (Chunk_.isChunk(input)) {
|
|
9506
9754
|
return Effect.mapBothEager(
|
|
9507
|
-
|
|
9755
|
+
SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
|
|
9508
9756
|
{
|
|
9509
9757
|
onSuccess: Chunk_.fromIterable,
|
|
9510
9758
|
onFailure: (issue) =>
|
|
9511
|
-
new
|
|
9759
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["values"], issue)])
|
|
9512
9760
|
}
|
|
9513
9761
|
)
|
|
9514
9762
|
}
|
|
9515
|
-
return Effect.fail(new
|
|
9763
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
9516
9764
|
}
|
|
9517
9765
|
},
|
|
9518
9766
|
{
|
|
@@ -9527,7 +9775,7 @@ export function Chunk<Value extends Top>(value: Value): Chunk<Value> {
|
|
|
9527
9775
|
toCodec: ([value]) =>
|
|
9528
9776
|
link<Chunk_.Chunk<Value["Encoded"]>>()(
|
|
9529
9777
|
ArraySchema(value),
|
|
9530
|
-
|
|
9778
|
+
SchemaTransformation.transform({
|
|
9531
9779
|
decode: Chunk_.fromIterable,
|
|
9532
9780
|
encode: Arr.fromIterable
|
|
9533
9781
|
})
|
|
@@ -9590,11 +9838,11 @@ export const RegExp: RegExp = instanceOf(
|
|
|
9590
9838
|
source: String,
|
|
9591
9839
|
flags: String
|
|
9592
9840
|
}),
|
|
9593
|
-
|
|
9841
|
+
SchemaTransformation.transformOrFail({
|
|
9594
9842
|
decode: (e) =>
|
|
9595
9843
|
Effect.try({
|
|
9596
9844
|
try: () => new globalThis.RegExp(e.source, e.flags),
|
|
9597
|
-
catch: (e) => new
|
|
9845
|
+
catch: (e) => new SchemaIssue.InvalidValue(Option_.some(e), { message: globalThis.String(e) })
|
|
9598
9846
|
}),
|
|
9599
9847
|
encode: (regExp) =>
|
|
9600
9848
|
Effect.succeed({
|
|
@@ -9667,7 +9915,7 @@ export const URL: URL = instanceOf(
|
|
|
9667
9915
|
toCodecJson: () =>
|
|
9668
9916
|
link<globalThis.URL>()(
|
|
9669
9917
|
URLString,
|
|
9670
|
-
|
|
9918
|
+
SchemaTransformation.urlFromString
|
|
9671
9919
|
),
|
|
9672
9920
|
toArbitrary: () => (fc) => fc.webUrl().map((s) => new globalThis.URL(s)),
|
|
9673
9921
|
toEquivalence: () => (a, b) => a.toString() === b.toString()
|
|
@@ -9698,7 +9946,7 @@ export interface URLFromString extends decodeTo<URL, String> {
|
|
|
9698
9946
|
* @category URL
|
|
9699
9947
|
* @since 4.0.0
|
|
9700
9948
|
*/
|
|
9701
|
-
export const URLFromString: URLFromString = URLString.pipe(decodeTo(URL,
|
|
9949
|
+
export const URLFromString: URLFromString = URLString.pipe(decodeTo(URL, SchemaTransformation.urlFromString))
|
|
9702
9950
|
|
|
9703
9951
|
/**
|
|
9704
9952
|
* Type-level representation of {@link Date}.
|
|
@@ -9717,8 +9965,8 @@ const DateString = String.annotate({ expected: "a string in ISO 8601 format that
|
|
|
9717
9965
|
*
|
|
9718
9966
|
* **When to use**
|
|
9719
9967
|
*
|
|
9720
|
-
* Use to validate in-memory values that must already be JavaScript
|
|
9721
|
-
*
|
|
9968
|
+
* Use to validate in-memory values that must already be JavaScript date
|
|
9969
|
+
* objects.
|
|
9722
9970
|
*
|
|
9723
9971
|
* **Details**
|
|
9724
9972
|
*
|
|
@@ -9754,7 +10002,7 @@ export const Date: Date = instanceOf(
|
|
|
9754
10002
|
toCodecJson: () =>
|
|
9755
10003
|
link<globalThis.Date>()(
|
|
9756
10004
|
DateString,
|
|
9757
|
-
|
|
10005
|
+
SchemaTransformation.dateFromString
|
|
9758
10006
|
),
|
|
9759
10007
|
toArbitrary: () => (fc, ctx) => fc.date(ctx?.constraints?.date)
|
|
9760
10008
|
}
|
|
@@ -9797,7 +10045,7 @@ export interface DateFromString extends decodeTo<Date, String> {
|
|
|
9797
10045
|
* @category Date
|
|
9798
10046
|
* @since 3.10.0
|
|
9799
10047
|
*/
|
|
9800
|
-
export const DateFromString: DateFromString = DateString.pipe(decodeTo(Date,
|
|
10048
|
+
export const DateFromString: DateFromString = DateString.pipe(decodeTo(Date, SchemaTransformation.dateFromString))
|
|
9801
10049
|
|
|
9802
10050
|
/**
|
|
9803
10051
|
* Type-level representation of {@link DateValid}.
|
|
@@ -9873,7 +10121,7 @@ export const Duration: Duration = declare(
|
|
|
9873
10121
|
Struct({ _tag: Literal("Nanos"), value: BigInt }),
|
|
9874
10122
|
Struct({ _tag: Literal("Millis"), value: Int })
|
|
9875
10123
|
]),
|
|
9876
|
-
|
|
10124
|
+
SchemaTransformation.transform({
|
|
9877
10125
|
decode: (e) => {
|
|
9878
10126
|
switch (e._tag) {
|
|
9879
10127
|
case "Infinity":
|
|
@@ -9940,7 +10188,7 @@ export interface DurationFromString extends decodeTo<Duration, String> {
|
|
|
9940
10188
|
* @since 4.0.0
|
|
9941
10189
|
*/
|
|
9942
10190
|
export const DurationFromString: DurationFromString = DurationString.pipe(
|
|
9943
|
-
decodeTo(Duration,
|
|
10191
|
+
decodeTo(Duration, SchemaTransformation.durationFromString)
|
|
9944
10192
|
)
|
|
9945
10193
|
|
|
9946
10194
|
/**
|
|
@@ -9973,7 +10221,7 @@ const bigint0 = globalThis.BigInt(0)
|
|
|
9973
10221
|
* @since 3.10.0
|
|
9974
10222
|
*/
|
|
9975
10223
|
export const DurationFromNanos: DurationFromNanos = BigInt.check(isGreaterThanOrEqualToBigInt(bigint0)).pipe(
|
|
9976
|
-
decodeTo(Duration,
|
|
10224
|
+
decodeTo(Duration, SchemaTransformation.durationFromNanos)
|
|
9977
10225
|
)
|
|
9978
10226
|
|
|
9979
10227
|
/**
|
|
@@ -10005,7 +10253,7 @@ export interface DurationFromMillis extends decodeTo<Duration, Number> {
|
|
|
10005
10253
|
* @since 3.10.0
|
|
10006
10254
|
*/
|
|
10007
10255
|
export const DurationFromMillis: DurationFromMillis = Number.check(isGreaterThanOrEqualTo(0)).pipe(
|
|
10008
|
-
decodeTo(Duration,
|
|
10256
|
+
decodeTo(Duration, SchemaTransformation.durationFromMillis)
|
|
10009
10257
|
)
|
|
10010
10258
|
|
|
10011
10259
|
/**
|
|
@@ -10025,7 +10273,7 @@ const BigDecimalString = String.annotate({ expected: "a string that will be deco
|
|
|
10025
10273
|
*
|
|
10026
10274
|
* **When to use**
|
|
10027
10275
|
*
|
|
10028
|
-
* Use when
|
|
10276
|
+
* Use when you already have Effect decimal instances and need schema
|
|
10029
10277
|
* validation, formatting, equivalence, and JSON string serialization.
|
|
10030
10278
|
*
|
|
10031
10279
|
* **Details**
|
|
@@ -10054,7 +10302,7 @@ export const BigDecimal: BigDecimal = declare(
|
|
|
10054
10302
|
toCodecJson: () =>
|
|
10055
10303
|
link<BigDecimal_.BigDecimal>()(
|
|
10056
10304
|
BigDecimalString,
|
|
10057
|
-
|
|
10305
|
+
SchemaTransformation.bigDecimalFromString
|
|
10058
10306
|
),
|
|
10059
10307
|
toArbitrary: () => (fc) =>
|
|
10060
10308
|
fc.tuple(fc.bigInt(), fc.integer({ min: 0, max: 20 }))
|
|
@@ -10102,7 +10350,7 @@ export interface BigDecimalFromString extends decodeTo<BigDecimal, String> {
|
|
|
10102
10350
|
* @since 4.0.0
|
|
10103
10351
|
*/
|
|
10104
10352
|
export const BigDecimalFromString: BigDecimalFromString = BigDecimalString.pipe(
|
|
10105
|
-
decodeTo(BigDecimal,
|
|
10353
|
+
decodeTo(BigDecimal, SchemaTransformation.bigDecimalFromString)
|
|
10106
10354
|
)
|
|
10107
10355
|
|
|
10108
10356
|
/**
|
|
@@ -10222,8 +10470,8 @@ export function fromJsonString<S extends Top>(schema: S): fromJsonString<S> {
|
|
|
10222
10470
|
return String.annotate({
|
|
10223
10471
|
expected: "a string that will be decoded as JSON",
|
|
10224
10472
|
contentMediaType: "application/json",
|
|
10225
|
-
contentSchema:
|
|
10226
|
-
}).pipe(decodeTo(schema,
|
|
10473
|
+
contentSchema: SchemaAST.toEncoded(schema.ast)
|
|
10474
|
+
}).pipe(decodeTo(schema, SchemaTransformation.fromJsonString))
|
|
10227
10475
|
}
|
|
10228
10476
|
|
|
10229
10477
|
/**
|
|
@@ -10264,12 +10512,12 @@ export const File: File = instanceOf(globalThis.File, {
|
|
|
10264
10512
|
name: String,
|
|
10265
10513
|
lastModified: Number
|
|
10266
10514
|
}),
|
|
10267
|
-
|
|
10515
|
+
SchemaTransformation.transformOrFail({
|
|
10268
10516
|
decode: (e) =>
|
|
10269
10517
|
Result_.match(Encoding.decodeBase64(e.data), {
|
|
10270
10518
|
onFailure: (error) =>
|
|
10271
10519
|
Effect.fail(
|
|
10272
|
-
new
|
|
10520
|
+
new SchemaIssue.InvalidValue(Option_.some(e.data), {
|
|
10273
10521
|
message: error.message
|
|
10274
10522
|
})
|
|
10275
10523
|
),
|
|
@@ -10292,7 +10540,7 @@ export const File: File = instanceOf(globalThis.File, {
|
|
|
10292
10540
|
}
|
|
10293
10541
|
},
|
|
10294
10542
|
catch: (e) =>
|
|
10295
|
-
new
|
|
10543
|
+
new SchemaIssue.InvalidValue(Option_.some(file), {
|
|
10296
10544
|
message: globalThis.String(e)
|
|
10297
10545
|
})
|
|
10298
10546
|
})
|
|
@@ -10341,7 +10589,7 @@ export const FormData: FormData = instanceOf(globalThis.FormData, {
|
|
|
10341
10589
|
])
|
|
10342
10590
|
])
|
|
10343
10591
|
),
|
|
10344
|
-
|
|
10592
|
+
SchemaTransformation.transformOrFail({
|
|
10345
10593
|
decode: (e) => {
|
|
10346
10594
|
const out = new globalThis.FormData()
|
|
10347
10595
|
for (const [key, entry] of e) {
|
|
@@ -10463,7 +10711,7 @@ export interface fromFormData<S extends Top> extends decodeTo<S, FormData> {
|
|
|
10463
10711
|
* @since 4.0.0
|
|
10464
10712
|
*/
|
|
10465
10713
|
export function fromFormData<S extends Top>(schema: S): fromFormData<S> {
|
|
10466
|
-
return FormData.pipe(decodeTo(schema,
|
|
10714
|
+
return FormData.pipe(decodeTo(schema, SchemaTransformation.fromFormData))
|
|
10467
10715
|
}
|
|
10468
10716
|
|
|
10469
10717
|
/**
|
|
@@ -10498,7 +10746,7 @@ export const URLSearchParams: URLSearchParams = instanceOf(globalThis.URLSearchP
|
|
|
10498
10746
|
toCodecJson: () =>
|
|
10499
10747
|
link<globalThis.URLSearchParams>()(
|
|
10500
10748
|
String.annotate({ expected: "a query string that will be decoded as URLSearchParams" }),
|
|
10501
|
-
|
|
10749
|
+
SchemaTransformation.transform({
|
|
10502
10750
|
decode: (e) => new globalThis.URLSearchParams(e),
|
|
10503
10751
|
encode: (params) => params.toString()
|
|
10504
10752
|
})
|
|
@@ -10596,7 +10844,7 @@ export interface fromURLSearchParams<S extends Top> extends decodeTo<S, URLSearc
|
|
|
10596
10844
|
* @since 4.0.0
|
|
10597
10845
|
*/
|
|
10598
10846
|
export function fromURLSearchParams<S extends Top>(schema: S): fromURLSearchParams<S> {
|
|
10599
|
-
return URLSearchParams.pipe(decodeTo(schema,
|
|
10847
|
+
return URLSearchParams.pipe(decodeTo(schema, SchemaTransformation.fromURLSearchParams))
|
|
10600
10848
|
}
|
|
10601
10849
|
|
|
10602
10850
|
/**
|
|
@@ -10664,7 +10912,7 @@ export interface NumberFromString extends decodeTo<Finite, String> {
|
|
|
10664
10912
|
*/
|
|
10665
10913
|
export const NumberFromString: NumberFromString = String.annotate({
|
|
10666
10914
|
expected: "a string that will be decoded as a number"
|
|
10667
|
-
}).pipe(decodeTo(Number,
|
|
10915
|
+
}).pipe(decodeTo(Number, SchemaTransformation.numberFromString))
|
|
10668
10916
|
|
|
10669
10917
|
/**
|
|
10670
10918
|
* Type-level representation of {@link FiniteFromString}.
|
|
@@ -10693,7 +10941,7 @@ export interface FiniteFromString extends decodeTo<Finite, String> {
|
|
|
10693
10941
|
*/
|
|
10694
10942
|
export const FiniteFromString: FiniteFromString = String.annotate({
|
|
10695
10943
|
expected: "a string that will be decoded as a finite number"
|
|
10696
|
-
}).pipe(decodeTo(Finite,
|
|
10944
|
+
}).pipe(decodeTo(Finite, SchemaTransformation.numberFromString))
|
|
10697
10945
|
|
|
10698
10946
|
/**
|
|
10699
10947
|
* Type-level representation of {@link BigIntFromString}.
|
|
@@ -10733,8 +10981,8 @@ export interface BigIntFromString extends decodeTo<BigInt, String> {
|
|
|
10733
10981
|
* @category BigInt
|
|
10734
10982
|
* @since 4.0.0
|
|
10735
10983
|
*/
|
|
10736
|
-
export const BigIntFromString: BigIntFromString = make<String>(
|
|
10737
|
-
decodeTo(BigInt,
|
|
10984
|
+
export const BigIntFromString: BigIntFromString = make<String>(SchemaAST.bigIntString).pipe(
|
|
10985
|
+
decodeTo(BigInt, SchemaTransformation.bigintFromString)
|
|
10738
10986
|
)
|
|
10739
10987
|
|
|
10740
10988
|
/**
|
|
@@ -10781,7 +11029,7 @@ export interface Trim extends decodeTo<Trimmed, String> {
|
|
|
10781
11029
|
*/
|
|
10782
11030
|
export const Trim: Trim = String.annotate({
|
|
10783
11031
|
expected: "a string that will be decoded as a trimmed string"
|
|
10784
|
-
}).pipe(decodeTo(Trimmed,
|
|
11032
|
+
}).pipe(decodeTo(Trimmed, SchemaTransformation.trim()))
|
|
10785
11033
|
|
|
10786
11034
|
/**
|
|
10787
11035
|
* Type-level representation of {@link StringFromBase64}.
|
|
@@ -10810,7 +11058,7 @@ export interface StringFromBase64 extends decodeTo<String, String> {
|
|
|
10810
11058
|
export const StringFromBase64: StringFromBase64 = String.annotate({
|
|
10811
11059
|
expected: "a base64 encoded string that will be decoded as a UTF-8 string"
|
|
10812
11060
|
}).pipe(
|
|
10813
|
-
decodeTo(String,
|
|
11061
|
+
decodeTo(String, SchemaTransformation.stringFromBase64String)
|
|
10814
11062
|
)
|
|
10815
11063
|
|
|
10816
11064
|
/**
|
|
@@ -10840,7 +11088,7 @@ export interface StringFromBase64Url extends decodeTo<String, String> {
|
|
|
10840
11088
|
export const StringFromBase64Url: StringFromBase64Url = String.annotate({
|
|
10841
11089
|
expected: "a base64 (URL) encoded string that will be decoded as a UTF-8 string"
|
|
10842
11090
|
}).pipe(
|
|
10843
|
-
decodeTo(String,
|
|
11091
|
+
decodeTo(String, SchemaTransformation.stringFromBase64UrlString)
|
|
10844
11092
|
)
|
|
10845
11093
|
|
|
10846
11094
|
/**
|
|
@@ -10870,7 +11118,7 @@ export interface StringFromHex extends decodeTo<String, String> {
|
|
|
10870
11118
|
export const StringFromHex: StringFromHex = String.annotate({
|
|
10871
11119
|
expected: "a hex encoded string that will be decoded as a UTF-8 string"
|
|
10872
11120
|
}).pipe(
|
|
10873
|
-
decodeTo(String,
|
|
11121
|
+
decodeTo(String, SchemaTransformation.stringFromHexString)
|
|
10874
11122
|
)
|
|
10875
11123
|
|
|
10876
11124
|
/**
|
|
@@ -10919,7 +11167,7 @@ export interface StringFromUriComponent extends decodeTo<String, String> {
|
|
|
10919
11167
|
export const StringFromUriComponent: StringFromUriComponent = String.annotate({
|
|
10920
11168
|
expected: "a URI component encoded string that will be decoded as a UTF-8 string"
|
|
10921
11169
|
}).pipe(
|
|
10922
|
-
decodeTo(String,
|
|
11170
|
+
decodeTo(String, SchemaTransformation.stringFromUriComponent)
|
|
10923
11171
|
)
|
|
10924
11172
|
|
|
10925
11173
|
/**
|
|
@@ -10981,7 +11229,7 @@ export interface BooleanFromBit extends decodeTo<Boolean, Literals<readonly [0,
|
|
|
10981
11229
|
export const BooleanFromBit: BooleanFromBit = Literals([0, 1]).pipe(
|
|
10982
11230
|
decodeTo(
|
|
10983
11231
|
Boolean,
|
|
10984
|
-
|
|
11232
|
+
SchemaTransformation.transform({
|
|
10985
11233
|
decode: (bit) => bit === 1,
|
|
10986
11234
|
encode: (bool) => bool ? 1 : 0
|
|
10987
11235
|
})
|
|
@@ -11028,7 +11276,7 @@ export const Uint8Array: Uint8Array = instanceOf(globalThis.Uint8Array<ArrayBuff
|
|
|
11028
11276
|
toCodecJson: () =>
|
|
11029
11277
|
link<globalThis.Uint8Array<ArrayBufferLike>>()(
|
|
11030
11278
|
Base64String,
|
|
11031
|
-
|
|
11279
|
+
SchemaTransformation.uint8ArrayFromBase64String
|
|
11032
11280
|
),
|
|
11033
11281
|
toArbitrary: () => (fc) => fc.uint8Array()
|
|
11034
11282
|
})
|
|
@@ -11059,7 +11307,7 @@ export interface Uint8ArrayFromBase64 extends decodeTo<Uint8Array, String> {
|
|
|
11059
11307
|
* @since 3.10.0
|
|
11060
11308
|
*/
|
|
11061
11309
|
export const Uint8ArrayFromBase64: Uint8ArrayFromBase64 = Base64String.pipe(
|
|
11062
|
-
decodeTo(Uint8Array,
|
|
11310
|
+
decodeTo(Uint8Array, SchemaTransformation.uint8ArrayFromBase64String)
|
|
11063
11311
|
)
|
|
11064
11312
|
|
|
11065
11313
|
/**
|
|
@@ -11091,8 +11339,8 @@ export const Uint8ArrayFromBase64Url: Uint8ArrayFromBase64Url = String.annotate(
|
|
|
11091
11339
|
expected: "a base64 (URL) encoded string that will be decoded as a Uint8Array"
|
|
11092
11340
|
}).pipe(
|
|
11093
11341
|
decodeTo(Uint8Array, {
|
|
11094
|
-
decode:
|
|
11095
|
-
encode:
|
|
11342
|
+
decode: SchemaGetter.decodeBase64Url(),
|
|
11343
|
+
encode: SchemaGetter.encodeBase64Url()
|
|
11096
11344
|
})
|
|
11097
11345
|
)
|
|
11098
11346
|
|
|
@@ -11125,8 +11373,8 @@ export const Uint8ArrayFromHex: Uint8ArrayFromHex = String.annotate({
|
|
|
11125
11373
|
expected: "a hex encoded string that will be decoded as a Uint8Array"
|
|
11126
11374
|
}).pipe(
|
|
11127
11375
|
decodeTo(Uint8Array, {
|
|
11128
|
-
decode:
|
|
11129
|
-
encode:
|
|
11376
|
+
decode: SchemaGetter.decodeHex(),
|
|
11377
|
+
encode: SchemaGetter.encodeHex()
|
|
11130
11378
|
})
|
|
11131
11379
|
)
|
|
11132
11380
|
|
|
@@ -11176,7 +11424,7 @@ export const DateTimeUtc: DateTimeUtc = declare(
|
|
|
11176
11424
|
toCodecJson: () =>
|
|
11177
11425
|
link<DateTime.Utc>()(
|
|
11178
11426
|
String,
|
|
11179
|
-
|
|
11427
|
+
SchemaTransformation.dateTimeUtcFromString
|
|
11180
11428
|
),
|
|
11181
11429
|
toArbitrary: () => (fc, ctx) =>
|
|
11182
11430
|
fc.date({ noInvalidDate: true, ...ctx?.constraints?.date }).map((date) => DateTime.fromDateUnsafe(date)),
|
|
@@ -11200,8 +11448,8 @@ export interface DateTimeUtcFromDate extends decodeTo<DateTimeUtc, Date> {
|
|
|
11200
11448
|
*
|
|
11201
11449
|
* **When to use**
|
|
11202
11450
|
*
|
|
11203
|
-
* Use when
|
|
11204
|
-
*
|
|
11451
|
+
* Use when you need to decode valid JavaScript `Date` objects into
|
|
11452
|
+
* `DateTime.Utc` values.
|
|
11205
11453
|
*
|
|
11206
11454
|
* **Details**
|
|
11207
11455
|
*
|
|
@@ -11221,8 +11469,8 @@ export interface DateTimeUtcFromDate extends decodeTo<DateTimeUtc, Date> {
|
|
|
11221
11469
|
*/
|
|
11222
11470
|
export const DateTimeUtcFromDate: DateTimeUtcFromDate = DateValid.pipe(
|
|
11223
11471
|
decodeTo(DateTimeUtc, {
|
|
11224
|
-
decode:
|
|
11225
|
-
encode:
|
|
11472
|
+
decode: SchemaGetter.dateTimeUtcFromInput(),
|
|
11473
|
+
encode: SchemaGetter.transform(DateTime.toDateUtc)
|
|
11226
11474
|
})
|
|
11227
11475
|
)
|
|
11228
11476
|
|
|
@@ -11258,7 +11506,7 @@ export const DateTimeUtcFromString: DateTimeUtcFromString = String.annotate({
|
|
|
11258
11506
|
}).pipe(
|
|
11259
11507
|
decodeTo(
|
|
11260
11508
|
DateTimeUtc,
|
|
11261
|
-
|
|
11509
|
+
SchemaTransformation.dateTimeUtcFromString
|
|
11262
11510
|
)
|
|
11263
11511
|
)
|
|
11264
11512
|
|
|
@@ -11288,8 +11536,8 @@ export interface DateTimeUtcFromMillis extends decodeTo<instanceOf<DateTime.Utc>
|
|
|
11288
11536
|
*/
|
|
11289
11537
|
export const DateTimeUtcFromMillis: DateTimeUtcFromMillis = Number.pipe(
|
|
11290
11538
|
decodeTo(DateTimeUtc, {
|
|
11291
|
-
decode:
|
|
11292
|
-
encode:
|
|
11539
|
+
decode: SchemaGetter.dateTimeUtcFromInput(),
|
|
11540
|
+
encode: SchemaGetter.transform(DateTime.toEpochMillis)
|
|
11293
11541
|
})
|
|
11294
11542
|
)
|
|
11295
11543
|
|
|
@@ -11330,7 +11578,7 @@ export const TimeZoneOffset: TimeZoneOffset = declare(
|
|
|
11330
11578
|
toCodecJson: () =>
|
|
11331
11579
|
link<DateTime.TimeZone.Offset>()(
|
|
11332
11580
|
Number,
|
|
11333
|
-
|
|
11581
|
+
SchemaTransformation.timeZoneOffsetFromNumber
|
|
11334
11582
|
),
|
|
11335
11583
|
toArbitrary: () => (fc) =>
|
|
11336
11584
|
fc.integer({ min: -12 * 60 * 60 * 1000, max: 14 * 60 * 60 * 1000 }).map((n) => DateTime.zoneMakeOffset(n)),
|
|
@@ -11378,7 +11626,7 @@ export const TimeZoneNamed: TimeZoneNamed = declare(
|
|
|
11378
11626
|
toCodecJson: () =>
|
|
11379
11627
|
link<DateTime.TimeZone.Named>()(
|
|
11380
11628
|
TimeZoneNamedString,
|
|
11381
|
-
|
|
11629
|
+
SchemaTransformation.timeZoneNamedFromString
|
|
11382
11630
|
),
|
|
11383
11631
|
toArbitrary: () => (fc) =>
|
|
11384
11632
|
fc.constantFrom(
|
|
@@ -11416,7 +11664,7 @@ export interface TimeZoneNamedFromString extends decodeTo<TimeZoneNamed, String>
|
|
|
11416
11664
|
* @since 4.0.0
|
|
11417
11665
|
*/
|
|
11418
11666
|
export const TimeZoneNamedFromString: TimeZoneNamedFromString = TimeZoneNamedString.pipe(
|
|
11419
|
-
decodeTo(TimeZoneNamed,
|
|
11667
|
+
decodeTo(TimeZoneNamed, SchemaTransformation.timeZoneNamedFromString)
|
|
11420
11668
|
)
|
|
11421
11669
|
|
|
11422
11670
|
/**
|
|
@@ -11461,7 +11709,7 @@ export const TimeZone: TimeZone = declare(
|
|
|
11461
11709
|
toCodecJson: () =>
|
|
11462
11710
|
link<DateTime.TimeZone>()(
|
|
11463
11711
|
TimeZoneString,
|
|
11464
|
-
|
|
11712
|
+
SchemaTransformation.timeZoneFromString
|
|
11465
11713
|
),
|
|
11466
11714
|
toArbitrary: () => (fc) =>
|
|
11467
11715
|
fc.oneof(
|
|
@@ -11502,7 +11750,7 @@ export interface TimeZoneFromString extends decodeTo<TimeZone, String> {
|
|
|
11502
11750
|
* @since 4.0.0
|
|
11503
11751
|
*/
|
|
11504
11752
|
export const TimeZoneFromString: TimeZoneFromString = TimeZoneString.pipe(
|
|
11505
|
-
decodeTo(TimeZone,
|
|
11753
|
+
decodeTo(TimeZone, SchemaTransformation.timeZoneFromString)
|
|
11506
11754
|
)
|
|
11507
11755
|
|
|
11508
11756
|
/**
|
|
@@ -11549,7 +11797,7 @@ export const DateTimeZoned: DateTimeZoned = declare(
|
|
|
11549
11797
|
toCodecJson: () =>
|
|
11550
11798
|
link<DateTime.Zoned>()(
|
|
11551
11799
|
DateTimeZonedString,
|
|
11552
|
-
|
|
11800
|
+
SchemaTransformation.dateTimeZonedFromString
|
|
11553
11801
|
),
|
|
11554
11802
|
toArbitrary: () => (fc, ctx) =>
|
|
11555
11803
|
fc.tuple(
|
|
@@ -11591,7 +11839,7 @@ export interface DateTimeZonedFromString extends decodeTo<DateTimeZoned, String>
|
|
|
11591
11839
|
* @since 4.0.0
|
|
11592
11840
|
*/
|
|
11593
11841
|
export const DateTimeZonedFromString: DateTimeZonedFromString = DateTimeZonedString.pipe(
|
|
11594
|
-
decodeTo(DateTimeZoned,
|
|
11842
|
+
decodeTo(DateTimeZoned, SchemaTransformation.dateTimeZonedFromString)
|
|
11595
11843
|
)
|
|
11596
11844
|
|
|
11597
11845
|
// -----------------------------------------------------------------------------
|
|
@@ -11610,7 +11858,7 @@ export interface Class<Self, S extends Top & { readonly fields: Struct.Fields },
|
|
|
11610
11858
|
S["Encoded"],
|
|
11611
11859
|
S["DecodingServices"],
|
|
11612
11860
|
S["EncodingServices"],
|
|
11613
|
-
|
|
11861
|
+
SchemaAST.Declaration,
|
|
11614
11862
|
decodeTo<declareConstructor<Self, S["Encoded"], readonly [S], S["Iso"]>, S>,
|
|
11615
11863
|
RequiredKeys<S["~type.make.in"]> extends never ? void | S["~type.make.in"] : S["~type.make.in"],
|
|
11616
11864
|
S["Iso"],
|
|
@@ -11702,32 +11950,32 @@ function makeClass<
|
|
|
11702
11950
|
static readonly identifier = identifier
|
|
11703
11951
|
static readonly fields = struct.fields
|
|
11704
11952
|
|
|
11705
|
-
static get ast():
|
|
11953
|
+
static get ast(): SchemaAST.Declaration {
|
|
11706
11954
|
return getClassSchema(this).ast
|
|
11707
11955
|
}
|
|
11708
11956
|
static pipe() {
|
|
11709
11957
|
return Pipeable.pipeArguments(this, arguments)
|
|
11710
11958
|
}
|
|
11711
|
-
static rebuild(ast:
|
|
11959
|
+
static rebuild(ast: SchemaAST.Declaration) {
|
|
11712
11960
|
return getClassSchema(this).rebuild(ast)
|
|
11713
11961
|
}
|
|
11714
11962
|
static make(input: S["~type.make.in"], options?: MakeOptions): Self {
|
|
11715
11963
|
return new this(input, options)
|
|
11716
11964
|
}
|
|
11717
11965
|
static makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self> {
|
|
11718
|
-
return
|
|
11966
|
+
return SchemaParser.makeOption(getClassSchema(this) as any)(input ?? {}, options) as any
|
|
11719
11967
|
}
|
|
11720
11968
|
static makeEffect(input: S["~type.make.in"], options?: MakeOptions): Effect.Effect<Self, SchemaError> {
|
|
11721
11969
|
return (getClassSchema(this) as any).makeEffect(input ?? {}, options)
|
|
11722
11970
|
}
|
|
11723
11971
|
static annotate(annotations: Annotations.Declaration<Self, readonly [S]>) {
|
|
11724
|
-
return this.rebuild(
|
|
11972
|
+
return this.rebuild(SchemaAST.annotate(this.ast, annotations))
|
|
11725
11973
|
}
|
|
11726
11974
|
static annotateKey(annotations: Annotations.Key<Self>) {
|
|
11727
|
-
return this.rebuild(
|
|
11975
|
+
return this.rebuild(SchemaAST.annotateKey(this.ast, annotations))
|
|
11728
11976
|
}
|
|
11729
|
-
static check(...checks: readonly [
|
|
11730
|
-
return this.rebuild(
|
|
11977
|
+
static check(...checks: readonly [SchemaAST.Check<Self>, ...Array<SchemaAST.Check<Self>>]) {
|
|
11978
|
+
return this.rebuild(SchemaAST.appendChecks(this.ast, checks))
|
|
11731
11979
|
}
|
|
11732
11980
|
static extend<Extended>(
|
|
11733
11981
|
identifier: string
|
|
@@ -11740,7 +11988,7 @@ function makeClass<
|
|
|
11740
11988
|
return makeClass(
|
|
11741
11989
|
this,
|
|
11742
11990
|
identifier,
|
|
11743
|
-
makeStruct(
|
|
11991
|
+
makeStruct(SchemaAST.struct(fields, struct.ast.checks, { identifier }), fields),
|
|
11744
11992
|
annotations,
|
|
11745
11993
|
proto
|
|
11746
11994
|
)
|
|
@@ -11764,9 +12012,9 @@ function makeClass<
|
|
|
11764
12012
|
}
|
|
11765
12013
|
|
|
11766
12014
|
function getClassTransformation(self: new(...args: ReadonlyArray<any>) => any) {
|
|
11767
|
-
return new
|
|
11768
|
-
|
|
11769
|
-
|
|
12015
|
+
return new SchemaTransformation.Transformation<any, any, never, never>(
|
|
12016
|
+
SchemaGetter.transform((input) => new self(input)),
|
|
12017
|
+
SchemaGetter.passthrough()
|
|
11770
12018
|
)
|
|
11771
12019
|
}
|
|
11772
12020
|
|
|
@@ -11786,22 +12034,22 @@ function getClassSchemaFactory<S extends Top>(
|
|
|
11786
12034
|
if (memo === undefined) {
|
|
11787
12035
|
const transformation = getClassTransformation(self)
|
|
11788
12036
|
const to = make<declareConstructor<Self, S["Encoded"], readonly [S]>>(
|
|
11789
|
-
new
|
|
12037
|
+
new SchemaAST.Declaration(
|
|
11790
12038
|
[from.ast],
|
|
11791
12039
|
() => (input, ast) => {
|
|
11792
12040
|
return input instanceof self ||
|
|
11793
12041
|
Predicate.hasProperty(input, getClassTypeId(identifier)) ?
|
|
11794
12042
|
Effect.succeed(input) :
|
|
11795
|
-
Effect.fail(new
|
|
12043
|
+
Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
11796
12044
|
},
|
|
11797
12045
|
{
|
|
11798
12046
|
identifier,
|
|
11799
|
-
[
|
|
11800
|
-
toCodec: ([from]: readonly [Codec<S["Encoded"]>]) => new
|
|
12047
|
+
[SchemaAST.ClassTypeId]: ([from]: readonly [SchemaAST.AST]) => new SchemaAST.Link(from, transformation),
|
|
12048
|
+
toCodec: ([from]: readonly [Codec<S["Encoded"]>]) => new SchemaAST.Link(from.ast, transformation),
|
|
11801
12049
|
toArbitrary: ([from]: readonly [FastCheck.Arbitrary<S["Type"]>]) => () =>
|
|
11802
12050
|
from.map((args) => new self(args)),
|
|
11803
12051
|
toFormatter: ([from]: readonly [Formatter<S["Type"]>]) => (t: Self) => `${self.identifier}(${from(t)})`,
|
|
11804
|
-
"~sentinels":
|
|
12052
|
+
"~sentinels": SchemaAST.collectSentinels(from.ast),
|
|
11805
12053
|
...annotations
|
|
11806
12054
|
}
|
|
11807
12055
|
)
|
|
@@ -11826,9 +12074,8 @@ type MissingSelfGeneric<Usage extends string> =
|
|
|
11826
12074
|
*
|
|
11827
12075
|
* **When to use**
|
|
11828
12076
|
*
|
|
11829
|
-
* Use
|
|
11830
|
-
*
|
|
11831
|
-
* inheritance.
|
|
12077
|
+
* Use when you need a schema-backed data class with validated construction,
|
|
12078
|
+
* schema-derived decoding/encoding, and class-style methods or inheritance.
|
|
11832
12079
|
*
|
|
11833
12080
|
* **Details**
|
|
11834
12081
|
*
|
|
@@ -11887,9 +12134,8 @@ export const Class: {
|
|
|
11887
12134
|
*
|
|
11888
12135
|
* **When to use**
|
|
11889
12136
|
*
|
|
11890
|
-
* Use
|
|
11891
|
-
*
|
|
11892
|
-
* inheritance.
|
|
12137
|
+
* Use when you need a schema-backed data class with validated construction,
|
|
12138
|
+
* schema-derived decoding/encoding, and class-style methods or inheritance.
|
|
11893
12139
|
*
|
|
11894
12140
|
* **Details**
|
|
11895
12141
|
*
|
|
@@ -11948,9 +12194,8 @@ export const Class: {
|
|
|
11948
12194
|
*
|
|
11949
12195
|
* **When to use**
|
|
11950
12196
|
*
|
|
11951
|
-
* Use
|
|
11952
|
-
*
|
|
11953
|
-
* inheritance.
|
|
12197
|
+
* Use when you need a schema-backed data class with validated construction,
|
|
12198
|
+
* schema-derived decoding/encoding, and class-style methods or inheritance.
|
|
11954
12199
|
*
|
|
11955
12200
|
* **Details**
|
|
11956
12201
|
*
|
|
@@ -12012,9 +12257,8 @@ export const Class: {
|
|
|
12012
12257
|
*
|
|
12013
12258
|
* **When to use**
|
|
12014
12259
|
*
|
|
12015
|
-
* Use
|
|
12016
|
-
*
|
|
12017
|
-
* inheritance.
|
|
12260
|
+
* Use when you need a schema-backed data class with validated construction,
|
|
12261
|
+
* schema-derived decoding/encoding, and class-style methods or inheritance.
|
|
12018
12262
|
*
|
|
12019
12263
|
* **Details**
|
|
12020
12264
|
*
|
|
@@ -12595,18 +12839,18 @@ export function overrideToFormatter<S extends Top>(toFormatter: () => Formatter<
|
|
|
12595
12839
|
*/
|
|
12596
12840
|
export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
12597
12841
|
readonly onBefore?:
|
|
12598
|
-
| ((ast:
|
|
12842
|
+
| ((ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => Formatter<any>) => Formatter<any> | undefined)
|
|
12599
12843
|
| undefined
|
|
12600
12844
|
}): Formatter<T> {
|
|
12601
12845
|
return recur(schema.ast)
|
|
12602
12846
|
|
|
12603
|
-
function recur(ast:
|
|
12847
|
+
function recur(ast: SchemaAST.AST): Formatter<T> {
|
|
12604
12848
|
// ---------------------------------------------
|
|
12605
12849
|
// handle annotation
|
|
12606
12850
|
// ---------------------------------------------
|
|
12607
12851
|
const annotation = InternalAnnotations.resolve(ast)?.["toFormatter"]
|
|
12608
12852
|
if (typeof annotation === "function") {
|
|
12609
|
-
return annotation(
|
|
12853
|
+
return annotation(SchemaAST.isDeclaration(ast) ? ast.typeParameters.map(recur) : [])
|
|
12610
12854
|
}
|
|
12611
12855
|
// ---------------------------------------------
|
|
12612
12856
|
// handle onBefore
|
|
@@ -12623,7 +12867,7 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12623
12867
|
return on(ast)
|
|
12624
12868
|
}
|
|
12625
12869
|
|
|
12626
|
-
function on(ast:
|
|
12870
|
+
function on(ast: SchemaAST.AST): Formatter<any> {
|
|
12627
12871
|
switch (ast._tag) {
|
|
12628
12872
|
default:
|
|
12629
12873
|
return format
|
|
@@ -12642,7 +12886,7 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12642
12886
|
// ---------------------------------------------
|
|
12643
12887
|
for (; i < elements.length; i++) {
|
|
12644
12888
|
if (t.length < i + 1) {
|
|
12645
|
-
if (
|
|
12889
|
+
if (SchemaAST.isOptional(ast.elements[i])) {
|
|
12646
12890
|
continue
|
|
12647
12891
|
}
|
|
12648
12892
|
} else {
|
|
@@ -12685,7 +12929,7 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12685
12929
|
const ps = ast.propertySignatures[i]
|
|
12686
12930
|
const name = ps.name
|
|
12687
12931
|
visited.add(name)
|
|
12688
|
-
if (
|
|
12932
|
+
if (SchemaAST.isOptional(ps.type) && !Object.hasOwn(t, name)) {
|
|
12689
12933
|
continue
|
|
12690
12934
|
}
|
|
12691
12935
|
out.push(`${formatPropertyKey(name)}: ${propertySignatures[i](t[name])}`)
|
|
@@ -12694,7 +12938,7 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12694
12938
|
// handle index signatures
|
|
12695
12939
|
// ---------------------------------------------
|
|
12696
12940
|
for (let i = 0; i < indexSignatures.length; i++) {
|
|
12697
|
-
const keys =
|
|
12941
|
+
const keys = SchemaAST.getIndexSignatureKeys(t, ast.indexSignatures[i].parameter)
|
|
12698
12942
|
for (const key of keys) {
|
|
12699
12943
|
if (visited.has(key)) {
|
|
12700
12944
|
continue
|
|
@@ -12708,10 +12952,10 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12708
12952
|
}
|
|
12709
12953
|
}
|
|
12710
12954
|
case "Union": {
|
|
12711
|
-
const getCandidates = (t: any) =>
|
|
12955
|
+
const getCandidates = (t: any) => SchemaAST.getCandidates(t, ast.types)
|
|
12712
12956
|
return (t) => {
|
|
12713
12957
|
const candidates = getCandidates(t)
|
|
12714
|
-
const refinements = candidates.map(
|
|
12958
|
+
const refinements = candidates.map(SchemaParser._is)
|
|
12715
12959
|
for (let i = 0; i < candidates.length; i++) {
|
|
12716
12960
|
const is = refinements[i]
|
|
12717
12961
|
if (is(t)) {
|
|
@@ -12722,7 +12966,7 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12722
12966
|
}
|
|
12723
12967
|
}
|
|
12724
12968
|
case "Suspend": {
|
|
12725
|
-
const get =
|
|
12969
|
+
const get = SchemaAST.memoizeThunk(() => recur(ast.thunk()))
|
|
12726
12970
|
return (t) => get()(t)
|
|
12727
12971
|
}
|
|
12728
12972
|
}
|
|
@@ -12739,8 +12983,8 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12739
12983
|
*
|
|
12740
12984
|
* **When to use**
|
|
12741
12985
|
*
|
|
12742
|
-
* Use when
|
|
12743
|
-
*
|
|
12986
|
+
* Use when you need a custom equivalence instead of the default structural
|
|
12987
|
+
* equivalence derived by {@link toEquivalence}.
|
|
12744
12988
|
*
|
|
12745
12989
|
* @category instances
|
|
12746
12990
|
* @since 4.0.0
|
|
@@ -12903,28 +13147,28 @@ export function toCodecJson<T, E, RD, RE>(schema: Codec<T, E, RD, RE>): Codec<T,
|
|
|
12903
13147
|
return make(toCodecJsonTop(schema.ast))
|
|
12904
13148
|
}
|
|
12905
13149
|
|
|
12906
|
-
const toCodecJsonTop =
|
|
13150
|
+
const toCodecJsonTop = SchemaAST.toCodec((ast) => {
|
|
12907
13151
|
const out = toCodecJsonBase(ast, toCodecJsonTop)
|
|
12908
|
-
return out !== ast &&
|
|
13152
|
+
return out !== ast && SchemaAST.isOptional(ast) ? SchemaAST.optionalKeyLastLink(out) : out
|
|
12909
13153
|
})
|
|
12910
13154
|
|
|
12911
|
-
function toCodecJsonBase(ast:
|
|
13155
|
+
function toCodecJsonBase(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
|
|
12912
13156
|
switch (ast._tag) {
|
|
12913
13157
|
case "Declaration": {
|
|
12914
13158
|
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec
|
|
12915
13159
|
if (Predicate.isFunction(getLink)) {
|
|
12916
|
-
const tps =
|
|
12917
|
-
? ast.typeParameters.map((tp) => InternalSchema.make(
|
|
13160
|
+
const tps = SchemaAST.isDeclaration(ast)
|
|
13161
|
+
? ast.typeParameters.map((tp) => InternalSchema.make(SchemaAST.toEncoded(tp)))
|
|
12918
13162
|
: []
|
|
12919
13163
|
const link = getLink(tps)
|
|
12920
13164
|
const to = recur(link.to)
|
|
12921
|
-
return
|
|
13165
|
+
return SchemaAST.replaceEncoding(ast, to === link.to ? [link] : [new SchemaAST.Link(to, link.transformation)])
|
|
12922
13166
|
}
|
|
12923
|
-
return
|
|
13167
|
+
return SchemaAST.replaceEncoding(ast, [SchemaAST.unknownToNull])
|
|
12924
13168
|
}
|
|
12925
13169
|
case "Unknown":
|
|
12926
13170
|
case "ObjectKeyword":
|
|
12927
|
-
return
|
|
13171
|
+
return SchemaAST.replaceEncoding(ast, [SchemaAST.unknownToJson])
|
|
12928
13172
|
case "Undefined":
|
|
12929
13173
|
case "Void":
|
|
12930
13174
|
case "Literal":
|
|
@@ -12943,7 +13187,7 @@ function toCodecJsonBase(ast: AST.AST, recur: (ast: AST.AST) => AST.AST): AST.AS
|
|
|
12943
13187
|
case "Union": {
|
|
12944
13188
|
const sortedTypes = InternalSchema.jsonReorder(ast.types)
|
|
12945
13189
|
if (sortedTypes !== ast.types) {
|
|
12946
|
-
return new
|
|
13190
|
+
return new SchemaAST.Union(
|
|
12947
13191
|
sortedTypes,
|
|
12948
13192
|
ast.mode,
|
|
12949
13193
|
ast.annotations,
|
|
@@ -12970,22 +13214,22 @@ function toCodecJsonBase(ast: AST.AST, recur: (ast: AST.AST) => AST.AST): AST.AS
|
|
|
12970
13214
|
* @since 4.0.0
|
|
12971
13215
|
*/
|
|
12972
13216
|
export function toCodecIso<S extends Top>(schema: S): Codec<S["Type"], S["Iso"]> {
|
|
12973
|
-
return make(toCodecIsoTop(
|
|
13217
|
+
return make(toCodecIsoTop(SchemaAST.toType(schema.ast)))
|
|
12974
13218
|
}
|
|
12975
13219
|
|
|
12976
|
-
const toCodecIsoTop = memoize((ast:
|
|
13220
|
+
const toCodecIsoTop = memoize((ast: SchemaAST.AST): SchemaAST.AST => {
|
|
12977
13221
|
const out = toCodecIsoBase(ast, toCodecIsoTop)
|
|
12978
|
-
return out !== ast &&
|
|
13222
|
+
return out !== ast && SchemaAST.isOptional(ast) ? SchemaAST.optionalKeyLastLink(out) : out
|
|
12979
13223
|
})
|
|
12980
13224
|
|
|
12981
|
-
function toCodecIsoBase(ast:
|
|
13225
|
+
function toCodecIsoBase(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
|
|
12982
13226
|
switch (ast._tag) {
|
|
12983
13227
|
case "Declaration": {
|
|
12984
13228
|
const getLink = ast.annotations?.toCodecIso ?? ast.annotations?.toCodec
|
|
12985
13229
|
if (Predicate.isFunction(getLink)) {
|
|
12986
13230
|
const link = getLink(ast.typeParameters.map((tp) => InternalSchema.make(tp)))
|
|
12987
13231
|
const to = recur(link.to)
|
|
12988
|
-
return
|
|
13232
|
+
return SchemaAST.replaceEncoding(ast, to === link.to ? [link] : [new SchemaAST.Link(to, link.transformation)])
|
|
12989
13233
|
}
|
|
12990
13234
|
return ast
|
|
12991
13235
|
}
|
|
@@ -13165,7 +13409,7 @@ const xml = {
|
|
|
13165
13409
|
}
|
|
13166
13410
|
}
|
|
13167
13411
|
|
|
13168
|
-
function getStringTreePriority(ast:
|
|
13412
|
+
function getStringTreePriority(ast: SchemaAST.AST): number {
|
|
13169
13413
|
switch (ast._tag) {
|
|
13170
13414
|
case "Null":
|
|
13171
13415
|
case "Boolean":
|
|
@@ -13182,30 +13426,30 @@ function getStringTreePriority(ast: AST.AST): number {
|
|
|
13182
13426
|
const treeReorder = InternalSchema.makeReorder(getStringTreePriority)
|
|
13183
13427
|
|
|
13184
13428
|
function serializerTree(
|
|
13185
|
-
ast:
|
|
13186
|
-
recur: (ast:
|
|
13187
|
-
onMissingAnnotation: (ast:
|
|
13188
|
-
):
|
|
13429
|
+
ast: SchemaAST.AST,
|
|
13430
|
+
recur: (ast: SchemaAST.AST) => SchemaAST.AST,
|
|
13431
|
+
onMissingAnnotation: (ast: SchemaAST.AST) => SchemaAST.AST
|
|
13432
|
+
): SchemaAST.AST {
|
|
13189
13433
|
switch (ast._tag) {
|
|
13190
13434
|
case "Declaration": {
|
|
13191
13435
|
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec
|
|
13192
13436
|
if (Predicate.isFunction(getLink)) {
|
|
13193
|
-
const tps =
|
|
13194
|
-
? ast.typeParameters.map((tp) => make(recur(
|
|
13437
|
+
const tps = SchemaAST.isDeclaration(ast)
|
|
13438
|
+
? ast.typeParameters.map((tp) => make(recur(SchemaAST.toEncoded(tp))))
|
|
13195
13439
|
: []
|
|
13196
13440
|
const link = getLink(tps)
|
|
13197
13441
|
const to = recur(link.to)
|
|
13198
|
-
return
|
|
13442
|
+
return SchemaAST.replaceEncoding(ast, to === link.to ? [link] : [new SchemaAST.Link(to, link.transformation)])
|
|
13199
13443
|
}
|
|
13200
13444
|
return onMissingAnnotation(ast)
|
|
13201
13445
|
}
|
|
13202
13446
|
case "Null":
|
|
13203
|
-
return
|
|
13447
|
+
return SchemaAST.replaceEncoding(ast, [nullToString])
|
|
13204
13448
|
case "Boolean":
|
|
13205
|
-
return
|
|
13449
|
+
return SchemaAST.replaceEncoding(ast, [booleanToString])
|
|
13206
13450
|
case "Unknown":
|
|
13207
13451
|
case "ObjectKeyword":
|
|
13208
|
-
return
|
|
13452
|
+
return SchemaAST.replaceEncoding(ast, [SchemaAST.unknownToStringTree])
|
|
13209
13453
|
case "Enum":
|
|
13210
13454
|
case "Number":
|
|
13211
13455
|
case "Literal":
|
|
@@ -13222,7 +13466,7 @@ function serializerTree(
|
|
|
13222
13466
|
case "Union": {
|
|
13223
13467
|
const sortedTypes = treeReorder(ast.types)
|
|
13224
13468
|
if (sortedTypes !== ast.types) {
|
|
13225
|
-
return new
|
|
13469
|
+
return new SchemaAST.Union(
|
|
13226
13470
|
sortedTypes,
|
|
13227
13471
|
ast.mode,
|
|
13228
13472
|
ast.annotations,
|
|
@@ -13241,75 +13485,75 @@ function serializerTree(
|
|
|
13241
13485
|
return ast
|
|
13242
13486
|
}
|
|
13243
13487
|
|
|
13244
|
-
const nullToString = new
|
|
13245
|
-
new
|
|
13246
|
-
new
|
|
13247
|
-
|
|
13248
|
-
|
|
13488
|
+
const nullToString = new SchemaAST.Link(
|
|
13489
|
+
new SchemaAST.Literal("null"),
|
|
13490
|
+
new SchemaTransformation.Transformation(
|
|
13491
|
+
SchemaGetter.transform(() => null),
|
|
13492
|
+
SchemaGetter.transform(() => "null")
|
|
13249
13493
|
)
|
|
13250
13494
|
)
|
|
13251
13495
|
|
|
13252
|
-
const booleanToString = new
|
|
13253
|
-
new
|
|
13254
|
-
new
|
|
13255
|
-
|
|
13256
|
-
|
|
13496
|
+
const booleanToString = new SchemaAST.Link(
|
|
13497
|
+
new SchemaAST.Union([new SchemaAST.Literal("true"), new SchemaAST.Literal("false")], "anyOf"),
|
|
13498
|
+
new SchemaTransformation.Transformation(
|
|
13499
|
+
SchemaGetter.transform((s) => s === "true"),
|
|
13500
|
+
SchemaGetter.String()
|
|
13257
13501
|
)
|
|
13258
13502
|
)
|
|
13259
13503
|
|
|
13260
|
-
const serializerStringTree =
|
|
13261
|
-
const out = serializerTree(ast, serializerStringTree, (ast) =>
|
|
13262
|
-
if (out !== ast &&
|
|
13263
|
-
return
|
|
13504
|
+
const serializerStringTree = SchemaAST.toCodec((ast) => {
|
|
13505
|
+
const out = serializerTree(ast, serializerStringTree, (ast) => SchemaAST.replaceEncoding(ast, [unknownToUndefined]))
|
|
13506
|
+
if (out !== ast && SchemaAST.isOptional(ast)) {
|
|
13507
|
+
return SchemaAST.optionalKeyLastLink(out)
|
|
13264
13508
|
}
|
|
13265
13509
|
return out
|
|
13266
13510
|
})
|
|
13267
13511
|
|
|
13268
|
-
const unknownToUndefined = new
|
|
13269
|
-
|
|
13270
|
-
new
|
|
13271
|
-
|
|
13272
|
-
|
|
13512
|
+
const unknownToUndefined = new SchemaAST.Link(
|
|
13513
|
+
SchemaAST.undefined,
|
|
13514
|
+
new SchemaTransformation.Transformation(
|
|
13515
|
+
SchemaGetter.passthrough(),
|
|
13516
|
+
SchemaGetter.transform(() => undefined)
|
|
13273
13517
|
)
|
|
13274
13518
|
)
|
|
13275
13519
|
|
|
13276
|
-
const serializerStringTreeKeepDeclarations =
|
|
13520
|
+
const serializerStringTreeKeepDeclarations = SchemaAST.toCodec((ast) => {
|
|
13277
13521
|
const out = serializerTree(ast, serializerStringTreeKeepDeclarations, identity)
|
|
13278
|
-
if (out !== ast &&
|
|
13279
|
-
return
|
|
13522
|
+
if (out !== ast && SchemaAST.isOptional(ast)) {
|
|
13523
|
+
return SchemaAST.optionalKeyLastLink(out)
|
|
13280
13524
|
}
|
|
13281
13525
|
return out
|
|
13282
13526
|
})
|
|
13283
13527
|
|
|
13284
13528
|
const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY"
|
|
13285
13529
|
|
|
13286
|
-
const toCodecEnsureArray =
|
|
13287
|
-
if (
|
|
13530
|
+
const toCodecEnsureArray = SchemaAST.toCodec((ast) => {
|
|
13531
|
+
if (SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY]) {
|
|
13288
13532
|
return ast
|
|
13289
13533
|
}
|
|
13290
13534
|
const out = onSerializerEnsureArray(ast)
|
|
13291
|
-
if (
|
|
13292
|
-
const ensure = new
|
|
13535
|
+
if (SchemaAST.isArrays(out)) {
|
|
13536
|
+
const ensure = new SchemaAST.Union(
|
|
13293
13537
|
[
|
|
13294
13538
|
out,
|
|
13295
|
-
|
|
13296
|
-
|
|
13539
|
+
SchemaAST.decodeTo(
|
|
13540
|
+
SchemaAST.string,
|
|
13297
13541
|
out,
|
|
13298
|
-
new
|
|
13299
|
-
|
|
13300
|
-
|
|
13542
|
+
new SchemaTransformation.Transformation(
|
|
13543
|
+
SchemaGetter.split(),
|
|
13544
|
+
SchemaGetter.passthrough()
|
|
13301
13545
|
)
|
|
13302
13546
|
)
|
|
13303
13547
|
],
|
|
13304
13548
|
"anyOf",
|
|
13305
13549
|
{ [SERIALIZER_ENSURE_ARRAY]: true }
|
|
13306
13550
|
)
|
|
13307
|
-
return
|
|
13551
|
+
return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure
|
|
13308
13552
|
}
|
|
13309
13553
|
return out
|
|
13310
13554
|
})
|
|
13311
13555
|
|
|
13312
|
-
function onSerializerEnsureArray(ast:
|
|
13556
|
+
function onSerializerEnsureArray(ast: SchemaAST.AST): SchemaAST.AST {
|
|
13313
13557
|
switch (ast._tag) {
|
|
13314
13558
|
default:
|
|
13315
13559
|
return ast
|
|
@@ -13335,7 +13579,7 @@ function onSerializerEnsureArray(ast: AST.AST): AST.AST {
|
|
|
13335
13579
|
*/
|
|
13336
13580
|
export function toIso<S extends Top>(schema: S): Optic_.Iso<S["Type"], S["Iso"]> {
|
|
13337
13581
|
const serializer = toCodecIso(schema)
|
|
13338
|
-
return Optic_.makeIso(
|
|
13582
|
+
return Optic_.makeIso(SchemaParser.encodeSync(serializer), SchemaParser.decodeSync(serializer))
|
|
13339
13583
|
}
|
|
13340
13584
|
|
|
13341
13585
|
/**
|
|
@@ -13406,14 +13650,14 @@ export interface overrideToCodecIso<S extends Top, Iso> extends
|
|
|
13406
13650
|
export function overrideToCodecIso<S extends Top, Iso>(
|
|
13407
13651
|
to: Codec<Iso>,
|
|
13408
13652
|
transformation: {
|
|
13409
|
-
readonly decode:
|
|
13410
|
-
readonly encode:
|
|
13653
|
+
readonly decode: SchemaGetter.Getter<S["Type"], Iso>
|
|
13654
|
+
readonly encode: SchemaGetter.Getter<Iso, S["Type"]>
|
|
13411
13655
|
}
|
|
13412
13656
|
) {
|
|
13413
13657
|
return (schema: S): overrideToCodecIso<S, Iso> => {
|
|
13414
13658
|
return make(
|
|
13415
|
-
|
|
13416
|
-
toCodecIso: () => new
|
|
13659
|
+
SchemaAST.annotate(schema.ast, {
|
|
13660
|
+
toCodecIso: () => new SchemaAST.Link(to.ast, SchemaTransformation.make(transformation))
|
|
13417
13661
|
}),
|
|
13418
13662
|
{ schema }
|
|
13419
13663
|
)
|
|
@@ -13434,8 +13678,8 @@ export function overrideToCodecIso<S extends Top, Iso>(
|
|
|
13434
13678
|
*/
|
|
13435
13679
|
export function toDifferJsonPatch<T, E>(schema: Codec<T, E>): Differ<T, JsonPatch.JsonPatch> {
|
|
13436
13680
|
const serializer = toCodecJson(schema)
|
|
13437
|
-
const get =
|
|
13438
|
-
const set =
|
|
13681
|
+
const get = SchemaParser.encodeSync(serializer)
|
|
13682
|
+
const set = SchemaParser.decodeSync(serializer)
|
|
13439
13683
|
return {
|
|
13440
13684
|
empty: [],
|
|
13441
13685
|
diff: (oldValue, newValue) => JsonPatch.get(get(oldValue), get(newValue)),
|
|
@@ -13535,7 +13779,14 @@ export interface JsonObject {
|
|
|
13535
13779
|
* @category schemas
|
|
13536
13780
|
* @since 4.0.0
|
|
13537
13781
|
*/
|
|
13538
|
-
export const Json: Codec<Json> = make(
|
|
13782
|
+
export const Json: Codec<Json> = make(SchemaAST.Json)
|
|
13783
|
+
|
|
13784
|
+
const JsonError = Struct({
|
|
13785
|
+
message: String,
|
|
13786
|
+
name: optionalKey(String),
|
|
13787
|
+
stack: optionalKey(String),
|
|
13788
|
+
cause: optionalKey(Json)
|
|
13789
|
+
})
|
|
13539
13790
|
|
|
13540
13791
|
/**
|
|
13541
13792
|
* Recursive TypeScript type for mutable JSON values: `null`, `number`,
|
|
@@ -13571,7 +13822,7 @@ export interface MutableJsonObject {
|
|
|
13571
13822
|
* @category schemas
|
|
13572
13823
|
* @since 4.0.0
|
|
13573
13824
|
*/
|
|
13574
|
-
export const MutableJson: Codec<MutableJson> = make(
|
|
13825
|
+
export const MutableJson: Codec<MutableJson> = make(SchemaAST.MutableJson)
|
|
13575
13826
|
|
|
13576
13827
|
// -----------------------------------------------------------------------------
|
|
13577
13828
|
// Annotations
|
|
@@ -13761,7 +14012,7 @@ export declare namespace Annotations {
|
|
|
13761
14012
|
* filter/refinement instead.
|
|
13762
14013
|
*/
|
|
13763
14014
|
readonly identifier?: string | undefined
|
|
13764
|
-
readonly parseOptions?:
|
|
14015
|
+
readonly parseOptions?: SchemaAST.ParseOptions | undefined
|
|
13765
14016
|
/**
|
|
13766
14017
|
* Optional metadata used to identify or extend the filter with custom data.
|
|
13767
14018
|
*/
|
|
@@ -13817,19 +14068,20 @@ export declare namespace Annotations {
|
|
|
13817
14068
|
extends Bottom<T, TypeParameters>
|
|
13818
14069
|
{
|
|
13819
14070
|
readonly toCodec?:
|
|
13820
|
-
| ((typeParameters: TypeParameters.Encoded<TypeParameters>) =>
|
|
14071
|
+
| ((typeParameters: TypeParameters.Encoded<TypeParameters>) => SchemaAST.Link)
|
|
13821
14072
|
| undefined
|
|
13822
14073
|
readonly toCodecJson?:
|
|
13823
|
-
| ((typeParameters: TypeParameters.Encoded<TypeParameters>) =>
|
|
14074
|
+
| ((typeParameters: TypeParameters.Encoded<TypeParameters>) => SchemaAST.Link)
|
|
13824
14075
|
| undefined
|
|
13825
14076
|
readonly toCodecIso?:
|
|
13826
|
-
| ((typeParameters: TypeParameters.Type<TypeParameters>) =>
|
|
14077
|
+
| ((typeParameters: TypeParameters.Type<TypeParameters>) => SchemaAST.Link)
|
|
13827
14078
|
| undefined
|
|
13828
14079
|
readonly toArbitrary?: ToArbitrary.Declaration<T, TypeParameters> | undefined
|
|
13829
14080
|
readonly toEquivalence?: ToEquivalence.Declaration<T, TypeParameters> | undefined
|
|
13830
14081
|
readonly toFormatter?: ToFormatter.Declaration<T, TypeParameters> | undefined
|
|
13831
14082
|
readonly typeConstructor?: {
|
|
13832
14083
|
readonly _tag: string
|
|
14084
|
+
readonly [key: string]: unknown
|
|
13833
14085
|
} | undefined
|
|
13834
14086
|
readonly generation?: {
|
|
13835
14087
|
readonly runtime: string
|
|
@@ -13838,11 +14090,11 @@ export declare namespace Annotations {
|
|
|
13838
14090
|
readonly importDeclaration?: string | undefined
|
|
13839
14091
|
} | undefined
|
|
13840
14092
|
/**
|
|
13841
|
-
* Used to collect sentinels from a Declaration
|
|
14093
|
+
* Used to collect sentinels from a Declaration SchemaAST.
|
|
13842
14094
|
*
|
|
13843
14095
|
* @internal
|
|
13844
14096
|
*/
|
|
13845
|
-
readonly "~sentinels"?: ReadonlyArray<
|
|
14097
|
+
readonly "~sentinels"?: ReadonlyArray<SchemaAST.Sentinel> | undefined
|
|
13846
14098
|
}
|
|
13847
14099
|
|
|
13848
14100
|
/**
|
|
@@ -14118,6 +14370,10 @@ export declare namespace Annotations {
|
|
|
14118
14370
|
readonly regExp: globalThis.RegExp
|
|
14119
14371
|
readonly version: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | undefined
|
|
14120
14372
|
}
|
|
14373
|
+
readonly isGUID: {
|
|
14374
|
+
readonly _tag: "isGUID"
|
|
14375
|
+
readonly regExp: globalThis.RegExp
|
|
14376
|
+
}
|
|
14121
14377
|
readonly isULID: {
|
|
14122
14378
|
readonly _tag: "isULID"
|
|
14123
14379
|
readonly regExp: globalThis.RegExp
|
|
@@ -14262,7 +14518,7 @@ export declare namespace Annotations {
|
|
|
14262
14518
|
}
|
|
14263
14519
|
readonly isPropertyNames: {
|
|
14264
14520
|
readonly _tag: "isPropertyNames"
|
|
14265
|
-
readonly propertyNames:
|
|
14521
|
+
readonly propertyNames: SchemaAST.AST
|
|
14266
14522
|
}
|
|
14267
14523
|
// Arrays Meta
|
|
14268
14524
|
readonly isUnique: {
|