oqronkit 0.0.1-alpha.1

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.
Files changed (109) hide show
  1. package/README.md +127 -0
  2. package/dist/chunk-I6QFT3MR.mjs +1732 -0
  3. package/dist/chunk-PLN5A6LU.mjs +1447 -0
  4. package/dist/core/config/config-loader.d.ts +3 -0
  5. package/dist/core/config/config-loader.d.ts.map +1 -0
  6. package/dist/core/config/default-config.d.ts +4 -0
  7. package/dist/core/config/default-config.d.ts.map +1 -0
  8. package/dist/core/config/define-config.d.ts +3 -0
  9. package/dist/core/config/define-config.d.ts.map +1 -0
  10. package/dist/core/config/find-up.d.ts +2 -0
  11. package/dist/core/config/find-up.d.ts.map +1 -0
  12. package/dist/core/config/schema.d.ts +306 -0
  13. package/dist/core/config/schema.d.ts.map +1 -0
  14. package/dist/core/context/cron-context.d.ts +14 -0
  15. package/dist/core/context/cron-context.d.ts.map +1 -0
  16. package/dist/core/context/cron-context.interface.d.ts +14 -0
  17. package/dist/core/context/cron-context.interface.d.ts.map +1 -0
  18. package/dist/core/context/job-context.d.ts +22 -0
  19. package/dist/core/context/job-context.d.ts.map +1 -0
  20. package/dist/core/context/schedule-context.d.ts +31 -0
  21. package/dist/core/context/schedule-context.d.ts.map +1 -0
  22. package/dist/core/errors/base.error.d.ts +13 -0
  23. package/dist/core/errors/base.error.d.ts.map +1 -0
  24. package/dist/core/events/event-bus.d.ts +16 -0
  25. package/dist/core/events/event-bus.d.ts.map +1 -0
  26. package/dist/core/index.d.ts +24 -0
  27. package/dist/core/index.d.ts.map +1 -0
  28. package/dist/core/logger/index.d.ts +30 -0
  29. package/dist/core/logger/index.d.ts.map +1 -0
  30. package/dist/core/registry.d.ts +13 -0
  31. package/dist/core/registry.d.ts.map +1 -0
  32. package/dist/core/types/config.types.d.ts +119 -0
  33. package/dist/core/types/config.types.d.ts.map +1 -0
  34. package/dist/core/types/cron.types.d.ts +53 -0
  35. package/dist/core/types/cron.types.d.ts.map +1 -0
  36. package/dist/core/types/db.types.d.ts +32 -0
  37. package/dist/core/types/db.types.d.ts.map +1 -0
  38. package/dist/core/types/index.d.ts +7 -0
  39. package/dist/core/types/index.d.ts.map +1 -0
  40. package/dist/core/types/lock.types.d.ts +7 -0
  41. package/dist/core/types/lock.types.d.ts.map +1 -0
  42. package/dist/core/types/module.types.d.ts +8 -0
  43. package/dist/core/types/module.types.d.ts.map +1 -0
  44. package/dist/core/types/scheduler.types.d.ts +62 -0
  45. package/dist/core/types/scheduler.types.d.ts.map +1 -0
  46. package/dist/cron-V0k1GcxJ.d.mts +102 -0
  47. package/dist/cron-V0k1GcxJ.d.ts +102 -0
  48. package/dist/cron.d.mts +2 -0
  49. package/dist/cron.d.ts +2 -0
  50. package/dist/cron.d.ts.map +1 -0
  51. package/dist/cron.js +215 -0
  52. package/dist/cron.mjs +1 -0
  53. package/dist/db/adapters/memory.adapter.d.ts +25 -0
  54. package/dist/db/adapters/memory.adapter.d.ts.map +1 -0
  55. package/dist/db/adapters/namespaced.adapter.d.ts +26 -0
  56. package/dist/db/adapters/namespaced.adapter.d.ts.map +1 -0
  57. package/dist/db/adapters/sqlite.adapter.d.ts +30 -0
  58. package/dist/db/adapters/sqlite.adapter.d.ts.map +1 -0
  59. package/dist/db/index.d.ts +4 -0
  60. package/dist/db/index.d.ts.map +1 -0
  61. package/dist/index.d.mts +797 -0
  62. package/dist/index.d.ts +32 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +2738 -0
  65. package/dist/index.mjs +747 -0
  66. package/dist/lock/adapters/db-lock.adapter.d.ts +17 -0
  67. package/dist/lock/adapters/db-lock.adapter.d.ts.map +1 -0
  68. package/dist/lock/adapters/memory-lock.adapter.d.ts +13 -0
  69. package/dist/lock/adapters/memory-lock.adapter.d.ts.map +1 -0
  70. package/dist/lock/adapters/namespaced-lock.adapter.d.ts +12 -0
  71. package/dist/lock/adapters/namespaced-lock.adapter.d.ts.map +1 -0
  72. package/dist/lock/heartbeat-worker.d.ts +16 -0
  73. package/dist/lock/heartbeat-worker.d.ts.map +1 -0
  74. package/dist/lock/index.d.ts +7 -0
  75. package/dist/lock/index.d.ts.map +1 -0
  76. package/dist/lock/leader-election.d.ts +16 -0
  77. package/dist/lock/leader-election.d.ts.map +1 -0
  78. package/dist/lock/stall-detector.d.ts +23 -0
  79. package/dist/lock/stall-detector.d.ts.map +1 -0
  80. package/dist/scheduler/cron-engine.d.ts +42 -0
  81. package/dist/scheduler/cron-engine.d.ts.map +1 -0
  82. package/dist/scheduler/define-cron.d.ts +36 -0
  83. package/dist/scheduler/define-cron.d.ts.map +1 -0
  84. package/dist/scheduler/define-schedule.d.ts +52 -0
  85. package/dist/scheduler/define-schedule.d.ts.map +1 -0
  86. package/dist/scheduler/expression-parser.d.ts +2 -0
  87. package/dist/scheduler/expression-parser.d.ts.map +1 -0
  88. package/dist/scheduler/index.d.ts +10 -0
  89. package/dist/scheduler/index.d.ts.map +1 -0
  90. package/dist/scheduler/missed-fire.handler.d.ts +8 -0
  91. package/dist/scheduler/missed-fire.handler.d.ts.map +1 -0
  92. package/dist/scheduler/registry-schedule.d.ts +6 -0
  93. package/dist/scheduler/registry-schedule.d.ts.map +1 -0
  94. package/dist/scheduler/registry.d.ts +6 -0
  95. package/dist/scheduler/registry.d.ts.map +1 -0
  96. package/dist/scheduler/schedule-engine.d.ts +36 -0
  97. package/dist/scheduler/schedule-engine.d.ts.map +1 -0
  98. package/dist/scheduler-HRR3UXGE.mjs +1 -0
  99. package/dist/scheduler.d.mts +248 -0
  100. package/dist/scheduler.d.ts +248 -0
  101. package/dist/scheduler.js +1461 -0
  102. package/dist/scheduler.mjs +1 -0
  103. package/dist/server/express.d.ts +9 -0
  104. package/dist/server/express.d.ts.map +1 -0
  105. package/dist/server/fastify.d.ts +9 -0
  106. package/dist/server/fastify.d.ts.map +1 -0
  107. package/dist/server/handlers.d.ts +15 -0
  108. package/dist/server/handlers.d.ts.map +1 -0
  109. package/package.json +59 -0
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # OqronKit
2
+
3
+ ![Version](https://img.shields.io/npm/v/oqronkit?style=flat-square)
4
+ ![License](https://img.shields.io/npm/l/oqronkit?style=flat-square)
5
+
6
+ OqronKit is a high-performance, enterprise-ready cron and job scheduling framework for Node.js. Designed for extreme scaling, multi-tenancy, and distributed microservices architectures, it features seamless Global Locking, automated Leader Election, missed-fire recovery, and zero-configuration database persistence.
7
+
8
+ Stop struggling with broken internal intervals. Scale confidently across a single monolith or a distributed 50-node cluster using SQLite, Redis, or Memory natively.
9
+
10
+ ## ๐ŸŒŸ Key Features
11
+
12
+ - **Multi-Tenant Isolation**: Safely run `staging` and `production` environments off the exact same database without collision.
13
+ - **Global Distributed Locks**: Automatically prevents duplicate processing across clusters nativelyโ€”you will never accidentally bill a user twice!
14
+ - **Leader Election**: Dynamically promotes a master node to handle system polling intervals natively.
15
+ - **Missed-Fire Recovery**: Automatic detection and recovery strategies (`run_now`, `skip`, or `discard`) when the server goes offline during a schedule.
16
+ - **Fully Declarative (`oqron.config.ts`)**: Define a single TS configuration file natively without writing massive infrastructure boots.
17
+ - **Stall Detection**: Natively monitors and revokes jobs if an executing worker crashes silently or hangs indefinitely.
18
+ - **File-based Auto-Routing**: Magically discovers and registers jobs simply by dropping `.ts` files into your `./jobs` directory!
19
+
20
+ ## ๐Ÿ“ฆ Installation
21
+
22
+ ```bash
23
+ npm install oqronkit
24
+ # or
25
+ yarn add oqronkit
26
+ # or
27
+ bun add oqronkit
28
+ ```
29
+
30
+ *Note: OqronKit bundles standard SQLite and Memory adapters internally. No additional database ORMs are required.*
31
+
32
+ ## ๐Ÿš€ Quick Start
33
+
34
+ ### 1. Configuration (`oqron.config.ts`)
35
+ Create a single definition file at the root of your application to magically boot the entire underlying layer:
36
+
37
+ ```typescript
38
+ import { defineConfig } from "oqronkit";
39
+
40
+ export default defineConfig({
41
+ project: "my-saas-platform",
42
+ environment: process.env.NODE_ENV || "development",
43
+ modules: ["cron", "scheduler"], // Enable standard Crons & dynamic Timed Schedules
44
+ jobsDir: "./src/jobs", // OqronKit automatically finds jobs here
45
+ });
46
+ ```
47
+
48
+ ### 2. Define a Job (`src/jobs/emails.ts`)
49
+ Declare a job logic structure. OqronKit strongly enforces execution wrappers to track success, failure, and execution limits!
50
+
51
+ ```typescript
52
+ import { cron } from "oqronkit";
53
+
54
+ export const dailyDigest = cron({
55
+ name: "daily-digest",
56
+ expression: "0 8 * * *", // Runs every day at 08:00 AM
57
+ timezone: "UTC",
58
+ overlap: "skip", // If it's still sending yesterday's batch, skip today's run
59
+ handler: async (ctx) => {
60
+ ctx.logger.info("Gathering active users...", {
61
+ env: ctx.environment
62
+ });
63
+
64
+ // Simulate complex DB queries natively
65
+ await new Promise((r) => setTimeout(r, 1000));
66
+
67
+ return { users_processed: 50 };
68
+ }
69
+ });
70
+ ```
71
+
72
+ ### 3. Initialize Server
73
+ Simply inject `OqronKit.init()` natively into your backend bootstrapping logic!
74
+
75
+ ```typescript
76
+ import { OqronKit } from "oqronkit";
77
+
78
+ async function boot() {
79
+ await OqronKit.init();
80
+ console.log("Enterprise Task Scheduling armed.");
81
+ }
82
+ boot();
83
+ ```
84
+
85
+ ---
86
+
87
+ ## ๐ŸŽ› Advanced Usage
88
+
89
+ ### Dynamic Specific-Time Scheduling
90
+ Unlike generic Crons, `scheduler` natively handles firing dynamic "one-off" events inside user logic boundaries, explicitly persisting to the DB out of the box!
91
+
92
+ ```typescript
93
+ import { schedule } from "oqronkit";
94
+
95
+ // 1. Define the handler type structure
96
+ export const subscriptionHandler = schedule<{ userId: string }>({
97
+ name: "cancel-subscription-job",
98
+ keepHistory: true, // Keep an internal audit trail within the DB
99
+ handler: async (ctx) => {
100
+ const { userId } = ctx.payload;
101
+ console.log(`Cancelled user ${userId} natively!`);
102
+ }
103
+ });
104
+
105
+ // 2. Trigger the job dynamically in your Express routes natively
106
+ await subscriptionHandler({ userId: "u_abc123" }, {
107
+ runAfter: { days: 3 }
108
+ });
109
+ ```
110
+
111
+ ---
112
+
113
+ ## ๐Ÿ— Architecture & Internal Isolation
114
+
115
+ By default, the `OqronAdapter` prefixes all Database identities mapping directly based on the config file context:
116
+ `${project}:${environment}:${job_name}`
117
+
118
+ This guarantees you can utilize the exact same Redis clusters, the same SQLite tables (`oqron_schedules`), and the identical physical database server for both your staging development servers and production monoliths flawlessly! The leader elections are mathematically isolated using the same prefix architecture natively.
119
+
120
+ ## ๐Ÿค Contributing
121
+ Issues and Pull Requests are welcome to natively expand support for PostgreSQL via `SKIP LOCKED` extensions and deeper Redis locks.
122
+
123
+ 1. Fork the Project
124
+ 2. Create your Feature Branch
125
+ 3. Commit your Changes natively.
126
+ 4. Push to the Branch natively.
127
+ 5. Open a Pull Request!