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/dist/Schema.js
CHANGED
|
@@ -118,11 +118,11 @@ import * as Record_ from "./Record.js";
|
|
|
118
118
|
import * as Redacted_ from "./Redacted.js";
|
|
119
119
|
import * as Result_ from "./Result.js";
|
|
120
120
|
import * as Scheduler from "./Scheduler.js";
|
|
121
|
-
import * as
|
|
122
|
-
import * as
|
|
123
|
-
import * as
|
|
124
|
-
import * as
|
|
125
|
-
import * as
|
|
121
|
+
import * as SchemaAST from "./SchemaAST.js";
|
|
122
|
+
import * as SchemaGetter from "./SchemaGetter.js";
|
|
123
|
+
import * as SchemaIssue from "./SchemaIssue.js";
|
|
124
|
+
import * as SchemaParser from "./SchemaParser.js";
|
|
125
|
+
import * as SchemaTransformation from "./SchemaTransformation.js";
|
|
126
126
|
import * as Struct_ from "./Struct.js";
|
|
127
127
|
import * as FastCheck from "./testing/FastCheck.js";
|
|
128
128
|
const TypeId = InternalSchema.TypeId;
|
|
@@ -131,6 +131,11 @@ const TypeId = InternalSchema.TypeId;
|
|
|
131
131
|
* `Array<A>`, `Option<A>`, etc.) by accepting a list of type-parameter schemas
|
|
132
132
|
* and a decoder factory.
|
|
133
133
|
*
|
|
134
|
+
* **When to use**
|
|
135
|
+
*
|
|
136
|
+
* Use when you are defining a schema for a generic container whose validation
|
|
137
|
+
* depends on one or more type-parameter schemas.
|
|
138
|
+
*
|
|
134
139
|
* **Details**
|
|
135
140
|
*
|
|
136
141
|
* The outer call `declareConstructor<T, E, Iso>()` fixes the decoded type `T`,
|
|
@@ -160,7 +165,7 @@ const TypeId = InternalSchema.TypeId;
|
|
|
160
165
|
* ([itemCodec]) =>
|
|
161
166
|
* (u, ast, options) => {
|
|
162
167
|
* if (!isBox(u)) {
|
|
163
|
-
* return Effect.fail(new
|
|
168
|
+
* return Effect.fail(new SchemaIssue.InvalidType(ast, Option.some(u)))
|
|
164
169
|
* }
|
|
165
170
|
* return Effect.map(
|
|
166
171
|
* SchemaParser.decodeUnknownEffect(itemCodec)(u.value, options),
|
|
@@ -177,7 +182,7 @@ const TypeId = InternalSchema.TypeId;
|
|
|
177
182
|
*/
|
|
178
183
|
export function declareConstructor() {
|
|
179
184
|
return (typeParameters, run, annotations) => {
|
|
180
|
-
return make(new
|
|
185
|
+
return make(new SchemaAST.Declaration(typeParameters.map(SchemaAST.getAST), typeParameters => run(typeParameters.map(ast => make(ast))), annotations));
|
|
181
186
|
};
|
|
182
187
|
}
|
|
183
188
|
/**
|
|
@@ -185,10 +190,10 @@ export function declareConstructor() {
|
|
|
185
190
|
* function. The schema accepts any unknown value and succeeds when `is` returns
|
|
186
191
|
* `true`, failing with an `InvalidType` issue otherwise.
|
|
187
192
|
*
|
|
188
|
-
* **
|
|
193
|
+
* **When to use**
|
|
189
194
|
*
|
|
190
|
-
* Use
|
|
191
|
-
*
|
|
195
|
+
* Use when you are defining a schema for an opaque type with no type parameters
|
|
196
|
+
* and validation can be expressed as a type guard.
|
|
192
197
|
*
|
|
193
198
|
* **Example** (Schema for a custom `UserId` branded type)
|
|
194
199
|
*
|
|
@@ -212,7 +217,7 @@ export function declareConstructor() {
|
|
|
212
217
|
* @since 3.10.0
|
|
213
218
|
*/
|
|
214
219
|
export function declare(is, annotations) {
|
|
215
|
-
return declareConstructor()([], () => (input, ast) => is(input) ? Effect.succeed(input) : Effect.fail(new
|
|
220
|
+
return declareConstructor()([], () => (input, ast) => is(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input))), annotations);
|
|
216
221
|
}
|
|
217
222
|
/**
|
|
218
223
|
* Returns a schema widened to the fully-parameterized {@link Bottom} interface,
|
|
@@ -342,7 +347,7 @@ export function annotateEncoded(annotations) {
|
|
|
342
347
|
*/
|
|
343
348
|
export function annotateKey(annotations) {
|
|
344
349
|
return self => {
|
|
345
|
-
return self.rebuild(
|
|
350
|
+
return self.rebuild(SchemaAST.annotateKey(self.ast, annotations));
|
|
346
351
|
};
|
|
347
352
|
}
|
|
348
353
|
/**
|
|
@@ -380,7 +385,7 @@ export {
|
|
|
380
385
|
*
|
|
381
386
|
* **Details**
|
|
382
387
|
*
|
|
383
|
-
* The `issue` field contains a structured {@link
|
|
388
|
+
* The `issue` field contains a structured {@link SchemaIssue.Issue} tree describing
|
|
384
389
|
* every validation failure, including the path to the problematic value,
|
|
385
390
|
* expected types, and actual values received. `message` renders the issue tree
|
|
386
391
|
* as a human-readable string.
|
|
@@ -500,12 +505,12 @@ function makeStandardResult(exit) {
|
|
|
500
505
|
* @since 4.0.0
|
|
501
506
|
*/
|
|
502
507
|
export function toStandardSchemaV1(self, options) {
|
|
503
|
-
const decodeUnknownEffect =
|
|
508
|
+
const decodeUnknownEffect = SchemaParser.decodeUnknownEffect(self);
|
|
504
509
|
const parseOptions = {
|
|
505
510
|
errors: "all",
|
|
506
511
|
...options?.parseOptions
|
|
507
512
|
};
|
|
508
|
-
const formatter =
|
|
513
|
+
const formatter = SchemaIssue.makeFormatterStandardSchemaV1(options);
|
|
509
514
|
const validate = value => {
|
|
510
515
|
const scheduler = new Scheduler.MixedScheduler();
|
|
511
516
|
const fiber = Effect.runFork(Effect.match(decodeUnknownEffect(value, parseOptions), {
|
|
@@ -629,7 +634,7 @@ export function toStandardJSONSchemaV1(self) {
|
|
|
629
634
|
* @category guards
|
|
630
635
|
* @since 3.10.0
|
|
631
636
|
*/
|
|
632
|
-
export const is =
|
|
637
|
+
export const is = SchemaParser.is;
|
|
633
638
|
/**
|
|
634
639
|
* Creates an assertion function that throws an error if the input doesn't match
|
|
635
640
|
* the schema.
|
|
@@ -637,7 +642,7 @@ export const is = Parser.is;
|
|
|
637
642
|
* **When to use**
|
|
638
643
|
*
|
|
639
644
|
* Use to validate unknown input at runtime while narrowing the value with a
|
|
640
|
-
* TypeScript
|
|
645
|
+
* TypeScript assertion signature.
|
|
641
646
|
*
|
|
642
647
|
* **Details**
|
|
643
648
|
*
|
|
@@ -667,14 +672,15 @@ export const is = Parser.is;
|
|
|
667
672
|
* @category guards
|
|
668
673
|
* @since 4.0.0
|
|
669
674
|
*/
|
|
670
|
-
export const asserts =
|
|
675
|
+
export const asserts = SchemaParser.asserts;
|
|
671
676
|
/**
|
|
672
677
|
* Decodes an `unknown` input against a schema, returning an `Effect` that
|
|
673
678
|
* succeeds with the decoded value or fails with a {@link SchemaError}.
|
|
674
679
|
*
|
|
675
680
|
* **When to use**
|
|
676
681
|
*
|
|
677
|
-
* Use when
|
|
682
|
+
* Use when you need to decode unknown input in an `Effect` whose failure
|
|
683
|
+
* channel is `SchemaError`.
|
|
678
684
|
*
|
|
679
685
|
* **Details**
|
|
680
686
|
*
|
|
@@ -683,11 +689,13 @@ export const asserts = Parser.asserts;
|
|
|
683
689
|
* Options may be provided either when creating the decoder or when applying it;
|
|
684
690
|
* application options override creation options.
|
|
685
691
|
*
|
|
692
|
+
* @see {@link SchemaParser.decodeUnknownEffect} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
693
|
+
*
|
|
686
694
|
* @category decoding
|
|
687
695
|
* @since 4.0.0
|
|
688
696
|
*/
|
|
689
697
|
export function decodeUnknownEffect(schema, options) {
|
|
690
|
-
const parser =
|
|
698
|
+
const parser = SchemaParser.decodeUnknownEffect(schema, options);
|
|
691
699
|
return (input, options) => {
|
|
692
700
|
return Effect.mapErrorEager(parser(input, options), issue => new SchemaError(issue));
|
|
693
701
|
};
|
|
@@ -699,7 +707,8 @@ export function decodeUnknownEffect(schema, options) {
|
|
|
699
707
|
*
|
|
700
708
|
* **When to use**
|
|
701
709
|
*
|
|
702
|
-
* Use when
|
|
710
|
+
* Use when you need to decode input already typed as the schema's `Encoded`
|
|
711
|
+
* type in an `Effect` whose failure channel is `SchemaError`.
|
|
703
712
|
*
|
|
704
713
|
* **Details**
|
|
705
714
|
*
|
|
@@ -707,6 +716,8 @@ export function decodeUnknownEffect(schema, options) {
|
|
|
707
716
|
* Options may be provided either when creating the decoder or when applying it;
|
|
708
717
|
* application options override creation options.
|
|
709
718
|
*
|
|
719
|
+
* @see {@link SchemaParser.decodeEffect} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
720
|
+
*
|
|
710
721
|
* @category decoding
|
|
711
722
|
* @since 4.0.0
|
|
712
723
|
*/
|
|
@@ -718,8 +729,8 @@ export const decodeEffect = decodeUnknownEffect;
|
|
|
718
729
|
*
|
|
719
730
|
* **When to use**
|
|
720
731
|
*
|
|
721
|
-
* Use when
|
|
722
|
-
* `
|
|
732
|
+
* Use when you need to decode unknown input into an `Exit` whose failure
|
|
733
|
+
* contains `SchemaError`.
|
|
723
734
|
*
|
|
724
735
|
* **Details**
|
|
725
736
|
*
|
|
@@ -729,11 +740,13 @@ export const decodeEffect = decodeUnknownEffect;
|
|
|
729
740
|
* Options may be provided either when creating the decoder or when applying it;
|
|
730
741
|
* application options override creation options.
|
|
731
742
|
*
|
|
743
|
+
* @see {@link SchemaParser.decodeUnknownExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
744
|
+
*
|
|
732
745
|
* @category decoding
|
|
733
746
|
* @since 4.0.0
|
|
734
747
|
*/
|
|
735
748
|
export function decodeUnknownExit(schema, options) {
|
|
736
|
-
const parser =
|
|
749
|
+
const parser = SchemaParser.decodeUnknownExit(schema, options);
|
|
737
750
|
return (input, options) => {
|
|
738
751
|
return Exit_.mapError(parser(input, options), issue => new SchemaError(issue));
|
|
739
752
|
};
|
|
@@ -745,8 +758,8 @@ export function decodeUnknownExit(schema, options) {
|
|
|
745
758
|
*
|
|
746
759
|
* **When to use**
|
|
747
760
|
*
|
|
748
|
-
* Use when
|
|
749
|
-
*
|
|
761
|
+
* Use when you need to decode already typed `Encoded` input into an `Exit`
|
|
762
|
+
* whose failure contains `SchemaError`.
|
|
750
763
|
*
|
|
751
764
|
* **Details**
|
|
752
765
|
*
|
|
@@ -755,6 +768,8 @@ export function decodeUnknownExit(schema, options) {
|
|
|
755
768
|
* Options may be provided either when creating the decoder or when applying it;
|
|
756
769
|
* application options override creation options.
|
|
757
770
|
*
|
|
771
|
+
* @see {@link SchemaParser.decodeExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
772
|
+
*
|
|
758
773
|
* @category decoding
|
|
759
774
|
* @since 4.0.0
|
|
760
775
|
*/
|
|
@@ -765,20 +780,21 @@ export const decodeExit = decodeUnknownExit;
|
|
|
765
780
|
*
|
|
766
781
|
* **When to use**
|
|
767
782
|
*
|
|
768
|
-
* Use when the input type
|
|
783
|
+
* Use when you do not know the input type statically and only need to know
|
|
769
784
|
* whether decoding succeeded.
|
|
770
785
|
*
|
|
771
786
|
* **Details**
|
|
772
787
|
*
|
|
773
788
|
* Prefer this over {@link decodeUnknownExit} or {@link decodeUnknownEffect}
|
|
774
|
-
* when you don't need error details. For typed
|
|
789
|
+
* when you don't need error details. For input already typed as the schema's
|
|
790
|
+
* `Encoded` type use {@link decodeOption}.
|
|
775
791
|
* Options may be provided either when creating the decoder or when applying it;
|
|
776
792
|
* application options override creation options.
|
|
777
793
|
*
|
|
778
794
|
* @category decoding
|
|
779
795
|
* @since 3.10.0
|
|
780
796
|
*/
|
|
781
|
-
export const decodeUnknownOption =
|
|
797
|
+
export const decodeUnknownOption = SchemaParser.decodeUnknownOption;
|
|
782
798
|
/**
|
|
783
799
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
784
800
|
* returning an `Option` that is `Some` with the decoded value on success or
|
|
@@ -786,7 +802,8 @@ export const decodeUnknownOption = Parser.decodeUnknownOption;
|
|
|
786
802
|
*
|
|
787
803
|
* **When to use**
|
|
788
804
|
*
|
|
789
|
-
* Use when
|
|
805
|
+
* Use when you already have input typed as the schema's `Encoded` type and
|
|
806
|
+
* only need to know whether decoding succeeded.
|
|
790
807
|
*
|
|
791
808
|
* **Details**
|
|
792
809
|
*
|
|
@@ -797,35 +814,43 @@ export const decodeUnknownOption = Parser.decodeUnknownOption;
|
|
|
797
814
|
* @category decoding
|
|
798
815
|
* @since 3.10.0
|
|
799
816
|
*/
|
|
800
|
-
export const decodeOption =
|
|
817
|
+
export const decodeOption = decodeUnknownOption;
|
|
801
818
|
/**
|
|
802
819
|
* Decodes an `unknown` input against a schema, returning a `Result` that
|
|
803
|
-
* succeeds with the decoded value or fails with a
|
|
820
|
+
* succeeds with the decoded value or fails with a {@link SchemaError}.
|
|
804
821
|
*
|
|
805
822
|
* **When to use**
|
|
806
823
|
*
|
|
807
|
-
* Use when the input type
|
|
808
|
-
* `Result` with
|
|
824
|
+
* Use when you do not know the input type statically and want decoding to
|
|
825
|
+
* return a `Result` with `SchemaError` failure data.
|
|
809
826
|
*
|
|
810
827
|
* **Details**
|
|
811
828
|
*
|
|
812
|
-
* For typed
|
|
829
|
+
* For input already typed as the schema's `Encoded` type use
|
|
830
|
+
* {@link decodeResult}.
|
|
813
831
|
* Options may be provided either when creating the decoder or when applying it;
|
|
814
832
|
* application options override creation options.
|
|
815
833
|
*
|
|
834
|
+
* @see {@link SchemaParser.decodeUnknownResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
835
|
+
*
|
|
816
836
|
* @category decoding
|
|
817
837
|
* @since 4.0.0
|
|
818
838
|
*/
|
|
819
|
-
export
|
|
839
|
+
export function decodeUnknownResult(schema, options) {
|
|
840
|
+
const parser = SchemaParser.decodeUnknownResult(schema, options);
|
|
841
|
+
return (input, options) => {
|
|
842
|
+
return Result_.mapError(parser(input, options), issue => new SchemaError(issue));
|
|
843
|
+
};
|
|
844
|
+
}
|
|
820
845
|
/**
|
|
821
846
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
822
847
|
* returning a `Result` that succeeds with the decoded value or fails with a
|
|
823
|
-
*
|
|
848
|
+
* {@link SchemaError}.
|
|
824
849
|
*
|
|
825
850
|
* **When to use**
|
|
826
851
|
*
|
|
827
|
-
* Use when
|
|
828
|
-
* data.
|
|
852
|
+
* Use when you already have input typed as the schema's `Encoded` type and
|
|
853
|
+
* want decoding to return a `Result` with `SchemaError` failure data.
|
|
829
854
|
*
|
|
830
855
|
* **Details**
|
|
831
856
|
*
|
|
@@ -833,36 +858,49 @@ export const decodeUnknownResult = Parser.decodeUnknownResult;
|
|
|
833
858
|
* Options may be provided either when creating the decoder or when applying it;
|
|
834
859
|
* application options override creation options.
|
|
835
860
|
*
|
|
861
|
+
* @see {@link SchemaParser.decodeResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
862
|
+
*
|
|
836
863
|
* @category decoding
|
|
837
864
|
* @since 4.0.0
|
|
838
865
|
*/
|
|
839
|
-
export const decodeResult =
|
|
866
|
+
export const decodeResult = decodeUnknownResult;
|
|
840
867
|
/**
|
|
841
868
|
* Decodes an `unknown` input against a schema, returning a `Promise` that
|
|
842
|
-
* resolves with the decoded value or rejects with a
|
|
869
|
+
* resolves with the decoded value or rejects with a {@link SchemaError}.
|
|
843
870
|
*
|
|
844
871
|
* **When to use**
|
|
845
872
|
*
|
|
846
|
-
* Use when
|
|
873
|
+
* Use when you need decoding of unknown input to return a JavaScript `Promise`
|
|
874
|
+
* that rejects with `SchemaError`.
|
|
847
875
|
*
|
|
848
876
|
* **Details**
|
|
849
877
|
*
|
|
850
|
-
* For typed
|
|
878
|
+
* For input already typed as the schema's `Encoded` type use
|
|
879
|
+
* {@link decodePromise}.
|
|
851
880
|
* Options may be provided either when creating the decoder or when applying it;
|
|
852
881
|
* application options override creation options.
|
|
853
882
|
*
|
|
883
|
+
* @see {@link SchemaParser.decodeUnknownPromise} for the adapter that rejects with `SchemaIssue.Issue` directly
|
|
884
|
+
*
|
|
854
885
|
* @category decoding
|
|
855
886
|
* @since 3.10.0
|
|
856
887
|
*/
|
|
857
|
-
export
|
|
888
|
+
export function decodeUnknownPromise(schema, options) {
|
|
889
|
+
const parser = decodeUnknownEffect(schema, options);
|
|
890
|
+
return (input, options) => {
|
|
891
|
+
return Effect.runPromise(parser(input, options));
|
|
892
|
+
};
|
|
893
|
+
}
|
|
858
894
|
/**
|
|
859
895
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
860
896
|
* returning a `Promise` that resolves with the decoded value or rejects with a
|
|
861
|
-
*
|
|
897
|
+
* {@link SchemaError}.
|
|
862
898
|
*
|
|
863
899
|
* **When to use**
|
|
864
900
|
*
|
|
865
|
-
* Use when
|
|
901
|
+
* Use when you already have input typed as the schema's `Encoded` type and
|
|
902
|
+
* need decoding to return a JavaScript `Promise` that rejects with
|
|
903
|
+
* `SchemaError`.
|
|
866
904
|
*
|
|
867
905
|
* **Details**
|
|
868
906
|
*
|
|
@@ -870,22 +908,24 @@ export const decodeUnknownPromise = Parser.decodeUnknownPromise;
|
|
|
870
908
|
* Options may be provided either when creating the decoder or when applying it;
|
|
871
909
|
* application options override creation options.
|
|
872
910
|
*
|
|
911
|
+
* @see {@link SchemaParser.decodePromise} for the adapter that rejects with `SchemaIssue.Issue` directly
|
|
912
|
+
*
|
|
873
913
|
* @category decoding
|
|
874
914
|
* @since 3.10.0
|
|
875
915
|
*/
|
|
876
|
-
export const decodePromise =
|
|
916
|
+
export const decodePromise = decodeUnknownPromise;
|
|
877
917
|
/**
|
|
878
918
|
* Decodes an `unknown` input against a schema synchronously, returning the
|
|
879
|
-
* decoded value or throwing
|
|
919
|
+
* decoded value or throwing a {@link SchemaError}.
|
|
880
920
|
*
|
|
881
921
|
* **When to use**
|
|
882
922
|
*
|
|
883
|
-
* Use when
|
|
884
|
-
*
|
|
923
|
+
* Use when you need to validate unknown data at a synchronous boundary and want
|
|
924
|
+
* schema mismatches to throw `SchemaError`.
|
|
885
925
|
*
|
|
886
926
|
* **Details**
|
|
887
927
|
*
|
|
888
|
-
* For typed
|
|
928
|
+
* For input already typed as the schema's `Encoded` type use `decodeSync`.
|
|
889
929
|
* Only service-free schemas can be decoded synchronously. For non-throwing
|
|
890
930
|
* alternatives see `decodeUnknownOption`, `decodeUnknownExit`, or
|
|
891
931
|
* `decodeUnknownEffect`. Options may be provided either when creating the
|
|
@@ -908,19 +948,25 @@ export const decodePromise = Parser.decodePromise;
|
|
|
908
948
|
* // └─ Expected a numeric string, actual "not a number"
|
|
909
949
|
* ```
|
|
910
950
|
*
|
|
951
|
+
* @see {@link SchemaParser.decodeUnknownSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
952
|
+
*
|
|
911
953
|
* @category decoding
|
|
912
954
|
* @since 4.0.0
|
|
913
955
|
*/
|
|
914
|
-
export
|
|
956
|
+
export function decodeUnknownSync(schema, options) {
|
|
957
|
+
const parser = decodeUnknownEffect(schema, options);
|
|
958
|
+
return (input, options) => {
|
|
959
|
+
return Effect.runSync(parser(input, options));
|
|
960
|
+
};
|
|
961
|
+
}
|
|
915
962
|
/**
|
|
916
963
|
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
917
|
-
* synchronously, returning the decoded value or throwing
|
|
918
|
-
* contains the schema issue.
|
|
964
|
+
* synchronously, returning the decoded value or throwing a {@link SchemaError}.
|
|
919
965
|
*
|
|
920
966
|
* **When to use**
|
|
921
967
|
*
|
|
922
|
-
* Use when
|
|
923
|
-
*
|
|
968
|
+
* Use when you already have input typed as the schema's `Encoded` type and
|
|
969
|
+
* want schema mismatches to throw `SchemaError` synchronously.
|
|
924
970
|
*
|
|
925
971
|
* **Details**
|
|
926
972
|
*
|
|
@@ -929,21 +975,24 @@ export const decodeUnknownSync = Parser.decodeUnknownSync;
|
|
|
929
975
|
* provided either when creating the decoder or when applying it; application
|
|
930
976
|
* options override creation options.
|
|
931
977
|
*
|
|
978
|
+
* @see {@link SchemaParser.decodeSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
979
|
+
*
|
|
932
980
|
* @category decoding
|
|
933
981
|
* @since 4.0.0
|
|
934
982
|
*/
|
|
935
|
-
export const decodeSync =
|
|
983
|
+
export const decodeSync = decodeUnknownSync;
|
|
936
984
|
/**
|
|
937
985
|
* Encodes an `unknown` input against a schema, returning an `Effect` that
|
|
938
986
|
* succeeds with the encoded value or fails with a {@link SchemaError}.
|
|
939
987
|
*
|
|
940
988
|
* **When to use**
|
|
941
989
|
*
|
|
942
|
-
* Use when
|
|
990
|
+
* Use when you need to encode unknown input in an `Effect` whose failure
|
|
991
|
+
* channel is `SchemaError`.
|
|
943
992
|
*
|
|
944
993
|
* **Details**
|
|
945
994
|
*
|
|
946
|
-
* Prefer {@link encodeEffect} when the
|
|
995
|
+
* Prefer {@link encodeEffect} when the value is already typed as the schema's
|
|
947
996
|
* `Type`.
|
|
948
997
|
* Options may be provided either when creating the encoder or when applying it;
|
|
949
998
|
* application options override creation options.
|
|
@@ -959,11 +1008,13 @@ export const decodeSync = Parser.decodeSync;
|
|
|
959
1008
|
* // Output: "42"
|
|
960
1009
|
* ```
|
|
961
1010
|
*
|
|
1011
|
+
* @see {@link SchemaParser.encodeUnknownEffect} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1012
|
+
*
|
|
962
1013
|
* @category encoding
|
|
963
1014
|
* @since 4.0.0
|
|
964
1015
|
*/
|
|
965
1016
|
export function encodeUnknownEffect(schema, options) {
|
|
966
|
-
const parser =
|
|
1017
|
+
const parser = SchemaParser.encodeUnknownEffect(schema, options);
|
|
967
1018
|
return (input, options) => {
|
|
968
1019
|
return Effect.mapErrorEager(parser(input, options), issue => new SchemaError(issue));
|
|
969
1020
|
};
|
|
@@ -975,7 +1026,8 @@ export function encodeUnknownEffect(schema, options) {
|
|
|
975
1026
|
*
|
|
976
1027
|
* **When to use**
|
|
977
1028
|
*
|
|
978
|
-
* Use when
|
|
1029
|
+
* Use when you need to encode input already typed as the schema's `Type` in
|
|
1030
|
+
* an `Effect` whose failure channel is `SchemaError`.
|
|
979
1031
|
*
|
|
980
1032
|
* **Details**
|
|
981
1033
|
*
|
|
@@ -983,6 +1035,8 @@ export function encodeUnknownEffect(schema, options) {
|
|
|
983
1035
|
* Options may be provided either when creating the encoder or when applying it;
|
|
984
1036
|
* application options override creation options.
|
|
985
1037
|
*
|
|
1038
|
+
* @see {@link SchemaParser.encodeEffect} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1039
|
+
*
|
|
986
1040
|
* @category encoding
|
|
987
1041
|
* @since 4.0.0
|
|
988
1042
|
*/
|
|
@@ -994,21 +1048,23 @@ export const encodeEffect = encodeUnknownEffect;
|
|
|
994
1048
|
*
|
|
995
1049
|
* **When to use**
|
|
996
1050
|
*
|
|
997
|
-
* Use when
|
|
998
|
-
* `
|
|
1051
|
+
* Use when you need to encode unknown input into an `Exit` whose failure
|
|
1052
|
+
* contains `SchemaError`.
|
|
999
1053
|
*
|
|
1000
1054
|
* **Details**
|
|
1001
1055
|
*
|
|
1002
1056
|
* Only usable with schemas that have no `EncodingServices` requirement. Prefer
|
|
1003
|
-
* {@link encodeExit} when the
|
|
1057
|
+
* {@link encodeExit} when the value is already typed as the schema's `Type`.
|
|
1004
1058
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1005
1059
|
* application options override creation options.
|
|
1006
1060
|
*
|
|
1061
|
+
* @see {@link SchemaParser.encodeUnknownExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1062
|
+
*
|
|
1007
1063
|
* @category encoding
|
|
1008
1064
|
* @since 4.0.0
|
|
1009
1065
|
*/
|
|
1010
1066
|
export function encodeUnknownExit(schema, options) {
|
|
1011
|
-
const parser =
|
|
1067
|
+
const parser = SchemaParser.encodeUnknownExit(schema, options);
|
|
1012
1068
|
return (input, options) => {
|
|
1013
1069
|
return Exit_.mapError(parser(input, options), issue => new SchemaError(issue));
|
|
1014
1070
|
};
|
|
@@ -1020,8 +1076,8 @@ export function encodeUnknownExit(schema, options) {
|
|
|
1020
1076
|
*
|
|
1021
1077
|
* **When to use**
|
|
1022
1078
|
*
|
|
1023
|
-
* Use when
|
|
1024
|
-
*
|
|
1079
|
+
* Use when you need to encode already typed schema values into an `Exit` whose
|
|
1080
|
+
* failure contains `SchemaError`.
|
|
1025
1081
|
*
|
|
1026
1082
|
* **Details**
|
|
1027
1083
|
*
|
|
@@ -1030,6 +1086,8 @@ export function encodeUnknownExit(schema, options) {
|
|
|
1030
1086
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1031
1087
|
* application options override creation options.
|
|
1032
1088
|
*
|
|
1089
|
+
* @see {@link SchemaParser.encodeExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1090
|
+
*
|
|
1033
1091
|
* @category encoding
|
|
1034
1092
|
* @since 4.0.0
|
|
1035
1093
|
*/
|
|
@@ -1040,20 +1098,21 @@ export const encodeExit = encodeUnknownExit;
|
|
|
1040
1098
|
*
|
|
1041
1099
|
* **When to use**
|
|
1042
1100
|
*
|
|
1043
|
-
* Use when the input type
|
|
1101
|
+
* Use when you do not know the input type statically and only need to know
|
|
1044
1102
|
* whether encoding succeeded.
|
|
1045
1103
|
*
|
|
1046
1104
|
* **Details**
|
|
1047
1105
|
*
|
|
1048
1106
|
* Prefer this over {@link encodeUnknownExit} or {@link encodeUnknownEffect}
|
|
1049
|
-
* when you don't need error details. For typed
|
|
1107
|
+
* when you don't need error details. For values already typed as the schema's
|
|
1108
|
+
* `Type` use {@link encodeOption}.
|
|
1050
1109
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1051
1110
|
* application options override creation options.
|
|
1052
1111
|
*
|
|
1053
1112
|
* @category encoding
|
|
1054
1113
|
* @since 3.10.0
|
|
1055
1114
|
*/
|
|
1056
|
-
export const encodeUnknownOption =
|
|
1115
|
+
export const encodeUnknownOption = SchemaParser.encodeUnknownOption;
|
|
1057
1116
|
/**
|
|
1058
1117
|
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
1059
1118
|
* `Option` that is `Some` with the encoded value on success or `None` on
|
|
@@ -1061,7 +1120,8 @@ export const encodeUnknownOption = Parser.encodeUnknownOption;
|
|
|
1061
1120
|
*
|
|
1062
1121
|
* **When to use**
|
|
1063
1122
|
*
|
|
1064
|
-
* Use when typed
|
|
1123
|
+
* Use when you already have a value typed as the schema's `Type` and only need
|
|
1124
|
+
* to know whether encoding succeeded.
|
|
1065
1125
|
*
|
|
1066
1126
|
* **Details**
|
|
1067
1127
|
*
|
|
@@ -1072,34 +1132,42 @@ export const encodeUnknownOption = Parser.encodeUnknownOption;
|
|
|
1072
1132
|
* @category encoding
|
|
1073
1133
|
* @since 3.10.0
|
|
1074
1134
|
*/
|
|
1075
|
-
export const encodeOption =
|
|
1135
|
+
export const encodeOption = encodeUnknownOption;
|
|
1076
1136
|
/**
|
|
1077
1137
|
* Encodes an `unknown` input against a schema, returning a `Result` that
|
|
1078
|
-
* succeeds with the encoded value or fails with a
|
|
1138
|
+
* succeeds with the encoded value or fails with a {@link SchemaError}.
|
|
1079
1139
|
*
|
|
1080
1140
|
* **When to use**
|
|
1081
1141
|
*
|
|
1082
|
-
* Use when the input type
|
|
1083
|
-
* `Result` with
|
|
1142
|
+
* Use when you do not know the input type statically and want encoding to
|
|
1143
|
+
* return a `Result` with `SchemaError` failure data.
|
|
1084
1144
|
*
|
|
1085
1145
|
* **Details**
|
|
1086
1146
|
*
|
|
1087
|
-
* For typed
|
|
1147
|
+
* For values already typed as the schema's `Type` use {@link encodeResult}.
|
|
1088
1148
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1089
1149
|
* application options override creation options.
|
|
1090
1150
|
*
|
|
1151
|
+
* @see {@link SchemaParser.encodeUnknownResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1152
|
+
*
|
|
1091
1153
|
* @category encoding
|
|
1092
1154
|
* @since 4.0.0
|
|
1093
1155
|
*/
|
|
1094
|
-
export
|
|
1156
|
+
export function encodeUnknownResult(schema, options) {
|
|
1157
|
+
const parser = SchemaParser.encodeUnknownResult(schema, options);
|
|
1158
|
+
return (input, options) => {
|
|
1159
|
+
return Result_.mapError(parser(input, options), issue => new SchemaError(issue));
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1095
1162
|
/**
|
|
1096
1163
|
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
1097
|
-
* `Result` that succeeds with the encoded value or fails with a
|
|
1164
|
+
* `Result` that succeeds with the encoded value or fails with a
|
|
1165
|
+
* {@link SchemaError}.
|
|
1098
1166
|
*
|
|
1099
1167
|
* **When to use**
|
|
1100
1168
|
*
|
|
1101
|
-
* Use when
|
|
1102
|
-
* data.
|
|
1169
|
+
* Use when you already have a value typed as the schema's `Type` and want
|
|
1170
|
+
* encoding to return a `Result` with `SchemaError` failure data.
|
|
1103
1171
|
*
|
|
1104
1172
|
* **Details**
|
|
1105
1173
|
*
|
|
@@ -1107,28 +1175,38 @@ export const encodeUnknownResult = Parser.encodeUnknownResult;
|
|
|
1107
1175
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1108
1176
|
* application options override creation options.
|
|
1109
1177
|
*
|
|
1178
|
+
* @see {@link SchemaParser.encodeResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1179
|
+
*
|
|
1110
1180
|
* @category encoding
|
|
1111
1181
|
* @since 4.0.0
|
|
1112
1182
|
*/
|
|
1113
|
-
export const encodeResult =
|
|
1183
|
+
export const encodeResult = encodeUnknownResult;
|
|
1114
1184
|
/**
|
|
1115
1185
|
* Encodes an `unknown` input against a schema, returning a `Promise` that
|
|
1116
|
-
* resolves with the encoded value or rejects with a
|
|
1186
|
+
* resolves with the encoded value or rejects with a {@link SchemaError}.
|
|
1117
1187
|
*
|
|
1118
1188
|
* **When to use**
|
|
1119
1189
|
*
|
|
1120
|
-
* Use when
|
|
1190
|
+
* Use when you need encoding of unknown input to return a JavaScript `Promise`
|
|
1191
|
+
* that rejects with `SchemaError`.
|
|
1121
1192
|
*
|
|
1122
1193
|
* **Details**
|
|
1123
1194
|
*
|
|
1124
|
-
* For typed
|
|
1195
|
+
* For values already typed as the schema's `Type` use {@link encodePromise}.
|
|
1125
1196
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1126
1197
|
* application options override creation options.
|
|
1127
1198
|
*
|
|
1199
|
+
* @see {@link SchemaParser.encodeUnknownPromise} for the adapter that rejects with `SchemaIssue.Issue` directly
|
|
1200
|
+
*
|
|
1128
1201
|
* @category encoding
|
|
1129
1202
|
* @since 3.10.0
|
|
1130
1203
|
*/
|
|
1131
|
-
export
|
|
1204
|
+
export function encodeUnknownPromise(schema, options) {
|
|
1205
|
+
const parser = encodeUnknownEffect(schema, options);
|
|
1206
|
+
return (input, options) => {
|
|
1207
|
+
return Effect.runPromise(parser(input, options));
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1132
1210
|
/**
|
|
1133
1211
|
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
1134
1212
|
* `Promise` that resolves with the encoded value or rejects with a
|
|
@@ -1136,7 +1214,8 @@ export const encodeUnknownPromise = Parser.encodeUnknownPromise;
|
|
|
1136
1214
|
*
|
|
1137
1215
|
* **When to use**
|
|
1138
1216
|
*
|
|
1139
|
-
* Use when
|
|
1217
|
+
* Use when you already have a value typed as the schema's `Type` and need
|
|
1218
|
+
* encoding to return a JavaScript `Promise` that rejects with `SchemaError`.
|
|
1140
1219
|
*
|
|
1141
1220
|
* **Details**
|
|
1142
1221
|
*
|
|
@@ -1144,39 +1223,48 @@ export const encodeUnknownPromise = Parser.encodeUnknownPromise;
|
|
|
1144
1223
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1145
1224
|
* application options override creation options.
|
|
1146
1225
|
*
|
|
1226
|
+
* @see {@link SchemaParser.encodePromise} for the adapter that rejects with `SchemaIssue.Issue` directly
|
|
1227
|
+
*
|
|
1147
1228
|
* @category encoding
|
|
1148
1229
|
* @since 3.10.0
|
|
1149
1230
|
*/
|
|
1150
|
-
export const encodePromise =
|
|
1231
|
+
export const encodePromise = encodeUnknownPromise;
|
|
1151
1232
|
/**
|
|
1152
1233
|
* Encodes an `unknown` input against a schema synchronously, throwing a
|
|
1153
1234
|
* {@link SchemaError} on failure.
|
|
1154
1235
|
*
|
|
1155
1236
|
* **When to use**
|
|
1156
1237
|
*
|
|
1157
|
-
* Use when
|
|
1158
|
-
* mismatches
|
|
1238
|
+
* Use when you need to serialize unknown data at a synchronous boundary and
|
|
1239
|
+
* want schema mismatches to throw `SchemaError`.
|
|
1159
1240
|
*
|
|
1160
1241
|
* **Details**
|
|
1161
1242
|
*
|
|
1162
1243
|
* For non-throwing alternatives see {@link encodeUnknownOption},
|
|
1163
|
-
* {@link encodeUnknownExit}, or {@link encodeUnknownEffect}. For
|
|
1164
|
-
* use {@link encodeSync}.
|
|
1244
|
+
* {@link encodeUnknownExit}, or {@link encodeUnknownEffect}. For values
|
|
1245
|
+
* already typed as the schema's `Type` use {@link encodeSync}.
|
|
1165
1246
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1166
1247
|
* application options override creation options.
|
|
1167
1248
|
*
|
|
1249
|
+
* @see {@link SchemaParser.encodeUnknownSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1250
|
+
*
|
|
1168
1251
|
* @category encoding
|
|
1169
1252
|
* @since 4.0.0
|
|
1170
1253
|
*/
|
|
1171
|
-
export
|
|
1254
|
+
export function encodeUnknownSync(schema, options) {
|
|
1255
|
+
const parser = encodeUnknownEffect(schema, options);
|
|
1256
|
+
return (input, options) => {
|
|
1257
|
+
return Effect.runSync(parser(input, options));
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1172
1260
|
/**
|
|
1173
1261
|
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
1174
1262
|
* throwing a {@link SchemaError} on failure.
|
|
1175
1263
|
*
|
|
1176
1264
|
* **When to use**
|
|
1177
1265
|
*
|
|
1178
|
-
* Use when
|
|
1179
|
-
*
|
|
1266
|
+
* Use when you already have a value typed as the schema's `Type` and want
|
|
1267
|
+
* schema mismatches to throw `SchemaError` synchronously.
|
|
1180
1268
|
*
|
|
1181
1269
|
* **Details**
|
|
1182
1270
|
*
|
|
@@ -1184,10 +1272,12 @@ export const encodeUnknownSync = Parser.encodeUnknownSync;
|
|
|
1184
1272
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1185
1273
|
* application options override creation options.
|
|
1186
1274
|
*
|
|
1275
|
+
* @see {@link SchemaParser.encodeSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1276
|
+
*
|
|
1187
1277
|
* @category encoding
|
|
1188
1278
|
* @since 4.0.0
|
|
1189
1279
|
*/
|
|
1190
|
-
export const encodeSync =
|
|
1280
|
+
export const encodeSync = encodeUnknownSync;
|
|
1191
1281
|
/**
|
|
1192
1282
|
* Creates a schema from an AST (Abstract Syntax Tree) node.
|
|
1193
1283
|
*
|
|
@@ -1263,7 +1353,7 @@ export function isSchema(u) {
|
|
|
1263
1353
|
* @category combinators
|
|
1264
1354
|
* @since 4.0.0
|
|
1265
1355
|
*/
|
|
1266
|
-
export const optionalKey = /*#__PURE__*/Struct_.lambda(schema => make(
|
|
1356
|
+
export const optionalKey = /*#__PURE__*/Struct_.lambda(schema => make(SchemaAST.optionalKey(schema.ast), {
|
|
1267
1357
|
schema
|
|
1268
1358
|
}));
|
|
1269
1359
|
/**
|
|
@@ -1331,7 +1421,7 @@ export const required = /*#__PURE__*/Struct_.lambda(self => self.schema.members[
|
|
|
1331
1421
|
* @category combinators
|
|
1332
1422
|
* @since 4.0.0
|
|
1333
1423
|
*/
|
|
1334
|
-
export const mutableKey = /*#__PURE__*/Struct_.lambda(schema => make(
|
|
1424
|
+
export const mutableKey = /*#__PURE__*/Struct_.lambda(schema => make(SchemaAST.mutableKey(schema.ast), {
|
|
1335
1425
|
schema
|
|
1336
1426
|
}));
|
|
1337
1427
|
/**
|
|
@@ -1353,7 +1443,7 @@ export const readonlyKey = /*#__PURE__*/Struct_.lambda(self => self.schema);
|
|
|
1353
1443
|
* @category transforming
|
|
1354
1444
|
* @since 4.0.0
|
|
1355
1445
|
*/
|
|
1356
|
-
export const toType = /*#__PURE__*/Struct_.lambda(schema => make(
|
|
1446
|
+
export const toType = /*#__PURE__*/Struct_.lambda(schema => make(SchemaAST.toType(schema.ast), {
|
|
1357
1447
|
schema
|
|
1358
1448
|
}));
|
|
1359
1449
|
/**
|
|
@@ -1363,7 +1453,7 @@ export const toType = /*#__PURE__*/Struct_.lambda(schema => make(AST.toType(sche
|
|
|
1363
1453
|
* @category transforming
|
|
1364
1454
|
* @since 4.0.0
|
|
1365
1455
|
*/
|
|
1366
|
-
export const toEncoded = /*#__PURE__*/Struct_.lambda(schema => make(
|
|
1456
|
+
export const toEncoded = /*#__PURE__*/Struct_.lambda(schema => make(SchemaAST.toEncoded(schema.ast), {
|
|
1367
1457
|
schema
|
|
1368
1458
|
}));
|
|
1369
1459
|
const FlipTypeId = "~effect/Schema/flip";
|
|
@@ -1372,9 +1462,9 @@ function isFlip$(schema) {
|
|
|
1372
1462
|
}
|
|
1373
1463
|
export function flip(schema) {
|
|
1374
1464
|
if (isFlip$(schema)) {
|
|
1375
|
-
return schema.schema.rebuild(
|
|
1465
|
+
return schema.schema.rebuild(SchemaAST.flip(schema.ast));
|
|
1376
1466
|
}
|
|
1377
|
-
return make(
|
|
1467
|
+
return make(SchemaAST.flip(schema.ast), {
|
|
1378
1468
|
[FlipTypeId]: FlipTypeId,
|
|
1379
1469
|
schema
|
|
1380
1470
|
});
|
|
@@ -1398,24 +1488,29 @@ export function flip(schema) {
|
|
|
1398
1488
|
* @since 3.10.0
|
|
1399
1489
|
*/
|
|
1400
1490
|
export function Literal(literal) {
|
|
1401
|
-
const out = make(new
|
|
1491
|
+
const out = make(new SchemaAST.Literal(literal), {
|
|
1402
1492
|
literal,
|
|
1403
1493
|
transform(to) {
|
|
1404
1494
|
return out.pipe(decodeTo(Literal(to), {
|
|
1405
|
-
decode:
|
|
1406
|
-
encode:
|
|
1495
|
+
decode: SchemaGetter.transform(() => to),
|
|
1496
|
+
encode: SchemaGetter.transform(() => literal)
|
|
1407
1497
|
}));
|
|
1408
1498
|
}
|
|
1409
1499
|
});
|
|
1410
1500
|
return out;
|
|
1411
1501
|
}
|
|
1412
1502
|
function templateLiteralFromParts(parts) {
|
|
1413
|
-
return new
|
|
1503
|
+
return new SchemaAST.TemplateLiteral(parts.map(part => isSchema(part) ? part.ast : new SchemaAST.Literal(part)));
|
|
1414
1504
|
}
|
|
1415
1505
|
/**
|
|
1416
1506
|
* Creates a schema that validates strings matching a template literal pattern. Each part can be
|
|
1417
1507
|
* a literal string/number/bigint or a schema whose encoded type is a string, number, or bigint.
|
|
1418
1508
|
*
|
|
1509
|
+
* **When to use**
|
|
1510
|
+
*
|
|
1511
|
+
* Use when the decoded value should remain the matched string and you do not
|
|
1512
|
+
* need the individual template parts parsed into a tuple.
|
|
1513
|
+
*
|
|
1419
1514
|
* **Example** (URL path pattern)
|
|
1420
1515
|
*
|
|
1421
1516
|
* ```ts
|
|
@@ -1486,7 +1581,7 @@ export function TemplateLiteralParser(parts) {
|
|
|
1486
1581
|
* @since 4.0.0
|
|
1487
1582
|
*/
|
|
1488
1583
|
export function Enum(enums) {
|
|
1489
|
-
return make(new
|
|
1584
|
+
return make(new SchemaAST.Enum(Object.keys(enums).filter(key => typeof enums[enums[key]] !== "number").map(key => [key, enums[key]])), {
|
|
1490
1585
|
enums
|
|
1491
1586
|
});
|
|
1492
1587
|
}
|
|
@@ -1496,7 +1591,7 @@ export function Enum(enums) {
|
|
|
1496
1591
|
* @category schemas
|
|
1497
1592
|
* @since 3.10.0
|
|
1498
1593
|
*/
|
|
1499
|
-
export const Never = /*#__PURE__*/make(
|
|
1594
|
+
export const Never = /*#__PURE__*/make(SchemaAST.never);
|
|
1500
1595
|
/**
|
|
1501
1596
|
* Schema for the `any` type. Accepts any value without validation.
|
|
1502
1597
|
*
|
|
@@ -1504,15 +1599,20 @@ export const Never = /*#__PURE__*/make(AST.never);
|
|
|
1504
1599
|
* @category schemas
|
|
1505
1600
|
* @since 3.10.0
|
|
1506
1601
|
*/
|
|
1507
|
-
export const Any = /*#__PURE__*/make(
|
|
1602
|
+
export const Any = /*#__PURE__*/make(SchemaAST.any);
|
|
1508
1603
|
/**
|
|
1509
1604
|
* Schema for the `unknown` type. Accepts any value without validation.
|
|
1510
1605
|
*
|
|
1606
|
+
* **When to use**
|
|
1607
|
+
*
|
|
1608
|
+
* Use as a top schema when you need to accept any input while preserving
|
|
1609
|
+
* TypeScript's `unknown` safety at use sites.
|
|
1610
|
+
*
|
|
1511
1611
|
* @see {@link Any} for the `any` variant.
|
|
1512
1612
|
* @category schemas
|
|
1513
1613
|
* @since 3.10.0
|
|
1514
1614
|
*/
|
|
1515
|
-
export const Unknown = /*#__PURE__*/make(
|
|
1615
|
+
export const Unknown = /*#__PURE__*/make(SchemaAST.unknown);
|
|
1516
1616
|
/**
|
|
1517
1617
|
* Schema for the `null` literal. Validates that the input is strictly `null`.
|
|
1518
1618
|
*
|
|
@@ -1520,7 +1620,7 @@ export const Unknown = /*#__PURE__*/make(AST.unknown);
|
|
|
1520
1620
|
* @category schemas
|
|
1521
1621
|
* @since 3.10.0
|
|
1522
1622
|
*/
|
|
1523
|
-
export const Null = /*#__PURE__*/make(
|
|
1623
|
+
export const Null = /*#__PURE__*/make(SchemaAST.null);
|
|
1524
1624
|
/**
|
|
1525
1625
|
* Schema for the `undefined` literal. Validates that the input is strictly `undefined`.
|
|
1526
1626
|
*
|
|
@@ -1528,14 +1628,14 @@ export const Null = /*#__PURE__*/make(AST.null);
|
|
|
1528
1628
|
* @category schemas
|
|
1529
1629
|
* @since 3.10.0
|
|
1530
1630
|
*/
|
|
1531
|
-
export const Undefined = /*#__PURE__*/make(
|
|
1631
|
+
export const Undefined = /*#__PURE__*/make(SchemaAST.undefined);
|
|
1532
1632
|
/**
|
|
1533
1633
|
* Schema for `string` values. Validates that the input is `typeof` `"string"`.
|
|
1534
1634
|
*
|
|
1535
1635
|
* @category schemas
|
|
1536
1636
|
* @since 4.0.0
|
|
1537
1637
|
*/
|
|
1538
|
-
export const String = /*#__PURE__*/make(
|
|
1638
|
+
export const String = /*#__PURE__*/make(SchemaAST.string);
|
|
1539
1639
|
/**
|
|
1540
1640
|
* Schema for `number` values, including `NaN`, `Infinity`, and `-Infinity`.
|
|
1541
1641
|
*
|
|
@@ -1550,7 +1650,7 @@ export const String = /*#__PURE__*/make(AST.string);
|
|
|
1550
1650
|
* @category schemas
|
|
1551
1651
|
* @since 4.0.0
|
|
1552
1652
|
*/
|
|
1553
|
-
export const Number = /*#__PURE__*/make(
|
|
1653
|
+
export const Number = /*#__PURE__*/make(SchemaAST.number);
|
|
1554
1654
|
/**
|
|
1555
1655
|
* Schema for `boolean` values. Validates that the input is `typeof` `"boolean"`.
|
|
1556
1656
|
*
|
|
@@ -1563,7 +1663,7 @@ export const Number = /*#__PURE__*/make(AST.number);
|
|
|
1563
1663
|
* @category boolean
|
|
1564
1664
|
* @since 4.0.0
|
|
1565
1665
|
*/
|
|
1566
|
-
export const Boolean = /*#__PURE__*/make(
|
|
1666
|
+
export const Boolean = /*#__PURE__*/make(SchemaAST.boolean);
|
|
1567
1667
|
/**
|
|
1568
1668
|
* Schema for `symbol` values. Validates that the input is `typeof` `"symbol"`.
|
|
1569
1669
|
*
|
|
@@ -1571,7 +1671,7 @@ export const Boolean = /*#__PURE__*/make(AST.boolean);
|
|
|
1571
1671
|
* @category schemas
|
|
1572
1672
|
* @since 4.0.0
|
|
1573
1673
|
*/
|
|
1574
|
-
export const Symbol = /*#__PURE__*/make(
|
|
1674
|
+
export const Symbol = /*#__PURE__*/make(SchemaAST.symbol);
|
|
1575
1675
|
/**
|
|
1576
1676
|
* Schema for `bigint` values. Validates that the input is `typeof` `"bigint"`.
|
|
1577
1677
|
*
|
|
@@ -1585,14 +1685,14 @@ export const Symbol = /*#__PURE__*/make(AST.symbol);
|
|
|
1585
1685
|
* @category schemas
|
|
1586
1686
|
* @since 4.0.0
|
|
1587
1687
|
*/
|
|
1588
|
-
export const BigInt = /*#__PURE__*/make(
|
|
1688
|
+
export const BigInt = /*#__PURE__*/make(SchemaAST.bigInt);
|
|
1589
1689
|
/**
|
|
1590
1690
|
* Schema for the `void` type. Accepts `undefined` as the encoded value.
|
|
1591
1691
|
*
|
|
1592
1692
|
* @category schemas
|
|
1593
1693
|
* @since 3.10.0
|
|
1594
1694
|
*/
|
|
1595
|
-
export const Void = /*#__PURE__*/make(
|
|
1695
|
+
export const Void = /*#__PURE__*/make(SchemaAST.void);
|
|
1596
1696
|
/**
|
|
1597
1697
|
* Schema for the `object` type. Validates that the input is a non-null object or function
|
|
1598
1698
|
* (i.e. `typeof value === "object" && value !== null || typeof value === "function"`).
|
|
@@ -1600,7 +1700,7 @@ export const Void = /*#__PURE__*/make(AST.void);
|
|
|
1600
1700
|
* @category schemas
|
|
1601
1701
|
* @since 4.0.0
|
|
1602
1702
|
*/
|
|
1603
|
-
export const ObjectKeyword = /*#__PURE__*/make(
|
|
1703
|
+
export const ObjectKeyword = /*#__PURE__*/make(SchemaAST.objectKeyword);
|
|
1604
1704
|
/**
|
|
1605
1705
|
* Creates a schema for a specific symbol. Only that exact symbol satisfies the schema.
|
|
1606
1706
|
*
|
|
@@ -1618,14 +1718,14 @@ export const ObjectKeyword = /*#__PURE__*/make(AST.objectKeyword);
|
|
|
1618
1718
|
* @since 4.0.0
|
|
1619
1719
|
*/
|
|
1620
1720
|
export function UniqueSymbol(symbol) {
|
|
1621
|
-
return make(new
|
|
1721
|
+
return make(new SchemaAST.UniqueSymbol(symbol));
|
|
1622
1722
|
}
|
|
1623
1723
|
function makeStruct(ast, fields) {
|
|
1624
1724
|
return make(ast, {
|
|
1625
1725
|
fields,
|
|
1626
1726
|
mapFields(f, options) {
|
|
1627
1727
|
const fields = f(this.fields);
|
|
1628
|
-
return makeStruct(
|
|
1728
|
+
return makeStruct(SchemaAST.struct(fields, options?.unsafePreserveChecks ? this.ast.checks : undefined), fields);
|
|
1629
1729
|
}
|
|
1630
1730
|
});
|
|
1631
1731
|
}
|
|
@@ -1663,15 +1763,15 @@ function makeStruct(ast, fields) {
|
|
|
1663
1763
|
* @since 3.10.0
|
|
1664
1764
|
*/
|
|
1665
1765
|
export function Struct(fields) {
|
|
1666
|
-
return makeStruct(
|
|
1766
|
+
return makeStruct(SchemaAST.struct(fields, undefined), fields);
|
|
1667
1767
|
}
|
|
1668
1768
|
/**
|
|
1669
1769
|
* Adds fields to a struct schema through a struct-mapping lambda.
|
|
1670
1770
|
*
|
|
1671
1771
|
* **When to use**
|
|
1672
1772
|
*
|
|
1673
|
-
* Use to add the same fields to an existing struct or
|
|
1674
|
-
*
|
|
1773
|
+
* Use to add the same fields to an existing struct or every struct member of a
|
|
1774
|
+
* union.
|
|
1675
1775
|
*
|
|
1676
1776
|
* **Details**
|
|
1677
1777
|
*
|
|
@@ -1734,7 +1834,7 @@ export function encodeKeys(mapping) {
|
|
|
1734
1834
|
fields[k] = encoded;
|
|
1735
1835
|
}
|
|
1736
1836
|
}
|
|
1737
|
-
return Struct(fields).pipe(decodeTo(self,
|
|
1837
|
+
return Struct(fields).pipe(decodeTo(self, SchemaTransformation.transform({
|
|
1738
1838
|
decode: Struct_.renameKeys(reverseMapping),
|
|
1739
1839
|
encode: Struct_.renameKeys(mapping)
|
|
1740
1840
|
})));
|
|
@@ -1780,7 +1880,7 @@ derive) {
|
|
|
1780
1880
|
...f,
|
|
1781
1881
|
...fields
|
|
1782
1882
|
});
|
|
1783
|
-
return self.pipe(decodeTo(to,
|
|
1883
|
+
return self.pipe(decodeTo(to, SchemaTransformation.transform({
|
|
1784
1884
|
decode: input => {
|
|
1785
1885
|
const out = {
|
|
1786
1886
|
...input
|
|
@@ -1828,8 +1928,8 @@ derive) {
|
|
|
1828
1928
|
* @since 3.10.0
|
|
1829
1929
|
*/
|
|
1830
1930
|
export function Record(key, value, options) {
|
|
1831
|
-
const keyValueCombiner = options?.keyValueCombiner?.decode || options?.keyValueCombiner?.encode ? new
|
|
1832
|
-
return make(
|
|
1931
|
+
const keyValueCombiner = options?.keyValueCombiner?.decode || options?.keyValueCombiner?.encode ? new SchemaAST.KeyValueCombiner(options.keyValueCombiner.decode, options.keyValueCombiner.encode) : undefined;
|
|
1932
|
+
return make(SchemaAST.record(key.ast, value.ast, keyValueCombiner), {
|
|
1833
1933
|
key,
|
|
1834
1934
|
value
|
|
1835
1935
|
});
|
|
@@ -1845,10 +1945,10 @@ export function Record(key, value, options) {
|
|
|
1845
1945
|
*
|
|
1846
1946
|
* const schema = Schema.StructWithRest(
|
|
1847
1947
|
* Schema.Struct({ id: Schema.Number }),
|
|
1848
|
-
* [Schema.Record(Schema.String, Schema.
|
|
1948
|
+
* [Schema.Record(Schema.String, Schema.Number)]
|
|
1849
1949
|
* )
|
|
1850
1950
|
*
|
|
1851
|
-
* // { readonly id: number
|
|
1951
|
+
* // { readonly id: number, readonly [x: string]: number }
|
|
1852
1952
|
* type T = typeof schema.Type
|
|
1853
1953
|
* ```
|
|
1854
1954
|
*
|
|
@@ -1856,7 +1956,7 @@ export function Record(key, value, options) {
|
|
|
1856
1956
|
* @since 4.0.0
|
|
1857
1957
|
*/
|
|
1858
1958
|
export function StructWithRest(schema, records) {
|
|
1859
|
-
return make(
|
|
1959
|
+
return make(SchemaAST.structWithRest(schema.ast, records.map(SchemaAST.getAST)), {
|
|
1860
1960
|
schema,
|
|
1861
1961
|
records
|
|
1862
1962
|
});
|
|
@@ -1866,7 +1966,7 @@ function makeTuple(ast, elements) {
|
|
|
1866
1966
|
elements,
|
|
1867
1967
|
mapElements(f, options) {
|
|
1868
1968
|
const elements = f(this.elements);
|
|
1869
|
-
return makeTuple(
|
|
1969
|
+
return makeTuple(SchemaAST.tuple(elements, options?.unsafePreserveChecks ? this.ast.checks : undefined), elements);
|
|
1870
1970
|
}
|
|
1871
1971
|
});
|
|
1872
1972
|
}
|
|
@@ -1889,7 +1989,7 @@ function makeTuple(ast, elements) {
|
|
|
1889
1989
|
* @since 3.10.0
|
|
1890
1990
|
*/
|
|
1891
1991
|
export function Tuple(elements) {
|
|
1892
|
-
return makeTuple(
|
|
1992
|
+
return makeTuple(SchemaAST.tuple(elements), elements);
|
|
1893
1993
|
}
|
|
1894
1994
|
/**
|
|
1895
1995
|
* Extends a fixed-length tuple schema with a variadic rest segment.
|
|
@@ -1922,7 +2022,7 @@ export function Tuple(elements) {
|
|
|
1922
2022
|
* @since 4.0.0
|
|
1923
2023
|
*/
|
|
1924
2024
|
export function TupleWithRest(schema, rest) {
|
|
1925
|
-
return make(
|
|
2025
|
+
return make(SchemaAST.tupleWithRest(schema.ast, rest.map(SchemaAST.getAST)), {
|
|
1926
2026
|
schema,
|
|
1927
2027
|
rest
|
|
1928
2028
|
});
|
|
@@ -1931,7 +2031,7 @@ export function TupleWithRest(schema, rest) {
|
|
|
1931
2031
|
* @category constructors
|
|
1932
2032
|
* @since 4.0.0
|
|
1933
2033
|
*/
|
|
1934
|
-
const ArraySchema = /*#__PURE__*/Struct_.lambda(schema => make(new
|
|
2034
|
+
const ArraySchema = /*#__PURE__*/Struct_.lambda(schema => make(new SchemaAST.Arrays(false, [], [schema.ast]), {
|
|
1935
2035
|
value: schema
|
|
1936
2036
|
}));
|
|
1937
2037
|
export {
|
|
@@ -1972,7 +2072,7 @@ ArraySchema as Array };
|
|
|
1972
2072
|
* @category constructors
|
|
1973
2073
|
* @since 3.10.0
|
|
1974
2074
|
*/
|
|
1975
|
-
export const NonEmptyArray = /*#__PURE__*/Struct_.lambda(schema => make(new
|
|
2075
|
+
export const NonEmptyArray = /*#__PURE__*/Struct_.lambda(schema => make(new SchemaAST.Arrays(false, [schema.ast], [schema.ast]), {
|
|
1976
2076
|
value: schema
|
|
1977
2077
|
}));
|
|
1978
2078
|
/**
|
|
@@ -2002,7 +2102,7 @@ export const NonEmptyArray = /*#__PURE__*/Struct_.lambda(schema => make(new AST.
|
|
|
2002
2102
|
* @since 3.10.0
|
|
2003
2103
|
*/
|
|
2004
2104
|
export function ArrayEnsure(schema) {
|
|
2005
|
-
return Union([schema, ArraySchema(schema)]).pipe(decodeTo(ArraySchema(toType(schema)),
|
|
2105
|
+
return Union([schema, ArraySchema(schema)]).pipe(decodeTo(ArraySchema(toType(schema)), SchemaTransformation.transform({
|
|
2006
2106
|
decode: Arr.ensure,
|
|
2007
2107
|
encode: array => array.length === 1 ? array[0] : array
|
|
2008
2108
|
})));
|
|
@@ -2039,7 +2139,7 @@ export function UniqueArray(item) {
|
|
|
2039
2139
|
* @since 3.10.0
|
|
2040
2140
|
*/
|
|
2041
2141
|
export const mutable = /*#__PURE__*/Struct_.lambda(schema => {
|
|
2042
|
-
return make(new
|
|
2142
|
+
return make(new SchemaAST.Arrays(true, schema.ast.elements, schema.ast.rest), {
|
|
2043
2143
|
schema
|
|
2044
2144
|
});
|
|
2045
2145
|
});
|
|
@@ -2048,7 +2148,7 @@ function makeUnion(ast, members) {
|
|
|
2048
2148
|
members,
|
|
2049
2149
|
mapMembers(f, options) {
|
|
2050
2150
|
const members = f(this.members);
|
|
2051
|
-
return makeUnion(
|
|
2151
|
+
return makeUnion(SchemaAST.union(members, this.ast.mode, options?.unsafePreserveChecks ? this.ast.checks : undefined), members);
|
|
2052
2152
|
}
|
|
2053
2153
|
});
|
|
2054
2154
|
}
|
|
@@ -2077,7 +2177,7 @@ function makeUnion(ast, members) {
|
|
|
2077
2177
|
* @since 3.10.0
|
|
2078
2178
|
*/
|
|
2079
2179
|
export function Union(members, options) {
|
|
2080
|
-
return makeUnion(
|
|
2180
|
+
return makeUnion(SchemaAST.union(members, options?.mode ?? "anyOf", undefined), members);
|
|
2081
2181
|
}
|
|
2082
2182
|
/**
|
|
2083
2183
|
* Creates a union schema from an array of literal values.
|
|
@@ -2097,7 +2197,7 @@ export function Union(members, options) {
|
|
|
2097
2197
|
*/
|
|
2098
2198
|
export function Literals(literals) {
|
|
2099
2199
|
const members = literals.map(Literal);
|
|
2100
|
-
return make(
|
|
2200
|
+
return make(SchemaAST.union(members, "anyOf", undefined), {
|
|
2101
2201
|
literals,
|
|
2102
2202
|
members,
|
|
2103
2203
|
mapMembers(f) {
|
|
@@ -2157,7 +2257,7 @@ export const NullishOr = /*#__PURE__*/Struct_.lambda(self => Union([self, Null,
|
|
|
2157
2257
|
* @since 3.10.0
|
|
2158
2258
|
*/
|
|
2159
2259
|
export function suspend(f) {
|
|
2160
|
-
return make(new
|
|
2260
|
+
return make(new SchemaAST.Suspend(() => f().ast));
|
|
2161
2261
|
}
|
|
2162
2262
|
/**
|
|
2163
2263
|
* Attaches one or more filter checks to a schema without changing the
|
|
@@ -2195,7 +2295,7 @@ export function check(...checks) {
|
|
|
2195
2295
|
* @since 3.10.0
|
|
2196
2296
|
*/
|
|
2197
2297
|
export function refine(refinement, annotations) {
|
|
2198
|
-
return schema => make(
|
|
2298
|
+
return schema => make(SchemaAST.appendChecks(schema.ast, [SchemaAST.makeFilterByGuard(refinement, annotations)]), {
|
|
2199
2299
|
schema
|
|
2200
2300
|
});
|
|
2201
2301
|
}
|
|
@@ -2219,7 +2319,7 @@ export function refine(refinement, annotations) {
|
|
|
2219
2319
|
* @since 3.10.0
|
|
2220
2320
|
*/
|
|
2221
2321
|
export function brand(identifier) {
|
|
2222
|
-
return schema => make(
|
|
2322
|
+
return schema => make(SchemaAST.brand(schema.ast, identifier), {
|
|
2223
2323
|
schema,
|
|
2224
2324
|
identifier
|
|
2225
2325
|
});
|
|
@@ -2262,7 +2362,7 @@ export function fromBrand(identifier, ctor) {
|
|
|
2262
2362
|
* @since 4.0.0
|
|
2263
2363
|
*/
|
|
2264
2364
|
export function middlewareDecoding(decode) {
|
|
2265
|
-
return schema => make(
|
|
2365
|
+
return schema => make(SchemaAST.middlewareDecoding(schema.ast, new SchemaTransformation.Middleware(decode, identity)), {
|
|
2266
2366
|
schema
|
|
2267
2367
|
});
|
|
2268
2368
|
}
|
|
@@ -2292,7 +2392,7 @@ export function middlewareDecoding(decode) {
|
|
|
2292
2392
|
* @since 4.0.0
|
|
2293
2393
|
*/
|
|
2294
2394
|
export function middlewareEncoding(encode) {
|
|
2295
|
-
return schema => make(
|
|
2395
|
+
return schema => make(SchemaAST.middlewareEncoding(schema.ast, new SchemaTransformation.Middleware(identity, encode)), {
|
|
2296
2396
|
schema
|
|
2297
2397
|
});
|
|
2298
2398
|
}
|
|
@@ -2326,7 +2426,8 @@ export function catchDecoding(f) {
|
|
|
2326
2426
|
*
|
|
2327
2427
|
* **When to use**
|
|
2328
2428
|
*
|
|
2329
|
-
* Use when decoding fallback logic
|
|
2429
|
+
* Use when you need decoding fallback logic to require services from the Effect
|
|
2430
|
+
* context.
|
|
2330
2431
|
*
|
|
2331
2432
|
* **Details**
|
|
2332
2433
|
*
|
|
@@ -2363,7 +2464,8 @@ export function catchEncoding(f) {
|
|
|
2363
2464
|
*
|
|
2364
2465
|
* **When to use**
|
|
2365
2466
|
*
|
|
2366
|
-
* Use when encoding fallback logic
|
|
2467
|
+
* Use when you need encoding fallback logic to require services from the Effect
|
|
2468
|
+
* context.
|
|
2367
2469
|
*
|
|
2368
2470
|
* **Details**
|
|
2369
2471
|
*
|
|
@@ -2382,7 +2484,7 @@ export function catchEncodingWithContext(f) {
|
|
|
2382
2484
|
}
|
|
2383
2485
|
export function decodeTo(to, transformation) {
|
|
2384
2486
|
return from => {
|
|
2385
|
-
return make(
|
|
2487
|
+
return make(SchemaAST.decodeTo(from.ast, to.ast, transformation ? SchemaTransformation.make(transformation) : SchemaTransformation.passthrough()), {
|
|
2386
2488
|
from,
|
|
2387
2489
|
to
|
|
2388
2490
|
});
|
|
@@ -2391,23 +2493,26 @@ export function decodeTo(to, transformation) {
|
|
|
2391
2493
|
/**
|
|
2392
2494
|
* Applies a transformation to a schema, creating a new schema with the same type but transformed encoding/decoding.
|
|
2393
2495
|
*
|
|
2496
|
+
* **When to use**
|
|
2497
|
+
*
|
|
2498
|
+
* Use when the decoded type stays the same and the transformation only
|
|
2499
|
+
* normalizes values during encoding and decoding.
|
|
2500
|
+
*
|
|
2394
2501
|
* **Details**
|
|
2395
2502
|
*
|
|
2396
|
-
*
|
|
2397
|
-
* The resulting schema
|
|
2398
|
-
*
|
|
2503
|
+
* Call it with a transformation object and then pipe a schema into the returned
|
|
2504
|
+
* function. The resulting schema keeps the same `Type` and `Encoded` types as
|
|
2505
|
+
* the source schema, while applying the transformation during both decoding and
|
|
2506
|
+
* encoding.
|
|
2507
|
+
*
|
|
2508
|
+
* Internally this uses `toType(self)` as the target schema and combines service
|
|
2509
|
+
* requirements from the source schema and the transformation.
|
|
2399
2510
|
*
|
|
2400
|
-
*
|
|
2401
|
-
* - Resulting schema has `Type = S["Type"]` and `Encoded = S["Encoded"]`
|
|
2402
|
-
* - Uses `toType(self)` as the target schema internally (creates a schema where both Type and Encoded are `S["Type"]`)
|
|
2403
|
-
* - Combines decoding/encoding services from the source schema and transformation
|
|
2404
|
-
* - Transformation `decode` maps `S["Type"]` → `S["Type"]` (used during encoding)
|
|
2405
|
-
* - Transformation `encode` maps `S["Type"]` → `S["Type"]` (used during decoding)
|
|
2511
|
+
* **Gotchas**
|
|
2406
2512
|
*
|
|
2407
|
-
*
|
|
2408
|
-
*
|
|
2409
|
-
*
|
|
2410
|
-
* - **Service dependencies**: Resulting schema requires services from the source schema and transformation; use `Schema.provideService` if needed
|
|
2513
|
+
* Use {@link decodeTo} instead when the transformation should change the
|
|
2514
|
+
* decoded type. For this helper, both transformation getters operate on
|
|
2515
|
+
* `S["Type"]` values.
|
|
2411
2516
|
*
|
|
2412
2517
|
* **Example** (Trimming string values during encoding/decoding)
|
|
2413
2518
|
*
|
|
@@ -2499,7 +2604,7 @@ export function withConstructorDefault(
|
|
|
2499
2604
|
// `S["~type.make.in"]` instead of `S["Type"]` is intentional here because
|
|
2500
2605
|
// it makes easier to define the default value if there are nested defaults
|
|
2501
2606
|
defaultValue) {
|
|
2502
|
-
return schema => make(
|
|
2607
|
+
return schema => make(SchemaAST.withConstructorDefault(schema.ast, Effect.mapErrorEager(defaultValue, e => e.issue)), {
|
|
2503
2608
|
schema
|
|
2504
2609
|
});
|
|
2505
2610
|
}
|
|
@@ -2538,10 +2643,10 @@ defaultValue) {
|
|
|
2538
2643
|
* @since 4.0.0
|
|
2539
2644
|
*/
|
|
2540
2645
|
export function withDecodingDefaultKey(defaultValue, options) {
|
|
2541
|
-
const encode = options?.encodingStrategy === "omit" ?
|
|
2646
|
+
const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough();
|
|
2542
2647
|
return self => {
|
|
2543
2648
|
return optionalKey(toEncoded(self)).pipe(decodeTo(self, {
|
|
2544
|
-
decode:
|
|
2649
|
+
decode: SchemaGetter.withDefault(Effect.mapErrorEager(defaultValue, e => e.issue)),
|
|
2545
2650
|
encode
|
|
2546
2651
|
}));
|
|
2547
2652
|
};
|
|
@@ -2578,6 +2683,11 @@ export function withDecodingDefaultTypeKey(defaultValue, options) {
|
|
|
2578
2683
|
* and provides a default `Encoded` value when the field is missing or
|
|
2579
2684
|
* `undefined` during decoding.
|
|
2580
2685
|
*
|
|
2686
|
+
* **When to use**
|
|
2687
|
+
*
|
|
2688
|
+
* Use when the default is expressed in the encoded representation, before the
|
|
2689
|
+
* field's decoding transformation runs.
|
|
2690
|
+
*
|
|
2581
2691
|
* **Details**
|
|
2582
2692
|
*
|
|
2583
2693
|
* The default value is specified in terms of the `Encoded` type (before any
|
|
@@ -2608,10 +2718,10 @@ export function withDecodingDefaultTypeKey(defaultValue, options) {
|
|
|
2608
2718
|
* @since 3.10.0
|
|
2609
2719
|
*/
|
|
2610
2720
|
export function withDecodingDefault(defaultValue, options) {
|
|
2611
|
-
const encode = options?.encodingStrategy === "omit" ?
|
|
2721
|
+
const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough();
|
|
2612
2722
|
return self => {
|
|
2613
2723
|
return optional(toEncoded(self)).pipe(decodeTo(self, {
|
|
2614
|
-
decode:
|
|
2724
|
+
decode: SchemaGetter.withDefault(Effect.mapErrorEager(defaultValue, e => e.issue)),
|
|
2615
2725
|
encode
|
|
2616
2726
|
}));
|
|
2617
2727
|
};
|
|
@@ -2621,6 +2731,11 @@ export function withDecodingDefault(defaultValue, options) {
|
|
|
2621
2731
|
* and provides a default `Type` value when the field is missing or
|
|
2622
2732
|
* `undefined` during decoding.
|
|
2623
2733
|
*
|
|
2734
|
+
* **When to use**
|
|
2735
|
+
*
|
|
2736
|
+
* Use when the default is already in the decoded representation and should not
|
|
2737
|
+
* pass through the field's decoding transformation.
|
|
2738
|
+
*
|
|
2624
2739
|
* **Details**
|
|
2625
2740
|
*
|
|
2626
2741
|
* Unlike {@link withDecodingDefault}, the default value is specified in terms
|
|
@@ -2795,10 +2910,10 @@ export function toTaggedUnion(tag) {
|
|
|
2795
2910
|
});
|
|
2796
2911
|
function walk(schema) {
|
|
2797
2912
|
const ast = schema.ast;
|
|
2798
|
-
if (
|
|
2913
|
+
if (SchemaAST.isUnion(ast) && "members" in schema && globalThis.Array.isArray(schema.members) && schema.members.every(isSchema)) {
|
|
2799
2914
|
return schema.members.forEach(walk);
|
|
2800
2915
|
}
|
|
2801
|
-
const sentinels =
|
|
2916
|
+
const sentinels = SchemaAST.collectSentinels(ast);
|
|
2802
2917
|
if (sentinels.length > 0) {
|
|
2803
2918
|
const literal = sentinels.find(s => s.key === tag)?.literal;
|
|
2804
2919
|
if (Predicate.isPropertyKey(literal)) {
|
|
@@ -2920,7 +3035,7 @@ export function instanceOf(constructor, annotations) {
|
|
|
2920
3035
|
return declare(u => u instanceof constructor, annotations);
|
|
2921
3036
|
}
|
|
2922
3037
|
/**
|
|
2923
|
-
* Constructs an `
|
|
3038
|
+
* Constructs an `SchemaAST.Link` that describes how a value of type `T` encodes to and decodes from a `To` schema.
|
|
2924
3039
|
* Used when building low-level AST transformations that bridge two schema types.
|
|
2925
3040
|
*
|
|
2926
3041
|
* @category transforming
|
|
@@ -2928,7 +3043,7 @@ export function instanceOf(constructor, annotations) {
|
|
|
2928
3043
|
*/
|
|
2929
3044
|
export function link() {
|
|
2930
3045
|
return (encodeTo, transformation) => {
|
|
2931
|
-
return new
|
|
3046
|
+
return new SchemaAST.Link(encodeTo.ast, SchemaTransformation.make(transformation));
|
|
2932
3047
|
};
|
|
2933
3048
|
}
|
|
2934
3049
|
// -----------------------------------------------------------------------------
|
|
@@ -2992,16 +3107,16 @@ export function link() {
|
|
|
2992
3107
|
* @category constructors
|
|
2993
3108
|
* @since 4.0.0
|
|
2994
3109
|
*/
|
|
2995
|
-
export const makeFilter =
|
|
3110
|
+
export const makeFilter = SchemaAST.makeFilter;
|
|
2996
3111
|
/**
|
|
2997
|
-
* Groups multiple checks into a single {@link
|
|
3112
|
+
* Groups multiple checks into a single {@link SchemaAST.FilterGroup}, applying
|
|
2998
3113
|
* optional shared annotations to the group as a whole.
|
|
2999
3114
|
*
|
|
3000
3115
|
* @category constructors
|
|
3001
3116
|
* @since 4.0.0
|
|
3002
3117
|
*/
|
|
3003
3118
|
export function makeFilterGroup(checks, annotations = undefined) {
|
|
3004
|
-
return new
|
|
3119
|
+
return new SchemaAST.FilterGroup(checks, annotations);
|
|
3005
3120
|
}
|
|
3006
3121
|
const TRIMMED_PATTERN = "^\\S[\\s\\S]*\\S$|^\\S$|^$";
|
|
3007
3122
|
/**
|
|
@@ -3054,7 +3169,7 @@ export function isTrimmed(annotations) {
|
|
|
3054
3169
|
* @category String checks
|
|
3055
3170
|
* @since 4.0.0
|
|
3056
3171
|
*/
|
|
3057
|
-
export const isPattern =
|
|
3172
|
+
export const isPattern = SchemaAST.isPattern;
|
|
3058
3173
|
/**
|
|
3059
3174
|
* Validates that a string represents a finite number.
|
|
3060
3175
|
*
|
|
@@ -3073,7 +3188,7 @@ export const isPattern = AST.isPattern;
|
|
|
3073
3188
|
* @category String checks
|
|
3074
3189
|
* @since 4.0.0
|
|
3075
3190
|
*/
|
|
3076
|
-
export const isStringFinite =
|
|
3191
|
+
export const isStringFinite = SchemaAST.isStringFinite;
|
|
3077
3192
|
/**
|
|
3078
3193
|
* Validates that a string is a signed base-10 integer literal for Effect's
|
|
3079
3194
|
* BigInt string encoding.
|
|
@@ -3091,7 +3206,7 @@ export const isStringFinite = AST.isStringFinite;
|
|
|
3091
3206
|
* @category String checks
|
|
3092
3207
|
* @since 4.0.0
|
|
3093
3208
|
*/
|
|
3094
|
-
export const isStringBigInt =
|
|
3209
|
+
export const isStringBigInt = SchemaAST.isStringBigInt;
|
|
3095
3210
|
/**
|
|
3096
3211
|
* Validates that a string has the `Symbol(description)` format used by Effect's
|
|
3097
3212
|
* symbol string encoding.
|
|
@@ -3104,7 +3219,7 @@ export const isStringBigInt = AST.isStringBigInt;
|
|
|
3104
3219
|
* @category String checks
|
|
3105
3220
|
* @since 4.0.0
|
|
3106
3221
|
*/
|
|
3107
|
-
export const isStringSymbol =
|
|
3222
|
+
export const isStringSymbol = SchemaAST.isStringSymbol;
|
|
3108
3223
|
/**
|
|
3109
3224
|
* Returns a RegExp for validating an RFC 4122 UUID.
|
|
3110
3225
|
*
|
|
@@ -3836,7 +3951,7 @@ export function isInt(annotations) {
|
|
|
3836
3951
|
* @since 4.0.0
|
|
3837
3952
|
*/
|
|
3838
3953
|
export function isInt32(annotations) {
|
|
3839
|
-
return new
|
|
3954
|
+
return new SchemaAST.FilterGroup([isInt(annotations), isBetween({
|
|
3840
3955
|
minimum: -2147483648,
|
|
3841
3956
|
maximum: 2147483647
|
|
3842
3957
|
})], {
|
|
@@ -3864,7 +3979,7 @@ export function isInt32(annotations) {
|
|
|
3864
3979
|
* @since 4.0.0
|
|
3865
3980
|
*/
|
|
3866
3981
|
export function isUint32(annotations) {
|
|
3867
|
-
return new
|
|
3982
|
+
return new SchemaAST.FilterGroup([isInt(), isBetween({
|
|
3868
3983
|
minimum: 0,
|
|
3869
3984
|
maximum: 4294967295
|
|
3870
3985
|
})], {
|
|
@@ -4306,7 +4421,7 @@ export function isMinLength(minLength, annotations) {
|
|
|
4306
4421
|
_tag: "isMinLength",
|
|
4307
4422
|
minLength
|
|
4308
4423
|
},
|
|
4309
|
-
[
|
|
4424
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
4310
4425
|
toArbitraryConstraint: {
|
|
4311
4426
|
string: {
|
|
4312
4427
|
minLength
|
|
@@ -4368,7 +4483,7 @@ export function isMaxLength(maxLength, annotations) {
|
|
|
4368
4483
|
_tag: "isMaxLength",
|
|
4369
4484
|
maxLength
|
|
4370
4485
|
},
|
|
4371
|
-
[
|
|
4486
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
4372
4487
|
toArbitraryConstraint: {
|
|
4373
4488
|
string: {
|
|
4374
4489
|
maxLength
|
|
@@ -4410,7 +4525,7 @@ export function isLengthBetween(minimum, maximum, annotations) {
|
|
|
4410
4525
|
minimum,
|
|
4411
4526
|
maximum
|
|
4412
4527
|
},
|
|
4413
|
-
[
|
|
4528
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
4414
4529
|
toArbitraryConstraint: {
|
|
4415
4530
|
string: {
|
|
4416
4531
|
minLength: minimum,
|
|
@@ -4452,7 +4567,7 @@ export function isMinSize(minSize, annotations) {
|
|
|
4452
4567
|
_tag: "isMinSize",
|
|
4453
4568
|
minSize
|
|
4454
4569
|
},
|
|
4455
|
-
[
|
|
4570
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
4456
4571
|
toArbitraryConstraint: {
|
|
4457
4572
|
array: {
|
|
4458
4573
|
minLength: minSize
|
|
@@ -4489,7 +4604,7 @@ export function isMaxSize(maxSize, annotations) {
|
|
|
4489
4604
|
_tag: "isMaxSize",
|
|
4490
4605
|
maxSize
|
|
4491
4606
|
},
|
|
4492
|
-
[
|
|
4607
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
4493
4608
|
toArbitraryConstraint: {
|
|
4494
4609
|
array: {
|
|
4495
4610
|
maxLength: maxSize
|
|
@@ -4528,7 +4643,7 @@ export function isSizeBetween(minimum, maximum, annotations) {
|
|
|
4528
4643
|
minimum,
|
|
4529
4644
|
maximum
|
|
4530
4645
|
},
|
|
4531
|
-
[
|
|
4646
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
4532
4647
|
toArbitraryConstraint: {
|
|
4533
4648
|
array: {
|
|
4534
4649
|
minLength: minimum,
|
|
@@ -4567,7 +4682,7 @@ export function isMinProperties(minProperties, annotations) {
|
|
|
4567
4682
|
_tag: "isMinProperties",
|
|
4568
4683
|
minProperties
|
|
4569
4684
|
},
|
|
4570
|
-
[
|
|
4685
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
4571
4686
|
toArbitraryConstraint: {
|
|
4572
4687
|
array: {
|
|
4573
4688
|
minLength: minProperties
|
|
@@ -4604,7 +4719,7 @@ export function isMaxProperties(maxProperties, annotations) {
|
|
|
4604
4719
|
_tag: "isMaxProperties",
|
|
4605
4720
|
maxProperties
|
|
4606
4721
|
},
|
|
4607
|
-
[
|
|
4722
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
4608
4723
|
toArbitraryConstraint: {
|
|
4609
4724
|
array: {
|
|
4610
4725
|
maxLength: maxProperties
|
|
@@ -4643,7 +4758,7 @@ export function isPropertiesLengthBetween(minimum, maximum, annotations) {
|
|
|
4643
4758
|
minimum,
|
|
4644
4759
|
maximum
|
|
4645
4760
|
},
|
|
4646
|
-
[
|
|
4761
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
4647
4762
|
toArbitraryConstraint: {
|
|
4648
4763
|
array: {
|
|
4649
4764
|
minLength: minimum,
|
|
@@ -4671,19 +4786,19 @@ export function isPropertiesLengthBetween(minimum, maximum, annotations) {
|
|
|
4671
4786
|
*/
|
|
4672
4787
|
export function isPropertyNames(keySchema, annotations) {
|
|
4673
4788
|
const propertyNames = toEncoded(keySchema);
|
|
4674
|
-
const parser =
|
|
4789
|
+
const parser = SchemaParser._issue(propertyNames.ast);
|
|
4675
4790
|
return makeFilter((input, ast, options) => {
|
|
4676
4791
|
const keys = Reflect.ownKeys(input);
|
|
4677
4792
|
const issues = [];
|
|
4678
4793
|
for (const key of keys) {
|
|
4679
4794
|
const issue = parser(key, options);
|
|
4680
4795
|
if (issue !== undefined) {
|
|
4681
|
-
issues.push(new
|
|
4796
|
+
issues.push(new SchemaIssue.Pointer([key], issue));
|
|
4682
4797
|
if (options.errors === "first") break;
|
|
4683
4798
|
}
|
|
4684
4799
|
}
|
|
4685
4800
|
if (Arr.isArrayNonEmpty(issues)) {
|
|
4686
|
-
return new
|
|
4801
|
+
return new SchemaIssue.Composite(ast, Option_.some(input), issues);
|
|
4687
4802
|
}
|
|
4688
4803
|
return true;
|
|
4689
4804
|
}, {
|
|
@@ -4692,7 +4807,7 @@ export function isPropertyNames(keySchema, annotations) {
|
|
|
4692
4807
|
_tag: "isPropertyNames",
|
|
4693
4808
|
propertyNames: propertyNames.ast
|
|
4694
4809
|
},
|
|
4695
|
-
[
|
|
4810
|
+
[SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
|
|
4696
4811
|
...annotations
|
|
4697
4812
|
});
|
|
4698
4813
|
}
|
|
@@ -4766,12 +4881,12 @@ export function Option(value) {
|
|
|
4766
4881
|
if (Option_.isNone(input)) {
|
|
4767
4882
|
return Effect.succeedNone;
|
|
4768
4883
|
}
|
|
4769
|
-
return Effect.mapBothEager(
|
|
4884
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(value)(input.value, options), {
|
|
4770
4885
|
onSuccess: Option_.some,
|
|
4771
|
-
onFailure: issue => new
|
|
4886
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["value"], issue)])
|
|
4772
4887
|
});
|
|
4773
4888
|
}
|
|
4774
|
-
return Effect.fail(new
|
|
4889
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
4775
4890
|
}, {
|
|
4776
4891
|
typeConstructor: {
|
|
4777
4892
|
_tag: "effect/Option"
|
|
@@ -4787,7 +4902,7 @@ export function Option(value) {
|
|
|
4787
4902
|
value
|
|
4788
4903
|
}), Struct({
|
|
4789
4904
|
_tag: Literal("None")
|
|
4790
|
-
})]),
|
|
4905
|
+
})]), SchemaTransformation.transform({
|
|
4791
4906
|
decode: e => e._tag === "None" ? Option_.none() : Option_.some(e.value),
|
|
4792
4907
|
encode: o => Option_.isSome(o) ? {
|
|
4793
4908
|
_tag: "Some",
|
|
@@ -4817,97 +4932,75 @@ export function Option(value) {
|
|
|
4817
4932
|
*
|
|
4818
4933
|
* **Details**
|
|
4819
4934
|
*
|
|
4820
|
-
* Decoding
|
|
4821
|
-
*
|
|
4822
|
-
* - other values are decoded as `Some`
|
|
4823
|
-
*
|
|
4824
|
-
* Encoding:
|
|
4825
|
-
* - `None` is encoded as `null`
|
|
4826
|
-
* - `Some` is encoded as the value
|
|
4935
|
+
* Decoding maps `null` to `None` and all other values to `Some`. Encoding maps
|
|
4936
|
+
* `None` to `null` and maps `Some` to its value.
|
|
4827
4937
|
*
|
|
4828
4938
|
* @category Option
|
|
4829
4939
|
* @since 3.10.0
|
|
4830
4940
|
*/
|
|
4831
4941
|
export function OptionFromNullOr(schema) {
|
|
4832
|
-
return NullOr(schema).pipe(decodeTo(Option(toType(schema)),
|
|
4942
|
+
return NullOr(schema).pipe(decodeTo(Option(toType(schema)), SchemaTransformation.optionFromNullOr()));
|
|
4833
4943
|
}
|
|
4834
4944
|
/**
|
|
4835
|
-
* Decodes
|
|
4945
|
+
* Decodes a required value that may be `undefined` to a required `Option<T>`
|
|
4946
|
+
* value.
|
|
4836
4947
|
*
|
|
4837
4948
|
* **Details**
|
|
4838
4949
|
*
|
|
4839
|
-
* Decoding
|
|
4840
|
-
*
|
|
4841
|
-
* - other values are decoded as `Some`
|
|
4842
|
-
*
|
|
4843
|
-
* Encoding:
|
|
4844
|
-
* - `None` is encoded as `undefined`
|
|
4845
|
-
* - `Some` is encoded as the value
|
|
4950
|
+
* Decoding maps `undefined` to `None` and all other values to `Some`. Encoding
|
|
4951
|
+
* maps `None` to `undefined` and maps `Some` to its value.
|
|
4846
4952
|
*
|
|
4847
4953
|
* @category Option
|
|
4848
4954
|
* @since 3.10.0
|
|
4849
4955
|
*/
|
|
4850
4956
|
export function OptionFromUndefinedOr(schema) {
|
|
4851
|
-
return UndefinedOr(schema).pipe(decodeTo(Option(toType(schema)),
|
|
4957
|
+
return UndefinedOr(schema).pipe(decodeTo(Option(toType(schema)), SchemaTransformation.optionFromUndefinedOr()));
|
|
4852
4958
|
}
|
|
4853
4959
|
/**
|
|
4854
4960
|
* Decodes a nullish value `T` to a required `Option<T>` value.
|
|
4855
4961
|
*
|
|
4856
4962
|
* **Details**
|
|
4857
4963
|
*
|
|
4858
|
-
* Decoding
|
|
4859
|
-
*
|
|
4860
|
-
*
|
|
4861
|
-
*
|
|
4862
|
-
* Encoding:
|
|
4863
|
-
* - `None` is encoded as `null` or `undefined` depending on the provided `options.onNoneEncoding` (defaults to `undefined`)
|
|
4864
|
-
* - `Some` is encoded as the value
|
|
4964
|
+
* Decoding maps `null` and `undefined` to `None` and all other values to
|
|
4965
|
+
* `Some`. Encoding maps `None` to `null` or `undefined` depending on
|
|
4966
|
+
* `options.onNoneEncoding`, which defaults to `undefined`, and maps `Some` to
|
|
4967
|
+
* its value.
|
|
4865
4968
|
*
|
|
4866
4969
|
* @category Option
|
|
4867
4970
|
* @since 3.10.0
|
|
4868
4971
|
*/
|
|
4869
4972
|
export function OptionFromNullishOr(schema, options) {
|
|
4870
|
-
return NullishOr(schema).pipe(decodeTo(Option(toType(schema)),
|
|
4973
|
+
return NullishOr(schema).pipe(decodeTo(Option(toType(schema)), SchemaTransformation.optionFromNullishOr(options)));
|
|
4871
4974
|
}
|
|
4872
4975
|
/**
|
|
4873
4976
|
* Decodes an optional value `A` to a required `Option<A>` value.
|
|
4874
4977
|
*
|
|
4875
4978
|
* **Details**
|
|
4876
4979
|
*
|
|
4877
|
-
* Decoding
|
|
4878
|
-
*
|
|
4879
|
-
* - a present value is decoded as `Some`
|
|
4880
|
-
*
|
|
4881
|
-
* Encoding:
|
|
4882
|
-
* - `None` is encoded as missing key
|
|
4883
|
-
* - `Some` is encoded as the value
|
|
4980
|
+
* Decoding maps a missing key to `None` and a present value to `Some`.
|
|
4981
|
+
* Encoding maps `None` to a missing key and maps `Some` to its value.
|
|
4884
4982
|
*
|
|
4885
4983
|
* @category Option
|
|
4886
4984
|
* @since 4.0.0
|
|
4887
4985
|
*/
|
|
4888
4986
|
export function OptionFromOptionalKey(schema) {
|
|
4889
|
-
return optionalKey(schema).pipe(decodeTo(Option(toType(schema)),
|
|
4987
|
+
return optionalKey(schema).pipe(decodeTo(Option(toType(schema)), SchemaTransformation.optionFromOptionalKey()));
|
|
4890
4988
|
}
|
|
4891
4989
|
/**
|
|
4892
|
-
* Decodes an optional or `undefined` value `A` to
|
|
4990
|
+
* Decodes an optional or `undefined` value `A` to a required `Option<A>`
|
|
4893
4991
|
* value.
|
|
4894
4992
|
*
|
|
4895
4993
|
* **Details**
|
|
4896
4994
|
*
|
|
4897
|
-
* Decoding
|
|
4898
|
-
*
|
|
4899
|
-
*
|
|
4900
|
-
* - all other values are decoded as `Some`
|
|
4901
|
-
*
|
|
4902
|
-
* Encoding:
|
|
4903
|
-
* - `None` is encoded as missing key
|
|
4904
|
-
* - `Some` is encoded as the value
|
|
4995
|
+
* Decoding maps a missing key or a present `undefined` value to `None`, and
|
|
4996
|
+
* maps all other values to `Some`. Encoding maps `None` to a missing key and
|
|
4997
|
+
* maps `Some` to its value.
|
|
4905
4998
|
*
|
|
4906
4999
|
* @category Option
|
|
4907
5000
|
* @since 4.0.0
|
|
4908
5001
|
*/
|
|
4909
5002
|
export function OptionFromOptional(schema) {
|
|
4910
|
-
return optional(schema).pipe(decodeTo(Option(toType(schema)),
|
|
5003
|
+
return optional(schema).pipe(decodeTo(Option(toType(schema)), SchemaTransformation.optionFromOptional()));
|
|
4911
5004
|
}
|
|
4912
5005
|
/**
|
|
4913
5006
|
* Decodes an optional or `null` or `undefined` value `A` to a required `Option<A>`
|
|
@@ -4915,17 +5008,10 @@ export function OptionFromOptional(schema) {
|
|
|
4915
5008
|
*
|
|
4916
5009
|
* **Details**
|
|
4917
5010
|
*
|
|
4918
|
-
* Decoding
|
|
4919
|
-
*
|
|
4920
|
-
*
|
|
4921
|
-
*
|
|
4922
|
-
* - all other values are decoded as `Some`
|
|
4923
|
-
*
|
|
4924
|
-
* Encoding (controlled by `options.onNoneEncoding`):
|
|
4925
|
-
* - `"omit"` (default): `None` is encoded as a missing key
|
|
4926
|
-
* - `null`: `None` is encoded as `null`
|
|
4927
|
-
* - `undefined`: `None` is encoded as `undefined`
|
|
4928
|
-
* - `Some` is always encoded as the value
|
|
5011
|
+
* Decoding maps a missing key, `undefined`, or `null` to `None`, and maps all
|
|
5012
|
+
* other values to `Some`. Encoding maps `Some` to its value. `None` is encoded
|
|
5013
|
+
* according to `options.onNoneEncoding`: `"omit"` encodes a missing key,
|
|
5014
|
+
* `null` encodes `null`, and `undefined` encodes `undefined`.
|
|
4929
5015
|
*
|
|
4930
5016
|
* @category Option
|
|
4931
5017
|
* @since 4.0.0
|
|
@@ -4933,7 +5019,7 @@ export function OptionFromOptional(schema) {
|
|
|
4933
5019
|
export function OptionFromOptionalNullOr(schema, options) {
|
|
4934
5020
|
const onNoneEncoding = options === undefined ? "omit" : options.onNoneEncoding;
|
|
4935
5021
|
const noneValue = onNoneEncoding === null ? null : undefined;
|
|
4936
|
-
return optional(NullOr(schema)).pipe(decodeTo(Option(toType(schema)),
|
|
5022
|
+
return optional(NullOr(schema)).pipe(decodeTo(Option(toType(schema)), SchemaTransformation.transformOptional({
|
|
4937
5023
|
decode: oe => oe.pipe(Option_.filter(Predicate.isNotNullish), Option_.some),
|
|
4938
5024
|
encode: onNoneEncoding === "omit" ? Option_.flatten : ot => Option_.some(Option_.getOrElse(Option_.flatten(ot), () => noneValue))
|
|
4939
5025
|
})));
|
|
@@ -4947,18 +5033,18 @@ export function OptionFromOptionalNullOr(schema, options) {
|
|
|
4947
5033
|
export function Result(success, failure) {
|
|
4948
5034
|
const schema = declareConstructor()([success, failure], ([success, failure]) => (input, ast, options) => {
|
|
4949
5035
|
if (!Result_.isResult(input)) {
|
|
4950
|
-
return Effect.fail(new
|
|
5036
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
4951
5037
|
}
|
|
4952
5038
|
switch (input._tag) {
|
|
4953
5039
|
case "Success":
|
|
4954
|
-
return Effect.mapBothEager(
|
|
5040
|
+
return Effect.mapBothEager(SchemaParser.decodeEffect(success)(input.success, options), {
|
|
4955
5041
|
onSuccess: Result_.succeed,
|
|
4956
|
-
onFailure: issue => new
|
|
5042
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["success"], issue)])
|
|
4957
5043
|
});
|
|
4958
5044
|
case "Failure":
|
|
4959
|
-
return Effect.mapBothEager(
|
|
5045
|
+
return Effect.mapBothEager(SchemaParser.decodeEffect(failure)(input.failure, options), {
|
|
4960
5046
|
onSuccess: Result_.fail,
|
|
4961
|
-
onFailure: issue => new
|
|
5047
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["failure"], issue)])
|
|
4962
5048
|
});
|
|
4963
5049
|
}
|
|
4964
5050
|
}, {
|
|
@@ -4977,7 +5063,7 @@ export function Result(success, failure) {
|
|
|
4977
5063
|
}), Struct({
|
|
4978
5064
|
_tag: Literal("Failure"),
|
|
4979
5065
|
failure
|
|
4980
|
-
})]),
|
|
5066
|
+
})]), SchemaTransformation.transform({
|
|
4981
5067
|
decode: e => e._tag === "Success" ? Result_.succeed(e.success) : Result_.fail(e.failure),
|
|
4982
5068
|
encode: r => Result_.isSuccess(r) ? {
|
|
4983
5069
|
_tag: "Success",
|
|
@@ -5028,35 +5114,36 @@ export function Result(success, failure) {
|
|
|
5028
5114
|
* @since 3.10.0
|
|
5029
5115
|
*/
|
|
5030
5116
|
export function Redacted(value, options) {
|
|
5031
|
-
const decodeLabel = typeof options?.label === "string" ?
|
|
5117
|
+
const decodeLabel = typeof options?.label === "string" ? SchemaParser.decodeUnknownEffect(Literal(options.label)) : undefined;
|
|
5032
5118
|
const schema = declareConstructor()([value], ([value]) => (input, ast, poptions) => {
|
|
5033
5119
|
if (Redacted_.isRedacted(input)) {
|
|
5034
|
-
const label = decodeLabel !== undefined ? Effect.mapErrorEager(decodeLabel(input.label, poptions), issue => new
|
|
5035
|
-
return Effect.flatMapEager(label, () => Effect.mapBothEager(
|
|
5120
|
+
const label = decodeLabel !== undefined ? Effect.mapErrorEager(decodeLabel(input.label, poptions), issue => new SchemaIssue.Pointer(["label"], issue)) : Effect.void;
|
|
5121
|
+
return Effect.flatMapEager(label, () => Effect.mapBothEager(SchemaParser.decodeUnknownEffect(value)(Redacted_.value(input), poptions), {
|
|
5036
5122
|
onSuccess: () => input,
|
|
5037
5123
|
onFailure: (/** ignore the actual issue because of security reasons */
|
|
5038
5124
|
) => {
|
|
5039
5125
|
const oinput = Option_.some(input);
|
|
5040
|
-
return new
|
|
5126
|
+
return new SchemaIssue.Composite(ast, oinput, [new SchemaIssue.Pointer(["value"], new SchemaIssue.InvalidValue(oinput))]);
|
|
5041
5127
|
}
|
|
5042
5128
|
}));
|
|
5043
5129
|
}
|
|
5044
|
-
return Effect.fail(new
|
|
5130
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
5045
5131
|
}, {
|
|
5046
5132
|
typeConstructor: {
|
|
5047
|
-
_tag: "effect/Redacted"
|
|
5133
|
+
_tag: "effect/Redacted",
|
|
5134
|
+
options
|
|
5048
5135
|
},
|
|
5049
5136
|
generation: {
|
|
5050
|
-
runtime: `Schema.Redacted(?)`,
|
|
5137
|
+
runtime: options !== undefined ? `Schema.Redacted(?, ${format(options)})` : `Schema.Redacted(?)`,
|
|
5051
5138
|
Type: `Redacted.Redacted<?>`,
|
|
5052
5139
|
importDeclaration: `import * as Redacted from "effect/Redacted"`
|
|
5053
5140
|
},
|
|
5054
5141
|
expected: "Redacted",
|
|
5055
5142
|
toCodecJson: ([value]) => link()(redact(value), {
|
|
5056
|
-
decode:
|
|
5143
|
+
decode: SchemaGetter.transform(e => Redacted_.make(e, {
|
|
5057
5144
|
label: options?.label
|
|
5058
5145
|
})),
|
|
5059
|
-
encode: options?.disallowJsonEncode ?
|
|
5146
|
+
encode: options?.disallowJsonEncode ? SchemaGetter.forbidden(oe => "Cannot serialize Redacted" + (Option_.isSome(oe) && typeof oe.value.label === "string" ? ` with label: "${oe.value.label}"` : "")) : SchemaGetter.transform(Redacted_.value)
|
|
5060
5147
|
}),
|
|
5061
5148
|
toArbitrary: ([value]) => () => value.map(a => Redacted_.make(a, {
|
|
5062
5149
|
label: options?.label
|
|
@@ -5076,7 +5163,7 @@ export function Redacted(value, options) {
|
|
|
5076
5163
|
* @since 4.0.0
|
|
5077
5164
|
*/
|
|
5078
5165
|
export function redact(schema) {
|
|
5079
|
-
return schema.pipe(middlewareDecoding(Effect.mapErrorEager(
|
|
5166
|
+
return schema.pipe(middlewareDecoding(Effect.mapErrorEager(SchemaIssue.redact)));
|
|
5080
5167
|
}
|
|
5081
5168
|
/**
|
|
5082
5169
|
* Decodes a value and wraps it in `Redacted<A>`. Unlike {@link Redacted} which
|
|
@@ -5091,10 +5178,10 @@ export function RedactedFromValue(value, options) {
|
|
|
5091
5178
|
label: options?.label,
|
|
5092
5179
|
disallowJsonEncode: options?.disallowEncode
|
|
5093
5180
|
}), {
|
|
5094
|
-
decode:
|
|
5181
|
+
decode: SchemaGetter.transform(t => Redacted_.make(t, {
|
|
5095
5182
|
label: options?.label
|
|
5096
5183
|
})),
|
|
5097
|
-
encode: options?.disallowEncode ?
|
|
5184
|
+
encode: options?.disallowEncode ? SchemaGetter.forbidden(oe => "Cannot encode Redacted" + (Option_.isSome(oe) && typeof oe.value.label === "string" ? ` with label: "${oe.value.label}"` : "")) : SchemaGetter.transform(Redacted_.value)
|
|
5098
5185
|
}));
|
|
5099
5186
|
}
|
|
5100
5187
|
/**
|
|
@@ -5103,8 +5190,8 @@ export function RedactedFromValue(value, options) {
|
|
|
5103
5190
|
*
|
|
5104
5191
|
* **When to use**
|
|
5105
5192
|
*
|
|
5106
|
-
* Use
|
|
5107
|
-
*
|
|
5193
|
+
* Use when serializing or decoding individual cause reasons separately from a
|
|
5194
|
+
* full failure cause, with distinct schemas for typed errors and defects.
|
|
5108
5195
|
*
|
|
5109
5196
|
* **Details**
|
|
5110
5197
|
*
|
|
@@ -5120,18 +5207,18 @@ export function RedactedFromValue(value, options) {
|
|
|
5120
5207
|
export function CauseReason(error, defect) {
|
|
5121
5208
|
const schema = declareConstructor()([error, defect], ([error, defect]) => (input, ast, options) => {
|
|
5122
5209
|
if (!Cause_.isReason(input)) {
|
|
5123
|
-
return Effect.fail(new
|
|
5210
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
5124
5211
|
}
|
|
5125
5212
|
switch (input._tag) {
|
|
5126
5213
|
case "Fail":
|
|
5127
|
-
return Effect.mapBothEager(
|
|
5214
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(error)(input.error, options), {
|
|
5128
5215
|
onSuccess: Cause_.makeFailReason,
|
|
5129
|
-
onFailure: issue => new
|
|
5216
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["error"], issue)])
|
|
5130
5217
|
});
|
|
5131
5218
|
case "Die":
|
|
5132
|
-
return Effect.mapBothEager(
|
|
5219
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(defect)(input.defect, options), {
|
|
5133
5220
|
onSuccess: Cause_.makeDieReason,
|
|
5134
|
-
onFailure: issue => new
|
|
5221
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["defect"], issue)])
|
|
5135
5222
|
});
|
|
5136
5223
|
case "Interrupt":
|
|
5137
5224
|
return Effect.succeed(input);
|
|
@@ -5155,7 +5242,7 @@ export function CauseReason(error, defect) {
|
|
|
5155
5242
|
}), Struct({
|
|
5156
5243
|
_tag: Literal("Interrupt"),
|
|
5157
5244
|
fiberId: UndefinedOr(Finite)
|
|
5158
|
-
})]),
|
|
5245
|
+
})]), SchemaTransformation.transform({
|
|
5159
5246
|
decode: e => {
|
|
5160
5247
|
switch (e._tag) {
|
|
5161
5248
|
case "Fail":
|
|
@@ -5238,11 +5325,11 @@ export function Cause(error, defect) {
|
|
|
5238
5325
|
const failures = ArraySchema(CauseReason(error, defect));
|
|
5239
5326
|
return (input, ast, options) => {
|
|
5240
5327
|
if (!Cause_.isCause(input)) {
|
|
5241
|
-
return Effect.fail(new
|
|
5328
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
5242
5329
|
}
|
|
5243
|
-
return Effect.mapBothEager(
|
|
5330
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(failures)(input.reasons, options), {
|
|
5244
5331
|
onSuccess: Cause_.fromReasons,
|
|
5245
|
-
onFailure: issue => new
|
|
5332
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["failures"], issue)])
|
|
5246
5333
|
});
|
|
5247
5334
|
};
|
|
5248
5335
|
}, {
|
|
@@ -5255,7 +5342,7 @@ export function Cause(error, defect) {
|
|
|
5255
5342
|
importDeclaration: `import * as Cause from "effect/Cause"`
|
|
5256
5343
|
},
|
|
5257
5344
|
expected: "Cause",
|
|
5258
|
-
toCodec: ([error, defect]) => link()(ArraySchema(CauseReason(error, defect)),
|
|
5345
|
+
toCodec: ([error, defect]) => link()(ArraySchema(CauseReason(error, defect)), SchemaTransformation.transform({
|
|
5259
5346
|
decode: Cause_.fromReasons,
|
|
5260
5347
|
encode: ({
|
|
5261
5348
|
reasons: failures
|
|
@@ -5310,7 +5397,7 @@ export const Error = /*#__PURE__*/instanceOf(globalThis.Error, {
|
|
|
5310
5397
|
Type: `globalThis.Error`
|
|
5311
5398
|
},
|
|
5312
5399
|
expected: "Error",
|
|
5313
|
-
toCodecJson: () => link()(ErrorJsonEncoded,
|
|
5400
|
+
toCodecJson: () => link()(ErrorJsonEncoded, SchemaTransformation.errorFromErrorJsonEncoded()),
|
|
5314
5401
|
toArbitrary: () => fc => fc.string().map(message => new globalThis.Error(message))
|
|
5315
5402
|
});
|
|
5316
5403
|
/**
|
|
@@ -5335,12 +5422,12 @@ export const ErrorWithStack = /*#__PURE__*/instanceOf(globalThis.Error, {
|
|
|
5335
5422
|
Type: `globalThis.Error`
|
|
5336
5423
|
},
|
|
5337
5424
|
expected: "Error",
|
|
5338
|
-
toCodecJson: () => link()(ErrorJsonEncoded,
|
|
5425
|
+
toCodecJson: () => link()(ErrorJsonEncoded, SchemaTransformation.errorFromErrorJsonEncoded({
|
|
5339
5426
|
includeStack: true
|
|
5340
5427
|
})),
|
|
5341
5428
|
toArbitrary: () => fc => fc.string().map(message => new globalThis.Error(message))
|
|
5342
5429
|
});
|
|
5343
|
-
const defectTransformation = /*#__PURE__*/new
|
|
5430
|
+
const defectTransformation = /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.passthrough(), /*#__PURE__*/SchemaGetter.transform(u => {
|
|
5344
5431
|
try {
|
|
5345
5432
|
return JSON.parse(JSON.stringify(u));
|
|
5346
5433
|
} catch {
|
|
@@ -5360,7 +5447,7 @@ const defectTransformation = /*#__PURE__*/new Transformation.Transformation(/*#_
|
|
|
5360
5447
|
* @category constructors
|
|
5361
5448
|
* @since 3.10.0
|
|
5362
5449
|
*/
|
|
5363
|
-
export const Defect = /*#__PURE__*/Union([/*#__PURE__*/ErrorJsonEncoded.pipe(/*#__PURE__*/decodeTo(Error, /*#__PURE__*/
|
|
5450
|
+
export const Defect = /*#__PURE__*/Union([/*#__PURE__*/ErrorJsonEncoded.pipe(/*#__PURE__*/decodeTo(Error, /*#__PURE__*/SchemaTransformation.errorFromErrorJsonEncoded())), /*#__PURE__*/Any.pipe(/*#__PURE__*/decodeTo(/*#__PURE__*/Unknown.annotate({
|
|
5364
5451
|
toCodecJson: () => link()(Any, defectTransformation),
|
|
5365
5452
|
toArbitrary: () => fc => fc.json()
|
|
5366
5453
|
}), defectTransformation))]);
|
|
@@ -5370,7 +5457,7 @@ export const Defect = /*#__PURE__*/Union([/*#__PURE__*/ErrorJsonEncoded.pipe(/*#
|
|
|
5370
5457
|
* @category Defect
|
|
5371
5458
|
* @since 4.0.0
|
|
5372
5459
|
*/
|
|
5373
|
-
export const DefectWithStack = /*#__PURE__*/Union([/*#__PURE__*/ErrorJsonEncoded.pipe(/*#__PURE__*/decodeTo(ErrorWithStack, /*#__PURE__*/
|
|
5460
|
+
export const DefectWithStack = /*#__PURE__*/Union([/*#__PURE__*/ErrorJsonEncoded.pipe(/*#__PURE__*/decodeTo(ErrorWithStack, /*#__PURE__*/SchemaTransformation.errorFromErrorJsonEncoded({
|
|
5374
5461
|
includeStack: true
|
|
5375
5462
|
}))), /*#__PURE__*/Any.pipe(/*#__PURE__*/decodeTo(/*#__PURE__*/Unknown.annotate({
|
|
5376
5463
|
toCodecJson: () => link()(Any, defectTransformation),
|
|
@@ -5380,6 +5467,11 @@ export const DefectWithStack = /*#__PURE__*/Union([/*#__PURE__*/ErrorJsonEncoded
|
|
|
5380
5467
|
* Creates a schema for `Exit` values using schemas for the success value, typed
|
|
5381
5468
|
* failure, and unexpected defect channels.
|
|
5382
5469
|
*
|
|
5470
|
+
* **When to use**
|
|
5471
|
+
*
|
|
5472
|
+
* Use when serializing or validating an effect outcome where success, typed
|
|
5473
|
+
* failure, and defects each need their own schema.
|
|
5474
|
+
*
|
|
5383
5475
|
* @category Exit
|
|
5384
5476
|
* @since 3.10.0
|
|
5385
5477
|
*/
|
|
@@ -5388,18 +5480,18 @@ export function Exit(value, error, defect) {
|
|
|
5388
5480
|
const cause = Cause(error, defect);
|
|
5389
5481
|
return (input, ast, options) => {
|
|
5390
5482
|
if (!Exit_.isExit(input)) {
|
|
5391
|
-
return Effect.fail(new
|
|
5483
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
5392
5484
|
}
|
|
5393
5485
|
switch (input._tag) {
|
|
5394
5486
|
case "Success":
|
|
5395
|
-
return Effect.mapBothEager(
|
|
5487
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(value)(input.value, options), {
|
|
5396
5488
|
onSuccess: Exit_.succeed,
|
|
5397
|
-
onFailure: issue => new
|
|
5489
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["value"], issue)])
|
|
5398
5490
|
});
|
|
5399
5491
|
case "Failure":
|
|
5400
|
-
return Effect.mapBothEager(
|
|
5492
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(cause)(input.cause, options), {
|
|
5401
5493
|
onSuccess: Exit_.failCause,
|
|
5402
|
-
onFailure: issue => new
|
|
5494
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["cause"], issue)])
|
|
5403
5495
|
});
|
|
5404
5496
|
}
|
|
5405
5497
|
};
|
|
@@ -5419,7 +5511,7 @@ export function Exit(value, error, defect) {
|
|
|
5419
5511
|
}), Struct({
|
|
5420
5512
|
_tag: Literal("Failure"),
|
|
5421
5513
|
cause: Cause(error, defect)
|
|
5422
|
-
})]),
|
|
5514
|
+
})]), SchemaTransformation.transform({
|
|
5423
5515
|
decode: e => e._tag === "Success" ? Exit_.succeed(e.value) : Exit_.failCause(e.cause),
|
|
5424
5516
|
encode: exit => Exit_.isSuccess(exit) ? {
|
|
5425
5517
|
_tag: "Success",
|
|
@@ -5475,12 +5567,12 @@ export function ReadonlyMap(key, value) {
|
|
|
5475
5567
|
const array = ArraySchema(Tuple([key, value]));
|
|
5476
5568
|
return (input, ast, options) => {
|
|
5477
5569
|
if (input instanceof globalThis.Map) {
|
|
5478
|
-
return Effect.mapBothEager(
|
|
5570
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(array)([...input], options), {
|
|
5479
5571
|
onSuccess: array => new globalThis.Map(array),
|
|
5480
|
-
onFailure: issue => new
|
|
5572
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["entries"], issue)])
|
|
5481
5573
|
});
|
|
5482
5574
|
}
|
|
5483
|
-
return Effect.fail(new
|
|
5575
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
5484
5576
|
};
|
|
5485
5577
|
}, {
|
|
5486
5578
|
typeConstructor: {
|
|
@@ -5491,7 +5583,7 @@ export function ReadonlyMap(key, value) {
|
|
|
5491
5583
|
Type: `globalThis.ReadonlyMap<?, ?>`
|
|
5492
5584
|
},
|
|
5493
5585
|
expected: "ReadonlyMap",
|
|
5494
|
-
toCodec: ([key, value]) => link()(ArraySchema(Tuple([key, value])),
|
|
5586
|
+
toCodec: ([key, value]) => link()(ArraySchema(Tuple([key, value])), SchemaTransformation.transform({
|
|
5495
5587
|
decode: e => new globalThis.Map(e),
|
|
5496
5588
|
encode: map => [...map.entries()]
|
|
5497
5589
|
})),
|
|
@@ -5527,12 +5619,12 @@ export function HashMap(key, value) {
|
|
|
5527
5619
|
const entries = ArraySchema(Tuple([key, value]));
|
|
5528
5620
|
return (input, ast, options) => {
|
|
5529
5621
|
if (HashMap_.isHashMap(input)) {
|
|
5530
|
-
return Effect.mapBothEager(
|
|
5622
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options), {
|
|
5531
5623
|
onSuccess: HashMap_.fromIterable,
|
|
5532
|
-
onFailure: issue => new
|
|
5624
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["entries"], issue)])
|
|
5533
5625
|
});
|
|
5534
5626
|
}
|
|
5535
|
-
return Effect.fail(new
|
|
5627
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
5536
5628
|
};
|
|
5537
5629
|
}, {
|
|
5538
5630
|
typeConstructor: {
|
|
@@ -5544,7 +5636,7 @@ export function HashMap(key, value) {
|
|
|
5544
5636
|
importDeclaration: `import * as HashMap from "effect/HashMap"`
|
|
5545
5637
|
},
|
|
5546
5638
|
expected: "HashMap",
|
|
5547
|
-
toCodec: ([key, value]) => link()(ArraySchema(Tuple([key, value])),
|
|
5639
|
+
toCodec: ([key, value]) => link()(ArraySchema(Tuple([key, value])), SchemaTransformation.transform({
|
|
5548
5640
|
decode: HashMap_.fromIterable,
|
|
5549
5641
|
encode: HashMap_.toEntries
|
|
5550
5642
|
})),
|
|
@@ -5580,12 +5672,12 @@ export function ReadonlySet(value) {
|
|
|
5580
5672
|
const array = ArraySchema(value);
|
|
5581
5673
|
return (input, ast, options) => {
|
|
5582
5674
|
if (input instanceof globalThis.Set) {
|
|
5583
|
-
return Effect.mapBothEager(
|
|
5675
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(array)([...input], options), {
|
|
5584
5676
|
onSuccess: array => new globalThis.Set(array),
|
|
5585
|
-
onFailure: issue => new
|
|
5677
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["values"], issue)])
|
|
5586
5678
|
});
|
|
5587
5679
|
}
|
|
5588
|
-
return Effect.fail(new
|
|
5680
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
5589
5681
|
};
|
|
5590
5682
|
}, {
|
|
5591
5683
|
typeConstructor: {
|
|
@@ -5596,7 +5688,7 @@ export function ReadonlySet(value) {
|
|
|
5596
5688
|
Type: `globalThis.ReadonlySet<?>`
|
|
5597
5689
|
},
|
|
5598
5690
|
expected: "ReadonlySet",
|
|
5599
|
-
toCodec: ([value]) => link()(ArraySchema(value),
|
|
5691
|
+
toCodec: ([value]) => link()(ArraySchema(value), SchemaTransformation.transform({
|
|
5600
5692
|
decode: e => new globalThis.Set(e),
|
|
5601
5693
|
encode: set => [...set.values()]
|
|
5602
5694
|
})),
|
|
@@ -5631,12 +5723,12 @@ export function HashSet(value) {
|
|
|
5631
5723
|
const values = ArraySchema(value);
|
|
5632
5724
|
return (input, ast, options) => {
|
|
5633
5725
|
if (HashSet_.isHashSet(input)) {
|
|
5634
|
-
return Effect.mapBothEager(
|
|
5726
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
|
|
5635
5727
|
onSuccess: HashSet_.fromIterable,
|
|
5636
|
-
onFailure: issue => new
|
|
5728
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["values"], issue)])
|
|
5637
5729
|
});
|
|
5638
5730
|
}
|
|
5639
|
-
return Effect.fail(new
|
|
5731
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
5640
5732
|
};
|
|
5641
5733
|
}, {
|
|
5642
5734
|
typeConstructor: {
|
|
@@ -5647,7 +5739,7 @@ export function HashSet(value) {
|
|
|
5647
5739
|
Type: `HashSet.HashSet<?>`
|
|
5648
5740
|
},
|
|
5649
5741
|
expected: "HashSet",
|
|
5650
|
-
toCodec: ([value]) => link()(ArraySchema(value),
|
|
5742
|
+
toCodec: ([value]) => link()(ArraySchema(value), SchemaTransformation.transform({
|
|
5651
5743
|
decode: HashSet_.fromIterable,
|
|
5652
5744
|
encode: Arr.fromIterable
|
|
5653
5745
|
})),
|
|
@@ -5682,12 +5774,12 @@ export function Chunk(value) {
|
|
|
5682
5774
|
const values = ArraySchema(value);
|
|
5683
5775
|
return (input, ast, options) => {
|
|
5684
5776
|
if (Chunk_.isChunk(input)) {
|
|
5685
|
-
return Effect.mapBothEager(
|
|
5777
|
+
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
|
|
5686
5778
|
onSuccess: Chunk_.fromIterable,
|
|
5687
|
-
onFailure: issue => new
|
|
5779
|
+
onFailure: issue => new SchemaIssue.Composite(ast, Option_.some(input), [new SchemaIssue.Pointer(["values"], issue)])
|
|
5688
5780
|
});
|
|
5689
5781
|
}
|
|
5690
|
-
return Effect.fail(new
|
|
5782
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
5691
5783
|
};
|
|
5692
5784
|
}, {
|
|
5693
5785
|
typeConstructor: {
|
|
@@ -5698,7 +5790,7 @@ export function Chunk(value) {
|
|
|
5698
5790
|
Type: `Chunk.Chunk<?>`
|
|
5699
5791
|
},
|
|
5700
5792
|
expected: "Chunk",
|
|
5701
|
-
toCodec: ([value]) => link()(ArraySchema(value),
|
|
5793
|
+
toCodec: ([value]) => link()(ArraySchema(value), SchemaTransformation.transform({
|
|
5702
5794
|
decode: Chunk_.fromIterable,
|
|
5703
5795
|
encode: Arr.fromIterable
|
|
5704
5796
|
})),
|
|
@@ -5744,10 +5836,10 @@ export const RegExp = /*#__PURE__*/instanceOf(globalThis.RegExp, {
|
|
|
5744
5836
|
toCodecJson: () => link()(Struct({
|
|
5745
5837
|
source: String,
|
|
5746
5838
|
flags: String
|
|
5747
|
-
}),
|
|
5839
|
+
}), SchemaTransformation.transformOrFail({
|
|
5748
5840
|
decode: e => Effect.try({
|
|
5749
5841
|
try: () => new globalThis.RegExp(e.source, e.flags),
|
|
5750
|
-
catch: e => new
|
|
5842
|
+
catch: e => new SchemaIssue.InvalidValue(Option_.some(e), {
|
|
5751
5843
|
message: globalThis.String(e)
|
|
5752
5844
|
})
|
|
5753
5845
|
}),
|
|
@@ -5787,7 +5879,7 @@ export const URL = /*#__PURE__*/instanceOf(globalThis.URL, {
|
|
|
5787
5879
|
Type: `globalThis.URL`
|
|
5788
5880
|
},
|
|
5789
5881
|
expected: "URL",
|
|
5790
|
-
toCodecJson: () => link()(URLString,
|
|
5882
|
+
toCodecJson: () => link()(URLString, SchemaTransformation.urlFromString),
|
|
5791
5883
|
toArbitrary: () => fc => fc.webUrl().map(s => new globalThis.URL(s)),
|
|
5792
5884
|
toEquivalence: () => (a, b) => a.toString() === b.toString()
|
|
5793
5885
|
});
|
|
@@ -5805,7 +5897,7 @@ export const URL = /*#__PURE__*/instanceOf(globalThis.URL, {
|
|
|
5805
5897
|
* @category URL
|
|
5806
5898
|
* @since 4.0.0
|
|
5807
5899
|
*/
|
|
5808
|
-
export const URLFromString = /*#__PURE__*/URLString.pipe(/*#__PURE__*/decodeTo(URL,
|
|
5900
|
+
export const URLFromString = /*#__PURE__*/URLString.pipe(/*#__PURE__*/decodeTo(URL, SchemaTransformation.urlFromString));
|
|
5809
5901
|
const DateString = /*#__PURE__*/String.annotate({
|
|
5810
5902
|
expected: "a string in ISO 8601 format that will be decoded as a Date"
|
|
5811
5903
|
});
|
|
@@ -5814,8 +5906,8 @@ const DateString = /*#__PURE__*/String.annotate({
|
|
|
5814
5906
|
*
|
|
5815
5907
|
* **When to use**
|
|
5816
5908
|
*
|
|
5817
|
-
* Use to validate in-memory values that must already be JavaScript
|
|
5818
|
-
*
|
|
5909
|
+
* Use to validate in-memory values that must already be JavaScript date
|
|
5910
|
+
* objects.
|
|
5819
5911
|
*
|
|
5820
5912
|
* **Details**
|
|
5821
5913
|
*
|
|
@@ -5846,7 +5938,7 @@ export const Date = /*#__PURE__*/instanceOf(globalThis.Date, {
|
|
|
5846
5938
|
Type: `globalThis.Date`
|
|
5847
5939
|
},
|
|
5848
5940
|
expected: "Date",
|
|
5849
|
-
toCodecJson: () => link()(DateString,
|
|
5941
|
+
toCodecJson: () => link()(DateString, SchemaTransformation.dateFromString),
|
|
5850
5942
|
toArbitrary: () => (fc, ctx) => fc.date(ctx?.constraints?.date)
|
|
5851
5943
|
});
|
|
5852
5944
|
/**
|
|
@@ -5876,7 +5968,7 @@ export const Date = /*#__PURE__*/instanceOf(globalThis.Date, {
|
|
|
5876
5968
|
* @category Date
|
|
5877
5969
|
* @since 3.10.0
|
|
5878
5970
|
*/
|
|
5879
|
-
export const DateFromString = /*#__PURE__*/DateString.pipe(/*#__PURE__*/decodeTo(Date,
|
|
5971
|
+
export const DateFromString = /*#__PURE__*/DateString.pipe(/*#__PURE__*/decodeTo(Date, SchemaTransformation.dateFromString));
|
|
5880
5972
|
/**
|
|
5881
5973
|
* Schema for **valid** JavaScript `Date` objects.
|
|
5882
5974
|
*
|
|
@@ -5930,7 +6022,7 @@ export const Duration = /*#__PURE__*/declare(Duration_.isDuration, {
|
|
|
5930
6022
|
}), Struct({
|
|
5931
6023
|
_tag: Literal("Millis"),
|
|
5932
6024
|
value: Int
|
|
5933
|
-
})]),
|
|
6025
|
+
})]), SchemaTransformation.transform({
|
|
5934
6026
|
decode: e => {
|
|
5935
6027
|
switch (e._tag) {
|
|
5936
6028
|
case "Infinity":
|
|
@@ -5988,7 +6080,7 @@ const DurationString = /*#__PURE__*/String.annotate({
|
|
|
5988
6080
|
* @category Duration
|
|
5989
6081
|
* @since 4.0.0
|
|
5990
6082
|
*/
|
|
5991
|
-
export const DurationFromString = /*#__PURE__*/DurationString.pipe(/*#__PURE__*/decodeTo(Duration,
|
|
6083
|
+
export const DurationFromString = /*#__PURE__*/DurationString.pipe(/*#__PURE__*/decodeTo(Duration, SchemaTransformation.durationFromString));
|
|
5992
6084
|
const bigint0 = /*#__PURE__*/globalThis.BigInt(0);
|
|
5993
6085
|
/**
|
|
5994
6086
|
* Schema that decodes a non-negative `bigint` into a
|
|
@@ -6007,7 +6099,7 @@ const bigint0 = /*#__PURE__*/globalThis.BigInt(0);
|
|
|
6007
6099
|
* @category Duration
|
|
6008
6100
|
* @since 3.10.0
|
|
6009
6101
|
*/
|
|
6010
|
-
export const DurationFromNanos = /*#__PURE__*/BigInt.check(isGreaterThanOrEqualToBigInt(bigint0)).pipe(/*#__PURE__*/decodeTo(Duration,
|
|
6102
|
+
export const DurationFromNanos = /*#__PURE__*/BigInt.check(isGreaterThanOrEqualToBigInt(bigint0)).pipe(/*#__PURE__*/decodeTo(Duration, SchemaTransformation.durationFromNanos));
|
|
6011
6103
|
/**
|
|
6012
6104
|
* Schema that decodes a non-negative (possibly infinite)
|
|
6013
6105
|
* integer into a `Duration`, treating the integer value as the duration in
|
|
@@ -6026,7 +6118,7 @@ export const DurationFromNanos = /*#__PURE__*/BigInt.check(isGreaterThanOrEqualT
|
|
|
6026
6118
|
* @category Duration
|
|
6027
6119
|
* @since 3.10.0
|
|
6028
6120
|
*/
|
|
6029
|
-
export const DurationFromMillis = /*#__PURE__*/Number.check(isGreaterThanOrEqualTo(0)).pipe(/*#__PURE__*/decodeTo(Duration,
|
|
6121
|
+
export const DurationFromMillis = /*#__PURE__*/Number.check(isGreaterThanOrEqualTo(0)).pipe(/*#__PURE__*/decodeTo(Duration, SchemaTransformation.durationFromMillis));
|
|
6030
6122
|
const BigDecimalString = /*#__PURE__*/String.annotate({
|
|
6031
6123
|
expected: "a string that will be decoded as a BigDecimal"
|
|
6032
6124
|
});
|
|
@@ -6035,7 +6127,7 @@ const BigDecimalString = /*#__PURE__*/String.annotate({
|
|
|
6035
6127
|
*
|
|
6036
6128
|
* **When to use**
|
|
6037
6129
|
*
|
|
6038
|
-
* Use when
|
|
6130
|
+
* Use when you already have Effect decimal instances and need schema
|
|
6039
6131
|
* validation, formatting, equivalence, and JSON string serialization.
|
|
6040
6132
|
*
|
|
6041
6133
|
* **Details**
|
|
@@ -6059,7 +6151,7 @@ export const BigDecimal = /*#__PURE__*/declare(BigDecimal_.isBigDecimal, {
|
|
|
6059
6151
|
importDeclaration: `import * as BigDecimal from "effect/BigDecimal"`
|
|
6060
6152
|
},
|
|
6061
6153
|
expected: "BigDecimal",
|
|
6062
|
-
toCodecJson: () => link()(BigDecimalString,
|
|
6154
|
+
toCodecJson: () => link()(BigDecimalString, SchemaTransformation.bigDecimalFromString),
|
|
6063
6155
|
toArbitrary: () => fc => fc.tuple(fc.bigInt(), fc.integer({
|
|
6064
6156
|
min: 0,
|
|
6065
6157
|
max: 20
|
|
@@ -6094,7 +6186,7 @@ export const BigDecimal = /*#__PURE__*/declare(BigDecimal_.isBigDecimal, {
|
|
|
6094
6186
|
* @category BigDecimal
|
|
6095
6187
|
* @since 4.0.0
|
|
6096
6188
|
*/
|
|
6097
|
-
export const BigDecimalFromString = /*#__PURE__*/BigDecimalString.pipe(/*#__PURE__*/decodeTo(BigDecimal,
|
|
6189
|
+
export const BigDecimalFromString = /*#__PURE__*/BigDecimalString.pipe(/*#__PURE__*/decodeTo(BigDecimal, SchemaTransformation.bigDecimalFromString));
|
|
6098
6190
|
/**
|
|
6099
6191
|
* Schema that decodes a JSON-encoded string into an `unknown` value.
|
|
6100
6192
|
*
|
|
@@ -6191,8 +6283,8 @@ export function fromJsonString(schema) {
|
|
|
6191
6283
|
return String.annotate({
|
|
6192
6284
|
expected: "a string that will be decoded as JSON",
|
|
6193
6285
|
contentMediaType: "application/json",
|
|
6194
|
-
contentSchema:
|
|
6195
|
-
}).pipe(decodeTo(schema,
|
|
6286
|
+
contentSchema: SchemaAST.toEncoded(schema.ast)
|
|
6287
|
+
}).pipe(decodeTo(schema, SchemaTransformation.fromJsonString));
|
|
6196
6288
|
}
|
|
6197
6289
|
/**
|
|
6198
6290
|
* Schema for JavaScript `File` objects.
|
|
@@ -6219,9 +6311,9 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
|
6219
6311
|
type: String,
|
|
6220
6312
|
name: String,
|
|
6221
6313
|
lastModified: Number
|
|
6222
|
-
}),
|
|
6314
|
+
}), SchemaTransformation.transformOrFail({
|
|
6223
6315
|
decode: e => Result_.match(Encoding.decodeBase64(e.data), {
|
|
6224
|
-
onFailure: error => Effect.fail(new
|
|
6316
|
+
onFailure: error => Effect.fail(new SchemaIssue.InvalidValue(Option_.some(e.data), {
|
|
6225
6317
|
message: error.message
|
|
6226
6318
|
})),
|
|
6227
6319
|
onSuccess: bytes => {
|
|
@@ -6242,7 +6334,7 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
|
6242
6334
|
lastModified: file.lastModified
|
|
6243
6335
|
};
|
|
6244
6336
|
},
|
|
6245
|
-
catch: e => new
|
|
6337
|
+
catch: e => new SchemaIssue.InvalidValue(Option_.some(file), {
|
|
6246
6338
|
message: globalThis.String(e)
|
|
6247
6339
|
})
|
|
6248
6340
|
})
|
|
@@ -6274,7 +6366,7 @@ export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
|
|
|
6274
6366
|
}), Struct({
|
|
6275
6367
|
_tag: tag("File"),
|
|
6276
6368
|
value: File
|
|
6277
|
-
})])])),
|
|
6369
|
+
})])])), SchemaTransformation.transformOrFail({
|
|
6278
6370
|
decode: e => {
|
|
6279
6371
|
const out = new globalThis.FormData();
|
|
6280
6372
|
for (const [key, entry] of e) {
|
|
@@ -6388,7 +6480,7 @@ export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
|
|
|
6388
6480
|
* @since 4.0.0
|
|
6389
6481
|
*/
|
|
6390
6482
|
export function fromFormData(schema) {
|
|
6391
|
-
return FormData.pipe(decodeTo(schema,
|
|
6483
|
+
return FormData.pipe(decodeTo(schema, SchemaTransformation.fromFormData));
|
|
6392
6484
|
}
|
|
6393
6485
|
/**
|
|
6394
6486
|
* Schema for JavaScript `URLSearchParams` objects.
|
|
@@ -6411,7 +6503,7 @@ export const URLSearchParams = /*#__PURE__*/instanceOf(globalThis.URLSearchParam
|
|
|
6411
6503
|
expected: "URLSearchParams",
|
|
6412
6504
|
toCodecJson: () => link()(String.annotate({
|
|
6413
6505
|
expected: "a query string that will be decoded as URLSearchParams"
|
|
6414
|
-
}),
|
|
6506
|
+
}), SchemaTransformation.transform({
|
|
6415
6507
|
decode: e => new globalThis.URLSearchParams(e),
|
|
6416
6508
|
encode: params => params.toString()
|
|
6417
6509
|
}))
|
|
@@ -6497,7 +6589,7 @@ export const URLSearchParams = /*#__PURE__*/instanceOf(globalThis.URLSearchParam
|
|
|
6497
6589
|
* @since 4.0.0
|
|
6498
6590
|
*/
|
|
6499
6591
|
export function fromURLSearchParams(schema) {
|
|
6500
|
-
return URLSearchParams.pipe(decodeTo(schema,
|
|
6592
|
+
return URLSearchParams.pipe(decodeTo(schema, SchemaTransformation.fromURLSearchParams));
|
|
6501
6593
|
}
|
|
6502
6594
|
/**
|
|
6503
6595
|
* Schema for finite numbers, rejecting `NaN`, `Infinity`, and `-Infinity`.
|
|
@@ -6532,7 +6624,7 @@ export const Int = /*#__PURE__*/Number.check(/*#__PURE__*/isInt());
|
|
|
6532
6624
|
*/
|
|
6533
6625
|
export const NumberFromString = /*#__PURE__*/String.annotate({
|
|
6534
6626
|
expected: "a string that will be decoded as a number"
|
|
6535
|
-
}).pipe(/*#__PURE__*/decodeTo(Number,
|
|
6627
|
+
}).pipe(/*#__PURE__*/decodeTo(Number, SchemaTransformation.numberFromString));
|
|
6536
6628
|
/**
|
|
6537
6629
|
* Schema that parses a string into a finite number.
|
|
6538
6630
|
*
|
|
@@ -6550,7 +6642,7 @@ export const NumberFromString = /*#__PURE__*/String.annotate({
|
|
|
6550
6642
|
*/
|
|
6551
6643
|
export const FiniteFromString = /*#__PURE__*/String.annotate({
|
|
6552
6644
|
expected: "a string that will be decoded as a finite number"
|
|
6553
|
-
}).pipe(/*#__PURE__*/decodeTo(Finite,
|
|
6645
|
+
}).pipe(/*#__PURE__*/decodeTo(Finite, SchemaTransformation.numberFromString));
|
|
6554
6646
|
/**
|
|
6555
6647
|
* Schema that parses a string into a `bigint`.
|
|
6556
6648
|
*
|
|
@@ -6579,7 +6671,7 @@ export const FiniteFromString = /*#__PURE__*/String.annotate({
|
|
|
6579
6671
|
* @category BigInt
|
|
6580
6672
|
* @since 4.0.0
|
|
6581
6673
|
*/
|
|
6582
|
-
export const BigIntFromString = /*#__PURE__*/make(
|
|
6674
|
+
export const BigIntFromString = /*#__PURE__*/make(SchemaAST.bigIntString).pipe(/*#__PURE__*/decodeTo(BigInt, SchemaTransformation.bigintFromString));
|
|
6583
6675
|
/**
|
|
6584
6676
|
* Schema for strings that contains no leading or trailing whitespaces.
|
|
6585
6677
|
*
|
|
@@ -6603,7 +6695,7 @@ export const Trimmed = /*#__PURE__*/String.check(/*#__PURE__*/isTrimmed());
|
|
|
6603
6695
|
*/
|
|
6604
6696
|
export const Trim = /*#__PURE__*/String.annotate({
|
|
6605
6697
|
expected: "a string that will be decoded as a trimmed string"
|
|
6606
|
-
}).pipe(/*#__PURE__*/decodeTo(Trimmed, /*#__PURE__*/
|
|
6698
|
+
}).pipe(/*#__PURE__*/decodeTo(Trimmed, /*#__PURE__*/SchemaTransformation.trim()));
|
|
6607
6699
|
/**
|
|
6608
6700
|
* Decodes a base64 (RFC4648) encoded string into a UTF-8 string.
|
|
6609
6701
|
*
|
|
@@ -6620,7 +6712,7 @@ export const Trim = /*#__PURE__*/String.annotate({
|
|
|
6620
6712
|
*/
|
|
6621
6713
|
export const StringFromBase64 = /*#__PURE__*/String.annotate({
|
|
6622
6714
|
expected: "a base64 encoded string that will be decoded as a UTF-8 string"
|
|
6623
|
-
}).pipe(/*#__PURE__*/decodeTo(String,
|
|
6715
|
+
}).pipe(/*#__PURE__*/decodeTo(String, SchemaTransformation.stringFromBase64String));
|
|
6624
6716
|
/**
|
|
6625
6717
|
* Decodes a base64 (URL) encoded string into a UTF-8 string.
|
|
6626
6718
|
*
|
|
@@ -6637,7 +6729,7 @@ export const StringFromBase64 = /*#__PURE__*/String.annotate({
|
|
|
6637
6729
|
*/
|
|
6638
6730
|
export const StringFromBase64Url = /*#__PURE__*/String.annotate({
|
|
6639
6731
|
expected: "a base64 (URL) encoded string that will be decoded as a UTF-8 string"
|
|
6640
|
-
}).pipe(/*#__PURE__*/decodeTo(String,
|
|
6732
|
+
}).pipe(/*#__PURE__*/decodeTo(String, SchemaTransformation.stringFromBase64UrlString));
|
|
6641
6733
|
/**
|
|
6642
6734
|
* Decodes a hex encoded string into a UTF-8 string.
|
|
6643
6735
|
*
|
|
@@ -6654,7 +6746,7 @@ export const StringFromBase64Url = /*#__PURE__*/String.annotate({
|
|
|
6654
6746
|
*/
|
|
6655
6747
|
export const StringFromHex = /*#__PURE__*/String.annotate({
|
|
6656
6748
|
expected: "a hex encoded string that will be decoded as a UTF-8 string"
|
|
6657
|
-
}).pipe(/*#__PURE__*/decodeTo(String,
|
|
6749
|
+
}).pipe(/*#__PURE__*/decodeTo(String, SchemaTransformation.stringFromHexString));
|
|
6658
6750
|
/**
|
|
6659
6751
|
* Decodes a URI component encoded string into a UTF-8 string.
|
|
6660
6752
|
* Can be used to store data in a URL.
|
|
@@ -6690,7 +6782,7 @@ export const StringFromHex = /*#__PURE__*/String.annotate({
|
|
|
6690
6782
|
*/
|
|
6691
6783
|
export const StringFromUriComponent = /*#__PURE__*/String.annotate({
|
|
6692
6784
|
expected: "a URI component encoded string that will be decoded as a UTF-8 string"
|
|
6693
|
-
}).pipe(/*#__PURE__*/decodeTo(String,
|
|
6785
|
+
}).pipe(/*#__PURE__*/decodeTo(String, SchemaTransformation.stringFromUriComponent));
|
|
6694
6786
|
/**
|
|
6695
6787
|
* Schema for property keys accepted by Effect schemas: finite `number`,
|
|
6696
6788
|
* `symbol`, or `string`.
|
|
@@ -6737,7 +6829,7 @@ export const StandardSchemaV1FailureResult = /*#__PURE__*/Struct({
|
|
|
6737
6829
|
* @category boolean
|
|
6738
6830
|
* @since 4.0.0
|
|
6739
6831
|
*/
|
|
6740
|
-
export const BooleanFromBit = /*#__PURE__*/Literals([0, 1]).pipe(/*#__PURE__*/decodeTo(Boolean, /*#__PURE__*/
|
|
6832
|
+
export const BooleanFromBit = /*#__PURE__*/Literals([0, 1]).pipe(/*#__PURE__*/decodeTo(Boolean, /*#__PURE__*/SchemaTransformation.transform({
|
|
6741
6833
|
decode: bit => bit === 1,
|
|
6742
6834
|
encode: bool => bool ? 1 : 0
|
|
6743
6835
|
})));
|
|
@@ -6767,7 +6859,7 @@ export const Uint8Array = /*#__PURE__*/instanceOf(globalThis.Uint8Array, {
|
|
|
6767
6859
|
Type: `globalThis.Uint8Array`
|
|
6768
6860
|
},
|
|
6769
6861
|
expected: "Uint8Array",
|
|
6770
|
-
toCodecJson: () => link()(Base64String,
|
|
6862
|
+
toCodecJson: () => link()(Base64String, SchemaTransformation.uint8ArrayFromBase64String),
|
|
6771
6863
|
toArbitrary: () => fc => fc.uint8Array()
|
|
6772
6864
|
});
|
|
6773
6865
|
/**
|
|
@@ -6785,7 +6877,7 @@ export const Uint8Array = /*#__PURE__*/instanceOf(globalThis.Uint8Array, {
|
|
|
6785
6877
|
* @category Uint8Array
|
|
6786
6878
|
* @since 3.10.0
|
|
6787
6879
|
*/
|
|
6788
|
-
export const Uint8ArrayFromBase64 = /*#__PURE__*/Base64String.pipe(/*#__PURE__*/decodeTo(Uint8Array,
|
|
6880
|
+
export const Uint8ArrayFromBase64 = /*#__PURE__*/Base64String.pipe(/*#__PURE__*/decodeTo(Uint8Array, SchemaTransformation.uint8ArrayFromBase64String));
|
|
6789
6881
|
/**
|
|
6790
6882
|
* Schema that decodes a base64 (URL) encoded string into a
|
|
6791
6883
|
* `Uint8Array`.
|
|
@@ -6804,8 +6896,8 @@ export const Uint8ArrayFromBase64 = /*#__PURE__*/Base64String.pipe(/*#__PURE__*/
|
|
|
6804
6896
|
export const Uint8ArrayFromBase64Url = /*#__PURE__*/String.annotate({
|
|
6805
6897
|
expected: "a base64 (URL) encoded string that will be decoded as a Uint8Array"
|
|
6806
6898
|
}).pipe(/*#__PURE__*/decodeTo(Uint8Array, {
|
|
6807
|
-
decode: /*#__PURE__*/
|
|
6808
|
-
encode: /*#__PURE__*/
|
|
6899
|
+
decode: /*#__PURE__*/SchemaGetter.decodeBase64Url(),
|
|
6900
|
+
encode: /*#__PURE__*/SchemaGetter.encodeBase64Url()
|
|
6809
6901
|
}));
|
|
6810
6902
|
/**
|
|
6811
6903
|
* Schema that decodes a hex encoded string into a
|
|
@@ -6825,8 +6917,8 @@ export const Uint8ArrayFromBase64Url = /*#__PURE__*/String.annotate({
|
|
|
6825
6917
|
export const Uint8ArrayFromHex = /*#__PURE__*/String.annotate({
|
|
6826
6918
|
expected: "a hex encoded string that will be decoded as a Uint8Array"
|
|
6827
6919
|
}).pipe(/*#__PURE__*/decodeTo(Uint8Array, {
|
|
6828
|
-
decode: /*#__PURE__*/
|
|
6829
|
-
encode: /*#__PURE__*/
|
|
6920
|
+
decode: /*#__PURE__*/SchemaGetter.decodeHex(),
|
|
6921
|
+
encode: /*#__PURE__*/SchemaGetter.encodeHex()
|
|
6830
6922
|
}));
|
|
6831
6923
|
/**
|
|
6832
6924
|
* Schema for `DateTime.Utc` values.
|
|
@@ -6859,7 +6951,7 @@ export const DateTimeUtc = /*#__PURE__*/declare(u => DateTime.isDateTime(u) && D
|
|
|
6859
6951
|
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
6860
6952
|
},
|
|
6861
6953
|
expected: "DateTime.Utc",
|
|
6862
|
-
toCodecJson: () => link()(String,
|
|
6954
|
+
toCodecJson: () => link()(String, SchemaTransformation.dateTimeUtcFromString),
|
|
6863
6955
|
toArbitrary: () => (fc, ctx) => fc.date({
|
|
6864
6956
|
noInvalidDate: true,
|
|
6865
6957
|
...ctx?.constraints?.date
|
|
@@ -6872,8 +6964,8 @@ export const DateTimeUtc = /*#__PURE__*/declare(u => DateTime.isDateTime(u) && D
|
|
|
6872
6964
|
*
|
|
6873
6965
|
* **When to use**
|
|
6874
6966
|
*
|
|
6875
|
-
* Use when
|
|
6876
|
-
*
|
|
6967
|
+
* Use when you need to decode valid JavaScript `Date` objects into
|
|
6968
|
+
* `DateTime.Utc` values.
|
|
6877
6969
|
*
|
|
6878
6970
|
* **Details**
|
|
6879
6971
|
*
|
|
@@ -6892,8 +6984,8 @@ export const DateTimeUtc = /*#__PURE__*/declare(u => DateTime.isDateTime(u) && D
|
|
|
6892
6984
|
* @since 3.12.0
|
|
6893
6985
|
*/
|
|
6894
6986
|
export const DateTimeUtcFromDate = /*#__PURE__*/DateValid.pipe(/*#__PURE__*/decodeTo(DateTimeUtc, {
|
|
6895
|
-
decode: /*#__PURE__*/
|
|
6896
|
-
encode: /*#__PURE__*/
|
|
6987
|
+
decode: /*#__PURE__*/SchemaGetter.dateTimeUtcFromInput(),
|
|
6988
|
+
encode: /*#__PURE__*/SchemaGetter.transform(DateTime.toDateUtc)
|
|
6897
6989
|
}));
|
|
6898
6990
|
/**
|
|
6899
6991
|
* Schema that decodes a date-time string into a `DateTime.Utc`.
|
|
@@ -6914,7 +7006,7 @@ export const DateTimeUtcFromDate = /*#__PURE__*/DateValid.pipe(/*#__PURE__*/deco
|
|
|
6914
7006
|
*/
|
|
6915
7007
|
export const DateTimeUtcFromString = /*#__PURE__*/String.annotate({
|
|
6916
7008
|
expected: "a string that will be decoded as a DateTime.Utc"
|
|
6917
|
-
}).pipe(/*#__PURE__*/decodeTo(DateTimeUtc,
|
|
7009
|
+
}).pipe(/*#__PURE__*/decodeTo(DateTimeUtc, SchemaTransformation.dateTimeUtcFromString));
|
|
6918
7010
|
/**
|
|
6919
7011
|
* Schema that decodes a number into a `DateTime.Utc`.
|
|
6920
7012
|
*
|
|
@@ -6930,8 +7022,8 @@ export const DateTimeUtcFromString = /*#__PURE__*/String.annotate({
|
|
|
6930
7022
|
* @since 4.0.0
|
|
6931
7023
|
*/
|
|
6932
7024
|
export const DateTimeUtcFromMillis = /*#__PURE__*/Number.pipe(/*#__PURE__*/decodeTo(DateTimeUtc, {
|
|
6933
|
-
decode: /*#__PURE__*/
|
|
6934
|
-
encode: /*#__PURE__*/
|
|
7025
|
+
decode: /*#__PURE__*/SchemaGetter.dateTimeUtcFromInput(),
|
|
7026
|
+
encode: /*#__PURE__*/SchemaGetter.transform(DateTime.toEpochMillis)
|
|
6935
7027
|
}));
|
|
6936
7028
|
/**
|
|
6937
7029
|
* Schema for `DateTime.TimeZone.Offset` values.
|
|
@@ -6955,7 +7047,7 @@ export const TimeZoneOffset = /*#__PURE__*/declare(DateTime.isTimeZoneOffset, {
|
|
|
6955
7047
|
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
6956
7048
|
},
|
|
6957
7049
|
expected: "DateTime.TimeZone.Offset",
|
|
6958
|
-
toCodecJson: () => link()(Number,
|
|
7050
|
+
toCodecJson: () => link()(Number, SchemaTransformation.timeZoneOffsetFromNumber),
|
|
6959
7051
|
toArbitrary: () => fc => fc.integer({
|
|
6960
7052
|
min: -12 * 60 * 60 * 1000,
|
|
6961
7053
|
max: 14 * 60 * 60 * 1000
|
|
@@ -6988,7 +7080,7 @@ export const TimeZoneNamed = /*#__PURE__*/declare(DateTime.isTimeZoneNamed, {
|
|
|
6988
7080
|
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
6989
7081
|
},
|
|
6990
7082
|
expected: "DateTime.TimeZone.Named",
|
|
6991
|
-
toCodecJson: () => link()(TimeZoneNamedString,
|
|
7083
|
+
toCodecJson: () => link()(TimeZoneNamedString, SchemaTransformation.timeZoneNamedFromString),
|
|
6992
7084
|
toArbitrary: () => fc => fc.constantFrom(...["UTC", "Europe/London", "America/New_York", "Asia/Tokyo", "Australia/Sydney"].map(DateTime.zoneMakeNamedUnsafe)),
|
|
6993
7085
|
toFormatter: () => tz => DateTime.zoneToString(tz),
|
|
6994
7086
|
toEquivalence: () => (a, b) => a.id === b.id
|
|
@@ -7007,7 +7099,7 @@ export const TimeZoneNamed = /*#__PURE__*/declare(DateTime.isTimeZoneNamed, {
|
|
|
7007
7099
|
* @category DateTime
|
|
7008
7100
|
* @since 4.0.0
|
|
7009
7101
|
*/
|
|
7010
|
-
export const TimeZoneNamedFromString = /*#__PURE__*/TimeZoneNamedString.pipe(/*#__PURE__*/decodeTo(TimeZoneNamed,
|
|
7102
|
+
export const TimeZoneNamedFromString = /*#__PURE__*/TimeZoneNamedString.pipe(/*#__PURE__*/decodeTo(TimeZoneNamed, SchemaTransformation.timeZoneNamedFromString));
|
|
7011
7103
|
const TimeZoneString = /*#__PURE__*/String.annotate({
|
|
7012
7104
|
expected: "a time zone string (IANA identifier or offset like +03:00)"
|
|
7013
7105
|
});
|
|
@@ -7034,7 +7126,7 @@ export const TimeZone = /*#__PURE__*/declare(DateTime.isTimeZone, {
|
|
|
7034
7126
|
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
7035
7127
|
},
|
|
7036
7128
|
expected: "DateTime.TimeZone",
|
|
7037
|
-
toCodecJson: () => link()(TimeZoneString,
|
|
7129
|
+
toCodecJson: () => link()(TimeZoneString, SchemaTransformation.timeZoneFromString),
|
|
7038
7130
|
toArbitrary: () => fc => fc.oneof(fc.integer({
|
|
7039
7131
|
min: -12 * 60 * 60 * 1000,
|
|
7040
7132
|
max: 14 * 60 * 60 * 1000
|
|
@@ -7056,7 +7148,7 @@ export const TimeZone = /*#__PURE__*/declare(DateTime.isTimeZone, {
|
|
|
7056
7148
|
* @category DateTime
|
|
7057
7149
|
* @since 4.0.0
|
|
7058
7150
|
*/
|
|
7059
|
-
export const TimeZoneFromString = /*#__PURE__*/TimeZoneString.pipe(/*#__PURE__*/decodeTo(TimeZone,
|
|
7151
|
+
export const TimeZoneFromString = /*#__PURE__*/TimeZoneString.pipe(/*#__PURE__*/decodeTo(TimeZone, SchemaTransformation.timeZoneFromString));
|
|
7060
7152
|
const DateTimeZonedString = /*#__PURE__*/String.annotate({
|
|
7061
7153
|
expected: "a zoned DateTime string (e.g. 2024-01-01T00:00:00.000+00:00[Europe/London])"
|
|
7062
7154
|
});
|
|
@@ -7085,7 +7177,7 @@ export const DateTimeZoned = /*#__PURE__*/declare(u => DateTime.isDateTime(u) &&
|
|
|
7085
7177
|
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
7086
7178
|
},
|
|
7087
7179
|
expected: "DateTime.Zoned",
|
|
7088
|
-
toCodecJson: () => link()(DateTimeZonedString,
|
|
7180
|
+
toCodecJson: () => link()(DateTimeZonedString, SchemaTransformation.dateTimeZonedFromString),
|
|
7089
7181
|
toArbitrary: () => (fc, ctx) => fc.tuple(fc.date({
|
|
7090
7182
|
noInvalidDate: true,
|
|
7091
7183
|
min: new globalThis.Date(-8640000000000000 + 14 * 60 * 60 * 1000),
|
|
@@ -7111,7 +7203,7 @@ export const DateTimeZoned = /*#__PURE__*/declare(u => DateTime.isDateTime(u) &&
|
|
|
7111
7203
|
* @category DateTime
|
|
7112
7204
|
* @since 4.0.0
|
|
7113
7205
|
*/
|
|
7114
|
-
export const DateTimeZonedFromString = /*#__PURE__*/DateTimeZonedString.pipe(/*#__PURE__*/decodeTo(DateTimeZoned,
|
|
7206
|
+
export const DateTimeZonedFromString = /*#__PURE__*/DateTimeZonedString.pipe(/*#__PURE__*/decodeTo(DateTimeZoned, SchemaTransformation.dateTimeZonedFromString));
|
|
7115
7207
|
const immerable = /*#__PURE__*/globalThis.Symbol.for("immer-draftable");
|
|
7116
7208
|
function makeClass(Inherited, identifier, struct, annotations, proto) {
|
|
7117
7209
|
const getClassSchema = getClassSchemaFactory(struct, identifier, annotations);
|
|
@@ -7148,19 +7240,19 @@ function makeClass(Inherited, identifier, struct, annotations, proto) {
|
|
|
7148
7240
|
return new this(input, options);
|
|
7149
7241
|
}
|
|
7150
7242
|
static makeOption(input, options) {
|
|
7151
|
-
return
|
|
7243
|
+
return SchemaParser.makeOption(getClassSchema(this))(input ?? {}, options);
|
|
7152
7244
|
}
|
|
7153
7245
|
static makeEffect(input, options) {
|
|
7154
7246
|
return getClassSchema(this).makeEffect(input ?? {}, options);
|
|
7155
7247
|
}
|
|
7156
7248
|
static annotate(annotations) {
|
|
7157
|
-
return this.rebuild(
|
|
7249
|
+
return this.rebuild(SchemaAST.annotate(this.ast, annotations));
|
|
7158
7250
|
}
|
|
7159
7251
|
static annotateKey(annotations) {
|
|
7160
|
-
return this.rebuild(
|
|
7252
|
+
return this.rebuild(SchemaAST.annotateKey(this.ast, annotations));
|
|
7161
7253
|
}
|
|
7162
7254
|
static check(...checks) {
|
|
7163
|
-
return this.rebuild(
|
|
7255
|
+
return this.rebuild(SchemaAST.appendChecks(this.ast, checks));
|
|
7164
7256
|
}
|
|
7165
7257
|
static extend(identifier) {
|
|
7166
7258
|
return (newFields, annotations) => {
|
|
@@ -7168,7 +7260,7 @@ function makeClass(Inherited, identifier, struct, annotations, proto) {
|
|
|
7168
7260
|
...struct.fields,
|
|
7169
7261
|
...newFields
|
|
7170
7262
|
};
|
|
7171
|
-
return makeClass(this, identifier, makeStruct(
|
|
7263
|
+
return makeClass(this, identifier, makeStruct(SchemaAST.struct(fields, struct.ast.checks, {
|
|
7172
7264
|
identifier
|
|
7173
7265
|
}), fields), annotations, proto);
|
|
7174
7266
|
};
|
|
@@ -7183,7 +7275,7 @@ function makeClass(Inherited, identifier, struct, annotations, proto) {
|
|
|
7183
7275
|
return out;
|
|
7184
7276
|
}
|
|
7185
7277
|
function getClassTransformation(self) {
|
|
7186
|
-
return new
|
|
7278
|
+
return new SchemaTransformation.Transformation(SchemaGetter.transform(input => new self(input)), SchemaGetter.passthrough());
|
|
7187
7279
|
}
|
|
7188
7280
|
function getClassTypeId(identifier) {
|
|
7189
7281
|
return `~effect/Schema/Class/${identifier}`;
|
|
@@ -7193,15 +7285,15 @@ function getClassSchemaFactory(from, identifier, annotations) {
|
|
|
7193
7285
|
return self => {
|
|
7194
7286
|
if (memo === undefined) {
|
|
7195
7287
|
const transformation = getClassTransformation(self);
|
|
7196
|
-
const to = make(new
|
|
7197
|
-
return input instanceof self || Predicate.hasProperty(input, getClassTypeId(identifier)) ? Effect.succeed(input) : Effect.fail(new
|
|
7288
|
+
const to = make(new SchemaAST.Declaration([from.ast], () => (input, ast) => {
|
|
7289
|
+
return input instanceof self || Predicate.hasProperty(input, getClassTypeId(identifier)) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
7198
7290
|
}, {
|
|
7199
7291
|
identifier,
|
|
7200
|
-
[
|
|
7201
|
-
toCodec: ([from]) => new
|
|
7292
|
+
[SchemaAST.ClassTypeId]: ([from]) => new SchemaAST.Link(from, transformation),
|
|
7293
|
+
toCodec: ([from]) => new SchemaAST.Link(from.ast, transformation),
|
|
7202
7294
|
toArbitrary: ([from]) => () => from.map(args => new self(args)),
|
|
7203
7295
|
toFormatter: ([from]) => t => `${self.identifier}(${from(t)})`,
|
|
7204
|
-
"~sentinels":
|
|
7296
|
+
"~sentinels": SchemaAST.collectSentinels(from.ast),
|
|
7205
7297
|
...annotations
|
|
7206
7298
|
}));
|
|
7207
7299
|
memo = from.pipe(decodeTo(to, transformation));
|
|
@@ -7219,9 +7311,8 @@ function isStruct(schema) {
|
|
|
7219
7311
|
*
|
|
7220
7312
|
* **When to use**
|
|
7221
7313
|
*
|
|
7222
|
-
* Use
|
|
7223
|
-
*
|
|
7224
|
-
* inheritance.
|
|
7314
|
+
* Use when you need a schema-backed data class with validated construction,
|
|
7315
|
+
* schema-derived decoding/encoding, and class-style methods or inheritance.
|
|
7225
7316
|
*
|
|
7226
7317
|
* **Details**
|
|
7227
7318
|
*
|
|
@@ -7473,7 +7564,7 @@ export function toFormatter(schema, options) {
|
|
|
7473
7564
|
// ---------------------------------------------
|
|
7474
7565
|
const annotation = InternalAnnotations.resolve(ast)?.["toFormatter"];
|
|
7475
7566
|
if (typeof annotation === "function") {
|
|
7476
|
-
return annotation(
|
|
7567
|
+
return annotation(SchemaAST.isDeclaration(ast) ? ast.typeParameters.map(recur) : []);
|
|
7477
7568
|
}
|
|
7478
7569
|
// ---------------------------------------------
|
|
7479
7570
|
// handle onBefore
|
|
@@ -7509,7 +7600,7 @@ export function toFormatter(schema, options) {
|
|
|
7509
7600
|
// ---------------------------------------------
|
|
7510
7601
|
for (; i < elements.length; i++) {
|
|
7511
7602
|
if (t.length < i + 1) {
|
|
7512
|
-
if (
|
|
7603
|
+
if (SchemaAST.isOptional(ast.elements[i])) {
|
|
7513
7604
|
continue;
|
|
7514
7605
|
}
|
|
7515
7606
|
} else {
|
|
@@ -7552,7 +7643,7 @@ export function toFormatter(schema, options) {
|
|
|
7552
7643
|
const ps = ast.propertySignatures[i];
|
|
7553
7644
|
const name = ps.name;
|
|
7554
7645
|
visited.add(name);
|
|
7555
|
-
if (
|
|
7646
|
+
if (SchemaAST.isOptional(ps.type) && !Object.hasOwn(t, name)) {
|
|
7556
7647
|
continue;
|
|
7557
7648
|
}
|
|
7558
7649
|
out.push(`${formatPropertyKey(name)}: ${propertySignatures[i](t[name])}`);
|
|
@@ -7561,7 +7652,7 @@ export function toFormatter(schema, options) {
|
|
|
7561
7652
|
// handle index signatures
|
|
7562
7653
|
// ---------------------------------------------
|
|
7563
7654
|
for (let i = 0; i < indexSignatures.length; i++) {
|
|
7564
|
-
const keys =
|
|
7655
|
+
const keys = SchemaAST.getIndexSignatureKeys(t, ast.indexSignatures[i].parameter);
|
|
7565
7656
|
for (const key of keys) {
|
|
7566
7657
|
if (visited.has(key)) {
|
|
7567
7658
|
continue;
|
|
@@ -7575,10 +7666,10 @@ export function toFormatter(schema, options) {
|
|
|
7575
7666
|
}
|
|
7576
7667
|
case "Union":
|
|
7577
7668
|
{
|
|
7578
|
-
const getCandidates = t =>
|
|
7669
|
+
const getCandidates = t => SchemaAST.getCandidates(t, ast.types);
|
|
7579
7670
|
return t => {
|
|
7580
7671
|
const candidates = getCandidates(t);
|
|
7581
|
-
const refinements = candidates.map(
|
|
7672
|
+
const refinements = candidates.map(SchemaParser._is);
|
|
7582
7673
|
for (let i = 0; i < candidates.length; i++) {
|
|
7583
7674
|
const is = refinements[i];
|
|
7584
7675
|
if (is(t)) {
|
|
@@ -7590,7 +7681,7 @@ export function toFormatter(schema, options) {
|
|
|
7590
7681
|
}
|
|
7591
7682
|
case "Suspend":
|
|
7592
7683
|
{
|
|
7593
|
-
const get =
|
|
7684
|
+
const get = SchemaAST.memoizeThunk(() => recur(ast.thunk()));
|
|
7594
7685
|
return t => get()(t);
|
|
7595
7686
|
}
|
|
7596
7687
|
}
|
|
@@ -7605,8 +7696,8 @@ export function toFormatter(schema, options) {
|
|
|
7605
7696
|
*
|
|
7606
7697
|
* **When to use**
|
|
7607
7698
|
*
|
|
7608
|
-
* Use when
|
|
7609
|
-
*
|
|
7699
|
+
* Use when you need a custom equivalence instead of the default structural
|
|
7700
|
+
* equivalence derived by {@link toEquivalence}.
|
|
7610
7701
|
*
|
|
7611
7702
|
* @category instances
|
|
7612
7703
|
* @since 4.0.0
|
|
@@ -7686,9 +7777,9 @@ export function toJsonSchemaDocument(schema, options) {
|
|
|
7686
7777
|
export function toCodecJson(schema) {
|
|
7687
7778
|
return make(toCodecJsonTop(schema.ast));
|
|
7688
7779
|
}
|
|
7689
|
-
const toCodecJsonTop = /*#__PURE__*/
|
|
7780
|
+
const toCodecJsonTop = /*#__PURE__*/SchemaAST.toCodec(ast => {
|
|
7690
7781
|
const out = toCodecJsonBase(ast, toCodecJsonTop);
|
|
7691
|
-
return out !== ast &&
|
|
7782
|
+
return out !== ast && SchemaAST.isOptional(ast) ? SchemaAST.optionalKeyLastLink(out) : out;
|
|
7692
7783
|
});
|
|
7693
7784
|
function toCodecJsonBase(ast, recur) {
|
|
7694
7785
|
switch (ast._tag) {
|
|
@@ -7696,16 +7787,16 @@ function toCodecJsonBase(ast, recur) {
|
|
|
7696
7787
|
{
|
|
7697
7788
|
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec;
|
|
7698
7789
|
if (Predicate.isFunction(getLink)) {
|
|
7699
|
-
const tps =
|
|
7790
|
+
const tps = SchemaAST.isDeclaration(ast) ? ast.typeParameters.map(tp => InternalSchema.make(SchemaAST.toEncoded(tp))) : [];
|
|
7700
7791
|
const link = getLink(tps);
|
|
7701
7792
|
const to = recur(link.to);
|
|
7702
|
-
return
|
|
7793
|
+
return SchemaAST.replaceEncoding(ast, to === link.to ? [link] : [new SchemaAST.Link(to, link.transformation)]);
|
|
7703
7794
|
}
|
|
7704
|
-
return
|
|
7795
|
+
return SchemaAST.replaceEncoding(ast, [SchemaAST.unknownToNull]);
|
|
7705
7796
|
}
|
|
7706
7797
|
case "Unknown":
|
|
7707
7798
|
case "ObjectKeyword":
|
|
7708
|
-
return
|
|
7799
|
+
return SchemaAST.replaceEncoding(ast, [SchemaAST.unknownToJson]);
|
|
7709
7800
|
case "Undefined":
|
|
7710
7801
|
case "Void":
|
|
7711
7802
|
case "Literal":
|
|
@@ -7728,7 +7819,7 @@ function toCodecJsonBase(ast, recur) {
|
|
|
7728
7819
|
{
|
|
7729
7820
|
const sortedTypes = InternalSchema.jsonReorder(ast.types);
|
|
7730
7821
|
if (sortedTypes !== ast.types) {
|
|
7731
|
-
return new
|
|
7822
|
+
return new SchemaAST.Union(sortedTypes, ast.mode, ast.annotations, ast.checks, ast.encoding, ast.context).recur(recur);
|
|
7732
7823
|
}
|
|
7733
7824
|
return ast.recur(recur);
|
|
7734
7825
|
}
|
|
@@ -7747,11 +7838,11 @@ function toCodecJsonBase(ast, recur) {
|
|
|
7747
7838
|
* @since 4.0.0
|
|
7748
7839
|
*/
|
|
7749
7840
|
export function toCodecIso(schema) {
|
|
7750
|
-
return make(toCodecIsoTop(
|
|
7841
|
+
return make(toCodecIsoTop(SchemaAST.toType(schema.ast)));
|
|
7751
7842
|
}
|
|
7752
7843
|
const toCodecIsoTop = /*#__PURE__*/memoize(ast => {
|
|
7753
7844
|
const out = toCodecIsoBase(ast, toCodecIsoTop);
|
|
7754
|
-
return out !== ast &&
|
|
7845
|
+
return out !== ast && SchemaAST.isOptional(ast) ? SchemaAST.optionalKeyLastLink(out) : out;
|
|
7755
7846
|
});
|
|
7756
7847
|
function toCodecIsoBase(ast, recur) {
|
|
7757
7848
|
switch (ast._tag) {
|
|
@@ -7761,7 +7852,7 @@ function toCodecIsoBase(ast, recur) {
|
|
|
7761
7852
|
if (Predicate.isFunction(getLink)) {
|
|
7762
7853
|
const link = getLink(ast.typeParameters.map(tp => InternalSchema.make(tp)));
|
|
7763
7854
|
const to = recur(link.to);
|
|
7764
|
-
return
|
|
7855
|
+
return SchemaAST.replaceEncoding(ast, to === link.to ? [link] : [new SchemaAST.Link(to, link.transformation)]);
|
|
7765
7856
|
}
|
|
7766
7857
|
return ast;
|
|
7767
7858
|
}
|
|
@@ -7905,20 +7996,20 @@ function serializerTree(ast, recur, onMissingAnnotation) {
|
|
|
7905
7996
|
{
|
|
7906
7997
|
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec;
|
|
7907
7998
|
if (Predicate.isFunction(getLink)) {
|
|
7908
|
-
const tps =
|
|
7999
|
+
const tps = SchemaAST.isDeclaration(ast) ? ast.typeParameters.map(tp => make(recur(SchemaAST.toEncoded(tp)))) : [];
|
|
7909
8000
|
const link = getLink(tps);
|
|
7910
8001
|
const to = recur(link.to);
|
|
7911
|
-
return
|
|
8002
|
+
return SchemaAST.replaceEncoding(ast, to === link.to ? [link] : [new SchemaAST.Link(to, link.transformation)]);
|
|
7912
8003
|
}
|
|
7913
8004
|
return onMissingAnnotation(ast);
|
|
7914
8005
|
}
|
|
7915
8006
|
case "Null":
|
|
7916
|
-
return
|
|
8007
|
+
return SchemaAST.replaceEncoding(ast, [nullToString]);
|
|
7917
8008
|
case "Boolean":
|
|
7918
|
-
return
|
|
8009
|
+
return SchemaAST.replaceEncoding(ast, [booleanToString]);
|
|
7919
8010
|
case "Unknown":
|
|
7920
8011
|
case "ObjectKeyword":
|
|
7921
|
-
return
|
|
8012
|
+
return SchemaAST.replaceEncoding(ast, [SchemaAST.unknownToStringTree]);
|
|
7922
8013
|
case "Enum":
|
|
7923
8014
|
case "Number":
|
|
7924
8015
|
case "Literal":
|
|
@@ -7939,7 +8030,7 @@ function serializerTree(ast, recur, onMissingAnnotation) {
|
|
|
7939
8030
|
{
|
|
7940
8031
|
const sortedTypes = treeReorder(ast.types);
|
|
7941
8032
|
if (sortedTypes !== ast.types) {
|
|
7942
|
-
return new
|
|
8033
|
+
return new SchemaAST.Union(sortedTypes, ast.mode, ast.annotations, ast.checks, ast.encoding, ast.context).recur(recur);
|
|
7943
8034
|
}
|
|
7944
8035
|
return ast.recur(recur);
|
|
7945
8036
|
}
|
|
@@ -7950,34 +8041,34 @@ function serializerTree(ast, recur, onMissingAnnotation) {
|
|
|
7950
8041
|
// `Schema.Any` is used as an escape hatch
|
|
7951
8042
|
return ast;
|
|
7952
8043
|
}
|
|
7953
|
-
const nullToString = /*#__PURE__*/new
|
|
7954
|
-
const booleanToString = /*#__PURE__*/new
|
|
7955
|
-
const serializerStringTree = /*#__PURE__*/
|
|
7956
|
-
const out = serializerTree(ast, serializerStringTree, ast =>
|
|
7957
|
-
if (out !== ast &&
|
|
7958
|
-
return
|
|
8044
|
+
const nullToString = /*#__PURE__*/new SchemaAST.Link(/*#__PURE__*/new SchemaAST.Literal("null"), /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(() => null), /*#__PURE__*/SchemaGetter.transform(() => "null")));
|
|
8045
|
+
const booleanToString = /*#__PURE__*/new SchemaAST.Link(/*#__PURE__*/new SchemaAST.Union([/*#__PURE__*/new SchemaAST.Literal("true"), /*#__PURE__*/new SchemaAST.Literal("false")], "anyOf"), /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(s => s === "true"), /*#__PURE__*/SchemaGetter.String()));
|
|
8046
|
+
const serializerStringTree = /*#__PURE__*/SchemaAST.toCodec(ast => {
|
|
8047
|
+
const out = serializerTree(ast, serializerStringTree, ast => SchemaAST.replaceEncoding(ast, [unknownToUndefined]));
|
|
8048
|
+
if (out !== ast && SchemaAST.isOptional(ast)) {
|
|
8049
|
+
return SchemaAST.optionalKeyLastLink(out);
|
|
7959
8050
|
}
|
|
7960
8051
|
return out;
|
|
7961
8052
|
});
|
|
7962
|
-
const unknownToUndefined = /*#__PURE__*/new
|
|
7963
|
-
const serializerStringTreeKeepDeclarations = /*#__PURE__*/
|
|
8053
|
+
const unknownToUndefined = /*#__PURE__*/new SchemaAST.Link(SchemaAST.undefined, /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.passthrough(), /*#__PURE__*/SchemaGetter.transform(() => undefined)));
|
|
8054
|
+
const serializerStringTreeKeepDeclarations = /*#__PURE__*/SchemaAST.toCodec(ast => {
|
|
7964
8055
|
const out = serializerTree(ast, serializerStringTreeKeepDeclarations, identity);
|
|
7965
|
-
if (out !== ast &&
|
|
7966
|
-
return
|
|
8056
|
+
if (out !== ast && SchemaAST.isOptional(ast)) {
|
|
8057
|
+
return SchemaAST.optionalKeyLastLink(out);
|
|
7967
8058
|
}
|
|
7968
8059
|
return out;
|
|
7969
8060
|
});
|
|
7970
8061
|
const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY";
|
|
7971
|
-
const toCodecEnsureArray = /*#__PURE__*/
|
|
7972
|
-
if (
|
|
8062
|
+
const toCodecEnsureArray = /*#__PURE__*/SchemaAST.toCodec(ast => {
|
|
8063
|
+
if (SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY]) {
|
|
7973
8064
|
return ast;
|
|
7974
8065
|
}
|
|
7975
8066
|
const out = onSerializerEnsureArray(ast);
|
|
7976
|
-
if (
|
|
7977
|
-
const ensure = new
|
|
8067
|
+
if (SchemaAST.isArrays(out)) {
|
|
8068
|
+
const ensure = new SchemaAST.Union([out, SchemaAST.decodeTo(SchemaAST.string, out, new SchemaTransformation.Transformation(SchemaGetter.split(), SchemaGetter.passthrough()))], "anyOf", {
|
|
7978
8069
|
[SERIALIZER_ENSURE_ARRAY]: true
|
|
7979
8070
|
});
|
|
7980
|
-
return
|
|
8071
|
+
return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure;
|
|
7981
8072
|
}
|
|
7982
8073
|
return out;
|
|
7983
8074
|
});
|
|
@@ -8005,7 +8096,7 @@ function onSerializerEnsureArray(ast) {
|
|
|
8005
8096
|
*/
|
|
8006
8097
|
export function toIso(schema) {
|
|
8007
8098
|
const serializer = toCodecIso(schema);
|
|
8008
|
-
return Optic_.makeIso(
|
|
8099
|
+
return Optic_.makeIso(SchemaParser.encodeSync(serializer), SchemaParser.decodeSync(serializer));
|
|
8009
8100
|
}
|
|
8010
8101
|
/**
|
|
8011
8102
|
* Returns an identity `Iso` over the schema's source (`Type`) side.
|
|
@@ -8044,8 +8135,8 @@ export function toIsoFocus(_) {
|
|
|
8044
8135
|
*/
|
|
8045
8136
|
export function overrideToCodecIso(to, transformation) {
|
|
8046
8137
|
return schema => {
|
|
8047
|
-
return make(
|
|
8048
|
-
toCodecIso: () => new
|
|
8138
|
+
return make(SchemaAST.annotate(schema.ast, {
|
|
8139
|
+
toCodecIso: () => new SchemaAST.Link(to.ast, SchemaTransformation.make(transformation))
|
|
8049
8140
|
}), {
|
|
8050
8141
|
schema
|
|
8051
8142
|
});
|
|
@@ -8064,8 +8155,8 @@ export function overrideToCodecIso(to, transformation) {
|
|
|
8064
8155
|
*/
|
|
8065
8156
|
export function toDifferJsonPatch(schema) {
|
|
8066
8157
|
const serializer = toCodecJson(schema);
|
|
8067
|
-
const get =
|
|
8068
|
-
const set =
|
|
8158
|
+
const get = SchemaParser.encodeSync(serializer);
|
|
8159
|
+
const set = SchemaParser.decodeSync(serializer);
|
|
8069
8160
|
return {
|
|
8070
8161
|
empty: [],
|
|
8071
8162
|
diff: (oldValue, newValue) => JsonPatch.get(get(oldValue), get(newValue)),
|
|
@@ -8105,7 +8196,7 @@ export function Tree(node) {
|
|
|
8105
8196
|
* @category schemas
|
|
8106
8197
|
* @since 4.0.0
|
|
8107
8198
|
*/
|
|
8108
|
-
export const Json = /*#__PURE__*/make(
|
|
8199
|
+
export const Json = /*#__PURE__*/make(SchemaAST.Json);
|
|
8109
8200
|
/**
|
|
8110
8201
|
* Schema that accepts any mutable JSON-compatible value. See {@link Json} for
|
|
8111
8202
|
* the immutable variant.
|
|
@@ -8113,7 +8204,7 @@ export const Json = /*#__PURE__*/make(AST.Json);
|
|
|
8113
8204
|
* @category schemas
|
|
8114
8205
|
* @since 4.0.0
|
|
8115
8206
|
*/
|
|
8116
|
-
export const MutableJson = /*#__PURE__*/make(
|
|
8207
|
+
export const MutableJson = /*#__PURE__*/make(SchemaAST.MutableJson);
|
|
8117
8208
|
// -----------------------------------------------------------------------------
|
|
8118
8209
|
// Annotations
|
|
8119
8210
|
// -----------------------------------------------------------------------------
|