effect 3.10.19 → 3.11.0

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 (167) hide show
  1. package/dist/cjs/BigDecimal.js +125 -24
  2. package/dist/cjs/BigDecimal.js.map +1 -1
  3. package/dist/cjs/Channel.js +44 -4
  4. package/dist/cjs/Channel.js.map +1 -1
  5. package/dist/cjs/Config.js +8 -1
  6. package/dist/cjs/Config.js.map +1 -1
  7. package/dist/cjs/Context.js +26 -1
  8. package/dist/cjs/Context.js.map +1 -1
  9. package/dist/cjs/Cron.js +75 -67
  10. package/dist/cjs/Cron.js.map +1 -1
  11. package/dist/cjs/DateTime.js +114 -664
  12. package/dist/cjs/DateTime.js.map +1 -1
  13. package/dist/cjs/Effect.js +82 -4
  14. package/dist/cjs/Effect.js.map +1 -1
  15. package/dist/cjs/Inspectable.js +8 -4
  16. package/dist/cjs/Inspectable.js.map +1 -1
  17. package/dist/cjs/JSONSchema.js.map +1 -1
  18. package/dist/cjs/Micro.js +1099 -1072
  19. package/dist/cjs/Micro.js.map +1 -1
  20. package/dist/cjs/STM.js.map +1 -1
  21. package/dist/cjs/Schema.js +57 -8
  22. package/dist/cjs/Schema.js.map +1 -1
  23. package/dist/cjs/Sink.js +9 -1
  24. package/dist/cjs/Sink.js.map +1 -1
  25. package/dist/cjs/Stream.js +25 -7
  26. package/dist/cjs/Stream.js.map +1 -1
  27. package/dist/cjs/Utils.js +7 -1
  28. package/dist/cjs/Utils.js.map +1 -1
  29. package/dist/cjs/internal/channel/channelExecutor.js +5 -9
  30. package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
  31. package/dist/cjs/internal/channel.js +156 -130
  32. package/dist/cjs/internal/channel.js.map +1 -1
  33. package/dist/cjs/internal/config.js +13 -4
  34. package/dist/cjs/internal/config.js.map +1 -1
  35. package/dist/cjs/internal/context.js +46 -3
  36. package/dist/cjs/internal/context.js.map +1 -1
  37. package/dist/cjs/internal/dateTime.js +747 -0
  38. package/dist/cjs/internal/dateTime.js.map +1 -0
  39. package/dist/cjs/internal/fiberRuntime.js +34 -11
  40. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  41. package/dist/cjs/internal/groupBy.js +9 -3
  42. package/dist/cjs/internal/groupBy.js.map +1 -1
  43. package/dist/cjs/internal/layer.js +1 -1
  44. package/dist/cjs/internal/layer.js.map +1 -1
  45. package/dist/cjs/internal/mailbox.js +1 -1
  46. package/dist/cjs/internal/mailbox.js.map +1 -1
  47. package/dist/cjs/internal/sink.js +25 -21
  48. package/dist/cjs/internal/sink.js.map +1 -1
  49. package/dist/cjs/internal/stream.js +70 -71
  50. package/dist/cjs/internal/stream.js.map +1 -1
  51. package/dist/cjs/internal/version.js +1 -1
  52. package/dist/cjs/internal/version.js.map +1 -1
  53. package/dist/dts/BigDecimal.d.ts +56 -1
  54. package/dist/dts/BigDecimal.d.ts.map +1 -1
  55. package/dist/dts/Channel.d.ts +66 -5
  56. package/dist/dts/Channel.d.ts.map +1 -1
  57. package/dist/dts/Config.d.ts +23 -1
  58. package/dist/dts/Config.d.ts.map +1 -1
  59. package/dist/dts/Context.d.ts +111 -0
  60. package/dist/dts/Context.d.ts.map +1 -1
  61. package/dist/dts/Cron.d.ts +15 -6
  62. package/dist/dts/Cron.d.ts.map +1 -1
  63. package/dist/dts/DateTime.d.ts +40 -49
  64. package/dist/dts/DateTime.d.ts.map +1 -1
  65. package/dist/dts/Effect.d.ts +88 -1
  66. package/dist/dts/Effect.d.ts.map +1 -1
  67. package/dist/dts/Inspectable.d.ts.map +1 -1
  68. package/dist/dts/JSONSchema.d.ts +1 -0
  69. package/dist/dts/JSONSchema.d.ts.map +1 -1
  70. package/dist/dts/Micro.d.ts +875 -872
  71. package/dist/dts/Micro.d.ts.map +1 -1
  72. package/dist/dts/STM.d.ts +2 -0
  73. package/dist/dts/STM.d.ts.map +1 -1
  74. package/dist/dts/Schema.d.ts +32 -0
  75. package/dist/dts/Schema.d.ts.map +1 -1
  76. package/dist/dts/Sink.d.ts +8 -0
  77. package/dist/dts/Sink.d.ts.map +1 -1
  78. package/dist/dts/Stream.d.ts +50 -32
  79. package/dist/dts/Stream.d.ts.map +1 -1
  80. package/dist/dts/Utils.d.ts +4 -0
  81. package/dist/dts/Utils.d.ts.map +1 -1
  82. package/dist/dts/internal/context.d.ts +1 -1
  83. package/dist/dts/internal/context.d.ts.map +1 -1
  84. package/dist/dts/internal/dateTime.d.ts +2 -0
  85. package/dist/dts/internal/dateTime.d.ts.map +1 -0
  86. package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
  87. package/dist/dts/internal/stream.d.ts.map +1 -1
  88. package/dist/esm/BigDecimal.js +119 -20
  89. package/dist/esm/BigDecimal.js.map +1 -1
  90. package/dist/esm/Channel.js +42 -2
  91. package/dist/esm/Channel.js.map +1 -1
  92. package/dist/esm/Config.js +7 -0
  93. package/dist/esm/Config.js.map +1 -1
  94. package/dist/esm/Context.js +25 -0
  95. package/dist/esm/Context.js.map +1 -1
  96. package/dist/esm/Cron.js +75 -67
  97. package/dist/esm/Cron.js.map +1 -1
  98. package/dist/esm/DateTime.js +112 -627
  99. package/dist/esm/DateTime.js.map +1 -1
  100. package/dist/esm/Effect.js +77 -0
  101. package/dist/esm/Effect.js.map +1 -1
  102. package/dist/esm/Inspectable.js +8 -4
  103. package/dist/esm/Inspectable.js.map +1 -1
  104. package/dist/esm/JSONSchema.js.map +1 -1
  105. package/dist/esm/Micro.js +1077 -1047
  106. package/dist/esm/Micro.js.map +1 -1
  107. package/dist/esm/STM.js.map +1 -1
  108. package/dist/esm/Schema.js +54 -0
  109. package/dist/esm/Schema.js.map +1 -1
  110. package/dist/esm/Sink.js +8 -0
  111. package/dist/esm/Sink.js.map +1 -1
  112. package/dist/esm/Stream.js +23 -5
  113. package/dist/esm/Stream.js.map +1 -1
  114. package/dist/esm/Utils.js +5 -0
  115. package/dist/esm/Utils.js.map +1 -1
  116. package/dist/esm/internal/channel/channelExecutor.js +5 -7
  117. package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
  118. package/dist/esm/internal/channel.js +152 -129
  119. package/dist/esm/internal/channel.js.map +1 -1
  120. package/dist/esm/internal/config.js +11 -3
  121. package/dist/esm/internal/config.js.map +1 -1
  122. package/dist/esm/internal/context.js +42 -2
  123. package/dist/esm/internal/context.js.map +1 -1
  124. package/dist/esm/internal/dateTime.js +704 -0
  125. package/dist/esm/internal/dateTime.js.map +1 -0
  126. package/dist/esm/internal/fiberRuntime.js +31 -9
  127. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  128. package/dist/esm/internal/groupBy.js +9 -3
  129. package/dist/esm/internal/groupBy.js.map +1 -1
  130. package/dist/esm/internal/layer.js +1 -1
  131. package/dist/esm/internal/layer.js.map +1 -1
  132. package/dist/esm/internal/mailbox.js +1 -1
  133. package/dist/esm/internal/mailbox.js.map +1 -1
  134. package/dist/esm/internal/sink.js +23 -20
  135. package/dist/esm/internal/sink.js.map +1 -1
  136. package/dist/esm/internal/stream.js +66 -69
  137. package/dist/esm/internal/stream.js.map +1 -1
  138. package/dist/esm/internal/version.js +1 -1
  139. package/dist/esm/internal/version.js.map +1 -1
  140. package/package.json +1 -1
  141. package/src/BigDecimal.ts +131 -21
  142. package/src/Channel.ts +81 -5
  143. package/src/Config.ts +24 -1
  144. package/src/Context.ts +119 -0
  145. package/src/Cron.ts +85 -68
  146. package/src/DateTime.ts +155 -757
  147. package/src/Effect.ts +340 -1
  148. package/src/Inspectable.ts +11 -7
  149. package/src/JSONSchema.ts +1 -0
  150. package/src/Micro.ts +2005 -1757
  151. package/src/STM.ts +2 -0
  152. package/src/Schema.ts +60 -0
  153. package/src/Sink.ts +11 -0
  154. package/src/Stream.ts +55 -44
  155. package/src/Utils.ts +8 -0
  156. package/src/internal/channel/channelExecutor.ts +37 -33
  157. package/src/internal/channel.ts +504 -467
  158. package/src/internal/config.ts +18 -6
  159. package/src/internal/context.ts +56 -4
  160. package/src/internal/dateTime.ts +1126 -0
  161. package/src/internal/fiberRuntime.ts +35 -16
  162. package/src/internal/groupBy.ts +13 -22
  163. package/src/internal/layer.ts +5 -8
  164. package/src/internal/mailbox.ts +6 -4
  165. package/src/internal/sink.ts +55 -35
  166. package/src/internal/stream.ts +299 -299
  167. package/src/internal/version.ts +1 -1
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.10.19";
1
+ let moduleVersion = "3.11.0";
2
2
  export const getCurrentVersion = () => moduleVersion;
3
3
  export const setCurrentVersion = version => {
4
4
  moduleVersion = version;
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":["moduleVersion","getCurrentVersion","setCurrentVersion","version"],"sources":["../../../src/internal/version.ts"],"sourcesContent":[null],"mappings":"AAAA,IAAIA,aAAa,GAAG,SAAS;AAE7B,OAAO,MAAMC,iBAAiB,GAAGA,CAAA,KAAMD,aAAa;AAEpD,OAAO,MAAME,iBAAiB,GAAIC,OAAe,IAAI;EACnDH,aAAa,GAAGG,OAAO;AACzB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"version.js","names":["moduleVersion","getCurrentVersion","setCurrentVersion","version"],"sources":["../../../src/internal/version.ts"],"sourcesContent":[null],"mappings":"AAAA,IAAIA,aAAa,GAAG,QAAQ;AAE5B,OAAO,MAAMC,iBAAiB,GAAGA,CAAA,KAAMD,aAAa;AAEpD,OAAO,MAAME,iBAAiB,GAAIC,OAAe,IAAI;EACnDH,aAAa,GAAGG,OAAO;AACzB,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect",
3
- "version": "3.10.19",
3
+ "version": "3.11.0",
4
4
  "description": "The missing standard library for TypeScript, for writing production-grade software.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/BigDecimal.ts CHANGED
@@ -26,6 +26,7 @@ import { type Pipeable, pipeArguments } from "./Pipeable.js"
26
26
  import { hasProperty } from "./Predicate.js"
27
27
 
28
28
  const DEFAULT_PRECISION = 100
29
+ const FINITE_INT_REGEX = /^[+-]?\d+$/
29
30
 
30
31
  /**
31
32
  * @since 2.0.0
@@ -1473,6 +1474,8 @@ export const fromBigInt = (n: bigint): BigDecimal => make(n, 0)
1473
1474
  * It is not recommended to convert a floating point number to a decimal directly,
1474
1475
  * as the floating point representation may be unexpected.
1475
1476
  *
1477
+ * Throws a `RangeError` if the number is not finite (`NaN`, `+Infinity` or `-Infinity`).
1478
+ *
1476
1479
  * @param value - The `number` value to create a `BigDecimal` from.
1477
1480
  *
1478
1481
  * @example
@@ -1483,12 +1486,61 @@ export const fromBigInt = (n: bigint): BigDecimal => make(n, 0)
1483
1486
  * assert.deepStrictEqual(fromNumber(123.456), make(123456n, 3))
1484
1487
  * ```
1485
1488
  *
1489
+ * @since 3.11.0
1490
+ * @category constructors
1491
+ */
1492
+ export const unsafeFromNumber = (n: number): BigDecimal =>
1493
+ Option.getOrThrowWith(safeFromNumber(n), () => new RangeError(`Number must be finite, got ${n}`))
1494
+
1495
+ /**
1496
+ * Creates a `BigDecimal` from a `number` value.
1497
+ *
1498
+ * It is not recommended to convert a floating point number to a decimal directly,
1499
+ * as the floating point representation may be unexpected.
1500
+ *
1501
+ * Throws a `RangeError` if the number is not finite (`NaN`, `+Infinity` or `-Infinity`).
1502
+ *
1503
+ * @param value - The `number` value to create a `BigDecimal` from.
1504
+ *
1486
1505
  * @since 2.0.0
1487
1506
  * @category constructors
1507
+ * @deprecated Use {@link unsafeFromNumber} instead.
1488
1508
  */
1489
- export const fromNumber = (n: number): BigDecimal => {
1490
- const [lead, trail = ""] = `${n}`.split(".")
1491
- return make(BigInt(`${lead}${trail}`), trail.length)
1509
+ export const fromNumber: (n: number) => BigDecimal = unsafeFromNumber
1510
+
1511
+ /**
1512
+ * Creates a `BigDecimal` from a `number` value.
1513
+ *
1514
+ * It is not recommended to convert a floating point number to a decimal directly,
1515
+ * as the floating point representation may be unexpected.
1516
+ *
1517
+ * Returns `None` if the number is not finite (`NaN`, `+Infinity` or `-Infinity`).
1518
+ *
1519
+ * @param n - The `number` value to create a `BigDecimal` from.
1520
+ *
1521
+ * @example
1522
+ * import { BigDecimal, Option } from "effect"
1523
+ *
1524
+ * assert.deepStrictEqual(BigDecimal.safeFromNumber(123), Option.some(BigDecimal.make(123n, 0)))
1525
+ * assert.deepStrictEqual(BigDecimal.safeFromNumber(123.456), Option.some(BigDecimal.make(123456n, 3)))
1526
+ * assert.deepStrictEqual(BigDecimal.safeFromNumber(Infinity), Option.none())
1527
+ *
1528
+ * @since 3.11.0
1529
+ * @category constructors
1530
+ */
1531
+ export const safeFromNumber = (n: number): Option.Option<BigDecimal> => {
1532
+ // TODO: Rename this to `fromNumber` after removing the current, unsafe implementation of `fromNumber`.
1533
+ if (!Number.isFinite(n)) {
1534
+ return Option.none()
1535
+ }
1536
+
1537
+ const string = `${n}`
1538
+ if (string.includes("e")) {
1539
+ return fromString(string)
1540
+ }
1541
+
1542
+ const [lead, trail = ""] = string.split(".")
1543
+ return Option.some(make(BigInt(`${lead}${trail}`), trail.length))
1492
1544
  }
1493
1545
 
1494
1546
  /**
@@ -1509,26 +1561,44 @@ export const fromNumber = (n: number): BigDecimal => {
1509
1561
  * @category constructors
1510
1562
  */
1511
1563
  export const fromString = (s: string): Option.Option<BigDecimal> => {
1512
- let digits: string
1513
- let scale: number
1564
+ if (s === "") {
1565
+ return Option.some(zero)
1566
+ }
1514
1567
 
1515
- const dot = s.search(/\./)
1568
+ let base: string
1569
+ let exp: number
1570
+ const seperator = s.search(/[eE]/)
1571
+ if (seperator !== -1) {
1572
+ const trail = s.slice(seperator + 1)
1573
+ base = s.slice(0, seperator)
1574
+ exp = Number(trail)
1575
+ if (base === "" || !Number.isSafeInteger(exp) || !FINITE_INT_REGEX.test(trail)) {
1576
+ return Option.none()
1577
+ }
1578
+ } else {
1579
+ base = s
1580
+ exp = 0
1581
+ }
1582
+
1583
+ let digits: string
1584
+ let offset: number
1585
+ const dot = base.search(/\./)
1516
1586
  if (dot !== -1) {
1517
- const lead = s.slice(0, dot)
1518
- const trail = s.slice(dot + 1)
1587
+ const lead = base.slice(0, dot)
1588
+ const trail = base.slice(dot + 1)
1519
1589
  digits = `${lead}${trail}`
1520
- scale = trail.length
1590
+ offset = trail.length
1521
1591
  } else {
1522
- digits = s
1523
- scale = 0
1592
+ digits = base
1593
+ offset = 0
1524
1594
  }
1525
1595
 
1526
- if (digits === "") {
1527
- // TODO: This mimics the BigInt constructor behavior. Should this be `Option.none()`?
1528
- return Option.some(zero)
1596
+ if (!FINITE_INT_REGEX.test(digits)) {
1597
+ return Option.none()
1529
1598
  }
1530
1599
 
1531
- if (!/^(?:\+|-)?\d+$/.test(digits)) {
1600
+ const scale = offset - exp
1601
+ if (!Number.isSafeInteger(scale)) {
1532
1602
  return Option.none()
1533
1603
  }
1534
1604
 
@@ -1558,7 +1628,10 @@ export const unsafeFromString = (s: string): BigDecimal =>
1558
1628
  /**
1559
1629
  * Formats a given `BigDecimal` as a `string`.
1560
1630
  *
1561
- * @param normalized - The `BigDecimal` to format.
1631
+ * If the scale of the `BigDecimal` is greater than or equal to 16, the `BigDecimal` will
1632
+ * be formatted in scientific notation.
1633
+ *
1634
+ * @param n - The `BigDecimal` to format.
1562
1635
  *
1563
1636
  * @example
1564
1637
  * ```ts
@@ -1573,17 +1646,22 @@ export const unsafeFromString = (s: string): BigDecimal =>
1573
1646
  * @category conversions
1574
1647
  */
1575
1648
  export const format = (n: BigDecimal): string => {
1576
- const negative = n.value < bigint0
1577
- const absolute = negative ? `${n.value}`.substring(1) : `${n.value}`
1649
+ const normalized = normalize(n)
1650
+ if (Math.abs(normalized.scale) >= 16) {
1651
+ return toExponential(normalized)
1652
+ }
1653
+
1654
+ const negative = normalized.value < bigint0
1655
+ const absolute = negative ? `${normalized.value}`.substring(1) : `${normalized.value}`
1578
1656
 
1579
1657
  let before: string
1580
1658
  let after: string
1581
1659
 
1582
- if (n.scale >= absolute.length) {
1660
+ if (normalized.scale >= absolute.length) {
1583
1661
  before = "0"
1584
- after = "0".repeat(n.scale - absolute.length) + absolute
1662
+ after = "0".repeat(normalized.scale - absolute.length) + absolute
1585
1663
  } else {
1586
- const location = absolute.length - n.scale
1664
+ const location = absolute.length - normalized.scale
1587
1665
  if (location > absolute.length) {
1588
1666
  const zeros = location - absolute.length
1589
1667
  before = `${absolute}${"0".repeat(zeros)}`
@@ -1598,6 +1676,38 @@ export const format = (n: BigDecimal): string => {
1598
1676
  return negative ? `-${complete}` : complete
1599
1677
  }
1600
1678
 
1679
+ /**
1680
+ * Formats a given `BigDecimal` as a `string` in scientific notation.
1681
+ *
1682
+ * @param n - The `BigDecimal` to format.
1683
+ *
1684
+ * @example
1685
+ * import { toExponential, make } from "effect/BigDecimal"
1686
+ *
1687
+ * assert.deepStrictEqual(toExponential(make(123456n, -5)), "1.23456e+10")
1688
+ *
1689
+ * @since 3.11.0
1690
+ * @category conversions
1691
+ */
1692
+ export const toExponential = (n: BigDecimal): string => {
1693
+ if (isZero(n)) {
1694
+ return "0e+0"
1695
+ }
1696
+
1697
+ const normalized = normalize(n)
1698
+ const digits = `${abs(normalized).value}`
1699
+ const head = digits.slice(0, 1)
1700
+ const tail = digits.slice(1)
1701
+
1702
+ let output = `${isNegative(normalized) ? "-" : ""}${head}`
1703
+ if (tail !== "") {
1704
+ output += `.${tail}`
1705
+ }
1706
+
1707
+ const exp = tail.length - normalized.scale
1708
+ return `${output}e${exp >= 0 ? "+" : ""}${exp}`
1709
+ }
1710
+
1601
1711
  /**
1602
1712
  * Converts a `BigDecimal` to a `number`.
1603
1713
  *
package/src/Channel.ts CHANGED
@@ -2578,7 +2578,7 @@ export const repeated: <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
2578
2578
  */
2579
2579
  export const run: <OutErr, InErr, OutDone, InDone, Env>(
2580
2580
  self: Channel<never, unknown, OutErr, InErr, OutDone, InDone, Env>
2581
- ) => Effect.Effect<OutDone, OutErr, Exclude<Env, Scope.Scope>> = channel.run
2581
+ ) => Effect.Effect<OutDone, OutErr, Env> = channel.run
2582
2582
 
2583
2583
  /**
2584
2584
  * Run the channel until it finishes with a done value or fails with an error
@@ -2591,7 +2591,7 @@ export const run: <OutErr, InErr, OutDone, InDone, Env>(
2591
2591
  */
2592
2592
  export const runCollect: <OutElem, OutErr, InErr, OutDone, InDone, Env>(
2593
2593
  self: Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, Env>
2594
- ) => Effect.Effect<[Chunk.Chunk<OutElem>, OutDone], OutErr, Exclude<Env, Scope.Scope>> = channel.runCollect
2594
+ ) => Effect.Effect<[Chunk.Chunk<OutElem>, OutDone], OutErr, Env> = channel.runCollect
2595
2595
 
2596
2596
  /**
2597
2597
  * Runs a channel until the end is received.
@@ -2601,7 +2601,21 @@ export const runCollect: <OutElem, OutErr, InErr, OutDone, InDone, Env>(
2601
2601
  */
2602
2602
  export const runDrain: <OutElem, OutErr, InErr, OutDone, InDone, Env>(
2603
2603
  self: Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, Env>
2604
- ) => Effect.Effect<OutDone, OutErr, Exclude<Env, Scope.Scope>> = channel.runDrain
2604
+ ) => Effect.Effect<OutDone, OutErr, Env> = channel.runDrain
2605
+
2606
+ /**
2607
+ * Run the channel until it finishes with a done value or fails with an error.
2608
+ * The channel must not read any input or write any output.
2609
+ *
2610
+ * Closing the channel, which includes execution of all the finalizers
2611
+ * attached to the channel will be added to the current scope as a finalizer.
2612
+ *
2613
+ * @since 3.11.0
2614
+ * @category destructors
2615
+ */
2616
+ export const runScoped: <OutErr, InErr, OutDone, InDone, Env>(
2617
+ self: Channel<never, unknown, OutErr, InErr, OutDone, InDone, Env>
2618
+ ) => Effect.Effect<OutDone, OutErr, Env | Scope.Scope> = channel.runScoped
2605
2619
 
2606
2620
  /**
2607
2621
  * Use a scoped effect to emit an output element.
@@ -2613,6 +2627,18 @@ export const scoped: <A, E, R>(
2613
2627
  effect: Effect.Effect<A, E, R>
2614
2628
  ) => Channel<A, unknown, E, unknown, unknown, unknown, Exclude<R, Scope.Scope>> = channel.scoped
2615
2629
 
2630
+ /**
2631
+ * Use a function that receives a scope and returns an effect to emit an output
2632
+ * element. The output element will be the result of the returned effect, if
2633
+ * successful.
2634
+ *
2635
+ * @since 3.11.0
2636
+ * @category constructors
2637
+ */
2638
+ export const scopedWith: <A, E, R>(
2639
+ f: (scope: Scope.Scope) => Effect.Effect<A, E, R>
2640
+ ) => Channel<A, unknown, E, unknown, unknown, unknown, R> = channel.scopedWith
2641
+
2616
2642
  /**
2617
2643
  * Splits strings on newlines. Handles both Windows newlines (`\r\n`) and UNIX
2618
2644
  * newlines (`\n`).
@@ -2682,6 +2708,43 @@ export const toPull: <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
2682
2708
  ) => Effect.Effect<Effect.Effect<Either.Either<OutElem, OutDone>, OutErr, Env>, never, Scope.Scope | Env> =
2683
2709
  channel.toPull
2684
2710
 
2711
+ /**
2712
+ * Returns an `Effect` that can be used to repeatedly pull elements from the
2713
+ * constructed `Channel` within the provided `Scope`. The pull effect fails
2714
+ * with the channel's failure in case the channel fails, or returns either the
2715
+ * channel's done value or an emitted element.
2716
+ *
2717
+ * @since 3.11.0
2718
+ * @category destructors
2719
+ */
2720
+ export const toPullIn: {
2721
+ /**
2722
+ * Returns an `Effect` that can be used to repeatedly pull elements from the
2723
+ * constructed `Channel` within the provided `Scope`. The pull effect fails
2724
+ * with the channel's failure in case the channel fails, or returns either the
2725
+ * channel's done value or an emitted element.
2726
+ *
2727
+ * @since 3.11.0
2728
+ * @category destructors
2729
+ */
2730
+ (scope: Scope.Scope): <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
2731
+ self: Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>
2732
+ ) => Effect.Effect<Effect.Effect<Either.Either<OutElem, OutDone>, OutErr, Env>, never, Env>
2733
+ /**
2734
+ * Returns an `Effect` that can be used to repeatedly pull elements from the
2735
+ * constructed `Channel` within the provided `Scope`. The pull effect fails
2736
+ * with the channel's failure in case the channel fails, or returns either the
2737
+ * channel's done value or an emitted element.
2738
+ *
2739
+ * @since 3.11.0
2740
+ * @category destructors
2741
+ */
2742
+ <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
2743
+ self: Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>,
2744
+ scope: Scope.Scope
2745
+ ): Effect.Effect<Effect.Effect<Either.Either<OutElem, OutDone>, OutErr, Env>, never, Env>
2746
+ } = channel.toPullIn
2747
+
2685
2748
  /**
2686
2749
  * Converts a `Channel` to a `Queue`.
2687
2750
  *
@@ -2721,7 +2784,8 @@ export {
2721
2784
  }
2722
2785
 
2723
2786
  /**
2724
- * Makes a channel from an effect that returns a channel in case of success.
2787
+ * Constructs a `Channel` from an effect that will result in a `Channel` if
2788
+ * successful.
2725
2789
  *
2726
2790
  * @since 2.0.0
2727
2791
  * @category constructors
@@ -2731,7 +2795,8 @@ export const unwrap: <OutElem, InElem, OutErr, InErr, OutDone, InDone, R2, E, R>
2731
2795
  ) => Channel<OutElem, InElem, E | OutErr, InErr, OutDone, InDone, R | R2> = channel.unwrap
2732
2796
 
2733
2797
  /**
2734
- * Makes a channel from a managed that returns a channel in case of success.
2798
+ * Constructs a `Channel` from a scoped effect that will result in a
2799
+ * `Channel` if successful.
2735
2800
  *
2736
2801
  * @since 2.0.0
2737
2802
  * @category constructors
@@ -2740,6 +2805,17 @@ export const unwrapScoped: <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env
2740
2805
  self: Effect.Effect<Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>, E, R>
2741
2806
  ) => Channel<OutElem, InElem, E | OutErr, InErr, OutDone, InDone, Env | Exclude<R, Scope.Scope>> = channel.unwrapScoped
2742
2807
 
2808
+ /**
2809
+ * Constructs a `Channel` from a function which receives a `Scope` and returns
2810
+ * an effect that will result in a `Channel` if successful.
2811
+ *
2812
+ * @since 3.11.0
2813
+ * @category constructors
2814
+ */
2815
+ export const unwrapScopedWith: <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env, E, R>(
2816
+ f: (scope: Scope.Scope) => Effect.Effect<Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>, E, R>
2817
+ ) => Channel<OutElem, InElem, E | OutErr, InErr, OutDone, InDone, R | Env> = channel.unwrapScopedWith
2818
+
2743
2819
  /**
2744
2820
  * Updates a service in the context of this channel.
2745
2821
  *
package/src/Config.ts CHANGED
@@ -128,6 +128,14 @@ export const array: <A>(config: Config<A>, name?: string) => Config<Array<A>> =
128
128
  */
129
129
  export const boolean: (name?: string) => Config<boolean> = internal.boolean
130
130
 
131
+ /**
132
+ * Constructs a config for a URL value.
133
+ *
134
+ * @since 3.11.0
135
+ * @category constructors
136
+ */
137
+ export const url: (name?: string) => Config<URL> = internal.url
138
+
131
139
  /**
132
140
  * Constructs a config for a sequence of values.
133
141
  *
@@ -443,7 +451,22 @@ export const secret: (name?: string) => Config<Secret.Secret> = internal.secret
443
451
  * @since 2.0.0
444
452
  * @category constructors
445
453
  */
446
- export const redacted: (name?: string) => Config<Redacted.Redacted> = internal.redacted
454
+ export const redacted: {
455
+ /**
456
+ * Constructs a config for a redacted value.
457
+ *
458
+ * @since 2.0.0
459
+ * @category constructors
460
+ */
461
+ (name?: string): Config<Redacted.Redacted>
462
+ /**
463
+ * Constructs a config for a redacted value.
464
+ *
465
+ * @since 2.0.0
466
+ * @category constructors
467
+ */
468
+ <A>(config: Config<A>): Config<Redacted.Redacted<A>>
469
+ } = internal.redacted
447
470
 
448
471
  /**
449
472
  * Constructs a config for a sequence of values.
package/src/Context.ts CHANGED
@@ -45,6 +45,38 @@ export interface Tag<in out Id, in out Value> extends Pipeable, Inspectable {
45
45
  [Unify.ignoreSymbol]?: TagUnifyIgnore
46
46
  }
47
47
 
48
+ const ReferenceTypeId: unique symbol = internal.ReferenceTypeId
49
+
50
+ /**
51
+ * @since 3.11.0
52
+ * @category symbol
53
+ */
54
+ export type ReferenceTypeId = typeof ReferenceTypeId
55
+
56
+ /**
57
+ * @since 3.11.0
58
+ * @category models
59
+ */
60
+ export interface Reference<in out Id, in out Value> extends Pipeable, Inspectable {
61
+ readonly [ReferenceTypeId]: ReferenceTypeId
62
+ readonly defaultValue: () => Value
63
+
64
+ readonly _op: "Tag"
65
+ readonly Service: Value
66
+ readonly Identifier: Id
67
+ readonly [TagTypeId]: {
68
+ readonly _Service: Types.Invariant<Value>
69
+ readonly _Identifier: Types.Invariant<Id>
70
+ }
71
+ of(self: Value): Value
72
+ context(self: Value): Context<Id>
73
+ readonly stack?: string | undefined
74
+ readonly key: string
75
+ [Unify.typeSymbol]?: unknown
76
+ [Unify.unifySymbol]?: TagUnify<this>
77
+ [Unify.ignoreSymbol]?: TagUnifyIgnore
78
+ }
79
+
48
80
  /**
49
81
  * @since 2.0.0
50
82
  * @category models
@@ -63,6 +95,14 @@ export interface TagClass<Self, Id, Type> extends Tag<Self, Type> {
63
95
  new(_: never): TagClassShape<Id, Type>
64
96
  }
65
97
 
98
+ /**
99
+ * @since 3.11.0
100
+ * @category models
101
+ */
102
+ export interface ReferenceClass<Self, Id, Type> extends Reference<Self, Type> {
103
+ new(_: never): TagClassShape<Id, Type>
104
+ }
105
+
66
106
  /**
67
107
  * @category models
68
108
  * @since 2.0.0
@@ -178,6 +218,16 @@ export const isContext: (input: unknown) => input is Context<never> = internal.i
178
218
  */
179
219
  export const isTag: (input: unknown) => input is Tag<any, any> = internal.isTag
180
220
 
221
+ /**
222
+ * Checks if the provided argument is a `Reference`.
223
+ *
224
+ * @param input - The value to be checked if it is a `Reference`.
225
+ * @since 3.11.0
226
+ * @category guards
227
+ * @experimental
228
+ */
229
+ export const isReference: (u: unknown) => u is Reference<any, any> = internal.isReference
230
+
181
231
  /**
182
232
  * Returns an empty `Context`.
183
233
  *
@@ -319,6 +369,31 @@ export const add: {
319
369
  * @category getters
320
370
  */
321
371
  export const get: {
372
+ /**
373
+ * Get a service from the context that corresponds to the given tag.
374
+ *
375
+ * @param self - The `Context` to search for the service.
376
+ * @param tag - The `Tag` of the service to retrieve.
377
+ *
378
+ * @example
379
+ * ```ts
380
+ * import { pipe, Context } from "effect"
381
+ *
382
+ * const Port = Context.GenericTag<{ PORT: number }>("Port")
383
+ * const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
384
+ *
385
+ * const Services = pipe(
386
+ * Context.make(Port, { PORT: 8080 }),
387
+ * Context.add(Timeout, { TIMEOUT: 5000 })
388
+ * )
389
+ *
390
+ * assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
391
+ * ```
392
+ *
393
+ * @since 2.0.0
394
+ * @category getters
395
+ */
396
+ <I, S>(tag: Reference<I, S>): <Services>(self: Context<Services>) => S
322
397
  /**
323
398
  * Get a service from the context that corresponds to the given tag.
324
399
  *
@@ -344,6 +419,31 @@ export const get: {
344
419
  * @category getters
345
420
  */
346
421
  <Services, T extends ValidTagsById<Services>>(tag: T): (self: Context<Services>) => Tag.Service<T>
422
+ /**
423
+ * Get a service from the context that corresponds to the given tag.
424
+ *
425
+ * @param self - The `Context` to search for the service.
426
+ * @param tag - The `Tag` of the service to retrieve.
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * import { pipe, Context } from "effect"
431
+ *
432
+ * const Port = Context.GenericTag<{ PORT: number }>("Port")
433
+ * const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
434
+ *
435
+ * const Services = pipe(
436
+ * Context.make(Port, { PORT: 8080 }),
437
+ * Context.add(Timeout, { TIMEOUT: 5000 })
438
+ * )
439
+ *
440
+ * assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
441
+ * ```
442
+ *
443
+ * @since 2.0.0
444
+ * @category getters
445
+ */
446
+ <Services, I, S>(self: Context<Services>, tag: Reference<I, S>): S
347
447
  /**
348
448
  * Get a service from the context that corresponds to the given tag.
349
449
  *
@@ -683,3 +783,22 @@ export const omit: <Services, S extends Array<ValidTagsById<Services>>>(
683
783
  * @category constructors
684
784
  */
685
785
  export const Tag: <const Id extends string>(id: Id) => <Self, Shape>() => TagClass<Self, Id, Shape> = internal.Tag
786
+
787
+ /**
788
+ * @example
789
+ * import { Context, Layer } from "effect"
790
+ *
791
+ * class MyTag extends Context.Reference<MyTag>()("MyTag", {
792
+ * defaultValue: () => ({ myNum: 108 })
793
+ * }) {
794
+ * static Live = Layer.succeed(this, { myNum: 108 })
795
+ * }
796
+ *
797
+ * @since 3.11.0
798
+ * @category constructors
799
+ * @experimental
800
+ */
801
+ export const Reference: <Self>() => <const Id extends string, Service>(
802
+ id: Id,
803
+ options: { readonly defaultValue: () => Service }
804
+ ) => ReferenceClass<Self, Id, Service> = internal.Reference