effect 2.0.5 → 2.1.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/dist/cjs/Effect.js +6 -78
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Runtime.js.map +1 -1
- package/dist/cjs/internal/channel.js +6 -2
- package/dist/cjs/internal/channel.js.map +1 -1
- package/dist/cjs/internal/runtime.js +21 -7
- package/dist/cjs/internal/runtime.js.map +1 -1
- package/dist/cjs/internal/schedule.js +68 -24
- package/dist/cjs/internal/schedule.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Effect.d.ts +76 -105
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Runtime.d.ts +12 -2
- package/dist/dts/Runtime.d.ts.map +1 -1
- package/dist/dts/internal/version.d.ts +1 -1
- package/dist/esm/Effect.js +3 -75
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Runtime.js.map +1 -1
- package/dist/esm/internal/channel.js +6 -2
- package/dist/esm/internal/channel.js.map +1 -1
- package/dist/esm/internal/runtime.js +21 -7
- package/dist/esm/internal/runtime.js.map +1 -1
- package/dist/esm/internal/schedule.js +64 -21
- package/dist/esm/internal/schedule.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Effect.ts +92 -115
- package/src/Runtime.ts +14 -3
- package/src/internal/channel.ts +2 -2
- package/src/internal/runtime.ts +39 -12
- package/src/internal/schedule.ts +126 -135
- package/src/internal/version.ts +1 -1
package/src/internal/schedule.ts
CHANGED
|
@@ -11,13 +11,14 @@ import type { LazyArg } from "../Function.js"
|
|
|
11
11
|
import { constVoid, dual, pipe } from "../Function.js"
|
|
12
12
|
import * as Option from "../Option.js"
|
|
13
13
|
import { pipeArguments } from "../Pipeable.js"
|
|
14
|
-
import
|
|
14
|
+
import { hasProperty, type Predicate } from "../Predicate.js"
|
|
15
15
|
import * as Random from "../Random.js"
|
|
16
16
|
import type * as Ref from "../Ref.js"
|
|
17
17
|
import type * as Schedule from "../Schedule.js"
|
|
18
18
|
import * as ScheduleDecision from "../ScheduleDecision.js"
|
|
19
19
|
import * as Interval from "../ScheduleInterval.js"
|
|
20
20
|
import * as Intervals from "../ScheduleIntervals.js"
|
|
21
|
+
import * as internalCause from "./cause.js"
|
|
21
22
|
import * as effect from "./core-effect.js"
|
|
22
23
|
import * as core from "./core.js"
|
|
23
24
|
import * as ref from "./ref.js"
|
|
@@ -30,6 +31,9 @@ export const ScheduleTypeId: Schedule.ScheduleTypeId = Symbol.for(
|
|
|
30
31
|
ScheduleSymbolKey
|
|
31
32
|
) as Schedule.ScheduleTypeId
|
|
32
33
|
|
|
34
|
+
/** @internal */
|
|
35
|
+
export const isSchedule = (u: unknown): u is Schedule.Schedule<any, any, any> => hasProperty(u, ScheduleTypeId)
|
|
36
|
+
|
|
33
37
|
/** @internal */
|
|
34
38
|
const ScheduleDriverSymbolKey = "effect/ScheduleDriver"
|
|
35
39
|
|
|
@@ -1831,6 +1835,29 @@ export const findNextMonth = (now: number, day: number, months: number): number
|
|
|
1831
1835
|
|
|
1832
1836
|
// circular with Effect
|
|
1833
1837
|
|
|
1838
|
+
const ScheduleDefectTypeId = Symbol.for("effect/Schedule/ScheduleDefect")
|
|
1839
|
+
class ScheduleDefect<E> {
|
|
1840
|
+
readonly [ScheduleDefectTypeId]: typeof ScheduleDefectTypeId
|
|
1841
|
+
constructor(readonly error: E) {
|
|
1842
|
+
this[ScheduleDefectTypeId] = ScheduleDefectTypeId
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
const isScheduleDefect = <E = unknown>(u: unknown): u is ScheduleDefect<E> => hasProperty(u, ScheduleDefectTypeId)
|
|
1846
|
+
const scheduleDefectWrap = <R, E, A>(self: Effect.Effect<R, E, A>) =>
|
|
1847
|
+
core.catchAll(self, (e) => core.die(new ScheduleDefect(e)))
|
|
1848
|
+
const scheduleDefectRefail = <R, E, A>(self: Effect.Effect<R, E, A>) =>
|
|
1849
|
+
core.catchAllCause(self, (cause) =>
|
|
1850
|
+
Option.match(
|
|
1851
|
+
internalCause.find(
|
|
1852
|
+
cause,
|
|
1853
|
+
(_) => internalCause.isDieType(_) && isScheduleDefect<E>(_.defect) ? Option.some(_.defect) : Option.none()
|
|
1854
|
+
),
|
|
1855
|
+
{
|
|
1856
|
+
onNone: () => core.failCause(cause),
|
|
1857
|
+
onSome: (error) => core.fail(error.error)
|
|
1858
|
+
}
|
|
1859
|
+
))
|
|
1860
|
+
|
|
1834
1861
|
/** @internal */
|
|
1835
1862
|
export const repeat_Effect = dual<
|
|
1836
1863
|
<R1, A extends A0, A0, B>(
|
|
@@ -1842,6 +1869,57 @@ export const repeat_Effect = dual<
|
|
|
1842
1869
|
) => Effect.Effect<R | R1, E, B>
|
|
1843
1870
|
>(2, (self, schedule) => repeatOrElse_Effect(self, schedule, (e, _) => core.fail(e)))
|
|
1844
1871
|
|
|
1872
|
+
/** @internal */
|
|
1873
|
+
export const repeat_combined = dual<{
|
|
1874
|
+
<A, O extends Effect.Repeat.Options<A>>(
|
|
1875
|
+
options: O
|
|
1876
|
+
): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Repeat.Return<R, E, A, O>
|
|
1877
|
+
<R1, A extends A0, A0, B>(
|
|
1878
|
+
schedule: Schedule.Schedule<R1, A, B>
|
|
1879
|
+
): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E, B>
|
|
1880
|
+
}, {
|
|
1881
|
+
<R, E, A, O extends Effect.Repeat.Options<A>>(
|
|
1882
|
+
self: Effect.Effect<R, E, A>,
|
|
1883
|
+
options: O
|
|
1884
|
+
): Effect.Repeat.Return<R, E, A, O>
|
|
1885
|
+
<R, E, A extends A0, A0, R1, B>(
|
|
1886
|
+
self: Effect.Effect<R, E, A>,
|
|
1887
|
+
schedule: Schedule.Schedule<R1, A0, B>
|
|
1888
|
+
): Effect.Effect<R | R1, E, B>
|
|
1889
|
+
}>(
|
|
1890
|
+
2,
|
|
1891
|
+
(self: Effect.Effect<any, any, any>, options: Effect.Repeat.Options<any> | Schedule.Schedule<any, any, any>) => {
|
|
1892
|
+
if (isSchedule(options)) {
|
|
1893
|
+
return repeat_Effect(self, options)
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
const base = options.schedule ?? passthrough(forever)
|
|
1897
|
+
const withWhile = options.while ?
|
|
1898
|
+
whileInputEffect(base, (a) => {
|
|
1899
|
+
const applied = options.while!(a)
|
|
1900
|
+
if (typeof applied === "boolean") {
|
|
1901
|
+
return core.succeed(applied)
|
|
1902
|
+
}
|
|
1903
|
+
return scheduleDefectWrap(applied)
|
|
1904
|
+
}) :
|
|
1905
|
+
base
|
|
1906
|
+
const withUntil = options.until ?
|
|
1907
|
+
untilInputEffect(withWhile, (a) => {
|
|
1908
|
+
const applied = options.until!(a)
|
|
1909
|
+
if (typeof applied === "boolean") {
|
|
1910
|
+
return core.succeed(applied)
|
|
1911
|
+
}
|
|
1912
|
+
return scheduleDefectWrap(applied)
|
|
1913
|
+
}) :
|
|
1914
|
+
withWhile
|
|
1915
|
+
const withTimes = options.times ?
|
|
1916
|
+
intersect(withUntil, recurs(options.times)) :
|
|
1917
|
+
withUntil
|
|
1918
|
+
|
|
1919
|
+
return scheduleDefectRefail(repeat_Effect(self, withTimes))
|
|
1920
|
+
}
|
|
1921
|
+
)
|
|
1922
|
+
|
|
1845
1923
|
/** @internal */
|
|
1846
1924
|
export const repeatOrElse_Effect = dual<
|
|
1847
1925
|
<R2, A extends A0, A0, B, E, R3, E2>(
|
|
@@ -1877,66 +1955,6 @@ const repeatOrElseEffectLoop = <R, E, A extends A0, A0, R1, B, R2, E2, C>(
|
|
|
1877
1955
|
})
|
|
1878
1956
|
}
|
|
1879
1957
|
|
|
1880
|
-
/** @internal */
|
|
1881
|
-
export const repeatUntil_Effect = dual<
|
|
1882
|
-
{
|
|
1883
|
-
<A, B extends A>(f: Refinement<A, B>): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, B>
|
|
1884
|
-
<A>(f: Predicate<A>): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>
|
|
1885
|
-
},
|
|
1886
|
-
{
|
|
1887
|
-
<R, E, A, B extends A>(self: Effect.Effect<R, E, A>, f: Predicate<A>): Effect.Effect<R, E, B>
|
|
1888
|
-
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<A>): Effect.Effect<R, E, A>
|
|
1889
|
-
}
|
|
1890
|
-
>(
|
|
1891
|
-
2,
|
|
1892
|
-
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<A>) =>
|
|
1893
|
-
repeatUntilEffect_Effect(self, (a) => core.sync(() => f(a)))
|
|
1894
|
-
)
|
|
1895
|
-
|
|
1896
|
-
/** @internal */
|
|
1897
|
-
export const repeatUntilEffect_Effect: {
|
|
1898
|
-
<A, R2, E2>(
|
|
1899
|
-
f: (a: A) => Effect.Effect<R2, E2, boolean>
|
|
1900
|
-
): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R2, E | E2, A>
|
|
1901
|
-
<R, E, A, R2, E2>(
|
|
1902
|
-
self: Effect.Effect<R, E, A>,
|
|
1903
|
-
f: (a: A) => Effect.Effect<R2, E2, boolean>
|
|
1904
|
-
): Effect.Effect<R | R2, E | E2, A>
|
|
1905
|
-
} = dual<
|
|
1906
|
-
<A, R2, E2>(
|
|
1907
|
-
f: (a: A) => Effect.Effect<R2, E2, boolean>
|
|
1908
|
-
) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R2, E | E2, A>,
|
|
1909
|
-
<R, E, A, R2, E2>(
|
|
1910
|
-
self: Effect.Effect<R, E, A>,
|
|
1911
|
-
f: (a: A) => Effect.Effect<R2, E2, boolean>
|
|
1912
|
-
) => Effect.Effect<R | R2, E | E2, A>
|
|
1913
|
-
>(2, (self, f) =>
|
|
1914
|
-
core.flatMap(self, (a) =>
|
|
1915
|
-
core.flatMap(f(a), (result) =>
|
|
1916
|
-
result ?
|
|
1917
|
-
core.succeed(a) :
|
|
1918
|
-
core.flatMap(
|
|
1919
|
-
core.yieldNow(),
|
|
1920
|
-
() => repeatUntilEffect_Effect(self, f)
|
|
1921
|
-
))))
|
|
1922
|
-
|
|
1923
|
-
/** @internal */
|
|
1924
|
-
export const repeatWhile_Effect = dual<
|
|
1925
|
-
<A>(f: Predicate<A>) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>,
|
|
1926
|
-
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<A>) => Effect.Effect<R, E, A>
|
|
1927
|
-
>(2, (self, f) => repeatWhileEffect_Effect(self, (a) => core.sync(() => f(a))))
|
|
1928
|
-
|
|
1929
|
-
/** @internal */
|
|
1930
|
-
export const repeatWhileEffect_Effect = dual<
|
|
1931
|
-
<R1, A, E2>(
|
|
1932
|
-
f: (a: A) => Effect.Effect<R1, E2, boolean>
|
|
1933
|
-
) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E2, A>,
|
|
1934
|
-
<R, E, R1, A, E2>(
|
|
1935
|
-
self: Effect.Effect<R, E, A>,
|
|
1936
|
-
f: (a: A) => Effect.Effect<R1, E2, boolean>
|
|
1937
|
-
) => Effect.Effect<R | R1, E | E2, A>
|
|
1938
|
-
>(2, (self, f) => repeatUntilEffect_Effect(self, (a) => effect.negate(f(a))))
|
|
1939
|
-
|
|
1940
1958
|
/** @internal */
|
|
1941
1959
|
export const retry_Effect = dual<
|
|
1942
1960
|
<R1, E extends E0, E0, B>(
|
|
@@ -1949,21 +1967,54 @@ export const retry_Effect = dual<
|
|
|
1949
1967
|
>(2, (self, policy) => retryOrElse_Effect(self, policy, (e, _) => core.fail(e)))
|
|
1950
1968
|
|
|
1951
1969
|
/** @internal */
|
|
1952
|
-
export const
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1970
|
+
export const retry_combined = dual<{
|
|
1971
|
+
<E, O extends Effect.Retry.Options<E>>(
|
|
1972
|
+
options: O
|
|
1973
|
+
): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Retry.Return<R, E, A, O>
|
|
1974
|
+
<R1, E extends E0, E0, B>(
|
|
1975
|
+
policy: Schedule.Schedule<R1, E0, B>
|
|
1976
|
+
): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E, A>
|
|
1977
|
+
}, {
|
|
1978
|
+
<R, A, E, O extends Effect.Retry.Options<E>>(
|
|
1979
|
+
self: Effect.Effect<R, E, A>,
|
|
1980
|
+
options: O
|
|
1981
|
+
): Effect.Retry.Return<R, E, A, O>
|
|
1982
|
+
<R, E extends E0, E0, A, R1, B>(
|
|
1983
|
+
self: Effect.Effect<R, E, A>,
|
|
1984
|
+
policy: Schedule.Schedule<R1, E0, B>
|
|
1985
|
+
): Effect.Effect<R | R1, E, A>
|
|
1986
|
+
}>(
|
|
1987
|
+
2,
|
|
1988
|
+
(self: Effect.Effect<any, any, any>, options: Effect.Retry.Options<any> | Schedule.Schedule<any, any, any>) => {
|
|
1989
|
+
if (isSchedule(options)) {
|
|
1990
|
+
return retry_Effect(self, options)
|
|
1991
|
+
}
|
|
1956
1992
|
|
|
1957
|
-
|
|
1958
|
-
const
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1993
|
+
const base = options.schedule ?? forever
|
|
1994
|
+
const withWhile = options.while ?
|
|
1995
|
+
whileInputEffect(base, (e) => {
|
|
1996
|
+
const applied = options.while!(e)
|
|
1997
|
+
if (typeof applied === "boolean") {
|
|
1998
|
+
return core.succeed(applied)
|
|
1999
|
+
}
|
|
2000
|
+
return scheduleDefectWrap(applied)
|
|
2001
|
+
}) :
|
|
2002
|
+
base
|
|
2003
|
+
const withUntil = options.until ?
|
|
2004
|
+
untilInputEffect(withWhile, (e) => {
|
|
2005
|
+
const applied = options.until!(e)
|
|
2006
|
+
if (typeof applied === "boolean") {
|
|
2007
|
+
return core.succeed(applied)
|
|
2008
|
+
}
|
|
2009
|
+
return scheduleDefectWrap(applied)
|
|
2010
|
+
}) :
|
|
2011
|
+
withWhile
|
|
2012
|
+
const withTimes = options.times ?
|
|
2013
|
+
intersect(withUntil, recurs(options.times)) :
|
|
2014
|
+
withUntil
|
|
2015
|
+
return scheduleDefectRefail(retry_Effect(self, withTimes))
|
|
2016
|
+
}
|
|
2017
|
+
)
|
|
1967
2018
|
|
|
1968
2019
|
/** @internal */
|
|
1969
2020
|
export const retryOrElse_Effect = dual<
|
|
@@ -2003,66 +2054,6 @@ const retryOrElse_EffectLoop = <R, E, A, R1, A1, R2, E2, A2>(
|
|
|
2003
2054
|
)
|
|
2004
2055
|
}
|
|
2005
2056
|
|
|
2006
|
-
/** @internal */
|
|
2007
|
-
export const retryUntil_Effect = dual<
|
|
2008
|
-
{
|
|
2009
|
-
<E, E2 extends E>(f: Refinement<E, E2>): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E2, A>
|
|
2010
|
-
<E>(f: Predicate<E>): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>
|
|
2011
|
-
},
|
|
2012
|
-
{
|
|
2013
|
-
<R, E, A, E2 extends E>(self: Effect.Effect<R, E, A>, f: Refinement<E, E2>): Effect.Effect<R, E2, A>
|
|
2014
|
-
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<E>): Effect.Effect<R, E, A>
|
|
2015
|
-
}
|
|
2016
|
-
>(2, <R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<E>) =>
|
|
2017
|
-
retryUntilEffect_Effect(
|
|
2018
|
-
self,
|
|
2019
|
-
(e) => core.sync(() => f(e))
|
|
2020
|
-
))
|
|
2021
|
-
|
|
2022
|
-
/** @internal */
|
|
2023
|
-
export const retryUntilEffect_Effect: {
|
|
2024
|
-
<R1, E, E2>(
|
|
2025
|
-
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2026
|
-
): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R1 | R, E | E2, A>
|
|
2027
|
-
<R, E, A, R1, E2>(
|
|
2028
|
-
self: Effect.Effect<R, E, A>,
|
|
2029
|
-
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2030
|
-
): Effect.Effect<R | R1, E | E2, A>
|
|
2031
|
-
} = dual<
|
|
2032
|
-
<R1, E, E2>(
|
|
2033
|
-
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2034
|
-
) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E2, A>,
|
|
2035
|
-
<R, E, A, R1, E2>(
|
|
2036
|
-
self: Effect.Effect<R, E, A>,
|
|
2037
|
-
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2038
|
-
) => Effect.Effect<R | R1, E | E2, A>
|
|
2039
|
-
>(2, (self, f) =>
|
|
2040
|
-
core.catchAll(self, (e) =>
|
|
2041
|
-
core.flatMap(f(e), (b) =>
|
|
2042
|
-
b ?
|
|
2043
|
-
core.fail(e) :
|
|
2044
|
-
core.flatMap(
|
|
2045
|
-
core.yieldNow(),
|
|
2046
|
-
() => retryUntilEffect_Effect(self, f)
|
|
2047
|
-
))))
|
|
2048
|
-
|
|
2049
|
-
/** @internal */
|
|
2050
|
-
export const retryWhile_Effect = dual<
|
|
2051
|
-
<E>(f: Predicate<E>) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>,
|
|
2052
|
-
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<E>) => Effect.Effect<R, E, A>
|
|
2053
|
-
>(2, (self, f) => retryWhileEffect_Effect(self, (e) => core.sync(() => f(e))))
|
|
2054
|
-
|
|
2055
|
-
/** @internal */
|
|
2056
|
-
export const retryWhileEffect_Effect = dual<
|
|
2057
|
-
<R1, E, E2>(
|
|
2058
|
-
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2059
|
-
) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E2, A>,
|
|
2060
|
-
<R, E, A, R1, E2>(
|
|
2061
|
-
self: Effect.Effect<R, E, A>,
|
|
2062
|
-
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2063
|
-
) => Effect.Effect<R | R1, E | E2, A>
|
|
2064
|
-
>(2, (self, f) => retryUntilEffect_Effect(self, (e) => effect.negate(f(e))))
|
|
2065
|
-
|
|
2066
2057
|
/** @internal */
|
|
2067
2058
|
export const schedule_Effect = dual<
|
|
2068
2059
|
<R2, Out>(
|
package/src/internal/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const moduleVersion = "2.0
|
|
1
|
+
export const moduleVersion = "2.1.0"
|