@sapphire/plugin-scheduled-tasks 9.0.1 → 9.0.2-next.16ee17a.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.
@@ -8,7 +8,7 @@ var ScheduledTaskTypes_cjs = require('./lib/types/ScheduledTaskTypes.cjs');
8
8
  var _load_cjs = require('./listeners/_load.cjs');
9
9
 
10
10
  // src/index.ts
11
- var version = "9.0.1";
11
+ var version = "9.0.2-next.16ee17a.0";
12
12
 
13
13
  Object.defineProperty(exports, 'loadListeners', {
14
14
  enumerable: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";AAIA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,SAAS,qBAAqB;AA8BvB,IAAM,UAAkB","sourcesContent":["import type { ScheduledTaskHandler } from './lib/ScheduledTaskHandler';\nimport type { ScheduledTaskStore } from './lib/structures/ScheduledTaskStore';\nimport type { ScheduledTaskHandlerOptions } from './lib/types/ScheduledTaskTypes';\n\nexport * from './lib/ScheduledTaskHandler';\nexport * from './lib/structures/ScheduledTask';\nexport * from './lib/structures/ScheduledTaskStore';\nexport * from './lib/types/ScheduledTaskEvents';\nexport * from './lib/types/ScheduledTaskTypes';\n\nexport { loadListeners } from './listeners/_load';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\ttasks: ScheduledTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'scheduled-tasks': ScheduledTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\ttasks?: ScheduledTaskHandlerOptions;\n\t\t/**\n\t\t * If the the pre-included scheduled task error listeners should be loaded\n\t\t * @default false\n\t\t */\n\t\tloadScheduledTaskErrorListeners?: boolean;\n\t}\n}\n\n/**\n * The [@sapphire/plugin-scheduled-tasks](https://github.com/sapphiredev/plugins/blob/main/packages/scheduled-tasks) 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 = '9.0.1';\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";AAIA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,SAAS,qBAAqB;AA8BvB,IAAM,UAAkB","sourcesContent":["import type { ScheduledTaskHandler } from './lib/ScheduledTaskHandler';\nimport type { ScheduledTaskStore } from './lib/structures/ScheduledTaskStore';\nimport type { ScheduledTaskHandlerOptions } from './lib/types/ScheduledTaskTypes';\n\nexport * from './lib/ScheduledTaskHandler';\nexport * from './lib/structures/ScheduledTask';\nexport * from './lib/structures/ScheduledTaskStore';\nexport * from './lib/types/ScheduledTaskEvents';\nexport * from './lib/types/ScheduledTaskTypes';\n\nexport { loadListeners } from './listeners/_load';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\ttasks: ScheduledTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'scheduled-tasks': ScheduledTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\ttasks?: ScheduledTaskHandlerOptions;\n\t\t/**\n\t\t * If the the pre-included scheduled task error listeners should be loaded\n\t\t * @default false\n\t\t */\n\t\tloadScheduledTaskErrorListeners?: boolean;\n\t}\n}\n\n/**\n * The [@sapphire/plugin-scheduled-tasks](https://github.com/sapphiredev/plugins/blob/main/packages/scheduled-tasks) 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 = '9.0.2-next.16ee17a.0';\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/ScheduledTaskHandler.ts"],"names":[],"mappings":";;;;;;;;;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BAAoB,uBAAuB,MAAM,OAAO;AAC9E;AAAA,IACD;AAEA,UAAM,SAAS,MAAM,OAAO,UAAU,YAAY;AACjD,gBAAU,OAAO,KAAK,oBAAoB,kBAAkB,MAAM,OAAO;AAEzE,YAAM,YAAY,IAAI,UAAU;AAChC,YAAM,gBAAgB,MAAM,MAAM,IAAI,OAAO;AAC7C,YAAM,EAAE,SAAS,IAAI,UAAU,KAAK;AAEpC,gBAAU,OAAO,KAAK,oBAAoB,sBAAsB,MAAM,SAAS,eAAe,QAAQ;AAEtG,aAAO;AAAA,IACR,CAAC;AAED,WAAO,WAAW,CAAC,UAAU,UAAU,OAAO,KAAK,oBAAoB,oBAAoB,OAAO,MAAM,OAAO,CAAC;AAEhH,UAAM,QAAQ,OAAO,SAAS,IAAI;AAElC,cAAU,OAAO,KAAK,oBAAoB,uBAAuB,MAAM,OAAO,OAAO;AAErF,WAAO;AAAA,EACR;AAAA,EAEA,IAAY,QAA4B;AACvC,WAAO,UAAU,OAAO,OAAO,IAAI,iBAAiB;AAAA,EACrD;AACD;AAlJC;AAHiC;AAA3B,IAAM,uBAAN","sourcesContent":["import { container, Result } from '@sapphire/framework';\nimport { Stopwatch } from '@sapphire/stopwatch';\nimport { Job, Queue, Worker, type EntryId, type JobsOptions, type QueueOptions } from 'bullmq';\nimport type { ScheduledTaskStore } from './structures/ScheduledTaskStore';\nimport { ScheduledTaskEvents } from './types/ScheduledTaskEvents';\nimport type {\n\tBullClient,\n\tScheduledTaskCreateRepeatedTask,\n\tScheduledTaskHandlerOptions,\n\tScheduledTaskJob,\n\tScheduledTaskListOptions,\n\tScheduledTaskListRepeatedOptions,\n\tScheduledTaskListRepeatedReturnType,\n\tScheduledTasks,\n\tScheduledTasksTaskOptions\n} from './types/ScheduledTaskTypes';\n\nexport class ScheduledTaskHandler {\n\tpublic readonly options: QueueOptions;\n\tpublic readonly queue: string;\n\t#internalClient: BullClient | null = null;\n\n\tpublic constructor(options?: ScheduledTaskHandlerOptions) {\n\t\tthis.queue = options?.queue ?? 'scheduled-tasks';\n\t\tthis.options = options?.bull ?? {};\n\n\t\tconst connectResult = Result.from(() => {\n\t\t\tthis.#internalClient = new Queue(this.queue, this.options);\n\t\t\tnew Worker(this.queue, async (job) => this.run(job?.name, job?.data), { connection: this.options.connection });\n\t\t});\n\n\t\tconnectResult.inspectErr((error) => container.client.emit(ScheduledTaskEvents.ScheduledTaskStrategyConnectError, error));\n\t}\n\n\tpublic get client(): BullClient {\n\t\treturn this.#internalClient!;\n\t}\n\n\tpublic create<T = unknown>(\n\t\ttask: keyof ScheduledTasks,\n\t\tpayload?: ScheduledTaskJob | null,\n\t\toptions?: ScheduledTasksTaskOptions | number\n\t): Promise<Job<T, any, string>> | undefined {\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof options === 'number') {\n\t\t\toptions = {\n\t\t\t\trepeated: false,\n\t\t\t\tdelay: options\n\t\t\t};\n\t\t}\n\n\t\tlet jobOptions: JobsOptions = {\n\t\t\tdelay: options?.delay,\n\t\t\t...options?.customJobOptions\n\t\t};\n\n\t\tif (options?.repeated) {\n\t\t\tjobOptions = {\n\t\t\t\t...jobOptions,\n\t\t\t\trepeat: options?.interval\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tevery: options.interval!\n\t\t\t\t\t }\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tpattern: options.pattern!\n\t\t\t\t\t }\n\t\t\t};\n\t\t}\n\n\t\treturn this.#internalClient.add(task, payload ?? null, jobOptions) as Promise<Job<T>> | undefined;\n\t}\n\n\tpublic async createRepeated(tasks?: ScheduledTaskCreateRepeatedTask[]): Promise<void> {\n\t\tconst { store } = this;\n\n\t\ttasks ??= store.repeatedTasks.map((piece) => ({\n\t\t\tname: piece.name,\n\t\t\toptions: {\n\t\t\t\trepeated: true,\n\t\t\t\t...(piece.interval\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tinterval: piece.interval,\n\t\t\t\t\t\t\tcustomJobOptions: piece.customJobOptions\n\t\t\t\t\t }\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tpattern: piece.pattern!,\n\t\t\t\t\t\t\tcustomJobOptions: piece.customJobOptions\n\t\t\t\t\t })\n\t\t\t}\n\t\t}));\n\n\t\tfor (const task of tasks) {\n\t\t\tawait this.create(task.name as keyof ScheduledTasks, null, task.options);\n\t\t}\n\t}\n\n\tpublic async delete(id: EntryId): Promise<void> {\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst job = await this.get(id);\n\t\treturn job?.remove();\n\t}\n\n\tpublic list<T = unknown>(options: ScheduledTaskListOptions): Promise<Job<T>[]> | undefined {\n\t\tconst { types, start, end, asc } = options;\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#internalClient.getJobs(types, start, end, asc) as Promise<Job<T>[]> | undefined;\n\t}\n\n\tpublic listRepeated(options: ScheduledTaskListRepeatedOptions): Promise<ScheduledTaskListRepeatedReturnType> | undefined {\n\t\tconst { start, end, asc } = options;\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#internalClient.getRepeatableJobs(start, end, asc);\n\t}\n\n\tpublic get<T = unknown>(id: EntryId): Promise<Job<T> | null> | undefined {\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#internalClient.getJob(id) as Promise<Job<T> | null> | undefined;\n\t}\n\n\tpublic async run(task: string, payload: unknown): Promise<unknown> {\n\t\tconst piece = this.store.get(task);\n\n\t\tif (!piece) {\n\t\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskNotFound, task, payload);\n\t\t\treturn;\n\t\t}\n\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskRun, task, payload);\n\n\t\t\tconst stopwatch = new Stopwatch();\n\t\t\tconst taskRunResult = await piece.run(payload);\n\t\t\tconst { duration } = stopwatch.stop();\n\n\t\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskSuccess, task, payload, taskRunResult, duration);\n\n\t\t\treturn duration;\n\t\t});\n\n\t\tresult.inspectErr((error) => container.client.emit(ScheduledTaskEvents.ScheduledTaskError, error, task, payload));\n\n\t\tconst value = result.unwrapOr(null);\n\n\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskFinished, task, value, payload);\n\n\t\treturn value;\n\t}\n\n\tprivate get store(): ScheduledTaskStore {\n\t\treturn container.client.stores.get('scheduled-tasks') as unknown as ScheduledTaskStore;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/lib/ScheduledTaskHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,WAAW,cAAc;AAClC,SAAS,iBAAiB;AAC1B,SAAc,OAAO,cAAiE;AAEtF,SAAS,2BAA2B;AAJpC;AAiBO,IAAM,wBAAN,MAAM,sBAAqB;AAAA,EAK1B,YAAY,SAAuC;AAJ1D,wBAAgB;AAChB,wBAAgB;AAChB,wCAAqC;AAGpC,SAAK,QAAQ,SAAS,SAAS;AAC/B,SAAK,UAAU,SAAS,QAAQ,CAAC;AAEjC,UAAM,gBAAgB,OAAO,KAAK,MAAM;AACvC,yBAAK,iBAAkB,IAAI,MAAM,KAAK,OAAO,KAAK,OAAO;AACzD,UAAI,OAAO,KAAK,OAAO,OAAO,QAAQ,KAAK,IAAI,KAAK,MAAM,KAAK,IAAI,GAAG,EAAE,YAAY,KAAK,QAAQ,WAAW,CAAC;AAAA,IAC9G,CAAC;AAED,kBAAc,WAAW,CAAC,UAAU,UAAU,OAAO,KAAK,oBAAoB,mCAAmC,KAAK,CAAC;AAAA,EACxH;AAAA,EAEA,IAAW,SAAqB;AAC/B,WAAO,mBAAK;AAAA,EACb;AAAA,EAEO,OACN,MACA,SACA,SAC2C;AAC3C,QAAI,CAAC,mBAAK,kBAAiB;AAC1B;AAAA,IACD;AAEA,QAAI,OAAO,YAAY,UA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a,SAAqG;AACxH,UAAM,EAAE,OAAO,KAAK,IAAI,IAAI;AAC5B,QAAI,CAAC,mBAAK,kBAAiB;AAC1B;AAAA,IACD;AAEA,WAAO,mBAAK,iBAAgB,kBAAkB,OAAO,KAAK,GAAG;AAAA,EAC9D;AAAA,EAEO,IAAiB,IAAiD;AACxE,QAAI,CAAC,mBAAK,kBAAiB;AAC1B;AAAA,IACD;AAEA,WAAO,mBAAK,iBAAgB,OAAO,EAAE;AAAA,EACtC;AAAA,EAEA,MAAa,IAAI,MAAc,SAAoC;AAClE,UAAM,QAAQ,KAAK,MAAM,IAAI,IAAI;AAEjC,QAAI,CAAC,OAAO;AACX,gBAAU,OAAO,KAAK,oBAAoB,uBAAuB,MAAM,OAAO;AAC9E;AAAA,IACD;AAEA,UAAM,SAAS,MAAM,OAAO,UAAU,YAAY;AACjD,gBAAU,OAAO,KAAK,oBAAoB,kBAAkB,MAAM,OAAO;AAEzE,YAAM,YAAY,IAAI,UAAU;AAChC,YAAM,gBAAgB,MAAM,MAAM,IAAI,OAAO;AAC7C,YAAM,EAAE,SAAS,IAAI,UAAU,KAAK;AAEpC,gBAAU,OAAO,KAAK,oBAAoB,sBAAsB,MAAM,SAAS,eAAe,QAAQ;AAEtG,aAAO;AAAA,IACR,CAAC;AAED,WAAO,WAAW,CAAC,UAAU,UAAU,OAAO,KAAK,oBAAoB,oBAAoB,OAAO,MAAM,OAAO,CAAC;AAEhH,UAAM,QAAQ,OAAO,SAAS,IAAI;AAElC,cAAU,OAAO,KAAK,oBAAoB,uBAAuB,MAAM,OAAO,OAAO;AAErF,WAAO;AAAA,EACR;AAAA,EAEA,IAAY,QAA4B;AACvC,WAAO,UAAU,OAAO,OAAO,IAAI,iBAAiB;AAAA,EACrD;AACD;AAlJC;AAHiC;AAA3B,IAAM,uBAAN","sourcesContent":["import { container, Result } from '@sapphire/framework';\nimport { Stopwatch } from '@sapphire/stopwatch';\nimport { Job, Queue, Worker, type EntryId, type JobsOptions, type QueueOptions } from 'bullmq';\nimport type { ScheduledTaskStore } from './structures/ScheduledTaskStore';\nimport { ScheduledTaskEvents } from './types/ScheduledTaskEvents';\nimport type {\n\tBullClient,\n\tScheduledTaskCreateRepeatedTask,\n\tScheduledTaskHandlerOptions,\n\tScheduledTaskJob,\n\tScheduledTaskListOptions,\n\tScheduledTaskListRepeatedOptions,\n\tScheduledTaskListRepeatedReturnType,\n\tScheduledTasks,\n\tScheduledTasksTaskOptions\n} from './types/ScheduledTaskTypes';\n\nexport class ScheduledTaskHandler {\n\tpublic readonly options: QueueOptions;\n\tpublic readonly queue: string;\n\t#internalClient: BullClient | null = null;\n\n\tpublic constructor(options?: ScheduledTaskHandlerOptions) {\n\t\tthis.queue = options?.queue ?? 'scheduled-tasks';\n\t\tthis.options = options?.bull ?? {};\n\n\t\tconst connectResult = Result.from(() => {\n\t\t\tthis.#internalClient = new Queue(this.queue, this.options);\n\t\t\tnew Worker(this.queue, async (job) => this.run(job?.name, job?.data), { connection: this.options.connection });\n\t\t});\n\n\t\tconnectResult.inspectErr((error) => container.client.emit(ScheduledTaskEvents.ScheduledTaskStrategyConnectError, error));\n\t}\n\n\tpublic get client(): BullClient {\n\t\treturn this.#internalClient!;\n\t}\n\n\tpublic create<T = unknown>(\n\t\ttask: keyof ScheduledTasks,\n\t\tpayload?: ScheduledTaskJob | null,\n\t\toptions?: ScheduledTasksTaskOptions | number\n\t): Promise<Job<T, any, string>> | undefined {\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof options === 'number') {\n\t\t\toptions = {\n\t\t\t\trepeated: false,\n\t\t\t\tdelay: options\n\t\t\t};\n\t\t}\n\n\t\tlet jobOptions: JobsOptions = {\n\t\t\tdelay: options?.delay,\n\t\t\t...options?.customJobOptions\n\t\t};\n\n\t\tif (options?.repeated) {\n\t\t\tjobOptions = {\n\t\t\t\t...jobOptions,\n\t\t\t\trepeat: options?.interval\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tevery: options.interval!\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tpattern: options.pattern!\n\t\t\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\treturn this.#internalClient.add(task, payload ?? null, jobOptions) as Promise<Job<T>> | undefined;\n\t}\n\n\tpublic async createRepeated(tasks?: ScheduledTaskCreateRepeatedTask[]): Promise<void> {\n\t\tconst { store } = this;\n\n\t\ttasks ??= store.repeatedTasks.map((piece) => ({\n\t\t\tname: piece.name,\n\t\t\toptions: {\n\t\t\t\trepeated: true,\n\t\t\t\t...(piece.interval\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tinterval: piece.interval,\n\t\t\t\t\t\t\tcustomJobOptions: piece.customJobOptions\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tpattern: piece.pattern!,\n\t\t\t\t\t\t\tcustomJobOptions: piece.customJobOptions\n\t\t\t\t\t\t})\n\t\t\t}\n\t\t}));\n\n\t\tfor (const task of tasks) {\n\t\t\tawait this.create(task.name as keyof ScheduledTasks, null, task.options);\n\t\t}\n\t}\n\n\tpublic async delete(id: EntryId): Promise<void> {\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst job = await this.get(id);\n\t\treturn job?.remove();\n\t}\n\n\tpublic list<T = unknown>(options: ScheduledTaskListOptions): Promise<Job<T>[]> | undefined {\n\t\tconst { types, start, end, asc } = options;\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#internalClient.getJobs(types, start, end, asc) as Promise<Job<T>[]> | undefined;\n\t}\n\n\tpublic listRepeated(options: ScheduledTaskListRepeatedOptions): Promise<ScheduledTaskListRepeatedReturnType> | undefined {\n\t\tconst { start, end, asc } = options;\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#internalClient.getRepeatableJobs(start, end, asc);\n\t}\n\n\tpublic get<T = unknown>(id: EntryId): Promise<Job<T> | null> | undefined {\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#internalClient.getJob(id) as Promise<Job<T> | null> | undefined;\n\t}\n\n\tpublic async run(task: string, payload: unknown): Promise<unknown> {\n\t\tconst piece = this.store.get(task);\n\n\t\tif (!piece) {\n\t\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskNotFound, task, payload);\n\t\t\treturn;\n\t\t}\n\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskRun, task, payload);\n\n\t\t\tconst stopwatch = new Stopwatch();\n\t\t\tconst taskRunResult = await piece.run(payload);\n\t\t\tconst { duration } = stopwatch.stop();\n\n\t\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskSuccess, task, payload, taskRunResult, duration);\n\n\t\t\treturn duration;\n\t\t});\n\n\t\tresult.inspectErr((error) => container.client.emit(ScheduledTaskEvents.ScheduledTaskError, error, task, payload));\n\n\t\tconst value = result.unwrapOr(null);\n\n\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskFinished, task, value, payload);\n\n\t\treturn value;\n\t}\n\n\tprivate get store(): ScheduledTaskStore {\n\t\treturn container.client.stores.get('scheduled-tasks') as unknown as ScheduledTaskStore;\n\t}\n}\n"]}
@@ -6,7 +6,7 @@ export * from './lib/types/ScheduledTaskEvents.mjs';
6
6
  export * from './lib/types/ScheduledTaskTypes.mjs';
7
7
  export { loadListeners } from './listeners/_load.mjs';
8
8
 
9
- var version = "9.0.1";
9
+ var version = "9.0.2-next.16ee17a.0";
10
10
 
11
11
  export { version };
12
12
  //# sourceMappingURL=out.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;AAIA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,SAAS,qBAAqB;AA8BvB,IAAM,UAAkB","sourcesContent":["import type { ScheduledTaskHandler } from './lib/ScheduledTaskHandler';\nimport type { ScheduledTaskStore } from './lib/structures/ScheduledTaskStore';\nimport type { ScheduledTaskHandlerOptions } from './lib/types/ScheduledTaskTypes';\n\nexport * from './lib/ScheduledTaskHandler';\nexport * from './lib/structures/ScheduledTask';\nexport * from './lib/structures/ScheduledTaskStore';\nexport * from './lib/types/ScheduledTaskEvents';\nexport * from './lib/types/ScheduledTaskTypes';\n\nexport { loadListeners } from './listeners/_load';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\ttasks: ScheduledTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'scheduled-tasks': ScheduledTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\ttasks?: ScheduledTaskHandlerOptions;\n\t\t/**\n\t\t * If the the pre-included scheduled task error listeners should be loaded\n\t\t * @default false\n\t\t */\n\t\tloadScheduledTaskErrorListeners?: boolean;\n\t}\n}\n\n/**\n * The [@sapphire/plugin-scheduled-tasks](https://github.com/sapphiredev/plugins/blob/main/packages/scheduled-tasks) 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 = '9.0.1';\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;AAIA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,SAAS,qBAAqB;AA8BvB,IAAM,UAAkB","sourcesContent":["import type { ScheduledTaskHandler } from './lib/ScheduledTaskHandler';\nimport type { ScheduledTaskStore } from './lib/structures/ScheduledTaskStore';\nimport type { ScheduledTaskHandlerOptions } from './lib/types/ScheduledTaskTypes';\n\nexport * from './lib/ScheduledTaskHandler';\nexport * from './lib/structures/ScheduledTask';\nexport * from './lib/structures/ScheduledTaskStore';\nexport * from './lib/types/ScheduledTaskEvents';\nexport * from './lib/types/ScheduledTaskTypes';\n\nexport { loadListeners } from './listeners/_load';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\ttasks: ScheduledTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'scheduled-tasks': ScheduledTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\ttasks?: ScheduledTaskHandlerOptions;\n\t\t/**\n\t\t * If the the pre-included scheduled task error listeners should be loaded\n\t\t * @default false\n\t\t */\n\t\tloadScheduledTaskErrorListeners?: boolean;\n\t}\n}\n\n/**\n * The [@sapphire/plugin-scheduled-tasks](https://github.com/sapphiredev/plugins/blob/main/packages/scheduled-tasks) 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 = '9.0.2-next.16ee17a.0';\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/ScheduledTaskHandler.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,WAAW,cAAc;AAClC,SAAS,iBAAiB;AAC1B,SAAc,OAAO,cAAiE;AAEtF,SAAS,2BAA2B;AAJpC;AAiBO,IAAM,wBAAN,MAAM,sBAAqB;AAAA,EAK1B,YAAY,SAAuC;AAJ1D,wBAAgB;AAChB,wBAAgB;AAChB,wCAAqC;AAGpC,SAAK,QAAQ,SAAS,SAAS;AAC/B,SAAK,UAAU,SAAS,QAAQ,CAAC;AAEjC,UAAM,gBAAgB,OAAO,KAAK,MAAM;AACvC,yBAAK,iBAAkB,IAAI,MAAM,KAAK,OAAO,KAAK,OAAO;AACzD,UAAI,OAAO,KAAK,OAAO,OAAO,QAAQ,KAAK,IAAI,KAAK,MAAM,KAAK,IAAI,GAAG,EAAE,YAAY,KAAK,QAAQ,WAAW,CAAC;AAAA,IAC9G,CAAC;AAED,kBAAc,WAAW,CAAC,UAAU,UAAU,OAAO,KAA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,QAA4B;AACvC,WAAO,UAAU,OAAO,OAAO,IAAI,iBAAiB;AAAA,EACrD;AACD;AAlJC;AAHiC;AAA3B,IAAM,uBAAN","sourcesContent":["import { container, Result } from '@sapphire/framework';\nimport { Stopwatch } from '@sapphire/stopwatch';\nimport { Job, Queue, Worker, type EntryId, type JobsOptions, type QueueOptions } from 'bullmq';\nimport type { ScheduledTaskStore } from './structures/ScheduledTaskStore';\nimport { ScheduledTaskEvents } from './types/ScheduledTaskEvents';\nimport type {\n\tBullClient,\n\tScheduledTaskCreateRepeatedTask,\n\tScheduledTaskHandlerOptions,\n\tScheduledTaskJob,\n\tScheduledTaskListOptions,\n\tScheduledTaskListRepeatedOptions,\n\tScheduledTaskListRepeatedReturnType,\n\tScheduledTasks,\n\tScheduledTasksTaskOptions\n} from './types/ScheduledTaskTypes';\n\nexport class ScheduledTaskHandler {\n\tpublic readonly options: QueueOptions;\n\tpublic readonly queue: string;\n\t#internalClient: BullClient | null = null;\n\n\tpublic constructor(options?: ScheduledTaskHandlerOptions) {\n\t\tthis.queue = options?.queue ?? 'scheduled-tasks';\n\t\tthis.options = options?.bull ?? {};\n\n\t\tconst connectResult = Result.from(() => {\n\t\t\tthis.#internalClient = new Queue(this.queue, this.options);\n\t\t\tnew Worker(this.queue, async (job) => this.run(job?.name, job?.data), { connection: this.options.connection });\n\t\t});\n\n\t\tconnectResult.inspectErr((error) => container.client.emit(ScheduledTaskEvents.ScheduledTaskStrategyConnectError, error));\n\t}\n\n\tpublic get client(): BullClient {\n\t\treturn this.#internalClient!;\n\t}\n\n\tpublic create<T = unknown>(\n\t\ttask: keyof ScheduledTasks,\n\t\tpayload?: ScheduledTaskJob | null,\n\t\toptions?: ScheduledTasksTaskOptions | number\n\t): Promise<Job<T, any, string>> | undefined {\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof options === 'number') {\n\t\t\toptions = {\n\t\t\t\trepeated: false,\n\t\t\t\tdelay: options\n\t\t\t};\n\t\t}\n\n\t\tlet jobOptions: JobsOptions = {\n\t\t\tdelay: options?.delay,\n\t\t\t...options?.customJobOptions\n\t\t};\n\n\t\tif (options?.repeated) {\n\t\t\tjobOptions = {\n\t\t\t\t...jobOptions,\n\t\t\t\trepeat: options?.interval\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tevery: options.interval!\n\t\t\t\t\t }\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tpattern: options.pattern!\n\t\t\t\t\t }\n\t\t\t};\n\t\t}\n\n\t\treturn this.#internalClient.add(task, payload ?? null, jobOptions) as Promise<Job<T>> | undefined;\n\t}\n\n\tpublic async createRepeated(tasks?: ScheduledTaskCreateRepeatedTask[]): Promise<void> {\n\t\tconst { store } = this;\n\n\t\ttasks ??= store.repeatedTasks.map((piece) => ({\n\t\t\tname: piece.name,\n\t\t\toptions: {\n\t\t\t\trepeated: true,\n\t\t\t\t...(piece.interval\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tinterval: piece.interval,\n\t\t\t\t\t\t\tcustomJobOptions: piece.customJobOptions\n\t\t\t\t\t }\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tpattern: piece.pattern!,\n\t\t\t\t\t\t\tcustomJobOptions: piece.customJobOptions\n\t\t\t\t\t })\n\t\t\t}\n\t\t}));\n\n\t\tfor (const task of tasks) {\n\t\t\tawait this.create(task.name as keyof ScheduledTasks, null, task.options);\n\t\t}\n\t}\n\n\tpublic async delete(id: EntryId): Promise<void> {\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst job = await this.get(id);\n\t\treturn job?.remove();\n\t}\n\n\tpublic list<T = unknown>(options: ScheduledTaskListOptions): Promise<Job<T>[]> | undefined {\n\t\tconst { types, start, end, asc } = options;\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#internalClient.getJobs(types, start, end, asc) as Promise<Job<T>[]> | undefined;\n\t}\n\n\tpublic listRepeated(options: ScheduledTaskListRepeatedOptions): Promise<ScheduledTaskListRepeatedReturnType> | undefined {\n\t\tconst { start, end, asc } = options;\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#internalClient.getRepeatableJobs(start, end, asc);\n\t}\n\n\tpublic get<T = unknown>(id: EntryId): Promise<Job<T> | null> | undefined {\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#internalClient.getJob(id) as Promise<Job<T> | null> | undefined;\n\t}\n\n\tpublic async run(task: string, payload: unknown): Promise<unknown> {\n\t\tconst piece = this.store.get(task);\n\n\t\tif (!piece) {\n\t\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskNotFound, task, payload);\n\t\t\treturn;\n\t\t}\n\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskRun, task, payload);\n\n\t\t\tconst stopwatch = new Stopwatch();\n\t\t\tconst taskRunResult = await piece.run(payload);\n\t\t\tconst { duration } = stopwatch.stop();\n\n\t\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskSuccess, task, payload, taskRunResult, duration);\n\n\t\t\treturn duration;\n\t\t});\n\n\t\tresult.inspectErr((error) => container.client.emit(ScheduledTaskEvents.ScheduledTaskError, error, task, payload));\n\n\t\tconst value = result.unwrapOr(null);\n\n\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskFinished, task, value, payload);\n\n\t\treturn value;\n\t}\n\n\tprivate get store(): ScheduledTaskStore {\n\t\treturn container.client.stores.get('scheduled-tasks') as unknown as ScheduledTaskStore;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/lib/ScheduledTaskHandler.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,WAAW,cAAc;AAClC,SAAS,iBAAiB;AAC1B,SAAc,OAAO,cAAiE;AAEtF,SAAS,2BAA2B;AAJpC;AAiBO,IAAM,wBAAN,MAAM,sBAAqB;AAAA,EAK1B,YA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AAChC,YAAM,gBAAgB,MAAM,MAAM,IAAI,OAAO;AAC7C,YAAM,EAAE,SAAS,IAAI,UAAU,KAAK;AAEpC,gBAAU,OAAO,KAAK,oBAAoB,sBAAsB,MAAM,SAAS,eAAe,QAAQ;AAEtG,aAAO;AAAA,IACR,CAAC;AAED,WAAO,WAAW,CAAC,UAAU,UAAU,OAAO,KAAK,oBAAoB,oBAAoB,OAAO,MAAM,OAAO,CAAC;AAEhH,UAAM,QAAQ,OAAO,SAAS,IAAI;AAElC,cAAU,OAAO,KAAK,oBAAoB,uBAAuB,MAAM,OAAO,OAAO;AAErF,WAAO;AAAA,EACR;AAAA,EAEA,IAAY,QAA4B;AACvC,WAAO,UAAU,OAAO,OAAO,IAAI,iBAAiB;AAAA,EACrD;AACD;AAlJC;AAHiC;AAA3B,IAAM,uBAAN","sourcesContent":["import { container, Result } from '@sapphire/framework';\nimport { Stopwatch } from '@sapphire/stopwatch';\nimport { Job, Queue, Worker, type EntryId, type JobsOptions, type QueueOptions } from 'bullmq';\nimport type { ScheduledTaskStore } from './structures/ScheduledTaskStore';\nimport { ScheduledTaskEvents } from './types/ScheduledTaskEvents';\nimport type {\n\tBullClient,\n\tScheduledTaskCreateRepeatedTask,\n\tScheduledTaskHandlerOptions,\n\tScheduledTaskJob,\n\tScheduledTaskListOptions,\n\tScheduledTaskListRepeatedOptions,\n\tScheduledTaskListRepeatedReturnType,\n\tScheduledTasks,\n\tScheduledTasksTaskOptions\n} from './types/ScheduledTaskTypes';\n\nexport class ScheduledTaskHandler {\n\tpublic readonly options: QueueOptions;\n\tpublic readonly queue: string;\n\t#internalClient: BullClient | null = null;\n\n\tpublic constructor(options?: ScheduledTaskHandlerOptions) {\n\t\tthis.queue = options?.queue ?? 'scheduled-tasks';\n\t\tthis.options = options?.bull ?? {};\n\n\t\tconst connectResult = Result.from(() => {\n\t\t\tthis.#internalClient = new Queue(this.queue, this.options);\n\t\t\tnew Worker(this.queue, async (job) => this.run(job?.name, job?.data), { connection: this.options.connection });\n\t\t});\n\n\t\tconnectResult.inspectErr((error) => container.client.emit(ScheduledTaskEvents.ScheduledTaskStrategyConnectError, error));\n\t}\n\n\tpublic get client(): BullClient {\n\t\treturn this.#internalClient!;\n\t}\n\n\tpublic create<T = unknown>(\n\t\ttask: keyof ScheduledTasks,\n\t\tpayload?: ScheduledTaskJob | null,\n\t\toptions?: ScheduledTasksTaskOptions | number\n\t): Promise<Job<T, any, string>> | undefined {\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof options === 'number') {\n\t\t\toptions = {\n\t\t\t\trepeated: false,\n\t\t\t\tdelay: options\n\t\t\t};\n\t\t}\n\n\t\tlet jobOptions: JobsOptions = {\n\t\t\tdelay: options?.delay,\n\t\t\t...options?.customJobOptions\n\t\t};\n\n\t\tif (options?.repeated) {\n\t\t\tjobOptions = {\n\t\t\t\t...jobOptions,\n\t\t\t\trepeat: options?.interval\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tevery: options.interval!\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tpattern: options.pattern!\n\t\t\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\treturn this.#internalClient.add(task, payload ?? null, jobOptions) as Promise<Job<T>> | undefined;\n\t}\n\n\tpublic async createRepeated(tasks?: ScheduledTaskCreateRepeatedTask[]): Promise<void> {\n\t\tconst { store } = this;\n\n\t\ttasks ??= store.repeatedTasks.map((piece) => ({\n\t\t\tname: piece.name,\n\t\t\toptions: {\n\t\t\t\trepeated: true,\n\t\t\t\t...(piece.interval\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tinterval: piece.interval,\n\t\t\t\t\t\t\tcustomJobOptions: piece.customJobOptions\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tpattern: piece.pattern!,\n\t\t\t\t\t\t\tcustomJobOptions: piece.customJobOptions\n\t\t\t\t\t\t})\n\t\t\t}\n\t\t}));\n\n\t\tfor (const task of tasks) {\n\t\t\tawait this.create(task.name as keyof ScheduledTasks, null, task.options);\n\t\t}\n\t}\n\n\tpublic async delete(id: EntryId): Promise<void> {\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst job = await this.get(id);\n\t\treturn job?.remove();\n\t}\n\n\tpublic list<T = unknown>(options: ScheduledTaskListOptions): Promise<Job<T>[]> | undefined {\n\t\tconst { types, start, end, asc } = options;\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#internalClient.getJobs(types, start, end, asc) as Promise<Job<T>[]> | undefined;\n\t}\n\n\tpublic listRepeated(options: ScheduledTaskListRepeatedOptions): Promise<ScheduledTaskListRepeatedReturnType> | undefined {\n\t\tconst { start, end, asc } = options;\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#internalClient.getRepeatableJobs(start, end, asc);\n\t}\n\n\tpublic get<T = unknown>(id: EntryId): Promise<Job<T> | null> | undefined {\n\t\tif (!this.#internalClient) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#internalClient.getJob(id) as Promise<Job<T> | null> | undefined;\n\t}\n\n\tpublic async run(task: string, payload: unknown): Promise<unknown> {\n\t\tconst piece = this.store.get(task);\n\n\t\tif (!piece) {\n\t\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskNotFound, task, payload);\n\t\t\treturn;\n\t\t}\n\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskRun, task, payload);\n\n\t\t\tconst stopwatch = new Stopwatch();\n\t\t\tconst taskRunResult = await piece.run(payload);\n\t\t\tconst { duration } = stopwatch.stop();\n\n\t\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskSuccess, task, payload, taskRunResult, duration);\n\n\t\t\treturn duration;\n\t\t});\n\n\t\tresult.inspectErr((error) => container.client.emit(ScheduledTaskEvents.ScheduledTaskError, error, task, payload));\n\n\t\tconst value = result.unwrapOr(null);\n\n\t\tcontainer.client.emit(ScheduledTaskEvents.ScheduledTaskFinished, task, value, payload);\n\n\t\treturn value;\n\t}\n\n\tprivate get store(): ScheduledTaskStore {\n\t\treturn container.client.stores.get('scheduled-tasks') as unknown as ScheduledTaskStore;\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/plugin-scheduled-tasks",
3
- "version": "9.0.1",
3
+ "version": "9.0.2-next.16ee17a.0",
4
4
  "description": "Plugin for @sapphire/framework to have scheduled tasks",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -61,7 +61,7 @@
61
61
  "tsx": "^4.6.2",
62
62
  "typedoc": "^0.25.4",
63
63
  "typedoc-json-parser": "^9.0.1",
64
- "typescript": "^5.3.2"
64
+ "typescript": "^5.3.3"
65
65
  },
66
66
  "repository": {
67
67
  "type": "git",