effect 2.4.17 → 2.4.19

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 (136) hide show
  1. package/Readable/package.json +6 -0
  2. package/RegExp/package.json +6 -0
  3. package/Subscribable/package.json +6 -0
  4. package/dist/cjs/Duration.js +39 -2
  5. package/dist/cjs/Duration.js.map +1 -1
  6. package/dist/cjs/List.js +5 -4
  7. package/dist/cjs/List.js.map +1 -1
  8. package/dist/cjs/Logger.js +11 -1
  9. package/dist/cjs/Logger.js.map +1 -1
  10. package/dist/cjs/Readable.js +79 -0
  11. package/dist/cjs/Readable.js.map +1 -0
  12. package/dist/cjs/RegExp.js +24 -0
  13. package/dist/cjs/RegExp.js.map +1 -0
  14. package/dist/cjs/Subscribable.js +91 -0
  15. package/dist/cjs/Subscribable.js.map +1 -0
  16. package/dist/cjs/SubscriptionRef.js.map +1 -1
  17. package/dist/cjs/TestAnnotation.js +2 -1
  18. package/dist/cjs/TestAnnotation.js.map +1 -1
  19. package/dist/cjs/index.js +8 -2
  20. package/dist/cjs/index.js.map +1 -1
  21. package/dist/cjs/internal/cause.js +3 -2
  22. package/dist/cjs/internal/cause.js.map +1 -1
  23. package/dist/cjs/internal/configProvider.js +2 -2
  24. package/dist/cjs/internal/configProvider.js.map +1 -1
  25. package/dist/cjs/internal/core-effect.js +28 -14
  26. package/dist/cjs/internal/core-effect.js.map +1 -1
  27. package/dist/cjs/internal/core.js +16 -85
  28. package/dist/cjs/internal/core.js.map +1 -1
  29. package/dist/cjs/internal/effect/circular.js +5 -0
  30. package/dist/cjs/internal/effect/circular.js.map +1 -1
  31. package/dist/cjs/internal/errors.js +13 -0
  32. package/dist/cjs/internal/errors.js.map +1 -0
  33. package/dist/cjs/internal/fiberRuntime.js +94 -61
  34. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  35. package/dist/cjs/internal/hashMap.js +1 -1
  36. package/dist/cjs/internal/hashMap.js.map +1 -1
  37. package/dist/cjs/internal/matcher.js +5 -4
  38. package/dist/cjs/internal/matcher.js.map +1 -1
  39. package/dist/cjs/internal/ref.js +6 -1
  40. package/dist/cjs/internal/ref.js.map +1 -1
  41. package/dist/cjs/internal/schedule/intervals.js +2 -1
  42. package/dist/cjs/internal/schedule/intervals.js.map +1 -1
  43. package/dist/cjs/internal/subscriptionRef.js +8 -0
  44. package/dist/cjs/internal/subscriptionRef.js.map +1 -1
  45. package/dist/cjs/internal/trie.js +1 -1
  46. package/dist/cjs/internal/trie.js.map +1 -1
  47. package/dist/cjs/internal/version.js +1 -1
  48. package/dist/dts/Duration.d.ts +16 -0
  49. package/dist/dts/Duration.d.ts.map +1 -1
  50. package/dist/dts/List.d.ts.map +1 -1
  51. package/dist/dts/Logger.d.ts +10 -0
  52. package/dist/dts/Logger.d.ts.map +1 -1
  53. package/dist/dts/Readable.d.ts +55 -0
  54. package/dist/dts/Readable.d.ts.map +1 -0
  55. package/dist/dts/Ref.d.ts +2 -2
  56. package/dist/dts/Ref.d.ts.map +1 -1
  57. package/dist/dts/RegExp.d.ts +17 -0
  58. package/dist/dts/RegExp.d.ts.map +1 -0
  59. package/dist/dts/Subscribable.d.ts +59 -0
  60. package/dist/dts/Subscribable.d.ts.map +1 -0
  61. package/dist/dts/SubscriptionRef.d.ts +2 -2
  62. package/dist/dts/SubscriptionRef.d.ts.map +1 -1
  63. package/dist/dts/TestAnnotation.d.ts.map +1 -1
  64. package/dist/dts/index.d.ts +14 -0
  65. package/dist/dts/index.d.ts.map +1 -1
  66. package/dist/dts/internal/errors.d.ts +5 -0
  67. package/dist/dts/internal/errors.d.ts.map +1 -0
  68. package/dist/esm/Duration.js +38 -1
  69. package/dist/esm/Duration.js.map +1 -1
  70. package/dist/esm/List.js +4 -3
  71. package/dist/esm/List.js.map +1 -1
  72. package/dist/esm/Logger.js +10 -0
  73. package/dist/esm/Logger.js.map +1 -1
  74. package/dist/esm/Readable.js +45 -0
  75. package/dist/esm/Readable.js.map +1 -0
  76. package/dist/esm/RegExp.js +17 -0
  77. package/dist/esm/RegExp.js.map +1 -0
  78. package/dist/esm/Subscribable.js +56 -0
  79. package/dist/esm/Subscribable.js.map +1 -0
  80. package/dist/esm/SubscriptionRef.js.map +1 -1
  81. package/dist/esm/TestAnnotation.js +2 -1
  82. package/dist/esm/TestAnnotation.js.map +1 -1
  83. package/dist/esm/index.js +14 -0
  84. package/dist/esm/index.js.map +1 -1
  85. package/dist/esm/internal/cause.js +3 -2
  86. package/dist/esm/internal/cause.js.map +1 -1
  87. package/dist/esm/internal/configProvider.js +2 -2
  88. package/dist/esm/internal/configProvider.js.map +1 -1
  89. package/dist/esm/internal/core-effect.js +25 -12
  90. package/dist/esm/internal/core-effect.js.map +1 -1
  91. package/dist/esm/internal/core.js +13 -82
  92. package/dist/esm/internal/core.js.map +1 -1
  93. package/dist/esm/internal/effect/circular.js +5 -0
  94. package/dist/esm/internal/effect/circular.js.map +1 -1
  95. package/dist/esm/internal/errors.js +6 -0
  96. package/dist/esm/internal/errors.js.map +1 -0
  97. package/dist/esm/internal/fiberRuntime.js +90 -57
  98. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  99. package/dist/esm/internal/hashMap.js +1 -1
  100. package/dist/esm/internal/hashMap.js.map +1 -1
  101. package/dist/esm/internal/matcher.js +4 -3
  102. package/dist/esm/internal/matcher.js.map +1 -1
  103. package/dist/esm/internal/ref.js +6 -1
  104. package/dist/esm/internal/ref.js.map +1 -1
  105. package/dist/esm/internal/schedule/intervals.js +2 -1
  106. package/dist/esm/internal/schedule/intervals.js.map +1 -1
  107. package/dist/esm/internal/subscriptionRef.js +8 -0
  108. package/dist/esm/internal/subscriptionRef.js.map +1 -1
  109. package/dist/esm/internal/trie.js +1 -1
  110. package/dist/esm/internal/trie.js.map +1 -1
  111. package/dist/esm/internal/version.js +1 -1
  112. package/package.json +25 -1
  113. package/src/Duration.ts +54 -1
  114. package/src/List.ts +5 -3
  115. package/src/Logger.ts +12 -0
  116. package/src/Readable.ts +92 -0
  117. package/src/Ref.ts +2 -2
  118. package/src/RegExp.ts +17 -0
  119. package/src/Subscribable.ts +99 -0
  120. package/src/SubscriptionRef.ts +2 -2
  121. package/src/TestAnnotation.ts +2 -1
  122. package/src/index.ts +17 -0
  123. package/src/internal/cause.ts +3 -2
  124. package/src/internal/configProvider.ts +2 -3
  125. package/src/internal/core-effect.ts +78 -66
  126. package/src/internal/core.ts +13 -150
  127. package/src/internal/effect/circular.ts +7 -1
  128. package/src/internal/errors.ts +7 -0
  129. package/src/internal/fiberRuntime.ts +136 -111
  130. package/src/internal/hashMap.ts +1 -1
  131. package/src/internal/matcher.ts +5 -3
  132. package/src/internal/ref.ts +8 -2
  133. package/src/internal/schedule/intervals.ts +2 -1
  134. package/src/internal/subscriptionRef.ts +8 -0
  135. package/src/internal/trie.ts +1 -1
  136. package/src/internal/version.ts +1 -1
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @since 2.0.0
3
+ */
4
+ import type { Effect } from "./Effect.js"
5
+ import { dual } from "./Function.js"
6
+ import * as core from "./internal/core.js"
7
+ import { type Pipeable, pipeArguments } from "./Pipeable.js"
8
+ import { hasProperty } from "./Predicate.js"
9
+
10
+ /**
11
+ * @since 2.0.0
12
+ * @category type ids
13
+ */
14
+ export const TypeId = Symbol.for("effect/Readable")
15
+
16
+ /**
17
+ * @since 2.0.0
18
+ * @category type ids
19
+ */
20
+ export type TypeId = typeof TypeId
21
+
22
+ /**
23
+ * @since 2.0.0
24
+ * @category models
25
+ */
26
+ export interface Readable<A, E = never, R = never> extends Pipeable {
27
+ readonly [TypeId]: TypeId
28
+ readonly get: Effect<A, E, R>
29
+ }
30
+
31
+ /**
32
+ * @since 2.0.0
33
+ * @category refinements
34
+ */
35
+ export const isReadable = (u: unknown): u is Readable<unknown, unknown, unknown> => hasProperty(u, TypeId)
36
+
37
+ const Proto: Omit<Readable<any>, "get"> = {
38
+ [TypeId]: TypeId,
39
+ pipe() {
40
+ return pipeArguments(this, arguments)
41
+ }
42
+ }
43
+
44
+ /**
45
+ * @since 2.0.0
46
+ * @category constructors
47
+ */
48
+ export const make = <A, E, R>(get: Effect<A, E, R>): Readable<A, E, R> => {
49
+ const self = Object.create(Proto)
50
+ self.get = get
51
+ return self
52
+ }
53
+
54
+ /**
55
+ * @since 2.0.0
56
+ * @category combinators
57
+ */
58
+ export const map: {
59
+ <A, B>(f: (a: NoInfer<A>) => B): <E, R>(fa: Readable<A, E, R>) => Readable<B, E, R>
60
+ <A, E, R, B>(self: Readable<A, E, R>, f: (a: NoInfer<A>) => B): Readable<B, E, R>
61
+ } = dual(
62
+ 2,
63
+ <A, E, R, B>(self: Readable<A, E, R>, f: (a: NoInfer<A>) => B): Readable<B, E, R> => make(core.map(self.get, f))
64
+ )
65
+
66
+ /**
67
+ * @since 2.0.0
68
+ * @category combinators
69
+ */
70
+ export const mapEffect: {
71
+ <A, B, E2, R2>(
72
+ f: (a: NoInfer<A>) => Effect<B, E2, R2>
73
+ ): <E, R>(fa: Readable<A, E, R>) => Readable<B, E | E2, R | R2>
74
+ <A, E, R, B, E2, R2>(
75
+ self: Readable<A, E, R>,
76
+ f: (a: NoInfer<A>) => Effect<B, E2, R2>
77
+ ): Readable<B, E | E2, R | R2>
78
+ } = dual(2, <A, E, R, B, E2, R2>(
79
+ self: Readable<A, E, R>,
80
+ f: (a: NoInfer<A>) => Effect<B, E2, R2>
81
+ ): Readable<B, E | E2, R | R2> => make(core.flatMap(self.get, f)))
82
+
83
+ /**
84
+ * @since 2.0.0
85
+ * @category constructors
86
+ */
87
+ export const unwrap = <A, E, R, E1, R1>(
88
+ effect: Effect<Readable<A, E, R>, E1, R1>
89
+ ): Readable<A, E | E1, R | R1> =>
90
+ make(
91
+ core.flatMap(effect, (s) => s.get)
92
+ )
package/src/Ref.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  import type * as Effect from "./Effect.js"
5
5
  import * as internal from "./internal/ref.js"
6
6
  import type * as Option from "./Option.js"
7
- import type { Pipeable } from "./Pipeable.js"
7
+ import type { Readable } from "./Readable.js"
8
8
  import type * as Types from "./Types.js"
9
9
 
10
10
  /**
@@ -23,7 +23,7 @@ export type RefTypeId = typeof RefTypeId
23
23
  * @since 2.0.0
24
24
  * @category models
25
25
  */
26
- export interface Ref<in out A> extends Ref.Variance<A>, Pipeable {
26
+ export interface Ref<in out A> extends Ref.Variance<A>, Readable<A> {
27
27
  modify<B>(f: (a: A) => readonly [B, A]): Effect.Effect<B>
28
28
  }
29
29
 
package/src/RegExp.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * This module provides utility functions for working with RegExp in TypeScript.
3
+ *
4
+ * @since 2.0.0
5
+ */
6
+
7
+ /**
8
+ * Escapes special characters in a regular expression pattern.
9
+ *
10
+ * @example
11
+ * import * as RegExp from "effect/RegExp"
12
+ *
13
+ * assert.deepStrictEqual(RegExp.escape("a*b"), "a\\*b")
14
+ *
15
+ * @since 2.0.0
16
+ */
17
+ export const escape = (string: string): string => string.replace(/[/\\^$*+?.()|[\]{}]/g, "\\$&")
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @since 2.0.0
3
+ */
4
+ import * as Effect from "./Effect.js"
5
+ import { dual } from "./Function.js"
6
+ import { pipeArguments } from "./Pipeable.js"
7
+ import { hasProperty } from "./Predicate.js"
8
+ import * as Readable from "./Readable.js"
9
+ import * as Stream from "./Stream.js"
10
+
11
+ /**
12
+ * @since 2.0.0
13
+ * @category type ids
14
+ */
15
+ export const TypeId = Symbol.for("effect/Subscribable")
16
+
17
+ /**
18
+ * @since 2.0.0
19
+ * @category type ids
20
+ */
21
+ export type TypeId = typeof TypeId
22
+
23
+ /**
24
+ * @since 2.0.0
25
+ * @category models
26
+ */
27
+ export interface Subscribable<A, E = never, R = never> extends Readable.Readable<A, E, R> {
28
+ readonly [TypeId]: TypeId
29
+ readonly changes: Stream.Stream<A, E, R>
30
+ }
31
+
32
+ /**
33
+ * @since 2.0.0
34
+ * @category refinements
35
+ */
36
+ export const isSubscribable = (u: unknown): u is Subscribable<unknown, unknown, unknown> => hasProperty(u, TypeId)
37
+
38
+ const Proto: Omit<Subscribable<any>, "get" | "changes"> = {
39
+ [Readable.TypeId]: Readable.TypeId,
40
+ [TypeId]: TypeId,
41
+ pipe() {
42
+ return pipeArguments(this, arguments)
43
+ }
44
+ }
45
+
46
+ /**
47
+ * @since 2.0.0
48
+ * @category constructors
49
+ */
50
+ export const make = <A, E, R>(options: {
51
+ readonly get: Effect.Effect<A, E, R>
52
+ readonly changes: Stream.Stream<A, E, R>
53
+ }): Subscribable<A, E, R> => Object.assign(Object.create(Proto), options)
54
+
55
+ /**
56
+ * @since 2.0.0
57
+ * @category combinators
58
+ */
59
+ export const map: {
60
+ <A, B>(f: (a: NoInfer<A>) => B): <E, R>(fa: Subscribable<A, E, R>) => Subscribable<B, E, R>
61
+ <A, E, R, B>(self: Subscribable<A, E, R>, f: (a: NoInfer<A>) => B): Subscribable<B, E, R>
62
+ } = dual(2, <A, E, R, B>(self: Subscribable<A, E, R>, f: (a: NoInfer<A>) => B): Subscribable<B, E, R> =>
63
+ make({
64
+ get: Effect.map(self.get, f),
65
+ changes: Stream.map(self.changes, f)
66
+ }))
67
+
68
+ /**
69
+ * @since 2.0.0
70
+ * @category combinators
71
+ */
72
+ export const mapEffect: {
73
+ <A, B, E2, R2>(
74
+ f: (a: NoInfer<A>) => Effect.Effect<B, E2, R2>
75
+ ): <E, R>(fa: Subscribable<A, E, R>) => Subscribable<B, E | E2, R | R2>
76
+ <A, E, R, B, E2, R2>(
77
+ self: Subscribable<A, E, R>,
78
+ f: (a: NoInfer<A>) => Effect.Effect<B, E2, R2>
79
+ ): Subscribable<B, E | E2, R | R2>
80
+ } = dual(2, <A, E, R, B, E2, R2>(
81
+ self: Subscribable<A, E, R>,
82
+ f: (a: NoInfer<A>) => Effect.Effect<B, E2, R2>
83
+ ): Subscribable<B, E | E2, R | R2> =>
84
+ make({
85
+ get: Effect.flatMap(self.get, f),
86
+ changes: Stream.mapEffect(self.changes, f)
87
+ }))
88
+
89
+ /**
90
+ * @since 2.0.0
91
+ * @category constructors
92
+ */
93
+ export const unwrap = <A, E, R, E1, R1>(
94
+ effect: Effect.Effect<Subscribable<A, E, R>, E1, R1>
95
+ ): Subscribable<A, E | E1, R | R1> =>
96
+ make({
97
+ get: Effect.flatMap(effect, (s) => s.get),
98
+ changes: Stream.unwrap(Effect.map(effect, (s) => s.changes))
99
+ })
@@ -4,10 +4,10 @@
4
4
  import type * as Effect from "./Effect.js"
5
5
  import * as internal from "./internal/subscriptionRef.js"
6
6
  import type * as Option from "./Option.js"
7
- import type { Pipeable } from "./Pipeable.js"
8
7
  import type * as PubSub from "./PubSub.js"
9
8
  import * as Ref from "./Ref.js"
10
9
  import type * as Stream from "./Stream.js"
10
+ import type { Subscribable } from "./Subscribable.js"
11
11
  import * as Synchronized from "./SynchronizedRef.js"
12
12
  import type * as Types from "./Types.js"
13
13
 
@@ -31,7 +31,7 @@ export type SubscriptionRefTypeId = typeof SubscriptionRefTypeId
31
31
  * @category models
32
32
  */
33
33
  export interface SubscriptionRef<in out A>
34
- extends SubscriptionRef.Variance<A>, Synchronized.SynchronizedRef<A>, Pipeable
34
+ extends SubscriptionRef.Variance<A>, Synchronized.SynchronizedRef<A>, Subscribable<A>
35
35
  {
36
36
  /** @internal */
37
37
  readonly ref: Ref.Ref<A>
@@ -8,6 +8,7 @@ import type * as Fiber from "./Fiber.js"
8
8
  import { pipe } from "./Function.js"
9
9
  import * as Hash from "./Hash.js"
10
10
  import * as HashSet from "./HashSet.js"
11
+ import { getBugErrorMessage } from "./internal/errors.js"
11
12
  import type * as MutableRef from "./MutableRef.js"
12
13
  import { hasProperty } from "./Predicate.js"
13
14
  import type * as SortedSet from "./SortedSet.js"
@@ -96,7 +97,7 @@ export const compose = <A>(
96
97
  if (Either.isLeft(left) && Either.isRight(right)) {
97
98
  return right
98
99
  }
99
- throw new Error("BUG: TestAnnotation.compose - please report an issue at https://github.com/Effect-TS/effect/issues")
100
+ throw new Error(getBugErrorMessage("TestAnnotation.compose"))
100
101
  }
101
102
 
102
103
  /**
package/src/index.ts CHANGED
@@ -570,6 +570,11 @@ export * as Random from "./Random.js"
570
570
  */
571
571
  export * as RateLimiter from "./RateLimiter.js"
572
572
 
573
+ /**
574
+ * @since 2.0.0
575
+ */
576
+ export * as Readable from "./Readable.js"
577
+
573
578
  /**
574
579
  * This module provides utility functions for working with arrays in TypeScript.
575
580
  *
@@ -594,6 +599,13 @@ export * as RedBlackTree from "./RedBlackTree.js"
594
599
  */
595
600
  export * as Ref from "./Ref.js"
596
601
 
602
+ /**
603
+ * This module provides utility functions for working with RegExp in TypeScript.
604
+ *
605
+ * @since 2.0.0
606
+ */
607
+ export * as RegExp from "./RegExp.js"
608
+
597
609
  /**
598
610
  * @since 2.0.0
599
611
  */
@@ -740,6 +752,11 @@ export * as String from "./String.js"
740
752
  */
741
753
  export * as Struct from "./Struct.js"
742
754
 
755
+ /**
756
+ * @since 2.0.0
757
+ */
758
+ export * as Subscribable from "./Subscribable.js"
759
+
743
760
  /**
744
761
  * @since 2.0.0
745
762
  */
@@ -14,6 +14,7 @@ import type { Predicate, Refinement } from "../Predicate.js"
14
14
  import * as ReadonlyArray from "../ReadonlyArray.js"
15
15
  import type { ParentSpan, Span } from "../Tracer.js"
16
16
  import type { NoInfer } from "../Types.js"
17
+ import { getBugErrorMessage } from "./errors.js"
17
18
  import * as OpCodes from "./opCodes/cause.js"
18
19
 
19
20
  // -----------------------------------------------------------------------------
@@ -604,7 +605,7 @@ const flattenCauseLoop = (
604
605
  causes = sequential
605
606
  flattened = updated
606
607
  }
607
- throw new Error("BUG: Cause.flattenCauseLoop - please report an issue at https://github.com/Effect-TS/effect/issues")
608
+ throw new Error(getBugErrorMessage("Cause.flattenCauseLoop"))
608
609
  }
609
610
 
610
611
  // -----------------------------------------------------------------------------
@@ -740,7 +741,7 @@ const evaluateCause = (
740
741
  }
741
742
  }
742
743
  }
743
- throw new Error("BUG: Cause.evaluateCauseLoop - please report an issue at https://github.com/Effect-TS/effect/issues")
744
+ throw new Error(getBugErrorMessage("Cause.evaluateCauseLoop"))
744
745
  }
745
746
 
746
747
  // -----------------------------------------------------------------------------
@@ -13,6 +13,7 @@ import * as number from "../Number.js"
13
13
  import * as Option from "../Option.js"
14
14
  import { pipeArguments } from "../Pipeable.js"
15
15
  import * as ReadonlyArray from "../ReadonlyArray.js"
16
+ import * as regexp from "../RegExp.js"
16
17
  import type * as _config from "./config.js"
17
18
  import * as configError from "./configError.js"
18
19
  import * as pathPatch from "./configProvider/pathPatch.js"
@@ -595,7 +596,7 @@ export const within = dual<
595
596
  })
596
597
 
597
598
  const splitPathString = (text: string, delim: string): ReadonlyArray<string> => {
598
- const split = text.split(new RegExp(`\\s*${escapeRegex(delim)}\\s*`))
599
+ const split = text.split(new RegExp(`\\s*${regexp.escape(delim)}\\s*`))
599
600
  return split
600
601
  }
601
602
 
@@ -626,8 +627,6 @@ const transpose = <A>(array: ReadonlyArray<ReadonlyArray<A>>): ReadonlyArray<Rea
626
627
  return Object.keys(array[0]).map((column) => array.map((row) => row[column as any]))
627
628
  }
628
629
 
629
- const escapeRegex = (string: string): string => string.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&")
630
-
631
630
  const indicesFrom = (quotedIndices: HashSet.HashSet<string>): Effect.Effect<ReadonlyArray<number>> =>
632
631
  pipe(
633
632
  core.forEachSequential(quotedIndices, parseQuotedIndex),
@@ -27,9 +27,11 @@ import type * as runtimeFlagsPatch from "../RuntimeFlagsPatch.js"
27
27
  import * as Tracer from "../Tracer.js"
28
28
  import type { MergeRecord, NoInfer } from "../Types.js"
29
29
  import * as internalCause from "./cause.js"
30
+ import { clockTag } from "./clock.js"
30
31
  import * as core from "./core.js"
31
32
  import * as defaultServices from "./defaultServices.js"
32
33
  import * as fiberRefsPatch from "./fiberRefs/patch.js"
34
+ import type { FiberRuntime } from "./fiberRuntime.js"
33
35
  import * as metricLabel from "./metric/label.js"
34
36
  import * as runtimeFlags from "./runtimeFlags.js"
35
37
  import * as SingleShotGen from "./singleShotGen.js"
@@ -1072,8 +1074,9 @@ export const mapAccum: {
1072
1074
  let i = 0
1073
1075
  while (!(next = iterator.next()).done) {
1074
1076
  const index = i++
1077
+ const value = next.value
1075
1078
  result = core.flatMap(result, (state) =>
1076
- core.map(f(state, next.value, index), ([z, b]) => {
1079
+ core.map(f(state, value, index), ([z, b]) => {
1077
1080
  builder.push(b)
1078
1081
  return z
1079
1082
  }))
@@ -2006,13 +2009,6 @@ export const currentSpan: Effect.Effect<Tracer.Span, Cause.NoSuchElementExceptio
2006
2009
  }
2007
2010
  )
2008
2011
 
2009
- const bigint0 = BigInt(0)
2010
- /** @internal */
2011
- export const currentTimeNanosTracing = core.fiberRefGetWith(
2012
- core.currentTracerTimingEnabled,
2013
- (enabled) => enabled ? Clock.currentTimeNanos : core.succeed(bigint0)
2014
- )
2015
-
2016
2012
  /* @internal */
2017
2013
  export const linkSpans = dual<
2018
2014
  (
@@ -2040,8 +2036,11 @@ export const linkSpans = dual<
2040
2036
  )
2041
2037
  )
2042
2038
 
2039
+ const bigint0 = BigInt(0)
2040
+
2043
2041
  /** @internal */
2044
- export const makeSpan = (
2042
+ export const unsafeMakeSpan = <XA, XE>(
2043
+ fiber: FiberRuntime<XA, XE>,
2045
2044
  name: string,
2046
2045
  options?: {
2047
2046
  readonly attributes?: Record<string, unknown> | undefined
@@ -2050,55 +2049,67 @@ export const makeSpan = (
2050
2049
  readonly root?: boolean | undefined
2051
2050
  readonly context?: Context.Context<never> | undefined
2052
2051
  }
2053
- ): Effect.Effect<Tracer.Span> =>
2054
- core.flatMap(fiberRefs, (fiberRefs) =>
2055
- core.sync(() => {
2056
- const enabled = FiberRefs.getOrDefault(fiberRefs, core.currentTracerEnabled)
2057
- if (enabled === false) {
2058
- return core.noopSpan(name)
2059
- }
2052
+ ) => {
2053
+ const enabled = fiber.getFiberRef(core.currentTracerEnabled)
2054
+ if (enabled === false) {
2055
+ return core.noopSpan(name)
2056
+ }
2060
2057
 
2061
- const context = FiberRefs.getOrDefault(fiberRefs, core.currentContext)
2062
- const services = FiberRefs.getOrDefault(fiberRefs, defaultServices.currentServices)
2063
-
2064
- const tracer = Context.get(services, internalTracer.tracerTag)
2065
- const clock = Context.get(services, Clock.Clock)
2066
- const timingEnabled = FiberRefs.getOrDefault(fiberRefs, core.currentTracerTimingEnabled)
2067
- const annotationsFromEnv = FiberRefs.get(fiberRefs, core.currentTracerSpanAnnotations)
2068
- const linksFromEnv = FiberRefs.get(fiberRefs, core.currentTracerSpanLinks)
2069
-
2070
- const parent = options?.parent
2071
- ? Option.some(options.parent)
2072
- : options?.root
2073
- ? Option.none()
2074
- : Context.getOption(context, internalTracer.spanTag)
2075
-
2076
- const links = linksFromEnv._tag === "Some" ?
2077
- options?.links !== undefined ?
2078
- [
2079
- ...Chunk.toReadonlyArray(linksFromEnv.value),
2080
- ...(options?.links ?? [])
2081
- ] :
2082
- Chunk.toReadonlyArray(linksFromEnv.value) :
2083
- options?.links ?? ReadonlyArray.empty()
2084
-
2085
- const span = tracer.span(
2086
- name,
2087
- parent,
2088
- options?.context ?? Context.empty(),
2089
- links,
2090
- timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0
2091
- )
2058
+ const context = fiber.getFiberRef(core.currentContext)
2059
+ const services = fiber.getFiberRef(defaultServices.currentServices)
2060
+
2061
+ const tracer = Context.get(services, internalTracer.tracerTag)
2062
+ const clock = Context.get(services, Clock.Clock)
2063
+ const timingEnabled = fiber.getFiberRef(core.currentTracerTimingEnabled)
2064
+
2065
+ const fiberRefs = fiber.getFiberRefs()
2066
+ const annotationsFromEnv = FiberRefs.get(fiberRefs, core.currentTracerSpanAnnotations)
2067
+ const linksFromEnv = FiberRefs.get(fiberRefs, core.currentTracerSpanLinks)
2068
+
2069
+ const parent = options?.parent
2070
+ ? Option.some(options.parent)
2071
+ : options?.root
2072
+ ? Option.none()
2073
+ : Context.getOption(context, internalTracer.spanTag)
2074
+
2075
+ const links = linksFromEnv._tag === "Some" ?
2076
+ options?.links !== undefined ?
2077
+ [
2078
+ ...Chunk.toReadonlyArray(linksFromEnv.value),
2079
+ ...(options?.links ?? [])
2080
+ ] :
2081
+ Chunk.toReadonlyArray(linksFromEnv.value) :
2082
+ options?.links ?? ReadonlyArray.empty()
2083
+
2084
+ const span = tracer.span(
2085
+ name,
2086
+ parent,
2087
+ options?.context ?? Context.empty(),
2088
+ links,
2089
+ timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0
2090
+ )
2092
2091
 
2093
- if (annotationsFromEnv._tag === "Some") {
2094
- HashMap.forEach(annotationsFromEnv.value, (value, key) => span.attribute(key, value))
2095
- }
2096
- if (options?.attributes) {
2097
- Object.entries(options.attributes).forEach(([k, v]) => span.attribute(k, v))
2098
- }
2092
+ if (annotationsFromEnv._tag === "Some") {
2093
+ HashMap.forEach(annotationsFromEnv.value, (value, key) => span.attribute(key, value))
2094
+ }
2095
+ if (options?.attributes !== undefined) {
2096
+ Object.entries(options.attributes).forEach(([k, v]) => span.attribute(k, v))
2097
+ }
2099
2098
 
2100
- return span
2101
- }))
2099
+ return span
2100
+ }
2101
+
2102
+ /** @internal */
2103
+ export const makeSpan = (
2104
+ name: string,
2105
+ options?: {
2106
+ readonly attributes?: Record<string, unknown> | undefined
2107
+ readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
2108
+ readonly parent?: Tracer.ParentSpan | undefined
2109
+ readonly root?: boolean | undefined
2110
+ readonly context?: Context.Context<never> | undefined
2111
+ }
2112
+ ): Effect.Effect<Tracer.Span> => core.withFiberRuntime((fiber) => core.succeed(unsafeMakeSpan(fiber, name, options)))
2102
2113
 
2103
2114
  /* @internal */
2104
2115
  export const spanAnnotations: Effect.Effect<HashMap.HashMap<string, unknown>> = core
@@ -2134,17 +2145,18 @@ export const useSpan: {
2134
2145
  } | undefined = args.length === 1 ? undefined : args[0]
2135
2146
  const evaluate: (span: Tracer.Span) => Effect.Effect<A, E, R> = args[args.length - 1]
2136
2147
 
2137
- return core.acquireUseRelease(
2138
- makeSpan(name, options),
2139
- evaluate,
2140
- (span, exit) =>
2141
- span.status._tag === "Ended" ?
2142
- core.unit :
2143
- core.flatMap(
2144
- currentTimeNanosTracing,
2145
- (endTime) => core.sync(() => span.end(endTime, exit))
2146
- )
2147
- )
2148
+ return core.withFiberRuntime<A, E, R>((fiber) => {
2149
+ const span = unsafeMakeSpan(fiber, name, options)
2150
+ const timingEnabled = fiber.getFiberRef(core.currentTracerTimingEnabled)
2151
+ const clock = Context.get(fiber.getFiberRef(defaultServices.currentServices), clockTag)
2152
+ return core.onExit(evaluate(span), (exit) =>
2153
+ core.sync(() => {
2154
+ if (span.status._tag === "Ended") {
2155
+ return
2156
+ }
2157
+ span.end(timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0, exit)
2158
+ }))
2159
+ })
2148
2160
  }
2149
2161
 
2150
2162
  /** @internal */