effect 3.9.2 → 3.10.0
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/Arbitrary/package.json +6 -0
- package/FastCheck/package.json +6 -0
- package/JSONSchema/package.json +6 -0
- package/ParseResult/package.json +6 -0
- package/Pretty/package.json +6 -0
- package/Schema/package.json +6 -0
- package/SchemaAST/package.json +6 -0
- package/TSubscriptionRef/package.json +6 -0
- package/dist/cjs/Arbitrary.js +490 -0
- package/dist/cjs/Arbitrary.js.map +1 -0
- package/dist/cjs/Effect.js +247 -16
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/FastCheck.js +17 -0
- package/dist/cjs/FastCheck.js.map +1 -0
- package/dist/cjs/Inspectable.js +43 -3
- package/dist/cjs/Inspectable.js.map +1 -1
- package/dist/cjs/JSONSchema.js +418 -0
- package/dist/cjs/JSONSchema.js.map +1 -0
- package/dist/cjs/ParseResult.js +1539 -0
- package/dist/cjs/ParseResult.js.map +1 -0
- package/dist/cjs/Predicate.js +3 -1
- package/dist/cjs/Predicate.js.map +1 -1
- package/dist/cjs/Pretty.js +183 -0
- package/dist/cjs/Pretty.js.map +1 -0
- package/dist/cjs/Schema.js +5529 -0
- package/dist/cjs/Schema.js.map +1 -0
- package/dist/cjs/SchemaAST.js +2365 -0
- package/dist/cjs/SchemaAST.js.map +1 -0
- package/dist/cjs/Stream.js +17 -3
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/TPubSub.js +9 -1
- package/dist/cjs/TPubSub.js.map +1 -1
- package/dist/cjs/TQueue.js.map +1 -1
- package/dist/cjs/TRef.js.map +1 -1
- package/dist/cjs/TSubscriptionRef.js +96 -0
- package/dist/cjs/TSubscriptionRef.js.map +1 -0
- package/dist/cjs/index.js +18 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/cause.js +2 -2
- package/dist/cjs/internal/cause.js.map +1 -1
- package/dist/cjs/internal/core.js +4 -4
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +14 -12
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/logger.js +7 -6
- package/dist/cjs/internal/logger.js.map +1 -1
- package/dist/cjs/internal/redacted.js +4 -0
- package/dist/cjs/internal/redacted.js.map +1 -1
- package/dist/cjs/internal/schema/errors.js +116 -0
- package/dist/cjs/internal/schema/errors.js.map +1 -0
- package/dist/cjs/internal/schema/filters.js +41 -0
- package/dist/cjs/internal/schema/filters.js.map +1 -0
- package/dist/cjs/internal/schema/util.js +96 -0
- package/dist/cjs/internal/schema/util.js.map +1 -0
- package/dist/cjs/internal/stm/core.js +2 -3
- package/dist/cjs/internal/stm/core.js.map +1 -1
- package/dist/cjs/internal/stm/tPubSub.js.map +1 -1
- package/dist/cjs/internal/stm/tQueue.js +1 -2
- package/dist/cjs/internal/stm/tQueue.js.map +1 -1
- package/dist/cjs/internal/stm/tRef.js +6 -2
- package/dist/cjs/internal/stm/tRef.js.map +1 -1
- package/dist/cjs/internal/stm/tSubscriptionRef.js +178 -0
- package/dist/cjs/internal/stm/tSubscriptionRef.js.map +1 -0
- package/dist/cjs/internal/stream.js +36 -16
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/cjs/internal/version.js.map +1 -1
- package/dist/dts/Arbitrary.d.ts +45 -0
- package/dist/dts/Arbitrary.d.ts.map +1 -0
- package/dist/dts/Effect.d.ts +298 -30
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/FastCheck.d.ts +9 -0
- package/dist/dts/FastCheck.d.ts.map +1 -0
- package/dist/dts/Inspectable.d.ts +28 -0
- package/dist/dts/Inspectable.d.ts.map +1 -1
- package/dist/dts/JSONSchema.d.ts +181 -0
- package/dist/dts/JSONSchema.d.ts.map +1 -0
- package/dist/dts/ParseResult.d.ts +551 -0
- package/dist/dts/ParseResult.d.ts.map +1 -0
- package/dist/dts/Predicate.d.ts.map +1 -1
- package/dist/dts/Pretty.d.ts +26 -0
- package/dist/dts/Pretty.d.ts.map +1 -0
- package/dist/dts/Schema.d.ts +4562 -0
- package/dist/dts/Schema.d.ts.map +1 -0
- package/dist/dts/SchemaAST.d.ts +1321 -0
- package/dist/dts/SchemaAST.d.ts.map +1 -0
- package/dist/dts/Stream.d.ts +67 -2
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/TPubSub.d.ts +8 -0
- package/dist/dts/TPubSub.d.ts.map +1 -1
- package/dist/dts/TQueue.d.ts +7 -7
- package/dist/dts/TQueue.d.ts.map +1 -1
- package/dist/dts/TRef.d.ts +2 -1
- package/dist/dts/TRef.d.ts.map +1 -1
- package/dist/dts/TSubscriptionRef.d.ts +251 -0
- package/dist/dts/TSubscriptionRef.d.ts.map +1 -0
- package/dist/dts/index.d.ts +32 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
- package/dist/dts/internal/schema/errors.d.ts +2 -0
- package/dist/dts/internal/schema/errors.d.ts.map +1 -0
- package/dist/dts/internal/schema/filters.d.ts +2 -0
- package/dist/dts/internal/schema/filters.d.ts.map +1 -0
- package/dist/dts/internal/schema/util.d.ts +2 -0
- package/dist/dts/internal/schema/util.d.ts.map +1 -0
- package/dist/dts/internal/stm/tRef.d.ts +3 -1
- package/dist/dts/internal/stm/tRef.d.ts.map +1 -1
- package/dist/dts/internal/stm/tSubscriptionRef.d.ts +2 -0
- package/dist/dts/internal/stm/tSubscriptionRef.d.ts.map +1 -0
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Arbitrary.js +472 -0
- package/dist/esm/Arbitrary.js.map +1 -0
- package/dist/esm/Effect.js +256 -18
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/FastCheck.js +9 -0
- package/dist/esm/FastCheck.js.map +1 -0
- package/dist/esm/Inspectable.js +39 -2
- package/dist/esm/Inspectable.js.map +1 -1
- package/dist/esm/JSONSchema.js +408 -0
- package/dist/esm/JSONSchema.js.map +1 -0
- package/dist/esm/ParseResult.js +1503 -0
- package/dist/esm/ParseResult.js.map +1 -0
- package/dist/esm/Predicate.js +2 -1
- package/dist/esm/Predicate.js.map +1 -1
- package/dist/esm/Pretty.js +173 -0
- package/dist/esm/Pretty.js.map +1 -0
- package/dist/esm/Schema.js +5328 -0
- package/dist/esm/Schema.js.map +1 -0
- package/dist/esm/SchemaAST.js +2300 -0
- package/dist/esm/SchemaAST.js.map +1 -0
- package/dist/esm/Stream.js +14 -0
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/TPubSub.js +8 -0
- package/dist/esm/TPubSub.js.map +1 -1
- package/dist/esm/TQueue.js.map +1 -1
- package/dist/esm/TRef.js.map +1 -1
- package/dist/esm/TSubscriptionRef.js +87 -0
- package/dist/esm/TSubscriptionRef.js.map +1 -0
- package/dist/esm/index.js +32 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/cause.js +3 -3
- package/dist/esm/internal/cause.js.map +1 -1
- package/dist/esm/internal/core.js +4 -4
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +14 -12
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/logger.js +7 -6
- package/dist/esm/internal/logger.js.map +1 -1
- package/dist/esm/internal/redacted.js +4 -0
- package/dist/esm/internal/redacted.js.map +1 -1
- package/dist/esm/internal/schema/errors.js +87 -0
- package/dist/esm/internal/schema/errors.js.map +1 -0
- package/dist/esm/internal/schema/filters.js +35 -0
- package/dist/esm/internal/schema/filters.js.map +1 -0
- package/dist/esm/internal/schema/util.js +78 -0
- package/dist/esm/internal/schema/util.js.map +1 -0
- package/dist/esm/internal/stm/core.js +1 -2
- package/dist/esm/internal/stm/core.js.map +1 -1
- package/dist/esm/internal/stm/tPubSub.js.map +1 -1
- package/dist/esm/internal/stm/tQueue.js +1 -2
- package/dist/esm/internal/stm/tQueue.js.map +1 -1
- package/dist/esm/internal/stm/tRef.js +5 -1
- package/dist/esm/internal/stm/tRef.js.map +1 -1
- package/dist/esm/internal/stm/tSubscriptionRef.js +166 -0
- package/dist/esm/internal/stm/tSubscriptionRef.js.map +1 -0
- package/dist/esm/internal/stream.js +33 -15
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/dist/esm/internal/version.js.map +1 -1
- package/package.json +68 -1
- package/src/Arbitrary.ts +563 -0
- package/src/Effect.ts +302 -31
- package/src/FastCheck.ts +9 -0
- package/src/Inspectable.ts +56 -2
- package/src/JSONSchema.ts +601 -0
- package/src/ParseResult.ts +2027 -0
- package/src/Predicate.ts +3 -1
- package/src/Pretty.ts +204 -0
- package/src/Schema.ts +10388 -0
- package/src/SchemaAST.ts +2827 -0
- package/src/Stream.ts +77 -9
- package/src/TPubSub.ts +9 -0
- package/src/TQueue.ts +7 -7
- package/src/TRef.ts +2 -1
- package/src/TSubscriptionRef.ts +284 -0
- package/src/index.ts +40 -0
- package/src/internal/cause.ts +3 -3
- package/src/internal/core-effect.ts +2 -2
- package/src/internal/core.ts +4 -4
- package/src/internal/fiberRuntime.ts +14 -12
- package/src/internal/logger.ts +7 -6
- package/src/internal/redacted.ts +4 -0
- package/src/internal/schema/errors.ts +189 -0
- package/src/internal/schema/filters.ts +86 -0
- package/src/internal/schema/util.ts +113 -0
- package/src/internal/stm/core.ts +1 -2
- package/src/internal/stm/tPubSub.ts +1 -0
- package/src/internal/stm/tQueue.ts +2 -2
- package/src/internal/stm/tRef.ts +7 -2
- package/src/internal/stm/tSubscriptionRef.ts +286 -0
- package/src/internal/stream.ts +97 -20
- package/src/internal/version.ts +1 -1
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.setCurrentVersion = exports.getCurrentVersion = void 0;
|
|
7
|
-
let moduleVersion = "3.
|
|
7
|
+
let moduleVersion = "3.10.0";
|
|
8
8
|
const getCurrentVersion = () => moduleVersion;
|
|
9
9
|
exports.getCurrentVersion = getCurrentVersion;
|
|
10
10
|
const setCurrentVersion = version => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":["moduleVersion","getCurrentVersion","exports","setCurrentVersion","version"],"sources":["../../../src/internal/version.ts"],"sourcesContent":[null],"mappings":";;;;;;AAAA,IAAIA,aAAa,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","names":["moduleVersion","getCurrentVersion","exports","setCurrentVersion","version"],"sources":["../../../src/internal/version.ts"],"sourcesContent":[null],"mappings":";;;;;;AAAA,IAAIA,aAAa,GAAG,QAAQ;AAErB,MAAMC,iBAAiB,GAAGA,CAAA,KAAMD,aAAa;AAAAE,OAAA,CAAAD,iBAAA,GAAAA,iBAAA;AAE7C,MAAME,iBAAiB,GAAIC,OAAe,IAAI;EACnDJ,aAAa,GAAGI,OAAO;AACzB,CAAC;AAAAF,OAAA,CAAAC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 3.10.0
|
|
3
|
+
*/
|
|
4
|
+
import * as FastCheck from "./FastCheck.js";
|
|
5
|
+
import type * as Schema from "./Schema.js";
|
|
6
|
+
/**
|
|
7
|
+
* @category model
|
|
8
|
+
* @since 3.10.0
|
|
9
|
+
*/
|
|
10
|
+
export interface LazyArbitrary<A> {
|
|
11
|
+
(fc: typeof FastCheck): FastCheck.Arbitrary<A>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @category annotations
|
|
15
|
+
* @since 3.10.0
|
|
16
|
+
*/
|
|
17
|
+
export interface ArbitraryGenerationContext {
|
|
18
|
+
readonly depthIdentifier?: string;
|
|
19
|
+
readonly maxDepth: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @category annotations
|
|
23
|
+
* @since 3.10.0
|
|
24
|
+
*/
|
|
25
|
+
export type ArbitraryAnnotation<A, TypeParameters extends ReadonlyArray<any> = readonly []> = (...arbitraries: [
|
|
26
|
+
...{
|
|
27
|
+
readonly [K in keyof TypeParameters]: LazyArbitrary<TypeParameters[K]>;
|
|
28
|
+
},
|
|
29
|
+
ctx: ArbitraryGenerationContext
|
|
30
|
+
]) => LazyArbitrary<A>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns a LazyArbitrary for the `A` type of the provided schema.
|
|
33
|
+
*
|
|
34
|
+
* @category arbitrary
|
|
35
|
+
* @since 3.10.0
|
|
36
|
+
*/
|
|
37
|
+
export declare const makeLazy: <A, I, R>(schema: Schema.Schema<A, I, R>) => LazyArbitrary<A>;
|
|
38
|
+
/**
|
|
39
|
+
* Returns a fast-check Arbitrary for the `A` type of the provided schema.
|
|
40
|
+
*
|
|
41
|
+
* @category arbitrary
|
|
42
|
+
* @since 3.10.0
|
|
43
|
+
*/
|
|
44
|
+
export declare const make: <A, I, R>(schema: Schema.Schema<A, I, R>) => FastCheck.Arbitrary<A>;
|
|
45
|
+
//# sourceMappingURL=Arbitrary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Arbitrary.d.ts","sourceRoot":"","sources":["../../src/Arbitrary.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAM3C,OAAO,KAAK,KAAK,MAAM,MAAM,aAAa,CAAA;AAG1C;;;GAGG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,CAAC,EAAE,EAAE,OAAO,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;CAC/C;AAED;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAED;;;GAGG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,EAAE,cAAc,SAAS,aAAa,CAAC,GAAG,CAAC,GAAG,SAAS,EAAE,IAAI,CAC5F,GAAG,WAAW,EAAE;IACd,GAAG;QAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,cAAc,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;KAAE;IAC7E,GAAG,EAAE,0BAA0B;CAChC,KACE,aAAa,CAAC,CAAC,CAAC,CAAA;AAErB;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAG,aAAa,CAAC,CAAC,CAC7C,CAAA;AAErC;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAgC,CAAA"}
|
package/dist/dts/Effect.d.ts
CHANGED
|
@@ -1390,25 +1390,45 @@ export declare const validateFirst: {
|
|
|
1390
1390
|
} | undefined): Effect<B, Array<E>, R>;
|
|
1391
1391
|
};
|
|
1392
1392
|
/**
|
|
1393
|
-
*
|
|
1394
|
-
* function `Effect<A, E, R> => void` **MUST** be called at most once.
|
|
1393
|
+
* Creates an `Effect` from a callback-based asynchronous API.
|
|
1395
1394
|
*
|
|
1396
|
-
*
|
|
1397
|
-
* executed if the `Fiber` executing this Effect is interrupted.
|
|
1395
|
+
* Useful for integrating Node.js-style callback functions into the Effect system.
|
|
1398
1396
|
*
|
|
1399
|
-
* The
|
|
1397
|
+
* The `resume` function **MUST** be called at most once.
|
|
1398
|
+
*
|
|
1399
|
+
* The `resume` function can optionally return an `Effect`, which will be
|
|
1400
|
+
* executed if the `Fiber` executing this `Effect` is interrupted.
|
|
1401
|
+
*
|
|
1402
|
+
* The `resume` function can also receive an `AbortSignal` if required for
|
|
1400
1403
|
* interruption.
|
|
1401
1404
|
*
|
|
1402
1405
|
* The `FiberId` of the fiber that may complete the async callback may also be
|
|
1403
1406
|
* specified. This is called the "blocking fiber" because it suspends the fiber
|
|
1404
|
-
* executing the `async`
|
|
1407
|
+
* executing the `async` effect (i.e. semantically blocks the fiber from making
|
|
1405
1408
|
* progress). Specifying this fiber id in cases where it is known will improve
|
|
1406
1409
|
* diagnostics, but not affect the behavior of the returned effect.
|
|
1407
1410
|
*
|
|
1411
|
+
* @example
|
|
1412
|
+
* import { Effect } from "effect"
|
|
1413
|
+
* import * as fs from "fs"
|
|
1414
|
+
*
|
|
1415
|
+
* // Wrapping a callback-based API using Effect.async
|
|
1416
|
+
* const readFile = (filename: string) => Effect.async<Buffer, Error>((resume) => {
|
|
1417
|
+
* fs.readFile(filename, (error, data) => {
|
|
1418
|
+
* if (error) {
|
|
1419
|
+
* resume(Effect.fail(error))
|
|
1420
|
+
* } else {
|
|
1421
|
+
* resume(Effect.succeed(data))
|
|
1422
|
+
* }
|
|
1423
|
+
* });
|
|
1424
|
+
* });
|
|
1425
|
+
*
|
|
1426
|
+
* const program = readFile("todos.txt")
|
|
1427
|
+
*
|
|
1408
1428
|
* @since 2.0.0
|
|
1409
1429
|
* @category constructors
|
|
1410
1430
|
*/
|
|
1411
|
-
export declare const async: <A, E = never, R = never>(
|
|
1431
|
+
export declare const async: <A, E = never, R = never>(resume: (callback: (_: Effect<A, E, R>) => void, signal: AbortSignal) => void | Effect<void, never, R>, blockingOn?: FiberId.FiberId) => Effect<A, E, R>;
|
|
1412
1432
|
/**
|
|
1413
1433
|
* Converts an asynchronous, callback-style API into an `Effect`, which will
|
|
1414
1434
|
* be executed asynchronously.
|
|
@@ -1503,6 +1523,29 @@ export declare const custom: {
|
|
|
1503
1523
|
*/
|
|
1504
1524
|
export declare const withFiberRuntime: <A, E = never, R = never>(withRuntime: (fiber: Fiber.RuntimeFiber<A, E>, status: FiberStatus.Running) => Effect<A, E, R>) => Effect<A, E, R>;
|
|
1505
1525
|
/**
|
|
1526
|
+
* Creates an `Effect` that represents a recoverable error.
|
|
1527
|
+
*
|
|
1528
|
+
* This `Effect` does not succeed but instead fails with the provided error. The
|
|
1529
|
+
* failure can be of any type, and will propagate through the effect pipeline
|
|
1530
|
+
* unless handled.
|
|
1531
|
+
*
|
|
1532
|
+
* Use this function when you want to explicitly signal an error in an `Effect`
|
|
1533
|
+
* computation. The failed effect can later be handled with functions like
|
|
1534
|
+
* {@link catchAll} or {@link catchTag}.
|
|
1535
|
+
*
|
|
1536
|
+
* @example
|
|
1537
|
+
* import { Effect } from "effect"
|
|
1538
|
+
*
|
|
1539
|
+
* // Example of creating a failed effect
|
|
1540
|
+
* const failedEffect = Effect.fail("Something went wrong")
|
|
1541
|
+
*
|
|
1542
|
+
* // Handle the failure
|
|
1543
|
+
* failedEffect.pipe(
|
|
1544
|
+
* Effect.catchAll((error) => Effect.succeed(`Recovered from: ${error}`)),
|
|
1545
|
+
* Effect.runPromise
|
|
1546
|
+
* ).then(console.log)
|
|
1547
|
+
* // Output: "Recovered from: Something went wrong"
|
|
1548
|
+
*
|
|
1506
1549
|
* @since 2.0.0
|
|
1507
1550
|
* @category constructors
|
|
1508
1551
|
*/
|
|
@@ -1608,16 +1651,40 @@ export declare const never: Effect<never>;
|
|
|
1608
1651
|
*/
|
|
1609
1652
|
export declare const none: <A, E, R>(self: Effect<Option.Option<A>, E, R>) => Effect<void, E | Cause.NoSuchElementException, R>;
|
|
1610
1653
|
/**
|
|
1611
|
-
*
|
|
1654
|
+
* Creates an `Effect` that represents an asynchronous computation guaranteed to succeed.
|
|
1655
|
+
*
|
|
1656
|
+
* The provided function (`thunk`) returns a `Promise` that should never reject.
|
|
1657
|
+
* If the `Promise` does reject, the rejection is treated as a defect.
|
|
1612
1658
|
*
|
|
1613
1659
|
* An optional `AbortSignal` can be provided to allow for interruption of the
|
|
1614
|
-
* wrapped Promise
|
|
1660
|
+
* wrapped `Promise` API.
|
|
1661
|
+
*
|
|
1662
|
+
* @example
|
|
1663
|
+
* import { Effect } from "effect"
|
|
1664
|
+
*
|
|
1665
|
+
* // Creating an effect that resolves after a delay
|
|
1666
|
+
* const delay = (message: string) => Effect.promise(() => new Promise((resolve) => {
|
|
1667
|
+
* setTimeout(() => resolve(message), 2000)
|
|
1668
|
+
* }))
|
|
1669
|
+
*
|
|
1670
|
+
* const program = delay("Async operation completed successfully!")
|
|
1615
1671
|
*
|
|
1616
1672
|
* @since 2.0.0
|
|
1617
1673
|
* @category constructors
|
|
1618
1674
|
*/
|
|
1619
1675
|
export declare const promise: <A>(evaluate: (signal: AbortSignal) => PromiseLike<A>) => Effect<A>;
|
|
1620
1676
|
/**
|
|
1677
|
+
* Creates an `Effect` that succeeds with the provided value.
|
|
1678
|
+
*
|
|
1679
|
+
* Use this function to represent a successful computation that yields a value of type `A`.
|
|
1680
|
+
* The effect does not fail and does not require any environmental context.
|
|
1681
|
+
*
|
|
1682
|
+
* @example
|
|
1683
|
+
* import { Effect } from "effect"
|
|
1684
|
+
*
|
|
1685
|
+
* // Creating an effect that succeeds with the number 42
|
|
1686
|
+
* const success = Effect.succeed(42)
|
|
1687
|
+
*
|
|
1621
1688
|
* @since 2.0.0
|
|
1622
1689
|
* @category constructors
|
|
1623
1690
|
*/
|
|
@@ -1637,15 +1704,49 @@ export declare const succeedNone: Effect<Option.Option<never>>;
|
|
|
1637
1704
|
*/
|
|
1638
1705
|
export declare const succeedSome: <A>(value: A) => Effect<Option.Option<A>>;
|
|
1639
1706
|
/**
|
|
1707
|
+
* Creates an `Effect` that defers the creation of another effect until it is needed.
|
|
1708
|
+
*
|
|
1709
|
+
* Useful for lazy evaluation, handling circular dependencies, or avoiding eager execution in recursive functions.
|
|
1710
|
+
*
|
|
1711
|
+
* @example
|
|
1712
|
+
* import { Effect } from "effect"
|
|
1713
|
+
*
|
|
1714
|
+
* // Handling recursion without stack overflow
|
|
1715
|
+
* const fibonacci = (n: number): Effect.Effect<number> =>
|
|
1716
|
+
* n < 2
|
|
1717
|
+
* ? Effect.succeed(1)
|
|
1718
|
+
* : Effect.zipWith(
|
|
1719
|
+
* Effect.suspend(() => fibonacci(n - 1)),
|
|
1720
|
+
* Effect.suspend(() => fibonacci(n - 2)),
|
|
1721
|
+
* (a, b) => a + b
|
|
1722
|
+
* )
|
|
1723
|
+
*
|
|
1724
|
+
* console.log(Effect.runSync(fibonacci(10))) // Output: 89
|
|
1725
|
+
*
|
|
1640
1726
|
* @since 2.0.0
|
|
1641
1727
|
* @category constructors
|
|
1642
1728
|
*/
|
|
1643
1729
|
export declare const suspend: <A, E, R>(effect: LazyArg<Effect<A, E, R>>) => Effect<A, E, R>;
|
|
1644
1730
|
/**
|
|
1731
|
+
* Creates an `Effect` that represents a synchronous side-effectful computation.
|
|
1732
|
+
*
|
|
1733
|
+
* The provided function (`thunk`) should not throw errors; if it does, the error is treated as a defect.
|
|
1734
|
+
* Use `Effect.sync` when you are certain the operation will not fail.
|
|
1735
|
+
*
|
|
1736
|
+
* @example
|
|
1737
|
+
* import { Effect } from "effect"
|
|
1738
|
+
*
|
|
1739
|
+
* // Creating an effect that logs a message
|
|
1740
|
+
* const log = (message: string) => Effect.sync(() => {
|
|
1741
|
+
* console.log(message) // side effect
|
|
1742
|
+
* })
|
|
1743
|
+
*
|
|
1744
|
+
* const program = log("Hello, World!")
|
|
1745
|
+
*
|
|
1645
1746
|
* @since 2.0.0
|
|
1646
1747
|
* @category constructors
|
|
1647
1748
|
*/
|
|
1648
|
-
export declare const sync: <A>(
|
|
1749
|
+
export declare const sync: <A>(thunk: LazyArg<A>) => Effect<A>;
|
|
1649
1750
|
declare const _void: Effect<void>;
|
|
1650
1751
|
export {
|
|
1651
1752
|
/**
|
|
@@ -2147,12 +2248,19 @@ declare const try_: {
|
|
|
2147
2248
|
readonly try: LazyArg<A>;
|
|
2148
2249
|
readonly catch: (error: unknown) => E;
|
|
2149
2250
|
}): Effect<A, E>;
|
|
2150
|
-
<A>(
|
|
2251
|
+
<A>(thunk: LazyArg<A>): Effect<A, Cause.UnknownException>;
|
|
2151
2252
|
};
|
|
2152
2253
|
export {
|
|
2153
2254
|
/**
|
|
2154
|
-
*
|
|
2155
|
-
*
|
|
2255
|
+
* Creates an `Effect` that represents a synchronous computation that might fail.
|
|
2256
|
+
*
|
|
2257
|
+
* If the function (`thunk`) throws an error, it is caught and the effect fails with an `UnknownException`.
|
|
2258
|
+
*
|
|
2259
|
+
* **Overload with custom error handling:**
|
|
2260
|
+
*
|
|
2261
|
+
* Creates an `Effect` that represents a synchronous computation that might fail, with custom error mapping.
|
|
2262
|
+
*
|
|
2263
|
+
* If the `try` function throws an error, the `catch` function maps it to an error of type `E`.
|
|
2156
2264
|
*
|
|
2157
2265
|
* @since 2.0.0
|
|
2158
2266
|
* @category error handling
|
|
@@ -2198,7 +2306,7 @@ export declare const tryMap: {
|
|
|
2198
2306
|
* via the `catch` function.
|
|
2199
2307
|
*
|
|
2200
2308
|
* An optional `AbortSignal` can be provided to allow for interruption of the
|
|
2201
|
-
* wrapped Promise
|
|
2309
|
+
* wrapped `Promise` API.
|
|
2202
2310
|
*
|
|
2203
2311
|
* @since 2.0.0
|
|
2204
2312
|
* @category error handling
|
|
@@ -2210,7 +2318,7 @@ export declare const tryMapPromise: {
|
|
|
2210
2318
|
* via the `catch` function.
|
|
2211
2319
|
*
|
|
2212
2320
|
* An optional `AbortSignal` can be provided to allow for interruption of the
|
|
2213
|
-
* wrapped Promise
|
|
2321
|
+
* wrapped `Promise` API.
|
|
2214
2322
|
*
|
|
2215
2323
|
* @since 2.0.0
|
|
2216
2324
|
* @category error handling
|
|
@@ -2225,7 +2333,7 @@ export declare const tryMapPromise: {
|
|
|
2225
2333
|
* via the `catch` function.
|
|
2226
2334
|
*
|
|
2227
2335
|
* An optional `AbortSignal` can be provided to allow for interruption of the
|
|
2228
|
-
* wrapped Promise
|
|
2336
|
+
* wrapped `Promise` API.
|
|
2229
2337
|
*
|
|
2230
2338
|
* @since 2.0.0
|
|
2231
2339
|
* @category error handling
|
|
@@ -2236,22 +2344,52 @@ export declare const tryMapPromise: {
|
|
|
2236
2344
|
}): Effect<B, E | E1, R>;
|
|
2237
2345
|
};
|
|
2238
2346
|
/**
|
|
2239
|
-
*
|
|
2240
|
-
*
|
|
2347
|
+
* Creates an `Effect` that represents an asynchronous computation that might fail.
|
|
2348
|
+
*
|
|
2349
|
+
* If the `Promise` returned by `evaluate` rejects, the error is caught and the effect fails with an `UnknownException`.
|
|
2241
2350
|
*
|
|
2242
2351
|
* An optional `AbortSignal` can be provided to allow for interruption of the
|
|
2243
|
-
* wrapped Promise
|
|
2352
|
+
* wrapped `Promise` API.
|
|
2353
|
+
*
|
|
2354
|
+
* **Overload with custom error handling:**
|
|
2355
|
+
*
|
|
2356
|
+
* Creates an `Effect` that represents an asynchronous computation that might fail, with custom error mapping.
|
|
2357
|
+
*
|
|
2358
|
+
* If the `Promise` rejects, the `catch` function maps the error to an error of type `E`.
|
|
2359
|
+
*
|
|
2360
|
+
* @example
|
|
2361
|
+
* import { Effect } from "effect"
|
|
2362
|
+
*
|
|
2363
|
+
* // Fetching data from an API that may fail
|
|
2364
|
+
* const getTodo = (id: number) => Effect.tryPromise(() =>
|
|
2365
|
+
* fetch(`https://jsonplaceholder.typicode.com/todos/${id}`)
|
|
2366
|
+
* )
|
|
2244
2367
|
*
|
|
2245
2368
|
* @since 2.0.0
|
|
2246
2369
|
* @category error handling
|
|
2247
2370
|
*/
|
|
2248
2371
|
export declare const tryPromise: {
|
|
2249
2372
|
/**
|
|
2250
|
-
*
|
|
2251
|
-
*
|
|
2373
|
+
* Creates an `Effect` that represents an asynchronous computation that might fail.
|
|
2374
|
+
*
|
|
2375
|
+
* If the `Promise` returned by `evaluate` rejects, the error is caught and the effect fails with an `UnknownException`.
|
|
2252
2376
|
*
|
|
2253
2377
|
* An optional `AbortSignal` can be provided to allow for interruption of the
|
|
2254
|
-
* wrapped Promise
|
|
2378
|
+
* wrapped `Promise` API.
|
|
2379
|
+
*
|
|
2380
|
+
* **Overload with custom error handling:**
|
|
2381
|
+
*
|
|
2382
|
+
* Creates an `Effect` that represents an asynchronous computation that might fail, with custom error mapping.
|
|
2383
|
+
*
|
|
2384
|
+
* If the `Promise` rejects, the `catch` function maps the error to an error of type `E`.
|
|
2385
|
+
*
|
|
2386
|
+
* @example
|
|
2387
|
+
* import { Effect } from "effect"
|
|
2388
|
+
*
|
|
2389
|
+
* // Fetching data from an API that may fail
|
|
2390
|
+
* const getTodo = (id: number) => Effect.tryPromise(() =>
|
|
2391
|
+
* fetch(`https://jsonplaceholder.typicode.com/todos/${id}`)
|
|
2392
|
+
* )
|
|
2255
2393
|
*
|
|
2256
2394
|
* @since 2.0.0
|
|
2257
2395
|
* @category error handling
|
|
@@ -2261,16 +2399,31 @@ export declare const tryPromise: {
|
|
|
2261
2399
|
readonly catch: (error: unknown) => E;
|
|
2262
2400
|
}): Effect<A, E>;
|
|
2263
2401
|
/**
|
|
2264
|
-
*
|
|
2265
|
-
*
|
|
2402
|
+
* Creates an `Effect` that represents an asynchronous computation that might fail.
|
|
2403
|
+
*
|
|
2404
|
+
* If the `Promise` returned by `evaluate` rejects, the error is caught and the effect fails with an `UnknownException`.
|
|
2266
2405
|
*
|
|
2267
2406
|
* An optional `AbortSignal` can be provided to allow for interruption of the
|
|
2268
|
-
* wrapped Promise
|
|
2407
|
+
* wrapped `Promise` API.
|
|
2408
|
+
*
|
|
2409
|
+
* **Overload with custom error handling:**
|
|
2410
|
+
*
|
|
2411
|
+
* Creates an `Effect` that represents an asynchronous computation that might fail, with custom error mapping.
|
|
2412
|
+
*
|
|
2413
|
+
* If the `Promise` rejects, the `catch` function maps the error to an error of type `E`.
|
|
2414
|
+
*
|
|
2415
|
+
* @example
|
|
2416
|
+
* import { Effect } from "effect"
|
|
2417
|
+
*
|
|
2418
|
+
* // Fetching data from an API that may fail
|
|
2419
|
+
* const getTodo = (id: number) => Effect.tryPromise(() =>
|
|
2420
|
+
* fetch(`https://jsonplaceholder.typicode.com/todos/${id}`)
|
|
2421
|
+
* )
|
|
2269
2422
|
*
|
|
2270
2423
|
* @since 2.0.0
|
|
2271
2424
|
* @category error handling
|
|
2272
2425
|
*/
|
|
2273
|
-
<A>(
|
|
2426
|
+
<A>(evaluate: (signal: AbortSignal) => PromiseLike<A>): Effect<A, Cause.UnknownException>;
|
|
2274
2427
|
};
|
|
2275
2428
|
/**
|
|
2276
2429
|
* The inverse operation `sandbox(effect)`
|
|
@@ -7840,6 +7993,28 @@ export declare const unsafeMakeLatch: (open?: boolean | undefined) => Latch;
|
|
|
7840
7993
|
*/
|
|
7841
7994
|
export declare const makeLatch: (open?: boolean | undefined) => Effect<Latch, never, never>;
|
|
7842
7995
|
/**
|
|
7996
|
+
* Executes an effect and returns a `RuntimeFiber` that represents the running computation.
|
|
7997
|
+
*
|
|
7998
|
+
* Use `runFork` when you want to start an effect without blocking the current execution flow.
|
|
7999
|
+
* It returns a fiber that you can observe, interrupt, or join as needed.
|
|
8000
|
+
*
|
|
8001
|
+
* @example
|
|
8002
|
+
* import { Effect, Console, Schedule, Fiber } from "effect"
|
|
8003
|
+
*
|
|
8004
|
+
* // Define an effect that repeats a message every 200 milliseconds
|
|
8005
|
+
* const program = Effect.repeat(
|
|
8006
|
+
* Console.log("running..."),
|
|
8007
|
+
* Schedule.spaced("200 millis")
|
|
8008
|
+
* )
|
|
8009
|
+
*
|
|
8010
|
+
* // Start the effect without blocking
|
|
8011
|
+
* const fiber = Effect.runFork(program)
|
|
8012
|
+
*
|
|
8013
|
+
* // Interrupt the fiber after 500 milliseconds
|
|
8014
|
+
* setTimeout(() => {
|
|
8015
|
+
* Effect.runFork(Fiber.interrupt(fiber))
|
|
8016
|
+
* }, 500)
|
|
8017
|
+
*
|
|
7843
8018
|
* @since 2.0.0
|
|
7844
8019
|
* @category execution
|
|
7845
8020
|
*/
|
|
@@ -7850,8 +8025,21 @@ export declare const runFork: <A, E>(effect: Effect<A, E>, options?: Runtime.Run
|
|
|
7850
8025
|
*/
|
|
7851
8026
|
export declare const runCallback: <A, E>(effect: Effect<A, E>, options?: Runtime.RunCallbackOptions<A, E> | undefined) => Runtime.Cancel<A, E>;
|
|
7852
8027
|
/**
|
|
7853
|
-
*
|
|
7854
|
-
*
|
|
8028
|
+
* Executes an effect and returns a `Promise` that resolves with the result.
|
|
8029
|
+
*
|
|
8030
|
+
* Use `runPromise` when working with asynchronous effects and you need to integrate with code that uses Promises.
|
|
8031
|
+
* If the effect fails, the returned Promise will be rejected with the error.
|
|
8032
|
+
*
|
|
8033
|
+
* @example
|
|
8034
|
+
* import { Effect } from "effect"
|
|
8035
|
+
*
|
|
8036
|
+
* // Execute an effect and handle the result with a Promise
|
|
8037
|
+
* Effect.runPromise(Effect.succeed(1)).then(console.log) // Output: 1
|
|
8038
|
+
*
|
|
8039
|
+
* // Execute a failing effect and handle the rejection
|
|
8040
|
+
* Effect.runPromise(Effect.fail("my error")).catch((error) => {
|
|
8041
|
+
* console.error("Effect failed with error:", error)
|
|
8042
|
+
* })
|
|
7855
8043
|
*
|
|
7856
8044
|
* @since 2.0.0
|
|
7857
8045
|
* @category execution
|
|
@@ -7860,8 +8048,35 @@ export declare const runPromise: <A, E>(effect: Effect<A, E, never>, options?: {
|
|
|
7860
8048
|
readonly signal?: AbortSignal;
|
|
7861
8049
|
} | undefined) => Promise<A>;
|
|
7862
8050
|
/**
|
|
7863
|
-
*
|
|
7864
|
-
*
|
|
8051
|
+
* Executes an effect and returns a `Promise` that resolves with an `Exit` describing the result.
|
|
8052
|
+
*
|
|
8053
|
+
* Use `runPromiseExit` when you need detailed information about the outcome of the effect, including success or failure,
|
|
8054
|
+
* and you want to work with Promises.
|
|
8055
|
+
*
|
|
8056
|
+
* @example
|
|
8057
|
+
* import { Effect } from "effect"
|
|
8058
|
+
*
|
|
8059
|
+
* // Execute a successful effect and get the Exit result as a Promise
|
|
8060
|
+
* Effect.runPromiseExit(Effect.succeed(1)).then(console.log)
|
|
8061
|
+
* // Output:
|
|
8062
|
+
* // {
|
|
8063
|
+
* // _id: "Exit",
|
|
8064
|
+
* // _tag: "Success",
|
|
8065
|
+
* // value: 1
|
|
8066
|
+
* // }
|
|
8067
|
+
*
|
|
8068
|
+
* // Execute a failing effect and get the Exit result as a Promise
|
|
8069
|
+
* Effect.runPromiseExit(Effect.fail("my error")).then(console.log)
|
|
8070
|
+
* // Output:
|
|
8071
|
+
* // {
|
|
8072
|
+
* // _id: "Exit",
|
|
8073
|
+
* // _tag: "Failure",
|
|
8074
|
+
* // cause: {
|
|
8075
|
+
* // _id: "Cause",
|
|
8076
|
+
* // _tag: "Fail",
|
|
8077
|
+
* // failure: "my error"
|
|
8078
|
+
* // }
|
|
8079
|
+
* // }
|
|
7865
8080
|
*
|
|
7866
8081
|
* @since 2.0.0
|
|
7867
8082
|
* @category execution
|
|
@@ -7870,11 +8085,64 @@ export declare const runPromiseExit: <A, E>(effect: Effect<A, E, never>, options
|
|
|
7870
8085
|
readonly signal?: AbortSignal;
|
|
7871
8086
|
} | undefined) => Promise<Exit.Exit<A, E>>;
|
|
7872
8087
|
/**
|
|
8088
|
+
* Executes an effect synchronously and returns its result.
|
|
8089
|
+
*
|
|
8090
|
+
* Use `runSync` when you are certain that the effect is purely synchronous and will not perform any asynchronous operations.
|
|
8091
|
+
* If the effect fails or contains asynchronous tasks, it will throw an error.
|
|
8092
|
+
*
|
|
8093
|
+
* @example
|
|
8094
|
+
* import { Effect } from "effect"
|
|
8095
|
+
*
|
|
8096
|
+
* // Define a synchronous effect
|
|
8097
|
+
* const program = Effect.sync(() => {
|
|
8098
|
+
* console.log("Hello, World!")
|
|
8099
|
+
* return 1
|
|
8100
|
+
* })
|
|
8101
|
+
*
|
|
8102
|
+
* // Execute the effect synchronously
|
|
8103
|
+
* const result = Effect.runSync(program)
|
|
8104
|
+
* // Output: Hello, World!
|
|
8105
|
+
*
|
|
8106
|
+
* console.log(result)
|
|
8107
|
+
* // Output: 1
|
|
8108
|
+
*
|
|
7873
8109
|
* @since 2.0.0
|
|
7874
8110
|
* @category execution
|
|
7875
8111
|
*/
|
|
7876
8112
|
export declare const runSync: <A, E>(effect: Effect<A, E>) => A;
|
|
7877
8113
|
/**
|
|
8114
|
+
* Executes an effect synchronously and returns an `Exit` describing the result.
|
|
8115
|
+
*
|
|
8116
|
+
* Use `runSyncExit` when you need detailed information about the outcome of the effect,
|
|
8117
|
+
* including whether it succeeded or failed, without throwing exceptions.
|
|
8118
|
+
*
|
|
8119
|
+
* @example
|
|
8120
|
+
* import { Effect } from "effect"
|
|
8121
|
+
*
|
|
8122
|
+
* // Execute a successful effect and get the Exit result
|
|
8123
|
+
* const result1 = Effect.runSyncExit(Effect.succeed(1))
|
|
8124
|
+
* console.log(result1)
|
|
8125
|
+
* // Output:
|
|
8126
|
+
* // {
|
|
8127
|
+
* // _id: "Exit",
|
|
8128
|
+
* // _tag: "Success",
|
|
8129
|
+
* // value: 1
|
|
8130
|
+
* // }
|
|
8131
|
+
*
|
|
8132
|
+
* // Execute a failing effect and get the Exit result
|
|
8133
|
+
* const result2 = Effect.runSyncExit(Effect.fail("my error"))
|
|
8134
|
+
* console.log(result2)
|
|
8135
|
+
* // Output:
|
|
8136
|
+
* // {
|
|
8137
|
+
* // _id: "Exit",
|
|
8138
|
+
* // _tag: "Failure",
|
|
8139
|
+
* // cause: {
|
|
8140
|
+
* // _id: "Cause",
|
|
8141
|
+
* // _tag: "Fail",
|
|
8142
|
+
* // failure: "my error"
|
|
8143
|
+
* // }
|
|
8144
|
+
* // }
|
|
8145
|
+
*
|
|
7878
8146
|
* @since 2.0.0
|
|
7879
8147
|
* @category execution
|
|
7880
8148
|
*/
|