@stacksjs/cron 0.70.72 → 0.70.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { parseCron } from './parser';
|
|
|
8
8
|
// parse('0 0 * * *') → next midnight UTC
|
|
9
9
|
// parse('@hourly') → next hour
|
|
10
10
|
// parse('0,15,30,45 * * * *') → next 15-min mark
|
|
11
|
-
export declare function parse(expression: string, relativeDate?: Date | number): Date | null;
|
|
11
|
+
export declare function parse(expression: string, relativeDate?: Date | number, options?: import('./parser').ParseCronOptions): Date | null;
|
|
12
12
|
/**
|
|
13
13
|
* Register an OS-level cron job that persists across process restarts.
|
|
14
14
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var g={"@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 * * * *"},w={jan:1,feb:2,mar:3,apr:4,may:5,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12,january:1,february:2,march:3,april:4,june:6,july:7,august:8,september:9,october:10,november:11,december:12},M={sun:0,mon:1,tue:2,wed:3,thu:4,fri:5,sat:6,sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6},S=new Set;function D(q,b){if(S.has(q))return;S.add(q),console.warn(`[cron] 6-field cron expression '${q}' has seconds='${b}' \u2014 the parser is 5-field only. `+"Seconds field IGNORED. For second-precision use the scheduler's '.everySecond()' instead.")}function y(q,b){return q.replace(/[a-z]+/gi,(
|
|
2
|
+
var g={"@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 * * * *"},w={jan:1,feb:2,mar:3,apr:4,may:5,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12,january:1,february:2,march:3,april:4,june:6,july:7,august:8,september:9,october:10,november:11,december:12},M={sun:0,mon:1,tue:2,wed:3,thu:4,fri:5,sat:6,sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6},S=new Set;function D(q,b){if(S.has(q))return;S.add(q),console.warn(`[cron] 6-field cron expression '${q}' has seconds='${b}' \u2014 the parser is 5-field only. `+"Seconds field IGNORED. For second-precision use the scheduler's '.everySecond()' instead.")}function y(q,b){return q.replace(/[a-z]+/gi,(J)=>{let X=b[J.toLowerCase()];if(X===void 0)throw Error(`Invalid cron value: ${J}`);return String(X)})}function U(q,b,J,X){let _=X?y(q,X):q,R=new Set;for(let H of _.split(",")){let $=H.match(/^(.+)\/(\d+)$/),V,Z=1;if($){if(V=$[1]??"",Z=Number.parseInt($[2]??"",10),Z<=0)throw Error(`Invalid step: ${Z}`)}else V=H;if(V==="*")for(let C=b;C<=J;C+=Z)R.add(C);else if(V.includes("-")){let[C,L]=V.split("-"),K=Number.parseInt(C??"",10),Y=Number.parseInt(L??"",10);if(Number.isNaN(K)||Number.isNaN(Y))throw Error(`Invalid range: ${V}`);if(K<b||Y>J)throw Error(`Range out of bounds: ${V} (${b}-${J})`);for(let j=K;j<=Y;j+=Z)R.add(j)}else{let C=Number.parseInt(V,10);if(Number.isNaN(C))throw Error(`Invalid cron value: ${V}`);if(C<b||C>J)throw Error(`Value out of range: ${C} (${b}-${J})`);R.add(C)}}return R}function P(q,b,J={}){let X=q.trim(),R=(g[X.toLowerCase()]??X).split(/\s+/).filter(Boolean);if(R.length===6){let Q=R[0];if(Q!=="0"&&Q!=="*")D(q,Q);R=R.slice(1)}if(R.length!==5)throw Error(`Invalid cron expression: expected 5 fields (or 6 with leading seconds), got ${R.length}`);let[H,$,V,Z,C]=R,L=U(H,0,59),K=U($,0,23),Y=U(V,1,31),j=U(Z,1,12,w),E=U(C,0,7,M);if(E.has(7))E.add(0),E.delete(7);let k=V==="*",z=C==="*",I=b instanceof Date?b.getTime():typeof b==="number"?b:Date.now();if(Number.isNaN(I)||!Number.isFinite(I))throw Error("Invalid date");let A=J.tz,T=A?x(A):(Q)=>({year:Q.getUTCFullYear(),month:Q.getUTCMonth()+1,day:Q.getUTCDate(),hour:Q.getUTCHours(),minute:Q.getUTCMinutes(),dow:Q.getUTCDay()}),G=new Date(I);G.setUTCSeconds(0,0),G.setUTCMinutes(G.getUTCMinutes()+1);let W=G.getTime()+126230400000;while(G.getTime()<W){let Q=T(G);if(!j.has(Q.month)){G.setUTCMonth(G.getUTCMonth()+1,1),G.setUTCHours(0,0,0,0);continue}let N=Y.has(Q.day),O=E.has(Q.dow),B;if(k&&z)B=!0;else if(k)B=O;else if(z)B=N;else B=N||O;if(!B){G.setUTCDate(G.getUTCDate()+1),G.setUTCHours(0,0,0,0);continue}if(!K.has(Q.hour)){G.setUTCHours(G.getUTCHours()+1,0,0,0);continue}if(!L.has(Q.minute)){G.setUTCMinutes(G.getUTCMinutes()+1,0,0);continue}return new Date(G.getTime())}return null}function x(q){let b=new Intl.DateTimeFormat("en-US",{timeZone:q,hourCycle:"h23",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",weekday:"short"}),J={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return(X)=>{let _=b.formatToParts(X),R=0,H=0,$=0,V=0,Z=0,C=0;for(let L of _)if(L.type==="year")R=Number.parseInt(L.value,10);else if(L.type==="month")H=Number.parseInt(L.value,10);else if(L.type==="day")$=Number.parseInt(L.value,10);else if(L.type==="hour")V=Number.parseInt(L.value,10)%24;else if(L.type==="minute")Z=Number.parseInt(L.value,10);else if(L.type==="weekday")C=J[L.value]??0;return{year:R,month:H,day:$,hour:V,minute:Z,dow:C}}}function v(q,b,J={}){if(typeof Bun<"u"&&Bun.cron?.parse)return Bun.cron.parse(q,b);return P(q,b,J)}async function f(q,b,J){if(typeof Bun>"u"||!Bun.cron)throw Error("Bun.cron is not available. OS-level cron requires a Bun version with native cron support.");await Bun.cron(q,b,J)}async function c(q){if(typeof Bun>"u"||!Bun.cron?.remove)throw Error("Bun.cron is not available. OS-level cron requires a Bun version with native cron support.");await Bun.cron.remove(q)}export{c as remove,f as register,P as parseCron,v as parse};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/cron",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.70.
|
|
4
|
+
"version": "0.70.74",
|
|
5
5
|
"description": "The Stacks cron.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|
|
@@ -52,6 +52,6 @@
|
|
|
52
52
|
"prepublishOnly": "bun run build"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"better-dx": "^0.2.
|
|
55
|
+
"better-dx": "^0.2.16"
|
|
56
56
|
}
|
|
57
57
|
}
|