traceflow-cron 1.0.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/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # Traceflow Cron
2
+
3
+ Lightweight and simple cron scheduler for Node.js & TypeScript.
4
+
5
+ Built on top of `node-cron` with a clean developer-friendly API.
6
+
7
+ ---
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install traceflow-cron
13
+ ```
14
+
15
+ ---
16
+
17
+ ## Features
18
+
19
+ * Simple cron scheduling
20
+ * TypeScript support
21
+ * Multiple job management
22
+ * Start / Stop jobs
23
+ * Lightweight
24
+ * Easy integration
25
+
26
+ ---
27
+
28
+ ## Usage
29
+
30
+ ### Basic Example
31
+
32
+ ```ts
33
+ import { TraceflowCron } from "traceflow-cron";
34
+
35
+ const cron = new TraceflowCron();
36
+
37
+ cron.schedule(
38
+ "daily-task",
39
+ "0 2 * * *",
40
+ () => {
41
+ console.log("Runs every day at 2 AM");
42
+ }
43
+ );
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Cron Expression Format
49
+
50
+ ```txt
51
+ * * * * *
52
+ | | | | |
53
+ | | | | └─ Day of week
54
+ | | | └── Month
55
+ | | └──── Day
56
+ | └────── Hour
57
+ └──────── Minute
58
+ ```
59
+
60
+ ---
61
+
62
+ ## Examples
63
+
64
+ ### Every Day at 2 AM
65
+
66
+ ```ts
67
+ cron.schedule(
68
+ "night-job",
69
+ "0 2 * * *",
70
+ () => {
71
+ console.log("Night task");
72
+ }
73
+ );
74
+ ```
75
+
76
+ ---
77
+
78
+ ### Every 5 Seconds
79
+
80
+ ```ts
81
+ cron.schedule(
82
+ "test-job",
83
+ "*/5 * * * * *",
84
+ () => {
85
+ console.log("Runs every 5 seconds");
86
+ }
87
+ );
88
+ ```
89
+
90
+ ---
91
+
92
+ ### Every Monday at 9 AM
93
+
94
+ ```ts
95
+ cron.schedule(
96
+ "weekly-report",
97
+ "0 9 * * 1",
98
+ () => {
99
+ console.log("Weekly report");
100
+ }
101
+ );
102
+ ```
103
+
104
+ ---
105
+
106
+ ## API
107
+
108
+ ### schedule(name, expression, callback)
109
+
110
+ Create a new cron job.
111
+
112
+ ```ts
113
+ cron.schedule(
114
+ "backup",
115
+ "0 0 * * *",
116
+ () => {}
117
+ );
118
+ ```
119
+
120
+ | Parameter | Type | Description |
121
+ | ---------- | -------- | ------------------- |
122
+ | name | string | Unique job name |
123
+ | expression | string | Cron expression |
124
+ | callback | function | Function to execute |
125
+
126
+ ---
127
+
128
+ ### stop(name)
129
+
130
+ Stop a running job.
131
+
132
+ ```ts
133
+ cron.stop("backup");
134
+ ```
135
+
136
+ ---
137
+
138
+ ### start(name)
139
+
140
+ Restart a stopped job.
141
+
142
+ ```ts
143
+ cron.start("backup");
144
+ ```
145
+
146
+ ---
147
+
148
+ ### destroy(name)
149
+
150
+ Remove a job completely.
151
+
152
+ ```ts
153
+ cron.destroy("backup");
154
+ ```
155
+
156
+ ---
157
+
158
+ ### getJobs()
159
+
160
+ Get all registered jobs.
161
+
162
+ ```ts
163
+ console.log(cron.getJobs());
164
+ ```
165
+
166
+ ---
167
+
168
+ ## TypeScript Support
169
+
170
+ Fully typed with declaration files included.
171
+
172
+ ---
173
+
174
+ ## License
175
+
176
+ MIT
177
+
178
+ ---
179
+
180
+ ## Author
181
+
182
+ Built with ❤️ by Lokith
@@ -0,0 +1,27 @@
1
+ type JobCallback = () => void;
2
+ declare class BossCron {
3
+ private jobs;
4
+ constructor();
5
+ /**
6
+ * Create a cron job
7
+ */
8
+ schedule(name: string, expression: string, callback: JobCallback): void;
9
+ /**
10
+ * Stop a specific job
11
+ */
12
+ stop(name: string): void;
13
+ /**
14
+ * Start a stopped job
15
+ */
16
+ start(name: string): void;
17
+ /**
18
+ * Delete a job
19
+ */
20
+ destroy(name: string): void;
21
+ /**
22
+ * Get all jobs
23
+ */
24
+ getJobs(): string[];
25
+ }
26
+
27
+ export { BossCron, type JobCallback };
package/dist/index.js ADDED
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ BossCron: () => BossCron
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_node_cron = __toESM(require("node-cron"));
37
+ var BossCron = class {
38
+ jobs;
39
+ constructor() {
40
+ this.jobs = /* @__PURE__ */ new Map();
41
+ }
42
+ /**
43
+ * Create a cron job
44
+ */
45
+ schedule(name, expression, callback) {
46
+ if (this.jobs.has(name)) {
47
+ throw new Error(`Job "${name}" already exists`);
48
+ }
49
+ const task = import_node_cron.default.schedule(expression, () => {
50
+ console.log(`[${name}] Job started`);
51
+ callback();
52
+ });
53
+ this.jobs.set(name, task);
54
+ console.log(`Job "${name}" scheduled with "${expression}"`);
55
+ }
56
+ /**
57
+ * Stop a specific job
58
+ */
59
+ stop(name) {
60
+ const job = this.jobs.get(name);
61
+ if (!job) {
62
+ throw new Error(`Job "${name}" not found`);
63
+ }
64
+ job.stop();
65
+ console.log(`Job "${name}" stopped`);
66
+ }
67
+ /**
68
+ * Start a stopped job
69
+ */
70
+ start(name) {
71
+ const job = this.jobs.get(name);
72
+ if (!job) {
73
+ throw new Error(`Job "${name}" not found`);
74
+ }
75
+ job.start();
76
+ console.log(`Job "${name}" started`);
77
+ }
78
+ /**
79
+ * Delete a job
80
+ */
81
+ destroy(name) {
82
+ const job = this.jobs.get(name);
83
+ if (!job) {
84
+ throw new Error(`Job "${name}" not found`);
85
+ }
86
+ job.stop();
87
+ this.jobs.delete(name);
88
+ console.log(`Job "${name}" destroyed`);
89
+ }
90
+ /**
91
+ * Get all jobs
92
+ */
93
+ getJobs() {
94
+ return [...this.jobs.keys()];
95
+ }
96
+ };
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ BossCron
100
+ });
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "traceflow-cron",
3
+ "version": "1.0.0",
4
+ "description": "Lightweight TypeScript cron scheduler",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "commonjs",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "start": "npm run dev",
13
+ "dev": "tsup src/index.ts --format cjs --watch --dts",
14
+ "build": "tsup src/index.ts --format cjs --dts"
15
+ },
16
+ "keywords": [
17
+ "cron",
18
+ "scheduler",
19
+ "typescript",
20
+ "jobs"
21
+ ],
22
+ "author": "Lokith",
23
+ "license": "MIT",
24
+ "devDependencies": {
25
+ "@types/node": "^25.9.1",
26
+ "tsup": "^8.5.1",
27
+ "typescript": "^6.0.3"
28
+ },
29
+ "dependencies": {
30
+ "node-cron": "^4.2.1"
31
+ }
32
+ }