@monque/core 0.3.0 → 1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monque/core",
3
- "version": "0.3.0",
3
+ "version": "1.1.0",
4
4
  "description": "MongoDB-backed job scheduler with atomic locking, exponential backoff, and cron scheduling",
5
5
  "author": "Maurice de Bruyn <debruyn.maurice@gmail.com>",
6
6
  "repository": {
@@ -14,7 +14,6 @@
14
14
  "homepage": "https://github.com/ueberBrot/monque#readme",
15
15
  "sideEffects": false,
16
16
  "type": "module",
17
- "packageManager": "bun@1.3.5",
18
17
  "engines": {
19
18
  "node": ">=22.0.0"
20
19
  },
@@ -1,155 +0,0 @@
1
-
2
- //#region src/shared/errors.ts
3
- /**
4
- * Base error class for all Monque-related errors.
5
- *
6
- * @example
7
- * ```typescript
8
- * try {
9
- * await monque.enqueue('job', data);
10
- * } catch (error) {
11
- * if (error instanceof MonqueError) {
12
- * console.error('Monque error:', error.message);
13
- * }
14
- * }
15
- * ```
16
- */
17
- var MonqueError = class MonqueError extends Error {
18
- constructor(message) {
19
- super(message);
20
- this.name = "MonqueError";
21
- /* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */
22
- if (Error.captureStackTrace) Error.captureStackTrace(this, MonqueError);
23
- }
24
- };
25
- /**
26
- * Error thrown when an invalid cron expression is provided.
27
- *
28
- * @example
29
- * ```typescript
30
- * try {
31
- * await monque.schedule('invalid cron', 'job', data);
32
- * } catch (error) {
33
- * if (error instanceof InvalidCronError) {
34
- * console.error('Invalid expression:', error.expression);
35
- * }
36
- * }
37
- * ```
38
- */
39
- var InvalidCronError = class InvalidCronError extends MonqueError {
40
- constructor(expression, message) {
41
- super(message);
42
- this.expression = expression;
43
- this.name = "InvalidCronError";
44
- /* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */
45
- if (Error.captureStackTrace) Error.captureStackTrace(this, InvalidCronError);
46
- }
47
- };
48
- /**
49
- * Error thrown when there's a database connection issue.
50
- *
51
- * @example
52
- * ```typescript
53
- * try {
54
- * await monque.enqueue('job', data);
55
- * } catch (error) {
56
- * if (error instanceof ConnectionError) {
57
- * console.error('Database connection lost');
58
- * }
59
- * }
60
- * ```
61
- */
62
- var ConnectionError = class ConnectionError extends MonqueError {
63
- constructor(message, options) {
64
- super(message);
65
- this.name = "ConnectionError";
66
- if (options?.cause) this.cause = options.cause;
67
- /* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */
68
- if (Error.captureStackTrace) Error.captureStackTrace(this, ConnectionError);
69
- }
70
- };
71
- /**
72
- * Error thrown when graceful shutdown times out.
73
- * Includes information about jobs that were still in progress.
74
- *
75
- * @example
76
- * ```typescript
77
- * try {
78
- * await monque.stop();
79
- * } catch (error) {
80
- * if (error instanceof ShutdownTimeoutError) {
81
- * console.error('Incomplete jobs:', error.incompleteJobs.length);
82
- * }
83
- * }
84
- * ```
85
- */
86
- var ShutdownTimeoutError = class ShutdownTimeoutError extends MonqueError {
87
- constructor(message, incompleteJobs) {
88
- super(message);
89
- this.incompleteJobs = incompleteJobs;
90
- this.name = "ShutdownTimeoutError";
91
- /* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */
92
- if (Error.captureStackTrace) Error.captureStackTrace(this, ShutdownTimeoutError);
93
- }
94
- };
95
- /**
96
- * Error thrown when attempting to register a worker for a job name
97
- * that already has a registered worker, without explicitly allowing replacement.
98
- *
99
- * @example
100
- * ```typescript
101
- * try {
102
- * monque.register('send-email', handler1);
103
- * monque.register('send-email', handler2); // throws
104
- * } catch (error) {
105
- * if (error instanceof WorkerRegistrationError) {
106
- * console.error('Worker already registered for:', error.jobName);
107
- * }
108
- * }
109
- *
110
- * // To intentionally replace a worker:
111
- * monque.register('send-email', handler2, { replace: true });
112
- * ```
113
- */
114
- var WorkerRegistrationError = class WorkerRegistrationError extends MonqueError {
115
- constructor(message, jobName) {
116
- super(message);
117
- this.jobName = jobName;
118
- this.name = "WorkerRegistrationError";
119
- /* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */
120
- if (Error.captureStackTrace) Error.captureStackTrace(this, WorkerRegistrationError);
121
- }
122
- };
123
-
124
- //#endregion
125
- Object.defineProperty(exports, 'ConnectionError', {
126
- enumerable: true,
127
- get: function () {
128
- return ConnectionError;
129
- }
130
- });
131
- Object.defineProperty(exports, 'InvalidCronError', {
132
- enumerable: true,
133
- get: function () {
134
- return InvalidCronError;
135
- }
136
- });
137
- Object.defineProperty(exports, 'MonqueError', {
138
- enumerable: true,
139
- get: function () {
140
- return MonqueError;
141
- }
142
- });
143
- Object.defineProperty(exports, 'ShutdownTimeoutError', {
144
- enumerable: true,
145
- get: function () {
146
- return ShutdownTimeoutError;
147
- }
148
- });
149
- Object.defineProperty(exports, 'WorkerRegistrationError', {
150
- enumerable: true,
151
- get: function () {
152
- return WorkerRegistrationError;
153
- }
154
- });
155
- //# sourceMappingURL=errors-D5ZGG2uI.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors-D5ZGG2uI.cjs","names":[],"sources":["../src/shared/errors.ts"],"sourcesContent":["import type { Job } from '@/jobs';\n\n/**\n * Base error class for all Monque-related errors.\n *\n * @example\n * ```typescript\n * try {\n * await monque.enqueue('job', data);\n * } catch (error) {\n * if (error instanceof MonqueError) {\n * console.error('Monque error:', error.message);\n * }\n * }\n * ```\n */\nexport class MonqueError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = 'MonqueError';\n\t\t// Maintains proper stack trace for where our error was thrown (only available on V8)\n\t\t/* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */\n\t\tif (Error.captureStackTrace) {\n\t\t\tError.captureStackTrace(this, MonqueError);\n\t\t}\n\t}\n}\n\n/**\n * Error thrown when an invalid cron expression is provided.\n *\n * @example\n * ```typescript\n * try {\n * await monque.schedule('invalid cron', 'job', data);\n * } catch (error) {\n * if (error instanceof InvalidCronError) {\n * console.error('Invalid expression:', error.expression);\n * }\n * }\n * ```\n */\nexport class InvalidCronError extends MonqueError {\n\tconstructor(\n\t\tpublic readonly expression: string,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'InvalidCronError';\n\t\t/* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */\n\t\tif (Error.captureStackTrace) {\n\t\t\tError.captureStackTrace(this, InvalidCronError);\n\t\t}\n\t}\n}\n\n/**\n * Error thrown when there's a database connection issue.\n *\n * @example\n * ```typescript\n * try {\n * await monque.enqueue('job', data);\n * } catch (error) {\n * if (error instanceof ConnectionError) {\n * console.error('Database connection lost');\n * }\n * }\n * ```\n */\nexport class ConnectionError extends MonqueError {\n\tconstructor(message: string, options?: { cause?: Error }) {\n\t\tsuper(message);\n\t\tthis.name = 'ConnectionError';\n\t\tif (options?.cause) {\n\t\t\tthis.cause = options.cause;\n\t\t}\n\t\t/* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */\n\t\tif (Error.captureStackTrace) {\n\t\t\tError.captureStackTrace(this, ConnectionError);\n\t\t}\n\t}\n}\n\n/**\n * Error thrown when graceful shutdown times out.\n * Includes information about jobs that were still in progress.\n *\n * @example\n * ```typescript\n * try {\n * await monque.stop();\n * } catch (error) {\n * if (error instanceof ShutdownTimeoutError) {\n * console.error('Incomplete jobs:', error.incompleteJobs.length);\n * }\n * }\n * ```\n */\nexport class ShutdownTimeoutError extends MonqueError {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly incompleteJobs: Job[],\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'ShutdownTimeoutError';\n\t\t/* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */\n\t\tif (Error.captureStackTrace) {\n\t\t\tError.captureStackTrace(this, ShutdownTimeoutError);\n\t\t}\n\t}\n}\n\n/**\n * Error thrown when attempting to register a worker for a job name\n * that already has a registered worker, without explicitly allowing replacement.\n *\n * @example\n * ```typescript\n * try {\n * monque.register('send-email', handler1);\n * monque.register('send-email', handler2); // throws\n * } catch (error) {\n * if (error instanceof WorkerRegistrationError) {\n * console.error('Worker already registered for:', error.jobName);\n * }\n * }\n *\n * // To intentionally replace a worker:\n * monque.register('send-email', handler2, { replace: true });\n * ```\n */\nexport class WorkerRegistrationError extends MonqueError {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly jobName: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'WorkerRegistrationError';\n\t\t/* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */\n\t\tif (Error.captureStackTrace) {\n\t\t\tError.captureStackTrace(this, WorkerRegistrationError);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,IAAa,cAAb,MAAa,oBAAoB,MAAM;CACtC,YAAY,SAAiB;AAC5B,QAAM,QAAQ;AACd,OAAK,OAAO;;AAGZ,MAAI,MAAM,kBACT,OAAM,kBAAkB,MAAM,YAAY;;;;;;;;;;;;;;;;;AAmB7C,IAAa,mBAAb,MAAa,yBAAyB,YAAY;CACjD,YACC,AAAgB,YAChB,SACC;AACD,QAAM,QAAQ;EAHE;AAIhB,OAAK,OAAO;;AAEZ,MAAI,MAAM,kBACT,OAAM,kBAAkB,MAAM,iBAAiB;;;;;;;;;;;;;;;;;AAmBlD,IAAa,kBAAb,MAAa,wBAAwB,YAAY;CAChD,YAAY,SAAiB,SAA6B;AACzD,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,MAAI,SAAS,MACZ,MAAK,QAAQ,QAAQ;;AAGtB,MAAI,MAAM,kBACT,OAAM,kBAAkB,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;AAoBjD,IAAa,uBAAb,MAAa,6BAA6B,YAAY;CACrD,YACC,SACA,AAAgB,gBACf;AACD,QAAM,QAAQ;EAFE;AAGhB,OAAK,OAAO;;AAEZ,MAAI,MAAM,kBACT,OAAM,kBAAkB,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;AAwBtD,IAAa,0BAAb,MAAa,gCAAgC,YAAY;CACxD,YACC,SACA,AAAgB,SACf;AACD,QAAM,QAAQ;EAFE;AAGhB,OAAK,OAAO;;AAEZ,MAAI,MAAM,kBACT,OAAM,kBAAkB,MAAM,wBAAwB"}
@@ -1,3 +0,0 @@
1
- import { a as WorkerRegistrationError, i as ShutdownTimeoutError, n as InvalidCronError, r as MonqueError, t as ConnectionError } from "./errors-DQ2_gprw.mjs";
2
-
3
- export { ShutdownTimeoutError };
@@ -1,125 +0,0 @@
1
- //#region src/shared/errors.ts
2
- /**
3
- * Base error class for all Monque-related errors.
4
- *
5
- * @example
6
- * ```typescript
7
- * try {
8
- * await monque.enqueue('job', data);
9
- * } catch (error) {
10
- * if (error instanceof MonqueError) {
11
- * console.error('Monque error:', error.message);
12
- * }
13
- * }
14
- * ```
15
- */
16
- var MonqueError = class MonqueError extends Error {
17
- constructor(message) {
18
- super(message);
19
- this.name = "MonqueError";
20
- /* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */
21
- if (Error.captureStackTrace) Error.captureStackTrace(this, MonqueError);
22
- }
23
- };
24
- /**
25
- * Error thrown when an invalid cron expression is provided.
26
- *
27
- * @example
28
- * ```typescript
29
- * try {
30
- * await monque.schedule('invalid cron', 'job', data);
31
- * } catch (error) {
32
- * if (error instanceof InvalidCronError) {
33
- * console.error('Invalid expression:', error.expression);
34
- * }
35
- * }
36
- * ```
37
- */
38
- var InvalidCronError = class InvalidCronError extends MonqueError {
39
- constructor(expression, message) {
40
- super(message);
41
- this.expression = expression;
42
- this.name = "InvalidCronError";
43
- /* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */
44
- if (Error.captureStackTrace) Error.captureStackTrace(this, InvalidCronError);
45
- }
46
- };
47
- /**
48
- * Error thrown when there's a database connection issue.
49
- *
50
- * @example
51
- * ```typescript
52
- * try {
53
- * await monque.enqueue('job', data);
54
- * } catch (error) {
55
- * if (error instanceof ConnectionError) {
56
- * console.error('Database connection lost');
57
- * }
58
- * }
59
- * ```
60
- */
61
- var ConnectionError = class ConnectionError extends MonqueError {
62
- constructor(message, options) {
63
- super(message);
64
- this.name = "ConnectionError";
65
- if (options?.cause) this.cause = options.cause;
66
- /* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */
67
- if (Error.captureStackTrace) Error.captureStackTrace(this, ConnectionError);
68
- }
69
- };
70
- /**
71
- * Error thrown when graceful shutdown times out.
72
- * Includes information about jobs that were still in progress.
73
- *
74
- * @example
75
- * ```typescript
76
- * try {
77
- * await monque.stop();
78
- * } catch (error) {
79
- * if (error instanceof ShutdownTimeoutError) {
80
- * console.error('Incomplete jobs:', error.incompleteJobs.length);
81
- * }
82
- * }
83
- * ```
84
- */
85
- var ShutdownTimeoutError = class ShutdownTimeoutError extends MonqueError {
86
- constructor(message, incompleteJobs) {
87
- super(message);
88
- this.incompleteJobs = incompleteJobs;
89
- this.name = "ShutdownTimeoutError";
90
- /* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */
91
- if (Error.captureStackTrace) Error.captureStackTrace(this, ShutdownTimeoutError);
92
- }
93
- };
94
- /**
95
- * Error thrown when attempting to register a worker for a job name
96
- * that already has a registered worker, without explicitly allowing replacement.
97
- *
98
- * @example
99
- * ```typescript
100
- * try {
101
- * monque.register('send-email', handler1);
102
- * monque.register('send-email', handler2); // throws
103
- * } catch (error) {
104
- * if (error instanceof WorkerRegistrationError) {
105
- * console.error('Worker already registered for:', error.jobName);
106
- * }
107
- * }
108
- *
109
- * // To intentionally replace a worker:
110
- * monque.register('send-email', handler2, { replace: true });
111
- * ```
112
- */
113
- var WorkerRegistrationError = class WorkerRegistrationError extends MonqueError {
114
- constructor(message, jobName) {
115
- super(message);
116
- this.jobName = jobName;
117
- this.name = "WorkerRegistrationError";
118
- /* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */
119
- if (Error.captureStackTrace) Error.captureStackTrace(this, WorkerRegistrationError);
120
- }
121
- };
122
-
123
- //#endregion
124
- export { WorkerRegistrationError as a, ShutdownTimeoutError as i, InvalidCronError as n, MonqueError as r, ConnectionError as t };
125
- //# sourceMappingURL=errors-DQ2_gprw.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors-DQ2_gprw.mjs","names":[],"sources":["../src/shared/errors.ts"],"sourcesContent":["import type { Job } from '@/jobs';\n\n/**\n * Base error class for all Monque-related errors.\n *\n * @example\n * ```typescript\n * try {\n * await monque.enqueue('job', data);\n * } catch (error) {\n * if (error instanceof MonqueError) {\n * console.error('Monque error:', error.message);\n * }\n * }\n * ```\n */\nexport class MonqueError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = 'MonqueError';\n\t\t// Maintains proper stack trace for where our error was thrown (only available on V8)\n\t\t/* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */\n\t\tif (Error.captureStackTrace) {\n\t\t\tError.captureStackTrace(this, MonqueError);\n\t\t}\n\t}\n}\n\n/**\n * Error thrown when an invalid cron expression is provided.\n *\n * @example\n * ```typescript\n * try {\n * await monque.schedule('invalid cron', 'job', data);\n * } catch (error) {\n * if (error instanceof InvalidCronError) {\n * console.error('Invalid expression:', error.expression);\n * }\n * }\n * ```\n */\nexport class InvalidCronError extends MonqueError {\n\tconstructor(\n\t\tpublic readonly expression: string,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'InvalidCronError';\n\t\t/* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */\n\t\tif (Error.captureStackTrace) {\n\t\t\tError.captureStackTrace(this, InvalidCronError);\n\t\t}\n\t}\n}\n\n/**\n * Error thrown when there's a database connection issue.\n *\n * @example\n * ```typescript\n * try {\n * await monque.enqueue('job', data);\n * } catch (error) {\n * if (error instanceof ConnectionError) {\n * console.error('Database connection lost');\n * }\n * }\n * ```\n */\nexport class ConnectionError extends MonqueError {\n\tconstructor(message: string, options?: { cause?: Error }) {\n\t\tsuper(message);\n\t\tthis.name = 'ConnectionError';\n\t\tif (options?.cause) {\n\t\t\tthis.cause = options.cause;\n\t\t}\n\t\t/* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */\n\t\tif (Error.captureStackTrace) {\n\t\t\tError.captureStackTrace(this, ConnectionError);\n\t\t}\n\t}\n}\n\n/**\n * Error thrown when graceful shutdown times out.\n * Includes information about jobs that were still in progress.\n *\n * @example\n * ```typescript\n * try {\n * await monque.stop();\n * } catch (error) {\n * if (error instanceof ShutdownTimeoutError) {\n * console.error('Incomplete jobs:', error.incompleteJobs.length);\n * }\n * }\n * ```\n */\nexport class ShutdownTimeoutError extends MonqueError {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly incompleteJobs: Job[],\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'ShutdownTimeoutError';\n\t\t/* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */\n\t\tif (Error.captureStackTrace) {\n\t\t\tError.captureStackTrace(this, ShutdownTimeoutError);\n\t\t}\n\t}\n}\n\n/**\n * Error thrown when attempting to register a worker for a job name\n * that already has a registered worker, without explicitly allowing replacement.\n *\n * @example\n * ```typescript\n * try {\n * monque.register('send-email', handler1);\n * monque.register('send-email', handler2); // throws\n * } catch (error) {\n * if (error instanceof WorkerRegistrationError) {\n * console.error('Worker already registered for:', error.jobName);\n * }\n * }\n *\n * // To intentionally replace a worker:\n * monque.register('send-email', handler2, { replace: true });\n * ```\n */\nexport class WorkerRegistrationError extends MonqueError {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly jobName: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'WorkerRegistrationError';\n\t\t/* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */\n\t\tif (Error.captureStackTrace) {\n\t\t\tError.captureStackTrace(this, WorkerRegistrationError);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,IAAa,cAAb,MAAa,oBAAoB,MAAM;CACtC,YAAY,SAAiB;AAC5B,QAAM,QAAQ;AACd,OAAK,OAAO;;AAGZ,MAAI,MAAM,kBACT,OAAM,kBAAkB,MAAM,YAAY;;;;;;;;;;;;;;;;;AAmB7C,IAAa,mBAAb,MAAa,yBAAyB,YAAY;CACjD,YACC,AAAgB,YAChB,SACC;AACD,QAAM,QAAQ;EAHE;AAIhB,OAAK,OAAO;;AAEZ,MAAI,MAAM,kBACT,OAAM,kBAAkB,MAAM,iBAAiB;;;;;;;;;;;;;;;;;AAmBlD,IAAa,kBAAb,MAAa,wBAAwB,YAAY;CAChD,YAAY,SAAiB,SAA6B;AACzD,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,MAAI,SAAS,MACZ,MAAK,QAAQ,QAAQ;;AAGtB,MAAI,MAAM,kBACT,OAAM,kBAAkB,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;AAoBjD,IAAa,uBAAb,MAAa,6BAA6B,YAAY;CACrD,YACC,SACA,AAAgB,gBACf;AACD,QAAM,QAAQ;EAFE;AAGhB,OAAK,OAAO;;AAEZ,MAAI,MAAM,kBACT,OAAM,kBAAkB,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;AAwBtD,IAAa,0BAAb,MAAa,gCAAgC,YAAY;CACxD,YACC,SACA,AAAgB,SACf;AACD,QAAM,QAAQ;EAFE;AAGhB,OAAK,OAAO;;AAEZ,MAAI,MAAM,kBACT,OAAM,kBAAkB,MAAM,wBAAwB"}
@@ -1,3 +0,0 @@
1
- const require_errors = require('./errors-D5ZGG2uI.cjs');
2
-
3
- exports.ShutdownTimeoutError = require_errors.ShutdownTimeoutError;