@catbee/utils 0.0.1 → 0.0.2

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 (197) hide show
  1. package/README.md +303 -107
  2. package/build/esm/config.d.ts +12 -0
  3. package/build/esm/config.js +12 -0
  4. package/build/esm/config.js.map +1 -1
  5. package/build/esm/index.d.ts +1 -0
  6. package/build/esm/index.js +1 -0
  7. package/build/esm/index.js.map +1 -1
  8. package/build/esm/types/api-response.d.ts +82 -0
  9. package/build/esm/types/api-response.js.map +1 -1
  10. package/build/esm/utils/array.utils.d.ts +64 -1
  11. package/build/esm/utils/array.utils.js +139 -2
  12. package/build/esm/utils/array.utils.js.map +1 -1
  13. package/build/esm/utils/async.utils.d.ts +60 -1
  14. package/build/esm/utils/async.utils.js +160 -2
  15. package/build/esm/utils/async.utils.js.map +1 -1
  16. package/build/esm/utils/cache.utils.d.ts +67 -4
  17. package/build/esm/utils/cache.utils.js +210 -28
  18. package/build/esm/utils/cache.utils.js.map +1 -1
  19. package/build/esm/utils/context-store.utils.d.ts +101 -0
  20. package/build/esm/utils/context-store.utils.js +182 -0
  21. package/build/esm/utils/context-store.utils.js.map +1 -1
  22. package/build/esm/utils/crypto.utils.d.ts +110 -8
  23. package/build/esm/utils/crypto.utils.js +298 -15
  24. package/build/esm/utils/crypto.utils.js.map +1 -1
  25. package/build/esm/utils/decorators.utils.d.ts +40 -0
  26. package/build/esm/utils/decorators.utils.js +312 -0
  27. package/build/esm/utils/decorators.utils.js.map +1 -0
  28. package/build/esm/utils/dir.utils.d.ts +121 -0
  29. package/build/esm/utils/dir.utils.js +577 -0
  30. package/build/esm/utils/dir.utils.js.map +1 -1
  31. package/build/esm/utils/env.utils.d.ts +83 -0
  32. package/build/esm/utils/env.utils.js +233 -0
  33. package/build/esm/utils/env.utils.js.map +1 -1
  34. package/build/esm/utils/exception.utils.d.ts +116 -0
  35. package/build/esm/utils/exception.utils.js +322 -0
  36. package/build/esm/utils/exception.utils.js.map +1 -1
  37. package/build/esm/utils/fs.utils.d.ts +132 -0
  38. package/build/esm/utils/fs.utils.js +421 -0
  39. package/build/esm/utils/fs.utils.js.map +1 -1
  40. package/build/esm/utils/http-status-codes.d.ts +87 -178
  41. package/build/esm/utils/http-status-codes.js +92 -178
  42. package/build/esm/utils/http-status-codes.js.map +1 -1
  43. package/build/esm/utils/id.utils.d.ts +11 -10
  44. package/build/esm/utils/id.utils.js +29 -20
  45. package/build/esm/utils/id.utils.js.map +1 -1
  46. package/build/esm/utils/logger.utils.d.ts +24 -0
  47. package/build/esm/utils/logger.utils.js +54 -0
  48. package/build/esm/utils/logger.utils.js.map +1 -1
  49. package/build/esm/utils/middleware.utils.d.ts +72 -0
  50. package/build/esm/utils/middleware.utils.js +158 -0
  51. package/build/esm/utils/middleware.utils.js.map +1 -0
  52. package/build/esm/utils/obj.utils.d.ts +65 -3
  53. package/build/esm/utils/obj.utils.js +205 -6
  54. package/build/esm/utils/obj.utils.js.map +1 -1
  55. package/build/esm/utils/response.utils.d.ts +101 -0
  56. package/build/esm/utils/response.utils.js +153 -0
  57. package/build/esm/utils/response.utils.js.map +1 -1
  58. package/build/esm/utils/string.utils.d.ts +61 -5
  59. package/build/esm/utils/string.utils.js +101 -11
  60. package/build/esm/utils/string.utils.js.map +1 -1
  61. package/build/esm/utils/url.utils.d.ts +117 -0
  62. package/build/esm/utils/url.utils.js +287 -0
  63. package/build/esm/utils/url.utils.js.map +1 -1
  64. package/build/esm/utils/validate.utils.d.ts +110 -0
  65. package/build/esm/utils/validate.utils.js +186 -0
  66. package/build/esm/utils/validate.utils.js.map +1 -1
  67. package/build/esnext/config.d.ts +12 -0
  68. package/build/esnext/config.js +12 -0
  69. package/build/esnext/config.js.map +1 -1
  70. package/build/esnext/index.d.ts +1 -0
  71. package/build/esnext/index.js +1 -0
  72. package/build/esnext/index.js.map +1 -1
  73. package/build/esnext/types/api-response.d.ts +82 -0
  74. package/build/esnext/types/api-response.js.map +1 -1
  75. package/build/esnext/utils/array.utils.d.ts +64 -1
  76. package/build/esnext/utils/array.utils.js +129 -2
  77. package/build/esnext/utils/array.utils.js.map +1 -1
  78. package/build/esnext/utils/async.utils.d.ts +60 -1
  79. package/build/esnext/utils/async.utils.js +117 -1
  80. package/build/esnext/utils/async.utils.js.map +1 -1
  81. package/build/esnext/utils/cache.utils.d.ts +67 -4
  82. package/build/esnext/utils/cache.utils.js +137 -9
  83. package/build/esnext/utils/cache.utils.js.map +1 -1
  84. package/build/esnext/utils/context-store.utils.d.ts +101 -0
  85. package/build/esnext/utils/context-store.utils.js +168 -0
  86. package/build/esnext/utils/context-store.utils.js.map +1 -1
  87. package/build/esnext/utils/crypto.utils.d.ts +110 -8
  88. package/build/esnext/utils/crypto.utils.js +205 -15
  89. package/build/esnext/utils/crypto.utils.js.map +1 -1
  90. package/build/esnext/utils/decorators.utils.d.ts +40 -0
  91. package/build/esnext/utils/decorators.utils.js +155 -0
  92. package/build/esnext/utils/decorators.utils.js.map +1 -0
  93. package/build/esnext/utils/dir.utils.d.ts +121 -0
  94. package/build/esnext/utils/dir.utils.js +306 -0
  95. package/build/esnext/utils/dir.utils.js.map +1 -1
  96. package/build/esnext/utils/env.utils.d.ts +83 -0
  97. package/build/esnext/utils/env.utils.js +185 -0
  98. package/build/esnext/utils/env.utils.js.map +1 -1
  99. package/build/esnext/utils/exception.utils.d.ts +116 -0
  100. package/build/esnext/utils/exception.utils.js +213 -0
  101. package/build/esnext/utils/exception.utils.js.map +1 -1
  102. package/build/esnext/utils/fs.utils.d.ts +132 -0
  103. package/build/esnext/utils/fs.utils.js +268 -0
  104. package/build/esnext/utils/fs.utils.js.map +1 -1
  105. package/build/esnext/utils/http-status-codes.d.ts +87 -178
  106. package/build/esnext/utils/http-status-codes.js +92 -178
  107. package/build/esnext/utils/http-status-codes.js.map +1 -1
  108. package/build/esnext/utils/id.utils.d.ts +11 -10
  109. package/build/esnext/utils/id.utils.js +27 -19
  110. package/build/esnext/utils/id.utils.js.map +1 -1
  111. package/build/esnext/utils/logger.utils.d.ts +24 -0
  112. package/build/esnext/utils/logger.utils.js +42 -0
  113. package/build/esnext/utils/logger.utils.js.map +1 -1
  114. package/build/esnext/utils/middleware.utils.d.ts +72 -0
  115. package/build/esnext/utils/middleware.utils.js +157 -0
  116. package/build/esnext/utils/middleware.utils.js.map +1 -0
  117. package/build/esnext/utils/obj.utils.d.ts +65 -3
  118. package/build/esnext/utils/obj.utils.js +167 -3
  119. package/build/esnext/utils/obj.utils.js.map +1 -1
  120. package/build/esnext/utils/response.utils.d.ts +101 -0
  121. package/build/esnext/utils/response.utils.js +138 -0
  122. package/build/esnext/utils/response.utils.js.map +1 -1
  123. package/build/esnext/utils/string.utils.d.ts +61 -5
  124. package/build/esnext/utils/string.utils.js +110 -14
  125. package/build/esnext/utils/string.utils.js.map +1 -1
  126. package/build/esnext/utils/url.utils.d.ts +117 -0
  127. package/build/esnext/utils/url.utils.js +248 -0
  128. package/build/esnext/utils/url.utils.js.map +1 -1
  129. package/build/esnext/utils/validate.utils.d.ts +110 -0
  130. package/build/esnext/utils/validate.utils.js +184 -0
  131. package/build/esnext/utils/validate.utils.js.map +1 -1
  132. package/build/src/config.d.ts +12 -0
  133. package/build/src/config.js +12 -0
  134. package/build/src/config.js.map +1 -1
  135. package/build/src/index.d.ts +1 -0
  136. package/build/src/index.js +1 -0
  137. package/build/src/index.js.map +1 -1
  138. package/build/src/types/api-response.d.ts +82 -0
  139. package/build/src/types/api-response.js.map +1 -1
  140. package/build/src/utils/array.utils.d.ts +64 -1
  141. package/build/src/utils/array.utils.js +137 -4
  142. package/build/src/utils/array.utils.js.map +1 -1
  143. package/build/src/utils/async.utils.d.ts +60 -1
  144. package/build/src/utils/async.utils.js +124 -4
  145. package/build/src/utils/async.utils.js.map +1 -1
  146. package/build/src/utils/cache.utils.d.ts +67 -4
  147. package/build/src/utils/cache.utils.js +137 -9
  148. package/build/src/utils/cache.utils.js.map +1 -1
  149. package/build/src/utils/context-store.utils.d.ts +101 -0
  150. package/build/src/utils/context-store.utils.js +171 -1
  151. package/build/src/utils/context-store.utils.js.map +1 -1
  152. package/build/src/utils/crypto.utils.d.ts +110 -8
  153. package/build/src/utils/crypto.utils.js +224 -27
  154. package/build/src/utils/crypto.utils.js.map +1 -1
  155. package/build/src/utils/decorators.utils.d.ts +40 -0
  156. package/build/src/utils/decorators.utils.js +165 -0
  157. package/build/src/utils/decorators.utils.js.map +1 -0
  158. package/build/src/utils/dir.utils.d.ts +121 -0
  159. package/build/src/utils/dir.utils.js +316 -0
  160. package/build/src/utils/dir.utils.js.map +1 -1
  161. package/build/src/utils/env.utils.d.ts +83 -0
  162. package/build/src/utils/env.utils.js +186 -1
  163. package/build/src/utils/env.utils.js.map +1 -1
  164. package/build/src/utils/exception.utils.d.ts +116 -0
  165. package/build/src/utils/exception.utils.js +226 -1
  166. package/build/src/utils/exception.utils.js.map +1 -1
  167. package/build/src/utils/fs.utils.d.ts +132 -0
  168. package/build/src/utils/fs.utils.js +282 -0
  169. package/build/src/utils/fs.utils.js.map +1 -1
  170. package/build/src/utils/http-status-codes.d.ts +87 -178
  171. package/build/src/utils/http-status-codes.js +92 -178
  172. package/build/src/utils/http-status-codes.js.map +1 -1
  173. package/build/src/utils/id.utils.d.ts +11 -10
  174. package/build/src/utils/id.utils.js +27 -19
  175. package/build/src/utils/id.utils.js.map +1 -1
  176. package/build/src/utils/logger.utils.d.ts +24 -0
  177. package/build/src/utils/logger.utils.js +45 -0
  178. package/build/src/utils/logger.utils.js.map +1 -1
  179. package/build/src/utils/middleware.utils.d.ts +72 -0
  180. package/build/src/utils/middleware.utils.js +163 -0
  181. package/build/src/utils/middleware.utils.js.map +1 -0
  182. package/build/src/utils/obj.utils.d.ts +65 -3
  183. package/build/src/utils/obj.utils.js +177 -7
  184. package/build/src/utils/obj.utils.js.map +1 -1
  185. package/build/src/utils/response.utils.d.ts +101 -0
  186. package/build/src/utils/response.utils.js +146 -1
  187. package/build/src/utils/response.utils.js.map +1 -1
  188. package/build/src/utils/string.utils.d.ts +61 -5
  189. package/build/src/utils/string.utils.js +122 -20
  190. package/build/src/utils/string.utils.js.map +1 -1
  191. package/build/src/utils/url.utils.d.ts +117 -0
  192. package/build/src/utils/url.utils.js +257 -0
  193. package/build/src/utils/url.utils.js.map +1 -1
  194. package/build/src/utils/validate.utils.d.ts +110 -0
  195. package/build/src/utils/validate.utils.js +198 -0
  196. package/build/src/utils/validate.utils.js.map +1 -1
  197. package/package.json +20 -12
@@ -13,7 +13,69 @@ var __extends = (this && this.__extends) || (function () {
13
13
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
14
  };
15
15
  })();
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
27
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ var __read = (this && this.__read) || function (o, n) {
53
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
54
+ if (!m) return o;
55
+ var i = m.call(o), r, ar = [], e;
56
+ try {
57
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
58
+ }
59
+ catch (error) { e = { error: error }; }
60
+ finally {
61
+ try {
62
+ if (r && !r.done && (m = i["return"])) m.call(i);
63
+ }
64
+ finally { if (e) throw e.error; }
65
+ }
66
+ return ar;
67
+ };
68
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
69
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
70
+ if (ar || !(i in from)) {
71
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
72
+ ar[i] = from[i];
73
+ }
74
+ }
75
+ return to.concat(ar || Array.prototype.slice.call(from));
76
+ };
16
77
  import { HttpStatusCodes } from "./http-status-codes";
78
+ import { getLogger } from "./logger.utils";
17
79
  import { ErrorResponse } from "./response.utils";
18
80
  /**
19
81
  * Generic HTTP error class used for custom exceptions with any status code.
@@ -214,4 +276,264 @@ var GatewayTimeoutException = /** @class */ (function (_super) {
214
276
  return GatewayTimeoutException;
215
277
  }(ErrorResponse));
216
278
  export { GatewayTimeoutException };
279
+ /**
280
+ * Represents a 422 Unprocessable Entity Error.
281
+ * Used when the server understands the content type but cannot process the contained instructions.
282
+ */
283
+ var UnprocessableEntityException = /** @class */ (function (_super) {
284
+ __extends(UnprocessableEntityException, _super);
285
+ /**
286
+ * @param message - Optional custom message. Defaults to "Unprocessable Entity".
287
+ * @param details - Optional validation details or additional error context.
288
+ */
289
+ function UnprocessableEntityException(message, details) {
290
+ if (message === void 0) { message = "Unprocessable Entity"; }
291
+ var _this = _super.call(this, message) || this;
292
+ _this.details = details;
293
+ _this.status = HttpStatusCodes.UNPROCESSABLE_ENTITY;
294
+ return _this;
295
+ }
296
+ return UnprocessableEntityException;
297
+ }(ErrorResponse));
298
+ export { UnprocessableEntityException };
299
+ /**
300
+ * Represents a 405 Method Not Allowed Error.
301
+ * Used when the request method is not supported for the requested resource.
302
+ */
303
+ var MethodNotAllowedException = /** @class */ (function (_super) {
304
+ __extends(MethodNotAllowedException, _super);
305
+ /**
306
+ * @param message - Optional custom message. Defaults to "Method Not Allowed".
307
+ * @param allowedMethods - Optional array of allowed HTTP methods.
308
+ */
309
+ function MethodNotAllowedException(message, allowedMethods) {
310
+ if (message === void 0) { message = "Method Not Allowed"; }
311
+ var _this = _super.call(this, message) || this;
312
+ _this.allowedMethods = allowedMethods;
313
+ _this.status = HttpStatusCodes.METHOD_NOT_ALLOWED;
314
+ return _this;
315
+ }
316
+ return MethodNotAllowedException;
317
+ }(ErrorResponse));
318
+ export { MethodNotAllowedException };
319
+ /**
320
+ * Represents a 406 Not Acceptable Error.
321
+ * Used when the server cannot produce a response matching the client's accepted content types.
322
+ */
323
+ var NotAcceptableException = /** @class */ (function (_super) {
324
+ __extends(NotAcceptableException, _super);
325
+ /**
326
+ * @param message - Optional custom message. Defaults to "Not Acceptable".
327
+ */
328
+ function NotAcceptableException(message) {
329
+ if (message === void 0) { message = "Not Acceptable"; }
330
+ var _this = _super.call(this, message) || this;
331
+ _this.status = HttpStatusCodes.NOT_ACCEPTABLE;
332
+ return _this;
333
+ }
334
+ return NotAcceptableException;
335
+ }(ErrorResponse));
336
+ export { NotAcceptableException };
337
+ /**
338
+ * Represents a 408 Request Timeout Error.
339
+ * Used when the server times out waiting for the client to send a request.
340
+ */
341
+ var RequestTimeoutException = /** @class */ (function (_super) {
342
+ __extends(RequestTimeoutException, _super);
343
+ /**
344
+ * @param message - Optional custom message. Defaults to "Request Timeout".
345
+ */
346
+ function RequestTimeoutException(message) {
347
+ if (message === void 0) { message = "Request Timeout"; }
348
+ var _this = _super.call(this, message) || this;
349
+ _this.status = HttpStatusCodes.REQUEST_TIMEOUT;
350
+ return _this;
351
+ }
352
+ return RequestTimeoutException;
353
+ }(ErrorResponse));
354
+ export { RequestTimeoutException };
355
+ /**
356
+ * Represents a 415 Unsupported Media Type Error.
357
+ * Used when the request's Content-Type is not supported.
358
+ */
359
+ var UnsupportedMediaTypeException = /** @class */ (function (_super) {
360
+ __extends(UnsupportedMediaTypeException, _super);
361
+ /**
362
+ * @param message - Optional custom message. Defaults to "Unsupported Media Type".
363
+ */
364
+ function UnsupportedMediaTypeException(message) {
365
+ if (message === void 0) { message = "Unsupported Media Type"; }
366
+ var _this = _super.call(this, message) || this;
367
+ _this.status = HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE;
368
+ return _this;
369
+ }
370
+ return UnsupportedMediaTypeException;
371
+ }(ErrorResponse));
372
+ export { UnsupportedMediaTypeException };
373
+ /**
374
+ * Represents a 413 Payload Too Large Error.
375
+ * Used when the request body exceeds server limits.
376
+ */
377
+ var PayloadTooLargeException = /** @class */ (function (_super) {
378
+ __extends(PayloadTooLargeException, _super);
379
+ /**
380
+ * @param message - Optional custom message. Defaults to "Payload Too Large".
381
+ */
382
+ function PayloadTooLargeException(message) {
383
+ if (message === void 0) { message = "Payload Too Large"; }
384
+ var _this = _super.call(this, message) || this;
385
+ _this.status = HttpStatusCodes.PAYLOAD_TOO_LARGE;
386
+ return _this;
387
+ }
388
+ return PayloadTooLargeException;
389
+ }(ErrorResponse));
390
+ export { PayloadTooLargeException };
391
+ /**
392
+ * Represents a 507 Insufficient Storage Error.
393
+ * Used when the server has insufficient storage to complete the request.
394
+ */
395
+ var InsufficientStorageException = /** @class */ (function (_super) {
396
+ __extends(InsufficientStorageException, _super);
397
+ /**
398
+ * @param message - Optional custom message. Defaults to "Insufficient Storage".
399
+ */
400
+ function InsufficientStorageException(message) {
401
+ if (message === void 0) { message = "Insufficient Storage"; }
402
+ var _this = _super.call(this, message) || this;
403
+ _this.status = HttpStatusCodes.INSUFFICIENT_STORAGE;
404
+ return _this;
405
+ }
406
+ return InsufficientStorageException;
407
+ }(ErrorResponse));
408
+ export { InsufficientStorageException };
409
+ /**
410
+ * Checks if an error is an instance of HttpError or its subclasses.
411
+ *
412
+ * @param error - The error to check.
413
+ * @returns True if the error is an HttpError, false otherwise.
414
+ */
415
+ export function isHttpError(error) {
416
+ return error instanceof ErrorResponse;
417
+ }
418
+ /**
419
+ * Creates an HTTP error with the specified status code and message.
420
+ * Factory function for creating appropriate HTTP error instances.
421
+ *
422
+ * @param status - HTTP status code.
423
+ * @param message - Optional custom error message.
424
+ * @returns An instance of the appropriate HTTP error class.
425
+ */
426
+ export function createHttpError(status, message) {
427
+ switch (status) {
428
+ case HttpStatusCodes.BAD_REQUEST:
429
+ return new BadRequestException(message);
430
+ case HttpStatusCodes.UNAUTHORIZED:
431
+ return new UnauthorizedException(message);
432
+ case HttpStatusCodes.FORBIDDEN:
433
+ return new ForbiddenException(message);
434
+ case HttpStatusCodes.NOT_FOUND:
435
+ return new NotFoundException(message);
436
+ case HttpStatusCodes.METHOD_NOT_ALLOWED:
437
+ return new MethodNotAllowedException(message);
438
+ case HttpStatusCodes.NOT_ACCEPTABLE:
439
+ return new NotAcceptableException(message);
440
+ case HttpStatusCodes.REQUEST_TIMEOUT:
441
+ return new RequestTimeoutException(message);
442
+ case HttpStatusCodes.CONFLICT:
443
+ return new ConflictException(message);
444
+ case HttpStatusCodes.GONE:
445
+ return new HttpError(HttpStatusCodes.GONE, message || "Gone");
446
+ case HttpStatusCodes.PAYLOAD_TOO_LARGE:
447
+ return new PayloadTooLargeException(message);
448
+ case HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE:
449
+ return new UnsupportedMediaTypeException(message);
450
+ case HttpStatusCodes.UNPROCESSABLE_ENTITY:
451
+ return new UnprocessableEntityException(message);
452
+ case HttpStatusCodes.TOO_MANY_REQUESTS:
453
+ return new TooManyRequestsException(message);
454
+ case HttpStatusCodes.INTERNAL_SERVER_ERROR:
455
+ return new InternalServerErrorException(message);
456
+ case HttpStatusCodes.BAD_GATEWAY:
457
+ return new BadGatewayException(message);
458
+ case HttpStatusCodes.SERVICE_UNAVAILABLE:
459
+ return new ServiceUnavailableException(message);
460
+ case HttpStatusCodes.GATEWAY_TIMEOUT:
461
+ return new GatewayTimeoutException(message);
462
+ case HttpStatusCodes.INSUFFICIENT_STORAGE:
463
+ return new InsufficientStorageException(message);
464
+ default:
465
+ return new HttpError(status, message || "HTTP Error ".concat(status));
466
+ }
467
+ }
468
+ /**
469
+ * Type guard to check if an object has specific error properties.
470
+ *
471
+ * @param error - The object to check.
472
+ * @returns True if object has error-like structure.
473
+ */
474
+ export function hasErrorShape(error) {
475
+ return (typeof error === "object" &&
476
+ error !== null &&
477
+ "message" in error &&
478
+ typeof error.message === "string");
479
+ }
480
+ /**
481
+ * Safely extracts message from any error type.
482
+ *
483
+ * @param error - Any error object or value.
484
+ * @returns A string error message.
485
+ */
486
+ export function getErrorMessage(error) {
487
+ if (typeof error === "string") {
488
+ return error;
489
+ }
490
+ if (error instanceof Error) {
491
+ return error.message;
492
+ }
493
+ if (hasErrorShape(error)) {
494
+ return error.message;
495
+ }
496
+ return "Unknown error occurred";
497
+ }
498
+ /**
499
+ * Wraps a function and transforms any errors into HTTP errors.
500
+ * Useful for API handlers to ensure consistent error responses.
501
+ *
502
+ * @param handler - The async function to wrap.
503
+ * @returns A function that always returns or throws an HTTP error.
504
+ */
505
+ export function withErrorHandling(handler) {
506
+ var _this = this;
507
+ return function () {
508
+ var args = [];
509
+ for (var _i = 0; _i < arguments.length; _i++) {
510
+ args[_i] = arguments[_i];
511
+ }
512
+ return __awaiter(_this, void 0, void 0, function () {
513
+ var error_1, status_1;
514
+ return __generator(this, function (_a) {
515
+ switch (_a.label) {
516
+ case 0:
517
+ _a.trys.push([0, 2, , 3]);
518
+ return [4 /*yield*/, handler.apply(void 0, __spreadArray([], __read(args), false))];
519
+ case 1: return [2 /*return*/, _a.sent()];
520
+ case 2:
521
+ error_1 = _a.sent();
522
+ if (isHttpError(error_1)) {
523
+ throw error_1;
524
+ }
525
+ // Log the original error (consider using a proper logger)
526
+ getLogger().error("Caught error in handler:", error_1);
527
+ status_1 = HttpStatusCodes.INTERNAL_SERVER_ERROR;
528
+ if (hasErrorShape(error_1) && typeof error_1.status === "number") {
529
+ status_1 = error_1.status;
530
+ }
531
+ // Create appropriate HTTP error
532
+ throw createHttpError(status_1, getErrorMessage(error_1));
533
+ case 3: return [2 /*return*/];
534
+ }
535
+ });
536
+ });
537
+ };
538
+ }
217
539
  //# sourceMappingURL=exception.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"exception.utils.js","sourceRoot":"","sources":["../../../src/utils/exception.utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;GAGG;AACH;IAA+B,6BAAa;IAC1C;;;;OAIG;IACH,mBAAY,MAAc,EAAE,OAAe;QACzC,YAAA,MAAK,YAAC,OAAO,CAAC,SAAC;QACf,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;;IACv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AAK,YAAC,OAAO,CAAC,SAAC;QACf,KAAI,CAAC,MAAM,GAAG,eAAe,CAAC,eAAe,CAAC;;IAChD,CAAC;IACH,8BAAC;AAAD,CAAC,AARD,CAA6C,aAAa,GAQzD","sourcesContent":["import { HttpStatusCodes } from \"./http-status-codes\";\nimport { ErrorResponse } from \"./response.utils\";\n\n/**\n * Generic HTTP error class used for custom exceptions with any status code.\n * Inherit this when you need to throw errors dynamically at runtime.\n */\nexport class HttpError extends ErrorResponse {\n /**\n * Creates a new HTTP error instance.\n * @param status - A valid HTTP status code (e.g., 400, 500).\n * @param message - The error message to return to the client.\n */\n constructor(status: number, message: string) {\n super(message);\n this.status = status;\n }\n}\n\n/**\n * Represents a 500 Internal Server Error.\n * Use this for unexpected backend errors that are not caused by the client.\n */\nexport class InternalServerErrorException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Internal server error\".\n */\n constructor(message: string = \"Internal server error\") {\n super(message);\n this.status = HttpStatusCodes.INTERNAL_SERVER_ERROR;\n }\n}\n\n/**\n * Represents a 401 Unauthorized Error.\n * Indicates that authentication is required and has failed or not been provided.\n */\nexport class UnauthorizedException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Unauthorized\".\n */\n constructor(message: string = \"Unauthorized\") {\n super(message);\n this.status = HttpStatusCodes.UNAUTHORIZED;\n }\n}\n\n/**\n * Represents a 400 Bad Request Error.\n * Indicates that the client has sent invalid data (e.g., malformed request body).\n */\nexport class BadRequestException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Bad request\".\n */\n constructor(message: string = \"Bad request\") {\n super(message);\n this.status = HttpStatusCodes.BAD_REQUEST;\n }\n}\n\n/**\n * Represents a 404 Not Found Error.\n * Used when a requested resource (e.g., user, file) could not be located.\n */\nexport class NotFoundException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Resource not found\".\n */\n constructor(message: string = \"Resource not found\") {\n super(message);\n this.status = HttpStatusCodes.NOT_FOUND;\n }\n}\n\n/**\n * Represents a 403 Forbidden Error.\n * Indicates that the client is authenticated but not allowed to access the resource.\n */\nexport class ForbiddenException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Forbidden\".\n */\n constructor(message: string = \"Forbidden\") {\n super(message);\n this.status = HttpStatusCodes.FORBIDDEN;\n }\n}\n\n/**\n * Represents a 409 Conflict Error.\n * Commonly used when a resource already exists or a versioning conflict occurs.\n */\nexport class ConflictException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Conflict\".\n */\n constructor(message: string = \"Conflict\") {\n super(message);\n this.status = HttpStatusCodes.CONFLICT;\n }\n}\n\n/**\n * Represents a 502 Bad Gateway Error.\n * Used when the server receives an invalid response from an upstream server.\n */\nexport class BadGatewayException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Bad Gateway\".\n */\n constructor(message: string = \"Bad Gateway\") {\n super(message);\n this.status = HttpStatusCodes.BAD_GATEWAY;\n }\n}\n\n/**\n * Represents a 429 Too Many Requests Error.\n * Returned when the client has hit a rate limit.\n */\nexport class TooManyRequestsException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Too many requests\".\n */\n constructor(message: string = \"Too many requests\") {\n super(message);\n this.status = HttpStatusCodes.TOO_MANY_REQUESTS;\n }\n}\n\n/**\n * Represents a 503 Service Unavailable Error.\n * Indicates that the server is temporarily unavailable (e.g., for maintenance).\n */\nexport class ServiceUnavailableException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Service Unavailable\".\n */\n constructor(message: string = \"Service Unavailable\") {\n super(message);\n this.status = HttpStatusCodes.SERVICE_UNAVAILABLE;\n }\n}\n\n/**\n * Represents a 504 Gateway Timeout Error.\n * Returned when the server acting as a gateway times out waiting for a response.\n */\nexport class GatewayTimeoutException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Gateway Timeout\".\n */\n constructor(message: string = \"Gateway Timeout\") {\n super(message);\n this.status = HttpStatusCodes.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AAO,wBAAwB,CAAC;AAClC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAU;IADZ,iBAwBC;IArBC,OAAO;QAAO,cAAsB;aAAtB,UAAsB,EAAtB,qBAAsB,EAAtB,IAAsB;YAAtB,yBAAsB;;;;;;;;wBAEzB,qBAAM,OAAO,wCAAI,IAAI,YAAC;4BAA7B,sBAAO,SAAsB,EAAC;;;wBAE9B,IAAI,WAAW,CAAC,OAAK,CAAC,EAAE,CAAC;4BACvB,MAAM,OAAK,CAAC;wBACd,CAAC;wBAED,0DAA0D;wBAC1D,SAAS,EAAE,CAAC,KAAK,CAAC,0BAA0B,EAAE,OAAK,CAAC,CAAC;wBAGjD,WAAS,eAAe,CAAC,qBAAqB,CAAC;wBACnD,IAAI,aAAa,CAAC,OAAK,CAAC,IAAI,OAAO,OAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;4BAC7D,QAAM,GAAG,OAAK,CAAC,MAAM,CAAC;wBACxB,CAAC;wBAED,gCAAgC;wBAChC,MAAM,eAAe,CAAC,QAAM,EAAE,eAAe,CAAC,OAAK,CAAC,CAAC,CAAC;;;;;KAEzD,CAAC;AACJ,CAAC","sourcesContent":["import { HttpStatusCodes } from \"./http-status-codes\";\nimport { getLogger } from \"./logger.utils\";\nimport { ErrorResponse } from \"./response.utils\";\n\n/**\n * Generic HTTP error class used for custom exceptions with any status code.\n * Inherit this when you need to throw errors dynamically at runtime.\n */\nexport class HttpError extends ErrorResponse {\n /**\n * Creates a new HTTP error instance.\n * @param status - A valid HTTP status code (e.g., 400, 500).\n * @param message - The error message to return to the client.\n */\n constructor(status: number, message: string) {\n super(message);\n this.status = status;\n }\n}\n\n/**\n * Represents a 500 Internal Server Error.\n * Use this for unexpected backend errors that are not caused by the client.\n */\nexport class InternalServerErrorException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Internal server error\".\n */\n constructor(message: string = \"Internal server error\") {\n super(message);\n this.status = HttpStatusCodes.INTERNAL_SERVER_ERROR;\n }\n}\n\n/**\n * Represents a 401 Unauthorized Error.\n * Indicates that authentication is required and has failed or not been provided.\n */\nexport class UnauthorizedException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Unauthorized\".\n */\n constructor(message: string = \"Unauthorized\") {\n super(message);\n this.status = HttpStatusCodes.UNAUTHORIZED;\n }\n}\n\n/**\n * Represents a 400 Bad Request Error.\n * Indicates that the client has sent invalid data (e.g., malformed request body).\n */\nexport class BadRequestException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Bad request\".\n */\n constructor(message: string = \"Bad request\") {\n super(message);\n this.status = HttpStatusCodes.BAD_REQUEST;\n }\n}\n\n/**\n * Represents a 404 Not Found Error.\n * Used when a requested resource (e.g., user, file) could not be located.\n */\nexport class NotFoundException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Resource not found\".\n */\n constructor(message: string = \"Resource not found\") {\n super(message);\n this.status = HttpStatusCodes.NOT_FOUND;\n }\n}\n\n/**\n * Represents a 403 Forbidden Error.\n * Indicates that the client is authenticated but not allowed to access the resource.\n */\nexport class ForbiddenException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Forbidden\".\n */\n constructor(message: string = \"Forbidden\") {\n super(message);\n this.status = HttpStatusCodes.FORBIDDEN;\n }\n}\n\n/**\n * Represents a 409 Conflict Error.\n * Commonly used when a resource already exists or a versioning conflict occurs.\n */\nexport class ConflictException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Conflict\".\n */\n constructor(message: string = \"Conflict\") {\n super(message);\n this.status = HttpStatusCodes.CONFLICT;\n }\n}\n\n/**\n * Represents a 502 Bad Gateway Error.\n * Used when the server receives an invalid response from an upstream server.\n */\nexport class BadGatewayException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Bad Gateway\".\n */\n constructor(message: string = \"Bad Gateway\") {\n super(message);\n this.status = HttpStatusCodes.BAD_GATEWAY;\n }\n}\n\n/**\n * Represents a 429 Too Many Requests Error.\n * Returned when the client has hit a rate limit.\n */\nexport class TooManyRequestsException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Too many requests\".\n */\n constructor(message: string = \"Too many requests\") {\n super(message);\n this.status = HttpStatusCodes.TOO_MANY_REQUESTS;\n }\n}\n\n/**\n * Represents a 503 Service Unavailable Error.\n * Indicates that the server is temporarily unavailable (e.g., for maintenance).\n */\nexport class ServiceUnavailableException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Service Unavailable\".\n */\n constructor(message: string = \"Service Unavailable\") {\n super(message);\n this.status = HttpStatusCodes.SERVICE_UNAVAILABLE;\n }\n}\n\n/**\n * Represents a 504 Gateway Timeout Error.\n * Returned when the server acting as a gateway times out waiting for a response.\n */\nexport class GatewayTimeoutException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Gateway Timeout\".\n */\n constructor(message: string = \"Gateway Timeout\") {\n super(message);\n this.status = HttpStatusCodes.GATEWAY_TIMEOUT;\n }\n}\n\n/**\n * Represents a 422 Unprocessable Entity Error.\n * Used when the server understands the content type but cannot process the contained instructions.\n */\nexport class UnprocessableEntityException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Unprocessable Entity\".\n * @param details - Optional validation details or additional error context.\n */\n constructor(\n message: string = \"Unprocessable Entity\",\n public details?: Record<string, any>,\n ) {\n super(message);\n this.status = HttpStatusCodes.UNPROCESSABLE_ENTITY;\n }\n}\n\n/**\n * Represents a 405 Method Not Allowed Error.\n * Used when the request method is not supported for the requested resource.\n */\nexport class MethodNotAllowedException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Method Not Allowed\".\n * @param allowedMethods - Optional array of allowed HTTP methods.\n */\n constructor(\n message: string = \"Method Not Allowed\",\n public allowedMethods?: string[],\n ) {\n super(message);\n this.status = HttpStatusCodes.METHOD_NOT_ALLOWED;\n }\n}\n\n/**\n * Represents a 406 Not Acceptable Error.\n * Used when the server cannot produce a response matching the client's accepted content types.\n */\nexport class NotAcceptableException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Not Acceptable\".\n */\n constructor(message: string = \"Not Acceptable\") {\n super(message);\n this.status = HttpStatusCodes.NOT_ACCEPTABLE;\n }\n}\n\n/**\n * Represents a 408 Request Timeout Error.\n * Used when the server times out waiting for the client to send a request.\n */\nexport class RequestTimeoutException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Request Timeout\".\n */\n constructor(message: string = \"Request Timeout\") {\n super(message);\n this.status = HttpStatusCodes.REQUEST_TIMEOUT;\n }\n}\n\n/**\n * Represents a 415 Unsupported Media Type Error.\n * Used when the request's Content-Type is not supported.\n */\nexport class UnsupportedMediaTypeException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Unsupported Media Type\".\n */\n constructor(message: string = \"Unsupported Media Type\") {\n super(message);\n this.status = HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE;\n }\n}\n\n/**\n * Represents a 413 Payload Too Large Error.\n * Used when the request body exceeds server limits.\n */\nexport class PayloadTooLargeException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Payload Too Large\".\n */\n constructor(message: string = \"Payload Too Large\") {\n super(message);\n this.status = HttpStatusCodes.PAYLOAD_TOO_LARGE;\n }\n}\n\n/**\n * Represents a 507 Insufficient Storage Error.\n * Used when the server has insufficient storage to complete the request.\n */\nexport class InsufficientStorageException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Insufficient Storage\".\n */\n constructor(message: string = \"Insufficient Storage\") {\n super(message);\n this.status = HttpStatusCodes.INSUFFICIENT_STORAGE;\n }\n}\n\n/**\n * Checks if an error is an instance of HttpError or its subclasses.\n *\n * @param error - The error to check.\n * @returns True if the error is an HttpError, false otherwise.\n */\nexport function isHttpError(error: unknown): error is ErrorResponse {\n return error instanceof ErrorResponse;\n}\n\n/**\n * Creates an HTTP error with the specified status code and message.\n * Factory function for creating appropriate HTTP error instances.\n *\n * @param status - HTTP status code.\n * @param message - Optional custom error message.\n * @returns An instance of the appropriate HTTP error class.\n */\nexport function createHttpError(\n status: number,\n message?: string,\n): ErrorResponse {\n switch (status) {\n case HttpStatusCodes.BAD_REQUEST:\n return new BadRequestException(message);\n case HttpStatusCodes.UNAUTHORIZED:\n return new UnauthorizedException(message);\n case HttpStatusCodes.FORBIDDEN:\n return new ForbiddenException(message);\n case HttpStatusCodes.NOT_FOUND:\n return new NotFoundException(message);\n case HttpStatusCodes.METHOD_NOT_ALLOWED:\n return new MethodNotAllowedException(message);\n case HttpStatusCodes.NOT_ACCEPTABLE:\n return new NotAcceptableException(message);\n case HttpStatusCodes.REQUEST_TIMEOUT:\n return new RequestTimeoutException(message);\n case HttpStatusCodes.CONFLICT:\n return new ConflictException(message);\n case HttpStatusCodes.GONE:\n return new HttpError(HttpStatusCodes.GONE, message || \"Gone\");\n case HttpStatusCodes.PAYLOAD_TOO_LARGE:\n return new PayloadTooLargeException(message);\n case HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE:\n return new UnsupportedMediaTypeException(message);\n case HttpStatusCodes.UNPROCESSABLE_ENTITY:\n return new UnprocessableEntityException(message);\n case HttpStatusCodes.TOO_MANY_REQUESTS:\n return new TooManyRequestsException(message);\n case HttpStatusCodes.INTERNAL_SERVER_ERROR:\n return new InternalServerErrorException(message);\n case HttpStatusCodes.BAD_GATEWAY:\n return new BadGatewayException(message);\n case HttpStatusCodes.SERVICE_UNAVAILABLE:\n return new ServiceUnavailableException(message);\n case HttpStatusCodes.GATEWAY_TIMEOUT:\n return new GatewayTimeoutException(message);\n case HttpStatusCodes.INSUFFICIENT_STORAGE:\n return new InsufficientStorageException(message);\n default:\n return new HttpError(status, message || `HTTP Error ${status}`);\n }\n}\n\n/**\n * Type guard to check if an object has specific error properties.\n *\n * @param error - The object to check.\n * @returns True if object has error-like structure.\n */\nexport function hasErrorShape(\n error: unknown,\n): error is { message: string; status?: number; code?: string } {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"message\" in error &&\n typeof (error as any).message === \"string\"\n );\n}\n\n/**\n * Safely extracts message from any error type.\n *\n * @param error - Any error object or value.\n * @returns A string error message.\n */\nexport function getErrorMessage(error: unknown): string {\n if (typeof error === \"string\") {\n return error;\n }\n\n if (error instanceof Error) {\n return error.message;\n }\n\n if (hasErrorShape(error)) {\n return error.message;\n }\n\n return \"Unknown error occurred\";\n}\n\n/**\n * Wraps a function and transforms any errors into HTTP errors.\n * Useful for API handlers to ensure consistent error responses.\n *\n * @param handler - The async function to wrap.\n * @returns A function that always returns or throws an HTTP error.\n */\nexport function withErrorHandling<T extends (...args: any[]) => Promise<any>>(\n handler: T,\n): (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>> {\n return async (...args: Parameters<T>) => {\n try {\n return await handler(...args);\n } catch (error) {\n if (isHttpError(error)) {\n throw error;\n }\n\n // Log the original error (consider using a proper logger)\n getLogger().error(\"Caught error in handler:\", error);\n\n // Extract status code if it exists, otherwise use 500\n let status = HttpStatusCodes.INTERNAL_SERVER_ERROR;\n if (hasErrorShape(error) && typeof error.status === \"number\") {\n status = error.status;\n }\n\n // Create appropriate HTTP error\n throw createHttpError(status, getErrorMessage(error));\n }\n };\n}\n"]}
@@ -1,3 +1,5 @@
1
+ import { BufferEncoding } from "./crypto.utils";
2
+ import { Stats } from "fs";
1
3
  /**
2
4
  * Checks whether a file or directory exists at the given path.
3
5
  *
@@ -29,4 +31,134 @@ export declare function writeJsonFile(path: string, data: any, space?: number):
29
31
  * @returns {Promise<boolean>} Resolves to `true` if the file was deleted or didn't exist, `false` if deletion failed.
30
32
  */
31
33
  export declare function deleteFileIfExists(path: string): Promise<boolean>;
34
+ /**
35
+ * Reads a text file from the specified path.
36
+ *
37
+ * @param {string} path - The path to the text file.
38
+ * @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
39
+ * @returns {Promise<string | null>} The file contents, or `null` if reading fails.
40
+ */
41
+ export declare function readTextFile(path: string, encoding?: BufferEncoding): Promise<string | null>;
42
+ /**
43
+ * Writes text content to a file.
44
+ *
45
+ * @param {string} path - The destination file path.
46
+ * @param {string} content - The text content to write.
47
+ * @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
48
+ * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
49
+ */
50
+ export declare function writeTextFile(path: string, content: string, encoding?: BufferEncoding): Promise<boolean>;
51
+ /**
52
+ * Appends text content to a file.
53
+ *
54
+ * @param {string} path - The file path to append to.
55
+ * @param {string} content - The text content to append.
56
+ * @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
57
+ * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
58
+ */
59
+ export declare function appendTextFile(path: string, content: string, encoding?: BufferEncoding): Promise<boolean>;
60
+ /**
61
+ * Copies a file from source to destination.
62
+ *
63
+ * @param {string} source - Source file path.
64
+ * @param {string} destination - Destination file path.
65
+ * @param {boolean} [overwrite=false] - Whether to overwrite if destination exists.
66
+ * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
67
+ */
68
+ export declare function copyFile(source: string, destination: string, overwrite?: boolean): Promise<boolean>;
69
+ /**
70
+ * Renames/moves a file.
71
+ *
72
+ * @param {string} oldPath - Current file path.
73
+ * @param {string} newPath - New file path.
74
+ * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
75
+ */
76
+ export declare function moveFile(oldPath: string, newPath: string): Promise<boolean>;
77
+ /**
78
+ * Gets file stats if the file exists.
79
+ *
80
+ * @param {string} path - Path to the file.
81
+ * @returns {Promise<fs.Stats | null>} File stats object or null if file doesn't exist.
82
+ */
83
+ export declare function getFileStats(path: string): Promise<Stats | null>;
84
+ /**
85
+ * Creates a temporary file with optional content.
86
+ *
87
+ * @param {object} [options] - Options for creating the temp file.
88
+ * @param {string} [options.prefix="tmp-"] - Filename prefix.
89
+ * @param {string} [options.extension=""] - File extension.
90
+ * @param {string} [options.dir] - Directory to create the file in (defaults to OS temp dir).
91
+ * @param {string | Buffer} [options.content] - Optional content to write to the file.
92
+ * @returns {Promise<string>} Path to the created temporary file.
93
+ */
94
+ export declare function createTempFile({ prefix, extension, dir, content, }?: {
95
+ prefix?: string;
96
+ extension?: string;
97
+ dir?: string;
98
+ content?: string | Buffer;
99
+ }): Promise<string>;
100
+ /**
101
+ * Streams a file from source to destination.
102
+ * Useful for large files to avoid loading the entire file into memory.
103
+ *
104
+ * @param {string} source - Source file path.
105
+ * @param {string} destination - Destination file path.
106
+ * @returns {Promise<void>} Resolves when streaming completes.
107
+ * @throws {Error} If streaming fails.
108
+ */
109
+ export declare function streamFile(source: string, destination: string): Promise<void>;
110
+ /**
111
+ * Reads a directory and returns file names.
112
+ *
113
+ * @param {string} dirPath - Path to the directory.
114
+ * @param {object} [options] - Options for reading the directory.
115
+ * @param {boolean} [options.fullPaths=false] - Whether to return full paths.
116
+ * @param {RegExp} [options.filter] - Optional regex to filter files.
117
+ * @returns {Promise<string[]>} Array of file names or paths.
118
+ * @throws {Error} If directory cannot be read.
119
+ */
120
+ export declare function readDirectory(dirPath: string, options?: {
121
+ fullPaths?: boolean;
122
+ filter?: RegExp;
123
+ }): Promise<string[]>;
124
+ /**
125
+ * Creates a directory if it doesn't exist.
126
+ *
127
+ * @param {string} dirPath - Path to the directory.
128
+ * @param {boolean} [recursive=true] - Whether to create parent directories.
129
+ * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
130
+ */
131
+ export declare function createDirectory(dirPath: string, recursive?: boolean): Promise<boolean>;
132
+ /**
133
+ * Safely reads and parses a JSON file with error details.
134
+ *
135
+ * @typeParam T - The expected type of the parsed JSON object.
136
+ * @param {string} path - The path to the JSON file.
137
+ * @returns {Promise<{ data: T | null; error: Error | null }>} Object with data and error properties.
138
+ */
139
+ export declare function safeReadJsonFile<T = any>(path: string): Promise<{
140
+ data: T | null;
141
+ error: Error | null;
142
+ }>;
143
+ /**
144
+ * Checks if a path points to a file (not a directory).
145
+ *
146
+ * @param {string} path - Path to check.
147
+ * @returns {Promise<boolean>} True if the path is a file, false otherwise.
148
+ */
149
+ export declare function isFile(path: string): Promise<boolean>;
150
+ /**
151
+ * Gets the size of a file in bytes.
152
+ *
153
+ * @param {string} path - Path to the file.
154
+ * @returns {Promise<number>} Size in bytes or -1 if file doesn't exist.
155
+ */
156
+ export declare function getFileSize(path: string): Promise<number>;
157
+ /**
158
+ * Reads a file as a Buffer.
159
+ *
160
+ * @param {string} path - Path to the file.
161
+ * @returns {Promise<Buffer | null>} File contents as Buffer or null if reading fails.
162
+ */
163
+ export declare function readFileBuffer(path: string): Promise<Buffer | null>;
32
164
  //# sourceMappingURL=fs.utils.d.ts.map