@wild-framework/scheduling 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wild Framework contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # @wild-framework/scheduling
2
+
3
+ Task scheduling for [Wild Framework](https://github.com/your-org/wild-framework).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @wild-framework/scheduling
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { Scheduler } from "@wild-framework/scheduling";
15
+
16
+ scheduler.every(60_000, async () => {
17
+ await cleanupExpiredSessions();
18
+ });
19
+
20
+ // Job class (resolved from the container for DI)
21
+ scheduler.every(5 * 60_000, SyncProductsJob);
22
+ ```
23
+
24
+ The `SchedulerProvider` starts tasks on boot and stops them on shutdown.
25
+
26
+ ## License
27
+
28
+ MIT
@@ -0,0 +1,3 @@
1
+ export { Scheduler } from "./scheduler.js";
2
+ export { SchedulerProvider } from "./provider.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { Scheduler } from "./scheduler.js";
2
+ export { SchedulerProvider } from "./provider.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Provider, Application } from "@wild-framework/core";
2
+ /**
3
+ * Registers the scheduler with the application.
4
+ *
5
+ * Binds a `Scheduler` into the container. Starts scheduled tasks
6
+ * on boot and stops them on shutdown.
7
+ */
8
+ export declare class SchedulerProvider implements Provider {
9
+ register(app: Application): void;
10
+ boot(app: Application): void;
11
+ shutdown(app: Application): void;
12
+ }
13
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIlE;;;;;GAKG;AACH,qBAAa,iBAAkB,YAAW,QAAQ;IAC9C,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAMhC,IAAI,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAK5B,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;CAInC"}
@@ -0,0 +1,24 @@
1
+ import { Container } from "@wild-framework/container";
2
+ import { Scheduler } from "./scheduler.js";
3
+ /**
4
+ * Registers the scheduler with the application.
5
+ *
6
+ * Binds a `Scheduler` into the container. Starts scheduled tasks
7
+ * on boot and stops them on shutdown.
8
+ */
9
+ export class SchedulerProvider {
10
+ register(app) {
11
+ const container = app.resolve(Container);
12
+ const scheduler = new Scheduler(container);
13
+ container.singleton(Scheduler, () => scheduler);
14
+ }
15
+ boot(app) {
16
+ const scheduler = app.resolve(Scheduler);
17
+ scheduler.start();
18
+ }
19
+ shutdown(app) {
20
+ const scheduler = app.resolve(Scheduler);
21
+ scheduler.stop();
22
+ }
23
+ }
24
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IAC1B,QAAQ,CAAC,GAAgB;QACrB,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACzC,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC;QAC3C,SAAS,CAAC,SAAS,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,CAAC,GAAgB;QACjB,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAY,SAAS,CAAC,CAAC;QACpD,SAAS,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,QAAQ,CAAC,GAAgB;QACrB,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAY,SAAS,CAAC,CAAC;QACpD,SAAS,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;CACJ"}
@@ -0,0 +1,45 @@
1
+ import { Container } from "@wild-framework/container";
2
+ /**
3
+ * A scheduled task's run logic.
4
+ */
5
+ type TaskCallback = () => void | Promise<void>;
6
+ /**
7
+ * A job class with a no-arg `handle()` method.
8
+ * Resolved from the container so jobs get DI.
9
+ */
10
+ type JobConstructor = new () => {
11
+ handle(): void | Promise<void>;
12
+ };
13
+ /**
14
+ * Interval-based scheduler.
15
+ *
16
+ * Tasks are registered with `every()`, started via `start()`,
17
+ * and stopped via `stop()`. Job classes are resolved from the
18
+ * container, so scheduled jobs get constructor DI.
19
+ */
20
+ export declare class Scheduler {
21
+ private container;
22
+ private tasks;
23
+ constructor(container: Container);
24
+ /**
25
+ * Schedule a task to run every `intervalMs`.
26
+ *
27
+ * Accepts either a callback or a job class (resolved from the container).
28
+ */
29
+ every(intervalMs: number, task: TaskCallback | JobConstructor): void;
30
+ /**
31
+ * Start all scheduled tasks.
32
+ */
33
+ start(): void;
34
+ /**
35
+ * Stop all scheduled tasks.
36
+ */
37
+ stop(): void;
38
+ /**
39
+ * Number of scheduled tasks.
40
+ */
41
+ taskCount(): number;
42
+ private resolveTask;
43
+ }
44
+ export {};
45
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD;;GAEG;AACH,KAAK,YAAY,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE/C;;;GAGG;AACH,KAAK,cAAc,GAAG,UAAU;IAAE,MAAM,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC;AAWnE;;;;;;GAMG;AACH,qBAAa,SAAS;IAGN,OAAO,CAAC,SAAS;IAF7B,OAAO,CAAC,KAAK,CAAc;gBAEP,SAAS,EAAE,SAAS;IAExC;;;;OAIG;IACH,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,cAAc,GAAG,IAAI;IAKpE;;OAEG;IACH,KAAK,IAAI,IAAI;IAUb;;OAEG;IACH,IAAI,IAAI,IAAI;IASZ;;OAEG;IACH,SAAS,IAAI,MAAM;IAInB,OAAO,CAAC,WAAW;CAUtB"}
@@ -0,0 +1,64 @@
1
+ import { Container } from "@wild-framework/container";
2
+ /**
3
+ * Interval-based scheduler.
4
+ *
5
+ * Tasks are registered with `every()`, started via `start()`,
6
+ * and stopped via `stop()`. Job classes are resolved from the
7
+ * container, so scheduled jobs get constructor DI.
8
+ */
9
+ export class Scheduler {
10
+ container;
11
+ tasks = [];
12
+ constructor(container) {
13
+ this.container = container;
14
+ }
15
+ /**
16
+ * Schedule a task to run every `intervalMs`.
17
+ *
18
+ * Accepts either a callback or a job class (resolved from the container).
19
+ */
20
+ every(intervalMs, task) {
21
+ const callback = this.resolveTask(task);
22
+ this.tasks.push({ intervalMs, callback });
23
+ }
24
+ /**
25
+ * Start all scheduled tasks.
26
+ */
27
+ start() {
28
+ for (const task of this.tasks) {
29
+ if (!task.timer) {
30
+ task.timer = setInterval(() => {
31
+ void task.callback();
32
+ }, task.intervalMs);
33
+ }
34
+ }
35
+ }
36
+ /**
37
+ * Stop all scheduled tasks.
38
+ */
39
+ stop() {
40
+ for (const task of this.tasks) {
41
+ if (task.timer) {
42
+ clearInterval(task.timer);
43
+ task.timer = undefined;
44
+ }
45
+ }
46
+ }
47
+ /**
48
+ * Number of scheduled tasks.
49
+ */
50
+ taskCount() {
51
+ return this.tasks.length;
52
+ }
53
+ resolveTask(task) {
54
+ if (typeof task === "function" && task.prototype?.handle) {
55
+ // Job class — resolve from the container each run
56
+ return async () => {
57
+ const instance = this.container.resolve(task);
58
+ await instance.handle();
59
+ };
60
+ }
61
+ return task;
62
+ }
63
+ }
64
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1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AM,EAAE,CAAC;YACvD,kDAAkD;YAClD,OAAO,KAAK,IAAI,EAAE;gBACd,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAqC,IAAI,CAAC,CAAC;gBAClF,MAAM,QAAQ,CAAC,MAAM,EAAE,CAAC;YAC5B,CAAC,CAAC;QACN,CAAC;QACD,OAAO,IAAoB,CAAC;IAChC,CAAC;CACJ"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@wild-framework/scheduling",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Sphah",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/KhandaSoftware/wild-framework.git"
24
+ },
25
+ "description": "Task scheduling for Wild Framework.",
26
+ "keywords": [
27
+ "wild",
28
+ "framework",
29
+ "scheduler",
30
+ "cron",
31
+ "tasks"
32
+ ],
33
+ "dependencies": {
34
+ "@wild-framework/core": "0.1.0",
35
+ "@wild-framework/container": "0.1.0"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc",
39
+ "clean": "rm -rf dist",
40
+ "test": "vitest run"
41
+ }
42
+ }