effect 3.12.7 → 3.12.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/cjs/BigDecimal.js +1 -1
- package/dist/cjs/BigDecimal.js.map +1 -1
- package/dist/cjs/Cause.js +630 -167
- package/dist/cjs/Cause.js.map +1 -1
- package/dist/cjs/Chunk.js +4 -8
- package/dist/cjs/Chunk.js.map +1 -1
- package/dist/cjs/ConfigProvider.js +1 -0
- package/dist/cjs/ConfigProvider.js.map +1 -1
- package/dist/cjs/Cron.js +26 -10
- package/dist/cjs/Cron.js.map +1 -1
- package/dist/cjs/Duration.js +7 -4
- package/dist/cjs/Duration.js.map +1 -1
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Either.js +5 -24
- package/dist/cjs/Either.js.map +1 -1
- package/dist/cjs/Layer.js.map +1 -1
- package/dist/cjs/Option.js +1042 -363
- package/dist/cjs/Option.js.map +1 -1
- package/dist/cjs/ParseResult.js +41 -18
- package/dist/cjs/ParseResult.js.map +1 -1
- package/dist/cjs/Schedule.js +8 -1
- package/dist/cjs/Schedule.js.map +1 -1
- package/dist/cjs/Schema.js +51 -10
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/internal/cause.js +23 -108
- package/dist/cjs/internal/cause.js.map +1 -1
- package/dist/cjs/internal/core.js +4 -5
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/schedule.js.map +1 -1
- package/dist/cjs/internal/secret.js +6 -5
- package/dist/cjs/internal/secret.js.map +1 -1
- package/dist/cjs/internal/stream.js +21 -23
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/BigDecimal.d.ts.map +1 -1
- package/dist/dts/Cause.d.ts +1157 -304
- package/dist/dts/Cause.d.ts.map +1 -1
- package/dist/dts/Chunk.d.ts +3 -6
- package/dist/dts/Chunk.d.ts.map +1 -1
- package/dist/dts/ConfigProvider.d.ts.map +1 -1
- package/dist/dts/Cron.d.ts +25 -9
- package/dist/dts/Cron.d.ts.map +1 -1
- package/dist/dts/Duration.d.ts +1 -1
- package/dist/dts/Duration.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +3 -2
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Either.d.ts.map +1 -1
- package/dist/dts/Layer.d.ts +1 -1
- package/dist/dts/Layer.d.ts.map +1 -1
- package/dist/dts/Option.d.ts +2288 -784
- package/dist/dts/Option.d.ts.map +1 -1
- package/dist/dts/ParseResult.d.ts +4 -4
- package/dist/dts/ParseResult.d.ts.map +1 -1
- package/dist/dts/Schedule.d.ts +7 -0
- package/dist/dts/Schedule.d.ts.map +1 -1
- package/dist/dts/Schema.d.ts +15 -4
- package/dist/dts/Schema.d.ts.map +1 -1
- package/dist/dts/internal/core.d.ts.map +1 -1
- package/dist/dts/internal/stream.d.ts +1 -1
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/BigDecimal.js +1 -1
- package/dist/esm/BigDecimal.js.map +1 -1
- package/dist/esm/Cause.js +630 -167
- package/dist/esm/Cause.js.map +1 -1
- package/dist/esm/Chunk.js +4 -8
- package/dist/esm/Chunk.js.map +1 -1
- package/dist/esm/ConfigProvider.js +1 -0
- package/dist/esm/ConfigProvider.js.map +1 -1
- package/dist/esm/Cron.js +27 -11
- package/dist/esm/Cron.js.map +1 -1
- package/dist/esm/Duration.js +7 -4
- package/dist/esm/Duration.js.map +1 -1
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Either.js +5 -24
- package/dist/esm/Either.js.map +1 -1
- package/dist/esm/Layer.js.map +1 -1
- package/dist/esm/Option.js +1041 -363
- package/dist/esm/Option.js.map +1 -1
- package/dist/esm/ParseResult.js +41 -18
- package/dist/esm/ParseResult.js.map +1 -1
- package/dist/esm/Schedule.js +7 -0
- package/dist/esm/Schedule.js.map +1 -1
- package/dist/esm/Schema.js +51 -10
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/internal/cause.js +22 -108
- package/dist/esm/internal/cause.js.map +1 -1
- package/dist/esm/internal/core.js +4 -5
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/schedule.js.map +1 -1
- package/dist/esm/internal/secret.js +5 -4
- package/dist/esm/internal/secret.js.map +1 -1
- package/dist/esm/internal/stream.js +21 -23
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/BigDecimal.ts +1 -1
- package/src/Cause.ts +1158 -304
- package/src/Chunk.ts +8 -11
- package/src/ConfigProvider.ts +1 -0
- package/src/Cron.ts +28 -11
- package/src/Duration.ts +10 -5
- package/src/Effect.ts +5 -2
- package/src/Either.ts +11 -28
- package/src/Layer.ts +1 -1
- package/src/Option.ts +2314 -820
- package/src/ParseResult.ts +53 -29
- package/src/Schedule.ts +8 -0
- package/src/Schema.ts +68 -12
- package/src/internal/cause.ts +38 -137
- package/src/internal/core.ts +4 -5
- package/src/internal/layer.ts +1 -1
- package/src/internal/schedule.ts +7 -6
- package/src/internal/secret.ts +6 -4
- package/src/internal/stream.ts +24 -37
- package/src/internal/version.ts +1 -1
package/src/ParseResult.ts
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* @since 3.10.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import * as
|
|
6
|
-
import
|
|
5
|
+
import * as Arr from "./Array.js"
|
|
6
|
+
import * as Cause from "./Cause.js"
|
|
7
7
|
import { TaggedError } from "./Data.js"
|
|
8
8
|
import * as Effect from "./Effect.js"
|
|
9
9
|
import * as Either from "./Either.js"
|
|
10
|
+
import * as Exit from "./Exit.js"
|
|
10
11
|
import type { LazyArg } from "./Function.js"
|
|
11
12
|
import { dual } from "./Function.js"
|
|
12
13
|
import { globalValue } from "./GlobalValue.js"
|
|
@@ -14,6 +15,7 @@ import * as Inspectable from "./Inspectable.js"
|
|
|
14
15
|
import * as util_ from "./internal/schema/util.js"
|
|
15
16
|
import * as Option from "./Option.js"
|
|
16
17
|
import * as Predicate from "./Predicate.js"
|
|
18
|
+
import * as Scheduler from "./Scheduler.js"
|
|
17
19
|
import type * as Schema from "./Schema.js"
|
|
18
20
|
import * as AST from "./SchemaAST.js"
|
|
19
21
|
import type { Concurrency } from "./Types.js"
|
|
@@ -40,7 +42,7 @@ export type ParseIssue =
|
|
|
40
42
|
* @category model
|
|
41
43
|
* @since 3.10.0
|
|
42
44
|
*/
|
|
43
|
-
export type SingleOrNonEmpty<A> = A |
|
|
45
|
+
export type SingleOrNonEmpty<A> = A | Arr.NonEmptyReadonlyArray<A>
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
48
|
* @category model
|
|
@@ -959,7 +961,7 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
959
961
|
const concurrency = getConcurrency(ast)
|
|
960
962
|
const batching = getBatching(ast)
|
|
961
963
|
return (input: unknown, options) => {
|
|
962
|
-
if (!
|
|
964
|
+
if (!Arr.isArray(input)) {
|
|
963
965
|
return Either.left(new Type(ast, input))
|
|
964
966
|
}
|
|
965
967
|
const allErrors = options?.errors === "all"
|
|
@@ -1057,7 +1059,7 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1057
1059
|
// ---------------------------------------------
|
|
1058
1060
|
// handle rest element
|
|
1059
1061
|
// ---------------------------------------------
|
|
1060
|
-
if (
|
|
1062
|
+
if (Arr.isNonEmptyReadonlyArray(rest)) {
|
|
1061
1063
|
const [head, ...tail] = rest
|
|
1062
1064
|
for (; i < len - tail.length; i++) {
|
|
1063
1065
|
const te = head(input[i], options)
|
|
@@ -1153,15 +1155,15 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1153
1155
|
// compute result
|
|
1154
1156
|
// ---------------------------------------------
|
|
1155
1157
|
const computeResult = ({ es, output }: State) =>
|
|
1156
|
-
|
|
1158
|
+
Arr.isNonEmptyArray(es) ?
|
|
1157
1159
|
Either.left(new Composite(ast, input, sortByIndex(es), sortByIndex(output))) :
|
|
1158
1160
|
Either.right(sortByIndex(output))
|
|
1159
1161
|
if (queue && queue.length > 0) {
|
|
1160
1162
|
const cqueue = queue
|
|
1161
1163
|
return Effect.suspend(() => {
|
|
1162
1164
|
const state: State = {
|
|
1163
|
-
es:
|
|
1164
|
-
output:
|
|
1165
|
+
es: Arr.copy(es),
|
|
1166
|
+
output: Arr.copy(output)
|
|
1165
1167
|
}
|
|
1166
1168
|
return Effect.flatMap(
|
|
1167
1169
|
Effect.forEach(cqueue, (f) => f(state), { concurrency, batching, discard: true }),
|
|
@@ -1379,7 +1381,7 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1379
1381
|
// compute result
|
|
1380
1382
|
// ---------------------------------------------
|
|
1381
1383
|
const computeResult = ({ es, output }: State) => {
|
|
1382
|
-
if (
|
|
1384
|
+
if (Arr.isNonEmptyArray(es)) {
|
|
1383
1385
|
return Either.left(new Composite(ast, input, sortByIndex(es), output))
|
|
1384
1386
|
}
|
|
1385
1387
|
if (options?.propertyOrder === "original") {
|
|
@@ -1404,7 +1406,7 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1404
1406
|
const cqueue = queue
|
|
1405
1407
|
return Effect.suspend(() => {
|
|
1406
1408
|
const state: State = {
|
|
1407
|
-
es:
|
|
1409
|
+
es: Arr.copy(es),
|
|
1408
1410
|
output: Object.assign({}, output)
|
|
1409
1411
|
}
|
|
1410
1412
|
return Effect.flatMap(
|
|
@@ -1528,7 +1530,7 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1528
1530
|
// compute result
|
|
1529
1531
|
// ---------------------------------------------
|
|
1530
1532
|
const computeResult = (es: State["es"]) =>
|
|
1531
|
-
|
|
1533
|
+
Arr.isNonEmptyArray(es) ?
|
|
1532
1534
|
es.length === 1 && es[0][1]._tag === "Type" ?
|
|
1533
1535
|
Either.left(es[0][1]) :
|
|
1534
1536
|
Either.left(new Composite(ast, input, sortByIndex(es))) :
|
|
@@ -1538,7 +1540,7 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1538
1540
|
if (queue && queue.length > 0) {
|
|
1539
1541
|
const cqueue = queue
|
|
1540
1542
|
return Effect.suspend(() => {
|
|
1541
|
-
const state: State = { es:
|
|
1543
|
+
const state: State = { es: Arr.copy(es) }
|
|
1542
1544
|
return Effect.flatMap(
|
|
1543
1545
|
Effect.forEach(cqueue, (f) => f(state), { concurrency, batching, discard: true }),
|
|
1544
1546
|
() => {
|
|
@@ -1687,31 +1689,53 @@ const handleForbidden = <A, R>(
|
|
|
1687
1689
|
actual: unknown,
|
|
1688
1690
|
options: InternalOptions | undefined
|
|
1689
1691
|
): Effect.Effect<A, ParseIssue, R> => {
|
|
1692
|
+
// If effects are allowed, return the original effect
|
|
1693
|
+
if (options?.isEffectAllowed === true) {
|
|
1694
|
+
return effect
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
// Convert the effect to an Either, if possible
|
|
1690
1698
|
const eu = eitherOrUndefined(effect)
|
|
1699
|
+
// If the effect is already an Either, return it directly
|
|
1691
1700
|
if (eu) {
|
|
1692
1701
|
return eu
|
|
1693
1702
|
}
|
|
1694
|
-
|
|
1695
|
-
|
|
1703
|
+
|
|
1704
|
+
// Otherwise, attempt to execute the effect synchronously
|
|
1705
|
+
const scheduler = new Scheduler.SyncScheduler()
|
|
1706
|
+
const fiber = Effect.runFork(effect as Effect.Effect<A, ParseIssue>, { scheduler })
|
|
1707
|
+
scheduler.flush()
|
|
1708
|
+
const exit = fiber.unsafePoll()
|
|
1709
|
+
|
|
1710
|
+
if (exit) {
|
|
1711
|
+
if (Exit.isSuccess(exit)) {
|
|
1712
|
+
// If the effect successfully resolves, wrap the value in a Right
|
|
1713
|
+
return Either.right(exit.value)
|
|
1714
|
+
}
|
|
1715
|
+
const cause = exit.cause
|
|
1716
|
+
if (Cause.isFailType(cause)) {
|
|
1717
|
+
// The effect executed synchronously but failed due to a ParseIssue
|
|
1718
|
+
return Either.left(cause.error)
|
|
1719
|
+
}
|
|
1720
|
+
// The effect executed synchronously but failed due to a defect (e.g., a missing dependency)
|
|
1721
|
+
return Either.left(new Forbidden(ast, actual, Cause.pretty(cause)))
|
|
1696
1722
|
}
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
"cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work"
|
|
1705
|
-
)
|
|
1723
|
+
|
|
1724
|
+
// The effect could not be resolved synchronously, meaning it performs async work
|
|
1725
|
+
return Either.left(
|
|
1726
|
+
new Forbidden(
|
|
1727
|
+
ast,
|
|
1728
|
+
actual,
|
|
1729
|
+
"cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work"
|
|
1706
1730
|
)
|
|
1707
|
-
|
|
1731
|
+
)
|
|
1708
1732
|
}
|
|
1709
1733
|
|
|
1710
1734
|
const compare = ([a]: [number, ...Array<unknown>], [b]: [number, ...Array<unknown>]) => a > b ? 1 : a < b ? -1 : 0
|
|
1711
1735
|
|
|
1712
1736
|
function sortByIndex<T>(
|
|
1713
|
-
es:
|
|
1714
|
-
):
|
|
1737
|
+
es: Arr.NonEmptyArray<[number, T]>
|
|
1738
|
+
): Arr.NonEmptyArray<T>
|
|
1715
1739
|
function sortByIndex<T>(es: Array<[number, T]>): Array<T>
|
|
1716
1740
|
function sortByIndex(es: Array<[number, any]>) {
|
|
1717
1741
|
return es.sort(compare).map((t) => t[1])
|
|
@@ -1850,7 +1874,7 @@ interface CurrentMessage {
|
|
|
1850
1874
|
|
|
1851
1875
|
const getCurrentMessage = (
|
|
1852
1876
|
issue: ParseIssue
|
|
1853
|
-
): Effect.Effect<CurrentMessage,
|
|
1877
|
+
): Effect.Effect<CurrentMessage, Cause.NoSuchElementException> =>
|
|
1854
1878
|
getAnnotated(issue).pipe(
|
|
1855
1879
|
Option.flatMap(AST.getMessageAnnotation),
|
|
1856
1880
|
Effect.flatMap((annotation) => {
|
|
@@ -1882,7 +1906,7 @@ const isTransformation = createParseIssueGuard("Transformation")
|
|
|
1882
1906
|
|
|
1883
1907
|
const getMessage: (
|
|
1884
1908
|
issue: ParseIssue
|
|
1885
|
-
) => Effect.Effect<string,
|
|
1909
|
+
) => Effect.Effect<string, Cause.NoSuchElementException> = (issue: ParseIssue) =>
|
|
1886
1910
|
getCurrentMessage(issue).pipe(
|
|
1887
1911
|
Effect.flatMap((currentMessage) => {
|
|
1888
1912
|
const useInnerMessage = !currentMessage.override && (
|
|
@@ -2058,7 +2082,7 @@ const formatArray = (
|
|
|
2058
2082
|
case "Composite":
|
|
2059
2083
|
return getArray(e, path, () =>
|
|
2060
2084
|
util_.isNonEmpty(e.issues)
|
|
2061
|
-
? Effect.map(Effect.forEach(e.issues, (issue) => formatArray(issue, path)),
|
|
2085
|
+
? Effect.map(Effect.forEach(e.issues, (issue) => formatArray(issue, path)), Arr.flatten)
|
|
2062
2086
|
: formatArray(e.issues, path))
|
|
2063
2087
|
case "Refinement":
|
|
2064
2088
|
case "Transformation":
|
package/src/Schedule.ts
CHANGED
|
@@ -140,6 +140,14 @@ export const makeWithState: <S, In, Out, R = never>(
|
|
|
140
140
|
) => Effect.Effect<readonly [S, Out, ScheduleDecision.ScheduleDecision], never, R>
|
|
141
141
|
) => Schedule<Out, In, R> = internal.makeWithState
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Returns `true` if the specified value is a `Schedule`, `false` otherwise.
|
|
145
|
+
*
|
|
146
|
+
* @since 2.0.0
|
|
147
|
+
* @category guards
|
|
148
|
+
*/
|
|
149
|
+
export const isSchedule: (u: unknown) => u is Schedule<unknown, never, unknown> = internal.isSchedule
|
|
150
|
+
|
|
143
151
|
/**
|
|
144
152
|
* Returns a new schedule with the given delay added to every interval defined
|
|
145
153
|
* by this schedule.
|
package/src/Schema.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @since 3.10.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import * as internalCause_ from "effect/internal/cause"
|
|
5
6
|
import type { ArbitraryAnnotation, ArbitraryGenerationContext, LazyArbitrary } from "./Arbitrary.js"
|
|
6
7
|
import * as array_ from "./Array.js"
|
|
7
8
|
import * as bigDecimal_ from "./BigDecimal.js"
|
|
@@ -6202,6 +6203,37 @@ export class DurationFromMillis extends transform(
|
|
|
6202
6203
|
}
|
|
6203
6204
|
).annotations({ identifier: "DurationFromMillis" }) {}
|
|
6204
6205
|
|
|
6206
|
+
const DurationValueMillis = TaggedStruct("Millis", { millis: NonNegativeInt })
|
|
6207
|
+
const DurationValueNanos = TaggedStruct("Nanos", { nanos: BigInt$ })
|
|
6208
|
+
const DurationValueInfinity = TaggedStruct("Infinity", {})
|
|
6209
|
+
const durationValueInfinity = DurationValueInfinity.make({})
|
|
6210
|
+
|
|
6211
|
+
/**
|
|
6212
|
+
* @category Duration utils
|
|
6213
|
+
* @since 3.12.8
|
|
6214
|
+
*/
|
|
6215
|
+
export type DurationEncoded =
|
|
6216
|
+
| {
|
|
6217
|
+
readonly _tag: "Millis"
|
|
6218
|
+
readonly millis: number
|
|
6219
|
+
}
|
|
6220
|
+
| {
|
|
6221
|
+
readonly _tag: "Nanos"
|
|
6222
|
+
readonly nanos: string
|
|
6223
|
+
}
|
|
6224
|
+
| {
|
|
6225
|
+
readonly _tag: "Infinity"
|
|
6226
|
+
}
|
|
6227
|
+
|
|
6228
|
+
const DurationValue: Schema<duration_.DurationValue, DurationEncoded> = Union(
|
|
6229
|
+
DurationValueMillis,
|
|
6230
|
+
DurationValueNanos,
|
|
6231
|
+
DurationValueInfinity
|
|
6232
|
+
).annotations({
|
|
6233
|
+
identifier: "DurationValue",
|
|
6234
|
+
description: "an JSON-compatible tagged union to be decoded into a Duration"
|
|
6235
|
+
})
|
|
6236
|
+
|
|
6205
6237
|
const FiniteHRTime = Tuple(
|
|
6206
6238
|
element(NonNegativeInt).annotations({ title: "seconds" }),
|
|
6207
6239
|
element(NonNegativeInt).annotations({ title: "nanos" })
|
|
@@ -6214,22 +6246,45 @@ const HRTime: Schema<readonly [seconds: number, nanos: number]> = Union(FiniteHR
|
|
|
6214
6246
|
description: "a tuple of seconds and nanos to be decoded into a Duration"
|
|
6215
6247
|
})
|
|
6216
6248
|
|
|
6249
|
+
const isDurationValue = (u: duration_.DurationValue | typeof HRTime.Type): u is duration_.DurationValue =>
|
|
6250
|
+
typeof u === "object"
|
|
6251
|
+
|
|
6252
|
+
// TODO(4.0): remove HRTime union member
|
|
6217
6253
|
/**
|
|
6218
|
-
* A schema that
|
|
6219
|
-
*
|
|
6220
|
-
* Infinite durations are encoded as `[-1, 0]`.
|
|
6254
|
+
* A schema that converts a JSON-compatible tagged union into a `Duration`.
|
|
6221
6255
|
*
|
|
6222
6256
|
* @category Duration transformations
|
|
6223
6257
|
* @since 3.10.0
|
|
6224
6258
|
*/
|
|
6225
6259
|
export class Duration extends transform(
|
|
6226
|
-
HRTime,
|
|
6260
|
+
Union(DurationValue, HRTime),
|
|
6227
6261
|
DurationFromSelf,
|
|
6228
6262
|
{
|
|
6229
6263
|
strict: true,
|
|
6230
|
-
decode: (
|
|
6231
|
-
|
|
6232
|
-
|
|
6264
|
+
decode: (input) => {
|
|
6265
|
+
if (isDurationValue(input)) {
|
|
6266
|
+
switch (input._tag) {
|
|
6267
|
+
case "Millis":
|
|
6268
|
+
return duration_.millis(input.millis)
|
|
6269
|
+
case "Nanos":
|
|
6270
|
+
return duration_.nanos(input.nanos)
|
|
6271
|
+
case "Infinity":
|
|
6272
|
+
return duration_.infinity
|
|
6273
|
+
}
|
|
6274
|
+
}
|
|
6275
|
+
const [seconds, nanos] = input
|
|
6276
|
+
return seconds === -1 ? duration_.infinity : duration_.nanos(BigInt(seconds) * BigInt(1e9) + BigInt(nanos))
|
|
6277
|
+
},
|
|
6278
|
+
encode: (duration) => {
|
|
6279
|
+
switch (duration.value._tag) {
|
|
6280
|
+
case "Millis":
|
|
6281
|
+
return DurationValueMillis.make({ millis: duration.value.millis })
|
|
6282
|
+
case "Nanos":
|
|
6283
|
+
return DurationValueNanos.make({ nanos: duration.value.nanos })
|
|
6284
|
+
case "Infinity":
|
|
6285
|
+
return durationValueInfinity
|
|
6286
|
+
}
|
|
6287
|
+
}
|
|
6233
6288
|
}
|
|
6234
6289
|
).annotations({ identifier: "Duration" }) {}
|
|
6235
6290
|
|
|
@@ -6678,9 +6733,9 @@ export const itemsCount = <A extends ReadonlyArray<any>>(
|
|
|
6678
6733
|
) =>
|
|
6679
6734
|
<I, R>(self: Schema<A, I, R>): filter<Schema<A, I, R>> => {
|
|
6680
6735
|
const itemsCount = Math.floor(n)
|
|
6681
|
-
if (itemsCount <
|
|
6736
|
+
if (itemsCount < 0) {
|
|
6682
6737
|
throw new Error(
|
|
6683
|
-
errors_.getInvalidArgumentErrorMessage(`Expected an integer greater than or equal to
|
|
6738
|
+
errors_.getInvalidArgumentErrorMessage(`Expected an integer greater than or equal to 0, actual ${n}`)
|
|
6684
6739
|
)
|
|
6685
6740
|
}
|
|
6686
6741
|
return self.pipe(
|
|
@@ -9012,8 +9067,9 @@ type MakeOptions = boolean | {
|
|
|
9012
9067
|
readonly disableValidation?: boolean
|
|
9013
9068
|
}
|
|
9014
9069
|
|
|
9015
|
-
|
|
9016
|
-
Predicate.isBoolean(options) ? options : options?.disableValidation ?? false
|
|
9070
|
+
function getDisableValidationMakeOption(options: MakeOptions | undefined): boolean {
|
|
9071
|
+
return Predicate.isBoolean(options) ? options : options?.disableValidation ?? false
|
|
9072
|
+
}
|
|
9017
9073
|
|
|
9018
9074
|
const astCache = globalValue("effect/Schema/astCache", () => new WeakMap<any, AST.AST>())
|
|
9019
9075
|
|
|
@@ -9643,7 +9699,7 @@ export const Defect: Defect = transform(
|
|
|
9643
9699
|
// no stack because of security reasons
|
|
9644
9700
|
}
|
|
9645
9701
|
}
|
|
9646
|
-
return
|
|
9702
|
+
return internalCause_.prettyErrorMessage(defect)
|
|
9647
9703
|
}
|
|
9648
9704
|
}
|
|
9649
9705
|
).annotations({ identifier: "Defect" })
|
package/src/internal/cause.ts
CHANGED
|
@@ -259,34 +259,12 @@ export const dieOption = <E>(self: Cause.Cause<E>): Option.Option<unknown> =>
|
|
|
259
259
|
/** @internal */
|
|
260
260
|
export const flipCauseOption = <E>(self: Cause.Cause<Option.Option<E>>): Option.Option<Cause.Cause<E>> =>
|
|
261
261
|
match(self, {
|
|
262
|
-
onEmpty: Option.some(empty),
|
|
263
|
-
onFail:
|
|
262
|
+
onEmpty: Option.some<Cause.Cause<E>>(empty),
|
|
263
|
+
onFail: Option.map(fail),
|
|
264
264
|
onDie: (defect) => Option.some(die(defect)),
|
|
265
265
|
onInterrupt: (fiberId) => Option.some(interrupt(fiberId)),
|
|
266
|
-
onSequential: (
|
|
267
|
-
|
|
268
|
-
return Option.some(sequential(left.value, right.value))
|
|
269
|
-
}
|
|
270
|
-
if (Option.isNone(left) && Option.isSome(right)) {
|
|
271
|
-
return Option.some(right.value)
|
|
272
|
-
}
|
|
273
|
-
if (Option.isSome(left) && Option.isNone(right)) {
|
|
274
|
-
return Option.some(left.value)
|
|
275
|
-
}
|
|
276
|
-
return Option.none()
|
|
277
|
-
},
|
|
278
|
-
onParallel: (left, right) => {
|
|
279
|
-
if (Option.isSome(left) && Option.isSome(right)) {
|
|
280
|
-
return Option.some(parallel(left.value, right.value))
|
|
281
|
-
}
|
|
282
|
-
if (Option.isNone(left) && Option.isSome(right)) {
|
|
283
|
-
return Option.some(right.value)
|
|
284
|
-
}
|
|
285
|
-
if (Option.isSome(left) && Option.isNone(right)) {
|
|
286
|
-
return Option.some(left.value)
|
|
287
|
-
}
|
|
288
|
-
return Option.none()
|
|
289
|
-
}
|
|
266
|
+
onSequential: Option.mergeWith(sequential),
|
|
267
|
+
onParallel: Option.mergeWith(parallel)
|
|
290
268
|
})
|
|
291
269
|
|
|
292
270
|
/** @internal */
|
|
@@ -298,68 +276,24 @@ export const interruptOption = <E>(self: Cause.Cause<E>): Option.Option<FiberId.
|
|
|
298
276
|
|
|
299
277
|
/** @internal */
|
|
300
278
|
export const keepDefects = <E>(self: Cause.Cause<E>): Option.Option<Cause.Cause<never>> =>
|
|
301
|
-
match
|
|
279
|
+
match(self, {
|
|
302
280
|
onEmpty: Option.none(),
|
|
303
281
|
onFail: () => Option.none(),
|
|
304
282
|
onDie: (defect) => Option.some(die(defect)),
|
|
305
283
|
onInterrupt: () => Option.none(),
|
|
306
|
-
onSequential: (
|
|
307
|
-
|
|
308
|
-
return Option.some(sequential(left.value, right.value))
|
|
309
|
-
}
|
|
310
|
-
if (Option.isSome(left) && Option.isNone(right)) {
|
|
311
|
-
return Option.some(left.value)
|
|
312
|
-
}
|
|
313
|
-
if (Option.isNone(left) && Option.isSome(right)) {
|
|
314
|
-
return Option.some(right.value)
|
|
315
|
-
}
|
|
316
|
-
return Option.none()
|
|
317
|
-
},
|
|
318
|
-
onParallel: (left, right) => {
|
|
319
|
-
if (Option.isSome(left) && Option.isSome(right)) {
|
|
320
|
-
return Option.some(parallel(left.value, right.value))
|
|
321
|
-
}
|
|
322
|
-
if (Option.isSome(left) && Option.isNone(right)) {
|
|
323
|
-
return Option.some(left.value)
|
|
324
|
-
}
|
|
325
|
-
if (Option.isNone(left) && Option.isSome(right)) {
|
|
326
|
-
return Option.some(right.value)
|
|
327
|
-
}
|
|
328
|
-
return Option.none()
|
|
329
|
-
}
|
|
284
|
+
onSequential: Option.mergeWith(sequential),
|
|
285
|
+
onParallel: Option.mergeWith(parallel)
|
|
330
286
|
})
|
|
331
287
|
|
|
332
288
|
/** @internal */
|
|
333
289
|
export const keepDefectsAndElectFailures = <E>(self: Cause.Cause<E>): Option.Option<Cause.Cause<never>> =>
|
|
334
|
-
match
|
|
290
|
+
match(self, {
|
|
335
291
|
onEmpty: Option.none(),
|
|
336
292
|
onFail: (failure) => Option.some(die(failure)),
|
|
337
293
|
onDie: (defect) => Option.some(die(defect)),
|
|
338
294
|
onInterrupt: () => Option.none(),
|
|
339
|
-
onSequential: (
|
|
340
|
-
|
|
341
|
-
return Option.some(sequential(left.value, right.value))
|
|
342
|
-
}
|
|
343
|
-
if (Option.isSome(left) && Option.isNone(right)) {
|
|
344
|
-
return Option.some(left.value)
|
|
345
|
-
}
|
|
346
|
-
if (Option.isNone(left) && Option.isSome(right)) {
|
|
347
|
-
return Option.some(right.value)
|
|
348
|
-
}
|
|
349
|
-
return Option.none()
|
|
350
|
-
},
|
|
351
|
-
onParallel: (left, right) => {
|
|
352
|
-
if (Option.isSome(left) && Option.isSome(right)) {
|
|
353
|
-
return Option.some(parallel(left.value, right.value))
|
|
354
|
-
}
|
|
355
|
-
if (Option.isSome(left) && Option.isNone(right)) {
|
|
356
|
-
return Option.some(left.value)
|
|
357
|
-
}
|
|
358
|
-
if (Option.isNone(left) && Option.isSome(right)) {
|
|
359
|
-
return Option.some(right.value)
|
|
360
|
-
}
|
|
361
|
-
return Option.none()
|
|
362
|
-
}
|
|
295
|
+
onSequential: Option.mergeWith(sequential),
|
|
296
|
+
onParallel: Option.mergeWith(parallel)
|
|
363
297
|
})
|
|
364
298
|
|
|
365
299
|
/** @internal */
|
|
@@ -370,25 +304,9 @@ export const linearize = <E>(self: Cause.Cause<E>): HashSet.HashSet<Cause.Cause<
|
|
|
370
304
|
onDie: (defect) => HashSet.make(die(defect)),
|
|
371
305
|
onInterrupt: (fiberId) => HashSet.make(interrupt(fiberId)),
|
|
372
306
|
onSequential: (leftSet, rightSet) =>
|
|
373
|
-
|
|
374
|
-
leftSet,
|
|
375
|
-
HashSet.flatMap((leftCause) =>
|
|
376
|
-
pipe(
|
|
377
|
-
rightSet,
|
|
378
|
-
HashSet.map((rightCause) => sequential(leftCause, rightCause))
|
|
379
|
-
)
|
|
380
|
-
)
|
|
381
|
-
),
|
|
307
|
+
HashSet.flatMap(leftSet, (leftCause) => HashSet.map(rightSet, (rightCause) => sequential(leftCause, rightCause))),
|
|
382
308
|
onParallel: (leftSet, rightSet) =>
|
|
383
|
-
|
|
384
|
-
leftSet,
|
|
385
|
-
HashSet.flatMap((leftCause) =>
|
|
386
|
-
pipe(
|
|
387
|
-
rightSet,
|
|
388
|
-
HashSet.map((rightCause) => parallel(leftCause, rightCause))
|
|
389
|
-
)
|
|
390
|
-
)
|
|
391
|
-
)
|
|
309
|
+
HashSet.flatMap(leftSet, (leftCause) => HashSet.map(rightSet, (rightCause) => parallel(leftCause, rightCause)))
|
|
392
310
|
})
|
|
393
311
|
|
|
394
312
|
/** @internal */
|
|
@@ -396,8 +314,8 @@ export const stripFailures = <E>(self: Cause.Cause<E>): Cause.Cause<never> =>
|
|
|
396
314
|
match(self, {
|
|
397
315
|
onEmpty: empty,
|
|
398
316
|
onFail: () => empty,
|
|
399
|
-
onDie:
|
|
400
|
-
onInterrupt:
|
|
317
|
+
onDie: die,
|
|
318
|
+
onInterrupt: interrupt,
|
|
401
319
|
onSequential: sequential,
|
|
402
320
|
onParallel: parallel
|
|
403
321
|
})
|
|
@@ -406,51 +324,32 @@ export const stripFailures = <E>(self: Cause.Cause<E>): Cause.Cause<never> =>
|
|
|
406
324
|
export const electFailures = <E>(self: Cause.Cause<E>): Cause.Cause<never> =>
|
|
407
325
|
match(self, {
|
|
408
326
|
onEmpty: empty,
|
|
409
|
-
onFail:
|
|
410
|
-
onDie:
|
|
411
|
-
onInterrupt:
|
|
412
|
-
onSequential:
|
|
413
|
-
onParallel:
|
|
327
|
+
onFail: die,
|
|
328
|
+
onDie: die,
|
|
329
|
+
onInterrupt: interrupt,
|
|
330
|
+
onSequential: sequential,
|
|
331
|
+
onParallel: parallel
|
|
414
332
|
})
|
|
415
333
|
|
|
416
334
|
/** @internal */
|
|
417
335
|
export const stripSomeDefects = dual<
|
|
418
336
|
(pf: (defect: unknown) => Option.Option<unknown>) => <E>(self: Cause.Cause<E>) => Option.Option<Cause.Cause<E>>,
|
|
419
337
|
<E>(self: Cause.Cause<E>, pf: (defect: unknown) => Option.Option<unknown>) => Option.Option<Cause.Cause<E>>
|
|
420
|
-
>(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
if (Option.isNone(left) && Option.isSome(right)) {
|
|
437
|
-
return Option.some(right.value)
|
|
438
|
-
}
|
|
439
|
-
return Option.none()
|
|
440
|
-
},
|
|
441
|
-
onParallel: (left, right) => {
|
|
442
|
-
if (Option.isSome(left) && Option.isSome(right)) {
|
|
443
|
-
return Option.some(parallel(left.value, right.value))
|
|
444
|
-
}
|
|
445
|
-
if (Option.isSome(left) && Option.isNone(right)) {
|
|
446
|
-
return Option.some(left.value)
|
|
447
|
-
}
|
|
448
|
-
if (Option.isNone(left) && Option.isSome(right)) {
|
|
449
|
-
return Option.some(right.value)
|
|
450
|
-
}
|
|
451
|
-
return Option.none()
|
|
452
|
-
}
|
|
453
|
-
}))
|
|
338
|
+
>(
|
|
339
|
+
2,
|
|
340
|
+
<E>(self: Cause.Cause<E>, pf: (defect: unknown) => Option.Option<unknown>): Option.Option<Cause.Cause<E>> =>
|
|
341
|
+
match(self, {
|
|
342
|
+
onEmpty: Option.some<Cause.Cause<E>>(empty),
|
|
343
|
+
onFail: (error) => Option.some(fail(error)),
|
|
344
|
+
onDie: (defect) => {
|
|
345
|
+
const option = pf(defect)
|
|
346
|
+
return Option.isSome(option) ? Option.none() : Option.some(die(defect))
|
|
347
|
+
},
|
|
348
|
+
onInterrupt: (fiberId) => Option.some(interrupt(fiberId)),
|
|
349
|
+
onSequential: Option.mergeWith(sequential),
|
|
350
|
+
onParallel: Option.mergeWith(parallel)
|
|
351
|
+
})
|
|
352
|
+
)
|
|
454
353
|
|
|
455
354
|
// -----------------------------------------------------------------------------
|
|
456
355
|
// Mapping
|
|
@@ -996,7 +895,8 @@ const renderErrorCause = (cause: PrettyError, prefix: string) => {
|
|
|
996
895
|
return stack
|
|
997
896
|
}
|
|
998
897
|
|
|
999
|
-
|
|
898
|
+
/** @internal */
|
|
899
|
+
export class PrettyError extends globalThis.Error implements Cause.PrettyError {
|
|
1000
900
|
span: undefined | Span = undefined
|
|
1001
901
|
constructor(originalError: unknown) {
|
|
1002
902
|
const originalErrorIsObject = typeof originalError === "object" && originalError !== null
|
|
@@ -1128,7 +1028,8 @@ const prettyErrorStack = (message: string, stack: string, span?: Span | undefine
|
|
|
1128
1028
|
return out.join("\n")
|
|
1129
1029
|
}
|
|
1130
1030
|
|
|
1131
|
-
|
|
1031
|
+
/** @internal */
|
|
1032
|
+
export const spanSymbol = Symbol.for("effect/SpanAnnotation")
|
|
1132
1033
|
|
|
1133
1034
|
/** @internal */
|
|
1134
1035
|
export const prettyErrors = <E>(cause: Cause.Cause<E>): Array<PrettyError> =>
|
package/src/internal/core.ts
CHANGED
|
@@ -653,7 +653,6 @@ export const checkInterruptible = <A, E, R>(
|
|
|
653
653
|
f: (isInterruptible: boolean) => Effect.Effect<A, E, R>
|
|
654
654
|
): Effect.Effect<A, E, R> => withFiberRuntime((_, status) => f(runtimeFlags_.interruption(status.runtimeFlags)))
|
|
655
655
|
|
|
656
|
-
const spanSymbol = Symbol.for("effect/SpanAnnotation")
|
|
657
656
|
const originalSymbol = Symbol.for("effect/OriginalAnnotation")
|
|
658
657
|
|
|
659
658
|
/* @internal */
|
|
@@ -670,10 +669,10 @@ export const capture = <E>(obj: E & object, span: Option.Option<Tracer.Span>): E
|
|
|
670
669
|
if (Option.isSome(span)) {
|
|
671
670
|
return new Proxy(obj, {
|
|
672
671
|
has(target, p) {
|
|
673
|
-
return p === spanSymbol || p === originalSymbol || p in target
|
|
672
|
+
return p === internalCause.spanSymbol || p === originalSymbol || p in target
|
|
674
673
|
},
|
|
675
674
|
get(target, p) {
|
|
676
|
-
if (p === spanSymbol) {
|
|
675
|
+
if (p === internalCause.spanSymbol) {
|
|
677
676
|
return span.value
|
|
678
677
|
}
|
|
679
678
|
if (p === originalSymbol) {
|
|
@@ -689,7 +688,7 @@ export const capture = <E>(obj: E & object, span: Option.Option<Tracer.Span>): E
|
|
|
689
688
|
|
|
690
689
|
/* @internal */
|
|
691
690
|
export const die = (defect: unknown): Effect.Effect<never> =>
|
|
692
|
-
isObject(defect) && !(spanSymbol in defect) ?
|
|
691
|
+
isObject(defect) && !(internalCause.spanSymbol in defect) ?
|
|
693
692
|
withFiberRuntime((fiber) => failCause(internalCause.die(capture(defect, currentSpanFromFiber(fiber)))))
|
|
694
693
|
: failCause(internalCause.die(defect))
|
|
695
694
|
|
|
@@ -716,7 +715,7 @@ export const exit = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<Exit.
|
|
|
716
715
|
|
|
717
716
|
/* @internal */
|
|
718
717
|
export const fail = <E>(error: E): Effect.Effect<never, E> =>
|
|
719
|
-
isObject(error) && !(spanSymbol in error) ?
|
|
718
|
+
isObject(error) && !(internalCause.spanSymbol in error) ?
|
|
720
719
|
withFiberRuntime((fiber) => failCause(internalCause.fail(capture(error, currentSpanFromFiber(fiber)))))
|
|
721
720
|
: failCause(internalCause.fail(error))
|
|
722
721
|
|
package/src/internal/layer.ts
CHANGED
|
@@ -874,7 +874,7 @@ export const scopedContext = <A, E, R>(
|
|
|
874
874
|
}
|
|
875
875
|
|
|
876
876
|
/** @internal */
|
|
877
|
-
export const scope: Layer.Layer<Scope.Scope
|
|
877
|
+
export const scope: Layer.Layer<Scope.Scope> = scopedContext(
|
|
878
878
|
core.map(
|
|
879
879
|
fiberRuntime.acquireRelease(
|
|
880
880
|
fiberRuntime.scopeMake(),
|
package/src/internal/schedule.ts
CHANGED
|
@@ -34,7 +34,8 @@ export const ScheduleTypeId: Schedule.ScheduleTypeId = Symbol.for(
|
|
|
34
34
|
) as Schedule.ScheduleTypeId
|
|
35
35
|
|
|
36
36
|
/** @internal */
|
|
37
|
-
export const isSchedule = (u: unknown): u is Schedule.Schedule<
|
|
37
|
+
export const isSchedule = (u: unknown): u is Schedule.Schedule<unknown, never, unknown> =>
|
|
38
|
+
hasProperty(u, ScheduleTypeId)
|
|
38
39
|
|
|
39
40
|
/** @internal */
|
|
40
41
|
const ScheduleDriverSymbolKey = "effect/ScheduleDriver"
|
|
@@ -1989,16 +1990,16 @@ const retryOrElse_EffectLoop = <A, E, R, R1, A1, A2, E2, R2>(
|
|
|
1989
1990
|
|
|
1990
1991
|
/** @internal */
|
|
1991
1992
|
export const schedule_Effect = dual<
|
|
1992
|
-
<R2, Out>(
|
|
1993
|
-
schedule: Schedule.Schedule<Out,
|
|
1994
|
-
) => <
|
|
1993
|
+
<A, R2, Out>(
|
|
1994
|
+
schedule: Schedule.Schedule<Out, NoInfer<A> | undefined, R2>
|
|
1995
|
+
) => <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Out, E, R | R2>,
|
|
1995
1996
|
<A, E, R, R2, Out>(
|
|
1996
1997
|
self: Effect.Effect<A, E, R>,
|
|
1997
|
-
schedule: Schedule.Schedule<Out,
|
|
1998
|
+
schedule: Schedule.Schedule<Out, A | undefined, R2>
|
|
1998
1999
|
) => Effect.Effect<Out, E, R | R2>
|
|
1999
2000
|
>(2, <A, E, R, R2, Out>(
|
|
2000
2001
|
self: Effect.Effect<A, E, R>,
|
|
2001
|
-
schedule: Schedule.Schedule<Out,
|
|
2002
|
+
schedule: Schedule.Schedule<Out, A | undefined, R2>
|
|
2002
2003
|
) => scheduleFrom_Effect(self, void 0, schedule))
|
|
2003
2004
|
|
|
2004
2005
|
/** @internal */
|