cron 3.0.0 → 3.1.0
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 +18 -0
- package/dist/index.d.ts +1 -1
- package/dist/job.d.ts +8 -8
- package/dist/job.js +3 -3
- package/dist/time.d.ts +2 -2
- package/dist/types/cron.types.d.ts +12 -6
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## [3.1.0](https://github.com/kelektiv/node-cron/compare/v3.0.0...v3.1.0) (2023-10-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### ✨ Features
|
|
5
|
+
|
|
6
|
+
* improve context, onTick & onComplete typings ([#705](https://github.com/kelektiv/node-cron/issues/705)) ([82c78d7](https://github.com/kelektiv/node-cron/commit/82c78d79594c2d1c1e36baa67ecd76c033a171e4))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### 🚨 Tests
|
|
10
|
+
|
|
11
|
+
* check at runtime that all tests call expect ([#706](https://github.com/kelektiv/node-cron/issues/706)) [skip ci] ([cc4e62f](https://github.com/kelektiv/node-cron/commit/cc4e62fd1fd713d4c8a324ba36c0caa8b0c364e9))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### ♻️ Chores
|
|
15
|
+
|
|
16
|
+
* **deps:** update semantic-release related packages ([#709](https://github.com/kelektiv/node-cron/issues/709)) [skip ci] ([b94a48a](https://github.com/kelektiv/node-cron/commit/b94a48a6b24e20c1f3a9c5109158ff359d048bac))
|
|
17
|
+
* reflect repository label changes ([#708](https://github.com/kelektiv/node-cron/issues/708)) ([85c9e18](https://github.com/kelektiv/node-cron/commit/85c9e18023aea907c10ca77bc92db7a8086f1b6b))
|
|
18
|
+
|
|
1
19
|
## [3.0.0](https://github.com/kelektiv/node-cron/compare/v2.4.4...v3.0.0) (2023-09-30)
|
|
2
20
|
|
|
3
21
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DateTime } from 'luxon';
|
|
2
2
|
export { CronJob } from './job';
|
|
3
3
|
export { CronTime } from './time';
|
|
4
|
-
export { CronCommand, CronJobParams, Ranges, TimeUnit } from './types/cron.types';
|
|
4
|
+
export { CronCallback, CronCommand, CronContext, CronJobParams, CronOnCompleteCallback, CronOnCompleteCommand, Ranges, TimeUnit } from './types/cron.types';
|
|
5
5
|
export declare const sendAt: (cronTime: string | Date | DateTime) => DateTime;
|
|
6
6
|
export declare const timeout: (cronTime: string | Date | DateTime) => number;
|
package/dist/job.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { CronTime } from './time';
|
|
2
|
-
import { CronJobParams } from './types/cron.types';
|
|
3
|
-
export declare class CronJob {
|
|
2
|
+
import { CronCallback, CronContext, CronJobParams, CronOnCompleteCallback, CronOnCompleteCommand, WithOnComplete } from './types/cron.types';
|
|
3
|
+
export declare class CronJob<OC extends CronOnCompleteCommand<C> | 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
|
-
context:
|
|
10
|
-
onComplete?:
|
|
9
|
+
context: CronContext<C>;
|
|
10
|
+
onComplete?: WithOnComplete<OC> extends true ? CronOnCompleteCallback<C> : undefined;
|
|
11
11
|
private _timeout?;
|
|
12
12
|
private _callbacks;
|
|
13
|
-
constructor(cronTime: CronJobParams['cronTime'], onTick: CronJobParams['onTick'], onComplete?: CronJobParams['onComplete'], start?: CronJobParams['start'], timeZone?: CronJobParams['timeZone'], context?: CronJobParams['context'], runOnInit?: CronJobParams['runOnInit'], utcOffset?: null, unrefTimeout?: CronJobParams['unrefTimeout']);
|
|
14
|
-
constructor(cronTime: CronJobParams['cronTime'], onTick: CronJobParams['onTick'], onComplete?: CronJobParams['onComplete'], start?: CronJobParams['start'], timeZone?: null, context?: CronJobParams['context'], runOnInit?: CronJobParams['runOnInit'], utcOffset?: CronJobParams['utcOffset'], unrefTimeout?: CronJobParams['unrefTimeout']);
|
|
15
|
-
static from(params: CronJobParams): CronJob
|
|
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
|
+
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<C = null, OC extends CronOnCompleteCommand<C> | null = null>(params: CronJobParams<OC, C>): CronJob<OC, C>;
|
|
16
16
|
private _fnWrap;
|
|
17
|
-
addCallback(callback:
|
|
17
|
+
addCallback(callback: CronCallback<C, WithOnComplete<OC>>): void;
|
|
18
18
|
setTime(time: CronTime): void;
|
|
19
19
|
nextDate(): import("luxon").DateTime;
|
|
20
20
|
fireOnTick(): void;
|
package/dist/job.js
CHANGED
|
@@ -11,7 +11,7 @@ class CronJob {
|
|
|
11
11
|
this.lastExecution = null;
|
|
12
12
|
this.runOnce = false;
|
|
13
13
|
this._callbacks = [];
|
|
14
|
-
this.context = context
|
|
14
|
+
this.context = (context !== null && context !== void 0 ? context : this);
|
|
15
15
|
if (timeZone != null && utcOffset != null) {
|
|
16
16
|
throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
|
|
17
17
|
}
|
|
@@ -63,7 +63,7 @@ class CronJob {
|
|
|
63
63
|
}
|
|
64
64
|
case 'string': {
|
|
65
65
|
const [command, ...args] = cmd.split(' ');
|
|
66
|
-
return child_process_1.spawn.bind(undefined, command !== null && command !== void 0 ? command : cmd, args);
|
|
66
|
+
return child_process_1.spawn.bind(undefined, command !== null && command !== void 0 ? command : cmd, args, {});
|
|
67
67
|
}
|
|
68
68
|
case 'object': {
|
|
69
69
|
return child_process_1.spawn.bind(undefined, cmd.command, (_a = cmd.args) !== null && _a !== void 0 ? _a : [], (_b = cmd.options) !== null && _b !== void 0 ? _b : {});
|
|
@@ -160,7 +160,7 @@ class CronJob {
|
|
|
160
160
|
clearTimeout(this._timeout);
|
|
161
161
|
this.running = false;
|
|
162
162
|
if (typeof this.onComplete === 'function') {
|
|
163
|
-
this.onComplete();
|
|
163
|
+
this.onComplete.call(this.context);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
}
|
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['cronTime'], timeZone?: CronJobParams['timeZone'], utcOffset?: null);
|
|
15
|
-
constructor(source: CronJobParams['cronTime'], timeZone?: null, utcOffset?: CronJobParams['utcOffset']);
|
|
14
|
+
constructor(source: CronJobParams<null>['cronTime'], timeZone?: CronJobParams<null>['timeZone'], utcOffset?: null);
|
|
15
|
+
constructor(source: CronJobParams<null>['cronTime'], timeZone?: null, utcOffset?: CronJobParams<null>['utcOffset']);
|
|
16
16
|
private _getWeekDay;
|
|
17
17
|
private _verifyParse;
|
|
18
18
|
sendAt(): DateTime;
|
|
@@ -4,27 +4,33 @@ 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 {
|
|
7
|
+
interface BaseCronJobParams<OC extends CronOnCompleteCommand<C> | null, C = null> {
|
|
8
8
|
cronTime: string | Date | DateTime;
|
|
9
|
-
onTick: CronCommand
|
|
10
|
-
onComplete?:
|
|
9
|
+
onTick: CronCommand<C, WithOnComplete<OC>>;
|
|
10
|
+
onComplete?: OC;
|
|
11
11
|
start?: boolean | null;
|
|
12
|
-
context?:
|
|
12
|
+
context?: C;
|
|
13
13
|
runOnInit?: boolean | null;
|
|
14
14
|
unrefTimeout?: boolean | null;
|
|
15
15
|
}
|
|
16
|
-
export type CronJobParams = BaseCronJobParams & ({
|
|
16
|
+
export type CronJobParams<OC extends CronOnCompleteCommand<C> | 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
|
|
23
|
+
export type CronContext<C> = C extends null ? CronJob<null> : NonNullable<C>;
|
|
24
|
+
export type CronCallback<C, WithOnCompleteBool extends boolean = false> = (this: CronContext<C>, onComplete: WithOnCompleteBool extends true ? OmitThisParameter<CronOnCompleteCallback<C>> : never) => void;
|
|
25
|
+
export type CronOnCompleteCallback<C> = (this: CronContext<C>) => void;
|
|
26
|
+
export type CronSystemCommand = string | {
|
|
24
27
|
command: string;
|
|
25
28
|
args?: readonly string[] | null;
|
|
26
29
|
options?: SpawnOptions | null;
|
|
27
30
|
};
|
|
31
|
+
export type CronCommand<C, WithOnCompleteBool extends boolean = false> = CronCallback<C, WithOnCompleteBool> | CronSystemCommand;
|
|
32
|
+
export type CronOnCompleteCommand<C> = OmitThisParameter<CronOnCompleteCallback<C>> | CronSystemCommand;
|
|
33
|
+
export type WithOnComplete<OC> = OC extends null ? false : true;
|
|
28
34
|
export type TimeUnit = (typeof TIME_UNITS_MAP)[keyof typeof TIME_UNITS_MAP];
|
|
29
35
|
export type TimeUnitField<T extends TimeUnit> = Partial<Record<Ranges[T], boolean>>;
|
|
30
36
|
export interface Ranges {
|
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.
|
|
4
|
+
"version": "3.1.0",
|
|
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"
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"luxon": "~3.3.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@commitlint/cli": "
|
|
31
|
-
"@insurgentlab/commitlint-config": "
|
|
32
|
-
"@insurgentlab/conventional-changelog-preset": "
|
|
33
|
-
"@semantic-release/changelog": "
|
|
34
|
-
"@semantic-release/commit-analyzer": "
|
|
35
|
-
"@semantic-release/git": "
|
|
36
|
-
"@semantic-release/github": "
|
|
37
|
-
"@semantic-release/npm": "
|
|
38
|
-
"@semantic-release/release-notes-generator": "
|
|
30
|
+
"@commitlint/cli": "17.7.2",
|
|
31
|
+
"@insurgentlab/commitlint-config": "18.1.3",
|
|
32
|
+
"@insurgentlab/conventional-changelog-preset": "7.0.0",
|
|
33
|
+
"@semantic-release/changelog": "6.0.3",
|
|
34
|
+
"@semantic-release/commit-analyzer": "11.0.0",
|
|
35
|
+
"@semantic-release/git": "10.0.1",
|
|
36
|
+
"@semantic-release/github": "9.2.1",
|
|
37
|
+
"@semantic-release/npm": "11.0.0",
|
|
38
|
+
"@semantic-release/release-notes-generator": "12.0.0",
|
|
39
39
|
"@types/jest": "^29.5.5",
|
|
40
40
|
"@types/node": "^20.6.0",
|
|
41
41
|
"@types/sinon": "^10.0.16",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"husky": "^8.0.3",
|
|
49
49
|
"jest": "~29.5.x",
|
|
50
50
|
"prettier": "~2.8.x",
|
|
51
|
-
"semantic-release": "
|
|
51
|
+
"semantic-release": "22.0.5",
|
|
52
52
|
"sinon": "^15.0.x",
|
|
53
53
|
"ts-jest": "^29.1.1",
|
|
54
54
|
"typescript": "~5.1.6"
|