@little-nebulae/http 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/LICENSE.txt +21 -0
- package/README.md +1 -0
- package/dist/index.d.ts +203 -0
- package/dist/index.js +98 -0
- package/package.json +47 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ryan Luong
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# HTTP library
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { ValueOf } from "@little-nebulae/type-utils";
|
|
2
|
+
//#region src/constants/headers.d.ts
|
|
3
|
+
export declare const HTTP_HEADER_RECORD: {
|
|
4
|
+
readonly AUTHORIZATION: "authorization";
|
|
5
|
+
readonly CONTENT_TYPE: "content-type";
|
|
6
|
+
readonly COOKIE: "cookie";
|
|
7
|
+
readonly RETRY_AFTER: "retry-after";
|
|
8
|
+
};
|
|
9
|
+
export type HttpHeader = ValueOf<typeof HTTP_HEADER_RECORD>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/constants/request-methods.d.ts
|
|
12
|
+
export declare const HTTP_REQUEST_METHOD_RECORD: {
|
|
13
|
+
readonly GET: "GET";
|
|
14
|
+
readonly POST: "POST";
|
|
15
|
+
readonly DELETE: "DELETE";
|
|
16
|
+
readonly PUT: "PUT";
|
|
17
|
+
readonly PATCH: "PATCH";
|
|
18
|
+
readonly HEAD: "HEAD";
|
|
19
|
+
readonly OPTIONS: "OPTIONS";
|
|
20
|
+
readonly TRACE: "TRACE";
|
|
21
|
+
readonly CONNECT: "CONNECT";
|
|
22
|
+
};
|
|
23
|
+
export type HttpRequestMethod = ValueOf<typeof HTTP_REQUEST_METHOD_RECORD>;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/constants/response-statuses/index.d.ts
|
|
26
|
+
export declare const HTTP_RESPONSE_STATUS_RECORD: {
|
|
27
|
+
readonly BAD_REQUEST: {
|
|
28
|
+
readonly code: 400;
|
|
29
|
+
readonly text: "Bad Request";
|
|
30
|
+
};
|
|
31
|
+
readonly UNAUTHORIZED: {
|
|
32
|
+
readonly code: 401;
|
|
33
|
+
readonly text: "Unauthorized";
|
|
34
|
+
};
|
|
35
|
+
readonly FORBIDDEN: {
|
|
36
|
+
readonly code: 403;
|
|
37
|
+
readonly text: "Forbidden";
|
|
38
|
+
};
|
|
39
|
+
readonly NOT_FOUND: {
|
|
40
|
+
readonly code: 404;
|
|
41
|
+
readonly text: "Not Found";
|
|
42
|
+
};
|
|
43
|
+
readonly CONFLICT: {
|
|
44
|
+
readonly code: 409;
|
|
45
|
+
readonly text: "Conflict";
|
|
46
|
+
};
|
|
47
|
+
readonly UNPROCESSABLE_CONTENT: {
|
|
48
|
+
readonly code: 422;
|
|
49
|
+
readonly text: "Unprocessable Content";
|
|
50
|
+
};
|
|
51
|
+
readonly TOO_MANY_REQUESTS: {
|
|
52
|
+
readonly code: 429;
|
|
53
|
+
readonly text: "Too Many Requests";
|
|
54
|
+
};
|
|
55
|
+
readonly INTERNAL_SERVER_ERROR: {
|
|
56
|
+
readonly code: 500;
|
|
57
|
+
readonly text: "Internal Server Error";
|
|
58
|
+
};
|
|
59
|
+
readonly SERVICE_UNAVAILABLE: {
|
|
60
|
+
readonly code: 503;
|
|
61
|
+
readonly text: "Service Unavailable";
|
|
62
|
+
};
|
|
63
|
+
readonly GATEWAY_TIMEOUT: {
|
|
64
|
+
readonly code: 504;
|
|
65
|
+
readonly text: "Gateway Timeout";
|
|
66
|
+
};
|
|
67
|
+
readonly OK: {
|
|
68
|
+
readonly code: 200;
|
|
69
|
+
readonly text: "OK";
|
|
70
|
+
};
|
|
71
|
+
readonly CREATED: {
|
|
72
|
+
readonly code: 201;
|
|
73
|
+
readonly text: "Created";
|
|
74
|
+
};
|
|
75
|
+
readonly NO_CONTENT: {
|
|
76
|
+
readonly code: 204;
|
|
77
|
+
readonly text: "No Content";
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
export type HttpResponseStatusRecord = typeof HTTP_RESPONSE_STATUS_RECORD;
|
|
81
|
+
export type HttpResponseStatusCode = ValueOf<HttpResponseStatusRecord>["code"];
|
|
82
|
+
export type HttpResponseStatusText = ValueOf<HttpResponseStatusRecord>["text"];
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/constants/response-statuses/success.d.ts
|
|
85
|
+
export declare const HTTP_SUCCESSFUL_RESPONSE_STATUS_RECORD: {
|
|
86
|
+
readonly OK: {
|
|
87
|
+
readonly code: 200;
|
|
88
|
+
readonly text: "OK";
|
|
89
|
+
};
|
|
90
|
+
readonly CREATED: {
|
|
91
|
+
readonly code: 201;
|
|
92
|
+
readonly text: "Created";
|
|
93
|
+
};
|
|
94
|
+
readonly NO_CONTENT: {
|
|
95
|
+
readonly code: 204;
|
|
96
|
+
readonly text: "No Content";
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
export type HttpSuccessfulResponseStatusRecord = typeof HTTP_SUCCESSFUL_RESPONSE_STATUS_RECORD;
|
|
100
|
+
export type HttpSuccessfulResponseStatusCode = ValueOf<HttpSuccessfulResponseStatusRecord>["code"];
|
|
101
|
+
export type HttpSuccessfulResponseStatusText = ValueOf<HttpSuccessfulResponseStatusRecord>["text"];
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/constants/response-statuses/error/index.d.ts
|
|
104
|
+
export declare const HTTP_ERROR_RESPONSE_STATUS_RECORD: {
|
|
105
|
+
readonly BAD_REQUEST: {
|
|
106
|
+
readonly code: 400;
|
|
107
|
+
readonly text: "Bad Request";
|
|
108
|
+
};
|
|
109
|
+
readonly UNAUTHORIZED: {
|
|
110
|
+
readonly code: 401;
|
|
111
|
+
readonly text: "Unauthorized";
|
|
112
|
+
};
|
|
113
|
+
readonly FORBIDDEN: {
|
|
114
|
+
readonly code: 403;
|
|
115
|
+
readonly text: "Forbidden";
|
|
116
|
+
};
|
|
117
|
+
readonly NOT_FOUND: {
|
|
118
|
+
readonly code: 404;
|
|
119
|
+
readonly text: "Not Found";
|
|
120
|
+
};
|
|
121
|
+
readonly CONFLICT: {
|
|
122
|
+
readonly code: 409;
|
|
123
|
+
readonly text: "Conflict";
|
|
124
|
+
};
|
|
125
|
+
readonly UNPROCESSABLE_CONTENT: {
|
|
126
|
+
readonly code: 422;
|
|
127
|
+
readonly text: "Unprocessable Content";
|
|
128
|
+
};
|
|
129
|
+
readonly TOO_MANY_REQUESTS: {
|
|
130
|
+
readonly code: 429;
|
|
131
|
+
readonly text: "Too Many Requests";
|
|
132
|
+
};
|
|
133
|
+
readonly INTERNAL_SERVER_ERROR: {
|
|
134
|
+
readonly code: 500;
|
|
135
|
+
readonly text: "Internal Server Error";
|
|
136
|
+
};
|
|
137
|
+
readonly SERVICE_UNAVAILABLE: {
|
|
138
|
+
readonly code: 503;
|
|
139
|
+
readonly text: "Service Unavailable";
|
|
140
|
+
};
|
|
141
|
+
readonly GATEWAY_TIMEOUT: {
|
|
142
|
+
readonly code: 504;
|
|
143
|
+
readonly text: "Gateway Timeout";
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
export type HttpErrorResponseStatusRecord = typeof HTTP_ERROR_RESPONSE_STATUS_RECORD;
|
|
147
|
+
export type HttpErrorResponseStatusCode = ValueOf<HttpErrorResponseStatusRecord>["code"];
|
|
148
|
+
export type HttpErrorResponseStatusText = ValueOf<HttpErrorResponseStatusRecord>["text"];
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/constants/response-statuses/error/client.d.ts
|
|
151
|
+
export declare const HTTP_CLIENT_ERROR_RESPONSE_STATUS_RECORD: {
|
|
152
|
+
readonly BAD_REQUEST: {
|
|
153
|
+
readonly code: 400;
|
|
154
|
+
readonly text: "Bad Request";
|
|
155
|
+
};
|
|
156
|
+
readonly UNAUTHORIZED: {
|
|
157
|
+
readonly code: 401;
|
|
158
|
+
readonly text: "Unauthorized";
|
|
159
|
+
};
|
|
160
|
+
readonly FORBIDDEN: {
|
|
161
|
+
readonly code: 403;
|
|
162
|
+
readonly text: "Forbidden";
|
|
163
|
+
};
|
|
164
|
+
readonly NOT_FOUND: {
|
|
165
|
+
readonly code: 404;
|
|
166
|
+
readonly text: "Not Found";
|
|
167
|
+
};
|
|
168
|
+
readonly CONFLICT: {
|
|
169
|
+
readonly code: 409;
|
|
170
|
+
readonly text: "Conflict";
|
|
171
|
+
};
|
|
172
|
+
readonly UNPROCESSABLE_CONTENT: {
|
|
173
|
+
readonly code: 422;
|
|
174
|
+
readonly text: "Unprocessable Content";
|
|
175
|
+
};
|
|
176
|
+
readonly TOO_MANY_REQUESTS: {
|
|
177
|
+
readonly code: 429;
|
|
178
|
+
readonly text: "Too Many Requests";
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
export type HttpClientErrorResponseStatusRecord = typeof HTTP_CLIENT_ERROR_RESPONSE_STATUS_RECORD;
|
|
182
|
+
export type HttpClientErrorResponseStatusCode = ValueOf<HttpClientErrorResponseStatusRecord>["code"];
|
|
183
|
+
export type HttpClientErrorResponseStatusText = ValueOf<HttpClientErrorResponseStatusRecord>["text"];
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/constants/response-statuses/error/server.d.ts
|
|
186
|
+
export declare const HTTP_SERVER_ERROR_RESPONSE_STATUS_RECORD: {
|
|
187
|
+
readonly INTERNAL_SERVER_ERROR: {
|
|
188
|
+
readonly code: 500;
|
|
189
|
+
readonly text: "Internal Server Error";
|
|
190
|
+
};
|
|
191
|
+
readonly SERVICE_UNAVAILABLE: {
|
|
192
|
+
readonly code: 503;
|
|
193
|
+
readonly text: "Service Unavailable";
|
|
194
|
+
};
|
|
195
|
+
readonly GATEWAY_TIMEOUT: {
|
|
196
|
+
readonly code: 504;
|
|
197
|
+
readonly text: "Gateway Timeout";
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
export type HttpServerErrorResponseStatusRecord = typeof HTTP_SERVER_ERROR_RESPONSE_STATUS_RECORD;
|
|
201
|
+
export type HttpServerErrorResponseStatusCode = ValueOf<HttpServerErrorResponseStatusRecord>["code"];
|
|
202
|
+
export type HttpServerErrorResponseStatusText = ValueOf<HttpServerErrorResponseStatusRecord>["text"];
|
|
203
|
+
//#endregion
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
//#region src/constants/headers.ts
|
|
2
|
+
const HTTP_HEADER_RECORD = {
|
|
3
|
+
AUTHORIZATION: "authorization",
|
|
4
|
+
CONTENT_TYPE: "content-type",
|
|
5
|
+
COOKIE: "cookie",
|
|
6
|
+
RETRY_AFTER: "retry-after"
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/constants/request-methods.ts
|
|
10
|
+
const HTTP_REQUEST_METHOD_RECORD = {
|
|
11
|
+
GET: "GET",
|
|
12
|
+
POST: "POST",
|
|
13
|
+
DELETE: "DELETE",
|
|
14
|
+
PUT: "PUT",
|
|
15
|
+
PATCH: "PATCH",
|
|
16
|
+
HEAD: "HEAD",
|
|
17
|
+
OPTIONS: "OPTIONS",
|
|
18
|
+
TRACE: "TRACE",
|
|
19
|
+
CONNECT: "CONNECT"
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/constants/response-statuses/error/client.ts
|
|
23
|
+
const HTTP_CLIENT_ERROR_RESPONSE_STATUS_RECORD = {
|
|
24
|
+
BAD_REQUEST: {
|
|
25
|
+
code: 400,
|
|
26
|
+
text: "Bad Request"
|
|
27
|
+
},
|
|
28
|
+
UNAUTHORIZED: {
|
|
29
|
+
code: 401,
|
|
30
|
+
text: "Unauthorized"
|
|
31
|
+
},
|
|
32
|
+
FORBIDDEN: {
|
|
33
|
+
code: 403,
|
|
34
|
+
text: "Forbidden"
|
|
35
|
+
},
|
|
36
|
+
NOT_FOUND: {
|
|
37
|
+
code: 404,
|
|
38
|
+
text: "Not Found"
|
|
39
|
+
},
|
|
40
|
+
CONFLICT: {
|
|
41
|
+
code: 409,
|
|
42
|
+
text: "Conflict"
|
|
43
|
+
},
|
|
44
|
+
UNPROCESSABLE_CONTENT: {
|
|
45
|
+
code: 422,
|
|
46
|
+
text: "Unprocessable Content"
|
|
47
|
+
},
|
|
48
|
+
TOO_MANY_REQUESTS: {
|
|
49
|
+
code: 429,
|
|
50
|
+
text: "Too Many Requests"
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/constants/response-statuses/error/server.ts
|
|
55
|
+
const HTTP_SERVER_ERROR_RESPONSE_STATUS_RECORD = {
|
|
56
|
+
INTERNAL_SERVER_ERROR: {
|
|
57
|
+
code: 500,
|
|
58
|
+
text: "Internal Server Error"
|
|
59
|
+
},
|
|
60
|
+
SERVICE_UNAVAILABLE: {
|
|
61
|
+
code: 503,
|
|
62
|
+
text: "Service Unavailable"
|
|
63
|
+
},
|
|
64
|
+
GATEWAY_TIMEOUT: {
|
|
65
|
+
code: 504,
|
|
66
|
+
text: "Gateway Timeout"
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/constants/response-statuses/error/index.ts
|
|
71
|
+
const HTTP_ERROR_RESPONSE_STATUS_RECORD = {
|
|
72
|
+
...HTTP_CLIENT_ERROR_RESPONSE_STATUS_RECORD,
|
|
73
|
+
...HTTP_SERVER_ERROR_RESPONSE_STATUS_RECORD
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/constants/response-statuses/success.ts
|
|
77
|
+
const HTTP_SUCCESSFUL_RESPONSE_STATUS_RECORD = {
|
|
78
|
+
OK: {
|
|
79
|
+
code: 200,
|
|
80
|
+
text: "OK"
|
|
81
|
+
},
|
|
82
|
+
CREATED: {
|
|
83
|
+
code: 201,
|
|
84
|
+
text: "Created"
|
|
85
|
+
},
|
|
86
|
+
NO_CONTENT: {
|
|
87
|
+
code: 204,
|
|
88
|
+
text: "No Content"
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/constants/response-statuses/index.ts
|
|
93
|
+
const HTTP_RESPONSE_STATUS_RECORD = {
|
|
94
|
+
...HTTP_SUCCESSFUL_RESPONSE_STATUS_RECORD,
|
|
95
|
+
...HTTP_ERROR_RESPONSE_STATUS_RECORD
|
|
96
|
+
};
|
|
97
|
+
//#endregion
|
|
98
|
+
export { HTTP_CLIENT_ERROR_RESPONSE_STATUS_RECORD, HTTP_ERROR_RESPONSE_STATUS_RECORD, HTTP_HEADER_RECORD, HTTP_REQUEST_METHOD_RECORD, HTTP_RESPONSE_STATUS_RECORD, HTTP_SERVER_ERROR_RESPONSE_STATUS_RECORD, HTTP_SUCCESSFUL_RESPONSE_STATUS_RECORD };
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@little-nebulae/http",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.js",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@arethetypeswrong/core": "0.18.5",
|
|
15
|
+
"@little-nebulae/type-utils": "1.1.0",
|
|
16
|
+
"@types/node": "26.6.2",
|
|
17
|
+
"oxfmt": "0.68.0",
|
|
18
|
+
"oxlint": "1.83.0",
|
|
19
|
+
"oxlint-tsgolint": "7.0.2002",
|
|
20
|
+
"publint": "0.3.24",
|
|
21
|
+
"tsdown": "0.23.0",
|
|
22
|
+
"tsx": "4.23.13",
|
|
23
|
+
"typescript": "7.0.2",
|
|
24
|
+
"vitest": "5.0.1"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@little-nebulae/type-utils": "^1.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devEngines": {
|
|
30
|
+
"packageManager": {
|
|
31
|
+
"name": "pnpm",
|
|
32
|
+
"version": "12.5.1",
|
|
33
|
+
"onFail": "warn"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsdown",
|
|
38
|
+
"try": "tsx ./src/try.ts",
|
|
39
|
+
"fmt": "oxfmt --disable-nested-config",
|
|
40
|
+
"fmt:check": "oxfmt --check --disable-nested-config",
|
|
41
|
+
"lint": "oxlint --disable-nested-config",
|
|
42
|
+
"lint:fix": "oxlint --fix --disable-nested-config",
|
|
43
|
+
"check": "pnpm run lint && pnpm run fmt:check",
|
|
44
|
+
"fix": "pnpm run lint:fix && pnpm run fmt",
|
|
45
|
+
"test": "vitest run"
|
|
46
|
+
}
|
|
47
|
+
}
|