hoa 0.1.2 → 0.2.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 +9 -0
- package/README.md +1 -1
- package/dist/cjs/context.js +7 -5
- package/dist/cjs/{application.js → hoa.js} +24 -21
- package/dist/cjs/lib/http-error.js +1 -1
- package/dist/cjs/request.js +2 -2
- package/dist/cjs/response.js +2 -3
- package/dist/esm/context.js +7 -5
- package/dist/esm/{application.js → hoa.js} +21 -18
- package/dist/esm/lib/http-error.js +1 -1
- package/dist/esm/request.js +2 -2
- package/dist/esm/response.js +2 -3
- package/package.json +7 -11
- package/types/index.d.ts +53 -85
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<a href="https://hoa-js.com">
|
|
3
|
-
<img src="https://raw.githubusercontent.com/hoa-js/
|
|
3
|
+
<img src="https://raw.githubusercontent.com/hoa-js/website/master/logo.png" width="400" height="400" alt="Hoa"/>
|
|
4
4
|
</a>
|
|
5
5
|
</div>
|
|
6
6
|
|
package/dist/cjs/context.js
CHANGED
|
@@ -51,8 +51,8 @@ class HoaContext {
|
|
|
51
51
|
/**
|
|
52
52
|
* Throw an HttpError.
|
|
53
53
|
*
|
|
54
|
-
* @param {number} status
|
|
55
|
-
* @param {string|{message?: string, cause?: any, headers?: HeadersInit}} [messageOrOptions]
|
|
54
|
+
* @param {number} status - HTTP status code
|
|
55
|
+
* @param {string|{message?: string, cause?: any, headers?: HeadersInit}} [messageOrOptions] - Error message or options object
|
|
56
56
|
* @throws {HttpError}
|
|
57
57
|
* @public
|
|
58
58
|
*/
|
|
@@ -73,8 +73,9 @@ class HoaContext {
|
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Default error handling and response builder.
|
|
76
|
-
*
|
|
77
|
-
* @
|
|
76
|
+
*
|
|
77
|
+
* @param {Error} err - Error to handle
|
|
78
|
+
* @returns {Response} Web Standard Response object
|
|
78
79
|
* @private
|
|
79
80
|
*/
|
|
80
81
|
onerror(err) {
|
|
@@ -98,7 +99,8 @@ class HoaContext {
|
|
|
98
99
|
}
|
|
99
100
|
/**
|
|
100
101
|
* Return JSON representation of the context.
|
|
101
|
-
*
|
|
102
|
+
*
|
|
103
|
+
* @returns {CtxJSON} JSON representation of context
|
|
102
104
|
* @public
|
|
103
105
|
*/
|
|
104
106
|
toJSON() {
|
|
@@ -25,26 +25,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
30
|
-
Hoa: () =>
|
|
28
|
+
var hoa_exports = {};
|
|
29
|
+
__export(hoa_exports, {
|
|
30
|
+
Hoa: () => Hoa,
|
|
31
31
|
HoaContext: () => import_context.default,
|
|
32
32
|
HoaRequest: () => import_request.default,
|
|
33
33
|
HoaResponse: () => import_response.default,
|
|
34
34
|
HttpError: () => import_http_error.default,
|
|
35
35
|
compose: () => import_compose.default,
|
|
36
|
-
default: () =>
|
|
36
|
+
default: () => Hoa
|
|
37
37
|
});
|
|
38
|
-
module.exports = __toCommonJS(
|
|
38
|
+
module.exports = __toCommonJS(hoa_exports);
|
|
39
39
|
var import_compose = __toESM(require("./lib/compose.js"), 1);
|
|
40
40
|
var import_http_error = __toESM(require("./lib/http-error.js"), 1);
|
|
41
41
|
var import_utils = require("./lib/utils.js");
|
|
42
42
|
var import_context = __toESM(require("./context.js"), 1);
|
|
43
43
|
var import_request = __toESM(require("./request.js"), 1);
|
|
44
44
|
var import_response = __toESM(require("./response.js"), 1);
|
|
45
|
-
class
|
|
45
|
+
class Hoa {
|
|
46
46
|
/**
|
|
47
|
-
* Create an
|
|
47
|
+
* Create an Hoa instance.
|
|
48
48
|
*
|
|
49
49
|
* @param {Object} [options={}] - Application options
|
|
50
50
|
* @param {string} [options.name='Hoa'] - Application name for identification
|
|
@@ -59,9 +59,10 @@ class Application {
|
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Extend the application with a plugin initializer.
|
|
62
|
-
*
|
|
63
|
-
* @
|
|
64
|
-
* @
|
|
62
|
+
*
|
|
63
|
+
* @param {HoaExtension} fn - Plugin function that receives the app instance
|
|
64
|
+
* @returns {Hoa} The Hoa instance for method chaining
|
|
65
|
+
* @throws {TypeError}
|
|
65
66
|
* @public
|
|
66
67
|
*/
|
|
67
68
|
extend(fn) {
|
|
@@ -73,9 +74,10 @@ class Application {
|
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
75
76
|
* Register a middleware. Executed in registration order.
|
|
76
|
-
*
|
|
77
|
-
* @
|
|
78
|
-
* @
|
|
77
|
+
*
|
|
78
|
+
* @param {HoaMiddleware} fn - Middleware function
|
|
79
|
+
* @returns {Hoa} The Hoa instance for method chaining
|
|
80
|
+
* @throws {TypeError}
|
|
79
81
|
* @public
|
|
80
82
|
*/
|
|
81
83
|
use(fn) {
|
|
@@ -93,7 +95,7 @@ class Application {
|
|
|
93
95
|
* @param {Request} request - Web Standard Request object
|
|
94
96
|
* @param {any} [env] - Environment variables (platform-specific)
|
|
95
97
|
* @param {any} [executionCtx] - Execution context (platform-specific)
|
|
96
|
-
* @returns {Promise<Response>}
|
|
98
|
+
* @returns {Promise<Response>} Web Standard Response object
|
|
97
99
|
* @public
|
|
98
100
|
*/
|
|
99
101
|
fetch(request, env, executionCtx) {
|
|
@@ -106,8 +108,8 @@ class Application {
|
|
|
106
108
|
* Manages error handling and response building.
|
|
107
109
|
*
|
|
108
110
|
* @param {HoaContext} ctx - Request context
|
|
109
|
-
* @param {
|
|
110
|
-
* @returns {Promise<Response>}
|
|
111
|
+
* @param {HoaMiddleware} middlewareFn - Composed middleware function
|
|
112
|
+
* @returns {Promise<Response>} Web Standard Response object
|
|
111
113
|
* @private
|
|
112
114
|
*/
|
|
113
115
|
handleRequest(ctx, middlewareFn) {
|
|
@@ -122,7 +124,7 @@ class Application {
|
|
|
122
124
|
* @param {Request} request - Web Standard Request object
|
|
123
125
|
* @param {any} [env] - Environment variables
|
|
124
126
|
* @param {any} [executionCtx] - Execution context
|
|
125
|
-
* @returns {HoaContext}
|
|
127
|
+
* @returns {HoaContext} Created context instance
|
|
126
128
|
* @private
|
|
127
129
|
*/
|
|
128
130
|
createContext(request, env, executionCtx) {
|
|
@@ -141,7 +143,8 @@ class Application {
|
|
|
141
143
|
*
|
|
142
144
|
* @param {Error} err - Error to handle
|
|
143
145
|
* @param {HoaContext} [ctx] - Request context (optional)
|
|
144
|
-
* @
|
|
146
|
+
* @returns {void}
|
|
147
|
+
* @throws {TypeError}
|
|
145
148
|
* @private
|
|
146
149
|
*/
|
|
147
150
|
onerror(err, ctx) {
|
|
@@ -159,16 +162,16 @@ ${msg.replace(/^/gm, " ")}
|
|
|
159
162
|
/**
|
|
160
163
|
* ESM/CJS interop helper for default exports.
|
|
161
164
|
*
|
|
162
|
-
* @returns {typeof
|
|
165
|
+
* @returns {typeof Hoa} The Hoa class
|
|
163
166
|
* @static
|
|
164
167
|
*/
|
|
165
168
|
static get default() {
|
|
166
|
-
return
|
|
169
|
+
return Hoa;
|
|
167
170
|
}
|
|
168
171
|
/**
|
|
169
172
|
* Return JSON representation of the app.
|
|
170
173
|
*
|
|
171
|
-
* @returns {AppJSON}
|
|
174
|
+
* @returns {AppJSON} JSON representation of application
|
|
172
175
|
* @public
|
|
173
176
|
*/
|
|
174
177
|
toJSON() {
|
|
@@ -28,7 +28,7 @@ class HttpError extends Error {
|
|
|
28
28
|
* @param {number} status - HTTP status code (400-599, invalid codes become 500)
|
|
29
29
|
* @param {string|HttpErrorOptions} [message] - Error message or options object
|
|
30
30
|
* @param {HttpErrorOptions} [options] - Additional options when second param is string
|
|
31
|
-
* @throws {TypeError}
|
|
31
|
+
* @throws {TypeError}
|
|
32
32
|
*/
|
|
33
33
|
constructor(status, message, options) {
|
|
34
34
|
if (!Number.isInteger(status)) {
|
package/dist/cjs/request.js
CHANGED
|
@@ -513,7 +513,7 @@ class HoaRequest {
|
|
|
513
513
|
* This method can only be called once per request.
|
|
514
514
|
*
|
|
515
515
|
* @returns {Promise<any>} The parsed JSON data
|
|
516
|
-
* @throws {SyntaxError}
|
|
516
|
+
* @throws {SyntaxError}
|
|
517
517
|
* @public
|
|
518
518
|
*/
|
|
519
519
|
async json() {
|
|
@@ -533,7 +533,7 @@ class HoaRequest {
|
|
|
533
533
|
/**
|
|
534
534
|
* Return JSON representation of the request.
|
|
535
535
|
*
|
|
536
|
-
* @returns {ReqJSON}
|
|
536
|
+
* @returns {ReqJSON} JSON representation of request
|
|
537
537
|
* @public
|
|
538
538
|
*/
|
|
539
539
|
toJSON() {
|
package/dist/cjs/response.js
CHANGED
|
@@ -160,8 +160,7 @@ class HoaResponse {
|
|
|
160
160
|
* Automatically clears body for status codes that should not have content.
|
|
161
161
|
*
|
|
162
162
|
* @param {number} val - The HTTP status code (100-599)
|
|
163
|
-
* @throws {TypeError}
|
|
164
|
-
* @throws {TypeError} When status code is out of valid range (100–599)
|
|
163
|
+
* @throws {TypeError}
|
|
165
164
|
* @public
|
|
166
165
|
*/
|
|
167
166
|
set status(val) {
|
|
@@ -367,7 +366,7 @@ class HoaResponse {
|
|
|
367
366
|
/**
|
|
368
367
|
* Return JSON representation of the response.
|
|
369
368
|
*
|
|
370
|
-
* @returns {ResJSON}
|
|
369
|
+
* @returns {ResJSON} JSON representation of response
|
|
371
370
|
* @public
|
|
372
371
|
*/
|
|
373
372
|
toJSON() {
|
package/dist/esm/context.js
CHANGED
|
@@ -19,8 +19,8 @@ class HoaContext {
|
|
|
19
19
|
/**
|
|
20
20
|
* Throw an HttpError.
|
|
21
21
|
*
|
|
22
|
-
* @param {number} status
|
|
23
|
-
* @param {string|{message?: string, cause?: any, headers?: HeadersInit}} [messageOrOptions]
|
|
22
|
+
* @param {number} status - HTTP status code
|
|
23
|
+
* @param {string|{message?: string, cause?: any, headers?: HeadersInit}} [messageOrOptions] - Error message or options object
|
|
24
24
|
* @throws {HttpError}
|
|
25
25
|
* @public
|
|
26
26
|
*/
|
|
@@ -41,8 +41,9 @@ class HoaContext {
|
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Default error handling and response builder.
|
|
44
|
-
*
|
|
45
|
-
* @
|
|
44
|
+
*
|
|
45
|
+
* @param {Error} err - Error to handle
|
|
46
|
+
* @returns {Response} Web Standard Response object
|
|
46
47
|
* @private
|
|
47
48
|
*/
|
|
48
49
|
onerror(err) {
|
|
@@ -66,7 +67,8 @@ class HoaContext {
|
|
|
66
67
|
}
|
|
67
68
|
/**
|
|
68
69
|
* Return JSON representation of the context.
|
|
69
|
-
*
|
|
70
|
+
*
|
|
71
|
+
* @returns {CtxJSON} JSON representation of context
|
|
70
72
|
* @public
|
|
71
73
|
*/
|
|
72
74
|
toJSON() {
|
|
@@ -4,9 +4,9 @@ import { statusEmptyMapping } from "./lib/utils.js";
|
|
|
4
4
|
import HoaContext from "./context.js";
|
|
5
5
|
import HoaRequest from "./request.js";
|
|
6
6
|
import HoaResponse from "./response.js";
|
|
7
|
-
class
|
|
7
|
+
class Hoa {
|
|
8
8
|
/**
|
|
9
|
-
* Create an
|
|
9
|
+
* Create an Hoa instance.
|
|
10
10
|
*
|
|
11
11
|
* @param {Object} [options={}] - Application options
|
|
12
12
|
* @param {string} [options.name='Hoa'] - Application name for identification
|
|
@@ -21,9 +21,10 @@ class Application {
|
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Extend the application with a plugin initializer.
|
|
24
|
-
*
|
|
25
|
-
* @
|
|
26
|
-
* @
|
|
24
|
+
*
|
|
25
|
+
* @param {HoaExtension} fn - Plugin function that receives the app instance
|
|
26
|
+
* @returns {Hoa} The Hoa instance for method chaining
|
|
27
|
+
* @throws {TypeError}
|
|
27
28
|
* @public
|
|
28
29
|
*/
|
|
29
30
|
extend(fn) {
|
|
@@ -35,9 +36,10 @@ class Application {
|
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
37
38
|
* Register a middleware. Executed in registration order.
|
|
38
|
-
*
|
|
39
|
-
* @
|
|
40
|
-
* @
|
|
39
|
+
*
|
|
40
|
+
* @param {HoaMiddleware} fn - Middleware function
|
|
41
|
+
* @returns {Hoa} The Hoa instance for method chaining
|
|
42
|
+
* @throws {TypeError}
|
|
41
43
|
* @public
|
|
42
44
|
*/
|
|
43
45
|
use(fn) {
|
|
@@ -55,7 +57,7 @@ class Application {
|
|
|
55
57
|
* @param {Request} request - Web Standard Request object
|
|
56
58
|
* @param {any} [env] - Environment variables (platform-specific)
|
|
57
59
|
* @param {any} [executionCtx] - Execution context (platform-specific)
|
|
58
|
-
* @returns {Promise<Response>}
|
|
60
|
+
* @returns {Promise<Response>} Web Standard Response object
|
|
59
61
|
* @public
|
|
60
62
|
*/
|
|
61
63
|
fetch(request, env, executionCtx) {
|
|
@@ -68,8 +70,8 @@ class Application {
|
|
|
68
70
|
* Manages error handling and response building.
|
|
69
71
|
*
|
|
70
72
|
* @param {HoaContext} ctx - Request context
|
|
71
|
-
* @param {
|
|
72
|
-
* @returns {Promise<Response>}
|
|
73
|
+
* @param {HoaMiddleware} middlewareFn - Composed middleware function
|
|
74
|
+
* @returns {Promise<Response>} Web Standard Response object
|
|
73
75
|
* @private
|
|
74
76
|
*/
|
|
75
77
|
handleRequest(ctx, middlewareFn) {
|
|
@@ -84,7 +86,7 @@ class Application {
|
|
|
84
86
|
* @param {Request} request - Web Standard Request object
|
|
85
87
|
* @param {any} [env] - Environment variables
|
|
86
88
|
* @param {any} [executionCtx] - Execution context
|
|
87
|
-
* @returns {HoaContext}
|
|
89
|
+
* @returns {HoaContext} Created context instance
|
|
88
90
|
* @private
|
|
89
91
|
*/
|
|
90
92
|
createContext(request, env, executionCtx) {
|
|
@@ -103,7 +105,8 @@ class Application {
|
|
|
103
105
|
*
|
|
104
106
|
* @param {Error} err - Error to handle
|
|
105
107
|
* @param {HoaContext} [ctx] - Request context (optional)
|
|
106
|
-
* @
|
|
108
|
+
* @returns {void}
|
|
109
|
+
* @throws {TypeError}
|
|
107
110
|
* @private
|
|
108
111
|
*/
|
|
109
112
|
onerror(err, ctx) {
|
|
@@ -121,16 +124,16 @@ ${msg.replace(/^/gm, " ")}
|
|
|
121
124
|
/**
|
|
122
125
|
* ESM/CJS interop helper for default exports.
|
|
123
126
|
*
|
|
124
|
-
* @returns {typeof
|
|
127
|
+
* @returns {typeof Hoa} The Hoa class
|
|
125
128
|
* @static
|
|
126
129
|
*/
|
|
127
130
|
static get default() {
|
|
128
|
-
return
|
|
131
|
+
return Hoa;
|
|
129
132
|
}
|
|
130
133
|
/**
|
|
131
134
|
* Return JSON representation of the app.
|
|
132
135
|
*
|
|
133
|
-
* @returns {AppJSON}
|
|
136
|
+
* @returns {AppJSON} JSON representation of application
|
|
134
137
|
* @public
|
|
135
138
|
*/
|
|
136
139
|
toJSON() {
|
|
@@ -197,11 +200,11 @@ function respond(ctx) {
|
|
|
197
200
|
});
|
|
198
201
|
}
|
|
199
202
|
export {
|
|
200
|
-
|
|
203
|
+
Hoa,
|
|
201
204
|
HoaContext,
|
|
202
205
|
HoaRequest,
|
|
203
206
|
HoaResponse,
|
|
204
207
|
HttpError,
|
|
205
208
|
compose,
|
|
206
|
-
|
|
209
|
+
Hoa as default
|
|
207
210
|
};
|
|
@@ -6,7 +6,7 @@ class HttpError extends Error {
|
|
|
6
6
|
* @param {number} status - HTTP status code (400-599, invalid codes become 500)
|
|
7
7
|
* @param {string|HttpErrorOptions} [message] - Error message or options object
|
|
8
8
|
* @param {HttpErrorOptions} [options] - Additional options when second param is string
|
|
9
|
-
* @throws {TypeError}
|
|
9
|
+
* @throws {TypeError}
|
|
10
10
|
*/
|
|
11
11
|
constructor(status, message, options) {
|
|
12
12
|
if (!Number.isInteger(status)) {
|
package/dist/esm/request.js
CHANGED
|
@@ -491,7 +491,7 @@ class HoaRequest {
|
|
|
491
491
|
* This method can only be called once per request.
|
|
492
492
|
*
|
|
493
493
|
* @returns {Promise<any>} The parsed JSON data
|
|
494
|
-
* @throws {SyntaxError}
|
|
494
|
+
* @throws {SyntaxError}
|
|
495
495
|
* @public
|
|
496
496
|
*/
|
|
497
497
|
async json() {
|
|
@@ -511,7 +511,7 @@ class HoaRequest {
|
|
|
511
511
|
/**
|
|
512
512
|
* Return JSON representation of the request.
|
|
513
513
|
*
|
|
514
|
-
* @returns {ReqJSON}
|
|
514
|
+
* @returns {ReqJSON} JSON representation of request
|
|
515
515
|
* @public
|
|
516
516
|
*/
|
|
517
517
|
toJSON() {
|
package/dist/esm/response.js
CHANGED
|
@@ -138,8 +138,7 @@ class HoaResponse {
|
|
|
138
138
|
* Automatically clears body for status codes that should not have content.
|
|
139
139
|
*
|
|
140
140
|
* @param {number} val - The HTTP status code (100-599)
|
|
141
|
-
* @throws {TypeError}
|
|
142
|
-
* @throws {TypeError} When status code is out of valid range (100–599)
|
|
141
|
+
* @throws {TypeError}
|
|
143
142
|
* @public
|
|
144
143
|
*/
|
|
145
144
|
set status(val) {
|
|
@@ -345,7 +344,7 @@ class HoaResponse {
|
|
|
345
344
|
/**
|
|
346
345
|
* Return JSON representation of the response.
|
|
347
346
|
*
|
|
348
|
-
* @returns {ResJSON}
|
|
347
|
+
* @returns {ResJSON} JSON representation of response
|
|
349
348
|
* @public
|
|
350
349
|
*/
|
|
351
350
|
toJSON() {
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hoa",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "A minimal web framework built on Web Standards",
|
|
5
|
-
"main": "./dist/cjs/
|
|
5
|
+
"main": "./dist/cjs/hoa.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"module": "./dist/esm/
|
|
7
|
+
"module": "./dist/esm/hoa.js",
|
|
8
8
|
"types": "./types/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./types/index.d.ts",
|
|
12
|
-
"import": "./dist/esm/
|
|
13
|
-
"require": "./dist/cjs/
|
|
14
|
-
"default": "./dist/esm/
|
|
12
|
+
"import": "./dist/esm/hoa.js",
|
|
13
|
+
"require": "./dist/cjs/hoa.js",
|
|
14
|
+
"default": "./dist/esm/hoa.js"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
@@ -21,9 +21,6 @@
|
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
23
|
"lint": "eslint .",
|
|
24
|
-
"docs:dev": "vitepress dev",
|
|
25
|
-
"docs:build": "vitepress build",
|
|
26
|
-
"docs:preview": "vitepress preview",
|
|
27
24
|
"build": "tsup",
|
|
28
25
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
29
26
|
"prepublishOnly": "npm run lint && npm run test && npm run build",
|
|
@@ -58,8 +55,7 @@
|
|
|
58
55
|
"husky": "9.1.7",
|
|
59
56
|
"jest": "30.2.0",
|
|
60
57
|
"neostandard": "0.12.2",
|
|
61
|
-
"tsup": "8.5.0"
|
|
62
|
-
"vitepress": "1.6.4"
|
|
58
|
+
"tsup": "8.5.0"
|
|
63
59
|
},
|
|
64
60
|
"engines": {
|
|
65
61
|
"node": ">=20"
|
package/types/index.d.ts
CHANGED
|
@@ -1,75 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface ApplicationOptions {
|
|
4
|
-
name?: string;
|
|
1
|
+
interface AppJSON {
|
|
2
|
+
name: string;
|
|
5
3
|
}
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export interface AppJSON {
|
|
12
|
-
name: string;
|
|
5
|
+
interface CtxJSON {
|
|
6
|
+
app: AppJSON;
|
|
7
|
+
req: ReqJSON;
|
|
8
|
+
res: ResJSON;
|
|
13
9
|
}
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
interface ReqJSON {
|
|
16
12
|
method: string;
|
|
17
13
|
url: string;
|
|
18
14
|
headers: Record<string, string>;
|
|
19
15
|
}
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
interface ResJSON {
|
|
22
18
|
status: number;
|
|
23
19
|
statusText: string;
|
|
24
20
|
headers: Record<string, string>;
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
export
|
|
28
|
-
app: AppJSON;
|
|
29
|
-
req: ReqJSON;
|
|
30
|
-
res: ResJSON;
|
|
31
|
-
}
|
|
23
|
+
export type HoaExtension = (app: Hoa) => void;
|
|
32
24
|
|
|
33
|
-
export
|
|
34
|
-
request?: Request;
|
|
35
|
-
env?: any;
|
|
36
|
-
executionCtx?: any;
|
|
37
|
-
}
|
|
25
|
+
export type HoaMiddleware = (ctx: HoaContext, next?: () => Promise<void>) => Promise<void> | void;
|
|
38
26
|
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
cause?: unknown;
|
|
42
|
-
expose?: boolean;
|
|
43
|
-
headers?: HoaHeadersInit;
|
|
44
|
-
}
|
|
27
|
+
export declare class Hoa {
|
|
28
|
+
constructor(options?: { name?: string });
|
|
45
29
|
|
|
46
|
-
|
|
30
|
+
name: string;
|
|
31
|
+
silent?: boolean;
|
|
32
|
+
readonly HoaContext: typeof HoaContext;
|
|
33
|
+
readonly HoaRequest: typeof HoaRequest;
|
|
34
|
+
readonly HoaResponse: typeof HoaResponse;
|
|
35
|
+
readonly middlewares: HoaMiddleware[];
|
|
47
36
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
extend(fn: HoaExtension): this;
|
|
38
|
+
use(fn: HoaMiddleware): this;
|
|
39
|
+
fetch(request: Request, env?: any, executionCtx?: any): Promise<Response>;
|
|
40
|
+
protected handleRequest(ctx: HoaContext, middlewareFn: HoaMiddleware): Promise<Response>;
|
|
41
|
+
protected createContext(request: Request, env?: any, executionCtx?: any): HoaContext;
|
|
42
|
+
protected onerror(err: unknown, ctx?: HoaContext): void;
|
|
43
|
+
toJSON(): AppJSON;
|
|
44
|
+
|
|
45
|
+
static get default(): typeof Hoa;
|
|
54
46
|
}
|
|
55
47
|
|
|
56
48
|
export declare class HoaContext {
|
|
57
|
-
constructor(options?:
|
|
58
|
-
app:
|
|
49
|
+
constructor(options?: { request?: Request; env?: any; executionCtx?: any });
|
|
50
|
+
app: Hoa;
|
|
59
51
|
req: HoaRequest;
|
|
60
52
|
res: HoaResponse;
|
|
61
53
|
request?: Request;
|
|
62
54
|
env?: any;
|
|
63
55
|
executionCtx?: any;
|
|
64
56
|
state: Record<string, any>;
|
|
65
|
-
throw(status: number, message?: string |
|
|
66
|
-
assert<T>(value: T, status: number, message?: string |
|
|
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>;
|
|
67
59
|
onerror(err: unknown): Response;
|
|
68
60
|
toJSON(): CtxJSON;
|
|
69
61
|
}
|
|
70
62
|
|
|
71
63
|
export declare class HoaRequest {
|
|
72
|
-
app:
|
|
64
|
+
app: Hoa;
|
|
73
65
|
ctx: HoaContext;
|
|
74
66
|
res: HoaResponse;
|
|
75
67
|
|
|
@@ -107,10 +99,10 @@ export declare class HoaRequest {
|
|
|
107
99
|
set method(value: string);
|
|
108
100
|
|
|
109
101
|
get query(): Record<string, string | string[]>;
|
|
110
|
-
set query(value: Record<string, string |
|
|
102
|
+
set query(value: Record<string, string | string[]>);
|
|
111
103
|
|
|
112
104
|
get headers(): Record<string, string>;
|
|
113
|
-
set headers(value:
|
|
105
|
+
set headers(value: Headers | Record<string, string> | Iterable<readonly [string, string]>);
|
|
114
106
|
|
|
115
107
|
get body(): ReadableStream<Uint8Array> | null;
|
|
116
108
|
set body(value: any);
|
|
@@ -139,7 +131,7 @@ export declare class HoaRequest {
|
|
|
139
131
|
toJSON(): ReqJSON;
|
|
140
132
|
}
|
|
141
133
|
|
|
142
|
-
|
|
134
|
+
type ResponseBody =
|
|
143
135
|
| string
|
|
144
136
|
| Blob
|
|
145
137
|
| ArrayBuffer
|
|
@@ -153,12 +145,12 @@ export type ResponseBody =
|
|
|
153
145
|
| undefined;
|
|
154
146
|
|
|
155
147
|
export declare class HoaResponse {
|
|
156
|
-
app:
|
|
148
|
+
app: Hoa;
|
|
157
149
|
ctx: HoaContext;
|
|
158
150
|
req: HoaRequest;
|
|
159
151
|
|
|
160
152
|
get headers(): Record<string, string>;
|
|
161
|
-
set headers(value:
|
|
153
|
+
set headers(value: Headers | Record<string, string> | Iterable<readonly [string, string]>);
|
|
162
154
|
|
|
163
155
|
get(field: string): string | null;
|
|
164
156
|
getSetCookie(): string[];
|
|
@@ -190,45 +182,21 @@ export declare class HoaResponse {
|
|
|
190
182
|
toJSON(): ResJSON;
|
|
191
183
|
}
|
|
192
184
|
|
|
193
|
-
export declare class
|
|
194
|
-
constructor(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
readonly
|
|
200
|
-
readonly
|
|
201
|
-
readonly
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
use(fn: HoaMiddleware): this;
|
|
205
|
-
fetch(request: Request, env?: any, executionCtx?: any): Promise<Response>;
|
|
206
|
-
protected handleRequest(ctx: HoaContext, middlewareFn: (ctx: HoaContext) => Promise<void>): Promise<Response>;
|
|
207
|
-
protected createContext(request: Request, env?: any, executionCtx?: any): HoaContext;
|
|
208
|
-
protected onerror(err: unknown, ctx?: HoaContext): void;
|
|
209
|
-
toJSON(): AppJSON;
|
|
210
|
-
|
|
211
|
-
static get default(): typeof Application;
|
|
185
|
+
export declare class HttpError extends Error {
|
|
186
|
+
constructor(
|
|
187
|
+
status: number,
|
|
188
|
+
message?: string | { message?: string; cause?: unknown; expose?: boolean; headers?: Headers | Record<string, string> | Iterable<readonly [string, string]> },
|
|
189
|
+
options?: { message?: string; cause?: unknown; expose?: boolean; headers?: Headers | Record<string, string> | Iterable<readonly [string, string]> }
|
|
190
|
+
);
|
|
191
|
+
readonly name: string;
|
|
192
|
+
readonly status: number;
|
|
193
|
+
readonly statusCode: number;
|
|
194
|
+
readonly expose: boolean;
|
|
195
|
+
readonly headers?: Record<string, string>;
|
|
212
196
|
}
|
|
213
197
|
|
|
214
|
-
export declare function compose
|
|
215
|
-
middlewares: ReadonlyArray<HoaMiddleware
|
|
216
|
-
):
|
|
217
|
-
|
|
218
|
-
export
|
|
219
|
-
ApplicationOptions,
|
|
220
|
-
AppJSON,
|
|
221
|
-
CtxJSON,
|
|
222
|
-
CtxOptions,
|
|
223
|
-
HoaHeadersInit,
|
|
224
|
-
HoaMiddleware,
|
|
225
|
-
HttpErrorOptions,
|
|
226
|
-
ReqJSON,
|
|
227
|
-
ResJSON,
|
|
228
|
-
NextFunction,
|
|
229
|
-
ResponseBody
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
export { Application as Hoa, HoaContext, HoaRequest, HoaResponse, HttpError, compose };
|
|
233
|
-
|
|
234
|
-
export default Application;
|
|
198
|
+
export declare function compose(
|
|
199
|
+
middlewares: ReadonlyArray<HoaMiddleware> | ReadonlyArray<ReadonlyArray<HoaMiddleware>>
|
|
200
|
+
): HoaMiddleware;
|
|
201
|
+
|
|
202
|
+
export default Hoa;
|