@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.
- package/dist/backend/core/global.cjs +283 -0
- package/dist/backend/core/global.cjs.map +1 -0
- package/dist/backend/core/global.d.cts +294 -0
- package/dist/backend/core/global.d.ts +294 -0
- package/dist/backend/core/global.js +39 -0
- package/dist/backend/core/global.js.map +1 -0
- package/dist/backend/core/onion-layers.cjs +2302 -0
- package/dist/backend/core/onion-layers.cjs.map +1 -0
- package/dist/backend/core/onion-layers.d.cts +1675 -0
- package/dist/backend/core/onion-layers.d.ts +1675 -0
- package/dist/backend/core/onion-layers.js +1158 -0
- package/dist/backend/core/onion-layers.js.map +1 -0
- package/dist/backend/core/presentation.cjs +573 -0
- package/dist/backend/core/presentation.cjs.map +1 -0
- package/dist/backend/core/presentation.d.cts +5 -0
- package/dist/backend/core/presentation.d.ts +5 -0
- package/dist/backend/core/presentation.js +28 -0
- package/dist/backend/core/presentation.js.map +1 -0
- package/dist/backend/core/validators/arktype.cjs +947 -0
- package/dist/backend/core/validators/arktype.cjs.map +1 -0
- package/dist/backend/core/validators/arktype.d.cts +188 -0
- package/dist/backend/core/validators/arktype.d.ts +188 -0
- package/dist/backend/core/validators/arktype.js +287 -0
- package/dist/backend/core/validators/arktype.js.map +1 -0
- package/dist/backend/core/validators/typebox.cjs +939 -0
- package/dist/backend/core/validators/typebox.cjs.map +1 -0
- package/dist/backend/core/validators/typebox.d.cts +189 -0
- package/dist/backend/core/validators/typebox.d.ts +189 -0
- package/dist/backend/core/validators/typebox.js +281 -0
- package/dist/backend/core/validators/typebox.js.map +1 -0
- package/dist/backend/core/validators/valibot.cjs +942 -0
- package/dist/backend/core/validators/valibot.cjs.map +1 -0
- package/dist/backend/core/validators/valibot.d.cts +160 -0
- package/dist/backend/core/validators/valibot.d.ts +160 -0
- package/dist/backend/core/validators/valibot.js +294 -0
- package/dist/backend/core/validators/valibot.js.map +1 -0
- package/dist/backend/core/validators/zod.cjs +934 -0
- package/dist/backend/core/validators/zod.cjs.map +1 -0
- package/dist/backend/core/validators/zod.d.cts +188 -0
- package/dist/backend/core/validators/zod.d.ts +188 -0
- package/dist/backend/core/validators/zod.js +278 -0
- package/dist/backend/core/validators/zod.js.map +1 -0
- package/dist/backend/frameworks/elysia.cjs +715 -0
- package/dist/backend/frameworks/elysia.cjs.map +1 -0
- package/dist/backend/frameworks/elysia.d.cts +208 -0
- package/dist/backend/frameworks/elysia.d.ts +208 -0
- package/dist/backend/frameworks/elysia.js +251 -0
- package/dist/backend/frameworks/elysia.js.map +1 -0
- package/dist/backend/frameworks/fastify.cjs +677 -0
- package/dist/backend/frameworks/fastify.cjs.map +1 -0
- package/dist/backend/frameworks/fastify.d.cts +201 -0
- package/dist/backend/frameworks/fastify.d.ts +201 -0
- package/dist/backend/frameworks/fastify.js +213 -0
- package/dist/backend/frameworks/fastify.js.map +1 -0
- package/dist/backend/frameworks/hono.cjs +715 -0
- package/dist/backend/frameworks/hono.cjs.map +1 -0
- package/dist/backend/frameworks/hono.d.cts +163 -0
- package/dist/backend/frameworks/hono.d.ts +163 -0
- package/dist/backend/frameworks/hono.js +249 -0
- package/dist/backend/frameworks/hono.js.map +1 -0
- package/dist/backend/frameworks/nestjs.cjs +260 -0
- package/dist/backend/frameworks/nestjs.cjs.map +1 -0
- package/dist/backend/frameworks/nestjs.d.cts +168 -0
- package/dist/backend/frameworks/nestjs.d.ts +168 -0
- package/dist/backend/frameworks/nestjs.js +193 -0
- package/dist/backend/frameworks/nestjs.js.map +1 -0
- package/dist/base-dto.class-D7W9iqoU.d.cts +146 -0
- package/dist/base-dto.class-D7W9iqoU.d.ts +146 -0
- package/dist/base-uuid-v7.vo-BPGEIWLM.d.ts +799 -0
- package/dist/base-uuid-v7.vo-BjqKX44G.d.cts +799 -0
- package/dist/chunk-74IKUOSE.js +116 -0
- package/dist/chunk-74IKUOSE.js.map +1 -0
- package/dist/chunk-BKZOLGQW.js +29 -0
- package/dist/chunk-BKZOLGQW.js.map +1 -0
- package/dist/chunk-CGZBV6BD.js +54 -0
- package/dist/chunk-CGZBV6BD.js.map +1 -0
- package/dist/chunk-DDAHJZVK.js +258 -0
- package/dist/chunk-DDAHJZVK.js.map +1 -0
- package/dist/chunk-MQD5GXMT.js +171 -0
- package/dist/chunk-MQD5GXMT.js.map +1 -0
- package/dist/chunk-OKFXZHBC.js +43 -0
- package/dist/chunk-OKFXZHBC.js.map +1 -0
- package/dist/chunk-RLLWYFPI.js +168 -0
- package/dist/chunk-RLLWYFPI.js.map +1 -0
- package/dist/chunk-VCHFXT5W.js +425 -0
- package/dist/chunk-VCHFXT5W.js.map +1 -0
- package/dist/chunk-ZWLYNGO3.js +40 -0
- package/dist/chunk-ZWLYNGO3.js.map +1 -0
- package/dist/http-response-BAhi8lF4.d.cts +124 -0
- package/dist/http-response-BAhi8lF4.d.ts +124 -0
- package/dist/index-DingXh7B.d.cts +1187 -0
- package/dist/index-tOH7XBa3.d.ts +1187 -0
- package/dist/routing.type-DB4pt-d9.d.ts +184 -0
- package/dist/routing.type-DF2BIL7x.d.cts +184 -0
- package/dist/validation-error.type-kD4_qNZ9.d.cts +199 -0
- package/dist/validation-error.type-kD4_qNZ9.d.ts +199 -0
- package/package.json +191 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// src/backend/core/global/exceptions/coded-error.error.ts
|
|
2
|
+
var CodedError = class extends Error {
|
|
3
|
+
/** Machine-readable error code for programmatic handling. */
|
|
4
|
+
code;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new CodedError instance.
|
|
7
|
+
*
|
|
8
|
+
* @param options - Error configuration
|
|
9
|
+
* @param options.message - Human-readable error message
|
|
10
|
+
* @param options.code - Machine-readable error code from ErrorCodes registry or custom string
|
|
11
|
+
* @param options.cause - Optional underlying error that caused this error
|
|
12
|
+
*/
|
|
13
|
+
constructor({
|
|
14
|
+
message,
|
|
15
|
+
code,
|
|
16
|
+
cause
|
|
17
|
+
}) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = this.constructor.name;
|
|
20
|
+
this.code = code;
|
|
21
|
+
if (cause !== void 0) {
|
|
22
|
+
Object.defineProperty(this, "cause", {
|
|
23
|
+
value: cause,
|
|
24
|
+
writable: false,
|
|
25
|
+
enumerable: false,
|
|
26
|
+
configurable: true
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Factory method to create a typed error from a caught error.
|
|
32
|
+
*
|
|
33
|
+
* Subclasses should override this to provide proper error transformation.
|
|
34
|
+
* Designed for use with {@link wrapErrorAsync} and {@link wrapError}.
|
|
35
|
+
*
|
|
36
|
+
* @param _cause - The original caught error
|
|
37
|
+
* @returns A new CodedError instance
|
|
38
|
+
* @throws {Error} If not overridden by subclass
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* class NotFoundError extends UseCaseError {
|
|
43
|
+
* static override fromError(cause: unknown): NotFoundError {
|
|
44
|
+
* return new NotFoundError({
|
|
45
|
+
* message: 'Resource not found',
|
|
46
|
+
* cause,
|
|
47
|
+
* });
|
|
48
|
+
* }
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
static fromError(_cause) {
|
|
53
|
+
throw new Error(`${this.name}.fromError() must be implemented by subclass`);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/backend/core/global/exceptions/error-codes.const.ts
|
|
58
|
+
var ErrorCodes = {
|
|
59
|
+
/**
|
|
60
|
+
* Domain layer error codes.
|
|
61
|
+
* Used for business rule violations and invariant failures.
|
|
62
|
+
*/
|
|
63
|
+
Domain: {
|
|
64
|
+
/** Generic domain error */
|
|
65
|
+
DOMAIN_ERROR: "DOMAIN_ERROR",
|
|
66
|
+
/** Business invariant was violated */
|
|
67
|
+
INVARIANT_VIOLATION: "INVARIANT_VIOLATION",
|
|
68
|
+
/** Aggregate was partially loaded (missing required relations) */
|
|
69
|
+
PARTIAL_LOAD: "PARTIAL_LOAD"
|
|
70
|
+
},
|
|
71
|
+
/**
|
|
72
|
+
* Application layer (use case) error codes.
|
|
73
|
+
* Used for orchestration failures and business operation errors.
|
|
74
|
+
*/
|
|
75
|
+
App: {
|
|
76
|
+
/** Generic use case error */
|
|
77
|
+
USE_CASE_ERROR: "USE_CASE_ERROR",
|
|
78
|
+
/** Requested resource was not found */
|
|
79
|
+
NOT_FOUND: "NOT_FOUND",
|
|
80
|
+
/** Resource state conflict (e.g., duplicate, already exists) */
|
|
81
|
+
CONFLICT: "CONFLICT",
|
|
82
|
+
/** Request is valid but cannot be processed due to business rules */
|
|
83
|
+
UNPROCESSABLE: "UNPROCESSABLE"
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* Infrastructure layer error codes.
|
|
87
|
+
* Used for data access, external services, and I/O failures.
|
|
88
|
+
*/
|
|
89
|
+
Infra: {
|
|
90
|
+
/** Generic infrastructure error */
|
|
91
|
+
INFRA_ERROR: "INFRA_ERROR",
|
|
92
|
+
/** Database operation failed */
|
|
93
|
+
DB_ERROR: "DB_ERROR",
|
|
94
|
+
/** Network connectivity or communication error */
|
|
95
|
+
NETWORK_ERROR: "NETWORK_ERROR",
|
|
96
|
+
/** Operation timed out */
|
|
97
|
+
TIMEOUT_ERROR: "TIMEOUT_ERROR",
|
|
98
|
+
/** External/third-party service error */
|
|
99
|
+
EXTERNAL_SERVICE_ERROR: "EXTERNAL_SERVICE_ERROR"
|
|
100
|
+
},
|
|
101
|
+
/**
|
|
102
|
+
* Presentation layer error codes.
|
|
103
|
+
* Used for controller, request handling, and authorization errors.
|
|
104
|
+
*/
|
|
105
|
+
Presentation: {
|
|
106
|
+
/** Generic controller error */
|
|
107
|
+
CONTROLLER_ERROR: "CONTROLLER_ERROR",
|
|
108
|
+
/** Request denied due to authorization failure */
|
|
109
|
+
ACCESS_DENIED: "ACCESS_DENIED",
|
|
110
|
+
/** Request validation failed (malformed input) */
|
|
111
|
+
INVALID_REQUEST: "INVALID_REQUEST"
|
|
112
|
+
},
|
|
113
|
+
/**
|
|
114
|
+
* Global/cross-cutting error codes.
|
|
115
|
+
* Used for validation and other cross-layer concerns.
|
|
116
|
+
*/
|
|
117
|
+
Global: {
|
|
118
|
+
/** Object/schema validation failed */
|
|
119
|
+
OBJECT_VALIDATION_ERROR: "OBJECT_VALIDATION_ERROR"
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// src/backend/core/global/exceptions/object-validation.error.ts
|
|
124
|
+
var ObjectValidationError = class _ObjectValidationError extends CodedError {
|
|
125
|
+
/**
|
|
126
|
+
* Array of field-level validation errors.
|
|
127
|
+
*
|
|
128
|
+
* Each entry contains:
|
|
129
|
+
* - `field`: Dot-notation path to the invalid field (e.g., 'user.email')
|
|
130
|
+
* - `message`: Human-readable validation failure message
|
|
131
|
+
*/
|
|
132
|
+
validationErrors;
|
|
133
|
+
/**
|
|
134
|
+
* Creates a new ObjectValidationError instance.
|
|
135
|
+
*
|
|
136
|
+
* @param options - Error configuration
|
|
137
|
+
* @param options.message - Human-readable summary message
|
|
138
|
+
* @param options.code - Machine-readable error code (default: 'OBJECT_VALIDATION_ERROR')
|
|
139
|
+
* @param options.cause - Optional underlying error from validation library
|
|
140
|
+
* @param options.validationErrors - Array of field-level validation errors
|
|
141
|
+
*/
|
|
142
|
+
constructor({
|
|
143
|
+
message,
|
|
144
|
+
code = ErrorCodes.Global.OBJECT_VALIDATION_ERROR,
|
|
145
|
+
cause,
|
|
146
|
+
validationErrors
|
|
147
|
+
}) {
|
|
148
|
+
super({ message, code, cause });
|
|
149
|
+
this.validationErrors = validationErrors;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Creates an ObjectValidationError from a caught error.
|
|
153
|
+
*
|
|
154
|
+
* @param cause - The original caught error
|
|
155
|
+
* @returns A new ObjectValidationError instance with the cause attached
|
|
156
|
+
*/
|
|
157
|
+
static fromError(cause) {
|
|
158
|
+
return new _ObjectValidationError({
|
|
159
|
+
message: cause instanceof Error ? cause.message : "Validation failed",
|
|
160
|
+
cause,
|
|
161
|
+
validationErrors: []
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export {
|
|
167
|
+
CodedError,
|
|
168
|
+
ErrorCodes,
|
|
169
|
+
ObjectValidationError
|
|
170
|
+
};
|
|
171
|
+
//# sourceMappingURL=chunk-MQD5GXMT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/backend/core/global/exceptions/coded-error.error.ts","../src/backend/core/global/exceptions/error-codes.const.ts","../src/backend/core/global/exceptions/object-validation.error.ts"],"sourcesContent":["import type { ErrorCode } from './error-codes.const';\n\n/**\n * Base error class for all application errors with a machine-readable code.\n *\n * Abstract class that extends the native `Error` with:\n * - A `code` property for programmatic error handling\n * - Optional `cause` for error chaining (ES2022 compatible)\n * - A `fromError` static factory pattern for error transformation\n *\n * **Why abstract:** Prevents non-declarative error usage. All errors must\n * be explicitly defined as subclasses to ensure consistent error taxonomy.\n *\n * @example Subclass implementation\n * ```typescript\n * class DbError extends InfraError {\n * static override fromError(cause: unknown): DbError {\n * return new DbError({\n * message: cause instanceof Error ? cause.message : 'Database error',\n * cause,\n * });\n * }\n * }\n * ```\n *\n * @example Usage with wrapErrorAsync\n * ```typescript\n * await wrapErrorAsync(\n * () => this.db.query(...),\n * DbError.fromError,\n * );\n * ```\n */\nexport abstract class CodedError extends Error {\n /** Machine-readable error code for programmatic handling. */\n public readonly code: ErrorCode | string;\n\n /**\n * Creates a new CodedError instance.\n *\n * @param options - Error configuration\n * @param options.message - Human-readable error message\n * @param options.code - Machine-readable error code from ErrorCodes registry or custom string\n * @param options.cause - Optional underlying error that caused this error\n */\n constructor({\n message,\n code,\n cause,\n }: {\n message: string;\n code: ErrorCode | string;\n cause?: unknown;\n }) {\n super(message);\n this.name = this.constructor.name;\n this.code = code;\n if (cause !== undefined) {\n Object.defineProperty(this, 'cause', {\n value: cause,\n writable: false,\n enumerable: false,\n configurable: true,\n });\n }\n }\n\n /**\n * Factory method to create a typed error from a caught error.\n *\n * Subclasses should override this to provide proper error transformation.\n * Designed for use with {@link wrapErrorAsync} and {@link wrapError}.\n *\n * @param _cause - The original caught error\n * @returns A new CodedError instance\n * @throws {Error} If not overridden by subclass\n *\n * @example\n * ```typescript\n * class NotFoundError extends UseCaseError {\n * static override fromError(cause: unknown): NotFoundError {\n * return new NotFoundError({\n * message: 'Resource not found',\n * cause,\n * });\n * }\n * }\n * ```\n */\n static fromError(_cause: unknown): CodedError {\n throw new Error(`${this.name}.fromError() must be implemented by subclass`);\n }\n}\n","/**\n * Centralized registry of all error codes used across the application.\n *\n * Error codes are grouped by architectural layer to maintain clear boundaries\n * and make it easy to identify where an error originated.\n *\n * @example Using error codes in custom errors\n * ```typescript\n * import { ErrorCodes } from '@cosmneo/onion-lasagna/backend/core/global';\n *\n * throw new NotFoundError({\n * message: 'User not found',\n * code: ErrorCodes.App.NOT_FOUND,\n * });\n * ```\n *\n * @example Checking error codes programmatically\n * ```typescript\n * if (error.code === ErrorCodes.App.NOT_FOUND) {\n * // Handle not found case\n * }\n * ```\n */\nexport const ErrorCodes = {\n /**\n * Domain layer error codes.\n * Used for business rule violations and invariant failures.\n */\n Domain: {\n /** Generic domain error */\n DOMAIN_ERROR: 'DOMAIN_ERROR',\n /** Business invariant was violated */\n INVARIANT_VIOLATION: 'INVARIANT_VIOLATION',\n /** Aggregate was partially loaded (missing required relations) */\n PARTIAL_LOAD: 'PARTIAL_LOAD',\n },\n\n /**\n * Application layer (use case) error codes.\n * Used for orchestration failures and business operation errors.\n */\n App: {\n /** Generic use case error */\n USE_CASE_ERROR: 'USE_CASE_ERROR',\n /** Requested resource was not found */\n NOT_FOUND: 'NOT_FOUND',\n /** Resource state conflict (e.g., duplicate, already exists) */\n CONFLICT: 'CONFLICT',\n /** Request is valid but cannot be processed due to business rules */\n UNPROCESSABLE: 'UNPROCESSABLE',\n },\n\n /**\n * Infrastructure layer error codes.\n * Used for data access, external services, and I/O failures.\n */\n Infra: {\n /** Generic infrastructure error */\n INFRA_ERROR: 'INFRA_ERROR',\n /** Database operation failed */\n DB_ERROR: 'DB_ERROR',\n /** Network connectivity or communication error */\n NETWORK_ERROR: 'NETWORK_ERROR',\n /** Operation timed out */\n TIMEOUT_ERROR: 'TIMEOUT_ERROR',\n /** External/third-party service error */\n EXTERNAL_SERVICE_ERROR: 'EXTERNAL_SERVICE_ERROR',\n },\n\n /**\n * Presentation layer error codes.\n * Used for controller, request handling, and authorization errors.\n */\n Presentation: {\n /** Generic controller error */\n CONTROLLER_ERROR: 'CONTROLLER_ERROR',\n /** Request denied due to authorization failure */\n ACCESS_DENIED: 'ACCESS_DENIED',\n /** Request validation failed (malformed input) */\n INVALID_REQUEST: 'INVALID_REQUEST',\n },\n\n /**\n * Global/cross-cutting error codes.\n * Used for validation and other cross-layer concerns.\n */\n Global: {\n /** Object/schema validation failed */\n OBJECT_VALIDATION_ERROR: 'OBJECT_VALIDATION_ERROR',\n },\n} as const;\n\n/**\n * Type representing all possible domain error codes.\n */\nexport type DomainErrorCode = (typeof ErrorCodes.Domain)[keyof typeof ErrorCodes.Domain];\n\n/**\n * Type representing all possible application error codes.\n */\nexport type AppErrorCode = (typeof ErrorCodes.App)[keyof typeof ErrorCodes.App];\n\n/**\n * Type representing all possible infrastructure error codes.\n */\nexport type InfraErrorCode = (typeof ErrorCodes.Infra)[keyof typeof ErrorCodes.Infra];\n\n/**\n * Type representing all possible presentation error codes.\n */\nexport type PresentationErrorCode =\n (typeof ErrorCodes.Presentation)[keyof typeof ErrorCodes.Presentation];\n\n/**\n * Type representing all possible global error codes.\n */\nexport type GlobalErrorCode = (typeof ErrorCodes.Global)[keyof typeof ErrorCodes.Global];\n\n/**\n * Union type of all error codes across all layers.\n *\n * Use this when you need to accept any valid error code.\n *\n * @example\n * ```typescript\n * function logError(code: ErrorCode, message: string) {\n * console.error(`[${code}] ${message}`);\n * }\n * ```\n */\nexport type ErrorCode =\n | DomainErrorCode\n | AppErrorCode\n | InfraErrorCode\n | PresentationErrorCode\n | GlobalErrorCode;\n","import { CodedError } from './coded-error.error';\nimport { ErrorCodes, type GlobalErrorCode } from './error-codes.const';\nimport type { ValidationError } from '../interfaces/types/validation-error.type';\n\n/**\n * Error thrown when object validation fails.\n *\n * Contains structured validation errors with field paths and messages,\n * making it easy to report specific validation failures to clients.\n * Thrown by all validator implementations (Zod, ArkType, TypeBox, Valibot).\n *\n * **Flow:**\n * 1. Validator throws `ObjectValidationError` with field-level errors\n * 2. Controller catches and converts to {@link InvalidRequestError}\n * 3. HTTP layer maps to 400 Bad Request with error details\n *\n * @example\n * ```typescript\n * try {\n * const dto = CreateUserDto.create(invalidData);\n * } catch (error) {\n * if (error instanceof ObjectValidationError) {\n * console.log(error.validationErrors);\n * // [\n * // { field: 'email', message: 'Invalid email format' },\n * // { field: 'age', message: 'Must be a positive number' }\n * // ]\n * }\n * }\n * ```\n */\nexport class ObjectValidationError extends CodedError {\n /**\n * Array of field-level validation errors.\n *\n * Each entry contains:\n * - `field`: Dot-notation path to the invalid field (e.g., 'user.email')\n * - `message`: Human-readable validation failure message\n */\n validationErrors: ValidationError[];\n\n /**\n * Creates a new ObjectValidationError instance.\n *\n * @param options - Error configuration\n * @param options.message - Human-readable summary message\n * @param options.code - Machine-readable error code (default: 'OBJECT_VALIDATION_ERROR')\n * @param options.cause - Optional underlying error from validation library\n * @param options.validationErrors - Array of field-level validation errors\n */\n constructor({\n message,\n code = ErrorCodes.Global.OBJECT_VALIDATION_ERROR,\n cause,\n validationErrors,\n }: {\n message: string;\n code?: GlobalErrorCode | string;\n cause?: unknown;\n validationErrors: ValidationError[];\n }) {\n super({ message, code, cause });\n this.validationErrors = validationErrors;\n }\n\n /**\n * Creates an ObjectValidationError from a caught error.\n *\n * @param cause - The original caught error\n * @returns A new ObjectValidationError instance with the cause attached\n */\n static override fromError(cause: unknown): ObjectValidationError {\n return new ObjectValidationError({\n message: cause instanceof Error ? cause.message : 'Validation failed',\n cause,\n validationErrors: [],\n });\n }\n}\n"],"mappings":";AAiCO,IAAe,aAAf,cAAkC,MAAM;AAAA;AAAA,EAE7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUhB,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAIG;AACD,UAAM,OAAO;AACb,SAAK,OAAO,KAAK,YAAY;AAC7B,SAAK,OAAO;AACZ,QAAI,UAAU,QAAW;AACvB,aAAO,eAAe,MAAM,SAAS;AAAA,QACnC,OAAO;AAAA,QACP,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,cAAc;AAAA,MAChB,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwBA,OAAO,UAAU,QAA6B;AAC5C,UAAM,IAAI,MAAM,GAAG,KAAK,IAAI,8CAA8C;AAAA,EAC5E;AACF;;;ACrEO,IAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxB,QAAQ;AAAA;AAAA,IAEN,cAAc;AAAA;AAAA,IAEd,qBAAqB;AAAA;AAAA,IAErB,cAAc;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAK;AAAA;AAAA,IAEH,gBAAgB;AAAA;AAAA,IAEhB,WAAW;AAAA;AAAA,IAEX,UAAU;AAAA;AAAA,IAEV,eAAe;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO;AAAA;AAAA,IAEL,aAAa;AAAA;AAAA,IAEb,UAAU;AAAA;AAAA,IAEV,eAAe;AAAA;AAAA,IAEf,eAAe;AAAA;AAAA,IAEf,wBAAwB;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAc;AAAA;AAAA,IAEZ,kBAAkB;AAAA;AAAA,IAElB,eAAe;AAAA;AAAA,IAEf,iBAAiB;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAQ;AAAA;AAAA,IAEN,yBAAyB;AAAA,EAC3B;AACF;;;AC3DO,IAAM,wBAAN,MAAM,+BAA8B,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,YAAY;AAAA,IACV;AAAA,IACA,OAAO,WAAW,OAAO;AAAA,IACzB;AAAA,IACA;AAAA,EACF,GAKG;AACD,UAAM,EAAE,SAAS,MAAM,MAAM,CAAC;AAC9B,SAAK,mBAAmB;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAgB,UAAU,OAAuC;AAC/D,WAAO,IAAI,uBAAsB;AAAA,MAC/B,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD;AAAA,MACA,kBAAkB,CAAC;AAAA,IACrB,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/backend/core/global/utils/wrap-error.util.ts
|
|
2
|
+
function wrapError(fn, errorFactory) {
|
|
3
|
+
try {
|
|
4
|
+
return fn();
|
|
5
|
+
} catch (error) {
|
|
6
|
+
throw errorFactory(error);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
async function wrapErrorAsync(fn, errorFactory) {
|
|
10
|
+
try {
|
|
11
|
+
return await fn();
|
|
12
|
+
} catch (error) {
|
|
13
|
+
throw errorFactory(error);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function wrapErrorUnless(fn, errorFactory, passthroughTypes) {
|
|
17
|
+
try {
|
|
18
|
+
return fn();
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (passthroughTypes.some((Type) => error instanceof Type)) {
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
throw errorFactory(error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function wrapErrorUnlessAsync(fn, errorFactory, passthroughTypes) {
|
|
27
|
+
try {
|
|
28
|
+
return await fn();
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (passthroughTypes.some((Type) => error instanceof Type)) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
throw errorFactory(error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
wrapError,
|
|
39
|
+
wrapErrorAsync,
|
|
40
|
+
wrapErrorUnless,
|
|
41
|
+
wrapErrorUnlessAsync
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=chunk-OKFXZHBC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/backend/core/global/utils/wrap-error.util.ts"],"sourcesContent":["/**\n * Error wrapping utilities for boundary error handling.\n *\n * Provides functions to wrap code execution with error transformation,\n * converting caught errors into typed Error instances.\n * Useful at layer boundaries (infra, use case, controller) to normalize errors.\n *\n * @example Wrapping async database calls\n * ```typescript\n * const user = await wrapErrorAsync(\n * () => this.db.query('SELECT * FROM users WHERE id = ?', [id]),\n * (cause) => new DbError({ message: 'Failed to fetch user', cause }),\n * );\n * ```\n *\n * @example Wrapping sync operations\n * ```typescript\n * const parsed = wrapError(\n * () => JSON.parse(data),\n * (cause) => new InvariantViolationError({\n * message: 'Invalid JSON format',\n * cause,\n * }),\n * );\n * ```\n *\n * @module\n */\n\n/**\n * Factory function that creates an Error from a caught error.\n *\n * @typeParam E - The specific Error subclass to create\n * @param cause - The original caught error\n * @returns A new Error instance\n */\nexport type ErrorFactory<E extends Error> = (cause: unknown) => E;\n\n/**\n * Wraps a synchronous function with error transformation.\n *\n * Executes the provided function and catches any thrown errors,\n * transforming them using the error factory.\n *\n * @typeParam T - The return type of the wrapped function\n * @typeParam E - The Error subclass to throw on error\n * @param fn - The function to execute\n * @param errorFactory - Factory to create the typed error from the caught error\n * @returns The result of the function if successful\n * @throws {E} The transformed error if the function throws\n *\n * @example\n * ```typescript\n * const config = wrapError(\n * () => JSON.parse(configString),\n * (cause) => new InvariantViolationError({\n * message: 'Invalid configuration format',\n * code: 'CONFIG_PARSE_ERROR',\n * cause,\n * }),\n * );\n * ```\n */\nexport function wrapError<T, E extends Error>(fn: () => T, errorFactory: ErrorFactory<E>): T {\n try {\n return fn();\n } catch (error) {\n throw errorFactory(error);\n }\n}\n\n/**\n * Wraps an asynchronous function with error transformation.\n *\n * Executes the provided async function and catches any thrown errors,\n * transforming them using the error factory.\n *\n * @typeParam T - The return type of the wrapped function\n * @typeParam E - The Error subclass to throw on error\n * @param fn - The async function to execute\n * @param errorFactory - Factory to create the typed error from the caught error\n * @returns A promise resolving to the result if successful\n * @throws {E} The transformed error if the function throws\n *\n * @example Repository usage\n * ```typescript\n * async findById(id: string): Promise<User | null> {\n * return wrapErrorAsync(\n * () => this.db.users.findUnique({ where: { id } }),\n * (cause) => new DbError({\n * message: `Failed to find user by ID: ${id}`,\n * cause,\n * }),\n * );\n * }\n * ```\n *\n * @example External service usage\n * ```typescript\n * async sendEmail(to: string, body: string): Promise<void> {\n * await wrapErrorAsync(\n * () => this.emailClient.send({ to, body }),\n * (cause) => new ExternalServiceError({\n * message: 'Email delivery failed',\n * code: 'EMAIL_SEND_FAILED',\n * cause,\n * }),\n * );\n * }\n * ```\n */\nexport async function wrapErrorAsync<T, E extends Error>(\n fn: () => Promise<T>,\n errorFactory: ErrorFactory<E>,\n): Promise<T> {\n try {\n return await fn();\n } catch (error) {\n throw errorFactory(error);\n }\n}\n\n/**\n * Constructor type for error classes (including abstract classes).\n *\n * Used to specify error types that should pass through without transformation.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ErrorConstructor = abstract new (...args: any[]) => Error;\n\n/**\n * Wraps a synchronous function with conditional error transformation.\n *\n * Executes the provided function and catches any thrown errors.\n * Errors matching any of the passthrough types are re-thrown as-is.\n * All other errors are transformed using the error factory.\n *\n * @typeParam T - The return type of the wrapped function\n * @typeParam E - The Error subclass to throw for unknown errors\n * @param fn - The function to execute\n * @param errorFactory - Factory to create the typed error from unknown errors\n * @param passthroughTypes - Array of error classes to re-throw without transformation\n * @returns The result of the function if successful\n * @throws The original error if it matches a passthrough type\n * @throws {E} The transformed error for unknown error types\n *\n * @example Controller boundary\n * ```typescript\n * const result = wrapErrorUnless(\n * () => this.requestMapper(input),\n * (cause) => new ControllerError({ message: 'Mapping failed', cause }),\n * [CodedError],\n * );\n * ```\n */\nexport function wrapErrorUnless<T, E extends Error>(\n fn: () => T,\n errorFactory: ErrorFactory<E>,\n passthroughTypes: ErrorConstructor[],\n): T {\n try {\n return fn();\n } catch (error) {\n if (passthroughTypes.some((Type) => error instanceof Type)) {\n throw error;\n }\n throw errorFactory(error);\n }\n}\n\n/**\n * Wraps an asynchronous function with conditional error transformation.\n *\n * Executes the provided async function and catches any thrown errors.\n * Errors matching any of the passthrough types are re-thrown as-is.\n * All other errors are transformed using the error factory.\n *\n * @typeParam T - The return type of the wrapped function\n * @typeParam E - The Error subclass to throw for unknown errors\n * @param fn - The async function to execute\n * @param errorFactory - Factory to create the typed error from unknown errors\n * @param passthroughTypes - Array of error classes to re-throw without transformation\n * @returns A promise resolving to the result if successful\n * @throws The original error if it matches a passthrough type\n * @throws {E} The transformed error for unknown error types\n *\n * @example Use case boundary\n * ```typescript\n * return wrapErrorUnlessAsync(\n * () => this.handle(input),\n * (cause) => new UseCaseError({ message: 'Unexpected error', cause }),\n * [ObjectValidationError, UseCaseError, DomainError, InfraError],\n * );\n * ```\n *\n * @example Controller boundary\n * ```typescript\n * return wrapErrorUnlessAsync(\n * async () => {\n * const result = await this.useCase.execute(input);\n * return this.responseMapper(result);\n * },\n * (cause) => new ControllerError({ message: 'Controller failed', cause }),\n * [CodedError],\n * );\n * ```\n */\nexport async function wrapErrorUnlessAsync<T, E extends Error>(\n fn: () => Promise<T>,\n errorFactory: ErrorFactory<E>,\n passthroughTypes: ErrorConstructor[],\n): Promise<T> {\n try {\n return await fn();\n } catch (error) {\n if (passthroughTypes.some((Type) => error instanceof Type)) {\n throw error;\n }\n throw errorFactory(error);\n }\n}\n"],"mappings":";AA+DO,SAAS,UAA8B,IAAa,cAAkC;AAC3F,MAAI;AACF,WAAO,GAAG;AAAA,EACZ,SAAS,OAAO;AACd,UAAM,aAAa,KAAK;AAAA,EAC1B;AACF;AA0CA,eAAsB,eACpB,IACA,cACY;AACZ,MAAI;AACF,WAAO,MAAM,GAAG;AAAA,EAClB,SAAS,OAAO;AACd,UAAM,aAAa,KAAK;AAAA,EAC1B;AACF;AAmCO,SAAS,gBACd,IACA,cACA,kBACG;AACH,MAAI;AACF,WAAO,GAAG;AAAA,EACZ,SAAS,OAAO;AACd,QAAI,iBAAiB,KAAK,CAAC,SAAS,iBAAiB,IAAI,GAAG;AAC1D,YAAM;AAAA,IACR;AACA,UAAM,aAAa,KAAK;AAAA,EAC1B;AACF;AAuCA,eAAsB,qBACpB,IACA,cACA,kBACY;AACZ,MAAI;AACF,WAAO,MAAM,GAAG;AAAA,EAClB,SAAS,OAAO;AACd,QAAI,iBAAiB,KAAK,CAAC,SAAS,iBAAiB,IAAI,GAAG;AAC1D,YAAM;AAAA,IACR;AACA,UAAM,aAAa,KAAK;AAAA,EAC1B;AACF;","names":[]}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CodedError,
|
|
3
|
+
ErrorCodes
|
|
4
|
+
} from "./chunk-MQD5GXMT.js";
|
|
5
|
+
|
|
6
|
+
// src/backend/core/onion-layers/app/exceptions/use-case.error.ts
|
|
7
|
+
var UseCaseError = class _UseCaseError extends CodedError {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new UseCaseError instance.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Error configuration
|
|
12
|
+
* @param options.message - Human-readable error description
|
|
13
|
+
* @param options.code - Machine-readable error code (default: 'USE_CASE_ERROR')
|
|
14
|
+
* @param options.cause - Optional underlying error
|
|
15
|
+
*/
|
|
16
|
+
constructor({
|
|
17
|
+
message,
|
|
18
|
+
code = ErrorCodes.App.USE_CASE_ERROR,
|
|
19
|
+
cause
|
|
20
|
+
}) {
|
|
21
|
+
super({ message, code, cause });
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a UseCaseError from a caught error.
|
|
25
|
+
*
|
|
26
|
+
* @param cause - The original caught error
|
|
27
|
+
* @returns A new UseCaseError instance with the cause attached
|
|
28
|
+
*/
|
|
29
|
+
static fromError(cause) {
|
|
30
|
+
return new _UseCaseError({
|
|
31
|
+
message: cause instanceof Error ? cause.message : "Use case error",
|
|
32
|
+
cause
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/backend/core/onion-layers/infra/exceptions/infra.error.ts
|
|
38
|
+
var InfraError = class _InfraError extends CodedError {
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new InfraError instance.
|
|
41
|
+
*
|
|
42
|
+
* @param options - Error configuration
|
|
43
|
+
* @param options.message - Human-readable error description
|
|
44
|
+
* @param options.code - Machine-readable error code (default: 'INFRA_ERROR')
|
|
45
|
+
* @param options.cause - Optional underlying error
|
|
46
|
+
*/
|
|
47
|
+
constructor({
|
|
48
|
+
message,
|
|
49
|
+
code = ErrorCodes.Infra.INFRA_ERROR,
|
|
50
|
+
cause
|
|
51
|
+
}) {
|
|
52
|
+
super({ message, code, cause });
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates an InfraError from a caught error.
|
|
56
|
+
*
|
|
57
|
+
* @param cause - The original caught error
|
|
58
|
+
* @returns A new InfraError instance with the cause attached
|
|
59
|
+
*/
|
|
60
|
+
static fromError(cause) {
|
|
61
|
+
return new _InfraError({
|
|
62
|
+
message: cause instanceof Error ? cause.message : "Infrastructure error",
|
|
63
|
+
cause
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/backend/core/onion-layers/app/exceptions/not-found.error.ts
|
|
69
|
+
var NotFoundError = class _NotFoundError extends UseCaseError {
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new NotFoundError instance.
|
|
72
|
+
*
|
|
73
|
+
* @param options - Error configuration
|
|
74
|
+
* @param options.message - Description of what was not found
|
|
75
|
+
* @param options.code - Machine-readable error code (default: 'NOT_FOUND')
|
|
76
|
+
* @param options.cause - Optional underlying error
|
|
77
|
+
*/
|
|
78
|
+
constructor({
|
|
79
|
+
message,
|
|
80
|
+
code = ErrorCodes.App.NOT_FOUND,
|
|
81
|
+
cause
|
|
82
|
+
}) {
|
|
83
|
+
super({ message, code, cause });
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates a NotFoundError from a caught error.
|
|
87
|
+
*
|
|
88
|
+
* @param cause - The original caught error
|
|
89
|
+
* @returns A new NotFoundError instance with the cause attached
|
|
90
|
+
*/
|
|
91
|
+
static fromError(cause) {
|
|
92
|
+
return new _NotFoundError({
|
|
93
|
+
message: cause instanceof Error ? cause.message : "Resource not found",
|
|
94
|
+
cause
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// src/backend/core/onion-layers/app/exceptions/conflict.error.ts
|
|
100
|
+
var ConflictError = class _ConflictError extends UseCaseError {
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new ConflictError instance.
|
|
103
|
+
*
|
|
104
|
+
* @param options - Error configuration
|
|
105
|
+
* @param options.message - Description of the conflict
|
|
106
|
+
* @param options.code - Machine-readable error code (default: 'CONFLICT')
|
|
107
|
+
* @param options.cause - Optional underlying error
|
|
108
|
+
*/
|
|
109
|
+
constructor({
|
|
110
|
+
message,
|
|
111
|
+
code = ErrorCodes.App.CONFLICT,
|
|
112
|
+
cause
|
|
113
|
+
}) {
|
|
114
|
+
super({ message, code, cause });
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Creates a ConflictError from a caught error.
|
|
118
|
+
*
|
|
119
|
+
* @param cause - The original caught error
|
|
120
|
+
* @returns A new ConflictError instance with the cause attached
|
|
121
|
+
*/
|
|
122
|
+
static fromError(cause) {
|
|
123
|
+
return new _ConflictError({
|
|
124
|
+
message: cause instanceof Error ? cause.message : "Conflict error",
|
|
125
|
+
cause
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/backend/core/onion-layers/app/exceptions/unprocessable.error.ts
|
|
131
|
+
var UnprocessableError = class _UnprocessableError extends UseCaseError {
|
|
132
|
+
/**
|
|
133
|
+
* Creates a new UnprocessableError instance.
|
|
134
|
+
*
|
|
135
|
+
* @param options - Error configuration
|
|
136
|
+
* @param options.message - Description of why the request cannot be processed
|
|
137
|
+
* @param options.code - Machine-readable error code (default: 'UNPROCESSABLE')
|
|
138
|
+
* @param options.cause - Optional underlying error
|
|
139
|
+
*/
|
|
140
|
+
constructor({
|
|
141
|
+
message,
|
|
142
|
+
code = ErrorCodes.App.UNPROCESSABLE,
|
|
143
|
+
cause
|
|
144
|
+
}) {
|
|
145
|
+
super({ message, code, cause });
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Creates an UnprocessableError from a caught error.
|
|
149
|
+
*
|
|
150
|
+
* @param cause - The original caught error
|
|
151
|
+
* @returns A new UnprocessableError instance with the cause attached
|
|
152
|
+
*/
|
|
153
|
+
static fromError(cause) {
|
|
154
|
+
return new _UnprocessableError({
|
|
155
|
+
message: cause instanceof Error ? cause.message : "Unprocessable request",
|
|
156
|
+
cause
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export {
|
|
162
|
+
UseCaseError,
|
|
163
|
+
InfraError,
|
|
164
|
+
NotFoundError,
|
|
165
|
+
ConflictError,
|
|
166
|
+
UnprocessableError
|
|
167
|
+
};
|
|
168
|
+
//# sourceMappingURL=chunk-RLLWYFPI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/backend/core/onion-layers/app/exceptions/use-case.error.ts","../src/backend/core/onion-layers/infra/exceptions/infra.error.ts","../src/backend/core/onion-layers/app/exceptions/not-found.error.ts","../src/backend/core/onion-layers/app/exceptions/conflict.error.ts","../src/backend/core/onion-layers/app/exceptions/unprocessable.error.ts"],"sourcesContent":["import { CodedError } from '../../../global/exceptions/coded-error.error';\nimport { ErrorCodes, type AppErrorCode } from '../../../global/exceptions/error-codes.const';\n\n/**\n * Base error class for application layer (use case) failures.\n *\n * Use case errors represent failures in the application's business logic\n * orchestration, such as resource conflicts, missing entities, or\n * unprocessable requests. They bridge domain errors to the presentation layer.\n *\n * **When to throw:**\n * - Resource not found (e.g., \"User with ID X not found\")\n * - Conflict states (e.g., \"Email already registered\")\n * - Unprocessable business operations\n *\n * **Child classes:**\n * - {@link ConflictError} - Resource state conflicts (HTTP 409)\n * - {@link NotFoundError} - Resource not found (HTTP 404)\n * - {@link UnprocessableError} - Valid but unprocessable request (HTTP 422)\n *\n * @example\n * ```typescript\n * const user = await this.userRepo.findById(id);\n * if (!user) {\n * throw new NotFoundError({\n * message: `User with ID ${id} not found`,\n * code: 'USER_NOT_FOUND',\n * });\n * }\n * ```\n */\nexport class UseCaseError extends CodedError {\n /**\n * Creates a new UseCaseError instance.\n *\n * @param options - Error configuration\n * @param options.message - Human-readable error description\n * @param options.code - Machine-readable error code (default: 'USE_CASE_ERROR')\n * @param options.cause - Optional underlying error\n */\n constructor({\n message,\n code = ErrorCodes.App.USE_CASE_ERROR,\n cause,\n }: {\n message: string;\n code?: AppErrorCode | string;\n cause?: unknown;\n }) {\n super({ message, code, cause });\n }\n\n /**\n * Creates a UseCaseError from a caught error.\n *\n * @param cause - The original caught error\n * @returns A new UseCaseError instance with the cause attached\n */\n static override fromError(cause: unknown): UseCaseError {\n return new UseCaseError({\n message: cause instanceof Error ? cause.message : 'Use case error',\n cause,\n });\n }\n}\n","import { CodedError } from '../../../global/exceptions/coded-error.error';\nimport { ErrorCodes, type InfraErrorCode } from '../../../global/exceptions/error-codes.const';\n\n/**\n * Base error class for infrastructure layer failures.\n *\n * Infrastructure errors represent failures in external dependencies\n * such as databases, network services, file systems, or third-party APIs.\n * They are automatically created by {@link BaseOutboundAdapter} when\n * repository or gateway methods fail.\n *\n * **When to throw:**\n * - Database connection or query failures\n * - Network timeouts or connection errors\n * - External API failures\n * - File system errors\n *\n * **Child classes:**\n * - {@link DbError} - Database operation failures\n * - {@link NetworkError} - Network connectivity issues\n * - {@link TimeoutError} - Operation timeout\n * - {@link ExternalServiceError} - Third-party service failures\n *\n * @example\n * ```typescript\n * // In a repository extending BaseOutboundAdapter\n * protected override createInfraError(error: unknown, methodName: string): InfraError {\n * return new DbError({\n * message: `Database error in ${methodName}`,\n * cause: error,\n * });\n * }\n * ```\n */\nexport class InfraError extends CodedError {\n /**\n * Creates a new InfraError instance.\n *\n * @param options - Error configuration\n * @param options.message - Human-readable error description\n * @param options.code - Machine-readable error code (default: 'INFRA_ERROR')\n * @param options.cause - Optional underlying error\n */\n constructor({\n message,\n code = ErrorCodes.Infra.INFRA_ERROR,\n cause,\n }: {\n message: string;\n code?: InfraErrorCode | string;\n cause?: unknown;\n }) {\n super({ message, code, cause });\n }\n\n /**\n * Creates an InfraError from a caught error.\n *\n * @param cause - The original caught error\n * @returns A new InfraError instance with the cause attached\n */\n static override fromError(cause: unknown): InfraError {\n return new InfraError({\n message: cause instanceof Error ? cause.message : 'Infrastructure error',\n cause,\n });\n }\n}\n","import { ErrorCodes, type AppErrorCode } from '../../../global/exceptions/error-codes.const';\nimport { UseCaseError } from './use-case.error';\n\n/**\n * Error thrown when a requested resource does not exist.\n *\n * Indicates that the entity or resource referenced by the request\n * could not be found in the system.\n *\n * **When to throw:**\n * - Entity lookup by ID returns null\n * - Referenced resource doesn't exist\n * - Parent entity for a child operation not found\n *\n * @example\n * ```typescript\n * const user = await this.userRepo.findById(userId);\n * if (!user) {\n * throw new NotFoundError({\n * message: `User with ID ${userId} not found`,\n * code: 'USER_NOT_FOUND',\n * });\n * }\n * ```\n *\n * @extends UseCaseError\n */\nexport class NotFoundError extends UseCaseError {\n /**\n * Creates a new NotFoundError instance.\n *\n * @param options - Error configuration\n * @param options.message - Description of what was not found\n * @param options.code - Machine-readable error code (default: 'NOT_FOUND')\n * @param options.cause - Optional underlying error\n */\n constructor({\n message,\n code = ErrorCodes.App.NOT_FOUND,\n cause,\n }: {\n message: string;\n code?: AppErrorCode | string;\n cause?: unknown;\n }) {\n super({ message, code, cause });\n }\n\n /**\n * Creates a NotFoundError from a caught error.\n *\n * @param cause - The original caught error\n * @returns A new NotFoundError instance with the cause attached\n */\n static override fromError(cause: unknown): NotFoundError {\n return new NotFoundError({\n message: cause instanceof Error ? cause.message : 'Resource not found',\n cause,\n });\n }\n}\n","import { ErrorCodes, type AppErrorCode } from '../../../global/exceptions/error-codes.const';\nimport { UseCaseError } from './use-case.error';\n\n/**\n * Error thrown when an operation conflicts with existing state.\n *\n * Indicates that the requested operation cannot be completed because\n * it would violate uniqueness constraints or cause state conflicts.\n *\n * **When to throw:**\n * - Duplicate unique field (e.g., email already registered)\n * - Optimistic locking conflict (stale version)\n * - Concurrent modification detected\n *\n * @example\n * ```typescript\n * const existing = await this.userRepo.findByEmail(email);\n * if (existing) {\n * throw new ConflictError({\n * message: 'Email already registered',\n * code: 'EMAIL_ALREADY_EXISTS',\n * });\n * }\n * ```\n *\n * @extends UseCaseError\n */\nexport class ConflictError extends UseCaseError {\n /**\n * Creates a new ConflictError instance.\n *\n * @param options - Error configuration\n * @param options.message - Description of the conflict\n * @param options.code - Machine-readable error code (default: 'CONFLICT')\n * @param options.cause - Optional underlying error\n */\n constructor({\n message,\n code = ErrorCodes.App.CONFLICT,\n cause,\n }: {\n message: string;\n code?: AppErrorCode | string;\n cause?: unknown;\n }) {\n super({ message, code, cause });\n }\n\n /**\n * Creates a ConflictError from a caught error.\n *\n * @param cause - The original caught error\n * @returns A new ConflictError instance with the cause attached\n */\n static override fromError(cause: unknown): ConflictError {\n return new ConflictError({\n message: cause instanceof Error ? cause.message : 'Conflict error',\n cause,\n });\n }\n}\n","import { ErrorCodes, type AppErrorCode } from '../../../global/exceptions/error-codes.const';\nimport { UseCaseError } from './use-case.error';\n\n/**\n * Error thrown when a request is valid but cannot be processed.\n *\n * The request is syntactically correct and passes validation, but\n * business logic prevents the operation from being completed.\n *\n * **When to throw:**\n * - Business rule prevents operation (e.g., insufficient balance)\n * - Invalid state transition (e.g., canceling a completed order)\n * - Preconditions not met for the operation\n *\n * @example\n * ```typescript\n * if (account.balance < amount) {\n * throw new UnprocessableError({\n * message: 'Insufficient balance for withdrawal',\n * code: 'INSUFFICIENT_BALANCE',\n * });\n * }\n * ```\n *\n * @extends UseCaseError\n */\nexport class UnprocessableError extends UseCaseError {\n /**\n * Creates a new UnprocessableError instance.\n *\n * @param options - Error configuration\n * @param options.message - Description of why the request cannot be processed\n * @param options.code - Machine-readable error code (default: 'UNPROCESSABLE')\n * @param options.cause - Optional underlying error\n */\n constructor({\n message,\n code = ErrorCodes.App.UNPROCESSABLE,\n cause,\n }: {\n message: string;\n code?: AppErrorCode | string;\n cause?: unknown;\n }) {\n super({ message, code, cause });\n }\n\n /**\n * Creates an UnprocessableError from a caught error.\n *\n * @param cause - The original caught error\n * @returns A new UnprocessableError instance with the cause attached\n */\n static override fromError(cause: unknown): UnprocessableError {\n return new UnprocessableError({\n message: cause instanceof Error ? cause.message : 'Unprocessable request',\n cause,\n });\n }\n}\n"],"mappings":";;;;;;AA+BO,IAAM,eAAN,MAAM,sBAAqB,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS3C,YAAY;AAAA,IACV;AAAA,IACA,OAAO,WAAW,IAAI;AAAA,IACtB;AAAA,EACF,GAIG;AACD,UAAM,EAAE,SAAS,MAAM,MAAM,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAgB,UAAU,OAA8B;AACtD,WAAO,IAAI,cAAa;AAAA,MACtB,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;AC9BO,IAAM,aAAN,MAAM,oBAAmB,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASzC,YAAY;AAAA,IACV;AAAA,IACA,OAAO,WAAW,MAAM;AAAA,IACxB;AAAA,EACF,GAIG;AACD,UAAM,EAAE,SAAS,MAAM,MAAM,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAgB,UAAU,OAA4B;AACpD,WAAO,IAAI,YAAW;AAAA,MACpB,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;ACxCO,IAAM,gBAAN,MAAM,uBAAsB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS9C,YAAY;AAAA,IACV;AAAA,IACA,OAAO,WAAW,IAAI;AAAA,IACtB;AAAA,EACF,GAIG;AACD,UAAM,EAAE,SAAS,MAAM,MAAM,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAgB,UAAU,OAA+B;AACvD,WAAO,IAAI,eAAc;AAAA,MACvB,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;ACjCO,IAAM,gBAAN,MAAM,uBAAsB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS9C,YAAY;AAAA,IACV;AAAA,IACA,OAAO,WAAW,IAAI;AAAA,IACtB;AAAA,EACF,GAIG;AACD,UAAM,EAAE,SAAS,MAAM,MAAM,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAgB,UAAU,OAA+B;AACvD,WAAO,IAAI,eAAc;AAAA,MACvB,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;AClCO,IAAM,qBAAN,MAAM,4BAA2B,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASnD,YAAY;AAAA,IACV;AAAA,IACA,OAAO,WAAW,IAAI;AAAA,IACtB;AAAA,EACF,GAIG;AACD,UAAM,EAAE,SAAS,MAAM,MAAM,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAgB,UAAU,OAAoC;AAC5D,WAAO,IAAI,oBAAmB;AAAA,MAC5B,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
|