effect 4.0.0-rc.118 → 4.0.1

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 (254) hide show
  1. package/README.md +17 -4
  2. package/dist/Array.d.ts +25 -25
  3. package/dist/Array.d.ts.map +1 -1
  4. package/dist/Array.js +16 -16
  5. package/dist/Array.js.map +1 -1
  6. package/dist/Cache.d.ts.map +1 -1
  7. package/dist/Cache.js +20 -16
  8. package/dist/Cache.js.map +1 -1
  9. package/dist/Cause.d.ts.map +1 -1
  10. package/dist/Cause.js +1 -1
  11. package/dist/Cause.js.map +1 -1
  12. package/dist/Chunk.d.ts +26 -26
  13. package/dist/Chunk.d.ts.map +1 -1
  14. package/dist/Chunk.js +15 -15
  15. package/dist/Chunk.js.map +1 -1
  16. package/dist/Effect.d.ts +167 -39
  17. package/dist/Effect.d.ts.map +1 -1
  18. package/dist/Effect.js +16 -10
  19. package/dist/Effect.js.map +1 -1
  20. package/dist/HashRing.d.ts.map +1 -1
  21. package/dist/HashRing.js +13 -5
  22. package/dist/HashRing.js.map +1 -1
  23. package/dist/MutableHashMap.d.ts.map +1 -1
  24. package/dist/MutableHashMap.js +4 -22
  25. package/dist/MutableHashMap.js.map +1 -1
  26. package/dist/Option.d.ts +17 -17
  27. package/dist/Option.d.ts.map +1 -1
  28. package/dist/Option.js +6 -6
  29. package/dist/Option.js.map +1 -1
  30. package/dist/Pool.d.ts +9 -5
  31. package/dist/Pool.d.ts.map +1 -1
  32. package/dist/Pool.js +34 -41
  33. package/dist/Pool.js.map +1 -1
  34. package/dist/Queue.d.ts +19 -2
  35. package/dist/Queue.d.ts.map +1 -1
  36. package/dist/Queue.js +9 -4
  37. package/dist/Queue.js.map +1 -1
  38. package/dist/RcMap.d.ts.map +1 -1
  39. package/dist/RcMap.js +16 -1
  40. package/dist/RcMap.js.map +1 -1
  41. package/dist/Record.d.ts +14 -14
  42. package/dist/Record.d.ts.map +1 -1
  43. package/dist/Record.js +10 -10
  44. package/dist/Record.js.map +1 -1
  45. package/dist/Schema.d.ts +37 -21
  46. package/dist/Schema.d.ts.map +1 -1
  47. package/dist/Schema.js +29 -10
  48. package/dist/Schema.js.map +1 -1
  49. package/dist/SchemaAST.d.ts.map +1 -1
  50. package/dist/SchemaAST.js +116 -97
  51. package/dist/SchemaAST.js.map +1 -1
  52. package/dist/SchemaRepresentation.d.ts +3 -1
  53. package/dist/SchemaRepresentation.d.ts.map +1 -1
  54. package/dist/SchemaRepresentation.js +3 -1
  55. package/dist/SchemaRepresentation.js.map +1 -1
  56. package/dist/ScopedCache.d.ts.map +1 -1
  57. package/dist/ScopedCache.js +24 -16
  58. package/dist/ScopedCache.js.map +1 -1
  59. package/dist/Stream.d.ts +45 -6
  60. package/dist/Stream.d.ts.map +1 -1
  61. package/dist/Stream.js +55 -44
  62. package/dist/Stream.js.map +1 -1
  63. package/dist/ai/LanguageModel.d.ts +8 -0
  64. package/dist/ai/LanguageModel.d.ts.map +1 -1
  65. package/dist/ai/LanguageModel.js +13 -2
  66. package/dist/ai/LanguageModel.js.map +1 -1
  67. package/dist/ai/McpSchema.d.ts +402 -402
  68. package/dist/ai/McpSchema.d.ts.map +1 -1
  69. package/dist/ai/McpSchema.js +1 -1
  70. package/dist/ai/McpSchema.js.map +1 -1
  71. package/dist/ai/McpServer.d.ts.map +1 -1
  72. package/dist/ai/McpServer.js +11 -3
  73. package/dist/ai/McpServer.js.map +1 -1
  74. package/dist/ai/Response.d.ts.map +1 -1
  75. package/dist/ai/Response.js +22 -12
  76. package/dist/ai/Response.js.map +1 -1
  77. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +1 -0
  78. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  79. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +1 -0
  80. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  81. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +1 -0
  82. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  83. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +1 -0
  84. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  85. package/dist/ai/internal/mcpSchema/v2024_11_05.js +3 -1
  86. package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
  87. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  88. package/dist/cluster/ClusterWorkflowEngine.js +16 -3
  89. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  90. package/dist/cluster/MessageStorage.d.ts +32 -8
  91. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  92. package/dist/cluster/MessageStorage.js +2 -1
  93. package/dist/cluster/MessageStorage.js.map +1 -1
  94. package/dist/cluster/Sharding.d.ts +5 -2
  95. package/dist/cluster/Sharding.d.ts.map +1 -1
  96. package/dist/cluster/Sharding.js +15 -8
  97. package/dist/cluster/Sharding.js.map +1 -1
  98. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  99. package/dist/cluster/SqlMessageStorage.js +36 -16
  100. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  101. package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
  102. package/dist/cluster/SqlRunnerStorage.js +30 -44
  103. package/dist/cluster/SqlRunnerStorage.js.map +1 -1
  104. package/dist/cluster/internal/entityManager.js +63 -62
  105. package/dist/cluster/internal/entityManager.js.map +1 -1
  106. package/dist/cluster/internal/interruptors.js +8 -0
  107. package/dist/cluster/internal/interruptors.js.map +1 -1
  108. package/dist/cluster/internal/resourceMap.js +39 -14
  109. package/dist/cluster/internal/resourceMap.js.map +1 -1
  110. package/dist/cluster/internal/resourceRef.js +168 -87
  111. package/dist/cluster/internal/resourceRef.js.map +1 -1
  112. package/dist/http/HttpEffect.d.ts +1 -0
  113. package/dist/http/HttpEffect.d.ts.map +1 -1
  114. package/dist/http/HttpEffect.js +29 -22
  115. package/dist/http/HttpEffect.js.map +1 -1
  116. package/dist/http/HttpMiddleware.d.ts.map +1 -1
  117. package/dist/http/HttpMiddleware.js +3 -2
  118. package/dist/http/HttpMiddleware.js.map +1 -1
  119. package/dist/http/HttpStaticServer.d.ts.map +1 -1
  120. package/dist/http/HttpStaticServer.js +14 -0
  121. package/dist/http/HttpStaticServer.js.map +1 -1
  122. package/dist/http/HttpTraceContext.d.ts +1 -1
  123. package/dist/http/HttpTraceContext.d.ts.map +1 -1
  124. package/dist/http/HttpTraceContext.js +4 -4
  125. package/dist/http/HttpTraceContext.js.map +1 -1
  126. package/dist/http-api/HttpApiError.d.ts +1 -0
  127. package/dist/http-api/HttpApiError.d.ts.map +1 -1
  128. package/dist/http-api/HttpApiError.js +1 -0
  129. package/dist/http-api/HttpApiError.js.map +1 -1
  130. package/dist/internal/core.js +43 -2
  131. package/dist/internal/core.js.map +1 -1
  132. package/dist/internal/dateTime.js +1 -1
  133. package/dist/internal/dateTime.js.map +1 -1
  134. package/dist/internal/effect.js +138 -165
  135. package/dist/internal/effect.js.map +1 -1
  136. package/dist/internal/rcRef.js +59 -23
  137. package/dist/internal/rcRef.js.map +1 -1
  138. package/dist/internal/schema/annotations.js +1 -7
  139. package/dist/internal/schema/annotations.js.map +1 -1
  140. package/dist/internal/schema/codegen.js +56 -28
  141. package/dist/internal/schema/codegen.js.map +1 -1
  142. package/dist/internal/schema/fromJsonSchemaDocument.js +11 -8
  143. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  144. package/dist/internal/schema/toCodeDocument.js +10 -30
  145. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  146. package/dist/internal/schema/toCodec.js +1 -15
  147. package/dist/internal/schema/toCodec.js.map +1 -1
  148. package/dist/internal/schema/toEquivalence.js +4 -3
  149. package/dist/internal/schema/toEquivalence.js.map +1 -1
  150. package/dist/internal/schema/toFormatter.js +4 -4
  151. package/dist/internal/schema/toFormatter.js.map +1 -1
  152. package/dist/reactivity/Atom.d.ts.map +1 -1
  153. package/dist/reactivity/Atom.js +6 -2
  154. package/dist/reactivity/Atom.js.map +1 -1
  155. package/dist/reactivity/AtomRpc.d.ts +3 -3
  156. package/dist/reactivity/AtomRpc.d.ts.map +1 -1
  157. package/dist/rpc/Rpc.d.ts +2 -2
  158. package/dist/rpc/Rpc.d.ts.map +1 -1
  159. package/dist/rpc/RpcClient.d.ts +7 -7
  160. package/dist/rpc/RpcClient.d.ts.map +1 -1
  161. package/dist/rpc/RpcClient.js +21 -16
  162. package/dist/rpc/RpcClient.js.map +1 -1
  163. package/dist/rpc/RpcMessage.d.ts +1 -1
  164. package/dist/rpc/RpcMessage.d.ts.map +1 -1
  165. package/dist/rpc/RpcServer.d.ts.map +1 -1
  166. package/dist/rpc/RpcServer.js +2 -2
  167. package/dist/rpc/RpcServer.js.map +1 -1
  168. package/dist/rpc/Utils.d.ts +2 -3
  169. package/dist/rpc/Utils.d.ts.map +1 -1
  170. package/dist/rpc/Utils.js +3 -4
  171. package/dist/rpc/Utils.js.map +1 -1
  172. package/dist/schema/SchemaCompiler/runtime.js +6 -1
  173. package/dist/schema/SchemaCompiler/runtime.js.map +1 -1
  174. package/dist/testing/TestSchema.d.ts +234 -6
  175. package/dist/testing/TestSchema.d.ts.map +1 -1
  176. package/dist/testing/TestSchema.js +244 -25
  177. package/dist/testing/TestSchema.js.map +1 -1
  178. package/dist/testing/index.d.ts +1 -0
  179. package/dist/testing/index.d.ts.map +1 -1
  180. package/dist/testing/index.js +1 -0
  181. package/dist/testing/index.js.map +1 -1
  182. package/dist/workflow/DurableDeferred.js +1 -1
  183. package/dist/workflow/DurableDeferred.js.map +1 -1
  184. package/dist/workflow/Workflow.js +1 -1
  185. package/dist/workflow/Workflow.js.map +1 -1
  186. package/dist/workflow/WorkflowEngine.d.ts +2 -0
  187. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  188. package/dist/workflow/WorkflowEngine.js +1 -0
  189. package/dist/workflow/WorkflowEngine.js.map +1 -1
  190. package/package.json +1 -1
  191. package/src/Array.ts +31 -31
  192. package/src/Cache.ts +22 -16
  193. package/src/Cause.ts +1 -1
  194. package/src/Chunk.ts +29 -29
  195. package/src/Effect.ts +170 -39
  196. package/src/HashRing.ts +14 -5
  197. package/src/MutableHashMap.ts +4 -24
  198. package/src/Option.ts +19 -19
  199. package/src/Pool.ts +28 -36
  200. package/src/Queue.ts +26 -6
  201. package/src/RcMap.ts +26 -2
  202. package/src/Record.ts +20 -20
  203. package/src/Schema.ts +48 -24
  204. package/src/SchemaAST.ts +135 -115
  205. package/src/SchemaRepresentation.ts +3 -1
  206. package/src/ScopedCache.ts +27 -16
  207. package/src/Stream.ts +158 -88
  208. package/src/ai/LanguageModel.ts +27 -2
  209. package/src/ai/McpSchema.ts +3 -3
  210. package/src/ai/McpServer.ts +12 -3
  211. package/src/ai/Response.ts +27 -12
  212. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +1 -0
  213. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +1 -0
  214. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +1 -0
  215. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +1 -0
  216. package/src/ai/internal/mcpSchema/v2024_11_05.ts +4 -2
  217. package/src/cluster/ClusterWorkflowEngine.ts +26 -5
  218. package/src/cluster/MessageStorage.ts +22 -5
  219. package/src/cluster/Sharding.ts +32 -28
  220. package/src/cluster/SqlMessageStorage.ts +45 -21
  221. package/src/cluster/SqlRunnerStorage.ts +85 -113
  222. package/src/cluster/internal/entityManager.ts +68 -80
  223. package/src/cluster/internal/interruptors.ts +13 -0
  224. package/src/cluster/internal/resourceMap.ts +55 -17
  225. package/src/cluster/internal/resourceRef.ts +189 -96
  226. package/src/http/HttpEffect.ts +15 -9
  227. package/src/http/HttpMiddleware.ts +8 -2
  228. package/src/http/HttpStaticServer.ts +16 -0
  229. package/src/http/HttpTraceContext.ts +8 -4
  230. package/src/http-api/HttpApiError.ts +1 -0
  231. package/src/internal/core.ts +56 -2
  232. package/src/internal/dateTime.ts +3 -1
  233. package/src/internal/effect.ts +146 -173
  234. package/src/internal/rcRef.ts +83 -33
  235. package/src/internal/schema/annotations.ts +0 -9
  236. package/src/internal/schema/codegen.ts +90 -43
  237. package/src/internal/schema/fromJsonSchemaDocument.ts +5 -3
  238. package/src/internal/schema/toCodeDocument.ts +10 -47
  239. package/src/internal/schema/toCodec.ts +3 -16
  240. package/src/internal/schema/toEquivalence.ts +4 -5
  241. package/src/internal/schema/toFormatter.ts +4 -6
  242. package/src/reactivity/Atom.ts +6 -2
  243. package/src/reactivity/AtomRpc.ts +5 -5
  244. package/src/rpc/Rpc.ts +2 -2
  245. package/src/rpc/RpcClient.ts +35 -32
  246. package/src/rpc/RpcMessage.ts +1 -1
  247. package/src/rpc/RpcServer.ts +2 -1
  248. package/src/rpc/Utils.ts +4 -10
  249. package/src/schema/SchemaCompiler/runtime.ts +17 -1
  250. package/src/testing/TestSchema.ts +315 -63
  251. package/src/testing/index.ts +1 -0
  252. package/src/workflow/DurableDeferred.ts +1 -1
  253. package/src/workflow/Workflow.ts +1 -1
  254. package/src/workflow/WorkflowEngine.ts +4 -0
package/dist/Effect.d.ts CHANGED
@@ -391,13 +391,13 @@ export declare const all: <const Arg extends Iterable<Effect<any, any, any>> | R
391
391
  readonly mode?: "default" | "result" | undefined;
392
392
  }>(arg: Arg, options?: O) => All.Return<Arg, O>;
393
393
  /**
394
- * Applies an effectful function to each element and partitions failures and
395
- * successes.
394
+ * Applies an effectful function to each element and partitions successes and
395
+ * failures.
396
396
  *
397
397
  * **Details**
398
398
  *
399
- * The returned tuple is `[excluded, satisfying]`, where `excluded` contains
400
- * all failures and `satisfying` contains all successes.
399
+ * The returned tuple is `[passes, fails]`, where `passes` contains all
400
+ * successes and `fails` contains all failures.
401
401
  *
402
402
  * This function runs every effect and never fails. Use `concurrency` to control
403
403
  * parallelism.
@@ -411,7 +411,7 @@ export declare const all: <const Arg extends Iterable<Effect<any, any, any>> | R
411
411
  * n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
412
412
  * )
413
413
  *
414
- * await Effect.runPromise(program) // => [['0 is even', '2 is even'], [1, 3]]
414
+ * await Effect.runPromise(program) // => [[1, 3], ['0 is even', '2 is even']]
415
415
  * ```
416
416
  *
417
417
  * @category collecting
@@ -419,13 +419,13 @@ export declare const all: <const Arg extends Iterable<Effect<any, any, any>> | R
419
419
  */
420
420
  export declare const partition: {
421
421
  /**
422
- * Applies an effectful function to each element and partitions failures and
423
- * successes.
422
+ * Applies an effectful function to each element and partitions successes and
423
+ * failures.
424
424
  *
425
425
  * **Details**
426
426
  *
427
- * The returned tuple is `[excluded, satisfying]`, where `excluded` contains
428
- * all failures and `satisfying` contains all successes.
427
+ * The returned tuple is `[passes, fails]`, where `passes` contains all
428
+ * successes and `fails` contains all failures.
429
429
  *
430
430
  * This function runs every effect and never fails. Use `concurrency` to control
431
431
  * parallelism.
@@ -439,7 +439,7 @@ export declare const partition: {
439
439
  * n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
440
440
  * )
441
441
  *
442
- * await Effect.runPromise(program) // => [['0 is even', '2 is even'], [1, 3]]
442
+ * await Effect.runPromise(program) // => [[1, 3], ['0 is even', '2 is even']]
443
443
  * ```
444
444
  *
445
445
  * @category collecting
@@ -447,15 +447,15 @@ export declare const partition: {
447
447
  */
448
448
  <A, B, E, R>(f: (a: A, i: number) => Effect<B, E, R>, options?: {
449
449
  readonly concurrency?: Concurrency | undefined;
450
- }): (elements: Iterable<A>) => Effect<[excluded: Array<E>, satisfying: Array<B>], never, R>;
450
+ }): (elements: Iterable<A>) => Effect<[passes: Array<B>, fails: Array<E>], never, R>;
451
451
  /**
452
- * Applies an effectful function to each element and partitions failures and
453
- * successes.
452
+ * Applies an effectful function to each element and partitions successes and
453
+ * failures.
454
454
  *
455
455
  * **Details**
456
456
  *
457
- * The returned tuple is `[excluded, satisfying]`, where `excluded` contains
458
- * all failures and `satisfying` contains all successes.
457
+ * The returned tuple is `[passes, fails]`, where `passes` contains all
458
+ * successes and `fails` contains all failures.
459
459
  *
460
460
  * This function runs every effect and never fails. Use `concurrency` to control
461
461
  * parallelism.
@@ -469,7 +469,7 @@ export declare const partition: {
469
469
  * n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
470
470
  * )
471
471
  *
472
- * await Effect.runPromise(program) // => [['0 is even', '2 is even'], [1, 3]]
472
+ * await Effect.runPromise(program) // => [[1, 3], ['0 is even', '2 is even']]
473
473
  * ```
474
474
  *
475
475
  * @category collecting
@@ -477,7 +477,7 @@ export declare const partition: {
477
477
  */
478
478
  <A, B, E, R>(elements: Iterable<A>, f: (a: A, i: number) => Effect<B, E, R>, options?: {
479
479
  readonly concurrency?: Concurrency | undefined;
480
- }): Effect<[excluded: Array<E>, satisfying: Array<B>], never, R>;
480
+ }): Effect<[passes: Array<B>, fails: Array<E>], never, R>;
481
481
  };
482
482
  /**
483
483
  * Reduces elements from left to right with an effectful accumulator function.
@@ -12919,6 +12919,11 @@ export declare const onExitFilter: {
12919
12919
  * evaluations of the same effect will return the cached result without
12920
12920
  * re-executing the logic.
12921
12921
  *
12922
+ * Concurrent callers share the pending computation, which is interrupted only
12923
+ * once every caller waiting on it has been interrupted. Interrupted
12924
+ * computations are never cached, so the next evaluation starts a fresh
12925
+ * computation.
12926
+ *
12922
12927
  * **Example** (Memoizing an effect until invalidated)
12923
12928
  *
12924
12929
  * ```ts import.meta.vitest
@@ -12979,11 +12984,12 @@ export declare const cached: <A, E, R>(self: Effect<A, E, R>) => Effect<Effect<A
12979
12984
  * `Duration.Input`. The function runs once after each fresh computation,
12980
12985
  * including failures, so successes and failures can have different TTLs. It
12981
12986
  * does not run when the cache is created or when a cached result is reused.
12982
- * The callback also receives interruption exits, which are cached for the
12983
- * returned duration.
12987
+ * Interrupted computations are never cached and do not call the function.
12984
12988
  *
12985
12989
  * The TTL starts when the computation completes. Concurrent callers share the
12986
- * pending computation. A zero TTL expires immediately, and an infinite TTL
12990
+ * pending computation, which is interrupted only once every caller waiting on
12991
+ * it has been interrupted. The next evaluation then starts a fresh
12992
+ * computation. A zero TTL expires immediately, and an infinite TTL
12987
12993
  * keeps the result indefinitely.
12988
12994
  *
12989
12995
  * **Example** (Memoizing an effect with TTL)
@@ -13063,11 +13069,12 @@ export declare const cachedWithTTL: {
13063
13069
  * `Duration.Input`. The function runs once after each fresh computation,
13064
13070
  * including failures, so successes and failures can have different TTLs. It
13065
13071
  * does not run when the cache is created or when a cached result is reused.
13066
- * The callback also receives interruption exits, which are cached for the
13067
- * returned duration.
13072
+ * Interrupted computations are never cached and do not call the function.
13068
13073
  *
13069
13074
  * The TTL starts when the computation completes. Concurrent callers share the
13070
- * pending computation. A zero TTL expires immediately, and an infinite TTL
13075
+ * pending computation, which is interrupted only once every caller waiting on
13076
+ * it has been interrupted. The next evaluation then starts a fresh
13077
+ * computation. A zero TTL expires immediately, and an infinite TTL
13071
13078
  * keeps the result indefinitely.
13072
13079
  *
13073
13080
  * **Example** (Memoizing an effect with TTL)
@@ -13147,11 +13154,12 @@ export declare const cachedWithTTL: {
13147
13154
  * `Duration.Input`. The function runs once after each fresh computation,
13148
13155
  * including failures, so successes and failures can have different TTLs. It
13149
13156
  * does not run when the cache is created or when a cached result is reused.
13150
- * The callback also receives interruption exits, which are cached for the
13151
- * returned duration.
13157
+ * Interrupted computations are never cached and do not call the function.
13152
13158
  *
13153
13159
  * The TTL starts when the computation completes. Concurrent callers share the
13154
- * pending computation. A zero TTL expires immediately, and an infinite TTL
13160
+ * pending computation, which is interrupted only once every caller waiting on
13161
+ * it has been interrupted. The next evaluation then starts a fresh
13162
+ * computation. A zero TTL expires immediately, and an infinite TTL
13155
13163
  * keeps the result indefinitely.
13156
13164
  *
13157
13165
  * **Example** (Memoizing an effect with TTL)
@@ -13231,11 +13239,12 @@ export declare const cachedWithTTL: {
13231
13239
  * `Duration.Input`. The function runs once after each fresh computation,
13232
13240
  * including failures, so successes and failures can have different TTLs. It
13233
13241
  * does not run when the cache is created or when a cached result is reused.
13234
- * The callback also receives interruption exits, which are cached for the
13235
- * returned duration.
13242
+ * Interrupted computations are never cached and do not call the function.
13236
13243
  *
13237
13244
  * The TTL starts when the computation completes. Concurrent callers share the
13238
- * pending computation. A zero TTL expires immediately, and an infinite TTL
13245
+ * pending computation, which is interrupted only once every caller waiting on
13246
+ * it has been interrupted. The next evaluation then starts a fresh
13247
+ * computation. A zero TTL expires immediately, and an infinite TTL
13239
13248
  * keeps the result indefinitely.
13240
13249
  *
13241
13250
  * **Example** (Memoizing an effect with TTL)
@@ -13315,11 +13324,12 @@ export declare const cachedWithTTL: {
13315
13324
  * `Duration.Input`. The function runs once after each fresh computation,
13316
13325
  * including failures, so successes and failures can have different TTLs. It
13317
13326
  * does not run when the cache is created or when a cached result is reused.
13318
- * The callback also receives interruption exits, which are cached for the
13319
- * returned duration.
13327
+ * Interrupted computations are never cached and do not call the function.
13320
13328
  *
13321
13329
  * The TTL starts when the computation completes. Concurrent callers share the
13322
- * pending computation. A zero TTL expires immediately, and an infinite TTL
13330
+ * pending computation, which is interrupted only once every caller waiting on
13331
+ * it has been interrupted. The next evaluation then starts a fresh
13332
+ * computation. A zero TTL expires immediately, and an infinite TTL
13323
13333
  * keeps the result indefinitely.
13324
13334
  *
13325
13335
  * **Example** (Memoizing an effect with TTL)
@@ -13376,8 +13386,8 @@ export declare const cachedWithTTL: {
13376
13386
  <A, E, R>(self: Effect<A, E, R>, timeToLive: Duration.Input | ((exit: Exit.Exit<A, E>) => Duration.Input)): Effect<Effect<A, E, R>>;
13377
13387
  };
13378
13388
  /**
13379
- * Creates a cached effect result for a specified duration and allows manual
13380
- * invalidation before expiration.
13389
+ * Creates a cached effect result for a fixed duration or a duration computed
13390
+ * from its `Exit` and allows manual invalidation before expiration.
13381
13391
  *
13382
13392
  * **When to use**
13383
13393
  *
@@ -13435,8 +13445,67 @@ export declare const cachedWithTTL: {
13435
13445
  */
13436
13446
  export declare const cachedInvalidateWithTTL: {
13437
13447
  /**
13438
- * Creates a cached effect result for a specified duration and allows manual
13439
- * invalidation before expiration.
13448
+ * Creates a cached effect result for a fixed duration or a duration computed
13449
+ * from its `Exit` and allows manual invalidation before expiration.
13450
+ *
13451
+ * **When to use**
13452
+ *
13453
+ * Use when an effect result should be cached for a bounded time and callers
13454
+ * also need a manual invalidation effect to force recomputation before
13455
+ * expiration.
13456
+ *
13457
+ * **Details**
13458
+ *
13459
+ * This function behaves similarly to {@link cachedWithTTL} by caching the
13460
+ * result of an effect for a specified period of time. However, it introduces an
13461
+ * additional feature: it provides an effect that allows you to manually
13462
+ * invalidate the cached result before it naturally expires.
13463
+ *
13464
+ * This gives you more control over the cache, allowing you to refresh the
13465
+ * result when needed, even if the original cache has not yet expired.
13466
+ *
13467
+ * Once the cache is invalidated, the next time the effect is evaluated, the
13468
+ * result will be recomputed, and the cache will be refreshed.
13469
+ *
13470
+ * **Example** (Memoizing with TTL and invalidation)
13471
+ *
13472
+ * ```ts import.meta.vitest
13473
+ * import { Effect } from "effect"
13474
+ * const output: Array<unknown> = []
13475
+ * const record = (value: unknown) => Effect.sync(() => { output.push(value) })
13476
+ *
13477
+ * let i = 1
13478
+ * const expensiveTask = Effect.sync(() => {
13479
+ * void output.push("expensive task...")
13480
+ * return `result ${i++}`
13481
+ * })
13482
+ *
13483
+ * const program = Effect.gen(function*() {
13484
+ * const [cached, invalidate] = yield* Effect.cachedInvalidateWithTTL(
13485
+ * expensiveTask,
13486
+ * "1 hour"
13487
+ * )
13488
+ * yield* cached.pipe(Effect.andThen(record))
13489
+ * yield* cached.pipe(Effect.andThen(record))
13490
+ * yield* invalidate
13491
+ * yield* cached.pipe(Effect.andThen(record))
13492
+ * })
13493
+ *
13494
+ * Effect.runSync(program)
13495
+ * output // => ["expensive task...", "result 1", "result 1", "expensive task...", "result 2"]
13496
+ * ```
13497
+ *
13498
+ * @see {@link cached} for a similar function that caches the result
13499
+ * indefinitely.
13500
+ * @see {@link cachedWithTTL} for a similar function that caches the result for
13501
+ * a specified duration but does not include an effect for manual invalidation.
13502
+ * @category caching
13503
+ * @since 2.0.0
13504
+ */
13505
+ <A, E>(timeToLive: (exit: Exit.Exit<A, E>) => Duration.Input): <R>(self: Effect<A, E, R>) => Effect<[Effect<A, E, R>, Effect<void>]>;
13506
+ /**
13507
+ * Creates a cached effect result for a fixed duration or a duration computed
13508
+ * from its `Exit` and allows manual invalidation before expiration.
13440
13509
  *
13441
13510
  * **When to use**
13442
13511
  *
@@ -13494,8 +13563,67 @@ export declare const cachedInvalidateWithTTL: {
13494
13563
  */
13495
13564
  (timeToLive: Duration.Input): <A, E, R>(self: Effect<A, E, R>) => Effect<[Effect<A, E, R>, Effect<void>]>;
13496
13565
  /**
13497
- * Creates a cached effect result for a specified duration and allows manual
13498
- * invalidation before expiration.
13566
+ * Creates a cached effect result for a fixed duration or a duration computed
13567
+ * from its `Exit` and allows manual invalidation before expiration.
13568
+ *
13569
+ * **When to use**
13570
+ *
13571
+ * Use when an effect result should be cached for a bounded time and callers
13572
+ * also need a manual invalidation effect to force recomputation before
13573
+ * expiration.
13574
+ *
13575
+ * **Details**
13576
+ *
13577
+ * This function behaves similarly to {@link cachedWithTTL} by caching the
13578
+ * result of an effect for a specified period of time. However, it introduces an
13579
+ * additional feature: it provides an effect that allows you to manually
13580
+ * invalidate the cached result before it naturally expires.
13581
+ *
13582
+ * This gives you more control over the cache, allowing you to refresh the
13583
+ * result when needed, even if the original cache has not yet expired.
13584
+ *
13585
+ * Once the cache is invalidated, the next time the effect is evaluated, the
13586
+ * result will be recomputed, and the cache will be refreshed.
13587
+ *
13588
+ * **Example** (Memoizing with TTL and invalidation)
13589
+ *
13590
+ * ```ts import.meta.vitest
13591
+ * import { Effect } from "effect"
13592
+ * const output: Array<unknown> = []
13593
+ * const record = (value: unknown) => Effect.sync(() => { output.push(value) })
13594
+ *
13595
+ * let i = 1
13596
+ * const expensiveTask = Effect.sync(() => {
13597
+ * void output.push("expensive task...")
13598
+ * return `result ${i++}`
13599
+ * })
13600
+ *
13601
+ * const program = Effect.gen(function*() {
13602
+ * const [cached, invalidate] = yield* Effect.cachedInvalidateWithTTL(
13603
+ * expensiveTask,
13604
+ * "1 hour"
13605
+ * )
13606
+ * yield* cached.pipe(Effect.andThen(record))
13607
+ * yield* cached.pipe(Effect.andThen(record))
13608
+ * yield* invalidate
13609
+ * yield* cached.pipe(Effect.andThen(record))
13610
+ * })
13611
+ *
13612
+ * Effect.runSync(program)
13613
+ * output // => ["expensive task...", "result 1", "result 1", "expensive task...", "result 2"]
13614
+ * ```
13615
+ *
13616
+ * @see {@link cached} for a similar function that caches the result
13617
+ * indefinitely.
13618
+ * @see {@link cachedWithTTL} for a similar function that caches the result for
13619
+ * a specified duration but does not include an effect for manual invalidation.
13620
+ * @category caching
13621
+ * @since 2.0.0
13622
+ */
13623
+ <A, E>(timeToLive: Duration.Input | ((exit: Exit.Exit<A, E>) => Duration.Input)): <R>(self: Effect<A, E, R>) => Effect<[Effect<A, E, R>, Effect<void>]>;
13624
+ /**
13625
+ * Creates a cached effect result for a fixed duration or a duration computed
13626
+ * from its `Exit` and allows manual invalidation before expiration.
13499
13627
  *
13500
13628
  * **When to use**
13501
13629
  *
@@ -13551,7 +13679,7 @@ export declare const cachedInvalidateWithTTL: {
13551
13679
  * @category caching
13552
13680
  * @since 2.0.0
13553
13681
  */
13554
- <A, E, R>(self: Effect<A, E, R>, timeToLive: Duration.Input): Effect<[Effect<A, E, R>, Effect<void>]>;
13682
+ <A, E, R>(self: Effect<A, E, R>, timeToLive: Duration.Input | ((exit: Exit.Exit<A, E>) => Duration.Input)): Effect<[Effect<A, E, R>, Effect<void>]>;
13555
13683
  };
13556
13684
  /**
13557
13685
  * Returns an effect that is immediately interrupted.