hoa 0.0.1 → 0.1.1
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/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/README.md +60 -0
- package/dist/cjs/application.js +248 -0
- package/dist/cjs/context.js +111 -0
- package/dist/cjs/lib/compose.js +40 -0
- package/dist/cjs/lib/http-error.js +61 -0
- package/dist/cjs/lib/utils.js +190 -0
- package/dist/cjs/request.js +546 -0
- package/dist/cjs/response.js +380 -0
- package/dist/esm/application.js +210 -0
- package/dist/esm/context.js +82 -0
- package/dist/esm/lib/compose.js +21 -0
- package/dist/esm/lib/http-error.js +42 -0
- package/dist/esm/lib/utils.js +161 -0
- package/dist/esm/request.js +527 -0
- package/dist/esm/response.js +361 -0
- package/package.json +62 -7
- package/types/index.d.ts +233 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var utils_exports = {};
|
|
19
|
+
__export(utils_exports, {
|
|
20
|
+
commonTypeMapping: () => commonTypeMapping,
|
|
21
|
+
encodeUrl: () => encodeUrl,
|
|
22
|
+
parseSearchParamsToQuery: () => parseSearchParamsToQuery,
|
|
23
|
+
statusEmptyMapping: () => statusEmptyMapping,
|
|
24
|
+
statusRedirectMapping: () => statusRedirectMapping,
|
|
25
|
+
statusTextMapping: () => statusTextMapping,
|
|
26
|
+
stringifyQueryToString: () => stringifyQueryToString
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(utils_exports);
|
|
29
|
+
function parseSearchParamsToQuery(searchParams) {
|
|
30
|
+
const query = {};
|
|
31
|
+
for (const [key, value] of searchParams) {
|
|
32
|
+
if (query[key] !== void 0) {
|
|
33
|
+
query[key] = [].concat(query[key], value);
|
|
34
|
+
} else {
|
|
35
|
+
query[key] = value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return query;
|
|
39
|
+
}
|
|
40
|
+
function stringifyQueryToString(query) {
|
|
41
|
+
if (!query) {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
const params = new URLSearchParams();
|
|
45
|
+
for (const [key, value] of Object.entries(query)) {
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
value.forEach((v) => params.append(key, v ?? ""));
|
|
48
|
+
} else {
|
|
49
|
+
params.append(key, value ?? "");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return params.toString();
|
|
53
|
+
}
|
|
54
|
+
const statusTextMapping = {
|
|
55
|
+
100: "Continue",
|
|
56
|
+
101: "Switching Protocols",
|
|
57
|
+
102: "Processing",
|
|
58
|
+
103: "Early Hints",
|
|
59
|
+
200: "OK",
|
|
60
|
+
201: "Created",
|
|
61
|
+
202: "Accepted",
|
|
62
|
+
203: "Non-Authoritative Information",
|
|
63
|
+
204: "No Content",
|
|
64
|
+
205: "Reset Content",
|
|
65
|
+
206: "Partial Content",
|
|
66
|
+
207: "Multi-Status",
|
|
67
|
+
208: "Already Reported",
|
|
68
|
+
226: "IM Used",
|
|
69
|
+
300: "Multiple Choices",
|
|
70
|
+
301: "Moved Permanently",
|
|
71
|
+
302: "Found",
|
|
72
|
+
303: "See Other",
|
|
73
|
+
304: "Not Modified",
|
|
74
|
+
305: "Use Proxy",
|
|
75
|
+
307: "Temporary Redirect",
|
|
76
|
+
308: "Permanent Redirect",
|
|
77
|
+
400: "Bad Request",
|
|
78
|
+
401: "Unauthorized",
|
|
79
|
+
402: "Payment Required",
|
|
80
|
+
403: "Forbidden",
|
|
81
|
+
404: "Not Found",
|
|
82
|
+
405: "Method Not Allowed",
|
|
83
|
+
406: "Not Acceptable",
|
|
84
|
+
407: "Proxy Authentication Required",
|
|
85
|
+
408: "Request Timeout",
|
|
86
|
+
409: "Conflict",
|
|
87
|
+
410: "Gone",
|
|
88
|
+
411: "Length Required",
|
|
89
|
+
412: "Precondition Failed",
|
|
90
|
+
413: "Payload Too Large",
|
|
91
|
+
414: "URI Too Long",
|
|
92
|
+
415: "Unsupported Media Type",
|
|
93
|
+
416: "Range Not Satisfiable",
|
|
94
|
+
417: "Expectation Failed",
|
|
95
|
+
418: "I'm a Teapot",
|
|
96
|
+
421: "Misdirected Request",
|
|
97
|
+
422: "Unprocessable Entity",
|
|
98
|
+
423: "Locked",
|
|
99
|
+
424: "Failed Dependency",
|
|
100
|
+
425: "Too Early",
|
|
101
|
+
426: "Upgrade Required",
|
|
102
|
+
428: "Precondition Required",
|
|
103
|
+
429: "Too Many Requests",
|
|
104
|
+
431: "Request Header Fields Too Large",
|
|
105
|
+
451: "Unavailable For Legal Reasons",
|
|
106
|
+
500: "Internal Server Error",
|
|
107
|
+
501: "Not Implemented",
|
|
108
|
+
502: "Bad Gateway",
|
|
109
|
+
503: "Service Unavailable",
|
|
110
|
+
504: "Gateway Timeout",
|
|
111
|
+
505: "HTTP Version Not Supported",
|
|
112
|
+
506: "Variant Also Negotiates",
|
|
113
|
+
507: "Insufficient Storage",
|
|
114
|
+
508: "Loop Detected",
|
|
115
|
+
509: "Bandwidth Limit Exceeded",
|
|
116
|
+
510: "Not Extended",
|
|
117
|
+
511: "Network Authentication Required"
|
|
118
|
+
};
|
|
119
|
+
const statusRedirectMapping = {
|
|
120
|
+
300: true,
|
|
121
|
+
301: true,
|
|
122
|
+
302: true,
|
|
123
|
+
303: true,
|
|
124
|
+
305: true,
|
|
125
|
+
307: true,
|
|
126
|
+
308: true
|
|
127
|
+
};
|
|
128
|
+
const statusEmptyMapping = {
|
|
129
|
+
204: true,
|
|
130
|
+
205: true,
|
|
131
|
+
304: true
|
|
132
|
+
};
|
|
133
|
+
const commonTypeMapping = {
|
|
134
|
+
// Text types
|
|
135
|
+
html: "text/html;charset=UTF-8",
|
|
136
|
+
text: "text/plain;charset=UTF-8",
|
|
137
|
+
xml: "text/xml;charset=UTF-8",
|
|
138
|
+
md: "text/markdown;charset=UTF-8",
|
|
139
|
+
// Application types
|
|
140
|
+
json: "application/json",
|
|
141
|
+
form: "application/x-www-form-urlencoded;charset=UTF-8",
|
|
142
|
+
pdf: "application/pdf",
|
|
143
|
+
zip: "application/zip",
|
|
144
|
+
wasm: "application/wasm",
|
|
145
|
+
webmanifest: "application/manifest+json",
|
|
146
|
+
// JavaScript/TypeScript
|
|
147
|
+
js: "application/javascript;charset=UTF-8",
|
|
148
|
+
ts: "application/typescript;charset=UTF-8",
|
|
149
|
+
// Image types
|
|
150
|
+
png: "image/png",
|
|
151
|
+
jpg: "image/jpeg",
|
|
152
|
+
jpeg: "image/jpeg",
|
|
153
|
+
gif: "image/gif",
|
|
154
|
+
svg: "image/svg+xml",
|
|
155
|
+
webp: "image/webp",
|
|
156
|
+
avif: "image/avif",
|
|
157
|
+
ico: "image/x-icon",
|
|
158
|
+
// Audio types
|
|
159
|
+
mp3: "audio/mpeg",
|
|
160
|
+
wav: "audio/wav",
|
|
161
|
+
ogg: "audio/ogg",
|
|
162
|
+
// Video types
|
|
163
|
+
mp4: "video/mp4",
|
|
164
|
+
webm: "video/webm",
|
|
165
|
+
avi: "video/x-msvideo",
|
|
166
|
+
mov: "video/quicktime",
|
|
167
|
+
// Font types
|
|
168
|
+
woff: "font/woff",
|
|
169
|
+
woff2: "font/woff2",
|
|
170
|
+
ttf: "font/ttf",
|
|
171
|
+
otf: "font/otf",
|
|
172
|
+
// Binary
|
|
173
|
+
bin: "application/octet-stream"
|
|
174
|
+
};
|
|
175
|
+
const ENCODE_CHARS_REGEXP = /(?:[^\x21\x23-\x3B\x3D\x3F-\x5F\x61-\x7A\x7C\x7E]|%(?:[^0-9A-Fa-f]|[0-9A-Fa-f][^0-9A-Fa-f]|$))+/g;
|
|
176
|
+
const UNMATCHED_SURROGATE_PAIR_REGEXP = /(^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF]([^\uDC00-\uDFFF]|$)/g;
|
|
177
|
+
const UNMATCHED_SURROGATE_PAIR_REPLACE = "$1\uFFFD$2";
|
|
178
|
+
function encodeUrl(url) {
|
|
179
|
+
return String(url).replace(UNMATCHED_SURROGATE_PAIR_REGEXP, UNMATCHED_SURROGATE_PAIR_REPLACE).replace(ENCODE_CHARS_REGEXP, encodeURI);
|
|
180
|
+
}
|
|
181
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
182
|
+
0 && (module.exports = {
|
|
183
|
+
commonTypeMapping,
|
|
184
|
+
encodeUrl,
|
|
185
|
+
parseSearchParamsToQuery,
|
|
186
|
+
statusEmptyMapping,
|
|
187
|
+
statusRedirectMapping,
|
|
188
|
+
statusTextMapping,
|
|
189
|
+
stringifyQueryToString
|
|
190
|
+
});
|