croner 10.0.1 → 10.0.2-dev.1
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 +4 -3
- package/dist/croner.cjs +1 -1
- package/dist/croner.d.cts +27 -2
- package/dist/croner.d.ts +27 -2
- package/dist/croner.js +1 -1
- package/dist/croner.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,10 +74,10 @@ Using Deno
|
|
|
74
74
|
|
|
75
75
|
```typescript
|
|
76
76
|
// From deno.land/x
|
|
77
|
-
import { Cron } from "https://deno.land/x/croner@10.0.
|
|
77
|
+
import { Cron } from "https://deno.land/x/croner@10.0.1/dist/croner.js";
|
|
78
78
|
|
|
79
79
|
// ... or jsr.io
|
|
80
|
-
import { Cron } from "jsr:@hexagon/croner@10.0.
|
|
80
|
+
import { Cron } from "jsr:@hexagon/croner@10.0.1";
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
In a webpage using the UMD-module
|
|
@@ -164,6 +164,7 @@ job.name // Optional job name, populated if a name were passed to options
|
|
|
164
164
|
| utcOffset | undefined | number | Schedule using a specific utc offset in minutes. This does not take care of daylight savings time, you probably want to use option `timezone` instead. |
|
|
165
165
|
| protect | undefined | boolean\|Function | Enabled over-run protection. Will block new triggers as long as an old trigger is in progress. Pass either `true` or a callback function to enable |
|
|
166
166
|
| alternativeWeekdays | false | boolean | Enable Quartz-style weekday numbering (1=Sunday, 2=Monday, ..., 7=Saturday). When false (default), uses standard cron format (0=Sunday, 1=Monday, ..., 6=Saturday). |
|
|
167
|
+
| allowPast | false | boolean | If true, date-based jobs scheduled in the past will fire immediately. If false, only jobs scheduled within the past second will fire (to handle timing edge cases). |
|
|
167
168
|
|
|
168
169
|
> **Warning**
|
|
169
170
|
> Unreferencing timers (option `unref`) is only supported by Node.js and Deno.
|
|
@@ -199,7 +200,7 @@ Croner uses [Vixie Cron](https://en.wikipedia.org/wiki/Cron#CRON_expression) bas
|
|
|
199
200
|
* **Enhanced logical control**:
|
|
200
201
|
- *+*: Explicit AND logic modifier. Prefix the day-of-week field with `+` to require both day-of-month AND day-of-week to match. Example: `0 12 1 * +MON` only triggers when the 1st is also a Monday.
|
|
201
202
|
- *?*: Wildcard alias (behaves identically to `*`). **Non-portable**: Its use is discouraged in patterns intended for cross-system use. Supported in all fields for compatibility, but primarily meaningful in day-of-month and day-of-week fields.
|
|
202
|
-
- Proper DST handling: Jobs scheduled during DST gaps are skipped
|
|
203
|
+
- Proper DST handling: Jobs scheduled during DST gaps are skipped. During DST overlaps (fall-back), specific-time patterns (e.g. `0 30 2 * * *`) run once at the first occurrence; high-frequency patterns (e.g. `* * * * *`) continue executing without gaps.
|
|
203
204
|
|
|
204
205
|
* Croner allows you to pass a JavaScript Date object or an ISO 8601 formatted string as a pattern. The scheduled function will trigger at the specified date/time and only once. If you use a timezone different from the local timezone, you should pass the ISO 8601 local time in the target location and specify the timezone using the options (2nd parameter).
|
|
205
206
|
|
package/dist/croner.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var D=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var I=(s,e)=>{for(var t in e)D(s,t,{get:e[t],enumerable:!0})},L=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of S(e))!z.call(s,n)&&n!==t&&D(s,n,{get:()=>e[n],enumerable:!(r=U(e,n))||r.enumerable});return s};var Y=s=>L(D({},"__esModule",{value:!0}),s);var $={};I($,{Cron:()=>R,CronDate:()=>m,CronPattern:()=>p,scheduledJobs:()=>b});module.exports=Y($);function C(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function v(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function F(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");let r=s.substring(9);return r.includes("Z")||r.includes("+")||r.includes("-")?w(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):w(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function k(s,e,t){return O(F(s,e),t)}function O(s,e){let t=new Date(C(s)),r=g(t,s.tz),n=C(s),i=C(r),a=n-i,o=new Date(t.getTime()+a),h=g(o,s.tz);if(v(h,s)){let u=new Date(o.getTime()-36e5),d=g(u,s.tz);return v(d,s)?u:o}let l=new Date(o.getTime()+C(s)-C(h)),y=g(l,s.tz);if(v(y,s))return l;if(e)throw new Error("Invalid date passed to fromTZ()");return o.getTime()>l.getTime()?o:l}function g(s,e){let t,r;try{t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),r=t.formatToParts(s)}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 n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of r)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(n[i.type]=parseInt(i.value,10));if(isNaN(n.year)||isNaN(n.month)||isNaN(n.day)||isNaN(n.hour)||isNaN(n.minute)||isNaN(n.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(n)}`);return n.hour===24&&(n.hour=0),{y:n.year,m:n.month,d:n.day,h:n.hour,i:n.minute,s:n.second,tz:e}}function w(s,e,t,r,n,i,a){return{y:s,m:e,d:t,h:r,i:n,s:i,tz:a}}var N=[1,2,4,8,16],p=class{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,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=Array(1e4).fill(0),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.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 n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let a=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${a} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlphaMonths(e[4])),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlphaDaysQuartz(e[5]):this.replaceAlphaDays(e[5])),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.pattern.indexOf("?")>=0&&(e[0]=e[0].replace(/\?/g,"*"),e[1]=e[1].replace(/\?/g,"*"),e[2]=e[2].replace(/\?/g,"*"),e[3]=e[3].replace(/\?/g,"*"),e[4]=e[4].replace(/\?/g,"*"),e[5]=e[5].replace(/\?/g,"*"),e[6]&&(e[6]=e[6].replace(/\?/g,"*"))),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 r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,r,n){let i=this[e],a=e==="day"&&this.lastDayOfMonth,o=e==="day"&&this.lastWeekday;if(t===""&&!a&&!o)throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(n);let h=t.split(",");if(h.length>1)for(let l=0;l<h.length;l++)this.partToArray(e,h[l],r,n);else t.indexOf("-")!==-1&&t.indexOf("/")!==-1?this.handleRangeWithStepping(t,e,r,n):t.indexOf("-")!==-1?this.handleRange(t,e,r,n):t.indexOf("/")!==-1?this.handleStepping(t,e,r,n):t!==""&&this.handleNumber(t,e,r,n)}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,r,n){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=parseInt(i[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,i[1]||n)}setPart(e,t,r){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,r);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]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,n,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[n].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[n].length+")")}}handleRangeWithStepping(e,t,r,n){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,h,l]=a,y=parseInt(o,10)+r,u=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(y,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(y,u,d,t,e);for(let c=y;c<=u;c+=d)this.setPart(t,c,i[1]||n)}extractNth(e,t){let r=e,n;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");n=r.split("#")[1],r=r.split("#")[0]}else if(r.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)");n="L",r=r.slice(0,-1)}return[r,n]}handleRange(e,t,r,n){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=parseInt(a[0],10)+r,h=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(h,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,h,void 0,t,e);for(let l=o;l<=h;l++)this.setPart(t,l,i[1]||n)}handleStepping(e,t,r,n){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=parseInt(a[0],10)+r);let h=parseInt(a[1],10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,h,t,e);for(let l=o;l<this[t].length;l+=h)this.setPart(t,l,i[1]||n)}replaceAlphaDays(e){return e.replace(/-sun/gi,"-7").replace(/sun/gi,"0").replace(/mon/gi,"1").replace(/tue/gi,"2").replace(/wed/gi,"3").replace(/thu/gi,"4").replace(/fri/gi,"5").replace(/sat/gi,"6")}replaceAlphaDaysQuartz(e){return e.replace(/sun/gi,"1").replace(/mon/gi,"2").replace(/tue/gi,"3").replace(/wed/gi,"4").replace(/thu/gi,"5").replace(/fri/gi,"6").replace(/sat/gi,"7")}replaceAlphaMonths(e){return e.replace(/jan/gi,"1").replace(/feb/gi,"2").replace(/mar/gi,"3").replace(/apr/gi,"4").replace(/may/gi,"5").replace(/jun/gi,"6").replace(/jul/gi,"7").replace(/aug/gi,"8").replace(/sep/gi,"9").replace(/oct/gi,"10").replace(/nov/gi,"11").replace(/dec/gi,"12")}handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@yearly"||t==="@annually")return"0 0 1 1 *";if(t==="@monthly")return"0 0 1 * *";if(t==="@weekly")return"0 0 * * 0";if(t==="@daily"||t==="@midnight")return"0 0 * * *";if(t==="@hourly")return"0 * * * *";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 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]|N[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var M=[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 s{tz;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 s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?M[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r-2:i===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r===n?r-2:r+1:a===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let a=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let h=1;h<=r;h++)new Date(Date.UTC(e,t,h)).getUTCDay()===a&&o++;if(n&63&&N[o-1]&n)return!0;if(n&32){let h=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=h;l++)if(new Date(Date.UTC(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=g(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}catch(t){let r=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: ${r}`)}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()}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}apply(){if(this.month>11||this.month<0||this.day>M[this.month]||this.day<1||this.hour>59||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return 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"){let t=k(e);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(k(e,this.tz))}findNext(e,t,r,n){return this._findMatch(e,t,r,n,1)}_findMatch(e,t,r,n,i){let a=this[t],o;r.lastDayOfMonth&&(o=this.getLastDayOfMonth(this.year,this.month));let h=!r.starDOW&&t=="day"?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0,l=this[t]+n,y=i===1?u=>u<r[t].length:u=>u>=0;for(let u=l;y(u);u+=i){let d=r[t][u];if(t==="day"&&!d){for(let c=0;c<r.nearestWeekdays.length;c++)if(r.nearestWeekdays[c]){let _=this.getNearestWeekday(this.year,this.month,c-n);if(_===-1)continue;if(_===u-n){d=1;break}}}if(t==="day"&&r.lastWeekday){let c=this.getLastWeekday(this.year,this.month);u-n===c&&(d=1)}if(t==="day"&&r.lastDayOfMonth&&u-n==o&&(d=1),t==="day"&&!r.starDOW){let c=r.dayOfWeek[(h+(u-n-1))%7];if(c&&c&63)c=this.isNthWeekdayOfMonth(this.year,this.month,u-n,c)?1:0;else if(c)throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${c}`);r.useAndLogic?d=d&&c:!e.domAndDow&&!r.starDOM?d=d||c:d=d&&c}if(d)return this[t]=u-n,a!==this[t]?2:1}return 3}recurse(e,t,r){if(r===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 n=this.findNext(t,f[r][0],e,f[r][2]);if(n>1){let i=r+1;for(;i<f.length;)this[f[i][0]]=-f[i][2],i++;if(n===3){if(this[f[r][1]]++,this[f[r][0]]=-f[r][2],this.apply(),r===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 this.recurse(e,t,0)}else if(this.apply())return this.recurse(e,t,r-1)}return r+=1,r>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:this.recurse(e,t,r)}increment(e,t,r){return this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0,0)}recurseBackward(e,t,r,n=0){if(n>1e4)return null;if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let a=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){a=o;break}if(a===-1)return null;this.year=a,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 i=this.findPrevious(t,f[r][0],e,f[r][2]);if(i>1){let a=r+1;for(;a<f.length;){let o=f[a][0],h=f[a][2],l=this.getMaxPatternValue(o,e,h);this[o]=l,a++}if(i===3){if(this[f[r][1]]--,r===0){let y=this.getLastDayOfMonth(this.year,this.month);this.day>y&&(this.day=y)}if(r===1)if(this.day<=0)this.day=1;else{let y=this.year,u=this.month;for(;u<0;)u+=12,y--;for(;u>11;)u-=12,y++;let d=u!==1?M[u]:new Date(Date.UTC(y,u+1,0)).getUTCDate();this.day>d&&(this.day=d)}this.apply();let o=f[r][0],h=f[r][2],l=this.getMaxPatternValue(o,e,h);if(o==="day"){let y=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,y)}else this[o]=l;if(this.apply(),r===0){let y=f[1][2],u=this.getMaxPatternValue("day",e,y),d=this.getLastDayOfMonth(this.year,this.month),c=Math.min(u,d);c!==this.day&&(this.day=c,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(r===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 this.recurseBackward(e,t,0,n+1)}else if(this.apply())return this.recurseBackward(e,t,r-1,n+1)}return r+=1,r>=f.length?this:this.year<0?null:this.recurseBackward(e,t,r,n+1)}getMaxPatternValue(e,t,r){if(e==="day"&&t.lastDayOfMonth)return this.getLastDayOfMonth(this.year,this.month);if(e==="day"&&!t.starDOW)return this.getLastDayOfMonth(this.year,this.month);for(let n=t[e].length-1;n>=0;n--)if(t[e][n])return n-r;return t[e].length-1-r}findPrevious(e,t,r,n){return this._findMatch(e,t,r,n,-1)}getDate(e){return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):O(w(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 r=0;r<f.length;r++){let n=f[r][0],i=f[r][2],a=this[n];if(a+i<0||a+i>=e[n].length)return!1;let o=e[n][a+i];if(n==="day"){if(!o){for(let h=0;h<e.nearestWeekdays.length;h++)if(e.nearestWeekdays[h]){let l=this.getNearestWeekday(this.year,this.month,h-i);if(l!==-1&&l===a){o=1;break}}}if(e.lastWeekday){let h=this.getLastWeekday(this.year,this.month);a===h&&(o=1)}if(e.lastDayOfMonth){let h=this.getLastDayOfMonth(this.year,this.month);a===h&&(o=1)}if(!e.starDOW){let h=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),l=e.dayOfWeek[(h+(a-1))%7];l&&l&63&&(l=this.isNthWeekdayOfMonth(this.year,this.month,a,l)?1:0),e.useAndLogic?o=o&&l:!t.domAndDow&&!e.starDOM?o=o||l:o=o&&l}}if(!o)return!1}return!0}};function x(s){if(s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow,s.paused=s.paused===void 0?!1:s.paused,s.maxRuns=s.maxRuns===void 0?1/0:s.maxRuns,s.catch=s.catch===void 0?!1:s.catch,s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),s.unref=s.unref===void 0?!1:s.unref,s.mode=s.mode===void 0?"auto":s.mode,s.alternativeWeekdays=s.alternativeWeekdays===void 0?!1:s.alternativeWeekdays,s.sloppyRanges=s.sloppyRanges===void 0?!1:s.sloppyRanges,!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.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(s.startAt&&(s.startAt=new m(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new m(s.stopAt,s.timezone)),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}function T(s){return Object.prototype.toString.call(s)==="[object Function]"||typeof s=="function"||s instanceof Function}function W(s){return T(s)}function E(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var A=30*1e3,b=[],R=class{name;options;_states;fn;getTz(){return this.options.timezone||this.options.utcOffset}applyDayOffset(e){if(this.options.dayOffset!==void 0&&this.options.dayOffset!==0){let t=this.options.dayOffset*24*60*60*1e3;return new Date(e.getTime()+t)}return e}constructor(e,t,r){let n,i;if(T(t))i=t;else if(typeof t=="object")n=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(T(r))i=r;else if(typeof r=="object")n=r;else if(r!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");if(this.name=n?.name,this.options=x(n),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:n?n.maxRuns:void 0,paused:n?n.paused:!1,pattern:new p("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new m(e,this.getTz()):this._states.pattern=new p(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(b.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");b.push(this)}return i!==void 0&&W(i)&&(this.fn=i,this.schedule()),this}nextRun(e){let t=this._next(e);return t?this.applyDayOffset(t.getDate(!1)):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}_enumerateRuns(e,t,r){let n=[],i=t?new m(t,this.getTz()):null,a=r==="next"?this._next:this._previous;for(;e--;){let o=a.call(this,i);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),i=o}return n}match(e){if(this._states.once){let r=new m(e,this.getTz());r.ms=0;let n=new m(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.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(){let e=this.nextRun(this._states.currentRun),t=!this._states.paused,r=this.fn!==void 0,n=!this._states.kill;return t&&r&&n&&e!==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=this._next(e);return t?e instanceof m||e instanceof Date?t.getTime()-e.getTime():t.getTime()-new m(e).getTime():null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=b.indexOf(this);e>=0&&b.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){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 t=this.msToNext(),r=this.nextRun(this._states.currentRun);return t==null||isNaN(t)||r===null?this:(t>A&&(t=A),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(r),t),this._states.currentTimeout&&this.options.unref&&E(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new m(void 0,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(T(this.options.catch))try{this.options.catch(t,this)}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,r=!this._states.paused&&t.getTime()>=e.getTime(),n=this._states.blocking&&this.options.protect;r&&!n?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger()):r&&n&&T(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this.schedule()}_next(e){let t=!!(e||this._states.currentRun),r=!1;!e&&this.options.startAt&&this.options.interval&&([e,t]=this._calculatePreviousRun(e,t),r=!e),e=new m(e,this.getTz()),this.options.startAt&&e&&e.getTime()<this.options.startAt.getTime()&&(e=this.options.startAt);let n=this._states.once||new m(e,this.getTz());return!r&&n!==this._states.once&&(n=n.increment(this._states.pattern,this.options,t)),this._states.once&&this._states.once.getTime()<=e.getTime()||n===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||this.options.stopAt&&n.getTime()>=this.options.stopAt.getTime()?null:n}_previous(e){let t=new m(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new m(t,this.getTz());return this._states.once?this._states.once.getTime()<t.getTime()?this._states.once:null:(r=r.decrement(this._states.pattern,this.options),r===null||this.options.startAt&&r.getTime()<this.options.startAt.getTime()?null:r)}_calculatePreviousRun(e,t){let r=new m(void 0,this.getTz()),n=e;if(this.options.startAt.getTime()<=r.getTime()){n=this.options.startAt;let i=n.getTime()+this.options.interval*1e3;for(;i<=r.getTime();)n=new m(n,this.getTz()).increment(this._states.pattern,this.options,!0),i=n.getTime()+this.options.interval*1e3;t=!0}return n===null&&(n=void 0),[n,t]}};0&&(module.exports={Cron,CronDate,CronPattern,scheduledJobs});
|
|
1
|
+
var P=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var $=(s,e)=>{for(var t in e)P(s,t,{get:e[t],enumerable:!0})},V=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of F(e))!j.call(s,n)&&n!==t&&P(s,n,{get:()=>e[n],enumerable:!(r=Y(e,n))||r.enumerable});return s};var Z=s=>V(P({},"__esModule",{value:!0}),s);var J={};$(J,{Cron:()=>W,CronDate:()=>y,CronPattern:()=>p,scheduledJobs:()=>w});module.exports=Z(J);function b(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function D(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function B(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");let r=s.substring(9);return r.includes("Z")||r.includes("+")||r.includes("-")?v(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):v(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function M(s,e,t){return N(B(s,e),t)}function N(s,e,t){let r=new Date(b(s)),n=g(r,s.tz),i=b(s),a=b(n),o=i-a,h=new Date(r.getTime()+o),l=g(h,s.tz);if(D(l,s)){let d=new Date(h.getTime()-36e5),f=g(d,s.tz),C=new Date(h.getTime()+36e5),z=g(C,s.tz),k=D(f,s),I=D(z,s);if(k||I){let O=k?d:h,L=k?h:C;return t!==void 0?O.getTime()>=t?O:L:O}return h}let m=new Date(h.getTime()+b(s)-b(l)),u=g(m,s.tz);if(D(u,s))return m;if(e)throw new Error("Invalid date passed to fromTZ()");return h.getTime()>m.getTime()?h:m}function g(s,e){let t,r;try{t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),r=t.formatToParts(s)}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 n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of r)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(n[i.type]=parseInt(i.value,10));if(isNaN(n.year)||isNaN(n.month)||isNaN(n.day)||isNaN(n.hour)||isNaN(n.minute)||isNaN(n.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(n)}`);return n.hour===24&&(n.hour=0),{y:n.year,m:n.month,d:n.day,h:n.hour,i:n.minute,s:n.second,tz:e}}function v(s,e,t,r,n,i,a){return{y:s,m:e,d:t,h:r,i:n,s:i,tz:a}}var R=[1,2,4,8,16],p=class{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,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=Array(1e4).fill(0),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.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 n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let a=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${a} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlphaMonths(e[4])),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlphaDaysQuartz(e[5]):this.replaceAlphaDays(e[5])),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.pattern.indexOf("?")>=0&&(e[0]=e[0].replace(/\?/g,"*"),e[1]=e[1].replace(/\?/g,"*"),e[2]=e[2].replace(/\?/g,"*"),e[3]=e[3].replace(/\?/g,"*"),e[4]=e[4].replace(/\?/g,"*"),e[5]=e[5].replace(/\?/g,"*"),e[6]&&(e[6]=e[6].replace(/\?/g,"*"))),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 r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,r,n){let i=this[e],a=e==="day"&&this.lastDayOfMonth,o=e==="day"&&this.lastWeekday;if(t===""&&!a&&!o)throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(n);let h=t.split(",");if(h.length>1)for(let l=0;l<h.length;l++)this.partToArray(e,h[l],r,n);else t.indexOf("-")!==-1&&t.indexOf("/")!==-1?this.handleRangeWithStepping(t,e,r,n):t.indexOf("-")!==-1?this.handleRange(t,e,r,n):t.indexOf("/")!==-1?this.handleStepping(t,e,r,n):t!==""&&this.handleNumber(t,e,r,n)}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,r,n){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=parseInt(i[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,i[1]||n)}setPart(e,t,r){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,r);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]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,n,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[n].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[n].length+")")}}handleRangeWithStepping(e,t,r,n){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,h,l]=a,m=parseInt(o,10)+r,u=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(m,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(m,u,d,t,e);for(let f=m;f<=u;f+=d)this.setPart(t,f,i[1]||n)}extractNth(e,t){let r=e,n;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");n=r.split("#")[1],r=r.split("#")[0]}else if(r.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)");n="L",r=r.slice(0,-1)}return[r,n]}handleRange(e,t,r,n){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=parseInt(a[0],10)+r,h=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(h,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,h,void 0,t,e);for(let l=o;l<=h;l++)this.setPart(t,l,i[1]||n)}handleStepping(e,t,r,n){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=parseInt(a[0],10)+r);let h=parseInt(a[1],10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,h,t,e);for(let l=o;l<this[t].length;l+=h)this.setPart(t,l,i[1]||n)}replaceAlphaDays(e){return e.replace(/-sun/gi,"-7").replace(/sun/gi,"0").replace(/mon/gi,"1").replace(/tue/gi,"2").replace(/wed/gi,"3").replace(/thu/gi,"4").replace(/fri/gi,"5").replace(/sat/gi,"6")}replaceAlphaDaysQuartz(e){return e.replace(/sun/gi,"1").replace(/mon/gi,"2").replace(/tue/gi,"3").replace(/wed/gi,"4").replace(/thu/gi,"5").replace(/fri/gi,"6").replace(/sat/gi,"7")}replaceAlphaMonths(e){return e.replace(/jan/gi,"1").replace(/feb/gi,"2").replace(/mar/gi,"3").replace(/apr/gi,"4").replace(/may/gi,"5").replace(/jun/gi,"6").replace(/jul/gi,"7").replace(/aug/gi,"8").replace(/sep/gi,"9").replace(/oct/gi,"10").replace(/nov/gi,"11").replace(/dec/gi,"12")}handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@yearly"||t==="@annually")return"0 0 1 1 *";if(t==="@monthly")return"0 0 1 * *";if(t==="@weekly")return"0 0 * * 0";if(t==="@daily"||t==="@midnight")return"0 0 * * *";if(t==="@hourly")return"0 * * * *";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 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]|R[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var x=[31,28,31,30,31,30,31,31,30,31,30,31],c=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],y=class s{tz;afterMs;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 s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?x[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r-2:i===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r===n?r-2:r+1:a===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let a=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let h=1;h<=r;h++)new Date(Date.UTC(e,t,h)).getUTCDay()===a&&o++;if(n&63&&R[o-1]&n)return!0;if(n&32){let h=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=h;l++)if(new Date(Date.UTC(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=g(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.afterMs=e.getTime()}catch(t){let r=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: ${r}`)}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()}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.afterMs=e.afterMs}apply(){if(this.month>11||this.month<0||this.day>x[this.month]||this.day<1||this.hour>59||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return 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"){let t=M(e);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(M(e,this.tz))}findNext(e,t,r,n){return this._findMatch(e,t,r,n,1)}_findMatch(e,t,r,n,i){let a=this[t],o;r.lastDayOfMonth&&(o=this.getLastDayOfMonth(this.year,this.month));let h=!r.starDOW&&t=="day"?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0,l=this[t]+n,m=i===1?u=>u<r[t].length:u=>u>=0;for(let u=l;m(u);u+=i){let d=r[t][u];if(t==="day"&&!d){for(let f=0;f<r.nearestWeekdays.length;f++)if(r.nearestWeekdays[f]){let C=this.getNearestWeekday(this.year,this.month,f-n);if(C===-1)continue;if(C===u-n){d=1;break}}}if(t==="day"&&r.lastWeekday){let f=this.getLastWeekday(this.year,this.month);u-n===f&&(d=1)}if(t==="day"&&r.lastDayOfMonth&&u-n==o&&(d=1),t==="day"&&!r.starDOW){let f=r.dayOfWeek[(h+(u-n-1))%7];if(f&&f&63)f=this.isNthWeekdayOfMonth(this.year,this.month,u-n,f)?1:0;else if(f)throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${f}`);r.useAndLogic?d=d&&f:!e.domAndDow&&!r.starDOM?d=d||f:d=d&&f}if(d)return this[t]=u-n,a!==this[t]?2:1}return 3}recurse(e,t,r){if(r===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 n=this.findNext(t,c[r][0],e,c[r][2]);if(n>1){let i=r+1;for(;i<c.length;)this[c[i][0]]=-c[i][2],i++;if(n===3){if(this[c[r][1]]++,this[c[r][0]]=-c[r][2],this.apply(),r===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 this.recurse(e,t,0)}else if(this.apply())return this.recurse(e,t,r-1)}return r+=1,r>=c.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:this.recurse(e,t,r)}increment(e,t,r){return this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0,0)}recurseBackward(e,t,r,n=0){if(n>1e4)return null;if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let a=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){a=o;break}if(a===-1)return null;this.year=a,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 i=this.findPrevious(t,c[r][0],e,c[r][2]);if(i>1){let a=r+1;for(;a<c.length;){let o=c[a][0],h=c[a][2],l=this.getMaxPatternValue(o,e,h);this[o]=l,a++}if(i===3){if(this[c[r][1]]--,r===0){let m=this.getLastDayOfMonth(this.year,this.month);this.day>m&&(this.day=m)}if(r===1)if(this.day<=0)this.day=1;else{let m=this.year,u=this.month;for(;u<0;)u+=12,m--;for(;u>11;)u-=12,m++;let d=u!==1?x[u]:new Date(Date.UTC(m,u+1,0)).getUTCDate();this.day>d&&(this.day=d)}this.apply();let o=c[r][0],h=c[r][2],l=this.getMaxPatternValue(o,e,h);if(o==="day"){let m=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,m)}else this[o]=l;if(this.apply(),r===0){let m=c[1][2],u=this.getMaxPatternValue("day",e,m),d=this.getLastDayOfMonth(this.year,this.month),f=Math.min(u,d);f!==this.day&&(this.day=f,this.hour=this.getMaxPatternValue("hour",e,c[2][2]),this.minute=this.getMaxPatternValue("minute",e,c[3][2]),this.second=this.getMaxPatternValue("second",e,c[4][2]))}if(r===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 this.recurseBackward(e,t,0,n+1)}else if(this.apply())return this.recurseBackward(e,t,r-1,n+1)}return r+=1,r>=c.length?this:this.year<0?null:this.recurseBackward(e,t,r,n+1)}getMaxPatternValue(e,t,r){if(e==="day"&&t.lastDayOfMonth)return this.getLastDayOfMonth(this.year,this.month);if(e==="day"&&!t.starDOW)return this.getLastDayOfMonth(this.year,this.month);for(let n=t[e].length-1;n>=0;n--)if(t[e][n])return n-r;return t[e].length-1-r}findPrevious(e,t,r,n){return this._findMatch(e,t,r,n,-1)}getDate(e,t){let r=t??this.afterMs;return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):N(v(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1,r)}getTime(e){return this.getDate(!1,e).getTime()}setAfterMs(e){this.afterMs=e}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let r=0;r<c.length;r++){let n=c[r][0],i=c[r][2],a=this[n];if(a+i<0||a+i>=e[n].length)return!1;let o=e[n][a+i];if(n==="day"){if(!o){for(let h=0;h<e.nearestWeekdays.length;h++)if(e.nearestWeekdays[h]){let l=this.getNearestWeekday(this.year,this.month,h-i);if(l!==-1&&l===a){o=1;break}}}if(e.lastWeekday){let h=this.getLastWeekday(this.year,this.month);a===h&&(o=1)}if(e.lastDayOfMonth){let h=this.getLastDayOfMonth(this.year,this.month);a===h&&(o=1)}if(!e.starDOW){let h=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),l=e.dayOfWeek[(h+(a-1))%7];l&&l&63&&(l=this.isNthWeekdayOfMonth(this.year,this.month,a,l)?1:0),e.useAndLogic?o=o&&l:!t.domAndDow&&!e.starDOM?o=o||l:o=o&&l}}if(!o)return!1}return!0}};function E(s){if(s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow,s.paused=s.paused===void 0?!1:s.paused,s.maxRuns=s.maxRuns===void 0?1/0:s.maxRuns,s.catch=s.catch===void 0?!1:s.catch,s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),s.unref=s.unref===void 0?!1:s.unref,s.mode=s.mode===void 0?"auto":s.mode,s.alternativeWeekdays=s.alternativeWeekdays===void 0?!1:s.alternativeWeekdays,s.sloppyRanges=s.sloppyRanges===void 0?!1:s.sloppyRanges,s.allowPast=s.allowPast===void 0?!1:s.allowPast,!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.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(s.startAt&&(s.startAt=new y(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new y(s.stopAt,s.timezone)),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}function T(s){return Object.prototype.toString.call(s)==="[object Function]"||typeof s=="function"||s instanceof Function}function A(s){return T(s)}function U(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var S=30*1e3,w=[],W=class{name;options;_states;fn;getTz(){return this.options.timezone||this.options.utcOffset}applyDayOffset(e){if(this.options.dayOffset!==void 0&&this.options.dayOffset!==0){let t=this.options.dayOffset*24*60*60*1e3;return new Date(e.getTime()+t)}return e}constructor(e,t,r){let n,i;if(T(t))i=t;else if(typeof t=="object")n=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(T(r))i=r;else if(typeof r=="object")n=r;else if(r!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");if(this.name=n?.name,this.options=E(n),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:n?n.maxRuns:void 0,paused:n?n.paused:!1,pattern:new p("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new y(e,this.getTz()):this._states.pattern=new p(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(w.find(o=>o.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&&A(i)&&(this.fn=i,this.schedule()),this}nextRun(e){let t=this._next(e);return t?this.applyDayOffset(t.getDate(!1)):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}_enumerateRuns(e,t,r){let n=[],i=t?new y(t,this.getTz()):null,a=r==="next"?this._next:this._previous;for(;e--;){let o=a.call(this,i);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),i=o}return n}match(e){if(this._states.once){let r=new y(e,this.getTz());r.ms=0;let n=new y(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.getTime()}let t=new y(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(){let e=this.nextRun(this._states.currentRun),t=!this._states.paused,r=this.fn!==void 0,n=!this._states.kill;return t&&r&&n&&e!==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=this._next(e);return t?e instanceof y||e instanceof Date?t.getTime()-e.getTime():t.getTime()-new y(e).getTime():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){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 t=this.msToNext(),r=this.nextRun(this._states.currentRun);return t==null||isNaN(t)||r===null?this:(t>S&&(t=S),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(r),t),this._states.currentTimeout&&this.options.unref&&U(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new y(void 0,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(T(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new y(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,r=!this._states.paused&&t.getTime()>=e.getTime(),n=this._states.blocking&&this.options.protect;r&&!n?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger()):r&&n&&T(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this.schedule()}_next(e){let t=!!(e||this._states.currentRun),r=!1;!e&&this.options.startAt&&this.options.interval&&([e,t]=this._calculatePreviousRun(e,t),r=!e),e=new y(e,this.getTz()),this.options.startAt&&e&&e.getTime()<this.options.startAt.getTime()&&(e=this.options.startAt);let n=this._states.once||new y(e,this.getTz());if(!r&&n!==this._states.once&&(n=n.increment(this._states.pattern,this.options,t)),this._states.once){if(this._states.currentRun&&this._states.once.getTime()<=this._states.currentRun.getTime()||e.getTime()===this._states.once.getTime())return null;let i=e.getTime()-this._states.once.getTime();if(i>0&&!this.options.allowPast&&i>1e3)return null}if(n!==null&&n!==this._states.once&&typeof this.getTz()=="string"){let i=e.getTime(),a=n.getTime(),o=(this.options.interval&&t?this.options.interval:1)*1e3,h=a-i;if(h>=o+36e5||h<0){let l=h<0?a+36e5:a-36e5,m=new Date(l),u=new y(m,this.getTz());u.match(this._states.pattern,this.options)&&l>i&&(u.setAfterMs(i),n=u)}}return n===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||this.options.stopAt&&n.getTime()>=this.options.stopAt.getTime()?null:n}_previous(e){let t=new y(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new y(t,this.getTz());return this._states.once?this._states.once.getTime()<t.getTime()?this._states.once:null:(r=r.decrement(this._states.pattern,this.options),r===null||this.options.startAt&&r.getTime()<this.options.startAt.getTime()?null:r)}_calculatePreviousRun(e,t){let r=new y(void 0,this.getTz()),n=e;if(this.options.startAt.getTime()<=r.getTime()){n=this.options.startAt;let i=n.getTime()+this.options.interval*1e3;for(;i<=r.getTime();)n=new y(n,this.getTz()).increment(this._states.pattern,this.options,!0),i=n.getTime()+this.options.interval*1e3;t=!0}return n===null&&(n=void 0),[n,t]}};0&&(module.exports={Cron,CronDate,CronPattern,scheduledJobs});
|
package/dist/croner.d.cts
CHANGED
|
@@ -271,6 +271,13 @@ export interface CronOptions<T = undefined> {
|
|
|
271
271
|
* @default false
|
|
272
272
|
*/
|
|
273
273
|
sloppyRanges?: boolean;
|
|
274
|
+
/**
|
|
275
|
+
* If true, date-based jobs scheduled in the past will fire immediately.
|
|
276
|
+
* If false, only jobs scheduled within the past second will fire immediately (to handle timing edge cases).
|
|
277
|
+
* Jobs scheduled more than 1 second in the past will be rejected unless this is true.
|
|
278
|
+
* @default false
|
|
279
|
+
*/
|
|
280
|
+
allowPast?: boolean;
|
|
274
281
|
}
|
|
275
282
|
/**
|
|
276
283
|
* Converts date to CronDate
|
|
@@ -280,6 +287,13 @@ export interface CronOptions<T = undefined> {
|
|
|
280
287
|
*/
|
|
281
288
|
export declare class CronDate<T = undefined> {
|
|
282
289
|
tz: string | number | undefined;
|
|
290
|
+
/**
|
|
291
|
+
* Optional UTC ms threshold for resolving DST overlap ambiguity.
|
|
292
|
+
* When set, getTime()/getDate() will return the earliest occurrence
|
|
293
|
+
* that is at or after this threshold.
|
|
294
|
+
* @private
|
|
295
|
+
*/
|
|
296
|
+
private afterMs?;
|
|
283
297
|
/**
|
|
284
298
|
* Current milliseconds
|
|
285
299
|
* @type {number}
|
|
@@ -480,12 +494,23 @@ export declare class CronDate<T = undefined> {
|
|
|
480
494
|
* Convert current state back to a javascript Date()
|
|
481
495
|
*
|
|
482
496
|
* @param internal If this is an internal call
|
|
497
|
+
* @param afterMs Optional UTC ms threshold for resolving DST overlap ambiguity
|
|
483
498
|
*/
|
|
484
|
-
getDate(internal?: boolean): Date;
|
|
499
|
+
getDate(internal?: boolean, afterMs?: number): Date;
|
|
485
500
|
/**
|
|
486
501
|
* Convert current state back to a javascript Date() and return UTC milliseconds
|
|
502
|
+
*
|
|
503
|
+
* @param afterMs Optional UTC ms threshold for resolving DST overlap ambiguity
|
|
504
|
+
*/
|
|
505
|
+
getTime(afterMs?: number): number;
|
|
506
|
+
/**
|
|
507
|
+
* Set the afterMs threshold for DST overlap resolution.
|
|
508
|
+
* When set, getTime()/getDate() will return the earliest occurrence
|
|
509
|
+
* that is at or after this threshold.
|
|
510
|
+
*
|
|
511
|
+
* @param ms UTC milliseconds threshold
|
|
487
512
|
*/
|
|
488
|
-
|
|
513
|
+
setAfterMs(ms: number): void;
|
|
489
514
|
/**
|
|
490
515
|
* Check if the current CronDate matches a cron pattern
|
|
491
516
|
*
|
package/dist/croner.d.ts
CHANGED
|
@@ -271,6 +271,13 @@ export interface CronOptions<T = undefined> {
|
|
|
271
271
|
* @default false
|
|
272
272
|
*/
|
|
273
273
|
sloppyRanges?: boolean;
|
|
274
|
+
/**
|
|
275
|
+
* If true, date-based jobs scheduled in the past will fire immediately.
|
|
276
|
+
* If false, only jobs scheduled within the past second will fire immediately (to handle timing edge cases).
|
|
277
|
+
* Jobs scheduled more than 1 second in the past will be rejected unless this is true.
|
|
278
|
+
* @default false
|
|
279
|
+
*/
|
|
280
|
+
allowPast?: boolean;
|
|
274
281
|
}
|
|
275
282
|
/**
|
|
276
283
|
* Converts date to CronDate
|
|
@@ -280,6 +287,13 @@ export interface CronOptions<T = undefined> {
|
|
|
280
287
|
*/
|
|
281
288
|
export declare class CronDate<T = undefined> {
|
|
282
289
|
tz: string | number | undefined;
|
|
290
|
+
/**
|
|
291
|
+
* Optional UTC ms threshold for resolving DST overlap ambiguity.
|
|
292
|
+
* When set, getTime()/getDate() will return the earliest occurrence
|
|
293
|
+
* that is at or after this threshold.
|
|
294
|
+
* @private
|
|
295
|
+
*/
|
|
296
|
+
private afterMs?;
|
|
283
297
|
/**
|
|
284
298
|
* Current milliseconds
|
|
285
299
|
* @type {number}
|
|
@@ -480,12 +494,23 @@ export declare class CronDate<T = undefined> {
|
|
|
480
494
|
* Convert current state back to a javascript Date()
|
|
481
495
|
*
|
|
482
496
|
* @param internal If this is an internal call
|
|
497
|
+
* @param afterMs Optional UTC ms threshold for resolving DST overlap ambiguity
|
|
483
498
|
*/
|
|
484
|
-
getDate(internal?: boolean): Date;
|
|
499
|
+
getDate(internal?: boolean, afterMs?: number): Date;
|
|
485
500
|
/**
|
|
486
501
|
* Convert current state back to a javascript Date() and return UTC milliseconds
|
|
502
|
+
*
|
|
503
|
+
* @param afterMs Optional UTC ms threshold for resolving DST overlap ambiguity
|
|
504
|
+
*/
|
|
505
|
+
getTime(afterMs?: number): number;
|
|
506
|
+
/**
|
|
507
|
+
* Set the afterMs threshold for DST overlap resolution.
|
|
508
|
+
* When set, getTime()/getDate() will return the earliest occurrence
|
|
509
|
+
* that is at or after this threshold.
|
|
510
|
+
*
|
|
511
|
+
* @param ms UTC milliseconds threshold
|
|
487
512
|
*/
|
|
488
|
-
|
|
513
|
+
setAfterMs(ms: number): void;
|
|
489
514
|
/**
|
|
490
515
|
* Check if the current CronDate matches a cron pattern
|
|
491
516
|
*
|
package/dist/croner.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function T(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function D(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function A(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");let r=s.substring(9);return r.includes("Z")||r.includes("+")||r.includes("-")?b(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):b(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function v(s,e,t){return k(A(s,e),t)}function k(s,e){let t=new Date(T(s)),r=g(t,s.tz),n=T(s),i=T(r),a=n-i,o=new Date(t.getTime()+a),h=g(o,s.tz);if(D(h,s)){let u=new Date(o.getTime()-36e5),d=g(u,s.tz);return D(d,s)?u:o}let l=new Date(o.getTime()+T(s)-T(h)),y=g(l,s.tz);if(D(y,s))return l;if(e)throw new Error("Invalid date passed to fromTZ()");return o.getTime()>l.getTime()?o:l}function g(s,e){let t,r;try{t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),r=t.formatToParts(s)}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 n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of r)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(n[i.type]=parseInt(i.value,10));if(isNaN(n.year)||isNaN(n.month)||isNaN(n.day)||isNaN(n.hour)||isNaN(n.minute)||isNaN(n.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(n)}`);return n.hour===24&&(n.hour=0),{y:n.year,m:n.month,d:n.day,h:n.hour,i:n.minute,s:n.second,tz:e}}function b(s,e,t,r,n,i,a){return{y:s,m:e,d:t,h:r,i:n,s:i,tz:a}}var O=[1,2,4,8,16],C=class{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,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=Array(1e4).fill(0),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.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 n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let a=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${a} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlphaMonths(e[4])),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlphaDaysQuartz(e[5]):this.replaceAlphaDays(e[5])),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.pattern.indexOf("?")>=0&&(e[0]=e[0].replace(/\?/g,"*"),e[1]=e[1].replace(/\?/g,"*"),e[2]=e[2].replace(/\?/g,"*"),e[3]=e[3].replace(/\?/g,"*"),e[4]=e[4].replace(/\?/g,"*"),e[5]=e[5].replace(/\?/g,"*"),e[6]&&(e[6]=e[6].replace(/\?/g,"*"))),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 r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,r,n){let i=this[e],a=e==="day"&&this.lastDayOfMonth,o=e==="day"&&this.lastWeekday;if(t===""&&!a&&!o)throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(n);let h=t.split(",");if(h.length>1)for(let l=0;l<h.length;l++)this.partToArray(e,h[l],r,n);else t.indexOf("-")!==-1&&t.indexOf("/")!==-1?this.handleRangeWithStepping(t,e,r,n):t.indexOf("-")!==-1?this.handleRange(t,e,r,n):t.indexOf("/")!==-1?this.handleStepping(t,e,r,n):t!==""&&this.handleNumber(t,e,r,n)}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,r,n){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=parseInt(i[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,i[1]||n)}setPart(e,t,r){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,r);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]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,n,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[n].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[n].length+")")}}handleRangeWithStepping(e,t,r,n){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,h,l]=a,y=parseInt(o,10)+r,u=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(y,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(y,u,d,t,e);for(let c=y;c<=u;c+=d)this.setPart(t,c,i[1]||n)}extractNth(e,t){let r=e,n;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");n=r.split("#")[1],r=r.split("#")[0]}else if(r.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)");n="L",r=r.slice(0,-1)}return[r,n]}handleRange(e,t,r,n){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=parseInt(a[0],10)+r,h=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(h,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,h,void 0,t,e);for(let l=o;l<=h;l++)this.setPart(t,l,i[1]||n)}handleStepping(e,t,r,n){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=parseInt(a[0],10)+r);let h=parseInt(a[1],10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,h,t,e);for(let l=o;l<this[t].length;l+=h)this.setPart(t,l,i[1]||n)}replaceAlphaDays(e){return e.replace(/-sun/gi,"-7").replace(/sun/gi,"0").replace(/mon/gi,"1").replace(/tue/gi,"2").replace(/wed/gi,"3").replace(/thu/gi,"4").replace(/fri/gi,"5").replace(/sat/gi,"6")}replaceAlphaDaysQuartz(e){return e.replace(/sun/gi,"1").replace(/mon/gi,"2").replace(/tue/gi,"3").replace(/wed/gi,"4").replace(/thu/gi,"5").replace(/fri/gi,"6").replace(/sat/gi,"7")}replaceAlphaMonths(e){return e.replace(/jan/gi,"1").replace(/feb/gi,"2").replace(/mar/gi,"3").replace(/apr/gi,"4").replace(/may/gi,"5").replace(/jun/gi,"6").replace(/jul/gi,"7").replace(/aug/gi,"8").replace(/sep/gi,"9").replace(/oct/gi,"10").replace(/nov/gi,"11").replace(/dec/gi,"12")}handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@yearly"||t==="@annually")return"0 0 1 1 *";if(t==="@monthly")return"0 0 1 * *";if(t==="@weekly")return"0 0 * * 0";if(t==="@daily"||t==="@midnight")return"0 0 * * *";if(t==="@hourly")return"0 * * * *";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 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]|O[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var P=[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 s{tz;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 s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?P[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r-2:i===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r===n?r-2:r+1:a===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let a=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let h=1;h<=r;h++)new Date(Date.UTC(e,t,h)).getUTCDay()===a&&o++;if(n&63&&O[o-1]&n)return!0;if(n&32){let h=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=h;l++)if(new Date(Date.UTC(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=g(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}catch(t){let r=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: ${r}`)}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()}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}apply(){if(this.month>11||this.month<0||this.day>P[this.month]||this.day<1||this.hour>59||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return 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"){let t=v(e);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,r,n){return this._findMatch(e,t,r,n,1)}_findMatch(e,t,r,n,i){let a=this[t],o;r.lastDayOfMonth&&(o=this.getLastDayOfMonth(this.year,this.month));let h=!r.starDOW&&t=="day"?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0,l=this[t]+n,y=i===1?u=>u<r[t].length:u=>u>=0;for(let u=l;y(u);u+=i){let d=r[t][u];if(t==="day"&&!d){for(let c=0;c<r.nearestWeekdays.length;c++)if(r.nearestWeekdays[c]){let M=this.getNearestWeekday(this.year,this.month,c-n);if(M===-1)continue;if(M===u-n){d=1;break}}}if(t==="day"&&r.lastWeekday){let c=this.getLastWeekday(this.year,this.month);u-n===c&&(d=1)}if(t==="day"&&r.lastDayOfMonth&&u-n==o&&(d=1),t==="day"&&!r.starDOW){let c=r.dayOfWeek[(h+(u-n-1))%7];if(c&&c&63)c=this.isNthWeekdayOfMonth(this.year,this.month,u-n,c)?1:0;else if(c)throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${c}`);r.useAndLogic?d=d&&c:!e.domAndDow&&!r.starDOM?d=d||c:d=d&&c}if(d)return this[t]=u-n,a!==this[t]?2:1}return 3}recurse(e,t,r){if(r===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 n=this.findNext(t,f[r][0],e,f[r][2]);if(n>1){let i=r+1;for(;i<f.length;)this[f[i][0]]=-f[i][2],i++;if(n===3){if(this[f[r][1]]++,this[f[r][0]]=-f[r][2],this.apply(),r===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 this.recurse(e,t,0)}else if(this.apply())return this.recurse(e,t,r-1)}return r+=1,r>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:this.recurse(e,t,r)}increment(e,t,r){return this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0,0)}recurseBackward(e,t,r,n=0){if(n>1e4)return null;if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let a=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){a=o;break}if(a===-1)return null;this.year=a,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 i=this.findPrevious(t,f[r][0],e,f[r][2]);if(i>1){let a=r+1;for(;a<f.length;){let o=f[a][0],h=f[a][2],l=this.getMaxPatternValue(o,e,h);this[o]=l,a++}if(i===3){if(this[f[r][1]]--,r===0){let y=this.getLastDayOfMonth(this.year,this.month);this.day>y&&(this.day=y)}if(r===1)if(this.day<=0)this.day=1;else{let y=this.year,u=this.month;for(;u<0;)u+=12,y--;for(;u>11;)u-=12,y++;let d=u!==1?P[u]:new Date(Date.UTC(y,u+1,0)).getUTCDate();this.day>d&&(this.day=d)}this.apply();let o=f[r][0],h=f[r][2],l=this.getMaxPatternValue(o,e,h);if(o==="day"){let y=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,y)}else this[o]=l;if(this.apply(),r===0){let y=f[1][2],u=this.getMaxPatternValue("day",e,y),d=this.getLastDayOfMonth(this.year,this.month),c=Math.min(u,d);c!==this.day&&(this.day=c,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(r===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 this.recurseBackward(e,t,0,n+1)}else if(this.apply())return this.recurseBackward(e,t,r-1,n+1)}return r+=1,r>=f.length?this:this.year<0?null:this.recurseBackward(e,t,r,n+1)}getMaxPatternValue(e,t,r){if(e==="day"&&t.lastDayOfMonth)return this.getLastDayOfMonth(this.year,this.month);if(e==="day"&&!t.starDOW)return this.getLastDayOfMonth(this.year,this.month);for(let n=t[e].length-1;n>=0;n--)if(t[e][n])return n-r;return t[e].length-1-r}findPrevious(e,t,r,n){return this._findMatch(e,t,r,n,-1)}getDate(e){return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):k(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 r=0;r<f.length;r++){let n=f[r][0],i=f[r][2],a=this[n];if(a+i<0||a+i>=e[n].length)return!1;let o=e[n][a+i];if(n==="day"){if(!o){for(let h=0;h<e.nearestWeekdays.length;h++)if(e.nearestWeekdays[h]){let l=this.getNearestWeekday(this.year,this.month,h-i);if(l!==-1&&l===a){o=1;break}}}if(e.lastWeekday){let h=this.getLastWeekday(this.year,this.month);a===h&&(o=1)}if(e.lastDayOfMonth){let h=this.getLastDayOfMonth(this.year,this.month);a===h&&(o=1)}if(!e.starDOW){let h=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),l=e.dayOfWeek[(h+(a-1))%7];l&&l&63&&(l=this.isNthWeekdayOfMonth(this.year,this.month,a,l)?1:0),e.useAndLogic?o=o&&l:!t.domAndDow&&!e.starDOM?o=o||l:o=o&&l}}if(!o)return!1}return!0}};function R(s){if(s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow,s.paused=s.paused===void 0?!1:s.paused,s.maxRuns=s.maxRuns===void 0?1/0:s.maxRuns,s.catch=s.catch===void 0?!1:s.catch,s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),s.unref=s.unref===void 0?!1:s.unref,s.mode=s.mode===void 0?"auto":s.mode,s.alternativeWeekdays=s.alternativeWeekdays===void 0?!1:s.alternativeWeekdays,s.sloppyRanges=s.sloppyRanges===void 0?!1:s.sloppyRanges,!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.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(s.startAt&&(s.startAt=new m(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new m(s.stopAt,s.timezone)),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}function p(s){return Object.prototype.toString.call(s)==="[object Function]"||typeof s=="function"||s instanceof Function}function _(s){return p(s)}function x(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var W=30*1e3,w=[],E=class{name;options;_states;fn;getTz(){return this.options.timezone||this.options.utcOffset}applyDayOffset(e){if(this.options.dayOffset!==void 0&&this.options.dayOffset!==0){let t=this.options.dayOffset*24*60*60*1e3;return new Date(e.getTime()+t)}return e}constructor(e,t,r){let n,i;if(p(t))i=t;else if(typeof t=="object")n=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(p(r))i=r;else if(typeof r=="object")n=r;else if(r!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");if(this.name=n?.name,this.options=R(n),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:n?n.maxRuns:void 0,paused:n?n.paused:!1,pattern:new C("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new m(e,this.getTz()):this._states.pattern=new C(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(w.find(o=>o.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&&_(i)&&(this.fn=i,this.schedule()),this}nextRun(e){let t=this._next(e);return t?this.applyDayOffset(t.getDate(!1)):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}_enumerateRuns(e,t,r){let n=[],i=t?new m(t,this.getTz()):null,a=r==="next"?this._next:this._previous;for(;e--;){let o=a.call(this,i);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),i=o}return n}match(e){if(this._states.once){let r=new m(e,this.getTz());r.ms=0;let n=new m(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.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(){let e=this.nextRun(this._states.currentRun),t=!this._states.paused,r=this.fn!==void 0,n=!this._states.kill;return t&&r&&n&&e!==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=this._next(e);return t?e instanceof m||e instanceof Date?t.getTime()-e.getTime():t.getTime()-new m(e).getTime():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){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 t=this.msToNext(),r=this.nextRun(this._states.currentRun);return t==null||isNaN(t)||r===null?this:(t>W&&(t=W),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(r),t),this._states.currentTimeout&&this.options.unref&&x(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new m(void 0,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(p(this.options.catch))try{this.options.catch(t,this)}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,r=!this._states.paused&&t.getTime()>=e.getTime(),n=this._states.blocking&&this.options.protect;r&&!n?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger()):r&&n&&p(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this.schedule()}_next(e){let t=!!(e||this._states.currentRun),r=!1;!e&&this.options.startAt&&this.options.interval&&([e,t]=this._calculatePreviousRun(e,t),r=!e),e=new m(e,this.getTz()),this.options.startAt&&e&&e.getTime()<this.options.startAt.getTime()&&(e=this.options.startAt);let n=this._states.once||new m(e,this.getTz());return!r&&n!==this._states.once&&(n=n.increment(this._states.pattern,this.options,t)),this._states.once&&this._states.once.getTime()<=e.getTime()||n===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||this.options.stopAt&&n.getTime()>=this.options.stopAt.getTime()?null:n}_previous(e){let t=new m(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new m(t,this.getTz());return this._states.once?this._states.once.getTime()<t.getTime()?this._states.once:null:(r=r.decrement(this._states.pattern,this.options),r===null||this.options.startAt&&r.getTime()<this.options.startAt.getTime()?null:r)}_calculatePreviousRun(e,t){let r=new m(void 0,this.getTz()),n=e;if(this.options.startAt.getTime()<=r.getTime()){n=this.options.startAt;let i=n.getTime()+this.options.interval*1e3;for(;i<=r.getTime();)n=new m(n,this.getTz()).increment(this._states.pattern,this.options,!0),i=n.getTime()+this.options.interval*1e3;t=!0}return n===null&&(n=void 0),[n,t]}};export{E as Cron,m as CronDate,C as CronPattern,w as scheduledJobs};
|
|
1
|
+
function C(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function w(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function L(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");let r=s.substring(9);return r.includes("Z")||r.includes("+")||r.includes("-")?D(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):D(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function P(s,e,t){return M(L(s,e),t)}function M(s,e,t){let r=new Date(C(s)),n=g(r,s.tz),i=C(s),a=C(n),o=i-a,h=new Date(r.getTime()+o),l=g(h,s.tz);if(w(l,s)){let d=new Date(h.getTime()-36e5),f=g(d,s.tz),T=new Date(h.getTime()+36e5),S=g(T,s.tz),k=w(f,s),z=w(S,s);if(k||z){let O=k?d:h,I=k?h:T;return t!==void 0?O.getTime()>=t?O:I:O}return h}let m=new Date(h.getTime()+C(s)-C(l)),u=g(m,s.tz);if(w(u,s))return m;if(e)throw new Error("Invalid date passed to fromTZ()");return h.getTime()>m.getTime()?h:m}function g(s,e){let t,r;try{t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),r=t.formatToParts(s)}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 n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of r)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(n[i.type]=parseInt(i.value,10));if(isNaN(n.year)||isNaN(n.month)||isNaN(n.day)||isNaN(n.hour)||isNaN(n.minute)||isNaN(n.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(n)}`);return n.hour===24&&(n.hour=0),{y:n.year,m:n.month,d:n.day,h:n.hour,i:n.minute,s:n.second,tz:e}}function D(s,e,t,r,n,i,a){return{y:s,m:e,d:t,h:r,i:n,s:i,tz:a}}var N=[1,2,4,8,16],b=class{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,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=Array(1e4).fill(0),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.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 n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let a=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${a} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlphaMonths(e[4])),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlphaDaysQuartz(e[5]):this.replaceAlphaDays(e[5])),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.pattern.indexOf("?")>=0&&(e[0]=e[0].replace(/\?/g,"*"),e[1]=e[1].replace(/\?/g,"*"),e[2]=e[2].replace(/\?/g,"*"),e[3]=e[3].replace(/\?/g,"*"),e[4]=e[4].replace(/\?/g,"*"),e[5]=e[5].replace(/\?/g,"*"),e[6]&&(e[6]=e[6].replace(/\?/g,"*"))),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 r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,r,n){let i=this[e],a=e==="day"&&this.lastDayOfMonth,o=e==="day"&&this.lastWeekday;if(t===""&&!a&&!o)throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(n);let h=t.split(",");if(h.length>1)for(let l=0;l<h.length;l++)this.partToArray(e,h[l],r,n);else t.indexOf("-")!==-1&&t.indexOf("/")!==-1?this.handleRangeWithStepping(t,e,r,n):t.indexOf("-")!==-1?this.handleRange(t,e,r,n):t.indexOf("/")!==-1?this.handleStepping(t,e,r,n):t!==""&&this.handleNumber(t,e,r,n)}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,r,n){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=parseInt(i[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,i[1]||n)}setPart(e,t,r){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,r);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]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,n,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[n].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[n].length+")")}}handleRangeWithStepping(e,t,r,n){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,h,l]=a,m=parseInt(o,10)+r,u=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(m,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(m,u,d,t,e);for(let f=m;f<=u;f+=d)this.setPart(t,f,i[1]||n)}extractNth(e,t){let r=e,n;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");n=r.split("#")[1],r=r.split("#")[0]}else if(r.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)");n="L",r=r.slice(0,-1)}return[r,n]}handleRange(e,t,r,n){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=parseInt(a[0],10)+r,h=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(h,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,h,void 0,t,e);for(let l=o;l<=h;l++)this.setPart(t,l,i[1]||n)}handleStepping(e,t,r,n){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=parseInt(a[0],10)+r);let h=parseInt(a[1],10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,h,t,e);for(let l=o;l<this[t].length;l+=h)this.setPart(t,l,i[1]||n)}replaceAlphaDays(e){return e.replace(/-sun/gi,"-7").replace(/sun/gi,"0").replace(/mon/gi,"1").replace(/tue/gi,"2").replace(/wed/gi,"3").replace(/thu/gi,"4").replace(/fri/gi,"5").replace(/sat/gi,"6")}replaceAlphaDaysQuartz(e){return e.replace(/sun/gi,"1").replace(/mon/gi,"2").replace(/tue/gi,"3").replace(/wed/gi,"4").replace(/thu/gi,"5").replace(/fri/gi,"6").replace(/sat/gi,"7")}replaceAlphaMonths(e){return e.replace(/jan/gi,"1").replace(/feb/gi,"2").replace(/mar/gi,"3").replace(/apr/gi,"4").replace(/may/gi,"5").replace(/jun/gi,"6").replace(/jul/gi,"7").replace(/aug/gi,"8").replace(/sep/gi,"9").replace(/oct/gi,"10").replace(/nov/gi,"11").replace(/dec/gi,"12")}handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@yearly"||t==="@annually")return"0 0 1 1 *";if(t==="@monthly")return"0 0 1 * *";if(t==="@weekly")return"0 0 * * 0";if(t==="@daily"||t==="@midnight")return"0 0 * * *";if(t==="@hourly")return"0 * * * *";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 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]|N[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var _=[31,28,31,30,31,30,31,31,30,31,30,31],c=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],y=class s{tz;afterMs;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 s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?_[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r-2:i===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r===n?r-2:r+1:a===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let a=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let h=1;h<=r;h++)new Date(Date.UTC(e,t,h)).getUTCDay()===a&&o++;if(n&63&&N[o-1]&n)return!0;if(n&32){let h=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=h;l++)if(new Date(Date.UTC(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=g(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.afterMs=e.getTime()}catch(t){let r=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: ${r}`)}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()}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.afterMs=e.afterMs}apply(){if(this.month>11||this.month<0||this.day>_[this.month]||this.day<1||this.hour>59||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return 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"){let t=P(e);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(P(e,this.tz))}findNext(e,t,r,n){return this._findMatch(e,t,r,n,1)}_findMatch(e,t,r,n,i){let a=this[t],o;r.lastDayOfMonth&&(o=this.getLastDayOfMonth(this.year,this.month));let h=!r.starDOW&&t=="day"?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0,l=this[t]+n,m=i===1?u=>u<r[t].length:u=>u>=0;for(let u=l;m(u);u+=i){let d=r[t][u];if(t==="day"&&!d){for(let f=0;f<r.nearestWeekdays.length;f++)if(r.nearestWeekdays[f]){let T=this.getNearestWeekday(this.year,this.month,f-n);if(T===-1)continue;if(T===u-n){d=1;break}}}if(t==="day"&&r.lastWeekday){let f=this.getLastWeekday(this.year,this.month);u-n===f&&(d=1)}if(t==="day"&&r.lastDayOfMonth&&u-n==o&&(d=1),t==="day"&&!r.starDOW){let f=r.dayOfWeek[(h+(u-n-1))%7];if(f&&f&63)f=this.isNthWeekdayOfMonth(this.year,this.month,u-n,f)?1:0;else if(f)throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${f}`);r.useAndLogic?d=d&&f:!e.domAndDow&&!r.starDOM?d=d||f:d=d&&f}if(d)return this[t]=u-n,a!==this[t]?2:1}return 3}recurse(e,t,r){if(r===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 n=this.findNext(t,c[r][0],e,c[r][2]);if(n>1){let i=r+1;for(;i<c.length;)this[c[i][0]]=-c[i][2],i++;if(n===3){if(this[c[r][1]]++,this[c[r][0]]=-c[r][2],this.apply(),r===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 this.recurse(e,t,0)}else if(this.apply())return this.recurse(e,t,r-1)}return r+=1,r>=c.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:this.recurse(e,t,r)}increment(e,t,r){return this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0,0)}recurseBackward(e,t,r,n=0){if(n>1e4)return null;if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let a=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){a=o;break}if(a===-1)return null;this.year=a,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 i=this.findPrevious(t,c[r][0],e,c[r][2]);if(i>1){let a=r+1;for(;a<c.length;){let o=c[a][0],h=c[a][2],l=this.getMaxPatternValue(o,e,h);this[o]=l,a++}if(i===3){if(this[c[r][1]]--,r===0){let m=this.getLastDayOfMonth(this.year,this.month);this.day>m&&(this.day=m)}if(r===1)if(this.day<=0)this.day=1;else{let m=this.year,u=this.month;for(;u<0;)u+=12,m--;for(;u>11;)u-=12,m++;let d=u!==1?_[u]:new Date(Date.UTC(m,u+1,0)).getUTCDate();this.day>d&&(this.day=d)}this.apply();let o=c[r][0],h=c[r][2],l=this.getMaxPatternValue(o,e,h);if(o==="day"){let m=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,m)}else this[o]=l;if(this.apply(),r===0){let m=c[1][2],u=this.getMaxPatternValue("day",e,m),d=this.getLastDayOfMonth(this.year,this.month),f=Math.min(u,d);f!==this.day&&(this.day=f,this.hour=this.getMaxPatternValue("hour",e,c[2][2]),this.minute=this.getMaxPatternValue("minute",e,c[3][2]),this.second=this.getMaxPatternValue("second",e,c[4][2]))}if(r===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 this.recurseBackward(e,t,0,n+1)}else if(this.apply())return this.recurseBackward(e,t,r-1,n+1)}return r+=1,r>=c.length?this:this.year<0?null:this.recurseBackward(e,t,r,n+1)}getMaxPatternValue(e,t,r){if(e==="day"&&t.lastDayOfMonth)return this.getLastDayOfMonth(this.year,this.month);if(e==="day"&&!t.starDOW)return this.getLastDayOfMonth(this.year,this.month);for(let n=t[e].length-1;n>=0;n--)if(t[e][n])return n-r;return t[e].length-1-r}findPrevious(e,t,r,n){return this._findMatch(e,t,r,n,-1)}getDate(e,t){let r=t??this.afterMs;return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):M(D(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1,r)}getTime(e){return this.getDate(!1,e).getTime()}setAfterMs(e){this.afterMs=e}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let r=0;r<c.length;r++){let n=c[r][0],i=c[r][2],a=this[n];if(a+i<0||a+i>=e[n].length)return!1;let o=e[n][a+i];if(n==="day"){if(!o){for(let h=0;h<e.nearestWeekdays.length;h++)if(e.nearestWeekdays[h]){let l=this.getNearestWeekday(this.year,this.month,h-i);if(l!==-1&&l===a){o=1;break}}}if(e.lastWeekday){let h=this.getLastWeekday(this.year,this.month);a===h&&(o=1)}if(e.lastDayOfMonth){let h=this.getLastDayOfMonth(this.year,this.month);a===h&&(o=1)}if(!e.starDOW){let h=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),l=e.dayOfWeek[(h+(a-1))%7];l&&l&63&&(l=this.isNthWeekdayOfMonth(this.year,this.month,a,l)?1:0),e.useAndLogic?o=o&&l:!t.domAndDow&&!e.starDOM?o=o||l:o=o&&l}}if(!o)return!1}return!0}};function x(s){if(s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow,s.paused=s.paused===void 0?!1:s.paused,s.maxRuns=s.maxRuns===void 0?1/0:s.maxRuns,s.catch=s.catch===void 0?!1:s.catch,s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),s.unref=s.unref===void 0?!1:s.unref,s.mode=s.mode===void 0?"auto":s.mode,s.alternativeWeekdays=s.alternativeWeekdays===void 0?!1:s.alternativeWeekdays,s.sloppyRanges=s.sloppyRanges===void 0?!1:s.sloppyRanges,s.allowPast=s.allowPast===void 0?!1:s.allowPast,!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.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(s.startAt&&(s.startAt=new y(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new y(s.stopAt,s.timezone)),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}function p(s){return Object.prototype.toString.call(s)==="[object Function]"||typeof s=="function"||s instanceof Function}function W(s){return p(s)}function E(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var A=30*1e3,v=[],U=class{name;options;_states;fn;getTz(){return this.options.timezone||this.options.utcOffset}applyDayOffset(e){if(this.options.dayOffset!==void 0&&this.options.dayOffset!==0){let t=this.options.dayOffset*24*60*60*1e3;return new Date(e.getTime()+t)}return e}constructor(e,t,r){let n,i;if(p(t))i=t;else if(typeof t=="object")n=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(p(r))i=r;else if(typeof r=="object")n=r;else if(r!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");if(this.name=n?.name,this.options=x(n),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:n?n.maxRuns:void 0,paused:n?n.paused:!1,pattern:new b("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new y(e,this.getTz()):this._states.pattern=new b(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(v.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");v.push(this)}return i!==void 0&&W(i)&&(this.fn=i,this.schedule()),this}nextRun(e){let t=this._next(e);return t?this.applyDayOffset(t.getDate(!1)):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}_enumerateRuns(e,t,r){let n=[],i=t?new y(t,this.getTz()):null,a=r==="next"?this._next:this._previous;for(;e--;){let o=a.call(this,i);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),i=o}return n}match(e){if(this._states.once){let r=new y(e,this.getTz());r.ms=0;let n=new y(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.getTime()}let t=new y(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(){let e=this.nextRun(this._states.currentRun),t=!this._states.paused,r=this.fn!==void 0,n=!this._states.kill;return t&&r&&n&&e!==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=this._next(e);return t?e instanceof y||e instanceof Date?t.getTime()-e.getTime():t.getTime()-new y(e).getTime():null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=v.indexOf(this);e>=0&&v.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){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 t=this.msToNext(),r=this.nextRun(this._states.currentRun);return t==null||isNaN(t)||r===null?this:(t>A&&(t=A),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(r),t),this._states.currentTimeout&&this.options.unref&&E(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new y(void 0,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(p(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new y(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,r=!this._states.paused&&t.getTime()>=e.getTime(),n=this._states.blocking&&this.options.protect;r&&!n?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger()):r&&n&&p(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this.schedule()}_next(e){let t=!!(e||this._states.currentRun),r=!1;!e&&this.options.startAt&&this.options.interval&&([e,t]=this._calculatePreviousRun(e,t),r=!e),e=new y(e,this.getTz()),this.options.startAt&&e&&e.getTime()<this.options.startAt.getTime()&&(e=this.options.startAt);let n=this._states.once||new y(e,this.getTz());if(!r&&n!==this._states.once&&(n=n.increment(this._states.pattern,this.options,t)),this._states.once){if(this._states.currentRun&&this._states.once.getTime()<=this._states.currentRun.getTime()||e.getTime()===this._states.once.getTime())return null;let i=e.getTime()-this._states.once.getTime();if(i>0&&!this.options.allowPast&&i>1e3)return null}if(n!==null&&n!==this._states.once&&typeof this.getTz()=="string"){let i=e.getTime(),a=n.getTime(),o=(this.options.interval&&t?this.options.interval:1)*1e3,h=a-i;if(h>=o+36e5||h<0){let l=h<0?a+36e5:a-36e5,m=new Date(l),u=new y(m,this.getTz());u.match(this._states.pattern,this.options)&&l>i&&(u.setAfterMs(i),n=u)}}return n===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||this.options.stopAt&&n.getTime()>=this.options.stopAt.getTime()?null:n}_previous(e){let t=new y(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new y(t,this.getTz());return this._states.once?this._states.once.getTime()<t.getTime()?this._states.once:null:(r=r.decrement(this._states.pattern,this.options),r===null||this.options.startAt&&r.getTime()<this.options.startAt.getTime()?null:r)}_calculatePreviousRun(e,t){let r=new y(void 0,this.getTz()),n=e;if(this.options.startAt.getTime()<=r.getTime()){n=this.options.startAt;let i=n.getTime()+this.options.interval*1e3;for(;i<=r.getTime();)n=new y(n,this.getTz()).increment(this._states.pattern,this.options,!0),i=n.getTime()+this.options.interval*1e3;t=!0}return n===null&&(n=void 0),[n,t]}};export{U as Cron,y as CronDate,b as CronPattern,v as scheduledJobs};
|
package/dist/croner.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Cron=(()=>{var g=(s,e)=>()=>(s&&(e=s(s=0)),e);var j=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);function C(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function k(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function $(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");let r=s.substring(9);return r.includes("Z")||r.includes("+")||r.includes("-")?w(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):w(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function O(s,e,t){return N($(s,e),t)}function N(s,e){let t=new Date(C(s)),r=p(t,s.tz),n=C(s),i=C(r),a=n-i,o=new Date(t.getTime()+a),h=p(o,s.tz);if(k(h,s)){let u=new Date(o.getTime()-36e5),d=p(u,s.tz);return k(d,s)?u:o}let l=new Date(o.getTime()+C(s)-C(h)),y=p(l,s.tz);if(k(y,s))return l;if(e)throw new Error("Invalid date passed to fromTZ()");return o.getTime()>l.getTime()?o:l}function p(s,e){let t,r;try{t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),r=t.formatToParts(s)}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 n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of r)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(n[i.type]=parseInt(i.value,10));if(isNaN(n.year)||isNaN(n.month)||isNaN(n.day)||isNaN(n.hour)||isNaN(n.minute)||isNaN(n.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(n)}`);return n.hour===24&&(n.hour=0),{y:n.year,m:n.month,d:n.day,h:n.hour,i:n.minute,s:n.second,tz:e}}function w(s,e,t,r,n,i,a){return{y:s,m:e,d:t,h:r,i:n,s:i,tz:a}}var E=g(()=>{});var P,b,M=g(()=>{P=[1,2,4,8,16],b=class{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,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=Array(1e4).fill(0),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.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 n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let a=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${a} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlphaMonths(e[4])),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlphaDaysQuartz(e[5]):this.replaceAlphaDays(e[5])),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.pattern.indexOf("?")>=0&&(e[0]=e[0].replace(/\?/g,"*"),e[1]=e[1].replace(/\?/g,"*"),e[2]=e[2].replace(/\?/g,"*"),e[3]=e[3].replace(/\?/g,"*"),e[4]=e[4].replace(/\?/g,"*"),e[5]=e[5].replace(/\?/g,"*"),e[6]&&(e[6]=e[6].replace(/\?/g,"*"))),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 r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,r,n){let i=this[e],a=e==="day"&&this.lastDayOfMonth,o=e==="day"&&this.lastWeekday;if(t===""&&!a&&!o)throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(n);let h=t.split(",");if(h.length>1)for(let l=0;l<h.length;l++)this.partToArray(e,h[l],r,n);else t.indexOf("-")!==-1&&t.indexOf("/")!==-1?this.handleRangeWithStepping(t,e,r,n):t.indexOf("-")!==-1?this.handleRange(t,e,r,n):t.indexOf("/")!==-1?this.handleStepping(t,e,r,n):t!==""&&this.handleNumber(t,e,r,n)}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,r,n){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=parseInt(i[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,i[1]||n)}setPart(e,t,r){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,r);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]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,n,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[n].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[n].length+")")}}handleRangeWithStepping(e,t,r,n){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,h,l]=a,y=parseInt(o,10)+r,u=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(y,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(y,u,d,t,e);for(let c=y;c<=u;c+=d)this.setPart(t,c,i[1]||n)}extractNth(e,t){let r=e,n;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");n=r.split("#")[1],r=r.split("#")[0]}else if(r.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)");n="L",r=r.slice(0,-1)}return[r,n]}handleRange(e,t,r,n){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=parseInt(a[0],10)+r,h=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(h,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,h,void 0,t,e);for(let l=o;l<=h;l++)this.setPart(t,l,i[1]||n)}handleStepping(e,t,r,n){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=parseInt(a[0],10)+r);let h=parseInt(a[1],10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,h,t,e);for(let l=o;l<this[t].length;l+=h)this.setPart(t,l,i[1]||n)}replaceAlphaDays(e){return e.replace(/-sun/gi,"-7").replace(/sun/gi,"0").replace(/mon/gi,"1").replace(/tue/gi,"2").replace(/wed/gi,"3").replace(/thu/gi,"4").replace(/fri/gi,"5").replace(/sat/gi,"6")}replaceAlphaDaysQuartz(e){return e.replace(/sun/gi,"1").replace(/mon/gi,"2").replace(/tue/gi,"3").replace(/wed/gi,"4").replace(/thu/gi,"5").replace(/fri/gi,"6").replace(/sat/gi,"7")}replaceAlphaMonths(e){return e.replace(/jan/gi,"1").replace(/feb/gi,"2").replace(/mar/gi,"3").replace(/apr/gi,"4").replace(/may/gi,"5").replace(/jun/gi,"6").replace(/jul/gi,"7").replace(/aug/gi,"8").replace(/sep/gi,"9").replace(/oct/gi,"10").replace(/nov/gi,"11").replace(/dec/gi,"12")}handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@yearly"||t==="@annually")return"0 0 1 1 *";if(t==="@monthly")return"0 0 1 * *";if(t==="@weekly")return"0 0 * * 0";if(t==="@daily"||t==="@midnight")return"0 0 * * *";if(t==="@hourly")return"0 * * * *";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 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]|P[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}}});var _,f,m,x=g(()=>{E();M();_=[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 s{tz;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 s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?_[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r-2:i===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r===n?r-2:r+1:a===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let a=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let h=1;h<=r;h++)new Date(Date.UTC(e,t,h)).getUTCDay()===a&&o++;if(n&63&&P[o-1]&n)return!0;if(n&32){let h=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=h;l++)if(new Date(Date.UTC(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}catch(t){let r=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: ${r}`)}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()}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}apply(){if(this.month>11||this.month<0||this.day>_[this.month]||this.day<1||this.hour>59||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return 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"){let t=O(e);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(O(e,this.tz))}findNext(e,t,r,n){return this._findMatch(e,t,r,n,1)}_findMatch(e,t,r,n,i){let a=this[t],o;r.lastDayOfMonth&&(o=this.getLastDayOfMonth(this.year,this.month));let h=!r.starDOW&&t=="day"?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0,l=this[t]+n,y=i===1?u=>u<r[t].length:u=>u>=0;for(let u=l;y(u);u+=i){let d=r[t][u];if(t==="day"&&!d){for(let c=0;c<r.nearestWeekdays.length;c++)if(r.nearestWeekdays[c]){let W=this.getNearestWeekday(this.year,this.month,c-n);if(W===-1)continue;if(W===u-n){d=1;break}}}if(t==="day"&&r.lastWeekday){let c=this.getLastWeekday(this.year,this.month);u-n===c&&(d=1)}if(t==="day"&&r.lastDayOfMonth&&u-n==o&&(d=1),t==="day"&&!r.starDOW){let c=r.dayOfWeek[(h+(u-n-1))%7];if(c&&c&63)c=this.isNthWeekdayOfMonth(this.year,this.month,u-n,c)?1:0;else if(c)throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${c}`);r.useAndLogic?d=d&&c:!e.domAndDow&&!r.starDOM?d=d||c:d=d&&c}if(d)return this[t]=u-n,a!==this[t]?2:1}return 3}recurse(e,t,r){if(r===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 n=this.findNext(t,f[r][0],e,f[r][2]);if(n>1){let i=r+1;for(;i<f.length;)this[f[i][0]]=-f[i][2],i++;if(n===3){if(this[f[r][1]]++,this[f[r][0]]=-f[r][2],this.apply(),r===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 this.recurse(e,t,0)}else if(this.apply())return this.recurse(e,t,r-1)}return r+=1,r>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:this.recurse(e,t,r)}increment(e,t,r){return this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0,0)}recurseBackward(e,t,r,n=0){if(n>1e4)return null;if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let a=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){a=o;break}if(a===-1)return null;this.year=a,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 i=this.findPrevious(t,f[r][0],e,f[r][2]);if(i>1){let a=r+1;for(;a<f.length;){let o=f[a][0],h=f[a][2],l=this.getMaxPatternValue(o,e,h);this[o]=l,a++}if(i===3){if(this[f[r][1]]--,r===0){let y=this.getLastDayOfMonth(this.year,this.month);this.day>y&&(this.day=y)}if(r===1)if(this.day<=0)this.day=1;else{let y=this.year,u=this.month;for(;u<0;)u+=12,y--;for(;u>11;)u-=12,y++;let d=u!==1?_[u]:new Date(Date.UTC(y,u+1,0)).getUTCDate();this.day>d&&(this.day=d)}this.apply();let o=f[r][0],h=f[r][2],l=this.getMaxPatternValue(o,e,h);if(o==="day"){let y=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,y)}else this[o]=l;if(this.apply(),r===0){let y=f[1][2],u=this.getMaxPatternValue("day",e,y),d=this.getLastDayOfMonth(this.year,this.month),c=Math.min(u,d);c!==this.day&&(this.day=c,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(r===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 this.recurseBackward(e,t,0,n+1)}else if(this.apply())return this.recurseBackward(e,t,r-1,n+1)}return r+=1,r>=f.length?this:this.year<0?null:this.recurseBackward(e,t,r,n+1)}getMaxPatternValue(e,t,r){if(e==="day"&&t.lastDayOfMonth)return this.getLastDayOfMonth(this.year,this.month);if(e==="day"&&!t.starDOW)return this.getLastDayOfMonth(this.year,this.month);for(let n=t[e].length-1;n>=0;n--)if(t[e][n])return n-r;return t[e].length-1-r}findPrevious(e,t,r,n){return this._findMatch(e,t,r,n,-1)}getDate(e){return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):N(w(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 r=0;r<f.length;r++){let n=f[r][0],i=f[r][2],a=this[n];if(a+i<0||a+i>=e[n].length)return!1;let o=e[n][a+i];if(n==="day"){if(!o){for(let h=0;h<e.nearestWeekdays.length;h++)if(e.nearestWeekdays[h]){let l=this.getNearestWeekday(this.year,this.month,h-i);if(l!==-1&&l===a){o=1;break}}}if(e.lastWeekday){let h=this.getLastWeekday(this.year,this.month);a===h&&(o=1)}if(e.lastDayOfMonth){let h=this.getLastDayOfMonth(this.year,this.month);a===h&&(o=1)}if(!e.starDOW){let h=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),l=e.dayOfWeek[(h+(a-1))%7];l&&l&63&&(l=this.isNthWeekdayOfMonth(this.year,this.month,a,l)?1:0),e.useAndLogic?o=o&&l:!t.domAndDow&&!e.starDOM?o=o||l:o=o&&l}}if(!o)return!1}return!0}}});function A(s){if(s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow,s.paused=s.paused===void 0?!1:s.paused,s.maxRuns=s.maxRuns===void 0?1/0:s.maxRuns,s.catch=s.catch===void 0?!1:s.catch,s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),s.unref=s.unref===void 0?!1:s.unref,s.mode=s.mode===void 0?"auto":s.mode,s.alternativeWeekdays=s.alternativeWeekdays===void 0?!1:s.alternativeWeekdays,s.sloppyRanges=s.sloppyRanges===void 0?!1:s.sloppyRanges,!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.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(s.startAt&&(s.startAt=new m(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new m(s.stopAt,s.timezone)),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}var U=g(()=>{x()});function T(s){return Object.prototype.toString.call(s)==="[object Function]"||typeof s=="function"||s instanceof Function}function S(s){return T(s)}function z(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var I=g(()=>{});var L,D,v,Y=g(()=>{x();M();U();I();L=30*1e3,D=[],v=class{name;options;_states;fn;getTz(){return this.options.timezone||this.options.utcOffset}applyDayOffset(e){if(this.options.dayOffset!==void 0&&this.options.dayOffset!==0){let t=this.options.dayOffset*24*60*60*1e3;return new Date(e.getTime()+t)}return e}constructor(e,t,r){let n,i;if(T(t))i=t;else if(typeof t=="object")n=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(T(r))i=r;else if(typeof r=="object")n=r;else if(r!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");if(this.name=n?.name,this.options=A(n),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:n?n.maxRuns:void 0,paused:n?n.paused:!1,pattern:new b("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new m(e,this.getTz()):this._states.pattern=new b(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(D.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");D.push(this)}return i!==void 0&&S(i)&&(this.fn=i,this.schedule()),this}nextRun(e){let t=this._next(e);return t?this.applyDayOffset(t.getDate(!1)):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}_enumerateRuns(e,t,r){let n=[],i=t?new m(t,this.getTz()):null,a=r==="next"?this._next:this._previous;for(;e--;){let o=a.call(this,i);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),i=o}return n}match(e){if(this._states.once){let r=new m(e,this.getTz());r.ms=0;let n=new m(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.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(){let e=this.nextRun(this._states.currentRun),t=!this._states.paused,r=this.fn!==void 0,n=!this._states.kill;return t&&r&&n&&e!==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=this._next(e);return t?e instanceof m||e instanceof Date?t.getTime()-e.getTime():t.getTime()-new m(e).getTime():null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=D.indexOf(this);e>=0&&D.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){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 t=this.msToNext(),r=this.nextRun(this._states.currentRun);return t==null||isNaN(t)||r===null?this:(t>L&&(t=L),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(r),t),this._states.currentTimeout&&this.options.unref&&z(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new m(void 0,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(T(this.options.catch))try{this.options.catch(t,this)}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,r=!this._states.paused&&t.getTime()>=e.getTime(),n=this._states.blocking&&this.options.protect;r&&!n?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger()):r&&n&&T(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this.schedule()}_next(e){let t=!!(e||this._states.currentRun),r=!1;!e&&this.options.startAt&&this.options.interval&&([e,t]=this._calculatePreviousRun(e,t),r=!e),e=new m(e,this.getTz()),this.options.startAt&&e&&e.getTime()<this.options.startAt.getTime()&&(e=this.options.startAt);let n=this._states.once||new m(e,this.getTz());return!r&&n!==this._states.once&&(n=n.increment(this._states.pattern,this.options,t)),this._states.once&&this._states.once.getTime()<=e.getTime()||n===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||this.options.stopAt&&n.getTime()>=this.options.stopAt.getTime()?null:n}_previous(e){let t=new m(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new m(t,this.getTz());return this._states.once?this._states.once.getTime()<t.getTime()?this._states.once:null:(r=r.decrement(this._states.pattern,this.options),r===null||this.options.startAt&&r.getTime()<this.options.startAt.getTime()?null:r)}_calculatePreviousRun(e,t){let r=new m(void 0,this.getTz()),n=e;if(this.options.startAt.getTime()<=r.getTime()){n=this.options.startAt;let i=n.getTime()+this.options.interval*1e3;for(;i<=r.getTime();)n=new m(n,this.getTz()).increment(this._states.pattern,this.options,!0),i=n.getTime()+this.options.interval*1e3;t=!0}return n===null&&(n=void 0),[n,t]}}});var Z=j((oe,F)=>{Y();F.exports=v});return Z();})();
|
|
1
|
+
var Cron=(()=>{var p=(s,e)=>()=>(s&&(e=s(s=0)),e);var H=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);function b(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function D(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function J(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");let r=s.substring(9);return r.includes("Z")||r.includes("+")||r.includes("-")?v(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):v(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function N(s,e,t){return R(J(s,e),t)}function R(s,e,t){let r=new Date(b(s)),n=g(r,s.tz),i=b(s),a=b(n),o=i-a,h=new Date(r.getTime()+o),l=g(h,s.tz);if(D(l,s)){let d=new Date(h.getTime()-36e5),f=g(d,s.tz),C=new Date(h.getTime()+36e5),V=g(C,s.tz),P=D(f,s),Z=D(V,s);if(P||Z){let M=P?d:h,B=P?h:C;return t!==void 0?M.getTime()>=t?M:B:M}return h}let m=new Date(h.getTime()+b(s)-b(l)),u=g(m,s.tz);if(D(u,s))return m;if(e)throw new Error("Invalid date passed to fromTZ()");return h.getTime()>m.getTime()?h:m}function g(s,e){let t,r;try{t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),r=t.formatToParts(s)}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 n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of r)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(n[i.type]=parseInt(i.value,10));if(isNaN(n.year)||isNaN(n.month)||isNaN(n.day)||isNaN(n.hour)||isNaN(n.minute)||isNaN(n.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(n)}`);return n.hour===24&&(n.hour=0),{y:n.year,m:n.month,d:n.day,h:n.hour,i:n.minute,s:n.second,tz:e}}function v(s,e,t,r,n,i,a){return{y:s,m:e,d:t,h:r,i:n,s:i,tz:a}}var U=p(()=>{});var _,w,x=p(()=>{_=[1,2,4,8,16],w=class{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,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=Array(1e4).fill(0),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.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 n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let a=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${a} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlphaMonths(e[4])),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlphaDaysQuartz(e[5]):this.replaceAlphaDays(e[5])),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.pattern.indexOf("?")>=0&&(e[0]=e[0].replace(/\?/g,"*"),e[1]=e[1].replace(/\?/g,"*"),e[2]=e[2].replace(/\?/g,"*"),e[3]=e[3].replace(/\?/g,"*"),e[4]=e[4].replace(/\?/g,"*"),e[5]=e[5].replace(/\?/g,"*"),e[6]&&(e[6]=e[6].replace(/\?/g,"*"))),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 r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,r,n){let i=this[e],a=e==="day"&&this.lastDayOfMonth,o=e==="day"&&this.lastWeekday;if(t===""&&!a&&!o)throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(n);let h=t.split(",");if(h.length>1)for(let l=0;l<h.length;l++)this.partToArray(e,h[l],r,n);else t.indexOf("-")!==-1&&t.indexOf("/")!==-1?this.handleRangeWithStepping(t,e,r,n):t.indexOf("-")!==-1?this.handleRange(t,e,r,n):t.indexOf("/")!==-1?this.handleStepping(t,e,r,n):t!==""&&this.handleNumber(t,e,r,n)}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,r,n){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=parseInt(i[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,i[1]||n)}setPart(e,t,r){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,r);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]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,n,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[n].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[n].length+")")}}handleRangeWithStepping(e,t,r,n){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,h,l]=a,m=parseInt(o,10)+r,u=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(m,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(m,u,d,t,e);for(let f=m;f<=u;f+=d)this.setPart(t,f,i[1]||n)}extractNth(e,t){let r=e,n;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");n=r.split("#")[1],r=r.split("#")[0]}else if(r.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)");n="L",r=r.slice(0,-1)}return[r,n]}handleRange(e,t,r,n){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=parseInt(a[0],10)+r,h=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(h,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,h,void 0,t,e);for(let l=o;l<=h;l++)this.setPart(t,l,i[1]||n)}handleStepping(e,t,r,n){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=parseInt(a[0],10)+r);let h=parseInt(a[1],10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,h,t,e);for(let l=o;l<this[t].length;l+=h)this.setPart(t,l,i[1]||n)}replaceAlphaDays(e){return e.replace(/-sun/gi,"-7").replace(/sun/gi,"0").replace(/mon/gi,"1").replace(/tue/gi,"2").replace(/wed/gi,"3").replace(/thu/gi,"4").replace(/fri/gi,"5").replace(/sat/gi,"6")}replaceAlphaDaysQuartz(e){return e.replace(/sun/gi,"1").replace(/mon/gi,"2").replace(/tue/gi,"3").replace(/wed/gi,"4").replace(/thu/gi,"5").replace(/fri/gi,"6").replace(/sat/gi,"7")}replaceAlphaMonths(e){return e.replace(/jan/gi,"1").replace(/feb/gi,"2").replace(/mar/gi,"3").replace(/apr/gi,"4").replace(/may/gi,"5").replace(/jun/gi,"6").replace(/jul/gi,"7").replace(/aug/gi,"8").replace(/sep/gi,"9").replace(/oct/gi,"10").replace(/nov/gi,"11").replace(/dec/gi,"12")}handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@yearly"||t==="@annually")return"0 0 1 1 *";if(t==="@monthly")return"0 0 1 * *";if(t==="@weekly")return"0 0 * * 0";if(t==="@daily"||t==="@midnight")return"0 0 * * *";if(t==="@hourly")return"0 * * * *";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 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]|_[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}}});var E,c,y,A=p(()=>{U();x();E=[31,28,31,30,31,30,31,31,30,31,30,31],c=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],y=class s{tz;afterMs;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 s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?E[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r-2:i===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r===n?r-2:r+1:a===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let a=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let h=1;h<=r;h++)new Date(Date.UTC(e,t,h)).getUTCDay()===a&&o++;if(n&63&&_[o-1]&n)return!0;if(n&32){let h=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=h;l++)if(new Date(Date.UTC(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=g(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.afterMs=e.getTime()}catch(t){let r=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: ${r}`)}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()}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.afterMs=e.afterMs}apply(){if(this.month>11||this.month<0||this.day>E[this.month]||this.day<1||this.hour>59||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return 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"){let t=N(e);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(N(e,this.tz))}findNext(e,t,r,n){return this._findMatch(e,t,r,n,1)}_findMatch(e,t,r,n,i){let a=this[t],o;r.lastDayOfMonth&&(o=this.getLastDayOfMonth(this.year,this.month));let h=!r.starDOW&&t=="day"?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0,l=this[t]+n,m=i===1?u=>u<r[t].length:u=>u>=0;for(let u=l;m(u);u+=i){let d=r[t][u];if(t==="day"&&!d){for(let f=0;f<r.nearestWeekdays.length;f++)if(r.nearestWeekdays[f]){let C=this.getNearestWeekday(this.year,this.month,f-n);if(C===-1)continue;if(C===u-n){d=1;break}}}if(t==="day"&&r.lastWeekday){let f=this.getLastWeekday(this.year,this.month);u-n===f&&(d=1)}if(t==="day"&&r.lastDayOfMonth&&u-n==o&&(d=1),t==="day"&&!r.starDOW){let f=r.dayOfWeek[(h+(u-n-1))%7];if(f&&f&63)f=this.isNthWeekdayOfMonth(this.year,this.month,u-n,f)?1:0;else if(f)throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${f}`);r.useAndLogic?d=d&&f:!e.domAndDow&&!r.starDOM?d=d||f:d=d&&f}if(d)return this[t]=u-n,a!==this[t]?2:1}return 3}recurse(e,t,r){if(r===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 n=this.findNext(t,c[r][0],e,c[r][2]);if(n>1){let i=r+1;for(;i<c.length;)this[c[i][0]]=-c[i][2],i++;if(n===3){if(this[c[r][1]]++,this[c[r][0]]=-c[r][2],this.apply(),r===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 this.recurse(e,t,0)}else if(this.apply())return this.recurse(e,t,r-1)}return r+=1,r>=c.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:this.recurse(e,t,r)}increment(e,t,r){return this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0,0)}recurseBackward(e,t,r,n=0){if(n>1e4)return null;if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let a=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){a=o;break}if(a===-1)return null;this.year=a,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 i=this.findPrevious(t,c[r][0],e,c[r][2]);if(i>1){let a=r+1;for(;a<c.length;){let o=c[a][0],h=c[a][2],l=this.getMaxPatternValue(o,e,h);this[o]=l,a++}if(i===3){if(this[c[r][1]]--,r===0){let m=this.getLastDayOfMonth(this.year,this.month);this.day>m&&(this.day=m)}if(r===1)if(this.day<=0)this.day=1;else{let m=this.year,u=this.month;for(;u<0;)u+=12,m--;for(;u>11;)u-=12,m++;let d=u!==1?E[u]:new Date(Date.UTC(m,u+1,0)).getUTCDate();this.day>d&&(this.day=d)}this.apply();let o=c[r][0],h=c[r][2],l=this.getMaxPatternValue(o,e,h);if(o==="day"){let m=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,m)}else this[o]=l;if(this.apply(),r===0){let m=c[1][2],u=this.getMaxPatternValue("day",e,m),d=this.getLastDayOfMonth(this.year,this.month),f=Math.min(u,d);f!==this.day&&(this.day=f,this.hour=this.getMaxPatternValue("hour",e,c[2][2]),this.minute=this.getMaxPatternValue("minute",e,c[3][2]),this.second=this.getMaxPatternValue("second",e,c[4][2]))}if(r===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 this.recurseBackward(e,t,0,n+1)}else if(this.apply())return this.recurseBackward(e,t,r-1,n+1)}return r+=1,r>=c.length?this:this.year<0?null:this.recurseBackward(e,t,r,n+1)}getMaxPatternValue(e,t,r){if(e==="day"&&t.lastDayOfMonth)return this.getLastDayOfMonth(this.year,this.month);if(e==="day"&&!t.starDOW)return this.getLastDayOfMonth(this.year,this.month);for(let n=t[e].length-1;n>=0;n--)if(t[e][n])return n-r;return t[e].length-1-r}findPrevious(e,t,r,n){return this._findMatch(e,t,r,n,-1)}getDate(e,t){let r=t??this.afterMs;return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):R(v(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1,r)}getTime(e){return this.getDate(!1,e).getTime()}setAfterMs(e){this.afterMs=e}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let r=0;r<c.length;r++){let n=c[r][0],i=c[r][2],a=this[n];if(a+i<0||a+i>=e[n].length)return!1;let o=e[n][a+i];if(n==="day"){if(!o){for(let h=0;h<e.nearestWeekdays.length;h++)if(e.nearestWeekdays[h]){let l=this.getNearestWeekday(this.year,this.month,h-i);if(l!==-1&&l===a){o=1;break}}}if(e.lastWeekday){let h=this.getLastWeekday(this.year,this.month);a===h&&(o=1)}if(e.lastDayOfMonth){let h=this.getLastDayOfMonth(this.year,this.month);a===h&&(o=1)}if(!e.starDOW){let h=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),l=e.dayOfWeek[(h+(a-1))%7];l&&l&63&&(l=this.isNthWeekdayOfMonth(this.year,this.month,a,l)?1:0),e.useAndLogic?o=o&&l:!t.domAndDow&&!e.starDOM?o=o||l:o=o&&l}}if(!o)return!1}return!0}}});function S(s){if(s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow,s.paused=s.paused===void 0?!1:s.paused,s.maxRuns=s.maxRuns===void 0?1/0:s.maxRuns,s.catch=s.catch===void 0?!1:s.catch,s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),s.unref=s.unref===void 0?!1:s.unref,s.mode=s.mode===void 0?"auto":s.mode,s.alternativeWeekdays=s.alternativeWeekdays===void 0?!1:s.alternativeWeekdays,s.sloppyRanges=s.sloppyRanges===void 0?!1:s.sloppyRanges,s.allowPast=s.allowPast===void 0?!1:s.allowPast,!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.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(s.startAt&&(s.startAt=new y(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new y(s.stopAt,s.timezone)),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}var z=p(()=>{A()});function T(s){return Object.prototype.toString.call(s)==="[object Function]"||typeof s=="function"||s instanceof Function}function I(s){return T(s)}function L(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var Y=p(()=>{});var F,k,O,j=p(()=>{A();x();z();Y();F=30*1e3,k=[],O=class{name;options;_states;fn;getTz(){return this.options.timezone||this.options.utcOffset}applyDayOffset(e){if(this.options.dayOffset!==void 0&&this.options.dayOffset!==0){let t=this.options.dayOffset*24*60*60*1e3;return new Date(e.getTime()+t)}return e}constructor(e,t,r){let n,i;if(T(t))i=t;else if(typeof t=="object")n=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(T(r))i=r;else if(typeof r=="object")n=r;else if(r!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");if(this.name=n?.name,this.options=S(n),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:n?n.maxRuns:void 0,paused:n?n.paused:!1,pattern:new w("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new y(e,this.getTz()):this._states.pattern=new w(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(k.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");k.push(this)}return i!==void 0&&I(i)&&(this.fn=i,this.schedule()),this}nextRun(e){let t=this._next(e);return t?this.applyDayOffset(t.getDate(!1)):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}_enumerateRuns(e,t,r){let n=[],i=t?new y(t,this.getTz()):null,a=r==="next"?this._next:this._previous;for(;e--;){let o=a.call(this,i);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),i=o}return n}match(e){if(this._states.once){let r=new y(e,this.getTz());r.ms=0;let n=new y(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.getTime()}let t=new y(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(){let e=this.nextRun(this._states.currentRun),t=!this._states.paused,r=this.fn!==void 0,n=!this._states.kill;return t&&r&&n&&e!==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=this._next(e);return t?e instanceof y||e instanceof Date?t.getTime()-e.getTime():t.getTime()-new y(e).getTime():null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=k.indexOf(this);e>=0&&k.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){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 t=this.msToNext(),r=this.nextRun(this._states.currentRun);return t==null||isNaN(t)||r===null?this:(t>F&&(t=F),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(r),t),this._states.currentTimeout&&this.options.unref&&L(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new y(void 0,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(T(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new y(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,r=!this._states.paused&&t.getTime()>=e.getTime(),n=this._states.blocking&&this.options.protect;r&&!n?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger()):r&&n&&T(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this.schedule()}_next(e){let t=!!(e||this._states.currentRun),r=!1;!e&&this.options.startAt&&this.options.interval&&([e,t]=this._calculatePreviousRun(e,t),r=!e),e=new y(e,this.getTz()),this.options.startAt&&e&&e.getTime()<this.options.startAt.getTime()&&(e=this.options.startAt);let n=this._states.once||new y(e,this.getTz());if(!r&&n!==this._states.once&&(n=n.increment(this._states.pattern,this.options,t)),this._states.once){if(this._states.currentRun&&this._states.once.getTime()<=this._states.currentRun.getTime()||e.getTime()===this._states.once.getTime())return null;let i=e.getTime()-this._states.once.getTime();if(i>0&&!this.options.allowPast&&i>1e3)return null}if(n!==null&&n!==this._states.once&&typeof this.getTz()=="string"){let i=e.getTime(),a=n.getTime(),o=(this.options.interval&&t?this.options.interval:1)*1e3,h=a-i;if(h>=o+36e5||h<0){let l=h<0?a+36e5:a-36e5,m=new Date(l),u=new y(m,this.getTz());u.match(this._states.pattern,this.options)&&l>i&&(u.setAfterMs(i),n=u)}}return n===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||this.options.stopAt&&n.getTime()>=this.options.stopAt.getTime()?null:n}_previous(e){let t=new y(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new y(t,this.getTz());return this._states.once?this._states.once.getTime()<t.getTime()?this._states.once:null:(r=r.decrement(this._states.pattern,this.options),r===null||this.options.startAt&&r.getTime()<this.options.startAt.getTime()?null:r)}_calculatePreviousRun(e,t){let r=new y(void 0,this.getTz()),n=e;if(this.options.startAt.getTime()<=r.getTime()){n=this.options.startAt;let i=n.getTime()+this.options.interval*1e3;for(;i<=r.getTime();)n=new y(n,this.getTz()).increment(this._states.pattern,this.options,!0),i=n.getTime()+this.options.interval*1e3;t=!0}return n===null&&(n=void 0),[n,t]}}});var K=H((ce,$)=>{j();$.exports=O});return K();})();
|
package/package.json
CHANGED