effect 4.0.0-beta.82 → 4.0.0-beta.84

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.
Files changed (199) hide show
  1. package/dist/Array.d.ts +64 -64
  2. package/dist/Array.js +26 -26
  3. package/dist/Cache.d.ts +1 -1
  4. package/dist/Cache.js +1 -1
  5. package/dist/Cause.d.ts +68 -68
  6. package/dist/Cause.js +47 -47
  7. package/dist/Channel.d.ts +5 -5
  8. package/dist/Channel.js +3 -3
  9. package/dist/Clock.d.ts +1 -1
  10. package/dist/Clock.js +1 -1
  11. package/dist/Combiner.d.ts +9 -9
  12. package/dist/Combiner.js +8 -8
  13. package/dist/Config.d.ts +15 -94
  14. package/dist/Config.d.ts.map +1 -1
  15. package/dist/Config.js +22 -70
  16. package/dist/Config.js.map +1 -1
  17. package/dist/ConfigProvider.d.ts +58 -74
  18. package/dist/ConfigProvider.d.ts.map +1 -1
  19. package/dist/ConfigProvider.js +66 -41
  20. package/dist/ConfigProvider.js.map +1 -1
  21. package/dist/Console.d.ts +1 -1
  22. package/dist/Console.js +1 -1
  23. package/dist/Data.d.ts +15 -15
  24. package/dist/Data.js +3 -3
  25. package/dist/DateTime.d.ts +6 -6
  26. package/dist/DateTime.js +2 -2
  27. package/dist/Duration.d.ts +3 -3
  28. package/dist/Duration.js +3 -3
  29. package/dist/Effect.d.ts +84 -45
  30. package/dist/Effect.d.ts.map +1 -1
  31. package/dist/Effect.js +72 -33
  32. package/dist/Effect.js.map +1 -1
  33. package/dist/Equal.d.ts +7 -7
  34. package/dist/Equal.js +5 -5
  35. package/dist/Equivalence.d.ts +17 -17
  36. package/dist/Equivalence.js +13 -13
  37. package/dist/Exit.d.ts +3 -3
  38. package/dist/Exit.js +3 -3
  39. package/dist/Formatter.d.ts +5 -5
  40. package/dist/Formatter.js +4 -4
  41. package/dist/Function.d.ts +10 -10
  42. package/dist/Function.js +3 -3
  43. package/dist/HashMap.d.ts +3 -3
  44. package/dist/HashMap.js +1 -1
  45. package/dist/Iterable.d.ts +6 -6
  46. package/dist/Iterable.js +2 -2
  47. package/dist/JsonPatch.d.ts +2 -2
  48. package/dist/Layer.d.ts +1 -1
  49. package/dist/Layer.js +1 -1
  50. package/dist/Logger.d.ts +1 -1
  51. package/dist/Logger.js +1 -1
  52. package/dist/Match.d.ts +8 -8
  53. package/dist/Match.js +8 -8
  54. package/dist/Metric.d.ts +3 -3
  55. package/dist/Metric.js +3 -3
  56. package/dist/Optic.d.ts +30 -30
  57. package/dist/Optic.js +12 -12
  58. package/dist/Option.d.ts +7 -7
  59. package/dist/Option.js +7 -7
  60. package/dist/Order.d.ts +23 -23
  61. package/dist/Order.js +20 -20
  62. package/dist/Pool.d.ts +1 -1
  63. package/dist/Pool.js +1 -1
  64. package/dist/Predicate.d.ts +88 -88
  65. package/dist/Predicate.js +47 -47
  66. package/dist/PubSub.d.ts +3 -3
  67. package/dist/PubSub.js +3 -3
  68. package/dist/Reducer.d.ts +1 -1
  69. package/dist/Reducer.js +1 -1
  70. package/dist/Result.d.ts +18 -18
  71. package/dist/Result.js +8 -8
  72. package/dist/Runtime.d.ts +1 -1
  73. package/dist/Runtime.js +1 -1
  74. package/dist/Schema.d.ts +265 -120
  75. package/dist/Schema.d.ts.map +1 -1
  76. package/dist/Schema.js +285 -116
  77. package/dist/Schema.js.map +1 -1
  78. package/dist/SchemaAST.d.ts +1 -1
  79. package/dist/SchemaAST.d.ts.map +1 -1
  80. package/dist/SchemaAST.js +13 -9
  81. package/dist/SchemaAST.js.map +1 -1
  82. package/dist/SchemaGetter.d.ts +48 -48
  83. package/dist/SchemaGetter.js +44 -44
  84. package/dist/SchemaIssue.d.ts +3 -3
  85. package/dist/SchemaIssue.js +3 -3
  86. package/dist/SchemaParser.d.ts +122 -22
  87. package/dist/SchemaParser.d.ts.map +1 -1
  88. package/dist/SchemaParser.js +186 -50
  89. package/dist/SchemaParser.js.map +1 -1
  90. package/dist/SchemaRepresentation.d.ts +1 -1
  91. package/dist/SchemaRepresentation.d.ts.map +1 -1
  92. package/dist/SchemaRepresentation.js +96 -2
  93. package/dist/SchemaRepresentation.js.map +1 -1
  94. package/dist/SchemaTransformation.d.ts +20 -20
  95. package/dist/SchemaTransformation.js +18 -18
  96. package/dist/Stream.d.ts +3 -3
  97. package/dist/Stream.js +2 -2
  98. package/dist/Stream.js.map +1 -1
  99. package/dist/String.d.ts +1 -1
  100. package/dist/String.js +1 -1
  101. package/dist/Struct.d.ts +1 -1
  102. package/dist/Struct.js +1 -1
  103. package/dist/Types.d.ts +13 -13
  104. package/dist/internal/effect.js +23 -10
  105. package/dist/internal/effect.js.map +1 -1
  106. package/dist/internal/schema/cause.d.ts +2 -0
  107. package/dist/internal/schema/cause.d.ts.map +1 -0
  108. package/dist/internal/schema/cause.js +24 -0
  109. package/dist/internal/schema/cause.js.map +1 -0
  110. package/dist/internal/schema/schema.d.ts +8 -4
  111. package/dist/internal/schema/schema.d.ts.map +1 -1
  112. package/dist/internal/schema/schema.js +21 -8
  113. package/dist/internal/schema/schema.js.map +1 -1
  114. package/dist/testing/TestSchema.d.ts +3 -3
  115. package/dist/testing/TestSchema.js +1 -1
  116. package/dist/unstable/ai/AiError.d.ts +1 -1
  117. package/dist/unstable/ai/AiError.js +1 -1
  118. package/dist/unstable/ai/Chat.d.ts +1 -1
  119. package/dist/unstable/ai/Chat.js +1 -1
  120. package/dist/unstable/cli/Prompt.js +2 -2
  121. package/dist/unstable/cli/Prompt.js.map +1 -1
  122. package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
  123. package/dist/unstable/httpapi/HttpApiSchema.d.ts +39 -0
  124. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  125. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  126. package/dist/unstable/rpc/Rpc.d.ts +1 -1
  127. package/dist/unstable/rpc/Rpc.js +1 -1
  128. package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
  129. package/dist/unstable/rpc/RpcGroup.js +3 -4
  130. package/dist/unstable/rpc/RpcGroup.js.map +1 -1
  131. package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
  132. package/dist/unstable/sql/SqlResolver.js +15 -2
  133. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  134. package/dist/unstable/workflow/Activity.d.ts +1 -0
  135. package/dist/unstable/workflow/Activity.d.ts.map +1 -1
  136. package/dist/unstable/workflow/Activity.js +1 -0
  137. package/dist/unstable/workflow/Activity.js.map +1 -1
  138. package/dist/unstable/workflow/WorkflowEngine.js +1 -1
  139. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  140. package/package.json +1 -1
  141. package/src/Array.ts +65 -65
  142. package/src/Cache.ts +1 -1
  143. package/src/Cause.ts +68 -68
  144. package/src/Channel.ts +5 -5
  145. package/src/Clock.ts +1 -1
  146. package/src/Combiner.ts +9 -9
  147. package/src/Config.ts +40 -108
  148. package/src/ConfigProvider.ts +139 -100
  149. package/src/Console.ts +1 -1
  150. package/src/Data.ts +15 -15
  151. package/src/DateTime.ts +6 -6
  152. package/src/Duration.ts +3 -3
  153. package/src/Effect.ts +89 -45
  154. package/src/Equal.ts +7 -7
  155. package/src/Equivalence.ts +17 -17
  156. package/src/Exit.ts +3 -3
  157. package/src/Formatter.ts +5 -5
  158. package/src/Function.ts +10 -10
  159. package/src/HashMap.ts +3 -3
  160. package/src/Iterable.ts +6 -6
  161. package/src/JsonPatch.ts +2 -2
  162. package/src/Layer.ts +1 -1
  163. package/src/Logger.ts +1 -1
  164. package/src/Match.ts +8 -8
  165. package/src/Metric.ts +3 -3
  166. package/src/Optic.ts +30 -30
  167. package/src/Option.ts +7 -7
  168. package/src/Order.ts +23 -23
  169. package/src/Pool.ts +1 -1
  170. package/src/Predicate.ts +88 -88
  171. package/src/PubSub.ts +3 -3
  172. package/src/Reducer.ts +1 -1
  173. package/src/Result.ts +20 -20
  174. package/src/Runtime.ts +1 -1
  175. package/src/Schema.ts +314 -131
  176. package/src/SchemaAST.ts +20 -11
  177. package/src/SchemaGetter.ts +48 -48
  178. package/src/SchemaIssue.ts +3 -3
  179. package/src/SchemaParser.ts +197 -58
  180. package/src/SchemaRepresentation.ts +73 -3
  181. package/src/SchemaTransformation.ts +20 -20
  182. package/src/Stream.ts +4 -4
  183. package/src/String.ts +1 -1
  184. package/src/Struct.ts +1 -1
  185. package/src/Types.ts +13 -13
  186. package/src/internal/effect.ts +29 -10
  187. package/src/internal/schema/cause.ts +26 -0
  188. package/src/internal/schema/schema.ts +36 -10
  189. package/src/testing/TestSchema.ts +3 -3
  190. package/src/unstable/ai/AiError.ts +1 -1
  191. package/src/unstable/ai/Chat.ts +1 -1
  192. package/src/unstable/cli/Prompt.ts +1 -1
  193. package/src/unstable/httpapi/HttpApiScalar.ts +2 -2
  194. package/src/unstable/httpapi/HttpApiSchema.ts +18 -6
  195. package/src/unstable/rpc/Rpc.ts +1 -1
  196. package/src/unstable/rpc/RpcGroup.ts +3 -4
  197. package/src/unstable/sql/SqlResolver.ts +15 -2
  198. package/src/unstable/workflow/Activity.ts +2 -0
  199. package/src/unstable/workflow/WorkflowEngine.ts +1 -1
package/dist/Schema.js CHANGED
@@ -123,7 +123,7 @@ export function declareConstructor() {
123
123
  * Use when you are defining a schema for an opaque type with no type parameters
124
124
  * and validation can be expressed as a type guard.
125
125
  *
126
- * **Example** (Schema for a custom `UserId` branded type)
126
+ * **Example** (Defining a schema for a custom `UserId` branded type)
127
127
  *
128
128
  * ```ts
129
129
  * import { Schema } from "effect"
@@ -255,7 +255,7 @@ export function annotateEncoded(annotations) {
255
255
  * as well as standard documentation fields such as `title`, `description`,
256
256
  * and `examples`.
257
257
  *
258
- * **Example** (Custom missing-key message for a required field)
258
+ * **Example** (Customizing the missing-key message for a required field)
259
259
  *
260
260
  * ```ts
261
261
  * import { Schema } from "effect"
@@ -342,7 +342,7 @@ SchemaError };
342
342
  /**
343
343
  * Returns `true` if `u` is a {@link SchemaError}.
344
344
  *
345
- * **Example** (Type guard in a catch block)
345
+ * **Example** (Narrowing Schema errors in a catch block)
346
346
  *
347
347
  * ```ts
348
348
  * import { Schema } from "effect"
@@ -538,10 +538,16 @@ export function toStandardJSONSchemaV1(self) {
538
538
  * **Details**
539
539
  *
540
540
  * This function returns a predicate that performs a type-safe check, narrowing
541
- * the type of the input value if the check passes. It's particularly useful for
542
- * runtime type validation and TypeScript type narrowing.
541
+ * the type of the input value if the check passes. The predicate returns `false`
542
+ * for schema mismatches.
543
543
  *
544
- * **Example** (Basic Type Guard)
544
+ * **Gotchas**
545
+ *
546
+ * Only causes made entirely of schema issues are converted to `false`. Causes
547
+ * that contain defects, interruptions, or other non-schema reasons throw
548
+ * instead.
549
+ *
550
+ * **Example** (Defining a basic type guard)
545
551
  *
546
552
  * ```ts
547
553
  * import { Schema } from "effect"
@@ -564,7 +570,7 @@ export function toStandardJSONSchemaV1(self) {
564
570
  */
565
571
  export const is = SchemaParser.is;
566
572
  /**
567
- * Creates an assertion function that throws an error if the input doesn't match
573
+ * Creates an assertion function that throws an error if the input does not match
568
574
  * the schema.
569
575
  *
570
576
  * **When to use**
@@ -574,10 +580,16 @@ export const is = SchemaParser.is;
574
580
  *
575
581
  * **Details**
576
582
  *
577
- * The input is narrowed if the assertion succeeds. If validation fails, the
578
- * assertion throws.
583
+ * The input is narrowed if the assertion succeeds. If schema validation fails,
584
+ * the assertion throws an `Error` whose cause is `SchemaIssue.Issue`.
585
+ *
586
+ * **Gotchas**
587
+ *
588
+ * Causes that contain defects, interruptions, or other non-schema reasons throw
589
+ * with the underlying `Cause` attached instead of being converted to schema
590
+ * validation errors.
579
591
  *
580
- * **Example** (Basic Usage)
592
+ * **Example** (Asserting and narrowing an input)
581
593
  *
582
594
  * ```ts
583
595
  * import { Schema } from "effect"
@@ -625,7 +637,7 @@ export const asserts = SchemaParser.asserts;
625
637
  export function decodeUnknownEffect(schema, options) {
626
638
  const parser = SchemaParser.decodeUnknownEffect(schema, options);
627
639
  return (input, options) => {
628
- return Effect.mapErrorEager(parser(input, options), issue => new SchemaError(issue));
640
+ return InternalSchema.mapSchemaIssueEffect(parser(input, options));
629
641
  };
630
642
  }
631
643
  /**
@@ -650,15 +662,46 @@ export function decodeUnknownEffect(schema, options) {
650
662
  * @since 4.0.0
651
663
  */
652
664
  export const decodeEffect = decodeUnknownEffect;
665
+ function getSchemaErrorOrThrow(cause, message) {
666
+ let schemaError;
667
+ for (const reason of cause.reasons) {
668
+ if (!Cause_.isFailReason(reason) || !isSchemaError(reason.error)) {
669
+ throw new globalThis.Error(message, {
670
+ cause
671
+ });
672
+ }
673
+ schemaError ??= reason.error;
674
+ }
675
+ if (schemaError === undefined) {
676
+ throw new globalThis.Error(message, {
677
+ cause
678
+ });
679
+ }
680
+ return schemaError;
681
+ }
682
+ function runSchemaErrorPromise(self) {
683
+ return Effect.runPromiseExit(self).then(exit => {
684
+ if (Exit_.isSuccess(exit)) {
685
+ return exit.value;
686
+ }
687
+ throw getSchemaErrorOrThrow(exit.cause, "Promise adapter can only reject schema errors");
688
+ });
689
+ }
690
+ function runSchemaErrorSync(self) {
691
+ const exit = Effect.runSyncExit(self);
692
+ if (Exit_.isSuccess(exit)) {
693
+ return exit.value;
694
+ }
695
+ throw getSchemaErrorOrThrow(exit.cause, "Sync adapter can only throw schema errors");
696
+ }
653
697
  /**
654
698
  * Decodes an `unknown` input against a schema synchronously, returning an
655
- * `Exit` that is either a `Success` with the decoded value or a `Failure` with
656
- * a {@link SchemaError}.
699
+ * `Exit` that is either a `Success` with the decoded value or a `Failure`.
657
700
  *
658
701
  * **When to use**
659
702
  *
660
- * Use when you need to decode unknown input into an `Exit` whose failure
661
- * contains `SchemaError`.
703
+ * Use when you need to decode unknown input into an `Exit` and capture schema
704
+ * mismatches as `SchemaError`.
662
705
  *
663
706
  * **Details**
664
707
  *
@@ -667,6 +710,14 @@ export const decodeEffect = decodeUnknownEffect;
667
710
  * type.
668
711
  * Options may be provided either when creating the decoder or when applying it;
669
712
  * application options override creation options.
713
+ * Schema mismatches are represented by a `Failure` cause containing
714
+ * `SchemaError`.
715
+ *
716
+ * **Gotchas**
717
+ *
718
+ * Schema issue fail reasons are wrapped as `SchemaError`. Defects,
719
+ * interruptions, and other non-schema reasons remain in the returned `Cause`,
720
+ * including when they are mixed with schema issues.
670
721
  *
671
722
  * @see {@link SchemaParser.decodeUnknownExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
672
723
  *
@@ -676,18 +727,18 @@ export const decodeEffect = decodeUnknownEffect;
676
727
  export function decodeUnknownExit(schema, options) {
677
728
  const parser = SchemaParser.decodeUnknownExit(schema, options);
678
729
  return (input, options) => {
679
- return Exit_.mapError(parser(input, options), issue => new SchemaError(issue));
730
+ return InternalSchema.mapSchemaIssueExit(parser(input, options));
680
731
  };
681
732
  }
682
733
  /**
683
734
  * Decodes a typed input (the schema's `Encoded` type) against a schema
684
- * synchronously, returning an `Exit` that is either a `Success` with the
685
- * decoded value or a `Failure` with a {@link SchemaError}.
735
+ * synchronously, returning an `Exit` that is either a `Success` with the decoded
736
+ * value or a `Failure`.
686
737
  *
687
738
  * **When to use**
688
739
  *
689
- * Use when you need to decode already typed `Encoded` input into an `Exit`
690
- * whose failure contains `SchemaError`.
740
+ * Use when you need to decode already typed `Encoded` input into an `Exit` and
741
+ * capture schema mismatches as `SchemaError`.
691
742
  *
692
743
  * **Details**
693
744
  *
@@ -695,6 +746,14 @@ export function decodeUnknownExit(schema, options) {
695
746
  * `unknown` input use {@link decodeUnknownExit}.
696
747
  * Options may be provided either when creating the decoder or when applying it;
697
748
  * application options override creation options.
749
+ * Schema mismatches are represented by a `Failure` cause containing
750
+ * `SchemaError`.
751
+ *
752
+ * **Gotchas**
753
+ *
754
+ * Schema issue fail reasons are wrapped as `SchemaError`. Defects,
755
+ * interruptions, and other non-schema reasons remain in the returned `Cause`,
756
+ * including when they are mixed with schema issues.
698
757
  *
699
758
  * @see {@link SchemaParser.decodeExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
700
759
  *
@@ -704,7 +763,7 @@ export function decodeUnknownExit(schema, options) {
704
763
  export const decodeExit = decodeUnknownExit;
705
764
  /**
706
765
  * Decodes an `unknown` input against a schema, returning an `Option` that is
707
- * `Some` with the decoded value on success or `None` on failure.
766
+ * `Some` with the decoded value on success or `None` for schema mismatches.
708
767
  *
709
768
  * **When to use**
710
769
  *
@@ -719,6 +778,12 @@ export const decodeExit = decodeUnknownExit;
719
778
  * Options may be provided either when creating the decoder or when applying it;
720
779
  * application options override creation options.
721
780
  *
781
+ * **Gotchas**
782
+ *
783
+ * Only causes made entirely of schema issues are converted to `None`. Causes
784
+ * that contain defects, interruptions, or other non-schema reasons throw
785
+ * instead.
786
+ *
722
787
  * @category decoding
723
788
  * @since 3.10.0
724
789
  */
@@ -726,7 +791,7 @@ export const decodeUnknownOption = SchemaParser.decodeUnknownOption;
726
791
  /**
727
792
  * Decodes a typed input (the schema's `Encoded` type) against a schema,
728
793
  * returning an `Option` that is `Some` with the decoded value on success or
729
- * `None` on failure.
794
+ * `None` for schema mismatches.
730
795
  *
731
796
  * **When to use**
732
797
  *
@@ -739,18 +804,25 @@ export const decodeUnknownOption = SchemaParser.decodeUnknownOption;
739
804
  * Options may be provided either when creating the decoder or when applying it;
740
805
  * application options override creation options.
741
806
  *
807
+ * **Gotchas**
808
+ *
809
+ * Only causes made entirely of schema issues are converted to `None`. Causes
810
+ * that contain defects, interruptions, or other non-schema reasons throw
811
+ * instead.
812
+ *
742
813
  * @category decoding
743
814
  * @since 3.10.0
744
815
  */
745
816
  export const decodeOption = decodeUnknownOption;
746
817
  /**
747
818
  * Decodes an `unknown` input against a schema, returning a `Result` that
748
- * succeeds with the decoded value or fails with a {@link SchemaError}.
819
+ * succeeds with the decoded value or fails with a {@link SchemaError} for schema
820
+ * mismatches.
749
821
  *
750
822
  * **When to use**
751
823
  *
752
- * Use when you do not know the input type statically and want decoding to
753
- * return a `Result` with `SchemaError` failure data.
824
+ * Use when you do not know the input type statically and want schema mismatches
825
+ * returned as `Result.fail` with `SchemaError`.
754
826
  *
755
827
  * **Details**
756
828
  *
@@ -758,6 +830,13 @@ export const decodeOption = decodeUnknownOption;
758
830
  * {@link decodeResult}.
759
831
  * Options may be provided either when creating the decoder or when applying it;
760
832
  * application options override creation options.
833
+ * Schema mismatches are returned as `Result.fail` with `SchemaError`.
834
+ *
835
+ * **Gotchas**
836
+ *
837
+ * Only causes made entirely of schema issues are returned as `Result.fail`.
838
+ * Causes that contain defects, interruptions, or other non-schema reasons throw
839
+ * instead.
761
840
  *
762
841
  * @see {@link SchemaParser.decodeUnknownResult} for the adapter that fails with `SchemaIssue.Issue` directly
763
842
  *
@@ -773,18 +852,25 @@ export function decodeUnknownResult(schema, options) {
773
852
  /**
774
853
  * Decodes a typed input (the schema's `Encoded` type) against a schema,
775
854
  * returning a `Result` that succeeds with the decoded value or fails with a
776
- * {@link SchemaError}.
855
+ * {@link SchemaError} for schema mismatches.
777
856
  *
778
857
  * **When to use**
779
858
  *
780
- * Use when you already have input typed as the schema's `Encoded` type and
781
- * want decoding to return a `Result` with `SchemaError` failure data.
859
+ * Use when you already have input typed as the schema's `Encoded` type and want
860
+ * schema mismatches returned as `Result.fail` with `SchemaError`.
782
861
  *
783
862
  * **Details**
784
863
  *
785
864
  * For `unknown` input use {@link decodeUnknownResult}.
786
865
  * Options may be provided either when creating the decoder or when applying it;
787
866
  * application options override creation options.
867
+ * Schema mismatches are returned as `Result.fail` with `SchemaError`.
868
+ *
869
+ * **Gotchas**
870
+ *
871
+ * Only causes made entirely of schema issues are returned as `Result.fail`.
872
+ * Causes that contain defects, interruptions, or other non-schema reasons throw
873
+ * instead.
788
874
  *
789
875
  * @see {@link SchemaParser.decodeResult} for the adapter that fails with `SchemaIssue.Issue` directly
790
876
  *
@@ -794,12 +880,13 @@ export function decodeUnknownResult(schema, options) {
794
880
  export const decodeResult = decodeUnknownResult;
795
881
  /**
796
882
  * Decodes an `unknown` input against a schema, returning a `Promise` that
797
- * resolves with the decoded value or rejects with a {@link SchemaError}.
883
+ * resolves with the decoded value or rejects with a {@link SchemaError} for
884
+ * schema mismatches.
798
885
  *
799
886
  * **When to use**
800
887
  *
801
888
  * Use when you need decoding of unknown input to return a JavaScript `Promise`
802
- * that rejects with `SchemaError`.
889
+ * that rejects with `SchemaError` for schema mismatches.
803
890
  *
804
891
  * **Details**
805
892
  *
@@ -808,7 +895,12 @@ export const decodeResult = decodeUnknownResult;
808
895
  * Options may be provided either when creating the decoder or when applying it;
809
896
  * application options override creation options.
810
897
  *
811
- * @see {@link SchemaParser.decodeUnknownPromise} for the adapter that rejects with `SchemaIssue.Issue` directly
898
+ * **Gotchas**
899
+ *
900
+ * Non-schema failures may reject with a runtime failure instead of
901
+ * `SchemaError`.
902
+ *
903
+ * @see {@link SchemaParser.decodeUnknownPromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
812
904
  *
813
905
  * @category decoding
814
906
  * @since 3.10.0
@@ -816,19 +908,19 @@ export const decodeResult = decodeUnknownResult;
816
908
  export function decodeUnknownPromise(schema, options) {
817
909
  const parser = decodeUnknownEffect(schema, options);
818
910
  return (input, options) => {
819
- return Effect.runPromise(parser(input, options));
911
+ return runSchemaErrorPromise(parser(input, options));
820
912
  };
821
913
  }
822
914
  /**
823
915
  * Decodes a typed input (the schema's `Encoded` type) against a schema,
824
916
  * returning a `Promise` that resolves with the decoded value or rejects with a
825
- * {@link SchemaError}.
917
+ * {@link SchemaError} for schema mismatches.
826
918
  *
827
919
  * **When to use**
828
920
  *
829
921
  * Use when you already have input typed as the schema's `Encoded` type and
830
922
  * need decoding to return a JavaScript `Promise` that rejects with
831
- * `SchemaError`.
923
+ * `SchemaError` for schema mismatches.
832
924
  *
833
925
  * **Details**
834
926
  *
@@ -836,7 +928,12 @@ export function decodeUnknownPromise(schema, options) {
836
928
  * Options may be provided either when creating the decoder or when applying it;
837
929
  * application options override creation options.
838
930
  *
839
- * @see {@link SchemaParser.decodePromise} for the adapter that rejects with `SchemaIssue.Issue` directly
931
+ * **Gotchas**
932
+ *
933
+ * Non-schema failures may reject with a runtime failure instead of
934
+ * `SchemaError`.
935
+ *
936
+ * @see {@link SchemaParser.decodePromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
840
937
  *
841
938
  * @category decoding
842
939
  * @since 3.10.0
@@ -844,7 +941,7 @@ export function decodeUnknownPromise(schema, options) {
844
941
  export const decodePromise = decodeUnknownPromise;
845
942
  /**
846
943
  * Decodes an `unknown` input against a schema synchronously, returning the
847
- * decoded value or throwing a {@link SchemaError}.
944
+ * decoded value or throwing a {@link SchemaError} for schema mismatches.
848
945
  *
849
946
  * **When to use**
850
947
  *
@@ -854,10 +951,15 @@ export const decodePromise = decodeUnknownPromise;
854
951
  * **Details**
855
952
  *
856
953
  * For input already typed as the schema's `Encoded` type use `decodeSync`.
857
- * Only service-free schemas can be decoded synchronously. For non-throwing
858
- * alternatives see `decodeUnknownOption`, `decodeUnknownExit`, or
859
- * `decodeUnknownEffect`. Options may be provided either when creating the
860
- * decoder or when applying it; application options override creation options.
954
+ * Only service-free schemas can be decoded synchronously. For alternatives that
955
+ * do not throw on schema mismatches, see `decodeUnknownOption`,
956
+ * `decodeUnknownExit`, or `decodeUnknownEffect`. Options may be provided either
957
+ * when creating the decoder or when applying it; application options override
958
+ * creation options.
959
+ *
960
+ * **Gotchas**
961
+ *
962
+ * Non-schema failures may throw a runtime failure instead of `SchemaError`.
861
963
  *
862
964
  * **Example** (Decoding with a transformation schema)
863
965
  *
@@ -884,12 +986,13 @@ export const decodePromise = decodeUnknownPromise;
884
986
  export function decodeUnknownSync(schema, options) {
885
987
  const parser = decodeUnknownEffect(schema, options);
886
988
  return (input, options) => {
887
- return Effect.runSync(parser(input, options));
989
+ return runSchemaErrorSync(parser(input, options));
888
990
  };
889
991
  }
890
992
  /**
891
993
  * Decodes a typed input (the schema's `Encoded` type) against a schema
892
- * synchronously, returning the decoded value or throwing a {@link SchemaError}.
994
+ * synchronously, returning the decoded value or throwing a {@link SchemaError}
995
+ * for schema mismatches.
893
996
  *
894
997
  * **When to use**
895
998
  *
@@ -903,6 +1006,10 @@ export function decodeUnknownSync(schema, options) {
903
1006
  * provided either when creating the decoder or when applying it; application
904
1007
  * options override creation options.
905
1008
  *
1009
+ * **Gotchas**
1010
+ *
1011
+ * Non-schema failures may throw a runtime failure instead of `SchemaError`.
1012
+ *
906
1013
  * @see {@link SchemaParser.decodeSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
907
1014
  *
908
1015
  * @category decoding
@@ -944,7 +1051,7 @@ export const decodeSync = decodeUnknownSync;
944
1051
  export function encodeUnknownEffect(schema, options) {
945
1052
  const parser = SchemaParser.encodeUnknownEffect(schema, options);
946
1053
  return (input, options) => {
947
- return Effect.mapErrorEager(parser(input, options), issue => new SchemaError(issue));
1054
+ return InternalSchema.mapSchemaIssueEffect(parser(input, options));
948
1055
  };
949
1056
  }
950
1057
  /**
@@ -971,13 +1078,12 @@ export function encodeUnknownEffect(schema, options) {
971
1078
  export const encodeEffect = encodeUnknownEffect;
972
1079
  /**
973
1080
  * Encodes an `unknown` input against a schema synchronously, returning an
974
- * `Exit` that is either a `Success` with the encoded value or a `Failure` with
975
- * a {@link SchemaError}.
1081
+ * `Exit` that is either a `Success` with the encoded value or a `Failure`.
976
1082
  *
977
1083
  * **When to use**
978
1084
  *
979
- * Use when you need to encode unknown input into an `Exit` whose failure
980
- * contains `SchemaError`.
1085
+ * Use when you need to encode unknown input into an `Exit` and capture schema
1086
+ * mismatches as `SchemaError`.
981
1087
  *
982
1088
  * **Details**
983
1089
  *
@@ -985,6 +1091,14 @@ export const encodeEffect = encodeUnknownEffect;
985
1091
  * {@link encodeExit} when the value is already typed as the schema's `Type`.
986
1092
  * Options may be provided either when creating the encoder or when applying it;
987
1093
  * application options override creation options.
1094
+ * Schema mismatches are represented by a `Failure` cause containing
1095
+ * `SchemaError`.
1096
+ *
1097
+ * **Gotchas**
1098
+ *
1099
+ * Schema issue fail reasons are wrapped as `SchemaError`. Defects,
1100
+ * interruptions, and other non-schema reasons remain in the returned `Cause`,
1101
+ * including when they are mixed with schema issues.
988
1102
  *
989
1103
  * @see {@link SchemaParser.encodeUnknownExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
990
1104
  *
@@ -994,18 +1108,18 @@ export const encodeEffect = encodeUnknownEffect;
994
1108
  export function encodeUnknownExit(schema, options) {
995
1109
  const parser = SchemaParser.encodeUnknownExit(schema, options);
996
1110
  return (input, options) => {
997
- return Exit_.mapError(parser(input, options), issue => new SchemaError(issue));
1111
+ return InternalSchema.mapSchemaIssueExit(parser(input, options));
998
1112
  };
999
1113
  }
1000
1114
  /**
1001
1115
  * Encodes a typed input (the schema's `Type`) against a schema synchronously,
1002
1116
  * returning an `Exit` that is either a `Success` with the encoded value or a
1003
- * `Failure` with a {@link SchemaError}.
1117
+ * `Failure`.
1004
1118
  *
1005
1119
  * **When to use**
1006
1120
  *
1007
- * Use when you need to encode already typed schema values into an `Exit` whose
1008
- * failure contains `SchemaError`.
1121
+ * Use when you need to encode already typed schema values into an `Exit` and
1122
+ * capture schema mismatches as `SchemaError`.
1009
1123
  *
1010
1124
  * **Details**
1011
1125
  *
@@ -1013,6 +1127,14 @@ export function encodeUnknownExit(schema, options) {
1013
1127
  * `unknown` input use {@link encodeUnknownExit}.
1014
1128
  * Options may be provided either when creating the encoder or when applying it;
1015
1129
  * application options override creation options.
1130
+ * Schema mismatches are represented by a `Failure` cause containing
1131
+ * `SchemaError`.
1132
+ *
1133
+ * **Gotchas**
1134
+ *
1135
+ * Schema issue fail reasons are wrapped as `SchemaError`. Defects,
1136
+ * interruptions, and other non-schema reasons remain in the returned `Cause`,
1137
+ * including when they are mixed with schema issues.
1016
1138
  *
1017
1139
  * @see {@link SchemaParser.encodeExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
1018
1140
  *
@@ -1022,7 +1144,7 @@ export function encodeUnknownExit(schema, options) {
1022
1144
  export const encodeExit = encodeUnknownExit;
1023
1145
  /**
1024
1146
  * Encodes an `unknown` input against a schema, returning an `Option` that is
1025
- * `Some` with the encoded value on success or `None` on failure.
1147
+ * `Some` with the encoded value on success or `None` for schema mismatches.
1026
1148
  *
1027
1149
  * **When to use**
1028
1150
  *
@@ -1037,14 +1159,20 @@ export const encodeExit = encodeUnknownExit;
1037
1159
  * Options may be provided either when creating the encoder or when applying it;
1038
1160
  * application options override creation options.
1039
1161
  *
1162
+ * **Gotchas**
1163
+ *
1164
+ * Only causes made entirely of schema issues are converted to `None`. Causes
1165
+ * that contain defects, interruptions, or other non-schema reasons throw
1166
+ * instead.
1167
+ *
1040
1168
  * @category encoding
1041
1169
  * @since 3.10.0
1042
1170
  */
1043
1171
  export const encodeUnknownOption = SchemaParser.encodeUnknownOption;
1044
1172
  /**
1045
1173
  * Encodes a typed input (the schema's `Type`) against a schema, returning an
1046
- * `Option` that is `Some` with the encoded value on success or `None` on
1047
- * failure.
1174
+ * `Option` that is `Some` with the encoded value on success or `None` for schema
1175
+ * mismatches.
1048
1176
  *
1049
1177
  * **When to use**
1050
1178
  *
@@ -1057,24 +1185,38 @@ export const encodeUnknownOption = SchemaParser.encodeUnknownOption;
1057
1185
  * Options may be provided either when creating the encoder or when applying it;
1058
1186
  * application options override creation options.
1059
1187
  *
1188
+ * **Gotchas**
1189
+ *
1190
+ * Only causes made entirely of schema issues are converted to `None`. Causes
1191
+ * that contain defects, interruptions, or other non-schema reasons throw
1192
+ * instead.
1193
+ *
1060
1194
  * @category encoding
1061
1195
  * @since 3.10.0
1062
1196
  */
1063
1197
  export const encodeOption = encodeUnknownOption;
1064
1198
  /**
1065
1199
  * Encodes an `unknown` input against a schema, returning a `Result` that
1066
- * succeeds with the encoded value or fails with a {@link SchemaError}.
1200
+ * succeeds with the encoded value or fails with a {@link SchemaError} for schema
1201
+ * mismatches.
1067
1202
  *
1068
1203
  * **When to use**
1069
1204
  *
1070
- * Use when you do not know the input type statically and want encoding to
1071
- * return a `Result` with `SchemaError` failure data.
1205
+ * Use when you do not know the input type statically and want schema mismatches
1206
+ * returned as `Result.fail` with `SchemaError`.
1072
1207
  *
1073
1208
  * **Details**
1074
1209
  *
1075
1210
  * For values already typed as the schema's `Type` use {@link encodeResult}.
1076
1211
  * Options may be provided either when creating the encoder or when applying it;
1077
1212
  * application options override creation options.
1213
+ * Schema mismatches are returned as `Result.fail` with `SchemaError`.
1214
+ *
1215
+ * **Gotchas**
1216
+ *
1217
+ * Only causes made entirely of schema issues are returned as `Result.fail`.
1218
+ * Causes that contain defects, interruptions, or other non-schema reasons throw
1219
+ * instead.
1078
1220
  *
1079
1221
  * @see {@link SchemaParser.encodeUnknownResult} for the adapter that fails with `SchemaIssue.Issue` directly
1080
1222
  *
@@ -1090,18 +1232,25 @@ export function encodeUnknownResult(schema, options) {
1090
1232
  /**
1091
1233
  * Encodes a typed input (the schema's `Type`) against a schema, returning a
1092
1234
  * `Result` that succeeds with the encoded value or fails with a
1093
- * {@link SchemaError}.
1235
+ * {@link SchemaError} for schema mismatches.
1094
1236
  *
1095
1237
  * **When to use**
1096
1238
  *
1097
- * Use when you already have a value typed as the schema's `Type` and want
1098
- * encoding to return a `Result` with `SchemaError` failure data.
1239
+ * Use when you already have a value typed as the schema's `Type` and want schema
1240
+ * mismatches returned as `Result.fail` with `SchemaError`.
1099
1241
  *
1100
1242
  * **Details**
1101
1243
  *
1102
1244
  * For `unknown` input use {@link encodeUnknownResult}.
1103
1245
  * Options may be provided either when creating the encoder or when applying it;
1104
1246
  * application options override creation options.
1247
+ * Schema mismatches are returned as `Result.fail` with `SchemaError`.
1248
+ *
1249
+ * **Gotchas**
1250
+ *
1251
+ * Only causes made entirely of schema issues are returned as `Result.fail`.
1252
+ * Causes that contain defects, interruptions, or other non-schema reasons throw
1253
+ * instead.
1105
1254
  *
1106
1255
  * @see {@link SchemaParser.encodeResult} for the adapter that fails with `SchemaIssue.Issue` directly
1107
1256
  *
@@ -1111,12 +1260,13 @@ export function encodeUnknownResult(schema, options) {
1111
1260
  export const encodeResult = encodeUnknownResult;
1112
1261
  /**
1113
1262
  * Encodes an `unknown` input against a schema, returning a `Promise` that
1114
- * resolves with the encoded value or rejects with a {@link SchemaError}.
1263
+ * resolves with the encoded value or rejects with a {@link SchemaError} for
1264
+ * schema mismatches.
1115
1265
  *
1116
1266
  * **When to use**
1117
1267
  *
1118
1268
  * Use when you need encoding of unknown input to return a JavaScript `Promise`
1119
- * that rejects with `SchemaError`.
1269
+ * that rejects with `SchemaError` for schema mismatches.
1120
1270
  *
1121
1271
  * **Details**
1122
1272
  *
@@ -1124,7 +1274,12 @@ export const encodeResult = encodeUnknownResult;
1124
1274
  * Options may be provided either when creating the encoder or when applying it;
1125
1275
  * application options override creation options.
1126
1276
  *
1127
- * @see {@link SchemaParser.encodeUnknownPromise} for the adapter that rejects with `SchemaIssue.Issue` directly
1277
+ * **Gotchas**
1278
+ *
1279
+ * Non-schema failures may reject with a runtime failure instead of
1280
+ * `SchemaError`.
1281
+ *
1282
+ * @see {@link SchemaParser.encodeUnknownPromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
1128
1283
  *
1129
1284
  * @category encoding
1130
1285
  * @since 3.10.0
@@ -1132,18 +1287,19 @@ export const encodeResult = encodeUnknownResult;
1132
1287
  export function encodeUnknownPromise(schema, options) {
1133
1288
  const parser = encodeUnknownEffect(schema, options);
1134
1289
  return (input, options) => {
1135
- return Effect.runPromise(parser(input, options));
1290
+ return runSchemaErrorPromise(parser(input, options));
1136
1291
  };
1137
1292
  }
1138
1293
  /**
1139
1294
  * Encodes a typed input (the schema's `Type`) against a schema, returning a
1140
1295
  * `Promise` that resolves with the encoded value or rejects with a
1141
- * {@link SchemaError}.
1296
+ * {@link SchemaError} for schema mismatches.
1142
1297
  *
1143
1298
  * **When to use**
1144
1299
  *
1145
1300
  * Use when you already have a value typed as the schema's `Type` and need
1146
- * encoding to return a JavaScript `Promise` that rejects with `SchemaError`.
1301
+ * encoding to return a JavaScript `Promise` that rejects with `SchemaError` for
1302
+ * schema mismatches.
1147
1303
  *
1148
1304
  * **Details**
1149
1305
  *
@@ -1151,7 +1307,12 @@ export function encodeUnknownPromise(schema, options) {
1151
1307
  * Options may be provided either when creating the encoder or when applying it;
1152
1308
  * application options override creation options.
1153
1309
  *
1154
- * @see {@link SchemaParser.encodePromise} for the adapter that rejects with `SchemaIssue.Issue` directly
1310
+ * **Gotchas**
1311
+ *
1312
+ * Non-schema failures may reject with a runtime failure instead of
1313
+ * `SchemaError`.
1314
+ *
1315
+ * @see {@link SchemaParser.encodePromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
1155
1316
  *
1156
1317
  * @category encoding
1157
1318
  * @since 3.10.0
@@ -1159,7 +1320,7 @@ export function encodeUnknownPromise(schema, options) {
1159
1320
  export const encodePromise = encodeUnknownPromise;
1160
1321
  /**
1161
1322
  * Encodes an `unknown` input against a schema synchronously, throwing a
1162
- * {@link SchemaError} on failure.
1323
+ * {@link SchemaError} for schema mismatches.
1163
1324
  *
1164
1325
  * **When to use**
1165
1326
  *
@@ -1168,11 +1329,15 @@ export const encodePromise = encodeUnknownPromise;
1168
1329
  *
1169
1330
  * **Details**
1170
1331
  *
1171
- * For non-throwing alternatives see {@link encodeUnknownOption},
1172
- * {@link encodeUnknownExit}, or {@link encodeUnknownEffect}. For values
1173
- * already typed as the schema's `Type` use {@link encodeSync}.
1174
- * Options may be provided either when creating the encoder or when applying it;
1175
- * application options override creation options.
1332
+ * For alternatives that do not throw on schema mismatches, see
1333
+ * {@link encodeUnknownOption}, {@link encodeUnknownExit}, or
1334
+ * {@link encodeUnknownEffect}. For values already typed as the schema's `Type`
1335
+ * use {@link encodeSync}. Options may be provided either when creating the
1336
+ * encoder or when applying it; application options override creation options.
1337
+ *
1338
+ * **Gotchas**
1339
+ *
1340
+ * Non-schema failures may throw a runtime failure instead of `SchemaError`.
1176
1341
  *
1177
1342
  * @see {@link SchemaParser.encodeUnknownSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
1178
1343
  *
@@ -1182,12 +1347,12 @@ export const encodePromise = encodeUnknownPromise;
1182
1347
  export function encodeUnknownSync(schema, options) {
1183
1348
  const parser = encodeUnknownEffect(schema, options);
1184
1349
  return (input, options) => {
1185
- return Effect.runSync(parser(input, options));
1350
+ return runSchemaErrorSync(parser(input, options));
1186
1351
  };
1187
1352
  }
1188
1353
  /**
1189
1354
  * Encodes a typed input (the schema's `Type`) against a schema synchronously,
1190
- * throwing a {@link SchemaError} on failure.
1355
+ * throwing a {@link SchemaError} for schema mismatches.
1191
1356
  *
1192
1357
  * **When to use**
1193
1358
  *
@@ -1200,6 +1365,10 @@ export function encodeUnknownSync(schema, options) {
1200
1365
  * Options may be provided either when creating the encoder or when applying it;
1201
1366
  * application options override creation options.
1202
1367
  *
1368
+ * **Gotchas**
1369
+ *
1370
+ * Non-schema failures may throw a runtime failure instead of `SchemaError`.
1371
+ *
1203
1372
  * @see {@link SchemaParser.encodeSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
1204
1373
  *
1205
1374
  * @category encoding
@@ -1308,7 +1477,7 @@ export const requiredKey = /*#__PURE__*/Struct_.lambda(self => self.schema);
1308
1477
  * Use {@link optionalKey} instead if you want exact optional semantics (absent
1309
1478
  * only, not `undefined`).
1310
1479
  *
1311
- * **Example** (Optional field accepting undefined)
1480
+ * **Example** (Defining an optional field accepting undefined)
1312
1481
  *
1313
1482
  * ```ts
1314
1483
  * import { Schema } from "effect"
@@ -1400,7 +1569,7 @@ export function flip(schema) {
1400
1569
  /**
1401
1570
  * Creates a schema for a single literal value (string, number, bigint, boolean, or null).
1402
1571
  *
1403
- * **Example** (String literal)
1572
+ * **Example** (Defining a string literal)
1404
1573
  *
1405
1574
  * ```ts
1406
1575
  * import { Schema } from "effect"
@@ -1439,7 +1608,7 @@ function templateLiteralFromParts(parts) {
1439
1608
  * Use when the decoded value should remain the matched string and you do not
1440
1609
  * need the individual template parts parsed into a tuple.
1441
1610
  *
1442
- * **Example** (URL path pattern)
1611
+ * **Example** (Defining a URL path pattern)
1443
1612
  *
1444
1613
  * ```ts
1445
1614
  * import { Schema } from "effect"
@@ -1470,7 +1639,7 @@ export function TemplateLiteral(parts) {
1470
1639
  * Unlike {@link TemplateLiteral}, this schema decodes the matched string into a
1471
1640
  * readonly tuple with one element per schema part.
1472
1641
  *
1473
- * **Example** (Parse path parameters)
1642
+ * **Example** (Parsing path parameters)
1474
1643
  *
1475
1644
  * ```ts
1476
1645
  * import { Schema } from "effect"
@@ -1491,7 +1660,7 @@ export function TemplateLiteralParser(parts) {
1491
1660
  /**
1492
1661
  * Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
1493
1662
  *
1494
- * **Example** (Direction enum)
1663
+ * **Example** (Defining a direction enum)
1495
1664
  *
1496
1665
  * ```ts
1497
1666
  * import { Schema } from "effect"
@@ -1632,7 +1801,7 @@ export const ObjectKeyword = /*#__PURE__*/make(SchemaAST.objectKeyword);
1632
1801
  /**
1633
1802
  * Creates a schema for a specific symbol. Only that exact symbol satisfies the schema.
1634
1803
  *
1635
- * **Example** (Specific symbol)
1804
+ * **Example** (Defining a specific symbol)
1636
1805
  *
1637
1806
  * ```ts
1638
1807
  * import { Schema } from "effect"
@@ -1668,7 +1837,7 @@ function makeStruct(ast, fields) {
1668
1837
  * The resulting schema's `Type` is a readonly object type with the fields'
1669
1838
  * decoded types. The `Encoded` form mirrors the field schemas' encoded types.
1670
1839
  *
1671
- * **Example** (Basic struct)
1840
+ * **Example** (Defining a basic struct)
1672
1841
  *
1673
1842
  * ```ts
1674
1843
  * import { Schema } from "effect"
@@ -1735,7 +1904,7 @@ const canonicalPropertyKey = key => typeof key === "symbol" ? key : globalThis.S
1735
1904
  * If two existing fields would produce the same encoded key, construction
1736
1905
  * fails.
1737
1906
  *
1738
- * **Example** (Rename `name` to `full_name` in the encoded form)
1907
+ * **Example** (Renaming `name` to `full_name` in the encoded form)
1739
1908
  *
1740
1909
  * ```ts
1741
1910
  * import { Schema } from "effect"
@@ -1789,7 +1958,7 @@ export function encodeKeys(mapping) {
1789
1958
  * computed or enriched fields to live in the decoded type without appearing in
1790
1959
  * the encoded form.
1791
1960
  *
1792
- * **Example** (Add a computed `fullName` field)
1961
+ * **Example** (Adding a computed `fullName` field)
1793
1962
  *
1794
1963
  * ```ts
1795
1964
  * import { Option, Schema } from "effect"
@@ -1848,7 +2017,7 @@ derive) {
1848
2017
  /**
1849
2018
  * Defines a record (dictionary) schema with typed keys and values.
1850
2019
  *
1851
- * **Example** (String-keyed record of numbers)
2020
+ * **Example** (Defining a string-keyed record of numbers)
1852
2021
  *
1853
2022
  * ```ts
1854
2023
  * import { Schema } from "effect"
@@ -1877,7 +2046,7 @@ export function Record(key, value, options) {
1877
2046
  * Extends a struct schema with one or more record (index-signature) schemas,
1878
2047
  * producing a schema whose decoded type intersects the struct and all records.
1879
2048
  *
1880
- * **Example** (Struct with string-indexed extra keys)
2049
+ * **Example** (Defining structs with string-indexed extra keys)
1881
2050
  *
1882
2051
  * ```ts
1883
2052
  * import { Schema } from "effect"
@@ -1912,7 +2081,7 @@ function makeTuple(ast, elements) {
1912
2081
  /**
1913
2082
  * Defines a fixed-length tuple schema from an array of element schemas.
1914
2083
  *
1915
- * **Example** (Pair of string and number)
2084
+ * **Example** (Defining a pair of string and number)
1916
2085
  *
1917
2086
  * ```ts
1918
2087
  * import { Schema } from "effect"
@@ -1941,7 +2110,7 @@ export function Tuple(elements) {
1941
2110
  * example, `[Schema.Boolean, Schema.String]` represents zero or more booleans
1942
2111
  * followed by a final string.
1943
2112
  *
1944
- * **Example** (Tuple with rest)
2113
+ * **Example** (Defining tuples with rest elements)
1945
2114
  *
1946
2115
  * ```ts
1947
2116
  * import { Schema } from "effect"
@@ -1977,7 +2146,7 @@ export {
1977
2146
  /**
1978
2147
  * Defines a `ReadonlyArray` schema for a given element schema.
1979
2148
  *
1980
- * **Example** (Array of strings)
2149
+ * **Example** (Defining an array of strings)
1981
2150
  *
1982
2151
  * ```ts
1983
2152
  * import { Schema } from "effect"
@@ -1997,7 +2166,7 @@ ArraySchema as Array };
1997
2166
  * Defines a non-empty `ReadonlyArray` schema — at least one element required.
1998
2167
  * Type is `readonly [T, ...T[]]`.
1999
2168
  *
2000
- * **Example** (Non-empty array of numbers)
2169
+ * **Example** (Defining a non-empty array of numbers)
2001
2170
  *
2002
2171
  * ```ts
2003
2172
  * import { Schema } from "effect"
@@ -2063,7 +2232,7 @@ export function UniqueArray(item) {
2063
2232
  /**
2064
2233
  * Makes an array or tuple schema mutable, removing the `readonly` modifier.
2065
2234
  *
2066
- * **Example** (Mutable array)
2235
+ * **Example** (Defining mutable arrays)
2067
2236
  *
2068
2237
  * ```ts
2069
2238
  * import { Schema } from "effect"
@@ -2101,7 +2270,7 @@ function makeUnion(ast, members) {
2101
2270
  * - `"anyOf"` (default) — matches if any member matches.
2102
2271
  * - `"oneOf"` — matches if exactly one member matches.
2103
2272
  *
2104
- * **Example** (String or number union)
2273
+ * **Example** (Defining a string or number union)
2105
2274
  *
2106
2275
  * ```ts
2107
2276
  * import { Schema } from "effect"
@@ -2121,7 +2290,7 @@ export function Union(members, options) {
2121
2290
  /**
2122
2291
  * Creates a union schema from an array of literal values.
2123
2292
  *
2124
- * **Example** (Status codes)
2293
+ * **Example** (Defining status codes)
2125
2294
  *
2126
2295
  * ```ts
2127
2296
  * import { Schema } from "effect"
@@ -2176,7 +2345,7 @@ export const NullishOr = /*#__PURE__*/Struct_.lambda(self => Union([self, Null,
2176
2345
  * essential for creating recursive schemas where a schema references itself,
2177
2346
  * preventing infinite recursion during schema definition.
2178
2347
  *
2179
- * **Example** (Recursive tree schema)
2348
+ * **Example** (Defining recursive tree schemas)
2180
2349
  *
2181
2350
  * ```ts
2182
2351
  * import { Schema } from "effect"
@@ -2520,7 +2689,7 @@ export function encode(transformation) {
2520
2689
  * Constructor defaults are applied only during `make*`, not during decoding or
2521
2690
  * encoding.
2522
2691
  *
2523
- * **Example** (Optional field with a static default)
2692
+ * **Example** (Defining an optional field with a static default)
2524
2693
  *
2525
2694
  * ```ts
2526
2695
  * import { Effect, Schema } from "effect"
@@ -2543,7 +2712,7 @@ export function withConstructorDefault(
2543
2712
  // `S["~type.make.in"]` instead of `S["Type"]` is intentional here because
2544
2713
  // it makes easier to define the default value if there are nested defaults
2545
2714
  defaultValue) {
2546
- return schema => make(SchemaAST.withConstructorDefault(schema.ast, Effect.mapErrorEager(defaultValue, e => e.issue)), {
2715
+ return schema => make(SchemaAST.withConstructorDefault(schema.ast, InternalSchema.mapSchemaErrorEffect(defaultValue)), {
2547
2716
  schema
2548
2717
  });
2549
2718
  }
@@ -2563,7 +2732,7 @@ defaultValue) {
2563
2732
  * - `"passthrough"` (default): include the value in the encoded output.
2564
2733
  * - `"omit"`: omit the key from the encoded output.
2565
2734
  *
2566
- * **Example** (Default for a missing struct key)
2735
+ * **Example** (Providing a default for a missing struct key)
2567
2736
  *
2568
2737
  * ```ts
2569
2738
  * import { Effect, Schema } from "effect"
@@ -2585,7 +2754,7 @@ export function withDecodingDefaultKey(defaultValue, options) {
2585
2754
  const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough();
2586
2755
  return self => {
2587
2756
  return optionalKey(toEncoded(self)).pipe(decodeTo(self, {
2588
- decode: SchemaGetter.withDefault(Effect.mapErrorEager(defaultValue, e => e.issue)),
2757
+ decode: SchemaGetter.withDefault(InternalSchema.mapSchemaErrorEffect(defaultValue)),
2589
2758
  encode
2590
2759
  }));
2591
2760
  };
@@ -2638,7 +2807,7 @@ export function withDecodingDefaultTypeKey(defaultValue, options) {
2638
2807
  * - `"passthrough"` (default): include the value in the encoded output.
2639
2808
  * - `"omit"`: omit the key from the encoded output.
2640
2809
  *
2641
- * **Example** (Default for an optional field value)
2810
+ * **Example** (Providing a default for an optional field value)
2642
2811
  *
2643
2812
  * ```ts
2644
2813
  * import { Effect, Schema } from "effect"
@@ -2660,7 +2829,7 @@ export function withDecodingDefault(defaultValue, options) {
2660
2829
  const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough();
2661
2830
  return self => {
2662
2831
  return optional(toEncoded(self)).pipe(decodeTo(self, {
2663
- decode: SchemaGetter.withDefault(Effect.mapErrorEager(defaultValue, e => e.issue)),
2832
+ decode: SchemaGetter.withDefault(InternalSchema.mapSchemaErrorEffect(defaultValue)),
2664
2833
  encode
2665
2834
  }));
2666
2835
  };
@@ -2702,7 +2871,7 @@ export function withDecodingDefaultType(defaultValue, options) {
2702
2871
  * for discriminator fields in tagged unions. When constructing via `make`, the
2703
2872
  * `_tag` field can be omitted and will be filled automatically.
2704
2873
  *
2705
- * **Example** (Discriminated union tag)
2874
+ * **Example** (Defining a discriminated union tag)
2706
2875
  *
2707
2876
  * ```ts
2708
2877
  * import { Schema } from "effect"
@@ -2735,7 +2904,7 @@ export function tag(literal) {
2735
2904
  * The tag is filled during decoding and construction, like {@link tag}, but is
2736
2905
  * omitted when encoding.
2737
2906
  *
2738
- * **Example** (Tag omitted during encoding)
2907
+ * **Example** (Omitting tags during encoding)
2739
2908
  *
2740
2909
  * ```ts
2741
2910
  * import { Schema } from "effect"
@@ -2772,7 +2941,7 @@ export function tagDefaultOmit(literal) {
2772
2941
  * added automatically. However, when decoding or encoding, the `_tag` field
2773
2942
  * must be present in the input.
2774
2943
  *
2775
- * **Example** (Tagged struct as a shorthand for a struct with a `_tag` field)
2944
+ * **Example** (Defining a tagged struct shorthand)
2776
2945
  *
2777
2946
  * ```ts
2778
2947
  * import { Schema } from "effect"
@@ -2881,7 +3050,7 @@ export function toTaggedUnion(tag) {
2881
3050
  * Each key becomes the `_tag` literal and the value is passed to {@link TaggedStruct}.
2882
3051
  * The result includes `cases`, `guards`, `isAnyOf`, and `match` utilities.
2883
3052
  *
2884
- * **Example** (Discriminated union with pattern matching)
3053
+ * **Example** (Pattern matching a discriminated union)
2885
3054
  *
2886
3055
  * ```ts
2887
3056
  * import { Schema } from "effect"
@@ -2926,7 +3095,7 @@ export function TaggedUnion(casesByTag) {
2926
3095
  * Useful for creating opaque types that are structurally identical to a base struct
2927
3096
  * but type-incompatible with it.
2928
3097
  *
2929
- * **Example** (Opaque struct)
3098
+ * **Example** (Defining opaque structs)
2930
3099
  *
2931
3100
  * ```ts
2932
3101
  * import { Schema } from "effect"
@@ -2956,7 +3125,7 @@ export function Opaque() {
2956
3125
  * Creates a schema that validates values using `instanceof`.
2957
3126
  * Decoding and encoding pass the value through unchanged.
2958
3127
  *
2959
- * **Example** (Schema for a built-in class)
3128
+ * **Example** (Defining a schema for a built-in class)
2960
3129
  *
2961
3130
  * ```ts
2962
3131
  * import { Schema } from "effect"
@@ -3002,7 +3171,7 @@ export function link() {
3002
3171
  * When `abort` is `true`, parsing stops after this filter fails instead of
3003
3172
  * collecting later check failures.
3004
3173
  *
3005
- * **Example** (Failure at a nested path)
3174
+ * **Example** (Reporting failure at a nested path)
3006
3175
  *
3007
3176
  * ```ts
3008
3177
  * import { Schema } from "effect"
@@ -4345,7 +4514,7 @@ export const isBetweenBigDecimal = /*#__PURE__*/makeIsBetween({
4345
4514
  * constraint to ensure generated strings or arrays have at least the required
4346
4515
  * length.
4347
4516
  *
4348
- * **Example** (Minimum length check)
4517
+ * **Example** (Checking minimum length)
4349
4518
  *
4350
4519
  * ```ts
4351
4520
  * import { Schema } from "effect"
@@ -5916,7 +6085,7 @@ const DateString = /*#__PURE__*/String.annotate({
5916
6085
  * JSON serializer encodes valid dates as ISO 8601 strings; invalid dates encode
5917
6086
  * as `"Invalid Date"`.
5918
6087
  *
5919
- * **Example** (Date schema)
6088
+ * **Example** (Defining a Date schema)
5920
6089
  *
5921
6090
  * ```ts
5922
6091
  * import { Schema } from "effect"
@@ -5990,7 +6159,7 @@ export const DateValid = /*#__PURE__*/Date.check(/*#__PURE__*/isDateValid());
5990
6159
  * The default JSON serializer encodes `Duration` as a tagged object with the
5991
6160
  * duration type and value.
5992
6161
  *
5993
- * **Example** (Duration schema)
6162
+ * **Example** (Defining a Duration schema)
5994
6163
  *
5995
6164
  * ```ts
5996
6165
  * import { Duration, Schema } from "effect"
@@ -6491,7 +6660,7 @@ export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
6491
6660
  * // Success({"a":"1"})
6492
6661
  * ```
6493
6662
  *
6494
- * **Example** (Nested fields)
6663
+ * **Example** (Decoding nested fields)
6495
6664
  *
6496
6665
  * ```ts
6497
6666
  * import { Schema } from "effect"
@@ -6605,7 +6774,7 @@ export const URLSearchParams = /*#__PURE__*/instanceOf(globalThis.URLSearchParam
6605
6774
  * // Success({"a":"1"})
6606
6775
  * ```
6607
6776
  *
6608
- * **Example** (Nested fields)
6777
+ * **Example** (Decoding nested fields)
6609
6778
  *
6610
6779
  * ```ts
6611
6780
  * import { Schema } from "effect"
@@ -7384,7 +7553,7 @@ function isStruct(schema) {
7384
7553
  *
7385
7554
  * Passing `disableChecks` in the options skips constructor validation.
7386
7555
  *
7387
- * **Example** (Basic class)
7556
+ * **Example** (Defining a basic class)
7388
7557
  *
7389
7558
  * ```ts
7390
7559
  * import { Schema } from "effect"
@@ -7447,7 +7616,7 @@ export const Class = identifier => (schema, annotations) => {
7447
7616
  * The optional `identifier` parameter overrides the schema identifier;
7448
7617
  * it defaults to the `tag` value.
7449
7618
  *
7450
- * **Example** (Tagged class)
7619
+ * **Example** (Defining a tagged class)
7451
7620
  *
7452
7621
  * ```ts
7453
7622
  * import { Schema } from "effect"
@@ -7514,7 +7683,7 @@ export const ErrorClass = identifier => (schema, annotations) => {
7514
7683
  * Use to define typed errors that are schema validated, yielded in `Effect.gen`,
7515
7684
  * and matched as tagged union members.
7516
7685
  *
7517
- * **Example** (Tagged error class)
7686
+ * **Example** (Defining a tagged error class)
7518
7687
  *
7519
7688
  * ```ts
7520
7689
  * import { Effect, Schema } from "effect"
@@ -7763,7 +7932,7 @@ export function overrideToEquivalence(toEquivalence) {
7763
7932
  * every field (and nested field) compares equal according to the schema
7764
7933
  * structure.
7765
7934
  *
7766
- * **Example** (Struct equivalence)
7935
+ * **Example** (Comparing structs)
7767
7936
  *
7768
7937
  * ```ts
7769
7938
  * import { Schema } from "effect"