@alextheman/utility 5.15.1 → 5.16.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.
package/dist/index.cjs CHANGED
@@ -38,6 +38,51 @@ const UUID_REGEX = new RegExp(`^${UUID_PATTERN}$`);
38
38
  const VERSION_NUMBER_PATTERN = String.raw`^(?:v)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$`;
39
39
  const VERSION_NUMBER_REGEX = RegExp(`^${VERSION_NUMBER_PATTERN}$`);
40
40
  //#endregion
41
+ //#region src/root/deprecated/APIError.ts
42
+ const httpErrorCodeLookup = {
43
+ 400: "BAD_REQUEST",
44
+ 401: "UNAUTHORISED",
45
+ 403: "FORBIDDEN",
46
+ 404: "NOT_FOUND",
47
+ 418: "I_AM_A_TEAPOT",
48
+ 500: "INTERNAL_SERVER_ERROR"
49
+ };
50
+ /**
51
+ * Represents common errors you may get from a HTTP API request.
52
+ *
53
+ * @category Types
54
+ *
55
+ * @deprecated Please use `APIError` from `@alextheman/utility/v6` instead.
56
+ */
57
+ var APIError = class APIError extends Error {
58
+ status;
59
+ /**
60
+ * @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
61
+ * @param message - An error message to display alongside the status code.
62
+ * @param options - Extra options to be passed to super Error constructor.
63
+ */
64
+ constructor(status = 500, message, options) {
65
+ super(message, options);
66
+ this.status = status;
67
+ if (message) this.message = message;
68
+ else this.message = httpErrorCodeLookup[this.status] ?? "API_ERROR";
69
+ Object.defineProperty(this, "message", { enumerable: true });
70
+ Object.setPrototypeOf(this, new.target.prototype);
71
+ }
72
+ /**
73
+ * Checks whether the given input may have been caused by an APIError.
74
+ *
75
+ * @param input - The input to check.
76
+ *
77
+ * @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
78
+ */
79
+ static check(input) {
80
+ if (input instanceof APIError) return true;
81
+ const data = input;
82
+ return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
83
+ }
84
+ };
85
+ //#endregion
41
86
  //#region src/root/functions/arrayHelpers/fillArray.ts
42
87
  /**
43
88
  * Creates a new array where each element is the result of the provided callback.
@@ -185,6 +230,17 @@ var CodeError = class CodeError extends Error {
185
230
  }
186
231
  throw new Error(`Expected a ${this.name} to be thrown but none was thrown`);
187
232
  }
233
+ /**
234
+ * Converts the `CodeError` instance to a serialised JSON payload.
235
+ *
236
+ * @returns A JSON serialised version of the current `CodeError` instance.
237
+ */
238
+ toJSON() {
239
+ return {
240
+ code: this.code,
241
+ message: this.message
242
+ };
243
+ }
188
244
  };
189
245
  //#endregion
190
246
  //#region src/v6/DataError.ts
@@ -193,14 +249,15 @@ var CodeError = class CodeError extends Error {
193
249
  *
194
250
  * @category Types
195
251
  *
196
- * @template DataType - The type of the data that caused the error.
252
+ * @template DataType The type of the data that caused the error.
253
+ * @template ErrorCode The type of the standardised error code.
197
254
  */
198
255
  var DataError$1 = class DataError$1 extends CodeError {
199
256
  data;
200
257
  /**
201
258
  * @param data - The data that caused the error.
202
259
  * @param code - A standardised code (e.g. UNEXPECTED_DATA).
203
- * @param message - A human-readable error message (e.g. The data provided is invalid).
260
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
204
261
  * @param options - Extra options to pass to super Error constructor.
205
262
  */
206
263
  constructor(data, code, message = "The data provided is invalid", options) {
@@ -220,7 +277,7 @@ var DataError$1 = class DataError$1 extends CodeError {
220
277
  */
221
278
  static check(input) {
222
279
  if (input instanceof DataError$1) return true;
223
- return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input;
280
+ return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input && typeof input.data === "object" && input.data !== null;
224
281
  }
225
282
  /**
226
283
  * Check a `DataError` against its error code
@@ -265,6 +322,17 @@ var DataError$1 = class DataError$1 extends CodeError {
265
322
  static async expectErrorAsync(errorFunction, options) {
266
323
  return await super.expectErrorAsync(errorFunction, options);
267
324
  }
325
+ /**
326
+ * Converts the `DataError` instance to a serialised JSON payload.
327
+ *
328
+ * @returns A JSON serialised version of the current `DataError` instance.
329
+ */
330
+ toJSON() {
331
+ return {
332
+ ...super.toJSON(),
333
+ data: this.data
334
+ };
335
+ }
268
336
  };
269
337
  //#endregion
270
338
  //#region src/root/functions/parsers/parseIntStrict.ts
@@ -922,49 +990,6 @@ function parseBoolean(inputString) {
922
990
  return normalisedString === "true";
923
991
  }
924
992
  //#endregion
925
- //#region src/root/types/APIError.ts
926
- const httpErrorCodeLookup = {
927
- 400: "BAD_REQUEST",
928
- 401: "UNAUTHORISED",
929
- 403: "FORBIDDEN",
930
- 404: "NOT_FOUND",
931
- 418: "I_AM_A_TEAPOT",
932
- 500: "INTERNAL_SERVER_ERROR"
933
- };
934
- /**
935
- * Represents common errors you may get from a HTTP API request.
936
- *
937
- * @category Types
938
- */
939
- var APIError = class APIError extends Error {
940
- status;
941
- /**
942
- * @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
943
- * @param message - An error message to display alongside the status code.
944
- * @param options - Extra options to be passed to super Error constructor.
945
- */
946
- constructor(status = 500, message, options) {
947
- super(message, options);
948
- this.status = status;
949
- if (message) this.message = message;
950
- else this.message = httpErrorCodeLookup[this.status] ?? "API_ERROR";
951
- Object.defineProperty(this, "message", { enumerable: true });
952
- Object.setPrototypeOf(this, new.target.prototype);
953
- }
954
- /**
955
- * Checks whether the given input may have been caused by an APIError.
956
- *
957
- * @param input - The input to check.
958
- *
959
- * @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
960
- */
961
- static check(input) {
962
- if (input instanceof APIError) return true;
963
- const data = input;
964
- return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
965
- }
966
- };
967
- //#endregion
968
993
  //#region src/root/types/VersionNumber.ts
969
994
  /**
970
995
  * Represents a software version number, considered to be made up of a major, minor, and patch part.
package/dist/index.d.cts CHANGED
@@ -16,6 +16,34 @@ declare const UUID_REGEX: RegExp;
16
16
  declare const VERSION_NUMBER_PATTERN: string;
17
17
  declare const VERSION_NUMBER_REGEX: RegExp;
18
18
  //#endregion
19
+ //#region src/root/deprecated/APIError.d.ts
20
+ type HTTPErrorCode = 400 | 401 | 403 | 404 | 418 | 500;
21
+ declare const httpErrorCodeLookup: Record<HTTPErrorCode, string>;
22
+ /**
23
+ * Represents common errors you may get from a HTTP API request.
24
+ *
25
+ * @category Types
26
+ *
27
+ * @deprecated Please use `APIError` from `@alextheman/utility/v6` instead.
28
+ */
29
+ declare class APIError extends Error {
30
+ status: number;
31
+ /**
32
+ * @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
33
+ * @param message - An error message to display alongside the status code.
34
+ * @param options - Extra options to be passed to super Error constructor.
35
+ */
36
+ constructor(status?: HTTPErrorCode | number, message?: string, options?: ErrorOptions);
37
+ /**
38
+ * Checks whether the given input may have been caused by an APIError.
39
+ *
40
+ * @param input - The input to check.
41
+ *
42
+ * @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
43
+ */
44
+ static check(input: unknown): input is APIError;
45
+ }
46
+ //#endregion
19
47
  //#region src/root/deprecated/DataError.d.ts
20
48
  interface ExpectErrorOptions$1 {
21
49
  expectedCode?: string;
@@ -84,32 +112,6 @@ declare class DataError<DataType extends Record<PropertyKey, unknown> = Record<P
84
112
  */
85
113
  type RecordKey = string | number | symbol;
86
114
  //#endregion
87
- //#region src/root/types/APIError.d.ts
88
- type HTTPErrorCode = 400 | 401 | 403 | 404 | 418 | 500;
89
- declare const httpErrorCodeLookup: Record<HTTPErrorCode, string>;
90
- /**
91
- * Represents common errors you may get from a HTTP API request.
92
- *
93
- * @category Types
94
- */
95
- declare class APIError extends Error {
96
- status: number;
97
- /**
98
- * @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
99
- * @param message - An error message to display alongside the status code.
100
- * @param options - Extra options to be passed to super Error constructor.
101
- */
102
- constructor(status?: HTTPErrorCode | number, message?: string, options?: ErrorOptions);
103
- /**
104
- * Checks whether the given input may have been caused by an APIError.
105
- *
106
- * @param input - The input to check.
107
- *
108
- * @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
109
- */
110
- static check(input: unknown): input is APIError;
111
- }
112
- //#endregion
113
115
  //#region src/root/functions/arrayHelpers/fillArray.d.ts
114
116
  /**
115
117
  * Creates a new array where each element is the resolved result of the provided asynchronous callback.
@@ -1200,6 +1202,12 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
1200
1202
  * @returns The `CodeError` that was thrown by the `errorFunction`
1201
1203
  */
1202
1204
  static expectErrorAsync<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<CodeError>;
1205
+ /**
1206
+ * Converts the `CodeError` instance to a serialised JSON payload.
1207
+ *
1208
+ * @returns A JSON serialised version of the current `CodeError` instance.
1209
+ */
1210
+ toJSON(): Omit<CodeError<ErrorCode>, "toJSON" | "name">;
1203
1211
  }
1204
1212
  //#endregion
1205
1213
  //#region src/v6/DataError.d.ts
@@ -1208,14 +1216,15 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
1208
1216
  *
1209
1217
  * @category Types
1210
1218
  *
1211
- * @template DataType - The type of the data that caused the error.
1219
+ * @template DataType The type of the data that caused the error.
1220
+ * @template ErrorCode The type of the standardised error code.
1212
1221
  */
1213
1222
  declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = string> extends CodeError<ErrorCode> {
1214
1223
  data: DataType;
1215
1224
  /**
1216
1225
  * @param data - The data that caused the error.
1217
1226
  * @param code - A standardised code (e.g. UNEXPECTED_DATA).
1218
- * @param message - A human-readable error message (e.g. The data provided is invalid).
1227
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
1219
1228
  * @param options - Extra options to pass to super Error constructor.
1220
1229
  */
1221
1230
  constructor(data: DataType, code: ErrorCode, message?: string, options?: ErrorOptions);
@@ -1264,6 +1273,12 @@ declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>
1264
1273
  * @returns The `DataError` that was thrown by the `errorFunction`
1265
1274
  */
1266
1275
  static expectErrorAsync<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = string>(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<DataError$1<DataType, ErrorCode>>;
1276
+ /**
1277
+ * Converts the `DataError` instance to a serialised JSON payload.
1278
+ *
1279
+ * @returns A JSON serialised version of the current `DataError` instance.
1280
+ */
1281
+ toJSON(): Omit<DataError$1<DataType, ErrorCode>, "toJSON" | "name">;
1267
1282
  }
1268
1283
  //#endregion
1269
1284
  //#region src/root/zod/parseZodSchema.d.ts
package/dist/index.d.ts CHANGED
@@ -16,6 +16,34 @@ declare const UUID_REGEX: RegExp;
16
16
  declare const VERSION_NUMBER_PATTERN: string;
17
17
  declare const VERSION_NUMBER_REGEX: RegExp;
18
18
  //#endregion
19
+ //#region src/root/deprecated/APIError.d.ts
20
+ type HTTPErrorCode = 400 | 401 | 403 | 404 | 418 | 500;
21
+ declare const httpErrorCodeLookup: Record<HTTPErrorCode, string>;
22
+ /**
23
+ * Represents common errors you may get from a HTTP API request.
24
+ *
25
+ * @category Types
26
+ *
27
+ * @deprecated Please use `APIError` from `@alextheman/utility/v6` instead.
28
+ */
29
+ declare class APIError extends Error {
30
+ status: number;
31
+ /**
32
+ * @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
33
+ * @param message - An error message to display alongside the status code.
34
+ * @param options - Extra options to be passed to super Error constructor.
35
+ */
36
+ constructor(status?: HTTPErrorCode | number, message?: string, options?: ErrorOptions);
37
+ /**
38
+ * Checks whether the given input may have been caused by an APIError.
39
+ *
40
+ * @param input - The input to check.
41
+ *
42
+ * @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
43
+ */
44
+ static check(input: unknown): input is APIError;
45
+ }
46
+ //#endregion
19
47
  //#region src/root/deprecated/DataError.d.ts
20
48
  interface ExpectErrorOptions$1 {
21
49
  expectedCode?: string;
@@ -84,32 +112,6 @@ declare class DataError<DataType extends Record<PropertyKey, unknown> = Record<P
84
112
  */
85
113
  type RecordKey = string | number | symbol;
86
114
  //#endregion
87
- //#region src/root/types/APIError.d.ts
88
- type HTTPErrorCode = 400 | 401 | 403 | 404 | 418 | 500;
89
- declare const httpErrorCodeLookup: Record<HTTPErrorCode, string>;
90
- /**
91
- * Represents common errors you may get from a HTTP API request.
92
- *
93
- * @category Types
94
- */
95
- declare class APIError extends Error {
96
- status: number;
97
- /**
98
- * @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
99
- * @param message - An error message to display alongside the status code.
100
- * @param options - Extra options to be passed to super Error constructor.
101
- */
102
- constructor(status?: HTTPErrorCode | number, message?: string, options?: ErrorOptions);
103
- /**
104
- * Checks whether the given input may have been caused by an APIError.
105
- *
106
- * @param input - The input to check.
107
- *
108
- * @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
109
- */
110
- static check(input: unknown): input is APIError;
111
- }
112
- //#endregion
113
115
  //#region src/root/functions/arrayHelpers/fillArray.d.ts
114
116
  /**
115
117
  * Creates a new array where each element is the resolved result of the provided asynchronous callback.
@@ -1200,6 +1202,12 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
1200
1202
  * @returns The `CodeError` that was thrown by the `errorFunction`
1201
1203
  */
1202
1204
  static expectErrorAsync<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<CodeError>;
1205
+ /**
1206
+ * Converts the `CodeError` instance to a serialised JSON payload.
1207
+ *
1208
+ * @returns A JSON serialised version of the current `CodeError` instance.
1209
+ */
1210
+ toJSON(): Omit<CodeError<ErrorCode>, "toJSON" | "name">;
1203
1211
  }
1204
1212
  //#endregion
1205
1213
  //#region src/v6/DataError.d.ts
@@ -1208,14 +1216,15 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
1208
1216
  *
1209
1217
  * @category Types
1210
1218
  *
1211
- * @template DataType - The type of the data that caused the error.
1219
+ * @template DataType The type of the data that caused the error.
1220
+ * @template ErrorCode The type of the standardised error code.
1212
1221
  */
1213
1222
  declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = string> extends CodeError<ErrorCode> {
1214
1223
  data: DataType;
1215
1224
  /**
1216
1225
  * @param data - The data that caused the error.
1217
1226
  * @param code - A standardised code (e.g. UNEXPECTED_DATA).
1218
- * @param message - A human-readable error message (e.g. The data provided is invalid).
1227
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
1219
1228
  * @param options - Extra options to pass to super Error constructor.
1220
1229
  */
1221
1230
  constructor(data: DataType, code: ErrorCode, message?: string, options?: ErrorOptions);
@@ -1264,6 +1273,12 @@ declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>
1264
1273
  * @returns The `DataError` that was thrown by the `errorFunction`
1265
1274
  */
1266
1275
  static expectErrorAsync<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = string>(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<DataError$1<DataType, ErrorCode>>;
1276
+ /**
1277
+ * Converts the `DataError` instance to a serialised JSON payload.
1278
+ *
1279
+ * @returns A JSON serialised version of the current `DataError` instance.
1280
+ */
1281
+ toJSON(): Omit<DataError$1<DataType, ErrorCode>, "toJSON" | "name">;
1267
1282
  }
1268
1283
  //#endregion
1269
1284
  //#region src/root/zod/parseZodSchema.d.ts
package/dist/index.js CHANGED
@@ -14,6 +14,51 @@ const UUID_REGEX = new RegExp(`^${UUID_PATTERN}$`);
14
14
  const VERSION_NUMBER_PATTERN = String.raw`^(?:v)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$`;
15
15
  const VERSION_NUMBER_REGEX = RegExp(`^${VERSION_NUMBER_PATTERN}$`);
16
16
  //#endregion
17
+ //#region src/root/deprecated/APIError.ts
18
+ const httpErrorCodeLookup = {
19
+ 400: "BAD_REQUEST",
20
+ 401: "UNAUTHORISED",
21
+ 403: "FORBIDDEN",
22
+ 404: "NOT_FOUND",
23
+ 418: "I_AM_A_TEAPOT",
24
+ 500: "INTERNAL_SERVER_ERROR"
25
+ };
26
+ /**
27
+ * Represents common errors you may get from a HTTP API request.
28
+ *
29
+ * @category Types
30
+ *
31
+ * @deprecated Please use `APIError` from `@alextheman/utility/v6` instead.
32
+ */
33
+ var APIError = class APIError extends Error {
34
+ status;
35
+ /**
36
+ * @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
37
+ * @param message - An error message to display alongside the status code.
38
+ * @param options - Extra options to be passed to super Error constructor.
39
+ */
40
+ constructor(status = 500, message, options) {
41
+ super(message, options);
42
+ this.status = status;
43
+ if (message) this.message = message;
44
+ else this.message = httpErrorCodeLookup[this.status] ?? "API_ERROR";
45
+ Object.defineProperty(this, "message", { enumerable: true });
46
+ Object.setPrototypeOf(this, new.target.prototype);
47
+ }
48
+ /**
49
+ * Checks whether the given input may have been caused by an APIError.
50
+ *
51
+ * @param input - The input to check.
52
+ *
53
+ * @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
54
+ */
55
+ static check(input) {
56
+ if (input instanceof APIError) return true;
57
+ const data = input;
58
+ return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
59
+ }
60
+ };
61
+ //#endregion
17
62
  //#region src/root/functions/arrayHelpers/fillArray.ts
18
63
  /**
19
64
  * Creates a new array where each element is the result of the provided callback.
@@ -161,6 +206,17 @@ var CodeError = class CodeError extends Error {
161
206
  }
162
207
  throw new Error(`Expected a ${this.name} to be thrown but none was thrown`);
163
208
  }
209
+ /**
210
+ * Converts the `CodeError` instance to a serialised JSON payload.
211
+ *
212
+ * @returns A JSON serialised version of the current `CodeError` instance.
213
+ */
214
+ toJSON() {
215
+ return {
216
+ code: this.code,
217
+ message: this.message
218
+ };
219
+ }
164
220
  };
165
221
  //#endregion
166
222
  //#region src/v6/DataError.ts
@@ -169,14 +225,15 @@ var CodeError = class CodeError extends Error {
169
225
  *
170
226
  * @category Types
171
227
  *
172
- * @template DataType - The type of the data that caused the error.
228
+ * @template DataType The type of the data that caused the error.
229
+ * @template ErrorCode The type of the standardised error code.
173
230
  */
174
231
  var DataError$1 = class DataError$1 extends CodeError {
175
232
  data;
176
233
  /**
177
234
  * @param data - The data that caused the error.
178
235
  * @param code - A standardised code (e.g. UNEXPECTED_DATA).
179
- * @param message - A human-readable error message (e.g. The data provided is invalid).
236
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
180
237
  * @param options - Extra options to pass to super Error constructor.
181
238
  */
182
239
  constructor(data, code, message = "The data provided is invalid", options) {
@@ -196,7 +253,7 @@ var DataError$1 = class DataError$1 extends CodeError {
196
253
  */
197
254
  static check(input) {
198
255
  if (input instanceof DataError$1) return true;
199
- return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input;
256
+ return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input && typeof input.data === "object" && input.data !== null;
200
257
  }
201
258
  /**
202
259
  * Check a `DataError` against its error code
@@ -241,6 +298,17 @@ var DataError$1 = class DataError$1 extends CodeError {
241
298
  static async expectErrorAsync(errorFunction, options) {
242
299
  return await super.expectErrorAsync(errorFunction, options);
243
300
  }
301
+ /**
302
+ * Converts the `DataError` instance to a serialised JSON payload.
303
+ *
304
+ * @returns A JSON serialised version of the current `DataError` instance.
305
+ */
306
+ toJSON() {
307
+ return {
308
+ ...super.toJSON(),
309
+ data: this.data
310
+ };
311
+ }
244
312
  };
245
313
  //#endregion
246
314
  //#region src/root/functions/parsers/parseIntStrict.ts
@@ -898,49 +966,6 @@ function parseBoolean(inputString) {
898
966
  return normalisedString === "true";
899
967
  }
900
968
  //#endregion
901
- //#region src/root/types/APIError.ts
902
- const httpErrorCodeLookup = {
903
- 400: "BAD_REQUEST",
904
- 401: "UNAUTHORISED",
905
- 403: "FORBIDDEN",
906
- 404: "NOT_FOUND",
907
- 418: "I_AM_A_TEAPOT",
908
- 500: "INTERNAL_SERVER_ERROR"
909
- };
910
- /**
911
- * Represents common errors you may get from a HTTP API request.
912
- *
913
- * @category Types
914
- */
915
- var APIError = class APIError extends Error {
916
- status;
917
- /**
918
- * @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
919
- * @param message - An error message to display alongside the status code.
920
- * @param options - Extra options to be passed to super Error constructor.
921
- */
922
- constructor(status = 500, message, options) {
923
- super(message, options);
924
- this.status = status;
925
- if (message) this.message = message;
926
- else this.message = httpErrorCodeLookup[this.status] ?? "API_ERROR";
927
- Object.defineProperty(this, "message", { enumerable: true });
928
- Object.setPrototypeOf(this, new.target.prototype);
929
- }
930
- /**
931
- * Checks whether the given input may have been caused by an APIError.
932
- *
933
- * @param input - The input to check.
934
- *
935
- * @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
936
- */
937
- static check(input) {
938
- if (input instanceof APIError) return true;
939
- const data = input;
940
- return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
941
- }
942
- };
943
- //#endregion
944
969
  //#region src/root/types/VersionNumber.ts
945
970
  /**
946
971
  * Represents a software version number, considered to be made up of a major, minor, and patch part.
@@ -184,6 +184,17 @@ var CodeError = class CodeError extends Error {
184
184
  }
185
185
  throw new Error(`Expected a ${this.name} to be thrown but none was thrown`);
186
186
  }
187
+ /**
188
+ * Converts the `CodeError` instance to a serialised JSON payload.
189
+ *
190
+ * @returns A JSON serialised version of the current `CodeError` instance.
191
+ */
192
+ toJSON() {
193
+ return {
194
+ code: this.code,
195
+ message: this.message
196
+ };
197
+ }
187
198
  };
188
199
  //#endregion
189
200
  //#region src/v6/DataError.ts
@@ -192,14 +203,15 @@ var CodeError = class CodeError extends Error {
192
203
  *
193
204
  * @category Types
194
205
  *
195
- * @template DataType - The type of the data that caused the error.
206
+ * @template DataType The type of the data that caused the error.
207
+ * @template ErrorCode The type of the standardised error code.
196
208
  */
197
209
  var DataError = class DataError extends CodeError {
198
210
  data;
199
211
  /**
200
212
  * @param data - The data that caused the error.
201
213
  * @param code - A standardised code (e.g. UNEXPECTED_DATA).
202
- * @param message - A human-readable error message (e.g. The data provided is invalid).
214
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
203
215
  * @param options - Extra options to pass to super Error constructor.
204
216
  */
205
217
  constructor(data, code, message = "The data provided is invalid", options) {
@@ -219,7 +231,7 @@ var DataError = class DataError extends CodeError {
219
231
  */
220
232
  static check(input) {
221
233
  if (input instanceof DataError) return true;
222
- return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input;
234
+ return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input && typeof input.data === "object" && input.data !== null;
223
235
  }
224
236
  /**
225
237
  * Check a `DataError` against its error code
@@ -264,6 +276,17 @@ var DataError = class DataError extends CodeError {
264
276
  static async expectErrorAsync(errorFunction, options) {
265
277
  return await super.expectErrorAsync(errorFunction, options);
266
278
  }
279
+ /**
280
+ * Converts the `DataError` instance to a serialised JSON payload.
281
+ *
282
+ * @returns A JSON serialised version of the current `DataError` instance.
283
+ */
284
+ toJSON() {
285
+ return {
286
+ ...super.toJSON(),
287
+ data: this.data
288
+ };
289
+ }
267
290
  };
268
291
  //#endregion
269
292
  //#region src/root/functions/parsers/parseIntStrict.ts
@@ -89,6 +89,12 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
89
89
  * @returns The `CodeError` that was thrown by the `errorFunction`
90
90
  */
91
91
  static expectErrorAsync<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<CodeError>;
92
+ /**
93
+ * Converts the `CodeError` instance to a serialised JSON payload.
94
+ *
95
+ * @returns A JSON serialised version of the current `CodeError` instance.
96
+ */
97
+ toJSON(): Omit<CodeError<ErrorCode>, "toJSON" | "name">;
92
98
  }
93
99
  //#endregion
94
100
  //#region src/v6/DataError.d.ts
@@ -97,14 +103,15 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
97
103
  *
98
104
  * @category Types
99
105
  *
100
- * @template DataType - The type of the data that caused the error.
106
+ * @template DataType The type of the data that caused the error.
107
+ * @template ErrorCode The type of the standardised error code.
101
108
  */
102
109
  declare class DataError<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = string> extends CodeError<ErrorCode> {
103
110
  data: DataType;
104
111
  /**
105
112
  * @param data - The data that caused the error.
106
113
  * @param code - A standardised code (e.g. UNEXPECTED_DATA).
107
- * @param message - A human-readable error message (e.g. The data provided is invalid).
114
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
108
115
  * @param options - Extra options to pass to super Error constructor.
109
116
  */
110
117
  constructor(data: DataType, code: ErrorCode, message?: string, options?: ErrorOptions);
@@ -153,6 +160,12 @@ declare class DataError<DataType extends object = Record<PropertyKey, unknown>,
153
160
  * @returns The `DataError` that was thrown by the `errorFunction`
154
161
  */
155
162
  static expectErrorAsync<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = string>(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<DataError<DataType, ErrorCode>>;
163
+ /**
164
+ * Converts the `DataError` instance to a serialised JSON payload.
165
+ *
166
+ * @returns A JSON serialised version of the current `DataError` instance.
167
+ */
168
+ toJSON(): Omit<DataError<DataType, ErrorCode>, "toJSON" | "name">;
156
169
  }
157
170
  //#endregion
158
171
  //#region src/internal/DependencyGroup.d.ts