effect 2.3.5 → 2.3.6

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 (102) hide show
  1. package/dist/cjs/Effect.js +18 -2
  2. package/dist/cjs/Effect.js.map +1 -1
  3. package/dist/cjs/FiberId.js.map +1 -1
  4. package/dist/cjs/Function.js +21 -2
  5. package/dist/cjs/Function.js.map +1 -1
  6. package/dist/cjs/Random.js +6 -1
  7. package/dist/cjs/Random.js.map +1 -1
  8. package/dist/cjs/RequestResolver.js +27 -1
  9. package/dist/cjs/RequestResolver.js.map +1 -1
  10. package/dist/cjs/Runtime.js +39 -1
  11. package/dist/cjs/Runtime.js.map +1 -1
  12. package/dist/cjs/TestAnnotation.js.map +1 -1
  13. package/dist/cjs/TestAnnotationMap.js +40 -15
  14. package/dist/cjs/TestAnnotationMap.js.map +1 -1
  15. package/dist/cjs/TestAnnotations.js.map +1 -1
  16. package/dist/cjs/internal/cause.js +6 -2
  17. package/dist/cjs/internal/cause.js.map +1 -1
  18. package/dist/cjs/internal/dataSource.js +6 -1
  19. package/dist/cjs/internal/dataSource.js.map +1 -1
  20. package/dist/cjs/internal/defaultServices.js +3 -1
  21. package/dist/cjs/internal/defaultServices.js.map +1 -1
  22. package/dist/cjs/internal/fiberId.js +2 -0
  23. package/dist/cjs/internal/fiberId.js.map +1 -1
  24. package/dist/cjs/internal/fiberRefs.js.map +1 -1
  25. package/dist/cjs/internal/fiberRuntime.js +5 -1
  26. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  27. package/dist/cjs/internal/runtime.js +15 -1
  28. package/dist/cjs/internal/runtime.js.map +1 -1
  29. package/dist/cjs/internal/tracer.js +12 -4
  30. package/dist/cjs/internal/tracer.js.map +1 -1
  31. package/dist/cjs/internal/version.js +1 -1
  32. package/dist/dts/Effect.d.ts +23 -4
  33. package/dist/dts/Effect.d.ts.map +1 -1
  34. package/dist/dts/FiberId.d.ts +11 -4
  35. package/dist/dts/FiberId.d.ts.map +1 -1
  36. package/dist/dts/FiberRefs.d.ts +14 -14
  37. package/dist/dts/FiberRefs.d.ts.map +1 -1
  38. package/dist/dts/Function.d.ts +18 -0
  39. package/dist/dts/Function.d.ts.map +1 -1
  40. package/dist/dts/Random.d.ts +6 -0
  41. package/dist/dts/Random.d.ts.map +1 -1
  42. package/dist/dts/RequestResolver.d.ts +29 -0
  43. package/dist/dts/RequestResolver.d.ts.map +1 -1
  44. package/dist/dts/Runtime.d.ts +48 -0
  45. package/dist/dts/Runtime.d.ts.map +1 -1
  46. package/dist/dts/TestAnnotation.d.ts.map +1 -1
  47. package/dist/dts/TestAnnotationMap.d.ts +2 -1
  48. package/dist/dts/TestAnnotationMap.d.ts.map +1 -1
  49. package/dist/dts/TestAnnotations.d.ts +3 -0
  50. package/dist/dts/TestAnnotations.d.ts.map +1 -1
  51. package/dist/dts/internal/version.d.ts +1 -1
  52. package/dist/esm/Effect.js +16 -0
  53. package/dist/esm/Effect.js.map +1 -1
  54. package/dist/esm/FiberId.js.map +1 -1
  55. package/dist/esm/Function.js +18 -0
  56. package/dist/esm/Function.js.map +1 -1
  57. package/dist/esm/Random.js +5 -0
  58. package/dist/esm/Random.js.map +1 -1
  59. package/dist/esm/RequestResolver.js +26 -0
  60. package/dist/esm/RequestResolver.js.map +1 -1
  61. package/dist/esm/Runtime.js +38 -0
  62. package/dist/esm/Runtime.js.map +1 -1
  63. package/dist/esm/TestAnnotation.js.map +1 -1
  64. package/dist/esm/TestAnnotationMap.js +16 -16
  65. package/dist/esm/TestAnnotationMap.js.map +1 -1
  66. package/dist/esm/TestAnnotations.js.map +1 -1
  67. package/dist/esm/internal/cause.js +6 -2
  68. package/dist/esm/internal/cause.js.map +1 -1
  69. package/dist/esm/internal/dataSource.js +5 -0
  70. package/dist/esm/internal/dataSource.js.map +1 -1
  71. package/dist/esm/internal/defaultServices.js +2 -0
  72. package/dist/esm/internal/defaultServices.js.map +1 -1
  73. package/dist/esm/internal/fiberId.js +2 -0
  74. package/dist/esm/internal/fiberId.js.map +1 -1
  75. package/dist/esm/internal/fiberRefs.js.map +1 -1
  76. package/dist/esm/internal/fiberRuntime.js +3 -0
  77. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  78. package/dist/esm/internal/runtime.js +14 -0
  79. package/dist/esm/internal/runtime.js.map +1 -1
  80. package/dist/esm/internal/tracer.js +12 -4
  81. package/dist/esm/internal/tracer.js.map +1 -1
  82. package/dist/esm/internal/version.js +1 -1
  83. package/package.json +1 -1
  84. package/src/Effect.ts +26 -4
  85. package/src/FiberId.ts +12 -4
  86. package/src/FiberRefs.ts +14 -14
  87. package/src/Function.ts +19 -0
  88. package/src/Random.ts +7 -0
  89. package/src/RequestResolver.ts +37 -0
  90. package/src/Runtime.ts +51 -0
  91. package/src/TestAnnotation.ts +1 -0
  92. package/src/TestAnnotationMap.ts +19 -23
  93. package/src/TestAnnotations.ts +3 -0
  94. package/src/internal/cause.ts +11 -6
  95. package/src/internal/dataSource.ts +27 -0
  96. package/src/internal/defaultServices.ts +12 -2
  97. package/src/internal/fiberId.ts +6 -4
  98. package/src/internal/fiberRefs.ts +25 -25
  99. package/src/internal/fiberRuntime.ts +8 -1
  100. package/src/internal/runtime.ts +41 -0
  101. package/src/internal/tracer.ts +12 -4
  102. package/src/internal/version.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tracer.js","names":["Context","globalValue","MutableRef","TracerTypeId","Symbol","for","make","options","tracerTag","GenericTag","spanTag","ids","NativeSpan","name","parent","context","links","startTime","_tag","spanId","traceId","sampled","status","attributes","events","constructor","Map","incrementAndGet","end","endTime","exit","attribute","key","value","set","event","push","nativeTracer","span","f","externalSpan","empty"],"sources":["../../../src/internal/tracer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,OAAO,MAAM,eAAe;AAExC,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAO,KAAKC,UAAU,MAAM,kBAAkB;AAI9C;AACA,OAAO,MAAMC,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MACJb,SAAS,EAAE,IAAI,CAACK,MAAM,CAACL;KACxB;EACH,CAAC;EAEDc,SAAS,GAAGA,CAACC,GAAW,EAAEC,KAAc,KAAU;IAChD,IAAI,CAACV,UAAU,CAACW,GAAG,CAACF,GAAG,EAAEC,KAAK,CAAC;EACjC,CAAC;EAEDE,KAAK,GAAGA,CAACtB,IAAY,EAAEI,SAAiB,EAAEM,UAAoC,KAAU;IACtF,IAAI,CAACC,MAAM,CAACY,IAAI,CAAC,CAACvB,IAAI,EAAEI,SAAS,EAAEM,UAAU,IAAI,EAAE,CAAC,CAAC;EACvD,CAAC;;AAGH;AACA,OAAO,MAAMc,YAAY,gBAAkB/B,IAAI,CAAC;EAC9CgC,IAAI,EAAEA,CAACzB,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAEC,KAAK,EAAEC,SAAS,KAC5C,IAAIL,UAAU,CACZC,IAAI,EACJC,MAAM,EACNC,OAAO,EACPC,KAAK,EACLC,SAAS,CACV;EACHF,OAAO,EAAGwB,CAAC,IAAKA,CAAC;CAClB,CAAC;AAEF;AACA,OAAO,MAAMC,YAAY,GAAIjC,OAK5B,KAA2B;EAC1BW,IAAI,EAAE,cAAc;EACpBC,MAAM,EAAEZ,OAAO,CAACY,MAAM;EACtBC,OAAO,EAAEb,OAAO,CAACa,OAAO;EACxBC,OAAO,EAAEd,OAAO,CAACc,OAAO,IAAI,IAAI;EAChCN,OAAO,EAAER,OAAO,CAACQ,OAAO,IAAIf,OAAO,CAACyC,KAAK;CAC1C,CAAC"}
1
+ {"version":3,"file":"tracer.js","names":["Context","TracerTypeId","Symbol","for","make","options","tracerTag","GenericTag","spanTag","randomString","characters","charactersLength","length","result","i","charAt","Math","floor","random","NativeSpan","name","parent","context","links","startTime","_tag","spanId","traceId","sampled","status","attributes","events","constructor","Map","end","endTime","exit","attribute","key","value","set","event","push","nativeTracer","span","f","externalSpan","empty"],"sources":["../../../src/internal/tracer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,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IAAI,IAAI;EAChCN,OAAO,EAAEjB,OAAO,CAACiB,OAAO,IAAItB,OAAO,CAAC+C,KAAK;CAC1C,CAAC"}
@@ -1,2 +1,2 @@
1
- export const moduleVersion = "2.3.5";
1
+ export const moduleVersion = "2.3.6";
2
2
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect",
3
- "version": "2.3.5",
3
+ "version": "2.3.6",
4
4
  "description": "Functional programming in TypeScript",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/Effect.ts CHANGED
@@ -2817,8 +2817,8 @@ export const withClockScoped: <A extends Clock.Clock>(value: A) => Effect<void,
2817
2817
  * @category clock
2818
2818
  */
2819
2819
  export const withClock: {
2820
- <A extends Clock.Clock>(value: A): <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R>
2821
- <R, E, A extends Clock.Clock>(effect: Effect<A, E, R>, value: A): Effect<A, E, R>
2820
+ <X extends Clock.Clock>(value: X): <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R>
2821
+ <X extends Clock.Clock, A, E, R>(effect: Effect<A, E, R>, value: X): Effect<A, E, R>
2822
2822
  } = defaultServices.withClock
2823
2823
 
2824
2824
  // -------------------------------------------------------------------------------------
@@ -4087,11 +4087,11 @@ export const schedule: {
4087
4087
  export const scheduleForked: {
4088
4088
  <R2, Out>(
4089
4089
  schedule: Schedule.Schedule<R2, unknown, Out>
4090
- ): <A, E, R>(self: Effect<A, E, R>) => Effect<Scope.Scope | R2 | R, never, Fiber.RuntimeFiber<Out, E>>
4090
+ ): <A, E, R>(self: Effect<A, E, R>) => Effect<Fiber.RuntimeFiber<Out, E>, never, Scope.Scope | R2 | R>
4091
4091
  <R, E, A, R2, Out>(
4092
4092
  self: Effect<A, E, R>,
4093
4093
  schedule: Schedule.Schedule<R2, unknown, Out>
4094
- ): Effect<Scope.Scope | R | R2, never, Fiber.RuntimeFiber<Out, E>>
4094
+ ): Effect<Fiber.RuntimeFiber<Out, E>, never, Scope.Scope | R | R2>
4095
4095
  } = circular.scheduleForked
4096
4096
 
4097
4097
  /**
@@ -4524,6 +4524,28 @@ export const random: Effect<Random.Random> = effect.random
4524
4524
  export const randomWith: <A, E, R>(f: (random: Random.Random) => Effect<A, E, R>) => Effect<A, E, R> =
4525
4525
  defaultServices.randomWith
4526
4526
 
4527
+ /**
4528
+ * Executes the specified workflow with the specified implementation of the
4529
+ * random service.
4530
+ *
4531
+ * @since 2.0.0
4532
+ * @category random
4533
+ */
4534
+ export const withRandom: {
4535
+ <X extends Random.Random>(value: X): <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R>
4536
+ <X extends Random.Random, A, E, R>(effect: Effect<A, E, R>, value: X): Effect<A, E, R>
4537
+ } = defaultServices.withRandom
4538
+
4539
+ /**
4540
+ * Sets the implementation of the random service to the specified value and
4541
+ * restores it to its original value when the scope is closed.
4542
+ *
4543
+ * @since 2.0.0
4544
+ * @category constructors
4545
+ */
4546
+ export const withRandomScoped: <A extends Random.Random>(value: A) => Effect<void, never, Scope.Scope> =
4547
+ fiberRuntime.withRandomScoped
4548
+
4527
4549
  // -------------------------------------------------------------------------------------
4528
4550
  // runtime
4529
4551
  // -------------------------------------------------------------------------------------
package/src/FiberId.ts CHANGED
@@ -23,7 +23,13 @@ export type FiberIdTypeId = typeof FiberIdTypeId
23
23
  * @since 2.0.0
24
24
  * @category models
25
25
  */
26
- export type FiberId = None | Runtime | Composite
26
+ export type Single = None | Runtime
27
+
28
+ /**
29
+ * @since 2.0.0
30
+ * @category models
31
+ */
32
+ export type FiberId = Single | Composite
27
33
 
28
34
  /**
29
35
  * @since 2.0.0
@@ -32,6 +38,8 @@ export type FiberId = None | Runtime | Composite
32
38
  export interface None extends Equal.Equal, Inspectable {
33
39
  readonly [FiberIdTypeId]: FiberIdTypeId
34
40
  readonly _tag: "None"
41
+ readonly id: -1
42
+ readonly startTimeMillis: -1
35
43
  }
36
44
 
37
45
  /**
@@ -60,19 +68,19 @@ export interface Composite extends Equal.Equal, Inspectable {
60
68
  * @since 2.0.0
61
69
  * @category constructors
62
70
  */
63
- export const none: FiberId = internal.none
71
+ export const none: None = internal.none
64
72
 
65
73
  /**
66
74
  * @since 2.0.0
67
75
  * @category constructors
68
76
  */
69
- export const runtime: (id: number, startTimeMillis: number) => FiberId = internal.runtime
77
+ export const runtime: (id: number, startTimeMillis: number) => Runtime = internal.runtime
70
78
 
71
79
  /**
72
80
  * @since 2.0.0
73
81
  * @category constructors
74
82
  */
75
- export const composite: (left: FiberId, right: FiberId) => FiberId = internal.composite
83
+ export const composite: (left: FiberId, right: FiberId) => Composite = internal.composite
76
84
 
77
85
  /**
78
86
  * Returns `true` if the specified unknown value is a `FiberId`, `false`
package/src/FiberRefs.ts CHANGED
@@ -33,7 +33,7 @@ export type FiberRefsSym = typeof FiberRefsSym
33
33
  */
34
34
  export interface FiberRefs extends Pipeable {
35
35
  readonly [FiberRefsSym]: FiberRefsSym
36
- readonly locals: Map<FiberRef.FiberRef<any>, Arr.NonEmptyReadonlyArray<readonly [FiberId.Runtime, any]>>
36
+ readonly locals: Map<FiberRef.FiberRef<any>, Arr.NonEmptyReadonlyArray<readonly [FiberId.Single, any]>>
37
37
  }
38
38
 
39
39
  const delete_: {
@@ -68,8 +68,8 @@ export const fiberRefs: (self: FiberRefs) => HashSet.HashSet<FiberRef.FiberRef<a
68
68
  * @category utils
69
69
  */
70
70
  export const forkAs: {
71
- (childId: FiberId.Runtime): (self: FiberRefs) => FiberRefs
72
- (self: FiberRefs, childId: FiberId.Runtime): FiberRefs
71
+ (childId: FiberId.Single): (self: FiberRefs) => FiberRefs
72
+ (self: FiberRefs, childId: FiberId.Single): FiberRefs
73
73
  } = internal.forkAs
74
74
 
75
75
  /**
@@ -105,8 +105,8 @@ export const getOrDefault: {
105
105
  * @category utils
106
106
  */
107
107
  export const joinAs: {
108
- (fiberId: FiberId.Runtime, that: FiberRefs): (self: FiberRefs) => FiberRefs
109
- (self: FiberRefs, fiberId: FiberId.Runtime, that: FiberRefs): FiberRefs
108
+ (fiberId: FiberId.Single, that: FiberRefs): (self: FiberRefs) => FiberRefs
109
+ (self: FiberRefs, fiberId: FiberId.Single, that: FiberRefs): FiberRefs
110
110
  } = internal.joinAs
111
111
 
112
112
  /**
@@ -126,7 +126,7 @@ export const setAll: (self: FiberRefs) => Effect.Effect<void> = internal.setAll
126
126
  export const updateAs: {
127
127
  <A>(
128
128
  options: {
129
- readonly fiberId: FiberId.Runtime
129
+ readonly fiberId: FiberId.Single
130
130
  readonly fiberRef: FiberRef.FiberRef<A>
131
131
  readonly value: A
132
132
  }
@@ -134,7 +134,7 @@ export const updateAs: {
134
134
  <A>(
135
135
  self: FiberRefs,
136
136
  options: {
137
- readonly fiberId: FiberId.Runtime
137
+ readonly fiberId: FiberId.Single
138
138
  readonly fiberRef: FiberRef.FiberRef<A>
139
139
  readonly value: A
140
140
  }
@@ -150,16 +150,16 @@ export const updateAs: {
150
150
  export const updateManyAs: {
151
151
  (
152
152
  options: {
153
- readonly forkAs?: FiberId.Runtime | undefined
153
+ readonly forkAs?: FiberId.Single | undefined
154
154
  readonly entries: readonly [
155
155
  readonly [
156
156
  FiberRef.FiberRef<any>,
157
- readonly [readonly [FiberId.Runtime, any], ...Array<readonly [FiberId.Runtime, any]>]
157
+ readonly [readonly [FiberId.Single, any], ...Array<readonly [FiberId.Single, any]>]
158
158
  ],
159
159
  ...Array<
160
160
  readonly [
161
161
  FiberRef.FiberRef<any>,
162
- readonly [readonly [FiberId.Runtime, any], ...Array<readonly [FiberId.Runtime, any]>]
162
+ readonly [readonly [FiberId.Single, any], ...Array<readonly [FiberId.Single, any]>]
163
163
  ]
164
164
  >
165
165
  ]
@@ -168,16 +168,16 @@ export const updateManyAs: {
168
168
  (
169
169
  self: FiberRefs,
170
170
  options: {
171
- readonly forkAs?: FiberId.Runtime | undefined
171
+ readonly forkAs?: FiberId.Single | undefined
172
172
  readonly entries: readonly [
173
173
  readonly [
174
174
  FiberRef.FiberRef<any>,
175
- readonly [readonly [FiberId.Runtime, any], ...Array<readonly [FiberId.Runtime, any]>]
175
+ readonly [readonly [FiberId.Single, any], ...Array<readonly [FiberId.Single, any]>]
176
176
  ],
177
177
  ...Array<
178
178
  readonly [
179
179
  FiberRef.FiberRef<any>,
180
- readonly [readonly [FiberId.Runtime, any], ...Array<readonly [FiberId.Runtime, any]>]
180
+ readonly [readonly [FiberId.Single, any], ...Array<readonly [FiberId.Single, any]>]
181
181
  ]
182
182
  >
183
183
  ]
@@ -192,7 +192,7 @@ export const updateManyAs: {
192
192
  * @category unsafe
193
193
  */
194
194
  export const unsafeMake: (
195
- fiberRefLocals: Map<FiberRef.FiberRef<any>, Arr.NonEmptyReadonlyArray<readonly [FiberId.Runtime, any]>>
195
+ fiberRefLocals: Map<FiberRef.FiberRef<any>, Arr.NonEmptyReadonlyArray<readonly [FiberId.Single, any]>>
196
196
  ) => FiberRefs = internal.unsafeMake
197
197
 
198
198
  /**
package/src/Function.ts CHANGED
@@ -202,6 +202,25 @@ export interface FunctionN<A extends ReadonlyArray<unknown>, B> {
202
202
  */
203
203
  export const identity = <A>(a: A): A => a
204
204
 
205
+ /**
206
+ * A function that ensures that the type of an expression matches some type,
207
+ * without changing the resulting type of that expression.
208
+ *
209
+ * @example
210
+ * import { satisfies } from "effect/Function"
211
+ *
212
+ * const test1 = satisfies<number>()(5 as const)
213
+ * //^? const test: 5
214
+ * // @ts-expect-error
215
+ * const test2 = satisfies<string>()(5)
216
+ * //^? Argument of type 'number' is not assignable to parameter of type 'string'
217
+ *
218
+ * assert.deepStrictEqual(satisfies<number>()(5), 5)
219
+ *
220
+ * @since 2.0.0
221
+ */
222
+ export const satisfies = <A>() => <B extends A>(b: B) => b
223
+
205
224
  /**
206
225
  * Casts the result to the specified type.
207
226
  *
package/src/Random.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  * @since 2.0.0
3
3
  */
4
4
  import type * as Chunk from "./Chunk.js"
5
+ import type * as Context from "./Context.js"
5
6
  import type * as Effect from "./Effect.js"
6
7
  import * as defaultServices from "./internal/defaultServices.js"
7
8
  import * as internal from "./internal/random.js"
@@ -111,3 +112,9 @@ export const shuffle: <A>(elements: Iterable<A>) => Effect.Effect<Chunk.Chunk<A>
111
112
  */
112
113
  export const randomWith: <A, E, R>(f: (random: Random) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> =
113
114
  defaultServices.randomWith
115
+
116
+ /**
117
+ * @since 2.0.0
118
+ * @category context
119
+ */
120
+ export const Random: Context.Tag<Random, Random> = internal.randomTag
@@ -160,6 +160,43 @@ export const around: {
160
160
  ): RequestResolver<A, R | R2 | R3>
161
161
  } = internal.around
162
162
 
163
+ /**
164
+ * A data source aspect that executes requests between two effects, `before`
165
+ * and `after`, where the result of `before` can be used by `after`.
166
+ *
167
+ * The `before` and `after` effects are provided with the requests being executed.
168
+ *
169
+ * @since 2.0.0
170
+ * @category combinators
171
+ * @example
172
+ * import { Effect, Request, RequestResolver } from "effect"
173
+ *
174
+ * interface GetUserById extends Request.Request<unknown> {
175
+ * readonly id: number
176
+ * }
177
+ *
178
+ * const resolver = RequestResolver.fromFunction(
179
+ * (request: GetUserById) => ({ id: request.id, name: "John" })
180
+ * )
181
+ *
182
+ * RequestResolver.aroundRequests(
183
+ * resolver,
184
+ * (requests) => Effect.log(`got ${requests.length} requests`),
185
+ * (requests, _) => Effect.log(`finised running ${requests.length} requests`)
186
+ * )
187
+ */
188
+ export const aroundRequests: {
189
+ <A, R2, A2, R3, _>(
190
+ before: (requests: ReadonlyArray<Types.NoInfer<A>>) => Effect.Effect<A2, never, R2>,
191
+ after: (requests: ReadonlyArray<Types.NoInfer<A>>, _: A2) => Effect.Effect<_, never, R3>
192
+ ): <R>(self: RequestResolver<A, R>) => RequestResolver<A, R2 | R3 | R>
193
+ <R, A, R2, A2, R3, _>(
194
+ self: RequestResolver<A, R>,
195
+ before: (requests: ReadonlyArray<Types.NoInfer<A>>) => Effect.Effect<A2, never, R2>,
196
+ after: (requests: ReadonlyArray<Types.NoInfer<A>>, _: A2) => Effect.Effect<_, never, R3>
197
+ ): RequestResolver<A, R | R2 | R3>
198
+ } = internal.aroundRequests
199
+
163
200
  /**
164
201
  * Returns a data source that executes at most `n` requests in parallel.
165
202
  *
package/src/Runtime.ts CHANGED
@@ -7,6 +7,7 @@ import type * as Effect from "./Effect.js"
7
7
  import type * as Exit from "./Exit.js"
8
8
  import type * as Fiber from "./Fiber.js"
9
9
  import type * as FiberId from "./FiberId.js"
10
+ import type * as FiberRef from "./FiberRef.js"
10
11
  import type * as FiberRefs from "./FiberRefs.js"
11
12
  import type { Inspectable } from "./Inspectable.js"
12
13
  import * as internal from "./internal/runtime.js"
@@ -277,3 +278,53 @@ export const provideService: {
277
278
  <I, S>(tag: Context.Tag<I, S>, service: S): <R>(self: Runtime<R>) => Runtime<I | R>
278
279
  <R, I, S>(self: Runtime<R>, tag: Context.Tag<I, S>, service: S): Runtime<R | I>
279
280
  } = internal.provideService
281
+
282
+ /**
283
+ * @since 2.0.0
284
+ * @category fiber refs
285
+ */
286
+ export const updateFiberRefs: {
287
+ (f: (fiberRefs: FiberRefs.FiberRefs) => FiberRefs.FiberRefs): <R>(self: Runtime<R>) => Runtime<R>
288
+ <R>(self: Runtime<R>, f: (fiberRefs: FiberRefs.FiberRefs) => FiberRefs.FiberRefs): Runtime<R>
289
+ } = internal.updateFiberRefs
290
+
291
+ /**
292
+ * @since 2.0.0
293
+ * @category fiber refs
294
+ * @example
295
+ * import { Effect, FiberRef, Runtime } from "effect"
296
+ *
297
+ * const ref = FiberRef.unsafeMake(0)
298
+ *
299
+ * const updatedRuntime = Runtime.defaultRuntime.pipe(
300
+ * Runtime.setFiberRef(ref, 1)
301
+ * )
302
+ *
303
+ * // returns 1
304
+ * const result = Runtime.runSync(updatedRuntime)(FiberRef.get(ref))
305
+ */
306
+ export const setFiberRef: {
307
+ <A>(fiberRef: FiberRef.FiberRef<A>, value: A): <R>(self: Runtime<R>) => Runtime<R>
308
+ <R, A>(self: Runtime<R>, fiberRef: FiberRef.FiberRef<A>, value: A): Runtime<R>
309
+ } = internal.setFiberRef
310
+
311
+ /**
312
+ * @since 2.0.0
313
+ * @category fiber refs
314
+ * @example
315
+ * import { Effect, FiberRef, Runtime } from "effect"
316
+ *
317
+ * const ref = FiberRef.unsafeMake(0)
318
+ *
319
+ * const updatedRuntime = Runtime.defaultRuntime.pipe(
320
+ * Runtime.setFiberRef(ref, 1),
321
+ * Runtime.deleteFiberRef(ref)
322
+ * )
323
+ *
324
+ * // returns 0
325
+ * const result = Runtime.runSync(updatedRuntime)(FiberRef.get(ref))
326
+ */
327
+ export const deleteFiberRef: {
328
+ <A>(fiberRef: FiberRef.FiberRef<A>): <R>(self: Runtime<R>) => Runtime<R>
329
+ <R, A>(self: Runtime<R>, fiberRef: FiberRef.FiberRef<A>): Runtime<R>
330
+ } = internal.deleteFiberRef
@@ -12,6 +12,7 @@ import type * as MutableRef from "./MutableRef.js"
12
12
  import { hasProperty } from "./Predicate.js"
13
13
  import type * as SortedSet from "./SortedSet.js"
14
14
  import type * as Types from "./Types.js"
15
+
15
16
  /** @internal */
16
17
  const TestAnnotationSymbolKey = "effect/TestAnnotation"
17
18
 
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @since 2.0.0
3
3
  */
4
- import { dual, pipe } from "./Function.js"
4
+ import { dual } from "./Function.js"
5
+ import * as HashMap from "./HashMap.js"
5
6
  import { hasProperty } from "./Predicate.js"
6
7
  import type * as TestAnnotation from "./TestAnnotation.js"
7
8
 
@@ -23,13 +24,13 @@ export type TestAnnotationMapTypeId = typeof TestAnnotationMapTypeId
23
24
  export interface TestAnnotationMap {
24
25
  readonly [TestAnnotationMapTypeId]: TestAnnotationMapTypeId
25
26
  /** @internal */
26
- readonly map: ReadonlyMap<TestAnnotation.TestAnnotation<unknown>, unknown>
27
+ readonly map: HashMap.HashMap<TestAnnotation.TestAnnotation<any>, any>
27
28
  }
28
29
 
29
30
  /** @internal */
30
31
  class TestAnnotationMapImpl implements TestAnnotationMap {
31
32
  readonly [TestAnnotationMapTypeId]: TestAnnotationMapTypeId = TestAnnotationMapTypeId
32
- constructor(readonly map: ReadonlyMap<TestAnnotation.TestAnnotation<unknown>, unknown>) {
33
+ constructor(readonly map: HashMap.HashMap<TestAnnotation.TestAnnotation<any>, any>) {
33
34
  }
34
35
  }
35
36
 
@@ -41,12 +42,12 @@ export const isTestAnnotationMap = (u: unknown): u is TestAnnotationMap => hasPr
41
42
  /**
42
43
  * @since 2.0.0
43
44
  */
44
- export const empty: (_: void) => TestAnnotationMap = () => new TestAnnotationMapImpl(new Map())
45
+ export const empty: (_: void) => TestAnnotationMap = () => new TestAnnotationMapImpl(HashMap.empty())
45
46
 
46
47
  /**
47
48
  * @since 2.0.0
48
49
  */
49
- export const make = (map: ReadonlyMap<TestAnnotation.TestAnnotation<unknown>, unknown>): TestAnnotationMap => {
50
+ export const make = (map: HashMap.HashMap<TestAnnotation.TestAnnotation<any>, any>): TestAnnotationMap => {
50
51
  return new TestAnnotationMapImpl(map)
51
52
  }
52
53
 
@@ -56,11 +57,7 @@ export const make = (map: ReadonlyMap<TestAnnotation.TestAnnotation<unknown>, un
56
57
  export const overwrite = dual<
57
58
  <A>(key: TestAnnotation.TestAnnotation<A>, value: A) => (self: TestAnnotationMap) => TestAnnotationMap,
58
59
  <A>(self: TestAnnotationMap, key: TestAnnotation.TestAnnotation<A>, value: A) => TestAnnotationMap
59
- >(3, (self, key, value) =>
60
- make(
61
- (self.map as Map<TestAnnotation.TestAnnotation<unknown>, unknown>)
62
- .set(key as TestAnnotation.TestAnnotation<unknown>, value)
63
- ))
60
+ >(3, (self, key, value) => make(HashMap.set(self.map, key, value)))
64
61
 
65
62
  /**
66
63
  * @since 2.0.0
@@ -69,11 +66,11 @@ export const update = dual<
69
66
  <A>(key: TestAnnotation.TestAnnotation<A>, f: (value: A) => A) => (self: TestAnnotationMap) => TestAnnotationMap,
70
67
  <A>(self: TestAnnotationMap, key: TestAnnotation.TestAnnotation<A>, f: (value: A) => A) => TestAnnotationMap
71
68
  >(3, <A>(self: TestAnnotationMap, key: TestAnnotation.TestAnnotation<A>, f: (value: A) => A) => {
72
- let value = self.map.get(key as TestAnnotation.TestAnnotation<unknown>)
73
- if (value === undefined) {
74
- value = key.initial
69
+ let value = key.initial
70
+ if (HashMap.has(self.map, key.identifier)) {
71
+ value = HashMap.unsafeGet(self.map, key.identifier) as A
75
72
  }
76
- return pipe(self, overwrite(key, f(value as A)))
73
+ return overwrite(self, key, f(value))
77
74
  })
78
75
 
79
76
  /**
@@ -86,11 +83,10 @@ export const get = dual<
86
83
  <A>(key: TestAnnotation.TestAnnotation<A>) => (self: TestAnnotationMap) => A,
87
84
  <A>(self: TestAnnotationMap, key: TestAnnotation.TestAnnotation<A>) => A
88
85
  >(2, <A>(self: TestAnnotationMap, key: TestAnnotation.TestAnnotation<A>) => {
89
- const value = self.map.get(key as TestAnnotation.TestAnnotation<unknown>)
90
- if (value === undefined) {
91
- return key.initial as A
86
+ if (HashMap.has(self.map, key.identifier)) {
87
+ return HashMap.unsafeGet(self.map, key.identifier) as A
92
88
  }
93
- return value as A
89
+ return key.initial
94
90
  })
95
91
 
96
92
  /**
@@ -110,13 +106,13 @@ export const combine = dual<
110
106
  (that: TestAnnotationMap) => (self: TestAnnotationMap) => TestAnnotationMap,
111
107
  (self: TestAnnotationMap, that: TestAnnotationMap) => TestAnnotationMap
112
108
  >(2, (self, that) => {
113
- const result = new Map<TestAnnotation.TestAnnotation<unknown>, unknown>(self.map)
109
+ let result = self.map
114
110
  for (const entry of that.map) {
115
- if (result.has(entry[0])) {
116
- const value = result.get(entry[0])!
117
- result.set(entry[0], entry[0].combine(value, entry[1]))
111
+ if (HashMap.has(result, entry[0])) {
112
+ const value = HashMap.get(result, entry[0])!
113
+ result = HashMap.set(result, entry[0], entry[0].combine(value, entry[1]))
118
114
  } else {
119
- result.set(entry[0], entry[1])
115
+ result = HashMap.set(result, entry[0], entry[1])
120
116
  }
121
117
  }
122
118
  return make(result)
@@ -40,6 +40,9 @@ export type TestAnnotationsTypeId = typeof TestAnnotationsTypeId
40
40
  export interface TestAnnotations {
41
41
  readonly [TestAnnotationsTypeId]: TestAnnotationsTypeId
42
42
 
43
+ /**
44
+ * A ref containing the bacnking map for all annotations
45
+ */
43
46
  readonly ref: Ref.Ref<TestAnnotationMap.TestAnnotationMap>
44
47
 
45
48
  /**
@@ -1040,12 +1040,17 @@ export const prettyErrorMessage = (u: unknown): string => {
1040
1040
  return `Error: ${u}`
1041
1041
  }
1042
1042
  // 2)
1043
- if (
1044
- hasProperty(u, "toString") &&
1045
- isFunction(u["toString"]) &&
1046
- u["toString"] !== Object.prototype.toString
1047
- ) {
1048
- return u["toString"]()
1043
+ try {
1044
+ if (
1045
+ hasProperty(u, "toString") &&
1046
+ isFunction(u["toString"]) &&
1047
+ u["toString"] !== Object.prototype.toString &&
1048
+ u["toString"] !== Array.prototype.toString
1049
+ ) {
1050
+ return u["toString"]()
1051
+ }
1052
+ } catch {
1053
+ // something's off, rollback to json
1049
1054
  }
1050
1055
  // 3)
1051
1056
  return `Error: ${JSON.stringify(u)}`
@@ -7,6 +7,7 @@ import { dual, pipe } from "../Function.js"
7
7
  import * as RA from "../ReadonlyArray.js"
8
8
  import type * as Request from "../Request.js"
9
9
  import type * as RequestResolver from "../RequestResolver.js"
10
+ import type { NoInfer } from "../Types.js"
10
11
  import * as core from "./core.js"
11
12
  import { invokeWithInterrupt, zipWithOptions } from "./fiberRuntime.js"
12
13
  import { complete } from "./request.js"
@@ -71,6 +72,32 @@ export const around = dual<
71
72
  Chunk.make("Around", self, before, after)
72
73
  ))
73
74
 
75
+ /** @internal */
76
+ export const aroundRequests = dual<
77
+ <A, R2, A2, R3, _>(
78
+ before: (requests: ReadonlyArray<NoInfer<A>>) => Effect.Effect<A2, never, R2>,
79
+ after: (requests: ReadonlyArray<NoInfer<A>>, _: A2) => Effect.Effect<_, never, R3>
80
+ ) => <R>(
81
+ self: RequestResolver.RequestResolver<A, R>
82
+ ) => RequestResolver.RequestResolver<A, R | R2 | R3>,
83
+ <R, A, R2, A2, R3, _>(
84
+ self: RequestResolver.RequestResolver<A, R>,
85
+ before: (requests: ReadonlyArray<NoInfer<A>>) => Effect.Effect<A2, never, R2>,
86
+ after: (requests: ReadonlyArray<NoInfer<A>>, _: A2) => Effect.Effect<_, never, R3>
87
+ ) => RequestResolver.RequestResolver<A, R | R2 | R3>
88
+ >(3, (self, before, after) =>
89
+ new core.RequestResolverImpl(
90
+ (requests) => {
91
+ const flatRequests = requests.flatMap((chunk) => chunk.map((entry) => entry.request))
92
+ return core.acquireUseRelease(
93
+ before(flatRequests),
94
+ () => self.runAll(requests),
95
+ (a2) => after(flatRequests, a2)
96
+ )
97
+ },
98
+ Chunk.make("AroundRequests", self, before, after)
99
+ ))
100
+
74
101
  /** @internal */
75
102
  export const batchN = dual<
76
103
  (n: number) => <R, A>(
@@ -58,8 +58,8 @@ export const currentTimeNanos: Effect.Effect<bigint> = clockWith((clock) => cloc
58
58
 
59
59
  /** @internal */
60
60
  export const withClock = dual<
61
- <A extends Clock.Clock>(value: A) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
62
- <A extends Clock.Clock, E, R>(effect: Effect.Effect<A, E, R>, value: A) => Effect.Effect<A, E, R>
61
+ <X extends Clock.Clock>(value: X) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
62
+ <X extends Clock.Clock, A, E, R>(effect: Effect.Effect<A, E, R>, value: X) => Effect.Effect<A, E, R>
63
63
  >(2, (effect, value) =>
64
64
  core.fiberRefLocallyWith(
65
65
  currentServices,
@@ -102,6 +102,16 @@ export const randomWith = <A, E, R>(f: (random: Random.Random) => Effect.Effect<
102
102
  (services) => f(Context.get(services, random.randomTag))
103
103
  )
104
104
 
105
+ /** @internal */
106
+ export const withRandom = dual<
107
+ <X extends Random.Random>(value: X) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
108
+ <X extends Random.Random, A, E, R>(effect: Effect.Effect<A, E, R>, value: X) => Effect.Effect<A, E, R>
109
+ >(2, (effect, value) =>
110
+ core.fiberRefLocallyWith(
111
+ currentServices,
112
+ Context.add(random.randomTag, value)
113
+ )(effect))
114
+
105
115
  /** @internal */
106
116
  export const next: Effect.Effect<number> = randomWith((random) => random.next)
107
117
 
@@ -40,7 +40,9 @@ const emptyHash = Hash.string(`${FiberIdSymbolKey}-${OP_NONE}`)
40
40
  /** @internal */
41
41
  class None implements FiberId.None {
42
42
  readonly [FiberIdTypeId]: FiberId.FiberIdTypeId = FiberIdTypeId
43
- readonly _tag = OP_NONE;
43
+ readonly _tag = OP_NONE
44
+ readonly id = -1
45
+ readonly startTimeMillis = -1;
44
46
  [Hash.symbol](): number {
45
47
  return emptyHash
46
48
  }
@@ -141,15 +143,15 @@ class Composite implements FiberId.Composite {
141
143
  }
142
144
 
143
145
  /** @internal */
144
- export const none: FiberId.FiberId = new None()
146
+ export const none: FiberId.None = new None()
145
147
 
146
148
  /** @internal */
147
- export const runtime = (id: number, startTimeMillis: number): FiberId.FiberId => {
149
+ export const runtime = (id: number, startTimeMillis: number): FiberId.Runtime => {
148
150
  return new Runtime(id, startTimeMillis)
149
151
  }
150
152
 
151
153
  /** @internal */
152
- export const composite = (left: FiberId.FiberId, right: FiberId.FiberId): FiberId.FiberId => {
154
+ export const composite = (left: FiberId.FiberId, right: FiberId.FiberId): FiberId.Composite => {
153
155
  return new Composite(left, right)
154
156
  }
155
157