cron 3.0.0-beta.2 → 3.0.0-beta.4

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 CHANGED
@@ -1,30 +1,62 @@
1
- ## [3.0.0-beta.2](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2023-08-15)
1
+ ## [3.0.0-beta.4](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2023-09-10)
2
2
 
3
3
 
4
4
  ### 🐛 Bug Fixes
5
5
 
6
- * replace loop timeout by max match date ([#686](https://github.com/kelektiv/node-cron/issues/686)) ([c685c63](https://github.com/kelektiv/node-cron/commit/c685c63a6d7fa86d6c8afca29b536b9da24e824b))
6
+ * **deps:** update dependency luxon to v3.3.0 & add [@types](https://github.com/types)/luxon ([#689](https://github.com/kelektiv/node-cron/issues/689)) ([c95a449](https://github.com/kelektiv/node-cron/commit/c95a449121e440b82d391fc11f8dc148748f93ec)), closes [#688](https://github.com/kelektiv/node-cron/issues/688)
7
+ * fix range parsing when upper limit = 0 ([#687](https://github.com/kelektiv/node-cron/issues/687)) ([d96746f](https://github.com/kelektiv/node-cron/commit/d96746f7b8f357e565d1fad48c9f70d3d646da64))
7
8
 
8
9
 
9
10
  ### 🚨 Tests
10
11
 
11
- * update new test for cron standard alignments ([ea56fc1](https://github.com/kelektiv/node-cron/commit/ea56fc1c32905d711b160823fc09f39169dd3efd))
12
+ * add TS types check ([#690](https://github.com/kelektiv/node-cron/issues/690)) ([f046016](https://github.com/kelektiv/node-cron/commit/f046016dc64438c4a12a4615a919b046d3a846de))
12
13
 
14
+ ## [2.4.3](https://github.com/kelektiv/node-cron/compare/v2.4.2...v2.4.3) (2023-08-26)
13
15
 
14
- ### ⚙️ Continuous Integrations
15
16
 
16
- * **renovate:** configure renovate ([#683](https://github.com/kelektiv/node-cron/issues/683)) ([9dbe962](https://github.com/kelektiv/node-cron/commit/9dbe962fad1c8b1b020441bce84ab91b1a7b4415))
17
+ ### 🐛 Bug Fixes
17
18
 
18
- ## [3.0.0-beta.1](https://github.com/kelektiv/node-cron/compare/v2.3.1...v3.0.0-beta.1) (2023-07-23)
19
+ * fix range parsing when upper limit = 0 ([#687](https://github.com/kelektiv/node-cron/issues/687)) ([d96746f](https://github.com/kelektiv/node-cron/commit/d96746f7b8f357e565d1fad48c9f70d3d646da64))
20
+
21
+
22
+ ### 🚨 Tests
23
+
24
+ * add TS types check ([#690](https://github.com/kelektiv/node-cron/issues/690)) ([f046016](https://github.com/kelektiv/node-cron/commit/f046016dc64438c4a12a4615a919b046d3a846de))
25
+
26
+ ## [2.4.2](https://github.com/kelektiv/node-cron/compare/v2.4.1...v2.4.2) (2023-08-26)
27
+
28
+
29
+ ### 🐛 Bug Fixes
30
+
31
+ * **deps:** update dependency luxon to v3.3.0 & add [@types](https://github.com/types)/luxon ([#689](https://github.com/kelektiv/node-cron/issues/689)) ([c95a449](https://github.com/kelektiv/node-cron/commit/c95a449121e440b82d391fc11f8dc148748f93ec)), closes [#688](https://github.com/kelektiv/node-cron/issues/688)
32
+
33
+ ## [3.0.0-beta.3](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2023-08-15)
19
34
 
20
35
 
21
36
  ### ⚠ Breaking changes
22
37
 
23
- * UNIX standard alignments (#667)
38
+ * return empty array from nextDates when called without argument (#519)
24
39
 
25
- ### ✨ Features
40
+ ### 🐛 Bug Fixes
41
+
42
+ * return empty array from nextDates when called without argument ([#519](https://github.com/kelektiv/node-cron/issues/519)) ([e65c3dc](https://github.com/kelektiv/node-cron/commit/e65c3dc6c334b8d4df0da317b75494d78cd5d52b))
43
+
44
+ ## [3.0.0-beta.2](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2023-08-15)
26
45
 
27
- * UNIX standard alignments ([#667](https://github.com/kelektiv/node-cron/issues/667)) ([96ef954](https://github.com/kelektiv/node-cron/commit/96ef954998f9c109cc2a969296568b1b56bbbd79))
46
+
47
+ ### 🐛 Bug Fixes
48
+
49
+ * replace loop timeout by max match date ([#686](https://github.com/kelektiv/node-cron/issues/686)) ([c685c63](https://github.com/kelektiv/node-cron/commit/c685c63a6d7fa86d6c8afca29b536b9da24e824b))
50
+
51
+
52
+ ### 🚨 Tests
53
+
54
+ * update new test for cron standard alignments ([ea56fc1](https://github.com/kelektiv/node-cron/commit/ea56fc1c32905d711b160823fc09f39169dd3efd))
55
+
56
+
57
+ ### ⚙️ Continuous Integrations
58
+
59
+ * **renovate:** configure renovate ([#683](https://github.com/kelektiv/node-cron/issues/683)) ([9dbe962](https://github.com/kelektiv/node-cron/commit/9dbe962fad1c8b1b020441bce84ab91b1a7b4415))
28
60
 
29
61
  ## [2.4.1](https://github.com/kelektiv/node-cron/compare/v2.4.0...v2.4.1) (2023-08-14)
30
62
 
@@ -73,6 +105,17 @@
73
105
  * update default branch name ([#678](https://github.com/kelektiv/node-cron/issues/678)) ([7471e95](https://github.com/kelektiv/node-cron/commit/7471e95cb7433b4f29cfa68da0a652ec8cf630b6))
74
106
  * wrap setTime tests in describe and move down ([31989e0](https://github.com/kelektiv/node-cron/commit/31989e06f939bf1e9dbc6c0b6fc62c0a7144b9eb))
75
107
 
108
+ ## [3.0.0-beta.1](https://github.com/kelektiv/node-cron/compare/v2.3.1...v3.0.0-beta.1) (2023-07-23)
109
+
110
+
111
+ ### ⚠ Breaking changes
112
+
113
+ * UNIX standard alignments (#667)
114
+
115
+ ### ✨ Features
116
+
117
+ * UNIX standard alignments ([#667](https://github.com/kelektiv/node-cron/issues/667)) ([96ef954](https://github.com/kelektiv/node-cron/commit/96ef954998f9c109cc2a969296568b1b56bbbd79))
118
+
76
119
  ## [v2.3.1](https://github.com/kelektiv/node-cron/compare/v2.3.0...v2.3.1) (2023-05-25)
77
120
 
78
121
  ### Added
package/README.md CHANGED
@@ -52,7 +52,7 @@ As goes with semver, breaking backwards compatibility should be explicit in the
52
52
  var CronJob = require('cron').CronJob;
53
53
  var job = new CronJob(
54
54
  '* * * * * *',
55
- function() {
55
+ function () {
56
56
  console.log('You will see this message every second');
57
57
  },
58
58
  null,
@@ -125,6 +125,7 @@ Parameter Based
125
125
  - `stop` - Stops your job.
126
126
  - `setTime` - Stops and changes the time for the `CronJob`. Param must be a `CronTime`.
127
127
  - `lastDate` - Tells you the last execution date.
128
+ - `nextDate` - Provides the next date that will trigger an `onTick`.
128
129
  - `nextDates` - Provides an array of the next set of dates that will trigger an `onTick`.
129
130
  - `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.
130
131
  - `addCallback` - Allows you to add `onTick` callbacks.
package/lib/job.js CHANGED
@@ -106,7 +106,7 @@ function CronJob(CronTime, spawn) {
106
106
  CJ.prototype.fireOnTick = fireOnTick;
107
107
 
108
108
  CJ.prototype.nextDates = function (i) {
109
- return this.cronTime.sendAt(i);
109
+ return this.cronTime.sendAt(i || 0);
110
110
  };
111
111
 
112
112
  const start = function () {
package/lib/time.js CHANGED
@@ -774,7 +774,7 @@ function CronTime(luxon) {
774
774
  if (allRanges[i].match(RE_RANGE)) {
775
775
  allRanges[i].replace(RE_RANGE, ($0, lower, upper, step) => {
776
776
  lower = parseInt(lower, 10);
777
- upper = parseInt(upper, 10) || undefined;
777
+ upper = upper !== undefined ? parseInt(upper, 10) : undefined;
778
778
 
779
779
  const wasStepDefined = !isNaN(parseInt(step, 10));
780
780
  if (step === '0') {
@@ -782,14 +782,14 @@ function CronTime(luxon) {
782
782
  }
783
783
  step = parseInt(step, 10) || 1;
784
784
 
785
- if (upper && lower > upper) {
785
+ if (upper !== undefined && lower > upper) {
786
786
  throw new Error(`Field (${type}) has an invalid range`);
787
787
  }
788
788
 
789
789
  const outOfRangeError =
790
790
  lower < low ||
791
- (upper && upper > high) ||
792
- (!upper && lower > high);
791
+ (upper !== undefined && upper > high) ||
792
+ (upper === undefined && lower > high);
793
793
 
794
794
  if (outOfRangeError) {
795
795
  throw new Error(`Field value (${value}) is out of range`);
@@ -799,7 +799,7 @@ function CronTime(luxon) {
799
799
  lower = Math.min(Math.max(low, ~~Math.abs(lower)), high);
800
800
 
801
801
  // Positive integer lower than constraints[1]
802
- if (upper) {
802
+ if (upper !== undefined) {
803
803
  upper = Math.min(high, ~~Math.abs(upper));
804
804
  } else {
805
805
  // If step is provided, the default upper range is the highest value
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.0.0-beta.2",
4
+ "version": "3.0.0-beta.4",
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"
@@ -15,12 +15,14 @@
15
15
  "lint": "eslint {lib,tests}/*.js",
16
16
  "test": "jest --coverage",
17
17
  "test:watch": "jest --watch --coverage",
18
+ "test:types": "tsd",
18
19
  "prepare": "husky install",
19
20
  "release": "semantic-release"
20
21
  },
21
22
  "types": "types/index.d.ts",
22
23
  "dependencies": {
23
- "luxon": "^3.2.1"
24
+ "@types/luxon": "~3.3.0",
25
+ "luxon": "~3.3.0"
24
26
  },
25
27
  "devDependencies": {
26
28
  "@commitlint/cli": "~17.6.6",
@@ -45,7 +47,8 @@
45
47
  "jest": "~29.5.x",
46
48
  "prettier": "~2.8.x",
47
49
  "semantic-release": "~21.0.x",
48
- "sinon": "^15.0.x"
50
+ "sinon": "^15.0.x",
51
+ "tsd": "^0.28.1"
49
52
  },
50
53
  "keywords": [
51
54
  "cron",
@@ -0,0 +1,85 @@
1
+ import * as luxon from 'luxon';
2
+ import { expectType } from 'tsd';
3
+ import * as cron from '..';
4
+
5
+ const CronJob = cron.CronJob;
6
+ const CronTime = cron.CronTime;
7
+
8
+ const DateTime = luxon.DateTime;
9
+
10
+ const timeZone = 'America/Los_Angeles';
11
+
12
+ // basic cron usage
13
+ const job = new CronJob(
14
+ '* * * * * *',
15
+ () => {},
16
+ null,
17
+ true
18
+ );
19
+
20
+ // using factory function with parameters object
21
+ expectType<cron.CronJob>(cron.job({
22
+ cronTime: '00 30 11 * * 1-5',
23
+ onTick: () => {},
24
+ start: false,
25
+ timeZone: 'America/Los_Angeles'
26
+ }));
27
+
28
+ // with timezone
29
+ new CronJob(
30
+ '* * * * * *',
31
+ () => {},
32
+ null,
33
+ true,
34
+ timeZone
35
+ );
36
+
37
+ // with onComplete
38
+ new CronJob(
39
+ '00 30 11 * * 1-5',
40
+ () => {},
41
+ () => {},
42
+ true,
43
+ timeZone
44
+ );
45
+
46
+ // with Date
47
+ new CronJob(
48
+ new Date(),
49
+ () => {},
50
+ null,
51
+ true,
52
+ timeZone
53
+ );
54
+
55
+ // with Luxon DateTime
56
+ new CronJob(
57
+ DateTime.local(),
58
+ () => {},
59
+ null,
60
+ true,
61
+ timeZone
62
+ );
63
+
64
+ // with system commands
65
+ new CronJob(
66
+ '00 30 11 * * 1-5',
67
+ 'ls',
68
+ { command: 'ls', args: ['./'] },
69
+ true,
70
+ timeZone
71
+ );
72
+
73
+ // check function return types
74
+ expectType<Date>(job.lastDate());
75
+ expectType<luxon.DateTime>(job.nextDates());
76
+ expectType<luxon.DateTime | luxon.DateTime[]>(job.nextDates(1));
77
+ expectType<boolean | undefined>(job.running);
78
+ job.setTime(new CronTime('00 30 11 * * 1-2'));
79
+ job.start();
80
+ job.stop();
81
+
82
+ // check cronTime format
83
+ new CronTime('* * * * * *');
84
+ new CronTime(new Date());
85
+ new CronTime(DateTime.local());