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