@kingsworld/plugin-cron 5.0.0-next.667641e → 5.0.0-next.797e8cd
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/cjs/{CronTaskHandler-D94YuXWl.cjs → CronTaskHandler-fVZWiMAa.cjs} +10 -10
- package/dist/cjs/CronTaskHandler-fVZWiMAa.cjs.map +1 -0
- package/dist/cjs/index.cjs +3 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +6 -6
- package/dist/cjs/index.d.cts.map +1 -1
- package/dist/cjs/lib/CronTaskHandler.cjs +1 -1
- package/dist/cjs/lib/CronTaskHandler.d.cts +27 -2
- package/dist/cjs/lib/CronTaskHandler.d.cts.map +1 -0
- package/dist/cjs/lib/structures/CronTask.cjs +15 -10
- package/dist/cjs/lib/structures/CronTask.cjs.map +1 -1
- package/dist/cjs/lib/structures/CronTask.d.cts +86 -2
- package/dist/cjs/lib/structures/CronTask.d.cts.map +1 -0
- package/dist/cjs/lib/structures/CronTaskStore.cjs +1 -4
- package/dist/cjs/lib/structures/CronTaskStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/CronTaskStore.d.cts +49 -2
- package/dist/cjs/lib/structures/CronTaskStore.d.cts.map +1 -0
- package/dist/cjs/lib/types/CronTaskTypes.d.cts +27 -2
- package/dist/cjs/lib/types/CronTaskTypes.d.cts.map +1 -0
- package/dist/cjs/lib/utils/normalizePattern.cjs.map +1 -1
- package/dist/cjs/register.cjs +1 -1
- package/dist/cjs/register.cjs.map +1 -1
- package/dist/cjs/register.d.cts.map +1 -1
- package/dist/{cjs/CronTask-DHhctNBr.d.cts → esm/CronTask-yw_82mkr.d.mts} +22 -16
- package/dist/esm/CronTask-yw_82mkr.d.mts.map +1 -0
- package/dist/esm/{CronTaskHandler-B-JlxyTe.mjs → CronTaskHandler-DL6DRegu.mjs} +10 -10
- package/dist/esm/CronTaskHandler-DL6DRegu.mjs.map +1 -0
- package/dist/{cjs/CronTaskHandler-vuZq_6em.d.cts → esm/CronTaskHandler-kTcROO_P.d.mts} +7 -6
- package/dist/esm/CronTaskHandler-kTcROO_P.d.mts.map +1 -0
- package/dist/esm/{CronTaskStore-OcB-CF8h.d.mts → CronTaskStore-Cxdru_tz.d.mts} +2 -5
- package/dist/esm/CronTaskStore-Cxdru_tz.d.mts.map +1 -0
- package/dist/esm/{CronTaskTypes-DYOJOqEY.d.mts → CronTaskTypes-BRnD-V2d.d.mts} +7 -5
- package/dist/esm/CronTaskTypes-BRnD-V2d.d.mts.map +1 -0
- package/dist/esm/index.d.mts +6 -6
- package/dist/esm/index.d.mts.map +1 -1
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/CronTaskHandler.d.mts +1 -1
- package/dist/esm/lib/CronTaskHandler.mjs +1 -1
- package/dist/esm/lib/structures/CronTask.d.mts +1 -1
- package/dist/esm/lib/structures/CronTask.mjs +15 -10
- package/dist/esm/lib/structures/CronTask.mjs.map +1 -1
- package/dist/esm/lib/structures/CronTaskStore.d.mts +1 -1
- package/dist/esm/lib/structures/CronTaskStore.mjs +1 -4
- package/dist/esm/lib/structures/CronTaskStore.mjs.map +1 -1
- package/dist/esm/lib/types/CronTaskTypes.d.mts +1 -1
- package/dist/esm/lib/utils/normalizePattern.d.mts.map +1 -1
- package/dist/esm/lib/utils/normalizePattern.mjs.map +1 -1
- package/dist/esm/register.d.mts.map +1 -1
- package/dist/esm/register.mjs +1 -1
- package/dist/esm/register.mjs.map +1 -1
- package/package.json +6 -4
- package/dist/cjs/CronTask-DHhctNBr.d.cts.map +0 -1
- package/dist/cjs/CronTaskHandler-D94YuXWl.cjs.map +0 -1
- package/dist/cjs/CronTaskHandler-vuZq_6em.d.cts.map +0 -1
- package/dist/cjs/CronTaskStore-BF1lvPJM.d.cts +0 -54
- package/dist/cjs/CronTaskStore-BF1lvPJM.d.cts.map +0 -1
- package/dist/cjs/CronTaskTypes-DOfUFMbV.d.cts +0 -27
- package/dist/cjs/CronTaskTypes-DOfUFMbV.d.cts.map +0 -1
- package/dist/esm/CronTask-BRxg3jbY.d.mts +0 -80
- package/dist/esm/CronTask-BRxg3jbY.d.mts.map +0 -1
- package/dist/esm/CronTaskHandler-B-JlxyTe.mjs.map +0 -1
- package/dist/esm/CronTaskHandler-BnLFnUd9.d.mts +0 -26
- package/dist/esm/CronTaskHandler-BnLFnUd9.d.mts.map +0 -1
- package/dist/esm/CronTaskStore-OcB-CF8h.d.mts.map +0 -1
- package/dist/esm/CronTaskTypes-DYOJOqEY.d.mts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// \0@oxc-project+runtime@0.
|
|
3
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
4
4
|
function _typeof(o) {
|
|
5
5
|
"@babel/helpers - typeof";
|
|
6
6
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -10,25 +10,25 @@ function _typeof(o) {
|
|
|
10
10
|
}, _typeof(o);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
// \0@oxc-project+runtime@0.
|
|
14
|
-
function toPrimitive(t,
|
|
13
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
14
|
+
function toPrimitive(t, e) {
|
|
15
15
|
if ("object" != _typeof(t) || !t) return t;
|
|
16
|
-
var
|
|
17
|
-
if (void 0 !==
|
|
18
|
-
var i =
|
|
16
|
+
var r;
|
|
17
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
18
|
+
var i = r.call(t, e || "default");
|
|
19
19
|
if ("object" != _typeof(i)) return i;
|
|
20
20
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
21
21
|
}
|
|
22
|
-
return ("string" ===
|
|
22
|
+
return ("string" === e ? String : Number)(t);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// \0@oxc-project+runtime@0.
|
|
25
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
26
26
|
function toPropertyKey(t) {
|
|
27
27
|
var i = toPrimitive(t, "string");
|
|
28
28
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// \0@oxc-project+runtime@0.
|
|
31
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
32
32
|
function _defineProperty(e, r, t) {
|
|
33
33
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
34
34
|
value: t,
|
|
@@ -55,4 +55,4 @@ Object.defineProperty(exports, "CronTaskHandler", {
|
|
|
55
55
|
return CronTaskHandler;
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
|
-
//# sourceMappingURL=CronTaskHandler-
|
|
58
|
+
//# sourceMappingURL=CronTaskHandler-fVZWiMAa.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CronTaskHandler-fVZWiMAa.cjs","names":[],"sources":["../../src/lib/CronTaskHandler.ts"],"sourcesContent":["import type Sentry from '@sentry/node';\nimport type { CronTaskHandlerOptions } from './types/CronTaskTypes';\n\nexport class CronTaskHandler {\n\t/**\n\t * The default IANA/TZ timezone to use for all cron jobs.\n\t * You can override this per task, using the timezone option.\n\t *\n\t * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\n\t */\n\tpublic defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];\n\n\t/**\n\t * The ability to opt-out of instrumenting cron jobs with Sentry.\n\t * If you don't use Sentry, you can ignore this option.\n\t *\n\t * @see https://docs.sentry.io/product/crons/\n\t * @defaultValue false\n\t */\n\tpublic disableSentry: boolean;\n\n\t/**\n\t * The Sentry instance to use for instrumenting cron jobs.\n\t * This is only available when [`@sentry/node`](https://www.npmjs.com/package/\\@sentry/node)\n\t * is installed and the {@link CronTaskHandler.disableSentry | `disableSentry`} option is set to false.\n\t */\n\tpublic sentry?: typeof Sentry;\n\n\tpublic constructor(options?: Partial<CronTaskHandlerOptions>) {\n\t\tthis.defaultTimezone = options?.defaultTimezone;\n\t\tthis.disableSentry = options?.disableSentry ?? false;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAa,kBAAb,MAA6B;CAyBrB,YAAY,SAA2C;wBAlBvD;wBASA;wBAOA;EAGN,KAAK,kBAAkB,SAAS;EAChC,KAAK,gBAAgB,SAAS,iBAAiB;CAChD;AACD"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_CronTaskHandler = require("./CronTaskHandler-
|
|
4
|
+
const require_CronTaskHandler = require("./CronTaskHandler-fVZWiMAa.cjs");
|
|
5
5
|
const require_lib_structures_CronTask = require("./lib/structures/CronTask.cjs");
|
|
6
6
|
const require_lib_structures_CronTaskStore = require("./lib/structures/CronTaskStore.cjs");
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
9
|
/**
|
|
10
|
-
* The [
|
|
10
|
+
* The [\@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.
|
|
11
11
|
* An example use of this is showing it of in a bot information command.
|
|
12
12
|
*
|
|
13
13
|
* Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild
|
|
14
14
|
*/
|
|
15
|
-
const version = "5.0.0-next.
|
|
15
|
+
const version = "5.0.0-next.797e8cd";
|
|
16
16
|
|
|
17
17
|
exports.CronTask = require_lib_structures_CronTask.CronTask;
|
|
18
18
|
exports.CronTaskHandler = require_CronTaskHandler.CronTaskHandler;
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import type { CronTaskStore } from './lib/structures/CronTaskStore';\nimport type { CronTaskHandler } from './lib/CronTaskHandler';\nimport type { CronTaskHandlerOptions } from './lib/types/CronTaskTypes';\n\nexport * from './lib/CronTaskHandler';\nexport * from './lib/structures/CronTask';\nexport * from './lib/structures/CronTaskStore';\nexport * from './lib/types/CronTaskTypes';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\tcronTasks: CronTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'cron-tasks': CronTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\tcronTasks?: Partial<CronTaskHandlerOptions>;\n\t}\n}\n\n/**\n * The [
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import type { CronTaskStore } from './lib/structures/CronTaskStore';\nimport type { CronTaskHandler } from './lib/CronTaskHandler';\nimport type { CronTaskHandlerOptions } from './lib/types/CronTaskTypes';\n\nexport * from './lib/CronTaskHandler';\nexport * from './lib/structures/CronTask';\nexport * from './lib/structures/CronTaskStore';\nexport type * from './lib/types/CronTaskTypes';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\tcronTasks: CronTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'cron-tasks': CronTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\tcronTasks?: Partial<CronTaskHandlerOptions>;\n\t}\n}\n\n/**\n * The [\\@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '[VI]{{inject}}[/VI]';\n"],"mappings":";;;;;;;;;;;;;;AAgCA,MAAa,UAAkB"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { CronTaskStore } from "./lib/structures/CronTaskStore.cjs";
|
|
3
|
+
import { CronTaskHandler } from "./lib/CronTaskHandler.cjs";
|
|
4
|
+
import { CronJobOptions, CronTaskHandlerOptions } from "./lib/types/CronTaskTypes.cjs";
|
|
5
|
+
import { CronTask } from "./lib/structures/CronTask.cjs";
|
|
6
6
|
declare module '@sapphire/pieces' {
|
|
7
7
|
interface Container {
|
|
8
8
|
cronTasks: CronTaskHandler;
|
|
@@ -17,11 +17,11 @@ declare module 'discord.js' {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* The [
|
|
20
|
+
* The [\@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.
|
|
21
21
|
* An example use of this is showing it of in a bot information command.
|
|
22
22
|
*
|
|
23
23
|
* Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild
|
|
24
24
|
*/
|
|
25
25
|
export declare const version: string;
|
|
26
|
-
export { CronJobOptions, CronTask, CronTaskHandler, CronTaskHandlerOptions, CronTaskStore };
|
|
26
|
+
export { type CronJobOptions, CronTask, CronTaskHandler, type CronTaskHandlerOptions, CronTaskStore };
|
|
27
27
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/cjs/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;;;YAUW;IACT,WAAW;;YAGF;IACT,cAAc;;;;YAKE;IAChB,YAAY,QAAQ;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;;;YAUW;IACT,WAAW;;YAGF;IACT,cAAc;;;;YAKE;IAChB,YAAY,QAAQ;;;;;;;;;qBAWT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_CronTaskHandler = require("../CronTaskHandler-
|
|
4
|
+
const require_CronTaskHandler = require("../CronTaskHandler-fVZWiMAa.cjs");
|
|
5
5
|
|
|
6
6
|
exports.CronTaskHandler = require_CronTaskHandler.CronTaskHandler;
|
|
@@ -1,3 +1,28 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { CronTaskHandlerOptions } from "./types/CronTaskTypes.cjs";
|
|
3
|
+
import Sentry from "@sentry/node";
|
|
4
|
+
export declare class CronTaskHandler {
|
|
5
|
+
/**
|
|
6
|
+
* The default IANA/TZ timezone to use for all cron jobs.
|
|
7
|
+
* You can override this per task, using the timezone option.
|
|
8
|
+
*
|
|
9
|
+
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
|
10
|
+
*/
|
|
11
|
+
defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];
|
|
12
|
+
/**
|
|
13
|
+
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
|
14
|
+
* If you don't use Sentry, you can ignore this option.
|
|
15
|
+
*
|
|
16
|
+
* @see https://docs.sentry.io/product/crons/
|
|
17
|
+
* @defaultValue false
|
|
18
|
+
*/
|
|
19
|
+
disableSentry: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The Sentry instance to use for instrumenting cron jobs.
|
|
22
|
+
* This is only available when [`@sentry/node`](https://www.npmjs.com/package/\@sentry/node)
|
|
23
|
+
* is installed and the {@link CronTaskHandler.disableSentry | `disableSentry`} option is set to false.
|
|
24
|
+
*/
|
|
25
|
+
sentry?: typeof Sentry;
|
|
26
|
+
constructor(options?: Partial<CronTaskHandlerOptions>);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=CronTaskHandler.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CronTaskHandler.d.cts","names":[],"sources":["../../../src/lib/CronTaskHandler.ts"],"mappings":";;;qBAGa;;;;;;;EAOL,kBAAkB;;;;;;;;EASlB;;;;;;EAOA,gBAAgB;EAEJ,YAAA,UAAU,QAAQ"}
|
|
@@ -31,8 +31,9 @@ var CronTask = class extends _sapphire_pieces.Piece {
|
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
|
34
|
-
*
|
|
35
|
-
* @param
|
|
34
|
+
*
|
|
35
|
+
* @param message - The message to include after the prefix
|
|
36
|
+
* @param other - Extra parameters to pass to the logger
|
|
36
37
|
* @example
|
|
37
38
|
* this.info('Hello world!'); // CronTask[my-task] Hello world!
|
|
38
39
|
*/
|
|
@@ -41,8 +42,9 @@ var CronTask = class extends _sapphire_pieces.Piece {
|
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
|
44
|
-
*
|
|
45
|
-
* @param
|
|
45
|
+
*
|
|
46
|
+
* @param message - The message to include after the prefix
|
|
47
|
+
* @param other - Extra parameters to pass to the logger
|
|
46
48
|
* @example
|
|
47
49
|
* this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
|
|
48
50
|
*/
|
|
@@ -51,8 +53,9 @@ var CronTask = class extends _sapphire_pieces.Piece {
|
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
53
55
|
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
|
54
|
-
*
|
|
55
|
-
* @param
|
|
56
|
+
*
|
|
57
|
+
* @param message - The message to include after the prefix
|
|
58
|
+
* @param other - Extra parameters to pass to the logger
|
|
56
59
|
* @example
|
|
57
60
|
* this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
|
|
58
61
|
*/
|
|
@@ -61,8 +64,9 @@ var CronTask = class extends _sapphire_pieces.Piece {
|
|
|
61
64
|
}
|
|
62
65
|
/**
|
|
63
66
|
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
|
64
|
-
*
|
|
65
|
-
* @param
|
|
67
|
+
*
|
|
68
|
+
* @param message - The message to include after the prefix
|
|
69
|
+
* @param other - Extra parameters to pass to the logger
|
|
66
70
|
* @example
|
|
67
71
|
* this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
|
|
68
72
|
*/
|
|
@@ -71,8 +75,9 @@ var CronTask = class extends _sapphire_pieces.Piece {
|
|
|
71
75
|
}
|
|
72
76
|
/**
|
|
73
77
|
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
|
74
|
-
*
|
|
75
|
-
* @param
|
|
78
|
+
*
|
|
79
|
+
* @param message - The message to include after the prefix
|
|
80
|
+
* @param other - Extra parameters to pass to the logger
|
|
76
81
|
* @example
|
|
77
82
|
* this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
|
|
78
83
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CronTask.cjs","names":["Piece"],"sources":["../../../../src/lib/structures/CronTask.ts"],"sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { Cron } from 'croner';\nimport type { CronJobOptions } from '../types/CronTaskTypes';\n\n/**\n * @example\n *\n * ```typescript\n * // ping.ts\n * import { CronTask } from '@kingsworld/plugin-cron';\n *\n * export class PingPong extends CronTask {\n * \tpublic constructor(context: CronTask.LoaderContext, options: CronTask.Options) {\n * \t\tsuper(context, {\n * \t\t\t...options,\n * \t\t\tpattern: '* * * * *'\n * \t\t});\n * \t}\n *\n * \tpublic run() {\n * \t\tthis.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓\n * \t}\n * }\n * ```\n */\nexport abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {\n\tdeclare public job: Cron;\n\n\tpublic constructor(context: CronTask.LoaderContext, options: Options) {\n\t\tsuper(context, options);\n\t}\n\n\tpublic abstract run(): Awaitable<unknown>;\n\n\tpublic protect?(job: Cron): Awaitable<unknown>;\n\n\tpublic catch?(error: unknown, job: Cron): Awaitable<unknown>;\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.info('Hello world!'); // CronTask[my-task] Hello world!\n\t */\n\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!\n\t */\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!\n\t */\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!\n\t */\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.\n\t */\n\tpublic trace(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n}\n\nexport namespace CronTask {\n\texport type Options = Piece.Options
|
|
1
|
+
{"version":3,"file":"CronTask.cjs","names":["Piece"],"sources":["../../../../src/lib/structures/CronTask.ts"],"sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { Cron } from 'croner';\nimport type { CronJobOptions } from '../types/CronTaskTypes';\n\n/**\n * @example\n *\n * ```typescript\n * // ping.ts\n * import { CronTask } from '@kingsworld/plugin-cron';\n *\n * export class PingPong extends CronTask {\n * \tpublic constructor(context: CronTask.LoaderContext, options: CronTask.Options) {\n * \t\tsuper(context, {\n * \t\t\t...options,\n * \t\t\tpattern: '* * * * *'\n * \t\t});\n * \t}\n *\n * \tpublic run() {\n * \t\tthis.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓\n * \t}\n * }\n * ```\n */\nexport abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {\n\tdeclare public job: Cron;\n\n\tpublic constructor(context: CronTask.LoaderContext, options: Options) {\n\t\tsuper(context, options);\n\t}\n\n\tpublic abstract run(): Awaitable<unknown>;\n\n\tpublic protect?(job: Cron): Awaitable<unknown>;\n\n\tpublic catch?(error: unknown, job: Cron): Awaitable<unknown>;\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t *\n\t * @param message - The message to include after the prefix\n\t * @param other - Extra parameters to pass to the logger\n\t * @example\n\t * this.info('Hello world!'); // CronTask[my-task] Hello world!\n\t */\n\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t *\n\t * @param message - The message to include after the prefix\n\t * @param other - Extra parameters to pass to the logger\n\t * @example\n\t * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!\n\t */\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t *\n\t * @param message - The message to include after the prefix\n\t * @param other - Extra parameters to pass to the logger\n\t * @example\n\t * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!\n\t */\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t *\n\t * @param message - The message to include after the prefix\n\t * @param other - Extra parameters to pass to the logger\n\t * @example\n\t * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!\n\t */\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t *\n\t * @param message - The message to include after the prefix\n\t * @param other - Extra parameters to pass to the logger\n\t * @example\n\t * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.\n\t */\n\tpublic trace(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n}\n\nexport declare namespace CronTask {\n\texport type Options = CronJobOptions & Piece.Options;\n\t/**\n\t * @deprecated Use {@link LoaderContext} instead.\n\t */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'cron-tasks'>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAsB,WAAtB,cAA4FA,uBAA6B;CAGjH,YAAY,SAAiC,SAAkB;EACrE,MAAM,SAAS,OAAO;CACvB;;;;;;;;;CAgBO,KAAK,SAAiB,GAAG,OAAkB;EACjD,KAAK,UAAU,OAAO,KAAK,YAAY,KAAK,KAAK,IAAI,WAAW,GAAG,KAAK;CACzE;;;;;;;;;CAUO,MAAM,SAAiB,GAAG,OAAkB;EAClD,KAAK,UAAU,OAAO,MAAM,YAAY,KAAK,KAAK,IAAI,WAAW,GAAG,KAAK;CAC1E;;;;;;;;;CAUO,KAAK,SAAiB,GAAG,OAAkB;EACjD,KAAK,UAAU,OAAO,KAAK,YAAY,KAAK,KAAK,IAAI,WAAW,GAAG,KAAK;CACzE;;;;;;;;;CAUO,MAAM,SAAiB,GAAG,OAAkB;EAClD,KAAK,UAAU,OAAO,MAAM,YAAY,KAAK,KAAK,IAAI,WAAW,GAAG,KAAK;CAC1E;;;;;;;;;CAUO,MAAM,SAAiB,GAAG,OAAkB;EAClD,KAAK,UAAU,OAAO,MAAM,YAAY,KAAK,KAAK,IAAI,WAAW,GAAG,KAAK;CAC1E;AACD"}
|
|
@@ -1,3 +1,87 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { CronJobOptions } from "../types/CronTaskTypes.cjs";
|
|
3
|
+
import { Piece } from "@sapphire/pieces";
|
|
4
|
+
import { Awaitable } from "@sapphire/framework";
|
|
5
|
+
import { Cron } from "croner";
|
|
6
|
+
/**
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // ping.ts
|
|
11
|
+
* import { CronTask } from '@kingsworld/plugin-cron';
|
|
12
|
+
*
|
|
13
|
+
* export class PingPong extends CronTask {
|
|
14
|
+
* public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
|
|
15
|
+
* super(context, {
|
|
16
|
+
* ...options,
|
|
17
|
+
* pattern: '* * * * *'
|
|
18
|
+
* });
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* public run() {
|
|
22
|
+
* this.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {
|
|
28
|
+
job: Cron;
|
|
29
|
+
constructor(context: CronTask.LoaderContext, options: Options);
|
|
30
|
+
abstract run(): Awaitable<unknown>;
|
|
31
|
+
protect?(job: Cron): Awaitable<unknown>;
|
|
32
|
+
catch?(error: unknown, job: Cron): Awaitable<unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
|
35
|
+
*
|
|
36
|
+
* @param message - The message to include after the prefix
|
|
37
|
+
* @param other - Extra parameters to pass to the logger
|
|
38
|
+
* @example
|
|
39
|
+
* this.info('Hello world!'); // CronTask[my-task] Hello world!
|
|
40
|
+
*/
|
|
41
|
+
info(message: string, ...other: unknown[]): void;
|
|
42
|
+
/**
|
|
43
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
|
44
|
+
*
|
|
45
|
+
* @param message - The message to include after the prefix
|
|
46
|
+
* @param other - Extra parameters to pass to the logger
|
|
47
|
+
* @example
|
|
48
|
+
* this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
|
|
49
|
+
*/
|
|
50
|
+
error(message: string, ...other: unknown[]): void;
|
|
51
|
+
/**
|
|
52
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
|
53
|
+
*
|
|
54
|
+
* @param message - The message to include after the prefix
|
|
55
|
+
* @param other - Extra parameters to pass to the logger
|
|
56
|
+
* @example
|
|
57
|
+
* this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
|
|
58
|
+
*/
|
|
59
|
+
warn(message: string, ...other: unknown[]): void;
|
|
60
|
+
/**
|
|
61
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
|
62
|
+
*
|
|
63
|
+
* @param message - The message to include after the prefix
|
|
64
|
+
* @param other - Extra parameters to pass to the logger
|
|
65
|
+
* @example
|
|
66
|
+
* this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
|
|
67
|
+
*/
|
|
68
|
+
debug(message: string, ...other: unknown[]): void;
|
|
69
|
+
/**
|
|
70
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
|
71
|
+
*
|
|
72
|
+
* @param message - The message to include after the prefix
|
|
73
|
+
* @param other - Extra parameters to pass to the logger
|
|
74
|
+
* @example
|
|
75
|
+
* this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
|
|
76
|
+
*/
|
|
77
|
+
trace(message: string, ...other: unknown[]): void;
|
|
78
|
+
}
|
|
79
|
+
export declare namespace CronTask {
|
|
80
|
+
type Options = CronJobOptions & Piece.Options;
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated Use {@link LoaderContext} instead.
|
|
83
|
+
*/
|
|
84
|
+
type Context = LoaderContext;
|
|
85
|
+
type LoaderContext = Piece.LoaderContext<'cron-tasks'>;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=CronTask.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CronTask.d.cts","names":[],"sources":["../../../../src/lib/structures/CronTask.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;8BA0BsB,SAAS,gBAAgB,SAAS,UAAU,SAAS,iBAAiB,MAAM;EAClF,KAAK;EAED,YAAA,SAAS,SAAS,eAAe,SAAS;WAI7C,OAAO;EAEhB,SAAS,KAAK,OAAO;EAErB,OAAO,gBAAgB,KAAK,OAAO;;;;;;;;;EAUnC,KAAK,oBAAoB;;;;;;;;;EAYzB,MAAM,oBAAoB;;;;;;;;;EAY1B,KAAK,oBAAoB;;;;;;;;;EAYzB,MAAM,oBAAoB;;;;;;;;;EAY1B,MAAM,oBAAoB;;yBAKT;OACZ,UAAU,iBAAiB,MAAM;;;;OAIjC,UAAU;OACV,gBAAgB,MAAM"}
|
|
@@ -19,7 +19,6 @@ var CronTaskStore = class extends _sapphire_pieces.Store {
|
|
|
19
19
|
* - Are enabled
|
|
20
20
|
* - Are currently running
|
|
21
21
|
* - Have not been permanently stopped
|
|
22
|
-
*
|
|
23
22
|
* @returns CronTaskStore
|
|
24
23
|
*/
|
|
25
24
|
pauseAll() {
|
|
@@ -38,7 +37,6 @@ var CronTaskStore = class extends _sapphire_pieces.Store {
|
|
|
38
37
|
* - Are enabled
|
|
39
38
|
* - Are not currently running
|
|
40
39
|
* - Have not been permanently stopped
|
|
41
|
-
*
|
|
42
40
|
* @returns CronTaskStore
|
|
43
41
|
*/
|
|
44
42
|
resumeAll() {
|
|
@@ -58,7 +56,6 @@ var CronTaskStore = class extends _sapphire_pieces.Store {
|
|
|
58
56
|
* - Have not been permanently stopped
|
|
59
57
|
*
|
|
60
58
|
* ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!
|
|
61
|
-
*
|
|
62
59
|
* @returns CronTaskStore
|
|
63
60
|
*/
|
|
64
61
|
stopAll() {
|
|
@@ -119,7 +116,7 @@ var CronTaskStore = class extends _sapphire_pieces.Store {
|
|
|
119
116
|
*/
|
|
120
117
|
clear() {
|
|
121
118
|
this.stopAll();
|
|
122
|
-
|
|
119
|
+
super.clear();
|
|
123
120
|
}
|
|
124
121
|
};
|
|
125
122
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CronTaskStore.cjs","names":["Store","CronTask","Cron","normalizePattern"],"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Cron } from 'croner';\nimport { CronTask } from './CronTask';\nimport { normalizePattern } from '../utils/normalizePattern';\n\nexport class CronTaskStore extends Store<CronTask, 'cron-tasks'> {\n\tpublic constructor() {\n\t\tsuper(CronTask, { name: 'cron-tasks' });\n\t}\n\n\t/**\n\t * Loops over all tasks and pauses those that are running.\n\t *\n\t * @remarks\n\t * This method will only pause tasks that:\n\t * - Are enabled\n\t * - Are currently running\n\t * - Have not been permanently stopped\n\t
|
|
1
|
+
{"version":3,"file":"CronTaskStore.cjs","names":["Store","CronTask","Cron","normalizePattern"],"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Cron } from 'croner';\nimport { CronTask } from './CronTask';\nimport { normalizePattern } from '../utils/normalizePattern';\n\nexport class CronTaskStore extends Store<CronTask, 'cron-tasks'> {\n\tpublic constructor() {\n\t\tsuper(CronTask, { name: 'cron-tasks' });\n\t}\n\n\t/**\n\t * Loops over all tasks and pauses those that are running.\n\t *\n\t * @remarks\n\t * This method will only pause tasks that:\n\t * - Are enabled\n\t * - Are currently running\n\t * - Have not been permanently stopped\n\t * @returns CronTaskStore\n\t */\n\tpublic pauseAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || !task.job.isRunning()) continue;\n\t\t\ttask.job.pause();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [PAUSE] Paused all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and resumes those that are paused.\n\t *\n\t * @remarks\n\t * This method will only resume tasks that:\n\t * - Are enabled\n\t * - Are not currently running\n\t * - Have not been permanently stopped\n\t * @returns CronTaskStore\n\t */\n\tpublic resumeAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || task.job.isRunning() || task.job.isStopped()) continue;\n\t\t\ttask.job.resume();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [RESUME] Resumed all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and stops those that are running.\n\t *\n\t * @remarks\n\t * This method will only stop tasks that:\n\t * - Are enabled\n\t * - Have not been permanently stopped\n\t *\n\t * ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!\n\t * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || task.job.isStopped()) continue;\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\tpublic override set(key: string, value: CronTask): this {\n\t\tconst { pattern, timezone, protect, ...options } = value.options;\n\t\tconst { sentry, defaultTimezone } = this.container.cronTasks;\n\n\t\t// if a task with the same key already exists, stop it before creating a new one\n\t\tif (this.has(key)) {\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [SET] Stopping existing cronjob task before creating a new one.`);\n\t\t\tthis.get(key)?.job.stop();\n\t\t}\n\n\t\tconst timeZone = timezone ?? defaultTimezone;\n\n\t\ttry {\n\t\t\tStore.logger?.(\n\t\t\t\t`[STORE => ${this.name}] [SET] Creating cronjob for ${key} with '${pattern}' as the pattern and '${timeZone}' for the timezone`\n\t\t\t);\n\n\t\t\tvalue.job = new Cron(\n\t\t\t\tpattern,\n\t\t\t\t{\n\t\t\t\t\tname: key,\n\t\t\t\t\ttimezone: timeZone,\n\t\t\t\t\tpaused: true, // we start the job manually once the client is ready\n\t\t\t\t\tprotect: value.protect?.bind(value) ?? protect,\n\t\t\t\t\tcatch: (error) => {\n\t\t\t\t\t\tvalue.error('Encountered an error while running the cron job', error);\n\t\t\t\t\t\tsentry?.captureException(error);\n\t\t\t\t\t\tvalue.catch?.bind(value)(error, value.job);\n\t\t\t\t\t},\n\t\t\t\t\t...options\n\t\t\t\t},\n\t\t\t\tasync () => {\n\t\t\t\t\t// we only want to monitor cron patterns and not single-use tasks that croner supports\n\t\t\t\t\tif (sentry && typeof pattern === 'string' && !pattern.includes(':')) {\n\t\t\t\t\t\tawait sentry.withMonitor(key, value.run.bind(value), {\n\t\t\t\t\t\t\tschedule: { type: 'crontab', value: normalizePattern(pattern) },\n\t\t\t\t\t\t\ttimezone: timeZone\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tawait value.run.bind(value)();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tvalue.error('Encountered an error while creating the cron job', error);\n\t\t\tvoid value.unload();\n\t\t}\n\n\t\treturn super.set(key, value);\n\t}\n\n\t/**\n\t * Deletes a task from the store and stops it if it's running.\n\t */\n\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task && !task.job.isStopped()) {\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\treturn super.delete(key);\n\t}\n\n\t/**\n\t * Stops all running cron jobs and clears the store.\n\t */\n\tpublic override clear() {\n\t\tthis.stopAll();\n\t\tsuper.clear();\n\t}\n}\n"],"mappings":";;;;;;;;;AAKA,IAAa,gBAAb,cAAmCA,uBAA8B;CACzD,cAAc;EACpB,MAAMC,0CAAU,EAAE,MAAM,aAAa,CAAC;CACvC;;;;;;;;;;;CAYO,WAAW;EACjB,KAAK,MAAM,QAAQ,KAAK,OAAO,GAAG;GACjC,IAAI,CAAC,KAAK,WAAW,CAAC,KAAK,IAAI,UAAU,GAAG;GAC5C,KAAK,IAAI,MAAM;EAChB;EAEAD,uBAAM,SAAS,aAAa,KAAK,KAAK,oCAAoC;EAC1E,OAAO;CACR;;;;;;;;;;;CAYO,YAAY;EAClB,KAAK,MAAM,QAAQ,KAAK,OAAO,GAAG;GACjC,IAAI,CAAC,KAAK,WAAW,KAAK,IAAI,UAAU,KAAK,KAAK,IAAI,UAAU,GAAG;GACnE,KAAK,IAAI,OAAO;EACjB;EAEAA,uBAAM,SAAS,aAAa,KAAK,KAAK,sCAAsC;EAC5E,OAAO;CACR;;;;;;;;;;;;CAaO,UAAU;EAChB,KAAK,MAAM,QAAQ,KAAK,OAAO,GAAG;GACjC,IAAI,CAAC,KAAK,WAAW,KAAK,IAAI,UAAU,GAAG;GAC3C,KAAK,IAAI,KAAK;EACf;EAEAA,uBAAM,SAAS,aAAa,KAAK,KAAK,oCAAoC;EAC1E,OAAO;CACR;CAEgB,IAAI,KAAa,OAAuB;EACvD,MAAM,EAAE,SAAS,UAAU,SAAS,GAAG,YAAY,MAAM;EACzD,MAAM,EAAE,QAAQ,oBAAoB,KAAK,UAAU;EAGnD,IAAI,KAAK,IAAI,GAAG,GAAG;GAClBA,uBAAM,SAAS,aAAa,KAAK,KAAK,kEAAkE;GACxG,KAAK,IAAI,GAAG,CAAC,EAAE,IAAI,KAAK;EACzB;EAEA,MAAM,WAAW,YAAY;EAE7B,IAAI;GACHA,uBAAM,SACL,aAAa,KAAK,KAAK,+BAA+B,IAAI,SAAS,QAAQ,wBAAwB,SAAS,mBAC7G;GAEA,MAAM,MAAM,IAAIE,YACf,SACA;IACC,MAAM;IACN,UAAU;IACV,QAAQ;IACR,SAAS,MAAM,SAAS,KAAK,KAAK,KAAK;IACvC,QAAQ,UAAU;KACjB,MAAM,MAAM,mDAAmD,KAAK;KACpE,QAAQ,iBAAiB,KAAK;KAC9B,MAAM,OAAO,KAAK,KAAK,CAAC,CAAC,OAAO,MAAM,GAAG;IAC1C;IACA,GAAG;GACJ,GACA,YAAY;IAEX,IAAI,UAAU,OAAO,YAAY,YAAY,CAAC,QAAQ,SAAS,GAAG,GACjE,MAAM,OAAO,YAAY,KAAK,MAAM,IAAI,KAAK,KAAK,GAAG;KACpD,UAAU;MAAE,MAAM;MAAW,OAAOC,oDAAiB,OAAO;KAAE;KAC9D,UAAU;IACX,CAAC;SAED,MAAM,MAAM,IAAI,KAAK,KAAK,CAAC,CAAC;GAE9B,CACD;EACD,SAAS,OAAO;GACf,MAAM,MAAM,oDAAoD,KAAK;GAChE,MAAM,OAAO;EACnB;EAEA,OAAO,MAAM,IAAI,KAAK,KAAK;CAC5B;;;;CAKgB,OAAO,KAAa;EACnC,MAAM,OAAO,KAAK,IAAI,GAAG;EACzB,IAAI,QAAQ,CAAC,KAAK,IAAI,UAAU,GAC/B,KAAK,IAAI,KAAK;EAGf,OAAO,MAAM,OAAO,GAAG;CACxB;;;;CAKgB,QAAQ;EACvB,KAAK,QAAQ;EACb,MAAM,MAAM;CACb;AACD"}
|
|
@@ -1,3 +1,50 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { CronTask } from "./CronTask.cjs";
|
|
3
|
+
import { Store } from "@sapphire/pieces";
|
|
4
|
+
export declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
|
|
5
|
+
constructor();
|
|
6
|
+
/**
|
|
7
|
+
* Loops over all tasks and pauses those that are running.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This method will only pause tasks that:
|
|
11
|
+
* - Are enabled
|
|
12
|
+
* - Are currently running
|
|
13
|
+
* - Have not been permanently stopped
|
|
14
|
+
* @returns CronTaskStore
|
|
15
|
+
*/
|
|
16
|
+
pauseAll(): this;
|
|
17
|
+
/**
|
|
18
|
+
* Loops over all tasks and resumes those that are paused.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* This method will only resume tasks that:
|
|
22
|
+
* - Are enabled
|
|
23
|
+
* - Are not currently running
|
|
24
|
+
* - Have not been permanently stopped
|
|
25
|
+
* @returns CronTaskStore
|
|
26
|
+
*/
|
|
27
|
+
resumeAll(): this;
|
|
28
|
+
/**
|
|
29
|
+
* Loops over all tasks and stops those that are running.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* This method will only stop tasks that:
|
|
33
|
+
* - Are enabled
|
|
34
|
+
* - Have not been permanently stopped
|
|
35
|
+
*
|
|
36
|
+
* ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!
|
|
37
|
+
* @returns CronTaskStore
|
|
38
|
+
*/
|
|
39
|
+
stopAll(): this;
|
|
40
|
+
set(key: string, value: CronTask): this;
|
|
41
|
+
/**
|
|
42
|
+
* Deletes a task from the store and stops it if it's running.
|
|
43
|
+
*/
|
|
44
|
+
delete(key: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Stops all running cron jobs and clears the store.
|
|
47
|
+
*/
|
|
48
|
+
clear(): void;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=CronTaskStore.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CronTaskStore.d.cts","names":[],"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"mappings":";;;qBAKa,sBAAsB,MAAM;;;;;;;;;;;;EAejC;;;;;;;;;;;EAoBA;;;;;;;;;;;;EAqBA;EAUS,IAAI,aAAa,OAAO;;;;EAsDxB,OAAO;;;;EAYP"}
|
|
@@ -1,3 +1,28 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
2
|
+
import { CronOptions } from "croner";
|
|
3
|
+
export interface CronTaskHandlerOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The default IANA timezone to use for all cron jobs.
|
|
6
|
+
* You can override this per task, using the timezone option.
|
|
7
|
+
*/
|
|
8
|
+
defaultTimezone?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
|
11
|
+
* If you don't use Sentry, you can ignore this option.
|
|
12
|
+
*
|
|
13
|
+
* @see https://docs.sentry.io/product/crons/
|
|
14
|
+
* @defaultValue false
|
|
15
|
+
*/
|
|
16
|
+
disableSentry: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface CronJobOptions extends Pick<CronOptions, 'maxRuns' | 'timezone' | 'unref'> {
|
|
19
|
+
pattern: Date | string;
|
|
20
|
+
/**
|
|
21
|
+
* If true, prevents the job from running if the previous execution is still in progress.
|
|
22
|
+
* If the task has a protect method, it will be called if the job is blocked.
|
|
23
|
+
*
|
|
24
|
+
* @defaultValue false
|
|
25
|
+
*/
|
|
26
|
+
protect?: boolean;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=CronTaskTypes.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CronTaskTypes.d.cts","names":[],"sources":["../../../../src/lib/types/CronTaskTypes.ts"],"mappings":";;iBAEiB;;;;;EAKhB;;;;;;;;EASA;;iBAGgB,uBAAuB,KAAK;EAC5C,SAAS;;;;;;;EAOT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizePattern.cjs","names":[],"sources":["../../../../src/lib/utils/normalizePattern.ts"],"sourcesContent":["/*\n * Credits to Sapphire for this\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/constants.ts#L26-L57\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/Cron.ts#L91\n */\n\nconst predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nconst cronTokens: Record<string, number> = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nconst tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n\nexport function normalizePattern(pattern: string): string {\n\tif (Reflect.has(predefined, pattern)) return Reflect.get(predefined, pattern);\n\treturn pattern.replaceAll(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n}\n"],"mappings":";;;;AAMA,
|
|
1
|
+
{"version":3,"file":"normalizePattern.cjs","names":[],"sources":["../../../../src/lib/utils/normalizePattern.ts"],"sourcesContent":["/*\n * Credits to Sapphire for this\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/constants.ts#L26-L57\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/Cron.ts#L91\n */\n\nconst predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nconst cronTokens: Record<string, number> = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nconst tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n\nexport function normalizePattern(pattern: string): string {\n\tif (Reflect.has(predefined, pattern)) return Reflect.get(predefined, pattern);\n\treturn pattern.replaceAll(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n}\n"],"mappings":";;;;AAMA,MAAM,aAAa;CAClB,aAAa;CACb,WAAW;CACX,YAAY;CACZ,WAAW;CACX,UAAU;CACV,WAAW;AACZ;AAEA,MAAM,aAAqC;CAC1C,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;AACN;AAEA,MAAM,cAAc,IAAI,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,KAAK,GAAG,GAAG,GAAG;AAErE,SAAgB,iBAAiB,SAAyB;CACzD,IAAI,QAAQ,IAAI,YAAY,OAAO,GAAG,OAAO,QAAQ,IAAI,YAAY,OAAO;CAC5E,OAAO,QAAQ,WAAW,cAAc,UAAU,OAAO,QAAQ,IAAI,YAAY,KAAK,CAAC,CAAC;AACzF"}
|
package/dist/cjs/register.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_CronTaskHandler = require("./CronTaskHandler-
|
|
4
|
+
const require_CronTaskHandler = require("./CronTaskHandler-fVZWiMAa.cjs");
|
|
5
5
|
const require_lib_structures_CronTaskStore = require("./lib/structures/CronTaskStore.cjs");
|
|
6
6
|
require("./index.cjs");
|
|
7
7
|
let _sapphire_framework = require("@sapphire/framework");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.cjs","names":["Plugin","preGenericsInitialization","CronTaskHandler","postInitialization","CronTaskStore","preLogin","
|
|
1
|
+
{"version":3,"file":"register.cjs","names":["Plugin","preGenericsInitialization","container","CronTaskHandler","postInitialization","CronTaskStore","preLogin","postLogin","SapphireClient"],"sources":["../../src/register.ts"],"sourcesContent":["/* eslint-disable import-x/no-duplicates */\nimport './index';\n\nimport { container, Plugin, postInitialization, postLogin, preGenericsInitialization, preLogin, SapphireClient } from '@sapphire/framework';\nimport type { ClientOptions } from 'discord.js';\nimport { CronTaskHandler, CronTaskStore } from './index';\n\nexport class CronTaskPlugin extends Plugin {\n\tpublic static override [preGenericsInitialization](this: SapphireClient, options: ClientOptions) {\n\t\tcontainer.cronTasks = new CronTaskHandler(options.cronTasks);\n\t}\n\n\tpublic static override [postInitialization](this: SapphireClient) {\n\t\tthis.stores.register(new CronTaskStore());\n\t}\n\n\tpublic static override async [preLogin](this: SapphireClient) {\n\t\tif (container.cronTasks.disableSentry) return;\n\t\t// eslint-disable-next-line require-atomic-updates\n\t\tcontainer.cronTasks.sentry = await import('@sentry/node').catch(() => undefined);\n\t}\n\n\tpublic static override [postLogin](this: SapphireClient) {\n\t\tthis.stores.get('cron-tasks').resumeAll();\n\t}\n}\n\nSapphireClient.plugins.registerPreGenericsInitializationHook(CronTaskPlugin[preGenericsInitialization], 'Cron-Task-PreGenericsInitialization');\n\nSapphireClient.plugins.registerPostInitializationHook(CronTaskPlugin[postInitialization], 'Cron-Task-PostInitialization');\n\nSapphireClient.plugins.registerPreLoginHook(CronTaskPlugin[preLogin], 'Cron-Task-PreLogin');\n\nSapphireClient.plugins.registerPostLoginHook(CronTaskPlugin[postLogin], 'Cron-Task-PostLogin');\n"],"mappings":";;;;;;;;;AAOA,IAAa,iBAAb,cAAoCA,2BAAO;CAC1C,QAAwBC,+CAAiD,SAAwB;EAChGC,8BAAU,YAAY,IAAIC,wCAAgB,QAAQ,SAAS;CAC5D;CAEA,QAAwBC,0CAA0C;EACjE,KAAK,OAAO,SAAS,IAAIC,mDAAc,CAAC;CACzC;CAEA,cAA8BC,gCAAgC;EAC7D,IAAIJ,8BAAU,UAAU,eAAe;EAEvCA,8BAAU,UAAU,SAAS,MAAM,OAAO,eAAe,CAAC,YAAY,MAAS;CAChF;CAEA,QAAwBK,iCAAiC;EACxD,KAAK,OAAO,IAAI,YAAY,CAAC,CAAC,UAAU;CACzC;AACD;AAEAC,mCAAe,QAAQ,sCAAsC,eAAeP,gDAA4B,qCAAqC;AAE7IO,mCAAe,QAAQ,+BAA+B,eAAeJ,yCAAqB,8BAA8B;AAExHI,mCAAe,QAAQ,qBAAqB,eAAeF,+BAAW,oBAAoB;AAE1FE,mCAAe,QAAQ,sBAAsB,eAAeD,gCAAY,qBAAqB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.cts","names":[],"sources":["../../src/register.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"register.d.cts","names":[],"sources":["../../src/register.ts"],"mappings":";;;;qBAOa,uBAAuB;UACX,2BAA2B,MAAM,gBAAgB,SAAS;UAI1D,oBAAoB,MAAM;UAIpB,UAAU,MAAM,iBAAc;UAMpC,WAAW,MAAM"}
|