bunqueue 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/LICENSE +21 -0
- package/README.md +640 -0
- package/dist/application/dlqManager.d.ts +19 -0
- package/dist/application/dlqManager.d.ts.map +1 -0
- package/dist/application/dlqManager.js +44 -0
- package/dist/application/dlqManager.js.map +1 -0
- package/dist/application/eventsManager.d.ts +28 -0
- package/dist/application/eventsManager.d.ts.map +1 -0
- package/dist/application/eventsManager.js +59 -0
- package/dist/application/eventsManager.js.map +1 -0
- package/dist/application/jobLogsManager.d.ts +20 -0
- package/dist/application/jobLogsManager.d.ts.map +1 -0
- package/dist/application/jobLogsManager.js +28 -0
- package/dist/application/jobLogsManager.js.map +1 -0
- package/dist/application/metricsExporter.d.ts +24 -0
- package/dist/application/metricsExporter.d.ts.map +1 -0
- package/dist/application/metricsExporter.js +80 -0
- package/dist/application/metricsExporter.js.map +1 -0
- package/dist/application/operations/ack.d.ts +48 -0
- package/dist/application/operations/ack.d.ts.map +1 -0
- package/dist/application/operations/ack.js +109 -0
- package/dist/application/operations/ack.js.map +1 -0
- package/dist/application/operations/index.d.ts +10 -0
- package/dist/application/operations/index.d.ts.map +1 -0
- package/dist/application/operations/index.js +10 -0
- package/dist/application/operations/index.js.map +1 -0
- package/dist/application/operations/jobManagement.d.ts +32 -0
- package/dist/application/operations/jobManagement.d.ts.map +1 -0
- package/dist/application/operations/jobManagement.js +122 -0
- package/dist/application/operations/jobManagement.js.map +1 -0
- package/dist/application/operations/pull.d.ts +36 -0
- package/dist/application/operations/pull.d.ts.map +1 -0
- package/dist/application/operations/pull.js +109 -0
- package/dist/application/operations/pull.js.map +1 -0
- package/dist/application/operations/push.d.ts +36 -0
- package/dist/application/operations/push.d.ts.map +1 -0
- package/dist/application/operations/push.js +94 -0
- package/dist/application/operations/push.js.map +1 -0
- package/dist/application/operations/queryOperations.d.ts +33 -0
- package/dist/application/operations/queryOperations.d.ts.map +1 -0
- package/dist/application/operations/queryOperations.js +57 -0
- package/dist/application/operations/queryOperations.js.map +1 -0
- package/dist/application/operations/queueControl.d.ts +32 -0
- package/dist/application/operations/queueControl.d.ts.map +1 -0
- package/dist/application/operations/queueControl.js +72 -0
- package/dist/application/operations/queueControl.js.map +1 -0
- package/dist/application/queueManager.d.ts +113 -0
- package/dist/application/queueManager.d.ts.map +1 -0
- package/dist/application/queueManager.js +406 -0
- package/dist/application/queueManager.js.map +1 -0
- package/dist/application/webhookManager.d.ts +35 -0
- package/dist/application/webhookManager.d.ts.map +1 -0
- package/dist/application/webhookManager.js +109 -0
- package/dist/application/webhookManager.js.map +1 -0
- package/dist/application/workerManager.d.ts +48 -0
- package/dist/application/workerManager.d.ts.map +1 -0
- package/dist/application/workerManager.js +121 -0
- package/dist/application/workerManager.js.map +1 -0
- package/dist/domain/queue/index.d.ts +6 -0
- package/dist/domain/queue/index.d.ts.map +1 -0
- package/dist/domain/queue/index.js +6 -0
- package/dist/domain/queue/index.js.map +1 -0
- package/dist/domain/queue/priorityQueue.d.ts +45 -0
- package/dist/domain/queue/priorityQueue.d.ts.map +1 -0
- package/dist/domain/queue/priorityQueue.js +203 -0
- package/dist/domain/queue/priorityQueue.js.map +1 -0
- package/dist/domain/queue/shard.d.ts +98 -0
- package/dist/domain/queue/shard.d.ts.map +1 -0
- package/dist/domain/queue/shard.js +245 -0
- package/dist/domain/queue/shard.js.map +1 -0
- package/dist/domain/types/command.d.ts +270 -0
- package/dist/domain/types/command.d.ts.map +1 -0
- package/dist/domain/types/command.js +6 -0
- package/dist/domain/types/command.js.map +1 -0
- package/dist/domain/types/cron.d.ts +32 -0
- package/dist/domain/types/cron.d.ts.map +1 -0
- package/dist/domain/types/cron.js +31 -0
- package/dist/domain/types/cron.js.map +1 -0
- package/dist/domain/types/index.d.ts +9 -0
- package/dist/domain/types/index.d.ts.map +1 -0
- package/dist/domain/types/index.js +9 -0
- package/dist/domain/types/index.js.map +1 -0
- package/dist/domain/types/job.d.ts +94 -0
- package/dist/domain/types/job.d.ts.map +1 -0
- package/dist/domain/types/job.js +81 -0
- package/dist/domain/types/job.js.map +1 -0
- package/dist/domain/types/queue.d.ts +86 -0
- package/dist/domain/types/queue.d.ts.map +1 -0
- package/dist/domain/types/queue.js +84 -0
- package/dist/domain/types/queue.js.map +1 -0
- package/dist/domain/types/response.d.ts +158 -0
- package/dist/domain/types/response.d.ts.map +1 -0
- package/dist/domain/types/response.js +86 -0
- package/dist/domain/types/response.js.map +1 -0
- package/dist/domain/types/webhook.d.ts +33 -0
- package/dist/domain/types/webhook.d.ts.map +1 -0
- package/dist/domain/types/webhook.js +20 -0
- package/dist/domain/types/webhook.js.map +1 -0
- package/dist/domain/types/worker.d.ts +27 -0
- package/dist/domain/types/worker.d.ts.map +1 -0
- package/dist/domain/types/worker.js +27 -0
- package/dist/domain/types/worker.js.map +1 -0
- package/dist/infrastructure/persistence/index.d.ts +6 -0
- package/dist/infrastructure/persistence/index.d.ts.map +1 -0
- package/dist/infrastructure/persistence/index.js +6 -0
- package/dist/infrastructure/persistence/index.js.map +1 -0
- package/dist/infrastructure/persistence/schema.d.ts +14 -0
- package/dist/infrastructure/persistence/schema.d.ts.map +1 -0
- package/dist/infrastructure/persistence/schema.js +123 -0
- package/dist/infrastructure/persistence/schema.js.map +1 -0
- package/dist/infrastructure/persistence/sqlite.d.ts +42 -0
- package/dist/infrastructure/persistence/sqlite.d.ts.map +1 -0
- package/dist/infrastructure/persistence/sqlite.js +164 -0
- package/dist/infrastructure/persistence/sqlite.js.map +1 -0
- package/dist/infrastructure/persistence/statements.d.ts +55 -0
- package/dist/infrastructure/persistence/statements.d.ts.map +1 -0
- package/dist/infrastructure/persistence/statements.js +42 -0
- package/dist/infrastructure/persistence/statements.js.map +1 -0
- package/dist/infrastructure/scheduler/cronParser.d.ts +44 -0
- package/dist/infrastructure/scheduler/cronParser.d.ts.map +1 -0
- package/dist/infrastructure/scheduler/cronParser.js +90 -0
- package/dist/infrastructure/scheduler/cronParser.js.map +1 -0
- package/dist/infrastructure/scheduler/cronScheduler.d.ts +68 -0
- package/dist/infrastructure/scheduler/cronScheduler.d.ts.map +1 -0
- package/dist/infrastructure/scheduler/cronScheduler.js +172 -0
- package/dist/infrastructure/scheduler/cronScheduler.js.map +1 -0
- package/dist/infrastructure/scheduler/index.d.ts +6 -0
- package/dist/infrastructure/scheduler/index.d.ts.map +1 -0
- package/dist/infrastructure/scheduler/index.js +6 -0
- package/dist/infrastructure/scheduler/index.js.map +1 -0
- package/dist/infrastructure/server/handler.d.ts +13 -0
- package/dist/infrastructure/server/handler.d.ts.map +1 -0
- package/dist/infrastructure/server/handler.js +167 -0
- package/dist/infrastructure/server/handler.js.map +1 -0
- package/dist/infrastructure/server/handlers/advanced.d.ts +68 -0
- package/dist/infrastructure/server/handlers/advanced.d.ts.map +1 -0
- package/dist/infrastructure/server/handlers/advanced.js +99 -0
- package/dist/infrastructure/server/handlers/advanced.js.map +1 -0
- package/dist/infrastructure/server/handlers/core.d.ts +36 -0
- package/dist/infrastructure/server/handlers/core.d.ts.map +1 -0
- package/dist/infrastructure/server/handlers/core.js +82 -0
- package/dist/infrastructure/server/handlers/core.js.map +1 -0
- package/dist/infrastructure/server/handlers/cron.d.ts +20 -0
- package/dist/infrastructure/server/handlers/cron.d.ts.map +1 -0
- package/dist/infrastructure/server/handlers/cron.js +56 -0
- package/dist/infrastructure/server/handlers/cron.js.map +1 -0
- package/dist/infrastructure/server/handlers/dlq.d.ts +20 -0
- package/dist/infrastructure/server/handlers/dlq.d.ts.map +1 -0
- package/dist/infrastructure/server/handlers/dlq.js +31 -0
- package/dist/infrastructure/server/handlers/dlq.js.map +1 -0
- package/dist/infrastructure/server/handlers/index.d.ts +7 -0
- package/dist/infrastructure/server/handlers/index.d.ts.map +1 -0
- package/dist/infrastructure/server/handlers/index.js +7 -0
- package/dist/infrastructure/server/handlers/index.js.map +1 -0
- package/dist/infrastructure/server/handlers/management.d.ts +36 -0
- package/dist/infrastructure/server/handlers/management.d.ts.map +1 -0
- package/dist/infrastructure/server/handlers/management.js +75 -0
- package/dist/infrastructure/server/handlers/management.js.map +1 -0
- package/dist/infrastructure/server/handlers/monitoring.d.ts +18 -0
- package/dist/infrastructure/server/handlers/monitoring.d.ts.map +1 -0
- package/dist/infrastructure/server/handlers/monitoring.js +102 -0
- package/dist/infrastructure/server/handlers/monitoring.js.map +1 -0
- package/dist/infrastructure/server/handlers/query.d.ts +32 -0
- package/dist/infrastructure/server/handlers/query.d.ts.map +1 -0
- package/dist/infrastructure/server/handlers/query.js +61 -0
- package/dist/infrastructure/server/handlers/query.js.map +1 -0
- package/dist/infrastructure/server/http.d.ts +43 -0
- package/dist/infrastructure/server/http.d.ts.map +1 -0
- package/dist/infrastructure/server/http.js +344 -0
- package/dist/infrastructure/server/http.js.map +1 -0
- package/dist/infrastructure/server/index.d.ts +8 -0
- package/dist/infrastructure/server/index.d.ts.map +1 -0
- package/dist/infrastructure/server/index.js +8 -0
- package/dist/infrastructure/server/index.js.map +1 -0
- package/dist/infrastructure/server/protocol.d.ts +44 -0
- package/dist/infrastructure/server/protocol.d.ts.map +1 -0
- package/dist/infrastructure/server/protocol.js +129 -0
- package/dist/infrastructure/server/protocol.js.map +1 -0
- package/dist/infrastructure/server/rateLimiter.d.ts +31 -0
- package/dist/infrastructure/server/rateLimiter.d.ts.map +1 -0
- package/dist/infrastructure/server/rateLimiter.js +79 -0
- package/dist/infrastructure/server/rateLimiter.js.map +1 -0
- package/dist/infrastructure/server/tcp.d.ts +36 -0
- package/dist/infrastructure/server/tcp.d.ts.map +1 -0
- package/dist/infrastructure/server/tcp.js +101 -0
- package/dist/infrastructure/server/tcp.js.map +1 -0
- package/dist/infrastructure/server/types.d.ts +11 -0
- package/dist/infrastructure/server/types.d.ts.map +1 -0
- package/dist/infrastructure/server/types.js +5 -0
- package/dist/infrastructure/server/types.js.map +1 -0
- package/dist/main.d.ts +6 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +111 -0
- package/dist/main.js.map +1 -0
- package/dist/shared/hash.d.ts +30 -0
- package/dist/shared/hash.d.ts.map +1 -0
- package/dist/shared/hash.js +69 -0
- package/dist/shared/hash.js.map +1 -0
- package/dist/shared/index.d.ts +6 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +6 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/lock.d.ts +70 -0
- package/dist/shared/lock.d.ts.map +1 -0
- package/dist/shared/lock.js +207 -0
- package/dist/shared/lock.js.map +1 -0
- package/dist/shared/logger.d.ts +38 -0
- package/dist/shared/logger.d.ts.map +1 -0
- package/dist/shared/logger.js +74 -0
- package/dist/shared/logger.js.map +1 -0
- package/dist/shared/serialization.d.ts +23 -0
- package/dist/shared/serialization.d.ts.map +1 -0
- package/dist/shared/serialization.js +63 -0
- package/dist/shared/serialization.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepared SQLite statements
|
|
3
|
+
* Pre-compiled SQL for better performance
|
|
4
|
+
*/
|
|
5
|
+
import type { Database } from 'bun:sqlite';
|
|
6
|
+
/** Statement names */
|
|
7
|
+
export type StatementName = 'insertJob' | 'updateJobState' | 'completeJob' | 'deleteJob' | 'getJob' | 'nextJobId' | 'insertResult' | 'getResult' | 'insertDlq' | 'insertCron';
|
|
8
|
+
/** SQL statements */
|
|
9
|
+
export declare const SQL_STATEMENTS: Record<StatementName, string>;
|
|
10
|
+
/** Prepare all statements */
|
|
11
|
+
export declare function prepareStatements(db: Database): Map<StatementName, ReturnType<Database['prepare']>>;
|
|
12
|
+
/** Database row type for jobs */
|
|
13
|
+
export interface DbJob {
|
|
14
|
+
id: number;
|
|
15
|
+
queue: string;
|
|
16
|
+
data: string;
|
|
17
|
+
priority: number;
|
|
18
|
+
created_at: number;
|
|
19
|
+
run_at: number;
|
|
20
|
+
started_at: number | null;
|
|
21
|
+
completed_at: number | null;
|
|
22
|
+
attempts: number;
|
|
23
|
+
max_attempts: number;
|
|
24
|
+
backoff: number;
|
|
25
|
+
ttl: number | null;
|
|
26
|
+
timeout: number | null;
|
|
27
|
+
unique_key: string | null;
|
|
28
|
+
custom_id: string | null;
|
|
29
|
+
depends_on: string | null;
|
|
30
|
+
parent_id: number | null;
|
|
31
|
+
children_ids: string | null;
|
|
32
|
+
tags: string | null;
|
|
33
|
+
state: string;
|
|
34
|
+
lifo: number;
|
|
35
|
+
group_id: string | null;
|
|
36
|
+
progress: number | null;
|
|
37
|
+
progress_msg: string | null;
|
|
38
|
+
remove_on_complete: number;
|
|
39
|
+
remove_on_fail: number;
|
|
40
|
+
stall_timeout: number | null;
|
|
41
|
+
last_heartbeat: number | null;
|
|
42
|
+
}
|
|
43
|
+
/** Database row type for cron jobs */
|
|
44
|
+
export interface DbCron {
|
|
45
|
+
name: string;
|
|
46
|
+
queue: string;
|
|
47
|
+
data: string;
|
|
48
|
+
schedule: string | null;
|
|
49
|
+
repeat_every: number | null;
|
|
50
|
+
priority: number;
|
|
51
|
+
next_run: number;
|
|
52
|
+
executions: number;
|
|
53
|
+
max_limit: number | null;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=statements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/persistence/statements.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,sBAAsB;AACtB,MAAM,MAAM,aAAa,GACrB,WAAW,GACX,gBAAgB,GAChB,aAAa,GACb,WAAW,GACX,QAAQ,GACR,WAAW,GACX,cAAc,GACd,WAAW,GACX,WAAW,GACX,YAAY,CAAC;AAEjB,qBAAqB;AACrB,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAsCxD,CAAC;AAEF,6BAA6B;AAC7B,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,QAAQ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IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepared SQLite statements
|
|
3
|
+
* Pre-compiled SQL for better performance
|
|
4
|
+
*/
|
|
5
|
+
/** SQL statements */
|
|
6
|
+
export const SQL_STATEMENTS = {
|
|
7
|
+
insertJob: `
|
|
8
|
+
INSERT INTO jobs (
|
|
9
|
+
id, queue, data, priority, created_at, run_at, attempts,
|
|
10
|
+
max_attempts, backoff, ttl, timeout, unique_key, custom_id,
|
|
11
|
+
depends_on, parent_id, tags, state, lifo, group_id,
|
|
12
|
+
remove_on_complete, remove_on_fail, stall_timeout
|
|
13
|
+
) VALUES (
|
|
14
|
+
?, ?, ?, ?, ?, ?, ?,
|
|
15
|
+
?, ?, ?, ?, ?, ?,
|
|
16
|
+
?, ?, ?, ?, ?, ?,
|
|
17
|
+
?, ?, ?
|
|
18
|
+
)
|
|
19
|
+
`,
|
|
20
|
+
updateJobState: 'UPDATE jobs SET state = ?, started_at = ? WHERE id = ?',
|
|
21
|
+
completeJob: 'UPDATE jobs SET state = ?, completed_at = ?, progress = 100 WHERE id = ?',
|
|
22
|
+
deleteJob: 'DELETE FROM jobs WHERE id = ?',
|
|
23
|
+
getJob: 'SELECT * FROM jobs WHERE id = ?',
|
|
24
|
+
nextJobId: "UPDATE sequences SET value = value + 1 WHERE name = 'job_id' RETURNING value",
|
|
25
|
+
insertResult: 'INSERT OR REPLACE INTO job_results (job_id, result, completed_at) VALUES (?, ?, ?)',
|
|
26
|
+
getResult: 'SELECT result FROM job_results WHERE job_id = ?',
|
|
27
|
+
insertDlq: 'INSERT INTO dlq (job_id, queue, data, error, failed_at, attempts) VALUES (?, ?, ?, ?, ?, ?)',
|
|
28
|
+
insertCron: `
|
|
29
|
+
INSERT OR REPLACE INTO cron_jobs
|
|
30
|
+
(name, queue, data, schedule, repeat_every, priority, next_run, executions, max_limit)
|
|
31
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
32
|
+
`,
|
|
33
|
+
};
|
|
34
|
+
/** Prepare all statements */
|
|
35
|
+
export function prepareStatements(db) {
|
|
36
|
+
const statements = new Map();
|
|
37
|
+
for (const [name, sql] of Object.entries(SQL_STATEMENTS)) {
|
|
38
|
+
statements.set(name, db.prepare(sql));
|
|
39
|
+
}
|
|
40
|
+
return statements;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=statements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statements.js","sourceRoot":"","sources":["../../../src/infrastructure/persistence/statements.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH,qBAAqB;AACrB,MAAM,CAAC,MAAM,cAAc,GAAkC;IAC3D,SAAS,EAAE;;;;;;;;;;;;GAYV;IAED,cAAc,EAAE,wDAAwD;IAExE,WAAW,EAAE,0EAA0E;IAEvF,SAAS,EAAE,+BAA+B;IAE1C,MAAM,EAAE,iCAAiC;IAEzC,SAAS,EAAE,8EAA8E;IAEzF,YAAY,EACV,oFAAoF;IAEtF,SAAS,EAAE,iDAAiD;IAE5D,SAAS,EACP,6FAA6F;IAE/F,UAAU,EAAE;;;;GAIX;CACF,CAAC;AAEF,6BAA6B;AAC7B,MAAM,UAAU,iBAAiB,CAC/B,EAAY;IAEZ,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkD,CAAC;IAE7E,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QACzD,UAAU,CAAC,GAAG,CAAC,IAAqB,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cron Expression Parser
|
|
3
|
+
* Parses 5-6 field cron expressions and calculates next run time
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Validate a cron expression
|
|
7
|
+
* @param expression - Cron expression (5 or 6 fields)
|
|
8
|
+
* @returns null if valid, error message if invalid
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateCronExpression(expression: string): string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Calculate next run time from a cron expression
|
|
13
|
+
* @param expression - Cron expression
|
|
14
|
+
* @param fromTime - Start time (default: now)
|
|
15
|
+
* @returns Next run timestamp in milliseconds
|
|
16
|
+
*/
|
|
17
|
+
export declare function getNextCronRun(expression: string, fromTime?: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* Calculate next run time from repeatEvery interval
|
|
20
|
+
* @param intervalMs - Interval in milliseconds
|
|
21
|
+
* @param lastRun - Last run timestamp
|
|
22
|
+
* @returns Next run timestamp
|
|
23
|
+
*/
|
|
24
|
+
export declare function getNextIntervalRun(intervalMs: number, lastRun?: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* Check if a cron job is due to run
|
|
27
|
+
* @param nextRun - Scheduled next run time
|
|
28
|
+
* @param now - Current time (default: Date.now())
|
|
29
|
+
* @returns true if job should run
|
|
30
|
+
*/
|
|
31
|
+
export declare function isDue(nextRun: number, now?: number): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Parse common cron shortcuts
|
|
34
|
+
*/
|
|
35
|
+
export declare const CRON_SHORTCUTS: Record<string, string>;
|
|
36
|
+
/**
|
|
37
|
+
* Expand cron shortcut to full expression
|
|
38
|
+
*/
|
|
39
|
+
export declare function expandCronShortcut(expression: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Get human-readable description of cron schedule
|
|
42
|
+
*/
|
|
43
|
+
export declare function describeCron(expression: string): string;
|
|
44
|
+
//# sourceMappingURL=cronParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronParser.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/scheduler/cronParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOxE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAmB,GAAG,MAAM,CAIxF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,MAAmB,GAAG,MAAM,CAE3F;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,MAAmB,GAAG,OAAO,CAExE;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAQjD,CAAC;AAEF;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAsBvD"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cron Expression Parser
|
|
3
|
+
* Parses 5-6 field cron expressions and calculates next run time
|
|
4
|
+
*/
|
|
5
|
+
import { Cron } from 'croner';
|
|
6
|
+
/**
|
|
7
|
+
* Validate a cron expression
|
|
8
|
+
* @param expression - Cron expression (5 or 6 fields)
|
|
9
|
+
* @returns null if valid, error message if invalid
|
|
10
|
+
*/
|
|
11
|
+
export function validateCronExpression(expression) {
|
|
12
|
+
try {
|
|
13
|
+
new Cron(expression);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
return err instanceof Error ? err.message : 'Invalid cron expression';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Calculate next run time from a cron expression
|
|
22
|
+
* @param expression - Cron expression
|
|
23
|
+
* @param fromTime - Start time (default: now)
|
|
24
|
+
* @returns Next run timestamp in milliseconds
|
|
25
|
+
*/
|
|
26
|
+
export function getNextCronRun(expression, fromTime = Date.now()) {
|
|
27
|
+
const cron = new Cron(expression);
|
|
28
|
+
const nextDate = cron.nextRun(new Date(fromTime));
|
|
29
|
+
return nextDate ? nextDate.getTime() : 0;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Calculate next run time from repeatEvery interval
|
|
33
|
+
* @param intervalMs - Interval in milliseconds
|
|
34
|
+
* @param lastRun - Last run timestamp
|
|
35
|
+
* @returns Next run timestamp
|
|
36
|
+
*/
|
|
37
|
+
export function getNextIntervalRun(intervalMs, lastRun = Date.now()) {
|
|
38
|
+
return lastRun + intervalMs;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Check if a cron job is due to run
|
|
42
|
+
* @param nextRun - Scheduled next run time
|
|
43
|
+
* @param now - Current time (default: Date.now())
|
|
44
|
+
* @returns true if job should run
|
|
45
|
+
*/
|
|
46
|
+
export function isDue(nextRun, now = Date.now()) {
|
|
47
|
+
return nextRun <= now;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parse common cron shortcuts
|
|
51
|
+
*/
|
|
52
|
+
export const CRON_SHORTCUTS = {
|
|
53
|
+
'@yearly': '0 0 1 1 *',
|
|
54
|
+
'@annually': '0 0 1 1 *',
|
|
55
|
+
'@monthly': '0 0 1 * *',
|
|
56
|
+
'@weekly': '0 0 * * 0',
|
|
57
|
+
'@daily': '0 0 * * *',
|
|
58
|
+
'@midnight': '0 0 * * *',
|
|
59
|
+
'@hourly': '0 * * * *',
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Expand cron shortcut to full expression
|
|
63
|
+
*/
|
|
64
|
+
export function expandCronShortcut(expression) {
|
|
65
|
+
const trimmed = expression.trim().toLowerCase();
|
|
66
|
+
return CRON_SHORTCUTS[trimmed] ?? expression;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get human-readable description of cron schedule
|
|
70
|
+
*/
|
|
71
|
+
export function describeCron(expression) {
|
|
72
|
+
const expanded = expandCronShortcut(expression);
|
|
73
|
+
const parts = expanded.split(/\s+/);
|
|
74
|
+
if (parts.length < 5) {
|
|
75
|
+
return 'Invalid cron expression';
|
|
76
|
+
}
|
|
77
|
+
const [minute, hour, dayOfMonth, month, dayOfWeek] = parts;
|
|
78
|
+
// Common patterns
|
|
79
|
+
if (minute === '0' && hour === '0' && dayOfMonth === '*' && month === '*' && dayOfWeek === '*') {
|
|
80
|
+
return 'Every day at midnight';
|
|
81
|
+
}
|
|
82
|
+
if (minute === '0' && hour === '*' && dayOfMonth === '*' && month === '*' && dayOfWeek === '*') {
|
|
83
|
+
return 'Every hour';
|
|
84
|
+
}
|
|
85
|
+
if (minute === '*' && hour === '*' && dayOfMonth === '*' && month === '*' && dayOfWeek === '*') {
|
|
86
|
+
return 'Every minute';
|
|
87
|
+
}
|
|
88
|
+
return `At ${minute} ${hour} on day ${dayOfMonth} of ${month}, day of week ${dayOfWeek}`;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=cronParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronParser.js","sourceRoot":"","sources":["../../../src/infrastructure/scheduler/cronParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAkB;IACvD,IAAI,CAAC;QACH,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;QACrB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;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,UAAkB;IAC7C,MAAM,QAAQ,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAEpC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,OAAO,yBAAyB,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;IAE3D,kBAAkB;IAClB,IAAI,MAAM,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,KAAK,KAAK,GAAG,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;QAC/F,OAAO,uBAAuB,CAAC;IACjC,CAAC;IACD,IAAI,MAAM,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,KAAK,KAAK,GAAG,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;QAC/F,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,IAAI,MAAM,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,KAAK,KAAK,GAAG,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;QAC/F,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,OAAO,MAAM,MAAM,IAAI,IAAI,WAAW,UAAU,OAAO,KAAK,iBAAiB,SAAS,EAAE,CAAC;AAC3F,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cron Scheduler
|
|
3
|
+
* Manages scheduled jobs and executes them on time
|
|
4
|
+
*/
|
|
5
|
+
import { type CronJob, type CronJobInput } from '../../domain/types/cron';
|
|
6
|
+
import type { JobInput } from '../../domain/types/job';
|
|
7
|
+
/** Cron scheduler configuration */
|
|
8
|
+
export interface CronSchedulerConfig {
|
|
9
|
+
checkIntervalMs?: number;
|
|
10
|
+
}
|
|
11
|
+
/** Push job callback type */
|
|
12
|
+
export type PushJobCallback = (queue: string, input: JobInput) => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Cron Scheduler
|
|
15
|
+
* Periodically checks and executes due cron jobs
|
|
16
|
+
*/
|
|
17
|
+
export declare class CronScheduler {
|
|
18
|
+
private readonly config;
|
|
19
|
+
private readonly cronJobs;
|
|
20
|
+
private checkInterval;
|
|
21
|
+
private pushJob;
|
|
22
|
+
constructor(config?: CronSchedulerConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Set the push job callback
|
|
25
|
+
*/
|
|
26
|
+
setPushCallback(callback: PushJobCallback): void;
|
|
27
|
+
/**
|
|
28
|
+
* Start the scheduler
|
|
29
|
+
*/
|
|
30
|
+
start(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Stop the scheduler
|
|
33
|
+
*/
|
|
34
|
+
stop(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Add a cron job
|
|
37
|
+
*/
|
|
38
|
+
add(input: CronJobInput): CronJob;
|
|
39
|
+
/**
|
|
40
|
+
* Remove a cron job
|
|
41
|
+
*/
|
|
42
|
+
remove(name: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Get a cron job by name
|
|
45
|
+
*/
|
|
46
|
+
get(name: string): CronJob | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* List all cron jobs
|
|
49
|
+
*/
|
|
50
|
+
list(): CronJob[];
|
|
51
|
+
/**
|
|
52
|
+
* Load cron jobs from storage
|
|
53
|
+
*/
|
|
54
|
+
load(crons: CronJob[]): void;
|
|
55
|
+
/**
|
|
56
|
+
* Check and execute due cron jobs
|
|
57
|
+
*/
|
|
58
|
+
private tick;
|
|
59
|
+
/**
|
|
60
|
+
* Get scheduler stats
|
|
61
|
+
*/
|
|
62
|
+
getStats(): {
|
|
63
|
+
total: number;
|
|
64
|
+
pending: number;
|
|
65
|
+
nextRun: number | null;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=cronScheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronScheduler.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/scheduler/cronScheduler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,YAAY,EAA4B,MAAM,yBAAyB,CAAC;AACpG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAQvD,mCAAmC;AACnC,MAAM,WAAW,mBAAmB;IAClC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAMD,6BAA6B;AAC7B,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEhF;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;IACvD,OAAO,CAAC,aAAa,CAA+C;IACpE,OAAO,CAAC,OAAO,CAAgC;gBAEnC,MAAM,GAAE,mBAAwB;IAI5C;;OAEG;IACH,eAAe,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAIhD;;OAEG;IACH,KAAK,IAAI,IAAI;IAUb;;OAEG;IACH,IAAI,IAAI,IAAI;IAQZ;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO;IAkCjC;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAQ7B;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAItC;;OAEG;IACH,IAAI,IAAI,OAAO,EAAE;IAIjB;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI;IAO5B;;OAEG;YACW,IAAI;IA2ClB;;OAEG;IACH,QAAQ,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE;CAmBvE"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cron Scheduler
|
|
3
|
+
* Manages scheduled jobs and executes them on time
|
|
4
|
+
*/
|
|
5
|
+
import { createCronJob, isAtLimit } from '../../domain/types/cron';
|
|
6
|
+
import { validateCronExpression, getNextCronRun, getNextIntervalRun, expandCronShortcut, } from './cronParser';
|
|
7
|
+
const DEFAULT_CONFIG = {
|
|
8
|
+
checkIntervalMs: 1000,
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Cron Scheduler
|
|
12
|
+
* Periodically checks and executes due cron jobs
|
|
13
|
+
*/
|
|
14
|
+
export class CronScheduler {
|
|
15
|
+
config;
|
|
16
|
+
cronJobs = new Map();
|
|
17
|
+
checkInterval = null;
|
|
18
|
+
pushJob = null;
|
|
19
|
+
constructor(config = {}) {
|
|
20
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Set the push job callback
|
|
24
|
+
*/
|
|
25
|
+
setPushCallback(callback) {
|
|
26
|
+
this.pushJob = callback;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Start the scheduler
|
|
30
|
+
*/
|
|
31
|
+
start() {
|
|
32
|
+
if (this.checkInterval)
|
|
33
|
+
return;
|
|
34
|
+
this.checkInterval = setInterval(() => {
|
|
35
|
+
void this.tick();
|
|
36
|
+
}, this.config.checkIntervalMs);
|
|
37
|
+
console.log('[Cron] Scheduler started');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Stop the scheduler
|
|
41
|
+
*/
|
|
42
|
+
stop() {
|
|
43
|
+
if (this.checkInterval) {
|
|
44
|
+
clearInterval(this.checkInterval);
|
|
45
|
+
this.checkInterval = null;
|
|
46
|
+
}
|
|
47
|
+
console.log('[Cron] Scheduler stopped');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Add a cron job
|
|
51
|
+
*/
|
|
52
|
+
add(input) {
|
|
53
|
+
// Validate
|
|
54
|
+
if (!input.schedule && !input.repeatEvery) {
|
|
55
|
+
throw new Error('Cron job must have either schedule or repeatEvery');
|
|
56
|
+
}
|
|
57
|
+
if (input.schedule) {
|
|
58
|
+
const expanded = expandCronShortcut(input.schedule);
|
|
59
|
+
const error = validateCronExpression(expanded);
|
|
60
|
+
if (error) {
|
|
61
|
+
throw new Error(`Invalid cron expression: ${error}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Calculate next run
|
|
65
|
+
const now = Date.now();
|
|
66
|
+
let nextRun;
|
|
67
|
+
if (input.schedule) {
|
|
68
|
+
const expanded = expandCronShortcut(input.schedule);
|
|
69
|
+
nextRun = getNextCronRun(expanded, now);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
nextRun = getNextIntervalRun(input.repeatEvery, now);
|
|
73
|
+
}
|
|
74
|
+
// Create cron job
|
|
75
|
+
const cron = createCronJob(input, nextRun);
|
|
76
|
+
this.cronJobs.set(cron.name, cron);
|
|
77
|
+
console.log(`[Cron] Added job "${cron.name}" - next run: ${new Date(nextRun).toISOString()}`);
|
|
78
|
+
return cron;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Remove a cron job
|
|
82
|
+
*/
|
|
83
|
+
remove(name) {
|
|
84
|
+
const deleted = this.cronJobs.delete(name);
|
|
85
|
+
if (deleted) {
|
|
86
|
+
console.log(`[Cron] Removed job "${name}"`);
|
|
87
|
+
}
|
|
88
|
+
return deleted;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get a cron job by name
|
|
92
|
+
*/
|
|
93
|
+
get(name) {
|
|
94
|
+
return this.cronJobs.get(name);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* List all cron jobs
|
|
98
|
+
*/
|
|
99
|
+
list() {
|
|
100
|
+
return Array.from(this.cronJobs.values());
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Load cron jobs from storage
|
|
104
|
+
*/
|
|
105
|
+
load(crons) {
|
|
106
|
+
for (const cron of crons) {
|
|
107
|
+
this.cronJobs.set(cron.name, cron);
|
|
108
|
+
}
|
|
109
|
+
console.log(`[Cron] Loaded ${crons.length} jobs`);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check and execute due cron jobs
|
|
113
|
+
*/
|
|
114
|
+
async tick() {
|
|
115
|
+
if (!this.pushJob)
|
|
116
|
+
return;
|
|
117
|
+
const now = Date.now();
|
|
118
|
+
for (const [name, cron] of this.cronJobs) {
|
|
119
|
+
// Skip if not due
|
|
120
|
+
if (cron.nextRun > now)
|
|
121
|
+
continue;
|
|
122
|
+
// Skip if at limit
|
|
123
|
+
if (isAtLimit(cron)) {
|
|
124
|
+
console.log(`[Cron] Job "${name}" reached execution limit`);
|
|
125
|
+
this.cronJobs.delete(name);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
// Push the job
|
|
130
|
+
await this.pushJob(cron.queue, {
|
|
131
|
+
data: cron.data,
|
|
132
|
+
priority: cron.priority,
|
|
133
|
+
});
|
|
134
|
+
// Update execution count
|
|
135
|
+
cron.executions++;
|
|
136
|
+
// Calculate next run
|
|
137
|
+
if (cron.schedule) {
|
|
138
|
+
const expanded = expandCronShortcut(cron.schedule);
|
|
139
|
+
cron.nextRun = getNextCronRun(expanded, now);
|
|
140
|
+
}
|
|
141
|
+
else if (cron.repeatEvery) {
|
|
142
|
+
cron.nextRun = getNextIntervalRun(cron.repeatEvery, now);
|
|
143
|
+
}
|
|
144
|
+
console.log(`[Cron] Executed "${name}" (${cron.executions}x) - next: ${new Date(cron.nextRun).toISOString()}`);
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
console.error(`[Cron] Failed to execute "${name}":`, err);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get scheduler stats
|
|
153
|
+
*/
|
|
154
|
+
getStats() {
|
|
155
|
+
let nextRun = null;
|
|
156
|
+
let pending = 0;
|
|
157
|
+
for (const cron of this.cronJobs.values()) {
|
|
158
|
+
if (!isAtLimit(cron)) {
|
|
159
|
+
pending++;
|
|
160
|
+
if (nextRun === null || cron.nextRun < nextRun) {
|
|
161
|
+
nextRun = cron.nextRun;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
total: this.cronJobs.size,
|
|
167
|
+
pending,
|
|
168
|
+
nextRun,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=cronScheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronScheduler.js","sourceRoot":"","sources":["../../../src/infrastructure/scheduler/cronScheduler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAmC,aAAa,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpG,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAOtB,MAAM,cAAc,GAAkC;IACpD,eAAe,EAAE,IAAI;CACtB,CAAC;AAKF;;;GAGG;AACH,MAAM,OAAO,aAAa;IACP,MAAM,CAAgC;IACtC,QAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;IAC/C,aAAa,GAA0C,IAAI,CAAC;IAC5D,OAAO,GAA2B,IAAI,CAAC;IAE/C,YAAY,SAA8B,EAAE;QAC1C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;IACjD,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C,GAAG,CACT,oBAAoB,IAAI,MAAM,IAAI,CAAC,UAAU,cAAc,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAClG,CAAC;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,6BAA6B,IAAI,IAAI,EAAE,GAAG,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,IAAI,OAAO,GAAkB,IAAI,CAAC;QAClC,IAAI,OAAO,GAAG,CAAC,CAAC;QAEhB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC1C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,OAAO,EAAE,CAAC;gBACV,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,CAAC;oBAC/C,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;gBACzB,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;YACzB,OAAO;YACP,OAAO;SACR,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/scheduler/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/infrastructure/scheduler/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Handler Router
|
|
3
|
+
* Routes commands to appropriate handlers
|
|
4
|
+
*/
|
|
5
|
+
import type { Command } from '../../domain/types/command';
|
|
6
|
+
import type { Response } from '../../domain/types/response';
|
|
7
|
+
import type { HandlerContext } from './types';
|
|
8
|
+
export type { HandlerContext } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Main command handler - routes to specific handlers
|
|
11
|
+
*/
|
|
12
|
+
export declare function handleCommand(cmd: Command, ctx: HandlerContext): Promise<Response>;
|
|
13
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/server/handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAqE9C,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAmB9C;;GAEG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqJxF"}
|