@ix-xs/node-comfort 1.2.0 → 2.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +340 -0
  2. package/README.md +137 -548
  3. package/index.js +80 -35
  4. package/package.json +161 -33
  5. package/src/Arr.js +1050 -418
  6. package/src/Async.js +817 -0
  7. package/src/Cache.js +433 -0
  8. package/src/Checker.js +1202 -539
  9. package/src/Cli.js +1293 -0
  10. package/src/Color.js +556 -0
  11. package/src/Crypto.js +1082 -0
  12. package/src/Emitter.js +356 -0
  13. package/src/Env.js +689 -0
  14. package/src/FS.js +1626 -894
  15. package/src/Func.js +823 -356
  16. package/src/Http.js +700 -0
  17. package/src/Id.js +568 -200
  18. package/src/Logger.js +963 -378
  19. package/src/Num.js +965 -360
  20. package/src/Obj.js +1077 -379
  21. package/src/SQLite.js +1629 -1005
  22. package/src/Schema.js +2101 -0
  23. package/src/Str.js +1209 -432
  24. package/src/Sys.js +654 -0
  25. package/src/Time.js +1533 -440
  26. package/src/Utils.js +342 -325
  27. package/src/errors.js +335 -0
  28. package/src/internal/shared.js +415 -0
  29. package/types/index.d.ts +735 -526
  30. package/types/src/Arr.d.ts +533 -145
  31. package/types/src/Arr.d.ts.map +1 -1
  32. package/types/src/Async.d.ts +372 -0
  33. package/types/src/Async.d.ts.map +1 -0
  34. package/types/src/Cache.d.ts +221 -0
  35. package/types/src/Cache.d.ts.map +1 -0
  36. package/types/src/Checker.d.ts +651 -232
  37. package/types/src/Checker.d.ts.map +1 -1
  38. package/types/src/Cli.d.ts +664 -0
  39. package/types/src/Cli.d.ts.map +1 -0
  40. package/types/src/Color.d.ts +300 -0
  41. package/types/src/Color.d.ts.map +1 -0
  42. package/types/src/Crypto.d.ts +620 -0
  43. package/types/src/Crypto.d.ts.map +1 -0
  44. package/types/src/Emitter.d.ts +189 -0
  45. package/types/src/Emitter.d.ts.map +1 -0
  46. package/types/src/Env.d.ts +412 -0
  47. package/types/src/Env.d.ts.map +1 -0
  48. package/types/src/FS.d.ts +717 -238
  49. package/types/src/FS.d.ts.map +1 -1
  50. package/types/src/Func.d.ts +508 -135
  51. package/types/src/Func.d.ts.map +1 -1
  52. package/types/src/Http.d.ts +444 -0
  53. package/types/src/Http.d.ts.map +1 -0
  54. package/types/src/Id.d.ts +199 -66
  55. package/types/src/Id.d.ts.map +1 -1
  56. package/types/src/Logger.d.ts +414 -46
  57. package/types/src/Logger.d.ts.map +1 -1
  58. package/types/src/Num.d.ts +514 -137
  59. package/types/src/Num.d.ts.map +1 -1
  60. package/types/src/Obj.d.ts +453 -104
  61. package/types/src/Obj.d.ts.map +1 -1
  62. package/types/src/SQLite.d.ts +754 -308
  63. package/types/src/SQLite.d.ts.map +1 -1
  64. package/types/src/Schema.d.ts +1189 -0
  65. package/types/src/Schema.d.ts.map +1 -0
  66. package/types/src/Str.d.ts +617 -166
  67. package/types/src/Str.d.ts.map +1 -1
  68. package/types/src/Sys.d.ts +314 -0
  69. package/types/src/Sys.d.ts.map +1 -0
  70. package/types/src/Time.d.ts +759 -204
  71. package/types/src/Time.d.ts.map +1 -1
  72. package/types/src/Utils.d.ts +158 -102
  73. package/types/src/Utils.d.ts.map +1 -1
  74. package/types/src/errors.d.ts +316 -0
  75. package/types/src/errors.d.ts.map +1 -0
  76. package/types/src/internal/shared.d.ts +123 -0
  77. package/types/src/internal/shared.d.ts.map +1 -0
  78. package/types/index.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Time.d.ts","sourceRoot":"","sources":["../../src/Time.js"],"names":[],"mappings":";;;;IA2HE;;;;;;;;;OASG;IACH,2BAHW,MAAM,GACJ,UAAU,CAKtB;IAED;;;;;;;;;OASG;IACH,+BAHW,MAAM,GAAC,SAAS,GACd,UAAU,CAKtB;IAED;;;;OAIG;IACH,sBAFa;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAC,SAAS,CAAA;KAA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ED;;;;;;;;;;;;;;;GAeG;AACH,gCANW,MAAM,GAAG,MAAM,QACf,MAAM,OAAO,YACb,YAAY,GACV,aAAa,CAoCzB;AAqDD;;;;;;;;;;;;;;;;;;GAkBG;AACH,oCALW,MAAM,YACN,WAAW,GACT,IAAI,GAAG,SAAS,CAK5B;AAED;;;;;;;;;;;;;;;GAeG;AACH,iCANW,MAAM,QACN,MAAM,OAAO,YACb,WAAW,GACT,aAAa,CAgDzB"}
@@ -1,124 +1,180 @@
1
1
  /**
2
- * Waits for a given number of milliseconds.
3
- *
4
- * @example
5
- * await nodeComfort.wait(500); // waits 500 ms
6
- *
7
- * @param {number} ms - Delay in milliseconds.
8
- * @returns {Promise<void>} A promise that resolves after the delay.
2
+ * Options for `wait()`.
9
3
  */
10
- export function wait(ms: number): Promise<void>;
4
+ export type WaitOptions = {
5
+ /**
6
+ * Cancels the wait; the promise rejects with an `AbortError`.
7
+ */
8
+ signal?: AbortSignal | undefined;
9
+ /**
10
+ * Let the process exit even if the timer is still pending.
11
+ */
12
+ unref?: boolean | undefined;
13
+ };
11
14
  /**
12
- * Polls a predicate at a given interval and emits events when it matches or times out.
13
- *
14
- * The predicate is evaluated every `options.interval` milliseconds (default: 50 ms).
15
- * Be careful with the default interval: 50 ms is very frequent polling and can be
16
- * unnecessarily CPU‑intensive if your predicate or trigger handlers are heavy.
17
- * When `options.max` is `null`, the predicate can match indefinitely (infinite triggers),
18
- * so you should choose an interval that makes sense for your use‑case.
19
- *
20
- * A `when(...)` task is one‑shot: once it has been stopped (manually or via `max`/`timeout`),
21
- * calling `.start()` again on the same task will not restart it.
22
- *
23
- * @param {boolean|Promise<boolean>|(() => boolean|Promise<boolean>)} predicate
24
- * Condition to evaluate at each tick, or a function returning it.
25
- * @param {*} [payload={}]
26
- * Value passed to listeners when events are emitted (e.g. an object or message).
27
- * @param {object} [options]
28
- * @param {number} [options.interval=50]
29
- * Polling interval in milliseconds. Increase this value if your predicate is
30
- * expensive or you expect many triggers without a `max` limit.
31
- * @param {number|null} [options.timeout=null]
32
- * Maximum time in milliseconds before emitting a "timeout" event and stopping.
33
- * If `null`, no timeout is applied.
34
- * @param {number|null} [options.max=null]
35
- * Maximum number of successful predicate evaluations ("trigger" events) before
36
- * automatically stopping. If `null`, triggers are infinite until `stop()` is called.
15
+ * Options for `when()`.
16
+ */
17
+ export type WhenOptions = {
18
+ /**
19
+ * Time between two checks, in ms or like `"1s"`. Defaults to `50`.
20
+ */
21
+ interval?: string | number | undefined;
22
+ /**
23
+ * Give up after this long, in ms or like `"10s"`, and emit `"timeout"`.
24
+ */
25
+ timeout?: string | number | null | undefined;
26
+ /**
27
+ * Stop after this many triggers.
28
+ */
29
+ max?: number | null | undefined;
30
+ };
31
+ /**
32
+ * The task returned by `when()`. Every method returns the task, so calls chain.
33
+ */
34
+ export type WhenTask = {
35
+ /**
36
+ * Starts checking. A stopped task can't be restarted.
37
+ */
38
+ start: () => WhenTask;
39
+ /**
40
+ * Stops checking and clears the timers.
41
+ */
42
+ stop: () => WhenTask;
43
+ /**
44
+ * Listens to `"trigger"` (the condition is true), `"error"` (it threw) or `"timeout"`.
45
+ */
46
+ on: <E extends "trigger" | "error" | "timeout">(event: E, handler: E extends "error" ? (error: unknown) => void : (payload: any) => void) => WhenTask;
47
+ };
48
+ /**
49
+ * Events you can customize on `dontCrash()`.
50
+ */
51
+ export type DontCrashEvent = "error" | "exit" | "sig" | "beforeExit";
52
+ /**
53
+ * Returned by `dontCrash()`.
54
+ */
55
+ export type DontCrashController = {
56
+ /**
57
+ * Replaces the handler for an event. Call it without a handler to restore the default one.
58
+ */
59
+ on: <E extends DontCrashEvent>(event: E, handler?: E extends "error" ? (error: unknown) => void : E extends "sig" ? (signal: NodeJS.Signals) => void : (code: number) => void) => DontCrashController;
60
+ /**
61
+ * Removes everything `dontCrash()` installed.
62
+ */
63
+ dispose: () => void;
64
+ };
65
+ /**
66
+ * Options for `wait()`.
67
+ * @typedef {object} WaitOptions
68
+ * @property {AbortSignal} [signal] Cancels the wait; the promise rejects with an `AbortError`.
69
+ * @property {boolean} [unref] Let the process exit even if the timer is still pending.
70
+ */
71
+ /**
72
+ * Options for `when()`.
73
+ * @typedef {object} WhenOptions
74
+ * @property {number | string} [interval] Time between two checks, in ms or like `"1s"`. Defaults to `50`.
75
+ * @property {number | string | null} [timeout] Give up after this long, in ms or like `"10s"`, and emit `"timeout"`.
76
+ * @property {number | null} [max] Stop after this many triggers.
77
+ */
78
+ /**
79
+ * The task returned by `when()`. Every method returns the task, so calls chain.
80
+ * @typedef {object} WhenTask
81
+ * @property {() => WhenTask} start Starts checking. A stopped task can't be restarted.
82
+ * @property {() => WhenTask} stop Stops checking and clears the timers.
83
+ * @property {<E extends "trigger" | "error" | "timeout">(event: E, handler: E extends "error" ? (error: unknown) => void : (payload: any) => void) => WhenTask} on Listens to `"trigger"` (the condition is true), `"error"` (it threw) or `"timeout"`.
84
+ */
85
+ /**
86
+ * Events you can customize on `dontCrash()`.
87
+ * @typedef {"error" | "exit" | "sig" | "beforeExit"} DontCrashEvent
88
+ */
89
+ /**
90
+ * Returned by `dontCrash()`.
91
+ * @typedef {object} DontCrashController
92
+ * @property {<E extends DontCrashEvent>(event: E, handler?: E extends "error" ? (error: unknown) => void : E extends "sig" ? (signal: NodeJS.Signals) => void : (code: number) => void) => DontCrashController} on Replaces the handler for an event. Call it without a handler to restore the default one.
93
+ * @property {() => void} dispose Removes everything `dontCrash()` installed.
94
+ */
95
+ /**
96
+ * Resolves after a delay, given in milliseconds or as a duration string.
37
97
  *
38
98
  * @example
39
- * // Basic usage: infinite triggers every 50 ms (default interval) – use with caution.
40
- * const task = nodeComfort.when(() => true, { message: "Ok" });
41
- *
42
- * task
43
- * .on("trigger", (payload) => {
44
- * console.log(payload.message);
45
- * // task.stop(); // stop when you’re done
46
- * })
47
- * .start();
99
+ * await nc.wait(500);
100
+ * await nc.wait("2s");
101
+ * await nc.wait("1m", { signal: controller.signal });
102
+ *
103
+ * @param {number | string} duration Milliseconds, or a string like `"250ms"`, `"2s"`, `"1m30s"`.
104
+ * @param {WaitOptions} [options]
105
+ * @returns {Promise<void>}
106
+ * @throws {AbortError} If the signal is aborted.
107
+ * @throws {TypeError} If the duration can't be parsed.
108
+ */
109
+ export function wait(duration: number | string, options?: WaitOptions): Promise<void>;
110
+ /**
111
+ * Checks a condition at a regular interval and tells you when it's true.
112
+ * Call `.start()` once your listeners are in place. If you just want to
113
+ * await a condition, `nc.async.poll()` is simpler.
48
114
  *
49
115
  * @example
50
- * // Safer usage: limit triggers and/or lower polling frequency.
51
- * nodeComfort.when(() => true, { message: "Ok" }, { max: 1, interval: 500 })
52
- * .on("trigger", (payload) => {
53
- * console.log(payload.message);
54
- * })
55
- * .on("timeout", (payload) => {
56
- * console.log("Timed out", payload);
57
- * })
116
+ * nc.when(() => queue.length > 0, { reason: "jobs waiting" }, { interval: 500, max: 1, timeout: "10s" })
117
+ * .on("trigger", (payload) => nc.info(payload.reason))
118
+ * .on("timeout", () => nc.warn("Nothing happened in 10s"))
58
119
  * .start();
59
120
  *
60
- * @returns {{
61
- * start: () => any,
62
- * stop: () => any,
63
- * on: <E extends "error"|"trigger"|"timeout">(event: E, handler: E extends "error"
64
- * ? (error: unknown) => void|Promise<void>
65
- * : (payload: any) => void|Promise<void>) => any
66
- * }} A small task controller with `start`, `stop` and `on`.
121
+ * @param {boolean | PromiseLike<boolean> | (() => unknown)} predicate The condition, or a function (sync or async) that returns it.
122
+ * @param {any} [payload={}] Passed to the `"trigger"` and `"timeout"` listeners.
123
+ * @param {WhenOptions} [options]
124
+ * @returns {WhenTask}
67
125
  */
68
- export function when(predicate: boolean | Promise<boolean> | (() => boolean | Promise<boolean>), payload?: any, options?: {
69
- interval?: number | undefined;
70
- timeout?: number | null | undefined;
71
- max?: number | null | undefined;
72
- }): {
73
- start: () => any;
74
- stop: () => any;
75
- on: <E extends "error" | "trigger" | "timeout">(event: E, handler: E extends "error" ? (error: unknown) => void | Promise<void> : (payload: any) => void | Promise<void>) => any;
76
- };
126
+ export function when(predicate: boolean | PromiseLike<boolean> | (() => unknown), payload?: any, options?: WhenOptions): WhenTask;
77
127
  /**
78
- * Installs process-level safety nets for errors, exits and signals.
79
- *
80
- * By default, it:
81
- * - logs uncaught exceptions and unhandled rejections,
82
- * - logs process exit codes,
83
- * - logs SIGINT/SIGTERM/SIGQUIT and exits with code 0.
128
+ * Keeps the process alive when something goes wrong. Uncaught exceptions and
129
+ * unhandled rejections are logged instead of crashing, and `SIGINT`/`SIGTERM`
130
+ * are logged before a clean exit. Customize any of it with `.on()`.
84
131
  *
85
- * You can override each handler with `.on(event, handler)`.
86
- *
87
- * @example
88
- * // Use defaults:
89
- * nodeComfort.dontCrash();
132
+ * Only its own handlers are ever removed; listeners added by your code or by
133
+ * other libraries are left alone.
90
134
  *
91
135
  * @example
92
- * // Custom error handler:
93
- * nodeComfort.dontCrash().on("error", (err) => {
94
- * console.error("Global error:", err);
95
- * process.exit(1);
96
- * });
97
- *
98
- * @returns {{
99
- * on: <E extends "error"|"exit"|"sig"|"beforeExit">(event: E, handler?: (
100
- * E extends "error" ? (error: Error|unknown) => void|Promise<void> :
101
- * E extends "exit" ? (code: number) => void|Promise<void> :
102
- * E extends "sig" ? (signal: "SIGINT"|"SIGTERM"|"SIGQUIT") => void|Promise<void> :
103
- * (code: number) => void|Promise<void>
104
- * )) => any
105
- * }} A small controller to configure global handlers.
136
+ * nc.dontCrash()
137
+ * .on("error", (error) => sentry.captureException(error))
138
+ * .on("sig", async () => {
139
+ * await server.close();
140
+ * process.exit(0);
141
+ * });
142
+ *
143
+ * @returns {DontCrashController}
106
144
  */
107
- export function dontCrash(): {
108
- on: <E extends "error" | "exit" | "sig" | "beforeExit">(event: E, handler?: (E extends "error" ? (error: Error | unknown) => void | Promise<void> : E extends "exit" ? (code: number) => void | Promise<void> : E extends "sig" ? (signal: "SIGINT" | "SIGTERM" | "SIGQUIT") => void | Promise<void> : (code: number) => void | Promise<void>)) => any;
109
- };
145
+ export function dontCrash(): DontCrashController;
110
146
  /**
111
- * Safely stringifies a value to pretty-printed JSON (4 spaces indent).
147
+ * `JSON.stringify` that never throws. Circular references become
148
+ * `"[Circular]"`, bigints become strings, Maps become objects, Sets become
149
+ * arrays, and errors keep their name, message and stack.
112
150
  *
113
- * @param {*} value - Value to stringify.
114
- * @returns {string} JSON string representation.
151
+ * @example
152
+ * nc.JSONString({ a: 1 }); // '{\n "a": 1\n}'
153
+ * nc.JSONString({ id: 10n, tags: new Set(["x"]) }, 0); // '{"id":"10","tags":["x"]}'
154
+ * nc.JSONString({ error: new Error("boom") }, 0); // '{"error":{"name":"Error","message":"boom","stack":"..."}}'
155
+ *
156
+ * @param {unknown} value
157
+ * @param {number} [spaces=4] Indentation. Use `0` for a single line.
158
+ * @returns {string} The JSON text, or `"undefined"` for values JSON can't represent.
115
159
  */
116
- export function JSONString(value: any): string;
160
+ export function JSONString(value: unknown, spaces?: number): string;
117
161
  /**
118
- * Parses a JSON string.
162
+ * `JSON.parse` with an optional fallback. With a fallback, invalid input
163
+ * returns it instead of throwing. A leading byte order mark, which Windows
164
+ * editors like to add, is ignored.
119
165
  *
120
- * @param {string} value - JSON string to parse.
121
- * @returns {*} Parsed value.
166
+ * @example
167
+ * nc.JSONParse('{"a":1}'); // { a: 1 }
168
+ * nc.JSONParse("oops", null); // null
169
+ * nc.JSONParse("oops"); // throws SyntaxError
170
+ * nc.JSONParse(text, {}, (key, value) => (key === "at" ? new Date(value) : value));
171
+ *
172
+ * @template [T=any]
173
+ * @param {string} text
174
+ * @param {T} [fallback] Returned when `text` isn't valid JSON.
175
+ * @param {(this: any, key: string, value: any) => any} [reviver] Passed to `JSON.parse`.
176
+ * @returns {T}
177
+ * @throws {SyntaxError} If `text` is invalid and there's no fallback.
122
178
  */
123
- export function JSONParse(value: string): any;
179
+ export function JSONParse<T = any>(text: string, fallback?: T, reviver?: (this: any, key: string, value: any) => any, ...args: any[]): T;
124
180
  //# sourceMappingURL=Utils.d.ts.map
@@ -1 +1 @@
1
-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,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,YAChD,GAAG,YACH,WAAW,GACT,QAAQ,CAuEpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,6BAFa,mBAAmB,CAoE/B;AAKD;;;;;;;;;;;;;GAaG;AACH,kCAJW,OAAO,WACP,MAAM,GACJ,MAAM,CA6BlB;AAgBD;;;;;;;;;;;;;;;;;GAiBG;AACH,0BAPc,CAAC,cACJ,MAAM,aACN,CAAC,YACD,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,mBACzC,CAAC,CAWb"}
@@ -0,0 +1,316 @@
1
+ /**
2
+ * Options shared by every error constructor.
3
+ */
4
+ export type NodeComfortErrorOptions = {
5
+ /**
6
+ * Machine-readable code, like `"ETIMEDOUT"`.
7
+ */
8
+ code?: string | undefined;
9
+ /**
10
+ * The error that caused this one, kept as `error.cause`.
11
+ */
12
+ cause?: unknown;
13
+ };
14
+ /**
15
+ * One problem found while validating data.
16
+ */
17
+ export type ValidationIssue = {
18
+ /**
19
+ * Where the problem is, like `["user", "emails", 0]`. Empty for the root value.
20
+ */
21
+ path: Array<string | number>;
22
+ /**
23
+ * What went wrong: `"invalid_type"`, `"too_small"`, `"invalid_string"`, `"custom"`...
24
+ */
25
+ code: string;
26
+ /**
27
+ * A message you can show to users.
28
+ */
29
+ message: string;
30
+ /**
31
+ * The expected type, for type errors.
32
+ */
33
+ expected?: string | undefined;
34
+ /**
35
+ * The received type, for type errors.
36
+ */
37
+ received?: string | undefined;
38
+ };
39
+ /**
40
+ * The errors node-comfort throws when something goes wrong at run time: a
41
+ * request fails, data is invalid, a command exits badly. They all extend
42
+ * `NodeComfortError` (itself a regular `Error`) and carry a stable `code`,
43
+ * so you can branch on the kind of failure without parsing messages.
44
+ *
45
+ * A mistake in your own code, like a wrong argument, still throws a plain
46
+ * `TypeError` or `RangeError`, as it does everywhere in JavaScript.
47
+ *
48
+ * @example
49
+ * try {
50
+ * await nc.http.get("https://api.example.com/users/42");
51
+ * } catch (error) {
52
+ * if (error instanceof nc.errors.HttpError && error.status === 404) return null;
53
+ * throw error;
54
+ * }
55
+ */
56
+ /**
57
+ * Options shared by every error constructor.
58
+ * @typedef {object} NodeComfortErrorOptions
59
+ * @property {string} [code] Machine-readable code, like `"ETIMEDOUT"`.
60
+ * @property {unknown} [cause] The error that caused this one, kept as `error.cause`.
61
+ */
62
+ /**
63
+ * Base class of every node-comfort error. `name` is the class name and
64
+ * `code` a stable identifier.
65
+ *
66
+ * @example
67
+ * if (error instanceof nc.errors.NodeComfortError) logger.warn(error.code);
68
+ */
69
+ export class NodeComfortError extends Error {
70
+ /**
71
+ * Makes `instanceof` work when two copies of the package are installed,
72
+ * which would otherwise give two unrelated `HttpError` classes.
73
+ *
74
+ * @override
75
+ * @param {unknown} value
76
+ * @returns {boolean}
77
+ */
78
+ static override [Symbol.hasInstance](value: unknown): boolean;
79
+ /**
80
+ * @param {string} message
81
+ * @param {NodeComfortErrorOptions} [options]
82
+ */
83
+ constructor(message: string, options?: NodeComfortErrorOptions);
84
+ /** Stable, machine-readable code. */
85
+ code: string;
86
+ /**
87
+ * What `JSON.stringify()` writes for the error: its name, code, message
88
+ * and own fields, without the stack. Handy for API responses and logs.
89
+ *
90
+ * @example
91
+ * res.status(400).json({ error });
92
+ * // {"error":{"name":"ValidationError","code":"ERR_VALIDATION","message":"...","issues":[...]}}
93
+ *
94
+ * @returns {Record<string, unknown>}
95
+ */
96
+ toJSON(): Record<string, unknown>;
97
+ }
98
+ /**
99
+ * Thrown by `nc.assert()` and `nc.assertType()`.
100
+ *
101
+ * @example
102
+ * nc.assert(user, "User is required");
103
+ */
104
+ export class AssertionError extends NodeComfortError {
105
+ /**
106
+ * @param {string} [message="Assertion failed"]
107
+ * @param {NodeComfortErrorOptions} [options]
108
+ */
109
+ constructor(message?: string, options?: NodeComfortErrorOptions);
110
+ }
111
+ /**
112
+ * Thrown when something takes too long: `func.timeout`, `async.poll`, HTTP
113
+ * requests, `emitter.waitFor`...
114
+ *
115
+ * @example
116
+ * try {
117
+ * await nc.func.timeout(slowTask(), 1000);
118
+ * } catch (error) {
119
+ * if (error instanceof nc.errors.TimeoutError) console.log(`Gave up after ${error.timeout}ms`);
120
+ * }
121
+ */
122
+ export class TimeoutError extends NodeComfortError {
123
+ /**
124
+ * @param {string} [message="Operation timed out"]
125
+ * @param {NodeComfortErrorOptions & { timeout?: number }} [options] Can include the time limit in milliseconds.
126
+ */
127
+ constructor(message?: string, options?: NodeComfortErrorOptions & {
128
+ timeout?: number;
129
+ });
130
+ /** The time limit in milliseconds, when known. */
131
+ timeout: number | undefined;
132
+ }
133
+ /**
134
+ * Thrown when an operation is cancelled with an `AbortSignal`. Its name is
135
+ * `"AbortError"`, like native abort errors, so existing checks keep working.
136
+ */
137
+ export class AbortError extends NodeComfortError {
138
+ /**
139
+ * @param {string} [message="The operation was aborted"]
140
+ * @param {NodeComfortErrorOptions} [options] Usually `{ cause: signal.reason }`.
141
+ */
142
+ constructor(message?: string, options?: NodeComfortErrorOptions);
143
+ }
144
+ /**
145
+ * One problem found while validating data.
146
+ * @typedef {object} ValidationIssue
147
+ * @property {Array<string|number>} path Where the problem is, like `["user", "emails", 0]`. Empty for the root value.
148
+ * @property {string} code What went wrong: `"invalid_type"`, `"too_small"`, `"invalid_string"`, `"custom"`...
149
+ * @property {string} message A message you can show to users.
150
+ * @property {string} [expected] The expected type, for type errors.
151
+ * @property {string} [received] The received type, for type errors.
152
+ */
153
+ /**
154
+ * Thrown when data doesn't match a schema or when environment variables are
155
+ * invalid. `issues` lists every problem, not just the first one.
156
+ *
157
+ * @example
158
+ * try {
159
+ * User.parse(body);
160
+ * } catch (error) {
161
+ * if (error instanceof nc.errors.ValidationError) return res.status(400).json(error.flatten());
162
+ * throw error;
163
+ * }
164
+ */
165
+ export class ValidationError extends NodeComfortError {
166
+ /**
167
+ * Turns issues into a readable message, one line per issue.
168
+ *
169
+ * @param {ValidationIssue[]} issues
170
+ * @returns {string}
171
+ */
172
+ static format(issues: ValidationIssue[]): string;
173
+ /**
174
+ * @param {ValidationIssue[]} issues
175
+ * @param {NodeComfortErrorOptions & { message?: string }} [options]
176
+ */
177
+ constructor(issues: ValidationIssue[], options?: NodeComfortErrorOptions & {
178
+ message?: string;
179
+ });
180
+ /** Every problem found, in order. */
181
+ issues: ValidationIssue[];
182
+ /**
183
+ * Groups messages by path, which is handy for forms.
184
+ *
185
+ * @example
186
+ * error.flatten(); // { email: ["Invalid email address"], age: ["Must be at least 18"] }
187
+ *
188
+ * @returns {Record<string, string[]>} Messages by dotted path (`""` for the root).
189
+ */
190
+ flatten(): Record<string, string[]>;
191
+ }
192
+ /**
193
+ * Thrown by `nc.http` when the response status isn't 2xx (unless you pass
194
+ * `throwHttpErrors: false`), and for network failures (`status` 0).
195
+ *
196
+ * @example
197
+ * try {
198
+ * await nc.http.get(url);
199
+ * } catch (error) {
200
+ * if (error instanceof nc.errors.HttpError) console.log(error.status, error.data);
201
+ * }
202
+ */
203
+ export class HttpError extends NodeComfortError {
204
+ /**
205
+ * @param {string} message
206
+ * @param {NodeComfortErrorOptions & { status?: number, statusText?: string, url?: string, method?: string, headers?: Record<string, string>, data?: unknown }} [options]
207
+ */
208
+ constructor(message: string, options?: NodeComfortErrorOptions & {
209
+ status?: number;
210
+ statusText?: string;
211
+ url?: string;
212
+ method?: string;
213
+ headers?: Record<string, string>;
214
+ data?: unknown;
215
+ });
216
+ /** HTTP status, like `404`. `0` when no response came back. */
217
+ status: number;
218
+ /** HTTP status text, like `"Not Found"`. */
219
+ statusText: string;
220
+ /** The requested URL. */
221
+ url: string;
222
+ /** The HTTP method, like `"GET"`. */
223
+ method: string;
224
+ /** Response headers, with lower-cased names. */
225
+ headers: Record<string, string>;
226
+ /** The response body: parsed JSON when possible, text otherwise. */
227
+ data: unknown;
228
+ }
229
+ /**
230
+ * Thrown by `nc.crypto.verifyJWT()`. The `code` tells you why:
231
+ * `ERR_JWT_MALFORMED`, `ERR_JWT_ALGORITHM`, `ERR_JWT_SIGNATURE`,
232
+ * `ERR_JWT_EXPIRED`, `ERR_JWT_NOT_BEFORE` or `ERR_JWT_CLAIM`.
233
+ *
234
+ * @example
235
+ * try {
236
+ * return nc.crypto.verifyJWT(token, secret);
237
+ * } catch (error) {
238
+ * if (error.code === "ERR_JWT_EXPIRED") return refreshSession();
239
+ * throw error;
240
+ * }
241
+ */
242
+ export class JWTError extends NodeComfortError {
243
+ /**
244
+ * @param {string} message
245
+ * @param {NodeComfortErrorOptions & { expiredAt?: Date }} [options]
246
+ */
247
+ constructor(message: string, options?: NodeComfortErrorOptions & {
248
+ expiredAt?: Date;
249
+ });
250
+ /** When the token expired. Only set for `ERR_JWT_EXPIRED`. */
251
+ expiredAt: Date | undefined;
252
+ }
253
+ /**
254
+ * Thrown by `nc.sys.run()` and `nc.sys.exec()` when a command fails, is
255
+ * killed or times out. Its output is kept on the error.
256
+ *
257
+ * @example
258
+ * try {
259
+ * await nc.sys.run("git", ["push"]);
260
+ * } catch (error) {
261
+ * console.error(error.exitCode, error.stderr);
262
+ * }
263
+ */
264
+ export class ProcessError extends NodeComfortError {
265
+ /**
266
+ * @param {string} message
267
+ * @param {NodeComfortErrorOptions & { command?: string, exitCode?: number | null, signal?: string | null, stdout?: string, stderr?: string, timedOut?: boolean }} [options]
268
+ */
269
+ constructor(message: string, options?: NodeComfortErrorOptions & {
270
+ command?: string;
271
+ exitCode?: number | null;
272
+ signal?: string | null;
273
+ stdout?: string;
274
+ stderr?: string;
275
+ timedOut?: boolean;
276
+ });
277
+ /** The command that ran. */
278
+ command: string;
279
+ /** Exit code, or `null` if a signal killed the process. */
280
+ exitCode: number | null;
281
+ /** The signal that killed the process, like `"SIGTERM"`. */
282
+ signal: string | null;
283
+ /** Everything written to stdout. */
284
+ stdout: string;
285
+ /** Everything written to stderr. */
286
+ stderr: string;
287
+ /** `true` if the process was killed for exceeding its `timeout`. */
288
+ timedOut: boolean;
289
+ }
290
+ /**
291
+ * Thrown by `nc.SQLite` when a statement fails. Check `sqliteCode` to handle
292
+ * specific cases like a duplicate value.
293
+ *
294
+ * @example
295
+ * try {
296
+ * db.insert("users", { email });
297
+ * } catch (error) {
298
+ * if (error.sqliteCode === "SQLITE_CONSTRAINT_UNIQUE") return "Email already taken";
299
+ * throw error;
300
+ * }
301
+ */
302
+ export class SQLiteError extends NodeComfortError {
303
+ /**
304
+ * @param {string} message
305
+ * @param {NodeComfortErrorOptions & { sql?: string, sqliteCode?: string }} [options]
306
+ */
307
+ constructor(message: string, options?: NodeComfortErrorOptions & {
308
+ sql?: string;
309
+ sqliteCode?: string;
310
+ });
311
+ /** The SQL that failed, when there is one. */
312
+ sql: string | undefined;
313
+ /** SQLite's error code, like `"SQLITE_CONSTRAINT_UNIQUE"`, when known. */
314
+ sqliteCode: string | undefined;
315
+ }
316
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.js"],"names":[],"mappings":";;;;;;;;;;;YAwBc,OAAO;;;;;;;;;UAkHP,KAAK,CAAC,MAAM,GAAC,MAAM,CAAC;;;;UACpB,MAAM;;;;aACN,MAAM;;;;;;;;;;AA1IpB;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;GAKG;AAEH;;;;;;GAMG;AACH;IAgCE;;;;;;;OAOG;IACH,4CAHW,OAAO,GACL,OAAO,CAOnB;IA5CD;;;OAGG;IACH,qBAHW,MAAM,YACN,uBAAuB,EAQjC;IAFC,qCAAqC;IACrC,aAA8C;IAGhD;;;;;;;;;OASG;IACH,UAFa,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASnC;CAgBF;AAED;;;;;GAKG;AACH;IACE;;;OAGG;IACH,sBAHW,MAAM,YACN,uBAAuB,EAIjC;CACF;AAED;;;;;;;;;;GAUG;AACH;IACE;;;OAGG;IACH,sBAHW,MAAM,YACN,uBAAuB,GAAG;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