@little-nebulae/http 0.3.1 → 0.5.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.ts +52 -0
- package/dist/index.js +59 -1
- package/package.json +6 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ValueOf } from "type-fest";
|
|
2
|
+
import { ExtractFrom } from "@little-nebulae/utility-types";
|
|
2
3
|
export declare const HTTP_HEADER_ENUM: {
|
|
3
4
|
readonly AUTHORIZATION: "authorization";
|
|
4
5
|
readonly CACHE_CONTROL: "cache-control";
|
|
@@ -28,6 +29,7 @@ export declare const HTTP_HEADER_ENUM: {
|
|
|
28
29
|
export type HttpHeader = ValueOf<typeof HTTP_HEADER_ENUM>;
|
|
29
30
|
export declare const HTTP_REQUEST_METHOD_ENUM: {
|
|
30
31
|
readonly GET: "GET";
|
|
32
|
+
readonly QUERY: "QUERY";
|
|
31
33
|
readonly POST: "POST";
|
|
32
34
|
readonly DELETE: "DELETE";
|
|
33
35
|
readonly PUT: "PUT";
|
|
@@ -38,6 +40,15 @@ export declare const HTTP_REQUEST_METHOD_ENUM: {
|
|
|
38
40
|
readonly CONNECT: "CONNECT";
|
|
39
41
|
};
|
|
40
42
|
export type HttpRequestMethod = ValueOf<typeof HTTP_REQUEST_METHOD_ENUM>;
|
|
43
|
+
export declare const HTTP_CACHE_MODE_ENUM: {
|
|
44
|
+
readonly DEFAULT: "default";
|
|
45
|
+
readonly NO_STORE: "no-store";
|
|
46
|
+
readonly RELOAD: "reload";
|
|
47
|
+
readonly NO_CACHE: "no-cache";
|
|
48
|
+
readonly FORCE_CACHE: "force-cache";
|
|
49
|
+
readonly ONLY_IF_CACHED: "only-if-cached";
|
|
50
|
+
};
|
|
51
|
+
export type HttpCacheMode = ValueOf<typeof HTTP_CACHE_MODE_ENUM>;
|
|
41
52
|
export declare const HTTP_RESPONSE_STATUS_ENUM: {
|
|
42
53
|
readonly BAD_REQUEST: {
|
|
43
54
|
readonly CODE: 400;
|
|
@@ -713,4 +724,45 @@ export declare const HTTP_SERVER_ERROR_RESPONSE_STATUS_ENUM: {
|
|
|
713
724
|
type HttpServerErrorResponseStatus = ValueOf<typeof HTTP_SERVER_ERROR_RESPONSE_STATUS_ENUM>;
|
|
714
725
|
export type HttpServerErrorResponseStatusCode = HttpServerErrorResponseStatus["CODE"];
|
|
715
726
|
export type HttpServerErrorResponseStatusText = HttpServerErrorResponseStatus["TEXT"];
|
|
727
|
+
export declare const HTTP_APPLICATION_MEDIA_TYPE_ENUM: {
|
|
728
|
+
readonly BINARY: "application/octet-stream";
|
|
729
|
+
readonly JSON: "application/json";
|
|
730
|
+
readonly PDF: "application/pdf";
|
|
731
|
+
};
|
|
732
|
+
export type HttpApplicationMediaType = ValueOf<typeof HTTP_APPLICATION_MEDIA_TYPE_ENUM>;
|
|
733
|
+
export declare const HTTP_TEXT_MEDIA_TYPE_ENUM: {
|
|
734
|
+
readonly CSS: "text/css";
|
|
735
|
+
readonly CSV: "text/csv";
|
|
736
|
+
readonly HTML: "text/html";
|
|
737
|
+
readonly JAVASCRIPT: "text/javascript";
|
|
738
|
+
readonly MARKDOWN: "text/markdown";
|
|
739
|
+
readonly PLAIN: "text/plain";
|
|
740
|
+
};
|
|
741
|
+
export type HttpTextMediaType = ValueOf<typeof HTTP_TEXT_MEDIA_TYPE_ENUM>;
|
|
742
|
+
export declare const HTTP_MEDIA_TYPE_ENUM: {
|
|
743
|
+
BINARY: "application/octet-stream";
|
|
744
|
+
JSON: "application/json";
|
|
745
|
+
PDF: "application/pdf";
|
|
746
|
+
CSS: "text/css";
|
|
747
|
+
CSV: "text/csv";
|
|
748
|
+
HTML: "text/html";
|
|
749
|
+
JAVASCRIPT: "text/javascript";
|
|
750
|
+
MARKDOWN: "text/markdown";
|
|
751
|
+
PLAIN: "text/plain";
|
|
752
|
+
};
|
|
753
|
+
export type HttpMediaType = ValueOf<typeof HTTP_MEDIA_TYPE_ENUM>;
|
|
754
|
+
export type HttpRequestMethodThatAllowsBodyInRequest = ExtractFrom<HttpRequestMethod, "OPTIONS">;
|
|
755
|
+
export declare function isHttpRequestMethodThatAllowsBodyInRequest(method: string): method is HttpRequestMethodThatAllowsBodyInRequest;
|
|
756
|
+
export type HttpRequestMethodThatAllowsBodyInSuccessfulResponse = ExtractFrom<HttpRequestMethod, "DELETE" | "OPTIONS" | "PATCH" | "PUT">;
|
|
757
|
+
export declare function isHttpRequestMethodThatAllowsBodyInSuccessfulResponse(method: string): method is HttpRequestMethodThatAllowsBodyInSuccessfulResponse;
|
|
758
|
+
export type HttpRequestMethodThatForbidsBodyInRequest = ExtractFrom<HttpRequestMethod, "CONNECT" | "DELETE" | "GET" | "HEAD" | "TRACE">;
|
|
759
|
+
export declare function isHttpRequestMethodThatForbidsBodyInRequest(method: string): method is HttpRequestMethodThatForbidsBodyInRequest;
|
|
760
|
+
export type HttpRequestMethodThatForbidsBodyInSuccessfulResponse = ExtractFrom<HttpRequestMethod, "CONNECT" | "HEAD">;
|
|
761
|
+
export declare function isHttpRequestMethodThatForbidsBodyInSuccessfulResponse(method: string): method is HttpRequestMethodThatForbidsBodyInSuccessfulResponse;
|
|
762
|
+
export type HttpRequestMethodThatForbidsBodyInErrorResponse = ExtractFrom<HttpRequestMethod, "HEAD">;
|
|
763
|
+
export declare function isHttpRequestMethodThatForbidsBodyInErrorResponse(method: string): method is HttpRequestMethodThatForbidsBodyInErrorResponse;
|
|
764
|
+
export type HttpRequestMethodThatRequiresBodyInRequest = ExtractFrom<HttpRequestMethod, "PATCH" | "POST" | "PUT" | "QUERY">;
|
|
765
|
+
export declare function isHttpRequestMethodThatRequiresBodyInRequest(method: string): method is HttpRequestMethodThatRequiresBodyInRequest;
|
|
766
|
+
export type HttpRequestMethodThatRequiresBodyInSuccessfulResponse = ExtractFrom<HttpRequestMethod, "GET" | "POST" | "QUERY" | "TRACE">;
|
|
767
|
+
export declare function isHttpRequestMethodThatRequiresBodyInSuccessfulResponse(method: string): method is HttpRequestMethodThatRequiresBodyInSuccessfulResponse;
|
|
716
768
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ const HTTP_HEADER_ENUM = {
|
|
|
28
28
|
// src/constants/request-methods.ts
|
|
29
29
|
const HTTP_REQUEST_METHOD_ENUM = {
|
|
30
30
|
GET: "GET",
|
|
31
|
+
QUERY: "QUERY",
|
|
31
32
|
POST: "POST",
|
|
32
33
|
DELETE: "DELETE",
|
|
33
34
|
PUT: "PUT",
|
|
@@ -37,6 +38,15 @@ const HTTP_REQUEST_METHOD_ENUM = {
|
|
|
37
38
|
TRACE: "TRACE",
|
|
38
39
|
CONNECT: "CONNECT"
|
|
39
40
|
};
|
|
41
|
+
// src/constants/cache-mode.ts
|
|
42
|
+
const HTTP_CACHE_MODE_ENUM = {
|
|
43
|
+
DEFAULT: "default",
|
|
44
|
+
NO_STORE: "no-store",
|
|
45
|
+
RELOAD: "reload",
|
|
46
|
+
NO_CACHE: "no-cache",
|
|
47
|
+
FORCE_CACHE: "force-cache",
|
|
48
|
+
ONLY_IF_CACHED: "only-if-cached"
|
|
49
|
+
};
|
|
40
50
|
// src/constants/response-statuses/error/client.ts
|
|
41
51
|
const HTTP_CLIENT_ERROR_RESPONSE_STATUS_ENUM = {
|
|
42
52
|
BAD_REQUEST: {
|
|
@@ -304,4 +314,52 @@ const HTTP_RESPONSE_STATUS_ENUM = {
|
|
|
304
314
|
...HTTP_REDIRECTION_RESPONSE_STATUS_ENUM,
|
|
305
315
|
...HTTP_ERROR_RESPONSE_STATUS_ENUM
|
|
306
316
|
};
|
|
307
|
-
|
|
317
|
+
// src/constants/media-types/application.ts
|
|
318
|
+
const HTTP_APPLICATION_MEDIA_TYPE_ENUM = {
|
|
319
|
+
BINARY: "application/octet-stream",
|
|
320
|
+
JSON: "application/json",
|
|
321
|
+
PDF: "application/pdf"
|
|
322
|
+
};
|
|
323
|
+
// src/constants/media-types/text.ts
|
|
324
|
+
const HTTP_TEXT_MEDIA_TYPE_ENUM = {
|
|
325
|
+
CSS: "text/css",
|
|
326
|
+
CSV: "text/csv",
|
|
327
|
+
HTML: "text/html",
|
|
328
|
+
JAVASCRIPT: "text/javascript",
|
|
329
|
+
MARKDOWN: "text/markdown",
|
|
330
|
+
PLAIN: "text/plain"
|
|
331
|
+
};
|
|
332
|
+
// src/constants/media-types/index.ts
|
|
333
|
+
const HTTP_MEDIA_TYPE_ENUM = {
|
|
334
|
+
...HTTP_APPLICATION_MEDIA_TYPE_ENUM,
|
|
335
|
+
...HTTP_TEXT_MEDIA_TYPE_ENUM
|
|
336
|
+
};
|
|
337
|
+
// src/guards/request-method/allows/body-in-request.ts
|
|
338
|
+
function isHttpRequestMethodThatAllowsBodyInRequest(method) {
|
|
339
|
+
return method === HTTP_REQUEST_METHOD_ENUM.OPTIONS;
|
|
340
|
+
}
|
|
341
|
+
// src/guards/request-method/allows/body-in-successful-response.ts
|
|
342
|
+
function isHttpRequestMethodThatAllowsBodyInSuccessfulResponse(method) {
|
|
343
|
+
return method === HTTP_REQUEST_METHOD_ENUM.DELETE || method === HTTP_REQUEST_METHOD_ENUM.OPTIONS || method === HTTP_REQUEST_METHOD_ENUM.PATCH || method === HTTP_REQUEST_METHOD_ENUM.PUT;
|
|
344
|
+
}
|
|
345
|
+
// src/guards/request-method/forbids/body-in-request.ts
|
|
346
|
+
function isHttpRequestMethodThatForbidsBodyInRequest(method) {
|
|
347
|
+
return method === HTTP_REQUEST_METHOD_ENUM.CONNECT || method === HTTP_REQUEST_METHOD_ENUM.DELETE || method === HTTP_REQUEST_METHOD_ENUM.GET || method === HTTP_REQUEST_METHOD_ENUM.HEAD || method === HTTP_REQUEST_METHOD_ENUM.TRACE;
|
|
348
|
+
}
|
|
349
|
+
// src/guards/request-method/forbids/body-in-successful-response.ts
|
|
350
|
+
function isHttpRequestMethodThatForbidsBodyInSuccessfulResponse(method) {
|
|
351
|
+
return method === HTTP_REQUEST_METHOD_ENUM.CONNECT || method === HTTP_REQUEST_METHOD_ENUM.HEAD;
|
|
352
|
+
}
|
|
353
|
+
// src/guards/request-method/forbids/body-in-error-response.ts
|
|
354
|
+
function isHttpRequestMethodThatForbidsBodyInErrorResponse(method) {
|
|
355
|
+
return method === HTTP_REQUEST_METHOD_ENUM.HEAD;
|
|
356
|
+
}
|
|
357
|
+
// src/guards/request-method/requires/body-in-request.ts
|
|
358
|
+
function isHttpRequestMethodThatRequiresBodyInRequest(method) {
|
|
359
|
+
return method === HTTP_REQUEST_METHOD_ENUM.PATCH || method === HTTP_REQUEST_METHOD_ENUM.POST || method === HTTP_REQUEST_METHOD_ENUM.PUT || method === HTTP_REQUEST_METHOD_ENUM.QUERY;
|
|
360
|
+
}
|
|
361
|
+
// src/guards/request-method/requires/body-in-successful-response.ts
|
|
362
|
+
function isHttpRequestMethodThatRequiresBodyInSuccessfulResponse(method) {
|
|
363
|
+
return method === HTTP_REQUEST_METHOD_ENUM.GET || method === HTTP_REQUEST_METHOD_ENUM.POST || method === HTTP_REQUEST_METHOD_ENUM.QUERY || method === HTTP_REQUEST_METHOD_ENUM.TRACE;
|
|
364
|
+
}
|
|
365
|
+
export { HTTP_APPLICATION_MEDIA_TYPE_ENUM, HTTP_CACHE_MODE_ENUM, HTTP_CLIENT_ERROR_RESPONSE_STATUS_ENUM, HTTP_ERROR_RESPONSE_STATUS_ENUM, HTTP_HEADER_ENUM, HTTP_INFORMATIONAL_RESPONSE_STATUS_ENUM, HTTP_MEDIA_TYPE_ENUM, HTTP_REDIRECTION_RESPONSE_STATUS_ENUM, HTTP_REQUEST_METHOD_ENUM, HTTP_RESPONSE_STATUS_ENUM, HTTP_SERVER_ERROR_RESPONSE_STATUS_ENUM, HTTP_SUCCESSFUL_RESPONSE_STATUS_ENUM, HTTP_TEXT_MEDIA_TYPE_ENUM, isHttpRequestMethodThatAllowsBodyInRequest, isHttpRequestMethodThatAllowsBodyInSuccessfulResponse, isHttpRequestMethodThatForbidsBodyInErrorResponse, isHttpRequestMethodThatForbidsBodyInRequest, isHttpRequestMethodThatForbidsBodyInSuccessfulResponse, isHttpRequestMethodThatRequiresBodyInRequest, isHttpRequestMethodThatRequiresBodyInSuccessfulResponse };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@little-nebulae/http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -17,23 +17,25 @@
|
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@arethetypeswrong/core": "0.18.5",
|
|
20
|
+
"@little-nebulae/utility-types": "0.5.0",
|
|
20
21
|
"@types/node": "26.6.6",
|
|
21
22
|
"oxfmt": "0.78.0",
|
|
22
23
|
"oxlint": "1.93.0",
|
|
23
24
|
"oxlint-tsgolint": "7.0.2007",
|
|
24
25
|
"publint": "0.3.25",
|
|
25
26
|
"tsdown": "0.23.7",
|
|
26
|
-
"type-fest": "
|
|
27
|
+
"type-fest": "6.0.0",
|
|
27
28
|
"typescript": "7.1.0-beta",
|
|
28
29
|
"vitest": "5.1.0"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
31
|
-
"
|
|
32
|
+
"@little-nebulae/utility-types": "0",
|
|
33
|
+
"type-fest": "^6.0.0"
|
|
32
34
|
},
|
|
33
35
|
"devEngines": {
|
|
34
36
|
"packageManager": {
|
|
35
37
|
"name": "pnpm",
|
|
36
|
-
"version": "12.
|
|
38
|
+
"version": "12.21.0",
|
|
37
39
|
"onFail": "warn"
|
|
38
40
|
},
|
|
39
41
|
"runtime": {
|