@rineex/ddd 2.2.0 → 3.0.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/index.d.mts +278 -185
- package/dist/index.d.ts +278 -185
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,169 +1,9 @@
|
|
|
1
|
-
import { Primitive as Primitive$2, Tagged } from 'type-fest';
|
|
1
|
+
import { Primitive as Primitive$2, EmptyObject, Tagged } from 'type-fest';
|
|
2
2
|
import z from 'zod';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* HTTP status code catalog.
|
|
6
|
-
*
|
|
7
|
-
* This object provides a typed, immutable map of standard HTTP status names
|
|
8
|
-
* to their numeric codes. Designed for server-side frameworks such as Fastify.
|
|
9
|
-
*
|
|
10
|
-
* - All identifiers use clear, canonical semantic names.
|
|
11
|
-
* - Values are numeric status codes.
|
|
12
|
-
* - Frozen to prevent runtime mutation.
|
|
13
|
-
* - Exporting `HttpStatus` ensures type-safe usage across the codebase.
|
|
14
|
-
* Usage:
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { HttpStatus } from 'path-to-this-file';
|
|
17
|
-
*
|
|
18
|
-
* function handleRequest() {
|
|
19
|
-
* return {
|
|
20
|
-
* statusCode: HttpStatus.OK,
|
|
21
|
-
* body: 'Success',
|
|
22
|
-
* };
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
declare const HttpStatus: Readonly<{
|
|
27
|
-
readonly REQUEST_HEADER_FIELDS_TOO_LARGE: 431;
|
|
28
|
-
readonly NETWORK_AUTHENTICATION_REQUIRED: 511;
|
|
29
|
-
readonly NON_AUTHORITATIVE_INFORMATION: 203;
|
|
30
|
-
readonly PROXY_AUTHENTICATION_REQUIRED: 407;
|
|
31
|
-
readonly UNAVAILABLE_FOR_LEGAL_REASONS: 451;
|
|
32
|
-
readonly HTTP_VERSION_NOT_SUPPORTED: 505;
|
|
33
|
-
readonly BANDWIDTH_LIMIT_EXCEEDED: 509;
|
|
34
|
-
readonly VARIANT_ALSO_NEGOTIATES: 506;
|
|
35
|
-
readonly UNSUPPORTED_MEDIA_TYPE: 415;
|
|
36
|
-
readonly RANGE_NOT_SATISFIABLE: 416;
|
|
37
|
-
readonly PRECONDITION_REQUIRED: 428;
|
|
38
|
-
readonly INTERNAL_SERVER_ERROR: 500;
|
|
39
|
-
readonly UNPROCESSABLE_ENTITY: 422;
|
|
40
|
-
readonly INSUFFICIENT_STORAGE: 507;
|
|
41
|
-
readonly SWITCHING_PROTOCOLS: 101;
|
|
42
|
-
readonly PRECONDITION_FAILED: 412;
|
|
43
|
-
readonly MISDIRECTED_REQUEST: 421;
|
|
44
|
-
readonly SERVICE_UNAVAILABLE: 503;
|
|
45
|
-
readonly TEMPORARY_REDIRECT: 307;
|
|
46
|
-
readonly PERMANENT_REDIRECT: 308;
|
|
47
|
-
readonly METHOD_NOT_ALLOWED: 405;
|
|
48
|
-
readonly EXPECTATION_FAILED: 417;
|
|
49
|
-
readonly MOVED_PERMANENTLY: 301;
|
|
50
|
-
readonly PAYLOAD_TOO_LARGE: 413;
|
|
51
|
-
readonly FAILED_DEPENDENCY: 424;
|
|
52
|
-
readonly TOO_MANY_REQUESTS: 429;
|
|
53
|
-
readonly ALREADY_REPORTED: 208;
|
|
54
|
-
readonly MULTIPLE_CHOICES: 300;
|
|
55
|
-
readonly PAYMENT_REQUIRED: 402;
|
|
56
|
-
readonly UPGRADE_REQUIRED: 426;
|
|
57
|
-
readonly PARTIAL_CONTENT: 206;
|
|
58
|
-
readonly REQUEST_TIMEOUT: 408;
|
|
59
|
-
readonly LENGTH_REQUIRED: 411;
|
|
60
|
-
readonly NOT_IMPLEMENTED: 501;
|
|
61
|
-
readonly GATEWAY_TIMEOUT: 504;
|
|
62
|
-
readonly NOT_ACCEPTABLE: 406;
|
|
63
|
-
readonly RESET_CONTENT: 205;
|
|
64
|
-
readonly LOOP_DETECTED: 508;
|
|
65
|
-
readonly MULTI_STATUS: 207;
|
|
66
|
-
readonly NOT_MODIFIED: 304;
|
|
67
|
-
readonly UNAUTHORIZED: 401;
|
|
68
|
-
readonly URI_TOO_LONG: 414;
|
|
69
|
-
readonly NOT_EXTENDED: 510;
|
|
70
|
-
readonly EARLY_HINTS: 103;
|
|
71
|
-
readonly BAD_REQUEST: 400;
|
|
72
|
-
readonly IM_A_TEAPOT: 418;
|
|
73
|
-
readonly BAD_GATEWAY: 502;
|
|
74
|
-
readonly PROCESSING: 102;
|
|
75
|
-
readonly NO_CONTENT: 204;
|
|
76
|
-
readonly SEE_OTHER: 303;
|
|
77
|
-
readonly USE_PROXY: 305;
|
|
78
|
-
readonly FORBIDDEN: 403;
|
|
79
|
-
readonly NOT_FOUND: 404;
|
|
80
|
-
readonly TOO_EARLY: 425;
|
|
81
|
-
readonly CONTINUE: 100;
|
|
82
|
-
readonly ACCEPTED: 202;
|
|
83
|
-
readonly CONFLICT: 409;
|
|
84
|
-
readonly CREATED: 201;
|
|
85
|
-
readonly IM_USED: 226;
|
|
86
|
-
readonly LOCKED: 423;
|
|
87
|
-
readonly FOUND: 302;
|
|
88
|
-
readonly GONE: 410;
|
|
89
|
-
readonly OK: 200;
|
|
90
|
-
}>;
|
|
91
|
-
type HttpStatusCode = keyof typeof HttpStatusMessage;
|
|
92
|
-
/**
|
|
93
|
-
* HTTP status messages mapped by numeric code.
|
|
94
|
-
* Use for sending descriptive text in responses or logging.
|
|
95
|
-
*/
|
|
96
|
-
declare const HttpStatusMessage: {
|
|
97
|
-
readonly 431: "Request Header Fields Too Large";
|
|
98
|
-
readonly 511: "Network Authentication Required";
|
|
99
|
-
readonly 203: "Non-Authoritative Information";
|
|
100
|
-
readonly 407: "Proxy Authentication Required";
|
|
101
|
-
readonly 451: "Unavailable For Legal Reasons";
|
|
102
|
-
readonly 505: "HTTP Version Not Supported";
|
|
103
|
-
readonly 509: "Bandwidth Limit Exceeded";
|
|
104
|
-
readonly 506: "Variant Also Negotiates";
|
|
105
|
-
readonly 415: "Unsupported Media Type";
|
|
106
|
-
readonly 416: "Range Not Satisfiable";
|
|
107
|
-
readonly 428: "Precondition Required";
|
|
108
|
-
readonly 500: "Internal Server Error";
|
|
109
|
-
readonly 422: "Unprocessable Entity";
|
|
110
|
-
readonly 507: "Insufficient Storage";
|
|
111
|
-
readonly 101: "Switching Protocols";
|
|
112
|
-
readonly 412: "Precondition Failed";
|
|
113
|
-
readonly 421: "Misdirected Request";
|
|
114
|
-
readonly 503: "Service Unavailable";
|
|
115
|
-
readonly 307: "Temporary Redirect";
|
|
116
|
-
readonly 308: "Permanent Redirect";
|
|
117
|
-
readonly 405: "Method Not Allowed";
|
|
118
|
-
readonly 417: "Expectation Failed";
|
|
119
|
-
readonly 301: "Moved Permanently";
|
|
120
|
-
readonly 413: "Payload Too Large";
|
|
121
|
-
readonly 424: "Failed Dependency";
|
|
122
|
-
readonly 429: "Too Many Requests";
|
|
123
|
-
readonly 208: "Already Reported";
|
|
124
|
-
readonly 300: "Multiple Choices";
|
|
125
|
-
readonly 402: "Payment Required";
|
|
126
|
-
readonly 426: "Upgrade Required";
|
|
127
|
-
readonly 206: "Partial Content";
|
|
128
|
-
readonly 408: "Request Timeout";
|
|
129
|
-
readonly 411: "Length Required";
|
|
130
|
-
readonly 501: "Not Implemented";
|
|
131
|
-
readonly 504: "Gateway Timeout";
|
|
132
|
-
readonly 406: "Not Acceptable";
|
|
133
|
-
readonly 205: "Reset Content";
|
|
134
|
-
readonly 508: "Loop Detected";
|
|
135
|
-
readonly 207: "Multi-Status";
|
|
136
|
-
readonly 304: "Not Modified";
|
|
137
|
-
readonly 401: "Unauthorized";
|
|
138
|
-
readonly 414: "URI Too Long";
|
|
139
|
-
readonly 418: "I'm a Teapot";
|
|
140
|
-
readonly 510: "Not Extended";
|
|
141
|
-
readonly 103: "Early Hints";
|
|
142
|
-
readonly 400: "Bad Request";
|
|
143
|
-
readonly 502: "Bad Gateway";
|
|
144
|
-
readonly 102: "Processing";
|
|
145
|
-
readonly 204: "No Content";
|
|
146
|
-
readonly 303: "See Other";
|
|
147
|
-
readonly 305: "Use Proxy";
|
|
148
|
-
readonly 403: "Forbidden";
|
|
149
|
-
readonly 404: "Not Found";
|
|
150
|
-
readonly 425: "Too Early";
|
|
151
|
-
readonly 100: "Continue";
|
|
152
|
-
readonly 202: "Accepted";
|
|
153
|
-
readonly 226: "I'm Used";
|
|
154
|
-
readonly 409: "Conflict";
|
|
155
|
-
readonly 201: "Created";
|
|
156
|
-
readonly 423: "Locked";
|
|
157
|
-
readonly 302: "Found";
|
|
158
|
-
readonly 410: "Gone";
|
|
159
|
-
readonly 200: "OK";
|
|
160
|
-
};
|
|
161
|
-
type HttpStatusMessage = (typeof HttpStatusMessage)[keyof typeof HttpStatusMessage];
|
|
162
|
-
|
|
163
4
|
interface ErrorParams {
|
|
164
5
|
message: string;
|
|
165
|
-
code:
|
|
166
|
-
status?: HttpStatusCode;
|
|
6
|
+
code: string;
|
|
167
7
|
metadata?: Record<string, unknown>;
|
|
168
8
|
isOperational?: boolean;
|
|
169
9
|
cause?: Error;
|
|
@@ -183,7 +23,6 @@ interface ErrorParams {
|
|
|
183
23
|
* constructor(userId: string) {
|
|
184
24
|
* super({
|
|
185
25
|
* code: HttpStatusMessage['404'],
|
|
186
|
-
* status: 404,
|
|
187
26
|
* isOperational: true,
|
|
188
27
|
* message: `User with id ${userId} not found`,
|
|
189
28
|
* metadata: { userId }
|
|
@@ -196,14 +35,12 @@ declare abstract class ApplicationError extends Error {
|
|
|
196
35
|
/** Optional cause (linked error) */
|
|
197
36
|
readonly cause?: Error | undefined;
|
|
198
37
|
/** Machine-readable error code (e.g. `OTP_LOCKED`, `USER_NOT_FOUND`) */
|
|
199
|
-
readonly code:
|
|
38
|
+
readonly code: string;
|
|
200
39
|
/** Operational vs programmer error flag */
|
|
201
40
|
readonly isOperational: boolean;
|
|
202
41
|
/** Optional structured metadata for debugging or clients */
|
|
203
42
|
readonly metadata?: Record<string, unknown> | undefined;
|
|
204
|
-
|
|
205
|
-
readonly status: HttpStatusCode;
|
|
206
|
-
constructor({ code, isOperational, status, metadata, message, cause, }: ErrorParams);
|
|
43
|
+
constructor({ isOperational, metadata, message, cause, code, }: ErrorParams);
|
|
207
44
|
}
|
|
208
45
|
|
|
209
46
|
/**
|
|
@@ -475,7 +312,7 @@ declare abstract class ValueObject<T> {
|
|
|
475
312
|
}
|
|
476
313
|
|
|
477
314
|
type Primitive = boolean | number | string | null | undefined;
|
|
478
|
-
type Metadata<T =
|
|
315
|
+
type Metadata<T = EmptyObject> = T extends Record<string, Primitive> ? T : EmptyObject;
|
|
479
316
|
/**
|
|
480
317
|
* Categories of domain errors based on the nature of the violation.
|
|
481
318
|
*
|
|
@@ -583,7 +420,7 @@ type ExtractErrorName<Code extends DomainErrorCode> = Code extends `${string}.${
|
|
|
583
420
|
*
|
|
584
421
|
* @abstract
|
|
585
422
|
*/
|
|
586
|
-
declare abstract class DomainError<Meta extends Record<string, Primitive> =
|
|
423
|
+
declare abstract class DomainError<Meta extends Record<string, Primitive> = EmptyObject, Code extends DomainErrorCode = DomainErrorCode> {
|
|
587
424
|
/**
|
|
588
425
|
* Machine-readable error code in format: NAMESPACE.ERROR_NAME
|
|
589
426
|
*
|
|
@@ -712,15 +549,17 @@ declare abstract class DomainError<Meta extends Record<string, Primitive> = {},
|
|
|
712
549
|
* - Metadata is optional for empty metadata types and required if a non-empty type is provided.
|
|
713
550
|
* - Useful for debugging, logging, and adding context to unexpected failures.
|
|
714
551
|
*
|
|
552
|
+
* @template T - Type of metadata object (must extend Record<string, Primitive>)
|
|
553
|
+
*
|
|
715
554
|
* @example
|
|
716
555
|
* // Catch a programming error:
|
|
717
556
|
* try {
|
|
718
557
|
* complexBusinessLogic();
|
|
719
558
|
* } catch (error) {
|
|
720
|
-
* throw new InternalError(
|
|
721
|
-
*
|
|
722
|
-
*
|
|
723
|
-
*
|
|
559
|
+
* throw new InternalError(
|
|
560
|
+
* 'Unexpected error in complexBusinessLogic',
|
|
561
|
+
* { originalError: error.message, timestamp: Date.now() }
|
|
562
|
+
* );
|
|
724
563
|
* }
|
|
725
564
|
*
|
|
726
565
|
* @example
|
|
@@ -731,13 +570,21 @@ declare abstract class DomainError<Meta extends Record<string, Primitive> = {},
|
|
|
731
570
|
* case 'COMPLETED':
|
|
732
571
|
* break;
|
|
733
572
|
* default:
|
|
734
|
-
* throw new InternalError(
|
|
735
|
-
*
|
|
736
|
-
*
|
|
737
|
-
*
|
|
573
|
+
* throw new InternalError(
|
|
574
|
+
* `Unhandled status: ${status}`,
|
|
575
|
+
* { status }
|
|
576
|
+
* );
|
|
738
577
|
* }
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* // With custom metadata type:
|
|
581
|
+
* type ErrorMetadata = { userId: string; action: string };
|
|
582
|
+
* throw new InternalError<ErrorMetadata>(
|
|
583
|
+
* 'Failed to process user action',
|
|
584
|
+
* { userId: 'usr_123', action: 'activate' }
|
|
585
|
+
* );
|
|
739
586
|
*/
|
|
740
|
-
declare class InternalError<T = Record<string, Primitive>> extends DomainError<Metadata<T>> {
|
|
587
|
+
declare class InternalError<T extends Record<string, Primitive> = Record<string, Primitive>> extends DomainError<Metadata<T>> {
|
|
741
588
|
/** @inheritdoc */
|
|
742
589
|
readonly code: "CORE.INTERNAL_ERROR";
|
|
743
590
|
/** @inheritdoc */
|
|
@@ -745,16 +592,86 @@ declare class InternalError<T = Record<string, Primitive>> extends DomainError<M
|
|
|
745
592
|
/**
|
|
746
593
|
* Creates a new InternalError.
|
|
747
594
|
*
|
|
748
|
-
* @param message - Description of the internal error
|
|
749
|
-
* @param metadata - Optional debug information
|
|
595
|
+
* @param message - Description of the internal error (defaults to 'An unexpected internal error occurred')
|
|
596
|
+
* @param metadata - Optional debug information (primitive values only)
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* // Basic usage:
|
|
600
|
+
* throw new InternalError('Something went wrong');
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* // With metadata:
|
|
604
|
+
* throw new InternalError(
|
|
605
|
+
* 'Database connection failed',
|
|
606
|
+
* { host: 'localhost', port: 5432, retries: 3 }
|
|
607
|
+
* );
|
|
750
608
|
*/
|
|
751
609
|
constructor(message?: string, metadata?: Metadata<T>);
|
|
752
610
|
}
|
|
753
611
|
|
|
612
|
+
/**
|
|
613
|
+
* Error thrown when an entity or aggregate is in an invalid state for the requested operation.
|
|
614
|
+
* Use for state violations (e.g., "Cannot checkout empty cart", "Cannot cancel completed order").
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* // Prevent invalid state transitions:
|
|
618
|
+
* if (order.status === 'COMPLETED') {
|
|
619
|
+
* throw new InvalidStateError('Cannot cancel a completed order');
|
|
620
|
+
* }
|
|
621
|
+
*
|
|
622
|
+
* @example
|
|
623
|
+
* // With context:
|
|
624
|
+
* if (!cart.hasItems()) {
|
|
625
|
+
* throw new InvalidStateError('Cannot checkout empty cart');
|
|
626
|
+
* }
|
|
627
|
+
*/
|
|
628
|
+
declare class InvalidStateError extends DomainError<Record<string, Primitive>> {
|
|
629
|
+
code: DomainErrorCode;
|
|
630
|
+
type: DomainErrorType;
|
|
631
|
+
constructor(message?: string);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Error thrown when a value violates domain rules or constraints.
|
|
636
|
+
* Use for value violations (e.g., "Email format is invalid", "Age cannot be negative").
|
|
637
|
+
*
|
|
638
|
+
* @template T - Type of metadata object (must extend Record<string, Primitive>)
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* // Basic usage:
|
|
642
|
+
* if (age < 0) {
|
|
643
|
+
* throw new InvalidValueError('Age cannot be negative');
|
|
644
|
+
* }
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* // With metadata:
|
|
648
|
+
* if (!isValidEmail(email)) {
|
|
649
|
+
* throw new InvalidValueError(
|
|
650
|
+
* 'Invalid email format',
|
|
651
|
+
* { email, pattern: '^[^@]+@[^@]+\\.[^@]+$' }
|
|
652
|
+
* );
|
|
653
|
+
* }
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* // With custom metadata type:
|
|
657
|
+
* type ValidationMetadata = { field: string; value: unknown; reason: string };
|
|
658
|
+
* throw new InvalidValueError<ValidationMetadata>(
|
|
659
|
+
* 'Validation failed',
|
|
660
|
+
* { field: 'email', value: email, reason: 'Invalid format' }
|
|
661
|
+
* );
|
|
662
|
+
*/
|
|
663
|
+
declare class InvalidValueError<T extends Record<string, Primitive> = Record<string, Primitive>> extends DomainError<Metadata<T>> {
|
|
664
|
+
code: DomainErrorCode;
|
|
665
|
+
type: DomainErrorType;
|
|
666
|
+
constructor(msg?: string, meta?: Metadata<T>);
|
|
667
|
+
}
|
|
668
|
+
|
|
754
669
|
/**
|
|
755
670
|
* Error thrown when an operation times out.
|
|
756
671
|
* Use for operations that exceed their allowed execution time.
|
|
757
672
|
*
|
|
673
|
+
* @template T - Type of metadata object (must extend Record<string, Primitive>)
|
|
674
|
+
*
|
|
758
675
|
* @example
|
|
759
676
|
* // Operation timeout:
|
|
760
677
|
* const timeout = setTimeout(() => {
|
|
@@ -765,7 +682,7 @@ declare class InternalError<T = Record<string, Primitive>> extends DomainError<M
|
|
|
765
682
|
*
|
|
766
683
|
* @example
|
|
767
684
|
* // With Promise.race:
|
|
768
|
-
* type Props = { url: string
|
|
685
|
+
* type Props = { url: string; timeoutMs: number };
|
|
769
686
|
* async function fetchWithTimeout(url: string, timeoutMs: number) {
|
|
770
687
|
* const timeoutPromise = new Promise<never>((_, reject) => {
|
|
771
688
|
* setTimeout(() => {
|
|
@@ -778,8 +695,15 @@ declare class InternalError<T = Record<string, Primitive>> extends DomainError<M
|
|
|
778
695
|
*
|
|
779
696
|
* return await Promise.race([fetch(url), timeoutPromise]);
|
|
780
697
|
* }
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* // With custom metadata:
|
|
701
|
+
* throw new TimeoutError(
|
|
702
|
+
* 'Database query timed out',
|
|
703
|
+
* { query: 'SELECT * FROM users', timeout: 5000, retries: 3 }
|
|
704
|
+
* );
|
|
781
705
|
*/
|
|
782
|
-
declare class TimeoutError<T = Record<string, Primitive>> extends DomainError<Metadata<T>> {
|
|
706
|
+
declare class TimeoutError<T extends Record<string, Primitive> = Record<string, Primitive>> extends DomainError<Metadata<T>> {
|
|
783
707
|
/** @inheritdoc */
|
|
784
708
|
readonly code: "SYSTEM.TIMEOUT";
|
|
785
709
|
/** @inheritdoc */
|
|
@@ -1134,13 +1058,23 @@ declare class Result<T, E> {
|
|
|
1134
1058
|
isSuccessResult(): this is Result<T, never>;
|
|
1135
1059
|
}
|
|
1136
1060
|
|
|
1061
|
+
type ClockPort = {
|
|
1062
|
+
now: () => Date;
|
|
1063
|
+
};
|
|
1064
|
+
|
|
1065
|
+
interface ExtraProps extends Record<string, Primitive> {
|
|
1066
|
+
entityId?: string;
|
|
1067
|
+
entityType?: string;
|
|
1068
|
+
}
|
|
1069
|
+
type Props$1 = Metadata<ExtraProps>;
|
|
1137
1070
|
/**
|
|
1138
1071
|
* Custom error class for entity validation failures.
|
|
1139
1072
|
*/
|
|
1140
|
-
declare class EntityValidationError extends DomainError {
|
|
1073
|
+
declare class EntityValidationError extends DomainError<Props$1> {
|
|
1141
1074
|
code: DomainErrorCode;
|
|
1142
1075
|
type: DomainErrorType;
|
|
1143
|
-
|
|
1076
|
+
constructor(message: string, props: Props$1);
|
|
1077
|
+
static create(msg: string, props: Props$1): EntityValidationError;
|
|
1144
1078
|
}
|
|
1145
1079
|
|
|
1146
1080
|
type Params = {
|
|
@@ -1258,6 +1192,165 @@ declare class Email extends PrimitiveValueObject<string> {
|
|
|
1258
1192
|
protected validate(value: string): void;
|
|
1259
1193
|
}
|
|
1260
1194
|
|
|
1195
|
+
/**
|
|
1196
|
+
* HTTP status code catalog.
|
|
1197
|
+
*
|
|
1198
|
+
* This object provides a typed, immutable map of standard HTTP status names
|
|
1199
|
+
* to their numeric codes. Designed for server-side frameworks such as Fastify.
|
|
1200
|
+
*
|
|
1201
|
+
* - All identifiers use clear, canonical semantic names.
|
|
1202
|
+
* - Values are numeric status codes.
|
|
1203
|
+
* - Frozen to prevent runtime mutation.
|
|
1204
|
+
* - Exporting `HttpStatus` ensures type-safe usage across the codebase.
|
|
1205
|
+
* Usage:
|
|
1206
|
+
* ```ts
|
|
1207
|
+
* import { HttpStatus } from 'path-to-this-file';
|
|
1208
|
+
*
|
|
1209
|
+
* function handleRequest() {
|
|
1210
|
+
* return {
|
|
1211
|
+
* statusCode: HttpStatus.OK,
|
|
1212
|
+
* body: 'Success',
|
|
1213
|
+
* };
|
|
1214
|
+
* }
|
|
1215
|
+
* ```
|
|
1216
|
+
*/
|
|
1217
|
+
declare const HttpStatus: Readonly<{
|
|
1218
|
+
readonly REQUEST_HEADER_FIELDS_TOO_LARGE: 431;
|
|
1219
|
+
readonly NETWORK_AUTHENTICATION_REQUIRED: 511;
|
|
1220
|
+
readonly NON_AUTHORITATIVE_INFORMATION: 203;
|
|
1221
|
+
readonly PROXY_AUTHENTICATION_REQUIRED: 407;
|
|
1222
|
+
readonly UNAVAILABLE_FOR_LEGAL_REASONS: 451;
|
|
1223
|
+
readonly HTTP_VERSION_NOT_SUPPORTED: 505;
|
|
1224
|
+
readonly BANDWIDTH_LIMIT_EXCEEDED: 509;
|
|
1225
|
+
readonly VARIANT_ALSO_NEGOTIATES: 506;
|
|
1226
|
+
readonly UNSUPPORTED_MEDIA_TYPE: 415;
|
|
1227
|
+
readonly RANGE_NOT_SATISFIABLE: 416;
|
|
1228
|
+
readonly PRECONDITION_REQUIRED: 428;
|
|
1229
|
+
readonly INTERNAL_SERVER_ERROR: 500;
|
|
1230
|
+
readonly UNPROCESSABLE_ENTITY: 422;
|
|
1231
|
+
readonly INSUFFICIENT_STORAGE: 507;
|
|
1232
|
+
readonly SWITCHING_PROTOCOLS: 101;
|
|
1233
|
+
readonly PRECONDITION_FAILED: 412;
|
|
1234
|
+
readonly MISDIRECTED_REQUEST: 421;
|
|
1235
|
+
readonly SERVICE_UNAVAILABLE: 503;
|
|
1236
|
+
readonly TEMPORARY_REDIRECT: 307;
|
|
1237
|
+
readonly PERMANENT_REDIRECT: 308;
|
|
1238
|
+
readonly METHOD_NOT_ALLOWED: 405;
|
|
1239
|
+
readonly EXPECTATION_FAILED: 417;
|
|
1240
|
+
readonly MOVED_PERMANENTLY: 301;
|
|
1241
|
+
readonly PAYLOAD_TOO_LARGE: 413;
|
|
1242
|
+
readonly FAILED_DEPENDENCY: 424;
|
|
1243
|
+
readonly TOO_MANY_REQUESTS: 429;
|
|
1244
|
+
readonly ALREADY_REPORTED: 208;
|
|
1245
|
+
readonly MULTIPLE_CHOICES: 300;
|
|
1246
|
+
readonly PAYMENT_REQUIRED: 402;
|
|
1247
|
+
readonly UPGRADE_REQUIRED: 426;
|
|
1248
|
+
readonly PARTIAL_CONTENT: 206;
|
|
1249
|
+
readonly REQUEST_TIMEOUT: 408;
|
|
1250
|
+
readonly LENGTH_REQUIRED: 411;
|
|
1251
|
+
readonly NOT_IMPLEMENTED: 501;
|
|
1252
|
+
readonly GATEWAY_TIMEOUT: 504;
|
|
1253
|
+
readonly NOT_ACCEPTABLE: 406;
|
|
1254
|
+
readonly RESET_CONTENT: 205;
|
|
1255
|
+
readonly LOOP_DETECTED: 508;
|
|
1256
|
+
readonly MULTI_STATUS: 207;
|
|
1257
|
+
readonly NOT_MODIFIED: 304;
|
|
1258
|
+
readonly UNAUTHORIZED: 401;
|
|
1259
|
+
readonly URI_TOO_LONG: 414;
|
|
1260
|
+
readonly NOT_EXTENDED: 510;
|
|
1261
|
+
readonly EARLY_HINTS: 103;
|
|
1262
|
+
readonly BAD_REQUEST: 400;
|
|
1263
|
+
readonly IM_A_TEAPOT: 418;
|
|
1264
|
+
readonly BAD_GATEWAY: 502;
|
|
1265
|
+
readonly PROCESSING: 102;
|
|
1266
|
+
readonly NO_CONTENT: 204;
|
|
1267
|
+
readonly SEE_OTHER: 303;
|
|
1268
|
+
readonly USE_PROXY: 305;
|
|
1269
|
+
readonly FORBIDDEN: 403;
|
|
1270
|
+
readonly NOT_FOUND: 404;
|
|
1271
|
+
readonly TOO_EARLY: 425;
|
|
1272
|
+
readonly CONTINUE: 100;
|
|
1273
|
+
readonly ACCEPTED: 202;
|
|
1274
|
+
readonly CONFLICT: 409;
|
|
1275
|
+
readonly CREATED: 201;
|
|
1276
|
+
readonly IM_USED: 226;
|
|
1277
|
+
readonly LOCKED: 423;
|
|
1278
|
+
readonly FOUND: 302;
|
|
1279
|
+
readonly GONE: 410;
|
|
1280
|
+
readonly OK: 200;
|
|
1281
|
+
}>;
|
|
1282
|
+
type HttpStatusCode = keyof typeof HttpStatusMessage;
|
|
1283
|
+
/**
|
|
1284
|
+
* HTTP status messages mapped by numeric code.
|
|
1285
|
+
* Use for sending descriptive text in responses or logging.
|
|
1286
|
+
*/
|
|
1287
|
+
declare const HttpStatusMessage: {
|
|
1288
|
+
readonly 431: "Request Header Fields Too Large";
|
|
1289
|
+
readonly 511: "Network Authentication Required";
|
|
1290
|
+
readonly 203: "Non-Authoritative Information";
|
|
1291
|
+
readonly 407: "Proxy Authentication Required";
|
|
1292
|
+
readonly 451: "Unavailable For Legal Reasons";
|
|
1293
|
+
readonly 505: "HTTP Version Not Supported";
|
|
1294
|
+
readonly 509: "Bandwidth Limit Exceeded";
|
|
1295
|
+
readonly 506: "Variant Also Negotiates";
|
|
1296
|
+
readonly 415: "Unsupported Media Type";
|
|
1297
|
+
readonly 416: "Range Not Satisfiable";
|
|
1298
|
+
readonly 428: "Precondition Required";
|
|
1299
|
+
readonly 500: "Internal Server Error";
|
|
1300
|
+
readonly 422: "Unprocessable Entity";
|
|
1301
|
+
readonly 507: "Insufficient Storage";
|
|
1302
|
+
readonly 101: "Switching Protocols";
|
|
1303
|
+
readonly 412: "Precondition Failed";
|
|
1304
|
+
readonly 421: "Misdirected Request";
|
|
1305
|
+
readonly 503: "Service Unavailable";
|
|
1306
|
+
readonly 307: "Temporary Redirect";
|
|
1307
|
+
readonly 308: "Permanent Redirect";
|
|
1308
|
+
readonly 405: "Method Not Allowed";
|
|
1309
|
+
readonly 417: "Expectation Failed";
|
|
1310
|
+
readonly 301: "Moved Permanently";
|
|
1311
|
+
readonly 413: "Payload Too Large";
|
|
1312
|
+
readonly 424: "Failed Dependency";
|
|
1313
|
+
readonly 429: "Too Many Requests";
|
|
1314
|
+
readonly 208: "Already Reported";
|
|
1315
|
+
readonly 300: "Multiple Choices";
|
|
1316
|
+
readonly 402: "Payment Required";
|
|
1317
|
+
readonly 426: "Upgrade Required";
|
|
1318
|
+
readonly 206: "Partial Content";
|
|
1319
|
+
readonly 408: "Request Timeout";
|
|
1320
|
+
readonly 411: "Length Required";
|
|
1321
|
+
readonly 501: "Not Implemented";
|
|
1322
|
+
readonly 504: "Gateway Timeout";
|
|
1323
|
+
readonly 406: "Not Acceptable";
|
|
1324
|
+
readonly 205: "Reset Content";
|
|
1325
|
+
readonly 508: "Loop Detected";
|
|
1326
|
+
readonly 207: "Multi-Status";
|
|
1327
|
+
readonly 304: "Not Modified";
|
|
1328
|
+
readonly 401: "Unauthorized";
|
|
1329
|
+
readonly 414: "URI Too Long";
|
|
1330
|
+
readonly 418: "I'm a Teapot";
|
|
1331
|
+
readonly 510: "Not Extended";
|
|
1332
|
+
readonly 103: "Early Hints";
|
|
1333
|
+
readonly 400: "Bad Request";
|
|
1334
|
+
readonly 502: "Bad Gateway";
|
|
1335
|
+
readonly 102: "Processing";
|
|
1336
|
+
readonly 204: "No Content";
|
|
1337
|
+
readonly 303: "See Other";
|
|
1338
|
+
readonly 305: "Use Proxy";
|
|
1339
|
+
readonly 403: "Forbidden";
|
|
1340
|
+
readonly 404: "Not Found";
|
|
1341
|
+
readonly 425: "Too Early";
|
|
1342
|
+
readonly 100: "Continue";
|
|
1343
|
+
readonly 202: "Accepted";
|
|
1344
|
+
readonly 226: "I'm Used";
|
|
1345
|
+
readonly 409: "Conflict";
|
|
1346
|
+
readonly 201: "Created";
|
|
1347
|
+
readonly 423: "Locked";
|
|
1348
|
+
readonly 302: "Found";
|
|
1349
|
+
readonly 410: "Gone";
|
|
1350
|
+
readonly 200: "OK";
|
|
1351
|
+
};
|
|
1352
|
+
type HttpStatusMessage = (typeof HttpStatusMessage)[keyof typeof HttpStatusMessage];
|
|
1353
|
+
|
|
1261
1354
|
/**
|
|
1262
1355
|
* Deeply freezes an object graph to enforce runtime immutability.
|
|
1263
1356
|
* - Handles arrays
|
|
@@ -1269,4 +1362,4 @@ declare class Email extends PrimitiveValueObject<string> {
|
|
|
1269
1362
|
*/
|
|
1270
1363
|
declare function deepFreeze<T>(value: T, seen?: WeakSet<object>): Readonly<T>;
|
|
1271
1364
|
|
|
1272
|
-
export { AggregateId, AggregateRoot, ApplicationError, type ApplicationServicePort, type CreateEventProps, DomainError, type DomainErrorCode, type DomainErrorNamespaces, type DomainErrorType, DomainEvent, type DomainEventPayload, DomainID, Email, Entity, type EntityId, type EntityProps, EntityValidationError, type ExtractErrorName, type ExtractNamespace, HttpStatus, type HttpStatusCode, HttpStatusMessage, type Immutable, InternalError, InvalidValueObjectError, type Metadata, type Primitive, PrimitiveValueObject, Result, TimeoutError, UUID, type UnionToIntersection, type UnixTimestampMillis, type UuID, ValueObject, type ValueOf, deepFreeze };
|
|
1365
|
+
export { AggregateId, AggregateRoot, ApplicationError, type ApplicationServicePort, type ClockPort, type CreateEventProps, DomainError, type DomainErrorCode, type DomainErrorNamespaces, type DomainErrorType, DomainEvent, type DomainEventPayload, DomainID, Email, Entity, type EntityId, type EntityProps, EntityValidationError, type ExtractErrorName, type ExtractNamespace, HttpStatus, type HttpStatusCode, HttpStatusMessage, type Immutable, InternalError, InvalidStateError, InvalidValueError, InvalidValueObjectError, type Metadata, type Primitive, PrimitiveValueObject, Result, TimeoutError, UUID, type UnionToIntersection, type UnixTimestampMillis, type UuID, ValueObject, type ValueOf, deepFreeze };
|