croner 8.1.2 → 9.0.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types/croner.d.ts DELETED
@@ -1,320 +0,0 @@
1
- export type TimePoint = {
2
- /**
3
- * - 1970--
4
- */
5
- y: number;
6
- /**
7
- * - 1-12
8
- */
9
- m: number;
10
- /**
11
- * - 1-31
12
- */
13
- d: number;
14
- /**
15
- * - 0-24
16
- */
17
- h: number;
18
- /**
19
- * - 0-60 Minute
20
- */
21
- i: number;
22
- /**
23
- * - 0-60
24
- */
25
- s: number;
26
- /**
27
- * - Time zone in IANA database format 'Europe/Stockholm'
28
- */
29
- tz: string;
30
- };
31
- export type CatchCallbackFn = (e: unknown, job: Cron) => any;
32
- export type ProtectCallbackFn = (job: Cron) => any;
33
- /**
34
- * - Cron scheduler options
35
- */
36
- export type CronOptions = {
37
- /**
38
- * - Name of a job
39
- */
40
- name?: string;
41
- /**
42
- * - Job is paused
43
- */
44
- paused?: boolean;
45
- /**
46
- * - Job is about to be killed or killed
47
- */
48
- kill?: boolean;
49
- /**
50
- * - Continue exection even if a unhandled error is thrown by triggered function
51
- * - If set to a function, execute function on catching the error.
52
- */
53
- catch?: boolean | CatchCallbackFn;
54
- /**
55
- * - Abort job instantly if nothing else keeps the event loop running.
56
- */
57
- unref?: boolean;
58
- /**
59
- * - Maximum nuber of executions
60
- */
61
- maxRuns?: number;
62
- /**
63
- * - Minimum interval between executions, in seconds
64
- */
65
- interval?: number;
66
- /**
67
- * - Skip current run if job is already running
68
- */
69
- protect?: boolean | ProtectCallbackFn;
70
- /**
71
- * - When to start running
72
- */
73
- startAt?: string | Date;
74
- /**
75
- * - When to stop running
76
- */
77
- stopAt?: string | Date;
78
- /**
79
- * - Time zone in Europe/Stockholm format
80
- */
81
- timezone?: string;
82
- /**
83
- * - Offset from UTC in minutes
84
- */
85
- utcOffset?: number;
86
- /**
87
- * - Combine day-of-month and day-of-week using true = OR, false = AND. Default is true = OR.
88
- */
89
- legacyMode?: boolean;
90
- /**
91
- * - Used to pass any object to scheduled function
92
- */
93
- context?: unknown;
94
- };
95
- /**
96
- * Name for each part of the cron pattern
97
- */
98
- export type CronPatternPart = ("second" | "minute" | "hour" | "day" | "month" | "dayOfWeek");
99
- /**
100
- * Offset, 0 or -1.
101
- *
102
- * 0 offset is used for seconds,minutes and hours as they start on 1.
103
- * -1 on days and months, as they start on 0
104
- */
105
- export type CronIndexOffset = number;
106
- /**
107
- * Cron entrypoint
108
- *
109
- * @constructor
110
- * @param {string|Date} pattern - Input pattern, input date, or input ISO 8601 time string
111
- * @param {CronOptions|Function} [fnOrOptions1] - Options or function to be run each iteration of pattern
112
- * @param {CronOptions|Function} [fnOrOptions2] - Options or function to be run each iteration of pattern
113
- * @returns {Cron}
114
- */
115
- export function Cron(pattern: string | Date, fnOrOptions1?: CronOptions | Function, fnOrOptions2?: CronOptions | Function): Cron;
116
- export class Cron {
117
- /**
118
- * Cron entrypoint
119
- *
120
- * @constructor
121
- * @param {string|Date} pattern - Input pattern, input date, or input ISO 8601 time string
122
- * @param {CronOptions|Function} [fnOrOptions1] - Options or function to be run each iteration of pattern
123
- * @param {CronOptions|Function} [fnOrOptions2] - Options or function to be run each iteration of pattern
124
- * @returns {Cron}
125
- */
126
- constructor(pattern: string | Date, fnOrOptions1?: CronOptions | Function, fnOrOptions2?: CronOptions | Function);
127
- /**
128
- * @public
129
- * @type {string|undefined} */
130
- public name: string | undefined;
131
- /**
132
- * @public
133
- * @type {CronOptions} */
134
- public options: CronOptions;
135
- /**
136
- * Encapsulate all internal states in an object.
137
- * Duplicate all options that can change to internal states, for example maxRuns and paused.
138
- * @private
139
- */
140
- private _states;
141
- fn: Function | CronOptions;
142
- /**
143
- * Find next runtime, based on supplied date. Strips milliseconds.
144
- *
145
- * @param {CronDate|Date|string} [prev] - Date to start from
146
- * @returns {Date | null} - Next run time
147
- */
148
- nextRun(prev?: CronDate | Date | string): Date | null;
149
- /**
150
- * Find next n runs, based on supplied date. Strips milliseconds.
151
- *
152
- * @param {number} n - Number of runs to enumerate
153
- * @param {Date|string} [previous] - Date to start from
154
- * @returns {Date[]} - Next n run times
155
- */
156
- nextRuns(n: number, previous?: Date | string): Date[];
157
- /**
158
- * Return the original pattern, if there was one
159
- *
160
- * @returns {string|undefined} - Original pattern
161
- */
162
- getPattern(): string | undefined;
163
- /**
164
- * Indicates whether or not the cron job is scheduled and running, e.g. awaiting next trigger
165
- * @public
166
- *
167
- * @returns {boolean} - Running or not
168
- */
169
- public isRunning(): boolean;
170
- /**
171
- * Indicates whether or not the cron job is permanently stopped
172
- * @public
173
- *
174
- * @returns {boolean} - Running or not
175
- */
176
- public isStopped(): boolean;
177
- /**
178
- * Indicates whether or not the cron job is currently working
179
- * @public
180
- *
181
- * @returns {boolean} - Running or not
182
- */
183
- public isBusy(): boolean;
184
- /**
185
- * Return current/previous run start time
186
- * @public
187
- *
188
- * @returns {Date | null} - Previous run time
189
- */
190
- public currentRun(): Date | null;
191
- /**
192
- * Return previous run start time
193
- * @public
194
- *
195
- * @returns {Date | null} - Previous run time
196
- */
197
- public previousRun(): Date | null;
198
- /**
199
- * Returns number of milliseconds to next run
200
- * @public
201
- *
202
- * @param {CronDate|Date|string} [prev] - Starting date, defaults to now - minimum interval
203
- * @returns {number | null}
204
- */
205
- public msToNext(prev?: CronDate | Date | string): number | null;
206
- /**
207
- * Stop execution
208
- *
209
- * Running this will forcefully stop the job, and prevent furter exection. `.resume()` will not work after stopping.
210
- * It will also be removed from the scheduledJobs array if it were named.
211
- *
212
- * @public
213
- */
214
- public stop(): void;
215
- /**
216
- * Pause execution
217
- * @public
218
- *
219
- * @returns {boolean} - Wether pause was successful
220
- */
221
- public pause(): boolean;
222
- /**
223
- * Resume execution
224
- * @public
225
- *
226
- * @returns {boolean} - Wether resume was successful
227
- */
228
- public resume(): boolean;
229
- /**
230
- * Schedule a new job
231
- * @public
232
- *
233
- * @param {Function} func - Function to be run each iteration of pattern
234
- * @returns {Cron}
235
- */
236
- public schedule(func: Function): Cron;
237
- private _trigger;
238
- /**
239
- * Trigger a run manually
240
- * @public
241
- */
242
- public trigger(): Promise<void>;
243
- private _checkTrigger;
244
- private _next;
245
- private _calculatePreviousRun;
246
- }
247
- export namespace Cron {
248
- export { Cron };
249
- export { scheduledJobs };
250
- }
251
- /**
252
- * An array containing all named cron jobs.
253
- *
254
- * @constant
255
- * @type {Cron[]}
256
- */
257
- export const scheduledJobs: Cron[];
258
- /**
259
- * Converts date to CronDate
260
- * @constructor
261
- *
262
- * @param {CronDate|Date|string} [d] - Input date, if using string representation ISO 8001 (2015-11-24T19:40:00) local timezone is expected
263
- * @param {string|number} [tz] - String representation of target timezone in Europe/Stockholm format, or a number representing offset in minutes.
264
- */
265
- declare function CronDate(d?: CronDate | Date | string, tz?: string | number): void;
266
- declare class CronDate {
267
- /**
268
- * Converts date to CronDate
269
- * @constructor
270
- *
271
- * @param {CronDate|Date|string} [d] - Input date, if using string representation ISO 8001 (2015-11-24T19:40:00) local timezone is expected
272
- * @param {string|number} [tz] - String representation of target timezone in Europe/Stockholm format, or a number representing offset in minutes.
273
- */
274
- constructor(d?: CronDate | Date | string, tz?: string | number);
275
- /**
276
- * TimeZone
277
- * @type {string|number|undefined}
278
- */
279
- tz: string | number | undefined;
280
- private isNthWeekdayOfMonth;
281
- private fromDate;
282
- ms: number;
283
- second: number;
284
- minute: number;
285
- hour: number;
286
- day: number;
287
- month: number;
288
- year: number;
289
- private fromCronDate;
290
- private apply;
291
- private fromString;
292
- private findNext;
293
- private recurse;
294
- /**
295
- * Increment to next run time
296
- * @public
297
- *
298
- * @param {string} pattern - The pattern used to increment current state
299
- * @param {CronOptions} options - Cron options used for incrementing
300
- * @param {boolean} [hasPreviousRun] - If this run should adhere to minimum interval
301
- * @return {CronDate|null} - Returns itthis for chaining, or null if increment wasnt possible
302
- */
303
- public increment(pattern: string, options: CronOptions, hasPreviousRun?: boolean): CronDate | null;
304
- /**
305
- * Convert current state back to a javascript Date()
306
- * @public
307
- *
308
- * @param {boolean} internal - If this is an internal call
309
- * @returns {Date}
310
- */
311
- public getDate(internal: boolean): Date;
312
- /**
313
- * Convert current state back to a javascript Date() and return UTC milliseconds
314
- * @public
315
- *
316
- * @returns {Date}
317
- */
318
- public getTime(): Date;
319
- }
320
- export { Cron as default };