@monque/core 1.4.0 → 1.5.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.
@@ -19,11 +19,15 @@ export interface ResolvedMonqueOptions
19
19
  | 'maxBackoffDelay'
20
20
  | 'jobRetention'
21
21
  | 'instanceConcurrency'
22
+ | 'maxPayloadSize'
22
23
  | 'defaultConcurrency'
23
24
  | 'maxConcurrency'
24
25
  >
25
26
  >,
26
- Pick<MonqueOptions, 'maxBackoffDelay' | 'jobRetention' | 'instanceConcurrency'> {
27
+ Pick<
28
+ MonqueOptions,
29
+ 'maxBackoffDelay' | 'jobRetention' | 'instanceConcurrency' | 'maxPayloadSize'
30
+ > {
27
31
  // Ensure resolved options use the new naming convention
28
32
  workerConcurrency: number;
29
33
  }
@@ -173,4 +173,27 @@ export interface MonqueOptions {
173
173
  * @default false
174
174
  */
175
175
  skipIndexCreation?: boolean;
176
+
177
+ /**
178
+ * Maximum allowed BSON byte size for job data payloads.
179
+ *
180
+ * When set, `enqueue()`, `now()`, and `schedule()` validate the payload size
181
+ * using `BSON.calculateObjectSize()` before insertion. Jobs exceeding this limit
182
+ * throw `PayloadTooLargeError`.
183
+ *
184
+ * When undefined, no size validation occurs.
185
+ */
186
+ maxPayloadSize?: number | undefined;
187
+
188
+ /**
189
+ * TTL in milliseconds for getQueueStats() result caching.
190
+ *
191
+ * When set to a positive value, repeated getQueueStats() calls with the same
192
+ * filter return cached results instead of re-executing the aggregation pipeline.
193
+ * Each unique filter (job name) maintains its own cache entry.
194
+ *
195
+ * Set to 0 to disable caching entirely.
196
+ * @default 5000
197
+ */
198
+ statsCacheTtlMs?: number;
176
199
  }
@@ -223,3 +223,34 @@ export class AggregationTimeoutError extends MonqueError {
223
223
  }
224
224
  }
225
225
  }
226
+
227
+ /**
228
+ * Error thrown when a job payload exceeds the configured maximum BSON byte size.
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * const monque = new Monque(db, { maxPayloadSize: 1_000_000 }); // 1 MB
233
+ *
234
+ * try {
235
+ * await monque.enqueue('job', hugePayload);
236
+ * } catch (error) {
237
+ * if (error instanceof PayloadTooLargeError) {
238
+ * console.error(`Payload ${error.actualSize} bytes exceeds limit ${error.maxSize} bytes`);
239
+ * }
240
+ * }
241
+ * ```
242
+ */
243
+ export class PayloadTooLargeError extends MonqueError {
244
+ constructor(
245
+ message: string,
246
+ public readonly actualSize: number,
247
+ public readonly maxSize: number,
248
+ ) {
249
+ super(message);
250
+ this.name = 'PayloadTooLargeError';
251
+ /* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */
252
+ if (Error.captureStackTrace) {
253
+ Error.captureStackTrace(this, PayloadTooLargeError);
254
+ }
255
+ }
256
+ }
@@ -5,6 +5,7 @@ export {
5
5
  InvalidCursorError,
6
6
  JobStateError,
7
7
  MonqueError,
8
+ PayloadTooLargeError,
8
9
  ShutdownTimeoutError,
9
10
  WorkerRegistrationError,
10
11
  } from './errors.js';