effect 4.0.0-beta.6 → 4.0.0-beta.8
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.
- package/dist/Cache.d.ts +2 -2
- package/dist/Cache.d.ts.map +1 -1
- package/dist/Cache.js +1 -1
- package/dist/Cache.js.map +1 -1
- package/dist/Combiner.d.ts +280 -13
- package/dist/Combiner.d.ts.map +1 -1
- package/dist/Combiner.js +198 -7
- package/dist/Combiner.js.map +1 -1
- package/dist/Config.d.ts +2 -2
- package/dist/Config.js +3 -3
- package/dist/Config.js.map +1 -1
- package/dist/DateTime.d.ts +23 -161
- package/dist/DateTime.d.ts.map +1 -1
- package/dist/DateTime.js +6 -51
- package/dist/DateTime.js.map +1 -1
- package/dist/Duration.d.ts +12 -12
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +12 -12
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +13 -13
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +1 -1
- package/dist/Effect.js.map +1 -1
- package/dist/Formatter.d.ts +131 -47
- package/dist/Formatter.d.ts.map +1 -1
- package/dist/Formatter.js +228 -50
- package/dist/Formatter.js.map +1 -1
- package/dist/JsonSchema.d.ts +299 -10
- package/dist/JsonSchema.d.ts.map +1 -1
- package/dist/JsonSchema.js +323 -4
- package/dist/JsonSchema.js.map +1 -1
- package/dist/LayerMap.d.ts +4 -4
- package/dist/LayerMap.d.ts.map +1 -1
- package/dist/LogLevel.d.ts +27 -0
- package/dist/LogLevel.d.ts.map +1 -1
- package/dist/LogLevel.js +28 -100
- package/dist/LogLevel.js.map +1 -1
- package/dist/Logger.d.ts +4 -4
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Metric.d.ts +2 -2
- package/dist/Metric.d.ts.map +1 -1
- package/dist/Metric.js +1 -1
- package/dist/Metric.js.map +1 -1
- package/dist/Pool.d.ts +1 -1
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +1 -1
- package/dist/Pool.js.map +1 -1
- package/dist/Random.d.ts +1 -1
- package/dist/Random.d.ts.map +1 -1
- package/dist/Random.js +3 -12
- package/dist/Random.js.map +1 -1
- package/dist/RcMap.d.ts +2 -2
- package/dist/RcMap.d.ts.map +1 -1
- package/dist/RcMap.js +1 -1
- package/dist/RcMap.js.map +1 -1
- package/dist/RcRef.d.ts +1 -1
- package/dist/RcRef.d.ts.map +1 -1
- package/dist/Reducer.d.ts +166 -7
- package/dist/Reducer.d.ts.map +1 -1
- package/dist/Reducer.js +135 -1
- package/dist/Reducer.js.map +1 -1
- package/dist/RequestResolver.d.ts +6 -6
- package/dist/RequestResolver.d.ts.map +1 -1
- package/dist/RequestResolver.js.map +1 -1
- package/dist/Schedule.d.ts +20 -11
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +23 -9
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +4 -4
- package/dist/Schema.d.ts.map +1 -1
- package/dist/ScopedCache.d.ts +2 -2
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +1 -1
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Stream.d.ts +19 -19
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +3 -3
- package/dist/Stream.js.map +1 -1
- package/dist/index.d.ts +258 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +258 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/dateTime.js +3 -11
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +2 -2
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/random.d.ts +2 -0
- package/dist/internal/random.d.ts.map +1 -0
- package/dist/internal/random.js +13 -0
- package/dist/internal/random.js.map +1 -0
- package/dist/internal/rcRef.js +1 -1
- package/dist/internal/rcRef.js.map +1 -1
- package/dist/testing/TestClock.d.ts +4 -4
- package/dist/testing/TestClock.d.ts.map +1 -1
- package/dist/testing/TestClock.js +1 -1
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +6 -6
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/unstable/ai/AiError.d.ts +10 -10
- package/dist/unstable/ai/AiError.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +3 -3
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js +2 -2
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +2 -2
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +1 -1
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts +17 -17
- package/dist/unstable/ai/Prompt.d.ts.map +1 -1
- package/dist/unstable/ai/Response.d.ts +23 -23
- package/dist/unstable/ai/Response.d.ts.map +1 -1
- package/dist/unstable/ai/Response.js +1 -1
- package/dist/unstable/ai/Response.js.map +1 -1
- package/dist/unstable/cluster/ClusterCron.d.ts +1 -1
- package/dist/unstable/cluster/ClusterCron.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterCron.js +1 -1
- package/dist/unstable/cluster/ClusterCron.js.map +1 -1
- package/dist/unstable/cluster/Entity.d.ts +3 -3
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityResource.d.ts +2 -2
- package/dist/unstable/cluster/EntityResource.d.ts.map +1 -1
- package/dist/unstable/cluster/K8sHttpClient.js +1 -1
- package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
- package/dist/unstable/cluster/MessageStorage.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts +2 -2
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +1 -1
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.d.ts +21 -21
- package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +1 -1
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/encoding/Sse.d.ts +2 -2
- package/dist/unstable/encoding/Sse.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/http/Cookies.d.ts +1 -1
- package/dist/unstable/http/Cookies.d.ts.map +1 -1
- package/dist/unstable/http/Cookies.js +2 -2
- package/dist/unstable/http/Cookies.js.map +1 -1
- package/dist/unstable/http/HttpClient.d.ts +4 -4
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts +11 -11
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +8 -1
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpMethod.d.ts +4 -4
- package/dist/unstable/http/HttpMethod.d.ts.map +1 -1
- package/dist/unstable/http/HttpMethod.js +3 -3
- package/dist/unstable/http/HttpMethod.js.map +1 -1
- package/dist/unstable/observability/Otlp.d.ts +12 -12
- package/dist/unstable/observability/Otlp.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.d.ts +2 -2
- package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.js +1 -1
- package/dist/unstable/observability/OtlpExporter.js.map +1 -1
- package/dist/unstable/observability/OtlpLogger.d.ts +4 -4
- package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.d.ts +4 -4
- package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpTracer.d.ts +4 -4
- package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistable.d.ts +2 -2
- package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.d.ts +12 -12
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +6 -6
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Persistence.d.ts +1 -1
- package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistence.js +2 -2
- package/dist/unstable/persistence/Persistence.js.map +1 -1
- package/dist/unstable/persistence/RateLimiter.d.ts +3 -3
- package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
- package/dist/unstable/persistence/RateLimiter.js +1 -1
- package/dist/unstable/persistence/RateLimiter.js.map +1 -1
- package/dist/unstable/process/ChildProcess.d.ts +2 -2
- package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +6 -6
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +3 -3
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.d.ts +1 -1
- package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.js +1 -1
- package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +2 -2
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts +5 -26
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +3 -11
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts +4 -4
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/sql/SqlModel.d.ts +2 -2
- package/dist/unstable/sql/SqlModel.d.ts.map +1 -1
- package/dist/unstable/sql/SqlModel.js +3 -3
- package/dist/unstable/sql/SqlModel.js.map +1 -1
- package/dist/unstable/sql/SqlSchema.d.ts +16 -5
- package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
- package/dist/unstable/sql/SqlSchema.js +17 -7
- package/dist/unstable/sql/SqlSchema.js.map +1 -1
- package/dist/unstable/workflow/DurableClock.d.ts +3 -3
- package/dist/unstable/workflow/DurableClock.d.ts.map +1 -1
- package/dist/unstable/workflow/DurableClock.js +3 -3
- package/dist/unstable/workflow/DurableClock.js.map +1 -1
- package/package.json +1 -1
- package/src/Cache.ts +3 -3
- package/src/Combiner.ts +280 -13
- package/src/Config.ts +3 -3
- package/src/DateTime.ts +24 -164
- package/src/Duration.ts +15 -15
- package/src/Effect.ts +15 -15
- package/src/Formatter.ts +252 -50
- package/src/JsonSchema.ts +383 -10
- package/src/LayerMap.ts +5 -5
- package/src/LogLevel.ts +31 -0
- package/src/Logger.ts +5 -5
- package/src/Metric.ts +4 -4
- package/src/Pool.ts +4 -4
- package/src/Random.ts +5 -14
- package/src/RcMap.ts +5 -5
- package/src/RcRef.ts +1 -1
- package/src/Reducer.ts +166 -7
- package/src/RequestResolver.ts +9 -9
- package/src/Schedule.ts +44 -25
- package/src/Schema.ts +4 -4
- package/src/ScopedCache.ts +3 -3
- package/src/Stream.ts +34 -34
- package/src/index.ts +258 -0
- package/src/internal/dateTime.ts +9 -30
- package/src/internal/effect.ts +21 -21
- package/src/internal/random.ts +20 -0
- package/src/internal/rcRef.ts +2 -2
- package/src/testing/TestClock.ts +5 -5
- package/src/testing/TestSchema.ts +8 -8
- package/src/unstable/ai/AiError.ts +1 -1
- package/src/unstable/ai/Chat.ts +10 -10
- package/src/unstable/ai/LanguageModel.ts +3 -3
- package/src/unstable/ai/McpServer.ts +2 -2
- package/src/unstable/ai/Prompt.ts +17 -17
- package/src/unstable/ai/Response.ts +23 -23
- package/src/unstable/cluster/ClusterCron.ts +2 -2
- package/src/unstable/cluster/Entity.ts +5 -5
- package/src/unstable/cluster/EntityResource.ts +4 -4
- package/src/unstable/cluster/K8sHttpClient.ts +1 -1
- package/src/unstable/cluster/MessageStorage.ts +1 -4
- package/src/unstable/cluster/Sharding.ts +3 -3
- package/src/unstable/cluster/ShardingConfig.ts +10 -11
- package/src/unstable/cluster/SqlRunnerStorage.ts +1 -1
- package/src/unstable/cluster/internal/entityManager.ts +3 -3
- package/src/unstable/encoding/Sse.ts +2 -4
- package/src/unstable/http/Cookies.ts +3 -3
- package/src/unstable/http/HttpClient.ts +4 -4
- package/src/unstable/http/HttpClientRequest.ts +15 -11
- package/src/unstable/http/HttpMethod.ts +16 -4
- package/src/unstable/observability/Otlp.ts +12 -12
- package/src/unstable/observability/OtlpExporter.ts +3 -3
- package/src/unstable/observability/OtlpLogger.ts +4 -4
- package/src/unstable/observability/OtlpMetrics.ts +4 -4
- package/src/unstable/observability/OtlpTracer.ts +4 -4
- package/src/unstable/persistence/Persistable.ts +2 -2
- package/src/unstable/persistence/PersistedQueue.ts +18 -18
- package/src/unstable/persistence/Persistence.ts +3 -3
- package/src/unstable/persistence/RateLimiter.ts +4 -4
- package/src/unstable/process/ChildProcess.ts +2 -2
- package/src/unstable/reactivity/Atom.ts +13 -13
- package/src/unstable/reactivity/AtomHttpApi.ts +3 -3
- package/src/unstable/reactivity/AtomRpc.ts +3 -3
- package/src/unstable/rpc/Rpc.ts +3 -3
- package/src/unstable/rpc/RpcClient.ts +8 -51
- package/src/unstable/socket/Socket.ts +4 -4
- package/src/unstable/sql/SqlModel.ts +5 -5
- package/src/unstable/sql/SqlSchema.ts +41 -25
- 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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
53
|
+
export const Random: ServiceMap.Reference<{
|
|
53
54
|
nextIntUnsafe(): number
|
|
54
55
|
nextDoubleUnsafe(): number
|
|
55
|
-
}>
|
|
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(
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
356
|
-
: constant(Duration.
|
|
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.
|
|
123
|
+
readonly idleTimeToLive?: Duration.Input | undefined
|
|
124
124
|
}
|
|
125
125
|
) => Effect.Effect<RcRef<A, E>, never, R | Scope> = internal.make
|
|
126
126
|
|
package/src/Reducer.ts
CHANGED
|
@@ -1,17 +1,107 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* A module for reducing collections of values into a single result.
|
|
3
|
+
*
|
|
4
|
+
* A `Reducer<A>` extends {@link Combiner.Combiner} by adding an
|
|
5
|
+
* `initialValue` (identity element) and a `combineAll` method that folds an
|
|
6
|
+
* entire collection. Think `Array.prototype.reduce`, but packaged as a
|
|
7
|
+
* reusable, composable value.
|
|
8
|
+
*
|
|
9
|
+
* ## Mental model
|
|
10
|
+
*
|
|
11
|
+
* - **Reducer** – a {@link Combiner.Combiner} plus an `initialValue` and a
|
|
12
|
+
* `combineAll` method.
|
|
13
|
+
* - **initialValue** – the neutral/identity element. Combining any value with
|
|
14
|
+
* `initialValue` should return the original value unchanged (e.g. `0` for
|
|
15
|
+
* addition, `""` for string concatenation).
|
|
16
|
+
* - **combineAll** – folds an `Iterable<A>` starting from `initialValue`.
|
|
17
|
+
* When omitted from {@link make}, a default left-to-right fold is used.
|
|
18
|
+
* - **Purity** – all reducers produced by this module are pure; they never
|
|
19
|
+
* mutate their arguments.
|
|
20
|
+
* - **Composability** – reducers can be lifted into `Option`, `Struct`,
|
|
21
|
+
* `Tuple`, `Record`, and other container types via helpers in those modules.
|
|
22
|
+
* - **Subtype of Combiner** – every `Reducer` is also a valid
|
|
23
|
+
* `Combiner`, so you can pass a `Reducer` anywhere a `Combiner` is
|
|
24
|
+
* expected.
|
|
25
|
+
*
|
|
26
|
+
* ## Common tasks
|
|
27
|
+
*
|
|
28
|
+
* - Create a reducer from a combine function and initial value → {@link make}
|
|
29
|
+
* - Swap argument order → {@link flip}
|
|
30
|
+
* - Combine two values without an initial value → use {@link Combiner.Combiner}
|
|
31
|
+
* instead
|
|
32
|
+
*
|
|
33
|
+
* ## Gotchas
|
|
34
|
+
*
|
|
35
|
+
* - `combineAll` on an empty iterable returns `initialValue`, not an error.
|
|
36
|
+
* - The default `combineAll` folds left-to-right. If your `combine` is not
|
|
37
|
+
* associative, order matters. Pass a custom `combineAll` to {@link make} if
|
|
38
|
+
* you need different traversal or short-circuiting.
|
|
39
|
+
* - A `Reducer` is also a valid `Combiner` — but a `Combiner` is *not* a
|
|
40
|
+
* `Reducer` (it lacks `initialValue`).
|
|
41
|
+
*
|
|
42
|
+
* ## Quickstart
|
|
43
|
+
*
|
|
44
|
+
* **Example** (summing a list of numbers)
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { Reducer } from "effect"
|
|
48
|
+
*
|
|
49
|
+
* const Sum = Reducer.make<number>((a, b) => a + b, 0)
|
|
50
|
+
*
|
|
51
|
+
* console.log(Sum.combine(3, 4))
|
|
52
|
+
* // Output: 7
|
|
53
|
+
*
|
|
54
|
+
* console.log(Sum.combineAll([1, 2, 3, 4]))
|
|
55
|
+
* // Output: 10
|
|
56
|
+
*
|
|
57
|
+
* console.log(Sum.combineAll([]))
|
|
58
|
+
* // Output: 0
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* ## See also
|
|
62
|
+
*
|
|
63
|
+
* - {@link make} – the primary constructor
|
|
64
|
+
* - {@link Reducer} – the core interface
|
|
65
|
+
* - {@link Combiner.Combiner} – the parent interface (no `initialValue`)
|
|
66
|
+
*
|
|
2
67
|
* @since 4.0.0
|
|
3
68
|
*/
|
|
4
69
|
|
|
5
70
|
import type * as Combiner from "./Combiner.ts"
|
|
6
71
|
|
|
7
72
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
73
|
+
* Represents a strategy for reducing a collection of values of type `A` into
|
|
74
|
+
* a single result.
|
|
75
|
+
*
|
|
76
|
+
* Extends {@link Combiner.Combiner} with:
|
|
77
|
+
* - `initialValue` – the identity/neutral element for `combine`.
|
|
78
|
+
* - `combineAll` – folds an entire `Iterable<A>` from `initialValue`.
|
|
79
|
+
*
|
|
80
|
+
* When to use:
|
|
81
|
+
* - You need to fold/reduce a collection into a single value.
|
|
82
|
+
* - You want a reusable reducing strategy that can be passed to library
|
|
83
|
+
* functions like `Struct.makeReducer`, `Option.makeReducer`, or
|
|
84
|
+
* `Record.makeReducerUnion`.
|
|
85
|
+
* - You need both the combining logic *and* a known starting value.
|
|
86
|
+
*
|
|
87
|
+
* Many modules ship pre-built reducers:
|
|
88
|
+
* - `Number.ReducerSum`, `Number.ReducerMultiply`
|
|
89
|
+
* - `String.ReducerConcat`
|
|
90
|
+
* - `Boolean.ReducerAnd`, `Boolean.ReducerOr`
|
|
10
91
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
92
|
+
* **Example** (string concatenation reducer)
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { Reducer } from "effect"
|
|
96
|
+
*
|
|
97
|
+
* const Concat = Reducer.make<string>((a, b) => a + b, "")
|
|
98
|
+
*
|
|
99
|
+
* console.log(Concat.combineAll(["hello", " ", "world"]))
|
|
100
|
+
* // Output: "hello world"
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @see {@link make} – create a `Reducer` from a function and initial value
|
|
104
|
+
* @see {@link Combiner.Combiner} – parent interface without `initialValue`
|
|
15
105
|
*
|
|
16
106
|
* @category model
|
|
17
107
|
* @since 4.0.0
|
|
@@ -27,7 +117,44 @@ export interface Reducer<A> extends Combiner.Combiner<A> {
|
|
|
27
117
|
/**
|
|
28
118
|
* Creates a `Reducer` from a `combine` function and an `initialValue`.
|
|
29
119
|
*
|
|
30
|
-
*
|
|
120
|
+
* When to use:
|
|
121
|
+
* - You have a custom reducing operation not covered by a pre-built reducer.
|
|
122
|
+
* - You want to provide an optimized `combineAll` (e.g. short-circuiting on
|
|
123
|
+
* a known absorbing element like `0` for multiplication).
|
|
124
|
+
*
|
|
125
|
+
* Behavior:
|
|
126
|
+
* - If `combineAll` is omitted, a default left-to-right fold starting from
|
|
127
|
+
* `initialValue` is used.
|
|
128
|
+
* - If `combineAll` is provided, it completely replaces the default fold.
|
|
129
|
+
* - Pure – the returned reducer does not mutate its arguments.
|
|
130
|
+
*
|
|
131
|
+
* **Example** (multiplication with short-circuit)
|
|
132
|
+
*
|
|
133
|
+
* ```ts
|
|
134
|
+
* import { Reducer } from "effect"
|
|
135
|
+
*
|
|
136
|
+
* const Product = Reducer.make<number>(
|
|
137
|
+
* (a, b) => a * b,
|
|
138
|
+
* 1,
|
|
139
|
+
* (collection) => {
|
|
140
|
+
* let acc = 1
|
|
141
|
+
* for (const n of collection) {
|
|
142
|
+
* if (n === 0) return 0
|
|
143
|
+
* acc *= n
|
|
144
|
+
* }
|
|
145
|
+
* return acc
|
|
146
|
+
* }
|
|
147
|
+
* )
|
|
148
|
+
*
|
|
149
|
+
* console.log(Product.combineAll([2, 3, 4]))
|
|
150
|
+
* // Output: 24
|
|
151
|
+
*
|
|
152
|
+
* console.log(Product.combineAll([2, 0, 4]))
|
|
153
|
+
* // Output: 0
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @see {@link Reducer} – the interface this creates
|
|
157
|
+
* @see {@link flip} – reverse the argument order
|
|
31
158
|
*
|
|
32
159
|
* @since 4.0.0
|
|
33
160
|
*/
|
|
@@ -51,6 +178,38 @@ export function make<A>(
|
|
|
51
178
|
}
|
|
52
179
|
|
|
53
180
|
/**
|
|
181
|
+
* Reverses the argument order of a reducer's `combine` method.
|
|
182
|
+
*
|
|
183
|
+
* When to use:
|
|
184
|
+
* - You need the "right" value to act as the accumulator side.
|
|
185
|
+
* - You want to reverse the natural direction of a non-commutative reducer
|
|
186
|
+
* (e.g. string concatenation becomes prepend).
|
|
187
|
+
*
|
|
188
|
+
* Behavior:
|
|
189
|
+
* - Returns a new `Reducer` where `combine(self, that)` calls the original
|
|
190
|
+
* reducer as `combine(that, self)`.
|
|
191
|
+
* - The `initialValue` is preserved from the original reducer.
|
|
192
|
+
* - The `combineAll` is re-derived from the flipped `combine` (using the
|
|
193
|
+
* default left-to-right fold), not carried over from the original.
|
|
194
|
+
* - Does not mutate the input reducer.
|
|
195
|
+
*
|
|
196
|
+
* **Example** (reversing string concatenation)
|
|
197
|
+
*
|
|
198
|
+
* ```ts
|
|
199
|
+
* import { Reducer, String } from "effect"
|
|
200
|
+
*
|
|
201
|
+
* const Prepend = Reducer.flip(String.ReducerConcat)
|
|
202
|
+
*
|
|
203
|
+
* console.log(Prepend.combine("a", "b"))
|
|
204
|
+
* // Output: "ba"
|
|
205
|
+
*
|
|
206
|
+
* console.log(Prepend.combineAll(["a", "b", "c"]))
|
|
207
|
+
* // Output: "cba"
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @see {@link make}
|
|
211
|
+
* @see {@link Combiner.flip} – the same operation on a plain `Combiner`
|
|
212
|
+
*
|
|
54
213
|
* @since 4.0.0
|
|
55
214
|
*/
|
|
56
215
|
export function flip<A>(reducer: Reducer<A>): Reducer<A> {
|
package/src/RequestResolver.ts
CHANGED
|
@@ -652,7 +652,7 @@ export const setDelay: {
|
|
|
652
652
|
* @since 4.0.0
|
|
653
653
|
* @category delay
|
|
654
654
|
*/
|
|
655
|
-
(duration: Duration.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
3024
|
-
const duration = Duration.
|
|
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.
|
|
3119
|
+
export const during = (duration: Duration.Input): Schedule<Duration.Duration> =>
|
|
3118
3120
|
while_(
|
|
3119
3121
|
elapsed,
|
|
3120
|
-
({ output }) => effect.succeed(Duration.isLessThanOrEqualTo(output, 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.
|
|
3862
|
+
base: Duration.Input,
|
|
3861
3863
|
factor: number = 2
|
|
3862
3864
|
): Schedule<Duration.Duration> => {
|
|
3863
|
-
const baseMillis = Duration.toMillis(Duration.
|
|
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.
|
|
3935
|
-
const oneMillis = Duration.toMillis(Duration.
|
|
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.
|
|
4012
|
-
const window = Duration.toMillis(Duration.
|
|
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.
|
|
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.
|
|
4347
|
-
) => Effect<Duration.
|
|
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.
|
|
4354
|
-
) => Effect<Duration.
|
|
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.
|
|
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.
|
|
4871
|
-
const decoded = 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.
|
|
5962
|
-
const window = Duration.toMillis(Duration.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
364
|
+
export type EncodingServices<S> = S extends Top ? S["EncodingServices"] : never
|
|
365
365
|
/**
|
|
366
366
|
* @since 4.0.0
|
|
367
367
|
*/
|
package/src/ScopedCache.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
119
|
+
readonly timeToLive?: Duration.Input | undefined
|
|
120
120
|
readonly requireServicesAt?: ServiceMode | undefined
|
|
121
121
|
}
|
|
122
122
|
): Effect.Effect<
|