croner 11.0.0-dev.5 → 11.0.0-dev.7
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 +34 -21
- package/dist/croner.d.ts +34 -21
- package/dist/croner.js +1 -1
- package/dist/croner.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,16 +74,16 @@ Using Deno
|
|
|
74
74
|
|
|
75
75
|
```typescript
|
|
76
76
|
// From deno.land/x
|
|
77
|
-
import { Cron } from "https://deno.land/x/croner@11.0.0-dev.
|
|
77
|
+
import { Cron } from "https://deno.land/x/croner@11.0.0-dev.7/dist/croner.js";
|
|
78
78
|
|
|
79
79
|
// ... or jsr.io
|
|
80
|
-
import { Cron } from "jsr:@hexagon/croner@11.0.0-dev.
|
|
80
|
+
import { Cron } from "jsr:@hexagon/croner@11.0.0-dev.7";
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
In a webpage using the UMD-module
|
|
84
84
|
|
|
85
85
|
```html
|
|
86
|
-
<script src="https://cdn.jsdelivr.net/npm/croner@11.0.0-dev.
|
|
86
|
+
<script src="https://cdn.jsdelivr.net/npm/croner@11.0.0-dev.7/dist/croner.umd.min.js"></script>
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
## Documentation
|
|
@@ -237,6 +237,7 @@ Croner uses [Vixie Cron](https://en.wikipedia.org/wiki/Cron#CRON_expression) bas
|
|
|
237
237
|
| \@weekly | Run once a week, i.e. "0 0 * * 0". |
|
|
238
238
|
| \@daily / \@midnight | Run once a day, i.e. "0 0 * * *". |
|
|
239
239
|
| \@hourly | Run once an hour, i.e. "0 * * * *". |
|
|
240
|
+
| \@reboot | Recognized but not supported. Throws an error as Croner cannot detect system reboot events. |
|
|
240
241
|
|
|
241
242
|
## Why another JavaScript cron implementation
|
|
242
243
|
|
package/dist/croner.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var x=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var H=(s,e)=>{for(var t in e)x(s,t,{get:e[t],enumerable:!0})},J=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Z(e))!B.call(s,n)&&n!==t&&x(s,n,{get:()=>e[n],enumerable:!(r=V(e,n))||r.enumerable});return s};var q=s=>J(x({},"__esModule",{value:!0}),s);var Q={};H(Q,{Cron:()=>S,CronDate:()=>d,CronIterator:()=>_,CronPattern:()=>D,scheduledJobs:()=>k});module.exports=q(Q);function w(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function z(s,e){return w(p(s,e))-s.getTime()}function M(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 K(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("-")?P(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):P(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function A(s,e,t){return W(K(s,e),t)}function W(s,e,t){let r=new Date(w(s)),n=p(r,s.tz),i=w(s),a=w(n),o=i-a,l=new Date(r.getTime()+o),h=p(l,s.tz);if(M(h,s)){let m=z(new Date(l.getTime()-864e5),s.tz)-z(new Date(l.getTime()+864e5),s.tz),f=m>0?m:36e5,g=new Date(l.getTime()-f),R=p(g,s.tz),O=new Date(l.getTime()+f),b=p(O,s.tz),T=M(R,s),N=M(b,s);if(T||N){let C=T?g:l,$=T?l:O;return t!==void 0?C.getTime()>=t?C:$:C}return l}let c=new Date(l.getTime()+w(s)-w(h)),u=p(c,s.tz);if(M(u,s))return c;if(e)throw new Error("Invalid date passed to fromTZ()");return l.getTime()>c.getTime()?l:c}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 P(s,e,t,r,n,i,a){return{y:s,m:e,d:t,h:r,i:n,s:i,tz:a}}var E=[1,2,4,8,16],D=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("*"),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,"*"))),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.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 l=t.split(",");if(l.length>1)for(let h=0;h<l.length;h++)this.partToArray(e,l[h],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,l,h]=a,c=parseInt(o,10)+r,u=parseInt(l,10)+r,m=parseInt(h,10);this.validateNotNaN(c,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(c,u,m,t,e);for(let f=c;f<=u;f+=m)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,l=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(l,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,l,void 0,t,e);for(let h=o;h<=l;h++)this.setPart(t,h,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 l=parseInt(a[1],10);this.validateNotNaN(l,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,l,t,e);for(let h=o;h<this[t].length;h+=l)t==="year"&&h===0||this.setPart(t,h,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]|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 I=[31,28,31,30,31,30,31,31,30,31,30,31],y=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],d=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?I[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 l=1;l<=r;l++)new Date(Date.UTC(e,t,l)).getUTCDay()===a&&o++;if(n&63&&E[o-1]&n)return!0;if(n&32){let l=this.getLastDayOfMonth(e,t);for(let h=r+1;h<=l;h++)if(new Date(Date.UTC(e,t,h)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=p(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.afterMs=e.getTime()-e.getUTCMilliseconds()}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.getLastDayOfMonth(this.year,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=A(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(A(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 l=!r.starDOW&&t=="day"?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0,h=this[t]+n,c=i===1?u=>u<r[t].length:u=>u>=0;for(let u=h;c(u);u+=i){let m=r[t][u];if(t==="day"&&!m){for(let f=0;f<r.nearestWeekdays.length;f++)if(r.nearestWeekdays[f]){let g=this.getNearestWeekday(this.year,this.month,f-n);if(g===-1)continue;if(g===u-n){m=1;break}}}if(t==="day"&&r.lastWeekday){let f=this.getLastWeekday(this.year,this.month);u-n===f&&(m=1)}if(t==="day"&&r.lastDayOfMonth&&u-n==o&&(m=1),t==="day"&&!r.starDOW){let f=r.dayOfWeek[(l+(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?m=m&&f:!e.domAndDow&&!r.starDOM?m=m||f:m=m&&f}if(m)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,y[r][0],e,y[r][2]);if(n>1){let i=r+1;for(;i<y.length;)this[y[i][0]]=-y[i][2],i++;if(n===3){if(this[y[r][1]]++,this[y[r][0]]=-y[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>=y.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,y[r][0],e,y[r][2]);if(i>1){let a=r+1;for(;a<y.length;){let o=y[a][0],l=y[a][2],h=this.getMaxPatternValue(o,e,l);o==="day"?this[o]=Math.min(h,this.getLastDayOfMonth(this.year,this.month)):this[o]=h,a++}if(i===3){if(this[y[r][1]]--,r===0){let c=this.getLastDayOfMonth(this.year,this.month);this.day>c&&(this.day=c)}if(r===1)if(this.day<=0)this.day=1;else{let c=this.year,u=this.month;for(;u<0;)u+=12,c--;for(;u>11;)u-=12,c++;let m=u!==1?I[u]:new Date(Date.UTC(c,u+1,0)).getUTCDate();this.day>m&&(this.day=m)}this.apply();let o=y[r][0],l=y[r][2],h=this.getMaxPatternValue(o,e,l);if(o==="day"){let c=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(h,c)}else this[o]=h;if(this.apply(),r===0){let c=y[1][2],u=this.getMaxPatternValue("day",e,c),m=this.getLastDayOfMonth(this.year,this.month),f=Math.min(u,m);f!==this.day&&(this.day=f,this.hour=this.getMaxPatternValue("hour",e,y[2][2]),this.minute=this.getMaxPatternValue("minute",e,y[3][2]),this.second=this.getMaxPatternValue("second",e,y[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>=y.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)):W(P(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<y.length;r++){let n=y[r][0],i=y[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 l=0;l<e.nearestWeekdays.length;l++)if(e.nearestWeekdays[l]){let h=this.getNearestWeekday(this.year,this.month,l-i);if(h!==-1&&h===a){o=1;break}}}if(e.lastWeekday){let l=this.getLastWeekday(this.year,this.month);a===l&&(o=1)}if(e.lastDayOfMonth){let l=this.getLastDayOfMonth(this.year,this.month);a===l&&(o=1)}if(!e.starDOW){let l=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),h=e.dayOfWeek[(l+(a-1))%7];h&&h&63&&(h=this.isNthWeekdayOfMonth(this.year,this.month,a,h)?1:0),e.useAndLogic?o=o&&h:!t.domAndDow&&!e.starDOM?o=o||h:o=o&&h}}if(!o)return!1}return!0}};function L(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 d(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new d(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 v(s){return Object.prototype.toString.call(s)==="[object Function]"||typeof s=="function"||s instanceof Function}function F(s){return v(s)}function Y(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var j=30*1e3,k=[],S=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}_nextTarget(e,t){let r=(this.options.dayOffset??0)*24*60*60*1e3;if(this._states.once&&this._states.currentRun&&this._states.once.getTime()+r<=this._states.currentRun.getTime())return null;let n=new Date(t.getTime()-r),i={startAt:this.options.startAt?new d(new Date(this.options.startAt.getTime()-r),this.getTz()):void 0,stopAt:this.options.stopAt?new d(new Date(this.options.stopAt.getTime()-r),this.getTz()):void 0,includeStartAt:r!==0},a=this._next(e?new Date(e.getTime()-r):void 0,n,i);for(;a;){let o=this.applyDayOffset(a.getDate(!1));if(this.options.startAt&&o.getTime()<this.options.startAt.getTime()){a=this._next(a,n,i);continue}return this.options.stopAt&&o.getTime()>=this.options.stopAt.getTime()?null:o}return null}constructor(e,t,r){let n,i;if(v(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(v(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=L(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 D("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new d(e,this.getTz()):this._states.pattern=new D(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&&F(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")}enumerate(e){return new _(this,e)}_enumerateRuns(e,t,r){let n=[],i=t?new d(t,this.getTz()):null,a=r==="next"?this._next:this._previous;for(;e--;){let o=a.call(this,i);if(!o)break;let l=o.getDate(!1);n.push(this.applyDayOffset(l)),i=o}return n}match(e){if(this._states.once){let r=new d(e,this.getTz());r.ms=0;let n=new d(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.getTime()}let t=new d(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);if(t){if(e instanceof d||e instanceof Date)return t.getTime()-e.getTime();{let r=typeof e=="string"?this.getTz():void 0;return t.getTime()-new d(e,r).getTime()}}else return 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){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let r=t??new Date,n=this._nextTarget(void 0,r),i=n?n.getTime()-r.getTime():null,a=this._states.blocking&&this.options.protect?void 0:this._states.currentRun,o=this._nextTarget(a,r);return i==null||isNaN(i)||o===null?this:(i>j&&(i=j),i<0&&(i=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),i),this._states.currentTimeout&&this.options.unref&&Y(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new d(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(v(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 d(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(t)):r&&n&&v(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,r?void 0:t)}_next(e,t,r){let n=r?r.startAt:this.options.startAt,i=r?r.stopAt:this.options.stopAt,a=!!(e||this._states.currentRun),o=!1;!e&&n&&this.options.interval&&([e,a]=this._calculatePreviousRun(e,a,t,n),o=!e),e=new d(e??t,this.getTz());let l=r?.includeStartAt&&n&&!o?new d(new Date(n.getTime()-1e3),this.getTz()):n;l&&e&&e.getTime()<l.getTime()&&(e=l);let h=this._states.once||new d(e,this.getTz());if(!o&&h!==this._states.once&&(h=h.increment(this._states.pattern,this.options,a)),this._states.once){if(n&&this._states.once.getTime()<n.getTime()||this._states.currentRun&&this._states.once.getTime()<=this._states.currentRun.getTime()||e.getTime()===this._states.once.getTime())return null;let c=e.getTime()-this._states.once.getTime();if(c>0&&!this.options.allowPast&&c>1e3)return null}if(h!==null&&h!==this._states.once&&typeof this.getTz()=="string"){let c=e.getTime(),u=h.getTime(),m=(this.options.interval&&a?this.options.interval:1)*1e3,f=u-c,g=e,R=Date.UTC(g.year,g.month,g.day,g.hour,g.minute,g.second)-c,O=Date.UTC(h.year,h.month,h.day,h.hour,h.minute,h.second)-u,b=R-O;if(b>0&&(f>=m+b||f<0)){let T=f<0?u+b:u-b,N=new Date(T),C=new d(N,this.getTz());C.match(this._states.pattern,this.options)&&T>c&&(C.setAfterMs(T),h=C)}}return h===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||i&&h.getTime()>=i.getTime()?null:h}_previous(e){let t=new d(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new d(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,r,n){let i=new d(r,this.getTz()),a=e;if(n&&n.getTime()<=i.getTime()){a=n;let o=a.getTime()+this.options.interval*1e3;for(;o<=i.getTime();){let l=new d(a,this.getTz()).increment(this._states.pattern,this.options,!0);if(l===null)break;a=l,o=a.getTime()+this.options.interval*1e3}t=!0}return a===null&&(a=void 0),[a,t]}},_=class s{cron;cursor;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.cursor=s._normalizeCursor(t),this.done=!1,this.initialMaxRuns=e.options.maxRuns??1/0,this.remainingRuns=this.initialMaxRuns}static _normalizeCursor(e){if(e!=null)return e instanceof Date?new Date(e.getTime()):e}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron.nextRun(this.cursor??null);if(e===null)return this.done=!0,{value:void 0,done:!0};let r=this.cron.options.dayOffset??0,n=e.getTime()-r*24*60*60*1e3;return this.cursor=new Date(n),this.remainingRuns--,{value:e,done:!1}}peek(){return this.done||this.remainingRuns<=0?null:this.cron.nextRun(this.cursor??null)}reset(e){this.cursor=s._normalizeCursor(e),this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}};0&&(module.exports={Cron,CronDate,CronIterator,CronPattern,scheduledJobs});
|
|
1
|
+
var M=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var B=(s,e)=>{for(var t in e)M(s,t,{get:e[t],enumerable:!0})},J=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of H(e))!V.call(s,n)&&n!==t&&M(s,n,{get:()=>e[n],enumerable:!(r=j(e,n))||r.enumerable});return s};var K=s=>J(M({},"__esModule",{value:!0}),s);var X={};B(X,{Cron:()=>R,CronDate:()=>c,CronIterator:()=>v,CronPattern:()=>T,scheduledJobs:()=>b});module.exports=K(X);function p(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function U(s,e){return p(y(s,e))-s.getTime()}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 q(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 _(s,e,t){return N(q(s,e),t)}function N(s,e,t){let r=new Date(p(s)),n=y(r,s.tz),a=p(s),i=p(n),o=a-i,h=new Date(r.getTime()+o),l=y(h,s.tz);if(w(l,s)){let d=U(new Date(h.getTime()-864e5),s.tz)-U(new Date(h.getTime()+864e5),s.tz),g=d>0?d:36e5,E=new Date(h.getTime()-g),Y=y(E,s.tz),x=new Date(h.getTime()+g),F=y(x,s.tz),O=w(Y,s),Z=w(F,s);if(O||Z){let k=O?E:h,$=O?h:x;return t!==void 0?k.getTime()>=t?k:$:k}return h}let u=new Date(h.getTime()+p(s)-p(l)),m=y(u,s.tz);if(w(m,s))return u;if(e)throw new Error("Invalid date passed to fromTZ()");return h.getTime()>u.getTime()?h:u}function y(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(a){let i=a instanceof Error?a.message:String(a);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${i}`)}let n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let a of r)(a.type==="year"||a.type==="month"||a.type==="day"||a.type==="hour"||a.type==="minute"||a.type==="second")&&(n[a.type]=parseInt(a.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,a,i){return{y:s,m:e,d:t,h:r,i:n,s:a,tz:i}}var P=[1,2,4,8,16],T=class s{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 i=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${i} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let n=0;n<e.length;n++)e[n]=e[n].replace(/\?/g,"*");if(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.replaceAlpha(e[4],s.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],s.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],s.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let 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 a=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return a.fill(n);let i=t.split(",");if(i.length>1)for(let o of i)this.partToArray(e,o,r,n);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,r,n):t.includes("-")?this.handleRange(t,e,r,n):t.includes("/")?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 a=this.extractNth(e,t),i=e.toUpperCase().includes("W");if(t!=="day"&&i)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");i&&(t="nearestWeekdays");let o=parseInt(a[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,a[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,a){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+a+"'");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 a=this.extractNth(e,t),i=a[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(i===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,h,l]=i,u=parseInt(o,10)+r,m=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(u,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(u,m,d,t,e);for(let g=u;g<=m;g+=d)this.setPart(t,g,a[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 a=this.extractNth(e,t),i=a[0].split("-");if(i.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(i[0],10)+r,h=parseInt(i[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,a[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 a=this.extractNth(e,t),i=a[0].split("/");if(i.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)i[0]===""&&(i[0]="*");else{if(i[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(i[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;i[0]!=="*"&&(o=parseInt(i[0],10)+r);let h=parseInt(i[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)t==="year"&&l===0||this.setPart(t,l,a[1]||n)}replaceAlpha(e,t){let r=e;for(let[n,a]of Object.entries(t))r=r.replace(new RegExp(n,"gi"),a);return r}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return s.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|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 Q=[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]],c=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?Q[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r-2:a===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r===n?r-2:r+1:i===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let i=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()===i&&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()===i)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=y(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.afterMs=e.getTime()-e.getUTCMilliseconds()}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.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(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=_(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(_(e,this.tz))}findNext(e,t,r,n){return this._findMatch(e,t,r,n,1)}_matchDayValue(e,t,r,n){let a=e;if(!a){for(let i=0;i<r.nearestWeekdays.length;i++)if(r.nearestWeekdays[i]){let o=this.getNearestWeekday(this.year,this.month,i+1);if(o!==-1&&o===t){a=1;break}}}if(r.lastWeekday){let i=this.getLastWeekday(this.year,this.month);t===i&&(a=1)}if(r.lastDayOfMonth){let i=this.getLastDayOfMonth(this.year,this.month);t===i&&(a=1)}if(!r.starDOW){let i=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=r.dayOfWeek[(i+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),r.useAndLogic?a=a&&o:!n.domAndDow&&!r.starDOM?a=a||o:a=a&&o}return a}_findMatch(e,t,r,n,a){let i=this[t],o=this[t]+n,h=a===1?l=>l<r[t].length:l=>l>=0;for(let l=o;h(l);l+=a){let u=r[t][l];if(t==="day"&&(u=this._matchDayValue(u,l-n,r,e)),u)return this[t]=l-n,i!==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 a=-1;for(let i=this.year+1;i<e.year.length&&i<1e4;i++)if(e.year[i]===1){a=i;break}if(a===-1)return null;this.year=a,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 a=r+1;for(;a<f.length;)this[f[a][0]]=-f[a][2],a++;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 i=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){i=o;break}if(i===-1)return null;this.year=i,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let a=this.findPrevious(t,f[r][0],e,f[r][2]);if(a>1){let i=r+1;for(;i<f.length;){let o=f[i][0],h=f[i][2],l=this.getMaxPatternValue(o,e,h);o==="day"?this[o]=Math.min(l,this.getLastDayOfMonth(this.year,this.month)):this[o]=l,i++}if(a===3){if(this[f[r][1]]--,r===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(r===1)if(this.day<=0)this.day=1;else{let u=this.year,m=this.month;for(;m<0;)m+=12,u--;for(;m>11;)m-=12,u++;let d=this.getLastDayOfMonth(u,m);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 u=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,u)}else this[o]=l;if(this.apply(),r===0){let u=f[1][2],m=this.getMaxPatternValue("day",e,u),d=this.getLastDayOfMonth(this.year,this.month),g=Math.min(m,d);g!==this.day&&(this.day=g,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,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(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<f.length;r++){let n=f[r][0],a=f[r][2],i=this[n];if(i+a<0||i+a>=e[n].length)return!1;let o=e[n][i+a];if(n==="day"&&(o=this._matchDayValue(o,i,e,t)),!o)return!1}return!0}};function W(s){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;let e=(t,r)=>t===void 0?r:t;if(s.paused=e(s.paused,!1),s.maxRuns=e(s.maxRuns,1/0),s.catch=e(s.catch,!1),s.unref=e(s.unref,!1),s.mode=e(s.mode,"auto"),s.alternativeWeekdays=e(s.alternativeWeekdays,!1),s.sloppyRanges=e(s.sloppyRanges,!1),s.allowPast=e(s.allowPast,!1),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),!["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 c(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new c(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 C(s){return typeof s=="function"}function z(s){return C(s)}function I(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var A=1440*60*1e3,L=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*A;return new Date(e.getTime()+t)}return e}_nextTarget(e,t){let r=(this.options.dayOffset??0)*A;if(this._states.once&&this._states.currentRun&&this._states.once.getTime()+r<=this._states.currentRun.getTime())return null;let n=new Date(t.getTime()-r),a=h=>h?new c(new Date(h.getTime()-r),this.getTz()):void 0,i={startAt:a(this.options.startAt),stopAt:a(this.options.stopAt),includeStartAt:r!==0},o=this._next(e?new Date(e.getTime()-r):void 0,n,i);for(;o;){let h=this.applyDayOffset(o.getDate(!1));if(this.options.startAt&&h.getTime()<this.options.startAt.getTime()){o=this._next(o,n,i);continue}return this.options.stopAt&&h.getTime()>=this.options.stopAt.getTime()?null:h}return null}constructor(e,t,r){let n,a;for(let i of[t,r])if(C(i))a=i;else if(typeof i=="object")n=i;else if(i!==void 0)throw new Error("Cron: Invalid argument passed. Should be one of function, or object (options).");if(this.name=n?.name,this.options=W(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 T("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new c(e,this.getTz()):this._states.pattern=new T(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 a!==void 0&&z(a)&&(this.fn=a,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")}enumerate(e){return new v(this,e)}_enumerateRuns(e,t,r){let n=[],a=t?new c(t,this.getTz()):null,i=r==="next"?this._next:this._previous;for(;e--;){let o=i.call(this,a);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),a=o}return n}match(e){if(this._states.once){let r=new c(e,this.getTz());r.ms=0;let n=new c(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.getTime()}let t=new c(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this.nextRun(this._states.currentRun)!==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);if(t){if(e instanceof c||e instanceof Date)return t.getTime()-e.getTime();{let r=typeof e=="string"?this.getTz():void 0;return t.getTime()-new c(e,r).getTime()}}else return 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){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let r=t??new Date,n=this._states.blocking&&this.options.protect?void 0:this._states.currentRun,a=n&&n.getTime()>r.getTime()?void 0:n,i=this._nextTarget(void 0,r),o=i?i.getTime()-r.getTime():null,h=this._nextTarget(a,r);return o==null||isNaN(o)||h===null?this:(o>L&&(o=L),o<0&&(o=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(h),o),this._states.currentTimeout&&this.options.unref&&I(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new c(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(C(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new c(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(t)):r&&n&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,r?void 0:t)}_next(e,t,r){let n=r?r.startAt:this.options.startAt,a=r?r.stopAt:this.options.stopAt,i=!!(e||this._states.currentRun),o=!1;!e&&n&&this.options.interval&&([e,i]=this._calculatePreviousRun(e,i,t,n),o=!e),e=new c(e??t,this.getTz());let h=r?.includeStartAt&&n&&!o?new c(new Date(n.getTime()-1e3),this.getTz()):n;h&&e&&e.getTime()<h.getTime()&&(e=h);let l=this._states.once||new c(e,this.getTz());if(!o&&l!==this._states.once&&(l=l.increment(this._states.pattern,this.options,i)),this._states.once){if(n&&this._states.once.getTime()<n.getTime()||this._states.currentRun&&this._states.once.getTime()<=this._states.currentRun.getTime()||e.getTime()===this._states.once.getTime())return null;let u=e.getTime()-this._states.once.getTime();if(u>0&&!this.options.allowPast&&u>1e3)return null}return l=this._resolveDSTOverlap(l,e,i),l===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||a&&l.getTime()>=a.getTime()?null:l}_previous(e){let t=new c(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new c(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)}_resolveDSTOverlap(e,t,r){if(e===null||e===this._states.once||typeof this.getTz()!="string")return e;let n=t.getTime(),a=e.getTime(),i=(this.options.interval&&r?this.options.interval:1)*1e3,o=a-n,h=Date.UTC(t.year,t.month,t.day,t.hour,t.minute,t.second)-n,l=Date.UTC(e.year,e.month,e.day,e.hour,e.minute,e.second)-a,u=h-l;if(u>0&&(o>=i+u||o<0)){let m=o<0?a+u:a-u,d=new Date(m),g=new c(d,this.getTz());if(g.match(this._states.pattern,this.options)&&m>n)return g.setAfterMs(m),g}return e}_calculatePreviousRun(e,t,r,n){let a=new c(r,this.getTz()),i=e;if(n&&n.getTime()<=a.getTime()){i=n;let o=i.getTime()+this.options.interval*1e3;for(;o<=a.getTime();){let h=new c(i,this.getTz()).increment(this._states.pattern,this.options,!0);if(h===null)break;i=h,o=i.getTime()+this.options.interval*1e3}t=!0}return i===null&&(i=void 0),[i,t]}},v=class s{cron;cursor;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.cursor=s._normalizeCursor(t),this.done=!1,this.initialMaxRuns=e.options.maxRuns??1/0,this.remainingRuns=this.initialMaxRuns}static _normalizeCursor(e){if(e!=null)return e instanceof Date?new Date(e.getTime()):e}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron.nextRun(this.cursor??null);if(e===null)return this.done=!0,{value:void 0,done:!0};let r=this.cron.options.dayOffset??0,n=e.getTime()-r*A;return this.cursor=new Date(n),this.remainingRuns--,{value:e,done:!1}}peek(){return this.done||this.remainingRuns<=0?null:this.cron.nextRun(this.cursor??null)}reset(e){this.cursor=s._normalizeCursor(e),this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}};0&&(module.exports={Cron,CronDate,CronIterator,CronPattern,scheduledJobs});
|
package/dist/croner.d.cts
CHANGED
|
@@ -111,30 +111,21 @@ declare class CronPattern {
|
|
|
111
111
|
*/
|
|
112
112
|
private handleStepping;
|
|
113
113
|
/**
|
|
114
|
-
* Replace day
|
|
114
|
+
* Replace alpha names (day/month) with numeric values using a mapping.
|
|
115
115
|
*
|
|
116
|
-
* @param conf Current part, expected to be a string that might contain
|
|
117
|
-
*
|
|
118
|
-
* @returns Conf with
|
|
119
|
-
*/
|
|
120
|
-
private replaceAlphaDays;
|
|
121
|
-
/**
|
|
122
|
-
* Replace day name with day numbers (Quartz mode)
|
|
123
|
-
* In Quartz mode: Sunday=1, Monday=2, ..., Saturday=7
|
|
124
|
-
*
|
|
125
|
-
* @param conf Current part, expected to be a string that might contain sun,mon etc.
|
|
126
|
-
*
|
|
127
|
-
* @returns Conf with Quartz-style numbering
|
|
116
|
+
* @param conf Current part, expected to be a string that might contain alpha names.
|
|
117
|
+
* @param mapping Object mapping names to their numeric string replacements.
|
|
118
|
+
* @returns Conf with alpha names replaced by numbers.
|
|
128
119
|
*/
|
|
129
|
-
private
|
|
120
|
+
private replaceAlpha;
|
|
130
121
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @param conf Current part, expected to be a string that might contain jan,feb etc.
|
|
134
|
-
*
|
|
135
|
-
* @returns conf with 0 instead of sun etc.
|
|
122
|
+
* Map of cron nickname patterns to their equivalent cron expressions.
|
|
123
|
+
* @private
|
|
136
124
|
*/
|
|
137
|
-
private
|
|
125
|
+
private static DAY_NAMES;
|
|
126
|
+
private static DAY_NAMES_QUARTZ;
|
|
127
|
+
private static MONTH_NAMES;
|
|
128
|
+
private static NICKNAME_MAP;
|
|
138
129
|
/**
|
|
139
130
|
* Replace nicknames with actual cron patterns
|
|
140
131
|
*
|
|
@@ -319,7 +310,7 @@ declare class CronDate<T = undefined> {
|
|
|
319
310
|
*/
|
|
320
311
|
day: number;
|
|
321
312
|
/**
|
|
322
|
-
* Current month (
|
|
313
|
+
* Current month (0-11), in local time or target timezone specified by `this.tz`
|
|
323
314
|
* @type {number}
|
|
324
315
|
*/
|
|
325
316
|
month: number;
|
|
@@ -406,6 +397,20 @@ declare class CronDate<T = undefined> {
|
|
|
406
397
|
*
|
|
407
398
|
* @private
|
|
408
399
|
*/
|
|
400
|
+
/**
|
|
401
|
+
* Evaluate whether a specific day value matches, applying all day-specific
|
|
402
|
+
* special-case logic (W, LW, L modifiers and DOW AND/OR combination).
|
|
403
|
+
*
|
|
404
|
+
* Used by both `_findMatch` (iterative search) and `match` (static check).
|
|
405
|
+
*
|
|
406
|
+
* @param initialMatch - The match value from the pattern array for this day index
|
|
407
|
+
* @param dayValue - The actual day of month (1-31)
|
|
408
|
+
* @param pattern - The cron pattern to match against
|
|
409
|
+
* @param options - The cron options that influence matching behavior
|
|
410
|
+
* @returns 1 if the day matches, 0 otherwise
|
|
411
|
+
* @private
|
|
412
|
+
*/
|
|
413
|
+
private _matchDayValue;
|
|
409
414
|
private _findMatch;
|
|
410
415
|
/**
|
|
411
416
|
* Increment to next run time recursively.
|
|
@@ -719,6 +724,14 @@ declare class Cron<T = undefined> {
|
|
|
719
724
|
* @returns Previous scheduled run time, or null if no previous run exists
|
|
720
725
|
*/
|
|
721
726
|
private _previous;
|
|
727
|
+
/**
|
|
728
|
+
* Resolve DST fall-back overlap: when increment() produces a next run that is not
|
|
729
|
+
* monotonically advancing in UTC relative to the previous run, adjust to the correct
|
|
730
|
+
* DST occurrence (earlier wall clock, later UTC).
|
|
731
|
+
*
|
|
732
|
+
* @private
|
|
733
|
+
*/
|
|
734
|
+
private _resolveDSTOverlap;
|
|
722
735
|
/**
|
|
723
736
|
* Calculate the previous run if no previous run is supplied, but startAt and interval are set.
|
|
724
737
|
* This calculation is only necessary if the startAt time is before the current time.
|
package/dist/croner.d.ts
CHANGED
|
@@ -111,30 +111,21 @@ declare class CronPattern {
|
|
|
111
111
|
*/
|
|
112
112
|
private handleStepping;
|
|
113
113
|
/**
|
|
114
|
-
* Replace day
|
|
114
|
+
* Replace alpha names (day/month) with numeric values using a mapping.
|
|
115
115
|
*
|
|
116
|
-
* @param conf Current part, expected to be a string that might contain
|
|
117
|
-
*
|
|
118
|
-
* @returns Conf with
|
|
119
|
-
*/
|
|
120
|
-
private replaceAlphaDays;
|
|
121
|
-
/**
|
|
122
|
-
* Replace day name with day numbers (Quartz mode)
|
|
123
|
-
* In Quartz mode: Sunday=1, Monday=2, ..., Saturday=7
|
|
124
|
-
*
|
|
125
|
-
* @param conf Current part, expected to be a string that might contain sun,mon etc.
|
|
126
|
-
*
|
|
127
|
-
* @returns Conf with Quartz-style numbering
|
|
116
|
+
* @param conf Current part, expected to be a string that might contain alpha names.
|
|
117
|
+
* @param mapping Object mapping names to their numeric string replacements.
|
|
118
|
+
* @returns Conf with alpha names replaced by numbers.
|
|
128
119
|
*/
|
|
129
|
-
private
|
|
120
|
+
private replaceAlpha;
|
|
130
121
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @param conf Current part, expected to be a string that might contain jan,feb etc.
|
|
134
|
-
*
|
|
135
|
-
* @returns conf with 0 instead of sun etc.
|
|
122
|
+
* Map of cron nickname patterns to their equivalent cron expressions.
|
|
123
|
+
* @private
|
|
136
124
|
*/
|
|
137
|
-
private
|
|
125
|
+
private static DAY_NAMES;
|
|
126
|
+
private static DAY_NAMES_QUARTZ;
|
|
127
|
+
private static MONTH_NAMES;
|
|
128
|
+
private static NICKNAME_MAP;
|
|
138
129
|
/**
|
|
139
130
|
* Replace nicknames with actual cron patterns
|
|
140
131
|
*
|
|
@@ -319,7 +310,7 @@ declare class CronDate<T = undefined> {
|
|
|
319
310
|
*/
|
|
320
311
|
day: number;
|
|
321
312
|
/**
|
|
322
|
-
* Current month (
|
|
313
|
+
* Current month (0-11), in local time or target timezone specified by `this.tz`
|
|
323
314
|
* @type {number}
|
|
324
315
|
*/
|
|
325
316
|
month: number;
|
|
@@ -406,6 +397,20 @@ declare class CronDate<T = undefined> {
|
|
|
406
397
|
*
|
|
407
398
|
* @private
|
|
408
399
|
*/
|
|
400
|
+
/**
|
|
401
|
+
* Evaluate whether a specific day value matches, applying all day-specific
|
|
402
|
+
* special-case logic (W, LW, L modifiers and DOW AND/OR combination).
|
|
403
|
+
*
|
|
404
|
+
* Used by both `_findMatch` (iterative search) and `match` (static check).
|
|
405
|
+
*
|
|
406
|
+
* @param initialMatch - The match value from the pattern array for this day index
|
|
407
|
+
* @param dayValue - The actual day of month (1-31)
|
|
408
|
+
* @param pattern - The cron pattern to match against
|
|
409
|
+
* @param options - The cron options that influence matching behavior
|
|
410
|
+
* @returns 1 if the day matches, 0 otherwise
|
|
411
|
+
* @private
|
|
412
|
+
*/
|
|
413
|
+
private _matchDayValue;
|
|
409
414
|
private _findMatch;
|
|
410
415
|
/**
|
|
411
416
|
* Increment to next run time recursively.
|
|
@@ -719,6 +724,14 @@ declare class Cron<T = undefined> {
|
|
|
719
724
|
* @returns Previous scheduled run time, or null if no previous run exists
|
|
720
725
|
*/
|
|
721
726
|
private _previous;
|
|
727
|
+
/**
|
|
728
|
+
* Resolve DST fall-back overlap: when increment() produces a next run that is not
|
|
729
|
+
* monotonically advancing in UTC relative to the previous run, adjust to the correct
|
|
730
|
+
* DST occurrence (earlier wall clock, later UTC).
|
|
731
|
+
*
|
|
732
|
+
* @private
|
|
733
|
+
*/
|
|
734
|
+
private _resolveDSTOverlap;
|
|
722
735
|
/**
|
|
723
736
|
* Calculate the previous run if no previous run is supplied, but startAt and interval are set.
|
|
724
737
|
* This calculation is only necessary if the startAt time is before the current time.
|
package/dist/croner.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function w(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function U(s,e){return w(p(s,e))-s.getTime()}function O(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("-")?M(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):M(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function N(s,e,t){return x($(s,e),t)}function x(s,e,t){let r=new Date(w(s)),n=p(r,s.tz),i=w(s),a=w(n),o=i-a,l=new Date(r.getTime()+o),h=p(l,s.tz);if(O(h,s)){let d=U(new Date(l.getTime()-864e5),s.tz)-U(new Date(l.getTime()+864e5),s.tz),f=d>0?d:36e5,g=new Date(l.getTime()-f),_=p(g,s.tz),k=new Date(l.getTime()+f),b=p(k,s.tz),T=O(_,s),R=O(b,s);if(T||R){let C=T?g:l,j=T?l:k;return t!==void 0?C.getTime()>=t?C:j:C}return l}let c=new Date(l.getTime()+w(s)-w(h)),u=p(c,s.tz);if(O(u,s))return c;if(e)throw new Error("Invalid date passed to fromTZ()");return l.getTime()>c.getTime()?l:c}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 M(s,e,t,r,n,i,a){return{y:s,m:e,d:t,h:r,i:n,s:i,tz:a}}var A=[1,2,4,8,16],v=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("*"),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,"*"))),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.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 l=t.split(",");if(l.length>1)for(let h=0;h<l.length;h++)this.partToArray(e,l[h],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,l,h]=a,c=parseInt(o,10)+r,u=parseInt(l,10)+r,d=parseInt(h,10);this.validateNotNaN(c,"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(c,u,d,t,e);for(let f=c;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,l=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(l,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,l,void 0,t,e);for(let h=o;h<=l;h++)this.setPart(t,h,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 l=parseInt(a[1],10);this.validateNotNaN(l,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,l,t,e);for(let h=o;h<this[t].length;h+=l)t==="year"&&h===0||this.setPart(t,h,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]|A[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var S=[31,28,31,30,31,30,31,31,30,31,30,31],m=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],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?S[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 l=1;l<=r;l++)new Date(Date.UTC(e,t,l)).getUTCDay()===a&&o++;if(n&63&&A[o-1]&n)return!0;if(n&32){let l=this.getLastDayOfMonth(e,t);for(let h=r+1;h<=l;h++)if(new Date(Date.UTC(e,t,h)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=p(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.afterMs=e.getTime()-e.getUTCMilliseconds()}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.getLastDayOfMonth(this.year,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 l=!r.starDOW&&t=="day"?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0,h=this[t]+n,c=i===1?u=>u<r[t].length:u=>u>=0;for(let u=h;c(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 g=this.getNearestWeekday(this.year,this.month,f-n);if(g===-1)continue;if(g===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[(l+(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,m[r][0],e,m[r][2]);if(n>1){let i=r+1;for(;i<m.length;)this[m[i][0]]=-m[i][2],i++;if(n===3){if(this[m[r][1]]++,this[m[r][0]]=-m[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>=m.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,m[r][0],e,m[r][2]);if(i>1){let a=r+1;for(;a<m.length;){let o=m[a][0],l=m[a][2],h=this.getMaxPatternValue(o,e,l);o==="day"?this[o]=Math.min(h,this.getLastDayOfMonth(this.year,this.month)):this[o]=h,a++}if(i===3){if(this[m[r][1]]--,r===0){let c=this.getLastDayOfMonth(this.year,this.month);this.day>c&&(this.day=c)}if(r===1)if(this.day<=0)this.day=1;else{let c=this.year,u=this.month;for(;u<0;)u+=12,c--;for(;u>11;)u-=12,c++;let d=u!==1?S[u]:new Date(Date.UTC(c,u+1,0)).getUTCDate();this.day>d&&(this.day=d)}this.apply();let o=m[r][0],l=m[r][2],h=this.getMaxPatternValue(o,e,l);if(o==="day"){let c=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(h,c)}else this[o]=h;if(this.apply(),r===0){let c=m[1][2],u=this.getMaxPatternValue("day",e,c),d=this.getLastDayOfMonth(this.year,this.month),f=Math.min(u,d);f!==this.day&&(this.day=f,this.hour=this.getMaxPatternValue("hour",e,m[2][2]),this.minute=this.getMaxPatternValue("minute",e,m[3][2]),this.second=this.getMaxPatternValue("second",e,m[4][2]))}if(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>=m.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)):x(M(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<m.length;r++){let n=m[r][0],i=m[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 l=0;l<e.nearestWeekdays.length;l++)if(e.nearestWeekdays[l]){let h=this.getNearestWeekday(this.year,this.month,l-i);if(h!==-1&&h===a){o=1;break}}}if(e.lastWeekday){let l=this.getLastWeekday(this.year,this.month);a===l&&(o=1)}if(e.lastDayOfMonth){let l=this.getLastDayOfMonth(this.year,this.month);a===l&&(o=1)}if(!e.starDOW){let l=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),h=e.dayOfWeek[(l+(a-1))%7];h&&h&63&&(h=this.isNthWeekdayOfMonth(this.year,this.month,a,h)?1:0),e.useAndLogic?o=o&&h:!t.domAndDow&&!e.starDOM?o=o||h:o=o&&h}}if(!o)return!1}return!0}};function z(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 D(s){return Object.prototype.toString.call(s)==="[object Function]"||typeof s=="function"||s instanceof Function}function I(s){return D(s)}function L(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var F=30*1e3,P=[],Y=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}_nextTarget(e,t){let r=(this.options.dayOffset??0)*24*60*60*1e3;if(this._states.once&&this._states.currentRun&&this._states.once.getTime()+r<=this._states.currentRun.getTime())return null;let n=new Date(t.getTime()-r),i={startAt:this.options.startAt?new y(new Date(this.options.startAt.getTime()-r),this.getTz()):void 0,stopAt:this.options.stopAt?new y(new Date(this.options.stopAt.getTime()-r),this.getTz()):void 0,includeStartAt:r!==0},a=this._next(e?new Date(e.getTime()-r):void 0,n,i);for(;a;){let o=this.applyDayOffset(a.getDate(!1));if(this.options.startAt&&o.getTime()<this.options.startAt.getTime()){a=this._next(a,n,i);continue}return this.options.stopAt&&o.getTime()>=this.options.stopAt.getTime()?null:o}return null}constructor(e,t,r){let n,i;if(D(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(D(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=z(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 v("* * * * *",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 v(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(P.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");P.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")}enumerate(e){return new E(this,e)}_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 l=o.getDate(!1);n.push(this.applyDayOffset(l)),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);if(t){if(e instanceof y||e instanceof Date)return t.getTime()-e.getTime();{let r=typeof e=="string"?this.getTz():void 0;return t.getTime()-new y(e,r).getTime()}}else return null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=P.indexOf(this);e>=0&&P.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let r=t??new Date,n=this._nextTarget(void 0,r),i=n?n.getTime()-r.getTime():null,a=this._states.blocking&&this.options.protect?void 0:this._states.currentRun,o=this._nextTarget(a,r);return i==null||isNaN(i)||o===null?this:(i>F&&(i=F),i<0&&(i=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),i),this._states.currentTimeout&&this.options.unref&&L(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new y(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(D(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(t)):r&&n&&D(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,r?void 0:t)}_next(e,t,r){let n=r?r.startAt:this.options.startAt,i=r?r.stopAt:this.options.stopAt,a=!!(e||this._states.currentRun),o=!1;!e&&n&&this.options.interval&&([e,a]=this._calculatePreviousRun(e,a,t,n),o=!e),e=new y(e??t,this.getTz());let l=r?.includeStartAt&&n&&!o?new y(new Date(n.getTime()-1e3),this.getTz()):n;l&&e&&e.getTime()<l.getTime()&&(e=l);let h=this._states.once||new y(e,this.getTz());if(!o&&h!==this._states.once&&(h=h.increment(this._states.pattern,this.options,a)),this._states.once){if(n&&this._states.once.getTime()<n.getTime()||this._states.currentRun&&this._states.once.getTime()<=this._states.currentRun.getTime()||e.getTime()===this._states.once.getTime())return null;let c=e.getTime()-this._states.once.getTime();if(c>0&&!this.options.allowPast&&c>1e3)return null}if(h!==null&&h!==this._states.once&&typeof this.getTz()=="string"){let c=e.getTime(),u=h.getTime(),d=(this.options.interval&&a?this.options.interval:1)*1e3,f=u-c,g=e,_=Date.UTC(g.year,g.month,g.day,g.hour,g.minute,g.second)-c,k=Date.UTC(h.year,h.month,h.day,h.hour,h.minute,h.second)-u,b=_-k;if(b>0&&(f>=d+b||f<0)){let T=f<0?u+b:u-b,R=new Date(T),C=new y(R,this.getTz());C.match(this._states.pattern,this.options)&&T>c&&(C.setAfterMs(T),h=C)}}return h===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||i&&h.getTime()>=i.getTime()?null:h}_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,r,n){let i=new y(r,this.getTz()),a=e;if(n&&n.getTime()<=i.getTime()){a=n;let o=a.getTime()+this.options.interval*1e3;for(;o<=i.getTime();){let l=new y(a,this.getTz()).increment(this._states.pattern,this.options,!0);if(l===null)break;a=l,o=a.getTime()+this.options.interval*1e3}t=!0}return a===null&&(a=void 0),[a,t]}},E=class s{cron;cursor;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.cursor=s._normalizeCursor(t),this.done=!1,this.initialMaxRuns=e.options.maxRuns??1/0,this.remainingRuns=this.initialMaxRuns}static _normalizeCursor(e){if(e!=null)return e instanceof Date?new Date(e.getTime()):e}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron.nextRun(this.cursor??null);if(e===null)return this.done=!0,{value:void 0,done:!0};let r=this.cron.options.dayOffset??0,n=e.getTime()-r*24*60*60*1e3;return this.cursor=new Date(n),this.remainingRuns--,{value:e,done:!1}}peek(){return this.done||this.remainingRuns<=0?null:this.cron.nextRun(this.cursor??null)}reset(e){this.cursor=s._normalizeCursor(e),this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}};export{Y as Cron,y as CronDate,E as CronIterator,v as CronPattern,P as scheduledJobs};
|
|
1
|
+
function p(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function E(s,e){return p(y(s,e))-s.getTime()}function b(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 k(s,e,t){return M($(s,e),t)}function M(s,e,t){let r=new Date(p(s)),n=y(r,s.tz),a=p(s),i=p(n),o=a-i,h=new Date(r.getTime()+o),l=y(h,s.tz);if(b(l,s)){let d=E(new Date(h.getTime()-864e5),s.tz)-E(new Date(h.getTime()+864e5),s.tz),g=d>0?d:36e5,A=new Date(h.getTime()-g),L=y(A,s.tz),R=new Date(h.getTime()+g),Y=y(R,s.tz),v=b(L,s),F=b(Y,s);if(v||F){let O=v?A:h,Z=v?h:R;return t!==void 0?O.getTime()>=t?O:Z:O}return h}let u=new Date(h.getTime()+p(s)-p(l)),m=y(u,s.tz);if(b(m,s))return u;if(e)throw new Error("Invalid date passed to fromTZ()");return h.getTime()>u.getTime()?h:u}function y(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(a){let i=a instanceof Error?a.message:String(a);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${i}`)}let n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let a of r)(a.type==="year"||a.type==="month"||a.type==="day"||a.type==="hour"||a.type==="minute"||a.type==="second")&&(n[a.type]=parseInt(a.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,a,i){return{y:s,m:e,d:t,h:r,i:n,s:a,tz:i}}var _=[1,2,4,8,16],T=class s{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 i=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${i} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let n=0;n<e.length;n++)e[n]=e[n].replace(/\?/g,"*");if(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.replaceAlpha(e[4],s.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],s.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],s.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let 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 a=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return a.fill(n);let i=t.split(",");if(i.length>1)for(let o of i)this.partToArray(e,o,r,n);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,r,n):t.includes("-")?this.handleRange(t,e,r,n):t.includes("/")?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 a=this.extractNth(e,t),i=e.toUpperCase().includes("W");if(t!=="day"&&i)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");i&&(t="nearestWeekdays");let o=parseInt(a[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,a[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,a){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+a+"'");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 a=this.extractNth(e,t),i=a[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(i===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,h,l]=i,u=parseInt(o,10)+r,m=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(u,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(u,m,d,t,e);for(let g=u;g<=m;g+=d)this.setPart(t,g,a[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 a=this.extractNth(e,t),i=a[0].split("-");if(i.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(i[0],10)+r,h=parseInt(i[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,a[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 a=this.extractNth(e,t),i=a[0].split("/");if(i.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)i[0]===""&&(i[0]="*");else{if(i[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(i[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;i[0]!=="*"&&(o=parseInt(i[0],10)+r);let h=parseInt(i[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)t==="year"&&l===0||this.setPart(t,l,a[1]||n)}replaceAlpha(e,t){let r=e;for(let[n,a]of Object.entries(t))r=r.replace(new RegExp(n,"gi"),a);return r}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return s.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|_[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var H=[31,28,31,30,31,30,31,31,30,31,30,31],f=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],c=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?H[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r-2:a===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r===n?r-2:r+1:i===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let i=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()===i&&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()===i)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=y(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.afterMs=e.getTime()-e.getUTCMilliseconds()}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.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(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)}_matchDayValue(e,t,r,n){let a=e;if(!a){for(let i=0;i<r.nearestWeekdays.length;i++)if(r.nearestWeekdays[i]){let o=this.getNearestWeekday(this.year,this.month,i+1);if(o!==-1&&o===t){a=1;break}}}if(r.lastWeekday){let i=this.getLastWeekday(this.year,this.month);t===i&&(a=1)}if(r.lastDayOfMonth){let i=this.getLastDayOfMonth(this.year,this.month);t===i&&(a=1)}if(!r.starDOW){let i=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=r.dayOfWeek[(i+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),r.useAndLogic?a=a&&o:!n.domAndDow&&!r.starDOM?a=a||o:a=a&&o}return a}_findMatch(e,t,r,n,a){let i=this[t],o=this[t]+n,h=a===1?l=>l<r[t].length:l=>l>=0;for(let l=o;h(l);l+=a){let u=r[t][l];if(t==="day"&&(u=this._matchDayValue(u,l-n,r,e)),u)return this[t]=l-n,i!==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 a=-1;for(let i=this.year+1;i<e.year.length&&i<1e4;i++)if(e.year[i]===1){a=i;break}if(a===-1)return null;this.year=a,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 a=r+1;for(;a<f.length;)this[f[a][0]]=-f[a][2],a++;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 i=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){i=o;break}if(i===-1)return null;this.year=i,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let a=this.findPrevious(t,f[r][0],e,f[r][2]);if(a>1){let i=r+1;for(;i<f.length;){let o=f[i][0],h=f[i][2],l=this.getMaxPatternValue(o,e,h);o==="day"?this[o]=Math.min(l,this.getLastDayOfMonth(this.year,this.month)):this[o]=l,i++}if(a===3){if(this[f[r][1]]--,r===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(r===1)if(this.day<=0)this.day=1;else{let u=this.year,m=this.month;for(;m<0;)m+=12,u--;for(;m>11;)m-=12,u++;let d=this.getLastDayOfMonth(u,m);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 u=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,u)}else this[o]=l;if(this.apply(),r===0){let u=f[1][2],m=this.getMaxPatternValue("day",e,u),d=this.getLastDayOfMonth(this.year,this.month),g=Math.min(m,d);g!==this.day&&(this.day=g,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,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(w(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<f.length;r++){let n=f[r][0],a=f[r][2],i=this[n];if(i+a<0||i+a>=e[n].length)return!1;let o=e[n][i+a];if(n==="day"&&(o=this._matchDayValue(o,i,e,t)),!o)return!1}return!0}};function U(s){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;let e=(t,r)=>t===void 0?r:t;if(s.paused=e(s.paused,!1),s.maxRuns=e(s.maxRuns,1/0),s.catch=e(s.catch,!1),s.unref=e(s.unref,!1),s.mode=e(s.mode,"auto"),s.alternativeWeekdays=e(s.alternativeWeekdays,!1),s.sloppyRanges=e(s.sloppyRanges,!1),s.allowPast=e(s.allowPast,!1),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),!["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 c(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new c(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 C(s){return typeof s=="function"}function S(s){return C(s)}function W(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var N=1440*60*1e3,z=30*1e3,D=[],I=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*N;return new Date(e.getTime()+t)}return e}_nextTarget(e,t){let r=(this.options.dayOffset??0)*N;if(this._states.once&&this._states.currentRun&&this._states.once.getTime()+r<=this._states.currentRun.getTime())return null;let n=new Date(t.getTime()-r),a=h=>h?new c(new Date(h.getTime()-r),this.getTz()):void 0,i={startAt:a(this.options.startAt),stopAt:a(this.options.stopAt),includeStartAt:r!==0},o=this._next(e?new Date(e.getTime()-r):void 0,n,i);for(;o;){let h=this.applyDayOffset(o.getDate(!1));if(this.options.startAt&&h.getTime()<this.options.startAt.getTime()){o=this._next(o,n,i);continue}return this.options.stopAt&&h.getTime()>=this.options.stopAt.getTime()?null:h}return null}constructor(e,t,r){let n,a;for(let i of[t,r])if(C(i))a=i;else if(typeof i=="object")n=i;else if(i!==void 0)throw new Error("Cron: Invalid argument passed. Should be one of function, or object (options).");if(this.name=n?.name,this.options=U(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 T("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new c(e,this.getTz()):this._states.pattern=new T(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 a!==void 0&&S(a)&&(this.fn=a,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")}enumerate(e){return new P(this,e)}_enumerateRuns(e,t,r){let n=[],a=t?new c(t,this.getTz()):null,i=r==="next"?this._next:this._previous;for(;e--;){let o=i.call(this,a);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),a=o}return n}match(e){if(this._states.once){let r=new c(e,this.getTz());r.ms=0;let n=new c(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.getTime()}let t=new c(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this.nextRun(this._states.currentRun)!==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);if(t){if(e instanceof c||e instanceof Date)return t.getTime()-e.getTime();{let r=typeof e=="string"?this.getTz():void 0;return t.getTime()-new c(e,r).getTime()}}else return 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){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let r=t??new Date,n=this._states.blocking&&this.options.protect?void 0:this._states.currentRun,a=n&&n.getTime()>r.getTime()?void 0:n,i=this._nextTarget(void 0,r),o=i?i.getTime()-r.getTime():null,h=this._nextTarget(a,r);return o==null||isNaN(o)||h===null?this:(o>z&&(o=z),o<0&&(o=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(h),o),this._states.currentTimeout&&this.options.unref&&W(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new c(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(C(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new c(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(t)):r&&n&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,r?void 0:t)}_next(e,t,r){let n=r?r.startAt:this.options.startAt,a=r?r.stopAt:this.options.stopAt,i=!!(e||this._states.currentRun),o=!1;!e&&n&&this.options.interval&&([e,i]=this._calculatePreviousRun(e,i,t,n),o=!e),e=new c(e??t,this.getTz());let h=r?.includeStartAt&&n&&!o?new c(new Date(n.getTime()-1e3),this.getTz()):n;h&&e&&e.getTime()<h.getTime()&&(e=h);let l=this._states.once||new c(e,this.getTz());if(!o&&l!==this._states.once&&(l=l.increment(this._states.pattern,this.options,i)),this._states.once){if(n&&this._states.once.getTime()<n.getTime()||this._states.currentRun&&this._states.once.getTime()<=this._states.currentRun.getTime()||e.getTime()===this._states.once.getTime())return null;let u=e.getTime()-this._states.once.getTime();if(u>0&&!this.options.allowPast&&u>1e3)return null}return l=this._resolveDSTOverlap(l,e,i),l===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||a&&l.getTime()>=a.getTime()?null:l}_previous(e){let t=new c(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new c(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)}_resolveDSTOverlap(e,t,r){if(e===null||e===this._states.once||typeof this.getTz()!="string")return e;let n=t.getTime(),a=e.getTime(),i=(this.options.interval&&r?this.options.interval:1)*1e3,o=a-n,h=Date.UTC(t.year,t.month,t.day,t.hour,t.minute,t.second)-n,l=Date.UTC(e.year,e.month,e.day,e.hour,e.minute,e.second)-a,u=h-l;if(u>0&&(o>=i+u||o<0)){let m=o<0?a+u:a-u,d=new Date(m),g=new c(d,this.getTz());if(g.match(this._states.pattern,this.options)&&m>n)return g.setAfterMs(m),g}return e}_calculatePreviousRun(e,t,r,n){let a=new c(r,this.getTz()),i=e;if(n&&n.getTime()<=a.getTime()){i=n;let o=i.getTime()+this.options.interval*1e3;for(;o<=a.getTime();){let h=new c(i,this.getTz()).increment(this._states.pattern,this.options,!0);if(h===null)break;i=h,o=i.getTime()+this.options.interval*1e3}t=!0}return i===null&&(i=void 0),[i,t]}},P=class s{cron;cursor;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.cursor=s._normalizeCursor(t),this.done=!1,this.initialMaxRuns=e.options.maxRuns??1/0,this.remainingRuns=this.initialMaxRuns}static _normalizeCursor(e){if(e!=null)return e instanceof Date?new Date(e.getTime()):e}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron.nextRun(this.cursor??null);if(e===null)return this.done=!0,{value:void 0,done:!0};let r=this.cron.options.dayOffset??0,n=e.getTime()-r*N;return this.cursor=new Date(n),this.remainingRuns--,{value:e,done:!1}}peek(){return this.done||this.remainingRuns<=0?null:this.cron.nextRun(this.cursor??null)}reset(e){this.cursor=s._normalizeCursor(e),this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}};export{I as Cron,c as CronDate,P as CronIterator,T as CronPattern,D as scheduledJobs};
|
package/dist/croner.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Cron=(()=>{var w=(s,e,t)=>()=>{if(t)throw t[0];try{return s&&(e=s(s=0)),e}catch(r){throw t=[r],r}};var G=(s,e)=>()=>{try{return e||s((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};function D(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function L(s,e){return D(p(s,e))-s.getTime()}function M(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 Q(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("-")?P(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):P(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function A(s,e,t){return W(Q(s,e),t)}function W(s,e,t){let r=new Date(D(s)),n=p(r,s.tz),i=D(s),a=D(n),o=i-a,l=new Date(r.getTime()+o),h=p(l,s.tz);if(M(h,s)){let d=L(new Date(l.getTime()-864e5),s.tz)-L(new Date(l.getTime()+864e5),s.tz),f=d>0?d:36e5,g=new Date(l.getTime()-f),N=p(g,s.tz),O=new Date(l.getTime()+f),b=p(O,s.tz),T=M(N,s),x=M(b,s);if(T||x){let C=T?g:l,K=T?l:O;return t!==void 0?C.getTime()>=t?C:K:C}return l}let c=new Date(l.getTime()+D(s)-D(h)),u=p(c,s.tz);if(M(u,s))return c;if(e)throw new Error("Invalid date passed to fromTZ()");return l.getTime()>c.getTime()?l:c}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 P(s,e,t,r,n,i,a){return{y:s,m:e,d:t,h:r,i:n,s:i,tz:a}}var F=w(()=>{});var E,k,U=w(()=>{E=[1,2,4,8,16],k=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("*"),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,"*"))),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.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 l=t.split(",");if(l.length>1)for(let h=0;h<l.length;h++)this.partToArray(e,l[h],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,l,h]=a,c=parseInt(o,10)+r,u=parseInt(l,10)+r,d=parseInt(h,10);this.validateNotNaN(c,"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(c,u,d,t,e);for(let f=c;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,l=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(l,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,l,void 0,t,e);for(let h=o;h<=l;h++)this.setPart(t,h,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 l=parseInt(a[1],10);this.validateNotNaN(l,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,l,t,e);for(let h=o;h<this[t].length;h+=l)t==="year"&&h===0||this.setPart(t,h,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]|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 Y,m,y,z=w(()=>{F();U();Y=[31,28,31,30,31,30,31,31,30,31,30,31],m=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],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?Y[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 l=1;l<=r;l++)new Date(Date.UTC(e,t,l)).getUTCDay()===a&&o++;if(n&63&&E[o-1]&n)return!0;if(n&32){let l=this.getLastDayOfMonth(e,t);for(let h=r+1;h<=l;h++)if(new Date(Date.UTC(e,t,h)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=p(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.afterMs=e.getTime()-e.getUTCMilliseconds()}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.getLastDayOfMonth(this.year,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=A(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(A(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 l=!r.starDOW&&t=="day"?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0,h=this[t]+n,c=i===1?u=>u<r[t].length:u=>u>=0;for(let u=h;c(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 g=this.getNearestWeekday(this.year,this.month,f-n);if(g===-1)continue;if(g===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[(l+(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,m[r][0],e,m[r][2]);if(n>1){let i=r+1;for(;i<m.length;)this[m[i][0]]=-m[i][2],i++;if(n===3){if(this[m[r][1]]++,this[m[r][0]]=-m[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>=m.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,m[r][0],e,m[r][2]);if(i>1){let a=r+1;for(;a<m.length;){let o=m[a][0],l=m[a][2],h=this.getMaxPatternValue(o,e,l);o==="day"?this[o]=Math.min(h,this.getLastDayOfMonth(this.year,this.month)):this[o]=h,a++}if(i===3){if(this[m[r][1]]--,r===0){let c=this.getLastDayOfMonth(this.year,this.month);this.day>c&&(this.day=c)}if(r===1)if(this.day<=0)this.day=1;else{let c=this.year,u=this.month;for(;u<0;)u+=12,c--;for(;u>11;)u-=12,c++;let d=u!==1?Y[u]:new Date(Date.UTC(c,u+1,0)).getUTCDate();this.day>d&&(this.day=d)}this.apply();let o=m[r][0],l=m[r][2],h=this.getMaxPatternValue(o,e,l);if(o==="day"){let c=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(h,c)}else this[o]=h;if(this.apply(),r===0){let c=m[1][2],u=this.getMaxPatternValue("day",e,c),d=this.getLastDayOfMonth(this.year,this.month),f=Math.min(u,d);f!==this.day&&(this.day=f,this.hour=this.getMaxPatternValue("hour",e,m[2][2]),this.minute=this.getMaxPatternValue("minute",e,m[3][2]),this.second=this.getMaxPatternValue("second",e,m[4][2]))}if(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>=m.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)):W(P(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<m.length;r++){let n=m[r][0],i=m[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 l=0;l<e.nearestWeekdays.length;l++)if(e.nearestWeekdays[l]){let h=this.getNearestWeekday(this.year,this.month,l-i);if(h!==-1&&h===a){o=1;break}}}if(e.lastWeekday){let l=this.getLastWeekday(this.year,this.month);a===l&&(o=1)}if(e.lastDayOfMonth){let l=this.getLastDayOfMonth(this.year,this.month);a===l&&(o=1)}if(!e.starDOW){let l=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),h=e.dayOfWeek[(l+(a-1))%7];h&&h&63&&(h=this.isNthWeekdayOfMonth(this.year,this.month,a,h)?1:0),e.useAndLogic?o=o&&h:!t.domAndDow&&!e.starDOM?o=o||h:o=o&&h}}if(!o)return!1}return!0}}});function j(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 $=w(()=>{z()});function v(s){return Object.prototype.toString.call(s)==="[object Function]"||typeof s=="function"||s instanceof Function}function V(s){return v(s)}function Z(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var B=w(()=>{});var H,_,R,I,J=w(()=>{z();U();$();B();H=30*1e3,_=[],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}_nextTarget(e,t){let r=(this.options.dayOffset??0)*24*60*60*1e3;if(this._states.once&&this._states.currentRun&&this._states.once.getTime()+r<=this._states.currentRun.getTime())return null;let n=new Date(t.getTime()-r),i={startAt:this.options.startAt?new y(new Date(this.options.startAt.getTime()-r),this.getTz()):void 0,stopAt:this.options.stopAt?new y(new Date(this.options.stopAt.getTime()-r),this.getTz()):void 0,includeStartAt:r!==0},a=this._next(e?new Date(e.getTime()-r):void 0,n,i);for(;a;){let o=this.applyDayOffset(a.getDate(!1));if(this.options.startAt&&o.getTime()<this.options.startAt.getTime()){a=this._next(a,n,i);continue}return this.options.stopAt&&o.getTime()>=this.options.stopAt.getTime()?null:o}return null}constructor(e,t,r){let n,i;if(v(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(v(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=j(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 k("* * * * *",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 k(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(_.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");_.push(this)}return i!==void 0&&V(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")}enumerate(e){return new I(this,e)}_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 l=o.getDate(!1);n.push(this.applyDayOffset(l)),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);if(t){if(e instanceof y||e instanceof Date)return t.getTime()-e.getTime();{let r=typeof e=="string"?this.getTz():void 0;return t.getTime()-new y(e,r).getTime()}}else return null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=_.indexOf(this);e>=0&&_.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let r=t??new Date,n=this._nextTarget(void 0,r),i=n?n.getTime()-r.getTime():null,a=this._states.blocking&&this.options.protect?void 0:this._states.currentRun,o=this._nextTarget(a,r);return i==null||isNaN(i)||o===null?this:(i>H&&(i=H),i<0&&(i=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),i),this._states.currentTimeout&&this.options.unref&&Z(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new y(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(v(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(t)):r&&n&&v(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,r?void 0:t)}_next(e,t,r){let n=r?r.startAt:this.options.startAt,i=r?r.stopAt:this.options.stopAt,a=!!(e||this._states.currentRun),o=!1;!e&&n&&this.options.interval&&([e,a]=this._calculatePreviousRun(e,a,t,n),o=!e),e=new y(e??t,this.getTz());let l=r?.includeStartAt&&n&&!o?new y(new Date(n.getTime()-1e3),this.getTz()):n;l&&e&&e.getTime()<l.getTime()&&(e=l);let h=this._states.once||new y(e,this.getTz());if(!o&&h!==this._states.once&&(h=h.increment(this._states.pattern,this.options,a)),this._states.once){if(n&&this._states.once.getTime()<n.getTime()||this._states.currentRun&&this._states.once.getTime()<=this._states.currentRun.getTime()||e.getTime()===this._states.once.getTime())return null;let c=e.getTime()-this._states.once.getTime();if(c>0&&!this.options.allowPast&&c>1e3)return null}if(h!==null&&h!==this._states.once&&typeof this.getTz()=="string"){let c=e.getTime(),u=h.getTime(),d=(this.options.interval&&a?this.options.interval:1)*1e3,f=u-c,g=e,N=Date.UTC(g.year,g.month,g.day,g.hour,g.minute,g.second)-c,O=Date.UTC(h.year,h.month,h.day,h.hour,h.minute,h.second)-u,b=N-O;if(b>0&&(f>=d+b||f<0)){let T=f<0?u+b:u-b,x=new Date(T),C=new y(x,this.getTz());C.match(this._states.pattern,this.options)&&T>c&&(C.setAfterMs(T),h=C)}}return h===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||i&&h.getTime()>=i.getTime()?null:h}_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,r,n){let i=new y(r,this.getTz()),a=e;if(n&&n.getTime()<=i.getTime()){a=n;let o=a.getTime()+this.options.interval*1e3;for(;o<=i.getTime();){let l=new y(a,this.getTz()).increment(this._states.pattern,this.options,!0);if(l===null)break;a=l,o=a.getTime()+this.options.interval*1e3}t=!0}return a===null&&(a=void 0),[a,t]}},I=class s{cron;cursor;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.cursor=s._normalizeCursor(t),this.done=!1,this.initialMaxRuns=e.options.maxRuns??1/0,this.remainingRuns=this.initialMaxRuns}static _normalizeCursor(e){if(e!=null)return e instanceof Date?new Date(e.getTime()):e}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron.nextRun(this.cursor??null);if(e===null)return this.done=!0,{value:void 0,done:!0};let r=this.cron.options.dayOffset??0,n=e.getTime()-r*24*60*60*1e3;return this.cursor=new Date(n),this.remainingRuns--,{value:e,done:!1}}peek(){return this.done||this.remainingRuns<=0?null:this.cron.nextRun(this.cursor??null)}reset(e){this.cursor=s._normalizeCursor(e),this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}}});var ee=G((ge,q)=>{J();q.exports=R});return ee();})();
|
|
1
|
+
var Cron=(()=>{var p=(s,e,t)=>()=>{if(t)throw t[0];try{return s&&(e=s(s=0)),e}catch(r){throw t=[r],r}};var G=(s,e)=>()=>{try{return e||s((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};function T(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function W(s,e){return T(y(s,e))-s.getTime()}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 Q(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 _(s,e,t){return N(Q(s,e),t)}function N(s,e,t){let r=new Date(T(s)),n=y(r,s.tz),a=T(s),i=T(n),o=a-i,h=new Date(r.getTime()+o),l=y(h,s.tz);if(w(l,s)){let d=W(new Date(h.getTime()-864e5),s.tz)-W(new Date(h.getTime()+864e5),s.tz),g=d>0?d:36e5,U=new Date(h.getTime()-g),B=y(U,s.tz),S=new Date(h.getTime()+g),J=y(S,s.tz),k=w(B,s),K=w(J,s);if(k||K){let M=k?U:h,q=k?h:S;return t!==void 0?M.getTime()>=t?M:q:M}return h}let u=new Date(h.getTime()+T(s)-T(l)),m=y(u,s.tz);if(w(m,s))return u;if(e)throw new Error("Invalid date passed to fromTZ()");return h.getTime()>u.getTime()?h:u}function y(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(a){let i=a instanceof Error?a.message:String(a);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${i}`)}let n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let a of r)(a.type==="year"||a.type==="month"||a.type==="day"||a.type==="hour"||a.type==="minute"||a.type==="second")&&(n[a.type]=parseInt(a.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,a,i){return{y:s,m:e,d:t,h:r,i:n,s:a,tz:i}}var z=p(()=>{});var P,C,A=p(()=>{P=[1,2,4,8,16],C=class s{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 i=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${i} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let n=0;n<e.length;n++)e[n]=e[n].replace(/\?/g,"*");if(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.replaceAlpha(e[4],s.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],s.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],s.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let 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 a=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return a.fill(n);let i=t.split(",");if(i.length>1)for(let o of i)this.partToArray(e,o,r,n);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,r,n):t.includes("-")?this.handleRange(t,e,r,n):t.includes("/")?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 a=this.extractNth(e,t),i=e.toUpperCase().includes("W");if(t!=="day"&&i)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");i&&(t="nearestWeekdays");let o=parseInt(a[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,a[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,a){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+a+"'");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 a=this.extractNth(e,t),i=a[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(i===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,h,l]=i,u=parseInt(o,10)+r,m=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(u,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(u,m,d,t,e);for(let g=u;g<=m;g+=d)this.setPart(t,g,a[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 a=this.extractNth(e,t),i=a[0].split("-");if(i.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(i[0],10)+r,h=parseInt(i[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,a[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 a=this.extractNth(e,t),i=a[0].split("/");if(i.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)i[0]===""&&(i[0]="*");else{if(i[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(i[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;i[0]!=="*"&&(o=parseInt(i[0],10)+r);let h=parseInt(i[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)t==="year"&&l===0||this.setPart(t,l,a[1]||n)}replaceAlpha(e,t){let r=e;for(let[n,a]of Object.entries(t))r=r.replace(new RegExp(n,"gi"),a);return r}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return s.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|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 ee,f,c,R=p(()=>{z();A();ee=[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]],c=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?ee[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r-2:a===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r===n?r-2:r+1:i===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let i=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()===i&&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()===i)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=y(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.afterMs=e.getTime()-e.getUTCMilliseconds()}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.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(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=_(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(_(e,this.tz))}findNext(e,t,r,n){return this._findMatch(e,t,r,n,1)}_matchDayValue(e,t,r,n){let a=e;if(!a){for(let i=0;i<r.nearestWeekdays.length;i++)if(r.nearestWeekdays[i]){let o=this.getNearestWeekday(this.year,this.month,i+1);if(o!==-1&&o===t){a=1;break}}}if(r.lastWeekday){let i=this.getLastWeekday(this.year,this.month);t===i&&(a=1)}if(r.lastDayOfMonth){let i=this.getLastDayOfMonth(this.year,this.month);t===i&&(a=1)}if(!r.starDOW){let i=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=r.dayOfWeek[(i+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),r.useAndLogic?a=a&&o:!n.domAndDow&&!r.starDOM?a=a||o:a=a&&o}return a}_findMatch(e,t,r,n,a){let i=this[t],o=this[t]+n,h=a===1?l=>l<r[t].length:l=>l>=0;for(let l=o;h(l);l+=a){let u=r[t][l];if(t==="day"&&(u=this._matchDayValue(u,l-n,r,e)),u)return this[t]=l-n,i!==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 a=-1;for(let i=this.year+1;i<e.year.length&&i<1e4;i++)if(e.year[i]===1){a=i;break}if(a===-1)return null;this.year=a,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 a=r+1;for(;a<f.length;)this[f[a][0]]=-f[a][2],a++;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 i=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){i=o;break}if(i===-1)return null;this.year=i,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let a=this.findPrevious(t,f[r][0],e,f[r][2]);if(a>1){let i=r+1;for(;i<f.length;){let o=f[i][0],h=f[i][2],l=this.getMaxPatternValue(o,e,h);o==="day"?this[o]=Math.min(l,this.getLastDayOfMonth(this.year,this.month)):this[o]=l,i++}if(a===3){if(this[f[r][1]]--,r===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(r===1)if(this.day<=0)this.day=1;else{let u=this.year,m=this.month;for(;m<0;)m+=12,u--;for(;m>11;)m-=12,u++;let d=this.getLastDayOfMonth(u,m);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 u=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,u)}else this[o]=l;if(this.apply(),r===0){let u=f[1][2],m=this.getMaxPatternValue("day",e,u),d=this.getLastDayOfMonth(this.year,this.month),g=Math.min(m,d);g!==this.day&&(this.day=g,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,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(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<f.length;r++){let n=f[r][0],a=f[r][2],i=this[n];if(i+a<0||i+a>=e[n].length)return!1;let o=e[n][i+a];if(n==="day"&&(o=this._matchDayValue(o,i,e,t)),!o)return!1}return!0}}});function L(s){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;let e=(t,r)=>t===void 0?r:t;if(s.paused=e(s.paused,!1),s.maxRuns=e(s.maxRuns,1/0),s.catch=e(s.catch,!1),s.unref=e(s.unref,!1),s.mode=e(s.mode,"auto"),s.alternativeWeekdays=e(s.alternativeWeekdays,!1),s.sloppyRanges=e(s.sloppyRanges,!1),s.allowPast=e(s.allowPast,!1),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),!["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 c(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new c(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 Y=p(()=>{R()});function b(s){return typeof s=="function"}function F(s){return b(s)}function Z(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var $=p(()=>{});var E,j,v,O,x,H=p(()=>{R();A();Y();$();E=1440*60*1e3,j=30*1e3,v=[],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*E;return new Date(e.getTime()+t)}return e}_nextTarget(e,t){let r=(this.options.dayOffset??0)*E;if(this._states.once&&this._states.currentRun&&this._states.once.getTime()+r<=this._states.currentRun.getTime())return null;let n=new Date(t.getTime()-r),a=h=>h?new c(new Date(h.getTime()-r),this.getTz()):void 0,i={startAt:a(this.options.startAt),stopAt:a(this.options.stopAt),includeStartAt:r!==0},o=this._next(e?new Date(e.getTime()-r):void 0,n,i);for(;o;){let h=this.applyDayOffset(o.getDate(!1));if(this.options.startAt&&h.getTime()<this.options.startAt.getTime()){o=this._next(o,n,i);continue}return this.options.stopAt&&h.getTime()>=this.options.stopAt.getTime()?null:h}return null}constructor(e,t,r){let n,a;for(let i of[t,r])if(b(i))a=i;else if(typeof i=="object")n=i;else if(i!==void 0)throw new Error("Cron: Invalid argument passed. Should be one of function, or object (options).");if(this.name=n?.name,this.options=L(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 c(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(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 a!==void 0&&F(a)&&(this.fn=a,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")}enumerate(e){return new x(this,e)}_enumerateRuns(e,t,r){let n=[],a=t?new c(t,this.getTz()):null,i=r==="next"?this._next:this._previous;for(;e--;){let o=i.call(this,a);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),a=o}return n}match(e){if(this._states.once){let r=new c(e,this.getTz());r.ms=0;let n=new c(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.getTime()}let t=new c(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this.nextRun(this._states.currentRun)!==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);if(t){if(e instanceof c||e instanceof Date)return t.getTime()-e.getTime();{let r=typeof e=="string"?this.getTz():void 0;return t.getTime()-new c(e,r).getTime()}}else return 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){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let r=t??new Date,n=this._states.blocking&&this.options.protect?void 0:this._states.currentRun,a=n&&n.getTime()>r.getTime()?void 0:n,i=this._nextTarget(void 0,r),o=i?i.getTime()-r.getTime():null,h=this._nextTarget(a,r);return o==null||isNaN(o)||h===null?this:(o>j&&(o=j),o<0&&(o=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(h),o),this._states.currentTimeout&&this.options.unref&&Z(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new c(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(b(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new c(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(t)):r&&n&&b(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,r?void 0:t)}_next(e,t,r){let n=r?r.startAt:this.options.startAt,a=r?r.stopAt:this.options.stopAt,i=!!(e||this._states.currentRun),o=!1;!e&&n&&this.options.interval&&([e,i]=this._calculatePreviousRun(e,i,t,n),o=!e),e=new c(e??t,this.getTz());let h=r?.includeStartAt&&n&&!o?new c(new Date(n.getTime()-1e3),this.getTz()):n;h&&e&&e.getTime()<h.getTime()&&(e=h);let l=this._states.once||new c(e,this.getTz());if(!o&&l!==this._states.once&&(l=l.increment(this._states.pattern,this.options,i)),this._states.once){if(n&&this._states.once.getTime()<n.getTime()||this._states.currentRun&&this._states.once.getTime()<=this._states.currentRun.getTime()||e.getTime()===this._states.once.getTime())return null;let u=e.getTime()-this._states.once.getTime();if(u>0&&!this.options.allowPast&&u>1e3)return null}return l=this._resolveDSTOverlap(l,e,i),l===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||a&&l.getTime()>=a.getTime()?null:l}_previous(e){let t=new c(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new c(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)}_resolveDSTOverlap(e,t,r){if(e===null||e===this._states.once||typeof this.getTz()!="string")return e;let n=t.getTime(),a=e.getTime(),i=(this.options.interval&&r?this.options.interval:1)*1e3,o=a-n,h=Date.UTC(t.year,t.month,t.day,t.hour,t.minute,t.second)-n,l=Date.UTC(e.year,e.month,e.day,e.hour,e.minute,e.second)-a,u=h-l;if(u>0&&(o>=i+u||o<0)){let m=o<0?a+u:a-u,d=new Date(m),g=new c(d,this.getTz());if(g.match(this._states.pattern,this.options)&&m>n)return g.setAfterMs(m),g}return e}_calculatePreviousRun(e,t,r,n){let a=new c(r,this.getTz()),i=e;if(n&&n.getTime()<=a.getTime()){i=n;let o=i.getTime()+this.options.interval*1e3;for(;o<=a.getTime();){let h=new c(i,this.getTz()).increment(this._states.pattern,this.options,!0);if(h===null)break;i=h,o=i.getTime()+this.options.interval*1e3}t=!0}return i===null&&(i=void 0),[i,t]}},x=class s{cron;cursor;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.cursor=s._normalizeCursor(t),this.done=!1,this.initialMaxRuns=e.options.maxRuns??1/0,this.remainingRuns=this.initialMaxRuns}static _normalizeCursor(e){if(e!=null)return e instanceof Date?new Date(e.getTime()):e}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron.nextRun(this.cursor??null);if(e===null)return this.done=!0,{value:void 0,done:!0};let r=this.cron.options.dayOffset??0,n=e.getTime()-r*E;return this.cursor=new Date(n),this.remainingRuns--,{value:e,done:!1}}peek(){return this.done||this.remainingRuns<=0?null:this.cron.nextRun(this.cursor??null)}reset(e){this.cursor=s._normalizeCursor(e),this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}}});var te=G((pe,V)=>{H();V.exports=O});return te();})();
|
package/package.json
CHANGED