effect 4.0.0-beta.6 → 4.0.0-beta.7

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 (273) hide show
  1. package/dist/Cache.d.ts +2 -2
  2. package/dist/Cache.d.ts.map +1 -1
  3. package/dist/Cache.js +1 -1
  4. package/dist/Cache.js.map +1 -1
  5. package/dist/Config.d.ts +2 -2
  6. package/dist/Config.js +3 -3
  7. package/dist/Config.js.map +1 -1
  8. package/dist/DateTime.d.ts +23 -161
  9. package/dist/DateTime.d.ts.map +1 -1
  10. package/dist/DateTime.js +6 -51
  11. package/dist/DateTime.js.map +1 -1
  12. package/dist/Duration.d.ts +12 -12
  13. package/dist/Duration.d.ts.map +1 -1
  14. package/dist/Duration.js +12 -12
  15. package/dist/Duration.js.map +1 -1
  16. package/dist/Effect.d.ts +13 -13
  17. package/dist/Effect.d.ts.map +1 -1
  18. package/dist/Effect.js +1 -1
  19. package/dist/Effect.js.map +1 -1
  20. package/dist/Formatter.d.ts +131 -47
  21. package/dist/Formatter.d.ts.map +1 -1
  22. package/dist/Formatter.js +228 -50
  23. package/dist/Formatter.js.map +1 -1
  24. package/dist/JsonSchema.d.ts +299 -10
  25. package/dist/JsonSchema.d.ts.map +1 -1
  26. package/dist/JsonSchema.js +323 -4
  27. package/dist/JsonSchema.js.map +1 -1
  28. package/dist/LayerMap.d.ts +4 -4
  29. package/dist/LayerMap.d.ts.map +1 -1
  30. package/dist/LogLevel.d.ts +27 -0
  31. package/dist/LogLevel.d.ts.map +1 -1
  32. package/dist/LogLevel.js +28 -100
  33. package/dist/LogLevel.js.map +1 -1
  34. package/dist/Logger.d.ts +4 -4
  35. package/dist/Logger.d.ts.map +1 -1
  36. package/dist/Metric.d.ts +2 -2
  37. package/dist/Metric.d.ts.map +1 -1
  38. package/dist/Metric.js +1 -1
  39. package/dist/Metric.js.map +1 -1
  40. package/dist/Pool.d.ts +1 -1
  41. package/dist/Pool.d.ts.map +1 -1
  42. package/dist/Pool.js +1 -1
  43. package/dist/Pool.js.map +1 -1
  44. package/dist/Random.d.ts +1 -1
  45. package/dist/Random.d.ts.map +1 -1
  46. package/dist/Random.js +3 -12
  47. package/dist/Random.js.map +1 -1
  48. package/dist/RcMap.d.ts +2 -2
  49. package/dist/RcMap.d.ts.map +1 -1
  50. package/dist/RcMap.js +1 -1
  51. package/dist/RcMap.js.map +1 -1
  52. package/dist/RcRef.d.ts +1 -1
  53. package/dist/RcRef.d.ts.map +1 -1
  54. package/dist/RequestResolver.d.ts +6 -6
  55. package/dist/RequestResolver.d.ts.map +1 -1
  56. package/dist/RequestResolver.js.map +1 -1
  57. package/dist/Schedule.d.ts +20 -11
  58. package/dist/Schedule.d.ts.map +1 -1
  59. package/dist/Schedule.js +23 -9
  60. package/dist/Schedule.js.map +1 -1
  61. package/dist/Schema.d.ts +4 -4
  62. package/dist/Schema.d.ts.map +1 -1
  63. package/dist/ScopedCache.d.ts +2 -2
  64. package/dist/ScopedCache.d.ts.map +1 -1
  65. package/dist/ScopedCache.js +1 -1
  66. package/dist/ScopedCache.js.map +1 -1
  67. package/dist/Stream.d.ts +19 -19
  68. package/dist/Stream.d.ts.map +1 -1
  69. package/dist/Stream.js +3 -3
  70. package/dist/Stream.js.map +1 -1
  71. package/dist/index.d.ts +134 -0
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +134 -0
  74. package/dist/index.js.map +1 -1
  75. package/dist/internal/dateTime.js +3 -11
  76. package/dist/internal/dateTime.js.map +1 -1
  77. package/dist/internal/effect.js +2 -2
  78. package/dist/internal/effect.js.map +1 -1
  79. package/dist/internal/random.d.ts +2 -0
  80. package/dist/internal/random.d.ts.map +1 -0
  81. package/dist/internal/random.js +13 -0
  82. package/dist/internal/random.js.map +1 -0
  83. package/dist/internal/rcRef.js +1 -1
  84. package/dist/internal/rcRef.js.map +1 -1
  85. package/dist/testing/TestClock.d.ts +4 -4
  86. package/dist/testing/TestClock.d.ts.map +1 -1
  87. package/dist/testing/TestClock.js +1 -1
  88. package/dist/testing/TestClock.js.map +1 -1
  89. package/dist/testing/TestSchema.d.ts +6 -6
  90. package/dist/testing/TestSchema.d.ts.map +1 -1
  91. package/dist/unstable/ai/AiError.d.ts +10 -10
  92. package/dist/unstable/ai/AiError.d.ts.map +1 -1
  93. package/dist/unstable/ai/Chat.d.ts +3 -3
  94. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  95. package/dist/unstable/ai/Chat.js +2 -2
  96. package/dist/unstable/ai/Chat.js.map +1 -1
  97. package/dist/unstable/ai/LanguageModel.d.ts +2 -2
  98. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  99. package/dist/unstable/ai/McpServer.d.ts +1 -1
  100. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  101. package/dist/unstable/ai/McpServer.js.map +1 -1
  102. package/dist/unstable/ai/Prompt.d.ts +17 -17
  103. package/dist/unstable/ai/Prompt.d.ts.map +1 -1
  104. package/dist/unstable/ai/Response.d.ts +23 -23
  105. package/dist/unstable/ai/Response.d.ts.map +1 -1
  106. package/dist/unstable/ai/Response.js +1 -1
  107. package/dist/unstable/ai/Response.js.map +1 -1
  108. package/dist/unstable/cluster/ClusterCron.d.ts +1 -1
  109. package/dist/unstable/cluster/ClusterCron.d.ts.map +1 -1
  110. package/dist/unstable/cluster/ClusterCron.js +1 -1
  111. package/dist/unstable/cluster/ClusterCron.js.map +1 -1
  112. package/dist/unstable/cluster/Entity.d.ts +3 -3
  113. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  114. package/dist/unstable/cluster/EntityResource.d.ts +2 -2
  115. package/dist/unstable/cluster/EntityResource.d.ts.map +1 -1
  116. package/dist/unstable/cluster/K8sHttpClient.js +1 -1
  117. package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
  118. package/dist/unstable/cluster/MessageStorage.js.map +1 -1
  119. package/dist/unstable/cluster/Sharding.d.ts +2 -2
  120. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  121. package/dist/unstable/cluster/Sharding.js +1 -1
  122. package/dist/unstable/cluster/Sharding.js.map +1 -1
  123. package/dist/unstable/cluster/ShardingConfig.d.ts +21 -21
  124. package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
  125. package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
  126. package/dist/unstable/cluster/SqlRunnerStorage.js +1 -1
  127. package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
  128. package/dist/unstable/cluster/internal/entityManager.js +1 -1
  129. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  130. package/dist/unstable/encoding/Sse.d.ts +2 -2
  131. package/dist/unstable/encoding/Sse.d.ts.map +1 -1
  132. package/dist/unstable/encoding/Sse.js.map +1 -1
  133. package/dist/unstable/http/Cookies.d.ts +1 -1
  134. package/dist/unstable/http/Cookies.d.ts.map +1 -1
  135. package/dist/unstable/http/Cookies.js +2 -2
  136. package/dist/unstable/http/Cookies.js.map +1 -1
  137. package/dist/unstable/http/HttpClient.d.ts +4 -4
  138. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  139. package/dist/unstable/http/HttpClientRequest.d.ts +11 -11
  140. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  141. package/dist/unstable/http/HttpClientRequest.js +8 -1
  142. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  143. package/dist/unstable/http/HttpMethod.d.ts +4 -4
  144. package/dist/unstable/http/HttpMethod.d.ts.map +1 -1
  145. package/dist/unstable/http/HttpMethod.js +3 -3
  146. package/dist/unstable/http/HttpMethod.js.map +1 -1
  147. package/dist/unstable/observability/Otlp.d.ts +12 -12
  148. package/dist/unstable/observability/Otlp.d.ts.map +1 -1
  149. package/dist/unstable/observability/OtlpExporter.d.ts +2 -2
  150. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  151. package/dist/unstable/observability/OtlpExporter.js +1 -1
  152. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  153. package/dist/unstable/observability/OtlpLogger.d.ts +4 -4
  154. package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
  155. package/dist/unstable/observability/OtlpMetrics.d.ts +4 -4
  156. package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
  157. package/dist/unstable/observability/OtlpTracer.d.ts +4 -4
  158. package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
  159. package/dist/unstable/persistence/Persistable.d.ts +2 -2
  160. package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
  161. package/dist/unstable/persistence/PersistedQueue.d.ts +12 -12
  162. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  163. package/dist/unstable/persistence/PersistedQueue.js +6 -6
  164. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  165. package/dist/unstable/persistence/Persistence.d.ts +1 -1
  166. package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
  167. package/dist/unstable/persistence/Persistence.js +2 -2
  168. package/dist/unstable/persistence/Persistence.js.map +1 -1
  169. package/dist/unstable/persistence/RateLimiter.d.ts +3 -3
  170. package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
  171. package/dist/unstable/persistence/RateLimiter.js +1 -1
  172. package/dist/unstable/persistence/RateLimiter.js.map +1 -1
  173. package/dist/unstable/process/ChildProcess.d.ts +1 -1
  174. package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
  175. package/dist/unstable/reactivity/Atom.d.ts +6 -6
  176. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  177. package/dist/unstable/reactivity/Atom.js +3 -3
  178. package/dist/unstable/reactivity/Atom.js.map +1 -1
  179. package/dist/unstable/reactivity/AtomHttpApi.d.ts +1 -1
  180. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  181. package/dist/unstable/reactivity/AtomHttpApi.js +1 -1
  182. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  183. package/dist/unstable/reactivity/AtomRpc.d.ts +1 -1
  184. package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
  185. package/dist/unstable/reactivity/AtomRpc.js +1 -1
  186. package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
  187. package/dist/unstable/rpc/Rpc.d.ts +2 -2
  188. package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
  189. package/dist/unstable/rpc/RpcClient.d.ts +5 -26
  190. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  191. package/dist/unstable/rpc/RpcClient.js +3 -11
  192. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  193. package/dist/unstable/socket/Socket.d.ts +4 -4
  194. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  195. package/dist/unstable/sql/SqlModel.d.ts +2 -2
  196. package/dist/unstable/sql/SqlModel.d.ts.map +1 -1
  197. package/dist/unstable/sql/SqlModel.js +3 -3
  198. package/dist/unstable/sql/SqlModel.js.map +1 -1
  199. package/dist/unstable/sql/SqlSchema.d.ts +16 -5
  200. package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
  201. package/dist/unstable/sql/SqlSchema.js +17 -7
  202. package/dist/unstable/sql/SqlSchema.js.map +1 -1
  203. package/dist/unstable/workflow/DurableClock.d.ts +3 -3
  204. package/dist/unstable/workflow/DurableClock.d.ts.map +1 -1
  205. package/dist/unstable/workflow/DurableClock.js +3 -3
  206. package/dist/unstable/workflow/DurableClock.js.map +1 -1
  207. package/package.json +1 -1
  208. package/src/Cache.ts +3 -3
  209. package/src/Config.ts +3 -3
  210. package/src/DateTime.ts +24 -164
  211. package/src/Duration.ts +15 -15
  212. package/src/Effect.ts +15 -15
  213. package/src/Formatter.ts +252 -50
  214. package/src/JsonSchema.ts +383 -10
  215. package/src/LayerMap.ts +5 -5
  216. package/src/LogLevel.ts +31 -0
  217. package/src/Logger.ts +5 -5
  218. package/src/Metric.ts +4 -4
  219. package/src/Pool.ts +4 -4
  220. package/src/Random.ts +5 -14
  221. package/src/RcMap.ts +5 -5
  222. package/src/RcRef.ts +1 -1
  223. package/src/RequestResolver.ts +9 -9
  224. package/src/Schedule.ts +44 -25
  225. package/src/Schema.ts +4 -4
  226. package/src/ScopedCache.ts +3 -3
  227. package/src/Stream.ts +34 -34
  228. package/src/index.ts +134 -0
  229. package/src/internal/dateTime.ts +9 -30
  230. package/src/internal/effect.ts +21 -21
  231. package/src/internal/random.ts +20 -0
  232. package/src/internal/rcRef.ts +2 -2
  233. package/src/testing/TestClock.ts +5 -5
  234. package/src/testing/TestSchema.ts +8 -8
  235. package/src/unstable/ai/AiError.ts +1 -1
  236. package/src/unstable/ai/Chat.ts +10 -10
  237. package/src/unstable/ai/LanguageModel.ts +3 -3
  238. package/src/unstable/ai/McpServer.ts +2 -2
  239. package/src/unstable/ai/Prompt.ts +17 -17
  240. package/src/unstable/ai/Response.ts +23 -23
  241. package/src/unstable/cluster/ClusterCron.ts +2 -2
  242. package/src/unstable/cluster/Entity.ts +5 -5
  243. package/src/unstable/cluster/EntityResource.ts +4 -4
  244. package/src/unstable/cluster/K8sHttpClient.ts +1 -1
  245. package/src/unstable/cluster/MessageStorage.ts +1 -4
  246. package/src/unstable/cluster/Sharding.ts +3 -3
  247. package/src/unstable/cluster/ShardingConfig.ts +10 -11
  248. package/src/unstable/cluster/SqlRunnerStorage.ts +1 -1
  249. package/src/unstable/cluster/internal/entityManager.ts +3 -3
  250. package/src/unstable/encoding/Sse.ts +2 -4
  251. package/src/unstable/http/Cookies.ts +3 -3
  252. package/src/unstable/http/HttpClient.ts +4 -4
  253. package/src/unstable/http/HttpClientRequest.ts +15 -11
  254. package/src/unstable/http/HttpMethod.ts +16 -4
  255. package/src/unstable/observability/Otlp.ts +12 -12
  256. package/src/unstable/observability/OtlpExporter.ts +3 -3
  257. package/src/unstable/observability/OtlpLogger.ts +4 -4
  258. package/src/unstable/observability/OtlpMetrics.ts +4 -4
  259. package/src/unstable/observability/OtlpTracer.ts +4 -4
  260. package/src/unstable/persistence/Persistable.ts +2 -2
  261. package/src/unstable/persistence/PersistedQueue.ts +18 -18
  262. package/src/unstable/persistence/Persistence.ts +3 -3
  263. package/src/unstable/persistence/RateLimiter.ts +4 -4
  264. package/src/unstable/process/ChildProcess.ts +1 -1
  265. package/src/unstable/reactivity/Atom.ts +13 -13
  266. package/src/unstable/reactivity/AtomHttpApi.ts +3 -3
  267. package/src/unstable/reactivity/AtomRpc.ts +3 -3
  268. package/src/unstable/rpc/Rpc.ts +3 -3
  269. package/src/unstable/rpc/RpcClient.ts +8 -51
  270. package/src/unstable/socket/Socket.ts +4 -4
  271. package/src/unstable/sql/SqlModel.ts +5 -5
  272. package/src/unstable/sql/SqlSchema.ts +41 -25
  273. package/src/unstable/workflow/DurableClock.ts +8 -8
package/src/Pool.ts CHANGED
@@ -172,7 +172,7 @@ export const makeWithTTL = <A, E, R>(options: {
172
172
  readonly max: number
173
173
  readonly concurrency?: number | undefined
174
174
  readonly targetUtilization?: number | undefined
175
- readonly timeToLive: Duration.DurationInput
175
+ readonly timeToLive: Duration.Input
176
176
  readonly timeToLiveStrategy?: "creation" | "usage" | undefined
177
177
  }): Effect.Effect<Pool<A, E>, never, R | Scope.Scope> =>
178
178
  Effect.flatMap(
@@ -473,10 +473,10 @@ const strategyNoop = <A, E>(): Strategy<A, E> => ({
473
473
  reclaim: (_) => Effect.undefined
474
474
  })
475
475
 
476
- const strategyCreationTTL = Effect.fnUntraced(function*<A, E>(ttl: Duration.DurationInput) {
476
+ const strategyCreationTTL = Effect.fnUntraced(function*<A, E>(ttl: Duration.Input) {
477
477
  const clock = yield* Clock
478
478
  const queue = yield* Queue.unbounded<PoolItem<A, E>>()
479
- const ttlMillis = Duration.toMillis(Duration.fromDurationInputUnsafe(ttl))
479
+ const ttlMillis = Duration.toMillis(Duration.fromInputUnsafe(ttl))
480
480
  const creationTimes = new WeakMap<PoolItem<A, E>, number>()
481
481
  return identity<Strategy<A, E>>({
482
482
  run: (pool) => {
@@ -506,7 +506,7 @@ const strategyCreationTTL = Effect.fnUntraced(function*<A, E>(ttl: Duration.Dura
506
506
  })
507
507
  })
508
508
 
509
- const strategyUsageTTL = Effect.fnUntraced(function*<A, E>(ttl: Duration.DurationInput) {
509
+ const strategyUsageTTL = Effect.fnUntraced(function*<A, E>(ttl: Duration.Input) {
510
510
  const queue = yield* Queue.unbounded<PoolItem<A, E>>()
511
511
  return identity<Strategy<A, E>>({
512
512
  run: (pool) => {
package/src/Random.ts CHANGED
@@ -23,8 +23,9 @@
23
23
  */
24
24
  import * as Effect from "./Effect.ts"
25
25
  import { dual } from "./Function.ts"
26
+ import * as random from "./internal/random.ts"
26
27
  import * as Predicate from "./Predicate.ts"
27
- import * as ServiceMap from "./ServiceMap.ts"
28
+ import type * as ServiceMap from "./ServiceMap.ts"
28
29
 
29
30
  /**
30
31
  * Represents a service for generating random numbers.
@@ -49,23 +50,13 @@ import * as ServiceMap from "./ServiceMap.ts"
49
50
  * @since 4.0.0
50
51
  * @category Random Number Generators
51
52
  */
52
- export const Random = ServiceMap.Reference<{
53
+ export const Random: ServiceMap.Reference<{
53
54
  nextIntUnsafe(): number
54
55
  nextDoubleUnsafe(): number
55
- }>("effect/Random", {
56
- defaultValue: () => ({
57
- nextIntUnsafe() {
58
- return Math.floor(Math.random() * (Number.MAX_SAFE_INTEGER - Number.MIN_SAFE_INTEGER + 1)) +
59
- Number.MIN_SAFE_INTEGER
60
- },
61
- nextDoubleUnsafe() {
62
- return Math.random()
63
- }
64
- })
65
- })
56
+ }> = random.Random
66
57
 
67
58
  const randomWith = <A>(f: (random: typeof Random["Service"]) => A): Effect.Effect<A> =>
68
- Effect.withFiber((fiber) => Effect.succeed(f(ServiceMap.get(fiber.services, Random))))
59
+ Effect.withFiber((fiber) => Effect.succeed(f(fiber.getRef(Random))))
69
60
 
70
61
  /**
71
62
  * Generates a random number between 0 (inclusive) and 1 (inclusive).
package/src/RcMap.ts CHANGED
@@ -292,7 +292,7 @@ export const make: {
292
292
  <K, A, E, R>(
293
293
  options: {
294
294
  readonly lookup: (key: K) => Effect.Effect<A, E, R>
295
- readonly idleTimeToLive?: Duration.DurationInput | ((key: K) => Duration.DurationInput) | undefined
295
+ readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined
296
296
  readonly capacity?: undefined
297
297
  }
298
298
  ): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
@@ -335,13 +335,13 @@ export const make: {
335
335
  <K, A, E, R>(
336
336
  options: {
337
337
  readonly lookup: (key: K) => Effect.Effect<A, E, R>
338
- readonly idleTimeToLive?: Duration.DurationInput | ((key: K) => Duration.DurationInput) | undefined
338
+ readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined
339
339
  readonly capacity: number
340
340
  }
341
341
  ): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
342
342
  } = <K, A, E, R>(options: {
343
343
  readonly lookup: (key: K) => Effect.Effect<A, E, R>
344
- readonly idleTimeToLive?: Duration.DurationInput | ((key: K) => Duration.DurationInput) | undefined
344
+ readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined
345
345
  readonly capacity?: number | undefined
346
346
  }) =>
347
347
  Effect.withFiber<RcMap<K, A, E>, never, R | Scope.Scope>((fiber) => {
@@ -352,8 +352,8 @@ export const make: {
352
352
  services,
353
353
  scope,
354
354
  idleTimeToLive: typeof options.idleTimeToLive === "function"
355
- ? flow(options.idleTimeToLive, Duration.fromDurationInputUnsafe)
356
- : constant(Duration.fromDurationInputUnsafe(options.idleTimeToLive ?? Duration.zero)),
355
+ ? flow(options.idleTimeToLive, Duration.fromInputUnsafe)
356
+ : constant(Duration.fromInputUnsafe(options.idleTimeToLive ?? Duration.zero)),
357
357
  capacity: Math.max(options.capacity ?? Number.POSITIVE_INFINITY, 0)
358
358
  })
359
359
  return Effect.as(
package/src/RcRef.ts CHANGED
@@ -120,7 +120,7 @@ export const make: <A, E, R>(
120
120
  * When the reference count reaches zero, the resource will be released
121
121
  * after this duration.
122
122
  */
123
- readonly idleTimeToLive?: Duration.DurationInput | undefined
123
+ readonly idleTimeToLive?: Duration.Input | undefined
124
124
  }
125
125
  ) => Effect.Effect<RcRef<A, E>, never, R | Scope> = internal.make
126
126
 
@@ -652,7 +652,7 @@ export const setDelay: {
652
652
  * @since 4.0.0
653
653
  * @category delay
654
654
  */
655
- (duration: Duration.DurationInput): <A extends Request.Any>(self: RequestResolver<A>) => RequestResolver<A>
655
+ (duration: Duration.Input): <A extends Request.Any>(self: RequestResolver<A>) => RequestResolver<A>
656
656
  /**
657
657
  * Sets the batch delay window for this request resolver to the specified duration.
658
658
  *
@@ -683,10 +683,10 @@ export const setDelay: {
683
683
  * @since 4.0.0
684
684
  * @category delay
685
685
  */
686
- <A extends Request.Any>(self: RequestResolver<A>, duration: Duration.DurationInput): RequestResolver<A>
686
+ <A extends Request.Any>(self: RequestResolver<A>, duration: Duration.Input): RequestResolver<A>
687
687
  } = dual(
688
688
  2,
689
- <A extends Request.Any>(self: RequestResolver<A>, duration: Duration.DurationInput): RequestResolver<A> =>
689
+ <A extends Request.Any>(self: RequestResolver<A>, duration: Duration.Input): RequestResolver<A> =>
690
690
  makeWith({
691
691
  ...self,
692
692
  delay: Effect.sleep(duration)
@@ -1448,7 +1448,7 @@ export const asCache: {
1448
1448
  >(
1449
1449
  options: {
1450
1450
  readonly capacity: number
1451
- readonly timeToLive?: ((exit: Request.Result<A>, request: A) => Duration.DurationInput) | undefined
1451
+ readonly timeToLive?: ((exit: Request.Result<A>, request: A) => Duration.Input) | undefined
1452
1452
  readonly requireServicesAt?: ServiceMode | undefined
1453
1453
  }
1454
1454
  ): (self: RequestResolver<A>) => Effect.Effect<
@@ -1475,7 +1475,7 @@ export const asCache: {
1475
1475
  self: RequestResolver<A>,
1476
1476
  options: {
1477
1477
  readonly capacity: number
1478
- readonly timeToLive?: ((exit: Request.Result<A>, request: A) => Duration.DurationInput) | undefined
1478
+ readonly timeToLive?: ((exit: Request.Result<A>, request: A) => Duration.Input) | undefined
1479
1479
  readonly requireServicesAt?: ServiceMode | undefined
1480
1480
  }
1481
1481
  ): Effect.Effect<
@@ -1493,7 +1493,7 @@ export const asCache: {
1493
1493
  ServiceMode extends "lookup" | "construction" = never
1494
1494
  >(self: RequestResolver<A>, options: {
1495
1495
  readonly capacity: number
1496
- readonly timeToLive?: ((exit: Request.Result<A>, request: A) => Duration.DurationInput) | undefined
1496
+ readonly timeToLive?: ((exit: Request.Result<A>, request: A) => Duration.Input) | undefined
1497
1497
  readonly requireServicesAt?: ServiceMode | undefined
1498
1498
  }): Effect.Effect<
1499
1499
  Cache.Cache<
@@ -1629,7 +1629,7 @@ export const persisted: {
1629
1629
  <A extends Request.Request<any, Persistence.PersistenceError | Schema.SchemaError, any> & Persistable.Any>(
1630
1630
  options: {
1631
1631
  readonly storeId: string
1632
- readonly timeToLive?: ((exit: Request.Result<A>, request: A) => Duration.DurationInput) | undefined
1632
+ readonly timeToLive?: ((exit: Request.Result<A>, request: A) => Duration.Input) | undefined
1633
1633
  readonly staleWhileRevalidate?: ((exit: Request.Result<A>, request: A) => boolean) | undefined
1634
1634
  }
1635
1635
  ): (self: RequestResolver<A>) => Effect.Effect<
@@ -1647,7 +1647,7 @@ export const persisted: {
1647
1647
  self: RequestResolver<A>,
1648
1648
  options: {
1649
1649
  readonly storeId: string
1650
- readonly timeToLive?: ((exit: Request.Result<A>, request: A) => Duration.DurationInput) | undefined
1650
+ readonly timeToLive?: ((exit: Request.Result<A>, request: A) => Duration.Input) | undefined
1651
1651
  readonly staleWhileRevalidate?: ((exit: Request.Result<A>, request: A) => boolean) | undefined
1652
1652
  }
1653
1653
  ): Effect.Effect<
@@ -1663,7 +1663,7 @@ export const persisted: {
1663
1663
  self: RequestResolver<A>,
1664
1664
  options: {
1665
1665
  readonly storeId: string
1666
- readonly timeToLive?: ((exit: Request.Result<A>, request: A) => Duration.DurationInput) | undefined
1666
+ readonly timeToLive?: ((exit: Request.Result<A>, request: A) => Duration.Input) | undefined
1667
1667
  readonly staleWhileRevalidate?: ((exit: Request.Result<A>, request: A) => boolean) | undefined
1668
1668
  }
1669
1669
  ) {
package/src/Schedule.ts CHANGED
@@ -38,6 +38,7 @@ import type { LazyArg } from "./Function.ts"
38
38
  import { constant, dual, identity } from "./Function.ts"
39
39
  import { isEffect } from "./internal/core.ts"
40
40
  import * as effect from "./internal/effect.ts"
41
+ import * as random from "./internal/random.ts"
41
42
  import { type Pipeable, pipeArguments } from "./Pipeable.ts"
42
43
  import { hasProperty } from "./Predicate.ts"
43
44
  import * as Pull from "./Pull.ts"
@@ -47,6 +48,8 @@ import type { Contravariant, Covariant, Mutable } from "./Types.ts"
47
48
 
48
49
  const TypeId = "~effect/Schedule"
49
50
 
51
+ const randomNext: Effect<number> = random.Random.useSync((random) => random.nextDoubleUnsafe())
52
+
50
53
  /**
51
54
  * A Schedule defines a strategy for repeating or retrying effects based on some policy.
52
55
  *
@@ -747,7 +750,7 @@ export const addDelay: {
747
750
  * @since 2.0.0
748
751
  * @category utils
749
752
  */
750
- <Output, Error2 = never, Env2 = never>(f: (output: Output) => Effect<Duration.DurationInput, Error2, Env2>): <Input, Error, Env>(
753
+ <Output, Error2 = never, Env2 = never>(f: (output: Output) => Effect<Duration.Input, Error2, Env2>): <Input, Error, Env>(
751
754
  self: Schedule<Output, Input, Error, Env>
752
755
  ) => Schedule<Output, Input, Error | Error2, Env | Env2>
753
756
  /**
@@ -868,17 +871,16 @@ export const addDelay: {
868
871
  */
869
872
  <Output, Input, Error, Env, Error2 = never, Env2 = never>(
870
873
  self: Schedule<Output, Input, Error, Env>,
871
- f: (output: Output) => Effect<Duration.DurationInput, Error2, Env2>
874
+ f: (output: Output) => Effect<Duration.Input, Error2, Env2>
872
875
  ): Schedule<Output, Input, Error | Error2, Env | Env2>
873
876
  } = dual(2, <Output, Input, Error, Env, Error2 = never, Env2 = never>(
874
877
  self: Schedule<Output, Input, Error, Env>,
875
- f: (output: Output) => Effect<Duration.DurationInput, Error2, Env2>
878
+ f: (output: Output) => Effect<Duration.Input, Error2, Env2>
876
879
  ): Schedule<Output, Input, Error | Error2, Env | Env2> =>
877
880
  modifyDelay(
878
881
  self,
879
882
  (output, delay) =>
880
- effect.map(f(output), (d) =>
881
- Duration.sum(Duration.fromDurationInputUnsafe(d), Duration.fromDurationInputUnsafe(delay)))
883
+ effect.map(f(output), (d) => Duration.sum(Duration.fromInputUnsafe(d), Duration.fromInputUnsafe(delay)))
882
884
  ))
883
885
 
884
886
  /**
@@ -3020,8 +3022,8 @@ export const delays = <Out, In, E, R>(self: Schedule<Out, In, E, R>): Schedule<D
3020
3022
  * @since 2.0.0
3021
3023
  * @category constructors
3022
3024
  */
3023
- export const duration = (durationInput: Duration.DurationInput): Schedule<Duration.Duration> => {
3024
- const duration = Duration.fromDurationInputUnsafe(durationInput)
3025
+ export const duration = (durationInput: Duration.Input): Schedule<Duration.Duration> => {
3026
+ const duration = Duration.fromInputUnsafe(durationInput)
3025
3027
  return fromStepWithMetadata(effect.succeed((meta) =>
3026
3028
  meta.attempt === 1
3027
3029
  ? effect.succeed([duration, duration])
@@ -3114,10 +3116,10 @@ export const duration = (durationInput: Duration.DurationInput): Schedule<Durati
3114
3116
  * @since 4.0.0
3115
3117
  * @category constructors
3116
3118
  */
3117
- export const during = (duration: Duration.DurationInput): Schedule<Duration.Duration> =>
3119
+ export const during = (duration: Duration.Input): Schedule<Duration.Duration> =>
3118
3120
  while_(
3119
3121
  elapsed,
3120
- ({ output }) => effect.succeed(Duration.isLessThanOrEqualTo(output, Duration.fromDurationInputUnsafe(duration)))
3122
+ ({ output }) => effect.succeed(Duration.isLessThanOrEqualTo(output, Duration.fromInputUnsafe(duration)))
3121
3123
  )
3122
3124
 
3123
3125
  /**
@@ -3857,10 +3859,10 @@ export const elapsed: Schedule<Duration.Duration> = fromStepWithMetadata(
3857
3859
  * @category constructors
3858
3860
  */
3859
3861
  export const exponential = (
3860
- base: Duration.DurationInput,
3862
+ base: Duration.Input,
3861
3863
  factor: number = 2
3862
3864
  ): Schedule<Duration.Duration> => {
3863
- const baseMillis = Duration.toMillis(Duration.fromDurationInputUnsafe(base))
3865
+ const baseMillis = Duration.toMillis(Duration.fromInputUnsafe(base))
3864
3866
  return fromStepWithMetadata(effect.succeed((meta) => {
3865
3867
  const duration = Duration.millis(baseMillis * Math.pow(factor, meta.attempt - 1))
3866
3868
  return effect.succeed([duration, duration])
@@ -3931,8 +3933,8 @@ export const exponential = (
3931
3933
  * @since 2.0.0
3932
3934
  * @category constructors
3933
3935
  */
3934
- export const fibonacci = (one: Duration.DurationInput): Schedule<Duration.Duration> => {
3935
- const oneMillis = Duration.toMillis(Duration.fromDurationInputUnsafe(one))
3936
+ export const fibonacci = (one: Duration.Input): Schedule<Duration.Duration> => {
3937
+ const oneMillis = Duration.toMillis(Duration.fromInputUnsafe(one))
3936
3938
  return fromStep(effect.sync(() => {
3937
3939
  let a = 0
3938
3940
  let b = oneMillis
@@ -4008,8 +4010,8 @@ export const fibonacci = (one: Duration.DurationInput): Schedule<Duration.Durati
4008
4010
  * @since 2.0.0
4009
4011
  * @category constructors
4010
4012
  */
4011
- export const fixed = (interval: Duration.DurationInput): Schedule<number> => {
4012
- const window = Duration.toMillis(Duration.fromDurationInputUnsafe(interval))
4013
+ export const fixed = (interval: Duration.Input): Schedule<number> => {
4014
+ const window = Duration.toMillis(Duration.fromInputUnsafe(interval))
4013
4015
  return fromStepWithMetadata(effect.succeed((meta) =>
4014
4016
  effect.succeed([
4015
4017
  meta.attempt - 1,
@@ -4303,7 +4305,7 @@ export const modifyDelay: {
4303
4305
  f: (
4304
4306
  output: Output,
4305
4307
  delay: Duration.Duration
4306
- ) => Effect<Duration.DurationInput, Error2, Env2>
4308
+ ) => Effect<Duration.Input, Error2, Env2>
4307
4309
  ): <Input, Error, Env>(
4308
4310
  self: Schedule<Output, Input, Error, Env>
4309
4311
  ) => Schedule<Output, Input, Error | Error2, Env | Env2>
@@ -4343,22 +4345,39 @@ export const modifyDelay: {
4343
4345
  self: Schedule<Output, Input, Error, Env>,
4344
4346
  f: (
4345
4347
  output: Output,
4346
- delay: Duration.DurationInput
4347
- ) => Effect<Duration.DurationInput, Error2, Env2>
4348
+ delay: Duration.Input
4349
+ ) => Effect<Duration.Input, Error2, Env2>
4348
4350
  ): Schedule<Output, Input, Error | Error2, Env | Env2>
4349
4351
  } = dual(2, <Output, Input, Error, Env, Error2 = never, Env2 = never>(
4350
4352
  self: Schedule<Output, Input, Error, Env>,
4351
4353
  f: (
4352
4354
  output: Output,
4353
- delay: Duration.DurationInput
4354
- ) => Effect<Duration.DurationInput, Error2, Env2>
4355
+ delay: Duration.Input
4356
+ ) => Effect<Duration.Input, Error2, Env2>
4355
4357
  ): Schedule<Output, Input, Error | Error2, Env | Env2> =>
4356
4358
  fromStep(effect.map(toStep(self), (step) => (now, input) =>
4357
4359
  effect.flatMap(
4358
4360
  step(now, input),
4359
- ([output, delay]) => effect.map(f(output, delay), (delay) => [output, Duration.fromDurationInputUnsafe(delay)])
4361
+ ([output, delay]) => effect.map(f(output, delay), (delay) => [output, Duration.fromInputUnsafe(delay)])
4360
4362
  ))))
4361
4363
 
4364
+ /**
4365
+ * Returns a new `Schedule` that randomly adjusts each recurrence delay.
4366
+ *
4367
+ * Delays are jittered between `80%` and `120%` of the original delay.
4368
+ *
4369
+ * @since 2.0.0
4370
+ * @category utilities
4371
+ */
4372
+ export const jittered = <Output, Input, Error, Env>(
4373
+ self: Schedule<Output, Input, Error, Env>
4374
+ ): Schedule<Output, Input, Error, Env> =>
4375
+ modifyDelay(self, (_, delay) =>
4376
+ effect.map(randomNext, (random) => {
4377
+ const millis = Duration.toMillis(Duration.fromInputUnsafe(delay))
4378
+ return Duration.millis(millis * 0.8 * (1 - random) + millis * 1.2 * random)
4379
+ }))
4380
+
4362
4381
  /**
4363
4382
  * Returns a new `Schedule` that outputs the inputs of the specified schedule.
4364
4383
  *
@@ -4867,8 +4886,8 @@ export const reduce: {
4867
4886
  * @since 2.0.0
4868
4887
  * @category constructors
4869
4888
  */
4870
- export const spaced = (duration: Duration.DurationInput): Schedule<number> => {
4871
- const decoded = Duration.fromDurationInputUnsafe(duration)
4889
+ export const spaced = (duration: Duration.Input): Schedule<number> => {
4890
+ const decoded = Duration.fromInputUnsafe(duration)
4872
4891
  return fromStepWithMetadata(effect.succeed((meta) => effect.succeed([meta.attempt - 1, decoded])))
4873
4892
  }
4874
4893
 
@@ -5958,8 +5977,8 @@ export {
5958
5977
  * @since 2.0.0
5959
5978
  * @category constructors
5960
5979
  */
5961
- export const windowed = (interval: Duration.DurationInput): Schedule<number> => {
5962
- const window = Duration.toMillis(Duration.fromDurationInputUnsafe(interval))
5980
+ export const windowed = (interval: Duration.Input): Schedule<number> => {
5981
+ const window = Duration.toMillis(Duration.fromInputUnsafe(interval))
5963
5982
  return fromStepWithMetadata(effect.succeed((meta) =>
5964
5983
  effect.sync(() => [
5965
5984
  meta.attempt - 1,
package/src/Schema.ts CHANGED
@@ -325,7 +325,7 @@ export declare namespace Schema {
325
325
  /**
326
326
  * @since 4.0.0
327
327
  */
328
- export type Type<S extends Top> = S["Type"]
328
+ export type Type<S> = S extends Top ? S["Type"] : never
329
329
  }
330
330
 
331
331
  /**
@@ -353,15 +353,15 @@ export declare namespace Codec {
353
353
  /**
354
354
  * @since 4.0.0
355
355
  */
356
- export type Encoded<S extends Top> = S["Encoded"]
356
+ export type Encoded<S> = S extends Top ? S["Encoded"] : never
357
357
  /**
358
358
  * @since 4.0.0
359
359
  */
360
- export type DecodingServices<S extends Top> = S["DecodingServices"]
360
+ export type DecodingServices<S> = S extends Top ? S["DecodingServices"] : never
361
361
  /**
362
362
  * @since 4.0.0
363
363
  */
364
- export type EncodingServices<S extends Top> = S["EncodingServices"]
364
+ export type EncodingServices<S> = S extends Top ? S["EncodingServices"] : never
365
365
  /**
366
366
  * @since 4.0.0
367
367
  */
@@ -69,7 +69,7 @@ export const makeWith = <
69
69
  >(options: {
70
70
  readonly lookup: (key: Key) => Effect.Effect<A, E, R | Scope.Scope>
71
71
  readonly capacity: number
72
- readonly timeToLive?: ((exit: Exit.Exit<A, E>, key: Key) => Duration.DurationInput) | undefined
72
+ readonly timeToLive?: ((exit: Exit.Exit<A, E>, key: Key) => Duration.Input) | undefined
73
73
  readonly requireServicesAt?: ServiceMode | undefined
74
74
  }): Effect.Effect<
75
75
  ScopedCache<Key, A, E, "lookup" extends ServiceMode ? Exclude<R, Scope.Scope> : never>,
@@ -88,7 +88,7 @@ export const makeWith = <
88
88
  self.state = { _tag: "Open", map }
89
89
  self.capacity = options.capacity
90
90
  self.timeToLive = options.timeToLive
91
- ? (exit: Exit.Exit<A, E>, key: Key) => Duration.fromDurationInputUnsafe(options.timeToLive!(exit, key))
91
+ ? (exit: Exit.Exit<A, E>, key: Key) => Duration.fromInputUnsafe(options.timeToLive!(exit, key))
92
92
  : defaultTimeToLive
93
93
  return effect.as(
94
94
  Scope.addFinalizer(
@@ -116,7 +116,7 @@ export const make = <
116
116
  options: {
117
117
  readonly lookup: (key: Key) => Effect.Effect<A, E, R | Scope.Scope>
118
118
  readonly capacity: number
119
- readonly timeToLive?: Duration.DurationInput | undefined
119
+ readonly timeToLive?: Duration.Input | undefined
120
120
  readonly requireServicesAt?: ServiceMode | undefined
121
121
  }
122
122
  ): Effect.Effect<