UNPKG

veffect

Version:

powerful TypeScript validation library built on the robust foundation of Effect combining exceptional type safety, high performance, and developer experience. Taking inspiration from Effect's functional principles, VEffect delivers a balanced approach tha

849 lines (848 loc) 26.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.zipWith = exports.zipRight = exports.zipLeft = exports.windowed = exports.whileOutputEffect = exports.whileOutput = exports.whileInputEffect = exports.whileInput = exports.upTo = exports.untilOutputEffect = exports.untilOutput = exports.untilInputEffect = exports.untilInput = exports.unionWith = exports.union = exports.unfold = exports.tapOutput = exports.tapInput = exports.sync = exports.succeed = exports.stop = exports.spaced = exports.secondOfMinute = exports.run = exports.resetWhen = exports.resetAfter = exports.repetitions = exports.repeatForever = exports.reduceEffect = exports.reduce = exports.recurs = exports.recurWhileEffect = exports.recurWhile = exports.recurUpTo = exports.recurUntilOption = exports.recurUntilEffect = exports.recurUntil = exports.provideService = exports.provideContext = exports.passthrough = exports.once = exports.onDecision = exports.modifyDelayEffect = exports.modifyDelay = exports.minuteOfHour = exports.mapInputEffect = exports.mapInputContext = exports.mapInput = exports.mapEffect = exports.mapBothEffect = exports.mapBoth = exports.map = exports.makeWithState = exports.linear = exports.jitteredWith = exports.jittered = exports.intersectWith = exports.intersect = exports.identity = exports.hourOfDay = exports.fromFunction = exports.fromDelays = exports.fromDelay = exports.forever = exports.fixed = exports.fibonacci = exports.exponential = exports.ensuring = exports.elapsed = exports.eitherWith = exports.either = exports.duration = exports.driver = exports.delays = exports.delayedSchedule = exports.delayedEffect = exports.delayed = exports.dayOfWeek = exports.dayOfMonth = exports.cron = exports.count = exports.compose = exports.collectWhileEffect = exports.collectWhile = exports.collectUntilEffect = exports.collectUntil = exports.collectAllOutputs = exports.collectAllInputs = exports.checkEffect = exports.check = exports.bothInOut = exports.asUnit = exports.as = exports.andThenEither = exports.andThen = exports.addDelayEffect = exports.addDelay = exports.ScheduleTypeId = exports.ScheduleDriverTypeId = void 0; var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./internal/schedule.js")); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /** * @since 2.0.0 * @category symbols */ const ScheduleTypeId = exports.ScheduleTypeId = internal.ScheduleTypeId; /** * @since 2.0.0 * @category symbols */ const ScheduleDriverTypeId = exports.ScheduleDriverTypeId = internal.ScheduleDriverTypeId; /** * Constructs a new `Schedule` with the specified `initial` state and the * specified `step` function. * * @since 2.0.0 * @category constructors */ const makeWithState = exports.makeWithState = internal.makeWithState; /** * Returns a new schedule with the given delay added to every interval defined * by this schedule. * * @since 2.0.0 * @category utils */ const addDelay = exports.addDelay = internal.addDelay; /** * Returns a new schedule with the given effectfully computed delay added to * every interval defined by this schedule. * * @since 2.0.0 * @category utils */ const addDelayEffect = exports.addDelayEffect = internal.addDelayEffect; /** * The same as `andThenEither`, but merges the output. * * @since 2.0.0 * @category sequencing */ const andThen = exports.andThen = internal.andThen; /** * Returns a new schedule that first executes this schedule to completion, and * then executes the specified schedule to completion. * * @since 2.0.0 * @category sequencing */ const andThenEither = exports.andThenEither = internal.andThenEither; /** * Returns a new schedule that maps this schedule to a constant output. * * @since 2.0.0 * @category mapping */ const as = exports.as = internal.as; /** * Returns a new schedule that maps the output of this schedule to unit. * * @since 2.0.0 * @category constructors */ const asUnit = exports.asUnit = internal.asUnit; /** * Returns a new schedule that has both the inputs and outputs of this and the * specified schedule. * * @since 2.0.0 * @category utils */ const bothInOut = exports.bothInOut = internal.bothInOut; /** * Returns a new schedule that passes each input and output of this schedule * to the specified function, and then determines whether or not to continue * based on the return value of the function. * * @since 2.0.0 * @category utils */ const check = exports.check = internal.check; /** * Returns a new schedule that passes each input and output of this schedule * to the specified function, and then determines whether or not to continue * based on the return value of the function. * * @since 2.0.0 * @category utils */ const checkEffect = exports.checkEffect = internal.checkEffect; /** * A schedule that recurs anywhere, collecting all inputs into a `Chunk`. * * @since 2.0.0 * @category constructors */ const collectAllInputs = exports.collectAllInputs = internal.collectAllInputs; /** * Returns a new schedule that collects the outputs of this one into a chunk. * * @since 2.0.0 * @category utils */ const collectAllOutputs = exports.collectAllOutputs = internal.collectAllOutputs; /** * A schedule that recurs until the condition f fails, collecting all inputs * into a list. * * @since 2.0.0 * @category utils */ const collectUntil = exports.collectUntil = internal.collectUntil; /** * A schedule that recurs until the effectful condition f fails, collecting * all inputs into a list. * * @since 2.0.0 * @category utils */ const collectUntilEffect = exports.collectUntilEffect = internal.collectUntilEffect; /** * A schedule that recurs as long as the condition f holds, collecting all * inputs into a list. * * @since 2.0.0 * @category utils */ const collectWhile = exports.collectWhile = internal.collectWhile; /** * A schedule that recurs as long as the effectful condition holds, collecting * all inputs into a list. * * @category utils * @since 2.0.0 */ const collectWhileEffect = exports.collectWhileEffect = internal.collectWhileEffect; /** * Returns the composition of this schedule and the specified schedule, by * piping the output of this one into the input of the other. Effects * described by this schedule will always be executed before the effects * described by the second schedule. * * @since 2.0.0 * @category utils */ const compose = exports.compose = internal.compose; /** * Returns a new schedule that deals with a narrower class of inputs than this * schedule. * * @since 2.0.0 * @category mapping */ const mapInput = exports.mapInput = internal.mapInput; /** * Transforms the context being provided to this schedule with the * specified function. * * @since 2.0.0 * @category context */ const mapInputContext = exports.mapInputContext = internal.mapInputContext; /** * Returns a new schedule that deals with a narrower class of inputs than this * schedule. * * @since 2.0.0 * @category mapping */ const mapInputEffect = exports.mapInputEffect = internal.mapInputEffect; /** * A schedule that always recurs, which counts the number of recurrences. * * @since 2.0.0 * @category constructors */ const count = exports.count = internal.count; /** * Cron schedule that recurs every `minute` that matches the schedule. * * It triggers at zero second of the minute. Producing the timestamps of the cron window. * * NOTE: `expression` parameter is validated lazily. Must be a valid cron expression. * * @since 2.0.0 * @category constructors */ const cron = exports.cron = internal.cron; /** * Cron-like schedule that recurs every specified `day` of month. Won't recur * on months containing less days than specified in `day` param. * * It triggers at zero hour of the day. Producing a count of repeats: 0, 1, 2. * * NOTE: `day` parameter is validated lazily. Must be in range 1...31. * * @since 2.0.0 * @category constructors */ const dayOfMonth = exports.dayOfMonth = internal.dayOfMonth; /** * Cron-like schedule that recurs every specified `day` of each week. It * triggers at zero hour of the week. Producing a count of repeats: 0, 1, 2. * * NOTE: `day` parameter is validated lazily. Must be in range 1 (Monday)...7 * (Sunday). * * @since 2.0.0 * @category constructors */ const dayOfWeek = exports.dayOfWeek = internal.dayOfWeek; /** * Returns a new schedule with the specified effectfully computed delay added * before the start of each interval produced by this schedule. * * @since 2.0.0 * @category utils */ const delayed = exports.delayed = internal.delayed; /** * Returns a new schedule with the specified effectfully computed delay added * before the start of each interval produced by this schedule. * * @since 2.0.0 * @category constructors */ const delayedEffect = exports.delayedEffect = internal.delayedEffect; /** * Takes a schedule that produces a delay, and returns a new schedule that * uses this delay to further delay intervals in the resulting schedule. * * @since 2.0.0 * @category constructors */ const delayedSchedule = exports.delayedSchedule = internal.delayedSchedule; /** * Returns a new schedule that outputs the delay between each occurence. * * @since 2.0.0 * @category constructors */ const delays = exports.delays = internal.delays; /** * Returns a new schedule that maps both the input and output. * * @since 2.0.0 * @category mapping */ const mapBoth = exports.mapBoth = internal.mapBoth; /** * Returns a new schedule that maps both the input and output. * * @since 2.0.0 * @category mapping */ const mapBothEffect = exports.mapBothEffect = internal.mapBothEffect; /** * Returns a driver that can be used to step the schedule, appropriately * handling sleeping. * * @since 2.0.0 * @category getter */ const driver = exports.driver = internal.driver; /** * A schedule that can recur one time, the specified amount of time into the * future. * * @since 2.0.0 * @category constructors */ const duration = exports.duration = internal.duration; /** * Returns a new schedule that performs a geometric union on the intervals * defined by both schedules. * * @since 2.0.0 * @category alternatives */ const either = exports.either = internal.either; /** * The same as `either` followed by `map`. * * @since 2.0.0 * @category alternatives */ const eitherWith = exports.eitherWith = internal.eitherWith; /** * A schedule that occurs everywhere, which returns the total elapsed duration * since the first step. * * @since 2.0.0 * @category constructors */ const elapsed = exports.elapsed = internal.elapsed; /** * Returns a new schedule that will run the specified finalizer as soon as the * schedule is complete. Note that unlike `Effect.ensuring`, this method does not * guarantee the finalizer will be run. The `Schedule` may not initialize or * the driver of the schedule may not run to completion. However, if the * `Schedule` ever decides not to continue, then the finalizer will be run. * * @since 2.0.0 * @category finalization */ const ensuring = exports.ensuring = internal.ensuring; /** * A schedule that always recurs, but will wait a certain amount between * repetitions, given by `base * factor.pow(n)`, where `n` is the number of * repetitions so far. Returns the current duration between recurrences. * * @since 2.0.0 * @category constructors */ const exponential = exports.exponential = internal.exponential; /** * A schedule that always recurs, increasing delays by summing the preceding * two delays (similar to the fibonacci sequence). Returns the current * duration between recurrences. * * @since 2.0.0 * @category constructors */ const fibonacci = exports.fibonacci = internal.fibonacci; /** * A schedule that recurs on a fixed interval. Returns the number of * repetitions of the schedule so far. * * If the action run between updates takes longer than the interval, then the * action will be run immediately, but re-runs will not "pile up". * * ``` * |-----interval-----|-----interval-----|-----interval-----| * |---------action--------||action|-----|action|-----------| * ``` * * @since 2.0.0 * @category constructors */ const fixed = exports.fixed = internal.fixed; /** * A schedule that always recurs, producing a count of repeats: 0, 1, 2. * * @since 2.0.0 * @category constructors */ const forever = exports.forever = internal.forever; /** * A schedule that recurs once with the specified delay. * * @since 2.0.0 * @category constructors */ const fromDelay = exports.fromDelay = internal.fromDelay; /** * A schedule that recurs once for each of the specified durations, delaying * each time for the length of the specified duration. Returns the length of * the current duration between recurrences. * * @since 2.0.0 * @category constructors */ const fromDelays = exports.fromDelays = internal.fromDelays; /** * A schedule that always recurs, mapping input values through the specified * function. * * @since 2.0.0 * @category constructors */ const fromFunction = exports.fromFunction = internal.fromFunction; /** * Cron-like schedule that recurs every specified `hour` of each day. It * triggers at zero minute of the hour. Producing a count of repeats: 0, 1, 2. * * NOTE: `hour` parameter is validated lazily. Must be in range 0...23. * * @since 2.0.0 * @category constructors */ const hourOfDay = exports.hourOfDay = internal.hourOfDay; /** * A schedule that always recurs, which returns inputs as outputs. * * @since 2.0.0 * @category constructors */ const identity = exports.identity = internal.identity; /** * Returns a new schedule that performs a geometric intersection on the * intervals defined by both schedules. * * @since 2.0.0 * @category utils */ const intersect = exports.intersect = internal.intersect; /** * Returns a new schedule that combines this schedule with the specified * schedule, continuing as long as both schedules want to continue and merging * the next intervals according to the specified merge function. * * @since 2.0.0 * @category utils */ const intersectWith = exports.intersectWith = internal.intersectWith; /** * Returns a new schedule that randomly modifies the size of the intervals of * this schedule. * * Defaults `min` to `0.8` and `max` to `1.2`. * * The new interval size is between `min * old interval size` and `max * old * interval size`. * * @since 2.0.0 * @category constructors */ const jittered = exports.jittered = internal.jittered; /** * Returns a new schedule that randomly modifies the size of the intervals of * this schedule. * * The new interval size is between `min * old interval size` and `max * old * interval size`. * * @since 2.0.0 * @category constructors */ const jitteredWith = exports.jitteredWith = internal.jitteredWith; /** * A schedule that always recurs, but will repeat on a linear time interval, * given by `base * n` where `n` is the number of repetitions so far. Returns * the current duration between recurrences. * * @since 2.0.0 * @category constructors */ const linear = exports.linear = internal.linear; /** * Returns a new schedule that maps the output of this schedule through the * specified function. * * @since 2.0.0 * @category mapping */ const map = exports.map = internal.map; /** * Returns a new schedule that maps the output of this schedule through the * specified effectful function. * * @since 2.0.0 * @category mapping */ const mapEffect = exports.mapEffect = internal.mapEffect; /** * Cron-like schedule that recurs every specified `minute` of each hour. It * triggers at zero second of the minute. Producing a count of repeats: 0, 1, * 2. * * NOTE: `minute` parameter is validated lazily. Must be in range 0...59. * * @since 2.0.0 * @category constructors */ const minuteOfHour = exports.minuteOfHour = internal.minuteOfHour; /** * Returns a new schedule that modifies the delay using the specified * function. * * @since 2.0.0 * @category utils */ const modifyDelay = exports.modifyDelay = internal.modifyDelay; /** * Returns a new schedule that modifies the delay using the specified * effectual function. * * @since 2.0.0 * @category utils */ const modifyDelayEffect = exports.modifyDelayEffect = internal.modifyDelayEffect; /** * Returns a new schedule that applies the current one but runs the specified * effect for every decision of this schedule. This can be used to create * schedules that log failures, decisions, or computed values. * * @since 2.0.0 * @category utils */ const onDecision = exports.onDecision = internal.onDecision; /** * A schedule that recurs one time. * * @since 2.0.0 * @category constructors */ const once = exports.once = internal.once; /** * Returns a new schedule that passes through the inputs of this schedule. * * @since 2.0.0 * @category utils */ const passthrough = exports.passthrough = internal.passthrough; /** * Returns a new schedule with its context provided to it, so the * resulting schedule does not require any context. * * @since 2.0.0 * @category context */ const provideContext = exports.provideContext = internal.provideContext; /** * Returns a new schedule with the single service it requires provided to it. * If the schedule requires multiple services use `provideContext` * instead. * * @since 2.0.0 * @category context */ const provideService = exports.provideService = internal.provideService; /** * A schedule that recurs for until the predicate evaluates to true. * * @since 2.0.0 * @category utils */ const recurUntil = exports.recurUntil = internal.recurUntil; /** * A schedule that recurs for until the predicate evaluates to true. * * @since 2.0.0 * @category utils */ const recurUntilEffect = exports.recurUntilEffect = internal.recurUntilEffect; /** * A schedule that recurs for until the input value becomes applicable to * partial function and then map that value with given function. * * @since 2.0.0 * @category utils */ const recurUntilOption = exports.recurUntilOption = internal.recurUntilOption; /** * A schedule that recurs during the given duration. * * @since 2.0.0 * @category utils */ const recurUpTo = exports.recurUpTo = internal.recurUpTo; /** * A schedule that recurs for as long as the predicate evaluates to true. * * @since 2.0.0 * @category utils */ const recurWhile = exports.recurWhile = internal.recurWhile; /** * A schedule that recurs for as long as the effectful predicate evaluates to * true. * * @since 2.0.0 * @category utils */ const recurWhileEffect = exports.recurWhileEffect = internal.recurWhileEffect; /** * A schedule spanning all time, which can be stepped only the specified * number of times before it terminates. * * @category constructors * @since 2.0.0 */ const recurs = exports.recurs = internal.recurs; /** * Returns a new schedule that folds over the outputs of this one. * * @since 2.0.0 * @category folding */ const reduce = exports.reduce = internal.reduce; /** * Returns a new schedule that effectfully folds over the outputs of this one. * * @since 2.0.0 * @category folding */ const reduceEffect = exports.reduceEffect = internal.reduceEffect; /** * Returns a new schedule that loops this one continuously, resetting the * state when this schedule is done. * * @since 2.0.0 * @category constructors */ const repeatForever = exports.repeatForever = internal.forever; /** * Returns a new schedule that outputs the number of repetitions of this one. * * @since 2.0.0 * @category utils */ const repetitions = exports.repetitions = internal.repetitions; /** * Return a new schedule that automatically resets the schedule to its initial * state after some time of inactivity defined by `duration`. * * @since 2.0.0 * @category utils */ const resetAfter = exports.resetAfter = internal.resetAfter; /** * Resets the schedule when the specified predicate on the schedule output * evaluates to true. * * @since 2.0.0 * @category utils */ const resetWhen = exports.resetWhen = internal.resetWhen; /** * Runs a schedule using the provided inputs, and collects all outputs. * * @since 2.0.0 * @category destructors */ const run = exports.run = internal.run; /** * Cron-like schedule that recurs every specified `second` of each minute. It * triggers at zero nanosecond of the second. Producing a count of repeats: 0, * 1, 2. * * NOTE: `second` parameter is validated lazily. Must be in range 0...59. * * @since 2.0.0 * @category constructors */ const secondOfMinute = exports.secondOfMinute = internal.secondOfMinute; /** * Returns a schedule that recurs continuously, each repetition spaced the * specified duration from the last run. * * @since 2.0.0 * @category constructors */ const spaced = exports.spaced = internal.spaced; /** * A schedule that does not recur, it just stops. * * @since 2.0.0 * @category constructors */ const stop = exports.stop = internal.stop; /** * Returns a schedule that repeats one time, producing the specified constant * value. * * @since 2.0.0 * @category constructors */ const succeed = exports.succeed = internal.succeed; /** * Returns a schedule that repeats one time, producing the specified constant * value. * * @category constructors * @since 2.0.0 */ const sync = exports.sync = internal.sync; /** * Returns a new schedule that effectfully processes every input to this * schedule. * * @since 2.0.0 * @category sequencing */ const tapInput = exports.tapInput = internal.tapInput; /** * Returns a new schedule that effectfully processes every output from this * schedule. * * @since 2.0.0 * @category sequencing */ const tapOutput = exports.tapOutput = internal.tapOutput; /** * Unfolds a schedule that repeats one time from the specified state and * iterator. * * @since 2.0.0 * @category constructors */ const unfold = exports.unfold = internal.unfold; /** * Returns a new schedule that performs a geometric union on the intervals * defined by both schedules. * * @since 2.0.0 * @category utils */ const union = exports.union = internal.union; /** * Returns a new schedule that combines this schedule with the specified * schedule, continuing as long as either schedule wants to continue and * merging the next intervals according to the specified merge function. * * @since 2.0.0 * @category utils */ const unionWith = exports.unionWith = internal.unionWith; /** * Returns a new schedule that continues until the specified predicate on the * input evaluates to true. * * @since 2.0.0 * @category utils */ const untilInput = exports.untilInput = internal.untilInput; /** * Returns a new schedule that continues until the specified effectful * predicate on the input evaluates to true. * * @since 2.0.0 * @category utils */ const untilInputEffect = exports.untilInputEffect = internal.untilInputEffect; /** * Returns a new schedule that continues until the specified predicate on the * output evaluates to true. * * @since 2.0.0 * @category utils */ const untilOutput = exports.untilOutput = internal.untilOutput; /** * Returns a new schedule that continues until the specified effectful * predicate on the output evaluates to true. * * @since 2.0.0 * @category utils */ const untilOutputEffect = exports.untilOutputEffect = internal.untilOutputEffect; /** * A schedule that recurs during the given duration. * * @since 2.0.0 * @category utils */ const upTo = exports.upTo = internal.upTo; /** * Returns a new schedule that continues for as long the specified predicate * on the input evaluates to true. * * @since 2.0.0 * @category utils */ const whileInput = exports.whileInput = internal.whileInput; /** * Returns a new schedule that continues for as long the specified effectful * predicate on the input evaluates to true. * * @since 2.0.0 * @category utils */ const whileInputEffect = exports.whileInputEffect = internal.whileInputEffect; /** * Returns a new schedule that continues for as long the specified predicate * on the output evaluates to true. * * @since 2.0.0 * @category utils */ const whileOutput = exports.whileOutput = internal.whileOutput; /** * Returns a new schedule that continues for as long the specified effectful * predicate on the output evaluates to true. * * @since 2.0.0 * @category utils */ const whileOutputEffect = exports.whileOutputEffect = internal.whileOutputEffect; /** * A schedule that divides the timeline to `interval`-long windows, and sleeps * until the nearest window boundary every time it recurs. * * For example, `windowed(Duration.seconds(10))` would produce a schedule as * follows: * * ``` * 10s 10s 10s 10s * |----------|----------|----------|----------| * |action------|sleep---|act|-sleep|action----| * ``` * * @since 2.0.0 * @category constructors */ const windowed = exports.windowed = internal.windowed; /** * The same as `intersect` but ignores the right output. * * @since 2.0.0 * @category zipping */ const zipLeft = exports.zipLeft = internal.zipLeft; /** * The same as `intersect` but ignores the left output. * * @since 2.0.0 * @category zipping */ const zipRight = exports.zipRight = internal.zipRight; /** * Equivalent to `intersect` followed by `map`. * * @since 2.0.0 * @category zipping */ const zipWith = exports.zipWith = internal.zipWith; //# sourceMappingURL=Schedule.js.map