Skip to content

Commit 451ea02

Browse files
committed
fix: types improvements
1 parent 70fdc4d commit 451ea02

File tree

4 files changed

+61
-50
lines changed

4 files changed

+61
-50
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v0.3.3 / 2025-12-03
2+
3+
- fix: types improvements
4+
15
## v0.3.2 / 2025-11-09
26

37
- fix: export statusTextMapping + statusRedirectMapping + statusEmptyMapping

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hoa",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"description": "A minimal web framework built on Web Standards",
55
"main": "./dist/cjs/hoa.js",
66
"type": "module",

src/response.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,10 @@ export default class HoaResponse {
366366
* @param {string} type - The content type or alias (e.g., 'json', 'html', 'application/json')
367367
* @public
368368
*/
369-
set type (type) {
370-
if (!type) return
371-
type = commonTypeMapping[type] || type
372-
this.set('Content-Type', type)
369+
set type (val) {
370+
if (!val) return
371+
val = commonTypeMapping[val] || val
372+
this.set('Content-Type', val)
373373
}
374374

375375
/**

types/index.d.ts

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
interface AppJSON {
1+
interface HoaAppJson {
22
name: string;
33
}
44

5-
interface CtxJSON {
6-
app: AppJSON;
7-
req: ReqJSON;
8-
res: ResJSON;
5+
interface HoaContextJson {
6+
app: HoaAppJson;
7+
req: HoaRequestJson;
8+
res: HoaResponseJson;
99
}
1010

11-
interface ReqJSON {
11+
interface HoaRequestJson {
1212
method: string;
1313
url: string;
1414
headers: Record<string, string>;
1515
}
1616

17-
interface ResJSON {
17+
interface HoaResponseJson {
1818
status: number;
1919
statusText: string;
2020
headers: Record<string, string>;
2121
}
2222

23+
interface HoaError {
24+
message?: string;
25+
cause?: unknown;
26+
expose?: boolean;
27+
headers?: Headers | Record<string, string> | Iterable<readonly [string, string]>;
28+
}
29+
2330
export type HoaExtension = (app: Hoa) => void;
2431

2532
export type HoaMiddleware = (ctx: HoaContext, next?: () => Promise<void>) => Promise<void> | void;
@@ -40,7 +47,7 @@ export declare class Hoa {
4047
protected handleRequest(ctx: HoaContext, middlewareFn: HoaMiddleware): Promise<Response>;
4148
protected createContext(request: Request, env?: any, executionCtx?: any): HoaContext;
4249
protected onerror(err: unknown, ctx?: HoaContext): void;
43-
toJSON(): AppJSON;
50+
toJSON(): HoaAppJson;
4451

4552
static get default(): typeof Hoa;
4653
}
@@ -54,10 +61,10 @@ export declare class HoaContext {
5461
env?: any;
5562
executionCtx?: any;
5663
state: Record<string, any>;
57-
throw(status: number, message?: string | { message?: string; cause?: unknown; expose?: boolean; headers?: Headers | Record<string, string> | Iterable<readonly [string, string]> }, options?: { message?: string; cause?: unknown; expose?: boolean; headers?: Headers | Record<string, string> | Iterable<readonly [string, string]> }): never;
58-
assert<T>(value: T, status: number, message?: string | { message?: string; cause?: unknown; expose?: boolean; headers?: Headers | Record<string, string> | Iterable<readonly [string, string]> }, options?: { message?: string; cause?: unknown; expose?: boolean; headers?: Headers | Record<string, string> | Iterable<readonly [string, string]> }): asserts value is NonNullable<T>;
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>;
5966
onerror(err: unknown): Response;
60-
toJSON(): CtxJSON;
67+
toJSON(): HoaContextJson;
6168
readonly response: Response;
6269
}
6370

@@ -67,54 +74,54 @@ export declare class HoaRequest {
6774
res: HoaResponse;
6875

6976
get url(): URL;
70-
set url(value: string | URL);
77+
set url(val: string | URL);
7178

7279
get href(): string;
73-
set href(value: string);
80+
set href(val: string);
7481

7582
get origin(): string;
76-
set origin(value: string);
83+
set origin(val: string);
7784

7885
get protocol(): string;
79-
set protocol(value: string);
86+
set protocol(val: string);
8087

8188
get host(): string;
82-
set host(value: string);
89+
set host(val: string);
8390

8491
get hostname(): string;
85-
set hostname(value: string);
92+
set hostname(val: string);
8693

8794
get port(): string;
88-
set port(value: string);
95+
set port(val: string);
8996

9097
get pathname(): string;
91-
set pathname(value: string);
98+
set pathname(val: string);
9299

93100
get search(): string;
94-
set search(value: string);
101+
set search(val: string);
95102

96103
get hash(): string;
97-
set hash(value: string);
104+
set hash(val: string);
98105

99106
get method(): string;
100-
set method(value: string);
107+
set method(val: string);
101108

102109
get query(): Record<string, string | string[]>;
103-
set query(value: Record<string, string | string[]>);
110+
set query(val: Record<string, string | string[]>);
104111

105112
get headers(): Record<string, string>;
106-
set headers(value: Headers | Record<string, string> | Iterable<readonly [string, string]>);
113+
set headers(val: Headers | Record<string, string> | Iterable<readonly [string, string]>);
107114

108115
get body(): ReadableStream<Uint8Array> | null;
109-
set body(value: any);
116+
set body(val: any);
110117

111118
get(field: string): string | null;
112119
getSetCookie(): string[];
113120
has(field: string): boolean;
114-
set(field: string, value: string): void;
115-
set(values: Record<string, string>): void;
116-
append(field: string, value: string): void;
117-
append(values: Record<string, string>): void;
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;
118125
delete(field: string): void;
119126

120127
get ips(): string[];
@@ -129,10 +136,10 @@ export declare class HoaRequest {
129136
text(): Promise<string>;
130137
json<T = any>(): Promise<T>;
131138
formData(): Promise<FormData>;
132-
toJSON(): ReqJSON;
139+
toJSON(): HoaRequestJson;
133140
}
134141

135-
type ResponseBody =
142+
type HoaResponseBody =
136143
| string
137144
| Blob
138145
| ArrayBuffer
@@ -151,43 +158,43 @@ export declare class HoaResponse {
151158
req: HoaRequest;
152159

153160
get headers(): Record<string, string>;
154-
set headers(value: Headers | Record<string, string> | Iterable<readonly [string, string]>);
161+
set headers(val: Headers | Record<string, string> | Iterable<readonly [string, string]>);
155162

156163
get(field: string): string | null;
157164
getSetCookie(): string[];
158165
has(field: string): boolean;
159-
set(field: string, value: string): void;
160-
set(values: Record<string, string>): void;
161-
append(field: string, value: string): void;
162-
append(values: Record<string, string>): void;
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;
163170
delete(field: string): void;
164171

165172
get status(): number;
166-
set status(value: number);
173+
set status(val: number);
167174

168175
get statusText(): string;
169-
set statusText(value: string);
176+
set statusText(val: string);
170177

171-
get body(): ResponseBody;
172-
set body(value: ResponseBody);
178+
get body(): HoaResponseBody;
179+
set body(val: HoaResponseBody);
173180

174181
redirect(url: string): void;
175182
back(alt?: string): void;
176183

177184
get type(): string | null;
178-
set type(value: string);
185+
set type(val: string);
179186

180187
get length(): number | null;
181-
set length(value: number | string);
188+
set length(val: number | string);
182189

183-
toJSON(): ResJSON;
190+
toJSON(): HoaResponseJson;
184191
}
185192

186193
export declare class HttpError extends Error {
187194
constructor(
188195
status: number,
189-
message?: string | { message?: string; cause?: unknown; expose?: boolean; headers?: Headers | Record<string, string> | Iterable<readonly [string, string]> },
190-
options?: { message?: string; cause?: unknown; expose?: boolean; headers?: Headers | Record<string, string> | Iterable<readonly [string, string]> }
196+
message?: string | HoaError,
197+
options?: HoaError
191198
);
192199
readonly name: string;
193200
readonly status: number;

0 commit comments

Comments
 (0)