hoa 0.3.1 → 0.3.3
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/dist/cjs/hoa.js +9 -2
- package/dist/cjs/response.js +4 -4
- package/dist/esm/hoa.js +5 -1
- package/dist/esm/response.js +4 -4
- package/package.json +1 -1
- package/types/index.d.ts +52 -45
package/CHANGELOG.md
CHANGED
package/dist/cjs/hoa.js
CHANGED
|
@@ -33,11 +33,15 @@ __export(hoa_exports, {
|
|
|
33
33
|
HoaResponse: () => import_response.default,
|
|
34
34
|
HttpError: () => import_http_error.default,
|
|
35
35
|
compose: () => import_compose.default,
|
|
36
|
-
default: () => Hoa
|
|
36
|
+
default: () => Hoa,
|
|
37
|
+
statusEmptyMapping: () => import_utils.statusEmptyMapping,
|
|
38
|
+
statusRedirectMapping: () => import_utils.statusRedirectMapping,
|
|
39
|
+
statusTextMapping: () => import_utils.statusTextMapping
|
|
37
40
|
});
|
|
38
41
|
module.exports = __toCommonJS(hoa_exports);
|
|
39
42
|
var import_compose = __toESM(require("./lib/compose.js"), 1);
|
|
40
43
|
var import_http_error = __toESM(require("./lib/http-error.js"), 1);
|
|
44
|
+
var import_utils = require("./lib/utils.js");
|
|
41
45
|
var import_context = __toESM(require("./context.js"), 1);
|
|
42
46
|
var import_request = __toESM(require("./request.js"), 1);
|
|
43
47
|
var import_response = __toESM(require("./response.js"), 1);
|
|
@@ -181,5 +185,8 @@ class Hoa {
|
|
|
181
185
|
HoaRequest,
|
|
182
186
|
HoaResponse,
|
|
183
187
|
HttpError,
|
|
184
|
-
compose
|
|
188
|
+
compose,
|
|
189
|
+
statusEmptyMapping,
|
|
190
|
+
statusRedirectMapping,
|
|
191
|
+
statusTextMapping
|
|
185
192
|
});
|
package/dist/cjs/response.js
CHANGED
|
@@ -325,10 +325,10 @@ class HoaResponse {
|
|
|
325
325
|
* @param {string} type - The content type or alias (e.g., 'json', 'html', 'application/json')
|
|
326
326
|
* @public
|
|
327
327
|
*/
|
|
328
|
-
set type(
|
|
329
|
-
if (!
|
|
330
|
-
|
|
331
|
-
this.set("Content-Type",
|
|
328
|
+
set type(val) {
|
|
329
|
+
if (!val) return;
|
|
330
|
+
val = import_utils.commonTypeMapping[val] || val;
|
|
331
|
+
this.set("Content-Type", val);
|
|
332
332
|
}
|
|
333
333
|
/**
|
|
334
334
|
* Get the response Content-Length as a number.
|
package/dist/esm/hoa.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import compose from "./lib/compose.js";
|
|
2
2
|
import HttpError from "./lib/http-error.js";
|
|
3
|
+
import { statusTextMapping, statusRedirectMapping, statusEmptyMapping } from "./lib/utils.js";
|
|
3
4
|
import HoaContext from "./context.js";
|
|
4
5
|
import HoaRequest from "./request.js";
|
|
5
6
|
import HoaResponse from "./response.js";
|
|
@@ -143,5 +144,8 @@ export {
|
|
|
143
144
|
HoaResponse,
|
|
144
145
|
HttpError,
|
|
145
146
|
compose,
|
|
146
|
-
Hoa as default
|
|
147
|
+
Hoa as default,
|
|
148
|
+
statusEmptyMapping,
|
|
149
|
+
statusRedirectMapping,
|
|
150
|
+
statusTextMapping
|
|
147
151
|
};
|
package/dist/esm/response.js
CHANGED
|
@@ -303,10 +303,10 @@ class HoaResponse {
|
|
|
303
303
|
* @param {string} type - The content type or alias (e.g., 'json', 'html', 'application/json')
|
|
304
304
|
* @public
|
|
305
305
|
*/
|
|
306
|
-
set type(
|
|
307
|
-
if (!
|
|
308
|
-
|
|
309
|
-
this.set("Content-Type",
|
|
306
|
+
set type(val) {
|
|
307
|
+
if (!val) return;
|
|
308
|
+
val = commonTypeMapping[val] || val;
|
|
309
|
+
this.set("Content-Type", val);
|
|
310
310
|
}
|
|
311
311
|
/**
|
|
312
312
|
* Get the response Content-Length as a number.
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
interface
|
|
1
|
+
interface HoaAppJson {
|
|
2
2
|
name: string;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
interface
|
|
6
|
-
app:
|
|
7
|
-
req:
|
|
8
|
-
res:
|
|
5
|
+
interface HoaContextJson {
|
|
6
|
+
app: HoaAppJson;
|
|
7
|
+
req: HoaRequestJson;
|
|
8
|
+
res: HoaResponseJson;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
interface
|
|
11
|
+
interface HoaRequestJson {
|
|
12
12
|
method: string;
|
|
13
13
|
url: string;
|
|
14
14
|
headers: Record<string, string>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
interface
|
|
17
|
+
interface HoaResponseJson {
|
|
18
18
|
status: number;
|
|
19
19
|
statusText: string;
|
|
20
20
|
headers: Record<string, string>;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
interface HoaError {
|
|
24
|
+
message?: string;
|
|
25
|
+
cause?: unknown;
|
|
26
|
+
expose?: boolean;
|
|
27
|
+
headers?: Headers | Record<string, string> | Iterable<readonly [string, string]>;
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
export type HoaExtension = (app: Hoa) => void;
|
|
24
31
|
|
|
25
32
|
export type HoaMiddleware = (ctx: HoaContext, next?: () => Promise<void>) => Promise<void> | void;
|
|
@@ -40,7 +47,7 @@ export declare class Hoa {
|
|
|
40
47
|
protected handleRequest(ctx: HoaContext, middlewareFn: HoaMiddleware): Promise<Response>;
|
|
41
48
|
protected createContext(request: Request, env?: any, executionCtx?: any): HoaContext;
|
|
42
49
|
protected onerror(err: unknown, ctx?: HoaContext): void;
|
|
43
|
-
toJSON():
|
|
50
|
+
toJSON(): HoaAppJson;
|
|
44
51
|
|
|
45
52
|
static get default(): typeof Hoa;
|
|
46
53
|
}
|
|
@@ -54,10 +61,10 @@ export declare class HoaContext {
|
|
|
54
61
|
env?: any;
|
|
55
62
|
executionCtx?: any;
|
|
56
63
|
state: Record<string, any>;
|
|
57
|
-
throw(status: number, message?: string |
|
|
58
|
-
assert<T>(value: T, status: number, message?: string |
|
|
64
|
+
throw(status: number, message?: string | HoaError, options?: HoaError): never;
|
|
65
|
+
assert<T>(value: T, status: number, message?: string | HoaError, options?: HoaError): asserts value is NonNullable<T>;
|
|
59
66
|
onerror(err: unknown): Response;
|
|
60
|
-
toJSON():
|
|
67
|
+
toJSON(): HoaContextJson;
|
|
61
68
|
readonly response: Response;
|
|
62
69
|
}
|
|
63
70
|
|
|
@@ -67,54 +74,54 @@ export declare class HoaRequest {
|
|
|
67
74
|
res: HoaResponse;
|
|
68
75
|
|
|
69
76
|
get url(): URL;
|
|
70
|
-
set url(
|
|
77
|
+
set url(val: string | URL);
|
|
71
78
|
|
|
72
79
|
get href(): string;
|
|
73
|
-
set href(
|
|
80
|
+
set href(val: string);
|
|
74
81
|
|
|
75
82
|
get origin(): string;
|
|
76
|
-
set origin(
|
|
83
|
+
set origin(val: string);
|
|
77
84
|
|
|
78
85
|
get protocol(): string;
|
|
79
|
-
set protocol(
|
|
86
|
+
set protocol(val: string);
|
|
80
87
|
|
|
81
88
|
get host(): string;
|
|
82
|
-
set host(
|
|
89
|
+
set host(val: string);
|
|
83
90
|
|
|
84
91
|
get hostname(): string;
|
|
85
|
-
set hostname(
|
|
92
|
+
set hostname(val: string);
|
|
86
93
|
|
|
87
94
|
get port(): string;
|
|
88
|
-
set port(
|
|
95
|
+
set port(val: string);
|
|
89
96
|
|
|
90
97
|
get pathname(): string;
|
|
91
|
-
set pathname(
|
|
98
|
+
set pathname(val: string);
|
|
92
99
|
|
|
93
100
|
get search(): string;
|
|
94
|
-
set search(
|
|
101
|
+
set search(val: string);
|
|
95
102
|
|
|
96
103
|
get hash(): string;
|
|
97
|
-
set hash(
|
|
104
|
+
set hash(val: string);
|
|
98
105
|
|
|
99
106
|
get method(): string;
|
|
100
|
-
set method(
|
|
107
|
+
set method(val: string);
|
|
101
108
|
|
|
102
109
|
get query(): Record<string, string | string[]>;
|
|
103
|
-
set query(
|
|
110
|
+
set query(val: Record<string, string | string[]>);
|
|
104
111
|
|
|
105
112
|
get headers(): Record<string, string>;
|
|
106
|
-
set headers(
|
|
113
|
+
set headers(val: Headers | Record<string, string> | Iterable<readonly [string, string]>);
|
|
107
114
|
|
|
108
115
|
get body(): ReadableStream<Uint8Array> | null;
|
|
109
|
-
set body(
|
|
116
|
+
set body(val: any);
|
|
110
117
|
|
|
111
118
|
get(field: string): string | null;
|
|
112
119
|
getSetCookie(): string[];
|
|
113
120
|
has(field: string): boolean;
|
|
114
|
-
set(field: string,
|
|
115
|
-
set(
|
|
116
|
-
append(field: string,
|
|
117
|
-
append(
|
|
121
|
+
set(field: string, val: string): void;
|
|
122
|
+
set(field: Record<string, string>): void;
|
|
123
|
+
append(field: string, val: string): void;
|
|
124
|
+
append(field: Record<string, string>): void;
|
|
118
125
|
delete(field: string): void;
|
|
119
126
|
|
|
120
127
|
get ips(): string[];
|
|
@@ -129,10 +136,10 @@ export declare class HoaRequest {
|
|
|
129
136
|
text(): Promise<string>;
|
|
130
137
|
json<T = any>(): Promise<T>;
|
|
131
138
|
formData(): Promise<FormData>;
|
|
132
|
-
toJSON():
|
|
139
|
+
toJSON(): HoaRequestJson;
|
|
133
140
|
}
|
|
134
141
|
|
|
135
|
-
type
|
|
142
|
+
type HoaResponseBody =
|
|
136
143
|
| string
|
|
137
144
|
| Blob
|
|
138
145
|
| ArrayBuffer
|
|
@@ -151,43 +158,43 @@ export declare class HoaResponse {
|
|
|
151
158
|
req: HoaRequest;
|
|
152
159
|
|
|
153
160
|
get headers(): Record<string, string>;
|
|
154
|
-
set headers(
|
|
161
|
+
set headers(val: Headers | Record<string, string> | Iterable<readonly [string, string]>);
|
|
155
162
|
|
|
156
163
|
get(field: string): string | null;
|
|
157
164
|
getSetCookie(): string[];
|
|
158
165
|
has(field: string): boolean;
|
|
159
|
-
set(field: string,
|
|
160
|
-
set(
|
|
161
|
-
append(field: string,
|
|
162
|
-
append(
|
|
166
|
+
set(field: string, val: string): void;
|
|
167
|
+
set(field: Record<string, string>): void;
|
|
168
|
+
append(field: string, val: string): void;
|
|
169
|
+
append(field: Record<string, string>): void;
|
|
163
170
|
delete(field: string): void;
|
|
164
171
|
|
|
165
172
|
get status(): number;
|
|
166
|
-
set status(
|
|
173
|
+
set status(val: number);
|
|
167
174
|
|
|
168
175
|
get statusText(): string;
|
|
169
|
-
set statusText(
|
|
176
|
+
set statusText(val: string);
|
|
170
177
|
|
|
171
|
-
get body():
|
|
172
|
-
set body(
|
|
178
|
+
get body(): HoaResponseBody;
|
|
179
|
+
set body(val: HoaResponseBody);
|
|
173
180
|
|
|
174
181
|
redirect(url: string): void;
|
|
175
182
|
back(alt?: string): void;
|
|
176
183
|
|
|
177
184
|
get type(): string | null;
|
|
178
|
-
set type(
|
|
185
|
+
set type(val: string);
|
|
179
186
|
|
|
180
187
|
get length(): number | null;
|
|
181
|
-
set length(
|
|
188
|
+
set length(val: number | string);
|
|
182
189
|
|
|
183
|
-
toJSON():
|
|
190
|
+
toJSON(): HoaResponseJson;
|
|
184
191
|
}
|
|
185
192
|
|
|
186
193
|
export declare class HttpError extends Error {
|
|
187
194
|
constructor(
|
|
188
195
|
status: number,
|
|
189
|
-
message?: string |
|
|
190
|
-
options?:
|
|
196
|
+
message?: string | HoaError,
|
|
197
|
+
options?: HoaError
|
|
191
198
|
);
|
|
192
199
|
readonly name: string;
|
|
193
200
|
readonly status: number;
|