effect 4.0.0-beta.4 → 4.0.0-beta.40
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 +213 -385
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +149 -102
- package/dist/Array.js.map +1 -1
- package/dist/BigDecimal.d.ts +46 -45
- package/dist/BigDecimal.d.ts.map +1 -1
- package/dist/BigDecimal.js +35 -38
- package/dist/BigDecimal.js.map +1 -1
- package/dist/BigInt.d.ts +39 -32
- package/dist/BigInt.d.ts.map +1 -1
- package/dist/BigInt.js +32 -29
- package/dist/BigInt.js.map +1 -1
- package/dist/Brand.d.ts +1 -1
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +1 -1
- package/dist/Brand.js.map +1 -1
- package/dist/Cache.d.ts +2 -2
- package/dist/Cache.d.ts.map +1 -1
- package/dist/Cache.js +6 -5
- package/dist/Cache.js.map +1 -1
- package/dist/Cause.d.ts +33 -2
- package/dist/Cause.d.ts.map +1 -1
- package/dist/Cause.js +19 -0
- package/dist/Cause.js.map +1 -1
- package/dist/Channel.d.ts +130 -35
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +96 -45
- package/dist/Channel.js.map +1 -1
- package/dist/Chunk.d.ts +112 -304
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js +56 -88
- package/dist/Chunk.js.map +1 -1
- package/dist/Combiner.d.ts +280 -13
- package/dist/Combiner.d.ts.map +1 -1
- package/dist/Combiner.js +198 -7
- package/dist/Combiner.js.map +1 -1
- package/dist/Config.d.ts +169 -9
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +69 -11
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts +1 -1
- package/dist/Cron.d.ts +11 -7
- package/dist/Cron.d.ts.map +1 -1
- package/dist/Cron.js +120 -63
- package/dist/Cron.js.map +1 -1
- package/dist/Data.d.ts +535 -366
- package/dist/Data.d.ts.map +1 -1
- package/dist/Data.js +132 -79
- package/dist/Data.js.map +1 -1
- package/dist/DateTime.d.ts +72 -253
- package/dist/DateTime.d.ts.map +1 -1
- package/dist/DateTime.js +15 -60
- package/dist/DateTime.js.map +1 -1
- package/dist/Deferred.d.ts +7 -5
- package/dist/Deferred.d.ts.map +1 -1
- package/dist/Deferred.js +7 -5
- package/dist/Deferred.js.map +1 -1
- package/dist/Duration.d.ts +62 -32
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +108 -78
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +1224 -951
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +398 -338
- package/dist/Effect.js.map +1 -1
- package/dist/Encoding.d.ts +194 -0
- package/dist/Encoding.d.ts.map +1 -0
- package/dist/Encoding.js +352 -0
- package/dist/Encoding.js.map +1 -0
- package/dist/Equal.d.ts +276 -109
- package/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +124 -48
- package/dist/Equal.js.map +1 -1
- package/dist/Equivalence.d.ts +60 -3
- package/dist/Equivalence.d.ts.map +1 -1
- package/dist/Equivalence.js +70 -13
- package/dist/Equivalence.js.map +1 -1
- package/dist/ErrorReporter.d.ts +374 -0
- package/dist/ErrorReporter.d.ts.map +1 -0
- package/dist/ErrorReporter.js +245 -0
- package/dist/ErrorReporter.js.map +1 -0
- package/dist/Exit.d.ts +24 -12
- package/dist/Exit.d.ts.map +1 -1
- package/dist/Exit.js +8 -4
- package/dist/Exit.js.map +1 -1
- package/dist/Fiber.d.ts +5 -3
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Fiber.js.map +1 -1
- package/dist/FiberHandle.d.ts +9 -8
- package/dist/FiberHandle.d.ts.map +1 -1
- package/dist/FiberHandle.js +8 -7
- package/dist/FiberHandle.js.map +1 -1
- package/dist/FiberMap.d.ts +20 -19
- package/dist/FiberMap.d.ts.map +1 -1
- package/dist/FiberMap.js +6 -6
- package/dist/FiberMap.js.map +1 -1
- package/dist/FileSystem.d.ts +18 -17
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js +17 -13
- package/dist/FileSystem.js.map +1 -1
- package/dist/Filter.d.ts +34 -38
- package/dist/Filter.d.ts.map +1 -1
- package/dist/Filter.js +15 -13
- package/dist/Filter.js.map +1 -1
- package/dist/Formatter.d.ts +131 -47
- package/dist/Formatter.d.ts.map +1 -1
- package/dist/Formatter.js +229 -51
- package/dist/Formatter.js.map +1 -1
- package/dist/Function.d.ts +1 -9
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +2 -10
- package/dist/Function.js.map +1 -1
- package/dist/Graph.d.ts +65 -65
- package/dist/Graph.d.ts.map +1 -1
- package/dist/Graph.js +60 -62
- package/dist/Graph.js.map +1 -1
- package/dist/HashMap.d.ts +26 -19
- package/dist/HashMap.d.ts.map +1 -1
- package/dist/HashMap.js +7 -5
- package/dist/HashMap.js.map +1 -1
- package/dist/Iterable.d.ts +50 -50
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +106 -34
- package/dist/Iterable.js.map +1 -1
- package/dist/JsonSchema.d.ts +299 -10
- package/dist/JsonSchema.d.ts.map +1 -1
- package/dist/JsonSchema.js +323 -4
- package/dist/JsonSchema.js.map +1 -1
- package/dist/Latch.d.ts +175 -0
- package/dist/Latch.d.ts.map +1 -0
- package/dist/Latch.js +130 -0
- package/dist/Latch.js.map +1 -0
- package/dist/Layer.d.ts +306 -129
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +92 -47
- package/dist/Layer.js.map +1 -1
- package/dist/LayerMap.d.ts +9 -8
- package/dist/LayerMap.d.ts.map +1 -1
- package/dist/LayerMap.js +3 -3
- package/dist/LayerMap.js.map +1 -1
- package/dist/LogLevel.d.ts +32 -0
- package/dist/LogLevel.d.ts.map +1 -1
- package/dist/LogLevel.js +28 -100
- package/dist/LogLevel.js.map +1 -1
- package/dist/Logger.d.ts +29 -95
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +2 -3
- package/dist/Logger.js.map +1 -1
- package/dist/ManagedRuntime.d.ts +2 -2
- package/dist/ManagedRuntime.js +2 -2
- package/dist/Metric.d.ts +4 -6
- package/dist/Metric.d.ts.map +1 -1
- package/dist/Metric.js +3 -5
- package/dist/Metric.js.map +1 -1
- package/dist/MutableHashMap.d.ts +7 -0
- package/dist/MutableHashMap.d.ts.map +1 -1
- package/dist/MutableHashMap.js +8 -0
- package/dist/MutableHashMap.js.map +1 -1
- package/dist/MutableHashSet.d.ts +7 -0
- package/dist/MutableHashSet.d.ts.map +1 -1
- package/dist/MutableHashSet.js +8 -0
- package/dist/MutableHashSet.js.map +1 -1
- package/dist/Newtype.d.ts +291 -0
- package/dist/Newtype.d.ts.map +1 -0
- package/dist/Newtype.js +161 -0
- package/dist/Newtype.js.map +1 -0
- package/dist/Number.d.ts +74 -18
- package/dist/Number.d.ts.map +1 -1
- package/dist/Number.js +34 -15
- package/dist/Number.js.map +1 -1
- package/dist/Optic.d.ts +947 -18
- package/dist/Optic.d.ts.map +1 -1
- package/dist/Optic.js +454 -5
- package/dist/Optic.js.map +1 -1
- package/dist/Option.d.ts +25 -16
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +15 -9
- package/dist/Option.js.map +1 -1
- package/dist/Order.d.ts +6 -1
- package/dist/Order.d.ts.map +1 -1
- package/dist/Order.js +19 -14
- package/dist/Order.js.map +1 -1
- package/dist/PartitionedSemaphore.d.ts +146 -15
- package/dist/PartitionedSemaphore.d.ts.map +1 -1
- package/dist/PartitionedSemaphore.js +174 -61
- package/dist/PartitionedSemaphore.js.map +1 -1
- package/dist/Pipeable.d.ts +17 -0
- package/dist/Pipeable.d.ts.map +1 -1
- package/dist/Pipeable.js +19 -1
- package/dist/Pipeable.js.map +1 -1
- package/dist/PlatformError.d.ts +10 -9
- package/dist/PlatformError.d.ts.map +1 -1
- package/dist/PlatformError.js +2 -2
- package/dist/PlatformError.js.map +1 -1
- package/dist/Pool.d.ts +6 -4
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +7 -5
- package/dist/Pool.js.map +1 -1
- package/dist/PubSub.d.ts +8 -6
- package/dist/PubSub.d.ts.map +1 -1
- package/dist/PubSub.js +18 -10
- package/dist/PubSub.js.map +1 -1
- package/dist/Pull.d.ts.map +1 -1
- package/dist/Pull.js +1 -1
- package/dist/Pull.js.map +1 -1
- package/dist/Queue.d.ts +9 -6
- package/dist/Queue.d.ts.map +1 -1
- package/dist/Queue.js +7 -5
- package/dist/Queue.js.map +1 -1
- package/dist/Random.d.ts +35 -1
- package/dist/Random.d.ts.map +1 -1
- package/dist/Random.js +46 -12
- package/dist/Random.js.map +1 -1
- package/dist/RcMap.d.ts +2 -2
- package/dist/RcMap.d.ts.map +1 -1
- package/dist/RcMap.js +1 -1
- package/dist/RcMap.js.map +1 -1
- package/dist/RcRef.d.ts +1 -1
- package/dist/RcRef.d.ts.map +1 -1
- package/dist/Record.d.ts +63 -160
- package/dist/Record.d.ts.map +1 -1
- package/dist/Record.js +37 -56
- package/dist/Record.js.map +1 -1
- package/dist/Reducer.d.ts +166 -7
- package/dist/Reducer.d.ts.map +1 -1
- package/dist/Reducer.js +135 -1
- package/dist/Reducer.js.map +1 -1
- package/dist/References.d.ts +242 -226
- package/dist/References.d.ts.map +1 -1
- package/dist/References.js +240 -247
- package/dist/References.js.map +1 -1
- package/dist/Request.d.ts +1 -1
- package/dist/Request.d.ts.map +1 -1
- package/dist/Request.js +2 -1
- package/dist/Request.js.map +1 -1
- package/dist/RequestResolver.d.ts +25 -45
- package/dist/RequestResolver.d.ts.map +1 -1
- package/dist/RequestResolver.js +10 -30
- package/dist/RequestResolver.js.map +1 -1
- package/dist/Resource.d.ts.map +1 -1
- package/dist/Resource.js +2 -1
- package/dist/Resource.js.map +1 -1
- package/dist/Result.d.ts +1 -1
- package/dist/Result.d.ts.map +1 -1
- package/dist/Result.js +1 -2
- package/dist/Result.js.map +1 -1
- package/dist/Runtime.d.ts +66 -0
- package/dist/Runtime.d.ts.map +1 -1
- package/dist/Runtime.js +79 -6
- package/dist/Runtime.js.map +1 -1
- package/dist/Schedule.d.ts +174 -291
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +160 -134
- package/dist/Schedule.js.map +1 -1
- package/dist/Scheduler.d.ts +34 -123
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +31 -123
- package/dist/Scheduler.js.map +1 -1
- package/dist/Schema.d.ts +2722 -247
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +1947 -224
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +7 -2
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +131 -25
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaGetter.d.ts +5 -5
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +18 -18
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaParser.d.ts +44 -54
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +55 -2
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +46 -45
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +49 -24
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +107 -3
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +173 -13
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/ScopedCache.d.ts +2 -2
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +1 -1
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Semaphore.d.ts +307 -0
- package/dist/Semaphore.d.ts.map +1 -0
- package/dist/Semaphore.js +222 -0
- package/dist/Semaphore.js.map +1 -0
- package/dist/ServiceMap.d.ts +67 -31
- package/dist/ServiceMap.d.ts.map +1 -1
- package/dist/ServiceMap.js +39 -24
- package/dist/ServiceMap.js.map +1 -1
- package/dist/Sink.d.ts +18 -15
- package/dist/Sink.d.ts.map +1 -1
- package/dist/Sink.js +53 -6
- package/dist/Sink.js.map +1 -1
- package/dist/Stdio.d.ts +16 -4
- package/dist/Stdio.d.ts.map +1 -1
- package/dist/Stdio.js +18 -0
- package/dist/Stdio.js.map +1 -1
- package/dist/Stream.d.ts +284 -431
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +189 -88
- package/dist/Stream.js.map +1 -1
- package/dist/String.d.ts +114 -47
- package/dist/String.d.ts.map +1 -1
- package/dist/String.js +29 -47
- package/dist/String.js.map +1 -1
- package/dist/Struct.d.ts +23 -7
- package/dist/Struct.d.ts.map +1 -1
- package/dist/Struct.js +22 -0
- package/dist/Struct.js.map +1 -1
- package/dist/SubscriptionRef.d.ts +3 -3
- package/dist/SubscriptionRef.d.ts.map +1 -1
- package/dist/SubscriptionRef.js +85 -117
- package/dist/SubscriptionRef.js.map +1 -1
- package/dist/SynchronizedRef.d.ts +2 -1
- package/dist/SynchronizedRef.d.ts.map +1 -1
- package/dist/SynchronizedRef.js +2 -1
- package/dist/SynchronizedRef.js.map +1 -1
- package/dist/Terminal.d.ts +2 -1
- package/dist/Terminal.d.ts.map +1 -1
- package/dist/Terminal.js.map +1 -1
- package/dist/Tracer.d.ts +5 -4
- package/dist/Tracer.d.ts.map +1 -1
- package/dist/Tracer.js +2 -1
- package/dist/Tracer.js.map +1 -1
- package/dist/Trie.d.ts +44 -31
- package/dist/Trie.d.ts.map +1 -1
- package/dist/Trie.js +13 -9
- package/dist/Trie.js.map +1 -1
- package/dist/TxChunk.d.ts +37 -37
- package/dist/TxChunk.d.ts.map +1 -1
- package/dist/TxChunk.js +3 -3
- package/dist/TxChunk.js.map +1 -1
- package/dist/TxDeferred.d.ts +328 -0
- package/dist/TxDeferred.d.ts.map +1 -0
- package/dist/TxDeferred.js +197 -0
- package/dist/TxDeferred.js.map +1 -0
- package/dist/TxHashMap.d.ts +159 -140
- package/dist/TxHashMap.d.ts.map +1 -1
- package/dist/TxHashMap.js +51 -44
- package/dist/TxHashMap.js.map +1 -1
- package/dist/TxHashSet.d.ts +36 -36
- package/dist/TxHashSet.d.ts.map +1 -1
- package/dist/TxHashSet.js +16 -15
- package/dist/TxHashSet.js.map +1 -1
- package/dist/TxPriorityQueue.d.ts +609 -0
- package/dist/TxPriorityQueue.d.ts.map +1 -0
- package/dist/TxPriorityQueue.js +416 -0
- package/dist/TxPriorityQueue.js.map +1 -0
- package/dist/TxPubSub.d.ts +585 -0
- package/dist/TxPubSub.d.ts.map +1 -0
- package/dist/TxPubSub.js +521 -0
- package/dist/TxPubSub.js.map +1 -0
- package/dist/TxQueue.d.ts +32 -32
- package/dist/TxQueue.d.ts.map +1 -1
- package/dist/TxQueue.js +26 -26
- package/dist/TxQueue.js.map +1 -1
- package/dist/TxReentrantLock.d.ts +523 -0
- package/dist/TxReentrantLock.d.ts.map +1 -0
- package/dist/TxReentrantLock.js +504 -0
- package/dist/TxReentrantLock.js.map +1 -0
- package/dist/TxRef.d.ts +34 -34
- package/dist/TxRef.d.ts.map +1 -1
- package/dist/TxRef.js +21 -14
- package/dist/TxRef.js.map +1 -1
- package/dist/TxSemaphore.d.ts +170 -10
- package/dist/TxSemaphore.d.ts.map +1 -1
- package/dist/TxSemaphore.js +23 -8
- package/dist/TxSemaphore.js.map +1 -1
- package/dist/TxSubscriptionRef.d.ts +508 -0
- package/dist/TxSubscriptionRef.d.ts.map +1 -0
- package/dist/TxSubscriptionRef.js +293 -0
- package/dist/TxSubscriptionRef.js.map +1 -0
- package/dist/Types.d.ts +80 -23
- package/dist/Types.d.ts.map +1 -1
- package/dist/Utils.d.ts +137 -65
- package/dist/Utils.d.ts.map +1 -1
- package/dist/Utils.js +38 -66
- package/dist/Utils.js.map +1 -1
- package/dist/index.d.ts +804 -53
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +804 -53
- package/dist/index.js.map +1 -1
- package/dist/internal/core.js +11 -3
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/dateTime.js +77 -71
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +281 -201
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/hashMap.js +7 -5
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/option.js +6 -0
- package/dist/internal/option.js.map +1 -1
- package/dist/internal/random.d.ts +2 -0
- package/dist/internal/random.d.ts.map +1 -0
- package/dist/internal/random.js +13 -0
- package/dist/internal/random.js.map +1 -0
- package/dist/internal/rcRef.js +3 -2
- package/dist/internal/rcRef.js.map +1 -1
- package/dist/internal/references.d.ts +2 -0
- package/dist/internal/references.d.ts.map +1 -0
- package/dist/internal/references.js +51 -0
- package/dist/internal/references.js.map +1 -0
- package/dist/internal/request.js +2 -2
- package/dist/internal/request.js.map +1 -1
- package/dist/internal/schema/annotations.js +2 -0
- package/dist/internal/schema/annotations.js.map +1 -1
- package/dist/internal/schema/representation.js +47 -106
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.js +1 -0
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/internal/schema/to-codec.js +7 -10
- package/dist/internal/schema/to-codec.js.map +1 -1
- package/dist/internal/trie.js +8 -7
- package/dist/internal/trie.js.map +1 -1
- package/dist/testing/TestClock.d.ts +8 -7
- package/dist/testing/TestClock.d.ts.map +1 -1
- package/dist/testing/TestClock.js +6 -4
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +266 -32
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js +296 -23
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/testing/index.d.ts +64 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +64 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/unstable/ai/AiError.d.ts +136 -54
- package/dist/unstable/ai/AiError.d.ts.map +1 -1
- package/dist/unstable/ai/AiError.js +28 -23
- package/dist/unstable/ai/AiError.js.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.js +4 -0
- package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +7 -8
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js +38 -44
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/EmbeddingModel.d.ts +130 -0
- package/dist/unstable/ai/EmbeddingModel.d.ts.map +1 -0
- package/dist/unstable/ai/EmbeddingModel.js +127 -0
- package/dist/unstable/ai/EmbeddingModel.js.map +1 -0
- package/dist/unstable/ai/LanguageModel.d.ts +53 -45
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +265 -143
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +183 -88
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +57 -12
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +66 -13
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +193 -51
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Model.d.ts +25 -7
- package/dist/unstable/ai/Model.d.ts.map +1 -1
- package/dist/unstable/ai/Model.js +22 -6
- package/dist/unstable/ai/Model.js.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.js +4 -0
- package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts +20 -20
- package/dist/unstable/ai/Prompt.d.ts.map +1 -1
- package/dist/unstable/ai/Response.d.ts +26 -26
- package/dist/unstable/ai/Response.d.ts.map +1 -1
- package/dist/unstable/ai/Response.js +1 -1
- package/dist/unstable/ai/Response.js.map +1 -1
- package/dist/unstable/ai/ResponseIdTracker.d.ts +38 -0
- package/dist/unstable/ai/ResponseIdTracker.d.ts.map +1 -0
- package/dist/unstable/ai/ResponseIdTracker.js +68 -0
- package/dist/unstable/ai/ResponseIdTracker.js.map +1 -0
- package/dist/unstable/ai/Tool.d.ts +34 -4
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +28 -10
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/ai/Toolkit.d.ts +1 -1
- package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
- package/dist/unstable/ai/Toolkit.js +4 -11
- package/dist/unstable/ai/Toolkit.js.map +1 -1
- package/dist/unstable/ai/index.d.ts +22 -1
- package/dist/unstable/ai/index.d.ts.map +1 -1
- package/dist/unstable/ai/index.js +22 -1
- package/dist/unstable/ai/index.js.map +1 -1
- package/dist/unstable/ai/internal/codec-transformer.js +0 -5
- package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
- package/dist/unstable/cli/Argument.d.ts +2 -4
- package/dist/unstable/cli/Argument.d.ts.map +1 -1
- package/dist/unstable/cli/Argument.js +1 -3
- package/dist/unstable/cli/Argument.js.map +1 -1
- package/dist/unstable/cli/CliError.d.ts +27 -60
- package/dist/unstable/cli/CliError.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.js +25 -57
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/CliOutput.d.ts +3 -2
- package/dist/unstable/cli/CliOutput.d.ts.map +1 -1
- package/dist/unstable/cli/CliOutput.js +65 -10
- package/dist/unstable/cli/CliOutput.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +371 -58
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +328 -67
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/Completions.d.ts +16 -0
- package/dist/unstable/cli/Completions.d.ts.map +1 -0
- package/dist/unstable/cli/Completions.js +23 -0
- package/dist/unstable/cli/Completions.js.map +1 -0
- package/dist/unstable/cli/Flag.d.ts +2 -2
- package/dist/unstable/cli/Flag.d.ts.map +1 -1
- package/dist/unstable/cli/Flag.js +1 -1
- package/dist/unstable/cli/Flag.js.map +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts +125 -0
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -0
- package/dist/unstable/cli/GlobalFlag.js +118 -0
- package/dist/unstable/cli/GlobalFlag.js.map +1 -0
- package/dist/unstable/cli/HelpDoc.d.ts +81 -11
- package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
- package/dist/unstable/cli/Param.d.ts +4 -4
- package/dist/unstable/cli/Param.d.ts.map +1 -1
- package/dist/unstable/cli/Param.js +7 -7
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/Primitive.d.ts +2 -2
- package/dist/unstable/cli/Primitive.d.ts.map +1 -1
- package/dist/unstable/cli/Primitive.js +1 -1
- package/dist/unstable/cli/Primitive.js.map +1 -1
- package/dist/unstable/cli/Prompt.js +258 -84
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +8 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +8 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts +40 -14
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +72 -46
- package/dist/unstable/cli/internal/command.js.map +1 -1
- package/dist/unstable/cli/internal/completions/CommandDescriptor.js +16 -4
- package/dist/unstable/cli/internal/completions/CommandDescriptor.js.map +1 -1
- package/dist/unstable/cli/internal/config.js +42 -0
- package/dist/unstable/cli/internal/config.js.map +1 -1
- package/dist/unstable/cli/internal/help.d.ts +33 -0
- package/dist/unstable/cli/internal/help.d.ts.map +1 -0
- package/dist/unstable/cli/internal/help.js +125 -0
- package/dist/unstable/cli/internal/help.js.map +1 -0
- package/dist/unstable/cli/internal/parser.js +61 -43
- package/dist/unstable/cli/internal/parser.js.map +1 -1
- package/dist/unstable/cluster/ClusterCron.d.ts +1 -1
- package/dist/unstable/cluster/ClusterCron.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterCron.js +1 -1
- package/dist/unstable/cluster/ClusterCron.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +3 -2
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +29 -26
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/DeliverAt.js +1 -1
- package/dist/unstable/cluster/DeliverAt.js.map +1 -1
- package/dist/unstable/cluster/Entity.d.ts +10 -8
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/Entity.js +7 -7
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/EntityAddress.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityAddress.js +1 -1
- package/dist/unstable/cluster/EntityAddress.js.map +1 -1
- package/dist/unstable/cluster/EntityResource.d.ts +2 -2
- package/dist/unstable/cluster/EntityResource.d.ts.map +1 -1
- package/dist/unstable/cluster/Envelope.d.ts +1 -1
- package/dist/unstable/cluster/K8sHttpClient.d.ts +1 -1
- package/dist/unstable/cluster/K8sHttpClient.js +4 -4
- package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
- package/dist/unstable/cluster/Message.d.ts +14 -13
- package/dist/unstable/cluster/Message.d.ts.map +1 -1
- package/dist/unstable/cluster/Message.js +3 -2
- package/dist/unstable/cluster/Message.js.map +1 -1
- package/dist/unstable/cluster/MessageStorage.d.ts +10 -10
- package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/MessageStorage.js +14 -13
- package/dist/unstable/cluster/MessageStorage.js.map +1 -1
- package/dist/unstable/cluster/Reply.d.ts +8 -7
- package/dist/unstable/cluster/Reply.d.ts.map +1 -1
- package/dist/unstable/cluster/Reply.js +4 -3
- package/dist/unstable/cluster/Reply.js.map +1 -1
- package/dist/unstable/cluster/Runner.d.ts +1 -1
- package/dist/unstable/cluster/Runner.d.ts.map +1 -1
- package/dist/unstable/cluster/Runner.js +1 -1
- package/dist/unstable/cluster/Runner.js.map +1 -1
- package/dist/unstable/cluster/RunnerAddress.d.ts.map +1 -1
- package/dist/unstable/cluster/RunnerAddress.js +1 -1
- package/dist/unstable/cluster/RunnerAddress.js.map +1 -1
- package/dist/unstable/cluster/RunnerServer.d.ts.map +1 -1
- package/dist/unstable/cluster/RunnerServer.js +9 -8
- package/dist/unstable/cluster/RunnerServer.js.map +1 -1
- package/dist/unstable/cluster/Runners.d.ts +2 -1
- package/dist/unstable/cluster/Runners.d.ts.map +1 -1
- package/dist/unstable/cluster/Runners.js +11 -9
- package/dist/unstable/cluster/Runners.js.map +1 -1
- package/dist/unstable/cluster/ShardId.js +3 -3
- package/dist/unstable/cluster/ShardId.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts +2 -2
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +28 -20
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.d.ts +26 -25
- package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.js +24 -24
- package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.js +19 -18
- package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +14 -14
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/cluster/internal/entityReaper.js +2 -1
- package/dist/unstable/cluster/internal/entityReaper.js.map +1 -1
- package/dist/unstable/cluster/internal/resourceRef.js +2 -1
- package/dist/unstable/cluster/internal/resourceRef.js.map +1 -1
- package/dist/unstable/devtools/DevToolsClient.d.ts.map +1 -1
- package/dist/unstable/devtools/DevToolsClient.js +4 -3
- package/dist/unstable/devtools/DevToolsClient.js.map +1 -1
- package/dist/unstable/devtools/DevToolsSchema.d.ts +40 -40
- package/dist/unstable/devtools/DevToolsSchema.d.ts.map +1 -1
- package/dist/unstable/devtools/DevToolsSchema.js +9 -2
- package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
- package/dist/unstable/encoding/Msgpack.d.ts +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +9 -9
- package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
- package/dist/unstable/encoding/Ndjson.js.map +1 -1
- package/dist/unstable/encoding/Sse.d.ts +4 -4
- package/dist/unstable/encoding/Sse.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.js +1 -1
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +2 -2
- package/dist/unstable/eventlog/EventJournal.js +2 -2
- package/dist/unstable/eventlog/EventJournal.js.map +1 -1
- package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLog.js +3 -2
- package/dist/unstable/eventlog/EventLog.js.map +1 -1
- package/dist/unstable/eventlog/EventLogRemote.d.ts +6 -6
- package/dist/unstable/eventlog/SqlEventLogJournal.js +2 -2
- package/dist/unstable/eventlog/SqlEventLogJournal.js.map +1 -1
- package/dist/unstable/http/Cookies.d.ts +52 -7
- package/dist/unstable/http/Cookies.d.ts.map +1 -1
- package/dist/unstable/http/Cookies.js +27 -6
- package/dist/unstable/http/Cookies.js.map +1 -1
- package/dist/unstable/http/Etag.d.ts.map +1 -1
- package/dist/unstable/http/Etag.js +5 -1
- package/dist/unstable/http/Etag.js.map +1 -1
- package/dist/unstable/http/Headers.d.ts +19 -2
- package/dist/unstable/http/Headers.d.ts.map +1 -1
- package/dist/unstable/http/Headers.js +40 -11
- package/dist/unstable/http/Headers.js.map +1 -1
- package/dist/unstable/http/HttpBody.d.ts +1 -1
- package/dist/unstable/http/HttpClient.d.ts +117 -15
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +191 -13
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpClientError.d.ts +7 -7
- package/dist/unstable/http/HttpClientRequest.d.ts +43 -15
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +131 -21
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpClientResponse.d.ts +2 -1
- package/dist/unstable/http/HttpClientResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientResponse.js +6 -1
- package/dist/unstable/http/HttpClientResponse.js.map +1 -1
- package/dist/unstable/http/HttpEffect.d.ts +7 -5
- package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
- package/dist/unstable/http/HttpEffect.js +46 -54
- package/dist/unstable/http/HttpEffect.js.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts +3 -2
- package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
- package/dist/unstable/http/HttpMethod.d.ts +4 -4
- package/dist/unstable/http/HttpMethod.d.ts.map +1 -1
- package/dist/unstable/http/HttpMethod.js +3 -3
- package/dist/unstable/http/HttpMethod.js.map +1 -1
- package/dist/unstable/http/HttpMiddleware.d.ts +1 -6
- package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/unstable/http/HttpMiddleware.js +24 -32
- package/dist/unstable/http/HttpMiddleware.js.map +1 -1
- package/dist/unstable/http/HttpPlatform.d.ts.map +1 -1
- package/dist/unstable/http/HttpPlatform.js +3 -2
- package/dist/unstable/http/HttpPlatform.js.map +1 -1
- package/dist/unstable/http/HttpRouter.d.ts +2 -1
- package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
- package/dist/unstable/http/HttpRouter.js +7 -7
- package/dist/unstable/http/HttpRouter.js.map +1 -1
- package/dist/unstable/http/HttpServer.d.ts.map +1 -1
- package/dist/unstable/http/HttpServer.js +2 -2
- package/dist/unstable/http/HttpServer.js.map +1 -1
- package/dist/unstable/http/HttpServerError.d.ts +22 -34
- package/dist/unstable/http/HttpServerError.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerError.js +39 -45
- package/dist/unstable/http/HttpServerError.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts +15 -3
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +301 -7
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerRespondable.d.ts +2 -2
- package/dist/unstable/http/HttpServerRespondable.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRespondable.js +5 -5
- package/dist/unstable/http/HttpServerRespondable.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts +50 -3
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +236 -1
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/HttpStaticServer.d.ts +69 -0
- package/dist/unstable/http/HttpStaticServer.d.ts.map +1 -0
- package/dist/unstable/http/HttpStaticServer.js +353 -0
- package/dist/unstable/http/HttpStaticServer.js.map +1 -0
- package/dist/unstable/http/HttpTraceContext.d.ts +3 -2
- package/dist/unstable/http/HttpTraceContext.d.ts.map +1 -1
- package/dist/unstable/http/HttpTraceContext.js +27 -15
- package/dist/unstable/http/HttpTraceContext.js.map +1 -1
- package/dist/unstable/http/Multipart.d.ts +3 -3
- package/dist/unstable/http/Url.d.ts +604 -0
- package/dist/unstable/http/Url.d.ts.map +1 -0
- package/dist/unstable/http/Url.js +256 -0
- package/dist/unstable/http/Url.js.map +1 -0
- package/dist/unstable/http/UrlParams.d.ts +19 -10
- package/dist/unstable/http/UrlParams.d.ts.map +1 -1
- package/dist/unstable/http/UrlParams.js +6 -7
- package/dist/unstable/http/UrlParams.js.map +1 -1
- package/dist/unstable/http/index.d.ts +8 -0
- package/dist/unstable/http/index.d.ts.map +1 -1
- package/dist/unstable/http/index.js +8 -0
- package/dist/unstable/http/index.js.map +1 -1
- package/dist/unstable/http/internal/preResponseHandler.d.ts +2 -0
- package/dist/unstable/http/internal/preResponseHandler.d.ts.map +1 -0
- package/dist/unstable/http/internal/preResponseHandler.js +10 -0
- package/dist/unstable/http/internal/preResponseHandler.js.map +1 -0
- package/dist/unstable/httpapi/HttpApi.d.ts +4 -4
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +11 -5
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +40 -27
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +83 -7
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +78 -10
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +207 -101
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +49 -43
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +31 -14
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +125 -32
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +4 -3
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +46 -15
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +32 -3
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.d.ts +6 -0
- package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +5 -0
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js +20 -2
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSecurity.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiSecurity.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSecurity.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +34 -26
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/observability/Otlp.d.ts +12 -12
- package/dist/unstable/observability/Otlp.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.d.ts +2 -2
- package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.js +3 -3
- package/dist/unstable/observability/OtlpExporter.js.map +1 -1
- package/dist/unstable/observability/OtlpLogger.d.ts +4 -4
- package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpLogger.js +7 -4
- package/dist/unstable/observability/OtlpLogger.js.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.d.ts +4 -4
- package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpTracer.d.ts +4 -4
- package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpTracer.js +7 -3
- package/dist/unstable/observability/OtlpTracer.js.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.d.ts +1 -1
- package/dist/unstable/persistence/KeyValueStore.js +6 -6
- package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
- package/dist/unstable/persistence/Persistable.d.ts +2 -2
- package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistable.js +1 -1
- package/dist/unstable/persistence/Persistable.js.map +1 -1
- package/dist/unstable/persistence/PersistedCache.d.ts +6 -5
- package/dist/unstable/persistence/PersistedCache.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedCache.js +2 -1
- package/dist/unstable/persistence/PersistedCache.js.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.d.ts +12 -12
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +12 -11
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Persistence.d.ts +1 -1
- package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistence.js +2 -2
- package/dist/unstable/persistence/Persistence.js.map +1 -1
- package/dist/unstable/persistence/RateLimiter.d.ts +3 -3
- package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
- package/dist/unstable/persistence/RateLimiter.js +1 -1
- package/dist/unstable/persistence/RateLimiter.js.map +1 -1
- package/dist/unstable/process/ChildProcess.d.ts +5 -128
- package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
- package/dist/unstable/process/ChildProcess.js +1 -65
- package/dist/unstable/process/ChildProcess.js.map +1 -1
- package/dist/unstable/process/ChildProcessSpawner.d.ts +45 -7
- package/dist/unstable/process/ChildProcessSpawner.d.ts.map +1 -1
- package/dist/unstable/process/ChildProcessSpawner.js +21 -1
- package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +73 -12
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +108 -25
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +17 -15
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +45 -15
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.d.ts +6 -0
- package/dist/unstable/reactivity/AtomRegistry.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js +54 -11
- package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.d.ts +9 -9
- package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.js +47 -21
- package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
- package/dist/unstable/reactivity/Hydration.d.ts +39 -0
- package/dist/unstable/reactivity/Hydration.d.ts.map +1 -0
- package/dist/unstable/reactivity/Hydration.js +76 -0
- package/dist/unstable/reactivity/Hydration.js.map +1 -0
- package/dist/unstable/reactivity/index.d.ts +4 -0
- package/dist/unstable/reactivity/index.d.ts.map +1 -1
- package/dist/unstable/reactivity/index.js +4 -0
- package/dist/unstable/reactivity/index.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +5 -5
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js +4 -3
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts +5 -26
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +10 -17
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcGroup.d.ts +3 -5
- package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcGroup.js.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts +8 -8
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
- package/dist/unstable/rpc/RpcSchema.d.ts +13 -0
- package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSchema.js +17 -2
- package/dist/unstable/rpc/RpcSchema.js.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.js +39 -11
- package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts +6 -10
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +20 -19
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/rpc/Utils.d.ts.map +1 -1
- package/dist/unstable/rpc/Utils.js +3 -2
- package/dist/unstable/rpc/Utils.js.map +1 -1
- package/dist/unstable/schema/Model.d.ts +22 -1
- package/dist/unstable/schema/Model.d.ts.map +1 -1
- package/dist/unstable/schema/Model.js +15 -0
- package/dist/unstable/schema/Model.js.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +6 -6
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js +6 -6
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts +6 -5
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +12 -9
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/dist/unstable/socket/SocketServer.d.ts +3 -3
- package/dist/unstable/sql/Migrator.d.ts +1 -1
- package/dist/unstable/sql/Migrator.d.ts.map +1 -1
- package/dist/unstable/sql/Migrator.js +2 -2
- package/dist/unstable/sql/Migrator.js.map +1 -1
- package/dist/unstable/sql/SqlClient.d.ts +1 -1
- package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
- package/dist/unstable/sql/SqlClient.js +1 -1
- package/dist/unstable/sql/SqlClient.js.map +1 -1
- package/dist/unstable/sql/SqlError.d.ts +237 -17
- package/dist/unstable/sql/SqlError.d.ts.map +1 -1
- package/dist/unstable/sql/SqlError.js +260 -4
- package/dist/unstable/sql/SqlError.js.map +1 -1
- package/dist/unstable/sql/SqlModel.d.ts +2 -2
- package/dist/unstable/sql/SqlModel.d.ts.map +1 -1
- package/dist/unstable/sql/SqlModel.js +3 -3
- package/dist/unstable/sql/SqlModel.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
- package/dist/unstable/sql/SqlResolver.js +17 -8
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/sql/SqlSchema.d.ts +17 -6
- package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
- package/dist/unstable/sql/SqlSchema.js +17 -7
- package/dist/unstable/sql/SqlSchema.js.map +1 -1
- package/dist/unstable/sql/Statement.js +0 -1
- package/dist/unstable/sql/Statement.js.map +1 -1
- package/dist/unstable/workers/Worker.d.ts.map +1 -1
- package/dist/unstable/workers/Worker.js +2 -1
- package/dist/unstable/workers/Worker.js.map +1 -1
- package/dist/unstable/workflow/DurableClock.d.ts +3 -3
- package/dist/unstable/workflow/DurableClock.d.ts.map +1 -1
- package/dist/unstable/workflow/DurableClock.js +3 -3
- package/dist/unstable/workflow/DurableClock.js.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.js +8 -8
- package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +5 -4
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.js +1 -1
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +17 -5
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +153 -12
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +2 -2
- package/src/Array.ts +304 -447
- package/src/BigDecimal.ts +63 -66
- package/src/BigInt.ts +49 -41
- package/src/Brand.ts +1 -1
- package/src/Cache.ts +9 -8
- package/src/Cause.ts +37 -2
- package/src/Channel.ts +582 -154
- package/src/Chunk.ts +149 -331
- package/src/Combiner.ts +280 -13
- package/src/Config.ts +195 -25
- package/src/Cron.ts +155 -63
- package/src/Data.ts +539 -376
- package/src/DateTime.ts +75 -256
- package/src/Deferred.ts +8 -6
- package/src/Duration.ts +122 -66
- package/src/Effect.ts +1483 -1157
- package/src/Encoding.ts +879 -0
- package/src/Equal.ts +278 -111
- package/src/Equivalence.ts +114 -52
- package/src/ErrorReporter.ts +458 -0
- package/src/Exit.ts +24 -12
- package/src/Fiber.ts +12 -3
- package/src/FiberHandle.ts +10 -9
- package/src/FiberMap.ts +22 -22
- package/src/FileSystem.ts +34 -31
- package/src/Filter.ts +52 -63
- package/src/Formatter.ts +253 -51
- package/src/Function.ts +2 -10
- package/src/Graph.ts +131 -117
- package/src/HashMap.ts +26 -19
- package/src/Iterable.ts +117 -63
- package/src/JsonSchema.ts +383 -10
- package/src/Latch.ts +194 -0
- package/src/Layer.ts +393 -159
- package/src/LayerMap.ts +11 -9
- package/src/LogLevel.ts +37 -0
- package/src/Logger.ts +33 -100
- package/src/ManagedRuntime.ts +2 -2
- package/src/Metric.ts +6 -8
- package/src/MutableHashMap.ts +9 -0
- package/src/MutableHashSet.ts +9 -0
- package/src/Newtype.ts +308 -0
- package/src/Number.ts +85 -26
- package/src/Optic.ts +948 -19
- package/src/Option.ts +34 -24
- package/src/Order.ts +39 -32
- package/src/PartitionedSemaphore.ts +288 -56
- package/src/Pipeable.ts +32 -1
- package/src/PlatformError.ts +5 -5
- package/src/Pool.ts +13 -11
- package/src/PubSub.ts +30 -20
- package/src/Pull.ts +1 -1
- package/src/Queue.ts +11 -9
- package/src/Random.ts +51 -14
- package/src/RcMap.ts +5 -5
- package/src/RcRef.ts +1 -1
- package/src/Record.ts +94 -199
- package/src/Reducer.ts +166 -7
- package/src/References.ts +283 -287
- package/src/Request.ts +3 -2
- package/src/RequestResolver.ts +29 -49
- package/src/Resource.ts +2 -1
- package/src/Result.ts +2 -4
- package/src/Runtime.ts +102 -6
- package/src/Schedule.ts +458 -449
- package/src/Scheduler.ts +49 -126
- package/src/Schema.ts +3298 -392
- package/src/SchemaAST.ts +172 -33
- package/src/SchemaGetter.ts +19 -21
- package/src/SchemaParser.ts +92 -27
- package/src/SchemaRepresentation.ts +51 -26
- package/src/SchemaTransformation.ts +198 -13
- package/src/ScopedCache.ts +3 -3
- package/src/Semaphore.ts +444 -0
- package/src/ServiceMap.ts +133 -71
- package/src/Sink.ts +83 -28
- package/src/Stdio.ts +27 -4
- package/src/Stream.ts +687 -617
- package/src/String.ts +122 -69
- package/src/Struct.ts +33 -7
- package/src/SubscriptionRef.ts +101 -120
- package/src/SynchronizedRef.ts +3 -2
- package/src/Terminal.ts +2 -1
- package/src/Tracer.ts +6 -5
- package/src/Trie.ts +44 -31
- package/src/TxChunk.ts +72 -53
- package/src/TxDeferred.ts +394 -0
- package/src/TxHashMap.ts +409 -343
- package/src/TxHashSet.ts +113 -118
- package/src/TxPriorityQueue.ts +766 -0
- package/src/TxPubSub.ts +789 -0
- package/src/TxQueue.ts +241 -251
- package/src/TxReentrantLock.ts +753 -0
- package/src/TxRef.ts +50 -38
- package/src/TxSemaphore.ts +217 -44
- package/src/TxSubscriptionRef.ts +639 -0
- package/src/Types.ts +73 -19
- package/src/Utils.ts +137 -111
- package/src/index.ts +814 -54
- package/src/internal/core.ts +12 -5
- package/src/internal/dateTime.ts +91 -96
- package/src/internal/effect.ts +841 -432
- package/src/internal/hashMap.ts +12 -10
- package/src/internal/option.ts +7 -0
- package/src/internal/random.ts +20 -0
- package/src/internal/rcRef.ts +4 -3
- package/src/internal/references.ts +72 -0
- package/src/internal/request.ts +2 -2
- package/src/internal/schema/annotations.ts +2 -0
- package/src/internal/schema/representation.ts +45 -94
- package/src/internal/schema/schema.ts +1 -0
- package/src/internal/schema/to-codec.ts +7 -17
- package/src/internal/trie.ts +21 -15
- package/src/testing/TestClock.ts +13 -11
- package/src/testing/TestSchema.ts +332 -35
- package/src/testing/index.ts +64 -1
- package/src/unstable/ai/AiError.ts +111 -54
- package/src/unstable/ai/AnthropicStructuredOutput.ts +4 -0
- package/src/unstable/ai/Chat.ts +62 -74
- package/src/unstable/ai/EmbeddingModel.ts +209 -0
- package/src/unstable/ai/LanguageModel.ts +544 -230
- package/src/unstable/ai/McpSchema.ts +73 -13
- package/src/unstable/ai/McpServer.ts +271 -61
- package/src/unstable/ai/Model.ts +40 -9
- package/src/unstable/ai/OpenAiStructuredOutput.ts +4 -0
- package/src/unstable/ai/Prompt.ts +37 -37
- package/src/unstable/ai/Response.ts +25 -25
- package/src/unstable/ai/ResponseIdTracker.ts +97 -0
- package/src/unstable/ai/Tool.ts +42 -16
- package/src/unstable/ai/Toolkit.ts +5 -14
- package/src/unstable/ai/index.ts +24 -1
- package/src/unstable/ai/internal/codec-transformer.ts +0 -7
- package/src/unstable/cli/Argument.ts +2 -4
- package/src/unstable/cli/CliError.ts +47 -59
- package/src/unstable/cli/CliOutput.ts +85 -13
- package/src/unstable/cli/Command.ts +801 -192
- package/src/unstable/cli/Completions.ts +36 -0
- package/src/unstable/cli/Flag.ts +2 -2
- package/src/unstable/cli/GlobalFlag.ts +242 -0
- package/src/unstable/cli/HelpDoc.ts +91 -11
- package/src/unstable/cli/Param.ts +15 -11
- package/src/unstable/cli/Primitive.ts +2 -2
- package/src/unstable/cli/Prompt.ts +262 -100
- package/src/unstable/cli/index.ts +10 -0
- package/src/unstable/cli/internal/command.ts +109 -63
- package/src/unstable/cli/internal/completions/CommandDescriptor.ts +10 -4
- package/src/unstable/cli/internal/config.ts +49 -0
- package/src/unstable/cli/internal/help.ts +171 -0
- package/src/unstable/cli/internal/parser.ts +71 -63
- package/src/unstable/cluster/ClusterCron.ts +2 -2
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +40 -34
- package/src/unstable/cluster/DeliverAt.ts +1 -1
- package/src/unstable/cluster/Entity.ts +24 -22
- package/src/unstable/cluster/EntityAddress.ts +1 -1
- package/src/unstable/cluster/EntityResource.ts +4 -4
- package/src/unstable/cluster/Envelope.ts +1 -1
- package/src/unstable/cluster/K8sHttpClient.ts +5 -5
- package/src/unstable/cluster/Message.ts +6 -5
- package/src/unstable/cluster/MessageStorage.ts +29 -30
- package/src/unstable/cluster/Reply.ts +7 -4
- package/src/unstable/cluster/Runner.ts +1 -1
- package/src/unstable/cluster/RunnerAddress.ts +1 -1
- package/src/unstable/cluster/RunnerServer.ts +10 -13
- package/src/unstable/cluster/Runners.ts +14 -12
- package/src/unstable/cluster/ShardId.ts +2 -2
- package/src/unstable/cluster/Sharding.ts +36 -27
- package/src/unstable/cluster/ShardingConfig.ts +36 -37
- package/src/unstable/cluster/SqlMessageStorage.ts +21 -18
- package/src/unstable/cluster/SqlRunnerStorage.ts +1 -1
- package/src/unstable/cluster/internal/entityManager.ts +36 -29
- package/src/unstable/cluster/internal/entityReaper.ts +2 -1
- package/src/unstable/cluster/internal/resourceRef.ts +2 -1
- package/src/unstable/devtools/DevToolsClient.ts +23 -18
- package/src/unstable/devtools/DevToolsSchema.ts +16 -3
- package/src/unstable/encoding/Ndjson.ts +17 -17
- package/src/unstable/encoding/Sse.ts +3 -5
- package/src/unstable/eventlog/EventJournal.ts +2 -2
- package/src/unstable/eventlog/EventLog.ts +3 -2
- package/src/unstable/eventlog/SqlEventLogJournal.ts +2 -2
- package/src/unstable/http/Cookies.ts +94 -11
- package/src/unstable/http/Etag.ts +5 -3
- package/src/unstable/http/Headers.ts +68 -18
- package/src/unstable/http/HttpClient.ts +376 -34
- package/src/unstable/http/HttpClientRequest.ts +151 -39
- package/src/unstable/http/HttpClientResponse.ts +12 -6
- package/src/unstable/http/HttpEffect.ts +54 -68
- package/src/unstable/http/HttpIncomingMessage.ts +3 -2
- package/src/unstable/http/HttpMethod.ts +16 -4
- package/src/unstable/http/HttpMiddleware.ts +25 -39
- package/src/unstable/http/HttpPlatform.ts +3 -2
- package/src/unstable/http/HttpRouter.ts +9 -9
- package/src/unstable/http/HttpServer.ts +3 -9
- package/src/unstable/http/HttpServerError.ts +45 -47
- package/src/unstable/http/HttpServerRequest.ts +407 -16
- package/src/unstable/http/HttpServerRespondable.ts +6 -6
- package/src/unstable/http/HttpServerResponse.ts +345 -7
- package/src/unstable/http/HttpStaticServer.ts +456 -0
- package/src/unstable/http/HttpTraceContext.ts +31 -17
- package/src/unstable/http/Multipart.ts +2 -2
- package/src/unstable/http/Url.ts +650 -0
- package/src/unstable/http/UrlParams.ts +31 -19
- package/src/unstable/http/index.ts +10 -0
- package/src/unstable/http/internal/preResponseHandler.ts +15 -0
- package/src/unstable/httpapi/HttpApi.ts +6 -6
- package/src/unstable/httpapi/HttpApiBuilder.ts +106 -41
- package/src/unstable/httpapi/HttpApiClient.ts +180 -28
- package/src/unstable/httpapi/HttpApiEndpoint.ts +216 -104
- package/src/unstable/httpapi/HttpApiError.ts +108 -30
- package/src/unstable/httpapi/HttpApiGroup.ts +7 -6
- package/src/unstable/httpapi/HttpApiMiddleware.ts +83 -22
- package/src/unstable/httpapi/HttpApiScalar.ts +6 -0
- package/src/unstable/httpapi/HttpApiSchema.ts +20 -2
- package/src/unstable/httpapi/HttpApiSecurity.ts +3 -3
- package/src/unstable/httpapi/OpenApi.ts +43 -29
- package/src/unstable/observability/Otlp.ts +12 -12
- package/src/unstable/observability/OtlpExporter.ts +8 -5
- package/src/unstable/observability/OtlpLogger.ts +13 -9
- package/src/unstable/observability/OtlpMetrics.ts +4 -4
- package/src/unstable/observability/OtlpTracer.ts +12 -8
- package/src/unstable/persistence/KeyValueStore.ts +6 -6
- package/src/unstable/persistence/Persistable.ts +3 -3
- package/src/unstable/persistence/PersistedCache.ts +20 -9
- package/src/unstable/persistence/PersistedQueue.ts +25 -24
- package/src/unstable/persistence/Persistence.ts +3 -3
- package/src/unstable/persistence/RateLimiter.ts +4 -4
- package/src/unstable/process/ChildProcess.ts +6 -208
- package/src/unstable/process/ChildProcessSpawner.ts +75 -14
- package/src/unstable/reactivity/Atom.ts +212 -54
- package/src/unstable/reactivity/AtomHttpApi.ts +81 -41
- package/src/unstable/reactivity/AtomRegistry.ts +66 -12
- package/src/unstable/reactivity/AtomRpc.ts +51 -20
- package/src/unstable/reactivity/Hydration.ts +112 -0
- package/src/unstable/reactivity/index.ts +5 -0
- package/src/unstable/rpc/Rpc.ts +11 -12
- package/src/unstable/rpc/RpcClient.ts +22 -63
- package/src/unstable/rpc/RpcGroup.ts +7 -7
- package/src/unstable/rpc/RpcMiddleware.ts +15 -9
- package/src/unstable/rpc/RpcSchema.ts +23 -5
- package/src/unstable/rpc/RpcSerialization.ts +49 -11
- package/src/unstable/rpc/RpcServer.ts +31 -35
- package/src/unstable/rpc/Utils.ts +3 -2
- package/src/unstable/schema/Model.ts +31 -0
- package/src/unstable/schema/VariantSchema.ts +10 -10
- package/src/unstable/socket/Socket.ts +31 -27
- package/src/unstable/sql/Migrator.ts +7 -5
- package/src/unstable/sql/SqlClient.ts +6 -4
- package/src/unstable/sql/SqlError.ts +365 -11
- package/src/unstable/sql/SqlModel.ts +5 -5
- package/src/unstable/sql/SqlResolver.ts +17 -7
- package/src/unstable/sql/SqlSchema.ts +42 -26
- package/src/unstable/sql/Statement.ts +0 -1
- package/src/unstable/workers/Worker.ts +2 -1
- package/src/unstable/workflow/DurableClock.ts +8 -8
- package/src/unstable/workflow/DurableDeferred.ts +8 -8
- package/src/unstable/workflow/Workflow.ts +7 -3
- package/src/unstable/workflow/WorkflowEngine.ts +211 -19
- package/dist/NullOr.d.ts +0 -149
- package/dist/NullOr.d.ts.map +0 -1
- package/dist/NullOr.js +0 -152
- package/dist/NullOr.js.map +0 -1
- package/dist/encoding/Base64.d.ts +0 -67
- package/dist/encoding/Base64.d.ts.map +0 -1
- package/dist/encoding/Base64.js +0 -146
- package/dist/encoding/Base64.js.map +0 -1
- package/dist/encoding/Base64Url.d.ts +0 -60
- package/dist/encoding/Base64Url.d.ts.map +0 -1
- package/dist/encoding/Base64Url.js +0 -89
- package/dist/encoding/Base64Url.js.map +0 -1
- package/dist/encoding/EncodingError.d.ts +0 -31
- package/dist/encoding/EncodingError.d.ts.map +0 -1
- package/dist/encoding/EncodingError.js +0 -22
- package/dist/encoding/EncodingError.js.map +0 -1
- package/dist/encoding/Hex.d.ts +0 -61
- package/dist/encoding/Hex.d.ts.map +0 -1
- package/dist/encoding/Hex.js +0 -115
- package/dist/encoding/Hex.js.map +0 -1
- package/dist/encoding/index.d.ts +0 -26
- package/dist/encoding/index.d.ts.map +0 -1
- package/dist/encoding/index.js +0 -27
- package/dist/encoding/index.js.map +0 -1
- package/dist/unstable/cli/internal/builtInFlags.d.ts +0 -7
- package/dist/unstable/cli/internal/builtInFlags.d.ts.map +0 -1
- package/dist/unstable/cli/internal/builtInFlags.js +0 -44
- package/dist/unstable/cli/internal/builtInFlags.js.map +0 -1
- package/dist/unstable/cli/internal/completions/Completions.d.ts +0 -2
- package/dist/unstable/cli/internal/completions/Completions.d.ts.map +0 -1
- package/dist/unstable/cli/internal/completions/Completions.js +0 -23
- package/dist/unstable/cli/internal/completions/Completions.js.map +0 -1
- package/src/NullOr.ts +0 -204
- package/src/encoding/Base64.ts +0 -366
- package/src/encoding/Base64Url.ts +0 -104
- package/src/encoding/EncodingError.ts +0 -35
- package/src/encoding/Hex.ts +0 -390
- package/src/encoding/index.ts +0 -31
- package/src/unstable/cli/internal/builtInFlags.ts +0 -78
- package/src/unstable/cli/internal/completions/Completions.ts +0 -31
package/dist/Schema.js
CHANGED
|
@@ -1,18 +1,104 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Define data shapes, validate unknown input, and transform values between formats.
|
|
3
|
+
*
|
|
4
|
+
* ## Mental model
|
|
5
|
+
*
|
|
6
|
+
* - **Schema** — a description of a data shape. Every schema carries a decoded
|
|
7
|
+
* *Type* (the value you work with) and an *Encoded* representation (the
|
|
8
|
+
* serialized form, e.g. JSON).
|
|
9
|
+
* - **Decoding** — turning unknown external data (API responses, form
|
|
10
|
+
* submissions, config files) into typed, validated values.
|
|
11
|
+
* - **Encoding** — turning typed values back into a serializable format.
|
|
12
|
+
* - **Codec** — a schema that tracks both Type and Encoded, so it can decode
|
|
13
|
+
* *and* encode. Most concrete schemas are Codecs.
|
|
14
|
+
* - **Check / Filter** — a constraint attached to a schema (e.g. `isMinLength`,
|
|
15
|
+
* `isGreaterThan`). Attach them with `.check(...)`.
|
|
16
|
+
* - **Transformation** — a pair of functions (decode + encode) that convert
|
|
17
|
+
* values between two schemas. Created with {@link decodeTo} / {@link encodeTo}.
|
|
18
|
+
* - **Annotation** — metadata attached to a schema (title, description, custom
|
|
19
|
+
* keys). Attach with `.annotate(...)`.
|
|
20
|
+
*
|
|
21
|
+
* ## Common tasks
|
|
22
|
+
*
|
|
23
|
+
* - Define a struct: {@link Struct}
|
|
24
|
+
* - Define a union: {@link Union}, {@link TaggedUnion}, {@link Literals}
|
|
25
|
+
* - Define an array: {@link ArraySchema}, {@link NonEmptyArray}
|
|
26
|
+
* - Define a record: {@link Record}
|
|
27
|
+
* - Define a tuple: {@link Tuple}, {@link TupleWithRest}
|
|
28
|
+
* - Validate unknown data synchronously: {@link decodeUnknownSync}
|
|
29
|
+
* - Validate unknown data (Effect): {@link decodeUnknownEffect}
|
|
30
|
+
* - Encode a value: {@link encodeUnknownSync}, {@link encodeUnknownEffect}
|
|
31
|
+
* - Type guard: {@link is}
|
|
32
|
+
* - Assertion: {@link asserts}
|
|
33
|
+
* - Add constraints: `.check(...)` with filters like {@link isMinLength},
|
|
34
|
+
* {@link isGreaterThan}, {@link isPattern}, {@link isUUID}
|
|
35
|
+
* - Transform between schemas: {@link decodeTo}, {@link encodeTo}
|
|
36
|
+
* - Add a default for missing keys: {@link withDecodingDefault}, {@link withDecodingDefaultKey}
|
|
37
|
+
* - Create branded types: {@link brand}
|
|
38
|
+
* - Define classes with validation: {@link Class}, {@link TaggedClass}
|
|
39
|
+
* - Define error classes: {@link ErrorClass}, {@link TaggedErrorClass}
|
|
40
|
+
* - Generate JSON Schema: {@link toJsonSchemaDocument}
|
|
41
|
+
* - Generate test data: {@link toArbitrary}
|
|
42
|
+
* - Derive equivalence: {@link toEquivalence}
|
|
43
|
+
*
|
|
44
|
+
* ## Gotchas
|
|
45
|
+
*
|
|
46
|
+
* - `Schema.optional` creates `T | undefined` (key can be missing *or*
|
|
47
|
+
* `undefined`). Use `Schema.optionalKey` for exact optional properties.
|
|
48
|
+
* - `decodeTo` is curried: use `from.pipe(Schema.decodeTo(to, ...))`.
|
|
49
|
+
* - `decodeUnknownSync` throws on failure. Use `decodeUnknownExit` or
|
|
50
|
+
* `decodeUnknownOption` for non-throwing alternatives.
|
|
51
|
+
* - Filters do not change the TypeScript type. Use {@link refine} or
|
|
52
|
+
* {@link brand} to narrow the type.
|
|
53
|
+
* - Recursive schemas require {@link suspend} to avoid infinite loops.
|
|
54
|
+
*
|
|
55
|
+
* ## Quickstart
|
|
56
|
+
*
|
|
57
|
+
* **Example** (Validate a user object)
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { Schema } from "effect"
|
|
61
|
+
*
|
|
62
|
+
* const User = Schema.Struct({
|
|
63
|
+
* name: Schema.String.check(Schema.isMinLength(1)),
|
|
64
|
+
* age: Schema.Number.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
65
|
+
* email: Schema.optionalKey(Schema.String)
|
|
66
|
+
* })
|
|
67
|
+
*
|
|
68
|
+
* // Decode unknown input — throws on failure
|
|
69
|
+
* const user = Schema.decodeUnknownSync(User)({
|
|
70
|
+
* name: "Alice",
|
|
71
|
+
* age: 30
|
|
72
|
+
* })
|
|
73
|
+
*
|
|
74
|
+
* console.log(user)
|
|
75
|
+
* // { name: "Alice", age: 30 }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @see {@link Schema} — type-level view tracking only the decoded Type
|
|
79
|
+
* @see {@link Codec} — type-level view tracking both Type and Encoded
|
|
80
|
+
* @see {@link Struct} — define object shapes
|
|
81
|
+
* @see {@link decodeUnknownSync} — synchronous validation
|
|
82
|
+
* @see {@link decodeTo} — schema transformations
|
|
83
|
+
*
|
|
2
84
|
* @since 4.0.0
|
|
3
85
|
*/
|
|
4
86
|
import * as Arr from "./Array.js";
|
|
87
|
+
import * as BigDecimal_ from "./BigDecimal.js";
|
|
5
88
|
import * as Cause_ from "./Cause.js";
|
|
89
|
+
import * as Chunk_ from "./Chunk.js";
|
|
6
90
|
import * as Data from "./Data.js";
|
|
7
91
|
import * as DateTime from "./DateTime.js";
|
|
8
92
|
import * as Duration_ from "./Duration.js";
|
|
9
93
|
import * as Effect from "./Effect.js";
|
|
10
|
-
import * as
|
|
94
|
+
import * as Encoding from "./Encoding.js";
|
|
11
95
|
import * as Equal from "./Equal.js";
|
|
12
96
|
import * as Equivalence from "./Equivalence.js";
|
|
13
97
|
import * as Exit_ from "./Exit.js";
|
|
14
98
|
import { format, formatDate, formatPropertyKey } from "./Formatter.js";
|
|
15
99
|
import { identity } from "./Function.js";
|
|
100
|
+
import * as HashMap_ from "./HashMap.js";
|
|
101
|
+
import * as HashSet_ from "./HashSet.js";
|
|
16
102
|
import * as core from "./internal/core.js";
|
|
17
103
|
import * as InternalAnnotations from "./internal/schema/annotations.js";
|
|
18
104
|
import * as InternalArbitrary from "./internal/schema/arbitrary.js";
|
|
@@ -41,9 +127,51 @@ import * as Struct_ from "./Struct.js";
|
|
|
41
127
|
import * as FastCheck from "./testing/FastCheck.js";
|
|
42
128
|
const TypeId = InternalSchema.TypeId;
|
|
43
129
|
/**
|
|
44
|
-
*
|
|
130
|
+
* Creates a schema for a **parametric** type (a generic container such as
|
|
131
|
+
* `Array<A>`, `Option<A>`, etc.) by accepting a list of type-parameter schemas
|
|
132
|
+
* and a decoder factory.
|
|
133
|
+
*
|
|
134
|
+
* The outer call `declareConstructor<T, E, Iso>()` fixes the decoded type `T`,
|
|
135
|
+
* the encoded type `E`, and the optional iso type. The inner call receives:
|
|
136
|
+
* - `typeParameters` — the concrete schemas for each type variable
|
|
137
|
+
* - `run` — a factory that, given resolved codecs for each type parameter,
|
|
138
|
+
* returns a parsing function `(u, ast, options) => Effect<T, Issue>`
|
|
139
|
+
* - `annotations` — optional metadata
|
|
45
140
|
*
|
|
46
|
-
* @see {@link declare} for creating schemas for non
|
|
141
|
+
* @see {@link declare} for creating schemas for non-parametric types.
|
|
142
|
+
*
|
|
143
|
+
* **Example** (Schema for a parametric `Box<A>` type)
|
|
144
|
+
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* import { Effect, Schema } from "effect"
|
|
147
|
+
* import * as SchemaParser from "effect/SchemaParser"
|
|
148
|
+
* import * as Issue from "effect/SchemaIssue"
|
|
149
|
+
* import * as Option from "effect/Option"
|
|
150
|
+
*
|
|
151
|
+
* interface Box<A> {
|
|
152
|
+
* readonly value: A
|
|
153
|
+
* }
|
|
154
|
+
*
|
|
155
|
+
* const isBox = (u: unknown): u is Box<unknown> =>
|
|
156
|
+
* typeof u === "object" && u !== null && "value" in u
|
|
157
|
+
*
|
|
158
|
+
* const Box = <A extends Schema.Top>(item: A) =>
|
|
159
|
+
* Schema.declareConstructor<Box<A["Type"]>, Box<A["Encoded"]>>()(
|
|
160
|
+
* [item],
|
|
161
|
+
* ([itemCodec]) =>
|
|
162
|
+
* (u, ast, options) => {
|
|
163
|
+
* if (!isBox(u)) {
|
|
164
|
+
* return Effect.fail(new Issue.InvalidType(ast, Option.some(u)))
|
|
165
|
+
* }
|
|
166
|
+
* return Effect.map(
|
|
167
|
+
* SchemaParser.decodeUnknownEffect(itemCodec)(u.value, options),
|
|
168
|
+
* (value) => ({ value })
|
|
169
|
+
* )
|
|
170
|
+
* }
|
|
171
|
+
* )
|
|
172
|
+
*
|
|
173
|
+
* const schema = Box(Schema.Number)
|
|
174
|
+
* ```
|
|
47
175
|
*
|
|
48
176
|
* @category Constructors
|
|
49
177
|
* @since 4.0.0
|
|
@@ -54,18 +182,60 @@ export function declareConstructor() {
|
|
|
54
182
|
};
|
|
55
183
|
}
|
|
56
184
|
/**
|
|
57
|
-
*
|
|
185
|
+
* Creates a schema for a **non-parametric** opaque type using a type-guard
|
|
186
|
+
* function. The schema accepts any unknown value and succeeds when `is` returns
|
|
187
|
+
* `true`, failing with an `InvalidType` issue otherwise.
|
|
188
|
+
*
|
|
189
|
+
* Use this when the type has no type parameters. For parametric types such as
|
|
190
|
+
* `Option<A>` or `Array<A>`, use {@link declareConstructor} instead.
|
|
191
|
+
*
|
|
192
|
+
* **Example** (Schema for a custom `UserId` branded type)
|
|
193
|
+
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* import { Schema } from "effect"
|
|
196
|
+
*
|
|
197
|
+
* type UserId = string & { readonly _tag: "UserId" }
|
|
198
|
+
*
|
|
199
|
+
* const isUserId = (u: unknown): u is UserId =>
|
|
200
|
+
* typeof u === "string" && u.startsWith("user_")
|
|
201
|
+
*
|
|
202
|
+
* const UserId = Schema.declare<UserId>(isUserId, {
|
|
203
|
+
* title: "UserId",
|
|
204
|
+
* description: "A user identifier starting with 'user_'"
|
|
205
|
+
* })
|
|
206
|
+
* ```
|
|
58
207
|
*
|
|
59
208
|
* @see {@link declareConstructor} for creating schemas for parametric types.
|
|
60
209
|
*
|
|
210
|
+
* @category Constructors
|
|
61
211
|
* @since 4.0.0
|
|
62
212
|
*/
|
|
63
213
|
export function declare(is, annotations) {
|
|
64
214
|
return declareConstructor()([], () => (input, ast) => is(input) ? Effect.succeed(input) : Effect.fail(new Issue.InvalidType(ast, Option_.some(input))), annotations);
|
|
65
215
|
}
|
|
66
216
|
/**
|
|
67
|
-
*
|
|
68
|
-
* parameters.
|
|
217
|
+
* Widens a schema's type to the fully-parameterized {@link Bottom} interface,
|
|
218
|
+
* making all 14 type parameters visible to TypeScript.
|
|
219
|
+
*
|
|
220
|
+
* Normally, concrete schema interfaces (e.g. `Schema<string>`) hide most type
|
|
221
|
+
* parameters. `revealBottom` is useful when writing generic utilities that need
|
|
222
|
+
* to inspect or propagate the complete set of type parameters.
|
|
223
|
+
*
|
|
224
|
+
* **Example** (Inspecting all type parameters of a schema)
|
|
225
|
+
*
|
|
226
|
+
* ```ts
|
|
227
|
+
* import { Schema } from "effect"
|
|
228
|
+
*
|
|
229
|
+
* const schema = Schema.String
|
|
230
|
+
*
|
|
231
|
+
* // Widen to Bottom to access all 14 type parameters
|
|
232
|
+
* const bottom = Schema.revealBottom(schema)
|
|
233
|
+
*
|
|
234
|
+
* // `bottom` now exposes Type, Encoded, DecodingServices, EncodingServices,
|
|
235
|
+
* // ast, ~rebuild.out, ~type.make.in, Iso, ~type.parameters, etc.
|
|
236
|
+
* type T = typeof bottom["Type"] // string
|
|
237
|
+
* type E = typeof bottom["Encoded"] // string
|
|
238
|
+
* ```
|
|
69
239
|
*
|
|
70
240
|
* @since 4.0.0
|
|
71
241
|
*/
|
|
@@ -74,8 +244,24 @@ export function revealBottom(bottom) {
|
|
|
74
244
|
}
|
|
75
245
|
/**
|
|
76
246
|
* Adds metadata annotations to a schema without changing its runtime behavior.
|
|
77
|
-
*
|
|
78
|
-
*
|
|
247
|
+
* This is the pipeable (curried) counterpart of the `.annotate` method.
|
|
248
|
+
*
|
|
249
|
+
* Annotations provide extra context used by documentation generators, JSON
|
|
250
|
+
* Schema converters, error formatters, and other tooling. Common keys include
|
|
251
|
+
* `title`, `description`, `examples`, `message`, and `identifier`.
|
|
252
|
+
*
|
|
253
|
+
* **Example** (Adding a title and description)
|
|
254
|
+
*
|
|
255
|
+
* ```ts
|
|
256
|
+
* import { Schema } from "effect"
|
|
257
|
+
*
|
|
258
|
+
* const Age = Schema.Number.pipe(
|
|
259
|
+
* Schema.annotate({
|
|
260
|
+
* title: "Age",
|
|
261
|
+
* description: "A non-negative integer representing age in years"
|
|
262
|
+
* })
|
|
263
|
+
* )
|
|
264
|
+
* ```
|
|
79
265
|
*
|
|
80
266
|
* @category Annotations
|
|
81
267
|
* @since 4.0.0
|
|
@@ -86,9 +272,29 @@ export function annotate(annotations) {
|
|
|
86
272
|
};
|
|
87
273
|
}
|
|
88
274
|
/**
|
|
89
|
-
* Adds key-
|
|
90
|
-
*
|
|
91
|
-
*
|
|
275
|
+
* Adds key-level annotations to a schema field. This is the pipeable
|
|
276
|
+
* (curried) counterpart of the `.annotateKey` method.
|
|
277
|
+
*
|
|
278
|
+
* Key annotations apply to a field's position inside a `Struct` or `Tuple`
|
|
279
|
+
* rather than to the field's value type. They can carry a
|
|
280
|
+
* `messageMissingKey` to customise the error shown when the field is absent,
|
|
281
|
+
* as well as standard documentation fields such as `title`, `description`,
|
|
282
|
+
* and `examples`.
|
|
283
|
+
*
|
|
284
|
+
* **Example** (Custom missing-key message for a required field)
|
|
285
|
+
*
|
|
286
|
+
* ```ts
|
|
287
|
+
* import { Schema } from "effect"
|
|
288
|
+
*
|
|
289
|
+
* const schema = Schema.Struct({
|
|
290
|
+
* username: Schema.String.pipe(
|
|
291
|
+
* Schema.annotateKey({
|
|
292
|
+
* description: "The username used to log in",
|
|
293
|
+
* messageMissingKey: "Username is required"
|
|
294
|
+
* })
|
|
295
|
+
* )
|
|
296
|
+
* })
|
|
297
|
+
* ```
|
|
92
298
|
*
|
|
93
299
|
* @category Annotations
|
|
94
300
|
* @since 4.0.0
|
|
@@ -99,6 +305,25 @@ export function annotateKey(annotations) {
|
|
|
99
305
|
};
|
|
100
306
|
}
|
|
101
307
|
/**
|
|
308
|
+
* Identity function that widens a value to the full {@link Codec} interface,
|
|
309
|
+
* prompting TypeScript to infer all four type parameters (`T`, `E`, `RD`, `RE`).
|
|
310
|
+
*
|
|
311
|
+
* When a schema is stored in a variable typed as `Schema<T>` or `Top`, the
|
|
312
|
+
* encoded type and service requirements are erased. Passing the value through
|
|
313
|
+
* `revealCodec` recovers those parameters without any runtime cost.
|
|
314
|
+
*
|
|
315
|
+
* **Example** (Recovering encoded type from a schema variable)
|
|
316
|
+
*
|
|
317
|
+
* ```ts
|
|
318
|
+
* import { Schema } from "effect"
|
|
319
|
+
*
|
|
320
|
+
* const schema: Schema.Schema<number> = Schema.NumberFromString
|
|
321
|
+
*
|
|
322
|
+
* // Without revealCodec, Encoded is unknown
|
|
323
|
+
* const codec = Schema.revealCodec(schema)
|
|
324
|
+
* type Enc = typeof codec["Encoded"] // string
|
|
325
|
+
* ```
|
|
326
|
+
*
|
|
102
327
|
* @since 4.0.0
|
|
103
328
|
*/
|
|
104
329
|
export function revealCodec(codec) {
|
|
@@ -106,12 +331,30 @@ export function revealCodec(codec) {
|
|
|
106
331
|
}
|
|
107
332
|
const SchemaErrorTypeId = "~effect/Schema/SchemaError";
|
|
108
333
|
/**
|
|
109
|
-
*
|
|
334
|
+
* Error thrown (or returned as the error channel value) when schema decoding
|
|
335
|
+
* or encoding fails.
|
|
336
|
+
*
|
|
337
|
+
* The `issue` field contains a structured {@link Issue.Issue} tree describing
|
|
338
|
+
* every validation failure, including the path to the problematic value,
|
|
339
|
+
* expected types, and actual values received. `message` renders the issue tree
|
|
340
|
+
* as a human-readable string.
|
|
110
341
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
342
|
+
* Use {@link isSchemaError} to narrow an unknown value to `SchemaError`.
|
|
343
|
+
*
|
|
344
|
+
* **Example** (Catching a SchemaError)
|
|
345
|
+
*
|
|
346
|
+
* ```ts
|
|
347
|
+
* import { Schema } from "effect"
|
|
348
|
+
*
|
|
349
|
+
* try {
|
|
350
|
+
* Schema.decodeUnknownSync(Schema.Number)("not a number")
|
|
351
|
+
* } catch (err) {
|
|
352
|
+
* if (Schema.isSchemaError(err)) {
|
|
353
|
+
* console.log(err.message)
|
|
354
|
+
* // Expected number, actual "not a number"
|
|
355
|
+
* }
|
|
356
|
+
* }
|
|
357
|
+
* ```
|
|
115
358
|
*
|
|
116
359
|
* @since 4.0.0
|
|
117
360
|
*/
|
|
@@ -131,6 +374,22 @@ export class SchemaError {
|
|
|
131
374
|
}
|
|
132
375
|
}
|
|
133
376
|
/**
|
|
377
|
+
* Returns `true` if `u` is a {@link SchemaError}.
|
|
378
|
+
*
|
|
379
|
+
* **Example** (Type guard in a catch block)
|
|
380
|
+
*
|
|
381
|
+
* ```ts
|
|
382
|
+
* import { Schema } from "effect"
|
|
383
|
+
*
|
|
384
|
+
* try {
|
|
385
|
+
* Schema.decodeUnknownSync(Schema.Number)("oops")
|
|
386
|
+
* } catch (err) {
|
|
387
|
+
* if (Schema.isSchemaError(err)) {
|
|
388
|
+
* console.log(err._tag) // "SchemaError"
|
|
389
|
+
* }
|
|
390
|
+
* }
|
|
391
|
+
* ```
|
|
392
|
+
*
|
|
134
393
|
* @since 4.0.0
|
|
135
394
|
*/
|
|
136
395
|
export function isSchemaError(u) {
|
|
@@ -221,7 +480,7 @@ export function toStandardSchemaV1(self, options) {
|
|
|
221
480
|
}), {
|
|
222
481
|
scheduler
|
|
223
482
|
});
|
|
224
|
-
|
|
483
|
+
fiber.currentDispatcher?.flush();
|
|
225
484
|
const exit = fiber.pollUnsafe();
|
|
226
485
|
if (exit) {
|
|
227
486
|
return makeStandardResult(exit);
|
|
@@ -370,6 +629,11 @@ export const is = Parser.is;
|
|
|
370
629
|
*/
|
|
371
630
|
export const asserts = Parser.asserts;
|
|
372
631
|
/**
|
|
632
|
+
* Decodes an `unknown` input against a schema, returning an `Effect` that
|
|
633
|
+
* succeeds with the decoded value or fails with a {@link SchemaError}. Use this
|
|
634
|
+
* when the input type is not statically known. Prefer {@link decodeEffect} when
|
|
635
|
+
* the input is already typed as the schema's `Encoded` type.
|
|
636
|
+
*
|
|
373
637
|
* @category Decoding
|
|
374
638
|
* @since 4.0.0
|
|
375
639
|
*/
|
|
@@ -380,11 +644,22 @@ export function decodeUnknownEffect(schema) {
|
|
|
380
644
|
};
|
|
381
645
|
}
|
|
382
646
|
/**
|
|
647
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
648
|
+
* returning an `Effect` that succeeds with the decoded value or fails with a
|
|
649
|
+
* {@link SchemaError}. Use this when the input is already typed; for `unknown`
|
|
650
|
+
* input use {@link decodeUnknownEffect}.
|
|
651
|
+
*
|
|
383
652
|
* @category Decoding
|
|
384
653
|
* @since 4.0.0
|
|
385
654
|
*/
|
|
386
655
|
export const decodeEffect = decodeUnknownEffect;
|
|
387
656
|
/**
|
|
657
|
+
* Decodes an `unknown` input against a schema synchronously, returning an
|
|
658
|
+
* `Exit` that is either a `Success` with the decoded value or a `Failure` with
|
|
659
|
+
* a {@link SchemaError}. Only usable with schemas that have no
|
|
660
|
+
* `DecodingServices` requirement. Prefer {@link decodeExit} when the input is
|
|
661
|
+
* already typed as the schema's `Encoded` type.
|
|
662
|
+
*
|
|
388
663
|
* @category Decoding
|
|
389
664
|
* @since 4.0.0
|
|
390
665
|
*/
|
|
@@ -395,41 +670,120 @@ export function decodeUnknownExit(schema) {
|
|
|
395
670
|
};
|
|
396
671
|
}
|
|
397
672
|
/**
|
|
673
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
674
|
+
* synchronously, returning an `Exit` that is either a `Success` with the
|
|
675
|
+
* decoded value or a `Failure` with a {@link SchemaError}. Only usable with
|
|
676
|
+
* schemas that have no `DecodingServices` requirement. For `unknown` input use
|
|
677
|
+
* {@link decodeUnknownExit}.
|
|
678
|
+
*
|
|
398
679
|
* @category Decoding
|
|
399
680
|
* @since 4.0.0
|
|
400
681
|
*/
|
|
401
682
|
export const decodeExit = decodeUnknownExit;
|
|
402
683
|
/**
|
|
684
|
+
* Decodes an `unknown` input against a schema, returning an `Option` that is
|
|
685
|
+
* `Some` with the decoded value on success or `None` on failure. Prefer this
|
|
686
|
+
* over {@link decodeUnknownExit} or {@link decodeUnknownEffect} when you only
|
|
687
|
+
* need to know whether decoding succeeded and don't need error details. For
|
|
688
|
+
* typed input use {@link decodeOption}.
|
|
689
|
+
*
|
|
403
690
|
* @category Decoding
|
|
404
691
|
* @since 4.0.0
|
|
405
692
|
*/
|
|
406
693
|
export const decodeUnknownOption = Parser.decodeUnknownOption;
|
|
407
694
|
/**
|
|
695
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
696
|
+
* returning an `Option` that is `Some` with the decoded value on success or
|
|
697
|
+
* `None` on failure. For `unknown` input use {@link decodeUnknownOption}.
|
|
698
|
+
*
|
|
408
699
|
* @category Decoding
|
|
409
700
|
* @since 4.0.0
|
|
410
701
|
*/
|
|
411
702
|
export const decodeOption = Parser.decodeOption;
|
|
703
|
+
/**
|
|
704
|
+
* Decodes an `unknown` input against a schema, returning a `Promise` that
|
|
705
|
+
* resolves with the decoded value or rejects with a {@link SchemaError}. Useful
|
|
706
|
+
* for integrating with Promise-based APIs. For typed input use
|
|
707
|
+
* {@link decodePromise}.
|
|
708
|
+
*
|
|
709
|
+
* @category Decoding
|
|
710
|
+
* @since 4.0.0
|
|
711
|
+
*/
|
|
712
|
+
export const decodeUnknownResult = Parser.decodeUnknownResult;
|
|
713
|
+
/**
|
|
714
|
+
* @category Decoding
|
|
715
|
+
* @since 4.0.0
|
|
716
|
+
*/
|
|
717
|
+
export const decodeResult = Parser.decodeResult;
|
|
412
718
|
/**
|
|
413
719
|
* @category Decoding
|
|
414
720
|
* @since 4.0.0
|
|
415
721
|
*/
|
|
416
722
|
export const decodeUnknownPromise = Parser.decodeUnknownPromise;
|
|
417
723
|
/**
|
|
724
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
725
|
+
* returning a `Promise` that resolves with the decoded value or rejects with a
|
|
726
|
+
* {@link SchemaError}. For `unknown` input use {@link decodeUnknownPromise}.
|
|
727
|
+
*
|
|
418
728
|
* @category Decoding
|
|
419
729
|
* @since 4.0.0
|
|
420
730
|
*/
|
|
421
731
|
export const decodePromise = Parser.decodePromise;
|
|
422
732
|
/**
|
|
733
|
+
* Decodes an `unknown` input against a schema synchronously, throwing a
|
|
734
|
+
* {@link SchemaError} on failure. Use this when you want to validate data at a
|
|
735
|
+
* boundary and treat a schema mismatch as an unrecoverable error. For
|
|
736
|
+
* non-throwing alternatives see {@link decodeUnknownOption},
|
|
737
|
+
* {@link decodeUnknownExit}, or {@link decodeUnknownEffect}. For typed input
|
|
738
|
+
* use {@link decodeSync}.
|
|
739
|
+
*
|
|
740
|
+
* **Example** (Decoding with a transformation schema)
|
|
741
|
+
*
|
|
742
|
+
* ```ts
|
|
743
|
+
* import { Schema } from "effect"
|
|
744
|
+
*
|
|
745
|
+
* const NumberFromString = Schema.NumberFromString
|
|
746
|
+
*
|
|
747
|
+
* console.log(Schema.decodeUnknownSync(NumberFromString)("42"))
|
|
748
|
+
* // Output: 42
|
|
749
|
+
*
|
|
750
|
+
* Schema.decodeUnknownSync(NumberFromString)("not a number")
|
|
751
|
+
* // throws SchemaError: NumberFromString
|
|
752
|
+
* // └─ Encoded side transformation failure
|
|
753
|
+
* // └─ NumberFromString
|
|
754
|
+
* // └─ Expected a numeric string, actual "not a number"
|
|
755
|
+
* ```
|
|
756
|
+
*
|
|
423
757
|
* @category Decoding
|
|
424
758
|
* @since 4.0.0
|
|
425
759
|
*/
|
|
426
760
|
export const decodeUnknownSync = Parser.decodeUnknownSync;
|
|
427
761
|
/**
|
|
762
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
763
|
+
* synchronously, throwing a {@link SchemaError} on failure. For `unknown` input
|
|
764
|
+
* use {@link decodeUnknownSync}.
|
|
765
|
+
*
|
|
428
766
|
* @category Decoding
|
|
429
767
|
* @since 4.0.0
|
|
430
768
|
*/
|
|
431
769
|
export const decodeSync = Parser.decodeSync;
|
|
432
770
|
/**
|
|
771
|
+
* Encodes an `unknown` input against a schema, returning an `Effect` that
|
|
772
|
+
* succeeds with the encoded value or fails with a {@link SchemaError}. Use this
|
|
773
|
+
* when the input type is not statically known. Prefer {@link encodeEffect} when
|
|
774
|
+
* the input is already typed as the schema's `Type`.
|
|
775
|
+
*
|
|
776
|
+
* **Example** (Encoding a value to a string)
|
|
777
|
+
*
|
|
778
|
+
* ```ts
|
|
779
|
+
* import { Effect, Schema } from "effect"
|
|
780
|
+
*
|
|
781
|
+
* const NumberFromString = Schema.NumberFromString
|
|
782
|
+
*
|
|
783
|
+
* Effect.runPromise(Schema.encodeUnknownEffect(NumberFromString)(42)).then(console.log)
|
|
784
|
+
* // Output: "42"
|
|
785
|
+
* ```
|
|
786
|
+
*
|
|
433
787
|
* @category Encoding
|
|
434
788
|
* @since 4.0.0
|
|
435
789
|
*/
|
|
@@ -440,11 +794,22 @@ export function encodeUnknownEffect(schema) {
|
|
|
440
794
|
};
|
|
441
795
|
}
|
|
442
796
|
/**
|
|
797
|
+
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
798
|
+
* `Effect` that succeeds with the encoded value or fails with a
|
|
799
|
+
* {@link SchemaError}. Use this when the input is already typed; for `unknown`
|
|
800
|
+
* input use {@link encodeUnknownEffect}.
|
|
801
|
+
*
|
|
443
802
|
* @category Encoding
|
|
444
803
|
* @since 4.0.0
|
|
445
804
|
*/
|
|
446
805
|
export const encodeEffect = encodeUnknownEffect;
|
|
447
806
|
/**
|
|
807
|
+
* Encodes an `unknown` input against a schema synchronously, returning an
|
|
808
|
+
* `Exit` that is either a `Success` with the encoded value or a `Failure` with
|
|
809
|
+
* a {@link SchemaError}. Only usable with schemas that have no
|
|
810
|
+
* `EncodingServices` requirement. Prefer {@link encodeExit} when the input is
|
|
811
|
+
* already typed as the schema's `Type`.
|
|
812
|
+
*
|
|
448
813
|
* @category Encoding
|
|
449
814
|
* @since 4.0.0
|
|
450
815
|
*/
|
|
@@ -455,36 +820,82 @@ export function encodeUnknownExit(schema) {
|
|
|
455
820
|
};
|
|
456
821
|
}
|
|
457
822
|
/**
|
|
823
|
+
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
824
|
+
* returning an `Exit` that is either a `Success` with the encoded value or a
|
|
825
|
+
* `Failure` with a {@link SchemaError}. Only usable with schemas that have no
|
|
826
|
+
* `EncodingServices` requirement. For `unknown` input use
|
|
827
|
+
* {@link encodeUnknownExit}.
|
|
828
|
+
*
|
|
458
829
|
* @category Encoding
|
|
459
830
|
* @since 4.0.0
|
|
460
831
|
*/
|
|
461
832
|
export const encodeExit = encodeUnknownExit;
|
|
462
833
|
/**
|
|
834
|
+
* Encodes an `unknown` input against a schema, returning an `Option` that is
|
|
835
|
+
* `Some` with the encoded value on success or `None` on failure. Prefer this
|
|
836
|
+
* over {@link encodeUnknownExit} or {@link encodeUnknownEffect} when you only
|
|
837
|
+
* need to know whether encoding succeeded and don't need error details. For
|
|
838
|
+
* typed input use {@link encodeOption}.
|
|
839
|
+
*
|
|
463
840
|
* @category Encoding
|
|
464
841
|
* @since 4.0.0
|
|
465
842
|
*/
|
|
466
843
|
export const encodeUnknownOption = Parser.encodeUnknownOption;
|
|
467
844
|
/**
|
|
845
|
+
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
846
|
+
* `Option` that is `Some` with the encoded value on success or `None` on
|
|
847
|
+
* failure. For `unknown` input use {@link encodeUnknownOption}.
|
|
848
|
+
*
|
|
468
849
|
* @category Encoding
|
|
469
850
|
* @since 4.0.0
|
|
470
851
|
*/
|
|
471
852
|
export const encodeOption = Parser.encodeOption;
|
|
853
|
+
/**
|
|
854
|
+
* Encodes an `unknown` input against a schema, returning a `Promise` that
|
|
855
|
+
* resolves with the encoded value or rejects with a {@link SchemaError}. Useful
|
|
856
|
+
* for integrating with Promise-based APIs. For typed input use
|
|
857
|
+
* {@link encodePromise}.
|
|
858
|
+
*
|
|
859
|
+
* @category Encoding
|
|
860
|
+
* @since 4.0.0
|
|
861
|
+
*/
|
|
862
|
+
export const encodeUnknownResult = Parser.encodeUnknownResult;
|
|
863
|
+
/**
|
|
864
|
+
* @category Encoding
|
|
865
|
+
* @since 4.0.0
|
|
866
|
+
*/
|
|
867
|
+
export const encodeResult = Parser.encodeResult;
|
|
472
868
|
/**
|
|
473
869
|
* @category Encoding
|
|
474
870
|
* @since 4.0.0
|
|
475
871
|
*/
|
|
476
872
|
export const encodeUnknownPromise = Parser.encodeUnknownPromise;
|
|
477
873
|
/**
|
|
874
|
+
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
875
|
+
* `Promise` that resolves with the encoded value or rejects with a
|
|
876
|
+
* {@link SchemaError}. For `unknown` input use {@link encodeUnknownPromise}.
|
|
877
|
+
*
|
|
478
878
|
* @category Encoding
|
|
479
879
|
* @since 4.0.0
|
|
480
880
|
*/
|
|
481
881
|
export const encodePromise = Parser.encodePromise;
|
|
482
882
|
/**
|
|
883
|
+
* Encodes an `unknown` input against a schema synchronously, throwing a
|
|
884
|
+
* {@link SchemaError} on failure. Use this when you want to serialize data at a
|
|
885
|
+
* boundary and treat a schema mismatch as an unrecoverable error. For
|
|
886
|
+
* non-throwing alternatives see {@link encodeUnknownOption},
|
|
887
|
+
* {@link encodeUnknownExit}, or {@link encodeUnknownEffect}. For typed input
|
|
888
|
+
* use {@link encodeSync}.
|
|
889
|
+
*
|
|
483
890
|
* @category Encoding
|
|
484
891
|
* @since 4.0.0
|
|
485
892
|
*/
|
|
486
893
|
export const encodeUnknownSync = Parser.encodeUnknownSync;
|
|
487
894
|
/**
|
|
895
|
+
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
896
|
+
* throwing a {@link SchemaError} on failure. For `unknown` input use
|
|
897
|
+
* {@link encodeUnknownSync}.
|
|
898
|
+
*
|
|
488
899
|
* @category Encoding
|
|
489
900
|
* @since 4.0.0
|
|
490
901
|
*/
|
|
@@ -539,57 +950,74 @@ export const optionalKey = /*#__PURE__*/Struct_.lambda(schema => make(AST.option
|
|
|
539
950
|
schema
|
|
540
951
|
}));
|
|
541
952
|
/**
|
|
953
|
+
* Reverses {@link optionalKey}, returning the inner required schema. Only
|
|
954
|
+
* applicable to schemas already wrapped with `optionalKey`.
|
|
955
|
+
*
|
|
542
956
|
* @since 4.0.0
|
|
543
957
|
*/
|
|
544
958
|
export const requiredKey = /*#__PURE__*/Struct_.lambda(self => self.schema);
|
|
545
959
|
/**
|
|
546
|
-
*
|
|
960
|
+
* Marks a struct field as optional, allowing the key to be absent or
|
|
547
961
|
* `undefined`.
|
|
548
962
|
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
* - Can contain the specified schema type
|
|
963
|
+
* explicitly set to `undefined`. Equivalent to `optionalKey(UndefinedOr(S))`.
|
|
964
|
+
*
|
|
965
|
+
* Use {@link optionalKey} instead if you want exact optional semantics (absent
|
|
966
|
+
* only, not `undefined`).
|
|
554
967
|
*
|
|
555
|
-
* **Example** (
|
|
968
|
+
* **Example** (Optional field accepting undefined)
|
|
556
969
|
*
|
|
557
970
|
* ```ts
|
|
558
971
|
* import { Schema } from "effect"
|
|
559
972
|
*
|
|
560
973
|
* const schema = Schema.Struct({
|
|
561
974
|
* name: Schema.String,
|
|
562
|
-
* age: Schema.
|
|
975
|
+
* age: Schema.optional(Schema.Number)
|
|
563
976
|
* })
|
|
564
977
|
*
|
|
565
|
-
* //
|
|
566
|
-
* type Person = typeof schema
|
|
978
|
+
* // { readonly name: string; readonly age?: number | undefined }
|
|
979
|
+
* type Person = typeof schema.Type
|
|
567
980
|
* ```
|
|
568
981
|
*
|
|
569
982
|
* @since 4.0.0
|
|
570
983
|
*/
|
|
571
984
|
export const optional = /*#__PURE__*/Struct_.lambda(self => optionalKey(UndefinedOr(self)));
|
|
572
985
|
/**
|
|
986
|
+
* Reverses {@link optional}, returning the inner schema (unwrapping `UndefinedOr`).
|
|
987
|
+
* Only applicable to schemas already wrapped with `optional`.
|
|
988
|
+
*
|
|
573
989
|
* @since 4.0.0
|
|
574
990
|
*/
|
|
575
991
|
export const required = /*#__PURE__*/Struct_.lambda(self => self.schema.members[0]);
|
|
576
992
|
/**
|
|
993
|
+
* Makes a struct field mutable (removes the `readonly` modifier on the property).
|
|
994
|
+
* Use {@link readonlyKey} to reverse.
|
|
995
|
+
*
|
|
577
996
|
* @since 4.0.0
|
|
578
997
|
*/
|
|
579
998
|
export const mutableKey = /*#__PURE__*/Struct_.lambda(schema => make(AST.mutableKey(schema.ast), {
|
|
580
999
|
schema
|
|
581
1000
|
}));
|
|
582
1001
|
/**
|
|
1002
|
+
* Reverses {@link mutableKey}, returning the inner schema as readonly again.
|
|
1003
|
+
* Only applicable to schemas already wrapped with `mutableKey`.
|
|
1004
|
+
*
|
|
583
1005
|
* @since 4.0.0
|
|
584
1006
|
*/
|
|
585
1007
|
export const readonlyKey = /*#__PURE__*/Struct_.lambda(self => self.schema);
|
|
586
1008
|
/**
|
|
1009
|
+
* Extracts the type-side schema: sets `Encoded` to equal the decoded `Type`,
|
|
1010
|
+
* discarding the encoding transformation path.
|
|
1011
|
+
*
|
|
587
1012
|
* @since 4.0.0
|
|
588
1013
|
*/
|
|
589
1014
|
export const toType = /*#__PURE__*/Struct_.lambda(schema => make(AST.toType(schema.ast), {
|
|
590
1015
|
schema
|
|
591
1016
|
}));
|
|
592
1017
|
/**
|
|
1018
|
+
* Extracts the encoded-side schema: sets `Type` to equal the `Encoded`,
|
|
1019
|
+
* discarding the decoding transformation path.
|
|
1020
|
+
*
|
|
593
1021
|
* @since 4.0.0
|
|
594
1022
|
*/
|
|
595
1023
|
export const toEncoded = /*#__PURE__*/Struct_.lambda(schema => make(AST.toEncoded(schema.ast), {
|
|
@@ -609,6 +1037,16 @@ export function flip(schema) {
|
|
|
609
1037
|
});
|
|
610
1038
|
}
|
|
611
1039
|
/**
|
|
1040
|
+
* Creates a schema for a single literal value (string, number, bigint, boolean, or null).
|
|
1041
|
+
*
|
|
1042
|
+
* **Example** (String literal)
|
|
1043
|
+
* ```ts
|
|
1044
|
+
* import { Schema } from "effect"
|
|
1045
|
+
*
|
|
1046
|
+
* const schema = Schema.Literal("hello")
|
|
1047
|
+
* // Type: Schema.Literal<"hello">
|
|
1048
|
+
* ```
|
|
1049
|
+
*
|
|
612
1050
|
* @see {@link Literals} for a schema that represents a union of literals.
|
|
613
1051
|
* @see {@link tag} for a schema that represents a literal value that can be
|
|
614
1052
|
* used as a discriminator field in tagged unions and has a constructor default.
|
|
@@ -630,6 +1068,18 @@ function templateLiteralFromParts(parts) {
|
|
|
630
1068
|
return new AST.TemplateLiteral(parts.map(part => isSchema(part) ? part.ast : new AST.Literal(part)));
|
|
631
1069
|
}
|
|
632
1070
|
/**
|
|
1071
|
+
* Creates a schema that validates strings matching a template literal pattern. Each part can be
|
|
1072
|
+
* a literal string/number/bigint or a schema whose encoded type is a string, number, or bigint.
|
|
1073
|
+
*
|
|
1074
|
+
* **Example** (URL path pattern)
|
|
1075
|
+
* ```ts
|
|
1076
|
+
* import { Schema } from "effect"
|
|
1077
|
+
*
|
|
1078
|
+
* const schema = Schema.TemplateLiteral(["/user/", Schema.Number])
|
|
1079
|
+
* // matches strings like "/user/123", "/user/42", etc.
|
|
1080
|
+
* ```
|
|
1081
|
+
*
|
|
1082
|
+
* @see {@link TemplateLiteralParser} for a schema that also parses matched parts into a tuple.
|
|
633
1083
|
* @since 4.0.0
|
|
634
1084
|
*/
|
|
635
1085
|
export function TemplateLiteral(parts) {
|
|
@@ -638,6 +1088,18 @@ export function TemplateLiteral(parts) {
|
|
|
638
1088
|
});
|
|
639
1089
|
}
|
|
640
1090
|
/**
|
|
1091
|
+
* Like {@link TemplateLiteral} but decodes the matched string into a readonly tuple of typed values,
|
|
1092
|
+
* one element per schema part.
|
|
1093
|
+
*
|
|
1094
|
+
* **Example** (Parse path parameters)
|
|
1095
|
+
* ```ts
|
|
1096
|
+
* import { Schema } from "effect"
|
|
1097
|
+
*
|
|
1098
|
+
* const schema = Schema.TemplateLiteralParser(["/user/", Schema.NumberFromString])
|
|
1099
|
+
* // decodes "/user/42" => readonly ["/user/", 42]
|
|
1100
|
+
* ```
|
|
1101
|
+
*
|
|
1102
|
+
* @see {@link TemplateLiteral} for a validation-only version that keeps the string encoded.
|
|
641
1103
|
* @since 4.0.0
|
|
642
1104
|
*/
|
|
643
1105
|
export function TemplateLiteralParser(parts) {
|
|
@@ -646,6 +1108,21 @@ export function TemplateLiteralParser(parts) {
|
|
|
646
1108
|
});
|
|
647
1109
|
}
|
|
648
1110
|
/**
|
|
1111
|
+
* Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
|
|
1112
|
+
*
|
|
1113
|
+
* **Example** (Direction enum)
|
|
1114
|
+
* ```ts
|
|
1115
|
+
* import { Schema } from "effect"
|
|
1116
|
+
*
|
|
1117
|
+
* enum Direction {
|
|
1118
|
+
* Up = "Up",
|
|
1119
|
+
* Down = "Down"
|
|
1120
|
+
* }
|
|
1121
|
+
*
|
|
1122
|
+
* const schema = Schema.Enum(Direction)
|
|
1123
|
+
* // accepts "Up" or "Down"
|
|
1124
|
+
* ```
|
|
1125
|
+
*
|
|
649
1126
|
* @since 4.0.0
|
|
650
1127
|
*/
|
|
651
1128
|
export function Enum(enums) {
|
|
@@ -654,84 +1131,102 @@ export function Enum(enums) {
|
|
|
654
1131
|
});
|
|
655
1132
|
}
|
|
656
1133
|
/**
|
|
1134
|
+
* Schema for the `never` type. Always fails validation — no value satisfies it.
|
|
1135
|
+
*
|
|
657
1136
|
* @since 4.0.0
|
|
658
1137
|
*/
|
|
659
1138
|
export const Never = /*#__PURE__*/make(AST.never);
|
|
660
1139
|
/**
|
|
1140
|
+
* Schema for the `any` type. Accepts any value without validation.
|
|
1141
|
+
*
|
|
1142
|
+
* @see {@link Unknown} for a safer alternative that uses `unknown`.
|
|
661
1143
|
* @since 4.0.0
|
|
662
1144
|
*/
|
|
663
1145
|
export const Any = /*#__PURE__*/make(AST.any);
|
|
664
1146
|
/**
|
|
1147
|
+
* Schema for the `unknown` type. Accepts any value without validation.
|
|
1148
|
+
*
|
|
1149
|
+
* @see {@link Any} for the `any` variant.
|
|
665
1150
|
* @since 4.0.0
|
|
666
1151
|
*/
|
|
667
1152
|
export const Unknown = /*#__PURE__*/make(AST.unknown);
|
|
668
1153
|
/**
|
|
1154
|
+
* Schema for the `null` literal. Validates that the input is strictly `null`.
|
|
1155
|
+
*
|
|
1156
|
+
* @see {@link NullOr} for a union with another schema.
|
|
669
1157
|
* @since 4.0.0
|
|
670
1158
|
*/
|
|
671
1159
|
export const Null = /*#__PURE__*/make(AST.null);
|
|
672
1160
|
/**
|
|
1161
|
+
* Schema for the `undefined` literal. Validates that the input is strictly `undefined`.
|
|
1162
|
+
*
|
|
1163
|
+
* @see {@link UndefinedOr} for a union with another schema.
|
|
673
1164
|
* @since 4.0.0
|
|
674
1165
|
*/
|
|
675
1166
|
export const Undefined = /*#__PURE__*/make(AST.undefined);
|
|
676
1167
|
/**
|
|
677
|
-
*
|
|
1168
|
+
* Schema for `string` values. Validates that the input is `typeof` `"string"`.
|
|
678
1169
|
*
|
|
679
1170
|
* @since 4.0.0
|
|
680
1171
|
*/
|
|
681
1172
|
export const String = /*#__PURE__*/make(AST.string);
|
|
682
1173
|
/**
|
|
683
|
-
*
|
|
1174
|
+
* Schema for `number` values, including `NaN`, `Infinity`, and `-Infinity`.
|
|
684
1175
|
*
|
|
685
1176
|
* **Default Json Serializer**
|
|
686
1177
|
*
|
|
687
|
-
* -
|
|
688
|
-
* -
|
|
1178
|
+
* - Finite numbers are serialized as numbers.
|
|
1179
|
+
* - Non-finite values are serialized as strings (`"NaN"`, `"Infinity"`, `"-Infinity"`).
|
|
689
1180
|
*
|
|
1181
|
+
* @see {@link Finite} for a schema that excludes non-finite values.
|
|
690
1182
|
* @since 4.0.0
|
|
691
1183
|
*/
|
|
692
1184
|
export const Number = /*#__PURE__*/make(AST.number);
|
|
693
1185
|
/**
|
|
694
|
-
*
|
|
1186
|
+
* Schema for `boolean` values. Validates that the input is `typeof` `"boolean"`.
|
|
695
1187
|
*
|
|
696
1188
|
* @category Boolean
|
|
697
1189
|
* @since 4.0.0
|
|
698
1190
|
*/
|
|
699
1191
|
export const Boolean = /*#__PURE__*/make(AST.boolean);
|
|
700
1192
|
/**
|
|
701
|
-
*
|
|
1193
|
+
* Schema for `symbol` values. Validates that the input is `typeof` `"symbol"`.
|
|
702
1194
|
*
|
|
1195
|
+
* @see {@link UniqueSymbol} for a schema that matches a specific symbol.
|
|
703
1196
|
* @since 4.0.0
|
|
704
1197
|
*/
|
|
705
1198
|
export const Symbol = /*#__PURE__*/make(AST.symbol);
|
|
706
1199
|
/**
|
|
707
|
-
*
|
|
1200
|
+
* Schema for `bigint` values. Validates that the input is `typeof` `"bigint"`.
|
|
708
1201
|
*
|
|
709
1202
|
* @since 4.0.0
|
|
710
1203
|
*/
|
|
711
1204
|
export const BigInt = /*#__PURE__*/make(AST.bigInt);
|
|
712
1205
|
/**
|
|
713
|
-
*
|
|
1206
|
+
* Schema for the `void` type. Accepts `undefined` as the encoded value.
|
|
714
1207
|
*
|
|
715
1208
|
* @since 4.0.0
|
|
716
1209
|
*/
|
|
717
1210
|
export const Void = /*#__PURE__*/make(AST.void);
|
|
718
1211
|
/**
|
|
719
|
-
*
|
|
1212
|
+
* Schema for the `object` type. Validates that the input is a non-null object or function
|
|
1213
|
+
* (i.e. `typeof value === "object" && value !== null || typeof value === "function"`).
|
|
720
1214
|
*
|
|
721
1215
|
* @since 4.0.0
|
|
722
1216
|
*/
|
|
723
1217
|
export const ObjectKeyword = /*#__PURE__*/make(AST.objectKeyword);
|
|
724
1218
|
/**
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
|
-
* **Example**
|
|
1219
|
+
* Creates a schema for a specific symbol. Only that exact symbol satisfies the schema.
|
|
728
1220
|
*
|
|
1221
|
+
* **Example** (Specific symbol)
|
|
729
1222
|
* ```ts
|
|
730
1223
|
* import { Schema } from "effect"
|
|
731
1224
|
*
|
|
732
|
-
* const
|
|
733
|
-
* const schema = Schema.UniqueSymbol(
|
|
1225
|
+
* const mySymbol = Symbol.for("mySymbol")
|
|
1226
|
+
* const schema = Schema.UniqueSymbol(mySymbol)
|
|
734
1227
|
* ```
|
|
1228
|
+
*
|
|
1229
|
+
* @see {@link Symbol} for a schema that accepts any symbol.
|
|
735
1230
|
* @since 4.0.0
|
|
736
1231
|
*/
|
|
737
1232
|
export function UniqueSymbol(symbol) {
|
|
@@ -747,6 +1242,34 @@ function makeStruct(ast, fields) {
|
|
|
747
1242
|
});
|
|
748
1243
|
}
|
|
749
1244
|
/**
|
|
1245
|
+
* Defines a struct schema from a map of field schemas.
|
|
1246
|
+
*
|
|
1247
|
+
* Each field value is a schema. Use {@link optionalKey} or {@link optional} to
|
|
1248
|
+
* mark fields as optional, and {@link mutableKey} to mark them as mutable.
|
|
1249
|
+
*
|
|
1250
|
+
* The resulting schema's `Type` is a readonly object type with the fields'
|
|
1251
|
+
* decoded types. The `Encoded` form mirrors the field schemas' encoded types.
|
|
1252
|
+
*
|
|
1253
|
+
* **Example** (Basic struct)
|
|
1254
|
+
*
|
|
1255
|
+
* ```ts
|
|
1256
|
+
* import { Schema } from "effect"
|
|
1257
|
+
*
|
|
1258
|
+
* const Person = Schema.Struct({
|
|
1259
|
+
* name: Schema.String,
|
|
1260
|
+
* age: Schema.Number,
|
|
1261
|
+
* email: Schema.optionalKey(Schema.String)
|
|
1262
|
+
* })
|
|
1263
|
+
*
|
|
1264
|
+
* // { readonly name: string; readonly age: number; readonly email?: string }
|
|
1265
|
+
* type Person = typeof Person.Type
|
|
1266
|
+
*
|
|
1267
|
+
* const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
|
|
1268
|
+
* console.log(alice)
|
|
1269
|
+
* // { name: 'Alice', age: 30 }
|
|
1270
|
+
* ```
|
|
1271
|
+
*
|
|
1272
|
+
* @category Constructors
|
|
750
1273
|
* @since 4.0.0
|
|
751
1274
|
*/
|
|
752
1275
|
export function Struct(fields) {
|
|
@@ -774,6 +1297,26 @@ export function fieldsAssign(fields) {
|
|
|
774
1297
|
return Struct_.lambda(struct => struct.mapFields(Struct_.assign(fields)));
|
|
775
1298
|
}
|
|
776
1299
|
/**
|
|
1300
|
+
* Renames struct keys in the encoded form without changing the decoded type.
|
|
1301
|
+
*
|
|
1302
|
+
* Takes a partial mapping `{ decodedKey: encodedKey }` and produces a
|
|
1303
|
+
* transformation schema that decodes from the renamed keys and encodes back to
|
|
1304
|
+
* the renamed keys. Keys not present in the mapping are left unchanged.
|
|
1305
|
+
*
|
|
1306
|
+
* **Example** (Rename `name` to `full_name` in the encoded form)
|
|
1307
|
+
*
|
|
1308
|
+
* ```ts
|
|
1309
|
+
* import { Schema } from "effect"
|
|
1310
|
+
*
|
|
1311
|
+
* const Person = Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
1312
|
+
* const Encoded = Person.pipe(Schema.encodeKeys({ name: "full_name" }))
|
|
1313
|
+
*
|
|
1314
|
+
* // Decodes { full_name: "Alice", age: 30 } → { name: "Alice", age: 30 }
|
|
1315
|
+
* const alice = Schema.decodeUnknownSync(Encoded)({ full_name: "Alice", age: 30 })
|
|
1316
|
+
* console.log(alice)
|
|
1317
|
+
* // { name: 'Alice', age: 30 }
|
|
1318
|
+
* ```
|
|
1319
|
+
*
|
|
777
1320
|
* @category Struct transformations
|
|
778
1321
|
* @since 4.0.0
|
|
779
1322
|
*/
|
|
@@ -782,11 +1325,12 @@ export function encodeKeys(mapping) {
|
|
|
782
1325
|
const fields = {};
|
|
783
1326
|
const reverseMapping = {};
|
|
784
1327
|
for (const k in self.fields) {
|
|
1328
|
+
const encoded = toEncoded(self.fields[k]);
|
|
785
1329
|
if (Object.hasOwn(mapping, k)) {
|
|
786
|
-
fields[mapping[k]] =
|
|
1330
|
+
fields[mapping[k]] = encoded;
|
|
787
1331
|
reverseMapping[mapping[k]] = k;
|
|
788
1332
|
} else {
|
|
789
|
-
fields[k] =
|
|
1333
|
+
fields[k] = encoded;
|
|
790
1334
|
}
|
|
791
1335
|
}
|
|
792
1336
|
return Struct(fields).pipe(decodeTo(self, Transformation.transform({
|
|
@@ -796,6 +1340,31 @@ export function encodeKeys(mapping) {
|
|
|
796
1340
|
};
|
|
797
1341
|
}
|
|
798
1342
|
/**
|
|
1343
|
+
* Adds derived fields to a struct schema during decoding.
|
|
1344
|
+
*
|
|
1345
|
+
* Each new field is derived from the decoded struct value via a function that
|
|
1346
|
+
* returns `Option`. On encoding the derived fields are stripped. This allows
|
|
1347
|
+
* computed or enriched fields to live in the decoded type without appearing in
|
|
1348
|
+
* the encoded form.
|
|
1349
|
+
*
|
|
1350
|
+
* **Example** (Add a computed `fullName` field)
|
|
1351
|
+
*
|
|
1352
|
+
* ```ts
|
|
1353
|
+
* import { Option, Schema } from "effect"
|
|
1354
|
+
*
|
|
1355
|
+
* const Person = Schema.Struct({ first: Schema.String, last: Schema.String })
|
|
1356
|
+
* const Extended = Person.pipe(
|
|
1357
|
+
* Schema.extendTo(
|
|
1358
|
+
* { fullName: Schema.String },
|
|
1359
|
+
* { fullName: (p) => Option.some(`${p.first} ${p.last}`) }
|
|
1360
|
+
* )
|
|
1361
|
+
* )
|
|
1362
|
+
*
|
|
1363
|
+
* const alice = Schema.decodeUnknownSync(Extended)({ first: "Alice", last: "Smith" })
|
|
1364
|
+
* console.log(alice.fullName)
|
|
1365
|
+
* // Alice Smith
|
|
1366
|
+
* ```
|
|
1367
|
+
*
|
|
799
1368
|
* @since 4.0.0
|
|
800
1369
|
* @experimental
|
|
801
1370
|
*/
|
|
@@ -835,6 +1404,24 @@ derive) {
|
|
|
835
1404
|
};
|
|
836
1405
|
}
|
|
837
1406
|
/**
|
|
1407
|
+
* Defines a record (dictionary) schema with typed keys and values.
|
|
1408
|
+
*
|
|
1409
|
+
* **Example** (String-keyed record of numbers)
|
|
1410
|
+
*
|
|
1411
|
+
* ```ts
|
|
1412
|
+
* import { Schema } from "effect"
|
|
1413
|
+
*
|
|
1414
|
+
* const schema = Schema.Record(Schema.String, Schema.Number)
|
|
1415
|
+
*
|
|
1416
|
+
* // { readonly [x: string]: number }
|
|
1417
|
+
* type R = typeof schema.Type
|
|
1418
|
+
*
|
|
1419
|
+
* const result = Schema.decodeUnknownSync(schema)({ a: 1, b: 2 })
|
|
1420
|
+
* console.log(result)
|
|
1421
|
+
* // { a: 1, b: 2 }
|
|
1422
|
+
* ```
|
|
1423
|
+
*
|
|
1424
|
+
* @category Constructors
|
|
838
1425
|
* @since 4.0.0
|
|
839
1426
|
*/
|
|
840
1427
|
export function Record(key, value, options) {
|
|
@@ -845,6 +1432,24 @@ export function Record(key, value, options) {
|
|
|
845
1432
|
});
|
|
846
1433
|
}
|
|
847
1434
|
/**
|
|
1435
|
+
* Extends a struct schema with one or more record (index-signature) schemas,
|
|
1436
|
+
* producing a schema whose decoded type intersects the struct and all records.
|
|
1437
|
+
*
|
|
1438
|
+
* **Example** (Struct with string-indexed extra keys)
|
|
1439
|
+
*
|
|
1440
|
+
* ```ts
|
|
1441
|
+
* import { Schema } from "effect"
|
|
1442
|
+
*
|
|
1443
|
+
* const schema = Schema.StructWithRest(
|
|
1444
|
+
* Schema.Struct({ id: Schema.Number }),
|
|
1445
|
+
* [Schema.Record(Schema.String, Schema.String)]
|
|
1446
|
+
* )
|
|
1447
|
+
*
|
|
1448
|
+
* // { readonly id: number } & { readonly [x: string]: string }
|
|
1449
|
+
* type T = typeof schema.Type
|
|
1450
|
+
* ```
|
|
1451
|
+
*
|
|
1452
|
+
* @category Constructors
|
|
848
1453
|
* @since 4.0.0
|
|
849
1454
|
*/
|
|
850
1455
|
export function StructWithRest(schema, records) {
|
|
@@ -863,6 +1468,20 @@ function makeTuple(ast, elements) {
|
|
|
863
1468
|
});
|
|
864
1469
|
}
|
|
865
1470
|
/**
|
|
1471
|
+
* Defines a fixed-length tuple schema from an array of element schemas.
|
|
1472
|
+
*
|
|
1473
|
+
* **Example** (Pair of string and number)
|
|
1474
|
+
*
|
|
1475
|
+
* ```ts
|
|
1476
|
+
* import { Schema } from "effect"
|
|
1477
|
+
*
|
|
1478
|
+
* const schema = Schema.Tuple([Schema.String, Schema.Number])
|
|
1479
|
+
*
|
|
1480
|
+
* const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
|
|
1481
|
+
* console.log(pair)
|
|
1482
|
+
* // [ 'hello', 42 ]
|
|
1483
|
+
* ```
|
|
1484
|
+
*
|
|
866
1485
|
* @category Constructors
|
|
867
1486
|
* @since 4.0.0
|
|
868
1487
|
*/
|
|
@@ -870,6 +1489,26 @@ export function Tuple(elements) {
|
|
|
870
1489
|
return makeTuple(AST.tuple(elements), elements);
|
|
871
1490
|
}
|
|
872
1491
|
/**
|
|
1492
|
+
* Extends a fixed-length tuple schema with rest elements, creating a variadic
|
|
1493
|
+
* tuple that starts with the fixed elements and ends with zero or more rest
|
|
1494
|
+
* elements.
|
|
1495
|
+
*
|
|
1496
|
+
* **Example** (Tuple with rest)
|
|
1497
|
+
*
|
|
1498
|
+
* ```ts
|
|
1499
|
+
* import { Schema } from "effect"
|
|
1500
|
+
*
|
|
1501
|
+
* // [string, number, ...boolean[]]
|
|
1502
|
+
* const schema = Schema.TupleWithRest(
|
|
1503
|
+
* Schema.Tuple([Schema.String, Schema.Number]),
|
|
1504
|
+
* [Schema.Boolean]
|
|
1505
|
+
* )
|
|
1506
|
+
*
|
|
1507
|
+
* const result = Schema.decodeUnknownSync(schema)(["hello", 1, true, false])
|
|
1508
|
+
* console.log(result)
|
|
1509
|
+
* // [ 'hello', 1, true, false ]
|
|
1510
|
+
* ```
|
|
1511
|
+
*
|
|
873
1512
|
* @category Constructors
|
|
874
1513
|
* @since 4.0.0
|
|
875
1514
|
*/
|
|
@@ -883,16 +1522,70 @@ export function TupleWithRest(schema, rest) {
|
|
|
883
1522
|
* @category Constructors
|
|
884
1523
|
* @since 4.0.0
|
|
885
1524
|
*/
|
|
886
|
-
|
|
1525
|
+
const ArraySchema = /*#__PURE__*/Struct_.lambda(schema => make(new AST.Arrays(false, [], [schema.ast]), {
|
|
887
1526
|
schema
|
|
888
1527
|
}));
|
|
1528
|
+
export {
|
|
889
1529
|
/**
|
|
1530
|
+
* Defines a `ReadonlyArray` schema for a given element schema.
|
|
1531
|
+
*
|
|
1532
|
+
* **Example** (Array of strings)
|
|
1533
|
+
*
|
|
1534
|
+
* ```ts
|
|
1535
|
+
* import { Schema } from "effect"
|
|
1536
|
+
*
|
|
1537
|
+
* const schema = Schema.Array(Schema.String)
|
|
1538
|
+
*
|
|
1539
|
+
* const result = Schema.decodeUnknownSync(schema)(["a", "b", "c"])
|
|
1540
|
+
* console.log(result)
|
|
1541
|
+
* // [ 'a', 'b', 'c' ]
|
|
1542
|
+
* ```
|
|
1543
|
+
*
|
|
1544
|
+
* @category Constructors
|
|
1545
|
+
* @since 4.0.0
|
|
1546
|
+
*/
|
|
1547
|
+
ArraySchema as Array };
|
|
1548
|
+
/**
|
|
1549
|
+
* Defines a non-empty `ReadonlyArray` schema — at least one element required.
|
|
1550
|
+
* Type is `readonly [T, ...T[]]`.
|
|
1551
|
+
*
|
|
1552
|
+
* **Example** (Non-empty array of numbers)
|
|
1553
|
+
*
|
|
1554
|
+
* ```ts
|
|
1555
|
+
* import { Schema } from "effect"
|
|
1556
|
+
*
|
|
1557
|
+
* const schema = Schema.NonEmptyArray(Schema.Number)
|
|
1558
|
+
*
|
|
1559
|
+
* Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
|
|
1560
|
+
* Schema.decodeUnknownSync(schema)([]) // throws
|
|
1561
|
+
* ```
|
|
1562
|
+
*
|
|
890
1563
|
* @category Constructors
|
|
891
1564
|
* @since 4.0.0
|
|
892
1565
|
*/
|
|
893
1566
|
export const NonEmptyArray = /*#__PURE__*/Struct_.lambda(schema => make(new AST.Arrays(false, [schema.ast], [schema.ast]), {
|
|
894
1567
|
schema
|
|
895
1568
|
}));
|
|
1569
|
+
/**
|
|
1570
|
+
* Decodes a single value or an array of values into an array.
|
|
1571
|
+
*
|
|
1572
|
+
* Decoding:
|
|
1573
|
+
* - a single value is decoded as a one-element array
|
|
1574
|
+
* - an array is decoded as-is
|
|
1575
|
+
*
|
|
1576
|
+
* Encoding:
|
|
1577
|
+
* - a one-element array is encoded as a single value
|
|
1578
|
+
* - arrays with more than one element are encoded as arrays
|
|
1579
|
+
*
|
|
1580
|
+
* @category Arrays
|
|
1581
|
+
* @since 4.0.0
|
|
1582
|
+
*/
|
|
1583
|
+
export function ArrayEnsure(schema) {
|
|
1584
|
+
return Union([schema, ArraySchema(schema)]).pipe(decodeTo(ArraySchema(toType(schema)), Transformation.transform({
|
|
1585
|
+
decode: Arr.ensure,
|
|
1586
|
+
encode: array => array.length === 1 ? array[0] : array
|
|
1587
|
+
})));
|
|
1588
|
+
}
|
|
896
1589
|
/**
|
|
897
1590
|
* Returns a new array schema that ensures all elements are unique.
|
|
898
1591
|
*
|
|
@@ -903,10 +1596,21 @@ export const NonEmptyArray = /*#__PURE__*/Struct_.lambda(schema => make(new AST.
|
|
|
903
1596
|
* @since 4.0.0
|
|
904
1597
|
*/
|
|
905
1598
|
export function UniqueArray(item) {
|
|
906
|
-
return
|
|
1599
|
+
return ArraySchema(item).check(isUnique());
|
|
907
1600
|
}
|
|
908
1601
|
/**
|
|
909
|
-
* Makes
|
|
1602
|
+
* Makes an array or tuple schema mutable, removing the `readonly` modifier.
|
|
1603
|
+
*
|
|
1604
|
+
* **Example** (Mutable array)
|
|
1605
|
+
*
|
|
1606
|
+
* ```ts
|
|
1607
|
+
* import { Schema } from "effect"
|
|
1608
|
+
*
|
|
1609
|
+
* const schema = Schema.mutable(Schema.Array(Schema.Number))
|
|
1610
|
+
*
|
|
1611
|
+
* // number[] (mutable)
|
|
1612
|
+
* type T = typeof schema.Type
|
|
1613
|
+
* ```
|
|
910
1614
|
*
|
|
911
1615
|
* @since 4.0.0
|
|
912
1616
|
*/
|
|
@@ -925,12 +1629,23 @@ function makeUnion(ast, members) {
|
|
|
925
1629
|
});
|
|
926
1630
|
}
|
|
927
1631
|
/**
|
|
928
|
-
* Creates a schema
|
|
1632
|
+
* Creates a union schema from an array of member schemas. Members are tested in
|
|
1633
|
+
* order; the first match is returned.
|
|
929
1634
|
*
|
|
930
|
-
* Optionally,
|
|
1635
|
+
* Optionally, specify `mode`:
|
|
1636
|
+
* - `"anyOf"` (default) — matches if any member matches.
|
|
1637
|
+
* - `"oneOf"` — matches if exactly one member matches.
|
|
931
1638
|
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
1639
|
+
* **Example** (String or number union)
|
|
1640
|
+
*
|
|
1641
|
+
* ```ts
|
|
1642
|
+
* import { Schema } from "effect"
|
|
1643
|
+
*
|
|
1644
|
+
* const schema = Schema.Union([Schema.String, Schema.Number])
|
|
1645
|
+
*
|
|
1646
|
+
* Schema.decodeUnknownSync(schema)("hello") // "hello"
|
|
1647
|
+
* Schema.decodeUnknownSync(schema)(42) // 42
|
|
1648
|
+
* ```
|
|
934
1649
|
*
|
|
935
1650
|
* @category Constructors
|
|
936
1651
|
* @since 4.0.0
|
|
@@ -939,6 +1654,16 @@ export function Union(members, options) {
|
|
|
939
1654
|
return makeUnion(AST.union(members, options?.mode ?? "anyOf", undefined), members);
|
|
940
1655
|
}
|
|
941
1656
|
/**
|
|
1657
|
+
* Creates a union schema from an array of literal values.
|
|
1658
|
+
*
|
|
1659
|
+
* **Example** (Status codes)
|
|
1660
|
+
* ```ts
|
|
1661
|
+
* import { Schema } from "effect"
|
|
1662
|
+
*
|
|
1663
|
+
* const schema = Schema.Literals(["active", "inactive", "pending"])
|
|
1664
|
+
* // accepts "active", "inactive", or "pending"
|
|
1665
|
+
* ```
|
|
1666
|
+
*
|
|
942
1667
|
* @see {@link Literal} for a schema that represents a single literal.
|
|
943
1668
|
* @category Constructors
|
|
944
1669
|
* @since 4.0.0
|
|
@@ -960,16 +1685,21 @@ export function Literals(literals) {
|
|
|
960
1685
|
});
|
|
961
1686
|
}
|
|
962
1687
|
/**
|
|
1688
|
+
* Creates a union schema of `S | null`.
|
|
1689
|
+
*
|
|
963
1690
|
* @category Constructors
|
|
964
1691
|
* @since 4.0.0
|
|
965
1692
|
*/
|
|
966
1693
|
export const NullOr = /*#__PURE__*/Struct_.lambda(self => Union([self, Null]));
|
|
967
1694
|
/**
|
|
1695
|
+
* Creates a union schema of `S | undefined`.
|
|
1696
|
+
*
|
|
968
1697
|
* @category Constructors
|
|
969
1698
|
* @since 4.0.0
|
|
970
1699
|
*/
|
|
971
1700
|
export const UndefinedOr = /*#__PURE__*/Struct_.lambda(self => Union([self, Undefined]));
|
|
972
1701
|
/**
|
|
1702
|
+
* Creates a union schema of `S | null | undefined`.
|
|
973
1703
|
* @category Constructors
|
|
974
1704
|
* @since 4.0.0
|
|
975
1705
|
*/
|
|
@@ -979,6 +1709,21 @@ export const NullishOr = /*#__PURE__*/Struct_.lambda(self => Union([self, Null,
|
|
|
979
1709
|
* essential for creating recursive schemas where a schema references itself,
|
|
980
1710
|
* preventing infinite recursion during schema definition.
|
|
981
1711
|
*
|
|
1712
|
+
* **Example** (Recursive tree schema)
|
|
1713
|
+
* ```ts
|
|
1714
|
+
* import { Schema } from "effect"
|
|
1715
|
+
*
|
|
1716
|
+
* interface Tree {
|
|
1717
|
+
* readonly value: number
|
|
1718
|
+
* readonly children: ReadonlyArray<Tree>
|
|
1719
|
+
* }
|
|
1720
|
+
*
|
|
1721
|
+
* const Tree = Schema.Struct({
|
|
1722
|
+
* value: Schema.Number,
|
|
1723
|
+
* children: Schema.Array(Schema.suspend((): Schema.Codec<Tree> => Tree))
|
|
1724
|
+
* })
|
|
1725
|
+
* ```
|
|
1726
|
+
*
|
|
982
1727
|
* @category Constructors
|
|
983
1728
|
* @since 4.0.0
|
|
984
1729
|
*/
|
|
@@ -986,6 +1731,18 @@ export function suspend(f) {
|
|
|
986
1731
|
return make(new AST.Suspend(() => f().ast));
|
|
987
1732
|
}
|
|
988
1733
|
/**
|
|
1734
|
+
* Pipeable function that attaches one or more filter checks to a schema without
|
|
1735
|
+
* changing the TypeScript type.
|
|
1736
|
+
*
|
|
1737
|
+
* **Example** (Adding checks to a schema)
|
|
1738
|
+
* ```ts
|
|
1739
|
+
* import { Schema } from "effect"
|
|
1740
|
+
*
|
|
1741
|
+
* const AgeSchema = Schema.Number.pipe(
|
|
1742
|
+
* Schema.check(Schema.isGreaterThanOrEqualTo(0), Schema.isLessThanOrEqualTo(120))
|
|
1743
|
+
* )
|
|
1744
|
+
* ```
|
|
1745
|
+
*
|
|
989
1746
|
* @category Filtering
|
|
990
1747
|
* @since 4.0.0
|
|
991
1748
|
*/
|
|
@@ -993,6 +1750,9 @@ export function check(...checks) {
|
|
|
993
1750
|
return self => self.check(...checks);
|
|
994
1751
|
}
|
|
995
1752
|
/**
|
|
1753
|
+
* Narrows the TypeScript type of a schema's output via a type guard predicate,
|
|
1754
|
+
* attaching the guard as a runtime filter check.
|
|
1755
|
+
*
|
|
996
1756
|
* @category Filtering
|
|
997
1757
|
* @since 4.0.0
|
|
998
1758
|
*/
|
|
@@ -1002,7 +1762,8 @@ export function refine(refinement, annotations) {
|
|
|
1002
1762
|
});
|
|
1003
1763
|
}
|
|
1004
1764
|
/**
|
|
1005
|
-
* Adds a brand to a schema
|
|
1765
|
+
* Adds a nominal brand to a schema, intersecting the output type with
|
|
1766
|
+
* `Brand.Brand<B>` to prevent accidental mixing of structurally identical types.
|
|
1006
1767
|
*
|
|
1007
1768
|
* @category Branding
|
|
1008
1769
|
* @since 4.0.0
|
|
@@ -1014,7 +1775,10 @@ export function brand(identifier) {
|
|
|
1014
1775
|
});
|
|
1015
1776
|
}
|
|
1016
1777
|
/**
|
|
1017
|
-
* @
|
|
1778
|
+
* Creates a branded schema from a {@link Brand.Constructor}, applying the
|
|
1779
|
+
* constructor's checks and brand tag to the underlying schema.
|
|
1780
|
+
*
|
|
1781
|
+
* @category Branding
|
|
1018
1782
|
* @since 4.0.0
|
|
1019
1783
|
*/
|
|
1020
1784
|
export function fromBrand(identifier, ctor) {
|
|
@@ -1023,6 +1787,25 @@ export function fromBrand(identifier, ctor) {
|
|
|
1023
1787
|
};
|
|
1024
1788
|
}
|
|
1025
1789
|
/**
|
|
1790
|
+
* Intercepts the decoding pipeline of a schema.
|
|
1791
|
+
*
|
|
1792
|
+
* The provided function receives the current decoding `Effect` and `ParseOptions`,
|
|
1793
|
+
* and returns a new `Effect` — potentially adding service requirements (`RD`),
|
|
1794
|
+
* recovering from errors, or augmenting the result.
|
|
1795
|
+
*
|
|
1796
|
+
* **Example** (Logging decode failures)
|
|
1797
|
+
*
|
|
1798
|
+
* ```ts
|
|
1799
|
+
* import { Effect, Schema } from "effect"
|
|
1800
|
+
*
|
|
1801
|
+
* const Logged = Schema.String.pipe(
|
|
1802
|
+
* Schema.middlewareDecoding((effect) =>
|
|
1803
|
+
* Effect.tapError(effect, (issue) => Effect.log("decode failed", issue))
|
|
1804
|
+
* )
|
|
1805
|
+
* )
|
|
1806
|
+
* ```
|
|
1807
|
+
*
|
|
1808
|
+
* @see {@link catchDecoding} for a simpler error-recovery variant
|
|
1026
1809
|
* @since 4.0.0
|
|
1027
1810
|
*/
|
|
1028
1811
|
export function middlewareDecoding(decode) {
|
|
@@ -1031,6 +1814,25 @@ export function middlewareDecoding(decode) {
|
|
|
1031
1814
|
});
|
|
1032
1815
|
}
|
|
1033
1816
|
/**
|
|
1817
|
+
* Intercepts the encoding pipeline of a schema.
|
|
1818
|
+
*
|
|
1819
|
+
* The provided function receives the current encoding `Effect` and `ParseOptions`,
|
|
1820
|
+
* and returns a new `Effect` — potentially adding service requirements (`RE`),
|
|
1821
|
+
* recovering from errors, or augmenting the result.
|
|
1822
|
+
*
|
|
1823
|
+
* **Example** (Logging encode failures)
|
|
1824
|
+
*
|
|
1825
|
+
* ```ts
|
|
1826
|
+
* import { Effect, Schema } from "effect"
|
|
1827
|
+
*
|
|
1828
|
+
* const Logged = Schema.String.pipe(
|
|
1829
|
+
* Schema.middlewareEncoding((effect) =>
|
|
1830
|
+
* Effect.tapError(effect, (issue) => Effect.log("encode failed", issue))
|
|
1831
|
+
* )
|
|
1832
|
+
* )
|
|
1833
|
+
* ```
|
|
1834
|
+
*
|
|
1835
|
+
* @see {@link catchEncoding} for a simpler error-recovery variant
|
|
1034
1836
|
* @since 4.0.0
|
|
1035
1837
|
*/
|
|
1036
1838
|
export function middlewareEncoding(encode) {
|
|
@@ -1039,24 +1841,50 @@ export function middlewareEncoding(encode) {
|
|
|
1039
1841
|
});
|
|
1040
1842
|
}
|
|
1041
1843
|
/**
|
|
1844
|
+
* Recovers from a decoding error by providing a fallback value.
|
|
1845
|
+
*
|
|
1846
|
+
* The handler receives the `Issue` and returns an `Effect` that either
|
|
1847
|
+
* succeeds with a fallback value or re-fails with a (possibly different) issue.
|
|
1848
|
+
*
|
|
1849
|
+
* **Example** (Returning a default on decode failure)
|
|
1850
|
+
*
|
|
1851
|
+
* ```ts
|
|
1852
|
+
* import { Effect, Option, Schema } from "effect"
|
|
1853
|
+
*
|
|
1854
|
+
* const schema = Schema.Number.pipe(
|
|
1855
|
+
* Schema.catchDecoding((_issue) => Effect.succeed(Option.some(0)))
|
|
1856
|
+
* )
|
|
1857
|
+
* ```
|
|
1858
|
+
*
|
|
1859
|
+
* @see {@link catchDecodingWithContext} to add service requirements to the handler
|
|
1042
1860
|
* @since 4.0.0
|
|
1043
1861
|
*/
|
|
1044
1862
|
export function catchDecoding(f) {
|
|
1045
1863
|
return catchDecodingWithContext(f);
|
|
1046
1864
|
}
|
|
1047
1865
|
/**
|
|
1866
|
+
* Like {@link catchDecoding}, but the handler may require Effect services (`R`).
|
|
1867
|
+
*
|
|
1048
1868
|
* @since 4.0.0
|
|
1049
1869
|
*/
|
|
1050
1870
|
export function catchDecodingWithContext(f) {
|
|
1051
1871
|
return self => self.pipe(middlewareDecoding(Effect.catchEager(f)));
|
|
1052
1872
|
}
|
|
1053
1873
|
/**
|
|
1874
|
+
* Recovers from an encoding error by providing a fallback value.
|
|
1875
|
+
*
|
|
1876
|
+
* The handler receives the `Issue` and returns an `Effect` that either
|
|
1877
|
+
* succeeds with a fallback value or re-fails with a (possibly different) issue.
|
|
1878
|
+
*
|
|
1879
|
+
* @see {@link catchEncodingWithContext} to add service requirements to the handler
|
|
1054
1880
|
* @since 4.0.0
|
|
1055
1881
|
*/
|
|
1056
1882
|
export function catchEncoding(f) {
|
|
1057
1883
|
return catchEncodingWithContext(f);
|
|
1058
1884
|
}
|
|
1059
1885
|
/**
|
|
1886
|
+
* Like {@link catchEncoding}, but the handler may require Effect services (`R`).
|
|
1887
|
+
*
|
|
1060
1888
|
* @since 4.0.0
|
|
1061
1889
|
*/
|
|
1062
1890
|
export function catchEncodingWithContext(f) {
|
|
@@ -1118,6 +1946,25 @@ export function encodeTo(to, transformation) {
|
|
|
1118
1946
|
};
|
|
1119
1947
|
}
|
|
1120
1948
|
/**
|
|
1949
|
+
* Applies a transformation to a schema's encoded type, creating a new schema where encoding/decoding
|
|
1950
|
+
* operate on `S["Encoded"]` rather than `S["Type"]`.
|
|
1951
|
+
*
|
|
1952
|
+
* The `decode` getter maps `S["Encoded"]` → `S["Encoded"]` (applied during decoding),
|
|
1953
|
+
* and the `encode` getter maps `S["Encoded"]` → `S["Encoded"]` (applied during encoding).
|
|
1954
|
+
*
|
|
1955
|
+
* **Example** (Upper-casing encoded strings)
|
|
1956
|
+
*
|
|
1957
|
+
* ```ts
|
|
1958
|
+
* import { Schema, SchemaGetter } from "effect"
|
|
1959
|
+
*
|
|
1960
|
+
* const UpperFromLower = Schema.String.pipe(
|
|
1961
|
+
* Schema.encode({
|
|
1962
|
+
* decode: SchemaGetter.transform((s: string) => s.toLowerCase()),
|
|
1963
|
+
* encode: SchemaGetter.transform((s: string) => s.toUpperCase())
|
|
1964
|
+
* })
|
|
1965
|
+
* )
|
|
1966
|
+
* ```
|
|
1967
|
+
*
|
|
1121
1968
|
* @since 4.0.0
|
|
1122
1969
|
*/
|
|
1123
1970
|
export function encode(transformation) {
|
|
@@ -1126,6 +1973,32 @@ export function encode(transformation) {
|
|
|
1126
1973
|
};
|
|
1127
1974
|
}
|
|
1128
1975
|
/**
|
|
1976
|
+
* Attaches a constructor default value to a schema field.
|
|
1977
|
+
*
|
|
1978
|
+
* The `defaultValue` function receives `Option.some(undefined)` when the field is
|
|
1979
|
+
* explicitly set to `undefined`, or `Option.none()` when the field is absent.
|
|
1980
|
+
* Return `Option.some(value)` to supply a default, or `Option.none()` to leave the
|
|
1981
|
+
* field required. An `Effect` may be returned for async or service-dependent defaults.
|
|
1982
|
+
*
|
|
1983
|
+
* Constructor defaults are applied only during `makeUnsafe` / `make`, not during
|
|
1984
|
+
* decoding or encoding.
|
|
1985
|
+
*
|
|
1986
|
+
* **Example** (Optional field with a static default)
|
|
1987
|
+
*
|
|
1988
|
+
* ```ts
|
|
1989
|
+
* import { Option, Schema } from "effect"
|
|
1990
|
+
*
|
|
1991
|
+
* const MySchema = Schema.Struct({
|
|
1992
|
+
* name: Schema.String.pipe(
|
|
1993
|
+
* Schema.optionalKey,
|
|
1994
|
+
* Schema.withConstructorDefault(() => Option.some("anonymous"))
|
|
1995
|
+
* )
|
|
1996
|
+
* })
|
|
1997
|
+
*
|
|
1998
|
+
* const value = MySchema.makeUnsafe({})
|
|
1999
|
+
* // value: { name: "anonymous" }
|
|
2000
|
+
* ```
|
|
2001
|
+
*
|
|
1129
2002
|
* @since 4.0.0
|
|
1130
2003
|
*/
|
|
1131
2004
|
export function withConstructorDefault(defaultValue) {
|
|
@@ -1142,6 +2015,27 @@ export function withConstructorDefault(defaultValue) {
|
|
|
1142
2015
|
* - `passthrough`: (default) Pass the default value through to the output.
|
|
1143
2016
|
* - `omit`: Omit the value from the output.
|
|
1144
2017
|
*
|
|
2018
|
+
* Provides a default value for a missing key during decoding.
|
|
2019
|
+
*
|
|
2020
|
+
* When the key is absent from the input, `defaultValue()` is called to supply a value.
|
|
2021
|
+
* During encoding, the behavior is controlled by `options.encodingStrategy`:
|
|
2022
|
+
* - `"passthrough"` (default): include the value in the output
|
|
2023
|
+
* - `"omit"`: omit the key from the output
|
|
2024
|
+
*
|
|
2025
|
+
* **Example** (Default for a missing struct key)
|
|
2026
|
+
*
|
|
2027
|
+
* ```ts
|
|
2028
|
+
* import { Schema } from "effect"
|
|
2029
|
+
*
|
|
2030
|
+
* const MySchema = Schema.Struct({
|
|
2031
|
+
* name: Schema.String.pipe(Schema.withDecodingDefaultKey(() => "anonymous"))
|
|
2032
|
+
* })
|
|
2033
|
+
*
|
|
2034
|
+
* const result = Schema.decodeUnknownSync(MySchema)({})
|
|
2035
|
+
* // result: { name: "anonymous" }
|
|
2036
|
+
* ```
|
|
2037
|
+
*
|
|
2038
|
+
* @see {@link withDecodingDefault} for the `optional` (value-level) variant
|
|
1145
2039
|
* @since 4.0.0
|
|
1146
2040
|
*/
|
|
1147
2041
|
export function withDecodingDefaultKey(defaultValue, options) {
|
|
@@ -1160,6 +2054,30 @@ export function withDecodingDefaultKey(defaultValue, options) {
|
|
|
1160
2054
|
* - `passthrough`: (default) Pass the default value through to the output.
|
|
1161
2055
|
* - `omit`: Omit the value from the output.
|
|
1162
2056
|
*
|
|
2057
|
+
* Provides a default value for an `optional` field during decoding.
|
|
2058
|
+
*
|
|
2059
|
+
* Similar to {@link withDecodingDefaultKey} but works on `optional` (value-level optional)
|
|
2060
|
+
* rather than `optionalKey` (key-level optional).
|
|
2061
|
+
*
|
|
2062
|
+
* When the value is `undefined` or absent, `defaultValue()` is called to supply a value.
|
|
2063
|
+
* During encoding, the behavior is controlled by `options.encodingStrategy`:
|
|
2064
|
+
* - `"passthrough"` (default): include the value in the output
|
|
2065
|
+
* - `"omit"`: omit the value from the output
|
|
2066
|
+
*
|
|
2067
|
+
* **Example** (Default for an optional field value)
|
|
2068
|
+
*
|
|
2069
|
+
* ```ts
|
|
2070
|
+
* import { Schema } from "effect"
|
|
2071
|
+
*
|
|
2072
|
+
* const MySchema = Schema.Struct({
|
|
2073
|
+
* name: Schema.String.pipe(Schema.optional, Schema.withDecodingDefault(() => "anonymous"))
|
|
2074
|
+
* })
|
|
2075
|
+
*
|
|
2076
|
+
* const result = Schema.decodeUnknownSync(MySchema)({ name: undefined })
|
|
2077
|
+
* // result: { name: "anonymous" }
|
|
2078
|
+
* ```
|
|
2079
|
+
*
|
|
2080
|
+
* @see {@link withDecodingDefaultKey} for the key-level variant
|
|
1163
2081
|
* @since 4.0.0
|
|
1164
2082
|
*/
|
|
1165
2083
|
export function withDecodingDefault(defaultValue, options) {
|
|
@@ -1172,23 +2090,50 @@ export function withDecodingDefault(defaultValue, options) {
|
|
|
1172
2090
|
};
|
|
1173
2091
|
}
|
|
1174
2092
|
/**
|
|
1175
|
-
*
|
|
1176
|
-
*
|
|
2093
|
+
* Combines a {@link Literal} schema with {@link withConstructorDefault}, making it ideal
|
|
2094
|
+
* for discriminator fields in tagged unions. When constructing via `makeUnsafe`, the
|
|
2095
|
+
* `_tag` field can be omitted and will be filled automatically.
|
|
1177
2096
|
*
|
|
1178
|
-
*
|
|
1179
|
-
* making it perfect for discriminated unions and tagged data structures. The
|
|
1180
|
-
* tag value is automatically provided when the field is missing during
|
|
1181
|
-
* construction.
|
|
2097
|
+
* **Example** (Discriminated union tag)
|
|
1182
2098
|
*
|
|
2099
|
+
* ```ts
|
|
2100
|
+
* import { Schema } from "effect"
|
|
2101
|
+
*
|
|
2102
|
+
* const A = Schema.Struct({ _tag: Schema.tag("A"), value: Schema.Number })
|
|
2103
|
+
*
|
|
2104
|
+
* // _tag is optional in makeUnsafe, auto-filled to "A"
|
|
2105
|
+
* const a = A.makeUnsafe({ value: 42 })
|
|
2106
|
+
* // a: { _tag: "A", value: 42 }
|
|
2107
|
+
* ```
|
|
2108
|
+
*
|
|
2109
|
+
* @see {@link tagDefaultOmit} to also omit the tag during encoding
|
|
2110
|
+
* @see {@link TaggedStruct} for a shorthand that adds `_tag` automatically
|
|
1183
2111
|
* @since 4.0.0
|
|
1184
2112
|
*/
|
|
1185
2113
|
export function tag(literal) {
|
|
1186
2114
|
return Literal(literal).pipe(withConstructorDefault(() => Option_.some(literal)));
|
|
1187
2115
|
}
|
|
1188
2116
|
/**
|
|
1189
|
-
*
|
|
1190
|
-
* the
|
|
2117
|
+
* Like {@link tag}, but additionally omits the tag field from the encoded output.
|
|
2118
|
+
* Useful when the encoded form (e.g. JSON) does not include the discriminator key,
|
|
2119
|
+
* but the decoded type and constructor still need it.
|
|
2120
|
+
*
|
|
2121
|
+
* **Example** (Tag omitted during encoding)
|
|
2122
|
+
*
|
|
2123
|
+
* ```ts
|
|
2124
|
+
* import { Schema } from "effect"
|
|
2125
|
+
*
|
|
2126
|
+
* const A = Schema.Struct({
|
|
2127
|
+
* _tag: Schema.tagDefaultOmit("A"),
|
|
2128
|
+
* value: Schema.Number
|
|
2129
|
+
* })
|
|
1191
2130
|
*
|
|
2131
|
+
* // Encode strips the _tag field
|
|
2132
|
+
* const encoded = Schema.encodeUnknownSync(A)({ _tag: "A", value: 1 })
|
|
2133
|
+
* // encoded: { value: 1 }
|
|
2134
|
+
* ```
|
|
2135
|
+
*
|
|
2136
|
+
* @see {@link tag} for the variant that keeps the tag during encoding
|
|
1192
2137
|
* @since 4.0.0
|
|
1193
2138
|
*/
|
|
1194
2139
|
export function tagDefaultOmit(literal) {
|
|
@@ -1244,18 +2189,27 @@ export function TaggedStruct(value, fields) {
|
|
|
1244
2189
|
...fields
|
|
1245
2190
|
});
|
|
1246
2191
|
}
|
|
1247
|
-
/** @internal */
|
|
1248
|
-
export function _getTagValueIfPropertyKey(tag, ast) {
|
|
1249
|
-
const ps = ast.propertySignatures.find(p => p.name === tag);
|
|
1250
|
-
if (ps) {
|
|
1251
|
-
if (AST.isLiteral(ps.type) && Predicate.isPropertyKey(ps.type.literal)) {
|
|
1252
|
-
return ps.type.literal;
|
|
1253
|
-
} else if (AST.isUniqueSymbol(ps.type)) {
|
|
1254
|
-
return ps.type.symbol;
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
2192
|
/**
|
|
2193
|
+
* Augments an existing {@link Union} of tagged structs with utility methods keyed by the discriminant field.
|
|
2194
|
+
*
|
|
2195
|
+
* **Example** (Adding tagged-union utilities to an existing union)
|
|
2196
|
+
*
|
|
2197
|
+
* ```ts
|
|
2198
|
+
* import { Schema } from "effect"
|
|
2199
|
+
*
|
|
2200
|
+
* const A = Schema.TaggedStruct("A", { value: Schema.Number })
|
|
2201
|
+
* const B = Schema.TaggedStruct("B", { name: Schema.String })
|
|
2202
|
+
*
|
|
2203
|
+
* const MyUnion = Schema.Union([A, B]).pipe(Schema.toTaggedUnion("_tag"))
|
|
2204
|
+
*
|
|
2205
|
+
* // Pattern-match on the union
|
|
2206
|
+
* const result = MyUnion.match({ _tag: "A", value: 1 }, {
|
|
2207
|
+
* A: (a) => `number: ${a.value}`,
|
|
2208
|
+
* B: (b) => `name: ${b.name}`
|
|
2209
|
+
* })
|
|
2210
|
+
* ```
|
|
2211
|
+
*
|
|
2212
|
+
* @see {@link TaggedUnion} for a shorthand that builds the union from scratch
|
|
1259
2213
|
* @since 4.0.0
|
|
1260
2214
|
* @experimental
|
|
1261
2215
|
*/
|
|
@@ -1276,15 +2230,16 @@ export function toTaggedUnion(tag) {
|
|
|
1276
2230
|
if (AST.isUnion(ast) && "members" in schema && globalThis.Array.isArray(schema.members) && schema.members.every(isSchema)) {
|
|
1277
2231
|
return schema.members.forEach(walk);
|
|
1278
2232
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
2233
|
+
const sentinels = AST.collectSentinels(ast);
|
|
2234
|
+
if (sentinels.length > 0) {
|
|
2235
|
+
const literal = sentinels.find(s => s.key === tag)?.literal;
|
|
2236
|
+
if (Predicate.isPropertyKey(literal)) {
|
|
2237
|
+
cases[literal] = schema;
|
|
2238
|
+
guards[literal] = is(toType(schema));
|
|
1284
2239
|
return;
|
|
1285
2240
|
}
|
|
1286
2241
|
}
|
|
1287
|
-
throw new globalThis.Error("No literal found");
|
|
2242
|
+
throw new globalThis.Error("No literal or unique symbol found");
|
|
1288
2243
|
}
|
|
1289
2244
|
function match() {
|
|
1290
2245
|
if (arguments.length === 1) {
|
|
@@ -1300,6 +2255,28 @@ export function toTaggedUnion(tag) {
|
|
|
1300
2255
|
};
|
|
1301
2256
|
}
|
|
1302
2257
|
/**
|
|
2258
|
+
* Builds a discriminated union from a record of field sets, one per variant.
|
|
2259
|
+
* Each key becomes the `_tag` literal and the value is passed to {@link TaggedStruct}.
|
|
2260
|
+
* The result includes `cases`, `guards`, `isAnyOf`, and `match` utilities.
|
|
2261
|
+
*
|
|
2262
|
+
* **Example** (Discriminated union with pattern matching)
|
|
2263
|
+
*
|
|
2264
|
+
* ```ts
|
|
2265
|
+
* import { Schema } from "effect"
|
|
2266
|
+
*
|
|
2267
|
+
* const Shape = Schema.TaggedUnion({
|
|
2268
|
+
* Circle: { radius: Schema.Number },
|
|
2269
|
+
* Rectangle: { width: Schema.Number, height: Schema.Number }
|
|
2270
|
+
* })
|
|
2271
|
+
*
|
|
2272
|
+
* // Pattern-match on a decoded value
|
|
2273
|
+
* const area = Shape.match({ _tag: "Circle", radius: 5 }, {
|
|
2274
|
+
* Circle: (c) => Math.PI * c.radius ** 2,
|
|
2275
|
+
* Rectangle: (r) => r.width * r.height
|
|
2276
|
+
* })
|
|
2277
|
+
* ```
|
|
2278
|
+
*
|
|
2279
|
+
* @see {@link toTaggedUnion} to augment an existing union instead
|
|
1303
2280
|
* @category Constructors
|
|
1304
2281
|
* @since 4.0.0
|
|
1305
2282
|
*/
|
|
@@ -1323,6 +2300,23 @@ export function TaggedUnion(casesByTag) {
|
|
|
1323
2300
|
});
|
|
1324
2301
|
}
|
|
1325
2302
|
/**
|
|
2303
|
+
* Wraps a schema so that its decoded `Type` becomes a nominally distinct type `Self`.
|
|
2304
|
+
* Useful for creating opaque types that are structurally identical to a base schema
|
|
2305
|
+
* but type-incompatible with it.
|
|
2306
|
+
*
|
|
2307
|
+
* **Example** (Opaque user ID)
|
|
2308
|
+
*
|
|
2309
|
+
* ```ts
|
|
2310
|
+
* import { Schema } from "effect"
|
|
2311
|
+
*
|
|
2312
|
+
* type UserId = string & { readonly _tag: "UserId" }
|
|
2313
|
+
* const UserId = Schema.Opaque<UserId>()(Schema.String)
|
|
2314
|
+
*
|
|
2315
|
+
* // Decoded value is UserId, not plain string
|
|
2316
|
+
* const id = Schema.decodeUnknownSync(UserId)("abc")
|
|
2317
|
+
* // id: UserId
|
|
2318
|
+
* ```
|
|
2319
|
+
*
|
|
1326
2320
|
* @since 4.0.0
|
|
1327
2321
|
*/
|
|
1328
2322
|
export function Opaque() {
|
|
@@ -1334,7 +2328,19 @@ export function Opaque() {
|
|
|
1334
2328
|
};
|
|
1335
2329
|
}
|
|
1336
2330
|
/**
|
|
1337
|
-
* Creates a schema that validates
|
|
2331
|
+
* Creates a schema that validates values using `instanceof`.
|
|
2332
|
+
* Decoding and encoding pass the value through unchanged.
|
|
2333
|
+
*
|
|
2334
|
+
* **Example** (Schema for a built-in class)
|
|
2335
|
+
*
|
|
2336
|
+
* ```ts
|
|
2337
|
+
* import { Schema } from "effect"
|
|
2338
|
+
*
|
|
2339
|
+
* const DateSchema = Schema.instanceOf(Date)
|
|
2340
|
+
*
|
|
2341
|
+
* const decoded = Schema.decodeUnknownSync(DateSchema)(new Date("2024-01-01"))
|
|
2342
|
+
* // decoded: Date
|
|
2343
|
+
* ```
|
|
1338
2344
|
*
|
|
1339
2345
|
* @category Constructors
|
|
1340
2346
|
* @since 4.0.0
|
|
@@ -1343,6 +2349,9 @@ export function instanceOf(constructor, annotations) {
|
|
|
1343
2349
|
return declare(u => u instanceof constructor, annotations);
|
|
1344
2350
|
}
|
|
1345
2351
|
/**
|
|
2352
|
+
* Constructs an `AST.Link` that describes how a value of type `T` encodes to and decodes from a `To` schema.
|
|
2353
|
+
* Used when building low-level AST transformations that bridge two schema types.
|
|
2354
|
+
*
|
|
1346
2355
|
* @since 4.0.0
|
|
1347
2356
|
* @experimental
|
|
1348
2357
|
*/
|
|
@@ -1355,11 +2364,30 @@ export function link() {
|
|
|
1355
2364
|
// Checks
|
|
1356
2365
|
// -----------------------------------------------------------------------------
|
|
1357
2366
|
/**
|
|
2367
|
+
* Creates a custom filter check from a predicate function. The predicate
|
|
2368
|
+
* receives the input value, the schema's AST, and parse options, and returns
|
|
2369
|
+
* `true`/`undefined` on success or a failure description on error.
|
|
2370
|
+
*
|
|
2371
|
+
* **Example** (Custom filter check)
|
|
2372
|
+
* ```ts
|
|
2373
|
+
* import { Schema } from "effect"
|
|
2374
|
+
*
|
|
2375
|
+
* // Check that a number is even
|
|
2376
|
+
* const isEven = Schema.makeFilter(
|
|
2377
|
+
* (n: number) => n % 2 === 0 || "expected an even number"
|
|
2378
|
+
* )
|
|
2379
|
+
*
|
|
2380
|
+
* const EvenNumber = Schema.Number.check(isEven)
|
|
2381
|
+
* ```
|
|
2382
|
+
*
|
|
1358
2383
|
* @category Checks Constructors
|
|
1359
2384
|
* @since 4.0.0
|
|
1360
2385
|
*/
|
|
1361
2386
|
export const makeFilter = AST.makeFilter;
|
|
1362
2387
|
/**
|
|
2388
|
+
* Groups multiple checks into a single {@link AST.FilterGroup}, applying
|
|
2389
|
+
* optional shared annotations to the group as a whole.
|
|
2390
|
+
*
|
|
1363
2391
|
* @category Checks Constructors
|
|
1364
2392
|
* @since 4.0.0
|
|
1365
2393
|
*/
|
|
@@ -1847,6 +2875,9 @@ export function isFinite(annotations) {
|
|
|
1847
2875
|
});
|
|
1848
2876
|
}
|
|
1849
2877
|
/**
|
|
2878
|
+
* Generic factory for creating a "greater than" (`>`) check for any ordered
|
|
2879
|
+
* type by supplying an {@link Order.Order} instance.
|
|
2880
|
+
*
|
|
1850
2881
|
* @category Order checks
|
|
1851
2882
|
* @since 4.0.0
|
|
1852
2883
|
*/
|
|
@@ -1862,6 +2893,9 @@ export function makeIsGreaterThan(options) {
|
|
|
1862
2893
|
};
|
|
1863
2894
|
}
|
|
1864
2895
|
/**
|
|
2896
|
+
* Generic factory for creating a ">=" check for any ordered type by supplying
|
|
2897
|
+
* an {@link Order.Order} instance.
|
|
2898
|
+
*
|
|
1865
2899
|
* @category Order checks
|
|
1866
2900
|
* @since 4.0.0
|
|
1867
2901
|
*/
|
|
@@ -1877,6 +2911,9 @@ export function makeIsGreaterThanOrEqualTo(options) {
|
|
|
1877
2911
|
};
|
|
1878
2912
|
}
|
|
1879
2913
|
/**
|
|
2914
|
+
* Generic factory for creating a "<" check for any ordered type by supplying
|
|
2915
|
+
* an {@link Order.Order} instance.
|
|
2916
|
+
*
|
|
1880
2917
|
* @category Order checks
|
|
1881
2918
|
* @since 4.0.0
|
|
1882
2919
|
*/
|
|
@@ -1892,6 +2929,9 @@ export function makeIsLessThan(options) {
|
|
|
1892
2929
|
};
|
|
1893
2930
|
}
|
|
1894
2931
|
/**
|
|
2932
|
+
* Generic factory for creating a "<=" check for any ordered type by supplying
|
|
2933
|
+
* an {@link Order.Order} instance.
|
|
2934
|
+
*
|
|
1895
2935
|
* @category Order checks
|
|
1896
2936
|
* @since 4.0.0
|
|
1897
2937
|
*/
|
|
@@ -1907,6 +2947,9 @@ export function makeIsLessThanOrEqualTo(options) {
|
|
|
1907
2947
|
};
|
|
1908
2948
|
}
|
|
1909
2949
|
/**
|
|
2950
|
+
* Generic factory for creating an inclusive/exclusive range check for any
|
|
2951
|
+
* ordered type by supplying an {@link Order.Order} instance.
|
|
2952
|
+
*
|
|
1910
2953
|
* @category Order checks
|
|
1911
2954
|
* @since 4.0.0
|
|
1912
2955
|
*/
|
|
@@ -1927,6 +2970,9 @@ export function makeIsBetween(deriveOptions) {
|
|
|
1927
2970
|
};
|
|
1928
2971
|
}
|
|
1929
2972
|
/**
|
|
2973
|
+
* Generic factory for creating a divisibility check for any numeric type by
|
|
2974
|
+
* supplying a remainder function and a zero value.
|
|
2975
|
+
*
|
|
1930
2976
|
* @category Numeric checks
|
|
1931
2977
|
* @since 4.0.0
|
|
1932
2978
|
*/
|
|
@@ -2528,6 +3574,58 @@ export const isBetweenBigInt = /*#__PURE__*/makeIsBetween({
|
|
|
2528
3574
|
}
|
|
2529
3575
|
})
|
|
2530
3576
|
});
|
|
3577
|
+
/**
|
|
3578
|
+
* Validates that a BigDecimal is greater than the specified value (exclusive).
|
|
3579
|
+
*
|
|
3580
|
+
* @category BigDecimal checks
|
|
3581
|
+
* @since 4.0.0
|
|
3582
|
+
*/
|
|
3583
|
+
export const isGreaterThanBigDecimal = /*#__PURE__*/makeIsGreaterThan({
|
|
3584
|
+
order: BigDecimal_.Order,
|
|
3585
|
+
formatter: bd => BigDecimal_.format(bd)
|
|
3586
|
+
});
|
|
3587
|
+
/**
|
|
3588
|
+
* Validates that a BigDecimal is greater than or equal to the specified value
|
|
3589
|
+
* (inclusive).
|
|
3590
|
+
*
|
|
3591
|
+
* @category BigDecimal checks
|
|
3592
|
+
* @since 4.0.0
|
|
3593
|
+
*/
|
|
3594
|
+
export const isGreaterThanOrEqualToBigDecimal = /*#__PURE__*/makeIsGreaterThanOrEqualTo({
|
|
3595
|
+
order: BigDecimal_.Order,
|
|
3596
|
+
formatter: bd => BigDecimal_.format(bd)
|
|
3597
|
+
});
|
|
3598
|
+
/**
|
|
3599
|
+
* Validates that a BigDecimal is less than the specified value (exclusive).
|
|
3600
|
+
*
|
|
3601
|
+
* @category BigDecimal checks
|
|
3602
|
+
* @since 4.0.0
|
|
3603
|
+
*/
|
|
3604
|
+
export const isLessThanBigDecimal = /*#__PURE__*/makeIsLessThan({
|
|
3605
|
+
order: BigDecimal_.Order,
|
|
3606
|
+
formatter: bd => BigDecimal_.format(bd)
|
|
3607
|
+
});
|
|
3608
|
+
/**
|
|
3609
|
+
* Validates that a BigDecimal is less than or equal to the specified value
|
|
3610
|
+
* (inclusive).
|
|
3611
|
+
*
|
|
3612
|
+
* @category BigDecimal checks
|
|
3613
|
+
* @since 4.0.0
|
|
3614
|
+
*/
|
|
3615
|
+
export const isLessThanOrEqualToBigDecimal = /*#__PURE__*/makeIsLessThanOrEqualTo({
|
|
3616
|
+
order: BigDecimal_.Order,
|
|
3617
|
+
formatter: bd => BigDecimal_.format(bd)
|
|
3618
|
+
});
|
|
3619
|
+
/**
|
|
3620
|
+
* Validates that a BigDecimal is within a specified range.
|
|
3621
|
+
*
|
|
3622
|
+
* @category BigDecimal checks
|
|
3623
|
+
* @since 4.0.0
|
|
3624
|
+
*/
|
|
3625
|
+
export const isBetweenBigDecimal = /*#__PURE__*/makeIsBetween({
|
|
3626
|
+
order: BigDecimal_.Order,
|
|
3627
|
+
formatter: bd => BigDecimal_.format(bd)
|
|
3628
|
+
});
|
|
2531
3629
|
/**
|
|
2532
3630
|
* Validates that a value has at least the specified length. Works with strings
|
|
2533
3631
|
* and arrays.
|
|
@@ -2543,6 +3641,14 @@ export const isBetweenBigInt = /*#__PURE__*/makeIsBetween({
|
|
|
2543
3641
|
* constraint to ensure generated strings or arrays have at least the required
|
|
2544
3642
|
* length.
|
|
2545
3643
|
*
|
|
3644
|
+
* **Example** (Minimum length check)
|
|
3645
|
+
* ```ts
|
|
3646
|
+
* import { Schema } from "effect"
|
|
3647
|
+
*
|
|
3648
|
+
* const NonEmptyStringSchema = Schema.String.check(Schema.isMinLength(1))
|
|
3649
|
+
* const NonEmptyArraySchema = Schema.Array(Schema.Number).check(Schema.isMinLength(1))
|
|
3650
|
+
* ```
|
|
3651
|
+
*
|
|
2546
3652
|
* @category Length checks
|
|
2547
3653
|
* @since 4.0.0
|
|
2548
3654
|
*/
|
|
@@ -2935,6 +4041,7 @@ export function isPropertyNames(keySchema, annotations) {
|
|
|
2935
4041
|
* constraint using the provided equivalence function to ensure generated arrays
|
|
2936
4042
|
* contain only unique items.
|
|
2937
4043
|
*
|
|
4044
|
+
* @category Array checks
|
|
2938
4045
|
* @since 4.0.0
|
|
2939
4046
|
*/
|
|
2940
4047
|
export function isUnique(annotations) {
|
|
@@ -2969,6 +4076,8 @@ export const NonEmptyString = /*#__PURE__*/String.check(/*#__PURE__*/isNonEmpty(
|
|
|
2969
4076
|
*/
|
|
2970
4077
|
export const Char = /*#__PURE__*/String.check(/*#__PURE__*/isLengthBetween(1, 1));
|
|
2971
4078
|
/**
|
|
4079
|
+
* Creates a schema for `Option<A>`. See {@link Option} for details.
|
|
4080
|
+
*
|
|
2972
4081
|
* @category Option
|
|
2973
4082
|
* @since 4.0.0
|
|
2974
4083
|
*/
|
|
@@ -3041,6 +4150,40 @@ export function Option(value) {
|
|
|
3041
4150
|
export function OptionFromNullOr(schema) {
|
|
3042
4151
|
return NullOr(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromNullOr()));
|
|
3043
4152
|
}
|
|
4153
|
+
/**
|
|
4154
|
+
* Decodes an undefined-or value `T` to a required `Option<T>` value.
|
|
4155
|
+
*
|
|
4156
|
+
* Decoding:
|
|
4157
|
+
* - `undefined` is decoded as `None`
|
|
4158
|
+
* - other values are decoded as `Some`
|
|
4159
|
+
*
|
|
4160
|
+
* Encoding:
|
|
4161
|
+
* - `None` is encoded as `undefined`
|
|
4162
|
+
* - `Some` is encoded as the value
|
|
4163
|
+
*
|
|
4164
|
+
* @category Option
|
|
4165
|
+
* @since 4.0.0
|
|
4166
|
+
*/
|
|
4167
|
+
export function OptionFromUndefinedOr(schema) {
|
|
4168
|
+
return UndefinedOr(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromUndefinedOr()));
|
|
4169
|
+
}
|
|
4170
|
+
/**
|
|
4171
|
+
* Decodes a nullish value `T` to a required `Option<T>` value.
|
|
4172
|
+
*
|
|
4173
|
+
* Decoding:
|
|
4174
|
+
* - `null` and `undefined` are decoded as `None`
|
|
4175
|
+
* - other values are decoded as `Some`
|
|
4176
|
+
*
|
|
4177
|
+
* Encoding:
|
|
4178
|
+
* - `None` is encoded as `null` or `undefined` depending on the provided `options.onNoneEncoding` (defaults to `undefined`)
|
|
4179
|
+
* - `Some` is encoded as the value
|
|
4180
|
+
*
|
|
4181
|
+
* @category Option
|
|
4182
|
+
* @since 4.0.0
|
|
4183
|
+
*/
|
|
4184
|
+
export function OptionFromNullishOr(schema, options) {
|
|
4185
|
+
return NullishOr(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromNullishOr(options)));
|
|
4186
|
+
}
|
|
3044
4187
|
/**
|
|
3045
4188
|
* Decodes an optional value `A` to a required `Option<A>` value.
|
|
3046
4189
|
*
|
|
@@ -3078,6 +4221,35 @@ export function OptionFromOptional(schema) {
|
|
|
3078
4221
|
return optional(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromOptional()));
|
|
3079
4222
|
}
|
|
3080
4223
|
/**
|
|
4224
|
+
* Decodes an optional or `null` or `undefined` value `A` to a required `Option<A>`
|
|
4225
|
+
* value.
|
|
4226
|
+
*
|
|
4227
|
+
* Decoding:
|
|
4228
|
+
* - a missing key is decoded as `None`
|
|
4229
|
+
* - a present key with an `undefined` value is decoded as `None`
|
|
4230
|
+
* - a present key with a `null` value is decoded as `None`
|
|
4231
|
+
* - all other values are decoded as `Some`
|
|
4232
|
+
*
|
|
4233
|
+
* Encoding (controlled by `options.onNoneEncoding`):
|
|
4234
|
+
* - `"omit"` (default): `None` is encoded as a missing key
|
|
4235
|
+
* - `null`: `None` is encoded as `null`
|
|
4236
|
+
* - `undefined`: `None` is encoded as `undefined`
|
|
4237
|
+
* - `Some` is always encoded as the value
|
|
4238
|
+
*
|
|
4239
|
+
* @category Option
|
|
4240
|
+
* @since 4.0.0
|
|
4241
|
+
*/
|
|
4242
|
+
export function OptionFromOptionalNullOr(schema, options) {
|
|
4243
|
+
const onNoneEncoding = options === undefined ? "omit" : options.onNoneEncoding;
|
|
4244
|
+
const noneValue = onNoneEncoding === null ? null : undefined;
|
|
4245
|
+
return optional(NullOr(schema)).pipe(decodeTo(Option(toType(schema)), Transformation.transformOptional({
|
|
4246
|
+
decode: oe => oe.pipe(Option_.filter(Predicate.isNotNullish), Option_.some),
|
|
4247
|
+
encode: onNoneEncoding === "omit" ? Option_.flatten : ot => Option_.some(Option_.getOrElse(Option_.flatten(ot), () => noneValue))
|
|
4248
|
+
})));
|
|
4249
|
+
}
|
|
4250
|
+
/**
|
|
4251
|
+
* Creates a schema for `Result<A, E>`. See {@link Result} for details.
|
|
4252
|
+
*
|
|
3081
4253
|
* @category Result
|
|
3082
4254
|
* @since 4.0.0
|
|
3083
4255
|
*/
|
|
@@ -3206,6 +4378,9 @@ export function Redacted(value, options) {
|
|
|
3206
4378
|
});
|
|
3207
4379
|
}
|
|
3208
4380
|
/**
|
|
4381
|
+
* Middleware that wraps decoded errors in `Redacted`, preventing sensitive
|
|
4382
|
+
* schema details from leaking in error messages.
|
|
4383
|
+
*
|
|
3209
4384
|
* @category Redacted
|
|
3210
4385
|
* @since 4.0.0
|
|
3211
4386
|
*/
|
|
@@ -3213,6 +4388,10 @@ export function redact(schema) {
|
|
|
3213
4388
|
return schema.pipe(middlewareDecoding(Effect.mapErrorEager(Issue.redact)));
|
|
3214
4389
|
}
|
|
3215
4390
|
/**
|
|
4391
|
+
* Decodes a value and wraps it in `Redacted<A>`. Unlike {@link Redacted} which
|
|
4392
|
+
* expects the input to already be a `Redacted` instance, this schema decodes
|
|
4393
|
+
* the raw value and wraps it.
|
|
4394
|
+
*
|
|
3216
4395
|
* @category Redacted
|
|
3217
4396
|
* @since 4.0.0
|
|
3218
4397
|
*/
|
|
@@ -3225,10 +4404,12 @@ export function RedactedFromValue(value, options) {
|
|
|
3225
4404
|
}));
|
|
3226
4405
|
}
|
|
3227
4406
|
/**
|
|
3228
|
-
* @
|
|
4407
|
+
* Creates a schema for `Cause.Reason<E>`. See {@link CauseReason} for details.
|
|
4408
|
+
*
|
|
4409
|
+
* @category CauseReason
|
|
3229
4410
|
* @since 4.0.0
|
|
3230
4411
|
*/
|
|
3231
|
-
export function
|
|
4412
|
+
export function CauseReason(error, defect) {
|
|
3232
4413
|
const schema = declareConstructor()([error, defect], ([error, defect]) => (input, ast, options) => {
|
|
3233
4414
|
if (!Cause_.isReason(input)) {
|
|
3234
4415
|
return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
|
|
@@ -3252,7 +4433,7 @@ export function CauseFailure(error, defect) {
|
|
|
3252
4433
|
_tag: "effect/Cause/Failure"
|
|
3253
4434
|
},
|
|
3254
4435
|
generation: {
|
|
3255
|
-
runtime: `Schema.
|
|
4436
|
+
runtime: `Schema.CauseReason(?, ?)`,
|
|
3256
4437
|
Type: `Cause.Failure<?, ?>`,
|
|
3257
4438
|
importDeclaration: `import * as Cause from "effect/Cause"`
|
|
3258
4439
|
},
|
|
@@ -3279,16 +4460,16 @@ export function CauseFailure(error, defect) {
|
|
|
3279
4460
|
},
|
|
3280
4461
|
encode: identity
|
|
3281
4462
|
})),
|
|
3282
|
-
toArbitrary: ([error, defect]) =>
|
|
3283
|
-
toEquivalence: ([error, defect]) =>
|
|
3284
|
-
toFormatter: ([error, defect]) =>
|
|
4463
|
+
toArbitrary: ([error, defect]) => causeReasonToArbitrary(error, defect),
|
|
4464
|
+
toEquivalence: ([error, defect]) => causeReasonToEquivalence(error, defect),
|
|
4465
|
+
toFormatter: ([error, defect]) => causeReasonToFormatter(error, defect)
|
|
3285
4466
|
});
|
|
3286
4467
|
return make(schema.ast, {
|
|
3287
4468
|
error,
|
|
3288
4469
|
defect
|
|
3289
4470
|
});
|
|
3290
4471
|
}
|
|
3291
|
-
function
|
|
4472
|
+
function causeReasonToArbitrary(error, defect) {
|
|
3292
4473
|
return (fc, ctx) => {
|
|
3293
4474
|
return fc.oneof(ctx?.isSuspend ? {
|
|
3294
4475
|
maxDepth: 2,
|
|
@@ -3298,7 +4479,7 @@ function causeFailureToArbitrary(error, defect) {
|
|
|
3298
4479
|
}).map(Cause_.makeInterruptReason), error.map(e => Cause_.makeFailReason(e)), defect.map(d => Cause_.makeDieReason(d)));
|
|
3299
4480
|
};
|
|
3300
4481
|
}
|
|
3301
|
-
function
|
|
4482
|
+
function causeReasonToEquivalence(error, defect) {
|
|
3302
4483
|
return (a, b) => {
|
|
3303
4484
|
if (a._tag !== b._tag) return false;
|
|
3304
4485
|
switch (a._tag) {
|
|
@@ -3311,7 +4492,7 @@ function causeFailureToEquivalence(error, defect) {
|
|
|
3311
4492
|
}
|
|
3312
4493
|
};
|
|
3313
4494
|
}
|
|
3314
|
-
function
|
|
4495
|
+
function causeReasonToFormatter(error, defect) {
|
|
3315
4496
|
return t => {
|
|
3316
4497
|
switch (t._tag) {
|
|
3317
4498
|
case "Fail":
|
|
@@ -3324,19 +4505,23 @@ function causeFailureToFormatter(error, defect) {
|
|
|
3324
4505
|
};
|
|
3325
4506
|
}
|
|
3326
4507
|
/**
|
|
4508
|
+
* Creates a schema for `Cause<E>`. See {@link Cause} for details.
|
|
4509
|
+
*
|
|
3327
4510
|
* @category Cause
|
|
3328
4511
|
* @since 4.0.0
|
|
3329
4512
|
*/
|
|
3330
4513
|
export function Cause(error, defect) {
|
|
3331
|
-
const schema = declareConstructor()([error, defect], ([error, defect]) =>
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
4514
|
+
const schema = declareConstructor()([error, defect], ([error, defect]) => {
|
|
4515
|
+
const failures = ArraySchema(CauseReason(error, defect));
|
|
4516
|
+
return (input, ast, options) => {
|
|
4517
|
+
if (!Cause_.isCause(input)) {
|
|
4518
|
+
return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
|
|
4519
|
+
}
|
|
4520
|
+
return Effect.mapBothEager(Parser.decodeUnknownEffect(failures)(input.reasons, options), {
|
|
4521
|
+
onSuccess: Cause_.fromReasons,
|
|
4522
|
+
onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["failures"], issue)])
|
|
4523
|
+
});
|
|
4524
|
+
};
|
|
3340
4525
|
}, {
|
|
3341
4526
|
typeConstructor: {
|
|
3342
4527
|
_tag: "effect/Cause"
|
|
@@ -3347,7 +4532,7 @@ export function Cause(error, defect) {
|
|
|
3347
4532
|
importDeclaration: `import * as Cause from "effect/Cause"`
|
|
3348
4533
|
},
|
|
3349
4534
|
expected: "Cause",
|
|
3350
|
-
toCodec: ([error, defect]) => link()(
|
|
4535
|
+
toCodec: ([error, defect]) => link()(ArraySchema(CauseReason(error, defect)), Transformation.transform({
|
|
3351
4536
|
decode: Cause_.fromReasons,
|
|
3352
4537
|
encode: ({
|
|
3353
4538
|
reasons: failures
|
|
@@ -3364,16 +4549,16 @@ export function Cause(error, defect) {
|
|
|
3364
4549
|
}
|
|
3365
4550
|
function causeToArbitrary(error, defect) {
|
|
3366
4551
|
return (fc, ctx) => {
|
|
3367
|
-
return fc.array(
|
|
4552
|
+
return fc.array(causeReasonToArbitrary(error, defect)(fc, ctx)).map(Cause_.fromReasons);
|
|
3368
4553
|
};
|
|
3369
4554
|
}
|
|
3370
4555
|
function causeToEquivalence(error, defect) {
|
|
3371
|
-
const failures = Equivalence.Array(
|
|
4556
|
+
const failures = Equivalence.Array(causeReasonToEquivalence(error, defect));
|
|
3372
4557
|
return (a, b) => failures(a.reasons, b.reasons);
|
|
3373
4558
|
}
|
|
3374
4559
|
function causeToFormatter(error, defect) {
|
|
3375
|
-
const
|
|
3376
|
-
return t => `Cause([${t.reasons.map(
|
|
4560
|
+
const causeReason = causeReasonToFormatter(error, defect);
|
|
4561
|
+
return t => `Cause([${t.reasons.map(causeReason).join(", ")}])`;
|
|
3377
4562
|
}
|
|
3378
4563
|
const ErrorJsonEncoded = /*#__PURE__*/Struct({
|
|
3379
4564
|
message: String,
|
|
@@ -3455,27 +4640,31 @@ export const DefectWithStack = /*#__PURE__*/Union([/*#__PURE__*/ErrorJsonEncoded
|
|
|
3455
4640
|
toArbitrary: () => fc => fc.json()
|
|
3456
4641
|
}), defectTransformation))]);
|
|
3457
4642
|
/**
|
|
4643
|
+
* Creates a schema for `Exit<A, E>`. See {@link Exit} for details.
|
|
4644
|
+
*
|
|
3458
4645
|
* @category Exit
|
|
3459
4646
|
* @since 4.0.0
|
|
3460
4647
|
*/
|
|
3461
4648
|
export function Exit(value, error, defect) {
|
|
3462
|
-
const schema = declareConstructor()([value, error, defect], ([value, error, defect]) =>
|
|
3463
|
-
if (!Exit_.isExit(input)) {
|
|
3464
|
-
return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
|
|
3465
|
-
}
|
|
4649
|
+
const schema = declareConstructor()([value, error, defect], ([value, error, defect]) => {
|
|
3466
4650
|
const cause = Cause(error, defect);
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
return Effect.
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
4651
|
+
return (input, ast, options) => {
|
|
4652
|
+
if (!Exit_.isExit(input)) {
|
|
4653
|
+
return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
|
|
4654
|
+
}
|
|
4655
|
+
switch (input._tag) {
|
|
4656
|
+
case "Success":
|
|
4657
|
+
return Effect.mapBothEager(Parser.decodeUnknownEffect(value)(input.value, options), {
|
|
4658
|
+
onSuccess: Exit_.succeed,
|
|
4659
|
+
onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["value"], issue)])
|
|
4660
|
+
});
|
|
4661
|
+
case "Failure":
|
|
4662
|
+
return Effect.mapBothEager(Parser.decodeUnknownEffect(cause)(input.cause, options), {
|
|
4663
|
+
onSuccess: Exit_.failCause,
|
|
4664
|
+
onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["cause"], issue)])
|
|
4665
|
+
});
|
|
4666
|
+
}
|
|
4667
|
+
};
|
|
3479
4668
|
}, {
|
|
3480
4669
|
typeConstructor: {
|
|
3481
4670
|
_tag: "effect/Exit"
|
|
@@ -3544,90 +4733,252 @@ export function Exit(value, error, defect) {
|
|
|
3544
4733
|
* @since 4.0.0
|
|
3545
4734
|
*/
|
|
3546
4735
|
export function ReadonlyMap(key, value) {
|
|
3547
|
-
const schema = declareConstructor()([key, value], ([key, value]) =>
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
4736
|
+
const schema = declareConstructor()([key, value], ([key, value]) => {
|
|
4737
|
+
const array = ArraySchema(Tuple([key, value]));
|
|
4738
|
+
return (input, ast, options) => {
|
|
4739
|
+
if (input instanceof globalThis.Map) {
|
|
4740
|
+
return Effect.mapBothEager(Parser.decodeUnknownEffect(array)([...input], options), {
|
|
4741
|
+
onSuccess: array => new globalThis.Map(array),
|
|
4742
|
+
onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["entries"], issue)])
|
|
4743
|
+
});
|
|
4744
|
+
}
|
|
4745
|
+
return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
|
|
4746
|
+
};
|
|
4747
|
+
}, {
|
|
4748
|
+
typeConstructor: {
|
|
4749
|
+
_tag: "ReadonlyMap"
|
|
4750
|
+
},
|
|
4751
|
+
generation: {
|
|
4752
|
+
runtime: `Schema.ReadonlyMap(?, ?)`,
|
|
4753
|
+
Type: `globalThis.ReadonlyMap<?, ?>`
|
|
4754
|
+
},
|
|
4755
|
+
expected: "ReadonlyMap",
|
|
4756
|
+
toCodec: ([key, value]) => link()(ArraySchema(Tuple([key, value])), Transformation.transform({
|
|
4757
|
+
decode: e => new globalThis.Map(e),
|
|
4758
|
+
encode: map => [...map.entries()]
|
|
4759
|
+
})),
|
|
4760
|
+
toArbitrary: ([key, value]) => (fc, ctx) => {
|
|
4761
|
+
return fc.oneof(ctx?.isSuspend ? {
|
|
4762
|
+
maxDepth: 2,
|
|
4763
|
+
depthIdentifier: "ReadonlyMap"
|
|
4764
|
+
} : {}, fc.constant([]), fc.array(fc.tuple(key, value), ctx?.constraints?.array)).map(as => new globalThis.Map(as));
|
|
4765
|
+
},
|
|
4766
|
+
toEquivalence: ([key, value]) => Equal.makeCompareMap(key, value),
|
|
4767
|
+
toFormatter: ([key, value]) => t => {
|
|
4768
|
+
const size = t.size;
|
|
4769
|
+
if (size === 0) {
|
|
4770
|
+
return "ReadonlyMap(0) {}";
|
|
4771
|
+
}
|
|
4772
|
+
const entries = globalThis.Array.from(t.entries()).sort().map(([k, v]) => `${key(k)} => ${value(v)}`);
|
|
4773
|
+
return `ReadonlyMap(${size}) { ${entries.join(", ")} }`;
|
|
3554
4774
|
}
|
|
3555
|
-
|
|
4775
|
+
});
|
|
4776
|
+
return make(schema.ast, {
|
|
4777
|
+
key,
|
|
4778
|
+
value
|
|
4779
|
+
});
|
|
4780
|
+
}
|
|
4781
|
+
/**
|
|
4782
|
+
* Creates a schema that validates a `HashMap` where keys and values must
|
|
4783
|
+
* conform to the provided schemas.
|
|
4784
|
+
*
|
|
4785
|
+
* @category HashMap
|
|
4786
|
+
* @since 4.0.0
|
|
4787
|
+
*/
|
|
4788
|
+
export function HashMap(key, value) {
|
|
4789
|
+
const schema = declareConstructor()([key, value], ([key, value]) => {
|
|
4790
|
+
const entries = ArraySchema(Tuple([key, value]));
|
|
4791
|
+
return (input, ast, options) => {
|
|
4792
|
+
if (HashMap_.isHashMap(input)) {
|
|
4793
|
+
return Effect.mapBothEager(Parser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options), {
|
|
4794
|
+
onSuccess: HashMap_.fromIterable,
|
|
4795
|
+
onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["entries"], issue)])
|
|
4796
|
+
});
|
|
4797
|
+
}
|
|
4798
|
+
return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
|
|
4799
|
+
};
|
|
4800
|
+
}, {
|
|
4801
|
+
typeConstructor: {
|
|
4802
|
+
_tag: "effect/HashMap"
|
|
4803
|
+
},
|
|
4804
|
+
generation: {
|
|
4805
|
+
runtime: `Schema.HashMap(?, ?)`,
|
|
4806
|
+
Type: `HashMap.HashMap<?, ?>`,
|
|
4807
|
+
importDeclaration: `import * as HashMap from "effect/HashMap"`
|
|
4808
|
+
},
|
|
4809
|
+
expected: "HashMap",
|
|
4810
|
+
toCodec: ([key, value]) => link()(ArraySchema(Tuple([key, value])), Transformation.transform({
|
|
4811
|
+
decode: HashMap_.fromIterable,
|
|
4812
|
+
encode: HashMap_.toEntries
|
|
4813
|
+
})),
|
|
4814
|
+
toArbitrary: ([key, value]) => (fc, ctx) => {
|
|
4815
|
+
return fc.oneof(ctx?.isSuspend ? {
|
|
4816
|
+
maxDepth: 2,
|
|
4817
|
+
depthIdentifier: "HashMap"
|
|
4818
|
+
} : {}, fc.constant([]), fc.array(fc.tuple(key, value), ctx?.constraints?.array)).map(HashMap_.fromIterable);
|
|
4819
|
+
},
|
|
4820
|
+
toEquivalence: ([key, value]) => Equal.makeCompareMap(key, value),
|
|
4821
|
+
toFormatter: ([key, value]) => t => {
|
|
4822
|
+
const size = HashMap_.size(t);
|
|
4823
|
+
if (size === 0) {
|
|
4824
|
+
return "HashMap(0) {}";
|
|
4825
|
+
}
|
|
4826
|
+
const entries = HashMap_.toEntries(t).sort().map(([k, v]) => `${key(k)} => ${value(v)}`);
|
|
4827
|
+
return `HashMap(${size}) { ${entries.join(", ")} }`;
|
|
4828
|
+
}
|
|
4829
|
+
});
|
|
4830
|
+
return make(schema.ast, {
|
|
4831
|
+
key,
|
|
4832
|
+
value
|
|
4833
|
+
});
|
|
4834
|
+
}
|
|
4835
|
+
/**
|
|
4836
|
+
* @category ReadonlySet
|
|
4837
|
+
* @since 4.0.0
|
|
4838
|
+
*/
|
|
4839
|
+
export function ReadonlySet(value) {
|
|
4840
|
+
const schema = declareConstructor()([value], ([value]) => {
|
|
4841
|
+
const array = ArraySchema(value);
|
|
4842
|
+
return (input, ast, options) => {
|
|
4843
|
+
if (input instanceof globalThis.Set) {
|
|
4844
|
+
return Effect.mapBothEager(Parser.decodeUnknownEffect(array)([...input], options), {
|
|
4845
|
+
onSuccess: array => new globalThis.Set(array),
|
|
4846
|
+
onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["values"], issue)])
|
|
4847
|
+
});
|
|
4848
|
+
}
|
|
4849
|
+
return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
|
|
4850
|
+
};
|
|
4851
|
+
}, {
|
|
4852
|
+
typeConstructor: {
|
|
4853
|
+
_tag: "ReadonlySet"
|
|
4854
|
+
},
|
|
4855
|
+
generation: {
|
|
4856
|
+
runtime: `Schema.ReadonlySet(?)`,
|
|
4857
|
+
Type: `globalThis.ReadonlySet<?>`
|
|
4858
|
+
},
|
|
4859
|
+
expected: "ReadonlySet",
|
|
4860
|
+
toCodec: ([value]) => link()(ArraySchema(value), Transformation.transform({
|
|
4861
|
+
decode: e => new globalThis.Set(e),
|
|
4862
|
+
encode: set => [...set.values()]
|
|
4863
|
+
})),
|
|
4864
|
+
toArbitrary: ([value]) => (fc, ctx) => {
|
|
4865
|
+
return fc.oneof(ctx?.isSuspend ? {
|
|
4866
|
+
maxDepth: 2,
|
|
4867
|
+
depthIdentifier: "ReadonlySet"
|
|
4868
|
+
} : {}, fc.constant([]), fc.array(value, ctx?.constraints?.array)).map(as => new globalThis.Set(as));
|
|
4869
|
+
},
|
|
4870
|
+
toEquivalence: ([value]) => Equal.makeCompareSet(value),
|
|
4871
|
+
toFormatter: ([value]) => t => {
|
|
4872
|
+
const size = t.size;
|
|
4873
|
+
if (size === 0) {
|
|
4874
|
+
return "ReadonlySet(0) {}";
|
|
4875
|
+
}
|
|
4876
|
+
const values = globalThis.Array.from(t.values()).sort().map(v => `${value(v)}`);
|
|
4877
|
+
return `ReadonlySet(${size}) { ${values.join(", ")} }`;
|
|
4878
|
+
}
|
|
4879
|
+
});
|
|
4880
|
+
return make(schema.ast, {
|
|
4881
|
+
value
|
|
4882
|
+
});
|
|
4883
|
+
}
|
|
4884
|
+
/**
|
|
4885
|
+
* Creates a schema that validates a `HashSet` where values must conform to the
|
|
4886
|
+
* provided schema.
|
|
4887
|
+
*
|
|
4888
|
+
* @category HashSet
|
|
4889
|
+
* @since 4.0.0
|
|
4890
|
+
*/
|
|
4891
|
+
export function HashSet(value) {
|
|
4892
|
+
const schema = declareConstructor()([value], ([value]) => {
|
|
4893
|
+
const values = ArraySchema(value);
|
|
4894
|
+
return (input, ast, options) => {
|
|
4895
|
+
if (HashSet_.isHashSet(input)) {
|
|
4896
|
+
return Effect.mapBothEager(Parser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
|
|
4897
|
+
onSuccess: HashSet_.fromIterable,
|
|
4898
|
+
onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["values"], issue)])
|
|
4899
|
+
});
|
|
4900
|
+
}
|
|
4901
|
+
return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
|
|
4902
|
+
};
|
|
3556
4903
|
}, {
|
|
3557
4904
|
typeConstructor: {
|
|
3558
|
-
_tag: "
|
|
4905
|
+
_tag: "effect/HashSet"
|
|
3559
4906
|
},
|
|
3560
4907
|
generation: {
|
|
3561
|
-
runtime: `Schema.
|
|
3562
|
-
Type: `
|
|
4908
|
+
runtime: `Schema.HashSet(?)`,
|
|
4909
|
+
Type: `HashSet.HashSet<?>`
|
|
3563
4910
|
},
|
|
3564
|
-
expected: "
|
|
3565
|
-
toCodec: ([
|
|
3566
|
-
decode:
|
|
3567
|
-
encode:
|
|
4911
|
+
expected: "HashSet",
|
|
4912
|
+
toCodec: ([value]) => link()(ArraySchema(value), Transformation.transform({
|
|
4913
|
+
decode: HashSet_.fromIterable,
|
|
4914
|
+
encode: Arr.fromIterable
|
|
3568
4915
|
})),
|
|
3569
|
-
toArbitrary: ([
|
|
4916
|
+
toArbitrary: ([value]) => (fc, ctx) => {
|
|
3570
4917
|
return fc.oneof(ctx?.isSuspend ? {
|
|
3571
4918
|
maxDepth: 2,
|
|
3572
|
-
depthIdentifier: "
|
|
3573
|
-
} : {}, fc.constant([]), fc.array(
|
|
4919
|
+
depthIdentifier: "HashSet"
|
|
4920
|
+
} : {}, fc.constant([]), fc.array(value, ctx?.constraints?.array)).map(HashSet_.fromIterable);
|
|
3574
4921
|
},
|
|
3575
|
-
toEquivalence: ([
|
|
3576
|
-
toFormatter: ([
|
|
3577
|
-
const size =
|
|
4922
|
+
toEquivalence: ([value]) => Equal.makeCompareSet(value),
|
|
4923
|
+
toFormatter: ([value]) => t => {
|
|
4924
|
+
const size = HashSet_.size(t);
|
|
3578
4925
|
if (size === 0) {
|
|
3579
|
-
return "
|
|
4926
|
+
return "HashSet(0) {}";
|
|
3580
4927
|
}
|
|
3581
|
-
const
|
|
3582
|
-
return `
|
|
4928
|
+
const values = globalThis.Array.from(t).sort().map(v => `${value(v)}`);
|
|
4929
|
+
return `HashSet(${size}) { ${values.join(", ")} }`;
|
|
3583
4930
|
}
|
|
3584
4931
|
});
|
|
3585
4932
|
return make(schema.ast, {
|
|
3586
|
-
key,
|
|
3587
4933
|
value
|
|
3588
4934
|
});
|
|
3589
4935
|
}
|
|
3590
4936
|
/**
|
|
3591
|
-
*
|
|
4937
|
+
* Creates a schema that validates a `Chunk` where values must conform to the
|
|
4938
|
+
* provided schema.
|
|
4939
|
+
*
|
|
4940
|
+
* @category Chunk
|
|
3592
4941
|
* @since 4.0.0
|
|
3593
4942
|
*/
|
|
3594
|
-
export function
|
|
3595
|
-
const schema = declareConstructor()([value], ([value]) =>
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
4943
|
+
export function Chunk(value) {
|
|
4944
|
+
const schema = declareConstructor()([value], ([value]) => {
|
|
4945
|
+
const values = ArraySchema(value);
|
|
4946
|
+
return (input, ast, options) => {
|
|
4947
|
+
if (Chunk_.isChunk(input)) {
|
|
4948
|
+
return Effect.mapBothEager(Parser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
|
|
4949
|
+
onSuccess: Chunk_.fromIterable,
|
|
4950
|
+
onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["values"], issue)])
|
|
4951
|
+
});
|
|
4952
|
+
}
|
|
4953
|
+
return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
|
|
4954
|
+
};
|
|
3604
4955
|
}, {
|
|
3605
4956
|
typeConstructor: {
|
|
3606
|
-
_tag: "
|
|
4957
|
+
_tag: "effect/Chunk"
|
|
3607
4958
|
},
|
|
3608
4959
|
generation: {
|
|
3609
|
-
runtime: `Schema.
|
|
3610
|
-
Type: `
|
|
4960
|
+
runtime: `Schema.Chunk(?)`,
|
|
4961
|
+
Type: `Chunk.Chunk<?>`
|
|
3611
4962
|
},
|
|
3612
|
-
expected: "
|
|
3613
|
-
toCodec: ([value]) => link()(
|
|
3614
|
-
decode:
|
|
3615
|
-
encode:
|
|
4963
|
+
expected: "Chunk",
|
|
4964
|
+
toCodec: ([value]) => link()(ArraySchema(value), Transformation.transform({
|
|
4965
|
+
decode: Chunk_.fromIterable,
|
|
4966
|
+
encode: Arr.fromIterable
|
|
3616
4967
|
})),
|
|
3617
4968
|
toArbitrary: ([value]) => (fc, ctx) => {
|
|
3618
4969
|
return fc.oneof(ctx?.isSuspend ? {
|
|
3619
4970
|
maxDepth: 2,
|
|
3620
|
-
depthIdentifier: "
|
|
3621
|
-
} : {}, fc.constant([]), fc.array(value, ctx?.constraints?.array)).map(
|
|
4971
|
+
depthIdentifier: "Chunk"
|
|
4972
|
+
} : {}, fc.constant([]), fc.array(value, ctx?.constraints?.array)).map(Chunk_.fromIterable);
|
|
3622
4973
|
},
|
|
3623
|
-
toEquivalence: ([value]) =>
|
|
4974
|
+
toEquivalence: ([value]) => Chunk_.makeEquivalence(value),
|
|
3624
4975
|
toFormatter: ([value]) => t => {
|
|
3625
|
-
const size =
|
|
4976
|
+
const size = Chunk_.size(t);
|
|
3626
4977
|
if (size === 0) {
|
|
3627
|
-
return "
|
|
4978
|
+
return "Chunk(0) {}";
|
|
3628
4979
|
}
|
|
3629
|
-
const values = globalThis.Array.from(t
|
|
3630
|
-
return `
|
|
4980
|
+
const values = globalThis.Array.from(t).sort().map(v => `${value(v)}`);
|
|
4981
|
+
return `Chunk(${size}) { ${values.join(", ")} }`;
|
|
3631
4982
|
}
|
|
3632
4983
|
});
|
|
3633
4984
|
return make(schema.ast, {
|
|
@@ -3635,6 +4986,11 @@ export function ReadonlySet(value) {
|
|
|
3635
4986
|
});
|
|
3636
4987
|
}
|
|
3637
4988
|
/**
|
|
4989
|
+
* Schema for JavaScript `RegExp` objects.
|
|
4990
|
+
*
|
|
4991
|
+
* The default JSON serializer encodes a `RegExp` as `{ source, flags }`.
|
|
4992
|
+
*
|
|
4993
|
+
* @category Schemas
|
|
3638
4994
|
* @since 4.0.0
|
|
3639
4995
|
*/
|
|
3640
4996
|
export const RegExp = /*#__PURE__*/instanceOf(globalThis.RegExp, {
|
|
@@ -3712,8 +5068,19 @@ export const URLFromString = /*#__PURE__*/String.annotate({
|
|
|
3712
5068
|
* A schema for JavaScript `Date` objects.
|
|
3713
5069
|
*
|
|
3714
5070
|
* This schema accepts any `Date` instance, including invalid dates (e.g., `new
|
|
3715
|
-
* Date("invalid")`). For validating only valid dates, use
|
|
5071
|
+
* Date("invalid")`). For validating only valid dates, use {@link DateValid}
|
|
5072
|
+
* instead. The default JSON serializer encodes `Date` as an ISO 8601 string.
|
|
5073
|
+
*
|
|
5074
|
+
* **Example** (Date schema)
|
|
5075
|
+
*
|
|
5076
|
+
* ```ts
|
|
5077
|
+
* import { Schema } from "effect"
|
|
5078
|
+
*
|
|
5079
|
+
* Schema.decodeUnknownSync(Schema.Date)(new Date("2024-01-01"))
|
|
5080
|
+
* // => Date { 2024-01-01T00:00:00.000Z }
|
|
5081
|
+
* ```
|
|
3716
5082
|
*
|
|
5083
|
+
* @category Schemas
|
|
3717
5084
|
* @since 4.0.0
|
|
3718
5085
|
*/
|
|
3719
5086
|
export const Date = /*#__PURE__*/instanceOf(globalThis.Date, {
|
|
@@ -3745,9 +5112,20 @@ export const DateValid = /*#__PURE__*/Date.check(/*#__PURE__*/isDateValid());
|
|
|
3745
5112
|
/**
|
|
3746
5113
|
* A schema for `Duration` values.
|
|
3747
5114
|
*
|
|
3748
|
-
*
|
|
5115
|
+
* The default JSON serializer encodes `Duration` as a tagged object with the
|
|
5116
|
+
* duration type and value.
|
|
5117
|
+
*
|
|
5118
|
+
* **Example** (Duration schema)
|
|
5119
|
+
*
|
|
5120
|
+
* ```ts
|
|
5121
|
+
* import { Schema } from "effect"
|
|
5122
|
+
* import { Duration } from "effect"
|
|
5123
|
+
*
|
|
5124
|
+
* Schema.decodeUnknownSync(Schema.Duration)(Duration.seconds(5))
|
|
5125
|
+
* // => Duration(5s)
|
|
5126
|
+
* ```
|
|
3749
5127
|
*
|
|
3750
|
-
*
|
|
5128
|
+
* @category Duration
|
|
3751
5129
|
*
|
|
3752
5130
|
* @since 4.0.0
|
|
3753
5131
|
*/
|
|
@@ -3842,6 +5220,35 @@ export const DurationFromNanos = /*#__PURE__*/BigInt.check(isGreaterThanOrEqualT
|
|
|
3842
5220
|
* @since 4.0.0
|
|
3843
5221
|
*/
|
|
3844
5222
|
export const DurationFromMillis = /*#__PURE__*/Number.check(isGreaterThanOrEqualTo(0)).pipe(/*#__PURE__*/decodeTo(Duration, Transformation.durationFromMillis));
|
|
5223
|
+
/**
|
|
5224
|
+
* A schema for `BigDecimal` values.
|
|
5225
|
+
*
|
|
5226
|
+
* **Default JSON serializer**
|
|
5227
|
+
*
|
|
5228
|
+
* - encodes `BigDecimal` as a `string`
|
|
5229
|
+
*
|
|
5230
|
+
* @since 4.0.0
|
|
5231
|
+
*/
|
|
5232
|
+
export const BigDecimal = /*#__PURE__*/declare(BigDecimal_.isBigDecimal, {
|
|
5233
|
+
typeConstructor: {
|
|
5234
|
+
_tag: "effect/BigDecimal"
|
|
5235
|
+
},
|
|
5236
|
+
generation: {
|
|
5237
|
+
runtime: `Schema.BigDecimal`,
|
|
5238
|
+
Type: `BigDecimal.BigDecimal`,
|
|
5239
|
+
importDeclaration: `import * as BigDecimal from "effect/BigDecimal"`
|
|
5240
|
+
},
|
|
5241
|
+
expected: "BigDecimal",
|
|
5242
|
+
toCodecJson: () => link()(String.annotate({
|
|
5243
|
+
expected: "a string that will be decoded as a BigDecimal"
|
|
5244
|
+
}), Transformation.bigDecimalFromString),
|
|
5245
|
+
toArbitrary: () => fc => fc.tuple(fc.bigInt(), fc.integer({
|
|
5246
|
+
min: 0,
|
|
5247
|
+
max: 20
|
|
5248
|
+
})).map(([value, scale]) => BigDecimal_.make(value, scale)),
|
|
5249
|
+
toFormatter: () => bd => BigDecimal_.format(bd),
|
|
5250
|
+
toEquivalence: () => BigDecimal_.Equivalence
|
|
5251
|
+
});
|
|
3845
5252
|
/**
|
|
3846
5253
|
* A transformation schema that decodes a JSON-encoded string into an `unknown` value.
|
|
3847
5254
|
*
|
|
@@ -3936,6 +5343,12 @@ export function fromJsonString(schema) {
|
|
|
3936
5343
|
}).pipe(decodeTo(schema, Transformation.fromJsonString));
|
|
3937
5344
|
}
|
|
3938
5345
|
/**
|
|
5346
|
+
* Schema for JavaScript `File` objects.
|
|
5347
|
+
*
|
|
5348
|
+
* The default JSON serializer encodes a `File` as `{ data, type, name, lastModified }`
|
|
5349
|
+
* where `data` is base64-encoded.
|
|
5350
|
+
*
|
|
5351
|
+
* @category Schemas
|
|
3939
5352
|
* @since 4.0.0
|
|
3940
5353
|
*/
|
|
3941
5354
|
export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
@@ -3953,7 +5366,7 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
|
3953
5366
|
name: String,
|
|
3954
5367
|
lastModified: Number
|
|
3955
5368
|
}), Transformation.transformOrFail({
|
|
3956
|
-
decode: e => Result_.match(
|
|
5369
|
+
decode: e => Result_.match(Encoding.decodeBase64(e.data), {
|
|
3957
5370
|
onFailure: error => Effect.fail(new Issue.InvalidValue(Option_.some(e.data), {
|
|
3958
5371
|
message: error.message
|
|
3959
5372
|
})),
|
|
@@ -3969,7 +5382,7 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
|
3969
5382
|
try: async () => {
|
|
3970
5383
|
const bytes = new globalThis.Uint8Array(await file.arrayBuffer());
|
|
3971
5384
|
return {
|
|
3972
|
-
data:
|
|
5385
|
+
data: Encoding.encodeBase64(bytes),
|
|
3973
5386
|
type: file.type,
|
|
3974
5387
|
name: file.name,
|
|
3975
5388
|
lastModified: file.lastModified
|
|
@@ -3982,6 +5395,12 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
|
3982
5395
|
}))
|
|
3983
5396
|
});
|
|
3984
5397
|
/**
|
|
5398
|
+
* Schema for JavaScript `FormData` objects.
|
|
5399
|
+
*
|
|
5400
|
+
* The default JSON serializer encodes a `FormData` as an array of `[key, entry]`
|
|
5401
|
+
* pairs where each entry is tagged as `"String"` or `"File"`.
|
|
5402
|
+
*
|
|
5403
|
+
* @category Schemas
|
|
3985
5404
|
* @since 4.0.0
|
|
3986
5405
|
*/
|
|
3987
5406
|
export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
|
|
@@ -3993,7 +5412,7 @@ export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
|
|
|
3993
5412
|
Type: `globalThis.FormData`
|
|
3994
5413
|
},
|
|
3995
5414
|
expected: "FormData",
|
|
3996
|
-
toCodecJson: () => link()(
|
|
5415
|
+
toCodecJson: () => link()(ArraySchema(Tuple([String, Union([Struct({
|
|
3997
5416
|
_tag: tag("String"),
|
|
3998
5417
|
value: String
|
|
3999
5418
|
}), Struct({
|
|
@@ -4111,6 +5530,11 @@ export function fromFormData(schema) {
|
|
|
4111
5530
|
return FormData.pipe(decodeTo(schema, Transformation.fromFormData));
|
|
4112
5531
|
}
|
|
4113
5532
|
/**
|
|
5533
|
+
* Schema for JavaScript `URLSearchParams` objects.
|
|
5534
|
+
*
|
|
5535
|
+
* The default JSON serializer encodes a `URLSearchParams` as a query string.
|
|
5536
|
+
*
|
|
5537
|
+
* @category Schemas
|
|
4114
5538
|
* @since 4.0.0
|
|
4115
5539
|
*/
|
|
4116
5540
|
export const URLSearchParams = /*#__PURE__*/instanceOf(globalThis.URLSearchParams, {
|
|
@@ -4268,6 +5692,9 @@ export const Trim = /*#__PURE__*/String.annotate({
|
|
|
4268
5692
|
expected: "a string that will be decoded as a trimmed string"
|
|
4269
5693
|
}).pipe(/*#__PURE__*/decodeTo(Trimmed, /*#__PURE__*/Transformation.trim()));
|
|
4270
5694
|
/**
|
|
5695
|
+
* A union schema for JavaScript property keys: `number | symbol | string`.
|
|
5696
|
+
*
|
|
5697
|
+
* @category Schemas
|
|
4271
5698
|
* @since 4.0.0
|
|
4272
5699
|
*/
|
|
4273
5700
|
export const PropertyKey = /*#__PURE__*/Union([Finite, Symbol, String]);
|
|
@@ -4275,9 +5702,9 @@ export const PropertyKey = /*#__PURE__*/Union([Finite, Symbol, String]);
|
|
|
4275
5702
|
* @since 4.0.0
|
|
4276
5703
|
*/
|
|
4277
5704
|
export const StandardSchemaV1FailureResult = /*#__PURE__*/Struct({
|
|
4278
|
-
issues: /*#__PURE__*/
|
|
5705
|
+
issues: /*#__PURE__*/ArraySchema(/*#__PURE__*/Struct({
|
|
4279
5706
|
message: String,
|
|
4280
|
-
path: /*#__PURE__*/optional(/*#__PURE__*/
|
|
5707
|
+
path: /*#__PURE__*/optional(/*#__PURE__*/ArraySchema(/*#__PURE__*/Union([PropertyKey, /*#__PURE__*/Struct({
|
|
4281
5708
|
key: PropertyKey
|
|
4282
5709
|
})])))
|
|
4283
5710
|
}))
|
|
@@ -4383,7 +5810,7 @@ export const Uint8ArrayFromHex = /*#__PURE__*/String.annotate({
|
|
|
4383
5810
|
*/
|
|
4384
5811
|
export const DateTimeUtc = /*#__PURE__*/declare(u => DateTime.isDateTime(u) && DateTime.isUtc(u), {
|
|
4385
5812
|
typeConstructor: {
|
|
4386
|
-
_tag: "DateTime.Utc"
|
|
5813
|
+
_tag: "effect/DateTime.Utc"
|
|
4387
5814
|
},
|
|
4388
5815
|
generation: {
|
|
4389
5816
|
runtime: `Schema.DateTimeUtc`,
|
|
@@ -4391,10 +5818,7 @@ export const DateTimeUtc = /*#__PURE__*/declare(u => DateTime.isDateTime(u) && D
|
|
|
4391
5818
|
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
4392
5819
|
},
|
|
4393
5820
|
expected: "DateTime.Utc",
|
|
4394
|
-
toCodecJson: () => link()(String,
|
|
4395
|
-
decode: Getter.dateTimeUtcFromInput(),
|
|
4396
|
-
encode: Getter.transform(DateTime.formatIso)
|
|
4397
|
-
}),
|
|
5821
|
+
toCodecJson: () => link()(String, Transformation.dateTimeUtcFromString),
|
|
4398
5822
|
toArbitrary: () => (fc, ctx) => fc.date({
|
|
4399
5823
|
noInvalidDate: true,
|
|
4400
5824
|
...ctx?.constraints?.date
|
|
@@ -4434,10 +5858,7 @@ export const DateTimeUtcFromDate = /*#__PURE__*/DateValid.pipe(/*#__PURE__*/deco
|
|
|
4434
5858
|
*/
|
|
4435
5859
|
export const DateTimeUtcFromString = /*#__PURE__*/String.annotate({
|
|
4436
5860
|
expected: "a string that will be decoded as a DateTime.Utc"
|
|
4437
|
-
}).pipe(/*#__PURE__*/decodeTo(DateTimeUtc,
|
|
4438
|
-
decode: DateTime.makeUnsafe,
|
|
4439
|
-
encode: DateTime.formatIso
|
|
4440
|
-
})));
|
|
5861
|
+
}).pipe(/*#__PURE__*/decodeTo(DateTimeUtc, Transformation.dateTimeUtcFromString));
|
|
4441
5862
|
/**
|
|
4442
5863
|
* A transformation schema that decodes a number into a `DateTime.Utc`.
|
|
4443
5864
|
*
|
|
@@ -4454,24 +5875,142 @@ export const DateTimeUtcFromMillis = /*#__PURE__*/Number.pipe(/*#__PURE__*/decod
|
|
|
4454
5875
|
decode: /*#__PURE__*/Getter.dateTimeUtcFromInput(),
|
|
4455
5876
|
encode: /*#__PURE__*/Getter.transform(DateTime.toEpochMillis)
|
|
4456
5877
|
}));
|
|
5878
|
+
/**
|
|
5879
|
+
* A schema for `DateTime.TimeZone.Offset` values.
|
|
5880
|
+
*
|
|
5881
|
+
* **Default JSON serializer**
|
|
5882
|
+
*
|
|
5883
|
+
* - encodes `DateTime.TimeZone.Offset` as a number (offset in milliseconds)
|
|
5884
|
+
*
|
|
5885
|
+
* @category DateTime
|
|
5886
|
+
* @since 4.0.0
|
|
5887
|
+
*/
|
|
5888
|
+
export const TimeZoneOffset = /*#__PURE__*/declare(DateTime.isTimeZoneOffset, {
|
|
5889
|
+
typeConstructor: {
|
|
5890
|
+
_tag: "effect/DateTime.TimeZone.Offset"
|
|
5891
|
+
},
|
|
5892
|
+
generation: {
|
|
5893
|
+
runtime: `Schema.TimeZoneOffset`,
|
|
5894
|
+
Type: `DateTime.TimeZone.Offset`,
|
|
5895
|
+
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
5896
|
+
},
|
|
5897
|
+
expected: "DateTime.TimeZone.Offset",
|
|
5898
|
+
toCodecJson: () => link()(Number, Transformation.timeZoneOffsetFromNumber),
|
|
5899
|
+
toArbitrary: () => fc => fc.integer({
|
|
5900
|
+
min: -12 * 60 * 60 * 1000,
|
|
5901
|
+
max: 14 * 60 * 60 * 1000
|
|
5902
|
+
}).map(n => DateTime.zoneMakeOffset(n)),
|
|
5903
|
+
toFormatter: () => tz => DateTime.zoneToString(tz),
|
|
5904
|
+
toEquivalence: () => (a, b) => a.offset === b.offset
|
|
5905
|
+
});
|
|
5906
|
+
/**
|
|
5907
|
+
* A schema for `DateTime.TimeZone.Named` values.
|
|
5908
|
+
*
|
|
5909
|
+
* **Default JSON serializer**
|
|
5910
|
+
*
|
|
5911
|
+
* - encodes `DateTime.TimeZone.Named` as a string (IANA time zone identifier)
|
|
5912
|
+
*
|
|
5913
|
+
* @category DateTime
|
|
5914
|
+
* @since 4.0.0
|
|
5915
|
+
*/
|
|
5916
|
+
export const TimeZoneNamed = /*#__PURE__*/declare(DateTime.isTimeZoneNamed, {
|
|
5917
|
+
typeConstructor: {
|
|
5918
|
+
_tag: "effect/DateTime.TimeZone.Named"
|
|
5919
|
+
},
|
|
5920
|
+
generation: {
|
|
5921
|
+
runtime: `Schema.TimeZoneNamed`,
|
|
5922
|
+
Type: `DateTime.TimeZone.Named`,
|
|
5923
|
+
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
5924
|
+
},
|
|
5925
|
+
expected: "DateTime.TimeZone.Named",
|
|
5926
|
+
toCodecJson: () => link()(String.annotate({
|
|
5927
|
+
expected: "an IANA time zone identifier"
|
|
5928
|
+
}), Transformation.timeZoneNamedFromString),
|
|
5929
|
+
toArbitrary: () => fc => fc.constantFrom(...["UTC", "Europe/London", "America/New_York", "Asia/Tokyo", "Australia/Sydney"].map(DateTime.zoneMakeNamedUnsafe)),
|
|
5930
|
+
toFormatter: () => tz => DateTime.zoneToString(tz),
|
|
5931
|
+
toEquivalence: () => (a, b) => a.id === b.id
|
|
5932
|
+
});
|
|
5933
|
+
/**
|
|
5934
|
+
* A schema for `DateTime.TimeZone` values.
|
|
5935
|
+
*
|
|
5936
|
+
* **Default JSON serializer**
|
|
5937
|
+
*
|
|
5938
|
+
* - encodes `DateTime.TimeZone` as a string (IANA identifier or offset like
|
|
5939
|
+
* `+03:00`)
|
|
5940
|
+
*
|
|
5941
|
+
* @category DateTime
|
|
5942
|
+
* @since 4.0.0
|
|
5943
|
+
*/
|
|
5944
|
+
export const TimeZone = /*#__PURE__*/declare(DateTime.isTimeZone, {
|
|
5945
|
+
typeConstructor: {
|
|
5946
|
+
_tag: "effect/DateTime.TimeZone"
|
|
5947
|
+
},
|
|
5948
|
+
generation: {
|
|
5949
|
+
runtime: `Schema.TimeZone`,
|
|
5950
|
+
Type: `DateTime.TimeZone`,
|
|
5951
|
+
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
5952
|
+
},
|
|
5953
|
+
expected: "DateTime.TimeZone",
|
|
5954
|
+
toCodecJson: () => link()(String.annotate({
|
|
5955
|
+
expected: "a time zone string (IANA identifier or offset like +03:00)"
|
|
5956
|
+
}), Transformation.timeZoneFromString),
|
|
5957
|
+
toArbitrary: () => fc => fc.oneof(fc.integer({
|
|
5958
|
+
min: -12 * 60 * 60 * 1000,
|
|
5959
|
+
max: 14 * 60 * 60 * 1000
|
|
5960
|
+
}).map(n => DateTime.zoneMakeOffset(n)), fc.constantFrom(...["UTC", "Europe/London", "America/New_York", "Asia/Tokyo", "Australia/Sydney"].map(DateTime.zoneMakeNamedUnsafe))),
|
|
5961
|
+
toFormatter: () => tz => DateTime.zoneToString(tz),
|
|
5962
|
+
toEquivalence: () => (a, b) => DateTime.zoneToString(a) === DateTime.zoneToString(b)
|
|
5963
|
+
});
|
|
5964
|
+
/**
|
|
5965
|
+
* A schema for `DateTime.Zoned` values.
|
|
5966
|
+
*
|
|
5967
|
+
* **Default JSON serializer**
|
|
5968
|
+
*
|
|
5969
|
+
* - encodes `DateTime.Zoned` as a string in the format
|
|
5970
|
+
* `YYYY-MM-DDTHH:mm:ss.sss+HH:MM[Time/Zone]`
|
|
5971
|
+
*
|
|
5972
|
+
* @category DateTime
|
|
5973
|
+
* @since 4.0.0
|
|
5974
|
+
*/
|
|
5975
|
+
export const DateTimeZoned = /*#__PURE__*/declare(u => DateTime.isDateTime(u) && DateTime.isZoned(u), {
|
|
5976
|
+
typeConstructor: {
|
|
5977
|
+
_tag: "effect/DateTime.Zoned"
|
|
5978
|
+
},
|
|
5979
|
+
generation: {
|
|
5980
|
+
runtime: `Schema.DateTimeZoned`,
|
|
5981
|
+
Type: `DateTime.Zoned`,
|
|
5982
|
+
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
5983
|
+
},
|
|
5984
|
+
expected: "DateTime.Zoned",
|
|
5985
|
+
toCodecJson: () => link()(String.annotate({
|
|
5986
|
+
expected: "a zoned DateTime string (e.g. 2024-01-01T00:00:00.000+00:00[Europe/London])"
|
|
5987
|
+
}), Transformation.dateTimeZonedFromString),
|
|
5988
|
+
toArbitrary: () => (fc, ctx) => fc.tuple(fc.date({
|
|
5989
|
+
noInvalidDate: true,
|
|
5990
|
+
min: new globalThis.Date(-8640000000000000 + 14 * 60 * 60 * 1000),
|
|
5991
|
+
max: new globalThis.Date(8640000000000000 - 14 * 60 * 60 * 1000),
|
|
5992
|
+
...ctx?.constraints?.date
|
|
5993
|
+
}), fc.constantFrom("UTC", "Europe/London", "America/New_York", "Asia/Tokyo", "Australia/Sydney")).map(([date, zone]) => DateTime.makeZonedUnsafe(date, {
|
|
5994
|
+
timeZone: zone
|
|
5995
|
+
})),
|
|
5996
|
+
toFormatter: () => zoned => DateTime.formatIsoZoned(zoned),
|
|
5997
|
+
toEquivalence: () => DateTime.Equivalence
|
|
5998
|
+
});
|
|
4457
5999
|
const immerable = /*#__PURE__*/globalThis.Symbol.for("immer-draftable");
|
|
4458
6000
|
function makeClass(Inherited, identifier, struct, annotations) {
|
|
4459
6001
|
const getClassSchema = getClassSchemaFactory(struct, identifier, annotations);
|
|
4460
6002
|
const ClassTypeId = getClassTypeId(identifier); // HMR support
|
|
4461
6003
|
return class extends Inherited {
|
|
4462
6004
|
constructor(...[input, options]) {
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
disableValidation: true
|
|
4473
|
-
});
|
|
4474
|
-
}
|
|
6005
|
+
const props = input ?? {};
|
|
6006
|
+
const validated = struct.makeUnsafe(props, options);
|
|
6007
|
+
super({
|
|
6008
|
+
...props,
|
|
6009
|
+
...validated
|
|
6010
|
+
}, {
|
|
6011
|
+
...options,
|
|
6012
|
+
disableChecks: true
|
|
6013
|
+
});
|
|
4475
6014
|
}
|
|
4476
6015
|
toString() {
|
|
4477
6016
|
return `${identifier}(${format({
|
|
@@ -4497,6 +6036,9 @@ function makeClass(Inherited, identifier, struct, annotations) {
|
|
|
4497
6036
|
static makeUnsafe(input, options) {
|
|
4498
6037
|
return new this(input, options);
|
|
4499
6038
|
}
|
|
6039
|
+
static makeOption(input, options) {
|
|
6040
|
+
return Parser.makeOption(getClassSchema(this))(input, options);
|
|
6041
|
+
}
|
|
4500
6042
|
static annotate(annotations) {
|
|
4501
6043
|
return this.rebuild(AST.annotate(this.ast, annotations));
|
|
4502
6044
|
}
|
|
@@ -4541,6 +6083,7 @@ function getClassSchemaFactory(from, identifier, annotations) {
|
|
|
4541
6083
|
toCodec: ([from]) => new AST.Link(from.ast, transformation),
|
|
4542
6084
|
toArbitrary: ([from]) => () => from.map(args => new self(args)),
|
|
4543
6085
|
toFormatter: ([from]) => t => `${self.identifier}(${from(t)})`,
|
|
6086
|
+
"~sentinels": AST.collectSentinels(from.ast),
|
|
4544
6087
|
...annotations
|
|
4545
6088
|
}));
|
|
4546
6089
|
memo = from.pipe(decodeTo(to, transformation));
|
|
@@ -4552,6 +6095,46 @@ function isStruct(schema) {
|
|
|
4552
6095
|
return isSchema(schema);
|
|
4553
6096
|
}
|
|
4554
6097
|
/**
|
|
6098
|
+
* Creates a schema-backed class whose constructor validates input against a
|
|
6099
|
+
* {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
|
|
6100
|
+
* input (unless `disableChecks` is set in the options).
|
|
6101
|
+
*
|
|
6102
|
+
* Pass the desired class type as the first type parameter. The second optional
|
|
6103
|
+
* type parameter can be used to add nominal brands.
|
|
6104
|
+
*
|
|
6105
|
+
* **Example** (Basic class)
|
|
6106
|
+
*
|
|
6107
|
+
* ```ts
|
|
6108
|
+
* import { Schema } from "effect"
|
|
6109
|
+
*
|
|
6110
|
+
* class Person extends Schema.Class<Person>("Person")({
|
|
6111
|
+
* name: Schema.String,
|
|
6112
|
+
* age: Schema.Number
|
|
6113
|
+
* }) {}
|
|
6114
|
+
*
|
|
6115
|
+
* const alice = new Person({ name: "Alice", age: 30 })
|
|
6116
|
+
* console.log(alice.name) // "Alice"
|
|
6117
|
+
* console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
|
|
6118
|
+
* ```
|
|
6119
|
+
*
|
|
6120
|
+
* **Example** (Extending a class)
|
|
6121
|
+
*
|
|
6122
|
+
* ```ts
|
|
6123
|
+
* import { Schema } from "effect"
|
|
6124
|
+
*
|
|
6125
|
+
* class Animal extends Schema.Class<Animal>("Animal")({
|
|
6126
|
+
* name: Schema.String
|
|
6127
|
+
* }) {}
|
|
6128
|
+
*
|
|
6129
|
+
* class Dog extends Animal.extend<Dog>("Dog")({
|
|
6130
|
+
* breed: Schema.String
|
|
6131
|
+
* }) {}
|
|
6132
|
+
*
|
|
6133
|
+
* const dog = new Dog({ name: "Rex", breed: "Labrador" })
|
|
6134
|
+
* console.log(dog.name) // "Rex"
|
|
6135
|
+
* console.log(dog.breed) // "Labrador"
|
|
6136
|
+
* ```
|
|
6137
|
+
*
|
|
4555
6138
|
* @category Constructors
|
|
4556
6139
|
* @since 4.0.0
|
|
4557
6140
|
*/
|
|
@@ -4560,6 +6143,27 @@ export const Class = identifier => (schema, annotations) => {
|
|
|
4560
6143
|
return makeClass(Data.Class, identifier, struct, annotations);
|
|
4561
6144
|
};
|
|
4562
6145
|
/**
|
|
6146
|
+
* Like {@link Class} but automatically adds a `_tag` literal field set to the
|
|
6147
|
+
* given `tag` value. This makes instances compatible with tagged union
|
|
6148
|
+
* discrimination patterns.
|
|
6149
|
+
*
|
|
6150
|
+
* The optional `identifier` parameter overrides the schema identifier;
|
|
6151
|
+
* it defaults to the `tag` value.
|
|
6152
|
+
*
|
|
6153
|
+
* **Example** (Tagged class)
|
|
6154
|
+
*
|
|
6155
|
+
* ```ts
|
|
6156
|
+
* import { Schema } from "effect"
|
|
6157
|
+
*
|
|
6158
|
+
* class Circle extends Schema.TaggedClass<Circle>()("Circle", {
|
|
6159
|
+
* radius: Schema.Number
|
|
6160
|
+
* }) {}
|
|
6161
|
+
*
|
|
6162
|
+
* const c = new Circle({ radius: 5 })
|
|
6163
|
+
* console.log(c._tag) // "Circle"
|
|
6164
|
+
* console.log(c.radius) // 5
|
|
6165
|
+
* ```
|
|
6166
|
+
*
|
|
4563
6167
|
* @category Constructors
|
|
4564
6168
|
* @since 4.0.0
|
|
4565
6169
|
*/
|
|
@@ -4574,14 +6178,53 @@ export const TaggedClass = identifier => {
|
|
|
4574
6178
|
};
|
|
4575
6179
|
};
|
|
4576
6180
|
/**
|
|
6181
|
+
* Creates a schema-backed error class that can be used as a typed,
|
|
6182
|
+
* yieldable error in Effect programs. Combines {@link Class} validation with
|
|
6183
|
+
* the `YieldableError` interface so instances can be yielded directly inside
|
|
6184
|
+
* `Effect.gen`.
|
|
6185
|
+
*
|
|
6186
|
+
* **Example** (Schema-backed error)
|
|
6187
|
+
*
|
|
6188
|
+
* ```ts
|
|
6189
|
+
* import { Effect, Schema } from "effect"
|
|
6190
|
+
*
|
|
6191
|
+
* class NotFound extends Schema.ErrorClass<NotFound>("NotFound")({
|
|
6192
|
+
* id: Schema.Number
|
|
6193
|
+
* }) {}
|
|
6194
|
+
*
|
|
6195
|
+
* const program = Effect.gen(function*() {
|
|
6196
|
+
* yield* new NotFound({ id: 1 })
|
|
6197
|
+
* })
|
|
6198
|
+
* ```
|
|
6199
|
+
*
|
|
4577
6200
|
* @category Constructors
|
|
4578
6201
|
* @since 4.0.0
|
|
4579
6202
|
*/
|
|
4580
6203
|
export const ErrorClass = identifier => (schema, annotations) => {
|
|
4581
6204
|
const struct = isStruct(schema) ? schema : Struct(schema);
|
|
4582
|
-
|
|
6205
|
+
const self = makeClass(core.Error, identifier, struct, annotations);
|
|
6206
|
+
self.prototype.name = identifier;
|
|
6207
|
+
return self;
|
|
4583
6208
|
};
|
|
4584
6209
|
/**
|
|
6210
|
+
* Like {@link ErrorClass} but automatically adds a `_tag` literal field. The
|
|
6211
|
+
* resulting class is both a schema-validated, yieldable error and a tagged
|
|
6212
|
+
* union member.
|
|
6213
|
+
*
|
|
6214
|
+
* **Example** (Tagged error class)
|
|
6215
|
+
*
|
|
6216
|
+
* ```ts
|
|
6217
|
+
* import { Effect, Schema } from "effect"
|
|
6218
|
+
*
|
|
6219
|
+
* class NotFound extends Schema.TaggedErrorClass<NotFound>()("NotFound", {
|
|
6220
|
+
* id: Schema.Number
|
|
6221
|
+
* }) {}
|
|
6222
|
+
*
|
|
6223
|
+
* const program = Effect.gen(function*() {
|
|
6224
|
+
* yield* new NotFound({ id: 42 })
|
|
6225
|
+
* })
|
|
6226
|
+
* ```
|
|
6227
|
+
*
|
|
4585
6228
|
* @category Constructors
|
|
4586
6229
|
* @since 4.0.0
|
|
4587
6230
|
*/
|
|
@@ -4596,6 +6239,11 @@ export const TaggedErrorClass = identifier => {
|
|
|
4596
6239
|
};
|
|
4597
6240
|
};
|
|
4598
6241
|
/**
|
|
6242
|
+
* Derives a {@link LazyArbitrary} from a schema. The result is memoized so
|
|
6243
|
+
* repeated calls with the same schema are cheap.
|
|
6244
|
+
*
|
|
6245
|
+
* Prefer {@link toArbitrary} when you just need the arbitrary directly.
|
|
6246
|
+
*
|
|
4599
6247
|
* @category Arbitrary
|
|
4600
6248
|
* @since 4.0.0
|
|
4601
6249
|
*/
|
|
@@ -4604,6 +6252,24 @@ export function toArbitraryLazy(schema) {
|
|
|
4604
6252
|
return fc => lawc(fc, {});
|
|
4605
6253
|
}
|
|
4606
6254
|
/**
|
|
6255
|
+
* Derives a `fast-check` `Arbitrary` from a schema for property-based
|
|
6256
|
+
* testing. The derived arbitrary generates values that satisfy the schema.
|
|
6257
|
+
*
|
|
6258
|
+
* **Example** (Generating arbitrary values)
|
|
6259
|
+
*
|
|
6260
|
+
* ```ts
|
|
6261
|
+
* import { Schema } from "effect"
|
|
6262
|
+
* import * as FastCheck from "fast-check"
|
|
6263
|
+
*
|
|
6264
|
+
* const PersonArb = Schema.toArbitrary(
|
|
6265
|
+
* Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
6266
|
+
* )
|
|
6267
|
+
*
|
|
6268
|
+
* // Sample a random value
|
|
6269
|
+
* const sample = FastCheck.sample(PersonArb, 1)[0]
|
|
6270
|
+
* console.log(typeof sample.name) // "string"
|
|
6271
|
+
* ```
|
|
6272
|
+
*
|
|
4607
6273
|
* @category Arbitrary
|
|
4608
6274
|
* @since 4.0.0
|
|
4609
6275
|
*/
|
|
@@ -4630,6 +6296,13 @@ export function overrideToFormatter(toFormatter) {
|
|
|
4630
6296
|
};
|
|
4631
6297
|
}
|
|
4632
6298
|
/**
|
|
6299
|
+
* Derives a string formatter function from a schema. The formatter converts
|
|
6300
|
+
* a value to its human-readable string representation, recursing into structs,
|
|
6301
|
+
* arrays, and unions.
|
|
6302
|
+
*
|
|
6303
|
+
* The optional `onBefore` hook lets you intercept specific AST nodes before
|
|
6304
|
+
* the default formatting logic runs.
|
|
6305
|
+
*
|
|
4633
6306
|
* @category Formatter
|
|
4634
6307
|
* @since 4.0.0
|
|
4635
6308
|
*/
|
|
@@ -4768,10 +6441,9 @@ export function toFormatter(schema, options) {
|
|
|
4768
6441
|
// Equivalence
|
|
4769
6442
|
// -----------------------------------------------------------------------------
|
|
4770
6443
|
/**
|
|
4771
|
-
*
|
|
4772
|
-
*
|
|
4773
|
-
*
|
|
4774
|
-
* the schema invariant.
|
|
6444
|
+
* Overrides the equivalence derivation for a schema by supplying a custom
|
|
6445
|
+
* `Equivalence`. Use this when the default structural equivalence derived by
|
|
6446
|
+
* {@link toEquivalence} is not appropriate for a type.
|
|
4775
6447
|
*
|
|
4776
6448
|
* @category Equivalence
|
|
4777
6449
|
* @since 4.0.0
|
|
@@ -4782,6 +6454,21 @@ export function overrideToEquivalence(toEquivalence) {
|
|
|
4782
6454
|
});
|
|
4783
6455
|
}
|
|
4784
6456
|
/**
|
|
6457
|
+
* Derives an `Equivalence` from a schema. Two values are considered equal when
|
|
6458
|
+
* every field (and nested field) compares equal according to the schema
|
|
6459
|
+
* structure.
|
|
6460
|
+
*
|
|
6461
|
+
* **Example** (Struct equivalence)
|
|
6462
|
+
*
|
|
6463
|
+
* ```ts
|
|
6464
|
+
* import { Schema } from "effect"
|
|
6465
|
+
*
|
|
6466
|
+
* const eq = Schema.toEquivalence(Schema.Struct({ id: Schema.Number, name: Schema.String }))
|
|
6467
|
+
*
|
|
6468
|
+
* console.log(eq({ id: 1, name: "Alice" }, { id: 1, name: "Alice" })) // true
|
|
6469
|
+
* console.log(eq({ id: 1, name: "Alice" }, { id: 2, name: "Alice" })) // false
|
|
6470
|
+
* ```
|
|
6471
|
+
*
|
|
4785
6472
|
* @category Equivalence
|
|
4786
6473
|
* @since 4.0.0
|
|
4787
6474
|
*/
|
|
@@ -4792,6 +6479,10 @@ export function toEquivalence(schema) {
|
|
|
4792
6479
|
// Representation
|
|
4793
6480
|
// -----------------------------------------------------------------------------
|
|
4794
6481
|
/**
|
|
6482
|
+
* Derives an intermediate `SchemaRepresentation.Document` from a schema. This
|
|
6483
|
+
* document is used internally by {@link toJsonSchemaDocument} and related
|
|
6484
|
+
* functions to produce JSON Schema output.
|
|
6485
|
+
*
|
|
4795
6486
|
* @category Representation
|
|
4796
6487
|
* @since 4.0.0
|
|
4797
6488
|
*/
|
|
@@ -4816,17 +6507,23 @@ export function toJsonSchemaDocument(schema, options) {
|
|
|
4816
6507
|
};
|
|
4817
6508
|
}
|
|
4818
6509
|
// -----------------------------------------------------------------------------
|
|
4819
|
-
//
|
|
6510
|
+
// Canonical Codecs
|
|
4820
6511
|
// -----------------------------------------------------------------------------
|
|
4821
6512
|
/**
|
|
4822
|
-
*
|
|
6513
|
+
* Derives a canonical JSON codec from a schema. The encoded form is `unknown`
|
|
6514
|
+
* (any JSON-compatible value), decoded to the schema's `Type`.
|
|
6515
|
+
*
|
|
6516
|
+
* @category Canonical Codecs
|
|
4823
6517
|
* @since 4.0.0
|
|
4824
6518
|
*/
|
|
4825
6519
|
export function toCodecJson(schema) {
|
|
4826
6520
|
return make(InternalToCodec.toCodecJson(schema.ast));
|
|
4827
6521
|
}
|
|
4828
6522
|
/**
|
|
4829
|
-
*
|
|
6523
|
+
* Derives an isomorphism codec from a schema. The encoded form is the
|
|
6524
|
+
* schema's `Iso` type — the intermediate representation used for round-tripping.
|
|
6525
|
+
*
|
|
6526
|
+
* @category Canonical Codecs
|
|
4830
6527
|
* @since 4.0.0
|
|
4831
6528
|
*/
|
|
4832
6529
|
export function toCodecIso(schema) {
|
|
@@ -4840,7 +6537,11 @@ export function toCodecStringTree(schema, options) {
|
|
|
4840
6537
|
}
|
|
4841
6538
|
}
|
|
4842
6539
|
/**
|
|
4843
|
-
*
|
|
6540
|
+
* Derives an XML encoder from a codec. Encodes a value to an XML string by
|
|
6541
|
+
* first converting it through {@link toCodecStringTree}, then serializing the
|
|
6542
|
+
* resulting tree to XML.
|
|
6543
|
+
*
|
|
6544
|
+
* @category Canonical Codecs
|
|
4844
6545
|
* @since 4.0.0
|
|
4845
6546
|
*/
|
|
4846
6547
|
export function toEncoderXml(codec, options) {
|
|
@@ -4956,8 +6657,6 @@ function getStringTreePriority(ast) {
|
|
|
4956
6657
|
const treeReorder = /*#__PURE__*/InternalToCodec.makeReorder(getStringTreePriority);
|
|
4957
6658
|
function serializerTree(ast, recur, onMissingAnnotation) {
|
|
4958
6659
|
switch (ast._tag) {
|
|
4959
|
-
case "Unknown":
|
|
4960
|
-
case "ObjectKeyword":
|
|
4961
6660
|
case "Declaration":
|
|
4962
6661
|
{
|
|
4963
6662
|
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec;
|
|
@@ -4973,6 +6672,9 @@ function serializerTree(ast, recur, onMissingAnnotation) {
|
|
|
4973
6672
|
return AST.replaceEncoding(ast, [nullToString]);
|
|
4974
6673
|
case "Boolean":
|
|
4975
6674
|
return AST.replaceEncoding(ast, [booleanToString]);
|
|
6675
|
+
case "Unknown":
|
|
6676
|
+
case "ObjectKeyword":
|
|
6677
|
+
return AST.replaceEncoding(ast, [AST.unknownToStringTree]);
|
|
4976
6678
|
case "Enum":
|
|
4977
6679
|
case "Number":
|
|
4978
6680
|
case "Literal":
|
|
@@ -5051,6 +6753,9 @@ function onSerializerEnsureArray(ast) {
|
|
|
5051
6753
|
// Optic APIs
|
|
5052
6754
|
// -----------------------------------------------------------------------------
|
|
5053
6755
|
/**
|
|
6756
|
+
* Derives an `Iso` optic from a schema that isomorphically converts between
|
|
6757
|
+
* the schema's `Type` and its `Iso` (intermediate / serialized form).
|
|
6758
|
+
*
|
|
5054
6759
|
* @category Optic
|
|
5055
6760
|
* @since 4.0.0
|
|
5056
6761
|
*/
|
|
@@ -5059,6 +6764,8 @@ export function toIso(schema) {
|
|
|
5059
6764
|
return Optic_.makeIso(Parser.encodeSync(serializer), Parser.decodeSync(serializer));
|
|
5060
6765
|
}
|
|
5061
6766
|
/**
|
|
6767
|
+
* Returns an identity `Iso` over the schema's source (`Type`) side.
|
|
6768
|
+
*
|
|
5062
6769
|
* @category Optic
|
|
5063
6770
|
* @since 4.0.0
|
|
5064
6771
|
*/
|
|
@@ -5066,6 +6773,8 @@ export function toIsoSource(_) {
|
|
|
5066
6773
|
return Optic_.id();
|
|
5067
6774
|
}
|
|
5068
6775
|
/**
|
|
6776
|
+
* Returns an identity `Iso` over the schema's focus (`Iso`) side.
|
|
6777
|
+
*
|
|
5069
6778
|
* @category Optic
|
|
5070
6779
|
* @since 4.0.0
|
|
5071
6780
|
*/
|
|
@@ -5073,10 +6782,11 @@ export function toIsoFocus(_) {
|
|
|
5073
6782
|
return Optic_.id();
|
|
5074
6783
|
}
|
|
5075
6784
|
/**
|
|
5076
|
-
*
|
|
5077
|
-
*
|
|
5078
|
-
*
|
|
5079
|
-
* the
|
|
6785
|
+
* Overrides the ISO codec derivation for a schema by providing a target codec
|
|
6786
|
+
* and explicit `decode`/`encode` getters. The resulting schema carries a
|
|
6787
|
+
* custom `Iso` type, which changes the schema's type parameter — use
|
|
6788
|
+
* {@link overrideToCodecIso} when the default ISO transformation is not
|
|
6789
|
+
* appropriate.
|
|
5080
6790
|
*
|
|
5081
6791
|
* @category Optic
|
|
5082
6792
|
* @since 4.0.0
|
|
@@ -5094,11 +6804,15 @@ export function overrideToCodecIso(to, transformation) {
|
|
|
5094
6804
|
// Differ APIs
|
|
5095
6805
|
// -----------------------------------------------------------------------------
|
|
5096
6806
|
/**
|
|
6807
|
+
* Derives a JSON Patch differ from a codec. Serializes values to JSON (via
|
|
6808
|
+
* {@link toCodecJson}), computes RFC 6902 JSON Patch operations between old
|
|
6809
|
+
* and new values, and can apply patches back to the typed value.
|
|
6810
|
+
*
|
|
5097
6811
|
* @category JsonPatch
|
|
5098
6812
|
* @since 4.0.0
|
|
5099
6813
|
*/
|
|
5100
6814
|
export function toDifferJsonPatch(schema) {
|
|
5101
|
-
const serializer = toCodecJson(schema);
|
|
6815
|
+
const serializer = toCodecJson(schema);
|
|
5102
6816
|
const get = Parser.encodeSync(serializer);
|
|
5103
6817
|
const set = Parser.decodeSync(serializer);
|
|
5104
6818
|
return {
|
|
@@ -5113,33 +6827,42 @@ export function toDifferJsonPatch(schema) {
|
|
|
5113
6827
|
};
|
|
5114
6828
|
}
|
|
5115
6829
|
/**
|
|
6830
|
+
* Creates a recursive schema for a {@link Tree} of values described by `node`.
|
|
6831
|
+
* The resulting schema accepts a single node value, an array of trees, or an
|
|
6832
|
+
* object whose values are trees.
|
|
6833
|
+
*
|
|
5116
6834
|
* @category Tree
|
|
5117
6835
|
* @since 4.0.0
|
|
5118
6836
|
*/
|
|
5119
6837
|
export function Tree(node) {
|
|
5120
6838
|
const Tree$ref = suspend(() => Tree);
|
|
5121
|
-
const Tree = Union([node,
|
|
6839
|
+
const Tree = Union([node, ArraySchema(Tree$ref), Record(String, Tree$ref)]);
|
|
5122
6840
|
return Tree;
|
|
5123
6841
|
}
|
|
5124
6842
|
/**
|
|
5125
|
-
*
|
|
5126
|
-
*
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
}
|
|
5133
|
-
|
|
6843
|
+
* Schema that accepts and validates any immutable JSON-compatible value.
|
|
6844
|
+
*
|
|
6845
|
+
* **Example** (Validating a JSON value)
|
|
6846
|
+
*
|
|
6847
|
+
* ```ts
|
|
6848
|
+
* import { Schema } from "effect"
|
|
6849
|
+
*
|
|
6850
|
+
* const result = Schema.decodeUnknownOption(Schema.Json)({ key: [1, true, null] })
|
|
6851
|
+
* console.log(result._tag) // "Some"
|
|
6852
|
+
* ```
|
|
6853
|
+
*
|
|
5134
6854
|
* @category JSON
|
|
5135
6855
|
* @since 4.0.0
|
|
5136
6856
|
*/
|
|
5137
|
-
export const Json = /*#__PURE__*/
|
|
6857
|
+
export const Json = /*#__PURE__*/make(AST.Json);
|
|
5138
6858
|
/**
|
|
6859
|
+
* Schema that accepts any mutable JSON-compatible value. See {@link Json} for
|
|
6860
|
+
* the immutable variant.
|
|
6861
|
+
*
|
|
5139
6862
|
* @category JSON
|
|
5140
6863
|
* @since 4.0.0
|
|
5141
6864
|
*/
|
|
5142
|
-
export const MutableJson = /*#__PURE__*/
|
|
6865
|
+
export const MutableJson = /*#__PURE__*/make(AST.MutableJson);
|
|
5143
6866
|
// -----------------------------------------------------------------------------
|
|
5144
6867
|
// Annotations
|
|
5145
6868
|
// -----------------------------------------------------------------------------
|