@monque/core 1.3.0 → 1.4.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/dist/CHANGELOG.md +18 -0
- package/dist/index.cjs +235 -145
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -12
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +10 -12
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +235 -145
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/jobs/document-to-persisted-job.ts +52 -0
- package/src/jobs/index.ts +2 -0
- package/src/scheduler/monque.ts +33 -91
- package/src/scheduler/services/change-stream-handler.ts +2 -1
- package/src/scheduler/services/job-manager.ts +20 -32
- package/src/scheduler/services/job-processor.ts +94 -62
- package/src/scheduler/types.ts +11 -0
- package/src/shared/index.ts +1 -0
- package/src/shared/utils/error.ts +33 -0
- package/src/shared/utils/index.ts +1 -0
package/src/shared/index.ts
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize an unknown caught value into a proper `Error` instance.
|
|
3
|
+
*
|
|
4
|
+
* In JavaScript, any value can be thrown — strings, numbers, objects, `undefined`, etc.
|
|
5
|
+
* This function ensures we always have a real `Error` with a proper stack trace and message.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The caught value (typically from a `catch` block typed as `unknown`).
|
|
8
|
+
* @returns The original value if already an `Error`, otherwise a new `Error` wrapping `String(value)`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* try {
|
|
13
|
+
* riskyOperation();
|
|
14
|
+
* } catch (error: unknown) {
|
|
15
|
+
* const normalized = toError(error);
|
|
16
|
+
* console.error(normalized.message);
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export function toError(value: unknown): Error {
|
|
23
|
+
if (value instanceof Error) return value;
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
return new Error(String(value));
|
|
27
|
+
} catch (conversionError: unknown) {
|
|
28
|
+
const detail =
|
|
29
|
+
conversionError instanceof Error ? conversionError.message : 'unknown conversion failure';
|
|
30
|
+
|
|
31
|
+
return new Error(`Unserializable value (${detail})`);
|
|
32
|
+
}
|
|
33
|
+
}
|