@cosmneo/onion-lasagna 0.3.0 → 0.4.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 (74) hide show
  1. package/dist/{chunk-XWKHOLIP.js → chunk-4HMXTGHK.js} +2 -2
  2. package/dist/chunk-4RFWJ5XZ.js +192 -0
  3. package/dist/chunk-4RFWJ5XZ.js.map +1 -0
  4. package/dist/{chunk-4BVOLXDJ.js → chunk-4YBAV6LZ.js} +2 -2
  5. package/dist/chunk-ANLXZHUS.js +230 -0
  6. package/dist/chunk-ANLXZHUS.js.map +1 -0
  7. package/dist/chunk-BG2FY27M.js +36 -0
  8. package/dist/chunk-BG2FY27M.js.map +1 -0
  9. package/dist/chunk-FEY2GSVT.js +1 -0
  10. package/dist/chunk-FEY2GSVT.js.map +1 -0
  11. package/dist/{chunk-2BVCU32G.js → chunk-HNEAH6OZ.js} +121 -2
  12. package/dist/chunk-HNEAH6OZ.js.map +1 -0
  13. package/dist/chunk-NQMFWI6Q.js +1 -0
  14. package/dist/chunk-NQMFWI6Q.js.map +1 -0
  15. package/dist/chunk-TZRBETT3.js +127 -0
  16. package/dist/chunk-TZRBETT3.js.map +1 -0
  17. package/dist/{chunk-MF2JDREK.js → chunk-UNVB4INM.js} +1 -1
  18. package/dist/{chunk-MF2JDREK.js.map → chunk-UNVB4INM.js.map} +1 -1
  19. package/dist/chunk-VBG3UYQR.js +119 -0
  20. package/dist/chunk-VBG3UYQR.js.map +1 -0
  21. package/dist/events/index.js +3 -4
  22. package/dist/events/server/index.js +3 -4
  23. package/dist/events/shared/index.js +2 -3
  24. package/dist/graphql/field/index.cjs +189 -0
  25. package/dist/graphql/field/index.cjs.map +1 -0
  26. package/dist/graphql/field/index.d.cts +214 -0
  27. package/dist/graphql/field/index.d.ts +214 -0
  28. package/dist/graphql/field/index.js +25 -0
  29. package/dist/graphql/field/index.js.map +1 -0
  30. package/dist/graphql/index.cjs +1148 -0
  31. package/dist/graphql/index.cjs.map +1 -0
  32. package/dist/graphql/index.d.cts +8 -0
  33. package/dist/graphql/index.d.ts +8 -0
  34. package/dist/graphql/index.js +49 -0
  35. package/dist/graphql/index.js.map +1 -0
  36. package/dist/graphql/sdl/index.cjs +241 -0
  37. package/dist/graphql/sdl/index.cjs.map +1 -0
  38. package/dist/graphql/sdl/index.d.cts +77 -0
  39. package/dist/graphql/sdl/index.d.ts +77 -0
  40. package/dist/graphql/sdl/index.js +8 -0
  41. package/dist/graphql/sdl/index.js.map +1 -0
  42. package/dist/graphql/server/index.cjs +505 -0
  43. package/dist/graphql/server/index.cjs.map +1 -0
  44. package/dist/graphql/server/index.d.cts +268 -0
  45. package/dist/graphql/server/index.d.ts +268 -0
  46. package/dist/graphql/server/index.js +15 -0
  47. package/dist/graphql/server/index.js.map +1 -0
  48. package/dist/graphql/shared/index.cjs +586 -0
  49. package/dist/graphql/shared/index.cjs.map +1 -0
  50. package/dist/graphql/shared/index.d.cts +82 -0
  51. package/dist/graphql/shared/index.d.ts +82 -0
  52. package/dist/graphql/shared/index.js +16 -0
  53. package/dist/graphql/shared/index.js.map +1 -0
  54. package/dist/http/index.cjs.map +1 -1
  55. package/dist/http/index.js +2 -3
  56. package/dist/http/route/index.cjs.map +1 -1
  57. package/dist/http/route/index.d.cts +4 -0
  58. package/dist/http/route/index.d.ts +4 -0
  59. package/dist/http/route/index.js +1 -1
  60. package/dist/http/shared/index.js +1 -2
  61. package/dist/index.cjs +672 -0
  62. package/dist/index.cjs.map +1 -1
  63. package/dist/index.d.cts +8 -0
  64. package/dist/index.d.ts +8 -0
  65. package/dist/index.js +43 -1
  66. package/dist/index.js.map +1 -1
  67. package/dist/schema-definition.type-C9PntBVc.d.cts +166 -0
  68. package/dist/schema-definition.type-CuhQLDr0.d.ts +166 -0
  69. package/package.json +31 -1
  70. package/dist/chunk-2BVCU32G.js.map +0 -1
  71. package/dist/chunk-H5TNDC5U.js +0 -138
  72. package/dist/chunk-H5TNDC5U.js.map +0 -1
  73. /package/dist/{chunk-XWKHOLIP.js.map → chunk-4HMXTGHK.js.map} +0 -0
  74. /package/dist/{chunk-4BVOLXDJ.js.map → chunk-4YBAV6LZ.js.map} +0 -0
@@ -0,0 +1,586 @@
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/presentation/graphql/shared/index.ts
21
+ var shared_exports = {};
22
+ __export(shared_exports, {
23
+ getGraphQLErrorCode: () => getGraphQLErrorCode,
24
+ mapErrorToGraphQLError: () => mapErrorToGraphQLError,
25
+ shouldMaskGraphQLError: () => shouldMaskGraphQLError
26
+ });
27
+ module.exports = __toCommonJS(shared_exports);
28
+
29
+ // src/global/exceptions/coded-error.error.ts
30
+ var CodedError = class extends Error {
31
+ /** Machine-readable error code for programmatic handling. */
32
+ code;
33
+ /**
34
+ * Creates a new CodedError instance.
35
+ *
36
+ * @param options - Error configuration
37
+ * @param options.message - Human-readable error message
38
+ * @param options.code - Machine-readable error code from ErrorCodes registry or custom string
39
+ * @param options.cause - Optional underlying error that caused this error
40
+ */
41
+ constructor({
42
+ message,
43
+ code,
44
+ cause
45
+ }) {
46
+ super(message);
47
+ this.name = this.constructor.name;
48
+ this.code = code;
49
+ if (cause !== void 0) {
50
+ Object.defineProperty(this, "cause", {
51
+ value: cause,
52
+ writable: false,
53
+ enumerable: false,
54
+ configurable: true
55
+ });
56
+ }
57
+ }
58
+ /**
59
+ * Factory method to create a typed error from a caught error.
60
+ *
61
+ * Subclasses should override this to provide proper error transformation.
62
+ * Designed for use with {@link wrapErrorAsync} and {@link wrapError}.
63
+ *
64
+ * @param _cause - The original caught error
65
+ * @returns A new CodedError instance
66
+ * @throws {Error} If not overridden by subclass
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * class NotFoundError extends UseCaseError {
71
+ * static override fromError(cause: unknown): NotFoundError {
72
+ * return new NotFoundError({
73
+ * message: 'Resource not found',
74
+ * cause,
75
+ * });
76
+ * }
77
+ * }
78
+ * ```
79
+ */
80
+ static fromError(_cause) {
81
+ throw new Error(`${this.name}.fromError() must be implemented by subclass`);
82
+ }
83
+ };
84
+
85
+ // src/global/exceptions/error-codes.const.ts
86
+ var ErrorCodes = {
87
+ /**
88
+ * Domain layer error codes.
89
+ * Used for business rule violations and invariant failures.
90
+ */
91
+ Domain: {
92
+ /** Generic domain error */
93
+ DOMAIN_ERROR: "DOMAIN_ERROR",
94
+ /** Business invariant was violated */
95
+ INVARIANT_VIOLATION: "INVARIANT_VIOLATION",
96
+ /** Aggregate was partially loaded (missing required relations) */
97
+ PARTIAL_LOAD: "PARTIAL_LOAD"
98
+ },
99
+ /**
100
+ * Application layer (use case) error codes.
101
+ * Used for orchestration failures and business operation errors.
102
+ */
103
+ App: {
104
+ /** Generic use case error */
105
+ USE_CASE_ERROR: "USE_CASE_ERROR",
106
+ /** Requested resource was not found */
107
+ NOT_FOUND: "NOT_FOUND",
108
+ /** Resource state conflict (e.g., duplicate, already exists) */
109
+ CONFLICT: "CONFLICT",
110
+ /** Request is valid but cannot be processed due to business rules */
111
+ UNPROCESSABLE: "UNPROCESSABLE",
112
+ /** Authorization denied - user lacks permission for this operation */
113
+ FORBIDDEN: "FORBIDDEN",
114
+ /** Authentication required or invalid - user is not authenticated */
115
+ UNAUTHORIZED: "UNAUTHORIZED"
116
+ },
117
+ /**
118
+ * Infrastructure layer error codes.
119
+ * Used for data access, external services, and I/O failures.
120
+ */
121
+ Infra: {
122
+ /** Generic infrastructure error */
123
+ INFRA_ERROR: "INFRA_ERROR",
124
+ /** Database operation failed */
125
+ DB_ERROR: "DB_ERROR",
126
+ /** Network connectivity or communication error */
127
+ NETWORK_ERROR: "NETWORK_ERROR",
128
+ /** Operation timed out */
129
+ TIMEOUT_ERROR: "TIMEOUT_ERROR",
130
+ /** External/third-party service error */
131
+ EXTERNAL_SERVICE_ERROR: "EXTERNAL_SERVICE_ERROR"
132
+ },
133
+ /**
134
+ * Presentation layer error codes.
135
+ * Used for controller, request handling, and authorization errors.
136
+ */
137
+ Presentation: {
138
+ /** Generic controller error */
139
+ CONTROLLER_ERROR: "CONTROLLER_ERROR",
140
+ /** Request denied due to authorization failure */
141
+ ACCESS_DENIED: "ACCESS_DENIED",
142
+ /** Request validation failed (malformed input) */
143
+ INVALID_REQUEST: "INVALID_REQUEST"
144
+ },
145
+ /**
146
+ * Global/cross-cutting error codes.
147
+ * Used for validation and other cross-layer concerns.
148
+ */
149
+ Global: {
150
+ /** Object/schema validation failed */
151
+ OBJECT_VALIDATION_ERROR: "OBJECT_VALIDATION_ERROR"
152
+ }
153
+ };
154
+
155
+ // src/global/exceptions/object-validation.error.ts
156
+ var ObjectValidationError = class _ObjectValidationError extends CodedError {
157
+ /**
158
+ * Array of field-level validation errors.
159
+ *
160
+ * Each entry contains:
161
+ * - `field`: Dot-notation path to the invalid field (e.g., 'user.email')
162
+ * - `message`: Human-readable validation failure message
163
+ */
164
+ validationErrors;
165
+ /**
166
+ * Creates a new ObjectValidationError instance.
167
+ *
168
+ * @param options - Error configuration
169
+ * @param options.message - Human-readable summary message
170
+ * @param options.code - Machine-readable error code (default: 'OBJECT_VALIDATION_ERROR')
171
+ * @param options.cause - Optional underlying error from validation library
172
+ * @param options.validationErrors - Array of field-level validation errors
173
+ */
174
+ constructor({
175
+ message,
176
+ code = ErrorCodes.Global.OBJECT_VALIDATION_ERROR,
177
+ cause,
178
+ validationErrors
179
+ }) {
180
+ super({ message, code, cause });
181
+ this.validationErrors = validationErrors;
182
+ }
183
+ /**
184
+ * Creates an ObjectValidationError from a caught error.
185
+ *
186
+ * @param cause - The original caught error
187
+ * @returns A new ObjectValidationError instance with the cause attached
188
+ */
189
+ static fromError(cause) {
190
+ return new _ObjectValidationError({
191
+ message: cause instanceof Error ? cause.message : "Validation failed",
192
+ cause,
193
+ validationErrors: []
194
+ });
195
+ }
196
+ };
197
+
198
+ // src/domain/exceptions/domain.error.ts
199
+ var DomainError = class _DomainError extends CodedError {
200
+ /**
201
+ * Creates a new DomainError instance.
202
+ *
203
+ * @param options - Error configuration
204
+ * @param options.message - Human-readable error description
205
+ * @param options.code - Machine-readable error code (default: 'DOMAIN_ERROR')
206
+ * @param options.cause - Optional underlying error
207
+ */
208
+ constructor({
209
+ message,
210
+ code = ErrorCodes.Domain.DOMAIN_ERROR,
211
+ cause
212
+ }) {
213
+ super({ message, code, cause });
214
+ }
215
+ /**
216
+ * Creates a DomainError from a caught error.
217
+ *
218
+ * @param cause - The original caught error
219
+ * @returns A new DomainError instance with the cause attached
220
+ */
221
+ static fromError(cause) {
222
+ return new _DomainError({
223
+ message: cause instanceof Error ? cause.message : "Domain error",
224
+ cause
225
+ });
226
+ }
227
+ };
228
+
229
+ // src/app/exceptions/use-case.error.ts
230
+ var UseCaseError = class _UseCaseError extends CodedError {
231
+ /**
232
+ * Creates a new UseCaseError instance.
233
+ *
234
+ * @param options - Error configuration
235
+ * @param options.message - Human-readable error description
236
+ * @param options.code - Machine-readable error code (default: 'USE_CASE_ERROR')
237
+ * @param options.cause - Optional underlying error
238
+ */
239
+ constructor({
240
+ message,
241
+ code = ErrorCodes.App.USE_CASE_ERROR,
242
+ cause
243
+ }) {
244
+ super({ message, code, cause });
245
+ }
246
+ /**
247
+ * Creates a UseCaseError from a caught error.
248
+ *
249
+ * @param cause - The original caught error
250
+ * @returns A new UseCaseError instance with the cause attached
251
+ */
252
+ static fromError(cause) {
253
+ return new _UseCaseError({
254
+ message: cause instanceof Error ? cause.message : "Use case error",
255
+ cause
256
+ });
257
+ }
258
+ };
259
+
260
+ // src/app/exceptions/not-found.error.ts
261
+ var NotFoundError = class _NotFoundError extends UseCaseError {
262
+ /**
263
+ * Creates a new NotFoundError instance.
264
+ *
265
+ * @param options - Error configuration
266
+ * @param options.message - Description of what was not found
267
+ * @param options.code - Machine-readable error code (default: 'NOT_FOUND')
268
+ * @param options.cause - Optional underlying error
269
+ */
270
+ constructor({
271
+ message,
272
+ code = ErrorCodes.App.NOT_FOUND,
273
+ cause
274
+ }) {
275
+ super({ message, code, cause });
276
+ }
277
+ /**
278
+ * Creates a NotFoundError from a caught error.
279
+ *
280
+ * @param cause - The original caught error
281
+ * @returns A new NotFoundError instance with the cause attached
282
+ */
283
+ static fromError(cause) {
284
+ return new _NotFoundError({
285
+ message: cause instanceof Error ? cause.message : "Resource not found",
286
+ cause
287
+ });
288
+ }
289
+ };
290
+
291
+ // src/app/exceptions/conflict.error.ts
292
+ var ConflictError = class _ConflictError extends UseCaseError {
293
+ /**
294
+ * Creates a new ConflictError instance.
295
+ *
296
+ * @param options - Error configuration
297
+ * @param options.message - Description of the conflict
298
+ * @param options.code - Machine-readable error code (default: 'CONFLICT')
299
+ * @param options.cause - Optional underlying error
300
+ */
301
+ constructor({
302
+ message,
303
+ code = ErrorCodes.App.CONFLICT,
304
+ cause
305
+ }) {
306
+ super({ message, code, cause });
307
+ }
308
+ /**
309
+ * Creates a ConflictError from a caught error.
310
+ *
311
+ * @param cause - The original caught error
312
+ * @returns A new ConflictError instance with the cause attached
313
+ */
314
+ static fromError(cause) {
315
+ return new _ConflictError({
316
+ message: cause instanceof Error ? cause.message : "Conflict error",
317
+ cause
318
+ });
319
+ }
320
+ };
321
+
322
+ // src/app/exceptions/unprocessable.error.ts
323
+ var UnprocessableError = class _UnprocessableError extends UseCaseError {
324
+ /**
325
+ * Creates a new UnprocessableError instance.
326
+ *
327
+ * @param options - Error configuration
328
+ * @param options.message - Description of why the request cannot be processed
329
+ * @param options.code - Machine-readable error code (default: 'UNPROCESSABLE')
330
+ * @param options.cause - Optional underlying error
331
+ */
332
+ constructor({
333
+ message,
334
+ code = ErrorCodes.App.UNPROCESSABLE,
335
+ cause
336
+ }) {
337
+ super({ message, code, cause });
338
+ }
339
+ /**
340
+ * Creates an UnprocessableError from a caught error.
341
+ *
342
+ * @param cause - The original caught error
343
+ * @returns A new UnprocessableError instance with the cause attached
344
+ */
345
+ static fromError(cause) {
346
+ return new _UnprocessableError({
347
+ message: cause instanceof Error ? cause.message : "Unprocessable request",
348
+ cause
349
+ });
350
+ }
351
+ };
352
+
353
+ // src/app/exceptions/forbidden.error.ts
354
+ var ForbiddenError = class _ForbiddenError extends UseCaseError {
355
+ /**
356
+ * Creates a new ForbiddenError instance.
357
+ *
358
+ * @param options - Error configuration
359
+ * @param options.message - Description of why authorization was denied
360
+ * @param options.code - Machine-readable error code (default: 'FORBIDDEN')
361
+ * @param options.cause - Optional underlying error
362
+ */
363
+ constructor({
364
+ message,
365
+ code = ErrorCodes.App.FORBIDDEN,
366
+ cause
367
+ }) {
368
+ super({ message, code, cause });
369
+ }
370
+ /**
371
+ * Creates a ForbiddenError from a caught error.
372
+ *
373
+ * @param cause - The original caught error
374
+ * @returns A new ForbiddenError instance with the cause attached
375
+ */
376
+ static fromError(cause) {
377
+ return new _ForbiddenError({
378
+ message: cause instanceof Error ? cause.message : "Operation forbidden",
379
+ cause
380
+ });
381
+ }
382
+ };
383
+
384
+ // src/app/exceptions/unauthorized.error.ts
385
+ var UnauthorizedError = class _UnauthorizedError extends UseCaseError {
386
+ /**
387
+ * Creates a new UnauthorizedError instance.
388
+ *
389
+ * @param options - Error configuration
390
+ * @param options.message - Description of why authentication failed
391
+ * @param options.code - Machine-readable error code (default: 'UNAUTHORIZED')
392
+ * @param options.cause - Optional underlying error
393
+ */
394
+ constructor({
395
+ message,
396
+ code = ErrorCodes.App.UNAUTHORIZED,
397
+ cause
398
+ }) {
399
+ super({ message, code, cause });
400
+ }
401
+ /**
402
+ * Creates an UnauthorizedError from a caught error.
403
+ *
404
+ * @param cause - The original caught error
405
+ * @returns A new UnauthorizedError instance with the cause attached
406
+ */
407
+ static fromError(cause) {
408
+ return new _UnauthorizedError({
409
+ message: cause instanceof Error ? cause.message : "Authentication required",
410
+ cause
411
+ });
412
+ }
413
+ };
414
+
415
+ // src/infra/exceptions/infra.error.ts
416
+ var InfraError = class _InfraError extends CodedError {
417
+ /**
418
+ * Creates a new InfraError instance.
419
+ *
420
+ * @param options - Error configuration
421
+ * @param options.message - Human-readable error description
422
+ * @param options.code - Machine-readable error code (default: 'INFRA_ERROR')
423
+ * @param options.cause - Optional underlying error
424
+ */
425
+ constructor({
426
+ message,
427
+ code = ErrorCodes.Infra.INFRA_ERROR,
428
+ cause
429
+ }) {
430
+ super({ message, code, cause });
431
+ }
432
+ /**
433
+ * Creates an InfraError from a caught error.
434
+ *
435
+ * @param cause - The original caught error
436
+ * @returns A new InfraError instance with the cause attached
437
+ */
438
+ static fromError(cause) {
439
+ return new _InfraError({
440
+ message: cause instanceof Error ? cause.message : "Infrastructure error",
441
+ cause
442
+ });
443
+ }
444
+ };
445
+
446
+ // src/presentation/exceptions/access-denied.error.ts
447
+ var AccessDeniedError = class _AccessDeniedError extends CodedError {
448
+ /**
449
+ * Creates a new AccessDeniedError instance.
450
+ *
451
+ * @param options - Error configuration
452
+ * @param options.message - Description of why access was denied
453
+ * @param options.code - Machine-readable error code (default: 'ACCESS_DENIED')
454
+ * @param options.cause - Optional underlying error
455
+ */
456
+ constructor({
457
+ message,
458
+ code = ErrorCodes.Presentation.ACCESS_DENIED,
459
+ cause
460
+ }) {
461
+ super({ message, code, cause });
462
+ }
463
+ /**
464
+ * Creates an AccessDeniedError from a caught error.
465
+ *
466
+ * @param cause - The original caught error
467
+ * @returns A new AccessDeniedError instance with the cause attached
468
+ */
469
+ static fromError(cause) {
470
+ return new _AccessDeniedError({
471
+ message: cause instanceof Error ? cause.message : "Access denied",
472
+ cause
473
+ });
474
+ }
475
+ };
476
+
477
+ // src/presentation/http/shared/error-mapping.ts
478
+ function isErrorType(error, typeName) {
479
+ if (!error || typeof error !== "object") return false;
480
+ const constructor = Object.prototype.hasOwnProperty.call(error, "constructor") ? error.constructor : Object.getPrototypeOf(error)?.constructor;
481
+ if (!constructor) return false;
482
+ const name = constructor.name;
483
+ return name === typeName || name === `_${typeName}`;
484
+ }
485
+ function hasValidationErrors(error) {
486
+ if (!error || typeof error !== "object") return false;
487
+ return "validationErrors" in error && Array.isArray(error.validationErrors);
488
+ }
489
+
490
+ // src/presentation/graphql/shared/error-mapping.ts
491
+ var MASKED_ERROR = {
492
+ message: "An unexpected error occurred",
493
+ extensions: { code: "INTERNAL_ERROR" }
494
+ };
495
+ var INTERNAL_ERROR_TYPES = [
496
+ "DomainError",
497
+ "InfraError",
498
+ "ControllerError",
499
+ "NetworkError",
500
+ "PersistenceError",
501
+ "ExternalServiceError",
502
+ "InvariantViolationError"
503
+ ];
504
+ function getGraphQLErrorCode(error) {
505
+ if (error instanceof ObjectValidationError) return "VALIDATION_ERROR";
506
+ if (error instanceof UnauthorizedError) return "FORBIDDEN";
507
+ if (error instanceof ForbiddenError) return "FORBIDDEN";
508
+ if (error instanceof AccessDeniedError) return "FORBIDDEN";
509
+ if (error instanceof NotFoundError) return "NOT_FOUND";
510
+ if (error instanceof ConflictError) return "CONFLICT";
511
+ if (error instanceof UnprocessableError) return "UNPROCESSABLE";
512
+ if (error instanceof UseCaseError) return "BAD_REQUEST";
513
+ if (isErrorType(error, "ObjectValidationError")) return "VALIDATION_ERROR";
514
+ if (isErrorType(error, "UnauthorizedError")) return "FORBIDDEN";
515
+ if (isErrorType(error, "ForbiddenError")) return "FORBIDDEN";
516
+ if (isErrorType(error, "AccessDeniedError")) return "FORBIDDEN";
517
+ if (isErrorType(error, "NotFoundError")) return "NOT_FOUND";
518
+ if (isErrorType(error, "ConflictError")) return "CONFLICT";
519
+ if (isErrorType(error, "UnprocessableError")) return "UNPROCESSABLE";
520
+ if (isErrorType(error, "UseCaseError")) return "BAD_REQUEST";
521
+ return "INTERNAL_ERROR";
522
+ }
523
+ function shouldMaskGraphQLError(error) {
524
+ if (error instanceof DomainError || error instanceof InfraError) {
525
+ return true;
526
+ }
527
+ for (const errorType of INTERNAL_ERROR_TYPES) {
528
+ if (isErrorType(error, errorType)) {
529
+ return true;
530
+ }
531
+ }
532
+ return false;
533
+ }
534
+ function mapErrorToGraphQLError(error) {
535
+ if (shouldMaskGraphQLError(error)) {
536
+ return MASKED_ERROR;
537
+ }
538
+ const code = getGraphQLErrorCode(error);
539
+ if (error instanceof ObjectValidationError) {
540
+ return buildValidationError(error.message, code, error.code, error.validationErrors);
541
+ }
542
+ if (isErrorType(error, "ObjectValidationError") && hasValidationErrors(error)) {
543
+ return buildValidationError(error.message, code, error.code, error.validationErrors);
544
+ }
545
+ if (error instanceof CodedError) {
546
+ return {
547
+ message: error.message,
548
+ extensions: { code, originalCode: error.code }
549
+ };
550
+ }
551
+ if (isErrorType(error, "CodedError")) {
552
+ return {
553
+ message: error.message,
554
+ extensions: { code, originalCode: error.code }
555
+ };
556
+ }
557
+ if (error && typeof error === "object" && "message" in error && "code" in error && typeof error.message === "string" && typeof error.code === "string") {
558
+ return {
559
+ message: error.message,
560
+ extensions: { code, originalCode: error.code }
561
+ };
562
+ }
563
+ return MASKED_ERROR;
564
+ }
565
+ function buildValidationError(message, code, originalCode, validationErrors) {
566
+ return {
567
+ message,
568
+ extensions: {
569
+ code,
570
+ originalCode,
571
+ validationErrors: validationErrors.map(
572
+ (e) => ({
573
+ field: e.field,
574
+ message: e.message
575
+ })
576
+ )
577
+ }
578
+ };
579
+ }
580
+ // Annotate the CommonJS export names for ESM import in node:
581
+ 0 && (module.exports = {
582
+ getGraphQLErrorCode,
583
+ mapErrorToGraphQLError,
584
+ shouldMaskGraphQLError
585
+ });
586
+ //# sourceMappingURL=index.cjs.map