@devvit/scheduler 0.11.17-next-2025-05-29-56029c461.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/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2023 Reddit Inc.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+ 3. Neither the name of the copyright holder nor the names of its
13
+ contributors may be used to endorse or promote products derived from
14
+ this software without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
+ SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @devvit/scheduler
2
+
3
+ Contains a Scheduler client for use with the Devvit framework.
4
+
5
+ Sign up for Reddit's Developer Platform [here!](https://developers.reddit.com)
@@ -0,0 +1,10 @@
1
+ import type { Scheduler as SchedulerPlugin } from '@devvit/protos';
2
+ import type { ScheduledCronJob, ScheduledCronJobOptions, ScheduledJob, ScheduledJobOptions, Scheduler } from './types/scheduler.js';
3
+ export declare class SchedulerClient implements Scheduler {
4
+ #private;
5
+ constructor(schedulerPlugin: SchedulerPlugin);
6
+ runJob(job: ScheduledJobOptions | ScheduledCronJobOptions): Promise<string>;
7
+ cancelJob(jobId: string): Promise<void>;
8
+ listJobs(): Promise<(ScheduledJob | ScheduledCronJob)[]>;
9
+ }
10
+ //# sourceMappingURL=SchedulerClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchedulerClient.d.ts","sourceRoot":"","sources":["../src/SchedulerClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,SAAS,IAAI,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAK7E,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACV,MAAM,sBAAsB,CAAC;AAE9B,qBAAa,eAAgB,YAAW,SAAS;;gBAGnC,eAAe,EAAE,eAAe;IAItC,MAAM,CAAC,GAAG,EAAE,mBAAmB,GAAG,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC;IAgB3E,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASvC,QAAQ,IAAI,OAAO,CAAC,CAAC,YAAY,GAAG,gBAAgB,CAAC,EAAE,CAAC;CAsC/D"}
@@ -0,0 +1,69 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _SchedulerClient_instances, _SchedulerClient_schedulerPlugin, _SchedulerClient_metadata_get;
13
+ import { getContext } from '@devvit/server';
14
+ import { assertNonNull } from '@devvit/shared-types/NonNull.js';
15
+ export class SchedulerClient {
16
+ constructor(schedulerPlugin) {
17
+ _SchedulerClient_instances.add(this);
18
+ _SchedulerClient_schedulerPlugin.set(this, void 0);
19
+ __classPrivateFieldSet(this, _SchedulerClient_schedulerPlugin, schedulerPlugin, "f");
20
+ }
21
+ async runJob(job) {
22
+ const response = await __classPrivateFieldGet(this, _SchedulerClient_schedulerPlugin, "f").Schedule({
23
+ action: {
24
+ type: job.name,
25
+ data: job.data,
26
+ },
27
+ cron: 'cron' in job ? job.cron : undefined,
28
+ when: 'runAt' in job ? job.runAt : undefined,
29
+ }, __classPrivateFieldGet(this, _SchedulerClient_instances, "a", _SchedulerClient_metadata_get));
30
+ return response.id;
31
+ }
32
+ async cancelJob(jobId) {
33
+ await __classPrivateFieldGet(this, _SchedulerClient_schedulerPlugin, "f").Cancel({
34
+ id: jobId,
35
+ }, __classPrivateFieldGet(this, _SchedulerClient_instances, "a", _SchedulerClient_metadata_get));
36
+ }
37
+ async listJobs() {
38
+ const response = await __classPrivateFieldGet(this, _SchedulerClient_schedulerPlugin, "f").List(
39
+ /**
40
+ * after and before are required for this API to work
41
+ * so we hardcode after to Unix epoch and before to 10 years from now
42
+ * https://reddit.atlassian.net/browse/DX-3060
43
+ */
44
+ {
45
+ after: new Date(0),
46
+ before: new Date(Date.now() + 10 * 365 * 86400 * 1000),
47
+ }, __classPrivateFieldGet(this, _SchedulerClient_instances, "a", _SchedulerClient_metadata_get));
48
+ return response.actions.map((action) => {
49
+ assertNonNull(action.request?.action, 'Scheduled job is malformed');
50
+ if ('when' in action.request && action.request.when != null) {
51
+ return {
52
+ id: action.id,
53
+ name: action.request.action.type,
54
+ runAt: action.request.when,
55
+ data: action.request.action.data,
56
+ };
57
+ }
58
+ return {
59
+ id: action.id,
60
+ name: action.request.action.type,
61
+ cron: action.request.cron ?? '',
62
+ data: action.request.action,
63
+ };
64
+ });
65
+ }
66
+ }
67
+ _SchedulerClient_schedulerPlugin = new WeakMap(), _SchedulerClient_instances = new WeakSet(), _SchedulerClient_metadata_get = function _SchedulerClient_metadata_get() {
68
+ return getContext().debug.metadata;
69
+ };
@@ -0,0 +1,3 @@
1
+ import { SchedulerClient } from './SchedulerClient.js';
2
+ export declare function getScheduler(): SchedulerClient;
3
+ //# sourceMappingURL=getScheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getScheduler.d.ts","sourceRoot":"","sources":["../src/getScheduler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAIvD,wBAAgB,YAAY,IAAI,eAAe,CAM9C"}
@@ -0,0 +1,10 @@
1
+ import { SchedulerDefinition } from '@devvit/protos';
2
+ import { getDevvitConfig } from '@devvit/server/get-devvit-config.js';
3
+ import { SchedulerClient } from './SchedulerClient.js';
4
+ let schedulerPlugin;
5
+ export function getScheduler() {
6
+ if (!schedulerPlugin) {
7
+ schedulerPlugin = getDevvitConfig().use(SchedulerDefinition);
8
+ }
9
+ return new SchedulerClient(schedulerPlugin);
10
+ }
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { getScheduler } from './getScheduler.js';
2
+ export type { SchedulerClient } from './SchedulerClient.js';
3
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export { getScheduler } from './getScheduler.js';
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@devvit/scheduler",
3
+ "version": "0.11.17-next-2025-05-29-56029c461.0",
4
+ "license": "BSD-3-Clause",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://developers.reddit.com/"
8
+ },
9
+ "type": "module",
10
+ "main": "./index.js",
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "clean": "rm -rf .turbo coverage dist",
14
+ "clobber": "yarn clean && rm -rf node_modules",
15
+ "dev": "tsc -w",
16
+ "lint": "redlint .",
17
+ "lint:fix": "yarn lint --fix",
18
+ "prepublishOnly": "publish-package-json",
19
+ "test": "yarn test:types && yarn lint",
20
+ "test:types": "tsc --noEmit"
21
+ },
22
+ "types": "./index.d.ts",
23
+ "dependencies": {
24
+ "@devvit/protos": "0.11.17-next-2025-05-29-56029c461.0",
25
+ "@devvit/shared-types": "0.11.17-next-2025-05-29-56029c461.0"
26
+ },
27
+ "peerDependencies": {
28
+ "@devvit/server": "*"
29
+ },
30
+ "devDependencies": {
31
+ "@devvit/repo-tools": "0.11.17-next-2025-05-29-56029c461.0",
32
+ "@devvit/server": "0.11.17-next-2025-05-29-56029c461.0",
33
+ "@devvit/tsconfig": "0.11.17-next-2025-05-29-56029c461.0",
34
+ "eslint": "9.11.1",
35
+ "typescript": "5.8.3"
36
+ },
37
+ "publishConfig": {
38
+ "directory": "dist"
39
+ },
40
+ "source": "./src/index.ts",
41
+ "gitHead": "5b71a6e7c2128ed851dcc90ec38b6f475fef42b1"
42
+ }
@@ -0,0 +1,83 @@
1
+ import type { JSONObject } from '@devvit/shared-types/json.js';
2
+ export type ScheduledJob = {
3
+ /** ID of the scheduled job. Use this with scheduler.cancelJob to cancel the job. */
4
+ id: string;
5
+ /** The name of the scheduled job type */
6
+ name: string;
7
+ /** Additional data passed in by the scheduler client */
8
+ data: JSONObject | undefined;
9
+ /** The Date of when this job should run */
10
+ runAt: Date;
11
+ };
12
+ export type ScheduledCronJob = {
13
+ /** ID of the scheduled job. Use this with scheduler.cancelJob to cancel the job. */
14
+ id: string;
15
+ /** The name of the scheduled job type */
16
+ name: string;
17
+ /** Additional data passed in by the scheduler client */
18
+ data?: JSONObject | undefined;
19
+ /** The cron string of when this job should run */
20
+ cron: string;
21
+ };
22
+ export type ScheduledJobOptions<T extends JSONObject | undefined = JSONObject | undefined> = {
23
+ /** The name of the scheduled job type */
24
+ name: string;
25
+ /** Additional data passed in by the scheduler client */
26
+ data?: T;
27
+ /** The Date of when this job should run */
28
+ runAt: Date;
29
+ };
30
+ export type ScheduledCronJobOptions<T extends JSONObject | undefined = JSONObject | undefined> = {
31
+ /** The name of the scheduled job type */
32
+ name: string;
33
+ /** Additional data passed in by the scheduler client */
34
+ data?: T;
35
+ /** The cron string of when this job should run */
36
+ cron: string;
37
+ };
38
+ /**
39
+ * Schedule a new job to run at a specific time or on a cron schedule
40
+ * @param job The job to schedule
41
+ * @returns {string} The id of the scheduled job
42
+ */
43
+ export type RunJob<Data extends JSONObject | undefined> = (job: ScheduledJobOptions<Data> | ScheduledCronJobOptions<Data>) => Promise<string>;
44
+ /**
45
+ * Cancel a scheduled job
46
+ * @param jobId The id of the job to cancel
47
+ */
48
+ export type CancelJob = (jobId: string) => Promise<void>;
49
+ /**
50
+ * The Scheduler client lets you schedule new jobs or cancel existing jobs.
51
+ * You must have the `scheduler` enabled in `Devvit.configure` to use this client.
52
+ */
53
+ export type Scheduler = {
54
+ /**
55
+ * Schedule a new job to run at a specific time or on a cron schedule
56
+ * @param job The job to schedule
57
+ * @returns {} The id of the scheduled job
58
+ */
59
+ runJob: <Data extends JSONObject | undefined>(job: ScheduledJobOptions<Data> | ScheduledCronJobOptions<Data>) => Promise<string>;
60
+ /**
61
+ * Cancel a scheduled job
62
+ * @param jobId The id of the job to cancel
63
+ */
64
+ cancelJob: CancelJob;
65
+ /**
66
+ * Gets the list of all scheduled jobs.
67
+ */
68
+ listJobs: () => Promise<(ScheduledJob | ScheduledCronJob)[]>;
69
+ };
70
+ export type ScheduledJobEvent<T extends JSONObject | undefined> = {
71
+ /** The name of the scheduled job */
72
+ name: string;
73
+ /** Additional data passed in by the scheduler client */
74
+ data: T;
75
+ };
76
+ export type ScheduledJobHandler<Data extends JSONObject | undefined = JSONObject | undefined> = (event: ScheduledJobEvent<Data>) => void | Promise<void>;
77
+ export type ScheduledJobType<Data extends JSONObject | undefined> = {
78
+ /** The name of the scheduled job type */
79
+ name: string;
80
+ /** The function that will be called when the job is scheduled to run */
81
+ onRun: ScheduledJobHandler<Data>;
82
+ };
83
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/types/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D,MAAM,MAAM,YAAY,GAAG;IACzB,oFAAoF;IACpF,EAAE,EAAE,MAAM,CAAC;IACX,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;IAC7B,2CAA2C;IAC3C,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,oFAAoF;IACpF,EAAE,EAAE,MAAM,CAAC;IACX,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,IAAI,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IAC9B,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;CACd,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