cron 3.1.0 → 3.1.2
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/CHANGELOG.md +35 -0
- package/README.md +4 -2
- package/dist/job.d.ts +3 -3
- package/dist/job.js +1 -1
- package/dist/time.d.ts +2 -2
- package/dist/types/cron.types.d.ts +6 -6
- package/package.json +18 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
## [3.1.2](https://github.com/kelektiv/node-cron/compare/v3.1.1...v3.1.2) (2023-10-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🛠 Builds
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency luxon to ~3.4.0 ([#730](https://github.com/kelektiv/node-cron/issues/730)) ([c3806c5](https://github.com/kelektiv/node-cron/commit/c3806c54574d2f1886272f0b6fc0742b84dcba03))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### ♻️ Chores
|
|
10
|
+
|
|
11
|
+
* **deps:** lock file maintenance ([#731](https://github.com/kelektiv/node-cron/issues/731)) ([b6bc715](https://github.com/kelektiv/node-cron/commit/b6bc715e20f48550b4265b90bd5a21b635ece14c))
|
|
12
|
+
* **deps:** pin dependencies ([#719](https://github.com/kelektiv/node-cron/issues/719)) [skip ci] ([5003745](https://github.com/kelektiv/node-cron/commit/5003745208f2312bfc41dd88b68520c00d72cf5c))
|
|
13
|
+
* **deps:** pin dependencies ([#720](https://github.com/kelektiv/node-cron/issues/720)) [skip ci] ([4f977ef](https://github.com/kelektiv/node-cron/commit/4f977efb245d0c8a4113ef979e92c90c4ce6b0ee))
|
|
14
|
+
* **deps:** pin dependencies ([#721](https://github.com/kelektiv/node-cron/issues/721)) [skip ci] ([60fbf7f](https://github.com/kelektiv/node-cron/commit/60fbf7fa9f34cb1a214673eb556aa62eab3b848b))
|
|
15
|
+
* **deps:** update dependency [@commitlint](https://github.com/commitlint)/cli to v17.8.0 ([#723](https://github.com/kelektiv/node-cron/issues/723)) [skip ci] ([a7a18cb](https://github.com/kelektiv/node-cron/commit/a7a18cbd8d550214377ff5c8d77f29952d2b91c7))
|
|
16
|
+
* **deps:** update dependency [@types](https://github.com/types)/node to v20.8.6 ([#724](https://github.com/kelektiv/node-cron/issues/724)) [skip ci] ([b5e4c9f](https://github.com/kelektiv/node-cron/commit/b5e4c9f463543f6d1ba2bc9eebbd5eb6f3d1b5ea))
|
|
17
|
+
* **deps:** update dependency sinon to v16 ([#726](https://github.com/kelektiv/node-cron/issues/726)) [skip ci] ([d114a12](https://github.com/kelektiv/node-cron/commit/d114a1291d4257a899150468e4736c594b542355))
|
|
18
|
+
* **deps:** update dependency typescript to v5.2.2 ([#729](https://github.com/kelektiv/node-cron/issues/729)) [skip ci] ([d1b267e](https://github.com/kelektiv/node-cron/commit/d1b267e6490347786e9aa77be6a1016598b968ea))
|
|
19
|
+
* **deps:** update linters ([#728](https://github.com/kelektiv/node-cron/issues/728)) [skip ci] ([9ab00e8](https://github.com/kelektiv/node-cron/commit/9ab00e8e2adac547017bfbe5b6d97d7bc9c6fb28))
|
|
20
|
+
* **deps:** update linters (major) ([#727](https://github.com/kelektiv/node-cron/issues/727)) [skip ci] ([a75418a](https://github.com/kelektiv/node-cron/commit/a75418aca0f51b98625979087aa86e166ac17c56))
|
|
21
|
+
* **deps:** update tests ([#722](https://github.com/kelektiv/node-cron/issues/722)) [skip ci] ([6b4c6fa](https://github.com/kelektiv/node-cron/commit/6b4c6fae750d005c3e30f12b868e4f01a3b99a68))
|
|
22
|
+
|
|
23
|
+
## [3.1.1](https://github.com/kelektiv/node-cron/compare/v3.1.0...v3.1.1) (2023-10-12)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### 🐛 Bug Fixes
|
|
27
|
+
|
|
28
|
+
* fix lastDate() value for intervals > 25 days ([#711](https://github.com/kelektiv/node-cron/issues/711)) ([141aa00](https://github.com/kelektiv/node-cron/commit/141aa00f55fa105d89df7e257d82c94ad2bb2b3a))
|
|
29
|
+
* fix object constructor typings & make OC generic type optional ([#712](https://github.com/kelektiv/node-cron/issues/712)) ([6536084](https://github.com/kelektiv/node-cron/commit/653608451caecd51f50884d83563c03c6c27bc54))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### 📚 Documentation
|
|
33
|
+
|
|
34
|
+
* **readme:** update nextDates documentation ([#702](https://github.com/kelektiv/node-cron/issues/702)) ([1ad2e22](https://github.com/kelektiv/node-cron/commit/1ad2e228f75bcaab3eb97a27665c06b7892678c5))
|
|
35
|
+
|
|
1
36
|
## [3.1.0](https://github.com/kelektiv/node-cron/compare/v3.0.0...v3.1.0) (2023-10-09)
|
|
2
37
|
|
|
3
38
|
|
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ For day-of-week indexing, we only added support for `7` as Sunday, so you don't
|
|
|
44
44
|
|
|
45
45
|
- **constructor no longer accepts an object as its first and only params. Use `CronJob.from(argsObject)` instead.**
|
|
46
46
|
- **callbacks are now called in the order they were registered.**
|
|
47
|
+
- **`nextDates(count?: number)` now always returns an array (empty if no argument is provided). Use `nextDate()` instead for a single date.**
|
|
47
48
|
|
|
48
49
|
### Removed methods
|
|
49
50
|
|
|
@@ -118,7 +119,7 @@ Parameter Based
|
|
|
118
119
|
- `constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout)`
|
|
119
120
|
- `cronTime` - [REQUIRED] - The time to fire off your job. This can be in the form of cron syntax or a JS [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.
|
|
120
121
|
- `onTick` - [REQUIRED] - The function to fire at the specified time. If an `onComplete` callback was provided, `onTick` will receive it as an argument. `onTick` may call `onComplete` when it has finished its work.
|
|
121
|
-
- `onComplete` - [OPTIONAL] - A function that will fire when the job is stopped with `job.stop()`, and may also be called by `onTick` at the end of each run.
|
|
122
|
+
- `onComplete` - [OPTIONAL] - A function that will fire when the job is stopped with `job.stop()`, and may also be called by `onTick` at the end of each run. **Note for TS users**: This should either be an arrow function, or a regular function cast to `() => void` (bug with generic type inference).
|
|
122
123
|
- `start` - [OPTIONAL] - Specifies whether to start the job just before exiting the constructor. By default this is set to false. If left at default you will need to call `job.start()` in order to start the job (assuming `job` is the variable you set the cronjob to). This does not immediately fire your `onTick` function, it just gives you more control over the behavior of your jobs.
|
|
123
124
|
- `timeZone` - [OPTIONAL] - Specify the time zone for the execution. This will modify the actual time relative to your time zone. If the time zone is invalid, an error is thrown. By default (if this is omitted) the local time zone will be used. You can check the various time zones format accepted in the [Luxon documentation](https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone). Note: This parameter supports minutes offsets, e.g. `UTC+5:30`. **Note**: Cannot be used together with `utcOffset`.
|
|
124
125
|
- `context` - [OPTIONAL] - The context within which to execute the onTick method. This defaults to the cronjob itself allowing you to call `this.stop()`. However, if you change this you'll have access to the functions and values within your context object.
|
|
@@ -131,7 +132,8 @@ Parameter Based
|
|
|
131
132
|
- `setTime` - Stops and changes the time for the `CronJob`. Param must be a `CronTime`.
|
|
132
133
|
- `lastDate` - Tells you the last execution date.
|
|
133
134
|
- `nextDate` - Provides the next date that will trigger an `onTick`.
|
|
134
|
-
- `nextDates` - Provides an array of the next set of dates that will trigger an `onTick`.
|
|
135
|
+
- `nextDates(count)` - Provides an array of the next set of dates that will trigger an `onTick`.
|
|
136
|
+
- `count` - [OPTIONAL] - The number of next dates to return. Defaults to 0, returning an empty array.
|
|
135
137
|
- `fireOnTick` - Allows you to override the `onTick` calling behavior. This matters so only do this if you have a really good reason to do so.
|
|
136
138
|
- `addCallback` - Allows you to add `onTick` callbacks. Callbacks are run in the order they are registered.
|
|
137
139
|
- `CronTime`
|
package/dist/job.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { CronTime } from './time';
|
|
2
2
|
import { CronCallback, CronContext, CronJobParams, CronOnCompleteCallback, CronOnCompleteCommand, WithOnComplete } from './types/cron.types';
|
|
3
|
-
export declare class CronJob<OC extends CronOnCompleteCommand
|
|
3
|
+
export declare class CronJob<OC extends CronOnCompleteCommand | null = null, C = null> {
|
|
4
4
|
cronTime: CronTime;
|
|
5
5
|
running: boolean;
|
|
6
6
|
unrefTimeout: boolean;
|
|
7
7
|
lastExecution: Date | null;
|
|
8
8
|
runOnce: boolean;
|
|
9
9
|
context: CronContext<C>;
|
|
10
|
-
onComplete?: WithOnComplete<OC> extends true ? CronOnCompleteCallback
|
|
10
|
+
onComplete?: WithOnComplete<OC> extends true ? CronOnCompleteCallback : undefined;
|
|
11
11
|
private _timeout?;
|
|
12
12
|
private _callbacks;
|
|
13
13
|
constructor(cronTime: CronJobParams<OC, C>['cronTime'], onTick: CronJobParams<OC, C>['onTick'], onComplete?: CronJobParams<OC, C>['onComplete'], start?: CronJobParams<OC, C>['start'], timeZone?: CronJobParams<OC, C>['timeZone'], context?: CronJobParams<OC, C>['context'], runOnInit?: CronJobParams<OC, C>['runOnInit'], utcOffset?: null, unrefTimeout?: CronJobParams<OC, C>['unrefTimeout']);
|
|
14
14
|
constructor(cronTime: CronJobParams<OC, C>['cronTime'], onTick: CronJobParams<OC, C>['onTick'], onComplete?: CronJobParams<OC, C>['onComplete'], start?: CronJobParams<OC, C>['start'], timeZone?: null, context?: CronJobParams<OC, C>['context'], runOnInit?: CronJobParams<OC, C>['runOnInit'], utcOffset?: CronJobParams<OC, C>['utcOffset'], unrefTimeout?: CronJobParams<OC, C>['unrefTimeout']);
|
|
15
|
-
static from<
|
|
15
|
+
static from<OC extends CronOnCompleteCommand | null = null, C = null>(params: CronJobParams<OC, C>): CronJob<OC, C>;
|
|
16
16
|
private _fnWrap;
|
|
17
17
|
addCallback(callback: CronCallback<C, WithOnComplete<OC>>): void;
|
|
18
18
|
setTime(time: CronTime): void;
|
package/dist/job.js
CHANGED
|
@@ -120,7 +120,6 @@ class CronJob {
|
|
|
120
120
|
}
|
|
121
121
|
remaining += newTimeout;
|
|
122
122
|
}
|
|
123
|
-
this.lastExecution = new Date();
|
|
124
123
|
if (remaining) {
|
|
125
124
|
if (remaining > MAXDELAY) {
|
|
126
125
|
remaining -= MAXDELAY;
|
|
@@ -133,6 +132,7 @@ class CronJob {
|
|
|
133
132
|
setCronTimeout(timeout);
|
|
134
133
|
}
|
|
135
134
|
else {
|
|
135
|
+
this.lastExecution = new Date();
|
|
136
136
|
this.running = false;
|
|
137
137
|
if (!this.runOnce) {
|
|
138
138
|
this.start();
|
package/dist/time.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export declare class CronTime {
|
|
|
11
11
|
private dayOfMonth;
|
|
12
12
|
private month;
|
|
13
13
|
private dayOfWeek;
|
|
14
|
-
constructor(source: CronJobParams
|
|
15
|
-
constructor(source: CronJobParams
|
|
14
|
+
constructor(source: CronJobParams['cronTime'], timeZone?: CronJobParams['timeZone'], utcOffset?: null);
|
|
15
|
+
constructor(source: CronJobParams['cronTime'], timeZone?: null, utcOffset?: CronJobParams['utcOffset']);
|
|
16
16
|
private _getWeekDay;
|
|
17
17
|
private _verifyParse;
|
|
18
18
|
sendAt(): DateTime;
|
|
@@ -4,7 +4,7 @@ import { DateTime } from 'luxon';
|
|
|
4
4
|
import { CONSTRAINTS, TIME_UNITS_MAP } from '../constants';
|
|
5
5
|
import { CronJob } from '../job';
|
|
6
6
|
import { IntRange } from './utils';
|
|
7
|
-
interface BaseCronJobParams<OC extends CronOnCompleteCommand
|
|
7
|
+
interface BaseCronJobParams<OC extends CronOnCompleteCommand | null = null, C = null> {
|
|
8
8
|
cronTime: string | Date | DateTime;
|
|
9
9
|
onTick: CronCommand<C, WithOnComplete<OC>>;
|
|
10
10
|
onComplete?: OC;
|
|
@@ -13,23 +13,23 @@ interface BaseCronJobParams<OC extends CronOnCompleteCommand<C> | null, C = null
|
|
|
13
13
|
runOnInit?: boolean | null;
|
|
14
14
|
unrefTimeout?: boolean | null;
|
|
15
15
|
}
|
|
16
|
-
export type CronJobParams<OC extends CronOnCompleteCommand
|
|
16
|
+
export type CronJobParams<OC extends CronOnCompleteCommand | null = null, C = null> = BaseCronJobParams<OC, C> & ({
|
|
17
17
|
timeZone?: string | null;
|
|
18
18
|
utcOffset?: never;
|
|
19
19
|
} | {
|
|
20
20
|
timeZone?: never;
|
|
21
21
|
utcOffset?: number | null;
|
|
22
22
|
});
|
|
23
|
-
export type CronContext<C> = C extends null ? CronJob
|
|
24
|
-
export type CronCallback<C, WithOnCompleteBool extends boolean = false> = (this: CronContext<C>, onComplete: WithOnCompleteBool extends true ?
|
|
25
|
-
export type CronOnCompleteCallback
|
|
23
|
+
export type CronContext<C> = C extends null ? CronJob : NonNullable<C>;
|
|
24
|
+
export type CronCallback<C, WithOnCompleteBool extends boolean = false> = (this: CronContext<C>, onComplete: WithOnCompleteBool extends true ? CronOnCompleteCallback : never) => void;
|
|
25
|
+
export type CronOnCompleteCallback = () => void;
|
|
26
26
|
export type CronSystemCommand = string | {
|
|
27
27
|
command: string;
|
|
28
28
|
args?: readonly string[] | null;
|
|
29
29
|
options?: SpawnOptions | null;
|
|
30
30
|
};
|
|
31
31
|
export type CronCommand<C, WithOnCompleteBool extends boolean = false> = CronCallback<C, WithOnCompleteBool> | CronSystemCommand;
|
|
32
|
-
export type CronOnCompleteCommand
|
|
32
|
+
export type CronOnCompleteCommand = CronOnCompleteCallback | CronSystemCommand;
|
|
33
33
|
export type WithOnComplete<OC> = OC extends null ? false : true;
|
|
34
34
|
export type TimeUnit = (typeof TIME_UNITS_MAP)[keyof typeof TIME_UNITS_MAP];
|
|
35
35
|
export type TimeUnitField<T extends TimeUnit> = Partial<Record<Ranges[T], boolean>>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cron",
|
|
3
3
|
"description": "Cron jobs for your node",
|
|
4
|
-
"version": "3.1.
|
|
4
|
+
"version": "3.1.2",
|
|
5
5
|
"author": "Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/kelektiv/node-cron/issues"
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@types/luxon": "~3.3.0",
|
|
27
|
-
"luxon": "~3.
|
|
27
|
+
"luxon": "~3.4.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@commitlint/cli": "17.
|
|
30
|
+
"@commitlint/cli": "17.8.0",
|
|
31
31
|
"@insurgentlab/commitlint-config": "18.1.3",
|
|
32
32
|
"@insurgentlab/conventional-changelog-preset": "7.0.0",
|
|
33
33
|
"@semantic-release/changelog": "6.0.3",
|
|
@@ -36,22 +36,22 @@
|
|
|
36
36
|
"@semantic-release/github": "9.2.1",
|
|
37
37
|
"@semantic-release/npm": "11.0.0",
|
|
38
38
|
"@semantic-release/release-notes-generator": "12.0.0",
|
|
39
|
-
"@types/jest": "
|
|
40
|
-
"@types/node": "
|
|
41
|
-
"@types/sinon": "
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "
|
|
43
|
-
"chai": "
|
|
44
|
-
"eslint": "
|
|
45
|
-
"eslint-config-prettier": "
|
|
46
|
-
"eslint-plugin-jest": "
|
|
47
|
-
"eslint-plugin-prettier": "
|
|
48
|
-
"husky": "
|
|
49
|
-
"jest": "
|
|
50
|
-
"prettier": "
|
|
39
|
+
"@types/jest": "29.5.5",
|
|
40
|
+
"@types/node": "20.8.6",
|
|
41
|
+
"@types/sinon": "10.0.19",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "6.7.5",
|
|
43
|
+
"chai": "4.3.10",
|
|
44
|
+
"eslint": "8.51.0",
|
|
45
|
+
"eslint-config-prettier": "9.0.0",
|
|
46
|
+
"eslint-plugin-jest": "27.4.2",
|
|
47
|
+
"eslint-plugin-prettier": "5.0.1",
|
|
48
|
+
"husky": "8.0.3",
|
|
49
|
+
"jest": "29.7.0",
|
|
50
|
+
"prettier": "3.0.3",
|
|
51
51
|
"semantic-release": "22.0.5",
|
|
52
|
-
"sinon": "
|
|
53
|
-
"ts-jest": "
|
|
54
|
-
"typescript": "
|
|
52
|
+
"sinon": "16.1.0",
|
|
53
|
+
"ts-jest": "29.1.1",
|
|
54
|
+
"typescript": "5.2.2"
|
|
55
55
|
},
|
|
56
56
|
"keywords": [
|
|
57
57
|
"cron",
|