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