effect 4.0.0-rc.113 → 4.0.0-rc.114
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/Effect.d.ts +268 -7
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +33 -2
- package/dist/Effect.js.map +1 -1
- package/dist/Effectable.d.ts +1 -2
- package/dist/Effectable.d.ts.map +1 -1
- package/dist/Effectable.js.map +1 -1
- package/dist/FileSystem.d.ts +3 -4
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js.map +1 -1
- package/dist/Match.d.ts +1 -14
- package/dist/Match.d.ts.map +1 -1
- package/dist/Schema.d.ts +4 -4
- package/dist/Schema.d.ts.map +1 -1
- package/dist/SchemaRepresentation.d.ts +39 -24
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +37 -23
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/internal/arbitrary/schema.js.map +1 -1
- package/dist/internal/effect.js +16 -8
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/fromJsonSchemaDocument.js +221 -230
- package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
- package/dist/internal/schema/toCodeDocument.js +4 -4
- package/dist/internal/schema/toCodeDocument.js.map +1 -1
- package/dist/unstable/cli/Prompt.d.ts +6 -2
- package/dist/unstable/cli/Prompt.d.ts.map +1 -1
- package/dist/unstable/cli/Prompt.js +8 -7
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts +1 -6
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +2 -0
- package/dist/unstable/cli/internal/command.js.map +1 -1
- package/package.json +1 -1
- package/src/Effect.ts +271 -7
- package/src/Effectable.ts +2 -2
- package/src/FileSystem.ts +3 -4
- package/src/Match.ts +1 -1
- package/src/Schema.ts +4 -7
- package/src/SchemaRepresentation.ts +39 -24
- package/src/internal/arbitrary/schema.ts +16 -16
- package/src/internal/effect.ts +34 -11
- package/src/internal/schema/fromJsonSchemaDocument.ts +294 -268
- package/src/internal/schema/toCodeDocument.ts +4 -4
- package/src/unstable/cli/Prompt.ts +22 -11
- package/src/unstable/cli/internal/command.ts +2 -0
package/dist/Effect.d.ts
CHANGED
|
@@ -12949,8 +12949,8 @@ export declare const onExitFilter: {
|
|
|
12949
12949
|
*/
|
|
12950
12950
|
export declare const cached: <A, E, R>(self: Effect<A, E, R>) => Effect<Effect<A, E, R>>;
|
|
12951
12951
|
/**
|
|
12952
|
-
* Returns an effect that caches its result for a
|
|
12953
|
-
* known as "timeToLive" (TTL).
|
|
12952
|
+
* Returns an effect that caches its result for a fixed duration or a duration
|
|
12953
|
+
* computed from its `Exit`, known as "timeToLive" (TTL).
|
|
12954
12954
|
*
|
|
12955
12955
|
* **When to use**
|
|
12956
12956
|
*
|
|
@@ -12969,6 +12969,17 @@ export declare const cached: <A, E, R>(self: Effect<A, E, R>) => Effect<Effect<A
|
|
|
12969
12969
|
* After the specified duration has passed, the cache expires, and the effect
|
|
12970
12970
|
* will be recomputed upon the next evaluation.
|
|
12971
12971
|
*
|
|
12972
|
+
* `timeToLive` accepts a `Duration.Input` or a function from `Exit<A, E>` to
|
|
12973
|
+
* `Duration.Input`. The function runs once after each fresh computation,
|
|
12974
|
+
* including failures, so successes and failures can have different TTLs. It
|
|
12975
|
+
* does not run when the cache is created or when a cached result is reused.
|
|
12976
|
+
* The callback also receives interruption exits, which are cached for the
|
|
12977
|
+
* returned duration.
|
|
12978
|
+
*
|
|
12979
|
+
* The TTL starts when the computation completes. Concurrent callers share the
|
|
12980
|
+
* pending computation. A zero TTL expires immediately, and an infinite TTL
|
|
12981
|
+
* keeps the result indefinitely.
|
|
12982
|
+
*
|
|
12972
12983
|
* **Example** (Memoizing an effect with TTL)
|
|
12973
12984
|
*
|
|
12974
12985
|
* ```ts import.meta.vitest
|
|
@@ -12993,6 +13004,26 @@ export declare const cached: <A, E, R>(self: Effect<A, E, R>) => Effect<Effect<A
|
|
|
12993
13004
|
* output // => ["expensive task...", "result 1", "result 1", "result 1"]
|
|
12994
13005
|
* ```
|
|
12995
13006
|
*
|
|
13007
|
+
* **Example** (Caching successes while retrying failures)
|
|
13008
|
+
*
|
|
13009
|
+
* ```ts import.meta.vitest
|
|
13010
|
+
* import { Effect, Exit } from "effect"
|
|
13011
|
+
*
|
|
13012
|
+
* let attempts = 0
|
|
13013
|
+
* const task = Effect.suspend(() =>
|
|
13014
|
+
* ++attempts === 1 ? Effect.fail("temporary failure") : Effect.succeed(42)
|
|
13015
|
+
* )
|
|
13016
|
+
* const program = Effect.gen(function*() {
|
|
13017
|
+
* const cached = yield* task.pipe(
|
|
13018
|
+
* Effect.cachedWithTTL((exit) => Exit.isSuccess(exit) ? "1 hour" : 0)
|
|
13019
|
+
* )
|
|
13020
|
+
* yield* Effect.exit(cached)
|
|
13021
|
+
* return yield* cached
|
|
13022
|
+
* })
|
|
13023
|
+
*
|
|
13024
|
+
* Effect.runSync(program) // => 42
|
|
13025
|
+
* ```
|
|
13026
|
+
*
|
|
12996
13027
|
* @see {@link cached} for a similar function that caches the result
|
|
12997
13028
|
* indefinitely.
|
|
12998
13029
|
* @see {@link cachedInvalidateWithTTL} for a similar function that includes an
|
|
@@ -13002,8 +13033,8 @@ export declare const cached: <A, E, R>(self: Effect<A, E, R>) => Effect<Effect<A
|
|
|
13002
13033
|
*/
|
|
13003
13034
|
export declare const cachedWithTTL: {
|
|
13004
13035
|
/**
|
|
13005
|
-
* Returns an effect that caches its result for a
|
|
13006
|
-
* known as "timeToLive" (TTL).
|
|
13036
|
+
* Returns an effect that caches its result for a fixed duration or a duration
|
|
13037
|
+
* computed from its `Exit`, known as "timeToLive" (TTL).
|
|
13007
13038
|
*
|
|
13008
13039
|
* **When to use**
|
|
13009
13040
|
*
|
|
@@ -13022,6 +13053,17 @@ export declare const cachedWithTTL: {
|
|
|
13022
13053
|
* After the specified duration has passed, the cache expires, and the effect
|
|
13023
13054
|
* will be recomputed upon the next evaluation.
|
|
13024
13055
|
*
|
|
13056
|
+
* `timeToLive` accepts a `Duration.Input` or a function from `Exit<A, E>` to
|
|
13057
|
+
* `Duration.Input`. The function runs once after each fresh computation,
|
|
13058
|
+
* including failures, so successes and failures can have different TTLs. It
|
|
13059
|
+
* does not run when the cache is created or when a cached result is reused.
|
|
13060
|
+
* The callback also receives interruption exits, which are cached for the
|
|
13061
|
+
* returned duration.
|
|
13062
|
+
*
|
|
13063
|
+
* The TTL starts when the computation completes. Concurrent callers share the
|
|
13064
|
+
* pending computation. A zero TTL expires immediately, and an infinite TTL
|
|
13065
|
+
* keeps the result indefinitely.
|
|
13066
|
+
*
|
|
13025
13067
|
* **Example** (Memoizing an effect with TTL)
|
|
13026
13068
|
*
|
|
13027
13069
|
* ```ts import.meta.vitest
|
|
@@ -13046,6 +13088,110 @@ export declare const cachedWithTTL: {
|
|
|
13046
13088
|
* output // => ["expensive task...", "result 1", "result 1", "result 1"]
|
|
13047
13089
|
* ```
|
|
13048
13090
|
*
|
|
13091
|
+
* **Example** (Caching successes while retrying failures)
|
|
13092
|
+
*
|
|
13093
|
+
* ```ts import.meta.vitest
|
|
13094
|
+
* import { Effect, Exit } from "effect"
|
|
13095
|
+
*
|
|
13096
|
+
* let attempts = 0
|
|
13097
|
+
* const task = Effect.suspend(() =>
|
|
13098
|
+
* ++attempts === 1 ? Effect.fail("temporary failure") : Effect.succeed(42)
|
|
13099
|
+
* )
|
|
13100
|
+
* const program = Effect.gen(function*() {
|
|
13101
|
+
* const cached = yield* task.pipe(
|
|
13102
|
+
* Effect.cachedWithTTL((exit) => Exit.isSuccess(exit) ? "1 hour" : 0)
|
|
13103
|
+
* )
|
|
13104
|
+
* yield* Effect.exit(cached)
|
|
13105
|
+
* return yield* cached
|
|
13106
|
+
* })
|
|
13107
|
+
*
|
|
13108
|
+
* Effect.runSync(program) // => 42
|
|
13109
|
+
* ```
|
|
13110
|
+
*
|
|
13111
|
+
* @see {@link cached} for a similar function that caches the result
|
|
13112
|
+
* indefinitely.
|
|
13113
|
+
* @see {@link cachedInvalidateWithTTL} for a similar function that includes an
|
|
13114
|
+
* additional effect for manually invalidating the cached value.
|
|
13115
|
+
* @category caching
|
|
13116
|
+
* @since 2.0.0
|
|
13117
|
+
*/
|
|
13118
|
+
<A, E>(timeToLive: (exit: Exit.Exit<A, E>) => Duration.Input): <R>(self: Effect<A, E, R>) => Effect<Effect<A, E, R>>;
|
|
13119
|
+
/**
|
|
13120
|
+
* Returns an effect that caches its result for a fixed duration or a duration
|
|
13121
|
+
* computed from its `Exit`, known as "timeToLive" (TTL).
|
|
13122
|
+
*
|
|
13123
|
+
* **When to use**
|
|
13124
|
+
*
|
|
13125
|
+
* Use when you need a costly effect result to be reused for a bounded duration
|
|
13126
|
+
* before being recomputed.
|
|
13127
|
+
*
|
|
13128
|
+
* **Details**
|
|
13129
|
+
*
|
|
13130
|
+
* This function is used to cache the result of an effect for a specified amount
|
|
13131
|
+
* of time. This means that the first time the effect is evaluated, its result
|
|
13132
|
+
* is computed and stored.
|
|
13133
|
+
*
|
|
13134
|
+
* If the effect is evaluated again within the specified `timeToLive`, the
|
|
13135
|
+
* cached result will be used, avoiding recomputation.
|
|
13136
|
+
*
|
|
13137
|
+
* After the specified duration has passed, the cache expires, and the effect
|
|
13138
|
+
* will be recomputed upon the next evaluation.
|
|
13139
|
+
*
|
|
13140
|
+
* `timeToLive` accepts a `Duration.Input` or a function from `Exit<A, E>` to
|
|
13141
|
+
* `Duration.Input`. The function runs once after each fresh computation,
|
|
13142
|
+
* including failures, so successes and failures can have different TTLs. It
|
|
13143
|
+
* does not run when the cache is created or when a cached result is reused.
|
|
13144
|
+
* The callback also receives interruption exits, which are cached for the
|
|
13145
|
+
* returned duration.
|
|
13146
|
+
*
|
|
13147
|
+
* The TTL starts when the computation completes. Concurrent callers share the
|
|
13148
|
+
* pending computation. A zero TTL expires immediately, and an infinite TTL
|
|
13149
|
+
* keeps the result indefinitely.
|
|
13150
|
+
*
|
|
13151
|
+
* **Example** (Memoizing an effect with TTL)
|
|
13152
|
+
*
|
|
13153
|
+
* ```ts import.meta.vitest
|
|
13154
|
+
* import { Effect } from "effect"
|
|
13155
|
+
* const output: Array<unknown> = []
|
|
13156
|
+
* const record = (value: unknown) => Effect.sync(() => { output.push(value) })
|
|
13157
|
+
*
|
|
13158
|
+
* let i = 1
|
|
13159
|
+
* const expensiveTask = Effect.sync(() => {
|
|
13160
|
+
* void output.push("expensive task...")
|
|
13161
|
+
* return `result ${i++}`
|
|
13162
|
+
* })
|
|
13163
|
+
*
|
|
13164
|
+
* const program = Effect.gen(function*() {
|
|
13165
|
+
* const cached = yield* Effect.cachedWithTTL(expensiveTask, "1 hour")
|
|
13166
|
+
* yield* cached.pipe(Effect.andThen(record))
|
|
13167
|
+
* yield* cached.pipe(Effect.andThen(record))
|
|
13168
|
+
* yield* cached.pipe(Effect.andThen(record))
|
|
13169
|
+
* })
|
|
13170
|
+
*
|
|
13171
|
+
* Effect.runSync(program)
|
|
13172
|
+
* output // => ["expensive task...", "result 1", "result 1", "result 1"]
|
|
13173
|
+
* ```
|
|
13174
|
+
*
|
|
13175
|
+
* **Example** (Caching successes while retrying failures)
|
|
13176
|
+
*
|
|
13177
|
+
* ```ts import.meta.vitest
|
|
13178
|
+
* import { Effect, Exit } from "effect"
|
|
13179
|
+
*
|
|
13180
|
+
* let attempts = 0
|
|
13181
|
+
* const task = Effect.suspend(() =>
|
|
13182
|
+
* ++attempts === 1 ? Effect.fail("temporary failure") : Effect.succeed(42)
|
|
13183
|
+
* )
|
|
13184
|
+
* const program = Effect.gen(function*() {
|
|
13185
|
+
* const cached = yield* task.pipe(
|
|
13186
|
+
* Effect.cachedWithTTL((exit) => Exit.isSuccess(exit) ? "1 hour" : 0)
|
|
13187
|
+
* )
|
|
13188
|
+
* yield* Effect.exit(cached)
|
|
13189
|
+
* return yield* cached
|
|
13190
|
+
* })
|
|
13191
|
+
*
|
|
13192
|
+
* Effect.runSync(program) // => 42
|
|
13193
|
+
* ```
|
|
13194
|
+
*
|
|
13049
13195
|
* @see {@link cached} for a similar function that caches the result
|
|
13050
13196
|
* indefinitely.
|
|
13051
13197
|
* @see {@link cachedInvalidateWithTTL} for a similar function that includes an
|
|
@@ -13055,8 +13201,8 @@ export declare const cachedWithTTL: {
|
|
|
13055
13201
|
*/
|
|
13056
13202
|
(timeToLive: Duration.Input): <A, E, R>(self: Effect<A, E, R>) => Effect<Effect<A, E, R>>;
|
|
13057
13203
|
/**
|
|
13058
|
-
* Returns an effect that caches its result for a
|
|
13059
|
-
* known as "timeToLive" (TTL).
|
|
13204
|
+
* Returns an effect that caches its result for a fixed duration or a duration
|
|
13205
|
+
* computed from its `Exit`, known as "timeToLive" (TTL).
|
|
13060
13206
|
*
|
|
13061
13207
|
* **When to use**
|
|
13062
13208
|
*
|
|
@@ -13075,6 +13221,17 @@ export declare const cachedWithTTL: {
|
|
|
13075
13221
|
* After the specified duration has passed, the cache expires, and the effect
|
|
13076
13222
|
* will be recomputed upon the next evaluation.
|
|
13077
13223
|
*
|
|
13224
|
+
* `timeToLive` accepts a `Duration.Input` or a function from `Exit<A, E>` to
|
|
13225
|
+
* `Duration.Input`. The function runs once after each fresh computation,
|
|
13226
|
+
* including failures, so successes and failures can have different TTLs. It
|
|
13227
|
+
* does not run when the cache is created or when a cached result is reused.
|
|
13228
|
+
* The callback also receives interruption exits, which are cached for the
|
|
13229
|
+
* returned duration.
|
|
13230
|
+
*
|
|
13231
|
+
* The TTL starts when the computation completes. Concurrent callers share the
|
|
13232
|
+
* pending computation. A zero TTL expires immediately, and an infinite TTL
|
|
13233
|
+
* keeps the result indefinitely.
|
|
13234
|
+
*
|
|
13078
13235
|
* **Example** (Memoizing an effect with TTL)
|
|
13079
13236
|
*
|
|
13080
13237
|
* ```ts import.meta.vitest
|
|
@@ -13099,6 +13256,110 @@ export declare const cachedWithTTL: {
|
|
|
13099
13256
|
* output // => ["expensive task...", "result 1", "result 1", "result 1"]
|
|
13100
13257
|
* ```
|
|
13101
13258
|
*
|
|
13259
|
+
* **Example** (Caching successes while retrying failures)
|
|
13260
|
+
*
|
|
13261
|
+
* ```ts import.meta.vitest
|
|
13262
|
+
* import { Effect, Exit } from "effect"
|
|
13263
|
+
*
|
|
13264
|
+
* let attempts = 0
|
|
13265
|
+
* const task = Effect.suspend(() =>
|
|
13266
|
+
* ++attempts === 1 ? Effect.fail("temporary failure") : Effect.succeed(42)
|
|
13267
|
+
* )
|
|
13268
|
+
* const program = Effect.gen(function*() {
|
|
13269
|
+
* const cached = yield* task.pipe(
|
|
13270
|
+
* Effect.cachedWithTTL((exit) => Exit.isSuccess(exit) ? "1 hour" : 0)
|
|
13271
|
+
* )
|
|
13272
|
+
* yield* Effect.exit(cached)
|
|
13273
|
+
* return yield* cached
|
|
13274
|
+
* })
|
|
13275
|
+
*
|
|
13276
|
+
* Effect.runSync(program) // => 42
|
|
13277
|
+
* ```
|
|
13278
|
+
*
|
|
13279
|
+
* @see {@link cached} for a similar function that caches the result
|
|
13280
|
+
* indefinitely.
|
|
13281
|
+
* @see {@link cachedInvalidateWithTTL} for a similar function that includes an
|
|
13282
|
+
* additional effect for manually invalidating the cached value.
|
|
13283
|
+
* @category caching
|
|
13284
|
+
* @since 2.0.0
|
|
13285
|
+
*/
|
|
13286
|
+
<A, E>(timeToLive: Duration.Input | ((exit: Exit.Exit<A, E>) => Duration.Input)): <R>(self: Effect<A, E, R>) => Effect<Effect<A, E, R>>;
|
|
13287
|
+
/**
|
|
13288
|
+
* Returns an effect that caches its result for a fixed duration or a duration
|
|
13289
|
+
* computed from its `Exit`, known as "timeToLive" (TTL).
|
|
13290
|
+
*
|
|
13291
|
+
* **When to use**
|
|
13292
|
+
*
|
|
13293
|
+
* Use when you need a costly effect result to be reused for a bounded duration
|
|
13294
|
+
* before being recomputed.
|
|
13295
|
+
*
|
|
13296
|
+
* **Details**
|
|
13297
|
+
*
|
|
13298
|
+
* This function is used to cache the result of an effect for a specified amount
|
|
13299
|
+
* of time. This means that the first time the effect is evaluated, its result
|
|
13300
|
+
* is computed and stored.
|
|
13301
|
+
*
|
|
13302
|
+
* If the effect is evaluated again within the specified `timeToLive`, the
|
|
13303
|
+
* cached result will be used, avoiding recomputation.
|
|
13304
|
+
*
|
|
13305
|
+
* After the specified duration has passed, the cache expires, and the effect
|
|
13306
|
+
* will be recomputed upon the next evaluation.
|
|
13307
|
+
*
|
|
13308
|
+
* `timeToLive` accepts a `Duration.Input` or a function from `Exit<A, E>` to
|
|
13309
|
+
* `Duration.Input`. The function runs once after each fresh computation,
|
|
13310
|
+
* including failures, so successes and failures can have different TTLs. It
|
|
13311
|
+
* does not run when the cache is created or when a cached result is reused.
|
|
13312
|
+
* The callback also receives interruption exits, which are cached for the
|
|
13313
|
+
* returned duration.
|
|
13314
|
+
*
|
|
13315
|
+
* The TTL starts when the computation completes. Concurrent callers share the
|
|
13316
|
+
* pending computation. A zero TTL expires immediately, and an infinite TTL
|
|
13317
|
+
* keeps the result indefinitely.
|
|
13318
|
+
*
|
|
13319
|
+
* **Example** (Memoizing an effect with TTL)
|
|
13320
|
+
*
|
|
13321
|
+
* ```ts import.meta.vitest
|
|
13322
|
+
* import { Effect } from "effect"
|
|
13323
|
+
* const output: Array<unknown> = []
|
|
13324
|
+
* const record = (value: unknown) => Effect.sync(() => { output.push(value) })
|
|
13325
|
+
*
|
|
13326
|
+
* let i = 1
|
|
13327
|
+
* const expensiveTask = Effect.sync(() => {
|
|
13328
|
+
* void output.push("expensive task...")
|
|
13329
|
+
* return `result ${i++}`
|
|
13330
|
+
* })
|
|
13331
|
+
*
|
|
13332
|
+
* const program = Effect.gen(function*() {
|
|
13333
|
+
* const cached = yield* Effect.cachedWithTTL(expensiveTask, "1 hour")
|
|
13334
|
+
* yield* cached.pipe(Effect.andThen(record))
|
|
13335
|
+
* yield* cached.pipe(Effect.andThen(record))
|
|
13336
|
+
* yield* cached.pipe(Effect.andThen(record))
|
|
13337
|
+
* })
|
|
13338
|
+
*
|
|
13339
|
+
* Effect.runSync(program)
|
|
13340
|
+
* output // => ["expensive task...", "result 1", "result 1", "result 1"]
|
|
13341
|
+
* ```
|
|
13342
|
+
*
|
|
13343
|
+
* **Example** (Caching successes while retrying failures)
|
|
13344
|
+
*
|
|
13345
|
+
* ```ts import.meta.vitest
|
|
13346
|
+
* import { Effect, Exit } from "effect"
|
|
13347
|
+
*
|
|
13348
|
+
* let attempts = 0
|
|
13349
|
+
* const task = Effect.suspend(() =>
|
|
13350
|
+
* ++attempts === 1 ? Effect.fail("temporary failure") : Effect.succeed(42)
|
|
13351
|
+
* )
|
|
13352
|
+
* const program = Effect.gen(function*() {
|
|
13353
|
+
* const cached = yield* task.pipe(
|
|
13354
|
+
* Effect.cachedWithTTL((exit) => Exit.isSuccess(exit) ? "1 hour" : 0)
|
|
13355
|
+
* )
|
|
13356
|
+
* yield* Effect.exit(cached)
|
|
13357
|
+
* return yield* cached
|
|
13358
|
+
* })
|
|
13359
|
+
*
|
|
13360
|
+
* Effect.runSync(program) // => 42
|
|
13361
|
+
* ```
|
|
13362
|
+
*
|
|
13102
13363
|
* @see {@link cached} for a similar function that caches the result
|
|
13103
13364
|
* indefinitely.
|
|
13104
13365
|
* @see {@link cachedInvalidateWithTTL} for a similar function that includes an
|
|
@@ -13106,7 +13367,7 @@ export declare const cachedWithTTL: {
|
|
|
13106
13367
|
* @category caching
|
|
13107
13368
|
* @since 2.0.0
|
|
13108
13369
|
*/
|
|
13109
|
-
<A, E, R>(self: Effect<A, E, R>, timeToLive: Duration.Input): Effect<Effect<A, E, R>>;
|
|
13370
|
+
<A, E, R>(self: Effect<A, E, R>, timeToLive: Duration.Input | ((exit: Exit.Exit<A, E>) => Duration.Input)): Effect<Effect<A, E, R>>;
|
|
13110
13371
|
};
|
|
13111
13372
|
/**
|
|
13112
13373
|
* Creates a cached effect result for a specified duration and allows manual
|