effect 4.0.0-beta.6 → 4.0.0-beta.62
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 +82 -45
- package/dist/BigDecimal.d.ts.map +1 -1
- package/dist/BigDecimal.js +105 -52
- 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 +36 -33
- package/dist/BigInt.js.map +1 -1
- package/dist/Brand.d.ts +3 -5
- 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 +14 -45
- package/dist/Cache.d.ts.map +1 -1
- package/dist/Cache.js +21 -47
- package/dist/Cache.js.map +1 -1
- package/dist/Cause.d.ts +53 -22
- package/dist/Cause.d.ts.map +1 -1
- package/dist/Cause.js +108 -10
- package/dist/Cause.js.map +1 -1
- package/dist/Channel.d.ts +166 -48
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +176 -87
- 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/Clock.d.ts +2 -2
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.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 +189 -29
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +85 -35
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts +6 -6
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +5 -5
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Console.d.ts +2 -2
- package/dist/Console.d.ts.map +1 -1
- package/dist/Console.js.map +1 -1
- package/dist/Context.d.ts +1150 -0
- package/dist/Context.d.ts.map +1 -0
- package/dist/{ServiceMap.js → Context.js} +181 -165
- package/dist/Context.js.map +1 -0
- 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 +533 -365
- package/dist/Data.d.ts.map +1 -1
- package/dist/Data.js +125 -73
- package/dist/Data.js.map +1 -1
- package/dist/DateTime.d.ts +74 -255
- package/dist/DateTime.d.ts.map +1 -1
- package/dist/DateTime.js +17 -62
- package/dist/DateTime.js.map +1 -1
- package/dist/Deferred.d.ts +12 -5
- package/dist/Deferred.d.ts.map +1 -1
- package/dist/Deferred.js +13 -5
- package/dist/Deferred.js.map +1 -1
- package/dist/Duration.d.ts +74 -40
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +126 -87
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +1435 -927
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +516 -328
- package/dist/Effect.js.map +1 -1
- package/dist/Effectable.d.ts +29 -0
- package/dist/Effectable.d.ts.map +1 -0
- package/dist/Effectable.js +31 -0
- package/dist/Effectable.js.map +1 -0
- package/dist/Encoding.d.ts +1 -1
- package/dist/Equal.d.ts +276 -109
- package/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +140 -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/ExecutionPlan.d.ts +6 -6
- package/dist/ExecutionPlan.d.ts.map +1 -1
- package/dist/ExecutionPlan.js +4 -4
- package/dist/ExecutionPlan.js.map +1 -1
- 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 +10 -8
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Fiber.js.map +1 -1
- package/dist/FiberHandle.d.ts +11 -10
- package/dist/FiberHandle.d.ts.map +1 -1
- package/dist/FiberHandle.js +12 -11
- package/dist/FiberHandle.js.map +1 -1
- package/dist/FiberMap.d.ts +22 -21
- package/dist/FiberMap.d.ts.map +1 -1
- package/dist/FiberMap.js +10 -10
- package/dist/FiberMap.js.map +1 -1
- package/dist/FiberSet.d.ts +2 -2
- package/dist/FiberSet.d.ts.map +1 -1
- package/dist/FiberSet.js +4 -4
- package/dist/FiberSet.js.map +1 -1
- package/dist/FileSystem.d.ts +20 -19
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js +15 -11
- package/dist/FileSystem.js.map +1 -1
- package/dist/Filter.d.ts +4 -37
- package/dist/Filter.d.ts.map +1 -1
- package/dist/Filter.js +0 -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 +243 -55
- 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 +58 -60
- package/dist/Graph.js.map +1 -1
- package/dist/Hash.js +1 -1
- package/dist/Hash.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/Inspectable.d.ts +0 -4
- package/dist/Inspectable.d.ts.map +1 -1
- package/dist/Inspectable.js +4 -13
- package/dist/Inspectable.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 +69 -3
- package/dist/Latch.d.ts.map +1 -1
- package/dist/Latch.js +58 -0
- package/dist/Latch.js.map +1 -1
- package/dist/Layer.d.ts +599 -379
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +249 -180
- package/dist/Layer.js.map +1 -1
- package/dist/LayerMap.d.ts +27 -26
- package/dist/LayerMap.d.ts.map +1 -1
- package/dist/LayerMap.js +21 -18
- 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 +31 -97
- 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 +8 -8
- package/dist/ManagedRuntime.d.ts.map +1 -1
- package/dist/ManagedRuntime.js +34 -25
- package/dist/ManagedRuntime.js.map +1 -1
- package/dist/Metric.d.ts +23 -25
- package/dist/Metric.d.ts.map +1 -1
- package/dist/Metric.js +24 -26
- 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/MutableList.d.ts.map +1 -1
- package/dist/MutableList.js +3 -0
- package/dist/MutableList.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 +46 -18
- 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 +183 -0
- package/dist/PartitionedSemaphore.d.ts.map +1 -0
- package/dist/PartitionedSemaphore.js +231 -0
- package/dist/PartitionedSemaphore.js.map +1 -0
- package/dist/Path.d.ts +2 -2
- package/dist/Path.d.ts.map +1 -1
- package/dist/Path.js +2 -2
- package/dist/Path.js.map +1 -1
- package/dist/PlatformError.d.ts +2 -2
- package/dist/Pool.d.ts +1 -1
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +5 -5
- package/dist/Pool.js.map +1 -1
- package/dist/Predicate.d.ts +1 -1
- package/dist/Predicate.d.ts.map +1 -1
- package/dist/PubSub.d.ts +5 -4
- package/dist/PubSub.d.ts.map +1 -1
- package/dist/PubSub.js +15 -8
- 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 +36 -2
- package/dist/Random.d.ts.map +1 -1
- package/dist/Random.js +46 -35
- package/dist/Random.js.map +1 -1
- package/dist/RcMap.d.ts +4 -4
- package/dist/RcMap.d.ts.map +1 -1
- package/dist/RcMap.js +13 -13
- 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/Redactable.d.ts +139 -62
- package/dist/Redactable.d.ts.map +1 -1
- package/dist/Redactable.js +59 -55
- package/dist/Redactable.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 +257 -229
- package/dist/References.d.ts.map +1 -1
- package/dist/References.js +240 -259
- package/dist/References.js.map +1 -1
- package/dist/Request.d.ts +5 -5
- package/dist/Request.d.ts.map +1 -1
- package/dist/Request.js.map +1 -1
- package/dist/RequestResolver.d.ts +25 -25
- package/dist/RequestResolver.d.ts.map +1 -1
- package/dist/RequestResolver.js +15 -16
- package/dist/RequestResolver.js.map +1 -1
- package/dist/Resource.d.ts +0 -3
- package/dist/Resource.d.ts.map +1 -1
- package/dist/Resource.js +5 -4
- 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 +132 -120
- package/dist/Schedule.js.map +1 -1
- package/dist/Scheduler.d.ts +36 -125
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +37 -126
- package/dist/Scheduler.js.map +1 -1
- package/dist/Schema.d.ts +3213 -392
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +2058 -252
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +13 -2
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +340 -257
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaGetter.d.ts +55 -13
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +73 -11
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaIssue.d.ts.map +1 -1
- package/dist/SchemaIssue.js +29 -11
- package/dist/SchemaIssue.js.map +1 -1
- package/dist/SchemaParser.d.ts +44 -54
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +69 -4
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +2 -2
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +63 -39
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +245 -3
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +297 -33
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/Scope.d.ts +2 -2
- package/dist/Scope.d.ts.map +1 -1
- package/dist/Scope.js.map +1 -1
- package/dist/ScopedCache.d.ts +2 -2
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +5 -5
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Semaphore.d.ts +148 -52
- package/dist/Semaphore.d.ts.map +1 -1
- package/dist/Semaphore.js +135 -117
- package/dist/Semaphore.js.map +1 -1
- package/dist/Sink.d.ts +22 -19
- package/dist/Sink.d.ts.map +1 -1
- package/dist/Sink.js +54 -7
- package/dist/Sink.js.map +1 -1
- package/dist/Stdio.d.ts +18 -6
- package/dist/Stdio.d.ts.map +1 -1
- package/dist/Stdio.js +20 -2
- package/dist/Stdio.js.map +1 -1
- package/dist/Stream.d.ts +465 -542
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +329 -145
- 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 +7 -7
- package/dist/Struct.d.ts.map +1 -1
- package/dist/SubscriptionRef.d.ts +1 -2
- package/dist/SubscriptionRef.d.ts.map +1 -1
- package/dist/SubscriptionRef.js +83 -116
- package/dist/SubscriptionRef.js.map +1 -1
- package/dist/Terminal.d.ts +5 -4
- package/dist/Terminal.d.ts.map +1 -1
- package/dist/Terminal.js +2 -2
- package/dist/Terminal.js.map +1 -1
- package/dist/Tracer.d.ts +21 -20
- package/dist/Tracer.d.ts.map +1 -1
- package/dist/Tracer.js +13 -9
- 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 +4 -4
- package/dist/TxChunk.d.ts.map +1 -1
- package/dist/TxChunk.js +4 -4
- 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 +105 -86
- 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 +2 -2
- 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 +1 -1
- package/dist/TxQueue.d.ts.map +1 -1
- package/dist/TxQueue.js +42 -57
- package/dist/TxQueue.js.map +1 -1
- package/dist/TxReentrantLock.d.ts +500 -0
- package/dist/TxReentrantLock.d.ts.map +1 -0
- package/dist/TxReentrantLock.js +481 -0
- package/dist/TxReentrantLock.js.map +1 -0
- package/dist/TxRef.d.ts +14 -20
- package/dist/TxRef.d.ts.map +1 -1
- package/dist/TxRef.js +8 -10
- package/dist/TxRef.js.map +1 -1
- package/dist/TxSemaphore.d.ts +162 -2
- package/dist/TxSemaphore.d.ts.map +1 -1
- package/dist/TxSemaphore.js +25 -10
- 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 -22
- package/dist/Types.d.ts.map +1 -1
- package/dist/Unify.d.ts +8 -2
- package/dist/Unify.d.ts.map +1 -1
- package/dist/Unify.js.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 +886 -71
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +886 -71
- package/dist/index.js.map +1 -1
- 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 +502 -326
- 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/layer.js +3 -3
- package/dist/internal/layer.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 +9 -9
- 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 +6 -6
- package/dist/internal/request.js.map +1 -1
- package/dist/internal/schedule.js +1 -1
- package/dist/internal/schedule.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 +87 -109
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.d.ts +10 -1
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +59 -1
- package/dist/internal/schema/schema.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 +5 -5
- package/dist/testing/TestClock.d.ts.map +1 -1
- package/dist/testing/TestClock.js +2 -2
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +267 -33
- 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 +127 -45
- package/dist/unstable/ai/AiError.d.ts.map +1 -1
- package/dist/unstable/ai/AiError.js +29 -23
- package/dist/unstable/ai/AiError.js.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.js +9 -2
- package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +39 -11
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js +40 -47
- 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/IdGenerator.d.ts +2 -2
- package/dist/unstable/ai/IdGenerator.d.ts.map +1 -1
- package/dist/unstable/ai/IdGenerator.js +2 -2
- package/dist/unstable/ai/IdGenerator.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +119 -49
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +260 -61
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +207 -112
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +71 -19
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +68 -15
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +225 -73
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Model.d.ts +27 -9
- package/dist/unstable/ai/Model.d.ts.map +1 -1
- package/dist/unstable/ai/Model.js +25 -9
- package/dist/unstable/ai/Model.js.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.js +9 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts +17 -17
- package/dist/unstable/ai/Prompt.d.ts.map +1 -1
- package/dist/unstable/ai/Prompt.js +6 -9
- package/dist/unstable/ai/Prompt.js.map +1 -1
- package/dist/unstable/ai/Response.d.ts +24 -24
- package/dist/unstable/ai/Response.d.ts.map +1 -1
- package/dist/unstable/ai/Response.js +7 -8
- 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/Telemetry.d.ts +35 -2
- package/dist/unstable/ai/Telemetry.d.ts.map +1 -1
- package/dist/unstable/ai/Telemetry.js +2 -2
- package/dist/unstable/ai/Telemetry.js.map +1 -1
- package/dist/unstable/ai/Tokenizer.d.ts +2 -2
- package/dist/unstable/ai/Tokenizer.d.ts.map +1 -1
- package/dist/unstable/ai/Tokenizer.js +2 -2
- package/dist/unstable/ai/Tokenizer.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +46 -16
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +68 -22
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/ai/Toolkit.d.ts +4 -4
- package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
- package/dist/unstable/ai/Toolkit.js +14 -21
- 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 +5 -7
- package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
- package/dist/unstable/cli/Argument.d.ts +4 -7
- 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 +51 -63
- package/dist/unstable/cli/CliError.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.js +32 -57
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/CliOutput.d.ts +5 -4
- package/dist/unstable/cli/CliOutput.d.ts.map +1 -1
- package/dist/unstable/cli/CliOutput.js +67 -12
- package/dist/unstable/cli/CliOutput.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +372 -59
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +328 -66
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/Completions.d.ts +97 -0
- package/dist/unstable/cli/Completions.d.ts.map +1 -0
- package/dist/unstable/cli/Completions.js +25 -0
- package/dist/unstable/cli/Completions.js.map +1 -0
- package/dist/unstable/cli/Flag.d.ts +4 -5
- 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 +34 -6
- package/dist/unstable/cli/Param.d.ts.map +1 -1
- package/dist/unstable/cli/Param.js +24 -14
- 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 +266 -86
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +10 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +10 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts +41 -15
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +84 -47
- package/dist/unstable/cli/internal/command.js.map +1 -1
- package/dist/unstable/cli/internal/completions/bash.js.map +1 -1
- package/dist/unstable/cli/internal/completions/descriptor.d.ts +2 -0
- package/dist/unstable/cli/internal/completions/descriptor.d.ts.map +1 -0
- package/dist/unstable/cli/internal/completions/{CommandDescriptor.js → descriptor.js} +17 -5
- package/dist/unstable/cli/internal/completions/descriptor.js.map +1 -0
- package/dist/unstable/cli/internal/completions/fish.js.map +1 -1
- package/dist/unstable/cli/internal/completions/zsh.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 +155 -58
- 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/ClusterError.d.ts +7 -7
- package/dist/unstable/cluster/ClusterSchema.d.ts +28 -7
- package/dist/unstable/cluster/ClusterSchema.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterSchema.js +28 -8
- package/dist/unstable/cluster/ClusterSchema.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +4 -2
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +96 -63
- 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 +17 -16
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/Entity.js +31 -25
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/EntityAddress.d.ts +2 -2
- 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/EntityProxy.js +3 -3
- package/dist/unstable/cluster/EntityProxy.js.map +1 -1
- package/dist/unstable/cluster/EntityProxyServer.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityProxyServer.js +6 -6
- package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
- package/dist/unstable/cluster/EntityResource.d.ts +4 -4
- package/dist/unstable/cluster/EntityResource.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityResource.js +2 -2
- package/dist/unstable/cluster/EntityResource.js.map +1 -1
- package/dist/unstable/cluster/Envelope.d.ts +3 -3
- package/dist/unstable/cluster/HttpRunner.js +2 -2
- package/dist/unstable/cluster/HttpRunner.js.map +1 -1
- package/dist/unstable/cluster/K8sHttpClient.d.ts +5 -5
- package/dist/unstable/cluster/K8sHttpClient.d.ts.map +1 -1
- package/dist/unstable/cluster/K8sHttpClient.js +7 -7
- package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
- package/dist/unstable/cluster/Message.d.ts +16 -10
- package/dist/unstable/cluster/Message.d.ts.map +1 -1
- package/dist/unstable/cluster/Message.js +16 -8
- package/dist/unstable/cluster/Message.js.map +1 -1
- package/dist/unstable/cluster/MessageStorage.d.ts +46 -23
- package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/MessageStorage.js +40 -25
- package/dist/unstable/cluster/MessageStorage.js.map +1 -1
- package/dist/unstable/cluster/Reply.d.ts +7 -6
- package/dist/unstable/cluster/Reply.d.ts.map +1 -1
- package/dist/unstable/cluster/Reply.js +8 -7
- 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 +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/RunnerHealth.d.ts +2 -2
- package/dist/unstable/cluster/RunnerHealth.d.ts.map +1 -1
- package/dist/unstable/cluster/RunnerHealth.js +2 -2
- package/dist/unstable/cluster/RunnerHealth.js.map +1 -1
- package/dist/unstable/cluster/RunnerServer.d.ts.map +1 -1
- package/dist/unstable/cluster/RunnerServer.js +10 -9
- package/dist/unstable/cluster/RunnerServer.js.map +1 -1
- package/dist/unstable/cluster/RunnerStorage.d.ts +12 -12
- package/dist/unstable/cluster/RunnerStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/RunnerStorage.js +3 -3
- package/dist/unstable/cluster/RunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/Runners.d.ts +5 -4
- package/dist/unstable/cluster/Runners.d.ts.map +1 -1
- package/dist/unstable/cluster/Runners.js +16 -14
- package/dist/unstable/cluster/Runners.js.map +1 -1
- package/dist/unstable/cluster/ShardId.d.ts +35 -49
- package/dist/unstable/cluster/ShardId.d.ts.map +1 -1
- package/dist/unstable/cluster/ShardId.js +65 -67
- package/dist/unstable/cluster/ShardId.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts +4 -4
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +59 -49
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.d.ts +28 -27
- package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.js +27 -27
- package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
- package/dist/unstable/cluster/SingletonAddress.d.ts +2 -2
- package/dist/unstable/cluster/Snowflake.d.ts +2 -2
- package/dist/unstable/cluster/Snowflake.d.ts.map +1 -1
- package/dist/unstable/cluster/Snowflake.js +2 -2
- package/dist/unstable/cluster/Snowflake.js.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.js +24 -20
- package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js +7 -7
- package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +30 -24
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/cluster/internal/entityReaper.js +2 -2
- package/dist/unstable/cluster/internal/entityReaper.js.map +1 -1
- package/dist/unstable/cluster/internal/resourceMap.js +3 -3
- package/dist/unstable/cluster/internal/resourceMap.js.map +1 -1
- package/dist/unstable/devtools/DevToolsClient.d.ts +2 -2
- package/dist/unstable/devtools/DevToolsClient.d.ts.map +1 -1
- package/dist/unstable/devtools/DevToolsClient.js +9 -8
- package/dist/unstable/devtools/DevToolsClient.js.map +1 -1
- package/dist/unstable/devtools/DevToolsSchema.d.ts +4 -4
- 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 +3 -3
- 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/Event.d.ts +0 -6
- package/dist/unstable/eventlog/Event.d.ts.map +1 -1
- package/dist/unstable/eventlog/Event.js +0 -5
- package/dist/unstable/eventlog/Event.js.map +1 -1
- package/dist/unstable/eventlog/EventGroup.d.ts +0 -2
- package/dist/unstable/eventlog/EventGroup.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventGroup.js +0 -2
- package/dist/unstable/eventlog/EventGroup.js.map +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +27 -10
- package/dist/unstable/eventlog/EventJournal.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventJournal.js +130 -71
- package/dist/unstable/eventlog/EventJournal.js.map +1 -1
- package/dist/unstable/eventlog/EventLog.d.ts +94 -37
- package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLog.js +225 -151
- package/dist/unstable/eventlog/EventLog.js.map +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.d.ts +11 -9
- package/dist/unstable/eventlog/EventLogEncryption.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.js +15 -17
- package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.d.ts +228 -0
- package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -0
- package/dist/unstable/eventlog/EventLogMessage.js +214 -0
- package/dist/unstable/eventlog/EventLogMessage.js.map +1 -0
- package/dist/unstable/eventlog/EventLogRemote.d.ts +112 -194
- package/dist/unstable/eventlog/EventLogRemote.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogRemote.js +168 -322
- package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
- package/dist/unstable/eventlog/EventLogServer.d.ts +26 -48
- package/dist/unstable/eventlog/EventLogServer.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogServer.js +128 -199
- package/dist/unstable/eventlog/EventLogServer.js.map +1 -1
- package/dist/unstable/eventlog/EventLogServerEncrypted.d.ts +60 -0
- package/dist/unstable/eventlog/EventLogServerEncrypted.d.ts.map +1 -0
- package/dist/unstable/eventlog/EventLogServerEncrypted.js +166 -0
- package/dist/unstable/eventlog/EventLogServerEncrypted.js.map +1 -0
- package/dist/unstable/eventlog/EventLogServerUnencrypted.d.ts +183 -0
- package/dist/unstable/eventlog/EventLogServerUnencrypted.d.ts.map +1 -0
- package/dist/unstable/eventlog/EventLogServerUnencrypted.js +461 -0
- package/dist/unstable/eventlog/EventLogServerUnencrypted.js.map +1 -0
- package/dist/unstable/eventlog/EventLogSessionAuth.d.ts +117 -0
- package/dist/unstable/eventlog/EventLogSessionAuth.d.ts.map +1 -0
- package/dist/unstable/eventlog/EventLogSessionAuth.js +284 -0
- package/dist/unstable/eventlog/EventLogSessionAuth.js.map +1 -0
- package/dist/unstable/eventlog/{SqlEventLogJournal.d.ts → SqlEventJournal.d.ts} +2 -2
- package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -0
- package/dist/unstable/eventlog/{SqlEventLogJournal.js → SqlEventJournal.js} +28 -21
- package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -0
- package/dist/unstable/eventlog/{SqlEventLogServer.d.ts → SqlEventLogServerEncrypted.d.ts} +5 -5
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -0
- package/dist/unstable/eventlog/{SqlEventLogServer.js → SqlEventLogServerEncrypted.js} +69 -27
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -0
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.d.ts +25 -0
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.d.ts.map +1 -0
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +355 -0
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -0
- package/dist/unstable/eventlog/index.d.ts +22 -2
- package/dist/unstable/eventlog/index.d.ts.map +1 -1
- package/dist/unstable/eventlog/index.js +22 -2
- package/dist/unstable/eventlog/index.js.map +1 -1
- package/dist/unstable/eventlog/internal/identityRootSecretDerivation.d.ts +2 -0
- package/dist/unstable/eventlog/internal/identityRootSecretDerivation.d.ts.map +1 -0
- package/dist/unstable/eventlog/internal/identityRootSecretDerivation.js +89 -0
- package/dist/unstable/eventlog/internal/identityRootSecretDerivation.js.map +1 -0
- package/dist/unstable/http/Cookies.d.ts +51 -6
- 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 +2 -2
- package/dist/unstable/http/Etag.d.ts.map +1 -1
- package/dist/unstable/http/Etag.js +7 -3
- package/dist/unstable/http/Etag.js.map +1 -1
- package/dist/unstable/http/FetchHttpClient.d.ts +6 -3
- package/dist/unstable/http/FetchHttpClient.d.ts.map +1 -1
- package/dist/unstable/http/FetchHttpClient.js +5 -5
- package/dist/unstable/http/FetchHttpClient.js.map +1 -1
- package/dist/unstable/http/Headers.d.ts +24 -4
- package/dist/unstable/http/Headers.d.ts.map +1 -1
- package/dist/unstable/http/Headers.js +42 -13
- 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 +125 -21
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +197 -19
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpClientError.d.ts +8 -8
- 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 +18 -3
- package/dist/unstable/http/HttpClientResponse.js.map +1 -1
- package/dist/unstable/http/HttpEffect.d.ts +13 -11
- package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
- package/dist/unstable/http/HttpEffect.js +51 -51
- package/dist/unstable/http/HttpEffect.js.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts +5 -4
- package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.js +6 -10
- 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 +4 -9
- package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/unstable/http/HttpMiddleware.js +47 -43
- package/dist/unstable/http/HttpMiddleware.js.map +1 -1
- package/dist/unstable/http/HttpPlatform.d.ts +2 -2
- package/dist/unstable/http/HttpPlatform.d.ts.map +1 -1
- package/dist/unstable/http/HttpPlatform.js +5 -4
- package/dist/unstable/http/HttpPlatform.js.map +1 -1
- package/dist/unstable/http/HttpRouter.d.ts +9 -8
- package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
- package/dist/unstable/http/HttpRouter.js +36 -36
- package/dist/unstable/http/HttpRouter.js.map +1 -1
- package/dist/unstable/http/HttpServer.d.ts +2 -2
- package/dist/unstable/http/HttpServer.d.ts.map +1 -1
- package/dist/unstable/http/HttpServer.js +4 -4
- 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 +19 -7
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +307 -13
- 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 +52 -5
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +240 -5
- 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 +7 -7
- package/dist/unstable/http/Multipart.d.ts.map +1 -1
- package/dist/unstable/http/Multipart.js +7 -7
- package/dist/unstable/http/Multipart.js.map +1 -1
- 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 +18 -9
- 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 +11 -11
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js +8 -8
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +12 -9
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +73 -48
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +82 -7
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +79 -11
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +210 -105
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +52 -47
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +66 -29
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +138 -32
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +9 -8
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js +4 -4
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +49 -17
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +38 -8
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +88 -9
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js +86 -11
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSecurity.d.ts +9 -6
- package/dist/unstable/httpapi/HttpApiSecurity.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSecurity.js +6 -6
- package/dist/unstable/httpapi/HttpApiSecurity.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts +17 -25
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +59 -60
- 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 +8 -8
- 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/OtlpMetrics.js +2 -2
- package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
- package/dist/unstable/observability/OtlpSerialization.d.ts +2 -2
- package/dist/unstable/observability/OtlpSerialization.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpSerialization.js +2 -2
- package/dist/unstable/observability/OtlpSerialization.js.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/observability/PrometheusMetrics.d.ts +3 -3
- package/dist/unstable/observability/PrometheusMetrics.d.ts.map +1 -1
- package/dist/unstable/observability/PrometheusMetrics.js +4 -33
- package/dist/unstable/observability/PrometheusMetrics.js.map +1 -1
- package/dist/unstable/observability/internal/protobuf.js +4 -4
- package/dist/unstable/observability/internal/protobuf.js.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.d.ts +24 -3
- package/dist/unstable/persistence/KeyValueStore.d.ts.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.js +144 -2
- 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 +1 -2
- package/dist/unstable/persistence/PersistedCache.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedCache.js +10 -11
- package/dist/unstable/persistence/PersistedCache.js.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.d.ts +16 -16
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +9 -9
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Persistence.d.ts +5 -5
- package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistence.js +5 -5
- package/dist/unstable/persistence/Persistence.js.map +1 -1
- package/dist/unstable/persistence/RateLimiter.d.ts +9 -9
- package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
- package/dist/unstable/persistence/RateLimiter.js +4 -4
- package/dist/unstable/persistence/RateLimiter.js.map +1 -1
- package/dist/unstable/persistence/Redis.d.ts +3 -3
- package/dist/unstable/persistence/Redis.d.ts.map +1 -1
- package/dist/unstable/persistence/Redis.js +2 -2
- package/dist/unstable/persistence/Redis.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 +83 -8
- package/dist/unstable/process/ChildProcessSpawner.d.ts.map +1 -1
- package/dist/unstable/process/ChildProcessSpawner.js +22 -2
- package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.d.ts +37 -17
- package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.js +9 -0
- package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +108 -47
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +105 -25
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +25 -20
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +58 -26
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.d.ts +8 -2
- package/dist/unstable/reactivity/AtomRegistry.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js +57 -14
- package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.d.ts +12 -12
- package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.js +59 -31
- package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
- package/dist/unstable/reactivity/Reactivity.d.ts +2 -2
- package/dist/unstable/reactivity/Reactivity.d.ts.map +1 -1
- package/dist/unstable/reactivity/Reactivity.js +6 -6
- package/dist/unstable/reactivity/Reactivity.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +137 -19
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js +99 -7
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts +26 -47
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +117 -75
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcClientError.d.ts +2 -2
- package/dist/unstable/rpc/RpcGroup.d.ts +15 -11
- package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcGroup.js +30 -20
- package/dist/unstable/rpc/RpcGroup.js.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts +12 -12
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.js +5 -5
- package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
- package/dist/unstable/rpc/RpcSchema.d.ts +14 -1
- 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 +13 -2
- package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.js +60 -27
- package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts +8 -12
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +73 -43
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/rpc/RpcWorker.d.ts +2 -2
- package/dist/unstable/rpc/RpcWorker.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcWorker.js +4 -4
- package/dist/unstable/rpc/RpcWorker.js.map +1 -1
- package/dist/unstable/rpc/Utils.d.ts +6 -3
- package/dist/unstable/rpc/Utils.d.ts.map +1 -1
- package/dist/unstable/rpc/Utils.js +46 -5
- package/dist/unstable/rpc/Utils.js.map +1 -1
- package/dist/unstable/schema/Model.d.ts +24 -3
- package/dist/unstable/schema/Model.d.ts.map +1 -1
- package/dist/unstable/schema/Model.js +17 -4
- package/dist/unstable/schema/Model.js.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +7 -7
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js +7 -18
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts +35 -15
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +34 -27
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/dist/unstable/socket/SocketServer.d.ts +8 -5
- package/dist/unstable/socket/SocketServer.d.ts.map +1 -1
- package/dist/unstable/socket/SocketServer.js +2 -2
- package/dist/unstable/socket/SocketServer.js.map +1 -1
- 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 +24 -6
- package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
- package/dist/unstable/sql/SqlClient.js +37 -32
- package/dist/unstable/sql/SqlClient.js.map +1 -1
- package/dist/unstable/sql/SqlConnection.d.ts +2 -2
- package/dist/unstable/sql/SqlConnection.d.ts.map +1 -1
- package/dist/unstable/sql/SqlConnection.js +5 -2
- package/dist/unstable/sql/SqlConnection.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 +8 -9
- package/dist/unstable/sql/SqlModel.d.ts.map +1 -1
- package/dist/unstable/sql/SqlModel.js +12 -38
- package/dist/unstable/sql/SqlModel.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.js +24 -17
- 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.d.ts +3 -5
- package/dist/unstable/sql/Statement.d.ts.map +1 -1
- package/dist/unstable/sql/Statement.js +14 -13
- package/dist/unstable/sql/Statement.js.map +1 -1
- package/dist/unstable/workers/Transferable.d.ts +4 -4
- package/dist/unstable/workers/Transferable.d.ts.map +1 -1
- package/dist/unstable/workers/Transferable.js +7 -7
- package/dist/unstable/workers/Transferable.js.map +1 -1
- package/dist/unstable/workers/Worker.d.ts +3 -3
- package/dist/unstable/workers/Worker.d.ts.map +1 -1
- package/dist/unstable/workers/Worker.js +6 -3
- package/dist/unstable/workers/Worker.js.map +1 -1
- package/dist/unstable/workers/WorkerError.d.ts +5 -5
- package/dist/unstable/workers/WorkerRunner.d.ts +2 -2
- package/dist/unstable/workers/WorkerRunner.d.ts.map +1 -1
- package/dist/unstable/workers/WorkerRunner.js +5 -2
- package/dist/unstable/workers/WorkerRunner.js.map +1 -1
- package/dist/unstable/workflow/Activity.d.ts +8 -3
- package/dist/unstable/workflow/Activity.d.ts.map +1 -1
- package/dist/unstable/workflow/Activity.js +25 -11
- package/dist/unstable/workflow/Activity.js.map +1 -1
- package/dist/unstable/workflow/DurableClock.d.ts +3 -6
- package/dist/unstable/workflow/DurableClock.d.ts.map +1 -1
- package/dist/unstable/workflow/DurableClock.js +6 -6
- package/dist/unstable/workflow/DurableClock.js.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.d.ts +2 -5
- package/dist/unstable/workflow/DurableDeferred.d.ts.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.js +33 -15
- package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +12 -14
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.js +30 -26
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +24 -7
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +165 -16
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.js +4 -4
- package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
- package/package.json +11 -10
- package/src/Array.ts +304 -447
- package/src/BigDecimal.ts +137 -82
- package/src/BigInt.ts +53 -45
- package/src/Brand.ts +3 -5
- package/src/Cache.ts +27 -54
- package/src/Cause.ts +57 -22
- package/src/Channel.ts +687 -220
- package/src/Chunk.ts +149 -331
- package/src/Clock.ts +2 -2
- package/src/Combiner.ts +280 -13
- package/src/Config.ts +214 -52
- package/src/ConfigProvider.ts +5 -5
- package/src/Console.ts +2 -2
- package/src/Context.ts +1454 -0
- package/src/Cron.ts +155 -63
- package/src/Data.ts +530 -368
- package/src/DateTime.ts +77 -258
- package/src/Deferred.ts +15 -6
- package/src/Duration.ts +151 -81
- package/src/Effect.ts +1633 -1055
- package/src/Effectable.ts +47 -0
- package/src/Equal.ts +293 -109
- package/src/Equivalence.ts +114 -52
- package/src/ErrorReporter.ts +458 -0
- package/src/ExecutionPlan.ts +8 -9
- package/src/Exit.ts +24 -12
- package/src/Fiber.ts +17 -8
- package/src/FiberHandle.ts +15 -14
- package/src/FiberMap.ts +27 -27
- package/src/FiberSet.ts +5 -5
- package/src/FileSystem.ts +30 -26
- package/src/Filter.ts +4 -62
- package/src/Formatter.ts +268 -60
- package/src/Function.ts +2 -10
- package/src/Graph.ts +123 -112
- package/src/Hash.ts +2 -2
- package/src/HashMap.ts +26 -19
- package/src/Inspectable.ts +2 -22
- package/src/Iterable.ts +117 -63
- package/src/JsonSchema.ts +383 -10
- package/src/Latch.ts +85 -3
- package/src/Layer.ts +728 -441
- package/src/LayerMap.ts +38 -35
- package/src/LogLevel.ts +37 -0
- package/src/Logger.ts +35 -102
- package/src/ManagedRuntime.ts +61 -48
- package/src/Metric.ts +64 -66
- package/src/MutableHashMap.ts +9 -0
- package/src/MutableHashSet.ts +9 -0
- package/src/MutableList.ts +3 -0
- package/src/Newtype.ts +308 -0
- package/src/Number.ts +98 -29
- package/src/Optic.ts +948 -19
- package/src/Option.ts +34 -24
- package/src/Order.ts +39 -32
- package/src/PartitionedSemaphore.ts +414 -0
- package/src/Path.ts +2 -2
- package/src/Pool.ts +9 -9
- package/src/Predicate.ts +1 -1
- package/src/PubSub.ts +20 -11
- package/src/Pull.ts +1 -1
- package/src/Queue.ts +11 -9
- package/src/Random.ts +51 -14
- package/src/RcMap.ts +19 -19
- package/src/RcRef.ts +1 -1
- package/src/Record.ts +94 -199
- package/src/Redactable.ts +146 -72
- package/src/Reducer.ts +166 -7
- package/src/References.ts +283 -287
- package/src/Request.ts +5 -5
- package/src/RequestResolver.ts +34 -35
- package/src/Resource.ts +6 -5
- package/src/Result.ts +2 -4
- package/src/Runtime.ts +102 -6
- package/src/Schedule.ts +243 -336
- package/src/Scheduler.ts +52 -129
- package/src/Schema.ts +3769 -597
- package/src/SchemaAST.ts +480 -302
- package/src/SchemaGetter.ts +80 -24
- package/src/SchemaIssue.ts +28 -15
- package/src/SchemaParser.ts +100 -29
- package/src/SchemaRepresentation.ts +57 -33
- package/src/SchemaTransformation.ts +321 -32
- package/src/Scope.ts +2 -2
- package/src/ScopedCache.ts +8 -8
- package/src/Semaphore.ts +268 -182
- package/src/Sink.ts +89 -34
- package/src/Stdio.ts +29 -6
- package/src/Stream.ts +908 -752
- package/src/String.ts +122 -69
- package/src/Struct.ts +7 -7
- package/src/SubscriptionRef.ts +98 -118
- package/src/Terminal.ts +5 -4
- package/src/Tracer.ts +23 -22
- package/src/Trie.ts +44 -31
- package/src/TxChunk.ts +26 -16
- package/src/TxDeferred.ts +391 -0
- package/src/TxHashMap.ts +347 -291
- package/src/TxHashSet.ts +54 -61
- package/src/TxPriorityQueue.ts +762 -0
- package/src/TxPubSub.ts +787 -0
- package/src/TxQueue.ts +221 -245
- package/src/TxReentrantLock.ts +729 -0
- package/src/TxRef.ts +31 -31
- package/src/TxSemaphore.ts +203 -31
- package/src/TxSubscriptionRef.ts +637 -0
- package/src/Types.ts +75 -23
- package/src/Unify.ts +26 -2
- package/src/Utils.ts +137 -111
- package/src/index.ts +896 -73
- package/src/internal/core.ts +9 -10
- package/src/internal/dateTime.ts +91 -96
- package/src/internal/effect.ts +1179 -614
- package/src/internal/hashMap.ts +12 -10
- package/src/internal/layer.ts +7 -7
- package/src/internal/option.ts +7 -0
- package/src/internal/random.ts +20 -0
- package/src/internal/rcRef.ts +12 -12
- package/src/internal/references.ts +72 -0
- package/src/internal/request.ts +8 -8
- package/src/internal/schedule.ts +3 -1
- package/src/internal/schema/annotations.ts +2 -0
- package/src/internal/schema/representation.ts +82 -97
- package/src/internal/schema/schema.ts +68 -1
- package/src/internal/trie.ts +21 -15
- package/src/testing/TestClock.ts +6 -6
- package/src/testing/TestSchema.ts +333 -36
- package/src/testing/index.ts +64 -1
- package/src/unstable/ai/AiError.ts +111 -53
- package/src/unstable/ai/AnthropicStructuredOutput.ts +7 -3
- package/src/unstable/ai/Chat.ts +136 -88
- package/src/unstable/ai/EmbeddingModel.ts +209 -0
- package/src/unstable/ai/IdGenerator.ts +2 -2
- package/src/unstable/ai/LanguageModel.ts +685 -255
- package/src/unstable/ai/McpSchema.ts +84 -22
- package/src/unstable/ai/McpServer.ts +307 -87
- package/src/unstable/ai/Model.ts +44 -13
- package/src/unstable/ai/OpenAiStructuredOutput.ts +9 -2
- package/src/unstable/ai/Prompt.ts +23 -29
- package/src/unstable/ai/Response.ts +29 -31
- package/src/unstable/ai/ResponseIdTracker.ts +95 -0
- package/src/unstable/ai/Telemetry.ts +2 -2
- package/src/unstable/ai/Tokenizer.ts +2 -2
- package/src/unstable/ai/Tool.ts +62 -36
- package/src/unstable/ai/Toolkit.ts +17 -26
- package/src/unstable/ai/index.ts +24 -1
- package/src/unstable/ai/internal/codec-transformer.ts +3 -9
- package/src/unstable/cli/Argument.ts +5 -8
- package/src/unstable/cli/CliError.ts +67 -66
- package/src/unstable/cli/CliOutput.ts +87 -15
- package/src/unstable/cli/Command.ts +808 -193
- package/src/unstable/cli/Completions.ts +107 -0
- package/src/unstable/cli/Flag.ts +5 -6
- package/src/unstable/cli/GlobalFlag.ts +242 -0
- package/src/unstable/cli/HelpDoc.ts +91 -11
- package/src/unstable/cli/Param.ts +54 -27
- package/src/unstable/cli/Primitive.ts +2 -2
- package/src/unstable/cli/Prompt.ts +275 -104
- package/src/unstable/cli/index.ts +12 -0
- package/src/unstable/cli/internal/command.ts +125 -64
- package/src/unstable/cli/internal/completions/bash.ts +7 -7
- package/src/unstable/cli/internal/completions/{CommandDescriptor.ts → descriptor.ts} +16 -58
- package/src/unstable/cli/internal/completions/fish.ts +7 -7
- package/src/unstable/cli/internal/completions/zsh.ts +8 -14
- 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 +201 -84
- package/src/unstable/cluster/ClusterCron.ts +2 -2
- package/src/unstable/cluster/ClusterSchema.ts +38 -10
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +142 -80
- package/src/unstable/cluster/DeliverAt.ts +1 -1
- package/src/unstable/cluster/Entity.ts +58 -45
- package/src/unstable/cluster/EntityAddress.ts +1 -1
- package/src/unstable/cluster/EntityProxy.ts +3 -3
- package/src/unstable/cluster/EntityProxyServer.ts +6 -6
- package/src/unstable/cluster/EntityResource.ts +6 -6
- package/src/unstable/cluster/HttpRunner.ts +2 -2
- package/src/unstable/cluster/K8sHttpClient.ts +10 -10
- package/src/unstable/cluster/Message.ts +30 -17
- package/src/unstable/cluster/MessageStorage.ts +74 -45
- package/src/unstable/cluster/Reply.ts +13 -10
- package/src/unstable/cluster/Runner.ts +1 -1
- package/src/unstable/cluster/RunnerAddress.ts +1 -1
- package/src/unstable/cluster/RunnerHealth.ts +2 -2
- package/src/unstable/cluster/RunnerServer.ts +11 -14
- package/src/unstable/cluster/RunnerStorage.ts +9 -9
- package/src/unstable/cluster/Runners.ts +22 -18
- package/src/unstable/cluster/ShardId.ts +84 -74
- package/src/unstable/cluster/Sharding.ts +75 -60
- package/src/unstable/cluster/ShardingConfig.ts +39 -40
- package/src/unstable/cluster/Snowflake.ts +2 -2
- package/src/unstable/cluster/SqlMessageStorage.ts +29 -20
- package/src/unstable/cluster/SqlRunnerStorage.ts +13 -7
- package/src/unstable/cluster/internal/entityManager.ts +60 -41
- package/src/unstable/cluster/internal/entityReaper.ts +2 -2
- package/src/unstable/cluster/internal/resourceMap.ts +3 -3
- package/src/unstable/devtools/DevToolsClient.ts +26 -21
- 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/Event.ts +0 -8
- package/src/unstable/eventlog/EventGroup.ts +0 -4
- package/src/unstable/eventlog/EventJournal.ts +148 -80
- package/src/unstable/eventlog/EventLog.ts +360 -234
- package/src/unstable/eventlog/EventLogEncryption.ts +18 -32
- package/src/unstable/eventlog/EventLogMessage.ts +277 -0
- package/src/unstable/eventlog/EventLogRemote.ts +264 -410
- package/src/unstable/eventlog/EventLogServer.ts +183 -275
- package/src/unstable/eventlog/EventLogServerEncrypted.ts +206 -0
- package/src/unstable/eventlog/EventLogServerUnencrypted.ts +749 -0
- package/src/unstable/eventlog/EventLogSessionAuth.ts +437 -0
- package/src/unstable/eventlog/{SqlEventLogJournal.ts → SqlEventJournal.ts} +38 -22
- package/src/unstable/eventlog/{SqlEventLogServer.ts → SqlEventLogServerEncrypted.ts} +110 -43
- package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +506 -0
- package/src/unstable/eventlog/index.ts +27 -2
- package/src/unstable/eventlog/internal/identityRootSecretDerivation.ts +153 -0
- package/src/unstable/http/Cookies.ts +94 -11
- package/src/unstable/http/Etag.ts +7 -5
- package/src/unstable/http/FetchHttpClient.ts +5 -5
- package/src/unstable/http/Headers.ts +70 -20
- package/src/unstable/http/HttpClient.ts +385 -42
- package/src/unstable/http/HttpClientRequest.ts +151 -39
- package/src/unstable/http/HttpClientResponse.ts +24 -8
- package/src/unstable/http/HttpEffect.ts +71 -77
- package/src/unstable/http/HttpIncomingMessage.ts +9 -8
- package/src/unstable/http/HttpMethod.ts +16 -4
- package/src/unstable/http/HttpMiddleware.ts +50 -50
- package/src/unstable/http/HttpPlatform.ts +5 -4
- package/src/unstable/http/HttpRouter.ts +46 -46
- package/src/unstable/http/HttpServer.ts +5 -11
- package/src/unstable/http/HttpServerError.ts +45 -47
- package/src/unstable/http/HttpServerRequest.ts +414 -23
- package/src/unstable/http/HttpServerRespondable.ts +6 -6
- package/src/unstable/http/HttpServerResponse.ts +351 -13
- package/src/unstable/http/HttpStaticServer.ts +456 -0
- package/src/unstable/http/HttpTraceContext.ts +31 -17
- package/src/unstable/http/Multipart.ts +8 -8
- package/src/unstable/http/Url.ts +650 -0
- package/src/unstable/http/UrlParams.ts +30 -18
- package/src/unstable/http/index.ts +10 -0
- package/src/unstable/http/internal/preResponseHandler.ts +15 -0
- package/src/unstable/httpapi/HttpApi.ts +22 -22
- package/src/unstable/httpapi/HttpApiBuilder.ts +156 -66
- package/src/unstable/httpapi/HttpApiClient.ts +185 -34
- package/src/unstable/httpapi/HttpApiEndpoint.ts +225 -114
- package/src/unstable/httpapi/HttpApiError.ts +129 -30
- package/src/unstable/httpapi/HttpApiGroup.ts +18 -17
- package/src/unstable/httpapi/HttpApiMiddleware.ts +95 -32
- package/src/unstable/httpapi/HttpApiSchema.ts +106 -11
- package/src/unstable/httpapi/HttpApiSecurity.ts +13 -13
- package/src/unstable/httpapi/OpenApi.ts +74 -73
- package/src/unstable/observability/Otlp.ts +12 -12
- package/src/unstable/observability/OtlpExporter.ts +14 -10
- package/src/unstable/observability/OtlpLogger.ts +13 -9
- package/src/unstable/observability/OtlpMetrics.ts +6 -6
- package/src/unstable/observability/OtlpSerialization.ts +2 -2
- package/src/unstable/observability/OtlpTracer.ts +14 -10
- package/src/unstable/observability/PrometheusMetrics.ts +5 -5
- package/src/unstable/observability/internal/protobuf.ts +4 -4
- package/src/unstable/persistence/KeyValueStore.ts +226 -3
- package/src/unstable/persistence/Persistable.ts +3 -3
- package/src/unstable/persistence/PersistedCache.ts +20 -17
- package/src/unstable/persistence/PersistedQueue.ts +21 -21
- package/src/unstable/persistence/Persistence.ts +7 -7
- package/src/unstable/persistence/RateLimiter.ts +7 -7
- package/src/unstable/persistence/Redis.ts +2 -2
- package/src/unstable/process/ChildProcess.ts +6 -208
- package/src/unstable/process/ChildProcessSpawner.ts +114 -15
- package/src/unstable/reactivity/AsyncResult.ts +59 -17
- package/src/unstable/reactivity/Atom.ts +280 -124
- package/src/unstable/reactivity/AtomHttpApi.ts +127 -61
- package/src/unstable/reactivity/AtomRegistry.ts +70 -16
- package/src/unstable/reactivity/AtomRpc.ts +82 -37
- package/src/unstable/reactivity/Reactivity.ts +6 -6
- package/src/unstable/rpc/Rpc.ts +212 -32
- package/src/unstable/rpc/RpcClient.ts +161 -142
- package/src/unstable/rpc/RpcGroup.ts +51 -34
- package/src/unstable/rpc/RpcMiddleware.ts +28 -22
- package/src/unstable/rpc/RpcSchema.ts +24 -6
- package/src/unstable/rpc/RpcSerialization.ts +97 -54
- package/src/unstable/rpc/RpcServer.ts +91 -65
- package/src/unstable/rpc/RpcWorker.ts +5 -5
- package/src/unstable/rpc/Utils.ts +63 -4
- package/src/unstable/schema/Model.ts +35 -6
- package/src/unstable/schema/VariantSchema.ts +14 -27
- package/src/unstable/socket/Socket.ts +102 -62
- package/src/unstable/socket/SocketServer.ts +2 -2
- package/src/unstable/sql/Migrator.ts +7 -5
- package/src/unstable/sql/SqlClient.ts +48 -19
- package/src/unstable/sql/SqlConnection.ts +2 -2
- package/src/unstable/sql/SqlError.ts +365 -11
- package/src/unstable/sql/SqlModel.ts +57 -85
- package/src/unstable/sql/SqlResolver.ts +28 -20
- package/src/unstable/sql/SqlSchema.ts +42 -26
- package/src/unstable/sql/Statement.ts +21 -25
- package/src/unstable/workers/Transferable.ts +17 -19
- package/src/unstable/workers/Worker.ts +4 -4
- package/src/unstable/workers/WorkerRunner.ts +2 -2
- package/src/unstable/workflow/Activity.ts +36 -13
- package/src/unstable/workflow/DurableClock.ts +11 -11
- package/src/unstable/workflow/DurableDeferred.ts +36 -18
- package/src/unstable/workflow/Workflow.ts +46 -35
- package/src/unstable/workflow/WorkflowEngine.ts +236 -23
- package/src/unstable/workflow/WorkflowProxyServer.ts +4 -4
- 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/ServiceMap.d.ts +0 -1126
- package/dist/ServiceMap.d.ts.map +0 -1
- package/dist/ServiceMap.js.map +0 -1
- package/dist/internal/schema/to-codec.d.ts +0 -2
- package/dist/internal/schema/to-codec.d.ts.map +0 -1
- package/dist/internal/schema/to-codec.js +0 -129
- package/dist/internal/schema/to-codec.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/CommandDescriptor.d.ts +0 -2
- package/dist/unstable/cli/internal/completions/CommandDescriptor.d.ts.map +0 -1
- package/dist/unstable/cli/internal/completions/CommandDescriptor.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/dist/unstable/eventlog/SqlEventLogJournal.d.ts.map +0 -1
- package/dist/unstable/eventlog/SqlEventLogJournal.js.map +0 -1
- package/dist/unstable/eventlog/SqlEventLogServer.d.ts.map +0 -1
- package/dist/unstable/eventlog/SqlEventLogServer.js.map +0 -1
- package/src/NullOr.ts +0 -204
- package/src/ServiceMap.ts +0 -1410
- package/src/internal/schema/to-codec.ts +0 -148
- 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,9 +1,92 @@
|
|
|
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";
|
|
5
87
|
import * as BigDecimal_ from "./BigDecimal.js";
|
|
6
88
|
import * as Cause_ from "./Cause.js";
|
|
89
|
+
import * as Chunk_ from "./Chunk.js";
|
|
7
90
|
import * as Data from "./Data.js";
|
|
8
91
|
import * as DateTime from "./DateTime.js";
|
|
9
92
|
import * as Duration_ from "./Duration.js";
|
|
@@ -12,8 +95,8 @@ import * as Encoding from "./Encoding.js";
|
|
|
12
95
|
import * as Equal from "./Equal.js";
|
|
13
96
|
import * as Equivalence from "./Equivalence.js";
|
|
14
97
|
import * as Exit_ from "./Exit.js";
|
|
15
|
-
import { format,
|
|
16
|
-
import { identity } from "./Function.js";
|
|
98
|
+
import { format, formatPropertyKey } from "./Formatter.js";
|
|
99
|
+
import { identity, memoize } from "./Function.js";
|
|
17
100
|
import * as HashMap_ from "./HashMap.js";
|
|
18
101
|
import * as HashSet_ from "./HashSet.js";
|
|
19
102
|
import * as core from "./internal/core.js";
|
|
@@ -22,7 +105,7 @@ import * as InternalArbitrary from "./internal/schema/arbitrary.js";
|
|
|
22
105
|
import * as InternalEquivalence from "./internal/schema/equivalence.js";
|
|
23
106
|
import * as InternalStandard from "./internal/schema/representation.js";
|
|
24
107
|
import * as InternalSchema from "./internal/schema/schema.js";
|
|
25
|
-
import
|
|
108
|
+
import { SchemaError } from "./internal/schema/schema.js";
|
|
26
109
|
import * as JsonPatch from "./JsonPatch.js";
|
|
27
110
|
import * as JsonSchema from "./JsonSchema.js";
|
|
28
111
|
import { remainder } from "./Number.js";
|
|
@@ -44,9 +127,51 @@ import * as Struct_ from "./Struct.js";
|
|
|
44
127
|
import * as FastCheck from "./testing/FastCheck.js";
|
|
45
128
|
const TypeId = InternalSchema.TypeId;
|
|
46
129
|
/**
|
|
47
|
-
*
|
|
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
|
|
48
140
|
*
|
|
49
|
-
* @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
|
+
* ```
|
|
50
175
|
*
|
|
51
176
|
* @category Constructors
|
|
52
177
|
* @since 4.0.0
|
|
@@ -57,18 +182,60 @@ export function declareConstructor() {
|
|
|
57
182
|
};
|
|
58
183
|
}
|
|
59
184
|
/**
|
|
60
|
-
*
|
|
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
|
+
* ```
|
|
61
207
|
*
|
|
62
208
|
* @see {@link declareConstructor} for creating schemas for parametric types.
|
|
63
209
|
*
|
|
210
|
+
* @category Constructors
|
|
64
211
|
* @since 4.0.0
|
|
65
212
|
*/
|
|
66
213
|
export function declare(is, annotations) {
|
|
67
214
|
return declareConstructor()([], () => (input, ast) => is(input) ? Effect.succeed(input) : Effect.fail(new Issue.InvalidType(ast, Option_.some(input))), annotations);
|
|
68
215
|
}
|
|
69
216
|
/**
|
|
70
|
-
*
|
|
71
|
-
* 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, ~type.make.in, Iso, ~type.parameters, etc.
|
|
236
|
+
* type T = typeof bottom["Type"] // string
|
|
237
|
+
* type E = typeof bottom["Encoded"] // string
|
|
238
|
+
* ```
|
|
72
239
|
*
|
|
73
240
|
* @since 4.0.0
|
|
74
241
|
*/
|
|
@@ -77,21 +244,88 @@ export function revealBottom(bottom) {
|
|
|
77
244
|
}
|
|
78
245
|
/**
|
|
79
246
|
* Adds metadata annotations to a schema without changing its runtime behavior.
|
|
80
|
-
*
|
|
81
|
-
*
|
|
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
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @see {@link annotateEncoded} to annotate the encoded side instead.
|
|
82
267
|
*
|
|
83
268
|
* @category Annotations
|
|
84
269
|
* @since 4.0.0
|
|
85
270
|
*/
|
|
86
271
|
export function annotate(annotations) {
|
|
87
|
-
return self =>
|
|
88
|
-
|
|
89
|
-
|
|
272
|
+
return self => self.annotate(annotations);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Adds metadata annotations to the **encoded** side of a schema without
|
|
276
|
+
* changing its runtime behavior. This is the encoded-side counterpart of
|
|
277
|
+
* `annotate`, which targets the decoded (Type) side.
|
|
278
|
+
*
|
|
279
|
+
* Internally the schema is flipped so that `Encoded` becomes `Type`,
|
|
280
|
+
* annotated, and then flipped back.
|
|
281
|
+
*
|
|
282
|
+
* **Example** (Adding a title to the encoded representation)
|
|
283
|
+
*
|
|
284
|
+
* ```ts
|
|
285
|
+
* import { Schema } from "effect"
|
|
286
|
+
*
|
|
287
|
+
* const schema = Schema.NumberFromString.pipe(
|
|
288
|
+
* Schema.annotateEncoded({
|
|
289
|
+
* title: "my title"
|
|
290
|
+
* })
|
|
291
|
+
* )
|
|
292
|
+
*
|
|
293
|
+
* console.log(Schema.toEncoded(schema).ast.annotations?.title)
|
|
294
|
+
* // "my title"
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* @see {@link annotate} to annotate the type side instead.
|
|
298
|
+
*
|
|
299
|
+
* @category Annotations
|
|
300
|
+
* @since 4.0.0
|
|
301
|
+
*/
|
|
302
|
+
export function annotateEncoded(annotations) {
|
|
303
|
+
return self => flip(flip(self).annotate(annotations));
|
|
90
304
|
}
|
|
91
305
|
/**
|
|
92
|
-
* Adds key-
|
|
93
|
-
*
|
|
94
|
-
*
|
|
306
|
+
* Adds key-level annotations to a schema field. This is the pipeable
|
|
307
|
+
* (curried) counterpart of the `.annotateKey` method.
|
|
308
|
+
*
|
|
309
|
+
* Key annotations apply to a field's position inside a `Struct` or `Tuple`
|
|
310
|
+
* rather than to the field's value type. They can carry a
|
|
311
|
+
* `messageMissingKey` to customise the error shown when the field is absent,
|
|
312
|
+
* as well as standard documentation fields such as `title`, `description`,
|
|
313
|
+
* and `examples`.
|
|
314
|
+
*
|
|
315
|
+
* **Example** (Custom missing-key message for a required field)
|
|
316
|
+
*
|
|
317
|
+
* ```ts
|
|
318
|
+
* import { Schema } from "effect"
|
|
319
|
+
*
|
|
320
|
+
* const schema = Schema.Struct({
|
|
321
|
+
* username: Schema.String.pipe(
|
|
322
|
+
* Schema.annotateKey({
|
|
323
|
+
* description: "The username used to log in",
|
|
324
|
+
* messageMissingKey: "Username is required"
|
|
325
|
+
* })
|
|
326
|
+
* )
|
|
327
|
+
* })
|
|
328
|
+
* ```
|
|
95
329
|
*
|
|
96
330
|
* @category Annotations
|
|
97
331
|
* @since 4.0.0
|
|
@@ -102,42 +336,81 @@ export function annotateKey(annotations) {
|
|
|
102
336
|
};
|
|
103
337
|
}
|
|
104
338
|
/**
|
|
339
|
+
* Identity function that widens a value to the full {@link Codec} interface,
|
|
340
|
+
* prompting TypeScript to infer all four type parameters (`T`, `E`, `RD`, `RE`).
|
|
341
|
+
*
|
|
342
|
+
* When a schema is stored in a variable typed as `Schema<T>` or `Top`, the
|
|
343
|
+
* encoded type and service requirements are erased. Passing the value through
|
|
344
|
+
* `revealCodec` recovers those parameters without any runtime cost.
|
|
345
|
+
*
|
|
346
|
+
* **Example** (Recovering encoded type from a schema variable)
|
|
347
|
+
*
|
|
348
|
+
* ```ts
|
|
349
|
+
* import { Schema } from "effect"
|
|
350
|
+
*
|
|
351
|
+
* const schema: Schema.Schema<number> = Schema.NumberFromString
|
|
352
|
+
*
|
|
353
|
+
* // Without revealCodec, Encoded is unknown
|
|
354
|
+
* const codec = Schema.revealCodec(schema)
|
|
355
|
+
* type Enc = typeof codec["Encoded"] // string
|
|
356
|
+
* ```
|
|
357
|
+
*
|
|
105
358
|
* @since 4.0.0
|
|
106
359
|
*/
|
|
107
360
|
export function revealCodec(codec) {
|
|
108
361
|
return codec;
|
|
109
362
|
}
|
|
110
|
-
|
|
363
|
+
export {
|
|
111
364
|
/**
|
|
112
|
-
*
|
|
365
|
+
* Error thrown (or returned as the error channel value) when schema decoding
|
|
366
|
+
* or encoding fails.
|
|
113
367
|
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
368
|
+
* The `issue` field contains a structured {@link Issue.Issue} tree describing
|
|
369
|
+
* every validation failure, including the path to the problematic value,
|
|
370
|
+
* expected types, and actual values received. `message` renders the issue tree
|
|
371
|
+
* as a human-readable string.
|
|
372
|
+
*
|
|
373
|
+
* Use {@link isSchemaError} to narrow an unknown value to `SchemaError`.
|
|
374
|
+
*
|
|
375
|
+
* **Example** (Catching a SchemaError)
|
|
376
|
+
*
|
|
377
|
+
* ```ts
|
|
378
|
+
* import { Schema } from "effect"
|
|
379
|
+
*
|
|
380
|
+
* try {
|
|
381
|
+
* Schema.decodeUnknownSync(Schema.Number)("not a number")
|
|
382
|
+
* } catch (err) {
|
|
383
|
+
* if (Schema.isSchemaError(err)) {
|
|
384
|
+
* console.log(err.message)
|
|
385
|
+
* // Expected number, actual "not a number"
|
|
386
|
+
* }
|
|
387
|
+
* }
|
|
388
|
+
* ```
|
|
118
389
|
*
|
|
119
390
|
* @since 4.0.0
|
|
120
391
|
*/
|
|
121
|
-
|
|
122
|
-
[SchemaErrorTypeId] = SchemaErrorTypeId;
|
|
123
|
-
_tag = "SchemaError";
|
|
124
|
-
name = "SchemaError";
|
|
125
|
-
issue;
|
|
126
|
-
constructor(issue) {
|
|
127
|
-
this.issue = issue;
|
|
128
|
-
}
|
|
129
|
-
get message() {
|
|
130
|
-
return this.issue.toString();
|
|
131
|
-
}
|
|
132
|
-
toString() {
|
|
133
|
-
return `SchemaError(${this.message})`;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
392
|
+
SchemaError };
|
|
136
393
|
/**
|
|
394
|
+
* Returns `true` if `u` is a {@link SchemaError}.
|
|
395
|
+
*
|
|
396
|
+
* **Example** (Type guard in a catch block)
|
|
397
|
+
*
|
|
398
|
+
* ```ts
|
|
399
|
+
* import { Schema } from "effect"
|
|
400
|
+
*
|
|
401
|
+
* try {
|
|
402
|
+
* Schema.decodeUnknownSync(Schema.Number)("oops")
|
|
403
|
+
* } catch (err) {
|
|
404
|
+
* if (Schema.isSchemaError(err)) {
|
|
405
|
+
* console.log(err._tag) // "SchemaError"
|
|
406
|
+
* }
|
|
407
|
+
* }
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
137
410
|
* @since 4.0.0
|
|
138
411
|
*/
|
|
139
412
|
export function isSchemaError(u) {
|
|
140
|
-
return Predicate.hasProperty(u, SchemaErrorTypeId);
|
|
413
|
+
return Predicate.hasProperty(u, InternalSchema.SchemaErrorTypeId);
|
|
141
414
|
}
|
|
142
415
|
function makeStandardResult(exit) {
|
|
143
416
|
return Exit_.isSuccess(exit) ? exit.value : {
|
|
@@ -224,7 +497,7 @@ export function toStandardSchemaV1(self, options) {
|
|
|
224
497
|
}), {
|
|
225
498
|
scheduler
|
|
226
499
|
});
|
|
227
|
-
|
|
500
|
+
fiber.currentDispatcher?.flush();
|
|
228
501
|
const exit = fiber.pollUnsafe();
|
|
229
502
|
if (exit) {
|
|
230
503
|
return makeStandardResult(exit);
|
|
@@ -373,6 +646,11 @@ export const is = Parser.is;
|
|
|
373
646
|
*/
|
|
374
647
|
export const asserts = Parser.asserts;
|
|
375
648
|
/**
|
|
649
|
+
* Decodes an `unknown` input against a schema, returning an `Effect` that
|
|
650
|
+
* succeeds with the decoded value or fails with a {@link SchemaError}. Use this
|
|
651
|
+
* when the input type is not statically known. Prefer {@link decodeEffect} when
|
|
652
|
+
* the input is already typed as the schema's `Encoded` type.
|
|
653
|
+
*
|
|
376
654
|
* @category Decoding
|
|
377
655
|
* @since 4.0.0
|
|
378
656
|
*/
|
|
@@ -383,11 +661,22 @@ export function decodeUnknownEffect(schema) {
|
|
|
383
661
|
};
|
|
384
662
|
}
|
|
385
663
|
/**
|
|
664
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
665
|
+
* returning an `Effect` that succeeds with the decoded value or fails with a
|
|
666
|
+
* {@link SchemaError}. Use this when the input is already typed; for `unknown`
|
|
667
|
+
* input use {@link decodeUnknownEffect}.
|
|
668
|
+
*
|
|
386
669
|
* @category Decoding
|
|
387
670
|
* @since 4.0.0
|
|
388
671
|
*/
|
|
389
672
|
export const decodeEffect = decodeUnknownEffect;
|
|
390
673
|
/**
|
|
674
|
+
* Decodes an `unknown` input against a schema synchronously, returning an
|
|
675
|
+
* `Exit` that is either a `Success` with the decoded value or a `Failure` with
|
|
676
|
+
* a {@link SchemaError}. Only usable with schemas that have no
|
|
677
|
+
* `DecodingServices` requirement. Prefer {@link decodeExit} when the input is
|
|
678
|
+
* already typed as the schema's `Encoded` type.
|
|
679
|
+
*
|
|
391
680
|
* @category Decoding
|
|
392
681
|
* @since 4.0.0
|
|
393
682
|
*/
|
|
@@ -398,41 +687,120 @@ export function decodeUnknownExit(schema) {
|
|
|
398
687
|
};
|
|
399
688
|
}
|
|
400
689
|
/**
|
|
690
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
691
|
+
* synchronously, returning an `Exit` that is either a `Success` with the
|
|
692
|
+
* decoded value or a `Failure` with a {@link SchemaError}. Only usable with
|
|
693
|
+
* schemas that have no `DecodingServices` requirement. For `unknown` input use
|
|
694
|
+
* {@link decodeUnknownExit}.
|
|
695
|
+
*
|
|
401
696
|
* @category Decoding
|
|
402
697
|
* @since 4.0.0
|
|
403
698
|
*/
|
|
404
699
|
export const decodeExit = decodeUnknownExit;
|
|
405
700
|
/**
|
|
701
|
+
* Decodes an `unknown` input against a schema, returning an `Option` that is
|
|
702
|
+
* `Some` with the decoded value on success or `None` on failure. Prefer this
|
|
703
|
+
* over {@link decodeUnknownExit} or {@link decodeUnknownEffect} when you only
|
|
704
|
+
* need to know whether decoding succeeded and don't need error details. For
|
|
705
|
+
* typed input use {@link decodeOption}.
|
|
706
|
+
*
|
|
406
707
|
* @category Decoding
|
|
407
708
|
* @since 4.0.0
|
|
408
709
|
*/
|
|
409
710
|
export const decodeUnknownOption = Parser.decodeUnknownOption;
|
|
410
711
|
/**
|
|
712
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
713
|
+
* returning an `Option` that is `Some` with the decoded value on success or
|
|
714
|
+
* `None` on failure. For `unknown` input use {@link decodeUnknownOption}.
|
|
715
|
+
*
|
|
411
716
|
* @category Decoding
|
|
412
717
|
* @since 4.0.0
|
|
413
718
|
*/
|
|
414
719
|
export const decodeOption = Parser.decodeOption;
|
|
720
|
+
/**
|
|
721
|
+
* Decodes an `unknown` input against a schema, returning a `Promise` that
|
|
722
|
+
* resolves with the decoded value or rejects with a {@link SchemaError}. Useful
|
|
723
|
+
* for integrating with Promise-based APIs. For typed input use
|
|
724
|
+
* {@link decodePromise}.
|
|
725
|
+
*
|
|
726
|
+
* @category Decoding
|
|
727
|
+
* @since 4.0.0
|
|
728
|
+
*/
|
|
729
|
+
export const decodeUnknownResult = Parser.decodeUnknownResult;
|
|
730
|
+
/**
|
|
731
|
+
* @category Decoding
|
|
732
|
+
* @since 4.0.0
|
|
733
|
+
*/
|
|
734
|
+
export const decodeResult = Parser.decodeResult;
|
|
415
735
|
/**
|
|
416
736
|
* @category Decoding
|
|
417
737
|
* @since 4.0.0
|
|
418
738
|
*/
|
|
419
739
|
export const decodeUnknownPromise = Parser.decodeUnknownPromise;
|
|
420
740
|
/**
|
|
741
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
742
|
+
* returning a `Promise` that resolves with the decoded value or rejects with a
|
|
743
|
+
* {@link SchemaError}. For `unknown` input use {@link decodeUnknownPromise}.
|
|
744
|
+
*
|
|
421
745
|
* @category Decoding
|
|
422
746
|
* @since 4.0.0
|
|
423
747
|
*/
|
|
424
748
|
export const decodePromise = Parser.decodePromise;
|
|
425
749
|
/**
|
|
750
|
+
* Decodes an `unknown` input against a schema synchronously, throwing a
|
|
751
|
+
* {@link SchemaError} on failure. Use this when you want to validate data at a
|
|
752
|
+
* boundary and treat a schema mismatch as an unrecoverable error. For
|
|
753
|
+
* non-throwing alternatives see {@link decodeUnknownOption},
|
|
754
|
+
* {@link decodeUnknownExit}, or {@link decodeUnknownEffect}. For typed input
|
|
755
|
+
* use {@link decodeSync}.
|
|
756
|
+
*
|
|
757
|
+
* **Example** (Decoding with a transformation schema)
|
|
758
|
+
*
|
|
759
|
+
* ```ts
|
|
760
|
+
* import { Schema } from "effect"
|
|
761
|
+
*
|
|
762
|
+
* const NumberFromString = Schema.NumberFromString
|
|
763
|
+
*
|
|
764
|
+
* console.log(Schema.decodeUnknownSync(NumberFromString)("42"))
|
|
765
|
+
* // Output: 42
|
|
766
|
+
*
|
|
767
|
+
* Schema.decodeUnknownSync(NumberFromString)("not a number")
|
|
768
|
+
* // throws SchemaError: NumberFromString
|
|
769
|
+
* // └─ Encoded side transformation failure
|
|
770
|
+
* // └─ NumberFromString
|
|
771
|
+
* // └─ Expected a numeric string, actual "not a number"
|
|
772
|
+
* ```
|
|
773
|
+
*
|
|
426
774
|
* @category Decoding
|
|
427
775
|
* @since 4.0.0
|
|
428
776
|
*/
|
|
429
777
|
export const decodeUnknownSync = Parser.decodeUnknownSync;
|
|
430
778
|
/**
|
|
779
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
780
|
+
* synchronously, throwing a {@link SchemaError} on failure. For `unknown` input
|
|
781
|
+
* use {@link decodeUnknownSync}.
|
|
782
|
+
*
|
|
431
783
|
* @category Decoding
|
|
432
784
|
* @since 4.0.0
|
|
433
785
|
*/
|
|
434
786
|
export const decodeSync = Parser.decodeSync;
|
|
435
787
|
/**
|
|
788
|
+
* Encodes an `unknown` input against a schema, returning an `Effect` that
|
|
789
|
+
* succeeds with the encoded value or fails with a {@link SchemaError}. Use this
|
|
790
|
+
* when the input type is not statically known. Prefer {@link encodeEffect} when
|
|
791
|
+
* the input is already typed as the schema's `Type`.
|
|
792
|
+
*
|
|
793
|
+
* **Example** (Encoding a value to a string)
|
|
794
|
+
*
|
|
795
|
+
* ```ts
|
|
796
|
+
* import { Effect, Schema } from "effect"
|
|
797
|
+
*
|
|
798
|
+
* const NumberFromString = Schema.NumberFromString
|
|
799
|
+
*
|
|
800
|
+
* Effect.runPromise(Schema.encodeUnknownEffect(NumberFromString)(42)).then(console.log)
|
|
801
|
+
* // Output: "42"
|
|
802
|
+
* ```
|
|
803
|
+
*
|
|
436
804
|
* @category Encoding
|
|
437
805
|
* @since 4.0.0
|
|
438
806
|
*/
|
|
@@ -443,11 +811,22 @@ export function encodeUnknownEffect(schema) {
|
|
|
443
811
|
};
|
|
444
812
|
}
|
|
445
813
|
/**
|
|
814
|
+
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
815
|
+
* `Effect` that succeeds with the encoded value or fails with a
|
|
816
|
+
* {@link SchemaError}. Use this when the input is already typed; for `unknown`
|
|
817
|
+
* input use {@link encodeUnknownEffect}.
|
|
818
|
+
*
|
|
446
819
|
* @category Encoding
|
|
447
820
|
* @since 4.0.0
|
|
448
821
|
*/
|
|
449
822
|
export const encodeEffect = encodeUnknownEffect;
|
|
450
823
|
/**
|
|
824
|
+
* Encodes an `unknown` input against a schema synchronously, returning an
|
|
825
|
+
* `Exit` that is either a `Success` with the encoded value or a `Failure` with
|
|
826
|
+
* a {@link SchemaError}. Only usable with schemas that have no
|
|
827
|
+
* `EncodingServices` requirement. Prefer {@link encodeExit} when the input is
|
|
828
|
+
* already typed as the schema's `Type`.
|
|
829
|
+
*
|
|
451
830
|
* @category Encoding
|
|
452
831
|
* @since 4.0.0
|
|
453
832
|
*/
|
|
@@ -458,36 +837,82 @@ export function encodeUnknownExit(schema) {
|
|
|
458
837
|
};
|
|
459
838
|
}
|
|
460
839
|
/**
|
|
840
|
+
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
841
|
+
* returning an `Exit` that is either a `Success` with the encoded value or a
|
|
842
|
+
* `Failure` with a {@link SchemaError}. Only usable with schemas that have no
|
|
843
|
+
* `EncodingServices` requirement. For `unknown` input use
|
|
844
|
+
* {@link encodeUnknownExit}.
|
|
845
|
+
*
|
|
461
846
|
* @category Encoding
|
|
462
847
|
* @since 4.0.0
|
|
463
848
|
*/
|
|
464
849
|
export const encodeExit = encodeUnknownExit;
|
|
465
850
|
/**
|
|
851
|
+
* Encodes an `unknown` input against a schema, returning an `Option` that is
|
|
852
|
+
* `Some` with the encoded value on success or `None` on failure. Prefer this
|
|
853
|
+
* over {@link encodeUnknownExit} or {@link encodeUnknownEffect} when you only
|
|
854
|
+
* need to know whether encoding succeeded and don't need error details. For
|
|
855
|
+
* typed input use {@link encodeOption}.
|
|
856
|
+
*
|
|
466
857
|
* @category Encoding
|
|
467
858
|
* @since 4.0.0
|
|
468
859
|
*/
|
|
469
860
|
export const encodeUnknownOption = Parser.encodeUnknownOption;
|
|
470
861
|
/**
|
|
862
|
+
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
863
|
+
* `Option` that is `Some` with the encoded value on success or `None` on
|
|
864
|
+
* failure. For `unknown` input use {@link encodeUnknownOption}.
|
|
865
|
+
*
|
|
471
866
|
* @category Encoding
|
|
472
867
|
* @since 4.0.0
|
|
473
868
|
*/
|
|
474
869
|
export const encodeOption = Parser.encodeOption;
|
|
870
|
+
/**
|
|
871
|
+
* Encodes an `unknown` input against a schema, returning a `Promise` that
|
|
872
|
+
* resolves with the encoded value or rejects with a {@link SchemaError}. Useful
|
|
873
|
+
* for integrating with Promise-based APIs. For typed input use
|
|
874
|
+
* {@link encodePromise}.
|
|
875
|
+
*
|
|
876
|
+
* @category Encoding
|
|
877
|
+
* @since 4.0.0
|
|
878
|
+
*/
|
|
879
|
+
export const encodeUnknownResult = Parser.encodeUnknownResult;
|
|
880
|
+
/**
|
|
881
|
+
* @category Encoding
|
|
882
|
+
* @since 4.0.0
|
|
883
|
+
*/
|
|
884
|
+
export const encodeResult = Parser.encodeResult;
|
|
475
885
|
/**
|
|
476
886
|
* @category Encoding
|
|
477
887
|
* @since 4.0.0
|
|
478
888
|
*/
|
|
479
889
|
export const encodeUnknownPromise = Parser.encodeUnknownPromise;
|
|
480
890
|
/**
|
|
891
|
+
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
892
|
+
* `Promise` that resolves with the encoded value or rejects with a
|
|
893
|
+
* {@link SchemaError}. For `unknown` input use {@link encodeUnknownPromise}.
|
|
894
|
+
*
|
|
481
895
|
* @category Encoding
|
|
482
896
|
* @since 4.0.0
|
|
483
897
|
*/
|
|
484
898
|
export const encodePromise = Parser.encodePromise;
|
|
485
899
|
/**
|
|
900
|
+
* Encodes an `unknown` input against a schema synchronously, throwing a
|
|
901
|
+
* {@link SchemaError} on failure. Use this when you want to serialize data at a
|
|
902
|
+
* boundary and treat a schema mismatch as an unrecoverable error. For
|
|
903
|
+
* non-throwing alternatives see {@link encodeUnknownOption},
|
|
904
|
+
* {@link encodeUnknownExit}, or {@link encodeUnknownEffect}. For typed input
|
|
905
|
+
* use {@link encodeSync}.
|
|
906
|
+
*
|
|
486
907
|
* @category Encoding
|
|
487
908
|
* @since 4.0.0
|
|
488
909
|
*/
|
|
489
910
|
export const encodeUnknownSync = Parser.encodeUnknownSync;
|
|
490
911
|
/**
|
|
912
|
+
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
913
|
+
* throwing a {@link SchemaError} on failure. For `unknown` input use
|
|
914
|
+
* {@link encodeUnknownSync}.
|
|
915
|
+
*
|
|
491
916
|
* @category Encoding
|
|
492
917
|
* @since 4.0.0
|
|
493
918
|
*/
|
|
@@ -508,6 +933,31 @@ export const encodeSync = Parser.encodeSync;
|
|
|
508
933
|
* @since 4.0.0
|
|
509
934
|
*/
|
|
510
935
|
export const make = InternalSchema.make;
|
|
936
|
+
/**
|
|
937
|
+
* Transforms a schema into a class that can be extended with `extends`. The
|
|
938
|
+
* resulting class inherits the full schema API (e.g. `annotate`) and can define
|
|
939
|
+
* static methods that reference `this`.
|
|
940
|
+
*
|
|
941
|
+
* **Example** (Wrapping a primitive schema)
|
|
942
|
+
*
|
|
943
|
+
* ```ts
|
|
944
|
+
* import { Schema } from "effect"
|
|
945
|
+
*
|
|
946
|
+
* class MyString extends Schema.asClass(Schema.String) {
|
|
947
|
+
* static readonly decodeUnknownSync = Schema.decodeUnknownSync(this)
|
|
948
|
+
* }
|
|
949
|
+
*
|
|
950
|
+
* console.log(MyString.decodeUnknownSync("a"))
|
|
951
|
+
* // "a"
|
|
952
|
+
* ```
|
|
953
|
+
*
|
|
954
|
+
* @since 4.0.0
|
|
955
|
+
*/
|
|
956
|
+
export function asClass(schema) {
|
|
957
|
+
// oxlint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
958
|
+
class Class {}
|
|
959
|
+
return Object.setPrototypeOf(Class, schema);
|
|
960
|
+
}
|
|
511
961
|
/**
|
|
512
962
|
* Tests if a value is a `Schema`.
|
|
513
963
|
*
|
|
@@ -542,57 +992,74 @@ export const optionalKey = /*#__PURE__*/Struct_.lambda(schema => make(AST.option
|
|
|
542
992
|
schema
|
|
543
993
|
}));
|
|
544
994
|
/**
|
|
995
|
+
* Reverses {@link optionalKey}, returning the inner required schema. Only
|
|
996
|
+
* applicable to schemas already wrapped with `optionalKey`.
|
|
997
|
+
*
|
|
545
998
|
* @since 4.0.0
|
|
546
999
|
*/
|
|
547
1000
|
export const requiredKey = /*#__PURE__*/Struct_.lambda(self => self.schema);
|
|
548
1001
|
/**
|
|
549
|
-
*
|
|
1002
|
+
* Marks a struct field as optional, allowing the key to be absent or
|
|
550
1003
|
* `undefined`.
|
|
551
1004
|
*
|
|
552
|
-
*
|
|
553
|
-
* that:
|
|
554
|
-
* - Can be omitted from the object entirely
|
|
555
|
-
* - Can be explicitly set to `undefined`
|
|
556
|
-
* - Can contain the specified schema type
|
|
1005
|
+
* explicitly set to `undefined`. Equivalent to `optionalKey(UndefinedOr(S))`.
|
|
557
1006
|
*
|
|
558
|
-
*
|
|
1007
|
+
* Use {@link optionalKey} instead if you want exact optional semantics (absent
|
|
1008
|
+
* only, not `undefined`).
|
|
1009
|
+
*
|
|
1010
|
+
* **Example** (Optional field accepting undefined)
|
|
559
1011
|
*
|
|
560
1012
|
* ```ts
|
|
561
1013
|
* import { Schema } from "effect"
|
|
562
1014
|
*
|
|
563
1015
|
* const schema = Schema.Struct({
|
|
564
1016
|
* name: Schema.String,
|
|
565
|
-
* age: Schema.
|
|
1017
|
+
* age: Schema.optional(Schema.Number)
|
|
566
1018
|
* })
|
|
567
1019
|
*
|
|
568
|
-
* //
|
|
569
|
-
* type Person = typeof schema
|
|
1020
|
+
* // { readonly name: string; readonly age?: number | undefined }
|
|
1021
|
+
* type Person = typeof schema.Type
|
|
570
1022
|
* ```
|
|
571
1023
|
*
|
|
572
1024
|
* @since 4.0.0
|
|
573
1025
|
*/
|
|
574
1026
|
export const optional = /*#__PURE__*/Struct_.lambda(self => optionalKey(UndefinedOr(self)));
|
|
575
1027
|
/**
|
|
1028
|
+
* Reverses {@link optional}, returning the inner schema (unwrapping `UndefinedOr`).
|
|
1029
|
+
* Only applicable to schemas already wrapped with `optional`.
|
|
1030
|
+
*
|
|
576
1031
|
* @since 4.0.0
|
|
577
1032
|
*/
|
|
578
1033
|
export const required = /*#__PURE__*/Struct_.lambda(self => self.schema.members[0]);
|
|
579
1034
|
/**
|
|
1035
|
+
* Makes a struct field mutable (removes the `readonly` modifier on the property).
|
|
1036
|
+
* Use {@link readonlyKey} to reverse.
|
|
1037
|
+
*
|
|
580
1038
|
* @since 4.0.0
|
|
581
1039
|
*/
|
|
582
1040
|
export const mutableKey = /*#__PURE__*/Struct_.lambda(schema => make(AST.mutableKey(schema.ast), {
|
|
583
1041
|
schema
|
|
584
1042
|
}));
|
|
585
1043
|
/**
|
|
1044
|
+
* Reverses {@link mutableKey}, returning the inner schema as readonly again.
|
|
1045
|
+
* Only applicable to schemas already wrapped with `mutableKey`.
|
|
1046
|
+
*
|
|
586
1047
|
* @since 4.0.0
|
|
587
1048
|
*/
|
|
588
1049
|
export const readonlyKey = /*#__PURE__*/Struct_.lambda(self => self.schema);
|
|
589
1050
|
/**
|
|
1051
|
+
* Extracts the type-side schema: sets `Encoded` to equal the decoded `Type`,
|
|
1052
|
+
* discarding the encoding transformation path.
|
|
1053
|
+
*
|
|
590
1054
|
* @since 4.0.0
|
|
591
1055
|
*/
|
|
592
1056
|
export const toType = /*#__PURE__*/Struct_.lambda(schema => make(AST.toType(schema.ast), {
|
|
593
1057
|
schema
|
|
594
1058
|
}));
|
|
595
1059
|
/**
|
|
1060
|
+
* Extracts the encoded-side schema: sets `Type` to equal the `Encoded`,
|
|
1061
|
+
* discarding the decoding transformation path.
|
|
1062
|
+
*
|
|
596
1063
|
* @since 4.0.0
|
|
597
1064
|
*/
|
|
598
1065
|
export const toEncoded = /*#__PURE__*/Struct_.lambda(schema => make(AST.toEncoded(schema.ast), {
|
|
@@ -612,6 +1079,16 @@ export function flip(schema) {
|
|
|
612
1079
|
});
|
|
613
1080
|
}
|
|
614
1081
|
/**
|
|
1082
|
+
* Creates a schema for a single literal value (string, number, bigint, boolean, or null).
|
|
1083
|
+
*
|
|
1084
|
+
* **Example** (String literal)
|
|
1085
|
+
* ```ts
|
|
1086
|
+
* import { Schema } from "effect"
|
|
1087
|
+
*
|
|
1088
|
+
* const schema = Schema.Literal("hello")
|
|
1089
|
+
* // Type: Schema.Literal<"hello">
|
|
1090
|
+
* ```
|
|
1091
|
+
*
|
|
615
1092
|
* @see {@link Literals} for a schema that represents a union of literals.
|
|
616
1093
|
* @see {@link tag} for a schema that represents a literal value that can be
|
|
617
1094
|
* used as a discriminator field in tagged unions and has a constructor default.
|
|
@@ -633,6 +1110,18 @@ function templateLiteralFromParts(parts) {
|
|
|
633
1110
|
return new AST.TemplateLiteral(parts.map(part => isSchema(part) ? part.ast : new AST.Literal(part)));
|
|
634
1111
|
}
|
|
635
1112
|
/**
|
|
1113
|
+
* Creates a schema that validates strings matching a template literal pattern. Each part can be
|
|
1114
|
+
* a literal string/number/bigint or a schema whose encoded type is a string, number, or bigint.
|
|
1115
|
+
*
|
|
1116
|
+
* **Example** (URL path pattern)
|
|
1117
|
+
* ```ts
|
|
1118
|
+
* import { Schema } from "effect"
|
|
1119
|
+
*
|
|
1120
|
+
* const schema = Schema.TemplateLiteral(["/user/", Schema.Number])
|
|
1121
|
+
* // matches strings like "/user/123", "/user/42", etc.
|
|
1122
|
+
* ```
|
|
1123
|
+
*
|
|
1124
|
+
* @see {@link TemplateLiteralParser} for a schema that also parses matched parts into a tuple.
|
|
636
1125
|
* @since 4.0.0
|
|
637
1126
|
*/
|
|
638
1127
|
export function TemplateLiteral(parts) {
|
|
@@ -641,14 +1130,41 @@ export function TemplateLiteral(parts) {
|
|
|
641
1130
|
});
|
|
642
1131
|
}
|
|
643
1132
|
/**
|
|
1133
|
+
* Like {@link TemplateLiteral} but decodes the matched string into a readonly tuple of typed values,
|
|
1134
|
+
* one element per schema part.
|
|
1135
|
+
*
|
|
1136
|
+
* **Example** (Parse path parameters)
|
|
1137
|
+
* ```ts
|
|
1138
|
+
* import { Schema } from "effect"
|
|
1139
|
+
*
|
|
1140
|
+
* const schema = Schema.TemplateLiteralParser(["/user/", Schema.NumberFromString])
|
|
1141
|
+
* // decodes "/user/42" => readonly ["/user/", 42]
|
|
1142
|
+
* ```
|
|
1143
|
+
*
|
|
1144
|
+
* @see {@link TemplateLiteral} for a validation-only version that keeps the string encoded.
|
|
644
1145
|
* @since 4.0.0
|
|
645
1146
|
*/
|
|
646
1147
|
export function TemplateLiteralParser(parts) {
|
|
647
1148
|
return make(templateLiteralFromParts(parts).asTemplateLiteralParser(), {
|
|
648
|
-
parts
|
|
1149
|
+
parts
|
|
649
1150
|
});
|
|
650
1151
|
}
|
|
651
1152
|
/**
|
|
1153
|
+
* Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
|
|
1154
|
+
*
|
|
1155
|
+
* **Example** (Direction enum)
|
|
1156
|
+
* ```ts
|
|
1157
|
+
* import { Schema } from "effect"
|
|
1158
|
+
*
|
|
1159
|
+
* enum Direction {
|
|
1160
|
+
* Up = "Up",
|
|
1161
|
+
* Down = "Down"
|
|
1162
|
+
* }
|
|
1163
|
+
*
|
|
1164
|
+
* const schema = Schema.Enum(Direction)
|
|
1165
|
+
* // accepts "Up" or "Down"
|
|
1166
|
+
* ```
|
|
1167
|
+
*
|
|
652
1168
|
* @since 4.0.0
|
|
653
1169
|
*/
|
|
654
1170
|
export function Enum(enums) {
|
|
@@ -657,84 +1173,102 @@ export function Enum(enums) {
|
|
|
657
1173
|
});
|
|
658
1174
|
}
|
|
659
1175
|
/**
|
|
1176
|
+
* Schema for the `never` type. Always fails validation — no value satisfies it.
|
|
1177
|
+
*
|
|
660
1178
|
* @since 4.0.0
|
|
661
1179
|
*/
|
|
662
1180
|
export const Never = /*#__PURE__*/make(AST.never);
|
|
663
1181
|
/**
|
|
1182
|
+
* Schema for the `any` type. Accepts any value without validation.
|
|
1183
|
+
*
|
|
1184
|
+
* @see {@link Unknown} for a safer alternative that uses `unknown`.
|
|
664
1185
|
* @since 4.0.0
|
|
665
1186
|
*/
|
|
666
1187
|
export const Any = /*#__PURE__*/make(AST.any);
|
|
667
1188
|
/**
|
|
1189
|
+
* Schema for the `unknown` type. Accepts any value without validation.
|
|
1190
|
+
*
|
|
1191
|
+
* @see {@link Any} for the `any` variant.
|
|
668
1192
|
* @since 4.0.0
|
|
669
1193
|
*/
|
|
670
1194
|
export const Unknown = /*#__PURE__*/make(AST.unknown);
|
|
671
1195
|
/**
|
|
1196
|
+
* Schema for the `null` literal. Validates that the input is strictly `null`.
|
|
1197
|
+
*
|
|
1198
|
+
* @see {@link NullOr} for a union with another schema.
|
|
672
1199
|
* @since 4.0.0
|
|
673
1200
|
*/
|
|
674
1201
|
export const Null = /*#__PURE__*/make(AST.null);
|
|
675
1202
|
/**
|
|
1203
|
+
* Schema for the `undefined` literal. Validates that the input is strictly `undefined`.
|
|
1204
|
+
*
|
|
1205
|
+
* @see {@link UndefinedOr} for a union with another schema.
|
|
676
1206
|
* @since 4.0.0
|
|
677
1207
|
*/
|
|
678
1208
|
export const Undefined = /*#__PURE__*/make(AST.undefined);
|
|
679
1209
|
/**
|
|
680
|
-
*
|
|
1210
|
+
* Schema for `string` values. Validates that the input is `typeof` `"string"`.
|
|
681
1211
|
*
|
|
682
1212
|
* @since 4.0.0
|
|
683
1213
|
*/
|
|
684
1214
|
export const String = /*#__PURE__*/make(AST.string);
|
|
685
1215
|
/**
|
|
686
|
-
*
|
|
1216
|
+
* Schema for `number` values, including `NaN`, `Infinity`, and `-Infinity`.
|
|
687
1217
|
*
|
|
688
1218
|
* **Default Json Serializer**
|
|
689
1219
|
*
|
|
690
|
-
* -
|
|
691
|
-
* -
|
|
1220
|
+
* - Finite numbers are serialized as numbers.
|
|
1221
|
+
* - Non-finite values are serialized as strings (`"NaN"`, `"Infinity"`, `"-Infinity"`).
|
|
692
1222
|
*
|
|
1223
|
+
* @see {@link Finite} for a schema that excludes non-finite values.
|
|
693
1224
|
* @since 4.0.0
|
|
694
1225
|
*/
|
|
695
1226
|
export const Number = /*#__PURE__*/make(AST.number);
|
|
696
1227
|
/**
|
|
697
|
-
*
|
|
1228
|
+
* Schema for `boolean` values. Validates that the input is `typeof` `"boolean"`.
|
|
698
1229
|
*
|
|
699
1230
|
* @category Boolean
|
|
700
1231
|
* @since 4.0.0
|
|
701
1232
|
*/
|
|
702
1233
|
export const Boolean = /*#__PURE__*/make(AST.boolean);
|
|
703
1234
|
/**
|
|
704
|
-
*
|
|
1235
|
+
* Schema for `symbol` values. Validates that the input is `typeof` `"symbol"`.
|
|
705
1236
|
*
|
|
1237
|
+
* @see {@link UniqueSymbol} for a schema that matches a specific symbol.
|
|
706
1238
|
* @since 4.0.0
|
|
707
1239
|
*/
|
|
708
1240
|
export const Symbol = /*#__PURE__*/make(AST.symbol);
|
|
709
1241
|
/**
|
|
710
|
-
*
|
|
1242
|
+
* Schema for `bigint` values. Validates that the input is `typeof` `"bigint"`.
|
|
711
1243
|
*
|
|
712
1244
|
* @since 4.0.0
|
|
713
1245
|
*/
|
|
714
1246
|
export const BigInt = /*#__PURE__*/make(AST.bigInt);
|
|
715
1247
|
/**
|
|
716
|
-
*
|
|
1248
|
+
* Schema for the `void` type. Accepts `undefined` as the encoded value.
|
|
717
1249
|
*
|
|
718
1250
|
* @since 4.0.0
|
|
719
1251
|
*/
|
|
720
1252
|
export const Void = /*#__PURE__*/make(AST.void);
|
|
721
1253
|
/**
|
|
722
|
-
*
|
|
1254
|
+
* Schema for the `object` type. Validates that the input is a non-null object or function
|
|
1255
|
+
* (i.e. `typeof value === "object" && value !== null || typeof value === "function"`).
|
|
723
1256
|
*
|
|
724
1257
|
* @since 4.0.0
|
|
725
1258
|
*/
|
|
726
1259
|
export const ObjectKeyword = /*#__PURE__*/make(AST.objectKeyword);
|
|
727
1260
|
/**
|
|
728
|
-
*
|
|
729
|
-
*
|
|
730
|
-
* **Example**
|
|
1261
|
+
* Creates a schema for a specific symbol. Only that exact symbol satisfies the schema.
|
|
731
1262
|
*
|
|
1263
|
+
* **Example** (Specific symbol)
|
|
732
1264
|
* ```ts
|
|
733
1265
|
* import { Schema } from "effect"
|
|
734
1266
|
*
|
|
735
|
-
* const
|
|
736
|
-
* const schema = Schema.UniqueSymbol(
|
|
1267
|
+
* const mySymbol = Symbol.for("mySymbol")
|
|
1268
|
+
* const schema = Schema.UniqueSymbol(mySymbol)
|
|
737
1269
|
* ```
|
|
1270
|
+
*
|
|
1271
|
+
* @see {@link Symbol} for a schema that accepts any symbol.
|
|
738
1272
|
* @since 4.0.0
|
|
739
1273
|
*/
|
|
740
1274
|
export function UniqueSymbol(symbol) {
|
|
@@ -750,6 +1284,34 @@ function makeStruct(ast, fields) {
|
|
|
750
1284
|
});
|
|
751
1285
|
}
|
|
752
1286
|
/**
|
|
1287
|
+
* Defines a struct schema from a map of field schemas.
|
|
1288
|
+
*
|
|
1289
|
+
* Each field value is a schema. Use {@link optionalKey} or {@link optional} to
|
|
1290
|
+
* mark fields as optional, and {@link mutableKey} to mark them as mutable.
|
|
1291
|
+
*
|
|
1292
|
+
* The resulting schema's `Type` is a readonly object type with the fields'
|
|
1293
|
+
* decoded types. The `Encoded` form mirrors the field schemas' encoded types.
|
|
1294
|
+
*
|
|
1295
|
+
* **Example** (Basic struct)
|
|
1296
|
+
*
|
|
1297
|
+
* ```ts
|
|
1298
|
+
* import { Schema } from "effect"
|
|
1299
|
+
*
|
|
1300
|
+
* const Person = Schema.Struct({
|
|
1301
|
+
* name: Schema.String,
|
|
1302
|
+
* age: Schema.Number,
|
|
1303
|
+
* email: Schema.optionalKey(Schema.String)
|
|
1304
|
+
* })
|
|
1305
|
+
*
|
|
1306
|
+
* // { readonly name: string; readonly age: number; readonly email?: string }
|
|
1307
|
+
* type Person = typeof Person.Type
|
|
1308
|
+
*
|
|
1309
|
+
* const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
|
|
1310
|
+
* console.log(alice)
|
|
1311
|
+
* // { name: 'Alice', age: 30 }
|
|
1312
|
+
* ```
|
|
1313
|
+
*
|
|
1314
|
+
* @category Constructors
|
|
753
1315
|
* @since 4.0.0
|
|
754
1316
|
*/
|
|
755
1317
|
export function Struct(fields) {
|
|
@@ -777,6 +1339,26 @@ export function fieldsAssign(fields) {
|
|
|
777
1339
|
return Struct_.lambda(struct => struct.mapFields(Struct_.assign(fields)));
|
|
778
1340
|
}
|
|
779
1341
|
/**
|
|
1342
|
+
* Renames struct keys in the encoded form without changing the decoded type.
|
|
1343
|
+
*
|
|
1344
|
+
* Takes a partial mapping `{ decodedKey: encodedKey }` and produces a
|
|
1345
|
+
* transformation schema that decodes from the renamed keys and encodes back to
|
|
1346
|
+
* the renamed keys. Keys not present in the mapping are left unchanged.
|
|
1347
|
+
*
|
|
1348
|
+
* **Example** (Rename `name` to `full_name` in the encoded form)
|
|
1349
|
+
*
|
|
1350
|
+
* ```ts
|
|
1351
|
+
* import { Schema } from "effect"
|
|
1352
|
+
*
|
|
1353
|
+
* const Person = Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
1354
|
+
* const Encoded = Person.pipe(Schema.encodeKeys({ name: "full_name" }))
|
|
1355
|
+
*
|
|
1356
|
+
* // Decodes { full_name: "Alice", age: 30 } → { name: "Alice", age: 30 }
|
|
1357
|
+
* const alice = Schema.decodeUnknownSync(Encoded)({ full_name: "Alice", age: 30 })
|
|
1358
|
+
* console.log(alice)
|
|
1359
|
+
* // { name: 'Alice', age: 30 }
|
|
1360
|
+
* ```
|
|
1361
|
+
*
|
|
780
1362
|
* @category Struct transformations
|
|
781
1363
|
* @since 4.0.0
|
|
782
1364
|
*/
|
|
@@ -785,11 +1367,12 @@ export function encodeKeys(mapping) {
|
|
|
785
1367
|
const fields = {};
|
|
786
1368
|
const reverseMapping = {};
|
|
787
1369
|
for (const k in self.fields) {
|
|
1370
|
+
const encoded = toEncoded(self.fields[k]);
|
|
788
1371
|
if (Object.hasOwn(mapping, k)) {
|
|
789
|
-
fields[mapping[k]] =
|
|
1372
|
+
fields[mapping[k]] = encoded;
|
|
790
1373
|
reverseMapping[mapping[k]] = k;
|
|
791
1374
|
} else {
|
|
792
|
-
fields[k] =
|
|
1375
|
+
fields[k] = encoded;
|
|
793
1376
|
}
|
|
794
1377
|
}
|
|
795
1378
|
return Struct(fields).pipe(decodeTo(self, Transformation.transform({
|
|
@@ -799,6 +1382,31 @@ export function encodeKeys(mapping) {
|
|
|
799
1382
|
};
|
|
800
1383
|
}
|
|
801
1384
|
/**
|
|
1385
|
+
* Adds derived fields to a struct schema during decoding.
|
|
1386
|
+
*
|
|
1387
|
+
* Each new field is derived from the decoded struct value via a function that
|
|
1388
|
+
* returns `Option`. On encoding the derived fields are stripped. This allows
|
|
1389
|
+
* computed or enriched fields to live in the decoded type without appearing in
|
|
1390
|
+
* the encoded form.
|
|
1391
|
+
*
|
|
1392
|
+
* **Example** (Add a computed `fullName` field)
|
|
1393
|
+
*
|
|
1394
|
+
* ```ts
|
|
1395
|
+
* import { Option, Schema } from "effect"
|
|
1396
|
+
*
|
|
1397
|
+
* const Person = Schema.Struct({ first: Schema.String, last: Schema.String })
|
|
1398
|
+
* const Extended = Person.pipe(
|
|
1399
|
+
* Schema.extendTo(
|
|
1400
|
+
* { fullName: Schema.String },
|
|
1401
|
+
* { fullName: (p) => Option.some(`${p.first} ${p.last}`) }
|
|
1402
|
+
* )
|
|
1403
|
+
* )
|
|
1404
|
+
*
|
|
1405
|
+
* const alice = Schema.decodeUnknownSync(Extended)({ first: "Alice", last: "Smith" })
|
|
1406
|
+
* console.log(alice.fullName)
|
|
1407
|
+
* // Alice Smith
|
|
1408
|
+
* ```
|
|
1409
|
+
*
|
|
802
1410
|
* @since 4.0.0
|
|
803
1411
|
* @experimental
|
|
804
1412
|
*/
|
|
@@ -838,6 +1446,24 @@ derive) {
|
|
|
838
1446
|
};
|
|
839
1447
|
}
|
|
840
1448
|
/**
|
|
1449
|
+
* Defines a record (dictionary) schema with typed keys and values.
|
|
1450
|
+
*
|
|
1451
|
+
* **Example** (String-keyed record of numbers)
|
|
1452
|
+
*
|
|
1453
|
+
* ```ts
|
|
1454
|
+
* import { Schema } from "effect"
|
|
1455
|
+
*
|
|
1456
|
+
* const schema = Schema.Record(Schema.String, Schema.Number)
|
|
1457
|
+
*
|
|
1458
|
+
* // { readonly [x: string]: number }
|
|
1459
|
+
* type R = typeof schema.Type
|
|
1460
|
+
*
|
|
1461
|
+
* const result = Schema.decodeUnknownSync(schema)({ a: 1, b: 2 })
|
|
1462
|
+
* console.log(result)
|
|
1463
|
+
* // { a: 1, b: 2 }
|
|
1464
|
+
* ```
|
|
1465
|
+
*
|
|
1466
|
+
* @category Constructors
|
|
841
1467
|
* @since 4.0.0
|
|
842
1468
|
*/
|
|
843
1469
|
export function Record(key, value, options) {
|
|
@@ -848,6 +1474,24 @@ export function Record(key, value, options) {
|
|
|
848
1474
|
});
|
|
849
1475
|
}
|
|
850
1476
|
/**
|
|
1477
|
+
* Extends a struct schema with one or more record (index-signature) schemas,
|
|
1478
|
+
* producing a schema whose decoded type intersects the struct and all records.
|
|
1479
|
+
*
|
|
1480
|
+
* **Example** (Struct with string-indexed extra keys)
|
|
1481
|
+
*
|
|
1482
|
+
* ```ts
|
|
1483
|
+
* import { Schema } from "effect"
|
|
1484
|
+
*
|
|
1485
|
+
* const schema = Schema.StructWithRest(
|
|
1486
|
+
* Schema.Struct({ id: Schema.Number }),
|
|
1487
|
+
* [Schema.Record(Schema.String, Schema.String)]
|
|
1488
|
+
* )
|
|
1489
|
+
*
|
|
1490
|
+
* // { readonly id: number } & { readonly [x: string]: string }
|
|
1491
|
+
* type T = typeof schema.Type
|
|
1492
|
+
* ```
|
|
1493
|
+
*
|
|
1494
|
+
* @category Constructors
|
|
851
1495
|
* @since 4.0.0
|
|
852
1496
|
*/
|
|
853
1497
|
export function StructWithRest(schema, records) {
|
|
@@ -866,6 +1510,20 @@ function makeTuple(ast, elements) {
|
|
|
866
1510
|
});
|
|
867
1511
|
}
|
|
868
1512
|
/**
|
|
1513
|
+
* Defines a fixed-length tuple schema from an array of element schemas.
|
|
1514
|
+
*
|
|
1515
|
+
* **Example** (Pair of string and number)
|
|
1516
|
+
*
|
|
1517
|
+
* ```ts
|
|
1518
|
+
* import { Schema } from "effect"
|
|
1519
|
+
*
|
|
1520
|
+
* const schema = Schema.Tuple([Schema.String, Schema.Number])
|
|
1521
|
+
*
|
|
1522
|
+
* const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
|
|
1523
|
+
* console.log(pair)
|
|
1524
|
+
* // [ 'hello', 42 ]
|
|
1525
|
+
* ```
|
|
1526
|
+
*
|
|
869
1527
|
* @category Constructors
|
|
870
1528
|
* @since 4.0.0
|
|
871
1529
|
*/
|
|
@@ -873,6 +1531,26 @@ export function Tuple(elements) {
|
|
|
873
1531
|
return makeTuple(AST.tuple(elements), elements);
|
|
874
1532
|
}
|
|
875
1533
|
/**
|
|
1534
|
+
* Extends a fixed-length tuple schema with rest elements, creating a variadic
|
|
1535
|
+
* tuple that starts with the fixed elements and ends with zero or more rest
|
|
1536
|
+
* elements.
|
|
1537
|
+
*
|
|
1538
|
+
* **Example** (Tuple with rest)
|
|
1539
|
+
*
|
|
1540
|
+
* ```ts
|
|
1541
|
+
* import { Schema } from "effect"
|
|
1542
|
+
*
|
|
1543
|
+
* // [string, number, ...boolean[]]
|
|
1544
|
+
* const schema = Schema.TupleWithRest(
|
|
1545
|
+
* Schema.Tuple([Schema.String, Schema.Number]),
|
|
1546
|
+
* [Schema.Boolean]
|
|
1547
|
+
* )
|
|
1548
|
+
*
|
|
1549
|
+
* const result = Schema.decodeUnknownSync(schema)(["hello", 1, true, false])
|
|
1550
|
+
* console.log(result)
|
|
1551
|
+
* // [ 'hello', 1, true, false ]
|
|
1552
|
+
* ```
|
|
1553
|
+
*
|
|
876
1554
|
* @category Constructors
|
|
877
1555
|
* @since 4.0.0
|
|
878
1556
|
*/
|
|
@@ -886,16 +1564,70 @@ export function TupleWithRest(schema, rest) {
|
|
|
886
1564
|
* @category Constructors
|
|
887
1565
|
* @since 4.0.0
|
|
888
1566
|
*/
|
|
889
|
-
|
|
1567
|
+
const ArraySchema = /*#__PURE__*/Struct_.lambda(schema => make(new AST.Arrays(false, [], [schema.ast]), {
|
|
890
1568
|
schema
|
|
891
1569
|
}));
|
|
1570
|
+
export {
|
|
1571
|
+
/**
|
|
1572
|
+
* Defines a `ReadonlyArray` schema for a given element schema.
|
|
1573
|
+
*
|
|
1574
|
+
* **Example** (Array of strings)
|
|
1575
|
+
*
|
|
1576
|
+
* ```ts
|
|
1577
|
+
* import { Schema } from "effect"
|
|
1578
|
+
*
|
|
1579
|
+
* const schema = Schema.Array(Schema.String)
|
|
1580
|
+
*
|
|
1581
|
+
* const result = Schema.decodeUnknownSync(schema)(["a", "b", "c"])
|
|
1582
|
+
* console.log(result)
|
|
1583
|
+
* // [ 'a', 'b', 'c' ]
|
|
1584
|
+
* ```
|
|
1585
|
+
*
|
|
1586
|
+
* @category Constructors
|
|
1587
|
+
* @since 4.0.0
|
|
1588
|
+
*/
|
|
1589
|
+
ArraySchema as Array };
|
|
892
1590
|
/**
|
|
1591
|
+
* Defines a non-empty `ReadonlyArray` schema — at least one element required.
|
|
1592
|
+
* Type is `readonly [T, ...T[]]`.
|
|
1593
|
+
*
|
|
1594
|
+
* **Example** (Non-empty array of numbers)
|
|
1595
|
+
*
|
|
1596
|
+
* ```ts
|
|
1597
|
+
* import { Schema } from "effect"
|
|
1598
|
+
*
|
|
1599
|
+
* const schema = Schema.NonEmptyArray(Schema.Number)
|
|
1600
|
+
*
|
|
1601
|
+
* Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
|
|
1602
|
+
* Schema.decodeUnknownSync(schema)([]) // throws
|
|
1603
|
+
* ```
|
|
1604
|
+
*
|
|
893
1605
|
* @category Constructors
|
|
894
1606
|
* @since 4.0.0
|
|
895
1607
|
*/
|
|
896
1608
|
export const NonEmptyArray = /*#__PURE__*/Struct_.lambda(schema => make(new AST.Arrays(false, [schema.ast], [schema.ast]), {
|
|
897
1609
|
schema
|
|
898
1610
|
}));
|
|
1611
|
+
/**
|
|
1612
|
+
* Decodes a single value or an array of values into an array.
|
|
1613
|
+
*
|
|
1614
|
+
* Decoding:
|
|
1615
|
+
* - a single value is decoded as a one-element array
|
|
1616
|
+
* - an array is decoded as-is
|
|
1617
|
+
*
|
|
1618
|
+
* Encoding:
|
|
1619
|
+
* - a one-element array is encoded as a single value
|
|
1620
|
+
* - arrays with more than one element are encoded as arrays
|
|
1621
|
+
*
|
|
1622
|
+
* @category Arrays
|
|
1623
|
+
* @since 4.0.0
|
|
1624
|
+
*/
|
|
1625
|
+
export function ArrayEnsure(schema) {
|
|
1626
|
+
return Union([schema, ArraySchema(schema)]).pipe(decodeTo(ArraySchema(toType(schema)), Transformation.transform({
|
|
1627
|
+
decode: Arr.ensure,
|
|
1628
|
+
encode: array => array.length === 1 ? array[0] : array
|
|
1629
|
+
})));
|
|
1630
|
+
}
|
|
899
1631
|
/**
|
|
900
1632
|
* Returns a new array schema that ensures all elements are unique.
|
|
901
1633
|
*
|
|
@@ -906,10 +1638,21 @@ export const NonEmptyArray = /*#__PURE__*/Struct_.lambda(schema => make(new AST.
|
|
|
906
1638
|
* @since 4.0.0
|
|
907
1639
|
*/
|
|
908
1640
|
export function UniqueArray(item) {
|
|
909
|
-
return
|
|
1641
|
+
return ArraySchema(item).check(isUnique());
|
|
910
1642
|
}
|
|
911
1643
|
/**
|
|
912
|
-
* Makes
|
|
1644
|
+
* Makes an array or tuple schema mutable, removing the `readonly` modifier.
|
|
1645
|
+
*
|
|
1646
|
+
* **Example** (Mutable array)
|
|
1647
|
+
*
|
|
1648
|
+
* ```ts
|
|
1649
|
+
* import { Schema } from "effect"
|
|
1650
|
+
*
|
|
1651
|
+
* const schema = Schema.mutable(Schema.Array(Schema.Number))
|
|
1652
|
+
*
|
|
1653
|
+
* // number[] (mutable)
|
|
1654
|
+
* type T = typeof schema.Type
|
|
1655
|
+
* ```
|
|
913
1656
|
*
|
|
914
1657
|
* @since 4.0.0
|
|
915
1658
|
*/
|
|
@@ -928,12 +1671,23 @@ function makeUnion(ast, members) {
|
|
|
928
1671
|
});
|
|
929
1672
|
}
|
|
930
1673
|
/**
|
|
931
|
-
* Creates a schema
|
|
1674
|
+
* Creates a union schema from an array of member schemas. Members are tested in
|
|
1675
|
+
* order; the first match is returned.
|
|
1676
|
+
*
|
|
1677
|
+
* Optionally, specify `mode`:
|
|
1678
|
+
* - `"anyOf"` (default) — matches if any member matches.
|
|
1679
|
+
* - `"oneOf"` — matches if exactly one member matches.
|
|
932
1680
|
*
|
|
933
|
-
*
|
|
1681
|
+
* **Example** (String or number union)
|
|
934
1682
|
*
|
|
935
|
-
*
|
|
936
|
-
*
|
|
1683
|
+
* ```ts
|
|
1684
|
+
* import { Schema } from "effect"
|
|
1685
|
+
*
|
|
1686
|
+
* const schema = Schema.Union([Schema.String, Schema.Number])
|
|
1687
|
+
*
|
|
1688
|
+
* Schema.decodeUnknownSync(schema)("hello") // "hello"
|
|
1689
|
+
* Schema.decodeUnknownSync(schema)(42) // 42
|
|
1690
|
+
* ```
|
|
937
1691
|
*
|
|
938
1692
|
* @category Constructors
|
|
939
1693
|
* @since 4.0.0
|
|
@@ -942,6 +1696,16 @@ export function Union(members, options) {
|
|
|
942
1696
|
return makeUnion(AST.union(members, options?.mode ?? "anyOf", undefined), members);
|
|
943
1697
|
}
|
|
944
1698
|
/**
|
|
1699
|
+
* Creates a union schema from an array of literal values.
|
|
1700
|
+
*
|
|
1701
|
+
* **Example** (Status codes)
|
|
1702
|
+
* ```ts
|
|
1703
|
+
* import { Schema } from "effect"
|
|
1704
|
+
*
|
|
1705
|
+
* const schema = Schema.Literals(["active", "inactive", "pending"])
|
|
1706
|
+
* // accepts "active", "inactive", or "pending"
|
|
1707
|
+
* ```
|
|
1708
|
+
*
|
|
945
1709
|
* @see {@link Literal} for a schema that represents a single literal.
|
|
946
1710
|
* @category Constructors
|
|
947
1711
|
* @since 4.0.0
|
|
@@ -963,16 +1727,21 @@ export function Literals(literals) {
|
|
|
963
1727
|
});
|
|
964
1728
|
}
|
|
965
1729
|
/**
|
|
1730
|
+
* Creates a union schema of `S | null`.
|
|
1731
|
+
*
|
|
966
1732
|
* @category Constructors
|
|
967
1733
|
* @since 4.0.0
|
|
968
1734
|
*/
|
|
969
1735
|
export const NullOr = /*#__PURE__*/Struct_.lambda(self => Union([self, Null]));
|
|
970
1736
|
/**
|
|
1737
|
+
* Creates a union schema of `S | undefined`.
|
|
1738
|
+
*
|
|
971
1739
|
* @category Constructors
|
|
972
1740
|
* @since 4.0.0
|
|
973
1741
|
*/
|
|
974
1742
|
export const UndefinedOr = /*#__PURE__*/Struct_.lambda(self => Union([self, Undefined]));
|
|
975
1743
|
/**
|
|
1744
|
+
* Creates a union schema of `S | null | undefined`.
|
|
976
1745
|
* @category Constructors
|
|
977
1746
|
* @since 4.0.0
|
|
978
1747
|
*/
|
|
@@ -982,6 +1751,21 @@ export const NullishOr = /*#__PURE__*/Struct_.lambda(self => Union([self, Null,
|
|
|
982
1751
|
* essential for creating recursive schemas where a schema references itself,
|
|
983
1752
|
* preventing infinite recursion during schema definition.
|
|
984
1753
|
*
|
|
1754
|
+
* **Example** (Recursive tree schema)
|
|
1755
|
+
* ```ts
|
|
1756
|
+
* import { Schema } from "effect"
|
|
1757
|
+
*
|
|
1758
|
+
* interface Tree {
|
|
1759
|
+
* readonly value: number
|
|
1760
|
+
* readonly children: ReadonlyArray<Tree>
|
|
1761
|
+
* }
|
|
1762
|
+
*
|
|
1763
|
+
* const Tree = Schema.Struct({
|
|
1764
|
+
* value: Schema.Number,
|
|
1765
|
+
* children: Schema.Array(Schema.suspend((): Schema.Codec<Tree> => Tree))
|
|
1766
|
+
* })
|
|
1767
|
+
* ```
|
|
1768
|
+
*
|
|
985
1769
|
* @category Constructors
|
|
986
1770
|
* @since 4.0.0
|
|
987
1771
|
*/
|
|
@@ -989,6 +1773,18 @@ export function suspend(f) {
|
|
|
989
1773
|
return make(new AST.Suspend(() => f().ast));
|
|
990
1774
|
}
|
|
991
1775
|
/**
|
|
1776
|
+
* Pipeable function that attaches one or more filter checks to a schema without
|
|
1777
|
+
* changing the TypeScript type.
|
|
1778
|
+
*
|
|
1779
|
+
* **Example** (Adding checks to a schema)
|
|
1780
|
+
* ```ts
|
|
1781
|
+
* import { Schema } from "effect"
|
|
1782
|
+
*
|
|
1783
|
+
* const AgeSchema = Schema.Number.pipe(
|
|
1784
|
+
* Schema.check(Schema.isGreaterThanOrEqualTo(0), Schema.isLessThanOrEqualTo(120))
|
|
1785
|
+
* )
|
|
1786
|
+
* ```
|
|
1787
|
+
*
|
|
992
1788
|
* @category Filtering
|
|
993
1789
|
* @since 4.0.0
|
|
994
1790
|
*/
|
|
@@ -996,6 +1792,9 @@ export function check(...checks) {
|
|
|
996
1792
|
return self => self.check(...checks);
|
|
997
1793
|
}
|
|
998
1794
|
/**
|
|
1795
|
+
* Narrows the TypeScript type of a schema's output via a type guard predicate,
|
|
1796
|
+
* attaching the guard as a runtime filter check.
|
|
1797
|
+
*
|
|
999
1798
|
* @category Filtering
|
|
1000
1799
|
* @since 4.0.0
|
|
1001
1800
|
*/
|
|
@@ -1005,7 +1804,8 @@ export function refine(refinement, annotations) {
|
|
|
1005
1804
|
});
|
|
1006
1805
|
}
|
|
1007
1806
|
/**
|
|
1008
|
-
* Adds a brand to a schema
|
|
1807
|
+
* Adds a nominal brand to a schema, intersecting the output type with
|
|
1808
|
+
* `Brand.Brand<B>` to prevent accidental mixing of structurally identical types.
|
|
1009
1809
|
*
|
|
1010
1810
|
* @category Branding
|
|
1011
1811
|
* @since 4.0.0
|
|
@@ -1017,7 +1817,10 @@ export function brand(identifier) {
|
|
|
1017
1817
|
});
|
|
1018
1818
|
}
|
|
1019
1819
|
/**
|
|
1020
|
-
* @
|
|
1820
|
+
* Creates a branded schema from a {@link Brand.Constructor}, applying the
|
|
1821
|
+
* constructor's checks and brand tag to the underlying schema.
|
|
1822
|
+
*
|
|
1823
|
+
* @category Branding
|
|
1021
1824
|
* @since 4.0.0
|
|
1022
1825
|
*/
|
|
1023
1826
|
export function fromBrand(identifier, ctor) {
|
|
@@ -1026,6 +1829,25 @@ export function fromBrand(identifier, ctor) {
|
|
|
1026
1829
|
};
|
|
1027
1830
|
}
|
|
1028
1831
|
/**
|
|
1832
|
+
* Intercepts the decoding pipeline of a schema.
|
|
1833
|
+
*
|
|
1834
|
+
* The provided function receives the current decoding `Effect` and `ParseOptions`,
|
|
1835
|
+
* and returns a new `Effect` — potentially adding service requirements (`RD`),
|
|
1836
|
+
* recovering from errors, or augmenting the result.
|
|
1837
|
+
*
|
|
1838
|
+
* **Example** (Logging decode failures)
|
|
1839
|
+
*
|
|
1840
|
+
* ```ts
|
|
1841
|
+
* import { Effect, Schema } from "effect"
|
|
1842
|
+
*
|
|
1843
|
+
* const Logged = Schema.String.pipe(
|
|
1844
|
+
* Schema.middlewareDecoding((effect) =>
|
|
1845
|
+
* Effect.tapError(effect, (issue) => Effect.log("decode failed", issue))
|
|
1846
|
+
* )
|
|
1847
|
+
* )
|
|
1848
|
+
* ```
|
|
1849
|
+
*
|
|
1850
|
+
* @see {@link catchDecoding} for a simpler error-recovery variant
|
|
1029
1851
|
* @since 4.0.0
|
|
1030
1852
|
*/
|
|
1031
1853
|
export function middlewareDecoding(decode) {
|
|
@@ -1034,6 +1856,25 @@ export function middlewareDecoding(decode) {
|
|
|
1034
1856
|
});
|
|
1035
1857
|
}
|
|
1036
1858
|
/**
|
|
1859
|
+
* Intercepts the encoding pipeline of a schema.
|
|
1860
|
+
*
|
|
1861
|
+
* The provided function receives the current encoding `Effect` and `ParseOptions`,
|
|
1862
|
+
* and returns a new `Effect` — potentially adding service requirements (`RE`),
|
|
1863
|
+
* recovering from errors, or augmenting the result.
|
|
1864
|
+
*
|
|
1865
|
+
* **Example** (Logging encode failures)
|
|
1866
|
+
*
|
|
1867
|
+
* ```ts
|
|
1868
|
+
* import { Effect, Schema } from "effect"
|
|
1869
|
+
*
|
|
1870
|
+
* const Logged = Schema.String.pipe(
|
|
1871
|
+
* Schema.middlewareEncoding((effect) =>
|
|
1872
|
+
* Effect.tapError(effect, (issue) => Effect.log("encode failed", issue))
|
|
1873
|
+
* )
|
|
1874
|
+
* )
|
|
1875
|
+
* ```
|
|
1876
|
+
*
|
|
1877
|
+
* @see {@link catchEncoding} for a simpler error-recovery variant
|
|
1037
1878
|
* @since 4.0.0
|
|
1038
1879
|
*/
|
|
1039
1880
|
export function middlewareEncoding(encode) {
|
|
@@ -1042,24 +1883,50 @@ export function middlewareEncoding(encode) {
|
|
|
1042
1883
|
});
|
|
1043
1884
|
}
|
|
1044
1885
|
/**
|
|
1886
|
+
* Recovers from a decoding error by providing a fallback value.
|
|
1887
|
+
*
|
|
1888
|
+
* The handler receives the `Issue` and returns an `Effect` that either
|
|
1889
|
+
* succeeds with a fallback value or re-fails with a (possibly different) issue.
|
|
1890
|
+
*
|
|
1891
|
+
* **Example** (Returning a default on decode failure)
|
|
1892
|
+
*
|
|
1893
|
+
* ```ts
|
|
1894
|
+
* import { Effect, Option, Schema } from "effect"
|
|
1895
|
+
*
|
|
1896
|
+
* const schema = Schema.Number.pipe(
|
|
1897
|
+
* Schema.catchDecoding((_issue) => Effect.succeed(Option.some(0)))
|
|
1898
|
+
* )
|
|
1899
|
+
* ```
|
|
1900
|
+
*
|
|
1901
|
+
* @see {@link catchDecodingWithContext} to add service requirements to the handler
|
|
1045
1902
|
* @since 4.0.0
|
|
1046
1903
|
*/
|
|
1047
1904
|
export function catchDecoding(f) {
|
|
1048
1905
|
return catchDecodingWithContext(f);
|
|
1049
1906
|
}
|
|
1050
1907
|
/**
|
|
1908
|
+
* Like {@link catchDecoding}, but the handler may require Effect services (`R`).
|
|
1909
|
+
*
|
|
1051
1910
|
* @since 4.0.0
|
|
1052
1911
|
*/
|
|
1053
1912
|
export function catchDecodingWithContext(f) {
|
|
1054
1913
|
return self => self.pipe(middlewareDecoding(Effect.catchEager(f)));
|
|
1055
1914
|
}
|
|
1056
1915
|
/**
|
|
1916
|
+
* Recovers from an encoding error by providing a fallback value.
|
|
1917
|
+
*
|
|
1918
|
+
* The handler receives the `Issue` and returns an `Effect` that either
|
|
1919
|
+
* succeeds with a fallback value or re-fails with a (possibly different) issue.
|
|
1920
|
+
*
|
|
1921
|
+
* @see {@link catchEncodingWithContext} to add service requirements to the handler
|
|
1057
1922
|
* @since 4.0.0
|
|
1058
1923
|
*/
|
|
1059
1924
|
export function catchEncoding(f) {
|
|
1060
1925
|
return catchEncodingWithContext(f);
|
|
1061
1926
|
}
|
|
1062
1927
|
/**
|
|
1928
|
+
* Like {@link catchEncoding}, but the handler may require Effect services (`R`).
|
|
1929
|
+
*
|
|
1063
1930
|
* @since 4.0.0
|
|
1064
1931
|
*/
|
|
1065
1932
|
export function catchEncodingWithContext(f) {
|
|
@@ -1121,6 +1988,25 @@ export function encodeTo(to, transformation) {
|
|
|
1121
1988
|
};
|
|
1122
1989
|
}
|
|
1123
1990
|
/**
|
|
1991
|
+
* Applies a transformation to a schema's encoded type, creating a new schema where encoding/decoding
|
|
1992
|
+
* operate on `S["Encoded"]` rather than `S["Type"]`.
|
|
1993
|
+
*
|
|
1994
|
+
* The `decode` getter maps `S["Encoded"]` → `S["Encoded"]` (applied during decoding),
|
|
1995
|
+
* and the `encode` getter maps `S["Encoded"]` → `S["Encoded"]` (applied during encoding).
|
|
1996
|
+
*
|
|
1997
|
+
* **Example** (Upper-casing encoded strings)
|
|
1998
|
+
*
|
|
1999
|
+
* ```ts
|
|
2000
|
+
* import { Schema, SchemaGetter } from "effect"
|
|
2001
|
+
*
|
|
2002
|
+
* const UpperFromLower = Schema.String.pipe(
|
|
2003
|
+
* Schema.encode({
|
|
2004
|
+
* decode: SchemaGetter.transform((s: string) => s.toLowerCase()),
|
|
2005
|
+
* encode: SchemaGetter.transform((s: string) => s.toUpperCase())
|
|
2006
|
+
* })
|
|
2007
|
+
* )
|
|
2008
|
+
* ```
|
|
2009
|
+
*
|
|
1124
2010
|
* @since 4.0.0
|
|
1125
2011
|
*/
|
|
1126
2012
|
export function encode(transformation) {
|
|
@@ -1129,22 +2015,66 @@ export function encode(transformation) {
|
|
|
1129
2015
|
};
|
|
1130
2016
|
}
|
|
1131
2017
|
/**
|
|
2018
|
+
* Attaches a constructor default value to a schema field.
|
|
2019
|
+
*
|
|
2020
|
+
* Constructor defaults are applied only during `make*`, not during decoding or
|
|
2021
|
+
* encoding.
|
|
2022
|
+
*
|
|
2023
|
+
* **Example** (Optional field with a static default)
|
|
2024
|
+
*
|
|
2025
|
+
* ```ts
|
|
2026
|
+
* import { Effect, Schema } from "effect"
|
|
2027
|
+
*
|
|
2028
|
+
* const MySchema = Schema.Struct({
|
|
2029
|
+
* name: Schema.String.pipe(
|
|
2030
|
+
* Schema.optionalKey,
|
|
2031
|
+
* Schema.withConstructorDefault(Effect.succeed("anonymous"))
|
|
2032
|
+
* )
|
|
2033
|
+
* })
|
|
2034
|
+
*
|
|
2035
|
+
* const value = MySchema.make({})
|
|
2036
|
+
* // value: { name: "anonymous" }
|
|
2037
|
+
* ```
|
|
2038
|
+
*
|
|
1132
2039
|
* @since 4.0.0
|
|
1133
2040
|
*/
|
|
1134
|
-
export function withConstructorDefault(
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
2041
|
+
export function withConstructorDefault(
|
|
2042
|
+
// `S["~type.make.in"]` instead of `S["Type"]` is intentional here because
|
|
2043
|
+
// it makes easier to define the default value if there are nested defaults
|
|
2044
|
+
defaultValue) {
|
|
2045
|
+
return schema => make(AST.withConstructorDefault(schema.ast, defaultValue), {
|
|
2046
|
+
schema
|
|
2047
|
+
});
|
|
1140
2048
|
}
|
|
1141
2049
|
/**
|
|
2050
|
+
* Makes a struct key optional on the `Encoded` side and provides a default
|
|
2051
|
+
* `Encoded` value when the key is missing during decoding.
|
|
2052
|
+
*
|
|
2053
|
+
* The key uses `optionalKey` on the encoded side, so it may be absent from the
|
|
2054
|
+
* input object but **not** `undefined`. The default value is specified in terms
|
|
2055
|
+
* of the `Encoded` type (before any decoding transformations).
|
|
2056
|
+
*
|
|
1142
2057
|
* **Options**
|
|
1143
2058
|
*
|
|
1144
|
-
* - `encodingStrategy`:
|
|
1145
|
-
* - `passthrough
|
|
1146
|
-
* - `omit`:
|
|
2059
|
+
* - `encodingStrategy`:
|
|
2060
|
+
* - `"passthrough"` (default): include the value in the encoded output.
|
|
2061
|
+
* - `"omit"`: omit the key from the encoded output.
|
|
2062
|
+
*
|
|
2063
|
+
* **Example** (Default for a missing struct key)
|
|
2064
|
+
*
|
|
2065
|
+
* ```ts
|
|
2066
|
+
* import { Effect, Schema } from "effect"
|
|
1147
2067
|
*
|
|
2068
|
+
* const MySchema = Schema.Struct({
|
|
2069
|
+
* name: Schema.String.pipe(Schema.withDecodingDefaultKey(Effect.succeed("anonymous")))
|
|
2070
|
+
* })
|
|
2071
|
+
*
|
|
2072
|
+
* const result = Schema.decodeUnknownSync(MySchema)({})
|
|
2073
|
+
* // result: { name: "anonymous" }
|
|
2074
|
+
* ```
|
|
2075
|
+
*
|
|
2076
|
+
* @see {@link withDecodingDefault} for the value-level variant (key absent **or** `undefined`)
|
|
2077
|
+
* @see {@link withDecodingDefaultTypeKey} for the variant where the default is a `Type` value
|
|
1148
2078
|
* @since 4.0.0
|
|
1149
2079
|
*/
|
|
1150
2080
|
export function withDecodingDefaultKey(defaultValue, options) {
|
|
@@ -1157,12 +2087,58 @@ export function withDecodingDefaultKey(defaultValue, options) {
|
|
|
1157
2087
|
};
|
|
1158
2088
|
}
|
|
1159
2089
|
/**
|
|
2090
|
+
* Makes a struct key optional on the `Encoded` side (`optionalKey`, so the
|
|
2091
|
+
* key may be absent but **not** `undefined`) and provides a default `Type`
|
|
2092
|
+
* value when the key is missing during decoding.
|
|
2093
|
+
*
|
|
2094
|
+
* Unlike {@link withDecodingDefaultKey}, the default value is specified in
|
|
2095
|
+
* terms of the `Type` (decoded) representation, so it does not need to go
|
|
2096
|
+
* through the decoding transformation.
|
|
2097
|
+
*
|
|
1160
2098
|
* **Options**
|
|
1161
2099
|
*
|
|
1162
|
-
* - `encodingStrategy`:
|
|
1163
|
-
* - `passthrough
|
|
1164
|
-
* - `omit`:
|
|
2100
|
+
* - `encodingStrategy`:
|
|
2101
|
+
* - `"passthrough"` (default): include the value in the encoded output.
|
|
2102
|
+
* - `"omit"`: omit the key from the encoded output.
|
|
2103
|
+
*
|
|
2104
|
+
* @see {@link withDecodingDefaultKey} for the variant where the default is an `Encoded` value
|
|
2105
|
+
* @see {@link withDecodingDefaultType} for the value-level variant
|
|
2106
|
+
* @since 4.0.0
|
|
2107
|
+
*/
|
|
2108
|
+
export function withDecodingDefaultTypeKey(defaultValue, options) {
|
|
2109
|
+
return self => {
|
|
2110
|
+
return toType(self).pipe(withDecodingDefaultKey(defaultValue, options), encodeTo(optionalKey(self)));
|
|
2111
|
+
};
|
|
2112
|
+
}
|
|
2113
|
+
/**
|
|
2114
|
+
* Wraps the `Encoded` side with `optional` (key absent **or** `undefined`)
|
|
2115
|
+
* and provides a default `Encoded` value when the field is missing or
|
|
2116
|
+
* `undefined` during decoding.
|
|
2117
|
+
*
|
|
2118
|
+
* The default value is specified in terms of the `Encoded` type (before any
|
|
2119
|
+
* decoding transformations).
|
|
2120
|
+
*
|
|
2121
|
+
* **Options**
|
|
2122
|
+
*
|
|
2123
|
+
* - `encodingStrategy`:
|
|
2124
|
+
* - `"passthrough"` (default): include the value in the encoded output.
|
|
2125
|
+
* - `"omit"`: omit the key from the encoded output.
|
|
2126
|
+
*
|
|
2127
|
+
* **Example** (Default for an optional field value)
|
|
1165
2128
|
*
|
|
2129
|
+
* ```ts
|
|
2130
|
+
* import { Effect, Schema } from "effect"
|
|
2131
|
+
*
|
|
2132
|
+
* const MySchema = Schema.Struct({
|
|
2133
|
+
* name: Schema.String.pipe(Schema.optional, Schema.withDecodingDefault(Effect.succeed("anonymous")))
|
|
2134
|
+
* })
|
|
2135
|
+
*
|
|
2136
|
+
* const result = Schema.decodeUnknownSync(MySchema)({ name: undefined })
|
|
2137
|
+
* // result: { name: "anonymous" }
|
|
2138
|
+
* ```
|
|
2139
|
+
*
|
|
2140
|
+
* @see {@link withDecodingDefaultKey} for the key-level variant (key absent only, not `undefined`)
|
|
2141
|
+
* @see {@link withDecodingDefaultType} for the variant where the default is a `Type` value
|
|
1166
2142
|
* @since 4.0.0
|
|
1167
2143
|
*/
|
|
1168
2144
|
export function withDecodingDefault(defaultValue, options) {
|
|
@@ -1175,27 +2151,78 @@ export function withDecodingDefault(defaultValue, options) {
|
|
|
1175
2151
|
};
|
|
1176
2152
|
}
|
|
1177
2153
|
/**
|
|
1178
|
-
*
|
|
1179
|
-
* default
|
|
2154
|
+
* Wraps the `Encoded` side with `optional` (key absent **or** `undefined`)
|
|
2155
|
+
* and provides a default `Type` value when the field is missing or
|
|
2156
|
+
* `undefined` during decoding.
|
|
2157
|
+
*
|
|
2158
|
+
* Unlike {@link withDecodingDefault}, the default value is specified in terms
|
|
2159
|
+
* of the `Type` (decoded) representation, so it does not need to go through
|
|
2160
|
+
* the decoding transformation.
|
|
2161
|
+
*
|
|
2162
|
+
* **Options**
|
|
2163
|
+
*
|
|
2164
|
+
* - `encodingStrategy`:
|
|
2165
|
+
* - `"passthrough"` (default): include the value in the encoded output.
|
|
2166
|
+
* - `"omit"`: omit the key from the encoded output.
|
|
2167
|
+
*
|
|
2168
|
+
* @see {@link withDecodingDefault} for the variant where the default is an `Encoded` value
|
|
2169
|
+
* @see {@link withDecodingDefaultTypeKey} for the key-level variant
|
|
2170
|
+
* @since 4.0.0
|
|
2171
|
+
*/
|
|
2172
|
+
export function withDecodingDefaultType(defaultValue, options) {
|
|
2173
|
+
return self => {
|
|
2174
|
+
return toType(self).pipe(withDecodingDefault(defaultValue, options), encodeTo(optional(self)));
|
|
2175
|
+
};
|
|
2176
|
+
}
|
|
2177
|
+
/**
|
|
2178
|
+
* Combines a {@link Literal} schema with {@link withConstructorDefault}, making it ideal
|
|
2179
|
+
* for discriminator fields in tagged unions. When constructing via `make`, the
|
|
2180
|
+
* `_tag` field can be omitted and will be filled automatically.
|
|
2181
|
+
*
|
|
2182
|
+
* **Example** (Discriminated union tag)
|
|
2183
|
+
*
|
|
2184
|
+
* ```ts
|
|
2185
|
+
* import { Schema } from "effect"
|
|
1180
2186
|
*
|
|
1181
|
-
*
|
|
1182
|
-
*
|
|
1183
|
-
*
|
|
1184
|
-
*
|
|
2187
|
+
* const A = Schema.Struct({ _tag: Schema.tag("A"), value: Schema.Number })
|
|
2188
|
+
*
|
|
2189
|
+
* // _tag is optional in make, auto-filled to "A"
|
|
2190
|
+
* const a = A.make({ value: 42 })
|
|
2191
|
+
* // a: { _tag: "A", value: 42 }
|
|
2192
|
+
* ```
|
|
1185
2193
|
*
|
|
2194
|
+
* @see {@link tagDefaultOmit} to also omit the tag during encoding
|
|
2195
|
+
* @see {@link TaggedStruct} for a shorthand that adds `_tag` automatically
|
|
1186
2196
|
* @since 4.0.0
|
|
1187
2197
|
*/
|
|
1188
2198
|
export function tag(literal) {
|
|
1189
|
-
return Literal(literal).pipe(withConstructorDefault(
|
|
2199
|
+
return Literal(literal).pipe(withConstructorDefault(Effect.succeed(literal)));
|
|
1190
2200
|
}
|
|
1191
2201
|
/**
|
|
1192
|
-
*
|
|
1193
|
-
* the
|
|
2202
|
+
* Like {@link tag}, but additionally omits the tag field from the encoded output.
|
|
2203
|
+
* Useful when the encoded form (e.g. JSON) does not include the discriminator key,
|
|
2204
|
+
* but the decoded type and constructor still need it.
|
|
2205
|
+
*
|
|
2206
|
+
* **Example** (Tag omitted during encoding)
|
|
2207
|
+
*
|
|
2208
|
+
* ```ts
|
|
2209
|
+
* import { Schema } from "effect"
|
|
2210
|
+
*
|
|
2211
|
+
* const A = Schema.Struct({
|
|
2212
|
+
* _tag: Schema.tagDefaultOmit("A"),
|
|
2213
|
+
* value: Schema.Number
|
|
2214
|
+
* })
|
|
2215
|
+
*
|
|
2216
|
+
* // Encode strips the _tag field
|
|
2217
|
+
* const encoded = Schema.encodeUnknownSync(A)({ _tag: "A", value: 1 })
|
|
2218
|
+
* // encoded: { value: 1 }
|
|
2219
|
+
* ```
|
|
1194
2220
|
*
|
|
2221
|
+
* @see {@link tag} for the variant that keeps the tag during encoding
|
|
1195
2222
|
* @since 4.0.0
|
|
1196
2223
|
*/
|
|
1197
2224
|
export function tagDefaultOmit(literal) {
|
|
1198
|
-
return tag(literal).pipe(withDecodingDefaultKey(()
|
|
2225
|
+
return tag(literal).pipe(withDecodingDefaultKey(Effect.succeed(literal), {
|
|
1199
2226
|
encodingStrategy: "omit"
|
|
1200
2227
|
}));
|
|
1201
2228
|
}
|
|
@@ -1204,7 +2231,7 @@ export function tagDefaultOmit(literal) {
|
|
|
1204
2231
|
* to identify the specific variant of the object, which is especially useful
|
|
1205
2232
|
* when working with union types.
|
|
1206
2233
|
*
|
|
1207
|
-
* When using the `
|
|
2234
|
+
* When using the `make` method, the `_tag` field is optional and will be
|
|
1208
2235
|
* added automatically. However, when decoding or encoding, the `_tag` field
|
|
1209
2236
|
* must be present in the input.
|
|
1210
2237
|
*
|
|
@@ -1247,18 +2274,27 @@ export function TaggedStruct(value, fields) {
|
|
|
1247
2274
|
...fields
|
|
1248
2275
|
});
|
|
1249
2276
|
}
|
|
1250
|
-
/** @internal */
|
|
1251
|
-
export function _getTagValueIfPropertyKey(tag, ast) {
|
|
1252
|
-
const ps = ast.propertySignatures.find(p => p.name === tag);
|
|
1253
|
-
if (ps) {
|
|
1254
|
-
if (AST.isLiteral(ps.type) && Predicate.isPropertyKey(ps.type.literal)) {
|
|
1255
|
-
return ps.type.literal;
|
|
1256
|
-
} else if (AST.isUniqueSymbol(ps.type)) {
|
|
1257
|
-
return ps.type.symbol;
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
2277
|
/**
|
|
2278
|
+
* Augments an existing {@link Union} of tagged structs with utility methods keyed by the discriminant field.
|
|
2279
|
+
*
|
|
2280
|
+
* **Example** (Adding tagged-union utilities to an existing union)
|
|
2281
|
+
*
|
|
2282
|
+
* ```ts
|
|
2283
|
+
* import { Schema } from "effect"
|
|
2284
|
+
*
|
|
2285
|
+
* const A = Schema.TaggedStruct("A", { value: Schema.Number })
|
|
2286
|
+
* const B = Schema.TaggedStruct("B", { name: Schema.String })
|
|
2287
|
+
*
|
|
2288
|
+
* const MyUnion = Schema.Union([A, B]).pipe(Schema.toTaggedUnion("_tag"))
|
|
2289
|
+
*
|
|
2290
|
+
* // Pattern-match on the union
|
|
2291
|
+
* const result = MyUnion.match({ _tag: "A", value: 1 }, {
|
|
2292
|
+
* A: (a) => `number: ${a.value}`,
|
|
2293
|
+
* B: (b) => `name: ${b.name}`
|
|
2294
|
+
* })
|
|
2295
|
+
* ```
|
|
2296
|
+
*
|
|
2297
|
+
* @see {@link TaggedUnion} for a shorthand that builds the union from scratch
|
|
1262
2298
|
* @since 4.0.0
|
|
1263
2299
|
* @experimental
|
|
1264
2300
|
*/
|
|
@@ -1279,15 +2315,16 @@ export function toTaggedUnion(tag) {
|
|
|
1279
2315
|
if (AST.isUnion(ast) && "members" in schema && globalThis.Array.isArray(schema.members) && schema.members.every(isSchema)) {
|
|
1280
2316
|
return schema.members.forEach(walk);
|
|
1281
2317
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
2318
|
+
const sentinels = AST.collectSentinels(ast);
|
|
2319
|
+
if (sentinels.length > 0) {
|
|
2320
|
+
const literal = sentinels.find(s => s.key === tag)?.literal;
|
|
2321
|
+
if (Predicate.isPropertyKey(literal)) {
|
|
2322
|
+
cases[literal] = schema;
|
|
2323
|
+
guards[literal] = is(toType(schema));
|
|
1287
2324
|
return;
|
|
1288
2325
|
}
|
|
1289
2326
|
}
|
|
1290
|
-
throw new globalThis.Error("No literal found");
|
|
2327
|
+
throw new globalThis.Error("No literal or unique symbol found");
|
|
1291
2328
|
}
|
|
1292
2329
|
function match() {
|
|
1293
2330
|
if (arguments.length === 1) {
|
|
@@ -1303,6 +2340,28 @@ export function toTaggedUnion(tag) {
|
|
|
1303
2340
|
};
|
|
1304
2341
|
}
|
|
1305
2342
|
/**
|
|
2343
|
+
* Builds a discriminated union from a record of field sets, one per variant.
|
|
2344
|
+
* Each key becomes the `_tag` literal and the value is passed to {@link TaggedStruct}.
|
|
2345
|
+
* The result includes `cases`, `guards`, `isAnyOf`, and `match` utilities.
|
|
2346
|
+
*
|
|
2347
|
+
* **Example** (Discriminated union with pattern matching)
|
|
2348
|
+
*
|
|
2349
|
+
* ```ts
|
|
2350
|
+
* import { Schema } from "effect"
|
|
2351
|
+
*
|
|
2352
|
+
* const Shape = Schema.TaggedUnion({
|
|
2353
|
+
* Circle: { radius: Schema.Number },
|
|
2354
|
+
* Rectangle: { width: Schema.Number, height: Schema.Number }
|
|
2355
|
+
* })
|
|
2356
|
+
*
|
|
2357
|
+
* // Pattern-match on a decoded value
|
|
2358
|
+
* const area = Shape.match({ _tag: "Circle", radius: 5 }, {
|
|
2359
|
+
* Circle: (c) => Math.PI * c.radius ** 2,
|
|
2360
|
+
* Rectangle: (r) => r.width * r.height
|
|
2361
|
+
* })
|
|
2362
|
+
* ```
|
|
2363
|
+
*
|
|
2364
|
+
* @see {@link toTaggedUnion} to augment an existing union instead
|
|
1306
2365
|
* @category Constructors
|
|
1307
2366
|
* @since 4.0.0
|
|
1308
2367
|
*/
|
|
@@ -1326,18 +2385,49 @@ export function TaggedUnion(casesByTag) {
|
|
|
1326
2385
|
});
|
|
1327
2386
|
}
|
|
1328
2387
|
/**
|
|
2388
|
+
* Wraps a struct schema so that its decoded `Type` becomes a nominally distinct type `Self`.
|
|
2389
|
+
* Useful for creating opaque types that are structurally identical to a base struct
|
|
2390
|
+
* but type-incompatible with it.
|
|
2391
|
+
*
|
|
2392
|
+
* **Example** (Opaque struct)
|
|
2393
|
+
*
|
|
2394
|
+
* ```ts
|
|
2395
|
+
* import { Schema } from "effect"
|
|
2396
|
+
*
|
|
2397
|
+
* class Person extends Schema.Opaque<Person>()(
|
|
2398
|
+
* Schema.Struct({
|
|
2399
|
+
* name: Schema.String
|
|
2400
|
+
* })
|
|
2401
|
+
* ) {}
|
|
2402
|
+
*
|
|
2403
|
+
* // Decoded value is Person, not { name: string }
|
|
2404
|
+
* const person = Schema.decodeUnknownSync(Person)({ name: "Alice" })
|
|
2405
|
+
* // person: Person
|
|
2406
|
+
* ```
|
|
2407
|
+
*
|
|
1329
2408
|
* @since 4.0.0
|
|
1330
2409
|
*/
|
|
1331
2410
|
export function Opaque() {
|
|
1332
2411
|
return schema => {
|
|
1333
2412
|
// oxlint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
1334
2413
|
class Opaque {}
|
|
1335
|
-
Object.setPrototypeOf(Opaque, schema);
|
|
1336
|
-
return Opaque;
|
|
2414
|
+
return Object.setPrototypeOf(Opaque, schema);
|
|
1337
2415
|
};
|
|
1338
2416
|
}
|
|
1339
2417
|
/**
|
|
1340
|
-
* Creates a schema that validates
|
|
2418
|
+
* Creates a schema that validates values using `instanceof`.
|
|
2419
|
+
* Decoding and encoding pass the value through unchanged.
|
|
2420
|
+
*
|
|
2421
|
+
* **Example** (Schema for a built-in class)
|
|
2422
|
+
*
|
|
2423
|
+
* ```ts
|
|
2424
|
+
* import { Schema } from "effect"
|
|
2425
|
+
*
|
|
2426
|
+
* const DateSchema = Schema.instanceOf(Date)
|
|
2427
|
+
*
|
|
2428
|
+
* const decoded = Schema.decodeUnknownSync(DateSchema)(new Date("2024-01-01"))
|
|
2429
|
+
* // decoded: Date
|
|
2430
|
+
* ```
|
|
1341
2431
|
*
|
|
1342
2432
|
* @category Constructors
|
|
1343
2433
|
* @since 4.0.0
|
|
@@ -1346,8 +2436,10 @@ export function instanceOf(constructor, annotations) {
|
|
|
1346
2436
|
return declare(u => u instanceof constructor, annotations);
|
|
1347
2437
|
}
|
|
1348
2438
|
/**
|
|
2439
|
+
* Constructs an `AST.Link` that describes how a value of type `T` encodes to and decodes from a `To` schema.
|
|
2440
|
+
* Used when building low-level AST transformations that bridge two schema types.
|
|
2441
|
+
*
|
|
1349
2442
|
* @since 4.0.0
|
|
1350
|
-
* @experimental
|
|
1351
2443
|
*/
|
|
1352
2444
|
export function link() {
|
|
1353
2445
|
return (encodeTo, transformation) => {
|
|
@@ -1358,11 +2450,59 @@ export function link() {
|
|
|
1358
2450
|
// Checks
|
|
1359
2451
|
// -----------------------------------------------------------------------------
|
|
1360
2452
|
/**
|
|
2453
|
+
* Creates a custom filter check from a predicate function. The predicate
|
|
2454
|
+
* receives the input value, the schema's AST, and parse options, and returns
|
|
2455
|
+
* a value of type {@link FilterOutput}.
|
|
2456
|
+
*
|
|
2457
|
+
* **Example** (Failure at a nested path)
|
|
2458
|
+
*
|
|
2459
|
+
* ```ts
|
|
2460
|
+
* import { Schema } from "effect"
|
|
2461
|
+
*
|
|
2462
|
+
* const schema = Schema.Struct({ password: Schema.String, confirmPassword: Schema.String }).check(
|
|
2463
|
+
* Schema.makeFilter((o) =>
|
|
2464
|
+
* o.password === o.confirmPassword
|
|
2465
|
+
* ? undefined
|
|
2466
|
+
* : { path: ["password"], issue: "password and confirmPassword must match" }
|
|
2467
|
+
* )
|
|
2468
|
+
* )
|
|
2469
|
+
*
|
|
2470
|
+
* console.log(String(Schema.decodeUnknownExit(schema)({ password: "123456", confirmPassword: "1234567" })))
|
|
2471
|
+
* // Failure(Cause([Fail(SchemaError: password and confirmPassword must match
|
|
2472
|
+
* // at ["password"])]))
|
|
2473
|
+
* ```
|
|
2474
|
+
*
|
|
2475
|
+
* **Example** (Reporting multiple failures at once)
|
|
2476
|
+
*
|
|
2477
|
+
* ```ts
|
|
2478
|
+
* import { Schema } from "effect"
|
|
2479
|
+
*
|
|
2480
|
+
* const schema = Schema.Struct({ a: Schema.Finite, b: Schema.Finite, c: Schema.Finite }).check(
|
|
2481
|
+
* Schema.makeFilter((o) => {
|
|
2482
|
+
* const issues: Array<Schema.FilterIssue> = []
|
|
2483
|
+
* if (o.a > 0) {
|
|
2484
|
+
* if (o.b <= 0) issues.push({ path: ["b"], issue: "b must be greater than 0" })
|
|
2485
|
+
* if (o.c <= 0) issues.push({ path: ["c"], issue: "c must be greater than 0" })
|
|
2486
|
+
* }
|
|
2487
|
+
* return issues
|
|
2488
|
+
* })
|
|
2489
|
+
* )
|
|
2490
|
+
*
|
|
2491
|
+
* console.log(String(Schema.decodeUnknownExit(schema)({ a: 1, b: 0, c: 0 })))
|
|
2492
|
+
* // Failure(Cause([Fail(SchemaError: b must be greater than 0
|
|
2493
|
+
* // at ["b"]
|
|
2494
|
+
* // c must be greater than 0
|
|
2495
|
+
* // at ["c"])]))
|
|
2496
|
+
* ```
|
|
2497
|
+
*
|
|
1361
2498
|
* @category Checks Constructors
|
|
1362
2499
|
* @since 4.0.0
|
|
1363
2500
|
*/
|
|
1364
2501
|
export const makeFilter = AST.makeFilter;
|
|
1365
2502
|
/**
|
|
2503
|
+
* Groups multiple checks into a single {@link AST.FilterGroup}, applying
|
|
2504
|
+
* optional shared annotations to the group as a whole.
|
|
2505
|
+
*
|
|
1366
2506
|
* @category Checks Constructors
|
|
1367
2507
|
* @since 4.0.0
|
|
1368
2508
|
*/
|
|
@@ -1850,6 +2990,9 @@ export function isFinite(annotations) {
|
|
|
1850
2990
|
});
|
|
1851
2991
|
}
|
|
1852
2992
|
/**
|
|
2993
|
+
* Generic factory for creating a "greater than" (`>`) check for any ordered
|
|
2994
|
+
* type by supplying an {@link Order.Order} instance.
|
|
2995
|
+
*
|
|
1853
2996
|
* @category Order checks
|
|
1854
2997
|
* @since 4.0.0
|
|
1855
2998
|
*/
|
|
@@ -1865,6 +3008,9 @@ export function makeIsGreaterThan(options) {
|
|
|
1865
3008
|
};
|
|
1866
3009
|
}
|
|
1867
3010
|
/**
|
|
3011
|
+
* Generic factory for creating a ">=" check for any ordered type by supplying
|
|
3012
|
+
* an {@link Order.Order} instance.
|
|
3013
|
+
*
|
|
1868
3014
|
* @category Order checks
|
|
1869
3015
|
* @since 4.0.0
|
|
1870
3016
|
*/
|
|
@@ -1880,6 +3026,9 @@ export function makeIsGreaterThanOrEqualTo(options) {
|
|
|
1880
3026
|
};
|
|
1881
3027
|
}
|
|
1882
3028
|
/**
|
|
3029
|
+
* Generic factory for creating a "<" check for any ordered type by supplying
|
|
3030
|
+
* an {@link Order.Order} instance.
|
|
3031
|
+
*
|
|
1883
3032
|
* @category Order checks
|
|
1884
3033
|
* @since 4.0.0
|
|
1885
3034
|
*/
|
|
@@ -1895,6 +3044,9 @@ export function makeIsLessThan(options) {
|
|
|
1895
3044
|
};
|
|
1896
3045
|
}
|
|
1897
3046
|
/**
|
|
3047
|
+
* Generic factory for creating a "<=" check for any ordered type by supplying
|
|
3048
|
+
* an {@link Order.Order} instance.
|
|
3049
|
+
*
|
|
1898
3050
|
* @category Order checks
|
|
1899
3051
|
* @since 4.0.0
|
|
1900
3052
|
*/
|
|
@@ -1910,6 +3062,9 @@ export function makeIsLessThanOrEqualTo(options) {
|
|
|
1910
3062
|
};
|
|
1911
3063
|
}
|
|
1912
3064
|
/**
|
|
3065
|
+
* Generic factory for creating an inclusive/exclusive range check for any
|
|
3066
|
+
* ordered type by supplying an {@link Order.Order} instance.
|
|
3067
|
+
*
|
|
1913
3068
|
* @category Order checks
|
|
1914
3069
|
* @since 4.0.0
|
|
1915
3070
|
*/
|
|
@@ -1930,6 +3085,9 @@ export function makeIsBetween(deriveOptions) {
|
|
|
1930
3085
|
};
|
|
1931
3086
|
}
|
|
1932
3087
|
/**
|
|
3088
|
+
* Generic factory for creating a divisibility check for any numeric type by
|
|
3089
|
+
* supplying a remainder function and a zero value.
|
|
3090
|
+
*
|
|
1933
3091
|
* @category Numeric checks
|
|
1934
3092
|
* @since 4.0.0
|
|
1935
3093
|
*/
|
|
@@ -2598,6 +3756,14 @@ export const isBetweenBigDecimal = /*#__PURE__*/makeIsBetween({
|
|
|
2598
3756
|
* constraint to ensure generated strings or arrays have at least the required
|
|
2599
3757
|
* length.
|
|
2600
3758
|
*
|
|
3759
|
+
* **Example** (Minimum length check)
|
|
3760
|
+
* ```ts
|
|
3761
|
+
* import { Schema } from "effect"
|
|
3762
|
+
*
|
|
3763
|
+
* const NonEmptyStringSchema = Schema.String.check(Schema.isMinLength(1))
|
|
3764
|
+
* const NonEmptyArraySchema = Schema.Array(Schema.Number).check(Schema.isMinLength(1))
|
|
3765
|
+
* ```
|
|
3766
|
+
*
|
|
2601
3767
|
* @category Length checks
|
|
2602
3768
|
* @since 4.0.0
|
|
2603
3769
|
*/
|
|
@@ -2990,6 +4156,7 @@ export function isPropertyNames(keySchema, annotations) {
|
|
|
2990
4156
|
* constraint using the provided equivalence function to ensure generated arrays
|
|
2991
4157
|
* contain only unique items.
|
|
2992
4158
|
*
|
|
4159
|
+
* @category Array checks
|
|
2993
4160
|
* @since 4.0.0
|
|
2994
4161
|
*/
|
|
2995
4162
|
export function isUnique(annotations) {
|
|
@@ -3007,23 +4174,24 @@ export function isUnique(annotations) {
|
|
|
3007
4174
|
...annotations
|
|
3008
4175
|
});
|
|
3009
4176
|
}
|
|
3010
|
-
// -----------------------------------------------------------------------------
|
|
3011
|
-
// Built-in Schemas
|
|
3012
|
-
// -----------------------------------------------------------------------------
|
|
3013
4177
|
/**
|
|
3014
4178
|
* A schema for non-empty strings. Validates that a string has at least one
|
|
3015
4179
|
* character.
|
|
3016
4180
|
*
|
|
4181
|
+
* @category String
|
|
3017
4182
|
* @since 4.0.0
|
|
3018
4183
|
*/
|
|
3019
4184
|
export const NonEmptyString = /*#__PURE__*/String.check(/*#__PURE__*/isNonEmpty());
|
|
3020
4185
|
/**
|
|
3021
4186
|
* A schema representing a single character.
|
|
3022
4187
|
*
|
|
4188
|
+
* @category String
|
|
3023
4189
|
* @since 4.0.0
|
|
3024
4190
|
*/
|
|
3025
4191
|
export const Char = /*#__PURE__*/String.check(/*#__PURE__*/isLengthBetween(1, 1));
|
|
3026
4192
|
/**
|
|
4193
|
+
* Creates a schema for `Option<A>`. See {@link Option} for details.
|
|
4194
|
+
*
|
|
3027
4195
|
* @category Option
|
|
3028
4196
|
* @since 4.0.0
|
|
3029
4197
|
*/
|
|
@@ -3096,6 +4264,40 @@ export function Option(value) {
|
|
|
3096
4264
|
export function OptionFromNullOr(schema) {
|
|
3097
4265
|
return NullOr(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromNullOr()));
|
|
3098
4266
|
}
|
|
4267
|
+
/**
|
|
4268
|
+
* Decodes an undefined-or value `T` to a required `Option<T>` value.
|
|
4269
|
+
*
|
|
4270
|
+
* Decoding:
|
|
4271
|
+
* - `undefined` is decoded as `None`
|
|
4272
|
+
* - other values are decoded as `Some`
|
|
4273
|
+
*
|
|
4274
|
+
* Encoding:
|
|
4275
|
+
* - `None` is encoded as `undefined`
|
|
4276
|
+
* - `Some` is encoded as the value
|
|
4277
|
+
*
|
|
4278
|
+
* @category Option
|
|
4279
|
+
* @since 4.0.0
|
|
4280
|
+
*/
|
|
4281
|
+
export function OptionFromUndefinedOr(schema) {
|
|
4282
|
+
return UndefinedOr(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromUndefinedOr()));
|
|
4283
|
+
}
|
|
4284
|
+
/**
|
|
4285
|
+
* Decodes a nullish value `T` to a required `Option<T>` value.
|
|
4286
|
+
*
|
|
4287
|
+
* Decoding:
|
|
4288
|
+
* - `null` and `undefined` are decoded as `None`
|
|
4289
|
+
* - other values are decoded as `Some`
|
|
4290
|
+
*
|
|
4291
|
+
* Encoding:
|
|
4292
|
+
* - `None` is encoded as `null` or `undefined` depending on the provided `options.onNoneEncoding` (defaults to `undefined`)
|
|
4293
|
+
* - `Some` is encoded as the value
|
|
4294
|
+
*
|
|
4295
|
+
* @category Option
|
|
4296
|
+
* @since 4.0.0
|
|
4297
|
+
*/
|
|
4298
|
+
export function OptionFromNullishOr(schema, options) {
|
|
4299
|
+
return NullishOr(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromNullishOr(options)));
|
|
4300
|
+
}
|
|
3099
4301
|
/**
|
|
3100
4302
|
* Decodes an optional value `A` to a required `Option<A>` value.
|
|
3101
4303
|
*
|
|
@@ -3133,6 +4335,35 @@ export function OptionFromOptional(schema) {
|
|
|
3133
4335
|
return optional(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromOptional()));
|
|
3134
4336
|
}
|
|
3135
4337
|
/**
|
|
4338
|
+
* Decodes an optional or `null` or `undefined` value `A` to a required `Option<A>`
|
|
4339
|
+
* value.
|
|
4340
|
+
*
|
|
4341
|
+
* Decoding:
|
|
4342
|
+
* - a missing key is decoded as `None`
|
|
4343
|
+
* - a present key with an `undefined` value is decoded as `None`
|
|
4344
|
+
* - a present key with a `null` value is decoded as `None`
|
|
4345
|
+
* - all other values are decoded as `Some`
|
|
4346
|
+
*
|
|
4347
|
+
* Encoding (controlled by `options.onNoneEncoding`):
|
|
4348
|
+
* - `"omit"` (default): `None` is encoded as a missing key
|
|
4349
|
+
* - `null`: `None` is encoded as `null`
|
|
4350
|
+
* - `undefined`: `None` is encoded as `undefined`
|
|
4351
|
+
* - `Some` is always encoded as the value
|
|
4352
|
+
*
|
|
4353
|
+
* @category Option
|
|
4354
|
+
* @since 4.0.0
|
|
4355
|
+
*/
|
|
4356
|
+
export function OptionFromOptionalNullOr(schema, options) {
|
|
4357
|
+
const onNoneEncoding = options === undefined ? "omit" : options.onNoneEncoding;
|
|
4358
|
+
const noneValue = onNoneEncoding === null ? null : undefined;
|
|
4359
|
+
return optional(NullOr(schema)).pipe(decodeTo(Option(toType(schema)), Transformation.transformOptional({
|
|
4360
|
+
decode: oe => oe.pipe(Option_.filter(Predicate.isNotNullish), Option_.some),
|
|
4361
|
+
encode: onNoneEncoding === "omit" ? Option_.flatten : ot => Option_.some(Option_.getOrElse(Option_.flatten(ot), () => noneValue))
|
|
4362
|
+
})));
|
|
4363
|
+
}
|
|
4364
|
+
/**
|
|
4365
|
+
* Creates a schema for `Result<A, E>`. See {@link Result} for details.
|
|
4366
|
+
*
|
|
3136
4367
|
* @category Result
|
|
3137
4368
|
* @since 4.0.0
|
|
3138
4369
|
*/
|
|
@@ -3261,6 +4492,9 @@ export function Redacted(value, options) {
|
|
|
3261
4492
|
});
|
|
3262
4493
|
}
|
|
3263
4494
|
/**
|
|
4495
|
+
* Middleware that wraps decoded errors in `Redacted`, preventing sensitive
|
|
4496
|
+
* schema details from leaking in error messages.
|
|
4497
|
+
*
|
|
3264
4498
|
* @category Redacted
|
|
3265
4499
|
* @since 4.0.0
|
|
3266
4500
|
*/
|
|
@@ -3268,6 +4502,10 @@ export function redact(schema) {
|
|
|
3268
4502
|
return schema.pipe(middlewareDecoding(Effect.mapErrorEager(Issue.redact)));
|
|
3269
4503
|
}
|
|
3270
4504
|
/**
|
|
4505
|
+
* Decodes a value and wraps it in `Redacted<A>`. Unlike {@link Redacted} which
|
|
4506
|
+
* expects the input to already be a `Redacted` instance, this schema decodes
|
|
4507
|
+
* the raw value and wraps it.
|
|
4508
|
+
*
|
|
3271
4509
|
* @category Redacted
|
|
3272
4510
|
* @since 4.0.0
|
|
3273
4511
|
*/
|
|
@@ -3280,6 +4518,8 @@ export function RedactedFromValue(value, options) {
|
|
|
3280
4518
|
}));
|
|
3281
4519
|
}
|
|
3282
4520
|
/**
|
|
4521
|
+
* Creates a schema for `Cause.Reason<E>`. See {@link CauseReason} for details.
|
|
4522
|
+
*
|
|
3283
4523
|
* @category CauseReason
|
|
3284
4524
|
* @since 4.0.0
|
|
3285
4525
|
*/
|
|
@@ -3379,12 +4619,14 @@ function causeReasonToFormatter(error, defect) {
|
|
|
3379
4619
|
};
|
|
3380
4620
|
}
|
|
3381
4621
|
/**
|
|
4622
|
+
* Creates a schema for `Cause<E>`. See {@link Cause} for details.
|
|
4623
|
+
*
|
|
3382
4624
|
* @category Cause
|
|
3383
4625
|
* @since 4.0.0
|
|
3384
4626
|
*/
|
|
3385
4627
|
export function Cause(error, defect) {
|
|
3386
4628
|
const schema = declareConstructor()([error, defect], ([error, defect]) => {
|
|
3387
|
-
const failures =
|
|
4629
|
+
const failures = ArraySchema(CauseReason(error, defect));
|
|
3388
4630
|
return (input, ast, options) => {
|
|
3389
4631
|
if (!Cause_.isCause(input)) {
|
|
3390
4632
|
return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
|
|
@@ -3404,7 +4646,7 @@ export function Cause(error, defect) {
|
|
|
3404
4646
|
importDeclaration: `import * as Cause from "effect/Cause"`
|
|
3405
4647
|
},
|
|
3406
4648
|
expected: "Cause",
|
|
3407
|
-
toCodec: ([error, defect]) => link()(
|
|
4649
|
+
toCodec: ([error, defect]) => link()(ArraySchema(CauseReason(error, defect)), Transformation.transform({
|
|
3408
4650
|
decode: Cause_.fromReasons,
|
|
3409
4651
|
encode: ({
|
|
3410
4652
|
reasons: failures
|
|
@@ -3502,7 +4744,7 @@ export const Defect = /*#__PURE__*/Union([/*#__PURE__*/ErrorJsonEncoded.pipe(/*#
|
|
|
3502
4744
|
* A schema that represents defects, that also includes stack traces in the
|
|
3503
4745
|
* encoded form.
|
|
3504
4746
|
*
|
|
3505
|
-
* @category
|
|
4747
|
+
* @category Defect
|
|
3506
4748
|
* @since 4.0.0
|
|
3507
4749
|
*/
|
|
3508
4750
|
export const DefectWithStack = /*#__PURE__*/Union([/*#__PURE__*/ErrorJsonEncoded.pipe(/*#__PURE__*/decodeTo(ErrorWithStack, /*#__PURE__*/Transformation.errorFromErrorJsonEncoded({
|
|
@@ -3512,6 +4754,8 @@ export const DefectWithStack = /*#__PURE__*/Union([/*#__PURE__*/ErrorJsonEncoded
|
|
|
3512
4754
|
toArbitrary: () => fc => fc.json()
|
|
3513
4755
|
}), defectTransformation))]);
|
|
3514
4756
|
/**
|
|
4757
|
+
* Creates a schema for `Exit<A, E>`. See {@link Exit} for details.
|
|
4758
|
+
*
|
|
3515
4759
|
* @category Exit
|
|
3516
4760
|
* @since 4.0.0
|
|
3517
4761
|
*/
|
|
@@ -3604,7 +4848,7 @@ export function Exit(value, error, defect) {
|
|
|
3604
4848
|
*/
|
|
3605
4849
|
export function ReadonlyMap(key, value) {
|
|
3606
4850
|
const schema = declareConstructor()([key, value], ([key, value]) => {
|
|
3607
|
-
const array =
|
|
4851
|
+
const array = ArraySchema(Tuple([key, value]));
|
|
3608
4852
|
return (input, ast, options) => {
|
|
3609
4853
|
if (input instanceof globalThis.Map) {
|
|
3610
4854
|
return Effect.mapBothEager(Parser.decodeUnknownEffect(array)([...input], options), {
|
|
@@ -3623,7 +4867,7 @@ export function ReadonlyMap(key, value) {
|
|
|
3623
4867
|
Type: `globalThis.ReadonlyMap<?, ?>`
|
|
3624
4868
|
},
|
|
3625
4869
|
expected: "ReadonlyMap",
|
|
3626
|
-
toCodec: ([key, value]) => link()(
|
|
4870
|
+
toCodec: ([key, value]) => link()(ArraySchema(Tuple([key, value])), Transformation.transform({
|
|
3627
4871
|
decode: e => new globalThis.Map(e),
|
|
3628
4872
|
encode: map => [...map.entries()]
|
|
3629
4873
|
})),
|
|
@@ -3657,7 +4901,7 @@ export function ReadonlyMap(key, value) {
|
|
|
3657
4901
|
*/
|
|
3658
4902
|
export function HashMap(key, value) {
|
|
3659
4903
|
const schema = declareConstructor()([key, value], ([key, value]) => {
|
|
3660
|
-
const entries =
|
|
4904
|
+
const entries = ArraySchema(Tuple([key, value]));
|
|
3661
4905
|
return (input, ast, options) => {
|
|
3662
4906
|
if (HashMap_.isHashMap(input)) {
|
|
3663
4907
|
return Effect.mapBothEager(Parser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options), {
|
|
@@ -3677,7 +4921,7 @@ export function HashMap(key, value) {
|
|
|
3677
4921
|
importDeclaration: `import * as HashMap from "effect/HashMap"`
|
|
3678
4922
|
},
|
|
3679
4923
|
expected: "HashMap",
|
|
3680
|
-
toCodec: ([key, value]) => link()(
|
|
4924
|
+
toCodec: ([key, value]) => link()(ArraySchema(Tuple([key, value])), Transformation.transform({
|
|
3681
4925
|
decode: HashMap_.fromIterable,
|
|
3682
4926
|
encode: HashMap_.toEntries
|
|
3683
4927
|
})),
|
|
@@ -3708,7 +4952,7 @@ export function HashMap(key, value) {
|
|
|
3708
4952
|
*/
|
|
3709
4953
|
export function ReadonlySet(value) {
|
|
3710
4954
|
const schema = declareConstructor()([value], ([value]) => {
|
|
3711
|
-
const array =
|
|
4955
|
+
const array = ArraySchema(value);
|
|
3712
4956
|
return (input, ast, options) => {
|
|
3713
4957
|
if (input instanceof globalThis.Set) {
|
|
3714
4958
|
return Effect.mapBothEager(Parser.decodeUnknownEffect(array)([...input], options), {
|
|
@@ -3727,7 +4971,7 @@ export function ReadonlySet(value) {
|
|
|
3727
4971
|
Type: `globalThis.ReadonlySet<?>`
|
|
3728
4972
|
},
|
|
3729
4973
|
expected: "ReadonlySet",
|
|
3730
|
-
toCodec: ([value]) => link()(
|
|
4974
|
+
toCodec: ([value]) => link()(ArraySchema(value), Transformation.transform({
|
|
3731
4975
|
decode: e => new globalThis.Set(e),
|
|
3732
4976
|
encode: set => [...set.values()]
|
|
3733
4977
|
})),
|
|
@@ -3760,7 +5004,7 @@ export function ReadonlySet(value) {
|
|
|
3760
5004
|
*/
|
|
3761
5005
|
export function HashSet(value) {
|
|
3762
5006
|
const schema = declareConstructor()([value], ([value]) => {
|
|
3763
|
-
const values =
|
|
5007
|
+
const values = ArraySchema(value);
|
|
3764
5008
|
return (input, ast, options) => {
|
|
3765
5009
|
if (HashSet_.isHashSet(input)) {
|
|
3766
5010
|
return Effect.mapBothEager(Parser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
|
|
@@ -3772,14 +5016,14 @@ export function HashSet(value) {
|
|
|
3772
5016
|
};
|
|
3773
5017
|
}, {
|
|
3774
5018
|
typeConstructor: {
|
|
3775
|
-
_tag: "HashSet"
|
|
5019
|
+
_tag: "effect/HashSet"
|
|
3776
5020
|
},
|
|
3777
5021
|
generation: {
|
|
3778
5022
|
runtime: `Schema.HashSet(?)`,
|
|
3779
5023
|
Type: `HashSet.HashSet<?>`
|
|
3780
5024
|
},
|
|
3781
5025
|
expected: "HashSet",
|
|
3782
|
-
toCodec: ([value]) => link()(
|
|
5026
|
+
toCodec: ([value]) => link()(ArraySchema(value), Transformation.transform({
|
|
3783
5027
|
decode: HashSet_.fromIterable,
|
|
3784
5028
|
encode: Arr.fromIterable
|
|
3785
5029
|
})),
|
|
@@ -3804,6 +5048,63 @@ export function HashSet(value) {
|
|
|
3804
5048
|
});
|
|
3805
5049
|
}
|
|
3806
5050
|
/**
|
|
5051
|
+
* Creates a schema that validates a `Chunk` where values must conform to the
|
|
5052
|
+
* provided schema.
|
|
5053
|
+
*
|
|
5054
|
+
* @category Chunk
|
|
5055
|
+
* @since 4.0.0
|
|
5056
|
+
*/
|
|
5057
|
+
export function Chunk(value) {
|
|
5058
|
+
const schema = declareConstructor()([value], ([value]) => {
|
|
5059
|
+
const values = ArraySchema(value);
|
|
5060
|
+
return (input, ast, options) => {
|
|
5061
|
+
if (Chunk_.isChunk(input)) {
|
|
5062
|
+
return Effect.mapBothEager(Parser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
|
|
5063
|
+
onSuccess: Chunk_.fromIterable,
|
|
5064
|
+
onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["values"], issue)])
|
|
5065
|
+
});
|
|
5066
|
+
}
|
|
5067
|
+
return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
|
|
5068
|
+
};
|
|
5069
|
+
}, {
|
|
5070
|
+
typeConstructor: {
|
|
5071
|
+
_tag: "effect/Chunk"
|
|
5072
|
+
},
|
|
5073
|
+
generation: {
|
|
5074
|
+
runtime: `Schema.Chunk(?)`,
|
|
5075
|
+
Type: `Chunk.Chunk<?>`
|
|
5076
|
+
},
|
|
5077
|
+
expected: "Chunk",
|
|
5078
|
+
toCodec: ([value]) => link()(ArraySchema(value), Transformation.transform({
|
|
5079
|
+
decode: Chunk_.fromIterable,
|
|
5080
|
+
encode: Arr.fromIterable
|
|
5081
|
+
})),
|
|
5082
|
+
toArbitrary: ([value]) => (fc, ctx) => {
|
|
5083
|
+
return fc.oneof(ctx?.isSuspend ? {
|
|
5084
|
+
maxDepth: 2,
|
|
5085
|
+
depthIdentifier: "Chunk"
|
|
5086
|
+
} : {}, fc.constant([]), fc.array(value, ctx?.constraints?.array)).map(Chunk_.fromIterable);
|
|
5087
|
+
},
|
|
5088
|
+
toEquivalence: ([value]) => Chunk_.makeEquivalence(value),
|
|
5089
|
+
toFormatter: ([value]) => t => {
|
|
5090
|
+
const size = Chunk_.size(t);
|
|
5091
|
+
if (size === 0) {
|
|
5092
|
+
return "Chunk(0) {}";
|
|
5093
|
+
}
|
|
5094
|
+
const values = globalThis.Array.from(t).sort().map(v => `${value(v)}`);
|
|
5095
|
+
return `Chunk(${size}) { ${values.join(", ")} }`;
|
|
5096
|
+
}
|
|
5097
|
+
});
|
|
5098
|
+
return make(schema.ast, {
|
|
5099
|
+
value
|
|
5100
|
+
});
|
|
5101
|
+
}
|
|
5102
|
+
/**
|
|
5103
|
+
* Schema for JavaScript `RegExp` objects.
|
|
5104
|
+
*
|
|
5105
|
+
* The default JSON serializer encodes a `RegExp` as `{ source, flags }`.
|
|
5106
|
+
*
|
|
5107
|
+
* @category RegExp
|
|
3807
5108
|
* @since 4.0.0
|
|
3808
5109
|
*/
|
|
3809
5110
|
export const RegExp = /*#__PURE__*/instanceOf(globalThis.RegExp, {
|
|
@@ -3837,6 +5138,9 @@ export const RegExp = /*#__PURE__*/instanceOf(globalThis.RegExp, {
|
|
|
3837
5138
|
}).map(flags => flags.join(""))).map(([source, flags]) => new globalThis.RegExp(source, flags)),
|
|
3838
5139
|
toEquivalence: () => (a, b) => a.source === b.source && a.flags === b.flags
|
|
3839
5140
|
});
|
|
5141
|
+
const URLString = /*#__PURE__*/String.annotate({
|
|
5142
|
+
expected: "a string that will be decoded as a URL"
|
|
5143
|
+
});
|
|
3840
5144
|
/**
|
|
3841
5145
|
* A schema for JavaScript `URL` objects.
|
|
3842
5146
|
*
|
|
@@ -3856,9 +5160,7 @@ export const URL = /*#__PURE__*/instanceOf(globalThis.URL, {
|
|
|
3856
5160
|
Type: `globalThis.URL`
|
|
3857
5161
|
},
|
|
3858
5162
|
expected: "URL",
|
|
3859
|
-
toCodecJson: () => link()(
|
|
3860
|
-
expected: "a string that will be decoded as a URL"
|
|
3861
|
-
}), Transformation.urlFromString),
|
|
5163
|
+
toCodecJson: () => link()(URLString, Transformation.urlFromString),
|
|
3862
5164
|
toArbitrary: () => fc => fc.webUrl().map(s => new globalThis.URL(s)),
|
|
3863
5165
|
toEquivalence: () => (a, b) => a.toString() === b.toString()
|
|
3864
5166
|
});
|
|
@@ -3874,15 +5176,27 @@ export const URL = /*#__PURE__*/instanceOf(globalThis.URL, {
|
|
|
3874
5176
|
* @category URL
|
|
3875
5177
|
* @since 4.0.0
|
|
3876
5178
|
*/
|
|
3877
|
-
export const URLFromString = /*#__PURE__*/
|
|
3878
|
-
|
|
3879
|
-
|
|
5179
|
+
export const URLFromString = /*#__PURE__*/URLString.pipe(/*#__PURE__*/decodeTo(URL, Transformation.urlFromString));
|
|
5180
|
+
const DateString = /*#__PURE__*/String.annotate({
|
|
5181
|
+
expected: "a string in ISO 8601 format that will be decoded as a Date"
|
|
5182
|
+
});
|
|
3880
5183
|
/**
|
|
3881
5184
|
* A schema for JavaScript `Date` objects.
|
|
3882
5185
|
*
|
|
3883
5186
|
* This schema accepts any `Date` instance, including invalid dates (e.g., `new
|
|
3884
|
-
* Date("invalid")`). For validating only valid dates, use
|
|
5187
|
+
* Date("invalid")`). For validating only valid dates, use {@link DateValid}
|
|
5188
|
+
* instead. The default JSON serializer encodes `Date` as an ISO 8601 string.
|
|
5189
|
+
*
|
|
5190
|
+
* **Example** (Date schema)
|
|
5191
|
+
*
|
|
5192
|
+
* ```ts
|
|
5193
|
+
* import { Schema } from "effect"
|
|
3885
5194
|
*
|
|
5195
|
+
* Schema.decodeUnknownSync(Schema.Date)(new Date("2024-01-01"))
|
|
5196
|
+
* // => Date { 2024-01-01T00:00:00.000Z }
|
|
5197
|
+
* ```
|
|
5198
|
+
*
|
|
5199
|
+
* @category Date
|
|
3886
5200
|
* @since 4.0.0
|
|
3887
5201
|
*/
|
|
3888
5202
|
export const Date = /*#__PURE__*/instanceOf(globalThis.Date, {
|
|
@@ -3894,29 +5208,49 @@ export const Date = /*#__PURE__*/instanceOf(globalThis.Date, {
|
|
|
3894
5208
|
Type: `globalThis.Date`
|
|
3895
5209
|
},
|
|
3896
5210
|
expected: "Date",
|
|
3897
|
-
toCodecJson: () => link()(
|
|
3898
|
-
expected: "a string in ISO 8601 format that will be decoded as a Date"
|
|
3899
|
-
}), Transformation.transform({
|
|
3900
|
-
decode: s => new globalThis.Date(s),
|
|
3901
|
-
encode: formatDate
|
|
3902
|
-
})),
|
|
5211
|
+
toCodecJson: () => link()(DateString, Transformation.dateFromString),
|
|
3903
5212
|
toArbitrary: () => (fc, ctx) => fc.date(ctx?.constraints?.date)
|
|
3904
5213
|
});
|
|
5214
|
+
/**
|
|
5215
|
+
* A transformation schema that parses an ISO 8601 string into a `Date`.
|
|
5216
|
+
*
|
|
5217
|
+
* Decoding:
|
|
5218
|
+
* - A `string` is decoded as a `Date`.
|
|
5219
|
+
*
|
|
5220
|
+
* Encoding:
|
|
5221
|
+
* - A `Date` is encoded as a `string`.
|
|
5222
|
+
*
|
|
5223
|
+
* @category Date
|
|
5224
|
+
* @since 4.0.0
|
|
5225
|
+
*/
|
|
5226
|
+
export const DateFromString = /*#__PURE__*/DateString.pipe(/*#__PURE__*/decodeTo(Date, Transformation.dateFromString));
|
|
3905
5227
|
/**
|
|
3906
5228
|
* A schema for **valid** JavaScript `Date` objects.
|
|
3907
5229
|
*
|
|
3908
5230
|
* This schema accepts `Date` instances but rejects invalid dates (such as `new
|
|
3909
5231
|
* Date("invalid")`).
|
|
3910
5232
|
*
|
|
5233
|
+
* @category Date
|
|
3911
5234
|
* @since 4.0.0
|
|
3912
5235
|
*/
|
|
3913
5236
|
export const DateValid = /*#__PURE__*/Date.check(/*#__PURE__*/isDateValid());
|
|
3914
5237
|
/**
|
|
3915
5238
|
* A schema for `Duration` values.
|
|
3916
5239
|
*
|
|
3917
|
-
*
|
|
5240
|
+
* The default JSON serializer encodes `Duration` as a tagged object with the
|
|
5241
|
+
* duration type and value.
|
|
5242
|
+
*
|
|
5243
|
+
* **Example** (Duration schema)
|
|
5244
|
+
*
|
|
5245
|
+
* ```ts
|
|
5246
|
+
* import { Schema } from "effect"
|
|
5247
|
+
* import { Duration } from "effect"
|
|
5248
|
+
*
|
|
5249
|
+
* Schema.decodeUnknownSync(Schema.Duration)(Duration.seconds(5))
|
|
5250
|
+
* // => Duration(5s)
|
|
5251
|
+
* ```
|
|
3918
5252
|
*
|
|
3919
|
-
*
|
|
5253
|
+
* @category Duration
|
|
3920
5254
|
*
|
|
3921
5255
|
* @since 4.0.0
|
|
3922
5256
|
*/
|
|
@@ -3980,6 +5314,24 @@ export const Duration = /*#__PURE__*/declare(Duration_.isDuration, {
|
|
|
3980
5314
|
toFormatter: () => globalThis.String,
|
|
3981
5315
|
toEquivalence: () => Duration_.Equivalence
|
|
3982
5316
|
});
|
|
5317
|
+
const DurationString = /*#__PURE__*/String.annotate({
|
|
5318
|
+
expected: "a string that will be decoded as a Duration"
|
|
5319
|
+
});
|
|
5320
|
+
/**
|
|
5321
|
+
* A transformation schema that parses a string into a `Duration`.
|
|
5322
|
+
*
|
|
5323
|
+
* Decoding:
|
|
5324
|
+
* - A `string` is decoded as a `Duration`, accepting any format that
|
|
5325
|
+
* `Duration.fromInput` can parse.
|
|
5326
|
+
*
|
|
5327
|
+
* Encoding:
|
|
5328
|
+
* - A `Duration` is encoded as a parseable `string`.
|
|
5329
|
+
*
|
|
5330
|
+
* @category Duration
|
|
5331
|
+
* @since 4.0.0
|
|
5332
|
+
*/
|
|
5333
|
+
export const DurationFromString = /*#__PURE__*/DurationString.pipe(/*#__PURE__*/decodeTo(Duration, Transformation.durationFromString));
|
|
5334
|
+
const bigint0 = /*#__PURE__*/globalThis.BigInt(0);
|
|
3983
5335
|
/**
|
|
3984
5336
|
* A transformation schema that decodes a non-negative `bigint` into a
|
|
3985
5337
|
* `Duration`, treating the `bigint` value as the duration in nanoseconds.
|
|
@@ -3993,7 +5345,7 @@ export const Duration = /*#__PURE__*/declare(Duration_.isDuration, {
|
|
|
3993
5345
|
* @category Duration
|
|
3994
5346
|
* @since 4.0.0
|
|
3995
5347
|
*/
|
|
3996
|
-
export const DurationFromNanos = /*#__PURE__*/BigInt.check(isGreaterThanOrEqualToBigInt(
|
|
5348
|
+
export const DurationFromNanos = /*#__PURE__*/BigInt.check(isGreaterThanOrEqualToBigInt(bigint0)).pipe(/*#__PURE__*/decodeTo(Duration, Transformation.durationFromNanos));
|
|
3997
5349
|
/**
|
|
3998
5350
|
* A transformation schema that decodes a non-negative (possibly infinite)
|
|
3999
5351
|
* integer into a `Duration`, treating the integer value as the duration in
|
|
@@ -4011,6 +5363,9 @@ export const DurationFromNanos = /*#__PURE__*/BigInt.check(isGreaterThanOrEqualT
|
|
|
4011
5363
|
* @since 4.0.0
|
|
4012
5364
|
*/
|
|
4013
5365
|
export const DurationFromMillis = /*#__PURE__*/Number.check(isGreaterThanOrEqualTo(0)).pipe(/*#__PURE__*/decodeTo(Duration, Transformation.durationFromMillis));
|
|
5366
|
+
const BigDecimalString = /*#__PURE__*/String.annotate({
|
|
5367
|
+
expected: "a string that will be decoded as a BigDecimal"
|
|
5368
|
+
});
|
|
4014
5369
|
/**
|
|
4015
5370
|
* A schema for `BigDecimal` values.
|
|
4016
5371
|
*
|
|
@@ -4018,6 +5373,7 @@ export const DurationFromMillis = /*#__PURE__*/Number.check(isGreaterThanOrEqual
|
|
|
4018
5373
|
*
|
|
4019
5374
|
* - encodes `BigDecimal` as a `string`
|
|
4020
5375
|
*
|
|
5376
|
+
* @category BigDecimal
|
|
4021
5377
|
* @since 4.0.0
|
|
4022
5378
|
*/
|
|
4023
5379
|
export const BigDecimal = /*#__PURE__*/declare(BigDecimal_.isBigDecimal, {
|
|
@@ -4030,9 +5386,7 @@ export const BigDecimal = /*#__PURE__*/declare(BigDecimal_.isBigDecimal, {
|
|
|
4030
5386
|
importDeclaration: `import * as BigDecimal from "effect/BigDecimal"`
|
|
4031
5387
|
},
|
|
4032
5388
|
expected: "BigDecimal",
|
|
4033
|
-
toCodecJson: () => link()(
|
|
4034
|
-
expected: "a string that will be decoded as a BigDecimal"
|
|
4035
|
-
}), Transformation.bigDecimalFromString),
|
|
5389
|
+
toCodecJson: () => link()(BigDecimalString, Transformation.bigDecimalFromString),
|
|
4036
5390
|
toArbitrary: () => fc => fc.tuple(fc.bigInt(), fc.integer({
|
|
4037
5391
|
min: 0,
|
|
4038
5392
|
max: 20
|
|
@@ -4040,6 +5394,19 @@ export const BigDecimal = /*#__PURE__*/declare(BigDecimal_.isBigDecimal, {
|
|
|
4040
5394
|
toFormatter: () => bd => BigDecimal_.format(bd),
|
|
4041
5395
|
toEquivalence: () => BigDecimal_.Equivalence
|
|
4042
5396
|
});
|
|
5397
|
+
/**
|
|
5398
|
+
* A transformation schema that parses a string into a `BigDecimal`.
|
|
5399
|
+
*
|
|
5400
|
+
* Decoding:
|
|
5401
|
+
* - A `string` is decoded as a `BigDecimal`.
|
|
5402
|
+
*
|
|
5403
|
+
* Encoding:
|
|
5404
|
+
* - A `BigDecimal` is encoded as a `string`.
|
|
5405
|
+
*
|
|
5406
|
+
* @category BigDecimal
|
|
5407
|
+
* @since 4.0.0
|
|
5408
|
+
*/
|
|
5409
|
+
export const BigDecimalFromString = /*#__PURE__*/BigDecimalString.pipe(/*#__PURE__*/decodeTo(BigDecimal, Transformation.bigDecimalFromString));
|
|
4043
5410
|
/**
|
|
4044
5411
|
* A transformation schema that decodes a JSON-encoded string into an `unknown` value.
|
|
4045
5412
|
*
|
|
@@ -4060,6 +5427,7 @@ export const BigDecimal = /*#__PURE__*/declare(BigDecimal_.isBigDecimal, {
|
|
|
4060
5427
|
* // => { a: 1, b: 2 }
|
|
4061
5428
|
* ```
|
|
4062
5429
|
*
|
|
5430
|
+
* @category JSON
|
|
4063
5431
|
* @since 4.0.0
|
|
4064
5432
|
*/
|
|
4065
5433
|
export const UnknownFromJsonString = /*#__PURE__*/fromJsonString(Unknown);
|
|
@@ -4124,6 +5492,7 @@ export const UnknownFromJsonString = /*#__PURE__*/fromJsonString(Unknown);
|
|
|
4124
5492
|
* // }
|
|
4125
5493
|
* ```
|
|
4126
5494
|
*
|
|
5495
|
+
* @category JSON
|
|
4127
5496
|
* @since 4.0.0
|
|
4128
5497
|
*/
|
|
4129
5498
|
export function fromJsonString(schema) {
|
|
@@ -4134,6 +5503,12 @@ export function fromJsonString(schema) {
|
|
|
4134
5503
|
}).pipe(decodeTo(schema, Transformation.fromJsonString));
|
|
4135
5504
|
}
|
|
4136
5505
|
/**
|
|
5506
|
+
* Schema for JavaScript `File` objects.
|
|
5507
|
+
*
|
|
5508
|
+
* The default JSON serializer encodes a `File` as `{ data, type, name, lastModified }`
|
|
5509
|
+
* where `data` is base64-encoded.
|
|
5510
|
+
*
|
|
5511
|
+
* @category File
|
|
4137
5512
|
* @since 4.0.0
|
|
4138
5513
|
*/
|
|
4139
5514
|
export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
@@ -4180,6 +5555,12 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
|
4180
5555
|
}))
|
|
4181
5556
|
});
|
|
4182
5557
|
/**
|
|
5558
|
+
* Schema for JavaScript `FormData` objects.
|
|
5559
|
+
*
|
|
5560
|
+
* The default JSON serializer encodes a `FormData` as an array of `[key, entry]`
|
|
5561
|
+
* pairs where each entry is tagged as `"String"` or `"File"`.
|
|
5562
|
+
*
|
|
5563
|
+
* @category FormData
|
|
4183
5564
|
* @since 4.0.0
|
|
4184
5565
|
*/
|
|
4185
5566
|
export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
|
|
@@ -4191,7 +5572,7 @@ export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
|
|
|
4191
5572
|
Type: `globalThis.FormData`
|
|
4192
5573
|
},
|
|
4193
5574
|
expected: "FormData",
|
|
4194
|
-
toCodecJson: () => link()(
|
|
5575
|
+
toCodecJson: () => link()(ArraySchema(Tuple([String, Union([Struct({
|
|
4195
5576
|
_tag: tag("String"),
|
|
4196
5577
|
value: String
|
|
4197
5578
|
}), Struct({
|
|
@@ -4309,6 +5690,11 @@ export function fromFormData(schema) {
|
|
|
4309
5690
|
return FormData.pipe(decodeTo(schema, Transformation.fromFormData));
|
|
4310
5691
|
}
|
|
4311
5692
|
/**
|
|
5693
|
+
* Schema for JavaScript `URLSearchParams` objects.
|
|
5694
|
+
*
|
|
5695
|
+
* The default JSON serializer encodes a `URLSearchParams` as a query string.
|
|
5696
|
+
*
|
|
5697
|
+
* @category URLSearchParams
|
|
4312
5698
|
* @since 4.0.0
|
|
4313
5699
|
*/
|
|
4314
5700
|
export const URLSearchParams = /*#__PURE__*/instanceOf(globalThis.URLSearchParams, {
|
|
@@ -4407,75 +5793,177 @@ export function fromURLSearchParams(schema) {
|
|
|
4407
5793
|
/**
|
|
4408
5794
|
* A schema for finite numbers, rejecting `NaN`, `Infinity`, and `-Infinity`.
|
|
4409
5795
|
*
|
|
5796
|
+
* @category Number
|
|
4410
5797
|
* @since 4.0.0
|
|
4411
5798
|
*/
|
|
4412
5799
|
export const Finite = /*#__PURE__*/Number.check(/*#__PURE__*/isFinite());
|
|
4413
5800
|
/**
|
|
4414
5801
|
* A schema for integers, rejecting `NaN`, `Infinity`, and `-Infinity`.
|
|
4415
5802
|
*
|
|
5803
|
+
* @category Number
|
|
4416
5804
|
* @since 4.0.0
|
|
4417
5805
|
*/
|
|
4418
5806
|
export const Int = /*#__PURE__*/Number.check(/*#__PURE__*/isInt());
|
|
4419
5807
|
/**
|
|
4420
|
-
* A transformation schema that parses a string into a number.
|
|
5808
|
+
* A transformation schema that parses a string into a number.
|
|
5809
|
+
*
|
|
5810
|
+
* Decoding:
|
|
5811
|
+
* - A `string` is decoded as a finite number.
|
|
5812
|
+
*
|
|
5813
|
+
* Encoding:
|
|
5814
|
+
* - A number is encoded as a `string`.
|
|
5815
|
+
*
|
|
5816
|
+
* @category Number
|
|
5817
|
+
* @since 4.0.0
|
|
5818
|
+
*/
|
|
5819
|
+
export const NumberFromString = /*#__PURE__*/String.annotate({
|
|
5820
|
+
expected: "a string that will be decoded as a number"
|
|
5821
|
+
}).pipe(/*#__PURE__*/decodeTo(Number, Transformation.numberFromString));
|
|
5822
|
+
/**
|
|
5823
|
+
* A transformation schema that parses a string into a finite number.
|
|
5824
|
+
*
|
|
5825
|
+
* Decoding:
|
|
5826
|
+
* - A `string` is decoded as a finite number, rejecting `NaN`, `Infinity`, and
|
|
5827
|
+
* `-Infinity` values.
|
|
5828
|
+
*
|
|
5829
|
+
* Encoding:
|
|
5830
|
+
* - A finite number is encoded as a `string`.
|
|
5831
|
+
*
|
|
5832
|
+
* @category Number
|
|
5833
|
+
* @since 4.0.0
|
|
5834
|
+
*/
|
|
5835
|
+
export const FiniteFromString = /*#__PURE__*/String.annotate({
|
|
5836
|
+
expected: "a string that will be decoded as a finite number"
|
|
5837
|
+
}).pipe(/*#__PURE__*/decodeTo(Finite, Transformation.numberFromString));
|
|
5838
|
+
/**
|
|
5839
|
+
* A transformation schema that parses a string into a `bigint`.
|
|
5840
|
+
*
|
|
5841
|
+
* Decoding:
|
|
5842
|
+
* - A `string` is decoded as a `bigint`.
|
|
5843
|
+
*
|
|
5844
|
+
* Encoding:
|
|
5845
|
+
* - A `bigint` is encoded as a `string`.
|
|
5846
|
+
*
|
|
5847
|
+
* @category BigInt
|
|
5848
|
+
* @since 4.0.0
|
|
5849
|
+
*/
|
|
5850
|
+
export const BigIntFromString = /*#__PURE__*/make(AST.bigIntString).pipe(/*#__PURE__*/decodeTo(BigInt, Transformation.bigintFromString));
|
|
5851
|
+
/**
|
|
5852
|
+
* A schema for strings that contains no leading or trailing whitespaces.
|
|
5853
|
+
*
|
|
5854
|
+
* @category String
|
|
5855
|
+
* @since 4.0.0
|
|
5856
|
+
*/
|
|
5857
|
+
export const Trimmed = /*#__PURE__*/String.check(/*#__PURE__*/isTrimmed());
|
|
5858
|
+
/**
|
|
5859
|
+
* A transformation schema that trims whitespace from a string.
|
|
5860
|
+
*
|
|
5861
|
+
* Decoding:
|
|
5862
|
+
* - A `string` is decoded as a string with no leading or trailing whitespaces.
|
|
5863
|
+
*
|
|
5864
|
+
* Encoding:
|
|
5865
|
+
* - The trimmed string is encoded as is.
|
|
5866
|
+
*
|
|
5867
|
+
* @category String
|
|
5868
|
+
* @since 4.0.0
|
|
5869
|
+
*/
|
|
5870
|
+
export const Trim = /*#__PURE__*/String.annotate({
|
|
5871
|
+
expected: "a string that will be decoded as a trimmed string"
|
|
5872
|
+
}).pipe(/*#__PURE__*/decodeTo(Trimmed, /*#__PURE__*/Transformation.trim()));
|
|
5873
|
+
/**
|
|
5874
|
+
* Decodes a base64 (RFC4648) encoded string into a UTF-8 string.
|
|
4421
5875
|
*
|
|
4422
5876
|
* Decoding:
|
|
4423
|
-
* - A
|
|
5877
|
+
* - A **valid** base64 encoded string is decoded as a UTF-8 `string`.
|
|
4424
5878
|
*
|
|
4425
5879
|
* Encoding:
|
|
4426
|
-
* - A
|
|
5880
|
+
* - A `string` is encoded as a base64-encoded string.
|
|
4427
5881
|
*
|
|
5882
|
+
* @category String
|
|
4428
5883
|
* @since 4.0.0
|
|
4429
5884
|
*/
|
|
4430
|
-
export const
|
|
4431
|
-
expected: "a string that will be decoded as a
|
|
4432
|
-
}).pipe(/*#__PURE__*/decodeTo(
|
|
5885
|
+
export const StringFromBase64 = /*#__PURE__*/String.annotate({
|
|
5886
|
+
expected: "a base64 encoded string that will be decoded as a UTF-8 string"
|
|
5887
|
+
}).pipe(/*#__PURE__*/decodeTo(String, Transformation.stringFromBase64String));
|
|
4433
5888
|
/**
|
|
4434
|
-
*
|
|
5889
|
+
* Decodes a base64 (URL) encoded string into a UTF-8 string.
|
|
4435
5890
|
*
|
|
4436
5891
|
* Decoding:
|
|
4437
|
-
* - A
|
|
4438
|
-
* `-Infinity` values.
|
|
5892
|
+
* - A **valid** base64 (URL) encoded string is decoded as a UTF-8 `string`.
|
|
4439
5893
|
*
|
|
4440
5894
|
* Encoding:
|
|
4441
|
-
* - A
|
|
5895
|
+
* - A `string` is encoded as a base64 (URL) encoded string.
|
|
4442
5896
|
*
|
|
5897
|
+
* @category String
|
|
4443
5898
|
* @since 4.0.0
|
|
4444
5899
|
*/
|
|
4445
|
-
export const
|
|
4446
|
-
expected: "a string that will be decoded as a
|
|
4447
|
-
}).pipe(/*#__PURE__*/decodeTo(
|
|
5900
|
+
export const StringFromBase64Url = /*#__PURE__*/String.annotate({
|
|
5901
|
+
expected: "a base64 (URL) encoded string that will be decoded as a UTF-8 string"
|
|
5902
|
+
}).pipe(/*#__PURE__*/decodeTo(String, Transformation.stringFromBase64UrlString));
|
|
4448
5903
|
/**
|
|
4449
|
-
*
|
|
5904
|
+
* Decodes a hex encoded string into a UTF-8 string.
|
|
4450
5905
|
*
|
|
5906
|
+
* Decoding:
|
|
5907
|
+
* - A **valid** hex encoded string is decoded as a UTF-8 `string`.
|
|
5908
|
+
*
|
|
5909
|
+
* Encoding:
|
|
5910
|
+
* - A `string` is encoded as a hex string.
|
|
5911
|
+
*
|
|
5912
|
+
* @category String
|
|
4451
5913
|
* @since 4.0.0
|
|
4452
5914
|
*/
|
|
4453
|
-
export const
|
|
5915
|
+
export const StringFromHex = /*#__PURE__*/String.annotate({
|
|
5916
|
+
expected: "a hex encoded string that will be decoded as a UTF-8 string"
|
|
5917
|
+
}).pipe(/*#__PURE__*/decodeTo(String, Transformation.stringFromHexString));
|
|
4454
5918
|
/**
|
|
4455
|
-
*
|
|
5919
|
+
* Decodes a URI component encoded string into a UTF-8 string.
|
|
5920
|
+
* Can be used to store data in a URL.
|
|
4456
5921
|
*
|
|
4457
5922
|
* Decoding:
|
|
4458
|
-
* - A
|
|
5923
|
+
* - A **valid** URI component encoded string is decoded as a UTF-8 `string`.
|
|
4459
5924
|
*
|
|
4460
5925
|
* Encoding:
|
|
4461
|
-
* -
|
|
5926
|
+
* - A `string` is encoded as a URI component encoded string.
|
|
5927
|
+
*
|
|
5928
|
+
* **Example**
|
|
5929
|
+
*
|
|
5930
|
+
* ```ts
|
|
5931
|
+
* import { Schema } from "effect"
|
|
5932
|
+
*
|
|
5933
|
+
* const PaginationSchema = Schema.Struct({
|
|
5934
|
+
* maxItemPerPage: Schema.Number,
|
|
5935
|
+
* page: Schema.Number
|
|
5936
|
+
* })
|
|
5937
|
+
*
|
|
5938
|
+
* const UrlSchema = Schema.StringFromUriComponent.pipe(
|
|
5939
|
+
* Schema.decodeTo(Schema.fromJsonString(PaginationSchema))
|
|
5940
|
+
* )
|
|
5941
|
+
*
|
|
5942
|
+
* console.log(Schema.encodeSync(UrlSchema)({ maxItemPerPage: 10, page: 1 }))
|
|
5943
|
+
* // %7B%22maxItemPerPage%22%3A10%2C%22page%22%3A1%7D
|
|
5944
|
+
* ```
|
|
4462
5945
|
*
|
|
5946
|
+
* @category String
|
|
4463
5947
|
* @since 4.0.0
|
|
4464
5948
|
*/
|
|
4465
|
-
export const
|
|
4466
|
-
expected: "a string that will be decoded as a
|
|
4467
|
-
}).pipe(/*#__PURE__*/decodeTo(
|
|
5949
|
+
export const StringFromUriComponent = /*#__PURE__*/String.annotate({
|
|
5950
|
+
expected: "a URI component encoded string that will be decoded as a UTF-8 string"
|
|
5951
|
+
}).pipe(/*#__PURE__*/decodeTo(String, Transformation.stringFromUriComponent));
|
|
4468
5952
|
/**
|
|
5953
|
+
* A union schema for JavaScript property keys: `number | symbol | string`.
|
|
5954
|
+
*
|
|
5955
|
+
* @category PropertyKey
|
|
4469
5956
|
* @since 4.0.0
|
|
4470
5957
|
*/
|
|
4471
5958
|
export const PropertyKey = /*#__PURE__*/Union([Finite, Symbol, String]);
|
|
4472
5959
|
/**
|
|
5960
|
+
* @category StandardSchema
|
|
4473
5961
|
* @since 4.0.0
|
|
4474
5962
|
*/
|
|
4475
5963
|
export const StandardSchemaV1FailureResult = /*#__PURE__*/Struct({
|
|
4476
|
-
issues: /*#__PURE__*/
|
|
5964
|
+
issues: /*#__PURE__*/ArraySchema(/*#__PURE__*/Struct({
|
|
4477
5965
|
message: String,
|
|
4478
|
-
path: /*#__PURE__*/optional(/*#__PURE__*/
|
|
5966
|
+
path: /*#__PURE__*/optional(/*#__PURE__*/ArraySchema(/*#__PURE__*/Union([PropertyKey, /*#__PURE__*/Struct({
|
|
4479
5967
|
key: PropertyKey
|
|
4480
5968
|
})])))
|
|
4481
5969
|
}))
|
|
@@ -4581,7 +6069,7 @@ export const Uint8ArrayFromHex = /*#__PURE__*/String.annotate({
|
|
|
4581
6069
|
*/
|
|
4582
6070
|
export const DateTimeUtc = /*#__PURE__*/declare(u => DateTime.isDateTime(u) && DateTime.isUtc(u), {
|
|
4583
6071
|
typeConstructor: {
|
|
4584
|
-
_tag: "DateTime.Utc"
|
|
6072
|
+
_tag: "effect/DateTime.Utc"
|
|
4585
6073
|
},
|
|
4586
6074
|
generation: {
|
|
4587
6075
|
runtime: `Schema.DateTimeUtc`,
|
|
@@ -4658,7 +6146,7 @@ export const DateTimeUtcFromMillis = /*#__PURE__*/Number.pipe(/*#__PURE__*/decod
|
|
|
4658
6146
|
*/
|
|
4659
6147
|
export const TimeZoneOffset = /*#__PURE__*/declare(DateTime.isTimeZoneOffset, {
|
|
4660
6148
|
typeConstructor: {
|
|
4661
|
-
_tag: "DateTime.TimeZone.Offset"
|
|
6149
|
+
_tag: "effect/DateTime.TimeZone.Offset"
|
|
4662
6150
|
},
|
|
4663
6151
|
generation: {
|
|
4664
6152
|
runtime: `Schema.TimeZoneOffset`,
|
|
@@ -4674,6 +6162,9 @@ export const TimeZoneOffset = /*#__PURE__*/declare(DateTime.isTimeZoneOffset, {
|
|
|
4674
6162
|
toFormatter: () => tz => DateTime.zoneToString(tz),
|
|
4675
6163
|
toEquivalence: () => (a, b) => a.offset === b.offset
|
|
4676
6164
|
});
|
|
6165
|
+
const TimeZoneNamedString = /*#__PURE__*/String.annotate({
|
|
6166
|
+
expected: "an IANA time zone identifier"
|
|
6167
|
+
});
|
|
4677
6168
|
/**
|
|
4678
6169
|
* A schema for `DateTime.TimeZone.Named` values.
|
|
4679
6170
|
*
|
|
@@ -4686,7 +6177,7 @@ export const TimeZoneOffset = /*#__PURE__*/declare(DateTime.isTimeZoneOffset, {
|
|
|
4686
6177
|
*/
|
|
4687
6178
|
export const TimeZoneNamed = /*#__PURE__*/declare(DateTime.isTimeZoneNamed, {
|
|
4688
6179
|
typeConstructor: {
|
|
4689
|
-
_tag: "DateTime.TimeZone.Named"
|
|
6180
|
+
_tag: "effect/DateTime.TimeZone.Named"
|
|
4690
6181
|
},
|
|
4691
6182
|
generation: {
|
|
4692
6183
|
runtime: `Schema.TimeZoneNamed`,
|
|
@@ -4694,13 +6185,27 @@ export const TimeZoneNamed = /*#__PURE__*/declare(DateTime.isTimeZoneNamed, {
|
|
|
4694
6185
|
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
4695
6186
|
},
|
|
4696
6187
|
expected: "DateTime.TimeZone.Named",
|
|
4697
|
-
toCodecJson: () => link()(
|
|
4698
|
-
expected: "an IANA time zone identifier"
|
|
4699
|
-
}), Transformation.timeZoneNamedFromString),
|
|
6188
|
+
toCodecJson: () => link()(TimeZoneNamedString, Transformation.timeZoneNamedFromString),
|
|
4700
6189
|
toArbitrary: () => fc => fc.constantFrom(...["UTC", "Europe/London", "America/New_York", "Asia/Tokyo", "Australia/Sydney"].map(DateTime.zoneMakeNamedUnsafe)),
|
|
4701
6190
|
toFormatter: () => tz => DateTime.zoneToString(tz),
|
|
4702
6191
|
toEquivalence: () => (a, b) => a.id === b.id
|
|
4703
6192
|
});
|
|
6193
|
+
/**
|
|
6194
|
+
* A transformation schema that parses an IANA time zone identifier string into a `DateTime.TimeZone.Named`.
|
|
6195
|
+
*
|
|
6196
|
+
* Decoding:
|
|
6197
|
+
* - A `string` is decoded as a `DateTime.TimeZone.Named`.
|
|
6198
|
+
*
|
|
6199
|
+
* Encoding:
|
|
6200
|
+
* - A `DateTime.TimeZone.Named` is encoded as a `string`.
|
|
6201
|
+
*
|
|
6202
|
+
* @category DateTime
|
|
6203
|
+
* @since 4.0.0
|
|
6204
|
+
*/
|
|
6205
|
+
export const TimeZoneNamedFromString = /*#__PURE__*/TimeZoneNamedString.pipe(/*#__PURE__*/decodeTo(TimeZoneNamed, Transformation.timeZoneNamedFromString));
|
|
6206
|
+
const TimeZoneString = /*#__PURE__*/String.annotate({
|
|
6207
|
+
expected: "a time zone string (IANA identifier or offset like +03:00)"
|
|
6208
|
+
});
|
|
4704
6209
|
/**
|
|
4705
6210
|
* A schema for `DateTime.TimeZone` values.
|
|
4706
6211
|
*
|
|
@@ -4714,7 +6219,7 @@ export const TimeZoneNamed = /*#__PURE__*/declare(DateTime.isTimeZoneNamed, {
|
|
|
4714
6219
|
*/
|
|
4715
6220
|
export const TimeZone = /*#__PURE__*/declare(DateTime.isTimeZone, {
|
|
4716
6221
|
typeConstructor: {
|
|
4717
|
-
_tag: "DateTime.TimeZone"
|
|
6222
|
+
_tag: "effect/DateTime.TimeZone"
|
|
4718
6223
|
},
|
|
4719
6224
|
generation: {
|
|
4720
6225
|
runtime: `Schema.TimeZone`,
|
|
@@ -4722,9 +6227,7 @@ export const TimeZone = /*#__PURE__*/declare(DateTime.isTimeZone, {
|
|
|
4722
6227
|
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
4723
6228
|
},
|
|
4724
6229
|
expected: "DateTime.TimeZone",
|
|
4725
|
-
toCodecJson: () => link()(
|
|
4726
|
-
expected: "a time zone string (IANA identifier or offset like +03:00)"
|
|
4727
|
-
}), Transformation.timeZoneFromString),
|
|
6230
|
+
toCodecJson: () => link()(TimeZoneString, Transformation.timeZoneFromString),
|
|
4728
6231
|
toArbitrary: () => fc => fc.oneof(fc.integer({
|
|
4729
6232
|
min: -12 * 60 * 60 * 1000,
|
|
4730
6233
|
max: 14 * 60 * 60 * 1000
|
|
@@ -4732,6 +6235,22 @@ export const TimeZone = /*#__PURE__*/declare(DateTime.isTimeZone, {
|
|
|
4732
6235
|
toFormatter: () => tz => DateTime.zoneToString(tz),
|
|
4733
6236
|
toEquivalence: () => (a, b) => DateTime.zoneToString(a) === DateTime.zoneToString(b)
|
|
4734
6237
|
});
|
|
6238
|
+
/**
|
|
6239
|
+
* A transformation schema that parses a time zone string into a `DateTime.TimeZone`.
|
|
6240
|
+
*
|
|
6241
|
+
* Decoding:
|
|
6242
|
+
* - A `string` (IANA identifier or offset like `+03:00`) is decoded as a `DateTime.TimeZone`.
|
|
6243
|
+
*
|
|
6244
|
+
* Encoding:
|
|
6245
|
+
* - A `DateTime.TimeZone` is encoded as a `string`.
|
|
6246
|
+
*
|
|
6247
|
+
* @category DateTime
|
|
6248
|
+
* @since 4.0.0
|
|
6249
|
+
*/
|
|
6250
|
+
export const TimeZoneFromString = /*#__PURE__*/TimeZoneString.pipe(/*#__PURE__*/decodeTo(TimeZone, Transformation.timeZoneFromString));
|
|
6251
|
+
const DateTimeZonedString = /*#__PURE__*/String.annotate({
|
|
6252
|
+
expected: "a zoned DateTime string (e.g. 2024-01-01T00:00:00.000+00:00[Europe/London])"
|
|
6253
|
+
});
|
|
4735
6254
|
/**
|
|
4736
6255
|
* A schema for `DateTime.Zoned` values.
|
|
4737
6256
|
*
|
|
@@ -4745,7 +6264,7 @@ export const TimeZone = /*#__PURE__*/declare(DateTime.isTimeZone, {
|
|
|
4745
6264
|
*/
|
|
4746
6265
|
export const DateTimeZoned = /*#__PURE__*/declare(u => DateTime.isDateTime(u) && DateTime.isZoned(u), {
|
|
4747
6266
|
typeConstructor: {
|
|
4748
|
-
_tag: "DateTime.Zoned"
|
|
6267
|
+
_tag: "effect/DateTime.Zoned"
|
|
4749
6268
|
},
|
|
4750
6269
|
generation: {
|
|
4751
6270
|
runtime: `Schema.DateTimeZoned`,
|
|
@@ -4753,9 +6272,7 @@ export const DateTimeZoned = /*#__PURE__*/declare(u => DateTime.isDateTime(u) &&
|
|
|
4753
6272
|
importDeclaration: `import * as DateTime from "effect/DateTime"`
|
|
4754
6273
|
},
|
|
4755
6274
|
expected: "DateTime.Zoned",
|
|
4756
|
-
toCodecJson: () => link()(
|
|
4757
|
-
expected: "a zoned DateTime string (e.g. 2024-01-01T00:00:00.000+00:00[Europe/London])"
|
|
4758
|
-
}), Transformation.dateTimeZonedFromString),
|
|
6275
|
+
toCodecJson: () => link()(DateTimeZonedString, Transformation.dateTimeZonedFromString),
|
|
4759
6276
|
toArbitrary: () => (fc, ctx) => fc.tuple(fc.date({
|
|
4760
6277
|
noInvalidDate: true,
|
|
4761
6278
|
min: new globalThis.Date(-8640000000000000 + 14 * 60 * 60 * 1000),
|
|
@@ -4767,30 +6284,34 @@ export const DateTimeZoned = /*#__PURE__*/declare(u => DateTime.isDateTime(u) &&
|
|
|
4767
6284
|
toFormatter: () => zoned => DateTime.formatIsoZoned(zoned),
|
|
4768
6285
|
toEquivalence: () => DateTime.Equivalence
|
|
4769
6286
|
});
|
|
6287
|
+
/**
|
|
6288
|
+
* A transformation schema that parses a zoned DateTime string into a `DateTime.Zoned`.
|
|
6289
|
+
*
|
|
6290
|
+
* Decoding:
|
|
6291
|
+
* - A `string` (e.g. `2024-01-01T00:00:00.000+00:00[Europe/London]`) is decoded as a `DateTime.Zoned`.
|
|
6292
|
+
*
|
|
6293
|
+
* Encoding:
|
|
6294
|
+
* - A `DateTime.Zoned` is encoded as a `string`.
|
|
6295
|
+
*
|
|
6296
|
+
* @category DateTime
|
|
6297
|
+
* @since 4.0.0
|
|
6298
|
+
*/
|
|
6299
|
+
export const DateTimeZonedFromString = /*#__PURE__*/DateTimeZonedString.pipe(/*#__PURE__*/decodeTo(DateTimeZoned, Transformation.dateTimeZonedFromString));
|
|
4770
6300
|
const immerable = /*#__PURE__*/globalThis.Symbol.for("immer-draftable");
|
|
4771
|
-
function makeClass(Inherited, identifier, struct, annotations) {
|
|
6301
|
+
function makeClass(Inherited, identifier, struct, annotations, proto) {
|
|
4772
6302
|
const getClassSchema = getClassSchemaFactory(struct, identifier, annotations);
|
|
4773
6303
|
const ClassTypeId = getClassTypeId(identifier); // HMR support
|
|
4774
|
-
|
|
6304
|
+
const out = class extends Inherited {
|
|
4775
6305
|
constructor(...[input, options]) {
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
...options,
|
|
4786
|
-
disableValidation: true
|
|
4787
|
-
});
|
|
4788
|
-
}
|
|
4789
|
-
}
|
|
4790
|
-
toString() {
|
|
4791
|
-
return `${identifier}(${format({
|
|
4792
|
-
...this
|
|
4793
|
-
})})`;
|
|
6306
|
+
input = input ?? {};
|
|
6307
|
+
const validated = struct.make(input, options);
|
|
6308
|
+
super({
|
|
6309
|
+
...input,
|
|
6310
|
+
...validated
|
|
6311
|
+
}, {
|
|
6312
|
+
...options,
|
|
6313
|
+
disableChecks: true
|
|
6314
|
+
});
|
|
4794
6315
|
}
|
|
4795
6316
|
static [TypeId] = TypeId;
|
|
4796
6317
|
get [ClassTypeId]() {
|
|
@@ -4808,9 +6329,15 @@ function makeClass(Inherited, identifier, struct, annotations) {
|
|
|
4808
6329
|
static rebuild(ast) {
|
|
4809
6330
|
return getClassSchema(this).rebuild(ast);
|
|
4810
6331
|
}
|
|
4811
|
-
static
|
|
6332
|
+
static make(input, options) {
|
|
4812
6333
|
return new this(input, options);
|
|
4813
6334
|
}
|
|
6335
|
+
static makeOption(input, options) {
|
|
6336
|
+
return Parser.makeOption(getClassSchema(this))(input ?? {}, options);
|
|
6337
|
+
}
|
|
6338
|
+
static makeEffect(input, options) {
|
|
6339
|
+
return Effect.mapErrorEager(Parser.makeEffect(getClassSchema(this))(input ?? {}, options), issue => new SchemaError(issue));
|
|
6340
|
+
}
|
|
4814
6341
|
static annotate(annotations) {
|
|
4815
6342
|
return this.rebuild(AST.annotate(this.ast, annotations));
|
|
4816
6343
|
}
|
|
@@ -4828,13 +6355,17 @@ function makeClass(Inherited, identifier, struct, annotations) {
|
|
|
4828
6355
|
};
|
|
4829
6356
|
return makeClass(this, identifier, makeStruct(AST.struct(fields, struct.ast.checks, {
|
|
4830
6357
|
identifier
|
|
4831
|
-
}), fields), annotations);
|
|
6358
|
+
}), fields), annotations, proto);
|
|
4832
6359
|
};
|
|
4833
6360
|
}
|
|
4834
6361
|
static mapFields(f, options) {
|
|
4835
6362
|
return struct.mapFields(f, options);
|
|
4836
6363
|
}
|
|
4837
6364
|
};
|
|
6365
|
+
if (proto !== undefined) {
|
|
6366
|
+
Object.assign(out.prototype, proto(identifier));
|
|
6367
|
+
}
|
|
6368
|
+
return out;
|
|
4838
6369
|
}
|
|
4839
6370
|
function getClassTransformation(self) {
|
|
4840
6371
|
return new Transformation.Transformation(Getter.transform(input => new self(input)), Getter.passthrough());
|
|
@@ -4855,6 +6386,7 @@ function getClassSchemaFactory(from, identifier, annotations) {
|
|
|
4855
6386
|
toCodec: ([from]) => new AST.Link(from.ast, transformation),
|
|
4856
6387
|
toArbitrary: ([from]) => () => from.map(args => new self(args)),
|
|
4857
6388
|
toFormatter: ([from]) => t => `${self.identifier}(${from(t)})`,
|
|
6389
|
+
"~sentinels": AST.collectSentinels(from.ast),
|
|
4858
6390
|
...annotations
|
|
4859
6391
|
}));
|
|
4860
6392
|
memo = from.pipe(decodeTo(to, transformation));
|
|
@@ -4866,14 +6398,81 @@ function isStruct(schema) {
|
|
|
4866
6398
|
return isSchema(schema);
|
|
4867
6399
|
}
|
|
4868
6400
|
/**
|
|
6401
|
+
* Creates a schema-backed class whose constructor validates input against a
|
|
6402
|
+
* {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
|
|
6403
|
+
* input (unless `disableChecks` is set in the options).
|
|
6404
|
+
*
|
|
6405
|
+
* Pass the desired class type as the first type parameter. The second optional
|
|
6406
|
+
* type parameter can be used to add nominal brands.
|
|
6407
|
+
*
|
|
6408
|
+
* **Example** (Basic class)
|
|
6409
|
+
*
|
|
6410
|
+
* ```ts
|
|
6411
|
+
* import { Schema } from "effect"
|
|
6412
|
+
*
|
|
6413
|
+
* class Person extends Schema.Class<Person>("Person")({
|
|
6414
|
+
* name: Schema.String,
|
|
6415
|
+
* age: Schema.Number
|
|
6416
|
+
* }) {}
|
|
6417
|
+
*
|
|
6418
|
+
* const alice = new Person({ name: "Alice", age: 30 })
|
|
6419
|
+
* console.log(alice.name) // "Alice"
|
|
6420
|
+
* console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
|
|
6421
|
+
* ```
|
|
6422
|
+
*
|
|
6423
|
+
* **Example** (Extending a class)
|
|
6424
|
+
*
|
|
6425
|
+
* ```ts
|
|
6426
|
+
* import { Schema } from "effect"
|
|
6427
|
+
*
|
|
6428
|
+
* class Animal extends Schema.Class<Animal>("Animal")({
|
|
6429
|
+
* name: Schema.String
|
|
6430
|
+
* }) {}
|
|
6431
|
+
*
|
|
6432
|
+
* class Dog extends Animal.extend<Dog>("Dog")({
|
|
6433
|
+
* breed: Schema.String
|
|
6434
|
+
* }) {}
|
|
6435
|
+
*
|
|
6436
|
+
* const dog = new Dog({ name: "Rex", breed: "Labrador" })
|
|
6437
|
+
* console.log(dog.name) // "Rex"
|
|
6438
|
+
* console.log(dog.breed) // "Labrador"
|
|
6439
|
+
* ```
|
|
6440
|
+
*
|
|
4869
6441
|
* @category Constructors
|
|
4870
6442
|
* @since 4.0.0
|
|
4871
6443
|
*/
|
|
4872
6444
|
export const Class = identifier => (schema, annotations) => {
|
|
4873
6445
|
const struct = isStruct(schema) ? schema : Struct(schema);
|
|
4874
|
-
return makeClass(Data.Class, identifier, struct, annotations
|
|
6446
|
+
return makeClass(Data.Class, identifier, struct, annotations, identifier => ({
|
|
6447
|
+
toString() {
|
|
6448
|
+
return `${identifier}(${format({
|
|
6449
|
+
...this
|
|
6450
|
+
})})`;
|
|
6451
|
+
}
|
|
6452
|
+
}));
|
|
4875
6453
|
};
|
|
4876
6454
|
/**
|
|
6455
|
+
* Like {@link Class} but automatically adds a `_tag` literal field set to the
|
|
6456
|
+
* given `tag` value. This makes instances compatible with tagged union
|
|
6457
|
+
* discrimination patterns.
|
|
6458
|
+
*
|
|
6459
|
+
* The optional `identifier` parameter overrides the schema identifier;
|
|
6460
|
+
* it defaults to the `tag` value.
|
|
6461
|
+
*
|
|
6462
|
+
* **Example** (Tagged class)
|
|
6463
|
+
*
|
|
6464
|
+
* ```ts
|
|
6465
|
+
* import { Schema } from "effect"
|
|
6466
|
+
*
|
|
6467
|
+
* class Circle extends Schema.TaggedClass<Circle>()("Circle", {
|
|
6468
|
+
* radius: Schema.Number
|
|
6469
|
+
* }) {}
|
|
6470
|
+
*
|
|
6471
|
+
* const c = new Circle({ radius: 5 })
|
|
6472
|
+
* console.log(c._tag) // "Circle"
|
|
6473
|
+
* console.log(c.radius) // 5
|
|
6474
|
+
* ```
|
|
6475
|
+
*
|
|
4877
6476
|
* @category Constructors
|
|
4878
6477
|
* @since 4.0.0
|
|
4879
6478
|
*/
|
|
@@ -4888,14 +6487,54 @@ export const TaggedClass = identifier => {
|
|
|
4888
6487
|
};
|
|
4889
6488
|
};
|
|
4890
6489
|
/**
|
|
6490
|
+
* Creates a schema-backed error class that can be used as a typed,
|
|
6491
|
+
* yieldable error in Effect programs. Combines {@link Class} validation with
|
|
6492
|
+
* the `YieldableError` interface so instances can be yielded directly inside
|
|
6493
|
+
* `Effect.gen`.
|
|
6494
|
+
*
|
|
6495
|
+
* **Example** (Schema-backed error)
|
|
6496
|
+
*
|
|
6497
|
+
* ```ts
|
|
6498
|
+
* import { Effect, Schema } from "effect"
|
|
6499
|
+
*
|
|
6500
|
+
* class NotFound extends Schema.ErrorClass<NotFound>("NotFound")({
|
|
6501
|
+
* id: Schema.Number
|
|
6502
|
+
* }) {}
|
|
6503
|
+
*
|
|
6504
|
+
* const program = Effect.gen(function*() {
|
|
6505
|
+
* yield* new NotFound({ id: 1 })
|
|
6506
|
+
* })
|
|
6507
|
+
* ```
|
|
6508
|
+
*
|
|
4891
6509
|
* @category Constructors
|
|
4892
6510
|
* @since 4.0.0
|
|
4893
6511
|
*/
|
|
4894
6512
|
export const ErrorClass = identifier => (schema, annotations) => {
|
|
4895
6513
|
const struct = isStruct(schema) ? schema : Struct(schema);
|
|
4896
|
-
|
|
6514
|
+
const self = makeClass(core.Error, identifier, struct, annotations, identifier => ({
|
|
6515
|
+
name: identifier
|
|
6516
|
+
}));
|
|
6517
|
+
return self;
|
|
4897
6518
|
};
|
|
4898
6519
|
/**
|
|
6520
|
+
* Like {@link ErrorClass} but automatically adds a `_tag` literal field. The
|
|
6521
|
+
* resulting class is both a schema-validated, yieldable error and a tagged
|
|
6522
|
+
* union member.
|
|
6523
|
+
*
|
|
6524
|
+
* **Example** (Tagged error class)
|
|
6525
|
+
*
|
|
6526
|
+
* ```ts
|
|
6527
|
+
* import { Effect, Schema } from "effect"
|
|
6528
|
+
*
|
|
6529
|
+
* class NotFound extends Schema.TaggedErrorClass<NotFound>()("NotFound", {
|
|
6530
|
+
* id: Schema.Number
|
|
6531
|
+
* }) {}
|
|
6532
|
+
*
|
|
6533
|
+
* const program = Effect.gen(function*() {
|
|
6534
|
+
* yield* new NotFound({ id: 42 })
|
|
6535
|
+
* })
|
|
6536
|
+
* ```
|
|
6537
|
+
*
|
|
4899
6538
|
* @category Constructors
|
|
4900
6539
|
* @since 4.0.0
|
|
4901
6540
|
*/
|
|
@@ -4910,6 +6549,11 @@ export const TaggedErrorClass = identifier => {
|
|
|
4910
6549
|
};
|
|
4911
6550
|
};
|
|
4912
6551
|
/**
|
|
6552
|
+
* Derives a {@link LazyArbitrary} from a schema. The result is memoized so
|
|
6553
|
+
* repeated calls with the same schema are cheap.
|
|
6554
|
+
*
|
|
6555
|
+
* Prefer {@link toArbitrary} when you just need the arbitrary directly.
|
|
6556
|
+
*
|
|
4913
6557
|
* @category Arbitrary
|
|
4914
6558
|
* @since 4.0.0
|
|
4915
6559
|
*/
|
|
@@ -4918,6 +6562,24 @@ export function toArbitraryLazy(schema) {
|
|
|
4918
6562
|
return fc => lawc(fc, {});
|
|
4919
6563
|
}
|
|
4920
6564
|
/**
|
|
6565
|
+
* Derives a `fast-check` `Arbitrary` from a schema for property-based
|
|
6566
|
+
* testing. The derived arbitrary generates values that satisfy the schema.
|
|
6567
|
+
*
|
|
6568
|
+
* **Example** (Generating arbitrary values)
|
|
6569
|
+
*
|
|
6570
|
+
* ```ts
|
|
6571
|
+
* import { Schema } from "effect"
|
|
6572
|
+
* import * as FastCheck from "fast-check"
|
|
6573
|
+
*
|
|
6574
|
+
* const PersonArb = Schema.toArbitrary(
|
|
6575
|
+
* Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
6576
|
+
* )
|
|
6577
|
+
*
|
|
6578
|
+
* // Sample a random value
|
|
6579
|
+
* const sample = FastCheck.sample(PersonArb, 1)[0]
|
|
6580
|
+
* console.log(typeof sample.name) // "string"
|
|
6581
|
+
* ```
|
|
6582
|
+
*
|
|
4921
6583
|
* @category Arbitrary
|
|
4922
6584
|
* @since 4.0.0
|
|
4923
6585
|
*/
|
|
@@ -4944,6 +6606,13 @@ export function overrideToFormatter(toFormatter) {
|
|
|
4944
6606
|
};
|
|
4945
6607
|
}
|
|
4946
6608
|
/**
|
|
6609
|
+
* Derives a string formatter function from a schema. The formatter converts
|
|
6610
|
+
* a value to its human-readable string representation, recursing into structs,
|
|
6611
|
+
* arrays, and unions.
|
|
6612
|
+
*
|
|
6613
|
+
* The optional `onBefore` hook lets you intercept specific AST nodes before
|
|
6614
|
+
* the default formatting logic runs.
|
|
6615
|
+
*
|
|
4947
6616
|
* @category Formatter
|
|
4948
6617
|
* @since 4.0.0
|
|
4949
6618
|
*/
|
|
@@ -5082,10 +6751,9 @@ export function toFormatter(schema, options) {
|
|
|
5082
6751
|
// Equivalence
|
|
5083
6752
|
// -----------------------------------------------------------------------------
|
|
5084
6753
|
/**
|
|
5085
|
-
*
|
|
5086
|
-
*
|
|
5087
|
-
*
|
|
5088
|
-
* the schema invariant.
|
|
6754
|
+
* Overrides the equivalence derivation for a schema by supplying a custom
|
|
6755
|
+
* `Equivalence`. Use this when the default structural equivalence derived by
|
|
6756
|
+
* {@link toEquivalence} is not appropriate for a type.
|
|
5089
6757
|
*
|
|
5090
6758
|
* @category Equivalence
|
|
5091
6759
|
* @since 4.0.0
|
|
@@ -5096,6 +6764,21 @@ export function overrideToEquivalence(toEquivalence) {
|
|
|
5096
6764
|
});
|
|
5097
6765
|
}
|
|
5098
6766
|
/**
|
|
6767
|
+
* Derives an `Equivalence` from a schema. Two values are considered equal when
|
|
6768
|
+
* every field (and nested field) compares equal according to the schema
|
|
6769
|
+
* structure.
|
|
6770
|
+
*
|
|
6771
|
+
* **Example** (Struct equivalence)
|
|
6772
|
+
*
|
|
6773
|
+
* ```ts
|
|
6774
|
+
* import { Schema } from "effect"
|
|
6775
|
+
*
|
|
6776
|
+
* const eq = Schema.toEquivalence(Schema.Struct({ id: Schema.Number, name: Schema.String }))
|
|
6777
|
+
*
|
|
6778
|
+
* console.log(eq({ id: 1, name: "Alice" }, { id: 1, name: "Alice" })) // true
|
|
6779
|
+
* console.log(eq({ id: 1, name: "Alice" }, { id: 2, name: "Alice" })) // false
|
|
6780
|
+
* ```
|
|
6781
|
+
*
|
|
5099
6782
|
* @category Equivalence
|
|
5100
6783
|
* @since 4.0.0
|
|
5101
6784
|
*/
|
|
@@ -5106,6 +6789,10 @@ export function toEquivalence(schema) {
|
|
|
5106
6789
|
// Representation
|
|
5107
6790
|
// -----------------------------------------------------------------------------
|
|
5108
6791
|
/**
|
|
6792
|
+
* Derives an intermediate `SchemaRepresentation.Document` from a schema. This
|
|
6793
|
+
* document is used internally by {@link toJsonSchemaDocument} and related
|
|
6794
|
+
* functions to produce JSON Schema output.
|
|
6795
|
+
*
|
|
5109
6796
|
* @category Representation
|
|
5110
6797
|
* @since 4.0.0
|
|
5111
6798
|
*/
|
|
@@ -5130,31 +6817,114 @@ export function toJsonSchemaDocument(schema, options) {
|
|
|
5130
6817
|
};
|
|
5131
6818
|
}
|
|
5132
6819
|
// -----------------------------------------------------------------------------
|
|
5133
|
-
//
|
|
6820
|
+
// Canonical Codecs
|
|
5134
6821
|
// -----------------------------------------------------------------------------
|
|
5135
6822
|
/**
|
|
5136
|
-
*
|
|
6823
|
+
* Derives a canonical JSON codec from a schema. The encoded form is `unknown`
|
|
6824
|
+
* (any JSON-compatible value), decoded to the schema's `Type`.
|
|
6825
|
+
*
|
|
6826
|
+
* @category Canonical Codecs
|
|
5137
6827
|
* @since 4.0.0
|
|
5138
6828
|
*/
|
|
5139
6829
|
export function toCodecJson(schema) {
|
|
5140
|
-
return make(
|
|
6830
|
+
return make(toCodecJsonTop(schema.ast));
|
|
6831
|
+
}
|
|
6832
|
+
const toCodecJsonTop = /*#__PURE__*/AST.toCodec(ast => {
|
|
6833
|
+
const out = toCodecJsonBase(ast, toCodecJsonTop);
|
|
6834
|
+
return out !== ast && AST.isOptional(ast) ? AST.optionalKeyLastLink(out) : out;
|
|
6835
|
+
});
|
|
6836
|
+
function toCodecJsonBase(ast, recur) {
|
|
6837
|
+
switch (ast._tag) {
|
|
6838
|
+
case "Declaration":
|
|
6839
|
+
{
|
|
6840
|
+
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec;
|
|
6841
|
+
if (Predicate.isFunction(getLink)) {
|
|
6842
|
+
const tps = AST.isDeclaration(ast) ? ast.typeParameters.map(tp => InternalSchema.make(AST.toEncoded(tp))) : [];
|
|
6843
|
+
const link = getLink(tps);
|
|
6844
|
+
const to = recur(link.to);
|
|
6845
|
+
return AST.replaceEncoding(ast, to === link.to ? [link] : [new AST.Link(to, link.transformation)]);
|
|
6846
|
+
}
|
|
6847
|
+
return AST.replaceEncoding(ast, [AST.unknownToNull]);
|
|
6848
|
+
}
|
|
6849
|
+
case "Unknown":
|
|
6850
|
+
case "ObjectKeyword":
|
|
6851
|
+
return AST.replaceEncoding(ast, [AST.unknownToJson]);
|
|
6852
|
+
case "Undefined":
|
|
6853
|
+
case "Void":
|
|
6854
|
+
case "Literal":
|
|
6855
|
+
case "Number":
|
|
6856
|
+
return ast.toCodecJson();
|
|
6857
|
+
case "UniqueSymbol":
|
|
6858
|
+
case "Symbol":
|
|
6859
|
+
case "BigInt":
|
|
6860
|
+
return ast.toCodecStringTree();
|
|
6861
|
+
case "Objects":
|
|
6862
|
+
{
|
|
6863
|
+
if (ast.propertySignatures.some(ps => typeof ps.name !== "string")) {
|
|
6864
|
+
throw new globalThis.Error("Objects property names must be strings", {
|
|
6865
|
+
cause: ast
|
|
6866
|
+
});
|
|
6867
|
+
}
|
|
6868
|
+
return ast.recur(recur);
|
|
6869
|
+
}
|
|
6870
|
+
case "Union":
|
|
6871
|
+
{
|
|
6872
|
+
const sortedTypes = InternalSchema.jsonReorder(ast.types);
|
|
6873
|
+
if (sortedTypes !== ast.types) {
|
|
6874
|
+
return new AST.Union(sortedTypes, ast.mode, ast.annotations, ast.checks, ast.encoding, ast.context).recur(recur);
|
|
6875
|
+
}
|
|
6876
|
+
return ast.recur(recur);
|
|
6877
|
+
}
|
|
6878
|
+
case "Arrays":
|
|
6879
|
+
case "Suspend":
|
|
6880
|
+
return ast.recur(recur);
|
|
6881
|
+
}
|
|
6882
|
+
// `Schema.Any` is used as an escape hatch
|
|
6883
|
+
return ast;
|
|
5141
6884
|
}
|
|
5142
6885
|
/**
|
|
5143
|
-
*
|
|
6886
|
+
* Derives an isomorphism codec from a schema. The encoded form is the
|
|
6887
|
+
* schema's `Iso` type — the intermediate representation used for round-tripping.
|
|
6888
|
+
*
|
|
6889
|
+
* @category Canonical Codecs
|
|
5144
6890
|
* @since 4.0.0
|
|
5145
6891
|
*/
|
|
5146
6892
|
export function toCodecIso(schema) {
|
|
5147
|
-
return make(
|
|
6893
|
+
return make(toCodecIsoTop(AST.toType(schema.ast)));
|
|
5148
6894
|
}
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
6895
|
+
const toCodecIsoTop = /*#__PURE__*/memoize(ast => {
|
|
6896
|
+
const out = toCodecIsoBase(ast, toCodecIsoTop);
|
|
6897
|
+
return out !== ast && AST.isOptional(ast) ? AST.optionalKeyLastLink(out) : out;
|
|
6898
|
+
});
|
|
6899
|
+
function toCodecIsoBase(ast, recur) {
|
|
6900
|
+
switch (ast._tag) {
|
|
6901
|
+
case "Declaration":
|
|
6902
|
+
{
|
|
6903
|
+
const getLink = ast.annotations?.toCodecIso ?? ast.annotations?.toCodec;
|
|
6904
|
+
if (Predicate.isFunction(getLink)) {
|
|
6905
|
+
const link = getLink(ast.typeParameters.map(tp => InternalSchema.make(tp)));
|
|
6906
|
+
const to = recur(link.to);
|
|
6907
|
+
return AST.replaceEncoding(ast, to === link.to ? [link] : [new AST.Link(to, link.transformation)]);
|
|
6908
|
+
}
|
|
6909
|
+
return ast;
|
|
6910
|
+
}
|
|
6911
|
+
case "Arrays":
|
|
6912
|
+
case "Objects":
|
|
6913
|
+
case "Union":
|
|
6914
|
+
case "Suspend":
|
|
6915
|
+
return ast.recur(recur);
|
|
5154
6916
|
}
|
|
6917
|
+
return ast;
|
|
6918
|
+
}
|
|
6919
|
+
export function toCodecStringTree(schema, options) {
|
|
6920
|
+
return make(toCodecEnsureArray(options?.keepDeclarations === true ? serializerStringTreeKeepDeclarations(schema.ast) : serializerStringTree(schema.ast)));
|
|
5155
6921
|
}
|
|
5156
6922
|
/**
|
|
5157
|
-
*
|
|
6923
|
+
* Derives an XML encoder from a codec. Encodes a value to an XML string by
|
|
6924
|
+
* first converting it through {@link toCodecStringTree}, then serializing the
|
|
6925
|
+
* resulting tree to XML.
|
|
6926
|
+
*
|
|
6927
|
+
* @category Canonical Codecs
|
|
5158
6928
|
* @since 4.0.0
|
|
5159
6929
|
*/
|
|
5160
6930
|
export function toEncoderXml(codec, options) {
|
|
@@ -5267,11 +7037,9 @@ function getStringTreePriority(ast) {
|
|
|
5267
7037
|
return 1;
|
|
5268
7038
|
}
|
|
5269
7039
|
}
|
|
5270
|
-
const treeReorder = /*#__PURE__*/
|
|
7040
|
+
const treeReorder = /*#__PURE__*/InternalSchema.makeReorder(getStringTreePriority);
|
|
5271
7041
|
function serializerTree(ast, recur, onMissingAnnotation) {
|
|
5272
7042
|
switch (ast._tag) {
|
|
5273
|
-
case "Unknown":
|
|
5274
|
-
case "ObjectKeyword":
|
|
5275
7043
|
case "Declaration":
|
|
5276
7044
|
{
|
|
5277
7045
|
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec;
|
|
@@ -5287,6 +7055,9 @@ function serializerTree(ast, recur, onMissingAnnotation) {
|
|
|
5287
7055
|
return AST.replaceEncoding(ast, [nullToString]);
|
|
5288
7056
|
case "Boolean":
|
|
5289
7057
|
return AST.replaceEncoding(ast, [booleanToString]);
|
|
7058
|
+
case "Unknown":
|
|
7059
|
+
case "ObjectKeyword":
|
|
7060
|
+
return AST.replaceEncoding(ast, [AST.unknownToStringTree]);
|
|
5290
7061
|
case "Enum":
|
|
5291
7062
|
case "Number":
|
|
5292
7063
|
case "Literal":
|
|
@@ -5365,6 +7136,9 @@ function onSerializerEnsureArray(ast) {
|
|
|
5365
7136
|
// Optic APIs
|
|
5366
7137
|
// -----------------------------------------------------------------------------
|
|
5367
7138
|
/**
|
|
7139
|
+
* Derives an `Iso` optic from a schema that isomorphically converts between
|
|
7140
|
+
* the schema's `Type` and its `Iso` (intermediate / serialized form).
|
|
7141
|
+
*
|
|
5368
7142
|
* @category Optic
|
|
5369
7143
|
* @since 4.0.0
|
|
5370
7144
|
*/
|
|
@@ -5373,6 +7147,8 @@ export function toIso(schema) {
|
|
|
5373
7147
|
return Optic_.makeIso(Parser.encodeSync(serializer), Parser.decodeSync(serializer));
|
|
5374
7148
|
}
|
|
5375
7149
|
/**
|
|
7150
|
+
* Returns an identity `Iso` over the schema's source (`Type`) side.
|
|
7151
|
+
*
|
|
5376
7152
|
* @category Optic
|
|
5377
7153
|
* @since 4.0.0
|
|
5378
7154
|
*/
|
|
@@ -5380,6 +7156,8 @@ export function toIsoSource(_) {
|
|
|
5380
7156
|
return Optic_.id();
|
|
5381
7157
|
}
|
|
5382
7158
|
/**
|
|
7159
|
+
* Returns an identity `Iso` over the schema's focus (`Iso`) side.
|
|
7160
|
+
*
|
|
5383
7161
|
* @category Optic
|
|
5384
7162
|
* @since 4.0.0
|
|
5385
7163
|
*/
|
|
@@ -5387,10 +7165,11 @@ export function toIsoFocus(_) {
|
|
|
5387
7165
|
return Optic_.id();
|
|
5388
7166
|
}
|
|
5389
7167
|
/**
|
|
5390
|
-
*
|
|
5391
|
-
*
|
|
5392
|
-
*
|
|
5393
|
-
* the
|
|
7168
|
+
* Overrides the ISO codec derivation for a schema by providing a target codec
|
|
7169
|
+
* and explicit `decode`/`encode` getters. The resulting schema carries a
|
|
7170
|
+
* custom `Iso` type, which changes the schema's type parameter — use
|
|
7171
|
+
* {@link overrideToCodecIso} when the default ISO transformation is not
|
|
7172
|
+
* appropriate.
|
|
5394
7173
|
*
|
|
5395
7174
|
* @category Optic
|
|
5396
7175
|
* @since 4.0.0
|
|
@@ -5408,11 +7187,15 @@ export function overrideToCodecIso(to, transformation) {
|
|
|
5408
7187
|
// Differ APIs
|
|
5409
7188
|
// -----------------------------------------------------------------------------
|
|
5410
7189
|
/**
|
|
7190
|
+
* Derives a JSON Patch differ from a codec. Serializes values to JSON (via
|
|
7191
|
+
* {@link toCodecJson}), computes RFC 6902 JSON Patch operations between old
|
|
7192
|
+
* and new values, and can apply patches back to the typed value.
|
|
7193
|
+
*
|
|
5411
7194
|
* @category JsonPatch
|
|
5412
7195
|
* @since 4.0.0
|
|
5413
7196
|
*/
|
|
5414
7197
|
export function toDifferJsonPatch(schema) {
|
|
5415
|
-
const serializer = toCodecJson(schema);
|
|
7198
|
+
const serializer = toCodecJson(schema);
|
|
5416
7199
|
const get = Parser.encodeSync(serializer);
|
|
5417
7200
|
const set = Parser.decodeSync(serializer);
|
|
5418
7201
|
return {
|
|
@@ -5427,43 +7210,66 @@ export function toDifferJsonPatch(schema) {
|
|
|
5427
7210
|
};
|
|
5428
7211
|
}
|
|
5429
7212
|
/**
|
|
7213
|
+
* Creates a recursive schema for a {@link Tree} of values described by `node`.
|
|
7214
|
+
* The resulting schema accepts a single node value, an array of trees, or an
|
|
7215
|
+
* object whose values are trees.
|
|
7216
|
+
*
|
|
5430
7217
|
* @category Tree
|
|
5431
7218
|
* @since 4.0.0
|
|
5432
7219
|
*/
|
|
5433
7220
|
export function Tree(node) {
|
|
5434
7221
|
const Tree$ref = suspend(() => Tree);
|
|
5435
|
-
const Tree = Union([node,
|
|
7222
|
+
const Tree = Union([node, ArraySchema(Tree$ref), Record(String, Tree$ref)]);
|
|
5436
7223
|
return Tree;
|
|
5437
7224
|
}
|
|
5438
7225
|
/**
|
|
5439
|
-
*
|
|
5440
|
-
*
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
}
|
|
5447
|
-
|
|
7226
|
+
* Schema that accepts and validates any immutable JSON-compatible value.
|
|
7227
|
+
*
|
|
7228
|
+
* **Example** (Validating a JSON value)
|
|
7229
|
+
*
|
|
7230
|
+
* ```ts
|
|
7231
|
+
* import { Schema } from "effect"
|
|
7232
|
+
*
|
|
7233
|
+
* const result = Schema.decodeUnknownOption(Schema.Json)({ key: [1, true, null] })
|
|
7234
|
+
* console.log(result._tag) // "Some"
|
|
7235
|
+
* ```
|
|
7236
|
+
*
|
|
5448
7237
|
* @category JSON
|
|
5449
7238
|
* @since 4.0.0
|
|
5450
7239
|
*/
|
|
5451
|
-
export const Json = /*#__PURE__*/
|
|
7240
|
+
export const Json = /*#__PURE__*/make(AST.Json);
|
|
5452
7241
|
/**
|
|
7242
|
+
* Schema that accepts any mutable JSON-compatible value. See {@link Json} for
|
|
7243
|
+
* the immutable variant.
|
|
7244
|
+
*
|
|
5453
7245
|
* @category JSON
|
|
5454
7246
|
* @since 4.0.0
|
|
5455
7247
|
*/
|
|
5456
|
-
export const MutableJson = /*#__PURE__*/
|
|
7248
|
+
export const MutableJson = /*#__PURE__*/make(AST.MutableJson);
|
|
5457
7249
|
// -----------------------------------------------------------------------------
|
|
5458
7250
|
// Annotations
|
|
5459
7251
|
// -----------------------------------------------------------------------------
|
|
5460
7252
|
/**
|
|
5461
|
-
*
|
|
7253
|
+
* Resolves the typed annotations from a schema. The term "resolve" (rather
|
|
7254
|
+
* than "get") reflects the lookup strategy: if the schema has checks, the
|
|
7255
|
+
* annotations are taken from the last check; otherwise they are taken from
|
|
7256
|
+
* the base schema instance.
|
|
5462
7257
|
*
|
|
5463
7258
|
* @category Schema Resolvers
|
|
5464
7259
|
* @since 4.0.0
|
|
5465
7260
|
*/
|
|
5466
|
-
export function
|
|
7261
|
+
export function resolveAnnotations(schema) {
|
|
5467
7262
|
return InternalAnnotations.resolve(schema.ast);
|
|
5468
7263
|
}
|
|
7264
|
+
/**
|
|
7265
|
+
* Resolves the context (key-level) annotations from a schema. Context
|
|
7266
|
+
* annotations are those attached via `annotateKey` and live on the AST's
|
|
7267
|
+
* `context` rather than on the schema node itself.
|
|
7268
|
+
*
|
|
7269
|
+
* @category Schema Resolvers
|
|
7270
|
+
* @since 4.0.0
|
|
7271
|
+
*/
|
|
7272
|
+
export function resolveAnnotationsKey(schema) {
|
|
7273
|
+
return schema.ast.context?.annotations;
|
|
7274
|
+
}
|
|
5469
7275
|
//# sourceMappingURL=Schema.js.map
|