@cosmneo/onion-lasagna 0.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 (97) hide show
  1. package/dist/backend/core/global.cjs +283 -0
  2. package/dist/backend/core/global.cjs.map +1 -0
  3. package/dist/backend/core/global.d.cts +294 -0
  4. package/dist/backend/core/global.d.ts +294 -0
  5. package/dist/backend/core/global.js +39 -0
  6. package/dist/backend/core/global.js.map +1 -0
  7. package/dist/backend/core/onion-layers.cjs +2302 -0
  8. package/dist/backend/core/onion-layers.cjs.map +1 -0
  9. package/dist/backend/core/onion-layers.d.cts +1675 -0
  10. package/dist/backend/core/onion-layers.d.ts +1675 -0
  11. package/dist/backend/core/onion-layers.js +1158 -0
  12. package/dist/backend/core/onion-layers.js.map +1 -0
  13. package/dist/backend/core/presentation.cjs +573 -0
  14. package/dist/backend/core/presentation.cjs.map +1 -0
  15. package/dist/backend/core/presentation.d.cts +5 -0
  16. package/dist/backend/core/presentation.d.ts +5 -0
  17. package/dist/backend/core/presentation.js +28 -0
  18. package/dist/backend/core/presentation.js.map +1 -0
  19. package/dist/backend/core/validators/arktype.cjs +947 -0
  20. package/dist/backend/core/validators/arktype.cjs.map +1 -0
  21. package/dist/backend/core/validators/arktype.d.cts +188 -0
  22. package/dist/backend/core/validators/arktype.d.ts +188 -0
  23. package/dist/backend/core/validators/arktype.js +287 -0
  24. package/dist/backend/core/validators/arktype.js.map +1 -0
  25. package/dist/backend/core/validators/typebox.cjs +939 -0
  26. package/dist/backend/core/validators/typebox.cjs.map +1 -0
  27. package/dist/backend/core/validators/typebox.d.cts +189 -0
  28. package/dist/backend/core/validators/typebox.d.ts +189 -0
  29. package/dist/backend/core/validators/typebox.js +281 -0
  30. package/dist/backend/core/validators/typebox.js.map +1 -0
  31. package/dist/backend/core/validators/valibot.cjs +942 -0
  32. package/dist/backend/core/validators/valibot.cjs.map +1 -0
  33. package/dist/backend/core/validators/valibot.d.cts +160 -0
  34. package/dist/backend/core/validators/valibot.d.ts +160 -0
  35. package/dist/backend/core/validators/valibot.js +294 -0
  36. package/dist/backend/core/validators/valibot.js.map +1 -0
  37. package/dist/backend/core/validators/zod.cjs +934 -0
  38. package/dist/backend/core/validators/zod.cjs.map +1 -0
  39. package/dist/backend/core/validators/zod.d.cts +188 -0
  40. package/dist/backend/core/validators/zod.d.ts +188 -0
  41. package/dist/backend/core/validators/zod.js +278 -0
  42. package/dist/backend/core/validators/zod.js.map +1 -0
  43. package/dist/backend/frameworks/elysia.cjs +715 -0
  44. package/dist/backend/frameworks/elysia.cjs.map +1 -0
  45. package/dist/backend/frameworks/elysia.d.cts +208 -0
  46. package/dist/backend/frameworks/elysia.d.ts +208 -0
  47. package/dist/backend/frameworks/elysia.js +251 -0
  48. package/dist/backend/frameworks/elysia.js.map +1 -0
  49. package/dist/backend/frameworks/fastify.cjs +677 -0
  50. package/dist/backend/frameworks/fastify.cjs.map +1 -0
  51. package/dist/backend/frameworks/fastify.d.cts +201 -0
  52. package/dist/backend/frameworks/fastify.d.ts +201 -0
  53. package/dist/backend/frameworks/fastify.js +213 -0
  54. package/dist/backend/frameworks/fastify.js.map +1 -0
  55. package/dist/backend/frameworks/hono.cjs +715 -0
  56. package/dist/backend/frameworks/hono.cjs.map +1 -0
  57. package/dist/backend/frameworks/hono.d.cts +163 -0
  58. package/dist/backend/frameworks/hono.d.ts +163 -0
  59. package/dist/backend/frameworks/hono.js +249 -0
  60. package/dist/backend/frameworks/hono.js.map +1 -0
  61. package/dist/backend/frameworks/nestjs.cjs +260 -0
  62. package/dist/backend/frameworks/nestjs.cjs.map +1 -0
  63. package/dist/backend/frameworks/nestjs.d.cts +168 -0
  64. package/dist/backend/frameworks/nestjs.d.ts +168 -0
  65. package/dist/backend/frameworks/nestjs.js +193 -0
  66. package/dist/backend/frameworks/nestjs.js.map +1 -0
  67. package/dist/base-dto.class-D7W9iqoU.d.cts +146 -0
  68. package/dist/base-dto.class-D7W9iqoU.d.ts +146 -0
  69. package/dist/base-uuid-v7.vo-BPGEIWLM.d.ts +799 -0
  70. package/dist/base-uuid-v7.vo-BjqKX44G.d.cts +799 -0
  71. package/dist/chunk-74IKUOSE.js +116 -0
  72. package/dist/chunk-74IKUOSE.js.map +1 -0
  73. package/dist/chunk-BKZOLGQW.js +29 -0
  74. package/dist/chunk-BKZOLGQW.js.map +1 -0
  75. package/dist/chunk-CGZBV6BD.js +54 -0
  76. package/dist/chunk-CGZBV6BD.js.map +1 -0
  77. package/dist/chunk-DDAHJZVK.js +258 -0
  78. package/dist/chunk-DDAHJZVK.js.map +1 -0
  79. package/dist/chunk-MQD5GXMT.js +171 -0
  80. package/dist/chunk-MQD5GXMT.js.map +1 -0
  81. package/dist/chunk-OKFXZHBC.js +43 -0
  82. package/dist/chunk-OKFXZHBC.js.map +1 -0
  83. package/dist/chunk-RLLWYFPI.js +168 -0
  84. package/dist/chunk-RLLWYFPI.js.map +1 -0
  85. package/dist/chunk-VCHFXT5W.js +425 -0
  86. package/dist/chunk-VCHFXT5W.js.map +1 -0
  87. package/dist/chunk-ZWLYNGO3.js +40 -0
  88. package/dist/chunk-ZWLYNGO3.js.map +1 -0
  89. package/dist/http-response-BAhi8lF4.d.cts +124 -0
  90. package/dist/http-response-BAhi8lF4.d.ts +124 -0
  91. package/dist/index-DingXh7B.d.cts +1187 -0
  92. package/dist/index-tOH7XBa3.d.ts +1187 -0
  93. package/dist/routing.type-DB4pt-d9.d.ts +184 -0
  94. package/dist/routing.type-DF2BIL7x.d.cts +184 -0
  95. package/dist/validation-error.type-kD4_qNZ9.d.cts +199 -0
  96. package/dist/validation-error.type-kD4_qNZ9.d.ts +199 -0
  97. package/package.json +191 -0
@@ -0,0 +1,677 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/backend/frameworks/fastify/index.ts
21
+ var fastify_exports = {};
22
+ __export(fastify_exports, {
23
+ mapErrorToResponse: () => mapErrorToResponse,
24
+ onionErrorHandler: () => onionErrorHandler,
25
+ registerFastifyRoutes: () => registerFastifyRoutes
26
+ });
27
+ module.exports = __toCommonJS(fastify_exports);
28
+
29
+ // src/backend/frameworks/fastify/routing.ts
30
+ function toFastifyPath(path) {
31
+ return path.replace(/\{([^}]+)\}/g, ":$1");
32
+ }
33
+ function extractRequest(request) {
34
+ const headers = {};
35
+ for (const [key, value] of Object.entries(request.headers)) {
36
+ if (typeof value === "string") {
37
+ headers[key.toLowerCase()] = value;
38
+ } else if (Array.isArray(value)) {
39
+ headers[key.toLowerCase()] = value.join(", ");
40
+ }
41
+ }
42
+ const queryParams = {};
43
+ const query = request.query;
44
+ for (const [key, value] of Object.entries(query)) {
45
+ if (value != null) {
46
+ queryParams[key] = value;
47
+ }
48
+ }
49
+ return {
50
+ body: request.body,
51
+ headers,
52
+ queryParams,
53
+ pathParams: request.params
54
+ };
55
+ }
56
+ function sendResponse(reply, response) {
57
+ if (response.headers) {
58
+ for (const [key, value] of Object.entries(response.headers)) {
59
+ if (value != null) {
60
+ reply.header(key, String(value));
61
+ }
62
+ }
63
+ }
64
+ reply.status(response.statusCode);
65
+ if (response.body === void 0 || response.body === null) {
66
+ return reply.send();
67
+ }
68
+ return reply.send(response.body);
69
+ }
70
+ function registerFastifyRoutes(app, routes, options) {
71
+ const routeArray = Array.isArray(routes) ? routes : [routes];
72
+ const prefix = options?.prefix ?? "";
73
+ const middlewares = options?.middlewares ?? [];
74
+ for (const { metadata, controller, requestDtoFactory } of routeArray) {
75
+ const path = prefix + toFastifyPath(metadata.path);
76
+ const method = metadata.method.toUpperCase();
77
+ const handler = async (request, reply) => {
78
+ const rawRequest = extractRequest(request);
79
+ const requestDto = requestDtoFactory(rawRequest);
80
+ const responseDto = await controller.execute(requestDto);
81
+ return sendResponse(reply, responseDto.data);
82
+ };
83
+ app.route({
84
+ method,
85
+ url: path,
86
+ preHandler: middlewares,
87
+ handler
88
+ });
89
+ }
90
+ }
91
+
92
+ // src/backend/core/global/exceptions/coded-error.error.ts
93
+ var CodedError = class extends Error {
94
+ /** Machine-readable error code for programmatic handling. */
95
+ code;
96
+ /**
97
+ * Creates a new CodedError instance.
98
+ *
99
+ * @param options - Error configuration
100
+ * @param options.message - Human-readable error message
101
+ * @param options.code - Machine-readable error code from ErrorCodes registry or custom string
102
+ * @param options.cause - Optional underlying error that caused this error
103
+ */
104
+ constructor({
105
+ message,
106
+ code,
107
+ cause
108
+ }) {
109
+ super(message);
110
+ this.name = this.constructor.name;
111
+ this.code = code;
112
+ if (cause !== void 0) {
113
+ Object.defineProperty(this, "cause", {
114
+ value: cause,
115
+ writable: false,
116
+ enumerable: false,
117
+ configurable: true
118
+ });
119
+ }
120
+ }
121
+ /**
122
+ * Factory method to create a typed error from a caught error.
123
+ *
124
+ * Subclasses should override this to provide proper error transformation.
125
+ * Designed for use with {@link wrapErrorAsync} and {@link wrapError}.
126
+ *
127
+ * @param _cause - The original caught error
128
+ * @returns A new CodedError instance
129
+ * @throws {Error} If not overridden by subclass
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * class NotFoundError extends UseCaseError {
134
+ * static override fromError(cause: unknown): NotFoundError {
135
+ * return new NotFoundError({
136
+ * message: 'Resource not found',
137
+ * cause,
138
+ * });
139
+ * }
140
+ * }
141
+ * ```
142
+ */
143
+ static fromError(_cause) {
144
+ throw new Error(`${this.name}.fromError() must be implemented by subclass`);
145
+ }
146
+ };
147
+
148
+ // src/backend/core/global/exceptions/error-codes.const.ts
149
+ var ErrorCodes = {
150
+ /**
151
+ * Domain layer error codes.
152
+ * Used for business rule violations and invariant failures.
153
+ */
154
+ Domain: {
155
+ /** Generic domain error */
156
+ DOMAIN_ERROR: "DOMAIN_ERROR",
157
+ /** Business invariant was violated */
158
+ INVARIANT_VIOLATION: "INVARIANT_VIOLATION",
159
+ /** Aggregate was partially loaded (missing required relations) */
160
+ PARTIAL_LOAD: "PARTIAL_LOAD"
161
+ },
162
+ /**
163
+ * Application layer (use case) error codes.
164
+ * Used for orchestration failures and business operation errors.
165
+ */
166
+ App: {
167
+ /** Generic use case error */
168
+ USE_CASE_ERROR: "USE_CASE_ERROR",
169
+ /** Requested resource was not found */
170
+ NOT_FOUND: "NOT_FOUND",
171
+ /** Resource state conflict (e.g., duplicate, already exists) */
172
+ CONFLICT: "CONFLICT",
173
+ /** Request is valid but cannot be processed due to business rules */
174
+ UNPROCESSABLE: "UNPROCESSABLE"
175
+ },
176
+ /**
177
+ * Infrastructure layer error codes.
178
+ * Used for data access, external services, and I/O failures.
179
+ */
180
+ Infra: {
181
+ /** Generic infrastructure error */
182
+ INFRA_ERROR: "INFRA_ERROR",
183
+ /** Database operation failed */
184
+ DB_ERROR: "DB_ERROR",
185
+ /** Network connectivity or communication error */
186
+ NETWORK_ERROR: "NETWORK_ERROR",
187
+ /** Operation timed out */
188
+ TIMEOUT_ERROR: "TIMEOUT_ERROR",
189
+ /** External/third-party service error */
190
+ EXTERNAL_SERVICE_ERROR: "EXTERNAL_SERVICE_ERROR"
191
+ },
192
+ /**
193
+ * Presentation layer error codes.
194
+ * Used for controller, request handling, and authorization errors.
195
+ */
196
+ Presentation: {
197
+ /** Generic controller error */
198
+ CONTROLLER_ERROR: "CONTROLLER_ERROR",
199
+ /** Request denied due to authorization failure */
200
+ ACCESS_DENIED: "ACCESS_DENIED",
201
+ /** Request validation failed (malformed input) */
202
+ INVALID_REQUEST: "INVALID_REQUEST"
203
+ },
204
+ /**
205
+ * Global/cross-cutting error codes.
206
+ * Used for validation and other cross-layer concerns.
207
+ */
208
+ Global: {
209
+ /** Object/schema validation failed */
210
+ OBJECT_VALIDATION_ERROR: "OBJECT_VALIDATION_ERROR"
211
+ }
212
+ };
213
+
214
+ // src/backend/core/global/exceptions/object-validation.error.ts
215
+ var ObjectValidationError = class _ObjectValidationError extends CodedError {
216
+ /**
217
+ * Array of field-level validation errors.
218
+ *
219
+ * Each entry contains:
220
+ * - `field`: Dot-notation path to the invalid field (e.g., 'user.email')
221
+ * - `message`: Human-readable validation failure message
222
+ */
223
+ validationErrors;
224
+ /**
225
+ * Creates a new ObjectValidationError instance.
226
+ *
227
+ * @param options - Error configuration
228
+ * @param options.message - Human-readable summary message
229
+ * @param options.code - Machine-readable error code (default: 'OBJECT_VALIDATION_ERROR')
230
+ * @param options.cause - Optional underlying error from validation library
231
+ * @param options.validationErrors - Array of field-level validation errors
232
+ */
233
+ constructor({
234
+ message,
235
+ code = ErrorCodes.Global.OBJECT_VALIDATION_ERROR,
236
+ cause,
237
+ validationErrors
238
+ }) {
239
+ super({ message, code, cause });
240
+ this.validationErrors = validationErrors;
241
+ }
242
+ /**
243
+ * Creates an ObjectValidationError from a caught error.
244
+ *
245
+ * @param cause - The original caught error
246
+ * @returns A new ObjectValidationError instance with the cause attached
247
+ */
248
+ static fromError(cause) {
249
+ return new _ObjectValidationError({
250
+ message: cause instanceof Error ? cause.message : "Validation failed",
251
+ cause,
252
+ validationErrors: []
253
+ });
254
+ }
255
+ };
256
+
257
+ // src/backend/core/onion-layers/domain/exceptions/domain.error.ts
258
+ var DomainError = class _DomainError extends CodedError {
259
+ /**
260
+ * Creates a new DomainError instance.
261
+ *
262
+ * @param options - Error configuration
263
+ * @param options.message - Human-readable error description
264
+ * @param options.code - Machine-readable error code (default: 'DOMAIN_ERROR')
265
+ * @param options.cause - Optional underlying error
266
+ */
267
+ constructor({
268
+ message,
269
+ code = ErrorCodes.Domain.DOMAIN_ERROR,
270
+ cause
271
+ }) {
272
+ super({ message, code, cause });
273
+ }
274
+ /**
275
+ * Creates a DomainError from a caught error.
276
+ *
277
+ * @param cause - The original caught error
278
+ * @returns A new DomainError instance with the cause attached
279
+ */
280
+ static fromError(cause) {
281
+ return new _DomainError({
282
+ message: cause instanceof Error ? cause.message : "Domain error",
283
+ cause
284
+ });
285
+ }
286
+ };
287
+
288
+ // src/backend/core/onion-layers/app/exceptions/use-case.error.ts
289
+ var UseCaseError = class _UseCaseError extends CodedError {
290
+ /**
291
+ * Creates a new UseCaseError instance.
292
+ *
293
+ * @param options - Error configuration
294
+ * @param options.message - Human-readable error description
295
+ * @param options.code - Machine-readable error code (default: 'USE_CASE_ERROR')
296
+ * @param options.cause - Optional underlying error
297
+ */
298
+ constructor({
299
+ message,
300
+ code = ErrorCodes.App.USE_CASE_ERROR,
301
+ cause
302
+ }) {
303
+ super({ message, code, cause });
304
+ }
305
+ /**
306
+ * Creates a UseCaseError from a caught error.
307
+ *
308
+ * @param cause - The original caught error
309
+ * @returns A new UseCaseError instance with the cause attached
310
+ */
311
+ static fromError(cause) {
312
+ return new _UseCaseError({
313
+ message: cause instanceof Error ? cause.message : "Use case error",
314
+ cause
315
+ });
316
+ }
317
+ };
318
+
319
+ // src/backend/core/onion-layers/app/exceptions/not-found.error.ts
320
+ var NotFoundError = class _NotFoundError extends UseCaseError {
321
+ /**
322
+ * Creates a new NotFoundError instance.
323
+ *
324
+ * @param options - Error configuration
325
+ * @param options.message - Description of what was not found
326
+ * @param options.code - Machine-readable error code (default: 'NOT_FOUND')
327
+ * @param options.cause - Optional underlying error
328
+ */
329
+ constructor({
330
+ message,
331
+ code = ErrorCodes.App.NOT_FOUND,
332
+ cause
333
+ }) {
334
+ super({ message, code, cause });
335
+ }
336
+ /**
337
+ * Creates a NotFoundError from a caught error.
338
+ *
339
+ * @param cause - The original caught error
340
+ * @returns A new NotFoundError instance with the cause attached
341
+ */
342
+ static fromError(cause) {
343
+ return new _NotFoundError({
344
+ message: cause instanceof Error ? cause.message : "Resource not found",
345
+ cause
346
+ });
347
+ }
348
+ };
349
+
350
+ // src/backend/core/onion-layers/app/exceptions/conflict.error.ts
351
+ var ConflictError = class _ConflictError extends UseCaseError {
352
+ /**
353
+ * Creates a new ConflictError instance.
354
+ *
355
+ * @param options - Error configuration
356
+ * @param options.message - Description of the conflict
357
+ * @param options.code - Machine-readable error code (default: 'CONFLICT')
358
+ * @param options.cause - Optional underlying error
359
+ */
360
+ constructor({
361
+ message,
362
+ code = ErrorCodes.App.CONFLICT,
363
+ cause
364
+ }) {
365
+ super({ message, code, cause });
366
+ }
367
+ /**
368
+ * Creates a ConflictError from a caught error.
369
+ *
370
+ * @param cause - The original caught error
371
+ * @returns A new ConflictError instance with the cause attached
372
+ */
373
+ static fromError(cause) {
374
+ return new _ConflictError({
375
+ message: cause instanceof Error ? cause.message : "Conflict error",
376
+ cause
377
+ });
378
+ }
379
+ };
380
+
381
+ // src/backend/core/onion-layers/app/exceptions/unprocessable.error.ts
382
+ var UnprocessableError = class _UnprocessableError extends UseCaseError {
383
+ /**
384
+ * Creates a new UnprocessableError instance.
385
+ *
386
+ * @param options - Error configuration
387
+ * @param options.message - Description of why the request cannot be processed
388
+ * @param options.code - Machine-readable error code (default: 'UNPROCESSABLE')
389
+ * @param options.cause - Optional underlying error
390
+ */
391
+ constructor({
392
+ message,
393
+ code = ErrorCodes.App.UNPROCESSABLE,
394
+ cause
395
+ }) {
396
+ super({ message, code, cause });
397
+ }
398
+ /**
399
+ * Creates an UnprocessableError from a caught error.
400
+ *
401
+ * @param cause - The original caught error
402
+ * @returns A new UnprocessableError instance with the cause attached
403
+ */
404
+ static fromError(cause) {
405
+ return new _UnprocessableError({
406
+ message: cause instanceof Error ? cause.message : "Unprocessable request",
407
+ cause
408
+ });
409
+ }
410
+ };
411
+
412
+ // src/backend/core/onion-layers/infra/exceptions/infra.error.ts
413
+ var InfraError = class _InfraError extends CodedError {
414
+ /**
415
+ * Creates a new InfraError instance.
416
+ *
417
+ * @param options - Error configuration
418
+ * @param options.message - Human-readable error description
419
+ * @param options.code - Machine-readable error code (default: 'INFRA_ERROR')
420
+ * @param options.cause - Optional underlying error
421
+ */
422
+ constructor({
423
+ message,
424
+ code = ErrorCodes.Infra.INFRA_ERROR,
425
+ cause
426
+ }) {
427
+ super({ message, code, cause });
428
+ }
429
+ /**
430
+ * Creates an InfraError from a caught error.
431
+ *
432
+ * @param cause - The original caught error
433
+ * @returns A new InfraError instance with the cause attached
434
+ */
435
+ static fromError(cause) {
436
+ return new _InfraError({
437
+ message: cause instanceof Error ? cause.message : "Infrastructure error",
438
+ cause
439
+ });
440
+ }
441
+ };
442
+
443
+ // src/backend/core/onion-layers/presentation/exceptions/controller.error.ts
444
+ var ControllerError = class _ControllerError extends CodedError {
445
+ /**
446
+ * Creates a new ControllerError instance.
447
+ *
448
+ * @param options - Error configuration
449
+ * @param options.message - Human-readable error description
450
+ * @param options.code - Machine-readable error code (default: 'CONTROLLER_ERROR')
451
+ * @param options.cause - Optional underlying error
452
+ */
453
+ constructor({
454
+ message,
455
+ code = ErrorCodes.Presentation.CONTROLLER_ERROR,
456
+ cause
457
+ }) {
458
+ super({ message, code, cause });
459
+ }
460
+ /**
461
+ * Creates a ControllerError from a caught error.
462
+ *
463
+ * @param cause - The original caught error
464
+ * @returns A new ControllerError instance with the cause attached
465
+ */
466
+ static fromError(cause) {
467
+ return new _ControllerError({
468
+ message: cause instanceof Error ? cause.message : "Controller error",
469
+ cause
470
+ });
471
+ }
472
+ };
473
+
474
+ // src/backend/core/onion-layers/presentation/exceptions/access-denied.error.ts
475
+ var AccessDeniedError = class _AccessDeniedError extends CodedError {
476
+ /**
477
+ * Creates a new AccessDeniedError instance.
478
+ *
479
+ * @param options - Error configuration
480
+ * @param options.message - Description of why access was denied
481
+ * @param options.code - Machine-readable error code (default: 'ACCESS_DENIED')
482
+ * @param options.cause - Optional underlying error
483
+ */
484
+ constructor({
485
+ message,
486
+ code = ErrorCodes.Presentation.ACCESS_DENIED,
487
+ cause
488
+ }) {
489
+ super({ message, code, cause });
490
+ }
491
+ /**
492
+ * Creates an AccessDeniedError from a caught error.
493
+ *
494
+ * @param cause - The original caught error
495
+ * @returns A new AccessDeniedError instance with the cause attached
496
+ */
497
+ static fromError(cause) {
498
+ return new _AccessDeniedError({
499
+ message: cause instanceof Error ? cause.message : "Access denied",
500
+ cause
501
+ });
502
+ }
503
+ };
504
+
505
+ // src/backend/core/onion-layers/presentation/exceptions/invalid-request.error.ts
506
+ var InvalidRequestError = class _InvalidRequestError extends CodedError {
507
+ /**
508
+ * Array of field-level validation errors.
509
+ *
510
+ * Each entry contains:
511
+ * - `field`: Dot-notation path to the invalid field
512
+ * - `message`: Human-readable validation failure message
513
+ */
514
+ validationErrors;
515
+ /**
516
+ * Creates a new InvalidRequestError instance.
517
+ *
518
+ * @param options - Error configuration
519
+ * @param options.message - Summary of the validation failure
520
+ * @param options.code - Machine-readable error code (default: 'INVALID_REQUEST')
521
+ * @param options.cause - Optional underlying error
522
+ * @param options.validationErrors - Array of field-level validation errors
523
+ */
524
+ constructor({
525
+ message,
526
+ code = ErrorCodes.Presentation.INVALID_REQUEST,
527
+ cause,
528
+ validationErrors
529
+ }) {
530
+ super({ message, code, cause });
531
+ this.validationErrors = validationErrors;
532
+ }
533
+ /**
534
+ * Creates an InvalidRequestError from a caught error.
535
+ *
536
+ * @param cause - The original caught error
537
+ * @returns A new InvalidRequestError instance with the cause attached
538
+ */
539
+ static fromError(cause) {
540
+ return new _InvalidRequestError({
541
+ message: cause instanceof Error ? cause.message : "Invalid request",
542
+ cause,
543
+ validationErrors: []
544
+ });
545
+ }
546
+ };
547
+
548
+ // src/backend/frameworks/fastify/map-error-to-response.ts
549
+ function mapErrorToResponse(error) {
550
+ if (error instanceof ObjectValidationError) {
551
+ return {
552
+ statusCode: 400,
553
+ body: {
554
+ message: error.message,
555
+ errorCode: error.code,
556
+ errorItems: error.validationErrors.map((e) => ({
557
+ item: e.field,
558
+ message: e.message
559
+ }))
560
+ }
561
+ };
562
+ }
563
+ if (error instanceof InvalidRequestError) {
564
+ return {
565
+ statusCode: 400,
566
+ body: {
567
+ message: error.message,
568
+ errorCode: error.code,
569
+ errorItems: error.validationErrors.map((e) => ({
570
+ item: e.field,
571
+ message: e.message
572
+ }))
573
+ }
574
+ };
575
+ }
576
+ if (error instanceof AccessDeniedError) {
577
+ return {
578
+ statusCode: 403,
579
+ body: {
580
+ message: error.message,
581
+ errorCode: error.code
582
+ }
583
+ };
584
+ }
585
+ if (error instanceof NotFoundError) {
586
+ return {
587
+ statusCode: 404,
588
+ body: {
589
+ message: error.message,
590
+ errorCode: error.code
591
+ }
592
+ };
593
+ }
594
+ if (error instanceof ConflictError) {
595
+ return {
596
+ statusCode: 409,
597
+ body: {
598
+ message: error.message,
599
+ errorCode: error.code
600
+ }
601
+ };
602
+ }
603
+ if (error instanceof UnprocessableError) {
604
+ return {
605
+ statusCode: 422,
606
+ body: {
607
+ message: error.message,
608
+ errorCode: error.code
609
+ }
610
+ };
611
+ }
612
+ if (error instanceof UseCaseError) {
613
+ return {
614
+ statusCode: 400,
615
+ body: {
616
+ message: error.message,
617
+ errorCode: error.code
618
+ }
619
+ };
620
+ }
621
+ if (error instanceof DomainError) {
622
+ return {
623
+ statusCode: 500,
624
+ body: {
625
+ message: "An unexpected error occurred",
626
+ errorCode: "INTERNAL_ERROR"
627
+ }
628
+ };
629
+ }
630
+ if (error instanceof InfraError) {
631
+ return {
632
+ statusCode: 500,
633
+ body: {
634
+ message: "An unexpected error occurred",
635
+ errorCode: "INTERNAL_ERROR"
636
+ }
637
+ };
638
+ }
639
+ if (error instanceof ControllerError) {
640
+ return {
641
+ statusCode: 500,
642
+ body: {
643
+ message: "An unexpected error occurred",
644
+ errorCode: "INTERNAL_ERROR"
645
+ }
646
+ };
647
+ }
648
+ if (error instanceof CodedError) {
649
+ return {
650
+ statusCode: 500,
651
+ body: {
652
+ message: "An unexpected error occurred",
653
+ errorCode: "INTERNAL_ERROR"
654
+ }
655
+ };
656
+ }
657
+ return {
658
+ statusCode: 500,
659
+ body: {
660
+ message: "An unexpected error occurred",
661
+ errorCode: "INTERNAL_ERROR"
662
+ }
663
+ };
664
+ }
665
+
666
+ // src/backend/frameworks/fastify/error-handler.ts
667
+ function onionErrorHandler(error, _request, reply) {
668
+ const { statusCode, body } = mapErrorToResponse(error);
669
+ return reply.status(statusCode).send(body);
670
+ }
671
+ // Annotate the CommonJS export names for ESM import in node:
672
+ 0 && (module.exports = {
673
+ mapErrorToResponse,
674
+ onionErrorHandler,
675
+ registerFastifyRoutes
676
+ });
677
+ //# sourceMappingURL=fastify.cjs.map