croner 11.0.1-dev.3 → 11.0.1-dev.4

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/README.md CHANGED
@@ -75,13 +75,13 @@ const { Cron } = require("croner");
75
75
  Using Deno
76
76
 
77
77
  ```typescript
78
- import { Cron } from "jsr:@hexagon/croner@11.0.1-dev.3";
78
+ import { Cron } from "jsr:@hexagon/croner@11.0.1-dev.4";
79
79
  ```
80
80
 
81
81
  In a webpage using the UMD-module
82
82
 
83
83
  ```html
84
- <script src="https://cdn.jsdelivr.net/npm/croner@11.0.1-dev.3/dist/croner.umd.js"></script>
84
+ <script src="https://cdn.jsdelivr.net/npm/croner@11.0.1-dev.4/dist/croner.umd.js"></script>
85
85
  ```
86
86
 
87
87
  ## Documentation
package/dist/croner.cjs CHANGED
@@ -1 +1 @@
1
- var M=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var B=(r,e)=>{for(var t in e)M(r,t,{get:e[t],enumerable:!0})},J=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of H(e))!V.call(r,s)&&s!==t&&M(r,s,{get:()=>e[s],enumerable:!(n=Z(e,s))||n.enumerable});return r};var G=r=>J(M({},"__esModule",{value:!0}),r);var X={};B(X,{Cron:()=>S,CronDate:()=>f,CronIterator:()=>O,CronPattern:()=>b,scheduledJobs:()=>w});module.exports=G(X);function g(r,e,t,n=0,s=0,i=0,a=0){let o=r>=0&&r<100,u=Date.UTC(o?r+400:r,e,t,n,s,i,a);return o?u-126227808e5:u}function v(r){return g(r.y,r.m-1,r.d,r.h,r.i,r.s)}function D(r,e){return r.y===e.y&&r.m===e.m&&r.d===e.d&&r.h===e.h&&r.i===e.i&&r.s===e.s}function x(r){let e=r.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function K(r,e){let t=new Date(Date.parse(r));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return x(r)?{tp:T(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"),ms:t.getUTCMilliseconds()}:{tp:T(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e),ms:t.getMilliseconds()}}function _(r,e,t){let{tp:n,ms:s}=K(r,e);return new Date(P(n,t).getTime()+s)}function P(r,e){let t=k(r);if(t.kind==="single")return t.date;if(t.kind==="ambiguous")return t.earlier;if(e)throw new Error("Invalid date passed to fromTZ()");return t.after}function k(r){let e=v(r),t=a=>N(new Date(a),r.tz),n=e-t(e),s=y(new Date(n),r.tz);if(D(s,r)){let a=v(s)-n,o=n-(t(n-U)-a);if(o<n&&D(y(new Date(o),r.tz),r))return{kind:"ambiguous",earlier:new Date(o),later:new Date(n)};let u=n+(a-t(n+U));return u>n&&D(y(new Date(u),r.tz),r)?{kind:"ambiguous",earlier:new Date(n),later:new Date(u)}:{kind:"single",date:new Date(n)}}let i=e-(v(s)-n);return D(y(new Date(i),r.tz),r)?{kind:"single",date:new Date(i)}:{kind:"gap",before:new Date(Math.min(n,i)),after:new Date(Math.max(n,i))}}var U=3*36e5;function N(r,e){return v(y(r,e))-(r.getTime()-r.getUTCMilliseconds())}function R(r,e,t){let n=N(new Date(r),t);for(;e-r>1e3;){let s=r+Math.floor((e-r)/2e3)*1e3;N(new Date(s),t)===n?r=s:e=s}return e}function z(r,e){let t=k(y(new Date(r),e));if(t.kind==="ambiguous")return r<t.later.getTime()?"earlier":"later"}var W=new Map;function y(r,e){if(e===void 0)return T(r.getFullYear(),r.getMonth()+1,r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds());let t=W.get(e),n;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),W.set(e,t)),n=t.formatToParts(r)}catch(i){let a=i instanceof Error?i.message:String(i);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`)}let s={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of n)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(s[i.type]=parseInt(i.value,10));if(isNaN(s.year)||isNaN(s.month)||isNaN(s.day)||isNaN(s.hour)||isNaN(s.minute)||isNaN(s.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(s)}`);return s.hour===24&&(s.hour=0),{y:s.year,m:s.month,d:s.day,h:s.hour,i:s.minute,s:s.second,tz:e}}function T(r,e,t,n,s,i,a){return{y:r,m:e,d:t,h:n,i:s,s:i,tz:a}}var A=[1,2,4,8,16],b=class r{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;fixedTimeRule;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;isFixedTime;constructor(e,t,n){this.pattern=e,this.timezone=t,this.mode=n?.mode??"auto",this.alternativeWeekdays=n?.alternativeWeekdays??!1,this.sloppyRanges=n?.sloppyRanges??!1,this.fixedTimeRule=n?.fixedTimeRule??"single-value",this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=[],this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.isFixedTime=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let a;switch(this.mode){case"5-part":a=5;break;case"6-part":a=6;break;case"7-part":a=7;break;case"5-or-6-parts":a=[5,6];break;case"6-or-7-parts":a=[6,7];break;default:a=0}if(!(Array.isArray(a)?a.includes(t):t===a)){let u=Array.isArray(a)?a.join(" or "):a.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${u} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let a=0;a<e.length;a++)e[a]=e[a].replace(/\?/g,"*");if(e[3].toUpperCase()==="LW")this.lastWeekday=!0,e[3]="";else if(e[3].toUpperCase().indexOf("L")>=0){let a=e[3].split(",");if(a.some(o=>o===""||o.toUpperCase()!=="L"&&/l/i.test(o)))throw new TypeError("CronPattern: Syntax error, L has to be a value of its own in day-of-month ('"+e[3]+"').");e[3]=a.filter(o=>o.toUpperCase()!=="L").join(","),this.lastDayOfMonth=!0}if(e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlpha(e[4],r.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],r.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],r.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let n=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],n,63),e[6]==="*"?this.year=Array(1e4).fill(1):(this.year=Array(1e4).fill(0),this.partToArray("year",e[6],0,1)),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let s=this.fixedTimeRule==="single-value",i=(a,o)=>!a.includes("*")&&!a.includes("/")&&(!s||o.filter(u=>u).length===1);this.isFixedTime=i(e[0],this.second)&&i(e[1],this.minute)&&i(e[2],this.hour)}partToArray(e,t,n,s){let i=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(s);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,n,s);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,n,s):t.includes("-")?this.handleRange(t,e,n,s):t.includes("/")?this.handleStepping(t,e,n,s):t!==""&&this.handleNumber(t,e,n,s)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,n,s){let i=this.extractNth(e,t),a=e.toUpperCase().includes("W");if(t!=="day"&&a)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");a&&(t="nearestWeekdays");let o=a?i[0].replace(/W$/i,""):i[0],u=r.toNumber(o)+n;if(isNaN(u))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,u,i[1]||s)}setPart(e,t,n){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,n);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=n}static toNumber(e){return/^\d+$/.test(e)?parseInt(e,10):NaN}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,n,s,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(n!==void 0){if(n===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(n>this[s].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[s].length+")")}}handleRangeWithStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let i=this.extractNth(e,t),a=i[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,l]=a,h=parseInt(o,10)+n,c=parseInt(u,10)+n,d=parseInt(l,10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(c,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(h,c,d,t,e);for(let p=h;p<=c;p+=d)this.setPart(t,p,i[1]||s)}extractNth(e,t){let n=e,s;if(n.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");let i=n.split("#");if(i.length!==2||i[1]==="")throw new TypeError("CronPattern: Syntax error, illegal nth weekday: '"+e+"'");n=i[0],s=i[1]}else if(n.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");s="L",n=n.slice(0,-1)}return[n,s]}handleRange(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let i=this.extractNth(e,t),a=i[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=r.toNumber(a[0])+n,u=r.toNumber(a[1])+n;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,u,void 0,t,e);for(let l=o;l<=u;l++)this.setPart(t,l,i[1]||s)}handleStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let i=this.extractNth(e,t),a=i[0].split("/");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)a[0]===""&&(a[0]="*");else{if(a[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(a[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;a[0]!=="*"&&(o=r.toNumber(a[0])+n,this.validateNotNaN(o,"CronPattern: Syntax error, illegal stepping start (NaN)"));let u=r.toNumber(a[1]);this.validateNotNaN(u,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,u,t,e);for(let l=o;l<this[t].length;l+=u)t==="year"&&l===0||this.setPart(t,l,i[1]||s)}replaceAlpha(e,t){let n=e;for(let[s,i]of Object.entries(t))n=n.replace(new RegExp(s,"gi"),i);return n}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * SUN","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return r.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|A[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var Q=[31,28,31,30,31,30,31,31,30,31,30,31],m=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],f=class r{tz;instantMs;instantFields;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof r)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?Q[t]:new Date(g(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let n=this.getLastDayOfMonth(e,t),i=new Date(g(e,t,n)).getUTCDay();return i===0?n-2:i===6?n-1:n}getNearestWeekday(e,t,n){let s=this.getLastDayOfMonth(e,t);if(n>s)return-1;let a=new Date(g(e,t,n)).getUTCDay();return a===0?n===s?n-2:n+1:a===6?n===1?n+2:n-1:n}isNthWeekdayOfMonth(e,t,n,s){let a=new Date(g(e,t,n)).getUTCDay(),o=0;for(let u=1;u<=n;u++)new Date(g(e,t,u)).getUTCDay()===a&&o++;if(s&63&&A[o-1]&s)return!0;if(s&32){let u=this.getLastDayOfMonth(e,t);for(let l=n+1;l<=u;l++)if(new Date(g(e,t,l)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=y(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.cacheInstant(e.getTime()-this.ms)}catch(t){let n=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${n}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear(),this.cacheInstant(e.getTime()-this.ms)}cacheInstant(e){this.instantMs=e;let{year:t,month:n,day:s,hour:i,minute:a,second:o}=this;this.instantFields=[t,n,s,i,a,o,this.tz]}cachedInstant(){let e=this.instantFields;if(!(e===void 0||e[6]!==this.tz)&&!(e[5]!==this.second||e[4]!==this.minute||e[3]!==this.hour)&&!(e[2]!==this.day||e[1]!==this.month||e[0]!==this.year))return this.instantMs}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms,this.instantMs=e.instantMs,this.instantFields=e.instantFields}apply(){if(this.month>11||this.month<0||this.day>this.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(0);return e.setUTCFullYear(this.year,this.month,this.day),e.setUTCHours(this.hour,this.minute,this.second,this.ms),this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){if(x(e))return this.fromDate(_(e));let t=_(e,"Etc/UTC");this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(_(e,this.tz))}findNext(e,t,n,s){return this._findMatch(e,t,n,s,1)}_matchDayValue(e,t,n,s){let i=e;if(!i){for(let a=0;a<n.nearestWeekdays.length;a++)if(n.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){i=1;break}}}if(n.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(i=1)}if(n.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(i=1)}if(!n.starDOW){let a=new Date(g(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=n.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),n.useAndLogic?i=i&&o:!s.domAndDow&&!n.starDOM?i=i||o:i=i&&o}return i}_findMatch(e,t,n,s,i){let a=this[t],o=t==="day"?this.getLastDayOfMonth(this.year,this.month):0,u=this[t]+s,l=i===1?h=>h<n[t].length:h=>h>=0;for(let h=u;l(h);h+=i){let c=n[t][h];if(t==="day"){if(h-s>o)continue;c=this._matchDayValue(c,h-s,n,e)}if(c)return this[t]=h-s,a!==this[t]?2:1}return 3}recurse(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseStep(e,t,i)}return i}recurseStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let s=this.findNext(t,m[n][0],e,m[n][2]);if(s>1){let i=n+1;for(;i<m.length;)this[m[i][0]]=-m[i][2],i++;if(s===3){if(this[m[n][1]]++,this[m[n][0]]=-m[n][2],this.apply(),n===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return 0}else if(this.apply())return n-1}return n+=1,n>=m.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:n}increment(e,t,n){return this.instantMs=void 0,this.instantFields=void 0,this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t,n=!0){return this.instantMs=void 0,this.instantFields=void 0,this.second-=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0)}recurseBackward(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseBackwardStep(e,t,i)}return i}recurseBackwardStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let s=this.findPrevious(t,m[n][0],e,m[n][2]);if(s>1){let i=n+1;for(;i<m.length;){let a=m[i][0],o=m[i][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,i++}if(s===3){if(this[m[n][1]]--,n===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(n===1)if(this.day<=0)this.day=1;else{let u=this.year,l=this.month;for(;l<0;)l+=12,u--;for(;l>11;)l-=12,u++;let h=this.getLastDayOfMonth(u,l);this.day>h&&(this.day=h)}this.apply();let a=m[n][0],o=m[n][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),n===0){let u=m[1][2],l=this.getMaxPatternValue("day",e,u);l!==this.day&&(this.day=l,this.hour=this.getMaxPatternValue("hour",e,m[2][2]),this.minute=this.getMaxPatternValue("minute",e,m[3][2]),this.second=this.getMaxPatternValue("second",e,m[4][2]))}if(n===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return 0}else if(this.apply())return n-1}return n+=1,n>=m.length?this:this.year<0?null:n}getMaxPatternValue(e,t,n){let s=t[e].length-1-n;for(let i=t[e].length-1;i>=0;i--)if(t[e][i]){s=i-n;break}if(e==="day"){let i=this.getLastDayOfMonth(this.year,this.month);return t.lastWeekday||t.nearestWeekdays.some(a=>a)||t.lastDayOfMonth||!t.starDOW?i:Math.min(s,i)}return s}findPrevious(e,t,n,s){return this._findMatch(e,t,n,s,-1)}getDate(e){if(!e&&typeof this.tz!="number"){let t=this.cachedInstant();if(t!==void 0)return new Date(t+(this.tz===void 0?this.ms:0))}if(e||this.tz===void 0){if(this.year>=0&&this.year<100){let t=new Date(0);return t.setFullYear(this.year,this.month,this.day),t.setHours(this.hour,this.minute,this.second,this.ms),t}return new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms)}else return typeof this.tz=="number"?new Date(g(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):P(T(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let n=0;n<m.length;n++){let s=m[n][0],i=m[n][2],a=this[s];if(a+i<0||a+i>=e[s].length)return!1;let o=e[s][a+i];if(s==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}};function L(r){r===void 0&&(r={}),delete r.name,r.legacyMode!==void 0&&r.domAndDow===void 0?r.domAndDow=!r.legacyMode:r.domAndDow===void 0&&(r.domAndDow=!1),r.legacyMode=!r.domAndDow;let e=(n,s)=>n===void 0?s:n;if(r.paused=e(r.paused,!1),r.maxRuns=e(r.maxRuns,1/0),r.catch=e(r.catch,!1),r.unref=e(r.unref,!1),r.mode=e(r.mode,"auto"),r.alternativeWeekdays=e(r.alternativeWeekdays,!1),r.sloppyRanges=e(r.sloppyRanges,!1),r.fixedTimeRule=e(r.fixedTimeRule,"single-value"),r.allowPast=e(r.allowPast,!1),r.interval=r.interval===void 0?0:parseInt(r.interval.toString(),10),r.utcOffset=r.utcOffset===void 0?void 0:parseInt(r.utcOffset.toString(),10),r.dayOffset=r.dayOffset===void 0?0:parseInt(r.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(r.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");if(!["single-value","no-wildcard"].includes(r.fixedTimeRule))throw new Error("CronOptions: fixedTimeRule must be one of 'single-value' or 'no-wildcard'.");r.timezone===""&&(r.timezone=void 0);let t=r.timezone??r.utcOffset;if(r.startAt&&(r.startAt=F(new f(r.startAt,t))),r.stopAt&&(r.stopAt=F(new f(r.stopAt,t))),r.interval!==null){if(isNaN(r.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(r.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(r.utcOffset!==void 0){if(isNaN(r.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(r.utcOffset<-870||r.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(r.utcOffset!==void 0&&r.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(r.unref!==!0&&r.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(r.dayOffset!==void 0&&r.dayOffset!==0&&isNaN(r.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return r}function F(r){return r.ms?(r.ms=0,new f(new Date(r.getTime()+1e3),r.tz)):r}function C(r){return typeof r=="function"}function Y(r){return C(r)}function j(r){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(r):r&&typeof r.unref<"u"&&r.unref()}var E=1440*60*1e3,$=30*1e3,w=[],S=class{name;options;_states;fn;_startAtRoundingMs=0;getTz(){return this.options.timezone??this.options.utcOffset}applyDayOffset(e){let t=this._offsetMs();return t?new Date(e.getTime()+t):e}_offsetMs(){return(this.options.dayOffset??0)*E}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let n=this._offsetMs(),s=this._next(this._shift(e),new Date(t.getTime()-n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return s?this.applyDayOffset(s.getDate(!1)):null}_previousTarget(e,t){let n=this._previous(this._shift(e??t),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return n?this.applyDayOffset(n.getDate(!1)):null}_shift(e){if(e!=null)return new f(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,n){let s,i;if(C(t))i=t;else if(typeof t=="object")s=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(C(n))i=n;else if(typeof n=="object")s=n;else if(n!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");this.name=s?.name;let a=s?.startAt;this.options=L(s),a&&this._startAt&&(this._startAtRoundingMs=this._startAt.getTime()-new f(a,this.getTz()).getTime());let o=!!e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0);if(this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:s?s.maxRuns:void 0,paused:s?s.paused:!1,pattern:o?new b("* * * * *",void 0,{mode:"auto"}):new b(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges,fixedTimeRule:this.options.fixedTimeRule})},o&&(this._states.once=new f(e,this.getTz())),this.name){if(w.find(l=>l.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");w.push(this)}return i!==void 0&&Y(i)&&(this.fn=i,this.schedule()),this}nextRun(e){return this._nextTarget(e,new Date)}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let n=t||this._states.currentRun||void 0;return this._enumerateRuns(e,n,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new O(this,e)}_enumerateRuns(e,t,n){let s=[],i=new Date,a=t;for(;e-- >0;){let o=n==="next"?this._nextTarget(a,i):this._previousTarget(a,i);if(!o)break;s.push(o),a=o}return s}match(e){if(this._states.once){let n=new f(e,this.getTz());n.ms=0;let s=new f(this._states.once,this.getTz());return s.ms=0,n.getTime()===s.getTime()}let t=new f(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this._nextTarget(this._states.currentRun,new Date)!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=new Date,n=this._nextTarget(e,t);return n?n.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=w.indexOf(this);e>=0&&w.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let n=t??new Date,s=this._nextTarget(void 0,n),i=s?s.getTime()-n.getTime():null,a=this._states.currentRun;a&&a.getTime()>n.getTime()&&(a=void 0);let o=this._nextTarget(a,n);return i===null||isNaN(i)||o===null?this:(i>$&&(i=$),i<0&&(i=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),i),this._states.currentTimeout&&this.options.unref&&j(this._states.currentTimeout),this)}async _trigger(e=new Date){this._states.blocking=!0,this._states.currentRun=new f(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(C(this.options.catch))try{Promise.resolve(this.options.catch(t,this)).catch(()=>{})}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new f(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,n=!this._states.paused&&t.getTime()>=e.getTime(),s=this._states.blocking&&this.options.protect;n&&!s?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):n&&s&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,n?void 0:t)}_next(e,t,n){let s=n?n.startAt:this._startAt,i=n?n.stopAt:this._stopAt,a=!!e,o=!!(e||this._states.currentRun),u=!1;!e&&s&&this.options.interval&&(e=this._calculatePreviousRun(s,t),e&&(o=!0),u=!e);let l=e??t??new Date,h=this._toMs(l);e=new f(l,this.getTz()),s&&h<s.getTime()&&(e=u?s:new f(new Date(s.getTime()-1e3),this.getTz()),h=e.getTime());let c=this._states.once||new f(e,this.getTz());if(!u&&c!==this._states.once&&(c=this._findOccurrence(e,h,1,o)),this._states.once){let d=this._states.once.getTime(),p=h-d;if(s&&d<s.getTime()-this._startAtRoundingMs||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?p>=0:p>1e3&&!this.options.allowPast))return null}return c===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||i&&c.getTime()>=i.getTime()?null:c}_previous(e,t){let n=this._toMs(e??new Date);if(t.stopAt&&n>t.stopAt.getTime()&&(n=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<n?this._states.once:null;let s=this._findOccurrence(new f(new Date(n),this.getTz()),n,-1);return s===null||t.startAt&&s.getTime()<t.startAt.getTime()?null:s}_toMs(e){return e instanceof Date?e.getTime():new f(e,this.getTz()).getTime()}_findOccurrence(e,t,n,s=!1){let i=this.options.interval??0;if(i>1&&(n===-1||s)){t+=(i-1)*1e3*n;let c=new Date(t).getUTCFullYear();if(!(c>=1&&c<=9999))return null;e=new f(new Date(t),this.getTz()),s=!1}let a=this._walk(e,t,n,s),o=this.getTz();if(this._states.pattern.isFixedTime&&n===1||typeof o=="number"||z(t,o)!==(n===1?"earlier":"later"))return a;let u=Math.floor(t/1e3)*1e3,l=n===1?R(u,u+E,o):R(u-E,u,o)-1e3;if(a&&(l-a.getTime())*n>0)return a;let h=this._walk(new f(new Date(l),o),l-n,n,!1,!0);return!a||!h?a??h:(a.getTime()-h.getTime())*n>0?h:a}_walk(e,t,n,s,i=!1){let a=this._states.pattern,o=(l,h)=>n===1?l.increment(a,this.options,h):l.decrement(a,this.options,h),u=new f(e,this.getTz());for((!i||!u.match(a,this.options))&&(u=o(u,s));u;){let l=this._runAt(u,t,n);if(l)return new f(l,this.getTz());u=o(u,!1)}return null}_runAt(e,t,n){let s=d=>(d.getTime()-t)*n>0,i=e.tz;if(typeof i=="number"){let d=e.getDate();return s(d)?d:null}let a=T(e.year,e.month+1,e.day,e.hour,e.minute,e.second,i),o=k(a),u=this._states.pattern.isFixedTime;if(o.kind==="single")return s(o.date)?o.date:null;if(o.kind==="ambiguous"){let{earlier:d,later:p}=o;return(u?[d]:n===1?[d,p]:[p,d]).find(s)??null}if(!u)return null;let l=new Date(R(o.before.getTime(),o.after.getTime(),i)),h=y(l,i);return h.y===a.y&&h.m===a.m&&h.d===a.d&&s(l)?l:null}_calculatePreviousRun(e,t){let n=new f(t,this.getTz()).getTime();if(e.getTime()>n)return;let s=this.options.interval*1e3,i=e;for(;i.getTime()+s<=n;){let a=this._findOccurrence(i,i.getTime(),1,!0);if(a===null)break;i=a}return i}},O=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.runsLeft()??1/0,this.reset(t)}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron._nextTarget(this.cursor,this.now);return e===null?(this.done=!0,{value:void 0,done:!0}):(this.cursor=e,this.remainingRuns--,{value:e,done:!1})}peek(){return this.done||this.remainingRuns<=0?null:this.cron._nextTarget(this.cursor,this.now)}reset(e){this.cursor=e instanceof Date?new Date(e.getTime()):e??void 0,this.now=new Date,this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}};0&&(module.exports={Cron,CronDate,CronIterator,CronPattern,scheduledJobs});
1
+ var O=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var B=(r,e)=>{for(var t in e)O(r,t,{get:e[t],enumerable:!0})},J=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of H(e))!V.call(r,s)&&s!==t&&O(r,s,{get:()=>e[s],enumerable:!(n=Z(e,s))||n.enumerable});return r};var G=r=>J(O({},"__esModule",{value:!0}),r);var X={};B(X,{Cron:()=>S,CronDate:()=>f,CronIterator:()=>M,CronPattern:()=>b,scheduledJobs:()=>w});module.exports=G(X);function g(r,e,t,n=0,s=0,i=0,a=0){let o=r>=0&&r<100,u=Date.UTC(o?r+400:r,e,t,n,s,i,a);return o?u-126227808e5:u}function v(r){return g(r.y,r.m-1,r.d,r.h,r.i,r.s)}function D(r,e){return r.y===e.y&&r.m===e.m&&r.d===e.d&&r.h===e.h&&r.i===e.i&&r.s===e.s}function x(r){let e=r.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function K(r,e){let t=new Date(Date.parse(r));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return x(r)?{tp:T(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"),ms:t.getUTCMilliseconds()}:{tp:T(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e),ms:t.getMilliseconds()}}function _(r,e,t){let{tp:n,ms:s}=K(r,e);return new Date(P(n,t).getTime()+s)}function P(r,e){let t=k(r);if(t.kind==="single")return t.date;if(t.kind==="ambiguous")return t.earlier;if(e)throw new Error("Invalid date passed to fromTZ()");return t.after}function k(r){let e=v(r),t=a=>N(new Date(a),r.tz),n=e-t(e),s=y(new Date(n),r.tz);if(D(s,r)){let a=v(s)-n,o=n-(t(n-U)-a);if(o<n&&D(y(new Date(o),r.tz),r))return{kind:"ambiguous",earlier:new Date(o),later:new Date(n)};let u=n+(a-t(n+U));return u>n&&D(y(new Date(u),r.tz),r)?{kind:"ambiguous",earlier:new Date(n),later:new Date(u)}:{kind:"single",date:new Date(n)}}let i=e-(v(s)-n);return D(y(new Date(i),r.tz),r)?{kind:"single",date:new Date(i)}:{kind:"gap",before:new Date(Math.min(n,i)),after:new Date(Math.max(n,i))}}var U=3*36e5;function N(r,e){return v(y(r,e))-(r.getTime()-r.getUTCMilliseconds())}function R(r,e,t){let n=N(new Date(r),t);for(;e-r>1e3;){let s=r+Math.floor((e-r)/2e3)*1e3;N(new Date(s),t)===n?r=s:e=s}return e}function z(r,e){let t=k(y(new Date(r),e));if(t.kind==="ambiguous")return r<t.later.getTime()?"earlier":"later"}var W=new Map;function y(r,e){if(e===void 0)return T(r.getFullYear(),r.getMonth()+1,r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds());let t=W.get(e),n;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),W.set(e,t)),n=t.formatToParts(r)}catch(i){let a=i instanceof Error?i.message:String(i);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`)}let s={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of n)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(s[i.type]=parseInt(i.value,10));if(isNaN(s.year)||isNaN(s.month)||isNaN(s.day)||isNaN(s.hour)||isNaN(s.minute)||isNaN(s.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(s)}`);return s.hour===24&&(s.hour=0),{y:s.year,m:s.month,d:s.day,h:s.hour,i:s.minute,s:s.second,tz:e}}function T(r,e,t,n,s,i,a){return{y:r,m:e,d:t,h:n,i:s,s:i,tz:a}}var A=[1,2,4,8,16],b=class r{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;fixedTimeRule;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;isFixedTime;constructor(e,t,n){this.pattern=e,this.timezone=t,this.mode=n?.mode??"auto",this.alternativeWeekdays=n?.alternativeWeekdays??!1,this.sloppyRanges=n?.sloppyRanges??!1,this.fixedTimeRule=n?.fixedTimeRule??"single-value",this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=[],this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.isFixedTime=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let a;switch(this.mode){case"5-part":a=5;break;case"6-part":a=6;break;case"7-part":a=7;break;case"5-or-6-parts":a=[5,6];break;case"6-or-7-parts":a=[6,7];break;default:a=0}if(!(Array.isArray(a)?a.includes(t):t===a)){let u=Array.isArray(a)?a.join(" or "):a.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${u} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let a=0;a<e.length;a++)e[a]=e[a].replace(/\?/g,"*");if(e[3].toUpperCase()==="LW")this.lastWeekday=!0,e[3]="";else if(e[3].toUpperCase().indexOf("L")>=0){let a=e[3].split(",");if(a.some(o=>o===""||o.toUpperCase()!=="L"&&/l/i.test(o)))throw new TypeError("CronPattern: Syntax error, L has to be a value of its own in day-of-month ('"+e[3]+"').");e[3]=a.filter(o=>o.toUpperCase()!=="L").join(","),this.lastDayOfMonth=!0}if(e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlpha(e[4],r.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],r.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],r.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let n=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],n,63),e[6]==="*"?this.year=Array(1e4).fill(1):(this.year=Array(1e4).fill(0),this.partToArray("year",e[6],0,1)),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let s=this.fixedTimeRule==="single-value",i=(a,o)=>!a.includes("*")&&!a.includes("/")&&(!s||o.filter(u=>u).length===1);this.isFixedTime=i(e[0],this.second)&&i(e[1],this.minute)&&i(e[2],this.hour)}partToArray(e,t,n,s){let i=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(s);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,n,s);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,n,s):t.includes("-")?this.handleRange(t,e,n,s):t.includes("/")?this.handleStepping(t,e,n,s):t!==""&&this.handleNumber(t,e,n,s)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,n,s){let i=this.extractNth(e,t),a=e.toUpperCase().includes("W");if(t!=="day"&&a)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");a&&(t="nearestWeekdays");let o=a?i[0].replace(/W$/i,""):i[0],u=r.toNumber(o)+n;if(isNaN(u))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,u,i[1]||s)}setPart(e,t,n){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,n);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=n}static toNumber(e){return/^\d+$/.test(e)?parseInt(e,10):NaN}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,n,s,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(n!==void 0){if(n===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(n>this[s].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[s].length+")")}}handleRangeWithStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let i=this.extractNth(e,t),a=i[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,l]=a,h=parseInt(o,10)+n,c=parseInt(u,10)+n,d=parseInt(l,10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(c,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(h,c,d,t,e);for(let p=h;p<=c;p+=d)this.setPart(t,p,i[1]||s)}extractNth(e,t){let n=e,s;if(n.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");let i=n.split("#");if(i.length!==2||i[1]==="")throw new TypeError("CronPattern: Syntax error, illegal nth weekday: '"+e+"'");n=i[0],s=i[1]}else if(n.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");s="L",n=n.slice(0,-1)}return[n,s]}handleRange(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let i=this.extractNth(e,t),a=i[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=r.toNumber(a[0])+n,u=r.toNumber(a[1])+n;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,u,void 0,t,e);for(let l=o;l<=u;l++)this.setPart(t,l,i[1]||s)}handleStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let i=this.extractNth(e,t),a=i[0].split("/");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)a[0]===""&&(a[0]="*");else{if(a[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(a[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;a[0]!=="*"&&(o=r.toNumber(a[0])+n,this.validateNotNaN(o,"CronPattern: Syntax error, illegal stepping start (NaN)"));let u=r.toNumber(a[1]);this.validateNotNaN(u,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,u,t,e);for(let l=o;l<this[t].length;l+=u)t==="year"&&l===0||this.setPart(t,l,i[1]||s)}replaceAlpha(e,t){let n=e;for(let[s,i]of Object.entries(t))n=n.replace(new RegExp(s,"gi"),(a,o,u)=>{let l=o+a.length-3,h=u.charAt(l-1),c=u.charAt(l+3);if(/[a-z\d/#]/i.test(h)||/[a-km-z\d]/i.test(c))throw new TypeError(`CronPattern: Syntax error, a month or day name has to stand alone ('${e}').`);return i});return n}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * SUN","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return r.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|A[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var Q=[31,28,31,30,31,30,31,31,30,31,30,31],m=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],f=class r{tz;instantMs;instantFields;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof r)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?Q[t]:new Date(g(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let n=this.getLastDayOfMonth(e,t),i=new Date(g(e,t,n)).getUTCDay();return i===0?n-2:i===6?n-1:n}getNearestWeekday(e,t,n){let s=this.getLastDayOfMonth(e,t);if(n>s)return-1;let a=new Date(g(e,t,n)).getUTCDay();return a===0?n===s?n-2:n+1:a===6?n===1?n+2:n-1:n}isNthWeekdayOfMonth(e,t,n,s){let a=new Date(g(e,t,n)).getUTCDay(),o=0;for(let u=1;u<=n;u++)new Date(g(e,t,u)).getUTCDay()===a&&o++;if(s&63&&A[o-1]&s)return!0;if(s&32){let u=this.getLastDayOfMonth(e,t);for(let l=n+1;l<=u;l++)if(new Date(g(e,t,l)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=y(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.cacheInstant(e.getTime()-this.ms)}catch(t){let n=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${n}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear(),this.cacheInstant(e.getTime()-this.ms)}cacheInstant(e){this.instantMs=e;let{year:t,month:n,day:s,hour:i,minute:a,second:o}=this;this.instantFields=[t,n,s,i,a,o,this.tz]}cachedInstant(){let e=this.instantFields;if(!(e===void 0||e[6]!==this.tz)&&!(e[5]!==this.second||e[4]!==this.minute||e[3]!==this.hour)&&!(e[2]!==this.day||e[1]!==this.month||e[0]!==this.year))return this.instantMs}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms,this.instantMs=e.instantMs,this.instantFields=e.instantFields}apply(){if(this.month>11||this.month<0||this.day>this.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(0);return e.setUTCFullYear(this.year,this.month,this.day),e.setUTCHours(this.hour,this.minute,this.second,this.ms),this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){if(x(e))return this.fromDate(_(e));let t=_(e,"Etc/UTC");this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(_(e,this.tz))}findNext(e,t,n,s){return this._findMatch(e,t,n,s,1)}_matchDayValue(e,t,n,s){let i=e;if(!i){for(let a=0;a<n.nearestWeekdays.length;a++)if(n.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){i=1;break}}}if(n.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(i=1)}if(n.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(i=1)}if(!n.starDOW){let a=new Date(g(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=n.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),n.useAndLogic?i=i&&o:!s.domAndDow&&!n.starDOM?i=i||o:i=i&&o}return i}_findMatch(e,t,n,s,i){let a=this[t],o=t==="day"?this.getLastDayOfMonth(this.year,this.month):0,u=this[t]+s,l=i===1?h=>h<n[t].length:h=>h>=0;for(let h=u;l(h);h+=i){let c=n[t][h];if(t==="day"){if(h-s>o)continue;c=this._matchDayValue(c,h-s,n,e)}if(c)return this[t]=h-s,a!==this[t]?2:1}return 3}recurse(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseStep(e,t,i)}return i}recurseStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let s=this.findNext(t,m[n][0],e,m[n][2]);if(s>1){let i=n+1;for(;i<m.length;)this[m[i][0]]=-m[i][2],i++;if(s===3){if(this[m[n][1]]++,this[m[n][0]]=-m[n][2],this.apply(),n===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return 0}else if(this.apply())return n-1}return n+=1,n>=m.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:n}increment(e,t,n){return this.instantMs=void 0,this.instantFields=void 0,this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t,n=!0){this.instantMs=void 0,this.instantFields=void 0;let s=t.interval!==void 0&&t.interval>1;return(this.ms===0||s)&&(this.second-=s&&n?t.interval:1),this.ms=0,this.apply(),this.recurseBackward(e,t,0)}recurseBackward(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseBackwardStep(e,t,i)}return i}recurseBackwardStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let s=this.findPrevious(t,m[n][0],e,m[n][2]);if(s>1){let i=n+1;for(;i<m.length;){let a=m[i][0],o=m[i][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,i++}if(s===3){if(this[m[n][1]]--,n===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(n===1)if(this.day<=0)this.day=1;else{let u=this.year,l=this.month;for(;l<0;)l+=12,u--;for(;l>11;)l-=12,u++;let h=this.getLastDayOfMonth(u,l);this.day>h&&(this.day=h)}this.apply();let a=m[n][0],o=m[n][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),n===0){let u=m[1][2],l=this.getMaxPatternValue("day",e,u);l!==this.day&&(this.day=l,this.hour=this.getMaxPatternValue("hour",e,m[2][2]),this.minute=this.getMaxPatternValue("minute",e,m[3][2]),this.second=this.getMaxPatternValue("second",e,m[4][2]))}if(n===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return 0}else if(this.apply())return n-1}return n+=1,n>=m.length?this:this.year<0?null:n}getMaxPatternValue(e,t,n){let s=t[e].length-1-n;for(let i=t[e].length-1;i>=0;i--)if(t[e][i]){s=i-n;break}if(e==="day"){let i=this.getLastDayOfMonth(this.year,this.month);return t.lastWeekday||t.nearestWeekdays.some(a=>a)||t.lastDayOfMonth||!t.starDOW?i:Math.min(s,i)}return s}findPrevious(e,t,n,s){return this._findMatch(e,t,n,s,-1)}getDate(e){if(!e&&typeof this.tz!="number"){let t=this.cachedInstant();if(t!==void 0)return new Date(t+(this.tz===void 0?this.ms:0))}if(e||this.tz===void 0){if(this.year>=0&&this.year<100){let t=new Date(0);return t.setFullYear(this.year,this.month,this.day),t.setHours(this.hour,this.minute,this.second,this.ms),t}return new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms)}else return typeof this.tz=="number"?new Date(g(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):P(T(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let n=0;n<m.length;n++){let s=m[n][0],i=m[n][2],a=this[s];if(a+i<0||a+i>=e[s].length)return!1;let o=e[s][a+i];if(s==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}};function L(r){r===void 0&&(r={}),delete r.name,r.legacyMode!==void 0&&r.domAndDow===void 0?r.domAndDow=!r.legacyMode:r.domAndDow===void 0&&(r.domAndDow=!1),r.legacyMode=!r.domAndDow;let e=(n,s)=>n===void 0?s:n;if(r.paused=e(r.paused,!1),r.maxRuns=e(r.maxRuns,1/0),r.catch=e(r.catch,!1),r.unref=e(r.unref,!1),r.mode=e(r.mode,"auto"),r.alternativeWeekdays=e(r.alternativeWeekdays,!1),r.sloppyRanges=e(r.sloppyRanges,!1),r.fixedTimeRule=e(r.fixedTimeRule,"single-value"),r.allowPast=e(r.allowPast,!1),r.interval=r.interval===void 0?0:parseInt(r.interval.toString(),10),r.utcOffset=r.utcOffset===void 0?void 0:parseInt(r.utcOffset.toString(),10),r.dayOffset=r.dayOffset===void 0?0:parseInt(r.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(r.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");if(!["single-value","no-wildcard"].includes(r.fixedTimeRule))throw new Error("CronOptions: fixedTimeRule must be one of 'single-value' or 'no-wildcard'.");r.timezone===""&&(r.timezone=void 0);let t=r.timezone??r.utcOffset;if(r.startAt&&(r.startAt=F(new f(r.startAt,t))),r.stopAt&&(r.stopAt=F(new f(r.stopAt,t))),r.interval!==null){if(isNaN(r.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(r.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(r.utcOffset!==void 0){if(isNaN(r.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(r.utcOffset<-870||r.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(r.utcOffset!==void 0&&r.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(r.unref!==!0&&r.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(r.dayOffset!==void 0&&r.dayOffset!==0&&isNaN(r.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return r}function F(r){return r.ms?(r.ms=0,new f(new Date(r.getTime()+1e3),r.tz)):r}function C(r){return typeof r=="function"}function Y(r){return C(r)}function $(r){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(r):r&&typeof r.unref<"u"&&r.unref()}var E=1440*60*1e3,j=30*1e3,w=[],S=class{name;options;_states;fn;_startAtRoundingMs=0;getTz(){return this.options.timezone??this.options.utcOffset}applyDayOffset(e){let t=this._offsetMs();return t?new Date(e.getTime()+t):e}_offsetMs(){return(this.options.dayOffset??0)*E}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let n=this._offsetMs(),s=this._next(this._shift(e),new Date(t.getTime()-n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return s?this.applyDayOffset(s.getDate(!1)):null}_previousTarget(e,t){let n=this._toMs(e??t)-this._offsetMs(),s=this._previous(new Date(n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return s?this.applyDayOffset(s.getDate(!1)):null}_shift(e){if(e!=null)return new f(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,n){let s,i;if(C(t))i=t;else if(typeof t=="object")s=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(C(n))i=n;else if(typeof n=="object")s=n;else if(n!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");this.name=s?.name;let a=s?.startAt;this.options=L(s),a&&this._startAt&&(this._startAtRoundingMs=this._startAt.getTime()-new f(a,this.getTz()).getTime());let o=!!e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0);if(this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:s?s.maxRuns:void 0,paused:s?s.paused:!1,pattern:o?new b("* * * * *",void 0,{mode:"auto"}):new b(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges,fixedTimeRule:this.options.fixedTimeRule})},o&&(this._states.once=new f(e,this.getTz())),this.name){if(w.find(l=>l.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");w.push(this)}return i!==void 0&&Y(i)&&(this.fn=i,this.schedule()),this}nextRun(e){return this._nextTarget(e,new Date)}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let n=t||this._states.currentRun||void 0;return this._enumerateRuns(e,n,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new M(this,e)}_enumerateRuns(e,t,n){let s=[],i=new Date,a=t;for(;e-- >0;){let o=n==="next"?this._nextTarget(a,i):this._previousTarget(a,i);if(!o)break;s.push(o),a=o}return s}match(e){if(this._states.once){let n=new f(e,this.getTz());n.ms=0;let s=new f(this._states.once,this.getTz());return s.ms=0,n.getTime()===s.getTime()}let t=new f(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this._nextTarget(this._states.currentRun,new Date)!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=new Date,n=this._nextTarget(e,t);return n?n.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=w.indexOf(this);e>=0&&w.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let n=t??new Date,s=this._nextTarget(void 0,n),i=s?s.getTime()-n.getTime():null,a=this._states.currentRun;a&&a.getTime()>n.getTime()&&(a=void 0);let o=this._nextTarget(a,n);return i===null||isNaN(i)||o===null?this:(i>j&&(i=j),i<0&&(i=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),i),this._states.currentTimeout&&this.options.unref&&$(this._states.currentTimeout),this)}async _trigger(e=new Date){this._states.blocking=!0,this._states.currentRun=new f(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(C(this.options.catch))try{Promise.resolve(this.options.catch(t,this)).catch(()=>{})}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new f(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,n=!this._states.paused&&t.getTime()>=e.getTime(),s=this._states.blocking&&this.options.protect;n&&!s?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):n&&s&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,n?void 0:t)}_next(e,t,n){let s=n?n.startAt:this._startAt,i=n?n.stopAt:this._stopAt,a=!!e,o=!!(e||this._states.currentRun),u=!1;!e&&s&&this.options.interval&&(e=this._calculatePreviousRun(s,t),e&&(o=!0),u=!e);let l=e??t??new Date,h=this._toMs(l);e=new f(l,this.getTz()),s&&h<s.getTime()&&(e=u?s:new f(new Date(s.getTime()-1e3),this.getTz()),h=e.getTime());let c=this._states.once||new f(e,this.getTz());if(!u&&c!==this._states.once&&(c=this._findOccurrence(e,h,1,o)),this._states.once){let d=this._states.once.getTime(),p=h-d;if(s&&d<s.getTime()-this._startAtRoundingMs||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?p>=0:p>1e3&&!this.options.allowPast))return null}return c===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||i&&c.getTime()>=i.getTime()?null:c}_previous(e,t){let n=this._toMs(e??new Date);if(t.stopAt&&n>t.stopAt.getTime()&&(n=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<n?this._states.once:null;let s=this._findOccurrence(new f(new Date(n),this.getTz()),n,-1);return s===null||t.startAt&&s.getTime()<t.startAt.getTime()?null:s}_toMs(e){if(e instanceof Date)return e.getTime();let t=new f(e,this.getTz());return t.getTime()+(typeof t.tz=="string"?t.ms:0)}_findOccurrence(e,t,n,s=!1){let i=this.options.interval??0;if(i>1&&(n===-1||s)){t+=(i-1)*1e3*n;let c=new Date(t).getUTCFullYear();if(!(c>=1&&c<=9999))return null;e=new f(new Date(t),this.getTz()),s=!1}let a=this._walk(e,t,n,s),o=this.getTz();if(this._states.pattern.isFixedTime&&n===1||typeof o=="number"||z(t,o)!==(n===1?"earlier":"later"))return a;let u=Math.floor(t/1e3)*1e3,l=n===1?R(u,u+E,o):R(u-E,u,o)-1e3;if(a&&(l-a.getTime())*n>0)return a;let h=this._walk(new f(new Date(l),o),l-n,n,!1,!0);return!a||!h?a??h:(a.getTime()-h.getTime())*n>0?h:a}_walk(e,t,n,s,i=!1){let a=this._states.pattern,o=(l,h)=>n===1?l.increment(a,this.options,h):l.decrement(a,this.options,h),u=new f(e,this.getTz());for((!i||!u.match(a,this.options))&&(u=o(u,s));u;){let l=this._runAt(u,t,n);if(l)return new f(l,this.getTz());u=o(u,!1)}return null}_runAt(e,t,n){let s=d=>(d.getTime()-t)*n>0,i=e.tz;if(typeof i=="number"){let d=e.getDate();return s(d)?d:null}let a=T(e.year,e.month+1,e.day,e.hour,e.minute,e.second,i),o=k(a),u=this._states.pattern.isFixedTime;if(o.kind==="single")return s(o.date)?o.date:null;if(o.kind==="ambiguous"){let{earlier:d,later:p}=o;return(u?[d]:n===1?[d,p]:[p,d]).find(s)??null}if(!u)return null;let l=new Date(R(o.before.getTime(),o.after.getTime(),i)),h=y(l,i);return h.y===a.y&&h.m===a.m&&h.d===a.d&&s(l)?l:null}_calculatePreviousRun(e,t){let n=new f(t,this.getTz()).getTime();if(e.getTime()>n)return;let s=this.options.interval*1e3,i=e;for(;i.getTime()+s<=n;){let a=this._findOccurrence(i,i.getTime(),1,!0);if(a===null)break;i=a}return i}},M=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.runsLeft()??1/0,this.reset(t)}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron._nextTarget(this.cursor,this.now);return e===null?(this.done=!0,{value:void 0,done:!0}):(this.cursor=e,this.remainingRuns--,{value:e,done:!1})}peek(){return this.done||this.remainingRuns<=0?null:this.cron._nextTarget(this.cursor,this.now)}reset(e){this.cursor=e instanceof Date?new Date(e.getTime()):e??void 0,this.now=new Date,this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}};0&&(module.exports={Cron,CronDate,CronIterator,CronPattern,scheduledJobs});
package/dist/croner.d.cts CHANGED
@@ -132,11 +132,14 @@ declare class CronPattern {
132
132
  */
133
133
  private handleStepping;
134
134
  /**
135
- * Replace alpha names (day/month) with numeric values using a mapping.
135
+ * Replace alpha names (day/month) with numeric values using a mapping. A name has to stand
136
+ * alone, or SUN6 would be read as 6 and JANFEB as 12.
136
137
  *
137
138
  * @param conf Current part, expected to be a string that might contain alpha names.
138
139
  * @param mapping Object mapping names to their numeric string replacements.
139
140
  * @returns Conf with alpha names replaced by numbers.
141
+ * @throws If a name is next to a letter, a digit, a slash or a hash. Only an L can follow a
142
+ * name, as in FRIL.
140
143
  */
141
144
  private replaceAlpha;
142
145
  /**
@@ -668,7 +671,8 @@ declare class Cron<T = undefined> {
668
671
  */
669
672
  nextRuns(n: number, previous?: Date | string): Date[];
670
673
  /**
671
- * Find previous n runs, based on supplied date. Strips milliseconds.
674
+ * Find previous n runs before the supplied date (at least `interval` seconds before, if set). A
675
+ * run earlier in the same second as the reference is included.
672
676
  *
673
677
  * @param n - Number of runs to enumerate
674
678
  * @param reference - Date to start from (defaults to now)
package/dist/croner.d.ts CHANGED
@@ -132,11 +132,14 @@ declare class CronPattern {
132
132
  */
133
133
  private handleStepping;
134
134
  /**
135
- * Replace alpha names (day/month) with numeric values using a mapping.
135
+ * Replace alpha names (day/month) with numeric values using a mapping. A name has to stand
136
+ * alone, or SUN6 would be read as 6 and JANFEB as 12.
136
137
  *
137
138
  * @param conf Current part, expected to be a string that might contain alpha names.
138
139
  * @param mapping Object mapping names to their numeric string replacements.
139
140
  * @returns Conf with alpha names replaced by numbers.
141
+ * @throws If a name is next to a letter, a digit, a slash or a hash. Only an L can follow a
142
+ * name, as in FRIL.
140
143
  */
141
144
  private replaceAlpha;
142
145
  /**
@@ -668,7 +671,8 @@ declare class Cron<T = undefined> {
668
671
  */
669
672
  nextRuns(n: number, previous?: Date | string): Date[];
670
673
  /**
671
- * Find previous n runs, based on supplied date. Strips milliseconds.
674
+ * Find previous n runs before the supplied date (at least `interval` seconds before, if set). A
675
+ * run earlier in the same second as the reference is included.
672
676
  *
673
677
  * @param n - Number of runs to enumerate
674
678
  * @param reference - Date to start from (defaults to now)
package/dist/croner.js CHANGED
@@ -1 +1 @@
1
- function g(r,e,t,n=0,s=0,i=0,a=0){let o=r>=0&&r<100,u=Date.UTC(o?r+400:r,e,t,n,s,i,a);return o?u-126227808e5:u}function D(r){return g(r.y,r.m-1,r.d,r.h,r.i,r.s)}function w(r,e){return r.y===e.y&&r.m===e.m&&r.d===e.d&&r.h===e.h&&r.i===e.i&&r.s===e.s}function M(r){let e=r.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function $(r,e){let t=new Date(Date.parse(r));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return M(r)?{tp:T(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"),ms:t.getUTCMilliseconds()}:{tp:T(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e),ms:t.getMilliseconds()}}function v(r,e,t){let{tp:n,ms:s}=$(r,e);return new Date(N(n,t).getTime()+s)}function N(r,e){let t=_(r);if(t.kind==="single")return t.date;if(t.kind==="ambiguous")return t.earlier;if(e)throw new Error("Invalid date passed to fromTZ()");return t.after}function _(r){let e=D(r),t=a=>O(new Date(a),r.tz),n=e-t(e),s=y(new Date(n),r.tz);if(w(s,r)){let a=D(s)-n,o=n-(t(n-E)-a);if(o<n&&w(y(new Date(o),r.tz),r))return{kind:"ambiguous",earlier:new Date(o),later:new Date(n)};let u=n+(a-t(n+E));return u>n&&w(y(new Date(u),r.tz),r)?{kind:"ambiguous",earlier:new Date(n),later:new Date(u)}:{kind:"single",date:new Date(n)}}let i=e-(D(s)-n);return w(y(new Date(i),r.tz),r)?{kind:"single",date:new Date(i)}:{kind:"gap",before:new Date(Math.min(n,i)),after:new Date(Math.max(n,i))}}var E=3*36e5;function O(r,e){return D(y(r,e))-(r.getTime()-r.getUTCMilliseconds())}function k(r,e,t){let n=O(new Date(r),t);for(;e-r>1e3;){let s=r+Math.floor((e-r)/2e3)*1e3;O(new Date(s),t)===n?r=s:e=s}return e}function U(r,e){let t=_(y(new Date(r),e));if(t.kind==="ambiguous")return r<t.later.getTime()?"earlier":"later"}var S=new Map;function y(r,e){if(e===void 0)return T(r.getFullYear(),r.getMonth()+1,r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds());let t=S.get(e),n;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),S.set(e,t)),n=t.formatToParts(r)}catch(i){let a=i instanceof Error?i.message:String(i);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`)}let s={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of n)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(s[i.type]=parseInt(i.value,10));if(isNaN(s.year)||isNaN(s.month)||isNaN(s.day)||isNaN(s.hour)||isNaN(s.minute)||isNaN(s.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(s)}`);return s.hour===24&&(s.hour=0),{y:s.year,m:s.month,d:s.day,h:s.hour,i:s.minute,s:s.second,tz:e}}function T(r,e,t,n,s,i,a){return{y:r,m:e,d:t,h:n,i:s,s:i,tz:a}}var x=[1,2,4,8,16],C=class r{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;fixedTimeRule;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;isFixedTime;constructor(e,t,n){this.pattern=e,this.timezone=t,this.mode=n?.mode??"auto",this.alternativeWeekdays=n?.alternativeWeekdays??!1,this.sloppyRanges=n?.sloppyRanges??!1,this.fixedTimeRule=n?.fixedTimeRule??"single-value",this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=[],this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.isFixedTime=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let a;switch(this.mode){case"5-part":a=5;break;case"6-part":a=6;break;case"7-part":a=7;break;case"5-or-6-parts":a=[5,6];break;case"6-or-7-parts":a=[6,7];break;default:a=0}if(!(Array.isArray(a)?a.includes(t):t===a)){let u=Array.isArray(a)?a.join(" or "):a.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${u} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let a=0;a<e.length;a++)e[a]=e[a].replace(/\?/g,"*");if(e[3].toUpperCase()==="LW")this.lastWeekday=!0,e[3]="";else if(e[3].toUpperCase().indexOf("L")>=0){let a=e[3].split(",");if(a.some(o=>o===""||o.toUpperCase()!=="L"&&/l/i.test(o)))throw new TypeError("CronPattern: Syntax error, L has to be a value of its own in day-of-month ('"+e[3]+"').");e[3]=a.filter(o=>o.toUpperCase()!=="L").join(","),this.lastDayOfMonth=!0}if(e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlpha(e[4],r.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],r.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],r.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let n=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],n,63),e[6]==="*"?this.year=Array(1e4).fill(1):(this.year=Array(1e4).fill(0),this.partToArray("year",e[6],0,1)),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let s=this.fixedTimeRule==="single-value",i=(a,o)=>!a.includes("*")&&!a.includes("/")&&(!s||o.filter(u=>u).length===1);this.isFixedTime=i(e[0],this.second)&&i(e[1],this.minute)&&i(e[2],this.hour)}partToArray(e,t,n,s){let i=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(s);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,n,s);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,n,s):t.includes("-")?this.handleRange(t,e,n,s):t.includes("/")?this.handleStepping(t,e,n,s):t!==""&&this.handleNumber(t,e,n,s)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,n,s){let i=this.extractNth(e,t),a=e.toUpperCase().includes("W");if(t!=="day"&&a)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");a&&(t="nearestWeekdays");let o=a?i[0].replace(/W$/i,""):i[0],u=r.toNumber(o)+n;if(isNaN(u))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,u,i[1]||s)}setPart(e,t,n){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,n);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=n}static toNumber(e){return/^\d+$/.test(e)?parseInt(e,10):NaN}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,n,s,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(n!==void 0){if(n===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(n>this[s].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[s].length+")")}}handleRangeWithStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let i=this.extractNth(e,t),a=i[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,l]=a,h=parseInt(o,10)+n,c=parseInt(u,10)+n,d=parseInt(l,10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(c,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(h,c,d,t,e);for(let p=h;p<=c;p+=d)this.setPart(t,p,i[1]||s)}extractNth(e,t){let n=e,s;if(n.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");let i=n.split("#");if(i.length!==2||i[1]==="")throw new TypeError("CronPattern: Syntax error, illegal nth weekday: '"+e+"'");n=i[0],s=i[1]}else if(n.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");s="L",n=n.slice(0,-1)}return[n,s]}handleRange(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let i=this.extractNth(e,t),a=i[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=r.toNumber(a[0])+n,u=r.toNumber(a[1])+n;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,u,void 0,t,e);for(let l=o;l<=u;l++)this.setPart(t,l,i[1]||s)}handleStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let i=this.extractNth(e,t),a=i[0].split("/");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)a[0]===""&&(a[0]="*");else{if(a[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(a[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;a[0]!=="*"&&(o=r.toNumber(a[0])+n,this.validateNotNaN(o,"CronPattern: Syntax error, illegal stepping start (NaN)"));let u=r.toNumber(a[1]);this.validateNotNaN(u,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,u,t,e);for(let l=o;l<this[t].length;l+=u)t==="year"&&l===0||this.setPart(t,l,i[1]||s)}replaceAlpha(e,t){let n=e;for(let[s,i]of Object.entries(t))n=n.replace(new RegExp(s,"gi"),i);return n}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * SUN","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return r.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|x[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var H=[31,28,31,30,31,30,31,31,30,31,30,31],f=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],m=class r{tz;instantMs;instantFields;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof r)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?H[t]:new Date(g(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let n=this.getLastDayOfMonth(e,t),i=new Date(g(e,t,n)).getUTCDay();return i===0?n-2:i===6?n-1:n}getNearestWeekday(e,t,n){let s=this.getLastDayOfMonth(e,t);if(n>s)return-1;let a=new Date(g(e,t,n)).getUTCDay();return a===0?n===s?n-2:n+1:a===6?n===1?n+2:n-1:n}isNthWeekdayOfMonth(e,t,n,s){let a=new Date(g(e,t,n)).getUTCDay(),o=0;for(let u=1;u<=n;u++)new Date(g(e,t,u)).getUTCDay()===a&&o++;if(s&63&&x[o-1]&s)return!0;if(s&32){let u=this.getLastDayOfMonth(e,t);for(let l=n+1;l<=u;l++)if(new Date(g(e,t,l)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=y(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.cacheInstant(e.getTime()-this.ms)}catch(t){let n=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${n}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear(),this.cacheInstant(e.getTime()-this.ms)}cacheInstant(e){this.instantMs=e;let{year:t,month:n,day:s,hour:i,minute:a,second:o}=this;this.instantFields=[t,n,s,i,a,o,this.tz]}cachedInstant(){let e=this.instantFields;if(!(e===void 0||e[6]!==this.tz)&&!(e[5]!==this.second||e[4]!==this.minute||e[3]!==this.hour)&&!(e[2]!==this.day||e[1]!==this.month||e[0]!==this.year))return this.instantMs}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms,this.instantMs=e.instantMs,this.instantFields=e.instantFields}apply(){if(this.month>11||this.month<0||this.day>this.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(0);return e.setUTCFullYear(this.year,this.month,this.day),e.setUTCHours(this.hour,this.minute,this.second,this.ms),this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){if(M(e))return this.fromDate(v(e));let t=v(e,"Etc/UTC");this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(v(e,this.tz))}findNext(e,t,n,s){return this._findMatch(e,t,n,s,1)}_matchDayValue(e,t,n,s){let i=e;if(!i){for(let a=0;a<n.nearestWeekdays.length;a++)if(n.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){i=1;break}}}if(n.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(i=1)}if(n.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(i=1)}if(!n.starDOW){let a=new Date(g(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=n.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),n.useAndLogic?i=i&&o:!s.domAndDow&&!n.starDOM?i=i||o:i=i&&o}return i}_findMatch(e,t,n,s,i){let a=this[t],o=t==="day"?this.getLastDayOfMonth(this.year,this.month):0,u=this[t]+s,l=i===1?h=>h<n[t].length:h=>h>=0;for(let h=u;l(h);h+=i){let c=n[t][h];if(t==="day"){if(h-s>o)continue;c=this._matchDayValue(c,h-s,n,e)}if(c)return this[t]=h-s,a!==this[t]?2:1}return 3}recurse(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseStep(e,t,i)}return i}recurseStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let s=this.findNext(t,f[n][0],e,f[n][2]);if(s>1){let i=n+1;for(;i<f.length;)this[f[i][0]]=-f[i][2],i++;if(s===3){if(this[f[n][1]]++,this[f[n][0]]=-f[n][2],this.apply(),n===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return 0}else if(this.apply())return n-1}return n+=1,n>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:n}increment(e,t,n){return this.instantMs=void 0,this.instantFields=void 0,this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t,n=!0){return this.instantMs=void 0,this.instantFields=void 0,this.second-=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0)}recurseBackward(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseBackwardStep(e,t,i)}return i}recurseBackwardStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let s=this.findPrevious(t,f[n][0],e,f[n][2]);if(s>1){let i=n+1;for(;i<f.length;){let a=f[i][0],o=f[i][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,i++}if(s===3){if(this[f[n][1]]--,n===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(n===1)if(this.day<=0)this.day=1;else{let u=this.year,l=this.month;for(;l<0;)l+=12,u--;for(;l>11;)l-=12,u++;let h=this.getLastDayOfMonth(u,l);this.day>h&&(this.day=h)}this.apply();let a=f[n][0],o=f[n][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),n===0){let u=f[1][2],l=this.getMaxPatternValue("day",e,u);l!==this.day&&(this.day=l,this.hour=this.getMaxPatternValue("hour",e,f[2][2]),this.minute=this.getMaxPatternValue("minute",e,f[3][2]),this.second=this.getMaxPatternValue("second",e,f[4][2]))}if(n===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return 0}else if(this.apply())return n-1}return n+=1,n>=f.length?this:this.year<0?null:n}getMaxPatternValue(e,t,n){let s=t[e].length-1-n;for(let i=t[e].length-1;i>=0;i--)if(t[e][i]){s=i-n;break}if(e==="day"){let i=this.getLastDayOfMonth(this.year,this.month);return t.lastWeekday||t.nearestWeekdays.some(a=>a)||t.lastDayOfMonth||!t.starDOW?i:Math.min(s,i)}return s}findPrevious(e,t,n,s){return this._findMatch(e,t,n,s,-1)}getDate(e){if(!e&&typeof this.tz!="number"){let t=this.cachedInstant();if(t!==void 0)return new Date(t+(this.tz===void 0?this.ms:0))}if(e||this.tz===void 0){if(this.year>=0&&this.year<100){let t=new Date(0);return t.setFullYear(this.year,this.month,this.day),t.setHours(this.hour,this.minute,this.second,this.ms),t}return new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms)}else return typeof this.tz=="number"?new Date(g(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):N(T(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let n=0;n<f.length;n++){let s=f[n][0],i=f[n][2],a=this[s];if(a+i<0||a+i>=e[s].length)return!1;let o=e[s][a+i];if(s==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}};function I(r){r===void 0&&(r={}),delete r.name,r.legacyMode!==void 0&&r.domAndDow===void 0?r.domAndDow=!r.legacyMode:r.domAndDow===void 0&&(r.domAndDow=!1),r.legacyMode=!r.domAndDow;let e=(n,s)=>n===void 0?s:n;if(r.paused=e(r.paused,!1),r.maxRuns=e(r.maxRuns,1/0),r.catch=e(r.catch,!1),r.unref=e(r.unref,!1),r.mode=e(r.mode,"auto"),r.alternativeWeekdays=e(r.alternativeWeekdays,!1),r.sloppyRanges=e(r.sloppyRanges,!1),r.fixedTimeRule=e(r.fixedTimeRule,"single-value"),r.allowPast=e(r.allowPast,!1),r.interval=r.interval===void 0?0:parseInt(r.interval.toString(),10),r.utcOffset=r.utcOffset===void 0?void 0:parseInt(r.utcOffset.toString(),10),r.dayOffset=r.dayOffset===void 0?0:parseInt(r.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(r.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");if(!["single-value","no-wildcard"].includes(r.fixedTimeRule))throw new Error("CronOptions: fixedTimeRule must be one of 'single-value' or 'no-wildcard'.");r.timezone===""&&(r.timezone=void 0);let t=r.timezone??r.utcOffset;if(r.startAt&&(r.startAt=z(new m(r.startAt,t))),r.stopAt&&(r.stopAt=z(new m(r.stopAt,t))),r.interval!==null){if(isNaN(r.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(r.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(r.utcOffset!==void 0){if(isNaN(r.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(r.utcOffset<-870||r.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(r.utcOffset!==void 0&&r.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(r.unref!==!0&&r.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(r.dayOffset!==void 0&&r.dayOffset!==0&&isNaN(r.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return r}function z(r){return r.ms?(r.ms=0,new m(new Date(r.getTime()+1e3),r.tz)):r}function b(r){return typeof r=="function"}function F(r){return b(r)}function L(r){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(r):r&&typeof r.unref<"u"&&r.unref()}var P=1440*60*1e3,Y=30*1e3,R=[],j=class{name;options;_states;fn;_startAtRoundingMs=0;getTz(){return this.options.timezone??this.options.utcOffset}applyDayOffset(e){let t=this._offsetMs();return t?new Date(e.getTime()+t):e}_offsetMs(){return(this.options.dayOffset??0)*P}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let n=this._offsetMs(),s=this._next(this._shift(e),new Date(t.getTime()-n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return s?this.applyDayOffset(s.getDate(!1)):null}_previousTarget(e,t){let n=this._previous(this._shift(e??t),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return n?this.applyDayOffset(n.getDate(!1)):null}_shift(e){if(e!=null)return new m(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,n){let s,i;if(b(t))i=t;else if(typeof t=="object")s=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(b(n))i=n;else if(typeof n=="object")s=n;else if(n!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");this.name=s?.name;let a=s?.startAt;this.options=I(s),a&&this._startAt&&(this._startAtRoundingMs=this._startAt.getTime()-new m(a,this.getTz()).getTime());let o=!!e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0);if(this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:s?s.maxRuns:void 0,paused:s?s.paused:!1,pattern:o?new C("* * * * *",void 0,{mode:"auto"}):new C(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges,fixedTimeRule:this.options.fixedTimeRule})},o&&(this._states.once=new m(e,this.getTz())),this.name){if(R.find(l=>l.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");R.push(this)}return i!==void 0&&F(i)&&(this.fn=i,this.schedule()),this}nextRun(e){return this._nextTarget(e,new Date)}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let n=t||this._states.currentRun||void 0;return this._enumerateRuns(e,n,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new A(this,e)}_enumerateRuns(e,t,n){let s=[],i=new Date,a=t;for(;e-- >0;){let o=n==="next"?this._nextTarget(a,i):this._previousTarget(a,i);if(!o)break;s.push(o),a=o}return s}match(e){if(this._states.once){let n=new m(e,this.getTz());n.ms=0;let s=new m(this._states.once,this.getTz());return s.ms=0,n.getTime()===s.getTime()}let t=new m(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this._nextTarget(this._states.currentRun,new Date)!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=new Date,n=this._nextTarget(e,t);return n?n.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=R.indexOf(this);e>=0&&R.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let n=t??new Date,s=this._nextTarget(void 0,n),i=s?s.getTime()-n.getTime():null,a=this._states.currentRun;a&&a.getTime()>n.getTime()&&(a=void 0);let o=this._nextTarget(a,n);return i===null||isNaN(i)||o===null?this:(i>Y&&(i=Y),i<0&&(i=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),i),this._states.currentTimeout&&this.options.unref&&L(this._states.currentTimeout),this)}async _trigger(e=new Date){this._states.blocking=!0,this._states.currentRun=new m(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(b(this.options.catch))try{Promise.resolve(this.options.catch(t,this)).catch(()=>{})}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new m(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,n=!this._states.paused&&t.getTime()>=e.getTime(),s=this._states.blocking&&this.options.protect;n&&!s?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):n&&s&&b(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,n?void 0:t)}_next(e,t,n){let s=n?n.startAt:this._startAt,i=n?n.stopAt:this._stopAt,a=!!e,o=!!(e||this._states.currentRun),u=!1;!e&&s&&this.options.interval&&(e=this._calculatePreviousRun(s,t),e&&(o=!0),u=!e);let l=e??t??new Date,h=this._toMs(l);e=new m(l,this.getTz()),s&&h<s.getTime()&&(e=u?s:new m(new Date(s.getTime()-1e3),this.getTz()),h=e.getTime());let c=this._states.once||new m(e,this.getTz());if(!u&&c!==this._states.once&&(c=this._findOccurrence(e,h,1,o)),this._states.once){let d=this._states.once.getTime(),p=h-d;if(s&&d<s.getTime()-this._startAtRoundingMs||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?p>=0:p>1e3&&!this.options.allowPast))return null}return c===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||i&&c.getTime()>=i.getTime()?null:c}_previous(e,t){let n=this._toMs(e??new Date);if(t.stopAt&&n>t.stopAt.getTime()&&(n=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<n?this._states.once:null;let s=this._findOccurrence(new m(new Date(n),this.getTz()),n,-1);return s===null||t.startAt&&s.getTime()<t.startAt.getTime()?null:s}_toMs(e){return e instanceof Date?e.getTime():new m(e,this.getTz()).getTime()}_findOccurrence(e,t,n,s=!1){let i=this.options.interval??0;if(i>1&&(n===-1||s)){t+=(i-1)*1e3*n;let c=new Date(t).getUTCFullYear();if(!(c>=1&&c<=9999))return null;e=new m(new Date(t),this.getTz()),s=!1}let a=this._walk(e,t,n,s),o=this.getTz();if(this._states.pattern.isFixedTime&&n===1||typeof o=="number"||U(t,o)!==(n===1?"earlier":"later"))return a;let u=Math.floor(t/1e3)*1e3,l=n===1?k(u,u+P,o):k(u-P,u,o)-1e3;if(a&&(l-a.getTime())*n>0)return a;let h=this._walk(new m(new Date(l),o),l-n,n,!1,!0);return!a||!h?a??h:(a.getTime()-h.getTime())*n>0?h:a}_walk(e,t,n,s,i=!1){let a=this._states.pattern,o=(l,h)=>n===1?l.increment(a,this.options,h):l.decrement(a,this.options,h),u=new m(e,this.getTz());for((!i||!u.match(a,this.options))&&(u=o(u,s));u;){let l=this._runAt(u,t,n);if(l)return new m(l,this.getTz());u=o(u,!1)}return null}_runAt(e,t,n){let s=d=>(d.getTime()-t)*n>0,i=e.tz;if(typeof i=="number"){let d=e.getDate();return s(d)?d:null}let a=T(e.year,e.month+1,e.day,e.hour,e.minute,e.second,i),o=_(a),u=this._states.pattern.isFixedTime;if(o.kind==="single")return s(o.date)?o.date:null;if(o.kind==="ambiguous"){let{earlier:d,later:p}=o;return(u?[d]:n===1?[d,p]:[p,d]).find(s)??null}if(!u)return null;let l=new Date(k(o.before.getTime(),o.after.getTime(),i)),h=y(l,i);return h.y===a.y&&h.m===a.m&&h.d===a.d&&s(l)?l:null}_calculatePreviousRun(e,t){let n=new m(t,this.getTz()).getTime();if(e.getTime()>n)return;let s=this.options.interval*1e3,i=e;for(;i.getTime()+s<=n;){let a=this._findOccurrence(i,i.getTime(),1,!0);if(a===null)break;i=a}return i}},A=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.runsLeft()??1/0,this.reset(t)}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron._nextTarget(this.cursor,this.now);return e===null?(this.done=!0,{value:void 0,done:!0}):(this.cursor=e,this.remainingRuns--,{value:e,done:!1})}peek(){return this.done||this.remainingRuns<=0?null:this.cron._nextTarget(this.cursor,this.now)}reset(e){this.cursor=e instanceof Date?new Date(e.getTime()):e??void 0,this.now=new Date,this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}};export{j as Cron,m as CronDate,A as CronIterator,C as CronPattern,R as scheduledJobs};
1
+ function g(r,e,t,n=0,s=0,i=0,a=0){let o=r>=0&&r<100,u=Date.UTC(o?r+400:r,e,t,n,s,i,a);return o?u-126227808e5:u}function D(r){return g(r.y,r.m-1,r.d,r.h,r.i,r.s)}function w(r,e){return r.y===e.y&&r.m===e.m&&r.d===e.d&&r.h===e.h&&r.i===e.i&&r.s===e.s}function O(r){let e=r.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function j(r,e){let t=new Date(Date.parse(r));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return O(r)?{tp:T(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"),ms:t.getUTCMilliseconds()}:{tp:T(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e),ms:t.getMilliseconds()}}function v(r,e,t){let{tp:n,ms:s}=j(r,e);return new Date(N(n,t).getTime()+s)}function N(r,e){let t=_(r);if(t.kind==="single")return t.date;if(t.kind==="ambiguous")return t.earlier;if(e)throw new Error("Invalid date passed to fromTZ()");return t.after}function _(r){let e=D(r),t=a=>M(new Date(a),r.tz),n=e-t(e),s=y(new Date(n),r.tz);if(w(s,r)){let a=D(s)-n,o=n-(t(n-E)-a);if(o<n&&w(y(new Date(o),r.tz),r))return{kind:"ambiguous",earlier:new Date(o),later:new Date(n)};let u=n+(a-t(n+E));return u>n&&w(y(new Date(u),r.tz),r)?{kind:"ambiguous",earlier:new Date(n),later:new Date(u)}:{kind:"single",date:new Date(n)}}let i=e-(D(s)-n);return w(y(new Date(i),r.tz),r)?{kind:"single",date:new Date(i)}:{kind:"gap",before:new Date(Math.min(n,i)),after:new Date(Math.max(n,i))}}var E=3*36e5;function M(r,e){return D(y(r,e))-(r.getTime()-r.getUTCMilliseconds())}function k(r,e,t){let n=M(new Date(r),t);for(;e-r>1e3;){let s=r+Math.floor((e-r)/2e3)*1e3;M(new Date(s),t)===n?r=s:e=s}return e}function U(r,e){let t=_(y(new Date(r),e));if(t.kind==="ambiguous")return r<t.later.getTime()?"earlier":"later"}var S=new Map;function y(r,e){if(e===void 0)return T(r.getFullYear(),r.getMonth()+1,r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds());let t=S.get(e),n;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),S.set(e,t)),n=t.formatToParts(r)}catch(i){let a=i instanceof Error?i.message:String(i);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`)}let s={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of n)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(s[i.type]=parseInt(i.value,10));if(isNaN(s.year)||isNaN(s.month)||isNaN(s.day)||isNaN(s.hour)||isNaN(s.minute)||isNaN(s.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(s)}`);return s.hour===24&&(s.hour=0),{y:s.year,m:s.month,d:s.day,h:s.hour,i:s.minute,s:s.second,tz:e}}function T(r,e,t,n,s,i,a){return{y:r,m:e,d:t,h:n,i:s,s:i,tz:a}}var x=[1,2,4,8,16],C=class r{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;fixedTimeRule;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;isFixedTime;constructor(e,t,n){this.pattern=e,this.timezone=t,this.mode=n?.mode??"auto",this.alternativeWeekdays=n?.alternativeWeekdays??!1,this.sloppyRanges=n?.sloppyRanges??!1,this.fixedTimeRule=n?.fixedTimeRule??"single-value",this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=[],this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.isFixedTime=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let a;switch(this.mode){case"5-part":a=5;break;case"6-part":a=6;break;case"7-part":a=7;break;case"5-or-6-parts":a=[5,6];break;case"6-or-7-parts":a=[6,7];break;default:a=0}if(!(Array.isArray(a)?a.includes(t):t===a)){let u=Array.isArray(a)?a.join(" or "):a.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${u} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let a=0;a<e.length;a++)e[a]=e[a].replace(/\?/g,"*");if(e[3].toUpperCase()==="LW")this.lastWeekday=!0,e[3]="";else if(e[3].toUpperCase().indexOf("L")>=0){let a=e[3].split(",");if(a.some(o=>o===""||o.toUpperCase()!=="L"&&/l/i.test(o)))throw new TypeError("CronPattern: Syntax error, L has to be a value of its own in day-of-month ('"+e[3]+"').");e[3]=a.filter(o=>o.toUpperCase()!=="L").join(","),this.lastDayOfMonth=!0}if(e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlpha(e[4],r.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],r.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],r.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let n=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],n,63),e[6]==="*"?this.year=Array(1e4).fill(1):(this.year=Array(1e4).fill(0),this.partToArray("year",e[6],0,1)),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let s=this.fixedTimeRule==="single-value",i=(a,o)=>!a.includes("*")&&!a.includes("/")&&(!s||o.filter(u=>u).length===1);this.isFixedTime=i(e[0],this.second)&&i(e[1],this.minute)&&i(e[2],this.hour)}partToArray(e,t,n,s){let i=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(s);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,n,s);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,n,s):t.includes("-")?this.handleRange(t,e,n,s):t.includes("/")?this.handleStepping(t,e,n,s):t!==""&&this.handleNumber(t,e,n,s)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,n,s){let i=this.extractNth(e,t),a=e.toUpperCase().includes("W");if(t!=="day"&&a)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");a&&(t="nearestWeekdays");let o=a?i[0].replace(/W$/i,""):i[0],u=r.toNumber(o)+n;if(isNaN(u))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,u,i[1]||s)}setPart(e,t,n){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,n);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=n}static toNumber(e){return/^\d+$/.test(e)?parseInt(e,10):NaN}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,n,s,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(n!==void 0){if(n===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(n>this[s].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[s].length+")")}}handleRangeWithStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let i=this.extractNth(e,t),a=i[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,l]=a,h=parseInt(o,10)+n,c=parseInt(u,10)+n,d=parseInt(l,10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(c,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(h,c,d,t,e);for(let p=h;p<=c;p+=d)this.setPart(t,p,i[1]||s)}extractNth(e,t){let n=e,s;if(n.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");let i=n.split("#");if(i.length!==2||i[1]==="")throw new TypeError("CronPattern: Syntax error, illegal nth weekday: '"+e+"'");n=i[0],s=i[1]}else if(n.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");s="L",n=n.slice(0,-1)}return[n,s]}handleRange(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let i=this.extractNth(e,t),a=i[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=r.toNumber(a[0])+n,u=r.toNumber(a[1])+n;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,u,void 0,t,e);for(let l=o;l<=u;l++)this.setPart(t,l,i[1]||s)}handleStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let i=this.extractNth(e,t),a=i[0].split("/");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)a[0]===""&&(a[0]="*");else{if(a[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(a[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;a[0]!=="*"&&(o=r.toNumber(a[0])+n,this.validateNotNaN(o,"CronPattern: Syntax error, illegal stepping start (NaN)"));let u=r.toNumber(a[1]);this.validateNotNaN(u,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,u,t,e);for(let l=o;l<this[t].length;l+=u)t==="year"&&l===0||this.setPart(t,l,i[1]||s)}replaceAlpha(e,t){let n=e;for(let[s,i]of Object.entries(t))n=n.replace(new RegExp(s,"gi"),(a,o,u)=>{let l=o+a.length-3,h=u.charAt(l-1),c=u.charAt(l+3);if(/[a-z\d/#]/i.test(h)||/[a-km-z\d]/i.test(c))throw new TypeError(`CronPattern: Syntax error, a month or day name has to stand alone ('${e}').`);return i});return n}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * SUN","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return r.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|x[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var H=[31,28,31,30,31,30,31,31,30,31,30,31],f=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],m=class r{tz;instantMs;instantFields;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof r)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?H[t]:new Date(g(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let n=this.getLastDayOfMonth(e,t),i=new Date(g(e,t,n)).getUTCDay();return i===0?n-2:i===6?n-1:n}getNearestWeekday(e,t,n){let s=this.getLastDayOfMonth(e,t);if(n>s)return-1;let a=new Date(g(e,t,n)).getUTCDay();return a===0?n===s?n-2:n+1:a===6?n===1?n+2:n-1:n}isNthWeekdayOfMonth(e,t,n,s){let a=new Date(g(e,t,n)).getUTCDay(),o=0;for(let u=1;u<=n;u++)new Date(g(e,t,u)).getUTCDay()===a&&o++;if(s&63&&x[o-1]&s)return!0;if(s&32){let u=this.getLastDayOfMonth(e,t);for(let l=n+1;l<=u;l++)if(new Date(g(e,t,l)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=y(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.cacheInstant(e.getTime()-this.ms)}catch(t){let n=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${n}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear(),this.cacheInstant(e.getTime()-this.ms)}cacheInstant(e){this.instantMs=e;let{year:t,month:n,day:s,hour:i,minute:a,second:o}=this;this.instantFields=[t,n,s,i,a,o,this.tz]}cachedInstant(){let e=this.instantFields;if(!(e===void 0||e[6]!==this.tz)&&!(e[5]!==this.second||e[4]!==this.minute||e[3]!==this.hour)&&!(e[2]!==this.day||e[1]!==this.month||e[0]!==this.year))return this.instantMs}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms,this.instantMs=e.instantMs,this.instantFields=e.instantFields}apply(){if(this.month>11||this.month<0||this.day>this.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(0);return e.setUTCFullYear(this.year,this.month,this.day),e.setUTCHours(this.hour,this.minute,this.second,this.ms),this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){if(O(e))return this.fromDate(v(e));let t=v(e,"Etc/UTC");this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(v(e,this.tz))}findNext(e,t,n,s){return this._findMatch(e,t,n,s,1)}_matchDayValue(e,t,n,s){let i=e;if(!i){for(let a=0;a<n.nearestWeekdays.length;a++)if(n.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){i=1;break}}}if(n.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(i=1)}if(n.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(i=1)}if(!n.starDOW){let a=new Date(g(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=n.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),n.useAndLogic?i=i&&o:!s.domAndDow&&!n.starDOM?i=i||o:i=i&&o}return i}_findMatch(e,t,n,s,i){let a=this[t],o=t==="day"?this.getLastDayOfMonth(this.year,this.month):0,u=this[t]+s,l=i===1?h=>h<n[t].length:h=>h>=0;for(let h=u;l(h);h+=i){let c=n[t][h];if(t==="day"){if(h-s>o)continue;c=this._matchDayValue(c,h-s,n,e)}if(c)return this[t]=h-s,a!==this[t]?2:1}return 3}recurse(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseStep(e,t,i)}return i}recurseStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let s=this.findNext(t,f[n][0],e,f[n][2]);if(s>1){let i=n+1;for(;i<f.length;)this[f[i][0]]=-f[i][2],i++;if(s===3){if(this[f[n][1]]++,this[f[n][0]]=-f[n][2],this.apply(),n===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return 0}else if(this.apply())return n-1}return n+=1,n>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:n}increment(e,t,n){return this.instantMs=void 0,this.instantFields=void 0,this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t,n=!0){this.instantMs=void 0,this.instantFields=void 0;let s=t.interval!==void 0&&t.interval>1;return(this.ms===0||s)&&(this.second-=s&&n?t.interval:1),this.ms=0,this.apply(),this.recurseBackward(e,t,0)}recurseBackward(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseBackwardStep(e,t,i)}return i}recurseBackwardStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let s=this.findPrevious(t,f[n][0],e,f[n][2]);if(s>1){let i=n+1;for(;i<f.length;){let a=f[i][0],o=f[i][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,i++}if(s===3){if(this[f[n][1]]--,n===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(n===1)if(this.day<=0)this.day=1;else{let u=this.year,l=this.month;for(;l<0;)l+=12,u--;for(;l>11;)l-=12,u++;let h=this.getLastDayOfMonth(u,l);this.day>h&&(this.day=h)}this.apply();let a=f[n][0],o=f[n][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),n===0){let u=f[1][2],l=this.getMaxPatternValue("day",e,u);l!==this.day&&(this.day=l,this.hour=this.getMaxPatternValue("hour",e,f[2][2]),this.minute=this.getMaxPatternValue("minute",e,f[3][2]),this.second=this.getMaxPatternValue("second",e,f[4][2]))}if(n===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return 0}else if(this.apply())return n-1}return n+=1,n>=f.length?this:this.year<0?null:n}getMaxPatternValue(e,t,n){let s=t[e].length-1-n;for(let i=t[e].length-1;i>=0;i--)if(t[e][i]){s=i-n;break}if(e==="day"){let i=this.getLastDayOfMonth(this.year,this.month);return t.lastWeekday||t.nearestWeekdays.some(a=>a)||t.lastDayOfMonth||!t.starDOW?i:Math.min(s,i)}return s}findPrevious(e,t,n,s){return this._findMatch(e,t,n,s,-1)}getDate(e){if(!e&&typeof this.tz!="number"){let t=this.cachedInstant();if(t!==void 0)return new Date(t+(this.tz===void 0?this.ms:0))}if(e||this.tz===void 0){if(this.year>=0&&this.year<100){let t=new Date(0);return t.setFullYear(this.year,this.month,this.day),t.setHours(this.hour,this.minute,this.second,this.ms),t}return new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms)}else return typeof this.tz=="number"?new Date(g(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):N(T(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let n=0;n<f.length;n++){let s=f[n][0],i=f[n][2],a=this[s];if(a+i<0||a+i>=e[s].length)return!1;let o=e[s][a+i];if(s==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}};function I(r){r===void 0&&(r={}),delete r.name,r.legacyMode!==void 0&&r.domAndDow===void 0?r.domAndDow=!r.legacyMode:r.domAndDow===void 0&&(r.domAndDow=!1),r.legacyMode=!r.domAndDow;let e=(n,s)=>n===void 0?s:n;if(r.paused=e(r.paused,!1),r.maxRuns=e(r.maxRuns,1/0),r.catch=e(r.catch,!1),r.unref=e(r.unref,!1),r.mode=e(r.mode,"auto"),r.alternativeWeekdays=e(r.alternativeWeekdays,!1),r.sloppyRanges=e(r.sloppyRanges,!1),r.fixedTimeRule=e(r.fixedTimeRule,"single-value"),r.allowPast=e(r.allowPast,!1),r.interval=r.interval===void 0?0:parseInt(r.interval.toString(),10),r.utcOffset=r.utcOffset===void 0?void 0:parseInt(r.utcOffset.toString(),10),r.dayOffset=r.dayOffset===void 0?0:parseInt(r.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(r.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");if(!["single-value","no-wildcard"].includes(r.fixedTimeRule))throw new Error("CronOptions: fixedTimeRule must be one of 'single-value' or 'no-wildcard'.");r.timezone===""&&(r.timezone=void 0);let t=r.timezone??r.utcOffset;if(r.startAt&&(r.startAt=z(new m(r.startAt,t))),r.stopAt&&(r.stopAt=z(new m(r.stopAt,t))),r.interval!==null){if(isNaN(r.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(r.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(r.utcOffset!==void 0){if(isNaN(r.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(r.utcOffset<-870||r.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(r.utcOffset!==void 0&&r.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(r.unref!==!0&&r.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(r.dayOffset!==void 0&&r.dayOffset!==0&&isNaN(r.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return r}function z(r){return r.ms?(r.ms=0,new m(new Date(r.getTime()+1e3),r.tz)):r}function b(r){return typeof r=="function"}function F(r){return b(r)}function L(r){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(r):r&&typeof r.unref<"u"&&r.unref()}var P=1440*60*1e3,Y=30*1e3,R=[],$=class{name;options;_states;fn;_startAtRoundingMs=0;getTz(){return this.options.timezone??this.options.utcOffset}applyDayOffset(e){let t=this._offsetMs();return t?new Date(e.getTime()+t):e}_offsetMs(){return(this.options.dayOffset??0)*P}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let n=this._offsetMs(),s=this._next(this._shift(e),new Date(t.getTime()-n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return s?this.applyDayOffset(s.getDate(!1)):null}_previousTarget(e,t){let n=this._toMs(e??t)-this._offsetMs(),s=this._previous(new Date(n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return s?this.applyDayOffset(s.getDate(!1)):null}_shift(e){if(e!=null)return new m(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,n){let s,i;if(b(t))i=t;else if(typeof t=="object")s=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(b(n))i=n;else if(typeof n=="object")s=n;else if(n!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");this.name=s?.name;let a=s?.startAt;this.options=I(s),a&&this._startAt&&(this._startAtRoundingMs=this._startAt.getTime()-new m(a,this.getTz()).getTime());let o=!!e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0);if(this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:s?s.maxRuns:void 0,paused:s?s.paused:!1,pattern:o?new C("* * * * *",void 0,{mode:"auto"}):new C(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges,fixedTimeRule:this.options.fixedTimeRule})},o&&(this._states.once=new m(e,this.getTz())),this.name){if(R.find(l=>l.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");R.push(this)}return i!==void 0&&F(i)&&(this.fn=i,this.schedule()),this}nextRun(e){return this._nextTarget(e,new Date)}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let n=t||this._states.currentRun||void 0;return this._enumerateRuns(e,n,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new A(this,e)}_enumerateRuns(e,t,n){let s=[],i=new Date,a=t;for(;e-- >0;){let o=n==="next"?this._nextTarget(a,i):this._previousTarget(a,i);if(!o)break;s.push(o),a=o}return s}match(e){if(this._states.once){let n=new m(e,this.getTz());n.ms=0;let s=new m(this._states.once,this.getTz());return s.ms=0,n.getTime()===s.getTime()}let t=new m(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this._nextTarget(this._states.currentRun,new Date)!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=new Date,n=this._nextTarget(e,t);return n?n.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=R.indexOf(this);e>=0&&R.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let n=t??new Date,s=this._nextTarget(void 0,n),i=s?s.getTime()-n.getTime():null,a=this._states.currentRun;a&&a.getTime()>n.getTime()&&(a=void 0);let o=this._nextTarget(a,n);return i===null||isNaN(i)||o===null?this:(i>Y&&(i=Y),i<0&&(i=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),i),this._states.currentTimeout&&this.options.unref&&L(this._states.currentTimeout),this)}async _trigger(e=new Date){this._states.blocking=!0,this._states.currentRun=new m(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(b(this.options.catch))try{Promise.resolve(this.options.catch(t,this)).catch(()=>{})}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new m(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,n=!this._states.paused&&t.getTime()>=e.getTime(),s=this._states.blocking&&this.options.protect;n&&!s?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):n&&s&&b(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,n?void 0:t)}_next(e,t,n){let s=n?n.startAt:this._startAt,i=n?n.stopAt:this._stopAt,a=!!e,o=!!(e||this._states.currentRun),u=!1;!e&&s&&this.options.interval&&(e=this._calculatePreviousRun(s,t),e&&(o=!0),u=!e);let l=e??t??new Date,h=this._toMs(l);e=new m(l,this.getTz()),s&&h<s.getTime()&&(e=u?s:new m(new Date(s.getTime()-1e3),this.getTz()),h=e.getTime());let c=this._states.once||new m(e,this.getTz());if(!u&&c!==this._states.once&&(c=this._findOccurrence(e,h,1,o)),this._states.once){let d=this._states.once.getTime(),p=h-d;if(s&&d<s.getTime()-this._startAtRoundingMs||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?p>=0:p>1e3&&!this.options.allowPast))return null}return c===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||i&&c.getTime()>=i.getTime()?null:c}_previous(e,t){let n=this._toMs(e??new Date);if(t.stopAt&&n>t.stopAt.getTime()&&(n=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<n?this._states.once:null;let s=this._findOccurrence(new m(new Date(n),this.getTz()),n,-1);return s===null||t.startAt&&s.getTime()<t.startAt.getTime()?null:s}_toMs(e){if(e instanceof Date)return e.getTime();let t=new m(e,this.getTz());return t.getTime()+(typeof t.tz=="string"?t.ms:0)}_findOccurrence(e,t,n,s=!1){let i=this.options.interval??0;if(i>1&&(n===-1||s)){t+=(i-1)*1e3*n;let c=new Date(t).getUTCFullYear();if(!(c>=1&&c<=9999))return null;e=new m(new Date(t),this.getTz()),s=!1}let a=this._walk(e,t,n,s),o=this.getTz();if(this._states.pattern.isFixedTime&&n===1||typeof o=="number"||U(t,o)!==(n===1?"earlier":"later"))return a;let u=Math.floor(t/1e3)*1e3,l=n===1?k(u,u+P,o):k(u-P,u,o)-1e3;if(a&&(l-a.getTime())*n>0)return a;let h=this._walk(new m(new Date(l),o),l-n,n,!1,!0);return!a||!h?a??h:(a.getTime()-h.getTime())*n>0?h:a}_walk(e,t,n,s,i=!1){let a=this._states.pattern,o=(l,h)=>n===1?l.increment(a,this.options,h):l.decrement(a,this.options,h),u=new m(e,this.getTz());for((!i||!u.match(a,this.options))&&(u=o(u,s));u;){let l=this._runAt(u,t,n);if(l)return new m(l,this.getTz());u=o(u,!1)}return null}_runAt(e,t,n){let s=d=>(d.getTime()-t)*n>0,i=e.tz;if(typeof i=="number"){let d=e.getDate();return s(d)?d:null}let a=T(e.year,e.month+1,e.day,e.hour,e.minute,e.second,i),o=_(a),u=this._states.pattern.isFixedTime;if(o.kind==="single")return s(o.date)?o.date:null;if(o.kind==="ambiguous"){let{earlier:d,later:p}=o;return(u?[d]:n===1?[d,p]:[p,d]).find(s)??null}if(!u)return null;let l=new Date(k(o.before.getTime(),o.after.getTime(),i)),h=y(l,i);return h.y===a.y&&h.m===a.m&&h.d===a.d&&s(l)?l:null}_calculatePreviousRun(e,t){let n=new m(t,this.getTz()).getTime();if(e.getTime()>n)return;let s=this.options.interval*1e3,i=e;for(;i.getTime()+s<=n;){let a=this._findOccurrence(i,i.getTime(),1,!0);if(a===null)break;i=a}return i}},A=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.runsLeft()??1/0,this.reset(t)}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron._nextTarget(this.cursor,this.now);return e===null?(this.done=!0,{value:void 0,done:!0}):(this.cursor=e,this.remainingRuns--,{value:e,done:!1})}peek(){return this.done||this.remainingRuns<=0?null:this.cron._nextTarget(this.cursor,this.now)}reset(e){this.cursor=e instanceof Date?new Date(e.getTime()):e??void 0,this.now=new Date,this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}};export{$ as Cron,m as CronDate,A as CronIterator,C as CronPattern,R as scheduledJobs};
@@ -1 +1 @@
1
- var Cron=(()=>{var T=(r,e,t)=>()=>{if(t)throw t[0];try{return r&&(e=r(r=0)),e}catch(n){throw t=[n],n}};var Q=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};function g(r,e,t,n=0,s=0,i=0,a=0){let o=r>=0&&r<100,u=Date.UTC(o?r+400:r,e,t,n,s,i,a);return o?u-126227808e5:u}var N=T(()=>{});function v(r){return g(r.y,r.m-1,r.d,r.h,r.i,r.s)}function D(r,e){return r.y===e.y&&r.m===e.m&&r.d===e.d&&r.h===e.h&&r.i===e.i&&r.s===e.s}function P(r){let e=r.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function X(r,e){let t=new Date(Date.parse(r));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return P(r)?{tp:b(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"),ms:t.getUTCMilliseconds()}:{tp:b(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e),ms:t.getMilliseconds()}}function _(r,e,t){let{tp:n,ms:s}=X(r,e);return new Date(A(n,t).getTime()+s)}function A(r,e){let t=k(r);if(t.kind==="single")return t.date;if(t.kind==="ambiguous")return t.earlier;if(e)throw new Error("Invalid date passed to fromTZ()");return t.after}function k(r){let e=v(r),t=a=>x(new Date(a),r.tz),n=e-t(e),s=p(new Date(n),r.tz);if(D(s,r)){let a=v(s)-n,o=n-(t(n-F)-a);if(o<n&&D(p(new Date(o),r.tz),r))return{kind:"ambiguous",earlier:new Date(o),later:new Date(n)};let u=n+(a-t(n+F));return u>n&&D(p(new Date(u),r.tz),r)?{kind:"ambiguous",earlier:new Date(n),later:new Date(u)}:{kind:"single",date:new Date(n)}}let i=e-(v(s)-n);return D(p(new Date(i),r.tz),r)?{kind:"single",date:new Date(i)}:{kind:"gap",before:new Date(Math.min(n,i)),after:new Date(Math.max(n,i))}}function x(r,e){return v(p(r,e))-(r.getTime()-r.getUTCMilliseconds())}function R(r,e,t){let n=x(new Date(r),t);for(;e-r>1e3;){let s=r+Math.floor((e-r)/2e3)*1e3;x(new Date(s),t)===n?r=s:e=s}return e}function Y(r,e){let t=k(p(new Date(r),e));if(t.kind==="ambiguous")return r<t.later.getTime()?"earlier":"later"}function p(r,e){if(e===void 0)return b(r.getFullYear(),r.getMonth()+1,r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds());let t=L.get(e),n;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),L.set(e,t)),n=t.formatToParts(r)}catch(i){let a=i instanceof Error?i.message:String(i);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`)}let s={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of n)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(s[i.type]=parseInt(i.value,10));if(isNaN(s.year)||isNaN(s.month)||isNaN(s.day)||isNaN(s.hour)||isNaN(s.minute)||isNaN(s.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(s)}`);return s.hour===24&&(s.hour=0),{y:s.year,m:s.month,d:s.day,h:s.hour,i:s.minute,s:s.second,tz:e}}function b(r,e,t,n,s,i,a){return{y:r,m:e,d:t,h:n,i:s,s:i,tz:a}}var F,L,E=T(()=>{N();F=3*36e5;L=new Map});var S,w,U=T(()=>{S=[1,2,4,8,16],w=class r{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;fixedTimeRule;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;isFixedTime;constructor(e,t,n){this.pattern=e,this.timezone=t,this.mode=n?.mode??"auto",this.alternativeWeekdays=n?.alternativeWeekdays??!1,this.sloppyRanges=n?.sloppyRanges??!1,this.fixedTimeRule=n?.fixedTimeRule??"single-value",this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=[],this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.isFixedTime=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let a;switch(this.mode){case"5-part":a=5;break;case"6-part":a=6;break;case"7-part":a=7;break;case"5-or-6-parts":a=[5,6];break;case"6-or-7-parts":a=[6,7];break;default:a=0}if(!(Array.isArray(a)?a.includes(t):t===a)){let u=Array.isArray(a)?a.join(" or "):a.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${u} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let a=0;a<e.length;a++)e[a]=e[a].replace(/\?/g,"*");if(e[3].toUpperCase()==="LW")this.lastWeekday=!0,e[3]="";else if(e[3].toUpperCase().indexOf("L")>=0){let a=e[3].split(",");if(a.some(o=>o===""||o.toUpperCase()!=="L"&&/l/i.test(o)))throw new TypeError("CronPattern: Syntax error, L has to be a value of its own in day-of-month ('"+e[3]+"').");e[3]=a.filter(o=>o.toUpperCase()!=="L").join(","),this.lastDayOfMonth=!0}if(e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlpha(e[4],r.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],r.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],r.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let n=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],n,63),e[6]==="*"?this.year=Array(1e4).fill(1):(this.year=Array(1e4).fill(0),this.partToArray("year",e[6],0,1)),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let s=this.fixedTimeRule==="single-value",i=(a,o)=>!a.includes("*")&&!a.includes("/")&&(!s||o.filter(u=>u).length===1);this.isFixedTime=i(e[0],this.second)&&i(e[1],this.minute)&&i(e[2],this.hour)}partToArray(e,t,n,s){let i=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(s);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,n,s);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,n,s):t.includes("-")?this.handleRange(t,e,n,s):t.includes("/")?this.handleStepping(t,e,n,s):t!==""&&this.handleNumber(t,e,n,s)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,n,s){let i=this.extractNth(e,t),a=e.toUpperCase().includes("W");if(t!=="day"&&a)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");a&&(t="nearestWeekdays");let o=a?i[0].replace(/W$/i,""):i[0],u=r.toNumber(o)+n;if(isNaN(u))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,u,i[1]||s)}setPart(e,t,n){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,n);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=n}static toNumber(e){return/^\d+$/.test(e)?parseInt(e,10):NaN}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,n,s,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(n!==void 0){if(n===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(n>this[s].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[s].length+")")}}handleRangeWithStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let i=this.extractNth(e,t),a=i[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,l]=a,h=parseInt(o,10)+n,c=parseInt(u,10)+n,d=parseInt(l,10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(c,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(h,c,d,t,e);for(let y=h;y<=c;y+=d)this.setPart(t,y,i[1]||s)}extractNth(e,t){let n=e,s;if(n.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");let i=n.split("#");if(i.length!==2||i[1]==="")throw new TypeError("CronPattern: Syntax error, illegal nth weekday: '"+e+"'");n=i[0],s=i[1]}else if(n.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");s="L",n=n.slice(0,-1)}return[n,s]}handleRange(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let i=this.extractNth(e,t),a=i[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=r.toNumber(a[0])+n,u=r.toNumber(a[1])+n;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,u,void 0,t,e);for(let l=o;l<=u;l++)this.setPart(t,l,i[1]||s)}handleStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let i=this.extractNth(e,t),a=i[0].split("/");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)a[0]===""&&(a[0]="*");else{if(a[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(a[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;a[0]!=="*"&&(o=r.toNumber(a[0])+n,this.validateNotNaN(o,"CronPattern: Syntax error, illegal stepping start (NaN)"));let u=r.toNumber(a[1]);this.validateNotNaN(u,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,u,t,e);for(let l=o;l<this[t].length;l+=u)t==="year"&&l===0||this.setPart(t,l,i[1]||s)}replaceAlpha(e,t){let n=e;for(let[s,i]of Object.entries(t))n=n.replace(new RegExp(s,"gi"),i);return n}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * SUN","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return r.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|S[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}}});var te,f,m,W=T(()=>{E();N();U();te=[31,28,31,30,31,30,31,31,30,31,30,31],f=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],m=class r{tz;instantMs;instantFields;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof r)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?te[t]:new Date(g(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let n=this.getLastDayOfMonth(e,t),i=new Date(g(e,t,n)).getUTCDay();return i===0?n-2:i===6?n-1:n}getNearestWeekday(e,t,n){let s=this.getLastDayOfMonth(e,t);if(n>s)return-1;let a=new Date(g(e,t,n)).getUTCDay();return a===0?n===s?n-2:n+1:a===6?n===1?n+2:n-1:n}isNthWeekdayOfMonth(e,t,n,s){let a=new Date(g(e,t,n)).getUTCDay(),o=0;for(let u=1;u<=n;u++)new Date(g(e,t,u)).getUTCDay()===a&&o++;if(s&63&&S[o-1]&s)return!0;if(s&32){let u=this.getLastDayOfMonth(e,t);for(let l=n+1;l<=u;l++)if(new Date(g(e,t,l)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=p(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.cacheInstant(e.getTime()-this.ms)}catch(t){let n=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${n}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear(),this.cacheInstant(e.getTime()-this.ms)}cacheInstant(e){this.instantMs=e;let{year:t,month:n,day:s,hour:i,minute:a,second:o}=this;this.instantFields=[t,n,s,i,a,o,this.tz]}cachedInstant(){let e=this.instantFields;if(!(e===void 0||e[6]!==this.tz)&&!(e[5]!==this.second||e[4]!==this.minute||e[3]!==this.hour)&&!(e[2]!==this.day||e[1]!==this.month||e[0]!==this.year))return this.instantMs}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms,this.instantMs=e.instantMs,this.instantFields=e.instantFields}apply(){if(this.month>11||this.month<0||this.day>this.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(0);return e.setUTCFullYear(this.year,this.month,this.day),e.setUTCHours(this.hour,this.minute,this.second,this.ms),this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){if(P(e))return this.fromDate(_(e));let t=_(e,"Etc/UTC");this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(_(e,this.tz))}findNext(e,t,n,s){return this._findMatch(e,t,n,s,1)}_matchDayValue(e,t,n,s){let i=e;if(!i){for(let a=0;a<n.nearestWeekdays.length;a++)if(n.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){i=1;break}}}if(n.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(i=1)}if(n.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(i=1)}if(!n.starDOW){let a=new Date(g(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=n.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),n.useAndLogic?i=i&&o:!s.domAndDow&&!n.starDOM?i=i||o:i=i&&o}return i}_findMatch(e,t,n,s,i){let a=this[t],o=t==="day"?this.getLastDayOfMonth(this.year,this.month):0,u=this[t]+s,l=i===1?h=>h<n[t].length:h=>h>=0;for(let h=u;l(h);h+=i){let c=n[t][h];if(t==="day"){if(h-s>o)continue;c=this._matchDayValue(c,h-s,n,e)}if(c)return this[t]=h-s,a!==this[t]?2:1}return 3}recurse(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseStep(e,t,i)}return i}recurseStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let s=this.findNext(t,f[n][0],e,f[n][2]);if(s>1){let i=n+1;for(;i<f.length;)this[f[i][0]]=-f[i][2],i++;if(s===3){if(this[f[n][1]]++,this[f[n][0]]=-f[n][2],this.apply(),n===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return 0}else if(this.apply())return n-1}return n+=1,n>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:n}increment(e,t,n){return this.instantMs=void 0,this.instantFields=void 0,this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t,n=!0){return this.instantMs=void 0,this.instantFields=void 0,this.second-=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0)}recurseBackward(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseBackwardStep(e,t,i)}return i}recurseBackwardStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let s=this.findPrevious(t,f[n][0],e,f[n][2]);if(s>1){let i=n+1;for(;i<f.length;){let a=f[i][0],o=f[i][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,i++}if(s===3){if(this[f[n][1]]--,n===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(n===1)if(this.day<=0)this.day=1;else{let u=this.year,l=this.month;for(;l<0;)l+=12,u--;for(;l>11;)l-=12,u++;let h=this.getLastDayOfMonth(u,l);this.day>h&&(this.day=h)}this.apply();let a=f[n][0],o=f[n][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),n===0){let u=f[1][2],l=this.getMaxPatternValue("day",e,u);l!==this.day&&(this.day=l,this.hour=this.getMaxPatternValue("hour",e,f[2][2]),this.minute=this.getMaxPatternValue("minute",e,f[3][2]),this.second=this.getMaxPatternValue("second",e,f[4][2]))}if(n===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return 0}else if(this.apply())return n-1}return n+=1,n>=f.length?this:this.year<0?null:n}getMaxPatternValue(e,t,n){let s=t[e].length-1-n;for(let i=t[e].length-1;i>=0;i--)if(t[e][i]){s=i-n;break}if(e==="day"){let i=this.getLastDayOfMonth(this.year,this.month);return t.lastWeekday||t.nearestWeekdays.some(a=>a)||t.lastDayOfMonth||!t.starDOW?i:Math.min(s,i)}return s}findPrevious(e,t,n,s){return this._findMatch(e,t,n,s,-1)}getDate(e){if(!e&&typeof this.tz!="number"){let t=this.cachedInstant();if(t!==void 0)return new Date(t+(this.tz===void 0?this.ms:0))}if(e||this.tz===void 0){if(this.year>=0&&this.year<100){let t=new Date(0);return t.setFullYear(this.year,this.month,this.day),t.setHours(this.hour,this.minute,this.second,this.ms),t}return new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms)}else return typeof this.tz=="number"?new Date(g(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):A(b(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let n=0;n<f.length;n++){let s=f[n][0],i=f[n][2],a=this[s];if(a+i<0||a+i>=e[s].length)return!1;let o=e[s][a+i];if(s==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}}});function Z(r){r===void 0&&(r={}),delete r.name,r.legacyMode!==void 0&&r.domAndDow===void 0?r.domAndDow=!r.legacyMode:r.domAndDow===void 0&&(r.domAndDow=!1),r.legacyMode=!r.domAndDow;let e=(n,s)=>n===void 0?s:n;if(r.paused=e(r.paused,!1),r.maxRuns=e(r.maxRuns,1/0),r.catch=e(r.catch,!1),r.unref=e(r.unref,!1),r.mode=e(r.mode,"auto"),r.alternativeWeekdays=e(r.alternativeWeekdays,!1),r.sloppyRanges=e(r.sloppyRanges,!1),r.fixedTimeRule=e(r.fixedTimeRule,"single-value"),r.allowPast=e(r.allowPast,!1),r.interval=r.interval===void 0?0:parseInt(r.interval.toString(),10),r.utcOffset=r.utcOffset===void 0?void 0:parseInt(r.utcOffset.toString(),10),r.dayOffset=r.dayOffset===void 0?0:parseInt(r.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(r.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");if(!["single-value","no-wildcard"].includes(r.fixedTimeRule))throw new Error("CronOptions: fixedTimeRule must be one of 'single-value' or 'no-wildcard'.");r.timezone===""&&(r.timezone=void 0);let t=r.timezone??r.utcOffset;if(r.startAt&&(r.startAt=$(new m(r.startAt,t))),r.stopAt&&(r.stopAt=$(new m(r.stopAt,t))),r.interval!==null){if(isNaN(r.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(r.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(r.utcOffset!==void 0){if(isNaN(r.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(r.utcOffset<-870||r.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(r.utcOffset!==void 0&&r.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(r.unref!==!0&&r.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(r.dayOffset!==void 0&&r.dayOffset!==0&&isNaN(r.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return r}function $(r){return r.ms?(r.ms=0,new m(new Date(r.getTime()+1e3),r.tz)):r}var H=T(()=>{W()});function C(r){return typeof r=="function"}function V(r){return C(r)}function B(r){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(r):r&&typeof r.unref<"u"&&r.unref()}var J=T(()=>{});var z,G,O,M,I,K=T(()=>{W();U();H();J();E();z=1440*60*1e3,G=30*1e3,O=[],M=class{name;options;_states;fn;_startAtRoundingMs=0;getTz(){return this.options.timezone??this.options.utcOffset}applyDayOffset(e){let t=this._offsetMs();return t?new Date(e.getTime()+t):e}_offsetMs(){return(this.options.dayOffset??0)*z}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let n=this._offsetMs(),s=this._next(this._shift(e),new Date(t.getTime()-n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return s?this.applyDayOffset(s.getDate(!1)):null}_previousTarget(e,t){let n=this._previous(this._shift(e??t),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return n?this.applyDayOffset(n.getDate(!1)):null}_shift(e){if(e!=null)return new m(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,n){let s,i;if(C(t))i=t;else if(typeof t=="object")s=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(C(n))i=n;else if(typeof n=="object")s=n;else if(n!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");this.name=s?.name;let a=s?.startAt;this.options=Z(s),a&&this._startAt&&(this._startAtRoundingMs=this._startAt.getTime()-new m(a,this.getTz()).getTime());let o=!!e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0);if(this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:s?s.maxRuns:void 0,paused:s?s.paused:!1,pattern:o?new w("* * * * *",void 0,{mode:"auto"}):new w(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges,fixedTimeRule:this.options.fixedTimeRule})},o&&(this._states.once=new m(e,this.getTz())),this.name){if(O.find(l=>l.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");O.push(this)}return i!==void 0&&V(i)&&(this.fn=i,this.schedule()),this}nextRun(e){return this._nextTarget(e,new Date)}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let n=t||this._states.currentRun||void 0;return this._enumerateRuns(e,n,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new I(this,e)}_enumerateRuns(e,t,n){let s=[],i=new Date,a=t;for(;e-- >0;){let o=n==="next"?this._nextTarget(a,i):this._previousTarget(a,i);if(!o)break;s.push(o),a=o}return s}match(e){if(this._states.once){let n=new m(e,this.getTz());n.ms=0;let s=new m(this._states.once,this.getTz());return s.ms=0,n.getTime()===s.getTime()}let t=new m(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this._nextTarget(this._states.currentRun,new Date)!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=new Date,n=this._nextTarget(e,t);return n?n.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=O.indexOf(this);e>=0&&O.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let n=t??new Date,s=this._nextTarget(void 0,n),i=s?s.getTime()-n.getTime():null,a=this._states.currentRun;a&&a.getTime()>n.getTime()&&(a=void 0);let o=this._nextTarget(a,n);return i===null||isNaN(i)||o===null?this:(i>G&&(i=G),i<0&&(i=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),i),this._states.currentTimeout&&this.options.unref&&B(this._states.currentTimeout),this)}async _trigger(e=new Date){this._states.blocking=!0,this._states.currentRun=new m(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(C(this.options.catch))try{Promise.resolve(this.options.catch(t,this)).catch(()=>{})}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new m(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,n=!this._states.paused&&t.getTime()>=e.getTime(),s=this._states.blocking&&this.options.protect;n&&!s?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):n&&s&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,n?void 0:t)}_next(e,t,n){let s=n?n.startAt:this._startAt,i=n?n.stopAt:this._stopAt,a=!!e,o=!!(e||this._states.currentRun),u=!1;!e&&s&&this.options.interval&&(e=this._calculatePreviousRun(s,t),e&&(o=!0),u=!e);let l=e??t??new Date,h=this._toMs(l);e=new m(l,this.getTz()),s&&h<s.getTime()&&(e=u?s:new m(new Date(s.getTime()-1e3),this.getTz()),h=e.getTime());let c=this._states.once||new m(e,this.getTz());if(!u&&c!==this._states.once&&(c=this._findOccurrence(e,h,1,o)),this._states.once){let d=this._states.once.getTime(),y=h-d;if(s&&d<s.getTime()-this._startAtRoundingMs||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?y>=0:y>1e3&&!this.options.allowPast))return null}return c===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||i&&c.getTime()>=i.getTime()?null:c}_previous(e,t){let n=this._toMs(e??new Date);if(t.stopAt&&n>t.stopAt.getTime()&&(n=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<n?this._states.once:null;let s=this._findOccurrence(new m(new Date(n),this.getTz()),n,-1);return s===null||t.startAt&&s.getTime()<t.startAt.getTime()?null:s}_toMs(e){return e instanceof Date?e.getTime():new m(e,this.getTz()).getTime()}_findOccurrence(e,t,n,s=!1){let i=this.options.interval??0;if(i>1&&(n===-1||s)){t+=(i-1)*1e3*n;let c=new Date(t).getUTCFullYear();if(!(c>=1&&c<=9999))return null;e=new m(new Date(t),this.getTz()),s=!1}let a=this._walk(e,t,n,s),o=this.getTz();if(this._states.pattern.isFixedTime&&n===1||typeof o=="number"||Y(t,o)!==(n===1?"earlier":"later"))return a;let u=Math.floor(t/1e3)*1e3,l=n===1?R(u,u+z,o):R(u-z,u,o)-1e3;if(a&&(l-a.getTime())*n>0)return a;let h=this._walk(new m(new Date(l),o),l-n,n,!1,!0);return!a||!h?a??h:(a.getTime()-h.getTime())*n>0?h:a}_walk(e,t,n,s,i=!1){let a=this._states.pattern,o=(l,h)=>n===1?l.increment(a,this.options,h):l.decrement(a,this.options,h),u=new m(e,this.getTz());for((!i||!u.match(a,this.options))&&(u=o(u,s));u;){let l=this._runAt(u,t,n);if(l)return new m(l,this.getTz());u=o(u,!1)}return null}_runAt(e,t,n){let s=d=>(d.getTime()-t)*n>0,i=e.tz;if(typeof i=="number"){let d=e.getDate();return s(d)?d:null}let a=b(e.year,e.month+1,e.day,e.hour,e.minute,e.second,i),o=k(a),u=this._states.pattern.isFixedTime;if(o.kind==="single")return s(o.date)?o.date:null;if(o.kind==="ambiguous"){let{earlier:d,later:y}=o;return(u?[d]:n===1?[d,y]:[y,d]).find(s)??null}if(!u)return null;let l=new Date(R(o.before.getTime(),o.after.getTime(),i)),h=p(l,i);return h.y===a.y&&h.m===a.m&&h.d===a.d&&s(l)?l:null}_calculatePreviousRun(e,t){let n=new m(t,this.getTz()).getTime();if(e.getTime()>n)return;let s=this.options.interval*1e3,i=e;for(;i.getTime()+s<=n;){let a=this._findOccurrence(i,i.getTime(),1,!0);if(a===null)break;i=a}return i}},I=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.runsLeft()??1/0,this.reset(t)}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron._nextTarget(this.cursor,this.now);return e===null?(this.done=!0,{value:void 0,done:!0}):(this.cursor=e,this.remainingRuns--,{value:e,done:!1})}peek(){return this.done||this.remainingRuns<=0?null:this.cron._nextTarget(this.cursor,this.now)}reset(e){this.cursor=e instanceof Date?new Date(e.getTime()):e??void 0,this.now=new Date,this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}}});var ne=Q((ve,q)=>{K();q.exports=M});return ne();})();
1
+ var Cron=(()=>{var T=(r,e,t)=>()=>{if(t)throw t[0];try{return r&&(e=r(r=0)),e}catch(n){throw t=[n],n}};var Q=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};function g(r,e,t,n=0,s=0,i=0,a=0){let o=r>=0&&r<100,u=Date.UTC(o?r+400:r,e,t,n,s,i,a);return o?u-126227808e5:u}var N=T(()=>{});function v(r){return g(r.y,r.m-1,r.d,r.h,r.i,r.s)}function D(r,e){return r.y===e.y&&r.m===e.m&&r.d===e.d&&r.h===e.h&&r.i===e.i&&r.s===e.s}function P(r){let e=r.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function X(r,e){let t=new Date(Date.parse(r));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return P(r)?{tp:b(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"),ms:t.getUTCMilliseconds()}:{tp:b(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e),ms:t.getMilliseconds()}}function _(r,e,t){let{tp:n,ms:s}=X(r,e);return new Date(A(n,t).getTime()+s)}function A(r,e){let t=k(r);if(t.kind==="single")return t.date;if(t.kind==="ambiguous")return t.earlier;if(e)throw new Error("Invalid date passed to fromTZ()");return t.after}function k(r){let e=v(r),t=a=>x(new Date(a),r.tz),n=e-t(e),s=y(new Date(n),r.tz);if(D(s,r)){let a=v(s)-n,o=n-(t(n-F)-a);if(o<n&&D(y(new Date(o),r.tz),r))return{kind:"ambiguous",earlier:new Date(o),later:new Date(n)};let u=n+(a-t(n+F));return u>n&&D(y(new Date(u),r.tz),r)?{kind:"ambiguous",earlier:new Date(n),later:new Date(u)}:{kind:"single",date:new Date(n)}}let i=e-(v(s)-n);return D(y(new Date(i),r.tz),r)?{kind:"single",date:new Date(i)}:{kind:"gap",before:new Date(Math.min(n,i)),after:new Date(Math.max(n,i))}}function x(r,e){return v(y(r,e))-(r.getTime()-r.getUTCMilliseconds())}function R(r,e,t){let n=x(new Date(r),t);for(;e-r>1e3;){let s=r+Math.floor((e-r)/2e3)*1e3;x(new Date(s),t)===n?r=s:e=s}return e}function Y(r,e){let t=k(y(new Date(r),e));if(t.kind==="ambiguous")return r<t.later.getTime()?"earlier":"later"}function y(r,e){if(e===void 0)return b(r.getFullYear(),r.getMonth()+1,r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds());let t=L.get(e),n;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),L.set(e,t)),n=t.formatToParts(r)}catch(i){let a=i instanceof Error?i.message:String(i);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`)}let s={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of n)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(s[i.type]=parseInt(i.value,10));if(isNaN(s.year)||isNaN(s.month)||isNaN(s.day)||isNaN(s.hour)||isNaN(s.minute)||isNaN(s.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(s)}`);return s.hour===24&&(s.hour=0),{y:s.year,m:s.month,d:s.day,h:s.hour,i:s.minute,s:s.second,tz:e}}function b(r,e,t,n,s,i,a){return{y:r,m:e,d:t,h:n,i:s,s:i,tz:a}}var F,L,E=T(()=>{N();F=3*36e5;L=new Map});var S,w,U=T(()=>{S=[1,2,4,8,16],w=class r{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;fixedTimeRule;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;isFixedTime;constructor(e,t,n){this.pattern=e,this.timezone=t,this.mode=n?.mode??"auto",this.alternativeWeekdays=n?.alternativeWeekdays??!1,this.sloppyRanges=n?.sloppyRanges??!1,this.fixedTimeRule=n?.fixedTimeRule??"single-value",this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=[],this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.isFixedTime=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let a;switch(this.mode){case"5-part":a=5;break;case"6-part":a=6;break;case"7-part":a=7;break;case"5-or-6-parts":a=[5,6];break;case"6-or-7-parts":a=[6,7];break;default:a=0}if(!(Array.isArray(a)?a.includes(t):t===a)){let u=Array.isArray(a)?a.join(" or "):a.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${u} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let a=0;a<e.length;a++)e[a]=e[a].replace(/\?/g,"*");if(e[3].toUpperCase()==="LW")this.lastWeekday=!0,e[3]="";else if(e[3].toUpperCase().indexOf("L")>=0){let a=e[3].split(",");if(a.some(o=>o===""||o.toUpperCase()!=="L"&&/l/i.test(o)))throw new TypeError("CronPattern: Syntax error, L has to be a value of its own in day-of-month ('"+e[3]+"').");e[3]=a.filter(o=>o.toUpperCase()!=="L").join(","),this.lastDayOfMonth=!0}if(e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlpha(e[4],r.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],r.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],r.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let n=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],n,63),e[6]==="*"?this.year=Array(1e4).fill(1):(this.year=Array(1e4).fill(0),this.partToArray("year",e[6],0,1)),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let s=this.fixedTimeRule==="single-value",i=(a,o)=>!a.includes("*")&&!a.includes("/")&&(!s||o.filter(u=>u).length===1);this.isFixedTime=i(e[0],this.second)&&i(e[1],this.minute)&&i(e[2],this.hour)}partToArray(e,t,n,s){let i=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(s);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,n,s);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,n,s):t.includes("-")?this.handleRange(t,e,n,s):t.includes("/")?this.handleStepping(t,e,n,s):t!==""&&this.handleNumber(t,e,n,s)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,n,s){let i=this.extractNth(e,t),a=e.toUpperCase().includes("W");if(t!=="day"&&a)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");a&&(t="nearestWeekdays");let o=a?i[0].replace(/W$/i,""):i[0],u=r.toNumber(o)+n;if(isNaN(u))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,u,i[1]||s)}setPart(e,t,n){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,n);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=n}static toNumber(e){return/^\d+$/.test(e)?parseInt(e,10):NaN}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,n,s,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(n!==void 0){if(n===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(n>this[s].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[s].length+")")}}handleRangeWithStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let i=this.extractNth(e,t),a=i[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,l]=a,h=parseInt(o,10)+n,c=parseInt(u,10)+n,d=parseInt(l,10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(c,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(h,c,d,t,e);for(let p=h;p<=c;p+=d)this.setPart(t,p,i[1]||s)}extractNth(e,t){let n=e,s;if(n.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");let i=n.split("#");if(i.length!==2||i[1]==="")throw new TypeError("CronPattern: Syntax error, illegal nth weekday: '"+e+"'");n=i[0],s=i[1]}else if(n.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");s="L",n=n.slice(0,-1)}return[n,s]}handleRange(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let i=this.extractNth(e,t),a=i[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=r.toNumber(a[0])+n,u=r.toNumber(a[1])+n;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,u,void 0,t,e);for(let l=o;l<=u;l++)this.setPart(t,l,i[1]||s)}handleStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let i=this.extractNth(e,t),a=i[0].split("/");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)a[0]===""&&(a[0]="*");else{if(a[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(a[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;a[0]!=="*"&&(o=r.toNumber(a[0])+n,this.validateNotNaN(o,"CronPattern: Syntax error, illegal stepping start (NaN)"));let u=r.toNumber(a[1]);this.validateNotNaN(u,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,u,t,e);for(let l=o;l<this[t].length;l+=u)t==="year"&&l===0||this.setPart(t,l,i[1]||s)}replaceAlpha(e,t){let n=e;for(let[s,i]of Object.entries(t))n=n.replace(new RegExp(s,"gi"),(a,o,u)=>{let l=o+a.length-3,h=u.charAt(l-1),c=u.charAt(l+3);if(/[a-z\d/#]/i.test(h)||/[a-km-z\d]/i.test(c))throw new TypeError(`CronPattern: Syntax error, a month or day name has to stand alone ('${e}').`);return i});return n}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * SUN","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return r.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|S[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}}});var te,f,m,W=T(()=>{E();N();U();te=[31,28,31,30,31,30,31,31,30,31,30,31],f=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],m=class r{tz;instantMs;instantFields;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof r)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?te[t]:new Date(g(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let n=this.getLastDayOfMonth(e,t),i=new Date(g(e,t,n)).getUTCDay();return i===0?n-2:i===6?n-1:n}getNearestWeekday(e,t,n){let s=this.getLastDayOfMonth(e,t);if(n>s)return-1;let a=new Date(g(e,t,n)).getUTCDay();return a===0?n===s?n-2:n+1:a===6?n===1?n+2:n-1:n}isNthWeekdayOfMonth(e,t,n,s){let a=new Date(g(e,t,n)).getUTCDay(),o=0;for(let u=1;u<=n;u++)new Date(g(e,t,u)).getUTCDay()===a&&o++;if(s&63&&S[o-1]&s)return!0;if(s&32){let u=this.getLastDayOfMonth(e,t);for(let l=n+1;l<=u;l++)if(new Date(g(e,t,l)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=y(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.cacheInstant(e.getTime()-this.ms)}catch(t){let n=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${n}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear(),this.cacheInstant(e.getTime()-this.ms)}cacheInstant(e){this.instantMs=e;let{year:t,month:n,day:s,hour:i,minute:a,second:o}=this;this.instantFields=[t,n,s,i,a,o,this.tz]}cachedInstant(){let e=this.instantFields;if(!(e===void 0||e[6]!==this.tz)&&!(e[5]!==this.second||e[4]!==this.minute||e[3]!==this.hour)&&!(e[2]!==this.day||e[1]!==this.month||e[0]!==this.year))return this.instantMs}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms,this.instantMs=e.instantMs,this.instantFields=e.instantFields}apply(){if(this.month>11||this.month<0||this.day>this.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(0);return e.setUTCFullYear(this.year,this.month,this.day),e.setUTCHours(this.hour,this.minute,this.second,this.ms),this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){if(P(e))return this.fromDate(_(e));let t=_(e,"Etc/UTC");this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(_(e,this.tz))}findNext(e,t,n,s){return this._findMatch(e,t,n,s,1)}_matchDayValue(e,t,n,s){let i=e;if(!i){for(let a=0;a<n.nearestWeekdays.length;a++)if(n.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){i=1;break}}}if(n.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(i=1)}if(n.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(i=1)}if(!n.starDOW){let a=new Date(g(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=n.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),n.useAndLogic?i=i&&o:!s.domAndDow&&!n.starDOM?i=i||o:i=i&&o}return i}_findMatch(e,t,n,s,i){let a=this[t],o=t==="day"?this.getLastDayOfMonth(this.year,this.month):0,u=this[t]+s,l=i===1?h=>h<n[t].length:h=>h>=0;for(let h=u;l(h);h+=i){let c=n[t][h];if(t==="day"){if(h-s>o)continue;c=this._matchDayValue(c,h-s,n,e)}if(c)return this[t]=h-s,a!==this[t]?2:1}return 3}recurse(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseStep(e,t,i)}return i}recurseStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let s=this.findNext(t,f[n][0],e,f[n][2]);if(s>1){let i=n+1;for(;i<f.length;)this[f[i][0]]=-f[i][2],i++;if(s===3){if(this[f[n][1]]++,this[f[n][0]]=-f[n][2],this.apply(),n===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return 0}else if(this.apply())return n-1}return n+=1,n>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:n}increment(e,t,n){return this.instantMs=void 0,this.instantFields=void 0,this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t,n=!0){this.instantMs=void 0,this.instantFields=void 0;let s=t.interval!==void 0&&t.interval>1;return(this.ms===0||s)&&(this.second-=s&&n?t.interval:1),this.ms=0,this.apply(),this.recurseBackward(e,t,0)}recurseBackward(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseBackwardStep(e,t,i)}return i}recurseBackwardStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let s=this.findPrevious(t,f[n][0],e,f[n][2]);if(s>1){let i=n+1;for(;i<f.length;){let a=f[i][0],o=f[i][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,i++}if(s===3){if(this[f[n][1]]--,n===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(n===1)if(this.day<=0)this.day=1;else{let u=this.year,l=this.month;for(;l<0;)l+=12,u--;for(;l>11;)l-=12,u++;let h=this.getLastDayOfMonth(u,l);this.day>h&&(this.day=h)}this.apply();let a=f[n][0],o=f[n][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),n===0){let u=f[1][2],l=this.getMaxPatternValue("day",e,u);l!==this.day&&(this.day=l,this.hour=this.getMaxPatternValue("hour",e,f[2][2]),this.minute=this.getMaxPatternValue("minute",e,f[3][2]),this.second=this.getMaxPatternValue("second",e,f[4][2]))}if(n===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return 0}else if(this.apply())return n-1}return n+=1,n>=f.length?this:this.year<0?null:n}getMaxPatternValue(e,t,n){let s=t[e].length-1-n;for(let i=t[e].length-1;i>=0;i--)if(t[e][i]){s=i-n;break}if(e==="day"){let i=this.getLastDayOfMonth(this.year,this.month);return t.lastWeekday||t.nearestWeekdays.some(a=>a)||t.lastDayOfMonth||!t.starDOW?i:Math.min(s,i)}return s}findPrevious(e,t,n,s){return this._findMatch(e,t,n,s,-1)}getDate(e){if(!e&&typeof this.tz!="number"){let t=this.cachedInstant();if(t!==void 0)return new Date(t+(this.tz===void 0?this.ms:0))}if(e||this.tz===void 0){if(this.year>=0&&this.year<100){let t=new Date(0);return t.setFullYear(this.year,this.month,this.day),t.setHours(this.hour,this.minute,this.second,this.ms),t}return new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms)}else return typeof this.tz=="number"?new Date(g(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):A(b(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let n=0;n<f.length;n++){let s=f[n][0],i=f[n][2],a=this[s];if(a+i<0||a+i>=e[s].length)return!1;let o=e[s][a+i];if(s==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}}});function Z(r){r===void 0&&(r={}),delete r.name,r.legacyMode!==void 0&&r.domAndDow===void 0?r.domAndDow=!r.legacyMode:r.domAndDow===void 0&&(r.domAndDow=!1),r.legacyMode=!r.domAndDow;let e=(n,s)=>n===void 0?s:n;if(r.paused=e(r.paused,!1),r.maxRuns=e(r.maxRuns,1/0),r.catch=e(r.catch,!1),r.unref=e(r.unref,!1),r.mode=e(r.mode,"auto"),r.alternativeWeekdays=e(r.alternativeWeekdays,!1),r.sloppyRanges=e(r.sloppyRanges,!1),r.fixedTimeRule=e(r.fixedTimeRule,"single-value"),r.allowPast=e(r.allowPast,!1),r.interval=r.interval===void 0?0:parseInt(r.interval.toString(),10),r.utcOffset=r.utcOffset===void 0?void 0:parseInt(r.utcOffset.toString(),10),r.dayOffset=r.dayOffset===void 0?0:parseInt(r.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(r.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");if(!["single-value","no-wildcard"].includes(r.fixedTimeRule))throw new Error("CronOptions: fixedTimeRule must be one of 'single-value' or 'no-wildcard'.");r.timezone===""&&(r.timezone=void 0);let t=r.timezone??r.utcOffset;if(r.startAt&&(r.startAt=j(new m(r.startAt,t))),r.stopAt&&(r.stopAt=j(new m(r.stopAt,t))),r.interval!==null){if(isNaN(r.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(r.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(r.utcOffset!==void 0){if(isNaN(r.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(r.utcOffset<-870||r.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(r.utcOffset!==void 0&&r.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(r.unref!==!0&&r.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(r.dayOffset!==void 0&&r.dayOffset!==0&&isNaN(r.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return r}function j(r){return r.ms?(r.ms=0,new m(new Date(r.getTime()+1e3),r.tz)):r}var H=T(()=>{W()});function C(r){return typeof r=="function"}function V(r){return C(r)}function B(r){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(r):r&&typeof r.unref<"u"&&r.unref()}var J=T(()=>{});var z,G,M,O,I,K=T(()=>{W();U();H();J();E();z=1440*60*1e3,G=30*1e3,M=[],O=class{name;options;_states;fn;_startAtRoundingMs=0;getTz(){return this.options.timezone??this.options.utcOffset}applyDayOffset(e){let t=this._offsetMs();return t?new Date(e.getTime()+t):e}_offsetMs(){return(this.options.dayOffset??0)*z}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let n=this._offsetMs(),s=this._next(this._shift(e),new Date(t.getTime()-n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return s?this.applyDayOffset(s.getDate(!1)):null}_previousTarget(e,t){let n=this._toMs(e??t)-this._offsetMs(),s=this._previous(new Date(n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return s?this.applyDayOffset(s.getDate(!1)):null}_shift(e){if(e!=null)return new m(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,n){let s,i;if(C(t))i=t;else if(typeof t=="object")s=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(C(n))i=n;else if(typeof n=="object")s=n;else if(n!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");this.name=s?.name;let a=s?.startAt;this.options=Z(s),a&&this._startAt&&(this._startAtRoundingMs=this._startAt.getTime()-new m(a,this.getTz()).getTime());let o=!!e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0);if(this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:s?s.maxRuns:void 0,paused:s?s.paused:!1,pattern:o?new w("* * * * *",void 0,{mode:"auto"}):new w(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges,fixedTimeRule:this.options.fixedTimeRule})},o&&(this._states.once=new m(e,this.getTz())),this.name){if(M.find(l=>l.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");M.push(this)}return i!==void 0&&V(i)&&(this.fn=i,this.schedule()),this}nextRun(e){return this._nextTarget(e,new Date)}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let n=t||this._states.currentRun||void 0;return this._enumerateRuns(e,n,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new I(this,e)}_enumerateRuns(e,t,n){let s=[],i=new Date,a=t;for(;e-- >0;){let o=n==="next"?this._nextTarget(a,i):this._previousTarget(a,i);if(!o)break;s.push(o),a=o}return s}match(e){if(this._states.once){let n=new m(e,this.getTz());n.ms=0;let s=new m(this._states.once,this.getTz());return s.ms=0,n.getTime()===s.getTime()}let t=new m(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this._nextTarget(this._states.currentRun,new Date)!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=new Date,n=this._nextTarget(e,t);return n?n.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=M.indexOf(this);e>=0&&M.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let n=t??new Date,s=this._nextTarget(void 0,n),i=s?s.getTime()-n.getTime():null,a=this._states.currentRun;a&&a.getTime()>n.getTime()&&(a=void 0);let o=this._nextTarget(a,n);return i===null||isNaN(i)||o===null?this:(i>G&&(i=G),i<0&&(i=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),i),this._states.currentTimeout&&this.options.unref&&B(this._states.currentTimeout),this)}async _trigger(e=new Date){this._states.blocking=!0,this._states.currentRun=new m(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(C(this.options.catch))try{Promise.resolve(this.options.catch(t,this)).catch(()=>{})}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new m(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,n=!this._states.paused&&t.getTime()>=e.getTime(),s=this._states.blocking&&this.options.protect;n&&!s?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):n&&s&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,n?void 0:t)}_next(e,t,n){let s=n?n.startAt:this._startAt,i=n?n.stopAt:this._stopAt,a=!!e,o=!!(e||this._states.currentRun),u=!1;!e&&s&&this.options.interval&&(e=this._calculatePreviousRun(s,t),e&&(o=!0),u=!e);let l=e??t??new Date,h=this._toMs(l);e=new m(l,this.getTz()),s&&h<s.getTime()&&(e=u?s:new m(new Date(s.getTime()-1e3),this.getTz()),h=e.getTime());let c=this._states.once||new m(e,this.getTz());if(!u&&c!==this._states.once&&(c=this._findOccurrence(e,h,1,o)),this._states.once){let d=this._states.once.getTime(),p=h-d;if(s&&d<s.getTime()-this._startAtRoundingMs||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?p>=0:p>1e3&&!this.options.allowPast))return null}return c===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||i&&c.getTime()>=i.getTime()?null:c}_previous(e,t){let n=this._toMs(e??new Date);if(t.stopAt&&n>t.stopAt.getTime()&&(n=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<n?this._states.once:null;let s=this._findOccurrence(new m(new Date(n),this.getTz()),n,-1);return s===null||t.startAt&&s.getTime()<t.startAt.getTime()?null:s}_toMs(e){if(e instanceof Date)return e.getTime();let t=new m(e,this.getTz());return t.getTime()+(typeof t.tz=="string"?t.ms:0)}_findOccurrence(e,t,n,s=!1){let i=this.options.interval??0;if(i>1&&(n===-1||s)){t+=(i-1)*1e3*n;let c=new Date(t).getUTCFullYear();if(!(c>=1&&c<=9999))return null;e=new m(new Date(t),this.getTz()),s=!1}let a=this._walk(e,t,n,s),o=this.getTz();if(this._states.pattern.isFixedTime&&n===1||typeof o=="number"||Y(t,o)!==(n===1?"earlier":"later"))return a;let u=Math.floor(t/1e3)*1e3,l=n===1?R(u,u+z,o):R(u-z,u,o)-1e3;if(a&&(l-a.getTime())*n>0)return a;let h=this._walk(new m(new Date(l),o),l-n,n,!1,!0);return!a||!h?a??h:(a.getTime()-h.getTime())*n>0?h:a}_walk(e,t,n,s,i=!1){let a=this._states.pattern,o=(l,h)=>n===1?l.increment(a,this.options,h):l.decrement(a,this.options,h),u=new m(e,this.getTz());for((!i||!u.match(a,this.options))&&(u=o(u,s));u;){let l=this._runAt(u,t,n);if(l)return new m(l,this.getTz());u=o(u,!1)}return null}_runAt(e,t,n){let s=d=>(d.getTime()-t)*n>0,i=e.tz;if(typeof i=="number"){let d=e.getDate();return s(d)?d:null}let a=b(e.year,e.month+1,e.day,e.hour,e.minute,e.second,i),o=k(a),u=this._states.pattern.isFixedTime;if(o.kind==="single")return s(o.date)?o.date:null;if(o.kind==="ambiguous"){let{earlier:d,later:p}=o;return(u?[d]:n===1?[d,p]:[p,d]).find(s)??null}if(!u)return null;let l=new Date(R(o.before.getTime(),o.after.getTime(),i)),h=y(l,i);return h.y===a.y&&h.m===a.m&&h.d===a.d&&s(l)?l:null}_calculatePreviousRun(e,t){let n=new m(t,this.getTz()).getTime();if(e.getTime()>n)return;let s=this.options.interval*1e3,i=e;for(;i.getTime()+s<=n;){let a=this._findOccurrence(i,i.getTime(),1,!0);if(a===null)break;i=a}return i}},I=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.runsLeft()??1/0,this.reset(t)}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron._nextTarget(this.cursor,this.now);return e===null?(this.done=!0,{value:void 0,done:!0}):(this.cursor=e,this.remainingRuns--,{value:e,done:!1})}peek(){return this.done||this.remainingRuns<=0?null:this.cron._nextTarget(this.cursor,this.now)}reset(e){this.cursor=e instanceof Date?new Date(e.getTime()):e??void 0,this.now=new Date,this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}}});var ne=Q((ve,q)=>{K();q.exports=O});return ne();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "croner",
3
- "version": "11.0.1-dev.3",
3
+ "version": "11.0.1-dev.4",
4
4
  "description": "Trigger functions and/or evaluate cron expressions in JavaScript. No dependencies. Most features. All environments.",
5
5
  "author": "Hexagon <github.com/hexagon>",
6
6
  "homepage": "https://croner.56k.guru",