effect 4.0.0-beta.74 → 4.0.0-beta.75
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 +443 -371
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +518 -427
- 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 +80 -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 +30 -21
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +26 -22
- 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 +183 -159
- 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 +14 -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 +19 -17
- 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/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/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 +12 -12
- 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/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/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/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/reactivity/Atom.d.ts +3 -3
- package/dist/unstable/reactivity/Atom.js +3 -3
- 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/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/workflow/DurableDeferred.js +7 -7
- 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 +94 -72
- 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 +843 -649
- package/src/SchemaAST.ts +148 -117
- package/src/SchemaGetter.ts +142 -121
- package/src/SchemaIssue.ts +39 -41
- package/src/SchemaParser.ts +173 -229
- package/src/SchemaRepresentation.ts +38 -28
- package/src/SchemaTransformation.ts +233 -207
- 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 +23 -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 +19 -17
- 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/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/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 +14 -12
- 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/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/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/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/reactivity/Atom.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/sql/SqlSchema.ts +4 -4
- package/src/unstable/workers/Transferable.ts +6 -6
- package/src/unstable/workflow/DurableDeferred.ts +7 -7
- package/src/unstable/workflow/DurableQueue.ts +1 -2
- package/src/unstable/workflow/Workflow.ts +159 -114
- 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
|
@@ -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"]`.
|
|
5038
|
+
*
|
|
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.
|
|
4833
5043
|
*
|
|
4834
|
-
*
|
|
4835
|
-
* - Resulting schema has `Type = To["Type"]` and `Encoded = From["Encoded"]`
|
|
4836
|
-
* - When `transformation` is omitted, uses `Transformation.passthrough()` (schema composition)
|
|
4837
|
-
* - Combines decoding/encoding services from both `from` and `to` schemas
|
|
4838
|
-
* - Transformation `decode` maps `From["Type"]` → `To["Encoded"]` (used during encoding)
|
|
4839
|
-
* - Transformation `encode` maps `To["Encoded"]` → `From["Type"]` (used during decoding)
|
|
5044
|
+
* **Gotchas**
|
|
4840
5045
|
*
|
|
4841
|
-
*
|
|
4842
|
-
*
|
|
4843
|
-
*
|
|
4844
|
-
* - **Transformation direction**: `decode` goes `From["Type"]` → `To["Encoded"]`, `encode` goes `To["Encoded"]` → `From["Type"]`
|
|
4845
|
-
* - **Passthrough assumption**: Without transformation, schemas must satisfy `To["Encoded"] === From["Type"]` or use passthrough helpers
|
|
4846
|
-
* - **Service dependencies**: Resulting schema requires services from both schemas; use `Schema.provideService` if needed
|
|
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,7 +6232,7 @@ 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
6238
|
* Returns a RegExp for validating an RFC 4122 UUID.
|
|
@@ -6874,7 +7089,7 @@ export function isInt(annotations?: Annotations.Filter) {
|
|
|
6874
7089
|
* @since 4.0.0
|
|
6875
7090
|
*/
|
|
6876
7091
|
export function isInt32(annotations?: Annotations.Filter) {
|
|
6877
|
-
return new
|
|
7092
|
+
return new SchemaAST.FilterGroup(
|
|
6878
7093
|
[
|
|
6879
7094
|
isInt(annotations),
|
|
6880
7095
|
isBetween({ minimum: -2147483648, maximum: 2147483647 })
|
|
@@ -6906,7 +7121,7 @@ export function isInt32(annotations?: Annotations.Filter) {
|
|
|
6906
7121
|
* @since 4.0.0
|
|
6907
7122
|
*/
|
|
6908
7123
|
export function isUint32(annotations?: Annotations.Filter) {
|
|
6909
|
-
return new
|
|
7124
|
+
return new SchemaAST.FilterGroup(
|
|
6910
7125
|
[
|
|
6911
7126
|
isInt(),
|
|
6912
7127
|
isBetween({ minimum: 0, maximum: 4294967295 })
|
|
@@ -7377,7 +7592,7 @@ export function isMinLength(minLength: number, annotations?: Annotations.Filter)
|
|
|
7377
7592
|
_tag: "isMinLength",
|
|
7378
7593
|
minLength
|
|
7379
7594
|
},
|
|
7380
|
-
[
|
|
7595
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7381
7596
|
toArbitraryConstraint: {
|
|
7382
7597
|
string: {
|
|
7383
7598
|
minLength
|
|
@@ -7444,7 +7659,7 @@ export function isMaxLength(maxLength: number, annotations?: Annotations.Filter)
|
|
|
7444
7659
|
_tag: "isMaxLength",
|
|
7445
7660
|
maxLength
|
|
7446
7661
|
},
|
|
7447
|
-
[
|
|
7662
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7448
7663
|
toArbitraryConstraint: {
|
|
7449
7664
|
string: {
|
|
7450
7665
|
maxLength
|
|
@@ -7492,7 +7707,7 @@ export function isLengthBetween(minimum: number, maximum: number, annotations?:
|
|
|
7492
7707
|
minimum,
|
|
7493
7708
|
maximum
|
|
7494
7709
|
},
|
|
7495
|
-
[
|
|
7710
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7496
7711
|
toArbitraryConstraint: {
|
|
7497
7712
|
string: {
|
|
7498
7713
|
minLength: minimum,
|
|
@@ -7538,7 +7753,7 @@ export function isMinSize(minSize: number, annotations?: Annotations.Filter) {
|
|
|
7538
7753
|
_tag: "isMinSize",
|
|
7539
7754
|
minSize
|
|
7540
7755
|
},
|
|
7541
|
-
[
|
|
7756
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7542
7757
|
toArbitraryConstraint: {
|
|
7543
7758
|
array: {
|
|
7544
7759
|
minLength: minSize
|
|
@@ -7579,7 +7794,7 @@ export function isMaxSize(maxSize: number, annotations?: Annotations.Filter) {
|
|
|
7579
7794
|
_tag: "isMaxSize",
|
|
7580
7795
|
maxSize
|
|
7581
7796
|
},
|
|
7582
|
-
[
|
|
7797
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7583
7798
|
toArbitraryConstraint: {
|
|
7584
7799
|
array: {
|
|
7585
7800
|
maxLength: maxSize
|
|
@@ -7624,7 +7839,7 @@ export function isSizeBetween(minimum: number, maximum: number, annotations?: An
|
|
|
7624
7839
|
minimum,
|
|
7625
7840
|
maximum
|
|
7626
7841
|
},
|
|
7627
|
-
[
|
|
7842
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7628
7843
|
toArbitraryConstraint: {
|
|
7629
7844
|
array: {
|
|
7630
7845
|
minLength: minimum,
|
|
@@ -7667,7 +7882,7 @@ export function isMinProperties(minProperties: number, annotations?: Annotations
|
|
|
7667
7882
|
_tag: "isMinProperties",
|
|
7668
7883
|
minProperties
|
|
7669
7884
|
},
|
|
7670
|
-
[
|
|
7885
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7671
7886
|
toArbitraryConstraint: {
|
|
7672
7887
|
array: {
|
|
7673
7888
|
minLength: minProperties
|
|
@@ -7708,7 +7923,7 @@ export function isMaxProperties(maxProperties: number, annotations?: Annotations
|
|
|
7708
7923
|
_tag: "isMaxProperties",
|
|
7709
7924
|
maxProperties
|
|
7710
7925
|
},
|
|
7711
|
-
[
|
|
7926
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7712
7927
|
toArbitraryConstraint: {
|
|
7713
7928
|
array: {
|
|
7714
7929
|
maxLength: maxProperties
|
|
@@ -7753,7 +7968,7 @@ export function isPropertiesLengthBetween(minimum: number, maximum: number, anno
|
|
|
7753
7968
|
minimum,
|
|
7754
7969
|
maximum
|
|
7755
7970
|
},
|
|
7756
|
-
[
|
|
7971
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7757
7972
|
toArbitraryConstraint: {
|
|
7758
7973
|
array: {
|
|
7759
7974
|
minLength: minimum,
|
|
@@ -7783,20 +7998,20 @@ export function isPropertiesLengthBetween(minimum: number, maximum: number, anno
|
|
|
7783
7998
|
*/
|
|
7784
7999
|
export function isPropertyNames(keySchema: Top, annotations?: Annotations.Filter) {
|
|
7785
8000
|
const propertyNames = toEncoded(keySchema)
|
|
7786
|
-
const parser =
|
|
8001
|
+
const parser = SchemaParser._issue(propertyNames.ast)
|
|
7787
8002
|
return makeFilter<object>(
|
|
7788
8003
|
(input, ast, options) => {
|
|
7789
8004
|
const keys = Reflect.ownKeys(input)
|
|
7790
|
-
const issues: Array<
|
|
8005
|
+
const issues: Array<SchemaIssue.Issue> = []
|
|
7791
8006
|
for (const key of keys) {
|
|
7792
8007
|
const issue = parser(key, options)
|
|
7793
8008
|
if (issue !== undefined) {
|
|
7794
|
-
issues.push(new
|
|
8009
|
+
issues.push(new SchemaIssue.Pointer([key], issue))
|
|
7795
8010
|
if (options.errors === "first") break
|
|
7796
8011
|
}
|
|
7797
8012
|
}
|
|
7798
8013
|
if (Arr.isArrayNonEmpty(issues)) {
|
|
7799
|
-
return new
|
|
8014
|
+
return new SchemaIssue.Composite(ast, Option_.some(input), issues)
|
|
7800
8015
|
}
|
|
7801
8016
|
return true
|
|
7802
8017
|
},
|
|
@@ -7806,7 +8021,7 @@ export function isPropertyNames(keySchema: Top, annotations?: Annotations.Filter
|
|
|
7806
8021
|
_tag: "isPropertyNames",
|
|
7807
8022
|
propertyNames: propertyNames.ast
|
|
7808
8023
|
},
|
|
7809
|
-
[
|
|
8024
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
7810
8025
|
...annotations
|
|
7811
8026
|
}
|
|
7812
8027
|
)
|
|
@@ -7952,14 +8167,15 @@ export function Option<A extends Top>(value: A): Option<A> {
|
|
|
7952
8167
|
return Effect.succeedNone
|
|
7953
8168
|
}
|
|
7954
8169
|
return Effect.mapBothEager(
|
|
7955
|
-
|
|
8170
|
+
SchemaParser.decodeUnknownEffect(value)(input.value, options),
|
|
7956
8171
|
{
|
|
7957
8172
|
onSuccess: Option_.some,
|
|
7958
|
-
onFailure: (issue) =>
|
|
8173
|
+
onFailure: (issue) =>
|
|
8174
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["value"], issue)])
|
|
7959
8175
|
}
|
|
7960
8176
|
)
|
|
7961
8177
|
}
|
|
7962
|
-
return Effect.fail(new
|
|
8178
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
7963
8179
|
},
|
|
7964
8180
|
{
|
|
7965
8181
|
typeConstructor: {
|
|
@@ -7977,7 +8193,7 @@ export function Option<A extends Top>(value: A): Option<A> {
|
|
|
7977
8193
|
Struct({ _tag: Literal("Some"), value }),
|
|
7978
8194
|
Struct({ _tag: Literal("None") })
|
|
7979
8195
|
]),
|
|
7980
|
-
|
|
8196
|
+
SchemaTransformation.transform({
|
|
7981
8197
|
decode: (e) => e._tag === "None" ? Option_.none() : Option_.some(e.value),
|
|
7982
8198
|
encode: (o) => (Option_.isSome(o) ? { _tag: "Some", value: o.value } as const : { _tag: "None" } as const)
|
|
7983
8199
|
})
|
|
@@ -8015,13 +8231,8 @@ export interface OptionFromNullOr<S extends Top> extends decodeTo<Option<toType<
|
|
|
8015
8231
|
*
|
|
8016
8232
|
* **Details**
|
|
8017
8233
|
*
|
|
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
|
|
8234
|
+
* Decoding maps `null` to `None` and all other values to `Some`. Encoding maps
|
|
8235
|
+
* `None` to `null` and maps `Some` to its value.
|
|
8025
8236
|
*
|
|
8026
8237
|
* @category Option
|
|
8027
8238
|
* @since 3.10.0
|
|
@@ -8029,7 +8240,7 @@ export interface OptionFromNullOr<S extends Top> extends decodeTo<Option<toType<
|
|
|
8029
8240
|
export function OptionFromNullOr<S extends Top>(schema: S): OptionFromNullOr<S> {
|
|
8030
8241
|
return NullOr(schema).pipe(decodeTo(
|
|
8031
8242
|
Option(toType(schema)),
|
|
8032
|
-
|
|
8243
|
+
SchemaTransformation.optionFromNullOr()
|
|
8033
8244
|
))
|
|
8034
8245
|
}
|
|
8035
8246
|
|
|
@@ -8044,17 +8255,13 @@ export interface OptionFromUndefinedOr<S extends Top> extends decodeTo<Option<to
|
|
|
8044
8255
|
}
|
|
8045
8256
|
|
|
8046
8257
|
/**
|
|
8047
|
-
* Decodes
|
|
8258
|
+
* Decodes a required value that may be `undefined` to a required `Option<T>`
|
|
8259
|
+
* value.
|
|
8048
8260
|
*
|
|
8049
8261
|
* **Details**
|
|
8050
8262
|
*
|
|
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
|
|
8263
|
+
* Decoding maps `undefined` to `None` and all other values to `Some`. Encoding
|
|
8264
|
+
* maps `None` to `undefined` and maps `Some` to its value.
|
|
8058
8265
|
*
|
|
8059
8266
|
* @category Option
|
|
8060
8267
|
* @since 3.10.0
|
|
@@ -8062,7 +8269,7 @@ export interface OptionFromUndefinedOr<S extends Top> extends decodeTo<Option<to
|
|
|
8062
8269
|
export function OptionFromUndefinedOr<S extends Top>(schema: S): OptionFromUndefinedOr<S> {
|
|
8063
8270
|
return UndefinedOr(schema).pipe(decodeTo(
|
|
8064
8271
|
Option(toType(schema)),
|
|
8065
|
-
|
|
8272
|
+
SchemaTransformation.optionFromUndefinedOr()
|
|
8066
8273
|
))
|
|
8067
8274
|
}
|
|
8068
8275
|
|
|
@@ -8081,13 +8288,10 @@ export interface OptionFromNullishOr<S extends Top> extends decodeTo<Option<toTy
|
|
|
8081
8288
|
*
|
|
8082
8289
|
* **Details**
|
|
8083
8290
|
*
|
|
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
|
|
8291
|
+
* Decoding maps `null` and `undefined` to `None` and all other values to
|
|
8292
|
+
* `Some`. Encoding maps `None` to `null` or `undefined` depending on
|
|
8293
|
+
* `options.onNoneEncoding`, which defaults to `undefined`, and maps `Some` to
|
|
8294
|
+
* its value.
|
|
8091
8295
|
*
|
|
8092
8296
|
* @category Option
|
|
8093
8297
|
* @since 3.10.0
|
|
@@ -8100,7 +8304,7 @@ export function OptionFromNullishOr<S extends Top>(
|
|
|
8100
8304
|
): OptionFromNullishOr<S> {
|
|
8101
8305
|
return NullishOr(schema).pipe(decodeTo(
|
|
8102
8306
|
Option(toType(schema)),
|
|
8103
|
-
|
|
8307
|
+
SchemaTransformation.optionFromNullishOr(options)
|
|
8104
8308
|
))
|
|
8105
8309
|
}
|
|
8106
8310
|
|
|
@@ -8119,13 +8323,8 @@ export interface OptionFromOptionalKey<S extends Top> extends decodeTo<Option<to
|
|
|
8119
8323
|
*
|
|
8120
8324
|
* **Details**
|
|
8121
8325
|
*
|
|
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
|
|
8326
|
+
* Decoding maps a missing key to `None` and a present value to `Some`.
|
|
8327
|
+
* Encoding maps `None` to a missing key and maps `Some` to its value.
|
|
8129
8328
|
*
|
|
8130
8329
|
* @category Option
|
|
8131
8330
|
* @since 4.0.0
|
|
@@ -8133,7 +8332,7 @@ export interface OptionFromOptionalKey<S extends Top> extends decodeTo<Option<to
|
|
|
8133
8332
|
export function OptionFromOptionalKey<S extends Top>(schema: S): OptionFromOptionalKey<S> {
|
|
8134
8333
|
return optionalKey(schema).pipe(decodeTo(
|
|
8135
8334
|
Option(toType(schema)),
|
|
8136
|
-
|
|
8335
|
+
SchemaTransformation.optionFromOptionalKey()
|
|
8137
8336
|
))
|
|
8138
8337
|
}
|
|
8139
8338
|
|
|
@@ -8148,19 +8347,14 @@ export interface OptionFromOptional<S extends Top> extends decodeTo<Option<toTyp
|
|
|
8148
8347
|
}
|
|
8149
8348
|
|
|
8150
8349
|
/**
|
|
8151
|
-
* Decodes an optional or `undefined` value `A` to
|
|
8350
|
+
* Decodes an optional or `undefined` value `A` to a required `Option<A>`
|
|
8152
8351
|
* value.
|
|
8153
8352
|
*
|
|
8154
8353
|
* **Details**
|
|
8155
8354
|
*
|
|
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
|
|
8355
|
+
* Decoding maps a missing key or a present `undefined` value to `None`, and
|
|
8356
|
+
* maps all other values to `Some`. Encoding maps `None` to a missing key and
|
|
8357
|
+
* maps `Some` to its value.
|
|
8164
8358
|
*
|
|
8165
8359
|
* @category Option
|
|
8166
8360
|
* @since 4.0.0
|
|
@@ -8168,7 +8362,7 @@ export interface OptionFromOptional<S extends Top> extends decodeTo<Option<toTyp
|
|
|
8168
8362
|
export function OptionFromOptional<S extends Top>(schema: S): OptionFromOptional<S> {
|
|
8169
8363
|
return optional(schema).pipe(decodeTo(
|
|
8170
8364
|
Option(toType(schema)),
|
|
8171
|
-
|
|
8365
|
+
SchemaTransformation.optionFromOptional<any>()
|
|
8172
8366
|
))
|
|
8173
8367
|
}
|
|
8174
8368
|
|
|
@@ -8188,17 +8382,10 @@ export interface OptionFromOptionalNullOr<S extends Top> extends decodeTo<Option
|
|
|
8188
8382
|
*
|
|
8189
8383
|
* **Details**
|
|
8190
8384
|
*
|
|
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
|
|
8385
|
+
* Decoding maps a missing key, `undefined`, or `null` to `None`, and maps all
|
|
8386
|
+
* other values to `Some`. Encoding maps `Some` to its value. `None` is encoded
|
|
8387
|
+
* according to `options.onNoneEncoding`: `"omit"` encodes a missing key,
|
|
8388
|
+
* `null` encodes `null`, and `undefined` encodes `undefined`.
|
|
8202
8389
|
*
|
|
8203
8390
|
* @category Option
|
|
8204
8391
|
* @since 4.0.0
|
|
@@ -8215,7 +8402,7 @@ export function OptionFromOptionalNullOr<S extends Top>(
|
|
|
8215
8402
|
: undefined as S["Type"] | null | undefined
|
|
8216
8403
|
return optional(NullOr(schema)).pipe(decodeTo(
|
|
8217
8404
|
Option(toType(schema)),
|
|
8218
|
-
|
|
8405
|
+
SchemaTransformation.transformOptional<Option_.Option<S["Type"]>, S["Type"] | null | undefined>({
|
|
8219
8406
|
decode: (oe) => oe.pipe(Option_.filter(Predicate.isNotNullish), Option_.some),
|
|
8220
8407
|
encode: onNoneEncoding === "omit"
|
|
8221
8408
|
? Option_.flatten
|
|
@@ -8276,18 +8463,20 @@ export function Result<A extends Top, E extends Top>(
|
|
|
8276
8463
|
[success, failure],
|
|
8277
8464
|
([success, failure]) => (input, ast, options) => {
|
|
8278
8465
|
if (!Result_.isResult(input)) {
|
|
8279
|
-
return Effect.fail(new
|
|
8466
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
8280
8467
|
}
|
|
8281
8468
|
switch (input._tag) {
|
|
8282
8469
|
case "Success":
|
|
8283
|
-
return Effect.mapBothEager(
|
|
8470
|
+
return Effect.mapBothEager(SchemaParser.decodeEffect(success)(input.success, options), {
|
|
8284
8471
|
onSuccess: Result_.succeed,
|
|
8285
|
-
onFailure: (issue) =>
|
|
8472
|
+
onFailure: (issue) =>
|
|
8473
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["success"], issue)])
|
|
8286
8474
|
})
|
|
8287
8475
|
case "Failure":
|
|
8288
|
-
return Effect.mapBothEager(
|
|
8476
|
+
return Effect.mapBothEager(SchemaParser.decodeEffect(failure)(input.failure, options), {
|
|
8289
8477
|
onSuccess: Result_.fail,
|
|
8290
|
-
onFailure: (issue) =>
|
|
8478
|
+
onFailure: (issue) =>
|
|
8479
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["failure"], issue)])
|
|
8291
8480
|
})
|
|
8292
8481
|
}
|
|
8293
8482
|
},
|
|
@@ -8307,7 +8496,7 @@ export function Result<A extends Top, E extends Top>(
|
|
|
8307
8496
|
Struct({ _tag: Literal("Success"), success }),
|
|
8308
8497
|
Struct({ _tag: Literal("Failure"), failure })
|
|
8309
8498
|
]),
|
|
8310
|
-
|
|
8499
|
+
SchemaTransformation.transform({
|
|
8311
8500
|
decode: (e): Result_.Result<A["Encoded"], E["Encoded"]> =>
|
|
8312
8501
|
e._tag === "Success" ? Result_.succeed(e.success) : Result_.fail(e.failure),
|
|
8313
8502
|
encode: (r) =>
|
|
@@ -8379,43 +8568,44 @@ export function Redacted<S extends Top>(value: S, options?: {
|
|
|
8379
8568
|
readonly disallowJsonEncode?: boolean | undefined
|
|
8380
8569
|
}): Redacted<S> {
|
|
8381
8570
|
const decodeLabel = typeof options?.label === "string"
|
|
8382
|
-
?
|
|
8571
|
+
? SchemaParser.decodeUnknownEffect(Literal(options.label))
|
|
8383
8572
|
: undefined
|
|
8384
8573
|
const schema = declareConstructor<Redacted_.Redacted<S["Type"]>, Redacted_.Redacted<S["Encoded"]>>()(
|
|
8385
8574
|
[value],
|
|
8386
8575
|
([value]) => (input, ast, poptions) => {
|
|
8387
8576
|
if (Redacted_.isRedacted(input)) {
|
|
8388
|
-
const label: Effect.Effect<void,
|
|
8577
|
+
const label: Effect.Effect<void, SchemaIssue.Issue, never> = decodeLabel !== undefined
|
|
8389
8578
|
? Effect.mapErrorEager(
|
|
8390
8579
|
decodeLabel(input.label, poptions),
|
|
8391
|
-
(issue) => new
|
|
8580
|
+
(issue) => new SchemaIssue.Pointer(["label"], issue)
|
|
8392
8581
|
)
|
|
8393
8582
|
: Effect.void
|
|
8394
8583
|
return Effect.flatMapEager(
|
|
8395
8584
|
label,
|
|
8396
8585
|
() =>
|
|
8397
8586
|
Effect.mapBothEager(
|
|
8398
|
-
|
|
8587
|
+
SchemaParser.decodeUnknownEffect(value)(Redacted_.value(input), poptions),
|
|
8399
8588
|
{
|
|
8400
8589
|
onSuccess: () => input,
|
|
8401
8590
|
onFailure: (/** ignore the actual issue because of security reasons */) => {
|
|
8402
8591
|
const oinput = Option_.some(input)
|
|
8403
|
-
return new
|
|
8404
|
-
new
|
|
8592
|
+
return new SchemaIssue.Composite(ast, oinput, [
|
|
8593
|
+
new SchemaIssue.Pointer(["value"], new SchemaIssue.InvalidValue(oinput))
|
|
8405
8594
|
])
|
|
8406
8595
|
}
|
|
8407
8596
|
}
|
|
8408
8597
|
)
|
|
8409
8598
|
)
|
|
8410
8599
|
}
|
|
8411
|
-
return Effect.fail(new
|
|
8600
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
8412
8601
|
},
|
|
8413
8602
|
{
|
|
8414
8603
|
typeConstructor: {
|
|
8415
|
-
_tag: "effect/Redacted"
|
|
8604
|
+
_tag: "effect/Redacted",
|
|
8605
|
+
options
|
|
8416
8606
|
},
|
|
8417
8607
|
generation: {
|
|
8418
|
-
runtime: `Schema.Redacted(?)`,
|
|
8608
|
+
runtime: options !== undefined ? `Schema.Redacted(?, ${format(options)})` : `Schema.Redacted(?)`,
|
|
8419
8609
|
Type: `Redacted.Redacted<?>`,
|
|
8420
8610
|
importDeclaration: `import * as Redacted from "effect/Redacted"`
|
|
8421
8611
|
},
|
|
@@ -8424,13 +8614,13 @@ export function Redacted<S extends Top>(value: S, options?: {
|
|
|
8424
8614
|
link<Redacted_.Redacted<S["Encoded"]>>()(
|
|
8425
8615
|
redact(value),
|
|
8426
8616
|
{
|
|
8427
|
-
decode:
|
|
8617
|
+
decode: SchemaGetter.transform((e) => Redacted_.make(e, { label: options?.label })),
|
|
8428
8618
|
encode: options?.disallowJsonEncode ?
|
|
8429
|
-
|
|
8619
|
+
SchemaGetter.forbidden((oe) =>
|
|
8430
8620
|
"Cannot serialize Redacted" +
|
|
8431
8621
|
(Option_.isSome(oe) && typeof oe.value.label === "string" ? ` with label: "${oe.value.label}"` : "")
|
|
8432
8622
|
) :
|
|
8433
|
-
|
|
8623
|
+
SchemaGetter.transform(Redacted_.value)
|
|
8434
8624
|
}
|
|
8435
8625
|
),
|
|
8436
8626
|
toArbitrary: ([value]) => () => value.map((a) => Redacted_.make(a, { label: options?.label })),
|
|
@@ -8461,7 +8651,7 @@ export interface RedactedFromValue<S extends Top>
|
|
|
8461
8651
|
* @since 4.0.0
|
|
8462
8652
|
*/
|
|
8463
8653
|
export function redact<S extends Top>(schema: S): middlewareDecoding<S, S["DecodingServices"]> {
|
|
8464
|
-
return schema.pipe(middlewareDecoding(Effect.mapErrorEager(
|
|
8654
|
+
return schema.pipe(middlewareDecoding(Effect.mapErrorEager(SchemaIssue.redact)))
|
|
8465
8655
|
}
|
|
8466
8656
|
|
|
8467
8657
|
/**
|
|
@@ -8483,13 +8673,13 @@ export function RedactedFromValue<S extends Top>(value: S, options?: {
|
|
|
8483
8673
|
disallowJsonEncode: options?.disallowEncode
|
|
8484
8674
|
}),
|
|
8485
8675
|
{
|
|
8486
|
-
decode:
|
|
8676
|
+
decode: SchemaGetter.transform((t) => Redacted_.make(t, { label: options?.label })),
|
|
8487
8677
|
encode: options?.disallowEncode ?
|
|
8488
|
-
|
|
8678
|
+
SchemaGetter.forbidden((oe) =>
|
|
8489
8679
|
"Cannot encode Redacted" +
|
|
8490
8680
|
(Option_.isSome(oe) && typeof oe.value.label === "string" ? ` with label: "${oe.value.label}"` : "")
|
|
8491
8681
|
) :
|
|
8492
|
-
|
|
8682
|
+
SchemaGetter.transform(Redacted_.value)
|
|
8493
8683
|
}
|
|
8494
8684
|
)
|
|
8495
8685
|
)
|
|
@@ -8542,8 +8732,8 @@ export type CauseReasonIso<E extends Top, D extends Top> = {
|
|
|
8542
8732
|
*
|
|
8543
8733
|
* **When to use**
|
|
8544
8734
|
*
|
|
8545
|
-
* Use
|
|
8546
|
-
*
|
|
8735
|
+
* Use when serializing or decoding individual cause reasons separately from a
|
|
8736
|
+
* full failure cause, with distinct schemas for typed errors and defects.
|
|
8547
8737
|
*
|
|
8548
8738
|
* **Details**
|
|
8549
8739
|
*
|
|
@@ -8561,24 +8751,25 @@ export function CauseReason<E extends Top, D extends Top>(error: E, defect: D):
|
|
|
8561
8751
|
[error, defect],
|
|
8562
8752
|
([error, defect]) => (input, ast, options) => {
|
|
8563
8753
|
if (!Cause_.isReason(input)) {
|
|
8564
|
-
return Effect.fail(new
|
|
8754
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
8565
8755
|
}
|
|
8566
8756
|
switch (input._tag) {
|
|
8567
8757
|
case "Fail":
|
|
8568
8758
|
return Effect.mapBothEager(
|
|
8569
|
-
|
|
8759
|
+
SchemaParser.decodeUnknownEffect(error)(input.error, options),
|
|
8570
8760
|
{
|
|
8571
8761
|
onSuccess: Cause_.makeFailReason,
|
|
8572
|
-
onFailure: (issue) =>
|
|
8762
|
+
onFailure: (issue) =>
|
|
8763
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["error"], issue)])
|
|
8573
8764
|
}
|
|
8574
8765
|
)
|
|
8575
8766
|
case "Die":
|
|
8576
8767
|
return Effect.mapBothEager(
|
|
8577
|
-
|
|
8768
|
+
SchemaParser.decodeUnknownEffect(defect)(input.defect, options),
|
|
8578
8769
|
{
|
|
8579
8770
|
onSuccess: Cause_.makeDieReason,
|
|
8580
8771
|
onFailure: (issue) =>
|
|
8581
|
-
new
|
|
8772
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["defect"], issue)])
|
|
8582
8773
|
}
|
|
8583
8774
|
)
|
|
8584
8775
|
case "Interrupt":
|
|
@@ -8602,7 +8793,7 @@ export function CauseReason<E extends Top, D extends Top>(error: E, defect: D):
|
|
|
8602
8793
|
Struct({ _tag: Literal("Die"), defect }),
|
|
8603
8794
|
Struct({ _tag: Literal("Interrupt"), fiberId: UndefinedOr(Finite) })
|
|
8604
8795
|
]),
|
|
8605
|
-
|
|
8796
|
+
SchemaTransformation.transform({
|
|
8606
8797
|
decode: (e) => {
|
|
8607
8798
|
switch (e._tag) {
|
|
8608
8799
|
case "Fail":
|
|
@@ -8727,11 +8918,12 @@ export function Cause<E extends Top, D extends Top>(error: E, defect: D): Cause<
|
|
|
8727
8918
|
const failures = ArraySchema(CauseReason(error, defect))
|
|
8728
8919
|
return (input, ast, options) => {
|
|
8729
8920
|
if (!Cause_.isCause(input)) {
|
|
8730
|
-
return Effect.fail(new
|
|
8921
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
8731
8922
|
}
|
|
8732
|
-
return Effect.mapBothEager(
|
|
8923
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(failures)(input.reasons, options), {
|
|
8733
8924
|
onSuccess: Cause_.fromReasons,
|
|
8734
|
-
onFailure: (issue) =>
|
|
8925
|
+
onFailure: (issue) =>
|
|
8926
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["failures"], issue)])
|
|
8735
8927
|
})
|
|
8736
8928
|
}
|
|
8737
8929
|
},
|
|
@@ -8748,7 +8940,7 @@ export function Cause<E extends Top, D extends Top>(error: E, defect: D): Cause<
|
|
|
8748
8940
|
toCodec: ([error, defect]) =>
|
|
8749
8941
|
link<Cause_.Cause<E["Encoded"]>>()(
|
|
8750
8942
|
ArraySchema(CauseReason(error, defect)),
|
|
8751
|
-
|
|
8943
|
+
SchemaTransformation.transform({
|
|
8752
8944
|
decode: Cause_.fromReasons,
|
|
8753
8945
|
encode: ({ reasons: failures }) => failures
|
|
8754
8946
|
})
|
|
@@ -8815,7 +9007,7 @@ export const Error: Error = instanceOf(globalThis.Error, {
|
|
|
8815
9007
|
Type: `globalThis.Error`
|
|
8816
9008
|
},
|
|
8817
9009
|
expected: "Error",
|
|
8818
|
-
toCodecJson: () => link<globalThis.Error>()(ErrorJsonEncoded,
|
|
9010
|
+
toCodecJson: () => link<globalThis.Error>()(ErrorJsonEncoded, SchemaTransformation.errorFromErrorJsonEncoded()),
|
|
8819
9011
|
toArbitrary: () => (fc) => fc.string().map((message) => new globalThis.Error(message))
|
|
8820
9012
|
})
|
|
8821
9013
|
|
|
@@ -8844,7 +9036,7 @@ export const ErrorWithStack: Error = instanceOf(globalThis.Error, {
|
|
|
8844
9036
|
toCodecJson: () =>
|
|
8845
9037
|
link<globalThis.Error>()(
|
|
8846
9038
|
ErrorJsonEncoded,
|
|
8847
|
-
|
|
9039
|
+
SchemaTransformation.errorFromErrorJsonEncoded({
|
|
8848
9040
|
includeStack: true
|
|
8849
9041
|
})
|
|
8850
9042
|
),
|
|
@@ -8875,9 +9067,9 @@ export interface Defect extends
|
|
|
8875
9067
|
readonly "Rebuild": Defect
|
|
8876
9068
|
}
|
|
8877
9069
|
|
|
8878
|
-
const defectTransformation = new
|
|
8879
|
-
|
|
8880
|
-
|
|
9070
|
+
const defectTransformation = new SchemaTransformation.Transformation(
|
|
9071
|
+
SchemaGetter.passthrough(),
|
|
9072
|
+
SchemaGetter.transform((u) => {
|
|
8881
9073
|
try {
|
|
8882
9074
|
return JSON.parse(JSON.stringify(u))
|
|
8883
9075
|
} catch {
|
|
@@ -8900,7 +9092,7 @@ const defectTransformation = new Transformation.Transformation(
|
|
|
8900
9092
|
* @since 3.10.0
|
|
8901
9093
|
*/
|
|
8902
9094
|
export const Defect: Defect = Union([
|
|
8903
|
-
ErrorJsonEncoded.pipe(decodeTo(Error,
|
|
9095
|
+
ErrorJsonEncoded.pipe(decodeTo(Error, SchemaTransformation.errorFromErrorJsonEncoded())),
|
|
8904
9096
|
Any.pipe(decodeTo(
|
|
8905
9097
|
Unknown.annotate({
|
|
8906
9098
|
toCodecJson: () => link<unknown>()(Any, defectTransformation),
|
|
@@ -8919,7 +9111,7 @@ export const Defect: Defect = Union([
|
|
|
8919
9111
|
export const DefectWithStack: Defect = Union([
|
|
8920
9112
|
ErrorJsonEncoded.pipe(decodeTo(
|
|
8921
9113
|
ErrorWithStack,
|
|
8922
|
-
|
|
9114
|
+
SchemaTransformation.errorFromErrorJsonEncoded({
|
|
8923
9115
|
includeStack: true
|
|
8924
9116
|
})
|
|
8925
9117
|
)),
|
|
@@ -8975,6 +9167,11 @@ export type ExitIso<A extends Top, E extends Top, D extends Top> = {
|
|
|
8975
9167
|
* Creates a schema for `Exit` values using schemas for the success value, typed
|
|
8976
9168
|
* failure, and unexpected defect channels.
|
|
8977
9169
|
*
|
|
9170
|
+
* **When to use**
|
|
9171
|
+
*
|
|
9172
|
+
* Use when serializing or validating an effect outcome where success, typed
|
|
9173
|
+
* failure, and defects each need their own schema.
|
|
9174
|
+
*
|
|
8978
9175
|
* @category Exit
|
|
8979
9176
|
* @since 3.10.0
|
|
8980
9177
|
*/
|
|
@@ -8989,25 +9186,25 @@ export function Exit<A extends Top, E extends Top, D extends Top>(value: A, erro
|
|
|
8989
9186
|
const cause = Cause(error, defect)
|
|
8990
9187
|
return (input, ast, options) => {
|
|
8991
9188
|
if (!Exit_.isExit(input)) {
|
|
8992
|
-
return Effect.fail(new
|
|
9189
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
8993
9190
|
}
|
|
8994
9191
|
switch (input._tag) {
|
|
8995
9192
|
case "Success":
|
|
8996
9193
|
return Effect.mapBothEager(
|
|
8997
|
-
|
|
9194
|
+
SchemaParser.decodeUnknownEffect(value)(input.value, options),
|
|
8998
9195
|
{
|
|
8999
9196
|
onSuccess: Exit_.succeed,
|
|
9000
9197
|
onFailure: (issue) =>
|
|
9001
|
-
new
|
|
9198
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["value"], issue)])
|
|
9002
9199
|
}
|
|
9003
9200
|
)
|
|
9004
9201
|
case "Failure":
|
|
9005
9202
|
return Effect.mapBothEager(
|
|
9006
|
-
|
|
9203
|
+
SchemaParser.decodeUnknownEffect(cause)(input.cause, options),
|
|
9007
9204
|
{
|
|
9008
9205
|
onSuccess: Exit_.failCause,
|
|
9009
9206
|
onFailure: (issue) =>
|
|
9010
|
-
new
|
|
9207
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["cause"], issue)])
|
|
9011
9208
|
}
|
|
9012
9209
|
)
|
|
9013
9210
|
}
|
|
@@ -9029,7 +9226,7 @@ export function Exit<A extends Top, E extends Top, D extends Top>(value: A, erro
|
|
|
9029
9226
|
Struct({ _tag: Literal("Success"), value }),
|
|
9030
9227
|
Struct({ _tag: Literal("Failure"), cause: Cause(error, defect) })
|
|
9031
9228
|
]),
|
|
9032
|
-
|
|
9229
|
+
SchemaTransformation.transform({
|
|
9033
9230
|
decode: (e): Exit_.Exit<A["Encoded"], E["Encoded"]> =>
|
|
9034
9231
|
e._tag === "Success" ? Exit_.succeed(e.value) : Exit_.failCause(e.cause),
|
|
9035
9232
|
encode: (exit) =>
|
|
@@ -9119,15 +9316,15 @@ export function ReadonlyMap<Key extends Top, Value extends Top>(key: Key, value:
|
|
|
9119
9316
|
return (input, ast, options) => {
|
|
9120
9317
|
if (input instanceof globalThis.Map) {
|
|
9121
9318
|
return Effect.mapBothEager(
|
|
9122
|
-
|
|
9319
|
+
SchemaParser.decodeUnknownEffect(array)([...input], options),
|
|
9123
9320
|
{
|
|
9124
9321
|
onSuccess: (array: ReadonlyArray<readonly [Key["Type"], Value["Type"]]>) => new globalThis.Map(array),
|
|
9125
9322
|
onFailure: (issue) =>
|
|
9126
|
-
new
|
|
9323
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["entries"], issue)])
|
|
9127
9324
|
}
|
|
9128
9325
|
)
|
|
9129
9326
|
}
|
|
9130
|
-
return Effect.fail(new
|
|
9327
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
9131
9328
|
}
|
|
9132
9329
|
},
|
|
9133
9330
|
{
|
|
@@ -9142,7 +9339,7 @@ export function ReadonlyMap<Key extends Top, Value extends Top>(key: Key, value:
|
|
|
9142
9339
|
toCodec: ([key, value]) =>
|
|
9143
9340
|
link<globalThis.Map<Key["Encoded"], Value["Encoded"]>>()(
|
|
9144
9341
|
ArraySchema(Tuple([key, value])),
|
|
9145
|
-
|
|
9342
|
+
SchemaTransformation.transform({
|
|
9146
9343
|
decode: (e) => new globalThis.Map(e),
|
|
9147
9344
|
encode: (map) => [...map.entries()]
|
|
9148
9345
|
})
|
|
@@ -9214,15 +9411,15 @@ export function HashMap<Key extends Top, Value extends Top>(key: Key, value: Val
|
|
|
9214
9411
|
return (input, ast, options) => {
|
|
9215
9412
|
if (HashMap_.isHashMap(input)) {
|
|
9216
9413
|
return Effect.mapBothEager(
|
|
9217
|
-
|
|
9414
|
+
SchemaParser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options),
|
|
9218
9415
|
{
|
|
9219
9416
|
onSuccess: HashMap_.fromIterable,
|
|
9220
9417
|
onFailure: (issue) =>
|
|
9221
|
-
new
|
|
9418
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["entries"], issue)])
|
|
9222
9419
|
}
|
|
9223
9420
|
)
|
|
9224
9421
|
}
|
|
9225
|
-
return Effect.fail(new
|
|
9422
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
9226
9423
|
}
|
|
9227
9424
|
},
|
|
9228
9425
|
{
|
|
@@ -9238,7 +9435,7 @@ export function HashMap<Key extends Top, Value extends Top>(key: Key, value: Val
|
|
|
9238
9435
|
toCodec: ([key, value]) =>
|
|
9239
9436
|
link<HashMap_.HashMap<Key["Encoded"], Value["Encoded"]>>()(
|
|
9240
9437
|
ArraySchema(Tuple([key, value])),
|
|
9241
|
-
|
|
9438
|
+
SchemaTransformation.transform({
|
|
9242
9439
|
decode: HashMap_.fromIterable,
|
|
9243
9440
|
encode: HashMap_.toEntries
|
|
9244
9441
|
})
|
|
@@ -9309,15 +9506,15 @@ export function ReadonlySet<Value extends Top>(value: Value): $ReadonlySet<Value
|
|
|
9309
9506
|
return (input, ast, options) => {
|
|
9310
9507
|
if (input instanceof globalThis.Set) {
|
|
9311
9508
|
return Effect.mapBothEager(
|
|
9312
|
-
|
|
9509
|
+
SchemaParser.decodeUnknownEffect(array)([...input], options),
|
|
9313
9510
|
{
|
|
9314
9511
|
onSuccess: (array: ReadonlyArray<Value["Type"]>) => new globalThis.Set(array),
|
|
9315
9512
|
onFailure: (issue) =>
|
|
9316
|
-
new
|
|
9513
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["values"], issue)])
|
|
9317
9514
|
}
|
|
9318
9515
|
)
|
|
9319
9516
|
}
|
|
9320
|
-
return Effect.fail(new
|
|
9517
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
9321
9518
|
}
|
|
9322
9519
|
},
|
|
9323
9520
|
{
|
|
@@ -9332,7 +9529,7 @@ export function ReadonlySet<Value extends Top>(value: Value): $ReadonlySet<Value
|
|
|
9332
9529
|
toCodec: ([value]) =>
|
|
9333
9530
|
link<globalThis.Set<Value["Encoded"]>>()(
|
|
9334
9531
|
ArraySchema(value),
|
|
9335
|
-
|
|
9532
|
+
SchemaTransformation.transform({
|
|
9336
9533
|
decode: (e) => new globalThis.Set(e),
|
|
9337
9534
|
encode: (set) => [...set.values()]
|
|
9338
9535
|
})
|
|
@@ -9403,15 +9600,15 @@ export function HashSet<Value extends Top>(value: Value): HashSet<Value> {
|
|
|
9403
9600
|
return (input, ast, options) => {
|
|
9404
9601
|
if (HashSet_.isHashSet(input)) {
|
|
9405
9602
|
return Effect.mapBothEager(
|
|
9406
|
-
|
|
9603
|
+
SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
|
|
9407
9604
|
{
|
|
9408
9605
|
onSuccess: HashSet_.fromIterable,
|
|
9409
9606
|
onFailure: (issue) =>
|
|
9410
|
-
new
|
|
9607
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["values"], issue)])
|
|
9411
9608
|
}
|
|
9412
9609
|
)
|
|
9413
9610
|
}
|
|
9414
|
-
return Effect.fail(new
|
|
9611
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
9415
9612
|
}
|
|
9416
9613
|
},
|
|
9417
9614
|
{
|
|
@@ -9426,7 +9623,7 @@ export function HashSet<Value extends Top>(value: Value): HashSet<Value> {
|
|
|
9426
9623
|
toCodec: ([value]) =>
|
|
9427
9624
|
link<HashSet_.HashSet<Value["Encoded"]>>()(
|
|
9428
9625
|
ArraySchema(value),
|
|
9429
|
-
|
|
9626
|
+
SchemaTransformation.transform({
|
|
9430
9627
|
decode: HashSet_.fromIterable,
|
|
9431
9628
|
encode: Arr.fromIterable
|
|
9432
9629
|
})
|
|
@@ -9504,15 +9701,15 @@ export function Chunk<Value extends Top>(value: Value): Chunk<Value> {
|
|
|
9504
9701
|
return (input, ast, options) => {
|
|
9505
9702
|
if (Chunk_.isChunk(input)) {
|
|
9506
9703
|
return Effect.mapBothEager(
|
|
9507
|
-
|
|
9704
|
+
SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
|
|
9508
9705
|
{
|
|
9509
9706
|
onSuccess: Chunk_.fromIterable,
|
|
9510
9707
|
onFailure: (issue) =>
|
|
9511
|
-
new
|
|
9708
|
+
new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["values"], issue)])
|
|
9512
9709
|
}
|
|
9513
9710
|
)
|
|
9514
9711
|
}
|
|
9515
|
-
return Effect.fail(new
|
|
9712
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
9516
9713
|
}
|
|
9517
9714
|
},
|
|
9518
9715
|
{
|
|
@@ -9527,7 +9724,7 @@ export function Chunk<Value extends Top>(value: Value): Chunk<Value> {
|
|
|
9527
9724
|
toCodec: ([value]) =>
|
|
9528
9725
|
link<Chunk_.Chunk<Value["Encoded"]>>()(
|
|
9529
9726
|
ArraySchema(value),
|
|
9530
|
-
|
|
9727
|
+
SchemaTransformation.transform({
|
|
9531
9728
|
decode: Chunk_.fromIterable,
|
|
9532
9729
|
encode: Arr.fromIterable
|
|
9533
9730
|
})
|
|
@@ -9590,11 +9787,11 @@ export const RegExp: RegExp = instanceOf(
|
|
|
9590
9787
|
source: String,
|
|
9591
9788
|
flags: String
|
|
9592
9789
|
}),
|
|
9593
|
-
|
|
9790
|
+
SchemaTransformation.transformOrFail({
|
|
9594
9791
|
decode: (e) =>
|
|
9595
9792
|
Effect.try({
|
|
9596
9793
|
try: () => new globalThis.RegExp(e.source, e.flags),
|
|
9597
|
-
catch: (e) => new
|
|
9794
|
+
catch: (e) => new SchemaIssue.InvalidValue(Option_.some(e), { message: globalThis.String(e) })
|
|
9598
9795
|
}),
|
|
9599
9796
|
encode: (regExp) =>
|
|
9600
9797
|
Effect.succeed({
|
|
@@ -9667,7 +9864,7 @@ export const URL: URL = instanceOf(
|
|
|
9667
9864
|
toCodecJson: () =>
|
|
9668
9865
|
link<globalThis.URL>()(
|
|
9669
9866
|
URLString,
|
|
9670
|
-
|
|
9867
|
+
SchemaTransformation.urlFromString
|
|
9671
9868
|
),
|
|
9672
9869
|
toArbitrary: () => (fc) => fc.webUrl().map((s) => new globalThis.URL(s)),
|
|
9673
9870
|
toEquivalence: () => (a, b) => a.toString() === b.toString()
|
|
@@ -9698,7 +9895,7 @@ export interface URLFromString extends decodeTo<URL, String> {
|
|
|
9698
9895
|
* @category URL
|
|
9699
9896
|
* @since 4.0.0
|
|
9700
9897
|
*/
|
|
9701
|
-
export const URLFromString: URLFromString = URLString.pipe(decodeTo(URL,
|
|
9898
|
+
export const URLFromString: URLFromString = URLString.pipe(decodeTo(URL, SchemaTransformation.urlFromString))
|
|
9702
9899
|
|
|
9703
9900
|
/**
|
|
9704
9901
|
* Type-level representation of {@link Date}.
|
|
@@ -9717,8 +9914,8 @@ const DateString = String.annotate({ expected: "a string in ISO 8601 format that
|
|
|
9717
9914
|
*
|
|
9718
9915
|
* **When to use**
|
|
9719
9916
|
*
|
|
9720
|
-
* Use to validate in-memory values that must already be JavaScript
|
|
9721
|
-
*
|
|
9917
|
+
* Use to validate in-memory values that must already be JavaScript date
|
|
9918
|
+
* objects.
|
|
9722
9919
|
*
|
|
9723
9920
|
* **Details**
|
|
9724
9921
|
*
|
|
@@ -9754,7 +9951,7 @@ export const Date: Date = instanceOf(
|
|
|
9754
9951
|
toCodecJson: () =>
|
|
9755
9952
|
link<globalThis.Date>()(
|
|
9756
9953
|
DateString,
|
|
9757
|
-
|
|
9954
|
+
SchemaTransformation.dateFromString
|
|
9758
9955
|
),
|
|
9759
9956
|
toArbitrary: () => (fc, ctx) => fc.date(ctx?.constraints?.date)
|
|
9760
9957
|
}
|
|
@@ -9797,7 +9994,7 @@ export interface DateFromString extends decodeTo<Date, String> {
|
|
|
9797
9994
|
* @category Date
|
|
9798
9995
|
* @since 3.10.0
|
|
9799
9996
|
*/
|
|
9800
|
-
export const DateFromString: DateFromString = DateString.pipe(decodeTo(Date,
|
|
9997
|
+
export const DateFromString: DateFromString = DateString.pipe(decodeTo(Date, SchemaTransformation.dateFromString))
|
|
9801
9998
|
|
|
9802
9999
|
/**
|
|
9803
10000
|
* Type-level representation of {@link DateValid}.
|
|
@@ -9873,7 +10070,7 @@ export const Duration: Duration = declare(
|
|
|
9873
10070
|
Struct({ _tag: Literal("Nanos"), value: BigInt }),
|
|
9874
10071
|
Struct({ _tag: Literal("Millis"), value: Int })
|
|
9875
10072
|
]),
|
|
9876
|
-
|
|
10073
|
+
SchemaTransformation.transform({
|
|
9877
10074
|
decode: (e) => {
|
|
9878
10075
|
switch (e._tag) {
|
|
9879
10076
|
case "Infinity":
|
|
@@ -9940,7 +10137,7 @@ export interface DurationFromString extends decodeTo<Duration, String> {
|
|
|
9940
10137
|
* @since 4.0.0
|
|
9941
10138
|
*/
|
|
9942
10139
|
export const DurationFromString: DurationFromString = DurationString.pipe(
|
|
9943
|
-
decodeTo(Duration,
|
|
10140
|
+
decodeTo(Duration, SchemaTransformation.durationFromString)
|
|
9944
10141
|
)
|
|
9945
10142
|
|
|
9946
10143
|
/**
|
|
@@ -9973,7 +10170,7 @@ const bigint0 = globalThis.BigInt(0)
|
|
|
9973
10170
|
* @since 3.10.0
|
|
9974
10171
|
*/
|
|
9975
10172
|
export const DurationFromNanos: DurationFromNanos = BigInt.check(isGreaterThanOrEqualToBigInt(bigint0)).pipe(
|
|
9976
|
-
decodeTo(Duration,
|
|
10173
|
+
decodeTo(Duration, SchemaTransformation.durationFromNanos)
|
|
9977
10174
|
)
|
|
9978
10175
|
|
|
9979
10176
|
/**
|
|
@@ -10005,7 +10202,7 @@ export interface DurationFromMillis extends decodeTo<Duration, Number> {
|
|
|
10005
10202
|
* @since 3.10.0
|
|
10006
10203
|
*/
|
|
10007
10204
|
export const DurationFromMillis: DurationFromMillis = Number.check(isGreaterThanOrEqualTo(0)).pipe(
|
|
10008
|
-
decodeTo(Duration,
|
|
10205
|
+
decodeTo(Duration, SchemaTransformation.durationFromMillis)
|
|
10009
10206
|
)
|
|
10010
10207
|
|
|
10011
10208
|
/**
|
|
@@ -10025,7 +10222,7 @@ const BigDecimalString = String.annotate({ expected: "a string that will be deco
|
|
|
10025
10222
|
*
|
|
10026
10223
|
* **When to use**
|
|
10027
10224
|
*
|
|
10028
|
-
* Use when
|
|
10225
|
+
* Use when you already have Effect decimal instances and need schema
|
|
10029
10226
|
* validation, formatting, equivalence, and JSON string serialization.
|
|
10030
10227
|
*
|
|
10031
10228
|
* **Details**
|
|
@@ -10054,7 +10251,7 @@ export const BigDecimal: BigDecimal = declare(
|
|
|
10054
10251
|
toCodecJson: () =>
|
|
10055
10252
|
link<BigDecimal_.BigDecimal>()(
|
|
10056
10253
|
BigDecimalString,
|
|
10057
|
-
|
|
10254
|
+
SchemaTransformation.bigDecimalFromString
|
|
10058
10255
|
),
|
|
10059
10256
|
toArbitrary: () => (fc) =>
|
|
10060
10257
|
fc.tuple(fc.bigInt(), fc.integer({ min: 0, max: 20 }))
|
|
@@ -10102,7 +10299,7 @@ export interface BigDecimalFromString extends decodeTo<BigDecimal, String> {
|
|
|
10102
10299
|
* @since 4.0.0
|
|
10103
10300
|
*/
|
|
10104
10301
|
export const BigDecimalFromString: BigDecimalFromString = BigDecimalString.pipe(
|
|
10105
|
-
decodeTo(BigDecimal,
|
|
10302
|
+
decodeTo(BigDecimal, SchemaTransformation.bigDecimalFromString)
|
|
10106
10303
|
)
|
|
10107
10304
|
|
|
10108
10305
|
/**
|
|
@@ -10222,8 +10419,8 @@ export function fromJsonString<S extends Top>(schema: S): fromJsonString<S> {
|
|
|
10222
10419
|
return String.annotate({
|
|
10223
10420
|
expected: "a string that will be decoded as JSON",
|
|
10224
10421
|
contentMediaType: "application/json",
|
|
10225
|
-
contentSchema:
|
|
10226
|
-
}).pipe(decodeTo(schema,
|
|
10422
|
+
contentSchema: SchemaAST.toEncoded(schema.ast)
|
|
10423
|
+
}).pipe(decodeTo(schema, SchemaTransformation.fromJsonString))
|
|
10227
10424
|
}
|
|
10228
10425
|
|
|
10229
10426
|
/**
|
|
@@ -10264,12 +10461,12 @@ export const File: File = instanceOf(globalThis.File, {
|
|
|
10264
10461
|
name: String,
|
|
10265
10462
|
lastModified: Number
|
|
10266
10463
|
}),
|
|
10267
|
-
|
|
10464
|
+
SchemaTransformation.transformOrFail({
|
|
10268
10465
|
decode: (e) =>
|
|
10269
10466
|
Result_.match(Encoding.decodeBase64(e.data), {
|
|
10270
10467
|
onFailure: (error) =>
|
|
10271
10468
|
Effect.fail(
|
|
10272
|
-
new
|
|
10469
|
+
new SchemaIssue.InvalidValue(Option_.some(e.data), {
|
|
10273
10470
|
message: error.message
|
|
10274
10471
|
})
|
|
10275
10472
|
),
|
|
@@ -10292,7 +10489,7 @@ export const File: File = instanceOf(globalThis.File, {
|
|
|
10292
10489
|
}
|
|
10293
10490
|
},
|
|
10294
10491
|
catch: (e) =>
|
|
10295
|
-
new
|
|
10492
|
+
new SchemaIssue.InvalidValue(Option_.some(file), {
|
|
10296
10493
|
message: globalThis.String(e)
|
|
10297
10494
|
})
|
|
10298
10495
|
})
|
|
@@ -10341,7 +10538,7 @@ export const FormData: FormData = instanceOf(globalThis.FormData, {
|
|
|
10341
10538
|
])
|
|
10342
10539
|
])
|
|
10343
10540
|
),
|
|
10344
|
-
|
|
10541
|
+
SchemaTransformation.transformOrFail({
|
|
10345
10542
|
decode: (e) => {
|
|
10346
10543
|
const out = new globalThis.FormData()
|
|
10347
10544
|
for (const [key, entry] of e) {
|
|
@@ -10463,7 +10660,7 @@ export interface fromFormData<S extends Top> extends decodeTo<S, FormData> {
|
|
|
10463
10660
|
* @since 4.0.0
|
|
10464
10661
|
*/
|
|
10465
10662
|
export function fromFormData<S extends Top>(schema: S): fromFormData<S> {
|
|
10466
|
-
return FormData.pipe(decodeTo(schema,
|
|
10663
|
+
return FormData.pipe(decodeTo(schema, SchemaTransformation.fromFormData))
|
|
10467
10664
|
}
|
|
10468
10665
|
|
|
10469
10666
|
/**
|
|
@@ -10498,7 +10695,7 @@ export const URLSearchParams: URLSearchParams = instanceOf(globalThis.URLSearchP
|
|
|
10498
10695
|
toCodecJson: () =>
|
|
10499
10696
|
link<globalThis.URLSearchParams>()(
|
|
10500
10697
|
String.annotate({ expected: "a query string that will be decoded as URLSearchParams" }),
|
|
10501
|
-
|
|
10698
|
+
SchemaTransformation.transform({
|
|
10502
10699
|
decode: (e) => new globalThis.URLSearchParams(e),
|
|
10503
10700
|
encode: (params) => params.toString()
|
|
10504
10701
|
})
|
|
@@ -10596,7 +10793,7 @@ export interface fromURLSearchParams<S extends Top> extends decodeTo<S, URLSearc
|
|
|
10596
10793
|
* @since 4.0.0
|
|
10597
10794
|
*/
|
|
10598
10795
|
export function fromURLSearchParams<S extends Top>(schema: S): fromURLSearchParams<S> {
|
|
10599
|
-
return URLSearchParams.pipe(decodeTo(schema,
|
|
10796
|
+
return URLSearchParams.pipe(decodeTo(schema, SchemaTransformation.fromURLSearchParams))
|
|
10600
10797
|
}
|
|
10601
10798
|
|
|
10602
10799
|
/**
|
|
@@ -10664,7 +10861,7 @@ export interface NumberFromString extends decodeTo<Finite, String> {
|
|
|
10664
10861
|
*/
|
|
10665
10862
|
export const NumberFromString: NumberFromString = String.annotate({
|
|
10666
10863
|
expected: "a string that will be decoded as a number"
|
|
10667
|
-
}).pipe(decodeTo(Number,
|
|
10864
|
+
}).pipe(decodeTo(Number, SchemaTransformation.numberFromString))
|
|
10668
10865
|
|
|
10669
10866
|
/**
|
|
10670
10867
|
* Type-level representation of {@link FiniteFromString}.
|
|
@@ -10693,7 +10890,7 @@ export interface FiniteFromString extends decodeTo<Finite, String> {
|
|
|
10693
10890
|
*/
|
|
10694
10891
|
export const FiniteFromString: FiniteFromString = String.annotate({
|
|
10695
10892
|
expected: "a string that will be decoded as a finite number"
|
|
10696
|
-
}).pipe(decodeTo(Finite,
|
|
10893
|
+
}).pipe(decodeTo(Finite, SchemaTransformation.numberFromString))
|
|
10697
10894
|
|
|
10698
10895
|
/**
|
|
10699
10896
|
* Type-level representation of {@link BigIntFromString}.
|
|
@@ -10733,8 +10930,8 @@ export interface BigIntFromString extends decodeTo<BigInt, String> {
|
|
|
10733
10930
|
* @category BigInt
|
|
10734
10931
|
* @since 4.0.0
|
|
10735
10932
|
*/
|
|
10736
|
-
export const BigIntFromString: BigIntFromString = make<String>(
|
|
10737
|
-
decodeTo(BigInt,
|
|
10933
|
+
export const BigIntFromString: BigIntFromString = make<String>(SchemaAST.bigIntString).pipe(
|
|
10934
|
+
decodeTo(BigInt, SchemaTransformation.bigintFromString)
|
|
10738
10935
|
)
|
|
10739
10936
|
|
|
10740
10937
|
/**
|
|
@@ -10781,7 +10978,7 @@ export interface Trim extends decodeTo<Trimmed, String> {
|
|
|
10781
10978
|
*/
|
|
10782
10979
|
export const Trim: Trim = String.annotate({
|
|
10783
10980
|
expected: "a string that will be decoded as a trimmed string"
|
|
10784
|
-
}).pipe(decodeTo(Trimmed,
|
|
10981
|
+
}).pipe(decodeTo(Trimmed, SchemaTransformation.trim()))
|
|
10785
10982
|
|
|
10786
10983
|
/**
|
|
10787
10984
|
* Type-level representation of {@link StringFromBase64}.
|
|
@@ -10810,7 +11007,7 @@ export interface StringFromBase64 extends decodeTo<String, String> {
|
|
|
10810
11007
|
export const StringFromBase64: StringFromBase64 = String.annotate({
|
|
10811
11008
|
expected: "a base64 encoded string that will be decoded as a UTF-8 string"
|
|
10812
11009
|
}).pipe(
|
|
10813
|
-
decodeTo(String,
|
|
11010
|
+
decodeTo(String, SchemaTransformation.stringFromBase64String)
|
|
10814
11011
|
)
|
|
10815
11012
|
|
|
10816
11013
|
/**
|
|
@@ -10840,7 +11037,7 @@ export interface StringFromBase64Url extends decodeTo<String, String> {
|
|
|
10840
11037
|
export const StringFromBase64Url: StringFromBase64Url = String.annotate({
|
|
10841
11038
|
expected: "a base64 (URL) encoded string that will be decoded as a UTF-8 string"
|
|
10842
11039
|
}).pipe(
|
|
10843
|
-
decodeTo(String,
|
|
11040
|
+
decodeTo(String, SchemaTransformation.stringFromBase64UrlString)
|
|
10844
11041
|
)
|
|
10845
11042
|
|
|
10846
11043
|
/**
|
|
@@ -10870,7 +11067,7 @@ export interface StringFromHex extends decodeTo<String, String> {
|
|
|
10870
11067
|
export const StringFromHex: StringFromHex = String.annotate({
|
|
10871
11068
|
expected: "a hex encoded string that will be decoded as a UTF-8 string"
|
|
10872
11069
|
}).pipe(
|
|
10873
|
-
decodeTo(String,
|
|
11070
|
+
decodeTo(String, SchemaTransformation.stringFromHexString)
|
|
10874
11071
|
)
|
|
10875
11072
|
|
|
10876
11073
|
/**
|
|
@@ -10919,7 +11116,7 @@ export interface StringFromUriComponent extends decodeTo<String, String> {
|
|
|
10919
11116
|
export const StringFromUriComponent: StringFromUriComponent = String.annotate({
|
|
10920
11117
|
expected: "a URI component encoded string that will be decoded as a UTF-8 string"
|
|
10921
11118
|
}).pipe(
|
|
10922
|
-
decodeTo(String,
|
|
11119
|
+
decodeTo(String, SchemaTransformation.stringFromUriComponent)
|
|
10923
11120
|
)
|
|
10924
11121
|
|
|
10925
11122
|
/**
|
|
@@ -10981,7 +11178,7 @@ export interface BooleanFromBit extends decodeTo<Boolean, Literals<readonly [0,
|
|
|
10981
11178
|
export const BooleanFromBit: BooleanFromBit = Literals([0, 1]).pipe(
|
|
10982
11179
|
decodeTo(
|
|
10983
11180
|
Boolean,
|
|
10984
|
-
|
|
11181
|
+
SchemaTransformation.transform({
|
|
10985
11182
|
decode: (bit) => bit === 1,
|
|
10986
11183
|
encode: (bool) => bool ? 1 : 0
|
|
10987
11184
|
})
|
|
@@ -11028,7 +11225,7 @@ export const Uint8Array: Uint8Array = instanceOf(globalThis.Uint8Array<ArrayBuff
|
|
|
11028
11225
|
toCodecJson: () =>
|
|
11029
11226
|
link<globalThis.Uint8Array<ArrayBufferLike>>()(
|
|
11030
11227
|
Base64String,
|
|
11031
|
-
|
|
11228
|
+
SchemaTransformation.uint8ArrayFromBase64String
|
|
11032
11229
|
),
|
|
11033
11230
|
toArbitrary: () => (fc) => fc.uint8Array()
|
|
11034
11231
|
})
|
|
@@ -11059,7 +11256,7 @@ export interface Uint8ArrayFromBase64 extends decodeTo<Uint8Array, String> {
|
|
|
11059
11256
|
* @since 3.10.0
|
|
11060
11257
|
*/
|
|
11061
11258
|
export const Uint8ArrayFromBase64: Uint8ArrayFromBase64 = Base64String.pipe(
|
|
11062
|
-
decodeTo(Uint8Array,
|
|
11259
|
+
decodeTo(Uint8Array, SchemaTransformation.uint8ArrayFromBase64String)
|
|
11063
11260
|
)
|
|
11064
11261
|
|
|
11065
11262
|
/**
|
|
@@ -11091,8 +11288,8 @@ export const Uint8ArrayFromBase64Url: Uint8ArrayFromBase64Url = String.annotate(
|
|
|
11091
11288
|
expected: "a base64 (URL) encoded string that will be decoded as a Uint8Array"
|
|
11092
11289
|
}).pipe(
|
|
11093
11290
|
decodeTo(Uint8Array, {
|
|
11094
|
-
decode:
|
|
11095
|
-
encode:
|
|
11291
|
+
decode: SchemaGetter.decodeBase64Url(),
|
|
11292
|
+
encode: SchemaGetter.encodeBase64Url()
|
|
11096
11293
|
})
|
|
11097
11294
|
)
|
|
11098
11295
|
|
|
@@ -11125,8 +11322,8 @@ export const Uint8ArrayFromHex: Uint8ArrayFromHex = String.annotate({
|
|
|
11125
11322
|
expected: "a hex encoded string that will be decoded as a Uint8Array"
|
|
11126
11323
|
}).pipe(
|
|
11127
11324
|
decodeTo(Uint8Array, {
|
|
11128
|
-
decode:
|
|
11129
|
-
encode:
|
|
11325
|
+
decode: SchemaGetter.decodeHex(),
|
|
11326
|
+
encode: SchemaGetter.encodeHex()
|
|
11130
11327
|
})
|
|
11131
11328
|
)
|
|
11132
11329
|
|
|
@@ -11176,7 +11373,7 @@ export const DateTimeUtc: DateTimeUtc = declare(
|
|
|
11176
11373
|
toCodecJson: () =>
|
|
11177
11374
|
link<DateTime.Utc>()(
|
|
11178
11375
|
String,
|
|
11179
|
-
|
|
11376
|
+
SchemaTransformation.dateTimeUtcFromString
|
|
11180
11377
|
),
|
|
11181
11378
|
toArbitrary: () => (fc, ctx) =>
|
|
11182
11379
|
fc.date({ noInvalidDate: true, ...ctx?.constraints?.date }).map((date) => DateTime.fromDateUnsafe(date)),
|
|
@@ -11200,8 +11397,8 @@ export interface DateTimeUtcFromDate extends decodeTo<DateTimeUtc, Date> {
|
|
|
11200
11397
|
*
|
|
11201
11398
|
* **When to use**
|
|
11202
11399
|
*
|
|
11203
|
-
* Use when
|
|
11204
|
-
*
|
|
11400
|
+
* Use when you need to decode valid JavaScript `Date` objects into
|
|
11401
|
+
* `DateTime.Utc` values.
|
|
11205
11402
|
*
|
|
11206
11403
|
* **Details**
|
|
11207
11404
|
*
|
|
@@ -11221,8 +11418,8 @@ export interface DateTimeUtcFromDate extends decodeTo<DateTimeUtc, Date> {
|
|
|
11221
11418
|
*/
|
|
11222
11419
|
export const DateTimeUtcFromDate: DateTimeUtcFromDate = DateValid.pipe(
|
|
11223
11420
|
decodeTo(DateTimeUtc, {
|
|
11224
|
-
decode:
|
|
11225
|
-
encode:
|
|
11421
|
+
decode: SchemaGetter.dateTimeUtcFromInput(),
|
|
11422
|
+
encode: SchemaGetter.transform(DateTime.toDateUtc)
|
|
11226
11423
|
})
|
|
11227
11424
|
)
|
|
11228
11425
|
|
|
@@ -11258,7 +11455,7 @@ export const DateTimeUtcFromString: DateTimeUtcFromString = String.annotate({
|
|
|
11258
11455
|
}).pipe(
|
|
11259
11456
|
decodeTo(
|
|
11260
11457
|
DateTimeUtc,
|
|
11261
|
-
|
|
11458
|
+
SchemaTransformation.dateTimeUtcFromString
|
|
11262
11459
|
)
|
|
11263
11460
|
)
|
|
11264
11461
|
|
|
@@ -11288,8 +11485,8 @@ export interface DateTimeUtcFromMillis extends decodeTo<instanceOf<DateTime.Utc>
|
|
|
11288
11485
|
*/
|
|
11289
11486
|
export const DateTimeUtcFromMillis: DateTimeUtcFromMillis = Number.pipe(
|
|
11290
11487
|
decodeTo(DateTimeUtc, {
|
|
11291
|
-
decode:
|
|
11292
|
-
encode:
|
|
11488
|
+
decode: SchemaGetter.dateTimeUtcFromInput(),
|
|
11489
|
+
encode: SchemaGetter.transform(DateTime.toEpochMillis)
|
|
11293
11490
|
})
|
|
11294
11491
|
)
|
|
11295
11492
|
|
|
@@ -11330,7 +11527,7 @@ export const TimeZoneOffset: TimeZoneOffset = declare(
|
|
|
11330
11527
|
toCodecJson: () =>
|
|
11331
11528
|
link<DateTime.TimeZone.Offset>()(
|
|
11332
11529
|
Number,
|
|
11333
|
-
|
|
11530
|
+
SchemaTransformation.timeZoneOffsetFromNumber
|
|
11334
11531
|
),
|
|
11335
11532
|
toArbitrary: () => (fc) =>
|
|
11336
11533
|
fc.integer({ min: -12 * 60 * 60 * 1000, max: 14 * 60 * 60 * 1000 }).map((n) => DateTime.zoneMakeOffset(n)),
|
|
@@ -11378,7 +11575,7 @@ export const TimeZoneNamed: TimeZoneNamed = declare(
|
|
|
11378
11575
|
toCodecJson: () =>
|
|
11379
11576
|
link<DateTime.TimeZone.Named>()(
|
|
11380
11577
|
TimeZoneNamedString,
|
|
11381
|
-
|
|
11578
|
+
SchemaTransformation.timeZoneNamedFromString
|
|
11382
11579
|
),
|
|
11383
11580
|
toArbitrary: () => (fc) =>
|
|
11384
11581
|
fc.constantFrom(
|
|
@@ -11416,7 +11613,7 @@ export interface TimeZoneNamedFromString extends decodeTo<TimeZoneNamed, String>
|
|
|
11416
11613
|
* @since 4.0.0
|
|
11417
11614
|
*/
|
|
11418
11615
|
export const TimeZoneNamedFromString: TimeZoneNamedFromString = TimeZoneNamedString.pipe(
|
|
11419
|
-
decodeTo(TimeZoneNamed,
|
|
11616
|
+
decodeTo(TimeZoneNamed, SchemaTransformation.timeZoneNamedFromString)
|
|
11420
11617
|
)
|
|
11421
11618
|
|
|
11422
11619
|
/**
|
|
@@ -11461,7 +11658,7 @@ export const TimeZone: TimeZone = declare(
|
|
|
11461
11658
|
toCodecJson: () =>
|
|
11462
11659
|
link<DateTime.TimeZone>()(
|
|
11463
11660
|
TimeZoneString,
|
|
11464
|
-
|
|
11661
|
+
SchemaTransformation.timeZoneFromString
|
|
11465
11662
|
),
|
|
11466
11663
|
toArbitrary: () => (fc) =>
|
|
11467
11664
|
fc.oneof(
|
|
@@ -11502,7 +11699,7 @@ export interface TimeZoneFromString extends decodeTo<TimeZone, String> {
|
|
|
11502
11699
|
* @since 4.0.0
|
|
11503
11700
|
*/
|
|
11504
11701
|
export const TimeZoneFromString: TimeZoneFromString = TimeZoneString.pipe(
|
|
11505
|
-
decodeTo(TimeZone,
|
|
11702
|
+
decodeTo(TimeZone, SchemaTransformation.timeZoneFromString)
|
|
11506
11703
|
)
|
|
11507
11704
|
|
|
11508
11705
|
/**
|
|
@@ -11549,7 +11746,7 @@ export const DateTimeZoned: DateTimeZoned = declare(
|
|
|
11549
11746
|
toCodecJson: () =>
|
|
11550
11747
|
link<DateTime.Zoned>()(
|
|
11551
11748
|
DateTimeZonedString,
|
|
11552
|
-
|
|
11749
|
+
SchemaTransformation.dateTimeZonedFromString
|
|
11553
11750
|
),
|
|
11554
11751
|
toArbitrary: () => (fc, ctx) =>
|
|
11555
11752
|
fc.tuple(
|
|
@@ -11591,7 +11788,7 @@ export interface DateTimeZonedFromString extends decodeTo<DateTimeZoned, String>
|
|
|
11591
11788
|
* @since 4.0.0
|
|
11592
11789
|
*/
|
|
11593
11790
|
export const DateTimeZonedFromString: DateTimeZonedFromString = DateTimeZonedString.pipe(
|
|
11594
|
-
decodeTo(DateTimeZoned,
|
|
11791
|
+
decodeTo(DateTimeZoned, SchemaTransformation.dateTimeZonedFromString)
|
|
11595
11792
|
)
|
|
11596
11793
|
|
|
11597
11794
|
// -----------------------------------------------------------------------------
|
|
@@ -11610,7 +11807,7 @@ export interface Class<Self, S extends Top & { readonly fields: Struct.Fields },
|
|
|
11610
11807
|
S["Encoded"],
|
|
11611
11808
|
S["DecodingServices"],
|
|
11612
11809
|
S["EncodingServices"],
|
|
11613
|
-
|
|
11810
|
+
SchemaAST.Declaration,
|
|
11614
11811
|
decodeTo<declareConstructor<Self, S["Encoded"], readonly [S], S["Iso"]>, S>,
|
|
11615
11812
|
RequiredKeys<S["~type.make.in"]> extends never ? void | S["~type.make.in"] : S["~type.make.in"],
|
|
11616
11813
|
S["Iso"],
|
|
@@ -11702,32 +11899,32 @@ function makeClass<
|
|
|
11702
11899
|
static readonly identifier = identifier
|
|
11703
11900
|
static readonly fields = struct.fields
|
|
11704
11901
|
|
|
11705
|
-
static get ast():
|
|
11902
|
+
static get ast(): SchemaAST.Declaration {
|
|
11706
11903
|
return getClassSchema(this).ast
|
|
11707
11904
|
}
|
|
11708
11905
|
static pipe() {
|
|
11709
11906
|
return Pipeable.pipeArguments(this, arguments)
|
|
11710
11907
|
}
|
|
11711
|
-
static rebuild(ast:
|
|
11908
|
+
static rebuild(ast: SchemaAST.Declaration) {
|
|
11712
11909
|
return getClassSchema(this).rebuild(ast)
|
|
11713
11910
|
}
|
|
11714
11911
|
static make(input: S["~type.make.in"], options?: MakeOptions): Self {
|
|
11715
11912
|
return new this(input, options)
|
|
11716
11913
|
}
|
|
11717
11914
|
static makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self> {
|
|
11718
|
-
return
|
|
11915
|
+
return SchemaParser.makeOption(getClassSchema(this) as any)(input ?? {}, options) as any
|
|
11719
11916
|
}
|
|
11720
11917
|
static makeEffect(input: S["~type.make.in"], options?: MakeOptions): Effect.Effect<Self, SchemaError> {
|
|
11721
11918
|
return (getClassSchema(this) as any).makeEffect(input ?? {}, options)
|
|
11722
11919
|
}
|
|
11723
11920
|
static annotate(annotations: Annotations.Declaration<Self, readonly [S]>) {
|
|
11724
|
-
return this.rebuild(
|
|
11921
|
+
return this.rebuild(SchemaAST.annotate(this.ast, annotations))
|
|
11725
11922
|
}
|
|
11726
11923
|
static annotateKey(annotations: Annotations.Key<Self>) {
|
|
11727
|
-
return this.rebuild(
|
|
11924
|
+
return this.rebuild(SchemaAST.annotateKey(this.ast, annotations))
|
|
11728
11925
|
}
|
|
11729
|
-
static check(...checks: readonly [
|
|
11730
|
-
return this.rebuild(
|
|
11926
|
+
static check(...checks: readonly [SchemaAST.Check<Self>, ...Array<SchemaAST.Check<Self>>]) {
|
|
11927
|
+
return this.rebuild(SchemaAST.appendChecks(this.ast, checks))
|
|
11731
11928
|
}
|
|
11732
11929
|
static extend<Extended>(
|
|
11733
11930
|
identifier: string
|
|
@@ -11740,7 +11937,7 @@ function makeClass<
|
|
|
11740
11937
|
return makeClass(
|
|
11741
11938
|
this,
|
|
11742
11939
|
identifier,
|
|
11743
|
-
makeStruct(
|
|
11940
|
+
makeStruct(SchemaAST.struct(fields, struct.ast.checks, { identifier }), fields),
|
|
11744
11941
|
annotations,
|
|
11745
11942
|
proto
|
|
11746
11943
|
)
|
|
@@ -11764,9 +11961,9 @@ function makeClass<
|
|
|
11764
11961
|
}
|
|
11765
11962
|
|
|
11766
11963
|
function getClassTransformation(self: new(...args: ReadonlyArray<any>) => any) {
|
|
11767
|
-
return new
|
|
11768
|
-
|
|
11769
|
-
|
|
11964
|
+
return new SchemaTransformation.Transformation<any, any, never, never>(
|
|
11965
|
+
SchemaGetter.transform((input) => new self(input)),
|
|
11966
|
+
SchemaGetter.passthrough()
|
|
11770
11967
|
)
|
|
11771
11968
|
}
|
|
11772
11969
|
|
|
@@ -11786,22 +11983,22 @@ function getClassSchemaFactory<S extends Top>(
|
|
|
11786
11983
|
if (memo === undefined) {
|
|
11787
11984
|
const transformation = getClassTransformation(self)
|
|
11788
11985
|
const to = make<declareConstructor<Self, S["Encoded"], readonly [S]>>(
|
|
11789
|
-
new
|
|
11986
|
+
new SchemaAST.Declaration(
|
|
11790
11987
|
[from.ast],
|
|
11791
11988
|
() => (input, ast) => {
|
|
11792
11989
|
return input instanceof self ||
|
|
11793
11990
|
Predicate.hasProperty(input, getClassTypeId(identifier)) ?
|
|
11794
11991
|
Effect.succeed(input) :
|
|
11795
|
-
Effect.fail(new
|
|
11992
|
+
Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
|
|
11796
11993
|
},
|
|
11797
11994
|
{
|
|
11798
11995
|
identifier,
|
|
11799
|
-
[
|
|
11800
|
-
toCodec: ([from]: readonly [Codec<S["Encoded"]>]) => new
|
|
11996
|
+
[SchemaAST.ClassTypeId]: ([from]: readonly [SchemaAST.AST]) => new SchemaAST.Link(from, transformation),
|
|
11997
|
+
toCodec: ([from]: readonly [Codec<S["Encoded"]>]) => new SchemaAST.Link(from.ast, transformation),
|
|
11801
11998
|
toArbitrary: ([from]: readonly [FastCheck.Arbitrary<S["Type"]>]) => () =>
|
|
11802
11999
|
from.map((args) => new self(args)),
|
|
11803
12000
|
toFormatter: ([from]: readonly [Formatter<S["Type"]>]) => (t: Self) => `${self.identifier}(${from(t)})`,
|
|
11804
|
-
"~sentinels":
|
|
12001
|
+
"~sentinels": SchemaAST.collectSentinels(from.ast),
|
|
11805
12002
|
...annotations
|
|
11806
12003
|
}
|
|
11807
12004
|
)
|
|
@@ -11826,9 +12023,8 @@ type MissingSelfGeneric<Usage extends string> =
|
|
|
11826
12023
|
*
|
|
11827
12024
|
* **When to use**
|
|
11828
12025
|
*
|
|
11829
|
-
* Use
|
|
11830
|
-
*
|
|
11831
|
-
* inheritance.
|
|
12026
|
+
* Use when you need a schema-backed data class with validated construction,
|
|
12027
|
+
* schema-derived decoding/encoding, and class-style methods or inheritance.
|
|
11832
12028
|
*
|
|
11833
12029
|
* **Details**
|
|
11834
12030
|
*
|
|
@@ -11887,9 +12083,8 @@ export const Class: {
|
|
|
11887
12083
|
*
|
|
11888
12084
|
* **When to use**
|
|
11889
12085
|
*
|
|
11890
|
-
* Use
|
|
11891
|
-
*
|
|
11892
|
-
* inheritance.
|
|
12086
|
+
* Use when you need a schema-backed data class with validated construction,
|
|
12087
|
+
* schema-derived decoding/encoding, and class-style methods or inheritance.
|
|
11893
12088
|
*
|
|
11894
12089
|
* **Details**
|
|
11895
12090
|
*
|
|
@@ -11948,9 +12143,8 @@ export const Class: {
|
|
|
11948
12143
|
*
|
|
11949
12144
|
* **When to use**
|
|
11950
12145
|
*
|
|
11951
|
-
* Use
|
|
11952
|
-
*
|
|
11953
|
-
* inheritance.
|
|
12146
|
+
* Use when you need a schema-backed data class with validated construction,
|
|
12147
|
+
* schema-derived decoding/encoding, and class-style methods or inheritance.
|
|
11954
12148
|
*
|
|
11955
12149
|
* **Details**
|
|
11956
12150
|
*
|
|
@@ -12012,9 +12206,8 @@ export const Class: {
|
|
|
12012
12206
|
*
|
|
12013
12207
|
* **When to use**
|
|
12014
12208
|
*
|
|
12015
|
-
* Use
|
|
12016
|
-
*
|
|
12017
|
-
* inheritance.
|
|
12209
|
+
* Use when you need a schema-backed data class with validated construction,
|
|
12210
|
+
* schema-derived decoding/encoding, and class-style methods or inheritance.
|
|
12018
12211
|
*
|
|
12019
12212
|
* **Details**
|
|
12020
12213
|
*
|
|
@@ -12595,18 +12788,18 @@ export function overrideToFormatter<S extends Top>(toFormatter: () => Formatter<
|
|
|
12595
12788
|
*/
|
|
12596
12789
|
export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
12597
12790
|
readonly onBefore?:
|
|
12598
|
-
| ((ast:
|
|
12791
|
+
| ((ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => Formatter<any>) => Formatter<any> | undefined)
|
|
12599
12792
|
| undefined
|
|
12600
12793
|
}): Formatter<T> {
|
|
12601
12794
|
return recur(schema.ast)
|
|
12602
12795
|
|
|
12603
|
-
function recur(ast:
|
|
12796
|
+
function recur(ast: SchemaAST.AST): Formatter<T> {
|
|
12604
12797
|
// ---------------------------------------------
|
|
12605
12798
|
// handle annotation
|
|
12606
12799
|
// ---------------------------------------------
|
|
12607
12800
|
const annotation = InternalAnnotations.resolve(ast)?.["toFormatter"]
|
|
12608
12801
|
if (typeof annotation === "function") {
|
|
12609
|
-
return annotation(
|
|
12802
|
+
return annotation(SchemaAST.isDeclaration(ast) ? ast.typeParameters.map(recur) : [])
|
|
12610
12803
|
}
|
|
12611
12804
|
// ---------------------------------------------
|
|
12612
12805
|
// handle onBefore
|
|
@@ -12623,7 +12816,7 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12623
12816
|
return on(ast)
|
|
12624
12817
|
}
|
|
12625
12818
|
|
|
12626
|
-
function on(ast:
|
|
12819
|
+
function on(ast: SchemaAST.AST): Formatter<any> {
|
|
12627
12820
|
switch (ast._tag) {
|
|
12628
12821
|
default:
|
|
12629
12822
|
return format
|
|
@@ -12642,7 +12835,7 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12642
12835
|
// ---------------------------------------------
|
|
12643
12836
|
for (; i < elements.length; i++) {
|
|
12644
12837
|
if (t.length < i + 1) {
|
|
12645
|
-
if (
|
|
12838
|
+
if (SchemaAST.isOptional(ast.elements[i])) {
|
|
12646
12839
|
continue
|
|
12647
12840
|
}
|
|
12648
12841
|
} else {
|
|
@@ -12685,7 +12878,7 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12685
12878
|
const ps = ast.propertySignatures[i]
|
|
12686
12879
|
const name = ps.name
|
|
12687
12880
|
visited.add(name)
|
|
12688
|
-
if (
|
|
12881
|
+
if (SchemaAST.isOptional(ps.type) && !Object.hasOwn(t, name)) {
|
|
12689
12882
|
continue
|
|
12690
12883
|
}
|
|
12691
12884
|
out.push(`${formatPropertyKey(name)}: ${propertySignatures[i](t[name])}`)
|
|
@@ -12694,7 +12887,7 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12694
12887
|
// handle index signatures
|
|
12695
12888
|
// ---------------------------------------------
|
|
12696
12889
|
for (let i = 0; i < indexSignatures.length; i++) {
|
|
12697
|
-
const keys =
|
|
12890
|
+
const keys = SchemaAST.getIndexSignatureKeys(t, ast.indexSignatures[i].parameter)
|
|
12698
12891
|
for (const key of keys) {
|
|
12699
12892
|
if (visited.has(key)) {
|
|
12700
12893
|
continue
|
|
@@ -12708,10 +12901,10 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12708
12901
|
}
|
|
12709
12902
|
}
|
|
12710
12903
|
case "Union": {
|
|
12711
|
-
const getCandidates = (t: any) =>
|
|
12904
|
+
const getCandidates = (t: any) => SchemaAST.getCandidates(t, ast.types)
|
|
12712
12905
|
return (t) => {
|
|
12713
12906
|
const candidates = getCandidates(t)
|
|
12714
|
-
const refinements = candidates.map(
|
|
12907
|
+
const refinements = candidates.map(SchemaParser._is)
|
|
12715
12908
|
for (let i = 0; i < candidates.length; i++) {
|
|
12716
12909
|
const is = refinements[i]
|
|
12717
12910
|
if (is(t)) {
|
|
@@ -12722,7 +12915,7 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12722
12915
|
}
|
|
12723
12916
|
}
|
|
12724
12917
|
case "Suspend": {
|
|
12725
|
-
const get =
|
|
12918
|
+
const get = SchemaAST.memoizeThunk(() => recur(ast.thunk()))
|
|
12726
12919
|
return (t) => get()(t)
|
|
12727
12920
|
}
|
|
12728
12921
|
}
|
|
@@ -12739,8 +12932,8 @@ export function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
12739
12932
|
*
|
|
12740
12933
|
* **When to use**
|
|
12741
12934
|
*
|
|
12742
|
-
* Use when
|
|
12743
|
-
*
|
|
12935
|
+
* Use when you need a custom equivalence instead of the default structural
|
|
12936
|
+
* equivalence derived by {@link toEquivalence}.
|
|
12744
12937
|
*
|
|
12745
12938
|
* @category instances
|
|
12746
12939
|
* @since 4.0.0
|
|
@@ -12903,28 +13096,28 @@ export function toCodecJson<T, E, RD, RE>(schema: Codec<T, E, RD, RE>): Codec<T,
|
|
|
12903
13096
|
return make(toCodecJsonTop(schema.ast))
|
|
12904
13097
|
}
|
|
12905
13098
|
|
|
12906
|
-
const toCodecJsonTop =
|
|
13099
|
+
const toCodecJsonTop = SchemaAST.toCodec((ast) => {
|
|
12907
13100
|
const out = toCodecJsonBase(ast, toCodecJsonTop)
|
|
12908
|
-
return out !== ast &&
|
|
13101
|
+
return out !== ast && SchemaAST.isOptional(ast) ? SchemaAST.optionalKeyLastLink(out) : out
|
|
12909
13102
|
})
|
|
12910
13103
|
|
|
12911
|
-
function toCodecJsonBase(ast:
|
|
13104
|
+
function toCodecJsonBase(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
|
|
12912
13105
|
switch (ast._tag) {
|
|
12913
13106
|
case "Declaration": {
|
|
12914
13107
|
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec
|
|
12915
13108
|
if (Predicate.isFunction(getLink)) {
|
|
12916
|
-
const tps =
|
|
12917
|
-
? ast.typeParameters.map((tp) => InternalSchema.make(
|
|
13109
|
+
const tps = SchemaAST.isDeclaration(ast)
|
|
13110
|
+
? ast.typeParameters.map((tp) => InternalSchema.make(SchemaAST.toEncoded(tp)))
|
|
12918
13111
|
: []
|
|
12919
13112
|
const link = getLink(tps)
|
|
12920
13113
|
const to = recur(link.to)
|
|
12921
|
-
return
|
|
13114
|
+
return SchemaAST.replaceEncoding(ast, to === link.to ? [link] : [new SchemaAST.Link(to, link.transformation)])
|
|
12922
13115
|
}
|
|
12923
|
-
return
|
|
13116
|
+
return SchemaAST.replaceEncoding(ast, [SchemaAST.unknownToNull])
|
|
12924
13117
|
}
|
|
12925
13118
|
case "Unknown":
|
|
12926
13119
|
case "ObjectKeyword":
|
|
12927
|
-
return
|
|
13120
|
+
return SchemaAST.replaceEncoding(ast, [SchemaAST.unknownToJson])
|
|
12928
13121
|
case "Undefined":
|
|
12929
13122
|
case "Void":
|
|
12930
13123
|
case "Literal":
|
|
@@ -12943,7 +13136,7 @@ function toCodecJsonBase(ast: AST.AST, recur: (ast: AST.AST) => AST.AST): AST.AS
|
|
|
12943
13136
|
case "Union": {
|
|
12944
13137
|
const sortedTypes = InternalSchema.jsonReorder(ast.types)
|
|
12945
13138
|
if (sortedTypes !== ast.types) {
|
|
12946
|
-
return new
|
|
13139
|
+
return new SchemaAST.Union(
|
|
12947
13140
|
sortedTypes,
|
|
12948
13141
|
ast.mode,
|
|
12949
13142
|
ast.annotations,
|
|
@@ -12970,22 +13163,22 @@ function toCodecJsonBase(ast: AST.AST, recur: (ast: AST.AST) => AST.AST): AST.AS
|
|
|
12970
13163
|
* @since 4.0.0
|
|
12971
13164
|
*/
|
|
12972
13165
|
export function toCodecIso<S extends Top>(schema: S): Codec<S["Type"], S["Iso"]> {
|
|
12973
|
-
return make(toCodecIsoTop(
|
|
13166
|
+
return make(toCodecIsoTop(SchemaAST.toType(schema.ast)))
|
|
12974
13167
|
}
|
|
12975
13168
|
|
|
12976
|
-
const toCodecIsoTop = memoize((ast:
|
|
13169
|
+
const toCodecIsoTop = memoize((ast: SchemaAST.AST): SchemaAST.AST => {
|
|
12977
13170
|
const out = toCodecIsoBase(ast, toCodecIsoTop)
|
|
12978
|
-
return out !== ast &&
|
|
13171
|
+
return out !== ast && SchemaAST.isOptional(ast) ? SchemaAST.optionalKeyLastLink(out) : out
|
|
12979
13172
|
})
|
|
12980
13173
|
|
|
12981
|
-
function toCodecIsoBase(ast:
|
|
13174
|
+
function toCodecIsoBase(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
|
|
12982
13175
|
switch (ast._tag) {
|
|
12983
13176
|
case "Declaration": {
|
|
12984
13177
|
const getLink = ast.annotations?.toCodecIso ?? ast.annotations?.toCodec
|
|
12985
13178
|
if (Predicate.isFunction(getLink)) {
|
|
12986
13179
|
const link = getLink(ast.typeParameters.map((tp) => InternalSchema.make(tp)))
|
|
12987
13180
|
const to = recur(link.to)
|
|
12988
|
-
return
|
|
13181
|
+
return SchemaAST.replaceEncoding(ast, to === link.to ? [link] : [new SchemaAST.Link(to, link.transformation)])
|
|
12989
13182
|
}
|
|
12990
13183
|
return ast
|
|
12991
13184
|
}
|
|
@@ -13165,7 +13358,7 @@ const xml = {
|
|
|
13165
13358
|
}
|
|
13166
13359
|
}
|
|
13167
13360
|
|
|
13168
|
-
function getStringTreePriority(ast:
|
|
13361
|
+
function getStringTreePriority(ast: SchemaAST.AST): number {
|
|
13169
13362
|
switch (ast._tag) {
|
|
13170
13363
|
case "Null":
|
|
13171
13364
|
case "Boolean":
|
|
@@ -13182,30 +13375,30 @@ function getStringTreePriority(ast: AST.AST): number {
|
|
|
13182
13375
|
const treeReorder = InternalSchema.makeReorder(getStringTreePriority)
|
|
13183
13376
|
|
|
13184
13377
|
function serializerTree(
|
|
13185
|
-
ast:
|
|
13186
|
-
recur: (ast:
|
|
13187
|
-
onMissingAnnotation: (ast:
|
|
13188
|
-
):
|
|
13378
|
+
ast: SchemaAST.AST,
|
|
13379
|
+
recur: (ast: SchemaAST.AST) => SchemaAST.AST,
|
|
13380
|
+
onMissingAnnotation: (ast: SchemaAST.AST) => SchemaAST.AST
|
|
13381
|
+
): SchemaAST.AST {
|
|
13189
13382
|
switch (ast._tag) {
|
|
13190
13383
|
case "Declaration": {
|
|
13191
13384
|
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec
|
|
13192
13385
|
if (Predicate.isFunction(getLink)) {
|
|
13193
|
-
const tps =
|
|
13194
|
-
? ast.typeParameters.map((tp) => make(recur(
|
|
13386
|
+
const tps = SchemaAST.isDeclaration(ast)
|
|
13387
|
+
? ast.typeParameters.map((tp) => make(recur(SchemaAST.toEncoded(tp))))
|
|
13195
13388
|
: []
|
|
13196
13389
|
const link = getLink(tps)
|
|
13197
13390
|
const to = recur(link.to)
|
|
13198
|
-
return
|
|
13391
|
+
return SchemaAST.replaceEncoding(ast, to === link.to ? [link] : [new SchemaAST.Link(to, link.transformation)])
|
|
13199
13392
|
}
|
|
13200
13393
|
return onMissingAnnotation(ast)
|
|
13201
13394
|
}
|
|
13202
13395
|
case "Null":
|
|
13203
|
-
return
|
|
13396
|
+
return SchemaAST.replaceEncoding(ast, [nullToString])
|
|
13204
13397
|
case "Boolean":
|
|
13205
|
-
return
|
|
13398
|
+
return SchemaAST.replaceEncoding(ast, [booleanToString])
|
|
13206
13399
|
case "Unknown":
|
|
13207
13400
|
case "ObjectKeyword":
|
|
13208
|
-
return
|
|
13401
|
+
return SchemaAST.replaceEncoding(ast, [SchemaAST.unknownToStringTree])
|
|
13209
13402
|
case "Enum":
|
|
13210
13403
|
case "Number":
|
|
13211
13404
|
case "Literal":
|
|
@@ -13222,7 +13415,7 @@ function serializerTree(
|
|
|
13222
13415
|
case "Union": {
|
|
13223
13416
|
const sortedTypes = treeReorder(ast.types)
|
|
13224
13417
|
if (sortedTypes !== ast.types) {
|
|
13225
|
-
return new
|
|
13418
|
+
return new SchemaAST.Union(
|
|
13226
13419
|
sortedTypes,
|
|
13227
13420
|
ast.mode,
|
|
13228
13421
|
ast.annotations,
|
|
@@ -13241,75 +13434,75 @@ function serializerTree(
|
|
|
13241
13434
|
return ast
|
|
13242
13435
|
}
|
|
13243
13436
|
|
|
13244
|
-
const nullToString = new
|
|
13245
|
-
new
|
|
13246
|
-
new
|
|
13247
|
-
|
|
13248
|
-
|
|
13437
|
+
const nullToString = new SchemaAST.Link(
|
|
13438
|
+
new SchemaAST.Literal("null"),
|
|
13439
|
+
new SchemaTransformation.Transformation(
|
|
13440
|
+
SchemaGetter.transform(() => null),
|
|
13441
|
+
SchemaGetter.transform(() => "null")
|
|
13249
13442
|
)
|
|
13250
13443
|
)
|
|
13251
13444
|
|
|
13252
|
-
const booleanToString = new
|
|
13253
|
-
new
|
|
13254
|
-
new
|
|
13255
|
-
|
|
13256
|
-
|
|
13445
|
+
const booleanToString = new SchemaAST.Link(
|
|
13446
|
+
new SchemaAST.Union([new SchemaAST.Literal("true"), new SchemaAST.Literal("false")], "anyOf"),
|
|
13447
|
+
new SchemaTransformation.Transformation(
|
|
13448
|
+
SchemaGetter.transform((s) => s === "true"),
|
|
13449
|
+
SchemaGetter.String()
|
|
13257
13450
|
)
|
|
13258
13451
|
)
|
|
13259
13452
|
|
|
13260
|
-
const serializerStringTree =
|
|
13261
|
-
const out = serializerTree(ast, serializerStringTree, (ast) =>
|
|
13262
|
-
if (out !== ast &&
|
|
13263
|
-
return
|
|
13453
|
+
const serializerStringTree = SchemaAST.toCodec((ast) => {
|
|
13454
|
+
const out = serializerTree(ast, serializerStringTree, (ast) => SchemaAST.replaceEncoding(ast, [unknownToUndefined]))
|
|
13455
|
+
if (out !== ast && SchemaAST.isOptional(ast)) {
|
|
13456
|
+
return SchemaAST.optionalKeyLastLink(out)
|
|
13264
13457
|
}
|
|
13265
13458
|
return out
|
|
13266
13459
|
})
|
|
13267
13460
|
|
|
13268
|
-
const unknownToUndefined = new
|
|
13269
|
-
|
|
13270
|
-
new
|
|
13271
|
-
|
|
13272
|
-
|
|
13461
|
+
const unknownToUndefined = new SchemaAST.Link(
|
|
13462
|
+
SchemaAST.undefined,
|
|
13463
|
+
new SchemaTransformation.Transformation(
|
|
13464
|
+
SchemaGetter.passthrough(),
|
|
13465
|
+
SchemaGetter.transform(() => undefined)
|
|
13273
13466
|
)
|
|
13274
13467
|
)
|
|
13275
13468
|
|
|
13276
|
-
const serializerStringTreeKeepDeclarations =
|
|
13469
|
+
const serializerStringTreeKeepDeclarations = SchemaAST.toCodec((ast) => {
|
|
13277
13470
|
const out = serializerTree(ast, serializerStringTreeKeepDeclarations, identity)
|
|
13278
|
-
if (out !== ast &&
|
|
13279
|
-
return
|
|
13471
|
+
if (out !== ast && SchemaAST.isOptional(ast)) {
|
|
13472
|
+
return SchemaAST.optionalKeyLastLink(out)
|
|
13280
13473
|
}
|
|
13281
13474
|
return out
|
|
13282
13475
|
})
|
|
13283
13476
|
|
|
13284
13477
|
const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY"
|
|
13285
13478
|
|
|
13286
|
-
const toCodecEnsureArray =
|
|
13287
|
-
if (
|
|
13479
|
+
const toCodecEnsureArray = SchemaAST.toCodec((ast) => {
|
|
13480
|
+
if (SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY]) {
|
|
13288
13481
|
return ast
|
|
13289
13482
|
}
|
|
13290
13483
|
const out = onSerializerEnsureArray(ast)
|
|
13291
|
-
if (
|
|
13292
|
-
const ensure = new
|
|
13484
|
+
if (SchemaAST.isArrays(out)) {
|
|
13485
|
+
const ensure = new SchemaAST.Union(
|
|
13293
13486
|
[
|
|
13294
13487
|
out,
|
|
13295
|
-
|
|
13296
|
-
|
|
13488
|
+
SchemaAST.decodeTo(
|
|
13489
|
+
SchemaAST.string,
|
|
13297
13490
|
out,
|
|
13298
|
-
new
|
|
13299
|
-
|
|
13300
|
-
|
|
13491
|
+
new SchemaTransformation.Transformation(
|
|
13492
|
+
SchemaGetter.split(),
|
|
13493
|
+
SchemaGetter.passthrough()
|
|
13301
13494
|
)
|
|
13302
13495
|
)
|
|
13303
13496
|
],
|
|
13304
13497
|
"anyOf",
|
|
13305
13498
|
{ [SERIALIZER_ENSURE_ARRAY]: true }
|
|
13306
13499
|
)
|
|
13307
|
-
return
|
|
13500
|
+
return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure
|
|
13308
13501
|
}
|
|
13309
13502
|
return out
|
|
13310
13503
|
})
|
|
13311
13504
|
|
|
13312
|
-
function onSerializerEnsureArray(ast:
|
|
13505
|
+
function onSerializerEnsureArray(ast: SchemaAST.AST): SchemaAST.AST {
|
|
13313
13506
|
switch (ast._tag) {
|
|
13314
13507
|
default:
|
|
13315
13508
|
return ast
|
|
@@ -13335,7 +13528,7 @@ function onSerializerEnsureArray(ast: AST.AST): AST.AST {
|
|
|
13335
13528
|
*/
|
|
13336
13529
|
export function toIso<S extends Top>(schema: S): Optic_.Iso<S["Type"], S["Iso"]> {
|
|
13337
13530
|
const serializer = toCodecIso(schema)
|
|
13338
|
-
return Optic_.makeIso(
|
|
13531
|
+
return Optic_.makeIso(SchemaParser.encodeSync(serializer), SchemaParser.decodeSync(serializer))
|
|
13339
13532
|
}
|
|
13340
13533
|
|
|
13341
13534
|
/**
|
|
@@ -13406,14 +13599,14 @@ export interface overrideToCodecIso<S extends Top, Iso> extends
|
|
|
13406
13599
|
export function overrideToCodecIso<S extends Top, Iso>(
|
|
13407
13600
|
to: Codec<Iso>,
|
|
13408
13601
|
transformation: {
|
|
13409
|
-
readonly decode:
|
|
13410
|
-
readonly encode:
|
|
13602
|
+
readonly decode: SchemaGetter.Getter<S["Type"], Iso>
|
|
13603
|
+
readonly encode: SchemaGetter.Getter<Iso, S["Type"]>
|
|
13411
13604
|
}
|
|
13412
13605
|
) {
|
|
13413
13606
|
return (schema: S): overrideToCodecIso<S, Iso> => {
|
|
13414
13607
|
return make(
|
|
13415
|
-
|
|
13416
|
-
toCodecIso: () => new
|
|
13608
|
+
SchemaAST.annotate(schema.ast, {
|
|
13609
|
+
toCodecIso: () => new SchemaAST.Link(to.ast, SchemaTransformation.make(transformation))
|
|
13417
13610
|
}),
|
|
13418
13611
|
{ schema }
|
|
13419
13612
|
)
|
|
@@ -13434,8 +13627,8 @@ export function overrideToCodecIso<S extends Top, Iso>(
|
|
|
13434
13627
|
*/
|
|
13435
13628
|
export function toDifferJsonPatch<T, E>(schema: Codec<T, E>): Differ<T, JsonPatch.JsonPatch> {
|
|
13436
13629
|
const serializer = toCodecJson(schema)
|
|
13437
|
-
const get =
|
|
13438
|
-
const set =
|
|
13630
|
+
const get = SchemaParser.encodeSync(serializer)
|
|
13631
|
+
const set = SchemaParser.decodeSync(serializer)
|
|
13439
13632
|
return {
|
|
13440
13633
|
empty: [],
|
|
13441
13634
|
diff: (oldValue, newValue) => JsonPatch.get(get(oldValue), get(newValue)),
|
|
@@ -13535,7 +13728,7 @@ export interface JsonObject {
|
|
|
13535
13728
|
* @category schemas
|
|
13536
13729
|
* @since 4.0.0
|
|
13537
13730
|
*/
|
|
13538
|
-
export const Json: Codec<Json> = make(
|
|
13731
|
+
export const Json: Codec<Json> = make(SchemaAST.Json)
|
|
13539
13732
|
|
|
13540
13733
|
/**
|
|
13541
13734
|
* Recursive TypeScript type for mutable JSON values: `null`, `number`,
|
|
@@ -13571,7 +13764,7 @@ export interface MutableJsonObject {
|
|
|
13571
13764
|
* @category schemas
|
|
13572
13765
|
* @since 4.0.0
|
|
13573
13766
|
*/
|
|
13574
|
-
export const MutableJson: Codec<MutableJson> = make(
|
|
13767
|
+
export const MutableJson: Codec<MutableJson> = make(SchemaAST.MutableJson)
|
|
13575
13768
|
|
|
13576
13769
|
// -----------------------------------------------------------------------------
|
|
13577
13770
|
// Annotations
|
|
@@ -13761,7 +13954,7 @@ export declare namespace Annotations {
|
|
|
13761
13954
|
* filter/refinement instead.
|
|
13762
13955
|
*/
|
|
13763
13956
|
readonly identifier?: string | undefined
|
|
13764
|
-
readonly parseOptions?:
|
|
13957
|
+
readonly parseOptions?: SchemaAST.ParseOptions | undefined
|
|
13765
13958
|
/**
|
|
13766
13959
|
* Optional metadata used to identify or extend the filter with custom data.
|
|
13767
13960
|
*/
|
|
@@ -13817,19 +14010,20 @@ export declare namespace Annotations {
|
|
|
13817
14010
|
extends Bottom<T, TypeParameters>
|
|
13818
14011
|
{
|
|
13819
14012
|
readonly toCodec?:
|
|
13820
|
-
| ((typeParameters: TypeParameters.Encoded<TypeParameters>) =>
|
|
14013
|
+
| ((typeParameters: TypeParameters.Encoded<TypeParameters>) => SchemaAST.Link)
|
|
13821
14014
|
| undefined
|
|
13822
14015
|
readonly toCodecJson?:
|
|
13823
|
-
| ((typeParameters: TypeParameters.Encoded<TypeParameters>) =>
|
|
14016
|
+
| ((typeParameters: TypeParameters.Encoded<TypeParameters>) => SchemaAST.Link)
|
|
13824
14017
|
| undefined
|
|
13825
14018
|
readonly toCodecIso?:
|
|
13826
|
-
| ((typeParameters: TypeParameters.Type<TypeParameters>) =>
|
|
14019
|
+
| ((typeParameters: TypeParameters.Type<TypeParameters>) => SchemaAST.Link)
|
|
13827
14020
|
| undefined
|
|
13828
14021
|
readonly toArbitrary?: ToArbitrary.Declaration<T, TypeParameters> | undefined
|
|
13829
14022
|
readonly toEquivalence?: ToEquivalence.Declaration<T, TypeParameters> | undefined
|
|
13830
14023
|
readonly toFormatter?: ToFormatter.Declaration<T, TypeParameters> | undefined
|
|
13831
14024
|
readonly typeConstructor?: {
|
|
13832
14025
|
readonly _tag: string
|
|
14026
|
+
readonly [key: string]: unknown
|
|
13833
14027
|
} | undefined
|
|
13834
14028
|
readonly generation?: {
|
|
13835
14029
|
readonly runtime: string
|
|
@@ -13838,11 +14032,11 @@ export declare namespace Annotations {
|
|
|
13838
14032
|
readonly importDeclaration?: string | undefined
|
|
13839
14033
|
} | undefined
|
|
13840
14034
|
/**
|
|
13841
|
-
* Used to collect sentinels from a Declaration
|
|
14035
|
+
* Used to collect sentinels from a Declaration SchemaAST.
|
|
13842
14036
|
*
|
|
13843
14037
|
* @internal
|
|
13844
14038
|
*/
|
|
13845
|
-
readonly "~sentinels"?: ReadonlyArray<
|
|
14039
|
+
readonly "~sentinels"?: ReadonlyArray<SchemaAST.Sentinel> | undefined
|
|
13846
14040
|
}
|
|
13847
14041
|
|
|
13848
14042
|
/**
|
|
@@ -14262,7 +14456,7 @@ export declare namespace Annotations {
|
|
|
14262
14456
|
}
|
|
14263
14457
|
readonly isPropertyNames: {
|
|
14264
14458
|
readonly _tag: "isPropertyNames"
|
|
14265
|
-
readonly propertyNames:
|
|
14459
|
+
readonly propertyNames: SchemaAST.AST
|
|
14266
14460
|
}
|
|
14267
14461
|
// Arrays Meta
|
|
14268
14462
|
readonly isUnique: {
|