effect 4.0.0-beta.83 → 4.0.0-beta.85

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 (235) 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/Context.d.ts.map +1 -1
  24. package/dist/Context.js +4 -3
  25. package/dist/Context.js.map +1 -1
  26. package/dist/Data.d.ts +15 -15
  27. package/dist/Data.js +3 -3
  28. package/dist/DateTime.d.ts +6 -6
  29. package/dist/DateTime.js +2 -2
  30. package/dist/Duration.d.ts +3 -3
  31. package/dist/Duration.js +3 -3
  32. package/dist/Effect.d.ts +84 -45
  33. package/dist/Effect.d.ts.map +1 -1
  34. package/dist/Effect.js +72 -33
  35. package/dist/Effect.js.map +1 -1
  36. package/dist/Equal.d.ts +7 -7
  37. package/dist/Equal.js +5 -5
  38. package/dist/Equivalence.d.ts +17 -17
  39. package/dist/Equivalence.js +13 -13
  40. package/dist/Exit.d.ts +3 -3
  41. package/dist/Exit.js +3 -3
  42. package/dist/Formatter.d.ts +5 -5
  43. package/dist/Formatter.js +4 -4
  44. package/dist/Function.d.ts +10 -10
  45. package/dist/Function.js +3 -3
  46. package/dist/HashMap.d.ts +3 -3
  47. package/dist/HashMap.js +1 -1
  48. package/dist/Iterable.d.ts +6 -6
  49. package/dist/Iterable.js +2 -2
  50. package/dist/JsonPatch.d.ts +2 -2
  51. package/dist/Layer.d.ts +1 -1
  52. package/dist/Layer.js +5 -4
  53. package/dist/Layer.js.map +1 -1
  54. package/dist/LayerMap.d.ts.map +1 -1
  55. package/dist/LayerMap.js +4 -3
  56. package/dist/LayerMap.js.map +1 -1
  57. package/dist/Logger.d.ts +1 -1
  58. package/dist/Logger.js +1 -1
  59. package/dist/Match.d.ts +8 -8
  60. package/dist/Match.js +8 -8
  61. package/dist/Metric.d.ts +3 -3
  62. package/dist/Metric.js +3 -3
  63. package/dist/Optic.d.ts +30 -30
  64. package/dist/Optic.js +12 -12
  65. package/dist/Option.d.ts +7 -7
  66. package/dist/Option.js +7 -7
  67. package/dist/Order.d.ts +23 -23
  68. package/dist/Order.js +20 -20
  69. package/dist/Pool.d.ts +1 -1
  70. package/dist/Pool.js +1 -1
  71. package/dist/Predicate.d.ts +88 -88
  72. package/dist/Predicate.js +47 -47
  73. package/dist/PubSub.d.ts +3 -3
  74. package/dist/PubSub.js +3 -3
  75. package/dist/Random.d.ts +31 -0
  76. package/dist/Random.d.ts.map +1 -1
  77. package/dist/Random.js +32 -0
  78. package/dist/Random.js.map +1 -1
  79. package/dist/Reducer.d.ts +1 -1
  80. package/dist/Reducer.js +1 -1
  81. package/dist/Result.d.ts +18 -18
  82. package/dist/Result.js +8 -8
  83. package/dist/Runtime.d.ts +1 -1
  84. package/dist/Runtime.js +1 -1
  85. package/dist/Schema.d.ts +313 -126
  86. package/dist/Schema.d.ts.map +1 -1
  87. package/dist/Schema.js +316 -127
  88. package/dist/Schema.js.map +1 -1
  89. package/dist/SchemaAST.d.ts +9 -8
  90. package/dist/SchemaAST.d.ts.map +1 -1
  91. package/dist/SchemaAST.js +203 -140
  92. package/dist/SchemaAST.js.map +1 -1
  93. package/dist/SchemaGetter.d.ts +48 -48
  94. package/dist/SchemaGetter.js +44 -44
  95. package/dist/SchemaIssue.d.ts +3 -3
  96. package/dist/SchemaIssue.js +3 -3
  97. package/dist/SchemaParser.d.ts +122 -22
  98. package/dist/SchemaParser.d.ts.map +1 -1
  99. package/dist/SchemaParser.js +186 -50
  100. package/dist/SchemaParser.js.map +1 -1
  101. package/dist/SchemaRepresentation.d.ts +1 -1
  102. package/dist/SchemaRepresentation.d.ts.map +1 -1
  103. package/dist/SchemaRepresentation.js +96 -2
  104. package/dist/SchemaRepresentation.js.map +1 -1
  105. package/dist/SchemaTransformation.d.ts +20 -20
  106. package/dist/SchemaTransformation.js +18 -18
  107. package/dist/Stream.d.ts +3 -3
  108. package/dist/Stream.js +2 -2
  109. package/dist/Stream.js.map +1 -1
  110. package/dist/String.d.ts +1 -1
  111. package/dist/String.js +1 -1
  112. package/dist/Struct.d.ts +1 -1
  113. package/dist/Struct.js +1 -1
  114. package/dist/Types.d.ts +13 -13
  115. package/dist/internal/effect.js +33 -20
  116. package/dist/internal/effect.js.map +1 -1
  117. package/dist/internal/schema/arbitrary.js +17 -1
  118. package/dist/internal/schema/arbitrary.js.map +1 -1
  119. package/dist/internal/schema/cause.d.ts +2 -0
  120. package/dist/internal/schema/cause.d.ts.map +1 -0
  121. package/dist/internal/schema/cause.js +24 -0
  122. package/dist/internal/schema/cause.js.map +1 -0
  123. package/dist/internal/schema/schema.d.ts +8 -4
  124. package/dist/internal/schema/schema.d.ts.map +1 -1
  125. package/dist/internal/schema/schema.js +21 -8
  126. package/dist/internal/schema/schema.js.map +1 -1
  127. package/dist/internal/stackTraceLimit.d.ts +2 -0
  128. package/dist/internal/stackTraceLimit.d.ts.map +1 -0
  129. package/dist/internal/stackTraceLimit.js +40 -0
  130. package/dist/internal/stackTraceLimit.js.map +1 -0
  131. package/dist/internal/tracer.d.ts.map +1 -1
  132. package/dist/internal/tracer.js +4 -3
  133. package/dist/internal/tracer.js.map +1 -1
  134. package/dist/testing/TestSchema.d.ts +3 -3
  135. package/dist/testing/TestSchema.js +1 -1
  136. package/dist/unstable/ai/AiError.d.ts +1 -1
  137. package/dist/unstable/ai/AiError.js +1 -1
  138. package/dist/unstable/ai/Chat.d.ts +1 -1
  139. package/dist/unstable/ai/Chat.js +1 -1
  140. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  141. package/dist/unstable/ai/Tool.js +4 -5
  142. package/dist/unstable/ai/Tool.js.map +1 -1
  143. package/dist/unstable/cli/Prompt.js +2 -2
  144. package/dist/unstable/cli/Prompt.js.map +1 -1
  145. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  146. package/dist/unstable/httpapi/HttpApiMiddleware.js +4 -3
  147. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  148. package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
  149. package/dist/unstable/persistence/PersistedQueue.js +1 -1
  150. package/dist/unstable/rpc/Rpc.d.ts +1 -1
  151. package/dist/unstable/rpc/Rpc.js +1 -1
  152. package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
  153. package/dist/unstable/rpc/RpcGroup.js +3 -4
  154. package/dist/unstable/rpc/RpcGroup.js.map +1 -1
  155. package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
  156. package/dist/unstable/rpc/RpcMiddleware.js +4 -3
  157. package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
  158. package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
  159. package/dist/unstable/sql/SqlResolver.js +15 -2
  160. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  161. package/dist/unstable/workflow/Activity.d.ts +1 -0
  162. package/dist/unstable/workflow/Activity.d.ts.map +1 -1
  163. package/dist/unstable/workflow/Activity.js +1 -0
  164. package/dist/unstable/workflow/Activity.js.map +1 -1
  165. package/dist/unstable/workflow/WorkflowEngine.js +1 -1
  166. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  167. package/package.json +1 -1
  168. package/src/Array.ts +65 -65
  169. package/src/Cache.ts +1 -1
  170. package/src/Cause.ts +68 -68
  171. package/src/Channel.ts +5 -5
  172. package/src/Clock.ts +1 -1
  173. package/src/Combiner.ts +9 -9
  174. package/src/Config.ts +40 -108
  175. package/src/ConfigProvider.ts +139 -100
  176. package/src/Console.ts +1 -1
  177. package/src/Context.ts +4 -5
  178. package/src/Data.ts +15 -15
  179. package/src/DateTime.ts +6 -6
  180. package/src/Duration.ts +3 -3
  181. package/src/Effect.ts +89 -45
  182. package/src/Equal.ts +7 -7
  183. package/src/Equivalence.ts +17 -17
  184. package/src/Exit.ts +3 -3
  185. package/src/Formatter.ts +5 -5
  186. package/src/Function.ts +10 -10
  187. package/src/HashMap.ts +3 -3
  188. package/src/Iterable.ts +6 -6
  189. package/src/JsonPatch.ts +2 -2
  190. package/src/Layer.ts +5 -5
  191. package/src/LayerMap.ts +4 -3
  192. package/src/Logger.ts +1 -1
  193. package/src/Match.ts +8 -8
  194. package/src/Metric.ts +3 -3
  195. package/src/Optic.ts +30 -30
  196. package/src/Option.ts +7 -7
  197. package/src/Order.ts +23 -23
  198. package/src/Pool.ts +1 -1
  199. package/src/Predicate.ts +88 -88
  200. package/src/PubSub.ts +3 -3
  201. package/src/Random.ts +42 -0
  202. package/src/Reducer.ts +1 -1
  203. package/src/Result.ts +20 -20
  204. package/src/Runtime.ts +1 -1
  205. package/src/Schema.ts +389 -153
  206. package/src/SchemaAST.ts +237 -148
  207. package/src/SchemaGetter.ts +48 -48
  208. package/src/SchemaIssue.ts +3 -3
  209. package/src/SchemaParser.ts +197 -58
  210. package/src/SchemaRepresentation.ts +73 -3
  211. package/src/SchemaTransformation.ts +20 -20
  212. package/src/Stream.ts +4 -4
  213. package/src/String.ts +1 -1
  214. package/src/Struct.ts +1 -1
  215. package/src/Types.ts +13 -13
  216. package/src/internal/effect.ts +40 -21
  217. package/src/internal/schema/arbitrary.ts +23 -2
  218. package/src/internal/schema/cause.ts +26 -0
  219. package/src/internal/schema/schema.ts +36 -10
  220. package/src/internal/stackTraceLimit.ts +63 -0
  221. package/src/internal/tracer.ts +4 -3
  222. package/src/testing/TestSchema.ts +3 -3
  223. package/src/unstable/ai/AiError.ts +1 -1
  224. package/src/unstable/ai/Chat.ts +1 -1
  225. package/src/unstable/ai/Tool.ts +4 -3
  226. package/src/unstable/cli/Prompt.ts +1 -1
  227. package/src/unstable/httpapi/HttpApiMiddleware.ts +4 -3
  228. package/src/unstable/httpapi/HttpApiScalar.ts +2 -2
  229. package/src/unstable/persistence/PersistedQueue.ts +1 -1
  230. package/src/unstable/rpc/Rpc.ts +1 -1
  231. package/src/unstable/rpc/RpcGroup.ts +3 -4
  232. package/src/unstable/rpc/RpcMiddleware.ts +4 -3
  233. package/src/unstable/sql/SqlResolver.ts +15 -2
  234. package/src/unstable/workflow/Activity.ts +2 -0
  235. package/src/unstable/workflow/WorkflowEngine.ts +1 -1
@@ -447,7 +447,7 @@ export function trim(): Transformation<string, string> {
447
447
  * Encoding converts values such as `"myFieldName"` back to `"my_field_name"`.
448
448
  * The transformation is round-trippable for standard snake_case and camelCase.
449
449
  *
450
- * **Example** (Snake to camel conversion)
450
+ * **Example** (Converting snake case to camel case)
451
451
  *
452
452
  * ```ts
453
453
  * import { Schema, SchemaTransformation } from "effect"
@@ -722,7 +722,7 @@ export function passthrough<T>(): Transformation<T, T> {
722
722
  * Both decode and encode are no-ops and return a shared singleton
723
723
  * transformation.
724
724
  *
725
- * **Example** (Supertype passthrough)
725
+ * **Example** (Passing through supertypes)
726
726
  *
727
727
  * ```ts
728
728
  * import { SchemaTransformation } from "effect"
@@ -755,7 +755,7 @@ export function passthroughSupertype<T>(): Transformation<T, T> {
755
755
  * - Both decode and encode are no-ops (same as {@link passthrough}).
756
756
  * - Returns a shared singleton instance.
757
757
  *
758
- * **Example** (Subtype passthrough)
758
+ * **Example** (Passing through subtypes)
759
759
  *
760
760
  * ```ts
761
761
  * import { SchemaTransformation } from "effect"
@@ -790,7 +790,7 @@ export function passthroughSubtype<T>(): Transformation<T, T> {
790
790
  * result is finite; combine with `Schema.Finite` or `Schema.Int` for stricter
791
791
  * checks.
792
792
  *
793
- * **Example** (Number from string)
793
+ * **Example** (Converting a string to a number)
794
794
  *
795
795
  * ```ts
796
796
  * import { Schema, SchemaTransformation } from "effect"
@@ -826,7 +826,7 @@ export const numberFromString = new Transformation(
826
826
  * the bigint to a string like `String(n)`. Decoding fails if the string is not
827
827
  * a valid bigint representation.
828
828
  *
829
- * **Example** (BigInt from string)
829
+ * **Example** (Converting a string to a BigInt)
830
830
  *
831
831
  * ```ts
832
832
  * import { Schema, SchemaTransformation } from "effect"
@@ -861,7 +861,7 @@ export const bigintFromString = new Transformation(
861
861
  * converts the `Date` to an ISO string like `date.toISOString()`, returning
862
862
  * `"Invalid Date"` for invalid dates.
863
863
  *
864
- * **Example** (Date from string)
864
+ * **Example** (Converting a string to a Date)
865
865
  *
866
866
  * ```ts
867
867
  * import { Schema, SchemaTransformation } from "effect"
@@ -898,7 +898,7 @@ export const dateFromString: Transformation<globalThis.Date, string> = new Trans
898
898
  * producing strings such as `"2000 millis"` or `"10 nanos"` that round-trip
899
899
  * through the parser.
900
900
  *
901
- * **Example** (Duration from string)
901
+ * **Example** (Converting a string to a Duration)
902
902
  *
903
903
  * ```ts
904
904
  * import { Schema, SchemaTransformation } from "effect"
@@ -942,7 +942,7 @@ export const durationFromString: Transformation<Duration.Duration, string> = tra
942
942
  * fails with `InvalidValue` if the `Duration` cannot be represented as a
943
943
  * `bigint`, such as `Duration.infinity`.
944
944
  *
945
- * **Example** (Duration from nanoseconds)
945
+ * **Example** (Converting nanoseconds to a Duration)
946
946
  *
947
947
  * ```ts
948
948
  * import { Schema, SchemaTransformation } from "effect"
@@ -983,7 +983,7 @@ export const durationFromNanos: Transformation<Duration.Duration, bigint> = tran
983
983
  * Decode creates a duration from the number, and encode returns the duration
984
984
  * length in milliseconds.
985
985
  *
986
- * **Example** (Duration from milliseconds)
986
+ * **Example** (Converting milliseconds to a Duration)
987
987
  *
988
988
  * ```ts
989
989
  * import { Schema, SchemaTransformation } from "effect"
@@ -1098,7 +1098,7 @@ export const defectFromJson = (options?: ErrorOptions) =>
1098
1098
  * `Option.some(value)`. Encoding maps `Option.none()` to `null` and
1099
1099
  * `Option.some(value)` to `value`. The transformation is pure and synchronous.
1100
1100
  *
1101
- * **Example** (Option from nullable)
1101
+ * **Example** (Converting nullable values to an Option)
1102
1102
  *
1103
1103
  * ```ts
1104
1104
  * import { Schema, SchemaTransformation } from "effect"
@@ -1138,7 +1138,7 @@ export function optionFromNullOr<T>(): Transformation<Option.Option<T>, T | null
1138
1138
  * `Option.some(value)`. Encoding maps `Option.none()` to `undefined` and
1139
1139
  * `Option.some(value)` to `value`. The transformation is pure and synchronous.
1140
1140
  *
1141
- * **Example** (Option from undefined-or)
1141
+ * **Example** (Converting undefined-or values to an Option)
1142
1142
  *
1143
1143
  * ```ts
1144
1144
  * import { Schema, SchemaTransformation } from "effect"
@@ -1181,7 +1181,7 @@ export function optionFromUndefinedOr<T>(): Transformation<Option.Option<T>, T |
1181
1181
  * `undefined` according to `options.onNoneEncoding`, and maps
1182
1182
  * `Option.some(value)` to `value`. The transformation is pure and synchronous.
1183
1183
  *
1184
- * **Example** (Option from nullish, encoding None as null)
1184
+ * **Example** (Converting nullish values to an Option and encoding None as null)
1185
1185
  *
1186
1186
  * ```ts
1187
1187
  * import { Schema, SchemaTransformation } from "effect"
@@ -1227,7 +1227,7 @@ export function optionFromNullishOr<T>(
1227
1227
  * the key, and maps `Some(Some(v))` to `Some(v)`. This uses
1228
1228
  * `transformOptional` under the hood.
1229
1229
  *
1230
- * **Example** (Optional key to Option)
1230
+ * **Example** (Converting an optional key to an Option)
1231
1231
  *
1232
1232
  * ```ts
1233
1233
  * import { Schema, SchemaTransformation } from "effect"
@@ -1272,7 +1272,7 @@ export function optionFromOptionalKey<T>(): Transformation<Option.Option<T>, T>
1272
1272
  * value, and maps `Some(Some(v))` to `Some(v)`. This uses
1273
1273
  * `transformOptional` under the hood and filters out `undefined` on decode.
1274
1274
  *
1275
- * **Example** (Optional value to Option)
1275
+ * **Example** (Converting an optional value to an Option)
1276
1276
  *
1277
1277
  * ```ts
1278
1278
  * import { Schema, SchemaTransformation } from "effect"
@@ -1315,7 +1315,7 @@ export function optionFromOptional<T>(): Transformation<Option.Option<T>, T | un
1315
1315
  * Decoding calls `new URL(s)` and fails with `InvalidValue` if the string is
1316
1316
  * not a valid URL. Encoding returns `url.href`.
1317
1317
  *
1318
- * **Example** (URL from string)
1318
+ * **Example** (Converting a string to a URL)
1319
1319
  *
1320
1320
  * ```ts
1321
1321
  * import { Schema, SchemaTransformation } from "effect"
@@ -1385,7 +1385,7 @@ export const bigDecimalFromString: Transformation<BigDecimal.BigDecimal, string>
1385
1385
  * Decoding parses the Base64 string into bytes. Encoding writes the byte array
1386
1386
  * as a Base64 string.
1387
1387
  *
1388
- * **Example** (Uint8Array from Base64)
1388
+ * **Example** (Converting Base64 to a Uint8Array)
1389
1389
  *
1390
1390
  * ```ts
1391
1391
  * import { Schema, SchemaTransformation } from "effect"
@@ -1420,7 +1420,7 @@ export const uint8ArrayFromBase64String: Transformation<Uint8Array<ArrayBufferLi
1420
1420
  * Decoding parses the Base64 string into a UTF-8 string. Encoding writes the
1421
1421
  * string as a Base64 string.
1422
1422
  *
1423
- * **Example** (String from Base64)
1423
+ * **Example** (Converting Base64 to a string)
1424
1424
  *
1425
1425
  * ```ts
1426
1426
  * import { Schema, SchemaTransformation } from "effect"
@@ -1454,7 +1454,7 @@ export const stringFromBase64String: Transformation<string, string> = new Transf
1454
1454
  * Decoding parses the Base64 URL string into a UTF-8 string. Encoding writes
1455
1455
  * the string as a Base64 URL string.
1456
1456
  *
1457
- * **Example** (String from Base64Url)
1457
+ * **Example** (Converting Base64Url to a string)
1458
1458
  *
1459
1459
  * ```ts
1460
1460
  * import { Schema, SchemaTransformation } from "effect"
@@ -1488,7 +1488,7 @@ export const stringFromBase64UrlString: Transformation<string, string> = new Tra
1488
1488
  * Decoding parses the hex string into a UTF-8 string. Encoding writes the
1489
1489
  * string as a hex string.
1490
1490
  *
1491
- * **Example** (String from Hex)
1491
+ * **Example** (Converting hex to a string)
1492
1492
  *
1493
1493
  * ```ts
1494
1494
  * import { Schema, SchemaTransformation } from "effect"
@@ -1524,7 +1524,7 @@ export const stringFromHexString: Transformation<string, string> = new Transform
1524
1524
  * Decoding calls `decodeURIComponent` and fails if the input contains malformed
1525
1525
  * percent-encoding sequences. Encoding calls `encodeURIComponent`.
1526
1526
  *
1527
- * **Example** (URI component schema)
1527
+ * **Example** (Defining a URI component schema)
1528
1528
  *
1529
1529
  * ```ts
1530
1530
  * import { Schema, SchemaTransformation } from "effect"
package/src/Stream.ts CHANGED
@@ -2905,7 +2905,7 @@ export const tapSink: {
2905
2905
  * multiple inner streams may run at the same time and their outputs are merged
2906
2906
  * as they arrive.
2907
2907
  *
2908
- * **Example** (FlatMapping stream values)
2908
+ * **Example** (Flat mapping stream values)
2909
2909
  *
2910
2910
  * ```ts
2911
2911
  * import { Console, Effect, Stream } from "effect"
@@ -2936,7 +2936,7 @@ export const flatMap: {
2936
2936
  * multiple inner streams may run at the same time and their outputs are merged
2937
2937
  * as they arrive.
2938
2938
  *
2939
- * **Example** (FlatMapping stream values)
2939
+ * **Example** (Flat mapping stream values)
2940
2940
  *
2941
2941
  * ```ts
2942
2942
  * import { Console, Effect, Stream } from "effect"
@@ -2973,7 +2973,7 @@ export const flatMap: {
2973
2973
  * multiple inner streams may run at the same time and their outputs are merged
2974
2974
  * as they arrive.
2975
2975
  *
2976
- * **Example** (FlatMapping stream values)
2976
+ * **Example** (Flat mapping stream values)
2977
2977
  *
2978
2978
  * ```ts
2979
2979
  * import { Console, Effect, Stream } from "effect"
@@ -19522,7 +19522,7 @@ export const runForEachWhile: {
19522
19522
  if (!b) done = true
19523
19523
  }
19524
19524
  }),
19525
- () => done
19525
+ () => !done
19526
19526
  )
19527
19527
  }))
19528
19528
 
package/src/String.ts CHANGED
@@ -102,7 +102,7 @@ export const Equivalence: Equ.Equivalence<string> = Equ.String
102
102
  *
103
103
  * Use when you need the canonical empty string value from the `String` module.
104
104
  *
105
- * **Example** (Using the empty string)
105
+ * **Example** (Referencing the empty string)
106
106
  *
107
107
  * ```ts
108
108
  * import { String } from "effect"
package/src/Struct.ts CHANGED
@@ -199,7 +199,7 @@ export const get: {
199
199
  *
200
200
  * Symbol keys are excluded; only string keys are returned.
201
201
  *
202
- * **Example** (Typed keys)
202
+ * **Example** (Reading typed keys)
203
203
  *
204
204
  * ```ts
205
205
  * import { Struct } from "effect"
package/src/Types.ts CHANGED
@@ -31,7 +31,7 @@ type TupleOf_<T, N extends number, R extends Array<unknown>> = `${N}` extends `-
31
31
  * - If `N` is the general `number` type (non-literal), degrades to `Array<T>`.
32
32
  * - Negative numbers produce `never`.
33
33
  *
34
- * **Example** (Fixed-length tuple)
34
+ * **Example** (Checking fixed-length tuples)
35
35
  *
36
36
  * ```ts
37
37
  * import type { Types } from "effect"
@@ -66,7 +66,7 @@ export type TupleOf<N extends number, T> = N extends N ? number extends N ? Arra
66
66
  *
67
67
  * Produces a tuple with `N` fixed positions followed by `...Array<T>`.
68
68
  *
69
- * **Example** (Minimum-length tuple)
69
+ * **Example** (Checking minimum-length tuples)
70
70
  *
71
71
  * ```ts
72
72
  * import type { Types } from "effect"
@@ -201,7 +201,7 @@ export type ExtractTag<E, K extends string> = E extends { readonly _tag: infer T
201
201
  * - If the union members are incompatible (e.g. `string | number`), the
202
202
  * result is `never`.
203
203
  *
204
- * **Example** (Union to intersection)
204
+ * **Example** (Converting a union to an intersection)
205
205
  *
206
206
  * ```ts
207
207
  * import type { Types } from "effect"
@@ -264,7 +264,7 @@ export type Simplify<A> = {
264
264
  * distinguishing between `any`, `unknown`, `never`, and other types.
265
265
  * - Resolves to `true` if `X` and `Y` are identical, `false` otherwise.
266
266
  *
267
- * **Example** (Type equality check)
267
+ * **Example** (Checking type equality)
268
268
  *
269
269
  * ```ts
270
270
  * import type { Types } from "effect"
@@ -295,7 +295,7 @@ export type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <
295
295
  *
296
296
  * Returns `Y` when `A` and `B` are equal, `N` otherwise.
297
297
  *
298
- * **Example** (Conditional type based on equality)
298
+ * **Example** (Choosing a conditional type based on equality)
299
299
  *
300
300
  * ```ts
301
301
  * import type { Types } from "effect"
@@ -324,7 +324,7 @@ export type EqualsWith<A, B, Y, N> = (<T>() => T extends A ? 1 : 2) extends (<T>
324
324
  * Returns `true` if at least one key from `Key` exists in `A`, `false`
325
325
  * otherwise.
326
326
  *
327
- * **Example** (Key presence check)
327
+ * **Example** (Checking key presence)
328
328
  *
329
329
  * ```ts
330
330
  * import type { Types } from "effect"
@@ -352,7 +352,7 @@ export type Has<A, Key extends string> = (Key extends infer K ? K extends keyof
352
352
  *
353
353
  * Implemented as `MergeRight<Target, Source>`.
354
354
  *
355
- * **Example** (Left-biased merge)
355
+ * **Example** (Merging with left bias)
356
356
  *
357
357
  * ```ts
358
358
  * import type { Types } from "effect"
@@ -423,7 +423,7 @@ export type MergeRight<Target, Source> = Simplify<
423
423
  * - `"unbounded"` — run all effects concurrently with no limit.
424
424
  * - `"inherit"` — inherit the concurrency from the surrounding context.
425
425
  *
426
- * **Example** (Concurrency values)
426
+ * **Example** (Setting concurrency values)
427
427
  *
428
428
  * ```ts
429
429
  * import type { Types } from "effect"
@@ -451,7 +451,7 @@ export type Concurrency = number | "unbounded" | "inherit"
451
451
  *
452
452
  * Only affects the top level; nested properties remain readonly.
453
453
  *
454
- * **Example** (Shallow mutable conversion)
454
+ * **Example** (Converting shallowly to mutable types)
455
455
  *
456
456
  * ```ts
457
457
  * import type { Types } from "effect"
@@ -492,7 +492,7 @@ export type Mutable<T> = {
492
492
  * Recursion stops at primitives (`string`, `number`, `boolean`, `bigint`,
493
493
  * `symbol`) and functions.
494
494
  *
495
- * **Example** (Deep mutable conversion)
495
+ * **Example** (Converting deeply to mutable types)
496
496
  *
497
497
  * ```ts
498
498
  * import type { Types } from "effect"
@@ -557,7 +557,7 @@ export type NoInfer<A> = [A][A extends any ? 0 : never]
557
557
  * A value of type `Invariant<A>` cannot be assigned to `Invariant<B>` unless
558
558
  * `A` and `B` are the same type.
559
559
  *
560
- * **Example** (Invariant phantom type)
560
+ * **Example** (Defining an invariant phantom type)
561
561
  *
562
562
  * ```ts
563
563
  * import type { Types } from "effect"
@@ -625,7 +625,7 @@ export declare namespace Invariant {
625
625
  * `Covariant<A>` is assignable to `Covariant<B>` when `A extends B`, following
626
626
  * the subtype direction.
627
627
  *
628
- * **Example** (Covariant phantom type)
628
+ * **Example** (Defining a covariant phantom type)
629
629
  *
630
630
  * ```ts
631
631
  * import type { Types } from "effect"
@@ -693,7 +693,7 @@ export declare namespace Covariant {
693
693
  * `Contravariant<A>` is assignable to `Contravariant<B>` when `B extends A`,
694
694
  * following the supertype direction.
695
695
  *
696
- * **Example** (Contravariant phantom type)
696
+ * **Example** (Defining a contravariant phantom type)
697
697
  *
698
698
  * ```ts
699
699
  * import type { Types } from "effect"
@@ -96,7 +96,8 @@ import {
96
96
  TracerSpanLinks,
97
97
  TracerTimingEnabled
98
98
  } from "./references.ts"
99
- import { addSpanStackTrace, type ErrorWithStackTraceLimit, makeStackCleaner } from "./tracer.ts"
99
+ import { getStackTraceLimit, setStackTraceLimit } from "./stackTraceLimit.ts"
100
+ import { addSpanStackTrace, makeStackCleaner } from "./tracer.ts"
100
101
  import { version } from "./version.ts"
101
102
 
102
103
  // ----------------------------------------------------------------------------
@@ -314,9 +315,8 @@ export const causePrettyErrors = <E>(self: Cause.Cause<E>): Array<Error> => {
314
315
  const interrupts: Array<Cause.Interrupt> = []
315
316
  if (self.reasons.length === 0) return errors
316
317
 
317
- const prevStackLimit = (Error as ErrorWithStackTraceLimit).stackTraceLimit
318
- ;(Error as ErrorWithStackTraceLimit)
319
- .stackTraceLimit = 1
318
+ const prevStackLimit = getStackTraceLimit()
319
+ setStackTraceLimit(1)
320
320
 
321
321
  for (const failure of self.reasons) {
322
322
  if (failure._tag === "Interrupt") {
@@ -340,7 +340,7 @@ export const causePrettyErrors = <E>(self: Cause.Cause<E>): Array<Error> => {
340
340
  errors.push(causePrettyError(error, interrupts[0].annotations))
341
341
  }
342
342
 
343
- ;(Error as ErrorWithStackTraceLimit).stackTraceLimit = prevStackLimit
343
+ setStackTraceLimit(prevStackLimit)
344
344
  return errors
345
345
  }
346
346
 
@@ -933,6 +933,11 @@ export const succeedNone: Effect.Effect<Option.Option<never>> = succeed(
933
933
  Option.none()
934
934
  )
935
935
 
936
+ /** @internal */
937
+ export const transposeOption = <A = never, E = never, R = never>(
938
+ self: Option.Option<Effect.Effect<A, E, R>>
939
+ ): Effect.Effect<Option.Option<A>, E, R> => Option.isNone(self) ? succeedNone : map(self.value, Option.some)
940
+
936
941
  /** @internal */
937
942
  export const failCauseSync = <E>(
938
943
  evaluate: LazyArg<Cause.Cause<E>>
@@ -950,17 +955,24 @@ const void_: Effect.Effect<void> = succeed(void 0)
950
955
  export { void_ as void }
951
956
 
952
957
  /** @internal */
953
- const try_ = <A, E>(options: {
954
- try: LazyArg<A>
955
- catch: (error: unknown) => E
956
- }): Effect.Effect<A, E> =>
957
- suspend(() => {
958
+ const try_ = <A, E = Cause.UnknownError>(
959
+ options: {
960
+ readonly try: LazyArg<A>
961
+ readonly catch: (error: unknown) => E
962
+ } | LazyArg<A>
963
+ ): Effect.Effect<A, E> => {
964
+ const evaluate = typeof options === "function" ? options : options.try
965
+ const catcher = typeof options === "function"
966
+ ? ((cause: unknown) => new UnknownError(cause, "An error occurred in Effect.try"))
967
+ : options.catch
968
+ return suspend(() => {
958
969
  try {
959
- return succeed(internalCall(options.try))
970
+ return succeed(internalCall(evaluate))
960
971
  } catch (err) {
961
- return fail(internalCall(() => options.catch(err)))
972
+ return fail(internalCall(() => catcher(err)) as E)
962
973
  }
963
974
  })
975
+ }
964
976
  /** @internal */
965
977
  export { try_ as try }
966
978
 
@@ -987,15 +999,22 @@ export const tryPromise = <A, E = Cause.UnknownError>(
987
999
  ? ((cause: unknown) => new UnknownError(cause, "An error occurred in Effect.tryPromise"))
988
1000
  : options.catch
989
1001
  return callbackOptions<A, E>(function(resume, signal) {
1002
+ const failWithCatch = (cause: unknown) => {
1003
+ try {
1004
+ resume(fail(internalCall(() => catcher(cause)) as E))
1005
+ } catch (err) {
1006
+ resume(die(err))
1007
+ }
1008
+ }
990
1009
  try {
991
1010
  internalCall(() => f(signal!)).then(
992
1011
  (a) => resume(succeed(a)),
993
- (e) => resume(fail(internalCall(() => catcher(e)) as E))
1012
+ failWithCatch
994
1013
  )
995
1014
  } catch (err) {
996
- resume(fail(internalCall(() => catcher(err)) as E))
1015
+ failWithCatch(err)
997
1016
  }
998
- }, eval.length !== 0)
1017
+ }, f.length !== 0)
999
1018
  }
1000
1019
 
1001
1020
  /** @internal */
@@ -1138,10 +1157,10 @@ export const fn: typeof Effect.fn = function() {
1138
1157
  const name = nameFirst ? arguments[0] : "Effect.fn"
1139
1158
  const spanOptions = nameFirst ? arguments[1] : undefined
1140
1159
 
1141
- const prevLimit = globalThis.Error.stackTraceLimit
1142
- globalThis.Error.stackTraceLimit = 2
1160
+ const prevLimit = getStackTraceLimit()
1161
+ setStackTraceLimit(2)
1143
1162
  const defError = new globalThis.Error()
1144
- globalThis.Error.stackTraceLimit = prevLimit
1163
+ setStackTraceLimit(prevLimit)
1145
1164
 
1146
1165
  if (nameFirst) {
1147
1166
  return (body: Function | { readonly self: any }, ...pipeables: Array<Function>) =>
@@ -1181,10 +1200,10 @@ const makeFn = (
1181
1200
  if (!isEffect(result)) {
1182
1201
  return result
1183
1202
  }
1184
- const prevLimit = globalThis.Error.stackTraceLimit
1185
- globalThis.Error.stackTraceLimit = 2
1203
+ const prevLimit = getStackTraceLimit()
1204
+ setStackTraceLimit(2)
1186
1205
  const callError = new globalThis.Error()
1187
- globalThis.Error.stackTraceLimit = prevLimit
1206
+ setStackTraceLimit(prevLimit)
1188
1207
  return updateService(
1189
1208
  addSpan ?
1190
1209
  useSpan(name, spanOptions!, (span) => provideParentSpan(result, span)) :
@@ -382,6 +382,18 @@ function oneOf<T>(fc: typeof FastCheck, arbitraries: ReadonlyArray<FastCheck.Arb
382
382
  return arbitraries.length === 0 ? undefined : arbitraries.length === 1 ? arbitraries[0] : fc.oneof(...arbitraries)
383
383
  }
384
384
 
385
+ const finiteNumberConstraint: Constraint = {
386
+ noInfinity: true,
387
+ noNaN: true
388
+ }
389
+
390
+ function finiteNumberContext(ctx: Context): Context {
391
+ return {
392
+ ...ctx,
393
+ constraint: finiteNumberConstraint
394
+ }
395
+ }
396
+
385
397
  function reportChecks(report: MutableReport, checks: SchemaAST.Checks | undefined, path: ReadonlyArray<PropertyKey>) {
386
398
  function visit(check: SchemaAST.Check<any>, covered: boolean) {
387
399
  const arbitrary = check.annotations?.arbitrary
@@ -430,6 +442,9 @@ export function collectReport(ast: SchemaAST.AST, report: MutableReport) {
430
442
  case "Union":
431
443
  ast.types.forEach((type) => visit(type, path))
432
444
  break
445
+ case "TemplateLiteral":
446
+ ast.parts.forEach((part, i) => visit(SchemaAST.toEncoded(part), [...path, i]))
447
+ break
433
448
  case "Suspend":
434
449
  visit(ast.thunk(), path)
435
450
  break
@@ -605,8 +620,14 @@ function base(ast: SchemaAST.AST, path: ReadonlyArray<PropertyKey>): LazyArbitra
605
620
  return same((fc) => fc.oneof(fc.object(), fc.array(fc.anything())))
606
621
  case "Enum":
607
622
  return recur(SchemaAST.enumsToLiterals(ast), path)
608
- case "TemplateLiteral":
609
- return same((fc) => fc.stringMatching(SchemaAST.getTemplateLiteralRegExp(ast)))
623
+ case "TemplateLiteral": {
624
+ const parts = ast.parts.map((part, i) => recur(SchemaAST.toEncoded(part), [...path, i]))
625
+ return same((fc, ctx, recursionStack) =>
626
+ fc.tuple(...parts.map((part) => part(fc, finiteNumberContext(ctx), recursionStack))).map((segments) =>
627
+ segments.map((segment) => globalThis.String(segment)).join("")
628
+ )
629
+ )
630
+ }
610
631
  case "Arrays": {
611
632
  const elements = ast.elements.map((ast, i) => ({
612
633
  ast,
@@ -0,0 +1,26 @@
1
+ import * as Cause from "../../Cause.ts"
2
+ import * as SchemaIssue from "../../SchemaIssue.ts"
3
+
4
+ /** @internal */
5
+ export function getSchemaIssue(cause: Cause.Cause<SchemaIssue.Issue>): SchemaIssue.Issue | undefined {
6
+ let issue: SchemaIssue.Issue | undefined
7
+ for (const reason of cause.reasons) {
8
+ if (!Cause.isFailReason(reason) || !SchemaIssue.isIssue(reason.error)) {
9
+ return undefined
10
+ }
11
+ issue ??= reason.error
12
+ }
13
+ return issue
14
+ }
15
+
16
+ /** @internal */
17
+ export function getSchemaIssueOrThrow(
18
+ cause: Cause.Cause<SchemaIssue.Issue>,
19
+ message: string
20
+ ): SchemaIssue.Issue {
21
+ const issue = getSchemaIssue(cause)
22
+ if (issue === undefined) {
23
+ throw new Error(message, { cause })
24
+ }
25
+ return issue
26
+ }
@@ -1,5 +1,7 @@
1
+ import * as Cause from "../../Cause.ts"
2
+ import * as Data from "../../Data.ts"
1
3
  import * as Effect from "../../Effect.ts"
2
- import { flow } from "../../Function.ts"
4
+ import * as Exit from "../../Exit.ts"
3
5
  import * as Pipeable from "../../Pipeable.ts"
4
6
  import type * as Schema from "../../Schema.ts"
5
7
  import * as SchemaAST from "../../SchemaAST.ts"
@@ -33,7 +35,8 @@ export function make<S extends Schema.Top>(ast: S["ast"], options?: object): S {
33
35
  }
34
36
  self.ast = ast
35
37
  self.rebuild = (ast: SchemaAST.AST) => make(ast, options)
36
- self.makeEffect = flow(SchemaParser.makeEffect(self), Effect.mapErrorEager((issue) => new SchemaError(issue)))
38
+ self.makeEffect = (input: S["~type.make.in"], options?: Schema.MakeOptions) =>
39
+ mapSchemaIssueEffect(SchemaParser.makeEffect(self)(input, options))
37
40
  self.make = SchemaParser.make(self)
38
41
  self.makeOption = SchemaParser.makeOption(self)
39
42
  return self
@@ -42,23 +45,46 @@ export function make<S extends Schema.Top>(ast: S["ast"], options?: object): S {
42
45
  /** @internal */
43
46
  export const SchemaErrorTypeId = "~effect/Schema/SchemaError"
44
47
 
45
- // not internal
46
- export class SchemaError {
47
- readonly [SchemaErrorTypeId] = SchemaErrorTypeId
48
- readonly _tag = "SchemaError"
49
- readonly name: string = "SchemaError"
48
+ // purposefully not internal
49
+ export class SchemaError extends Data.TaggedError("SchemaError")<{
50
50
  readonly issue: Issue
51
+ }> {
52
+ readonly [SchemaErrorTypeId]: typeof SchemaErrorTypeId = SchemaErrorTypeId
51
53
  constructor(issue: Issue) {
52
- this.issue = issue
54
+ super({ issue })
53
55
  }
54
- get message() {
56
+ override get message() {
55
57
  return this.issue.toString()
56
58
  }
57
- toString() {
59
+ override toString() {
58
60
  return `SchemaError(${this.message})`
59
61
  }
60
62
  }
61
63
 
64
+ /** @internal */
65
+ export function mapSchemaIssueEffect<A, R>(
66
+ self: Effect.Effect<A, Issue, R>
67
+ ): Effect.Effect<A, SchemaError, R> {
68
+ return Effect.catchCause(
69
+ self,
70
+ (cause) => Effect.failCauseSync(() => Cause.map(cause, (issue) => new SchemaError(issue)))
71
+ )
72
+ }
73
+
74
+ /** @internal */
75
+ export function mapSchemaErrorEffect<A, R>(
76
+ self: Effect.Effect<A, SchemaError, R>
77
+ ): Effect.Effect<A, Issue, R> {
78
+ return Effect.catchCause(self, (cause) => Effect.failCauseSync(() => Cause.map(cause, (error) => error.issue)))
79
+ }
80
+
81
+ /** @internal */
82
+ export function mapSchemaIssueExit<A>(exit: Exit.Exit<A, Issue>): Exit.Exit<A, SchemaError> {
83
+ return Exit.isSuccess(exit)
84
+ ? Exit.succeed(exit.value)
85
+ : Exit.failCause(Cause.map(exit.cause, (issue) => new SchemaError(issue)))
86
+ }
87
+
62
88
  /** @internal */
63
89
  export const jsonReorder = makeReorder(getJsonPriority)
64
90