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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## v0.3.3 / 2025-12-03
2
+
3
+ - fix: types improvements
4
+
5
+ ## v0.3.2 / 2025-11-09
6
+
7
+ - fix: export statusTextMapping + statusRedirectMapping + statusEmptyMapping
8
+
1
9
  ## v0.3.1 / 2025-11-08
2
10
 
3
11
  - fix: app.onerror print original error
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
  });
@@ -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(type) {
329
- if (!type) return;
330
- type = import_utils.commonTypeMapping[type] || type;
331
- this.set("Content-Type", 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
  };
@@ -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(type) {
307
- if (!type) return;
308
- type = commonTypeMapping[type] || type;
309
- this.set("Content-Type", 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hoa",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "A minimal web framework built on Web Standards",
5
5
  "main": "./dist/cjs/hoa.js",
6
6
  "type": "module",
package/types/index.d.ts CHANGED
@@ -1,25 +1,32 @@
1
- interface AppJSON {
1
+ interface HoaAppJson {
2
2
  name: string;
3
3
  }
4
4
 
5
- interface CtxJSON {
6
- app: AppJSON;
7
- req: ReqJSON;
8
- res: ResJSON;
5
+ interface HoaContextJson {
6
+ app: HoaAppJson;
7
+ req: HoaRequestJson;
8
+ res: HoaResponseJson;
9
9
  }
10
10
 
11
- interface ReqJSON {
11
+ interface HoaRequestJson {
12
12
  method: string;
13
13
  url: string;
14
14
  headers: Record<string, string>;
15
15
  }
16
16
 
17
- interface ResJSON {
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(): AppJSON;
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 | { 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>;
59
66
  onerror(err: unknown): Response;
60
- toJSON(): CtxJSON;
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(value: string | URL);
77
+ set url(val: string | URL);
71
78
 
72
79
  get href(): string;
73
- set href(value: string);
80
+ set href(val: string);
74
81
 
75
82
  get origin(): string;
76
- set origin(value: string);
83
+ set origin(val: string);
77
84
 
78
85
  get protocol(): string;
79
- set protocol(value: string);
86
+ set protocol(val: string);
80
87
 
81
88
  get host(): string;
82
- set host(value: string);
89
+ set host(val: string);
83
90
 
84
91
  get hostname(): string;
85
- set hostname(value: string);
92
+ set hostname(val: string);
86
93
 
87
94
  get port(): string;
88
- set port(value: string);
95
+ set port(val: string);
89
96
 
90
97
  get pathname(): string;
91
- set pathname(value: string);
98
+ set pathname(val: string);
92
99
 
93
100
  get search(): string;
94
- set search(value: string);
101
+ set search(val: string);
95
102
 
96
103
  get hash(): string;
97
- set hash(value: string);
104
+ set hash(val: string);
98
105
 
99
106
  get method(): string;
100
- set method(value: string);
107
+ set method(val: string);
101
108
 
102
109
  get query(): Record<string, string | string[]>;
103
- set query(value: Record<string, string | string[]>);
110
+ set query(val: Record<string, string | string[]>);
104
111
 
105
112
  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]>);
107
114
 
108
115
  get body(): ReadableStream<Uint8Array> | null;
109
- set body(value: any);
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, 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;
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(): ReqJSON;
139
+ toJSON(): HoaRequestJson;
133
140
  }
134
141
 
135
- type ResponseBody =
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(value: Headers | Record<string, string> | Iterable<readonly [string, string]>);
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, 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;
163
170
  delete(field: string): void;
164
171
 
165
172
  get status(): number;
166
- set status(value: number);
173
+ set status(val: number);
167
174
 
168
175
  get statusText(): string;
169
- set statusText(value: string);
176
+ set statusText(val: string);
170
177
 
171
- get body(): ResponseBody;
172
- set body(value: ResponseBody);
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(value: string);
185
+ set type(val: string);
179
186
 
180
187
  get length(): number | null;
181
- set length(value: number | string);
188
+ set length(val: number | string);
182
189
 
183
- toJSON(): ResJSON;
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 | { 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
191
198
  );
192
199
  readonly name: string;
193
200
  readonly status: number;